@blotoutio/edgetag-sdk-browser 1.17.0 → 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.
Files changed (2) hide show
  1. package/index.js +45 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11,6 +11,7 @@
11
11
  get init () { return init; },
12
12
  get isNewUser () { return isNewUser; },
13
13
  get keys () { return keys; },
14
+ get ready () { return ready; },
14
15
  get setConfig () { return setConfig; },
15
16
  get tag () { return tag; },
16
17
  get user () { return user; }
@@ -926,7 +927,7 @@
926
927
  referrer: getReferrer(destination),
927
928
  search: getSearch(destination),
928
929
  locale: getLocale(),
929
- sdkVersion: "1.17.0" ,
930
+ sdkVersion: "1.18.0" ,
930
931
  ...(payload || {}),
931
932
  };
932
933
  let storage = {};
@@ -1573,6 +1574,32 @@
1573
1574
  processStubs(destination);
1574
1575
  };
1575
1576
 
1577
+ const mapData = (data) => async (callback) => {
1578
+ try {
1579
+ await callback(data);
1580
+ }
1581
+ catch (err) {
1582
+ console.error(err);
1583
+ }
1584
+ };
1585
+ const callbacks = new Set();
1586
+ const resolved = new Set();
1587
+ const onReady = async (data) => {
1588
+ const callbackData = {
1589
+ destination: data.destination,
1590
+ userId: data.userId,
1591
+ sessionId: data.session.sessionId,
1592
+ isNewUser: data.isNewUser,
1593
+ isNewSession: data.session.isNewSession,
1594
+ };
1595
+ resolved.add(callbackData);
1596
+ await Promise.all([...callbacks].map(mapData(callbackData)));
1597
+ };
1598
+ const handleReady = async (callback) => {
1599
+ callbacks.add(callback);
1600
+ await Promise.all([...resolved.values()].map((data) => mapData(data)(callback)));
1601
+ };
1602
+
1576
1603
  const handleInit = (preferences) => {
1577
1604
  const browserPackages = setPreferences(preferences);
1578
1605
  if (!browserPackages) {
@@ -1670,16 +1697,18 @@
1670
1697
  }
1671
1698
  handleManifest(preferences.edgeURL, result);
1672
1699
  try {
1700
+ const detail = {
1701
+ destination: preferences.edgeURL,
1702
+ userId: result.userId,
1703
+ isNewUser: result.isNewUser,
1704
+ consent: result.consent,
1705
+ consentSetting: result.consentSetting,
1706
+ session: result.session,
1707
+ };
1673
1708
  window.dispatchEvent(new CustomEvent('edgetag-initialized', {
1674
- detail: {
1675
- destination: preferences.edgeURL,
1676
- userId: result.userId,
1677
- isNewUser: result.isNewUser,
1678
- consent: result.consent,
1679
- consentSetting: result.consentSetting,
1680
- session: result.session,
1681
- },
1709
+ detail,
1682
1710
  }));
1711
+ onReady(detail);
1683
1712
  }
1684
1713
  catch {
1685
1714
  // do nothing
@@ -1863,6 +1892,9 @@
1863
1892
  const setConfig = (config, options) => {
1864
1893
  handleConfig(config, options);
1865
1894
  };
1895
+ const ready = (callback) => {
1896
+ handleReady(callback);
1897
+ };
1866
1898
 
1867
1899
  // TODO https://github.com/blotoutio/solutions/issues/826
1868
1900
 
@@ -1910,6 +1942,10 @@
1910
1942
  setConfig(config, options) {
1911
1943
  setConfig(config, options);
1912
1944
  }
1945
+
1946
+ ready(callback) {
1947
+ ready(callback);
1948
+ }
1913
1949
  }
1914
1950
 
1915
1951
  var api = new API();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",