@tanqory/partner-cli 0.1.0-alpha.0 → 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.
@@ -6,6 +6,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
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
+ };
9
16
  var __export = (target, all) => {
10
17
  for (var name in all)
11
18
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -28,16 +35,726 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
35
  ));
29
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
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
+
31
746
  // ../../apps/build-service/src/review/partner-source.ts
32
747
  var partner_source_exports = {};
33
748
  __export(partner_source_exports, {
34
- checkPartnerSource: () => checkPartnerSource
749
+ checkPartnerSource: () => checkPartnerSource,
750
+ editabilityLine: () => editabilityLine
35
751
  });
36
752
  module.exports = __toCommonJS(partner_source_exports);
37
753
  var import_node_fs4 = require("node:fs");
38
754
  var import_node_path4 = require("node:path");
39
755
  var import_node_stream = require("node:stream");
40
756
  var import_theme_abi2 = require("@tanqory/theme-abi");
757
+ var import_editability = __toESM(require_editability());
41
758
 
42
759
  // ../../apps/build-service/src/artifact/digest.ts
43
760
  var import_node_crypto = require("node:crypto");
@@ -76,6 +793,42 @@ function splitPackageKey(key) {
76
793
  if (at <= 0) throw new LockfileParseError(`unparseable package key: ${key}`);
77
794
  return { name: key.slice(0, at), version: key.slice(at + 1) };
78
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
+ }
79
832
  function parsePnpmLockfile(bytes) {
80
833
  let doc;
81
834
  try {
@@ -88,8 +841,11 @@ function parsePnpmLockfile(bytes) {
88
841
  const root = doc;
89
842
  const lockfileVersion = String(root["lockfileVersion"] ?? "");
90
843
  if (!lockfileVersion) throw new LockfileParseError("pnpm-lock.yaml has no lockfileVersion");
91
- const packages = [];
92
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 = [];
93
849
  for (const [key, entry] of Object.entries(rawPackages)) {
94
850
  const { name, version } = splitPackageKey(key);
95
851
  const resolution = entry?.["resolution"] ?? {};
@@ -97,12 +853,11 @@ function parsePnpmLockfile(bytes) {
97
853
  name,
98
854
  version,
99
855
  ...typeof resolution["integrity"] === "string" ? { integrity: resolution["integrity"] } : {},
100
- ...typeof resolution["tarball"] === "string" ? { tarball: resolution["tarball"] } : {}
856
+ ...typeof resolution["tarball"] === "string" ? { tarball: resolution["tarball"] } : {},
857
+ ...shipped && !shipped.has(key) ? { dev: true } : {}
101
858
  });
102
859
  }
103
860
  const rootDependencies = {};
104
- const importers = root["importers"] ?? {};
105
- const importer = importers["."] ?? {};
106
861
  for (const section of ["dependencies", "optionalDependencies", "devDependencies"]) {
107
862
  const deps = importer[section] ?? {};
108
863
  for (const [name, spec] of Object.entries(deps)) {
@@ -171,7 +926,12 @@ function buildCycloneDxSbom(input) {
171
926
  version: p.version,
172
927
  purl: purlOf(p.name, p.version),
173
928
  "bom-ref": purlOf(p.name, p.version),
174
- ...hash ? { hashes: [hash] } : {}
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" } : {}
175
935
  };
176
936
  }).sort((a, b) => a.purl < b.purl ? -1 : a.purl > b.purl ? 1 : 0);
177
937
  const direct = Object.entries(input.lockfile.rootDependencies).map(([name, version]) => purlOf(name, version)).sort();
@@ -203,14 +963,21 @@ function serializeSbom(input) {
203
963
  var ApiException = class extends Error {
204
964
  constructor(errorCode, options = {}) {
205
965
  super(options.message || String(errorCode));
206
- this.errorCode = String(errorCode).toLowerCase().replace(/\s+/g, "_");
207
- this.httpStatus = options.httpStatus ?? 500;
966
+ const code = String(errorCode).toLowerCase().replace(/\s+/g, "_");
967
+ const status = options.httpStatus ?? 500;
968
+ this.errorCode = code;
969
+ this.httpStatus = status;
208
970
  this.param = options.param;
209
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 } };
210
974
  }
211
975
  getStatus() {
212
976
  return this.httpStatus;
213
977
  }
978
+ getResponse() {
979
+ return this.response;
980
+ }
214
981
  };
215
982
 
216
983
  // ../../apps/build-service/src/common/errors/build-service-errors.ts
@@ -1227,17 +1994,30 @@ function parseNpmLockfile(bytes) {
1227
1994
  if (typeof doc.lockfileVersion !== "number" || doc.lockfileVersion < 2 || !doc.packages)
1228
1995
  throw new Error('package-lock.json lockfileVersion must be 2 or 3 with a "packages" map');
1229
1996
  const packages = [];
1230
- const seen = /* @__PURE__ */ new Set();
1997
+ const seen = /* @__PURE__ */ new Map();
1231
1998
  for (const [key, entry] of Object.entries(doc.packages)) {
1232
1999
  if (!key.startsWith("node_modules/") || entry["link"]) continue;
1233
2000
  const name = key.slice(key.lastIndexOf("node_modules/") + "node_modules/".length);
1234
2001
  const version = entry["version"];
1235
- if (typeof version !== "string" || seen.has(`${name}@${version}`)) continue;
1236
- seen.add(`${name}@${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);
1237
2016
  packages.push({
1238
2017
  name,
1239
2018
  version,
1240
- ...typeof entry["integrity"] === "string" ? { integrity: entry["integrity"] } : {}
2019
+ ...typeof entry["integrity"] === "string" ? { integrity: entry["integrity"] } : {},
2020
+ ...dev ? { dev: true } : {}
1241
2021
  });
1242
2022
  }
1243
2023
  const root = doc.packages[""] ?? {};
@@ -1496,6 +2276,8 @@ function licencesLine(files, table) {
1496
2276
  }
1497
2277
  }
1498
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");
1499
2281
  for (const c of components) {
1500
2282
  const name = typeof c.name === "string" ? c.name : "?";
1501
2283
  const version = typeof c.version === "string" ? c.version : "?";
@@ -1506,7 +2288,11 @@ function licencesLine(files, table) {
1506
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(", ")}).` });
1507
2289
  if (errors.length >= FINDINGS_MAX) break;
1508
2290
  }
1509
- return errors.length ? { status: "failed", message: errors[0].message, errors: errors.slice(0, FINDINGS_MAX) } : { status: "passed", message: `A LICENSE file, and ${components.length} SBOM component(s) all on the allowed licence list.`, errors: [] };
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
+ };
1510
2296
  }
1511
2297
 
1512
2298
  // ../../apps/build-service/src/review/partner-source.ts
@@ -1533,7 +2319,22 @@ var failure = (e) => ({
1533
2319
  code: e instanceof BuildServiceError ? String(e.kind ?? e.name) : "error",
1534
2320
  message: e.message
1535
2321
  });
1536
- async function checkPartnerSource(tgz, built) {
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 = {}) {
1537
2338
  const lines = [];
1538
2339
  let files = [];
1539
2340
  try {
@@ -1574,6 +2375,7 @@ async function checkPartnerSource(tgz, built) {
1574
2375
  }
1575
2376
  }
1576
2377
  lines.push(line("source_text", text, `${files.length} source file(s) checked`));
2378
+ lines.push(await editabilityLine(files, opts.imageFetch));
1577
2379
  if (built) {
1578
2380
  const out = treeOf(built);
1579
2381
  const manifestFile = out.find((f) => f.path === "manifest.json");
@@ -1613,5 +2415,6 @@ async function checkPartnerSource(tgz, built) {
1613
2415
  }
1614
2416
  // Annotate the CommonJS export names for ESM import in node:
1615
2417
  0 && (module.exports = {
1616
- checkPartnerSource
2418
+ checkPartnerSource,
2419
+ editabilityLine
1617
2420
  });