Skip to content

Commit 36c71d6

Browse files
committed
feat(ddo): adding ddo service
1 parent dc70b97 commit 36c71d6

File tree

5 files changed

+347
-0
lines changed

5 files changed

+347
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import root from 'window-or-global';
2+
import { settings as ddsSettings } from '@carbon/ibmdotcom-utilities';
3+
4+
/**
5+
* DDO API class with methods of fetching search results for
6+
* ibm.com
7+
*/
8+
class DDOAPI {
9+
/**
10+
* Promise function that determines when the digital data object is ready
11+
*
12+
* @returns {Promise} Resolved data layer ready signal
13+
*/
14+
static isReady() {
15+
return new Promise(resolve => {
16+
if (
17+
root.digitalData &&
18+
root.digitalData.page &&
19+
root.digitalData.page.isDataLayerReady
20+
) {
21+
resolve();
22+
} else {
23+
root.addEventListener('datalayer_ready', () => resolve);
24+
}
25+
});
26+
}
27+
28+
/**
29+
* Sets the version of the library to the DDO
30+
*/
31+
static async setVersion() {
32+
return await this.isReady().then(() => {
33+
root.digitalData.page.version = ddsSettings.version;
34+
});
35+
}
36+
37+
/**
38+
* Gets the locale for the current page based on the language set as metadata
39+
*
40+
* @returns {Promise<*>} Promise object
41+
*/
42+
static async getLanguage() {
43+
return await this.isReady().then(() => {
44+
return root.digitalData.page.pageInfo.language;
45+
});
46+
}
47+
}
48+
49+
export default DDOAPI;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import DDOAPI from '../DDO';
2+
import digitalDataResponse from './data/response.json';
3+
import root from 'window-or-global';
4+
5+
jest.mock('@carbon/ibmdotcom-utilities', () => ({
6+
settings: {
7+
version: 'dds.v1.0.0',
8+
},
9+
}));
10+
11+
describe('DDOAPI', () => {
12+
beforeEach(function() {
13+
root.digitalData = digitalDataResponse;
14+
});
15+
16+
it('should return the language', async () => {
17+
const language = await DDOAPI.getLanguage();
18+
19+
expect(language).toEqual('en-US');
20+
});
21+
22+
it('should set the version in the DDO', async () => {
23+
await DDOAPI.setVersion();
24+
25+
expect(root.digitalData.page.version).toEqual('dds.v1.0.0');
26+
});
27+
28+
it('should set an event listener if the data layer is not ready', () => {
29+
root.digitalData.page.isDataLayerReady = false;
30+
jest.useFakeTimers();
31+
32+
DDOAPI.isReady();
33+
34+
setTimeout(() => {
35+
root.digitalData.page.isDataLayerReady = 'test ready';
36+
root.dispatchEvent(new Event('datalayer_ready'));
37+
}, 500);
38+
jest.runAllTimers();
39+
40+
expect(root.digitalData.page.isDataLayerReady).toEqual('test ready');
41+
});
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
{
2+
"page": {
3+
"attributes": {
4+
"pageidQueryStrings": [
5+
"q",
6+
"s",
7+
"tabType[0]",
8+
"tabType%5B0%5D"
9+
],
10+
"agentMobileOS": "unknown"
11+
},
12+
"category": {
13+
"ibm": {},
14+
"primaryCategory": "null",
15+
"iniPrimaryCategory": "null"
16+
},
17+
"pageInfo": {
18+
"analytics": {
19+
"category": "Uncategorized"
20+
},
21+
"convertro": {
22+
"enabled": "false"
23+
},
24+
"coremetrics": {
25+
"visitorID": null,
26+
"visitorId": null,
27+
"clientID": "50200000|IBMTESTWWW",
28+
"isEluminateLoaded": false,
29+
"enabled": true
30+
},
31+
"demandbase": {
32+
"enabled": true
33+
},
34+
"hotjar": {
35+
"enabled": "false"
36+
},
37+
"ibm": {
38+
"siteID": "IBMTESTWWW",
39+
"country": "",
40+
"industry": "",
41+
"owner": "",
42+
"subject": "",
43+
"type": "",
44+
"iniSiteID": "IBMTESTWWW"
45+
},
46+
"lotame": {
47+
"activeAudience": null,
48+
"audience": "240097",
49+
"pid": "446689ed8a1d9791b415f537e490d3af"
50+
},
51+
"metrics": {},
52+
"medallia": {
53+
"triggerFired": "true"
54+
},
55+
"optimizely": {
56+
"enabled": "false",
57+
"projectID": ""
58+
},
59+
"segment": {
60+
"enabled": "false",
61+
"key": ""
62+
},
63+
"tealium": {
64+
"collect": {}
65+
},
66+
"trustarc": {
67+
"enabled": "true"
68+
},
69+
"urx": {},
70+
"destinationURL": "https://ibmdotcom-react.netlify.com/",
71+
"destinationDomain": "netlify.com",
72+
"description": "A collection of IBM.com components implemented using React and Carbon Design System.",
73+
"effectiveDate": "",
74+
"expiryDate": "",
75+
"keywords": "IBM, design, system, Carbon, design system, Bluemix, styleguide, style, guide, components, library, pattern, kit, component, cloud, React, React.js",
76+
"language": "en-US",
77+
"publishDate": "",
78+
"publisher": "",
79+
"rights": "",
80+
"source": "",
81+
"referrer": "",
82+
"referrerDomain": "",
83+
"referrerID": "",
84+
"urlID": "ibmdotcom-react.netlify.com",
85+
"clickableURLID": "https://ibmdotcom-react.netlify.com",
86+
"pageID": "ibmdotcom-react.netlify.com",
87+
"dleID": "6804808e6d33a5e4e0eed41c0771f7e9d725a0a8f50799b3c9bec2e488e72c8e",
88+
"dleURL": "https://tags.tiqcdn.com/dle/ibm/web/p_6804808e6d33a5e4e0eed41c0771f7e9d725a0a8f50799b3c9bec2e488e72c8e.js",
89+
"contentId": "url-6804808e6d33a5e4e0eed41c0771f7e9d725a0a8f50799b3c9bec2e488e72c8e",
90+
"canonical": "ibmdotcom-react.netlify.com",
91+
"onsiteSearchTerm": "",
92+
"onsiteSearchResult": "",
93+
"pageHeader": null,
94+
"pageName": "Storybook",
95+
"title": "Storybook",
96+
"google": {
97+
"gtag": {
98+
"pageURL": "https://ibmdotcom-react.netlify.com/",
99+
"pageReferrerURL": "",
100+
"pagePath": "ibmdotcom-react.netlify.com",
101+
"pageTitle": "",
102+
"customDimension1": 1,
103+
"customDimension2": "IBMTESTWWW",
104+
"customDimension4": "",
105+
"customDimension5": "5f3e204f-8dca-41f7-873b-3c608634cfdd",
106+
"customDimension7": "",
107+
"customDimension12": "ibmdotcom-react.netlify.com",
108+
"customDimension13": "https://ibmdotcom-react.netlify.com/",
109+
"customDimension16": "",
110+
"customDimension17": "",
111+
"customDimension3": "",
112+
"customDimension6": "",
113+
"customDimension8": "",
114+
"customDimension9": "",
115+
"customDimension10": "",
116+
"customDimension11": "",
117+
"customDimension14": "",
118+
"customDimension15": "S:628|T:2,162,46,28,93,53,45,94|L:100|IP:f|IPC:us|DBC:us",
119+
"customDimension18": "bf43c6e1-0681-49fd-8945-50a64c60fc92"
120+
}
121+
},
122+
"productTitle": "Unnamed Product"
123+
},
124+
"session": {
125+
"engagement": {
126+
"isEngaged": false,
127+
"isPageEngaged": false,
128+
"scorePage": 0,
129+
"scoreVisit": 0,
130+
"events": 0,
131+
"pages": 0,
132+
"totalPages": 1
133+
},
134+
"pageloadEpoch": 1569589572001,
135+
"pageviewId": "5f3e204f-8dca-41f7-873b-3c608634cfdd",
136+
"uPageViewID": "5f3e204f-8dca-41f7-873b-3c608634cfdd",
137+
"issuedInitialPageview": true,
138+
"event": "profile"
139+
},
140+
"isDataLayerReady": true
141+
},
142+
"events": {
143+
"processed": [],
144+
"current": {}
145+
},
146+
"content": {
147+
"drivers": {},
148+
"nbo": {}
149+
},
150+
"user": {
151+
"gdpr": {
152+
"state": "ny",
153+
"country": "us",
154+
"latitude": 40.75,
155+
"longitude": -73.9967,
156+
"isCountryMemberOfEU": false,
157+
"isCountryRequiringExplicitConsent": false
158+
},
159+
"profile": {
160+
"dw": {},
161+
"ex": {},
162+
"ng": {
163+
"iuiHashed": null
164+
},
165+
"topics": []
166+
},
167+
"segment": {
168+
"30": true,
169+
"31": true,
170+
"11241": true,
171+
"18192": true,
172+
"isIBMer": 1
173+
},
174+
"userInfo": {
175+
"registry_country_code": "us",
176+
"browserLanguage": "en-US",
177+
"annual_sales": 79590000000,
178+
"audience_segment": "software & technology",
179+
"audience": "enterprise business",
180+
"b2b": true,
181+
"b2c": true,
182+
"city": "poughkeepsie",
183+
"company_name": "ibm corporation",
184+
"country_name": "united states",
185+
"country": "us",
186+
"demandbase_sid": 50918973,
187+
"employee_count": 351000,
188+
"employee_range": "enterprise",
189+
"forbes_2000": false,
190+
"fortune_1000": false,
191+
"industry": "software & technology",
192+
"information_level": "detailed",
193+
"ip": "129.42.208.183",
194+
"isp": false,
195+
"latitude": 41.66,
196+
"longitude": -73.93,
197+
"marketing_alias": "ibm",
198+
"phone": "845-433-1234",
199+
"primary_naics": "334111",
200+
"primary_sic": "3571",
201+
"region_name": "new york",
202+
"registry_city": "new york",
203+
"registry_company_name": "advanced workstations division, ibm corporation",
204+
"registry_country": "united states",
205+
"registry_dma_code": 501,
206+
"registry_latitude": 40.77,
207+
"registry_longitude": -73.99,
208+
"registry_state": "ny",
209+
"registry_zip_code": "10019",
210+
"revenue_range": "over $5b",
211+
"state": "ny",
212+
"street_address": "2455 south rd",
213+
"sub_industry": "computer & mobile devices",
214+
"traffic": "very high",
215+
"web_site": "ibm.com",
216+
"zip": "12601",
217+
"ipLastOctet": "184"
218+
}
219+
},
220+
"util": {
221+
"cp": {
222+
"cmTPSet": "Y",
223+
"_ga": "GA1.3.781956925.1569442431",
224+
"_gid": "GA1.3.1110946260.1569442431",
225+
"CMAVID": "none",
226+
"notice_behavior": "implied|eu",
227+
"pageviewContext": "5f3e204f-8dca-41f7-873b-3c608634cfdd"
228+
},
229+
"meta": {
230+
"viewport": "width=device-width,initial-scale=1",
231+
"keywords": "IBM, design, system, Carbon, design system, Bluemix, styleguide, style, guide, components, library, pattern, kit, component, cloud, React, React.js",
232+
"description": "A collection of IBM.com components implemented using React and Carbon Design System.",
233+
"og:title": "IBM.com Library React",
234+
"og:site_name": "IBM.com Library React",
235+
"og:description": "A collection of IBM.com components implemented using React and Carbon Design System.",
236+
"og:image": "https://media.github.ibm.com/user/525/files/59e3bfde-b990-11e7-87ef-072e89a87719",
237+
"og:url": "https://ibmdotcom-react.netlify.com",
238+
"twitter:card": "summary_large_image",
239+
"twitter:image:alt": "IBM.com Library",
240+
"twitter:site": "@_IBM",
241+
"og:type": "website",
242+
"og:locale": "en-US"
243+
},
244+
"qp": {},
245+
"referrer": {}
246+
}
247+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Copyright IBM Corp. 2016, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
export { default as DDOAPI } from './DDO';

packages/utilities/src/utilities/settings/settings.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
*/
1010
const settings = {
11+
version: 'dds.v0.5.0',
1112
stablePrefix: 'dds',
1213
};
1314

0 commit comments

Comments
 (0)