@blotoutio/edgetag-sdk-browser 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +82 -95
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,38 +13,6 @@
|
|
|
13
13
|
get user () { return user; }
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
/******************************************************************************
|
|
17
|
-
Copyright (c) Microsoft Corporation.
|
|
18
|
-
|
|
19
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
20
|
-
purpose with or without fee is hereby granted.
|
|
21
|
-
|
|
22
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
23
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
24
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
25
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
26
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
27
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
29
|
-
***************************************************************************** */
|
|
30
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
34
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
36
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
37
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
38
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
39
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
-
var e = new Error(message);
|
|
45
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
16
|
const getMessage = (error) => {
|
|
49
17
|
if (error instanceof Error) {
|
|
50
18
|
return error.message;
|
|
@@ -55,7 +23,7 @@
|
|
|
55
23
|
try {
|
|
56
24
|
return JSON.stringify(error);
|
|
57
25
|
}
|
|
58
|
-
catch
|
|
26
|
+
catch {
|
|
59
27
|
return error;
|
|
60
28
|
}
|
|
61
29
|
};
|
|
@@ -136,7 +104,7 @@
|
|
|
136
104
|
});
|
|
137
105
|
}
|
|
138
106
|
}
|
|
139
|
-
catch
|
|
107
|
+
catch {
|
|
140
108
|
// do nothing
|
|
141
109
|
}
|
|
142
110
|
setUrl(preferences.edgeURL);
|
|
@@ -191,7 +159,7 @@
|
|
|
191
159
|
const nav = navigator;
|
|
192
160
|
return nav.userAgent;
|
|
193
161
|
}
|
|
194
|
-
catch
|
|
162
|
+
catch {
|
|
195
163
|
return '';
|
|
196
164
|
}
|
|
197
165
|
};
|
|
@@ -215,7 +183,7 @@
|
|
|
215
183
|
}
|
|
216
184
|
return window.location.href;
|
|
217
185
|
}
|
|
218
|
-
catch
|
|
186
|
+
catch {
|
|
219
187
|
return '';
|
|
220
188
|
}
|
|
221
189
|
};
|
|
@@ -223,7 +191,15 @@
|
|
|
223
191
|
try {
|
|
224
192
|
return window.location.search;
|
|
225
193
|
}
|
|
226
|
-
catch
|
|
194
|
+
catch {
|
|
195
|
+
return '';
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const getLocale = () => {
|
|
199
|
+
try {
|
|
200
|
+
return navigator.language;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
227
203
|
return '';
|
|
228
204
|
}
|
|
229
205
|
};
|
|
@@ -231,7 +207,7 @@
|
|
|
231
207
|
try {
|
|
232
208
|
return document.title;
|
|
233
209
|
}
|
|
234
|
-
catch
|
|
210
|
+
catch {
|
|
235
211
|
return '';
|
|
236
212
|
}
|
|
237
213
|
};
|
|
@@ -355,7 +331,10 @@
|
|
|
355
331
|
if (!currentSession['kv']) {
|
|
356
332
|
currentSession['kv'] = {};
|
|
357
333
|
}
|
|
358
|
-
currentSession['kv'] =
|
|
334
|
+
currentSession['kv'] = {
|
|
335
|
+
...currentSession['kv'],
|
|
336
|
+
...data,
|
|
337
|
+
};
|
|
359
338
|
saveData('session', currentSession);
|
|
360
339
|
};
|
|
361
340
|
const saveLocal = (value, key) => {
|
|
@@ -365,7 +344,7 @@
|
|
|
365
344
|
}
|
|
366
345
|
localStorage.setItem(key, JSON.stringify(value));
|
|
367
346
|
}
|
|
368
|
-
catch
|
|
347
|
+
catch {
|
|
369
348
|
log('Local storage not supported.');
|
|
370
349
|
}
|
|
371
350
|
};
|
|
@@ -380,7 +359,7 @@
|
|
|
380
359
|
}
|
|
381
360
|
return JSON.parse(data) || {};
|
|
382
361
|
}
|
|
383
|
-
catch
|
|
362
|
+
catch {
|
|
384
363
|
return {};
|
|
385
364
|
}
|
|
386
365
|
};
|
|
@@ -391,7 +370,7 @@
|
|
|
391
370
|
}
|
|
392
371
|
sessionStorage.setItem(key, JSON.stringify(value));
|
|
393
372
|
}
|
|
394
|
-
catch
|
|
373
|
+
catch {
|
|
395
374
|
log('Session storage not supported.');
|
|
396
375
|
}
|
|
397
376
|
};
|
|
@@ -406,7 +385,7 @@
|
|
|
406
385
|
}
|
|
407
386
|
return JSON.parse(data) || {};
|
|
408
387
|
}
|
|
409
|
-
catch
|
|
388
|
+
catch {
|
|
410
389
|
return {};
|
|
411
390
|
}
|
|
412
391
|
};
|
|
@@ -437,7 +416,7 @@
|
|
|
437
416
|
}
|
|
438
417
|
}
|
|
439
418
|
}
|
|
440
|
-
catch
|
|
419
|
+
catch {
|
|
441
420
|
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
442
421
|
console.log('[EdgeTag] Crypto module not found');
|
|
443
422
|
}
|
|
@@ -474,7 +453,7 @@
|
|
|
474
453
|
}
|
|
475
454
|
return '';
|
|
476
455
|
}
|
|
477
|
-
catch
|
|
456
|
+
catch {
|
|
478
457
|
return '';
|
|
479
458
|
}
|
|
480
459
|
};
|
|
@@ -504,66 +483,74 @@
|
|
|
504
483
|
return Promise.reject(new Error('Beacon not supported.'));
|
|
505
484
|
}
|
|
506
485
|
};
|
|
507
|
-
const ajax = (method, url, payload) =>
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
.catch((error) => {
|
|
526
|
-
return Promise.reject(new Error(error));
|
|
527
|
-
});
|
|
486
|
+
const ajax = (method, url, payload) => fetch(url, {
|
|
487
|
+
method,
|
|
488
|
+
headers: {
|
|
489
|
+
'Content-type': 'application/json; charset=utf-8',
|
|
490
|
+
Accept: 'application/json; charset=utf-8',
|
|
491
|
+
EdgeTagUserId: handleGetUserId(),
|
|
492
|
+
},
|
|
493
|
+
body: JSON.stringify(payload),
|
|
494
|
+
credentials: 'include',
|
|
495
|
+
})
|
|
496
|
+
.then((response) => response
|
|
497
|
+
.json()
|
|
498
|
+
.then((data) => ({ status: response.status, body: data })))
|
|
499
|
+
.then(({ status, body }) => {
|
|
500
|
+
if (status < 200 || status >= 300) {
|
|
501
|
+
throw new Error(`Request failed with code ${status}: ${JSON.stringify(body)}`);
|
|
502
|
+
}
|
|
503
|
+
return Promise.resolve(body);
|
|
528
504
|
});
|
|
529
505
|
const getStandardPayload = (payload) => {
|
|
530
|
-
const data =
|
|
506
|
+
const data = {
|
|
507
|
+
pageUrl: getPageUrl(),
|
|
508
|
+
pageTitle: getPageTitle(),
|
|
509
|
+
userAgent: getUserAgent(),
|
|
510
|
+
referrer: getReferrer(),
|
|
511
|
+
search: getSearch(),
|
|
512
|
+
locale: getLocale(),
|
|
513
|
+
sdkVersion: "0.22.0" ,
|
|
514
|
+
...(payload || {}),
|
|
515
|
+
};
|
|
531
516
|
let storage = {};
|
|
532
517
|
const session = getData$1('session');
|
|
533
518
|
if (session) {
|
|
534
|
-
storage =
|
|
519
|
+
storage = {
|
|
520
|
+
...storage,
|
|
521
|
+
...session,
|
|
522
|
+
};
|
|
535
523
|
}
|
|
536
524
|
const local = getData$1('local');
|
|
537
525
|
if (local) {
|
|
538
|
-
storage =
|
|
526
|
+
storage = {
|
|
527
|
+
...storage,
|
|
528
|
+
...local,
|
|
529
|
+
};
|
|
539
530
|
}
|
|
540
531
|
data.storage = storage;
|
|
541
532
|
return data;
|
|
542
533
|
};
|
|
543
|
-
function postRequest(url, data, options) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
return yield ajax('POST', url, payload);
|
|
553
|
-
});
|
|
534
|
+
async function postRequest(url, data, options) {
|
|
535
|
+
if (!url) {
|
|
536
|
+
return Promise.reject(new Error('URL is empty.'));
|
|
537
|
+
}
|
|
538
|
+
const payload = getStandardPayload(data);
|
|
539
|
+
if (options && options.method === 'beacon') {
|
|
540
|
+
return Promise.resolve(beacon(url, payload));
|
|
541
|
+
}
|
|
542
|
+
return await ajax('POST', url, payload);
|
|
554
543
|
}
|
|
555
|
-
function getRequest(url, options) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return yield ajax('GET', url);
|
|
566
|
-
});
|
|
544
|
+
async function getRequest(url, options) {
|
|
545
|
+
if (!url) {
|
|
546
|
+
return Promise.reject(new Error('URL is empty.'));
|
|
547
|
+
}
|
|
548
|
+
if (options && options.method === 'beacon') {
|
|
549
|
+
return {
|
|
550
|
+
result: Promise.resolve(beacon(url)),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
return await ajax('GET', url);
|
|
567
554
|
}
|
|
568
555
|
|
|
569
556
|
let memoryConsent;
|
|
@@ -724,7 +711,7 @@
|
|
|
724
711
|
try {
|
|
725
712
|
value = JSON.stringify(value);
|
|
726
713
|
}
|
|
727
|
-
catch
|
|
714
|
+
catch {
|
|
728
715
|
log('Error stringify value.');
|
|
729
716
|
return;
|
|
730
717
|
}
|
|
@@ -737,7 +724,7 @@
|
|
|
737
724
|
return;
|
|
738
725
|
}
|
|
739
726
|
}
|
|
740
|
-
catch
|
|
727
|
+
catch {
|
|
741
728
|
return;
|
|
742
729
|
}
|
|
743
730
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -771,7 +758,7 @@
|
|
|
771
758
|
}
|
|
772
759
|
}
|
|
773
760
|
}
|
|
774
|
-
catch
|
|
761
|
+
catch {
|
|
775
762
|
return;
|
|
776
763
|
}
|
|
777
764
|
if (!data) {
|