@vtex/checkout 0.16.7 → 0.17.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 (56) hide show
  1. package/dist/cli.d.ts +2 -1
  2. package/dist/cli.js +2 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/build.js +10 -1
  5. package/dist/commands/build.js.map +1 -1
  6. package/dist/commands/create.d.ts +3 -1
  7. package/dist/commands/create.js +26 -6
  8. package/dist/commands/create.js.map +1 -1
  9. package/dist/commands/dev.d.ts +1 -0
  10. package/dist/commands/dev.js +35 -6
  11. package/dist/commands/dev.js.map +1 -1
  12. package/dist/commands/index.d.ts +1 -0
  13. package/dist/commands/index.js +1 -0
  14. package/dist/commands/index.js.map +1 -1
  15. package/dist/commands/scripts-init.d.ts +10 -0
  16. package/dist/commands/scripts-init.js +58 -0
  17. package/dist/commands/scripts-init.js.map +1 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/lib/bundler.d.ts +11 -1
  22. package/dist/lib/bundler.js +49 -21
  23. package/dist/lib/bundler.js.map +1 -1
  24. package/dist/lib/checkout-config.d.ts +50 -0
  25. package/dist/lib/checkout-config.js +179 -0
  26. package/dist/lib/checkout-config.js.map +1 -0
  27. package/dist/lib/constants.d.ts +7 -1
  28. package/dist/lib/constants.js +7 -1
  29. package/dist/lib/constants.js.map +1 -1
  30. package/dist/lib/extensions-config.d.ts +18 -0
  31. package/dist/lib/extensions-config.js +12 -0
  32. package/dist/lib/extensions-config.js.map +1 -0
  33. package/dist/lib/project-files.d.ts +50 -0
  34. package/dist/lib/project-files.js +158 -0
  35. package/dist/lib/project-files.js.map +1 -0
  36. package/dist/lib/scripts-watcher.d.ts +28 -0
  37. package/dist/lib/scripts-watcher.js +79 -0
  38. package/dist/lib/scripts-watcher.js.map +1 -0
  39. package/dist/scripts/allowed-scripts.d.ts +77 -0
  40. package/dist/scripts/allowed-scripts.js +97 -0
  41. package/dist/scripts/allowed-scripts.js.map +1 -0
  42. package/dist/scripts/define-checkout-config.d.ts +38 -0
  43. package/dist/scripts/define-checkout-config.js +9 -0
  44. package/dist/scripts/define-checkout-config.js.map +1 -0
  45. package/dist/scripts/index.d.ts +5 -0
  46. package/dist/scripts/index.js +4 -0
  47. package/dist/scripts/index.js.map +1 -0
  48. package/dist/scripts/resolve-scripts.d.ts +35 -0
  49. package/dist/scripts/resolve-scripts.js +285 -0
  50. package/dist/scripts/resolve-scripts.js.map +1 -0
  51. package/dist/scripts/types.d.ts +56 -0
  52. package/dist/scripts/types.js +2 -0
  53. package/dist/scripts/types.js.map +1 -0
  54. package/package.json +2 -2
  55. package/template/checkout.config.ts +13 -0
  56. package/template/tsconfig.json +1 -1
@@ -0,0 +1,77 @@
1
+ export declare const SLOTS: readonly ["head-top", "head-bottom", "body-top", "body-bottom"];
2
+ /**
3
+ * Third-party scripts a merchant may inject into checkout.
4
+ *
5
+ * Merchants pick an entry by id and fill in its params. The URL, the
6
+ * attributes and the inline script always come from this constant, never from
7
+ * the merchant. Adding or changing an entry needs Security review, and
8
+ * Legal/Privacy review for `requiresConsent` and `onetrustCategory`.
9
+ *
10
+ * Invariants (enforced by the CI tests next to this file):
11
+ * - every param pattern compiles, is anchored, accepts only [A-Za-z0-9_.-]
12
+ * and rejects an empty value;
13
+ * - `inlineTemplate` never contains a `{param}` placeholder;
14
+ * - placeholders in `urlTemplate` and `attributes` are declared required params;
15
+ * - `urlTemplate` starts with `https://<fixed host>/`, so no placeholder can reach the scheme or host;
16
+ * - an attribute that holds a placeholder is a `data-*` attribute;
17
+ * - the object is deeply frozen at runtime.
18
+ */
19
+ export declare const ALLOWED_SCRIPTS: {
20
+ readonly 'google-gtm': {
21
+ readonly scriptName: "Google Tag Manager";
22
+ readonly urlTemplate: "https://www.googletagmanager.com/gtm.js?id={gtmId}";
23
+ readonly params: {
24
+ /** Google Tag Manager container ID, for example GTM-ABC1234. */
25
+ readonly gtmId: {
26
+ readonly required: true;
27
+ readonly pattern: "^GTM-[A-Z0-9]{4,12}$";
28
+ readonly description: "Google Tag Manager container ID, for example GTM-ABC1234.";
29
+ };
30
+ };
31
+ readonly allowedSlots: readonly ["head-top", "head-bottom"];
32
+ readonly attributes: {
33
+ readonly async: true;
34
+ };
35
+ readonly requiresConsent: true;
36
+ readonly onetrustCategory: "targeting";
37
+ readonly inlineTemplate: "(function(w,l){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});})(window,'dataLayer');";
38
+ };
39
+ readonly onetrust: {
40
+ readonly scriptName: "OneTrust Cookie Consent";
41
+ readonly urlTemplate: "https://cdn.cookielaw.org/scripttemplates/otSDKStub.js";
42
+ readonly params: {
43
+ /** OneTrust domain script ID (data-domain-script). */
44
+ readonly domainId: {
45
+ readonly required: true;
46
+ readonly pattern: "^[A-Za-z0-9_-]+$";
47
+ readonly description: "OneTrust domain script ID (data-domain-script).";
48
+ };
49
+ /** OneTrust group ID mapped to the performance category, for example C0002. */
50
+ readonly performanceGroupId: {
51
+ readonly required: true;
52
+ readonly pattern: "^[A-Za-z0-9_-]+$";
53
+ readonly description: "OneTrust group ID mapped to the performance category, for example C0002.";
54
+ };
55
+ /** OneTrust group ID mapped to the functional category, for example C0003. */
56
+ readonly functionalGroupId: {
57
+ readonly required: true;
58
+ readonly pattern: "^[A-Za-z0-9_-]+$";
59
+ readonly description: "OneTrust group ID mapped to the functional category, for example C0003.";
60
+ };
61
+ /** OneTrust group ID mapped to the targeting category, for example C0004. */
62
+ readonly targetingGroupId: {
63
+ readonly required: true;
64
+ readonly pattern: "^[A-Za-z0-9_-]+$";
65
+ readonly description: "OneTrust group ID mapped to the targeting category, for example C0004.";
66
+ };
67
+ };
68
+ readonly allowedSlots: readonly ["head-top"];
69
+ readonly attributes: {
70
+ readonly 'data-domain-script': "{domainId}";
71
+ readonly 'data-checkout-group-performance': "{performanceGroupId}";
72
+ readonly 'data-checkout-group-functional': "{functionalGroupId}";
73
+ readonly 'data-checkout-group-targeting': "{targetingGroupId}";
74
+ };
75
+ readonly requiresConsent: false;
76
+ };
77
+ };
@@ -0,0 +1,97 @@
1
+ export const SLOTS = [
2
+ 'head-top',
3
+ 'head-bottom',
4
+ 'body-top',
5
+ 'body-bottom',
6
+ ];
7
+ /**
8
+ * Freezes `value` and everything reachable from it. `as const` only protects
9
+ * the allow list at type level; the merchant's `checkout.config.ts` runs in the
10
+ * CLI process next to this module, so the runtime object must be immutable too.
11
+ */
12
+ function deepFreeze(value) {
13
+ if (typeof value === 'object' && value !== null && !Object.isFrozen(value)) {
14
+ Object.values(value).forEach(deepFreeze);
15
+ Object.freeze(value);
16
+ }
17
+ return value;
18
+ }
19
+ /**
20
+ * Third-party scripts a merchant may inject into checkout.
21
+ *
22
+ * Merchants pick an entry by id and fill in its params. The URL, the
23
+ * attributes and the inline script always come from this constant, never from
24
+ * the merchant. Adding or changing an entry needs Security review, and
25
+ * Legal/Privacy review for `requiresConsent` and `onetrustCategory`.
26
+ *
27
+ * Invariants (enforced by the CI tests next to this file):
28
+ * - every param pattern compiles, is anchored, accepts only [A-Za-z0-9_.-]
29
+ * and rejects an empty value;
30
+ * - `inlineTemplate` never contains a `{param}` placeholder;
31
+ * - placeholders in `urlTemplate` and `attributes` are declared required params;
32
+ * - `urlTemplate` starts with `https://<fixed host>/`, so no placeholder can reach the scheme or host;
33
+ * - an attribute that holds a placeholder is a `data-*` attribute;
34
+ * - the object is deeply frozen at runtime.
35
+ */
36
+ export const ALLOWED_SCRIPTS = deepFreeze({
37
+ // Google Tag Manager: the container is loaded from the URL, the inline
38
+ // snippet only bootstraps the dataLayer.
39
+ 'google-gtm': {
40
+ scriptName: 'Google Tag Manager',
41
+ urlTemplate: 'https://www.googletagmanager.com/gtm.js?id={gtmId}',
42
+ params: {
43
+ /** Google Tag Manager container ID, for example GTM-ABC1234. */
44
+ gtmId: {
45
+ required: true,
46
+ pattern: '^GTM-[A-Z0-9]{4,12}$',
47
+ description: 'Google Tag Manager container ID, for example GTM-ABC1234.',
48
+ },
49
+ },
50
+ allowedSlots: ['head-top', 'head-bottom'],
51
+ attributes: { async: true },
52
+ requiresConsent: true,
53
+ onetrustCategory: 'targeting',
54
+ inlineTemplate: "(function(w,l){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});})(window,'dataLayer');",
55
+ },
56
+ // OneTrust is the consent manager itself, so it is never gated by consent.
57
+ // The group IDs map OneTrust categories to the checkout consent categories.
58
+ onetrust: {
59
+ scriptName: 'OneTrust Cookie Consent',
60
+ urlTemplate: 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js',
61
+ params: {
62
+ /** OneTrust domain script ID (data-domain-script). */
63
+ domainId: {
64
+ required: true,
65
+ pattern: '^[A-Za-z0-9_-]+$',
66
+ description: 'OneTrust domain script ID (data-domain-script).',
67
+ },
68
+ /** OneTrust group ID mapped to the performance category, for example C0002. */
69
+ performanceGroupId: {
70
+ required: true,
71
+ pattern: '^[A-Za-z0-9_-]+$',
72
+ description: 'OneTrust group ID mapped to the performance category, for example C0002.',
73
+ },
74
+ /** OneTrust group ID mapped to the functional category, for example C0003. */
75
+ functionalGroupId: {
76
+ required: true,
77
+ pattern: '^[A-Za-z0-9_-]+$',
78
+ description: 'OneTrust group ID mapped to the functional category, for example C0003.',
79
+ },
80
+ /** OneTrust group ID mapped to the targeting category, for example C0004. */
81
+ targetingGroupId: {
82
+ required: true,
83
+ pattern: '^[A-Za-z0-9_-]+$',
84
+ description: 'OneTrust group ID mapped to the targeting category, for example C0004.',
85
+ },
86
+ },
87
+ allowedSlots: ['head-top'],
88
+ attributes: {
89
+ 'data-domain-script': '{domainId}',
90
+ 'data-checkout-group-performance': '{performanceGroupId}',
91
+ 'data-checkout-group-functional': '{functionalGroupId}',
92
+ 'data-checkout-group-targeting': '{targetingGroupId}',
93
+ },
94
+ requiresConsent: false,
95
+ },
96
+ });
97
+ //# sourceMappingURL=allowed-scripts.js.map
@@ -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BAC3B,WAAW,EAAE,iDAAiD;aAC/D;YACD,+EAA+E;YAC/E,kBAAkB,EAAE;gBAClB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,kBAAkB;gBAC3B,WAAW,EACT,0EAA0E;aAC7E;YACD,8EAA8E;YAC9E,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,kBAAkB;gBAC3B,WAAW,EACT,yEAAyE;aAC5E;YACD,6EAA6E;YAC7E,gBAAgB,EAAE;gBAChB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,kBAAkB;gBAC3B,WAAW,EACT,wEAAwE;aAC3E;SACF;QACD,YAAY,EAAE,CAAC,UAAU,CAAC;QAC1B,UAAU,EAAE;YACV,oBAAoB,EAAE,YAAY;YAClC,iCAAiC,EAAE,sBAAsB;YACzD,gCAAgC,EAAE,qBAAqB;YACvD,+BAA+B,EAAE,oBAAoB;SACtD;QACD,eAAe,EAAE,KAAK;KACvB;CACkD,CAAC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ALLOWED_SCRIPTS } from './allowed-scripts.js';
2
+ import type { Slot } from './types.js';
3
+ type AllowList = typeof ALLOWED_SCRIPTS;
4
+ export type ScriptId = keyof AllowList;
5
+ type ParamsOf<Id extends ScriptId> = AllowList[Id]['params'];
6
+ type RequiredKeys<P> = {
7
+ [K in keyof P]: P[K] extends {
8
+ required: true;
9
+ } ? K : never;
10
+ }[keyof P];
11
+ /**
12
+ * Params accepted by a script id: required keys are mandatory strings,
13
+ * optional keys are optional strings, no other keys are allowed.
14
+ */
15
+ export type ScriptParams<Id extends ScriptId> = {
16
+ -readonly [K in keyof ParamsOf<Id> as K extends RequiredKeys<ParamsOf<Id>> ? K : never]: string;
17
+ } & {
18
+ -readonly [K in keyof ParamsOf<Id> as K extends RequiredKeys<ParamsOf<Id>> ? never : K]?: string;
19
+ };
20
+ export type ScriptEntry = {
21
+ [Id in ScriptId]: {
22
+ id: Id;
23
+ params: ScriptParams<Id>;
24
+ };
25
+ }[ScriptId];
26
+ export type ScriptsConfig = {
27
+ [S in Slot]?: ScriptEntry[];
28
+ };
29
+ export type CheckoutConfig = {
30
+ scripts?: ScriptsConfig;
31
+ };
32
+ /**
33
+ * Identity helper that type-checks `checkout.config.ts`: script ids and their
34
+ * params are derived from the allow list, so typos and missing params fail
35
+ * `tsc`. Slot restrictions are validated by `checkout build`.
36
+ */
37
+ export declare function defineCheckoutConfig(config: CheckoutConfig): CheckoutConfig;
38
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Identity helper that type-checks `checkout.config.ts`: script ids and their
3
+ * params are derived from the allow list, so typos and missing params fail
4
+ * `tsc`. Slot restrictions are validated by `checkout build`.
5
+ */
6
+ export function defineCheckoutConfig(config) {
7
+ return config;
8
+ }
9
+ //# sourceMappingURL=define-checkout-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-checkout-config.js","sourceRoot":"","sources":["../../src/scripts/define-checkout-config.ts"],"names":[],"mappings":"AAmCA;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAsB;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { ALLOWED_SCRIPTS, SLOTS } from './allowed-scripts.js';
2
+ export { defineCheckoutConfig } from './define-checkout-config.js';
3
+ export { flattenScriptsConfig, formatScriptIssue, resolveScripts, } from './resolve-scripts.js';
4
+ export type { CheckoutConfig, ScriptEntry, ScriptId, ScriptParams, ScriptsConfig, } from './define-checkout-config.js';
5
+ export type { ConfiguredScript, ParamSpec, ResolvedScript, ScriptDefinition, ScriptIssue, ScriptIssueCode, ScriptsModule, Slot, } from './types.js';
@@ -0,0 +1,4 @@
1
+ export { ALLOWED_SCRIPTS, SLOTS } from './allowed-scripts.js';
2
+ export { defineCheckoutConfig } from './define-checkout-config.js';
3
+ export { flattenScriptsConfig, formatScriptIssue, resolveScripts, } from './resolve-scripts.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ConfiguredScript, ResolvedScript, ScriptDefinition, ScriptIssue } from './types.js';
2
+ type AllowListOption = Readonly<Record<string, ScriptDefinition>>;
3
+ /**
4
+ * Validates untrusted entries against the allow list and resolves the accepted
5
+ * ones. Never throws. Stops at the first failing rule per entry and records one
6
+ * issue for it. Rule 6 (duplicate id) only compares entries that passed rules
7
+ * 1 to 5: the first accepted entry for an id is kept.
8
+ *
9
+ * `accepted` is parallel to `resolved` and carries the validated copy of each
10
+ * entry's params. Callers that need the params must use it, not the original
11
+ * entries, which are untrusted and may change between reads.
12
+ *
13
+ * `entries` is untrusted too: a value that is not an array, or an array whose
14
+ * iteration throws (a proxy, for example), yields a single `invalid-shape`
15
+ * issue with a null slot, position and id, and nothing resolved.
16
+ */
17
+ export declare function resolveScripts(entries: unknown, options?: {
18
+ allowList?: AllowListOption;
19
+ }): {
20
+ resolved: ResolvedScript[];
21
+ issues: ScriptIssue[];
22
+ accepted: ConfiguredScript[];
23
+ };
24
+ /**
25
+ * Turns the `scripts` block of a config (an object keyed by slot) into the
26
+ * flat entry list `resolveScripts` expects. Entries are emitted in slot order,
27
+ * then array order, each tagged with its slot.
28
+ */
29
+ export declare function flattenScriptsConfig(scripts: unknown): {
30
+ entries: unknown[];
31
+ issues: ScriptIssue[];
32
+ };
33
+ /** Formats an issue as `scripts.<slot>[<position>] (<id>): <message>`. */
34
+ export declare function formatScriptIssue(issueToFormat: ScriptIssue): string;
35
+ export {};
@@ -0,0 +1,285 @@
1
+ import { ALLOWED_SCRIPTS, SLOTS } from './allowed-scripts.js';
2
+ const PLACEHOLDER = /\{([A-Za-z0-9_]+)\}/g;
3
+ const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
4
+ const isPlainObject = (value) => {
5
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
6
+ return false;
7
+ }
8
+ const prototype = Object.getPrototypeOf(value);
9
+ return prototype === Object.prototype || prototype === null;
10
+ };
11
+ const isSlot = (value) => SLOTS.includes(value);
12
+ const formatParamSpec = (spec) => {
13
+ const parts = [];
14
+ if (spec.description) {
15
+ // Descriptions are sentences; do not double the final period.
16
+ const sentence = spec.description.replace(/\.$/, '');
17
+ parts.push(`Expected: ${sentence}.`);
18
+ }
19
+ parts.push(`Pattern: ${spec.pattern}.`);
20
+ if (spec.minLength !== undefined || spec.maxLength !== undefined) {
21
+ parts.push(`Length: ${spec.minLength ?? 0}-${spec.maxLength ?? 'unbounded'}.`);
22
+ }
23
+ return parts.join(' ');
24
+ };
25
+ const matchesSpec = (value, spec) => {
26
+ if (spec.minLength !== undefined && value.length < spec.minLength) {
27
+ return false;
28
+ }
29
+ if (spec.maxLength !== undefined && value.length > spec.maxLength) {
30
+ return false;
31
+ }
32
+ try {
33
+ return new RegExp(spec.pattern).test(value);
34
+ }
35
+ catch {
36
+ return false;
37
+ }
38
+ };
39
+ const substitute = (template, definition, params, encode) => template.replace(PLACEHOLDER, (match, name) => {
40
+ if (!hasOwn(definition.params, name) || !hasOwn(params, name)) {
41
+ return match;
42
+ }
43
+ return encode(params[name] ?? '');
44
+ });
45
+ const identity = (value) => value;
46
+ const resolveEntry = (definition, id, slot, params) => {
47
+ const attributes = {};
48
+ for (const [name, value] of Object.entries(definition.attributes ?? {})) {
49
+ attributes[name] =
50
+ typeof value === 'string'
51
+ ? substitute(value, definition, params, identity)
52
+ : value;
53
+ }
54
+ return {
55
+ id,
56
+ slot,
57
+ url: definition.urlTemplate === undefined
58
+ ? null
59
+ : substitute(definition.urlTemplate, definition, params, encodeURIComponent),
60
+ inlineScript: definition.inlineTemplate ?? null,
61
+ attributes,
62
+ integrity: definition.integrity ?? null,
63
+ crossorigin: definition.crossorigin ?? null,
64
+ requiresConsent: definition.requiresConsent,
65
+ onetrustCategory: definition.onetrustCategory ?? null,
66
+ };
67
+ };
68
+ /**
69
+ * Reads an untrusted entry exactly once. Every later rule and substitution
70
+ * uses this copy, never the original, so a getter that answers differently on
71
+ * each read cannot pass validation with one value and be substituted with
72
+ * another. Never throws: a throwing getter or proxy trap yields an invalid
73
+ * shape.
74
+ */
75
+ const snapshotEntry = (entry) => {
76
+ let slot = null;
77
+ let id = null;
78
+ try {
79
+ if (!isPlainObject(entry))
80
+ return { slot, id, params: null };
81
+ const rawSlot = entry.slot;
82
+ slot = typeof rawSlot === 'string' ? rawSlot : null;
83
+ const rawId = entry.id;
84
+ id = typeof rawId === 'string' ? rawId : null;
85
+ const rawParams = entry.params;
86
+ if (!isPlainObject(rawParams))
87
+ return { slot, id, params: null };
88
+ // Null prototype: a param named `__proto__` or `constructor` is plain data.
89
+ const params = Object.create(null);
90
+ for (const [name, value] of Object.entries(rawParams)) {
91
+ if (typeof value !== 'string')
92
+ return { slot, id, params: null };
93
+ params[name] = value;
94
+ }
95
+ return { slot, id, params };
96
+ }
97
+ catch {
98
+ return { slot, id, params: null };
99
+ }
100
+ };
101
+ const issue = (context, code, message, param) => ({
102
+ code,
103
+ slot: context.slot,
104
+ position: context.position,
105
+ id: context.id,
106
+ ...(param === undefined ? {} : { param }),
107
+ message,
108
+ });
109
+ const list = (values) => values.length > 0 ? values.join(', ') : 'none';
110
+ /**
111
+ * Validates untrusted entries against the allow list and resolves the accepted
112
+ * ones. Never throws. Stops at the first failing rule per entry and records one
113
+ * issue for it. Rule 6 (duplicate id) only compares entries that passed rules
114
+ * 1 to 5: the first accepted entry for an id is kept.
115
+ *
116
+ * `accepted` is parallel to `resolved` and carries the validated copy of each
117
+ * entry's params. Callers that need the params must use it, not the original
118
+ * entries, which are untrusted and may change between reads.
119
+ *
120
+ * `entries` is untrusted too: a value that is not an array, or an array whose
121
+ * iteration throws (a proxy, for example), yields a single `invalid-shape`
122
+ * issue with a null slot, position and id, and nothing resolved.
123
+ */
124
+ export function resolveScripts(entries, options = {}) {
125
+ const allowList = options.allowList ?? ALLOWED_SCRIPTS;
126
+ const resolved = [];
127
+ const accepted = [];
128
+ const issues = [];
129
+ const acceptedSlotById = new Map();
130
+ const positionBySlot = new Map();
131
+ const listContext = { slot: null, position: null, id: null };
132
+ // Copied once, so the loop below never touches the untrusted list again.
133
+ let entryList;
134
+ try {
135
+ if (!Array.isArray(entries)) {
136
+ issues.push(issue(listContext, 'invalid-shape', 'Invalid scripts: expected an array of entries.'));
137
+ return { resolved, issues, accepted };
138
+ }
139
+ entryList = Array.from(entries);
140
+ }
141
+ catch {
142
+ issues.push(issue(listContext, 'invalid-shape', 'Invalid scripts: could not be read.'));
143
+ return { resolved, issues, accepted };
144
+ }
145
+ for (const entry of entryList) {
146
+ const snapshot = snapshotEntry(entry);
147
+ const { slot: slotName, id: rawId, params } = snapshot;
148
+ let position = null;
149
+ if (slotName !== null) {
150
+ position = positionBySlot.get(slotName) ?? 0;
151
+ positionBySlot.set(slotName, position + 1);
152
+ }
153
+ const context = {
154
+ slot: slotName,
155
+ position,
156
+ id: rawId,
157
+ };
158
+ if (rawId === null || slotName === null || params === null) {
159
+ issues.push(issue(context, 'invalid-shape', 'Invalid entry: expected { id: string, params: Record<string, string> }.'));
160
+ continue;
161
+ }
162
+ if (!isSlot(slotName)) {
163
+ issues.push(issue(context, 'unknown-slot', `Unknown slot "${slotName}". Valid slots: ${SLOTS.join(', ')}.`));
164
+ continue;
165
+ }
166
+ const definition = hasOwn(allowList, rawId) ? allowList[rawId] : undefined;
167
+ if (definition === undefined) {
168
+ issues.push(issue(context, 'unknown-id', `"${rawId}" is not in the allow list. Allowed ids: ${list(Object.keys(allowList))}.`));
169
+ continue;
170
+ }
171
+ let paramIssue = null;
172
+ for (const [name, spec] of Object.entries(definition.params)) {
173
+ if (!hasOwn(params, name)) {
174
+ if (spec.required) {
175
+ paramIssue = issue(context, 'missing-param', `Missing required param "${name}". ${formatParamSpec(spec)}`, name);
176
+ break;
177
+ }
178
+ continue;
179
+ }
180
+ if (!matchesSpec(params[name] ?? '', spec)) {
181
+ paramIssue = issue(context, 'invalid-param', `Param "${name}" has an invalid value. ${formatParamSpec(spec)}`, name);
182
+ break;
183
+ }
184
+ }
185
+ if (paramIssue === null) {
186
+ const unknown = Object.keys(params).find((name) => !hasOwn(definition.params, name));
187
+ if (unknown !== undefined) {
188
+ paramIssue = issue(context, 'unknown-param', `Param "${unknown}" is not accepted by "${rawId}". Accepted params: ${list(Object.keys(definition.params))}.`, unknown);
189
+ }
190
+ }
191
+ if (paramIssue !== null) {
192
+ issues.push(paramIssue);
193
+ continue;
194
+ }
195
+ if (!definition.allowedSlots.includes(slotName)) {
196
+ issues.push(issue(context, 'slot-not-allowed', `"${rawId}" cannot be placed in "${slotName}". Allowed slots: ${list(definition.allowedSlots)}.`));
197
+ continue;
198
+ }
199
+ const firstSlot = acceptedSlotById.get(rawId);
200
+ if (firstSlot !== undefined) {
201
+ issues.push(issue(context, 'duplicate-id', `"${rawId}" appears more than once: first in "${firstSlot}", again in "${slotName}". Each script id may appear only once.`));
202
+ continue;
203
+ }
204
+ acceptedSlotById.set(rawId, slotName);
205
+ resolved.push(resolveEntry(definition, rawId, slotName, params));
206
+ accepted.push({ id: rawId, slot: slotName, params: { ...params } });
207
+ }
208
+ return { resolved, issues, accepted };
209
+ }
210
+ /**
211
+ * Turns the `scripts` block of a config (an object keyed by slot) into the
212
+ * flat entry list `resolveScripts` expects. Entries are emitted in slot order,
213
+ * then array order, each tagged with its slot.
214
+ */
215
+ export function flattenScriptsConfig(scripts) {
216
+ const entries = [];
217
+ const issues = [];
218
+ if (scripts === undefined || scripts === null) {
219
+ return { entries, issues };
220
+ }
221
+ const invalidScripts = (message) => {
222
+ issues.push({
223
+ code: 'invalid-shape',
224
+ slot: null,
225
+ position: null,
226
+ id: null,
227
+ message,
228
+ });
229
+ return { entries: [], issues };
230
+ };
231
+ try {
232
+ if (!isPlainObject(scripts)) {
233
+ return invalidScripts('Invalid scripts config: expected an object keyed by slot.');
234
+ }
235
+ // Each slot value is read once, so a getter cannot answer differently for
236
+ // the shape check and for the entries that are collected.
237
+ const valueBySlot = new Map();
238
+ for (const key of Object.keys(scripts)) {
239
+ const value = scripts[key];
240
+ if (!isSlot(key)) {
241
+ issues.push({
242
+ code: 'unknown-slot',
243
+ slot: key,
244
+ position: null,
245
+ id: null,
246
+ message: `Unknown slot "${key}". Valid slots: ${SLOTS.join(', ')}.`,
247
+ });
248
+ continue;
249
+ }
250
+ if (!Array.isArray(value)) {
251
+ issues.push({
252
+ code: 'invalid-shape',
253
+ slot: key,
254
+ position: null,
255
+ id: null,
256
+ message: `Invalid slot "${key}": expected an array of entries.`,
257
+ });
258
+ continue;
259
+ }
260
+ valueBySlot.set(key, value);
261
+ }
262
+ for (const slot of SLOTS) {
263
+ const slotEntries = valueBySlot.get(slot);
264
+ if (slotEntries === undefined)
265
+ continue;
266
+ for (const element of slotEntries) {
267
+ entries.push(typeof element === 'object' && element !== null
268
+ ? { ...element, slot }
269
+ : { slot });
270
+ }
271
+ }
272
+ return { entries, issues };
273
+ }
274
+ catch {
275
+ return invalidScripts('Invalid scripts config: could not be read.');
276
+ }
277
+ }
278
+ /** Formats an issue as `scripts.<slot>[<position>] (<id>): <message>`. */
279
+ export function formatScriptIssue(issueToFormat) {
280
+ const slot = issueToFormat.slot === null ? '' : `.${issueToFormat.slot}`;
281
+ const position = issueToFormat.position === null ? '' : `[${issueToFormat.position}]`;
282
+ const id = issueToFormat.id === null ? '' : ` (${issueToFormat.id})`;
283
+ return `scripts${slot}${position}${id}: ${issueToFormat.message}`;
284
+ }
285
+ //# sourceMappingURL=resolve-scripts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-scripts.js","sourceRoot":"","sources":["../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@@ -0,0 +1,56 @@
1
+ export type Slot = 'head-top' | 'head-bottom' | 'body-top' | 'body-bottom';
2
+ export type ParamSpec = {
3
+ required: boolean;
4
+ pattern: string;
5
+ description?: string;
6
+ minLength?: number;
7
+ maxLength?: number;
8
+ };
9
+ type BaseDefinition = {
10
+ scriptName: string;
11
+ urlTemplate?: string;
12
+ inlineTemplate?: string;
13
+ params: Record<string, ParamSpec>;
14
+ allowedSlots: readonly Slot[];
15
+ attributes?: Record<string, string | boolean>;
16
+ integrity?: string;
17
+ crossorigin?: 'anonymous';
18
+ };
19
+ export type ScriptDefinition = (BaseDefinition & {
20
+ requiresConsent: false;
21
+ onetrustCategory?: never;
22
+ }) | (BaseDefinition & {
23
+ requiresConsent: true;
24
+ onetrustCategory: 'performance' | 'functional' | 'targeting';
25
+ });
26
+ export type ConfiguredScript = {
27
+ id: string;
28
+ slot: Slot;
29
+ params: Record<string, string>;
30
+ };
31
+ export type ScriptsModule = {
32
+ default: ConfiguredScript[];
33
+ };
34
+ export type ResolvedScript = {
35
+ id: string;
36
+ slot: Slot;
37
+ url: string | null;
38
+ inlineScript: string | null;
39
+ attributes: Record<string, string | boolean>;
40
+ integrity: string | null;
41
+ crossorigin: 'anonymous' | null;
42
+ requiresConsent: boolean;
43
+ onetrustCategory: 'performance' | 'functional' | 'targeting' | null;
44
+ };
45
+ export type ScriptIssueCode = 'invalid-shape' | 'unknown-slot' | 'unknown-id' | 'missing-param' | 'invalid-param' | 'unknown-param' | 'slot-not-allowed' | 'duplicate-id';
46
+ export type ScriptIssue = {
47
+ code: ScriptIssueCode;
48
+ slot: string | null;
49
+ /** Zero-based position inside its slot, null when unknown. */
50
+ position: number | null;
51
+ id: string | null;
52
+ param?: string;
53
+ /** Reason only, no location prefix, never contains param values. */
54
+ message: string;
55
+ };
56
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/scripts/types.ts"],"names":[],"mappings":""}