@tanqory/partner-cli 0.0.0-stage → 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/bin/tanqory-partner.mjs +10 -0
- package/config/mirror-allowlist.json +17 -0
- package/config/theme-licences.json +108 -0
- package/config/third-party-toolchains.json +45 -0
- package/lib/api.mjs +109 -0
- package/lib/auth.mjs +211 -0
- package/lib/check.mjs +66 -0
- package/lib/cli.mjs +217 -0
- package/lib/mcp.mjs +177 -0
- package/lib/ops.mjs +179 -0
- package/lib/theme.mjs +121 -0
- package/lib/vendor/partner-checks.cjs +2420 -0
- package/package.json +59 -4
- package/starter/LICENSE +18 -0
- package/starter/README.md +44 -0
- package/starter/config/settings.json +5 -0
- package/starter/gitignore +3 -0
- package/starter/locales/en.json +22 -0
- package/starter/locales/en.schema.json +69 -0
- package/starter/locales/th.json +22 -0
- package/starter/locales/th.schema.json +69 -0
- package/starter/package.json +29 -0
- package/starter/regions/footer.json +35 -0
- package/starter/regions/header.json +13 -0
- package/starter/scripts/build.mjs +211 -0
- package/starter/scripts/probe.ts +4 -0
- package/starter/src/bundle.ts +15 -0
- package/starter/src/components/parts.tsx +32 -0
- package/starter/src/entry.client.tsx +6 -0
- package/starter/src/entry.server.tsx +13 -0
- package/starter/src/sections/chrome.tsx +132 -0
- package/starter/src/sections/commerce.tsx +242 -0
- package/starter/src/sections/content.tsx +115 -0
- package/starter/src/sections/editorial.tsx +232 -0
- package/starter/src/settings.ts +12 -0
- package/starter/src/styles/theme.css +241 -0
- package/starter/src/templates.ts +14 -0
- package/starter/src/theme.tsx +86 -0
- package/starter/templates/404.json +14 -0
- package/starter/templates/account.json +14 -0
- package/starter/templates/article.json +14 -0
- package/starter/templates/blog.json +14 -0
- package/starter/templates/cart.json +14 -0
- package/starter/templates/collection.json +14 -0
- package/starter/templates/index.json +116 -0
- package/starter/templates/page.contact.json +22 -0
- package/starter/templates/page.json +14 -0
- package/starter/templates/product.json +18 -0
- package/starter/templates/search.json +14 -0
- package/starter/tsconfig.json +17 -0
- package/starter/vite.client.config.ts +17 -0
- package/starter/vite.probe.config.ts +16 -0
- package/starter/vite.server.config.ts +32 -0
- package/README.md +0 -3
|
@@ -0,0 +1,2420 @@
|
|
|
1
|
+
// GENERATED by scripts/prepare.mjs from apps/build-service/src/review/partner-source.ts. Do not edit.
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
try {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw mod = 0, e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
|
|
38
|
+
// ../theme-standard/lib/editability.js
|
|
39
|
+
var require_editability = __commonJS({
|
|
40
|
+
"../theme-standard/lib/editability.js"(exports2, module2) {
|
|
41
|
+
"use strict";
|
|
42
|
+
var STRUCTURAL_LINK = /^(#[\w-]*|\/|\/cart|\/search|\/account(\/[\w/-]*)?|\/collections|\/collections\/all(\?[\w=&-]*)?)$/;
|
|
43
|
+
var TEXT_ATTRS = /* @__PURE__ */ new Set(["alt", "title", "placeholder", "aria-label", "aria-description", "aria-placeholder"]);
|
|
44
|
+
var FORMAT_EXAMPLE = /^\s*([\w.+-]+@[\w-]+(\.[\w-]+)+|https?:\/\/\S+|[\w-]+(\.[\w-]+)+)\s*$/;
|
|
45
|
+
var LINK_ATTRS = /* @__PURE__ */ new Set(["href"]);
|
|
46
|
+
var MEDIA_ATTRS = /* @__PURE__ */ new Set(["src", "srcSet", "srcset", "poster", "image", "video"]);
|
|
47
|
+
var TEMPLATE_SECTIONS = /* @__PURE__ */ new Set(["product", "collection", "cart", "search", "account", "page", "blog", "article", "not-found", "password", "gift-card", "policy", "list-collections", "customers", "main"]);
|
|
48
|
+
var CONTENT_KEY = /^(heading|title|quote)$/i;
|
|
49
|
+
var KIT_SETTINGS = /* @__PURE__ */ new Set(["showLocale", "showAccount"]);
|
|
50
|
+
var CHROME_KEY = /(^|\.)(cart|account|search|product|price|form|forms|newsletter|contact|menu|nav|notFound|errors?|general|accessibility|a11y|pagination|sort|filter|filters|localization|consent|customer|checkout|journal|blog|article|footer\.rights|shelf\.empty|viewAll|readMore|skip)(\.|$)/i;
|
|
51
|
+
var LETTER = new RegExp("\\p{L}", "u");
|
|
52
|
+
var SVG_TEXT = /* @__PURE__ */ new Set(["text", "tspan", "title", "desc", "textPath"]);
|
|
53
|
+
var isWords = (s) => LETTER.test(s) && !/^\s*(&[a-z#0-9]+;\s*)+$/i.test(s);
|
|
54
|
+
function lineCol(src, i) {
|
|
55
|
+
let line2 = 1;
|
|
56
|
+
let last = -1;
|
|
57
|
+
for (let k = 0; k < i && k < src.length; k++) if (src.charCodeAt(k) === 10) {
|
|
58
|
+
line2++;
|
|
59
|
+
last = k;
|
|
60
|
+
}
|
|
61
|
+
return { line: line2, column: i - last };
|
|
62
|
+
}
|
|
63
|
+
function scan(src) {
|
|
64
|
+
const n = src.length;
|
|
65
|
+
const texts = [];
|
|
66
|
+
const attrs = [];
|
|
67
|
+
const strings = [];
|
|
68
|
+
const exprs = [];
|
|
69
|
+
const mask = src.split("");
|
|
70
|
+
let hiddenDepth = 0;
|
|
71
|
+
const blank = (a, b, ch = " ") => {
|
|
72
|
+
for (let k = a; k < b && k < n; k++) if (mask[k] !== "\n") mask[k] = ch;
|
|
73
|
+
};
|
|
74
|
+
const prevSignificant = (i) => {
|
|
75
|
+
let k = i - 1;
|
|
76
|
+
while (k >= 0 && /\s/.test(src[k])) k--;
|
|
77
|
+
if (k < 0) return { ch: "", word: "" };
|
|
78
|
+
let w = k;
|
|
79
|
+
while (w >= 0 && /[\w$]/.test(src[w])) w--;
|
|
80
|
+
return { ch: src[k], word: src.slice(w + 1, k + 1) };
|
|
81
|
+
};
|
|
82
|
+
const jsxCanStart = (i) => {
|
|
83
|
+
const nx = src[i + 1];
|
|
84
|
+
if (!(nx === ">" || /[A-Za-z]/.test(nx || ""))) return false;
|
|
85
|
+
const p = prevSignificant(i);
|
|
86
|
+
if (p.word === "return" || p.word === "default" || p.word === "") return p.ch === "" || /[\s(,=?:{[!&|;>]/.test(p.ch) || p.word === "return" || p.word === "default";
|
|
87
|
+
return /[(,=?:{[!&|;>]/.test(p.ch) && !/[\w$)\]]/.test(p.ch);
|
|
88
|
+
};
|
|
89
|
+
function skipString(i) {
|
|
90
|
+
const q = src[i];
|
|
91
|
+
let k = i + 1;
|
|
92
|
+
while (k < n && src[k] !== q && src[k] !== "\n") {
|
|
93
|
+
if (src[k] === "\\") k++;
|
|
94
|
+
k++;
|
|
95
|
+
}
|
|
96
|
+
strings.push({ start: i, end: k + 1, value: src.slice(i + 1, k) });
|
|
97
|
+
blank(i + 1, k, "_");
|
|
98
|
+
return k + 1;
|
|
99
|
+
}
|
|
100
|
+
function skipTemplate(i) {
|
|
101
|
+
let k = i + 1;
|
|
102
|
+
let static_ = "";
|
|
103
|
+
let dynamic = false;
|
|
104
|
+
while (k < n && src[k] !== "`") {
|
|
105
|
+
if (src[k] === "\\") {
|
|
106
|
+
k += 2;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (src[k] === "$" && src[k + 1] === "{") {
|
|
110
|
+
dynamic = true;
|
|
111
|
+
k = parseJS(k + 2, "}") + 1;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
static_ += src[k];
|
|
115
|
+
mask[k] = src[k] === "\n" ? "\n" : "_";
|
|
116
|
+
k++;
|
|
117
|
+
}
|
|
118
|
+
strings.push({ start: i, end: k + 1, value: static_, template: true, dynamic });
|
|
119
|
+
return k + 1;
|
|
120
|
+
}
|
|
121
|
+
function parseJS(i, stop) {
|
|
122
|
+
let depth = 0;
|
|
123
|
+
while (i < n) {
|
|
124
|
+
const c = src[i];
|
|
125
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
126
|
+
const e = src.indexOf("\n", i);
|
|
127
|
+
const end = e < 0 ? n : e;
|
|
128
|
+
blank(i, end);
|
|
129
|
+
i = end;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
133
|
+
const e = src.indexOf("*/", i + 2);
|
|
134
|
+
const end = e < 0 ? n : e + 2;
|
|
135
|
+
blank(i, end);
|
|
136
|
+
i = end;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (c === '"' || c === "'") {
|
|
140
|
+
i = skipString(i);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (c === "`") {
|
|
144
|
+
i = skipTemplate(i);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (c === "{" || c === "(" || c === "[") {
|
|
148
|
+
depth++;
|
|
149
|
+
i++;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (c === "}" || c === ")" || c === "]") {
|
|
153
|
+
if (depth === 0 && stop && c === stop) return i;
|
|
154
|
+
depth--;
|
|
155
|
+
i++;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (c === "<" && jsxCanStart(i)) {
|
|
159
|
+
const j = parseElement(i);
|
|
160
|
+
if (j > 0) {
|
|
161
|
+
i = j;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
i++;
|
|
166
|
+
}
|
|
167
|
+
return n;
|
|
168
|
+
}
|
|
169
|
+
function parseElement(i) {
|
|
170
|
+
const start = i;
|
|
171
|
+
i++;
|
|
172
|
+
if (src[i] === ">") return parseChildren(i + 1, "", start);
|
|
173
|
+
const m = /^[A-Za-z][\w.:-]*/.exec(src.slice(i, i + 80));
|
|
174
|
+
if (!m) return -1;
|
|
175
|
+
const tag = m[0];
|
|
176
|
+
i += tag.length;
|
|
177
|
+
const mine = [];
|
|
178
|
+
for (; ; ) {
|
|
179
|
+
while (i < n && /\s/.test(src[i])) i++;
|
|
180
|
+
if (src[i] === "/" && src[i + 1] === "/") {
|
|
181
|
+
const e = src.indexOf("\n", i);
|
|
182
|
+
const end = e < 0 ? n : e;
|
|
183
|
+
blank(i, end);
|
|
184
|
+
i = end;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (src[i] === "/" && src[i + 1] === "*") {
|
|
188
|
+
const e = src.indexOf("*/", i + 2);
|
|
189
|
+
const end = e < 0 ? n : e + 2;
|
|
190
|
+
blank(i, end);
|
|
191
|
+
i = end;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (i >= n) return -1;
|
|
195
|
+
if (src[i] === "/" && src[i + 1] === ">") {
|
|
196
|
+
attrs.push(...mine);
|
|
197
|
+
return i + 2;
|
|
198
|
+
}
|
|
199
|
+
if (src[i] === ">") {
|
|
200
|
+
attrs.push(...mine);
|
|
201
|
+
const hid = mine.some((a2) => a2.name === "aria-hidden" && a2.kind === "literal" && a2.value === "true" || a2.name === "hidden" && a2.kind === "flag");
|
|
202
|
+
if (hid) hiddenDepth++;
|
|
203
|
+
try {
|
|
204
|
+
return parseChildren(i + 1, tag, start);
|
|
205
|
+
} finally {
|
|
206
|
+
if (hid) hiddenDepth--;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (src[i] === "{") {
|
|
210
|
+
const j = parseJS(i + 1, "}");
|
|
211
|
+
if (j >= n) return -1;
|
|
212
|
+
i = j + 1;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const a = /^[A-Za-z_][\w:.-]*/.exec(src.slice(i, i + 60));
|
|
216
|
+
if (!a) return -1;
|
|
217
|
+
const name = a[0];
|
|
218
|
+
const at = i;
|
|
219
|
+
i += name.length;
|
|
220
|
+
while (i < n && /\s/.test(src[i])) i++;
|
|
221
|
+
if (src[i] !== "=") {
|
|
222
|
+
mine.push({ tag, name, at, kind: "flag" });
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
i++;
|
|
226
|
+
while (i < n && /\s/.test(src[i])) i++;
|
|
227
|
+
if (src[i] === '"' || src[i] === "'") {
|
|
228
|
+
const q = src[i];
|
|
229
|
+
const e = src.indexOf(q, i + 1);
|
|
230
|
+
if (e < 0) return -1;
|
|
231
|
+
mine.push({ tag, name, at, kind: "literal", value: src.slice(i + 1, e), vstart: i });
|
|
232
|
+
blank(i + 1, e, "_");
|
|
233
|
+
i = e + 1;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (src[i] === "{") {
|
|
237
|
+
const j = parseJS(i + 1, "}");
|
|
238
|
+
if (j >= n) return -1;
|
|
239
|
+
mine.push({ tag, name, at, kind: "expr", start: i + 1, end: j, value: src.slice(i + 1, j) });
|
|
240
|
+
i = j + 1;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
return -1;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function parseChildren(i, tag, openAt) {
|
|
247
|
+
let textStart = i;
|
|
248
|
+
const flush = (end) => {
|
|
249
|
+
const raw = src.slice(textStart, end);
|
|
250
|
+
if (raw.trim()) {
|
|
251
|
+
const lead = raw.length - raw.trimStart().length;
|
|
252
|
+
texts.push({ start: textStart + lead, value: raw.trim().replace(/\s+/g, " "), tag, hidden: hiddenDepth > 0 });
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
while (i < n) {
|
|
256
|
+
const c = src[i];
|
|
257
|
+
if (c === "{") {
|
|
258
|
+
flush(i);
|
|
259
|
+
const j = parseJS(i + 1, "}");
|
|
260
|
+
exprs.push({ start: i + 1, end: j, value: src.slice(i + 1, j), tag });
|
|
261
|
+
i = j + 1;
|
|
262
|
+
textStart = i;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (c === "<") {
|
|
266
|
+
if (src[i + 1] === "/") {
|
|
267
|
+
flush(i);
|
|
268
|
+
const e = src.indexOf(">", i);
|
|
269
|
+
return e < 0 ? n : e + 1;
|
|
270
|
+
}
|
|
271
|
+
flush(i);
|
|
272
|
+
const j = parseElement(i);
|
|
273
|
+
if (j < 0) {
|
|
274
|
+
i++;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
i = j;
|
|
278
|
+
textStart = i;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
i++;
|
|
282
|
+
}
|
|
283
|
+
void openAt;
|
|
284
|
+
return n;
|
|
285
|
+
}
|
|
286
|
+
parseJS(0, null);
|
|
287
|
+
return { texts, attrs, strings, exprs, mask: mask.join("") };
|
|
288
|
+
}
|
|
289
|
+
function matchBracket(mask, open) {
|
|
290
|
+
const pairs = { "{": "}", "(": ")", "[": "]" };
|
|
291
|
+
const stack = [];
|
|
292
|
+
for (let k = open; k < mask.length; k++) {
|
|
293
|
+
const c = mask[k];
|
|
294
|
+
if (pairs[c]) stack.push(pairs[c]);
|
|
295
|
+
else if (c === "}" || c === ")" || c === "]") {
|
|
296
|
+
if (stack.pop() !== c) return -1;
|
|
297
|
+
if (!stack.length) return k;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return -1;
|
|
301
|
+
}
|
|
302
|
+
function literalAt(src, i) {
|
|
303
|
+
const m = /^\s*(['"`])((?:\\.|(?!\1)[^\\\n])*)\1/.exec(src.slice(i, i + 4e3));
|
|
304
|
+
if (!m || m[1] === "`" && m[2].includes("${")) return null;
|
|
305
|
+
return m[2];
|
|
306
|
+
}
|
|
307
|
+
function definitions(src, mask) {
|
|
308
|
+
const out = [];
|
|
309
|
+
const re = /\bdefine(Section|Block)\s*\(\s*\{/g;
|
|
310
|
+
let m;
|
|
311
|
+
while (m = re.exec(mask)) {
|
|
312
|
+
const open = m.index + m[0].length - 1;
|
|
313
|
+
const close = matchBracket(mask, open);
|
|
314
|
+
if (close < 0) continue;
|
|
315
|
+
const body = mask.slice(open, close + 1);
|
|
316
|
+
const prop = (name) => {
|
|
317
|
+
const r = new RegExp(`[{,\\s]${name}\\s*:`, "g");
|
|
318
|
+
let p;
|
|
319
|
+
while (p = r.exec(body)) {
|
|
320
|
+
const at = open + p.index + p[0].length;
|
|
321
|
+
let depth = 0;
|
|
322
|
+
for (let k = open + 1; k < open + p.index + 1; k++) {
|
|
323
|
+
const c = mask[k];
|
|
324
|
+
if ("{([".includes(c)) depth++;
|
|
325
|
+
else if ("})]".includes(c)) depth--;
|
|
326
|
+
}
|
|
327
|
+
if (depth === 0) return at;
|
|
328
|
+
}
|
|
329
|
+
return -1;
|
|
330
|
+
};
|
|
331
|
+
const typeAt = prop("type");
|
|
332
|
+
const type = typeAt >= 0 ? literalAt(src, typeAt) : null;
|
|
333
|
+
const def = { kind: m[1] === "Section" ? "section" : "block", type, start: m.index, open, close, settings: [], has: {} };
|
|
334
|
+
for (const k of ["zone", "requires", "presets", "blocks", "component", "title"]) def.has[k] = prop(k) >= 0;
|
|
335
|
+
def.componentAt = def.has.component ? prop("component") : close;
|
|
336
|
+
const presetsAt = prop("presets");
|
|
337
|
+
if (presetsAt >= 0) {
|
|
338
|
+
const o = mask.indexOf("[", presetsAt);
|
|
339
|
+
const c = o >= 0 ? matchBracket(mask, o) : -1;
|
|
340
|
+
def.presets = c > 0 ? src.slice(o, c + 1) : "";
|
|
341
|
+
}
|
|
342
|
+
const blocksAt = prop("blocks");
|
|
343
|
+
if (blocksAt >= 0) {
|
|
344
|
+
const o = mask.indexOf("[", blocksAt);
|
|
345
|
+
const c = o >= 0 && o - blocksAt < 4 ? matchBracket(mask, o) : -1;
|
|
346
|
+
def.blocksList = c > 0 ? src.slice(o, c + 1) : "";
|
|
347
|
+
}
|
|
348
|
+
const settingsAt = prop("settings");
|
|
349
|
+
if (settingsAt >= 0) {
|
|
350
|
+
const o = mask.indexOf("{", settingsAt);
|
|
351
|
+
const c = o >= 0 && o - settingsAt < 4 ? matchBracket(mask, o) : -1;
|
|
352
|
+
if (c > 0) {
|
|
353
|
+
def.settingsRange = [o, c];
|
|
354
|
+
const fr = /([A-Za-z_$][\w$]*)\s*:\s*field\s*\.\s*(\w+)\s*\(/g;
|
|
355
|
+
const seg = mask.slice(o, c);
|
|
356
|
+
let f;
|
|
357
|
+
while (f = fr.exec(seg)) {
|
|
358
|
+
const callOpen = o + f.index + f[0].length - 1;
|
|
359
|
+
const callClose = matchBracket(mask, callOpen);
|
|
360
|
+
const args = callClose > 0 ? src.slice(callOpen + 1, callClose) : "";
|
|
361
|
+
const kind = f[2];
|
|
362
|
+
const dflt = kind === "resource" ? null : ["text", "textarea", "richtext", "url", "color"].includes(kind) ? literalAt(args, 0) : null;
|
|
363
|
+
def.settings.push({ key: f[1], kind, default: dflt, hasLabel: /\blabel\s*:/.test(args), at: o + f.index, resourceKind: kind === "resource" ? literalAt(args, 0) : null });
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
out.push(def);
|
|
368
|
+
}
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
function stemOf(key) {
|
|
372
|
+
let m = /^(first|second|third|fourth|fifth|sixth|seventh|eighth)([A-Z_]\w*)?$/.exec(key);
|
|
373
|
+
if (m) return `#${(m[2] || "").toLowerCase()}`;
|
|
374
|
+
m = /^([A-Za-z_]+?)_?(\d{1,2})([A-Z]\w*)?$/.exec(key);
|
|
375
|
+
if (m) return `${m[1].toLowerCase()}#${(m[3] || "").toLowerCase()}`;
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
function checkEditability2(files, opts = {}) {
|
|
379
|
+
const errors = [];
|
|
380
|
+
const warnings = [];
|
|
381
|
+
const add = (sev, code, file, src, at, message, fix) => {
|
|
382
|
+
const { line: line2, column } = lineCol(src, at);
|
|
383
|
+
const list = sev === "error" ? errors : warnings;
|
|
384
|
+
if (list.some((x) => x.code === code && x.file === file && x.line === line2 && x.column === column)) return;
|
|
385
|
+
list.push({ severity: sev, code, file, line: line2, column, message, ...fix ? { fix } : {} });
|
|
386
|
+
};
|
|
387
|
+
let en = opts.locales || null;
|
|
388
|
+
if (!en && typeof files["locales/en.json"] === "string") {
|
|
389
|
+
try {
|
|
390
|
+
en = JSON.parse(files["locales/en.json"]);
|
|
391
|
+
} catch {
|
|
392
|
+
en = null;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const flat = {};
|
|
396
|
+
const flatten = (o, p) => {
|
|
397
|
+
if (o && typeof o === "object") for (const [k, v] of Object.entries(o)) flatten(v, p ? `${p}.${k}` : k);
|
|
398
|
+
else if (typeof o === "string") flat[p] = o;
|
|
399
|
+
};
|
|
400
|
+
flatten(en, "");
|
|
401
|
+
const schemaLocale = (lang) => {
|
|
402
|
+
const t = files[`locales/${lang}.schema.json`];
|
|
403
|
+
if (typeof t !== "string") return null;
|
|
404
|
+
try {
|
|
405
|
+
const out = {};
|
|
406
|
+
const walk = (o, p) => {
|
|
407
|
+
if (o && typeof o === "object" && !Array.isArray(o)) for (const [k, v] of Object.entries(o)) walk(v, p ? `${p}.${k}` : k);
|
|
408
|
+
else if (typeof o === "string") out[p] = o;
|
|
409
|
+
};
|
|
410
|
+
walk(JSON.parse(t), "");
|
|
411
|
+
return out;
|
|
412
|
+
} catch {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const schemaEn = schemaLocale("en");
|
|
417
|
+
const labelScan = (file, src, ranges) => {
|
|
418
|
+
const found = [];
|
|
419
|
+
const re = /\b(label|title|description|info|placeholder|group)\s*:\s*(['"])((?:\\.|(?!\2)[^\\\n])*)\2/g;
|
|
420
|
+
let m;
|
|
421
|
+
while (m = re.exec(src)) if (ranges.some(([a, b]) => m.index > a && m.index < b)) found.push({ at: m.index + m[0].length - m[3].length - 1, value: m[3] });
|
|
422
|
+
const pre = /(presets\s*:\s*\[\s*\{|\}\s*,\s*\{)\s*name\s*:\s*(['"])((?:\\.|(?!\2)[^\\\n])*)\2/g;
|
|
423
|
+
while (m = pre.exec(src)) if (ranges.some(([a, b]) => m.index > a && m.index < b) && /presets\s*:/.test(src.slice(Math.max(0, m.index - 2e3), m.index + 12))) found.push({ at: m.index + m[0].length - m[3].length - 1, value: m[3] });
|
|
424
|
+
const ol = /optionLabels\s*:\s*\{([^}]*)\}/g;
|
|
425
|
+
while (m = ol.exec(src)) {
|
|
426
|
+
const inner = /:\s*(['"])((?:\\.|(?!\1)[^\\\n])*)\1/g;
|
|
427
|
+
let v;
|
|
428
|
+
while (v = inner.exec(m[1])) found.push({ at: m.index + m[0].indexOf(m[1]) + v.index + v[0].length - v[2].length - 1, value: v[2] });
|
|
429
|
+
}
|
|
430
|
+
let plain = null;
|
|
431
|
+
for (const f of found) {
|
|
432
|
+
if (f.value.startsWith("t:")) {
|
|
433
|
+
const key = f.value.slice(2);
|
|
434
|
+
if (!schemaEn) add("error", "missing_label_translation", file, src, f.at, `"${f.value}" needs locales/en.schema.json, which the theme does not have (or is not valid JSON).`, `Add locales/en.schema.json with the key ${key} (nested JSON, as the reference's schema locale files).`);
|
|
435
|
+
else if (typeof schemaEn[key] !== "string" || !schemaEn[key].trim()) add("error", "missing_label_translation", file, src, f.at, `"${f.value}" has no English words in locales/en.schema.json.`, `Add "${key}" to locales/en.schema.json.`);
|
|
436
|
+
} else if (f.value.trim() && !plain) plain = f;
|
|
437
|
+
}
|
|
438
|
+
if (plain) add("warning", "label_not_translated", file, src, plain.at, `Labels such as "${plain.value.slice(0, 40)}" are plain English, so a merchant using the editor in another language reads them in English.`, `Write labels as t:<key> (label: 't:labels.heading') with the words in locales/en.schema.json; other languages go in locales/<lang>.schema.json (optional).`);
|
|
439
|
+
};
|
|
440
|
+
if (typeof files["src/settings.ts"] === "string") labelScan("src/settings.ts", files["src/settings.ts"], [[0, files["src/settings.ts"].length]]);
|
|
441
|
+
const sections = [];
|
|
442
|
+
const paths = Object.keys(files || {}).filter((p) => /^src\/.+\.(tsx|jsx|ts)$/.test(p) && typeof files[p] === "string").sort();
|
|
443
|
+
for (const file of paths) {
|
|
444
|
+
const src = files[file];
|
|
445
|
+
const isSectionFile = /^src\/(sections|blocks)\//.test(file) || /\bdefine(Section|Block)\s*\(/.test(src);
|
|
446
|
+
const isMarkupFile = isSectionFile || /^src\/components\//.test(file);
|
|
447
|
+
if (!isMarkupFile || !/\.(tsx|jsx)$/.test(file) && !isSectionFile) continue;
|
|
448
|
+
const s = scan(src);
|
|
449
|
+
const defs = isSectionFile ? definitions(src, s.mask) : [];
|
|
450
|
+
const inConfig = (at) => defs.some((d) => d.settingsRange && at > d.settingsRange[0] && at < d.settingsRange[1]) || defs.some((d) => d.presets && at > d.open && at < d.close && src.slice(d.open, at).lastIndexOf("presets") > src.slice(d.open, at).lastIndexOf("component"));
|
|
451
|
+
const perSection = new Map(defs.filter((d) => d.kind === "section").map((d) => [d, { fixed: 0 }]));
|
|
452
|
+
const owner = (at) => {
|
|
453
|
+
let best = null;
|
|
454
|
+
for (const d of perSection.keys()) if (at >= d.start && at <= d.close) best = d;
|
|
455
|
+
if (!best && perSection.size === 1) best = [...perSection.keys()][0];
|
|
456
|
+
return best;
|
|
457
|
+
};
|
|
458
|
+
const bump = (at) => {
|
|
459
|
+
const d = owner(at);
|
|
460
|
+
if (d) perSection.get(d).fixed++;
|
|
461
|
+
};
|
|
462
|
+
for (const t of s.texts) {
|
|
463
|
+
if (!isWords(t.value)) continue;
|
|
464
|
+
if (SVG_TEXT.has(t.tag) || t.hidden) continue;
|
|
465
|
+
add("error", "literal_text", file, src, t.start, `"${t.value.slice(0, 60)}" is written in the section's code, so the merchant cannot change it in the theme editor.`, `Move it to a setting: heading: field.text(${JSON.stringify(t.value.slice(0, 60))}, { label: 'Heading' }), and render {settings.heading}. Interface words (a cart button, "Search") go through t('key') with the words in locales/en.json and locales/th.json.`);
|
|
466
|
+
bump(t.start);
|
|
467
|
+
}
|
|
468
|
+
for (const e of s.exprs) {
|
|
469
|
+
const v = e.value.trim();
|
|
470
|
+
const lit = /^(['"])(.*)\1$/s.exec(v) || /^`([^`$]*)`$/s.exec(v);
|
|
471
|
+
if (lit && isWords(lit[2] ?? lit[1])) {
|
|
472
|
+
add("error", "literal_text", file, src, e.start, `"${(lit[2] ?? lit[1]).slice(0, 60)}" is written in the section's code.`, "Move it to a text setting and render {settings.<key>}.");
|
|
473
|
+
bump(e.start);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
for (const a of s.attrs) {
|
|
477
|
+
const lit = a.kind === "literal" ? a.value : a.kind === "expr" ? (() => {
|
|
478
|
+
const v = a.value.trim();
|
|
479
|
+
const m = /^(['"])(.*)\1$/s.exec(v) || /^`([^`$]*)`$/s.exec(v);
|
|
480
|
+
return m ? m[2] ?? m[1] : null;
|
|
481
|
+
})() : null;
|
|
482
|
+
const at = a.kind === "literal" ? a.vstart : a.kind === "expr" ? a.start : a.at;
|
|
483
|
+
if (TEXT_ATTRS.has(a.name) && lit !== null && isWords(lit) && !FORMAT_EXAMPLE.test(lit)) {
|
|
484
|
+
add("error", "literal_text", file, src, at, `${a.name}="${lit.slice(0, 50)}" is written in the code.`, a.name === "alt" ? "Read it from the image's alt, or an imageAlt: field.text(...) setting beside the image." : "Interface words go through t('key') (locales/en.json and locales/th.json); shop copy goes in a text setting.");
|
|
485
|
+
bump(at);
|
|
486
|
+
}
|
|
487
|
+
if (LINK_ATTRS.has(a.name)) {
|
|
488
|
+
if (lit !== null && lit !== "" && !STRUCTURAL_LINK.test(lit)) {
|
|
489
|
+
add("error", "hardcoded_link", file, src, at, `href="${lit.slice(0, 60)}" is fixed in the code, so the merchant cannot point it somewhere else.`, `Add link: field.url(${JSON.stringify(lit)}, { label: 'Link' }) and use href={settings.link}. Links to a product, collection or page come from a resource setting (field.resource('product')) or a menu.`);
|
|
490
|
+
bump(at);
|
|
491
|
+
} else if (a.kind === "expr" && /(\|\||\?\?)\s*['"`][^'"`]*['"`]/.test(a.value) && /settings/.test(a.value)) {
|
|
492
|
+
const fb = /(\|\||\?\?)\s*(['"`])([^'"`]*)\2/.exec(a.value);
|
|
493
|
+
if (fb && fb[3] && !STRUCTURAL_LINK.test(fb[3])) {
|
|
494
|
+
add("error", "hidden_default", file, src, a.start, `This link falls back to "${fb[3]}" when its setting is empty, so the editor shows an empty field for a link that works.`, `Make "${fb[3]}" the setting's default (field.url(${JSON.stringify(fb[3])}, ...)) and use href={settings.<key>} alone.`);
|
|
495
|
+
bump(a.start);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (MEDIA_ATTRS.has(a.name) && lit !== null && lit.trim() !== "") {
|
|
500
|
+
add("error", "hardcoded_image", file, src, at, `${a.name}="${lit.slice(0, 60)}" is an image or video fixed in the code.`, "Add image: field.resource('image', '', { label: 'Image' }) and render <Image image={settings.image} alt={settings.imageAlt} />; upload the picture with theme_upload_asset and put its URL in the template's settings.");
|
|
501
|
+
bump(at);
|
|
502
|
+
}
|
|
503
|
+
if (a.name === "alt" && a.kind === "literal" && a.value === "" && a.tag === "Image") {
|
|
504
|
+
const near = src.slice(Math.max(0, a.at - 200), a.at + 200);
|
|
505
|
+
if (/image=\{\s*(settings|block|b)\b/.test(near)) add("warning", "image_alt", file, src, a.at, `A merchant's image is shown with alt="" and no way to describe it.`, "Add imageAlt: field.text('<what the picture shows>', { label: 'Image description' }) and pass alt={settings.imageAlt}.");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const lines = s.mask.split("\n");
|
|
509
|
+
const srcLines = src.split("\n");
|
|
510
|
+
let offset = 0;
|
|
511
|
+
for (let ln = 0; ln < lines.length; ln++) {
|
|
512
|
+
const codeLine = lines[ln];
|
|
513
|
+
const raw = srcLines[ln];
|
|
514
|
+
const patterns = [
|
|
515
|
+
/settings\??\.\s*\??\.?([A-Za-z_$][\w$]*)\b[^;\n]{0,60}?(\|\||\?\?)\s*(t\s*\(|['"`])/g,
|
|
516
|
+
/\b[A-Za-z_$][\w$]*\s*\(\s*(?:String\s*\(\s*)?(?:[\w$]+\.)?settings\??\.\s*([A-Za-z_$][\w$]*)[^,;\n()]*\)?\s*,\s*(t\s*\(|['"`])/g
|
|
517
|
+
];
|
|
518
|
+
for (const re of patterns) {
|
|
519
|
+
re.lastIndex = 0;
|
|
520
|
+
let m;
|
|
521
|
+
while (m = re.exec(codeLine)) {
|
|
522
|
+
const tail = raw.slice(m.index + m[0].length - m[m.length - 1].length);
|
|
523
|
+
const lit = /^(['"`])([^'"`]*)\1/.exec(tail);
|
|
524
|
+
const isT = /^t\s*\(/.test(tail);
|
|
525
|
+
if (!isT && !(lit && isWords(lit[2]))) continue;
|
|
526
|
+
if (!isT && /^[a-z0-9_-]+$/.test(lit[2])) continue;
|
|
527
|
+
if (!isT && /^(\/|#|https?:|mailto:|tel:)/.test(lit[2])) continue;
|
|
528
|
+
if (re === patterns[0] && /^(String|Number)\s*\(/.test(codeLine.slice(m.index - 7, m.index))) {
|
|
529
|
+
}
|
|
530
|
+
const words = isT ? flat[(/t\s*\(\s*['"]([^'"]+)/.exec(tail) || [])[1]] || "a locale string" : lit[2];
|
|
531
|
+
add("error", "hidden_default", file, src, offset + m.index, `When the merchant leaves "${m[1]}" empty the section shows "${String(words).slice(0, 50)}" instead, so the editor's field is empty while the page shows words the merchant cannot find.`, `Make it the setting's default: ${m[1]}: field.text(${JSON.stringify(String(words).slice(0, 60))}, { label: '\u2026' }), render {settings.${m[1]}} alone, and put the same words in the template's settings.`);
|
|
532
|
+
bump(offset + m.index);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
offset += raw.length + 1;
|
|
536
|
+
}
|
|
537
|
+
const arrays = [];
|
|
538
|
+
for (let k = 0; k < s.mask.length; k++) if (s.mask[k] === "[") {
|
|
539
|
+
const c = matchBracket(s.mask, k);
|
|
540
|
+
if (c > k) arrays.push([k, c]);
|
|
541
|
+
}
|
|
542
|
+
for (const [o, c] of arrays) {
|
|
543
|
+
if (inConfig(o)) continue;
|
|
544
|
+
if (arrays.some(([o2, c2]) => o2 < o && c2 > c)) continue;
|
|
545
|
+
const after = s.mask.slice(c + 1, c + 200);
|
|
546
|
+
let mapped = /^\s*(\.\s*\w+\s*\([^()]*\))*\s*\.\s*map\s*\(/.test(after);
|
|
547
|
+
if (!mapped) {
|
|
548
|
+
const before = s.mask.slice(Math.max(0, o - 60), o);
|
|
549
|
+
const nm = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]+)?=\s*$/.exec(before);
|
|
550
|
+
if (nm) mapped = new RegExp(`\\b${nm[1]}\\s*(\\.\\s*\\w+\\s*\\([^()]*\\))*\\s*\\.\\s*map\\s*\\(`).test(s.mask.slice(c));
|
|
551
|
+
}
|
|
552
|
+
if (!mapped) continue;
|
|
553
|
+
const inner = s.strings.filter((x) => x.start > o && x.end <= c + 1 && isWords(x.value) && (/[\s-]/.test(x.value) || /^[A-Z]/.test(x.value)));
|
|
554
|
+
const tCalls = (src.slice(o, c + 1).match(/\bt\s*\(\s*['"]/g) || []).length;
|
|
555
|
+
if (inner.length + tCalls >= 2) {
|
|
556
|
+
add("error", "hardcoded_list", file, src, o, `A list of ${inner.length + tCalls} items is written in the code and printed with .map(): the merchant cannot add, remove, reorder or change them.`, "Make each item a block: defineBlock({ type: 'item', title: 'Item', settings: { ... } }), add it to the section's blocks, render the section's blocks in order, and put the items in the preset and the template as blocks.");
|
|
557
|
+
bump(o);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
{
|
|
561
|
+
const re = /settings\??\.\s*([A-Za-z_$][\w$]*)[^;\n]{0,40}?\.split\s*\(\s*(['"`]\s*[,;|]|\/\s*\[?[,;|])/g;
|
|
562
|
+
let m;
|
|
563
|
+
while (m = re.exec(s.mask.replace(/_/g, ","))) {
|
|
564
|
+
if (/^(collections|products|pages|blogs|articles|menus|handles|tags)$/i.test(m[1])) continue;
|
|
565
|
+
add("error", "packed_list", file, src, m.index, `"${m[1]}" is a list typed into one field and split on commas: the merchant cannot add, remove or reorder its items, or give one its own link or image.`, `Make each item a block (defineBlock({ type: 'item', settings: { text: field.text(\u2026) } })) and render the section's blocks.`);
|
|
566
|
+
bump(m.index);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
for (const d of defs) {
|
|
570
|
+
const at = d.start;
|
|
571
|
+
if (d.kind === "section" && !d.has.presets && !d.has.zone && !d.has.requires && !TEMPLATE_SECTIONS.has(d.type || "")) {
|
|
572
|
+
add("error", "no_preset", file, src, at, `Section "${d.type}" has no preset, so the merchant cannot add it from "Add section".`, `presets: [{ name: '${d.type}', settings: { ...the sample content }${d.has.blocks ? ", blocks: [{ type: '\u2026', settings: {\u2026} }, \u2026]" : ""} }]`);
|
|
573
|
+
}
|
|
574
|
+
if (d.kind === "section" && d.has.blocks && d.blocksList && /\w/.test(d.blocksList) && d.has.presets && !/\bblocks\s*:/.test(d.presets || "")) {
|
|
575
|
+
add("error", "preset_without_blocks", file, src, at, `Section "${d.type}" takes blocks, but its preset adds none: a merchant who adds it gets an empty section.`, "Add the sample items to the preset: presets: [{ name: \u2026, blocks: [{ type: \u2026, settings: {\u2026} }, { \u2026 }, { \u2026 }] }]");
|
|
576
|
+
}
|
|
577
|
+
const stems = /* @__PURE__ */ new Map();
|
|
578
|
+
for (const st of d.settings) {
|
|
579
|
+
if (!st.hasLabel) add("error", "no_label", file, src, st.at, `Setting "${st.key}" has no label.`, `${st.key}: field.${st.kind}(\u2026, { label: '\u2026' })`);
|
|
580
|
+
const presetSets = d.presets && new RegExp(`\\b${st.key}\\s*:\\s*['"\`][^'"\`]`).test(d.presets);
|
|
581
|
+
if (["text", "textarea", "richtext"].includes(st.kind) && st.default === "" && CONTENT_KEY.test(st.key) && !presetSets) {
|
|
582
|
+
add(d.kind === "section" ? "error" : "warning", "empty_default", file, src, st.at, `Setting "${st.key}" is empty by default, so a newly added "${d.type}" shows nothing (or words from somewhere else).`, `Give it real sample words: ${st.key}: field.${st.kind}('\u2026', { label: '\u2026' }).`);
|
|
583
|
+
}
|
|
584
|
+
const stem = stemOf(st.key);
|
|
585
|
+
if (stem) stems.set(stem, [...stems.get(stem) || [], st]);
|
|
586
|
+
const outside = src.slice(0, d.settingsRange ? d.settingsRange[0] : 0) + src.slice(d.settingsRange ? d.settingsRange[1] : 0);
|
|
587
|
+
if (!KIT_SETTINGS.has(st.key) && !new RegExp(`(\\.|\\[\\s*['"])${st.key}\\b|\\b${st.key}\\s*[,}:]`).test(outside.replace(/presets\s*:[\s\S]*?\]\s*,/g, ""))) {
|
|
588
|
+
add("warning", "unused_setting", file, src, st.at, `Setting "${st.key}" of "${d.type}" is never read, so changing it in the editor changes nothing.`, `Render it, or remove it.`);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
for (const [, group] of stems) {
|
|
592
|
+
if (group.length >= 2) {
|
|
593
|
+
add("error", "repeated_settings", file, src, group[0].at, `Settings ${group.map((g) => `"${g.key}"`).join(", ")} are numbered copies of one item: the merchant cannot add a third, remove one or reorder them.`, "Make the item a block type with one set of these settings, list it in the section's blocks, and render the blocks in order.");
|
|
594
|
+
bump(group[0].at);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (defs.length) labelScan(file, src, defs.map((d) => [d.open, d.componentAt]));
|
|
599
|
+
if (isSectionFile) {
|
|
600
|
+
const tre = /\bt\s*\(\s*['"]([^'"]+)['"]/g;
|
|
601
|
+
let m;
|
|
602
|
+
while (m = tre.exec(src)) {
|
|
603
|
+
const v = flat[m[1]];
|
|
604
|
+
if (typeof v === "string" && v.split(/\s+/).length >= 8 && !CHROME_KEY.test(m[1])) {
|
|
605
|
+
add("warning", "locale_prose", file, src, m.index, `"${v.slice(0, 50)}\u2026" (${m[1]}) is shop copy kept in the locale files; the merchant edits it only through translations, not in the theme editor.`, "Make it a setting with these words as the default.");
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
for (const [d, v] of perSection) {
|
|
610
|
+
const visible = d.settings.filter((x) => ["text", "textarea", "richtext", "url", "color", "resource"].includes(x.kind)).length;
|
|
611
|
+
sections.push({ file, type: d.type, line: lineCol(src, d.start).line, settings: d.settings.length, editable: visible, fixed: v.fixed, blocks: d.has.blocks, presets: d.has.presets });
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
for (const file of Object.keys(files || {}).filter((p) => /^(templates|regions|groups)\/[^/]+\.json$/.test(p) && typeof files[p] === "string").sort()) {
|
|
615
|
+
let doc;
|
|
616
|
+
try {
|
|
617
|
+
doc = JSON.parse(files[file]);
|
|
618
|
+
} catch {
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
const seen = /* @__PURE__ */ new Set();
|
|
622
|
+
const visit = (node) => {
|
|
623
|
+
if (!node || typeof node !== "object") return;
|
|
624
|
+
if (Array.isArray(node)) {
|
|
625
|
+
node.forEach(visit);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
const st = node.settings;
|
|
629
|
+
if (st && typeof st === "object" && !Array.isArray(st) && node.type) {
|
|
630
|
+
const vals = Object.values(st).filter((v) => typeof v === "string");
|
|
631
|
+
const link = vals.find((v) => /^\/products\/[\w-]+\/?$/.test(v));
|
|
632
|
+
const words = vals.some((v) => !/^(\/|https?:|#)/.test(v) && isWords(v));
|
|
633
|
+
if (link && words && !seen.has(node.type)) {
|
|
634
|
+
seen.add(node.type);
|
|
635
|
+
const at = files[file].indexOf(JSON.stringify(link).slice(0, -1));
|
|
636
|
+
add("error", "product_by_hand", file, files[file], Math.max(0, at), `"${node.type}" names a product by hand (${link}) with its own title and picture: the price, stock and picture are not the store's and change nowhere when the product does.`, `Give "${node.type}" a product setting (product: field.resource('product', '', { label: 'Product' })) and show the product's own title, price and image with useProduct(settings.product); for a row of products use a collection setting.`);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
for (const v of Object.values(node)) if (v && typeof v === "object") visit(v);
|
|
640
|
+
};
|
|
641
|
+
visit(doc);
|
|
642
|
+
}
|
|
643
|
+
if (typeof files["src/settings.ts"] === "string" && !/type\s*:\s*['"]color['"]|field\s*\.\s*color\s*\(/.test(files["src/settings.ts"])) {
|
|
644
|
+
add("error", "no_colour_settings", "src/settings.ts", files["src/settings.ts"], 0, "The theme declares no colour setting, so the merchant cannot change its colours in the editor's Theme panel.", "Add colour settings (colorBackground: { type: 'color', label: 'Background', default: '#ffffff' }, text, accent) and turn them into CSS variables on the page's root with sx() (see the starter's theme.tsx themeVars); read every colour in theme.css from those variables.");
|
|
645
|
+
}
|
|
646
|
+
const editable = sections.reduce((a, x) => a + x.editable, 0);
|
|
647
|
+
const fixed = sections.reduce((a, x) => a + x.fixed, 0);
|
|
648
|
+
const ok = errors.length === 0;
|
|
649
|
+
return {
|
|
650
|
+
ok,
|
|
651
|
+
errors,
|
|
652
|
+
warnings,
|
|
653
|
+
sections,
|
|
654
|
+
score: { editable, fixed, percent: editable + fixed ? Math.round(100 * editable / (editable + fixed)) : 100 },
|
|
655
|
+
summary: ok ? `Editable: every section's words, images and links come from settings or blocks (${editable} settings${warnings.length ? `, ${warnings.length} warning${warnings.length === 1 ? "" : "s"}` : ""}).` : `${errors.length} place${errors.length === 1 ? "" : "s"} where the merchant cannot edit what the shopper sees (${fixed} fixed values against ${editable} settings).`
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
var IMAGE_KEY = /image|img|photo|picture|background|logo|poster|banner|cover|thumbnail|avatar|icon|src/i;
|
|
659
|
+
var IMAGE_EXT = /\.(png|jpe?g|webp|gif|avif|svg)(\?[^#]*)?$/i;
|
|
660
|
+
var STORE_HOST = /(^|\.)(tanqory\.(com|dev)|mytanqory\.(com|dev))$/i;
|
|
661
|
+
async function checkImageLinks2(files, opts = {}) {
|
|
662
|
+
const fetchImpl = opts.fetch || globalThis.fetch;
|
|
663
|
+
const timeoutMs = opts.timeoutMs || 8e3;
|
|
664
|
+
const max = opts.max || 60;
|
|
665
|
+
const concurrency = opts.concurrency || 6;
|
|
666
|
+
const errors = [];
|
|
667
|
+
const warnings = [];
|
|
668
|
+
const found = /* @__PURE__ */ new Map();
|
|
669
|
+
const note = (url, file, src) => {
|
|
670
|
+
if (!found.has(url) && found.size < max) found.set(url, { file, src, at: Math.max(0, src.indexOf(url)) });
|
|
671
|
+
};
|
|
672
|
+
for (const [file, text] of Object.entries(files || {}).sort()) {
|
|
673
|
+
if (typeof text !== "string") continue;
|
|
674
|
+
if (/^(templates|regions|groups)\/[^/]+\.json$|^config\/settings\.json$/.test(file)) {
|
|
675
|
+
let doc;
|
|
676
|
+
try {
|
|
677
|
+
doc = JSON.parse(text);
|
|
678
|
+
} catch {
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
const walk = (v, key) => {
|
|
682
|
+
if (typeof v === "string") {
|
|
683
|
+
if (/^https?:\/\//i.test(v) && (IMAGE_KEY.test(key || "") || IMAGE_EXT.test(v))) note(v, file, text);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
if (Array.isArray(v)) {
|
|
687
|
+
v.forEach((x) => walk(x, key));
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, k);
|
|
691
|
+
};
|
|
692
|
+
walk(doc, "");
|
|
693
|
+
} else if (/^src\/.+\.(tsx|ts|jsx|js)$/.test(file)) {
|
|
694
|
+
const re = /(['"`])(https?:\/\/[^'"`\s]+?\.(?:png|jpe?g|webp|gif|avif|svg)(?:\?[^'"`\s]*)?)\1/gi;
|
|
695
|
+
let m;
|
|
696
|
+
while (m = re.exec(text)) note(m[2], file, text);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const ask = async (url) => {
|
|
700
|
+
const go = async (method) => {
|
|
701
|
+
const ctl = new AbortController();
|
|
702
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
703
|
+
try {
|
|
704
|
+
return await fetchImpl(url, { method, redirect: "follow", signal: ctl.signal, headers: method === "GET" ? { range: "bytes=0-0" } : {} });
|
|
705
|
+
} finally {
|
|
706
|
+
clearTimeout(timer);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
try {
|
|
710
|
+
let r = await go("HEAD");
|
|
711
|
+
if (!r.ok) r = await go("GET");
|
|
712
|
+
const type = r.headers && typeof r.headers.get === "function" && r.headers.get("content-type") || "";
|
|
713
|
+
if (!r.ok) return { ok: false, why: `answers ${r.status}` };
|
|
714
|
+
if (type && !/^(image|video)\//i.test(type) && !/octet-stream/i.test(type)) return { ok: false, why: `is ${type.split(";")[0]}, not an image` };
|
|
715
|
+
return { ok: true };
|
|
716
|
+
} catch (e) {
|
|
717
|
+
return { ok: false, why: e && e.name === "AbortError" ? `did not answer within ${timeoutMs / 1e3} s` : "could not be reached" };
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
const list = [...found.entries()];
|
|
721
|
+
for (let i = 0; i < list.length; i += concurrency) {
|
|
722
|
+
await Promise.all(list.slice(i, i + concurrency).map(async ([url, where]) => {
|
|
723
|
+
const { line: line2, column } = lineCol(where.src, where.at);
|
|
724
|
+
const r = await ask(url);
|
|
725
|
+
let host = "";
|
|
726
|
+
try {
|
|
727
|
+
host = new URL(url).hostname;
|
|
728
|
+
} catch {
|
|
729
|
+
}
|
|
730
|
+
if (!r.ok) errors.push({ severity: "error", code: "image_not_found", file: where.file, line: line2, column, message: `The image ${url.slice(0, 100)} ${r.why}: the page would show an empty frame.`, fix: "Never guess an image address. Upload the picture with theme_upload_asset (or choose one of the store's files) and use the URL it returns." });
|
|
731
|
+
else if (!STORE_HOST.test(host)) warnings.push({ severity: "warning", code: "image_external", file: where.file, line: line2, column, message: `The image ${url.slice(0, 100)} is on another site (${host}): it can change or disappear.`, fix: "Upload it with theme_upload_asset and use the store file URL it returns." });
|
|
732
|
+
}));
|
|
733
|
+
}
|
|
734
|
+
const sort = (a, b) => (a.file + a.line).localeCompare(b.file + b.line);
|
|
735
|
+
errors.sort(sort);
|
|
736
|
+
warnings.sort(sort);
|
|
737
|
+
return { ok: errors.length === 0, errors, warnings, checked: list.length };
|
|
738
|
+
}
|
|
739
|
+
function formatEditability(result) {
|
|
740
|
+
return [...result.errors, ...result.warnings].map((f) => `${f.file}:${f.line}:${f.column} ${f.severity} ${f.code} ${f.message}${f.fix ? ` Fix: ${f.fix}` : ""}`).join("\n");
|
|
741
|
+
}
|
|
742
|
+
module2.exports = { checkEditability: checkEditability2, checkImageLinks: checkImageLinks2, formatEditability, scanTsx: scan, STRUCTURAL_LINK };
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
// ../../apps/build-service/src/review/partner-source.ts
|
|
747
|
+
var partner_source_exports = {};
|
|
748
|
+
__export(partner_source_exports, {
|
|
749
|
+
checkPartnerSource: () => checkPartnerSource,
|
|
750
|
+
editabilityLine: () => editabilityLine
|
|
751
|
+
});
|
|
752
|
+
module.exports = __toCommonJS(partner_source_exports);
|
|
753
|
+
var import_node_fs4 = require("node:fs");
|
|
754
|
+
var import_node_path4 = require("node:path");
|
|
755
|
+
var import_node_stream = require("node:stream");
|
|
756
|
+
var import_theme_abi2 = require("@tanqory/theme-abi");
|
|
757
|
+
var import_editability = __toESM(require_editability());
|
|
758
|
+
|
|
759
|
+
// ../../apps/build-service/src/artifact/digest.ts
|
|
760
|
+
var import_node_crypto = require("node:crypto");
|
|
761
|
+
var SHA256_HEX_RE = /^[0-9a-f]{64}$/;
|
|
762
|
+
function sha256Hex(bytes) {
|
|
763
|
+
return (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
|
|
764
|
+
}
|
|
765
|
+
function sha256Digest(bytes) {
|
|
766
|
+
return `sha256:${sha256Hex(bytes)}`;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// ../../apps/build-service/src/artifact/sbom.ts
|
|
770
|
+
var import_yaml = require("yaml");
|
|
771
|
+
|
|
772
|
+
// ../../apps/build-service/src/artifact/canonical-json.ts
|
|
773
|
+
var jcs = require("@tanqory/theme-abi/jcs");
|
|
774
|
+
var CanonicalJsonError = jcs.CanonicalJsonError;
|
|
775
|
+
var CANONICAL_JSON_MAX_DEPTH = jcs.CANONICAL_JSON_MAX_DEPTH;
|
|
776
|
+
function canonicalize(value) {
|
|
777
|
+
return jcs.canonicalJson(value);
|
|
778
|
+
}
|
|
779
|
+
function canonicalJsonFile(value) {
|
|
780
|
+
return Buffer.from(canonicalize(value) + "\n", "utf8");
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// ../../apps/build-service/src/artifact/sbom.ts
|
|
784
|
+
var CYCLONEDX_SPEC_VERSION = "1.6";
|
|
785
|
+
var LockfileParseError = class extends Error {
|
|
786
|
+
constructor() {
|
|
787
|
+
super(...arguments);
|
|
788
|
+
this.name = "LockfileParseError";
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
function splitPackageKey(key) {
|
|
792
|
+
const at = key.lastIndexOf("@");
|
|
793
|
+
if (at <= 0) throw new LockfileParseError(`unparseable package key: ${key}`);
|
|
794
|
+
return { name: key.slice(0, at), version: key.slice(at + 1) };
|
|
795
|
+
}
|
|
796
|
+
var DEPENDENCY_PATH_RE = /^(?:@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*@/i;
|
|
797
|
+
var packageIdOf = (path) => {
|
|
798
|
+
const paren = path.indexOf("(");
|
|
799
|
+
return paren >= 0 ? path.slice(0, paren) : path;
|
|
800
|
+
};
|
|
801
|
+
function pnpmShippedIds(lockfileVersion, importer, rawSnapshots, rawPackages) {
|
|
802
|
+
const major = Number.parseInt(lockfileVersion, 10);
|
|
803
|
+
if (!Number.isFinite(major) || major < 9) return null;
|
|
804
|
+
const ids = Object.keys(rawPackages);
|
|
805
|
+
if (ids.length === 0) return /* @__PURE__ */ new Set();
|
|
806
|
+
if (!rawSnapshots || typeof rawSnapshots !== "object") return null;
|
|
807
|
+
const snapshots = rawSnapshots;
|
|
808
|
+
const pathOf = (name, version) => DEPENDENCY_PATH_RE.test(version) ? version : `${name}@${version}`;
|
|
809
|
+
const stack = [];
|
|
810
|
+
for (const section of ["dependencies", "optionalDependencies"]) {
|
|
811
|
+
const deps = importer[section] ?? {};
|
|
812
|
+
for (const [name, spec] of Object.entries(deps))
|
|
813
|
+
stack.push(pathOf(name, typeof spec === "string" ? spec : String(spec?.version ?? "")));
|
|
814
|
+
}
|
|
815
|
+
const known = new Set(ids);
|
|
816
|
+
const seen = /* @__PURE__ */ new Set();
|
|
817
|
+
while (stack.length > 0) {
|
|
818
|
+
const path = stack.pop();
|
|
819
|
+
if (seen.has(path)) continue;
|
|
820
|
+
seen.add(path);
|
|
821
|
+
if (!Object.prototype.hasOwnProperty.call(snapshots, path)) {
|
|
822
|
+
if (known.has(packageIdOf(path))) return null;
|
|
823
|
+
continue;
|
|
824
|
+
}
|
|
825
|
+
const entry = snapshots[path] ?? {};
|
|
826
|
+
for (const section of ["dependencies", "optionalDependencies"])
|
|
827
|
+
for (const [name, version] of Object.entries(entry[section] ?? {}))
|
|
828
|
+
stack.push(pathOf(name, String(version)));
|
|
829
|
+
}
|
|
830
|
+
return new Set([...seen].map(packageIdOf));
|
|
831
|
+
}
|
|
832
|
+
function parsePnpmLockfile(bytes) {
|
|
833
|
+
let doc;
|
|
834
|
+
try {
|
|
835
|
+
doc = (0, import_yaml.parse)(Buffer.from(bytes).toString("utf8"));
|
|
836
|
+
} catch (e) {
|
|
837
|
+
throw new LockfileParseError(`pnpm-lock.yaml is not valid YAML: ${e.message}`);
|
|
838
|
+
}
|
|
839
|
+
if (!doc || typeof doc !== "object")
|
|
840
|
+
throw new LockfileParseError("pnpm-lock.yaml is not a mapping");
|
|
841
|
+
const root = doc;
|
|
842
|
+
const lockfileVersion = String(root["lockfileVersion"] ?? "");
|
|
843
|
+
if (!lockfileVersion) throw new LockfileParseError("pnpm-lock.yaml has no lockfileVersion");
|
|
844
|
+
const rawPackages = root["packages"] ?? {};
|
|
845
|
+
const importers = root["importers"] ?? {};
|
|
846
|
+
const importer = importers["."] ?? {};
|
|
847
|
+
const shipped = pnpmShippedIds(lockfileVersion, importer, root["snapshots"], rawPackages);
|
|
848
|
+
const packages = [];
|
|
849
|
+
for (const [key, entry] of Object.entries(rawPackages)) {
|
|
850
|
+
const { name, version } = splitPackageKey(key);
|
|
851
|
+
const resolution = entry?.["resolution"] ?? {};
|
|
852
|
+
packages.push({
|
|
853
|
+
name,
|
|
854
|
+
version,
|
|
855
|
+
...typeof resolution["integrity"] === "string" ? { integrity: resolution["integrity"] } : {},
|
|
856
|
+
...typeof resolution["tarball"] === "string" ? { tarball: resolution["tarball"] } : {},
|
|
857
|
+
...shipped && !shipped.has(key) ? { dev: true } : {}
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
const rootDependencies = {};
|
|
861
|
+
for (const section of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
862
|
+
const deps = importer[section] ?? {};
|
|
863
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
864
|
+
rootDependencies[name] = typeof spec === "string" ? spec : String(spec.version ?? "");
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
const importerDependencies = [];
|
|
868
|
+
for (const [importerName, imp] of Object.entries(importers)) {
|
|
869
|
+
for (const section of [
|
|
870
|
+
"dependencies",
|
|
871
|
+
"optionalDependencies",
|
|
872
|
+
"devDependencies",
|
|
873
|
+
"peerDependencies"
|
|
874
|
+
]) {
|
|
875
|
+
const deps = (imp ?? {})[section] ?? {};
|
|
876
|
+
for (const [name, spec] of Object.entries(deps))
|
|
877
|
+
importerDependencies.push({
|
|
878
|
+
importer: importerName,
|
|
879
|
+
section,
|
|
880
|
+
name,
|
|
881
|
+
specifier: typeof spec === "string" ? "" : String(spec?.specifier ?? ""),
|
|
882
|
+
version: typeof spec === "string" ? spec : String(spec?.version ?? "")
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
const snapshots = [];
|
|
887
|
+
const rawSnapshots = root["snapshots"] ?? {};
|
|
888
|
+
for (const [key, entry] of Object.entries(rawSnapshots)) {
|
|
889
|
+
const dependencies = [];
|
|
890
|
+
for (const section of ["dependencies", "optionalDependencies"]) {
|
|
891
|
+
const deps = (entry ?? {})[section] ?? {};
|
|
892
|
+
for (const [name, version] of Object.entries(deps))
|
|
893
|
+
dependencies.push({ name, version: String(version) });
|
|
894
|
+
}
|
|
895
|
+
snapshots.push({ key, dependencies });
|
|
896
|
+
}
|
|
897
|
+
packages.sort((a, b) => (a.name + "@" + a.version).localeCompare(b.name + "@" + b.version));
|
|
898
|
+
return { lockfileVersion, packages, rootDependencies, importerDependencies, snapshots };
|
|
899
|
+
}
|
|
900
|
+
var INTEGRITY_ALG = {
|
|
901
|
+
sha512: "SHA-512",
|
|
902
|
+
sha384: "SHA-384",
|
|
903
|
+
sha256: "SHA-256",
|
|
904
|
+
sha1: "SHA-1"
|
|
905
|
+
};
|
|
906
|
+
function integrityToHash(integrity) {
|
|
907
|
+
const dash = integrity.indexOf("-");
|
|
908
|
+
if (dash < 0) return void 0;
|
|
909
|
+
const alg = INTEGRITY_ALG[integrity.slice(0, dash)];
|
|
910
|
+
if (!alg) return void 0;
|
|
911
|
+
return { alg, content: Buffer.from(integrity.slice(dash + 1), "base64").toString("hex") };
|
|
912
|
+
}
|
|
913
|
+
function purlOf(name, version) {
|
|
914
|
+
if (name.startsWith("@")) {
|
|
915
|
+
const slash = name.indexOf("/");
|
|
916
|
+
return `pkg:npm/${encodeURIComponent(name.slice(1, slash))}/${name.slice(slash + 1)}@${version}`;
|
|
917
|
+
}
|
|
918
|
+
return `pkg:npm/${name}@${version}`;
|
|
919
|
+
}
|
|
920
|
+
function buildCycloneDxSbom(input) {
|
|
921
|
+
const components = input.lockfile.packages.map((p) => {
|
|
922
|
+
const hash = p.integrity ? integrityToHash(p.integrity) : void 0;
|
|
923
|
+
return {
|
|
924
|
+
type: "library",
|
|
925
|
+
name: p.name,
|
|
926
|
+
version: p.version,
|
|
927
|
+
purl: purlOf(p.name, p.version),
|
|
928
|
+
"bom-ref": purlOf(p.name, p.version),
|
|
929
|
+
...hash ? { hashes: [hash] } : {},
|
|
930
|
+
// CycloneDX 1.6 `component.scope` (bom-1.6.schema.json): "excluded" documents "component usage for test and
|
|
931
|
+
// other non-runtime purposes. Excluded components are not reachable within a call graph at runtime"; absent
|
|
932
|
+
// means "required". Only a dev-only package carries it, so an SBOM of a lockfile with none is byte-identical
|
|
933
|
+
// to before (DECISIONS row 185).
|
|
934
|
+
...p.dev ? { scope: "excluded" } : {}
|
|
935
|
+
};
|
|
936
|
+
}).sort((a, b) => a.purl < b.purl ? -1 : a.purl > b.purl ? 1 : 0);
|
|
937
|
+
const direct = Object.entries(input.lockfile.rootDependencies).map(([name, version]) => purlOf(name, version)).sort();
|
|
938
|
+
return {
|
|
939
|
+
bomFormat: "CycloneDX",
|
|
940
|
+
specVersion: CYCLONEDX_SPEC_VERSION,
|
|
941
|
+
version: 1,
|
|
942
|
+
metadata: {
|
|
943
|
+
component: {
|
|
944
|
+
type: "application",
|
|
945
|
+
name: input.themeName,
|
|
946
|
+
version: input.themeVersion,
|
|
947
|
+
"bom-ref": "theme",
|
|
948
|
+
properties: [
|
|
949
|
+
{ name: "tq:inputDigest", value: input.inputDigest },
|
|
950
|
+
{ name: "tq:sourceDigest", value: input.sourceDigest }
|
|
951
|
+
]
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
components,
|
|
955
|
+
dependencies: [{ ref: "theme", dependsOn: direct }]
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
function serializeSbom(input) {
|
|
959
|
+
return canonicalJsonFile(buildCycloneDxSbom(input));
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// shim:api-core-shim
|
|
963
|
+
var ApiException = class extends Error {
|
|
964
|
+
constructor(errorCode, options = {}) {
|
|
965
|
+
super(options.message || String(errorCode));
|
|
966
|
+
const code = String(errorCode).toLowerCase().replace(/\s+/g, "_");
|
|
967
|
+
const status = options.httpStatus ?? 500;
|
|
968
|
+
this.errorCode = code;
|
|
969
|
+
this.httpStatus = status;
|
|
970
|
+
this.param = options.param;
|
|
971
|
+
this.details = options.details;
|
|
972
|
+
this.errorType = status >= 500 ? "api_error" : "invalid_request_error";
|
|
973
|
+
this.response = { error: { type: this.errorType, code, message: this.message, status, param: options.param, details: options.details } };
|
|
974
|
+
}
|
|
975
|
+
getStatus() {
|
|
976
|
+
return this.httpStatus;
|
|
977
|
+
}
|
|
978
|
+
getResponse() {
|
|
979
|
+
return this.response;
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
// ../../apps/build-service/src/common/errors/build-service-errors.ts
|
|
984
|
+
var BuildServiceError = class extends ApiException {
|
|
985
|
+
constructor(type, code, status, message, details) {
|
|
986
|
+
super(code, { message, httpStatus: status, ...details ? { details: { ...details } } : {} });
|
|
987
|
+
this.name = "BuildServiceError";
|
|
988
|
+
const body = this.getResponse();
|
|
989
|
+
body.error.type = type;
|
|
990
|
+
this.errorType = type;
|
|
991
|
+
this.message = message;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
var IngestRejectedError = class extends BuildServiceError {
|
|
995
|
+
constructor(kind, message, path, extra, code = "ingest_rejected") {
|
|
996
|
+
super("invalid_request_error", code, 422, message, {
|
|
997
|
+
kind,
|
|
998
|
+
...path !== void 0 ? { path } : {},
|
|
999
|
+
...extra
|
|
1000
|
+
});
|
|
1001
|
+
this.kind = kind;
|
|
1002
|
+
this.path = path;
|
|
1003
|
+
this.name = "IngestRejectedError";
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
var PathCollisionError = class extends IngestRejectedError {
|
|
1007
|
+
constructor(message, paths) {
|
|
1008
|
+
super(
|
|
1009
|
+
"params",
|
|
1010
|
+
message,
|
|
1011
|
+
paths[1],
|
|
1012
|
+
{ paths: [...paths], collidesWith: paths[0] },
|
|
1013
|
+
"path_collision"
|
|
1014
|
+
);
|
|
1015
|
+
this.paths = paths;
|
|
1016
|
+
this.name = "PathCollisionError";
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
var UnsafeArchiveError = class extends IngestRejectedError {
|
|
1020
|
+
constructor(message, path) {
|
|
1021
|
+
super("archive", message, path);
|
|
1022
|
+
this.name = "UnsafeArchiveError";
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
// ../../apps/build-service/src/config/mirror-allowlist.ts
|
|
1027
|
+
var import_node_fs = require("node:fs");
|
|
1028
|
+
var import_node_path = require("node:path");
|
|
1029
|
+
var NAME_RE = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
1030
|
+
var VERSION_RE = /^(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})$/;
|
|
1031
|
+
var RANGE_RE = /^([\^~]?)((?:0|[1-9]\d{0,8})\.(?:0|[1-9]\d{0,8})\.(?:0|[1-9]\d{0,8}))$/;
|
|
1032
|
+
var INTEGRITY_RE = /^sha512-[A-Za-z0-9+/]{86}==$/;
|
|
1033
|
+
function parseExactVersion(version) {
|
|
1034
|
+
const m = VERSION_RE.exec(version);
|
|
1035
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
1036
|
+
}
|
|
1037
|
+
var compare = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
1038
|
+
function versionSatisfies(version, range) {
|
|
1039
|
+
const v = parseExactVersion(version);
|
|
1040
|
+
const r = RANGE_RE.exec(range);
|
|
1041
|
+
if (!v || !r) return false;
|
|
1042
|
+
const base = parseExactVersion(r[2]);
|
|
1043
|
+
if (compare(v, base) < 0) return false;
|
|
1044
|
+
switch (r[1]) {
|
|
1045
|
+
case "":
|
|
1046
|
+
return compare(v, base) === 0;
|
|
1047
|
+
case "~":
|
|
1048
|
+
return v[0] === base[0] && v[1] === base[1];
|
|
1049
|
+
default:
|
|
1050
|
+
if (base[0] > 0) return v[0] === base[0];
|
|
1051
|
+
if (base[1] > 0) return v[0] === 0 && v[1] === base[1];
|
|
1052
|
+
return compare(v, base) === 0;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
function parseMirrorAllowlist(raw, where = "mirror allowlist") {
|
|
1056
|
+
const fail = (message) => {
|
|
1057
|
+
throw new Error(`${where}: ${message}`);
|
|
1058
|
+
};
|
|
1059
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1060
|
+
if (!isRecord(raw)) return fail("the file must be a JSON object");
|
|
1061
|
+
for (const key of Object.keys(raw))
|
|
1062
|
+
if (key !== "$comment" && key !== "packages") fail(`unknown member ${JSON.stringify(key)}`);
|
|
1063
|
+
const list = raw["packages"];
|
|
1064
|
+
if (!isRecord(list))
|
|
1065
|
+
return fail(
|
|
1066
|
+
'"packages" must be an object of name \u2192 { range, versions } (names alone pin nothing)'
|
|
1067
|
+
);
|
|
1068
|
+
const packages = /* @__PURE__ */ new Map();
|
|
1069
|
+
for (const [name, entry] of Object.entries(list)) {
|
|
1070
|
+
const at = `packages[${JSON.stringify(name)}]`;
|
|
1071
|
+
if (!NAME_RE.test(name)) fail(`${at}: not a package name`);
|
|
1072
|
+
if (!isRecord(entry)) return fail(`${at} must be { range, versions }`);
|
|
1073
|
+
for (const key of Object.keys(entry))
|
|
1074
|
+
if (key !== "range" && key !== "versions")
|
|
1075
|
+
fail(`${at}: unknown member ${JSON.stringify(key)}`);
|
|
1076
|
+
const range = entry["range"];
|
|
1077
|
+
if (typeof range !== "string" || !RANGE_RE.test(range))
|
|
1078
|
+
return fail(`${at}.range must be X.Y.Z, ^X.Y.Z or ~X.Y.Z`);
|
|
1079
|
+
const listed = entry["versions"];
|
|
1080
|
+
if (!isRecord(listed) || Object.keys(listed).length === 0)
|
|
1081
|
+
return fail(`${at}.versions must list at least one version with its integrity`);
|
|
1082
|
+
const versions = /* @__PURE__ */ new Map();
|
|
1083
|
+
for (const [version, integrity] of Object.entries(listed)) {
|
|
1084
|
+
if (!parseExactVersion(version))
|
|
1085
|
+
fail(`${at}.versions: ${JSON.stringify(version)} is not X.Y.Z`);
|
|
1086
|
+
if (!versionSatisfies(version, range))
|
|
1087
|
+
fail(`${at}.versions: ${version} does not satisfy the entry's range ${range}`);
|
|
1088
|
+
if (typeof integrity !== "string" || !INTEGRITY_RE.test(integrity))
|
|
1089
|
+
return fail(`${at}.versions[${version}] must be a sha512 integrity (sha512-<base64>)`);
|
|
1090
|
+
versions.set(version, integrity);
|
|
1091
|
+
}
|
|
1092
|
+
packages.set(name, { range, versions });
|
|
1093
|
+
}
|
|
1094
|
+
return { packages };
|
|
1095
|
+
}
|
|
1096
|
+
function loadMirrorAllowlist(path = (0, import_node_path.join)(__dirname, "..", "..", "config", "mirror-allowlist.json")) {
|
|
1097
|
+
return parseMirrorAllowlist(JSON.parse((0, import_node_fs.readFileSync)(path, "utf8")), `mirror allowlist ${path}`);
|
|
1098
|
+
}
|
|
1099
|
+
function allowlistProblem(allowlist, name, version, integrity) {
|
|
1100
|
+
const entry = allowlist.packages.get(name);
|
|
1101
|
+
if (!entry) return "is not on the mirror allowlist";
|
|
1102
|
+
const pinned = entry.versions.get(version);
|
|
1103
|
+
if (pinned === void 0)
|
|
1104
|
+
return versionSatisfies(version, entry.range) ? `is within the allowlisted range ${entry.range} but that version has no pinned integrity (allowlisted: ${[...entry.versions.keys()].join(", ")})` : `is outside the allowlisted range ${entry.range}`;
|
|
1105
|
+
if (!integrity) return "has no resolution.integrity";
|
|
1106
|
+
if (integrity !== pinned)
|
|
1107
|
+
return `has resolution.integrity ${integrity}, not the one pinned on the mirror allowlist for that version`;
|
|
1108
|
+
return void 0;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// ../../apps/build-service/src/config/third-party.ts
|
|
1112
|
+
var import_node_fs2 = require("node:fs");
|
|
1113
|
+
var import_node_path2 = require("node:path");
|
|
1114
|
+
|
|
1115
|
+
// ../../apps/build-service/src/config/first-party-themes.ts
|
|
1116
|
+
var FIRST_PARTY_THEMES = Object.freeze([
|
|
1117
|
+
{
|
|
1118
|
+
// Nova on Theme ABI v2: tanqory/tanqory-platform-onlinestore `themes/nova-v2` (draft PR #194).
|
|
1119
|
+
// `themeId` is the installation's `theme_key` verbatim (site-release §1.3b, A12).
|
|
1120
|
+
themeId: "nova",
|
|
1121
|
+
visibility: "private",
|
|
1122
|
+
owner: "target-store",
|
|
1123
|
+
callers: ["platform-operator"],
|
|
1124
|
+
gitUrls: [],
|
|
1125
|
+
allowTarball: true
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
// Nova v3 — the redesigned Nova on Theme ABI v2: tanqory/tanqory-platform-onlinestore `themes/nova-v3`
|
|
1129
|
+
// (branch feat/nova-v3). Its own theme key, so a store can install it beside the Nova it runs (its own
|
|
1130
|
+
// Themes row, its own content line) and switch with Publish; rollback is the previous generation.
|
|
1131
|
+
themeId: "nova-v3",
|
|
1132
|
+
visibility: "private",
|
|
1133
|
+
owner: "target-store",
|
|
1134
|
+
// storefront-provisioner = central's provisioning of NEW stores (apps/api account/storefront-provisioning*.ts,
|
|
1135
|
+
// OS-RT-9; was admin-api's): one private Nova V3 build per new store, from the tarball digest the provisioner
|
|
1136
|
+
// holds as NOVA_V3_SOURCE_DIGEST.
|
|
1137
|
+
callers: ["platform-operator", "storefront-provisioner"],
|
|
1138
|
+
gitUrls: [],
|
|
1139
|
+
allowTarball: true
|
|
1140
|
+
}
|
|
1141
|
+
]);
|
|
1142
|
+
|
|
1143
|
+
// ../../apps/build-service/src/config/third-party.ts
|
|
1144
|
+
var THIRD_PARTY_PLATFORM_PACKAGES = /* @__PURE__ */ new Map([
|
|
1145
|
+
["@tanqory/theme-kit", "runtime"],
|
|
1146
|
+
["@tanqory/theme-abi", "runtime"],
|
|
1147
|
+
["@tanqory/theme-conformance", "runtime"],
|
|
1148
|
+
["@tanqory/cli", "dev"],
|
|
1149
|
+
["@tanqory/dev-mcp", "dev"]
|
|
1150
|
+
]);
|
|
1151
|
+
var EXACT_VERSION_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
|
|
1152
|
+
var THIRD_PARTY_TOOLCHAINS_PATH = (0, import_node_path2.join)(
|
|
1153
|
+
__dirname,
|
|
1154
|
+
"..",
|
|
1155
|
+
"..",
|
|
1156
|
+
"config",
|
|
1157
|
+
"third-party-toolchains.json"
|
|
1158
|
+
);
|
|
1159
|
+
function loadThirdPartyKits(path = THIRD_PARTY_TOOLCHAINS_PATH) {
|
|
1160
|
+
const doc = JSON.parse((0, import_node_fs2.readFileSync)(path, "utf8"));
|
|
1161
|
+
if (!Array.isArray(doc.kits) || doc.kits.length === 0)
|
|
1162
|
+
throw new Error(`${path}: kits must be a non-empty list`);
|
|
1163
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1164
|
+
return doc.kits.map((k) => {
|
|
1165
|
+
if (typeof k.version !== "string" || !EXACT_VERSION_RE.test(k.version) || !k.version.startsWith("2."))
|
|
1166
|
+
throw new Error(`${path}: ${JSON.stringify(k.version)} is not an exact 2.x version`);
|
|
1167
|
+
if (seen.has(k.version)) throw new Error(`${path}: ${k.version} is listed twice`);
|
|
1168
|
+
seen.add(k.version);
|
|
1169
|
+
if ("pack" in k) {
|
|
1170
|
+
if (k.pack !== `tanqory-theme-kit-${k.version}.tgz`)
|
|
1171
|
+
throw new Error(`${path}: ${k.version} pack must be tanqory-theme-kit-${k.version}.tgz`);
|
|
1172
|
+
if ("integrity" in k || "gitHead" in k)
|
|
1173
|
+
throw new Error(`${path}: ${k.version} is a pack; it pins no registry gitHead or integrity`);
|
|
1174
|
+
return { version: k.version, pack: `tanqory-theme-kit-${k.version}.tgz` };
|
|
1175
|
+
}
|
|
1176
|
+
if (typeof k.gitHead !== "string" || !/^[0-9a-f]{40}$/.test(k.gitHead))
|
|
1177
|
+
throw new Error(`${path}: ${k.version} has no 40-hex gitHead`);
|
|
1178
|
+
if (typeof k.integrity !== "string" || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(k.integrity))
|
|
1179
|
+
throw new Error(`${path}: ${k.version} has no sha512 integrity`);
|
|
1180
|
+
return { version: k.version, gitHead: k.gitHead, integrity: k.integrity };
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
var STARTER_ABI_VERSION = "2.0";
|
|
1184
|
+
var STARTER_DEFAULT_BUILDS = ["scripts/abi/build.mjs", "scripts/build.mjs"];
|
|
1185
|
+
var STARTER_DEFAULT_OUT = "dist/abi";
|
|
1186
|
+
var STARTER_PATH_RE = /^(?!\/)(?!.*(?:^|\/)\.\.?(?:\/|$))[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/;
|
|
1187
|
+
var STARTER_PROVIDED_PACKAGES = /* @__PURE__ */ new Set([
|
|
1188
|
+
"react",
|
|
1189
|
+
"react-dom",
|
|
1190
|
+
"vite",
|
|
1191
|
+
"@vitejs/plugin-react"
|
|
1192
|
+
]);
|
|
1193
|
+
function isStarterDevTool(name) {
|
|
1194
|
+
return /^(typescript|vitest|jsdom|axe-core|playwright|playwright-core)$/.test(name) || /^@types\/[a-z0-9._-]+$/.test(name) || /^@testing-library\/[a-z0-9._-]+$/.test(name);
|
|
1195
|
+
}
|
|
1196
|
+
function isStarterIgnoredPath(path) {
|
|
1197
|
+
const first = path.split("/")[0];
|
|
1198
|
+
return [
|
|
1199
|
+
"tests",
|
|
1200
|
+
".github",
|
|
1201
|
+
".vscode",
|
|
1202
|
+
".claude",
|
|
1203
|
+
".codex",
|
|
1204
|
+
".gemini",
|
|
1205
|
+
".cursor",
|
|
1206
|
+
".git",
|
|
1207
|
+
"node_modules",
|
|
1208
|
+
"dist",
|
|
1209
|
+
"reports",
|
|
1210
|
+
"coverage"
|
|
1211
|
+
].includes(first) || // .tanqory/ holds theme inputs (e.g. the Nova fork's frozen contracts); only the dev server's state is dropped
|
|
1212
|
+
path.startsWith(".tanqory/dev/") || [".mcp.json", "AGENTS.md", "CLAUDE.md", ".gitignore", "_gitignore", ".DS_Store"].includes(path);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// ../../apps/build-service/src/ingest/archive-guard.ts
|
|
1216
|
+
var import_node_crypto3 = require("node:crypto");
|
|
1217
|
+
var tar = __toESM(require("tar"));
|
|
1218
|
+
|
|
1219
|
+
// ../../apps/build-service/src/artifact/merkle.ts
|
|
1220
|
+
var import_node_crypto2 = require("node:crypto");
|
|
1221
|
+
var SOURCE_MERKLE_HEADER = "tanqory-theme-source/1\n";
|
|
1222
|
+
function comparePathBytes(a, b) {
|
|
1223
|
+
return Buffer.compare(Buffer.from(a, "utf8"), Buffer.from(b, "utf8"));
|
|
1224
|
+
}
|
|
1225
|
+
function sortLeaves(leaves) {
|
|
1226
|
+
return [...leaves].sort((a, b) => comparePathBytes(a.path, b.path));
|
|
1227
|
+
}
|
|
1228
|
+
var MerkleListError = class extends Error {
|
|
1229
|
+
constructor() {
|
|
1230
|
+
super(...arguments);
|
|
1231
|
+
this.name = "MerkleListError";
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
function merkleListPreimage(leaves, header) {
|
|
1235
|
+
const sorted = sortLeaves(leaves);
|
|
1236
|
+
const parts = [Buffer.from(header, "utf8")];
|
|
1237
|
+
let previous;
|
|
1238
|
+
for (const leaf of sorted) {
|
|
1239
|
+
if (previous !== void 0 && previous === leaf.path) {
|
|
1240
|
+
throw new MerkleListError(`duplicate path in Merkle list: ${leaf.path}`);
|
|
1241
|
+
}
|
|
1242
|
+
previous = leaf.path;
|
|
1243
|
+
if (!SHA256_HEX_RE.test(leaf.sha256)) {
|
|
1244
|
+
throw new MerkleListError(`leaf ${leaf.path}: sha256 must be 64 lowercase hex chars`);
|
|
1245
|
+
}
|
|
1246
|
+
if (!Number.isInteger(leaf.size) || leaf.size < 0) {
|
|
1247
|
+
throw new MerkleListError(`leaf ${leaf.path}: size must be a non-negative integer`);
|
|
1248
|
+
}
|
|
1249
|
+
if (/[\s\0]/.test(leaf.path)) {
|
|
1250
|
+
throw new MerkleListError(
|
|
1251
|
+
`leaf path contains whitespace or NUL: ${JSON.stringify(leaf.path)}`
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
parts.push(Buffer.from(`${leaf.sha256} ${leaf.size} ${leaf.path}
|
|
1255
|
+
`, "utf8"));
|
|
1256
|
+
}
|
|
1257
|
+
return Buffer.concat(parts);
|
|
1258
|
+
}
|
|
1259
|
+
function merkleListDigest(leaves, header) {
|
|
1260
|
+
const hex = (0, import_node_crypto2.createHash)("sha256").update(merkleListPreimage(leaves, header)).digest("hex");
|
|
1261
|
+
return `sha256:${hex}`;
|
|
1262
|
+
}
|
|
1263
|
+
var sourceDigestOf = (leaves) => merkleListDigest(leaves, SOURCE_MERKLE_HEADER);
|
|
1264
|
+
|
|
1265
|
+
// ../../apps/build-service/src/artifact/paths.ts
|
|
1266
|
+
var MAX_PATH_BYTES = 200;
|
|
1267
|
+
function relativePathProblem(path, opts = {}) {
|
|
1268
|
+
if (path.length === 0) return "empty";
|
|
1269
|
+
if (path.normalize("NFC") !== path) return "not_nfc";
|
|
1270
|
+
if (Buffer.byteLength(path, "utf8") > MAX_PATH_BYTES) return "too_long";
|
|
1271
|
+
if (path.startsWith("/")) return "absolute";
|
|
1272
|
+
if (path.includes("\\")) return "backslash";
|
|
1273
|
+
if (/[\u0000-\u001f\u007f]/.test(path)) return "control_char";
|
|
1274
|
+
if (/\s/.test(path)) return "whitespace";
|
|
1275
|
+
for (const segment of path.split("/")) {
|
|
1276
|
+
if (segment === "") return "empty_segment";
|
|
1277
|
+
if (segment === "." || segment === "..") return "dot_segment";
|
|
1278
|
+
if (!opts.allowDotfiles && segment.startsWith(".")) return "dotfile";
|
|
1279
|
+
}
|
|
1280
|
+
return null;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// ../../apps/build-service/src/artifact/inline-scripts.ts
|
|
1284
|
+
var INLINE_SCRIPT_SOURCE = /^src\/inline\/[^/]+\.js$/;
|
|
1285
|
+
function inlineScriptProblem(bytes) {
|
|
1286
|
+
const text = Buffer.from(bytes).toString("utf8");
|
|
1287
|
+
if (!Buffer.from(text, "utf8").equals(Buffer.from(bytes)) || text.charCodeAt(0) === 65279)
|
|
1288
|
+
return "must be valid UTF-8 without a BOM";
|
|
1289
|
+
if (/<\/script/i.test(text))
|
|
1290
|
+
return 'must not contain "</script" (it would end the inline script element early)';
|
|
1291
|
+
if (text.includes("<!--")) return 'must not contain "<!--" (HTML script-data escape)';
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// ../../apps/build-service/src/ingest/ingest-gate.ts
|
|
1296
|
+
var import_theme_abi = require("@tanqory/theme-abi");
|
|
1297
|
+
|
|
1298
|
+
// ../../apps/build-service/src/artifact/files.ts
|
|
1299
|
+
function leafOf(file) {
|
|
1300
|
+
return { path: file.path, sha256: sha256Hex(file.bytes), size: file.bytes.byteLength };
|
|
1301
|
+
}
|
|
1302
|
+
function leavesOf(files) {
|
|
1303
|
+
return sortLeaves(files.map(leafOf));
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// ../../apps/build-service/src/ingest/ingest-gate.ts
|
|
1307
|
+
var INGEST_LIMITS = Object.freeze({
|
|
1308
|
+
maxEntries: 1e4,
|
|
1309
|
+
maxUnpackedBytes: 64 * 1024 * 1024,
|
|
1310
|
+
maxFileBytes: 8 * 1024 * 1024,
|
|
1311
|
+
maxArchiveBytes: 100 * 1024 * 1024,
|
|
1312
|
+
/** unpacked / compressed, checked once ≥ ratioCheckAfterBytes of archive have been read */
|
|
1313
|
+
maxCompressionRatio: 100,
|
|
1314
|
+
ratioCheckAfterBytes: 4 * 1024 * 1024
|
|
1315
|
+
});
|
|
1316
|
+
var DENY_BASENAMES = /* @__PURE__ */ new Set([".npmrc", ".pnpmfile.cjs", "pnpm-workspace.yaml"]);
|
|
1317
|
+
var DENY_SEGMENTS = /* @__PURE__ */ new Set(["node_modules", ".git", ".github", ".husky"]);
|
|
1318
|
+
var ALLOW_FILES = /* @__PURE__ */ new Set(["package.json", "pnpm-lock.yaml", "manifest.json"]);
|
|
1319
|
+
var ALLOW_PREFIXES = [
|
|
1320
|
+
"src/",
|
|
1321
|
+
"sections/",
|
|
1322
|
+
"templates/",
|
|
1323
|
+
"layouts/",
|
|
1324
|
+
"assets/",
|
|
1325
|
+
"locales/",
|
|
1326
|
+
"config/"
|
|
1327
|
+
];
|
|
1328
|
+
var ALLOW_PATTERNS = [/^README[^/]*$/, /^LICENSE[^/]*$/];
|
|
1329
|
+
var FLATTENED_PREFIXES = ["locales/", "config/templates/", "config/regions/"];
|
|
1330
|
+
var TOOLCHAIN_EXACT = /* @__PURE__ */ new Set([
|
|
1331
|
+
"vite",
|
|
1332
|
+
"esbuild",
|
|
1333
|
+
"rollup",
|
|
1334
|
+
"react",
|
|
1335
|
+
"react-dom",
|
|
1336
|
+
"typescript",
|
|
1337
|
+
"postcss",
|
|
1338
|
+
"tailwindcss",
|
|
1339
|
+
"lightningcss"
|
|
1340
|
+
]);
|
|
1341
|
+
var TOOLCHAIN_PREFIXES = ["@vitejs/", "@rollup/", "@tanqory/theme-"];
|
|
1342
|
+
var VITE_IMPORT_ALLOW = [/^vite$/, /^@tanqory\/vite-plugin-[a-z0-9-]+$/, /^node:(path|url)$/];
|
|
1343
|
+
function isToolchainPackage(name) {
|
|
1344
|
+
return TOOLCHAIN_EXACT.has(name) || TOOLCHAIN_PREFIXES.some((p) => name.startsWith(p));
|
|
1345
|
+
}
|
|
1346
|
+
var PLATFORM_PACKAGE_SECTIONS = {
|
|
1347
|
+
runtime: ["dependencies", "devDependencies"],
|
|
1348
|
+
dev: ["devDependencies"]
|
|
1349
|
+
};
|
|
1350
|
+
function basename(path) {
|
|
1351
|
+
return path.slice(path.lastIndexOf("/") + 1);
|
|
1352
|
+
}
|
|
1353
|
+
function denyReason(path) {
|
|
1354
|
+
const base = basename(path);
|
|
1355
|
+
const segments = path.split("/");
|
|
1356
|
+
for (const seg of segments) {
|
|
1357
|
+
if (DENY_SEGMENTS.has(seg)) return `${seg}/ is not accepted`;
|
|
1358
|
+
}
|
|
1359
|
+
if (DENY_BASENAMES.has(base))
|
|
1360
|
+
return `${base} is rejected (pnpm/npm configuration is platform-owned)`;
|
|
1361
|
+
if (base.startsWith(".yarnrc"))
|
|
1362
|
+
return `${base} is rejected (yarn configuration is platform-owned)`;
|
|
1363
|
+
if (base.startsWith("Dockerfile")) return "Dockerfiles are rejected";
|
|
1364
|
+
if (base.startsWith(".env")) return "environment files are rejected";
|
|
1365
|
+
if (base.endsWith(".sh")) return "shell scripts are rejected";
|
|
1366
|
+
if (base.endsWith(".node")) return "native addons are rejected";
|
|
1367
|
+
if (base.endsWith(".wasm") && !path.startsWith("assets/"))
|
|
1368
|
+
return "wasm outside assets/ is rejected";
|
|
1369
|
+
return null;
|
|
1370
|
+
}
|
|
1371
|
+
function isAllowed(path) {
|
|
1372
|
+
if (ALLOW_FILES.has(path)) return true;
|
|
1373
|
+
if (ALLOW_PREFIXES.some((p) => path.startsWith(p))) return true;
|
|
1374
|
+
return ALLOW_PATTERNS.some((re) => re.test(path));
|
|
1375
|
+
}
|
|
1376
|
+
var IMPORT_SPECIFIER_RE = /(?:\bimport\s*(?:[\w*{}\s,$]*\bfrom\s*)?|\bexport\s+[\w*{}\s,$]*\bfrom\s*|\brequire\s*\(\s*|\bimport\s*\(\s*)['"]([^'"]+)['"]/g;
|
|
1377
|
+
function isPlainRegistryRange(spec) {
|
|
1378
|
+
if (typeof spec !== "string" || spec.length === 0 || spec.length > 128) return false;
|
|
1379
|
+
const comparator = /^(?:[<>]=?|=|~|\^)?v?(?:0|[1-9]\d*|[xX*])(?:\.(?:0|[1-9]\d*|[xX*])){0,2}(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1380
|
+
return spec.split("||").every((set) => {
|
|
1381
|
+
const parts = set.trim().split(/\s+/);
|
|
1382
|
+
if (parts.length === 1 && parts[0] === "") return false;
|
|
1383
|
+
if (parts.length === 3 && parts[1] === "-")
|
|
1384
|
+
return comparator.test(parts[0]) && comparator.test(parts[2]);
|
|
1385
|
+
return parts.every((p) => comparator.test(p));
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
function registryVersionOf(version) {
|
|
1389
|
+
const m = /^(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)(\(.+\))*$/.exec(version);
|
|
1390
|
+
return m ? m[1] : void 0;
|
|
1391
|
+
}
|
|
1392
|
+
function snapshotBase(key) {
|
|
1393
|
+
const paren = key.indexOf("(");
|
|
1394
|
+
const head = paren >= 0 ? key.slice(0, paren) : key;
|
|
1395
|
+
const at = head.lastIndexOf("@");
|
|
1396
|
+
if (at <= 0) return void 0;
|
|
1397
|
+
const version = registryVersionOf(key.slice(at + 1));
|
|
1398
|
+
return version ? `${head.slice(0, at)}@${version}` : void 0;
|
|
1399
|
+
}
|
|
1400
|
+
function disallowedViteImport(source) {
|
|
1401
|
+
for (const match of source.matchAll(IMPORT_SPECIFIER_RE)) {
|
|
1402
|
+
const spec = match[1];
|
|
1403
|
+
if (spec.startsWith("./") || spec.startsWith("../")) continue;
|
|
1404
|
+
if (!VITE_IMPORT_ALLOW.some((re) => re.test(spec))) return spec;
|
|
1405
|
+
}
|
|
1406
|
+
return null;
|
|
1407
|
+
}
|
|
1408
|
+
var IngestGate = class {
|
|
1409
|
+
constructor(opts) {
|
|
1410
|
+
this.opts = opts;
|
|
1411
|
+
}
|
|
1412
|
+
inspect(input) {
|
|
1413
|
+
if (this.opts.thirdParty && !input.some((f) => f.path === "manifest.json"))
|
|
1414
|
+
return this.inspectStarter(input);
|
|
1415
|
+
const files = sortLeaves(input);
|
|
1416
|
+
if (files.length > INGEST_LIMITS.maxEntries) {
|
|
1417
|
+
throw new IngestRejectedError(
|
|
1418
|
+
"size",
|
|
1419
|
+
`${files.length} entries exceeds the ${INGEST_LIMITS.maxEntries} entry cap`
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
let total = 0;
|
|
1423
|
+
for (const f of files) {
|
|
1424
|
+
total += f.bytes.byteLength;
|
|
1425
|
+
if (f.bytes.byteLength > INGEST_LIMITS.maxFileBytes) {
|
|
1426
|
+
throw new IngestRejectedError(
|
|
1427
|
+
"size",
|
|
1428
|
+
`${f.path} is ${f.bytes.byteLength} bytes; single file cap is ${INGEST_LIMITS.maxFileBytes}`,
|
|
1429
|
+
f.path
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (total > INGEST_LIMITS.maxUnpackedBytes) {
|
|
1434
|
+
throw new IngestRejectedError(
|
|
1435
|
+
"size",
|
|
1436
|
+
`tree is ${total} bytes; cap is ${INGEST_LIMITS.maxUnpackedBytes}`
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1440
|
+
for (const f of files) {
|
|
1441
|
+
const problem = relativePathProblem(f.path, { allowDotfiles: true });
|
|
1442
|
+
if (problem)
|
|
1443
|
+
throw new IngestRejectedError(
|
|
1444
|
+
"params",
|
|
1445
|
+
`path ${JSON.stringify(f.path)} rejected: ${problem}`,
|
|
1446
|
+
f.path
|
|
1447
|
+
);
|
|
1448
|
+
if (seen.has(f.path))
|
|
1449
|
+
throw new IngestRejectedError("params", `duplicate path ${f.path}`, f.path);
|
|
1450
|
+
seen.add(f.path);
|
|
1451
|
+
const deny = denyReason(f.path);
|
|
1452
|
+
if (deny) throw new IngestRejectedError("params", `${f.path}: ${deny}`, f.path);
|
|
1453
|
+
const base = basename(f.path);
|
|
1454
|
+
if (/^vite(st)?\.config\./.test(base)) {
|
|
1455
|
+
const bad = disallowedViteImport(f.bytes.toString("utf8"));
|
|
1456
|
+
if (bad) {
|
|
1457
|
+
throw new IngestRejectedError(
|
|
1458
|
+
"params",
|
|
1459
|
+
`${f.path} imports ${JSON.stringify(bad)}, which is not an allowlisted plugin`,
|
|
1460
|
+
f.path
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (!isAllowed(f.path)) {
|
|
1465
|
+
throw new IngestRejectedError(
|
|
1466
|
+
"params",
|
|
1467
|
+
`${f.path} is outside the accepted source layout`,
|
|
1468
|
+
f.path
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
if (INLINE_SCRIPT_SOURCE.test(f.path)) {
|
|
1472
|
+
const inlineProblem = inlineScriptProblem(f.bytes);
|
|
1473
|
+
if (inlineProblem)
|
|
1474
|
+
throw new IngestRejectedError(
|
|
1475
|
+
"params",
|
|
1476
|
+
`inline script ${f.path} ${inlineProblem}`,
|
|
1477
|
+
f.path
|
|
1478
|
+
);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
this.checkCollisions(files);
|
|
1482
|
+
const pkgFile = files.find((f) => f.path === "package.json");
|
|
1483
|
+
if (!pkgFile)
|
|
1484
|
+
throw new IngestRejectedError("params", "package.json is required", "package.json");
|
|
1485
|
+
const packageJson = this.checkPackageJson(pkgFile);
|
|
1486
|
+
const lockFile = files.find((f) => f.path === "pnpm-lock.yaml");
|
|
1487
|
+
if (!lockFile)
|
|
1488
|
+
throw new IngestRejectedError("deps", "pnpm-lock.yaml is required", "pnpm-lock.yaml");
|
|
1489
|
+
const lockfile = this.checkLockfile(lockFile);
|
|
1490
|
+
const manifestFile = files.find((f) => f.path === "manifest.json");
|
|
1491
|
+
if (!manifestFile)
|
|
1492
|
+
throw new IngestRejectedError("manifest", "manifest.json is required", "manifest.json");
|
|
1493
|
+
const manifest = this.checkManifest(manifestFile);
|
|
1494
|
+
return {
|
|
1495
|
+
files,
|
|
1496
|
+
sourceDigest: sourceDigestOf(leavesOf(files)),
|
|
1497
|
+
lockfileDigest: sha256Digest(lockFile.bytes),
|
|
1498
|
+
lockfile,
|
|
1499
|
+
manifest,
|
|
1500
|
+
abiVersion: manifest.abi,
|
|
1501
|
+
layout: "theme-source",
|
|
1502
|
+
packageJson
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* A starter tree (third-party lane, D18 option a). What is accepted:
|
|
1507
|
+
* - paths that are not build inputs (tests, CI, agent/editor config, build output) are DROPPED before
|
|
1508
|
+
* the source digest; the platform's deny-list (npm/pnpm/yarn config, Dockerfiles, env files, shell
|
|
1509
|
+
* scripts, native addons, wasm outside assets/) still REJECTS; every other path is a build input —
|
|
1510
|
+
* the theme's own build file runs over the whole tree in the sandbox;
|
|
1511
|
+
* - package.json: name + version; `tanqory.build` (a relative .mjs that exists; default: the
|
|
1512
|
+
* starters' own) and `tanqory.out` (default dist/abi); dependencies only platform packages at exact
|
|
1513
|
+
* versions, packages the image provides (react, react-dom, vite, @vitejs/plugin-react; the image's
|
|
1514
|
+
* versions are used, never the declared range) and — devDependencies only — developer tools the build
|
|
1515
|
+
* never runs; resolutions/workspaces/overrides/patches rejected as for any theme;
|
|
1516
|
+
* - a lockfile is optional (npm or pnpm): never installed from, read for the SBOM only;
|
|
1517
|
+
* - no manifest.json: the build writes it, and the platform checks the build's output.
|
|
1518
|
+
*/
|
|
1519
|
+
inspectStarter(input) {
|
|
1520
|
+
const files = sortLeaves(input.filter((f) => !isStarterIgnoredPath(f.path)));
|
|
1521
|
+
if (files.length > INGEST_LIMITS.maxEntries)
|
|
1522
|
+
throw new IngestRejectedError(
|
|
1523
|
+
"size",
|
|
1524
|
+
`${files.length} entries exceeds the ${INGEST_LIMITS.maxEntries} entry cap`
|
|
1525
|
+
);
|
|
1526
|
+
let total = 0;
|
|
1527
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1528
|
+
for (const f of files) {
|
|
1529
|
+
total += f.bytes.byteLength;
|
|
1530
|
+
if (f.bytes.byteLength > INGEST_LIMITS.maxFileBytes)
|
|
1531
|
+
throw new IngestRejectedError(
|
|
1532
|
+
"size",
|
|
1533
|
+
`${f.path} is ${f.bytes.byteLength} bytes; single file cap is ${INGEST_LIMITS.maxFileBytes}`,
|
|
1534
|
+
f.path
|
|
1535
|
+
);
|
|
1536
|
+
const problem = relativePathProblem(f.path, { allowDotfiles: true });
|
|
1537
|
+
if (problem)
|
|
1538
|
+
throw new IngestRejectedError(
|
|
1539
|
+
"params",
|
|
1540
|
+
`path ${JSON.stringify(f.path)} rejected: ${problem}`,
|
|
1541
|
+
f.path
|
|
1542
|
+
);
|
|
1543
|
+
if (seen.has(f.path))
|
|
1544
|
+
throw new IngestRejectedError("params", `duplicate path ${f.path}`, f.path);
|
|
1545
|
+
seen.add(f.path);
|
|
1546
|
+
const deny = denyReason(f.path);
|
|
1547
|
+
if (deny) throw new IngestRejectedError("params", `${f.path}: ${deny}`, f.path);
|
|
1548
|
+
}
|
|
1549
|
+
if (total > INGEST_LIMITS.maxUnpackedBytes)
|
|
1550
|
+
throw new IngestRejectedError(
|
|
1551
|
+
"size",
|
|
1552
|
+
`tree is ${total} bytes; cap is ${INGEST_LIMITS.maxUnpackedBytes}`
|
|
1553
|
+
);
|
|
1554
|
+
const folded = /* @__PURE__ */ new Map();
|
|
1555
|
+
for (const f of files) {
|
|
1556
|
+
const key = f.path.normalize("NFC").toLowerCase();
|
|
1557
|
+
const other = folded.get(key);
|
|
1558
|
+
if (other)
|
|
1559
|
+
throw new PathCollisionError(`${f.path} collides with ${other} when case is ignored`, [
|
|
1560
|
+
other,
|
|
1561
|
+
f.path
|
|
1562
|
+
]);
|
|
1563
|
+
folded.set(key, f.path);
|
|
1564
|
+
}
|
|
1565
|
+
const pkgFile = files.find((f) => f.path === "package.json");
|
|
1566
|
+
if (!pkgFile)
|
|
1567
|
+
throw new IngestRejectedError("params", "package.json is required", "package.json");
|
|
1568
|
+
const packageJson = this.checkStarterPackageJson(pkgFile, new Set(files.map((f) => f.path)));
|
|
1569
|
+
const pnpmLock = files.find((f) => f.path === "pnpm-lock.yaml");
|
|
1570
|
+
const npmLock = files.find((f) => f.path === "package-lock.json");
|
|
1571
|
+
let lockfile;
|
|
1572
|
+
try {
|
|
1573
|
+
lockfile = pnpmLock ? parsePnpmLockfile(pnpmLock.bytes) : npmLock ? parseNpmLockfile(npmLock.bytes) : EMPTY_LOCKFILE;
|
|
1574
|
+
} catch (e) {
|
|
1575
|
+
throw new IngestRejectedError(
|
|
1576
|
+
"deps",
|
|
1577
|
+
`${(pnpmLock ?? npmLock).path}: ${e.message}`,
|
|
1578
|
+
(pnpmLock ?? npmLock).path
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
return {
|
|
1582
|
+
files,
|
|
1583
|
+
sourceDigest: sourceDigestOf(leavesOf(files)),
|
|
1584
|
+
lockfileDigest: sha256Digest((pnpmLock ?? npmLock)?.bytes ?? Buffer.alloc(0)),
|
|
1585
|
+
lockfile,
|
|
1586
|
+
abiVersion: STARTER_ABI_VERSION,
|
|
1587
|
+
layout: "starter",
|
|
1588
|
+
packageJson
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
checkStarterPackageJson(file, paths) {
|
|
1592
|
+
let pkg;
|
|
1593
|
+
try {
|
|
1594
|
+
pkg = JSON.parse(file.bytes.toString("utf8"));
|
|
1595
|
+
} catch {
|
|
1596
|
+
throw new IngestRejectedError("params", "package.json is not valid JSON", file.path);
|
|
1597
|
+
}
|
|
1598
|
+
if (typeof pkg["name"] !== "string" || typeof pkg["version"] !== "string")
|
|
1599
|
+
throw new IngestRejectedError(
|
|
1600
|
+
"params",
|
|
1601
|
+
'package.json needs string "name" and "version"',
|
|
1602
|
+
file.path
|
|
1603
|
+
);
|
|
1604
|
+
for (const key of ["resolutions", "workspaces", "overrides"])
|
|
1605
|
+
if (key in pkg)
|
|
1606
|
+
throw new IngestRejectedError("params", `package.json "${key}" is rejected`, file.path);
|
|
1607
|
+
const pnpm = pkg["pnpm"] ?? {};
|
|
1608
|
+
for (const key of ["overrides", "patchedDependencies", "onlyBuiltDependencies"])
|
|
1609
|
+
if (key in pnpm)
|
|
1610
|
+
throw new IngestRejectedError("params", `package.json "pnpm.${key}" is rejected`, file.path);
|
|
1611
|
+
const tq = pkg["tanqory"] ?? {};
|
|
1612
|
+
if (typeof tq !== "object" || Array.isArray(tq))
|
|
1613
|
+
throw new IngestRejectedError("params", 'package.json "tanqory" must be an object', file.path);
|
|
1614
|
+
const build = tq["build"] ?? STARTER_DEFAULT_BUILDS.find((b) => paths.has(b)) ?? STARTER_DEFAULT_BUILDS[1];
|
|
1615
|
+
const out = tq["out"] ?? STARTER_DEFAULT_OUT;
|
|
1616
|
+
if (typeof build !== "string" || !STARTER_PATH_RE.test(build) || !build.endsWith(".mjs"))
|
|
1617
|
+
throw new IngestRejectedError(
|
|
1618
|
+
"params",
|
|
1619
|
+
`package.json tanqory.build ${JSON.stringify(build)} must be a relative path to a .mjs file in the theme`,
|
|
1620
|
+
file.path
|
|
1621
|
+
);
|
|
1622
|
+
if (!paths.has(build))
|
|
1623
|
+
throw new IngestRejectedError(
|
|
1624
|
+
"params",
|
|
1625
|
+
`the build file ${build} is not in the upload (package.json tanqory.build, or ${STARTER_DEFAULT_BUILDS.join(" / ")})`,
|
|
1626
|
+
build
|
|
1627
|
+
);
|
|
1628
|
+
if (typeof out !== "string" || !STARTER_PATH_RE.test(out))
|
|
1629
|
+
throw new IngestRejectedError(
|
|
1630
|
+
"params",
|
|
1631
|
+
`package.json tanqory.out ${JSON.stringify(out)} must be a relative directory in the theme`,
|
|
1632
|
+
file.path
|
|
1633
|
+
);
|
|
1634
|
+
const sections = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
1635
|
+
let kit = false;
|
|
1636
|
+
for (const section of sections) {
|
|
1637
|
+
const deps = pkg[section] ?? {};
|
|
1638
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
1639
|
+
if (typeof spec !== "string" || !isPlainRegistryRange(spec))
|
|
1640
|
+
throw new IngestRejectedError(
|
|
1641
|
+
"deps",
|
|
1642
|
+
`package.json ${section}.${name}: ${JSON.stringify(spec)} is not a plain registry version range`,
|
|
1643
|
+
file.path,
|
|
1644
|
+
{ entry: name }
|
|
1645
|
+
);
|
|
1646
|
+
const platform = THIRD_PARTY_PLATFORM_PACKAGES.get(name);
|
|
1647
|
+
if (platform) {
|
|
1648
|
+
const allowed = PLATFORM_PACKAGE_SECTIONS[platform];
|
|
1649
|
+
if (!allowed.includes(section))
|
|
1650
|
+
throw new IngestRejectedError(
|
|
1651
|
+
"deps",
|
|
1652
|
+
`package.json ${section}.${name}: ${name} may be named only in ${allowed.join(" or ")}`,
|
|
1653
|
+
file.path,
|
|
1654
|
+
{ entry: name }
|
|
1655
|
+
);
|
|
1656
|
+
if (!EXACT_VERSION_RE.test(spec))
|
|
1657
|
+
throw new IngestRejectedError(
|
|
1658
|
+
"deps",
|
|
1659
|
+
`package.json ${section}.${name}: ${JSON.stringify(spec)} must be an exact version (e.g. "2.0.0-alpha.3"), not a range`,
|
|
1660
|
+
file.path,
|
|
1661
|
+
{ entry: name }
|
|
1662
|
+
);
|
|
1663
|
+
if (name === "@tanqory/theme-kit") kit = true;
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
if (STARTER_PROVIDED_PACKAGES.has(name) && (section === "dependencies" || section === "devDependencies"))
|
|
1667
|
+
continue;
|
|
1668
|
+
if (isStarterDevTool(name) && section === "devDependencies") continue;
|
|
1669
|
+
throw new IngestRejectedError(
|
|
1670
|
+
"deps",
|
|
1671
|
+
`package.json ${section}.${name}: the builder does not provide ${name} (a starter build uses the kit, react, react-dom, vite and @vitejs/plugin-react from the builder image)`,
|
|
1672
|
+
file.path,
|
|
1673
|
+
{ entry: name }
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
if (!kit)
|
|
1678
|
+
throw new IngestRejectedError(
|
|
1679
|
+
"deps",
|
|
1680
|
+
"package.json must pin @tanqory/theme-kit exactly: it selects the toolchain the build runs with",
|
|
1681
|
+
file.path,
|
|
1682
|
+
{ entry: "@tanqory/theme-kit" }
|
|
1683
|
+
);
|
|
1684
|
+
return { name: pkg["name"], version: pkg["version"] };
|
|
1685
|
+
}
|
|
1686
|
+
checkCollisions(files) {
|
|
1687
|
+
const folded = /* @__PURE__ */ new Map();
|
|
1688
|
+
for (const f of files) {
|
|
1689
|
+
const key = f.path.normalize("NFC").toLowerCase();
|
|
1690
|
+
const other = folded.get(key);
|
|
1691
|
+
if (other) {
|
|
1692
|
+
throw new PathCollisionError(`${f.path} collides with ${other} when case is ignored`, [
|
|
1693
|
+
other,
|
|
1694
|
+
f.path
|
|
1695
|
+
]);
|
|
1696
|
+
}
|
|
1697
|
+
folded.set(key, f.path);
|
|
1698
|
+
}
|
|
1699
|
+
for (const prefix of FLATTENED_PREFIXES) {
|
|
1700
|
+
const byBase = /* @__PURE__ */ new Map();
|
|
1701
|
+
for (const f of files) {
|
|
1702
|
+
if (!f.path.startsWith(prefix)) continue;
|
|
1703
|
+
const base = basename(f.path);
|
|
1704
|
+
const other = byBase.get(base);
|
|
1705
|
+
if (other) {
|
|
1706
|
+
throw new PathCollisionError(
|
|
1707
|
+
`${other} and ${f.path} both map to ${prefix}${base} in the artifact`,
|
|
1708
|
+
[other, f.path]
|
|
1709
|
+
);
|
|
1710
|
+
}
|
|
1711
|
+
byBase.set(base, f.path);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
checkPackageJson(file) {
|
|
1716
|
+
let pkg;
|
|
1717
|
+
try {
|
|
1718
|
+
pkg = JSON.parse(file.bytes.toString("utf8"));
|
|
1719
|
+
} catch {
|
|
1720
|
+
throw new IngestRejectedError("params", "package.json is not valid JSON", file.path);
|
|
1721
|
+
}
|
|
1722
|
+
if (typeof pkg["name"] !== "string" || typeof pkg["version"] !== "string") {
|
|
1723
|
+
throw new IngestRejectedError(
|
|
1724
|
+
"params",
|
|
1725
|
+
'package.json needs string "name" and "version"',
|
|
1726
|
+
file.path
|
|
1727
|
+
);
|
|
1728
|
+
}
|
|
1729
|
+
for (const key of ["resolutions", "workspaces"]) {
|
|
1730
|
+
if (key in pkg)
|
|
1731
|
+
throw new IngestRejectedError("params", `package.json "${key}" is rejected`, file.path);
|
|
1732
|
+
}
|
|
1733
|
+
const pnpm = pkg["pnpm"] ?? {};
|
|
1734
|
+
for (const key of ["overrides", "patchedDependencies"]) {
|
|
1735
|
+
if (key in pnpm)
|
|
1736
|
+
throw new IngestRejectedError("params", `package.json "pnpm.${key}" is rejected`, file.path);
|
|
1737
|
+
}
|
|
1738
|
+
const onlyBuilt = pnpm["onlyBuiltDependencies"];
|
|
1739
|
+
if (onlyBuilt !== void 0 && !(Array.isArray(onlyBuilt) && onlyBuilt.length === 0)) {
|
|
1740
|
+
throw new IngestRejectedError(
|
|
1741
|
+
"deps",
|
|
1742
|
+
'package.json "pnpm.onlyBuiltDependencies" must be absent or []',
|
|
1743
|
+
file.path
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
for (const section of [
|
|
1747
|
+
"dependencies",
|
|
1748
|
+
"devDependencies",
|
|
1749
|
+
"optionalDependencies",
|
|
1750
|
+
"peerDependencies"
|
|
1751
|
+
]) {
|
|
1752
|
+
const deps = pkg[section] ?? {};
|
|
1753
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
1754
|
+
if (typeof spec !== "string" || !isPlainRegistryRange(spec)) {
|
|
1755
|
+
throw new IngestRejectedError(
|
|
1756
|
+
"deps",
|
|
1757
|
+
`package.json ${section}.${name}: ${JSON.stringify(spec)} is not a plain registry version range`,
|
|
1758
|
+
file.path,
|
|
1759
|
+
{ entry: name }
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
const platform = this.opts.thirdParty ? THIRD_PARTY_PLATFORM_PACKAGES.get(name) : void 0;
|
|
1763
|
+
if (platform) {
|
|
1764
|
+
const sections = PLATFORM_PACKAGE_SECTIONS[platform];
|
|
1765
|
+
if (!sections.includes(section))
|
|
1766
|
+
throw new IngestRejectedError(
|
|
1767
|
+
"deps",
|
|
1768
|
+
`package.json ${section}.${name}: ${name} may be named only in ${sections.join(" or ")}`,
|
|
1769
|
+
file.path,
|
|
1770
|
+
{ entry: name }
|
|
1771
|
+
);
|
|
1772
|
+
if (!EXACT_VERSION_RE.test(spec))
|
|
1773
|
+
throw new IngestRejectedError(
|
|
1774
|
+
"deps",
|
|
1775
|
+
`package.json ${section}.${name}: ${JSON.stringify(spec)} must be an exact version (e.g. "2.0.0-alpha.3"), not a range`,
|
|
1776
|
+
file.path,
|
|
1777
|
+
{ entry: name }
|
|
1778
|
+
);
|
|
1779
|
+
continue;
|
|
1780
|
+
}
|
|
1781
|
+
if (isToolchainPackage(name)) {
|
|
1782
|
+
throw new IngestRejectedError(
|
|
1783
|
+
"deps",
|
|
1784
|
+
`package.json ${section}.${name}: toolchain packages are provided by the builder image`,
|
|
1785
|
+
file.path,
|
|
1786
|
+
{ entry: name }
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
1792
|
+
const deps = pkg[section] ?? {};
|
|
1793
|
+
for (const name of Object.keys(deps)) {
|
|
1794
|
+
if (this.opts.thirdParty && THIRD_PARTY_PLATFORM_PACKAGES.has(name)) continue;
|
|
1795
|
+
if (!this.opts.allowlist.packages.has(name)) {
|
|
1796
|
+
throw new IngestRejectedError(
|
|
1797
|
+
"deps",
|
|
1798
|
+
`package.json ${section}.${name} is not on the mirror allowlist`,
|
|
1799
|
+
file.path,
|
|
1800
|
+
{ entry: name }
|
|
1801
|
+
);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
return { name: pkg["name"], version: pkg["version"] };
|
|
1806
|
+
}
|
|
1807
|
+
checkLockfile(file) {
|
|
1808
|
+
let lock;
|
|
1809
|
+
try {
|
|
1810
|
+
lock = parsePnpmLockfile(file.bytes);
|
|
1811
|
+
} catch (e) {
|
|
1812
|
+
throw new IngestRejectedError("deps", e.message, file.path);
|
|
1813
|
+
}
|
|
1814
|
+
const major = Number.parseInt(lock.lockfileVersion, 10);
|
|
1815
|
+
if (!Number.isFinite(major) || major < 9) {
|
|
1816
|
+
throw new IngestRejectedError(
|
|
1817
|
+
"deps",
|
|
1818
|
+
`pnpm-lock.yaml lockfileVersion ${lock.lockfileVersion} < 9`,
|
|
1819
|
+
file.path
|
|
1820
|
+
);
|
|
1821
|
+
}
|
|
1822
|
+
const platformOnly = this.opts.thirdParty ? platformOnlyClosure(lock) : /* @__PURE__ */ new Set();
|
|
1823
|
+
for (const p of lock.packages) {
|
|
1824
|
+
const entry = `${p.name}@${p.version}`;
|
|
1825
|
+
if (platformOnly.has(entry)) {
|
|
1826
|
+
if (!p.integrity || !/^sha512-/.test(p.integrity))
|
|
1827
|
+
throw new IngestRejectedError(
|
|
1828
|
+
"deps",
|
|
1829
|
+
`pnpm-lock.yaml ${entry} has no sha512 resolution.integrity`,
|
|
1830
|
+
file.path,
|
|
1831
|
+
{ entry }
|
|
1832
|
+
);
|
|
1833
|
+
} else if (isToolchainPackage(p.name)) {
|
|
1834
|
+
throw new IngestRejectedError(
|
|
1835
|
+
"deps",
|
|
1836
|
+
`pnpm-lock.yaml ${entry}: toolchain packages are provided by the builder image`,
|
|
1837
|
+
file.path,
|
|
1838
|
+
{ entry }
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
const problem = platformOnly.has(entry) ? void 0 : allowlistProblem(this.opts.allowlist, p.name, p.version, p.integrity);
|
|
1842
|
+
if (problem) {
|
|
1843
|
+
throw new IngestRejectedError("deps", `pnpm-lock.yaml ${entry} ${problem}`, file.path, {
|
|
1844
|
+
entry
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
if (p.tarball) {
|
|
1848
|
+
let host;
|
|
1849
|
+
try {
|
|
1850
|
+
host = new URL(p.tarball).host;
|
|
1851
|
+
} catch {
|
|
1852
|
+
throw new IngestRejectedError(
|
|
1853
|
+
"deps",
|
|
1854
|
+
`pnpm-lock.yaml ${entry}: resolution.tarball is not a URL`,
|
|
1855
|
+
file.path,
|
|
1856
|
+
{ entry }
|
|
1857
|
+
);
|
|
1858
|
+
}
|
|
1859
|
+
if (!this.opts.mirrorHosts.includes(host)) {
|
|
1860
|
+
throw new IngestRejectedError(
|
|
1861
|
+
"deps",
|
|
1862
|
+
`pnpm-lock.yaml ${entry}: tarball host ${host} is not the mirror`,
|
|
1863
|
+
file.path,
|
|
1864
|
+
{ entry }
|
|
1865
|
+
);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
const checked = new Set(lock.packages.map((p) => `${p.name}@${p.version}`));
|
|
1870
|
+
const refuse = (message, entry) => {
|
|
1871
|
+
throw new IngestRejectedError("deps", `pnpm-lock.yaml ${message}`, file.path, { entry });
|
|
1872
|
+
};
|
|
1873
|
+
for (const d of lock.importerDependencies) {
|
|
1874
|
+
const at = `importers[${JSON.stringify(d.importer)}].${d.section}.${d.name}`;
|
|
1875
|
+
if (d.importer !== ".") refuse(`${at}: only the root importer "." is accepted`, d.name);
|
|
1876
|
+
if (d.section === "peerDependencies")
|
|
1877
|
+
refuse(`${at}: an importer peer dependency is not accepted`, d.name);
|
|
1878
|
+
if (!isPlainRegistryRange(d.specifier))
|
|
1879
|
+
refuse(
|
|
1880
|
+
`${at}: specifier ${JSON.stringify(d.specifier)} is not a plain registry range`,
|
|
1881
|
+
d.name
|
|
1882
|
+
);
|
|
1883
|
+
const version = registryVersionOf(d.version);
|
|
1884
|
+
if (!version)
|
|
1885
|
+
refuse(`${at}: version ${JSON.stringify(d.version)} is not a registry version`, d.name);
|
|
1886
|
+
if (!checked.has(`${d.name}@${version}`))
|
|
1887
|
+
refuse(`${at}: ${d.name}@${version} has no entry in packages:`, d.name);
|
|
1888
|
+
if (this.opts.thirdParty && THIRD_PARTY_PLATFORM_PACKAGES.has(d.name) && d.specifier !== version)
|
|
1889
|
+
refuse(
|
|
1890
|
+
`${at}: specifier ${d.specifier} must be the exact version it resolves to (${version})`,
|
|
1891
|
+
d.name
|
|
1892
|
+
);
|
|
1893
|
+
}
|
|
1894
|
+
for (const snap of lock.snapshots) {
|
|
1895
|
+
const base = snapshotBase(snap.key);
|
|
1896
|
+
if (!base || !checked.has(base))
|
|
1897
|
+
refuse(
|
|
1898
|
+
`snapshots[${JSON.stringify(snap.key)}] names a package that packages: does not list`,
|
|
1899
|
+
snap.key
|
|
1900
|
+
);
|
|
1901
|
+
for (const d of snap.dependencies) {
|
|
1902
|
+
const version = registryVersionOf(d.version);
|
|
1903
|
+
if (!version || !checked.has(`${d.name}@${version}`))
|
|
1904
|
+
refuse(
|
|
1905
|
+
`snapshots[${JSON.stringify(snap.key)}].${d.name}: ${JSON.stringify(d.version)} does not resolve to an entry of packages:`,
|
|
1906
|
+
snap.key
|
|
1907
|
+
);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
return lock;
|
|
1911
|
+
}
|
|
1912
|
+
checkManifest(file) {
|
|
1913
|
+
if (file.bytes.byteLength > import_theme_abi.LIMITS.manifestBytes.hard) {
|
|
1914
|
+
throw new IngestRejectedError(
|
|
1915
|
+
"manifest",
|
|
1916
|
+
`manifest.json is ${file.bytes.byteLength} bytes; hard limit ${import_theme_abi.LIMITS.manifestBytes.hard}`,
|
|
1917
|
+
file.path
|
|
1918
|
+
);
|
|
1919
|
+
}
|
|
1920
|
+
let parsed;
|
|
1921
|
+
try {
|
|
1922
|
+
parsed = JSON.parse(file.bytes.toString("utf8"));
|
|
1923
|
+
} catch {
|
|
1924
|
+
throw new IngestRejectedError("manifest", "manifest.json is not valid JSON", file.path);
|
|
1925
|
+
}
|
|
1926
|
+
const result = (0, import_theme_abi.validateManifest)(parsed);
|
|
1927
|
+
if (!result.ok) {
|
|
1928
|
+
const first = result.errors[0];
|
|
1929
|
+
throw new IngestRejectedError(
|
|
1930
|
+
"manifest",
|
|
1931
|
+
`manifest.json invalid: ${first ? `${first.path || "/"}: ${first.message}` : "unknown error"}`,
|
|
1932
|
+
file.path,
|
|
1933
|
+
{
|
|
1934
|
+
errors: result.errors.map((e) => ({
|
|
1935
|
+
path: e.path,
|
|
1936
|
+
code: e.code,
|
|
1937
|
+
keyword: e.keyword,
|
|
1938
|
+
message: e.message
|
|
1939
|
+
}))
|
|
1940
|
+
}
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
return result.manifest;
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
function platformOnlyClosure(lock) {
|
|
1947
|
+
const edges = /* @__PURE__ */ new Map();
|
|
1948
|
+
for (const snap of lock.snapshots) {
|
|
1949
|
+
const base = snapshotBase(snap.key);
|
|
1950
|
+
if (!base) continue;
|
|
1951
|
+
const out = edges.get(base) ?? [];
|
|
1952
|
+
for (const d of snap.dependencies) {
|
|
1953
|
+
const v = registryVersionOf(d.version);
|
|
1954
|
+
if (v) out.push(`${d.name}@${v}`);
|
|
1955
|
+
}
|
|
1956
|
+
edges.set(base, out);
|
|
1957
|
+
}
|
|
1958
|
+
const reach = (roots) => {
|
|
1959
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1960
|
+
const stack = [...roots];
|
|
1961
|
+
while (stack.length > 0) {
|
|
1962
|
+
const k = stack.pop();
|
|
1963
|
+
if (seen.has(k)) continue;
|
|
1964
|
+
seen.add(k);
|
|
1965
|
+
stack.push(...edges.get(k) ?? []);
|
|
1966
|
+
}
|
|
1967
|
+
return seen;
|
|
1968
|
+
};
|
|
1969
|
+
const platformRoots = [];
|
|
1970
|
+
const otherRoots = [];
|
|
1971
|
+
for (const d of lock.importerDependencies) {
|
|
1972
|
+
if (d.importer !== ".") continue;
|
|
1973
|
+
const v = registryVersionOf(d.version);
|
|
1974
|
+
if (!v) continue;
|
|
1975
|
+
(THIRD_PARTY_PLATFORM_PACKAGES.has(d.name) ? platformRoots : otherRoots).push(`${d.name}@${v}`);
|
|
1976
|
+
}
|
|
1977
|
+
const other = reach(otherRoots);
|
|
1978
|
+
return new Set([...reach(platformRoots)].filter((k) => !other.has(k)));
|
|
1979
|
+
}
|
|
1980
|
+
var EMPTY_LOCKFILE = Object.freeze({
|
|
1981
|
+
lockfileVersion: "none",
|
|
1982
|
+
packages: [],
|
|
1983
|
+
rootDependencies: {},
|
|
1984
|
+
importerDependencies: [],
|
|
1985
|
+
snapshots: []
|
|
1986
|
+
});
|
|
1987
|
+
function parseNpmLockfile(bytes) {
|
|
1988
|
+
let doc;
|
|
1989
|
+
try {
|
|
1990
|
+
doc = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
1991
|
+
} catch {
|
|
1992
|
+
throw new Error("not valid JSON");
|
|
1993
|
+
}
|
|
1994
|
+
if (typeof doc.lockfileVersion !== "number" || doc.lockfileVersion < 2 || !doc.packages)
|
|
1995
|
+
throw new Error('package-lock.json lockfileVersion must be 2 or 3 with a "packages" map');
|
|
1996
|
+
const packages = [];
|
|
1997
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1998
|
+
for (const [key, entry] of Object.entries(doc.packages)) {
|
|
1999
|
+
if (!key.startsWith("node_modules/") || entry["link"]) continue;
|
|
2000
|
+
const name = key.slice(key.lastIndexOf("node_modules/") + "node_modules/".length);
|
|
2001
|
+
const version = entry["version"];
|
|
2002
|
+
if (typeof version !== "string") continue;
|
|
2003
|
+
const dev = entry["dev"] === true;
|
|
2004
|
+
const at = seen.get(`${name}@${version}`);
|
|
2005
|
+
if (at !== void 0) {
|
|
2006
|
+
const prev = packages[at];
|
|
2007
|
+
if (!dev && prev.dev)
|
|
2008
|
+
packages[at] = {
|
|
2009
|
+
name: prev.name,
|
|
2010
|
+
version: prev.version,
|
|
2011
|
+
...prev.integrity !== void 0 ? { integrity: prev.integrity } : {}
|
|
2012
|
+
};
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
2015
|
+
seen.set(`${name}@${version}`, packages.length);
|
|
2016
|
+
packages.push({
|
|
2017
|
+
name,
|
|
2018
|
+
version,
|
|
2019
|
+
...typeof entry["integrity"] === "string" ? { integrity: entry["integrity"] } : {},
|
|
2020
|
+
...dev ? { dev: true } : {}
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
const root = doc.packages[""] ?? {};
|
|
2024
|
+
const rootDependencies = {};
|
|
2025
|
+
for (const section of ["dependencies", "devDependencies"])
|
|
2026
|
+
for (const name of Object.keys(root[section] ?? {})) {
|
|
2027
|
+
const v = doc.packages[`node_modules/${name}`]?.["version"];
|
|
2028
|
+
if (typeof v === "string") rootDependencies[name] = v;
|
|
2029
|
+
}
|
|
2030
|
+
return {
|
|
2031
|
+
lockfileVersion: String(doc.lockfileVersion),
|
|
2032
|
+
packages,
|
|
2033
|
+
rootDependencies,
|
|
2034
|
+
importerDependencies: [],
|
|
2035
|
+
snapshots: []
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
// ../../apps/build-service/src/ingest/archive-guard.ts
|
|
2040
|
+
async function extractTarballGuarded(input, limits = INGEST_LIMITS) {
|
|
2041
|
+
const files = [];
|
|
2042
|
+
let archiveBytes = 0;
|
|
2043
|
+
let unpackedBytes = 0;
|
|
2044
|
+
let entries = 0;
|
|
2045
|
+
let failure2;
|
|
2046
|
+
const hash = (0, import_node_crypto3.createHash)("sha256");
|
|
2047
|
+
const parser = new tar.Parser({ strict: true });
|
|
2048
|
+
const fail = (err) => {
|
|
2049
|
+
if (!failure2) failure2 = err;
|
|
2050
|
+
parser.abort(err);
|
|
2051
|
+
};
|
|
2052
|
+
const normalisePath = (raw) => {
|
|
2053
|
+
let p = raw;
|
|
2054
|
+
while (p.startsWith("./")) p = p.slice(2);
|
|
2055
|
+
if (p.endsWith("/")) p = p.slice(0, -1);
|
|
2056
|
+
return p;
|
|
2057
|
+
};
|
|
2058
|
+
parser.on("entry", (entry) => {
|
|
2059
|
+
entries += 1;
|
|
2060
|
+
if (entries > limits.maxEntries) {
|
|
2061
|
+
fail(new UnsafeArchiveError(`archive has more than ${limits.maxEntries} entries`));
|
|
2062
|
+
entry.resume();
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
const path = normalisePath(entry.path);
|
|
2066
|
+
if (entry.type === "Directory") {
|
|
2067
|
+
if (path !== "" && relativePathProblem(path, { allowDotfiles: true })) {
|
|
2068
|
+
fail(
|
|
2069
|
+
new UnsafeArchiveError(`unsafe directory name ${JSON.stringify(entry.path)}`, entry.path)
|
|
2070
|
+
);
|
|
2071
|
+
}
|
|
2072
|
+
entry.resume();
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
if (entry.type !== "File") {
|
|
2076
|
+
fail(
|
|
2077
|
+
new UnsafeArchiveError(
|
|
2078
|
+
`entry ${JSON.stringify(entry.path)} is a ${entry.type}; only files and directories are accepted`,
|
|
2079
|
+
entry.path
|
|
2080
|
+
)
|
|
2081
|
+
);
|
|
2082
|
+
entry.resume();
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
const problem = relativePathProblem(path, { allowDotfiles: true });
|
|
2086
|
+
if (problem) {
|
|
2087
|
+
fail(
|
|
2088
|
+
new UnsafeArchiveError(
|
|
2089
|
+
`unsafe entry name ${JSON.stringify(entry.path)}: ${problem}`,
|
|
2090
|
+
entry.path
|
|
2091
|
+
)
|
|
2092
|
+
);
|
|
2093
|
+
entry.resume();
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
if (entry.size > limits.maxFileBytes) {
|
|
2097
|
+
fail(
|
|
2098
|
+
new UnsafeArchiveError(
|
|
2099
|
+
`${path} is ${entry.size} bytes; single file cap is ${limits.maxFileBytes}`,
|
|
2100
|
+
path
|
|
2101
|
+
)
|
|
2102
|
+
);
|
|
2103
|
+
entry.resume();
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
unpackedBytes += entry.size;
|
|
2107
|
+
if (unpackedBytes > limits.maxUnpackedBytes) {
|
|
2108
|
+
fail(new UnsafeArchiveError(`unpacked size exceeds ${limits.maxUnpackedBytes} bytes`, path));
|
|
2109
|
+
entry.resume();
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
const chunks = [];
|
|
2113
|
+
entry.on("data", (c) => chunks.push(c));
|
|
2114
|
+
entry.on("end", () => {
|
|
2115
|
+
if (!failure2) files.push({ path, bytes: Buffer.concat(chunks) });
|
|
2116
|
+
});
|
|
2117
|
+
});
|
|
2118
|
+
const done = new Promise((resolve, reject) => {
|
|
2119
|
+
parser.on("end", resolve);
|
|
2120
|
+
parser.on("error", reject);
|
|
2121
|
+
parser.on("abort", () => reject(failure2 ?? new UnsafeArchiveError("archive parsing aborted")));
|
|
2122
|
+
});
|
|
2123
|
+
try {
|
|
2124
|
+
for await (const chunk of input) {
|
|
2125
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
2126
|
+
archiveBytes += buf.byteLength;
|
|
2127
|
+
if (archiveBytes > limits.maxArchiveBytes) {
|
|
2128
|
+
fail(new UnsafeArchiveError(`archive exceeds ${limits.maxArchiveBytes} bytes`));
|
|
2129
|
+
break;
|
|
2130
|
+
}
|
|
2131
|
+
hash.update(buf);
|
|
2132
|
+
parser.write(buf);
|
|
2133
|
+
if (archiveBytes >= limits.ratioCheckAfterBytes && unpackedBytes / archiveBytes > limits.maxCompressionRatio) {
|
|
2134
|
+
fail(new UnsafeArchiveError(`compression ratio exceeds ${limits.maxCompressionRatio}`));
|
|
2135
|
+
break;
|
|
2136
|
+
}
|
|
2137
|
+
if (failure2) break;
|
|
2138
|
+
}
|
|
2139
|
+
if (!failure2) parser.end();
|
|
2140
|
+
await done;
|
|
2141
|
+
} catch (e) {
|
|
2142
|
+
if (failure2) throw failure2;
|
|
2143
|
+
if (e instanceof UnsafeArchiveError) throw e;
|
|
2144
|
+
throw new UnsafeArchiveError(`archive is not a readable tar(.gz): ${e.message}`);
|
|
2145
|
+
}
|
|
2146
|
+
if (failure2) throw failure2;
|
|
2147
|
+
return {
|
|
2148
|
+
files: sortLeaves(files),
|
|
2149
|
+
archiveBytes,
|
|
2150
|
+
unpackedBytes,
|
|
2151
|
+
archiveSha256: hash.digest("hex")
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
// ../../apps/build-service/src/review/static-checks.ts
|
|
2156
|
+
var import_node_fs3 = require("node:fs");
|
|
2157
|
+
var import_node_path3 = require("node:path");
|
|
2158
|
+
var import_acorn = require("acorn");
|
|
2159
|
+
var import_acorn_walk = require("acorn-walk");
|
|
2160
|
+
var import_zod = require("zod");
|
|
2161
|
+
var FINDINGS_MAX = 50;
|
|
2162
|
+
var isClientScript = (p) => /^client\/assets\/[A-Za-z0-9._-]+\.m?js$/.test(p);
|
|
2163
|
+
var calleeName = (callee) => {
|
|
2164
|
+
if (callee.type === "Identifier") return callee.name;
|
|
2165
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") return callee.property.name;
|
|
2166
|
+
if (callee.type === "MemberExpression" && callee.computed && callee.property?.type === "Literal" && typeof callee.property.value === "string") return callee.property.value;
|
|
2167
|
+
if (callee.type === "SequenceExpression") return calleeName(callee.expressions[callee.expressions.length - 1]);
|
|
2168
|
+
return null;
|
|
2169
|
+
};
|
|
2170
|
+
function evalFindings(path, source) {
|
|
2171
|
+
let ast;
|
|
2172
|
+
try {
|
|
2173
|
+
ast = (0, import_acorn.parse)(source, { ecmaVersion: "latest", sourceType: "module", locations: true });
|
|
2174
|
+
} catch {
|
|
2175
|
+
try {
|
|
2176
|
+
ast = (0, import_acorn.parse)(source, { ecmaVersion: "latest", sourceType: "script", locations: true });
|
|
2177
|
+
} catch (e) {
|
|
2178
|
+
return [{ path, code: "parse_error", message: `${path} does not parse as JavaScript: ${e.message}` }];
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
const out = [];
|
|
2182
|
+
const at = (n) => `${path}:${n.loc?.start.line ?? 0}:${(n.loc?.start.column ?? 0) + 1}`;
|
|
2183
|
+
(0, import_acorn_walk.full)(ast, (node) => {
|
|
2184
|
+
if (node.type !== "CallExpression" && node.type !== "NewExpression") return;
|
|
2185
|
+
const n = node;
|
|
2186
|
+
const name = calleeName(n.callee);
|
|
2187
|
+
if (name === "eval" && node.type === "CallExpression") out.push({ path: at(node), code: "eval", message: `${at(node)} calls eval(). Remove it: the storefront never allows code from strings.` });
|
|
2188
|
+
else if (name === "Function") out.push({ path: at(node), code: "new_function", message: `${at(node)} builds a function from a string (${node.type === "NewExpression" ? "new " : ""}Function). Remove it: the storefront never allows code from strings.` });
|
|
2189
|
+
else if ((name === "setTimeout" || name === "setInterval") && node.type === "CallExpression") {
|
|
2190
|
+
const first = n.arguments?.[0];
|
|
2191
|
+
if (first && (first.type === "Literal" && typeof first.value === "string" || first.type === "TemplateLiteral"))
|
|
2192
|
+
out.push({ path: at(node), code: "string_timer", message: `${at(node)} passes a string to ${name}. Pass a function instead.` });
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
return out;
|
|
2196
|
+
}
|
|
2197
|
+
function noEvalLine(files) {
|
|
2198
|
+
const scripts = files.filter((f) => isClientScript(f.path));
|
|
2199
|
+
const errors = scripts.flatMap((f) => evalFindings(f.path, f.bytes.toString("utf8"))).slice(0, FINDINGS_MAX);
|
|
2200
|
+
return errors.length ? { status: "failed", message: errors[0].message, errors } : { status: "passed", message: `No eval, new Function or string timer in ${scripts.length} client script(s).`, errors: [] };
|
|
2201
|
+
}
|
|
2202
|
+
var themeLicencesSchema = import_zod.z.object({
|
|
2203
|
+
$comment: import_zod.z.string().optional(),
|
|
2204
|
+
allowlist: import_zod.z.array(import_zod.z.string().regex(/^[A-Za-z0-9.+-]+$/)).min(1),
|
|
2205
|
+
sources: import_zod.z.array(import_zod.z.string().min(1)).min(1),
|
|
2206
|
+
packages: import_zod.z.record(import_zod.z.string())
|
|
2207
|
+
});
|
|
2208
|
+
var DEFAULT_THEME_LICENCES_PATH = (0, import_node_path3.join)(__dirname, "..", "..", "config", "theme-licences.json");
|
|
2209
|
+
function loadThemeLicences(path = DEFAULT_THEME_LICENCES_PATH) {
|
|
2210
|
+
const parsed = themeLicencesSchema.safeParse(JSON.parse((0, import_node_fs3.readFileSync)(path, "utf8")));
|
|
2211
|
+
if (!parsed.success) throw new Error(`theme licence table ${path} is invalid: ${parsed.error.issues[0]?.message}`);
|
|
2212
|
+
return parsed.data;
|
|
2213
|
+
}
|
|
2214
|
+
function expressionAllowed(expr, allow) {
|
|
2215
|
+
const tokens = expr.replace(/[()]/g, (m) => ` ${m} `).trim().split(/\s+/).filter(Boolean);
|
|
2216
|
+
let i = 0;
|
|
2217
|
+
const primary = () => {
|
|
2218
|
+
const t = tokens[i++];
|
|
2219
|
+
if (t === void 0) return null;
|
|
2220
|
+
if (t === "(") {
|
|
2221
|
+
const v2 = orExpr();
|
|
2222
|
+
if (tokens[i++] !== ")") return null;
|
|
2223
|
+
return v2;
|
|
2224
|
+
}
|
|
2225
|
+
if (/^(AND|OR|WITH|\))$/i.test(t)) return null;
|
|
2226
|
+
if (tokens[i]?.toUpperCase() === "WITH") {
|
|
2227
|
+
i += 2;
|
|
2228
|
+
return false;
|
|
2229
|
+
}
|
|
2230
|
+
return !t.endsWith("+") && allow.has(t);
|
|
2231
|
+
};
|
|
2232
|
+
const andExpr = () => {
|
|
2233
|
+
let v2 = primary();
|
|
2234
|
+
while (v2 !== null && tokens[i]?.toUpperCase() === "AND") {
|
|
2235
|
+
i++;
|
|
2236
|
+
const r = primary();
|
|
2237
|
+
v2 = r === null ? null : v2 && r;
|
|
2238
|
+
}
|
|
2239
|
+
return v2;
|
|
2240
|
+
};
|
|
2241
|
+
function orExpr() {
|
|
2242
|
+
let v2 = andExpr();
|
|
2243
|
+
while (v2 !== null && tokens[i]?.toUpperCase() === "OR") {
|
|
2244
|
+
i++;
|
|
2245
|
+
const r = andExpr();
|
|
2246
|
+
v2 = r === null ? null : v2 || r;
|
|
2247
|
+
}
|
|
2248
|
+
return v2;
|
|
2249
|
+
}
|
|
2250
|
+
const v = orExpr();
|
|
2251
|
+
return v === true && i === tokens.length;
|
|
2252
|
+
}
|
|
2253
|
+
function licenceOf(table, name, version) {
|
|
2254
|
+
const exact = table.packages[`${name}@${version}`] ?? table.packages[name];
|
|
2255
|
+
if (exact !== void 0) return exact;
|
|
2256
|
+
for (const [k, v] of Object.entries(table.packages)) {
|
|
2257
|
+
if (!k.includes("*")) continue;
|
|
2258
|
+
const re = new RegExp(`^${k.split("*").map((x) => x.replace(/[.+?^${}()|[\]\\/]/g, "\\$&")).join("[^/@]*")}$`);
|
|
2259
|
+
if (re.test(name)) return v;
|
|
2260
|
+
}
|
|
2261
|
+
return void 0;
|
|
2262
|
+
}
|
|
2263
|
+
function licencesLine(files, table) {
|
|
2264
|
+
const errors = [];
|
|
2265
|
+
if (!files.some((f) => f.path === "LICENSE"))
|
|
2266
|
+
errors.push({ path: "LICENSE", code: "licence_file_missing", message: "The theme has no LICENSE file. Add one at the root of the source: it is copied into the artifact." });
|
|
2267
|
+
const sbomFile = files.find((f) => f.path === "sbom.cdx.json");
|
|
2268
|
+
let components = [];
|
|
2269
|
+
if (!sbomFile) errors.push({ path: "sbom.cdx.json", code: "sbom_missing", message: "The artifact has no sbom.cdx.json." });
|
|
2270
|
+
else {
|
|
2271
|
+
try {
|
|
2272
|
+
const doc = JSON.parse(sbomFile.bytes.toString("utf8"));
|
|
2273
|
+
components = Array.isArray(doc.components) ? doc.components : [];
|
|
2274
|
+
} catch {
|
|
2275
|
+
errors.push({ path: "sbom.cdx.json", code: "sbom_invalid", message: "sbom.cdx.json is not JSON." });
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
const allow = new Set(table.allowlist);
|
|
2279
|
+
const devOnly = components.filter((c) => c.scope === "excluded").length;
|
|
2280
|
+
components = components.filter((c) => c.scope !== "excluded");
|
|
2281
|
+
for (const c of components) {
|
|
2282
|
+
const name = typeof c.name === "string" ? c.name : "?";
|
|
2283
|
+
const version = typeof c.version === "string" ? c.version : "?";
|
|
2284
|
+
const licence = licenceOf(table, name, version);
|
|
2285
|
+
if (licence === void 0)
|
|
2286
|
+
errors.push({ path: `${name}@${version}`, code: "licence_unknown", message: `${name}@${version} is neither a toolchain package nor on the mirror allowlist, so its licence is not known. Use only those packages.` });
|
|
2287
|
+
else if (!expressionAllowed(licence, allow))
|
|
2288
|
+
errors.push({ path: `${name}@${version}`, code: "licence_not_allowed", message: `${name}@${version} is licensed ${licence}, which is not on the allowed list (${table.allowlist.join(", ")}).` });
|
|
2289
|
+
if (errors.length >= FINDINGS_MAX) break;
|
|
2290
|
+
}
|
|
2291
|
+
return errors.length ? { status: "failed", message: errors[0].message, errors: errors.slice(0, FINDINGS_MAX) } : {
|
|
2292
|
+
status: "passed",
|
|
2293
|
+
message: `A LICENSE file, and ${components.length} SBOM component(s) all on the allowed licence list.${devOnly ? ` ${devOnly} development-only component(s) are not shipped and not counted.` : ""}`,
|
|
2294
|
+
errors: []
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
// ../../apps/build-service/src/review/partner-source.ts
|
|
2299
|
+
var BRAND_RE = new RegExp(Buffer.from("c2hvcGlmeQ==", "base64").toString(), "i");
|
|
2300
|
+
var EMOJI = /([\p{Extended_Pictographic}\u{1F1E6}-\u{1F1FF}])(\u{FE0F})?/gu;
|
|
2301
|
+
var TEXT_FORM_ALLOWED = /* @__PURE__ */ new Set(["\xA9", "\xAE", "\u2122"]);
|
|
2302
|
+
var hasEmoji = (s) => [...s.matchAll(EMOJI)].some(([, ch, vs]) => vs || !TEXT_FORM_ALLOWED.has(ch));
|
|
2303
|
+
var LABEL_KEYS = /* @__PURE__ */ new Set(["name", "title", "label", "info", "placeholder", "description"]);
|
|
2304
|
+
var line = (key, errors, passed) => errors.length ? { key, status: "failed", message: errors[0].message, errors: errors.slice(0, 50) } : { key, status: "passed", message: passed, errors: [] };
|
|
2305
|
+
function treeOf(dir) {
|
|
2306
|
+
const out = [];
|
|
2307
|
+
const walk = (abs) => {
|
|
2308
|
+
for (const name of (0, import_node_fs4.readdirSync)(abs).sort()) {
|
|
2309
|
+
const p = (0, import_node_path4.join)(abs, name);
|
|
2310
|
+
if ((0, import_node_fs4.statSync)(p).isDirectory()) walk(p);
|
|
2311
|
+
else out.push({ path: (0, import_node_path4.relative)(dir, p).split(import_node_path4.sep).join("/"), bytes: (0, import_node_fs4.readFileSync)(p) });
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
walk(dir);
|
|
2315
|
+
return out;
|
|
2316
|
+
}
|
|
2317
|
+
var failure = (e) => ({
|
|
2318
|
+
path: e.path?.toString() ?? "",
|
|
2319
|
+
code: e instanceof BuildServiceError ? String(e.kind ?? e.name) : "error",
|
|
2320
|
+
message: e.message
|
|
2321
|
+
});
|
|
2322
|
+
async function editabilityLine(files, imageFetch) {
|
|
2323
|
+
const text = {};
|
|
2324
|
+
for (const f of files) {
|
|
2325
|
+
if (!/^(src\/.+\.(tsx|ts|jsx|js)|locales\/[^/]+\.json|templates\/[^/]+\.json|regions\/[^/]+\.json|config\/settings\.json)$/.test(f.path)) continue;
|
|
2326
|
+
if (f.bytes.subarray(0, 8192).includes(0)) continue;
|
|
2327
|
+
text[f.path] = f.bytes.toString("utf8");
|
|
2328
|
+
}
|
|
2329
|
+
const r = (0, import_editability.checkEditability)(text);
|
|
2330
|
+
const errs = r.errors.map((e) => ({ path: `${e.file}:${e.line}:${e.column}`, code: e.code, message: `${e.message}${e.fix ? ` Fix: ${e.fix}` : ""}` }));
|
|
2331
|
+
if (imageFetch) {
|
|
2332
|
+
const img = await (0, import_editability.checkImageLinks)(text, { fetch: imageFetch });
|
|
2333
|
+
for (const e of img.errors) errs.push({ path: `${e.file}:${e.line}:${e.column}`, code: e.code, message: `${e.message}${e.fix ? ` Fix: ${e.fix}` : ""}` });
|
|
2334
|
+
}
|
|
2335
|
+
return line("editability", errs, `${r.score.editable} settings; every section's words, images and links are editable (${r.score.percent} %)${r.warnings.length ? `; ${r.warnings.length} warning(s)` : ""}`);
|
|
2336
|
+
}
|
|
2337
|
+
async function checkPartnerSource(tgz, built, opts = {}) {
|
|
2338
|
+
const lines = [];
|
|
2339
|
+
let files = [];
|
|
2340
|
+
try {
|
|
2341
|
+
files = (await extractTarballGuarded(import_node_stream.Readable.from([tgz]))).files;
|
|
2342
|
+
} catch (e) {
|
|
2343
|
+
lines.push(line("archive", [failure(e)], ""));
|
|
2344
|
+
}
|
|
2345
|
+
let ingest = null;
|
|
2346
|
+
try {
|
|
2347
|
+
ingest = new IngestGate({ mirrorHosts: [], allowlist: loadMirrorAllowlist(), thirdParty: true }).inspect(files);
|
|
2348
|
+
lines.push(line("ingest_gate", [], `${ingest.layout} layout, ${ingest.files.length} build input(s)`));
|
|
2349
|
+
} catch (e) {
|
|
2350
|
+
lines.push(line("ingest_gate", [failure(e)], ""));
|
|
2351
|
+
}
|
|
2352
|
+
const pkg = JSON.parse(files.find((f) => f.path === "package.json")?.bytes.toString("utf8") ?? "{}");
|
|
2353
|
+
const pinOf = (name) => pkg["dependencies"]?.[name] ?? pkg["devDependencies"]?.[name];
|
|
2354
|
+
const toolchains = JSON.parse((0, import_node_fs4.readFileSync)(THIRD_PARTY_TOOLCHAINS_PATH, "utf8"));
|
|
2355
|
+
const kits = loadThirdPartyKits().map((k) => k.version);
|
|
2356
|
+
const starterAbi = toolchains.starter?.packages?.find((p) => p.name === "@tanqory/theme-abi")?.version;
|
|
2357
|
+
const build = [];
|
|
2358
|
+
const kit = pinOf("@tanqory/theme-kit");
|
|
2359
|
+
if (!kit || !kits.includes(kit))
|
|
2360
|
+
build.push({ path: "package.json", code: "kit_not_carried", message: `package.json pins @tanqory/theme-kit ${JSON.stringify(kit ?? null)}; the builder carries ${kits.join(", ")}. Pin one of those exactly.` });
|
|
2361
|
+
const abi = pinOf("@tanqory/theme-abi");
|
|
2362
|
+
if (abi !== void 0 && ingest?.layout !== "theme-source" && abi !== starterAbi)
|
|
2363
|
+
build.push({ path: "package.json", code: "abi_not_carried", message: `package.json pins @tanqory/theme-abi ${JSON.stringify(abi)}; the builder's starter toolchain carries ${starterAbi}. Pin that exactly.` });
|
|
2364
|
+
lines.push(line("sandbox_build", build, `@tanqory/theme-kit ${kit} and @tanqory/theme-abi ${abi ?? "(not pinned)"} are carried by the builder`));
|
|
2365
|
+
const text = [];
|
|
2366
|
+
for (const f of files) {
|
|
2367
|
+
if (BRAND_RE.test(f.path)) text.push({ path: f.path, code: "brand_term", message: `The file name ${f.path} names another commerce platform. Rename it.` });
|
|
2368
|
+
else if (!f.bytes.subarray(0, 8192).includes(0)) {
|
|
2369
|
+
const s = f.bytes.toString("utf8");
|
|
2370
|
+
const i = s.search(BRAND_RE);
|
|
2371
|
+
if (i >= 0) {
|
|
2372
|
+
const at = s.slice(0, i).split("\n").length;
|
|
2373
|
+
text.push({ path: `${f.path}:${at}`, code: "brand_term", message: `${f.path} line ${at} names another commerce platform. Use your theme's own words.` });
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
lines.push(line("source_text", text, `${files.length} source file(s) checked`));
|
|
2378
|
+
lines.push(await editabilityLine(files, opts.imageFetch));
|
|
2379
|
+
if (built) {
|
|
2380
|
+
const out = treeOf(built);
|
|
2381
|
+
const manifestFile = out.find((f) => f.path === "manifest.json");
|
|
2382
|
+
let manifest = null;
|
|
2383
|
+
const mErrors = [];
|
|
2384
|
+
if (!manifestFile) mErrors.push({ path: "manifest.json", code: "manifest_missing", message: `The build wrote no manifest.json in ${built}.` });
|
|
2385
|
+
else {
|
|
2386
|
+
manifest = JSON.parse(manifestFile.bytes.toString("utf8"));
|
|
2387
|
+
const r = (0, import_theme_abi2.validateManifest)(manifest, { artifactFiles: out.map((f) => f.path) });
|
|
2388
|
+
if (!r.ok) for (const e of r.errors) mErrors.push({ path: e.path, code: e.code, message: e.message });
|
|
2389
|
+
}
|
|
2390
|
+
lines.push(line("manifest", mErrors, "theme-manifest v2: schema and semantic checks passed"));
|
|
2391
|
+
const labels = [];
|
|
2392
|
+
const walk = (v, path, key) => {
|
|
2393
|
+
if (typeof v === "string") {
|
|
2394
|
+
if (key !== null && LABEL_KEYS.has(key)) labels.push([path || "/", v]);
|
|
2395
|
+
} else if (Array.isArray(v)) v.forEach((x, i) => walk(x, `${path}/${i}`, key));
|
|
2396
|
+
else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, `${path}/${k.replace(/~/g, "~0").replace(/\//g, "~1")}`, k);
|
|
2397
|
+
};
|
|
2398
|
+
walk(manifest, "", null);
|
|
2399
|
+
lines.push(line("manifest_brand_term", labels.filter(([, s]) => BRAND_RE.test(s)).map(([path]) => ({ path, code: "brand_term", message: `${path} names another commerce platform.` })), `${labels.length} label(s) checked`));
|
|
2400
|
+
lines.push(line("manifest_emoji", labels.filter(([, s]) => hasEmoji(s)).map(([path]) => ({ path, code: "emoji", message: `${path} contains an emoji.` })), `${labels.length} label(s) checked`));
|
|
2401
|
+
const noEval = noEvalLine(out);
|
|
2402
|
+
lines.push({ key: "no_eval", ...noEval });
|
|
2403
|
+
if (ingest) {
|
|
2404
|
+
const sbom = serializeSbom({
|
|
2405
|
+
lockfile: ingest.lockfile,
|
|
2406
|
+
themeName: ingest.packageJson.name,
|
|
2407
|
+
themeVersion: ingest.packageJson.version,
|
|
2408
|
+
sourceDigest: ingest.sourceDigest,
|
|
2409
|
+
inputDigest: sha256Digest(Buffer.from("partner-source-check"))
|
|
2410
|
+
});
|
|
2411
|
+
lines.push({ key: "licences", ...licencesLine([...out, { path: "sbom.cdx.json", bytes: sbom }], loadThemeLicences()) });
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return { tgzBytes: tgz.length, layout: ingest?.layout ?? null, lines };
|
|
2415
|
+
}
|
|
2416
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2417
|
+
0 && (module.exports = {
|
|
2418
|
+
checkPartnerSource,
|
|
2419
|
+
editabilityLine
|
|
2420
|
+
});
|