@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,297 @@
1
+ /**
2
+ * App blocks → client config (spec: upstream-clients › Call a client). v7's
3
+ * autoconfig read each commerce app's settings from a saved block it found by
4
+ * name (`deco-vtex`, `deco-shopify`, `deco-wake`, `deco-resend`) and
5
+ * configured a global client from it. The next major has no apps: a site
6
+ * creates the platform's client in code. This step writes that code,
7
+ * `src/clients/<app>.ts`, from the saved block, with v7's rules:
8
+ *
9
+ * - each setting the client takes, as a literal (v7's defaults applied the
10
+ * same way: VTEX's sales channel "1", Wake's checkout URL);
11
+ * - each credential from the environment variable v7 fell back to
12
+ * (`VTEX_APP_KEY`, `SHOPIFY_STOREFRONT_TOKEN`, …), never its value: a
13
+ * plain string v7 accepted as is stays a literal, an encrypted one is read
14
+ * from the variable (the Worker's `env` on TanStack Start, `process.env` on
15
+ * Next.js), so the report names the variables to set;
16
+ * - the settings v7 kept beside the client (VTEX's `publicUrl`, Resend's
17
+ * sender) as an exported constant for the site's code.
18
+ *
19
+ * The saved block stays until the variables are set (the report says to
20
+ * delete it then: `deco check` rejects it). Returns the v7 type names handled,
21
+ * so the block map doesn't report them again.
22
+ */
23
+ import fs from "node:fs";
24
+ import path from "node:path";
25
+ import { type Framework, siteFramework } from "./framework";
26
+ import type { Report } from "./report";
27
+ import { isPlainObject, type JsonObject, readContent } from "./walk";
28
+
29
+ type Value = { literal: unknown } | { env: string; required: boolean };
30
+
31
+ interface AppPlan {
32
+ pkg: string;
33
+ create: string;
34
+ clientType: string;
35
+ /** The client's config, field by field. */
36
+ config: [string, Value][];
37
+ /** Settings v7 kept for the site's code. */
38
+ settings: Record<string, unknown>;
39
+ }
40
+
41
+ /** A setting's text, or undefined when empty (v7 treated "" as unset). */
42
+ const str = (v: unknown) => (typeof v === "string" && v.length > 0 ? v : undefined);
43
+
44
+ /** v7's resolveSecret(value, env): a plain string as is, else the environment variable. */
45
+ function secret(value: unknown, env: string, required: boolean): Value {
46
+ const plain = str(value);
47
+ return plain !== undefined ? { literal: plain } : { env, required };
48
+ }
49
+
50
+ /** The Storefront API version the installed v7 Shopify app spoke (latest 7.x: 2026-04). */
51
+ function shopifyApiVersion(root: string): string {
52
+ try {
53
+ const text = fs.readFileSync(
54
+ path.join(root, "node_modules", "@decocms", "apps-shopify", "src", "client.ts"),
55
+ "utf8",
56
+ );
57
+ const version = /\/api\/(\d{4}-\d{2})\/graphql/.exec(text)?.[1];
58
+ if (version) return version;
59
+ } catch {
60
+ // Not installed: 7.x's last version.
61
+ }
62
+ return "2026-04";
63
+ }
64
+
65
+ /** Each v7 app's `configure(block, resolveSecret)`, as the v8 client's config. */
66
+ const APPS: Record<string, (block: JsonObject, root: string) => AppPlan | undefined> = {
67
+ vtex: (b) => {
68
+ const account = str(b.account);
69
+ if (!account) return undefined;
70
+ const config: [string, Value][] = [
71
+ ["account", { literal: account }],
72
+ ["salesChannel", { literal: str(b.salesChannel) ?? "1" }],
73
+ ];
74
+ const locale = str(b.locale) ?? str(b.defaultLocale);
75
+ if (locale) config.push(["locale", { literal: locale }]);
76
+ if (str(b.domain)) config.push(["domain", { literal: b.domain }]);
77
+ config.push(["appKey", secret(b.appKey, "VTEX_APP_KEY", false)]);
78
+ config.push(["appToken", secret(b.appToken, "VTEX_APP_TOKEN", false)]);
79
+ const advanced = isPlainObject(b.advancedConfigs) ? b.advancedConfigs : {};
80
+ return {
81
+ pkg: "@decocms/apps-vtex",
82
+ create: "createVtexClient",
83
+ clientType: "VtexClient",
84
+ config,
85
+ settings: {
86
+ publicUrl: str(b.publicUrl) ?? null,
87
+ country: str(b.country) ?? null,
88
+ invalidPageNotFound: advanced.invalidPageNotFound === true,
89
+ },
90
+ };
91
+ },
92
+ shopify: (b, root) => {
93
+ const storeName = str(b.storeName);
94
+ if (!storeName) return undefined;
95
+ return {
96
+ pkg: "@decocms/apps-shopify",
97
+ create: "createShopifyClient",
98
+ clientType: "ShopifyClient",
99
+ config: [
100
+ ["storeName", { literal: storeName }],
101
+ [
102
+ "storefrontAccessToken",
103
+ secret(b.storefrontAccessToken, "SHOPIFY_STOREFRONT_TOKEN", true),
104
+ ],
105
+ ["apiVersion", { literal: shopifyApiVersion(root) }],
106
+ ],
107
+ settings: { publicUrl: str(b.publicUrl) ?? null },
108
+ };
109
+ },
110
+ wake: (b) => {
111
+ const account = str(b.account);
112
+ if (!account) return undefined;
113
+ const config: [string, Value][] = [
114
+ // v7 read Wake's token from the environment only.
115
+ ["storefrontToken", { env: "WAKE_TOKEN", required: true }],
116
+ ["checkoutUrl", { literal: str(b.checkoutUrl) ?? `https://${account}.checkout.fbits.store` }],
117
+ ];
118
+ if (str(b.storefrontEndpoint))
119
+ config.push(["storefrontEndpoint", { literal: b.storefrontEndpoint }]);
120
+ return {
121
+ pkg: "@decocms/apps-wake",
122
+ create: "createWakeClient",
123
+ clientType: "WakeClient",
124
+ config,
125
+ settings: { account },
126
+ };
127
+ },
128
+ resend: (b) => {
129
+ const from = isPlainObject(b.emailFrom) ? b.emailFrom : undefined;
130
+ return {
131
+ pkg: "@decocms/apps-resend",
132
+ create: "createResendClient",
133
+ clientType: "ResendClient",
134
+ config: [["apiKey", secret(b.apiKey, "RESEND_API_KEY", true)]],
135
+ settings: {
136
+ emailFrom: from
137
+ ? `${str(from.name) || "Contact"} <${str(from.domain) || "onboarding@resend.dev"}>`
138
+ : null,
139
+ emailTo: b.emailTo ?? null,
140
+ subject: b.subject ?? null,
141
+ },
142
+ };
143
+ },
144
+ };
145
+
146
+ const CLIENT_NAME: Record<string, string> = {
147
+ vtex: "vtexClient",
148
+ shopify: "shopifyClient",
149
+ wake: "wakeClient",
150
+ resend: "resendClient",
151
+ };
152
+
153
+ function render(app: string, name: string, plan: AppPlan, framework: Framework): string {
154
+ const envNames = plan.config.flatMap(([, v]) => ("env" in v ? [v.env] : []));
155
+ const value = (v: Value) => {
156
+ if ("literal" in v) return JSON.stringify(v.literal);
157
+ return v.required ? `required("${v.env}")` : `variable("${v.env}")`;
158
+ };
159
+ const needsRequired = plan.config.some(([, v]) => "env" in v && v.required);
160
+ const lines = [
161
+ "/**",
162
+ ` * The ${app} client, configured from v7's saved app block "${name}" (v7's autoconfig read the app's`,
163
+ " * settings from it). Generated by the deco-v7-to-v8-migration skill; it's your code now.",
164
+ ...(envNames.length > 0
165
+ ? [
166
+ ` * Credentials come from the environment variables v7 fell back to (${envNames.join(", ")});`,
167
+ ` * set them as ${framework === "tanstack" ? "the Worker's secrets (wrangler secret put)" : "the deployment's environment variables"}.`,
168
+ ]
169
+ : []),
170
+ " */",
171
+ `import { ${plan.create}, type ${plan.clientType} } from "${plan.pkg}";`,
172
+ ];
173
+ if (envNames.length > 0) {
174
+ if (framework === "tanstack") {
175
+ lines.push(
176
+ 'import { env } from "cloudflare:workers";',
177
+ "",
178
+ "/** An environment variable of the Worker. */",
179
+ "const variable = (name: string) =>",
180
+ " (env as unknown as Record<string, string | undefined>)[name] || undefined;",
181
+ );
182
+ } else {
183
+ lines.push(
184
+ "",
185
+ "/** An environment variable of the server. */",
186
+ "const variable = (name: string) => process.env[name] || undefined;",
187
+ );
188
+ }
189
+ if (needsRequired) {
190
+ lines.push(
191
+ "",
192
+ "const required = (name: string) => {",
193
+ " const value = variable(name);",
194
+ ` if (!value) throw new Error(\`${app} isn't configured: set \${name} (v7 read it from the saved "${name}" block or the environment)\`);`,
195
+ " return value;",
196
+ "};",
197
+ );
198
+ }
199
+ }
200
+ const settings = Object.entries(plan.settings);
201
+ if (settings.length > 0) {
202
+ lines.push(
203
+ "",
204
+ `/** What v7's ${app} app kept beside its client, for the site's code. */`,
205
+ `export const ${app}Settings = ${JSON.stringify(plan.settings, null, 2)} as const;`,
206
+ );
207
+ }
208
+ lines.push(
209
+ "",
210
+ `let client: ${plan.clientType} | undefined;`,
211
+ "",
212
+ `/** The ${app} client, created on first use. */`,
213
+ `export function ${CLIENT_NAME[app]}(): ${plan.clientType} {`,
214
+ ` client ??= ${plan.create}({`,
215
+ ...plan.config.map(([field, v]) => ` ${field}: ${value(v)},`),
216
+ " });",
217
+ " return client;",
218
+ "}",
219
+ "",
220
+ );
221
+ return lines.join("\n");
222
+ }
223
+
224
+ /** Writes `src/clients/<app>.ts` for each v7 app block. Returns the v7 type names handled. */
225
+ export function writeAppClients(root: string, report: Report): Set<string> {
226
+ const handled = new Set<string>();
227
+ const framework = siteFramework(root);
228
+ const { blocks, files } = readContent(root);
229
+ for (const [name, block] of Object.entries(blocks)) {
230
+ const app = /^deco-([a-z]+)$/.exec(name)?.[1];
231
+ if (!app || !isPlainObject(block)) continue;
232
+ const type = typeof block.__resolveType === "string" ? block.__resolveType : "";
233
+ // v7's app blocks: `site/apps/deco/<app>.ts` (or the app's own mod).
234
+ if (!/(^|\/)apps\/|\/mod\.tsx?$/.test(type)) continue;
235
+ const file = files[name];
236
+ const subject = `${file} (${type})`;
237
+ handled.add(type);
238
+ if (app === "analytics" || app === "htmx") {
239
+ report.manual.push({
240
+ step: "apps",
241
+ subject,
242
+ message:
243
+ app === "htmx"
244
+ ? "v7's HTMX app: v7 on TanStack Start and Next.js loaded no HTMX from it; delete the saved block"
245
+ : "v7's analytics app: analytics is the analytics section of the CMS block now (AnalyticsScript from @decocms/blocks/analytics, /next/analytics); delete the saved block",
246
+ });
247
+ continue;
248
+ }
249
+ const make = APPS[app];
250
+ if (!make) {
251
+ report.manual.push({
252
+ step: "apps",
253
+ subject,
254
+ message:
255
+ app === "nuvemshop"
256
+ ? "v7's Nuvemshop app: the next major has no Nuvemshop client; call the platform from site code over createInstrumentedFetch (/next/upstream-clients#write-a-client), then delete the saved block"
257
+ : "a v7 app block: create its client in code with these settings (/next/upstream-clients#call-a-client), then delete the saved block",
258
+ });
259
+ continue;
260
+ }
261
+ const plan = make(block, root);
262
+ if (!plan || !framework) {
263
+ report.manual.push({
264
+ step: "apps",
265
+ subject,
266
+ message: !plan
267
+ ? `v7's ${app} app had no ${app === "resend" ? "API key" : "account"} in it, so v7 never configured it: delete the saved block`
268
+ : `v7's ${app} app: create the ${app} client in code with these settings (/next/upstream-clients#call-a-client), then delete the saved block`,
269
+ });
270
+ continue;
271
+ }
272
+ const out = path.join(root, "src", "clients", `${app}.ts`);
273
+ const rel = path.relative(root, out).split(path.sep).join("/");
274
+ if (fs.existsSync(out)) {
275
+ report.manual.push({
276
+ step: "apps",
277
+ subject: rel,
278
+ message: `already exists, so it was kept: configure ${plan.create} from the saved "${name}" block's settings`,
279
+ });
280
+ continue;
281
+ }
282
+ fs.mkdirSync(path.dirname(out), { recursive: true });
283
+ fs.writeFileSync(out, render(app, name, plan, framework));
284
+ const envNames = plan.config.flatMap(([, v]) => ("env" in v ? [v.env] : []));
285
+ report.done.push({
286
+ step: "apps",
287
+ subject: rel,
288
+ message: `${CLIENT_NAME[app]}() creates ${plan.create} (${plan.pkg}) from the saved "${name}" block's settings, with v7's defaults`,
289
+ });
290
+ report.manual.push({
291
+ step: "apps",
292
+ subject,
293
+ message: `${envNames.length > 0 ? `set ${envNames.join(", ")} (the credentials v7 read from this block or, failing that, from those variables), then ` : ""}delete the saved block: ${rel} holds its settings now, and deco check rejects it. Call ${CLIENT_NAME[app]}() where the vendored ${app} code reads v7's global config`,
294
+ });
295
+ }
296
+ return handled;
297
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Async rendering: v7 could defer a section behind a wrapper block, rendered
3
+ * after the page (`website/sections/Rendering/Lazy.tsx`, its re-export
4
+ * `SingleDeferred.tsx`, both `{ section }`) or on a trigger
5
+ * (`Deferred.tsx`, `{ sections: [...] }`). The next major has no async
6
+ * rendering (spec: renames-and-migrations › Migrating from v7), so the
7
+ * migration unwraps them in saved content: each wrapper is replaced by the
8
+ * section(s) it held, props untouched, and the wrapper's own options
9
+ * (`loading`, `display`, `behavior`) go. In a list, a `Deferred` gives way to
10
+ * all its sections in place. Running it again changes nothing.
11
+ */
12
+ import fs from "node:fs";
13
+ import path from "node:path";
14
+ import { serializeBlock } from "@decocms/blocks/protocol/keys";
15
+ import type { Report } from "./report";
16
+ import { isPlainObject, type JsonObject, readContent } from "./walk";
17
+
18
+ const WRAPPER = /^website\/sections\/Rendering\/(Lazy|SingleDeferred|Deferred)\.tsx?$/;
19
+
20
+ /** The sections a wrapper held, or `null` when `value` isn't a wrapper. */
21
+ function wrapped(value: unknown): unknown[] | null {
22
+ if (!isPlainObject(value) || typeof value.__resolveType !== "string") return null;
23
+ const kind = WRAPPER.exec(value.__resolveType)?.[1];
24
+ if (kind === undefined) return null;
25
+ const inner = kind === "Deferred" ? value.sections : [value.section];
26
+ return Array.isArray(inner) ? inner.filter(isPlainObject) : [];
27
+ }
28
+
29
+ /**
30
+ * `value` with every wrapper unwrapped. Outside a list, a wrapper that doesn't
31
+ * hold exactly one section stays, and its type goes in `stuck`.
32
+ */
33
+ function unwrap(value: unknown, stuck: Set<string>): unknown {
34
+ if (Array.isArray(value)) {
35
+ return value.flatMap((item) => {
36
+ const inner = wrapped(item);
37
+ return inner === null ? [unwrap(item, stuck)] : (unwrap(inner, stuck) as unknown[]);
38
+ });
39
+ }
40
+ if (!isPlainObject(value)) return value;
41
+ const inner = wrapped(value);
42
+ if (inner?.length === 1) return unwrap(inner[0], stuck);
43
+ if (inner !== null) stuck.add(value.__resolveType as string); // kept; its sections still unwrap
44
+ const out: JsonObject = {};
45
+ for (const [key, child] of Object.entries(value)) out[key] = unwrap(child, stuck);
46
+ return out;
47
+ }
48
+
49
+ export function unwrapAsyncRendering(root: string, report: Report): void {
50
+ const { blocks, files } = readContent(root);
51
+ for (const [entry, block] of Object.entries(blocks)) {
52
+ const stuck = new Set<string>();
53
+ const next = unwrap(block, stuck);
54
+ const before = serializeBlock(block);
55
+ const after = serializeBlock(next);
56
+ if (after !== before) {
57
+ fs.writeFileSync(path.join(root, ".deco", "blocks", files[entry]!), after);
58
+ report.done.push({
59
+ step: "content",
60
+ subject: files[entry]!,
61
+ message: "unwrapped v7 async-rendering wrappers (Lazy/Deferred) to the sections they held",
62
+ });
63
+ }
64
+ for (const type of stuck) {
65
+ report.manual.push({
66
+ step: "content",
67
+ subject: `${type} (in ${files[entry]})`,
68
+ message:
69
+ "a v7 async-rendering wrapper holding no section or several where one block goes; the next major has no async rendering: replace it with its section(s) by hand",
70
+ });
71
+ }
72
+ }
73
+ }