@donotdev/functions 0.0.19 → 0.1.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/LICENSE.md +3 -3
- package/lib/firebase/auth/getCustomClaims.d.ts +25 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +29 -0
- package/lib/firebase/auth/index.d.ts +12 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +28 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +34 -0
- package/lib/firebase/baseFunction.d.ts +26 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +10 -0
- package/lib/firebase/billing/changePlan.d.ts +13 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +21 -0
- package/lib/firebase/billing/createCustomerPortal.d.ts +19 -0
- package/lib/firebase/billing/healthCheck.d.ts +5 -0
- package/lib/firebase/billing/index.d.ts +18 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +19 -0
- package/lib/firebase/billing/webhookHandler.d.ts +6 -0
- package/lib/firebase/config/constants.d.ts +89 -0
- package/lib/firebase/config/index.d.ts +9 -0
- package/lib/firebase/config/secrets.d.ts +15 -0
- package/lib/firebase/crud/aggregate.d.ts +98 -0
- package/lib/firebase/crud/create.d.ts +16 -0
- package/lib/firebase/crud/delete.d.ts +20 -0
- package/lib/firebase/crud/get.d.ts +24 -0
- package/lib/firebase/crud/index.d.ts +14 -0
- package/lib/firebase/crud/list.d.ts +25 -0
- package/lib/firebase/crud/update.d.ts +25 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +30 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +36 -0
- package/lib/firebase/helpers/index.d.ts +10 -0
- package/lib/firebase/index.d.ts +17 -0
- package/lib/firebase/index.js +25 -9110
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +12 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +9 -0
- package/lib/firebase/oauth/getConnections.d.ts +11 -0
- package/lib/firebase/oauth/githubAccess.d.ts +83 -0
- package/lib/firebase/oauth/index.d.ts +13 -0
- package/lib/firebase/oauth/refreshToken.d.ts +9 -0
- package/lib/firebase/registerCrudFunctions.d.ts +32 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +14 -0
- package/lib/firebase/scheduled/index.d.ts +9 -0
- package/lib/shared/billing/createCheckout.d.ts +50 -0
- package/lib/shared/billing/helpers/index.d.ts +10 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +34 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +45 -0
- package/lib/shared/billing/idempotency.d.ts +22 -0
- package/lib/shared/billing/index.d.ts +11 -0
- package/lib/shared/billing/webhookHandler.d.ts +37 -0
- package/lib/shared/errorHandling.d.ts +14 -0
- package/lib/shared/firebase.d.ts +73 -0
- package/lib/shared/github.d.ts +128 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +25 -6927
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +133 -0
- package/lib/shared/metadata.d.ts +36 -0
- package/lib/shared/oauth/exchangeToken.d.ts +24 -0
- package/lib/shared/oauth/grantAccess.d.ts +30 -0
- package/lib/shared/oauth/index.d.ts +10 -0
- package/lib/shared/schema.d.ts +56 -0
- package/lib/shared/utils/detectFirestore.d.ts +31 -0
- package/lib/shared/utils/external/date.d.ts +36 -0
- package/lib/shared/utils/external/index.d.ts +11 -0
- package/lib/shared/utils/external/references.d.ts +12 -0
- package/lib/shared/utils/external/subscription.d.ts +41 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +23 -0
- package/lib/shared/utils/functionWrapper.d.ts +36 -0
- package/lib/shared/utils/index.d.ts +14 -0
- package/lib/shared/utils/internal/auth.d.ts +57 -0
- package/lib/shared/utils/internal/firebase.d.ts +5 -0
- package/lib/shared/utils/internal/idempotency.d.ts +21 -0
- package/lib/shared/utils/internal/index.d.ts +14 -0
- package/lib/shared/utils/internal/monitoring.d.ts +80 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +82 -0
- package/lib/shared/utils/internal/validation.d.ts +43 -0
- package/lib/shared/utils/schemaValidation.d.ts +60 -0
- package/lib/shared/utils/validation.d.ts +98 -0
- package/lib/shared/utils/vercelHelpers.d.ts +18 -0
- package/lib/shared/utils.d.ts +234 -0
- package/lib/shared/validation.d.ts +16 -0
- package/lib/supabase/auth/deleteAccount.d.ts +16 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +18 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +18 -0
- package/lib/supabase/baseFunction.d.ts +43 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +9 -0
- package/lib/supabase/billing/changePlan.d.ts +11 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +11 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +9 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +9 -0
- package/lib/supabase/crud/aggregate.d.ts +27 -0
- package/lib/supabase/crud/create.d.ts +23 -0
- package/lib/supabase/crud/delete.d.ts +30 -0
- package/lib/supabase/crud/get.d.ts +23 -0
- package/lib/supabase/crud/index.d.ts +20 -0
- package/lib/supabase/crud/list.d.ts +33 -0
- package/lib/supabase/crud/update.d.ts +24 -0
- package/lib/supabase/helpers/authProvider.d.ts +22 -0
- package/lib/supabase/index.d.ts +30 -0
- package/lib/supabase/index.js +23 -0
- package/lib/supabase/index.js.map +7 -0
- package/lib/supabase/oauth/disconnect.d.ts +13 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +13 -0
- package/lib/supabase/oauth/getConnections.d.ts +13 -0
- package/lib/supabase/oauth/index.d.ts +12 -0
- package/lib/supabase/oauth/refreshToken.d.ts +13 -0
- package/lib/supabase/registerCrudFunctions.d.ts +24 -0
- package/lib/supabase/utils/idempotency.d.ts +36 -0
- package/lib/supabase/utils/monitoring.d.ts +59 -0
- package/lib/supabase/utils/rateLimiter.d.ts +56 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +2 -0
- package/lib/vercel/api/auth/index.d.ts +12 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +10 -0
- package/lib/vercel/api/billing/cancel.d.ts +10 -0
- package/lib/vercel/api/billing/change-plan.d.ts +11 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +13 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +3 -0
- package/lib/vercel/api/billing/index.d.ts +14 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +31 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +22 -0
- package/lib/vercel/api/config/constants.d.ts +103 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +19 -0
- package/lib/vercel/api/config/index.d.ts +10 -0
- package/lib/vercel/api/crud/create.d.ts +2 -0
- package/lib/vercel/api/crud/delete.d.ts +2 -0
- package/lib/vercel/api/crud/get.d.ts +2 -0
- package/lib/vercel/api/crud/index.d.ts +13 -0
- package/lib/vercel/api/crud/list.d.ts +2 -0
- package/lib/vercel/api/crud/update.d.ts +2 -0
- package/lib/vercel/api/index.d.ts +13 -0
- package/lib/vercel/api/index.js +22 -4790
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/index.d.ts +12 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +11 -0
- package/lib/vercel/api/utils/cors.d.ts +49 -0
- package/lib/vercel/baseFunction.d.ts +25 -0
- package/package.json +4 -4
- package/src/firebase/auth/getCustomClaims.ts +3 -3
- package/src/firebase/auth/getUserAuthStatus.ts +3 -3
- package/src/firebase/auth/index.ts +1 -1
- package/src/firebase/auth/removeCustomClaims.ts +3 -3
- package/src/firebase/auth/setCustomClaims.ts +130 -84
- package/src/firebase/baseFunction.ts +2 -2
- package/src/firebase/billing/cancelSubscription.ts +3 -3
- package/src/firebase/billing/changePlan.ts +3 -3
- package/src/firebase/billing/createCheckoutSession.ts +1 -1
- package/src/firebase/billing/createCustomerPortal.ts +1 -1
- package/src/firebase/billing/healthCheck.ts +8 -24
- package/src/firebase/billing/index.d.ts +11 -11
- package/src/firebase/billing/index.ts +1 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -3
- package/src/firebase/billing/webhookHandler.ts +1 -2
- package/src/firebase/config/constants.ts +4 -4
- package/src/firebase/config/index.ts +1 -1
- package/src/firebase/config/secrets.ts +1 -1
- package/src/firebase/crud/aggregate.ts +2 -2
- package/src/firebase/crud/create.ts +19 -4
- package/src/firebase/crud/delete.ts +3 -3
- package/src/firebase/crud/get.ts +1 -1
- package/src/firebase/crud/index.ts +1 -1
- package/src/firebase/crud/list.ts +1 -1
- package/src/firebase/crud/update.ts +2 -2
- package/src/firebase/helpers/githubAccessHelper.ts +4 -4
- package/src/firebase/helpers/githubTeamAccessHelper.ts +3 -3
- package/src/firebase/helpers/index.ts +1 -1
- package/src/firebase/index.d.ts +9 -9
- package/src/firebase/index.ts +1 -1
- package/src/firebase/oauth/disconnect.ts +2 -2
- package/src/firebase/oauth/exchangeToken.ts +7 -7
- package/src/firebase/oauth/getConnections.ts +2 -2
- package/src/firebase/oauth/githubAccess.ts +10 -10
- package/src/firebase/oauth/index.ts +1 -1
- package/src/firebase/oauth/refreshToken.ts +2 -2
- package/src/firebase/registerCrudFunctions.ts +1 -1
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +1 -1
- package/src/firebase/scheduled/index.ts +1 -1
- package/src/shared/__tests__/auth.test.ts +46 -0
- package/src/shared/__tests__/errorHandling.test.ts +66 -1
- package/src/shared/__tests__/firebase.test.ts +293 -0
- package/src/shared/__tests__/internalValidation.test.ts +190 -0
- package/src/shared/__tests__/metadata.test.ts +66 -0
- package/src/shared/__tests__/schema.test.ts +219 -0
- package/src/shared/__tests__/schemaValidation.test.ts +72 -0
- package/src/shared/__tests__/subscription.test.ts +45 -0
- package/src/shared/__tests__/utils.test.ts +281 -0
- package/src/shared/__tests__/validation-env.test.ts +73 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +1 -1
- package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -1
- package/src/shared/billing/createCheckout.ts +10 -5
- package/src/shared/billing/helpers/index.ts +1 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +4 -4
- package/src/shared/billing/helpers/updateUserSubscription.ts +4 -4
- package/src/shared/billing/idempotency.ts +4 -4
- package/src/shared/billing/index.ts +1 -1
- package/src/shared/billing/webhookHandler.ts +7 -7
- package/src/shared/errorHandling.ts +2 -2
- package/src/shared/firebase.ts +7 -7
- package/src/shared/github.ts +11 -11
- package/src/shared/index.d.ts +9 -9
- package/src/shared/index.ts +1 -1
- package/src/shared/logger.ts +8 -8
- package/src/shared/metadata.ts +3 -3
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +1 -1
- package/src/shared/oauth/exchangeToken.ts +2 -2
- package/src/shared/oauth/grantAccess.ts +2 -2
- package/src/shared/oauth/index.ts +1 -1
- package/src/shared/schema.ts +4 -4
- package/src/shared/utils/__tests__/functionWrapper.test.ts +1 -1
- package/src/shared/utils/detectFirestore.ts +3 -3
- package/src/shared/utils/external/date.ts +5 -5
- package/src/shared/utils/external/index.ts +1 -1
- package/src/shared/utils/external/references.ts +2 -2
- package/src/shared/utils/external/subscription.ts +5 -5
- package/src/shared/utils/firebaseHelpers.ts +3 -3
- package/src/shared/utils/functionWrapper.ts +4 -4
- package/src/shared/utils/index.ts +1 -1
- package/src/shared/utils/internal/auth.ts +7 -7
- package/src/shared/utils/internal/firebase.ts +1 -1
- package/src/shared/utils/internal/idempotency.ts +3 -3
- package/src/shared/utils/internal/index.ts +1 -1
- package/src/shared/utils/internal/monitoring.ts +8 -8
- package/src/shared/utils/internal/rateLimiter.ts +6 -6
- package/src/shared/utils/internal/validation.ts +6 -6
- package/src/shared/utils/schemaValidation.ts +6 -6
- package/src/shared/utils/validation.ts +10 -10
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +19 -19
- package/src/shared/validation.ts +2 -2
- package/src/supabase/auth/deleteAccount.ts +2 -2
- package/src/supabase/auth/getCustomClaims.ts +2 -2
- package/src/supabase/auth/getUserAuthStatus.ts +2 -2
- package/src/supabase/auth/removeCustomClaims.ts +2 -2
- package/src/supabase/auth/setCustomClaims.ts +2 -2
- package/src/supabase/baseFunction.ts +3 -3
- package/src/supabase/billing/cancelSubscription.ts +2 -2
- package/src/supabase/billing/changePlan.ts +2 -2
- package/src/supabase/billing/createCheckoutSession.ts +2 -2
- package/src/supabase/billing/createCustomerPortal.ts +2 -2
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -2
- package/src/supabase/crud/aggregate.ts +11 -8
- package/src/supabase/crud/create.ts +2 -2
- package/src/supabase/crud/delete.ts +1 -1
- package/src/supabase/crud/get.ts +2 -2
- package/src/supabase/crud/index.ts +1 -1
- package/src/supabase/crud/list.ts +2 -2
- package/src/supabase/crud/update.ts +2 -2
- package/src/supabase/helpers/authProvider.ts +2 -2
- package/src/supabase/index.ts +10 -2
- package/src/supabase/oauth/disconnect.ts +104 -0
- package/src/supabase/oauth/exchangeToken.ts +152 -0
- package/src/supabase/oauth/getConnections.ts +85 -0
- package/src/supabase/oauth/index.ts +15 -0
- package/src/supabase/oauth/refreshToken.ts +131 -0
- package/src/supabase/registerCrudFunctions.ts +1 -1
- package/src/supabase/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -1
- package/src/supabase/utils/rateLimiter.ts +1 -1
- package/src/vercel/api/auth/get-custom-claims.ts +1 -1
- package/src/vercel/api/auth/get-user-auth-status.ts +1 -1
- package/src/vercel/api/auth/index.ts +1 -1
- package/src/vercel/api/auth/remove-custom-claims.ts +1 -1
- package/src/vercel/api/auth/set-custom-claims.ts +69 -24
- package/src/vercel/api/billing/cancel.ts +3 -3
- package/src/vercel/api/billing/change-plan.ts +3 -3
- package/src/vercel/api/billing/create-checkout-session.ts +3 -3
- package/src/vercel/api/billing/customer-portal.ts +1 -1
- package/src/vercel/api/billing/index.ts +1 -1
- package/src/vercel/api/billing/refresh-subscription-status.ts +1 -1
- package/src/vercel/api/billing/webhook-handler.ts +3 -3
- package/src/vercel/api/config/constants.ts +9 -9
- package/src/vercel/api/config/firebase-admin.ts +3 -3
- package/src/vercel/api/config/index.ts +1 -1
- package/src/vercel/api/crud/create.ts +1 -1
- package/src/vercel/api/crud/delete.ts +1 -1
- package/src/vercel/api/crud/get.ts +1 -1
- package/src/vercel/api/crud/index.ts +1 -1
- package/src/vercel/api/crud/list.ts +1 -1
- package/src/vercel/api/crud/update.ts +1 -1
- package/src/vercel/api/index.d.ts +1 -1
- package/src/vercel/api/index.ts +1 -1
- package/src/vercel/api/oauth/check-github-access.ts +3 -3
- package/src/vercel/api/oauth/exchange-token.ts +1 -1
- package/src/vercel/api/oauth/grant-github-access.ts +3 -3
- package/src/vercel/api/oauth/index.ts +1 -1
- package/src/vercel/api/oauth/revoke-github-access.ts +1 -1
- package/src/vercel/api/utils/cors.ts +4 -4
- package/src/vercel/baseFunction.ts +2 -2
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Cancel Subscription — Supabase Edge Function
|
|
5
5
|
* @description Wraps the shared `cancelUserSubscription` for Supabase.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -33,7 +33,7 @@ const cancelSubscriptionSchema = v.object({
|
|
|
33
33
|
*
|
|
34
34
|
* @returns `(req: Request) => Promise<Response>` handler
|
|
35
35
|
*
|
|
36
|
-
* @version 0.0
|
|
36
|
+
* @version 0.1.0
|
|
37
37
|
* @since 0.5.0
|
|
38
38
|
*/
|
|
39
39
|
export function createCancelSubscription() {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Change Plan — Supabase Edge Function
|
|
5
5
|
* @description Wraps the shared `changeUserPlan` for Supabase.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -41,7 +41,7 @@ const changePlanSchema = v.object({
|
|
|
41
41
|
* @param billingConfig - Billing configuration with product definitions
|
|
42
42
|
* @returns `(req: Request) => Promise<Response>` handler
|
|
43
43
|
*
|
|
44
|
-
* @version 0.0
|
|
44
|
+
* @version 0.1.0
|
|
45
45
|
* @since 0.5.0
|
|
46
46
|
*/
|
|
47
47
|
export function createChangePlan(billingConfig: StripeBackConfig) {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Create Checkout Session — Supabase Edge Function
|
|
5
5
|
* @description Wraps the shared `createCheckoutAlgorithm` for Supabase.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -32,7 +32,7 @@ import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
|
|
|
32
32
|
* @param billingConfig - Billing configuration with product definitions
|
|
33
33
|
* @returns `(req: Request) => Promise<Response>` handler
|
|
34
34
|
*
|
|
35
|
-
* @version 0.0
|
|
35
|
+
* @version 0.1.0
|
|
36
36
|
* @since 0.5.0
|
|
37
37
|
*/
|
|
38
38
|
export function createCheckoutSession(billingConfig: StripeBackConfig) {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Create Customer Portal — Supabase Edge Function
|
|
5
5
|
* @description Wraps the shared `createCustomerPortalSession` for Supabase.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -34,7 +34,7 @@ const customerPortalSchema = v.object({
|
|
|
34
34
|
*
|
|
35
35
|
* @returns `(req: Request) => Promise<Response>` handler
|
|
36
36
|
*
|
|
37
|
-
* @version 0.0
|
|
37
|
+
* @version 0.1.0
|
|
38
38
|
* @since 0.5.0
|
|
39
39
|
*/
|
|
40
40
|
export function createCustomerPortal() {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Refresh Subscription Status — Supabase Edge Function
|
|
5
5
|
* @description Direct Stripe lookup + claim update via Supabase Admin.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -38,7 +38,7 @@ const refreshSubscriptionSchema = v.object({
|
|
|
38
38
|
*
|
|
39
39
|
* @returns `(req: Request) => Promise<Response>` handler
|
|
40
40
|
*
|
|
41
|
-
* @version 0.0
|
|
41
|
+
* @version 0.1.0
|
|
42
42
|
* @since 0.5.0
|
|
43
43
|
*/
|
|
44
44
|
export function createRefreshSubscriptionStatus() {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Generic handler to aggregate entities in Supabase.
|
|
5
5
|
* @description Provides aggregate operations (COUNT, SUM, AVG, MIN, MAX, GROUP BY) for PostgreSQL.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import * as v from 'valibot';
|
|
13
13
|
|
|
14
14
|
import type { UserRole } from '@donotdev/core/server';
|
|
15
|
-
import { defaultFieldMapper } from '@donotdev/supabase';
|
|
15
|
+
import { defaultFieldMapper } from '@donotdev/supabase/server';
|
|
16
16
|
|
|
17
17
|
import { DoNotDevError } from '../../shared/utils.js';
|
|
18
18
|
import { createSupabaseHandler } from '../baseFunction.js';
|
|
@@ -88,7 +88,8 @@ export function createSupabaseAggregateEntities(
|
|
|
88
88
|
const { supabaseAdmin } = ctx;
|
|
89
89
|
|
|
90
90
|
const aggregateColumn = mapper.toBackendField(aggregate.field);
|
|
91
|
-
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Dynamic aggregate builder; Supabase types change across chained calls
|
|
92
|
+
let query: any = supabaseAdmin.from(collection);
|
|
92
93
|
|
|
93
94
|
for (const [field, operator, value] of where) {
|
|
94
95
|
query = applyOperator(
|
|
@@ -143,9 +144,9 @@ export function createSupabaseAggregateEntities(
|
|
|
143
144
|
} else {
|
|
144
145
|
// Calculate aggregate from rows
|
|
145
146
|
const values = (rows || ([] as any[]))
|
|
146
|
-
.map((row) => row[aggregateColumn])
|
|
147
|
-
.filter((v) => v != null && !isNaN(Number(v)))
|
|
148
|
-
.map((v) => Number(v));
|
|
147
|
+
.map((row: any) => row[aggregateColumn])
|
|
148
|
+
.filter((v: any) => v != null && !isNaN(Number(v)))
|
|
149
|
+
.map((v: any) => Number(v));
|
|
149
150
|
|
|
150
151
|
if (values.length === 0) {
|
|
151
152
|
return { value: 0 };
|
|
@@ -154,10 +155,12 @@ export function createSupabaseAggregateEntities(
|
|
|
154
155
|
let result: number;
|
|
155
156
|
switch (aggregate.operation) {
|
|
156
157
|
case 'sum':
|
|
157
|
-
result = values.reduce((a, b) => a + b, 0);
|
|
158
|
+
result = values.reduce((a: number, b: number) => a + b, 0);
|
|
158
159
|
break;
|
|
159
160
|
case 'avg':
|
|
160
|
-
result =
|
|
161
|
+
result =
|
|
162
|
+
values.reduce((a: number, b: number) => a + b, 0) /
|
|
163
|
+
values.length;
|
|
161
164
|
break;
|
|
162
165
|
case 'min':
|
|
163
166
|
result = Math.min(...values);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Generic handler to create an entity in Supabase.
|
|
5
5
|
* @description Provides a reusable implementation for creating documents in PostgreSQL with validation.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
filterVisibleFields,
|
|
17
17
|
} from '@donotdev/core/server';
|
|
18
18
|
import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
|
|
19
|
-
import { defaultFieldMapper } from '@donotdev/supabase';
|
|
19
|
+
import { defaultFieldMapper } from '@donotdev/supabase/server';
|
|
20
20
|
|
|
21
21
|
import { createMetadata } from '../../shared/index.js';
|
|
22
22
|
import { DoNotDevError, validateDocument } from '../../shared/utils.js';
|
package/src/supabase/crud/get.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Generic handler to retrieve a single entity from Supabase.
|
|
5
5
|
* @description Provides a reusable implementation for retrieving documents from PostgreSQL with visibility filtering.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
createEntityAwareMapper,
|
|
22
22
|
defaultFieldMapper,
|
|
23
23
|
getEntityFieldNames,
|
|
24
|
-
} from '@donotdev/supabase';
|
|
24
|
+
} from '@donotdev/supabase/server';
|
|
25
25
|
|
|
26
26
|
import { DoNotDevError } from '../../shared/utils.js';
|
|
27
27
|
import { createSupabaseHandler } from '../baseFunction.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Generic handler to list entities from Supabase with pagination, filtering, and sorting.
|
|
5
5
|
* @description Provides a reusable implementation for listing documents from PostgreSQL with advanced query capabilities.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
createEntityAwareMapper,
|
|
26
26
|
defaultFieldMapper,
|
|
27
27
|
getEntityFieldNames,
|
|
28
|
-
} from '@donotdev/supabase';
|
|
28
|
+
} from '@donotdev/supabase/server';
|
|
29
29
|
|
|
30
30
|
import { DoNotDevError } from '../../shared/utils.js';
|
|
31
31
|
import { createSupabaseHandler } from '../baseFunction.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Generic handler to update an entity in Supabase.
|
|
5
5
|
* @description Provides a reusable implementation for updating documents in PostgreSQL with validation.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import * as v from 'valibot';
|
|
13
13
|
|
|
14
14
|
import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
|
|
15
|
-
import { defaultFieldMapper } from '@donotdev/supabase';
|
|
15
|
+
import { defaultFieldMapper } from '@donotdev/supabase/server';
|
|
16
16
|
|
|
17
17
|
import { updateMetadata } from '../../shared/index.js';
|
|
18
18
|
import { DoNotDevError, validateDocument } from '../../shared/utils.js';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @description Maps Supabase Admin auth to the shared `AuthProvider` interface,
|
|
6
6
|
* bridging `app_metadata` ↔ `customClaims`.
|
|
7
7
|
*
|
|
8
|
-
* @version 0.0
|
|
8
|
+
* @version 0.1.0
|
|
9
9
|
* @since 0.5.0
|
|
10
10
|
* @author AMBROISE PARK Consulting
|
|
11
11
|
*/
|
|
@@ -24,7 +24,7 @@ import type { SupabaseClient } from '@supabase/supabase-js';
|
|
|
24
24
|
* @param supabaseAdmin - Supabase client created with the service role key
|
|
25
25
|
* @returns AuthProvider compatible with shared billing helpers
|
|
26
26
|
*
|
|
27
|
-
* @version 0.0
|
|
27
|
+
* @version 0.1.0
|
|
28
28
|
* @since 0.5.0
|
|
29
29
|
*/
|
|
30
30
|
export function createSupabaseAuthProvider(
|
package/src/supabase/index.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Supabase Edge Functions barrel exports
|
|
5
|
-
* @description All Supabase Edge Function handlers for auth and
|
|
5
|
+
* @description All Supabase Edge Function handlers for auth, billing, and OAuth.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.5.0
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -30,6 +30,14 @@ export { createChangePlan } from './billing/changePlan.js';
|
|
|
30
30
|
export { createCustomerPortal } from './billing/createCustomerPortal.js';
|
|
31
31
|
export { createRefreshSubscriptionStatus } from './billing/refreshSubscriptionStatus.js';
|
|
32
32
|
|
|
33
|
+
// OAuth
|
|
34
|
+
export {
|
|
35
|
+
createExchangeToken,
|
|
36
|
+
createDisconnect,
|
|
37
|
+
createRefreshToken,
|
|
38
|
+
createGetConnections,
|
|
39
|
+
} from './oauth/index.js';
|
|
40
|
+
|
|
33
41
|
// CRUD
|
|
34
42
|
export {
|
|
35
43
|
createSupabaseGetEntity,
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// packages/functions/src/supabase/oauth/disconnect.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview OAuth disconnect Supabase Edge Function
|
|
5
|
+
* @description Supabase Edge Function for disconnecting OAuth providers
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as v from 'valibot';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
OAUTH_PARTNERS,
|
|
16
|
+
type OAuthPartnerId,
|
|
17
|
+
type OAuthPurpose,
|
|
18
|
+
} from '@donotdev/core/server';
|
|
19
|
+
|
|
20
|
+
import { createSupabaseHandler } from '../baseFunction.js';
|
|
21
|
+
import type { SupabaseHandlerContext } from '../baseFunction.js';
|
|
22
|
+
|
|
23
|
+
const disconnectSchema = v.object({
|
|
24
|
+
provider: v.string() as v.BaseSchema<
|
|
25
|
+
unknown,
|
|
26
|
+
OAuthPartnerId,
|
|
27
|
+
v.BaseIssue<unknown>
|
|
28
|
+
>,
|
|
29
|
+
purpose: v.picklist(['authentication', 'api-access']) as v.BaseSchema<
|
|
30
|
+
unknown,
|
|
31
|
+
OAuthPurpose,
|
|
32
|
+
v.BaseIssue<unknown>
|
|
33
|
+
>,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create an OAuth disconnect Edge Function handler
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { createDisconnect } from '@donotdev/functions/supabase';
|
|
42
|
+
* Deno.serve(createDisconnect());
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @version 0.1.0
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
*/
|
|
48
|
+
export function createDisconnect() {
|
|
49
|
+
return createSupabaseHandler(
|
|
50
|
+
'disconnect',
|
|
51
|
+
disconnectSchema,
|
|
52
|
+
async (
|
|
53
|
+
data: { provider: OAuthPartnerId; purpose: OAuthPurpose },
|
|
54
|
+
ctx: SupabaseHandlerContext
|
|
55
|
+
) => {
|
|
56
|
+
const { provider, purpose } = data;
|
|
57
|
+
|
|
58
|
+
// Get existing connection to revoke token
|
|
59
|
+
const { data: connection } = await ctx.supabaseAdmin
|
|
60
|
+
.from('oauth_connections')
|
|
61
|
+
.select('credentials')
|
|
62
|
+
.eq('user_id', ctx.uid)
|
|
63
|
+
.eq('provider', provider)
|
|
64
|
+
.eq('purpose', purpose)
|
|
65
|
+
.single();
|
|
66
|
+
|
|
67
|
+
// Revoke token if possible
|
|
68
|
+
if (connection?.credentials?.accessToken) {
|
|
69
|
+
const endpoints = OAUTH_PARTNERS[provider];
|
|
70
|
+
const revokeUrl =
|
|
71
|
+
'revokeUrl' in endpoints ? endpoints.revokeUrl : null;
|
|
72
|
+
if (revokeUrl) {
|
|
73
|
+
try {
|
|
74
|
+
await fetch(revokeUrl.toString(), {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
headers: {
|
|
77
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
78
|
+
},
|
|
79
|
+
body: new URLSearchParams({
|
|
80
|
+
token: connection.credentials.accessToken,
|
|
81
|
+
}).toString(),
|
|
82
|
+
});
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.warn(`Failed to revoke token for ${provider}:`, e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Delete connection
|
|
90
|
+
const { error } = await ctx.supabaseAdmin
|
|
91
|
+
.from('oauth_connections')
|
|
92
|
+
.delete()
|
|
93
|
+
.eq('user_id', ctx.uid)
|
|
94
|
+
.eq('provider', provider)
|
|
95
|
+
.eq('purpose', purpose);
|
|
96
|
+
|
|
97
|
+
if (error) {
|
|
98
|
+
throw new Error(`Failed to disconnect: ${error.message}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return { success: true };
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// packages/functions/src/supabase/oauth/exchangeToken.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview OAuth token exchange Supabase Edge Function
|
|
5
|
+
* @description Supabase Edge Function for exchanging OAuth codes for tokens
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as v from 'valibot';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
OAUTH_PARTNERS,
|
|
16
|
+
exchangeTokenSchema,
|
|
17
|
+
type ExchangeTokenRequest,
|
|
18
|
+
type OAuthPartnerId,
|
|
19
|
+
} from '@donotdev/core/server';
|
|
20
|
+
|
|
21
|
+
import { createSupabaseHandler } from '../baseFunction.js';
|
|
22
|
+
import type { SupabaseHandlerContext } from '../baseFunction.js';
|
|
23
|
+
|
|
24
|
+
/** Cross-runtime env var access (Deno Edge Functions + Node tests) */
|
|
25
|
+
function getEnv(key: string): string | undefined {
|
|
26
|
+
return typeof Deno !== 'undefined'
|
|
27
|
+
? Deno.env.get(key)
|
|
28
|
+
: process.env[key];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare const Deno:
|
|
32
|
+
| { env: { get(key: string): string | undefined } }
|
|
33
|
+
| undefined;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create an OAuth token exchange Edge Function handler
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { createExchangeToken } from '@donotdev/functions/supabase';
|
|
41
|
+
* Deno.serve(createExchangeToken());
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @version 0.1.0
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
*/
|
|
47
|
+
export function createExchangeToken() {
|
|
48
|
+
return createSupabaseHandler(
|
|
49
|
+
'exchange-token',
|
|
50
|
+
exchangeTokenSchema,
|
|
51
|
+
async (data: ExchangeTokenRequest, ctx: SupabaseHandlerContext) => {
|
|
52
|
+
const { provider, purpose, code, redirectUri, codeVerifier } = data;
|
|
53
|
+
|
|
54
|
+
// Get provider endpoints
|
|
55
|
+
const endpoints = OAUTH_PARTNERS[provider];
|
|
56
|
+
if (!endpoints?.endpoints?.tokenUrl) {
|
|
57
|
+
throw new Error(`Provider ${provider} is not supported`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Get client credentials from env
|
|
61
|
+
const clientId =
|
|
62
|
+
getEnv(`OAUTH_${provider.toUpperCase()}_CLIENT_ID`);
|
|
63
|
+
const clientSecret =
|
|
64
|
+
getEnv(`OAUTH_${provider.toUpperCase()}_CLIENT_SECRET`);
|
|
65
|
+
|
|
66
|
+
if (!clientId || !clientSecret) {
|
|
67
|
+
throw new Error(`Provider ${provider} is not configured`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Exchange code for token
|
|
71
|
+
const tokenResponse = await fetch(endpoints.endpoints.tokenUrl, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
75
|
+
Accept: 'application/json',
|
|
76
|
+
},
|
|
77
|
+
body: new URLSearchParams({
|
|
78
|
+
grant_type: 'authorization_code',
|
|
79
|
+
client_id: clientId,
|
|
80
|
+
client_secret: clientSecret,
|
|
81
|
+
code,
|
|
82
|
+
redirect_uri: redirectUri,
|
|
83
|
+
...(codeVerifier ? { code_verifier: codeVerifier } : {}),
|
|
84
|
+
}).toString(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (!tokenResponse.ok) {
|
|
88
|
+
const errorText = await tokenResponse.text();
|
|
89
|
+
console.error(
|
|
90
|
+
`Token exchange error for ${provider}: ${tokenResponse.status}`,
|
|
91
|
+
errorText
|
|
92
|
+
);
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Failed to exchange code for token: ${tokenResponse.status}`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const tokenData = (await tokenResponse.json()) as any;
|
|
99
|
+
|
|
100
|
+
// Format credentials
|
|
101
|
+
const credentials = {
|
|
102
|
+
accessToken: tokenData.access_token,
|
|
103
|
+
refreshToken: tokenData.refresh_token || null,
|
|
104
|
+
expiresAt: tokenData.expires_in
|
|
105
|
+
? Math.floor(Date.now() / 1000) + tokenData.expires_in
|
|
106
|
+
: null,
|
|
107
|
+
idToken: tokenData.id_token || null,
|
|
108
|
+
scope: tokenData.scope ? tokenData.scope.split(' ') : [],
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Get user profile
|
|
112
|
+
let profile = null;
|
|
113
|
+
if (credentials.accessToken && endpoints.endpoints.profileUrl) {
|
|
114
|
+
try {
|
|
115
|
+
const profileResponse = await fetch(endpoints.endpoints.profileUrl, {
|
|
116
|
+
headers: {
|
|
117
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
118
|
+
Accept: 'application/json',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
if (profileResponse.ok) {
|
|
122
|
+
profile = await profileResponse.json();
|
|
123
|
+
}
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.warn(`Failed to fetch profile for ${provider}:`, e);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Save connection to Supabase
|
|
130
|
+
const { error: upsertError } = await ctx.supabaseAdmin
|
|
131
|
+
.from('oauth_connections')
|
|
132
|
+
.upsert(
|
|
133
|
+
{
|
|
134
|
+
user_id: ctx.uid,
|
|
135
|
+
provider,
|
|
136
|
+
purpose,
|
|
137
|
+
credentials,
|
|
138
|
+
profile,
|
|
139
|
+
connected: true,
|
|
140
|
+
updated_at: new Date().toISOString(),
|
|
141
|
+
},
|
|
142
|
+
{ onConflict: 'user_id,provider,purpose' }
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (upsertError) {
|
|
146
|
+
console.error('Error saving OAuth connection:', upsertError);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return { success: true, credentials, profile };
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// packages/functions/src/supabase/oauth/getConnections.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Get OAuth connections Supabase Edge Function
|
|
5
|
+
* @description Supabase Edge Function for retrieving user OAuth connections
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as v from 'valibot';
|
|
13
|
+
|
|
14
|
+
import type { OAuthPurpose } from '@donotdev/core/server';
|
|
15
|
+
|
|
16
|
+
import { createSupabaseHandler } from '../baseFunction.js';
|
|
17
|
+
import type { SupabaseHandlerContext } from '../baseFunction.js';
|
|
18
|
+
|
|
19
|
+
const getConnectionsSchema = v.object({
|
|
20
|
+
purpose: v.optional(
|
|
21
|
+
v.picklist(['authentication', 'api-access']) as v.BaseSchema<
|
|
22
|
+
unknown,
|
|
23
|
+
OAuthPurpose,
|
|
24
|
+
v.BaseIssue<unknown>
|
|
25
|
+
>
|
|
26
|
+
),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a get OAuth connections Edge Function handler
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createGetConnections } from '@donotdev/functions/supabase';
|
|
35
|
+
* Deno.serve(createGetConnections());
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @version 0.1.0
|
|
39
|
+
* @since 0.1.0
|
|
40
|
+
*/
|
|
41
|
+
export function createGetConnections() {
|
|
42
|
+
return createSupabaseHandler(
|
|
43
|
+
'get-connections',
|
|
44
|
+
getConnectionsSchema,
|
|
45
|
+
async (
|
|
46
|
+
data: { purpose?: OAuthPurpose },
|
|
47
|
+
ctx: SupabaseHandlerContext
|
|
48
|
+
) => {
|
|
49
|
+
let query = ctx.supabaseAdmin
|
|
50
|
+
.from('oauth_connections')
|
|
51
|
+
.select('*')
|
|
52
|
+
.eq('user_id', ctx.uid);
|
|
53
|
+
|
|
54
|
+
if (data.purpose) {
|
|
55
|
+
query = query.eq('purpose', data.purpose);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { data: rows, error } = await query;
|
|
59
|
+
|
|
60
|
+
if (error) {
|
|
61
|
+
throw new Error(`Failed to get connections: ${error.message}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const connections = (rows || []).map((row: any) => {
|
|
65
|
+
const isExpired = row.credentials?.expiresAt
|
|
66
|
+
? row.credentials.expiresAt < Math.floor(Date.now() / 1000)
|
|
67
|
+
: false;
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
id: row.id,
|
|
71
|
+
userId: row.user_id,
|
|
72
|
+
provider: row.provider,
|
|
73
|
+
purpose: row.purpose,
|
|
74
|
+
connected: !isExpired,
|
|
75
|
+
createdAt: row.created_at,
|
|
76
|
+
updatedAt: row.updated_at,
|
|
77
|
+
hasCredentials: !isExpired && !!row.credentials,
|
|
78
|
+
profile: row.profile,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return { connections };
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// packages/functions/src/supabase/oauth/index.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Supabase OAuth functions barrel exports
|
|
5
|
+
* @description Centralized exports for Supabase OAuth Edge Functions
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export { createExchangeToken } from './exchangeToken.js';
|
|
13
|
+
export { createDisconnect } from './disconnect.js';
|
|
14
|
+
export { createRefreshToken } from './refreshToken.js';
|
|
15
|
+
export { createGetConnections } from './getConnections.js';
|