@blotoutio/edgetag-sdk-browser 0.10.4-beta.1 → 0.10.4

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 (2) hide show
  1. package/index.js +8 -50
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -295,6 +295,7 @@
295
295
  const tagStorage = 'edgeTag';
296
296
  const consentKey = 'consent';
297
297
  const keyPrefix = `_worker`;
298
+ const cookieKey = 'tag_user_id';
298
299
 
299
300
  const initKey = `${keyPrefix}Store`;
300
301
  const saveDataPerKey = (persistType, provider, value, key) => {
@@ -473,17 +474,12 @@
473
474
  if (initUserId) {
474
475
  return initUserId;
475
476
  }
476
- return getCookieValue('tag_user_id');
477
+ return getCookieValue(cookieKey);
477
478
  };
478
479
  const setUserId = (userId) => {
479
480
  initUserId = userId;
480
481
  };
481
482
 
482
- const getHeaders = () => ({
483
- 'Content-type': 'application/json; charset=utf-8',
484
- Accept: 'application/json; charset=utf-8',
485
- EdgeTagUserId: handleGetUserId(),
486
- });
487
483
  const beacon = (url, payload) => {
488
484
  try {
489
485
  let blob;
@@ -496,52 +492,14 @@
496
492
  return Promise.reject(new Error('Beacon not supported.'));
497
493
  }
498
494
  };
499
- const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
500
- const https = yield import('https');
501
- const options = {
502
- method,
503
- headers: getHeaders(),
504
- };
505
- return new Promise((resolve, reject) => {
506
- const req = https.request(url, options, (res) => {
507
- res.on('data', (data) => {
508
- try {
509
- data = JSON.parse(data);
510
- }
511
- catch (_a) {
512
- // do nothing
513
- }
514
- resolve({
515
- body: data,
516
- status: res.statusCode || 500,
517
- });
518
- });
519
- });
520
- req.on('error', (e) => {
521
- reject(new Error(e.message));
522
- });
523
- if (payload && method !== 'GET') {
524
- req.write(JSON.stringify(payload));
525
- }
526
- req.end();
527
- });
528
- });
529
495
  const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
530
- if (typeof fetch === 'undefined') {
531
- return yield fallbackAjax(method, url, payload)
532
- .then((data) => {
533
- if (data.status < 200 || data.status >= 300) {
534
- return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
535
- }
536
- return Promise.resolve(data.body);
537
- })
538
- .catch((error) => {
539
- return Promise.reject(new Error(error));
540
- });
541
- }
542
496
  return yield fetch(url, {
543
497
  method,
544
- headers: getHeaders(),
498
+ headers: {
499
+ 'Content-type': 'application/json; charset=utf-8',
500
+ Accept: 'application/json; charset=utf-8',
501
+ EdgeTagUserId: handleGetUserId(),
502
+ },
545
503
  body: JSON.stringify(payload),
546
504
  credentials: 'include',
547
505
  })
@@ -557,7 +515,7 @@
557
515
  });
558
516
  });
559
517
  const getStandardPayload = (payload) => {
560
- const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.3" }, (payload || {}));
518
+ const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.4" }, (payload || {}));
561
519
  let storage = {};
562
520
  const session = getData$1('session');
563
521
  if (session) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.10.4-beta.1",
3
+ "version": "0.10.4",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",