@blotoutio/edgetag-sdk-js 0.4.0 → 0.5.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/api/data.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { DataValue } from '../typings';
2
- export declare const handleData: (data: Record<string, DataValue>) => void;
1
+ import { EventOptions } from '../typings';
2
+ export declare const handleData: (data: Record<string, string>, options?: EventOptions) => void;
package/api/getData.d.ts CHANGED
@@ -1,2 +1 @@
1
- import { DataValue } from '../typings';
2
- export declare const handleGetData: (keys: string[], callback: (data: Record<string, DataValue>) => void) => void;
1
+ export declare const handleGetData: (keys: string[], callback: (data: Record<string, string>) => void) => void;
package/api/tag.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Data } from '../typings';
2
- export declare const handleTag: (name: string, data?: Data, providers?: Data) => void;
1
+ import { Data, EventOptions } from '../typings';
2
+ export declare const handleTag: (name: string, data?: Data, providers?: Data, options?: EventOptions) => void;
package/api/user.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { UserKey } from '../typings';
2
- export declare const handleUser: (key: UserKey, value: string) => void;
1
+ import { EventOptions, UserKey } from '../typings';
2
+ export declare const handleUser: (key: UserKey, value: string, options?: EventOptions) => void;
@@ -1,8 +1,7 @@
1
1
  import { PersistType } from '../typings/internal';
2
- import { DataValue } from '../typings';
3
2
  export declare const saveDataPerKey: (persistType: PersistType, provider: string, value: unknown, key: string) => void;
4
3
  export declare const savePerKey: (persistType: PersistType, provider: string, value: unknown, key: string) => void;
5
4
  export declare const getDataPerKey: (persistType: PersistType, provider: string, key: string) => unknown;
6
5
  export declare const saveData: (persistType: PersistType, value: unknown, key?: string) => void;
7
6
  export declare const getData: (persistType: PersistType, key?: string) => Record<string, Record<string, unknown>>;
8
- export declare const saveDataAPI: (data: Record<string, DataValue>) => void;
7
+ export declare const saveKV: (data: Record<string, string>) => void;
package/index.cjs CHANGED
@@ -81,18 +81,18 @@ const getData$1 = (persistType, key = initKey) => {
81
81
 
82
82
  return getLocal(key);
83
83
  };
84
- const saveDataAPI = data => {
84
+ const saveKV = data => {
85
85
  let currentSession = getData$1('session');
86
86
 
87
87
  if (!currentSession) {
88
88
  currentSession = {};
89
89
  }
90
90
 
91
- if (!currentSession['data']) {
92
- currentSession['data'] = {};
91
+ if (!currentSession['kv']) {
92
+ currentSession['kv'] = {};
93
93
  }
94
94
 
95
- currentSession['data'] = Object.assign(Object.assign({}, currentSession['data']), data);
95
+ currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
96
96
  saveData('session', currentSession);
97
97
  };
98
98
 
@@ -330,7 +330,7 @@ const handleConsent = consent => {
330
330
  postRequest(getConsentURL(), payload).catch(info);
331
331
  };
332
332
 
333
- const handleTag = (name, data, providers) => {
333
+ const handleTag = (name, data, providers, options) => {
334
334
  const payload = {
335
335
  eventName: name
336
336
  };
@@ -348,7 +348,7 @@ const handleTag = (name, data, providers) => {
348
348
  return;
349
349
  }
350
350
 
351
- postRequest(getTagURL(), payload).catch(info);
351
+ postRequest(getTagURL(), payload, options).catch(info);
352
352
  };
353
353
 
354
354
  const getCookieValue = key => {
@@ -453,16 +453,20 @@ const handleInit = preferences => {
453
453
  return;
454
454
  }
455
455
 
456
- let url = `${getInitURL()}`;
456
+ const url = new URL(getInitURL());
457
457
 
458
458
  if (preferences.disableConsentCheck) {
459
- url = `${url}?consentDisabled=true`;
459
+ url.searchParams.set('consentDisabled', 'true');
460
460
  saveConsent({
461
461
  all: true
462
462
  });
463
463
  }
464
464
 
465
- getRequest(url).then(result => {
465
+ if (preferences.userId) {
466
+ url.searchParams.set('userId', preferences.userId);
467
+ }
468
+
469
+ getRequest(url.href).then(result => {
466
470
  if (!result) {
467
471
  console.log('init failed');
468
472
  return;
@@ -472,31 +476,31 @@ const handleInit = preferences => {
472
476
  }).catch(info);
473
477
  };
474
478
 
475
- const handleUser = (key, value) => {
479
+ const handleUser = (key, value, options) => {
476
480
  if (!key || !value) {
477
481
  console.error('Key or Value is missing in user API.');
478
482
  return;
479
483
  }
480
484
 
481
- saveDataAPI({
485
+ saveKV({
482
486
  [key]: value
483
487
  });
484
488
  postRequest(getUserURL(), {
485
489
  key,
486
490
  value
487
- }).catch(info);
491
+ }, options).catch(info);
488
492
  };
489
493
 
490
- const handleData = data => {
494
+ const handleData = (data, options) => {
491
495
  if (!data || Object.keys(data).length === 0) {
492
496
  console.error('Provide data for data API.');
493
497
  return;
494
498
  }
495
499
 
496
- saveDataAPI(data);
500
+ saveKV(data);
497
501
  postRequest(getDataURL(), {
498
502
  data
499
- }).catch(info);
503
+ }, options).catch(info);
500
504
  };
501
505
 
502
506
  const handleGetData = (keys, callback) => {
@@ -519,17 +523,17 @@ const handleKeys = callback => {
519
523
  const init = preferences => {
520
524
  handleInit(preferences);
521
525
  };
522
- const tag = (name, data, providers) => {
523
- handleTag(name, data, providers);
526
+ const tag = (name, data, providers, options) => {
527
+ handleTag(name, data, providers, options);
524
528
  };
525
529
  const consent = consent => {
526
530
  handleConsent(consent);
527
531
  };
528
- const user = (key, value) => {
529
- handleUser(key, value);
532
+ const user = (key, value, options) => {
533
+ handleUser(key, value, options);
530
534
  };
531
- const data = data => {
532
- handleData(data);
535
+ const data = (data, options) => {
536
+ handleData(data, options);
533
537
  };
534
538
  const getData = (keys, callback) => {
535
539
  handleGetData(keys, callback);
package/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Data, DataValue, InitPreferences, UserKey } from './typings';
1
+ import { Data, EventOptions, InitPreferences, UserKey } from './typings';
2
2
  export declare const init: (preferences: InitPreferences) => void;
3
- export declare const tag: (name: string, data?: Data, providers?: Data) => void;
3
+ export declare const tag: (name: string, data?: Data, providers?: Data, options?: EventOptions) => void;
4
4
  export declare const consent: (consent: Data) => void;
5
- export declare const user: (key: UserKey, value: string) => void;
6
- export declare const data: (data: Record<string, DataValue>) => void;
7
- export declare const getData: (keys: string[], callback: (data: Record<string, DataValue>) => void) => void;
5
+ export declare const user: (key: UserKey, value: string, options?: EventOptions) => void;
6
+ export declare const data: (data: Record<string, string>, options?: EventOptions) => void;
7
+ export declare const getData: (keys: string[], callback: (data: Record<string, string>) => void) => void;
8
8
  export declare const keys: (callback: (keys: string[]) => void) => void;
package/index.js CHANGED
@@ -77,18 +77,18 @@ const getData$1 = (persistType, key = initKey) => {
77
77
 
78
78
  return getLocal(key);
79
79
  };
80
- const saveDataAPI = data => {
80
+ const saveKV = data => {
81
81
  let currentSession = getData$1('session');
82
82
 
83
83
  if (!currentSession) {
84
84
  currentSession = {};
85
85
  }
86
86
 
87
- if (!currentSession['data']) {
88
- currentSession['data'] = {};
87
+ if (!currentSession['kv']) {
88
+ currentSession['kv'] = {};
89
89
  }
90
90
 
91
- currentSession['data'] = Object.assign(Object.assign({}, currentSession['data']), data);
91
+ currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
92
92
  saveData('session', currentSession);
93
93
  };
94
94
 
@@ -326,7 +326,7 @@ const handleConsent = consent => {
326
326
  postRequest(getConsentURL(), payload).catch(info);
327
327
  };
328
328
 
329
- const handleTag = (name, data, providers) => {
329
+ const handleTag = (name, data, providers, options) => {
330
330
  const payload = {
331
331
  eventName: name
332
332
  };
@@ -344,7 +344,7 @@ const handleTag = (name, data, providers) => {
344
344
  return;
345
345
  }
346
346
 
347
- postRequest(getTagURL(), payload).catch(info);
347
+ postRequest(getTagURL(), payload, options).catch(info);
348
348
  };
349
349
 
350
350
  const getCookieValue = key => {
@@ -449,16 +449,20 @@ const handleInit = preferences => {
449
449
  return;
450
450
  }
451
451
 
452
- let url = `${getInitURL()}`;
452
+ const url = new URL(getInitURL());
453
453
 
454
454
  if (preferences.disableConsentCheck) {
455
- url = `${url}?consentDisabled=true`;
455
+ url.searchParams.set('consentDisabled', 'true');
456
456
  saveConsent({
457
457
  all: true
458
458
  });
459
459
  }
460
460
 
461
- getRequest(url).then(result => {
461
+ if (preferences.userId) {
462
+ url.searchParams.set('userId', preferences.userId);
463
+ }
464
+
465
+ getRequest(url.href).then(result => {
462
466
  if (!result) {
463
467
  console.log('init failed');
464
468
  return;
@@ -468,31 +472,31 @@ const handleInit = preferences => {
468
472
  }).catch(info);
469
473
  };
470
474
 
471
- const handleUser = (key, value) => {
475
+ const handleUser = (key, value, options) => {
472
476
  if (!key || !value) {
473
477
  console.error('Key or Value is missing in user API.');
474
478
  return;
475
479
  }
476
480
 
477
- saveDataAPI({
481
+ saveKV({
478
482
  [key]: value
479
483
  });
480
484
  postRequest(getUserURL(), {
481
485
  key,
482
486
  value
483
- }).catch(info);
487
+ }, options).catch(info);
484
488
  };
485
489
 
486
- const handleData = data => {
490
+ const handleData = (data, options) => {
487
491
  if (!data || Object.keys(data).length === 0) {
488
492
  console.error('Provide data for data API.');
489
493
  return;
490
494
  }
491
495
 
492
- saveDataAPI(data);
496
+ saveKV(data);
493
497
  postRequest(getDataURL(), {
494
498
  data
495
- }).catch(info);
499
+ }, options).catch(info);
496
500
  };
497
501
 
498
502
  const handleGetData = (keys, callback) => {
@@ -515,17 +519,17 @@ const handleKeys = callback => {
515
519
  const init = preferences => {
516
520
  handleInit(preferences);
517
521
  };
518
- const tag = (name, data, providers) => {
519
- handleTag(name, data, providers);
522
+ const tag = (name, data, providers, options) => {
523
+ handleTag(name, data, providers, options);
520
524
  };
521
525
  const consent = consent => {
522
526
  handleConsent(consent);
523
527
  };
524
- const user = (key, value) => {
525
- handleUser(key, value);
528
+ const user = (key, value, options) => {
529
+ handleUser(key, value, options);
526
530
  };
527
- const data = data => {
528
- handleData(data);
531
+ const data = (data, options) => {
532
+ handleData(data, options);
529
533
  };
530
534
  const getData = (keys, callback) => {
531
535
  handleGetData(keys, callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
@@ -13,11 +13,10 @@ type UserKey =
13
13
 
14
14
  type Data = Record<string, unknown>
15
15
 
16
- type DataValue = string | number | boolean
17
-
18
16
  interface InitPreferences {
19
17
  edgeURL: string
20
18
  disableConsentCheck?: boolean
19
+ userId?: string
21
20
  }
22
21
 
23
22
  interface EventOptions {
@@ -32,11 +31,11 @@ export declare const consent: (consent: Data) => void
32
31
 
33
32
  export declare const user: (key: UserKey, value: string) => void
34
33
 
35
- export declare const data: (data: Record<string, DataValue>) => void
34
+ export declare const data: (data: Record<string, string>) => void
36
35
 
37
36
  export declare const getData: (
38
37
  keys: string[],
39
- callback: (data: Record<string, DataValue>) => void
38
+ callback: (data: Record<string, string>) => void
40
39
  ) => void
41
40
 
42
41
  export declare const keys: (callback: (keys: string[]) => void) => void
@@ -1,4 +1,4 @@
1
- import { Data, DataValue, UserKey } from './index'
1
+ import { Data, UserKey } from './index'
2
2
 
3
3
  type PersistType = 'local' | 'session'
4
4
 
@@ -23,7 +23,7 @@ type UserPayload = {
23
23
  }
24
24
 
25
25
  type DataPayload = {
26
- data: Record<string, DataValue>
26
+ data: Record<string, string>
27
27
  }
28
28
 
29
29
  type PostPayload = {