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,6 +1,6 @@
1
1
  import { t as DbException } from "../db-exception-Dv18UZ-I.js";
2
2
  import { n as dbError } from "../errors-B7tCfCvX.js";
3
- import { t as isList } from "../guards-CsRa6v57.js";
3
+ import { n as isRecord, t as isList } from "../guards-CsRa6v57.js";
4
4
  import { t as isStorageApi } from "../storage-api-COQr77e8.js";
5
5
  import { a as ok, r as err } from "../result-8xza7w5W.js";
6
6
  import { o as isReadSet } from "../read-set-DEDoIHMM.js";
@@ -15,25 +15,57 @@ import { n as methodOf } from "../block-method-DIbWG4Mj.js";
15
15
  import { t as tenantOf } from "../tenant-Beqd7TTq.js";
16
16
  import { t as loadTimeline } from "../timeline-Bs-FGMIJ.js";
17
17
  import { r as permissionsOf } from "../permissions-BDt27oYF.js";
18
- import { a as sessionCacheKey, i as issuedAtOf, n as authzVersionOf, r as isSessionSnapshot, s as snapshotOf, t as authOfSnapshot } from "../snapshot-CVMSyTHH.js";
19
- import { i as toSession, s as checkAal } from "../view-BfEqjZJ_.js";
20
- import { c as extendServer, n as flushEvents, p as supportCookieMaxAge, r as handle, s as createServer, t as bearerRequest, v as outageResponse, x as serverCore } from "../adapter-CWzyKepA.js";
21
- import { t as isPrefetch } from "../refresh-B8t_KE3s.js";
22
- import { d as clearSessionAtScopes, g as sessionCookieName, t as clientIp, u as applyCookieWrites, v as writeSession } from "../resolve-FW8oeXvh.js";
23
- import { i as guard, n as defaultExpose, s as settle } from "../respond-DLH4tD2d.js";
24
- import { a as needsMfa, c as pkceGrant, d as safeRedirectPath, f as supportSessions, i as mfaGrant, l as pkcePair, n as emailFlow, o as otpGrant, r as isExistingAccount, s as passwordGrant, t as authorizeUrlFor, u as revokeSession } from "../sign-in-BMm1xhKq.js";
25
- import { i as defineAction } from "../resource-BbWk4hoP.js";
18
+ import { a as sessionCacheKey, i as issuedAtOf, n as authzVersionOf, r as isSessionSnapshot, s as snapshotOf, t as authOfSnapshot } from "../snapshot-BOA7lkRg.js";
19
+ import { i as toSession, s as checkAal } from "../view-Ch0Qtr36.js";
20
+ import { c as extendServer, n as flushEvents, p as supportCookieMaxAge, r as handle, s as createServer, t as bearerRequest, v as outageResponse, x as serverCore } from "../adapter-ddQ9Hzka.js";
21
+ import { t as isDocumentLoad } from "../request-kind-tNDM5Z_o.js";
22
+ import { d as sessionCookieName, f as writeSession, o as clearCookieSession, s as applyCookieWrites, t as clientIp } from "../resolve-CZV31iCm.js";
23
+ import { i as guard, n as defaultExpose, s as settle } from "../respond-8A3EOo61.js";
24
+ import { a as needsMfa, c as pkceGrant, d as safeRedirectPath, f as supportSessions, i as mfaGrant, l as pkcePair, n as emailFlow, o as otpGrant, r as isExistingAccount, s as passwordGrant, t as authorizeUrlFor, u as revokeSession } from "../sign-in-k2lXELeC.js";
25
+ import { i as defineAction } from "../resource-COaS9_i8.js";
26
26
  import { r as tagFor, t as cacheTagsOf } from "../tags-CW-KvjdL.js";
27
- import { i as requireCaller, n as formDataObject, t as authorizeCaller } from "../kit-9pZP5iLU.js";
27
+ import { i as requireCaller, n as formDataObject, t as authorizeCaller } from "../kit-D5rRAKWJ.js";
28
28
  import { t as withExtra } from "../extra-Dz9n5y1s.js";
29
- import { n as resourceRouter } from "../resources-DYSx9NYM.js";
29
+ import { n as resourceRouter } from "../resources-DhiK3yLO.js";
30
+ import { a as toResponse, n as bufferInPlace, t as around } from "../shared-Ci1g9nl4.js";
30
31
  import { cache } from "react";
31
32
  import { cacheLife, cacheTag, io, revalidateTag, updateTag } from "next/cache.js";
33
+ import { redirect } from "next/dist/client/components/redirect.js";
32
34
  import { cookies, headers } from "next/headers.js";
33
35
  import { NextResponse, after } from "next/server.js";
34
36
  import { forbidden } from "next/dist/client/components/forbidden.js";
35
37
  import { notFound } from "next/dist/client/components/not-found.js";
36
38
  import { unauthorized } from "next/dist/client/components/unauthorized.js";
39
+ // src/next/bootstrap.ts
40
+ /**
41
+ * The schema a `bsb.bootstrap()` call targets: the call's, then
42
+ * `bootstrapSchema`, then the one `gen` recorded, else `better_supabase`.
43
+ */
44
+ function bootstrapSchema(call, options, owner) {
45
+ return call.schema ?? options.bootstrapSchema ?? owner.meta.bootstrap?.schema ?? "better_supabase";
46
+ }
47
+ /** Calls `<schema>.bootstrap_<rpc>(args)` and checks the row it returns. */
48
+ async function runBootstrap(executor, schema, rpc, args) {
49
+ if (!executor.rpc) throw new DbException(dbError("unsupported", "bsb.bootstrap() needs an executor that calls functions"));
50
+ const result = await executor.rpc(`bootstrap_${rpc}`, { args }, {
51
+ schema,
52
+ errorMappers: []
53
+ });
54
+ if (!result.ok) throw new DbException(result.error);
55
+ return bootstrapRow(result.data);
56
+ }
57
+ /** The wrapper's jsonb, checked: a row the wrapper didn't write throws. */
58
+ function bootstrapRow(value) {
59
+ if (!isRecord(value) || typeof value["session_active"] !== "boolean") throw new DbException(dbError("unexpected", "The bootstrap wrapper returned no session_active"));
60
+ const version = value["authz_version"];
61
+ const tenant = value["tenant"];
62
+ return {
63
+ sessionActive: value["session_active"],
64
+ authzVersion: typeof version === "number" ? version : typeof version === "string" && /^\d+$/.test(version) ? Number(version) : null,
65
+ tenant: typeof tenant === "string" ? tenant : null,
66
+ data: value["data"] ?? null
67
+ };
68
+ }
37
69
  // src/next/cache.ts
38
70
  /** The tag `bsb.cached()` adds to entries rendered in a support session. */
39
71
  function supportTag(sessionId) {
@@ -41,28 +73,55 @@ function supportTag(sessionId) {
41
73
  }
42
74
  /** The shortest time the Next.js client router keeps a prefetched entry. */
43
75
  const MIN_CLIENT_STALE = 30;
76
+ /** The shortest `stale` a private entry needs to ride in the App Shell. */
77
+ const APP_SHELL_STALE = 300;
78
+ /** `"use cache: remote"` lifetimes when `life` leaves them unset. */
79
+ const REMOTE_LIFE = {
80
+ revalidate: 300,
81
+ expire: 3600
82
+ };
83
+ const warned = /* @__PURE__ */ new Set();
84
+ /** Logs `message` once per process. */
85
+ function warnOnce(warn, message) {
86
+ if (!warned.has(message)) {
87
+ warned.add(message);
88
+ warn(message);
89
+ }
90
+ }
44
91
  /**
45
- * `cacheLife` `stale` seconds for a view of `session`: `max`, but never past
46
- * the token's expiry, and 0 once fewer than `min` seconds are left. A
47
- * signed-out view that a refresh would change (an `expired` or `refresh_failed`
48
- * cookie, or an `invalid` token) is 0 as well, so it never joins the App
49
- * Shell.
92
+ * Whether a refresh or a sign-in would change the view, so no shell may keep
93
+ * it.
50
94
  */
51
- function sessionStale(session, options = {}, now = Date.now()) {
52
- const min = Math.max(MIN_CLIENT_STALE, options.min ?? MIN_CLIENT_STALE);
53
- const max = options.max ?? 300;
54
- switch (session.kind) {
55
- case "invalid": return 0;
56
- case "none": return session.reason === "expired" || session.reason === "refresh_failed" ? 0 : max;
57
- case "secret":
58
- case "apiKey": return max;
59
- case "user": {
60
- if (session.expiresAt === null) return max;
61
- const remaining = session.expiresAt - Math.floor(now / 1e3);
62
- return remaining < min ? 0 : Math.min(max, remaining);
63
- }
64
- default: return session;
65
- }
95
+ function changesOnRefresh(session) {
96
+ return session.kind === "invalid" || session.kind === "none" && (session.reason === "expired" || session.reason === "refresh_failed");
97
+ }
98
+ /** Seconds left on the token, or `undefined` for a view without one. */
99
+ function tokenSecondsLeft(session, now) {
100
+ return session.kind === "user" && session.expiresAt !== null ? session.expiresAt - Math.floor(now / 1e3) : void 0;
101
+ }
102
+ /**
103
+ * The `cacheLife` of a `bsb.cached()` entry. `stale` is `life.stale`, else 300
104
+ * seconds, so the entry rides in the App Shell; the token's lifetime caps it
105
+ * only with `capToToken`, because the proxy refreshes prefetches and the
106
+ * session tags are evicted on sign-out. A view that a refresh would change (an
107
+ * `expired` or `refresh_failed` cookie, an `invalid` token) is 0. Remote
108
+ * entries default to `revalidate` 300 and `expire` 3600. In development a
109
+ * `stale` below 300 warns that the entry leaves the App Shell, and below 30
110
+ * that it leaves the prerender.
111
+ */
112
+ function cachedLife(session, scope, life = {}, options = {}) {
113
+ const { warn } = options;
114
+ if (warn && life.stale !== void 0 && life.stale < APP_SHELL_STALE) warnOnce(warn, life.stale < MIN_CLIENT_STALE ? `bsb.cached(): life.stale ${String(life.stale)} is below 30 seconds, so the entry leaves the prerender and renders on every request` : `bsb.cached(): life.stale ${String(life.stale)} is below 300 seconds, so the entry leaves the App Shell and instant navigations wait for it`);
115
+ let stale = changesOnRefresh(session) ? 0 : life.stale ?? APP_SHELL_STALE;
116
+ const left = life.capToToken ? tokenSecondsLeft(session, options.now ?? Date.now()) : void 0;
117
+ if (left !== void 0) stale = left < MIN_CLIENT_STALE ? 0 : Math.min(stale, left);
118
+ const revalidate = life.revalidate ?? (scope === "remote" ? REMOTE_LIFE.revalidate : void 0);
119
+ const expire = life.expire ?? (scope === "remote" ? REMOTE_LIFE.expire : void 0);
120
+ return {
121
+ stale,
122
+ ...revalidate === void 0 ? {} : { revalidate },
123
+ ...expire === void 0 ? {} : { expire }
124
+ };
66
125
  }
67
126
  /** The tag `bsb.cached()` puts on a user's entries. */
68
127
  function sessionTag(userId) {
@@ -455,6 +514,56 @@ function recordListServer(bsb, recordList) {
455
514
  } : result;
456
515
  } };
457
516
  }
517
+ // src/next/remote-handoff.ts
518
+ const HANDOFFS = Symbol.for("better-supabase.remote-handoffs");
519
+ /**
520
+ * The handoff slot, on `globalThis` so the proxy's and the render's module
521
+ * graphs share it.
522
+ */
523
+ function handoffs() {
524
+ const scope = globalThis;
525
+ scope[HANDOFFS] ??= /* @__PURE__ */ new Map();
526
+ return scope[HANDOFFS];
527
+ }
528
+ /**
529
+ * The handoff entry for a key. It holds only what the key parts name, so a
530
+ * token registered under it belongs to that user and session.
531
+ */
532
+ function handoffKey(key) {
533
+ const owner = key.shared === null ? `${key.userId ?? "-"}:${key.sessionId ?? "*"}:${String(key.authzVersion ?? 0)}` : `key:${key.shared}`;
534
+ return key.support === null ? owner : `${owner}:support:${key.support}`;
535
+ }
536
+ /**
537
+ * Registers the caller's verified snapshot for one call and returns its
538
+ * release. Concurrent calls under one key count up, so the first to finish
539
+ * leaves the token for the others.
540
+ */
541
+ function handOff(key, snapshot) {
542
+ const slot = handoffKey(key);
543
+ const map = handoffs();
544
+ const entry = map.get(slot);
545
+ if (entry) {
546
+ entry.count += 1;
547
+ entry.snapshot = snapshot;
548
+ } else map.set(slot, {
549
+ snapshot,
550
+ count: 1
551
+ });
552
+ let released = false;
553
+ return () => {
554
+ if (released) return;
555
+ released = true;
556
+ const current = map.get(slot);
557
+ if (current) {
558
+ current.count -= 1;
559
+ if (current.count <= 0) map.delete(slot);
560
+ }
561
+ };
562
+ }
563
+ /** The snapshot a running call registered under the key. */
564
+ function takeHandoff(key) {
565
+ return handoffs().get(handoffKey(key))?.snapshot;
566
+ }
458
567
  // src/next/resources.ts
459
568
  /** One handler for every method; the resource router picks the operation. */
460
569
  function resourceRoutes(serve) {
@@ -466,9 +575,39 @@ function resourceRoutes(serve) {
466
575
  DELETE: serve
467
576
  };
468
577
  }
578
+ // src/next/session-tags.ts
579
+ /** The user's session tag and the authorization provider's tags for them. */
580
+ function userSessionTags(hooks, userId) {
581
+ return [sessionTag(userId), ...hooks?.sessionTags?.(userId) ?? []];
582
+ }
583
+ /**
584
+ * Drops the caller's own cached entries and evicts them from the version cache.
585
+ * Only the caller's verified snapshot decides whose, so the action is safe to
586
+ * expose.
587
+ */
588
+ async function refreshCallerCache(snapshot, server) {
589
+ if (!snapshot) return;
590
+ invalidateAll([...userSessionTags(server.authorization, snapshot.userId), ...snapshot.sessionId === null ? [] : [sessionIdTag(snapshot.sessionId)]]);
591
+ await server.evictSession(snapshot.userId);
592
+ }
469
593
  // src/next/sign-in.ts
470
594
  /** How long the PKCE verifier cookie lives, in seconds. */
471
595
  const VERIFIER_MAX_AGE = 600;
596
+ /**
597
+ * Where to send the user after signing in: the `next` value of the search
598
+ * params (a `URLSearchParams`, a page's `searchParams` object or a request)
599
+ * when it is a same-origin path, else `fallback`.
600
+ *
601
+ * ```ts
602
+ * redirect(postAuthPath(await searchParams, "/dashboard"));
603
+ * ```
604
+ */
605
+ function postAuthPath(source, fallback) {
606
+ if (source instanceof Request) return safeRedirectPath(new URL(source.url).searchParams.get("next"), fallback);
607
+ if (source instanceof URLSearchParams) return safeRedirectPath(source.get("next"), fallback);
608
+ const next = source["next"];
609
+ return safeRedirectPath(typeof next === "string" ? next : next?.[0], fallback);
610
+ }
472
611
  function refused(auth) {
473
612
  return {
474
613
  ok: false,
@@ -548,7 +687,12 @@ function authFlows(deps) {
548
687
  if (stored && resolution.auth.kind !== "user") return refused(resolution.auth);
549
688
  const jar = await deps.jar();
550
689
  const existing = jar.getAll();
551
- const writes = [...writeSession(existing, cookieName(), stored, auth?.cookie?.options, auth?.cookie?.encode === void 0 ? {} : { encode: auth.cookie.encode }), ...stored ? [] : clearSessionAtScopes(existing, cookieName(), deps.cookieScopes ?? [])];
690
+ const writes = stored ? writeSession(existing, cookieName(), stored, auth?.cookie?.options, auth?.cookie?.encode === void 0 ? {} : { encode: auth.cookie.encode }) : (await clearCookieSession({
691
+ cookieName: cookieName(),
692
+ cookies: existing,
693
+ ...auth?.cookie?.options ? { cookieOptions: auth.cookie.options } : {},
694
+ scopes: deps.cookieScopes ?? []
695
+ })).writes;
552
696
  for (const write of writes) jar.set(write.name, write.value, write.options);
553
697
  const headers = new Headers((await deps.request()).headers);
554
698
  headers.set("cookie", applyCookieWrites(existing, writes).map((cookie) => `${cookie.name}=${encodeURIComponent(cookie.value)}`).join("; "));
@@ -666,31 +810,15 @@ function endedRedirect(request, path, reason) {
666
810
  target.searchParams.set("reason", reason);
667
811
  return NextResponse.redirect(target);
668
812
  }
669
- function shouldCheckSession(request, options = {}) {
670
- if (request.method !== "GET" && request.method !== "HEAD") return false;
671
- if (isPrefetch(request) || !isDocument(request)) return false;
672
- return options.paths?.includes(request.nextUrl.pathname) ?? true;
673
- }
674
- /** A top-level page load, not an RSC request, a fetch or an iframe. */
675
- function isDocument(request) {
676
- const h = request.headers;
677
- if (h.get("rsc") === "1") return false;
678
- const dest = h.get("sec-fetch-dest");
679
- if (dest) return dest === "document";
680
- return h.get("accept")?.includes("text/html") ?? false;
681
- }
682
813
  /**
683
- * Page loads, client navigations and server actions; never prefetches or
684
- * assets.
814
+ * Whether the proxy asks Auth if the session still exists: top-level document
815
+ * loads (`sec-fetch-dest: document`) on `options.paths`, else on every path.
816
+ * Next.js strips its router headers before the proxy runs, so client
817
+ * navigations and prefetches are told apart by the browser's own headers.
685
818
  */
686
- function shouldRefresh(request) {
687
- const h = request.headers;
688
- if (request.method !== "GET" && request.method !== "HEAD") return h.has("next-action");
689
- if (isPrefetch(request)) return false;
690
- if (h.get("rsc") === "1") return true;
691
- const dest = h.get("sec-fetch-dest");
692
- if (dest) return dest === "document";
693
- return h.get("accept")?.includes("text/html") ?? false;
819
+ function shouldCheckSession(request, options = {}) {
820
+ if (!isDocumentLoad(request)) return false;
821
+ return options.paths?.includes(request.nextUrl.pathname) ?? true;
694
822
  }
695
823
  /**
696
824
  * A `proxy` `protect` that keeps signed-in users below `level` out of the
@@ -792,6 +920,7 @@ function createNext(betterSupabase, options = {}) {
792
920
  await cookies();
793
921
  return incomingRequest();
794
922
  };
923
+ const userTags = (userId) => userSessionTags(base.authorization, userId);
795
924
  const forget = (userId) => {
796
925
  base.evictSession(userId).catch((cause) => {
797
926
  betterSupabase.events.logger.warn("Could not evict the user's session", { cause });
@@ -827,6 +956,18 @@ function createNext(betterSupabase, options = {}) {
827
956
  });
828
957
  const getClaims = () => getClaimsAt(box().generation);
829
958
  const tenantClaim = claimsOf(betterSupabase.meta).tenant;
959
+ /**
960
+ * A `next/root-params` getter's value; `undefined` without the getter and
961
+ * outside a render (actions and route handlers have no root params).
962
+ */
963
+ const rootParam = async (getter) => {
964
+ if (!getter) return;
965
+ try {
966
+ return await getter();
967
+ } catch {
968
+ return;
969
+ }
970
+ };
830
971
  /** The tenant `scoped` resolved for a context, when it wasn't the claim. */
831
972
  const scopedTenants = /* @__PURE__ */ new WeakMap();
832
973
  const tenantFor = (ctx, view) => scopedTenants.get(ctx) ?? tenantOf(view, tenantClaim);
@@ -838,7 +979,7 @@ function createNext(betterSupabase, options = {}) {
838
979
  /** `null` runs `NextOptions.tenant`; a string is the caller's explicit tenant. */
839
980
  const scopedAt = cache(async (explicit, _generation) => {
840
981
  const { request, resolution } = await incoming();
841
- const [tenant, support] = await Promise.all([explicit ?? options.tenant?.(request, resolution.auth), base.support.current(request, resolution.auth)]);
982
+ const [tenant, support] = await Promise.all([explicit ?? (options.tenant ? options.tenant(request, resolution.auth) : rootParam(options.rootParams?.tenant)), base.support.current(request, resolution.auth)]);
842
983
  const ctx = core.context(resolution, request, {
843
984
  ...statsFor(request),
844
985
  ...support ? { support } : {}
@@ -858,22 +999,9 @@ function createNext(betterSupabase, options = {}) {
858
999
  path: options.support?.options.cookie?.path ?? "/",
859
1000
  secure: options.support?.options.cookie?.secure ?? true
860
1001
  };
861
- const contextFromView = async (view, { token }) => {
862
- const ctx = await base.context(bearerRequest(token));
863
- if (ctx.auth.kind === "invalid") return ctx;
864
- if (ctx.auth.kind === "user" ? view.kind === "user" && view.user.id === ctx.auth.user.id : view.kind === ctx.auth.kind) return ctx;
865
- return base.contextFor({
866
- kind: "invalid",
867
- reason: "token",
868
- error: dbError("unauthorized", "The token does not belong to the session passed to contextFromSession()")
869
- });
870
- };
871
- function contextFromSession(session, sessionOptions) {
872
- if (session !== null && "kind" in session) return contextFromView(session, sessionOptions !== void 0 && "token" in sessionOptions ? sessionOptions : { token: null });
873
- return base.contextFromSession(session, sessionOptions !== void 0 && "token" in sessionOptions ? {} : sessionOptions);
874
- }
1002
+ const contextFromSession = (snapshot, contextOptions) => base.contextFromSession(snapshot, contextOptions);
875
1003
  const evictSession = async (userId, evictOptions = {}) => {
876
- invalidateAll([sessionTag(userId), ...evictOptions.tags ?? []]);
1004
+ invalidateAll([...userTags(userId), ...evictOptions.tags ?? []]);
877
1005
  await base.evictSession(userId);
878
1006
  };
879
1007
  const withAccounts = withExtra(base, {
@@ -881,17 +1009,17 @@ function createNext(betterSupabase, options = {}) {
881
1009
  contextFromSession,
882
1010
  evictSession,
883
1011
  deleteAccount: ((userId, deleteOptions) => base.deleteAccount(userId, deleteOptions).map((result) => {
884
- invalidateAll([sessionTag(userId)]);
1012
+ invalidateAll(userTags(userId));
885
1013
  forget(userId);
886
1014
  return result;
887
1015
  })),
888
1016
  endSessions: ((userId) => base.endSessions(userId).map((result) => {
889
- invalidateAll([sessionTag(userId)]);
1017
+ invalidateAll(userTags(userId));
890
1018
  forget(userId);
891
1019
  return result;
892
1020
  })),
893
1021
  suspendAccount: ((userId, suspendOptions) => base.suspendAccount(userId, suspendOptions).map((result) => {
894
- invalidateAll([sessionTag(userId)]);
1022
+ invalidateAll(userTags(userId));
895
1023
  forget(userId);
896
1024
  return result;
897
1025
  }))
@@ -914,38 +1042,170 @@ function createNext(betterSupabase, options = {}) {
914
1042
  scope.generation += 1;
915
1043
  },
916
1044
  signedOut: (userId) => {
917
- invalidateAll([sessionTag(userId)]);
1045
+ invalidateAll(userTags(userId));
918
1046
  forget(userId);
919
1047
  }
920
1048
  });
1049
+ /**
1050
+ * The context of a cache scope: the request's in `'use cache: private'`, the
1051
+ * handed-off snapshot's in `'use cache: remote'`.
1052
+ */
1053
+ const scopeOf = async (cachedOptions) => {
1054
+ if (cachedOptions.scope !== "remote") {
1055
+ const [view, ctx] = await Promise.all([claims(), current(cachedOptions.tenant)]);
1056
+ return {
1057
+ ctx,
1058
+ view,
1059
+ scope: "private",
1060
+ tenant: tenantFor(ctx, view)
1061
+ };
1062
+ }
1063
+ const { key } = cachedOptions;
1064
+ const tenant = key.tenant ?? void 0;
1065
+ const snapshot = takeHandoff(key);
1066
+ const ctx = snapshot ? await base.contextFromSession(snapshot, tenant === void 0 ? {} : { tenant }) : base.contextFor(key.userId === null && key.shared === null && key.support === null ? {
1067
+ kind: "none",
1068
+ reason: "none"
1069
+ } : {
1070
+ kind: "invalid",
1071
+ reason: "token",
1072
+ error: dbError("unauthorized", "No caller handed this remote cache key over: call the function through bsb.remote()")
1073
+ });
1074
+ return {
1075
+ ctx,
1076
+ view: toSession(ctx.auth),
1077
+ scope: "remote",
1078
+ tenant
1079
+ };
1080
+ };
1081
+ /** Sets `cacheLife` and the session, support, table and row tags of an entry. */
1082
+ const applyEntry = (ctx, view, scope, tenant, entry) => {
1083
+ cacheLife(cachedLife(view, scope, entry.life, { ...development ? { warn: (message) => {
1084
+ betterSupabase.events.logger.warn(message);
1085
+ } } : {} }));
1086
+ const tables = entry.tables ?? [];
1087
+ const first = tables[0];
1088
+ const claimed = ctx.auth.kind === "user" ? ctx.auth.claims["session_id"] : void 0;
1089
+ const sessionId = typeof claimed === "string" ? claimed : void 0;
1090
+ const tags = [
1091
+ ...view.kind === "user" ? userTags(view.user.id) : [],
1092
+ ...sessionId === void 0 ? [] : [sessionIdTag(sessionId)],
1093
+ ...ctx.support ? [supportTag(ctx.support.session.id)] : [],
1094
+ ...entry.tags ?? [],
1095
+ ...tables.flatMap((table) => tableTags(table, tenant === void 0 ? {} : { tenant })),
1096
+ ...first !== void 0 && entry.id !== void 0 ? [tagFor(first, entry.id)] : []
1097
+ ];
1098
+ if (tags.length > 0) cacheTag(...tags);
1099
+ };
1100
+ /** The bootstrap calls of one request, by session key, schema, rpc and args. */
1101
+ const bootstrapCalls = cache(() => /* @__PURE__ */ new Map());
1102
+ const signedOutBootstrap = (view, tenant) => ({
1103
+ session: view,
1104
+ tenant: tenant ?? null,
1105
+ authzVersion: null,
1106
+ sessionActive: false,
1107
+ data: null
1108
+ });
921
1109
  const next = extendServer(withAccounts, {
922
1110
  claims,
923
1111
  getClaims,
1112
+ refreshSessionCache: async () => refreshCallerCache(await getClaims(), base),
924
1113
  async cached(cachedOptions = {}) {
925
- const [view, ctx] = await Promise.all([claims(), current(cachedOptions.tenant)]);
926
- const life = cachedOptions.life;
927
- const stale = sessionStale(view, life);
928
- cacheLife({
929
- stale: life?.stale === void 0 ? stale : Math.min(stale, life.stale),
930
- ...life?.revalidate === void 0 ? {} : { revalidate: life.revalidate },
931
- ...life?.expire === void 0 ? {} : { expire: life.expire }
932
- });
933
- const tables = cachedOptions.tables ?? [];
934
- const tenant = tables.length > 0 ? tenantFor(ctx, view) : void 0;
935
- const first = tables[0];
936
- const claimed = ctx.auth.kind === "user" ? ctx.auth.claims["session_id"] : void 0;
937
- const sessionId = typeof claimed === "string" ? claimed : void 0;
938
- const tags = [
939
- ...view.kind === "user" ? [sessionTag(view.user.id)] : [],
940
- ...sessionId === void 0 ? [] : [sessionIdTag(sessionId)],
941
- ...ctx.support ? [supportTag(ctx.support.session.id)] : [],
942
- ...cachedOptions.tags ?? [],
943
- ...tables.flatMap((table) => tableTags(table, tenant === void 0 ? {} : { tenant })),
944
- ...first !== void 0 && cachedOptions.id !== void 0 ? [tagFor(first, cachedOptions.id)] : []
945
- ];
946
- if (tags.length > 0) cacheTag(...tags);
1114
+ const { ctx, view, scope, tenant } = await scopeOf(cachedOptions);
1115
+ applyEntry(ctx, view, scope, tenant, cachedOptions);
947
1116
  return withExtra(ctx, { session: view });
948
1117
  },
1118
+ remote(fn, remoteOptions = {}) {
1119
+ return async (...args) => {
1120
+ const ctx = await current(remoteOptions.tenant?.(...args));
1121
+ const view = toSession(ctx.auth);
1122
+ const snapshot = ctx.support ? null : snapshotOf(ctx.auth);
1123
+ const share = remoteOptions.share ?? "session";
1124
+ const shared = typeof share === "object" ? share.key(snapshot) : null;
1125
+ const key = {
1126
+ userId: shared === null && view.kind === "user" ? view.user.id : null,
1127
+ sessionId: shared === null && share === "session" ? snapshot?.sessionId ?? null : null,
1128
+ tenant: tenantFor(ctx, view) ?? null,
1129
+ authzVersion: shared === null ? snapshot?.authzVersion ?? null : null,
1130
+ shared,
1131
+ support: ctx.support?.session.id ?? null
1132
+ };
1133
+ const release = snapshot ? handOff(key, snapshot) : void 0;
1134
+ try {
1135
+ return await fn(key, ...args);
1136
+ } finally {
1137
+ release?.();
1138
+ }
1139
+ };
1140
+ },
1141
+ async bootstrap(bootstrapOptions) {
1142
+ const { ctx, view, scope, tenant } = await scopeOf(bootstrapOptions);
1143
+ const snapshot = snapshotOf(ctx.auth);
1144
+ if (view.kind !== "user" || !snapshot) {
1145
+ applyEntry(ctx, view, scope, tenant, bootstrapOptions);
1146
+ return signedOutBootstrap(view, tenant);
1147
+ }
1148
+ const schema = bootstrapSchema(bootstrapOptions, options, betterSupabase);
1149
+ const args = {
1150
+ ...bootstrapOptions.args,
1151
+ ...tenant ? { tenant } : {}
1152
+ };
1153
+ const calls = bootstrapCalls();
1154
+ const callKey = `${sessionCacheKey(snapshot)}|${schema}|${bootstrapOptions.rpc}|${JSON.stringify(args)}`;
1155
+ let call = calls.get(callKey);
1156
+ if (!call) {
1157
+ call = runBootstrap(ctx.db.$executor, schema, bootstrapOptions.rpc, args);
1158
+ calls.set(callKey, call);
1159
+ }
1160
+ const row = await call;
1161
+ if (!row.sessionActive) {
1162
+ cacheLife({
1163
+ stale: 0,
1164
+ revalidate: 0,
1165
+ expire: 0
1166
+ });
1167
+ await evictSession(view.user.id);
1168
+ if (bootstrapOptions.redirect !== void 0) redirect(`${bootstrapOptions.redirect}?reason=session_not_found`);
1169
+ return {
1170
+ session: view,
1171
+ sessionActive: false,
1172
+ authzVersion: row.authzVersion,
1173
+ tenant: row.tenant ?? tenant ?? null,
1174
+ data: null
1175
+ };
1176
+ }
1177
+ if (row.authzVersion !== null) await options.versions?.seed?.(view.user.id, row.authzVersion);
1178
+ applyEntry(ctx, view, scope, tenant ?? row.tenant ?? void 0, bootstrapOptions);
1179
+ return {
1180
+ session: view,
1181
+ sessionActive: true,
1182
+ authzVersion: row.authzVersion,
1183
+ tenant: row.tenant ?? tenant ?? null,
1184
+ data: row.data
1185
+ };
1186
+ },
1187
+ async getAccess(source, accessOptions = {}) {
1188
+ const boot = source && "session" in source ? source : void 0;
1189
+ const tenant = boot?.tenant ?? void 0;
1190
+ const snapshot = isSessionSnapshot(source) ? source : accessOptions.key ? takeHandoff(accessOptions.key) ?? null : await getClaims();
1191
+ const ctx = await base.contextFromSession(snapshot, tenant === void 0 ? {} : { tenant });
1192
+ const view = toSession(ctx.auth);
1193
+ const resolvedTenant = tenant ?? tenantFor(ctx, view) ?? null;
1194
+ return {
1195
+ context: ctx,
1196
+ session: view,
1197
+ tenant: resolvedTenant,
1198
+ authzVersion: boot ? boot.authzVersion : snapshot?.authzVersion ?? null,
1199
+ async can(permission) {
1200
+ if (view.kind !== "user") return false;
1201
+ const outcome = await authorizeCaller(ctx.auth, { permission }, void 0, resolvedTenant ?? void 0, base.authorizer, ctx);
1202
+ return !("kind" in outcome && "message" in outcome);
1203
+ }
1204
+ };
1205
+ },
1206
+ locale: () => rootParam(options.rootParams?.locale),
1207
+ brand: () => rootParam(options.rootParams?.brand),
1208
+ tenant: () => rootParam(options.rootParams?.tenant),
949
1209
  async liveCount(spec, db) {
950
1210
  const result = await (db ?? (await current()).db).$run(spec);
951
1211
  return {
@@ -959,10 +1219,10 @@ function createNext(betterSupabase, options = {}) {
959
1219
  const id = collector ? crypto.randomUUID() : void 0;
960
1220
  let authMs = 0;
961
1221
  const phases = {};
962
- const sessionCheck = proxyOptions.verifySession === true ? {} : proxyOptions.verifySession;
1222
+ const sessionCheck = proxyOptions.verifySession === true ? {} : proxyOptions.verifySession === "bootstrap" ? void 0 : proxyOptions.verifySession;
963
1223
  const verifySession = sessionCheck !== void 0 && shouldCheckSession(request, sessionCheck);
964
1224
  const [early, resolution] = await Promise.all([proxyOptions.before?.(request), base.resolve(request, {
965
- refresh: shouldRefresh(request),
1225
+ refresh: true,
966
1226
  ...verifySession ? { verifySession } : {},
967
1227
  ...proxyOptions.leeway === void 0 ? {} : { leeway: proxyOptions.leeway },
968
1228
  ...proxyOptions.serverTiming ? { onTiming: (phase, ms) => {
@@ -973,10 +1233,9 @@ function createNext(betterSupabase, options = {}) {
973
1233
  return resolved;
974
1234
  })]);
975
1235
  if (resolution.cookies.length > 0) await base.sessions.seed(resolution.auth);
976
- const rendersSignedOut = proxyOptions.onExpiredPrefetch === "render" && resolution.auth.kind === "none" && resolution.auth.reason === "expired" && isPrefetch(request);
977
1236
  const protectMethods = proxyOptions.protectMethods;
978
1237
  const runsProtect = protectMethods === true ? true : (protectMethods ?? ["GET", "HEAD"]).includes(request.method);
979
- const custom = (resolution.sessionVerified === false && sessionCheck?.redirect !== void 0 && request.nextUrl.pathname !== sessionCheck.redirect ? endedRedirect(request, sessionCheck.redirect, resolution.reason === "user_banned" ? sessionCheck.reasons?.banned ?? "user_banned" : sessionCheck.reasons?.ended ?? "session_not_found") : void 0) ?? await outageResponse(proxyOptions.onAuthOutage, resolution, request, betterSupabase.events.logger) ?? (rendersSignedOut || !runsProtect ? void 0 : await proxyOptions.protect?.(resolution.auth, request));
1238
+ const custom = (resolution.sessionVerified === false && sessionCheck?.redirect !== void 0 && request.nextUrl.pathname !== sessionCheck.redirect ? endedRedirect(request, sessionCheck.redirect, resolution.reason === "user_banned" ? sessionCheck.reasons?.banned ?? "user_banned" : sessionCheck.reasons?.ended ?? "session_not_found") : void 0) ?? await outageResponse(proxyOptions.onAuthOutage, resolution, request, betterSupabase.events.logger) ?? (runsProtect ? await proxyOptions.protect?.(resolution.auth, request) : void 0);
980
1239
  const initial = custom ?? early;
981
1240
  if (!initial && resolution.cookies.length === 0 && !id && !proxyOptions.after && !proxyOptions.serverTiming) {
982
1241
  flushAfter();
@@ -995,7 +1254,7 @@ function createNext(betterSupabase, options = {}) {
995
1254
  }
996
1255
  if (proxyOptions.after) {
997
1256
  const replaced = await proxyOptions.after(response, resolution.auth);
998
- if (replaced) response = mutableResponse(replaced);
1257
+ if (replaced) response = resolution.apply(mutableResponse(replaced));
999
1258
  }
1000
1259
  if (proxyOptions.serverTiming) response.headers.append("server-timing", serverTimingValue({
1001
1260
  "bsb-proxy": performance.now() - started,
@@ -1140,7 +1399,7 @@ function createNext(betterSupabase, options = {}) {
1140
1399
  ...supportCookieOptions,
1141
1400
  maxAge: supportCookieMaxAge(support)
1142
1401
  });
1143
- if (resolution.auth.kind === "user") invalidateAll([sessionTag(resolution.auth.user.id)]);
1402
+ if (resolution.auth.kind === "user") invalidateAll(userTags(resolution.auth.user.id));
1144
1403
  return {
1145
1404
  ok: true,
1146
1405
  data: {
@@ -1167,7 +1426,7 @@ function createNext(betterSupabase, options = {}) {
1167
1426
  };
1168
1427
  const stopped = await base.support.stop(resolution.auth, id);
1169
1428
  flushAfter();
1170
- invalidateAll([supportTag(id), ...resolution.auth.kind === "user" ? [sessionTag(resolution.auth.user.id)] : []]);
1429
+ invalidateAll([supportTag(id), ...resolution.auth.kind === "user" ? userTags(resolution.auth.user.id) : []]);
1171
1430
  return stopped.ok ? {
1172
1431
  ok: true,
1173
1432
  data: { ended: stopped.data.ended },
@@ -1201,4 +1460,160 @@ function createNext(betterSupabase, options = {}) {
1201
1460
  });
1202
1461
  return next;
1203
1462
  }
1204
- export { REQUEST_ID_HEADER, STATS_URL_HEADER, authzVersionOf, bindingTag, createNext, defineAction, invalidateBinding, isSessionSnapshot, issuedAtOf, nextCache, permissionsOf, recordListServer, recordTag, requireAal, safeRedirectPath, sessionCacheKey, sessionIdTag, sessionStale, sessionTag, shouldCheckSession, shouldRefresh, supportOf, supportSessions, supportTag, tagFor, tenantOf, toSession };
1463
+ // src/bridges/next.ts
1464
+ /**
1465
+ * Runs an entry array around a Next.js route handler. The handler gets the
1466
+ * entries' contributions as `ctx` and may return a `Response` or a value (sent
1467
+ * as JSON, `undefined` as 204). Response-phase entries (`withCors`, refreshed
1468
+ * cookies) see the handler's response.
1469
+ *
1470
+ * ```ts
1471
+ * // src/app/api/notes/route.ts
1472
+ * export const GET = toNextRoute(
1473
+ * [withCors(cors), withRequiredClaims(), withSupabaseClient()],
1474
+ * async (request, ctx) =>
1475
+ * (await ctx.supabase.from("notes").select()).data,
1476
+ * );
1477
+ * ```
1478
+ */
1479
+ function toNextRoute(entries, handler, options = {}) {
1480
+ const run = around(entries);
1481
+ return async (request, context) => {
1482
+ bufferInPlace(request);
1483
+ return run(request, options.env?.(request), async (contributions) => toResponse(await handler(request, contributions, context)));
1484
+ };
1485
+ }
1486
+ /**
1487
+ * Thrown by an action whose entries answered before the action ran, such as
1488
+ * `withRequiredClaims` with a 401 for a caller without a session.
1489
+ */
1490
+ var NextActionRejected = class extends Error {
1491
+ status;
1492
+ response;
1493
+ constructor(response) {
1494
+ super(`The action was rejected with status ${String(response.status)}.`);
1495
+ this.name = "NextActionRejected";
1496
+ this.status = response.status;
1497
+ this.response = response;
1498
+ }
1499
+ };
1500
+ /**
1501
+ * The `Request` of a Server Action: a POST to the page that called it, with the
1502
+ * incoming headers. Next.js gives actions no `Request`, so the entries see this
1503
+ * one.
1504
+ */
1505
+ function actionRequest(headers) {
1506
+ const host = headers.get("x-forwarded-host") ?? headers.get("host");
1507
+ const protocol = headers.get("x-forwarded-proto") ?? "https";
1508
+ const origin = host ? `${protocol}://${host}` : "http://localhost";
1509
+ const path = headers.get("next-url") ?? "/";
1510
+ return new Request(new URL(path, origin), {
1511
+ method: "POST",
1512
+ headers
1513
+ });
1514
+ }
1515
+ /**
1516
+ * Runs an entry array around a Server Action with `io` reading the request and
1517
+ * writing cookies. `src/next` binds `io` to `headers()` and `cookies()`.
1518
+ */
1519
+ function nextAction(entries, action, io, options = {}) {
1520
+ const run = around(entries);
1521
+ return async (...args) => {
1522
+ const request = actionRequest(await io.headers());
1523
+ const outcome = { ran: false };
1524
+ const response = await run(request, options.env?.(request), async (contributions) => {
1525
+ outcome.result = await action(contributions, ...args);
1526
+ outcome.ran = true;
1527
+ return new Response(null, { status: 204 });
1528
+ });
1529
+ for (const header of response.headers.getSetCookie()) {
1530
+ const write = parseSetCookie(header);
1531
+ if (write) await io.setCookie(write);
1532
+ }
1533
+ if (!outcome.ran) throw new NextActionRejected(response);
1534
+ return outcome.result;
1535
+ };
1536
+ }
1537
+ const SAME_SITE = /* @__PURE__ */ new Set([
1538
+ "lax",
1539
+ "strict",
1540
+ "none"
1541
+ ]);
1542
+ function isSameSite(value) {
1543
+ return SAME_SITE.has(value);
1544
+ }
1545
+ /**
1546
+ * One `Set-Cookie` header as a cookie write, or `undefined` when it has no
1547
+ * name.
1548
+ */
1549
+ function parseSetCookie(header) {
1550
+ const [pair = "", ...attributes] = header.split(";");
1551
+ const equals = pair.indexOf("=");
1552
+ if (equals <= 0) return;
1553
+ const write = {
1554
+ name: pair.slice(0, equals).trim(),
1555
+ value: decodeURIComponent(pair.slice(equals + 1).trim())
1556
+ };
1557
+ for (const attribute of attributes) {
1558
+ const at = attribute.indexOf("=");
1559
+ const key = (at === -1 ? attribute : attribute.slice(0, at)).trim().toLowerCase();
1560
+ const value = at === -1 ? "" : attribute.slice(at + 1).trim();
1561
+ switch (key) {
1562
+ case "path":
1563
+ write.path = value;
1564
+ break;
1565
+ case "domain":
1566
+ write.domain = value;
1567
+ break;
1568
+ case "max-age": {
1569
+ const seconds = Number(value);
1570
+ if (Number.isFinite(seconds)) write.maxAge = seconds;
1571
+ break;
1572
+ }
1573
+ case "expires": {
1574
+ const date = new Date(value);
1575
+ if (!Number.isNaN(date.getTime())) write.expires = date;
1576
+ break;
1577
+ }
1578
+ case "httponly":
1579
+ write.httpOnly = true;
1580
+ break;
1581
+ case "secure":
1582
+ write.secure = true;
1583
+ break;
1584
+ case "samesite": {
1585
+ const sameSite = value.toLowerCase();
1586
+ if (isSameSite(sameSite)) write.sameSite = sameSite;
1587
+ break;
1588
+ }
1589
+ case "partitioned": write.partitioned = true;
1590
+ }
1591
+ }
1592
+ return write;
1593
+ }
1594
+ // src/next/bridge.ts
1595
+ /**
1596
+ * Runs an entry array around a Server Action. The entries see a request built
1597
+ * from `headers()` (the session cookie included), cookies they set go through
1598
+ * `cookies().set`, and the action gets their contributions as `ctx`. When an
1599
+ * entry answers first (a 401 from `withRequiredClaims`), the call throws
1600
+ * `NextActionRejected` with that response.
1601
+ *
1602
+ * ```ts
1603
+ * "use server";
1604
+ * export const addNote = toNextAction(
1605
+ * [withRequiredClaims(), withSupabaseClient()],
1606
+ * async (ctx, body: string) =>
1607
+ * ctx.supabase.from("notes").insert({ body }),
1608
+ * );
1609
+ * ```
1610
+ */
1611
+ function toNextAction(entries, action, options = {}) {
1612
+ return nextAction(entries, action, {
1613
+ headers: async () => new Headers(await headers()),
1614
+ setCookie: async ({ name, value, ...attributes }) => {
1615
+ (await cookies()).set(name, value, attributes);
1616
+ }
1617
+ }, options);
1618
+ }
1619
+ export { NextActionRejected, REQUEST_ID_HEADER, STATS_URL_HEADER, authzVersionOf, bindingTag, createNext, defineAction, invalidateBinding, isSessionSnapshot, issuedAtOf, nextCache, parseSetCookie, permissionsOf, postAuthPath, recordListServer, recordTag, requireAal, safeRedirectPath, sessionCacheKey, sessionIdTag, sessionTag, shouldCheckSession, supportOf, supportSessions, supportTag, tagFor, tenantOf, toNextAction, toNextRoute, toSession };