better-supabase 0.7.1 → 0.9.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.
- package/README.md +146 -81
- package/bin/better-supabase.js +14 -2
- package/dist/access-sql-DUSSMaC3.js +201 -0
- package/dist/actor-BAhb-d1S.d.ts +104 -0
- package/dist/actor-KHDOKGb1.js +151 -0
- package/dist/adapter-CEjmtazZ.js +1984 -0
- package/dist/agents-BCNhIxVZ.d.ts +111 -0
- package/dist/ai-cache-Dps7aRu1.d.ts +70 -0
- package/dist/ai-cache-zeUL94pB.js +84 -0
- package/dist/ai-chat-3GBSlFR4.d.ts +608 -0
- package/dist/ai-files-D2_9YLjF.js +331 -0
- package/dist/ai-message-DfaP8sis.js +14 -0
- package/dist/ai-sdk/agents/index.d.ts +154 -10
- package/dist/ai-sdk/agents/index.js +172 -17
- package/dist/ai-sdk/batches/index.d.ts +4 -4
- package/dist/ai-sdk/batches/index.js +5 -5
- package/dist/ai-sdk/cache/index.d.ts +2 -2
- package/dist/ai-sdk/cache/index.js +2 -2
- package/dist/ai-sdk/chat/index.d.ts +1 -1
- package/dist/ai-sdk/chat/index.js +10 -21
- package/dist/ai-sdk/embeddings/index.d.ts +3 -3
- package/dist/ai-sdk/embeddings/index.js +1 -2
- package/dist/ai-sdk/files/index.d.ts +3 -3
- package/dist/ai-sdk/files/index.js +4 -4
- package/dist/ai-sdk/index.d.ts +38 -9
- package/dist/ai-sdk/index.js +5 -3
- package/dist/ai-sdk/mcp/index.d.ts +43 -6
- package/dist/ai-sdk/mcp/index.js +37 -8
- package/dist/ai-sdk/memory/index.d.ts +5 -2
- package/dist/ai-sdk/memory/index.js +2 -2
- package/dist/ai-sdk/react/index.js +1 -2
- package/dist/ai-sdk/workflow/index.d.ts +7 -6
- package/dist/ai-sdk/workflow/index.js +15 -26
- package/dist/ai-tasks-Ih5oHfyj.d.ts +157 -0
- package/dist/announcements-BHCzraR6.js +128 -0
- package/dist/api-CFjuYKFY.js +680 -0
- package/dist/api-TG3jE5aO.d.ts +411 -0
- package/dist/api-keys-BEQatEUW.js +318 -0
- package/dist/api-keys-BYoGCM9p.d.ts +205 -0
- package/dist/app-tables-BGl5_U2x.js +584 -0
- package/dist/approvals-a2KmioBh.d.ts +124 -0
- package/dist/arazzo/index.d.ts +255 -0
- package/dist/arazzo/index.js +622 -0
- package/dist/assistant-Bf2cA6RO.d.ts +148 -0
- package/dist/astro/index.d.ts +9 -8
- package/dist/astro/index.js +12 -9
- package/dist/asyncapi/index.d.ts +103 -0
- package/dist/asyncapi/index.js +569 -0
- package/dist/attachments-DAj2Yp95.js +264 -0
- package/dist/attributes-D4mA7WhI.js +38 -0
- package/dist/audit-log-BMMuGPdP.js +786 -0
- package/dist/auth-CdBKt0CS.js +20 -0
- package/dist/auth-reply-DUCwb8YO.js +31 -0
- package/dist/auth-reply-Dj124sbX.d.ts +11 -0
- package/dist/authorization-DpRfs6Wx.d.ts +1412 -0
- package/dist/authorization-hooks-DkmrnDX7.d.ts +214 -0
- package/dist/authorizer-DH7DjkL3.js +126 -0
- package/dist/authorizer-eiOjo-3l.d.ts +73 -0
- package/dist/base64-BmeCBgGo.js +42 -0
- package/dist/batch-limit-DKVQDz4o.js +5 -0
- package/dist/before-route-B98js9m_.js +30 -0
- package/dist/better-result/index.d.ts +118 -0
- package/dist/better-result/index.js +64 -0
- package/dist/bind-a7sUgvf4.d.ts +70 -0
- package/dist/block-env-CBd_SoL5.js +29 -0
- package/dist/block-env-Dxl7rsI0.d.ts +10 -0
- package/dist/block-events-DD9Q_NUz.js +96 -0
- package/dist/block-fields-5UA84ZUg.d.ts +55 -0
- package/dist/block-fields-ffD6Gxe4.js +139 -0
- package/dist/block-helpers-C86hPEjI.d.ts +37 -0
- package/dist/block-helpers-CfG_MvDR.js +264 -0
- package/dist/block-hooks-BLPWD3Jt.d.ts +107 -0
- package/dist/block-hooks-BsXncUlZ.js +114 -0
- package/dist/block-transport-DaGGXjIw.d.ts +70 -0
- package/dist/block-transport-G4t1umrR.js +85 -0
- package/dist/blocks/access-requests/index.d.ts +98 -0
- package/dist/blocks/access-requests/index.js +99 -0
- package/dist/blocks/agents/index.d.ts +21 -3
- package/dist/blocks/agents/index.js +65 -18
- package/dist/blocks/ai-cache/index.d.ts +8 -3
- package/dist/blocks/ai-cache/index.js +15 -3
- package/dist/blocks/ai-chat/index.d.ts +28 -4
- package/dist/blocks/ai-chat/index.js +31 -5
- package/dist/blocks/ai-chat/react/index.d.ts +12 -46
- package/dist/blocks/ai-chat/react/index.js +43 -335
- package/dist/blocks/ai-chat/solid/index.d.ts +34 -0
- package/dist/blocks/ai-chat/solid/index.js +41 -0
- package/dist/blocks/ai-chat/svelte/index.d.ts +34 -0
- package/dist/blocks/ai-chat/svelte/index.js +41 -0
- package/dist/blocks/ai-chat/vue/index.d.ts +34 -0
- package/dist/blocks/ai-chat/vue/index.js +41 -0
- package/dist/blocks/ai-files/index.d.ts +11 -4
- package/dist/blocks/ai-files/index.js +16 -3
- package/dist/blocks/ai-providers/index.d.ts +18 -3
- package/dist/blocks/ai-providers/index.js +41 -15
- package/dist/blocks/ai-tasks/index.d.ts +10 -3
- package/dist/blocks/ai-tasks/index.js +71 -21
- package/dist/blocks/announcements/index.d.ts +18 -3
- package/dist/blocks/announcements/index.js +27 -3
- package/dist/blocks/announcements/react/index.d.ts +4 -14
- package/dist/blocks/announcements/react/index.js +22 -70
- package/dist/blocks/announcements/solid/index.d.ts +13 -0
- package/dist/blocks/announcements/solid/index.js +14 -0
- package/dist/blocks/announcements/svelte/index.d.ts +13 -0
- package/dist/blocks/announcements/svelte/index.js +14 -0
- package/dist/blocks/announcements/vue/index.d.ts +13 -0
- package/dist/blocks/announcements/vue/index.js +14 -0
- package/dist/blocks/api-keys/index.d.ts +24 -7
- package/dist/blocks/api-keys/index.js +30 -295
- package/dist/blocks/api-keys/react/index.d.ts +29 -0
- package/dist/blocks/api-keys/react/index.js +43 -0
- package/dist/blocks/api-keys/react/server.d.ts +7 -0
- package/dist/blocks/api-keys/react/server.js +7 -0
- package/dist/blocks/api-keys/solid/index.d.ts +13 -0
- package/dist/blocks/api-keys/solid/index.js +14 -0
- package/dist/blocks/api-keys/svelte/index.d.ts +13 -0
- package/dist/blocks/api-keys/svelte/index.js +14 -0
- package/dist/blocks/api-keys/vue/index.d.ts +13 -0
- package/dist/blocks/api-keys/vue/index.js +14 -0
- package/dist/blocks/approvals/index.d.ts +22 -0
- package/dist/blocks/approvals/index.js +189 -0
- package/dist/blocks/attachments/index.d.ts +18 -223
- package/dist/blocks/attachments/index.js +26 -233
- package/dist/blocks/audit/index.d.ts +72 -354
- package/dist/blocks/audit/index.js +91 -695
- package/dist/blocks/audit/react/index.d.ts +26 -0
- package/dist/blocks/audit/react/index.js +44 -0
- package/dist/blocks/audit/react/server.d.ts +7 -0
- package/dist/blocks/audit/react/server.js +7 -0
- package/dist/blocks/audit/solid/index.d.ts +13 -0
- package/dist/blocks/audit/solid/index.js +14 -0
- package/dist/blocks/audit/svelte/index.d.ts +13 -0
- package/dist/blocks/audit/svelte/index.js +14 -0
- package/dist/blocks/audit/vue/index.d.ts +13 -0
- package/dist/blocks/audit/vue/index.js +14 -0
- package/dist/blocks/billing/index.d.ts +40 -13
- package/dist/blocks/billing/index.js +49 -18
- package/dist/blocks/billing/react/index.d.ts +34 -0
- package/dist/blocks/billing/react/index.js +36 -0
- package/dist/blocks/billing/react/server.d.ts +7 -0
- package/dist/blocks/billing/react/server.js +7 -0
- package/dist/blocks/billing/solid/index.d.ts +15 -0
- package/dist/blocks/billing/solid/index.js +14 -0
- package/dist/blocks/billing/svelte/index.d.ts +15 -0
- package/dist/blocks/billing/svelte/index.js +14 -0
- package/dist/blocks/billing/vue/index.d.ts +15 -0
- package/dist/blocks/billing/vue/index.js +14 -0
- package/dist/blocks/bookings/index.d.ts +36 -0
- package/dist/blocks/bookings/index.js +28 -0
- package/dist/blocks/bookings/react/index.d.ts +31 -0
- package/dist/blocks/bookings/react/index.js +59 -0
- package/dist/blocks/bookings/react/server.d.ts +6 -0
- package/dist/blocks/bookings/react/server.js +7 -0
- package/dist/blocks/bookings/solid/index.d.ts +13 -0
- package/dist/blocks/bookings/solid/index.js +14 -0
- package/dist/blocks/bookings/svelte/index.d.ts +13 -0
- package/dist/blocks/bookings/svelte/index.js +14 -0
- package/dist/blocks/bookings/vue/index.d.ts +13 -0
- package/dist/blocks/bookings/vue/index.js +14 -0
- package/dist/blocks/bulk/index.d.ts +142 -0
- package/dist/blocks/bulk/index.js +154 -0
- package/dist/blocks/calendar/index.d.ts +20 -0
- package/dist/blocks/calendar/index.js +33 -0
- package/dist/blocks/calendar/react/index.d.ts +26 -0
- package/dist/blocks/calendar/react/index.js +58 -0
- package/dist/blocks/calendar/react/server.d.ts +6 -0
- package/dist/blocks/calendar/react/server.js +7 -0
- package/dist/blocks/calendar/solid/index.d.ts +13 -0
- package/dist/blocks/calendar/solid/index.js +14 -0
- package/dist/blocks/calendar/svelte/index.d.ts +13 -0
- package/dist/blocks/calendar/svelte/index.js +14 -0
- package/dist/blocks/calendar/vue/index.d.ts +13 -0
- package/dist/blocks/calendar/vue/index.js +14 -0
- package/dist/blocks/catalog/index.d.ts +224 -0
- package/dist/blocks/catalog/index.js +292 -0
- package/dist/blocks/collections/index.d.ts +184 -0
- package/dist/blocks/collections/index.js +208 -0
- package/dist/blocks/comments/index.d.ts +19 -166
- package/dist/blocks/comments/index.js +26 -206
- package/dist/blocks/comments/react/index.d.ts +27 -0
- package/dist/blocks/comments/react/index.js +45 -0
- package/dist/blocks/comments/react/server.d.ts +7 -0
- package/dist/blocks/comments/react/server.js +7 -0
- package/dist/blocks/comments/solid/index.d.ts +13 -0
- package/dist/blocks/comments/solid/index.js +14 -0
- package/dist/blocks/comments/svelte/index.d.ts +13 -0
- package/dist/blocks/comments/svelte/index.js +14 -0
- package/dist/blocks/comments/vue/index.d.ts +13 -0
- package/dist/blocks/comments/vue/index.js +14 -0
- package/dist/blocks/connectors/index.d.ts +21 -3
- package/dist/blocks/connectors/index.js +54 -18
- package/dist/blocks/custom-fields/index.d.ts +62 -0
- package/dist/blocks/custom-fields/index.js +85 -0
- package/dist/blocks/data-lifecycle/index.d.ts +119 -10
- package/dist/blocks/data-lifecycle/index.js +103 -12
- package/dist/blocks/deals/index.d.ts +262 -0
- package/dist/blocks/deals/index.js +380 -0
- package/dist/blocks/documents/index.d.ts +17 -0
- package/dist/blocks/documents/index.js +118 -0
- package/dist/blocks/domains/index.d.ts +117 -0
- package/dist/blocks/domains/index.js +118 -0
- package/dist/blocks/drive/index.d.ts +296 -0
- package/dist/blocks/drive/index.js +483 -0
- package/dist/blocks/employees/index.d.ts +205 -0
- package/dist/blocks/employees/index.js +289 -0
- package/dist/blocks/engagements/index.d.ts +125 -0
- package/dist/blocks/engagements/index.js +143 -0
- package/dist/blocks/entitlements/index.d.ts +40 -4
- package/dist/blocks/entitlements/index.js +14 -24
- package/dist/blocks/entitlements/react/index.d.ts +24 -0
- package/dist/blocks/entitlements/react/index.js +35 -0
- package/dist/blocks/entitlements/react/server.d.ts +6 -0
- package/dist/blocks/entitlements/react/server.js +7 -0
- package/dist/blocks/entitlements/solid/index.d.ts +13 -0
- package/dist/blocks/entitlements/solid/index.js +14 -0
- package/dist/blocks/entitlements/svelte/index.d.ts +13 -0
- package/dist/blocks/entitlements/svelte/index.js +14 -0
- package/dist/blocks/entitlements/vue/index.d.ts +13 -0
- package/dist/blocks/entitlements/vue/index.js +14 -0
- package/dist/blocks/flags/index.d.ts +61 -187
- package/dist/blocks/flags/index.js +65 -252
- package/dist/blocks/forms/index.d.ts +302 -0
- package/dist/blocks/forms/index.js +341 -0
- package/dist/blocks/forms/react/index.d.ts +16 -0
- package/dist/blocks/forms/react/index.js +25 -0
- package/dist/blocks/forms/react/server.d.ts +6 -0
- package/dist/blocks/forms/react/server.js +7 -0
- package/dist/blocks/forms/solid/index.d.ts +13 -0
- package/dist/blocks/forms/solid/index.js +14 -0
- package/dist/blocks/forms/svelte/index.d.ts +13 -0
- package/dist/blocks/forms/svelte/index.js +14 -0
- package/dist/blocks/forms/vue/index.d.ts +13 -0
- package/dist/blocks/forms/vue/index.js +14 -0
- package/dist/blocks/hiring/index.d.ts +154 -0
- package/dist/blocks/hiring/index.js +180 -0
- package/dist/blocks/identities/index.d.ts +83 -0
- package/dist/blocks/identities/index.js +103 -0
- package/dist/blocks/imports/index.d.ts +91 -0
- package/dist/blocks/imports/index.js +123 -0
- package/dist/blocks/inbox/index.d.ts +22 -3
- package/dist/blocks/inbox/index.js +78 -6
- package/dist/blocks/inbox/react/index.d.ts +3 -2
- package/dist/blocks/inbox/react/index.js +55 -199
- package/dist/blocks/inbox/react/server.d.ts +2 -1
- package/dist/blocks/inbox/solid/index.d.ts +27 -0
- package/dist/blocks/inbox/solid/index.js +32 -0
- package/dist/blocks/inbox/svelte/index.d.ts +27 -0
- package/dist/blocks/inbox/svelte/index.js +32 -0
- package/dist/blocks/inbox/vue/index.d.ts +27 -0
- package/dist/blocks/inbox/vue/index.js +32 -0
- package/dist/blocks/index.d.ts +9 -64
- package/dist/blocks/index.js +193 -57
- package/dist/blocks/inventory/index.d.ts +181 -0
- package/dist/blocks/inventory/index.js +219 -0
- package/dist/blocks/invoices/index.d.ts +154 -0
- package/dist/blocks/invoices/index.js +216 -0
- package/dist/blocks/jobs/index.d.ts +188 -49
- package/dist/blocks/jobs/index.js +698 -527
- package/dist/blocks/knowledge/index.d.ts +10 -3
- package/dist/blocks/knowledge/index.js +17 -3
- package/dist/blocks/leave/index.d.ts +241 -0
- package/dist/blocks/leave/index.js +209 -0
- package/dist/blocks/memory/index.d.ts +9 -4
- package/dist/blocks/memory/index.js +49 -12
- package/dist/blocks/metrics/index.d.ts +174 -0
- package/dist/blocks/metrics/index.js +217 -0
- package/dist/blocks/mfa/index.d.ts +7 -0
- package/dist/blocks/mfa/index.js +12 -0
- package/dist/blocks/mfa/react/index.d.ts +30 -0
- package/dist/blocks/mfa/react/index.js +45 -0
- package/dist/blocks/mfa/react/server.d.ts +9 -0
- package/dist/blocks/mfa/react/server.js +12 -0
- package/dist/blocks/mfa/solid/index.d.ts +20 -0
- package/dist/blocks/mfa/solid/index.js +23 -0
- package/dist/blocks/mfa/svelte/index.d.ts +20 -0
- package/dist/blocks/mfa/svelte/index.js +23 -0
- package/dist/blocks/mfa/vue/index.d.ts +20 -0
- package/dist/blocks/mfa/vue/index.js +23 -0
- package/dist/blocks/notifications/index.d.ts +345 -26
- package/dist/blocks/notifications/index.js +744 -120
- package/dist/blocks/notifications/react/index.d.ts +7 -32
- package/dist/blocks/notifications/react/index.js +23 -49
- package/dist/blocks/notifications/react/server.d.ts +2 -1
- package/dist/blocks/notifications/solid/index.d.ts +13 -0
- package/dist/blocks/notifications/solid/index.js +14 -0
- package/dist/blocks/notifications/svelte/index.d.ts +13 -0
- package/dist/blocks/notifications/svelte/index.js +14 -0
- package/dist/blocks/notifications/vue/index.d.ts +13 -0
- package/dist/blocks/notifications/vue/index.js +14 -0
- package/dist/blocks/number-sequences/index.d.ts +39 -0
- package/dist/blocks/number-sequences/index.js +38 -0
- package/dist/blocks/oauth-server/index.d.ts +228 -0
- package/dist/blocks/oauth-server/index.js +309 -0
- package/dist/blocks/onboarding/index.d.ts +8 -3
- package/dist/blocks/onboarding/index.js +17 -63
- package/dist/blocks/onboarding/react/index.d.ts +3 -12
- package/dist/blocks/onboarding/react/index.js +18 -60
- package/dist/blocks/onboarding/react/server.d.ts +2 -2
- package/dist/blocks/onboarding/react/server.js +2 -2
- package/dist/blocks/onboarding/solid/index.d.ts +13 -0
- package/dist/blocks/onboarding/solid/index.js +14 -0
- package/dist/blocks/onboarding/svelte/index.d.ts +13 -0
- package/dist/blocks/onboarding/svelte/index.js +14 -0
- package/dist/blocks/onboarding/vue/index.d.ts +13 -0
- package/dist/blocks/onboarding/vue/index.js +14 -0
- package/dist/blocks/orders/index.d.ts +264 -0
- package/dist/blocks/orders/index.js +589 -0
- package/dist/blocks/organizations/index.d.ts +31 -238
- package/dist/blocks/organizations/index.js +49 -399
- package/dist/blocks/organizations/react/index.d.ts +108 -0
- package/dist/blocks/organizations/react/index.js +113 -0
- package/dist/blocks/organizations/react/server.d.ts +11 -0
- package/dist/blocks/organizations/react/server.js +15 -0
- package/dist/blocks/organizations/solid/index.d.ts +34 -0
- package/dist/blocks/organizations/solid/index.js +32 -0
- package/dist/blocks/organizations/svelte/index.d.ts +34 -0
- package/dist/blocks/organizations/svelte/index.js +32 -0
- package/dist/blocks/organizations/vue/index.d.ts +34 -0
- package/dist/blocks/organizations/vue/index.js +32 -0
- package/dist/blocks/outbox/index.d.ts +12 -3
- package/dist/blocks/outbox/index.js +97 -67
- package/dist/blocks/parties/index.d.ts +181 -0
- package/dist/blocks/parties/index.js +258 -0
- package/dist/blocks/pipelines/index.d.ts +189 -0
- package/dist/blocks/pipelines/index.js +204 -0
- package/dist/blocks/profiles/index.d.ts +14 -9
- package/dist/blocks/profiles/index.js +20 -6
- package/dist/blocks/promotions/index.d.ts +125 -0
- package/dist/blocks/promotions/index.js +123 -0
- package/dist/blocks/push/index.d.ts +48 -28
- package/dist/blocks/push/index.js +45 -16
- package/dist/blocks/quotes/index.d.ts +152 -0
- package/dist/blocks/quotes/index.js +209 -0
- package/dist/blocks/rank/index.d.ts +71 -0
- package/dist/blocks/rank/index.js +53 -0
- package/dist/blocks/reactions/index.d.ts +18 -0
- package/dist/blocks/reactions/index.js +26 -0
- package/dist/blocks/reactions/react/index.d.ts +23 -0
- package/dist/blocks/reactions/react/index.js +46 -0
- package/dist/blocks/reactions/react/server.d.ts +6 -0
- package/dist/blocks/reactions/react/server.js +7 -0
- package/dist/blocks/reactions/solid/index.d.ts +13 -0
- package/dist/blocks/reactions/solid/index.js +14 -0
- package/dist/blocks/reactions/svelte/index.d.ts +13 -0
- package/dist/blocks/reactions/svelte/index.js +14 -0
- package/dist/blocks/reactions/vue/index.d.ts +13 -0
- package/dist/blocks/reactions/vue/index.js +14 -0
- package/dist/blocks/relations/index.d.ts +180 -0
- package/dist/blocks/relations/index.js +254 -0
- package/dist/blocks/reminders/index.d.ts +177 -0
- package/dist/blocks/reminders/index.js +171 -0
- package/dist/blocks/reviews/index.d.ts +148 -0
- package/dist/blocks/reviews/index.js +139 -0
- package/dist/blocks/rules/index.d.ts +103 -0
- package/dist/blocks/rules/index.js +54 -0
- package/dist/blocks/rules/react/index.d.ts +34 -0
- package/dist/blocks/rules/react/index.js +55 -0
- package/dist/blocks/rules/react/server.d.ts +6 -0
- package/dist/blocks/rules/react/server.js +7 -0
- package/dist/blocks/rules/solid/index.d.ts +13 -0
- package/dist/blocks/rules/solid/index.js +14 -0
- package/dist/blocks/rules/svelte/index.d.ts +13 -0
- package/dist/blocks/rules/svelte/index.js +14 -0
- package/dist/blocks/rules/vue/index.d.ts +13 -0
- package/dist/blocks/rules/vue/index.js +14 -0
- package/dist/blocks/saved-views/index.d.ts +17 -0
- package/dist/blocks/saved-views/index.js +29 -0
- package/dist/blocks/saved-views/react/index.d.ts +34 -0
- package/dist/blocks/saved-views/react/index.js +57 -0
- package/dist/blocks/saved-views/react/server.d.ts +7 -0
- package/dist/blocks/saved-views/react/server.js +7 -0
- package/dist/blocks/saved-views/solid/index.d.ts +13 -0
- package/dist/blocks/saved-views/solid/index.js +14 -0
- package/dist/blocks/saved-views/svelte/index.d.ts +13 -0
- package/dist/blocks/saved-views/svelte/index.js +14 -0
- package/dist/blocks/saved-views/vue/index.d.ts +13 -0
- package/dist/blocks/saved-views/vue/index.js +14 -0
- package/dist/blocks/search/index.d.ts +31 -0
- package/dist/blocks/search/index.js +61 -0
- package/dist/blocks/search/react/index.d.ts +36 -0
- package/dist/blocks/search/react/index.js +49 -0
- package/dist/blocks/search/react/server.d.ts +7 -0
- package/dist/blocks/search/react/server.js +8 -0
- package/dist/blocks/search/solid/index.d.ts +13 -0
- package/dist/blocks/search/solid/index.js +14 -0
- package/dist/blocks/search/svelte/index.d.ts +13 -0
- package/dist/blocks/search/svelte/index.js +14 -0
- package/dist/blocks/search/vue/index.d.ts +13 -0
- package/dist/blocks/search/vue/index.js +14 -0
- package/dist/blocks/service-principals/index.d.ts +126 -0
- package/dist/blocks/service-principals/index.js +107 -0
- package/dist/blocks/sessions/index.d.ts +7 -0
- package/dist/blocks/sessions/index.js +14 -0
- package/dist/blocks/sessions/react/index.d.ts +31 -0
- package/dist/blocks/sessions/react/index.js +51 -0
- package/dist/blocks/sessions/react/server.d.ts +9 -0
- package/dist/blocks/sessions/react/server.js +11 -0
- package/dist/blocks/sessions/solid/index.d.ts +20 -0
- package/dist/blocks/sessions/solid/index.js +23 -0
- package/dist/blocks/sessions/svelte/index.d.ts +20 -0
- package/dist/blocks/sessions/svelte/index.js +23 -0
- package/dist/blocks/sessions/vue/index.d.ts +20 -0
- package/dist/blocks/sessions/vue/index.js +23 -0
- package/dist/blocks/settings/index.d.ts +20 -86
- package/dist/blocks/settings/index.js +28 -101
- package/dist/blocks/settings/react/index.d.ts +25 -0
- package/dist/blocks/settings/react/index.js +37 -0
- package/dist/blocks/settings/react/server.d.ts +7 -0
- package/dist/blocks/settings/react/server.js +7 -0
- package/dist/blocks/settings/solid/index.d.ts +13 -0
- package/dist/blocks/settings/solid/index.js +14 -0
- package/dist/blocks/settings/svelte/index.d.ts +13 -0
- package/dist/blocks/settings/svelte/index.js +14 -0
- package/dist/blocks/settings/vue/index.d.ts +13 -0
- package/dist/blocks/settings/vue/index.js +14 -0
- package/dist/blocks/share-links/index.d.ts +99 -0
- package/dist/blocks/share-links/index.js +99 -0
- package/dist/blocks/shared-signals/index.d.ts +395 -0
- package/dist/blocks/shared-signals/index.js +880 -0
- package/dist/blocks/signing-keys/index.d.ts +29 -0
- package/dist/blocks/signing-keys/index.js +161 -0
- package/dist/blocks/sla/index.d.ts +114 -0
- package/dist/blocks/sla/index.js +122 -0
- package/dist/blocks/sso/index.d.ts +169 -147
- package/dist/blocks/sso/index.js +259 -321
- package/dist/blocks/state-machine/index.d.ts +105 -0
- package/dist/blocks/state-machine/index.js +116 -0
- package/dist/blocks/tags/index.d.ts +20 -0
- package/dist/blocks/tags/index.js +28 -0
- package/dist/blocks/tags/react/index.d.ts +28 -0
- package/dist/blocks/tags/react/index.js +47 -0
- package/dist/blocks/tags/react/server.d.ts +7 -0
- package/dist/blocks/tags/react/server.js +7 -0
- package/dist/blocks/tags/solid/index.d.ts +13 -0
- package/dist/blocks/tags/solid/index.js +14 -0
- package/dist/blocks/tags/svelte/index.d.ts +13 -0
- package/dist/blocks/tags/svelte/index.js +14 -0
- package/dist/blocks/tags/vue/index.d.ts +13 -0
- package/dist/blocks/tags/vue/index.js +14 -0
- package/dist/blocks/targets/index.d.ts +82 -0
- package/dist/blocks/targets/index.js +73 -0
- package/dist/blocks/teams/index.d.ts +61 -0
- package/dist/blocks/teams/index.js +83 -0
- package/dist/blocks/templates/index.d.ts +362 -0
- package/dist/blocks/templates/index.js +483 -0
- package/dist/blocks/time-tracking/index.d.ts +250 -0
- package/dist/blocks/time-tracking/index.js +317 -0
- package/dist/blocks/trash/index.d.ts +78 -0
- package/dist/blocks/trash/index.js +79 -0
- package/dist/blocks/undo/index.d.ts +9 -0
- package/dist/blocks/undo/index.js +14 -0
- package/dist/blocks/undo/react/index.d.ts +17 -0
- package/dist/blocks/undo/react/index.js +24 -0
- package/dist/blocks/undo/react/server.d.ts +7 -0
- package/dist/blocks/undo/react/server.js +7 -0
- package/dist/blocks/undo/solid/index.d.ts +13 -0
- package/dist/blocks/undo/solid/index.js +14 -0
- package/dist/blocks/undo/svelte/index.d.ts +13 -0
- package/dist/blocks/undo/svelte/index.js +14 -0
- package/dist/blocks/undo/vue/index.d.ts +13 -0
- package/dist/blocks/undo/vue/index.js +14 -0
- package/dist/blocks/usage/index.d.ts +10 -4
- package/dist/blocks/usage/index.js +16 -232
- package/dist/blocks/usage/react/index.d.ts +23 -0
- package/dist/blocks/usage/react/index.js +38 -0
- package/dist/blocks/usage/react/server.d.ts +7 -0
- package/dist/blocks/usage/react/server.js +7 -0
- package/dist/blocks/usage/solid/index.d.ts +13 -0
- package/dist/blocks/usage/solid/index.js +14 -0
- package/dist/blocks/usage/svelte/index.d.ts +13 -0
- package/dist/blocks/usage/svelte/index.js +14 -0
- package/dist/blocks/usage/vue/index.d.ts +13 -0
- package/dist/blocks/usage/vue/index.js +14 -0
- package/dist/blocks/versions/index.d.ts +165 -0
- package/dist/blocks/versions/index.js +283 -0
- package/dist/blocks/waitlist/index.d.ts +57 -19
- package/dist/blocks/waitlist/index.js +47 -12
- package/dist/blocks/webhooks/index.d.ts +275 -134
- package/dist/blocks/webhooks/index.js +775 -231
- package/dist/blocks/work-items/index.d.ts +208 -0
- package/dist/blocks/work-items/index.js +305 -0
- package/dist/blocks/workflow-builder/index.d.ts +26 -6
- package/dist/blocks/workflow-builder/index.js +30 -5
- package/dist/blocks/workflow-builder/react/index.d.ts +4 -19
- package/dist/blocks/workflow-builder/react/index.js +45 -89
- package/dist/blocks/workflow-builder/solid/index.d.ts +20 -0
- package/dist/blocks/workflow-builder/solid/index.js +23 -0
- package/dist/blocks/workflow-builder/svelte/index.d.ts +20 -0
- package/dist/blocks/workflow-builder/svelte/index.js +23 -0
- package/dist/blocks/workflow-builder/vue/index.d.ts +20 -0
- package/dist/blocks/workflow-builder/vue/index.js +23 -0
- package/dist/blocks/workflows/index.d.ts +20 -3
- package/dist/blocks/workflows/index.js +27 -3
- package/dist/blocks/workflows/react/index.d.ts +5 -20
- package/dist/blocks/workflows/react/index.js +41 -113
- package/dist/blocks/workflows/solid/index.d.ts +20 -0
- package/dist/blocks/workflows/solid/index.js +23 -0
- package/dist/blocks/workflows/svelte/index.d.ts +20 -0
- package/dist/blocks/workflows/svelte/index.js +23 -0
- package/dist/blocks/workflows/vue/index.d.ts +20 -0
- package/dist/blocks/workflows/vue/index.js +23 -0
- package/dist/blocks-D2WQ63PI.js +84 -0
- package/dist/bookings-0XnhHNLM.js +181 -0
- package/dist/build-Cm0T5MVG.js +1815 -0
- package/dist/build-Cx08LOT7.js +689 -0
- package/dist/calendar-DcFrpSOy.js +801 -0
- package/dist/casing-DdFWEtqr.js +16 -0
- package/dist/channel-D-LHCY11.d.ts +78 -0
- package/dist/channels-C-GCoNLd.js +114 -0
- package/dist/chat-sdk/index.d.ts +131 -7
- package/dist/chat-sdk/index.js +155 -6
- package/dist/chat-sdk/react/index.d.ts +2 -1
- package/dist/chat-sdk/react/index.js +1 -2
- package/dist/chat-sdk/react/server.d.ts +2 -1
- package/dist/chat-sdk/react/server.js +1 -2
- package/dist/claims-0KZVT804.js +61 -0
- package/dist/cli/add-B0zoJUYX.js +651 -0
- package/dist/cli/add-Bd5M6uEZ.js +75 -0
- package/dist/cli/add-CT6p5psO.js +1 -0
- package/dist/cli/adopt-C9jl8z0h.js +1 -0
- package/dist/cli/adopt-CebmlHL-.js +393 -0
- package/dist/cli/agent-CCt_aXpJ.js +176 -0
- package/dist/cli/apply-Dxk8AUNU.js +302 -0
- package/dist/cli/arazzo-1.0-BalU61-_.js +532 -0
- package/dist/cli/arazzo-1.1-Bnfasbun.js +705 -0
- package/dist/cli/asyncapi-3.0.0-C78dBjR6.js +5593 -0
- package/dist/cli/asyncapi-3.1.0-g-7aIfV1.js +5833 -0
- package/dist/cli/bin.js +41 -21
- package/dist/cli/blocks-Bzz326nn.js +1 -0
- package/dist/cli/blocks-Dq25D80b.js +124 -0
- package/dist/cli/cache-Cx6qlRDR.js +502 -0
- package/dist/cli/catalog-Di15TkM2.js +187 -0
- package/dist/cli/codemod-woL4cVe0.js +985 -0
- package/dist/cli/command-CK9Cn8HV.js +836 -0
- package/dist/cli/completion-BO5UK6bG.js +1 -0
- package/dist/cli/completion-CWoDmFZr.js +205 -0
- package/dist/cli/completion-J3dqnNoW.js +30 -0
- package/dist/cli/config-C1d-mbUA.js +1 -0
- package/dist/cli/config-CLHpTk9Y.js +1421 -0
- package/dist/cli/config-MuKY9kUj.js +39 -0
- package/dist/cli/config-edit-Ct1lXe8a.js +603 -0
- package/dist/cli/db-DT1bGB02.js +78 -0
- package/dist/cli/design-edit-B-WsnhUF.js +175 -0
- package/dist/cli/detect-DYDUBLU4.js +84 -0
- package/dist/cli/dist-D_VbPAMR.js +129 -0
- package/dist/cli/dist-DuiMMRbJ.js +1112 -0
- package/dist/cli/doctor-SGw36h1D.js +3806 -0
- package/dist/cli/emit-ZAYeh4Yn.js +1042 -0
- package/dist/cli/env-CVXvJoLP.js +142 -0
- package/dist/cli/env-D3gZ-OHj.js +1 -0
- package/dist/cli/env-DJ4ZaJpe.js +1 -0
- package/dist/cli/env-DMw_MBe5.js +996 -0
- package/dist/cli/errors-Caiz_0so.js +98 -0
- package/dist/cli/fastest-levenshtein-dhRRvrM2.js +120 -0
- package/dist/cli/files-DDvAwTko.js +963 -0
- package/dist/cli/gen-B344S1Oy.js +304 -0
- package/dist/cli/guards-CUlDNYZs.js +8 -0
- package/dist/cli/index.d.ts +297 -140
- package/dist/cli/index.js +13 -8
- package/dist/cli/init-B1dL-RZL.js +393 -0
- package/dist/cli/introspect-BPcFi8ow.js +51 -0
- package/dist/cli/io-BiPX-_J1.js +37 -0
- package/dist/cli/jsonc-C8M0EhHB.js +1 -0
- package/dist/cli/keys-jsxCNJdz.js +106 -0
- package/dist/cli/metadata-CxBZo4KM.js +138 -0
- package/dist/cli/module-migration-YFFdWC5X.js +592 -0
- package/dist/cli/moved-D9OT_Uyy.js +152 -0
- package/dist/cli/names-D6LrQnOv.js +6 -0
- package/dist/cli/openapi-3.0-t7xwkuRH.js +928 -0
- package/dist/cli/openapi-3.1-CVze7tBS.js +870 -0
- package/dist/cli/openapi-3.2-CFoMYM01.js +1031 -0
- package/dist/cli/parse-DE59XyWt.js +170 -0
- package/dist/cli/preset-DmcC4nWE.js +129 -0
- package/dist/cli/prompts-Bvg_DBpe.js +1137 -0
- package/dist/cli/redact-PjNswZOs.js +35 -0
- package/dist/cli/rolldown-runtime-kJ_i4yPo.js +26 -0
- package/dist/cli/run-CM_2g6KQ.js +684 -0
- package/dist/cli/run-DaHfUUO9.js +1539 -0
- package/dist/cli/scaffold-CFdDq36-.js +898 -0
- package/dist/cli/scaffold-Dsjr7sOT.js +1 -0
- package/dist/cli/seed-DldDdXWO.js +113 -0
- package/dist/cli/seed-DtRFysBe.js +1 -0
- package/dist/cli/shell-Btv_4Yhe.js +10 -0
- package/dist/cli/skills-v34NDb2D.js +121 -0
- package/dist/cli/snapshot-DAxLi4hO.js +347 -0
- package/dist/cli/source-args-0I9zylYy.js +47 -0
- package/dist/cli/spec-CaaSOYZS.js +7501 -0
- package/dist/cli/spec-De0cfceR.js +1 -0
- package/dist/cli/sql-0I1EQ3JG.js +2 -0
- package/dist/cli/sql-DDLWwzh9.js +326 -0
- package/dist/cli/stack-status-CRanl-CN.js +456 -0
- package/dist/cli/style-2JfIPVMQ.js +29 -0
- package/dist/cli/supabase-toml-DjLgBYEo.js +1153 -0
- package/dist/cli/sync-DFx-6t5n.js +88 -0
- package/dist/cli/topics-GJuIDwlY.js +30 -0
- package/dist/cli/trace-VbdO6bcN.js +7 -0
- package/dist/cli/typegen--TfvOPLh.js +494 -0
- package/dist/cli/typegen-version-BNBPI4Eu.js +9 -0
- package/dist/cli/validate-BfWNKvxy.js +7522 -0
- package/dist/cli/version-DNRW4DAP.js +4 -0
- package/dist/cli/write-BS6F3Yvz.js +180 -0
- package/dist/client/index.d.ts +7 -3
- package/dist/client/index.js +207 -4
- package/dist/client/native/index.d.ts +71 -4
- package/dist/client/native/index.js +65 -6
- package/dist/client-01MAuqzW.js +137 -0
- package/dist/client-B7QVIrJS.d.ts +263 -0
- package/dist/client-B9CqzgPO.js +75 -0
- package/dist/client-BAcILZOf.d.ts +122 -0
- package/dist/client-BOT2KVIp.js +128 -0
- package/dist/client-BUGIS__1.js +1051 -0
- package/dist/client-BVZtq_rQ.d.ts +34 -0
- package/dist/client-BYaOGCOG.js +84 -0
- package/dist/client-BfgwocyT.js +155 -0
- package/dist/client-BpS8a6Fm.js +51 -0
- package/dist/client-BxnLb9bz.d.ts +58 -0
- package/dist/client-BzCv4kKE.js +65 -0
- package/dist/client-C-2ajnhM.js +89 -0
- package/dist/client-C5mUEb2n.js +55 -0
- package/dist/client-C9QrWrnt.js +209 -0
- package/dist/client-CFdMJ1h9.d.ts +277 -0
- package/dist/client-CHmjaI0j.d.ts +103 -0
- package/dist/client-CWs3X4g1.js +120 -0
- package/dist/client-Cdedx_lw.js +438 -0
- package/dist/client-CiGjS6us.js +169 -0
- package/dist/client-CilSKXNu.js +288 -0
- package/dist/client-ClZ0D-if.d.ts +162 -0
- package/dist/client-Cmensu7l.d.ts +419 -0
- package/dist/client-Co6BPmvr.d.ts +108 -0
- package/dist/client-CoVGPi0c.js +133 -0
- package/dist/client-CvITjt-9.js +310 -0
- package/dist/client-CzI4QpG3.d.ts +131 -0
- package/dist/client-D5CZ2a34.d.ts +455 -0
- package/dist/client-DAHsEOVV.d.ts +155 -0
- package/dist/client-DG7FwgZD.js +104 -0
- package/dist/client-DIrCmOXz.d.ts +157 -0
- package/dist/client-DNq8xYb-.js +52 -0
- package/dist/client-DdfSIZ3M.d.ts +107 -0
- package/dist/client-DjTRlN3a.d.ts +68 -0
- package/dist/client-Ezlbskjq.js +60 -0
- package/dist/client-LLmgiCwJ.d.ts +135 -0
- package/dist/client-Lx3mlvKO.d.ts +100 -0
- package/dist/client-PGRk3DGz.js +98 -0
- package/dist/client-Tc47rlSe.d.ts +350 -0
- package/dist/client-VvY0K3wr.d.ts +59 -0
- package/dist/client-WAdEBBrH.d.ts +65 -0
- package/dist/client-WHeWTNVL.d.ts +130 -0
- package/dist/client-WgrPIHH-.js +213 -0
- package/dist/client-ZTtSV3l8.js +40 -0
- package/dist/client-b2_GjzzD.js +438 -0
- package/dist/client-ckXfdy1k.js +38 -0
- package/dist/client-e-hFkLUf.d.ts +34 -0
- package/dist/client-hyP_nS5R.d.ts +218 -0
- package/dist/client-i8glKhxh.js +67 -0
- package/dist/client-iDLLvGR4.d.ts +52 -0
- package/dist/client-pxjbgOz6.js +376 -0
- package/dist/client-xkSCp9hN.d.ts +101 -0
- package/dist/client-ysNShuJZ.d.ts +39 -0
- package/dist/clone-dN9XOL1K.js +29 -0
- package/dist/cloud-event-5rCEzIgK.d.ts +64 -0
- package/dist/cloud-event-CTh9Sr5w.js +60 -0
- package/dist/codecs-Bm46sVxr.d.ts +215 -0
- package/dist/codecs-YAekuQ08.js +358 -0
- package/dist/codegen-DeoSt1mi.d.ts +1571 -0
- package/dist/comments-D7sbd0xG.js +230 -0
- package/dist/commerce/index.d.ts +211 -0
- package/dist/commerce/index.js +517 -0
- package/dist/compiler-BVxepAY0.d.ts +14 -0
- package/dist/compose-Djntdacs.js +53 -0
- package/dist/composite-M6zPs1Xm.js +130 -0
- package/dist/composite-djtGy6bz.d.ts +67 -0
- package/dist/config/index.d.ts +7 -6
- package/dist/config/index.js +7 -4
- package/dist/config-BA1K4OPk.js +557 -0
- package/dist/config-C4MozTD7.js +3892 -0
- package/dist/connector-Cp8CqssJ.d.ts +107 -0
- package/dist/connectors-CjD-R2ks.d.ts +141 -0
- package/dist/context-1sSWcd7_.d.ts +365 -0
- package/dist/context-B8_p3MXo.js +11 -0
- package/dist/context-BDDgjoxz.js +41 -0
- package/dist/context-C-bHOtoD.js +5 -0
- package/dist/context-D6ZMKc2L.js +19 -0
- package/dist/context-wDKxSl9x.js +9 -0
- package/dist/controller-D6NyNrlZ.js +79 -0
- package/dist/controller-D845qKh2.d.ts +46 -0
- package/dist/credentials/index.d.ts +15 -5
- package/dist/credentials/index.js +17 -17
- package/dist/cron-CUaKTjWC.js +145 -0
- package/dist/cron-route-CoL-By8Z.js +24 -0
- package/dist/csv-CVfXqaAu.js +89 -0
- package/dist/csv-D3eKxV1T.d.ts +28 -0
- package/dist/define-B2ln373W.js +1896 -0
- package/dist/define-DxHHbNEb.d.ts +1005 -0
- package/dist/define-block-B6Gjs57G.js +52 -0
- package/dist/define-block-CLZMEFeK.d.ts +256 -0
- package/dist/delegation-Dt8hMJWu.js +140 -0
- package/dist/delivery-B1mKaOen.js +30 -0
- package/dist/delivery-BeHgwS3k.d.ts +69 -0
- package/dist/documents-CWn2mtYf.d.ts +96 -0
- package/dist/edge/index.d.ts +68 -13
- package/dist/edge/index.js +75 -43
- package/dist/elysia/index.d.ts +1 -1
- package/dist/elysia/index.js +2 -2
- package/dist/email-BcmbIWOX.d.ts +42 -0
- package/dist/embeddings-C2S14foD.d.ts +78 -0
- package/dist/embeddings-CVeOoufZ.js +128 -0
- package/dist/ended-nIdGCHxk.d.ts +70 -0
- package/dist/entitlements-BvU5dLpW.js +45 -0
- package/dist/entitlements-CbzCKalR.d.ts +53 -0
- package/dist/env/index.d.ts +1 -1
- package/dist/env/index.js +12 -5
- package/dist/envelope-CHYk5MXU.js +90 -0
- package/dist/errors-8i6tSICm.js +301 -0
- package/dist/errors-PIpcoe4z.js +44 -0
- package/dist/escape-like-AUEPn-C5.d.ts +15 -0
- package/dist/eve/index.d.ts +5 -5
- package/dist/eve/index.js +11 -17
- package/dist/eve-DUF70Vgi.d.ts +151 -0
- package/dist/event-calendar-DJXXMJ3x.d.ts +217 -0
- package/dist/event-map-Dy2vKHai.js +19 -0
- package/dist/events/index.d.ts +4 -4
- package/dist/events/index.js +16 -8
- package/dist/events-CTreRrgP.d.ts +800 -0
- package/dist/events-xbpHkcK9.js +82 -0
- package/dist/executor-BBHgjUJu.d.ts +39 -0
- package/dist/executor-BINiCFNp.d.ts +95 -0
- package/dist/executor-BXSHYyW2.js +735 -0
- package/dist/executor-D1kYY5BA.js +206 -0
- package/dist/executor-D3K3tycZ.js +147 -0
- package/dist/executor-DKrZr3AC.d.ts +174 -0
- package/dist/executor-DoE-5iM8.d.ts +272 -0
- package/dist/expo/index.d.ts +4 -4
- package/dist/expo/index.js +7 -7
- package/dist/expo-sqlite/index.d.ts +3 -3
- package/dist/expo-sqlite/index.js +2 -2
- package/dist/extra-CGQ2_q3S.js +10 -0
- package/dist/field-errors-CWXN_h_E.d.ts +113 -0
- package/dist/field-errors-DZVRWRkf.js +13 -0
- package/dist/field-formats-Cif5gr7c.js +102 -0
- package/dist/field-formats-DCvOQlOy.d.ts +39 -0
- package/dist/filter-evaluate-C0ULNfS7.js +214 -0
- package/dist/filter-evaluate-CjcFq0RT.d.ts +34 -0
- package/dist/filter-query-B3lhckKX.js +518 -0
- package/dist/filter-query-BKmRYrTE.d.ts +121 -0
- package/dist/flags-D_D1jAHB.d.ts +230 -0
- package/dist/flags-XAOsdNAc.js +279 -0
- package/dist/flags-sdk/index.d.ts +143 -0
- package/dist/flags-sdk/index.js +175 -0
- package/dist/form-definition-sagoefQr.d.ts +95 -0
- package/dist/format-CNwSjXUU.d.ts +70 -0
- package/dist/framework-DG5Bv39u.d.ts +26 -0
- package/dist/framework-INbjMZX1.js +51 -0
- package/dist/function-contract-B4c0XuTU.d.ts +21 -0
- package/dist/function-contract-DmkBg19r.js +5 -0
- package/dist/gateway-Cup00l0w.d.ts +109 -0
- package/dist/gateway-options-ClvvfuuU.d.ts +29 -0
- package/dist/gateway-options-DcLcWL5_.js +27 -0
- package/dist/graph-Cs28bOlK.js +360 -0
- package/dist/groups-CxonH3u5.js +16 -0
- package/dist/guards-6F2bCtQR.js +12 -0
- package/dist/h3/index.d.ts +7 -3
- package/dist/h3/index.js +3 -3
- package/dist/h3/v1/index.d.ts +1 -1
- package/dist/h3/v1/index.js +2 -2
- package/dist/history-GH1HJWQV.js +271 -0
- package/dist/hmac-DCud0myt.js +22 -0
- package/dist/hono/index.d.ts +33 -14
- package/dist/hono/index.js +58 -25
- package/dist/http-BF-V0CUF.js +25 -0
- package/dist/impersonation-CDeCzZP6.js +62 -0
- package/dist/impersonation-D5chOkrO.d.ts +25 -0
- package/dist/inbox-3ql4phyr.d.ts +400 -0
- package/dist/index-BIi8i6BO.d.ts +97 -0
- package/dist/index-BkzNUPId.d.ts +131 -0
- package/dist/index-BlqrGvb3.d.ts +227 -0
- package/dist/index-Brhm22eL.d.ts +138 -0
- package/dist/index-Bvw9r94Q.d.ts +245 -0
- package/dist/index-CETRk4YO.d.ts +82 -0
- package/dist/index-CrZitvSC.d.ts +258 -0
- package/dist/index-DfVXx4Ia.d.ts +202 -0
- package/dist/index-DygICr8c.d.ts +206 -0
- package/dist/index-Ej8XQ9w9.d.ts +58 -0
- package/dist/index-jhqhynmh.d.ts +58 -0
- package/dist/index.d.ts +90 -15
- package/dist/index.js +16 -14
- package/dist/iso4217-A8ev-CNW.js +176 -0
- package/dist/json-schema-CpYINXG8.js +548 -0
- package/dist/jws-35a8VhFV.d.ts +60 -0
- package/dist/jws-milwSg7E.js +191 -0
- package/dist/kit-D5S7KNFe.d.ts +66 -0
- package/dist/kit-MUK34-ZG.js +104 -0
- package/dist/knowledge-BXQ2-V0a.d.ts +187 -0
- package/dist/knowledge-CJ_Mm3ic.js +272 -0
- package/dist/lint/index.js +9 -9
- package/dist/list/index.d.ts +4 -3
- package/dist/list/index.js +4 -2
- package/dist/list-query-CBXNfJt4.js +549 -0
- package/dist/list-query-PvP3pPGQ.d.ts +194 -0
- package/dist/live-DwDreq1n.js +239 -0
- package/dist/mcp/index.d.ts +67 -20
- package/dist/mcp/index.js +220 -135
- package/dist/mcp/sdk/index.d.ts +38 -6
- package/dist/mcp/sdk/index.js +89 -7
- package/dist/message-B0fNJgq8.d.ts +93 -0
- package/dist/messages-Cx4ttLJJ.js +493 -0
- package/dist/metric-definition-95HFoW1V.d.ts +70 -0
- package/dist/metric-definition-BjxVn4R5.js +117 -0
- package/dist/mfa-DtflCXEt.d.ts +30 -0
- package/dist/model-lUafmeBQ.d.ts +311 -0
- package/dist/model-messages-CTu-6kBu.js +206 -0
- package/dist/model-messages-D4GZllOD.d.ts +34 -0
- package/dist/money-95Rff2vT.js +185 -0
- package/dist/money-DFpWzQvk.d.ts +76 -0
- package/dist/money-codec-C_-K5ZUU.js +41 -0
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +2 -2
- package/dist/next/index.d.ts +115 -55
- package/dist/next/index.js +208 -173
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +3 -3
- package/dist/nuxt/index.d.ts +2 -2
- package/dist/nuxt/index.js +3 -2
- package/dist/onboarding-BZvLLPaY.js +68 -0
- package/dist/openapi/index.d.ts +4 -2
- package/dist/openapi/index.js +21 -343
- package/dist/operations-C9-UcReN.d.ts +6 -0
- package/dist/operations-CsIfMED7.js +29 -0
- package/dist/optional-peer-Dx8TaYXw.js +29 -0
- package/dist/options-B0FcEKtH.js +5 -0
- package/dist/options-B5BU2Yg7.js +11 -0
- package/dist/options-B5woz53h.js +5 -0
- package/dist/options-B7EJaOX-.js +5 -0
- package/dist/options-B9q8CROT.js +9 -0
- package/dist/options-BA6jV6py.js +10 -0
- package/dist/options-BAW2ZlZ8.js +8 -0
- package/dist/options-BMjcVuaI.js +82 -0
- package/dist/options-BOOEzor9.js +5 -0
- package/dist/options-BQ07tTYr.js +11 -0
- package/dist/options-BZsoPJGX.js +5 -0
- package/dist/options-BesyRBnM.js +16 -0
- package/dist/options-Bf96aVk5.js +10 -0
- package/dist/options-BlOPivzq.js +8 -0
- package/dist/options-Blg8lAkz.js +9 -0
- package/dist/options-Bn4cu0gt.js +5 -0
- package/dist/options-BnoJOwXK.js +8 -0
- package/dist/options-Bp7sgKvl.js +30 -0
- package/dist/options-BqO9GYig.js +311 -0
- package/dist/options-BxcFLL1G.js +8 -0
- package/dist/options-C1HR4UZd.js +13 -0
- package/dist/options-C239TLRF.js +14 -0
- package/dist/options-C2HesT4A.js +9 -0
- package/dist/options-C3EzJATk.js +10 -0
- package/dist/options-C3hZ1fbC.js +10 -0
- package/dist/options-C6rEL6U5.js +8 -0
- package/dist/options-CAzVf-1T.js +8 -0
- package/dist/options-CGKSUFUq.js +5 -0
- package/dist/options-CGjGE8xS.js +12 -0
- package/dist/options-CK5WiFwG.js +11 -0
- package/dist/options-CN7PHkhU.js +8 -0
- package/dist/options-CTZNpb2n.js +5 -0
- package/dist/options-CUqQ9pm7.js +9 -0
- package/dist/options-CVSWgZpY.js +8 -0
- package/dist/options-CXFz0xxS.js +8 -0
- package/dist/options-CZk_fbbg.js +9 -0
- package/dist/options-C_pb1Nd3.js +5 -0
- package/dist/options-CbSOj53r.d.ts +52 -0
- package/dist/options-ChD15QxJ.js +9 -0
- package/dist/options-CkScQRJR.js +12 -0
- package/dist/options-CljDnQt2.js +25 -0
- package/dist/options-CmraJhd9.js +5 -0
- package/dist/options-CoX6VKGb.js +8 -0
- package/dist/options-CrC78Tee.js +5 -0
- package/dist/options-Ctac2R0Q.js +11 -0
- package/dist/options-CyD7OObW.js +17 -0
- package/dist/options-D1blDihM.js +9 -0
- package/dist/options-D2Gd6VfS.js +8 -0
- package/dist/options-D2d1fFuw.js +11 -0
- package/dist/options-D40CQzji.js +8 -0
- package/dist/options-D7f2VKzj.js +25 -0
- package/dist/options-DARkpk2P.js +8 -0
- package/dist/options-DCduTMST.js +17 -0
- package/dist/options-DDzggjN7.js +8 -0
- package/dist/options-DMR68VAC.js +5 -0
- package/dist/options-DNKyN5uq.js +20 -0
- package/dist/options-DTDxFT6J.js +13 -0
- package/dist/options-DWpz3V3F.js +8 -0
- package/dist/options-DXqcJyOP.js +10 -0
- package/dist/options-DYBQ973I.js +8 -0
- package/dist/options-Dh4wu9Ks.js +15 -0
- package/dist/options-Dmg1Da9P.js +25 -0
- package/dist/options-DsUgamiy.js +5 -0
- package/dist/options-EsUh744F.js +13 -0
- package/dist/options-Fz6xqu-b.js +5 -0
- package/dist/options-HSv8R6h5.js +13 -0
- package/dist/options-I8zVkB_y.js +8 -0
- package/dist/options-MHhjOoWz.js +5 -0
- package/dist/options-MLxMkd5B.js +11 -0
- package/dist/options-OJ5zmgr8.js +10 -0
- package/dist/options-QKP9FFcK.js +8 -0
- package/dist/options-SViK_2x2.js +12 -0
- package/dist/options-XgfTctbI.js +5 -0
- package/dist/options-_9arpsX9.js +11 -0
- package/dist/options-eBPsk4WI.js +11 -0
- package/dist/options-kLKILdIu.js +10 -0
- package/dist/options-n22NK3PL.js +8 -0
- package/dist/options-oeAq4Ho5.js +12 -0
- package/dist/options-qU8vgxhO.js +18 -0
- package/dist/options-vXMBEWSH.js +5 -0
- package/dist/options-wFnK3qWl.js +9 -0
- package/dist/options-xVAy3UsV.js +9 -0
- package/dist/organizations-Cw7om8uk.js +398 -0
- package/dist/orpc/index.d.ts +26 -10
- package/dist/orpc/index.js +66 -44
- package/dist/otel/index.d.ts +3 -3
- package/dist/otel/index.js +42 -7
- package/dist/outbox-BTeqjbum.d.ts +181 -0
- package/dist/overlay/index.d.ts +233 -0
- package/dist/overlay/index.js +554 -0
- package/dist/payments-h45bswA-.js +16 -0
- package/dist/pg-error-BV_X8Isq.js +26 -0
- package/dist/plugin-CDLJRFFg.d.ts +190 -0
- package/dist/plugins/actor/index.d.ts +1 -1
- package/dist/plugins/actor/index.js +1 -1
- package/dist/plugins/rules/index.d.ts +2 -2
- package/dist/plugins/rules/index.js +2 -2
- package/dist/plugins/soft-delete/index.d.ts +3 -3
- package/dist/plugins/soft-delete/index.js +11 -4
- package/dist/plugins/tenant/index.d.ts +9 -3
- package/dist/plugins/tenant/index.js +17 -3
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/timestamps/index.js +8 -1
- package/dist/plugins/validation/index.d.ts +2 -2
- package/dist/plugins/validation/index.js +4 -4
- package/dist/pool-CwOCsX9e.d.ts +114 -0
- package/dist/pool-errors-GMjlCN0d.js +27 -0
- package/dist/ports-Ca63W4cW.d.ts +285 -0
- package/dist/ports-DAdQyjZz.d.ts +86 -0
- package/dist/ports-DGK3KTDH.js +133 -0
- package/dist/postgres/index.d.ts +28 -6
- package/dist/postgres/index.js +54 -22
- package/dist/postgrest-Cw9Bs5gm.d.ts +53 -0
- package/dist/powersync/index.d.ts +5 -5
- package/dist/powersync/index.js +4 -4
- package/dist/powersync/react/index.d.ts +8 -3
- package/dist/powersync/react/index.js +11 -3
- package/dist/preset/index.d.ts +352 -0
- package/dist/preset/index.js +564 -0
- package/dist/problem-CEjyhV5T.d.ts +76 -0
- package/dist/problem-pIiL3WbE.js +159 -0
- package/dist/provider-9gBq9W6k.d.ts +113 -0
- package/dist/provider-DKh2xFZb.js +57 -0
- package/dist/push-token-D6REHMMw.js +16 -0
- package/dist/push-token-asrmi7-6.d.ts +24 -0
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +1 -1
- package/dist/query-Ctz-qKRx.js +303 -0
- package/dist/range-DwpWe8e7.js +7 -0
- package/dist/range-p5V4rBhZ.d.ts +8 -0
- package/dist/rank-keys-DcPMt_Jk.js +60 -0
- package/dist/rank-result-DS8IoLup.js +18 -0
- package/dist/rank-result-Dngpt2n5.d.ts +14 -0
- package/dist/rate-limit--QSiFA6D.js +325 -0
- package/dist/rate-limit-BtbddDnE.js +49 -0
- package/dist/rate-limit-C88MEAOm.d.ts +41 -0
- package/dist/ratelimit-headers-Bsxx0Tj2.js +62 -0
- package/dist/react/index.d.ts +9 -9
- package/dist/react/index.js +4 -5
- package/dist/react/native/index.d.ts +1 -1
- package/dist/react/native/index.js +2 -2
- package/dist/react/server.d.ts +10 -10
- package/dist/react/server.js +4 -4
- package/dist/react/session.d.ts +2 -2
- package/dist/react-CKXUkwPx.js +410 -0
- package/dist/react-controller-Xn-IU44p.js +40 -0
- package/dist/react-env-Cc7Vf6eb.js +13 -0
- package/dist/react-router/index.d.ts +6 -6
- package/dist/react-router/index.js +10 -12
- package/dist/read-set-GEb-i0On.js +314 -0
- package/dist/realtime/index.d.ts +8 -4
- package/dist/realtime/index.js +5 -333
- package/dist/realtime-status-D2dw1hOE.js +12 -0
- package/dist/realtime-status-DcsO00Gw.d.ts +8 -0
- package/dist/refusal-br4Ma9Cf.js +61 -0
- package/dist/refusal-oD3ISM9h.d.ts +18 -0
- package/dist/replicas-BvIL4_jL.js +94 -0
- package/dist/resolve-CAR9oaKW.js +869 -0
- package/dist/resolve-w9EpHzuM.d.ts +266 -0
- package/dist/resource-B4ka8dDH.d.ts +106 -0
- package/dist/resource-C8r5xGqY.js +463 -0
- package/dist/resource-DO4gbVi5.js +91 -0
- package/dist/resource-execute-D0yQ-8WR.d.ts +12 -0
- package/dist/resource-schemas-BJ518zFH.js +79 -0
- package/dist/resource-types-D2vEQVXI.d.ts +141 -0
- package/dist/resources-BklF-rjz.d.ts +7 -0
- package/dist/resources-BlZdLsWQ.js +64 -0
- package/dist/respond-C7I8kLK_.d.ts +93 -0
- package/dist/respond-DdhZ9Wbn.js +95 -0
- package/dist/result-BlgnMB0H.js +128 -0
- package/dist/result-Cj3yWhjH.d.ts +298 -0
- package/dist/rrule-zBh3CA1r.js +290 -0
- package/dist/rules-B0-3Iosu.js +261 -0
- package/dist/run-watch-CQRdpy-f.js +53 -0
- package/dist/sales-lines-BAk8In-Z.js +41 -0
- package/dist/sales-lines-C6gafAwg.d.ts +28 -0
- package/dist/sales-shared-DAAGwQwN.d.ts +8 -0
- package/dist/sales-shared-SblIgCgI.js +22 -0
- package/dist/scope-DgWjuXUw.js +90 -0
- package/dist/search-B6h03cAx.js +106 -0
- package/dist/search-BtoWY6n_.js +9 -0
- package/dist/server/index.d.ts +211 -43
- package/dist/server/index.js +296 -19
- package/dist/server-types-OohhIQb2.d.ts +737 -0
- package/dist/session-DiWHtYrO.d.ts +95 -0
- package/dist/settings-BXFn9zpS.js +90 -0
- package/dist/shared-BmMcMoW9.js +89 -0
- package/dist/shared-DbO3Dfms.js +14 -0
- package/dist/shared-as0EG51f.js +60 -0
- package/dist/sign-in-D0xN6E_l.js +360 -0
- package/dist/signatures-B41ApWXA.js +145 -0
- package/dist/signatures-BMdJ7neI.d.ts +43 -0
- package/dist/signers-CXt_wA9S.d.ts +385 -0
- package/dist/signing-keys-Bq9mMCTh.d.ts +90 -0
- package/dist/solid/index.d.ts +9 -18
- package/dist/solid/index.js +4 -9
- package/dist/solid-controller-DLsmrczT.js +33 -0
- package/dist/solid-controller-DqlvYFZa.d.ts +11 -0
- package/dist/solid-start/index.d.ts +8 -12
- package/dist/solid-start/index.js +10 -9
- package/dist/spec/index.d.ts +154 -0
- package/dist/spec/index.js +386 -0
- package/dist/spec-pins-Dqpml2dZ.d.ts +84 -0
- package/dist/spec-pins-S4PymRxp.js +60 -0
- package/dist/sql/index.d.ts +327 -140
- package/dist/sql/index.js +71245 -23282
- package/dist/sql-DJrXG-3Z.js +422 -0
- package/dist/sso-BDva_-4y.js +217 -0
- package/dist/sso-BN0LnMqE.d.ts +131 -0
- package/dist/ssr/index.d.ts +5 -6
- package/dist/ssr/index.js +4 -3
- package/dist/standard-B5fe2gnW.js +25 -0
- package/dist/standard-C3_AAF3g.d.ts +7 -0
- package/dist/stats-D6vkb89f.js +1128 -0
- package/dist/storage/index.d.ts +4 -6
- package/dist/storage/index.js +23 -20
- package/dist/storage-api-Cx-1iWBd.d.ts +582 -0
- package/dist/store-B5qYKsTh.d.ts +68 -0
- package/dist/streams/index.d.ts +5 -5
- package/dist/streams/index.js +6 -5
- package/dist/streams/redis/index.d.ts +1 -1
- package/dist/streams/redis/index.js +6 -12
- package/dist/stripe/index.d.ts +16 -0
- package/dist/stripe/index.js +14 -0
- package/dist/stripe-NVcNOhHy.d.ts +140 -0
- package/dist/stripe-XZrSmDTf.js +32 -0
- package/dist/subject-readers-DiePmaYP.js +46 -0
- package/dist/subject-readers-fxP5wu0s.d.ts +21 -0
- package/dist/subjects-z8VWA_lF.d.ts +69 -0
- package/dist/subscribers-Cq--DL1E.js +34 -0
- package/dist/supabase-mcp-C6tMoEjn.d.ts +43 -0
- package/dist/supabase-mcp-DomZ-amK.js +28 -0
- package/dist/support-BsKkvA92.js +522 -0
- package/dist/support-view-BbcZR7Io.d.ts +17 -0
- package/dist/svelte/index.d.ts +8 -17
- package/dist/svelte/index.js +3 -3
- package/dist/svelte-controller-CDAujo-_.js +50 -0
- package/dist/svelte-controller-DxxHEHxD.d.ts +10 -0
- package/dist/sveltekit/index.d.ts +11 -13
- package/dist/sveltekit/index.js +12 -14
- package/dist/table-schema-pQlER3jj.js +283 -0
- package/dist/tags-Dw8vKkcI.d.ts +30 -0
- package/dist/tags-PaG0Ns_9.js +84 -0
- package/dist/tanstack-db/index.d.ts +2 -2
- package/dist/tanstack-db/index.js +1 -1
- package/dist/tanstack-db/supabase/index.d.ts +51 -0
- package/dist/tanstack-db/supabase/index.js +268 -0
- package/dist/tanstack-start/index.d.ts +7 -7
- package/dist/tanstack-start/index.js +9 -13
- package/dist/tax-DDZUB_oc.d.ts +273 -0
- package/dist/tax-D_kSCdWU.js +140 -0
- package/dist/tee-Bsisfd7t.js +101 -0
- package/dist/template-DdgYjIZ5.js +123 -0
- package/dist/temporal-CB5Fpo5d.js +79 -0
- package/dist/temporal-required-DqRzr7i0.js +20 -0
- package/dist/tenant-B-fiItlJ.js +27 -0
- package/dist/tenant-DdmVhsff.d.ts +17 -0
- package/dist/tenant-naming-Bsj3Uvap.js +27 -0
- package/dist/testing/index.d.ts +459 -125
- package/dist/testing/index.js +2368 -720
- package/dist/timing-BMCWgpdZ.js +92 -0
- package/dist/topic-ByDz9edV.js +542 -0
- package/dist/topic-cMS7UtM1.d.ts +359 -0
- package/dist/ttl-cache-XzZ-Q2eX.js +29 -0
- package/dist/types-6oiy6rIa.d.ts +205 -0
- package/dist/types-BRTSpOIh.js +5 -0
- package/dist/types-CdP0z5tS.d.ts +564 -0
- package/dist/types-D0W4fnsc.d.ts +162 -0
- package/dist/types-R6syp1el.js +29 -0
- package/dist/types-YfwpIE-d.d.ts +357 -0
- package/dist/types-pNY_UpDs.d.ts +240 -0
- package/dist/types-vaoP9S9_.d.ts +635 -0
- package/dist/undo-CEGIRkPA.js +44 -0
- package/dist/undo-DGo0skyO.d.ts +43 -0
- package/dist/usage-CdlfuS3i.js +250 -0
- package/dist/usage-DM2rzczj.d.ts +202 -0
- package/dist/vault-tOkPLnMB.d.ts +50 -0
- package/dist/vercel-connect/index.d.ts +1 -1
- package/dist/vercel-connect/index.js +6 -12
- package/dist/verify-D63A2ALE.d.ts +142 -0
- package/dist/verify-EQcC3Khp.js +126 -0
- package/dist/version-D87ZteKy.js +4 -0
- package/dist/view-DZ63nqwt.js +105 -0
- package/dist/view-Dv0A949a.d.ts +90 -0
- package/dist/vue/index.d.ts +9 -18
- package/dist/vue/index.js +4 -17
- package/dist/vue-controller-C9tFzqAc.js +32 -0
- package/dist/vue-controller-HPfMTDa2.d.ts +11 -0
- package/dist/watch-DDuWYv0Y.d.ts +84 -0
- package/dist/watch-DT_B3CnJ.js +139 -0
- package/dist/watch-topic-EFpOIIDE.d.ts +28 -0
- package/dist/watch-topic-miuymrli.js +57 -0
- package/dist/wire-DEY0ajW9.js +45 -0
- package/dist/workflow-builder-OrglbXUh.js +681 -0
- package/dist/workflow-sdk/builder/index.d.ts +46 -15
- package/dist/workflow-sdk/builder/index.js +69 -21
- package/dist/workflow-sdk/index.d.ts +75 -2
- package/dist/workflow-sdk/index.js +83 -3
- package/dist/workflow-sdk/world/index.d.ts +51 -20
- package/dist/workflow-sdk/world/index.js +189 -128
- package/dist/workflow-sdk-BZ6qsRlY.js +243 -0
- package/dist/workflow-sdk-q8cLwW1K.d.ts +161 -0
- package/dist/workflow-sdk-world-DPMdBfzn.js +2103 -0
- package/dist/workflows-C-OvZpeg.js +282 -0
- package/dist/workflows-DFQeXDAI.d.ts +243 -0
- package/dist/yjs/index.d.ts +67 -0
- package/dist/yjs/index.js +212 -0
- package/package.json +837 -44
- package/schemas/cli-commands-v1.json +220 -0
- package/schemas/cli-result-v1.json +138 -0
- package/schemas/config-v1.json +4317 -653
- package/schemas/doctor-report-v1.json +27 -1
- package/schemas/snapshot-v2.json +271 -0
- package/schemas/spec-manifest-v1.json +95 -0
- package/skills/better-supabase/SKILL.md +19 -8
- package/skills/better-supabase/references/plugins.md +2 -2
- package/skills/better-supabase/references/troubleshooting.md +20 -20
- package/skills/better-supabase/references/ui-recipes.md +18652 -0
- package/skills/better-supabase-api/SKILL.md +14 -14
- package/skills/better-supabase-api/references/adapters.md +12 -2
- package/skills/better-supabase-api/references/ai.md +4 -4
- package/skills/better-supabase-api/references/expo.md +7 -4
- package/skills/better-supabase-api/references/powersync.md +2 -1
- package/skills/better-supabase-api/references/streams-credentials.md +8 -5
- package/skills/better-supabase-auth/SKILL.md +18 -11
- package/skills/better-supabase-auth/references/authorization-providers.md +5 -5
- package/skills/better-supabase-testing/SKILL.md +2 -2
- package/testing/act-cases.json +370 -0
- package/dist/access-sql-B0dF-SoF.js +0 -181
- package/dist/actor-CQTlc1Hh.d.ts +0 -43
- package/dist/adapter-iKgjHVPx.js +0 -1190
- package/dist/agents-CVHGd7It.d.ts +0 -94
- package/dist/ai-cache-CBWs1W0k.js +0 -80
- package/dist/ai-cache-DaDu_G5L.d.ts +0 -64
- package/dist/ai-chat-7amvXjmQ.d.ts +0 -590
- package/dist/ai-chat-B24UI962.js +0 -743
- package/dist/ai-files-CSPNswUY.js +0 -319
- package/dist/ai-tasks-Cd1HMFvB.d.ts +0 -131
- package/dist/announcements-CiyOs-xP.js +0 -107
- package/dist/announcements-ZRGnScWI.d.ts +0 -72
- package/dist/api-keys-CIjghYjV.d.ts +0 -156
- package/dist/assistant-DwdpDH1q.d.ts +0 -147
- package/dist/attributes-5dYul0u0.js +0 -13
- package/dist/authorization-BFCqamMs.d.ts +0 -172
- package/dist/base64-D2gsioCY.js +0 -42
- package/dist/before-route-CnR0C0Jr.js +0 -30
- package/dist/bind-Bu_ZNa3W.d.ts +0 -62
- package/dist/bind-l4kAvYSv.js +0 -97
- package/dist/block-events-CrT8r7Fe.js +0 -76
- package/dist/block-fields-GFkxl4dP.js +0 -49
- package/dist/block-fields-SJ6fEf3o.d.ts +0 -31
- package/dist/block-helpers-CKtbFcRv.d.ts +0 -37
- package/dist/block-helpers-DWHxHsEQ.js +0 -190
- package/dist/block-hooks-BmjMyXTa.js +0 -114
- package/dist/block-hooks-plbZ0AbJ.d.ts +0 -107
- package/dist/block-transport-BLr-ZgLc.js +0 -59
- package/dist/block-transport-DvaoPuZ9.d.ts +0 -48
- package/dist/bucket-Cl46E3jS.d.ts +0 -347
- package/dist/build-BXIzE6Xv.js +0 -689
- package/dist/channel-_2Mx1Oyu.d.ts +0 -70
- package/dist/channels-CkgQ_X60.js +0 -114
- package/dist/claims-DDBQT6BK.js +0 -61
- package/dist/cli/bin.d.ts +0 -1
- package/dist/cli/codemod-Bl_tQpHn.js +0 -491
- package/dist/cli/command-CK14fP91.js +0 -502
- package/dist/cli/config-B9HkL8nF.js +0 -2
- package/dist/cli/config-DU7EJImt.js +0 -49
- package/dist/cli/config-NiPxAmUF.js +0 -1077
- package/dist/cli/db-DOBPt660.js +0 -52
- package/dist/cli/diff-SjkO5rNr.js +0 -752
- package/dist/cli/dist-DBPdlPYK.js +0 -1112
- package/dist/cli/dist-DRAVaE6w.js +0 -842
- package/dist/cli/dist-DreZ24Sz.js +0 -129
- package/dist/cli/doctor-DJk0aeBi.js +0 -3591
- package/dist/cli/env-CJLbUVPB.js +0 -108
- package/dist/cli/env-qXgyMV6r.js +0 -511
- package/dist/cli/errors-4v4DTtda.js +0 -56
- package/dist/cli/fastest-levenshtein-CFN-lNDv.js +0 -120
- package/dist/cli/gen-CCMc39Dx.js +0 -3100
- package/dist/cli/gen-DRmzPI75.js +0 -2
- package/dist/cli/init-BHuEQrQK.js +0 -765
- package/dist/cli/introspect-DzR2nyQb.js +0 -81
- package/dist/cli/io-DI1mTdSA.js +0 -33
- package/dist/cli/jsonc-BUniUpOk.js +0 -2
- package/dist/cli/keys-BGCnnb-s.js +0 -85
- package/dist/cli/openapi-BlRJ18s3.js +0 -66
- package/dist/cli/project-DZRaBaY7.js +0 -75
- package/dist/cli/prompts-BNcNfAve.js +0 -1142
- package/dist/cli/prompts-BTYQGunc.js +0 -2
- package/dist/cli/read-sets-CETOSFx4.js +0 -223
- package/dist/cli/rolldown-runtime-BPOCksWG.js +0 -24
- package/dist/cli/run-BqDPh9UH.js +0 -361
- package/dist/cli/seed-DQzqT7LP.js +0 -100
- package/dist/cli/skills-QQs4q68J.js +0 -138
- package/dist/cli/sql-B8csQPyn.js +0 -495
- package/dist/cli/sql-layout-D6cphHT3.js +0 -69
- package/dist/cli/style-C0NFdJRL.js +0 -29
- package/dist/cli/supabase-toml-B-bIukQF.js +0 -1095
- package/dist/cli/typegen-version-DeFbtzYI.js +0 -8
- package/dist/cli/version-59gcepIG.js +0 -4
- package/dist/client-CI0Z2zWX.js +0 -277
- package/dist/clone-BfgmLU90.js +0 -21
- package/dist/cloud-event-BnmD5fb9.js +0 -46
- package/dist/cloud-event-C1JCc1bH.d.ts +0 -50
- package/dist/compiler-DY_wkj4R.d.ts +0 -14
- package/dist/compose-BIBNgAnq.js +0 -53
- package/dist/composite--yqry7uW.d.ts +0 -146
- package/dist/composite-DXVUibdi.js +0 -130
- package/dist/config-D44Y7PAv.d.ts +0 -984
- package/dist/config-Dn7F5k9A.js +0 -202
- package/dist/connector-Dv8kK0MO.d.ts +0 -107
- package/dist/connectors-CrpknU0P.d.ts +0 -120
- package/dist/context-BCrWe7ow.d.ts +0 -237
- package/dist/cron-DVPUg5k3.js +0 -145
- package/dist/csv-DCK-PT1n.js +0 -25
- package/dist/define-B-TVjC25.js +0 -1915
- package/dist/define-CJJkkr1-.d.ts +0 -980
- package/dist/embeddings-4ZvFzjsU.js +0 -127
- package/dist/embeddings-C9KGQnXt.d.ts +0 -68
- package/dist/ended-XjeGQ5XW.d.ts +0 -63
- package/dist/entitlements-BKSVGtrG.d.ts +0 -51
- package/dist/entitlements-DRl6ZJUm.js +0 -24
- package/dist/envelope-DqnYGRw7.js +0 -47
- package/dist/errors-B11Duf73.js +0 -266
- package/dist/errors-DLjJHPLK.js +0 -44
- package/dist/escape-like-ImTK0ps_.d.ts +0 -15
- package/dist/eve-gT2Fpjut.d.ts +0 -151
- package/dist/events-DWDhx77e.d.ts +0 -549
- package/dist/executor-BVBFM86G.d.ts +0 -36
- package/dist/executor-Bq28caBo.js +0 -718
- package/dist/executor-C-R4pucm.js +0 -83
- package/dist/executor-CaWigTyR.d.ts +0 -148
- package/dist/executor-DbvExCFC.d.ts +0 -30
- package/dist/executor-De1Of3m3.js +0 -523
- package/dist/executor-DvsBbNBS.d.ts +0 -261
- package/dist/field-errors-BFOa7WhB.d.ts +0 -99
- package/dist/field-errors-VF1yb8yI.js +0 -13
- package/dist/framework-BmzgK32X.d.ts +0 -25
- package/dist/framework-a7aRCIqv.js +0 -51
- package/dist/gateway-C1ssRHnf.d.ts +0 -130
- package/dist/graph-BGyLLFLX.js +0 -265
- package/dist/guards-BnzDvFrz.js +0 -10
- package/dist/history-BZih6SFP.js +0 -64
- package/dist/hooks-1BTCJsiw.js +0 -309
- package/dist/impersonation-DcqaTBHx.js +0 -148
- package/dist/inbox-i7E1ppo6.d.ts +0 -384
- package/dist/index-ACiNPN4Z.d.ts +0 -74
- package/dist/index-Bepi-Hgg.d.ts +0 -206
- package/dist/index-BkWT_uBO.d.ts +0 -51
- package/dist/index-Bxih3l0u.d.ts +0 -81
- package/dist/index-CLg87OBW.d.ts +0 -76
- package/dist/index-CaxrMD1A.d.ts +0 -1
- package/dist/index-CdZKQF98.d.ts +0 -138
- package/dist/index-CewnYSpv.d.ts +0 -267
- package/dist/index-ClmjK_o-.d.ts +0 -55
- package/dist/index-D48jVS-N.d.ts +0 -246
- package/dist/index-DQh4VCc9.d.ts +0 -98
- package/dist/index-DunNRdnT.d.ts +0 -300
- package/dist/json-schema-CvER4kgT.js +0 -502
- package/dist/keys-4MnkWTTh.js +0 -35
- package/dist/kit-CkNzZUqv.d.ts +0 -60
- package/dist/kit-Fm-Fv7q5.js +0 -78
- package/dist/knowledge-BXBbT0Tr.d.ts +0 -176
- package/dist/knowledge-CDmiMLew.js +0 -255
- package/dist/list-query-BRt-zDF7.d.ts +0 -164
- package/dist/list-query-gl808ac1.js +0 -459
- package/dist/live-CTAZQkwl.js +0 -257
- package/dist/message-CaKlqdsX.js +0 -219
- package/dist/message-CfDoR0Y6.d.ts +0 -94
- package/dist/messages-B9-5887d.js +0 -715
- package/dist/messages-DYP0sUTe.d.ts +0 -59
- package/dist/mfa-Daak8ukG.d.ts +0 -54
- package/dist/modules-DpPwzC7E.d.ts +0 -192
- package/dist/modules-dxrVK3ID.js +0 -228
- package/dist/onboarding-BZGHYJks.d.ts +0 -62
- package/dist/outbox-Cq7pPYvl.d.ts +0 -161
- package/dist/path-Cv__-OTj.d.ts +0 -17
- package/dist/plugin-FGY8UhYm.d.ts +0 -151
- package/dist/pool-CAu2nLrL.d.ts +0 -89
- package/dist/postgrest-BLVdEnfe.d.ts +0 -53
- package/dist/problem-BreOl8b8.js +0 -115
- package/dist/problem-DD8LZFjc.d.ts +0 -67
- package/dist/provider-D-UEMvSD.d.ts +0 -113
- package/dist/provider-Di3sRutW.js +0 -57
- package/dist/query-BQ-NaZon.js +0 -303
- package/dist/queue-CLJurhdy.d.ts +0 -427
- package/dist/react-F80mF4-t.js +0 -409
- package/dist/react-topic-seAWjL3_.js +0 -38
- package/dist/read-set-DuKWC9Mj.js +0 -314
- package/dist/refusal-CeJWxmkH.js +0 -61
- package/dist/refusal-DhSU2Vvr.d.ts +0 -15
- package/dist/replicas-CwrYp5Zj.js +0 -94
- package/dist/resolve-ChTYeTEl.d.ts +0 -169
- package/dist/resolve-tJZY3FEa.js +0 -697
- package/dist/resource-BsvzCMlX.js +0 -212
- package/dist/resource-IPS5xi9q.d.ts +0 -74
- package/dist/respond-BUgsXNgk.js +0 -91
- package/dist/respond-DprrgyXX.d.ts +0 -93
- package/dist/result-D7y2fT87.d.ts +0 -282
- package/dist/result-DzUbqgdW.js +0 -128
- package/dist/scope-CDHcS7dE.js +0 -90
- package/dist/search-CUWCRYKL.js +0 -9
- package/dist/server-Bh0EVSwU.d.ts +0 -558
- package/dist/session-ChiXDZdZ.d.ts +0 -72
- package/dist/shared-CBxosKK3.js +0 -75
- package/dist/shared-CxWmcyqB.js +0 -73
- package/dist/sign-in-Cb1mwv6X.js +0 -86
- package/dist/signers-4y62_VIi.d.ts +0 -166
- package/dist/spec-pins--j6mTok4.js +0 -27
- package/dist/spec-pins-C89s6DyW.d.ts +0 -27
- package/dist/standard-BK0cqJ7y.js +0 -25
- package/dist/standard-CYsm7xpT.d.ts +0 -7
- package/dist/stats-D_AD9GGu.js +0 -1123
- package/dist/store-CGjgWu5n.d.ts +0 -68
- package/dist/stripe-BMj5LtsT.js +0 -38
- package/dist/stripe-D04h-QBT.d.ts +0 -136
- package/dist/support-ig_K4PvS.js +0 -314
- package/dist/support-view-CVOJJLpc.d.ts +0 -17
- package/dist/tags-Cx-LnIQP.d.ts +0 -30
- package/dist/tee-CoEppCER.js +0 -101
- package/dist/template--jDkl3UP.js +0 -114
- package/dist/template-CwO38Do8.d.ts +0 -6
- package/dist/temporal-BJGitm-h.js +0 -79
- package/dist/temporal-required-BVvW7SYJ.js +0 -20
- package/dist/tenant-BxNFk9bx.d.ts +0 -17
- package/dist/tenant-I1TEZ_BX.js +0 -27
- package/dist/timing-CyTQPubY.js +0 -92
- package/dist/types-6BdhkmZe.d.ts +0 -340
- package/dist/types-6cYK9pbJ.js +0 -29
- package/dist/types-6rocye-y.d.ts +0 -156
- package/dist/types-AYOvcyep.d.ts +0 -359
- package/dist/types-C05bxW-W.d.ts +0 -220
- package/dist/types-DGs5L0VN.d.ts +0 -192
- package/dist/usage-CrvrL2vw.d.ts +0 -177
- package/dist/vault-wlbBhqm7.d.ts +0 -50
- package/dist/verify-DL41hbvY.js +0 -232
- package/dist/verify-DPuWngD4.d.ts +0 -172
- package/dist/version-C6OfRAIn.js +0 -4
- package/dist/view-BeFcRV6G.js +0 -99
- package/dist/view-CF7ihnkg.d.ts +0 -87
- package/dist/watch-DI34G86j.d.ts +0 -60
- package/dist/watch-Xuxrvxq-.js +0 -122
- package/dist/wire-DtZQ4sdE.js +0 -45
- package/dist/workflow-builder-DJ1oHn8g.js +0 -398
- package/dist/workflow-sdk-B3yLD6Br.d.ts +0 -98
- package/dist/workflow-sdk-C2WJ_G2O.js +0 -173
- package/dist/workflow-sdk-world-D-prir6O.js +0 -1397
- package/dist/workflows-B0j9WKPu.d.ts +0 -185
- package/dist/workflows-wu1WWBn7.js +0 -216
|
@@ -0,0 +1,1984 @@
|
|
|
1
|
+
import { c as mapDbError, n as dbError, o as isDbError, r as dbErrorOf } from "./errors-8i6tSICm.js";
|
|
2
|
+
import { t as temporal } from "./temporal-required-DqRzr7i0.js";
|
|
3
|
+
import { a as ok, r as err, s as toDbError, t as AsyncResult } from "./result-BlgnMB0H.js";
|
|
4
|
+
import { n as isRecord } from "./guards-6F2bCtQR.js";
|
|
5
|
+
import { a as postgrestExecutor, n as StatsRecorder } from "./stats-D6vkb89f.js";
|
|
6
|
+
import { o as problemResponse } from "./problem-pIiL3WbE.js";
|
|
7
|
+
import { loadEnv } from "./env/index.js";
|
|
8
|
+
import { i as userContext, t as actClaim } from "./impersonation-CDeCzZP6.js";
|
|
9
|
+
import { t as fromPgError } from "./pg-error-BV_X8Isq.js";
|
|
10
|
+
import { i as forwardBlockEvents, t as DEFAULT_TYPE_PREFIX } from "./cloud-event-CTh9Sr5w.js";
|
|
11
|
+
import { a as replicaState, i as primaryCookieWrite, o as routedExecutor, r as pinnedUntil, s as withPrimaryPin } from "./replicas-BvIL4_jL.js";
|
|
12
|
+
import { t as authContext } from "./context-BDDgjoxz.js";
|
|
13
|
+
import { a as narrowCap, i as delegatedClaims, r as contextClaims } from "./delegation-Dt8hMJWu.js";
|
|
14
|
+
import { d as parseCookies, h as sessionCookieName, m as serializeCookie, n as prefetchJwks, r as resolveAuth, s as AUTH_CACHE_HEADERS, u as clearSessionAtScopes } from "./resolve-CAR9oaKW.js";
|
|
15
|
+
import { t as credentialProviderOf } from "./provider-DKh2xFZb.js";
|
|
16
|
+
import { a as respond, n as defaultPrefetchJwks, r as guard, t as defaultExpose } from "./respond-DdhZ9Wbn.js";
|
|
17
|
+
import { createClient } from "@supabase/supabase-js";
|
|
18
|
+
import { defineMiddleware, getEnv, pipeline, seedContext } from "@supabase/middleware";
|
|
19
|
+
import { PostgrestClient } from "@supabase/postgrest-js";
|
|
20
|
+
//#region src/server/delete-account.ts
|
|
21
|
+
const REMOVE_BATCH = 1e3;
|
|
22
|
+
/** Maps an `AuthApiError` from `auth.admin.deleteUser` to a `DbError`. */
|
|
23
|
+
function fromAuthError(raw) {
|
|
24
|
+
if (isDbError(raw)) return raw;
|
|
25
|
+
const failure = typeof raw === "object" && raw !== null ? raw : {};
|
|
26
|
+
const message = failure.message ?? "Auth request failed";
|
|
27
|
+
const base = {
|
|
28
|
+
table: "auth.users",
|
|
29
|
+
...failure.code ? { code: failure.code } : {}
|
|
30
|
+
};
|
|
31
|
+
if (failure.code === "user_not_found" || failure.status === 404) return dbError("not_found", message, base);
|
|
32
|
+
if (/database error deleting user/i.test(message)) return dbError("conflict", message, {
|
|
33
|
+
...base,
|
|
34
|
+
hint: "A foreign key to auth.users without on delete cascade or set null blocks the delete (doctor BS406)"
|
|
35
|
+
});
|
|
36
|
+
if (failure.status === 401) return dbError("unauthorized", message, base);
|
|
37
|
+
if (failure.status === 403) return dbError("forbidden", message, base);
|
|
38
|
+
return failure.name === "AuthRetryableFetchError" || (failure.status ?? 0) >= 500 ? dbError("network", message, base) : dbError("unexpected", message, base);
|
|
39
|
+
}
|
|
40
|
+
const UUID$2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
41
|
+
const PROBE = "better_supabase.delete_account_probe";
|
|
42
|
+
/**
|
|
43
|
+
* The database error that refuses deleting `userId`, from the delete and its
|
|
44
|
+
* deferred checks run in a `do` block that always fails, so nothing is
|
|
45
|
+
* deleted. Undefined when the delete itself would pass.
|
|
46
|
+
*/
|
|
47
|
+
async function databaseRefusal(sql, userId) {
|
|
48
|
+
if (!UUID$2.test(userId)) return;
|
|
49
|
+
try {
|
|
50
|
+
await sql.queryRaw(`do $$
|
|
51
|
+
begin
|
|
52
|
+
delete from auth.users where id = '${userId}';
|
|
53
|
+
set constraints all immediate;
|
|
54
|
+
raise exception '${PROBE}';
|
|
55
|
+
end;
|
|
56
|
+
$$`);
|
|
57
|
+
} catch (cause) {
|
|
58
|
+
const raw = isDbError(cause) ? void 0 : fromPgError(cause);
|
|
59
|
+
const error = isDbError(cause) ? cause : raw && mapDbError(raw);
|
|
60
|
+
if (!error || error.message === PROBE) return;
|
|
61
|
+
return {
|
|
62
|
+
...error,
|
|
63
|
+
table: "auth.users"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Deletes the Auth user, then removes their Storage objects, then announces
|
|
69
|
+
* the delete. Rows referencing `auth.users` follow their foreign keys. The
|
|
70
|
+
* objects are listed first and removed only once the user is gone, so a
|
|
71
|
+
* delete the database refuses leaves them in place.
|
|
72
|
+
*
|
|
73
|
+
* `server.deleteAccount` calls it with the server's service client. Apps on
|
|
74
|
+
* the `@supabase/server` pipeline call it with theirs:
|
|
75
|
+
* `deleteAccount(betterSupabase, ctx.supabaseAdmin, userId)`.
|
|
76
|
+
*/
|
|
77
|
+
function deleteAccount(betterSupabase, service, userId, options = {}) {
|
|
78
|
+
return AsyncResult.from(async () => {
|
|
79
|
+
const client = typeof service === "function" ? service() : service;
|
|
80
|
+
const listedPaths = [];
|
|
81
|
+
for (const bucket of options.buckets ?? []) {
|
|
82
|
+
const param = bucket.owner;
|
|
83
|
+
if (!param) continue;
|
|
84
|
+
options.signal?.throwIfAborted();
|
|
85
|
+
const listed = await bucket.connect(client, { allTenants: true }).list({ [param]: userId }, options.signal ? { signal: options.signal } : {});
|
|
86
|
+
if (!listed.ok) return listed;
|
|
87
|
+
listedPaths.push([bucket, listed.data.map((object) => object.path).filter((path) => {
|
|
88
|
+
return bucket.match(path)?.[param] === userId;
|
|
89
|
+
})]);
|
|
90
|
+
}
|
|
91
|
+
options.signal?.throwIfAborted();
|
|
92
|
+
let alreadyGone = false;
|
|
93
|
+
try {
|
|
94
|
+
const { error } = await client.auth.admin.deleteUser(userId);
|
|
95
|
+
const failure = error ? fromAuthError(error) : void 0;
|
|
96
|
+
if (failure?.kind === "not_found") alreadyGone = true;
|
|
97
|
+
else if (failure) {
|
|
98
|
+
const refusal = options.sql && (failure.kind === "conflict" || failure.kind === "network" || failure.kind === "unexpected") ? await databaseRefusal(options.sql, userId) : void 0;
|
|
99
|
+
return err(refusal ?? failure);
|
|
100
|
+
}
|
|
101
|
+
} catch (cause) {
|
|
102
|
+
return err(fromAuthError(cause));
|
|
103
|
+
}
|
|
104
|
+
const removed = {};
|
|
105
|
+
for (const [bucket, paths] of listedPaths) {
|
|
106
|
+
const storage = bucket.connect(client, { allTenants: true });
|
|
107
|
+
for (let start = 0; start < paths.length; start += REMOVE_BATCH) {
|
|
108
|
+
const batch = await storage.remove(paths.slice(start, start + REMOVE_BATCH));
|
|
109
|
+
if (!batch.ok) return batch;
|
|
110
|
+
}
|
|
111
|
+
removed[bucket.id] = paths.length;
|
|
112
|
+
}
|
|
113
|
+
if (alreadyGone) return ok({
|
|
114
|
+
userId,
|
|
115
|
+
removed
|
|
116
|
+
});
|
|
117
|
+
const context = options.context ?? {};
|
|
118
|
+
betterSupabase.events.emit("mutation", {
|
|
119
|
+
table: "auth.users",
|
|
120
|
+
kind: "delete",
|
|
121
|
+
rows: [{ id: userId }],
|
|
122
|
+
context
|
|
123
|
+
});
|
|
124
|
+
for (const table of options.cascades ?? []) betterSupabase.events.emit("mutation", {
|
|
125
|
+
table,
|
|
126
|
+
kind: "delete",
|
|
127
|
+
rows: [],
|
|
128
|
+
context
|
|
129
|
+
});
|
|
130
|
+
return ok({
|
|
131
|
+
userId,
|
|
132
|
+
removed
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/server/suspend-account.ts
|
|
138
|
+
const UUID$1 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
139
|
+
const FOREVER = "876000h";
|
|
140
|
+
const END_SESSIONS = `with ended as (
|
|
141
|
+
delete from auth.sessions where user_id = $1::uuid returning id
|
|
142
|
+
), tokens as (
|
|
143
|
+
delete from auth.refresh_tokens where user_id = $1::text
|
|
144
|
+
)
|
|
145
|
+
select count(*)::int as ended from ended`;
|
|
146
|
+
function invalidUser(userId) {
|
|
147
|
+
return dbError("invalid_request", `"${userId}" is not a user id`, { table: "auth.users" });
|
|
148
|
+
}
|
|
149
|
+
function fromSqlError(cause) {
|
|
150
|
+
const known = dbErrorOf(cause);
|
|
151
|
+
if (known) return known;
|
|
152
|
+
const raw = fromPgError(cause);
|
|
153
|
+
if (raw) return {
|
|
154
|
+
...mapDbError(raw),
|
|
155
|
+
table: "auth.sessions"
|
|
156
|
+
};
|
|
157
|
+
return dbError("unexpected", cause instanceof Error ? cause.message : "Ending the sessions failed", { table: "auth.sessions" });
|
|
158
|
+
}
|
|
159
|
+
async function deleteSessions(sql, userId) {
|
|
160
|
+
const [row] = await sql.queryRaw(END_SESSIONS, [userId]);
|
|
161
|
+
return row?.ended ?? 0;
|
|
162
|
+
}
|
|
163
|
+
function endSessions(sql, userId) {
|
|
164
|
+
return AsyncResult.from(async () => {
|
|
165
|
+
if (!UUID$1.test(userId)) return err(invalidUser(userId));
|
|
166
|
+
try {
|
|
167
|
+
return ok({
|
|
168
|
+
userId,
|
|
169
|
+
ended: await deleteSessions(sql, userId)
|
|
170
|
+
});
|
|
171
|
+
} catch (cause) {
|
|
172
|
+
return err(fromSqlError(cause));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const LAST_SIGN_INS = `select user_id, last_sign_in_at
|
|
177
|
+
from better_supabase.last_sign_ins($1::uuid[])`;
|
|
178
|
+
/**
|
|
179
|
+
* The last sign-in of each user, in one query (`better_supabase.last_sign_ins`
|
|
180
|
+
* from the `sessions` module, which only the service role may call). Users
|
|
181
|
+
* that don't exist are missing from the map.
|
|
182
|
+
*/
|
|
183
|
+
function lastSignIns(sql, userIds) {
|
|
184
|
+
return AsyncResult.from(async () => {
|
|
185
|
+
const invalid = userIds.find((userId) => !UUID$1.test(userId));
|
|
186
|
+
if (invalid !== void 0) return err(invalidUser(invalid));
|
|
187
|
+
if (userIds.length === 0) return ok(/* @__PURE__ */ new Map());
|
|
188
|
+
try {
|
|
189
|
+
const rows = await sql.queryRaw(LAST_SIGN_INS, [[...new Set(userIds)]]);
|
|
190
|
+
return ok(new Map(rows.map((row) => [row.user_id, {
|
|
191
|
+
userId: row.user_id,
|
|
192
|
+
lastSignInAt: row.last_sign_in_at === null ? null : temporal().Instant.from(row.last_sign_in_at instanceof Date ? row.last_sign_in_at.toISOString() : row.last_sign_in_at)
|
|
193
|
+
}])));
|
|
194
|
+
} catch (cause) {
|
|
195
|
+
return err(fromSqlError(cause));
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async function ban(client, userId, duration) {
|
|
200
|
+
try {
|
|
201
|
+
const { error } = await client.auth.admin.updateUserById(userId, { ban_duration: duration });
|
|
202
|
+
return error ? fromAuthError(error) : void 0;
|
|
203
|
+
} catch (cause) {
|
|
204
|
+
return fromAuthError(cause);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function suspendAccount(service, sql, userId, options) {
|
|
208
|
+
return AsyncResult.from(async () => {
|
|
209
|
+
if (!UUID$1.test(userId)) return err(invalidUser(userId));
|
|
210
|
+
const client = typeof service === "function" ? service() : service;
|
|
211
|
+
const { suspended } = options;
|
|
212
|
+
if (suspended) {
|
|
213
|
+
const refused = await ban(client, userId, options.duration ?? FOREVER);
|
|
214
|
+
if (refused) return err(refused);
|
|
215
|
+
if (options.endSessions !== true) return ok({
|
|
216
|
+
userId,
|
|
217
|
+
suspended,
|
|
218
|
+
ended: 0
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
let ended;
|
|
222
|
+
try {
|
|
223
|
+
ended = await deleteSessions(sql, userId);
|
|
224
|
+
} catch (cause) {
|
|
225
|
+
return err(fromSqlError(cause));
|
|
226
|
+
}
|
|
227
|
+
if (!suspended) {
|
|
228
|
+
const refused = await ban(client, userId, "none");
|
|
229
|
+
if (refused) return err(refused);
|
|
230
|
+
}
|
|
231
|
+
return ok({
|
|
232
|
+
userId,
|
|
233
|
+
suspended,
|
|
234
|
+
ended
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/server/audit.ts
|
|
240
|
+
/** The CloudEvents `source` of the events the server sends to its `audit` sink. */
|
|
241
|
+
const SERVER_EVENT_SOURCE = "/better-supabase/server";
|
|
242
|
+
const OFF = { account: () => void 0 };
|
|
243
|
+
/**
|
|
244
|
+
* The server's audit trail: account actions are sent to `sink` as CloudEvents
|
|
245
|
+
* typed `dev.better-supabase.account.*` with subject `users/<id>`, and
|
|
246
|
+
* `support.denied` block events are forwarded to it.
|
|
247
|
+
*/
|
|
248
|
+
function serverAudit(betterSupabase, sink) {
|
|
249
|
+
if (sink === void 0) return OFF;
|
|
250
|
+
const { events } = betterSupabase;
|
|
251
|
+
forwardBlockEvents(betterSupabase, sink, {
|
|
252
|
+
source: SERVER_EVENT_SOURCE,
|
|
253
|
+
types: ["support.denied"]
|
|
254
|
+
});
|
|
255
|
+
const report = (cause) => {
|
|
256
|
+
events.logger.error("audit sink failed", { cause });
|
|
257
|
+
};
|
|
258
|
+
return { account(type, userId, data) {
|
|
259
|
+
const event = {
|
|
260
|
+
specversion: "1.0",
|
|
261
|
+
id: crypto.randomUUID(),
|
|
262
|
+
source: SERVER_EVENT_SOURCE,
|
|
263
|
+
type: `${DEFAULT_TYPE_PREFIX}.${type}`,
|
|
264
|
+
subject: `users/${userId}`,
|
|
265
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
266
|
+
datacontenttype: "application/json",
|
|
267
|
+
data: {
|
|
268
|
+
userId,
|
|
269
|
+
...data
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
try {
|
|
273
|
+
events.track(Promise.resolve(sink.send([event])).catch(report));
|
|
274
|
+
} catch (cause) {
|
|
275
|
+
report(cause);
|
|
276
|
+
}
|
|
277
|
+
} };
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/core/contracts/authorization-hooks.ts
|
|
281
|
+
/** Types `hooks` and freezes it; better-supabase never mutates a provider. */
|
|
282
|
+
function defineAuthorizationHooks(hooks) {
|
|
283
|
+
return Object.freeze(hooks);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The error for hooks built for another API version, or `undefined` for
|
|
287
|
+
* version 1.
|
|
288
|
+
*/
|
|
289
|
+
function hooksApiProblem(hooks) {
|
|
290
|
+
if (hooks.apiVersion === 1) return;
|
|
291
|
+
return `authorization hooks "${typeof hooks.name === "string" ? hooks.name : "provider"}" target API ${String(hooks.apiVersion)}; this better-supabase supports 1.`;
|
|
292
|
+
}
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/server/clients.ts
|
|
295
|
+
const STATELESS = {
|
|
296
|
+
persistSession: false,
|
|
297
|
+
autoRefreshToken: false,
|
|
298
|
+
detectSessionInUrl: false
|
|
299
|
+
};
|
|
300
|
+
/** The Supabase and PostgREST clients of one server: shared service and anon clients, per-request user clients. */
|
|
301
|
+
function createClients(input) {
|
|
302
|
+
const { options, env, definitionExecutor, lite, createClient } = input;
|
|
303
|
+
let adminClient;
|
|
304
|
+
let anonClient;
|
|
305
|
+
const secretKey = () => {
|
|
306
|
+
const key = env().secretKey;
|
|
307
|
+
if (!key) throw new TypeError("admin() needs SUPABASE_SECRET_KEY; it is not set");
|
|
308
|
+
return key;
|
|
309
|
+
};
|
|
310
|
+
const customFetch = options.fetch ? { fetch: options.fetch } : void 0;
|
|
311
|
+
const urlLengthLimit = options.db?.urlLengthLimit ?? definitionExecutor.urlLengthLimit;
|
|
312
|
+
const db = {
|
|
313
|
+
...options.db?.timeout === void 0 ? {} : { timeout: options.db.timeout },
|
|
314
|
+
...options.db?.retry === void 0 ? {} : { retry: options.db.retry },
|
|
315
|
+
...urlLengthLimit === void 0 ? {} : { urlLengthLimit }
|
|
316
|
+
};
|
|
317
|
+
const dbOptions = Object.keys(db).length > 0 ? { db } : {};
|
|
318
|
+
const sharedGlobal = {
|
|
319
|
+
...customFetch ? { global: customFetch } : {},
|
|
320
|
+
...dbOptions
|
|
321
|
+
};
|
|
322
|
+
/** postgrest-js options a bare `PostgrestClient` takes; `timeout` is the executor's. */
|
|
323
|
+
const restOptions = {
|
|
324
|
+
...db.retry === void 0 ? {} : { retry: db.retry },
|
|
325
|
+
...urlLengthLimit === void 0 ? {} : { urlLengthLimit }
|
|
326
|
+
};
|
|
327
|
+
const rpcUnavailable = lite?.rpcUnavailable;
|
|
328
|
+
const executorOptions = {
|
|
329
|
+
...definitionExecutor,
|
|
330
|
+
...urlLengthLimit === void 0 ? {} : { urlLengthLimit },
|
|
331
|
+
...db.timeout === void 0 ? {} : { timeout: db.timeout },
|
|
332
|
+
...db.retry === void 0 ? {} : { retry: db.retry },
|
|
333
|
+
...rpcUnavailable === void 0 ? {} : { rpcUnavailable }
|
|
334
|
+
};
|
|
335
|
+
/** Set when `db` options or the backend need an executor built with them. */
|
|
336
|
+
const tunedExecutor = options.db !== void 0 || rpcUnavailable !== void 0;
|
|
337
|
+
const serviceClient = () => {
|
|
338
|
+
adminClient ??= createClient(env().url, secretKey(), {
|
|
339
|
+
auth: STATELESS,
|
|
340
|
+
...sharedGlobal
|
|
341
|
+
});
|
|
342
|
+
return adminClient;
|
|
343
|
+
};
|
|
344
|
+
const readUrl = () => options.readUrl === false ? void 0 : options.readUrl?.replace(/\/+$/, "") ?? env().readUrl;
|
|
345
|
+
const apiKeyClient = () => {
|
|
346
|
+
throw new TypeError("ctx.supabase and ctx.db.$client are not available for an API key: ctx.db and ctx.sql run over direct Postgres with the key's claims");
|
|
347
|
+
};
|
|
348
|
+
/** Clients for the primary share the service and anon clients; others don't. */
|
|
349
|
+
const supabaseAt = (url, auth, headers = {}) => {
|
|
350
|
+
const custom = Object.keys(headers).length > 0;
|
|
351
|
+
const global = custom ? {
|
|
352
|
+
global: {
|
|
353
|
+
headers,
|
|
354
|
+
...customFetch
|
|
355
|
+
},
|
|
356
|
+
...dbOptions
|
|
357
|
+
} : sharedGlobal;
|
|
358
|
+
const shared = !custom && url === env().url;
|
|
359
|
+
switch (auth.kind) {
|
|
360
|
+
case "user": return createClient(url, env().publishableKey, {
|
|
361
|
+
accessToken: () => Promise.resolve(auth.token),
|
|
362
|
+
...global
|
|
363
|
+
});
|
|
364
|
+
case "service": return shared ? serviceClient() : createClient(url, secretKey(), {
|
|
365
|
+
auth: STATELESS,
|
|
366
|
+
...global
|
|
367
|
+
});
|
|
368
|
+
case "anon":
|
|
369
|
+
case "invalid":
|
|
370
|
+
if (!shared) return createClient(url, env().publishableKey, {
|
|
371
|
+
auth: STATELESS,
|
|
372
|
+
...global
|
|
373
|
+
});
|
|
374
|
+
anonClient ??= createClient(url, env().publishableKey, {
|
|
375
|
+
auth: STATELESS,
|
|
376
|
+
...sharedGlobal
|
|
377
|
+
});
|
|
378
|
+
return anonClient;
|
|
379
|
+
case "apiKey": return apiKeyClient();
|
|
380
|
+
default: return auth;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const supabaseFor = (auth, headers = {}) => supabaseAt(env().url, auth, headers);
|
|
384
|
+
const restUrls = /* @__PURE__ */ new Map();
|
|
385
|
+
const restUrl = (url) => {
|
|
386
|
+
let rest = restUrls.get(url);
|
|
387
|
+
if (rest === void 0) {
|
|
388
|
+
rest = new URL("rest/v1", url.endsWith("/") ? url : `${url}/`).href;
|
|
389
|
+
restUrls.set(url, rest);
|
|
390
|
+
}
|
|
391
|
+
return rest;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* The client queries run on. Requests need only PostgREST, so they skip
|
|
395
|
+
* building Realtime, Storage and Auth clients per request; the shared
|
|
396
|
+
* service and anon clients for the primary are built once anyway.
|
|
397
|
+
*/
|
|
398
|
+
const restAt = (url, auth, headers = {}) => {
|
|
399
|
+
let key;
|
|
400
|
+
let bearer;
|
|
401
|
+
switch (auth.kind) {
|
|
402
|
+
case "user":
|
|
403
|
+
key = env().publishableKey;
|
|
404
|
+
bearer = auth.token;
|
|
405
|
+
break;
|
|
406
|
+
case "service":
|
|
407
|
+
case "anon":
|
|
408
|
+
case "invalid":
|
|
409
|
+
if (Object.keys(headers).length === 0 && url === env().url) return supabaseAt(url, auth, headers);
|
|
410
|
+
key = auth.kind === "service" ? secretKey() : env().publishableKey;
|
|
411
|
+
bearer = key;
|
|
412
|
+
break;
|
|
413
|
+
case "apiKey": return apiKeyClient();
|
|
414
|
+
default: return auth;
|
|
415
|
+
}
|
|
416
|
+
return new PostgrestClient(restUrl(url), {
|
|
417
|
+
headers: {
|
|
418
|
+
...headers,
|
|
419
|
+
apikey: key,
|
|
420
|
+
Authorization: `Bearer ${bearer}`
|
|
421
|
+
},
|
|
422
|
+
...customFetch,
|
|
423
|
+
...restOptions
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
return {
|
|
427
|
+
executorOptions,
|
|
428
|
+
tunedExecutor,
|
|
429
|
+
serviceClient,
|
|
430
|
+
readUrl,
|
|
431
|
+
apiKeyClient,
|
|
432
|
+
supabaseFor,
|
|
433
|
+
restAt
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/server/entries/core.ts
|
|
438
|
+
const cores = /* @__PURE__ */ new WeakMap();
|
|
439
|
+
/** Records the core behind `server`, so `serverCore` finds it on copies too. */
|
|
440
|
+
function registerCore(server, core) {
|
|
441
|
+
cores.set(server, core);
|
|
442
|
+
}
|
|
443
|
+
/** Copies the registration from `from` to `to` (`extendServer` builds a new object). */
|
|
444
|
+
function shareCore(from, to) {
|
|
445
|
+
const core = cores.get(from);
|
|
446
|
+
if (core) cores.set(to, core);
|
|
447
|
+
}
|
|
448
|
+
/** The core of a server built by `createServer` or one of the adapter factories. */
|
|
449
|
+
function serverCore(server) {
|
|
450
|
+
const core = cores.get(server);
|
|
451
|
+
if (!core) throw new TypeError("better-supabase: this server was not built by createServer(); pass the definition or a server from createServer");
|
|
452
|
+
return core;
|
|
453
|
+
}
|
|
454
|
+
const CALL = Symbol("better-supabase.call");
|
|
455
|
+
const supportLookups = /* @__PURE__ */ new WeakMap();
|
|
456
|
+
/**
|
|
457
|
+
* Starts the support lookup for a signed-in caller, so `withTenant` can run
|
|
458
|
+
* the tenant resolver while the support store answers. Other callers never
|
|
459
|
+
* have a support session, so they skip it.
|
|
460
|
+
*/
|
|
461
|
+
function startSupportLookup(core, request, session) {
|
|
462
|
+
if (session.auth.kind !== "user" || supportLookups.has(session)) return;
|
|
463
|
+
const lookup = core.support(request, session.auth);
|
|
464
|
+
lookup.catch(() => void 0);
|
|
465
|
+
supportLookups.set(session, lookup);
|
|
466
|
+
}
|
|
467
|
+
/** The support session of a resolved request: the started lookup, else a new one. */
|
|
468
|
+
function supportLookup(core, request, session) {
|
|
469
|
+
return supportLookups.get(session) ?? core.support(request, session.auth);
|
|
470
|
+
}
|
|
471
|
+
/** The call state on a context seeded by `server.context()`, if any. */
|
|
472
|
+
function callOf(ctx) {
|
|
473
|
+
return ctx[CALL];
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/server/entries/context.ts
|
|
477
|
+
/**
|
|
478
|
+
* Entry contributing `ctx.bs`, the request's `ServerContext`: `auth`, `db`,
|
|
479
|
+
* `sql`, `supabase`, `replica`, `stats()` and the rest, each built on first
|
|
480
|
+
* read. In a support session `auth`, `db` and `sql` are the target's.
|
|
481
|
+
*/
|
|
482
|
+
function withServerContext(core) {
|
|
483
|
+
return defineMiddleware({
|
|
484
|
+
key: "bs",
|
|
485
|
+
run: () => (request, ctx) => {
|
|
486
|
+
const options = callOf(ctx)?.options ?? {};
|
|
487
|
+
const bs = core.context(ctx.session, request, ctx.support ? {
|
|
488
|
+
...options,
|
|
489
|
+
support: ctx.support
|
|
490
|
+
} : options, ctx.tenant);
|
|
491
|
+
return Promise.resolve({ bs });
|
|
492
|
+
}
|
|
493
|
+
})();
|
|
494
|
+
}
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/server/refresh.ts
|
|
497
|
+
/** A router or browser prefetch, by its request headers. */
|
|
498
|
+
function isPrefetch(request) {
|
|
499
|
+
const h = request.headers;
|
|
500
|
+
return h.has("next-router-prefetch") || h.get("purpose") === "prefetch" || (h.get("sec-purpose")?.includes("prefetch") ?? false);
|
|
501
|
+
}
|
|
502
|
+
const FORM_TYPES = ["application/x-www-form-urlencoded", "multipart/form-data"];
|
|
503
|
+
/**
|
|
504
|
+
* Whether a request should refresh an expired session cookie: page loads,
|
|
505
|
+
* client navigations (`rsc`, `x-sveltekit-*`, `_data` loaders), form posts
|
|
506
|
+
* and Server Actions. Prefetches, assets and `fetch` calls from scripts
|
|
507
|
+
* read the session as it is, so a burst of parallel requests never races
|
|
508
|
+
* on the single-use refresh token.
|
|
509
|
+
*/
|
|
510
|
+
function shouldRefresh(request) {
|
|
511
|
+
const h = request.headers;
|
|
512
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
513
|
+
if (h.has("next-action") || h.has("x-sveltekit-action")) return true;
|
|
514
|
+
if (h.get("sec-fetch-dest") === "document") return true;
|
|
515
|
+
const type = h.get("content-type") ?? "";
|
|
516
|
+
return FORM_TYPES.some((form) => type.startsWith(form));
|
|
517
|
+
}
|
|
518
|
+
if (isPrefetch(request)) return false;
|
|
519
|
+
if (h.get("rsc") === "1") return true;
|
|
520
|
+
const dest = h.get("sec-fetch-dest");
|
|
521
|
+
if (dest) return dest === "document";
|
|
522
|
+
return h.get("accept")?.includes("text/html") ?? false;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Whether a request should ask the Auth server if the session still exists
|
|
526
|
+
* (`checkSession`): full page loads, and `paths` you list for client
|
|
527
|
+
* navigations. Never prefetches or mutations.
|
|
528
|
+
*/
|
|
529
|
+
function shouldCheckSession(request, paths) {
|
|
530
|
+
if (request.method !== "GET" && request.method !== "HEAD") return false;
|
|
531
|
+
if (isPrefetch(request)) return false;
|
|
532
|
+
if (request.headers.get("sec-fetch-dest") === "document") return true;
|
|
533
|
+
return paths?.includes(new URL(request.url).pathname) ?? false;
|
|
534
|
+
}
|
|
535
|
+
/** `policy` for one request. */
|
|
536
|
+
function refreshFor(policy, request) {
|
|
537
|
+
if (policy === void 0 || typeof policy === "boolean") return policy;
|
|
538
|
+
return policy === "navigation" ? shouldRefresh(request) : policy(request);
|
|
539
|
+
}
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/server/entries/session.ts
|
|
542
|
+
function checkFor(policy, request) {
|
|
543
|
+
if (policy === void 0 || typeof policy === "boolean") return policy ?? false;
|
|
544
|
+
return policy === "navigation" ? shouldCheckSession(request) : policy(request);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Runs `hook` for a resolution with an outage and returns its response when
|
|
548
|
+
* the session couldn't be kept.
|
|
549
|
+
*/
|
|
550
|
+
async function outageResponse(hook, resolution, request, logger) {
|
|
551
|
+
const outage = resolution.outage;
|
|
552
|
+
if (!hook || !outage) return;
|
|
553
|
+
try {
|
|
554
|
+
const response = await hook(outage, request);
|
|
555
|
+
return outage.kept || !(response instanceof Response) ? void 0 : response;
|
|
556
|
+
} catch (cause) {
|
|
557
|
+
logger.warn("onAuthOutage threw", { cause });
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/** Appends `Max-Age=0` writes for the session cookie at the old scopes, and the no-store headers. */
|
|
562
|
+
function clearOldScopes(response, request, name, scopes) {
|
|
563
|
+
const writes = clearSessionAtScopes(parseCookies(request.headers.get("cookie")), name, scopes);
|
|
564
|
+
if (writes.length === 0) return response;
|
|
565
|
+
const headers = new Headers(response.headers);
|
|
566
|
+
for (const write of writes) headers.append("set-cookie", serializeCookie(write));
|
|
567
|
+
for (const [key, value] of Object.entries(AUTH_CACHE_HEADERS)) headers.set(key, value);
|
|
568
|
+
return new Response(response.body, {
|
|
569
|
+
status: response.status,
|
|
570
|
+
statusText: response.statusText,
|
|
571
|
+
headers
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Entry contributing `ctx.session`, the request's `AuthResolution`: a bearer
|
|
576
|
+
* token first, the session cookie second. It is the only entry with a
|
|
577
|
+
* response seam for cookies: on the way out it adds the refreshed session
|
|
578
|
+
* cookies and the no-store headers, and hands pending event sends to
|
|
579
|
+
* `waitUntil`.
|
|
580
|
+
*/
|
|
581
|
+
function withSession(core, config = {}) {
|
|
582
|
+
return defineMiddleware({
|
|
583
|
+
key: "session",
|
|
584
|
+
run: () => async function* run(request, ctx) {
|
|
585
|
+
const call = callOf(ctx)?.options;
|
|
586
|
+
const refresh = call ? call.refresh ?? false : refreshFor(config.refresh, request);
|
|
587
|
+
const cookies = call ? call.cookies : config.cookies;
|
|
588
|
+
const checkSession = !call && checkFor(config.checkSession, request);
|
|
589
|
+
const session = await core.resolve(request, {
|
|
590
|
+
...refresh === void 0 ? {} : { refresh },
|
|
591
|
+
...cookies === void 0 ? {} : { cookies },
|
|
592
|
+
...checkSession ? { checkSession } : {},
|
|
593
|
+
...config.encode === void 0 ? {} : { encode: config.encode }
|
|
594
|
+
});
|
|
595
|
+
const outage = await outageResponse(config.onAuthOutage, session, request, core.events.logger);
|
|
596
|
+
if (outage) return session.apply(outage);
|
|
597
|
+
try {
|
|
598
|
+
const response = yield { session };
|
|
599
|
+
const applied = session.apply(response);
|
|
600
|
+
return config.cookieScopes?.length ? clearOldScopes(applied, request, core.sessionCookie(), config.cookieScopes) : applied;
|
|
601
|
+
} finally {
|
|
602
|
+
if (config.waitUntil && core.events.pending) config.waitUntil(core.events.settled());
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
})();
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/server/entries/support.ts
|
|
609
|
+
/**
|
|
610
|
+
* Entry contributing `ctx.support`: the support session ("view as user") the
|
|
611
|
+
* request's support cookie names, when `ServerOptions.support` is set and
|
|
612
|
+
* the caller is the admin who started it. `undefined` otherwise.
|
|
613
|
+
*/
|
|
614
|
+
function withSupport(core) {
|
|
615
|
+
return defineMiddleware({
|
|
616
|
+
key: "support",
|
|
617
|
+
run: () => async (request, ctx) => {
|
|
618
|
+
return { support: callOf(ctx)?.options.support ?? await supportLookup(core, request, ctx.session) };
|
|
619
|
+
}
|
|
620
|
+
})();
|
|
621
|
+
}
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/server/entries/tenant.ts
|
|
624
|
+
/**
|
|
625
|
+
* Entry contributing `ctx.tenant`: the active tenant from
|
|
626
|
+
* `ServerOptions.tenant` (a URL slug, a header), or `undefined`. It becomes
|
|
627
|
+
* `context.tenant` for the `tenant()` plugin, the `better_supabase.tenant`
|
|
628
|
+
* setting over Postgres and the `x-bs-tenant` header over PostgREST. It
|
|
629
|
+
* starts the support lookup that `withSupport` awaits, so both run at once.
|
|
630
|
+
*/
|
|
631
|
+
function withTenant(core) {
|
|
632
|
+
return defineMiddleware({
|
|
633
|
+
key: "tenant",
|
|
634
|
+
run: () => async (request, ctx) => {
|
|
635
|
+
const options = callOf(ctx)?.options;
|
|
636
|
+
if (options?.support === void 0) startSupportLookup(core, request, ctx.session);
|
|
637
|
+
return { tenant: options?.tenant ?? await core.tenant(request, ctx.session.auth) };
|
|
638
|
+
}
|
|
639
|
+
})();
|
|
640
|
+
}
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region src/server/lite.ts
|
|
643
|
+
/** Lite's default driver, the one `lite init` scaffolds. */
|
|
644
|
+
const DEFAULT_LITE_DRIVER = "sqlite-postgres";
|
|
645
|
+
/** Whether the driver stores data in SQLite, where Lite has no database functions. */
|
|
646
|
+
function isSqliteDriver(driver) {
|
|
647
|
+
switch (driver) {
|
|
648
|
+
case "sqlite-postgres":
|
|
649
|
+
case "sqlite": return true;
|
|
650
|
+
case "pglite":
|
|
651
|
+
case "postgres": return false;
|
|
652
|
+
default: return driver;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function liteRpcUnavailable(driver) {
|
|
656
|
+
return `rpc() is not available on Supabase Lite with the ${driver} driver. Set [db] driver = "pglite" or "postgres" in supabase/config.toml, or call an HTTP endpoint instead.`;
|
|
657
|
+
}
|
|
658
|
+
/** What `backend: "lite"` changes in `createServer`; `undefined` for Supabase. */
|
|
659
|
+
function liteBackend(options, env) {
|
|
660
|
+
if (options.backend !== "lite") return;
|
|
661
|
+
const driver = options.liteDriver ?? DEFAULT_LITE_DRIVER;
|
|
662
|
+
if (options.postgres && driver !== "postgres") throw new TypeError(`Supabase Lite with the ${driver} driver has no Postgres connection for ctx.sql. Remove the postgres option, or run Lite with [db] driver = "postgres".`);
|
|
663
|
+
return {
|
|
664
|
+
auth() {
|
|
665
|
+
if (options.auth?.jwtSecret !== void 0) return options.auth;
|
|
666
|
+
const jwtSecret = env().jwtSecret;
|
|
667
|
+
if (jwtSecret === void 0) throw new TypeError("backend: \"lite\" needs SUPABASE_JWT_SECRET, the auth.jwt_secret Supabase Lite signs user tokens with");
|
|
668
|
+
return {
|
|
669
|
+
...options.auth,
|
|
670
|
+
jwtSecret
|
|
671
|
+
};
|
|
672
|
+
},
|
|
673
|
+
rpcUnavailable: isSqliteDriver(driver) ? liteRpcUnavailable(driver) : void 0
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region src/server/refusing-executor.ts
|
|
678
|
+
/**
|
|
679
|
+
* An executor for credentials that did not verify: every query, function
|
|
680
|
+
* call and batch answers `error`, so a handler that skips the route guard
|
|
681
|
+
* gets a 401 `Result` and never queries as anon.
|
|
682
|
+
*/
|
|
683
|
+
function refusingExecutor(error) {
|
|
684
|
+
const refuse = () => err(error);
|
|
685
|
+
return {
|
|
686
|
+
name: "refused",
|
|
687
|
+
functionSources: true,
|
|
688
|
+
execute: () => Promise.resolve(refuse()),
|
|
689
|
+
rpc: () => Promise.resolve(refuse()),
|
|
690
|
+
batch: (ops) => Promise.resolve(ops.map(() => refuse()))
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
//#endregion
|
|
694
|
+
//#region src/server/request-ids.ts
|
|
695
|
+
const REQUEST_ID_PATTERN = /^[A-Za-z0-9._:;,@/+=-]{1,128}$/;
|
|
696
|
+
function requestIdOrUndefined(value) {
|
|
697
|
+
return typeof value === "string" && REQUEST_ID_PATTERN.test(value) ? value : void 0;
|
|
698
|
+
}
|
|
699
|
+
function sessionWith(ids, tenant, readOnly = false) {
|
|
700
|
+
const settings = {
|
|
701
|
+
...ids.requestId === void 0 ? {} : { "better_supabase.request_id": ids.requestId },
|
|
702
|
+
...ids.correlationId === void 0 ? {} : { "better_supabase.correlation_id": ids.correlationId },
|
|
703
|
+
...tenant === void 0 ? {} : { "better_supabase.tenant": tenant }
|
|
704
|
+
};
|
|
705
|
+
const hasSettings = Object.keys(settings).length > 0;
|
|
706
|
+
if (!hasSettings && !readOnly) return;
|
|
707
|
+
return {
|
|
708
|
+
...readOnly ? { readOnly: true } : {},
|
|
709
|
+
...hasSettings ? { settings } : {}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function requestIdPolicy(options = {}) {
|
|
713
|
+
const on = options !== false;
|
|
714
|
+
const settings = on ? options : {};
|
|
715
|
+
const requestHeader = (settings.requestHeader ?? "x-request-id").toLowerCase();
|
|
716
|
+
const correlationHeader = (settings.correlationHeader ?? "x-correlation-id").toLowerCase();
|
|
717
|
+
const incoming = on && (settings.incoming ?? true);
|
|
718
|
+
const generate = on && (settings.generate ?? true);
|
|
719
|
+
const generated = /* @__PURE__ */ new WeakMap();
|
|
720
|
+
const fromHeader = (request, name) => incoming && request ? requestIdOrUndefined(request.headers.get(name)) : void 0;
|
|
721
|
+
const generatedFor = (request) => {
|
|
722
|
+
if (!generate || !request) return;
|
|
723
|
+
const known = generated.get(request);
|
|
724
|
+
if (known !== void 0) return known;
|
|
725
|
+
const id = crypto.randomUUID();
|
|
726
|
+
generated.set(request, id);
|
|
727
|
+
return id;
|
|
728
|
+
};
|
|
729
|
+
return {
|
|
730
|
+
forRequest(request, explicit) {
|
|
731
|
+
const requestId = requestIdOrUndefined(explicit.requestId) ?? fromHeader(request, requestHeader) ?? generatedFor(request);
|
|
732
|
+
const correlationId = requestIdOrUndefined(explicit.correlationId) ?? fromHeader(request, correlationHeader) ?? requestId;
|
|
733
|
+
return {
|
|
734
|
+
...requestId === void 0 ? {} : { requestId },
|
|
735
|
+
...correlationId === void 0 ? {} : { correlationId }
|
|
736
|
+
};
|
|
737
|
+
},
|
|
738
|
+
headers: (ids) => ({
|
|
739
|
+
...ids.requestId === void 0 ? {} : { [requestHeader]: ids.requestId },
|
|
740
|
+
...ids.correlationId === void 0 ? {} : { [correlationHeader]: ids.correlationId }
|
|
741
|
+
})
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region src/server/server-types.ts
|
|
746
|
+
/** The header `current_tenant_id()` reads over the Data API. */
|
|
747
|
+
const TENANT_HEADER = "x-bs-tenant";
|
|
748
|
+
//#endregion
|
|
749
|
+
//#region src/auth/support-cookie.ts
|
|
750
|
+
/** The cookie that carries the support session id. */
|
|
751
|
+
const SUPPORT_COOKIE = "bs-support";
|
|
752
|
+
/** Seconds until the session expires, rounded up so the cookie never outlives it by less than a second. */
|
|
753
|
+
function supportCookieMaxAge(session, now = Date.now()) {
|
|
754
|
+
return Math.max(0, Math.ceil((session.expiresAt.epochMilliseconds - now) / 1e3));
|
|
755
|
+
}
|
|
756
|
+
/** `Set-Cookie` for a session: HttpOnly, SameSite=Lax, gone when the session expires. */
|
|
757
|
+
function supportCookie(session, options = {}, now = Date.now()) {
|
|
758
|
+
return cookieLine(options, encodeURIComponent(session.id), supportCookieMaxAge(session, now));
|
|
759
|
+
}
|
|
760
|
+
/** `Set-Cookie` that removes the support cookie. */
|
|
761
|
+
function clearSupportCookie(options = {}) {
|
|
762
|
+
return cookieLine(options, "", 0);
|
|
763
|
+
}
|
|
764
|
+
function cookieLine(options, value, maxAge) {
|
|
765
|
+
return [
|
|
766
|
+
`${options.name ?? "bs-support"}=${value}`,
|
|
767
|
+
`Path=${options.path ?? "/"}`,
|
|
768
|
+
`Max-Age=${String(maxAge)}`,
|
|
769
|
+
"HttpOnly",
|
|
770
|
+
"SameSite=Lax",
|
|
771
|
+
...options.secure === false ? [] : ["Secure"]
|
|
772
|
+
].join("; ");
|
|
773
|
+
}
|
|
774
|
+
/** The support session id in a `Cookie` header, or `undefined`. */
|
|
775
|
+
function supportCookieValue(cookieHeader, name = SUPPORT_COOKIE) {
|
|
776
|
+
if (!cookieHeader) return;
|
|
777
|
+
for (const part of cookieHeader.split(";")) {
|
|
778
|
+
const index = part.indexOf("=");
|
|
779
|
+
if (index === -1 || part.slice(0, index).trim() !== name) continue;
|
|
780
|
+
let value;
|
|
781
|
+
try {
|
|
782
|
+
value = decodeURIComponent(part.slice(index + 1).trim());
|
|
783
|
+
} catch {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
return value === "" ? void 0 : value;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
//#endregion
|
|
790
|
+
//#region src/server/support-off.ts
|
|
791
|
+
const NOT_CONFIGURED = "Support sessions need createServer(betterSupabase, { support: supportSessions({ store }) })";
|
|
792
|
+
const notConfigured = () => AsyncResult.err(dbError("unexpected", NOT_CONFIGURED));
|
|
793
|
+
/** `bs.support` without `ServerOptions.support`: every call fails. */
|
|
794
|
+
const supportOff = {
|
|
795
|
+
start: notConfigured,
|
|
796
|
+
request: notConfigured,
|
|
797
|
+
approve: notConfigured,
|
|
798
|
+
stop: notConfigured,
|
|
799
|
+
revoke: notConfigured,
|
|
800
|
+
current: () => Promise.resolve(void 0),
|
|
801
|
+
resolve: () => Promise.resolve(void 0),
|
|
802
|
+
list: notConfigured,
|
|
803
|
+
expire: notConfigured,
|
|
804
|
+
expireRoute: () => () => Promise.resolve(problemResponse(dbError("unexpected", NOT_CONFIGURED))),
|
|
805
|
+
sessionIdOf: () => void 0,
|
|
806
|
+
clearCookie: () => clearSupportCookie()
|
|
807
|
+
};
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/server/support-storage.ts
|
|
810
|
+
const VISIBLE_OBJECT = "select exists (select 1 from storage.objects o where o.bucket_id = $1 and o.name = $2) as visible";
|
|
811
|
+
const VISIBLE_OBJECTS = `select n.path from unnest($2::text[]) as n(path)
|
|
812
|
+
where exists (select 1 from storage.objects o where o.bucket_id = $1 and o.name = n.path)`;
|
|
813
|
+
const OBJECT_INFO = "select to_jsonb(o) as object from storage.objects o where o.bucket_id = $1 and o.name = $2";
|
|
814
|
+
const SEARCH = `select s.name, s.id::text as id, s.updated_at, s.created_at, s.last_accessed_at, s.metadata
|
|
815
|
+
from storage.search($1::text, $2::text, $3::int, $4::int, $5::int, $6::text, $7::text, $8::text) s`;
|
|
816
|
+
const SEARCH_V2 = `select s.key, s.name, s.id::text as id, s.updated_at, s.created_at, s.last_accessed_at, s.metadata
|
|
817
|
+
from storage.search_v2($1::text, $2::text, $3::int, $4::int, $5::text, $6::text, $7::text, $8::text) s`;
|
|
818
|
+
const SAVEPOINT = "better_supabase_support_write";
|
|
819
|
+
const INSERT_OBJECT = `insert into storage.objects (bucket_id, name, owner, owner_id, user_metadata)
|
|
820
|
+
values ($1, $2, $3::uuid, $4, $5::jsonb)`;
|
|
821
|
+
const CURRENT_VERSION_INDEX = `select exists (select 1 from pg_indexes
|
|
822
|
+
where schemaname = 'storage' and tablename = 'objects' and indexname = 'idx_objects_current_version') as versioned`;
|
|
823
|
+
const upsertObject = (versioned) => `${INSERT_OBJECT}
|
|
824
|
+
on conflict ${versioned ? "(bucket_id, name collate \"C\") where archived_at is null" : "(bucket_id, name)"} do update
|
|
825
|
+
set owner = excluded.owner, owner_id = excluded.owner_id, user_metadata = excluded.user_metadata`;
|
|
826
|
+
const SOURCE_OBJECT = "select name, owner_id from storage.objects where bucket_id = $1 and name = $2";
|
|
827
|
+
const MOVE_OBJECT = `update storage.objects
|
|
828
|
+
set bucket_id = $3, name = $4, owner = $5::uuid, owner_id = $6
|
|
829
|
+
where bucket_id = $1 and name = $2
|
|
830
|
+
returning name`;
|
|
831
|
+
const ALLOW_DELETE = "select set_config('storage.allow_delete_query', 'true', true)";
|
|
832
|
+
const DELETE_OBJECTS = "delete from storage.objects where bucket_id = $1 and name = any($2::text[]) returning name";
|
|
833
|
+
const OWN_UPLOAD = `update storage.objects set owner = $3::uuid, owner_id = $4
|
|
834
|
+
where bucket_id = $1 and name = $2 and user_metadata ->> 'supportSessionId' = $5`;
|
|
835
|
+
const OWN_COPY = `update storage.objects
|
|
836
|
+
set owner = $3::uuid, owner_id = $4, user_metadata = coalesce(user_metadata, '{}'::jsonb) || $5::jsonb
|
|
837
|
+
where bucket_id = $1 and name = $2 and owner_id is null`;
|
|
838
|
+
const OWN_MOVE = `update storage.objects
|
|
839
|
+
set owner = $3::uuid, owner_id = $4, user_metadata = coalesce(user_metadata, '{}'::jsonb) || $5::jsonb
|
|
840
|
+
where bucket_id = $1 and name = $2 and owner_id is not distinct from $6`;
|
|
841
|
+
const UUID = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
842
|
+
const HIDDEN_URL = "Either the object does not exist or you do not have access to it";
|
|
843
|
+
const LIST_SORT_COLUMNS = /* @__PURE__ */ new Set([
|
|
844
|
+
"name",
|
|
845
|
+
"updated_at",
|
|
846
|
+
"created_at",
|
|
847
|
+
"last_accessed_at"
|
|
848
|
+
]);
|
|
849
|
+
const LIST_V2_SORT_COLUMNS = /* @__PURE__ */ new Set([
|
|
850
|
+
"name",
|
|
851
|
+
"updated_at",
|
|
852
|
+
"created_at"
|
|
853
|
+
]);
|
|
854
|
+
const FLAT_SORT_COLUMNS = /* @__PURE__ */ new Set(["updated_at", "created_at"]);
|
|
855
|
+
const SORT_ORDERS = /* @__PURE__ */ new Set(["asc", "desc"]);
|
|
856
|
+
const CURSOR_PARTS = {
|
|
857
|
+
l: "startAfter",
|
|
858
|
+
o: "sortOrder",
|
|
859
|
+
c: "sortColumn",
|
|
860
|
+
a: "sortColumnAfter"
|
|
861
|
+
};
|
|
862
|
+
const isCursorKey = (key) => Object.hasOwn(CURSOR_PARTS, key);
|
|
863
|
+
/** The path storage-js sends for an upload: no leading or trailing `/`, and no empty folders. */
|
|
864
|
+
function normalizePath(path) {
|
|
865
|
+
return path.replaceAll(/^\/|\/$/g, "").replaceAll(/\/+/g, "/");
|
|
866
|
+
}
|
|
867
|
+
/** `undefined` for an empty string, which storage-api treats as absent. */
|
|
868
|
+
const filled = (value) => value === "" ? void 0 : value;
|
|
869
|
+
/** `LIKE` escaping as storage-api applies it. */
|
|
870
|
+
function escapeLike(text) {
|
|
871
|
+
return text.replaceAll("\\", "\\\\").replaceAll(/([%_])/g, "\\$1");
|
|
872
|
+
}
|
|
873
|
+
function iso(value) {
|
|
874
|
+
if (value instanceof Date) return value.toISOString();
|
|
875
|
+
if (typeof value !== "string") return value;
|
|
876
|
+
const time = Date.parse(value);
|
|
877
|
+
return Number.isNaN(time) ? value : new Date(time).toISOString();
|
|
878
|
+
}
|
|
879
|
+
/** storage-api's continuation token: `key:value` lines, base64 encoded. */
|
|
880
|
+
function encodeCursor(cursor) {
|
|
881
|
+
const text = Object.entries(CURSOR_PARTS).flatMap(([key, part]) => cursor[part] ? [`${key}:${cursor[part]}`] : []).join("\n");
|
|
882
|
+
let binary = "";
|
|
883
|
+
for (const byte of new TextEncoder().encode(text)) binary += String.fromCodePoint(byte);
|
|
884
|
+
return btoa(binary);
|
|
885
|
+
}
|
|
886
|
+
function decodeCursor(token) {
|
|
887
|
+
let text;
|
|
888
|
+
try {
|
|
889
|
+
text = new TextDecoder().decode(Uint8Array.from(atob(token), (char) => char.codePointAt(0) ?? 0));
|
|
890
|
+
} catch {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const cursor = {
|
|
894
|
+
startAfter: "",
|
|
895
|
+
sortOrder: "asc"
|
|
896
|
+
};
|
|
897
|
+
for (const part of text.split("\n")) {
|
|
898
|
+
const match = /^(\S):(.*)/.exec(part);
|
|
899
|
+
const key = match?.[1];
|
|
900
|
+
if (!key || !isCursorKey(key)) return;
|
|
901
|
+
cursor[CURSOR_PARTS[key]] = match[2] ?? "";
|
|
902
|
+
}
|
|
903
|
+
return cursor;
|
|
904
|
+
}
|
|
905
|
+
const apiError = (status, message, code) => ({
|
|
906
|
+
name: "StorageApiError",
|
|
907
|
+
message,
|
|
908
|
+
status,
|
|
909
|
+
statusCode: String(status),
|
|
910
|
+
code
|
|
911
|
+
});
|
|
912
|
+
const ownerOf = (userId) => UUID.test(userId) ? userId : null;
|
|
913
|
+
const stampOf = (session) => ({
|
|
914
|
+
supportSessionId: session.id,
|
|
915
|
+
supportAdminId: session.adminId
|
|
916
|
+
});
|
|
917
|
+
const failed = (error) => ({
|
|
918
|
+
data: null,
|
|
919
|
+
error
|
|
920
|
+
});
|
|
921
|
+
/** Storage answers a hidden object like a missing one: HTTP 400 with `statusCode` 404. */
|
|
922
|
+
const NOT_FOUND = {
|
|
923
|
+
name: "StorageApiError",
|
|
924
|
+
message: "Object not found",
|
|
925
|
+
status: 400,
|
|
926
|
+
statusCode: "404",
|
|
927
|
+
code: "NoSuchKey"
|
|
928
|
+
};
|
|
929
|
+
const invalid = (message) => apiError(400, message, "InvalidRequest");
|
|
930
|
+
/** A database failure as a Storage `error` that `fromStorageError` passes through unchanged. */
|
|
931
|
+
function sqlFailure(cause) {
|
|
932
|
+
const raw = fromPgError(cause);
|
|
933
|
+
return {
|
|
934
|
+
name: "DbError",
|
|
935
|
+
...raw ? mapDbError(raw) : toDbError(cause)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
/** An RLS or duplicate failure of a dry run, as Storage reports it for the target's own request. */
|
|
939
|
+
function refusedWrite(cause) {
|
|
940
|
+
const raw = fromPgError(cause);
|
|
941
|
+
if (raw?.code === "42501") return apiError(403, raw.message === void 0 || raw.message.includes("row-level security") ? "new row violates row-level security policy" : raw.message, "AccessDenied");
|
|
942
|
+
if (raw?.code === "23505") return apiError(409, "The resource already exists", "Duplicate");
|
|
943
|
+
}
|
|
944
|
+
async function settled(run) {
|
|
945
|
+
try {
|
|
946
|
+
return await run();
|
|
947
|
+
} catch (cause) {
|
|
948
|
+
return failed(sqlFailure(cause));
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
function listProblem(options) {
|
|
952
|
+
const { limit, offset, sortBy } = options;
|
|
953
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1)) return "body/limit must be an integer of at least 1";
|
|
954
|
+
if (offset !== void 0 && (!Number.isInteger(offset) || offset < 0)) return "body/offset must be an integer of at least 0";
|
|
955
|
+
if (sortBy?.column !== void 0 && !LIST_SORT_COLUMNS.has(sortBy.column)) return "body/sortBy/column must be name, updated_at, created_at or last_accessed_at";
|
|
956
|
+
if (sortBy?.order !== void 0 && !SORT_ORDERS.has(sortBy.order)) return "body/sortBy/order must be asc or desc";
|
|
957
|
+
}
|
|
958
|
+
function listV2Problem(options) {
|
|
959
|
+
const { limit, sortBy } = options;
|
|
960
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1)) return "body/limit must be an integer of at least 1";
|
|
961
|
+
if (sortBy !== void 0 && !LIST_V2_SORT_COLUMNS.has(sortBy.column)) return "body/sortBy/column must be name, updated_at or created_at";
|
|
962
|
+
if (sortBy?.order !== void 0 && !SORT_ORDERS.has(sortBy.order)) return "body/sortBy/order must be asc or desc";
|
|
963
|
+
}
|
|
964
|
+
/** The query storage-api runs for a `list-v2` page without a delimiter. */
|
|
965
|
+
function flatPage(bucket, prefix, maxKeys, cursor, column, order) {
|
|
966
|
+
const values = [bucket, maxKeys];
|
|
967
|
+
const conditions = ["bucket_id = $1"];
|
|
968
|
+
const sortColumn = column && FLAT_SORT_COLUMNS.has(column) ? column : void 0;
|
|
969
|
+
const sortOrder = order && SORT_ORDERS.has(order) ? order : "asc";
|
|
970
|
+
const operator = sortOrder === "asc" ? ">" : "<";
|
|
971
|
+
const param = () => `$${String(values.length)}`;
|
|
972
|
+
if (prefix) {
|
|
973
|
+
values.push(`${escapeLike(prefix)}%`);
|
|
974
|
+
conditions.push(`name like ${param()}`);
|
|
975
|
+
}
|
|
976
|
+
const startAfter = cursor?.startAfter;
|
|
977
|
+
if (startAfter && sortColumn && cursor.sortColumnAfter) {
|
|
978
|
+
values.push(cursor.sortColumnAfter);
|
|
979
|
+
const afterParam = param();
|
|
980
|
+
values.push(startAfter);
|
|
981
|
+
conditions.push(`row(date_trunc('milliseconds', ${sortColumn}), name collate "C") ${operator} row(coalesce(nullif(${afterParam}, '')::timestamptz, 'epoch'::timestamptz), ${param()})`);
|
|
982
|
+
} else if (startAfter) {
|
|
983
|
+
values.push(startAfter);
|
|
984
|
+
conditions.push(`name collate "C" ${operator} ${param()}`);
|
|
985
|
+
}
|
|
986
|
+
return {
|
|
987
|
+
text: `select id::text as id, name, metadata, updated_at, created_at, last_accessed_at
|
|
988
|
+
from storage.objects
|
|
989
|
+
where ${conditions.join(" and ")}
|
|
990
|
+
order by ${sortColumn ? `${sortColumn} ${sortOrder}, ` : ""}name collate "C" ${sortOrder}
|
|
991
|
+
limit $2::int`,
|
|
992
|
+
values
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
/** Groups the entries below the next delimiter into folders, as storage-api does. */
|
|
996
|
+
function delimited(entries, prefix) {
|
|
997
|
+
const grouped = [];
|
|
998
|
+
let previous = "";
|
|
999
|
+
for (const entry of entries) {
|
|
1000
|
+
const name = String(entry["name"]);
|
|
1001
|
+
const index = name.replace(prefix, "").indexOf("/");
|
|
1002
|
+
if (index === -1) {
|
|
1003
|
+
grouped.push(entry);
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
const folder = name.slice(0, prefix.length + index + 1);
|
|
1007
|
+
if (folder === previous) continue;
|
|
1008
|
+
previous = folder;
|
|
1009
|
+
grouped.push({
|
|
1010
|
+
id: null,
|
|
1011
|
+
name: folder
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
return grouped;
|
|
1015
|
+
}
|
|
1016
|
+
const text = (value) => typeof value === "string" ? value : void 0;
|
|
1017
|
+
const metadataOf = (value) => isRecord(value) ? value : null;
|
|
1018
|
+
function listEntryOf(row) {
|
|
1019
|
+
return {
|
|
1020
|
+
name: String(row["name"]),
|
|
1021
|
+
id: text(row["id"]) ?? null,
|
|
1022
|
+
updated_at: text(iso(row["updated_at"])) ?? null,
|
|
1023
|
+
created_at: text(iso(row["created_at"])) ?? null,
|
|
1024
|
+
last_accessed_at: text(iso(row["last_accessed_at"])) ?? null,
|
|
1025
|
+
metadata: metadataOf(row["metadata"])
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
function folderOf(row) {
|
|
1029
|
+
const name = String(row["name"]);
|
|
1030
|
+
const key = text(row["key"]);
|
|
1031
|
+
return {
|
|
1032
|
+
name: name.endsWith("/") ? name : `${name}/`,
|
|
1033
|
+
...key === void 0 ? {} : { key }
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
function objectOf(row) {
|
|
1037
|
+
const key = text(row["key"]);
|
|
1038
|
+
const lastAccessed = text(iso(row["last_accessed_at"]));
|
|
1039
|
+
return {
|
|
1040
|
+
name: String(row["name"]),
|
|
1041
|
+
...key === void 0 ? {} : { key },
|
|
1042
|
+
id: text(row["id"]) ?? "",
|
|
1043
|
+
updated_at: text(iso(row["updated_at"])) ?? "",
|
|
1044
|
+
created_at: text(iso(row["created_at"])) ?? "",
|
|
1045
|
+
...lastAccessed === void 0 ? {} : { last_accessed_at: lastAccessed },
|
|
1046
|
+
metadata: metadataOf(row["metadata"])
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function infoOf(row) {
|
|
1050
|
+
const metadata = isRecord(row["metadata"]) ? row["metadata"] : {};
|
|
1051
|
+
const size = metadata["size"];
|
|
1052
|
+
const contentType = text(metadata["mimetype"]);
|
|
1053
|
+
const cacheControl = text(metadata["cacheControl"]);
|
|
1054
|
+
const etag = text(metadata["eTag"]);
|
|
1055
|
+
const lastModified = text(iso(row["updated_at"]));
|
|
1056
|
+
const userMetadata = row["user_metadata"];
|
|
1057
|
+
const archivedAt = row["archived_at"];
|
|
1058
|
+
const deleteMarker = row["is_delete_marker"];
|
|
1059
|
+
const versioned = row["is_versioned"];
|
|
1060
|
+
return {
|
|
1061
|
+
id: text(row["id"]) ?? "",
|
|
1062
|
+
name: text(row["name"]) ?? "",
|
|
1063
|
+
version: text(row["version"]) ?? "",
|
|
1064
|
+
bucketId: text(row["bucket_id"]) ?? "",
|
|
1065
|
+
createdAt: text(iso(row["created_at"])) ?? "",
|
|
1066
|
+
...typeof size === "number" ? { size } : {},
|
|
1067
|
+
...contentType === void 0 ? {} : { contentType },
|
|
1068
|
+
...cacheControl === void 0 ? {} : { cacheControl },
|
|
1069
|
+
...etag === void 0 ? {} : { etag },
|
|
1070
|
+
...lastModified === void 0 ? {} : { lastModified },
|
|
1071
|
+
...isRecord(userMetadata) ? { metadata: userMetadata } : {},
|
|
1072
|
+
...archivedAt === void 0 ? {} : { archivedAt: text(iso(archivedAt)) ?? null },
|
|
1073
|
+
...typeof deleteMarker === "boolean" ? { isDeleteMarker: deleteMarker } : {},
|
|
1074
|
+
...typeof versioned === "boolean" ? { isVersioned: versioned } : {}
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Storage for a support session, with the same `from(bucket)` file API as
|
|
1079
|
+
* `supabase.storage`, so `bucket.connect()` and the blocks take it.
|
|
1080
|
+
*
|
|
1081
|
+
* Storage policies read `auth.uid()` from the request's token, and there is
|
|
1082
|
+
* no token for the target, so reads go through Postgres as the target.
|
|
1083
|
+
* `exists`, `info`, `list` and `listV2` run entirely there: the listings
|
|
1084
|
+
* call the invoker-rights `storage.search` functions storage-api calls, so
|
|
1085
|
+
* RLS filters each page as it would for the target's own request.
|
|
1086
|
+
* `download` and the signed URLs first check there that the target may see
|
|
1087
|
+
* the object, then the service client serves it. A hidden object answers
|
|
1088
|
+
* like a missing one. `getPublicUrl` is built without a check, as it is
|
|
1089
|
+
* built without a request.
|
|
1090
|
+
*
|
|
1091
|
+
* In a writable session, `upload`, `update`, `remove`, `copy` and `move`
|
|
1092
|
+
* first run the row change Storage would make as the target, inside a
|
|
1093
|
+
* savepoint that is rolled back, so the policies on `storage.objects`
|
|
1094
|
+
* decide as for the target's own request. Then the service client writes,
|
|
1095
|
+
* the admin connection makes the target the owner of the stored object,
|
|
1096
|
+
* and its `user_metadata` records the session id and the admin's id. A
|
|
1097
|
+
* refused dry run resolves to Storage's `403`. Signed uploads resolve to a
|
|
1098
|
+
* `403` `SUPPORT_STORAGE_WRITES` error, and every write in a read-only
|
|
1099
|
+
* session to a `403` `SUPPORT_READ_ONLY` error.
|
|
1100
|
+
*/
|
|
1101
|
+
function supportStorage(options) {
|
|
1102
|
+
const readOnly = options.readOnly ?? true;
|
|
1103
|
+
const { adminSql, session, sql } = options;
|
|
1104
|
+
const writer = !readOnly && adminSql && session && sql.transaction ? {
|
|
1105
|
+
adminSql,
|
|
1106
|
+
session
|
|
1107
|
+
} : void 0;
|
|
1108
|
+
const refusal = readOnly ? apiError(403, "The support session is read-only", "SUPPORT_READ_ONLY") : apiError(403, "Storage writes in a support session need adminSql, session and a sql client with transaction", "SUPPORT_STORAGE_WRITES");
|
|
1109
|
+
const signedRefusal = readOnly ? refusal : apiError(403, "Signed uploads are not available in a support session", "SUPPORT_STORAGE_WRITES");
|
|
1110
|
+
const refuse = () => Promise.resolve(failed(refusal));
|
|
1111
|
+
const refuseSigned = () => Promise.resolve(failed(signedRefusal));
|
|
1112
|
+
const rows = (query, values) => sql.queryRaw(query, values);
|
|
1113
|
+
let versioned;
|
|
1114
|
+
const upsertStatement = () => (versioned ??= rows(CURRENT_VERSION_INDEX, []).then(([row]) => row?.["versioned"] === true).catch((cause) => {
|
|
1115
|
+
versioned = void 0;
|
|
1116
|
+
throw cause;
|
|
1117
|
+
})).then(upsertObject);
|
|
1118
|
+
const rehearse = async (run) => {
|
|
1119
|
+
if (!sql.transaction) return refusal;
|
|
1120
|
+
try {
|
|
1121
|
+
return await sql.transaction(async (client) => {
|
|
1122
|
+
await client.queryRaw(`savepoint ${SAVEPOINT}`);
|
|
1123
|
+
try {
|
|
1124
|
+
return await run(client);
|
|
1125
|
+
} finally {
|
|
1126
|
+
await client.queryRaw(`rollback to savepoint ${SAVEPOINT}`);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
} catch (cause) {
|
|
1130
|
+
const refused = refusedWrite(cause);
|
|
1131
|
+
if (refused) return refused;
|
|
1132
|
+
throw cause;
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
return { from(bucket) {
|
|
1136
|
+
const admin = () => options.admin.from(bucket);
|
|
1137
|
+
const visible = async (path) => {
|
|
1138
|
+
const [row] = await rows(VISIBLE_OBJECT, [bucket, path]);
|
|
1139
|
+
return row?.["visible"] === true;
|
|
1140
|
+
};
|
|
1141
|
+
const checked = (path, read) => settled(async () => {
|
|
1142
|
+
const name = normalizePath(path);
|
|
1143
|
+
if (!await visible(name)) return failed(NOT_FOUND);
|
|
1144
|
+
return read(name);
|
|
1145
|
+
});
|
|
1146
|
+
const list = (path, listOptions = {}) => settled(async () => {
|
|
1147
|
+
const problem = listProblem(listOptions);
|
|
1148
|
+
if (problem) return failed(invalid(problem));
|
|
1149
|
+
let prefix = path ?? "";
|
|
1150
|
+
if (prefix.length > 0 && !prefix.endsWith("/")) prefix = `${prefix}/`;
|
|
1151
|
+
const column = listOptions.sortBy?.column ?? "name";
|
|
1152
|
+
const escape = column !== "name";
|
|
1153
|
+
const safePrefix = escape ? escapeLike(prefix) : prefix;
|
|
1154
|
+
const search = listOptions.search ?? "";
|
|
1155
|
+
const safeSearch = escape ? escapeLike(search) : search;
|
|
1156
|
+
return {
|
|
1157
|
+
data: (await rows(SEARCH, [
|
|
1158
|
+
safePrefix,
|
|
1159
|
+
bucket,
|
|
1160
|
+
listOptions.limit ?? 100,
|
|
1161
|
+
(safePrefix + safeSearch).split("/").length,
|
|
1162
|
+
listOptions.offset ?? 0,
|
|
1163
|
+
safeSearch,
|
|
1164
|
+
column,
|
|
1165
|
+
listOptions.sortBy?.order ?? "asc"
|
|
1166
|
+
])).map(listEntryOf),
|
|
1167
|
+
error: null
|
|
1168
|
+
};
|
|
1169
|
+
});
|
|
1170
|
+
const listV2 = (listOptions = {}) => settled(async () => {
|
|
1171
|
+
const problem = listV2Problem(listOptions);
|
|
1172
|
+
if (problem) return failed(invalid(problem));
|
|
1173
|
+
const limit = Math.min(listOptions.limit ?? 1e3, 1e3);
|
|
1174
|
+
const prefix = listOptions.prefix ?? "";
|
|
1175
|
+
const cursor = listOptions.cursor ? decodeCursor(listOptions.cursor) : void 0;
|
|
1176
|
+
if (listOptions.cursor && !cursor) return failed(apiError(400, "Invalid continuation token", "InvalidParameter"));
|
|
1177
|
+
const sortOrder = filled(cursor?.sortOrder) ?? listOptions.sortBy?.order;
|
|
1178
|
+
const sortColumn = filled(cursor?.sortColumn) ?? listOptions.sortBy?.column;
|
|
1179
|
+
let found;
|
|
1180
|
+
if (listOptions.with_delimiter) found = await rows(SEARCH_V2, [
|
|
1181
|
+
prefix,
|
|
1182
|
+
bucket,
|
|
1183
|
+
limit + 1,
|
|
1184
|
+
prefix ? prefix.split("/").length : 1,
|
|
1185
|
+
cursor?.startAfter ?? "",
|
|
1186
|
+
sortOrder ?? "asc",
|
|
1187
|
+
sortColumn ?? "name",
|
|
1188
|
+
filled(cursor?.sortColumnAfter) ?? null
|
|
1189
|
+
]);
|
|
1190
|
+
else {
|
|
1191
|
+
const page = flatPage(bucket, listOptions.prefix, limit + 1, cursor, sortColumn, sortOrder);
|
|
1192
|
+
found = await rows(page.text, page.values);
|
|
1193
|
+
}
|
|
1194
|
+
const entries = listOptions.with_delimiter ? delimited(found, prefix) : found;
|
|
1195
|
+
const hasNext = entries.length > limit;
|
|
1196
|
+
const count = hasNext ? limit : entries.length;
|
|
1197
|
+
const folders = [];
|
|
1198
|
+
const objects = [];
|
|
1199
|
+
for (const entry of entries.slice(0, count)) if (entry["id"] === null || entry["id"] === void 0) folders.push(folderOf(entry));
|
|
1200
|
+
else objects.push(objectOf(entry));
|
|
1201
|
+
const last = entries[count - 1];
|
|
1202
|
+
const after = last && sortColumn && sortColumn !== "name" ? iso(last[sortColumn]) : void 0;
|
|
1203
|
+
const nextCursor = hasNext && last ? encodeCursor({
|
|
1204
|
+
startAfter: String(last["name"]),
|
|
1205
|
+
...sortOrder ? { sortOrder } : {},
|
|
1206
|
+
...sortColumn ? { sortColumn } : {},
|
|
1207
|
+
...typeof after === "string" ? { sortColumnAfter: new Date(after).toISOString() } : {}
|
|
1208
|
+
}) : void 0;
|
|
1209
|
+
return {
|
|
1210
|
+
data: {
|
|
1211
|
+
hasNext,
|
|
1212
|
+
...nextCursor === void 0 ? {} : { nextCursor },
|
|
1213
|
+
folders,
|
|
1214
|
+
objects
|
|
1215
|
+
},
|
|
1216
|
+
error: null
|
|
1217
|
+
};
|
|
1218
|
+
});
|
|
1219
|
+
const store = (method) => (path, body, fileOptions = {}) => {
|
|
1220
|
+
if (!writer) return refuse();
|
|
1221
|
+
const { adminSql: ownerSql, session: active } = writer;
|
|
1222
|
+
return settled(async () => {
|
|
1223
|
+
const name = normalizePath(path);
|
|
1224
|
+
const owner = ownerOf(active.targetUserId);
|
|
1225
|
+
const metadata = {
|
|
1226
|
+
...fileOptions.metadata,
|
|
1227
|
+
...stampOf(active)
|
|
1228
|
+
};
|
|
1229
|
+
const statement = method === "update" || fileOptions.upsert === true ? await upsertStatement() : INSERT_OBJECT;
|
|
1230
|
+
const refused = await rehearse(async (client) => {
|
|
1231
|
+
await client.queryRaw(statement, [
|
|
1232
|
+
bucket,
|
|
1233
|
+
name,
|
|
1234
|
+
owner,
|
|
1235
|
+
active.targetUserId,
|
|
1236
|
+
JSON.stringify(metadata)
|
|
1237
|
+
]);
|
|
1238
|
+
return null;
|
|
1239
|
+
});
|
|
1240
|
+
if (refused) return failed(refused);
|
|
1241
|
+
const reply = await admin()[method](name, body, {
|
|
1242
|
+
...fileOptions,
|
|
1243
|
+
metadata
|
|
1244
|
+
});
|
|
1245
|
+
if (reply.error) return reply;
|
|
1246
|
+
try {
|
|
1247
|
+
await ownerSql.queryRaw(OWN_UPLOAD, [
|
|
1248
|
+
bucket,
|
|
1249
|
+
name,
|
|
1250
|
+
owner,
|
|
1251
|
+
active.targetUserId,
|
|
1252
|
+
active.id
|
|
1253
|
+
]);
|
|
1254
|
+
} catch (cause) {
|
|
1255
|
+
await admin().remove([name]);
|
|
1256
|
+
return failed(sqlFailure(cause));
|
|
1257
|
+
}
|
|
1258
|
+
return reply;
|
|
1259
|
+
});
|
|
1260
|
+
};
|
|
1261
|
+
const relocate = (method) => (from, to, destination = {}) => {
|
|
1262
|
+
if (!writer) return refuse();
|
|
1263
|
+
const { adminSql: ownerSql, session: active } = writer;
|
|
1264
|
+
return settled(async () => {
|
|
1265
|
+
const source = normalizePath(from);
|
|
1266
|
+
const name = normalizePath(to);
|
|
1267
|
+
const target = destination.destinationBucket ?? bucket;
|
|
1268
|
+
const owner = ownerOf(active.targetUserId);
|
|
1269
|
+
const stamp = JSON.stringify(stampOf(active));
|
|
1270
|
+
let previousOwner = null;
|
|
1271
|
+
const refused = await rehearse(async (client) => {
|
|
1272
|
+
const [found] = await client.queryRaw(SOURCE_OBJECT, [bucket, source]);
|
|
1273
|
+
if (!found) return NOT_FOUND;
|
|
1274
|
+
previousOwner = text(found["owner_id"]) ?? null;
|
|
1275
|
+
if (method === "copy") {
|
|
1276
|
+
await client.queryRaw(INSERT_OBJECT, [
|
|
1277
|
+
target,
|
|
1278
|
+
name,
|
|
1279
|
+
owner,
|
|
1280
|
+
active.targetUserId,
|
|
1281
|
+
stamp
|
|
1282
|
+
]);
|
|
1283
|
+
return null;
|
|
1284
|
+
}
|
|
1285
|
+
const [moved] = await client.queryRaw(MOVE_OBJECT, [
|
|
1286
|
+
bucket,
|
|
1287
|
+
source,
|
|
1288
|
+
target,
|
|
1289
|
+
name,
|
|
1290
|
+
owner,
|
|
1291
|
+
active.targetUserId
|
|
1292
|
+
]);
|
|
1293
|
+
return moved ? null : NOT_FOUND;
|
|
1294
|
+
});
|
|
1295
|
+
if (refused) return failed(refused);
|
|
1296
|
+
const reply = await admin()[method](source, name, destination);
|
|
1297
|
+
if (reply.error) return reply;
|
|
1298
|
+
try {
|
|
1299
|
+
await (method === "copy" ? ownerSql.queryRaw(OWN_COPY, [
|
|
1300
|
+
target,
|
|
1301
|
+
name,
|
|
1302
|
+
owner,
|
|
1303
|
+
active.targetUserId,
|
|
1304
|
+
stamp
|
|
1305
|
+
]) : ownerSql.queryRaw(OWN_MOVE, [
|
|
1306
|
+
target,
|
|
1307
|
+
name,
|
|
1308
|
+
owner,
|
|
1309
|
+
active.targetUserId,
|
|
1310
|
+
stamp,
|
|
1311
|
+
previousOwner
|
|
1312
|
+
]));
|
|
1313
|
+
} catch (cause) {
|
|
1314
|
+
const written = options.admin.from(target);
|
|
1315
|
+
await (method === "copy" ? written.remove([name]) : written.move(name, source, { destinationBucket: bucket }));
|
|
1316
|
+
return failed(sqlFailure(cause));
|
|
1317
|
+
}
|
|
1318
|
+
return reply;
|
|
1319
|
+
});
|
|
1320
|
+
};
|
|
1321
|
+
const remove = (paths) => {
|
|
1322
|
+
if (!writer) return refuse();
|
|
1323
|
+
return settled(async () => {
|
|
1324
|
+
const entries = paths.map((entry) => typeof entry === "string" ? normalizePath(entry) : {
|
|
1325
|
+
...entry,
|
|
1326
|
+
path: normalizePath(entry.path)
|
|
1327
|
+
});
|
|
1328
|
+
const names = entries.map((entry) => typeof entry === "string" ? entry : entry.path);
|
|
1329
|
+
const removable = /* @__PURE__ */ new Set();
|
|
1330
|
+
const refused = await rehearse(async (client) => {
|
|
1331
|
+
await client.queryRaw(ALLOW_DELETE);
|
|
1332
|
+
const deleted = await client.queryRaw(DELETE_OBJECTS, [bucket, [...new Set(names)]]);
|
|
1333
|
+
for (const row of deleted) removable.add(String(row["name"]));
|
|
1334
|
+
return null;
|
|
1335
|
+
});
|
|
1336
|
+
if (refused) return failed(refused);
|
|
1337
|
+
const permitted = entries.filter((_, index) => removable.has(names[index] ?? ""));
|
|
1338
|
+
if (permitted.length === 0) return {
|
|
1339
|
+
data: [],
|
|
1340
|
+
error: null
|
|
1341
|
+
};
|
|
1342
|
+
return admin().remove(permitted);
|
|
1343
|
+
});
|
|
1344
|
+
};
|
|
1345
|
+
return {
|
|
1346
|
+
exists: (path) => settled(async () => ({
|
|
1347
|
+
data: await visible(normalizePath(path)),
|
|
1348
|
+
error: null
|
|
1349
|
+
})).then((reply) => reply.error === null ? reply : {
|
|
1350
|
+
data: false,
|
|
1351
|
+
error: reply.error
|
|
1352
|
+
}),
|
|
1353
|
+
info: (path, infoOptions) => settled(async () => {
|
|
1354
|
+
const versionId = infoOptions?.versionId;
|
|
1355
|
+
const name = normalizePath(path);
|
|
1356
|
+
const [row] = await rows(versionId === void 0 ? OBJECT_INFO : `${OBJECT_INFO} and o.version = $3`, versionId === void 0 ? [bucket, name] : [
|
|
1357
|
+
bucket,
|
|
1358
|
+
name,
|
|
1359
|
+
versionId
|
|
1360
|
+
]);
|
|
1361
|
+
const object = row?.["object"];
|
|
1362
|
+
return isRecord(object) ? {
|
|
1363
|
+
data: infoOf(object),
|
|
1364
|
+
error: null
|
|
1365
|
+
} : failed(NOT_FOUND);
|
|
1366
|
+
}),
|
|
1367
|
+
download: (path, downloadOptions, parameters) => checked(path, (name) => admin().download(name, downloadOptions, parameters)),
|
|
1368
|
+
createSignedUrl: (path, expiresIn, urlOptions) => checked(path, (name) => admin().createSignedUrl(name, expiresIn, urlOptions)),
|
|
1369
|
+
createSignedUrls: (paths, expiresIn, urlOptions) => settled(async () => {
|
|
1370
|
+
const names = paths.map(normalizePath);
|
|
1371
|
+
const seen = new Set((await rows(VISIBLE_OBJECTS, [bucket, names])).map((row) => String(row["path"])));
|
|
1372
|
+
const shown = [...new Set(names.filter((name) => seen.has(name)))];
|
|
1373
|
+
const signed = /* @__PURE__ */ new Map();
|
|
1374
|
+
if (shown.length > 0) {
|
|
1375
|
+
const reply = await admin().createSignedUrls(shown, expiresIn, urlOptions);
|
|
1376
|
+
if (reply.error) return failed(reply.error);
|
|
1377
|
+
for (const entry of reply.data) if (entry.path !== null) signed.set(entry.path, entry);
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
data: names.map((name) => signed.get(name) ?? {
|
|
1381
|
+
error: HIDDEN_URL,
|
|
1382
|
+
path: name,
|
|
1383
|
+
signedUrl: null
|
|
1384
|
+
}),
|
|
1385
|
+
error: null
|
|
1386
|
+
};
|
|
1387
|
+
}),
|
|
1388
|
+
getPublicUrl: (path, urlOptions) => admin().getPublicUrl(path, urlOptions),
|
|
1389
|
+
list,
|
|
1390
|
+
listV2,
|
|
1391
|
+
upload: store("upload"),
|
|
1392
|
+
update: store("update"),
|
|
1393
|
+
createSignedUploadUrl: refuseSigned,
|
|
1394
|
+
uploadToSignedUrl: refuseSigned,
|
|
1395
|
+
remove,
|
|
1396
|
+
copy: relocate("copy"),
|
|
1397
|
+
move: relocate("move"),
|
|
1398
|
+
purgeCache: (path, cacheOptions, parameters) => writer ? checked(path, (name) => admin().purgeCache(name, cacheOptions, parameters)) : refuse()
|
|
1399
|
+
};
|
|
1400
|
+
} };
|
|
1401
|
+
}
|
|
1402
|
+
//#endregion
|
|
1403
|
+
//#region src/server/server.ts
|
|
1404
|
+
/** The environment as `getEnv` resolves it, one variable at a time. */
|
|
1405
|
+
const RUNTIME_ENV = new Proxy({}, { get: (_target, key) => typeof key === "string" ? getEnv(key) : void 0 });
|
|
1406
|
+
const needsPostgres = (method) => dbError("invalid_request", `${method} needs createServer(betterSupabase, { postgres: createPostgres() })`);
|
|
1407
|
+
/**
|
|
1408
|
+
* A framework adapter's server: `server` plus the adapter's own methods,
|
|
1409
|
+
* without reading the lazy `env` getter. `extra` can't replace a
|
|
1410
|
+
* `BetterServer` method.
|
|
1411
|
+
*/
|
|
1412
|
+
function extendServer(server, extra) {
|
|
1413
|
+
const extended = Object.defineProperties({}, {
|
|
1414
|
+
...Object.getOwnPropertyDescriptors(server),
|
|
1415
|
+
...Object.getOwnPropertyDescriptors(extra)
|
|
1416
|
+
});
|
|
1417
|
+
shareCore(server, extended);
|
|
1418
|
+
return extended;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Server-side entry point for APIs, jobs, MCP servers and framework
|
|
1422
|
+
* adapters. Holds the secrets; `betterSupabase` stays isomorphic.
|
|
1423
|
+
*/
|
|
1424
|
+
function createServer(betterSupabase, options = {}) {
|
|
1425
|
+
const credentials = options.credentials === void 0 ? {} : { credentials: credentialProviderOf(options.credentials) };
|
|
1426
|
+
let loaded;
|
|
1427
|
+
const env = () => loaded ??= options.env ?? loadEnv(RUNTIME_ENV);
|
|
1428
|
+
const lite = liteBackend(options, env);
|
|
1429
|
+
if (lite === void 0 && (options.prefetchJwks ?? defaultPrefetchJwks()) && options.auth?.jwks === void 0) try {
|
|
1430
|
+
prefetchJwks({
|
|
1431
|
+
...options.auth,
|
|
1432
|
+
env: env()
|
|
1433
|
+
});
|
|
1434
|
+
} catch {}
|
|
1435
|
+
const { executorOptions, tunedExecutor, serviceClient, readUrl, apiKeyClient, supabaseFor, restAt } = createClients({
|
|
1436
|
+
options,
|
|
1437
|
+
env,
|
|
1438
|
+
definitionExecutor: betterSupabase.executorOptions(),
|
|
1439
|
+
lite,
|
|
1440
|
+
createClient
|
|
1441
|
+
});
|
|
1442
|
+
/** `$client` stays the full Supabase client, built when first read. */
|
|
1443
|
+
const withLazyClient = (db, client) => Object.defineProperty(db, "$client", {
|
|
1444
|
+
get: client,
|
|
1445
|
+
enumerable: true,
|
|
1446
|
+
configurable: true
|
|
1447
|
+
});
|
|
1448
|
+
const dbFor = (auth, context = {}) => {
|
|
1449
|
+
let supabase;
|
|
1450
|
+
const rest = restAt(env().url, auth);
|
|
1451
|
+
const db = betterSupabase.connect(rest, {
|
|
1452
|
+
...authContext(auth),
|
|
1453
|
+
...context
|
|
1454
|
+
}, auth.kind === "invalid" ? { executor: refusingExecutor(auth.error) } : tunedExecutor ? { executor: postgrestExecutor(rest, executorOptions) } : {});
|
|
1455
|
+
return withLazyClient(db, () => supabase ??= supabaseFor(auth));
|
|
1456
|
+
};
|
|
1457
|
+
const sqlFor = (claims, context, stats, session, storage) => {
|
|
1458
|
+
if (!options.postgres) throw new TypeError("Direct Postgres access needs createServer(betterSupabase, { postgres: createPostgres() })");
|
|
1459
|
+
return betterSupabase.connect(session ? options.postgres.executorFor(claims, session) : options.postgres.executorFor(claims), context, {
|
|
1460
|
+
...stats ? { stats } : {},
|
|
1461
|
+
...storage ? { storage } : {}
|
|
1462
|
+
});
|
|
1463
|
+
};
|
|
1464
|
+
/** `ServerOptions.tenant` outside `context()`, where it can't be awaited. */
|
|
1465
|
+
const syncTenant = (request, auth) => {
|
|
1466
|
+
const tenant = options.tenant?.(request, auth);
|
|
1467
|
+
if (tenant !== void 0 && typeof tenant !== "string") throw new TypeError("ServerOptions.tenant returned a promise: use context(request), or pass { tenant } to contextFromResolution");
|
|
1468
|
+
return tenant;
|
|
1469
|
+
};
|
|
1470
|
+
const pinMs = options.replicas?.pinMs ?? 5e3;
|
|
1471
|
+
const idPolicy = requestIdPolicy(options.requestIds);
|
|
1472
|
+
if (options.support && !options.postgres) throw new TypeError("Support sessions need createServer(betterSupabase, { postgres: createPostgres(), support })");
|
|
1473
|
+
const hooksProblem = options.authorization === void 0 ? void 0 : hooksApiProblem(options.authorization);
|
|
1474
|
+
if (hooksProblem !== void 0) throw new TypeError(hooksProblem);
|
|
1475
|
+
const audit = serverAudit(betterSupabase, options.audit);
|
|
1476
|
+
const support = options.support ? options.support.create(betterSupabase.events, options.auth?.claims ?? betterSupabase.claimsSchema, betterSupabase.temporal, options.authorization) : supportOff;
|
|
1477
|
+
/**
|
|
1478
|
+
* The target's context in a support session. Queries run over direct
|
|
1479
|
+
* Postgres with the target's claims plus `act`, read-only unless the
|
|
1480
|
+
* session allows writes; nothing reaches Supabase with the admin's token.
|
|
1481
|
+
*/
|
|
1482
|
+
const supportContextFor = (resolution, active, parent, tenant, ids) => {
|
|
1483
|
+
const { session, claims } = active;
|
|
1484
|
+
const record = (key) => {
|
|
1485
|
+
const value = claims[key];
|
|
1486
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? Object.fromEntries(Object.entries(value)) : void 0;
|
|
1487
|
+
};
|
|
1488
|
+
const appMetadata = record("app_metadata");
|
|
1489
|
+
const userMetadata = record("user_metadata");
|
|
1490
|
+
const user = {
|
|
1491
|
+
id: session.targetUserId,
|
|
1492
|
+
role: typeof claims["role"] === "string" ? claims["role"] : "authenticated",
|
|
1493
|
+
...typeof claims["email"] === "string" ? { email: claims["email"] } : {},
|
|
1494
|
+
...appMetadata ? { appMetadata } : {},
|
|
1495
|
+
...userMetadata ? { userMetadata } : {}
|
|
1496
|
+
};
|
|
1497
|
+
const auth = {
|
|
1498
|
+
kind: "user",
|
|
1499
|
+
token: "",
|
|
1500
|
+
claims,
|
|
1501
|
+
user,
|
|
1502
|
+
source: "support",
|
|
1503
|
+
expiresAt: Math.floor(session.expiresAt.epochMilliseconds / 1e3)
|
|
1504
|
+
};
|
|
1505
|
+
const scope = tenant ?? session.tenant;
|
|
1506
|
+
const base = userContext(user, claims);
|
|
1507
|
+
const context = scope === void 0 ? base : {
|
|
1508
|
+
...base,
|
|
1509
|
+
tenant: scope
|
|
1510
|
+
};
|
|
1511
|
+
const sessionOptions = sessionWith(ids, scope, session.readOnly);
|
|
1512
|
+
const recorder = new StatsRecorder(parent);
|
|
1513
|
+
const sqlClaims = claims;
|
|
1514
|
+
const unavailable = () => {
|
|
1515
|
+
throw new TypeError("ctx.supabase and ctx.db.$client are not available in a support session; ctx.db and ctx.sql run as the target");
|
|
1516
|
+
};
|
|
1517
|
+
let db;
|
|
1518
|
+
let sql;
|
|
1519
|
+
let storage;
|
|
1520
|
+
const targetStorage = () => {
|
|
1521
|
+
const postgres = options.postgres;
|
|
1522
|
+
if (!postgres) throw new TypeError("Support sessions need createServer(betterSupabase, { postgres: createPostgres(), support })");
|
|
1523
|
+
let asTarget;
|
|
1524
|
+
const target = () => asTarget ??= postgres.asUser(sqlClaims, sessionOptions);
|
|
1525
|
+
storage ??= supportStorage({
|
|
1526
|
+
admin: { from: (bucket) => serviceClient().storage.from(bucket) },
|
|
1527
|
+
sql: {
|
|
1528
|
+
queryRaw: (text, params) => target().queryRaw(text, params),
|
|
1529
|
+
transaction: (fn) => target().transaction?.(fn) ?? Promise.reject(/* @__PURE__ */ new TypeError("The target's SQL client has no transaction"))
|
|
1530
|
+
},
|
|
1531
|
+
adminSql: postgres.admin,
|
|
1532
|
+
session,
|
|
1533
|
+
readOnly: session.readOnly
|
|
1534
|
+
});
|
|
1535
|
+
return storage;
|
|
1536
|
+
};
|
|
1537
|
+
return {
|
|
1538
|
+
...credentials,
|
|
1539
|
+
...ids,
|
|
1540
|
+
auth,
|
|
1541
|
+
resolution,
|
|
1542
|
+
support: active,
|
|
1543
|
+
get storage() {
|
|
1544
|
+
return targetStorage();
|
|
1545
|
+
},
|
|
1546
|
+
get supabase() {
|
|
1547
|
+
return unavailable();
|
|
1548
|
+
},
|
|
1549
|
+
get db() {
|
|
1550
|
+
db ??= Object.defineProperty(sqlFor(sqlClaims, context, recorder, sessionOptions, targetStorage()), "$client", {
|
|
1551
|
+
get: unavailable,
|
|
1552
|
+
enumerable: true,
|
|
1553
|
+
configurable: true
|
|
1554
|
+
});
|
|
1555
|
+
return db;
|
|
1556
|
+
},
|
|
1557
|
+
get sql() {
|
|
1558
|
+
sql ??= sqlFor(sqlClaims, context, recorder, sessionOptions, targetStorage());
|
|
1559
|
+
return sql;
|
|
1560
|
+
},
|
|
1561
|
+
replica: void 0,
|
|
1562
|
+
stats: () => recorder.snapshot(),
|
|
1563
|
+
apply: (response) => resolution.apply(response),
|
|
1564
|
+
cookies: () => resolution.cookies
|
|
1565
|
+
};
|
|
1566
|
+
};
|
|
1567
|
+
/**
|
|
1568
|
+
* An API key's context. There is no JWT for PostgREST, so `ctx.db` and
|
|
1569
|
+
* `ctx.sql` run over direct Postgres with the key's synthesized claims,
|
|
1570
|
+
* scoped to its organization unless the tenant option names another.
|
|
1571
|
+
*/
|
|
1572
|
+
const apiKeyContextFor = (resolution, auth, parent, tenant, ids) => {
|
|
1573
|
+
const scope = tenant ?? auth.organizationId;
|
|
1574
|
+
const base = authContext(auth);
|
|
1575
|
+
const context = scope === void 0 ? base : {
|
|
1576
|
+
...base,
|
|
1577
|
+
tenant: scope
|
|
1578
|
+
};
|
|
1579
|
+
const session = sessionWith(ids, scope);
|
|
1580
|
+
const recorder = new StatsRecorder(parent);
|
|
1581
|
+
let db;
|
|
1582
|
+
let sql;
|
|
1583
|
+
return {
|
|
1584
|
+
...credentials,
|
|
1585
|
+
...ids,
|
|
1586
|
+
auth: resolution.auth,
|
|
1587
|
+
resolution,
|
|
1588
|
+
get supabase() {
|
|
1589
|
+
return apiKeyClient();
|
|
1590
|
+
},
|
|
1591
|
+
get db() {
|
|
1592
|
+
db ??= Object.defineProperty(sqlFor(auth.claims, context, recorder, session), "$client", {
|
|
1593
|
+
get: apiKeyClient,
|
|
1594
|
+
enumerable: true,
|
|
1595
|
+
configurable: true
|
|
1596
|
+
});
|
|
1597
|
+
return db;
|
|
1598
|
+
},
|
|
1599
|
+
get sql() {
|
|
1600
|
+
sql ??= sqlFor(auth.claims, context, recorder, session);
|
|
1601
|
+
return sql;
|
|
1602
|
+
},
|
|
1603
|
+
replica: void 0,
|
|
1604
|
+
stats: () => recorder.snapshot(),
|
|
1605
|
+
apply: (response) => resolution.apply(response),
|
|
1606
|
+
cookies: () => resolution.cookies
|
|
1607
|
+
};
|
|
1608
|
+
};
|
|
1609
|
+
/** Clients and repositories are built on first access: most scopes use one of them. */
|
|
1610
|
+
const contextFor = (resolution, requestHeaders, parent, until = 0, tenant, active, ids = {}) => {
|
|
1611
|
+
if (active) return supportContextFor(resolution, active, parent, tenant, ids);
|
|
1612
|
+
const { auth } = resolution;
|
|
1613
|
+
if (auth.kind === "apiKey") return apiKeyContextFor(resolution, auth, parent, tenant, ids);
|
|
1614
|
+
const context = tenant === void 0 ? authContext(auth) : {
|
|
1615
|
+
...authContext(auth),
|
|
1616
|
+
tenant
|
|
1617
|
+
};
|
|
1618
|
+
const clientHeaders = tenant === void 0 ? requestHeaders : {
|
|
1619
|
+
...requestHeaders,
|
|
1620
|
+
[TENANT_HEADER]: tenant
|
|
1621
|
+
};
|
|
1622
|
+
const headers = {
|
|
1623
|
+
...idPolicy.headers(ids),
|
|
1624
|
+
...clientHeaders
|
|
1625
|
+
};
|
|
1626
|
+
const sharesClient = auth.kind !== "user";
|
|
1627
|
+
const session = sessionWith(ids, tenant);
|
|
1628
|
+
const recorder = new StatsRecorder(parent);
|
|
1629
|
+
let supabase;
|
|
1630
|
+
let db;
|
|
1631
|
+
let sql;
|
|
1632
|
+
const sqlClaims = auth.kind === "user" ? auth.claims : auth.kind === "anon" ? { role: "anon" } : void 0;
|
|
1633
|
+
const client = () => supabase ??= supabaseFor(auth, sharesClient ? clientHeaders : headers);
|
|
1634
|
+
let replica;
|
|
1635
|
+
const replicaUrl = () => {
|
|
1636
|
+
const url = readUrl();
|
|
1637
|
+
if (url) replica ??= replicaState(until);
|
|
1638
|
+
return url;
|
|
1639
|
+
};
|
|
1640
|
+
return {
|
|
1641
|
+
...credentials,
|
|
1642
|
+
...ids,
|
|
1643
|
+
auth,
|
|
1644
|
+
resolution,
|
|
1645
|
+
get supabase() {
|
|
1646
|
+
return client();
|
|
1647
|
+
},
|
|
1648
|
+
get db() {
|
|
1649
|
+
if (db) return db;
|
|
1650
|
+
const url = replicaUrl();
|
|
1651
|
+
const rest = (sharesClient ? void 0 : supabase) ?? restAt(env().url, auth, headers);
|
|
1652
|
+
const connected = betterSupabase.connect(rest, context, {
|
|
1653
|
+
stats: recorder,
|
|
1654
|
+
...auth.kind === "invalid" ? { executor: refusingExecutor(auth.error) } : url && replica ? { executor: routedExecutor(postgrestExecutor(rest, executorOptions), postgrestExecutor(restAt(url, auth, headers), executorOptions), replica) } : tunedExecutor ? { executor: postgrestExecutor(rest, executorOptions) } : {}
|
|
1655
|
+
});
|
|
1656
|
+
db = withLazyClient(connected, client);
|
|
1657
|
+
return db;
|
|
1658
|
+
},
|
|
1659
|
+
get replica() {
|
|
1660
|
+
replicaUrl();
|
|
1661
|
+
return replica;
|
|
1662
|
+
},
|
|
1663
|
+
get sql() {
|
|
1664
|
+
if (!options.postgres || !sqlClaims) return;
|
|
1665
|
+
sql ??= sqlFor(sqlClaims, context, recorder, session);
|
|
1666
|
+
return sql;
|
|
1667
|
+
},
|
|
1668
|
+
stats: () => recorder.snapshot(),
|
|
1669
|
+
apply: (response) => withPrimaryPin(resolution.apply(response), replica, pinMs),
|
|
1670
|
+
cookies: () => {
|
|
1671
|
+
const pin = primaryCookieWrite(replica, pinMs);
|
|
1672
|
+
return pin ? [...resolution.cookies, pin] : resolution.cookies;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
};
|
|
1676
|
+
const fromResolution = (resolution, request, contextOptions, tenant) => contextFor(resolution, options.headers?.(request) ?? {}, contextOptions.stats, contextOptions.pinnedUntil ?? (readUrl() ? pinnedUntil(resolution.requestCookies) : 0), tenant, contextOptions.support, idPolicy.forRequest(request, contextOptions));
|
|
1677
|
+
const resolve = async (request, resolveOptions = {}) => {
|
|
1678
|
+
const claims = options.auth?.claims ?? betterSupabase.claimsSchema;
|
|
1679
|
+
const userMetadata = betterSupabase.userMetadataSchema;
|
|
1680
|
+
const resolution = await resolveAuth(request, {
|
|
1681
|
+
logger: betterSupabase.events.logger,
|
|
1682
|
+
...lite ? lite.auth() : options.auth,
|
|
1683
|
+
...claims ? { claims } : {},
|
|
1684
|
+
...userMetadata ? { userMetadata } : {},
|
|
1685
|
+
env: env(),
|
|
1686
|
+
...resolveOptions.refresh === void 0 ? {} : { refresh: resolveOptions.refresh },
|
|
1687
|
+
...resolveOptions.cookies === void 0 ? {} : { cookies: resolveOptions.cookies },
|
|
1688
|
+
...resolveOptions.checkSession ? { checkSession: true } : {},
|
|
1689
|
+
...resolveOptions.encode === void 0 ? {} : { cookie: {
|
|
1690
|
+
...options.auth?.cookie,
|
|
1691
|
+
encode: resolveOptions.encode
|
|
1692
|
+
} },
|
|
1693
|
+
onRefresh: (event) => {
|
|
1694
|
+
options.auth?.onRefresh?.(event);
|
|
1695
|
+
betterSupabase.events.emit("refresh", event);
|
|
1696
|
+
}
|
|
1697
|
+
});
|
|
1698
|
+
if (betterSupabase.events.has("auth")) {
|
|
1699
|
+
const { auth } = resolution;
|
|
1700
|
+
betterSupabase.events.emit("auth", {
|
|
1701
|
+
source: auth.kind === "user" ? auth.source === "cookie" ? "cookie" : "bearer" : auth.kind === "service" || auth.kind === "apiKey" ? "bearer" : "none",
|
|
1702
|
+
ok: auth.kind !== "invalid",
|
|
1703
|
+
...auth.kind === "user" ? {
|
|
1704
|
+
userId: auth.user.id,
|
|
1705
|
+
rawSource: auth.source
|
|
1706
|
+
} : {},
|
|
1707
|
+
...auth.kind === "anon" || auth.kind === "invalid" ? { reason: auth.reason } : {}
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
return resolution;
|
|
1711
|
+
};
|
|
1712
|
+
/** One context per request and `refresh`/`cookies` pair: Server Components ask repeatedly. */
|
|
1713
|
+
const contextMemo = /* @__PURE__ */ new WeakMap();
|
|
1714
|
+
const server = {
|
|
1715
|
+
get env() {
|
|
1716
|
+
return env();
|
|
1717
|
+
},
|
|
1718
|
+
events: betterSupabase.events,
|
|
1719
|
+
authorizer: options.authorizer,
|
|
1720
|
+
authorization: options.authorization,
|
|
1721
|
+
resolve,
|
|
1722
|
+
supabaseFor,
|
|
1723
|
+
dbFor: (auth, context, dbOptions) => dbOptions?.support ? supportContextFor({
|
|
1724
|
+
auth,
|
|
1725
|
+
cookies: [],
|
|
1726
|
+
headers: {},
|
|
1727
|
+
requestCookies: [],
|
|
1728
|
+
apply: (response) => response
|
|
1729
|
+
}, dbOptions.support, void 0, context?.tenant, {}).db : dbFor(auth, context),
|
|
1730
|
+
contextFor: (auth, contextOptions = {}) => contextFor({
|
|
1731
|
+
auth,
|
|
1732
|
+
cookies: [],
|
|
1733
|
+
headers: {},
|
|
1734
|
+
requestCookies: [],
|
|
1735
|
+
apply: (response) => response
|
|
1736
|
+
}, {}, contextOptions.stats, contextOptions.pinnedUntil, contextOptions.tenant, contextOptions.support, idPolicy.forRequest(void 0, contextOptions)),
|
|
1737
|
+
context(request, contextOptions = {}) {
|
|
1738
|
+
const { refresh, cookies, ...rest } = contextOptions;
|
|
1739
|
+
const key = Object.keys(rest).length === 0 ? `${String(refresh ?? false)}:${String(cookies ?? true)}` : void 0;
|
|
1740
|
+
let byOptions = key ? contextMemo.get(request) : void 0;
|
|
1741
|
+
const known = key ? byOptions?.get(key) : void 0;
|
|
1742
|
+
if (known) return known;
|
|
1743
|
+
const resolving = (async () => {
|
|
1744
|
+
const call = { options: contextOptions };
|
|
1745
|
+
await fold(request, {
|
|
1746
|
+
...seedContext(),
|
|
1747
|
+
[CALL]: call
|
|
1748
|
+
});
|
|
1749
|
+
return call.context;
|
|
1750
|
+
})();
|
|
1751
|
+
if (key) {
|
|
1752
|
+
if (!byOptions) {
|
|
1753
|
+
byOptions = /* @__PURE__ */ new Map();
|
|
1754
|
+
contextMemo.set(request, byOptions);
|
|
1755
|
+
}
|
|
1756
|
+
const memo = byOptions;
|
|
1757
|
+
memo.set(key, resolving);
|
|
1758
|
+
resolving.catch(() => {
|
|
1759
|
+
if (memo.get(key) === resolving) memo.delete(key);
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
return resolving;
|
|
1763
|
+
},
|
|
1764
|
+
contextFromResolution: (resolution, request, contextOptions = {}) => fromResolution(resolution, request, contextOptions, contextOptions.tenant ?? syncTenant(request, resolution.auth)),
|
|
1765
|
+
admin: (context = {}) => {
|
|
1766
|
+
const client = serviceClient();
|
|
1767
|
+
return betterSupabase.connect(client, {
|
|
1768
|
+
actor: {
|
|
1769
|
+
id: "service",
|
|
1770
|
+
kind: "service",
|
|
1771
|
+
role: "service_role"
|
|
1772
|
+
},
|
|
1773
|
+
claims: { role: "service_role" },
|
|
1774
|
+
...context
|
|
1775
|
+
}, tunedExecutor ? { executor: postgrestExecutor(client, executorOptions) } : {});
|
|
1776
|
+
},
|
|
1777
|
+
support,
|
|
1778
|
+
deleteAccount: (userId, deleteOptions) => deleteAccount(betterSupabase, serviceClient, userId, {
|
|
1779
|
+
...options.postgres ? { sql: options.postgres.admin } : {},
|
|
1780
|
+
...deleteOptions
|
|
1781
|
+
}).map((deleted) => {
|
|
1782
|
+
audit.account("account.deleted", userId, { removed: deleted.removed });
|
|
1783
|
+
return deleted;
|
|
1784
|
+
}),
|
|
1785
|
+
endSessions: (userId) => options.postgres ? endSessions(options.postgres.admin, userId).map((ended) => {
|
|
1786
|
+
audit.account("account.sessions_ended", userId, { ended: ended.ended });
|
|
1787
|
+
return ended;
|
|
1788
|
+
}) : AsyncResult.err(needsPostgres("endSessions")),
|
|
1789
|
+
suspendAccount: (userId, suspendOptions) => options.postgres ? suspendAccount(serviceClient, options.postgres.admin, userId, suspendOptions).map((suspended) => {
|
|
1790
|
+
audit.account(suspended.suspended ? "account.suspended" : "account.unsuspended", userId, {
|
|
1791
|
+
ended: suspended.ended,
|
|
1792
|
+
...suspendOptions.duration === void 0 ? {} : { duration: suspendOptions.duration }
|
|
1793
|
+
});
|
|
1794
|
+
return suspended;
|
|
1795
|
+
}) : AsyncResult.err(needsPostgres("suspendAccount")),
|
|
1796
|
+
actingAs: (userId, claims = {}, impersonation) => {
|
|
1797
|
+
const full = {
|
|
1798
|
+
role: "authenticated",
|
|
1799
|
+
...claims,
|
|
1800
|
+
sub: userId,
|
|
1801
|
+
...impersonation ? { act: actClaim(impersonation) } : {}
|
|
1802
|
+
};
|
|
1803
|
+
return sqlFor(full, {
|
|
1804
|
+
actor: {
|
|
1805
|
+
id: userId,
|
|
1806
|
+
kind: "user",
|
|
1807
|
+
role: full.role ?? "authenticated",
|
|
1808
|
+
...impersonation ? { impersonator: impersonation.actor } : {}
|
|
1809
|
+
},
|
|
1810
|
+
claims: full
|
|
1811
|
+
});
|
|
1812
|
+
},
|
|
1813
|
+
forContext: (context, forOptions = {}) => AsyncResult.from(async () => {
|
|
1814
|
+
const subject = await ticketSubject(context, forOptions.ticket ?? options.authorization?.tickets?.subject);
|
|
1815
|
+
if (!subject.ok) return subject;
|
|
1816
|
+
const target = subject.data;
|
|
1817
|
+
const { tenant } = target;
|
|
1818
|
+
const checked = contextClaims(target);
|
|
1819
|
+
if (!checked.ok) return err(dbError("forbidden", checked.message));
|
|
1820
|
+
if (!options.postgres) return err(dbError("invalid_request", "Direct Postgres access needs createServer(betterSupabase, { postgres: createPostgres() })"));
|
|
1821
|
+
const userId = checked.claims.sub;
|
|
1822
|
+
const extra = await options.claimsFor?.(userId, target) ?? {};
|
|
1823
|
+
const permissions = narrowCap(await delegationCap(target, userId, options.authorization?.delegation?.permissions), forOptions.permissions);
|
|
1824
|
+
const built = contextClaims(target, {
|
|
1825
|
+
extra,
|
|
1826
|
+
...forOptions.reason === void 0 ? {} : { reason: forOptions.reason },
|
|
1827
|
+
...permissions === void 0 ? {} : { permissions }
|
|
1828
|
+
});
|
|
1829
|
+
if (!built.ok) return err(dbError("forbidden", built.message));
|
|
1830
|
+
const { claims, impersonator, readOnly } = built;
|
|
1831
|
+
const session = sessionWith({}, tenant, readOnly);
|
|
1832
|
+
return ok(sqlFor(claims, {
|
|
1833
|
+
actor: {
|
|
1834
|
+
id: userId,
|
|
1835
|
+
kind: "user",
|
|
1836
|
+
role: "authenticated",
|
|
1837
|
+
...impersonator ? { impersonator } : {}
|
|
1838
|
+
},
|
|
1839
|
+
claims,
|
|
1840
|
+
...tenant === void 0 ? {} : { tenant }
|
|
1841
|
+
}, void 0, session));
|
|
1842
|
+
})
|
|
1843
|
+
};
|
|
1844
|
+
const core = {
|
|
1845
|
+
events: betterSupabase.events,
|
|
1846
|
+
pinMs,
|
|
1847
|
+
resolve,
|
|
1848
|
+
sessionCookie: () => options.auth?.cookie?.name ?? sessionCookieName(env().url),
|
|
1849
|
+
tenant: (request, auth) => options.tenant?.(request, auth),
|
|
1850
|
+
support: (request, auth) => support.current(request, auth),
|
|
1851
|
+
context: (resolution, request, contextOptions, tenant) => fromResolution(resolution, request, contextOptions, tenant)
|
|
1852
|
+
};
|
|
1853
|
+
registerCore(server, core);
|
|
1854
|
+
const fold = pipeline([
|
|
1855
|
+
withSession(core),
|
|
1856
|
+
withTenant(core),
|
|
1857
|
+
withSupport(core),
|
|
1858
|
+
withServerContext(core)
|
|
1859
|
+
], (_request, ctx) => {
|
|
1860
|
+
const call = callOf(ctx);
|
|
1861
|
+
if (call) call.context = ctx.bs;
|
|
1862
|
+
return Promise.resolve(new Response(null, { status: 204 }));
|
|
1863
|
+
});
|
|
1864
|
+
return server;
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* The permission keys the provider's `delegation.permissions` hook grants a
|
|
1868
|
+
* delegated context, `undefined` for a context that is not delegated or
|
|
1869
|
+
* without the hook. A throw or an answer that is not a list of strings
|
|
1870
|
+
* grants nothing.
|
|
1871
|
+
*/
|
|
1872
|
+
async function delegationCap(context, userId, permissions) {
|
|
1873
|
+
if (permissions === void 0) return;
|
|
1874
|
+
const delegated = delegatedClaims(context.claims ?? {});
|
|
1875
|
+
if (!delegated.ok || delegated.delegation === void 0) return;
|
|
1876
|
+
const { client_id, scope, authorization_details } = delegated.delegation;
|
|
1877
|
+
try {
|
|
1878
|
+
const keys = await permissions({
|
|
1879
|
+
userId,
|
|
1880
|
+
...context.tenant === void 0 ? {} : { tenant: context.tenant },
|
|
1881
|
+
...client_id === void 0 ? {} : { clientId: client_id },
|
|
1882
|
+
scopes: scope === void 0 ? [] : scope.split(" "),
|
|
1883
|
+
...authorization_details === void 0 ? {} : { authorizationDetails: authorization_details }
|
|
1884
|
+
});
|
|
1885
|
+
return Array.isArray(keys) && keys.every((key) => typeof key === "string") ? keys : [];
|
|
1886
|
+
} catch {
|
|
1887
|
+
return [];
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* The context `forContext` runs as: `context` itself, or for a context
|
|
1892
|
+
* with a ticket, the context `resolve` returns for it. A ticket without a
|
|
1893
|
+
* resolver, a `null` answer and a throw are `forbidden`; none of them fall
|
|
1894
|
+
* back to the recorded actor.
|
|
1895
|
+
*/
|
|
1896
|
+
async function ticketSubject(context, resolve) {
|
|
1897
|
+
const ticket = context["ticket"];
|
|
1898
|
+
if (ticket === void 0) return ok(context);
|
|
1899
|
+
if (typeof ticket !== "string" || ticket === "") return err(dbError("forbidden", "forContext got an invalid ticket"));
|
|
1900
|
+
if (resolve === void 0) return err(dbError("forbidden", "forContext got a ticket but no ticket resolver: pass { ticket } or authorization.tickets.subject"));
|
|
1901
|
+
let resolved;
|
|
1902
|
+
try {
|
|
1903
|
+
resolved = await resolve(ticket);
|
|
1904
|
+
} catch {
|
|
1905
|
+
resolved = null;
|
|
1906
|
+
}
|
|
1907
|
+
if (typeof resolved !== "object" || resolved === null) return err(dbError("forbidden", "The ticket resolver refused the ticket"));
|
|
1908
|
+
return ok(resolved);
|
|
1909
|
+
}
|
|
1910
|
+
//#endregion
|
|
1911
|
+
//#region src/server/adapter.ts
|
|
1912
|
+
/** Hands event sink sends still running to `waitUntil`; a no-op without either. */
|
|
1913
|
+
function flushEvents(server, waitUntil) {
|
|
1914
|
+
if (waitUntil && server.events.pending) waitUntil(server.events.settled());
|
|
1915
|
+
}
|
|
1916
|
+
/** Runs `run`, then hands pending event sink sends to `waitUntil` even when it throws. */
|
|
1917
|
+
async function withFlush(server, waitUntil, run) {
|
|
1918
|
+
try {
|
|
1919
|
+
return await run();
|
|
1920
|
+
} finally {
|
|
1921
|
+
flushEvents(server, waitUntil);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
/** The 500 for an error a handler threw; the message only when `expose` is set. */
|
|
1925
|
+
function unexpectedResponse(cause, options) {
|
|
1926
|
+
return problemResponse(dbError("unexpected", options.expose && cause instanceof Error ? cause.message : "Internal server error"), options);
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* Runs `run` as the request's caller, the way every built-in adapter does:
|
|
1930
|
+
* resolves the context, applies the guard (401/403 Problem Details), turns
|
|
1931
|
+
* the return value into a response with `respond()`, turns other thrown
|
|
1932
|
+
* errors into a 500, adds the context's cookies with `ctx.apply()` and
|
|
1933
|
+
* hands pending event sink sends to `waitUntil`.
|
|
1934
|
+
*
|
|
1935
|
+
* ```ts
|
|
1936
|
+
* export default { fetch: (request, env, ctx) =>
|
|
1937
|
+
* handle(server, request, (c) => c.db.notes.findMany(), { waitUntil: (p) => ctx.waitUntil(p) }) }
|
|
1938
|
+
* ```
|
|
1939
|
+
*/
|
|
1940
|
+
async function handle(server, request, run, options = {}) {
|
|
1941
|
+
const expose = options.expose ?? defaultExpose();
|
|
1942
|
+
const instance = options.instance ?? new URL(request.url).pathname;
|
|
1943
|
+
const ctx = await server.context(request, {
|
|
1944
|
+
...options.context,
|
|
1945
|
+
refresh: refreshFor(options.refresh, request) ?? false
|
|
1946
|
+
});
|
|
1947
|
+
const denied = guard(ctx.auth, options.allow, options.aal, options.scopes);
|
|
1948
|
+
try {
|
|
1949
|
+
let response;
|
|
1950
|
+
try {
|
|
1951
|
+
response = denied ? problemResponse(denied, {
|
|
1952
|
+
instance,
|
|
1953
|
+
expose
|
|
1954
|
+
}) : await respond(() => run(ctx), {
|
|
1955
|
+
instance,
|
|
1956
|
+
expose,
|
|
1957
|
+
...options.status === void 0 ? {} : { status: options.status }
|
|
1958
|
+
});
|
|
1959
|
+
} catch (cause) {
|
|
1960
|
+
options.rethrow?.(cause);
|
|
1961
|
+
response = unexpectedResponse(cause, {
|
|
1962
|
+
instance,
|
|
1963
|
+
expose
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
return ctx.apply(response);
|
|
1967
|
+
} finally {
|
|
1968
|
+
flushEvents(server, options.waitUntil);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
/** A request carrying only `token` as a bearer, for resolvers that read headers. */
|
|
1972
|
+
function bearerRequest(token) {
|
|
1973
|
+
return new Request("http://localhost/", { headers: token ? { authorization: `Bearer ${token}` } : {} });
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Verifies a bare access token (an MCP transport's, a WebSocket's) without
|
|
1977
|
+
* cookies or a refresh. An empty token resolves to `anon`.
|
|
1978
|
+
*/
|
|
1979
|
+
async function resolveToken(server, token) {
|
|
1980
|
+
const { auth } = await server.resolve(bearerRequest(token), { cookies: false });
|
|
1981
|
+
return auth;
|
|
1982
|
+
}
|
|
1983
|
+
//#endregion
|
|
1984
|
+
export { suspendAccount as A, shouldRefresh as C, SERVER_EVENT_SOURCE as D, defineAuthorizationHooks as E, endSessions as O, shouldCheckSession as S, serverCore as T, withSupport as _, unexpectedResponse as a, isPrefetch as b, extendServer as c, clearSupportCookie as d, supportCookie as f, withTenant as g, TENANT_HEADER as h, resolveToken as i, deleteAccount as j, lastSignIns as k, supportStorage as l, supportCookieValue as m, flushEvents as n, withFlush as o, supportCookieMaxAge as p, handle as r, createServer as s, bearerRequest as t, SUPPORT_COOKIE as u, outageResponse as v, withServerContext as w, refreshFor as x, withSession as y };
|