@financial-times/cmp-client 4.1.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +228 -77
- package/dist/index.js +228 -77
- package/dist/scripts/cmp-static.js +2 -1
- package/dist/src/client.d.ts +1 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/consent-parsers/__fixtures__/gpp.d.ts +20 -0
- package/dist/src/consent-parsers/__fixtures__/gpp.d.ts.map +1 -0
- package/dist/src/consent-parsers/__tests__/index.test.d.ts +2 -0
- package/dist/src/consent-parsers/__tests__/index.test.d.ts.map +1 -0
- package/dist/src/consent-parsers/gpp/__tests__/parse-gpp-consent.test.d.ts +2 -0
- package/dist/src/consent-parsers/gpp/__tests__/parse-gpp-consent.test.d.ts.map +1 -0
- package/dist/src/consent-parsers/gpp/index.d.ts +3 -0
- package/dist/src/consent-parsers/gpp/index.d.ts.map +1 -0
- package/dist/src/consent-parsers/index.d.ts +6 -0
- package/dist/src/consent-parsers/index.d.ts.map +1 -0
- package/dist/src/consent-parsers/tcfv2/__tests__/check-consent.test.d.ts.map +1 -0
- package/dist/src/{consent-ready/utils/get-parsed-consent.d.ts → consent-parsers/tcfv2/index.d.ts} +2 -7
- package/dist/src/consent-parsers/tcfv2/index.d.ts.map +1 -0
- package/dist/src/consent-ready/index.d.ts.map +1 -1
- package/dist/src/html/__tests__/cmp-manage-cookies-links.test.d.ts +2 -0
- package/dist/src/html/__tests__/cmp-manage-cookies-links.test.d.ts.map +1 -0
- package/dist/src/html/cmp-manage-cookies-link.d.ts +6 -9
- package/dist/src/html/cmp-manage-cookies-link.d.ts.map +1 -1
- package/dist/src/html/cmp-scripts.d.ts +2 -2
- package/dist/src/html/cmp-scripts.d.ts.map +1 -1
- package/dist/src/lib/configurators/ft-dot-com.d.ts +7 -0
- package/dist/src/lib/configurators/ft-dot-com.d.ts.map +1 -0
- package/dist/src/lib/configurators/index.d.ts +14 -0
- package/dist/src/lib/configurators/index.d.ts.map +1 -0
- package/dist/src/lib/constants.d.ts +0 -4
- package/dist/src/lib/constants.d.ts.map +1 -1
- package/dist/src/lib/properties.d.ts +3 -12
- package/dist/src/lib/properties.d.ts.map +1 -1
- package/dist/src/utils/url.d.ts +3 -12
- package/dist/src/utils/url.d.ts.map +1 -1
- package/package.json +1 -1
- package/typings/globals.d.ts +5 -1
- package/typings/types.d.ts +97 -4
- package/dist/src/consent-ready/utils/__tests__/check-consent.test.d.ts.map +0 -1
- package/dist/src/consent-ready/utils/__tests__/get-parsed-consent.test.d.ts +0 -2
- package/dist/src/consent-ready/utils/__tests__/get-parsed-consent.test.d.ts.map +0 -1
- package/dist/src/consent-ready/utils/get-parsed-consent.d.ts.map +0 -1
- /package/dist/src/{consent-ready/utils → consent-parsers/tcfv2}/__tests__/check-consent.test.d.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -46,8 +46,7 @@ const debug = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
46
46
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
47
47
|
const defaults = {
|
|
48
48
|
joinHref: true,
|
|
49
|
-
gdpr: {}
|
|
50
|
-
ccpa: {}
|
|
49
|
+
gdpr: {}
|
|
51
50
|
};
|
|
52
51
|
const FT_DOTCOM_TEST = {
|
|
53
52
|
...defaults,
|
|
@@ -56,7 +55,8 @@ const FT_DOTCOM_TEST = {
|
|
|
56
55
|
propertyHref: "https://local.ft.com",
|
|
57
56
|
_clientOptions: {
|
|
58
57
|
privacyManagerId: 827767,
|
|
59
|
-
manageCookiesLinkOverride: "ft.com/preferences/manage-cookies"
|
|
58
|
+
manageCookiesLinkOverride: "ft.com/preferences/manage-cookies",
|
|
59
|
+
rootDomain: "ft.com"
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
const FT_DOTCOM_PROD = {
|
|
@@ -66,6 +66,8 @@ const FT_DOTCOM_PROD = {
|
|
|
66
66
|
propertyId: 31642,
|
|
67
67
|
_clientOptions: {
|
|
68
68
|
privacyManagerId: 827767,
|
|
69
|
+
usnatPrivacyManagerId: 944881,
|
|
70
|
+
ccpaPrivacyManagerId: 944882,
|
|
69
71
|
manageCookiesLinkOverride: "ft.com/preferences/manage-cookies",
|
|
70
72
|
rootDomain: "ft.com"
|
|
71
73
|
}
|
|
@@ -175,40 +177,75 @@ const properties = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
175
177
|
SP_SUSTAINABLE_VIEWS,
|
|
176
178
|
SP_THE_BANKER
|
|
177
179
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return resolve();
|
|
181
|
-
const isReady = () => ["interactive", "complete"].includes(document.readyState);
|
|
182
|
-
function onStateChange() {
|
|
183
|
-
if (isReady()) {
|
|
184
|
-
document.removeEventListener("readystatechange", onStateChange);
|
|
185
|
-
resolve();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (isReady())
|
|
189
|
-
return resolve();
|
|
190
|
-
document.addEventListener("readystatechange", onStateChange);
|
|
191
|
-
});
|
|
192
|
-
function findAndUpdateLinks(_clientOptions, loadPrivacyManagerModal) {
|
|
193
|
-
const { privacyManagerId, manageCookiesLinkOverride } = _clientOptions ?? {};
|
|
194
|
-
if (!privacyManagerId || !manageCookiesLinkOverride) {
|
|
195
|
-
return console.warn("_clientOptions is missing privacyManagerId or manageCookiesLinkOverride");
|
|
196
|
-
}
|
|
180
|
+
function findAndUpdateLinks(fallback, regionId, regionApplies, regionConfig, linkMap, manageCookiesLinkOverride) {
|
|
181
|
+
const { text, onClick } = regionConfig[regionId];
|
|
197
182
|
const anchors = document.querySelectorAll(`a[href*="${manageCookiesLinkOverride}"]`);
|
|
198
183
|
for (const anchor of anchors) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
184
|
+
if (regionApplies || fallback) {
|
|
185
|
+
if (linkMap.has(anchor)) {
|
|
186
|
+
anchor.removeEventListener("click", linkMap.get(anchor));
|
|
187
|
+
}
|
|
188
|
+
anchor.innerText = text;
|
|
189
|
+
anchor.addEventListener("click", onClick);
|
|
190
|
+
linkMap.set(anchor, onClick);
|
|
191
|
+
}
|
|
203
192
|
}
|
|
204
193
|
}
|
|
205
194
|
function interceptManageCookiesLinks({ _clientOptions } = FT_DOTCOM_PROD) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
195
|
+
const {
|
|
196
|
+
privacyManagerId,
|
|
197
|
+
ccpaPrivacyManagerId,
|
|
198
|
+
usnatPrivacyManagerId,
|
|
199
|
+
manageCookiesLinkOverride
|
|
200
|
+
} = _clientOptions ?? FT_DOTCOM_PROD._clientOptions;
|
|
201
|
+
const regionConfig = {
|
|
202
|
+
usnat: {
|
|
203
|
+
text: "Do not sell my data",
|
|
204
|
+
onClick: (e) => {
|
|
205
|
+
var _a;
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
(_a = window._sp_["usnat"]) == null ? void 0 : _a.loadPrivacyManagerModal(usnatPrivacyManagerId);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
ccpa: {
|
|
211
|
+
text: "Do not sell my data",
|
|
212
|
+
onClick: (e) => {
|
|
213
|
+
var _a;
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
(_a = window._sp_["ccpa"]) == null ? void 0 : _a.loadPrivacyManagerModal(ccpaPrivacyManagerId);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
gdpr: {
|
|
219
|
+
text: "Manage cookies",
|
|
220
|
+
onClick: (e) => {
|
|
221
|
+
var _a;
|
|
222
|
+
e.preventDefault();
|
|
223
|
+
(_a = window._sp_["gdpr"]) == null ? void 0 : _a.loadPrivacyManagerModal(privacyManagerId);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const linkMap = /* @__PURE__ */ new Map();
|
|
228
|
+
const onConsentReadyHandler = function(message_type, _uuid, _string, info) {
|
|
229
|
+
findAndUpdateLinks(
|
|
230
|
+
false,
|
|
231
|
+
message_type,
|
|
232
|
+
info.applies,
|
|
233
|
+
regionConfig,
|
|
234
|
+
linkMap,
|
|
235
|
+
manageCookiesLinkOverride
|
|
236
|
+
);
|
|
237
|
+
if (info.applies) {
|
|
238
|
+
window._sp_queue.push(() => {
|
|
239
|
+
var _a, _b;
|
|
240
|
+
(_b = (_a = window._sp_).removeEventListener) == null ? void 0 : _b.call(_a, "onConsentReady", onConsentReadyHandler);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
findAndUpdateLinks(true, "gdpr", false, regionConfig, linkMap, manageCookiesLinkOverride);
|
|
245
|
+
window._sp_queue ?? (window._sp_queue = []);
|
|
246
|
+
window._sp_queue.push(() => {
|
|
247
|
+
var _a, _b;
|
|
248
|
+
(_b = (_a = window._sp_).addEventListener) == null ? void 0 : _b.call(_a, "onConsentReady", onConsentReadyHandler);
|
|
212
249
|
});
|
|
213
250
|
}
|
|
214
251
|
const request = (url, { credentials = "omit" } = {}) => {
|
|
@@ -336,20 +373,34 @@ const scriptSources = {
|
|
|
336
373
|
};
|
|
337
374
|
const scriptContent = {
|
|
338
375
|
tcfStub: `"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(){var t=function(){var t,e,o=[],n=window,r=n;for(;r;){try{if(r.frames.__tcfapiLocator){t=r;break}}catch(t){}if(r===n.top)break;r=r.parent}t||(!function t(){var e=n.document,o=!!n.frames.__tcfapiLocator;if(!o)if(e.body){var r=e.createElement("iframe");r.style.cssText="display:none",r.name="__tcfapiLocator",r.title = "__tcfapiLocator",e.body.appendChild(r)}else setTimeout(t,5);return!o}(),n.__tcfapi=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(!n.length)return o;"setGdprApplies"===n[0]?n.length>3&&2===parseInt(n[1],10)&&"boolean"==typeof n[3]&&(e=n[3],"function"==typeof n[2]&&n[2]("set",!0)):"ping"===n[0]?"function"==typeof n[2]&&n[2]({gdprApplies:e,cmpLoaded:!1,cmpStatus:"stub"}):o.push(n)},n.addEventListener("message",(function(t){var e="string"==typeof t.data,o={};if(e)try{o=JSON.parse(t.data)}catch(t){}else o=t.data;var n="object"===_typeof(o)&&null!==o?o.__tcfapiCall:null;n&&window.__tcfapi(n.command,n.version,(function(o,r){var a={__tcfapiReturn:{returnValue:o,success:r,callId:n.callId}};t&&t.source&&t.source.postMessage&&t.source.postMessage(e?JSON.stringify(a):a,"*")}),n.parameter)}),!1))};"undefined"!=typeof module?module.exports=t:t()}();`,
|
|
339
|
-
|
|
376
|
+
gppStub: `window.__gpp_addFrame=function(e){if(!window.frames[e])if(document.body){var t=document.createElement("iframe");t.style.cssText="display:none",t.name=e,document.body.appendChild(t)}else window.setTimeout(window.__gpp_addFrame,10,e)},window.__gpp_stub=function(){var e=arguments;if(__gpp.queue=__gpp.queue||[],__gpp.events=__gpp.events||[],!e.length||1==e.length&&"queue"==e[0])return __gpp.queue;if(1==e.length&&"events"==e[0])return __gpp.events;var t=e[0],p=e.length>1?e[1]:null,s=e.length>2?e[2]:null;if("ping"===t)p({gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}},!0);else if("addEventListener"===t){"lastId"in __gpp||(__gpp.lastId=0),__gpp.lastId++;var n=__gpp.lastId;__gpp.events.push({id:n,callback:p,parameter:s}),p({eventName:"listenerRegistered",listenerId:n,data:!0,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}}},!0)}else if("removeEventListener"===t){for(var a=!1,i=0;i<__gpp.events.length;i++)if(__gpp.events[i].id==s){__gpp.events.splice(i,1),a=!0;break}p({eventName:"listenerRemoved",listenerId:s,data:a,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}}},!0)}else"hasSection"===t?p(!1,!0):"getSection"===t||"getField"===t?p(null,!0):__gpp.queue.push([].slice.apply(e))},window.__gpp_msghandler=function(e){var t="string"==typeof e.data;try{var p=t?JSON.parse(e.data):e.data}catch(e){p=null}if("object"==typeof p&&null!==p&&"__gppCall"in p){var s=p.__gppCall;window.__gpp(s.command,(function(p,n){var a={__gppReturn:{returnValue:p,success:n,callId:s.callId}};e.source.postMessage(t?JSON.stringify(a):a,"*")}),"parameter"in s?s.parameter:null,"version"in s?s.version:"1.1")}},"__gpp"in window&&"function"==typeof window.__gpp||(window.__gpp=window.__gpp_stub,window.addEventListener("message",window.__gpp_msghandler,!1),window.__gpp_addFrame("__gppLocator"));
|
|
377
|
+
`
|
|
340
378
|
};
|
|
341
|
-
function getCmpScripts() {
|
|
379
|
+
function getCmpScripts(options) {
|
|
342
380
|
const fragment = document.createDocumentFragment();
|
|
343
381
|
fragment.appendChild(createContentScript("tcf", scriptContent.tcfStub));
|
|
344
|
-
|
|
382
|
+
if (options.includeUsNat) {
|
|
383
|
+
fragment.appendChild(createContentScript("gpp", scriptContent.gppStub));
|
|
384
|
+
}
|
|
345
385
|
fragment.appendChild(createSourceScript(scriptSources.cmpFrames));
|
|
346
386
|
return fragment;
|
|
347
387
|
}
|
|
348
|
-
function
|
|
388
|
+
function applyOptionsToConfig(propertyConfig, options) {
|
|
389
|
+
const { userId, includeUsNat } = options;
|
|
390
|
+
if (userId) {
|
|
391
|
+
propertyConfig.authId = userId;
|
|
392
|
+
}
|
|
393
|
+
if (includeUsNat) {
|
|
394
|
+
propertyConfig.usnat = propertyConfig.usnat || {};
|
|
395
|
+
}
|
|
396
|
+
return propertyConfig;
|
|
397
|
+
}
|
|
398
|
+
function bootstrapCmp(config, options) {
|
|
349
399
|
const { _clientOptions, ...spConfig } = config;
|
|
350
|
-
|
|
400
|
+
const runtimeConfig = applyOptionsToConfig(spConfig, options);
|
|
401
|
+
window._sp_ = { config: runtimeConfig };
|
|
351
402
|
window._sp_queue ?? (window._sp_queue = []);
|
|
352
|
-
document.head.appendChild(getCmpScripts());
|
|
403
|
+
document.head.appendChild(getCmpScripts(options));
|
|
353
404
|
}
|
|
354
405
|
function getConsentPayload(parsedConsent, updateConsentStore, { formOfWordsId, cookieDomain }) {
|
|
355
406
|
const categoryNames = Object.keys(parsedConsent);
|
|
@@ -378,6 +429,89 @@ function getConsentPayload(parsedConsent, updateConsentStore, { formOfWordsId, c
|
|
|
378
429
|
}
|
|
379
430
|
return { data, cookieDomain };
|
|
380
431
|
}
|
|
432
|
+
const sections = {
|
|
433
|
+
CALIFORNIA: "uscav1",
|
|
434
|
+
US_NATIONAL: "usnatv1"
|
|
435
|
+
};
|
|
436
|
+
const sectionConfig = {
|
|
437
|
+
[sections.CALIFORNIA]: {
|
|
438
|
+
excludedCategories: {
|
|
439
|
+
personalisedMarketing: true
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
[sections.US_NATIONAL]: {
|
|
443
|
+
excludedCategories: {
|
|
444
|
+
personalisedMarketing: true
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
function getApplicableSection(gppData) {
|
|
449
|
+
const { applicableSections, supportedAPIs } = gppData;
|
|
450
|
+
const applicableSection = applicableSections[0];
|
|
451
|
+
if (applicableSection === -1 || typeof applicableSection === "undefined") {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const sectionApi = supportedAPIs.find((api) => api.startsWith(`${applicableSection}:`));
|
|
455
|
+
const sectionKey = sectionApi == null ? void 0 : sectionApi.split(":")[1];
|
|
456
|
+
return sectionKey;
|
|
457
|
+
}
|
|
458
|
+
function parseCaliforniaSection(sectionData) {
|
|
459
|
+
const { SaleOptOut, SharingOptOut, Gpc } = sectionData;
|
|
460
|
+
const { excludedCategories } = sectionConfig[sections.CALIFORNIA];
|
|
461
|
+
const userHasNotOptedOut = SaleOptOut !== 1 && SharingOptOut !== 1 && !Gpc;
|
|
462
|
+
const parsedConsent = {};
|
|
463
|
+
for (const categoryName of iabCategoryNames) {
|
|
464
|
+
if (categoryName in excludedCategories) {
|
|
465
|
+
parsedConsent[categoryName] = true;
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
parsedConsent[categoryName] = userHasNotOptedOut;
|
|
469
|
+
}
|
|
470
|
+
return parsedConsent;
|
|
471
|
+
}
|
|
472
|
+
function parseUsNationalSection(sectionData) {
|
|
473
|
+
const { SaleOptOut, SharingOptOut, TargetedAdvertisingOptOut } = sectionData;
|
|
474
|
+
const { excludedCategories } = sectionConfig[sections.US_NATIONAL];
|
|
475
|
+
const userHasNotOptedOut = SaleOptOut !== 1 && SharingOptOut !== 1 && TargetedAdvertisingOptOut !== 1;
|
|
476
|
+
const parsedConsent = {};
|
|
477
|
+
for (const categoryName of iabCategoryNames) {
|
|
478
|
+
if (categoryName in excludedCategories) {
|
|
479
|
+
parsedConsent[categoryName] = true;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
parsedConsent[categoryName] = userHasNotOptedOut;
|
|
483
|
+
}
|
|
484
|
+
return parsedConsent;
|
|
485
|
+
}
|
|
486
|
+
const sectionParsers = {
|
|
487
|
+
[sections.CALIFORNIA]: parseCaliforniaSection,
|
|
488
|
+
[sections.US_NATIONAL]: parseUsNationalSection
|
|
489
|
+
};
|
|
490
|
+
async function parseGPPConsent() {
|
|
491
|
+
const gppData = await new Promise((resolve, reject) => {
|
|
492
|
+
try {
|
|
493
|
+
if (window.__gpp) {
|
|
494
|
+
window.__gpp("ping", resolve);
|
|
495
|
+
} else {
|
|
496
|
+
reject(new Error("GPP API is not available on page"));
|
|
497
|
+
}
|
|
498
|
+
} catch (error) {
|
|
499
|
+
reject(error);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
const { parsedSections } = gppData;
|
|
503
|
+
const applicableSection = getApplicableSection(gppData);
|
|
504
|
+
if (!applicableSection || !parsedSections[applicableSection]) {
|
|
505
|
+
throw new Error("GPP parser was called without an applicable section");
|
|
506
|
+
}
|
|
507
|
+
const sectionData = parsedSections[applicableSection];
|
|
508
|
+
const parseSection = sectionParsers[applicableSection];
|
|
509
|
+
if (!parseSection || typeof parseSection !== "function") {
|
|
510
|
+
throw new Error(`No parser found for applicable GPP section: ${applicableSection}`);
|
|
511
|
+
}
|
|
512
|
+
const parsedConsent = parseSection(sectionData);
|
|
513
|
+
return parsedConsent;
|
|
514
|
+
}
|
|
381
515
|
function checkConsentFor(categoryName, { purpose, vendor, specialFeatureOptins }) {
|
|
382
516
|
const customCategory = iabCustomCategories[categoryName];
|
|
383
517
|
const requiredPurposesConsented = customCategory.purposes.every(
|
|
@@ -391,19 +525,14 @@ function checkConsentFor(categoryName, { purpose, vendor, specialFeatureOptins }
|
|
|
391
525
|
);
|
|
392
526
|
return requiredPurposesConsented && requiredIabVendorsConsented && requiredSpecialFeaturesConsented;
|
|
393
527
|
}
|
|
394
|
-
function parseCCPAConsent(ccpa) {
|
|
395
|
-
const userHasNotOptedOut = (ccpa == null ? void 0 : ccpa[2]) === "N";
|
|
396
|
-
const parsedConsent = {};
|
|
397
|
-
for (const categoryName of iabCategoryNames) {
|
|
398
|
-
parsedConsent[categoryName] = userHasNotOptedOut;
|
|
399
|
-
}
|
|
400
|
-
return parsedConsent;
|
|
401
|
-
}
|
|
402
528
|
async function parseGDPRConsent() {
|
|
403
529
|
const tcData = await new Promise((resolve, reject) => {
|
|
404
|
-
var _a;
|
|
405
530
|
try {
|
|
406
|
-
(
|
|
531
|
+
if (window.__tcfapi) {
|
|
532
|
+
window.__tcfapi("addEventListener", 2, resolve);
|
|
533
|
+
} else {
|
|
534
|
+
reject(new Error("TCF API is not available on page"));
|
|
535
|
+
}
|
|
407
536
|
} catch (error) {
|
|
408
537
|
reject(error);
|
|
409
538
|
}
|
|
@@ -414,8 +543,16 @@ async function parseGDPRConsent() {
|
|
|
414
543
|
}
|
|
415
544
|
return parsedConsent;
|
|
416
545
|
}
|
|
417
|
-
async function getParsedConsent(activeLegislation
|
|
418
|
-
|
|
546
|
+
async function getParsedConsent(activeLegislation) {
|
|
547
|
+
const legislationParsers = {
|
|
548
|
+
gdpr: parseGDPRConsent,
|
|
549
|
+
usnat: parseGPPConsent
|
|
550
|
+
};
|
|
551
|
+
const consentParser = legislationParsers[activeLegislation];
|
|
552
|
+
if (!consentParser) {
|
|
553
|
+
throw new Error("Unable to update user consent. Unsupported consent legislation.");
|
|
554
|
+
}
|
|
555
|
+
return consentParser();
|
|
419
556
|
}
|
|
420
557
|
function getConsentCookieValue() {
|
|
421
558
|
const cookies = Object.fromEntries(
|
|
@@ -471,11 +608,22 @@ function consentReadyHandlerFn(props) {
|
|
|
471
608
|
if (props.disableFTCookies) {
|
|
472
609
|
return;
|
|
473
610
|
}
|
|
611
|
+
if (!props.includeUsNat && legislation === "usnat") {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
474
614
|
const activeLegislation = consentMeta.applies ? legislation : "gdpr";
|
|
475
615
|
if (activeLegislation !== legislation || !consentString) {
|
|
476
616
|
return;
|
|
477
617
|
}
|
|
478
|
-
|
|
618
|
+
let parsedConsent;
|
|
619
|
+
try {
|
|
620
|
+
parsedConsent = await getParsedConsent(activeLegislation);
|
|
621
|
+
} catch (error) {
|
|
622
|
+
console.error(error);
|
|
623
|
+
}
|
|
624
|
+
if (!parsedConsent) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
479
627
|
const consentHasChanged = hasConsentChanged(parsedConsent, getConsentCookieValue());
|
|
480
628
|
if (!consentHasChanged) {
|
|
481
629
|
return;
|
|
@@ -650,18 +798,19 @@ function setupPmTracking(trackingProps, cmpBaseEndpoint) {
|
|
|
650
798
|
false
|
|
651
799
|
);
|
|
652
800
|
}
|
|
653
|
-
const version = "
|
|
654
|
-
async function initSourcepointCmp({
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
} = {}
|
|
801
|
+
const version = "5.0.0";
|
|
802
|
+
async function initSourcepointCmp(options) {
|
|
803
|
+
const {
|
|
804
|
+
useFTSession = true,
|
|
805
|
+
consentProxyHost = FT_CONSENT_PROXY_HOST,
|
|
806
|
+
cookieDomain = FT_COOKIE_DOMAIN,
|
|
807
|
+
formOfWordsId = SOURCEPOINT_FOW_ID,
|
|
808
|
+
useConsentStore = true,
|
|
809
|
+
trackingContext = {},
|
|
810
|
+
disableFTCookies = false,
|
|
811
|
+
includeUsNat = false
|
|
812
|
+
} = options || {};
|
|
813
|
+
let { propertyConfig = FT_DOTCOM_PROD, userId } = options || {};
|
|
665
814
|
if (typeof window === "undefined") {
|
|
666
815
|
console.error("The CMP client can only be initialised in a browser context");
|
|
667
816
|
return;
|
|
@@ -675,19 +824,8 @@ async function initSourcepointCmp({
|
|
|
675
824
|
console.error(error);
|
|
676
825
|
}
|
|
677
826
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
if (userId) {
|
|
682
|
-
propertyConfig.authId = userId;
|
|
683
|
-
}
|
|
684
|
-
if (propertyConfig.events) {
|
|
685
|
-
console.warn(
|
|
686
|
-
"[cmp-client] Passing an events map in the config is not supported and will be ignored. Please use window._sp_.addEventListener() to listen for events"
|
|
687
|
-
);
|
|
688
|
-
delete propertyConfig.events;
|
|
689
|
-
}
|
|
690
|
-
bootstrapCmp(propertyConfig);
|
|
827
|
+
propertyConfig = validateAndCleanConfig(propertyConfig);
|
|
828
|
+
bootstrapCmp(propertyConfig, { userId, includeUsNat });
|
|
691
829
|
window._sp_queue.push(() => {
|
|
692
830
|
var _a, _b;
|
|
693
831
|
(_b = (_a = window._sp_) == null ? void 0 : _a.addEventListener) == null ? void 0 : _b.call(
|
|
@@ -699,12 +837,25 @@ async function initSourcepointCmp({
|
|
|
699
837
|
cookieDomain,
|
|
700
838
|
formOfWordsId,
|
|
701
839
|
useConsentStore,
|
|
702
|
-
disableFTCookies
|
|
840
|
+
disableFTCookies,
|
|
841
|
+
includeUsNat
|
|
703
842
|
})
|
|
704
843
|
);
|
|
705
844
|
});
|
|
706
845
|
initTracking(trackingContext, propertyConfig.baseEndpoint);
|
|
707
846
|
}
|
|
847
|
+
function validateAndCleanConfig(propertyConfig) {
|
|
848
|
+
if (!(propertyConfig == null ? void 0 : propertyConfig.accountId)) {
|
|
849
|
+
throw new Error("Please pass a valid property config");
|
|
850
|
+
}
|
|
851
|
+
if (propertyConfig.events) {
|
|
852
|
+
console.warn(
|
|
853
|
+
"[cmp-client] Passing an events map in the config is not supported and will be ignored. Please use window._sp_.addEventListener() to listen for events"
|
|
854
|
+
);
|
|
855
|
+
delete propertyConfig.events;
|
|
856
|
+
}
|
|
857
|
+
return propertyConfig;
|
|
858
|
+
}
|
|
708
859
|
exports.debug = debug;
|
|
709
860
|
exports.initSourcepointCmp = initSourcepointCmp;
|
|
710
861
|
exports.interceptManageCookiesLinks = interceptManageCookiesLinks;
|