@adobe/alloy 2.34.2-beta.1 → 2.34.2-beta.3

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/dist/alloy.js CHANGED
@@ -6667,7 +6667,9 @@
6667
6667
  // so that sendBeacon requests don't override the edge info from before.
6668
6668
  edge = { ...edge, ...response.getEdge() };
6669
6669
 
6670
- identity.setIdentityAcquired();
6670
+ if (identity.getEcidFromCookie()) {
6671
+ identity.setIdentityAcquired();
6672
+ }
6671
6673
 
6672
6674
  return handleResponseForIdSyncs(response);
6673
6675
  },
@@ -7552,10 +7554,10 @@
7552
7554
  governing permissions and limitations under the License.
7553
7555
  */
7554
7556
 
7555
- // The 2.34.2-beta.1 keyword will be replace at alloy build time with the package.json version.
7557
+ // The 2.34.2-beta.3 keyword will be replace at alloy build time with the package.json version.
7556
7558
  // see babel-plugin-version
7557
7559
 
7558
- var libraryVersion = "2.34.2-beta.1";
7560
+ var libraryVersion = "2.34.2-beta.3";
7559
7561
 
7560
7562
  /*
7561
7563
  Copyright 2019 Adobe. All rights reserved.
@@ -17030,10 +17032,24 @@
17030
17032
  };
17031
17033
  });
17032
17034
  };
17033
- const loadScript = (url) => {
17035
+ const loadScript = (source) => {
17036
+ const url = getAttribute(source, SRC);
17034
17037
  const script = document.createElement("script");
17035
- script.src = url;
17038
+ // Preserve all author-supplied attributes (class, type, data-*, etc.) so
17039
+ // consumers relying on them keep working.
17040
+ const { attributes } = source;
17041
+ for (let i = 0; i < attributes.length; i += 1) {
17042
+ const { name, value } = attributes[i];
17043
+ script.setAttribute(name, value);
17044
+ }
17045
+ // Override invariants last so they can't be clobbered by the source element.
17046
+ const nonce = getNonce();
17047
+ if (nonce) {
17048
+ script.setAttribute("nonce", nonce);
17049
+ }
17036
17050
  script.async = true;
17051
+ // Assign load handlers after copying attributes so a copied inline
17052
+ // onload/onerror attribute can't break load-completion tracking.
17037
17053
  const promise = getPromise(url, script);
17038
17054
  document.head.appendChild(script);
17039
17055
  return promise;
@@ -17076,7 +17092,7 @@
17076
17092
  return result;
17077
17093
  };
17078
17094
 
17079
- const getRemoteScriptsUrls = (fragment) => {
17095
+ const getRemoteScripts = (fragment) => {
17080
17096
  const scripts = selectNodes(SCRIPT, fragment);
17081
17097
  const result = [];
17082
17098
  const { length } = scripts;
@@ -17084,17 +17100,12 @@
17084
17100
  for (let i = 0; i < length; i += 1) {
17085
17101
  const element = scripts[i];
17086
17102
 
17103
+ // isRemoteScript already requires a non-empty src attribute.
17087
17104
  if (!isRemoteScript(element)) {
17088
17105
  continue;
17089
17106
  }
17090
17107
 
17091
- const url = getAttribute(element, SRC);
17092
-
17093
- if (!url) {
17094
- continue;
17095
- }
17096
-
17097
- result.push(url);
17108
+ result.push(element);
17098
17109
  }
17099
17110
 
17100
17111
  return result;
@@ -17107,8 +17118,8 @@
17107
17118
  });
17108
17119
  };
17109
17120
 
17110
- const executeRemoteScripts = (urls) => {
17111
- return Promise.all(urls.map(loadScript));
17121
+ const executeRemoteScripts = (scripts) => {
17122
+ return Promise.all(scripts.map(loadScript));
17112
17123
  };
17113
17124
 
17114
17125
  /*
@@ -17129,7 +17140,7 @@
17129
17140
  addNonceToInlineStyleElements(fragment);
17130
17141
  const elements = getChildNodes(fragment);
17131
17142
  const scripts = getInlineScripts(fragment);
17132
- const scriptsUrls = getRemoteScriptsUrls(fragment);
17143
+ const remoteScripts = getRemoteScripts(fragment);
17133
17144
 
17134
17145
  loadImages(fragment);
17135
17146
 
@@ -17141,7 +17152,7 @@
17141
17152
 
17142
17153
  executeInlineScripts(container, scripts);
17143
17154
 
17144
- return executeRemoteScripts(scriptsUrls);
17155
+ return executeRemoteScripts(remoteScripts);
17145
17156
  };
17146
17157
 
17147
17158
  /*
@@ -17187,7 +17198,7 @@
17187
17198
  addNonceToInlineStyleElements(fragment);
17188
17199
  const elements = getChildNodes(fragment);
17189
17200
  const scripts = getInlineScripts(fragment);
17190
- const scriptsUrls = getRemoteScriptsUrls(fragment);
17201
+ const remoteScripts = getRemoteScripts(fragment);
17191
17202
  const { length } = elements;
17192
17203
  let i = length - 1;
17193
17204
 
@@ -17212,7 +17223,7 @@
17212
17223
 
17213
17224
  executeInlineScripts(container, scripts);
17214
17225
 
17215
- return executeRemoteScripts(scriptsUrls);
17226
+ return executeRemoteScripts(remoteScripts);
17216
17227
  };
17217
17228
 
17218
17229
  /*
@@ -17350,7 +17361,7 @@
17350
17361
  addNonceToInlineStyleElements(fragment);
17351
17362
  const elements = getChildNodes(fragment);
17352
17363
  const scripts = getInlineScripts(fragment);
17353
- const scriptsUrls = getRemoteScriptsUrls(fragment);
17364
+ const remoteScripts = getRemoteScripts(fragment);
17354
17365
 
17355
17366
  loadImages(fragment);
17356
17367
 
@@ -17361,7 +17372,7 @@
17361
17372
 
17362
17373
  executeInlineScripts(container, scripts);
17363
17374
 
17364
- return executeRemoteScripts(scriptsUrls);
17375
+ return executeRemoteScripts(remoteScripts);
17365
17376
  };
17366
17377
 
17367
17378
  /*
@@ -17401,7 +17412,7 @@
17401
17412
  addNonceToInlineStyleElements(fragment);
17402
17413
  const elements = getChildNodes(fragment);
17403
17414
  const scripts = getInlineScripts(fragment);
17404
- const scriptsUrls = getRemoteScriptsUrls(fragment);
17415
+ const remoteScripts = getRemoteScripts(fragment);
17405
17416
 
17406
17417
  loadImages(fragment);
17407
17418
 
@@ -17415,7 +17426,7 @@
17415
17426
 
17416
17427
  executeInlineScripts(container, scripts);
17417
17428
 
17418
- return executeRemoteScripts(scriptsUrls);
17429
+ return executeRemoteScripts(remoteScripts);
17419
17430
  };
17420
17431
 
17421
17432
  /*
@@ -20766,7 +20777,7 @@
20766
20777
  * @param {Object} data
20767
20778
  * @param {Logger} logger
20768
20779
  *
20769
- * @returns {Promise<void>}
20780
+ * @returns {Promise<boolean>} Whether the data was successfully saved.
20770
20781
  */
20771
20782
  async function saveToIndexedDB(data, logger) {
20772
20783
  try {
@@ -20800,8 +20811,12 @@
20800
20811
  "Successfully saved web SDK config to IndexedDB",
20801
20812
  updatedConfigData,
20802
20813
  );
20814
+
20815
+ return true;
20803
20816
  } catch (error) {
20804
20817
  logger.error("Failed to save config to IndexedDB", { error });
20818
+
20819
+ return false;
20805
20820
  }
20806
20821
  }
20807
20822
 
@@ -20855,6 +20870,14 @@
20855
20870
  await identity.awaitIdentity();
20856
20871
  const ecid = identity.getEcidFromCookie();
20857
20872
 
20873
+ if (!ecid) {
20874
+ logger.info(
20875
+ "No ECID is available. Not sending push subscription details to the server.",
20876
+ );
20877
+
20878
+ return;
20879
+ }
20880
+
20858
20881
  const pushSubscriptionDetails = await getPushSubscriptionDetails$1({
20859
20882
  vapidPublicKey,
20860
20883
  window,
@@ -20867,7 +20890,7 @@
20867
20890
  const cacheValue = `${ecid}${serializedPushSubscriptionDetails}`;
20868
20891
  const storedValue = await storage.getItem(SUBSCRIPTION_DETAILS);
20869
20892
 
20870
- if (cacheValue === storedValue) {
20893
+ if (storedValue && cacheValue === storedValue) {
20871
20894
  logger.info(
20872
20895
  "Subscription details have not changed. Not sending to the server.",
20873
20896
  );
@@ -20875,8 +20898,6 @@
20875
20898
  return;
20876
20899
  }
20877
20900
 
20878
- storage.setItem(SUBSCRIPTION_DETAILS, cacheValue);
20879
-
20880
20901
  const payload = await createSendPushSubscriptionPayload({
20881
20902
  eventManager,
20882
20903
  ecid,
@@ -20891,7 +20912,15 @@
20891
20912
  await consent.awaitConsent();
20892
20913
  await sendEdgeNetworkRequest({ request });
20893
20914
 
20894
- await saveToIndexedDB({ ecid }, logger);
20915
+ const savedToIndexedDb = await saveToIndexedDB({ ecid }, logger);
20916
+
20917
+ // Only cache the subscription details once the ECID has been persisted, so
20918
+ // that a failed send or a failed IndexedDB write does not short-circuit the
20919
+ // dedupe check on the next call. This lets a subsequent sendPushSubscription
20920
+ // self-heal instead of getting stuck with a cached subscription but no ECID.
20921
+ if (savedToIndexedDb) {
20922
+ storage.setItem(SUBSCRIPTION_DETAILS, cacheValue);
20923
+ }
20895
20924
  };
20896
20925
 
20897
20926
  /*