@adobe/alloy 2.21.0-beta.0 → 2.21.0-beta.10

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 (74) hide show
  1. package/LICENSE_BANNER +9 -0
  2. package/babel.config.cjs +93 -0
  3. package/libEs5/components/Audiences/injectProcessDestinations.js +1 -1
  4. package/libEs5/components/Context/index.js +1 -1
  5. package/libEs5/components/Context/injectHighEntropyUserAgentHints.js +4 -4
  6. package/libEs5/components/DataCollector/index.js +2 -2
  7. package/libEs5/components/DecisioningEngine/createConsequenceAdapter.js +1 -1
  8. package/libEs5/components/DecisioningEngine/createContextProvider.js +1 -1
  9. package/libEs5/components/DecisioningEngine/createEvaluableRulesetPayload.js +1 -1
  10. package/libEs5/components/DecisioningEngine/createEventRegistry.js +1 -1
  11. package/libEs5/components/DecisioningEngine/createOnResponseHandler.js +1 -1
  12. package/libEs5/components/DecisioningEngine/createSubscribeRulesetItems.js +1 -1
  13. package/libEs5/components/DecisioningEngine/index.js +1 -1
  14. package/libEs5/components/Identity/appendIdentityToUrl/injectAppendIdentityToUrl.js +4 -4
  15. package/libEs5/components/Identity/createLegacyIdentity.js +1 -1
  16. package/libEs5/components/Identity/injectAddQueryStringIdentityToPayload.js +4 -4
  17. package/libEs5/components/LegacyMediaAnalytics/createGetInstance.js +1 -1
  18. package/libEs5/components/LegacyMediaAnalytics/createLegacyMediaComponent.js +1 -1
  19. package/libEs5/components/LibraryInfo/index.js +6 -6
  20. package/libEs5/components/Personalization/createApplyPropositions.js +6 -6
  21. package/libEs5/components/Personalization/createClickStorage.js +1 -1
  22. package/libEs5/components/Personalization/createFetchDataHandler.js +5 -5
  23. package/libEs5/components/Personalization/createInteractionStorage.js +6 -6
  24. package/libEs5/components/Personalization/createPersonalizationDetails.js +5 -5
  25. package/libEs5/components/Personalization/createPreprocessors.js +1 -1
  26. package/libEs5/components/Personalization/dom-actions/clicks/collectClicks.js +5 -5
  27. package/libEs5/components/Personalization/dom-actions/clicks/collectInteractions.js +5 -5
  28. package/libEs5/components/Personalization/dom-actions/dom/selectNodesWithEq.js +4 -4
  29. package/libEs5/components/Personalization/dom-actions/initDomActionsModules.js +1 -1
  30. package/libEs5/components/Personalization/dom-actions/scripts.js +1 -1
  31. package/libEs5/components/Personalization/dom-actions/setStyles.js +2 -2
  32. package/libEs5/components/Personalization/event.js +1 -1
  33. package/libEs5/components/Personalization/flicker/index.js +1 -1
  34. package/libEs5/components/Personalization/handlers/createProcessDomAction.js +1 -1
  35. package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +1 -1
  36. package/libEs5/components/Personalization/handlers/createProcessPropositions.js +5 -5
  37. package/libEs5/components/Personalization/handlers/injectCreateProposition.js +1 -1
  38. package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +1 -1
  39. package/libEs5/components/Personalization/index.js +1 -1
  40. package/libEs5/components/Personalization/utils/metaUtils.js +2 -2
  41. package/libEs5/components/Privacy/createComponent.js +1 -1
  42. package/libEs5/components/Privacy/createConsentHashStore.js +2 -2
  43. package/libEs5/components/Privacy/parseConsentCookie.js +4 -4
  44. package/libEs5/components/StreamingMedia/validateMediaEventOptions.js +5 -5
  45. package/libEs5/constants/libraryVersion.js +1 -1
  46. package/libEs5/constants/propositionEventType.js +1 -1
  47. package/libEs5/core/buildAndValidateConfig.js +6 -6
  48. package/libEs5/core/componentCreators.js +4 -0
  49. package/libEs5/core/createEvent.js +5 -5
  50. package/libEs5/core/createEventManager.js +3 -3
  51. package/libEs5/core/edgeNetwork/mergeLifecycleResponses.js +5 -5
  52. package/libEs5/core/network/injectSendNetworkRequest.js +1 -1
  53. package/libEs5/standalone.js +18 -0
  54. package/libEs5/utils/assignConcatArrayValues.js +5 -5
  55. package/libEs5/utils/createLoggingCookieJar.js +1 -1
  56. package/libEs5/utils/createSubscription.js +5 -5
  57. package/libEs5/utils/filterObject.js +1 -1
  58. package/libEs5/utils/flattenArray.js +5 -5
  59. package/libEs5/utils/flattenObject.js +5 -5
  60. package/libEs5/utils/getBrowser.js +1 -1
  61. package/libEs5/utils/injectFireReferrerHideableImage.js +4 -4
  62. package/libEs5/utils/parseUrl.js +1 -1
  63. package/libEs5/utils/request/createRequestParams.js +2 -2
  64. package/libEs5/utils/validation/createDeprecatedValidator.js +3 -3
  65. package/libEs5/utils/validation/index.js +1 -1
  66. package/libEs6/constants/libraryVersion.js +1 -1
  67. package/libEs6/core/componentCreators.js +8 -0
  68. package/libEs6/standalone.js +16 -0
  69. package/package.json +43 -37
  70. package/rollup.config.js +164 -0
  71. package/scripts/alloyBuilder.js +215 -0
  72. package/scripts/helpers/alloyComponents.js +63 -0
  73. package/scripts/helpers/conditionalBuildBabelPlugin.js +57 -0
  74. package/scripts/helpers/versionBabelPlugin.js +43 -0
@@ -0,0 +1,215 @@
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 { Command, Option, InvalidOptionArgumentError } from "commander";
18
+ import inquirer from "inquirer";
19
+ import { fileURLToPath } from "url";
20
+ import { buildConfig } from "../rollup.config.js";
21
+ import conditionalBuildBabelPlugin from "./helpers/conditionalBuildBabelPlugin.js";
22
+ import components from "./helpers/alloyComponents.js";
23
+
24
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
25
+
26
+ let sourceRootPath = `${dirname}/../src`;
27
+ if (!fs.existsSync(sourceRootPath)) {
28
+ sourceRootPath = `${dirname}/../libEs6`;
29
+ }
30
+
31
+ const getOptionalComponents = (() => {
32
+ const componentCreatorsPath = `${sourceRootPath}/core/componentCreators.js`;
33
+
34
+ // Read componentCreators.js
35
+ const componentCreatorsContent = fs.readFileSync(
36
+ componentCreatorsPath,
37
+ "utf8",
38
+ );
39
+
40
+ // Extract optional components based on @skipwhen directive
41
+ const optionalComponents = componentCreatorsContent
42
+ .split("\n")
43
+ .filter((line) => line.trim().startsWith("/* @skipwhen"))
44
+ .map((line) => {
45
+ const match = line.match(/ENV\.alloy_([a-zA-Z0-9]+) === false/);
46
+ if (match) {
47
+ const [, componentName] = match;
48
+ return componentName.toLowerCase(); // Ensure this matches the expected format for exclusion
49
+ }
50
+ return null;
51
+ })
52
+ .filter(Boolean);
53
+
54
+ return () => optionalComponents;
55
+ })();
56
+
57
+ const getDefaultPath = () => {
58
+ return process.cwd();
59
+ };
60
+
61
+ const getFile = (argv) => {
62
+ return `${[argv.outputDir, `alloy${argv.minify ? ".min" : ""}.js`].join(path.sep)}`;
63
+ };
64
+
65
+ const getFileSizeInKB = (filePath) => {
66
+ const stats = fs.statSync(filePath);
67
+ const fileSizeInBytes = stats.size;
68
+ return `${(fileSizeInBytes / 1024).toFixed(2)} K`;
69
+ };
70
+
71
+ const build = async (argv) => {
72
+ const rollupConfig = buildConfig({
73
+ input: `${sourceRootPath}/standalone.js`,
74
+ file: getFile(argv),
75
+ minify: argv.minify,
76
+ babelPlugins: [
77
+ conditionalBuildBabelPlugin(
78
+ argv.exclude.reduce((acc, module) => {
79
+ acc[`alloy_${module}`] = "false";
80
+ return acc;
81
+ }, {}),
82
+ ),
83
+ ],
84
+ });
85
+
86
+ const bundle = await rollup(rollupConfig);
87
+ await bundle.write(rollupConfig.output[0]);
88
+ console.log(
89
+ `🎉 Wrote ${
90
+ path.isAbsolute(argv.outputDir)
91
+ ? rollupConfig.output[0].file
92
+ : path.relative(process.cwd(), rollupConfig.output[0].file)
93
+ } (${getFileSizeInKB(rollupConfig.output[0].file)}).`,
94
+ );
95
+ };
96
+
97
+ const getMakeBuildCommand = () =>
98
+ new Command("build")
99
+ .description("Build a custom version of the alloy.js library.")
100
+ .addOption(
101
+ new Option(
102
+ "-e, --exclude <modules...>",
103
+ "optional components that can be excluded from the build",
104
+ )
105
+ .choices(getOptionalComponents())
106
+ .default([])
107
+ .argParser((value) => {
108
+ const modules = value.split(",");
109
+
110
+ modules.forEach((module) => {
111
+ if (!getOptionalComponents().includes(module))
112
+ throw new InvalidOptionArgumentError(
113
+ `Module "${module}" does not exists. Allowed choices are "${getOptionalComponents().join('", "')}".`,
114
+ );
115
+ });
116
+
117
+ return modules;
118
+ }),
119
+ )
120
+ .addOption(new Option("-M, --no-minify", "disable code minification"))
121
+ .addOption(
122
+ new Option(
123
+ "-o, --outputDir <dir>",
124
+ "the output directory for the generated build",
125
+ )
126
+ .default(getDefaultPath())
127
+ .argParser((value) => {
128
+ if (!path.isAbsolute(value)) {
129
+ value = `${getDefaultPath()}${path.sep}${value}`;
130
+ }
131
+
132
+ try {
133
+ const stats = fs.statSync(value);
134
+ if (!stats.isDirectory()) {
135
+ throw new InvalidOptionArgumentError(
136
+ `Output directory "${value}" is not a valid directory path.`,
137
+ );
138
+ }
139
+ } catch (error) {
140
+ throw new InvalidOptionArgumentError(
141
+ `Output directory "${value}" is not a valid directory path. ${error.message}`,
142
+ );
143
+ }
144
+
145
+ return value.replace(new RegExp(`${path.sep}+$`, "g"), "");
146
+ }),
147
+ )
148
+ .action(async (opts) => {
149
+ await build(opts);
150
+ });
151
+
152
+ const getInteractiveBuildCommand = () =>
153
+ new Command("interactive-build")
154
+ .description(
155
+ "Interactive process that will ask a series of questions and then it will generate a build.",
156
+ )
157
+ .action(async () => {
158
+ await inquirer
159
+ .prompt([
160
+ {
161
+ type: "checkbox",
162
+ name: "include",
163
+ message: "What components should be included in your Alloy build?",
164
+ choices: components,
165
+ },
166
+ {
167
+ type: "list",
168
+ name: "minify",
169
+ message: "How would you like your JavaScript to be?",
170
+ choices: [
171
+ { name: "Minified", value: true },
172
+ { name: "Unminified", value: false },
173
+ ],
174
+ },
175
+ {
176
+ type: "string",
177
+ name: "outputDir",
178
+ message: "Where would you like to save the build?",
179
+ default: process.cwd(),
180
+ },
181
+ ])
182
+ .then(async (opts) => {
183
+ const { include } = opts;
184
+ const exclude = components
185
+ .map((v) => v.value)
186
+ .filter((component) => !include.includes(component));
187
+
188
+ opts.exclude = exclude;
189
+ delete opts.include;
190
+
191
+ await build(opts);
192
+ })
193
+ .catch((error) => {
194
+ if (error.isTtyError) {
195
+ console.error(
196
+ "Prompt couldn't be rendered in the current environment",
197
+ );
198
+ } else {
199
+ console.error("An error occurred: ", error);
200
+ }
201
+ });
202
+ });
203
+
204
+ const program = new Command();
205
+
206
+ program
207
+ .name("alloy")
208
+ .description(
209
+ "Tool for generating custom Adobe Experience Platform Web SDK builds.",
210
+ )
211
+ .version("1.0.0");
212
+
213
+ program.addCommand(getMakeBuildCommand());
214
+ program.addCommand(getInteractiveBuildCommand(), { isDefault: true });
215
+ program.parse();
@@ -0,0 +1,63 @@
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
+ Unless required by applicable law or agreed to in writing, software distributed under
7
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
+ OF ANY KIND, either express or implied. See the License for the specific language
9
+ governing permissions and limitations under the License.
10
+ */
11
+
12
+ export default [
13
+ {
14
+ name: "Activity Collector",
15
+ value: "activitycollector",
16
+ checked: true,
17
+ },
18
+ {
19
+ name: "Audiences",
20
+ value: "audiences",
21
+ checked: true,
22
+ },
23
+ {
24
+ name: "Context",
25
+ value: "context",
26
+ checked: true,
27
+ },
28
+ {
29
+ name: "Decision Engine",
30
+ value: "decisioningengine",
31
+ checked: true,
32
+ },
33
+ {
34
+ name: "Event Merge",
35
+ value: "eventmerge",
36
+ checked: true,
37
+ },
38
+ {
39
+ name: "Personalization",
40
+ value: "personalization",
41
+ checked: true,
42
+ },
43
+ {
44
+ name: "Privacy",
45
+ value: "privacy",
46
+ checked: true,
47
+ },
48
+ {
49
+ name: "Streaming Media",
50
+ value: "streamingmedia",
51
+ checked: true,
52
+ },
53
+ {
54
+ name: "Legacy Media Analytics",
55
+ value: "legacymediaanalytics",
56
+ checked: true,
57
+ },
58
+ {
59
+ name: "Machine Learning",
60
+ value: "machinelearning",
61
+ checked: true,
62
+ },
63
+ ];
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright 2023 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
+
13
+ export default (excludedModules) => ({
14
+ visitor: {
15
+ ImportDeclaration(path) {
16
+ let skipWhenComments = [];
17
+ if (path.node.leadingComments) {
18
+ skipWhenComments = path.node.leadingComments.filter((c) => {
19
+ return c.value.trim().startsWith("@skipwhen");
20
+ });
21
+ }
22
+
23
+ if (skipWhenComments.length > 0) {
24
+ const [, webSDKModuleName, value] = skipWhenComments[0].value.match(
25
+ "ENV.(.*) === (false|true)",
26
+ );
27
+
28
+ if (excludedModules[webSDKModuleName] === value) {
29
+ const variableName = path.node.specifiers[0].local.name;
30
+
31
+ // Wrap the variable declaration in an IIFE to turn it into an expression
32
+ path.replaceWithSourceString(
33
+ `(() => { const ${variableName} = () => {}; })()`,
34
+ );
35
+ }
36
+ }
37
+ },
38
+ ExportDefaultDeclaration(path) {
39
+ if (path.node.declaration.type === "ArrayExpression") {
40
+ path.node.declaration.elements = path.node.declaration.elements.filter(
41
+ (element) => {
42
+ if (element.name) {
43
+ const variableName = element.name;
44
+ const componentName = variableName
45
+ .replace("create", "")
46
+ .toLowerCase();
47
+ return !Object.keys(excludedModules).includes(
48
+ `alloy_${componentName}`,
49
+ );
50
+ }
51
+ return true;
52
+ },
53
+ );
54
+ }
55
+ },
56
+ },
57
+ });
@@ -0,0 +1,43 @@
1
+ import { createRequire } from "module";
2
+
3
+ const require = createRequire(import.meta.url);
4
+
5
+ const version = null;
6
+ const getVersion = ({ opts: { cwd } }) => {
7
+ if (version) {
8
+ return version;
9
+ }
10
+
11
+ // eslint-disable-next-line import/no-dynamic-require
12
+ const packageJson = require(`${cwd}/package.json`);
13
+ return packageJson.version;
14
+ };
15
+
16
+ export default (_ref) => {
17
+ const t = _ref.types;
18
+
19
+ return {
20
+ visitor: {
21
+ // __VERSION__
22
+ ReferencedIdentifier(path, state) {
23
+ const identifier = state.opts.identifier;
24
+ const transform = identifier === undefined ? true : identifier; // 默认转换
25
+
26
+ const define = state.opts.define || "__VERSION__"; // 默认值
27
+ if (transform && path.node.name === define) {
28
+ path.replaceWith(t.valueToNode(getVersion(state)));
29
+ }
30
+ },
31
+ // "__VERSION__"
32
+ StringLiteral(path, state) {
33
+ const stringLiteral = state.opts.stringLiteral;
34
+ const transform = stringLiteral === undefined ? true : stringLiteral;
35
+
36
+ const define = state.opts.define || "__VERSION__";
37
+ if (transform && path.node.value === define) {
38
+ path.replaceWith(t.valueToNode(getVersion(state)));
39
+ }
40
+ },
41
+ },
42
+ };
43
+ };