@adobe/alloy 2.20.0 → 2.21.0-beta.1

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 (120) hide show
  1. package/libEs5/components/Audiences/injectProcessDestinations.js +1 -1
  2. package/libEs5/components/Context/index.js +1 -1
  3. package/libEs5/components/Context/injectHighEntropyUserAgentHints.js +4 -4
  4. package/libEs5/components/DataCollector/index.js +2 -2
  5. package/libEs5/components/DecisioningEngine/createConsequenceAdapter.js +1 -1
  6. package/libEs5/components/DecisioningEngine/createContextProvider.js +1 -1
  7. package/libEs5/components/DecisioningEngine/createEvaluableRulesetPayload.js +1 -1
  8. package/libEs5/components/DecisioningEngine/createEventRegistry.js +1 -1
  9. package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +1 -1
  10. package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +1 -1
  11. package/libEs5/components/DecisioningEngine/index.js +1 -1
  12. package/libEs5/components/Identity/appendIdentityToUrl/injectAppendIdentityToUrl.js +4 -4
  13. package/libEs5/components/Identity/createLegacyIdentity.js +1 -1
  14. package/libEs5/components/Identity/injectAddQueryStringIdentityToPayload.js +4 -4
  15. package/libEs5/components/LegacyMediaAnalytics/createGetInstance.js +1 -1
  16. package/libEs5/components/LegacyMediaAnalytics/createLegacyMediaComponent.js +1 -1
  17. package/libEs5/components/LibraryInfo/index.js +6 -6
  18. package/libEs5/components/Personalization/createApplyPropositions.js +33 -16
  19. package/libEs5/components/Personalization/createClickStorage.js +5 -5
  20. package/libEs5/components/Personalization/createFetchDataHandler.js +5 -5
  21. package/libEs5/components/Personalization/createInteractionStorage.js +102 -0
  22. package/libEs5/components/Personalization/createOnClickHandler.js +49 -21
  23. package/libEs5/components/Personalization/createPersonalizationDetails.js +5 -5
  24. package/libEs5/components/Personalization/createPreprocessors.js +1 -1
  25. package/libEs5/components/Personalization/dom-actions/action.js +4 -4
  26. package/libEs5/components/Personalization/dom-actions/appendHtml.js +2 -1
  27. package/libEs5/components/Personalization/dom-actions/clicks/collectClicks.js +15 -33
  28. package/libEs5/components/Personalization/dom-actions/clicks/collectInteractions.js +81 -0
  29. package/libEs5/components/Personalization/dom-actions/collectInteractions.js +17 -0
  30. package/libEs5/components/Personalization/dom-actions/dom/isDomElement.js +17 -0
  31. package/libEs5/components/Personalization/dom-actions/dom/selectNodesWithEq.js +4 -4
  32. package/libEs5/components/Personalization/dom-actions/initDomActionsModules.js +36 -19
  33. package/libEs5/components/Personalization/dom-actions/insertHtmlAfter.js +5 -2
  34. package/libEs5/components/Personalization/dom-actions/insertHtmlBefore.js +2 -1
  35. package/libEs5/components/Personalization/dom-actions/prependHtml.js +2 -1
  36. package/libEs5/components/Personalization/dom-actions/rearrangeChildren.js +3 -1
  37. package/libEs5/components/Personalization/dom-actions/remapCustomCodeOffers.js +2 -2
  38. package/libEs5/components/Personalization/dom-actions/remapHeadOffers.js +2 -2
  39. package/libEs5/components/Personalization/dom-actions/replaceHtml.js +4 -3
  40. package/libEs5/components/Personalization/dom-actions/scripts.js +1 -1
  41. package/libEs5/components/Personalization/dom-actions/setAttributes.js +2 -1
  42. package/libEs5/components/Personalization/dom-actions/setHtml.js +2 -2
  43. package/libEs5/components/Personalization/dom-actions/setStyles.js +4 -3
  44. package/libEs5/components/Personalization/dom-actions/setText.js +2 -1
  45. package/libEs5/components/Personalization/dom-actions/swapImage.js +2 -1
  46. package/libEs5/components/Personalization/event.js +1 -1
  47. package/libEs5/components/Personalization/flicker/index.js +1 -1
  48. package/libEs5/components/Personalization/handlers/createDecorateProposition.js +60 -0
  49. package/libEs5/components/Personalization/handlers/createProcessDomAction.js +11 -7
  50. package/libEs5/components/Personalization/handlers/createProcessHtmlContent.js +6 -2
  51. package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +1 -1
  52. package/libEs5/components/Personalization/handlers/createProcessPropositions.js +6 -6
  53. package/libEs5/components/Personalization/handlers/injectCreateProposition.js +13 -2
  54. package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +1 -1
  55. package/libEs5/components/Personalization/index.js +27 -8
  56. package/libEs5/components/Personalization/utils/metaUtils.js +33 -0
  57. package/libEs5/components/Personalization/validateApplyPropositionsOptions.js +12 -1
  58. package/libEs5/components/Privacy/createComponent.js +1 -1
  59. package/libEs5/components/Privacy/createConsentHashStore.js +2 -2
  60. package/libEs5/components/Privacy/parseConsentCookie.js +4 -4
  61. package/libEs5/components/StreamingMedia/validateMediaEventOptions.js +5 -5
  62. package/libEs5/constants/decisionProvider.js +3 -2
  63. package/libEs5/constants/libraryVersion.js +1 -1
  64. package/libEs5/constants/propositionEventType.js +1 -1
  65. package/libEs5/constants/propositionInteractionType.js +18 -0
  66. package/libEs5/core/buildAndValidateConfig.js +6 -6
  67. package/libEs5/core/createEvent.js +5 -5
  68. package/libEs5/core/createEventManager.js +3 -3
  69. package/libEs5/core/edgeNetwork/mergeLifecycleResponses.js +5 -5
  70. package/libEs5/core/network/injectSendNetworkRequest.js +1 -1
  71. package/libEs5/utils/assignConcatArrayValues.js +5 -5
  72. package/libEs5/utils/createLoggingCookieJar.js +1 -1
  73. package/libEs5/utils/createSubscription.js +5 -5
  74. package/libEs5/utils/dom/awaitSelector.js +5 -1
  75. package/libEs5/utils/filterObject.js +1 -1
  76. package/libEs5/utils/flattenArray.js +5 -5
  77. package/libEs5/utils/flattenObject.js +5 -5
  78. package/libEs5/utils/getBrowser.js +1 -1
  79. package/libEs5/utils/injectFireReferrerHideableImage.js +4 -4
  80. package/libEs5/utils/parseUrl.js +1 -1
  81. package/libEs5/utils/request/createRequestParams.js +2 -2
  82. package/libEs5/utils/validation/createDeprecatedValidator.js +3 -3
  83. package/libEs5/utils/validation/index.js +1 -1
  84. package/libEs6/components/Personalization/createApplyPropositions.js +25 -10
  85. package/libEs6/components/Personalization/createClickStorage.js +4 -4
  86. package/libEs6/components/Personalization/createInteractionStorage.js +85 -0
  87. package/libEs6/components/Personalization/createOnClickHandler.js +49 -22
  88. package/libEs6/components/Personalization/dom-actions/action.js +4 -4
  89. package/libEs6/components/Personalization/dom-actions/appendHtml.js +3 -2
  90. package/libEs6/components/Personalization/dom-actions/clicks/collectClicks.js +8 -18
  91. package/libEs6/components/Personalization/dom-actions/clicks/collectInteractions.js +74 -0
  92. package/libEs6/components/Personalization/dom-actions/collectInteractions.js +15 -0
  93. package/libEs6/components/Personalization/dom-actions/dom/isDomElement.js +12 -0
  94. package/libEs6/components/Personalization/dom-actions/initDomActionsModules.js +46 -16
  95. package/libEs6/components/Personalization/dom-actions/insertHtmlAfter.js +5 -2
  96. package/libEs6/components/Personalization/dom-actions/insertHtmlBefore.js +3 -2
  97. package/libEs6/components/Personalization/dom-actions/prependHtml.js +3 -2
  98. package/libEs6/components/Personalization/dom-actions/rearrangeChildren.js +3 -1
  99. package/libEs6/components/Personalization/dom-actions/remapCustomCodeOffers.js +2 -2
  100. package/libEs6/components/Personalization/dom-actions/remapHeadOffers.js +2 -2
  101. package/libEs6/components/Personalization/dom-actions/replaceHtml.js +4 -3
  102. package/libEs6/components/Personalization/dom-actions/setAttributes.js +2 -1
  103. package/libEs6/components/Personalization/dom-actions/setHtml.js +2 -2
  104. package/libEs6/components/Personalization/dom-actions/setStyles.js +2 -1
  105. package/libEs6/components/Personalization/dom-actions/setText.js +2 -1
  106. package/libEs6/components/Personalization/dom-actions/swapImage.js +3 -2
  107. package/libEs6/components/Personalization/handlers/createDecorateProposition.js +59 -0
  108. package/libEs6/components/Personalization/handlers/createProcessDomAction.js +10 -4
  109. package/libEs6/components/Personalization/handlers/createProcessHtmlContent.js +6 -2
  110. package/libEs6/components/Personalization/handlers/createProcessPropositions.js +1 -1
  111. package/libEs6/components/Personalization/handlers/injectCreateProposition.js +12 -1
  112. package/libEs6/components/Personalization/index.js +32 -8
  113. package/libEs6/components/Personalization/utils/metaUtils.js +23 -0
  114. package/libEs6/components/Personalization/validateApplyPropositionsOptions.js +12 -1
  115. package/libEs6/constants/decisionProvider.js +2 -1
  116. package/libEs6/constants/libraryVersion.js +1 -1
  117. package/libEs6/constants/propositionInteractionType.js +15 -0
  118. package/libEs6/utils/dom/awaitSelector.js +5 -1
  119. package/package.json +23 -22
  120. package/scripts/build-alloy.js +125 -0
@@ -9,10 +9,15 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
+
13
+ import createDecorateProposition from "./createDecorateProposition.js";
14
+ import { DOM_ACTION_CLICK } from "../dom-actions/initDomActionsModules.js";
12
15
  export default (({
13
16
  modules,
14
17
  logger,
15
- storeClickMetrics
18
+ storeInteractionMeta,
19
+ storeClickMeta,
20
+ autoCollectPropositionInteractions
16
21
  }) => item => {
17
22
  const {
18
23
  type,
@@ -25,7 +30,7 @@ export default (({
25
30
  includeInNotification: false
26
31
  };
27
32
  }
28
- if (type === "click") {
33
+ if (type === DOM_ACTION_CLICK) {
29
34
  if (!selector) {
30
35
  logger.warn("Invalid DOM action data: missing selector.", item.getData());
31
36
  return {
@@ -33,7 +38,7 @@ export default (({
33
38
  includeInNotification: false
34
39
  };
35
40
  }
36
- storeClickMetrics({
41
+ storeClickMeta({
37
42
  selector,
38
43
  meta: {
39
44
  ...item.getProposition().getNotification(),
@@ -53,8 +58,9 @@ export default (({
53
58
  includeInNotification: false
54
59
  };
55
60
  }
61
+ const decorateProposition = createDecorateProposition(autoCollectPropositionInteractions, type, item.getProposition().getId(), item.getId(), item.getTrackingLabel(), item.getProposition().getScopeType(), item.getProposition().getNotification(), storeInteractionMeta);
56
62
  return {
57
- render: () => modules[type](item.getData()),
63
+ render: () => modules[type](item.getData(), decorateProposition),
58
64
  setRenderAttempted: true,
59
65
  includeInNotification: true
60
66
  };
@@ -9,9 +9,12 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
+ import createDecorateProposition from "./createDecorateProposition.js";
12
13
  export default (({
13
14
  modules,
14
- logger
15
+ logger,
16
+ storeInteractionMeta,
17
+ autoCollectPropositionInteractions
15
18
  }) => item => {
16
19
  const {
17
20
  type,
@@ -30,9 +33,10 @@ export default (({
30
33
  includeInNotification: false
31
34
  };
32
35
  }
36
+ const decorateProposition = createDecorateProposition(autoCollectPropositionInteractions, type, item.getProposition().getId(), item.getId(), item.getTrackingLabel(), item.getProposition().getScopeType(), item.getProposition().getNotification(), storeInteractionMeta);
33
37
  return {
34
38
  render: () => {
35
- modules[type](item.getData());
39
+ return modules[type](item.getData(), decorateProposition);
36
40
  },
37
41
  setRenderAttempted: true,
38
42
  includeInNotification: true
@@ -107,7 +107,7 @@ export default (({
107
107
  const meta = atLeastOneWithNotification ? proposition.getNotification() : undefined;
108
108
  renderers.push(() => renderItems(itemRenderers, meta));
109
109
  } else if (atLeastOneWithNotification) {
110
- renderers.push(() => proposition.getNotification());
110
+ renderers.push(() => Promise.resolve(proposition.getNotification()));
111
111
  }
112
112
  if (renderedItems.length > 0) {
113
113
  proposition.addToReturnValues(returnedPropositions, returnedDecisions, renderedItems, true);
@@ -11,24 +11,32 @@ governing permissions and limitations under the License.
11
11
  */
12
12
 
13
13
  import PAGE_WIDE_SCOPE from "../../../constants/pageWideScope.js";
14
- import { VIEW_SCOPE_TYPE, PAGE_SCOPE_TYPE, PROPOSITION_SCOPE_TYPE } from "../constants/scopeType.js";
14
+ import { PAGE_SCOPE_TYPE, PROPOSITION_SCOPE_TYPE, VIEW_SCOPE_TYPE } from "../constants/scopeType.js";
15
15
  export default (({
16
16
  preprocess,
17
17
  isPageWideSurface
18
18
  }) => {
19
19
  const createItem = (item, proposition) => {
20
20
  const {
21
+ id,
21
22
  schema,
22
23
  data,
23
24
  characteristics: {
24
25
  trackingLabel
25
26
  } = {}
26
27
  } = item;
28
+ const schemaType = data ? data.type : undefined;
27
29
  const processedData = preprocess(data);
28
30
  return {
31
+ getId() {
32
+ return id;
33
+ },
29
34
  getSchema() {
30
35
  return schema;
31
36
  },
37
+ getSchemaType() {
38
+ return schemaType;
39
+ },
32
40
  getData() {
33
41
  return processedData;
34
42
  },
@@ -87,6 +95,9 @@ export default (({
87
95
  scopeDetails
88
96
  };
89
97
  },
98
+ getId() {
99
+ return id;
100
+ },
90
101
  toJSON() {
91
102
  return payload;
92
103
  },
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { boolean, objectOf, string } from "../../utils/validation/index.js";
13
+ import { anyOf, boolean, literal, objectOf, string } from "../../utils/validation/index.js";
14
14
  import createComponent from "./createComponent.js";
15
15
  import { initDomActionsModules } from "./dom-actions/index.js";
16
16
  import createCollect from "./createCollect.js";
@@ -23,6 +23,7 @@ import createOnClickHandler from "./createOnClickHandler.js";
23
23
  import createViewCacheManager from "./createViewCacheManager.js";
24
24
  import createViewChangeHandler from "./createViewChangeHandler.js";
25
25
  import createClickStorage from "./createClickStorage.js";
26
+ import createInteractionStorage from "./createInteractionStorage.js";
26
27
  import createApplyPropositions from "./createApplyPropositions.js";
27
28
  import createGetPageLocation from "./createGetPageLocation.js";
28
29
  import createSetTargetMigration from "./createSetTargetMigration.js";
@@ -44,6 +45,9 @@ import initInAppMessageActionsModules from "./in-app-message-actions/initInAppMe
44
45
  import createRedirect from "./dom-actions/createRedirect.js";
45
46
  import createNotificationHandler from "./createNotificationHandler.js";
46
47
  import createHandleConsentFlicker from "./createHandleConsentFlicker.js";
48
+ import collectInteractions from "./dom-actions/clicks/collectInteractions.js";
49
+ import { ALWAYS, NEVER, PROPOSITION_INTERACTION_TYPES } from "../../constants/propositionInteractionType.js";
50
+ import { ADOBE_JOURNEY_OPTIMIZER, ADOBE_TARGET } from "../../constants/decisionProvider.js";
47
51
  const createPersonalization = ({
48
52
  config,
49
53
  logger,
@@ -52,16 +56,21 @@ const createPersonalization = ({
52
56
  }) => {
53
57
  const {
54
58
  targetMigrationEnabled,
55
- prehidingStyle
59
+ prehidingStyle,
60
+ autoCollectPropositionInteractions
56
61
  } = config;
57
62
  const collect = createCollect({
58
63
  eventManager,
59
64
  mergeDecisionsMeta
60
65
  });
61
66
  const {
62
- getClickMetasBySelector,
67
+ storeInteractionMeta,
68
+ getInteractionMetas
69
+ } = createInteractionStorage();
70
+ const {
71
+ storeClickMeta,
63
72
  getClickSelectors,
64
- storeClickMetrics
73
+ getClickMetas
65
74
  } = createClickStorage();
66
75
  const getPageLocation = createGetPageLocation({
67
76
  window
@@ -81,11 +90,15 @@ const createPersonalization = ({
81
90
  [schema.DOM_ACTION]: createProcessDomAction({
82
91
  modules: domActionsModules,
83
92
  logger,
84
- storeClickMetrics
93
+ storeInteractionMeta,
94
+ storeClickMeta,
95
+ autoCollectPropositionInteractions
85
96
  }),
86
97
  [schema.HTML_CONTENT_ITEM]: createProcessHtmlContent({
87
98
  modules: domActionsModules,
88
- logger
99
+ logger,
100
+ storeInteractionMeta,
101
+ autoCollectPropositionInteractions
89
102
  }),
90
103
  [schema.REDIRECT_ITEM]: createProcessRedirect({
91
104
  logger,
@@ -115,9 +128,12 @@ const createPersonalization = ({
115
128
  });
116
129
  const onClickHandler = createOnClickHandler({
117
130
  mergeDecisionsMeta,
131
+ collectInteractions,
118
132
  collectClicks,
133
+ getInteractionMetas,
134
+ getClickMetas,
119
135
  getClickSelectors,
120
- getClickMetasBySelector
136
+ autoCollectPropositionInteractions
121
137
  });
122
138
  const viewChangeHandler = createViewChangeHandler({
123
139
  processPropositions,
@@ -160,8 +176,16 @@ const createPersonalization = ({
160
176
  });
161
177
  };
162
178
  createPersonalization.namespace = "Personalization";
179
+ const interactionConfigOptions = PROPOSITION_INTERACTION_TYPES.map(propositionInteractionType => literal(propositionInteractionType));
163
180
  createPersonalization.configValidators = objectOf({
164
181
  prehidingStyle: string().nonEmpty(),
165
- targetMigrationEnabled: boolean().default(false)
182
+ targetMigrationEnabled: boolean().default(false),
183
+ autoCollectPropositionInteractions: objectOf({
184
+ [ADOBE_JOURNEY_OPTIMIZER]: anyOf(interactionConfigOptions).default(ALWAYS),
185
+ [ADOBE_TARGET]: anyOf(interactionConfigOptions).default(NEVER)
186
+ }).default({
187
+ [ADOBE_JOURNEY_OPTIMIZER]: ALWAYS,
188
+ [ADOBE_TARGET]: NEVER
189
+ }).noUnknownFields()
166
190
  });
167
191
  export default createPersonalization;
@@ -0,0 +1,23 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export const cleanMetas = metas => metas.map(meta => {
13
+ const {
14
+ trackingLabel,
15
+ scopeType,
16
+ ...rest
17
+ } = meta;
18
+ return rest;
19
+ });
20
+ export const dedupeMetas = metas => metas.filter((meta, index) => {
21
+ const stringifiedMeta = JSON.stringify(meta);
22
+ return index === metas.findIndex(innerMeta => JSON.stringify(innerMeta) === stringifiedMeta);
23
+ });
@@ -18,7 +18,18 @@ export default (({
18
18
  options
19
19
  }) => {
20
20
  const applyPropositionsOptionsValidator = objectOf({
21
- propositions: arrayOf(objectOf(anything())),
21
+ propositions: arrayOf(objectOf({
22
+ id: string().required(),
23
+ scope: string().required(),
24
+ scopeDetails: objectOf({
25
+ decisionProvider: string().required()
26
+ }).required(),
27
+ items: arrayOf(objectOf({
28
+ id: string().required(),
29
+ schema: string().required(),
30
+ data: anything().required()
31
+ })).nonEmpty().required()
32
+ }).required()).nonEmpty().required(),
22
33
  metadata: objectOf(anything()),
23
34
  viewName: string()
24
35
  }).required();
@@ -9,4 +9,5 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
9
9
  OF ANY KIND, either express or implied. See the License for the specific language
10
10
  governing permissions and limitations under the License.
11
11
  */
12
- export const ADOBE_JOURNEY_OPTIMIZER = "AJO";
12
+ export const ADOBE_JOURNEY_OPTIMIZER = "AJO";
13
+ export const ADOBE_TARGET = "TGT";
@@ -13,4 +13,4 @@ governing permissions and limitations under the License.
13
13
  // The __VERSION__ keyword will be replace at alloy build time with the package.json version.
14
14
  // see babel-plugin-version
15
15
 
16
- export default "2.20.0";
16
+ export default "2.21.0-beta.1";
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export const ALWAYS = "always";
13
+ export const NEVER = "never";
14
+ export const DECORATED_ELEMENTS_ONLY = "decoratedElementsOnly";
15
+ export const PROPOSITION_INTERACTION_TYPES = [ALWAYS, NEVER, DECORATED_ELEMENTS_ONLY];
@@ -34,14 +34,18 @@ export const canUseMutationObserver = win => {
34
34
  };
35
35
  export const awaitUsingMutationObserver = (win, doc, selector, timeout, selectFunc) => {
36
36
  return createPromise((resolve, reject) => {
37
+ let timer;
37
38
  const mutationObserver = new win[MUTATION_OBSERVER](() => {
38
39
  const nodes = selectFunc(selector);
39
40
  if (isNonEmptyArray(nodes)) {
40
41
  mutationObserver.disconnect();
42
+ if (timer) {
43
+ clearTimeout(timer);
44
+ }
41
45
  resolve(nodes);
42
46
  }
43
47
  });
44
- setTimeout(() => {
48
+ timer = setTimeout(() => {
45
49
  mutationObserver.disconnect();
46
50
  reject(createError(selector));
47
51
  }, timeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.20.0",
3
+ "version": "2.21.0-beta.1",
4
4
  "description": "Adobe Experience Platform Web SDK",
5
5
  "type": "module",
6
6
  "main": "libEs5/index.js",
@@ -9,6 +9,9 @@
9
9
  "libEs5",
10
10
  "libEs6"
11
11
  ],
12
+ "bin": {
13
+ "build-alloy": "scripts/build-alloy.js"
14
+ },
12
15
  "scripts": {
13
16
  "clean": "rimraf dist distTest libEs5 libEs6",
14
17
  "lint": "eslint --cache --fix \"*.js\" \"{src,test,scripts}/**/*.js\"",
@@ -28,10 +31,9 @@
28
31
  "test:functional:build:prod": "rollup -c --environment BASE_CODE_MIN,NPM_PACKAGE_PROD",
29
32
  "test:scripts": "jasmine --config=scripts/specs/jasmine.json",
30
33
  "sandbox:build": "rollup -c --environment SANDBOX && cd sandbox && npm run build",
31
- "sandbox:build:custom": "SANDBOX=true npm run build:custom -- --exclude personalization && cd sandbox && npm run build && npm run start",
32
34
  "dev": "concurrently --names build,sandbox \"rollup -c -w --environment SANDBOX\" \"cd sandbox && export REACT_APP_NONCE=321 && npm start\"",
33
- "build": "npm run format && npm run lint && npm run clean && rollup -c --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN && echo \"Base Code:\" && cat distTest/baseCode.min.js",
34
- "build:custom": "npm run clean && rollup -c --environment BASE_CODE_MIN,NPM_PACKAGE_LOCAL && node scripts/helpers/customBuild.js",
35
+ "build": "npm run clean && rollup -c --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN && echo \"Base Code:\" && cat distTest/baseCode.min.js",
36
+ "build:cli": "node scripts/build-alloy.js",
35
37
  "prepare": "husky && cd sandbox && npm install",
36
38
  "prepublishOnly": "rimraf libEs5 libEs6 && babel src -d libEs5 --env-name npmEs5 && babel src -d libEs6 --env-name npmEs6",
37
39
  "checkthattestfilesexist": "./scripts/checkThatTestFilesExist.js",
@@ -75,22 +77,21 @@
75
77
  "uuid": "^9.0.1"
76
78
  },
77
79
  "devDependencies": {
78
- "@adobe/alloy": "^2.20.0-beta.9",
79
- "@babel/cli": "^7.24.5",
80
- "@babel/core": "^7.24.5",
81
- "@babel/eslint-parser": "^7.24.5",
80
+ "@adobe/alloy": "2.21.0-beta.0",
81
+ "@babel/cli": "^7.24.7",
82
+ "@babel/core": "^7.24.7",
83
+ "@babel/eslint-parser": "^7.24.7",
82
84
  "@babel/plugin-proposal-object-rest-spread": "^7.3.2",
83
- "@babel/plugin-transform-runtime": "^7.24.3",
84
- "@babel/plugin-transform-template-literals": "^7.24.1",
85
- "@babel/preset-env": "^7.24.5",
86
- "@babel/types": "^7.24.5",
87
- "@eslint/js": "^9.2.0",
85
+ "@babel/plugin-transform-runtime": "^7.24.7",
86
+ "@babel/plugin-transform-template-literals": "^7.24.7",
87
+ "@babel/preset-env": "^7.24.7",
88
+ "@babel/types": "^7.24.7",
89
+ "@eslint/js": "^9.4.0",
88
90
  "@octokit/rest": "^20.1.1",
89
91
  "@rollup/plugin-babel": "^6.0.4",
90
- "@rollup/plugin-commonjs": "^25.0.7",
92
+ "@rollup/plugin-commonjs": "^26.0.1",
91
93
  "@rollup/plugin-node-resolve": "^15.2.3",
92
94
  "@rollup/plugin-terser": "^0.4.4",
93
- "babel-plugin-version": "^0.2.3",
94
95
  "bundlesize": "^0.18.2",
95
96
  "chai": "^5.1.1",
96
97
  "chalk": "^5.3.0",
@@ -105,8 +106,8 @@
105
106
  "eslint-plugin-prettier": "^5.1.3",
106
107
  "eslint-plugin-testcafe": "^0.2.1",
107
108
  "force-resolutions": "^1.0.11",
108
- "glob": "^10.3.15",
109
- "globals": "^15.2.0",
109
+ "glob": "^10.4.1",
110
+ "globals": "^15.4.0",
110
111
  "handlebars": "^4.7.8",
111
112
  "husky": "^9.0.11",
112
113
  "jasmine": "^5.1.0",
@@ -123,20 +124,20 @@
123
124
  "karma-safari-launcher": "^1.0.0",
124
125
  "karma-sauce-launcher": "^4.3.6",
125
126
  "karma-spec-reporter": "0.0.36",
126
- "lint-staged": "^15.2.2",
127
- "prettier": "^3.2.5",
127
+ "lint-staged": "^15.2.5",
128
+ "prettier": "^3.3.1",
128
129
  "promise-polyfill": "^8.3.0",
129
130
  "read-cache": "^1.0.0",
130
131
  "recursive-readdir": "^2.2.3",
131
132
  "request": "^2.88.0",
132
133
  "rimraf": "^5.0.7",
133
- "rollup": "^4.17.2",
134
+ "rollup": "^4.18.0",
134
135
  "rollup-plugin-glob-import": "^0.5.0",
135
136
  "rollup-plugin-istanbul": "^5.0.0",
136
137
  "rollup-plugin-license": "^3.4.0",
137
138
  "semver": "^7.6.2",
138
139
  "staged-git-files": "^1.3.0",
139
- "start-server-and-test": "^2.0.3",
140
+ "start-server-and-test": "^2.0.4",
140
141
  "testcafe": "^3.6.0",
141
142
  "testcafe-browser-provider-saucelabs": "^3.0.0",
142
143
  "testcafe-reporter-junit": "^3.0.2",
@@ -151,6 +152,6 @@
151
152
  }
152
153
  },
153
154
  "optionalDependencies": {
154
- "@rollup/rollup-linux-x64-gnu": "^4.17.2"
155
+ "@rollup/rollup-linux-x64-gnu": "^4.18.0"
155
156
  }
156
157
  }
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ Copyright 2023 Adobe. All rights reserved.
5
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License. You may obtain a copy
7
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ Unless required by applicable law or agreed to in writing, software distributed under
9
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
+ OF ANY KIND, either express or implied. See the License for the specific language
11
+ governing permissions and limitations under the License.
12
+ */
13
+
14
+ import fs from "fs";
15
+ import path from "path";
16
+ import { rollup } from "rollup";
17
+ import yargs from "yargs/yargs";
18
+ // eslint-disable-next-line import/extensions
19
+ import { hideBin } from "yargs/helpers";
20
+ import conditionalBuildBabelPlugin from "./helpers/conditionalBuildBabelPlugin.js";
21
+ import { buildConfig } from "../rollup.config.js";
22
+
23
+ const dirname = import.meta.dirname;
24
+
25
+ // Path to componentCreators.js
26
+ const componentCreatorsPath = path.join(
27
+ dirname,
28
+ "../src/core/componentCreators.js",
29
+ );
30
+
31
+ // Read componentCreators.js
32
+ const componentCreatorsContent = fs.readFileSync(componentCreatorsPath, "utf8");
33
+
34
+ // Extract optional components based on @skipwhen directive
35
+ const optionalComponents = componentCreatorsContent
36
+ .split("\n")
37
+ .filter((line) => line.trim().startsWith("/* @skipwhen"))
38
+ .map((line) => {
39
+ const match = line.match(/ENV\.alloy_([a-zA-Z0-9]+) === false/);
40
+ if (match) {
41
+ const [, componentName] = match;
42
+ return componentName.toLowerCase(); // Ensure this matches the expected format for exclusion
43
+ }
44
+ return null;
45
+ })
46
+ .filter(Boolean);
47
+
48
+ const getDefaultPath = () => {
49
+ return process.cwd();
50
+ };
51
+
52
+ const argv = yargs(hideBin(process.argv))
53
+ .scriptName("build-alloy")
54
+ .example([
55
+ [`$0 --exclude ${optionalComponents.slice(0, 2).join(" ")}`],
56
+ [`$0 --minify --exclude ${optionalComponents.slice(0, 2).join(" ")}`],
57
+ ])
58
+ .option("exclude", {
59
+ describe: "components that can be excluded from the build",
60
+ choices: optionalComponents,
61
+ type: "array",
62
+ alias: "e",
63
+ default: [],
64
+ })
65
+ .option("minify", {
66
+ type: "boolean",
67
+ default: false,
68
+ alias: "m",
69
+ })
70
+ .option("outputDir", {
71
+ alias: "o",
72
+ default: getDefaultPath(),
73
+ })
74
+ .coerce("outputDir", (opt) => {
75
+ if (opt !== getDefaultPath()) {
76
+ opt = `${getDefaultPath()}${path.sep}${opt}`;
77
+ }
78
+
79
+ try {
80
+ const stats = fs.statSync(opt);
81
+ if (!stats.isDirectory()) {
82
+ throw new Error("Output directory must be a valid directory path.");
83
+ }
84
+ } catch (error) {
85
+ throw new Error("Output directory must be a valid directory path.");
86
+ }
87
+
88
+ return opt.replace(new RegExp(`${path.sep}+$`, "g"), "");
89
+ }).argv;
90
+
91
+ const getFile = () => {
92
+ return `${[argv.outputDir, `alloy${argv.minify ? ".min" : ""}.js`].join(path.sep)}`;
93
+ };
94
+
95
+ const getFileSizeInKB = (filePath) => {
96
+ const stats = fs.statSync(filePath);
97
+ const fileSizeInBytes = stats.size;
98
+ return `${(fileSizeInBytes / 1024).toFixed(2)} K`;
99
+ };
100
+
101
+ const buildWithComponents = async () => {
102
+ const rollupConfig = buildConfig({
103
+ file: getFile(),
104
+ minify: argv.minify,
105
+ babelPlugins: [
106
+ conditionalBuildBabelPlugin(
107
+ argv.exclude.reduce((acc, module) => {
108
+ acc[`alloy_${module}`] = "false";
109
+ return acc;
110
+ }, {}),
111
+ ),
112
+ ],
113
+ });
114
+
115
+ const bundle = await rollup(rollupConfig);
116
+ await bundle.write(rollupConfig.output[0]);
117
+ console.log(
118
+ `🎉 Wrote ${path.relative(
119
+ process.cwd(),
120
+ rollupConfig.output[0].file,
121
+ )} (${getFileSizeInKB(rollupConfig.output[0].file)}).`,
122
+ );
123
+ };
124
+
125
+ buildWithComponents();