@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,82 +0,0 @@
1
- import type { CacheStorage } from "./cacheStorage";
2
- import { decodeBase64 } from "./encoding";
3
-
4
- interface StoredResponse {
5
- status: number;
6
- statusText: string;
7
- headers: [string, string][];
8
- body: string;
9
- }
10
-
11
- /** HTTP serialization belongs to the cache consumer, independent of its storage adapter. */
12
- export function createResponseCache(storage: CacheStorage, scope: string) {
13
- const keyFor = (request: Request) => JSON.stringify([scope, "responses", request.url]);
14
- return {
15
- async match(request: Request): Promise<Response | undefined> {
16
- const raw = await storage.get(keyFor(request));
17
- if (raw === null) return undefined;
18
- try {
19
- const stored = JSON.parse(raw) as StoredResponse;
20
- // Uint8Array.from(string, mapper) creates a large temporary iterable array.
21
- // Decode straight into the byte buffer to keep cache hits proportional to body size.
22
- const body = decodeBase64(stored.body);
23
- return new Response([204, 205, 304].includes(stored.status) ? null : body, {
24
- status: stored.status,
25
- statusText: stored.statusText,
26
- headers: stored.headers,
27
- });
28
- } catch {
29
- return undefined;
30
- }
31
- },
32
- async put(request: Request, response: Response): Promise<void> {
33
- const cc = response.headers.get("Cache-Control") ?? "";
34
- const ttl = Number(/(?:^|[,\s])max-age=(\d+)/i.exec(cc)?.[1] ?? 0);
35
- if (!ttl || /(?:private|no-store|no-cache)/i.test(cc) || response.headers.has("set-cookie"))
36
- return;
37
- const expiresAt = Date.now() + ttl * 1000;
38
- // Bound buffering before serialization; an oversized page can still stream to its caller.
39
- const chunks: Uint8Array[] = [];
40
- let size = 0;
41
- const reader = response.body?.getReader();
42
- if (reader) {
43
- while (true) {
44
- const { done, value } = await reader.read();
45
- if (done) break;
46
- size += value.byteLength;
47
- if (size > 8 * 1024 * 1024) {
48
- void reader.cancel().catch(() => {});
49
- return;
50
- }
51
- chunks.push(value);
52
- }
53
- }
54
- const bytes = new Uint8Array(size);
55
- let offset = 0;
56
- for (const chunk of chunks) {
57
- bytes.set(chunk, offset);
58
- offset += chunk.byteLength;
59
- }
60
- let binary = "";
61
- for (let i = 0; i < bytes.length; i += 8192) {
62
- binary += String.fromCharCode(...bytes.subarray(i, i + 8192));
63
- }
64
- const value: StoredResponse = {
65
- status: response.status,
66
- statusText: response.statusText,
67
- headers: [...response.headers.entries()],
68
- body: btoa(binary),
69
- };
70
- try {
71
- await storage.set(keyFor(request), JSON.stringify(value), expiresAt);
72
- } catch {
73
- /* Cache writes must not fail the response or its waitUntil task. */
74
- }
75
- },
76
- async delete(request: Request): Promise<boolean> {
77
- // KV deletion has no "existed" result. Report an accepted deletion, avoiding an extra read.
78
- await storage.delete(keyFor(request));
79
- return true;
80
- },
81
- };
82
- }
package/src/sdk/retry.ts DELETED
@@ -1,45 +0,0 @@
1
- export const CONNECTION_CLOSED_MESSAGE = "connection closed before message completed";
2
-
3
- function sleep(ms: number): Promise<void> {
4
- return new Promise((resolve) => setTimeout(resolve, ms));
5
- }
6
-
7
- /**
8
- * Simple retry utility — replaces cockatiel to avoid module-level AbortController
9
- * (cockatiel's abort.js creates new AbortController() at module scope, which is
10
- * forbidden in Cloudflare Workers global scope).
11
- *
12
- * Retries up to maxAttempts when the error matches the predicate.
13
- * Uses exponential backoff: delay = min(initialDelay * exponent^attempt, maxDelay).
14
- */
15
- export function retryExceptionOr500() {
16
- return {
17
- execute: async <T>(fn: () => Promise<T>): Promise<T> => {
18
- const maxAttempts = 3;
19
- const initialDelay = 100;
20
- const maxDelay = 5000;
21
- const exponent = 2;
22
-
23
- let lastErr: unknown;
24
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
25
- try {
26
- return await fn();
27
- } catch (err) {
28
- const message = err instanceof Error ? err.message : String(err);
29
- if (!message.includes(CONNECTION_CLOSED_MESSAGE)) {
30
- throw err;
31
- }
32
- lastErr = err;
33
- try {
34
- console.error("retrying...", err);
35
- } catch (_) {}
36
- if (attempt < maxAttempts - 1) {
37
- const delay = Math.min(initialDelay * Math.pow(exponent, attempt), maxDelay);
38
- await sleep(delay);
39
- }
40
- }
41
- }
42
- throw lastErr;
43
- },
44
- };
45
- }
@@ -1,68 +0,0 @@
1
- /**
2
- * Server-Timing header builder.
3
- *
4
- * Tracks named timing entries during a request and serializes them
5
- * into the `Server-Timing` HTTP header for visibility in DevTools.
6
- *
7
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
8
- *
9
- * @example
10
- * ```ts
11
- * const timings = createServerTimings();
12
- * const end = timings.start("resolve-cms");
13
- * await resolvePage();
14
- * end();
15
- * response.headers.set("Server-Timing", timings.toHeader());
16
- * ```
17
- */
18
- export interface ServerTimings {
19
- /** Start a named timing. Returns a function to call when done. */
20
- start(name: string, description?: string): () => void;
21
- /** Record a completed timing with a known duration. */
22
- record(name: string, durationMs: number, description?: string): void;
23
- /** Serialize all timings to a `Server-Timing` header value. */
24
- toHeader(): string;
25
- /** Get all recorded entries for diagnostics. */
26
- entries(): TimingEntry[];
27
- }
28
-
29
- export interface TimingEntry {
30
- name: string;
31
- durationMs: number;
32
- description?: string;
33
- }
34
-
35
- export function createServerTimings(): ServerTimings {
36
- const timingEntries: TimingEntry[] = [];
37
-
38
- return {
39
- start(name: string, description?: string) {
40
- const startTime = performance.now();
41
- return () => {
42
- const durationMs = performance.now() - startTime;
43
- timingEntries.push({ name, durationMs, description });
44
- };
45
- },
46
-
47
- record(name: string, durationMs: number, description?: string) {
48
- timingEntries.push({ name, durationMs, description });
49
- },
50
-
51
- toHeader(): string {
52
- return timingEntries
53
- .map((entry) => {
54
- let value = entry.name;
55
- if (entry.description) {
56
- value += `;desc="${entry.description}"`;
57
- }
58
- value += `;dur=${entry.durationMs.toFixed(1)}`;
59
- return value;
60
- })
61
- .join(", ");
62
- },
63
-
64
- entries() {
65
- return [...timingEntries];
66
- },
67
- };
68
- }
package/src/sdk/signal.ts DELETED
@@ -1,42 +0,0 @@
1
- /**
2
- * Reactive signal backed by @tanstack/store.
3
- *
4
- * Drop-in replacement for the preact signals shim.
5
- * Preserves the .value getter/setter API so consumers don't need to change.
6
- *
7
- * For React components that need to re-render on state changes,
8
- * use the useStore() hook from @tanstack/react-store:
9
- *
10
- * import { useStore } from "@tanstack/react-store";
11
- * const value = useStore(mySignal.store);
12
- */
13
- import { Store } from "@tanstack/store";
14
-
15
- export interface ReactiveSignal<T> {
16
- readonly store: Store<T>;
17
- value: T;
18
- peek(): T;
19
- subscribe(fn: () => void): () => void;
20
- }
21
-
22
- export function signal<T>(initialValue: T): ReactiveSignal<T> {
23
- const store = new Store<T>(initialValue);
24
-
25
- return {
26
- store,
27
- get value(): T {
28
- return store.state;
29
- },
30
- set value(v: T) {
31
- store.setState(() => v);
32
- },
33
- peek(): T {
34
- return store.state;
35
- },
36
- subscribe(fn: () => void): () => void {
37
- const sub = store.subscribe(() => fn());
38
- return () => sub.unsubscribe();
39
- },
40
- };
41
- }
42
-
@@ -1,160 +0,0 @@
1
- /**
2
- * Sitemap generation utilities.
3
- *
4
- * Provides XML sitemap generation from CMS page blocks and arbitrary
5
- * URL lists. Designed to be composed with commerce-specific sitemap
6
- * sources (VTEX, Shopify) in a TanStack Start API route.
7
- *
8
- * @example
9
- * ```ts
10
- * // src/routes/sitemap[.]xml.ts
11
- * import { createAPIFileRoute } from "@tanstack/react-start/api";
12
- * import { getCMSSitemapEntries, generateSitemapXml } from "@decocms/start/sdk/sitemap";
13
- * import { getVtexSitemapEntries } from "@decocms/apps/vtex/utils/sitemap";
14
- *
15
- * export const APIRoute = createAPIFileRoute("/sitemap.xml")({
16
- * GET: async ({ request }) => {
17
- * const origin = new URL(request.url).origin;
18
- * const cmsEntries = getCMSSitemapEntries(origin);
19
- * const vtexEntries = await getVtexSitemapEntries(origin);
20
- * const xml = generateSitemapXml([...cmsEntries, ...vtexEntries]);
21
- * return new Response(xml, {
22
- * headers: {
23
- * "Content-Type": "application/xml",
24
- * "Cache-Control": "public, s-maxage=3600, stale-while-revalidate=86400",
25
- * },
26
- * });
27
- * },
28
- * });
29
- * ```
30
- */
31
-
32
- import { getAllPages, loadBlocks } from "../cms/loader";
33
-
34
- // -------------------------------------------------------------------------
35
- // Types
36
- // -------------------------------------------------------------------------
37
-
38
- export interface SitemapEntry {
39
- loc: string;
40
- lastmod?: string;
41
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
42
- priority?: number;
43
- }
44
-
45
- export interface SitemapOptions {
46
- /** Maximum entries per sitemap (Google limit is 50,000). @default 50000 */
47
- maxEntries?: number;
48
- }
49
-
50
- export interface CMSSitemapOptions {
51
- /** Default changefreq for non-home pages. @default "weekly" */
52
- defaultChangefreq?: SitemapEntry["changefreq"];
53
- /** Default priority for non-home pages (0.0–1.0). @default 0.7 */
54
- defaultPriority?: number;
55
- /** Changefreq for the home page. @default "daily" */
56
- homeChangefreq?: SitemapEntry["changefreq"];
57
- /** Priority for the home page (0.0–1.0). @default 1.0 */
58
- homePriority?: number;
59
- }
60
-
61
- // -------------------------------------------------------------------------
62
- // CMS page entries
63
- // -------------------------------------------------------------------------
64
-
65
- /**
66
- * Extract sitemap entries from CMS page blocks.
67
- *
68
- * Reads all pages from the block store and generates URLs from their
69
- * path patterns (excluding wildcard-only patterns like `/*`).
70
- */
71
- export function getCMSSitemapEntries(origin: string, options?: CMSSitemapOptions): SitemapEntry[] {
72
- const pages = getAllPages();
73
- const entries: SitemapEntry[] = [];
74
- const today = new Date().toISOString().split("T")[0];
75
-
76
- const defaultChangefreq = options?.defaultChangefreq ?? "weekly";
77
- const defaultPriority = options?.defaultPriority ?? 0.7;
78
- const homeChangefreq = options?.homeChangefreq ?? "daily";
79
- const homePriority = options?.homePriority ?? 1.0;
80
-
81
- for (const { page } of pages) {
82
- if (!page.path) continue;
83
-
84
- if (page.path.includes("*") || page.path.includes(":")) continue;
85
-
86
- const isHome = page.path === "/";
87
- const loc = `${origin}${isHome ? "" : page.path}`;
88
- entries.push({
89
- loc: loc || origin,
90
- lastmod: today,
91
- changefreq: isHome ? homeChangefreq : defaultChangefreq,
92
- priority: isHome ? homePriority : defaultPriority,
93
- });
94
- }
95
-
96
- return entries;
97
- }
98
-
99
- // -------------------------------------------------------------------------
100
- // XML generation
101
- // -------------------------------------------------------------------------
102
-
103
- function escapeXml(str: string): string {
104
- return str
105
- .replace(/&/g, "&amp;")
106
- .replace(/</g, "&lt;")
107
- .replace(/>/g, "&gt;")
108
- .replace(/"/g, "&quot;")
109
- .replace(/'/g, "&apos;");
110
- }
111
-
112
- /**
113
- * Generate a sitemap XML string from entries.
114
- */
115
- export function generateSitemapXml(entries: SitemapEntry[], options?: SitemapOptions): string {
116
- const max = options?.maxEntries ?? 50000;
117
- const limited = entries.slice(0, max);
118
-
119
- const urls = limited.map((entry) => {
120
- let url = ` <url>\n <loc>${escapeXml(entry.loc)}</loc>`;
121
- if (entry.lastmod) url += `\n <lastmod>${entry.lastmod}</lastmod>`;
122
- if (entry.changefreq) url += `\n <changefreq>${entry.changefreq}</changefreq>`;
123
- if (entry.priority != null) url += `\n <priority>${entry.priority.toFixed(1)}</priority>`;
124
- url += "\n </url>";
125
- return url;
126
- });
127
-
128
- return [
129
- '<?xml version="1.0" encoding="UTF-8"?>',
130
- '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
131
- ...urls,
132
- "</urlset>",
133
- ].join("\n");
134
- }
135
-
136
- /**
137
- * Generate a sitemap index XML for splitting large sitemaps.
138
- *
139
- * @example
140
- * ```ts
141
- * const index = generateSitemapIndexXml([
142
- * `${origin}/sitemap-pages.xml`,
143
- * `${origin}/sitemap-products.xml`,
144
- * ]);
145
- * ```
146
- */
147
- export function generateSitemapIndexXml(sitemapUrls: string[]): string {
148
- const today = new Date().toISOString().split("T")[0];
149
- const sitemaps = sitemapUrls.map(
150
- (url) =>
151
- ` <sitemap>\n <loc>${escapeXml(url)}</loc>\n <lastmod>${today}</lastmod>\n </sitemap>`,
152
- );
153
-
154
- return [
155
- '<?xml version="1.0" encoding="UTF-8"?>',
156
- '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
157
- ...sitemaps,
158
- "</sitemapindex>",
159
- ].join("\n");
160
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * URL redaction for observability surfaces.
3
- *
4
- * Strips secrets from outbound URLs before they land on a log line or a
5
- * span attribute. The redacted output preserves enough of the URL for
6
- * operators to recognize the call (host, path, which query keys were
7
- * present) without leaking values that may carry tokens, session IDs,
8
- * personal data, or other regulated content.
9
- *
10
- * Why a separate helper (instead of doing it in the ingestor):
11
- *
12
- * - Spans land in CF Workers Tracing before they ever reach our
13
- * ingestor; once the unredacted value is stamped on `http.url`, it's
14
- * in the CF dashboard whether we like it or not.
15
- * - Logs go through `console.log` which Cloudflare captures into
16
- * Workers Logs immediately — same problem.
17
- * - The ingestor's `redactSensitiveHeaders` only covers headers, not
18
- * URLs. Redacting URLs at the emit site is the only way to avoid
19
- * landing a token on a platform we don't control.
20
- *
21
- * Redaction rules:
22
- *
23
- * - Strip userinfo (`https://user:pass@host`) entirely.
24
- * - Drop the fragment (`#...`) — fragments are client-side only and
25
- * may carry SPA state that includes tokens.
26
- * - Replace every query value with `"REDACTED"` unless its key is in
27
- * `keepQueryKeys`. Empty values stay empty so dashboards can still
28
- * distinguish `?foo=` from `?foo=secret`.
29
- * - Preserve the host and path verbatim. Path normalization (e.g.
30
- * collapsing `/p/[slug]`) lives in `observability.ts:normalizePath`
31
- * on the metrics side and is intentionally NOT bundled here.
32
- * - Unparseable inputs fall back to a defensive substring before the
33
- * `?`, so a malformed URL never accidentally surfaces a query string.
34
- */
35
-
36
- const REDACTED = "REDACTED";
37
-
38
- export interface RedactUrlOptions {
39
- /**
40
- * Query parameter names whose value should be left intact. Useful for
41
- * structural / debugging params like `page`, `sort`, `view` that don't
42
- * carry secrets. Names are case-sensitive (matches `URLSearchParams`).
43
- *
44
- * By default this is empty — every value is redacted.
45
- */
46
- keepQueryKeys?: ReadonlyArray<string>;
47
- }
48
-
49
- export function redactUrl(input: string, options: RedactUrlOptions = {}): string {
50
- const keep = options.keepQueryKeys ? new Set(options.keepQueryKeys) : null;
51
-
52
- try {
53
- const u = new URL(input);
54
- // userinfo — never preserve.
55
- u.username = "";
56
- u.password = "";
57
- // fragment — drop. Browsers don't send it, but it can sneak into
58
- // server-side URLs via misconfigured proxies.
59
- u.hash = "";
60
-
61
- // searchParams.set() mutates URLSearchParams in place. Iterating a
62
- // snapshot via [...entries()] is the supported way to avoid mutating
63
- // the iterator we're walking.
64
- const entries = [...u.searchParams.entries()];
65
- for (const [key, value] of entries) {
66
- if (keep && keep.has(key)) continue;
67
- // Preserve empty values (`?k=` stays `?k=`) so dashboards can still
68
- // distinguish empty from redacted-with-content.
69
- if (value.length === 0) continue;
70
- u.searchParams.set(key, REDACTED);
71
- }
72
-
73
- return u.toString();
74
- } catch {
75
- // Unparseable URL — defensively drop everything from the first `?`
76
- // OR `#` onwards. Either can carry a secret (`?token=…`,
77
- // `#access_token=…`); cutting at whichever appears first preserves
78
- // the most context while leaking nothing.
79
- const idx = input.search(/[?#]/);
80
- return idx >= 0 ? input.slice(0, idx) : input;
81
- }
82
- }
@@ -1,183 +0,0 @@
1
- /**
2
- * URL utility functions.
3
- *
4
- * Handles UTM parameter stripping for cache-friendly URLs,
5
- * canonical URL generation, and other URL manipulation.
6
- */
7
-
8
- const UTM_PARAMS = new Set([
9
- "utm_source",
10
- "utm_medium",
11
- "utm_campaign",
12
- "utm_term",
13
- "utm_content",
14
- "utmi_campaign",
15
- "utmi_page",
16
- "utmi_part",
17
- "fbclid",
18
- "gclid",
19
- "gclsrc",
20
- "dclid",
21
- "msclkid",
22
- "twclid",
23
- "li_fat_id",
24
- "mc_cid",
25
- "mc_eid",
26
- "ttclid",
27
- "srsltid",
28
- // GA4's newer campaign params. The five classic `utm_*` above predate them,
29
- // so a GA4-tagged campaign was still fragmenting the cache key.
30
- "utm_id",
31
- "utm_source_platform",
32
- "utm_creative_format",
33
- "utm_marketing_tactic",
34
- // Google Ads click ids that replaced bare `gclid` for privacy-restricted
35
- // traffic (iOS/Safari), plus the source tag now appended to essentially every
36
- // Google Ads click. Measured on a production storefront: each of these missed
37
- // the edge cache on 3/3 routes probed, deterministically.
38
- "gad_source",
39
- "gad_campaignid",
40
- "gbraid",
41
- "wbraid",
42
- // Google Analytics cross-domain linker. Sites already strip this by hand in
43
- // client code, which is the tell that it shows up in real URLs.
44
- "_gl",
45
- "igshid",
46
- "epik",
47
- "mkt_tok",
48
- "yclid",
49
- ]);
50
-
51
- /**
52
- * Register additional tracking parameters to strip from cache keys.
53
- * Useful for proprietary attribution params (e.g., custom analytics tags).
54
- */
55
- export function registerTrackingParam(param: string): void {
56
- UTM_PARAMS.add(param.toLowerCase());
57
- }
58
-
59
- /**
60
- * Register multiple additional tracking parameters at once.
61
- */
62
- export function registerTrackingParams(params: string[]): void {
63
- for (const param of params) {
64
- UTM_PARAMS.add(param.toLowerCase());
65
- }
66
- }
67
-
68
- /**
69
- * Whether a search param is a known tracking/attribution param.
70
- *
71
- * Exposed so cache-key builders can filter params in place without having to
72
- * round-trip through a `URL` (server-fn payloads carry bare relative paths) and
73
- * without keeping a second copy of the list.
74
- */
75
- export function isTrackingParam(param: string): boolean {
76
- return UTM_PARAMS.has(param.toLowerCase());
77
- }
78
-
79
- /**
80
- * Strip UTM and tracking parameters from a URL.
81
- *
82
- * Used to normalize URLs for caching -- two requests that differ
83
- * only in UTM params should hit the same cache entry.
84
- *
85
- * @example
86
- * ```ts
87
- * stripTrackingParams("https://example.com/shoes?color=red&utm_source=google")
88
- * // => "https://example.com/shoes?color=red"
89
- * ```
90
- */
91
- export function stripTrackingParams(urlString: string): string {
92
- try {
93
- const url = new URL(urlString);
94
- let changed = false;
95
-
96
- for (const param of [...url.searchParams.keys()]) {
97
- if (UTM_PARAMS.has(param.toLowerCase())) {
98
- url.searchParams.delete(param);
99
- changed = true;
100
- }
101
- }
102
-
103
- return changed ? url.toString() : urlString;
104
- } catch {
105
- return urlString;
106
- }
107
- }
108
-
109
- /**
110
- * Strip tracking params from a URL and return just the pathname + non-UTM search.
111
- * Useful for cache key generation.
112
- */
113
- export function cleanPathForCacheKey(urlString: string): string {
114
- try {
115
- const url = new URL(urlString);
116
-
117
- for (const param of [...url.searchParams.keys()]) {
118
- if (UTM_PARAMS.has(param.toLowerCase())) {
119
- url.searchParams.delete(param);
120
- }
121
- }
122
-
123
- const search = url.searchParams.toString();
124
- return search ? `${url.pathname}?${search}` : url.pathname;
125
- } catch {
126
- return urlString;
127
- }
128
- }
129
-
130
- /**
131
- * Build a canonical URL from a request, stripping tracking params
132
- * and normalizing the protocol/host.
133
- *
134
- * @param request - The incoming request
135
- * @param baseUrl - Override origin (useful when behind a proxy)
136
- */
137
- export function canonicalUrl(request: Request, baseUrl?: string): string {
138
- const url = new URL(request.url);
139
- const origin = baseUrl ?? url.origin;
140
-
141
- for (const param of [...url.searchParams.keys()]) {
142
- if (UTM_PARAMS.has(param.toLowerCase())) {
143
- url.searchParams.delete(param);
144
- }
145
- }
146
-
147
- const search = url.searchParams.toString();
148
- const path = search ? `${url.pathname}?${search}` : url.pathname;
149
-
150
- return `${origin}${path}`;
151
- }
152
-
153
- /**
154
- * Extract the pathname from an absolute or relative URL, stripping query
155
- * string and hash. Falls back to manual slicing when `new URL()` would
156
- * throw (relative URL without a base). Used by operation routers that
157
- * need to match against URL structure without caring about the host.
158
- */
159
- export function extractPathname(url: string): string {
160
- try {
161
- return new URL(url).pathname;
162
- } catch {
163
- const qs = url.indexOf("?");
164
- const hash = url.indexOf("#");
165
- const end = [qs, hash].filter((i) => i >= 0).sort((a, b) => a - b)[0];
166
- return end === undefined ? url : url.slice(0, end);
167
- }
168
- }
169
-
170
- /**
171
- * Check if a URL has any tracking/UTM parameters.
172
- */
173
- export function hasTrackingParams(urlString: string): boolean {
174
- try {
175
- const url = new URL(urlString);
176
- for (const param of url.searchParams.keys()) {
177
- if (UTM_PARAMS.has(param.toLowerCase())) return true;
178
- }
179
- return false;
180
- } catch {
181
- return false;
182
- }
183
- }