@financial-times/cmp-client 0.0.0-backup.1

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.
Files changed (78) hide show
  1. package/README.md +273 -0
  2. package/dist/index.cjs +862 -0
  3. package/dist/index.js +862 -0
  4. package/dist/scripts/cmp-static.js +8 -0
  5. package/dist/src/__tests__/index.test.d.ts +2 -0
  6. package/dist/src/__tests__/index.test.d.ts.map +1 -0
  7. package/dist/src/client.d.ts +3 -0
  8. package/dist/src/client.d.ts.map +1 -0
  9. package/dist/src/consent-parsers/__fixtures__/gpp.d.ts +20 -0
  10. package/dist/src/consent-parsers/__fixtures__/gpp.d.ts.map +1 -0
  11. package/dist/src/consent-parsers/__tests__/index.test.d.ts +2 -0
  12. package/dist/src/consent-parsers/__tests__/index.test.d.ts.map +1 -0
  13. package/dist/src/consent-parsers/gpp/__tests__/parse-gpp-consent.test.d.ts +2 -0
  14. package/dist/src/consent-parsers/gpp/__tests__/parse-gpp-consent.test.d.ts.map +1 -0
  15. package/dist/src/consent-parsers/gpp/index.d.ts +3 -0
  16. package/dist/src/consent-parsers/gpp/index.d.ts.map +1 -0
  17. package/dist/src/consent-parsers/index.d.ts +6 -0
  18. package/dist/src/consent-parsers/index.d.ts.map +1 -0
  19. package/dist/src/consent-parsers/tcfv2/__tests__/check-consent.test.d.ts +2 -0
  20. package/dist/src/consent-parsers/tcfv2/__tests__/check-consent.test.d.ts.map +1 -0
  21. package/dist/src/consent-parsers/tcfv2/index.d.ts +10 -0
  22. package/dist/src/consent-parsers/tcfv2/index.d.ts.map +1 -0
  23. package/dist/src/consent-ready/index.d.ts +5 -0
  24. package/dist/src/consent-ready/index.d.ts.map +1 -0
  25. package/dist/src/consent-ready/utils/__fixtures__/helpers.d.ts +28 -0
  26. package/dist/src/consent-ready/utils/__fixtures__/helpers.d.ts.map +1 -0
  27. package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts +5 -0
  28. package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts.map +1 -0
  29. package/dist/src/consent-ready/utils/__tests__/consent.test.d.ts +2 -0
  30. package/dist/src/consent-ready/utils/__tests__/consent.test.d.ts.map +1 -0
  31. package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts +2 -0
  32. package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts.map +1 -0
  33. package/dist/src/consent-ready/utils/consent.d.ts +6 -0
  34. package/dist/src/consent-ready/utils/consent.d.ts.map +1 -0
  35. package/dist/src/consent-ready/utils/get-consent-payload.d.ts +18 -0
  36. package/dist/src/consent-ready/utils/get-consent-payload.d.ts.map +1 -0
  37. package/dist/src/consent-ready/utils/validators.d.ts +15 -0
  38. package/dist/src/consent-ready/utils/validators.d.ts.map +1 -0
  39. package/dist/src/html/__tests__/cmp-manage-cookies-links.test.d.ts +2 -0
  40. package/dist/src/html/__tests__/cmp-manage-cookies-links.test.d.ts.map +1 -0
  41. package/dist/src/html/__tests__/cmp-scripts.test.d.ts +2 -0
  42. package/dist/src/html/__tests__/cmp-scripts.test.d.ts.map +1 -0
  43. package/dist/src/html/cmp-manage-cookies-link.d.ts +8 -0
  44. package/dist/src/html/cmp-manage-cookies-link.d.ts.map +1 -0
  45. package/dist/src/html/cmp-scripts.d.ts +7 -0
  46. package/dist/src/html/cmp-scripts.d.ts.map +1 -0
  47. package/dist/src/index.d.ts +5 -0
  48. package/dist/src/index.d.ts.map +1 -0
  49. package/dist/src/lib/configurators/ft-dot-com.d.ts +7 -0
  50. package/dist/src/lib/configurators/ft-dot-com.d.ts.map +1 -0
  51. package/dist/src/lib/configurators/index.d.ts +14 -0
  52. package/dist/src/lib/configurators/index.d.ts.map +1 -0
  53. package/dist/src/lib/constants.d.ts +40 -0
  54. package/dist/src/lib/constants.d.ts.map +1 -0
  55. package/dist/src/lib/debug.d.ts +15 -0
  56. package/dist/src/lib/debug.d.ts.map +1 -0
  57. package/dist/src/lib/properties.d.ts +132 -0
  58. package/dist/src/lib/properties.d.ts.map +1 -0
  59. package/dist/src/scripts/cmp-static.d.ts +3 -0
  60. package/dist/src/scripts/cmp-static.d.ts.map +1 -0
  61. package/dist/src/tracking/__tests__/state.test.d.ts +2 -0
  62. package/dist/src/tracking/__tests__/state.test.d.ts.map +1 -0
  63. package/dist/src/tracking/constants.d.ts +3 -0
  64. package/dist/src/tracking/constants.d.ts.map +1 -0
  65. package/dist/src/tracking/index.d.ts +3 -0
  66. package/dist/src/tracking/index.d.ts.map +1 -0
  67. package/dist/src/tracking/state.d.ts +15 -0
  68. package/dist/src/tracking/state.d.ts.map +1 -0
  69. package/dist/src/utils/__tests__/url.test.d.ts +2 -0
  70. package/dist/src/utils/__tests__/url.test.d.ts.map +1 -0
  71. package/dist/src/utils/dom.d.ts +3 -0
  72. package/dist/src/utils/dom.d.ts.map +1 -0
  73. package/dist/src/utils/url.d.ts +127 -0
  74. package/dist/src/utils/url.d.ts.map +1 -0
  75. package/package.json +42 -0
  76. package/typings/globals.d.ts +20 -0
  77. package/typings/modules.d.ts +1 -0
  78. package/typings/types.d.ts +280 -0
package/dist/index.js ADDED
@@ -0,0 +1,862 @@
1
+ const events = {
2
+ onMessageChoiceSelect: (...args) => {
3
+ console.log("[debug] onMessageChoiceSelect", args);
4
+ },
5
+ onMessageReady: (...args) => {
6
+ console.log("[debug] onMessageReady", args);
7
+ },
8
+ onMessageChoiceError: (...args) => {
9
+ console.log("[debug] onMessageChoiceError", args);
10
+ },
11
+ onPrivacyManagerAction: (...args) => {
12
+ console.log("[debug] onPrivacyManagerAction", args);
13
+ },
14
+ onPMCancel: (...args) => {
15
+ console.log("[debug] onPMCancel", args);
16
+ },
17
+ onMessageReceiveData: (...args) => {
18
+ console.log("[debug] onMessageReceiveData", args);
19
+ },
20
+ onSPPMObjectReady: (...args) => {
21
+ console.log("[debug] onSPPMObjectReady", args);
22
+ },
23
+ onConsentReady: async (...args) => {
24
+ const [legislation, consentUUID, consentString, consentMeta] = args;
25
+ console.log("[debug] onConsentReady", { legislation, consentString, consentMeta, consentUUID });
26
+ },
27
+ onError: (...args) => {
28
+ console.log("[debug] onError", args);
29
+ }
30
+ };
31
+ function logCmpEvents() {
32
+ window._sp_queue = window._sp_queue ?? [];
33
+ window._sp_queue.push(() => {
34
+ var _a, _b;
35
+ for (const [eventId, eventHandler] of Object.entries(events)) {
36
+ (_b = (_a = window._sp_).addEventListener) == null ? void 0 : _b.call(_a, eventId, eventHandler);
37
+ }
38
+ });
39
+ }
40
+ const debug = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
41
+ __proto__: null,
42
+ events,
43
+ logCmpEvents
44
+ }, Symbol.toStringTag, { value: "Module" }));
45
+ const defaults = {
46
+ joinHref: true,
47
+ gdpr: {}
48
+ };
49
+ const FT_DOTCOM_TEST = {
50
+ ...defaults,
51
+ accountId: 1906,
52
+ baseEndpoint: "https://consent-manager.ft.com",
53
+ propertyHref: "https://local.ft.com",
54
+ _clientOptions: {
55
+ privacyManagerId: 827767,
56
+ manageCookiesLinkOverride: "ft.com/preferences/manage-cookies",
57
+ rootDomain: "ft.com"
58
+ }
59
+ };
60
+ const FT_DOTCOM_PROD = {
61
+ ...defaults,
62
+ accountId: 1906,
63
+ baseEndpoint: "https://consent-manager.ft.com",
64
+ propertyId: 31642,
65
+ _clientOptions: {
66
+ privacyManagerId: 827767,
67
+ usnatPrivacyManagerId: 944881,
68
+ ccpaPrivacyManagerId: 944882,
69
+ manageCookiesLinkOverride: "ft.com/preferences/manage-cookies",
70
+ rootDomain: "ft.com"
71
+ }
72
+ };
73
+ const SP_PWMNET = {
74
+ ...defaults,
75
+ accountId: 1906,
76
+ baseEndpoint: "https://consent-manager.pwmnet.com",
77
+ propertyId: 33414,
78
+ _clientOptions: {
79
+ rootDomain: "pwmnet.com"
80
+ }
81
+ };
82
+ const SP_FDI_INTELLIGENCE = {
83
+ ...defaults,
84
+ accountId: 1906,
85
+ baseEndpoint: "https://consent-manager.fdiintelligence.com",
86
+ propertyId: 34061,
87
+ _clientOptions: {
88
+ rootDomain: "fdiintelligence.com"
89
+ }
90
+ };
91
+ const SP_THE_BANKER = {
92
+ ...defaults,
93
+ accountId: 1906,
94
+ baseEndpoint: "https://consent-manager.thebanker.com",
95
+ propertyId: 34060,
96
+ _clientOptions: {
97
+ rootDomain: "thebanker.com"
98
+ }
99
+ };
100
+ const SP_BANKING_RR = {
101
+ ...defaults,
102
+ accountId: 1906,
103
+ baseEndpoint: "https://consent-manager.bankingriskandregulation.com",
104
+ propertyId: 34059,
105
+ _clientOptions: {
106
+ rootDomain: "bankingriskandregulation.com"
107
+ }
108
+ };
109
+ const SP_SUSTAINABLE_VIEWS = {
110
+ ...defaults,
111
+ accountId: 1906,
112
+ baseEndpoint: "https://consent-manager.sustainableviews.com",
113
+ propertyId: 34058,
114
+ _clientOptions: {
115
+ rootDomain: "sustainableviews.com"
116
+ }
117
+ };
118
+ const SP_FT_ADVISER = {
119
+ ...defaults,
120
+ accountId: 1906,
121
+ baseEndpoint: "https://consent-manager.ftadviser.com",
122
+ propertyId: 33416,
123
+ _clientOptions: {
124
+ rootDomain: "ftadviser.com"
125
+ }
126
+ };
127
+ const SP_INVESTORS_CHRONICLE = {
128
+ ...defaults,
129
+ accountId: 1906,
130
+ baseEndpoint: "https://consent-manager.investorschronicle.co.uk",
131
+ propertyId: 33415,
132
+ _clientOptions: {
133
+ rootDomain: "investorschronicle.co.uk"
134
+ }
135
+ };
136
+ const MM_IGNITES_ASIA = {
137
+ ...defaults,
138
+ accountId: 1906,
139
+ baseEndpoint: "https://cdn.privacy-mgmt.com",
140
+ propertyId: 33947,
141
+ _clientOptions: {
142
+ rootDomain: "ignitesasia.com"
143
+ }
144
+ };
145
+ const MM_IGNITES_EUROPE = {
146
+ ...defaults,
147
+ accountId: 1906,
148
+ baseEndpoint: "https://cdn.privacy-mgmt.com",
149
+ propertyId: 33946,
150
+ _clientOptions: {
151
+ rootDomain: "igniteseurope.com"
152
+ }
153
+ };
154
+ const SP_MANDATE_WIRE = {
155
+ ...defaults,
156
+ accountId: 1906,
157
+ baseEndpoint: "https://consent-manager.mandatewire.com",
158
+ propertyId: 35490,
159
+ _clientOptions: {
160
+ rootDomain: "mandatewire.com"
161
+ }
162
+ };
163
+ const properties = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
164
+ __proto__: null,
165
+ FT_DOTCOM_PROD,
166
+ FT_DOTCOM_TEST,
167
+ MM_IGNITES_ASIA,
168
+ MM_IGNITES_EUROPE,
169
+ SP_BANKING_RR,
170
+ SP_FDI_INTELLIGENCE,
171
+ SP_FT_ADVISER,
172
+ SP_INVESTORS_CHRONICLE,
173
+ SP_MANDATE_WIRE,
174
+ SP_PWMNET,
175
+ SP_SUSTAINABLE_VIEWS,
176
+ SP_THE_BANKER
177
+ }, Symbol.toStringTag, { value: "Module" }));
178
+ function findAndUpdateLinks(fallback, regionId, regionApplies, regionConfig, linkMap, manageCookiesLinkOverride) {
179
+ const { text, onClick } = regionConfig[regionId];
180
+ const anchors = document.querySelectorAll(`a[href*="${manageCookiesLinkOverride}"]`);
181
+ for (const anchor of anchors) {
182
+ if (regionApplies || fallback) {
183
+ if (linkMap.has(anchor)) {
184
+ anchor.removeEventListener("click", linkMap.get(anchor));
185
+ }
186
+ anchor.innerText = text;
187
+ anchor.addEventListener("click", onClick);
188
+ linkMap.set(anchor, onClick);
189
+ }
190
+ }
191
+ }
192
+ function interceptManageCookiesLinks({ _clientOptions } = FT_DOTCOM_PROD) {
193
+ const {
194
+ privacyManagerId,
195
+ ccpaPrivacyManagerId,
196
+ usnatPrivacyManagerId,
197
+ manageCookiesLinkOverride
198
+ } = _clientOptions ?? FT_DOTCOM_PROD._clientOptions;
199
+ const regionConfig = {
200
+ usnat: {
201
+ text: "Do not sell my data",
202
+ onClick: (e) => {
203
+ var _a;
204
+ e.preventDefault();
205
+ (_a = window._sp_["usnat"]) == null ? void 0 : _a.loadPrivacyManagerModal(usnatPrivacyManagerId);
206
+ }
207
+ },
208
+ ccpa: {
209
+ text: "Do not sell my data",
210
+ onClick: (e) => {
211
+ var _a;
212
+ e.preventDefault();
213
+ (_a = window._sp_["ccpa"]) == null ? void 0 : _a.loadPrivacyManagerModal(ccpaPrivacyManagerId);
214
+ }
215
+ },
216
+ gdpr: {
217
+ text: "Manage Cookies",
218
+ onClick: (e) => {
219
+ var _a;
220
+ e.preventDefault();
221
+ (_a = window._sp_["gdpr"]) == null ? void 0 : _a.loadPrivacyManagerModal(privacyManagerId);
222
+ }
223
+ }
224
+ };
225
+ const linkMap = /* @__PURE__ */ new Map();
226
+ const onConsentReadyHandler = function(message_type, _uuid, _string, info) {
227
+ findAndUpdateLinks(
228
+ false,
229
+ message_type,
230
+ info.applies,
231
+ regionConfig,
232
+ linkMap,
233
+ manageCookiesLinkOverride
234
+ );
235
+ if (info.applies) {
236
+ window._sp_queue.push(() => {
237
+ var _a, _b;
238
+ (_b = (_a = window._sp_).removeEventListener) == null ? void 0 : _b.call(_a, "onConsentReady", onConsentReadyHandler);
239
+ });
240
+ }
241
+ };
242
+ findAndUpdateLinks(true, "gdpr", false, regionConfig, linkMap, manageCookiesLinkOverride);
243
+ window._sp_queue ?? (window._sp_queue = []);
244
+ window._sp_queue.push(() => {
245
+ var _a, _b;
246
+ (_b = (_a = window._sp_).addEventListener) == null ? void 0 : _b.call(_a, "onConsentReady", onConsentReadyHandler);
247
+ });
248
+ }
249
+ const request = (url, { credentials = "omit" } = {}) => {
250
+ return fetch(`https://session-next.ft.com${url}`, {
251
+ credentials,
252
+ useCorsProxy: true
253
+ }).then((response) => {
254
+ if (response.ok) {
255
+ return response.json();
256
+ } else {
257
+ return response.text().then((text) => {
258
+ throw new Error(`Next session responded with "${text}" (${response.status})`);
259
+ });
260
+ }
261
+ }).catch((err) => {
262
+ document.body.dispatchEvent(new CustomEvent("oErrors.log", {
263
+ bubbles: true,
264
+ detail: {
265
+ error: err,
266
+ info: {
267
+ component: "next-session-client"
268
+ }
269
+ }
270
+ }));
271
+ });
272
+ };
273
+ let detailsCache = {};
274
+ const cache = (name, value) => {
275
+ if (typeof name === "object") {
276
+ detailsCache = name;
277
+ return;
278
+ }
279
+ if (typeof name === "string" && typeof value === "string") {
280
+ detailsCache[name] = value;
281
+ return;
282
+ }
283
+ if (typeof name === "string" && typeof value === "undefined") {
284
+ return detailsCache[name] || null;
285
+ }
286
+ if (typeof name === "undefined" && typeof value === "undefined") {
287
+ return detailsCache;
288
+ }
289
+ throw new Error("Invalid arguments");
290
+ };
291
+ cache.clear = () => {
292
+ detailsCache = {};
293
+ };
294
+ const requests = {};
295
+ const getSessionId = () => {
296
+ const [, sessionId] = /FTSession_s=([^;]+)/.exec(document.cookie) || [];
297
+ return sessionId;
298
+ };
299
+ const getUuid = () => {
300
+ const cachedUUID = cache("uuid");
301
+ if (cachedUUID) {
302
+ return Promise.resolve({ uuid: cachedUUID });
303
+ }
304
+ const sessionId = getSessionId();
305
+ if (!sessionId) {
306
+ return Promise.resolve({ uuid: void 0 });
307
+ }
308
+ if (!requests.uuid) {
309
+ requests.uuid = request(`/sessions/s/${sessionId}`).then(({ uuid } = {}) => {
310
+ delete requests.uuid;
311
+ if (uuid) {
312
+ cache("uuid", uuid);
313
+ }
314
+ return { uuid };
315
+ });
316
+ }
317
+ return requests.uuid;
318
+ };
319
+ const SOURCEPOINT_CONSENT_SOURCE = "sourcepoint-cmp";
320
+ const SOURCEPOINT_FOW_SCOPE = "FTPINK";
321
+ const CONSENT_COOKIE_NAME = "FTConsent";
322
+ const SOURCEPOINT_FOW_ID = "sourcepointCmp/VngD.XycZut.595cp9fWdp5XYP9vlFvk";
323
+ const FT_COOKIE_DOMAIN = ".ft.com";
324
+ const FT_CONSENT_PROXY_HOST = "https://consent.ft.com";
325
+ const iabCustomCategories = {
326
+ permutiveAds: {
327
+ purposes: [2, 4, 8, 9],
328
+ iabVendors: [361],
329
+ customVendors: [],
330
+ specialFeatures: []
331
+ },
332
+ demographicAds: {
333
+ purposes: [7, 9, 10],
334
+ iabVendors: [],
335
+ customVendors: [],
336
+ specialFeatures: []
337
+ },
338
+ behaviouralAds: {
339
+ purposes: [2, 4, 8, 9],
340
+ iabVendors: [],
341
+ customVendors: [],
342
+ specialFeatures: []
343
+ },
344
+ programmaticAds: {
345
+ purposes: [2],
346
+ iabVendors: [],
347
+ customVendors: [],
348
+ specialFeatures: []
349
+ },
350
+ personalisedMarketing: {
351
+ purposes: [2, 7, 8, 9, 10],
352
+ iabVendors: [],
353
+ customVendors: [],
354
+ specialFeatures: []
355
+ }
356
+ };
357
+ const iabCategoryNames = Object.keys(iabCustomCategories);
358
+ function createContentScript(cmpScript, content) {
359
+ const s = document.createElement("script");
360
+ s.dataset.cmpScript = cmpScript;
361
+ s.innerHTML = content;
362
+ return s;
363
+ }
364
+ function createSourceScript(src) {
365
+ const s = document.createElement("script");
366
+ s.src = src;
367
+ return s;
368
+ }
369
+ const scriptSources = {
370
+ cmpFrames: "https://consent-manager.ft.com/unified/wrapperMessagingWithoutDetection.js"
371
+ };
372
+ const scriptContent = {
373
+ 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()}();`,
374
+ 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"));
375
+ `
376
+ };
377
+ function getCmpScripts(options) {
378
+ const fragment = document.createDocumentFragment();
379
+ fragment.appendChild(createContentScript("tcf", scriptContent.tcfStub));
380
+ if (options.includeUsNat) {
381
+ fragment.appendChild(createContentScript("gpp", scriptContent.gppStub));
382
+ }
383
+ fragment.appendChild(createSourceScript(scriptSources.cmpFrames));
384
+ return fragment;
385
+ }
386
+ function applyOptionsToConfig(propertyConfig, options) {
387
+ const { userId, includeUsNat } = options;
388
+ if (userId) {
389
+ propertyConfig.authId = userId;
390
+ }
391
+ if (includeUsNat) {
392
+ propertyConfig.usnat = propertyConfig.usnat || {};
393
+ }
394
+ return propertyConfig;
395
+ }
396
+ function bootstrapCmp(config, options) {
397
+ const { _clientOptions, ...spConfig } = config;
398
+ const runtimeConfig = applyOptionsToConfig(spConfig, options);
399
+ window._sp_ = { config: runtimeConfig };
400
+ window._sp_queue ?? (window._sp_queue = []);
401
+ document.head.appendChild(getCmpScripts(options));
402
+ }
403
+ function getConsentPayload(parsedConsent, updateConsentStore, { formOfWordsId, cookieDomain }) {
404
+ const categoryNames = Object.keys(parsedConsent);
405
+ const data = categoryNames.reduce(
406
+ (payload, categoryName) => {
407
+ payload[categoryName] = {
408
+ onsite: {
409
+ status: parsedConsent[categoryName],
410
+ lbi: false,
411
+ source: SOURCEPOINT_CONSENT_SOURCE,
412
+ fow: formOfWordsId
413
+ }
414
+ };
415
+ return payload;
416
+ },
417
+ {}
418
+ );
419
+ if (updateConsentStore) {
420
+ return {
421
+ setConsentCookie: true,
422
+ formOfWordsId,
423
+ consentSource: SOURCEPOINT_CONSENT_SOURCE,
424
+ cookieDomain,
425
+ data
426
+ };
427
+ }
428
+ return { data, cookieDomain };
429
+ }
430
+ const sections = {
431
+ CALIFORNIA: "uscav1",
432
+ US_NATIONAL: "usnatv1"
433
+ };
434
+ const sectionConfig = {
435
+ [sections.CALIFORNIA]: {
436
+ excludedCategories: {
437
+ personalisedMarketing: true
438
+ }
439
+ },
440
+ [sections.US_NATIONAL]: {
441
+ excludedCategories: {
442
+ personalisedMarketing: true
443
+ }
444
+ }
445
+ };
446
+ function getApplicableSection(gppData) {
447
+ const { applicableSections, supportedAPIs } = gppData;
448
+ const applicableSection = applicableSections[0];
449
+ if (applicableSection === -1 || typeof applicableSection === "undefined") {
450
+ return;
451
+ }
452
+ const sectionApi = supportedAPIs.find((api) => api.startsWith(`${applicableSection}:`));
453
+ const sectionKey = sectionApi == null ? void 0 : sectionApi.split(":")[1];
454
+ return sectionKey;
455
+ }
456
+ function parseCaliforniaSection(sectionData) {
457
+ const { SaleOptOut, SharingOptOut, Gpc } = sectionData;
458
+ const { excludedCategories } = sectionConfig[sections.CALIFORNIA];
459
+ const userHasNotOptedOut = SaleOptOut !== 1 && SharingOptOut !== 1 && !Gpc;
460
+ const parsedConsent = {};
461
+ for (const categoryName of iabCategoryNames) {
462
+ if (categoryName in excludedCategories) {
463
+ parsedConsent[categoryName] = true;
464
+ continue;
465
+ }
466
+ parsedConsent[categoryName] = userHasNotOptedOut;
467
+ }
468
+ return parsedConsent;
469
+ }
470
+ function parseUsNationalSection(sectionData) {
471
+ const { SaleOptOut, SharingOptOut, TargetedAdvertisingOptOut } = sectionData;
472
+ const { excludedCategories } = sectionConfig[sections.US_NATIONAL];
473
+ const userHasNotOptedOut = SaleOptOut !== 1 && SharingOptOut !== 1 && TargetedAdvertisingOptOut !== 1;
474
+ const parsedConsent = {};
475
+ for (const categoryName of iabCategoryNames) {
476
+ if (categoryName in excludedCategories) {
477
+ parsedConsent[categoryName] = true;
478
+ continue;
479
+ }
480
+ parsedConsent[categoryName] = userHasNotOptedOut;
481
+ }
482
+ return parsedConsent;
483
+ }
484
+ const sectionParsers = {
485
+ [sections.CALIFORNIA]: parseCaliforniaSection,
486
+ [sections.US_NATIONAL]: parseUsNationalSection
487
+ };
488
+ async function parseGPPConsent() {
489
+ const gppData = await new Promise((resolve, reject) => {
490
+ try {
491
+ if (window.__gpp) {
492
+ window.__gpp("ping", resolve);
493
+ } else {
494
+ reject(new Error("GPP API is not available on page"));
495
+ }
496
+ } catch (error) {
497
+ reject(error);
498
+ }
499
+ });
500
+ const { parsedSections } = gppData;
501
+ const applicableSection = getApplicableSection(gppData);
502
+ if (!applicableSection || !parsedSections[applicableSection]) {
503
+ throw new Error("GPP parser was called without an applicable section");
504
+ }
505
+ const sectionData = parsedSections[applicableSection];
506
+ const parseSection = sectionParsers[applicableSection];
507
+ if (!parseSection || typeof parseSection !== "function") {
508
+ throw new Error(`No parser found for applicable GPP section: ${applicableSection}`);
509
+ }
510
+ const parsedConsent = parseSection(sectionData);
511
+ return parsedConsent;
512
+ }
513
+ function checkConsentFor(categoryName, { purpose, vendor, specialFeatureOptins }) {
514
+ const customCategory = iabCustomCategories[categoryName];
515
+ const requiredPurposesConsented = customCategory.purposes.every(
516
+ (requiredPurpose) => (purpose == null ? void 0 : purpose.consents[requiredPurpose]) || (purpose == null ? void 0 : purpose.legitimateInterests[requiredPurpose])
517
+ );
518
+ const requiredIabVendorsConsented = customCategory.iabVendors.every(
519
+ (requiredVendor) => (vendor == null ? void 0 : vendor.consents[requiredVendor]) || (vendor == null ? void 0 : vendor.legitimateInterests[requiredVendor])
520
+ );
521
+ const requiredSpecialFeaturesConsented = customCategory.specialFeatures.every(
522
+ (requiredFeature) => (specialFeatureOptins == null ? void 0 : specialFeatureOptins[requiredFeature]) === true
523
+ );
524
+ return requiredPurposesConsented && requiredIabVendorsConsented && requiredSpecialFeaturesConsented;
525
+ }
526
+ async function parseGDPRConsent() {
527
+ const tcData = await new Promise((resolve, reject) => {
528
+ try {
529
+ if (window.__tcfapi) {
530
+ window.__tcfapi("addEventListener", 2, resolve);
531
+ } else {
532
+ reject(new Error("TCF API is not available on page"));
533
+ }
534
+ } catch (error) {
535
+ reject(error);
536
+ }
537
+ });
538
+ const parsedConsent = {};
539
+ for (const categoryName of iabCategoryNames) {
540
+ parsedConsent[categoryName] = checkConsentFor(categoryName, tcData);
541
+ }
542
+ return parsedConsent;
543
+ }
544
+ async function getParsedConsent(activeLegislation) {
545
+ const legislationParsers = {
546
+ gdpr: parseGDPRConsent,
547
+ usnat: parseGPPConsent
548
+ };
549
+ const consentParser = legislationParsers[activeLegislation];
550
+ if (!consentParser) {
551
+ throw new Error("Unable to update user consent. Unsupported consent legislation.");
552
+ }
553
+ return consentParser();
554
+ }
555
+ function getConsentCookieValue() {
556
+ const cookies = Object.fromEntries(
557
+ document.cookie.split("; ").map((cookie) => cookie.split("="))
558
+ );
559
+ const encodedValue = cookies[CONSENT_COOKIE_NAME];
560
+ if (!encodedValue)
561
+ return {};
562
+ const decodedValue = decodeURIComponent(encodedValue);
563
+ return Object.fromEntries(
564
+ decodedValue.split(",").map((consent) => {
565
+ const [category, value] = consent.split(":");
566
+ const booleanConsent = [category, value === "on" ? true : false];
567
+ return booleanConsent;
568
+ })
569
+ );
570
+ }
571
+ function hasConsentChanged(parsedConsent, previousConsent) {
572
+ const categories = Object.keys(parsedConsent);
573
+ return categories.some((category) => {
574
+ const adaptedCategoryName = `${category.toLowerCase()}Onsite`;
575
+ return parsedConsent[category] !== previousConsent[adaptedCategoryName];
576
+ });
577
+ }
578
+ function shouldUpdateConsentStore({ userId, useConsentStore }) {
579
+ return !!userId && useConsentStore === true;
580
+ }
581
+ function getConsentEndpoint(updateConsentStore, props) {
582
+ if (updateConsentStore) {
583
+ return `${props.consentProxyHost}/__consent/consent-record/${SOURCEPOINT_FOW_SCOPE}/${props.userId}`;
584
+ }
585
+ return `${props.consentProxyHost}/__consent/consent-record-cookie?cookieDomain=${props.cookieDomain}`;
586
+ }
587
+ async function saveConsent(consentEndpoint, payload) {
588
+ try {
589
+ const response = await fetch(consentEndpoint, {
590
+ method: "POST",
591
+ headers: {
592
+ "Content-Type": "application/json"
593
+ },
594
+ body: JSON.stringify(payload),
595
+ credentials: "include"
596
+ });
597
+ if (!response.ok) {
598
+ console.error("Unable to save consent preferences", response.status);
599
+ }
600
+ } catch (error) {
601
+ console.error("An error occurred while saving consent", error);
602
+ }
603
+ }
604
+ function consentReadyHandlerFn(props) {
605
+ return async function consentReadyHandler(legislation, _consentUUID, consentString, consentMeta) {
606
+ if (props.disableFTCookies) {
607
+ return;
608
+ }
609
+ if (!props.includeUsNat && legislation === "usnat") {
610
+ return;
611
+ }
612
+ const activeLegislation = consentMeta.applies ? legislation : "gdpr";
613
+ if (activeLegislation !== legislation || !consentString) {
614
+ return;
615
+ }
616
+ let parsedConsent;
617
+ try {
618
+ parsedConsent = await getParsedConsent(activeLegislation);
619
+ } catch (error) {
620
+ console.error(error);
621
+ }
622
+ if (!parsedConsent) {
623
+ return;
624
+ }
625
+ const consentHasChanged = hasConsentChanged(parsedConsent, getConsentCookieValue());
626
+ if (!consentHasChanged) {
627
+ return;
628
+ }
629
+ const updateConsentStore = shouldUpdateConsentStore(props);
630
+ const consentEndpoint = getConsentEndpoint(updateConsentStore, props);
631
+ const payload = getConsentPayload(parsedConsent, updateConsentStore, props);
632
+ await saveConsent(consentEndpoint, payload);
633
+ document.dispatchEvent(new CustomEvent("oCookieMessage.act", { bubbles: true }));
634
+ };
635
+ }
636
+ const COOKIE_MESSAGE = "cookie-message";
637
+ const PRIVACY_MANAGER = "manage-cookies";
638
+ const INITIAL_STATE = Object.freeze({
639
+ activeComponent: COOKIE_MESSAGE,
640
+ messageId: 0,
641
+ privacyManagerId: 0
642
+ });
643
+ let privateState = INITIAL_STATE;
644
+ function isPlainObject(obj) {
645
+ return typeof obj === "object" && obj !== null && obj.constructor === Object && Object.prototype.toString.call(obj) === "[object Object]";
646
+ }
647
+ const getState = () => ({ ...privateState });
648
+ const setState = (newState) => {
649
+ if (!isPlainObject(newState)) {
650
+ console.error("Invalid state changes");
651
+ return;
652
+ }
653
+ privateState = { ...privateState, ...newState };
654
+ };
655
+ const cookieToggleFlags = ["adsDisableInternalCMP", "pwm.cmp", "messageSlotBottom"];
656
+ function initTracking(context, cmpBaseEndpoint) {
657
+ const flags = extractRelevantFlags(context.flags);
658
+ window._sp_queue = window._sp_queue ?? [];
659
+ window._sp_queue.push(() => {
660
+ var _a, _b;
661
+ for (const [eventId, eventHandler] of Object.entries(trackingEventHandlers)) {
662
+ (_b = (_a = window._sp_).addEventListener) == null ? void 0 : _b.call(_a, eventId, eventHandler({ ...context, flags }));
663
+ }
664
+ });
665
+ setupPmTracking({ ...context, flags }, cmpBaseEndpoint);
666
+ }
667
+ function extractRelevantFlags(flags) {
668
+ const output = {};
669
+ if (typeof flags === "object") {
670
+ cookieToggleFlags.forEach((flagName) => {
671
+ if (Object.prototype.hasOwnProperty.call(flags, flagName)) {
672
+ output[flagName] = flags[flagName];
673
+ }
674
+ });
675
+ }
676
+ return output;
677
+ }
678
+ function track(payload) {
679
+ if (!payload)
680
+ return;
681
+ const rootEl = document.body;
682
+ const event = new CustomEvent("oTracking.event", {
683
+ bubbles: true,
684
+ cancelable: true,
685
+ detail: payload.detail
686
+ });
687
+ rootEl.dispatchEvent(event);
688
+ }
689
+ function dispatchComponentEvent({
690
+ trackingProps,
691
+ action,
692
+ triggerAction
693
+ }) {
694
+ let componentId;
695
+ const state = getState();
696
+ const { product, app, flags } = trackingProps;
697
+ if (state.activeComponent === COOKIE_MESSAGE) {
698
+ componentId = state.messageId;
699
+ } else {
700
+ componentId = state.privacyManagerId;
701
+ }
702
+ const event = {
703
+ detail: {
704
+ component: {
705
+ id: componentId,
706
+ name: state.activeComponent,
707
+ type: "overlay",
708
+ subtype: "cmp"
709
+ },
710
+ category: "component",
711
+ action,
712
+ ...triggerAction && { trigger_action: triggerAction },
713
+ ...product && { product },
714
+ ...app && { app },
715
+ custom: [
716
+ {
717
+ cookie_toggle_flag: flags
718
+ }
719
+ ],
720
+ url: window.document.location.href || null
721
+ }
722
+ };
723
+ track(event);
724
+ }
725
+ const trackingEventHandlers = {
726
+ onMessageChoiceSelect: (trackingProps) => (_messageType, _choiceId, choiceTypeId) => {
727
+ const choiceTypeTriggerMap = {
728
+ 11: "accept_all",
729
+ 12: "manage_cookies",
730
+ 13: "reject_all"
731
+ };
732
+ const triggerAction = choiceTypeTriggerMap[choiceTypeId];
733
+ if (triggerAction) {
734
+ dispatchComponentEvent({
735
+ trackingProps,
736
+ action: "click",
737
+ triggerAction
738
+ });
739
+ }
740
+ },
741
+ onMessageReady: (trackingProps) => () => {
742
+ dispatchComponentEvent({
743
+ trackingProps,
744
+ action: "view"
745
+ });
746
+ },
747
+ onMessageReceiveData: () => (_messageType, data) => {
748
+ const { messageId } = data;
749
+ if (messageId) {
750
+ setState({
751
+ messageId
752
+ });
753
+ }
754
+ },
755
+ onError: (trackingProps) => (_messageType, errorCode) => {
756
+ dispatchComponentEvent({
757
+ trackingProps,
758
+ action: "error",
759
+ triggerAction: errorCode
760
+ });
761
+ },
762
+ onPMCancel: () => () => {
763
+ setState({
764
+ activeComponent: COOKIE_MESSAGE
765
+ });
766
+ }
767
+ };
768
+ function setupPmTracking(trackingProps, cmpBaseEndpoint) {
769
+ window.addEventListener(
770
+ "message",
771
+ function(event) {
772
+ if (event.origin !== cmpBaseEndpoint)
773
+ return;
774
+ const actionTypeMap = {
775
+ 1: "save_and_close",
776
+ 11: "accept_all",
777
+ 13: "reject_all"
778
+ };
779
+ const { data: { fromPM, actionType, messageId = "0" } = {} } = event;
780
+ if (!fromPM)
781
+ return;
782
+ if (+messageId) {
783
+ setState({
784
+ activeComponent: PRIVACY_MANAGER,
785
+ privacyManagerId: +messageId
786
+ });
787
+ }
788
+ if (!actionType || !actionTypeMap[actionType])
789
+ return;
790
+ dispatchComponentEvent({
791
+ trackingProps,
792
+ action: "click",
793
+ triggerAction: actionTypeMap[actionType]
794
+ });
795
+ },
796
+ false
797
+ );
798
+ }
799
+ const version = "0.0.0-backup.1";
800
+ async function initSourcepointCmp(options) {
801
+ const {
802
+ useFTSession = true,
803
+ consentProxyHost = FT_CONSENT_PROXY_HOST,
804
+ cookieDomain = FT_COOKIE_DOMAIN,
805
+ formOfWordsId = SOURCEPOINT_FOW_ID,
806
+ useConsentStore = true,
807
+ trackingContext = {},
808
+ disableFTCookies = false,
809
+ includeUsNat = false
810
+ } = options || {};
811
+ let { propertyConfig = FT_DOTCOM_PROD, userId } = options || {};
812
+ if (typeof window === "undefined") {
813
+ console.error("The CMP client can only be initialised in a browser context");
814
+ return;
815
+ }
816
+ window.FT_CMP_CLIENT_VERSION = version;
817
+ if (!userId && useFTSession) {
818
+ try {
819
+ const response = await getUuid();
820
+ userId = response == null ? void 0 : response.uuid;
821
+ } catch (error) {
822
+ console.error(error);
823
+ }
824
+ }
825
+ propertyConfig = validateAndCleanConfig(propertyConfig);
826
+ bootstrapCmp(propertyConfig, { userId, includeUsNat });
827
+ window._sp_queue.push(() => {
828
+ var _a, _b;
829
+ (_b = (_a = window._sp_) == null ? void 0 : _a.addEventListener) == null ? void 0 : _b.call(
830
+ _a,
831
+ "onConsentReady",
832
+ consentReadyHandlerFn({
833
+ userId,
834
+ consentProxyHost,
835
+ cookieDomain,
836
+ formOfWordsId,
837
+ useConsentStore,
838
+ disableFTCookies,
839
+ includeUsNat
840
+ })
841
+ );
842
+ });
843
+ initTracking(trackingContext, propertyConfig.baseEndpoint);
844
+ }
845
+ function validateAndCleanConfig(propertyConfig) {
846
+ if (!(propertyConfig == null ? void 0 : propertyConfig.accountId)) {
847
+ throw new Error("Please pass a valid property config");
848
+ }
849
+ if (propertyConfig.events) {
850
+ console.warn(
851
+ "[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"
852
+ );
853
+ delete propertyConfig.events;
854
+ }
855
+ return propertyConfig;
856
+ }
857
+ export {
858
+ debug,
859
+ initSourcepointCmp,
860
+ interceptManageCookiesLinks,
861
+ properties
862
+ };