@decocms/blocks 8.9.1 → 8.11.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 (409) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/protocol/channel.d.ts +98 -0
  6. package/dist/protocol/channel.d.ts.map +1 -0
  7. package/dist/protocol/channel.js +58 -0
  8. package/dist/protocol/channel.js.map +1 -0
  9. package/dist/protocol/client.js +2 -2
  10. package/dist/protocol/client.js.map +1 -1
  11. package/dist/protocol/conformance/blockMetaVectors.json +214 -0
  12. package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
  13. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
  14. package/dist/protocol/conformance/contentHashFixtures.js +55 -0
  15. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
  16. package/dist/protocol/conformance/index.d.ts +2 -1
  17. package/dist/protocol/conformance/index.d.ts.map +1 -1
  18. package/dist/protocol/conformance/index.js +2 -1
  19. package/dist/protocol/conformance/index.js.map +1 -1
  20. package/dist/protocol/conformance/vectors.d.ts +33 -0
  21. package/dist/protocol/conformance/vectors.d.ts.map +1 -0
  22. package/dist/protocol/conformance/vectors.js +3 -0
  23. package/dist/protocol/conformance/vectors.js.map +1 -0
  24. package/dist/protocol/index.d.ts +11 -1
  25. package/dist/protocol/index.d.ts.map +1 -1
  26. package/dist/protocol/index.js +11 -1
  27. package/dist/protocol/index.js.map +1 -1
  28. package/dist/protocol/keys.d.ts +1 -1
  29. package/dist/protocol/keys.js +1 -1
  30. package/dist/v8/background.d.ts +13 -0
  31. package/dist/v8/background.d.ts.map +1 -1
  32. package/dist/v8/background.js +41 -0
  33. package/dist/v8/background.js.map +1 -1
  34. package/dist/v8/blockMeta.d.ts +27 -0
  35. package/dist/v8/blockMeta.d.ts.map +1 -0
  36. package/dist/v8/blockMeta.js +75 -0
  37. package/dist/v8/blockMeta.js.map +1 -0
  38. package/dist/v8/blockStore.d.ts +43 -0
  39. package/dist/v8/blockStore.d.ts.map +1 -0
  40. package/dist/v8/blockStore.js +95 -0
  41. package/dist/v8/blockStore.js.map +1 -0
  42. package/dist/v8/boundedJson.d.ts +5 -0
  43. package/dist/v8/boundedJson.d.ts.map +1 -1
  44. package/dist/v8/boundedJson.js +10 -2
  45. package/dist/v8/boundedJson.js.map +1 -1
  46. package/dist/v8/boundedMap.d.ts +19 -0
  47. package/dist/v8/boundedMap.d.ts.map +1 -0
  48. package/dist/v8/boundedMap.js +52 -0
  49. package/dist/v8/boundedMap.js.map +1 -0
  50. package/dist/v8/builtins/data.d.ts +18 -2
  51. package/dist/v8/builtins/data.d.ts.map +1 -1
  52. package/dist/v8/builtins/data.js +17 -1
  53. package/dist/v8/builtins/data.js.map +1 -1
  54. package/dist/v8/builtins/index.d.ts.map +1 -1
  55. package/dist/v8/builtins/index.js +2 -1
  56. package/dist/v8/builtins/index.js.map +1 -1
  57. package/dist/v8/builtins/legacy.d.ts +6 -3
  58. package/dist/v8/builtins/legacy.d.ts.map +1 -1
  59. package/dist/v8/builtins/legacy.js +6 -3
  60. package/dist/v8/builtins/legacy.js.map +1 -1
  61. package/dist/v8/canonical.d.ts +8 -0
  62. package/dist/v8/canonical.d.ts.map +1 -1
  63. package/dist/v8/canonical.js +15 -0
  64. package/dist/v8/canonical.js.map +1 -1
  65. package/dist/v8/cli/builtins.d.ts.map +1 -1
  66. package/dist/v8/cli/builtins.js +1 -0
  67. package/dist/v8/cli/builtins.js.map +1 -1
  68. package/dist/v8/cli/check/index.d.ts +10 -0
  69. package/dist/v8/cli/check/index.d.ts.map +1 -1
  70. package/dist/v8/cli/check/index.js +91 -7
  71. package/dist/v8/cli/check/index.js.map +1 -1
  72. package/dist/v8/cli/content.d.ts +12 -25
  73. package/dist/v8/cli/content.d.ts.map +1 -1
  74. package/dist/v8/cli/content.js +46 -75
  75. package/dist/v8/cli/content.js.map +1 -1
  76. package/dist/v8/cli/index.d.ts +2 -2
  77. package/dist/v8/cli/index.d.ts.map +1 -1
  78. package/dist/v8/cli/index.js +2 -2
  79. package/dist/v8/cli/index.js.map +1 -1
  80. package/dist/v8/cli/remote/commands.d.ts +71 -0
  81. package/dist/v8/cli/remote/commands.d.ts.map +1 -0
  82. package/dist/v8/cli/remote/commands.js +644 -0
  83. package/dist/v8/cli/remote/commands.js.map +1 -0
  84. package/dist/v8/cli/remote/diff.d.ts +15 -0
  85. package/dist/v8/cli/remote/diff.d.ts.map +1 -0
  86. package/dist/v8/cli/remote/diff.js +102 -0
  87. package/dist/v8/cli/remote/diff.js.map +1 -0
  88. package/dist/v8/cli/remote/env.d.ts +35 -0
  89. package/dist/v8/cli/remote/env.d.ts.map +1 -0
  90. package/dist/v8/cli/remote/env.js +84 -0
  91. package/dist/v8/cli/remote/env.js.map +1 -0
  92. package/dist/v8/cli/remote/http.d.ts +149 -0
  93. package/dist/v8/cli/remote/http.d.ts.map +1 -0
  94. package/dist/v8/cli/remote/http.js +381 -0
  95. package/dist/v8/cli/remote/http.js.map +1 -0
  96. package/dist/v8/cli/remote/local.d.ts +90 -0
  97. package/dist/v8/cli/remote/local.d.ts.map +1 -0
  98. package/dist/v8/cli/remote/local.js +309 -0
  99. package/dist/v8/cli/remote/local.js.map +1 -0
  100. package/dist/v8/cli/root.d.ts +29 -0
  101. package/dist/v8/cli/root.d.ts.map +1 -1
  102. package/dist/v8/cli/root.js +28 -0
  103. package/dist/v8/cli/root.js.map +1 -1
  104. package/dist/v8/cli/run.d.ts +13 -1
  105. package/dist/v8/cli/run.d.ts.map +1 -1
  106. package/dist/v8/cli/run.js +310 -124
  107. package/dist/v8/cli/run.js.map +1 -1
  108. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  109. package/dist/v8/cli/schema/builtinSchemas.js +28 -10
  110. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  111. package/dist/v8/cli/schema/generate.js +1 -1
  112. package/dist/v8/cli/schema/generate.js.map +1 -1
  113. package/dist/v8/cli/skills.d.ts +25 -0
  114. package/dist/v8/cli/skills.d.ts.map +1 -0
  115. package/dist/v8/cli/skills.js +70 -0
  116. package/dist/v8/cli/skills.js.map +1 -0
  117. package/dist/v8/client.d.ts +9 -9
  118. package/dist/v8/client.d.ts.map +1 -1
  119. package/dist/v8/client.js +138 -50
  120. package/dist/v8/client.js.map +1 -1
  121. package/dist/v8/cms.d.ts +2 -1
  122. package/dist/v8/cms.d.ts.map +1 -1
  123. package/dist/v8/cms.js +55 -46
  124. package/dist/v8/cms.js.map +1 -1
  125. package/dist/v8/content.d.ts +39 -78
  126. package/dist/v8/content.d.ts.map +1 -1
  127. package/dist/v8/content.js +155 -195
  128. package/dist/v8/content.js.map +1 -1
  129. package/dist/v8/contentIndex.d.ts +71 -0
  130. package/dist/v8/contentIndex.d.ts.map +1 -0
  131. package/dist/v8/contentIndex.js +137 -0
  132. package/dist/v8/contentIndex.js.map +1 -0
  133. package/dist/v8/draft.d.ts +7 -7
  134. package/dist/v8/draft.d.ts.map +1 -1
  135. package/dist/v8/draft.js +10 -9
  136. package/dist/v8/draft.js.map +1 -1
  137. package/dist/v8/draftChanges.d.ts +59 -32
  138. package/dist/v8/draftChanges.d.ts.map +1 -1
  139. package/dist/v8/draftChanges.js +139 -75
  140. package/dist/v8/draftChanges.js.map +1 -1
  141. package/dist/v8/errors.d.ts +21 -0
  142. package/dist/v8/errors.d.ts.map +1 -1
  143. package/dist/v8/errors.js +22 -0
  144. package/dist/v8/errors.js.map +1 -1
  145. package/dist/v8/hostedSource.d.ts +57 -0
  146. package/dist/v8/hostedSource.d.ts.map +1 -0
  147. package/dist/v8/hostedSource.js +18 -0
  148. package/dist/v8/hostedSource.js.map +1 -0
  149. package/dist/v8/identity.d.ts +1 -1
  150. package/dist/v8/identity.js +1 -1
  151. package/dist/v8/index.d.ts +1 -0
  152. package/dist/v8/index.d.ts.map +1 -1
  153. package/dist/v8/index.js +1 -0
  154. package/dist/v8/index.js.map +1 -1
  155. package/dist/v8/matchRoute.js +7 -4
  156. package/dist/v8/matchRoute.js.map +1 -1
  157. package/dist/v8/pin.d.ts +34 -0
  158. package/dist/v8/pin.d.ts.map +1 -0
  159. package/dist/v8/pin.js +156 -0
  160. package/dist/v8/pin.js.map +1 -0
  161. package/dist/v8/preview/StudioBridge.d.ts +8 -8
  162. package/dist/v8/preview/StudioBridge.d.ts.map +1 -1
  163. package/dist/v8/preview/StudioBridge.js +8 -10
  164. package/dist/v8/preview/StudioBridge.js.map +1 -1
  165. package/dist/v8/preview/StudioChannel.d.ts +51 -0
  166. package/dist/v8/preview/StudioChannel.d.ts.map +1 -0
  167. package/dist/v8/preview/StudioChannel.js +104 -0
  168. package/dist/v8/preview/StudioChannel.js.map +1 -0
  169. package/dist/v8/preview/index.d.ts +3 -0
  170. package/dist/v8/preview/index.d.ts.map +1 -1
  171. package/dist/v8/preview/index.js +3 -0
  172. package/dist/v8/preview/index.js.map +1 -1
  173. package/dist/v8/remoteLoader.d.ts +42 -5
  174. package/dist/v8/remoteLoader.d.ts.map +1 -1
  175. package/dist/v8/remoteLoader.js +317 -259
  176. package/dist/v8/remoteLoader.js.map +1 -1
  177. package/dist/v8/resolver.d.ts +22 -8
  178. package/dist/v8/resolver.d.ts.map +1 -1
  179. package/dist/v8/resolver.js +37 -32
  180. package/dist/v8/resolver.js.map +1 -1
  181. package/dist/v8/revisionId.d.ts +11 -0
  182. package/dist/v8/revisionId.d.ts.map +1 -0
  183. package/dist/v8/revisionId.js +13 -0
  184. package/dist/v8/revisionId.js.map +1 -0
  185. package/dist/v8/settings.d.ts +6 -6
  186. package/dist/v8/settings.d.ts.map +1 -1
  187. package/dist/v8/settings.js +8 -7
  188. package/dist/v8/settings.js.map +1 -1
  189. package/dist/v8/telemetry.d.ts +4 -2
  190. package/dist/v8/telemetry.d.ts.map +1 -1
  191. package/dist/v8/telemetry.js +2 -2
  192. package/dist/v8/telemetry.js.map +1 -1
  193. package/dist/v8/types.d.ts +52 -40
  194. package/dist/v8/types.d.ts.map +1 -1
  195. package/dist/v8/variants.d.ts +7 -2
  196. package/dist/v8/variants.d.ts.map +1 -1
  197. package/dist/v8/variants.js +21 -24
  198. package/dist/v8/variants.js.map +1 -1
  199. package/dist/v8/vite/index.d.ts +2 -2
  200. package/dist/v8/vite/index.js +1 -1
  201. package/dist/v8/vite/index.js.map +1 -1
  202. package/package.json +3 -2
  203. package/skills/deco-apps/SKILL.md +82 -0
  204. package/skills/deco-apps/references/algolia.md +51 -0
  205. package/skills/deco-apps/references/commerce-types.md +132 -0
  206. package/skills/deco-apps/references/instrumented-fetch.md +144 -0
  207. package/skills/deco-apps/references/magento.md +55 -0
  208. package/skills/deco-apps/references/messaging.md +76 -0
  209. package/skills/deco-apps/references/shopify.md +69 -0
  210. package/skills/deco-apps/references/vendored-loaders.md +135 -0
  211. package/skills/deco-apps/references/vtex-cookies-auth.md +146 -0
  212. package/skills/deco-apps/references/vtex.md +150 -0
  213. package/skills/deco-apps/references/wake.md +75 -0
  214. package/skills/deco-cms-schema/SKILL.md +80 -0
  215. package/skills/deco-cms-schema/references/annotations.md +147 -0
  216. package/skills/deco-cms-schema/references/content-hygiene.md +91 -0
  217. package/skills/deco-cms-schema/references/formats-and-widgets.md +112 -0
  218. package/skills/deco-cms-schema/references/shapes-that-break-the-form.md +165 -0
  219. package/skills/deco-cms-schema/references/types-to-fields.md +112 -0
  220. package/skills/deco-go-live/SKILL.md +127 -0
  221. package/skills/deco-go-live/references/content-releases.md +90 -0
  222. package/skills/deco-go-live/references/process.md +106 -0
  223. package/skills/deco-go-live/references/proxy-headers-checkout.md +139 -0
  224. package/skills/deco-go-live/references/qa-checklist-template.md +150 -0
  225. package/skills/deco-go-live/references/qa-inventory.md +120 -0
  226. package/skills/deco-go-live/references/react-spa.md +183 -0
  227. package/skills/deco-go-live/references/seo-analytics.md +114 -0
  228. package/skills/deco-go-live/references/traffic-ramp.md +87 -0
  229. package/skills/deco-go-live/references/worker-runtime.md +93 -0
  230. package/skills/deco-go-live/scripts/preflight.sh +221 -0
  231. package/skills/deco-images-media/SKILL.md +64 -0
  232. package/skills/deco-images-media/references/asset-upload.md +191 -0
  233. package/skills/deco-images-media/references/components-per-binding.md +167 -0
  234. package/skills/deco-images-media/references/providers-and-cdn.md +145 -0
  235. package/skills/deco-images-media/references/quality-and-lcp.md +93 -0
  236. package/skills/deco-images-media/references/troubleshooting.md +147 -0
  237. package/skills/deco-images-media/references/video.md +122 -0
  238. package/skills/deco-make-editable/SKILL.md +94 -0
  239. package/skills/deco-make-editable/references/a11y-and-e2e.md +104 -0
  240. package/skills/deco-make-editable/references/content-shapes.md +198 -0
  241. package/skills/deco-make-editable/references/from-figma.md +110 -0
  242. package/skills/deco-make-editable/references/i18n-fields.md +112 -0
  243. package/skills/deco-make-editable/references/inventory.md +79 -0
  244. package/skills/deco-make-editable/references/pixel-parity.md +175 -0
  245. package/skills/deco-make-editable/references/seeding-content.md +119 -0
  246. package/skills/deco-nextjs-site/SKILL.md +74 -0
  247. package/skills/deco-nextjs-site/references/caching.md +116 -0
  248. package/skills/deco-nextjs-site/references/metadata-seo.md +100 -0
  249. package/skills/deco-nextjs-site/references/proxy-and-drafts.md +177 -0
  250. package/skills/deco-nextjs-site/references/rendering.md +171 -0
  251. package/skills/deco-nextjs-site/references/setup.md +190 -0
  252. package/skills/deco-nextjs-site/references/studio-bridge.md +130 -0
  253. package/skills/deco-site-authoring/SKILL.md +75 -0
  254. package/skills/deco-site-authoring/references/lazy-blocks.md +155 -0
  255. package/skills/deco-site-authoring/references/loaders.md +192 -0
  256. package/skills/deco-site-authoring/references/pages.md +156 -0
  257. package/skills/deco-site-authoring/references/review-before-publish.md +95 -0
  258. package/skills/deco-site-authoring/references/sections.md +158 -0
  259. package/skills/deco-site-authoring/references/seo.md +116 -0
  260. package/skills/deco-site-workflow/SKILL.md +92 -0
  261. package/skills/deco-site-workflow/references/check.md +116 -0
  262. package/skills/deco-site-workflow/references/cli-reference.md +104 -0
  263. package/skills/deco-site-workflow/references/content-layout.md +93 -0
  264. package/skills/deco-site-workflow/references/content-sync.md +146 -0
  265. package/skills/deco-site-workflow/references/delivery.md +51 -0
  266. package/skills/deco-site-workflow/references/deploy.md +87 -0
  267. package/skills/deco-site-workflow/references/schema.md +173 -0
  268. package/skills/deco-site-workflow/references/serve-and-studio.md +138 -0
  269. package/skills/deco-storefront-caching/SKILL.md +67 -0
  270. package/skills/deco-storefront-caching/references/cache-keys.md +129 -0
  271. package/skills/deco-storefront-caching/references/case-study.md +82 -0
  272. package/skills/deco-storefront-caching/references/egress-traps.md +153 -0
  273. package/skills/deco-storefront-caching/references/nextjs.md +60 -0
  274. package/skills/deco-storefront-caching/references/perf-guardrails-e2e.md +123 -0
  275. package/skills/deco-storefront-caching/references/verification.md +136 -0
  276. package/skills/deco-storefront-caching/references/worker-page-cache.md +160 -0
  277. package/skills/deco-storefront-caching/scripts/html-anatomy.mjs +97 -0
  278. package/skills/deco-storefront-performance/SKILL.md +81 -0
  279. package/skills/deco-storefront-performance/references/cls-third-party.md +90 -0
  280. package/skills/deco-storefront-performance/references/hydration.md +116 -0
  281. package/skills/deco-storefront-performance/references/loaders-n-plus-1.md +107 -0
  282. package/skills/deco-storefront-performance/references/navigation-ux.md +130 -0
  283. package/skills/deco-storefront-performance/references/payload-trim.md +163 -0
  284. package/skills/deco-storefront-performance/references/render-location.md +152 -0
  285. package/skills/deco-storefront-performance/references/request-dedupe.md +147 -0
  286. package/skills/deco-storefront-performance/references/trace-reading.md +79 -0
  287. package/skills/deco-storefront-performance/references/worker-memory.md +176 -0
  288. package/skills/deco-tanstack-site/SKILL.md +68 -0
  289. package/skills/deco-tanstack-site/references/document-and-security.md +155 -0
  290. package/skills/deco-tanstack-site/references/router-and-navigation.md +137 -0
  291. package/skills/deco-tanstack-site/references/routes-and-pages.md +183 -0
  292. package/skills/deco-tanstack-site/references/server-functions.md +123 -0
  293. package/skills/deco-tanstack-site/references/setup.md +153 -0
  294. package/skills/deco-tanstack-site/references/worker-entry.md +152 -0
  295. package/skills/deco-v7-to-v8-migration/SKILL.md +122 -0
  296. package/skills/deco-v7-to-v8-migration/references/caching-and-privacy.md +10 -0
  297. package/skills/deco-v7-to-v8-migration/references/content.md +25 -0
  298. package/skills/deco-v7-to-v8-migration/references/editor-forms.md +27 -0
  299. package/skills/deco-v7-to-v8-migration/references/faststore.md +40 -0
  300. package/skills/deco-v7-to-v8-migration/references/framework-code.md +53 -0
  301. package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +16 -0
  302. package/skills/deco-v7-to-v8-migration/references/import-map.md +81 -0
  303. package/skills/deco-v7-to-v8-migration/references/legacy-names.md +33 -0
  304. package/skills/deco-v7-to-v8-migration/references/manual-steps.md +10 -0
  305. package/skills/deco-v7-to-v8-migration/references/native-apps.md +43 -0
  306. package/skills/deco-v7-to-v8-migration/references/nextjs.md +19 -0
  307. package/skills/deco-v7-to-v8-migration/references/parity.md +66 -0
  308. package/skills/deco-v7-to-v8-migration/references/rendering.md +13 -0
  309. package/skills/deco-v7-to-v8-migration/references/running-the-script.md +29 -0
  310. package/skills/deco-v7-to-v8-migration/references/script-steps.md +13 -0
  311. package/skills/deco-v7-to-v8-migration/references/server-functions.md +15 -0
  312. package/skills/deco-v7-to-v8-migration/references/sibling-port.md +11 -0
  313. package/skills/deco-v7-to-v8-migration/references/site-code.md +15 -0
  314. package/skills/deco-v7-to-v8-migration/references/telemetry.md +10 -0
  315. package/skills/deco-v7-to-v8-migration/references/verify.md +20 -0
  316. package/skills/deco-v7-to-v8-migration/scripts/apps.ts +297 -0
  317. package/skills/deco-v7-to-v8-migration/scripts/asyncRendering.ts +73 -0
  318. package/skills/deco-v7-to-v8-migration/scripts/blockMap.ts +584 -0
  319. package/skills/deco-v7-to-v8-migration/scripts/ciSchemaCheck.ts +145 -0
  320. package/skills/deco-v7-to-v8-migration/scripts/compat.ts +357 -0
  321. package/skills/deco-v7-to-v8-migration/scripts/content.ts +121 -0
  322. package/skills/deco-v7-to-v8-migration/scripts/experiments.ts +81 -0
  323. package/skills/deco-v7-to-v8-migration/scripts/framework.ts +61 -0
  324. package/skills/deco-v7-to-v8-migration/scripts/imageCopy.ts +276 -0
  325. package/skills/deco-v7-to-v8-migration/scripts/imageModule.ts +285 -0
  326. package/skills/deco-v7-to-v8-migration/scripts/imports.ts +942 -0
  327. package/skills/deco-v7-to-v8-migration/scripts/invoke.ts +624 -0
  328. package/skills/deco-v7-to-v8-migration/scripts/legacyNames.ts +45 -0
  329. package/skills/deco-v7-to-v8-migration/scripts/main.ts +59 -0
  330. package/skills/deco-v7-to-v8-migration/scripts/matchers.ts +41 -0
  331. package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +176 -0
  332. package/skills/deco-v7-to-v8-migration/scripts/redirects.ts +455 -0
  333. package/skills/deco-v7-to-v8-migration/scripts/report.ts +50 -0
  334. package/skills/deco-v7-to-v8-migration/scripts/scaffold.ts +1119 -0
  335. package/skills/deco-v7-to-v8-migration/scripts/secrets.ts +35 -0
  336. package/skills/deco-v7-to-v8-migration/scripts/sectionLoaders.ts +216 -0
  337. package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +261 -0
  338. package/skills/deco-v7-to-v8-migration/scripts/stubs.ts +388 -0
  339. package/skills/deco-v7-to-v8-migration/scripts/tsconfig.json +7 -0
  340. package/skills/deco-v7-to-v8-migration/scripts/vendor.ts +249 -0
  341. package/skills/deco-v7-to-v8-migration/scripts/vtexInvoke.ts +240 -0
  342. package/skills/deco-v7-to-v8-migration/scripts/walk.ts +30 -0
  343. package/skills/deco-variants/SKILL.md +57 -0
  344. package/skills/deco-variants/references/caching-variants.md +63 -0
  345. package/skills/deco-variants/references/custom-matchers.md +83 -0
  346. package/skills/deco-variants/references/draft-preview.md +59 -0
  347. package/skills/deco-variants/references/experiments-and-campaigns.md +104 -0
  348. package/skills/deco-variants/references/multivariate.md +85 -0
  349. package/skills/deco-variants/references/v7-matchers.md +71 -0
  350. package/src/index.ts +2 -0
  351. package/src/protocol/channel.ts +127 -0
  352. package/src/protocol/client.ts +2 -2
  353. package/src/protocol/conformance/blockMetaVectors.json +214 -0
  354. package/src/protocol/conformance/contentHashFixtures.ts +74 -0
  355. package/src/protocol/conformance/index.ts +9 -1
  356. package/src/protocol/conformance/vectors.ts +36 -0
  357. package/src/protocol/index.ts +32 -0
  358. package/src/protocol/keys.ts +1 -1
  359. package/src/v8/background.ts +42 -0
  360. package/src/v8/blockMeta.ts +100 -0
  361. package/src/v8/blockStore.ts +124 -0
  362. package/src/v8/boundedJson.ts +20 -2
  363. package/src/v8/boundedMap.ts +53 -0
  364. package/src/v8/builtins/data.ts +26 -2
  365. package/src/v8/builtins/index.ts +2 -1
  366. package/src/v8/builtins/legacy.ts +6 -3
  367. package/src/v8/canonical.ts +15 -0
  368. package/src/v8/cli/builtins.ts +1 -0
  369. package/src/v8/cli/check/index.ts +97 -7
  370. package/src/v8/cli/content.ts +49 -91
  371. package/src/v8/cli/index.ts +2 -2
  372. package/src/v8/cli/remote/commands.ts +834 -0
  373. package/src/v8/cli/remote/diff.ts +100 -0
  374. package/src/v8/cli/remote/env.ts +107 -0
  375. package/src/v8/cli/remote/http.ts +484 -0
  376. package/src/v8/cli/remote/local.ts +343 -0
  377. package/src/v8/cli/root.ts +40 -0
  378. package/src/v8/cli/run.ts +366 -135
  379. package/src/v8/cli/schema/builtinSchemas.ts +29 -10
  380. package/src/v8/cli/schema/generate.ts +1 -1
  381. package/src/v8/cli/skills.ts +91 -0
  382. package/src/v8/client.ts +162 -60
  383. package/src/v8/cms.ts +62 -53
  384. package/src/v8/content.ts +179 -229
  385. package/src/v8/contentIndex.ts +183 -0
  386. package/src/v8/draft.ts +15 -14
  387. package/src/v8/draftChanges.ts +151 -85
  388. package/src/v8/errors.ts +37 -0
  389. package/src/v8/hostedSource.ts +67 -0
  390. package/src/v8/identity.ts +1 -1
  391. package/src/v8/index.ts +1 -0
  392. package/src/v8/matchRoute.ts +7 -4
  393. package/src/v8/pin.ts +176 -0
  394. package/src/v8/preview/StudioBridge.ts +8 -10
  395. package/src/v8/preview/StudioChannel.ts +116 -0
  396. package/src/v8/preview/index.ts +3 -0
  397. package/src/v8/remoteLoader.ts +350 -286
  398. package/src/v8/resolver.ts +56 -33
  399. package/src/v8/revisionId.ts +14 -0
  400. package/src/v8/settings.ts +10 -9
  401. package/src/v8/telemetry.ts +3 -3
  402. package/src/v8/types.ts +52 -40
  403. package/src/v8/variants.ts +30 -26
  404. package/src/v8/vite/index.ts +3 -3
  405. package/dist/v8/cli/serve/server.d.ts +0 -29
  406. package/dist/v8/cli/serve/server.d.ts.map +0 -1
  407. package/dist/v8/cli/serve/server.js +0 -296
  408. package/dist/v8/cli/serve/server.js.map +0 -1
  409. package/src/v8/cli/serve/server.ts +0 -348
package/src/v8/cli/run.ts CHANGED
@@ -1,67 +1,139 @@
1
1
  /**
2
- * The `deco` command line: `deco <schema|content|check|serve> [flags]`
3
- * (spec: cli). Parses flags, runs one command and returns its exit code.
2
+ * The `deco` command line (spec: cli). Parses flags, runs one command and
3
+ * returns its exit code (spec: cli › Exit codes): 0 ok, 1 check failed (or
4
+ * any other failure), 2 conflict, 3 auth, 4 network, 5 busy (run again), 64
5
+ * usage. Every command takes `--json`: stdout then carries exactly one JSON
6
+ * object, and what a person reads goes to stderr.
4
7
  */
5
- import { check } from "./check/index.ts";
6
- import { content, writeContent } from "./content.ts";
8
+ import path from "node:path";
9
+ import { readSchemaFile, reportCheck } from "./check/index.ts";
10
+ import { content, readSavedBlocks, savedBlocksFromMap, writeContent } from "./content.ts";
7
11
  import { consoleReporter, type Reporter, withColor } from "./log.ts";
8
- import { CliError, decoPaths, findDecoRoot } from "./root.ts";
12
+ import {
13
+ diff,
14
+ drafts,
15
+ login,
16
+ type Outcome,
17
+ publish,
18
+ pull,
19
+ push,
20
+ type RemoteContext,
21
+ releases,
22
+ remoteBlocks,
23
+ schemaPush,
24
+ } from "./remote/commands.ts";
25
+ import type { CommandRunner, Env } from "./remote/env.ts";
26
+ import type { Fetch } from "./remote/http.ts";
27
+ import { checkDraftName, findSite, requireDraftName } from "./remote/local.ts";
28
+ import { CliError, decoPaths, EXIT, findDecoRoot, packageVersion, usageError } from "./root.ts";
9
29
  import { reportSchema, schema, writeSchema } from "./schema/index.ts";
10
- import { serve, startServer } from "./serve/server.ts";
30
+ import { installSkills } from "./skills.ts";
11
31
  import { watchFiles, watchTree } from "./watch.ts";
12
32
 
13
33
  type FlagKind = "string" | "boolean";
14
34
 
15
- const COMMANDS: Record<string, { usage: string; flags: Record<string, FlagKind> }> = {
16
- schema: {
17
- usage: "deco schema [--root <dir>] [--watch | --check]",
18
- flags: { root: "string", watch: "boolean", check: "boolean" },
35
+ interface CommandSpec {
36
+ usage: string;
37
+ flags: Record<string, FlagKind>;
38
+ /** How many positional arguments it takes, at most. */
39
+ positionals?: number;
40
+ }
41
+
42
+ const DRAFT = { draft: "string" } as const;
43
+
44
+ const COMMANDS: Record<string, CommandSpec> = {
45
+ login: { usage: "deco login", flags: {} },
46
+ pull: {
47
+ usage: "deco pull [--draft=<name>] [--force]",
48
+ flags: { ...DRAFT, force: "boolean" },
49
+ },
50
+ diff: { usage: "deco diff [--draft=<name>]", flags: { ...DRAFT } },
51
+ push: {
52
+ usage: "deco push --draft=<name> [--ours | --theirs] [--prune]",
53
+ flags: { ...DRAFT, ours: "boolean", theirs: "boolean", prune: "boolean" },
54
+ },
55
+ publish: {
56
+ usage: "deco publish --draft=<name> [--message=<text>]",
57
+ flags: { ...DRAFT, message: "string" },
58
+ },
59
+ drafts: {
60
+ usage: "deco drafts list | new <name> | discard <name> | url <name>",
61
+ flags: {},
62
+ positionals: 2,
63
+ },
64
+ releases: { usage: "deco releases [--cursor=<cursor>]", flags: { cursor: "string" } },
65
+ check: {
66
+ usage: "deco check [--draft=<name> | --revision=<id>]",
67
+ flags: { ...DRAFT, revision: "string" },
19
68
  },
20
69
  content: {
21
- usage: "deco content [--root <dir>] [--watch]",
22
- flags: { root: "string", watch: "boolean" },
70
+ usage: "deco content [--watch]",
71
+ flags: { watch: "boolean" },
23
72
  },
24
- check: { usage: "deco check [--root <dir>]", flags: { root: "string" } },
25
- serve: {
26
- usage:
27
- "deco serve [--root <dir>] [--port <n>] [--host <addr>] [--preview <host:port|url>] [--assets <dir>] [--read-only]",
28
- flags: {
29
- root: "string",
30
- port: "string",
31
- host: "string",
32
- preview: "string",
33
- assets: "string",
34
- "read-only": "boolean",
35
- },
73
+ schema: {
74
+ usage: "deco schema [--watch | --check]\n deco schema push",
75
+ flags: { watch: "boolean", check: "boolean" },
76
+ positionals: 1,
77
+ },
78
+ skills: {
79
+ usage: "deco skills install [--dir=<path>]",
80
+ flags: { dir: "string" },
81
+ positionals: 1,
36
82
  },
37
83
  };
38
84
 
85
+ /** Flags every command takes. */
86
+ const COMMON_FLAGS: Record<string, FlagKind> = { root: "string", json: "boolean" };
87
+
39
88
  export const USAGE = `Usage: deco <command> [flags]
40
89
 
41
90
  Commands:
91
+ login print how to log in (the session is Studio CLI's: npx decocms auth login)
92
+ pull write production, or a draft, into .deco/blocks
93
+ diff show what .deco/blocks changes against what was pulled, or against a draft
94
+ push save the blocks changed since the pull into a draft as one change (deletes with
95
+ --prune); prints its preview link
96
+ publish make a draft live (prints its changes first)
97
+ drafts list, create, discard a draft, or print its preview link
98
+ releases list the published revisions, newest first, 50 a page
99
+ check check that the content fits the schema (production; or a draft, or a revision;
100
+ with no DECO_SITE set anywhere, the saved blocks in .deco/blocks)
101
+ content turn .deco/blocks into the content module, .deco/blocks.gen.ts (content without
102
+ a site: createCMS({ blocks, content }))
42
103
  schema turn the types in .deco/index.ts into .deco/schema.gen.json
43
104
  (--check: write nothing, fail when the file is out of date; for CI)
44
- content turn .deco/blocks into the content module, .deco/blocks.gen.ts
45
- check check that every saved block fits the schema (writes nothing)
46
- serve serve .deco to the site editor on this machine, at http://localhost:4545/rpc;
47
- run it inside the site's git repository (the change list compares with HEAD)
105
+ schema push: upload it so Studio can draw forms (CI, on production deploys)
106
+ skills skills install: copy the agent skills of this @decocms/blocks into the site,
107
+ one folder per skill in .claude/skills (or --dir, relative to the folder that
108
+ contains .deco/); replaces those folders, leaves other skills alone; offline
48
109
 
49
110
  ${Object.values(COMMANDS)
50
111
  .map((c) => ` ${c.usage}`)
51
112
  .join("\n")}
52
113
 
53
114
  Every command finds .deco/ by walking up from the current folder, or takes --root.
54
- Every command takes --color or --no-color; without either, output is coloured only on a terminal.`;
115
+ Every command takes --json (one JSON object on stdout) and --color or --no-color.
116
+ Site: DECO_SITE, from the environment, else .env, .dev.vars, then vars.DECO_SITE in
117
+ wrangler.jsonc, wrangler.json or wrangler.toml (in the folder that contains .deco/).
118
+ Studio: DECO_STUDIO_URL (default https://studio.decocms.com); token: DECO_TOKEN, else
119
+ npx decocms auth token. Exit codes: 0 ok, 1 failed, 2 conflict, 3 auth, 4 network,
120
+ 5 busy (run again), 64 usage.`;
55
121
 
56
122
  export type ParsedFlags = Record<string, string | boolean | string[]>;
57
123
 
58
124
  export function parseFlags(command: string, args: string[]): ParsedFlags {
59
- const spec = COMMANDS[command].flags;
125
+ const command_ = COMMANDS[command]!;
126
+ const spec = { ...COMMON_FLAGS, ...command_.flags };
60
127
  const flags: ParsedFlags = {};
128
+ const positionals: string[] = [];
61
129
  for (let i = 0; i < args.length; i++) {
62
- const arg = args[i];
63
- if (!arg.startsWith("--"))
64
- throw new CliError(`unexpected argument "${arg}"\n${COMMANDS[command].usage}`);
130
+ const arg = args[i]!;
131
+ if (!arg.startsWith("--")) {
132
+ if (positionals.length >= (command_.positionals ?? 0))
133
+ throw usageError(`unexpected argument "${arg}"\n${command_.usage}`);
134
+ positionals.push(arg);
135
+ continue;
136
+ }
65
137
  // Every command's: `color` is true, false or absent; the last one given wins.
66
138
  if (arg === "--color" || arg === "--no-color") {
67
139
  flags.color = arg === "--color";
@@ -69,11 +141,11 @@ export function parseFlags(command: string, args: string[]): ParsedFlags {
69
141
  }
70
142
  const eq = arg.indexOf("=");
71
143
  const name = arg.slice(2, eq === -1 ? undefined : eq);
72
- if (name === "color" || name === "no-color") throw new CliError(`--${name} takes no value`);
144
+ if (name === "color" || name === "no-color") throw usageError(`--${name} takes no value`);
73
145
  const kind = Object.hasOwn(spec, name) ? spec[name] : undefined;
74
- if (!kind) throw new CliError(`unknown flag --${name}\n${COMMANDS[command].usage}`);
146
+ if (!kind) throw usageError(`unknown flag --${name}\n${command_.usage}`);
75
147
  if (kind === "boolean") {
76
- if (eq !== -1) throw new CliError(`--${name} takes no value`);
148
+ if (eq !== -1) throw usageError(`--${name} takes no value`);
77
149
  flags[name] = true;
78
150
  continue;
79
151
  }
@@ -82,11 +154,12 @@ export function parseFlags(command: string, args: string[]): ParsedFlags {
82
154
  else {
83
155
  value = args[i + 1];
84
156
  if (value === undefined || value.startsWith("--"))
85
- throw new CliError(`--${name} needs a value`);
157
+ throw usageError(`--${name} needs a value`);
86
158
  i++;
87
159
  }
88
160
  flags[name] = value;
89
161
  }
162
+ if (positionals.length > 0) flags._ = positionals;
90
163
  return flags;
91
164
  }
92
165
 
@@ -94,8 +167,18 @@ export interface RunOptions {
94
167
  cwd?: string;
95
168
  /** Defaults to the console, coloured when stdout and stderr are both terminals. */
96
169
  reporter?: Reporter;
97
- /** Resolves when a `--watch` or `serve` run should stop (tests); defaults to SIGINT/SIGTERM. */
170
+ /** Resolves when a `--watch` run should stop (tests); defaults to SIGINT/SIGTERM. */
98
171
  until?: Promise<void>;
172
+ /** The environment (`DECO_STUDIO_URL`, `DECO_TOKEN`); defaults to the process's. */
173
+ env?: Env;
174
+ /** Defaults to the global `fetch`. */
175
+ fetch?: Fetch;
176
+ /** Runs `npx decocms auth token` (tests replace it). */
177
+ runCommand?: CommandRunner;
178
+ /** Where `--json` writes its object; defaults to stdout. */
179
+ stdout?: (text: string) => void;
180
+ /** The skills `deco skills install` copies; defaults to the package's `skills/` (tests replace it). */
181
+ skillsDir?: string;
99
182
  }
100
183
 
101
184
  function stopSignal(): Promise<void> {
@@ -128,124 +211,272 @@ async function watchLoop(
128
211
  await running;
129
212
  }
130
213
 
131
- /**
132
- * What `deco publish` prints. It isn't one of the four commands and isn't in
133
- * the usage: publishing is committing (/next/design-decisions).
134
- */
135
- const PUBLISH_SIGNPOST = `There is no publish command: Git is the source of truth for content, so publishing is committing.
136
- Commit the changes in .deco/blocks (and push them). A deploy ships the commit; with the hosted
137
- Deco CMS, Studio's Publish (or Resync) makes the commit a release without a deploy.`;
214
+ /** Everything a person reads goes to stderr, so `--json`'s stdout is one object. */
215
+ const stderrReporter: Reporter = {
216
+ info: (message) => console.error(message),
217
+ warn: (message) => console.error(message),
218
+ error: (message) => console.error(message),
219
+ };
220
+
221
+ function stringFlag(flags: ParsedFlags, name: string): string | null {
222
+ const value = flags[name];
223
+ return typeof value === "string" ? value : null;
224
+ }
138
225
 
139
226
  /** Run one `deco` invocation; returns the exit code. */
140
227
  export async function runCli(argv: string[], options: RunOptions = {}): Promise<number> {
141
228
  let reporter = options.reporter ?? consoleReporter;
229
+ const stdout = options.stdout ?? ((text: string) => process.stdout.write(`${text}\n`));
142
230
  const [command, ...rest] = argv;
143
231
  if (!command || command === "help" || command === "--help" || command === "-h") {
144
232
  reporter.info(USAGE);
145
- return command ? 0 : 1;
146
- }
147
- if (command === "publish") {
148
- // Not a command: a signpost for agents that look for one (design-decisions).
149
- reporter.error(PUBLISH_SIGNPOST);
150
- return 1;
151
- }
152
- if (!Object.hasOwn(COMMANDS, command)) {
153
- reporter.error(`unknown command "${command}"\n\n${USAGE}`);
154
- return 1;
233
+ return command ? EXIT.ok : EXIT.usage;
155
234
  }
235
+ const json = rest.includes("--json");
236
+ if (json && !options.reporter) reporter = stderrReporter;
237
+ let outcome: Outcome;
156
238
  try {
239
+ if (!Object.hasOwn(COMMANDS, command))
240
+ throw usageError(`unknown command "${command}"\n\n${USAGE}`);
157
241
  const flags = parseFlags(command, rest);
158
242
  const color =
159
243
  typeof flags.color === "boolean"
160
244
  ? flags.color
161
245
  : options.reporter
162
246
  ? Boolean(options.reporter.color)
163
- : Boolean(process.stdout.isTTY && process.stderr.isTTY);
247
+ : !json && Boolean(process.stdout.isTTY && process.stderr.isTTY);
164
248
  reporter = withColor(reporter, color);
165
- const root = flags.root as string | undefined;
166
- const base = { root, cwd: options.cwd, reporter };
167
- switch (command) {
168
- case "schema": {
169
- if (flags.watch && flags.check) {
170
- throw new CliError(`--watch and --check can't be combined\n${COMMANDS.schema.usage}`);
171
- }
172
- if (!flags.watch) return await schema({ ...base, check: flags.check === true });
173
- const paths = decoPaths(findDecoRoot(base));
174
- // Monorepo packages the block map imports live outside the root:
175
- // watch the files the last run read there, too.
176
- const external = watchFiles(() => void once());
177
- let running = Promise.resolve();
178
- const run = async () => {
179
- const result = await writeSchema(paths);
180
- external.update(result.externalSources);
181
- reportSchema(result, reporter);
182
- };
183
- const once = () => {
184
- running = running.then(run).catch((error) => reporter.error((error as Error).message));
185
- return running;
249
+ const env = options.env ?? process.env;
250
+ outcome = await runCommand(command, flags, { ...options, env, reporter });
251
+ } catch (error) {
252
+ if (!(error instanceof CliError)) throw error;
253
+ reporter.error(error.message);
254
+ if (json) {
255
+ stdout(
256
+ JSON.stringify({
257
+ ok: false,
258
+ exitCode: error.exitCode,
259
+ error: { code: error.code, message: error.message },
260
+ ...error.details,
261
+ }),
262
+ );
263
+ }
264
+ return error.exitCode;
265
+ }
266
+ if (json) {
267
+ stdout(
268
+ JSON.stringify(
269
+ outcome.exitCode === EXIT.ok
270
+ ? { ok: true, ...outcome.result }
271
+ : { ok: false, exitCode: outcome.exitCode, ...outcome.result },
272
+ ),
273
+ );
274
+ }
275
+ return outcome.exitCode;
276
+ }
277
+
278
+ /**
279
+ * The root of a remote command. With no `.deco/` at all a remote command has
280
+ * no folder to work in nor to read `DECO_SITE` from, a usage error (64), as a
281
+ * missing `DECO_SITE` is (contract §7.4); local commands keep exit 1. The
282
+ * message stays the documented one (cli-09).
283
+ */
284
+ function remoteRoot(options: { root?: string; cwd?: string }): string {
285
+ try {
286
+ return findDecoRoot(options);
287
+ } catch (error) {
288
+ if (error instanceof CliError && error.exitCode !== EXIT.usage) {
289
+ throw usageError(error.message);
290
+ }
291
+ throw error;
292
+ }
293
+ }
294
+
295
+ async function runCommand(
296
+ command: string,
297
+ flags: ParsedFlags,
298
+ options: RunOptions & { env: Env; reporter: Reporter },
299
+ ): Promise<Outcome> {
300
+ const { reporter } = options;
301
+ const positionals = (flags._ as string[] | undefined) ?? [];
302
+ const root = flags.root as string | undefined;
303
+ const base = { root, cwd: options.cwd, reporter };
304
+ const remote = (): RemoteContext => ({
305
+ paths: decoPaths(remoteRoot(base)),
306
+ reporter,
307
+ env: options.env,
308
+ fetch: options.fetch ?? fetch,
309
+ runCommand: options.runCommand,
310
+ });
311
+ const legacy = (exitCode: number, result: Record<string, unknown> = {}): Outcome =>
312
+ exitCode === EXIT.ok
313
+ ? { exitCode, result }
314
+ : {
315
+ exitCode,
316
+ result: { error: { code: "failed", message: `deco ${command} failed` }, ...result },
186
317
  };
187
- await run();
188
- // Regenerate when any source file changes; the schema only depends on code.
189
- await watchLoop(
190
- paths.root,
191
- (rel) =>
192
- /\.(ts|tsx|mts|cts)$/.test(rel) &&
193
- !rel
194
- .split("/")
195
- .some((s) => s === "node_modules" || s.startsWith(".git") || s === "dist") &&
196
- !rel.endsWith(".gen.ts"),
197
- once,
198
- options.until ?? stopSignal(),
199
- reporter,
200
- );
201
- external.close();
202
- await running;
203
- return 0;
318
+ switch (command) {
319
+ case "login":
320
+ return login({ env: options.env, reporter });
321
+ case "pull": {
322
+ const draft = stringFlag(flags, "draft");
323
+ return pull(remote(), {
324
+ draft: draft === null ? null : checkDraftName(draft),
325
+ force: flags.force === true,
326
+ });
327
+ }
328
+ case "diff": {
329
+ const draft = stringFlag(flags, "draft");
330
+ return diff(remote(), { draft: draft === null ? null : checkDraftName(draft) });
331
+ }
332
+ case "push": {
333
+ const draft = requireDraftName(flags.draft, "push");
334
+ if (flags.ours && flags.theirs) throw usageError("--ours and --theirs can't be combined");
335
+ return push(remote(), {
336
+ draft,
337
+ side: flags.ours ? "ours" : flags.theirs ? "theirs" : null,
338
+ prune: flags.prune === true,
339
+ });
340
+ }
341
+ case "publish":
342
+ return publish(remote(), {
343
+ draft: requireDraftName(flags.draft, "publish"),
344
+ message: stringFlag(flags, "message") ?? undefined,
345
+ });
346
+ case "drafts": {
347
+ const name = positionals[1] ?? null;
348
+ return drafts(remote(), {
349
+ action: positionals[0],
350
+ name: name === null ? null : checkDraftName(name),
351
+ });
352
+ }
353
+ case "releases":
354
+ return releases(remote(), { cursor: stringFlag(flags, "cursor") ?? undefined });
355
+ case "check": {
356
+ const draft = stringFlag(flags, "draft");
357
+ const revision = stringFlag(flags, "revision");
358
+ if (draft !== null && revision !== null)
359
+ throw usageError("--draft and --revision can't be combined");
360
+ // No flag: production (latest.json, then each block by hash, from the
361
+ // CDN), always, even when .deco/blocks exists. No .deco/ at all stays
362
+ // exit 1 for check, as before.
363
+ const paths = decoPaths(findDecoRoot(base));
364
+ if (draft === null && revision === null && findSite(paths, options.env) === null) {
365
+ // No Studio site: the content is the git-backed .deco/blocks (a site
366
+ // on createCMS({ blocks, content }), a v7 site being migrated), checked
367
+ // as deco check always did.
368
+ const meta = readSchemaFile(paths.schema);
369
+ return checkOutcome(reportCheck(meta, readSavedBlocks(paths.blocks), reporter));
204
370
  }
205
- case "content": {
206
- if (!flags.watch) return await content(base);
207
- const paths = decoPaths(findDecoRoot(base));
208
- const once = async () => {
209
- const result = await writeContent(paths);
210
- if (result.changed) reporter.info(`wrote .deco/blocks.gen.ts (${result.count} blocks)`);
211
- };
212
- await content({ ...base, watching: true });
213
- await watchLoop(
214
- paths.blocks,
215
- (rel) => rel.endsWith(".json"),
216
- once,
217
- options.until ?? stopSignal(),
218
- reporter,
219
- );
220
- return 0;
371
+ const ctx = remote();
372
+ const meta = readSchemaFile(ctx.paths.schema);
373
+ const source = await remoteBlocks(ctx, {
374
+ draft: draft === null ? null : checkDraftName(draft),
375
+ revision,
376
+ });
377
+ reporter.info(`checking ${source.label}`);
378
+ return checkOutcome(reportCheck(meta, savedBlocksFromMap(source.blocks), reporter));
379
+ }
380
+ case "content": {
381
+ if (!flags.watch) return legacy(await content(base));
382
+ const paths = decoPaths(findDecoRoot(base));
383
+ const once = async () => {
384
+ const result = await writeContent(paths);
385
+ if (result.changed) reporter.info(`wrote .deco/blocks.gen.ts (${result.count} blocks)`);
386
+ };
387
+ await content({ ...base, watching: true });
388
+ await watchLoop(
389
+ paths.blocks,
390
+ (rel) => rel.endsWith(".json"),
391
+ once,
392
+ options.until ?? stopSignal(),
393
+ reporter,
394
+ );
395
+ return { exitCode: EXIT.ok, result: {} };
396
+ }
397
+ case "schema": {
398
+ if (positionals.length > 0) {
399
+ if (positionals[0] !== "push")
400
+ throw usageError(`unexpected argument "${positionals[0]}"\n${COMMANDS.schema!.usage}`);
401
+ if (flags.watch || flags.check)
402
+ throw usageError("deco schema push takes no --watch or --check");
403
+ return schemaPush(remote());
221
404
  }
222
- case "check":
223
- return check(base);
224
- case "serve": {
225
- const port = flags.port === undefined ? undefined : Number(flags.port);
226
- if (port !== undefined && !Number.isInteger(port))
227
- throw new CliError(`--port must be a number, got ${flags.port}`);
228
- const serveOptions = {
229
- ...base,
230
- port,
231
- host: flags.host as string | undefined,
232
- preview: flags.preview as string | undefined,
233
- assets: flags.assets as string | undefined,
234
- readOnly: Boolean(flags["read-only"]),
235
- };
236
- if (!options.until) return await serve(serveOptions);
237
- const running = await startServer(serveOptions);
238
- await options.until;
239
- await running.close();
240
- return 0;
405
+ if (flags.watch && flags.check) {
406
+ throw usageError(`--watch and --check can't be combined\n${COMMANDS.schema!.usage}`);
241
407
  }
408
+ if (!flags.watch) return legacy(await schema({ ...base, check: flags.check === true }));
409
+ const paths = decoPaths(findDecoRoot(base));
410
+ // Monorepo packages the block map imports live outside the root:
411
+ // watch the files the last run read there, too.
412
+ const external = watchFiles(() => void once());
413
+ let running = Promise.resolve();
414
+ const run = async () => {
415
+ const result = await writeSchema(paths);
416
+ external.update(result.externalSources);
417
+ reportSchema(result, reporter);
418
+ };
419
+ const once = () => {
420
+ running = running.then(run).catch((error) => reporter.error((error as Error).message));
421
+ return running;
422
+ };
423
+ await run();
424
+ // Regenerate when any source file changes; the schema only depends on code.
425
+ await watchLoop(
426
+ paths.root,
427
+ (rel) =>
428
+ /\.(ts|tsx|mts|cts)$/.test(rel) &&
429
+ !rel
430
+ .split("/")
431
+ .some((s) => s === "node_modules" || s.startsWith(".git") || s === "dist") &&
432
+ !rel.endsWith(".gen.ts"),
433
+ once,
434
+ options.until ?? stopSignal(),
435
+ reporter,
436
+ );
437
+ external.close();
438
+ await running;
439
+ return { exitCode: EXIT.ok, result: {} };
242
440
  }
243
- return 1;
244
- } catch (error) {
245
- if (error instanceof CliError) {
246
- reporter.error(error.message);
247
- return 1;
441
+ case "skills": {
442
+ if (positionals[0] !== "install") {
443
+ throw usageError(
444
+ positionals.length === 0
445
+ ? `deco skills needs a subcommand\n${COMMANDS.skills!.usage}`
446
+ : `unexpected argument "${positionals[0]}"\n${COMMANDS.skills!.usage}`,
447
+ );
448
+ }
449
+ const dir = stringFlag(flags, "dir") ?? undefined;
450
+ const paths = decoPaths(findDecoRoot(base));
451
+ const installed = installSkills({ root: paths.root, dir, from: options.skillsDir });
452
+ const shown = path.relative(paths.root, installed.dir) || ".";
453
+ const where = shown.startsWith("..") || path.isAbsolute(shown) ? installed.dir : shown;
454
+ for (const name of installed.skills) reporter.info(`installed ${path.join(where, name)}/`);
455
+ reporter.info(
456
+ `${installed.skills.length} skill(s) from @decocms/blocks ${packageVersion()} in ${where}`,
457
+ );
458
+ return {
459
+ exitCode: EXIT.ok,
460
+ result: { dir: installed.dir, version: packageVersion(), skills: installed.skills },
461
+ };
248
462
  }
249
- throw error;
250
463
  }
464
+ throw usageError(`unknown command "${command}"`);
465
+ }
466
+
467
+ function checkOutcome(report: ReturnType<typeof reportCheck>): Outcome {
468
+ const result = {
469
+ blocks: report.count,
470
+ errors: report.errors,
471
+ warnings: report.warnings,
472
+ problems: report.problems,
473
+ };
474
+ if (report.exitCode === EXIT.ok) return { exitCode: EXIT.ok, result };
475
+ return {
476
+ exitCode: report.exitCode,
477
+ result: {
478
+ error: { code: "check_failed", message: `${report.errors} errors` },
479
+ ...result,
480
+ },
481
+ };
251
482
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The forms of the twelve built-in blocks (spec: built-in-blocks, and the types
2
+ * The forms of the thirteen built-in blocks (spec: built-in-blocks, and the types
3
3
  * in api-reference › Types). They're always in the schema, unless the block
4
4
  * map declares the same key, which replaces the built-in.
5
5
  */
@@ -16,6 +16,7 @@ export const BUILT_IN_GROUPS: Record<string, ManifestGroup> = {
16
16
  campaign: "matchers",
17
17
  page: "pages",
18
18
  redirect: "redirects",
19
+ redirects: "redirects",
19
20
  "cms-settings": "content",
20
21
  "split-traffic": "content",
21
22
  calendar: "content",
@@ -42,6 +43,10 @@ const BUILT_IN_DOCS: Record<string, { title: string; description: string; icon?:
42
43
  },
43
44
  page: { title: "Page", description: "A page at a URL" },
44
45
  redirect: { title: "Redirect", description: "Sends one URL to another" },
46
+ redirects: {
47
+ title: "Redirects",
48
+ description: "The site's redirects: every rule in one block (the saved block Redirects)",
49
+ },
45
50
  "cms-settings": {
46
51
  title: "CMS settings",
47
52
  description: "Telemetry and analytics: the saved block named CMS",
@@ -61,6 +66,23 @@ const BUILT_IN_DOCS: Record<string, { title: string; description: string; icon?:
61
66
  },
62
67
  };
63
68
 
69
+ /** One redirect rule: the props of `redirect`, and each item of `redirects`. */
70
+ const REDIRECT_RULE = {
71
+ type: "object",
72
+ required: ["from", "to", "permanent"],
73
+ properties: {
74
+ from: { type: "string", title: "From" },
75
+ to: { type: "string", title: "To" },
76
+ permanent: {
77
+ type: "boolean",
78
+ title: "Permanent",
79
+ description: "301 when true, 307 otherwise",
80
+ },
81
+ status: { type: "number", enum: [301, 302, 307, 308], title: "Status" },
82
+ discardQueryParameters: { type: "boolean", title: "Discard query parameters" },
83
+ },
84
+ };
85
+
64
86
  /** The form of each test in a `split-traffic` block: a whole percentage. */
65
87
  const ALLOCATION = {
66
88
  type: "integer",
@@ -213,19 +235,16 @@ function builtInProps(name: string, ctx: BuiltInContext): any {
213
235
  },
214
236
  };
215
237
  case "redirect":
238
+ return REDIRECT_RULE;
239
+ case "redirects":
216
240
  return {
217
241
  type: "object",
218
- required: ["from", "to", "permanent"],
219
242
  properties: {
220
- from: { type: "string", title: "From" },
221
- to: { type: "string", title: "To" },
222
- permanent: {
223
- type: "boolean",
224
- title: "Permanent",
225
- description: "301 when true, 302 otherwise",
243
+ redirects: {
244
+ type: "array",
245
+ title: "Redirects",
246
+ items: { ...REDIRECT_RULE, title: "Redirect" },
226
247
  },
227
- status: { type: "number", enum: [301, 302, 307, 308], title: "Status" },
228
- discardQueryParameters: { type: "boolean", title: "Discard query parameters" },
229
248
  },
230
249
  };
231
250
  case "cms-settings":