@financial-times/cmp-client 0.0.0-beta.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.
- package/README.md +195 -0
- package/dist/index.cjs +2993 -0
- package/dist/index.js +2993 -0
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/consent-ready/index.d.ts +5 -0
- package/dist/src/consent-ready/index.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts +9 -0
- package/dist/src/consent-ready/utils/__fixtures__/strings.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/__tests__/check-consent.test.d.ts +2 -0
- package/dist/src/consent-ready/utils/__tests__/check-consent.test.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/__tests__/get-parsed-consent.test.d.ts +2 -0
- package/dist/src/consent-ready/utils/__tests__/get-parsed-consent.test.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts +2 -0
- package/dist/src/consent-ready/utils/__tests__/validators.test.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/get-consent-payload.d.ts +18 -0
- package/dist/src/consent-ready/utils/get-consent-payload.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/get-parsed-consent.d.ts +14 -0
- package/dist/src/consent-ready/utils/get-parsed-consent.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/has-consent-changed.d.ts +3 -0
- package/dist/src/consent-ready/utils/has-consent-changed.d.ts.map +1 -0
- package/dist/src/consent-ready/utils/validators.d.ts +16 -0
- package/dist/src/consent-ready/utils/validators.d.ts.map +1 -0
- package/dist/src/html/__tests__/cmp-footer-links.test.d.ts +2 -0
- package/dist/src/html/__tests__/cmp-footer-links.test.d.ts.map +1 -0
- package/dist/src/html/__tests__/cmp-scripts.test.d.ts +2 -0
- package/dist/src/html/__tests__/cmp-scripts.test.d.ts.map +1 -0
- package/dist/src/html/cmp-footer-link.d.ts +8 -0
- package/dist/src/html/cmp-footer-link.d.ts.map +1 -0
- package/dist/src/html/cmp-scripts.d.ts +7 -0
- package/dist/src/html/cmp-scripts.d.ts.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/constants.d.ts +13 -0
- package/dist/src/lib/constants.d.ts.map +1 -0
- package/dist/src/lib/debug.d.ts +15 -0
- package/dist/src/lib/debug.d.ts.map +1 -0
- package/dist/src/lib/properties.d.ts +94 -0
- package/dist/src/lib/properties.d.ts.map +1 -0
- package/dist/src/utils/dom.d.ts +3 -0
- package/dist/src/utils/dom.d.ts.map +1 -0
- package/package.json +40 -0
- package/typings/globals.d.ts +12 -0
- package/typings/modules.d.ts +1 -0
- package/typings/types.d.ts +98 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2993 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
9
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
const version = "0.0.0-beta.1";
|
|
11
|
+
const events = {
|
|
12
|
+
onMessageChoiceSelect: (...args) => {
|
|
13
|
+
console.log("[debug] onMessageChoiceSelect", args);
|
|
14
|
+
if (choice_type_id == 9) {
|
|
15
|
+
document.cookie = "cw=dismissed; expires=Thu, 18 Dec 2030 12:00:00 UTC";
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
onMessageReady: (...args) => {
|
|
19
|
+
console.log("[debug] onMessageReady", args);
|
|
20
|
+
},
|
|
21
|
+
onMessageChoiceError: (...args) => {
|
|
22
|
+
console.log("[debug] onMessageChoiceError", args);
|
|
23
|
+
},
|
|
24
|
+
onPrivacyManagerAction: (...args) => {
|
|
25
|
+
console.log("[debug] onPrivacyManagerAction", args);
|
|
26
|
+
if (pmData.purposeConsent == "none" && pmData.vendorConsent == "none") {
|
|
27
|
+
document.cookie = "cw=dismissed; expires=Thu, 18 Dec 2030 12:00:00 UTC";
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
onPMCancel: (...args) => {
|
|
31
|
+
console.log("[debug] onPMCancel", args);
|
|
32
|
+
},
|
|
33
|
+
onMessageReceiveData: (...args) => {
|
|
34
|
+
console.log("[debug] onMessageReceiveData", args);
|
|
35
|
+
},
|
|
36
|
+
onSPPMObjectReady: (...args) => {
|
|
37
|
+
console.log("[debug] onSPPMObjectReady", args);
|
|
38
|
+
},
|
|
39
|
+
onConsentReady: async (...args) => {
|
|
40
|
+
const [legislation2, consentUUID, consentString, consentMeta] = args;
|
|
41
|
+
console.log("[debug] onConsentReady", { legislation: legislation2, consentString, consentMeta, consentUUID });
|
|
42
|
+
},
|
|
43
|
+
onError: (...args) => {
|
|
44
|
+
console.log("[debug] onError", args);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function logCmpEvents() {
|
|
48
|
+
window._sp_queue = window._sp_queue ?? [];
|
|
49
|
+
window._sp_queue.push(() => {
|
|
50
|
+
var _a2, _b2;
|
|
51
|
+
for (const [eventId, eventHandler] of Object.entries(events)) {
|
|
52
|
+
(_b2 = (_a2 = window._sp_).addEventListener) == null ? void 0 : _b2.call(_a2, eventId, eventHandler);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const debug = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
57
|
+
__proto__: null,
|
|
58
|
+
events,
|
|
59
|
+
logCmpEvents
|
|
60
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
61
|
+
const defaults = {
|
|
62
|
+
joinHref: true,
|
|
63
|
+
gdpr: {},
|
|
64
|
+
ccpa: {}
|
|
65
|
+
};
|
|
66
|
+
const FT_DOTCOM_TEST = {
|
|
67
|
+
...defaults,
|
|
68
|
+
accountId: 1906,
|
|
69
|
+
baseEndpoint: "https://consent-manager.ft.com",
|
|
70
|
+
propertyHref: "https://local.ft.com"
|
|
71
|
+
};
|
|
72
|
+
const FT_DOTCOM_PROD = {
|
|
73
|
+
...defaults,
|
|
74
|
+
accountId: 1906,
|
|
75
|
+
baseEndpoint: "https://consent-manager.ft.com",
|
|
76
|
+
propertyId: 31642
|
|
77
|
+
};
|
|
78
|
+
const SP_PWMNET = {
|
|
79
|
+
...defaults,
|
|
80
|
+
accountId: 1906,
|
|
81
|
+
baseEndpoint: "https://consent-manager.pwmnet.com",
|
|
82
|
+
propertyId: 33414
|
|
83
|
+
};
|
|
84
|
+
const SP_FDI_INTELLIGENCE = {
|
|
85
|
+
...defaults,
|
|
86
|
+
accountId: 1906,
|
|
87
|
+
baseEndpoint: "https://consent-manager.fdiintelligence.com",
|
|
88
|
+
propertyId: 34061
|
|
89
|
+
};
|
|
90
|
+
const SP_THE_BANKER = {
|
|
91
|
+
...defaults,
|
|
92
|
+
accountId: 1906,
|
|
93
|
+
baseEndpoint: "https://consent-manager.thebanker.com",
|
|
94
|
+
propertyId: 34060
|
|
95
|
+
};
|
|
96
|
+
const SP_BANKING_RR = {
|
|
97
|
+
...defaults,
|
|
98
|
+
accountId: 1906,
|
|
99
|
+
baseEndpoint: "https://consent-manager.bankingriskandregulation.com",
|
|
100
|
+
propertyId: 34059
|
|
101
|
+
};
|
|
102
|
+
const SP_SUSTAINABLE_VIEWS = {
|
|
103
|
+
...defaults,
|
|
104
|
+
accountId: 1906,
|
|
105
|
+
baseEndpoint: "https://consent-manager.sustainableviews.com",
|
|
106
|
+
propertyId: 34058
|
|
107
|
+
};
|
|
108
|
+
const SP_FT_ADVISER = {
|
|
109
|
+
...defaults,
|
|
110
|
+
accountId: 1906,
|
|
111
|
+
baseEndpoint: "https://consent-manager.ftadviser.com",
|
|
112
|
+
propertyId: 33416
|
|
113
|
+
};
|
|
114
|
+
const SP_INVESTORS_CHRONICLE = {
|
|
115
|
+
...defaults,
|
|
116
|
+
accountId: 1906,
|
|
117
|
+
baseEndpoint: "https://consent-manager.investorschronicle.co.uk",
|
|
118
|
+
propertyId: 33415
|
|
119
|
+
};
|
|
120
|
+
const MM_IGNITES_ASIA = {
|
|
121
|
+
...defaults,
|
|
122
|
+
accountId: 1906,
|
|
123
|
+
baseEndpoint: "https://cdn.privacy-mgmt.com",
|
|
124
|
+
propertyId: 33947
|
|
125
|
+
};
|
|
126
|
+
const MM_IGNITES_EUROPE = {
|
|
127
|
+
...defaults,
|
|
128
|
+
accountId: 1906,
|
|
129
|
+
baseEndpoint: "https://cdn.privacy-mgmt.com",
|
|
130
|
+
propertyId: 33946
|
|
131
|
+
};
|
|
132
|
+
const properties = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
133
|
+
__proto__: null,
|
|
134
|
+
FT_DOTCOM_PROD,
|
|
135
|
+
FT_DOTCOM_TEST,
|
|
136
|
+
MM_IGNITES_ASIA,
|
|
137
|
+
MM_IGNITES_EUROPE,
|
|
138
|
+
SP_BANKING_RR,
|
|
139
|
+
SP_FDI_INTELLIGENCE,
|
|
140
|
+
SP_FT_ADVISER,
|
|
141
|
+
SP_INVESTORS_CHRONICLE,
|
|
142
|
+
SP_PWMNET,
|
|
143
|
+
SP_SUSTAINABLE_VIEWS,
|
|
144
|
+
SP_THE_BANKER
|
|
145
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
146
|
+
function updateFooterLinkCMP() {
|
|
147
|
+
const cookieLink = document.querySelector(
|
|
148
|
+
"[href='https://www.ft.com/preferences/manage-cookies']"
|
|
149
|
+
);
|
|
150
|
+
if (cookieLink) {
|
|
151
|
+
cookieLink.href = "#";
|
|
152
|
+
cookieLink.setAttribute("onclick", "window._sp_.gdpr.loadPrivacyManagerModal(943254);");
|
|
153
|
+
cookieLink.dataset.cmpLink = "updated";
|
|
154
|
+
return true;
|
|
155
|
+
} else {
|
|
156
|
+
console.warn("CMP Footer Link was not found and not updated");
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const request = (url, { credentials = "omit" } = {}) => {
|
|
161
|
+
return fetch(`https://session-next.ft.com${url}`, {
|
|
162
|
+
credentials,
|
|
163
|
+
useCorsProxy: true
|
|
164
|
+
}).then((response) => {
|
|
165
|
+
if (response.ok) {
|
|
166
|
+
return response.json();
|
|
167
|
+
} else {
|
|
168
|
+
return response.text().then((text) => {
|
|
169
|
+
throw new Error(`Next session responded with "${text}" (${response.status})`);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}).catch((err) => {
|
|
173
|
+
document.body.dispatchEvent(new CustomEvent("oErrors.log", {
|
|
174
|
+
bubbles: true,
|
|
175
|
+
detail: {
|
|
176
|
+
error: err,
|
|
177
|
+
info: {
|
|
178
|
+
component: "next-session-client"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}));
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
let detailsCache = {};
|
|
185
|
+
const cache = (name, value) => {
|
|
186
|
+
if (typeof name === "object") {
|
|
187
|
+
detailsCache = name;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (typeof name === "string" && typeof value === "string") {
|
|
191
|
+
detailsCache[name] = value;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (typeof name === "string" && typeof value === "undefined") {
|
|
195
|
+
return detailsCache[name] || null;
|
|
196
|
+
}
|
|
197
|
+
if (typeof name === "undefined" && typeof value === "undefined") {
|
|
198
|
+
return detailsCache;
|
|
199
|
+
}
|
|
200
|
+
throw new Error("Invalid arguments");
|
|
201
|
+
};
|
|
202
|
+
cache.clear = () => {
|
|
203
|
+
detailsCache = {};
|
|
204
|
+
};
|
|
205
|
+
const requests = {};
|
|
206
|
+
const getSessionId = () => {
|
|
207
|
+
const [, sessionId] = /FTSession_s=([^;]+)/.exec(document.cookie) || [];
|
|
208
|
+
return sessionId;
|
|
209
|
+
};
|
|
210
|
+
const getUuid = () => {
|
|
211
|
+
const cachedUUID = cache("uuid");
|
|
212
|
+
if (cachedUUID) {
|
|
213
|
+
return Promise.resolve({ uuid: cachedUUID });
|
|
214
|
+
}
|
|
215
|
+
const sessionId = getSessionId();
|
|
216
|
+
if (!sessionId) {
|
|
217
|
+
return Promise.resolve({ uuid: void 0 });
|
|
218
|
+
}
|
|
219
|
+
if (!requests.uuid) {
|
|
220
|
+
requests.uuid = request(`/sessions/s/${sessionId}`).then(({ uuid } = {}) => {
|
|
221
|
+
delete requests.uuid;
|
|
222
|
+
if (uuid) {
|
|
223
|
+
cache("uuid", uuid);
|
|
224
|
+
}
|
|
225
|
+
return { uuid };
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return requests.uuid;
|
|
229
|
+
};
|
|
230
|
+
const SOURCEPOINT_CONSENT_SOURCE = "sourcepoint-cmp";
|
|
231
|
+
const SOURCEPOINT_FOW_SCOPE = "FTPINK";
|
|
232
|
+
const CONSENT_COOKIE_NAME = "FTConsent";
|
|
233
|
+
const SOURCEPOINT_FOW_ID = "sourcepointCmp/VngD.XycZut.595cp9fWdp5XYP9vlFvk";
|
|
234
|
+
const FT_COOKIE_DOMAIN = ".ft.com";
|
|
235
|
+
const FT_CONSENT_PROXY_HOST = "https://consent.ft.com";
|
|
236
|
+
const legislation = {
|
|
237
|
+
CCPA: "ccpa",
|
|
238
|
+
GDPR: "gdpr"
|
|
239
|
+
};
|
|
240
|
+
const iabCustomCategories = {
|
|
241
|
+
permutiveAds: {
|
|
242
|
+
purposes: [2, 4, 8, 9],
|
|
243
|
+
iabVendors: [361],
|
|
244
|
+
customVendors: [],
|
|
245
|
+
specialFeatures: []
|
|
246
|
+
},
|
|
247
|
+
demographicAds: {
|
|
248
|
+
purposes: [3, 4, 7, 9, 10],
|
|
249
|
+
iabVendors: [],
|
|
250
|
+
customVendors: [],
|
|
251
|
+
specialFeatures: []
|
|
252
|
+
},
|
|
253
|
+
behaviouralAds: {
|
|
254
|
+
purposes: [2, 4, 8, 9],
|
|
255
|
+
iabVendors: [],
|
|
256
|
+
customVendors: [],
|
|
257
|
+
specialFeatures: []
|
|
258
|
+
},
|
|
259
|
+
personalisedMarketing: {
|
|
260
|
+
purposes: [1, 4, 8, 9, 10],
|
|
261
|
+
iabVendors: [],
|
|
262
|
+
customVendors: [],
|
|
263
|
+
specialFeatures: []
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
function createContentScript(cmpScript, content) {
|
|
267
|
+
const s = document.createElement("script");
|
|
268
|
+
s.dataset.cmpScript = cmpScript;
|
|
269
|
+
s.innerHTML = content;
|
|
270
|
+
return s;
|
|
271
|
+
}
|
|
272
|
+
function createSourceScript(src) {
|
|
273
|
+
const s = document.createElement("script");
|
|
274
|
+
s.src = src;
|
|
275
|
+
return s;
|
|
276
|
+
}
|
|
277
|
+
const scriptSources = {
|
|
278
|
+
cmpFrames: "https://consent-manager.ft.com/unified/wrapperMessagingWithoutDetection.js"
|
|
279
|
+
};
|
|
280
|
+
const scriptContent = {
|
|
281
|
+
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",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()}();`,
|
|
282
|
+
uspStub: `"use strict";(function () { var e = false; var c = window; var t = document; function r() { if (!c.frames["__uspapiLocator"]) { if (t.body) { var a = t.body; var e = t.createElement("iframe"); e.style.cssText = "display:none"; e.name = "__uspapiLocator"; a.appendChild(e) } else { setTimeout(r, 5) } } } r(); function p() { var a = arguments; __uspapi.a = __uspapi.a || []; if (!a.length) { return __uspapi.a } else if (a[0] === "ping") { a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true) } else { __uspapi.a.push([].slice.apply(a)) } } function l(t) { var r = typeof t.data === "string"; try { var a = r ? JSON.parse(t.data) : t.data; if (a.__cmpCall) { var n = a.__cmpCall; c.__uspapi(n.command, n.parameter, function (a, e) { var c = { __cmpReturn: { returnValue: a, success: e, callId: n.callId } }; t.source.postMessage(r ? JSON.stringify(c) : c, "*") }) } } catch (a) { } } if (typeof __uspapi !== "function") { c.__uspapi = p; __uspapi.msgHandler = l; c.addEventListener("message", l, false) } })();`
|
|
283
|
+
};
|
|
284
|
+
function getCmpScripts() {
|
|
285
|
+
const fragment = document.createDocumentFragment();
|
|
286
|
+
fragment.appendChild(createContentScript("tcf", scriptContent.tcfStub));
|
|
287
|
+
fragment.appendChild(createContentScript("usp", scriptContent.uspStub));
|
|
288
|
+
fragment.appendChild(createSourceScript(scriptSources.cmpFrames));
|
|
289
|
+
return fragment;
|
|
290
|
+
}
|
|
291
|
+
function bootstrapCmp(config) {
|
|
292
|
+
window._sp_ = { config };
|
|
293
|
+
window._sp_queue ?? (window._sp_queue = []);
|
|
294
|
+
document.head.appendChild(getCmpScripts());
|
|
295
|
+
}
|
|
296
|
+
function getConsentPayload(parsedConsent, { shouldUpdateConsentStore, formOfWordsId, cookieDomain }) {
|
|
297
|
+
const categoryNames = Object.keys(parsedConsent);
|
|
298
|
+
const data = categoryNames.reduce(
|
|
299
|
+
(payload, categoryName) => {
|
|
300
|
+
payload[categoryName] = {
|
|
301
|
+
onsite: {
|
|
302
|
+
status: parsedConsent[categoryName],
|
|
303
|
+
lbi: false,
|
|
304
|
+
source: SOURCEPOINT_CONSENT_SOURCE,
|
|
305
|
+
fow: formOfWordsId
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
return payload;
|
|
309
|
+
},
|
|
310
|
+
{}
|
|
311
|
+
);
|
|
312
|
+
if (!shouldUpdateConsentStore) {
|
|
313
|
+
return { data, cookieDomain };
|
|
314
|
+
} else {
|
|
315
|
+
return {
|
|
316
|
+
setConsentCookie: true,
|
|
317
|
+
formOfWordsId,
|
|
318
|
+
consentSource: SOURCEPOINT_CONSENT_SOURCE,
|
|
319
|
+
cookieDomain,
|
|
320
|
+
data
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
class DecodingError extends Error {
|
|
325
|
+
/**
|
|
326
|
+
* constructor - constructs an DecodingError
|
|
327
|
+
*
|
|
328
|
+
* @param {string} msg - Decoding Error Message
|
|
329
|
+
* @return {undefined}
|
|
330
|
+
*/
|
|
331
|
+
constructor(msg) {
|
|
332
|
+
super(msg);
|
|
333
|
+
this.name = "DecodingError";
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
class EncodingError extends Error {
|
|
337
|
+
/**
|
|
338
|
+
* constructor - constructs an EncodingError
|
|
339
|
+
*
|
|
340
|
+
* @param {string} msg - Encoding Error Message
|
|
341
|
+
* @return {undefined}
|
|
342
|
+
*/
|
|
343
|
+
constructor(msg) {
|
|
344
|
+
super(msg);
|
|
345
|
+
this.name = "EncodingError";
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
class GVLError extends Error {
|
|
349
|
+
/**
|
|
350
|
+
* constructor - constructs a GVLError
|
|
351
|
+
*
|
|
352
|
+
* @param {string} msg - Error message to display
|
|
353
|
+
* @return {undefined}
|
|
354
|
+
*/
|
|
355
|
+
constructor(msg) {
|
|
356
|
+
super(msg);
|
|
357
|
+
this.name = "GVLError";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
class TCModelError extends Error {
|
|
361
|
+
/**
|
|
362
|
+
* constructor - constructs an TCModelError
|
|
363
|
+
*
|
|
364
|
+
* @param {string} fieldName - the errored field
|
|
365
|
+
* @param {string} passedValue - what was passed
|
|
366
|
+
* @return {undefined}
|
|
367
|
+
*/
|
|
368
|
+
constructor(fieldName, passedValue, msg = "") {
|
|
369
|
+
super(`invalid value ${passedValue} passed for ${fieldName} ${msg}`);
|
|
370
|
+
this.name = "TCModelError";
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
class Base64Url {
|
|
374
|
+
/**
|
|
375
|
+
* encodes an arbitrary-length bitfield string into base64url
|
|
376
|
+
*
|
|
377
|
+
* @static
|
|
378
|
+
* @param {string} str - arbitrary-length bitfield string to be encoded to base64url
|
|
379
|
+
* @return {string} - base64url encoded result
|
|
380
|
+
*/
|
|
381
|
+
static encode(str) {
|
|
382
|
+
if (!/^[0-1]+$/.test(str)) {
|
|
383
|
+
throw new EncodingError("Invalid bitField");
|
|
384
|
+
}
|
|
385
|
+
const padding = str.length % this.LCM;
|
|
386
|
+
str += padding ? "0".repeat(this.LCM - padding) : "";
|
|
387
|
+
let result = "";
|
|
388
|
+
for (let i = 0; i < str.length; i += this.BASIS) {
|
|
389
|
+
result += this.DICT[parseInt(str.substr(i, this.BASIS), 2)];
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* decodes a base64url encoded bitfield string
|
|
395
|
+
*
|
|
396
|
+
* @static
|
|
397
|
+
* @param {string} str - base64url encoded bitfield string to be decoded
|
|
398
|
+
* @return {string} - bitfield string
|
|
399
|
+
*/
|
|
400
|
+
static decode(str) {
|
|
401
|
+
if (!/^[A-Za-z0-9\-_]+$/.test(str)) {
|
|
402
|
+
throw new DecodingError("Invalidly encoded Base64URL string");
|
|
403
|
+
}
|
|
404
|
+
let result = "";
|
|
405
|
+
for (let i = 0; i < str.length; i++) {
|
|
406
|
+
const strBits = this.REVERSE_DICT.get(str[i]).toString(2);
|
|
407
|
+
result += "0".repeat(this.BASIS - strBits.length) + strBits;
|
|
408
|
+
}
|
|
409
|
+
return result;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Base 64 URL character set. Different from standard Base64 char set
|
|
414
|
+
* in that '+' and '/' are replaced with '-' and '_'.
|
|
415
|
+
*/
|
|
416
|
+
__publicField(Base64Url, "DICT", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
|
417
|
+
__publicField(Base64Url, "REVERSE_DICT", /* @__PURE__ */ new Map([
|
|
418
|
+
["A", 0],
|
|
419
|
+
["B", 1],
|
|
420
|
+
["C", 2],
|
|
421
|
+
["D", 3],
|
|
422
|
+
["E", 4],
|
|
423
|
+
["F", 5],
|
|
424
|
+
["G", 6],
|
|
425
|
+
["H", 7],
|
|
426
|
+
["I", 8],
|
|
427
|
+
["J", 9],
|
|
428
|
+
["K", 10],
|
|
429
|
+
["L", 11],
|
|
430
|
+
["M", 12],
|
|
431
|
+
["N", 13],
|
|
432
|
+
["O", 14],
|
|
433
|
+
["P", 15],
|
|
434
|
+
["Q", 16],
|
|
435
|
+
["R", 17],
|
|
436
|
+
["S", 18],
|
|
437
|
+
["T", 19],
|
|
438
|
+
["U", 20],
|
|
439
|
+
["V", 21],
|
|
440
|
+
["W", 22],
|
|
441
|
+
["X", 23],
|
|
442
|
+
["Y", 24],
|
|
443
|
+
["Z", 25],
|
|
444
|
+
["a", 26],
|
|
445
|
+
["b", 27],
|
|
446
|
+
["c", 28],
|
|
447
|
+
["d", 29],
|
|
448
|
+
["e", 30],
|
|
449
|
+
["f", 31],
|
|
450
|
+
["g", 32],
|
|
451
|
+
["h", 33],
|
|
452
|
+
["i", 34],
|
|
453
|
+
["j", 35],
|
|
454
|
+
["k", 36],
|
|
455
|
+
["l", 37],
|
|
456
|
+
["m", 38],
|
|
457
|
+
["n", 39],
|
|
458
|
+
["o", 40],
|
|
459
|
+
["p", 41],
|
|
460
|
+
["q", 42],
|
|
461
|
+
["r", 43],
|
|
462
|
+
["s", 44],
|
|
463
|
+
["t", 45],
|
|
464
|
+
["u", 46],
|
|
465
|
+
["v", 47],
|
|
466
|
+
["w", 48],
|
|
467
|
+
["x", 49],
|
|
468
|
+
["y", 50],
|
|
469
|
+
["z", 51],
|
|
470
|
+
["0", 52],
|
|
471
|
+
["1", 53],
|
|
472
|
+
["2", 54],
|
|
473
|
+
["3", 55],
|
|
474
|
+
["4", 56],
|
|
475
|
+
["5", 57],
|
|
476
|
+
["6", 58],
|
|
477
|
+
["7", 59],
|
|
478
|
+
["8", 60],
|
|
479
|
+
["9", 61],
|
|
480
|
+
["-", 62],
|
|
481
|
+
["_", 63]
|
|
482
|
+
]));
|
|
483
|
+
/**
|
|
484
|
+
* log2(64) = 6
|
|
485
|
+
*/
|
|
486
|
+
__publicField(Base64Url, "BASIS", 6);
|
|
487
|
+
__publicField(Base64Url, "LCM", 24);
|
|
488
|
+
const _ConsentLanguages = class _ConsentLanguages {
|
|
489
|
+
has(key) {
|
|
490
|
+
return _ConsentLanguages.langSet.has(key);
|
|
491
|
+
}
|
|
492
|
+
parseLanguage(lang) {
|
|
493
|
+
lang = lang.toUpperCase();
|
|
494
|
+
const primaryLanguage = lang.split("-")[0];
|
|
495
|
+
if (lang.length >= 2 && primaryLanguage.length == 2) {
|
|
496
|
+
if (_ConsentLanguages.langSet.has(lang)) {
|
|
497
|
+
return lang;
|
|
498
|
+
} else if (_ConsentLanguages.langSet.has(primaryLanguage)) {
|
|
499
|
+
return primaryLanguage;
|
|
500
|
+
}
|
|
501
|
+
const fullPrimaryLang = primaryLanguage + "-" + primaryLanguage;
|
|
502
|
+
if (_ConsentLanguages.langSet.has(fullPrimaryLang)) {
|
|
503
|
+
return fullPrimaryLang;
|
|
504
|
+
}
|
|
505
|
+
for (const supportedLang of _ConsentLanguages.langSet) {
|
|
506
|
+
if (supportedLang.indexOf(lang) !== -1 || supportedLang.indexOf(primaryLanguage) !== -1) {
|
|
507
|
+
return supportedLang;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
throw new Error(`unsupported language ${lang}`);
|
|
512
|
+
}
|
|
513
|
+
forEach(callback) {
|
|
514
|
+
_ConsentLanguages.langSet.forEach(callback);
|
|
515
|
+
}
|
|
516
|
+
get size() {
|
|
517
|
+
return _ConsentLanguages.langSet.size;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
__publicField(_ConsentLanguages, "langSet", /* @__PURE__ */ new Set([
|
|
521
|
+
"AR",
|
|
522
|
+
"BG",
|
|
523
|
+
"BS",
|
|
524
|
+
"CA",
|
|
525
|
+
"CS",
|
|
526
|
+
"DA",
|
|
527
|
+
"DE",
|
|
528
|
+
"EL",
|
|
529
|
+
"EN",
|
|
530
|
+
"ES",
|
|
531
|
+
"ET",
|
|
532
|
+
"EU",
|
|
533
|
+
"FI",
|
|
534
|
+
"FR",
|
|
535
|
+
"GL",
|
|
536
|
+
"HR",
|
|
537
|
+
"HU",
|
|
538
|
+
"IT",
|
|
539
|
+
"JA",
|
|
540
|
+
"LT",
|
|
541
|
+
"LV",
|
|
542
|
+
"MT",
|
|
543
|
+
"NL",
|
|
544
|
+
"NO",
|
|
545
|
+
"PL",
|
|
546
|
+
"PT-BR",
|
|
547
|
+
"PT-PT",
|
|
548
|
+
"RO",
|
|
549
|
+
"RU",
|
|
550
|
+
"SK",
|
|
551
|
+
"SL",
|
|
552
|
+
"SR-LATN",
|
|
553
|
+
"SR-CYRL",
|
|
554
|
+
"SV",
|
|
555
|
+
"TR",
|
|
556
|
+
"ZH"
|
|
557
|
+
]));
|
|
558
|
+
let ConsentLanguages = _ConsentLanguages;
|
|
559
|
+
class Fields {
|
|
560
|
+
}
|
|
561
|
+
__publicField(Fields, "cmpId", "cmpId");
|
|
562
|
+
__publicField(Fields, "cmpVersion", "cmpVersion");
|
|
563
|
+
__publicField(Fields, "consentLanguage", "consentLanguage");
|
|
564
|
+
__publicField(Fields, "consentScreen", "consentScreen");
|
|
565
|
+
__publicField(Fields, "created", "created");
|
|
566
|
+
__publicField(Fields, "supportOOB", "supportOOB");
|
|
567
|
+
__publicField(Fields, "isServiceSpecific", "isServiceSpecific");
|
|
568
|
+
__publicField(Fields, "lastUpdated", "lastUpdated");
|
|
569
|
+
__publicField(Fields, "numCustomPurposes", "numCustomPurposes");
|
|
570
|
+
__publicField(Fields, "policyVersion", "policyVersion");
|
|
571
|
+
__publicField(Fields, "publisherCountryCode", "publisherCountryCode");
|
|
572
|
+
__publicField(Fields, "publisherCustomConsents", "publisherCustomConsents");
|
|
573
|
+
__publicField(Fields, "publisherCustomLegitimateInterests", "publisherCustomLegitimateInterests");
|
|
574
|
+
__publicField(Fields, "publisherLegitimateInterests", "publisherLegitimateInterests");
|
|
575
|
+
__publicField(Fields, "publisherConsents", "publisherConsents");
|
|
576
|
+
__publicField(Fields, "publisherRestrictions", "publisherRestrictions");
|
|
577
|
+
__publicField(Fields, "purposeConsents", "purposeConsents");
|
|
578
|
+
__publicField(Fields, "purposeLegitimateInterests", "purposeLegitimateInterests");
|
|
579
|
+
__publicField(Fields, "purposeOneTreatment", "purposeOneTreatment");
|
|
580
|
+
__publicField(Fields, "specialFeatureOptins", "specialFeatureOptins");
|
|
581
|
+
__publicField(Fields, "useNonStandardTexts", "useNonStandardTexts");
|
|
582
|
+
__publicField(Fields, "vendorConsents", "vendorConsents");
|
|
583
|
+
__publicField(Fields, "vendorLegitimateInterests", "vendorLegitimateInterests");
|
|
584
|
+
__publicField(Fields, "vendorListVersion", "vendorListVersion");
|
|
585
|
+
__publicField(Fields, "vendorsAllowed", "vendorsAllowed");
|
|
586
|
+
__publicField(Fields, "vendorsDisclosed", "vendorsDisclosed");
|
|
587
|
+
__publicField(Fields, "version", "version");
|
|
588
|
+
class Cloneable {
|
|
589
|
+
/**
|
|
590
|
+
* clone - returns a copy of the classes with new values and not references
|
|
591
|
+
*
|
|
592
|
+
* @return {T}
|
|
593
|
+
*/
|
|
594
|
+
clone() {
|
|
595
|
+
const myClone = new this.constructor();
|
|
596
|
+
const keys = Object.keys(this);
|
|
597
|
+
keys.forEach((key) => {
|
|
598
|
+
const value = this.deepClone(this[key]);
|
|
599
|
+
if (value !== void 0) {
|
|
600
|
+
myClone[key] = value;
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
return myClone;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* deepClone - recursive function that makes copies of reference values
|
|
607
|
+
*
|
|
608
|
+
* @param {unknown} item
|
|
609
|
+
* @return {unknown}
|
|
610
|
+
*/
|
|
611
|
+
deepClone(item) {
|
|
612
|
+
const itsType = typeof item;
|
|
613
|
+
if (itsType === "number" || itsType === "string" || itsType === "boolean") {
|
|
614
|
+
return item;
|
|
615
|
+
} else if (item !== null && itsType === "object") {
|
|
616
|
+
if (typeof item.clone === "function") {
|
|
617
|
+
return item.clone();
|
|
618
|
+
} else if (item instanceof Date) {
|
|
619
|
+
return new Date(item.getTime());
|
|
620
|
+
} else if (item[Symbol.iterator] !== void 0) {
|
|
621
|
+
const ar = [];
|
|
622
|
+
for (const subItem of item) {
|
|
623
|
+
ar.push(this.deepClone(subItem));
|
|
624
|
+
}
|
|
625
|
+
if (item instanceof Array) {
|
|
626
|
+
return ar;
|
|
627
|
+
} else {
|
|
628
|
+
return new item.constructor(ar);
|
|
629
|
+
}
|
|
630
|
+
} else {
|
|
631
|
+
const retr = {};
|
|
632
|
+
for (const prop in item) {
|
|
633
|
+
if (item.hasOwnProperty(prop)) {
|
|
634
|
+
retr[prop] = this.deepClone(item[prop]);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return retr;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
var RestrictionType;
|
|
643
|
+
(function(RestrictionType2) {
|
|
644
|
+
RestrictionType2[RestrictionType2["NOT_ALLOWED"] = 0] = "NOT_ALLOWED";
|
|
645
|
+
RestrictionType2[RestrictionType2["REQUIRE_CONSENT"] = 1] = "REQUIRE_CONSENT";
|
|
646
|
+
RestrictionType2[RestrictionType2["REQUIRE_LI"] = 2] = "REQUIRE_LI";
|
|
647
|
+
})(RestrictionType || (RestrictionType = {}));
|
|
648
|
+
const _PurposeRestriction = class _PurposeRestriction extends Cloneable {
|
|
649
|
+
/**
|
|
650
|
+
* constructor
|
|
651
|
+
*
|
|
652
|
+
* @param {number} purposeId? - may optionally pass the purposeId into the
|
|
653
|
+
* constructor
|
|
654
|
+
* @param {RestrictionType} restrictionType? - may
|
|
655
|
+
* optionally pass the restrictionType into the constructor
|
|
656
|
+
* @return {undefined}
|
|
657
|
+
*/
|
|
658
|
+
constructor(purposeId, restrictionType) {
|
|
659
|
+
super();
|
|
660
|
+
__publicField(this, "purposeId_");
|
|
661
|
+
__publicField(this, "restrictionType");
|
|
662
|
+
if (purposeId !== void 0) {
|
|
663
|
+
this.purposeId = purposeId;
|
|
664
|
+
}
|
|
665
|
+
if (restrictionType !== void 0) {
|
|
666
|
+
this.restrictionType = restrictionType;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
static unHash(hash) {
|
|
670
|
+
const splitUp = hash.split(this.hashSeparator);
|
|
671
|
+
const purpRestriction = new _PurposeRestriction();
|
|
672
|
+
if (splitUp.length !== 2) {
|
|
673
|
+
throw new TCModelError("hash", hash);
|
|
674
|
+
}
|
|
675
|
+
purpRestriction.purposeId = parseInt(splitUp[0], 10);
|
|
676
|
+
purpRestriction.restrictionType = parseInt(splitUp[1], 10);
|
|
677
|
+
return purpRestriction;
|
|
678
|
+
}
|
|
679
|
+
get hash() {
|
|
680
|
+
if (!this.isValid()) {
|
|
681
|
+
throw new Error("cannot hash invalid PurposeRestriction");
|
|
682
|
+
}
|
|
683
|
+
return `${this.purposeId}${_PurposeRestriction.hashSeparator}${this.restrictionType}`;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* @return {number} The purpose Id associated with a publisher
|
|
687
|
+
* purpose-by-vendor restriction that resulted in a different consent or LI
|
|
688
|
+
* status than the consent or LI purposes allowed lists.
|
|
689
|
+
*/
|
|
690
|
+
get purposeId() {
|
|
691
|
+
return this.purposeId_;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* @param {number} idNum - The purpose Id associated with a publisher
|
|
695
|
+
* purpose-by-vendor restriction that resulted in a different consent or LI
|
|
696
|
+
* status than the consent or LI purposes allowed lists.
|
|
697
|
+
*/
|
|
698
|
+
set purposeId(idNum) {
|
|
699
|
+
this.purposeId_ = idNum;
|
|
700
|
+
}
|
|
701
|
+
isValid() {
|
|
702
|
+
return Number.isInteger(this.purposeId) && this.purposeId > 0 && (this.restrictionType === RestrictionType.NOT_ALLOWED || this.restrictionType === RestrictionType.REQUIRE_CONSENT || this.restrictionType === RestrictionType.REQUIRE_LI);
|
|
703
|
+
}
|
|
704
|
+
isSameAs(otherPR) {
|
|
705
|
+
return this.purposeId === otherPR.purposeId && this.restrictionType === otherPR.restrictionType;
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
__publicField(_PurposeRestriction, "hashSeparator", "-");
|
|
709
|
+
let PurposeRestriction = _PurposeRestriction;
|
|
710
|
+
class PurposeRestrictionVector extends Cloneable {
|
|
711
|
+
constructor() {
|
|
712
|
+
super(...arguments);
|
|
713
|
+
/**
|
|
714
|
+
* if this originatd from an encoded string we'll need a place to store the
|
|
715
|
+
* bit length; it can be set and got from here
|
|
716
|
+
*/
|
|
717
|
+
__publicField(this, "bitLength", 0);
|
|
718
|
+
/**
|
|
719
|
+
* a map indexed by a string which will be a 'hash' of the purpose and
|
|
720
|
+
* restriction type.
|
|
721
|
+
*/
|
|
722
|
+
__publicField(this, "map", /* @__PURE__ */ new Map());
|
|
723
|
+
__publicField(this, "gvl_");
|
|
724
|
+
}
|
|
725
|
+
has(hash) {
|
|
726
|
+
return this.map.has(hash);
|
|
727
|
+
}
|
|
728
|
+
isOkToHave(restrictionType, purposeId, vendorId) {
|
|
729
|
+
var _a2;
|
|
730
|
+
let result = true;
|
|
731
|
+
if ((_a2 = this.gvl) == null ? void 0 : _a2.vendors) {
|
|
732
|
+
const vendor = this.gvl.vendors[vendorId];
|
|
733
|
+
if (vendor) {
|
|
734
|
+
if (restrictionType === RestrictionType.NOT_ALLOWED) {
|
|
735
|
+
result = vendor.legIntPurposes.includes(purposeId) || vendor.purposes.includes(purposeId);
|
|
736
|
+
} else if (vendor.flexiblePurposes.length) {
|
|
737
|
+
switch (restrictionType) {
|
|
738
|
+
case RestrictionType.REQUIRE_CONSENT:
|
|
739
|
+
result = vendor.flexiblePurposes.includes(purposeId) && vendor.legIntPurposes.includes(purposeId);
|
|
740
|
+
break;
|
|
741
|
+
case RestrictionType.REQUIRE_LI:
|
|
742
|
+
result = vendor.flexiblePurposes.includes(purposeId) && vendor.purposes.includes(purposeId);
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
} else {
|
|
746
|
+
result = false;
|
|
747
|
+
}
|
|
748
|
+
} else {
|
|
749
|
+
result = false;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return result;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* add - adds a given Vendor ID under a given Purpose Restriction
|
|
756
|
+
*
|
|
757
|
+
* @param {number} vendorId
|
|
758
|
+
* @param {PurposeRestriction} purposeRestriction
|
|
759
|
+
* @return {void}
|
|
760
|
+
*/
|
|
761
|
+
add(vendorId, purposeRestriction) {
|
|
762
|
+
if (this.isOkToHave(purposeRestriction.restrictionType, purposeRestriction.purposeId, vendorId)) {
|
|
763
|
+
const hash = purposeRestriction.hash;
|
|
764
|
+
if (!this.has(hash)) {
|
|
765
|
+
this.map.set(hash, /* @__PURE__ */ new Set());
|
|
766
|
+
this.bitLength = 0;
|
|
767
|
+
}
|
|
768
|
+
this.map.get(hash).add(vendorId);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* restrictPurposeToLegalBasis - adds all Vendors under a given Purpose Restriction
|
|
773
|
+
*
|
|
774
|
+
* @param {PurposeRestriction} purposeRestriction
|
|
775
|
+
* @return {void}
|
|
776
|
+
*/
|
|
777
|
+
restrictPurposeToLegalBasis(purposeRestriction) {
|
|
778
|
+
const vendors = Array.from(this.gvl.vendorIds);
|
|
779
|
+
const hash = purposeRestriction.hash;
|
|
780
|
+
const lastEntry = vendors[vendors.length - 1];
|
|
781
|
+
const values = [...Array(lastEntry).keys()].map((i) => i + 1);
|
|
782
|
+
if (!this.has(hash)) {
|
|
783
|
+
this.map.set(hash, new Set(values));
|
|
784
|
+
this.bitLength = 0;
|
|
785
|
+
} else {
|
|
786
|
+
for (let i = 1; i <= lastEntry; i++) {
|
|
787
|
+
this.map.get(hash).add(i);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* getVendors - returns array of vendor ids optionally narrowed by a given
|
|
793
|
+
* Purpose Restriction. If no purpose restriction is passed then all vendor
|
|
794
|
+
* ids will be returned. One can expect this result to be a unique set of
|
|
795
|
+
* ids no duplicates.
|
|
796
|
+
*
|
|
797
|
+
* @param {PurposeRestriction} [purposeRestriction] - optionally passed to
|
|
798
|
+
* get only Vendor IDs restricted under the given Purpose Restriction
|
|
799
|
+
* @return {number[]} - Unique ID set of vendors
|
|
800
|
+
*/
|
|
801
|
+
getVendors(purposeRestriction) {
|
|
802
|
+
let vendorIds = [];
|
|
803
|
+
if (purposeRestriction) {
|
|
804
|
+
const hash = purposeRestriction.hash;
|
|
805
|
+
if (this.has(hash)) {
|
|
806
|
+
vendorIds = Array.from(this.map.get(hash));
|
|
807
|
+
}
|
|
808
|
+
} else {
|
|
809
|
+
const vendorSet = /* @__PURE__ */ new Set();
|
|
810
|
+
this.map.forEach((set) => {
|
|
811
|
+
set.forEach((vendorId) => {
|
|
812
|
+
vendorSet.add(vendorId);
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
vendorIds = Array.from(vendorSet);
|
|
816
|
+
}
|
|
817
|
+
return vendorIds.sort((a, b) => a - b);
|
|
818
|
+
}
|
|
819
|
+
getRestrictionType(vendorId, purposeId) {
|
|
820
|
+
let rType;
|
|
821
|
+
this.getRestrictions(vendorId).forEach((purposeRestriction) => {
|
|
822
|
+
if (purposeRestriction.purposeId === purposeId) {
|
|
823
|
+
if (rType === void 0 || rType > purposeRestriction.restrictionType) {
|
|
824
|
+
rType = purposeRestriction.restrictionType;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
return rType;
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* vendorHasRestriction - determines whether a given Vendor ID is under a
|
|
832
|
+
* given Purpose Restriction
|
|
833
|
+
*
|
|
834
|
+
* @param {number} vendorId
|
|
835
|
+
* @param {PurposeRestriction} purposeRestriction
|
|
836
|
+
* @return {boolean} - true if the give Vendor ID is under the given Purpose
|
|
837
|
+
* Restriction
|
|
838
|
+
*/
|
|
839
|
+
vendorHasRestriction(vendorId, purposeRestriction) {
|
|
840
|
+
let has = false;
|
|
841
|
+
const restrictions = this.getRestrictions(vendorId);
|
|
842
|
+
for (let i = 0; i < restrictions.length && !has; i++) {
|
|
843
|
+
has = purposeRestriction.isSameAs(restrictions[i]);
|
|
844
|
+
}
|
|
845
|
+
return has;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* getMaxVendorId - gets the Maximum Vendor ID regardless of Purpose
|
|
849
|
+
* Restriction
|
|
850
|
+
*
|
|
851
|
+
* @return {number} - maximum Vendor ID
|
|
852
|
+
*/
|
|
853
|
+
getMaxVendorId() {
|
|
854
|
+
let retr = 0;
|
|
855
|
+
this.map.forEach((set) => {
|
|
856
|
+
retr = Math.max(Array.from(set)[set.size - 1], retr);
|
|
857
|
+
});
|
|
858
|
+
return retr;
|
|
859
|
+
}
|
|
860
|
+
getRestrictions(vendorId) {
|
|
861
|
+
const retr = [];
|
|
862
|
+
this.map.forEach((set, hash) => {
|
|
863
|
+
if (vendorId) {
|
|
864
|
+
if (set.has(vendorId)) {
|
|
865
|
+
retr.push(PurposeRestriction.unHash(hash));
|
|
866
|
+
}
|
|
867
|
+
} else {
|
|
868
|
+
retr.push(PurposeRestriction.unHash(hash));
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
return retr;
|
|
872
|
+
}
|
|
873
|
+
getPurposes() {
|
|
874
|
+
const purposeIds = /* @__PURE__ */ new Set();
|
|
875
|
+
this.map.forEach((set, hash) => {
|
|
876
|
+
purposeIds.add(PurposeRestriction.unHash(hash).purposeId);
|
|
877
|
+
});
|
|
878
|
+
return Array.from(purposeIds);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* remove - removes Vendor ID from a Purpose Restriction
|
|
882
|
+
*
|
|
883
|
+
* @param {number} vendorId
|
|
884
|
+
* @param {PurposeRestriction} purposeRestriction
|
|
885
|
+
* @return {void}
|
|
886
|
+
*/
|
|
887
|
+
remove(vendorId, purposeRestriction) {
|
|
888
|
+
const hash = purposeRestriction.hash;
|
|
889
|
+
const set = this.map.get(hash);
|
|
890
|
+
if (set) {
|
|
891
|
+
set.delete(vendorId);
|
|
892
|
+
if (set.size == 0) {
|
|
893
|
+
this.map.delete(hash);
|
|
894
|
+
this.bitLength = 0;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Essential for being able to determine whether we can actually set a
|
|
900
|
+
* purpose restriction since they have to have a flexible legal basis
|
|
901
|
+
*
|
|
902
|
+
* @param {GVL} value - the GVL instance
|
|
903
|
+
*/
|
|
904
|
+
set gvl(value) {
|
|
905
|
+
if (!this.gvl_) {
|
|
906
|
+
this.gvl_ = value;
|
|
907
|
+
this.map.forEach((set, hash) => {
|
|
908
|
+
const purposeRestriction = PurposeRestriction.unHash(hash);
|
|
909
|
+
const vendors = Array.from(set);
|
|
910
|
+
vendors.forEach((vendorId) => {
|
|
911
|
+
if (!this.isOkToHave(purposeRestriction.restrictionType, purposeRestriction.purposeId, vendorId)) {
|
|
912
|
+
set.delete(vendorId);
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* gvl returns local copy of the GVL these restrictions apply to
|
|
920
|
+
*
|
|
921
|
+
* @return {GVL}
|
|
922
|
+
*/
|
|
923
|
+
get gvl() {
|
|
924
|
+
return this.gvl_;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* isEmpty - whether or not this vector has any restrictions in it
|
|
928
|
+
*
|
|
929
|
+
* @return {boolean}
|
|
930
|
+
*/
|
|
931
|
+
isEmpty() {
|
|
932
|
+
return this.map.size === 0;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* numRestrictions - returns the number of Purpose Restrictions.
|
|
936
|
+
*
|
|
937
|
+
* @return {number}
|
|
938
|
+
*/
|
|
939
|
+
get numRestrictions() {
|
|
940
|
+
return this.map.size;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
var DeviceDisclosureStorageAccessType;
|
|
944
|
+
(function(DeviceDisclosureStorageAccessType2) {
|
|
945
|
+
DeviceDisclosureStorageAccessType2["COOKIE"] = "cookie";
|
|
946
|
+
DeviceDisclosureStorageAccessType2["WEB"] = "web";
|
|
947
|
+
DeviceDisclosureStorageAccessType2["APP"] = "app";
|
|
948
|
+
})(DeviceDisclosureStorageAccessType || (DeviceDisclosureStorageAccessType = {}));
|
|
949
|
+
var Segment;
|
|
950
|
+
(function(Segment2) {
|
|
951
|
+
Segment2["CORE"] = "core";
|
|
952
|
+
Segment2["VENDORS_DISCLOSED"] = "vendorsDisclosed";
|
|
953
|
+
Segment2["VENDORS_ALLOWED"] = "vendorsAllowed";
|
|
954
|
+
Segment2["PUBLISHER_TC"] = "publisherTC";
|
|
955
|
+
})(Segment || (Segment = {}));
|
|
956
|
+
class SegmentIDs {
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* 0 = default - reserved for core string (does not need to be present in the core string)
|
|
960
|
+
* 1 = OOB vendors disclosed
|
|
961
|
+
* 2 = OOB vendors allowed
|
|
962
|
+
* 3 = PublisherTC
|
|
963
|
+
*/
|
|
964
|
+
__publicField(SegmentIDs, "ID_TO_KEY", [
|
|
965
|
+
Segment.CORE,
|
|
966
|
+
Segment.VENDORS_DISCLOSED,
|
|
967
|
+
Segment.VENDORS_ALLOWED,
|
|
968
|
+
Segment.PUBLISHER_TC
|
|
969
|
+
]);
|
|
970
|
+
__publicField(SegmentIDs, "KEY_TO_ID", {
|
|
971
|
+
[Segment.CORE]: 0,
|
|
972
|
+
[Segment.VENDORS_DISCLOSED]: 1,
|
|
973
|
+
[Segment.VENDORS_ALLOWED]: 2,
|
|
974
|
+
[Segment.PUBLISHER_TC]: 3
|
|
975
|
+
});
|
|
976
|
+
class Vector extends Cloneable {
|
|
977
|
+
constructor() {
|
|
978
|
+
super(...arguments);
|
|
979
|
+
/**
|
|
980
|
+
* if this originatd from an encoded string we'll need a place to store the
|
|
981
|
+
* bit length; it can be set and got from here
|
|
982
|
+
*/
|
|
983
|
+
__publicField(this, "bitLength", 0);
|
|
984
|
+
__publicField(this, "maxId_", 0);
|
|
985
|
+
__publicField(this, "set_", /* @__PURE__ */ new Set());
|
|
986
|
+
}
|
|
987
|
+
*[Symbol.iterator]() {
|
|
988
|
+
for (let i = 1; i <= this.maxId; i++) {
|
|
989
|
+
yield [i, this.has(i)];
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* values()
|
|
994
|
+
*
|
|
995
|
+
* @return {IterableIterator<number>} - returns an iterator of the positive
|
|
996
|
+
* values in the set
|
|
997
|
+
*/
|
|
998
|
+
values() {
|
|
999
|
+
return this.set_.values();
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* maxId
|
|
1003
|
+
*
|
|
1004
|
+
* @return {number} - the highest id in this Vector
|
|
1005
|
+
*/
|
|
1006
|
+
get maxId() {
|
|
1007
|
+
return this.maxId_;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* get
|
|
1011
|
+
*
|
|
1012
|
+
* @param {number} id - key for value to check
|
|
1013
|
+
* @return {boolean} - value of that key, if never set it will be false
|
|
1014
|
+
*/
|
|
1015
|
+
has(id) {
|
|
1016
|
+
return this.set_.has(id);
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* unset
|
|
1020
|
+
*
|
|
1021
|
+
* @param {SingleIDOrCollection} id - id or ids to unset
|
|
1022
|
+
* @return {void}
|
|
1023
|
+
*/
|
|
1024
|
+
unset(id) {
|
|
1025
|
+
if (Array.isArray(id)) {
|
|
1026
|
+
id.forEach((id2) => this.unset(id2));
|
|
1027
|
+
} else if (typeof id === "object") {
|
|
1028
|
+
this.unset(Object.keys(id).map((strId) => Number(strId)));
|
|
1029
|
+
} else {
|
|
1030
|
+
this.set_.delete(Number(id));
|
|
1031
|
+
this.bitLength = 0;
|
|
1032
|
+
if (id === this.maxId) {
|
|
1033
|
+
this.maxId_ = 0;
|
|
1034
|
+
this.set_.forEach((id2) => {
|
|
1035
|
+
this.maxId_ = Math.max(this.maxId, id2);
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
isIntMap(item) {
|
|
1041
|
+
let result = typeof item === "object";
|
|
1042
|
+
result = result && Object.keys(item).every((key) => {
|
|
1043
|
+
let itemResult = Number.isInteger(parseInt(key, 10));
|
|
1044
|
+
itemResult = itemResult && this.isValidNumber(item[key].id);
|
|
1045
|
+
itemResult = itemResult && item[key].name !== void 0;
|
|
1046
|
+
return itemResult;
|
|
1047
|
+
});
|
|
1048
|
+
return result;
|
|
1049
|
+
}
|
|
1050
|
+
isValidNumber(item) {
|
|
1051
|
+
return parseInt(item, 10) > 0;
|
|
1052
|
+
}
|
|
1053
|
+
isSet(item) {
|
|
1054
|
+
let result = false;
|
|
1055
|
+
if (item instanceof Set) {
|
|
1056
|
+
result = Array.from(item).every(this.isValidNumber);
|
|
1057
|
+
}
|
|
1058
|
+
return result;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* set - sets an item assumed to be a truthy value by its presence
|
|
1062
|
+
*
|
|
1063
|
+
* @param {SingleIDOrCollection} item - May be a single id (positive integer)
|
|
1064
|
+
* or collection of ids in a set, GVL Int Map, or Array.
|
|
1065
|
+
*
|
|
1066
|
+
* @return {void}
|
|
1067
|
+
*/
|
|
1068
|
+
set(item) {
|
|
1069
|
+
if (Array.isArray(item)) {
|
|
1070
|
+
item.forEach((item2) => this.set(item2));
|
|
1071
|
+
} else if (this.isSet(item)) {
|
|
1072
|
+
this.set(Array.from(item));
|
|
1073
|
+
} else if (this.isIntMap(item)) {
|
|
1074
|
+
this.set(Object.keys(item).map((strId) => Number(strId)));
|
|
1075
|
+
} else if (this.isValidNumber(item)) {
|
|
1076
|
+
this.set_.add(item);
|
|
1077
|
+
this.maxId_ = Math.max(this.maxId, item);
|
|
1078
|
+
this.bitLength = 0;
|
|
1079
|
+
} else {
|
|
1080
|
+
throw new TCModelError("set()", item, "must be positive integer array, positive integer, Set<number>, or IntMap");
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
empty() {
|
|
1084
|
+
this.set_ = /* @__PURE__ */ new Set();
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* forEach - to traverse from id=1 to id=maxId in a sequential non-sparse manner
|
|
1088
|
+
*
|
|
1089
|
+
*
|
|
1090
|
+
* @param {forEachCallback} callback - callback to execute
|
|
1091
|
+
* @return {void}
|
|
1092
|
+
*
|
|
1093
|
+
* @callback forEachCallback
|
|
1094
|
+
* @param {boolean} value - whether or not this id exists in the vector
|
|
1095
|
+
* @param {number} id - the id number of the current iteration
|
|
1096
|
+
*/
|
|
1097
|
+
forEach(callback) {
|
|
1098
|
+
for (let i = 1; i <= this.maxId; i++) {
|
|
1099
|
+
callback(this.has(i), i);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
get size() {
|
|
1103
|
+
return this.set_.size;
|
|
1104
|
+
}
|
|
1105
|
+
setAll(intMap) {
|
|
1106
|
+
this.set(intMap);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
class BitLength {
|
|
1110
|
+
}
|
|
1111
|
+
_a = Fields.cmpId, _b = Fields.cmpVersion, _c = Fields.consentLanguage, _d = Fields.consentScreen, _e = Fields.created, _f = Fields.isServiceSpecific, _g = Fields.lastUpdated, _h = Fields.policyVersion, _i = Fields.publisherCountryCode, _j = Fields.publisherLegitimateInterests, _k = Fields.publisherConsents, _l = Fields.purposeConsents, _m = Fields.purposeLegitimateInterests, _n = Fields.purposeOneTreatment, _o = Fields.specialFeatureOptins, _p = Fields.useNonStandardTexts, _q = Fields.vendorListVersion, _r = Fields.version;
|
|
1112
|
+
__publicField(BitLength, _a, 12);
|
|
1113
|
+
__publicField(BitLength, _b, 12);
|
|
1114
|
+
__publicField(BitLength, _c, 12);
|
|
1115
|
+
__publicField(BitLength, _d, 6);
|
|
1116
|
+
__publicField(BitLength, _e, 36);
|
|
1117
|
+
__publicField(BitLength, _f, 1);
|
|
1118
|
+
__publicField(BitLength, _g, 36);
|
|
1119
|
+
__publicField(BitLength, _h, 6);
|
|
1120
|
+
__publicField(BitLength, _i, 12);
|
|
1121
|
+
__publicField(BitLength, _j, 24);
|
|
1122
|
+
__publicField(BitLength, _k, 24);
|
|
1123
|
+
__publicField(BitLength, _l, 24);
|
|
1124
|
+
__publicField(BitLength, _m, 24);
|
|
1125
|
+
__publicField(BitLength, _n, 1);
|
|
1126
|
+
__publicField(BitLength, _o, 12);
|
|
1127
|
+
__publicField(BitLength, _p, 1);
|
|
1128
|
+
__publicField(BitLength, _q, 12);
|
|
1129
|
+
__publicField(BitLength, _r, 6);
|
|
1130
|
+
__publicField(BitLength, "anyBoolean", 1);
|
|
1131
|
+
__publicField(BitLength, "encodingType", 1);
|
|
1132
|
+
__publicField(BitLength, "maxId", 16);
|
|
1133
|
+
__publicField(BitLength, "numCustomPurposes", 6);
|
|
1134
|
+
__publicField(BitLength, "numEntries", 12);
|
|
1135
|
+
__publicField(BitLength, "numRestrictions", 12);
|
|
1136
|
+
__publicField(BitLength, "purposeId", 6);
|
|
1137
|
+
__publicField(BitLength, "restrictionType", 2);
|
|
1138
|
+
__publicField(BitLength, "segmentType", 3);
|
|
1139
|
+
__publicField(BitLength, "singleOrRange", 1);
|
|
1140
|
+
__publicField(BitLength, "vendorId", 16);
|
|
1141
|
+
class BooleanEncoder {
|
|
1142
|
+
static encode(value) {
|
|
1143
|
+
return String(Number(value));
|
|
1144
|
+
}
|
|
1145
|
+
static decode(value) {
|
|
1146
|
+
return value === "1";
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
class IntEncoder {
|
|
1150
|
+
static encode(value, numBits) {
|
|
1151
|
+
let bitString;
|
|
1152
|
+
if (typeof value === "string") {
|
|
1153
|
+
value = parseInt(value, 10);
|
|
1154
|
+
}
|
|
1155
|
+
bitString = value.toString(2);
|
|
1156
|
+
if (bitString.length > numBits || value < 0) {
|
|
1157
|
+
throw new EncodingError(`${value} too large to encode into ${numBits}`);
|
|
1158
|
+
}
|
|
1159
|
+
if (bitString.length < numBits) {
|
|
1160
|
+
bitString = "0".repeat(numBits - bitString.length) + bitString;
|
|
1161
|
+
}
|
|
1162
|
+
return bitString;
|
|
1163
|
+
}
|
|
1164
|
+
static decode(value, numBits) {
|
|
1165
|
+
if (numBits !== value.length) {
|
|
1166
|
+
throw new DecodingError("invalid bit length");
|
|
1167
|
+
}
|
|
1168
|
+
return parseInt(value, 2);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
class DateEncoder {
|
|
1172
|
+
static encode(value, numBits) {
|
|
1173
|
+
return IntEncoder.encode(Math.round(value.getTime() / 100), numBits);
|
|
1174
|
+
}
|
|
1175
|
+
static decode(value, numBits) {
|
|
1176
|
+
if (numBits !== value.length) {
|
|
1177
|
+
throw new DecodingError("invalid bit length");
|
|
1178
|
+
}
|
|
1179
|
+
const date = /* @__PURE__ */ new Date();
|
|
1180
|
+
date.setTime(IntEncoder.decode(value, numBits) * 100);
|
|
1181
|
+
return date;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
class FixedVectorEncoder {
|
|
1185
|
+
static encode(value, numBits) {
|
|
1186
|
+
let bitString = "";
|
|
1187
|
+
for (let i = 1; i <= numBits; i++) {
|
|
1188
|
+
bitString += BooleanEncoder.encode(value.has(i));
|
|
1189
|
+
}
|
|
1190
|
+
return bitString;
|
|
1191
|
+
}
|
|
1192
|
+
static decode(value, numBits) {
|
|
1193
|
+
if (value.length !== numBits) {
|
|
1194
|
+
throw new DecodingError("bitfield encoding length mismatch");
|
|
1195
|
+
}
|
|
1196
|
+
const vector = new Vector();
|
|
1197
|
+
for (let i = 1; i <= numBits; i++) {
|
|
1198
|
+
if (BooleanEncoder.decode(value[i - 1])) {
|
|
1199
|
+
vector.set(i);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
vector.bitLength = value.length;
|
|
1203
|
+
return vector;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
class LangEncoder {
|
|
1207
|
+
static encode(value, numBits) {
|
|
1208
|
+
value = value.toUpperCase();
|
|
1209
|
+
const ASCII_START = 65;
|
|
1210
|
+
const firstLetter = value.charCodeAt(0) - ASCII_START;
|
|
1211
|
+
const secondLetter = value.charCodeAt(1) - ASCII_START;
|
|
1212
|
+
if (firstLetter < 0 || firstLetter > 25 || secondLetter < 0 || secondLetter > 25) {
|
|
1213
|
+
throw new EncodingError(`invalid language code: ${value}`);
|
|
1214
|
+
}
|
|
1215
|
+
if (numBits % 2 === 1) {
|
|
1216
|
+
throw new EncodingError(`numBits must be even, ${numBits} is not valid`);
|
|
1217
|
+
}
|
|
1218
|
+
numBits = numBits / 2;
|
|
1219
|
+
const firstLetterBString = IntEncoder.encode(firstLetter, numBits);
|
|
1220
|
+
const secondLetterBString = IntEncoder.encode(secondLetter, numBits);
|
|
1221
|
+
return firstLetterBString + secondLetterBString;
|
|
1222
|
+
}
|
|
1223
|
+
static decode(value, numBits) {
|
|
1224
|
+
let retr;
|
|
1225
|
+
if (numBits === value.length && !(value.length % 2)) {
|
|
1226
|
+
const ASCII_START = 65;
|
|
1227
|
+
const mid = value.length / 2;
|
|
1228
|
+
const firstLetter = IntEncoder.decode(value.slice(0, mid), mid) + ASCII_START;
|
|
1229
|
+
const secondLetter = IntEncoder.decode(value.slice(mid), mid) + ASCII_START;
|
|
1230
|
+
retr = String.fromCharCode(firstLetter) + String.fromCharCode(secondLetter);
|
|
1231
|
+
} else {
|
|
1232
|
+
throw new DecodingError("invalid bit length for language");
|
|
1233
|
+
}
|
|
1234
|
+
return retr;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
class PurposeRestrictionVectorEncoder {
|
|
1238
|
+
static encode(prVector) {
|
|
1239
|
+
let bitString = IntEncoder.encode(prVector.numRestrictions, BitLength.numRestrictions);
|
|
1240
|
+
if (!prVector.isEmpty()) {
|
|
1241
|
+
const nextGvlVendor = (vendorId, lastVendorId) => {
|
|
1242
|
+
for (let nextId = vendorId + 1; nextId <= lastVendorId; nextId++) {
|
|
1243
|
+
if (prVector.gvl.vendorIds.has(nextId)) {
|
|
1244
|
+
return nextId;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
return vendorId;
|
|
1248
|
+
};
|
|
1249
|
+
prVector.getRestrictions().forEach((purpRestriction) => {
|
|
1250
|
+
bitString += IntEncoder.encode(purpRestriction.purposeId, BitLength.purposeId);
|
|
1251
|
+
bitString += IntEncoder.encode(purpRestriction.restrictionType, BitLength.restrictionType);
|
|
1252
|
+
const vendors = prVector.getVendors(purpRestriction);
|
|
1253
|
+
const len = vendors.length;
|
|
1254
|
+
let numEntries = 0;
|
|
1255
|
+
let startId = 0;
|
|
1256
|
+
let rangeField = "";
|
|
1257
|
+
for (let i = 0; i < len; i++) {
|
|
1258
|
+
const vendorId = vendors[i];
|
|
1259
|
+
if (startId === 0) {
|
|
1260
|
+
numEntries++;
|
|
1261
|
+
startId = vendorId;
|
|
1262
|
+
}
|
|
1263
|
+
if (i === len - 1 || vendors[i + 1] > nextGvlVendor(vendorId, vendors[len - 1])) {
|
|
1264
|
+
const isRange = !(vendorId === startId);
|
|
1265
|
+
rangeField += BooleanEncoder.encode(isRange);
|
|
1266
|
+
rangeField += IntEncoder.encode(startId, BitLength.vendorId);
|
|
1267
|
+
if (isRange) {
|
|
1268
|
+
rangeField += IntEncoder.encode(vendorId, BitLength.vendorId);
|
|
1269
|
+
}
|
|
1270
|
+
startId = 0;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
bitString += IntEncoder.encode(numEntries, BitLength.numEntries);
|
|
1274
|
+
bitString += rangeField;
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
return bitString;
|
|
1278
|
+
}
|
|
1279
|
+
static decode(encodedString) {
|
|
1280
|
+
let index = 0;
|
|
1281
|
+
const vector = new PurposeRestrictionVector();
|
|
1282
|
+
const numRestrictions = IntEncoder.decode(encodedString.substr(index, BitLength.numRestrictions), BitLength.numRestrictions);
|
|
1283
|
+
index += BitLength.numRestrictions;
|
|
1284
|
+
for (let i = 0; i < numRestrictions; i++) {
|
|
1285
|
+
const purposeId = IntEncoder.decode(encodedString.substr(index, BitLength.purposeId), BitLength.purposeId);
|
|
1286
|
+
index += BitLength.purposeId;
|
|
1287
|
+
const restrictionType = IntEncoder.decode(encodedString.substr(index, BitLength.restrictionType), BitLength.restrictionType);
|
|
1288
|
+
index += BitLength.restrictionType;
|
|
1289
|
+
const purposeRestriction = new PurposeRestriction(purposeId, restrictionType);
|
|
1290
|
+
const numEntries = IntEncoder.decode(encodedString.substr(index, BitLength.numEntries), BitLength.numEntries);
|
|
1291
|
+
index += BitLength.numEntries;
|
|
1292
|
+
for (let j = 0; j < numEntries; j++) {
|
|
1293
|
+
const isARange = BooleanEncoder.decode(encodedString.substr(index, BitLength.anyBoolean));
|
|
1294
|
+
index += BitLength.anyBoolean;
|
|
1295
|
+
const startOrOnlyVendorId = IntEncoder.decode(encodedString.substr(index, BitLength.vendorId), BitLength.vendorId);
|
|
1296
|
+
index += BitLength.vendorId;
|
|
1297
|
+
if (isARange) {
|
|
1298
|
+
const endVendorId = IntEncoder.decode(encodedString.substr(index, BitLength.vendorId), BitLength.vendorId);
|
|
1299
|
+
index += BitLength.vendorId;
|
|
1300
|
+
if (endVendorId < startOrOnlyVendorId) {
|
|
1301
|
+
throw new DecodingError(`Invalid RangeEntry: endVendorId ${endVendorId} is less than ${startOrOnlyVendorId}`);
|
|
1302
|
+
}
|
|
1303
|
+
for (let k = startOrOnlyVendorId; k <= endVendorId; k++) {
|
|
1304
|
+
vector.add(k, purposeRestriction);
|
|
1305
|
+
}
|
|
1306
|
+
} else {
|
|
1307
|
+
vector.add(startOrOnlyVendorId, purposeRestriction);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
vector.bitLength = index;
|
|
1312
|
+
return vector;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
var VectorEncodingType;
|
|
1316
|
+
(function(VectorEncodingType2) {
|
|
1317
|
+
VectorEncodingType2[VectorEncodingType2["FIELD"] = 0] = "FIELD";
|
|
1318
|
+
VectorEncodingType2[VectorEncodingType2["RANGE"] = 1] = "RANGE";
|
|
1319
|
+
})(VectorEncodingType || (VectorEncodingType = {}));
|
|
1320
|
+
class VendorVectorEncoder {
|
|
1321
|
+
static encode(value) {
|
|
1322
|
+
const ranges = [];
|
|
1323
|
+
let range = [];
|
|
1324
|
+
let retrString = IntEncoder.encode(value.maxId, BitLength.maxId);
|
|
1325
|
+
let bitField = "";
|
|
1326
|
+
let rangeIsSmaller;
|
|
1327
|
+
const headerLength = BitLength.maxId + BitLength.encodingType;
|
|
1328
|
+
const bitFieldLength = headerLength + value.maxId;
|
|
1329
|
+
const minRangeLength = BitLength.vendorId * 2 + BitLength.singleOrRange + BitLength.numEntries;
|
|
1330
|
+
let rangeLength = headerLength + BitLength.numEntries;
|
|
1331
|
+
value.forEach((curValue, i) => {
|
|
1332
|
+
bitField += BooleanEncoder.encode(curValue);
|
|
1333
|
+
rangeIsSmaller = value.maxId > minRangeLength && rangeLength < bitFieldLength;
|
|
1334
|
+
if (rangeIsSmaller && curValue) {
|
|
1335
|
+
const nextValue = value.has(i + 1);
|
|
1336
|
+
if (!nextValue) {
|
|
1337
|
+
range.push(i);
|
|
1338
|
+
rangeLength += BitLength.vendorId;
|
|
1339
|
+
ranges.push(range);
|
|
1340
|
+
range = [];
|
|
1341
|
+
} else if (range.length === 0) {
|
|
1342
|
+
range.push(i);
|
|
1343
|
+
rangeLength += BitLength.singleOrRange;
|
|
1344
|
+
rangeLength += BitLength.vendorId;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
if (rangeIsSmaller) {
|
|
1349
|
+
retrString += String(VectorEncodingType.RANGE);
|
|
1350
|
+
retrString += this.buildRangeEncoding(ranges);
|
|
1351
|
+
} else {
|
|
1352
|
+
retrString += String(VectorEncodingType.FIELD);
|
|
1353
|
+
retrString += bitField;
|
|
1354
|
+
}
|
|
1355
|
+
return retrString;
|
|
1356
|
+
}
|
|
1357
|
+
static decode(value, version2) {
|
|
1358
|
+
let vector;
|
|
1359
|
+
let index = 0;
|
|
1360
|
+
const maxId = IntEncoder.decode(value.substr(index, BitLength.maxId), BitLength.maxId);
|
|
1361
|
+
index += BitLength.maxId;
|
|
1362
|
+
const encodingType = IntEncoder.decode(value.charAt(index), BitLength.encodingType);
|
|
1363
|
+
index += BitLength.encodingType;
|
|
1364
|
+
if (encodingType === VectorEncodingType.RANGE) {
|
|
1365
|
+
vector = new Vector();
|
|
1366
|
+
if (version2 === 1) {
|
|
1367
|
+
if (value.substr(index, 1) === "1") {
|
|
1368
|
+
throw new DecodingError("Unable to decode default consent=1");
|
|
1369
|
+
}
|
|
1370
|
+
index++;
|
|
1371
|
+
}
|
|
1372
|
+
const numEntries = IntEncoder.decode(value.substr(index, BitLength.numEntries), BitLength.numEntries);
|
|
1373
|
+
index += BitLength.numEntries;
|
|
1374
|
+
for (let i = 0; i < numEntries; i++) {
|
|
1375
|
+
const isIdRange = BooleanEncoder.decode(value.charAt(index));
|
|
1376
|
+
index += BitLength.singleOrRange;
|
|
1377
|
+
const firstId = IntEncoder.decode(value.substr(index, BitLength.vendorId), BitLength.vendorId);
|
|
1378
|
+
index += BitLength.vendorId;
|
|
1379
|
+
if (isIdRange) {
|
|
1380
|
+
const secondId = IntEncoder.decode(value.substr(index, BitLength.vendorId), BitLength.vendorId);
|
|
1381
|
+
index += BitLength.vendorId;
|
|
1382
|
+
for (let j = firstId; j <= secondId; j++) {
|
|
1383
|
+
vector.set(j);
|
|
1384
|
+
}
|
|
1385
|
+
} else {
|
|
1386
|
+
vector.set(firstId);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
} else {
|
|
1390
|
+
const bitField = value.substr(index, maxId);
|
|
1391
|
+
index += maxId;
|
|
1392
|
+
vector = FixedVectorEncoder.decode(bitField, maxId);
|
|
1393
|
+
}
|
|
1394
|
+
vector.bitLength = index;
|
|
1395
|
+
return vector;
|
|
1396
|
+
}
|
|
1397
|
+
static buildRangeEncoding(ranges) {
|
|
1398
|
+
const numEntries = ranges.length;
|
|
1399
|
+
let rangeString = IntEncoder.encode(numEntries, BitLength.numEntries);
|
|
1400
|
+
ranges.forEach((range) => {
|
|
1401
|
+
const single = range.length === 1;
|
|
1402
|
+
rangeString += BooleanEncoder.encode(!single);
|
|
1403
|
+
rangeString += IntEncoder.encode(range[0], BitLength.vendorId);
|
|
1404
|
+
if (!single) {
|
|
1405
|
+
rangeString += IntEncoder.encode(range[1], BitLength.vendorId);
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
return rangeString;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
function FieldEncoderMap() {
|
|
1412
|
+
return {
|
|
1413
|
+
[Fields.version]: IntEncoder,
|
|
1414
|
+
[Fields.created]: DateEncoder,
|
|
1415
|
+
[Fields.lastUpdated]: DateEncoder,
|
|
1416
|
+
[Fields.cmpId]: IntEncoder,
|
|
1417
|
+
[Fields.cmpVersion]: IntEncoder,
|
|
1418
|
+
[Fields.consentScreen]: IntEncoder,
|
|
1419
|
+
[Fields.consentLanguage]: LangEncoder,
|
|
1420
|
+
[Fields.vendorListVersion]: IntEncoder,
|
|
1421
|
+
[Fields.policyVersion]: IntEncoder,
|
|
1422
|
+
[Fields.isServiceSpecific]: BooleanEncoder,
|
|
1423
|
+
[Fields.useNonStandardTexts]: BooleanEncoder,
|
|
1424
|
+
[Fields.specialFeatureOptins]: FixedVectorEncoder,
|
|
1425
|
+
[Fields.purposeConsents]: FixedVectorEncoder,
|
|
1426
|
+
[Fields.purposeLegitimateInterests]: FixedVectorEncoder,
|
|
1427
|
+
[Fields.purposeOneTreatment]: BooleanEncoder,
|
|
1428
|
+
[Fields.publisherCountryCode]: LangEncoder,
|
|
1429
|
+
[Fields.vendorConsents]: VendorVectorEncoder,
|
|
1430
|
+
[Fields.vendorLegitimateInterests]: VendorVectorEncoder,
|
|
1431
|
+
[Fields.publisherRestrictions]: PurposeRestrictionVectorEncoder,
|
|
1432
|
+
segmentType: IntEncoder,
|
|
1433
|
+
[Fields.vendorsDisclosed]: VendorVectorEncoder,
|
|
1434
|
+
[Fields.vendorsAllowed]: VendorVectorEncoder,
|
|
1435
|
+
[Fields.publisherConsents]: FixedVectorEncoder,
|
|
1436
|
+
[Fields.publisherLegitimateInterests]: FixedVectorEncoder,
|
|
1437
|
+
[Fields.numCustomPurposes]: IntEncoder,
|
|
1438
|
+
[Fields.publisherCustomConsents]: FixedVectorEncoder,
|
|
1439
|
+
[Fields.publisherCustomLegitimateInterests]: FixedVectorEncoder
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
class FieldSequence {
|
|
1443
|
+
constructor() {
|
|
1444
|
+
__publicField(this, "1", {
|
|
1445
|
+
[Segment.CORE]: [
|
|
1446
|
+
Fields.version,
|
|
1447
|
+
Fields.created,
|
|
1448
|
+
Fields.lastUpdated,
|
|
1449
|
+
Fields.cmpId,
|
|
1450
|
+
Fields.cmpVersion,
|
|
1451
|
+
Fields.consentScreen,
|
|
1452
|
+
Fields.consentLanguage,
|
|
1453
|
+
Fields.vendorListVersion,
|
|
1454
|
+
Fields.purposeConsents,
|
|
1455
|
+
Fields.vendorConsents
|
|
1456
|
+
]
|
|
1457
|
+
});
|
|
1458
|
+
__publicField(this, "2", {
|
|
1459
|
+
[Segment.CORE]: [
|
|
1460
|
+
Fields.version,
|
|
1461
|
+
Fields.created,
|
|
1462
|
+
Fields.lastUpdated,
|
|
1463
|
+
Fields.cmpId,
|
|
1464
|
+
Fields.cmpVersion,
|
|
1465
|
+
Fields.consentScreen,
|
|
1466
|
+
Fields.consentLanguage,
|
|
1467
|
+
Fields.vendorListVersion,
|
|
1468
|
+
Fields.policyVersion,
|
|
1469
|
+
Fields.isServiceSpecific,
|
|
1470
|
+
Fields.useNonStandardTexts,
|
|
1471
|
+
Fields.specialFeatureOptins,
|
|
1472
|
+
Fields.purposeConsents,
|
|
1473
|
+
Fields.purposeLegitimateInterests,
|
|
1474
|
+
Fields.purposeOneTreatment,
|
|
1475
|
+
Fields.publisherCountryCode,
|
|
1476
|
+
Fields.vendorConsents,
|
|
1477
|
+
Fields.vendorLegitimateInterests,
|
|
1478
|
+
Fields.publisherRestrictions
|
|
1479
|
+
],
|
|
1480
|
+
[Segment.PUBLISHER_TC]: [
|
|
1481
|
+
Fields.publisherConsents,
|
|
1482
|
+
Fields.publisherLegitimateInterests,
|
|
1483
|
+
Fields.numCustomPurposes,
|
|
1484
|
+
Fields.publisherCustomConsents,
|
|
1485
|
+
Fields.publisherCustomLegitimateInterests
|
|
1486
|
+
],
|
|
1487
|
+
[Segment.VENDORS_ALLOWED]: [
|
|
1488
|
+
Fields.vendorsAllowed
|
|
1489
|
+
],
|
|
1490
|
+
[Segment.VENDORS_DISCLOSED]: [
|
|
1491
|
+
Fields.vendorsDisclosed
|
|
1492
|
+
]
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
class SegmentSequence {
|
|
1497
|
+
constructor(tcModel, options) {
|
|
1498
|
+
__publicField(this, "1", [
|
|
1499
|
+
Segment.CORE
|
|
1500
|
+
]);
|
|
1501
|
+
__publicField(this, "2", [
|
|
1502
|
+
Segment.CORE
|
|
1503
|
+
]);
|
|
1504
|
+
if (tcModel.version === 2) {
|
|
1505
|
+
if (tcModel.isServiceSpecific) {
|
|
1506
|
+
this["2"].push(Segment.PUBLISHER_TC);
|
|
1507
|
+
} else {
|
|
1508
|
+
const isForVendors = !!(options && options.isForVendors);
|
|
1509
|
+
if (!isForVendors || tcModel[Fields.supportOOB] === true) {
|
|
1510
|
+
this["2"].push(Segment.VENDORS_DISCLOSED);
|
|
1511
|
+
}
|
|
1512
|
+
if (isForVendors) {
|
|
1513
|
+
if (tcModel[Fields.supportOOB] && tcModel[Fields.vendorsAllowed].size > 0) {
|
|
1514
|
+
this["2"].push(Segment.VENDORS_ALLOWED);
|
|
1515
|
+
}
|
|
1516
|
+
this["2"].push(Segment.PUBLISHER_TC);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
class SegmentEncoder {
|
|
1523
|
+
static encode(tcModel, segment) {
|
|
1524
|
+
let sequence;
|
|
1525
|
+
try {
|
|
1526
|
+
sequence = this.fieldSequence[String(tcModel.version)][segment];
|
|
1527
|
+
} catch (err) {
|
|
1528
|
+
throw new EncodingError(`Unable to encode version: ${tcModel.version}, segment: ${segment}`);
|
|
1529
|
+
}
|
|
1530
|
+
let bitField = "";
|
|
1531
|
+
if (segment !== Segment.CORE) {
|
|
1532
|
+
bitField = IntEncoder.encode(SegmentIDs.KEY_TO_ID[segment], BitLength.segmentType);
|
|
1533
|
+
}
|
|
1534
|
+
const fieldEncoderMap = FieldEncoderMap();
|
|
1535
|
+
sequence.forEach((key) => {
|
|
1536
|
+
const value = tcModel[key];
|
|
1537
|
+
const encoder = fieldEncoderMap[key];
|
|
1538
|
+
let numBits = BitLength[key];
|
|
1539
|
+
if (numBits === void 0) {
|
|
1540
|
+
if (this.isPublisherCustom(key)) {
|
|
1541
|
+
numBits = Number(tcModel[Fields.numCustomPurposes]);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
try {
|
|
1545
|
+
bitField += encoder.encode(value, numBits);
|
|
1546
|
+
} catch (err) {
|
|
1547
|
+
throw new EncodingError(`Error encoding ${segment}->${key}: ${err.message}`);
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
return Base64Url.encode(bitField);
|
|
1551
|
+
}
|
|
1552
|
+
static decode(encodedString, tcModel, segment) {
|
|
1553
|
+
const bitField = Base64Url.decode(encodedString);
|
|
1554
|
+
let bStringIdx = 0;
|
|
1555
|
+
if (segment === Segment.CORE) {
|
|
1556
|
+
tcModel.version = IntEncoder.decode(bitField.substr(bStringIdx, BitLength[Fields.version]), BitLength[Fields.version]);
|
|
1557
|
+
}
|
|
1558
|
+
if (segment !== Segment.CORE) {
|
|
1559
|
+
bStringIdx += BitLength.segmentType;
|
|
1560
|
+
}
|
|
1561
|
+
const sequence = this.fieldSequence[String(tcModel.version)][segment];
|
|
1562
|
+
const fieldEncoderMap = FieldEncoderMap();
|
|
1563
|
+
sequence.forEach((key) => {
|
|
1564
|
+
const encoder = fieldEncoderMap[key];
|
|
1565
|
+
let numBits = BitLength[key];
|
|
1566
|
+
if (numBits === void 0) {
|
|
1567
|
+
if (this.isPublisherCustom(key)) {
|
|
1568
|
+
numBits = Number(tcModel[Fields.numCustomPurposes]);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
if (numBits !== 0) {
|
|
1572
|
+
const bits = bitField.substr(bStringIdx, numBits);
|
|
1573
|
+
if (encoder === VendorVectorEncoder) {
|
|
1574
|
+
tcModel[key] = encoder.decode(bits, tcModel.version);
|
|
1575
|
+
} else {
|
|
1576
|
+
tcModel[key] = encoder.decode(bits, numBits);
|
|
1577
|
+
}
|
|
1578
|
+
if (Number.isInteger(numBits)) {
|
|
1579
|
+
bStringIdx += numBits;
|
|
1580
|
+
} else if (Number.isInteger(tcModel[key].bitLength)) {
|
|
1581
|
+
bStringIdx += tcModel[key].bitLength;
|
|
1582
|
+
} else {
|
|
1583
|
+
throw new DecodingError(key);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
});
|
|
1587
|
+
return tcModel;
|
|
1588
|
+
}
|
|
1589
|
+
static isPublisherCustom(key) {
|
|
1590
|
+
return key.indexOf("publisherCustom") === 0;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
__publicField(SegmentEncoder, "fieldSequence", new FieldSequence());
|
|
1594
|
+
class SemanticPreEncoder {
|
|
1595
|
+
static process(tcModel, options) {
|
|
1596
|
+
const gvl = tcModel.gvl;
|
|
1597
|
+
if (!gvl) {
|
|
1598
|
+
throw new EncodingError("Unable to encode TCModel without a GVL");
|
|
1599
|
+
}
|
|
1600
|
+
if (!gvl.isReady) {
|
|
1601
|
+
throw new EncodingError("Unable to encode TCModel tcModel.gvl.readyPromise is not resolved");
|
|
1602
|
+
}
|
|
1603
|
+
tcModel = tcModel.clone();
|
|
1604
|
+
tcModel.consentLanguage = gvl.language.slice(0, 2).toUpperCase();
|
|
1605
|
+
if ((options == null ? void 0 : options.version) > 0 && (options == null ? void 0 : options.version) <= this.processor.length) {
|
|
1606
|
+
tcModel.version = options.version;
|
|
1607
|
+
} else {
|
|
1608
|
+
tcModel.version = this.processor.length;
|
|
1609
|
+
}
|
|
1610
|
+
const processorFunctionIndex = tcModel.version - 1;
|
|
1611
|
+
if (!this.processor[processorFunctionIndex]) {
|
|
1612
|
+
throw new EncodingError(`Invalid version: ${tcModel.version}`);
|
|
1613
|
+
}
|
|
1614
|
+
return this.processor[processorFunctionIndex](tcModel, gvl);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
__publicField(SemanticPreEncoder, "processor", [
|
|
1618
|
+
(tcModel) => tcModel,
|
|
1619
|
+
(tcModel, gvl) => {
|
|
1620
|
+
tcModel.publisherRestrictions.gvl = gvl;
|
|
1621
|
+
tcModel.purposeLegitimateInterests.unset([1, 3, 4, 5, 6]);
|
|
1622
|
+
const vectorToIntMap = /* @__PURE__ */ new Map();
|
|
1623
|
+
vectorToIntMap.set("legIntPurposes", tcModel.vendorLegitimateInterests);
|
|
1624
|
+
vectorToIntMap.set("purposes", tcModel.vendorConsents);
|
|
1625
|
+
vectorToIntMap.forEach((vector, gvlVendorKey) => {
|
|
1626
|
+
vector.forEach((value, vendorId) => {
|
|
1627
|
+
if (value) {
|
|
1628
|
+
const vendor = gvl.vendors[vendorId];
|
|
1629
|
+
if (!vendor || vendor.deletedDate) {
|
|
1630
|
+
vector.unset(vendorId);
|
|
1631
|
+
} else if (vendor[gvlVendorKey].length === 0) {
|
|
1632
|
+
if (gvlVendorKey === "legIntPurposes" && vendor["purposes"].length === 0 && vendor["legIntPurposes"].length === 0 && vendor["specialPurposes"].length > 0)
|
|
1633
|
+
;
|
|
1634
|
+
else {
|
|
1635
|
+
if (tcModel.isServiceSpecific) {
|
|
1636
|
+
if (vendor.flexiblePurposes.length === 0) {
|
|
1637
|
+
vector.unset(vendorId);
|
|
1638
|
+
} else {
|
|
1639
|
+
const restrictions = tcModel.publisherRestrictions.getRestrictions(vendorId);
|
|
1640
|
+
let isValid = false;
|
|
1641
|
+
for (let i = 0, len = restrictions.length; i < len && !isValid; i++) {
|
|
1642
|
+
isValid = restrictions[i].restrictionType === RestrictionType.REQUIRE_CONSENT && gvlVendorKey === "purposes" || restrictions[i].restrictionType === RestrictionType.REQUIRE_LI && gvlVendorKey === "legIntPurposes";
|
|
1643
|
+
}
|
|
1644
|
+
if (!isValid) {
|
|
1645
|
+
vector.unset(vendorId);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
} else {
|
|
1649
|
+
vector.unset(vendorId);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
});
|
|
1656
|
+
tcModel.vendorsDisclosed.set(gvl.vendors);
|
|
1657
|
+
return tcModel;
|
|
1658
|
+
}
|
|
1659
|
+
]);
|
|
1660
|
+
class Json {
|
|
1661
|
+
static absCall(url, body, sendCookies, timeout) {
|
|
1662
|
+
return new Promise((resolve, reject) => {
|
|
1663
|
+
const req = new XMLHttpRequest();
|
|
1664
|
+
const onLoad = () => {
|
|
1665
|
+
if (req.readyState == XMLHttpRequest.DONE) {
|
|
1666
|
+
if (req.status >= 200 && req.status < 300) {
|
|
1667
|
+
let response = req.response;
|
|
1668
|
+
if (typeof response === "string") {
|
|
1669
|
+
try {
|
|
1670
|
+
response = JSON.parse(response);
|
|
1671
|
+
} catch (e) {
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
resolve(response);
|
|
1675
|
+
} else {
|
|
1676
|
+
reject(new Error(`HTTP Status: ${req.status} response type: ${req.responseType}`));
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
const onError = () => {
|
|
1681
|
+
reject(new Error("error"));
|
|
1682
|
+
};
|
|
1683
|
+
const onAbort = () => {
|
|
1684
|
+
reject(new Error("aborted"));
|
|
1685
|
+
};
|
|
1686
|
+
const onTimeout = () => {
|
|
1687
|
+
reject(new Error("Timeout " + timeout + "ms " + url));
|
|
1688
|
+
};
|
|
1689
|
+
req.withCredentials = sendCookies;
|
|
1690
|
+
req.addEventListener("load", onLoad);
|
|
1691
|
+
req.addEventListener("error", onError);
|
|
1692
|
+
req.addEventListener("abort", onAbort);
|
|
1693
|
+
if (body === null) {
|
|
1694
|
+
req.open("GET", url, true);
|
|
1695
|
+
} else {
|
|
1696
|
+
req.open("POST", url, true);
|
|
1697
|
+
}
|
|
1698
|
+
req.responseType = "json";
|
|
1699
|
+
req.timeout = timeout;
|
|
1700
|
+
req.ontimeout = onTimeout;
|
|
1701
|
+
req.send(body);
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* @static
|
|
1706
|
+
* @param {string} url - full path to POST to
|
|
1707
|
+
* @param {object} body - JSON object to post
|
|
1708
|
+
* @param {boolean} sendCookies - Whether or not to send the XMLHttpRequest with credentials or not
|
|
1709
|
+
* @param {number} [timeout] - optional timeout in milliseconds
|
|
1710
|
+
* @return {Promise<object>} - if the server responds the response will be returned here
|
|
1711
|
+
*/
|
|
1712
|
+
static post(url, body, sendCookies = false, timeout = 0) {
|
|
1713
|
+
return this.absCall(url, JSON.stringify(body), sendCookies, timeout);
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* @static
|
|
1717
|
+
* @param {string} url - full path to the json
|
|
1718
|
+
* @param {boolean} sendCookies - Whether or not to send the XMLHttpRequest with credentials or not
|
|
1719
|
+
* @param {number} [timeout] - optional timeout in milliseconds
|
|
1720
|
+
* @return {Promise<object>} - resolves with parsed JSON
|
|
1721
|
+
*/
|
|
1722
|
+
static fetch(url, sendCookies = false, timeout = 0) {
|
|
1723
|
+
return this.absCall(url, null, sendCookies, timeout);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
const _GVL = class _GVL extends Cloneable {
|
|
1727
|
+
/**
|
|
1728
|
+
* @param {VersionOrVendorList} [versionOrVendorList] - can be either a
|
|
1729
|
+
* [[VendorList]] object or a version number represented as a string or
|
|
1730
|
+
* number to download. If nothing is passed the latest version of the GVL
|
|
1731
|
+
* will be loaded
|
|
1732
|
+
*/
|
|
1733
|
+
constructor(versionOrVendorList) {
|
|
1734
|
+
super();
|
|
1735
|
+
/**
|
|
1736
|
+
* @param {Promise} resolved when this GVL object is populated with the data
|
|
1737
|
+
* or rejected if there is an error.
|
|
1738
|
+
*/
|
|
1739
|
+
__publicField(this, "readyPromise");
|
|
1740
|
+
/**
|
|
1741
|
+
* @param {number} gvlSpecificationVersion - schema version for the GVL that is used
|
|
1742
|
+
*/
|
|
1743
|
+
__publicField(this, "gvlSpecificationVersion");
|
|
1744
|
+
/**
|
|
1745
|
+
* @param {number} incremented with each published file change
|
|
1746
|
+
*/
|
|
1747
|
+
__publicField(this, "vendorListVersion");
|
|
1748
|
+
/**
|
|
1749
|
+
* @param {number} tcfPolicyVersion - The TCF MO will increment this value
|
|
1750
|
+
* whenever a GVL change (such as adding a new Purpose or Feature or a change
|
|
1751
|
+
* in Purpose wording) legally invalidates existing TC Strings and requires
|
|
1752
|
+
* CMPs to re-establish transparency and consent from users. If the policy
|
|
1753
|
+
* version number in the latest GVL is different from the value in your TC
|
|
1754
|
+
* String, then you need to re-establish transparency and consent for that
|
|
1755
|
+
* user. A version 1 format TC String is considered to have a version value
|
|
1756
|
+
* of 1.
|
|
1757
|
+
*/
|
|
1758
|
+
__publicField(this, "tcfPolicyVersion");
|
|
1759
|
+
/**
|
|
1760
|
+
* @param {string | Date} lastUpdated - the date in which the vendor list
|
|
1761
|
+
* json file was last updated.
|
|
1762
|
+
*/
|
|
1763
|
+
__publicField(this, "lastUpdated");
|
|
1764
|
+
/**
|
|
1765
|
+
* @param {IntMap<Purpose>} a collection of [[Purpose]]s
|
|
1766
|
+
*/
|
|
1767
|
+
__publicField(this, "purposes");
|
|
1768
|
+
/**
|
|
1769
|
+
* @param {IntMap<Purpose>} a collection of [[Purpose]]s
|
|
1770
|
+
*/
|
|
1771
|
+
__publicField(this, "specialPurposes");
|
|
1772
|
+
/**
|
|
1773
|
+
* @param {IntMap<Feature>} a collection of [[Feature]]s
|
|
1774
|
+
*/
|
|
1775
|
+
__publicField(this, "features");
|
|
1776
|
+
/**
|
|
1777
|
+
* @param {IntMap<Feature>} a collection of [[Feature]]s
|
|
1778
|
+
*/
|
|
1779
|
+
__publicField(this, "specialFeatures");
|
|
1780
|
+
/**
|
|
1781
|
+
* @param {boolean} internal reference of when the GVL is ready to be used
|
|
1782
|
+
*/
|
|
1783
|
+
__publicField(this, "isReady_", false);
|
|
1784
|
+
/**
|
|
1785
|
+
* @param {IntMap<Vendor>} a collection of [[Vendor]]s
|
|
1786
|
+
*/
|
|
1787
|
+
__publicField(this, "vendors_");
|
|
1788
|
+
__publicField(this, "vendorIds");
|
|
1789
|
+
/**
|
|
1790
|
+
* @param {IntMap<Vendor>} a collection of [[Vendor]]. Used as a backup if a whitelist is sets
|
|
1791
|
+
*/
|
|
1792
|
+
__publicField(this, "fullVendorList");
|
|
1793
|
+
/**
|
|
1794
|
+
* @param {ByPurposeVendorMap} vendors by purpose
|
|
1795
|
+
*/
|
|
1796
|
+
__publicField(this, "byPurposeVendorMap");
|
|
1797
|
+
/**
|
|
1798
|
+
* @param {IDSetMap} vendors by special purpose
|
|
1799
|
+
*/
|
|
1800
|
+
__publicField(this, "bySpecialPurposeVendorMap");
|
|
1801
|
+
/**
|
|
1802
|
+
* @param {IDSetMap} vendors by feature
|
|
1803
|
+
*/
|
|
1804
|
+
__publicField(this, "byFeatureVendorMap");
|
|
1805
|
+
/**
|
|
1806
|
+
* @param {IDSetMap} vendors by special feature
|
|
1807
|
+
*/
|
|
1808
|
+
__publicField(this, "bySpecialFeatureVendorMap");
|
|
1809
|
+
/**
|
|
1810
|
+
* @param {IntMap<Stack>} a collection of [[Stack]]s
|
|
1811
|
+
*/
|
|
1812
|
+
__publicField(this, "stacks");
|
|
1813
|
+
/**
|
|
1814
|
+
* @param {IntMap<DataCategory>} a collection of [[DataCategory]]s
|
|
1815
|
+
*/
|
|
1816
|
+
__publicField(this, "dataCategories");
|
|
1817
|
+
__publicField(this, "lang_");
|
|
1818
|
+
__publicField(this, "cacheLang_");
|
|
1819
|
+
__publicField(this, "isLatest", false);
|
|
1820
|
+
let url = _GVL.baseUrl;
|
|
1821
|
+
this.lang_ = _GVL.DEFAULT_LANGUAGE;
|
|
1822
|
+
this.cacheLang_ = _GVL.DEFAULT_LANGUAGE;
|
|
1823
|
+
if (this.isVendorList(versionOrVendorList)) {
|
|
1824
|
+
this.populate(versionOrVendorList);
|
|
1825
|
+
this.readyPromise = Promise.resolve();
|
|
1826
|
+
} else {
|
|
1827
|
+
if (!url) {
|
|
1828
|
+
throw new GVLError("must specify GVL.baseUrl before loading GVL json");
|
|
1829
|
+
}
|
|
1830
|
+
if (versionOrVendorList > 0) {
|
|
1831
|
+
const version2 = versionOrVendorList;
|
|
1832
|
+
if (_GVL.CACHE.has(version2)) {
|
|
1833
|
+
this.populate(_GVL.CACHE.get(version2));
|
|
1834
|
+
this.readyPromise = Promise.resolve();
|
|
1835
|
+
} else {
|
|
1836
|
+
url += _GVL.versionedFilename.replace("[VERSION]", String(version2));
|
|
1837
|
+
this.readyPromise = this.fetchJson(url);
|
|
1838
|
+
}
|
|
1839
|
+
} else {
|
|
1840
|
+
if (_GVL.CACHE.has(_GVL.LATEST_CACHE_KEY)) {
|
|
1841
|
+
this.populate(_GVL.CACHE.get(_GVL.LATEST_CACHE_KEY));
|
|
1842
|
+
this.readyPromise = Promise.resolve();
|
|
1843
|
+
} else {
|
|
1844
|
+
this.isLatest = true;
|
|
1845
|
+
this.readyPromise = this.fetchJson(url + _GVL.latestFilename);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* baseUrl - Entities using the vendor-list.json are required by the iab to
|
|
1852
|
+
* host their own copy of it to reduce the load on the iab's infrastructure
|
|
1853
|
+
* so a 'base' url must be set to be put together with the versioning scheme
|
|
1854
|
+
* of the filenames.
|
|
1855
|
+
*
|
|
1856
|
+
* @static
|
|
1857
|
+
* @param {string} url - the base url to load the vendor-list.json from. This is
|
|
1858
|
+
* broken out from the filename because it follows a different scheme for
|
|
1859
|
+
* latest file vs versioned files.
|
|
1860
|
+
*
|
|
1861
|
+
* @throws {GVLError} - If the url is http[s]://vendorlist.consensu.org/...
|
|
1862
|
+
* this will throw an error. IAB Europe requires that that CMPs and Vendors
|
|
1863
|
+
* cache their own copies of the GVL to minimize load on their
|
|
1864
|
+
* infrastructure. For more information regarding caching of the
|
|
1865
|
+
* vendor-list.json, please see [the TCF documentation on 'Caching the Global
|
|
1866
|
+
* Vendor List'
|
|
1867
|
+
* ](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#caching-the-global-vendor-list)
|
|
1868
|
+
*/
|
|
1869
|
+
static set baseUrl(url) {
|
|
1870
|
+
const notValid = /^https?:\/\/vendorlist\.consensu\.org\//;
|
|
1871
|
+
if (notValid.test(url)) {
|
|
1872
|
+
throw new GVLError("Invalid baseUrl! You may not pull directly from vendorlist.consensu.org and must provide your own cache");
|
|
1873
|
+
}
|
|
1874
|
+
if (url.length > 0 && url[url.length - 1] !== "/") {
|
|
1875
|
+
url += "/";
|
|
1876
|
+
}
|
|
1877
|
+
this.baseUrl_ = url;
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* baseUrl - Entities using the vendor-list.json are required by the iab to
|
|
1881
|
+
* host their own copy of it to reduce the load on the iab's infrastructure
|
|
1882
|
+
* so a 'base' url must be set to be put together with the versioning scheme
|
|
1883
|
+
* of the filenames.
|
|
1884
|
+
*
|
|
1885
|
+
* @static
|
|
1886
|
+
* @return {string} - returns the previously set baseUrl, the default is
|
|
1887
|
+
* `undefined`
|
|
1888
|
+
*/
|
|
1889
|
+
static get baseUrl() {
|
|
1890
|
+
return this.baseUrl_;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* emptyLanguageCache
|
|
1894
|
+
*
|
|
1895
|
+
* @param {string} [lang] - Optional language code to remove from
|
|
1896
|
+
* the cache. Should be one of the languages in GVL.consentLanguages set.
|
|
1897
|
+
* If not then the whole cache will be deleted.
|
|
1898
|
+
* @return {boolean} - true if anything was deleted from the cache
|
|
1899
|
+
*/
|
|
1900
|
+
static emptyLanguageCache(lang) {
|
|
1901
|
+
let result = false;
|
|
1902
|
+
if (lang == null && _GVL.LANGUAGE_CACHE.size > 0) {
|
|
1903
|
+
_GVL.LANGUAGE_CACHE = /* @__PURE__ */ new Map();
|
|
1904
|
+
result = true;
|
|
1905
|
+
} else if (typeof lang === "string" && this.consentLanguages.has(lang.toUpperCase())) {
|
|
1906
|
+
_GVL.LANGUAGE_CACHE.delete(lang.toUpperCase());
|
|
1907
|
+
result = true;
|
|
1908
|
+
}
|
|
1909
|
+
return result;
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* emptyCache
|
|
1913
|
+
*
|
|
1914
|
+
* @param {number} [vendorListVersion] - version of the vendor list to delete
|
|
1915
|
+
* from the cache. If none is specified then the whole cache is deleted.
|
|
1916
|
+
* @return {boolean} - true if anything was deleted from the cache
|
|
1917
|
+
*/
|
|
1918
|
+
static emptyCache(vendorListVersion) {
|
|
1919
|
+
let retr = false;
|
|
1920
|
+
if (Number.isInteger(vendorListVersion) && vendorListVersion >= 0) {
|
|
1921
|
+
_GVL.CACHE.delete(vendorListVersion);
|
|
1922
|
+
retr = true;
|
|
1923
|
+
} else if (vendorListVersion === void 0) {
|
|
1924
|
+
_GVL.CACHE = /* @__PURE__ */ new Map();
|
|
1925
|
+
retr = true;
|
|
1926
|
+
}
|
|
1927
|
+
return retr;
|
|
1928
|
+
}
|
|
1929
|
+
cacheLanguage() {
|
|
1930
|
+
if (!_GVL.LANGUAGE_CACHE.has(this.cacheLang_)) {
|
|
1931
|
+
_GVL.LANGUAGE_CACHE.set(this.cacheLang_, {
|
|
1932
|
+
purposes: this.purposes,
|
|
1933
|
+
specialPurposes: this.specialPurposes,
|
|
1934
|
+
features: this.features,
|
|
1935
|
+
specialFeatures: this.specialFeatures,
|
|
1936
|
+
stacks: this.stacks,
|
|
1937
|
+
dataCategories: this.dataCategories
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
async fetchJson(url) {
|
|
1942
|
+
try {
|
|
1943
|
+
this.populate(await Json.fetch(url));
|
|
1944
|
+
} catch (err) {
|
|
1945
|
+
throw new GVLError(err.message);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* getJson - Method for getting the JSON that was downloaded to created this
|
|
1950
|
+
* `GVL` object
|
|
1951
|
+
*
|
|
1952
|
+
* @return {VendorList} - The basic JSON structure without the extra
|
|
1953
|
+
* functionality and methods of this class.
|
|
1954
|
+
*/
|
|
1955
|
+
getJson() {
|
|
1956
|
+
return JSON.parse(JSON.stringify({
|
|
1957
|
+
gvlSpecificationVersion: this.gvlSpecificationVersion,
|
|
1958
|
+
vendorListVersion: this.vendorListVersion,
|
|
1959
|
+
tcfPolicyVersion: this.tcfPolicyVersion,
|
|
1960
|
+
lastUpdated: this.lastUpdated,
|
|
1961
|
+
purposes: this.purposes,
|
|
1962
|
+
specialPurposes: this.specialPurposes,
|
|
1963
|
+
features: this.features,
|
|
1964
|
+
specialFeatures: this.specialFeatures,
|
|
1965
|
+
stacks: this.stacks,
|
|
1966
|
+
dataCategories: this.dataCategories,
|
|
1967
|
+
vendors: this.fullVendorList
|
|
1968
|
+
}));
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* changeLanguage - retrieves the purpose language translation and sets the
|
|
1972
|
+
* internal language variable
|
|
1973
|
+
*
|
|
1974
|
+
* @param {string} lang - language code to change language to
|
|
1975
|
+
* @return {Promise<void | GVLError>} - returns the `readyPromise` and
|
|
1976
|
+
* resolves when this GVL is populated with the data from the language file.
|
|
1977
|
+
*/
|
|
1978
|
+
async changeLanguage(lang) {
|
|
1979
|
+
let parsedLanguage = lang;
|
|
1980
|
+
try {
|
|
1981
|
+
parsedLanguage = _GVL.consentLanguages.parseLanguage(lang);
|
|
1982
|
+
} catch (e) {
|
|
1983
|
+
throw new GVLError("Error during parsing the language: " + e.message);
|
|
1984
|
+
}
|
|
1985
|
+
const cacheLang = lang.toUpperCase();
|
|
1986
|
+
if (parsedLanguage.toLowerCase() === _GVL.DEFAULT_LANGUAGE.toLowerCase() && !_GVL.LANGUAGE_CACHE.has(cacheLang)) {
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
if (parsedLanguage !== this.lang_) {
|
|
1990
|
+
this.lang_ = parsedLanguage;
|
|
1991
|
+
if (_GVL.LANGUAGE_CACHE.has(cacheLang)) {
|
|
1992
|
+
const cached = _GVL.LANGUAGE_CACHE.get(cacheLang);
|
|
1993
|
+
for (const prop in cached) {
|
|
1994
|
+
if (cached.hasOwnProperty(prop)) {
|
|
1995
|
+
this[prop] = cached[prop];
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
} else {
|
|
1999
|
+
const url = _GVL.baseUrl + _GVL.languageFilename.replace("[LANG]", this.lang_.toLowerCase());
|
|
2000
|
+
try {
|
|
2001
|
+
await this.fetchJson(url);
|
|
2002
|
+
this.cacheLang_ = cacheLang;
|
|
2003
|
+
this.cacheLanguage();
|
|
2004
|
+
} catch (err) {
|
|
2005
|
+
throw new GVLError("unable to load language: " + err.message);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
get language() {
|
|
2011
|
+
return this.lang_;
|
|
2012
|
+
}
|
|
2013
|
+
isVendorList(gvlObject) {
|
|
2014
|
+
return gvlObject !== void 0 && gvlObject.vendors !== void 0;
|
|
2015
|
+
}
|
|
2016
|
+
populate(gvlObject) {
|
|
2017
|
+
this.purposes = gvlObject.purposes;
|
|
2018
|
+
this.specialPurposes = gvlObject.specialPurposes;
|
|
2019
|
+
this.features = gvlObject.features;
|
|
2020
|
+
this.specialFeatures = gvlObject.specialFeatures;
|
|
2021
|
+
this.stacks = gvlObject.stacks;
|
|
2022
|
+
this.dataCategories = gvlObject.dataCategories;
|
|
2023
|
+
if (this.isVendorList(gvlObject)) {
|
|
2024
|
+
this.gvlSpecificationVersion = gvlObject.gvlSpecificationVersion;
|
|
2025
|
+
this.tcfPolicyVersion = gvlObject.tcfPolicyVersion;
|
|
2026
|
+
this.vendorListVersion = gvlObject.vendorListVersion;
|
|
2027
|
+
this.lastUpdated = gvlObject.lastUpdated;
|
|
2028
|
+
if (typeof this.lastUpdated === "string") {
|
|
2029
|
+
this.lastUpdated = new Date(this.lastUpdated);
|
|
2030
|
+
}
|
|
2031
|
+
this.vendors_ = gvlObject.vendors;
|
|
2032
|
+
this.fullVendorList = gvlObject.vendors;
|
|
2033
|
+
this.mapVendors();
|
|
2034
|
+
this.isReady_ = true;
|
|
2035
|
+
if (this.isLatest) {
|
|
2036
|
+
_GVL.CACHE.set(_GVL.LATEST_CACHE_KEY, this.getJson());
|
|
2037
|
+
}
|
|
2038
|
+
if (!_GVL.CACHE.has(this.vendorListVersion)) {
|
|
2039
|
+
_GVL.CACHE.set(this.vendorListVersion, this.getJson());
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
this.cacheLanguage();
|
|
2043
|
+
}
|
|
2044
|
+
mapVendors(vendorIds) {
|
|
2045
|
+
this.byPurposeVendorMap = {};
|
|
2046
|
+
this.bySpecialPurposeVendorMap = {};
|
|
2047
|
+
this.byFeatureVendorMap = {};
|
|
2048
|
+
this.bySpecialFeatureVendorMap = {};
|
|
2049
|
+
Object.keys(this.purposes).forEach((purposeId) => {
|
|
2050
|
+
this.byPurposeVendorMap[purposeId] = {
|
|
2051
|
+
legInt: /* @__PURE__ */ new Set(),
|
|
2052
|
+
consent: /* @__PURE__ */ new Set(),
|
|
2053
|
+
flexible: /* @__PURE__ */ new Set()
|
|
2054
|
+
};
|
|
2055
|
+
});
|
|
2056
|
+
Object.keys(this.specialPurposes).forEach((purposeId) => {
|
|
2057
|
+
this.bySpecialPurposeVendorMap[purposeId] = /* @__PURE__ */ new Set();
|
|
2058
|
+
});
|
|
2059
|
+
Object.keys(this.features).forEach((featureId) => {
|
|
2060
|
+
this.byFeatureVendorMap[featureId] = /* @__PURE__ */ new Set();
|
|
2061
|
+
});
|
|
2062
|
+
Object.keys(this.specialFeatures).forEach((featureId) => {
|
|
2063
|
+
this.bySpecialFeatureVendorMap[featureId] = /* @__PURE__ */ new Set();
|
|
2064
|
+
});
|
|
2065
|
+
if (!Array.isArray(vendorIds)) {
|
|
2066
|
+
vendorIds = Object.keys(this.fullVendorList).map((vId) => +vId);
|
|
2067
|
+
}
|
|
2068
|
+
this.vendorIds = new Set(vendorIds);
|
|
2069
|
+
this.vendors_ = vendorIds.reduce((vendors, vendorId) => {
|
|
2070
|
+
const vendor = this.vendors_[String(vendorId)];
|
|
2071
|
+
if (vendor && vendor.deletedDate === void 0) {
|
|
2072
|
+
vendor.purposes.forEach((purposeId) => {
|
|
2073
|
+
const purpGroup = this.byPurposeVendorMap[String(purposeId)];
|
|
2074
|
+
purpGroup.consent.add(vendorId);
|
|
2075
|
+
});
|
|
2076
|
+
vendor.specialPurposes.forEach((purposeId) => {
|
|
2077
|
+
this.bySpecialPurposeVendorMap[String(purposeId)].add(vendorId);
|
|
2078
|
+
});
|
|
2079
|
+
vendor.legIntPurposes.forEach((purposeId) => {
|
|
2080
|
+
this.byPurposeVendorMap[String(purposeId)].legInt.add(vendorId);
|
|
2081
|
+
});
|
|
2082
|
+
if (vendor.flexiblePurposes) {
|
|
2083
|
+
vendor.flexiblePurposes.forEach((purposeId) => {
|
|
2084
|
+
this.byPurposeVendorMap[String(purposeId)].flexible.add(vendorId);
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
vendor.features.forEach((featureId) => {
|
|
2088
|
+
this.byFeatureVendorMap[String(featureId)].add(vendorId);
|
|
2089
|
+
});
|
|
2090
|
+
vendor.specialFeatures.forEach((featureId) => {
|
|
2091
|
+
this.bySpecialFeatureVendorMap[String(featureId)].add(vendorId);
|
|
2092
|
+
});
|
|
2093
|
+
vendors[vendorId] = vendor;
|
|
2094
|
+
}
|
|
2095
|
+
return vendors;
|
|
2096
|
+
}, {});
|
|
2097
|
+
}
|
|
2098
|
+
getFilteredVendors(purposeOrFeature, id, subType, special) {
|
|
2099
|
+
const properPurposeOrFeature = purposeOrFeature.charAt(0).toUpperCase() + purposeOrFeature.slice(1);
|
|
2100
|
+
let vendorSet;
|
|
2101
|
+
const retr = {};
|
|
2102
|
+
if (purposeOrFeature === "purpose" && subType) {
|
|
2103
|
+
vendorSet = this["by" + properPurposeOrFeature + "VendorMap"][String(id)][subType];
|
|
2104
|
+
} else {
|
|
2105
|
+
vendorSet = this["by" + (special ? "Special" : "") + properPurposeOrFeature + "VendorMap"][String(id)];
|
|
2106
|
+
}
|
|
2107
|
+
vendorSet.forEach((vendorId) => {
|
|
2108
|
+
retr[String(vendorId)] = this.vendors[String(vendorId)];
|
|
2109
|
+
});
|
|
2110
|
+
return retr;
|
|
2111
|
+
}
|
|
2112
|
+
/**
|
|
2113
|
+
* getVendorsWithConsentPurpose
|
|
2114
|
+
*
|
|
2115
|
+
* @param {number} purposeId
|
|
2116
|
+
* @return {IntMap<Vendor>} - list of vendors that have declared the consent purpose id
|
|
2117
|
+
*/
|
|
2118
|
+
getVendorsWithConsentPurpose(purposeId) {
|
|
2119
|
+
return this.getFilteredVendors("purpose", purposeId, "consent");
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* getVendorsWithLegIntPurpose
|
|
2123
|
+
*
|
|
2124
|
+
* @param {number} purposeId
|
|
2125
|
+
* @return {IntMap<Vendor>} - list of vendors that have declared the legInt (Legitimate Interest) purpose id
|
|
2126
|
+
*/
|
|
2127
|
+
getVendorsWithLegIntPurpose(purposeId) {
|
|
2128
|
+
return this.getFilteredVendors("purpose", purposeId, "legInt");
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* getVendorsWithFlexiblePurpose
|
|
2132
|
+
*
|
|
2133
|
+
* @param {number} purposeId
|
|
2134
|
+
* @return {IntMap<Vendor>} - list of vendors that have declared the flexible purpose id
|
|
2135
|
+
*/
|
|
2136
|
+
getVendorsWithFlexiblePurpose(purposeId) {
|
|
2137
|
+
return this.getFilteredVendors("purpose", purposeId, "flexible");
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* getVendorsWithSpecialPurpose
|
|
2141
|
+
*
|
|
2142
|
+
* @param {number} specialPurposeId
|
|
2143
|
+
* @return {IntMap<Vendor>} - list of vendors that have declared the special purpose id
|
|
2144
|
+
*/
|
|
2145
|
+
getVendorsWithSpecialPurpose(specialPurposeId) {
|
|
2146
|
+
return this.getFilteredVendors("purpose", specialPurposeId, void 0, true);
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* getVendorsWithFeature
|
|
2150
|
+
*
|
|
2151
|
+
* @param {number} featureId
|
|
2152
|
+
* @return {IntMap<Vendor>} - list of vendors that have declared the feature id
|
|
2153
|
+
*/
|
|
2154
|
+
getVendorsWithFeature(featureId) {
|
|
2155
|
+
return this.getFilteredVendors("feature", featureId);
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* getVendorsWithSpecialFeature
|
|
2159
|
+
*
|
|
2160
|
+
* @param {number} specialFeatureId
|
|
2161
|
+
* @return {IntMap<Vendor>} - list of vendors that have declared the special feature id
|
|
2162
|
+
*/
|
|
2163
|
+
getVendorsWithSpecialFeature(specialFeatureId) {
|
|
2164
|
+
return this.getFilteredVendors("feature", specialFeatureId, void 0, true);
|
|
2165
|
+
}
|
|
2166
|
+
/**
|
|
2167
|
+
* vendors
|
|
2168
|
+
*
|
|
2169
|
+
* @return {IntMap<Vendor>} - the list of vendors as it would on the JSON file
|
|
2170
|
+
* except if `narrowVendorsTo` was called, it would be that narrowed list
|
|
2171
|
+
*/
|
|
2172
|
+
get vendors() {
|
|
2173
|
+
return this.vendors_;
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* narrowVendorsTo - narrows vendors represented in this GVL to the list of ids passed in
|
|
2177
|
+
*
|
|
2178
|
+
* @param {number[]} vendorIds - list of ids to narrow this GVL to
|
|
2179
|
+
* @return {void}
|
|
2180
|
+
*/
|
|
2181
|
+
narrowVendorsTo(vendorIds) {
|
|
2182
|
+
this.mapVendors(vendorIds);
|
|
2183
|
+
}
|
|
2184
|
+
/**
|
|
2185
|
+
* isReady - Whether or not this instance is ready to be used. This will be
|
|
2186
|
+
* immediately and synchronously true if a vendorlist object is passed into
|
|
2187
|
+
* the constructor or once the JSON vendorllist is retrieved.
|
|
2188
|
+
*
|
|
2189
|
+
* @return {boolean} whether or not the instance is ready to be interacted
|
|
2190
|
+
* with and all the data is populated
|
|
2191
|
+
*/
|
|
2192
|
+
get isReady() {
|
|
2193
|
+
return this.isReady_;
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* clone - overrides base `clone()` method since GVL is a special class that
|
|
2197
|
+
* represents a JSON structure with some additional functionality.
|
|
2198
|
+
*
|
|
2199
|
+
* @return {GVL}
|
|
2200
|
+
*/
|
|
2201
|
+
clone() {
|
|
2202
|
+
const result = new _GVL(this.getJson());
|
|
2203
|
+
if (this.lang_ !== _GVL.DEFAULT_LANGUAGE) {
|
|
2204
|
+
result.changeLanguage(this.lang_);
|
|
2205
|
+
}
|
|
2206
|
+
return result;
|
|
2207
|
+
}
|
|
2208
|
+
static isInstanceOf(questionableInstance) {
|
|
2209
|
+
const isSo = typeof questionableInstance === "object";
|
|
2210
|
+
return isSo && typeof questionableInstance.narrowVendorsTo === "function";
|
|
2211
|
+
}
|
|
2212
|
+
};
|
|
2213
|
+
__publicField(_GVL, "LANGUAGE_CACHE", /* @__PURE__ */ new Map());
|
|
2214
|
+
__publicField(_GVL, "CACHE", /* @__PURE__ */ new Map());
|
|
2215
|
+
__publicField(_GVL, "LATEST_CACHE_KEY", 0);
|
|
2216
|
+
__publicField(_GVL, "DEFAULT_LANGUAGE", "EN");
|
|
2217
|
+
/**
|
|
2218
|
+
* Set of available consent languages published by the IAB
|
|
2219
|
+
*/
|
|
2220
|
+
__publicField(_GVL, "consentLanguages", new ConsentLanguages());
|
|
2221
|
+
__publicField(_GVL, "baseUrl_");
|
|
2222
|
+
/**
|
|
2223
|
+
* @static
|
|
2224
|
+
* @param {string} - the latest is assumed to be vendor-list.json because
|
|
2225
|
+
* that is what the iab uses, but it could be different... if you want
|
|
2226
|
+
*/
|
|
2227
|
+
__publicField(_GVL, "latestFilename", "vendor-list.json");
|
|
2228
|
+
/**
|
|
2229
|
+
* @static
|
|
2230
|
+
* @param {string} - the versioned name is assumed to be
|
|
2231
|
+
* vendor-list-v[VERSION].json where [VERSION] will be replaced with the
|
|
2232
|
+
* specified version. But it could be different... if you want just make
|
|
2233
|
+
* sure to include the [VERSION] macro if you have a numbering scheme, it's a
|
|
2234
|
+
* simple string substitution.
|
|
2235
|
+
*
|
|
2236
|
+
* eg.
|
|
2237
|
+
* ```javascript
|
|
2238
|
+
* GVL.baseUrl = "http://www.mydomain.com/iabcmp/";
|
|
2239
|
+
* GVL.versionedFilename = "vendorlist?getVersion=[VERSION]";
|
|
2240
|
+
* ```
|
|
2241
|
+
*/
|
|
2242
|
+
__publicField(_GVL, "versionedFilename", "archives/vendor-list-v[VERSION].json");
|
|
2243
|
+
/**
|
|
2244
|
+
* @param {string} - Translations of the names and descriptions for Purposes,
|
|
2245
|
+
* Special Purposes, Features, and Special Features to non-English languages
|
|
2246
|
+
* are contained in a file where attributes containing English content
|
|
2247
|
+
* (except vendor declaration information) are translated. The iab publishes
|
|
2248
|
+
* one following the scheme below where the LANG is the iso639-1 language
|
|
2249
|
+
* code. For a list of available translations
|
|
2250
|
+
* [please go here](https://register.consensu.org/Translation).
|
|
2251
|
+
*
|
|
2252
|
+
* eg.
|
|
2253
|
+
* ```javascript
|
|
2254
|
+
* GVL.baseUrl = "http://www.mydomain.com/iabcmp/";
|
|
2255
|
+
* GVL.languageFilename = "purposes?getPurposes=[LANG]";
|
|
2256
|
+
* ```
|
|
2257
|
+
*/
|
|
2258
|
+
__publicField(_GVL, "languageFilename", "purposes-[LANG].json");
|
|
2259
|
+
let GVL = _GVL;
|
|
2260
|
+
class TCModel extends Cloneable {
|
|
2261
|
+
/**
|
|
2262
|
+
* Constructs the TCModel. Passing a [[GVL]] is optional when constructing
|
|
2263
|
+
* as this TCModel may be constructed from decoding an existing encoded
|
|
2264
|
+
* TCString.
|
|
2265
|
+
*
|
|
2266
|
+
* @param {GVL} [gvl]
|
|
2267
|
+
*/
|
|
2268
|
+
constructor(gvl) {
|
|
2269
|
+
super();
|
|
2270
|
+
__publicField(this, "isServiceSpecific_", false);
|
|
2271
|
+
__publicField(this, "supportOOB_", true);
|
|
2272
|
+
__publicField(this, "useNonStandardTexts_", false);
|
|
2273
|
+
__publicField(this, "purposeOneTreatment_", false);
|
|
2274
|
+
__publicField(this, "publisherCountryCode_", "AA");
|
|
2275
|
+
__publicField(this, "version_", 2);
|
|
2276
|
+
__publicField(this, "consentScreen_", 0);
|
|
2277
|
+
__publicField(this, "policyVersion_", 4);
|
|
2278
|
+
__publicField(this, "consentLanguage_", "EN");
|
|
2279
|
+
__publicField(this, "cmpId_", 0);
|
|
2280
|
+
__publicField(this, "cmpVersion_", 0);
|
|
2281
|
+
__publicField(this, "vendorListVersion_", 0);
|
|
2282
|
+
__publicField(this, "numCustomPurposes_", 0);
|
|
2283
|
+
// Member Variable for GVL
|
|
2284
|
+
__publicField(this, "gvl_");
|
|
2285
|
+
__publicField(this, "created");
|
|
2286
|
+
__publicField(this, "lastUpdated");
|
|
2287
|
+
/**
|
|
2288
|
+
* The TCF designates certain Features as special, that is, a CMP must afford
|
|
2289
|
+
* the user a means to opt in to their use. These Special Features are
|
|
2290
|
+
* published and numbered in the GVL separately from normal Features.
|
|
2291
|
+
* Provides for up to 12 special features.
|
|
2292
|
+
*/
|
|
2293
|
+
__publicField(this, "specialFeatureOptins", new Vector());
|
|
2294
|
+
/**
|
|
2295
|
+
* Renamed from `PurposesAllowed` in TCF v1.1
|
|
2296
|
+
* The user’s consent value for each Purpose established on the legal basis
|
|
2297
|
+
* of consent. Purposes are published in the Global Vendor List (see. [[GVL]]).
|
|
2298
|
+
*/
|
|
2299
|
+
__publicField(this, "purposeConsents", new Vector());
|
|
2300
|
+
/**
|
|
2301
|
+
* The user’s permission for each Purpose established on the legal basis of
|
|
2302
|
+
* legitimate interest. If the user has exercised right-to-object for a
|
|
2303
|
+
* purpose.
|
|
2304
|
+
*/
|
|
2305
|
+
__publicField(this, "purposeLegitimateInterests", new Vector());
|
|
2306
|
+
/**
|
|
2307
|
+
* The user’s consent value for each Purpose established on the legal basis
|
|
2308
|
+
* of consent, for the publisher. Purposes are published in the Global
|
|
2309
|
+
* Vendor List.
|
|
2310
|
+
*/
|
|
2311
|
+
__publicField(this, "publisherConsents", new Vector());
|
|
2312
|
+
/**
|
|
2313
|
+
* The user’s permission for each Purpose established on the legal basis of
|
|
2314
|
+
* legitimate interest. If the user has exercised right-to-object for a
|
|
2315
|
+
* purpose.
|
|
2316
|
+
*/
|
|
2317
|
+
__publicField(this, "publisherLegitimateInterests", new Vector());
|
|
2318
|
+
/**
|
|
2319
|
+
* The user’s consent value for each Purpose established on the legal basis
|
|
2320
|
+
* of consent, for the publisher. Purposes are published in the Global
|
|
2321
|
+
* Vendor List.
|
|
2322
|
+
*/
|
|
2323
|
+
__publicField(this, "publisherCustomConsents", new Vector());
|
|
2324
|
+
/**
|
|
2325
|
+
* The user’s permission for each Purpose established on the legal basis of
|
|
2326
|
+
* legitimate interest. If the user has exercised right-to-object for a
|
|
2327
|
+
* purpose that is established in the publisher's custom purposes.
|
|
2328
|
+
*/
|
|
2329
|
+
__publicField(this, "publisherCustomLegitimateInterests", new Vector());
|
|
2330
|
+
/**
|
|
2331
|
+
* set by a publisher if they wish to collect consent and LI Transparency for
|
|
2332
|
+
* purposes outside of the TCF
|
|
2333
|
+
*/
|
|
2334
|
+
__publicField(this, "customPurposes");
|
|
2335
|
+
/**
|
|
2336
|
+
* Each [[Vendor]] is keyed by id. Their consent value is true if it is in
|
|
2337
|
+
* the Vector
|
|
2338
|
+
*/
|
|
2339
|
+
__publicField(this, "vendorConsents", new Vector());
|
|
2340
|
+
/**
|
|
2341
|
+
* Each [[Vendor]] is keyed by id. Whether their Legitimate Interests
|
|
2342
|
+
* Disclosures have been established is stored as boolean.
|
|
2343
|
+
* see: [[Vector]]
|
|
2344
|
+
*/
|
|
2345
|
+
__publicField(this, "vendorLegitimateInterests", new Vector());
|
|
2346
|
+
/**
|
|
2347
|
+
* The value included for disclosed vendors signals which vendors have been
|
|
2348
|
+
* disclosed to the user in the interface surfaced by the CMP. This section
|
|
2349
|
+
* content is required when writing a TC string to the global (consensu)
|
|
2350
|
+
* scope. When a CMP has read from and is updating a TC string from the
|
|
2351
|
+
* global consensu.org storage, the CMP MUST retain the existing disclosure
|
|
2352
|
+
* information and only add information for vendors that it has disclosed
|
|
2353
|
+
* that had not been disclosed by other CMPs in prior interactions with this
|
|
2354
|
+
* device/user agent.
|
|
2355
|
+
*/
|
|
2356
|
+
__publicField(this, "vendorsDisclosed", new Vector());
|
|
2357
|
+
/**
|
|
2358
|
+
* Signals which vendors the publisher permits to use OOB legal bases.
|
|
2359
|
+
*/
|
|
2360
|
+
__publicField(this, "vendorsAllowed", new Vector());
|
|
2361
|
+
__publicField(this, "publisherRestrictions", new PurposeRestrictionVector());
|
|
2362
|
+
if (gvl) {
|
|
2363
|
+
this.gvl = gvl;
|
|
2364
|
+
}
|
|
2365
|
+
this.updated();
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* sets the [[GVL]] with side effects of also setting the `vendorListVersion`, `policyVersion`, and `consentLanguage`
|
|
2369
|
+
* @param {GVL} gvl
|
|
2370
|
+
*/
|
|
2371
|
+
set gvl(gvl) {
|
|
2372
|
+
if (!GVL.isInstanceOf(gvl)) {
|
|
2373
|
+
gvl = new GVL(gvl);
|
|
2374
|
+
}
|
|
2375
|
+
this.gvl_ = gvl;
|
|
2376
|
+
this.publisherRestrictions.gvl = gvl;
|
|
2377
|
+
}
|
|
2378
|
+
/**
|
|
2379
|
+
* @return {GVL} the gvl instance set on this TCModel instance
|
|
2380
|
+
*/
|
|
2381
|
+
get gvl() {
|
|
2382
|
+
return this.gvl_;
|
|
2383
|
+
}
|
|
2384
|
+
/**
|
|
2385
|
+
* @param {number} integer - A unique ID will be assigned to each Consent
|
|
2386
|
+
* Manager Provider (CMP) from the iab.
|
|
2387
|
+
*
|
|
2388
|
+
* @throws {TCModelError} if the value is not an integer greater than 1 as those are not valid.
|
|
2389
|
+
*/
|
|
2390
|
+
set cmpId(integer) {
|
|
2391
|
+
integer = Number(integer);
|
|
2392
|
+
if (Number.isInteger(integer) && integer > 1) {
|
|
2393
|
+
this.cmpId_ = integer;
|
|
2394
|
+
} else {
|
|
2395
|
+
throw new TCModelError("cmpId", integer);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
get cmpId() {
|
|
2399
|
+
return this.cmpId_;
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Each change to an operating CMP should receive a
|
|
2403
|
+
* new version number, for logging proof of consent. CmpVersion defined by
|
|
2404
|
+
* each CMP.
|
|
2405
|
+
*
|
|
2406
|
+
* @param {number} integer
|
|
2407
|
+
*
|
|
2408
|
+
* @throws {TCModelError} if the value is not an integer greater than 1 as those are not valid.
|
|
2409
|
+
*/
|
|
2410
|
+
set cmpVersion(integer) {
|
|
2411
|
+
integer = Number(integer);
|
|
2412
|
+
if (Number.isInteger(integer) && integer > -1) {
|
|
2413
|
+
this.cmpVersion_ = integer;
|
|
2414
|
+
} else {
|
|
2415
|
+
throw new TCModelError("cmpVersion", integer);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
get cmpVersion() {
|
|
2419
|
+
return this.cmpVersion_;
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* The screen number is CMP and CmpVersion
|
|
2423
|
+
* specific, and is for logging proof of consent.(For example, a CMP could
|
|
2424
|
+
* keep records so that a publisher can request information about the context
|
|
2425
|
+
* in which consent was gathered.)
|
|
2426
|
+
*
|
|
2427
|
+
* @param {number} integer
|
|
2428
|
+
*
|
|
2429
|
+
* @throws {TCModelError} if the value is not an integer greater than 0 as those are not valid.
|
|
2430
|
+
*/
|
|
2431
|
+
set consentScreen(integer) {
|
|
2432
|
+
integer = Number(integer);
|
|
2433
|
+
if (Number.isInteger(integer) && integer > -1) {
|
|
2434
|
+
this.consentScreen_ = integer;
|
|
2435
|
+
} else {
|
|
2436
|
+
throw new TCModelError("consentScreen", integer);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
get consentScreen() {
|
|
2440
|
+
return this.consentScreen_;
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* @param {string} lang - [two-letter ISO 639-1 language
|
|
2444
|
+
* code](http://www.loc.gov/standards/iso639-2/php/code_list.php) in which
|
|
2445
|
+
* the CMP UI was presented
|
|
2446
|
+
*
|
|
2447
|
+
* @throws {TCModelError} if the value is not a length-2 string of alpha characters
|
|
2448
|
+
*/
|
|
2449
|
+
set consentLanguage(lang) {
|
|
2450
|
+
this.consentLanguage_ = lang;
|
|
2451
|
+
}
|
|
2452
|
+
get consentLanguage() {
|
|
2453
|
+
return this.consentLanguage_;
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* @param {string} countryCode - [two-letter ISO 3166-1 alpha-2 country
|
|
2457
|
+
* code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the publisher,
|
|
2458
|
+
* determined by the CMP-settings of the publisher.
|
|
2459
|
+
*
|
|
2460
|
+
* @throws {TCModelError} if the value is not a length-2 string of alpha characters
|
|
2461
|
+
*/
|
|
2462
|
+
set publisherCountryCode(countryCode) {
|
|
2463
|
+
if (/^([A-z]){2}$/.test(countryCode)) {
|
|
2464
|
+
this.publisherCountryCode_ = countryCode.toUpperCase();
|
|
2465
|
+
} else {
|
|
2466
|
+
throw new TCModelError("publisherCountryCode", countryCode);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
get publisherCountryCode() {
|
|
2470
|
+
return this.publisherCountryCode_;
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Version of the GVL used to create this TCModel. Global
|
|
2474
|
+
* Vendor List versions will be released periodically.
|
|
2475
|
+
*
|
|
2476
|
+
* @param {number} integer
|
|
2477
|
+
*
|
|
2478
|
+
* @throws {TCModelError} if the value is not an integer greater than 0 as those are not valid.
|
|
2479
|
+
*/
|
|
2480
|
+
set vendorListVersion(integer) {
|
|
2481
|
+
integer = Number(integer) >> 0;
|
|
2482
|
+
if (integer < 0) {
|
|
2483
|
+
throw new TCModelError("vendorListVersion", integer);
|
|
2484
|
+
} else {
|
|
2485
|
+
this.vendorListVersion_ = integer;
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
get vendorListVersion() {
|
|
2489
|
+
if (this.gvl) {
|
|
2490
|
+
return this.gvl.vendorListVersion;
|
|
2491
|
+
} else {
|
|
2492
|
+
return this.vendorListVersion_;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* From the corresponding field in the GVL that was
|
|
2497
|
+
* used for obtaining consent. A new policy version invalidates existing
|
|
2498
|
+
* strings and requires CMPs to re-establish transparency and consent from
|
|
2499
|
+
* users.
|
|
2500
|
+
*
|
|
2501
|
+
* If a TCF policy version number is different from the one from the latest
|
|
2502
|
+
* GVL, the CMP must re-establish transparency and consent.
|
|
2503
|
+
*
|
|
2504
|
+
* @param {number} num - You do not need to set this. This comes
|
|
2505
|
+
* directly from the [[GVL]].
|
|
2506
|
+
*
|
|
2507
|
+
*/
|
|
2508
|
+
set policyVersion(num) {
|
|
2509
|
+
this.policyVersion_ = parseInt(num, 10);
|
|
2510
|
+
if (this.policyVersion_ < 0) {
|
|
2511
|
+
throw new TCModelError("policyVersion", num);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
get policyVersion() {
|
|
2515
|
+
if (this.gvl) {
|
|
2516
|
+
return this.gvl.tcfPolicyVersion;
|
|
2517
|
+
} else {
|
|
2518
|
+
return this.policyVersion_;
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
set version(num) {
|
|
2522
|
+
this.version_ = parseInt(num, 10);
|
|
2523
|
+
}
|
|
2524
|
+
get version() {
|
|
2525
|
+
return this.version_;
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* Whether the signals encoded in this TC String were from site-specific
|
|
2529
|
+
* storage `true` versus ‘global’ consensu.org shared storage `false`. A
|
|
2530
|
+
* string intended to be stored in global/shared scope but the CMP is unable
|
|
2531
|
+
* to store due to a user agent not accepting third-party cookies would be
|
|
2532
|
+
* considered site-specific `true`.
|
|
2533
|
+
*
|
|
2534
|
+
* @param {boolean} bool - value to set. Some changes to other fields in this
|
|
2535
|
+
* model will automatically change this value like adding publisher
|
|
2536
|
+
* restrictions.
|
|
2537
|
+
*/
|
|
2538
|
+
set isServiceSpecific(bool) {
|
|
2539
|
+
this.isServiceSpecific_ = bool;
|
|
2540
|
+
}
|
|
2541
|
+
get isServiceSpecific() {
|
|
2542
|
+
return this.isServiceSpecific_;
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Non-standard stacks means that a CMP is using publisher-customized stack
|
|
2546
|
+
* descriptions. Stacks (in terms of purposes in a stack) are pre-set by the
|
|
2547
|
+
* IAB. As are titles. Descriptions are pre-set, but publishers can customize
|
|
2548
|
+
* them. If they do, they need to set this bit to indicate that they've
|
|
2549
|
+
* customized descriptions.
|
|
2550
|
+
*
|
|
2551
|
+
* @param {boolean} bool - value to set
|
|
2552
|
+
*/
|
|
2553
|
+
set useNonStandardTexts(bool) {
|
|
2554
|
+
this.useNonStandardTexts_ = bool;
|
|
2555
|
+
}
|
|
2556
|
+
get useNonStandardTexts() {
|
|
2557
|
+
return this.useNonStandardTexts_;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Whether or not this publisher supports OOB signaling. On Global TC String
|
|
2561
|
+
* OOB Vendors Disclosed will be included if the publish wishes to no allow
|
|
2562
|
+
* these vendors they should set this to false.
|
|
2563
|
+
* @param {boolean} bool - value to set
|
|
2564
|
+
*/
|
|
2565
|
+
set supportOOB(bool) {
|
|
2566
|
+
this.supportOOB_ = bool;
|
|
2567
|
+
}
|
|
2568
|
+
get supportOOB() {
|
|
2569
|
+
return this.supportOOB_;
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
* `false` There is no special Purpose 1 status.
|
|
2573
|
+
* Purpose 1 was disclosed normally (consent) as expected by Policy. `true`
|
|
2574
|
+
* Purpose 1 not disclosed at all. CMPs use PublisherCC to indicate the
|
|
2575
|
+
* publisher’s country of establishment to help Vendors determine whether the
|
|
2576
|
+
* vendor requires Purpose 1 consent. In global scope TC strings, this field
|
|
2577
|
+
* must always have a value of `false`. When a CMP encounters a global scope
|
|
2578
|
+
* string with `purposeOneTreatment=true` then that string should be
|
|
2579
|
+
* considered invalid and the CMP must re-establish transparency and consent.
|
|
2580
|
+
*
|
|
2581
|
+
* @param {boolean} bool
|
|
2582
|
+
*/
|
|
2583
|
+
set purposeOneTreatment(bool) {
|
|
2584
|
+
this.purposeOneTreatment_ = bool;
|
|
2585
|
+
}
|
|
2586
|
+
get purposeOneTreatment() {
|
|
2587
|
+
return this.purposeOneTreatment_;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* setAllVendorConsents - sets all vendors on the GVL Consent (true)
|
|
2591
|
+
*
|
|
2592
|
+
* @return {void}
|
|
2593
|
+
*/
|
|
2594
|
+
setAllVendorConsents() {
|
|
2595
|
+
this.vendorConsents.set(this.gvl.vendors);
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* unsetAllVendorConsents - unsets all vendors on the GVL Consent (false)
|
|
2599
|
+
*
|
|
2600
|
+
* @return {void}
|
|
2601
|
+
*/
|
|
2602
|
+
unsetAllVendorConsents() {
|
|
2603
|
+
this.vendorConsents.empty();
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* setAllVendorsDisclosed - sets all vendors on the GVL Vendors Disclosed (true)
|
|
2607
|
+
*
|
|
2608
|
+
* @return {void}
|
|
2609
|
+
*/
|
|
2610
|
+
setAllVendorsDisclosed() {
|
|
2611
|
+
this.vendorsDisclosed.set(this.gvl.vendors);
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* unsetAllVendorsDisclosed - unsets all vendors on the GVL Consent (false)
|
|
2615
|
+
*
|
|
2616
|
+
* @return {void}
|
|
2617
|
+
*/
|
|
2618
|
+
unsetAllVendorsDisclosed() {
|
|
2619
|
+
this.vendorsDisclosed.empty();
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* setAllVendorsAllowed - sets all vendors on the GVL Consent (true)
|
|
2623
|
+
*
|
|
2624
|
+
* @return {void}
|
|
2625
|
+
*/
|
|
2626
|
+
setAllVendorsAllowed() {
|
|
2627
|
+
this.vendorsAllowed.set(this.gvl.vendors);
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* unsetAllVendorsAllowed - unsets all vendors on the GVL Consent (false)
|
|
2631
|
+
*
|
|
2632
|
+
* @return {void}
|
|
2633
|
+
*/
|
|
2634
|
+
unsetAllVendorsAllowed() {
|
|
2635
|
+
this.vendorsAllowed.empty();
|
|
2636
|
+
}
|
|
2637
|
+
/**
|
|
2638
|
+
* setAllVendorLegitimateInterests - sets all vendors on the GVL LegitimateInterests (true)
|
|
2639
|
+
*
|
|
2640
|
+
* @return {void}
|
|
2641
|
+
*/
|
|
2642
|
+
setAllVendorLegitimateInterests() {
|
|
2643
|
+
this.vendorLegitimateInterests.set(this.gvl.vendors);
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* unsetAllVendorLegitimateInterests - unsets all vendors on the GVL LegitimateInterests (false)
|
|
2647
|
+
*
|
|
2648
|
+
* @return {void}
|
|
2649
|
+
*/
|
|
2650
|
+
unsetAllVendorLegitimateInterests() {
|
|
2651
|
+
this.vendorLegitimateInterests.empty();
|
|
2652
|
+
}
|
|
2653
|
+
/**
|
|
2654
|
+
* setAllPurposeConsents - sets all purposes on the GVL Consent (true)
|
|
2655
|
+
*
|
|
2656
|
+
* @return {void}
|
|
2657
|
+
*/
|
|
2658
|
+
setAllPurposeConsents() {
|
|
2659
|
+
this.purposeConsents.set(this.gvl.purposes);
|
|
2660
|
+
}
|
|
2661
|
+
/**
|
|
2662
|
+
* unsetAllPurposeConsents - unsets all purposes on the GVL Consent (false)
|
|
2663
|
+
*
|
|
2664
|
+
* @return {void}
|
|
2665
|
+
*/
|
|
2666
|
+
unsetAllPurposeConsents() {
|
|
2667
|
+
this.purposeConsents.empty();
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2670
|
+
* setAllPurposeLegitimateInterests - sets all purposes on the GVL LI Transparency (true)
|
|
2671
|
+
*
|
|
2672
|
+
* @return {void}
|
|
2673
|
+
*/
|
|
2674
|
+
setAllPurposeLegitimateInterests() {
|
|
2675
|
+
this.purposeLegitimateInterests.set(this.gvl.purposes);
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* unsetAllPurposeLegitimateInterests - unsets all purposes on the GVL LI Transparency (false)
|
|
2679
|
+
*
|
|
2680
|
+
* @return {void}
|
|
2681
|
+
*/
|
|
2682
|
+
unsetAllPurposeLegitimateInterests() {
|
|
2683
|
+
this.purposeLegitimateInterests.empty();
|
|
2684
|
+
}
|
|
2685
|
+
/**
|
|
2686
|
+
* setAllSpecialFeatureOptins - sets all special featuresOptins on the GVL (true)
|
|
2687
|
+
*
|
|
2688
|
+
* @return {void}
|
|
2689
|
+
*/
|
|
2690
|
+
setAllSpecialFeatureOptins() {
|
|
2691
|
+
this.specialFeatureOptins.set(this.gvl.specialFeatures);
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* unsetAllSpecialFeatureOptins - unsets all special featuresOptins on the GVL (true)
|
|
2695
|
+
*
|
|
2696
|
+
* @return {void}
|
|
2697
|
+
*/
|
|
2698
|
+
unsetAllSpecialFeatureOptins() {
|
|
2699
|
+
this.specialFeatureOptins.empty();
|
|
2700
|
+
}
|
|
2701
|
+
setAll() {
|
|
2702
|
+
this.setAllVendorConsents();
|
|
2703
|
+
this.setAllPurposeLegitimateInterests();
|
|
2704
|
+
this.setAllSpecialFeatureOptins();
|
|
2705
|
+
this.setAllPurposeConsents();
|
|
2706
|
+
this.setAllVendorLegitimateInterests();
|
|
2707
|
+
}
|
|
2708
|
+
unsetAll() {
|
|
2709
|
+
this.unsetAllVendorConsents();
|
|
2710
|
+
this.unsetAllPurposeLegitimateInterests();
|
|
2711
|
+
this.unsetAllSpecialFeatureOptins();
|
|
2712
|
+
this.unsetAllPurposeConsents();
|
|
2713
|
+
this.unsetAllVendorLegitimateInterests();
|
|
2714
|
+
}
|
|
2715
|
+
get numCustomPurposes() {
|
|
2716
|
+
let len = this.numCustomPurposes_;
|
|
2717
|
+
if (typeof this.customPurposes === "object") {
|
|
2718
|
+
const purposeIds = Object.keys(this.customPurposes).sort((a, b) => Number(a) - Number(b));
|
|
2719
|
+
len = parseInt(purposeIds.pop(), 10);
|
|
2720
|
+
}
|
|
2721
|
+
return len;
|
|
2722
|
+
}
|
|
2723
|
+
set numCustomPurposes(num) {
|
|
2724
|
+
this.numCustomPurposes_ = parseInt(num, 10);
|
|
2725
|
+
if (this.numCustomPurposes_ < 0) {
|
|
2726
|
+
throw new TCModelError("numCustomPurposes", num);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
/**
|
|
2730
|
+
* updated - updates the created and lastUpdated dates with a 'now' day-level UTC timestamp
|
|
2731
|
+
*
|
|
2732
|
+
* @return {void}
|
|
2733
|
+
*/
|
|
2734
|
+
updated() {
|
|
2735
|
+
const date = /* @__PURE__ */ new Date();
|
|
2736
|
+
const utcDate = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
2737
|
+
this.created = utcDate;
|
|
2738
|
+
this.lastUpdated = utcDate;
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
/**
|
|
2742
|
+
* Set of available consent languages published by the IAB
|
|
2743
|
+
*/
|
|
2744
|
+
__publicField(TCModel, "consentLanguages", GVL.consentLanguages);
|
|
2745
|
+
class TCString {
|
|
2746
|
+
/**
|
|
2747
|
+
* encodes a model into a TCString
|
|
2748
|
+
*
|
|
2749
|
+
* @param {TCModel} tcModel - model to convert into encoded string
|
|
2750
|
+
* @param {EncodingOptions} options - for encoding options other than default
|
|
2751
|
+
* @return {string} - base64url encoded Transparency and Consent String
|
|
2752
|
+
*/
|
|
2753
|
+
static encode(tcModel, options) {
|
|
2754
|
+
let out = "";
|
|
2755
|
+
let sequence;
|
|
2756
|
+
tcModel = SemanticPreEncoder.process(tcModel, options);
|
|
2757
|
+
if (Array.isArray(options == null ? void 0 : options.segments)) {
|
|
2758
|
+
sequence = options.segments;
|
|
2759
|
+
} else {
|
|
2760
|
+
sequence = new SegmentSequence(tcModel, options)["" + tcModel.version];
|
|
2761
|
+
}
|
|
2762
|
+
sequence.forEach((segment, idx) => {
|
|
2763
|
+
let dotMaybe = "";
|
|
2764
|
+
if (idx < sequence.length - 1) {
|
|
2765
|
+
dotMaybe = ".";
|
|
2766
|
+
}
|
|
2767
|
+
out += SegmentEncoder.encode(tcModel, segment) + dotMaybe;
|
|
2768
|
+
});
|
|
2769
|
+
return out;
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* Decodes a string into a TCModel
|
|
2773
|
+
*
|
|
2774
|
+
* @param {string} encodedTCString - base64url encoded Transparency and
|
|
2775
|
+
* Consent String to decode - can also be a single or group of segments of
|
|
2776
|
+
* the string
|
|
2777
|
+
* @param {string} [tcModel] - model to enhance with the information. If
|
|
2778
|
+
* none is passed a new instance of TCModel will be created.
|
|
2779
|
+
* @return {TCModel} - Returns populated TCModel
|
|
2780
|
+
*/
|
|
2781
|
+
static decode(encodedTCString, tcModel) {
|
|
2782
|
+
const segments = encodedTCString.split(".");
|
|
2783
|
+
const len = segments.length;
|
|
2784
|
+
if (!tcModel) {
|
|
2785
|
+
tcModel = new TCModel();
|
|
2786
|
+
}
|
|
2787
|
+
for (let i = 0; i < len; i++) {
|
|
2788
|
+
const segString = segments[i];
|
|
2789
|
+
const firstChar = Base64Url.decode(segString.charAt(0));
|
|
2790
|
+
const segTypeBits = firstChar.substr(0, BitLength.segmentType);
|
|
2791
|
+
const segment = SegmentIDs.ID_TO_KEY[IntEncoder.decode(segTypeBits, BitLength.segmentType).toString()];
|
|
2792
|
+
SegmentEncoder.decode(segString, tcModel, segment);
|
|
2793
|
+
}
|
|
2794
|
+
return tcModel;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
function isValidGdprValue(val) {
|
|
2798
|
+
if (val === null) {
|
|
2799
|
+
return true;
|
|
2800
|
+
}
|
|
2801
|
+
try {
|
|
2802
|
+
TCString.decode(val);
|
|
2803
|
+
return true;
|
|
2804
|
+
} catch (error) {
|
|
2805
|
+
return false;
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
function isValidUspString(val) {
|
|
2809
|
+
if (val === null) {
|
|
2810
|
+
return true;
|
|
2811
|
+
}
|
|
2812
|
+
const regex = /^[1-9][YN-][YN-][YN-]$/;
|
|
2813
|
+
return regex.test(val);
|
|
2814
|
+
}
|
|
2815
|
+
function validateRawConsentState(input) {
|
|
2816
|
+
if (typeof input !== "object" || input === null) {
|
|
2817
|
+
throw new Error("Invalid consent state object");
|
|
2818
|
+
}
|
|
2819
|
+
if (!isValidGdprValue(input.gdpr)) {
|
|
2820
|
+
throw new Error("Invalid TC string provided");
|
|
2821
|
+
}
|
|
2822
|
+
if (!isValidUspString(input.ccpa)) {
|
|
2823
|
+
throw new Error("Invalid USP string provided");
|
|
2824
|
+
}
|
|
2825
|
+
if (!["ccpa", "gdpr"].includes(input.activeLegislation)) {
|
|
2826
|
+
throw new Error("Active legislation is required");
|
|
2827
|
+
}
|
|
2828
|
+
if (input.gdpr === void 0 && input.ccpa === void 0) {
|
|
2829
|
+
throw new Error("Either GDPR or CCPA consent must be provided");
|
|
2830
|
+
}
|
|
2831
|
+
return true;
|
|
2832
|
+
}
|
|
2833
|
+
function validateIabConsentCategory(categoryName) {
|
|
2834
|
+
if (!categoryName || categoryName in iabCustomCategories === false) {
|
|
2835
|
+
throw new Error("Provided custom category identifier does not exist. Please check");
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
function checkConsentFor(categoryName, consentState) {
|
|
2839
|
+
validateIabConsentCategory(categoryName);
|
|
2840
|
+
validateRawConsentState(consentState);
|
|
2841
|
+
const { gdpr, ccpa, activeLegislation } = consentState;
|
|
2842
|
+
const customCategory = iabCustomCategories[categoryName];
|
|
2843
|
+
if (activeLegislation === legislation.CCPA) {
|
|
2844
|
+
const userHasNotOptedOut = (ccpa == null ? void 0 : ccpa[2]) === "N";
|
|
2845
|
+
return userHasNotOptedOut;
|
|
2846
|
+
}
|
|
2847
|
+
const decodedGdprConsent = TCString.decode(gdpr);
|
|
2848
|
+
const { purposeConsents, vendorConsents, specialFeatureOptins } = decodedGdprConsent;
|
|
2849
|
+
const requiredPurposesConsented = customCategory.purposes.every(
|
|
2850
|
+
(requiredPurpose) => purposeConsents.has(requiredPurpose)
|
|
2851
|
+
);
|
|
2852
|
+
const requiredIabVendorsConsented = customCategory.iabVendors.every(
|
|
2853
|
+
(requiredVendor) => vendorConsents.has(requiredVendor)
|
|
2854
|
+
);
|
|
2855
|
+
const requiredSpecialFeaturesConsented = customCategory.specialFeatures.every(
|
|
2856
|
+
(requiredFeature) => specialFeatureOptins.has(requiredFeature)
|
|
2857
|
+
);
|
|
2858
|
+
return requiredPurposesConsented && requiredIabVendorsConsented && requiredSpecialFeaturesConsented;
|
|
2859
|
+
}
|
|
2860
|
+
function getParsedConsent(rawConsentState) {
|
|
2861
|
+
const categoryNames = Object.keys(iabCustomCategories);
|
|
2862
|
+
return categoryNames.reduce((parsedConsent, categoryName) => {
|
|
2863
|
+
parsedConsent[categoryName] = checkConsentFor(categoryName, rawConsentState);
|
|
2864
|
+
return parsedConsent;
|
|
2865
|
+
}, {});
|
|
2866
|
+
}
|
|
2867
|
+
function getConsentCookieValue() {
|
|
2868
|
+
const cookies = Object.fromEntries(
|
|
2869
|
+
document.cookie.split("; ").map((cookie) => cookie.split("="))
|
|
2870
|
+
);
|
|
2871
|
+
const encodedValue = cookies[CONSENT_COOKIE_NAME];
|
|
2872
|
+
if (!encodedValue)
|
|
2873
|
+
return {};
|
|
2874
|
+
const decodedValue = decodeURIComponent(encodedValue);
|
|
2875
|
+
return Object.fromEntries(
|
|
2876
|
+
decodedValue.split(",").map((consent) => {
|
|
2877
|
+
const [category, value] = consent.split(":");
|
|
2878
|
+
const booleanConsent = [category, value === "on" ? true : false];
|
|
2879
|
+
return booleanConsent;
|
|
2880
|
+
})
|
|
2881
|
+
);
|
|
2882
|
+
}
|
|
2883
|
+
function hasConsentChanged(parsedConsent) {
|
|
2884
|
+
const categories = Object.keys(parsedConsent);
|
|
2885
|
+
const previousConsent = getConsentCookieValue();
|
|
2886
|
+
return categories.some((category) => {
|
|
2887
|
+
const adaptedCategoryName = `${category.toLowerCase()}Onsite`;
|
|
2888
|
+
return parsedConsent[category] !== previousConsent[adaptedCategoryName];
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
async function saveConsent(consentEndpoint, payload) {
|
|
2892
|
+
try {
|
|
2893
|
+
const response = await fetch(consentEndpoint, {
|
|
2894
|
+
method: "POST",
|
|
2895
|
+
headers: {
|
|
2896
|
+
"Content-Type": "application/json"
|
|
2897
|
+
},
|
|
2898
|
+
body: JSON.stringify(payload),
|
|
2899
|
+
credentials: "include"
|
|
2900
|
+
});
|
|
2901
|
+
if (!response.ok) {
|
|
2902
|
+
console.error("Unable to save consent preferences", response.status);
|
|
2903
|
+
}
|
|
2904
|
+
} catch (error) {
|
|
2905
|
+
console.error("An error occurred while saving consent", error);
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
function consentReadyHandlerFn(props) {
|
|
2909
|
+
const { userId, consentProxyHost, cookieDomain, formOfWordsId, useConsentStore } = props;
|
|
2910
|
+
return async function consentReadyHandler(legislation2, _consentUUID, consentString, consentMeta) {
|
|
2911
|
+
const activeLegislation = consentMeta.applies ? legislation2 : "gdpr";
|
|
2912
|
+
if (activeLegislation !== legislation2 || !consentString) {
|
|
2913
|
+
return;
|
|
2914
|
+
}
|
|
2915
|
+
const parsedConsent = getParsedConsent({
|
|
2916
|
+
activeLegislation,
|
|
2917
|
+
gdpr: activeLegislation === "gdpr" ? consentString : null,
|
|
2918
|
+
ccpa: activeLegislation === "ccpa" ? consentString : null
|
|
2919
|
+
});
|
|
2920
|
+
const consentHasChanged = hasConsentChanged(parsedConsent);
|
|
2921
|
+
if (!consentHasChanged) {
|
|
2922
|
+
return;
|
|
2923
|
+
}
|
|
2924
|
+
let consentEndpoint = `${consentProxyHost}/__consent/consent-record-cookie?cookieDomain=${cookieDomain}`;
|
|
2925
|
+
const shouldUpdateConsentStore = !!userId && useConsentStore;
|
|
2926
|
+
if (shouldUpdateConsentStore) {
|
|
2927
|
+
consentEndpoint = `${consentProxyHost}/__consent/consent-record/${SOURCEPOINT_FOW_SCOPE}/${userId}`;
|
|
2928
|
+
}
|
|
2929
|
+
const payload = getConsentPayload(parsedConsent, {
|
|
2930
|
+
formOfWordsId,
|
|
2931
|
+
cookieDomain,
|
|
2932
|
+
shouldUpdateConsentStore
|
|
2933
|
+
});
|
|
2934
|
+
await saveConsent(consentEndpoint, payload);
|
|
2935
|
+
document.dispatchEvent(new CustomEvent("oCookieMessage.act", { bubbles: true }));
|
|
2936
|
+
};
|
|
2937
|
+
}
|
|
2938
|
+
async function initSourcepointCmp({
|
|
2939
|
+
propertyConfig = FT_DOTCOM_PROD,
|
|
2940
|
+
userId,
|
|
2941
|
+
useFTSession = true,
|
|
2942
|
+
consentProxyHost = FT_CONSENT_PROXY_HOST,
|
|
2943
|
+
cookieDomain = FT_COOKIE_DOMAIN,
|
|
2944
|
+
formOfWordsId = SOURCEPOINT_FOW_ID,
|
|
2945
|
+
useConsentStore = true
|
|
2946
|
+
} = {}) {
|
|
2947
|
+
var _a2;
|
|
2948
|
+
if (!userId && useFTSession) {
|
|
2949
|
+
try {
|
|
2950
|
+
const response = await getUuid();
|
|
2951
|
+
userId = response == null ? void 0 : response.uuid;
|
|
2952
|
+
} catch (error) {
|
|
2953
|
+
console.error(error);
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
if (!(propertyConfig == null ? void 0 : propertyConfig.accountId)) {
|
|
2957
|
+
throw new Error("Please pass a valid property config");
|
|
2958
|
+
}
|
|
2959
|
+
if (userId) {
|
|
2960
|
+
propertyConfig.authId = userId;
|
|
2961
|
+
}
|
|
2962
|
+
if ((_a2 = propertyConfig.events) == null ? void 0 : _a2.onConsentReady) {
|
|
2963
|
+
console.warn("[cmp-client] The supplied 'onConsentReady' event handler will be overwritten.");
|
|
2964
|
+
}
|
|
2965
|
+
const events2 = {
|
|
2966
|
+
...propertyConfig.events ?? {},
|
|
2967
|
+
onConsentReady: consentReadyHandlerFn({
|
|
2968
|
+
userId,
|
|
2969
|
+
consentProxyHost,
|
|
2970
|
+
cookieDomain,
|
|
2971
|
+
formOfWordsId,
|
|
2972
|
+
useConsentStore
|
|
2973
|
+
})
|
|
2974
|
+
};
|
|
2975
|
+
function getCookie(name) {
|
|
2976
|
+
const value = `; ${document.cookie}`;
|
|
2977
|
+
const parts = value.split(`; ${name}=`);
|
|
2978
|
+
if (parts.length === 2)
|
|
2979
|
+
return parts.pop().split(";").shift();
|
|
2980
|
+
}
|
|
2981
|
+
propertyConfig.gdpr = {
|
|
2982
|
+
targetingParams: {
|
|
2983
|
+
// @ts-ignore
|
|
2984
|
+
"cookiew": getCookie("cw")
|
|
2985
|
+
}
|
|
2986
|
+
};
|
|
2987
|
+
bootstrapCmp({ ...propertyConfig, events: events2 });
|
|
2988
|
+
}
|
|
2989
|
+
window.FT_CMP_CLIENT_VERSION = version;
|
|
2990
|
+
exports.debug = debug;
|
|
2991
|
+
exports.initSourcepointCmp = initSourcepointCmp;
|
|
2992
|
+
exports.properties = properties;
|
|
2993
|
+
exports.updateFooterLinkCMP = updateFooterLinkCMP;
|