@blotoutio/edgetag-sdk-browser 0.5.2 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +2 -0
  2. package/index.js +1116 -0
  3. package/package.json +3 -12
  4. package/index.cjs +0 -1
package/README.md CHANGED
@@ -1 +1,3 @@
1
1
  # EdgeTag SDK Browser
2
+
3
+ More info on https://app.edgetag.io/integration/js
package/index.js ADDED
@@ -0,0 +1,1116 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+
19
+ function __awaiter(thisArg, _arguments, P, generator) {
20
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
+ return new (P || (P = Promise))(function (resolve, reject) {
22
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ }
28
+
29
+ const tagStorage = 'edgeTag';
30
+ const consentKey = 'consent';
31
+ const providersKey = 'providers';
32
+ const keyPrefix = `_worker`;
33
+
34
+ const initKey = `${keyPrefix}Store`;
35
+ const getCookieValue = (key) => {
36
+ if (!document || !document.cookie) {
37
+ return '';
38
+ }
39
+ const name = `${key}=`;
40
+ const decodedCookie = decodeURIComponent(document.cookie);
41
+ const ca = decodedCookie.split(';');
42
+ for (let i = 0; i < ca.length; i++) {
43
+ let c = ca[i];
44
+ while (c.charAt(0) === ' ') {
45
+ c = c.substring(1);
46
+ }
47
+ if (c.indexOf(name) === 0) {
48
+ return c.substring(name.length, c.length);
49
+ }
50
+ }
51
+ return '';
52
+ };
53
+ const saveDataPerKey = (persistType, provider, value, key) => {
54
+ const storage = getData$1(persistType);
55
+ if (!storage['data']) {
56
+ storage['data'] = {};
57
+ }
58
+ if (!storage['data'][provider]) {
59
+ storage['data'][provider] = {};
60
+ }
61
+ storage['data'][provider][key] = value;
62
+ saveData(persistType, storage);
63
+ };
64
+ const savePerKey = (persistType, provider, value, key) => {
65
+ const storage = getData$1(persistType);
66
+ if (!storage[provider]) {
67
+ storage[provider] = {};
68
+ }
69
+ storage[provider][key] = value;
70
+ saveData(persistType, storage);
71
+ };
72
+ const getDataPerKey = (persistType, provider, key) => {
73
+ const storage = getData$1(persistType);
74
+ if (!storage[provider]) {
75
+ return undefined;
76
+ }
77
+ return storage[provider][key];
78
+ };
79
+ const saveData = (persistType, value, key = initKey) => {
80
+ if (persistType === 'session') {
81
+ saveSession(value, key);
82
+ return;
83
+ }
84
+ saveLocal(value, key);
85
+ };
86
+ const getData$1 = (persistType, key = initKey) => {
87
+ if (persistType === 'session') {
88
+ return getSession(key);
89
+ }
90
+ return getLocal(key);
91
+ };
92
+ const saveKV = (data) => {
93
+ let currentSession = getData$1('session');
94
+ if (!currentSession) {
95
+ currentSession = {};
96
+ }
97
+ if (!currentSession['kv']) {
98
+ currentSession['kv'] = {};
99
+ }
100
+ currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
101
+ saveData('session', currentSession);
102
+ };
103
+ const saveLocal = (value, key) => {
104
+ localStorage.setItem(key, JSON.stringify(value));
105
+ };
106
+ const getLocal = (key) => {
107
+ const data = localStorage.getItem(key);
108
+ if (!data) {
109
+ return {};
110
+ }
111
+ return JSON.parse(data) || {};
112
+ };
113
+ const saveSession = (value, key) => {
114
+ sessionStorage.setItem(key, JSON.stringify(value));
115
+ };
116
+ const getSession = (key) => {
117
+ const data = sessionStorage.getItem(key);
118
+ if (!data) {
119
+ return {};
120
+ }
121
+ return JSON.parse(data) || {};
122
+ };
123
+
124
+ let endpointUrl = '';
125
+ const generateUrl = (path) => {
126
+ const endpoint = getUrl();
127
+ if (!endpoint) {
128
+ console.log('URL is not valid');
129
+ return '';
130
+ }
131
+ return `${endpoint}${path}`;
132
+ };
133
+ const getUrl = () => {
134
+ return endpointUrl;
135
+ };
136
+ const setUrl = (url) => {
137
+ if (url == null) {
138
+ return;
139
+ }
140
+ endpointUrl = url;
141
+ };
142
+ const getTagURL = () => {
143
+ return generateUrl('/tag');
144
+ };
145
+ const getInitURL = () => {
146
+ return generateUrl('/init');
147
+ };
148
+ const getConsentURL = () => {
149
+ return generateUrl('/consent');
150
+ };
151
+ const getUserURL = () => {
152
+ return generateUrl('/user');
153
+ };
154
+ const getDataURL = () => {
155
+ return generateUrl(`/data`);
156
+ };
157
+ const getGetDataURL = (keys) => {
158
+ return generateUrl(`/data?keys=${encodeURIComponent(keys.join(','))}`);
159
+ };
160
+ const getKeysURL = () => {
161
+ return generateUrl(`/keys`);
162
+ };
163
+
164
+ let consentDisabled = false;
165
+ let providers = [];
166
+ const setPreferences = (preferences) => {
167
+ if (!preferences) {
168
+ return false;
169
+ }
170
+ if (!preferences.edgeURL) {
171
+ console.error('Please provide URL for EdgeTag');
172
+ return false;
173
+ }
174
+ consentDisabled = !!preferences.disableConsentCheck;
175
+ providers = preferences.providers || [];
176
+ if (window && window.edgetagPackages) {
177
+ providers = [...window.edgetagPackages, ...providers];
178
+ }
179
+ setUrl(preferences.edgeURL);
180
+ return true;
181
+ };
182
+ const isConsentDisabled = () => consentDisabled;
183
+ const getProvidersPackage = () => providers;
184
+
185
+ const getUserAgent = () => {
186
+ const nav = navigator;
187
+ let ua = nav.userAgent;
188
+ ua += nav.brave ? `${ua} Brave` : '';
189
+ return ua;
190
+ };
191
+ const allowTag = (providers) => {
192
+ const consent = getDataPerKey('local', tagStorage, consentKey);
193
+ if (isConsentDisabled()) {
194
+ return true;
195
+ }
196
+ if (!consent) {
197
+ return false;
198
+ }
199
+ if (consent['all']) {
200
+ return true;
201
+ }
202
+ if (!providers) {
203
+ return (Object.values(consent).find((isAllowed) => isAllowed) || false);
204
+ }
205
+ const allProviders = (getDataPerKey('local', tagStorage, providersKey) ||
206
+ []);
207
+ for (const provider of allProviders) {
208
+ const tagProviderSetting = providers[provider];
209
+ if (tagProviderSetting ||
210
+ (providers['all'] === true && tagProviderSetting === undefined) ||
211
+ (providers['all'] === false && tagProviderSetting === true)) {
212
+ if (consent[provider]) {
213
+ return true;
214
+ }
215
+ }
216
+ }
217
+ return false;
218
+ };
219
+ const allowProvider = (providers, providerId) => {
220
+ const consent = getDataPerKey('local', tagStorage, consentKey);
221
+ if (isConsentDisabled()) {
222
+ return true;
223
+ }
224
+ if (!consent) {
225
+ return false;
226
+ }
227
+ if (consent['all']) {
228
+ return true;
229
+ }
230
+ if (!providers) {
231
+ return consent[providerId];
232
+ }
233
+ const tagProvider = providers[providerId];
234
+ if (tagProvider ||
235
+ (providers['all'] === true && tagProvider === undefined) ||
236
+ (providers['all'] === false && tagProvider === true)) {
237
+ if (consent[providerId]) {
238
+ return true;
239
+ }
240
+ }
241
+ return false;
242
+ };
243
+
244
+ const beacon = (url, payload) => {
245
+ let blob;
246
+ if (payload) {
247
+ blob = new Blob([JSON.stringify(payload)], { type: 'application/json' });
248
+ }
249
+ return navigator.sendBeacon(url, blob);
250
+ };
251
+ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
252
+ return yield fetch(url, {
253
+ method,
254
+ headers: {
255
+ 'Content-type': 'application/json; charset=utf-8',
256
+ Accept: 'application/json; charset=utf-8',
257
+ },
258
+ body: JSON.stringify(payload),
259
+ credentials: 'include',
260
+ })
261
+ .then((response) => response.json().then((data) => ({ status: response.status, body: data })))
262
+ .then((data) => {
263
+ if (data.status < 200 || data.status >= 300) {
264
+ // Q: do we need to retry?
265
+ return Promise.reject(new Error(JSON.stringify(data.body)));
266
+ }
267
+ return Promise.resolve(data.body);
268
+ })
269
+ .catch((error) => {
270
+ // Q: do we need to retry?
271
+ return Promise.reject(new Error(error));
272
+ });
273
+ });
274
+ const getStandardPayload = (payload) => {
275
+ const data = Object.assign({ pageUrl: window.location.href, userAgent: getUserAgent() }, (payload || {}));
276
+ let storage = {};
277
+ const session = getData$1('session');
278
+ if (session) {
279
+ storage = Object.assign(Object.assign({}, storage), session);
280
+ }
281
+ const local = getData$1('local');
282
+ if (local) {
283
+ storage = Object.assign(Object.assign({}, storage), local);
284
+ }
285
+ data.storage = storage;
286
+ return data;
287
+ };
288
+ function postRequest(url, data, options) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ if (!url) {
291
+ return Promise.reject(new Error('URL is empty'));
292
+ }
293
+ const payload = getStandardPayload(data);
294
+ if (options && options.method === 'beacon') {
295
+ return Promise.resolve(beacon(url, payload));
296
+ }
297
+ return yield ajax('POST', url, payload);
298
+ });
299
+ }
300
+ function getRequest(url, options) {
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ if (!url) {
303
+ return Promise.reject(new Error('URL is empty'));
304
+ }
305
+ if (options && options.method === 'beacon') {
306
+ return {
307
+ result: Promise.resolve(beacon(url)),
308
+ };
309
+ }
310
+ return yield ajax('GET', url);
311
+ });
312
+ }
313
+
314
+ const info = (data) => {
315
+ };
316
+
317
+ const saveConsent = (consent) => {
318
+ savePerKey('local', tagStorage, consent, consentKey);
319
+ };
320
+ const handleConsent = (consent) => {
321
+ const payload = {
322
+ consentString: consent,
323
+ };
324
+ saveConsent(consent);
325
+ postRequest(getConsentURL(), payload).catch(info);
326
+ };
327
+
328
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
329
+ // require the crypto API and do not support built-in fallback to lower quality random number
330
+ // generators (like Math.random()).
331
+ var getRandomValues;
332
+ var rnds8 = new Uint8Array(16);
333
+ function rng() {
334
+ // lazy load so that environments that need to polyfill have a chance to do so
335
+ if (!getRandomValues) {
336
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
337
+ // find the complete implementation of crypto (msCrypto) on IE11.
338
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
339
+
340
+ if (!getRandomValues) {
341
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
342
+ }
343
+ }
344
+
345
+ return getRandomValues(rnds8);
346
+ }
347
+
348
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
349
+
350
+ function validate(uuid) {
351
+ return typeof uuid === 'string' && REGEX.test(uuid);
352
+ }
353
+
354
+ /**
355
+ * Convert array of 16 byte values to UUID string format of the form:
356
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
357
+ */
358
+
359
+ var byteToHex = [];
360
+
361
+ for (var i = 0; i < 256; ++i) {
362
+ byteToHex.push((i + 0x100).toString(16).substr(1));
363
+ }
364
+
365
+ function stringify(arr) {
366
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
367
+ // Note: Be careful editing this code! It's been tuned for performance
368
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
369
+ var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
370
+ // of the following:
371
+ // - One or more input array values don't map to a hex octet (leading to
372
+ // "undefined" in the uuid)
373
+ // - Invalid input values for the RFC `version` or `variant` fields
374
+
375
+ if (!validate(uuid)) {
376
+ throw TypeError('Stringified UUID is invalid');
377
+ }
378
+
379
+ return uuid;
380
+ }
381
+
382
+ function parse(uuid) {
383
+ if (!validate(uuid)) {
384
+ throw TypeError('Invalid UUID');
385
+ }
386
+
387
+ var v;
388
+ var arr = new Uint8Array(16); // Parse ########-....-....-....-............
389
+
390
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
391
+ arr[1] = v >>> 16 & 0xff;
392
+ arr[2] = v >>> 8 & 0xff;
393
+ arr[3] = v & 0xff; // Parse ........-####-....-....-............
394
+
395
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
396
+ arr[5] = v & 0xff; // Parse ........-....-####-....-............
397
+
398
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
399
+ arr[7] = v & 0xff; // Parse ........-....-....-####-............
400
+
401
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
402
+ arr[9] = v & 0xff; // Parse ........-....-....-....-############
403
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
404
+
405
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
406
+ arr[11] = v / 0x100000000 & 0xff;
407
+ arr[12] = v >>> 24 & 0xff;
408
+ arr[13] = v >>> 16 & 0xff;
409
+ arr[14] = v >>> 8 & 0xff;
410
+ arr[15] = v & 0xff;
411
+ return arr;
412
+ }
413
+
414
+ function stringToBytes(str) {
415
+ str = unescape(encodeURIComponent(str)); // UTF8 escape
416
+
417
+ var bytes = [];
418
+
419
+ for (var i = 0; i < str.length; ++i) {
420
+ bytes.push(str.charCodeAt(i));
421
+ }
422
+
423
+ return bytes;
424
+ }
425
+
426
+ var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
427
+ var URL$1 = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
428
+ function v35 (name, version, hashfunc) {
429
+ function generateUUID(value, namespace, buf, offset) {
430
+ if (typeof value === 'string') {
431
+ value = stringToBytes(value);
432
+ }
433
+
434
+ if (typeof namespace === 'string') {
435
+ namespace = parse(namespace);
436
+ }
437
+
438
+ if (namespace.length !== 16) {
439
+ throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
440
+ } // Compute hash of namespace and value, Per 4.3
441
+ // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
442
+ // hashfunc([...namespace, ... value])`
443
+
444
+
445
+ var bytes = new Uint8Array(16 + value.length);
446
+ bytes.set(namespace);
447
+ bytes.set(value, namespace.length);
448
+ bytes = hashfunc(bytes);
449
+ bytes[6] = bytes[6] & 0x0f | version;
450
+ bytes[8] = bytes[8] & 0x3f | 0x80;
451
+
452
+ if (buf) {
453
+ offset = offset || 0;
454
+
455
+ for (var i = 0; i < 16; ++i) {
456
+ buf[offset + i] = bytes[i];
457
+ }
458
+
459
+ return buf;
460
+ }
461
+
462
+ return stringify(bytes);
463
+ } // Function#name is not settable on some platforms (#270)
464
+
465
+
466
+ try {
467
+ generateUUID.name = name; // eslint-disable-next-line no-empty
468
+ } catch (err) {} // For CommonJS default export support
469
+
470
+
471
+ generateUUID.DNS = DNS;
472
+ generateUUID.URL = URL$1;
473
+ return generateUUID;
474
+ }
475
+
476
+ /*
477
+ * Browser-compatible JavaScript MD5
478
+ *
479
+ * Modification of JavaScript MD5
480
+ * https://github.com/blueimp/JavaScript-MD5
481
+ *
482
+ * Copyright 2011, Sebastian Tschan
483
+ * https://blueimp.net
484
+ *
485
+ * Licensed under the MIT license:
486
+ * https://opensource.org/licenses/MIT
487
+ *
488
+ * Based on
489
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
490
+ * Digest Algorithm, as defined in RFC 1321.
491
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
492
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
493
+ * Distributed under the BSD License
494
+ * See http://pajhome.org.uk/crypt/md5 for more info.
495
+ */
496
+ function md5(bytes) {
497
+ if (typeof bytes === 'string') {
498
+ var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
499
+
500
+ bytes = new Uint8Array(msg.length);
501
+
502
+ for (var i = 0; i < msg.length; ++i) {
503
+ bytes[i] = msg.charCodeAt(i);
504
+ }
505
+ }
506
+
507
+ return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
508
+ }
509
+ /*
510
+ * Convert an array of little-endian words to an array of bytes
511
+ */
512
+
513
+
514
+ function md5ToHexEncodedArray(input) {
515
+ var output = [];
516
+ var length32 = input.length * 32;
517
+ var hexTab = '0123456789abcdef';
518
+
519
+ for (var i = 0; i < length32; i += 8) {
520
+ var x = input[i >> 5] >>> i % 32 & 0xff;
521
+ var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
522
+ output.push(hex);
523
+ }
524
+
525
+ return output;
526
+ }
527
+ /**
528
+ * Calculate output length with padding and bit length
529
+ */
530
+
531
+
532
+ function getOutputLength(inputLength8) {
533
+ return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
534
+ }
535
+ /*
536
+ * Calculate the MD5 of an array of little-endian words, and a bit length.
537
+ */
538
+
539
+
540
+ function wordsToMd5(x, len) {
541
+ /* append padding */
542
+ x[len >> 5] |= 0x80 << len % 32;
543
+ x[getOutputLength(len) - 1] = len;
544
+ var a = 1732584193;
545
+ var b = -271733879;
546
+ var c = -1732584194;
547
+ var d = 271733878;
548
+
549
+ for (var i = 0; i < x.length; i += 16) {
550
+ var olda = a;
551
+ var oldb = b;
552
+ var oldc = c;
553
+ var oldd = d;
554
+ a = md5ff(a, b, c, d, x[i], 7, -680876936);
555
+ d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
556
+ c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
557
+ b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
558
+ a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
559
+ d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
560
+ c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
561
+ b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
562
+ a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
563
+ d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
564
+ c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
565
+ b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
566
+ a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
567
+ d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
568
+ c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
569
+ b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
570
+ a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
571
+ d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
572
+ c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
573
+ b = md5gg(b, c, d, a, x[i], 20, -373897302);
574
+ a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
575
+ d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
576
+ c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
577
+ b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
578
+ a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
579
+ d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
580
+ c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
581
+ b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
582
+ a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
583
+ d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
584
+ c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
585
+ b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
586
+ a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
587
+ d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
588
+ c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
589
+ b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
590
+ a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
591
+ d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
592
+ c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
593
+ b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
594
+ a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
595
+ d = md5hh(d, a, b, c, x[i], 11, -358537222);
596
+ c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
597
+ b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
598
+ a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
599
+ d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
600
+ c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
601
+ b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
602
+ a = md5ii(a, b, c, d, x[i], 6, -198630844);
603
+ d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
604
+ c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
605
+ b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
606
+ a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
607
+ d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
608
+ c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
609
+ b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
610
+ a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
611
+ d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
612
+ c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
613
+ b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
614
+ a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
615
+ d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
616
+ c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
617
+ b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
618
+ a = safeAdd(a, olda);
619
+ b = safeAdd(b, oldb);
620
+ c = safeAdd(c, oldc);
621
+ d = safeAdd(d, oldd);
622
+ }
623
+
624
+ return [a, b, c, d];
625
+ }
626
+ /*
627
+ * Convert an array bytes to an array of little-endian words
628
+ * Characters >255 have their high-byte silently ignored.
629
+ */
630
+
631
+
632
+ function bytesToWords(input) {
633
+ if (input.length === 0) {
634
+ return [];
635
+ }
636
+
637
+ var length8 = input.length * 8;
638
+ var output = new Uint32Array(getOutputLength(length8));
639
+
640
+ for (var i = 0; i < length8; i += 8) {
641
+ output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
642
+ }
643
+
644
+ return output;
645
+ }
646
+ /*
647
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
648
+ * to work around bugs in some JS interpreters.
649
+ */
650
+
651
+
652
+ function safeAdd(x, y) {
653
+ var lsw = (x & 0xffff) + (y & 0xffff);
654
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
655
+ return msw << 16 | lsw & 0xffff;
656
+ }
657
+ /*
658
+ * Bitwise rotate a 32-bit number to the left.
659
+ */
660
+
661
+
662
+ function bitRotateLeft(num, cnt) {
663
+ return num << cnt | num >>> 32 - cnt;
664
+ }
665
+ /*
666
+ * These functions implement the four basic operations the algorithm uses.
667
+ */
668
+
669
+
670
+ function md5cmn(q, a, b, x, s, t) {
671
+ return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
672
+ }
673
+
674
+ function md5ff(a, b, c, d, x, s, t) {
675
+ return md5cmn(b & c | ~b & d, a, b, x, s, t);
676
+ }
677
+
678
+ function md5gg(a, b, c, d, x, s, t) {
679
+ return md5cmn(b & d | c & ~d, a, b, x, s, t);
680
+ }
681
+
682
+ function md5hh(a, b, c, d, x, s, t) {
683
+ return md5cmn(b ^ c ^ d, a, b, x, s, t);
684
+ }
685
+
686
+ function md5ii(a, b, c, d, x, s, t) {
687
+ return md5cmn(c ^ (b | ~d), a, b, x, s, t);
688
+ }
689
+
690
+ v35('v3', 0x30, md5);
691
+
692
+ function v4(options, buf, offset) {
693
+ options = options || {};
694
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
695
+
696
+ rnds[6] = rnds[6] & 0x0f | 0x40;
697
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
698
+
699
+ if (buf) {
700
+ offset = offset || 0;
701
+
702
+ for (var i = 0; i < 16; ++i) {
703
+ buf[offset + i] = rnds[i];
704
+ }
705
+
706
+ return buf;
707
+ }
708
+
709
+ return stringify(rnds);
710
+ }
711
+
712
+ // Adapted from Chris Veness' SHA1 code at
713
+ // http://www.movable-type.co.uk/scripts/sha1.html
714
+ function f(s, x, y, z) {
715
+ switch (s) {
716
+ case 0:
717
+ return x & y ^ ~x & z;
718
+
719
+ case 1:
720
+ return x ^ y ^ z;
721
+
722
+ case 2:
723
+ return x & y ^ x & z ^ y & z;
724
+
725
+ case 3:
726
+ return x ^ y ^ z;
727
+ }
728
+ }
729
+
730
+ function ROTL(x, n) {
731
+ return x << n | x >>> 32 - n;
732
+ }
733
+
734
+ function sha1(bytes) {
735
+ var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
736
+ var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
737
+
738
+ if (typeof bytes === 'string') {
739
+ var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
740
+
741
+ bytes = [];
742
+
743
+ for (var i = 0; i < msg.length; ++i) {
744
+ bytes.push(msg.charCodeAt(i));
745
+ }
746
+ } else if (!Array.isArray(bytes)) {
747
+ // Convert Array-like to Array
748
+ bytes = Array.prototype.slice.call(bytes);
749
+ }
750
+
751
+ bytes.push(0x80);
752
+ var l = bytes.length / 4 + 2;
753
+ var N = Math.ceil(l / 16);
754
+ var M = new Array(N);
755
+
756
+ for (var _i = 0; _i < N; ++_i) {
757
+ var arr = new Uint32Array(16);
758
+
759
+ for (var j = 0; j < 16; ++j) {
760
+ arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3];
761
+ }
762
+
763
+ M[_i] = arr;
764
+ }
765
+
766
+ M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
767
+ M[N - 1][14] = Math.floor(M[N - 1][14]);
768
+ M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
769
+
770
+ for (var _i2 = 0; _i2 < N; ++_i2) {
771
+ var W = new Uint32Array(80);
772
+
773
+ for (var t = 0; t < 16; ++t) {
774
+ W[t] = M[_i2][t];
775
+ }
776
+
777
+ for (var _t = 16; _t < 80; ++_t) {
778
+ W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
779
+ }
780
+
781
+ var a = H[0];
782
+ var b = H[1];
783
+ var c = H[2];
784
+ var d = H[3];
785
+ var e = H[4];
786
+
787
+ for (var _t2 = 0; _t2 < 80; ++_t2) {
788
+ var s = Math.floor(_t2 / 20);
789
+ var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
790
+ e = d;
791
+ d = c;
792
+ c = ROTL(b, 30) >>> 0;
793
+ b = a;
794
+ a = T;
795
+ }
796
+
797
+ H[0] = H[0] + a >>> 0;
798
+ H[1] = H[1] + b >>> 0;
799
+ H[2] = H[2] + c >>> 0;
800
+ H[3] = H[3] + d >>> 0;
801
+ H[4] = H[4] + e >>> 0;
802
+ }
803
+
804
+ return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
805
+ }
806
+
807
+ v35('v5', 0x50, sha1);
808
+
809
+ const generateEventId = (name) => {
810
+ let time = Date.now().toString();
811
+ if (typeof performance !== 'undefined' &&
812
+ typeof performance.now === 'function') {
813
+ const perf = performance.now();
814
+ if (perf) {
815
+ time = perf.toFixed(4);
816
+ }
817
+ }
818
+ return `${btoa(name)}-${v4()}-${time}`;
819
+ };
820
+
821
+ const handleGetUserId = () => {
822
+ return getCookieValue('tag_user_id');
823
+ };
824
+
825
+ const manifestVariables = {};
826
+ const addProviderVariable = (name, variables) => {
827
+ manifestVariables[name] = variables;
828
+ };
829
+ const getProviderVariables = (name) => manifestVariables[name] || {};
830
+
831
+ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
832
+ const payload = {
833
+ eventName,
834
+ eventId,
835
+ timestamp: Date.now(),
836
+ data,
837
+ providerData,
838
+ };
839
+ if (providers) {
840
+ payload.providers = providers;
841
+ }
842
+ postRequest(getTagURL(), payload, options).catch(info);
843
+ };
844
+ const handleTag = (eventName, data = {}, providers, options) => {
845
+ if (!allowTag(providers)) {
846
+ console.log('No consent');
847
+ return;
848
+ }
849
+ let eventId = data['eventId'];
850
+ if (!eventId) {
851
+ eventId = generateEventId(eventName);
852
+ }
853
+ const providerPackages = getProvidersPackage();
854
+ const userId = handleGetUserId();
855
+ const providerData = {};
856
+ if (providerPackages) {
857
+ providerPackages.forEach((pkg) => {
858
+ if (!allowProvider(providers, pkg.name)) {
859
+ return;
860
+ }
861
+ if (pkg && pkg.tag) {
862
+ const result = pkg.tag({
863
+ userId,
864
+ eventName,
865
+ eventId,
866
+ data,
867
+ sendTag,
868
+ manifestVariables: getProviderVariables(pkg.name),
869
+ });
870
+ if (result) {
871
+ providerData[pkg.name] = result;
872
+ }
873
+ }
874
+ });
875
+ }
876
+ sendTag({
877
+ eventName,
878
+ eventId,
879
+ data,
880
+ providerData,
881
+ providers,
882
+ options,
883
+ });
884
+ };
885
+
886
+ const handleCaptureQuery = (provider, key, persistType) => {
887
+ if (!window) {
888
+ return;
889
+ }
890
+ const params = new URLSearchParams(window.location.search);
891
+ if (!params || !params.get(key)) {
892
+ return;
893
+ }
894
+ saveDataPerKey(persistType, provider, params.get(key), key);
895
+ };
896
+ const handleCaptureStorage = (provider, key, persistType, location) => {
897
+ let data;
898
+ switch (location) {
899
+ case 'cookie': {
900
+ data = getCookieValue(key);
901
+ break;
902
+ }
903
+ case 'local': {
904
+ data = sessionStorage && sessionStorage.getItem(key);
905
+ break;
906
+ }
907
+ case 'session': {
908
+ data = localStorage && localStorage.getItem(key);
909
+ break;
910
+ }
911
+ }
912
+ if (!data) {
913
+ return;
914
+ }
915
+ saveDataPerKey(persistType, provider, data, key);
916
+ };
917
+ const handleCapture = (provider, params) => {
918
+ params.forEach((param) => {
919
+ switch (param.type) {
920
+ case 'query': {
921
+ handleCaptureQuery(provider, param.key, param.persist);
922
+ break;
923
+ }
924
+ case 'storage': {
925
+ handleCaptureStorage(provider, param.key, param.persist, param.location);
926
+ break;
927
+ }
928
+ }
929
+ });
930
+ };
931
+
932
+ const handleManifest = (manifest) => {
933
+ const providers = [];
934
+ const providerPackages = getProvidersPackage();
935
+ const userId = handleGetUserId();
936
+ manifest.forEach((provider) => {
937
+ providers.push(provider.package);
938
+ addProviderVariable(provider.package, provider.variables);
939
+ if (provider.rules) {
940
+ Object.entries(provider.rules).forEach(([name, recipe]) => {
941
+ switch (name) {
942
+ case 'capture': {
943
+ handleCapture(provider.package, recipe);
944
+ return;
945
+ }
946
+ }
947
+ });
948
+ }
949
+ if (providerPackages) {
950
+ const pkg = providerPackages.find((pkg) => pkg.name === provider.package);
951
+ if (pkg && pkg.init) {
952
+ pkg.init({ userId, manifest: provider, sendTag });
953
+ }
954
+ }
955
+ });
956
+ savePerKey('local', tagStorage, providers, providersKey);
957
+ };
958
+
959
+ const handleInit = (preferences) => {
960
+ const success = setPreferences(preferences);
961
+ if (!success) {
962
+ return;
963
+ }
964
+ const url = new URL(getInitURL());
965
+ if (preferences.disableConsentCheck) {
966
+ url.searchParams.set('consentDisabled', 'true');
967
+ saveConsent({ all: true });
968
+ }
969
+ if (preferences.userId) {
970
+ url.searchParams.set('userId', preferences.userId);
971
+ }
972
+ getRequest(url.href)
973
+ .then((result) => {
974
+ if (!result) {
975
+ console.log('init failed');
976
+ return;
977
+ }
978
+ handleManifest(result.result);
979
+ })
980
+ .catch(info);
981
+ };
982
+
983
+ const handleUser = (key, value, options) => {
984
+ if (!key || !value) {
985
+ console.error('Key or Value is missing in user API.');
986
+ return;
987
+ }
988
+ saveKV({
989
+ [key]: value,
990
+ });
991
+ postRequest(getUserURL(), {
992
+ key,
993
+ value,
994
+ }, options).catch(info);
995
+ };
996
+
997
+ const handleData = (data, options) => {
998
+ if (!data || Object.keys(data).length === 0) {
999
+ console.error('Provide data for data API.');
1000
+ return;
1001
+ }
1002
+ saveKV(data);
1003
+ postRequest(getDataURL(), { data }, options).catch(info);
1004
+ };
1005
+
1006
+ const handleGetData = (keys, callback) => {
1007
+ if (!keys || keys.length === 0) {
1008
+ console.error('Provide keys for get data API.');
1009
+ return;
1010
+ }
1011
+ getRequest(getGetDataURL(keys))
1012
+ .then((result) => {
1013
+ callback((result === null || result === void 0 ? void 0 : result.result) || {});
1014
+ })
1015
+ .catch(info);
1016
+ };
1017
+
1018
+ const handleKeys = (callback) => {
1019
+ getRequest(getKeysURL())
1020
+ .then((result) => {
1021
+ callback((result === null || result === void 0 ? void 0 : result.result) || []);
1022
+ })
1023
+ .catch(info);
1024
+ };
1025
+
1026
+ const init = (preferences) => {
1027
+ handleInit(preferences);
1028
+ };
1029
+ const tag = (name, data, providers, options) => {
1030
+ handleTag(name, data, providers, options);
1031
+ };
1032
+ const consent = (consent) => {
1033
+ handleConsent(consent);
1034
+ };
1035
+ const user = (key, value, options) => {
1036
+ handleUser(key, value, options);
1037
+ };
1038
+ const data = (data, options) => {
1039
+ handleData(data, options);
1040
+ };
1041
+ const getData = (keys, callback) => {
1042
+ handleGetData(keys, callback);
1043
+ };
1044
+ const keys = (callback) => {
1045
+ handleKeys(callback);
1046
+ };
1047
+
1048
+ // TODO https://github.com/blotoutio/solutions/issues/826
1049
+
1050
+ class API {
1051
+ init(preferences) {
1052
+ init(preferences);
1053
+ }
1054
+
1055
+ tag(name, data, providers, options) {
1056
+ tag(name, data, providers, options);
1057
+ }
1058
+
1059
+ consent(consentString) {
1060
+ consent(consentString);
1061
+ }
1062
+
1063
+ user(key, value, options) {
1064
+ user(key, value, options);
1065
+ }
1066
+
1067
+ data(data$1, options) {
1068
+ data(data$1, options);
1069
+ }
1070
+
1071
+ getData(keys, callback) {
1072
+ getData(keys, callback);
1073
+ }
1074
+
1075
+ keys(callback) {
1076
+ keys(callback);
1077
+ }
1078
+ }
1079
+
1080
+ var api = new API();
1081
+
1082
+ (function () {
1083
+ const handleFunction = (arg) => {
1084
+ const sliced = [].slice.call(arg);
1085
+ if (!Array.isArray(sliced)) {
1086
+ return
1087
+ }
1088
+
1089
+ try {
1090
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1091
+ // @ts-ignore
1092
+ return library[sliced[0]](...sliced.slice(1))
1093
+ } catch (e) {
1094
+ console.error(e);
1095
+ }
1096
+ };
1097
+
1098
+ const library = api;
1099
+ let stubs = [];
1100
+ if (window.edgetag) {
1101
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1102
+ // @ts-ignore
1103
+ stubs = window.edgetag.stubs || [];
1104
+ }
1105
+
1106
+ // this needs to be regular function for arguments to work
1107
+ window.edgetag = function () {
1108
+ // eslint-disable-next-line prefer-rest-params
1109
+ return handleFunction(arguments)
1110
+ };
1111
+
1112
+ // restore calls that were triggered before lib was ready
1113
+ stubs.forEach(handleFunction);
1114
+ })();
1115
+
1116
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
@@ -8,23 +8,14 @@
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
+ "main": "./index.js",
11
12
  "repository": {
12
13
  "type": "git",
13
14
  "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
14
15
  },
15
16
  "files": [
16
17
  "index.js",
17
- "index.cjs",
18
18
  "package.json",
19
19
  "README.md"
20
- ],
21
- "main": "./index.cjs",
22
- "type": "commonjs",
23
- "types": "./index.d.ts",
24
- "exports": {
25
- ".": {
26
- "types": "./index.d.ts",
27
- "require": "./index.cjs"
28
- }
29
- }
20
+ ]
30
21
  }
package/index.cjs DELETED
@@ -1 +0,0 @@
1
- !function(){"use strict";function e(e,t,n,s){return new(n||(n=Promise))((function(o,r){function a(e){try{i(s.next(e))}catch(e){r(e)}}function c(e){try{i(s.throw(e))}catch(e){r(e)}}function i(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}i((s=s.apply(e,t||[])).next())}))}const t="edgeTag",n="consent",s="providers",o="_workerStore",r=(e,t,n,s)=>{const o=l(e);o.data||(o.data={}),o.data[t]||(o.data[t]={}),o.data[t][s]=n,i(e,o)},a=(e,t,n,s)=>{const o=l(e);o[t]||(o[t]={}),o[t][s]=n,i(e,o)},c=(e,t,n)=>{const s=l(e);if(s[t])return s[t][n]},i=(e,t,n=o)=>{"session"!==e?d(t,n):f(t,n)},l=(e,t=o)=>"session"===e?h(t):g(t),u=e=>{let t=l("session");t||(t={}),t.kv||(t.kv={}),t.kv=Object.assign(Object.assign({},t.kv),e),i("session",t)},d=(e,t)=>{localStorage.setItem(t,JSON.stringify(e))},g=e=>{const t=localStorage.getItem(e);return t&&JSON.parse(t)||{}},f=(e,t)=>{sessionStorage.setItem(t,JSON.stringify(e))},h=e=>{const t=sessionStorage.getItem(e);return t&&JSON.parse(t)||{}};let v="";const y=e=>{const t=p();return t?`${t}${e}`:(console.log("URL is not valid"),"")},p=()=>v;let b=!1;const m=e=>{return!!e&&(e.edgeURL?(b=!!e.disableConsentCheck,null!=(t=e.edgeURL)&&(v=t),!0):(console.error("Please provide URL for EdgeTag"),!1));var t},w=()=>{const e=navigator;let t=e.userAgent;return t+=e.brave?`${t} Brave`:"",t},k=e=>{const o=c("local",t,n);if(b)return!0;if(!o)return!1;if(o.all)return!0;if(!e)return Object.values(o).find((e=>e))||!1;const r=c("local",t,s)||[];for(const t of r){const n=e[t];if((n||!0===e.all&&void 0===n||!1===e.all&&!0===n)&&o[t])return!0}return!1},j=(e,t)=>{let n;return t&&(n=new Blob([JSON.stringify(t)],{type:"application/json"})),navigator.sendBeacon(e,n)},O=(t,n,s)=>e(void 0,void 0,void 0,(function*(){return yield fetch(n,{method:t,headers:{"Content-type":"application/json; charset=utf-8",Accept:"application/json; charset=utf-8"},body:JSON.stringify(s),credentials:"include"}).then((e=>e.json().then((t=>({status:e.status,body:t}))))).then((e=>e.status<200||e.status>=300?Promise.reject(new Error(JSON.stringify(e.body))):Promise.resolve(e.body))).catch((e=>Promise.reject(new Error(e))))}));function P(t,n,s){return e(this,void 0,void 0,(function*(){if(!t)return Promise.reject(new Error("URL is empty"));const e=(e=>{const t=Object.assign({pageUrl:window.location.href,userAgent:w()},e||{});let n={};const s=l("session");s&&(n=Object.assign(Object.assign({},n),s));const o=l("local");return o&&(n=Object.assign(Object.assign({},n),o)),t.storage=n,t})(n);return s&&"beacon"===s.method?Promise.resolve(j(t,e)):yield O("POST",t,e)}))}function S(t,n){return e(this,void 0,void 0,(function*(){return t?n&&"beacon"===n.method?{result:Promise.resolve(j(t))}:yield O("GET",t):Promise.reject(new Error("URL is empty"))}))}const I=e=>{},U=e=>{a("local",t,e,n)},E=e=>{const t={consentString:e};U(e),P(y("/consent"),t).catch(I)},R=(e,t,n,s)=>{const o={eventName:e};t&&(o.data=t),n&&(o.providers=n),k(n)?P(y("/tag"),o,s).catch(I):console.log("No consent")},A=(e,t,n,s)=>{let o;switch(s){case"cookie":o=(e=>{const t=`${e}=`,n=decodeURIComponent(document.cookie).split(";");for(let e=0;e<n.length;e++){let s=n[e];for(;" "===s.charAt(0);)s=s.substring(1);if(0===s.indexOf(t))return s.substring(t.length,s.length)}return""})(t);break;case"local":o=sessionStorage.getItem(t);break;case"session":o=localStorage.getItem(t)}o&&r(n,e,o,t)},N=(e,t)=>{t.forEach((t=>{switch(t.type){case"query":((e,t,n)=>{const s=new URLSearchParams(window.location.search);s&&s.get(t)&&r(n,e,s.get(t),t)})(e,t.key,t.persist);break;case"storage":A(e,t.key,t.persist,t.location)}}))},L=e=>{if(!m(e))return;const n=new URL(y("/init"));e.disableConsentCheck&&(n.searchParams.set("consentDisabled","true"),U({all:!0})),e.userId&&n.searchParams.set("userId",e.userId),S(n.href).then((e=>{e?(e=>{const n=[];e.forEach((e=>{n.push(e.package),e.rules&&Object.entries(e.rules).forEach((([t,n])=>{"capture"!==t||N(e.package,n)}))})),a("local",t,n,s)})(e.result):console.log("init failed")})).catch(I)},C=(e,t,n)=>{e&&t?(u({[e]:t}),P(y("/user"),{key:e,value:t},n).catch(I)):console.error("Key or Value is missing in user API.")},J=(e,t)=>{e&&0!==Object.keys(e).length?(u(e),P(y("/data"),{data:e},t).catch(I)):console.error("Provide data for data API.")},$=(e,t)=>{e&&0!==e.length?S((e=>y(`/data?keys=${encodeURIComponent(e.join(","))}`))(e)).then((e=>{t((null==e?void 0:e.result)||{})})).catch(I):console.error("Provide keys for get data API.")},T=e=>{S(y("/keys")).then((t=>{e((null==t?void 0:t.result)||[])})).catch(I)};var x=new class{init(e){(e=>{L(e)})(e)}tag(e,t,n,s){((e,t,n,s)=>{R(e,t,n,s)})(e,t,n,s)}consent(e){(e=>{E(e)})(e)}user(e,t,n){((e,t,n)=>{C(e,t,n)})(e,t,n)}data(e,t){((e,t)=>{J(e,t)})(e,t)}getData(e,t){((e,t)=>{$(e,t)})(e,t)}keys(e){(e=>{T(e)})(e)}};!function(){const e=e=>{const n=[].slice.call(e);if(Array.isArray(n))try{return t[n[0]](...n.slice(1))}catch(e){console.error(e)}},t=x;let n=[];window.edgetag&&(n=window.edgetag.stubs||[]),window.edgetag=function(){return e(arguments)},n.forEach(e)}()}();