@blotoutio/edgetag-sdk-js 1.17.1 → 1.18.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.js CHANGED
@@ -10,6 +10,7 @@ var api = /*#__PURE__*/Object.freeze({
10
10
  get init () { return init; },
11
11
  get isNewUser () { return isNewUser; },
12
12
  get keys () { return keys; },
13
+ get ready () { return ready; },
13
14
  get setConfig () { return setConfig; },
14
15
  get tag () { return tag; },
15
16
  get user () { return user; }
@@ -925,7 +926,7 @@ const getStandardPayload = (destination, payload) => {
925
926
  referrer: getReferrer(destination),
926
927
  search: getSearch(destination),
927
928
  locale: getLocale(),
928
- sdkVersion: "1.17.1" ,
929
+ sdkVersion: "1.18.0" ,
929
930
  ...(payload || {}),
930
931
  };
931
932
  let storage = {};
@@ -1572,6 +1573,32 @@ const handleManifest = (destination, response) => {
1572
1573
  processStubs(destination);
1573
1574
  };
1574
1575
 
1576
+ const mapData = (data) => async (callback) => {
1577
+ try {
1578
+ await callback(data);
1579
+ }
1580
+ catch (err) {
1581
+ console.error(err);
1582
+ }
1583
+ };
1584
+ const callbacks = new Set();
1585
+ const resolved = new Set();
1586
+ const onReady = async (data) => {
1587
+ const callbackData = {
1588
+ destination: data.destination,
1589
+ userId: data.userId,
1590
+ sessionId: data.session.sessionId,
1591
+ isNewUser: data.isNewUser,
1592
+ isNewSession: data.session.isNewSession,
1593
+ };
1594
+ resolved.add(callbackData);
1595
+ await Promise.all([...callbacks].map(mapData(callbackData)));
1596
+ };
1597
+ const handleReady = async (callback) => {
1598
+ callbacks.add(callback);
1599
+ await Promise.all([...resolved.values()].map((data) => mapData(data)(callback)));
1600
+ };
1601
+
1575
1602
  const handleInit = (preferences) => {
1576
1603
  const browserPackages = setPreferences(preferences);
1577
1604
  if (!browserPackages) {
@@ -1669,16 +1696,18 @@ const handleInit = (preferences) => {
1669
1696
  }
1670
1697
  handleManifest(preferences.edgeURL, result);
1671
1698
  try {
1699
+ const detail = {
1700
+ destination: preferences.edgeURL,
1701
+ userId: result.userId,
1702
+ isNewUser: result.isNewUser,
1703
+ consent: result.consent,
1704
+ consentSetting: result.consentSetting,
1705
+ session: result.session,
1706
+ };
1672
1707
  window.dispatchEvent(new CustomEvent('edgetag-initialized', {
1673
- detail: {
1674
- destination: preferences.edgeURL,
1675
- userId: result.userId,
1676
- isNewUser: result.isNewUser,
1677
- consent: result.consent,
1678
- consentSetting: result.consentSetting,
1679
- session: result.session,
1680
- },
1708
+ detail,
1681
1709
  }));
1710
+ onReady(detail);
1682
1711
  }
1683
1712
  catch {
1684
1713
  // do nothing
@@ -1862,6 +1891,9 @@ const isNewUser = (options) => {
1862
1891
  const setConfig = (config, options) => {
1863
1892
  handleConfig(config, options);
1864
1893
  };
1894
+ const ready = (callback) => {
1895
+ handleReady(callback);
1896
+ };
1865
1897
 
1866
1898
  exports.consent = consent;
1867
1899
  exports.data = data;
@@ -1871,6 +1903,7 @@ exports.getUserId = getUserId;
1871
1903
  exports.init = init;
1872
1904
  exports.isNewUser = isNewUser;
1873
1905
  exports.keys = keys;
1906
+ exports.ready = ready;
1874
1907
  exports.setConfig = setConfig;
1875
1908
  exports.tag = tag;
1876
1909
  exports.user = user;
package/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export {
21
21
  GetDataOptions,
22
22
  IsNewUserOptions,
23
23
  GetUserIdOptions,
24
+ ReadyCallback,
24
25
  } from '@blotoutio/shared/utility-sdk'
25
26
 
26
27
  export type UserKey =
@@ -101,6 +102,8 @@ export declare const getConsent: (
101
102
  options?: GetConsentOptions
102
103
  ) => void
103
104
 
105
+ export declare const ready: (callback: ReadyCallback) => void
106
+
104
107
  export declare global {
105
108
  interface Window {
106
109
  edgetagData: Record<string, string>
package/index.mjs CHANGED
@@ -8,6 +8,7 @@ var api = /*#__PURE__*/Object.freeze({
8
8
  get init () { return init; },
9
9
  get isNewUser () { return isNewUser; },
10
10
  get keys () { return keys; },
11
+ get ready () { return ready; },
11
12
  get setConfig () { return setConfig; },
12
13
  get tag () { return tag; },
13
14
  get user () { return user; }
@@ -923,7 +924,7 @@ const getStandardPayload = (destination, payload) => {
923
924
  referrer: getReferrer(destination),
924
925
  search: getSearch(destination),
925
926
  locale: getLocale(),
926
- sdkVersion: "1.17.1" ,
927
+ sdkVersion: "1.18.0" ,
927
928
  ...(payload || {}),
928
929
  };
929
930
  let storage = {};
@@ -1570,6 +1571,32 @@ const handleManifest = (destination, response) => {
1570
1571
  processStubs(destination);
1571
1572
  };
1572
1573
 
1574
+ const mapData = (data) => async (callback) => {
1575
+ try {
1576
+ await callback(data);
1577
+ }
1578
+ catch (err) {
1579
+ console.error(err);
1580
+ }
1581
+ };
1582
+ const callbacks = new Set();
1583
+ const resolved = new Set();
1584
+ const onReady = async (data) => {
1585
+ const callbackData = {
1586
+ destination: data.destination,
1587
+ userId: data.userId,
1588
+ sessionId: data.session.sessionId,
1589
+ isNewUser: data.isNewUser,
1590
+ isNewSession: data.session.isNewSession,
1591
+ };
1592
+ resolved.add(callbackData);
1593
+ await Promise.all([...callbacks].map(mapData(callbackData)));
1594
+ };
1595
+ const handleReady = async (callback) => {
1596
+ callbacks.add(callback);
1597
+ await Promise.all([...resolved.values()].map((data) => mapData(data)(callback)));
1598
+ };
1599
+
1573
1600
  const handleInit = (preferences) => {
1574
1601
  const browserPackages = setPreferences(preferences);
1575
1602
  if (!browserPackages) {
@@ -1667,16 +1694,18 @@ const handleInit = (preferences) => {
1667
1694
  }
1668
1695
  handleManifest(preferences.edgeURL, result);
1669
1696
  try {
1697
+ const detail = {
1698
+ destination: preferences.edgeURL,
1699
+ userId: result.userId,
1700
+ isNewUser: result.isNewUser,
1701
+ consent: result.consent,
1702
+ consentSetting: result.consentSetting,
1703
+ session: result.session,
1704
+ };
1670
1705
  window.dispatchEvent(new CustomEvent('edgetag-initialized', {
1671
- detail: {
1672
- destination: preferences.edgeURL,
1673
- userId: result.userId,
1674
- isNewUser: result.isNewUser,
1675
- consent: result.consent,
1676
- consentSetting: result.consentSetting,
1677
- session: result.session,
1678
- },
1706
+ detail,
1679
1707
  }));
1708
+ onReady(detail);
1680
1709
  }
1681
1710
  catch {
1682
1711
  // do nothing
@@ -1860,5 +1889,8 @@ const isNewUser = (options) => {
1860
1889
  const setConfig = (config, options) => {
1861
1890
  handleConfig(config, options);
1862
1891
  };
1892
+ const ready = (callback) => {
1893
+ handleReady(callback);
1894
+ };
1863
1895
 
1864
- export { consent, data, getConsent, getData, getUserId, init, isNewUser, keys, setConfig, tag, user };
1896
+ export { consent, data, getConsent, getData, getUserId, init, isNewUser, keys, ready, setConfig, tag, user };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "1.17.1",
3
+ "version": "1.18.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",