@tokenoftrust/cli 8.4.1 → 8.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/declared-config.d.mts +8 -0
- package/src/declared-config.mjs +194 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Token of Trust",
|
|
@@ -34,6 +34,14 @@ export function shippingDeclarationProblems(shipping: unknown): string[];
|
|
|
34
34
|
export const COMMERCE_KEYS: readonly string[];
|
|
35
35
|
export const ORDER_NUMBERING_KEYS: readonly string[];
|
|
36
36
|
export function commerceDeclarationProblems(commerce: unknown): string[];
|
|
37
|
+
export const DEFAULT_SALES_CHANNEL_ID: "default";
|
|
38
|
+
export const SALES_CHANNEL_ID_PATTERN: RegExp;
|
|
39
|
+
export const SALES_CHANNEL_COMPLIANCE_MODES: readonly string[];
|
|
40
|
+
export const SALES_CHANNEL_KEYS: readonly string[];
|
|
41
|
+
export const SALES_CHANNEL_CATALOG_FILTER_KEYS: readonly string[];
|
|
42
|
+
export function isValidSalesChannelId(value: unknown): value is string;
|
|
43
|
+
export function isValidChannelDomain(value: unknown): value is string;
|
|
44
|
+
export function channelsDeclarationProblems(channels: unknown): string[];
|
|
37
45
|
export const COMPLIANCE_NOTICES: Record<string, string>;
|
|
38
46
|
export const MANDATED_NOTICE_KEYS: string[];
|
|
39
47
|
export function nearestKey(key: string, known: readonly string[]): string | null;
|
package/src/declared-config.mjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
export const TOT_CONFIG_KEYS = [
|
|
21
21
|
"$schema", "tenant", "scope", "mappings", "hostPlatform", "sample", "seed",
|
|
22
|
-
"displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog", "commerce", "accessPolicy", "verification",
|
|
22
|
+
"displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog", "commerce", "accessPolicy", "verification", "channels",
|
|
23
23
|
];
|
|
24
24
|
// Keys other tooling has written that the platform does NOT read, with the key it does.
|
|
25
25
|
const RENAMED_CONFIG_KEYS = { appDomain: "scope", tenantId: "tenant" };
|
|
@@ -67,6 +67,194 @@ export function verificationDeclarationProblems(value) {
|
|
|
67
67
|
return problems;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
export const DEFAULT_SALES_CHANNEL_ID = "default";
|
|
71
|
+
export const SALES_CHANNEL_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
72
|
+
export const SALES_CHANNEL_COMPLIANCE_MODES = Object.freeze(["b2c", "b2b"]);
|
|
73
|
+
export const SALES_CHANNEL_KEYS = Object.freeze([
|
|
74
|
+
"id",
|
|
75
|
+
"displayName",
|
|
76
|
+
"domains",
|
|
77
|
+
"canonicalDomain",
|
|
78
|
+
"default",
|
|
79
|
+
"salesChannel",
|
|
80
|
+
"accessPolicy",
|
|
81
|
+
"catalogFilter",
|
|
82
|
+
"theme_tokens",
|
|
83
|
+
"seo",
|
|
84
|
+
]);
|
|
85
|
+
export const SALES_CHANNEL_CATALOG_FILTER_KEYS = Object.freeze([
|
|
86
|
+
"includeCollections",
|
|
87
|
+
"excludeCollections",
|
|
88
|
+
"includeTags",
|
|
89
|
+
"excludeTags",
|
|
90
|
+
"includeProductHandles",
|
|
91
|
+
"excludeProductHandles",
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const CHANNEL_THEME_SECTION_KEYS = Object.freeze(["color", "type", "space", "shape", "brand"]);
|
|
95
|
+
const CHANNEL_DOMAIN_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
96
|
+
const CHANNEL_SECRET_KEY_RE = /(?:secret|token|password|apikey|api_key|private|credential|kms|auth)/i;
|
|
97
|
+
const MAX_SALES_CHANNELS = 50;
|
|
98
|
+
const MAX_CHANNEL_DOMAINS = 50;
|
|
99
|
+
const MAX_CHANNEL_FILTER_ITEMS = 500;
|
|
100
|
+
|
|
101
|
+
/** @param {unknown} value @returns {value is string} */
|
|
102
|
+
export function isValidSalesChannelId(value) {
|
|
103
|
+
return typeof value === "string" && SALES_CHANNEL_ID_PATTERN.test(value);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @param {unknown} value @returns {value is string} */
|
|
107
|
+
export function isValidChannelDomain(value) {
|
|
108
|
+
return (
|
|
109
|
+
typeof value === "string" &&
|
|
110
|
+
value.length >= 3 &&
|
|
111
|
+
value.length <= 253 &&
|
|
112
|
+
value === value.trim() &&
|
|
113
|
+
value === value.toLowerCase() &&
|
|
114
|
+
CHANNEL_DOMAIN_RE.test(value)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @param {unknown} value @param {string} at @returns {string[]} */
|
|
119
|
+
function channelThemeTokensProblems(value, at) {
|
|
120
|
+
if (!isObject(value)) return [`\`${at}\` must be an object`];
|
|
121
|
+
const problems = [];
|
|
122
|
+
for (const [section, tokens] of Object.entries(/** @type {Record<string, unknown>} */ (value))) {
|
|
123
|
+
if (!CHANNEL_THEME_SECTION_KEYS.includes(section)) {
|
|
124
|
+
problems.push(`\`${at}.${section}\` is not a theme_tokens section (${CHANNEL_THEME_SECTION_KEYS.join(", ")})`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!isObject(tokens)) {
|
|
128
|
+
problems.push(`\`${at}.${section}\` must be an object`);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
for (const [key, val] of Object.entries(/** @type {Record<string, unknown>} */ (tokens))) {
|
|
132
|
+
if (CHANNEL_SECRET_KEY_RE.test(key)) {
|
|
133
|
+
problems.push(`\`${at}.${section}.${key}\` is not a permitted theme token key`);
|
|
134
|
+
} else if (typeof val !== "string" && typeof val !== "number" && typeof val !== "boolean") {
|
|
135
|
+
problems.push(`\`${at}.${section}.${key}\` must be a scalar theme value`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return problems;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @param {unknown} value @param {string} at @returns {string[]} */
|
|
143
|
+
function channelCatalogFilterProblems(value, at) {
|
|
144
|
+
if (!isObject(value)) return [`\`${at}\` must be an object`];
|
|
145
|
+
const problems = [];
|
|
146
|
+
const filter = /** @type {Record<string, unknown>} */ (value);
|
|
147
|
+
for (const key of Object.keys(filter)) {
|
|
148
|
+
if (!SALES_CHANNEL_CATALOG_FILTER_KEYS.includes(key)) {
|
|
149
|
+
problems.push(`\`${at}.${key}\` is not a catalogFilter key (${SALES_CHANNEL_CATALOG_FILTER_KEYS.join(", ")})`);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const list = filter[key];
|
|
153
|
+
if (
|
|
154
|
+
!Array.isArray(list) ||
|
|
155
|
+
list.length > MAX_CHANNEL_FILTER_ITEMS ||
|
|
156
|
+
!list.every((item) => typeof item === "string" && item.trim().length > 0 && item.length <= 120 && !/[\u0000-\u001f\u007f]/.test(item))
|
|
157
|
+
) {
|
|
158
|
+
problems.push(`\`${at}.${key}\` must be an array of at most ${MAX_CHANNEL_FILTER_ITEMS} non-empty strings`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return problems;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @param {unknown} value @returns {string[]} */
|
|
165
|
+
export function channelsDeclarationProblems(value) {
|
|
166
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > MAX_SALES_CHANNELS) {
|
|
167
|
+
return [`\`channels\` must be a non-empty array of at most ${MAX_SALES_CHANNELS} channel declarations`];
|
|
168
|
+
}
|
|
169
|
+
const problems = [];
|
|
170
|
+
const seenIds = new Set();
|
|
171
|
+
const seenDomains = new Set();
|
|
172
|
+
let defaultCount = 0;
|
|
173
|
+
|
|
174
|
+
value.forEach((raw, index) => {
|
|
175
|
+
const at = `channels[${index}]`;
|
|
176
|
+
if (!isObject(raw)) {
|
|
177
|
+
problems.push(`\`${at}\` must be an object`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const ch = /** @type {Record<string, unknown>} */ (raw);
|
|
181
|
+
for (const key of Object.keys(ch)) {
|
|
182
|
+
if (!SALES_CHANNEL_KEYS.includes(key)) {
|
|
183
|
+
problems.push(`\`${at}.${key}\` is not a sales channel key (${SALES_CHANNEL_KEYS.join(", ")})`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (!isValidSalesChannelId(ch.id)) {
|
|
187
|
+
problems.push(`\`${at}.id\` must match ${SALES_CHANNEL_ID_PATTERN}`);
|
|
188
|
+
} else if (seenIds.has(ch.id)) {
|
|
189
|
+
problems.push(`\`${at}.id\` duplicates channel id ${JSON.stringify(ch.id)}`);
|
|
190
|
+
} else {
|
|
191
|
+
seenIds.add(ch.id);
|
|
192
|
+
}
|
|
193
|
+
if (typeof ch.salesChannel !== "string" || !SALES_CHANNEL_COMPLIANCE_MODES.includes(ch.salesChannel)) {
|
|
194
|
+
problems.push(`\`${at}.salesChannel\` must be one of ${SALES_CHANNEL_COMPLIANCE_MODES.join(", ")}`);
|
|
195
|
+
}
|
|
196
|
+
if (
|
|
197
|
+
ch.displayName !== undefined &&
|
|
198
|
+
(typeof ch.displayName !== "string" || ch.displayName.trim() !== ch.displayName || ch.displayName.length === 0 || ch.displayName.length > 120 || /[\u0000-\u001f\u007f]/.test(ch.displayName))
|
|
199
|
+
) {
|
|
200
|
+
problems.push(`\`${at}.displayName\` must be a non-empty trimmed string (max 120 chars)`);
|
|
201
|
+
}
|
|
202
|
+
if (ch.default !== undefined) {
|
|
203
|
+
if (typeof ch.default !== "boolean") {
|
|
204
|
+
problems.push(`\`${at}.default\` must be true or false`);
|
|
205
|
+
} else if (ch.default) {
|
|
206
|
+
defaultCount += 1;
|
|
207
|
+
if (defaultCount > 1) problems.push(`\`${at}.default\`: only one channel may be marked default`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (ch.domains !== undefined) {
|
|
211
|
+
if (!Array.isArray(ch.domains) || ch.domains.length > MAX_CHANNEL_DOMAINS) {
|
|
212
|
+
problems.push(`\`${at}.domains\` must be an array of at most ${MAX_CHANNEL_DOMAINS} hostnames`);
|
|
213
|
+
} else {
|
|
214
|
+
for (let dIdx = 0; dIdx < ch.domains.length; dIdx += 1) {
|
|
215
|
+
const domain = ch.domains[dIdx];
|
|
216
|
+
if (!isValidChannelDomain(domain)) {
|
|
217
|
+
problems.push(`\`${at}.domains[${dIdx}]\` must be a normalized lowercase hostname with no scheme, port, path, userinfo, or wildcard`);
|
|
218
|
+
} else if (seenDomains.has(domain)) {
|
|
219
|
+
problems.push(`\`${at}.domains[${dIdx}]\` duplicates domain ${JSON.stringify(domain)}`);
|
|
220
|
+
} else {
|
|
221
|
+
seenDomains.add(domain);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (ch.canonicalDomain !== undefined) {
|
|
227
|
+
if (!isValidChannelDomain(ch.canonicalDomain)) {
|
|
228
|
+
problems.push(`\`${at}.canonicalDomain\` must be a normalized lowercase hostname`);
|
|
229
|
+
} else if (!(Array.isArray(ch.domains) && ch.domains.includes(ch.canonicalDomain))) {
|
|
230
|
+
if (seenDomains.has(ch.canonicalDomain)) {
|
|
231
|
+
problems.push(`\`${at}.canonicalDomain\` duplicates a domain bound to another channel`);
|
|
232
|
+
} else {
|
|
233
|
+
seenDomains.add(ch.canonicalDomain);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (ch.accessPolicy !== undefined) {
|
|
238
|
+
for (const p of accessPolicyDeclarationProblems(ch.accessPolicy)) {
|
|
239
|
+
problems.push(`\`${at}.accessPolicy\`: ${p}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (ch.catalogFilter !== undefined) {
|
|
243
|
+
problems.push(...channelCatalogFilterProblems(ch.catalogFilter, `${at}.catalogFilter`));
|
|
244
|
+
}
|
|
245
|
+
if (ch.theme_tokens !== undefined) {
|
|
246
|
+
problems.push(...channelThemeTokensProblems(ch.theme_tokens, `${at}.theme_tokens`));
|
|
247
|
+
}
|
|
248
|
+
if (ch.seo !== undefined) {
|
|
249
|
+
for (const p of seoDeclarationProblems(ch.seo)) {
|
|
250
|
+
problems.push(`\`${at}.seo\`: ${p}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return problems;
|
|
256
|
+
}
|
|
257
|
+
|
|
70
258
|
/** The currency a store sells in when `.tot/config.json` declares none. */
|
|
71
259
|
export const DEFAULT_CURRENCY = "USD";
|
|
72
260
|
|
|
@@ -978,6 +1166,11 @@ export function validateDeclaredConfig(config, file = ".tot/config.json") {
|
|
|
978
1166
|
out.push(mk(ERROR, "config-shopper-verification", file, problem));
|
|
979
1167
|
}
|
|
980
1168
|
}
|
|
1169
|
+
if (config.channels !== undefined) {
|
|
1170
|
+
for (const problem of channelsDeclarationProblems(config.channels)) {
|
|
1171
|
+
out.push(mk(ERROR, "config-channels", `${file} channels`, problem));
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
981
1174
|
if (config.catalog !== undefined) {
|
|
982
1175
|
const problems = catalogDeclarationProblems(config.catalog);
|
|
983
1176
|
if (problems.length > 0) {
|