zitejs 0.10.0-start.8 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (417) hide show
  1. package/dist/cjs/auth/actions.d.ts +28 -0
  2. package/dist/cjs/auth/actions.js +93 -0
  3. package/dist/cjs/auth/client.d.ts +357 -0
  4. package/dist/cjs/auth/client.js +66 -0
  5. package/dist/cjs/auth/config.js +9 -3
  6. package/dist/cjs/auth/index.d.ts +2 -249
  7. package/dist/cjs/auth/index.js +11 -108
  8. package/dist/cjs/auth/index.test.js +60 -0
  9. package/dist/cjs/auth/previewClaim.d.ts +7 -0
  10. package/dist/cjs/auth/previewClaim.js +16 -0
  11. package/dist/cjs/auth/profileUpdates.d.ts +9 -0
  12. package/dist/cjs/auth/profileUpdates.js +11 -0
  13. package/dist/cjs/backend/index.d.ts +15 -9
  14. package/dist/cjs/backend/index.js +13 -13
  15. package/dist/cjs/backend/index.test.js +102 -102
  16. package/dist/cjs/bundle/index.d.ts +8 -0
  17. package/dist/cjs/bundle/index.js +38 -24
  18. package/dist/cjs/caller/index.js +43 -43
  19. package/dist/cjs/check/index.d.ts +44 -1
  20. package/dist/cjs/check/index.js +188 -113
  21. package/dist/cjs/check/start/routeTree.d.ts +8 -0
  22. package/dist/cjs/check/start/routeTree.js +118 -0
  23. package/dist/cjs/check/start/tsgo.d.ts +2 -0
  24. package/dist/cjs/check/start/tsgo.js +35 -0
  25. package/dist/cjs/cli.js +10 -4
  26. package/dist/cjs/client/index.d.ts +26 -2
  27. package/dist/cjs/client/index.js +25 -25
  28. package/dist/cjs/dev/index.js +79 -54
  29. package/dist/cjs/dev/signin.d.ts +16 -0
  30. package/dist/cjs/dev/signin.js +84 -0
  31. package/dist/cjs/index.d.ts +5 -5
  32. package/dist/cjs/integrations/client.d.ts +3 -3
  33. package/dist/cjs/integrations/client.js +5 -4
  34. package/dist/cjs/integrations/client.test-d.js +15 -15
  35. package/dist/cjs/integrations/index.d.ts +2 -2
  36. package/dist/cjs/integrations/rules.d.ts +1 -0
  37. package/dist/cjs/integrations/rules.js +48 -43
  38. package/dist/cjs/integrations/rules.test.js +60 -54
  39. package/dist/cjs/internal/appMode.d.ts +14 -0
  40. package/dist/cjs/internal/appMode.js +19 -0
  41. package/dist/cjs/internal/env.js +3 -2
  42. package/dist/cjs/internal/platformFetch.d.ts +2 -0
  43. package/dist/cjs/internal/platformFetch.js +14 -0
  44. package/dist/cjs/internal/reservedIds.d.ts +8 -0
  45. package/dist/cjs/internal/reservedIds.js +14 -0
  46. package/dist/cjs/internal/serviceUrls.d.ts +5 -0
  47. package/dist/cjs/internal/serviceUrls.js +14 -0
  48. package/dist/cjs/pdf/index.js +2 -1
  49. package/dist/cjs/runtime/filterConditionTypes.test-d.js +11 -11
  50. package/dist/cjs/runtime/index.d.ts +126 -39
  51. package/dist/cjs/runtime/index.js +32 -26
  52. package/dist/cjs/runtime/index.test.js +34 -34
  53. package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +50 -0
  54. package/dist/cjs/runtime/writeResultTypes.test-d.js +8 -8
  55. package/dist/cjs/sourceRoots.js +15 -15
  56. package/dist/cjs/sourceRoots.test.js +29 -27
  57. package/dist/cjs/start/{entries.d.ts → build/entries.d.ts} +9 -4
  58. package/dist/cjs/start/{entries.js → build/entries.js} +38 -21
  59. package/dist/cjs/start/build/placeholders/devApp.d.ts +1 -0
  60. package/dist/cjs/start/build/placeholders/devApp.js +6 -0
  61. package/dist/{esm/start → cjs/start/describe}/describeBuilt.d.ts +2 -0
  62. package/dist/cjs/start/{describeBuilt.js → describe/describeBuilt.js} +55 -17
  63. package/dist/cjs/start/platform/aiUsage.d.ts +29 -0
  64. package/dist/cjs/start/platform/aiUsage.js +215 -0
  65. package/dist/cjs/start/platform/airtable/cache.d.ts +17 -0
  66. package/dist/cjs/start/platform/airtable/cache.js +93 -0
  67. package/dist/cjs/start/protocol.d.ts +19 -0
  68. package/dist/cjs/start/protocol.js +33 -0
  69. package/dist/cjs/start/serve/local/provider.d.ts +25 -0
  70. package/dist/cjs/start/serve/local/provider.js +196 -0
  71. package/dist/cjs/start/serve/provider.d.ts +19 -0
  72. package/dist/cjs/start/serve/provider.js +86 -0
  73. package/dist/cjs/start/types.d.ts +373 -0
  74. package/dist/cjs/start/types.js +2 -0
  75. package/dist/cjs/steps/index.d.ts +78 -0
  76. package/dist/cjs/steps/index.js +507 -0
  77. package/dist/cjs/steps/index.test.js +635 -0
  78. package/dist/cjs/sync/index.d.ts +1 -1
  79. package/dist/cjs/sync/index.js +28 -27
  80. package/dist/cjs/sync/lib.d.ts +15 -8
  81. package/dist/cjs/sync/lib.js +655 -655
  82. package/dist/cjs/sync/lib.test.js +177 -46
  83. package/dist/cjs/sync/sdkNames.d.ts +67 -9
  84. package/dist/cjs/sync/sdkNames.js +97 -31
  85. package/dist/cjs/sync/sdkNames.test.js +189 -113
  86. package/dist/cjs/types/fields.d.ts +9 -2
  87. package/dist/cjs/types/fields.js +110 -96
  88. package/dist/cjs/types/index.d.ts +2 -2
  89. package/dist/cjs/types/tables.d.ts +17 -1
  90. package/dist/cjs/upload/index.js +89 -24
  91. package/dist/cjs/upload/index.test.js +104 -1
  92. package/dist/cjs/vite/domTagNames.js +252 -252
  93. package/dist/cjs/vite/index.d.ts +1 -1
  94. package/dist/cjs/vite/index.js +46 -42
  95. package/dist/esm/auth/actions.d.ts +28 -0
  96. package/dist/esm/auth/actions.js +55 -0
  97. package/dist/esm/auth/client.d.ts +357 -0
  98. package/dist/esm/auth/client.js +62 -0
  99. package/dist/esm/auth/config.js +9 -3
  100. package/dist/esm/auth/index.d.ts +2 -249
  101. package/dist/esm/auth/index.js +2 -103
  102. package/dist/esm/auth/index.test.js +60 -0
  103. package/dist/esm/auth/previewClaim.d.ts +7 -0
  104. package/dist/esm/auth/previewClaim.js +12 -0
  105. package/dist/esm/auth/profileUpdates.d.ts +9 -0
  106. package/dist/esm/auth/profileUpdates.js +6 -0
  107. package/dist/esm/backend/index.d.ts +15 -9
  108. package/dist/esm/backend/index.js +13 -13
  109. package/dist/esm/backend/index.test.js +106 -106
  110. package/dist/esm/bundle/index.d.ts +8 -0
  111. package/dist/esm/bundle/index.js +37 -24
  112. package/dist/esm/caller/index.js +44 -44
  113. package/dist/esm/check/index.d.ts +44 -1
  114. package/dist/esm/check/index.js +187 -116
  115. package/dist/esm/check/start/routeTree.d.ts +8 -0
  116. package/dist/esm/check/start/routeTree.js +77 -0
  117. package/dist/esm/check/start/tsgo.d.ts +2 -0
  118. package/dist/esm/check/start/tsgo.js +29 -0
  119. package/dist/esm/cli.js +10 -4
  120. package/dist/esm/client/index.d.ts +26 -2
  121. package/dist/esm/client/index.js +25 -25
  122. package/dist/esm/dev/index.js +86 -61
  123. package/dist/esm/dev/signin.d.ts +16 -0
  124. package/dist/esm/dev/signin.js +80 -0
  125. package/dist/esm/index.d.ts +5 -5
  126. package/dist/esm/index.js +3 -3
  127. package/dist/esm/integrations/client.d.ts +3 -3
  128. package/dist/esm/integrations/client.js +6 -5
  129. package/dist/esm/integrations/client.test-d.js +19 -19
  130. package/dist/esm/integrations/index.d.ts +2 -2
  131. package/dist/esm/integrations/index.js +1 -1
  132. package/dist/esm/integrations/rules.d.ts +1 -0
  133. package/dist/esm/integrations/rules.js +48 -43
  134. package/dist/esm/integrations/rules.test.js +62 -56
  135. package/dist/esm/internal/appMode.d.ts +14 -0
  136. package/dist/esm/internal/appMode.js +13 -0
  137. package/dist/esm/internal/env.js +3 -2
  138. package/dist/esm/internal/platformFetch.d.ts +2 -0
  139. package/dist/esm/internal/platformFetch.js +9 -0
  140. package/dist/esm/internal/reservedIds.d.ts +8 -0
  141. package/dist/esm/internal/reservedIds.js +10 -0
  142. package/dist/esm/internal/serviceUrls.d.ts +5 -0
  143. package/dist/esm/internal/serviceUrls.js +10 -0
  144. package/dist/esm/pdf/index.js +2 -1
  145. package/dist/esm/runtime/filterConditionTypes.test-d.js +12 -12
  146. package/dist/esm/runtime/index.d.ts +126 -39
  147. package/dist/esm/runtime/index.js +35 -29
  148. package/dist/esm/runtime/index.test.js +36 -36
  149. package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
  150. package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +48 -0
  151. package/dist/esm/runtime/writeResultTypes.test-d.js +9 -9
  152. package/dist/esm/signin/conformance.d.ts +100 -0
  153. package/dist/esm/signin/conformance.js +616 -0
  154. package/dist/esm/signin/cookies.d.ts +28 -0
  155. package/dist/esm/signin/cookies.js +67 -0
  156. package/dist/esm/signin/encoding.d.ts +1 -0
  157. package/dist/esm/signin/encoding.js +12 -0
  158. package/dist/esm/signin/endpoints.d.ts +12 -0
  159. package/dist/esm/signin/endpoints.js +32 -0
  160. package/dist/esm/signin/http.d.ts +25 -0
  161. package/dist/esm/signin/http.js +106 -0
  162. package/dist/esm/signin/index.d.ts +8 -0
  163. package/dist/esm/signin/index.js +9 -0
  164. package/dist/esm/signin/keys.d.ts +35 -0
  165. package/dist/esm/signin/keys.js +230 -0
  166. package/dist/esm/signin/paths.d.ts +2 -0
  167. package/dist/esm/signin/paths.js +5 -0
  168. package/dist/esm/signin/seal.d.ts +19 -0
  169. package/dist/esm/signin/seal.js +47 -0
  170. package/dist/esm/signin/signin.d.ts +60 -0
  171. package/dist/esm/signin/signin.js +447 -0
  172. package/dist/esm/signin/transport.d.ts +112 -0
  173. package/dist/esm/signin/transport.js +1 -0
  174. package/dist/esm/signin/verifier.d.ts +2 -0
  175. package/dist/esm/signin/verifier.js +4 -0
  176. package/dist/esm/signin/verify.d.ts +83 -0
  177. package/dist/esm/signin/verify.js +142 -0
  178. package/dist/esm/sourceRoots.js +17 -17
  179. package/dist/esm/sourceRoots.test.js +34 -32
  180. package/dist/esm/start/access.d.ts +19 -0
  181. package/dist/esm/start/access.js +43 -0
  182. package/dist/esm/start/auth.d.ts +28 -0
  183. package/dist/esm/start/auth.js +33 -0
  184. package/dist/esm/start/automations/quiet.d.ts +2 -0
  185. package/dist/esm/start/automations/quiet.js +36 -0
  186. package/dist/esm/start/{registration.d.ts → automations/registration.d.ts} +1 -1
  187. package/dist/esm/start/{registration.js → automations/registration.js} +11 -7
  188. package/dist/esm/start/automations/steps.d.ts +29 -0
  189. package/dist/esm/start/automations/steps.js +95 -0
  190. package/dist/esm/start/automations/workflow.d.ts +83 -0
  191. package/dist/esm/start/automations/workflow.js +36 -0
  192. package/dist/esm/start/automations/workflow.test-d.d.ts +1 -0
  193. package/dist/esm/start/automations/workflow.test-d.js +130 -0
  194. package/dist/esm/start/automations/workflowRun.d.ts +130 -0
  195. package/dist/esm/start/automations/workflowRun.js +185 -0
  196. package/dist/esm/start/barrel.test-d.d.ts +10 -0
  197. package/dist/esm/start/barrel.test-d.js +6 -0
  198. package/dist/esm/start/{entries.d.ts → build/entries.d.ts} +9 -4
  199. package/dist/esm/start/{entries.js → build/entries.js} +38 -22
  200. package/dist/esm/start/build/placeholders/devApp.d.ts +1 -0
  201. package/dist/esm/start/build/placeholders/devApp.js +3 -0
  202. package/dist/esm/start/build/placeholders/devSignIn.d.ts +1 -0
  203. package/dist/esm/start/build/placeholders/devSignIn.js +3 -0
  204. package/dist/esm/start/build/placeholders/siteHead.d.ts +2 -0
  205. package/dist/esm/start/build/placeholders/siteHead.js +3 -0
  206. package/dist/esm/start/{workflowModules.js → build/placeholders/workflowModules.js} +1 -1
  207. package/dist/esm/start/build/placeholders/workspaceSchema.d.ts +2 -0
  208. package/dist/esm/start/build/placeholders/workspaceSchema.js +3 -0
  209. package/dist/esm/start/build/registrationHash.d.ts +11 -0
  210. package/dist/esm/start/build/registrationHash.js +88 -0
  211. package/dist/esm/start/build/sdk/axios.d.ts +76 -0
  212. package/dist/esm/start/build/sdk/axios.js +253 -0
  213. package/dist/esm/start/build/sdk/nodeFetch.d.ts +41 -0
  214. package/dist/esm/start/build/sdk/nodeFetch.js +35 -0
  215. package/dist/esm/start/build/sdk/undici.d.ts +34 -0
  216. package/dist/esm/start/build/sdk/undici.js +18 -0
  217. package/dist/esm/start/build/sdkPatches.d.ts +22 -0
  218. package/dist/esm/start/build/sdkPatches.js +430 -0
  219. package/dist/esm/start/build/siteHead.d.ts +26 -0
  220. package/dist/esm/start/build/siteHead.js +88 -0
  221. package/dist/esm/start/build/vite.d.ts +50 -0
  222. package/dist/esm/start/build/vite.js +487 -0
  223. package/dist/esm/start/classicOnly.d.ts +1 -0
  224. package/dist/esm/start/classicOnly.js +4 -0
  225. package/dist/esm/start/describe/describe.d.ts +120 -0
  226. package/dist/esm/start/describe/describe.js +372 -0
  227. package/dist/{cjs/start → esm/start/describe}/describeBuilt.d.ts +2 -0
  228. package/dist/esm/start/describe/describeBuilt.js +102 -0
  229. package/dist/esm/start/{descriptions.js → describe/descriptions.js} +17 -10
  230. package/dist/esm/start/errors.d.ts +20 -4
  231. package/dist/esm/start/errors.js +90 -26
  232. package/dist/esm/start/errors.test.js +47 -16
  233. package/dist/esm/start/factories.d.ts +14 -0
  234. package/dist/esm/start/factories.js +23 -0
  235. package/dist/esm/start/factories.test-d.d.ts +2 -0
  236. package/dist/esm/start/factories.test-d.js +60 -0
  237. package/dist/esm/start/failures.d.ts +7 -0
  238. package/dist/esm/start/failures.js +62 -0
  239. package/dist/esm/start/fnFactory.d.ts +16 -0
  240. package/dist/esm/start/fnFactory.js +1 -0
  241. package/dist/esm/start/host.d.ts +2 -2
  242. package/dist/esm/start/host.js +3 -3
  243. package/dist/esm/start/index.d.ts +10 -63
  244. package/dist/esm/start/index.js +7 -149
  245. package/dist/esm/start/login.d.ts +5 -0
  246. package/dist/esm/start/login.js +29 -0
  247. package/dist/esm/start/middlewareKind.d.ts +13 -0
  248. package/dist/esm/start/middlewareKind.js +9 -0
  249. package/dist/esm/start/platform/aiUsage.d.ts +29 -0
  250. package/dist/esm/start/platform/aiUsage.js +210 -0
  251. package/dist/esm/start/platform/airtable/built.d.ts +2 -0
  252. package/dist/esm/start/platform/airtable/built.js +3 -0
  253. package/dist/esm/start/platform/airtable/cache.d.ts +17 -0
  254. package/dist/esm/start/platform/airtable/cache.js +89 -0
  255. package/dist/esm/start/{airtable → platform/airtable}/dispatch.d.ts +5 -2
  256. package/dist/esm/start/{airtable → platform/airtable}/dispatch.js +195 -119
  257. package/dist/esm/start/{airtable → platform/airtable}/formulas.d.ts +2 -1
  258. package/dist/esm/start/{airtable → platform/airtable}/formulas.js +51 -25
  259. package/dist/esm/start/platform/airtable/index.d.ts +6 -0
  260. package/dist/esm/start/platform/airtable/index.js +51 -0
  261. package/dist/esm/start/platform/airtable/settings.d.ts +37 -0
  262. package/dist/esm/start/platform/airtable/settings.js +138 -0
  263. package/dist/esm/start/platform/analytics.d.ts +3 -0
  264. package/dist/esm/start/platform/analytics.js +59 -0
  265. package/dist/esm/start/platform/calls.d.ts +5 -0
  266. package/dist/esm/start/platform/calls.js +104 -0
  267. package/dist/esm/start/platform/caps.d.ts +9 -0
  268. package/dist/esm/start/platform/caps.js +35 -0
  269. package/dist/esm/start/platform/connections.d.ts +25 -0
  270. package/dist/esm/start/platform/connections.js +198 -0
  271. package/dist/esm/start/{data → platform/data}/baseRunner.d.ts +11 -6
  272. package/dist/esm/start/platform/data/baseRunner.js +117 -0
  273. package/dist/esm/start/{data → platform/data}/dispatch.d.ts +3 -2
  274. package/dist/esm/start/{data → platform/data}/dispatch.js +69 -51
  275. package/dist/esm/start/platform/data/fetch.d.ts +7 -0
  276. package/dist/esm/start/platform/data/fetch.js +9 -0
  277. package/dist/esm/start/platform/data/index.d.ts +27 -0
  278. package/dist/esm/start/platform/data/index.js +75 -0
  279. package/dist/esm/start/platform/data/names.d.ts +7 -0
  280. package/dist/esm/start/platform/data/names.js +18 -0
  281. package/dist/esm/start/{data → platform/data}/transformations.d.ts +0 -31
  282. package/dist/esm/start/{data → platform/data}/transformations.js +0 -56
  283. package/dist/esm/start/{data → platform/data}/types.d.ts +4 -1
  284. package/dist/esm/start/{data → platform/data}/types.js +2 -2
  285. package/dist/esm/start/platform/local.d.ts +6 -0
  286. package/dist/esm/start/platform/local.js +18 -0
  287. package/dist/esm/start/platform/meta.d.ts +3 -0
  288. package/dist/esm/start/platform/meta.js +33 -0
  289. package/dist/esm/start/platform/outbound.d.ts +17 -0
  290. package/dist/esm/start/platform/outbound.js +510 -0
  291. package/dist/esm/start/platform/redactSecrets.d.ts +13 -0
  292. package/dist/esm/start/{redactSecrets.js → platform/redactSecrets.js} +32 -7
  293. package/dist/esm/start/platform/redactSecrets.test.d.ts +1 -0
  294. package/dist/esm/start/platform/requestSecrets.d.ts +15 -0
  295. package/dist/esm/start/platform/requestSecrets.js +41 -0
  296. package/dist/esm/start/platform/runLog.d.ts +40 -0
  297. package/dist/esm/start/platform/runLog.js +149 -0
  298. package/dist/esm/start/platform/services.d.ts +7 -0
  299. package/dist/esm/start/platform/services.js +46 -0
  300. package/dist/esm/start/platform/steps.d.ts +9 -0
  301. package/dist/esm/start/platform/steps.js +60 -0
  302. package/dist/esm/start/platform/telemetry.d.ts +13 -0
  303. package/dist/esm/start/platform/telemetry.js +71 -0
  304. package/dist/esm/start/platform/transport.d.ts +28 -0
  305. package/dist/esm/start/platform/transport.js +59 -0
  306. package/dist/esm/start/platformHead.d.ts +23 -0
  307. package/dist/esm/start/platformHead.js +133 -0
  308. package/dist/esm/start/previewClaim.d.ts +3 -7
  309. package/dist/esm/start/previewClaim.js +9 -17
  310. package/dist/esm/start/protocol.d.ts +19 -0
  311. package/dist/esm/start/protocol.js +27 -0
  312. package/dist/esm/start/roles.d.ts +12 -0
  313. package/dist/esm/start/roles.js +27 -0
  314. package/dist/esm/start/router.d.ts +28 -4
  315. package/dist/esm/start/router.js +224 -21
  316. package/dist/esm/start/serve/authHooks.js +18 -0
  317. package/dist/esm/start/serve/demo.d.ts +9 -0
  318. package/dist/esm/start/serve/demo.js +24 -0
  319. package/dist/esm/start/serve/fetch.d.ts +1 -0
  320. package/dist/esm/start/serve/fetch.js +6 -0
  321. package/dist/esm/start/{instance.d.ts → serve/instance.d.ts} +6 -5
  322. package/dist/esm/start/serve/instance.js +134 -0
  323. package/dist/esm/start/serve/invoke.d.ts +13 -0
  324. package/dist/esm/start/serve/invoke.js +126 -0
  325. package/dist/esm/start/serve/local/load.d.ts +8 -0
  326. package/dist/esm/start/serve/local/load.js +44 -0
  327. package/dist/esm/start/serve/local/provider.d.ts +25 -0
  328. package/dist/esm/start/serve/local/provider.js +188 -0
  329. package/dist/esm/start/serve/local/signIn.d.ts +28 -0
  330. package/dist/esm/start/serve/local/signIn.js +123 -0
  331. package/dist/esm/start/serve/pageHead.d.ts +20 -0
  332. package/dist/esm/start/serve/pageHead.js +34 -0
  333. package/dist/esm/start/serve/provider.d.ts +19 -0
  334. package/dist/esm/start/serve/provider.js +78 -0
  335. package/dist/esm/start/serve/requestEnv.d.ts +2 -0
  336. package/dist/esm/start/serve/requestEnv.js +84 -0
  337. package/dist/esm/start/serve/scope.d.ts +18 -0
  338. package/dist/esm/start/serve/scope.js +67 -0
  339. package/dist/esm/start/serve/server.d.ts +56 -0
  340. package/dist/esm/start/serve/server.js +297 -0
  341. package/dist/esm/start/serve/uploads.d.ts +2 -0
  342. package/dist/esm/start/serve/uploads.js +49 -0
  343. package/dist/esm/start/serve/worker.d.ts +6 -0
  344. package/dist/esm/start/serve/worker.js +12 -0
  345. package/dist/esm/start/types.d.ts +270 -56
  346. package/dist/esm/start/version.d.ts +1 -1
  347. package/dist/esm/start/version.js +1 -1
  348. package/dist/esm/steps/index.d.ts +78 -0
  349. package/dist/esm/steps/index.js +502 -0
  350. package/dist/esm/steps/index.test.d.ts +1 -0
  351. package/dist/esm/steps/index.test.js +633 -0
  352. package/dist/esm/sync/index.d.ts +1 -1
  353. package/dist/esm/sync/index.js +32 -31
  354. package/dist/esm/sync/lib.d.ts +15 -8
  355. package/dist/esm/sync/lib.js +659 -659
  356. package/dist/esm/sync/lib.test.js +177 -46
  357. package/dist/esm/sync/sdkNames.d.ts +67 -9
  358. package/dist/esm/sync/sdkNames.js +94 -30
  359. package/dist/esm/sync/sdkNames.test.js +192 -116
  360. package/dist/esm/types/fields.d.ts +9 -2
  361. package/dist/esm/types/fields.js +110 -96
  362. package/dist/esm/types/index.d.ts +2 -2
  363. package/dist/esm/types/index.js +2 -2
  364. package/dist/esm/types/tables.d.ts +17 -1
  365. package/dist/esm/types/tables.js +2 -2
  366. package/dist/esm/upload/index.js +89 -24
  367. package/dist/esm/upload/index.test.js +104 -1
  368. package/dist/esm/vite/domTagNames.js +252 -252
  369. package/dist/esm/vite/index.d.ts +1 -1
  370. package/dist/esm/vite/index.js +51 -47
  371. package/package.json +95 -37
  372. package/dist/cjs/auth-server/index.d.ts +0 -369
  373. package/dist/cjs/auth-server/index.js +0 -119
  374. package/dist/cjs/start/problems.d.ts +0 -19
  375. package/dist/cjs/start/problems.js +0 -11
  376. package/dist/esm/auth-server/index.d.ts +0 -369
  377. package/dist/esm/auth-server/index.js +0 -116
  378. package/dist/esm/start/airtable/index.d.ts +0 -11
  379. package/dist/esm/start/airtable/index.js +0 -70
  380. package/dist/esm/start/authHooks.js +0 -10
  381. package/dist/esm/start/data/baseRunner.js +0 -83
  382. package/dist/esm/start/data/index.d.ts +0 -18
  383. package/dist/esm/start/data/index.js +0 -76
  384. package/dist/esm/start/describe.d.ts +0 -80
  385. package/dist/esm/start/describe.js +0 -197
  386. package/dist/esm/start/describeBuilt.js +0 -66
  387. package/dist/esm/start/instance.js +0 -80
  388. package/dist/esm/start/problems.d.ts +0 -19
  389. package/dist/esm/start/problems.js +0 -8
  390. package/dist/esm/start/redactSecrets.d.ts +0 -7
  391. package/dist/esm/start/runLog.d.ts +0 -8
  392. package/dist/esm/start/runLog.js +0 -76
  393. package/dist/esm/start/scope.d.ts +0 -15
  394. package/dist/esm/start/scope.js +0 -58
  395. package/dist/esm/start/server.d.ts +0 -55
  396. package/dist/esm/start/server.js +0 -317
  397. package/dist/esm/start/vite.d.ts +0 -9
  398. package/dist/esm/start/vite.js +0 -173
  399. package/dist/esm/start/worker.d.ts +0 -11
  400. package/dist/esm/start/worker.js +0 -20
  401. package/dist/esm/start/workflow.d.ts +0 -50
  402. package/dist/esm/start/workflow.js +0 -13
  403. package/dist/esm/start/workflow.test-d.js +0 -39
  404. package/dist/esm/start/workflowRun.d.ts +0 -80
  405. package/dist/esm/start/workflowRun.js +0 -108
  406. /package/dist/{esm/start/redactSecrets.test.d.ts → cjs/runtime/sendEmailParamsTypes.test-d.d.ts} +0 -0
  407. /package/dist/{esm/start/workflow.test-d.d.ts → cjs/steps/index.test.d.ts} +0 -0
  408. /package/dist/esm/start/{authHooksModule.d.ts → build/placeholders/authHooksModule.d.ts} +0 -0
  409. /package/dist/esm/start/{authHooksModule.js → build/placeholders/authHooksModule.js} +0 -0
  410. /package/dist/esm/start/{workflowModules.d.ts → build/placeholders/workflowModules.d.ts} +0 -0
  411. /package/dist/esm/start/{descriptions.d.ts → describe/descriptions.d.ts} +0 -0
  412. /package/dist/esm/start/{airtable → platform/airtable}/arrayFields.d.ts +0 -0
  413. /package/dist/esm/start/{airtable → platform/airtable}/arrayFields.js +0 -0
  414. /package/dist/esm/start/{data → platform/data}/sqlNameMappings.d.ts +0 -0
  415. /package/dist/esm/start/{data → platform/data}/sqlNameMappings.js +0 -0
  416. /package/dist/esm/start/{redactSecrets.test.js → platform/redactSecrets.test.js} +0 -0
  417. /package/dist/esm/start/{authHooks.d.ts → serve/authHooks.d.ts} +0 -0
@@ -0,0 +1,67 @@
1
+ // The module's cookies (T5 design §3.2). Byte-exact: names and values are never URL-decoded.
2
+ export const MODULE_COOKIES = {
3
+ /** The identity token. */
4
+ identity: 'zite_id',
5
+ /** One sign-in's state, PKCE verifier, nonce and return path. */
6
+ flow: 'zite_signin',
7
+ /** Off Zite only: the sealed refresh token. */
8
+ session: 'zite_session',
9
+ };
10
+ /** `__Host-` over https, so no sibling host can set or shadow it; plain on http://localhost, which can't hold one. */
11
+ export const cookieName = (cookie, secure) => secure ? `__Host-${MODULE_COOKIES[cookie]}` : MODULE_COOKIES[cookie];
12
+ const MODULE_COOKIE_NAME = /^(?:__host-)?zite_(?:id|signin|session)$/i;
13
+ export const isModuleCookie = (name) => MODULE_COOKIE_NAME.test(name);
14
+ // A framed preview is cross-site to the editor around it, so its cookies are SameSite=None and Partitioned to survive
15
+ // there. Lax everywhere else: the return leg through Google and the backend is a cross-site redirect chain, where
16
+ // Strict isn't sent.
17
+ const attributes = ({ secure, framed }, maxAge) => {
18
+ const crossSite = framed && secure;
19
+ return [
20
+ 'Path=/',
21
+ `Max-Age=${Math.max(Math.floor(maxAge), 0)}`,
22
+ 'HttpOnly',
23
+ crossSite ? 'SameSite=None' : 'SameSite=Lax',
24
+ ...(secure ? ['Secure'] : []),
25
+ ...(crossSite ? ['Partitioned'] : []),
26
+ ].join('; ');
27
+ };
28
+ export const setCookie = (cookie, value, context, maxAgeS) => `${cookieName(cookie, context.secure)}=${value}; ${attributes(context, maxAgeS)}`;
29
+ export const clearCookie = (cookie, context) => `${cookieName(cookie, context.secure)}=; ${attributes(context, 0)}`;
30
+ const pairsOf = (header) => (header ?? '')
31
+ .split(';')
32
+ .map(pair => pair.trim())
33
+ .filter(Boolean)
34
+ .map(pair => {
35
+ const eq = pair.indexOf('=');
36
+ return {
37
+ name: (eq === -1 ? pair : pair.slice(0, eq)).trim(),
38
+ value: eq === -1 ? '' : pair.slice(eq + 1).trim(),
39
+ pair,
40
+ };
41
+ });
42
+ /**
43
+ * The cookies sent once. A name sent twice is dropped: which copy wins differs between parsers, and that difference
44
+ * is how one cookie shadows another.
45
+ */
46
+ export const readCookies = (header) => {
47
+ const pairs = pairsOf(header);
48
+ const counts = new Map();
49
+ for (const { name } of pairs)
50
+ counts.set(name, (counts.get(name) ?? 0) + 1);
51
+ return new Map(pairs
52
+ .filter(({ name }) => counts.get(name) === 1)
53
+ .map(({ name, value }) => [name, value]));
54
+ };
55
+ /** The pairs of `header` whose names match, sent once each, as a Cookie header; null for none. */
56
+ export const cookiePairs = (header, names) => {
57
+ const sent = readCookies(header);
58
+ const kept = [...sent]
59
+ .filter(([name]) => names.test(name))
60
+ .map(([name, value]) => `${name}=${value}`);
61
+ return kept.length > 0 ? kept.join('; ') : null;
62
+ };
63
+ /** `header` without the pairs `drop` names; null when nothing is left. */
64
+ export const withoutCookies = (header, drop) => {
65
+ const kept = pairsOf(header).filter(({ name }) => !drop(name));
66
+ return kept.length > 0 ? kept.map(({ pair }) => pair).join('; ') : null;
67
+ };
@@ -0,0 +1 @@
1
+ export declare const canonicalBytes: (value: string) => Uint8Array | undefined;
@@ -0,0 +1,12 @@
1
+ import { base64url } from 'jose';
2
+ // jose decodes base64url as loosely as atob, which ignores a last character's unused bits: without the round trip one
3
+ // value would have several spellings.
4
+ export const canonicalBytes = (value) => {
5
+ try {
6
+ const bytes = base64url.decode(value);
7
+ return base64url.encode(bytes) === value ? bytes : undefined;
8
+ }
9
+ catch {
10
+ return undefined;
11
+ }
12
+ };
@@ -0,0 +1,12 @@
1
+ /** https, or plain http on a loopback host (a local stack, or a test's issuer). */
2
+ export declare const isServedUrl: (url: URL) => boolean;
3
+ /** The issuer's origin; throws for anything that isn't `https://<host>/auth`. */
4
+ export declare const issuerOrigin: (issuer: string) => string;
5
+ /** Where Zite's identity server answers for an issuer: better-auth's base path stays `/api/auth` (T5 design §2). */
6
+ export declare const ziteEndpoints: (issuer: string) => {
7
+ authorize: string;
8
+ token: string;
9
+ endSession: string;
10
+ revocation: string;
11
+ signInPage: string;
12
+ };
@@ -0,0 +1,32 @@
1
+ // `.localhost` names are loopback (RFC 6761): a local stack serves each app on its own `<app>.localhost`.
2
+ const LOOPBACK = /^(?:(?:[a-z0-9-]+\.)*localhost|127\.0\.0\.1|\[::1\])$/i;
3
+ /** https, or plain http on a loopback host (a local stack, or a test's issuer). */
4
+ export const isServedUrl = (url) => !url.username &&
5
+ !url.password &&
6
+ (url.protocol === 'https:' ||
7
+ (url.protocol === 'http:' && LOOPBACK.test(url.hostname)));
8
+ /** The issuer's origin; throws for anything that isn't `https://<host>/auth`. */
9
+ export const issuerOrigin = (issuer) => {
10
+ let url;
11
+ try {
12
+ url = new URL(issuer);
13
+ }
14
+ catch {
15
+ throw new Error(`The sign-in issuer ${issuer} isn't a URL`);
16
+ }
17
+ if (!isServedUrl(url) || url.pathname !== '/auth' || url.search || url.hash) {
18
+ throw new Error(`The sign-in issuer must be https://<host>/auth, not ${issuer}`);
19
+ }
20
+ return url.origin;
21
+ };
22
+ /** Where Zite's identity server answers for an issuer: better-auth's base path stays `/api/auth` (T5 design §2). */
23
+ export const ziteEndpoints = (issuer) => {
24
+ const origin = issuerOrigin(issuer);
25
+ return {
26
+ authorize: `${origin}/api/auth/oauth2/authorize`,
27
+ token: `${origin}/api/auth/oauth2/token`,
28
+ endSession: `${origin}/api/auth/oauth2/end-session`,
29
+ revocation: `${origin}/api/auth/oauth2/revoke`,
30
+ signInPage: `${origin}/auth/sign-in`,
31
+ };
32
+ };
@@ -0,0 +1,25 @@
1
+ import type { Sealer } from './seal.js';
2
+ import type { Transport } from './transport.js';
3
+ /** `none` for `<app>:dev` (PKCE and a loopback redirect); a secret, or later a private key JWT, for a hosted client. */
4
+ export type ClientAuth = {
5
+ kind: 'none';
6
+ } | {
7
+ kind: 'secret';
8
+ secret: string;
9
+ };
10
+ export type HttpTransportOptions = {
11
+ issuer: string;
12
+ clientId: string;
13
+ clientAuth?: ClientAuth;
14
+ /** Seals the refresh token into the module's session cookie. */
15
+ sealer: Sealer;
16
+ /** Overrides for endpoints other than Zite's layout. */
17
+ endpoints?: Partial<{
18
+ token: string;
19
+ endSession: string;
20
+ revocation: string;
21
+ }>;
22
+ fetch?: (request: Request) => Promise<Response>;
23
+ timeoutMs?: number;
24
+ };
25
+ export declare const httpTransport: (options: HttpTransportOptions) => Transport;
@@ -0,0 +1,106 @@
1
+ // Standard OIDC to the identity server's public endpoints, for the module off Zite (T5 design §3.1, §5.9).
2
+ import * as oauth from 'oauth4webapi';
3
+ import { ziteEndpoints } from './endpoints.js';
4
+ const DEFAULT_TIMEOUT_MS = 10_000;
5
+ export const httpTransport = (options) => {
6
+ const endpoints = { ...ziteEndpoints(options.issuer), ...options.endpoints };
7
+ const as = {
8
+ issuer: options.issuer,
9
+ token_endpoint: endpoints.token,
10
+ revocation_endpoint: endpoints.revocation,
11
+ end_session_endpoint: endpoints.endSession,
12
+ };
13
+ const client = {
14
+ client_id: options.clientId,
15
+ id_token_signed_response_alg: 'EdDSA',
16
+ };
17
+ const auth = options.clientAuth?.kind === 'secret'
18
+ ? oauth.ClientSecretBasic(options.clientAuth.secret)
19
+ : oauth.None();
20
+ const send = options.fetch ?? ((request) => fetch(request));
21
+ const timeout = () => AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
22
+ const http = {
23
+ // The issuer is https, or http on a loopback host: `ziteEndpoints` refuses anything else.
24
+ [oauth.allowInsecureRequests]: new URL(options.issuer).protocol === 'http:',
25
+ [oauth.customFetch]: (url, init) => send(new Request(url, init)),
26
+ signal: timeout,
27
+ };
28
+ const unanswered = (url, error) => console.error(`[zite] the identity server at ${url} didn't answer`, error);
29
+ return {
30
+ longLived: { kind: 'refresh-token', sealer: options.sealer },
31
+ async exchange({ code, verifier, redirectUri, nonce, }) {
32
+ try {
33
+ // The callback's state and issuer were checked where it arrived; oauth4webapi takes a code only from its own check.
34
+ const callback = oauth.validateAuthResponse(as, client, new URLSearchParams({ code }), oauth.skipStateCheck);
35
+ const response = await oauth.authorizationCodeGrantRequest(as, client, auth, callback, redirectUri, verifier, http);
36
+ const { id_token: idToken, refresh_token: refreshToken } = await oauth.processAuthorizationCodeResponse(as, client, response, {
37
+ expectedNonce: nonce,
38
+ });
39
+ return idToken
40
+ ? { kind: 'issued', idToken, refreshToken }
41
+ : { kind: 'failed', error: 'no id_token' };
42
+ }
43
+ catch (error) {
44
+ return {
45
+ kind: 'failed',
46
+ error: error instanceof oauth.ResponseBodyError
47
+ ? error.error
48
+ : String(error),
49
+ };
50
+ }
51
+ },
52
+ async renew({ longLived }) {
53
+ try {
54
+ const response = await oauth.refreshTokenGrantRequest(as, client, auth, longLived, http);
55
+ const { id_token: idToken, refresh_token: refreshToken } = await oauth.processRefreshTokenResponse(as, client, response);
56
+ return idToken
57
+ ? { kind: 'renewed', idToken, refreshToken }
58
+ : { kind: 'signed-out', code: 'no id_token' };
59
+ }
60
+ catch (error) {
61
+ // Only the token endpoint's own refusals (RFC 6749 §5.2) end the session; a busy or broken server doesn't.
62
+ if (error instanceof oauth.ResponseBodyError &&
63
+ [400, 401].includes(error.status))
64
+ return { kind: 'signed-out', code: error.error };
65
+ if (error instanceof oauth.WWWAuthenticateChallengeError &&
66
+ error.status === 401)
67
+ return { kind: 'signed-out', code: 'invalid_client' };
68
+ unanswered(endpoints.token, error);
69
+ return { kind: 'unavailable' };
70
+ }
71
+ },
72
+ // This device only: the refresh token is revoked, and the identity server's session ends when it can match the
73
+ // hint. A refresh token elsewhere is the identity server's to revoke.
74
+ async endSession({ longLived, idToken }) {
75
+ const revoke = async (token) => oauth.processRevocationResponse(await oauth.revocationRequest(as, client, auth, token, {
76
+ ...http,
77
+ additionalParameters: { token_type_hint: 'refresh_token' },
78
+ }));
79
+ // RP-Initiated Logout from the server, which oauth4webapi has no call for.
80
+ const end = async (hint) => {
81
+ const body = new URLSearchParams({
82
+ id_token_hint: hint,
83
+ client_id: options.clientId,
84
+ });
85
+ await send(new Request(endpoints.endSession, {
86
+ method: 'POST',
87
+ headers: { accept: 'application/json' },
88
+ body,
89
+ signal: timeout(),
90
+ }));
91
+ };
92
+ await Promise.all([
93
+ longLived
94
+ ? revoke(longLived).catch((error) => unanswered(endpoints.revocation, error))
95
+ : undefined,
96
+ idToken
97
+ ? end(idToken).catch((error) => unanswered(endpoints.endSession, error))
98
+ : undefined,
99
+ ]);
100
+ return {};
101
+ },
102
+ async updateProfile() {
103
+ return { kind: 'unsupported' };
104
+ },
105
+ };
106
+ };
@@ -0,0 +1,8 @@
1
+ export { createSignIn, isSignInPath, PREVIEW_IDENTITY_HEADER, PREVIEW_IDENTITY_PARAM, type Resolution, type SignIn, type SignInConfig, } from './signin.js';
2
+ export * from './verifier.js';
3
+ export { discoveredIdentityKeys, remoteIdentityKeys } from './keys.js';
4
+ export { clearCookie, cookieName, isModuleCookie, MODULE_COOKIES, type CookieContext, type ModuleCookie, } from './cookies.js';
5
+ export { aesGcmSealer, type SealedSession, type Sealer } from './seal.js';
6
+ export { httpTransport, type ClientAuth, type HttpTransportOptions, } from './http.js';
7
+ export { ziteEndpoints } from './endpoints.js';
8
+ export type { ExchangeOutcome, IdentityBinding, LongLived, PlatformTransportContext, PlatformTransportFactory, ProfileChanges, ProfileOutcome, RenewOutcome, RenewReason, Transport, } from './transport.js';
@@ -0,0 +1,9 @@
1
+ // `zitejs/signin`: Start's sign-in client. No TanStack, no `node:*`, Web Crypto only, so it runs in the dispatcher's
2
+ // bundle, in an app's Worker and on Node alike.
3
+ export { createSignIn, isSignInPath, PREVIEW_IDENTITY_HEADER, PREVIEW_IDENTITY_PARAM, } from './signin.js';
4
+ export * from './verifier.js';
5
+ export { discoveredIdentityKeys, remoteIdentityKeys } from './keys.js';
6
+ export { clearCookie, cookieName, isModuleCookie, MODULE_COOKIES, } from './cookies.js';
7
+ export { aesGcmSealer } from './seal.js';
8
+ export { httpTransport, } from './http.js';
9
+ export { ziteEndpoints } from './endpoints.js';
@@ -0,0 +1,35 @@
1
+ import { type CryptoKey, type JWSHeaderParameters } from 'jose';
2
+ /**
3
+ * The identity issuer's public keys by `kid`, each its raw Ed25519 key (base64url), as read from the issuer's JWK Set
4
+ * (RFC 7517): the dispatcher's `ZITE_IDENTITY_JWKS`, or the backend's `jwks_uri` off Zite.
5
+ */
6
+ export type IdentityKeys = Readonly<Record<string, string>>;
7
+ /**
8
+ * Where a verifier finds the key a token's header names, as jose's `jwtVerify` asks for it. It throws jose's
9
+ * `JWKSNoMatchingKey` for a `kid` it doesn't hold, and anything else when it has no keys to look in.
10
+ */
11
+ export type IdentityKeySource = (header: JWSHeaderParameters) => Promise<CryptoKey>;
12
+ /** An Ed25519 key's JWS `alg`: RFC 9864's `Ed25519`, or `EdDSA`, which the identity server signs with. */
13
+ export declare const ED25519_ALGS: readonly ["EdDSA", "Ed25519"];
14
+ /**
15
+ * Parses the identity issuer's JWK Set by the rule every verifier of it follows, restly's included. A key of a kind
16
+ * zitejs doesn't use (another `kty`, `crv` or `alg`) is skipped and logged, as RFC 7517 §5 has it. Anything else
17
+ * throws, so a bad deploy fails at once: a document that isn't a set, an Ed25519 key with a bad `x`, `kid` or `use`, a
18
+ * private member in any key, a `kid` two keys share, or no Ed25519 key at all.
19
+ */
20
+ export declare const identityKeys: (json: string) => IdentityKeys;
21
+ /** Keys that never change: the dispatcher's configured set. */
22
+ export declare const staticIdentityKeys: (keys: IdentityKeys) => IdentityKeySource;
23
+ /** How long a response may be held, in seconds, by its `Cache-Control` (RFC 9111 §5.2.2): its `max-age`, or none. */
24
+ export declare const maxAgeOf: (response: Response) => number;
25
+ type Fetch = (request: Request) => Promise<Response>;
26
+ type FetchOptions = {
27
+ fetch?: Fetch;
28
+ };
29
+ /** For tests: forget every fetched key set and discovery document. */
30
+ export declare const resetFetchedIdentityKeys: () => void;
31
+ /** Keys from the JWK Set at `url`, as {@link remoteKeySet} holds them. Make one per request. */
32
+ export declare const remoteIdentityKeys: (url: string, options?: FetchOptions) => IdentityKeySource;
33
+ /** Keys from the JWK Set `issuer`'s discovery document names, as {@link remoteIdentityKeys} holds them. */
34
+ export declare const discoveredIdentityKeys: (issuer: string, options?: FetchOptions) => IdentityKeySource;
35
+ export {};
@@ -0,0 +1,230 @@
1
+ import { createRemoteJWKSet, customFetch, errors, importJWK, jwksCache, } from 'jose';
2
+ import * as z from 'zod/mini';
3
+ import { canonicalBytes } from './encoding.js';
4
+ const KEY_SET_NAME = 'the identity JWK Set';
5
+ /** An Ed25519 key's JWS `alg`: RFC 9864's `Ed25519`, or `EdDSA`, which the identity server signs with. */
6
+ export const ED25519_ALGS = ['EdDSA', 'Ed25519'];
7
+ // RFC 7518 §6's private members, of every key type.
8
+ const PRIVATE_MEMBERS = ['d', 'p', 'q', 'dp', 'dq', 'qi', 'oth', 'k'];
9
+ const jwkSet = z.object({ keys: z.array(z.unknown()) });
10
+ const jwk = z.record(z.string(), z.unknown());
11
+ // The kind of key the identity server signs with; a set may hold others, for other clients.
12
+ const ed25519Kind = z.object({
13
+ kty: z.literal('OKP'),
14
+ crv: z.literal('Ed25519'),
15
+ alg: z.optional(z.enum(ED25519_ALGS)),
16
+ });
17
+ const X_PROBLEM = 'x must be a 32-byte key';
18
+ const KID_PROBLEM = 'kid must be 1 to 64 letters, digits, - or _';
19
+ // What's wrong with an Ed25519 key is an operator's typo, which fails at once, never skipped.
20
+ const ed25519Key = z.object({
21
+ use: z.optional(z.literal('sig', { error: 'use must be sig' })),
22
+ x: z
23
+ .string({ error: X_PROBLEM })
24
+ .check(z.refine(x => canonicalBytes(x)?.length === 32, { error: X_PROBLEM })),
25
+ kid: z
26
+ .string({ error: KID_PROBLEM })
27
+ .check(z.regex(/^[A-Za-z0-9_-]{1,64}$/, { error: KID_PROBLEM })),
28
+ });
29
+ // Each skipped key is logged once per process, and only so many: a fetched set is read again on every refetch.
30
+ const MAX_REPORTED_SKIPS = 32;
31
+ const reportedSkips = new Set();
32
+ const reportSkipped = (key) => {
33
+ const described = JSON.stringify({
34
+ kid: key.kid,
35
+ kty: key.kty,
36
+ crv: key.crv,
37
+ alg: key.alg,
38
+ });
39
+ if (reportedSkips.has(described) || reportedSkips.size >= MAX_REPORTED_SKIPS)
40
+ return;
41
+ reportedSkips.add(described);
42
+ console.warn(`[zite] skipped a key of another kind in ${KEY_SET_NAME}: ${described.slice(0, 256)}`);
43
+ };
44
+ const parsedJson = (json) => {
45
+ try {
46
+ return JSON.parse(json);
47
+ }
48
+ catch {
49
+ return undefined;
50
+ }
51
+ };
52
+ /**
53
+ * Parses the identity issuer's JWK Set by the rule every verifier of it follows, restly's included. A key of a kind
54
+ * zitejs doesn't use (another `kty`, `crv` or `alg`) is skipped and logged, as RFC 7517 §5 has it. Anything else
55
+ * throws, so a bad deploy fails at once: a document that isn't a set, an Ed25519 key with a bad `x`, `kid` or `use`, a
56
+ * private member in any key, a `kid` two keys share, or no Ed25519 key at all.
57
+ */
58
+ export const identityKeys = (json) => {
59
+ const set = jwkSet.safeParse(parsedJson(json));
60
+ if (!set.success)
61
+ throw new Error(`${KEY_SET_NAME} must be a JSON object with a keys array`);
62
+ // No prototype, so a `kid` of `__proto__` is a key like any other.
63
+ const keys = Object.create(null);
64
+ for (const [index, entry] of set.data.keys.entries()) {
65
+ const parsed = jwk.safeParse(entry);
66
+ const name = parsed.success && typeof parsed.data.kid === 'string'
67
+ ? parsed.data.kid.slice(0, 64)
68
+ : `#${index}`;
69
+ const fail = (problem) => new Error(`${KEY_SET_NAME}: key ${name}: ${problem}`);
70
+ if (!parsed.success)
71
+ throw fail('must be a JSON object');
72
+ if (PRIVATE_MEMBERS.some(member => Object.hasOwn(parsed.data, member)))
73
+ throw fail('holds a private key');
74
+ if (!ed25519Kind.safeParse(parsed.data).success) {
75
+ reportSkipped(parsed.data);
76
+ continue;
77
+ }
78
+ const key = ed25519Key.safeParse(parsed.data);
79
+ if (!key.success)
80
+ throw fail(key.error.issues[0]?.message ?? "isn't an Ed25519 key");
81
+ if (Object.hasOwn(keys, key.data.kid))
82
+ throw new Error(`${KEY_SET_NAME}: key ${key.data.kid} is in it twice`);
83
+ keys[key.data.kid] = key.data.x;
84
+ }
85
+ if (Object.keys(keys).length === 0)
86
+ throw new Error(`${KEY_SET_NAME} holds no Ed25519 key`);
87
+ return keys;
88
+ };
89
+ // Imported once per process; a CryptoKey holds no request's I/O.
90
+ const imported = new Map();
91
+ const publicKeyOf = async (x) => {
92
+ const held = imported.get(x);
93
+ if (held)
94
+ return held;
95
+ const key = await importJWK({ kty: 'OKP', crv: 'Ed25519', x }, 'Ed25519');
96
+ imported.set(x, key);
97
+ return key;
98
+ };
99
+ /** Keys that never change: the dispatcher's configured set. */
100
+ export const staticIdentityKeys = (keys) => async ({ kid }) => {
101
+ if (typeof kid !== 'string' || !Object.hasOwn(keys, kid))
102
+ throw new errors.JWKSNoMatchingKey();
103
+ return publicKeyOf(keys[kid]);
104
+ };
105
+ const REFETCH_EVERY_MS = 60_000;
106
+ const FETCH_TIMEOUT_MS = 5_000;
107
+ // What the backend sends, and how long a set is held when its response names no max-age.
108
+ const DEFAULT_MAX_AGE_S = 300;
109
+ /** How long a response may be held, in seconds, by its `Cache-Control` (RFC 9111 §5.2.2): its `max-age`, or none. */
110
+ export const maxAgeOf = (response) => {
111
+ const directives = (response.headers.get('cache-control') ?? '')
112
+ .toLowerCase()
113
+ .split(',')
114
+ .map(directive => directive.trim());
115
+ if (directives.includes('no-store') || directives.includes('no-cache'))
116
+ return 0;
117
+ const maxAge = directives
118
+ .map(directive => /^max-age=(\d+)$/.exec(directive)?.[1])
119
+ .find(value => value !== undefined);
120
+ return maxAge === undefined ? DEFAULT_MAX_AGE_S : Number(maxAge);
121
+ };
122
+ const getJson = (url, fetch = globalThis.fetch) => fetch(new Request(url, {
123
+ headers: { accept: 'application/json' },
124
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
125
+ }));
126
+ const fetched = new Map();
127
+ // Per process, each issuer's `jwks_uri`, once its discovery document named it.
128
+ const discovered = new Map();
129
+ /** For tests: forget every fetched key set and discovery document. */
130
+ export const resetFetchedIdentityKeys = () => {
131
+ fetched.clear();
132
+ discovered.clear();
133
+ };
134
+ const fetchedFor = (id) => {
135
+ let entry = fetched.get(id);
136
+ if (!entry)
137
+ fetched.set(id, (entry = { cache: {}, maxAgeMs: DEFAULT_MAX_AGE_S * 1000, retryAt: 0 }));
138
+ return entry;
139
+ };
140
+ /**
141
+ * jose's fetch of the set, with our rules on what comes back: jose gets only the Ed25519 keys, each without its `alg`,
142
+ * so it takes a token naming either. A fetch that fails, or a set the rules refuse, keeps what's held, which then holds
143
+ * for a minute before the next fetch.
144
+ */
145
+ const checkedFetch = (entry, fetch = globalThis.fetch) => async (url, init) => {
146
+ if (Date.now() >= entry.retryAt) {
147
+ try {
148
+ const response = await fetch(new Request(url, init));
149
+ if (!response.ok)
150
+ throw new Error(`${response.status}`);
151
+ const keys = identityKeys(await response.text());
152
+ entry.jwks = {
153
+ keys: Object.entries(keys).map(([kid, x]) => ({
154
+ kty: 'OKP',
155
+ crv: 'Ed25519',
156
+ kid,
157
+ x,
158
+ })),
159
+ };
160
+ entry.maxAgeMs = Math.max(maxAgeOf(response) * 1000, REFETCH_EVERY_MS);
161
+ }
162
+ catch (error) {
163
+ console.error(`[zite] couldn't fetch the identity keys from ${url}`, error);
164
+ entry.retryAt = Date.now() + REFETCH_EVERY_MS;
165
+ entry.maxAgeMs = REFETCH_EVERY_MS;
166
+ }
167
+ }
168
+ if (!entry.jwks)
169
+ throw new Error(`No identity keys from ${url}`);
170
+ return Response.json(entry.jwks);
171
+ };
172
+ /**
173
+ * jose's set over the keys at `url`, held per process under `id`: refetched once older than its response's `max-age`
174
+ * (five minutes without one, a minute at least), and on an unknown `kid` at most once a minute.
175
+ */
176
+ const remoteKeySet = (id, url, fetch) => {
177
+ const entry = fetchedFor(id);
178
+ return createRemoteJWKSet(new URL(url), {
179
+ timeoutDuration: FETCH_TIMEOUT_MS,
180
+ cacheMaxAge: entry.maxAgeMs,
181
+ cooldownDuration: REFETCH_EVERY_MS,
182
+ [jwksCache]: entry.cache,
183
+ [customFetch]: checkedFetch(entry, fetch),
184
+ });
185
+ };
186
+ /** Keys from the JWK Set at `url`, as {@link remoteKeySet} holds them. Make one per request. */
187
+ export const remoteIdentityKeys = (url, options = {}) => {
188
+ let keySet;
189
+ return async (header) => (keySet ??= remoteKeySet(url, url, options.fetch))(header);
190
+ };
191
+ const discoveryDocument = z.object({
192
+ issuer: z.string(),
193
+ jwks_uri: z.url({ protocol: /^https?$/ }),
194
+ });
195
+ /**
196
+ * The `jwks_uri` of `issuer`'s discovery document (OpenID Connect Discovery 1.0 §4), fetched once per process. It must
197
+ * name this issuer (§4.3), and an http(s) URL. A failed fetch waits a minute, as the keys' does.
198
+ */
199
+ const jwksUriOf = async (issuer, entry, fetch) => {
200
+ const held = discovered.get(issuer);
201
+ if (held)
202
+ return held;
203
+ const url = `${issuer.replace(/\/$/, '')}/.well-known/openid-configuration`;
204
+ if (Date.now() < entry.retryAt)
205
+ throw new Error(`No identity keys from ${url}`);
206
+ try {
207
+ const response = await getJson(url, fetch);
208
+ if (!response.ok)
209
+ throw new Error(`discovery answered ${response.status}`);
210
+ const metadata = discoveryDocument.safeParse(await response.json());
211
+ if (!metadata.success || metadata.data.issuer !== issuer)
212
+ throw new Error(`${issuer}'s discovery document names no jwks_uri for it`);
213
+ discovered.set(issuer, metadata.data.jwks_uri);
214
+ return metadata.data.jwks_uri;
215
+ }
216
+ catch (error) {
217
+ console.error(`[zite] couldn't fetch the identity keys from ${url}`, error);
218
+ entry.retryAt = Date.now() + REFETCH_EVERY_MS;
219
+ throw error;
220
+ }
221
+ };
222
+ /** Keys from the JWK Set `issuer`'s discovery document names, as {@link remoteIdentityKeys} holds them. */
223
+ export const discoveredIdentityKeys = (issuer, options = {}) => {
224
+ const id = `${issuer}/.well-known/openid-configuration`;
225
+ let keySet;
226
+ return async (header) => {
227
+ keySet ??= jwksUriOf(issuer, fetchedFor(id), options.fetch).then(url => remoteKeySet(id, url, options.fetch));
228
+ return (await keySet)(header);
229
+ };
230
+ };
@@ -0,0 +1,2 @@
1
+ /** The two reserved prefixes: an app never answers anything under them (T5 design §2). */
2
+ export declare const isSignInPath: (pathname: string) => boolean;
@@ -0,0 +1,5 @@
1
+ /** The two reserved prefixes: an app never answers anything under them (T5 design §2). */
2
+ export const isSignInPath = (pathname) => pathname === '/auth' ||
3
+ pathname.startsWith('/auth/') ||
4
+ pathname === '/api/auth' ||
5
+ pathname.startsWith('/api/auth/');
@@ -0,0 +1,19 @@
1
+ /** Off Zite, what the session cookie holds: the refresh token, and the identity it last got, for sign-out's hint. */
2
+ export type SealedSession = {
3
+ rt: string;
4
+ it: string;
5
+ };
6
+ /** Encrypts what only the server may read back, for one client. Times are seconds since the epoch. */
7
+ export type Sealer = {
8
+ seal(session: SealedSession, claims: {
9
+ audience: string;
10
+ expiresAt: number;
11
+ }): Promise<string>;
12
+ /** Undefined for anything this sealer didn't seal for `audience`, or that has expired. */
13
+ open(sealed: string, expect: {
14
+ audience: string;
15
+ now: number;
16
+ }): Promise<SealedSession | undefined>;
17
+ };
18
+ /** A JWE (`dir`, `A256GCM`) under a key derived from `secret` (`ZITE_AUTH_SECRET`). */
19
+ export declare const aesGcmSealer: (secret: string, label?: string) => Sealer;
@@ -0,0 +1,47 @@
1
+ import { EncryptJWT, jwtDecrypt } from 'jose';
2
+ import * as z from 'zod/mini';
3
+ const MIN_SECRET_LENGTH = 32;
4
+ const sealedSession = z.object({
5
+ rt: z.string().check(z.minLength(1)),
6
+ it: z.string().check(z.minLength(1)),
7
+ });
8
+ /** A JWE (`dir`, `A256GCM`) under a key derived from `secret` (`ZITE_AUTH_SECRET`). */
9
+ export const aesGcmSealer = (secret, label = 'zitejs signin session') => {
10
+ if (secret.length < MIN_SECRET_LENGTH)
11
+ throw new Error(`The sign-in secret must be at least ${MIN_SECRET_LENGTH} characters`);
12
+ const encoder = new TextEncoder();
13
+ let derived;
14
+ // Derived on first use, inside a request: Workers runs no crypto at module scope.
15
+ const key = () => (derived ??= crypto.subtle
16
+ .importKey('raw', encoder.encode(secret), 'HKDF', false, ['deriveKey'])
17
+ .then(base => crypto.subtle.deriveKey({
18
+ name: 'HKDF',
19
+ hash: 'SHA-256',
20
+ salt: new Uint8Array(),
21
+ info: encoder.encode(label),
22
+ }, base, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])));
23
+ return {
24
+ async seal({ rt, it }, { audience, expiresAt }) {
25
+ return new EncryptJWT({ rt, it })
26
+ .setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
27
+ .setAudience(audience)
28
+ .setExpirationTime(expiresAt)
29
+ .encrypt(await key());
30
+ },
31
+ async open(sealed, { audience, now }) {
32
+ try {
33
+ const { payload } = await jwtDecrypt(sealed, await key(), {
34
+ audience,
35
+ currentDate: new Date(now * 1000),
36
+ keyManagementAlgorithms: ['dir'],
37
+ contentEncryptionAlgorithms: ['A256GCM'],
38
+ });
39
+ const session = sealedSession.safeParse(payload);
40
+ return session.success ? session.data : undefined;
41
+ }
42
+ catch {
43
+ return undefined;
44
+ }
45
+ },
46
+ };
47
+ };