@blotoutio/edgetag-sdk-js 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.cjs CHANGED
@@ -12,38 +12,6 @@ var api = /*#__PURE__*/Object.freeze({
12
12
  get user () { return user; }
13
13
  });
14
14
 
15
- /******************************************************************************
16
- Copyright (c) Microsoft Corporation.
17
-
18
- Permission to use, copy, modify, and/or distribute this software for any
19
- purpose with or without fee is hereby granted.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
- PERFORMANCE OF THIS SOFTWARE.
28
- ***************************************************************************** */
29
- /* global Reflect, Promise, SuppressedError, Symbol */
30
-
31
-
32
- function __awaiter(thisArg, _arguments, P, generator) {
33
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
- return new (P || (P = Promise))(function (resolve, reject) {
35
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
- step((generator = generator.apply(thisArg, _arguments || [])).next());
39
- });
40
- }
41
-
42
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
43
- var e = new Error(message);
44
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
- };
46
-
47
15
  const getMessage = (error) => {
48
16
  if (error instanceof Error) {
49
17
  return error.message;
@@ -54,7 +22,7 @@ const getMessage = (error) => {
54
22
  try {
55
23
  return JSON.stringify(error);
56
24
  }
57
- catch (_a) {
25
+ catch {
58
26
  return error;
59
27
  }
60
28
  };
@@ -135,7 +103,7 @@ const setPreferences = (preferences) => {
135
103
  });
136
104
  }
137
105
  }
138
- catch (_b) {
106
+ catch {
139
107
  // do nothing
140
108
  }
141
109
  setUrl(preferences.edgeURL);
@@ -190,7 +158,7 @@ const getUserAgent = () => {
190
158
  const nav = navigator;
191
159
  return nav.userAgent;
192
160
  }
193
- catch (_a) {
161
+ catch {
194
162
  return '';
195
163
  }
196
164
  };
@@ -214,7 +182,7 @@ const getPageUrl = () => {
214
182
  }
215
183
  return window.location.href;
216
184
  }
217
- catch (_a) {
185
+ catch {
218
186
  return '';
219
187
  }
220
188
  };
@@ -222,7 +190,15 @@ const getSearch = () => {
222
190
  try {
223
191
  return window.location.search;
224
192
  }
225
- catch (_a) {
193
+ catch {
194
+ return '';
195
+ }
196
+ };
197
+ const getLocale = () => {
198
+ try {
199
+ return navigator.language;
200
+ }
201
+ catch {
226
202
  return '';
227
203
  }
228
204
  };
@@ -230,7 +206,7 @@ const getPageTitle = () => {
230
206
  try {
231
207
  return document.title;
232
208
  }
233
- catch (_a) {
209
+ catch {
234
210
  return '';
235
211
  }
236
212
  };
@@ -354,7 +330,10 @@ const saveKV = (data) => {
354
330
  if (!currentSession['kv']) {
355
331
  currentSession['kv'] = {};
356
332
  }
357
- currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
333
+ currentSession['kv'] = {
334
+ ...currentSession['kv'],
335
+ ...data,
336
+ };
358
337
  saveData('session', currentSession);
359
338
  };
360
339
  const saveLocal = (value, key) => {
@@ -364,7 +343,7 @@ const saveLocal = (value, key) => {
364
343
  }
365
344
  localStorage.setItem(key, JSON.stringify(value));
366
345
  }
367
- catch (_a) {
346
+ catch {
368
347
  log('Local storage not supported.');
369
348
  }
370
349
  };
@@ -379,7 +358,7 @@ const getLocal = (key) => {
379
358
  }
380
359
  return JSON.parse(data) || {};
381
360
  }
382
- catch (_a) {
361
+ catch {
383
362
  return {};
384
363
  }
385
364
  };
@@ -390,7 +369,7 @@ const saveSession = (value, key) => {
390
369
  }
391
370
  sessionStorage.setItem(key, JSON.stringify(value));
392
371
  }
393
- catch (_a) {
372
+ catch {
394
373
  log('Session storage not supported.');
395
374
  }
396
375
  };
@@ -405,7 +384,7 @@ const getSession = (key) => {
405
384
  }
406
385
  return JSON.parse(data) || {};
407
386
  }
408
- catch (_a) {
387
+ catch {
409
388
  return {};
410
389
  }
411
390
  };
@@ -436,7 +415,7 @@ const generateUUID = () => {
436
415
  }
437
416
  }
438
417
  }
439
- catch (_a) {
418
+ catch {
440
419
  id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
441
420
  console.log('[EdgeTag] Crypto module not found');
442
421
  }
@@ -473,7 +452,7 @@ const getCookieValue = (key) => {
473
452
  }
474
453
  return '';
475
454
  }
476
- catch (_a) {
455
+ catch {
477
456
  return '';
478
457
  }
479
458
  };
@@ -503,66 +482,74 @@ const beacon = (url, payload) => {
503
482
  return Promise.reject(new Error('Beacon not supported.'));
504
483
  }
505
484
  };
506
- const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
507
- return yield fetch(url, {
508
- method,
509
- headers: {
510
- 'Content-type': 'application/json; charset=utf-8',
511
- Accept: 'application/json; charset=utf-8',
512
- EdgeTagUserId: handleGetUserId(),
513
- },
514
- body: JSON.stringify(payload),
515
- credentials: 'include',
516
- })
517
- .then((response) => response.json().then((data) => ({ status: response.status, body: data })))
518
- .then((data) => {
519
- if (data.status < 200 || data.status >= 300) {
520
- return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
521
- }
522
- return Promise.resolve(data.body);
523
- })
524
- .catch((error) => {
525
- return Promise.reject(new Error(error));
526
- });
485
+ const ajax = (method, url, payload) => fetch(url, {
486
+ method,
487
+ headers: {
488
+ 'Content-type': 'application/json; charset=utf-8',
489
+ Accept: 'application/json; charset=utf-8',
490
+ EdgeTagUserId: handleGetUserId(),
491
+ },
492
+ body: JSON.stringify(payload),
493
+ credentials: 'include',
494
+ })
495
+ .then((response) => response
496
+ .json()
497
+ .then((data) => ({ status: response.status, body: data })))
498
+ .then(({ status, body }) => {
499
+ if (status < 200 || status >= 300) {
500
+ throw new Error(`Request failed with code ${status}: ${JSON.stringify(body)}`);
501
+ }
502
+ return Promise.resolve(body);
527
503
  });
528
504
  const getStandardPayload = (payload) => {
529
- const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.21.0" }, (payload || {}));
505
+ const data = {
506
+ pageUrl: getPageUrl(),
507
+ pageTitle: getPageTitle(),
508
+ userAgent: getUserAgent(),
509
+ referrer: getReferrer(),
510
+ search: getSearch(),
511
+ locale: getLocale(),
512
+ sdkVersion: "0.22.0" ,
513
+ ...(payload || {}),
514
+ };
530
515
  let storage = {};
531
516
  const session = getData$1('session');
532
517
  if (session) {
533
- storage = Object.assign(Object.assign({}, storage), session);
518
+ storage = {
519
+ ...storage,
520
+ ...session,
521
+ };
534
522
  }
535
523
  const local = getData$1('local');
536
524
  if (local) {
537
- storage = Object.assign(Object.assign({}, storage), local);
525
+ storage = {
526
+ ...storage,
527
+ ...local,
528
+ };
538
529
  }
539
530
  data.storage = storage;
540
531
  return data;
541
532
  };
542
- function postRequest(url, data, options) {
543
- return __awaiter(this, void 0, void 0, function* () {
544
- if (!url) {
545
- return Promise.reject(new Error('URL is empty.'));
546
- }
547
- const payload = getStandardPayload(data);
548
- if (options && options.method === 'beacon') {
549
- return Promise.resolve(beacon(url, payload));
550
- }
551
- return yield ajax('POST', url, payload);
552
- });
533
+ async function postRequest(url, data, options) {
534
+ if (!url) {
535
+ return Promise.reject(new Error('URL is empty.'));
536
+ }
537
+ const payload = getStandardPayload(data);
538
+ if (options && options.method === 'beacon') {
539
+ return Promise.resolve(beacon(url, payload));
540
+ }
541
+ return await ajax('POST', url, payload);
553
542
  }
554
- function getRequest(url, options) {
555
- return __awaiter(this, void 0, void 0, function* () {
556
- if (!url) {
557
- return Promise.reject(new Error('URL is empty.'));
558
- }
559
- if (options && options.method === 'beacon') {
560
- return {
561
- result: Promise.resolve(beacon(url)),
562
- };
563
- }
564
- return yield ajax('GET', url);
565
- });
543
+ async function getRequest(url, options) {
544
+ if (!url) {
545
+ return Promise.reject(new Error('URL is empty.'));
546
+ }
547
+ if (options && options.method === 'beacon') {
548
+ return {
549
+ result: Promise.resolve(beacon(url)),
550
+ };
551
+ }
552
+ return await ajax('GET', url);
566
553
  }
567
554
 
568
555
  let memoryConsent;
@@ -723,7 +710,7 @@ const saveDataToEdge = (key, value, provider) => {
723
710
  try {
724
711
  value = JSON.stringify(value);
725
712
  }
726
- catch (_a) {
713
+ catch {
727
714
  log('Error stringify value.');
728
715
  return;
729
716
  }
@@ -736,7 +723,7 @@ const handleCaptureQuery = (provider, key, persistType) => {
736
723
  return;
737
724
  }
738
725
  }
739
- catch (_a) {
726
+ catch {
740
727
  return;
741
728
  }
742
729
  const params = new URLSearchParams(window.location.search);
@@ -770,7 +757,7 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
770
757
  }
771
758
  }
772
759
  }
773
- catch (_a) {
760
+ catch {
774
761
  return;
775
762
  }
776
763
  if (!data) {
package/index.esm.js CHANGED
@@ -10,38 +10,6 @@ var api = /*#__PURE__*/Object.freeze({
10
10
  get user () { return user; }
11
11
  });
12
12
 
13
- /******************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
- /* global Reflect, Promise, SuppressedError, Symbol */
28
-
29
-
30
- function __awaiter(thisArg, _arguments, P, generator) {
31
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
- return new (P || (P = Promise))(function (resolve, reject) {
33
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37
- });
38
- }
39
-
40
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
41
- var e = new Error(message);
42
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
43
- };
44
-
45
13
  const getMessage = (error) => {
46
14
  if (error instanceof Error) {
47
15
  return error.message;
@@ -52,7 +20,7 @@ const getMessage = (error) => {
52
20
  try {
53
21
  return JSON.stringify(error);
54
22
  }
55
- catch (_a) {
23
+ catch {
56
24
  return error;
57
25
  }
58
26
  };
@@ -133,7 +101,7 @@ const setPreferences = (preferences) => {
133
101
  });
134
102
  }
135
103
  }
136
- catch (_b) {
104
+ catch {
137
105
  // do nothing
138
106
  }
139
107
  setUrl(preferences.edgeURL);
@@ -188,7 +156,7 @@ const getUserAgent = () => {
188
156
  const nav = navigator;
189
157
  return nav.userAgent;
190
158
  }
191
- catch (_a) {
159
+ catch {
192
160
  return '';
193
161
  }
194
162
  };
@@ -212,7 +180,7 @@ const getPageUrl = () => {
212
180
  }
213
181
  return window.location.href;
214
182
  }
215
- catch (_a) {
183
+ catch {
216
184
  return '';
217
185
  }
218
186
  };
@@ -220,7 +188,15 @@ const getSearch = () => {
220
188
  try {
221
189
  return window.location.search;
222
190
  }
223
- catch (_a) {
191
+ catch {
192
+ return '';
193
+ }
194
+ };
195
+ const getLocale = () => {
196
+ try {
197
+ return navigator.language;
198
+ }
199
+ catch {
224
200
  return '';
225
201
  }
226
202
  };
@@ -228,7 +204,7 @@ const getPageTitle = () => {
228
204
  try {
229
205
  return document.title;
230
206
  }
231
- catch (_a) {
207
+ catch {
232
208
  return '';
233
209
  }
234
210
  };
@@ -352,7 +328,10 @@ const saveKV = (data) => {
352
328
  if (!currentSession['kv']) {
353
329
  currentSession['kv'] = {};
354
330
  }
355
- currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
331
+ currentSession['kv'] = {
332
+ ...currentSession['kv'],
333
+ ...data,
334
+ };
356
335
  saveData('session', currentSession);
357
336
  };
358
337
  const saveLocal = (value, key) => {
@@ -362,7 +341,7 @@ const saveLocal = (value, key) => {
362
341
  }
363
342
  localStorage.setItem(key, JSON.stringify(value));
364
343
  }
365
- catch (_a) {
344
+ catch {
366
345
  log('Local storage not supported.');
367
346
  }
368
347
  };
@@ -377,7 +356,7 @@ const getLocal = (key) => {
377
356
  }
378
357
  return JSON.parse(data) || {};
379
358
  }
380
- catch (_a) {
359
+ catch {
381
360
  return {};
382
361
  }
383
362
  };
@@ -388,7 +367,7 @@ const saveSession = (value, key) => {
388
367
  }
389
368
  sessionStorage.setItem(key, JSON.stringify(value));
390
369
  }
391
- catch (_a) {
370
+ catch {
392
371
  log('Session storage not supported.');
393
372
  }
394
373
  };
@@ -403,7 +382,7 @@ const getSession = (key) => {
403
382
  }
404
383
  return JSON.parse(data) || {};
405
384
  }
406
- catch (_a) {
385
+ catch {
407
386
  return {};
408
387
  }
409
388
  };
@@ -434,7 +413,7 @@ const generateUUID = () => {
434
413
  }
435
414
  }
436
415
  }
437
- catch (_a) {
416
+ catch {
438
417
  id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
439
418
  console.log('[EdgeTag] Crypto module not found');
440
419
  }
@@ -471,7 +450,7 @@ const getCookieValue = (key) => {
471
450
  }
472
451
  return '';
473
452
  }
474
- catch (_a) {
453
+ catch {
475
454
  return '';
476
455
  }
477
456
  };
@@ -501,66 +480,74 @@ const beacon = (url, payload) => {
501
480
  return Promise.reject(new Error('Beacon not supported.'));
502
481
  }
503
482
  };
504
- const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
505
- return yield fetch(url, {
506
- method,
507
- headers: {
508
- 'Content-type': 'application/json; charset=utf-8',
509
- Accept: 'application/json; charset=utf-8',
510
- EdgeTagUserId: handleGetUserId(),
511
- },
512
- body: JSON.stringify(payload),
513
- credentials: 'include',
514
- })
515
- .then((response) => response.json().then((data) => ({ status: response.status, body: data })))
516
- .then((data) => {
517
- if (data.status < 200 || data.status >= 300) {
518
- return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
519
- }
520
- return Promise.resolve(data.body);
521
- })
522
- .catch((error) => {
523
- return Promise.reject(new Error(error));
524
- });
483
+ const ajax = (method, url, payload) => fetch(url, {
484
+ method,
485
+ headers: {
486
+ 'Content-type': 'application/json; charset=utf-8',
487
+ Accept: 'application/json; charset=utf-8',
488
+ EdgeTagUserId: handleGetUserId(),
489
+ },
490
+ body: JSON.stringify(payload),
491
+ credentials: 'include',
492
+ })
493
+ .then((response) => response
494
+ .json()
495
+ .then((data) => ({ status: response.status, body: data })))
496
+ .then(({ status, body }) => {
497
+ if (status < 200 || status >= 300) {
498
+ throw new Error(`Request failed with code ${status}: ${JSON.stringify(body)}`);
499
+ }
500
+ return Promise.resolve(body);
525
501
  });
526
502
  const getStandardPayload = (payload) => {
527
- const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.21.0" }, (payload || {}));
503
+ const data = {
504
+ pageUrl: getPageUrl(),
505
+ pageTitle: getPageTitle(),
506
+ userAgent: getUserAgent(),
507
+ referrer: getReferrer(),
508
+ search: getSearch(),
509
+ locale: getLocale(),
510
+ sdkVersion: "0.22.0" ,
511
+ ...(payload || {}),
512
+ };
528
513
  let storage = {};
529
514
  const session = getData$1('session');
530
515
  if (session) {
531
- storage = Object.assign(Object.assign({}, storage), session);
516
+ storage = {
517
+ ...storage,
518
+ ...session,
519
+ };
532
520
  }
533
521
  const local = getData$1('local');
534
522
  if (local) {
535
- storage = Object.assign(Object.assign({}, storage), local);
523
+ storage = {
524
+ ...storage,
525
+ ...local,
526
+ };
536
527
  }
537
528
  data.storage = storage;
538
529
  return data;
539
530
  };
540
- function postRequest(url, data, options) {
541
- return __awaiter(this, void 0, void 0, function* () {
542
- if (!url) {
543
- return Promise.reject(new Error('URL is empty.'));
544
- }
545
- const payload = getStandardPayload(data);
546
- if (options && options.method === 'beacon') {
547
- return Promise.resolve(beacon(url, payload));
548
- }
549
- return yield ajax('POST', url, payload);
550
- });
531
+ async function postRequest(url, data, options) {
532
+ if (!url) {
533
+ return Promise.reject(new Error('URL is empty.'));
534
+ }
535
+ const payload = getStandardPayload(data);
536
+ if (options && options.method === 'beacon') {
537
+ return Promise.resolve(beacon(url, payload));
538
+ }
539
+ return await ajax('POST', url, payload);
551
540
  }
552
- function getRequest(url, options) {
553
- return __awaiter(this, void 0, void 0, function* () {
554
- if (!url) {
555
- return Promise.reject(new Error('URL is empty.'));
556
- }
557
- if (options && options.method === 'beacon') {
558
- return {
559
- result: Promise.resolve(beacon(url)),
560
- };
561
- }
562
- return yield ajax('GET', url);
563
- });
541
+ async function getRequest(url, options) {
542
+ if (!url) {
543
+ return Promise.reject(new Error('URL is empty.'));
544
+ }
545
+ if (options && options.method === 'beacon') {
546
+ return {
547
+ result: Promise.resolve(beacon(url)),
548
+ };
549
+ }
550
+ return await ajax('GET', url);
564
551
  }
565
552
 
566
553
  let memoryConsent;
@@ -721,7 +708,7 @@ const saveDataToEdge = (key, value, provider) => {
721
708
  try {
722
709
  value = JSON.stringify(value);
723
710
  }
724
- catch (_a) {
711
+ catch {
725
712
  log('Error stringify value.');
726
713
  return;
727
714
  }
@@ -734,7 +721,7 @@ const handleCaptureQuery = (provider, key, persistType) => {
734
721
  return;
735
722
  }
736
723
  }
737
- catch (_a) {
724
+ catch {
738
725
  return;
739
726
  }
740
727
  const params = new URLSearchParams(window.location.search);
@@ -768,7 +755,7 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
768
755
  }
769
756
  }
770
757
  }
771
- catch (_a) {
758
+ catch {
772
759
  return;
773
760
  }
774
761
  if (!data) {
package/internal.d.ts CHANGED
@@ -33,6 +33,7 @@ type PostPayload = {
33
33
  pageTitle: string
34
34
  referrer: string
35
35
  search: string
36
+ locale: string
36
37
  sdkVersion: string
37
38
  userAgent: string
38
39
  data?: Data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",