@adobe/alloy 2.34.0-beta.0 → 2.34.0-beta.2

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 (30) hide show
  1. package/dist/alloy.js +483 -169
  2. package/dist/alloy.min.js +2 -2
  3. package/dist/types/browser/src/services/createBrowserCookieService.d.ts +15 -0
  4. package/dist/types/browser/src/services/createBrowserGlobalsService.d.ts +5 -0
  5. package/dist/types/browser/src/services/createBrowserLegacyService.d.ts +4 -0
  6. package/dist/types/browser/src/services/createBrowserNetworkService.d.ts +9 -0
  7. package/dist/types/browser/src/services/createBrowserPlatformServices.d.ts +9 -0
  8. package/dist/types/browser/src/services/createBrowserRuntimeService.d.ts +5 -0
  9. package/dist/types/browser/src/services/createBrowserStorageService.d.ts +4 -0
  10. package/dist/types/browser/src/services/index.d.ts +7 -0
  11. package/dist/types/core/src/components/BrandConcierge/createBuildEndpointUrl.d.ts +1 -2
  12. package/dist/types/core/src/components/BrandConcierge/createConversationServiceRequest.d.ts +2 -1
  13. package/dist/types/core/src/core/createLogController.d.ts +1 -2
  14. package/dist/types/core/src/core/index.d.ts +7 -12
  15. package/dist/types/core/src/index.d.ts +7 -2
  16. package/dist/types/core/src/services/index.d.ts +27 -0
  17. package/dist/types/core/src/services/types.d.ts +91 -0
  18. package/dist/types/core/src/utils/getApexDomain.d.ts +1 -1
  19. package/dist/types/core/src/utils/request/createGetAssuranceValidationTokenParams.d.ts +2 -2
  20. package/package.json +2 -2
  21. package/src/index.js +8 -4
  22. package/src/services/createBrowserCookieService.js +34 -0
  23. package/src/services/createBrowserGlobalsService.js +30 -0
  24. package/src/services/createBrowserLegacyService.js +91 -0
  25. package/src/services/createBrowserNetworkService.js +41 -0
  26. package/src/services/createBrowserPlatformServices.js +35 -0
  27. package/src/services/createBrowserRuntimeService.js +26 -0
  28. package/src/services/createBrowserStorageService.js +74 -0
  29. package/src/services/index.js +19 -0
  30. package/dist/types/core/src/core/createInstanceFunction.d.ts +0 -2
package/dist/alloy.js CHANGED
@@ -135,20 +135,18 @@
135
135
  return base64;
136
136
  };
137
137
 
138
- /*! js-cookie v3.0.5 | MIT */
139
- /* eslint-disable no-var */
138
+ /*! js-cookie v3.0.7 | MIT */
140
139
  function assign (target) {
141
140
  for (var i = 1; i < arguments.length; i++) {
142
141
  var source = arguments[i];
143
142
  for (var key in source) {
143
+ if (key === '__proto__') continue
144
144
  target[key] = source[key];
145
145
  }
146
146
  }
147
147
  return target
148
148
  }
149
- /* eslint-enable no-var */
150
149
 
151
- /* eslint-disable no-var */
152
150
  var defaultConverter = {
153
151
  read: function (value) {
154
152
  if (value[0] === '"') {
@@ -163,12 +161,9 @@
163
161
  )
164
162
  }
165
163
  };
166
- /* eslint-enable no-var */
167
164
 
168
- /* eslint-disable no-var */
169
-
170
- function init (converter, defaultAttributes) {
171
- function set (name, value, attributes) {
165
+ function init(converter, defaultAttributes) {
166
+ function set(name, value, attributes) {
172
167
  if (typeof document === 'undefined') {
173
168
  return
174
169
  }
@@ -212,7 +207,7 @@
212
207
  name + '=' + converter.write(value, name) + stringifiedAttributes)
213
208
  }
214
209
 
215
- function get (name) {
210
+ function get(name) {
216
211
  if (typeof document === 'undefined' || (arguments.length && !name)) {
217
212
  return
218
213
  }
@@ -227,12 +222,13 @@
227
222
 
228
223
  try {
229
224
  var found = decodeURIComponent(parts[0]);
230
- jar[found] = converter.read(value, found);
231
-
225
+ if (!(found in jar)) jar[found] = converter.read(value, found);
232
226
  if (name === found) {
233
227
  break
234
228
  }
235
- } catch (e) {}
229
+ } catch {
230
+ // Do nothing...
231
+ }
236
232
  }
237
233
 
238
234
  return name ? jar[name] : jar
@@ -1361,15 +1357,16 @@
1361
1357
  * Of the current web page's hostname, this is the top-most domain that is
1362
1358
  * not a "public suffix" as outlined in https://publicsuffix.org/. In other
1363
1359
  * words, this is top-most domain that is able to accept cookies.
1364
- * @param {Object} window
1360
+ * @param {string} hostname - Current hostname (typically from the globals
1361
+ * capability; previously read directly from `window.location.hostname`).
1365
1362
  * @param {Object} cookieJar
1366
1363
  * @returns {string}
1367
1364
  */
1368
- var getApexDomain = (window, cookieJar) => {
1365
+ var getApexDomain = (hostname, cookieJar) => {
1369
1366
  let topLevelCookieDomain = "";
1370
1367
 
1371
1368
  // If hostParts.length === 1, we may be on localhost.
1372
- const hostParts = window.location.hostname.toLowerCase().split(".");
1369
+ const hostParts = hostname.toLowerCase().split(".");
1373
1370
  let i = 1;
1374
1371
 
1375
1372
  while (i < hostParts.length && !cookieJar.get(cookieName)) {
@@ -3435,30 +3432,13 @@
3435
3432
  governing permissions and limitations under the License.
3436
3433
  */
3437
3434
 
3438
- var debugQueryParam = "alloy_debug";
3439
-
3440
- /*
3441
- Copyright 2019 Adobe. All rights reserved.
3442
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
3443
- you may not use this file except in compliance with the License. You may obtain a copy
3444
- of the License at http://www.apache.org/licenses/LICENSE-2.0
3445
-
3446
- Unless required by applicable law or agreed to in writing, software distributed under
3447
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
3448
- OF ANY KIND, either express or implied. See the License for the specific language
3449
- governing permissions and limitations under the License.
3450
- */
3451
-
3452
-
3453
3435
  var createLogController = ({
3454
3436
  console,
3455
- locationSearch,
3456
3437
  createLogger,
3457
3438
  instanceName,
3458
3439
  createNamespacedStorage,
3459
3440
  getMonitors,
3460
3441
  }) => {
3461
- const parsedQueryString = queryString.parse(locationSearch);
3462
3442
  const storage = createNamespacedStorage(`instance.${instanceName}.`);
3463
3443
 
3464
3444
  const debugSessionValue = storage.session.getItem("debug");
@@ -3478,12 +3458,6 @@
3478
3458
  }
3479
3459
  };
3480
3460
 
3481
- if (parsedQueryString[debugQueryParam] !== undefined) {
3482
- setDebugEnabled(stringToBoolean(parsedQueryString[debugQueryParam]), {
3483
- fromConfig: false,
3484
- });
3485
- }
3486
-
3487
3461
  return {
3488
3462
  setDebugEnabled,
3489
3463
  logger: createLogger({
@@ -5094,77 +5068,6 @@
5094
5068
  governing permissions and limitations under the License.
5095
5069
  */
5096
5070
 
5097
- var injectSendFetchRequest = ({ fetch }) => {
5098
- return (url, body) => {
5099
- return fetch(url, {
5100
- method: "POST",
5101
- cache: "no-cache",
5102
- credentials: "include", // To set the cookie header in the request.
5103
- headers: {
5104
- "Content-Type": "text/plain; charset=UTF-8",
5105
- },
5106
- referrerPolicy: "no-referrer-when-downgrade",
5107
- body,
5108
- }).then((response) => {
5109
- return response.text().then((responseBody) => ({
5110
- statusCode: response.status,
5111
- // We expose headers through a function instead of creating an object
5112
- // with all the headers up front largely because the native
5113
- // request.getResponseHeader method is case-insensitive.
5114
- getHeader(name) {
5115
- return response.headers.get(name);
5116
- },
5117
- body: responseBody,
5118
- }));
5119
- });
5120
- };
5121
- };
5122
-
5123
- /*
5124
- Copyright 2019 Adobe. All rights reserved.
5125
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
5126
- you may not use this file except in compliance with the License. You may obtain a copy
5127
- of the License at http://www.apache.org/licenses/LICENSE-2.0
5128
-
5129
- Unless required by applicable law or agreed to in writing, software distributed under
5130
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
5131
- OF ANY KIND, either express or implied. See the License for the specific language
5132
- governing permissions and limitations under the License.
5133
- */
5134
-
5135
- var injectSendBeaconRequest = ({ sendBeacon, sendFetchRequest, logger }) => {
5136
- return (url, body) => {
5137
- const blob = new Blob([body], { type: "text/plain; charset=UTF-8" });
5138
- if (!sendBeacon(url, blob)) {
5139
- logger.info("Unable to use `sendBeacon`; falling back to `fetch`.");
5140
- return sendFetchRequest(url, body);
5141
- }
5142
-
5143
- // Using sendBeacon, we technically don't get a response back from
5144
- // the server, but we'll resolve the promise with an object to maintain
5145
- // consistency with other network strategies.
5146
- return Promise.resolve({
5147
- statusCode: 204,
5148
- getHeader() {
5149
- return null;
5150
- },
5151
- body: "",
5152
- });
5153
- };
5154
- };
5155
-
5156
- /*
5157
- Copyright 2019 Adobe. All rights reserved.
5158
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
5159
- you may not use this file except in compliance with the License. You may obtain a copy
5160
- of the License at http://www.apache.org/licenses/LICENSE-2.0
5161
-
5162
- Unless required by applicable law or agreed to in writing, software distributed under
5163
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
5164
- OF ANY KIND, either express or implied. See the License for the specific language
5165
- governing permissions and limitations under the License.
5166
- */
5167
-
5168
5071
  var createLogger = ({ getDebugEnabled, console, getMonitors, context }) => {
5169
5072
  let prefix = `[${context.instanceName}]`;
5170
5073
  if (context.componentName) {
@@ -5716,10 +5619,10 @@
5716
5619
  return clientId;
5717
5620
  };
5718
5621
 
5719
- var createGetAssuranceValidationTokenParams = ({ window, createNamespacedStorage }) => {
5622
+ var createGetAssuranceValidationTokenParams = ({ getLocationSearch, createNamespacedStorage }) => {
5720
5623
  const storage = createNamespacedStorage(ASSURANCE_VALIDATION_NAMESPACE);
5721
5624
  return () => {
5722
- const parsedQuery = queryString.parse(window.location.search);
5625
+ const parsedQuery = queryString.parse(getLocationSearch());
5723
5626
  const validationSessionId =
5724
5627
  parsedQuery[ASSURANCE_VALIDATION_SESSION_URL_PARAM];
5725
5628
  if (!validationSessionId) {
@@ -6009,6 +5912,20 @@
6009
5912
  );
6010
5913
  };
6011
5914
 
5915
+ /*
5916
+ Copyright 2019 Adobe. All rights reserved.
5917
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
5918
+ you may not use this file except in compliance with the License. You may obtain a copy
5919
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
5920
+
5921
+ Unless required by applicable law or agreed to in writing, software distributed under
5922
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
5923
+ OF ANY KIND, either express or implied. See the License for the specific language
5924
+ governing permissions and limitations under the License.
5925
+ */
5926
+
5927
+ var debugQueryParam = "alloy_debug";
5928
+
6012
5929
  /*
6013
5930
  Copyright 2023 Adobe. All rights reserved.
6014
5931
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -7101,7 +7018,7 @@
7101
7018
  */
7102
7019
 
7103
7020
 
7104
- var awaitVisitorOptIn = ({ logger }) => {
7021
+ var awaitVisitorOptIn$1 = ({ logger }) => {
7105
7022
  return new Promise((resolve, reject) => {
7106
7023
  if (isObject(window.adobe) && isObject(window.adobe.optIn)) {
7107
7024
  const optInOld = window.adobe.optIn;
@@ -7137,7 +7054,7 @@
7137
7054
  */
7138
7055
 
7139
7056
 
7140
- var getVisitor = (window) => {
7057
+ var getVisitor$1 = (window) => {
7141
7058
  const Visitor = window.Visitor;
7142
7059
  return isFunction(Visitor) && isFunction(Visitor.getInstance) && Visitor;
7143
7060
  };
@@ -7157,7 +7074,7 @@
7157
7074
 
7158
7075
  var injectGetEcidFromVisitor = ({ logger, orgId, awaitVisitorOptIn }) => {
7159
7076
  return () => {
7160
- const Visitor = getVisitor(window);
7077
+ const Visitor = getVisitor$1(window);
7161
7078
  if (Visitor) {
7162
7079
  // Need to explicitly wait for optIn because visitor will call callback
7163
7080
  // with invalid values prior to optIn being approved
@@ -7825,7 +7742,7 @@
7825
7742
  const getEcidFromVisitor = injectGetEcidFromVisitor({
7826
7743
  logger,
7827
7744
  orgId,
7828
- awaitVisitorOptIn,
7745
+ awaitVisitorOptIn: awaitVisitorOptIn$1,
7829
7746
  });
7830
7747
  const loggingCookieJar = createLoggingCookieJar({ logger, cookieJar });
7831
7748
  const legacyIdentity = createLegacyIdentity({
@@ -7922,10 +7839,10 @@
7922
7839
  governing permissions and limitations under the License.
7923
7840
  */
7924
7841
 
7925
- // The 2.34.0-beta.0 keyword will be replace at alloy build time with the package.json version.
7842
+ // The 2.34.0-beta.2 keyword will be replace at alloy build time with the package.json version.
7926
7843
  // see babel-plugin-version
7927
7844
 
7928
- var libraryVersion = "2.34.0-beta.0";
7845
+ var libraryVersion = "2.34.0-beta.2";
7929
7846
 
7930
7847
  /*
7931
7848
  Copyright 2019 Adobe. All rights reserved.
@@ -8011,24 +7928,61 @@
8011
7928
  */
8012
7929
 
8013
7930
 
8014
- const createNamespacedStorage$1 = injectStorage(window);
8015
-
8016
- const { fetch, navigator: navigator$1 } = window;
8017
-
8018
7931
  const coreConfigValidators = createCoreConfigs();
8019
- const apexDomain = getApexDomain(window, cookieJar);
8020
- const sendFetchRequest = injectSendFetchRequest({ fetch });
8021
- const fireReferrerHideableImage = injectFireReferrerHideableImage();
8022
- const getAssuranceValidationTokenParams =
8023
- createGetAssuranceValidationTokenParams({ window, createNamespacedStorage: createNamespacedStorage$1 });
8024
-
8025
- const getBrowser = injectGetBrowser({ userAgent: window.navigator.userAgent });
8026
7932
 
7933
+ /**
7934
+ * @param {Object} params
7935
+ * @param {string} params.instanceName
7936
+ * @param {Array<import('./types.js').AlloyMonitor>} [params.monitors]
7937
+ * @param {Array<Function>} params.components
7938
+ * @param {(deps: { logger: import('./types.js').Logger }) => import('../services/index.js').PlatformServices} params.createPlatformServices
7939
+ */
8027
7940
  const createExecuteCommand = ({
8028
7941
  instanceName,
8029
- logController: { setDebugEnabled, logger, createComponentLogger },
7942
+ monitors = [],
8030
7943
  components,
7944
+ createPlatformServices,
8031
7945
  }) => {
7946
+ // `createLogController` and `createGetAssuranceValidationTokenParams` still
7947
+ // consume sync storage, so we can't use the async storage capability here
7948
+ // yet. Remove once those consumers are migrated.
7949
+ const createNamespacedStorage = injectStorage(window);
7950
+
7951
+ const logController = createLogController({
7952
+ console: globalThis.console,
7953
+ createLogger,
7954
+ instanceName,
7955
+ createNamespacedStorage,
7956
+ getMonitors: getMonitors.bind(null, monitors),
7957
+ });
7958
+
7959
+ const { setDebugEnabled, logger, createComponentLogger } = logController;
7960
+
7961
+ const platformServices = createPlatformServices({ logger });
7962
+
7963
+ const parsedQueryString = queryString.parse(
7964
+ platformServices.globals.getLocationSearch(),
7965
+ );
7966
+ if (parsedQueryString[debugQueryParam] !== undefined) {
7967
+ setDebugEnabled(stringToBoolean(parsedQueryString[debugQueryParam]), {
7968
+ fromConfig: false,
7969
+ });
7970
+ }
7971
+
7972
+ const apexDomain = getApexDomain(
7973
+ platformServices.globals.getHostname(),
7974
+ cookieJar,
7975
+ );
7976
+ const fireReferrerHideableImage = injectFireReferrerHideableImage();
7977
+ const getAssuranceValidationTokenParams =
7978
+ createGetAssuranceValidationTokenParams({
7979
+ getLocationSearch: () => platformServices.globals.getLocationSearch(),
7980
+ createNamespacedStorage,
7981
+ });
7982
+ const getBrowser = injectGetBrowser({
7983
+ userAgent: platformServices.globals.getUserAgent(),
7984
+ });
7985
+
8032
7986
  const componentRegistry = createComponentRegistry();
8033
7987
  const lifecycle = createLifecycle(componentRegistry);
8034
7988
 
@@ -8061,19 +8015,10 @@
8061
8015
  apexDomain,
8062
8016
  dateProvider: () => new Date(),
8063
8017
  });
8064
- const sendBeaconRequest = isFunction(navigator$1.sendBeacon)
8065
- ? injectSendBeaconRequest({
8066
- // Without the bind(), the browser will complain about an
8067
- // illegal invocation.
8068
- sendBeacon: navigator$1.sendBeacon.bind(navigator$1),
8069
- sendFetchRequest,
8070
- logger,
8071
- })
8072
- : sendFetchRequest;
8073
8018
  const sendNetworkRequest = injectSendNetworkRequest({
8074
8019
  logger,
8075
- sendFetchRequest,
8076
- sendBeaconRequest,
8020
+ sendFetchRequest: platformServices.network.sendFetchRequest,
8021
+ sendBeaconRequest: platformServices.network.sendBeaconRequest,
8077
8022
  isRequestRetryable,
8078
8023
  getRequestRetryDelay,
8079
8024
  });
@@ -8143,11 +8088,12 @@
8143
8088
  errorPrefix: `[${instanceName}] [${componentName}]`,
8144
8089
  logger: componentLogger,
8145
8090
  }),
8146
- createNamespacedStorage: createNamespacedStorage$1,
8091
+ createNamespacedStorage,
8147
8092
  apexDomain,
8148
8093
  getBrowser,
8149
8094
  cookieTransfer,
8150
8095
  createResponse,
8096
+ platformServices,
8151
8097
  };
8152
8098
  },
8153
8099
  });
@@ -8165,6 +8111,7 @@
8165
8111
  handleError,
8166
8112
  validateCommandOptions,
8167
8113
  });
8114
+ logger.logOnInstanceCreated({ instance: executeCommand });
8168
8115
  return executeCommand;
8169
8116
  };
8170
8117
 
@@ -12558,10 +12505,11 @@
12558
12505
  action = "conversations",
12559
12506
  sessionId,
12560
12507
  voiceEnabled = false,
12508
+ region,
12561
12509
  }) => {
12562
12510
  const edgeSubPath = voiceEnabled
12563
12511
  ? VOICE_BRAND_CONCIERGE_PATH
12564
- : BRAND_CONCIERGE_PATH;
12512
+ : `${BRAND_CONCIERGE_PATH}${region ? `/${region}` : ""}`;
12565
12513
 
12566
12514
  return createRequest({
12567
12515
  payload: payload,
@@ -13024,6 +12972,7 @@
13024
12972
  payload,
13025
12973
  sessionId: session.id,
13026
12974
  voiceEnabled,
12975
+ region: conversation.region,
13027
12976
  });
13028
12977
 
13029
12978
  const event = eventManager.createEvent();
@@ -13064,7 +13013,6 @@
13064
13013
  }
13065
13014
  const url = buildEndpointUrl({
13066
13015
  edgeDomain,
13067
- region: conversation.region,
13068
13016
  datastreamId,
13069
13017
  request,
13070
13018
  });
@@ -13143,15 +13091,14 @@
13143
13091
  */
13144
13092
 
13145
13093
  var createBuildEndpointUrl = ({ queryString }) => {
13146
- return ({ edgeDomain, region, request, datastreamId }) => {
13094
+ return ({ edgeDomain, request, datastreamId }) => {
13147
13095
  const params = request.getRequestParams();
13148
13096
  const configId = request.getDatastreamIdOverride() || datastreamId;
13149
13097
  params.requestId = request.getId();
13150
13098
  params.configId = configId;
13151
13099
  const stringifiedRequestParams = queryString.stringify({ ...params });
13152
- const regionSegment = region ? `/${region}` : "";
13153
13100
 
13154
- return `https://${edgeDomain}${request.getEdgeSubPath()}${regionSegment}/${request.getAction()}?${stringifiedRequestParams}`;
13101
+ return `https://${edgeDomain}${request.getEdgeSubPath()}/${request.getAction()}?${stringifiedRequestParams}`;
13155
13102
  };
13156
13103
  };
13157
13104
 
@@ -13354,9 +13301,6 @@
13354
13301
  */
13355
13302
 
13356
13303
 
13357
- const { console } = window;
13358
- const createNamespacedStorage = injectStorage(window);
13359
-
13360
13304
  /**
13361
13305
  * Creates a custom Alloy instance which can reduce the library size and increase performance.
13362
13306
  *
@@ -13364,11 +13308,15 @@
13364
13308
  * @param {string} [options.name=alloy] - The name of the instance.
13365
13309
  * @param {Array<AlloyMonitor>} [options.monitors] - Monitors for the instance.
13366
13310
  * @param {Array<Function>} [options.components] - Components for the instance.
13311
+ * @param {CreatePlatformServices} createPlatformServices
13367
13312
  * @returns {(commandName: string, options?: Object) => Promise<any>} A callable Alloy instance.
13368
13313
  *
13369
13314
  * @see {@link https://experienceleague.adobe.com/en/docs/experience-platform/web-sdk/install/create-custom-build} for more details.
13370
13315
  */
13371
- const createCustomInstance$1 = (options = {}) => {
13316
+ const createCustomInstance$1 = (
13317
+ options = {},
13318
+ createPlatformServices = undefined,
13319
+ ) => {
13372
13320
  const eventOptionsValidator = boundObjectOf({
13373
13321
  name: boundString().default("alloy"),
13374
13322
  monitors: boundArrayOf(boundObjectOf({})).default([]),
@@ -13377,23 +13325,12 @@
13377
13325
 
13378
13326
  const { name, monitors, components } = eventOptionsValidator(options);
13379
13327
 
13380
- const logController = createLogController({
13381
- console,
13382
- locationSearch: window.location.search,
13383
- createLogger,
13384
- instanceName: name,
13385
- createNamespacedStorage,
13386
- getMonitors: getMonitors.bind(null, monitors),
13387
- });
13388
-
13389
- const instance = createExecuteCommand({
13328
+ return createExecuteCommand({
13390
13329
  instanceName: name,
13391
- logController,
13330
+ monitors,
13392
13331
  components,
13332
+ createPlatformServices,
13393
13333
  });
13394
- logController.logger.logOnInstanceCreated({ instance });
13395
-
13396
- return instance;
13397
13334
  };
13398
13335
 
13399
13336
  /*
@@ -21797,6 +21734,380 @@
21797
21734
  context: createContext
21798
21735
  });
21799
21736
 
21737
+ /*
21738
+ Copyright 2019 Adobe. All rights reserved.
21739
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21740
+ you may not use this file except in compliance with the License. You may obtain a copy
21741
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21742
+
21743
+ Unless required by applicable law or agreed to in writing, software distributed under
21744
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21745
+ OF ANY KIND, either express or implied. See the License for the specific language
21746
+ governing permissions and limitations under the License.
21747
+ */
21748
+
21749
+ var injectSendFetchRequest = ({ fetch }) => {
21750
+ return (url, body) => {
21751
+ return fetch(url, {
21752
+ method: "POST",
21753
+ cache: "no-cache",
21754
+ credentials: "include", // To set the cookie header in the request.
21755
+ headers: {
21756
+ "Content-Type": "text/plain; charset=UTF-8",
21757
+ },
21758
+ referrerPolicy: "no-referrer-when-downgrade",
21759
+ body,
21760
+ }).then((response) => {
21761
+ return response.text().then((responseBody) => ({
21762
+ statusCode: response.status,
21763
+ // We expose headers through a function instead of creating an object
21764
+ // with all the headers up front largely because the native
21765
+ // request.getResponseHeader method is case-insensitive.
21766
+ getHeader(name) {
21767
+ return response.headers.get(name);
21768
+ },
21769
+ body: responseBody,
21770
+ }));
21771
+ });
21772
+ };
21773
+ };
21774
+
21775
+ /*
21776
+ Copyright 2019 Adobe. All rights reserved.
21777
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21778
+ you may not use this file except in compliance with the License. You may obtain a copy
21779
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21780
+
21781
+ Unless required by applicable law or agreed to in writing, software distributed under
21782
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21783
+ OF ANY KIND, either express or implied. See the License for the specific language
21784
+ governing permissions and limitations under the License.
21785
+ */
21786
+
21787
+ var injectSendBeaconRequest = ({ sendBeacon, sendFetchRequest, logger }) => {
21788
+ return (url, body) => {
21789
+ const blob = new Blob([body], { type: "text/plain; charset=UTF-8" });
21790
+ if (!sendBeacon(url, blob)) {
21791
+ logger.info("Unable to use `sendBeacon`; falling back to `fetch`.");
21792
+ return sendFetchRequest(url, body);
21793
+ }
21794
+
21795
+ // Using sendBeacon, we technically don't get a response back from
21796
+ // the server, but we'll resolve the promise with an object to maintain
21797
+ // consistency with other network strategies.
21798
+ return Promise.resolve({
21799
+ statusCode: 204,
21800
+ getHeader() {
21801
+ return null;
21802
+ },
21803
+ body: "",
21804
+ });
21805
+ };
21806
+ };
21807
+
21808
+ /*
21809
+ Copyright 2026 Adobe. All rights reserved.
21810
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21811
+ you may not use this file except in compliance with the License. You may obtain a copy
21812
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21813
+
21814
+ Unless required by applicable law or agreed to in writing, software distributed under
21815
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21816
+ OF ANY KIND, either express or implied. See the License for the specific language
21817
+ governing permissions and limitations under the License.
21818
+ */
21819
+
21820
+
21821
+ /**
21822
+ * @param {{ logger: import('@adobe/alloy-core/core/types.js').Logger }} dependencies
21823
+ * @returns {NetworkService}
21824
+ */
21825
+ const createBrowserNetworkService = ({ logger }) => {
21826
+ const { fetch, navigator } = window;
21827
+ const sendFetchRequest = injectSendFetchRequest({ fetch });
21828
+ const sendBeaconRequest =
21829
+ typeof navigator.sendBeacon === "function"
21830
+ ? injectSendBeaconRequest({
21831
+ // bind() avoids "illegal invocation" when sendBeacon loses its receiver.
21832
+ sendBeacon: navigator.sendBeacon.bind(navigator),
21833
+ sendFetchRequest,
21834
+ logger,
21835
+ })
21836
+ : sendFetchRequest;
21837
+
21838
+ return {
21839
+ sendFetchRequest,
21840
+ sendBeaconRequest,
21841
+ };
21842
+ };
21843
+
21844
+ /*
21845
+ Copyright 2026 Adobe. All rights reserved.
21846
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21847
+ you may not use this file except in compliance with the License. You may obtain a copy
21848
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21849
+
21850
+ Unless required by applicable law or agreed to in writing, software distributed under
21851
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21852
+ OF ANY KIND, either express or implied. See the License for the specific language
21853
+ governing permissions and limitations under the License.
21854
+ */
21855
+
21856
+
21857
+ // On Safari with storage disabled, even referencing `window.localStorage`
21858
+ // throws — hence the try/catch around every access.
21859
+ /**
21860
+ * @param {string} storageType - "localStorage" or "sessionStorage".
21861
+ * @param {string} namespace
21862
+ * @returns {Storage}
21863
+ */
21864
+ const wrapStorageArea = (storageType, namespace) => ({
21865
+ getItem(name) {
21866
+ try {
21867
+ return Promise.resolve(window[storageType].getItem(namespace + name));
21868
+ } catch {
21869
+ return Promise.resolve(null);
21870
+ }
21871
+ },
21872
+ setItem(name, value) {
21873
+ try {
21874
+ window[storageType].setItem(namespace + name, value);
21875
+ return Promise.resolve(true);
21876
+ } catch {
21877
+ return Promise.resolve(false);
21878
+ }
21879
+ },
21880
+ removeItem(name) {
21881
+ try {
21882
+ window[storageType].removeItem(namespace + name);
21883
+ return Promise.resolve(true);
21884
+ } catch {
21885
+ return Promise.resolve(false);
21886
+ }
21887
+ },
21888
+ clear() {
21889
+ try {
21890
+ Object.keys(window[storageType]).forEach((key) => {
21891
+ if (key.startsWith(namespace)) {
21892
+ window[storageType].removeItem(key);
21893
+ }
21894
+ });
21895
+ return Promise.resolve(true);
21896
+ } catch {
21897
+ return Promise.resolve(false);
21898
+ }
21899
+ },
21900
+ });
21901
+
21902
+ /** @returns {StorageService} */
21903
+ const createBrowserStorageService = () => ({
21904
+ createNamespacedStorage(additionalNamespace) {
21905
+ const finalNamespace = baseNamespace + additionalNamespace;
21906
+ /** @type {NamespacedStorage} */
21907
+ return {
21908
+ session: wrapStorageArea("sessionStorage", finalNamespace),
21909
+ persistent: wrapStorageArea("localStorage", finalNamespace),
21910
+ };
21911
+ },
21912
+ });
21913
+
21914
+ /*
21915
+ Copyright 2026 Adobe. All rights reserved.
21916
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21917
+ you may not use this file except in compliance with the License. You may obtain a copy
21918
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21919
+
21920
+ Unless required by applicable law or agreed to in writing, software distributed under
21921
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21922
+ OF ANY KIND, either express or implied. See the License for the specific language
21923
+ governing permissions and limitations under the License.
21924
+ */
21925
+
21926
+
21927
+ /**
21928
+ * The optional `jar` parameter is the recursion seam for `withConverter` —
21929
+ * every converted js-cookie instance must itself satisfy `CookieService`.
21930
+ *
21931
+ * @param {{ get: Function, set: Function, remove: Function, withConverter: Function }} [jar]
21932
+ * @returns {CookieService}
21933
+ */
21934
+ const createBrowserCookieService = (jar = cookieJar) => ({
21935
+ get: (name) => jar.get(name),
21936
+ set: (name, value, options) => jar.set(name, value, options),
21937
+ remove: (name, options) => {
21938
+ jar.remove(name, options);
21939
+ },
21940
+ withConverter: (converter) =>
21941
+ createBrowserCookieService(jar.withConverter(converter)),
21942
+ });
21943
+
21944
+ /*
21945
+ Copyright 2026 Adobe. All rights reserved.
21946
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21947
+ you may not use this file except in compliance with the License. You may obtain a copy
21948
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21949
+
21950
+ Unless required by applicable law or agreed to in writing, software distributed under
21951
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21952
+ OF ANY KIND, either express or implied. See the License for the specific language
21953
+ governing permissions and limitations under the License.
21954
+ */
21955
+
21956
+ /** @import { RuntimeService } from "@adobe/alloy-core/services" */
21957
+
21958
+ /** @returns {RuntimeService} */
21959
+ const createBrowserRuntimeService = () => ({
21960
+ setTimeout: window.setTimeout.bind(window),
21961
+ clearTimeout: window.clearTimeout.bind(window),
21962
+ atob: window.atob.bind(window),
21963
+ btoa: window.btoa.bind(window),
21964
+ TextEncoder: window.TextEncoder,
21965
+ TextDecoder: window.TextDecoder,
21966
+ now: () => Date.now(),
21967
+ });
21968
+
21969
+ /*
21970
+ Copyright 2026 Adobe. All rights reserved.
21971
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
21972
+ you may not use this file except in compliance with the License. You may obtain a copy
21973
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
21974
+
21975
+ Unless required by applicable law or agreed to in writing, software distributed under
21976
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21977
+ OF ANY KIND, either express or implied. See the License for the specific language
21978
+ governing permissions and limitations under the License.
21979
+ */
21980
+
21981
+
21982
+ const getVisitor = () => {
21983
+ const { Visitor } = window;
21984
+ return isFunction(Visitor) && isFunction(Visitor.getInstance) && Visitor;
21985
+ };
21986
+
21987
+ /**
21988
+ * @param {{ logger: import('@adobe/alloy-core/core/types.js').Logger }} params
21989
+ * @returns {Promise<void>}
21990
+ */
21991
+ const awaitVisitorOptIn = ({ logger }) =>
21992
+ new Promise((resolve, reject) => {
21993
+ if (isObject(window.adobe) && isObject(window.adobe.optIn)) {
21994
+ const optInOld = window.adobe.optIn;
21995
+ logger.info(
21996
+ "Delaying request while waiting for legacy opt-in to let Visitor retrieve ECID from server.",
21997
+ );
21998
+ optInOld.fetchPermissions(() => {
21999
+ if (optInOld.isApproved([optInOld.Categories.ECID])) {
22000
+ logger.info(
22001
+ "Received legacy opt-in approval to let Visitor retrieve ECID from server.",
22002
+ );
22003
+ resolve();
22004
+ } else {
22005
+ reject(new Error("Legacy opt-in was declined."));
22006
+ }
22007
+ }, true);
22008
+ } else {
22009
+ resolve();
22010
+ }
22011
+ });
22012
+
22013
+ /**
22014
+ * @param {{ orgId: string, logger: import('@adobe/alloy-core/core/types.js').Logger }} params
22015
+ * @returns {Promise<string | undefined>}
22016
+ */
22017
+ const getEcidFromVisitor = async ({ orgId, logger }) => {
22018
+ const Visitor = getVisitor();
22019
+ if (!Visitor) {
22020
+ return undefined;
22021
+ }
22022
+ try {
22023
+ await awaitVisitorOptIn({ logger });
22024
+ logger.info(
22025
+ "Delaying request while using Visitor to retrieve ECID from server.",
22026
+ );
22027
+ return await new Promise((resolve) => {
22028
+ const visitor = Visitor.getInstance(orgId, {});
22029
+ visitor.getMarketingCloudVisitorID((ecid) => {
22030
+ logger.info(
22031
+ "Resuming previously delayed request that was waiting for ECID from Visitor.",
22032
+ );
22033
+ resolve(ecid);
22034
+ }, true);
22035
+ });
22036
+ } catch (error) {
22037
+ // If consent was denied, fall back to retrieving the ECID from the
22038
+ // experience edge. OptIn and AEP Web SDK consent should operate
22039
+ // independently, but during ID migration AEP Web SDK needs to wait for
22040
+ // optIn so that only one ECID is generated.
22041
+ if (error) {
22042
+ logger.info(`${error.message}, retrieving ECID from experience edge`);
22043
+ } else {
22044
+ logger.info("An error occurred while obtaining the ECID from Visitor.");
22045
+ }
22046
+ return undefined;
22047
+ }
22048
+ };
22049
+
22050
+ /** @returns {LegacyService} */
22051
+ const createBrowserLegacyService = () => ({
22052
+ getEcidFromVisitor,
22053
+ awaitVisitorOptIn,
22054
+ });
22055
+
22056
+ /*
22057
+ Copyright 2026 Adobe. All rights reserved.
22058
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
22059
+ you may not use this file except in compliance with the License. You may obtain a copy
22060
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
22061
+
22062
+ Unless required by applicable law or agreed to in writing, software distributed under
22063
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22064
+ OF ANY KIND, either express or implied. See the License for the specific language
22065
+ governing permissions and limitations under the License.
22066
+ */
22067
+
22068
+ /* eslint-disable dot-notation */
22069
+
22070
+ /** @import { GlobalsService } from "@adobe/alloy-core/services" */
22071
+
22072
+ /** @returns {GlobalsService} */
22073
+ const createBrowserGlobalsService = () => ({
22074
+ getInstanceNames: () => window["__alloyNS"] || [],
22075
+ getInstanceQueue: (instanceName) => {
22076
+ const namespace = window[instanceName];
22077
+ return (namespace && namespace.q) || [];
22078
+ },
22079
+ getMonitors: () => window["__alloyMonitors"] || [],
22080
+ getLocationSearch: () => window.location.search,
22081
+ getUserAgent: () => window.navigator.userAgent,
22082
+ getHostname: () => window.location.hostname,
22083
+ });
22084
+
22085
+ /*
22086
+ Copyright 2026 Adobe. All rights reserved.
22087
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
22088
+ you may not use this file except in compliance with the License. You may obtain a copy
22089
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
22090
+
22091
+ Unless required by applicable law or agreed to in writing, software distributed under
22092
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
22093
+ OF ANY KIND, either express or implied. See the License for the specific language
22094
+ governing permissions and limitations under the License.
22095
+ */
22096
+
22097
+
22098
+ /**
22099
+ * @param {{ logger: import('@adobe/alloy-core/core/types.js').Logger }} dependencies
22100
+ * @returns {PlatformServices}
22101
+ */
22102
+ const createBrowserPlatformServices = ({ logger }) => ({
22103
+ network: createBrowserNetworkService({ logger }),
22104
+ storage: createBrowserStorageService(),
22105
+ cookie: createBrowserCookieService(),
22106
+ runtime: createBrowserRuntimeService(),
22107
+ legacy: createBrowserLegacyService(),
22108
+ globals: createBrowserGlobalsService(),
22109
+ });
22110
+
21800
22111
  /*
21801
22112
  Copyright 2025 Adobe. All rights reserved.
21802
22113
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -21810,10 +22121,13 @@
21810
22121
  */
21811
22122
 
21812
22123
  const createCustomInstance = ({ components = [], ...options } = {}) =>
21813
- createCustomInstance$1({
21814
- ...options,
21815
- components: [...Object.values(allRequiredComponents), ...components],
21816
- });
22124
+ createCustomInstance$1(
22125
+ {
22126
+ ...options,
22127
+ components: [...Object.values(allRequiredComponents), ...components],
22128
+ },
22129
+ createBrowserPlatformServices,
22130
+ );
21817
22131
 
21818
22132
  /*
21819
22133
  Copyright 2025 Adobe. All rights reserved.