@blotoutio/edgetag-sdk-browser 0.6.5 → 0.6.6

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 +100 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,18 @@
1
1
  (function () {
2
2
  'use strict';
3
3
 
4
+ var api$1 = /*#__PURE__*/Object.freeze({
5
+ __proto__: null,
6
+ get init () { return init; },
7
+ get tag () { return tag; },
8
+ get consent () { return consent; },
9
+ get user () { return user; },
10
+ get data () { return data; },
11
+ get getData () { return getData; },
12
+ get keys () { return keys; },
13
+ get getUserId () { return getUserId; }
14
+ });
15
+
4
16
  /******************************************************************************
5
17
  Copyright (c) Microsoft Corporation.
6
18
 
@@ -193,6 +205,7 @@
193
205
  return generateUrl(`/keys`);
194
206
  };
195
207
 
208
+ let initialized = false;
196
209
  let consentDisabled = false;
197
210
  const providers = {};
198
211
  const setPreferences = (preferences) => {
@@ -224,6 +237,10 @@
224
237
  };
225
238
  const isConsentDisabled = () => consentDisabled;
226
239
  const getProvidersPackage = () => providers;
240
+ const isInitialized = () => initialized;
241
+ const setInitialized = () => {
242
+ initialized = true;
243
+ };
227
244
 
228
245
  const getUserAgent = () => {
229
246
  const nav = navigator;
@@ -867,6 +884,24 @@
867
884
  };
868
885
  const getProviderVariables = (name) => manifestVariables[name] || {};
869
886
 
887
+ let stubs = [];
888
+ const addStubs = (newStubs) => {
889
+ stubs = [...stubs, ...newStubs];
890
+ };
891
+ const addStub = (stub) => {
892
+ stubs.push(stub);
893
+ };
894
+ const processStubs = () => {
895
+ try {
896
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
897
+ // @ts-ignore
898
+ stubs.forEach((stub) => api$1[stub.name](...(stub.arguments || [])));
899
+ }
900
+ catch (e) {
901
+ console.error(e);
902
+ }
903
+ };
904
+
870
905
  const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
871
906
  const payload = {
872
907
  eventName,
@@ -881,6 +916,13 @@
881
916
  postRequest(getTagURL(), payload, options).catch(info);
882
917
  };
883
918
  const handleTag = (eventName, data = {}, providers, options) => {
919
+ if (!isInitialized()) {
920
+ addStub({
921
+ name: 'tag',
922
+ arguments: [eventName, data, providers, options],
923
+ });
924
+ return;
925
+ }
884
926
  if (!allowTag(providers)) {
885
927
  console.log('No consent');
886
928
  return;
@@ -1025,6 +1067,8 @@
1025
1067
  }
1026
1068
  }
1027
1069
  });
1070
+ setInitialized();
1071
+ processStubs();
1028
1072
  savePerKey('local', tagStorage, providers, providersKey);
1029
1073
  };
1030
1074
 
@@ -1033,6 +1077,9 @@
1033
1077
  if (!success) {
1034
1078
  return;
1035
1079
  }
1080
+ if (preferences.afterManifestEvents) {
1081
+ addStubs(preferences.afterManifestEvents);
1082
+ }
1036
1083
  const url = new URL(getInitURL());
1037
1084
  if (preferences.disableConsentCheck) {
1038
1085
  url.searchParams.set('consentDisabled', 'true');
@@ -1107,6 +1154,9 @@
1107
1154
  const keys = (callback) => {
1108
1155
  handleKeys(callback);
1109
1156
  };
1157
+ const getUserId = () => {
1158
+ return handleGetUserId();
1159
+ };
1110
1160
 
1111
1161
  // TODO https://github.com/blotoutio/solutions/issues/826
1112
1162
 
@@ -1143,16 +1193,9 @@
1143
1193
  var api = new API();
1144
1194
 
1145
1195
  (function () {
1146
- const handleFunction = (arg) => {
1147
- const sliced = [].slice.call(arg);
1148
- if (!Array.isArray(sliced)) {
1149
- return
1150
- }
1151
-
1196
+ const handleStubs = (event) => {
1152
1197
  try {
1153
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1154
- // @ts-ignore
1155
- return library[sliced[0]](...sliced.slice(1))
1198
+ return library[event.name](...event.arguments)
1156
1199
  } catch (e) {
1157
1200
  console.error(e);
1158
1201
  }
@@ -1161,19 +1204,61 @@
1161
1204
  const library = api;
1162
1205
  let stubs = [];
1163
1206
  if (window.edgetag) {
1164
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1165
- // @ts-ignore
1166
1207
  stubs = window.edgetag.stubs || [];
1167
1208
  }
1168
1209
 
1169
1210
  // this needs to be regular function for arguments to work
1170
1211
  window.edgetag = function () {
1171
- // eslint-disable-next-line prefer-rest-params
1172
- return handleFunction(arguments)
1212
+ const sliced = [].slice.call(arguments);
1213
+ if (!Array.isArray(sliced)) {
1214
+ return
1215
+ }
1216
+
1217
+ try {
1218
+ return library[sliced[0]](...sliced.slice(1))
1219
+ } catch (e) {
1220
+ console.error(e);
1221
+ }
1173
1222
  };
1174
1223
 
1175
- // restore calls that were triggered before lib was ready
1176
- stubs.forEach(handleFunction);
1224
+ const beforeManifestEvents = [];
1225
+ const afterManifestEvents = [];
1226
+ let initCall = null;
1227
+
1228
+ stubs.forEach((arg) => {
1229
+ const sliced = [].slice.call(arg);
1230
+ if (!Array.isArray(sliced)) {
1231
+ return
1232
+ }
1233
+
1234
+ if (sliced[0] === 'init') {
1235
+ initCall = sliced.slice(1);
1236
+ return
1237
+ }
1238
+
1239
+ if (sliced[0] === 'tag') {
1240
+ afterManifestEvents.push({
1241
+ name: sliced[0],
1242
+ arguments: sliced.slice(1),
1243
+ });
1244
+ return
1245
+ }
1246
+
1247
+ beforeManifestEvents.push({
1248
+ name: sliced[0],
1249
+ arguments: sliced.slice(1),
1250
+ });
1251
+ });
1252
+
1253
+ if (initCall) {
1254
+ initCall[0]['afterManifestEvents'] = afterManifestEvents;
1255
+ handleStubs({
1256
+ name: 'init',
1257
+ arguments: initCall,
1258
+ });
1259
+ }
1260
+
1261
+ beforeManifestEvents.forEach(handleStubs);
1177
1262
  })();
1178
1263
 
1179
1264
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",