@decocms/parity 0.33.24 → 0.33.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +475 -204
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -19173,7 +19173,7 @@ var require_formdata = __commonJS(function(exports, module) {
19173
19173
  var { webidl } = require_webidl();
19174
19174
  var nodeUtil = __require("node:util");
19175
19175
 
19176
- class FormData {
19176
+ class FormData2 {
19177
19177
  #state = [];
19178
19178
  constructor(form = undefined) {
19179
19179
  webidl.util.markAsUncloneable(this);
@@ -19186,7 +19186,7 @@ var require_formdata = __commonJS(function(exports, module) {
19186
19186
  }
19187
19187
  }
19188
19188
  append(name, value, filename = undefined) {
19189
- webidl.brandCheck(this, FormData);
19189
+ webidl.brandCheck(this, FormData2);
19190
19190
  const prefix = "FormData.append";
19191
19191
  webidl.argumentLengthCheck(arguments, 2, prefix);
19192
19192
  name = webidl.converters.USVString(name);
@@ -19202,14 +19202,14 @@ var require_formdata = __commonJS(function(exports, module) {
19202
19202
  this.#state.push(entry);
19203
19203
  }
19204
19204
  delete(name) {
19205
- webidl.brandCheck(this, FormData);
19205
+ webidl.brandCheck(this, FormData2);
19206
19206
  const prefix = "FormData.delete";
19207
19207
  webidl.argumentLengthCheck(arguments, 1, prefix);
19208
19208
  name = webidl.converters.USVString(name);
19209
19209
  this.#state = this.#state.filter((entry) => entry.name !== name);
19210
19210
  }
19211
19211
  get(name) {
19212
- webidl.brandCheck(this, FormData);
19212
+ webidl.brandCheck(this, FormData2);
19213
19213
  const prefix = "FormData.get";
19214
19214
  webidl.argumentLengthCheck(arguments, 1, prefix);
19215
19215
  name = webidl.converters.USVString(name);
@@ -19220,21 +19220,21 @@ var require_formdata = __commonJS(function(exports, module) {
19220
19220
  return this.#state[idx].value;
19221
19221
  }
19222
19222
  getAll(name) {
19223
- webidl.brandCheck(this, FormData);
19223
+ webidl.brandCheck(this, FormData2);
19224
19224
  const prefix = "FormData.getAll";
19225
19225
  webidl.argumentLengthCheck(arguments, 1, prefix);
19226
19226
  name = webidl.converters.USVString(name);
19227
19227
  return this.#state.filter((entry) => entry.name === name).map((entry) => entry.value);
19228
19228
  }
19229
19229
  has(name) {
19230
- webidl.brandCheck(this, FormData);
19230
+ webidl.brandCheck(this, FormData2);
19231
19231
  const prefix = "FormData.has";
19232
19232
  webidl.argumentLengthCheck(arguments, 1, prefix);
19233
19233
  name = webidl.converters.USVString(name);
19234
19234
  return this.#state.findIndex((entry) => entry.name === name) !== -1;
19235
19235
  }
19236
19236
  set(name, value, filename = undefined) {
19237
- webidl.brandCheck(this, FormData);
19237
+ webidl.brandCheck(this, FormData2);
19238
19238
  const prefix = "FormData.set";
19239
19239
  webidl.argumentLengthCheck(arguments, 2, prefix);
19240
19240
  name = webidl.converters.USVString(name);
@@ -19283,11 +19283,11 @@ var require_formdata = __commonJS(function(exports, module) {
19283
19283
  formData.#state = newState;
19284
19284
  }
19285
19285
  }
19286
- var { getFormDataState, setFormDataState } = FormData;
19287
- Reflect.deleteProperty(FormData, "getFormDataState");
19288
- Reflect.deleteProperty(FormData, "setFormDataState");
19289
- iteratorMixin("FormData", FormData, getFormDataState, "name", "value");
19290
- Object.defineProperties(FormData.prototype, {
19286
+ var { getFormDataState, setFormDataState } = FormData2;
19287
+ Reflect.deleteProperty(FormData2, "getFormDataState");
19288
+ Reflect.deleteProperty(FormData2, "setFormDataState");
19289
+ iteratorMixin("FormData", FormData2, getFormDataState, "name", "value");
19290
+ Object.defineProperties(FormData2.prototype, {
19291
19291
  append: kEnumerableProperty,
19292
19292
  delete: kEnumerableProperty,
19293
19293
  get: kEnumerableProperty,
@@ -19314,8 +19314,8 @@ var require_formdata = __commonJS(function(exports, module) {
19314
19314
  }
19315
19315
  return { name, value };
19316
19316
  }
19317
- webidl.is.FormData = webidl.util.MakeTypeAssertion(FormData);
19318
- module.exports = { FormData, makeEntry, setFormDataState };
19317
+ webidl.is.FormData = webidl.util.MakeTypeAssertion(FormData2);
19318
+ module.exports = { FormData: FormData2, makeEntry, setFormDataState };
19319
19319
  });
19320
19320
 
19321
19321
  // ../../node_modules/.bun/undici@7.25.0/node_modules/undici/lib/web/fetch/formdata-parser.js
@@ -19595,7 +19595,7 @@ var require_body = __commonJS(function(exports, module) {
19595
19595
  fullyReadBody,
19596
19596
  extractMimeType
19597
19597
  } = require_util2();
19598
- var { FormData, setFormDataState } = require_formdata();
19598
+ var { FormData: FormData2, setFormDataState } = require_formdata();
19599
19599
  var { webidl } = require_webidl();
19600
19600
  var assert = __require("node:assert");
19601
19601
  var { isErrored, isDisturbed } = __require("node:stream");
@@ -19785,13 +19785,13 @@ ${normalizeLinefeeds(value)}\r
19785
19785
  switch (mimeType.essence) {
19786
19786
  case "multipart/form-data": {
19787
19787
  const parsed = multipartFormDataParser(value, mimeType);
19788
- const fd = new FormData;
19788
+ const fd = new FormData2;
19789
19789
  setFormDataState(fd, parsed);
19790
19790
  return fd;
19791
19791
  }
19792
19792
  case "application/x-www-form-urlencoded": {
19793
19793
  const entries = new URLSearchParams(value.toString());
19794
- const fd = new FormData;
19794
+ const fd = new FormData2;
19795
19795
  for (const [name, value] of entries) {
19796
19796
  fd.append(name, value);
19797
19797
  }
@@ -57480,8 +57480,8 @@ function printResult(result, meta) {
57480
57480
  }
57481
57481
 
57482
57482
  // src/commands/cms.ts
57483
- import { existsSync as existsSync14, mkdirSync as mkdirSync9, readFileSync as readFileSync17, writeFileSync as writeFileSync13 } from "node:fs";
57484
- import { dirname as dirname4, join as join19 } from "node:path";
57483
+ import { existsSync as existsSync14, mkdirSync as mkdirSync10, readFileSync as readFileSync17, writeFileSync as writeFileSync14 } from "node:fs";
57484
+ import { dirname as dirname4, join as join20 } from "node:path";
57485
57485
  import chalk7 from "chalk";
57486
57486
 
57487
57487
  // src/cms/client.ts
@@ -57837,23 +57837,337 @@ function describeSession(state) {
57837
57837
  return `${login ?? "?"} on ${account ?? "?"}${left}`;
57838
57838
  }
57839
57839
 
57840
+ // src/cms/media.ts
57841
+ import { createHash as createHash3 } from "node:crypto";
57842
+
57843
+ // src/migrate/vtex/content-assets.ts
57844
+ import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync13 } from "node:fs";
57845
+ import { join as join18 } from "node:path";
57846
+ var MAX_IMAGES = 150;
57847
+ var IMG_EXT = /\.(jpe?g|png|webp|gif|svg|avif)(\?|#|$)/i;
57848
+ var VTEX_ASSET = /vtexassets\.com|vteximg\.com\.br|\/arquivos\/(ids|assets)\//i;
57849
+ function isImageUrl(s) {
57850
+ if (typeof s !== "string")
57851
+ return false;
57852
+ const v = s.trim();
57853
+ if (!/^(https?:)?\/\//i.test(v))
57854
+ return false;
57855
+ return IMG_EXT.test(v) || VTEX_ASSET.test(v);
57856
+ }
57857
+ function isImageRef(s) {
57858
+ if (typeof s !== "string")
57859
+ return false;
57860
+ const v = s.trim();
57861
+ if (isImageUrl(v))
57862
+ return true;
57863
+ return v.startsWith("/") && !v.startsWith("//") && (IMG_EXT.test(v) || VTEX_ASSET.test(v) || v.startsWith("/img/"));
57864
+ }
57865
+ function resolveRef(ref, baseUrl) {
57866
+ const v = ref.trim();
57867
+ try {
57868
+ if (v.startsWith("//"))
57869
+ return `https:${v}`;
57870
+ return new URL(v, baseUrl).toString();
57871
+ } catch {
57872
+ return null;
57873
+ }
57874
+ }
57875
+ function collectImageRefs(blocks, baseUrl) {
57876
+ const out = {};
57877
+ const walk = (v) => {
57878
+ if (typeof v === "string") {
57879
+ const s = v.trim();
57880
+ if (isImageRef(s) && !(s in out)) {
57881
+ const abs = resolveRef(s, baseUrl);
57882
+ if (abs)
57883
+ out[s] = abs;
57884
+ }
57885
+ } else if (Array.isArray(v)) {
57886
+ for (const x of v)
57887
+ walk(x);
57888
+ } else if (v && typeof v === "object") {
57889
+ for (const x of Object.values(v))
57890
+ walk(x);
57891
+ }
57892
+ };
57893
+ for (const b of blocks)
57894
+ if (b.props)
57895
+ walk(b.props);
57896
+ return out;
57897
+ }
57898
+ function countContentImages(blocks) {
57899
+ const urls = new Set;
57900
+ const walk = (v) => {
57901
+ if (typeof v === "string") {
57902
+ if (isImageUrl(v.trim()))
57903
+ urls.add(v.trim());
57904
+ } else if (Array.isArray(v)) {
57905
+ for (const x of v)
57906
+ walk(x);
57907
+ } else if (v && typeof v === "object") {
57908
+ for (const x of Object.values(v))
57909
+ walk(x);
57910
+ }
57911
+ };
57912
+ for (const b of blocks)
57913
+ if (b.props)
57914
+ walk(b.props);
57915
+ return urls.size;
57916
+ }
57917
+ function rewriteBlockUrls(blocks, urlToPath) {
57918
+ const replace = (v) => {
57919
+ if (typeof v === "string")
57920
+ return urlToPath[v.trim()] ?? v;
57921
+ if (Array.isArray(v))
57922
+ return v.map(replace);
57923
+ if (v && typeof v === "object") {
57924
+ const out = {};
57925
+ for (const [k, val] of Object.entries(v))
57926
+ out[k] = replace(val);
57927
+ return out;
57928
+ }
57929
+ return v;
57930
+ };
57931
+ return blocks.map((b) => ({
57932
+ ...b,
57933
+ props: b.props ? replace(b.props) : b.props
57934
+ }));
57935
+ }
57936
+ function contentImageName(url, index, used) {
57937
+ let base = "img";
57938
+ try {
57939
+ base = new URL(url, "https://x").pathname.split("/").filter(Boolean).pop() ?? "img";
57940
+ } catch {}
57941
+ base = base.split("?")[0].replace(/[^\w.-]/g, "_").slice(-60) || "img";
57942
+ if (!/\.(jpe?g|png|webp|gif|svg|avif)$/i.test(base))
57943
+ base += ".img";
57944
+ let name = base;
57945
+ if (used.has(name))
57946
+ name = `${index}-${base}`;
57947
+ used.add(name);
57948
+ return name;
57949
+ }
57950
+ async function downloadContentImages(urls, runDir, fetchBytes) {
57951
+ const map = {};
57952
+ if (urls.length === 0)
57953
+ return { map, downloaded: 0, skipped: 0 };
57954
+ const dir = join18(runDir, "assets", "content");
57955
+ mkdirSync9(dir, { recursive: true });
57956
+ const used = new Set;
57957
+ const take = urls.slice(0, MAX_IMAGES);
57958
+ let downloaded = 0;
57959
+ for (const [i, url] of take.entries()) {
57960
+ const got = await fetchBytes(url.startsWith("//") ? `https:${url}` : url);
57961
+ if (!got)
57962
+ continue;
57963
+ const name = contentImageName(url, i, used);
57964
+ writeFileSync13(join18(dir, name), got.buf);
57965
+ map[url] = `assets/content/${name}`;
57966
+ downloaded++;
57967
+ }
57968
+ return { map, downloaded, skipped: Math.max(0, urls.length - take.length) };
57969
+ }
57970
+
57971
+ // src/cms/media.ts
57972
+ var GATEWAY = "_v/private/graphql/v1?workspace=master";
57973
+ var FILE_MANAGER = "vtex.file-manager-graphql@0.x";
57974
+ var ADMIN_CMS = "vtex.admin-cms-graphql-rc@1.x";
57975
+ function authHeaders(cfg, env = process.env) {
57976
+ const key = env.VTEX_APP_KEY;
57977
+ const token = env.VTEX_APP_TOKEN;
57978
+ return {
57979
+ cookie: `VtexIdclientAutCookie=${cfg.token}`,
57980
+ ...key && token ? { "X-VTEX-API-AppKey": key, "X-VTEX-API-AppToken": token } : {}
57981
+ };
57982
+ }
57983
+ function gatewayUrl(cfg) {
57984
+ return `https://${cfg.account}.myvtex.com/${GATEWAY}`;
57985
+ }
57986
+ function unwrapGraphql(body, what) {
57987
+ const err = body.errors?.[0]?.message;
57988
+ if (err) {
57989
+ const hint = /token|unauthor|forbidden/i.test(err) ? " — run `vtex login`, the toolbelt token expires daily" : "";
57990
+ throw new Error(`${what}: ${err}${hint}`);
57991
+ }
57992
+ if (!body.data)
57993
+ throw new Error(`${what}: empty response`);
57994
+ return body.data;
57995
+ }
57996
+ async function uploadToFileManager(cfg, file) {
57997
+ const form = new FormData;
57998
+ form.append("operations", JSON.stringify({
57999
+ query: `mutation($file: Upload!) { uploadFile(file: $file) @context(provider: "${FILE_MANAGER}") { fileUrl } }`,
58000
+ variables: { file: null }
58001
+ }));
58002
+ form.append("map", JSON.stringify({ "0": ["variables.file"] }));
58003
+ form.append("0", new Blob([new Uint8Array(file.bytes)], { type: file.mimetype }), file.filename);
58004
+ const res = await fetch(gatewayUrl(cfg), { method: "POST", headers: authHeaders(cfg), body: form });
58005
+ const text = await res.text().catch(() => "");
58006
+ if (!res.ok)
58007
+ throw new Error(`uploadFile ${file.filename}: HTTP ${res.status} ${text.slice(0, 300)}`);
58008
+ const data = unwrapGraphql(JSON.parse(text), `uploadFile ${file.filename}`);
58009
+ const url = data.uploadFile?.fileUrl;
58010
+ if (!url)
58011
+ throw new Error(`uploadFile ${file.filename}: no fileUrl in response`);
58012
+ return url;
58013
+ }
58014
+ async function registerInGallery(cfg, item) {
58015
+ const body = {
58016
+ query: `mutation($input: CreateContentInput!) {
58017
+ createContent(input: $input) @context(provider: "${ADMIN_CMS}") { content { id } }
58018
+ }`,
58019
+ variables: {
58020
+ input: {
58021
+ contentInput: { contentName: item.filename, contentTypeId: "image", builderId: "cms" },
58022
+ variantInput: [
58023
+ {
58024
+ variantConfigurationDataSet: [
58025
+ {
58026
+ configurationDataSetName: "Image",
58027
+ configurations: [
58028
+ {
58029
+ configurationDataName: "Image",
58030
+ data: {
58031
+ url: item.fileUrl,
58032
+ name: item.filename,
58033
+ mimetype: item.mimetype,
58034
+ encoding: "",
58035
+ extension: "",
58036
+ alternativeText: item.alt ?? "",
58037
+ size: item.size
58038
+ }
58039
+ }
58040
+ ]
58041
+ }
58042
+ ],
58043
+ variantSections: []
58044
+ }
58045
+ ]
58046
+ }
58047
+ }
58048
+ };
58049
+ const res = await fetch(gatewayUrl(cfg), {
58050
+ method: "POST",
58051
+ headers: { ...authHeaders(cfg), "content-type": "application/json" },
58052
+ body: JSON.stringify(body)
58053
+ });
58054
+ const text = await res.text().catch(() => "");
58055
+ if (!res.ok)
58056
+ throw new Error(`createContent ${item.filename}: HTTP ${res.status} ${text.slice(0, 300)}`);
58057
+ const data = unwrapGraphql(JSON.parse(text), `createContent ${item.filename}`);
58058
+ const id = data.createContent?.content?.id;
58059
+ if (!id)
58060
+ throw new Error(`createContent ${item.filename}: no content id in response`);
58061
+ return id;
58062
+ }
58063
+ function putMedia(cfg) {
58064
+ const seen = new Map;
58065
+ return async (file) => {
58066
+ const digest = createHash3("sha256").update(file.bytes).digest("hex");
58067
+ const hit = seen.get(digest);
58068
+ if (hit)
58069
+ return hit;
58070
+ const fileUrl = await uploadToFileManager(cfg, file);
58071
+ await registerInGallery(cfg, {
58072
+ fileUrl,
58073
+ filename: file.filename,
58074
+ mimetype: file.mimetype,
58075
+ size: file.bytes.byteLength
58076
+ });
58077
+ seen.set(digest, fileUrl);
58078
+ return fileUrl;
58079
+ };
58080
+ }
58081
+ function collectMediaUrls(data) {
58082
+ const out = [];
58083
+ const walk = (node, path) => {
58084
+ if (typeof node === "string") {
58085
+ const url = node.trim();
58086
+ if (isImageUrl(url))
58087
+ out.push({ path, url });
58088
+ } else if (Array.isArray(node)) {
58089
+ node.forEach((v, i) => walk(v, `${path}[${i}]`));
58090
+ } else if (node && typeof node === "object") {
58091
+ for (const [k, v] of Object.entries(node))
58092
+ walk(v, path ? `${path}.${k}` : k);
58093
+ }
58094
+ };
58095
+ walk(data, "");
58096
+ return out;
58097
+ }
58098
+ function foreignMedia(refs, account) {
58099
+ const own = new RegExp(`^${account}\\.vtexassets\\.com$|^${account}\\.vteximg\\.com\\.br$`, "i");
58100
+ return refs.filter((r) => {
58101
+ try {
58102
+ return !own.test(new URL(r.url.startsWith("//") ? `https:${r.url}` : r.url).hostname);
58103
+ } catch {
58104
+ return false;
58105
+ }
58106
+ });
58107
+ }
58108
+ function filenameFor(url) {
58109
+ try {
58110
+ const base = new URL(url, "https://x").pathname.split("/").filter(Boolean).pop() ?? "image";
58111
+ return decodeURIComponent(base).replace(/[^\w.\- ]/g, "_").slice(-80) || "image";
58112
+ } catch {
58113
+ return "image";
58114
+ }
58115
+ }
58116
+ async function rehostMedia(data, opts) {
58117
+ const byUrl = new Map;
58118
+ for (const ref of foreignMedia(collectMediaUrls(data), opts.account)) {
58119
+ byUrl.set(ref.url, [...byUrl.get(ref.url) ?? [], ref.path]);
58120
+ }
58121
+ const report = [];
58122
+ const swap = new Map;
58123
+ for (const [url, paths] of byUrl) {
58124
+ const got = await opts.fetchBytes(url.startsWith("//") ? `https:${url}` : url);
58125
+ if (!got) {
58126
+ report.push({ url, paths, rehosted: null, reason: "source unreachable" });
58127
+ continue;
58128
+ }
58129
+ try {
58130
+ const rehosted = await opts.put({
58131
+ bytes: got.buf,
58132
+ filename: filenameFor(url),
58133
+ mimetype: got.contentType?.split(";")[0]?.trim() || "application/octet-stream"
58134
+ });
58135
+ swap.set(url, rehosted);
58136
+ report.push({ url, paths, rehosted });
58137
+ } catch (err) {
58138
+ report.push({ url, paths, rehosted: null, reason: err instanceof Error ? err.message : String(err) });
58139
+ }
58140
+ }
58141
+ const replace = (node) => {
58142
+ if (typeof node === "string")
58143
+ return swap.get(node.trim()) ?? node;
58144
+ if (Array.isArray(node))
58145
+ return node.map(replace);
58146
+ if (node && typeof node === "object") {
58147
+ return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, replace(v)]));
58148
+ }
58149
+ return node;
58150
+ };
58151
+ return { data: replace(data), report };
58152
+ }
58153
+
57840
58154
  // src/cms/schema.ts
57841
58155
  import { readFileSync as readFileSync16, readdirSync as readdirSync3, existsSync as existsSync13 } from "node:fs";
57842
- import { join as join18 } from "node:path";
58156
+ import { join as join19 } from "node:path";
57843
58157
  function publishedComponentKeys(contentType) {
57844
58158
  const items = contentType?.properties?.sections?.items;
57845
58159
  const anyOf = items?.anyOf ?? [];
57846
58160
  return anyOf.map((s) => String(s.$componentKey ?? "")).filter(Boolean);
57847
58161
  }
57848
58162
  function localComponentKeys(repoDir, contentType) {
57849
- const dir = join18(repoDir, "cms", "faststore", "pages");
58163
+ const dir = join19(repoDir, "cms", "faststore", "pages");
57850
58164
  if (!existsSync13(dir))
57851
58165
  return null;
57852
58166
  const wanted = `cms_content_type__${contentType.toLowerCase()}.jsonc`;
57853
58167
  const file = readdirSync3(dir).find((f) => f.toLowerCase() === wanted);
57854
58168
  if (!file)
57855
58169
  return null;
57856
- const raw = readFileSync16(join18(dir, file), "utf8");
58170
+ const raw = readFileSync16(join19(dir, file), "utf8");
57857
58171
  const start = raw.indexOf('"sections"');
57858
58172
  if (start < 0)
57859
58173
  return [];
@@ -57923,7 +58237,7 @@ function parseJsonc(raw) {
57923
58237
  return JSON.parse(out);
57924
58238
  }
57925
58239
  function localComponentSchemas(repoDir) {
57926
- const dir = join18(repoDir, "cms", "faststore", "components");
58240
+ const dir = join19(repoDir, "cms", "faststore", "components");
57927
58241
  if (!existsSync13(dir))
57928
58242
  return {};
57929
58243
  const out = {};
@@ -57931,7 +58245,7 @@ function localComponentSchemas(repoDir) {
57931
58245
  if (!file.endsWith(".jsonc"))
57932
58246
  continue;
57933
58247
  try {
57934
- const parsed = parseJsonc(readFileSync16(join18(dir, file), "utf8"));
58248
+ const parsed = parseJsonc(readFileSync16(join19(dir, file), "utf8"));
57935
58249
  if (!parsed.$componentKey)
57936
58250
  continue;
57937
58251
  out[parsed.$componentKey] = {
@@ -58045,16 +58359,16 @@ function newPageData(template, page) {
58045
58359
  };
58046
58360
  }
58047
58361
  function writeRejectedPayload(entryId, body) {
58048
- const out = join19("parity-output", "cms-backups", `${entryId}-rejected.json`);
58049
- mkdirSync9(dirname4(out), { recursive: true });
58050
- writeFileSync13(out, `${JSON.stringify(body, null, 2)}
58362
+ const out = join20("parity-output", "cms-backups", `${entryId}-rejected.json`);
58363
+ mkdirSync10(dirname4(out), { recursive: true });
58364
+ writeFileSync14(out, `${JSON.stringify(body, null, 2)}
58051
58365
  `);
58052
58366
  return out;
58053
58367
  }
58054
58368
  function writeBackup(version) {
58055
- const backup = join19("parity-output", "cms-backups", `${version.entryId}-${version.baseHash.slice(0, 12)}.json`);
58056
- mkdirSync9(dirname4(backup), { recursive: true });
58057
- writeFileSync13(backup, `${JSON.stringify(version, null, 2)}
58369
+ const backup = join20("parity-output", "cms-backups", `${version.entryId}-${version.baseHash.slice(0, 12)}.json`);
58370
+ mkdirSync10(dirname4(backup), { recursive: true });
58371
+ writeFileSync14(backup, `${JSON.stringify(version, null, 2)}
58058
58372
  `);
58059
58373
  return backup;
58060
58374
  }
@@ -58191,7 +58505,7 @@ async function cmsSchemaPushCommand(opts, call = callCms, registryCall = callReg
58191
58505
  const cfg = config();
58192
58506
  if (!cfg)
58193
58507
  return 1;
58194
- const schemaPath = join19(opts.repo, "cms", "faststore", "schema.json");
58508
+ const schemaPath = join20(opts.repo, "cms", "faststore", "schema.json");
58195
58509
  if (!existsSync14(schemaPath)) {
58196
58510
  return fail(new Error(`No such file: ${schemaPath}. Generate it first (\`vtex content generate-schema\`).`));
58197
58511
  }
@@ -58275,9 +58589,9 @@ async function cmsPullCommand(opts, call = callCms) {
58275
58589
  return fail(branch);
58276
58590
  try {
58277
58591
  const version = await getLastVersion(cfg, { contentType: opts.contentType, entryId: opts.entry, branchId: branch }, call);
58278
- const out = opts.out ?? join19("parity-output", "cms", `${opts.contentType}-${opts.entry}.json`);
58279
- mkdirSync9(dirname4(out), { recursive: true });
58280
- writeFileSync13(out, `${JSON.stringify(version, null, 2)}
58592
+ const out = opts.out ?? join20("parity-output", "cms", `${opts.contentType}-${opts.entry}.json`);
58593
+ mkdirSync10(dirname4(out), { recursive: true });
58594
+ writeFileSync14(out, `${JSON.stringify(version, null, 2)}
58281
58595
  `);
58282
58596
  if (opts.json) {
58283
58597
  console.log(JSON.stringify({ out, sections: sectionsOf(version.data).length }, null, 2));
@@ -58371,6 +58685,12 @@ async function cmsPushCommand(opts, call = callCms, deliveryCall = callDelivery)
58371
58685
  const richTextRisk = richTextCombinationRisk(used);
58372
58686
  if (richTextRisk)
58373
58687
  console.log(`${chalk7.yellow("!")} ${richTextRisk}`);
58688
+ const foreign = foreignImagesIn(cfg, local.data);
58689
+ if (foreign.length > 0) {
58690
+ const hosts = [...new Set(foreign.map((r) => new URL(r.url).hostname))].join(", ");
58691
+ console.log(`${chalk7.yellow("!")} ${foreign.length} image(s) hosted off-account (${hosts}) — they rot when that host rotates a key or expires a signed URL.
58692
+ parity cms media rehost --file ${opts.file} --yes`);
58693
+ }
58374
58694
  if (!opts.yes) {
58375
58695
  console.log(chalk7.yellow("dry run — nothing written. Pass --yes to commit."));
58376
58696
  for (const line of summarizeSections(local.data))
@@ -58607,6 +58927,83 @@ async function cmsRmCommand(opts, call = callCms) {
58607
58927
  return fail(err);
58608
58928
  }
58609
58929
  }
58930
+ function foreignImagesIn(cfg, data) {
58931
+ return foreignMedia(collectMediaUrls(data), cfg.account);
58932
+ }
58933
+ async function cmsMediaScanCommand(opts) {
58934
+ const cfg = config();
58935
+ if (!cfg)
58936
+ return 1;
58937
+ const local = readPulled(opts.file);
58938
+ if (local instanceof Error)
58939
+ return fail(local);
58940
+ const foreign = foreignImagesIn(cfg, local.data);
58941
+ const checked = await Promise.all(foreign.map(async (ref) => {
58942
+ const status = await fetch(ref.url, { method: "HEAD", signal: AbortSignal.timeout(15000) }).then((r) => r.status).catch(() => 0);
58943
+ return { ...ref, status };
58944
+ }));
58945
+ if (opts.json) {
58946
+ console.log(JSON.stringify({ total: collectMediaUrls(local.data).length, foreign: checked }, null, 2));
58947
+ return 0;
58948
+ }
58949
+ const total = collectMediaUrls(local.data).length;
58950
+ if (checked.length === 0) {
58951
+ console.log(`${chalk7.green("✓")} ${total} image(s), all served by ${cfg.account}`);
58952
+ return 0;
58953
+ }
58954
+ console.log(`${checked.length} of ${total} image(s) live on another host:`);
58955
+ for (const r of checked) {
58956
+ const mark = r.status === 200 ? chalk7.yellow("!") : chalk7.red("✗");
58957
+ const code = r.status === 0 ? "unreachable" : String(r.status);
58958
+ console.log(` ${mark} ${code} ${new URL(r.url).hostname} ${chalk7.dim(r.path)}`);
58959
+ }
58960
+ console.log(chalk7.dim(` fix: parity cms media rehost --file ${opts.file} --yes`));
58961
+ return checked.some((r) => r.status !== 200) ? 1 : 0;
58962
+ }
58963
+ async function cmsMediaRehostCommand(opts, fetchBytes = nodeFetchBytes) {
58964
+ const cfg = config();
58965
+ if (!cfg)
58966
+ return 1;
58967
+ const local = readPulled(opts.file);
58968
+ if (local instanceof Error)
58969
+ return fail(local);
58970
+ const foreign = foreignImagesIn(cfg, local.data);
58971
+ if (foreign.length === 0) {
58972
+ console.log(`${chalk7.green("✓")} nothing to rehost — every image is already on ${cfg.account}`);
58973
+ return 0;
58974
+ }
58975
+ if (!opts.yes) {
58976
+ console.log(chalk7.yellow("dry run — nothing uploaded. Pass --yes to rehost."));
58977
+ for (const r of foreign)
58978
+ console.log(` ${new URL(r.url).hostname} ${chalk7.dim(r.path)}`);
58979
+ console.log(chalk7.dim(` ${foreign.length} image(s) would be uploaded to ${cfg.account} and added to the media gallery`));
58980
+ return 0;
58981
+ }
58982
+ try {
58983
+ const { data, report } = await rehostMedia(local.data, {
58984
+ fetchBytes,
58985
+ put: putMedia(cfg),
58986
+ account: cfg.account
58987
+ });
58988
+ const failed = report.filter((r) => !r.rehosted);
58989
+ writeFileSync14(opts.file, `${JSON.stringify({ ...local, data }, null, 2)}
58990
+ `);
58991
+ if (opts.json) {
58992
+ console.log(JSON.stringify({ file: opts.file, report }, null, 2));
58993
+ return failed.length > 0 ? 1 : 0;
58994
+ }
58995
+ for (const r of report.filter((x) => x.rehosted)) {
58996
+ console.log(`${chalk7.green("✓")} ${r.paths.length}× ${chalk7.dim(r.url.slice(0, 70))}`);
58997
+ console.log(` → ${r.rehosted}`);
58998
+ }
58999
+ for (const r of failed)
59000
+ console.log(`${chalk7.red("✗")} ${r.url.slice(0, 70)} — ${r.reason}`);
59001
+ console.log(chalk7.dim(` ${opts.file} rewritten · next: parity cms diff --file ${opts.file}`));
59002
+ return failed.length > 0 ? 1 : 0;
59003
+ } catch (err) {
59004
+ return fail(err);
59005
+ }
59006
+ }
58610
59007
 
58611
59008
  // src/commands/compare.ts
58612
59009
  import chalk8 from "chalk";
@@ -58975,7 +59372,7 @@ async function cssTraceCommand(opts) {
58975
59372
  }
58976
59373
 
58977
59374
  // src/commands/e2e.ts
58978
- import { writeFileSync as writeFileSync15 } from "node:fs";
59375
+ import { writeFileSync as writeFileSync16 } from "node:fs";
58979
59376
  import { spawn as spawn2 } from "node:child_process";
58980
59377
  import chalk11 from "chalk";
58981
59378
  import ora6 from "ora";
@@ -59927,8 +60324,8 @@ async function flowLogin(ctx) {
59927
60324
 
59928
60325
  // src/llm/resolve-search-terms.ts
59929
60326
  init_client();
59930
- import { existsSync as existsSync15, mkdirSync as mkdirSync10, readFileSync as readFileSync18, writeFileSync as writeFileSync14 } from "node:fs";
59931
- import { join as join20 } from "node:path";
60327
+ import { existsSync as existsSync15, mkdirSync as mkdirSync11, readFileSync as readFileSync18, writeFileSync as writeFileSync15 } from "node:fs";
60328
+ import { join as join21 } from "node:path";
59932
60329
  var CACHE_DIR2 = ".parity-cache";
59933
60330
  var FALLBACK_TERMS = ["produto", "preto", "promocao"];
59934
60331
  function makeNoResults(runId) {
@@ -60008,7 +60405,7 @@ async function resolveSearchTerms(url, html, opts = {}) {
60008
60405
  }
60009
60406
  const host = safeHost3(url);
60010
60407
  const cacheDir = opts.cacheDir ?? CACHE_DIR2;
60011
- const cachePath = join20(cacheDir, `search-terms-${host}.json`);
60408
+ const cachePath = join21(cacheDir, `search-terms-${host}.json`);
60012
60409
  if (!opts.noCache && existsSync15(cachePath)) {
60013
60410
  try {
60014
60411
  const cached = JSON.parse(readFileSync18(cachePath, "utf8"));
@@ -60020,8 +60417,8 @@ async function resolveSearchTerms(url, html, opts = {}) {
60020
60417
  const suggested = await suggestTermViaLlm(url, html);
60021
60418
  if (suggested) {
60022
60419
  if (!existsSync15(cacheDir))
60023
- mkdirSync10(cacheDir, { recursive: true });
60024
- writeFileSync14(cachePath, `${JSON.stringify({ withResults: suggested, source: "llm" }, null, 2)}
60420
+ mkdirSync11(cacheDir, { recursive: true });
60421
+ writeFileSync15(cachePath, `${JSON.stringify({ withResults: suggested, source: "llm" }, null, 2)}
60025
60422
  `, "utf8");
60026
60423
  return { withResults: suggested, noResults };
60027
60424
  }
@@ -61239,8 +61636,8 @@ async function e2eCommand(opts) {
61239
61636
  generatedAt: new Date().toISOString(),
61240
61637
  durationMs
61241
61638
  });
61242
- writeFileSync15(paths.reportHtml, html, "utf8");
61243
- writeFileSync15(paths.reportJson, `${JSON.stringify({
61639
+ writeFileSync16(paths.reportHtml, html, "utf8");
61640
+ writeFileSync16(paths.reportJson, `${JSON.stringify({
61244
61641
  runId,
61245
61642
  mode: "e2e",
61246
61643
  url: opts.url,
@@ -61445,7 +61842,7 @@ ${JSON.stringify(checks.map((c) => ({ name: c.name, status: c.status, summary: c
61445
61842
  }
61446
61843
 
61447
61844
  // src/commands/extract.ts
61448
- import { mkdirSync as mkdirSync14 } from "node:fs";
61845
+ import { mkdirSync as mkdirSync15 } from "node:fs";
61449
61846
  import { resolve as resolve4 } from "node:path";
61450
61847
  import chalk14 from "chalk";
61451
61848
 
@@ -61776,20 +62173,20 @@ function collectCandidatesInPage() {
61776
62173
  }
61777
62174
 
61778
62175
  // src/extract/exporters/json.ts
61779
- import { writeFileSync as writeFileSync16 } from "node:fs";
61780
- import { join as join21 } from "node:path";
62176
+ import { writeFileSync as writeFileSync17 } from "node:fs";
62177
+ import { join as join22 } from "node:path";
61781
62178
  var jsonExporter = {
61782
62179
  name: "json",
61783
62180
  async export(bundle, outDir) {
61784
- const path = join21(outDir, "manifest.json");
61785
- writeFileSync16(path, `${JSON.stringify(bundle, null, 2)}
62181
+ const path = join22(outDir, "manifest.json");
62182
+ writeFileSync17(path, `${JSON.stringify(bundle, null, 2)}
61786
62183
  `, "utf8");
61787
62184
  }
61788
62185
  };
61789
62186
 
61790
62187
  // src/extract/exporters/markdown.ts
61791
- import { mkdirSync as mkdirSync11, writeFileSync as writeFileSync17 } from "node:fs";
61792
- import { join as join22 } from "node:path";
62188
+ import { mkdirSync as mkdirSync12, writeFileSync as writeFileSync18 } from "node:fs";
62189
+ import { join as join23 } from "node:path";
61793
62190
 
61794
62191
  // src/extract/naming.ts
61795
62192
  function componentDirName(role, index) {
@@ -61803,13 +62200,13 @@ var markdownExporter = {
61803
62200
  async export(bundle, outDir) {
61804
62201
  const dirNames = bundle.components.map((c, i) => componentDirName(c.role, i + 1));
61805
62202
  const indexMd = renderIndex(bundle, dirNames);
61806
- writeFileSync17(join22(outDir, "index.md"), indexMd, "utf8");
62203
+ writeFileSync18(join23(outDir, "index.md"), indexMd, "utf8");
61807
62204
  bundle.components.forEach((component, i) => {
61808
62205
  const dirName = dirNames[i];
61809
- const componentDir = join22(outDir, "components", dirName);
61810
- mkdirSync11(componentDir, { recursive: true });
62206
+ const componentDir = join23(outDir, "components", dirName);
62207
+ mkdirSync12(componentDir, { recursive: true });
61811
62208
  const readme = renderComponentReadme(bundle, component);
61812
- writeFileSync17(join22(componentDir, "README.md"), readme, "utf8");
62209
+ writeFileSync18(join23(componentDir, "README.md"), readme, "utf8");
61813
62210
  });
61814
62211
  }
61815
62212
  };
@@ -61916,7 +62313,7 @@ function truncateHtml(html, max) {
61916
62313
  }
61917
62314
 
61918
62315
  // src/extract/extract-component.ts
61919
- import { mkdirSync as mkdirSync12, writeFileSync as writeFileSync18 } from "node:fs";
62316
+ import { mkdirSync as mkdirSync13, writeFileSync as writeFileSync19 } from "node:fs";
61920
62317
 
61921
62318
  // src/engine/section-capture.ts
61922
62319
  init_esm10();
@@ -62158,7 +62555,7 @@ async function captureSectionScreenshot(page, selector, outPath, preCapturedFull
62158
62555
  // src/extract/extract-component.ts
62159
62556
  var LINK_CAP = 30;
62160
62557
  async function extractComponent(page, component, opts) {
62161
- mkdirSync12(opts.outDir, { recursive: true });
62558
+ mkdirSync13(opts.outDir, { recursive: true });
62162
62559
  const artifacts = await captureSectionArtifacts(page, {
62163
62560
  selector: component.selector,
62164
62561
  wantHtml: true,
@@ -62179,8 +62576,8 @@ async function extractComponent(page, component, opts) {
62179
62576
  links: capLinks(links, LINK_CAP),
62180
62577
  textContent
62181
62578
  };
62182
- writeFileSync18(`${opts.outDir}/component.html`, extracted.html, "utf8");
62183
- writeFileSync18(`${opts.outDir}/styles.json`, `${JSON.stringify(computedStyles ?? {}, null, 2)}
62579
+ writeFileSync19(`${opts.outDir}/component.html`, extracted.html, "utf8");
62580
+ writeFileSync19(`${opts.outDir}/styles.json`, `${JSON.stringify(computedStyles ?? {}, null, 2)}
62184
62581
  `, "utf8");
62185
62582
  return extracted;
62186
62583
  }
@@ -62268,7 +62665,7 @@ function capLinks(links, max) {
62268
62665
  }
62269
62666
 
62270
62667
  // src/commands/section.ts
62271
- import { mkdirSync as mkdirSync13 } from "node:fs";
62668
+ import { mkdirSync as mkdirSync14 } from "node:fs";
62272
62669
  import { resolve as resolve3 } from "node:path";
62273
62670
  import chalk13 from "chalk";
62274
62671
  import * as diff from "diff";
@@ -62393,8 +62790,8 @@ function analyzeHeatmapBuffer(data, width, height, opts = {}) {
62393
62790
  }
62394
62791
 
62395
62792
  // src/diff/section-bundle.ts
62396
- import { writeFileSync as writeFileSync19 } from "node:fs";
62397
- import { basename as basename2, dirname as dirname5, join as join23, relative as relative3 } from "node:path";
62793
+ import { writeFileSync as writeFileSync20 } from "node:fs";
62794
+ import { basename as basename2, dirname as dirname5, join as join24, relative as relative3 } from "node:path";
62398
62795
  function buildStyleDeltas(input) {
62399
62796
  const cs = input.computedStyles;
62400
62797
  if (!cs)
@@ -62438,12 +62835,12 @@ function assembleSectionDiffBundle(input) {
62438
62835
  boundingRects: styleResultsToRects(input.computedStyles),
62439
62836
  styleDeltas
62440
62837
  };
62441
- const jsonPath = join23(input.outDir, `${input.filePrefix}-bundle.json`);
62442
- writeFileSync19(jsonPath, `${JSON.stringify(json, mapReplacer, 2)}
62838
+ const jsonPath = join24(input.outDir, `${input.filePrefix}-bundle.json`);
62839
+ writeFileSync20(jsonPath, `${JSON.stringify(json, mapReplacer, 2)}
62443
62840
  `, "utf8");
62444
62841
  const markdown = renderMarkdownBundle(input, styleDeltas);
62445
- const markdownPath = join23(input.outDir, `${input.filePrefix}-prompt.md`);
62446
- writeFileSync19(markdownPath, markdown, "utf8");
62842
+ const markdownPath = join24(input.outDir, `${input.filePrefix}-prompt.md`);
62843
+ writeFileSync20(markdownPath, markdown, "utf8");
62447
62844
  const summary = oneLineSummary(input, styleDeltas);
62448
62845
  return { jsonPath, markdownPath, summary };
62449
62846
  }
@@ -62655,7 +63052,7 @@ async function sectionCommand(opts) {
62655
63052
  };
62656
63053
  if (want.heatmap)
62657
63054
  want.screenshot = true;
62658
- mkdirSync13(opts.outDir, { recursive: true });
63055
+ mkdirSync14(opts.outDir, { recursive: true });
62659
63056
  const hash = hashSelector(opts.selector);
62660
63057
  const filePrefix = `section-${hash}-${viewport}`;
62661
63058
  const screenshotPaths = {
@@ -63130,7 +63527,7 @@ async function extractCommand(opts) {
63130
63527
  const timestamp = new Date().toISOString();
63131
63528
  const runDirTimestamp = timestamp.replace(/[:.]/g, "-");
63132
63529
  const runDir = resolve4(opts.outDir, host, runDirTimestamp);
63133
- mkdirSync14(runDir, { recursive: true });
63530
+ mkdirSync15(runDir, { recursive: true });
63134
63531
  const browser = await launchBrowser({ headless: true });
63135
63532
  try {
63136
63533
  const resolvedPages = await resolvePages(opts.url, opts.pages);
@@ -63571,8 +63968,8 @@ function formatPatch(patch) {
63571
63968
  }
63572
63969
 
63573
63970
  // src/commands/journey.ts
63574
- import { writeFileSync as writeFileSync20 } from "node:fs";
63575
- import { join as join24 } from "node:path";
63971
+ import { writeFileSync as writeFileSync21 } from "node:fs";
63972
+ import { join as join25 } from "node:path";
63576
63973
  import chalk16 from "chalk";
63577
63974
  import ora7 from "ora";
63578
63975
  init_client();
@@ -63642,7 +64039,7 @@ async function journeyCommand(opts) {
63642
64039
  };
63643
64040
  async function runOneSide(browserInstance, viewport, side) {
63644
64041
  const baseUrl = side === "prod" ? opts.prod : opts.cand;
63645
- const tracePath = join24(paths.tracesDir, `${viewport}-${side}.zip`);
64042
+ const tracePath = join25(paths.tracesDir, `${viewport}-${side}.zip`);
63646
64043
  const ctx = await newContext(browserInstance, {
63647
64044
  viewport,
63648
64045
  tracesDir: paths.tracesDir,
@@ -63734,7 +64131,7 @@ async function journeyCommand(opts) {
63734
64131
  if (opts.github)
63735
64132
  emitGithubAnnotations(failures);
63736
64133
  if (opts.junit) {
63737
- writeFileSync20(opts.junit, buildJUnit(rows, failures), "utf8");
64134
+ writeFileSync21(opts.junit, buildJUnit(rows, failures), "utf8");
63738
64135
  if (!opts.json)
63739
64136
  console.log(chalk16.dim(` → JUnit XML: ${opts.junit}`));
63740
64137
  }
@@ -64580,12 +64977,12 @@ function compactComponentHtml(html, maxChars = COMPONENT_HTML_MAX_CHARS) {
64580
64977
  }
64581
64978
 
64582
64979
  // src/migrate/exporters/json.ts
64583
- import { writeFileSync as writeFileSync21 } from "node:fs";
64584
- import { join as join25 } from "node:path";
64980
+ import { writeFileSync as writeFileSync22 } from "node:fs";
64981
+ import { join as join26 } from "node:path";
64585
64982
  var jsonExporter2 = {
64586
64983
  name: "json",
64587
64984
  async export(bundle, outDir) {
64588
- writeFileSync21(join25(outDir, "manifest.json"), `${JSON.stringify(bundle, null, 2)}
64985
+ writeFileSync22(join26(outDir, "manifest.json"), `${JSON.stringify(bundle, null, 2)}
64589
64986
  `, "utf8");
64590
64987
  }
64591
64988
  };
@@ -64593,136 +64990,6 @@ var jsonExporter2 = {
64593
64990
  // src/migrate/exporters/markdown.ts
64594
64991
  import { mkdirSync as mkdirSync16, writeFileSync as writeFileSync23 } from "node:fs";
64595
64992
  import { join as join27 } from "node:path";
64596
-
64597
- // src/migrate/vtex/content-assets.ts
64598
- import { mkdirSync as mkdirSync15, writeFileSync as writeFileSync22 } from "node:fs";
64599
- import { join as join26 } from "node:path";
64600
- var MAX_IMAGES = 150;
64601
- var IMG_EXT = /\.(jpe?g|png|webp|gif|svg|avif)(\?|#|$)/i;
64602
- var VTEX_ASSET = /vtexassets\.com|vteximg\.com\.br|\/arquivos\/(ids|assets)\//i;
64603
- function isImageUrl(s) {
64604
- if (typeof s !== "string")
64605
- return false;
64606
- const v = s.trim();
64607
- if (!/^(https?:)?\/\//i.test(v))
64608
- return false;
64609
- return IMG_EXT.test(v) || VTEX_ASSET.test(v);
64610
- }
64611
- function isImageRef(s) {
64612
- if (typeof s !== "string")
64613
- return false;
64614
- const v = s.trim();
64615
- if (isImageUrl(v))
64616
- return true;
64617
- return v.startsWith("/") && !v.startsWith("//") && (IMG_EXT.test(v) || VTEX_ASSET.test(v) || v.startsWith("/img/"));
64618
- }
64619
- function resolveRef(ref, baseUrl) {
64620
- const v = ref.trim();
64621
- try {
64622
- if (v.startsWith("//"))
64623
- return `https:${v}`;
64624
- return new URL(v, baseUrl).toString();
64625
- } catch {
64626
- return null;
64627
- }
64628
- }
64629
- function collectImageRefs(blocks, baseUrl) {
64630
- const out = {};
64631
- const walk = (v) => {
64632
- if (typeof v === "string") {
64633
- const s = v.trim();
64634
- if (isImageRef(s) && !(s in out)) {
64635
- const abs = resolveRef(s, baseUrl);
64636
- if (abs)
64637
- out[s] = abs;
64638
- }
64639
- } else if (Array.isArray(v)) {
64640
- for (const x of v)
64641
- walk(x);
64642
- } else if (v && typeof v === "object") {
64643
- for (const x of Object.values(v))
64644
- walk(x);
64645
- }
64646
- };
64647
- for (const b of blocks)
64648
- if (b.props)
64649
- walk(b.props);
64650
- return out;
64651
- }
64652
- function countContentImages(blocks) {
64653
- const urls = new Set;
64654
- const walk = (v) => {
64655
- if (typeof v === "string") {
64656
- if (isImageUrl(v.trim()))
64657
- urls.add(v.trim());
64658
- } else if (Array.isArray(v)) {
64659
- for (const x of v)
64660
- walk(x);
64661
- } else if (v && typeof v === "object") {
64662
- for (const x of Object.values(v))
64663
- walk(x);
64664
- }
64665
- };
64666
- for (const b of blocks)
64667
- if (b.props)
64668
- walk(b.props);
64669
- return urls.size;
64670
- }
64671
- function rewriteBlockUrls(blocks, urlToPath) {
64672
- const replace = (v) => {
64673
- if (typeof v === "string")
64674
- return urlToPath[v.trim()] ?? v;
64675
- if (Array.isArray(v))
64676
- return v.map(replace);
64677
- if (v && typeof v === "object") {
64678
- const out = {};
64679
- for (const [k, val] of Object.entries(v))
64680
- out[k] = replace(val);
64681
- return out;
64682
- }
64683
- return v;
64684
- };
64685
- return blocks.map((b) => ({
64686
- ...b,
64687
- props: b.props ? replace(b.props) : b.props
64688
- }));
64689
- }
64690
- function contentImageName(url, index, used) {
64691
- let base = "img";
64692
- try {
64693
- base = new URL(url, "https://x").pathname.split("/").filter(Boolean).pop() ?? "img";
64694
- } catch {}
64695
- base = base.split("?")[0].replace(/[^\w.-]/g, "_").slice(-60) || "img";
64696
- if (!/\.(jpe?g|png|webp|gif|svg|avif)$/i.test(base))
64697
- base += ".img";
64698
- let name = base;
64699
- if (used.has(name))
64700
- name = `${index}-${base}`;
64701
- used.add(name);
64702
- return name;
64703
- }
64704
- async function downloadContentImages(urls, runDir, fetchBytes) {
64705
- const map = {};
64706
- if (urls.length === 0)
64707
- return { map, downloaded: 0, skipped: 0 };
64708
- const dir = join26(runDir, "assets", "content");
64709
- mkdirSync15(dir, { recursive: true });
64710
- const used = new Set;
64711
- const take = urls.slice(0, MAX_IMAGES);
64712
- let downloaded = 0;
64713
- for (const [i, url] of take.entries()) {
64714
- const got = await fetchBytes(url.startsWith("//") ? `https:${url}` : url);
64715
- if (!got)
64716
- continue;
64717
- const name = contentImageName(url, i, used);
64718
- writeFileSync22(join26(dir, name), got.buf);
64719
- map[url] = `assets/content/${name}`;
64720
- downloaded++;
64721
- }
64722
- return { map, downloaded, skipped: Math.max(0, urls.length - take.length) };
64723
- }
64724
-
64725
- // src/migrate/exporters/markdown.ts
64726
64993
  var markdownExporter2 = {
64727
64994
  name: "markdown",
64728
64995
  async export(bundle, outDir) {
@@ -71154,7 +71421,11 @@ program.command("cms").description("Read and write VTEX Content Platform entries
71154
71421
  out: opts.out,
71155
71422
  json: Boolean(opts.json)
71156
71423
  }));
71157
- })).addCommand(new Command("diff").description("Compare a pulled file against the branch it came from. Exit 1 when they differ.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--branch <id>", "Compare against a different branch").option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
71424
+ })).addCommand(new Command("media").description("Move the images an entry points at onto this account. Content migrated from another site keeps that site's CDN URLs, which stop working the day it rotates a key or a signed URL expires — and nobody notices until the page renders empty frames.").addCommand(new Command("scan").description("List the entry's images that are served by another host, with the status each one answers today.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
71425
+ process.exit(await cmsMediaScanCommand({ file: opts.file, json: Boolean(opts.json) }));
71426
+ })).addCommand(new Command("rehost").description("Download each off-account image, upload it to this account's File Manager, register it in the Admin's media gallery so it is pickable there, and rewrite the pulled file to the new URLs. Dry run unless --yes. Push the file afterwards.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--yes", "Actually upload and rewrite. Without it, this is a dry run.", false).option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
71427
+ process.exit(await cmsMediaRehostCommand({ file: opts.file, yes: Boolean(opts.yes), json: Boolean(opts.json) }));
71428
+ }))).addCommand(new Command("diff").description("Compare a pulled file against the branch it came from. Exit 1 when they differ.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--branch <id>", "Compare against a different branch").option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
71158
71429
  process.exit(await cmsDiffCommand({ file: opts.file, branch: opts.branch, json: Boolean(opts.json) }));
71159
71430
  })).addCommand(new Command("push").description("Commit a pulled file back. Dry run unless --yes. Refuses main without --allow-main, refuses a stale baseHash, refuses sections the account cannot render, and backs the remote up before writing.").requiredOption("--file <path>", "File written by `parity cms pull`").option("--branch <id>", "Target branch (default: the branch in the file)").option("--message <text>", "Commit message", "parity cms push").option("--author <email>", "Commit author (default: the logged-in VTEX user)").option("--yes", "Actually write. Without it, this is a dry run.", false).option("--allow-main", "Permit committing straight to main", false).option("--json", "Emit structured JSON instead of human-readable text", false).action(async (opts) => {
71160
71431
  process.exit(await cmsPushCommand({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.33.24",
3
+ "version": "0.33.25",
4
4
  "description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with an LLM-ranked HTML report.",
5
5
  "type": "module",
6
6
  "license": "MIT",