@decocms/blocks 8.1.0-next.0 → 8.1.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (490) hide show
  1. package/bin/deco.js +5 -12
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +4 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/protocol/assets.d.ts +46 -0
  7. package/dist/protocol/assets.d.ts.map +1 -0
  8. package/dist/protocol/assets.js +105 -0
  9. package/dist/protocol/assets.js.map +1 -0
  10. package/dist/protocol/canonical.d.ts +8 -0
  11. package/dist/protocol/canonical.d.ts.map +1 -0
  12. package/dist/protocol/canonical.js +8 -0
  13. package/dist/protocol/canonical.js.map +1 -0
  14. package/dist/protocol/ciphertext.d.ts +7 -0
  15. package/dist/protocol/ciphertext.d.ts.map +1 -0
  16. package/dist/protocol/ciphertext.js +7 -0
  17. package/dist/protocol/ciphertext.js.map +1 -0
  18. package/dist/protocol/client.d.ts +54 -0
  19. package/dist/protocol/client.d.ts.map +1 -0
  20. package/dist/protocol/client.js +104 -0
  21. package/dist/protocol/client.js.map +1 -0
  22. package/dist/protocol/conformance/cases/assets.d.ts +3 -0
  23. package/dist/protocol/conformance/cases/assets.d.ts.map +1 -0
  24. package/dist/protocol/conformance/cases/assets.js +71 -0
  25. package/dist/protocol/conformance/cases/assets.js.map +1 -0
  26. package/dist/protocol/conformance/cases/guards.d.ts +3 -0
  27. package/dist/protocol/conformance/cases/guards.d.ts.map +1 -0
  28. package/dist/protocol/conformance/cases/guards.js +265 -0
  29. package/dist/protocol/conformance/cases/guards.js.map +1 -0
  30. package/dist/protocol/conformance/cases/reads.d.ts +3 -0
  31. package/dist/protocol/conformance/cases/reads.d.ts.map +1 -0
  32. package/dist/protocol/conformance/cases/reads.js +140 -0
  33. package/dist/protocol/conformance/cases/reads.js.map +1 -0
  34. package/dist/protocol/conformance/cases/types.d.ts +9 -0
  35. package/dist/protocol/conformance/cases/types.d.ts.map +1 -0
  36. package/dist/protocol/conformance/cases/types.js +2 -0
  37. package/dist/protocol/conformance/cases/types.js.map +1 -0
  38. package/dist/protocol/conformance/cases/wire.d.ts +3 -0
  39. package/dist/protocol/conformance/cases/wire.d.ts.map +1 -0
  40. package/dist/protocol/conformance/cases/wire.js +130 -0
  41. package/dist/protocol/conformance/cases/wire.js.map +1 -0
  42. package/dist/protocol/conformance/cases/writes.d.ts +3 -0
  43. package/dist/protocol/conformance/cases/writes.d.ts.map +1 -0
  44. package/dist/protocol/conformance/cases/writes.js +278 -0
  45. package/dist/protocol/conformance/cases/writes.js.map +1 -0
  46. package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
  47. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -0
  48. package/dist/protocol/conformance/contentHashFixtures.js +64 -0
  49. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -0
  50. package/dist/protocol/conformance/context.d.ts +100 -0
  51. package/dist/protocol/conformance/context.d.ts.map +1 -0
  52. package/dist/protocol/conformance/context.js +155 -0
  53. package/dist/protocol/conformance/context.js.map +1 -0
  54. package/dist/protocol/conformance/index.d.ts +32 -0
  55. package/dist/protocol/conformance/index.d.ts.map +1 -0
  56. package/dist/protocol/conformance/index.js +90 -0
  57. package/dist/protocol/conformance/index.js.map +1 -0
  58. package/dist/protocol/errors.d.ts +85 -0
  59. package/dist/protocol/errors.d.ts.map +1 -0
  60. package/dist/protocol/errors.js +62 -0
  61. package/dist/protocol/errors.js.map +1 -0
  62. package/dist/protocol/index.d.ts +25 -0
  63. package/dist/protocol/index.d.ts.map +1 -0
  64. package/dist/protocol/index.js +25 -0
  65. package/dist/protocol/index.js.map +1 -0
  66. package/dist/protocol/keys.d.ts +101 -0
  67. package/dist/protocol/keys.d.ts.map +1 -0
  68. package/dist/protocol/keys.js +223 -0
  69. package/dist/protocol/keys.js.map +1 -0
  70. package/dist/protocol/params.d.ts +10 -0
  71. package/dist/protocol/params.d.ts.map +1 -0
  72. package/dist/protocol/params.js +54 -0
  73. package/dist/protocol/params.js.map +1 -0
  74. package/dist/protocol/secrets.d.ts +22 -0
  75. package/dist/protocol/secrets.d.ts.map +1 -0
  76. package/dist/protocol/secrets.js +200 -0
  77. package/dist/protocol/secrets.js.map +1 -0
  78. package/dist/protocol/server/assets.d.ts +20 -0
  79. package/dist/protocol/server/assets.d.ts.map +1 -0
  80. package/dist/protocol/server/assets.js +77 -0
  81. package/dist/protocol/server/assets.js.map +1 -0
  82. package/dist/protocol/server/auth.d.ts +31 -0
  83. package/dist/protocol/server/auth.d.ts.map +1 -0
  84. package/dist/protocol/server/auth.js +32 -0
  85. package/dist/protocol/server/auth.js.map +1 -0
  86. package/dist/protocol/server/bodyCache.d.ts +28 -0
  87. package/dist/protocol/server/bodyCache.d.ts.map +1 -0
  88. package/dist/protocol/server/bodyCache.js +75 -0
  89. package/dist/protocol/server/bodyCache.js.map +1 -0
  90. package/dist/protocol/server/content.d.ts +44 -0
  91. package/dist/protocol/server/content.d.ts.map +1 -0
  92. package/dist/protocol/server/content.js +132 -0
  93. package/dist/protocol/server/content.js.map +1 -0
  94. package/dist/protocol/server/core.d.ts +63 -0
  95. package/dist/protocol/server/core.d.ts.map +1 -0
  96. package/dist/protocol/server/core.js +77 -0
  97. package/dist/protocol/server/core.js.map +1 -0
  98. package/dist/protocol/server/handler.d.ts +5 -0
  99. package/dist/protocol/server/handler.d.ts.map +1 -0
  100. package/dist/protocol/server/handler.js +70 -0
  101. package/dist/protocol/server/handler.js.map +1 -0
  102. package/dist/protocol/server/http.d.ts +24 -0
  103. package/dist/protocol/server/http.d.ts.map +1 -0
  104. package/dist/protocol/server/http.js +133 -0
  105. package/dist/protocol/server/http.js.map +1 -0
  106. package/dist/protocol/server/index.d.ts +11 -0
  107. package/dist/protocol/server/index.d.ts.map +1 -0
  108. package/dist/protocol/server/index.js +9 -0
  109. package/dist/protocol/server/index.js.map +1 -0
  110. package/dist/protocol/server/methods/apply.d.ts +4 -0
  111. package/dist/protocol/server/methods/apply.d.ts.map +1 -0
  112. package/dist/protocol/server/methods/apply.js +275 -0
  113. package/dist/protocol/server/methods/apply.js.map +1 -0
  114. package/dist/protocol/server/methods/read.d.ts +14 -0
  115. package/dist/protocol/server/methods/read.d.ts.map +1 -0
  116. package/dist/protocol/server/methods/read.js +132 -0
  117. package/dist/protocol/server/methods/read.js.map +1 -0
  118. package/dist/protocol/server/rpc.d.ts +7 -0
  119. package/dist/protocol/server/rpc.d.ts.map +1 -0
  120. package/dist/protocol/server/rpc.js +115 -0
  121. package/dist/protocol/server/rpc.js.map +1 -0
  122. package/dist/protocol/storage/fs/hash.d.ts +8 -0
  123. package/dist/protocol/storage/fs/hash.d.ts.map +1 -0
  124. package/dist/protocol/storage/fs/hash.js +20 -0
  125. package/dist/protocol/storage/fs/hash.js.map +1 -0
  126. package/dist/protocol/storage/fs/index.d.ts +30 -0
  127. package/dist/protocol/storage/fs/index.d.ts.map +1 -0
  128. package/dist/protocol/storage/fs/index.js +301 -0
  129. package/dist/protocol/storage/fs/index.js.map +1 -0
  130. package/dist/protocol/storage/fs/lock.d.ts +8 -0
  131. package/dist/protocol/storage/fs/lock.d.ts.map +1 -0
  132. package/dist/protocol/storage/fs/lock.js +61 -0
  133. package/dist/protocol/storage/fs/lock.js.map +1 -0
  134. package/dist/protocol/storage/fs/transaction.d.ts +19 -0
  135. package/dist/protocol/storage/fs/transaction.d.ts.map +1 -0
  136. package/dist/protocol/storage/fs/transaction.js +174 -0
  137. package/dist/protocol/storage/fs/transaction.js.map +1 -0
  138. package/dist/protocol/storage/fs/unsupported.d.ts +10 -0
  139. package/dist/protocol/storage/fs/unsupported.d.ts.map +1 -0
  140. package/dist/protocol/storage/fs/unsupported.js +4 -0
  141. package/dist/protocol/storage/fs/unsupported.js.map +1 -0
  142. package/dist/protocol/storage/memory.d.ts +40 -0
  143. package/dist/protocol/storage/memory.d.ts.map +1 -0
  144. package/dist/protocol/storage/memory.js +179 -0
  145. package/dist/protocol/storage/memory.js.map +1 -0
  146. package/dist/protocol/storage.d.ts +178 -0
  147. package/dist/protocol/storage.d.ts.map +1 -0
  148. package/dist/protocol/storage.js +29 -0
  149. package/dist/protocol/storage.js.map +1 -0
  150. package/dist/protocol/types.d.ts +194 -0
  151. package/dist/protocol/types.d.ts.map +1 -0
  152. package/dist/protocol/types.js +31 -0
  153. package/dist/protocol/types.js.map +1 -0
  154. package/dist/v8/analytics.d.ts +31 -0
  155. package/dist/v8/analytics.d.ts.map +1 -0
  156. package/dist/v8/analytics.js +46 -0
  157. package/dist/v8/analytics.js.map +1 -0
  158. package/dist/v8/background.d.ts +26 -0
  159. package/dist/v8/background.d.ts.map +1 -0
  160. package/dist/v8/background.js +95 -0
  161. package/dist/v8/background.js.map +1 -0
  162. package/dist/v8/builtins/data.d.ts +15 -0
  163. package/dist/v8/builtins/data.d.ts.map +1 -0
  164. package/dist/v8/builtins/data.js +18 -0
  165. package/dist/v8/builtins/data.js.map +1 -0
  166. package/dist/v8/builtins/index.d.ts +9 -0
  167. package/dist/v8/builtins/index.d.ts.map +1 -0
  168. package/dist/v8/builtins/index.js +24 -0
  169. package/dist/v8/builtins/index.js.map +1 -0
  170. package/dist/v8/builtins/lazy.d.ts +17 -0
  171. package/dist/v8/builtins/lazy.d.ts.map +1 -0
  172. package/dist/v8/builtins/lazy.js +13 -0
  173. package/dist/v8/builtins/lazy.js.map +1 -0
  174. package/dist/v8/builtins/legacy.d.ts +41 -0
  175. package/dist/v8/builtins/legacy.d.ts.map +1 -0
  176. package/dist/v8/builtins/legacy.js +62 -0
  177. package/dist/v8/builtins/legacy.js.map +1 -0
  178. package/dist/v8/builtins/matchers.d.ts +19 -0
  179. package/dist/v8/builtins/matchers.d.ts.map +1 -0
  180. package/dist/v8/builtins/matchers.js +24 -0
  181. package/dist/v8/builtins/matchers.js.map +1 -0
  182. package/dist/v8/builtins/multivariate.d.ts +15 -0
  183. package/dist/v8/builtins/multivariate.d.ts.map +1 -0
  184. package/dist/v8/builtins/multivariate.js +18 -0
  185. package/dist/v8/builtins/multivariate.js.map +1 -0
  186. package/dist/v8/builtins/secret.d.ts +7 -0
  187. package/dist/v8/builtins/secret.d.ts.map +1 -0
  188. package/dist/v8/builtins/secret.js +68 -0
  189. package/dist/v8/builtins/secret.js.map +1 -0
  190. package/dist/v8/canonical.d.ts +42 -0
  191. package/dist/v8/canonical.d.ts.map +1 -0
  192. package/dist/v8/canonical.js +111 -0
  193. package/dist/v8/canonical.js.map +1 -0
  194. package/dist/v8/ciphertext.d.ts +58 -0
  195. package/dist/v8/ciphertext.d.ts.map +1 -0
  196. package/dist/v8/ciphertext.js +134 -0
  197. package/dist/v8/ciphertext.js.map +1 -0
  198. package/dist/v8/cli/builtins.d.ts +11 -0
  199. package/dist/v8/cli/builtins.d.ts.map +1 -0
  200. package/dist/v8/cli/builtins.js +18 -0
  201. package/dist/v8/cli/builtins.js.map +1 -0
  202. package/dist/v8/cli/check/index.d.ts +41 -0
  203. package/dist/v8/cli/check/index.d.ts.map +1 -0
  204. package/dist/v8/cli/check/index.js +713 -0
  205. package/dist/v8/cli/check/index.js.map +1 -0
  206. package/dist/v8/cli/check/messages.d.ts +24 -0
  207. package/dist/v8/cli/check/messages.d.ts.map +1 -0
  208. package/dist/v8/cli/check/messages.js +150 -0
  209. package/dist/v8/cli/check/messages.js.map +1 -0
  210. package/dist/v8/cli/content.d.ts +60 -0
  211. package/dist/v8/cli/content.d.ts.map +1 -0
  212. package/dist/v8/cli/content.js +231 -0
  213. package/dist/v8/cli/content.js.map +1 -0
  214. package/dist/v8/cli/index.d.ts +18 -0
  215. package/dist/v8/cli/index.d.ts.map +1 -0
  216. package/dist/v8/cli/index.js +18 -0
  217. package/dist/v8/cli/index.js.map +1 -0
  218. package/dist/v8/cli/log.d.ts +9 -0
  219. package/dist/v8/cli/log.d.ts.map +1 -0
  220. package/dist/v8/cli/log.js +11 -0
  221. package/dist/v8/cli/log.js.map +1 -0
  222. package/dist/v8/cli/main.d.ts +2 -0
  223. package/dist/v8/cli/main.d.ts.map +1 -0
  224. package/dist/v8/cli/main.js +9 -0
  225. package/dist/v8/cli/main.js.map +1 -0
  226. package/dist/v8/cli/root.d.ts +28 -0
  227. package/dist/v8/cli/root.d.ts.map +1 -0
  228. package/dist/v8/cli/root.js +64 -0
  229. package/dist/v8/cli/root.js.map +1 -0
  230. package/dist/v8/cli/run.d.ts +13 -0
  231. package/dist/v8/cli/run.d.ts.map +1 -0
  232. package/dist/v8/cli/run.js +210 -0
  233. package/dist/v8/cli/run.js.map +1 -0
  234. package/dist/v8/cli/schema/builtinSchemas.d.ts +22 -0
  235. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -0
  236. package/dist/v8/cli/schema/builtinSchemas.js +213 -0
  237. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -0
  238. package/dist/v8/cli/schema/generate.d.ts +50 -0
  239. package/dist/v8/cli/schema/generate.d.ts.map +1 -0
  240. package/dist/v8/cli/schema/generate.js +415 -0
  241. package/dist/v8/cli/schema/generate.js.map +1 -0
  242. package/dist/v8/cli/schema/index.d.ts +21 -0
  243. package/dist/v8/cli/schema/index.d.ts.map +1 -0
  244. package/dist/v8/cli/schema/index.js +51 -0
  245. package/dist/v8/cli/schema/index.js.map +1 -0
  246. package/dist/v8/cli/schema/tsProgram.d.ts +120 -0
  247. package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -0
  248. package/dist/v8/cli/schema/tsProgram.js +418 -0
  249. package/dist/v8/cli/schema/tsProgram.js.map +1 -0
  250. package/dist/v8/cli/schema/typeToSchema.d.ts +81 -0
  251. package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -0
  252. package/dist/v8/cli/schema/typeToSchema.js +683 -0
  253. package/dist/v8/cli/schema/typeToSchema.js.map +1 -0
  254. package/dist/v8/cli/serve/server.d.ts +31 -0
  255. package/dist/v8/cli/serve/server.d.ts.map +1 -0
  256. package/dist/v8/cli/serve/server.js +247 -0
  257. package/dist/v8/cli/serve/server.js.map +1 -0
  258. package/dist/v8/cli/watch.d.ts +20 -0
  259. package/dist/v8/cli/watch.d.ts.map +1 -0
  260. package/dist/v8/cli/watch.js +79 -0
  261. package/dist/v8/cli/watch.js.map +1 -0
  262. package/dist/v8/client.d.ts +20 -0
  263. package/dist/v8/client.d.ts.map +1 -0
  264. package/dist/v8/client.js +115 -0
  265. package/dist/v8/client.js.map +1 -0
  266. package/dist/v8/cms.d.ts +9 -0
  267. package/dist/v8/cms.d.ts.map +1 -0
  268. package/dist/v8/cms.js +206 -0
  269. package/dist/v8/cms.js.map +1 -0
  270. package/dist/v8/content.d.ts +35 -0
  271. package/dist/v8/content.d.ts.map +1 -0
  272. package/dist/v8/content.js +183 -0
  273. package/dist/v8/content.js.map +1 -0
  274. package/dist/v8/draft.d.ts +44 -0
  275. package/dist/v8/draft.d.ts.map +1 -0
  276. package/dist/v8/draft.js +133 -0
  277. package/dist/v8/draft.js.map +1 -0
  278. package/dist/v8/errors.d.ts +21 -0
  279. package/dist/v8/errors.d.ts.map +1 -0
  280. package/dist/v8/errors.js +39 -0
  281. package/dist/v8/errors.js.map +1 -0
  282. package/dist/v8/fetch.d.ts +26 -0
  283. package/dist/v8/fetch.d.ts.map +1 -0
  284. package/dist/v8/fetch.js +98 -0
  285. package/dist/v8/fetch.js.map +1 -0
  286. package/dist/v8/identity.d.ts +19 -0
  287. package/dist/v8/identity.d.ts.map +1 -0
  288. package/dist/v8/identity.js +54 -0
  289. package/dist/v8/identity.js.map +1 -0
  290. package/dist/v8/index.d.ts +11 -0
  291. package/dist/v8/index.d.ts.map +1 -0
  292. package/dist/v8/index.js +10 -0
  293. package/dist/v8/index.js.map +1 -0
  294. package/dist/v8/json.d.ts +19 -0
  295. package/dist/v8/json.d.ts.map +1 -0
  296. package/dist/v8/json.js +65 -0
  297. package/dist/v8/json.js.map +1 -0
  298. package/dist/v8/matchRoute.d.ts +30 -0
  299. package/dist/v8/matchRoute.d.ts.map +1 -0
  300. package/dist/v8/matchRoute.js +175 -0
  301. package/dist/v8/matchRoute.js.map +1 -0
  302. package/dist/v8/remoteLoader.d.ts +16 -0
  303. package/dist/v8/remoteLoader.d.ts.map +1 -0
  304. package/dist/v8/remoteLoader.js +243 -0
  305. package/dist/v8/remoteLoader.js.map +1 -0
  306. package/dist/v8/resolver.d.ts +34 -0
  307. package/dist/v8/resolver.d.ts.map +1 -0
  308. package/dist/v8/resolver.js +219 -0
  309. package/dist/v8/resolver.js.map +1 -0
  310. package/dist/v8/secrets.d.ts +9 -0
  311. package/dist/v8/secrets.d.ts.map +1 -0
  312. package/dist/v8/secrets.js +14 -0
  313. package/dist/v8/secrets.js.map +1 -0
  314. package/dist/v8/telemetry.d.ts +61 -0
  315. package/dist/v8/telemetry.d.ts.map +1 -0
  316. package/dist/v8/telemetry.js +460 -0
  317. package/dist/v8/telemetry.js.map +1 -0
  318. package/dist/v8/types.d.ts +214 -0
  319. package/dist/v8/types.d.ts.map +1 -0
  320. package/dist/v8/types.js +2 -0
  321. package/dist/v8/types.js.map +1 -0
  322. package/package.json +65 -105
  323. package/src/index.ts +3 -13
  324. package/src/protocol/canonical.ts +1 -1
  325. package/src/protocol/ciphertext.ts +1 -1
  326. package/src/protocol/client.ts +2 -2
  327. package/src/protocol/conformance/cases/assets.ts +3 -3
  328. package/src/protocol/conformance/cases/guards.ts +4 -4
  329. package/src/protocol/conformance/cases/reads.ts +4 -4
  330. package/src/protocol/conformance/cases/types.ts +1 -1
  331. package/src/protocol/conformance/cases/wire.ts +4 -4
  332. package/src/protocol/conformance/cases/writes.ts +4 -4
  333. package/src/protocol/conformance/context.ts +4 -4
  334. package/src/protocol/conformance/index.ts +10 -10
  335. package/src/protocol/index.ts +6 -6
  336. package/src/protocol/params.ts +2 -2
  337. package/src/protocol/secrets.ts +3 -3
  338. package/src/protocol/server/assets.ts +6 -6
  339. package/src/protocol/server/auth.ts +1 -1
  340. package/src/protocol/server/content.ts +5 -5
  341. package/src/protocol/server/core.ts +12 -6
  342. package/src/protocol/server/handler.ts +6 -6
  343. package/src/protocol/server/http.ts +1 -1
  344. package/src/protocol/server/index.ts +3 -3
  345. package/src/protocol/server/methods/apply.ts +9 -9
  346. package/src/protocol/server/methods/read.ts +5 -5
  347. package/src/protocol/server/rpc.ts +6 -6
  348. package/src/protocol/storage/fs/index.ts +7 -7
  349. package/src/protocol/storage/fs/lock.ts +1 -1
  350. package/src/protocol/storage/fs/unsupported.ts +2 -2
  351. package/src/protocol/storage/memory.ts +5 -5
  352. package/src/protocol/storage.ts +1 -1
  353. package/src/v8/analytics.ts +2 -2
  354. package/src/v8/background.ts +3 -3
  355. package/src/v8/builtins/data.ts +1 -1
  356. package/src/v8/builtins/index.ts +6 -6
  357. package/src/v8/builtins/lazy.ts +1 -1
  358. package/src/v8/builtins/legacy.ts +2 -2
  359. package/src/v8/builtins/multivariate.ts +1 -1
  360. package/src/v8/builtins/secret.ts +2 -2
  361. package/src/v8/cli/builtins.ts +2 -2
  362. package/src/v8/cli/check/index.ts +11 -11
  363. package/src/v8/cli/content.ts +6 -6
  364. package/src/v8/cli/index.ts +8 -8
  365. package/src/v8/cli/main.ts +1 -1
  366. package/src/v8/cli/run.ts +7 -7
  367. package/src/v8/cli/schema/builtinSchemas.ts +1 -1
  368. package/src/v8/cli/schema/generate.ts +6 -6
  369. package/src/v8/cli/schema/index.ts +4 -4
  370. package/src/v8/cli/schema/tsProgram.ts +1 -1
  371. package/src/v8/cli/schema/typeToSchema.ts +24 -2
  372. package/src/v8/cli/serve/server.ts +9 -9
  373. package/src/v8/client.ts +5 -5
  374. package/src/v8/cms.ts +9 -9
  375. package/src/v8/content.ts +4 -4
  376. package/src/v8/draft.ts +1 -1
  377. package/src/v8/errors.ts +1 -1
  378. package/src/v8/fetch.ts +9 -28
  379. package/src/v8/identity.ts +1 -1
  380. package/src/v8/index.ts +5 -5
  381. package/src/v8/matchRoute.ts +1 -1
  382. package/src/v8/remoteLoader.ts +7 -7
  383. package/src/v8/resolver.ts +6 -6
  384. package/src/v8/secrets.ts +1 -1
  385. package/src/v8/telemetry.ts +6 -6
  386. package/src/cms/applySectionConventions.ts +0 -148
  387. package/src/cms/blockSource.ts +0 -228
  388. package/src/cms/client.ts +0 -85
  389. package/src/cms/deferredTrigger.ts +0 -58
  390. package/src/cms/draftSource.ts +0 -476
  391. package/src/cms/index.ts +0 -180
  392. package/src/cms/loadDecofileDirectory.ts +0 -89
  393. package/src/cms/loader.ts +0 -563
  394. package/src/cms/registry.ts +0 -264
  395. package/src/cms/renderJson.ts +0 -179
  396. package/src/cms/resolve.ts +0 -2583
  397. package/src/cms/schema.ts +0 -1219
  398. package/src/cms/sectionLoaderContext.ts +0 -113
  399. package/src/cms/sectionLoaders.ts +0 -686
  400. package/src/cms/sectionMixins.ts +0 -153
  401. package/src/flags/audience.ts +0 -56
  402. package/src/flags/everyone.ts +0 -29
  403. package/src/flags/flag.ts +0 -15
  404. package/src/flags/multivariate/image.ts +0 -11
  405. package/src/flags/multivariate/message.ts +0 -11
  406. package/src/flags/multivariate/page.ts +0 -16
  407. package/src/flags/multivariate/section.ts +0 -16
  408. package/src/flags/multivariate.ts +0 -1
  409. package/src/flags/types.ts +0 -59
  410. package/src/flags/utils/multivariate.ts +0 -20
  411. package/src/hooks/Image.tsx +0 -314
  412. package/src/hooks/JsonLd.tsx +0 -353
  413. package/src/hooks/LazySection.tsx +0 -121
  414. package/src/hooks/LiveControls.tsx +0 -144
  415. package/src/hooks/Picture.tsx +0 -127
  416. package/src/hooks/RenderSection.tsx +0 -91
  417. package/src/hooks/SectionErrorFallback.tsx +0 -97
  418. package/src/hooks/Stats.tsx +0 -134
  419. package/src/hooks/index.ts +0 -35
  420. package/src/hooks/useLoadMore.ts +0 -100
  421. package/src/matchers/builtins.ts +0 -459
  422. package/src/matchers/countryNames.ts +0 -104
  423. package/src/matchers/override.ts +0 -136
  424. package/src/matchers/posthog.ts +0 -154
  425. package/src/middleware/decoState.ts +0 -55
  426. package/src/middleware/healthMetrics.ts +0 -133
  427. package/src/middleware/hydrationContext.ts +0 -79
  428. package/src/middleware/index.ts +0 -88
  429. package/src/middleware/liveness.ts +0 -21
  430. package/src/middleware/observability.ts +0 -800
  431. package/src/middleware/validateSection.ts +0 -100
  432. package/src/preview/DraftPreviewBadge.tsx +0 -306
  433. package/src/preview/decoMark.ts +0 -11
  434. package/src/preview/index.ts +0 -8
  435. package/src/sdk/abTesting.ts +0 -556
  436. package/src/sdk/analytics.ts +0 -147
  437. package/src/sdk/cacheHeaders.ts +0 -633
  438. package/src/sdk/cacheStorage.ts +0 -287
  439. package/src/sdk/cachedLoader.ts +0 -556
  440. package/src/sdk/clx.ts +0 -5
  441. package/src/sdk/cn.ts +0 -28
  442. package/src/sdk/composite.ts +0 -114
  443. package/src/sdk/cookie.ts +0 -129
  444. package/src/sdk/crypto.ts +0 -199
  445. package/src/sdk/csp.ts +0 -59
  446. package/src/sdk/deepOmit.ts +0 -52
  447. package/src/sdk/detectDevice.ts +0 -45
  448. package/src/sdk/djb2.ts +0 -20
  449. package/src/sdk/encoding.ts +0 -44
  450. package/src/sdk/env.ts +0 -54
  451. package/src/sdk/experiments.ts +0 -314
  452. package/src/sdk/fetchCache.ts +0 -269
  453. package/src/sdk/fetchTimeout.ts +0 -58
  454. package/src/sdk/flags.ts +0 -138
  455. package/src/sdk/http.ts +0 -124
  456. package/src/sdk/index.ts +0 -97
  457. package/src/sdk/inflightTimeout.ts +0 -53
  458. package/src/sdk/instrumentedFetch.ts +0 -362
  459. package/src/sdk/invoke.ts +0 -298
  460. package/src/sdk/logger.ts +0 -304
  461. package/src/sdk/mergeCacheControl.ts +0 -150
  462. package/src/sdk/nonce.ts +0 -46
  463. package/src/sdk/normalizeUrls.ts +0 -91
  464. package/src/sdk/observability.ts +0 -116
  465. package/src/sdk/otel.ts +0 -1118
  466. package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
  467. package/src/sdk/otelAdapters.ts +0 -144
  468. package/src/sdk/otelHttpLog.ts +0 -419
  469. package/src/sdk/otelHttpMeter.ts +0 -532
  470. package/src/sdk/otelHttpTracer.ts +0 -543
  471. package/src/sdk/redirects.ts +0 -336
  472. package/src/sdk/requestContext.ts +0 -281
  473. package/src/sdk/requestContextStorage.browser.ts +0 -43
  474. package/src/sdk/requestContextStorage.ts +0 -35
  475. package/src/sdk/responseCache.ts +0 -82
  476. package/src/sdk/retry.ts +0 -45
  477. package/src/sdk/serverTimings.ts +0 -68
  478. package/src/sdk/signal.ts +0 -42
  479. package/src/sdk/sitemap.ts +0 -160
  480. package/src/sdk/urlRedaction.ts +0 -82
  481. package/src/sdk/urlUtils.ts +0 -183
  482. package/src/sdk/useDevice.ts +0 -89
  483. package/src/sdk/useDeviceContext.tsx +0 -108
  484. package/src/sdk/useId.ts +0 -7
  485. package/src/sdk/useScript.ts +0 -210
  486. package/src/sdk/useSuggestions.ts +0 -188
  487. package/src/sdk/wrapCaughtErrors.ts +0 -107
  488. package/src/setup.ts +0 -120
  489. package/src/types/index.ts +0 -53
  490. package/src/types/widgets.ts +0 -14
@@ -1,336 +0,0 @@
1
- /**
2
- * CMS-managed redirect system.
3
- *
4
- * Loads redirect definitions from .deco/blocks/ and provides
5
- * fast path matching for use in TanStack Start middleware.
6
- *
7
- * Supports:
8
- * - Exact path matches (/old-page -> /new-page)
9
- * - Glob patterns (/old/* -> /new/*)
10
- * - Permanent (301) and temporary (302) redirects
11
- * - CSV import for bulk redirects
12
- *
13
- * @example
14
- * ```ts
15
- * // In TanStack Start middleware
16
- * import { loadRedirects, matchRedirect } from "@decocms/start/sdk/redirects";
17
- * import { loadBlocks } from "@decocms/start/cms";
18
- *
19
- * const redirects = loadRedirects(loadBlocks());
20
- *
21
- * const middleware = createMiddleware().server(async ({ next, request }) => {
22
- * const url = new URL(request.url);
23
- * const redirect = matchRedirect(url.pathname, redirects);
24
- * if (redirect) {
25
- * return new Response(null, {
26
- * status: redirect.status,
27
- * headers: { Location: redirect.to },
28
- * });
29
- * }
30
- * return next();
31
- * });
32
- * ```
33
- */
34
-
35
- // -------------------------------------------------------------------------
36
- // Types
37
- // -------------------------------------------------------------------------
38
-
39
- export interface Redirect {
40
- from: string;
41
- to: string;
42
- status: 301 | 302;
43
- }
44
-
45
- export interface RedirectMap {
46
- /** Exact match redirects for O(1) lookup. */
47
- exact: Map<string, Redirect>;
48
- /** Glob/prefix redirects checked sequentially (few in practice). */
49
- patterns: Array<{ prefix: string; redirect: Redirect }>;
50
- }
51
-
52
- // -------------------------------------------------------------------------
53
- // Loading from CMS blocks
54
- // -------------------------------------------------------------------------
55
-
56
- interface BlockRedirectEntry {
57
- from: string;
58
- to: string;
59
- type?: "permanent" | "temporary";
60
- }
61
-
62
- const REDIRECT_RESOLVE_TYPES = new Set([
63
- "website/loaders/redirect.ts",
64
- "website/loaders/redirects.ts",
65
- "website/loaders/redirectsFromCsv.ts",
66
- "deco-sites/std/loaders/x/redirects.ts",
67
- ]);
68
-
69
- /**
70
- * Register additional __resolveType strings that should be treated as redirect blocks.
71
- * Useful for custom redirect loaders.
72
- */
73
- export function registerRedirectResolveType(resolveType: string): void {
74
- REDIRECT_RESOLVE_TYPES.add(resolveType);
75
- }
76
-
77
- /**
78
- * Load all redirect definitions from CMS blocks.
79
- *
80
- * Scans the blocks for known redirect resolve types and builds
81
- * a fast-lookup redirect map.
82
- */
83
- export function loadRedirects(blocks: Record<string, unknown>): RedirectMap {
84
- const exact = new Map<string, Redirect>();
85
- const patterns: Array<{ prefix: string; redirect: Redirect }> = [];
86
-
87
- for (const [_key, block] of Object.entries(blocks)) {
88
- if (!block || typeof block !== "object") continue;
89
- const obj = block as Record<string, unknown>;
90
- const resolveType = obj.__resolveType as string | undefined;
91
-
92
- if (!resolveType || !REDIRECT_RESOLVE_TYPES.has(resolveType)) continue;
93
-
94
- const entries = (obj.redirects ?? obj.redirect) as
95
- | BlockRedirectEntry[]
96
- | BlockRedirectEntry
97
- | undefined;
98
-
99
- if (!entries) continue;
100
-
101
- const list = Array.isArray(entries) ? entries : [entries];
102
-
103
- for (const entry of list) {
104
- if (!entry.from || !entry.to) continue;
105
-
106
- const redirect: Redirect = {
107
- from: normalizePath(entry.from),
108
- to: entry.to,
109
- status: entry.type === "permanent" ? 301 : 302,
110
- };
111
-
112
- if (redirect.from.includes("*")) {
113
- const prefix = redirect.from.replace(/\*+$/, "");
114
- patterns.push({ prefix, redirect });
115
- } else {
116
- exact.set(redirect.from, redirect);
117
- }
118
- }
119
- }
120
-
121
- return { exact, patterns };
122
- }
123
-
124
- // -------------------------------------------------------------------------
125
- // CSV import
126
- // -------------------------------------------------------------------------
127
-
128
- /**
129
- * Parse a CSV string into redirect entries.
130
- *
131
- * Expected format: `from,to[,type]` (one per line).
132
- * Lines starting with # are comments. Empty lines are skipped.
133
- * Type is "permanent" (301) or "temporary" (302, default).
134
- */
135
- export function parseRedirectsCsv(csv: string): Redirect[] {
136
- const redirects: Redirect[] = [];
137
- const lines = csv.split("\n");
138
-
139
- for (const raw of lines) {
140
- const line = raw.trim();
141
- if (!line || line.startsWith("#")) continue;
142
-
143
- const parts = line.split(",").map((p) => p.trim());
144
- if (parts.length < 2) continue;
145
-
146
- const [from, to, type] = parts;
147
- if (!from || !to) continue;
148
- // Skip a header row (`from,to[,type]`). Robust for CSVs with or without a
149
- // header, and for a header repeated when multiple files are concatenated.
150
- if (from.toLowerCase() === "from" && to.toLowerCase() === "to") continue;
151
-
152
- redirects.push({
153
- from: normalizePath(from),
154
- to,
155
- status: type === "permanent" || type === "301" ? 301 : 302,
156
- });
157
- }
158
-
159
- return redirects;
160
- }
161
-
162
- /**
163
- * Add parsed redirects to an existing redirect map.
164
- */
165
- export function addRedirects(map: RedirectMap, redirects: Redirect[]): void {
166
- for (const redirect of redirects) {
167
- if (redirect.from.includes("*")) {
168
- const prefix = redirect.from.replace(/\*+$/, "");
169
- map.patterns.push({ prefix, redirect });
170
- } else {
171
- map.exact.set(redirect.from, redirect);
172
- }
173
- }
174
- }
175
-
176
- // -------------------------------------------------------------------------
177
- // Matching
178
- // -------------------------------------------------------------------------
179
-
180
- /**
181
- * Find a redirect matching the given path.
182
- *
183
- * Checks exact matches first (O(1)), then glob patterns (O(n), but
184
- * typically few patterns exist).
185
- */
186
- export function matchRedirect(pathname: string, map: RedirectMap): Redirect | null {
187
- return matchExactRedirect(pathname, map) ?? matchPatternRedirect(pathname, map);
188
- }
189
-
190
- /**
191
- * Exact half of `matchRedirect`. Split out because the KV-keyed path has to
192
- * interleave a third source between the two halves: in-memory exact, then the
193
- * `redirect:<id>:<path>` KV lookup, then patterns. Collapsing that to
194
- * "matchRedirect, then KV" would let a glob win over an exact rule, inverting
195
- * the precedence every other path has.
196
- */
197
- export function matchExactRedirect(pathname: string, map: RedirectMap): Redirect | null {
198
- return map.exact.get(normalizePath(pathname)) ?? null;
199
- }
200
-
201
- /** Pattern half of `matchRedirect` — ordered prefix scan, `*` suffix carried over. */
202
- export function matchPatternRedirect(pathname: string, map: RedirectMap): Redirect | null {
203
- const normalized = normalizePath(pathname);
204
- for (const { prefix, redirect } of map.patterns) {
205
- if (normalized.startsWith(prefix)) {
206
- const suffix = normalized.slice(prefix.length);
207
- const to = redirect.to.includes("*") ? redirect.to.replace("*", suffix) : redirect.to;
208
- return { ...redirect, to };
209
- }
210
- }
211
- return null;
212
- }
213
-
214
- // -------------------------------------------------------------------------
215
- // Splitting exact rules out of the decofile (KV-keyed redirects)
216
- // -------------------------------------------------------------------------
217
-
218
- /** One exact rule, ready to be written to its own KV key. */
219
- export interface ExactRedirect {
220
- /** Normalized path — the KV key suffix. */
221
- path: string;
222
- to: string;
223
- status: 301 | 302;
224
- }
225
-
226
- export interface SplitRedirectsResult {
227
- /** The blocks map with every EXACT rule removed. Glob rules stay (they can't
228
- * be addressed by key), and a redirect block left with no entries at all is
229
- * dropped entirely rather than left as an empty husk. */
230
- blocks: Record<string, unknown>;
231
- /** The extracted exact rules, deduped by path (last wins, matching
232
- * `loadRedirects`, which is last-write-wins over insertion order). */
233
- exact: ExactRedirect[];
234
- }
235
-
236
- /**
237
- * Split a decofile into "blocks without exact redirects" + "the exact rules".
238
- *
239
- * A bulk-migration site can carry tens of thousands of rules. Left inside the
240
- * decofile they sit in every isolate twice — the parsed snapshot graph and the
241
- * `RedirectMap` built from it — for data that is consulted at most once per
242
- * request and usually matches nothing. Moved to one KV key each, the list is
243
- * never loaded.
244
- *
245
- * Read-only over `blocks`: the returned map shares every untouched value and
246
- * only clones the redirect blocks it had to rewrite.
247
- */
248
- const MAX_KV_PATH_BYTES = 400;
249
- const utf8 = new TextEncoder();
250
-
251
- export function splitExactRedirects(blocks: Record<string, unknown>): SplitRedirectsResult {
252
- const exact = new Map<string, ExactRedirect>();
253
- const out: Record<string, unknown> = {};
254
-
255
- for (const [key, block] of Object.entries(blocks)) {
256
- const obj = block && typeof block === "object" ? (block as Record<string, unknown>) : null;
257
- const resolveType = obj?.__resolveType as string | undefined;
258
- if (!obj || !resolveType || !REDIRECT_RESOLVE_TYPES.has(resolveType)) {
259
- out[key] = block;
260
- continue;
261
- }
262
-
263
- const raw = (obj.redirects ?? obj.redirect) as
264
- | BlockRedirectEntry[]
265
- | BlockRedirectEntry
266
- | undefined;
267
- if (!raw) {
268
- out[key] = block;
269
- continue;
270
- }
271
-
272
- const kept: BlockRedirectEntry[] = [];
273
- for (const entry of Array.isArray(raw) ? raw : [raw]) {
274
- if (!entry?.from || !entry.to) continue;
275
- const from = normalizePath(entry.from);
276
- // Globs must be scanned in order against the request path, so they can
277
- // never be a key lookup — they stay in the decofile.
278
- // Paths too long for a KV key (512 bytes, minus `redirect:<id>:`) stay
279
- // in memory too — loadRedirects still serves them from the exact map.
280
- if (from.includes("*") || utf8.encode(from).length > MAX_KV_PATH_BYTES) {
281
- kept.push(entry);
282
- continue;
283
- }
284
- exact.set(from, {
285
- path: from,
286
- to: entry.to,
287
- status: entry.type === "permanent" ? 301 : 302,
288
- });
289
- }
290
-
291
- // Nothing left to scan ⇒ drop the block rather than ship an empty husk.
292
- if (kept.length === 0) continue;
293
- // Rebuild without `redirect` — a block may have carried the singular form,
294
- // and leaving it would reintroduce the rule we just extracted.
295
- const { redirect: _dropped, ...rest } = obj;
296
- out[key] = { ...rest, redirects: kept };
297
- }
298
-
299
- return { blocks: out, exact: [...exact.values()] };
300
- }
301
-
302
- // -------------------------------------------------------------------------
303
- // Helpers
304
- // -------------------------------------------------------------------------
305
-
306
- /**
307
- * Canonical redirect-path form: origin stripped, leading slash forced, trailing
308
- * slash dropped, lower-cased.
309
- *
310
- * Exported because it is the KV key contract for `redirect:<id>:<path>` — the
311
- * sync script that WRITES the keys and the worker that READS them must agree
312
- * byte for byte, or a rule is stored under a key nothing ever asks for. Never
313
- * inline a different normalization on either side.
314
- */
315
- export function normalizePath(path: string): string {
316
- let p = path.trim();
317
-
318
- // If the "from" is a full URL, extract just the pathname
319
- if (p.startsWith("http://") || p.startsWith("https://")) {
320
- try {
321
- p = new URL(p).pathname;
322
- } catch {
323
- // malformed URL, keep as-is and try the prefix fallback
324
- const slashIdx = p.indexOf("/", p.indexOf("//") + 2);
325
- p = slashIdx >= 0 ? p.slice(slashIdx) : p;
326
- }
327
- }
328
-
329
- if (!p.startsWith("/")) {
330
- p = "/" + p;
331
- }
332
- if (p.length > 1 && p.endsWith("/")) {
333
- p = p.slice(0, -1);
334
- }
335
- return p.toLowerCase();
336
- }
@@ -1,281 +0,0 @@
1
- /**
2
- * Per-request context via AsyncLocalStorage.
3
- *
4
- * Binds request-scoped state (request, abort signal, device info, flags)
5
- * that any code in the call stack can access without prop drilling.
6
- *
7
- * Requires `nodejs_compat` in wrangler.jsonc (already enabled).
8
- *
9
- * **Design decisions:**
10
- * - We do NOT monkey-patch global `fetch`. Instead, `RequestContext.fetch`
11
- * provides a fetch that auto-injects the request's AbortSignal.
12
- * - The context is optional -- code that doesn't need it just doesn't call it.
13
- * Commerce loaders receive it explicitly via the updated `CommerceLoader` sig.
14
- *
15
- * @example
16
- * ```ts
17
- * // In TanStack Start middleware:
18
- * import { RequestContext } from "@decocms/start/sdk/requestContext";
19
- *
20
- * const middleware = createMiddleware().server(async ({ next, request }) => {
21
- * return RequestContext.run(request, () => next());
22
- * });
23
- *
24
- * // Anywhere in the call stack:
25
- * const req = RequestContext.request; // the current request
26
- * const signal = RequestContext.signal; // AbortSignal
27
- * const resp = await RequestContext.fetch(url); // auto-aborts on disconnect
28
- * ```
29
- */
30
-
31
- // The `node:async_hooks`-backed storage lives in a sibling module so that
32
- // bundlers targeting the browser can swap it for a no-op stub via the
33
- // `"browser"` export condition (see `./requestContextStorage` and the
34
- // `./sdk/requestContextStorage` entry in `package.json`). We import it through
35
- // the package's own name — NOT a relative path — because export conditions are
36
- // only consulted at package-specifier boundaries; a relative `./requestContextStorage`
37
- // would always resolve straight to the Node file and drag `node:async_hooks`
38
- // into the client graph, which is exactly the `UnhandledSchemeError` we're
39
- // avoiding. Node/Vitest resolve the `default`/`node` condition → real storage;
40
- // Next.js's client webpack compiler resolves `browser` → the stub.
41
- import { storage } from "@decocms/blocks/sdk/requestContextStorage";
42
-
43
- // -------------------------------------------------------------------------
44
- // Types
45
- // -------------------------------------------------------------------------
46
-
47
- export interface RequestContextData {
48
- request: Request;
49
- signal: AbortSignal;
50
- startedAt: number;
51
- /**
52
- * Stable per-request identifier. Generated by `workerEntry.ts` from
53
- * `cf-ray` when present, falling back to `crypto.randomUUID()`. Echoed
54
- * back to the client as the `X-Request-Id` response header so:
55
- *
56
- * - The producer Worker can stamp it on every log / span / metric
57
- * attribute (`request.id`) for join queries.
58
- * - The CF tail worker reads it from the response header and stamps
59
- * the same `request.id` on tail rows — restores the join key on a
60
- * channel that has no other shared identity with direct-POST.
61
- * - Clients can include it in support requests so we can pull the
62
- * full trace + logs from one ID.
63
- *
64
- * See `MIGRATION_TOOLING_PLAN.md` D-9 for the propagation policy.
65
- */
66
- requestId: string;
67
- /** Lazily computed device type. */
68
- _device?: "mobile" | "desktop";
69
- /** Lazily computed bot detection result. */
70
- _isBot?: boolean;
71
- /** Arbitrary bag for middleware to attach custom data. */
72
- bag: Map<string, unknown>;
73
- /**
74
- * Outgoing response headers that handlers can write to.
75
- * Invoke handlers (actions/loaders) use this to forward Set-Cookie
76
- * and other headers from upstream APIs (e.g., VTEX checkout).
77
- * The invoke HTTP handler copies these into the final Response.
78
- *
79
- * This mirrors deco-cx/deco's `ctx.response.headers` pattern where
80
- * `proxySetCookie(apiResponse.headers, ctx.response.headers)` forwards
81
- * cookies transparently.
82
- */
83
- responseHeaders: Headers;
84
- }
85
-
86
- // -------------------------------------------------------------------------
87
- // Storage
88
- // -------------------------------------------------------------------------
89
-
90
- import { isMobileUA } from "./detectDevice";
91
-
92
- const BOT_RE =
93
- /bot|crawl|spider|slurp|bingpreview|facebookexternalhit|linkedinbot|twitterbot|whatsapp|telegram|googlebot|yandex|baidu|duckduck/i;
94
-
95
- // -------------------------------------------------------------------------
96
- // Public API
97
- // -------------------------------------------------------------------------
98
-
99
- export const RequestContext = {
100
- /**
101
- * Run a function within a request context.
102
- *
103
- * Call this at the outermost middleware level. Everything inside
104
- * the callback (loaders, resolvers, utilities) can access the
105
- * context via the static getters.
106
- */
107
- run<T>(request: Request, fn: () => T): T {
108
- const controller = new AbortController();
109
-
110
- if (request.signal) {
111
- if (request.signal.aborted) {
112
- controller.abort(request.signal.reason);
113
- } else {
114
- request.signal.addEventListener("abort", () => controller.abort(request.signal.reason), {
115
- once: true,
116
- });
117
- }
118
- }
119
-
120
- // Resolve request.id with explicit precedence so the choice is
121
- // auditable from a single read:
122
- // (1) inbound `x-request-id` — caller-supplied (e.g. a load balancer
123
- // already tagged the request, or a synthetic test passed one in)
124
- // (2) `cf-ray` — Cloudflare's own per-request identifier, present
125
- // on every real Workers request and globally unique
126
- // (3) `crypto.randomUUID()` — last resort for tests and locally-run
127
- // dev without `cf-ray`
128
- const incomingReqId = request.headers.get("x-request-id");
129
- const cfRay = request.headers.get("cf-ray");
130
- const requestId =
131
- incomingReqId && incomingReqId.length > 0
132
- ? incomingReqId
133
- : cfRay && cfRay.length > 0
134
- ? cfRay
135
- : (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function"
136
- ? crypto.randomUUID()
137
- : `${Date.now()}-${Math.random().toString(16).slice(2)}`);
138
-
139
- const ctx: RequestContextData = {
140
- request,
141
- signal: controller.signal,
142
- startedAt: Date.now(),
143
- requestId,
144
- bag: new Map(),
145
- responseHeaders: new Headers(),
146
- };
147
-
148
- return storage.run(ctx, fn);
149
- },
150
-
151
- /**
152
- * Get the current request context, or null if not in a request scope.
153
- */
154
- get current(): RequestContextData | null {
155
- return storage.getStore() ?? null;
156
- },
157
-
158
- /**
159
- * Get the current Request object.
160
- * @throws if called outside a request context
161
- */
162
- get request(): Request {
163
- const ctx = storage.getStore();
164
- if (!ctx) throw new Error("RequestContext.request accessed outside a request scope");
165
- return ctx.request;
166
- },
167
-
168
- /**
169
- * Get the current AbortSignal.
170
- * Use this to cancel in-flight operations when the client disconnects.
171
- */
172
- get signal(): AbortSignal {
173
- const ctx = storage.getStore();
174
- if (!ctx) throw new Error("RequestContext.signal accessed outside a request scope");
175
- return ctx.signal;
176
- },
177
-
178
- /**
179
- * The stable per-request identifier — see `RequestContextData.requestId`
180
- * for the full propagation policy. Returns `null` when called outside a
181
- * request scope (vs throwing, because observability helpers in the
182
- * shutdown path of a Worker may pull it lazily).
183
- */
184
- get requestId(): string | null {
185
- return storage.getStore()?.requestId ?? null;
186
- },
187
-
188
- /**
189
- * Detected device type based on User-Agent.
190
- */
191
- get device(): "mobile" | "desktop" {
192
- const ctx = storage.getStore();
193
- if (!ctx) return "desktop";
194
- if (ctx._device) return ctx._device;
195
- const ua = ctx.request.headers.get("user-agent") ?? "";
196
- ctx._device = isMobileUA(ua) ? "mobile" : "desktop";
197
- return ctx._device;
198
- },
199
-
200
- /**
201
- * Whether the request appears to be from a bot/crawler.
202
- */
203
- get isBot(): boolean {
204
- const ctx = storage.getStore();
205
- if (!ctx) return false;
206
- if (ctx._isBot !== undefined) return ctx._isBot;
207
- const ua = ctx.request.headers.get("user-agent") ?? "";
208
- ctx._isBot = BOT_RE.test(ua);
209
- return ctx._isBot;
210
- },
211
-
212
- /**
213
- * Elapsed time since the request started (in milliseconds).
214
- */
215
- get elapsed(): number {
216
- const ctx = storage.getStore();
217
- if (!ctx) return 0;
218
- return Date.now() - ctx.startedAt;
219
- },
220
-
221
- /**
222
- * Fetch with automatic AbortSignal injection.
223
- *
224
- * When the client disconnects, this fetch aborts automatically.
225
- * This is NOT a global monkey-patch -- only code that explicitly
226
- * calls `RequestContext.fetch()` gets this behavior.
227
- */
228
- fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
229
- const ctx = storage.getStore();
230
- if (!ctx) return globalThis.fetch(input, init);
231
-
232
- return globalThis.fetch(input, {
233
- ...init,
234
- signal: init?.signal ?? ctx.signal,
235
- });
236
- },
237
-
238
- /**
239
- * Outgoing response headers. Handlers write here; the invoke endpoint
240
- * copies them into the HTTP Response (mirroring ctx.response.headers
241
- * from deco-cx/deco).
242
- */
243
- get responseHeaders(): Headers {
244
- const ctx = storage.getStore();
245
- if (!ctx) throw new Error("RequestContext.responseHeaders accessed outside a request scope");
246
- return ctx.responseHeaders;
247
- },
248
-
249
- /**
250
- * Get/set arbitrary values in the request bag.
251
- * Useful for middleware to pass data to loaders.
252
- */
253
- getBag<T>(key: string): T | undefined {
254
- const ctx = storage.getStore();
255
- return ctx?.bag.get(key) as T | undefined;
256
- },
257
-
258
- setBag(key: string, value: unknown): void {
259
- const ctx = storage.getStore();
260
- ctx?.bag.set(key, value);
261
- },
262
-
263
- /**
264
- * Get an app's state from the request bag.
265
- * Apps register their state via `setupApps()` which injects it
266
- * into the bag as `app:{name}:state` before each request.
267
- *
268
- * @example
269
- * ```ts
270
- * import { RequestContext } from "@decocms/start/sdk/requestContext";
271
- * import type { VtexState } from "@decocms/apps/vtex/mod";
272
- *
273
- * const vtex = RequestContext.getAppState<VtexState>("vtex");
274
- * if (vtex) console.log(vtex.config.account);
275
- * ```
276
- */
277
- getAppState<T>(appName: string): T | undefined {
278
- const ctx = storage.getStore();
279
- return ctx?.bag.get(`app:${appName}:state`) as T | undefined;
280
- },
281
- };
@@ -1,43 +0,0 @@
1
- /**
2
- * Browser-bundle stand-in for the `node:async_hooks`-backed request storage in
3
- * `./requestContextStorage`. Selected automatically by bundlers that set the
4
- * `"browser"` export condition (Next.js / webpack client compiler, Vite client
5
- * build) via the conditional `exports` entry in `packages/blocks/package.json`.
6
- *
7
- * There is no per-request async context on the client, so this backend simply
8
- * reports "no active store". Every `RequestContext` accessor built on top of it
9
- * therefore behaves exactly as the real implementation does when called outside
10
- * a request scope:
11
- * - `RequestContext.current` / `requestId` → `null`
12
- * - `RequestContext.request` / `signal` / `responseHeaders` → throw
13
- * - `RequestContext.device` → `"desktop"`, `isBot` → `false`, `elapsed` → `0`
14
- * - `RequestContext.fetch` → falls back to `globalThis.fetch`
15
- *
16
- * That is exactly the fall-through the sole client-reachable consumer
17
- * (`resolveDeviceFromRuntime` in `./useDevice`) relies on: `current === null`
18
- * → use the `navigator.userAgent` client path. Nothing on the client ever
19
- * establishes a request scope, so `run()` never needs real async propagation —
20
- * it just invokes the callback inline.
21
- *
22
- * `RequestContextStorageBackend` is imported `type`-only from the real
23
- * `./requestContextStorage` module — this is erased entirely at compile time
24
- * (by tsc and by the SWC pass Next.js runs before webpack ever sees the
25
- * module graph), so it does NOT drag `node:async_hooks` back into this file's
26
- * runtime output. Annotating `storage` with it means this stub and the real
27
- * `AsyncLocalStorage`-backed implementation are compiler-checked against the
28
- * exact same narrow surface — if one drifts (e.g. `requestContext.ts` starts
29
- * calling a method neither backend exposes), `tsc` fails here, not silently
30
- * at runtime on the client.
31
- */
32
-
33
- import type { RequestContextData } from "./requestContext";
34
- import type { RequestContextStorageBackend } from "./requestContextStorage";
35
-
36
- export const storage: RequestContextStorageBackend = {
37
- getStore(): RequestContextData | undefined {
38
- return undefined;
39
- },
40
- run<R>(_store: RequestContextData, fn: () => R): R {
41
- return fn();
42
- },
43
- };
@@ -1,35 +0,0 @@
1
- /**
2
- * Node/Workers implementation of the per-request storage backend for
3
- * `RequestContext` (see `./requestContext`).
4
- *
5
- * This is the ONE module in the `requestContext` graph that touches
6
- * `node:async_hooks`. It is split out from `requestContext.ts` so that
7
- * bundlers building for a browser target can swap it for the no-op stub in
8
- * `./requestContextStorage.browser` via the `"browser"` export condition in
9
- * `packages/blocks/package.json` — without that condition, Next.js's client
10
- * webpack compiler tries to resolve the `node:async_hooks` specifier for a
11
- * non-Node target and fails the build with `UnhandledSchemeError`, even though
12
- * `AsyncLocalStorage` is only ever meaningfully used server-side.
13
- *
14
- * Requires `nodejs_compat` in wrangler.jsonc (already enabled) on Workers.
15
- */
16
-
17
- import { AsyncLocalStorage } from "node:async_hooks";
18
- import type { RequestContextData } from "./requestContext";
19
-
20
- /**
21
- * The narrow surface `requestContext.ts` actually calls (`storage.getStore()`
22
- * / `storage.run(ctx, fn)`). Exporting `storage` typed as this interface —
23
- * rather than letting it infer the full `AsyncLocalStorage<RequestContextData>`
24
- * type — means `requestContext.ts` only ever sees these two members,
25
- * regardless of which backend (this file or `./requestContextStorage.browser`)
26
- * a given bundler's export condition resolves to. If `requestContext.ts` is
27
- * ever edited to call another `AsyncLocalStorage` method (e.g. `enterWith`,
28
- * `exit`, `disable`), that becomes an immediate compile error at the call
29
- * site — forcing whoever adds it to widen this type here AND add the method
30
- * to the browser stub, instead of silently working against the real backend
31
- * while quietly breaking on the client.
32
- */
33
- export type RequestContextStorageBackend = Pick<AsyncLocalStorage<RequestContextData>, "run" | "getStore">;
34
-
35
- export const storage: RequestContextStorageBackend = new AsyncLocalStorage<RequestContextData>();