@decocms/blocks 8.10.0 → 8.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/protocol/conformance/blockMetaVectors.json +80 -0
  5. package/dist/protocol/index.d.ts +5 -2
  6. package/dist/protocol/index.d.ts.map +1 -1
  7. package/dist/protocol/index.js +5 -2
  8. package/dist/protocol/index.js.map +1 -1
  9. package/dist/v8/blockMeta.d.ts +33 -4
  10. package/dist/v8/blockMeta.d.ts.map +1 -1
  11. package/dist/v8/blockMeta.js +70 -13
  12. package/dist/v8/blockMeta.js.map +1 -1
  13. package/dist/v8/cli/index.d.ts +1 -0
  14. package/dist/v8/cli/index.d.ts.map +1 -1
  15. package/dist/v8/cli/index.js +1 -0
  16. package/dist/v8/cli/index.js.map +1 -1
  17. package/dist/v8/cli/run.d.ts +2 -0
  18. package/dist/v8/cli/run.d.ts.map +1 -1
  19. package/dist/v8/cli/run.js +30 -1
  20. package/dist/v8/cli/run.js.map +1 -1
  21. package/dist/v8/cli/skills.d.ts +25 -0
  22. package/dist/v8/cli/skills.d.ts.map +1 -0
  23. package/dist/v8/cli/skills.js +70 -0
  24. package/dist/v8/cli/skills.js.map +1 -0
  25. package/dist/v8/client.d.ts +6 -4
  26. package/dist/v8/client.d.ts.map +1 -1
  27. package/dist/v8/client.js +26 -70
  28. package/dist/v8/client.js.map +1 -1
  29. package/dist/v8/cms.d.ts.map +1 -1
  30. package/dist/v8/cms.js +1 -2
  31. package/dist/v8/cms.js.map +1 -1
  32. package/dist/v8/contentIndex.d.ts +18 -7
  33. package/dist/v8/contentIndex.d.ts.map +1 -1
  34. package/dist/v8/contentIndex.js +46 -17
  35. package/dist/v8/contentIndex.js.map +1 -1
  36. package/dist/v8/draftChanges.d.ts.map +1 -1
  37. package/dist/v8/draftChanges.js +4 -1
  38. package/dist/v8/draftChanges.js.map +1 -1
  39. package/dist/v8/index.d.ts +1 -1
  40. package/dist/v8/index.d.ts.map +1 -1
  41. package/dist/v8/remoteLoader.d.ts +4 -2
  42. package/dist/v8/remoteLoader.d.ts.map +1 -1
  43. package/dist/v8/remoteLoader.js +13 -3
  44. package/dist/v8/remoteLoader.js.map +1 -1
  45. package/dist/v8/types.d.ts +47 -7
  46. package/dist/v8/types.d.ts.map +1 -1
  47. package/package.json +3 -2
  48. package/skills/deco-apps/SKILL.md +82 -0
  49. package/skills/deco-apps/references/algolia.md +51 -0
  50. package/skills/deco-apps/references/commerce-types.md +132 -0
  51. package/skills/deco-apps/references/instrumented-fetch.md +144 -0
  52. package/skills/deco-apps/references/magento.md +55 -0
  53. package/skills/deco-apps/references/messaging.md +76 -0
  54. package/skills/deco-apps/references/shopify.md +69 -0
  55. package/skills/deco-apps/references/vendored-loaders.md +135 -0
  56. package/skills/deco-apps/references/vtex-cookies-auth.md +146 -0
  57. package/skills/deco-apps/references/vtex.md +150 -0
  58. package/skills/deco-apps/references/wake.md +75 -0
  59. package/skills/deco-cms-schema/SKILL.md +80 -0
  60. package/skills/deco-cms-schema/references/annotations.md +147 -0
  61. package/skills/deco-cms-schema/references/content-hygiene.md +91 -0
  62. package/skills/deco-cms-schema/references/formats-and-widgets.md +112 -0
  63. package/skills/deco-cms-schema/references/shapes-that-break-the-form.md +165 -0
  64. package/skills/deco-cms-schema/references/types-to-fields.md +112 -0
  65. package/skills/deco-go-live/SKILL.md +127 -0
  66. package/skills/deco-go-live/references/content-releases.md +90 -0
  67. package/skills/deco-go-live/references/process.md +106 -0
  68. package/skills/deco-go-live/references/proxy-headers-checkout.md +139 -0
  69. package/skills/deco-go-live/references/qa-checklist-template.md +150 -0
  70. package/skills/deco-go-live/references/qa-inventory.md +120 -0
  71. package/skills/deco-go-live/references/react-spa.md +183 -0
  72. package/skills/deco-go-live/references/seo-analytics.md +114 -0
  73. package/skills/deco-go-live/references/traffic-ramp.md +87 -0
  74. package/skills/deco-go-live/references/worker-runtime.md +93 -0
  75. package/skills/deco-go-live/scripts/preflight.sh +221 -0
  76. package/skills/deco-images-media/SKILL.md +64 -0
  77. package/skills/deco-images-media/references/asset-upload.md +191 -0
  78. package/skills/deco-images-media/references/components-per-binding.md +167 -0
  79. package/skills/deco-images-media/references/providers-and-cdn.md +145 -0
  80. package/skills/deco-images-media/references/quality-and-lcp.md +93 -0
  81. package/skills/deco-images-media/references/troubleshooting.md +147 -0
  82. package/skills/deco-images-media/references/video.md +122 -0
  83. package/skills/deco-make-editable/SKILL.md +94 -0
  84. package/skills/deco-make-editable/references/a11y-and-e2e.md +104 -0
  85. package/skills/deco-make-editable/references/content-shapes.md +203 -0
  86. package/skills/deco-make-editable/references/from-figma.md +110 -0
  87. package/skills/deco-make-editable/references/i18n-fields.md +112 -0
  88. package/skills/deco-make-editable/references/inventory.md +79 -0
  89. package/skills/deco-make-editable/references/pixel-parity.md +175 -0
  90. package/skills/deco-make-editable/references/seeding-content.md +119 -0
  91. package/skills/deco-nextjs-site/SKILL.md +74 -0
  92. package/skills/deco-nextjs-site/references/caching.md +116 -0
  93. package/skills/deco-nextjs-site/references/metadata-seo.md +100 -0
  94. package/skills/deco-nextjs-site/references/proxy-and-drafts.md +177 -0
  95. package/skills/deco-nextjs-site/references/rendering.md +172 -0
  96. package/skills/deco-nextjs-site/references/setup.md +190 -0
  97. package/skills/deco-nextjs-site/references/studio-bridge.md +130 -0
  98. package/skills/deco-site-authoring/SKILL.md +75 -0
  99. package/skills/deco-site-authoring/references/lazy-blocks.md +155 -0
  100. package/skills/deco-site-authoring/references/loaders.md +192 -0
  101. package/skills/deco-site-authoring/references/pages.md +158 -0
  102. package/skills/deco-site-authoring/references/review-before-publish.md +95 -0
  103. package/skills/deco-site-authoring/references/sections.md +158 -0
  104. package/skills/deco-site-authoring/references/seo.md +116 -0
  105. package/skills/deco-site-workflow/SKILL.md +101 -0
  106. package/skills/deco-site-workflow/references/check.md +116 -0
  107. package/skills/deco-site-workflow/references/cli-reference.md +106 -0
  108. package/skills/deco-site-workflow/references/content-layout.md +93 -0
  109. package/skills/deco-site-workflow/references/content-sync.md +146 -0
  110. package/skills/deco-site-workflow/references/delivery.md +51 -0
  111. package/skills/deco-site-workflow/references/deploy.md +87 -0
  112. package/skills/deco-site-workflow/references/schema.md +173 -0
  113. package/skills/deco-site-workflow/references/serve-and-studio.md +138 -0
  114. package/skills/deco-storefront-caching/SKILL.md +67 -0
  115. package/skills/deco-storefront-caching/references/cache-keys.md +129 -0
  116. package/skills/deco-storefront-caching/references/case-study.md +82 -0
  117. package/skills/deco-storefront-caching/references/egress-traps.md +153 -0
  118. package/skills/deco-storefront-caching/references/nextjs.md +60 -0
  119. package/skills/deco-storefront-caching/references/perf-guardrails-e2e.md +123 -0
  120. package/skills/deco-storefront-caching/references/verification.md +136 -0
  121. package/skills/deco-storefront-caching/references/worker-page-cache.md +160 -0
  122. package/skills/deco-storefront-caching/scripts/html-anatomy.mjs +97 -0
  123. package/skills/deco-storefront-performance/SKILL.md +81 -0
  124. package/skills/deco-storefront-performance/references/cls-third-party.md +90 -0
  125. package/skills/deco-storefront-performance/references/hydration.md +116 -0
  126. package/skills/deco-storefront-performance/references/loaders-n-plus-1.md +107 -0
  127. package/skills/deco-storefront-performance/references/navigation-ux.md +130 -0
  128. package/skills/deco-storefront-performance/references/payload-trim.md +163 -0
  129. package/skills/deco-storefront-performance/references/render-location.md +152 -0
  130. package/skills/deco-storefront-performance/references/request-dedupe.md +147 -0
  131. package/skills/deco-storefront-performance/references/trace-reading.md +79 -0
  132. package/skills/deco-storefront-performance/references/worker-memory.md +176 -0
  133. package/skills/deco-tanstack-site/SKILL.md +68 -0
  134. package/skills/deco-tanstack-site/references/document-and-security.md +155 -0
  135. package/skills/deco-tanstack-site/references/router-and-navigation.md +137 -0
  136. package/skills/deco-tanstack-site/references/routes-and-pages.md +183 -0
  137. package/skills/deco-tanstack-site/references/server-functions.md +123 -0
  138. package/skills/deco-tanstack-site/references/setup.md +153 -0
  139. package/skills/deco-tanstack-site/references/worker-entry.md +152 -0
  140. package/skills/deco-v7-to-v8-migration/SKILL.md +123 -0
  141. package/skills/deco-v7-to-v8-migration/references/caching-and-privacy.md +10 -0
  142. package/skills/deco-v7-to-v8-migration/references/content.md +25 -0
  143. package/skills/deco-v7-to-v8-migration/references/editor-forms.md +27 -0
  144. package/skills/deco-v7-to-v8-migration/references/faststore.md +40 -0
  145. package/skills/deco-v7-to-v8-migration/references/framework-code.md +53 -0
  146. package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +16 -0
  147. package/skills/deco-v7-to-v8-migration/references/import-map.md +81 -0
  148. package/skills/deco-v7-to-v8-migration/references/legacy-names.md +33 -0
  149. package/skills/deco-v7-to-v8-migration/references/manual-steps.md +10 -0
  150. package/skills/deco-v7-to-v8-migration/references/native-apps.md +43 -0
  151. package/skills/deco-v7-to-v8-migration/references/nextjs.md +19 -0
  152. package/skills/deco-v7-to-v8-migration/references/parity.md +66 -0
  153. package/skills/deco-v7-to-v8-migration/references/rendering.md +13 -0
  154. package/skills/deco-v7-to-v8-migration/references/running-the-script.md +29 -0
  155. package/skills/deco-v7-to-v8-migration/references/script-steps.md +13 -0
  156. package/skills/deco-v7-to-v8-migration/references/server-functions.md +15 -0
  157. package/skills/deco-v7-to-v8-migration/references/sibling-port.md +11 -0
  158. package/skills/deco-v7-to-v8-migration/references/site-code.md +15 -0
  159. package/skills/deco-v7-to-v8-migration/references/telemetry.md +10 -0
  160. package/skills/deco-v7-to-v8-migration/references/verify.md +23 -0
  161. package/skills/deco-v7-to-v8-migration/scripts/apps.ts +297 -0
  162. package/skills/deco-v7-to-v8-migration/scripts/asyncRendering.ts +73 -0
  163. package/skills/deco-v7-to-v8-migration/scripts/blockMap.ts +584 -0
  164. package/skills/deco-v7-to-v8-migration/scripts/checkContentReads.ts +32 -0
  165. package/skills/deco-v7-to-v8-migration/scripts/ciSchemaCheck.ts +145 -0
  166. package/skills/deco-v7-to-v8-migration/scripts/compat.ts +357 -0
  167. package/skills/deco-v7-to-v8-migration/scripts/content.ts +121 -0
  168. package/skills/deco-v7-to-v8-migration/scripts/contentReads.ts +157 -0
  169. package/skills/deco-v7-to-v8-migration/scripts/experiments.ts +81 -0
  170. package/skills/deco-v7-to-v8-migration/scripts/framework.ts +61 -0
  171. package/skills/deco-v7-to-v8-migration/scripts/imageCopy.ts +276 -0
  172. package/skills/deco-v7-to-v8-migration/scripts/imageModule.ts +285 -0
  173. package/skills/deco-v7-to-v8-migration/scripts/imports.ts +942 -0
  174. package/skills/deco-v7-to-v8-migration/scripts/invoke.ts +624 -0
  175. package/skills/deco-v7-to-v8-migration/scripts/legacyNames.ts +45 -0
  176. package/skills/deco-v7-to-v8-migration/scripts/main.ts +59 -0
  177. package/skills/deco-v7-to-v8-migration/scripts/matchers.ts +41 -0
  178. package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +180 -0
  179. package/skills/deco-v7-to-v8-migration/scripts/redirects.ts +455 -0
  180. package/skills/deco-v7-to-v8-migration/scripts/report.ts +50 -0
  181. package/skills/deco-v7-to-v8-migration/scripts/scaffold.ts +1119 -0
  182. package/skills/deco-v7-to-v8-migration/scripts/secrets.ts +35 -0
  183. package/skills/deco-v7-to-v8-migration/scripts/sectionLoaders.ts +216 -0
  184. package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +261 -0
  185. package/skills/deco-v7-to-v8-migration/scripts/stubs.ts +388 -0
  186. package/skills/deco-v7-to-v8-migration/scripts/tsconfig.json +7 -0
  187. package/skills/deco-v7-to-v8-migration/scripts/vendor.ts +249 -0
  188. package/skills/deco-v7-to-v8-migration/scripts/vtexInvoke.ts +240 -0
  189. package/skills/deco-v7-to-v8-migration/scripts/walk.ts +30 -0
  190. package/skills/deco-variants/SKILL.md +57 -0
  191. package/skills/deco-variants/references/caching-variants.md +63 -0
  192. package/skills/deco-variants/references/custom-matchers.md +83 -0
  193. package/skills/deco-variants/references/draft-preview.md +59 -0
  194. package/skills/deco-variants/references/experiments-and-campaigns.md +104 -0
  195. package/skills/deco-variants/references/multivariate.md +85 -0
  196. package/skills/deco-variants/references/v7-matchers.md +71 -0
  197. package/src/index.ts +1 -1
  198. package/src/protocol/conformance/blockMetaVectors.json +80 -0
  199. package/src/protocol/index.ts +8 -1
  200. package/src/v8/blockMeta.ts +75 -11
  201. package/src/v8/cli/index.ts +1 -0
  202. package/src/v8/cli/run.ts +35 -1
  203. package/src/v8/cli/skills.ts +91 -0
  204. package/src/v8/client.ts +32 -77
  205. package/src/v8/cms.ts +1 -2
  206. package/src/v8/contentIndex.ts +49 -19
  207. package/src/v8/draftChanges.ts +5 -1
  208. package/src/v8/index.ts +1 -1
  209. package/src/v8/remoteLoader.ts +13 -3
  210. package/src/v8/types.ts +48 -7
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Reads of the whole content, which v8 sites don't do (8.12 on): a site reads
3
+ * the index (`client.routes()`, `client.redirects()`, `client.entries(type?)`:
4
+ * names, types, paths, references and `noIndex`, never a body) and one named
5
+ * block at a time (`client.resolve(name)`). Since 8.12 `client.list(type)`
6
+ * throws; on a hosted release it fetched every block of the type
7
+ * (one request per block), and a build-time scan of `.deco/blocks` reads
8
+ * content the site no longer bundles.
9
+ *
10
+ * - `list`: a `.list(…)` call on a CMS client (`c`, `cms`, `client`,
11
+ * `…Client`, `cms.forRelease()`, `cms.forDraft(…)`, `cms.client(…)`,
12
+ * `currentClient()`): an error. `scripts/checkContentReads.ts` fails on one. `Client`
13
+ * keeps a deprecated `list` so old code compiles, so the typecheck does
14
+ * not catch one (a wrapper calling it neither): it throws at runtime.
15
+ * - `scan`: a directory read or glob of `.deco/blocks` (`readdir`,
16
+ * `readdirSync`, `glob`, `import.meta.glob`, …; `.deco/blocks.gen` is the
17
+ * content module, not a scan): reported, since a native app may bundle the
18
+ * JSON on purpose (reference/native-apps.md).
19
+ *
20
+ * The fix for both: `entries(type)` for what the index knows (a sitemap is
21
+ * the `page` entries' paths without `:param` or `*` and without `noIndex`),
22
+ * or one `resolve(name)` for one block's body (a map keyed by path becomes
23
+ * one saved block per path, found through `entries()`).
24
+ */
25
+ import fs from "node:fs";
26
+ import path from "node:path";
27
+ import ts from "typescript";
28
+ import { parse } from "./compat";
29
+ import type { Report } from "./report";
30
+
31
+ export interface ContentRead {
32
+ /** Relative to the root, with `/`. */
33
+ file: string;
34
+ /** 1-based. */
35
+ line: number;
36
+ kind: "list" | "scan";
37
+ /** The call, as written (first line). */
38
+ code: string;
39
+ }
40
+
41
+ /** Where a site keeps code: the folders scanned, under the root. */
42
+ const CODE_DIRS = ["src", "app", "server", "lib", "scripts"];
43
+ const SOURCE = /\.(tsx?|mts|cts|jsx?|mjs|cjs)$/;
44
+ const SKIPPED = new Set(["node_modules", "dist", "build", ".next", ".output", ".deco-migrate"]);
45
+
46
+ /** A receiver that is a CMS client by its name or by the call that made it. */
47
+ const CLIENT_RECEIVER =
48
+ /(?:^|[.\s(])(?:c|cms|client|[A-Za-z_$][\w$]*Client)$|\b(?:for(?:Release|Draft)|client|currentClient)\([^)]*\)$/;
49
+ /** A directory read or glob. */
50
+ const SCAN_CALL = /(?:^|\.)(?:readdir|readdirSync|opendir|opendirSync|glob|globSync|sync)$/;
51
+ /** `.deco/blocks`, the folder itself or a file in it (not `.deco/blocks.gen`). */
52
+ const BLOCKS_DIR = /\.deco\/blocks(?:$|\/|[^.\w])/;
53
+
54
+ function sourcesUnder(dir: string): string[] {
55
+ if (!fs.existsSync(dir)) return [];
56
+ const out: string[] = [];
57
+ for (const d of fs.readdirSync(dir, { withFileTypes: true })) {
58
+ if (SKIPPED.has(d.name)) continue;
59
+ const full = path.join(dir, d.name);
60
+ if (d.isDirectory()) out.push(...sourcesUnder(full));
61
+ else if (d.isFile() && SOURCE.test(d.name) && !d.name.endsWith(".d.ts")) out.push(full);
62
+ }
63
+ return out;
64
+ }
65
+
66
+ /** The text of a string literal or a template (its literal parts). */
67
+ function literalText(node: ts.Node): string | undefined {
68
+ if (ts.isStringLiteralLike(node)) return node.text;
69
+ if (ts.isTemplateExpression(node)) {
70
+ return node.head.text + node.templateSpans.map((s) => s.literal.text).join("");
71
+ }
72
+ return undefined;
73
+ }
74
+
75
+ /** Whether any argument (or a string inside it, as in `path.join(…)`) names `.deco/blocks`. */
76
+ function namesBlocksDir(args: readonly ts.Node[]): boolean {
77
+ let found = false;
78
+ const visit = (node: ts.Node): void => {
79
+ if (found) return;
80
+ const text = literalText(node);
81
+ if (text !== undefined && BLOCKS_DIR.test(text)) {
82
+ found = true;
83
+ return;
84
+ }
85
+ ts.forEachChild(node, visit);
86
+ };
87
+ for (const arg of args) visit(arg);
88
+ return found;
89
+ }
90
+
91
+ /** The receiver as written, without parentheses, `await`, `!` or spaces: `(await client())` is `client()`. */
92
+ function receiverText(node: ts.Expression, source: ts.SourceFile): string {
93
+ let inner: ts.Expression = node;
94
+ while (
95
+ ts.isParenthesizedExpression(inner) ||
96
+ ts.isAwaitExpression(inner) ||
97
+ ts.isNonNullExpression(inner)
98
+ ) {
99
+ inner = inner.expression;
100
+ }
101
+ return inner.getText(source).replace(/\s+/g, "");
102
+ }
103
+
104
+ /** Every `list` call on a CMS client and every scan of `.deco/blocks` in the site's code. */
105
+ export function findContentReads(root: string): ContentRead[] {
106
+ const files = CODE_DIRS.flatMap((dir) => sourcesUnder(path.join(root, dir))).sort();
107
+ const found: ContentRead[] = [];
108
+ for (const file of files) {
109
+ const text = fs.readFileSync(file, "utf8");
110
+ if (!text.includes(".list") && !text.includes(".deco/blocks")) continue;
111
+ const source = parse(file, text);
112
+ const at = (node: ts.Node, kind: ContentRead["kind"]) => {
113
+ const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));
114
+ found.push({
115
+ file: path.relative(root, file).split(path.sep).join("/"),
116
+ line: line + 1,
117
+ kind,
118
+ code: node.getText(source).split("\n")[0]!,
119
+ });
120
+ };
121
+ const visit = (node: ts.Node): void => {
122
+ if (ts.isCallExpression(node)) {
123
+ const callee = node.expression;
124
+ if (
125
+ ts.isPropertyAccessExpression(callee) &&
126
+ callee.name.text === "list" &&
127
+ CLIENT_RECEIVER.test(receiverText(callee.expression, source))
128
+ ) {
129
+ at(node, "list");
130
+ } else if (SCAN_CALL.test(callee.getText(source)) && namesBlocksDir(node.arguments)) {
131
+ at(node, "scan");
132
+ }
133
+ }
134
+ ts.forEachChild(node, visit);
135
+ };
136
+ visit(source);
137
+ }
138
+ return found;
139
+ }
140
+
141
+ const LIST_FIX =
142
+ "client.list() throws (removed in 8.12): route with client.routes() and client.redirects(); client.entries(type) gives names, paths and noIndex from the index (a sitemap: page paths without :param or * and without noIndex), and client.resolve(name) reads one block; a map keyed by path becomes one saved block per path";
143
+ const SCAN_FIX =
144
+ "reads every saved block at build time: content comes from the CMS now (hosted releases leave .deco/blocks behind), so read client.entries(type) for paths and noIndex, or resolve one named block; keep it only for a native app that bundles the JSON (reference/native-apps.md)";
145
+
146
+ /** The migration's report lines: one per `list` call and per scan, as work left. */
147
+ export function reportContentReads(root: string, report: Report): ContentRead[] {
148
+ const reads = findContentReads(root);
149
+ for (const read of reads) {
150
+ report.manual.push({
151
+ step: "imports",
152
+ subject: `${read.file}:${read.line}`,
153
+ message: `${read.code}: ${read.kind === "list" ? LIST_FIX : SCAN_FIX}`,
154
+ });
155
+ }
156
+ return reads;
157
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * A/B tests and dates. v7 ran tests on its random matcher and date windows on
3
+ * its date matcher; the next major keeps both in content: tests in the saved
4
+ * block `experiments` (type `split-traffic`) read by the `experiment` rule,
5
+ * date windows in the saved block `campaigns` (type `calendar`) read by the
6
+ * `campaign` rule, which names one. The script moves neither: it
7
+ * reports each kind once, for whoever moves them by hand, and says who hands
8
+ * the visitor to the client when the site has tests.
9
+ */
10
+ import { siteFramework } from "./framework";
11
+ import type { Report } from "./report";
12
+ import { forEachBlock, readContent } from "./walk";
13
+
14
+ /** v7's random matcher, under each name v7 saved it with. */
15
+ const RANDOM_MATCHERS = new Set([
16
+ "website/matchers/random.ts",
17
+ "website/matchers/random",
18
+ "$live/matchers/MatchRandom.ts",
19
+ ]);
20
+
21
+ /** A date rule: v7's names (renamed to `date` by the content step) and v8's prerelease one. */
22
+ const DATE_RULES = new Set(["date", "website/matchers/date.ts", "$live/matchers/MatchDate.ts"]);
23
+
24
+ export const RUN_AN_AB_TEST = "/next/matchers-and-variants#run-an-a-b-test";
25
+ export const SCHEDULE_A_CAMPAIGN = "/next/matchers-and-variants#schedule-a-campaign";
26
+
27
+ const quoted = (names: Iterable<string>) =>
28
+ [...names]
29
+ .sort()
30
+ .map((n) => `"${n}"`)
31
+ .join(", ");
32
+
33
+ /**
34
+ * Reports v7's random matchers and every date rule (v7's, or the prerelease
35
+ * `date`, which no longer exists): one "Left to do" line each, pointing at
36
+ * the docs. Changes no file.
37
+ */
38
+ export function reportTestsAndDates(root: string, report: Report): void {
39
+ const { blocks, files } = readContent(root);
40
+ const tests = new Set<string>();
41
+ const dates = new Set<string>();
42
+ for (const [entry, block] of Object.entries(blocks)) {
43
+ if (RANDOM_MATCHERS.has(block.__resolveType as string)) {
44
+ tests.add(entry);
45
+ continue;
46
+ }
47
+ forEachBlock(block, (node) => {
48
+ if (RANDOM_MATCHERS.has(node.__resolveType)) tests.add(entry);
49
+ else if (DATE_RULES.has(node.__resolveType)) dates.add(entry);
50
+ });
51
+ }
52
+ if (tests.size > 0) {
53
+ report.manual.push({
54
+ step: "content",
55
+ subject: "A/B tests",
56
+ message: `v7's random matchers (in ${quoted([...tests].map((n) => files[n] ?? n))}) weren't moved: put each test in the saved block experiments (type split-traffic) under its saved-block name, so visitors keep their groups and results carry over, and point its rules at { "__resolveType": "experiment", "name": … } (Run an A/B test, ${RUN_AN_AB_TEST})`,
57
+ });
58
+ reportAssignment(root, report);
59
+ }
60
+ if (dates.size > 0) {
61
+ report.manual.push({
62
+ step: "content",
63
+ subject: "date rules",
64
+ message: `date rules (in ${quoted([...dates].map((n) => files[n] ?? n))}) weren't moved, and deco check rejects them until they are: put each window in the saved block campaigns (type calendar), each start and end a date and time with the store's offset (like 2026-11-27T00:00-03:00: v7 read a date-time without one in the server's time zone, and deco check rejects it), and write each rule as { "__resolveType": "campaign", "name": … } naming its campaign (a prerelease { "__resolveType": "date", "campaign": … } becomes that rule with the same name) (Schedule a campaign, ${SCHEDULE_A_CAMPAIGN})`,
65
+ });
66
+ }
67
+ }
68
+
69
+ /** Who hands the visitor to the client, by binding: without one every test is off. */
70
+ function reportAssignment(root: string, report: Report): void {
71
+ const framework = siteFramework(root);
72
+ if (framework === "tanstack") return; // createDecoWorker reads the visitor on every page request.
73
+ report.manual.push({
74
+ step: "content",
75
+ subject: "experiments",
76
+ message:
77
+ framework === "nextjs"
78
+ ? "decide the tests in proxy.ts: draftProxy from @decocms/nextjs/proxy does it, or decideVisitor, decideAssignments, visitorRequestHeaders, assignmentsRequestHeaders and applyVisitor next to the draft calls; the catch-all page's bindDraft and contentClient(cms) then build cms.client({ version, experiments, campaigns }) from what the proxy decided"
79
+ : "hand the visitor to the client per request: const { visitor, cookie } = readVisitor(request) from @decocms/blocks/experiments, cms.client({ visitor, ...(await cms.readVersion(request)) }), and the cookie on the response when it isn't null and the request isn't a preview (/next/built-in-blocks#split-traffic); until then every test is off",
80
+ });
81
+ }
@@ -0,0 +1,61 @@
1
+ /** Which v7 framework binding the site ran on, from its `package.json`. */
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { isPlainObject } from "./walk";
5
+
6
+ export type Framework = "tanstack" | "nextjs";
7
+
8
+ /**
9
+ * `"tanstack"` when the site depends on `@decocms/tanstack`, `"nextjs"` on
10
+ * `@decocms/nextjs`, else `undefined` (a native app, a FastStore store that
11
+ * isn't ejected). Each moves to the binding of the same name in v8.
12
+ */
13
+ export function siteFramework(root: string): Framework | undefined {
14
+ try {
15
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
16
+ const has = (name: string) =>
17
+ ["dependencies", "devDependencies"].some(
18
+ (field) => isPlainObject(pkg[field]) && Object.hasOwn(pkg[field], name),
19
+ );
20
+ if (has("@decocms/tanstack")) return "tanstack";
21
+ if (has("@decocms/nextjs")) return "nextjs";
22
+ } catch {
23
+ // No readable package.json: no binding.
24
+ }
25
+ return undefined;
26
+ }
27
+
28
+ /**
29
+ * The `@decocms/blocks` 7.x version the site ran: the installed copy's, else
30
+ * the lowest version its `package.json` range names; `undefined` when neither
31
+ * is a 7.x version. v7's image URLs changed across 7.x releases.
32
+ */
33
+ export function siteBlocksVersion(root: string): string | undefined {
34
+ const v7 = (v: unknown) =>
35
+ typeof v === "string" ? /(?:^|[^\d.])(7\.\d+\.\d+)/.exec(v)?.[1] : undefined;
36
+ try {
37
+ const installed = JSON.parse(
38
+ fs.readFileSync(
39
+ path.join(root, "node_modules", "@decocms", "blocks", "package.json"),
40
+ "utf8",
41
+ ),
42
+ );
43
+ const version = v7(installed.version);
44
+ if (version) return version;
45
+ } catch {
46
+ // Not installed: the range in package.json.
47
+ }
48
+ try {
49
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
50
+ for (const field of ["dependencies", "devDependencies"]) {
51
+ const version = isPlainObject(pkg[field]) ? v7(pkg[field]["@decocms/blocks"]) : undefined;
52
+ if (version) return version;
53
+ }
54
+ } catch {
55
+ // No readable package.json.
56
+ }
57
+ return undefined;
58
+ }
59
+
60
+ /** The v8 version every package of the release shares: blocks and both bindings. */
61
+ export const V8_RANGE = "^8.4.0";
@@ -0,0 +1,276 @@
1
+ /**
2
+ * A site's own copy of v7's image helper (`hooks/Image.tsx` from
3
+ * `@decocms/blocks` 7.x, vendored into `src/` and sometimes edited): its URLs
4
+ * are what the site serves, so the `decoCdn` options that reproduce them are
5
+ * read from the copy, not from the release the site's `package.json` names.
6
+ * The rules read are the ones that changed across 7.x releases (or that a
7
+ * site edited): the CDN domain and quality it starts with, whether the Deco
8
+ * asset hosts are stripped anywhere or only at the start, how decoims.com
9
+ * sources are treated, and Nuvemshop's fixed sizes.
10
+ */
11
+ import fs from "node:fs";
12
+ import path from "node:path";
13
+ import ts from "typescript";
14
+
15
+ const SOURCE = /\.(tsx?|mts|cts)$/;
16
+ const CLOUDFLARE_CDNS = new Set(["assets.decocms.com", "decoims.com"]);
17
+ export const DEFAULT_DOMAIN = "assets.decocms.com";
18
+
19
+ export interface ImageCopyRules {
20
+ /** `imageCdnDomain`'s initial value. */
21
+ domain: string;
22
+ /** `imageQuality`'s initial value, if any. */
23
+ quality?: string;
24
+ /** `"anywhere"`: `.replace(DECO_CACHE_URL, "")`; `"leading"`: an anchored regex. */
25
+ stripAssetHosts: "anywhere" | "leading";
26
+ /**
27
+ * decoims.com sources: `"none"` (kept whole), `"cloudflare"` (stripped on
28
+ * the Cloudflare CDNs, v7 from 7.71.5), `"always"` (in the anchored asset
29
+ * regex, v7 7.71.4).
30
+ */
31
+ decoims: "none" | "cloudflare" | "always";
32
+ /** v7's VTEX catalog rule (`vtexCatalog()`), Shopify's (`shopifyCdn()`), Nuvemshop's fixed sizes. */
33
+ vtex: boolean;
34
+ shopify: boolean;
35
+ nuvemshop: boolean;
36
+ }
37
+
38
+ export interface ImageCopy {
39
+ /** Path from the site root. */
40
+ file: string;
41
+ /** The rules read from the copy, or null when it doesn't have v7's shape. */
42
+ rules: ImageCopyRules | null;
43
+ }
44
+
45
+ const stripScheme = (d: string) => d.replace(/^https?:\/\//, "").replace(/\/+$/, "");
46
+
47
+ /** Whether `text` defines v7's image helper (not just imports it). */
48
+ export function isImageCopy(text: string): boolean {
49
+ return (
50
+ /(?:function\s+getOptimizedMediaUrl\b|\bgetOptimizedMediaUrl\s*=\s*(?:\(|function))/.test(
51
+ text,
52
+ ) && /assets\\?\.decocache\\?\.com/.test(text)
53
+ );
54
+ }
55
+
56
+ /** The URL rules of a copy of v7's image helper, or null when they can't be read. */
57
+ export function readImageCopy(text: string): ImageCopyRules | null {
58
+ const domain = /\blet\s+imageCdnDomain(?:\s*:\s*[^=]+)?\s*=\s*["'`]([^"'`]+)["'`]/.exec(
59
+ text,
60
+ )?.[1];
61
+ if (!domain) return null;
62
+ // The CDN's own URLs are always shown relative; a copy without that check is not v7's.
63
+ if (!/startsWith\(\s*(?:cdnPrefix|`https:\/\/\$\{imageCdnDomain\}\/`)\s*\)/.test(text))
64
+ return null;
65
+ const anchored = /\^https:\\\/\\\/\(\?:assets\\\.decocache\\\.com[^/\n]*/.exec(text)?.[0];
66
+ const anywhere =
67
+ /\.replace\(\s*(?:DECO_CACHE_URL|["'`]https:\/\/assets\.decocache\.com\/["'`])\s*,/.test(text);
68
+ if (!anchored && !anywhere) return null;
69
+ const quality = /\blet\s+imageQuality(?:\s*:\s*[^=]+)?\s*=\s*["'`](\w+)["'`]/.exec(text)?.[1];
70
+ const decoims =
71
+ anchored?.includes("decoims\\.com") === true
72
+ ? "always"
73
+ : /CLOUDFLARE_CDNS\.has\(\s*imageCdnDomain\s*\)/.test(text) && /decoims\\\.com/.test(text)
74
+ ? "cloudflare"
75
+ : /decoims\\\.com/.test(text)
76
+ ? null
77
+ : "none";
78
+ if (decoims === null) return null;
79
+ return {
80
+ domain: stripScheme(domain),
81
+ ...(quality ? { quality } : {}),
82
+ stripAssetHosts: anchored ? "leading" : "anywhere",
83
+ decoims,
84
+ vtex: /vteximg|vtexassets/.test(text),
85
+ shopify: text.includes("cdn.shopify.com"),
86
+ nuvemshop: text.includes("mitiendanube"),
87
+ };
88
+ }
89
+
90
+ /**
91
+ * The `decoCdn` options (besides the providers' order) that reproduce a
92
+ * copy's URLs. `registered` is what the site passes the copy's
93
+ * `registerImageCdnDomain`/`registerImageQuality` (a string literal), which
94
+ * overrides the copy's initial values; `null` when it passes something else,
95
+ * left as `domain`/`quality` for a person to fill in.
96
+ */
97
+ export function copyDecoCdnOptions(
98
+ rules: ImageCopyRules,
99
+ registered: { domain?: string | null; quality?: string | null } = {},
100
+ ): string {
101
+ const parts: string[] = [];
102
+ const domain = registered.domain === undefined ? rules.domain : registered.domain;
103
+ if (domain === null) parts.push("domain");
104
+ else if (stripScheme(domain) !== DEFAULT_DOMAIN) parts.push(`domain: "${stripScheme(domain)}"`);
105
+ const quality = registered.quality === undefined ? rules.quality : registered.quality;
106
+ if (quality === null) parts.push("quality");
107
+ else if (quality) parts.push(`quality: "${quality}"`);
108
+ parts.push('sources: "all"');
109
+ // stripAssetHosts is left at decoCdn's default, "leading", for every copy: a
110
+ // copy that stripped the asset hosts anywhere moves to "leading" too
111
+ // (approved, PO 2026-10-15), and `leadingStripChanges` counts the URLs that changes.
112
+ // decoCdn's default: decoims.com on the Cloudflare CDNs (but not the CDN's own host).
113
+ if (domain !== null) {
114
+ const host = stripScheme(domain);
115
+ const fallback = CLOUDFLARE_CDNS.has(host) && host !== "decoims.com" ? ["decoims.com"] : [];
116
+ const copy =
117
+ rules.decoims === "none"
118
+ ? []
119
+ : rules.decoims === "always"
120
+ ? host === "decoims.com"
121
+ ? []
122
+ : ["decoims.com"]
123
+ : fallback;
124
+ if (copy.join() !== fallback.join()) parts.push(`legacyHosts: ${JSON.stringify(copy)}`);
125
+ } else if (rules.decoims !== "cloudflare") {
126
+ parts.push(rules.decoims === "none" ? "legacyHosts: []" : 'legacyHosts: ["decoims.com"]');
127
+ }
128
+ return parts.join(", ");
129
+ }
130
+
131
+ function listSources(dir: string): string[] {
132
+ if (!fs.existsSync(dir)) return [];
133
+ return fs
134
+ .readdirSync(dir, { recursive: true, withFileTypes: true })
135
+ .filter((d) => d.isFile() && SOURCE.test(d.name) && !d.name.endsWith(".d.ts"))
136
+ .map((d) => path.join(d.parentPath, d.name))
137
+ .filter((f) => !f.split(path.sep).includes("node_modules") && !/\.test\.tsx?$/.test(f))
138
+ .sort();
139
+ }
140
+
141
+ /**
142
+ * What the site's code passes to `name(…)`: the string literal, null for
143
+ * anything else (or different values), undefined when it is never called.
144
+ */
145
+ function registeredValue(files: ts.SourceFile[], name: string): string | null | undefined {
146
+ const values = new Set<string | null>();
147
+ const visit = (node: ts.Node): void => {
148
+ if (ts.isCallExpression(node)) {
149
+ const callee = node.expression;
150
+ const called = ts.isIdentifier(callee)
151
+ ? callee.text
152
+ : ts.isPropertyAccessExpression(callee)
153
+ ? callee.name.text
154
+ : undefined;
155
+ if (called === name) {
156
+ const [arg] = node.arguments;
157
+ values.add(arg && ts.isStringLiteralLike(arg) ? arg.text : null);
158
+ }
159
+ }
160
+ ts.forEachChild(node, visit);
161
+ };
162
+ for (const file of files) visit(file);
163
+ if (values.size === 0) return undefined;
164
+ return values.size === 1 ? [...values][0] : null;
165
+ }
166
+
167
+ /** The site's copies of v7's image helper under `src/`, in path order. */
168
+ export function findImageCopies(root: string): {
169
+ copies: ImageCopy[];
170
+ registered: { domain?: string | null; quality?: string | null };
171
+ } {
172
+ const parsed: ts.SourceFile[] = [];
173
+ const copies: ImageCopy[] = [];
174
+ for (const file of listSources(path.join(root, "src"))) {
175
+ const text = fs.readFileSync(file, "utf8");
176
+ if (/registerImage(?:CdnDomain|Quality)\(/.test(text)) {
177
+ parsed.push(
178
+ ts.createSourceFile(
179
+ file,
180
+ text,
181
+ ts.ScriptTarget.Latest,
182
+ false,
183
+ file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
184
+ ),
185
+ );
186
+ }
187
+ if (isImageCopy(text)) {
188
+ copies.push({
189
+ file: path.relative(root, file).split(path.sep).join("/"),
190
+ rules: readImageCopy(text),
191
+ });
192
+ }
193
+ }
194
+ return {
195
+ copies,
196
+ registered: {
197
+ domain: registeredValue(parsed, "registerImageCdnDomain"),
198
+ quality: registeredValue(parsed, "registerImageQuality"),
199
+ },
200
+ };
201
+ }
202
+
203
+ const DECO_CACHE_URL = "https://assets.decocache.com/";
204
+ const DECO_S3_URL = "https://deco-sites-assets.s3.sa-east-1.amazonaws.com/";
205
+ const LEADING_ASSET_HOST =
206
+ /^https:\/\/(?:assets\.decocache\.com|deco-sites-assets\.s3\.sa-east-1\.amazonaws\.com)\//;
207
+ const URL_IN_TEXT = /https?:\/\/[^\s"'`<>()\\]+/g;
208
+
209
+ /**
210
+ * Whether decoCdn's `stripAssetHosts: "leading"` (its default) gives `src` a
211
+ * different source than v7's strip-anywhere did (`.replace(DECO_CACHE_URL, "")`,
212
+ * then the S3 bucket): true for a URL that merely contains an asset URL,
213
+ * such as `https://other.host/https://assets.decocache.com/…`.
214
+ */
215
+ export function changedByLeadingStrip(src: string): boolean {
216
+ // Both drop the query afterwards, as decoCdn does.
217
+ const anywhere = src.replace(DECO_CACHE_URL, "").replace(DECO_S3_URL, "").split("?")[0];
218
+ return anywhere !== src.replace(LEADING_ASSET_HOST, "").split("?")[0];
219
+ }
220
+
221
+ export interface LeadingStripChange {
222
+ /** Path from the site root. */
223
+ file: string;
224
+ url: string;
225
+ }
226
+
227
+ function stringsOf(value: unknown, out: string[]): string[] {
228
+ if (typeof value === "string") out.push(value);
229
+ else if (Array.isArray(value)) for (const v of value) stringsOf(v, out);
230
+ else if (value && typeof value === "object")
231
+ for (const v of Object.values(value)) stringsOf(v, out);
232
+ return out;
233
+ }
234
+
235
+ /**
236
+ * The URLs in the saved content (`.deco/blocks`) and in `src/` whose image
237
+ * source changes when the asset hosts are stripped only at the start, for a
238
+ * site whose v7 image code stripped them anywhere. One entry per URL and file.
239
+ */
240
+ export function leadingStripChanges(root: string): LeadingStripChange[] {
241
+ const found: LeadingStripChange[] = [];
242
+ const seen = new Set<string>();
243
+ const add = (file: string, texts: string[]) => {
244
+ const rel = path.relative(root, file).split(path.sep).join("/");
245
+ for (const text of texts) {
246
+ if (!text.includes(DECO_CACHE_URL) && !text.includes(DECO_S3_URL)) continue;
247
+ for (const [url] of text.matchAll(URL_IN_TEXT)) {
248
+ const key = `${rel}\0${url}`;
249
+ if (seen.has(key) || !changedByLeadingStrip(url)) continue;
250
+ seen.add(key);
251
+ found.push({ file: rel, url });
252
+ }
253
+ }
254
+ };
255
+ const blocks = path.join(root, ".deco", "blocks");
256
+ if (fs.existsSync(blocks)) {
257
+ const files = fs
258
+ .readdirSync(blocks, { recursive: true, withFileTypes: true })
259
+ .filter((d) => d.isFile() && d.name.endsWith(".json"))
260
+ .map((d) => path.join(d.parentPath, d.name))
261
+ .sort();
262
+ for (const file of files) {
263
+ const text = fs.readFileSync(file, "utf8");
264
+ let parsed: unknown;
265
+ try {
266
+ parsed = JSON.parse(text);
267
+ } catch {
268
+ parsed = text;
269
+ }
270
+ add(file, stringsOf(parsed, []));
271
+ }
272
+ }
273
+ for (const file of listSources(path.join(root, "src")))
274
+ add(file, [fs.readFileSync(file, "utf8")]);
275
+ return found;
276
+ }