@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,459 +0,0 @@
1
- /**
2
- * Built-in matchers matching deco-cx/apps website/matchers/*.
3
- *
4
- * These augment the matchers already handled inline in resolve.ts
5
- * (always, never, device, random, utm) with the additional matchers
6
- * that deco supported: cookie, cron, date, host, pathname, queryString,
7
- * location, userAgent, environment, multi, negate.
8
- *
9
- * Register these at startup:
10
- *
11
- * @example
12
- * ```ts
13
- * import { registerBuiltinMatchers } from "@decocms/start/matchers/builtins";
14
- * registerBuiltinMatchers();
15
- * ```
16
- */
17
-
18
- import type { MatcherContext } from "../cms/resolve";
19
- import { evaluateMatcher, registerMatcher } from "../cms/resolve";
20
- import { resolveCountryCode } from "./countryNames";
21
-
22
- // -------------------------------------------------------------------------
23
- // Cookie matcher
24
- // -------------------------------------------------------------------------
25
-
26
- function cookieMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
27
- const name = rule.name as string | undefined;
28
- const value = rule.value as string | undefined;
29
- if (!name) return false;
30
-
31
- const cookies = ctx.cookies ?? {};
32
- const cookieValue = cookies[name];
33
-
34
- if (cookieValue === undefined) return false;
35
- if (value === undefined) return true;
36
- return cookieValue === value;
37
- }
38
-
39
- // -------------------------------------------------------------------------
40
- // Cron matcher
41
- // -------------------------------------------------------------------------
42
-
43
- function cronMatcher(rule: Record<string, unknown>, _ctx: MatcherContext): boolean {
44
- const start = rule.start as string | undefined;
45
- const end = rule.end as string | undefined;
46
-
47
- if (!start && !end) return true;
48
-
49
- const now = Date.now();
50
-
51
- if (start) {
52
- const startTime = new Date(start).getTime();
53
- if (isNaN(startTime) || now < startTime) return false;
54
- }
55
-
56
- if (end) {
57
- const endTime = new Date(end).getTime();
58
- if (isNaN(endTime) || now > endTime) return false;
59
- }
60
-
61
- return true;
62
- }
63
-
64
- // -------------------------------------------------------------------------
65
- // Date matcher — parity with deco-cx/apps website/matchers/date.ts
66
- //
67
- // Unlike cronMatcher's inclusive [start, end] window (>=, <=), date.ts uses
68
- // strict inequalities: it matches only strictly *between* start and end, so
69
- // a request landing on the exact boundary instant does not match. Invalid
70
- // date strings produce NaN comparisons, which are always false — same
71
- // "reject silently" behavior as the original (no explicit isNaN check
72
- // needed to match upstream semantics).
73
- // -------------------------------------------------------------------------
74
-
75
- function dateMatcher(rule: Record<string, unknown>, _ctx: MatcherContext): boolean {
76
- const start = rule.start as string | undefined;
77
- const end = rule.end as string | undefined;
78
-
79
- const now = new Date();
80
- const afterStart = start ? now > new Date(start) : true;
81
- const beforeEnd = end ? now < new Date(end) : true;
82
-
83
- return afterStart && beforeEnd;
84
- }
85
-
86
- // -------------------------------------------------------------------------
87
- // Host matcher
88
- // -------------------------------------------------------------------------
89
-
90
- function hostMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
91
- const hostToMatch = rule.host as string | undefined;
92
- if (!hostToMatch) return false;
93
-
94
- const currentUrl = ctx.url;
95
- if (!currentUrl) return false;
96
-
97
- try {
98
- const url = new URL(currentUrl);
99
- return url.hostname === hostToMatch || url.host === hostToMatch;
100
- } catch {
101
- return false;
102
- }
103
- }
104
-
105
- // -------------------------------------------------------------------------
106
- // Pathname matcher
107
- // -------------------------------------------------------------------------
108
-
109
- const MAX_PATTERN_LENGTH = 500;
110
- const REDOS_HEURISTIC = /(\+|\*|\{[^}]*,\})\s*(\+|\*|\{[^}]*,\})/;
111
-
112
- function isSafePattern(pattern: string): boolean {
113
- if (pattern.length > MAX_PATTERN_LENGTH) return false;
114
- if (REDOS_HEURISTIC.test(pattern)) return false;
115
- return true;
116
- }
117
-
118
- function pathnameMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
119
- const path = ctx.path ?? "";
120
-
121
- // CMS "case" format: { type: "Includes" | "Equals" | "Not Includes" | "Starts With", pathname: "/..." }
122
- const caseObj = rule.case as { type?: string; pathname?: string } | undefined;
123
- if (caseObj?.pathname) {
124
- switch (caseObj.type) {
125
- case "Equals":
126
- return path === caseObj.pathname;
127
- case "Not Includes":
128
- return !path.includes(caseObj.pathname);
129
- case "Starts With":
130
- return path.startsWith(caseObj.pathname);
131
- case "Includes":
132
- default:
133
- return path.includes(caseObj.pathname);
134
- }
135
- }
136
-
137
- // Standard format: pattern (regex), includes (exact/glob), excludes (exact/glob)
138
- const pattern = rule.pattern as string | undefined;
139
- const includes = rule.includes as string[] | undefined;
140
- const excludes = rule.excludes as string[] | undefined;
141
-
142
- if (pattern) {
143
- if (!isSafePattern(pattern)) {
144
- console.warn(
145
- `[pathnameMatcher] Rejected potentially unsafe pattern: ${pattern.slice(0, 80)}`,
146
- );
147
- return false;
148
- }
149
- try {
150
- const regex = new RegExp(pattern);
151
- if (!regex.test(path)) return false;
152
- } catch {
153
- return false;
154
- }
155
- }
156
-
157
- if (includes && includes.length > 0) {
158
- const matches = includes.some((inc) => {
159
- if (inc.includes("*")) {
160
- const prefix = inc.replace(/\*+$/, "");
161
- return path.startsWith(prefix);
162
- }
163
- return path === inc;
164
- });
165
- if (!matches) return false;
166
- }
167
-
168
- if (excludes && excludes.length > 0) {
169
- const excluded = excludes.some((exc) => {
170
- if (exc.includes("*")) {
171
- const prefix = exc.replace(/\*+$/, "");
172
- return path.startsWith(prefix);
173
- }
174
- return path === exc;
175
- });
176
- if (excluded) return false;
177
- }
178
-
179
- // No constraints specified — vacuously true
180
- if (!pattern && !includes?.length && !excludes?.length) return false;
181
-
182
- return true;
183
- }
184
-
185
- // -------------------------------------------------------------------------
186
- // Query string matcher
187
- // -------------------------------------------------------------------------
188
-
189
- function queryStringMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
190
- const key = (rule.key ?? rule.param) as string | undefined;
191
- const value = rule.value as string | undefined;
192
-
193
- if (!key) return false;
194
-
195
- const currentUrl = ctx.url;
196
- if (!currentUrl) return false;
197
-
198
- try {
199
- const url = new URL(currentUrl);
200
- const paramValue = url.searchParams.get(key);
201
-
202
- if (paramValue === null) return false;
203
- if (value === undefined) return true;
204
- return paramValue === value;
205
- } catch {
206
- return false;
207
- }
208
- }
209
-
210
- // -------------------------------------------------------------------------
211
- // Location matcher — parity with deco-cx/apps/website/matchers/location.ts
212
- //
213
- // Each entry in includeLocations/excludeLocations is a union of:
214
- // Location: { city?, regionCode?, country? }
215
- // Map: { coordinates?: "lat,lng,radius_in_meters" }
216
- // Fields may coexist on the same entry; the matcher AND's every constraint
217
- // that is populated. An entry with zero constraints returns defaultNotMatched
218
- // (true for includes, false for excludes), matching upstream semantics.
219
- // -------------------------------------------------------------------------
220
-
221
- interface LocationOrMap {
222
- country?: string;
223
- regionCode?: string;
224
- city?: string;
225
- /** "latitude,longitude,radius_in_meters" — e.g. "-23.5505,-46.6333,5000" */
226
- coordinates?: string;
227
- }
228
-
229
- interface GeoSource {
230
- country: string;
231
- regionCode: string;
232
- city: string;
233
- /** "latitude,longitude" when available */
234
- coordinates?: string;
235
- }
236
-
237
- function decodeCookie(value: string | undefined): string {
238
- if (!value) return "";
239
- try {
240
- return decodeURIComponent(value);
241
- } catch {
242
- return value;
243
- }
244
- }
245
-
246
- /**
247
- * Extract geo data from the request context.
248
- *
249
- * Read order mirrors the original deco-cx/apps matcher (header-first), with
250
- * additional fallbacks for environments that don't preserve the cf-* request
251
- * headers (e.g. when TanStack Start re-wraps the request and drops them):
252
- * 1. cf-* request headers (cf-region-code, cf-ipcity, ...)
253
- * 2. request.cf (Cloudflare Workers native)
254
- * 3. __cf_geo_* cookies (injected by createDecoWorkerEntry)
255
- */
256
- function getGeoData(ctx: MatcherContext): GeoSource {
257
- const headers = ctx.headers ?? {};
258
- const reqHeaders = ctx.request?.headers;
259
- const h = (name: string): string =>
260
- headers[name] ?? reqHeaders?.get(name) ?? "";
261
-
262
- let regionCode = h("cf-region-code");
263
- let country = h("cf-ipcountry") || h("x-vercel-ip-country");
264
- let city = h("cf-ipcity");
265
- let latitude = h("cf-iplatitude");
266
- let longitude = h("cf-iplongitude");
267
-
268
- if (!country || !regionCode || !city || !latitude || !longitude) {
269
- const req = ctx.request;
270
- const cf = req ? ((req as any).cf as Record<string, unknown> | undefined) : undefined;
271
- if (cf) {
272
- country = country || ((cf.country as string) ?? "");
273
- regionCode = regionCode || ((cf.regionCode as string) ?? "");
274
- city = city || ((cf.city as string) ?? "");
275
- latitude = latitude || (cf.latitude != null ? String(cf.latitude) : "");
276
- longitude = longitude || (cf.longitude != null ? String(cf.longitude) : "");
277
- }
278
- }
279
-
280
- if (!country || !regionCode || !city || !latitude || !longitude) {
281
- const cookies = ctx.cookies ?? {};
282
- country = country || decodeCookie(cookies.__cf_geo_country);
283
- regionCode = regionCode || decodeCookie(cookies.__cf_geo_region_code);
284
- city = city || decodeCookie(cookies.__cf_geo_city);
285
- latitude = latitude || decodeCookie(cookies.__cf_geo_lat);
286
- longitude = longitude || decodeCookie(cookies.__cf_geo_lng);
287
- }
288
-
289
- const coordinates = latitude && longitude ? `${latitude},${longitude}` : undefined;
290
- return { country, regionCode, city, coordinates };
291
- }
292
-
293
- /**
294
- * Haversine "within radius" check.
295
- *
296
- * @param source "latitude,longitude" from the request's geo.
297
- * @param target "latitude,longitude,radius_in_meters" from the rule entry.
298
- */
299
- function haversineWithinRadius(source: string, target: string): boolean {
300
- const [slat, slng] = source.split(",").map(Number);
301
- const parts = target.split(",").map(Number);
302
- const [tlat, tlng, radiusMeters] = parts;
303
- if (
304
- !Number.isFinite(slat) ||
305
- !Number.isFinite(slng) ||
306
- !Number.isFinite(tlat) ||
307
- !Number.isFinite(tlng) ||
308
- !Number.isFinite(radiusMeters)
309
- ) {
310
- return false;
311
- }
312
- const R = 6371000;
313
- const toRad = (d: number) => (d * Math.PI) / 180;
314
- const dLat = toRad(tlat - slat);
315
- const dLng = toRad(tlng - slng);
316
- const a =
317
- Math.sin(dLat / 2) ** 2 +
318
- Math.cos(toRad(slat)) * Math.cos(toRad(tlat)) * Math.sin(dLng / 2) ** 2;
319
- const distance = 2 * R * Math.asin(Math.sqrt(a));
320
- return distance <= radiusMeters;
321
- }
322
-
323
- function matchLocation(defaultNotMatched: boolean, source: GeoSource) {
324
- return (target: LocationOrMap): boolean => {
325
- const hasRegion = !!target.regionCode;
326
- const hasCity = !!target.city;
327
- const hasCountry = !!target.country;
328
- const hasCoords = !!target.coordinates;
329
-
330
- if (!hasRegion && !hasCity && !hasCountry && !hasCoords) {
331
- return defaultNotMatched;
332
- }
333
-
334
- let result =
335
- !hasRegion ||
336
- (target.regionCode!.toLowerCase() === source.regionCode.toLowerCase());
337
-
338
- // Map-mode entries require the visitor to have coordinates — otherwise
339
- // we can't tell whether they're inside the target radius, so the
340
- // conservative default is "no match". This is a deliberate divergence
341
- // from deco-cx/apps, which let coord-only rules vacuously pass when the
342
- // visitor had no lat/lng — that behavior matches every visitor without
343
- // geo data, which is a footgun in production.
344
- result = result &&
345
- (!hasCoords ||
346
- (!!source.coordinates &&
347
- haversineWithinRadius(source.coordinates, target.coordinates!)));
348
-
349
- result = result &&
350
- (!hasCity || target.city!.toLowerCase() === source.city.toLowerCase());
351
-
352
- result = result &&
353
- (!hasCountry ||
354
- resolveCountryCode(target.country!).toUpperCase() ===
355
- source.country.toUpperCase());
356
-
357
- return result;
358
- };
359
- }
360
-
361
- function locationMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
362
- const source = getGeoData(ctx);
363
- const includeLocations = rule.includeLocations as LocationOrMap[] | undefined;
364
- const excludeLocations = rule.excludeLocations as LocationOrMap[] | undefined;
365
-
366
- if (excludeLocations?.some(matchLocation(false, source))) {
367
- return false;
368
- }
369
- if (!includeLocations || includeLocations.length === 0) {
370
- return true;
371
- }
372
- return includeLocations.some(matchLocation(true, source));
373
- }
374
-
375
- // -------------------------------------------------------------------------
376
- // User Agent matcher
377
- // -------------------------------------------------------------------------
378
-
379
- function userAgentMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
380
- const ua = ctx.userAgent ?? "";
381
- const includes = rule.includes as string | undefined;
382
- const match = rule.match as string | undefined;
383
-
384
- if (includes && !ua.includes(includes)) return false;
385
- if (match) {
386
- if (!isSafePattern(match)) return false;
387
- try {
388
- if (!new RegExp(match, "i").test(ua)) return false;
389
- } catch {
390
- return false;
391
- }
392
- }
393
- return true;
394
- }
395
-
396
- // -------------------------------------------------------------------------
397
- // Environment matcher
398
- // -------------------------------------------------------------------------
399
-
400
- function environmentMatcher(rule: Record<string, unknown>, _ctx: MatcherContext): boolean {
401
- const environment = rule.environment as string | undefined;
402
- if (!environment) return true;
403
-
404
- const isProd =
405
- typeof process !== "undefined" && process.env?.NODE_ENV === "production";
406
-
407
- if (environment === "production") return isProd;
408
- if (environment === "development") return !isProd;
409
- return false;
410
- }
411
-
412
- // -------------------------------------------------------------------------
413
- // Multi matcher (AND/OR combinator)
414
- // -------------------------------------------------------------------------
415
-
416
- function multiMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
417
- const op = (rule.op as string) ?? "and";
418
- const matchers = rule.matchers as Array<Record<string, unknown>> | undefined;
419
-
420
- if (!matchers?.length) return true;
421
-
422
- const results = matchers.map((m) => evaluateMatcher(m, ctx));
423
- return op === "or" ? results.some(Boolean) : results.every(Boolean);
424
- }
425
-
426
- // -------------------------------------------------------------------------
427
- // Negate matcher
428
- // -------------------------------------------------------------------------
429
-
430
- function negateMatcher(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
431
- const matcher = rule.matcher as Record<string, unknown> | undefined;
432
- if (!matcher) return false;
433
- return !evaluateMatcher(matcher, ctx);
434
- }
435
-
436
- // -------------------------------------------------------------------------
437
- // Registration
438
- // -------------------------------------------------------------------------
439
-
440
- /**
441
- * Register all built-in matchers with the CMS resolver.
442
- *
443
- * Call once during app setup (in setup.ts or similar).
444
- * These cover the matchers from deco-cx/apps that weren't
445
- * handled inline in resolve.ts.
446
- */
447
- export function registerBuiltinMatchers(): void {
448
- registerMatcher("website/matchers/cookie.ts", cookieMatcher);
449
- registerMatcher("website/matchers/cron.ts", cronMatcher);
450
- registerMatcher("website/matchers/date.ts", dateMatcher);
451
- registerMatcher("website/matchers/host.ts", hostMatcher);
452
- registerMatcher("website/matchers/pathname.ts", pathnameMatcher);
453
- registerMatcher("website/matchers/queryString.ts", queryStringMatcher);
454
- registerMatcher("website/matchers/location.ts", locationMatcher);
455
- registerMatcher("website/matchers/userAgent.ts", userAgentMatcher);
456
- registerMatcher("website/matchers/environment.ts", environmentMatcher);
457
- registerMatcher("website/matchers/multi.ts", multiMatcher);
458
- registerMatcher("website/matchers/negate.ts", negateMatcher);
459
- }
@@ -1,104 +0,0 @@
1
- /**
2
- * CMS country name → ISO 3166-1 alpha-2 code mapping.
3
- *
4
- * The CMS stores countries as full names ("Brasil", "United States").
5
- * Cloudflare and other geo providers return ISO codes ("BR", "US").
6
- * Keys are case-sensitive as authored in the CMS — callers should
7
- * try both the raw value and a case-normalized lookup.
8
- */
9
- export const COUNTRY_NAME_TO_CODE: Record<string, string> = {
10
- // Latin America
11
- Brasil: "BR", Brazil: "BR",
12
- Argentina: "AR",
13
- Chile: "CL",
14
- Colombia: "CO",
15
- Mexico: "MX", "México": "MX",
16
- Peru: "PE", "Perú": "PE",
17
- Uruguay: "UY",
18
- Paraguay: "PY",
19
- Bolivia: "BO",
20
- Ecuador: "EC",
21
- Venezuela: "VE",
22
- "Costa Rica": "CR",
23
- Panama: "PA", "Panamá": "PA",
24
- "Dominican Republic": "DO",
25
- Guatemala: "GT",
26
- Honduras: "HN",
27
- "El Salvador": "SV",
28
- Nicaragua: "NI",
29
- Cuba: "CU",
30
- "Puerto Rico": "PR",
31
-
32
- // North America
33
- "United States": "US", USA: "US", "Estados Unidos": "US",
34
- Canada: "CA", "Canadá": "CA",
35
-
36
- // Europe
37
- Spain: "ES", "España": "ES",
38
- Portugal: "PT",
39
- Germany: "DE", Alemania: "DE", Deutschland: "DE",
40
- France: "FR", Francia: "FR",
41
- Italy: "IT", Italia: "IT",
42
- "United Kingdom": "GB", UK: "GB",
43
- Netherlands: "NL",
44
- Switzerland: "CH",
45
- Sweden: "SE",
46
- Norway: "NO",
47
- Denmark: "DK",
48
- Finland: "FI",
49
- Belgium: "BE",
50
- Austria: "AT",
51
- Ireland: "IE",
52
- Turkey: "TR", "Türkiye": "TR",
53
- Poland: "PL",
54
- "Czech Republic": "CZ", Czechia: "CZ",
55
- Romania: "RO",
56
- Hungary: "HU",
57
- Greece: "GR",
58
- Croatia: "HR",
59
-
60
- // Asia & Oceania
61
- Japan: "JP", "Japón": "JP",
62
- China: "CN",
63
- "South Korea": "KR",
64
- India: "IN",
65
- Australia: "AU",
66
- "New Zealand": "NZ",
67
-
68
- // Middle East & Africa
69
- Israel: "IL",
70
- "Saudi Arabia": "SA",
71
- "United Arab Emirates": "AE",
72
- "South Africa": "ZA",
73
- };
74
-
75
- /**
76
- * Resolve a country name (as stored in CMS) to its ISO code.
77
- * Tries exact match first, then case-insensitive lookup.
78
- */
79
- export function resolveCountryCode(name: string): string {
80
- if (COUNTRY_NAME_TO_CODE[name]) return COUNTRY_NAME_TO_CODE[name];
81
-
82
- const lower = name.toLowerCase();
83
- for (const [key, code] of Object.entries(COUNTRY_NAME_TO_CODE)) {
84
- if (key.toLowerCase() === lower) return code;
85
- }
86
-
87
- // Assume it's already an ISO code
88
- return name.toUpperCase();
89
- }
90
-
91
- /**
92
- * Register an additional country name → ISO code mapping at runtime.
93
- * Useful for site-specific CMS values not covered by the built-in list.
94
- */
95
- export function registerCountryMapping(name: string, code: string): void {
96
- COUNTRY_NAME_TO_CODE[name] = code;
97
- }
98
-
99
- /**
100
- * Register multiple country name → ISO code mappings at once.
101
- */
102
- export function registerCountryMappings(mappings: Record<string, string>): void {
103
- Object.assign(COUNTRY_NAME_TO_CODE, mappings);
104
- }
@@ -1,136 +0,0 @@
1
- /**
2
- * Per-request matcher override — port of the Deno runtime's
3
- * `x-deco-matchers-override` flag (deco/blocks/matcher.ts).
4
- *
5
- * Forces matcher results without running them, keyed by the Deno-style
6
- * uniqueId derived from the matcher's position in the decofile:
7
- *
8
- * - Saved matcher block referenced by name → the block name
9
- * (`Segmento Mobile=1`), mirroring Deno's resolve chain stopping at the
10
- * first resolvable.
11
- * - Inline matcher → `<blockId>@<prop.path.to.rule>`
12
- * (`pages-home-c4bcbfb771e9@sections.2.variants.0.rule=0`).
13
- *
14
- * Carried by:
15
- * - Header: `x-deco-matchers-override: SegmentA=1 SegmentB=0`
16
- * (space-separated pairs; `=1` forces true, anything else forces false)
17
- * - Query string: `?x-deco-matchers-override=Segment%20A%3D1` (repeatable)
18
- *
19
- * Header takes precedence over query string when both are present.
20
- */
21
-
22
- import type { MatcherContext } from "../cms/resolve";
23
-
24
- export const DECO_MATCHERS_OVERRIDE_PARAM = "x-deco-matchers-override";
25
-
26
- /** Splits on the FIRST "=" so block names containing "=" still work. */
27
- function addPair(values: Record<string, boolean>, pair: string): void {
28
- const idx = pair.indexOf("=");
29
- if (idx <= 0) return;
30
- values[pair.slice(0, idx)] = pair.slice(idx + 1) === "1";
31
- }
32
-
33
- function parseFromHeaders(ctx: MatcherContext): Record<string, boolean> | undefined {
34
- const val =
35
- ctx.request?.headers.get(DECO_MATCHERS_OVERRIDE_PARAM) ??
36
- ctx.headers?.[DECO_MATCHERS_OVERRIDE_PARAM];
37
- if (!val) return undefined;
38
- const values: Record<string, boolean> = {};
39
- for (const pair of val.split(" ")) addPair(values, pair);
40
- return values;
41
- }
42
-
43
- function parseFromQS(ctx: MatcherContext): Record<string, boolean> | undefined {
44
- if (!ctx.url) return undefined;
45
- let url: URL;
46
- try {
47
- url = new URL(ctx.url);
48
- } catch {
49
- return undefined;
50
- }
51
- if (!url.searchParams.has(DECO_MATCHERS_OVERRIDE_PARAM)) return undefined;
52
- const values: Record<string, boolean> = {};
53
- for (const pair of url.searchParams.getAll(DECO_MATCHERS_OVERRIDE_PARAM)) {
54
- addPair(values, pair);
55
- }
56
- return values;
57
- }
58
-
59
- const EMPTY: Record<string, boolean> = {};
60
-
61
- // Memoized per Request so a page with many matchers parses once.
62
- const overridesByRequest = new WeakMap<Request, Record<string, boolean>>();
63
-
64
- /**
65
- * Parse the matcher overrides for this request (header first, then query
66
- * string). Returns an empty object when no override is present.
67
- */
68
- export function getMatchersOverride(ctx: MatcherContext): Record<string, boolean> {
69
- const request = ctx.request;
70
- if (request) {
71
- const cached = overridesByRequest.get(request);
72
- if (cached) return cached;
73
- }
74
- const values = parseFromHeaders(ctx) ?? parseFromQS(ctx) ?? EMPTY;
75
- if (request) overridesByRequest.set(request, values);
76
- return values;
77
- }
78
-
79
- export function hasMatchersOverride(ctx: MatcherContext): boolean {
80
- const overrides = getMatchersOverride(ctx);
81
- for (const _ in overrides) return true;
82
- return false;
83
- }
84
-
85
- // ---------------------------------------------------------------------------
86
- // Rule uniqueId index — Deno resolveChain semantics
87
- // ---------------------------------------------------------------------------
88
-
89
- type RuleIdIndex = WeakMap<object, string>;
90
-
91
- // Keyed by the blocks map identity, so the index is rebuilt on decofile
92
- // hot-reload / KV swap (setBlocks replaces the map) and admin preview
93
- // (withBlocksOverride returns a fresh merged map).
94
- const indexByBlocks = new WeakMap<Record<string, unknown>, RuleIdIndex>();
95
-
96
- function walkBlock(node: unknown, blockId: string, path: string, index: RuleIdIndex): void {
97
- if (!node || typeof node !== "object") return;
98
- if (Array.isArray(node)) {
99
- for (let i = 0; i < node.length; i++) {
100
- walkBlock(node[i], blockId, path ? `${path}.${i}` : `${i}`, index);
101
- }
102
- return;
103
- }
104
- const obj = node as Record<string, unknown>;
105
- if (path && typeof obj.__resolveType === "string") {
106
- index.set(obj, `${blockId}@${path}`);
107
- }
108
- for (const [key, value] of Object.entries(obj)) {
109
- if (key === "__resolveType") continue;
110
- walkBlock(value, blockId, path ? `${path}.${key}` : key, index);
111
- }
112
- }
113
-
114
- /**
115
- * Resolve the Deno-style uniqueId (`<blockId>@<prop.path>`) for an inline
116
- * rule object by its identity in the blocks map. Returns undefined for
117
- * objects created during resolution (spreads/merges) — those are addressed
118
- * by their saved-block name instead.
119
- *
120
- * The index is built lazily (only when a request carries an override) and
121
- * cached per blocks map, so override-free traffic pays nothing.
122
- */
123
- export function getRuleOverrideId(
124
- blocks: Record<string, unknown>,
125
- rule: object,
126
- ): string | undefined {
127
- let index = indexByBlocks.get(blocks);
128
- if (!index) {
129
- index = new WeakMap();
130
- for (const [blockId, block] of Object.entries(blocks)) {
131
- walkBlock(block, blockId, "", index);
132
- }
133
- indexByBlocks.set(blocks, index);
134
- }
135
- return index.get(rule);
136
- }