@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,633 +0,0 @@
1
- /**
2
- * Unified cache profile system for Deco storefronts.
3
- *
4
- * Each named profile (product, listing, search, static, etc.) defines cache
5
- * timing across ALL layers — edge, browser, loader, and client — in a single
6
- * object. This is the single source of truth for cache configuration.
7
- *
8
- * Sites override specific values via `setCacheProfile()` without touching
9
- * framework code. Derivation functions (`cacheHeaders`, `routeCacheDefaults`,
10
- * `loaderCacheOptions`, `edgeCacheConfig`) read from the profiles.
11
- *
12
- * @example
13
- * ```ts
14
- * // Site-level override (src/cache-config.ts):
15
- * import { setCacheProfile } from "@decocms/start/sdk/cacheHeaders";
16
- * setCacheProfile("product", { edge: { fresh: 600 } }); // 10min instead of 5min
17
- * ```
18
- */
19
-
20
- import { isTrackingParam } from "./urlUtils";
21
-
22
- // ---------------------------------------------------------------------------
23
- // Types
24
- // ---------------------------------------------------------------------------
25
-
26
- export type CacheProfileName =
27
- | "static"
28
- | "product"
29
- | "listing"
30
- | "search"
31
- | "cart"
32
- | "private"
33
- | "none";
34
-
35
- /** Time windows for a single caching layer (in seconds). */
36
- export interface CacheTimingWindow {
37
- /** How long content is considered fresh — served without origin contact. */
38
- fresh: number;
39
- /** After fresh expires, serve stale while refreshing in background. */
40
- swr: number;
41
- /** After fresh expires and origin is erroring, serve stale for this long. */
42
- sie: number;
43
- }
44
-
45
- /** Unified cache profile covering all layers. */
46
- export interface CacheProfileConfig {
47
- /** Edge / CDN layer (Cloudflare Cache API). Times in seconds. */
48
- edge: CacheTimingWindow;
49
- /** Browser layer (Cache-Control header). Times in seconds. */
50
- browser: CacheTimingWindow;
51
- /** In-memory loader layer. Times in milliseconds. */
52
- loader: {
53
- fresh: number;
54
- sie: number;
55
- };
56
- /** Client-side TanStack Router. Times in milliseconds. */
57
- client: {
58
- staleTime: number;
59
- gcTime: number;
60
- };
61
- /** Whether CDN can cache this profile. False = private, never cached. */
62
- isPublic: boolean;
63
- }
64
-
65
- /**
66
- * Deep partial of CacheProfileConfig for site-level overrides.
67
- * Only the fields you specify are merged; everything else keeps its default.
68
- */
69
- export type CacheProfileOverrides = {
70
- [K in keyof CacheProfileConfig]?: CacheProfileConfig[K] extends object
71
- ? Partial<CacheProfileConfig[K]>
72
- : CacheProfileConfig[K];
73
- };
74
-
75
- // ---------------------------------------------------------------------------
76
- // Default profiles
77
- // ---------------------------------------------------------------------------
78
-
79
- const PROFILES: Record<CacheProfileName, CacheProfileConfig> = {
80
- static: {
81
- edge: { fresh: 900, swr: 7200, sie: 21600 },
82
- browser: { fresh: 120, swr: 1800, sie: 7200 },
83
- loader: { fresh: 300_000, sie: 1_800_000 },
84
- client: { staleTime: 300_000, gcTime: 1_800_000 },
85
- isPublic: true,
86
- },
87
- product: {
88
- edge: { fresh: 300, swr: 1800, sie: 7200 },
89
- browser: { fresh: 60, swr: 600, sie: 3600 },
90
- loader: { fresh: 30_000, sie: 600_000 },
91
- client: { staleTime: 60_000, gcTime: 300_000 },
92
- isPublic: true,
93
- },
94
- listing: {
95
- edge: { fresh: 120, swr: 900, sie: 3600 },
96
- browser: { fresh: 30, swr: 300, sie: 1800 },
97
- loader: { fresh: 60_000, sie: 300_000 },
98
- client: { staleTime: 60_000, gcTime: 300_000 },
99
- isPublic: true,
100
- },
101
- search: {
102
- edge: { fresh: 60, swr: 300, sie: 1800 },
103
- browser: { fresh: 0, swr: 120, sie: 600 },
104
- loader: { fresh: 60_000, sie: 180_000 },
105
- client: { staleTime: 30_000, gcTime: 120_000 },
106
- isPublic: true,
107
- },
108
- cart: {
109
- edge: { fresh: 0, swr: 0, sie: 0 },
110
- browser: { fresh: 0, swr: 0, sie: 0 },
111
- loader: { fresh: 0, sie: 0 },
112
- client: { staleTime: 0, gcTime: 0 },
113
- isPublic: false,
114
- },
115
- private: {
116
- edge: { fresh: 0, swr: 0, sie: 0 },
117
- browser: { fresh: 0, swr: 0, sie: 0 },
118
- loader: { fresh: 0, sie: 0 },
119
- client: { staleTime: 0, gcTime: 0 },
120
- isPublic: false,
121
- },
122
- none: {
123
- edge: { fresh: 0, swr: 0, sie: 0 },
124
- browser: { fresh: 0, swr: 0, sie: 0 },
125
- loader: { fresh: 0, sie: 0 },
126
- client: { staleTime: 0, gcTime: 0 },
127
- isPublic: false,
128
- },
129
- };
130
-
131
- // ---------------------------------------------------------------------------
132
- // Profile accessors
133
- // ---------------------------------------------------------------------------
134
-
135
- export function getCacheProfile(profile: CacheProfileName): CacheProfileConfig {
136
- return PROFILES[profile];
137
- }
138
-
139
- /**
140
- * Override specific values of a cache profile. Only the fields you specify
141
- * are merged; everything else keeps its default.
142
- *
143
- * @example
144
- * ```ts
145
- * setCacheProfile("product", { edge: { fresh: 600 } });
146
- * setCacheProfile("static", { loader: { sie: 3_600_000 } });
147
- * ```
148
- */
149
- export function setCacheProfile(
150
- profile: CacheProfileName,
151
- overrides: CacheProfileOverrides,
152
- ): void {
153
- const current = PROFILES[profile];
154
-
155
- // `private`/`cart`/`none` are the profiles that keep authenticated pages off
156
- // the shared edge (and, once CDN caching is on, off the CDN). Flipping one to
157
- // public is how a checkout page ends up served to another visitor, so it
158
- // takes more than an `isPublic: true` in a props bag — see
159
- // `allowPublicPrivateProfile`.
160
- let isPublic = overrides.isPublic ?? current.isPublic;
161
- if (isPublic && !current.isPublic && !publicPrivateProfilesAllowed) {
162
- console.warn(
163
- `[deco] setCacheProfile("${profile}", { isPublic: true }) ignored: making a ` +
164
- `non-public profile public would let authenticated pages be shared between ` +
165
- `visitors. Call allowPublicPrivateProfile() first if this is deliberate.`,
166
- );
167
- isPublic = current.isPublic;
168
- }
169
-
170
- PROFILES[profile] = {
171
- edge: { ...current.edge, ...overrides.edge },
172
- browser: { ...current.browser, ...overrides.browser },
173
- loader: { ...current.loader, ...overrides.loader },
174
- client: { ...current.client, ...overrides.client },
175
- isPublic,
176
- };
177
- }
178
-
179
- let publicPrivateProfilesAllowed = false;
180
-
181
- /**
182
- * Opt out of the guard in `setCacheProfile` that refuses to turn a non-public
183
- * profile (`private`, `cart`, `none`) public.
184
- *
185
- * There is no legitimate storefront reason to call this. It exists so the
186
- * escape hatch has a name you have to type, rather than being a silent side
187
- * effect of passing `isPublic: true`.
188
- */
189
- export function allowPublicPrivateProfile(): void {
190
- publicPrivateProfilesAllowed = true;
191
- }
192
-
193
- // ---------------------------------------------------------------------------
194
- // Derivation: Cache-Control headers (browser layer)
195
- // ---------------------------------------------------------------------------
196
-
197
- /**
198
- * Generate a `Cache-Control` header from a named profile.
199
- * Returns a headers object ready to spread into route `headers()`.
200
- */
201
- export function cacheHeaders(profile: CacheProfileName): Record<string, string> {
202
- const p = PROFILES[profile];
203
-
204
- if (!p.isPublic || (p.edge.fresh === 0 && p.browser.fresh === 0)) {
205
- return {
206
- "Cache-Control": "private, no-cache, no-store, must-revalidate",
207
- };
208
- }
209
-
210
- const parts: string[] = ["public"];
211
- parts.push(p.browser.fresh > 0 ? `max-age=${p.browser.fresh}` : "max-age=0");
212
- if (p.edge.fresh > 0) parts.push(`s-maxage=${p.edge.fresh}`);
213
- if (p.browser.swr > 0) parts.push(`stale-while-revalidate=${p.browser.swr}`);
214
- if (p.browser.sie > 0) parts.push(`stale-if-error=${p.browser.sie}`);
215
-
216
- return {
217
- "Cache-Control": parts.join(", "),
218
- Vary: "Accept-Encoding",
219
- };
220
- }
221
-
222
- // ---------------------------------------------------------------------------
223
- // Derivation: Edge cache config (for workerEntry SWR/SIE logic)
224
- // ---------------------------------------------------------------------------
225
-
226
- export interface EdgeCacheConfig {
227
- fresh: number;
228
- swr: number;
229
- sie: number;
230
- isPublic: boolean;
231
- }
232
-
233
- export function edgeCacheConfig(profile: CacheProfileName): EdgeCacheConfig {
234
- const p = PROFILES[profile];
235
- return { ...p.edge, isPublic: p.isPublic };
236
- }
237
-
238
- // ---------------------------------------------------------------------------
239
- // Derivation: Client-side route cache defaults (TanStack Router)
240
- // ---------------------------------------------------------------------------
241
-
242
- /**
243
- * Returns `{ staleTime, gcTime }` for a cache profile, ready to spread
244
- * into a TanStack Router route definition.
245
- *
246
- * In dev mode, uses short staleTime (5s) to keep data fresh enough for
247
- * development while avoiding redundant re-fetches.
248
- *
249
- * staleTime is always Infinity in production: TanStack Router v1 dehydrates
250
- * SSR route data with updatedAt: 0, so any finite staleTime makes SSR data
251
- * appear immediately stale on client hydration. That triggers a second
252
- * /_serverFn/loadCmsPage request — a separate Worker isolate that re-runs all
253
- * loaders (including Magento ResolveURL/GetCompleteProduct) and doubles the
254
- * origin load on every first navigation. With Infinity, TanStack Router never
255
- * time-based-refetches in-memory data; gcTime controls how long the data lives
256
- * in memory, and the Cloudflare edge cache handles actual data freshness. (#355)
257
- */
258
- export function routeCacheDefaults(profile: CacheProfileName): { staleTime: number; gcTime: number } {
259
- const env = typeof globalThis.process !== "undefined" ? globalThis.process.env : undefined;
260
- const isDev = env?.DECO_CACHE_DISABLE === "true" || env?.NODE_ENV === "development";
261
- if (isDev) return { staleTime: 5_000, gcTime: 30_000 };
262
- return { staleTime: Infinity, gcTime: PROFILES[profile].client.gcTime };
263
- }
264
-
265
- // ---------------------------------------------------------------------------
266
- // Derivation: Loader cache options (for createCachedLoader)
267
- // ---------------------------------------------------------------------------
268
-
269
- export interface LoaderCacheOptions {
270
- policy: "stale-while-revalidate";
271
- maxAge: number;
272
- staleIfError: number;
273
- }
274
-
275
- /**
276
- * Get loader-layer cache options for a profile.
277
- * Pass directly to `createCachedLoader` as the options argument.
278
- */
279
- export function loaderCacheOptions(profile: CacheProfileName): LoaderCacheOptions {
280
- const p = PROFILES[profile];
281
- return {
282
- policy: "stale-while-revalidate",
283
- maxAge: p.loader.fresh,
284
- staleIfError: p.loader.sie,
285
- };
286
- }
287
-
288
- // ---------------------------------------------------------------------------
289
- // URL-based cache profile detection
290
- // ---------------------------------------------------------------------------
291
-
292
- interface CachePattern {
293
- test: (pathname: string, searchParams: URLSearchParams) => boolean;
294
- profile: CacheProfileName;
295
- }
296
-
297
- // Authenticated / per-user areas that must never be edge-cached. Anything not
298
- // matched here falls through to the cacheable `listing` default, so a missing
299
- // entry is a live content leak, not a missed optimization (see
300
- // decocms/blocks#412, which added the hyphenless `myaccount` VTEX wrapper path
301
- // and the pt-BR account routes).
302
- //
303
- // Three properties this regex must keep, each of which was a real hole:
304
- // - case-insensitive: `/Checkout` used to fall through to `listing`.
305
- // - optional locale prefix: `/pt/checkout`, `/br/minha-conta` likewise. Only
306
- // matches when followed by a private segment, so a legitimate two-letter
307
- // route can't be swallowed by it.
308
- // - wishlist / profile / signup / returns: absent until the CDN work, which
309
- // is what served a live store's `/listadedesejos` from the shared entry.
310
- const PRIVATE_SEGMENTS = [
311
- "cart",
312
- "carrinho",
313
- "checkout",
314
- "account",
315
- "myaccount",
316
- "my-account",
317
- "minha-conta",
318
- "meus-pedidos",
319
- "pedidos",
320
- "orders",
321
- "order-placed",
322
- "login",
323
- "logout",
324
- "sair",
325
- "cadastro",
326
- "signup",
327
- "register",
328
- "profile",
329
- "perfil",
330
- "wishlist",
331
- "favoritos",
332
- "listadedesejos",
333
- "lista-de-desejos",
334
- "minha-lista",
335
- "assinaturas",
336
- "subscriptions",
337
- "troca",
338
- "trocas",
339
- "devolucao",
340
- "devolucoes",
341
- ];
342
-
343
- const LOCALE_PREFIX = "(?:\\/[a-z]{2}(?:-[a-z]{2})?)?";
344
-
345
- const PRIVATE_PREFIX_RE = new RegExp(
346
- `^${LOCALE_PREFIX}\\/(?:${PRIVATE_SEGMENTS.join("|")})(?:\\/|$)`,
347
- "i",
348
- );
349
-
350
- // Site-registered private prefixes (see `registerPrivatePaths`). Kept separate
351
- // from `PRIVATE_SEGMENTS` so a site can only ever ADD to the private set.
352
- const extraPrivatePaths: string[] = [];
353
-
354
- /**
355
- * Mark additional path prefixes as private — never edge-cached, never served
356
- * from the CDN.
357
- *
358
- * This is the safe half of cache configuration: it can only restrict, never
359
- * relax. Prefer it over `registerCachePattern` (which can also make things
360
- * public, and is evaluated before the built-in private check).
361
- *
362
- * @example
363
- * ```ts
364
- * registerPrivatePaths(["/listadedesejos", "/trocas"]);
365
- * ```
366
- */
367
- export function registerPrivatePaths(paths: string[]): void {
368
- for (const path of paths) {
369
- const normalized = path.startsWith("/") ? path : `/${path}`;
370
- if (!extraPrivatePaths.includes(normalized)) extraPrivatePaths.push(normalized);
371
- }
372
- }
373
-
374
- function isPrivatePath(pathname: string): boolean {
375
- if (PRIVATE_PREFIX_RE.test(pathname)) return true;
376
- const lower = pathname.toLowerCase();
377
- return extraPrivatePaths.some((prefix) => {
378
- const p = prefix.toLowerCase();
379
- return lower === p || lower.startsWith(`${p}/`);
380
- });
381
- }
382
-
383
- const builtinPatterns: CachePattern[] = [
384
- {
385
- test: (p) => isPrivatePath(p),
386
- profile: "private",
387
- },
388
- {
389
- test: (p) =>
390
- p.startsWith("/api/") ||
391
- p.startsWith("/deco/") ||
392
- p.startsWith("/_build"),
393
- profile: "none",
394
- },
395
- {
396
- test: (p, sp) => p === "/s" || p.startsWith("/s/") || sp.has("q"),
397
- profile: "search",
398
- },
399
- {
400
- test: (p) => p.endsWith("/p") || /\/p[?#]/.test(p),
401
- profile: "product",
402
- },
403
- {
404
- test: (p) => p === "/" || p === "",
405
- profile: "static",
406
- },
407
- ];
408
-
409
- const customPatterns: CachePattern[] = [];
410
-
411
- /**
412
- * Register additional URL-to-profile patterns. Custom patterns are evaluated
413
- * before built-in ones, so they can override defaults — with one exception:
414
- * a custom pattern resolving to a PUBLIC profile cannot override the built-in
415
- * private check (see `detectCacheProfile`). A broad site pattern would
416
- * otherwise silently capture `/checkout` and make it cacheable.
417
- *
418
- * To mark routes as private, prefer {@link registerPrivatePaths} — it can only
419
- * restrict, and isn't subject to ordering rules.
420
- */
421
- export function registerCachePattern(pattern: CachePattern): void {
422
- customPatterns.push(pattern);
423
- }
424
-
425
- /**
426
- * Detect the appropriate cache profile based on a URL.
427
- * Evaluates custom patterns first, then built-in patterns.
428
- * Falls back to "listing" for unmatched paths.
429
- */
430
- export function detectCacheProfile(pathnameOrUrl: string | URL): CacheProfileName {
431
- let pathname: string;
432
- let searchParams: URLSearchParams;
433
-
434
- if (typeof pathnameOrUrl === "string" && !pathnameOrUrl.startsWith("http")) {
435
- const qIdx = pathnameOrUrl.indexOf("?");
436
- pathname = qIdx >= 0 ? pathnameOrUrl.slice(0, qIdx) : pathnameOrUrl;
437
- searchParams = new URLSearchParams(qIdx >= 0 ? pathnameOrUrl.slice(qIdx) : "");
438
- } else {
439
- const url = pathnameOrUrl instanceof URL ? pathnameOrUrl : new URL(pathnameOrUrl);
440
- pathname = url.pathname;
441
- searchParams = url.searchParams;
442
- }
443
-
444
- // A private path can never be talked into a public profile by a site pattern.
445
- // Custom patterns still win for anything non-public (a site can always make a
446
- // route MORE restricted), and for public-vs-public overrides on other paths.
447
- const privatePath = isPrivatePath(pathname);
448
-
449
- for (const pattern of customPatterns) {
450
- if (!pattern.test(pathname, searchParams)) continue;
451
- if (privatePath && PROFILES[pattern.profile].isPublic) return "private";
452
- return pattern.profile;
453
- }
454
- for (const pattern of builtinPatterns) {
455
- if (pattern.test(pathname, searchParams)) return pattern.profile;
456
- }
457
-
458
- return "listing";
459
- }
460
-
461
- /**
462
- * For a TanStack GET server-fn request (`/_serverFn/<hash>?payload=...`), the
463
- * page being loaded is encoded inside the serialized `payload` arg (e.g.
464
- * `loadCmsPage`'s `data` string `/product/p`). The request pathname itself is
465
- * `/_serverFn/...`, which {@link detectCacheProfile} can only classify as the
466
- * generic "listing" profile — so SPA-navigation data requests would cache under
467
- * a short TTL and rarely hit, even though the underlying page is a product
468
- * (5min) or the homepage (1 day).
469
- *
470
- * Returns the embedded page path so the data request can inherit the SAME cache
471
- * profile as its HTML document. Returns null for non-server-fn URLs or on any
472
- * parse miss, so callers fall back to URL-based detection (never worse than the
473
- * pre-existing behavior).
474
- *
475
- * The payload is TanStack's serialized envelope; rather than depend on its
476
- * exact shape, we walk the parsed JSON for the first arg-value string that
477
- * looks like a route path. `loadCmsPage` encodes exactly one such string.
478
- */
479
- export function serverFnPagePath(url: URL): string | null {
480
- if (
481
- !url.pathname.startsWith("/_serverFn/") &&
482
- !url.pathname.startsWith("/_server/")
483
- ) {
484
- return null;
485
- }
486
- const payload = url.searchParams.get("payload");
487
- if (!payload) return null;
488
- try {
489
- let found: string | null = null;
490
- const visit = (v: unknown): void => {
491
- if (found !== null) return;
492
- if (typeof v === "string") {
493
- if (v.startsWith("/") && !v.startsWith("//")) found = v;
494
- return;
495
- }
496
- if (Array.isArray(v)) {
497
- for (const x of v) visit(x);
498
- return;
499
- }
500
- if (v && typeof v === "object") {
501
- for (const x of Object.values(v)) visit(x);
502
- }
503
- };
504
- visit(JSON.parse(payload));
505
- return found;
506
- } catch {
507
- return null;
508
- }
509
- }
510
-
511
- /**
512
- * `true` when a server-fn payload (GET `payload` param or POST body) embeds a
513
- * route path or absolute URL carrying a tracking param — e.g. a deferred
514
- * section's `pageUrl` built from `location.href` on an ad landing. Same walk as
515
- * {@link canonicalizeServerFnPayloadForCacheKey}. Returns `false` on any parse
516
- * failure (fail-safe: the caller keeps its normal behavior).
517
- */
518
- export function payloadHasTrackingParams(payload: string): boolean {
519
- try {
520
- let found = false;
521
- const check = (s: string): void => {
522
- let search: string;
523
- if (/^https?:\/\//i.test(s)) {
524
- try {
525
- search = new URL(s).search;
526
- } catch {
527
- return;
528
- }
529
- } else if (s.startsWith("/") && !s.startsWith("//")) {
530
- const q = s.indexOf("?");
531
- if (q < 0) return;
532
- search = s.slice(q);
533
- } else {
534
- return;
535
- }
536
- for (const k of new URLSearchParams(search).keys()) {
537
- if (isTrackingParam(k)) {
538
- found = true;
539
- return;
540
- }
541
- }
542
- };
543
- const visit = (v: unknown): void => {
544
- if (found) return;
545
- if (typeof v === "string") {
546
- check(v);
547
- } else if (Array.isArray(v)) {
548
- for (const x of v) visit(x);
549
- } else if (v && typeof v === "object") {
550
- for (const x of Object.values(v)) visit(x);
551
- }
552
- };
553
- visit(JSON.parse(payload));
554
- return found;
555
- } catch {
556
- return false;
557
- }
558
- }
559
-
560
- /**
561
- * Search params that never change a CMS page's resolved server-fn response and
562
- * so must not fragment its edge cache key. `skuId`/`idsku` select a product
563
- * variant client-side (mirrors `cmsRouteConfig`'s default
564
- * `ignoreSearchParams: ["skuId"]`) — without stripping them, every PDP→PDP
565
- * navigation that carries a variant param is a unique key and always MISSes,
566
- * re-running the full page resolution (~1-2s) even though the response is
567
- * identical to the canonical `/product/p`.
568
- */
569
- export const DEFAULT_SERVERFN_CACHE_IGNORE_PARAMS = ["skuId", "idsku"];
570
-
571
- /**
572
- * Canonicalize a TanStack GET server-fn `payload` for use in the edge cache
573
- * key: re-serialize it (so equivalent requests always produce byte-identical
574
- * keys) and strip the cache-irrelevant search params — `ignoreParams` plus every
575
- * known tracking param — from any embedded route path or absolute URL. This
576
- * makes `/product/p?skuId=148940`, `/product/p?utm_source=ads` and `/product/p`
577
- * share one cache entry, since `loadCmsPage` resolves all three to the same
578
- * page.
579
- *
580
- * Returns the original payload unchanged on any parse failure (fail-safe: the
581
- * caller keeps the raw payload, never worse than before).
582
- */
583
- export function canonicalizeServerFnPayloadForCacheKey(
584
- payload: string,
585
- ignoreParams: string[] = DEFAULT_SERVERFN_CACHE_IGNORE_PARAMS,
586
- ): string {
587
- try {
588
- const drop = (sp: URLSearchParams): void => {
589
- for (const p of ignoreParams) sp.delete(p);
590
- // Tracking params never change what the server fn resolves, but they DO
591
- // change this key — so a shopper arriving from paid media mints a brand
592
- // new entry on every SPA interaction. Measured on a production
593
- // storefront: `/_serverFn/:id` at 84% MISS, 1401ms average.
594
- for (const k of [...sp.keys()]) if (isTrackingParam(k)) sp.delete(k);
595
- };
596
- const stripQuery = (s: string): string => {
597
- // Absolute URL: sites embed one in the payload (the deferred-section
598
- // `pageUrl` is built with `new URL(...)`), and it fragments the key
599
- // exactly like a relative path does — but the guard below skipped it, so
600
- // not even `skuId` was canonicalized there.
601
- if (/^https?:\/\//i.test(s)) {
602
- try {
603
- const u = new URL(s);
604
- drop(u.searchParams);
605
- return u.toString();
606
- } catch {
607
- return s;
608
- }
609
- }
610
- if (!s.startsWith("/") || s.startsWith("//")) return s;
611
- const qIdx = s.indexOf("?");
612
- if (qIdx < 0) return s;
613
- const path = s.slice(0, qIdx);
614
- const sp = new URLSearchParams(s.slice(qIdx + 1));
615
- drop(sp);
616
- const rest = sp.toString();
617
- return rest ? `${path}?${rest}` : path;
618
- };
619
- const visit = (v: unknown): unknown => {
620
- if (typeof v === "string") return stripQuery(v);
621
- if (Array.isArray(v)) return v.map(visit);
622
- if (v && typeof v === "object") {
623
- const out: Record<string, unknown> = {};
624
- for (const [k, val] of Object.entries(v)) out[k] = visit(val);
625
- return out;
626
- }
627
- return v;
628
- };
629
- return JSON.stringify(visit(JSON.parse(payload)));
630
- } catch {
631
- return payload;
632
- }
633
- }