better-supabase 0.35.0 → 0.36.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 (520) hide show
  1. package/dist/{adapter-CWzyKepA.js → adapter-ddQ9Hzka.js} +126 -91
  2. package/dist/{agents-DXiOPB3V.d.ts → agents-BwUHtvD6.d.ts} +4 -4
  3. package/dist/{ai-cache-CLiAXCPH.d.ts → ai-cache-CPOP2PYz.d.ts} +4 -4
  4. package/dist/{ai-chat-DlcBdOhJ.d.ts → ai-chat-BZhfCHHr.d.ts} +106 -25
  5. package/dist/{ai-schedules-Drx2KRTn.d.ts → ai-schedules-BZPmySUa.d.ts} +5 -5
  6. package/dist/ai-sdk/agents/index.d.ts +6 -6
  7. package/dist/ai-sdk/batches/index.d.ts +3 -3
  8. package/dist/ai-sdk/cache/index.d.ts +1 -1
  9. package/dist/ai-sdk/chat/index.d.ts +2 -2
  10. package/dist/ai-sdk/chat/index.js +3 -272
  11. package/dist/ai-sdk/embeddings/index.d.ts +2 -2
  12. package/dist/ai-sdk/files/index.d.ts +1 -1
  13. package/dist/ai-sdk/index.d.ts +5 -5
  14. package/dist/ai-sdk/index.js +2 -3
  15. package/dist/ai-sdk/mcp/index.d.ts +3 -3
  16. package/dist/ai-sdk/memory/index.d.ts +3 -3
  17. package/dist/ai-sdk/workflow/index.d.ts +6 -5
  18. package/dist/ai-sdk/workflow/index.js +9 -9
  19. package/dist/{api-myq2e9t5.d.ts → api-XEaCJbgv.d.ts} +5 -5
  20. package/dist/{api-keys-DbIbkGxx.d.ts → api-keys-C82fMru4.d.ts} +4 -4
  21. package/dist/{app-tables-X3yzJljM.d.ts → app-tables-C0XVpQEJ.d.ts} +1 -1
  22. package/dist/{approvals-Da4uAANx.js → approvals-D8gR1R8R.js} +95 -11
  23. package/dist/{approvals-DZoGtNFv.d.ts → approvals-DqCv7f-G.d.ts} +101 -7
  24. package/dist/{assistant-BEbRPjhn.d.ts → assistant-5heV2GeR.d.ts} +7 -3
  25. package/dist/assistant-BHZ6fqBR.js +300 -0
  26. package/dist/astro/index.d.ts +7 -7
  27. package/dist/astro/index.js +5 -5
  28. package/dist/{auth-module-CqXdm8qD.js → auth-module-DkqapRZJ.js} +1 -1
  29. package/dist/{authorization-D1P3VBOd.d.ts → authorization-2Rv1AJQJ.d.ts} +114 -39
  30. package/dist/{authorization-hooks-CxwsRnfV.d.ts → authorization-hooks-C0GfMvFm.d.ts} +8 -2
  31. package/dist/authz-topic-D7fPUY4P.js +13 -0
  32. package/dist/{availability-CebEOfMN.d.ts → availability-CZlcrkqD.d.ts} +49 -8
  33. package/dist/{base64-CVyKHBBw.js → base64-CEBz6-Jj.js} +9 -2
  34. package/dist/better-result/index.d.ts +3 -3
  35. package/dist/{bind-Bvv-Zrdh.d.ts → bind-C2XvMlfg.d.ts} +7 -7
  36. package/dist/{block-env-h_uPl2f_.d.ts → block-env-BQrtLPyc.d.ts} +4 -4
  37. package/dist/{block-helpers-disoUWCp.d.ts → block-helpers-BNtM1tqy.d.ts} +1 -1
  38. package/dist/{block-hooks-DrA_d1dJ.d.ts → block-hooks-CtMsgLQr.d.ts} +2 -2
  39. package/dist/{block-subjects-Br2MQNFn.d.ts → block-subjects-Bkieh2Xk.d.ts} +1 -1
  40. package/dist/{block-tables-pj3eHfoP.d.ts → block-tables-DPOgnT3y.d.ts} +1 -1
  41. package/dist/{block-transport-BEtC_Kis.d.ts → block-transport-CDmOUuLZ.d.ts} +2 -2
  42. package/dist/blocks/access-requests/index.d.ts +5 -5
  43. package/dist/blocks/activities/index.d.ts +9 -9
  44. package/dist/blocks/agents/index.d.ts +4 -4
  45. package/dist/blocks/ai-cache/index.d.ts +3 -3
  46. package/dist/blocks/ai-chat/index.d.ts +8 -8
  47. package/dist/blocks/ai-chat/index.js +80 -20
  48. package/dist/blocks/ai-files/index.d.ts +3 -3
  49. package/dist/blocks/ai-keys/index.d.ts +4 -4
  50. package/dist/blocks/ai-schedules/index.d.ts +3 -3
  51. package/dist/blocks/announcements/index.d.ts +8 -8
  52. package/dist/blocks/api-keys/index.d.ts +3 -3
  53. package/dist/blocks/approvals/index.d.ts +16 -5
  54. package/dist/blocks/approvals/index.js +7 -4
  55. package/dist/blocks/assets/index.d.ts +6 -6
  56. package/dist/blocks/assignment/index.d.ts +7 -7
  57. package/dist/blocks/attachments/index.d.ts +4 -4
  58. package/dist/blocks/audit/index.d.ts +13 -13
  59. package/dist/blocks/audit/index.js +1 -1
  60. package/dist/blocks/automations/index.d.ts +12 -12
  61. package/dist/blocks/billable-time/index.d.ts +6 -6
  62. package/dist/blocks/billing/index.d.ts +9 -9
  63. package/dist/blocks/billing/index.js +1 -1
  64. package/dist/blocks/bookings/index.d.ts +6 -6
  65. package/dist/blocks/bulk/index.d.ts +4 -4
  66. package/dist/blocks/calendar/index.d.ts +46 -8
  67. package/dist/blocks/calendar/index.js +306 -47
  68. package/dist/blocks/catalog/index.d.ts +39 -17
  69. package/dist/blocks/catalog/index.js +35 -15
  70. package/dist/blocks/channels/index.d.ts +7 -7
  71. package/dist/blocks/collections/index.d.ts +6 -6
  72. package/dist/blocks/comments/index.d.ts +10 -10
  73. package/dist/blocks/compliance/index.d.ts +5 -5
  74. package/dist/blocks/connectors/index.d.ts +4 -4
  75. package/dist/blocks/contacts/index.d.ts +6 -6
  76. package/dist/blocks/content/index.d.ts +5 -5
  77. package/dist/blocks/contracts/index.d.ts +6 -6
  78. package/dist/blocks/courses/index.d.ts +5 -5
  79. package/dist/blocks/created-by/index.d.ts +2 -2
  80. package/dist/blocks/custom-fields/index.d.ts +6 -6
  81. package/dist/blocks/data-lifecycle/index.d.ts +8 -8
  82. package/dist/blocks/deals/index.d.ts +6 -6
  83. package/dist/blocks/dispatch/index.d.ts +6 -6
  84. package/dist/blocks/documents/index.d.ts +4 -4
  85. package/dist/blocks/documents/index.js +1 -1
  86. package/dist/blocks/domains/index.d.ts +6 -6
  87. package/dist/blocks/donations/index.d.ts +6 -6
  88. package/dist/blocks/drive/index.d.ts +6 -6
  89. package/dist/blocks/employees/index.d.ts +8 -8
  90. package/dist/blocks/enrichment/index.d.ts +6 -6
  91. package/dist/blocks/enrollments/index.d.ts +74 -9
  92. package/dist/blocks/enrollments/index.js +67 -3
  93. package/dist/blocks/entitlements/index.d.ts +6 -6
  94. package/dist/blocks/expenses/index.d.ts +93 -6
  95. package/dist/blocks/expenses/index.js +95 -4
  96. package/dist/blocks/field-history/index.d.ts +4 -4
  97. package/dist/blocks/flags/index.d.ts +5 -5
  98. package/dist/blocks/forecasts/index.d.ts +6 -6
  99. package/dist/blocks/forms/index.d.ts +6 -6
  100. package/dist/blocks/goals/index.d.ts +4 -4
  101. package/dist/blocks/guests/index.d.ts +6 -6
  102. package/dist/blocks/hiring/index.d.ts +6 -6
  103. package/dist/blocks/identities/index.d.ts +5 -5
  104. package/dist/blocks/imports/index.d.ts +5 -5
  105. package/dist/blocks/inbox/index.d.ts +11 -11
  106. package/dist/blocks/inbox/index.js +56 -1
  107. package/dist/blocks/incidents/index.d.ts +5 -5
  108. package/dist/blocks/index.d.ts +9 -9
  109. package/dist/blocks/inventory/index.d.ts +6 -6
  110. package/dist/blocks/invoices/index.d.ts +26 -10
  111. package/dist/blocks/invoices/index.js +23 -7
  112. package/dist/blocks/knowledge/index.d.ts +4 -4
  113. package/dist/blocks/knowledge/index.js +1 -1
  114. package/dist/blocks/lead-scoring/index.d.ts +7 -7
  115. package/dist/blocks/leases/index.d.ts +6 -6
  116. package/dist/blocks/leave/index.d.ts +88 -15
  117. package/dist/blocks/leave/index.js +65 -14
  118. package/dist/blocks/ledger/index.d.ts +6 -6
  119. package/dist/blocks/mail-sync/index.d.ts +5 -5
  120. package/dist/blocks/memberships/index.d.ts +2 -2
  121. package/dist/blocks/memory/index.d.ts +5 -5
  122. package/dist/blocks/memory/index.js +30 -5
  123. package/dist/blocks/messaging/index.d.ts +11 -11
  124. package/dist/blocks/metrics/index.d.ts +6 -6
  125. package/dist/blocks/mfa/index.d.ts +2 -2
  126. package/dist/blocks/moderation/index.d.ts +6 -6
  127. package/dist/blocks/notifications/index.d.ts +11 -11
  128. package/dist/blocks/notifications/index.js +1 -1
  129. package/dist/blocks/numbering/index.d.ts +4 -4
  130. package/dist/blocks/oauth-server/index.d.ts +5 -5
  131. package/dist/blocks/oauth-server/index.js +1 -1
  132. package/dist/blocks/onboarding/index.d.ts +5 -5
  133. package/dist/blocks/orders/index.d.ts +7 -7
  134. package/dist/blocks/organizations/index.d.ts +8 -8
  135. package/dist/blocks/outbox/index.d.ts +4 -4
  136. package/dist/blocks/outbox/index.js +1 -1
  137. package/dist/blocks/passes/index.d.ts +8 -8
  138. package/dist/blocks/passes/index.js +2 -2
  139. package/dist/blocks/permissions/index.d.ts +7 -7
  140. package/dist/blocks/pipelines/index.d.ts +6 -6
  141. package/dist/blocks/posts/index.d.ts +5 -5
  142. package/dist/blocks/profiles/index.d.ts +4 -4
  143. package/dist/blocks/promotions/index.d.ts +5 -5
  144. package/dist/blocks/push/index.d.ts +7 -7
  145. package/dist/blocks/queue/index.d.ts +6 -6
  146. package/dist/blocks/queue/index.js +2 -2
  147. package/dist/blocks/quotes/index.d.ts +119 -27
  148. package/dist/blocks/quotes/index.js +111 -17
  149. package/dist/blocks/rank/index.d.ts +4 -4
  150. package/dist/blocks/reactions/index.d.ts +9 -9
  151. package/dist/blocks/relations/index.d.ts +7 -7
  152. package/dist/blocks/reminders/index.d.ts +78 -11
  153. package/dist/blocks/reminders/index.js +118 -6
  154. package/dist/blocks/reviews/index.d.ts +5 -5
  155. package/dist/blocks/saved-views/index.d.ts +6 -6
  156. package/dist/blocks/scores/index.d.ts +5 -5
  157. package/dist/blocks/search/index.d.ts +7 -7
  158. package/dist/blocks/security-events/index.d.ts +7 -7
  159. package/dist/blocks/security-events/index.js +1 -1
  160. package/dist/blocks/segments/index.d.ts +7 -7
  161. package/dist/blocks/sequences/index.d.ts +6 -6
  162. package/dist/blocks/service-accounts/index.d.ts +5 -5
  163. package/dist/blocks/sessions/index.d.ts +2 -2
  164. package/dist/blocks/sessions/index.js +1 -1
  165. package/dist/blocks/settings/index.d.ts +6 -6
  166. package/dist/blocks/share-links/index.d.ts +5 -5
  167. package/dist/blocks/shipments/index.d.ts +6 -6
  168. package/dist/blocks/shipments/index.js +1 -1
  169. package/dist/blocks/signatures/index.d.ts +5 -5
  170. package/dist/blocks/signing-keys/index.d.ts +4 -4
  171. package/dist/blocks/signing-keys/index.js +2 -2
  172. package/dist/blocks/sla/index.d.ts +7 -7
  173. package/dist/blocks/sso/index.d.ts +6 -6
  174. package/dist/blocks/state-machine/index.d.ts +27 -7
  175. package/dist/blocks/state-machine/index.js +7 -2
  176. package/dist/blocks/subjects/index.d.ts +6 -6
  177. package/dist/blocks/tags/index.d.ts +6 -6
  178. package/dist/blocks/tasks/index.d.ts +9 -9
  179. package/dist/blocks/teams/index.d.ts +4 -4
  180. package/dist/blocks/templates/index.d.ts +7 -7
  181. package/dist/blocks/time-tracking/index.d.ts +7 -7
  182. package/dist/blocks/timeline/index.d.ts +8 -8
  183. package/dist/blocks/trash/index.d.ts +6 -6
  184. package/dist/blocks/undo/index.d.ts +4 -4
  185. package/dist/blocks/updated-at/index.d.ts +2 -2
  186. package/dist/blocks/usage/index.d.ts +4 -4
  187. package/dist/blocks/vercel-marketplace/index.d.ts +5 -5
  188. package/dist/blocks/vercel-marketplace/index.js +3 -3
  189. package/dist/blocks/versions/index.d.ts +6 -6
  190. package/dist/blocks/waitlist/index.d.ts +5 -5
  191. package/dist/blocks/waitlist/index.js +1 -1
  192. package/dist/blocks/webhooks/index.d.ts +13 -13
  193. package/dist/blocks/webhooks/index.js +5 -5
  194. package/dist/blocks/workflow-editor/index.d.ts +10 -10
  195. package/dist/blocks/workflow-editor/index.js +65 -2
  196. package/dist/blocks/workflows/index.d.ts +7 -7
  197. package/dist/{bookings-Br0VXzaf.d.ts → bookings-Dj5cvXKv.d.ts} +4 -4
  198. package/dist/{bucket-DvG66r5G.d.ts → bucket-CrsJNHzi.d.ts} +1 -1
  199. package/dist/chat-sdk/index.d.ts +6 -6
  200. package/dist/claims/index.d.ts +6 -6
  201. package/dist/claims/index.js +2 -2
  202. package/dist/cli/{add-DzgsOE8V.js → add-D2CH8t_B.js} +2 -2
  203. package/dist/cli/add-De73Ghlh.js +1 -0
  204. package/dist/cli/{add-CYreXA68.js → add-Duf1-19E.js} +16 -14
  205. package/dist/cli/{agent-59XWXsRi.js → agent-Tqq3MAqx.js} +26 -1
  206. package/dist/cli/{app-table-files-BnISa3uY.js → app-table-files-ha8X0rRE.js} +2 -2
  207. package/dist/cli/app-tables-BIyQcsHH.js +42 -0
  208. package/dist/cli/{backfill-BLLTSDSa.js → backfill-CLgA6-ll.js} +3 -3
  209. package/dist/cli/bin.js +1 -1
  210. package/dist/cli/{blocks-uzh1g_0v.js → blocks-9AeouX4h.js} +2 -2
  211. package/dist/cli/{blocks-CpRvI7x8.js → blocks-BVB1fMMj.js} +1 -1
  212. package/dist/cli/{cache-BPWC7tGD.js → cache-aMk9vF1_.js} +1 -1
  213. package/dist/cli/{codemod-CbJVS_kG.js → codemod-B5wrcnF2.js} +113 -4
  214. package/dist/cli/{command-BpZ4AuhR.js → command-DM_x_yzZ.js} +6 -0
  215. package/dist/cli/{completion-DHTT6rjI.js → completion-CusuUJNn.js} +1 -1
  216. package/dist/cli/{completion-B08Q0xB3.js → completion-Cx2UYd-y.js} +2 -2
  217. package/dist/cli/{completion-CwL7e93t.js → completion-DbYb3N8e.js} +2 -2
  218. package/dist/cli/{config-D-Upz3jV.js → config-BeuImpav.js} +1 -1
  219. package/dist/cli/{content-mapper-Cjkm2Sg3.js → content-mapper-CEtdbshU.js} +2 -2
  220. package/dist/cli/{db-Diy1OebO.js → db-CeiQzhPq.js} +2 -2
  221. package/dist/cli/{doctor-D94FEJZs.js → doctor-DaOUWfRN.js} +386 -49
  222. package/dist/cli/env-BfWbheiC.js +1 -0
  223. package/dist/cli/{env-BAJn6wCA.js → env-DVV10l_r.js} +1 -1
  224. package/dist/cli/{gen-Cd0VNDjE.js → gen-BO-2NF-G.js} +14 -14
  225. package/dist/cli/index.d.ts +1 -1
  226. package/dist/cli/index.js +7 -7
  227. package/dist/cli/{init-Co1N9ZoA.js → init-Xit9Hnbb.js} +9 -9
  228. package/dist/cli/{keys-CxajkV_7.js → keys-DJTN2Avl.js} +1 -1
  229. package/dist/cli/{live-NFNeZsP7.js → live-CuMpyRjF.js} +2 -2
  230. package/dist/cli/{mcp-WZ8t7NMz.js → mcp-C7d4j5cq.js} +4 -4
  231. package/dist/cli/{metadata-BzMkmrZR.js → metadata-D2YvkY2D.js} +3 -3
  232. package/dist/cli/{migrate-C9gyDAV7.js → migrate-BCXxyTKt.js} +2 -2
  233. package/dist/cli/{migration-safety-BNi8PIiM.js → migration-safety-DfwTOBQ4.js} +1 -1
  234. package/dist/cli/{migrations-Ds0J_TmZ.js → migrations-nomh4TBo.js} +2 -2
  235. package/dist/cli/{module-migration-hFrlzQZ5.js → module-migration--9T_T-zt.js} +2 -2
  236. package/dist/cli/{moved-BAFPdJz_.js → moved-CT6i1csY.js} +1 -1
  237. package/dist/cli/{parse-BueItuNJ.js → parse-qgJylE_A.js} +1 -1
  238. package/dist/cli/{powersync-oFiwgsBi.js → powersync-DB9WZsIv.js} +4 -4
  239. package/dist/cli/powersync-IBM_v_eJ.js +1 -0
  240. package/dist/cli/{print-BtreoJSm.js → print-S6IF5rZm.js} +2 -2
  241. package/dist/cli/{providers-Be2dgyuR.js → providers-BDTcal71.js} +1 -1
  242. package/dist/cli/{prune-workflows-BPxgRrqY.js → prune-workflows-Zr2DjByi.js} +3 -3
  243. package/dist/cli/{remove-B4ad996E.js → remove-CPX5Tg5s.js} +6 -6
  244. package/dist/cli/{render-C-Mfq-o3.js → render-Bp7a7XQ9.js} +18 -4
  245. package/dist/cli/{run-D2nuyyPo.js → run-BclCFEyP.js} +12 -48
  246. package/dist/cli/{run-dY9uOC3W.js → run-BlVaLnt_.js} +2 -2
  247. package/dist/cli/{run-cLdnJHH0.js → run-kgG50x_Z.js} +44 -43
  248. package/dist/cli/{seed-BpaqqyO8.js → seed-Cn2R91cd.js} +2 -2
  249. package/dist/cli/seed-DGGjReq4.js +1 -0
  250. package/dist/cli/{shared-DCHxLAEL.js → shared-D60W9NS-.js} +1 -1
  251. package/dist/cli/{skills-jZThjL3B.js → skills-DH-yPDny.js} +1 -1
  252. package/dist/cli/{snapshot-CloKPNxv.js → snapshot-C3_eQUgY.js} +2 -2
  253. package/dist/cli/{source-Bwyp18Rj.js → source-Bk6XwIAK.js} +1 -1
  254. package/dist/cli/{spec-DsVq4_qV.js → spec-BDTpcBns.js} +1 -1
  255. package/dist/cli/{spec-DAUF4ybu.js → spec-C8ydQwZC.js} +3 -3
  256. package/dist/cli/{sql-layout-CHpEL0oq.js → sql-layout-DVQ20UMi.js} +2 -2
  257. package/dist/cli/{stack-147NqctC.js → stack-CmhSfY5V.js} +3 -2
  258. package/dist/cli/{sync-DZu1r34s.js → sync-D-WO4Yvl.js} +4 -4
  259. package/dist/cli/{table-D9FbJS8h.js → table-k5OABwy3.js} +1 -1
  260. package/dist/cli/{upgrade-Bpvi70zm.js → upgrade-DGe5Pv6v.js} +5 -5
  261. package/dist/cli/{upgrade-A-BALvp3.js → upgrade-XdhMuHAu.js} +3 -3
  262. package/dist/cli/{version-B59mZJoy.js → version-DKfeme2I.js} +1 -1
  263. package/dist/client/index.d.ts +6 -6
  264. package/dist/client/index.js +1 -1
  265. package/dist/client/native/index.d.ts +5 -5
  266. package/dist/client/native/index.js +2 -2
  267. package/dist/{client-Bky2z09B.js → client-DrejIxsu.js} +1 -1
  268. package/dist/{cloud-event-DXWmXrus.d.ts → cloud-event-BEmAUdl1.d.ts} +1 -1
  269. package/dist/commerce/index.js +1 -1
  270. package/dist/{compiler-qlXlokKn.d.ts → compiler-BOW4yPcW.d.ts} +2 -2
  271. package/dist/{composite-CIxjVcL1.d.ts → composite-B-oAH16L.d.ts} +7 -7
  272. package/dist/{composite-D2JnIiHt.js → composite-BidYZWZY.js} +3 -3
  273. package/dist/config/index.d.ts +3 -3
  274. package/dist/config/index.js +4 -4
  275. package/dist/{config-BZWSFxkG.js → config-BKxjItQ-.js} +3 -3
  276. package/dist/{config-DQP0IvDX.js → config-BrRlSxhx.js} +1 -1
  277. package/dist/{connectors-Cf2LeAuZ.d.ts → connectors-CrLRW4Ol.d.ts} +4 -4
  278. package/dist/{context-CderJRZf.d.ts → context-yfOlyAqb.d.ts} +3 -3
  279. package/dist/contract/index.d.ts +9 -9
  280. package/dist/{controller-DaWA9eWS.d.ts → controller-CAcLEndc.d.ts} +1 -1
  281. package/dist/{conversion-C9rndpEI.d.ts → conversion-s1NtB6S-.d.ts} +1 -1
  282. package/dist/create/index.d.ts +3 -3
  283. package/dist/create/index.js +3 -3
  284. package/dist/create/lite/index.d.ts +4 -4
  285. package/dist/create/lite/index.js +2 -2
  286. package/dist/credentials/index.d.ts +4 -4
  287. package/dist/credentials/index.js +1 -1
  288. package/dist/{cron-route-DSITg1yC.js → cron-route-uTsC2BD0.js} +1 -1
  289. package/dist/{data-engine-CMENsp3d.d.ts → data-engine-CX1oYDZl.d.ts} +1 -1
  290. package/dist/{define-ITQA71fw.d.ts → define-BvkaC3Oh.d.ts} +5 -5
  291. package/dist/{define-B6D55cO0.js → define-Duh2mMYk.js} +1 -1
  292. package/dist/{define-block-COmMkx2x.d.ts → define-block-Ds3aLZwz.d.ts} +12 -12
  293. package/dist/{documents-DeZw83ue.d.ts → documents-Btk0MhC0.d.ts} +3 -3
  294. package/dist/edge/index.d.ts +9 -9
  295. package/dist/edge/index.js +7 -7
  296. package/dist/elysia/index.d.ts +1 -1
  297. package/dist/elysia/index.js +1 -1
  298. package/dist/{embeddings-rVR2AKVz.d.ts → embeddings-CI6P_mtD.d.ts} +1 -1
  299. package/dist/{ended-NC_ZesY4.d.ts → ended-iq2wp8fc.d.ts} +8 -3
  300. package/dist/{entitlements-BefkpQIz.d.ts → entitlements-Dhu-4vlH.d.ts} +2 -2
  301. package/dist/env/index.d.ts +1 -1
  302. package/dist/{messages-CRk1g6oe.js → errors-0Qid9fGz.js} +107 -3
  303. package/dist/eve/index.d.ts +9 -9
  304. package/dist/eve/index.js +3 -3
  305. package/dist/{eve-DIKjuPp5.d.ts → eve-DleYrhwj.d.ts} +2 -2
  306. package/dist/{event-calendar-DUtFyRrv.d.ts → event-calendar-DPMcqy7Q.d.ts} +1 -1
  307. package/dist/events/index.d.ts +3 -3
  308. package/dist/{events-DVt3Z9hw.d.ts → events-DCw3c6pj.d.ts} +1 -1
  309. package/dist/{executor-DqNRrFxx.d.ts → executor-B-o7QMPp.d.ts} +16 -2
  310. package/dist/{executor-CFmee_nV.d.ts → executor-DoSNec_H.d.ts} +1 -1
  311. package/dist/{executor-CHnoKOxk.d.ts → executor-H8ZLkeHj.d.ts} +4 -4
  312. package/dist/{executor-BDMqPbVU.js → executor-RYiR4z47.js} +71 -37
  313. package/dist/expo/index.d.ts +4 -4
  314. package/dist/expo/index.js +7 -7
  315. package/dist/{field-errors-D1meOs_H.d.ts → field-errors-DXZk9Qjt.d.ts} +10 -10
  316. package/dist/{fields-CAVk9dxX.d.ts → fields-CP46SPNE.d.ts} +1 -1
  317. package/dist/{filter-evaluate-Bz3Fzhz2.d.ts → filter-evaluate-Bkbb0nuQ.d.ts} +1 -1
  318. package/dist/{filter-query-DV-x8fio.d.ts → filter-query-Xj40B5KT.d.ts} +1 -1
  319. package/dist/{flags-6emyAXly.d.ts → flags-Cuew4tGx.d.ts} +2 -2
  320. package/dist/flags-sdk/index.d.ts +2 -2
  321. package/dist/{framework-BFlaPuvv.d.ts → framework-Byr_j8G-.d.ts} +8 -8
  322. package/dist/{framework-ChzJYkJW.js → framework-z3KTPRjk.js} +4 -4
  323. package/dist/{gateway-DaekJ_Me.d.ts → gateway-B9k89AC4.d.ts} +3 -3
  324. package/dist/h3/index.d.ts +1 -1
  325. package/dist/h3/index.js +1 -1
  326. package/dist/h3/v1/index.d.ts +1 -1
  327. package/dist/h3/v1/index.js +1 -1
  328. package/dist/hono/index.d.ts +9 -10
  329. package/dist/hono/index.js +8 -8
  330. package/dist/{inbox-DavCzW7b.d.ts → inbox-yGfUVQr2.d.ts} +61 -6
  331. package/dist/{index-Dvpu22CJ.d.ts → index-1uV69AZq.d.ts} +1 -1
  332. package/dist/{index-BbDiBiKt.d.ts → index-6H-8Ib1w.d.ts} +4 -4
  333. package/dist/{index-M1izbwbN.d.ts → index-Ag-T51Jl.d.ts} +1 -1
  334. package/dist/{index-ZQZMQF4l.d.ts → index-BUluRi0b.d.ts} +6 -6
  335. package/dist/{index-BQlLxOj5.d.ts → index-C78VPlXW.d.ts} +1 -1
  336. package/dist/{index-D18su_r5.d.ts → index-CY612vAg.d.ts} +10 -5
  337. package/dist/{index-DXUiRyEk.d.ts → index-CnzGRpeH.d.ts} +5 -5
  338. package/dist/{index-BIAtapnD.d.ts → index-Dbd1E5Au.d.ts} +5 -5
  339. package/dist/{index-ChLuLxy-.d.ts → index-Dv6lfL5p.d.ts} +14 -14
  340. package/dist/{index-8w4OB5En.d.ts → index-F6lsRlsr.d.ts} +1 -1
  341. package/dist/{index-D9aV0Fvx.d.ts → index-kkZwp5M1.d.ts} +6 -6
  342. package/dist/{index-C13UgV67.d.ts → index-lMApFSAd.d.ts} +5 -5
  343. package/dist/index.d.ts +7 -7
  344. package/dist/index.js +1 -1
  345. package/dist/{instances-D9YrkoAy.js → instances-xQ2lupVE.js} +218 -11
  346. package/dist/jwks-cache-CBKtICNV.js +114 -0
  347. package/dist/{jws-B8p0ppgh.js → jws-De9qjIPV.js} +1 -1
  348. package/dist/{kit-9pZP5iLU.js → kit-D5rRAKWJ.js} +2 -2
  349. package/dist/{kit-OgFOW9rX.d.ts → kit-DCuO1ZhB.d.ts} +4 -4
  350. package/dist/{knowledge-DdZzUTQ-.js → knowledge-CJnZOaix.js} +67 -7
  351. package/dist/{knowledge-BBC2sfAY.d.ts → knowledge-DWXAxvkN.d.ts} +82 -11
  352. package/dist/lint/index.d.ts +1 -1
  353. package/dist/list/index.d.ts +3 -3
  354. package/dist/{list-query-C7V8kUaD.d.ts → list-query-D1h3Dmnk.d.ts} +3 -3
  355. package/dist/mapper/bin.js +5 -5
  356. package/dist/mcp/index.d.ts +3 -3
  357. package/dist/mcp/index.js +5 -5
  358. package/dist/mcp/sdk/index.d.ts +6 -6
  359. package/dist/mcp/sdk/index.js +2 -2
  360. package/dist/{messaging-D5z2TR37.d.ts → messaging-Bfe4p9Pm.d.ts} +4 -4
  361. package/dist/{model-messages-BcrkjsPE.js → model-messages-CIHqP7Z3.js} +1 -1
  362. package/dist/nestjs/index.d.ts +2 -2
  363. package/dist/nestjs/index.js +1 -1
  364. package/dist/next/client/index.d.ts +1 -1
  365. package/dist/next/index.d.ts +331 -79
  366. package/dist/next/index.js +520 -105
  367. package/dist/node/index.d.ts +2 -2
  368. package/dist/node/index.js +1 -1
  369. package/dist/{operations-t_hlXkS4.d.ts → operations-SWpzGC_K.d.ts} +1 -1
  370. package/dist/{options-D4dxMGHF.js → options-Bgnm4pTD.js} +1 -0
  371. package/dist/{options-C13-dVMH.js → options-D-jiqb0l.js} +2 -0
  372. package/dist/{options-C9bp3SEA.js → options-DqmTs2nv.js} +2 -1
  373. package/dist/{options-CuPWezcV.js → options-RYbyaVhv.js} +3 -1
  374. package/dist/options-SOjQVgfS.js +37 -0
  375. package/dist/{options-JnPEVbBJ.js → options-ScQ6Hnxo.js} +2 -1
  376. package/dist/{options-CuaWhsQS.js → options-X61tvckX.js} +2 -1
  377. package/dist/orpc/index.d.ts +8 -8
  378. package/dist/orpc/index.js +6 -6
  379. package/dist/otel/index.d.ts +2 -2
  380. package/dist/otel/index.js +4 -4
  381. package/dist/{outbox-7zgh-7nw.d.ts → outbox-BFZS6Kvz.d.ts} +4 -4
  382. package/dist/{permissions-C8p6RlIZ.d.ts → permissions-2UlVQDzY.d.ts} +1 -1
  383. package/dist/{pool-D-4HyhuW.d.ts → pool-yO-LzZAd.d.ts} +3 -3
  384. package/dist/{ports-CmEXVqhg.js → ports-CkygVOeE.js} +2 -2
  385. package/dist/{ports-C-8uduFM.d.ts → ports-prqYrReN.d.ts} +1 -1
  386. package/dist/postgres/index.d.ts +4 -4
  387. package/dist/{postgrest-DZtM2nIS.d.ts → postgrest-Bjain6nf.d.ts} +1 -1
  388. package/dist/powersync/index.d.ts +6 -6
  389. package/dist/preset/index.d.ts +3 -3
  390. package/dist/preset/index.js +3 -3
  391. package/dist/{preset-B_sSI9vg.js → preset-BvHNleCo.js} +2 -2
  392. package/dist/{project-DVlXQGEp.js → project-CBvowdKY.js} +5 -5
  393. package/dist/{provider-BI0KC4u5.d.ts → provider-bIAzxVMB.d.ts} +1 -1
  394. package/dist/{push-token-D41lOoE8.d.ts → push-token-DtqJeg8w.d.ts} +1 -1
  395. package/dist/query/index.d.ts +1 -1
  396. package/dist/{rate-limit-CRhlLFhP.js → rate-limit-BJ4EMdAy.js} +1 -1
  397. package/dist/react/index.d.ts +9 -9
  398. package/dist/react/index.js +3 -3
  399. package/dist/react/native/index.d.ts +1 -1
  400. package/dist/react/native/index.js +1 -1
  401. package/dist/react/server.d.ts +9 -9
  402. package/dist/react/server.js +2 -2
  403. package/dist/react/session.d.ts +2 -32
  404. package/dist/react/session.js +1 -37
  405. package/dist/{react-COIov1yC.js → react-DZ7AW2yf.js} +2 -2
  406. package/dist/react-router/index.d.ts +6 -6
  407. package/dist/react-router/index.js +5 -5
  408. package/dist/realtime/index.d.ts +6 -6
  409. package/dist/{record-form-DU2EoVsv.d.ts → record-form-BQA-lawE.d.ts} +1 -1
  410. package/dist/{recordings-D69Va7gP.d.ts → recordings-Bw5LoocX.d.ts} +1 -1
  411. package/dist/records/index.d.ts +9 -9
  412. package/dist/{refusal-CGi-0Q18.d.ts → refusal-BX1EvmpJ.d.ts} +3 -3
  413. package/dist/{refusal-5c6UMpUP.js → refusal-rnbr6RZD.js} +2 -2
  414. package/dist/{refresh-B8t_KE3s.js → request-kind-tNDM5Z_o.js} +15 -31
  415. package/dist/{resolve--LfVoOMg.d.ts → resolve-BIpQRhvF.d.ts} +97 -36
  416. package/dist/{resolve-FW8oeXvh.js → resolve-CZV31iCm.js} +402 -392
  417. package/dist/{resolved-names-h-3UbKcw.js → resolved-names-b6P2--jK.js} +1 -1
  418. package/dist/{resource-BbWk4hoP.js → resource-COaS9_i8.js} +1 -1
  419. package/dist/{resource-DWllVW8k.d.ts → resource-CaYpB07K.d.ts} +1 -1
  420. package/dist/{resource-execute-DUBYKTYU.d.ts → resource-execute-A1NbR-sd.d.ts} +2 -2
  421. package/dist/{resource-types-RgaljPs0.d.ts → resource-types-CTcc37WL.d.ts} +4 -4
  422. package/dist/{resources-Bki1J4jy.d.ts → resources-13ZFX1G6.d.ts} +2 -2
  423. package/dist/{resources-DYSx9NYM.js → resources-DhiK3yLO.js} +1 -1
  424. package/dist/{respond-DLH4tD2d.js → respond-8A3EOo61.js} +1 -1
  425. package/dist/{respond-BYOV7KZp.d.ts → respond-CAxhkwAi.d.ts} +15 -19
  426. package/dist/{sales-lines-DuNVoKHA.d.ts → sales-lines-wQHuL-pa.d.ts} +1 -1
  427. package/dist/{sandboxes-B2hBoBvJ.d.ts → sandboxes-BF9RxxCU.d.ts} +1 -1
  428. package/dist/{scores-FAORS4qU.d.ts → scores-Ce8MxQX9.d.ts} +5 -5
  429. package/dist/server/index.d.ts +58 -36
  430. package/dist/server/index.js +35 -41
  431. package/dist/{server-types-C2hlvhP4.d.ts → server-types-DEjva0MW.d.ts} +19 -17
  432. package/dist/{session-B4VasaAA.d.ts → session-BA0YDmjt.d.ts} +11 -12
  433. package/dist/session-BjPYE4dT.js +180 -0
  434. package/dist/session-CeYL3EPm.d.ts +77 -0
  435. package/dist/{session-status-D8CBxCqv.d.ts → session-status-Df6tuKY9.d.ts} +4 -3
  436. package/dist/{sign-in-CX1a5i2P.d.ts → sign-in-4u4vLtXG.d.ts} +16 -4
  437. package/dist/{sign-in-CxdoTEp5.js → sign-in-djgvab1X.js} +3 -3
  438. package/dist/{sign-in-BMm1xhKq.js → sign-in-k2lXELeC.js} +2 -2
  439. package/dist/{signatures-CBn7w4VR.js → signatures-DK01D2S7.js} +1 -1
  440. package/dist/{signers-6ih6i9aq.d.ts → signers-Dw9DBZjJ.d.ts} +4 -4
  441. package/dist/{signing-keys-De09WNJ3.d.ts → signing-keys-FglIQ6iL.d.ts} +2 -2
  442. package/dist/{signing-keys-BC5_hJN5.js → signing-keys-sGaXklwD.js} +1 -1
  443. package/dist/{snapshot-CVMSyTHH.js → snapshot-BOA7lkRg.js} +9 -17
  444. package/dist/solid/index.d.ts +10 -10
  445. package/dist/solid/index.js +1 -1
  446. package/dist/solid-start/index.d.ts +6 -6
  447. package/dist/solid-start/index.js +5 -5
  448. package/dist/spec/index.d.ts +2 -2
  449. package/dist/sql/index.d.ts +5 -5
  450. package/dist/sql/index.js +3 -3
  451. package/dist/{sql-C9nO-Mat.js → sql-BChN3Hxv.js} +7382 -2219
  452. package/dist/sqlite/index.d.ts +3 -3
  453. package/dist/{sso-CuzAjsc8.d.ts → sso-B7w7h8RJ.d.ts} +3 -3
  454. package/dist/ssr/index.d.ts +5 -6
  455. package/dist/ssr/index.js +3 -3
  456. package/dist/storage/index.d.ts +3 -3
  457. package/dist/storage/index.js +1 -1
  458. package/dist/streams/index.d.ts +1 -1
  459. package/dist/{subject-readers-BlD8tALG.d.ts → subject-readers-YL8H9G8X.d.ts} +2 -2
  460. package/dist/{subjects-Bv2dPflD.d.ts → subjects-CVjAE7nz.d.ts} +3 -3
  461. package/dist/{support-DxYI6sDM.d.ts → support-BwtMgjVg.d.ts} +4 -4
  462. package/dist/{support-view-DSmCett7.d.ts → support-view-GykHOIQ2.d.ts} +1 -1
  463. package/dist/svelte/index.d.ts +9 -9
  464. package/dist/svelte/index.js +1 -1
  465. package/dist/sveltekit/index.d.ts +7 -7
  466. package/dist/sveltekit/index.js +5 -5
  467. package/dist/{tags--k2fbPfO.d.ts → tags-CAfvzA1U.d.ts} +1 -1
  468. package/dist/tanstack-db/index.d.ts +3 -3
  469. package/dist/tanstack-start/index.d.ts +6 -6
  470. package/dist/tanstack-start/index.js +5 -5
  471. package/dist/{tenant-gezshhcs.d.ts → tenant-lBgoqg9T.d.ts} +1 -1
  472. package/dist/testing/index.d.ts +27 -28
  473. package/dist/testing/index.js +5 -5
  474. package/dist/{timeline-Bq658xsi.d.ts → timeline-CrO48Qa6.d.ts} +5 -5
  475. package/dist/{topic-BVq5RdsI.d.ts → topic-x-mrN_Ff.d.ts} +5 -5
  476. package/dist/{types-C8UyJOPJ.d.ts → types-6PMaLIyw.d.ts} +3 -3
  477. package/dist/{types-Dh2OGEW5.d.ts → types-BdhE7I8Z.d.ts} +5 -5
  478. package/dist/{types-BkYEUWdz.d.ts → types-BzIYSSWK.d.ts} +16 -1
  479. package/dist/{types-DCoqai8o.d.ts → types-C7K8mu9B.d.ts} +45 -15
  480. package/dist/{types-d0JBRTAg.d.ts → types-C9XfFGmA.d.ts} +128 -13
  481. package/dist/{types-hTj5OuFo.d.ts → types-CJqNGQKb.d.ts} +2 -2
  482. package/dist/{types-TH3zlMiM.d.ts → types-D5uf0l4_.d.ts} +1 -1
  483. package/dist/{types-BBqP9H6w.d.ts → types-auvHrNWC.d.ts} +4 -4
  484. package/dist/{undo-22ofP6Zp.d.ts → undo-CdKp5_2X.d.ts} +2 -2
  485. package/dist/{usage-CNCT6_3D.d.ts → usage-DZ8j5Tm_.d.ts} +4 -4
  486. package/dist/{vault-yGQD5Rdl.d.ts → vault-DjbG4XQS.d.ts} +2 -2
  487. package/dist/vercel-connect/index.d.ts +1 -1
  488. package/dist/vercel-sandbox/index.d.ts +2 -2
  489. package/dist/{verify-DY_j4GPZ.js → verify-96j8d5ps.js} +1 -1
  490. package/dist/{verify-BQu3eBNW.d.ts → verify-HOiu3lRR.d.ts} +2 -2
  491. package/dist/{view-BfEqjZJ_.js → view-Ch0Qtr36.js} +1 -1
  492. package/dist/{view-Cy2XxYp1.d.ts → view-DdDY88SC.d.ts} +1 -1
  493. package/dist/vue/index.d.ts +10 -10
  494. package/dist/vue/index.js +1 -1
  495. package/dist/{watch-topic-BOclyLFd.d.ts → watch-topic-D6bcqOrJ.d.ts} +1 -1
  496. package/dist/workflow-sdk/builder/index.d.ts +29 -5
  497. package/dist/workflow-sdk/builder/index.js +39 -12
  498. package/dist/workflow-sdk/index.d.ts +1 -1
  499. package/dist/workflow-sdk/index.js +2 -2
  500. package/dist/workflow-sdk/world/index.d.ts +1 -1
  501. package/dist/workflow-sdk/world/index.js +1 -1
  502. package/dist/{workflow-sdk-BL3wzkdp.js → workflow-sdk-CBS8L2Ku.js} +5 -0
  503. package/dist/{workflow-sdk-yIkECybp.d.ts → workflow-sdk-D3H10W5h.d.ts} +3 -3
  504. package/dist/{workflows-BljkWRxE.d.ts → workflows-BI4yKqFh.d.ts} +3 -3
  505. package/dist/yjs/index.d.ts +2 -2
  506. package/dist/yjs/index.js +1 -1
  507. package/package.json +1 -1
  508. package/schemas/config-v1.json +126 -0
  509. package/schemas/doctor-report-v1.json +4 -0
  510. package/skills/better-supabase-auth/SKILL.md +45 -11
  511. package/dist/cli/add-BaB3y1lv.js +0 -1
  512. package/dist/cli/env-UN6PJFX6.js +0 -1
  513. package/dist/cli/powersync-J2Kms2NT.js +0 -1
  514. package/dist/cli/seed-ByLneY1H.js +0 -1
  515. package/dist/errors-D3-4c-XF.js +0 -102
  516. package/dist/http-BDC1IvBX.js +0 -27
  517. package/dist/jwks-cache-IZaiICAV.js +0 -48
  518. package/dist/options-Itq7QYoW.js +0 -20
  519. package/dist/refresh-BtbC2rZe.d.ts +0 -52
  520. package/dist/snapshot-BGsJw9xn.d.ts +0 -83
@@ -1,18 +1,14 @@
1
1
  import { n as dbError } from "./errors-B7tCfCvX.js";
2
2
  import { t as consoleLogger } from "./logger-BkF8ukXV.js";
3
- import { n as decodeJwtPayload, r as fromBase64, t as base64ToText } from "./base64-CVyKHBBw.js";
3
+ import { i as fromBase64, n as decodeJwtHeader, r as decodeJwtPayload, t as base64ToText } from "./base64-CEBz6-Jj.js";
4
4
  import { a as invalidActorError, n as actorOf } from "./actor-B5b0i1Fs.js";
5
- import { DEFAULT_COOKIE_OPTIONS, createChunks, isChunkLike, parseCookieHeader, serializeCookieHeader, stringFromBase64URL, stringToBase64URL } from "@supabase/ssr";
5
+ import { n as sharedJwks } from "./jwks-cache-CBKtICNV.js";
6
+ import { DEFAULT_COOKIE_OPTIONS, clearAuthCookiesAtScopes, createChunks, createServerClient, isChunkLike, parseCookieHeader, serializeCookieHeader, stringFromBase64URL, stringToBase64URL } from "@supabase/ssr";
7
+ import { fromSupabaseUrl } from "@supabase/server";
6
8
  import { extractCredentials, verifyCredentials } from "@supabase/server/core";
7
9
  // src/auth/session.ts
8
10
  const DEFAULT_SESSION_ENCODING = "user-and-tokens";
9
11
  const BASE64_PREFIX = "base64-";
10
- /** Headers that keep responses carrying session cookies out of shared caches. */
11
- const AUTH_CACHE_HEADERS = {
12
- "Cache-Control": "private, no-cache, no-store, must-revalidate, max-age=0",
13
- Expires: "0",
14
- Pragma: "no-cache"
15
- };
16
12
  /** `sb-<first label of the hostname>-auth-token`, the supabase-js default. */
17
13
  function sessionCookieName(url) {
18
14
  let name = cookieNames.get(url);
@@ -111,35 +107,6 @@ function isStoredSession(value) {
111
107
  function readSession(cookies, name) {
112
108
  return readSessionParts(cookies, name).session;
113
109
  }
114
- /**
115
- * `Max-Age=0` writes for the session's chunk-like cookies that the readable
116
- * session doesn't use: a leftover `.2` after a shorter rewrite, chunks next to
117
- * a whole cookie, or chunks past a gap. Empty when no session reads.
118
- */
119
- function pruneSessionChunks(cookies, name, options = {}) {
120
- const { session, used } = readSessionParts(cookies, name);
121
- if (!session) return [];
122
- const kept = new Set(used);
123
- const base = {
124
- ...DEFAULT_COOKIE_OPTIONS,
125
- ...options
126
- };
127
- return cookies.filter((cookie) => isChunkLike(cookie.name, name) && !kept.has(cookie.name)).map((cookie) => ({
128
- name: cookie.name,
129
- value: "",
130
- options: {
131
- ...base,
132
- maxAge: 0
133
- }
134
- }));
135
- }
136
- /**
137
- * The encoding a stored session was written with: `tokens-only` without a
138
- * `user`.
139
- */
140
- function sessionEncoding(session) {
141
- return session.user === void 0 || session.user === null ? "tokens-only" : "user-and-tokens";
142
- }
143
110
  function encoded(session, encode) {
144
111
  switch (encode) {
145
112
  case "user-and-tokens": return JSON.stringify(session);
@@ -151,9 +118,10 @@ function encoded(session, encode) {
151
118
  }
152
119
  }
153
120
  /**
154
- * Cookie writes that store `session` (or clear it with `null`) exactly like
121
+ * Cookie writes that store a session a sign-in flow received, exactly like
155
122
  * `@supabase/ssr` with the same `encode`, and expire chunks the new value no
156
- * longer uses.
123
+ * longer uses. Refreshes and sign-outs write through `@supabase/ssr` itself
124
+ * (`ssr-client.ts`).
157
125
  */
158
126
  function writeSession(existing, name, session, options = {}, { encode = DEFAULT_SESSION_ENCODING } = {}) {
159
127
  const base = {
@@ -175,30 +143,6 @@ function writeSession(existing, name, session, options = {}, { encode = DEFAULT_
175
143
  options: base
176
144
  }))];
177
145
  }
178
- /**
179
- * `Max-Age=0` writes for every chunk of the session cookie at each of `scopes`,
180
- * like `clearAuthCookiesAtScopes` from `@supabase/ssr`. Use it once the cookie
181
- * `domain` or `path` changed, for the scopes earlier deploys wrote: browsers
182
- * ignore writes for scopes the host doesn't own, but a scope equal to the
183
- * current one clears the live session.
184
- */
185
- function clearSessionAtScopes(existing, name, scopes) {
186
- if (scopes.length === 0) return [];
187
- const chunks = existing.map((cookie) => cookie.name).filter((cookie) => isChunkLike(cookie, name));
188
- return scopes.flatMap((scope) => {
189
- const options = {
190
- ...DEFAULT_COOKIE_OPTIONS,
191
- ...scope.domain === void 0 ? {} : { domain: scope.domain },
192
- ...scope.path === void 0 ? {} : { path: scope.path },
193
- maxAge: 0
194
- };
195
- return chunks.map((chunk) => ({
196
- name: chunk,
197
- value: "",
198
- options
199
- }));
200
- });
201
- }
202
146
  /** Applies cookie writes to a cookie list, as the next request would see it. */
203
147
  function applyCookieWrites(cookies, writes) {
204
148
  const next = new Map(cookies.map((cookie) => [cookie.name, cookie.value]));
@@ -209,8 +153,262 @@ function applyCookieWrites(cookies, writes) {
209
153
  value
210
154
  }));
211
155
  }
156
+ // src/auth/ssr-client.ts
157
+ /** Auth's code for a refresh token another request already rotated. */
158
+ const RACED_CODE = "refresh_token_already_used";
159
+ /** How long a token response answers later requests with the same refresh token. */
160
+ const REUSE_MS = 1e4;
161
+ const RECENT_MAX = 1e3;
162
+ /** The body the coalescing fetch answers with when Auth is unreachable. */
163
+ const UNREACHABLE_CODE = "bsb_auth_unreachable";
164
+ const REGISTRY = Symbol.for("better-supabase.refresh");
165
+ /**
166
+ * Shared on `globalThis`, so the proxy and route handlers in other module
167
+ * graphs answer a refresh token with one Auth call.
168
+ */
169
+ function registry() {
170
+ const scope = globalThis;
171
+ const shared = scope[REGISTRY] ?? {
172
+ inflight: /* @__PURE__ */ new Map(),
173
+ recent: /* @__PURE__ */ new Map()
174
+ };
175
+ scope[REGISTRY] = shared;
176
+ return shared;
177
+ }
178
+ function urlOf(input) {
179
+ if (typeof input === "string") return input;
180
+ return input instanceof URL ? input.href : input.url;
181
+ }
182
+ function refreshTokenOf(body) {
183
+ if (typeof body !== "string") return;
184
+ try {
185
+ const parsed = JSON.parse(body);
186
+ return typeof parsed === "object" && parsed !== null && "refresh_token" in parsed && typeof parsed.refresh_token === "string" ? parsed.refresh_token : void 0;
187
+ } catch {
188
+ return;
189
+ }
190
+ }
191
+ function errorCodeOf(body) {
192
+ try {
193
+ const parsed = JSON.parse(body);
194
+ if (typeof parsed !== "object" || parsed === null) return;
195
+ const code = "error_code" in parsed ? parsed.error_code : "code" in parsed ? parsed.code : void 0;
196
+ return typeof code === "string" ? code : void 0;
197
+ } catch {
198
+ return;
199
+ }
200
+ }
201
+ function responseOf(settled) {
202
+ return new Response(settled.body, {
203
+ status: settled.status,
204
+ statusText: settled.statusText,
205
+ headers: settled.headers.map(([name, value]) => [name, value])
206
+ });
207
+ }
208
+ function unreachable(outage, now) {
209
+ return {
210
+ status: 400,
211
+ statusText: "Auth unreachable",
212
+ headers: [["content-type", "application/json"]],
213
+ body: JSON.stringify({
214
+ error_code: UNREACHABLE_CODE,
215
+ msg: "The Auth server could not be reached"
216
+ }),
217
+ at: now,
218
+ outage
219
+ };
220
+ }
221
+ /**
222
+ * A `fetch` for auth-js that sends one `grant_type=refresh_token` request per
223
+ * refresh token, however many requests ask at once, and answers repeats of the
224
+ * same token from that response for 10 seconds. Single-use refresh tokens then
225
+ * never race between parallel requests (prefetches, islands, a burst of
226
+ * navigations). Every other request passes through.
227
+ */
228
+ function coalescingFetch(options, trace) {
229
+ const base = options.fetch ?? fetch;
230
+ const now = options.now ?? Date.now;
231
+ return async (input, init) => {
232
+ const url = urlOf(input);
233
+ const token = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase() === "POST" && url.includes("grant_type=refresh_token") ? refreshTokenOf(init?.body) : void 0;
234
+ if (token === void 0) return base(input, init);
235
+ const shared = registry();
236
+ const key = `${url}\n${token}`;
237
+ const recent = shared.recent.get(key);
238
+ const settle = (settled) => {
239
+ trace.status = settled.status;
240
+ if (settled.outage) trace.outage = settled.outage;
241
+ else if (settled.status >= 400) {
242
+ const code = errorCodeOf(settled.body);
243
+ if (code !== void 0) trace.code = code;
244
+ }
245
+ return responseOf(settled);
246
+ };
247
+ if (recent && now() - recent.at < REUSE_MS) {
248
+ trace.shared = true;
249
+ return settle(recent);
250
+ }
251
+ const running = shared.inflight.get(key);
252
+ if (running) {
253
+ trace.shared = true;
254
+ return settle(await running);
255
+ }
256
+ const headers = new Headers(init?.headers);
257
+ if (options.forwardedFor) {
258
+ headers.set("apikey", options.forwardedFor.secretKey);
259
+ headers.set("sb-forwarded-for", options.forwardedFor.ip);
260
+ headers.delete("authorization");
261
+ }
262
+ const timeout = AbortSignal.timeout(options.timeoutMs ?? 5e3);
263
+ const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
264
+ const request = (async () => {
265
+ try {
266
+ const response = await base(url, {
267
+ ...init,
268
+ method: "POST",
269
+ headers,
270
+ signal
271
+ });
272
+ if (response.status >= 500 || response.status === 429) return unreachable({
273
+ cause: "status",
274
+ status: response.status
275
+ }, now());
276
+ return {
277
+ status: response.status,
278
+ statusText: response.statusText,
279
+ headers: [...response.headers],
280
+ body: await response.text(),
281
+ at: now()
282
+ };
283
+ } catch {
284
+ return unreachable({ cause: timeout.aborted ? "timeout" : "network" }, now());
285
+ }
286
+ })();
287
+ shared.inflight.set(key, request);
288
+ try {
289
+ const settled = await request;
290
+ if (!settled.outage) {
291
+ shared.recent.set(key, settled);
292
+ if (shared.recent.size > RECENT_MAX) shared.recent.delete(shared.recent.keys().next().value);
293
+ }
294
+ return settle(settled);
295
+ } finally {
296
+ shared.inflight.delete(key);
297
+ }
298
+ };
299
+ }
300
+ function capture() {
301
+ const writes = [];
302
+ const headers = {};
303
+ return {
304
+ writes,
305
+ headers,
306
+ setAll(cookies, sent = {}) {
307
+ for (const cookie of cookies) {
308
+ const at = writes.findIndex((write) => write.name === cookie.name && write.options.path === cookie.options.path && write.options.domain === cookie.options.domain);
309
+ if (at !== -1) writes.splice(at, 1);
310
+ writes.push({
311
+ name: cookie.name,
312
+ value: cookie.value,
313
+ options: cookie.options
314
+ });
315
+ }
316
+ for (const [name, value] of Object.entries(sent)) headers[name.toLowerCase()] = value;
317
+ }
318
+ };
319
+ }
320
+ function plainCookies(cookies) {
321
+ return cookies.map((cookie) => ({
322
+ name: cookie.name,
323
+ value: cookie.value
324
+ }));
325
+ }
326
+ /**
327
+ * Refreshes the cookie session with a `@supabase/ssr` server client made for
328
+ * this request alone, so it delivers the cache headers with its writes. auth-js
329
+ * rotates the token and writes the cookies; the token request goes through a
330
+ * coalescing `fetch`.
331
+ */
332
+ async function refreshCookieSession(options) {
333
+ const trace = { shared: false };
334
+ const captured = capture();
335
+ const { data, error } = await createServerClient(options.url, options.publishableKey, {
336
+ cookieOptions: {
337
+ ...options.cookieOptions,
338
+ name: options.cookieName
339
+ },
340
+ cookies: {
341
+ getAll: () => plainCookies(options.cookies),
342
+ setAll: (cookies, headers) => {
343
+ captured.setAll(cookies, headers);
344
+ },
345
+ ...options.encode === void 0 ? {} : { encode: options.encode }
346
+ },
347
+ global: { fetch: coalescingFetch(options, trace) }
348
+ }).auth.refreshSession({ refresh_token: options.refreshToken });
349
+ return {
350
+ outcome: (() => {
351
+ if (trace.outage) return {
352
+ ok: false,
353
+ reason: "network",
354
+ cause: trace.outage.cause,
355
+ ...trace.outage.status === void 0 ? {} : { status: trace.outage.status }
356
+ };
357
+ if (error || !data.session) {
358
+ const code = trace.code ?? error?.code;
359
+ return {
360
+ ok: false,
361
+ reason: code === RACED_CODE || error?.name === "AuthRefreshDiscardedError" ? "raced" : "rejected",
362
+ ...trace.status === void 0 ? {} : { status: trace.status },
363
+ ...code === void 0 ? {} : { code }
364
+ };
365
+ }
366
+ return {
367
+ ok: true,
368
+ session: {
369
+ access_token: data.session.access_token,
370
+ refresh_token: data.session.refresh_token,
371
+ ...data.session.expires_at === void 0 ? {} : { expires_at: data.session.expires_at }
372
+ },
373
+ shared: trace.shared
374
+ };
375
+ })(),
376
+ writes: captured.writes,
377
+ headers: captured.headers
378
+ };
379
+ }
380
+ /**
381
+ * The writes that clear the session cookie and its chunks at the current scope
382
+ * and at every scope in `scopes` (an old `domain` or `path`), with the cache
383
+ * headers `@supabase/ssr` sends with them.
384
+ */
385
+ async function clearCookieSession(options) {
386
+ const captured = capture();
387
+ await clearAuthCookiesAtScopes({
388
+ getAll: () => plainCookies(options.cookies),
389
+ setAll: (cookies, headers) => {
390
+ captured.setAll(cookies, headers);
391
+ },
392
+ storageKey: options.cookieName,
393
+ scopes: [...options.current === false ? [] : [{ ...options.cookieOptions }], ...options.scopes ?? []]
394
+ });
395
+ return {
396
+ writes: captured.writes,
397
+ headers: captured.writes.length > 0 ? NO_STORE : {}
398
+ };
399
+ }
400
+ /**
401
+ * The headers `@supabase/ssr` sends with session writes. Its scope-clearing
402
+ * helper sends none, and a response that clears a session must not be cached
403
+ * either.
404
+ */
405
+ const NO_STORE = Object.freeze({
406
+ "cache-control": "private, no-cache, no-store, must-revalidate, max-age=0",
407
+ expires: "0",
408
+ pragma: "no-cache"
409
+ });
212
410
  // src/auth/ended.ts
213
- const DEFAULT_TIMEOUT_MS$1 = 5e3;
411
+ const DEFAULT_TIMEOUT_MS = 5e3;
214
412
  function accessTokenOf(request, options) {
215
413
  const bearer = extractCredentials(request).token;
216
414
  if (bearer) return bearer;
@@ -228,7 +426,7 @@ async function sessionStatus(input, options) {
228
426
  apikey: options.publishableKey,
229
427
  authorization: `Bearer ${token}`
230
428
  },
231
- signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS$1)
429
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
232
430
  });
233
431
  if (response.status === 401 || response.status === 403) return (await response.json().catch(() => null))?.["error_code"] === "user_banned" ? "banned" : "ended";
234
432
  await response.body?.cancel();
@@ -237,11 +435,20 @@ async function sessionStatus(input, options) {
237
435
  return "unknown";
238
436
  }
239
437
  }
240
- function clearSessionCookies(request, response, options) {
241
- const writes = writeSession(parseCookies(request.headers.get("cookie")), options.cookieName ?? sessionCookieName(options.url), null, options.cookie);
438
+ /**
439
+ * Clears the session cookie and its chunks on `response`, with the no-store
440
+ * headers, through `@supabase/ssr`. Resolves to `response` unchanged when the
441
+ * request carries no session cookie.
442
+ */
443
+ async function clearSessionCookies(request, response, options) {
444
+ const { writes, headers } = await clearCookieSession({
445
+ cookieName: options.cookieName ?? sessionCookieName(options.url),
446
+ cookies: parseCookies(request.headers.get("cookie")),
447
+ ...options.cookie ? { cookieOptions: options.cookie } : {}
448
+ });
242
449
  if (writes.length === 0) return response;
243
450
  for (const write of writes) response.headers.append("set-cookie", serializeCookie(write));
244
- for (const [key, value] of Object.entries(AUTH_CACHE_HEADERS)) response.headers.set(key, value);
451
+ for (const [key, value] of Object.entries(headers)) response.headers.set(key, value);
245
452
  return response;
246
453
  }
247
454
  // src/auth/hs256.ts
@@ -330,122 +537,6 @@ async function verifyHs256(token, secret, options) {
330
537
  }
331
538
  };
332
539
  }
333
- // src/auth/refresh.ts
334
- /**
335
- * How long a finished refresh is reused for requests still carrying the old
336
- * refresh token (parallel page loads, prefetches). Matches the default
337
- * refresh-token reuse interval of Supabase Auth.
338
- */
339
- const REUSE_MS = 1e4;
340
- const DEFAULT_TIMEOUT_MS = 5e3;
341
- /**
342
- * Finished refreshes kept for reuse; a burst of sign-ins can't grow it past
343
- * this.
344
- */
345
- const RECENT_MAX = 1e3;
346
- const inflight = /* @__PURE__ */ new Map();
347
- const recent = /* @__PURE__ */ new Map();
348
- function shared(outcome) {
349
- return outcome.ok ? {
350
- ...outcome,
351
- shared: true
352
- } : outcome;
353
- }
354
- function prune(now) {
355
- for (const [token, entry] of recent) {
356
- if (entry.until > now) return;
357
- recent.delete(token);
358
- }
359
- }
360
- async function request(refreshToken, options, now) {
361
- const doFetch = options.fetch ?? fetch;
362
- const signal = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
363
- let response;
364
- try {
365
- response = await doFetch(`${options.url}/auth/v1/token?grant_type=refresh_token`, {
366
- method: "POST",
367
- headers: {
368
- apikey: options.forwardedFor?.secretKey ?? options.publishableKey,
369
- "content-type": "application/json",
370
- ...options.forwardedFor ? { "sb-forwarded-for": options.forwardedFor.ip } : {}
371
- },
372
- body: JSON.stringify({ refresh_token: refreshToken }),
373
- signal
374
- });
375
- } catch (cause) {
376
- return {
377
- ok: false,
378
- reason: "network",
379
- cause: signal.aborted ? "timeout" : "fetch",
380
- message: cause instanceof Error ? cause.message : "fetch failed"
381
- };
382
- }
383
- const body = await response.json().catch(() => null);
384
- if (signal.aborted) return {
385
- ok: false,
386
- reason: "network",
387
- cause: "timeout",
388
- message: "refresh timed out"
389
- };
390
- if (!response.ok || !body || typeof body["access_token"] !== "string" || typeof body["refresh_token"] !== "string") {
391
- const message = typeof body?.["msg"] === "string" ? body["msg"] : typeof body?.["error_description"] === "string" ? body["error_description"] : `Refresh failed with ${String(response.status)}`;
392
- const outage = response.status >= 500 || response.status === 429;
393
- const code = typeof body?.["error_code"] === "string" ? body["error_code"] : void 0;
394
- return {
395
- ok: false,
396
- reason: outage ? "network" : code === RACED_CODE ? "raced" : "rejected",
397
- ...outage ? { cause: "status" } : {},
398
- status: response.status,
399
- ...typeof body?.["error_code"] === "string" ? { code: body["error_code"] } : {},
400
- message
401
- };
402
- }
403
- const expiresIn = typeof body["expires_in"] === "number" ? body["expires_in"] : void 0;
404
- return {
405
- ok: true,
406
- session: {
407
- ...body,
408
- access_token: body["access_token"],
409
- refresh_token: body["refresh_token"],
410
- ...typeof body["expires_at"] !== "number" && expiresIn !== void 0 ? { expires_at: Math.floor(now / 1e3) + expiresIn } : {}
411
- }
412
- };
413
- }
414
- /** The Auth error when a request tries a refresh token another request used. */
415
- const RACED_CODE = "refresh_token_already_used";
416
- /**
417
- * Exchanges a refresh token for a new session. Concurrent calls with the same
418
- * token share one request, and a successful result is reused for a short window
419
- * so parallel requests carrying the old cookie converge on one session.
420
- */
421
- function refreshSession(refreshToken, options) {
422
- const clock = options.now ?? Date.now;
423
- const now = clock();
424
- prune(now);
425
- const key = `${options.url}\n${refreshToken}`;
426
- const cached = recent.get(key);
427
- if (cached) return Promise.resolve(shared(cached.outcome));
428
- const pending = inflight.get(key);
429
- if (pending) return pending.then(shared);
430
- const promise = request(refreshToken, options, now).then((outcome) => {
431
- if (outcome.ok || outcome.reason === "rejected") {
432
- recent.delete(key);
433
- recent.set(key, {
434
- outcome,
435
- until: clock() + REUSE_MS
436
- });
437
- if (recent.size > RECENT_MAX) {
438
- const oldest = recent.keys().next();
439
- if (!oldest.done) recent.delete(oldest.value);
440
- }
441
- }
442
- return outcome;
443
- }).finally(() => {
444
- inflight.delete(key);
445
- });
446
- inflight.set(key, promise);
447
- return promise;
448
- }
449
540
  // src/auth/resolve.ts
450
541
  function expiryOf(session) {
451
542
  if (typeof session.expires_at === "number") return session.expires_at;
@@ -459,132 +550,66 @@ function jwksOf(options) {
459
550
  if (options.jwks === false || options.jwks === null) return NO_KEYS;
460
551
  return options.jwks ?? options.env.jwks ?? options.env.jwksUrl;
461
552
  }
462
- function serverEnv(options) {
553
+ /** The `iss` the verifier requires: only one the app set. */
554
+ function issuerOf(options) {
555
+ return options.issuer === false ? void 0 : options.issuer;
556
+ }
557
+ /** A verified token whose `iss` names another issuer than the project's Auth. */
558
+ function foreignIssuer(options, claims) {
559
+ if (options.issuer !== void 0 || typeof claims.iss !== "string") return;
560
+ return claims.iss === fromSupabaseUrl(options.env.url) ? void 0 : {
561
+ kind: "invalid",
562
+ reason: "token",
563
+ error: dbError("unauthorized", "The token was issued by another project", { code: "INVALID_ISSUER" })
564
+ };
565
+ }
566
+ /**
567
+ * The keys to verify `token` with. A JWKS URL goes through the process-wide
568
+ * cache (`sharedJwks`) and is passed inline, so `@supabase/server` never keeps
569
+ * a resolver of its own; a `kid` the cached set lacks refetches it once per
570
+ * cooldown, for key rotations.
571
+ */
572
+ async function keysFor(options, token) {
573
+ const source = jwksOf(options);
574
+ if (!(source instanceof URL)) return source;
575
+ if (!token) return NO_KEYS;
576
+ const shared = {
577
+ ...options.fetch ? { fetch: options.fetch } : {},
578
+ ...options.now ? { now: options.now } : {}
579
+ };
580
+ let result = await sharedJwks(source, false, shared);
581
+ const kid = decodeJwtHeader(token)?.["kid"];
582
+ if (result.ok && typeof kid === "string" && !result.data.keys.some((key) => key["kid"] === kid)) result = await sharedJwks(source, true, shared);
583
+ return result.ok ? result.data : result.error;
584
+ }
585
+ function serverEnv(options, jwks) {
463
586
  const { env } = options;
464
587
  return {
465
588
  url: env.url,
466
589
  publishableKeys: { default: env.publishableKey },
467
590
  secretKeys: env.secretKeys ?? (env.secretKey ? { default: env.secretKey } : {}),
468
- jwks: jwksOf(options)
591
+ jwks
469
592
  };
470
593
  }
471
- const MEMO_SIZE = 256;
472
- const memoByUrl = /* @__PURE__ */ new Map();
473
- let memoByJwks = /* @__PURE__ */ new WeakMap();
474
- /** The most JWT secrets remembered at once; the oldest goes first. */
475
- const SECRET_IDS_SIZE = 64;
476
- /**
477
- * A number per JWT secret, so memo keys tell secrets apart. Bounded, and never
478
- * reuses a number.
479
- */
480
- const secretIds = /* @__PURE__ */ new Map();
481
- let nextSecretId = 1;
482
- function secretId(secret) {
483
- if (secret === void 0) return null;
484
- let id = secretIds.get(secret);
485
- if (id === void 0) {
486
- id = nextSecretId;
487
- nextSecretId += 1;
488
- secretIds.set(secret, id);
489
- if (secretIds.size > SECRET_IDS_SIZE) {
490
- const oldest = secretIds.keys().next();
491
- if (!oldest.done) secretIds.delete(oldest.value);
492
- }
493
- }
494
- return id;
495
- }
496
- /**
497
- * Tokens that already verified, until they expire. Every private-cache scope
498
- * and island resolves the same token again; this skips the signature check. A
499
- * hit skips the audience and issuer checks too, so both are part of the key.
500
- */
501
- function memoFor(options) {
502
- const jwks = jwksOf(options);
503
- const inline = !(jwks instanceof URL);
504
- const key = JSON.stringify([
505
- inline ? null : String(jwks),
506
- options.env.url,
507
- options.audience ?? null,
508
- options.issuer ?? null,
509
- secretId(options.jwtSecret)
510
- ]);
511
- if (inline) {
512
- let byKey = memoByJwks.get(jwks);
513
- if (!byKey) memoByJwks.set(jwks, byKey = /* @__PURE__ */ new Map());
514
- let memo = byKey.get(key);
515
- if (!memo) byKey.set(key, memo = /* @__PURE__ */ new Map());
516
- return memo;
517
- }
518
- let memo = memoByUrl.get(key);
519
- if (!memo) memoByUrl.set(key, memo = /* @__PURE__ */ new Map());
520
- return memo;
521
- }
522
- function remembered(memo, token, now) {
523
- const hit = memo.get(token);
524
- if (!hit) return;
525
- memo.delete(token);
526
- if (hit.expiresAt === null || hit.expiresAt <= now) return;
527
- memo.set(token, hit);
528
- return hit;
529
- }
530
- const NO_SCHEMA = {};
531
- const checkedByMemo = /* @__PURE__ */ new WeakMap();
532
- /**
533
- * Tokens that already passed (or failed) the claims and `userMetadata` schemas,
534
- * per verification memo and schema pair, so a memo hit skips validation too.
535
- */
536
- function checkedFor(memo, options) {
537
- const claims = options.claims ?? NO_SCHEMA;
538
- const metadata = options.userMetadata ?? NO_SCHEMA;
539
- let byClaims = checkedByMemo.get(memo);
540
- if (!byClaims) checkedByMemo.set(memo, byClaims = /* @__PURE__ */ new WeakMap());
541
- let byMetadata = byClaims.get(claims);
542
- if (!byMetadata) byClaims.set(claims, byMetadata = /* @__PURE__ */ new WeakMap());
543
- let checked = byMetadata.get(metadata);
544
- if (!checked) byMetadata.set(metadata, checked = /* @__PURE__ */ new Map());
545
- return checked;
546
- }
547
- function withoutSource(state) {
548
- if (state.kind !== "user") return state;
549
- const { source: _source, ...rest } = state;
550
- return rest;
551
- }
552
- function remember(memo, token, user, expiresAt) {
553
- if (expiresAt === null) return;
554
- memo.set(token, user);
555
- if (memo.size > MEMO_SIZE) memo.delete(memo.keys().next().value);
594
+ async function verifyAndCheck(credentials, modes, options, source) {
595
+ return checkUser(await verifyOnce(credentials, modes, options, source), options);
556
596
  }
557
597
  async function verify(credentials, modes, options, source) {
558
598
  const token = modes.length === 1 && modes[0] === "user" && credentials.token;
559
- const memo = token ? memoFor(options) : void 0;
560
- if (token && memo) {
561
- const hit = remembered(memo, token, Math.floor((options.now ?? Date.now)() / 1e3));
562
- if (hit) {
563
- const checked = checkedFor(memo, options);
564
- const known = checked.get(token);
565
- if (known) return known.kind === "user" ? {
566
- ...known,
567
- source
568
- } : known;
569
- const state = await checkUser({
570
- ...hit,
571
- source
572
- }, options);
573
- remember(checked, token, withoutSource(state), hit.expiresAt);
574
- return state;
575
- }
576
- }
577
- const state = await verifyOnce(credentials, modes, options, source);
578
- if (token && memo && state.kind === "user") remember(memo, token, {
579
- kind: "user",
580
- token: state.token,
581
- claims: state.claims,
582
- user: state.user,
583
- expiresAt: state.expiresAt
584
- }, state.expiresAt);
585
- const checked = await checkUser(state, options);
586
- if (token && memo && state.kind === "user") remember(checkedFor(memo, options), token, withoutSource(checked), state.expiresAt);
587
- return checked;
599
+ const { memo } = options;
600
+ if (!token || !memo) return verifyAndCheck(credentials, modes, options, source);
601
+ let unstored;
602
+ const found = await memo.get(token, async () => {
603
+ const state = await verifyAndCheck(credentials, modes, options, source);
604
+ if (state.kind === "user" && state.expiresAt !== null) return state;
605
+ unstored = state;
606
+ return null;
607
+ });
608
+ if (found) return found.source === source ? found : {
609
+ ...found,
610
+ source
611
+ };
612
+ return unstored ?? verifyAndCheck(credentials, modes, options, source);
588
613
  }
589
614
  /** Validates a user's claims against `options.claims`, keeping every JWT claim. */
590
615
  async function checkClaims(state, options) {
@@ -639,44 +664,34 @@ async function checkUser(state, options) {
639
664
  }
640
665
  return user;
641
666
  }
642
- /** A token whose `kid` matches no key: verifying it loads the JWKS and fails. */
643
- const PREFETCH_TOKEN = `${base64url(JSON.stringify({
644
- alg: "ES256",
645
- kid: "better-supabase-prefetch",
646
- typ: "JWT"
647
- }))}.e30.AA`;
648
- function base64url(text) {
649
- return btoa(text).replaceAll("+", "-").replaceAll("/", "_").replace(/[=]+$/, "");
650
- }
651
667
  /**
652
- * Loads the remote JWKS into the verifier's cache so the first request doesn't
653
- * wait for it. Never throws; a failure leaves the first request to fetch it as
654
- * before.
668
+ * Loads the remote JWKS into the process-wide cache so the first request
669
+ * doesn't wait for it. Never throws; a failure leaves the first request to
670
+ * fetch it.
655
671
  */
656
- function prefetchJwks(options) {
657
- if (!(jwksOf(options) instanceof URL)) return Promise.resolve();
658
- return verifyCredentials({
659
- token: PREFETCH_TOKEN,
660
- apikey: null
661
- }, {
662
- auth: ["user"],
663
- env: serverEnv(options)
664
- }).then(() => void 0, () => void 0);
672
+ async function prefetchJwks(options) {
673
+ const source = jwksOf(options);
674
+ if (!(source instanceof URL)) return;
675
+ await sharedJwks(source, false, {
676
+ ...options.fetch ? { fetch: options.fetch } : {},
677
+ ...options.now ? { now: options.now } : {}
678
+ }).catch(() => void 0);
665
679
  }
666
680
  async function verifyOnce(credentials, modes, options, source) {
667
681
  const token = credentials.token;
682
+ const issuer = issuerOf(options);
668
683
  if (options.jwtSecret !== void 0 && token && modes.length === 1 && modes[0] === "user" && isSharedSecretToken(token)) {
669
684
  const verified = await verifyHs256(token, options.jwtSecret, {
670
685
  now: Math.floor((options.now ?? Date.now)() / 1e3),
671
686
  ...options.audience === void 0 ? {} : { audience: options.audience },
672
- ...options.issuer === void 0 ? {} : { issuer: options.issuer }
687
+ ...issuer === void 0 ? {} : { issuer }
673
688
  });
674
689
  if (!verified.ok) return {
675
690
  kind: "invalid",
676
691
  reason: "token",
677
692
  error: dbError("unauthorized", verified.message, { code: verified.code })
678
693
  };
679
- return {
694
+ return foreignIssuer(options, verified.claims) ?? {
680
695
  kind: "user",
681
696
  token,
682
697
  claims: verified.claims,
@@ -685,11 +700,17 @@ async function verifyOnce(credentials, modes, options, source) {
685
700
  expiresAt: typeof verified.claims.exp === "number" ? verified.claims.exp : null
686
701
  };
687
702
  }
703
+ const keys = await keysFor(options, token);
704
+ if (!("keys" in keys)) return {
705
+ kind: "invalid",
706
+ reason: "token",
707
+ error: keys
708
+ };
688
709
  const { data, error } = await verifyCredentials(credentials, {
689
710
  auth: modes,
690
- env: serverEnv(options),
711
+ env: serverEnv(options, keys),
691
712
  ...options.audience === void 0 ? {} : { audience: options.audience },
692
- ...options.issuer === void 0 ? {} : { issuer: options.issuer }
713
+ ...issuer === void 0 ? {} : { issuer }
693
714
  });
694
715
  if (error) {
695
716
  const kind = error.code === "JWKS_FETCH_FAILED" ? "network" : error.status >= 500 ? "unexpected" : "unauthorized";
@@ -703,7 +724,7 @@ async function verifyOnce(credentials, modes, options, source) {
703
724
  kind: "secret",
704
725
  keyName: data.keyName ?? "default"
705
726
  };
706
- if (data.authMode === "user" && data.token && data.jwtClaims && data.userClaims) return {
727
+ if (data.authMode === "user" && data.token && data.jwtClaims && data.userClaims) return foreignIssuer(options, data.jwtClaims) ?? {
707
728
  kind: "user",
708
729
  token: data.token,
709
730
  claims: data.jwtClaims,
@@ -716,8 +737,13 @@ async function verifyOnce(credentials, modes, options, source) {
716
737
  reason: "none"
717
738
  };
718
739
  }
719
- function resolution(auth, cookies, writes = [], rejected, outage) {
720
- const headers = writes.length > 0 ? AUTH_CACHE_HEADERS : {};
740
+ const NO_CHANGE = {
741
+ writes: [],
742
+ headers: {}
743
+ };
744
+ function resolution(auth, cookies, change = NO_CHANGE, rejected, outage) {
745
+ const { writes } = change;
746
+ const headers = writes.length === 0 ? {} : Object.keys(change.headers).length > 0 ? change.headers : NO_STORE;
721
747
  let requestCookies;
722
748
  return {
723
749
  auth,
@@ -757,24 +783,6 @@ function clientIp(request) {
757
783
  const last = request.headers.get("x-forwarded-for")?.split(",").at(-1)?.trim();
758
784
  return last && IP.test(last) ? last : void 0;
759
785
  }
760
- /**
761
- * Resolves who is calling: custom resolvers, then `Authorization: Bearer`
762
- * (APIs, MCP, mobile), then the `@supabase/ssr` session cookie (browsers).
763
- *
764
- * A valid token costs no network call: it is verified locally against the
765
- * cached JWKS. An expiring cookie session is refreshed only when `refresh` is
766
- * set, through a single-flight request, and only then are cookies written.
767
- */
768
- /**
769
- * The access token `resolveAuth` would verify for `request`, without verifying
770
- * it: the bearer token, else the session cookie's. `null` when there is none.
771
- */
772
- function requestToken(request, cookieName, cookies = true) {
773
- const credentials = extractCredentials(request);
774
- if (credentials.token) return credentials.token;
775
- if (!cookies) return null;
776
- return readSession(parseCookies(request.headers.get("cookie")), cookieName)?.access_token ?? null;
777
- }
778
786
  async function timed(options, phase, work) {
779
787
  if (!options.onTiming) return work();
780
788
  const started = performance.now();
@@ -789,7 +797,6 @@ async function resolveAuth(request, options) {
789
797
  const cookies = () => parsed ??= parseCookies(request.headers.get("cookie"));
790
798
  const verifyTimed = (...args) => timed(options, "verify", () => verify(...args));
791
799
  const statusTimed = (...args) => timed(options, "ended", () => sessionStatus(...args));
792
- const refreshTimed = (...args) => timed(options, "refresh", () => refreshSession(...args));
793
800
  for (const resolver of options.resolvers ?? []) {
794
801
  const state = await resolver.resolve(request);
795
802
  if (!state) continue;
@@ -813,19 +820,21 @@ async function resolveAuth(request, options) {
813
820
  reason: "none"
814
821
  }, cookies);
815
822
  const name = options.cookie?.name ?? sessionCookieName(options.env.url);
816
- const encoding = options.cookie?.encode === void 0 ? {} : { encode: options.cookie.encode };
817
823
  const parseStarted = options.onTiming ? performance.now() : 0;
818
824
  const session = readSession(cookies(), name);
819
825
  options.onTiming?.("parse", performance.now() - parseStarted);
826
+ const cleared = () => clearCookieSession({
827
+ cookieName: name,
828
+ cookies: cookies(),
829
+ ...options.cookie?.options ? { cookieOptions: options.cookie.options } : {}
830
+ });
820
831
  if (!session) {
821
832
  const stale = cookies().some((cookie) => cookie.name === name || cookie.name.startsWith(`${name}.`));
822
- const writes = stale && options.refresh ? writeSession(cookies(), name, null, options.cookie?.options, encoding) : [];
823
833
  return resolution({
824
834
  kind: "none",
825
835
  reason: stale ? "signed_out" : "none"
826
- }, cookies, writes);
836
+ }, cookies, stale && options.refresh ? await cleared() : NO_CHANGE);
827
837
  }
828
- const pruned = options.refresh && options.pruneChunks !== false ? pruneSessionChunks(cookies(), name, options.cookie?.options) : [];
829
838
  const now = Math.floor((options.now ?? Date.now)() / 1e3);
830
839
  const expiry = expiryOf(session);
831
840
  const leeway = options.refresh ? options.leeway ?? 60 : 0;
@@ -845,8 +854,8 @@ async function resolveAuth(request, options) {
845
854
  if (status === "ended" || status === "banned") return resolution({
846
855
  kind: "none",
847
856
  reason: "signed_out"
848
- }, cookies, options.refresh ? writeSession(cookies(), name, null, options.cookie?.options, encoding) : [], status === "banned" ? "user_banned" : "session_not_found");
849
- if (state.kind !== "invalid" || state.reason !== "token" || state.error.kind === "network") return resolution(state, cookies, pruned);
857
+ }, cookies, options.refresh ? await cleared() : NO_CHANGE, status === "banned" ? "user_banned" : "session_not_found");
858
+ if (state.kind !== "invalid" || state.reason !== "token" || state.error.kind === "network") return resolution(state, cookies);
850
859
  if (!options.refresh) return resolution({
851
860
  kind: "none",
852
861
  reason: "signed_out"
@@ -858,9 +867,14 @@ async function resolveAuth(request, options) {
858
867
  const secretKey = options.env.secretKey;
859
868
  const ip = secretKey && options.clientIp !== false ? (options.clientIp ?? clientIp)(request) : void 0;
860
869
  const started = performance.now();
861
- const outcome = await refreshTimed(session.refresh_token, {
870
+ const refreshed = await timed(options, "refresh", () => refreshCookieSession({
862
871
  url: options.env.url,
863
872
  publishableKey: options.env.publishableKey,
873
+ cookieName: name,
874
+ cookies: cookies(),
875
+ refreshToken: session.refresh_token,
876
+ ...options.cookie?.options ? { cookieOptions: options.cookie.options } : {},
877
+ ...options.cookie?.encode === void 0 ? {} : { encode: options.cookie.encode },
864
878
  ...secretKey && ip ? { forwardedFor: {
865
879
  ip,
866
880
  secretKey
@@ -868,60 +882,56 @@ async function resolveAuth(request, options) {
868
882
  ...options.fetch ? { fetch: options.fetch } : {},
869
883
  ...options.now ? { now: options.now } : {},
870
884
  ...options.refreshTimeoutMs === void 0 ? {} : { timeoutMs: options.refreshTimeoutMs }
871
- });
885
+ }));
886
+ const { outcome } = refreshed;
872
887
  const durationMs = performance.now() - started;
873
888
  options.onRefresh?.({
874
889
  ok: outcome.ok,
875
- shared: outcome.ok && outcome.shared === true,
890
+ shared: outcome.ok && outcome.shared,
876
891
  durationMs,
877
892
  ...outcome.ok ? {} : {
878
893
  reason: outcome.reason,
879
894
  ...outcome.status === void 0 ? {} : { status: outcome.status },
880
- ...outcome.code === void 0 ? {} : { code: outcome.code }
895
+ ..."code" in outcome ? { code: outcome.code } : {}
881
896
  }
882
897
  });
883
898
  if (!outcome.ok) {
884
- if (outcome.reason === "network") {
885
- const outage = (kept) => ({
886
- cause: outcome.cause === "timeout" ? "timeout" : outcome.cause === "status" ? "status" : "network",
887
- ...outcome.status === void 0 ? {} : { status: outcome.status },
888
- kept,
889
- durationMs
890
- });
891
- if (!fresh && expiry !== void 0 && expiry > now) {
892
- const state = await verifyTimed({
893
- token: session.access_token,
894
- apikey: null
895
- }, ["user"], options, "cookie");
896
- if (state.kind !== "invalid") return resolution(state, cookies, pruned, void 0, outage(true));
897
- }
898
- return resolution({
899
- kind: "none",
900
- reason: "refresh_failed"
901
- }, cookies, pruned, void 0, outage(false));
902
- }
903
- if (outcome.reason === "raced") {
904
- if (!fresh && expiry !== void 0 && expiry > now) {
905
- const state = await verifyTimed({
906
- token: session.access_token,
907
- apikey: null
908
- }, ["user"], options, "cookie");
909
- if (state.kind !== "invalid") return resolution(state, cookies, pruned);
899
+ const stillValid = async () => {
900
+ if (fresh || expiry === void 0 || expiry <= now) return;
901
+ const state = await verifyTimed({
902
+ token: session.access_token,
903
+ apikey: null
904
+ }, ["user"], options, "cookie");
905
+ return state.kind === "invalid" ? void 0 : state;
906
+ };
907
+ switch (outcome.reason) {
908
+ case "network": {
909
+ const kept = await stillValid();
910
+ const outage = {
911
+ cause: outcome.cause,
912
+ ...outcome.status === void 0 ? {} : { status: outcome.status },
913
+ kept: kept !== void 0,
914
+ durationMs
915
+ };
916
+ return resolution(kept ?? {
917
+ kind: "none",
918
+ reason: "refresh_failed"
919
+ }, cookies, NO_CHANGE, void 0, outage);
910
920
  }
911
- return resolution({
921
+ case "raced": return resolution(await stillValid() ?? {
912
922
  kind: "none",
913
923
  reason: "expired"
914
- }, cookies, pruned);
924
+ }, cookies);
925
+ case "rejected": return resolution({
926
+ kind: "none",
927
+ reason: "signed_out"
928
+ }, cookies, refreshed.writes.length > 0 ? refreshed : await cleared(), outcome.code === "user_banned" ? "user_banned" : void 0);
929
+ default: return outcome;
915
930
  }
916
- return resolution({
917
- kind: "none",
918
- reason: "signed_out"
919
- }, cookies, writeSession(cookies(), name, null, options.cookie?.options, encoding), outcome.code === "user_banned" ? "user_banned" : void 0);
920
931
  }
921
- const writes = writeSession(cookies(), name, outcome.session, options.cookie?.options, encoding);
922
932
  return resolution(await verifyTimed({
923
933
  token: outcome.session.access_token,
924
934
  apikey: null
925
- }, ["user"], options, "cookie"), cookies, writes);
935
+ }, ["user"], options, "cookie"), cookies, refreshed);
926
936
  }
927
- export { sessionEncoding as _, refreshSession as a, AUTH_CACHE_HEADERS as c, clearSessionAtScopes as d, parseCookies as f, sessionCookieName as g, serializeCookie as h, resolveAuth as i, DEFAULT_SESSION_ENCODING as l, readSession as m, prefetchJwks as n, clearSessionCookies as o, pruneSessionChunks as p, requestToken as r, sessionStatus as s, clientIp as t, applyCookieWrites as u, writeSession as v };
937
+ export { sessionStatus as a, parseCookies as c, sessionCookieName as d, writeSession as f, clearSessionCookies as i, readSession as l, prefetchJwks as n, clearCookieSession as o, resolveAuth as r, applyCookieWrites as s, clientIp as t, serializeCookie as u };