@donotdev/functions 0.1.44 → 0.2.1
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 +25 -14
- package/lib/chunks/chunk-3F4BWKQD.js +22 -0
- package/lib/chunks/chunk-3F4BWKQD.js.map +7 -0
- package/lib/chunks/chunk-5IPULSUX.js +22 -0
- package/lib/chunks/chunk-5IPULSUX.js.map +7 -0
- package/lib/chunks/chunk-6USHTJED.js +22 -0
- package/lib/chunks/chunk-6USHTJED.js.map +7 -0
- package/lib/chunks/chunk-AYY7UXNI.js +22 -0
- package/lib/chunks/chunk-AYY7UXNI.js.map +7 -0
- package/lib/chunks/chunk-CXBSROEW.js +23 -0
- package/lib/chunks/chunk-CXBSROEW.js.map +7 -0
- package/lib/chunks/chunk-GYTCWMXV.js +22 -0
- package/lib/chunks/chunk-GYTCWMXV.js.map +7 -0
- package/lib/chunks/chunk-HLNYUAZH.js +22 -0
- package/lib/chunks/chunk-HLNYUAZH.js.map +7 -0
- package/lib/chunks/chunk-LCDLG4VG.js +151 -0
- package/lib/chunks/chunk-LCDLG4VG.js.map +7 -0
- package/lib/chunks/chunk-MQANUSY3.js +22 -0
- package/lib/chunks/chunk-MQANUSY3.js.map +7 -0
- package/lib/chunks/chunk-OFQVO3FD.js +22 -0
- package/lib/chunks/chunk-OFQVO3FD.js.map +7 -0
- package/lib/chunks/chunk-PWAGW4R6.js +22 -0
- package/lib/chunks/chunk-PWAGW4R6.js.map +7 -0
- package/lib/chunks/chunk-US2VOP4S.js +22 -0
- package/lib/chunks/chunk-US2VOP4S.js.map +7 -0
- package/lib/chunks/chunk-YTKDNZNW.js +22 -0
- package/lib/chunks/chunk-YTKDNZNW.js.map +7 -0
- package/lib/chunks/monitoring-E7JBYBHQ.js +22 -0
- package/lib/chunks/monitoring-E7JBYBHQ.js.map +7 -0
- package/lib/chunks/rateLimiter-SQISLOP5.js +22 -0
- package/lib/chunks/rateLimiter-SQISLOP5.js.map +7 -0
- package/lib/chunks/server-IQ5JNJOM.js +22 -0
- package/lib/chunks/server-IQ5JNJOM.js.map +7 -0
- package/lib/firebase/auth/getCustomClaims.d.ts +1 -1
- package/lib/firebase/auth/getUserAuthStatus.d.ts +1 -1
- package/lib/firebase/auth/index.d.ts +0 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/firebase/auth/setCustomClaims.d.ts +1 -1
- package/lib/firebase/baseFunction.d.ts +1 -1
- package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
- package/lib/firebase/billing/changePlan.d.ts +0 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +2 -2
- package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
- package/lib/firebase/billing/healthCheck.d.ts +0 -0
- package/lib/firebase/billing/index.d.ts +2 -1
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -8
- package/lib/firebase/billing/webhookHandler.d.ts +17 -2
- package/lib/firebase/config/constants.d.ts +0 -0
- package/lib/firebase/config/index.d.ts +0 -0
- package/lib/firebase/config/secrets.d.ts +0 -0
- package/lib/firebase/crud/aggregate.d.ts +0 -9
- package/lib/firebase/crud/bulk.d.ts +2 -2
- package/lib/firebase/crud/create.d.ts +1 -1
- package/lib/firebase/crud/delete.d.ts +1 -1
- package/lib/firebase/crud/get.d.ts +1 -1
- package/lib/firebase/crud/index.d.ts +0 -0
- package/lib/firebase/crud/list.d.ts +1 -1
- package/lib/firebase/crud/update.d.ts +1 -9
- package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/index.d.ts +0 -0
- package/lib/firebase/index.d.ts +0 -0
- package/lib/firebase/index.js +1 -5
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +0 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
- package/lib/firebase/oauth/getConnections.d.ts +0 -0
- package/lib/firebase/oauth/githubAccess.d.ts +2 -2
- package/lib/firebase/oauth/index.d.ts +0 -0
- package/lib/firebase/oauth/refreshToken.d.ts +0 -0
- package/lib/firebase/registerCrudFunctions.d.ts +9 -1
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
- package/lib/firebase/scheduled/index.d.ts +0 -0
- package/lib/shared/ai/classifyAIError.d.ts +0 -0
- package/lib/shared/ai/costTracker.d.ts +0 -0
- package/lib/shared/ai/createAIRoute.d.ts +0 -0
- package/lib/shared/ai/index.d.ts +0 -0
- package/lib/shared/ai/resolveModelTier.d.ts +0 -0
- package/lib/shared/billing/apiVersion.d.ts +22 -0
- package/lib/shared/billing/checkoutPrice.d.ts +27 -0
- package/lib/shared/billing/checkoutValidation.d.ts +89 -0
- package/lib/shared/billing/createCheckout.d.ts +73 -24
- package/lib/shared/billing/firestoreIdempotency.d.ts +13 -0
- package/lib/shared/billing/helpers/index.d.ts +0 -1
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +4 -4
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -29
- package/lib/shared/billing/idempotency.d.ts +21 -10
- package/lib/shared/billing/idempotencyContract.d.ts +121 -0
- package/lib/shared/billing/index.d.ts +2 -0
- package/lib/shared/billing/orderWebhook.d.ts +75 -0
- package/lib/shared/billing/stripeClient.d.ts +45 -0
- package/lib/shared/billing/supabaseIdempotency.d.ts +32 -0
- package/lib/shared/billing/tierWebhookEvents.d.ts +54 -0
- package/lib/shared/billing/webhookHandler.d.ts +29 -20
- package/lib/shared/email/createEmailRoute.d.ts +0 -0
- package/lib/shared/email/index.d.ts +0 -0
- package/lib/shared/email/provider.d.ts +0 -0
- package/lib/shared/email/resendProvider.d.ts +0 -0
- package/lib/shared/errorHandling.d.ts +0 -0
- package/lib/shared/firebase.d.ts +0 -0
- package/lib/shared/github.d.ts +0 -0
- package/lib/shared/index.d.ts +0 -0
- package/lib/shared/index.js +1 -6
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +0 -0
- package/lib/shared/metadata.d.ts +0 -0
- package/lib/shared/oauth/exchangeToken.d.ts +0 -0
- package/lib/shared/oauth/grantAccess.d.ts +0 -0
- package/lib/shared/oauth/index.d.ts +0 -0
- package/lib/shared/schema.d.ts +0 -0
- package/lib/shared/utils/detectFirestore.d.ts +0 -0
- package/lib/shared/utils/external/date.d.ts +0 -0
- package/lib/shared/utils/external/index.d.ts +0 -0
- package/lib/shared/utils/external/references.d.ts +0 -0
- package/lib/shared/utils/external/subscription.d.ts +0 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
- package/lib/shared/utils/functionWrapper.d.ts +1 -1
- package/lib/shared/utils/index.d.ts +0 -0
- package/lib/shared/utils/internal/auth.d.ts +38 -1
- package/lib/shared/utils/internal/firebase.d.ts +0 -0
- package/lib/shared/utils/internal/idempotency.d.ts +0 -0
- package/lib/shared/utils/internal/index.d.ts +0 -0
- package/lib/shared/utils/internal/monitoring.d.ts +0 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +8 -0
- package/lib/shared/utils/internal/validation.d.ts +0 -8
- package/lib/shared/utils/schemaValidation.d.ts +1 -1
- package/lib/shared/utils/validation.d.ts +0 -0
- package/lib/shared/utils/vercelHelpers.d.ts +8 -0
- package/lib/shared/utils.d.ts +0 -56
- package/lib/shared/validation.d.ts +0 -0
- package/lib/supabase/ai/createAIFunction.d.ts +0 -0
- package/lib/supabase/auth/deleteAccount.d.ts +0 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +0 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +0 -0
- package/lib/supabase/baseFunction.d.ts +1 -1
- package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
- package/lib/supabase/billing/changePlan.d.ts +0 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
- package/lib/supabase/billing/stripeWebhook.d.ts +34 -0
- package/lib/supabase/crud/aggregate.d.ts +0 -0
- package/lib/supabase/crud/bulk.d.ts +1 -1
- package/lib/supabase/crud/create.d.ts +0 -0
- package/lib/supabase/crud/delete.d.ts +0 -0
- package/lib/supabase/crud/entityStore.d.ts +71 -0
- package/lib/supabase/crud/get.d.ts +0 -0
- package/lib/supabase/crud/index.d.ts +2 -0
- package/lib/supabase/crud/list.d.ts +0 -8
- package/lib/supabase/crud/update.d.ts +0 -0
- package/lib/supabase/edgeFunction.d.ts +0 -0
- package/lib/supabase/email/createEmailFunction.d.ts +0 -0
- package/lib/supabase/helpers/authProvider.d.ts +5 -5
- package/lib/supabase/index.d.ts +11 -2
- package/lib/supabase/index.js +1 -3
- package/lib/supabase/index.js.map +4 -4
- package/lib/supabase/oauth/disconnect.d.ts +0 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
- package/lib/supabase/oauth/getConnections.d.ts +0 -0
- package/lib/supabase/oauth/index.d.ts +0 -0
- package/lib/supabase/oauth/refreshToken.d.ts +0 -0
- package/lib/supabase/registerCrudFunctions.d.ts +0 -0
- package/lib/supabase/utils/idempotency.d.ts +0 -0
- package/lib/supabase/utils/monitoring.d.ts +0 -0
- package/lib/supabase/utils/rateLimiter.d.ts +1 -1
- package/lib/vercel/api/ai/chat.d.ts +0 -9
- package/lib/vercel/api/ai/index.d.ts +0 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +8 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +8 -0
- package/lib/vercel/api/auth/index.d.ts +0 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +8 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +8 -0
- package/lib/vercel/api/billing/backend.d.ts +39 -0
- package/lib/vercel/api/billing/cancel.d.ts +8 -0
- package/lib/vercel/api/billing/change-plan.d.ts +9 -1
- package/lib/vercel/api/billing/create-checkout-session.d.ts +25 -6
- package/lib/vercel/api/billing/customer-portal.d.ts +8 -0
- package/lib/vercel/api/billing/index.d.ts +4 -2
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +19 -3
- package/lib/vercel/api/billing/webhook-handler.d.ts +25 -4
- package/lib/vercel/api/config/constants.d.ts +0 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +8 -0
- package/lib/vercel/api/config/index.d.ts +0 -0
- package/lib/vercel/api/crud/bulk.d.ts +17 -0
- package/lib/vercel/api/crud/create.d.ts +8 -0
- package/lib/vercel/api/crud/delete.d.ts +8 -0
- package/lib/vercel/api/crud/get.d.ts +8 -0
- package/lib/vercel/api/crud/index.d.ts +0 -0
- package/lib/vercel/api/crud/list.d.ts +8 -0
- package/lib/vercel/api/crud/update.d.ts +8 -0
- package/lib/vercel/api/index.d.ts +0 -0
- package/lib/vercel/api/index.js +1 -3
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +8 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +8 -0
- package/lib/vercel/api/oauth/index.d.ts +0 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +1 -1
- package/lib/vercel/api/utils/cors.d.ts +0 -0
- package/lib/vercel/baseFunction.d.ts +4 -1
- package/lib/vercel/supabaseAdmin.d.ts +22 -0
- package/package.json +25 -26
- package/src/firebase/auth/getCustomClaims.ts +4 -5
- package/src/firebase/auth/getUserAuthStatus.ts +4 -5
- package/src/firebase/auth/removeCustomClaims.ts +4 -5
- package/src/firebase/auth/setCustomClaims.ts +4 -5
- package/src/firebase/baseFunction.ts +4 -5
- package/src/firebase/billing/cancelSubscription.ts +2 -3
- package/src/firebase/billing/changePlan.ts +3 -8
- package/src/firebase/billing/createCheckoutSession.ts +31 -61
- package/src/firebase/billing/createCustomerPortal.ts +5 -6
- package/src/firebase/billing/healthCheck.ts +1 -1
- package/src/firebase/billing/index.ts +8 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -4
- package/src/firebase/billing/webhookHandler.ts +21 -5
- package/src/firebase/crud/__tests__/bulk.test.ts +11 -1
- package/src/firebase/crud/aggregate.ts +1 -2
- package/src/firebase/crud/bulk.ts +5 -6
- package/src/firebase/crud/create.ts +5 -6
- package/src/firebase/crud/delete.ts +4 -5
- package/src/firebase/crud/get.ts +4 -5
- package/src/firebase/crud/list.ts +4 -5
- package/src/firebase/crud/update.ts +5 -6
- package/src/firebase/oauth/githubAccess.ts +2 -3
- package/src/firebase/registerCrudFunctions.ts +2 -2
- package/src/shared/__tests__/auth.test.ts +0 -3
- package/src/shared/__tests__/bulkCore.test.ts +3 -2
- package/src/shared/__tests__/errorHandling.test.ts +2 -2
- package/src/shared/__tests__/idempotency.test.ts +282 -55
- package/src/shared/__tests__/internalValidation.test.ts +3 -42
- package/src/shared/__tests__/logger.test.ts +31 -0
- package/src/shared/__tests__/rateLimiter.test.ts +2 -8
- package/src/shared/__tests__/schemaValidation.test.ts +1 -1
- package/src/shared/__tests__/utils.test.ts +3 -2
- package/src/shared/__tests__/validation-env.test.ts +0 -0
- package/src/shared/ai/createAIRoute.ts +53 -30
- package/src/shared/billing/__tests__/checkoutValidation.test.ts +219 -0
- package/src/shared/billing/__tests__/createCheckout.compat.test.ts +349 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +454 -411
- package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +92 -0
- package/src/shared/billing/__tests__/webhookCorrectness.test.ts +387 -0
- package/src/shared/billing/__tests__/webhookHandler.test.ts +370 -23
- package/src/shared/billing/apiVersion.ts +25 -0
- package/src/shared/billing/checkoutPrice.ts +125 -0
- package/src/shared/billing/checkoutValidation.ts +284 -0
- package/src/shared/billing/createCheckout.ts +332 -196
- package/src/shared/billing/firestoreIdempotency.ts +189 -0
- package/src/shared/billing/helpers/index.ts +0 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +8 -10
- package/src/shared/billing/helpers/updateUserSubscription.ts +3 -36
- package/src/shared/billing/idempotency.ts +104 -168
- package/src/shared/billing/idempotencyContract.ts +135 -0
- package/src/shared/billing/index.ts +2 -0
- package/src/shared/billing/orderWebhook.ts +269 -0
- package/src/shared/billing/stripeClient.ts +91 -0
- package/src/shared/billing/supabaseIdempotency.ts +228 -0
- package/src/shared/billing/tierWebhookEvents.ts +432 -0
- package/src/shared/billing/webhookHandler.ts +189 -386
- package/src/shared/logger.ts +4 -6
- package/src/shared/utils/external/subscription.ts +0 -0
- package/src/shared/utils/firebaseHelpers.ts +2 -3
- package/src/shared/utils/functionWrapper.ts +1 -2
- package/src/shared/utils/internal/auth.ts +55 -7
- package/src/shared/utils/internal/monitoring.ts +17 -9
- package/src/shared/utils/internal/rateLimiter.ts +14 -5
- package/src/shared/utils/internal/validation.ts +0 -18
- package/src/shared/utils/schemaValidation.ts +1 -2
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +5 -99
- package/src/shared/validation.ts +1 -1
- package/src/supabase/__tests__/bulk.test.ts +3 -1
- package/src/supabase/__tests__/entityStore.test.ts +90 -0
- package/src/supabase/baseFunction.ts +1 -2
- package/src/supabase/billing/cancelSubscription.ts +1 -1
- package/src/supabase/billing/changePlan.ts +1 -1
- package/src/supabase/billing/createCheckoutSession.ts +11 -41
- package/src/supabase/billing/createCustomerPortal.ts +1 -1
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -7
- package/src/supabase/billing/stripeWebhook.ts +79 -0
- package/src/supabase/crud/aggregate.ts +1 -1
- package/src/supabase/crud/bulk.ts +3 -7
- package/src/supabase/crud/create.ts +1 -1
- package/src/supabase/crud/entityStore.ts +240 -0
- package/src/supabase/crud/index.ts +8 -0
- package/src/supabase/crud/list.ts +2 -0
- package/src/supabase/crud/update.ts +1 -1
- package/src/supabase/helpers/authProvider.ts +6 -5
- package/src/supabase/index.ts +26 -0
- package/src/supabase/utils/rateLimiter.ts +2 -2
- package/src/vercel/__tests__/bulk.test.ts +24 -21
- package/src/vercel/__tests__/firebaseOptional.test.ts +64 -0
- package/src/vercel/api/ai/chat.ts +2 -1
- package/src/vercel/api/auth/get-custom-claims.ts +2 -3
- package/src/vercel/api/auth/get-user-auth-status.ts +2 -3
- package/src/vercel/api/auth/remove-custom-claims.ts +2 -3
- package/src/vercel/api/auth/set-custom-claims.ts +3 -3
- package/src/vercel/api/billing/backend.ts +72 -0
- package/src/vercel/api/billing/cancel.ts +2 -4
- package/src/vercel/api/billing/change-plan.ts +4 -5
- package/src/vercel/api/billing/create-checkout-session.ts +43 -73
- package/src/vercel/api/billing/customer-portal.ts +3 -5
- package/src/vercel/api/billing/index.ts +4 -2
- package/src/vercel/api/billing/refresh-subscription-status.ts +22 -7
- package/src/vercel/api/billing/webhook-handler.ts +32 -26
- package/src/vercel/api/config/firebase-admin.ts +2 -2
- package/src/vercel/api/crud/bulk.ts +6 -9
- package/src/vercel/api/crud/create.ts +6 -5
- package/src/vercel/api/crud/delete.ts +4 -3
- package/src/vercel/api/crud/get.ts +6 -5
- package/src/vercel/api/crud/list.ts +6 -5
- package/src/vercel/api/crud/update.ts +6 -5
- package/src/vercel/api/oauth/check-github-access.ts +5 -5
- package/src/vercel/api/oauth/exchange-token.ts +3 -3
- package/src/vercel/api/oauth/grant-github-access.ts +5 -5
- package/src/vercel/api/oauth/revoke-github-access.ts +3 -4
- package/src/vercel/baseFunction.ts +23 -8
- package/src/vercel/supabaseAdmin.ts +45 -0
- package/lib/shared/ai/createAIHandler.d.ts +0 -39
- package/lib/shared/ai/providers/anthropic.d.ts +0 -12
- package/lib/shared/ai/providers/google.d.ts +0 -10
- package/lib/shared/ai/providers/index.d.ts +0 -23
- package/lib/shared/ai/providers/openai.d.ts +0 -10
- package/lib/shared/ai/utils/parseSSE.d.ts +0 -22
package/lib/shared/logger.d.ts
CHANGED
|
File without changes
|
package/lib/shared/metadata.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/shared/schema.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
-
import * as v from 'valibot';
|
|
10
9
|
import type { CallableRequest } from 'firebase-functions/v2/https';
|
|
11
10
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
11
|
+
import * as v from 'valibot';
|
|
12
12
|
/**
|
|
13
13
|
* Simple wrapper that validates data against schema and calls the handler
|
|
14
14
|
* This is the ONLY pattern needed for all functions
|
|
File without changes
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Authentication utility functions
|
|
3
|
+
* @description Provider-agnostic functions for user authentication and authorization.
|
|
4
|
+
* Uses IServerAuthAdapter from provider registry when configured, falls back to Firebase Admin SDK.
|
|
5
|
+
*
|
|
6
|
+
* @version 0.1.0
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
1
10
|
import type { NextApiRequest } from 'next';
|
|
11
|
+
import * as v from 'valibot';
|
|
12
|
+
/**
|
|
13
|
+
* Auth backends a server function can be explicitly configured with.
|
|
14
|
+
*
|
|
15
|
+
* @version 0.2.0
|
|
16
|
+
* @since 0.2.0
|
|
17
|
+
* @author AMBROISE PARK Consulting
|
|
18
|
+
*/
|
|
19
|
+
export declare const AuthBackendSchema: v.PicklistSchema<["firebase", "supabase"], undefined>;
|
|
2
20
|
/** Auth provider type for explicit configuration */
|
|
3
|
-
export type AuthProvider =
|
|
21
|
+
export type AuthProvider = v.InferOutput<typeof AuthBackendSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* Validate an auth backend at runtime. Values typed as `AuthProvider` can
|
|
24
|
+
* still arrive as arbitrary strings from JS or env-driven config, and an
|
|
25
|
+
* unknown value must never silently run as Firebase.
|
|
26
|
+
*
|
|
27
|
+
* @param backend - Value to validate
|
|
28
|
+
* @returns The validated backend
|
|
29
|
+
* @throws DoNotDevError (`invalid-argument`) naming the allowed values
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const backend = parseAuthBackend(process.env.AUTH_BACKEND); // 'firebase' | 'supabase'
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @version 0.2.0
|
|
37
|
+
* @since 0.2.0
|
|
38
|
+
* @author AMBROISE PARK Consulting
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseAuthBackend(backend: unknown): AuthProvider;
|
|
4
41
|
/**
|
|
5
42
|
* Validates that user is authenticated
|
|
6
43
|
*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Server-side rate limiting utilities
|
|
3
|
+
* @description Rate limiting implementation for Firebase Functions and Vercel
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
1
9
|
import type { ServerRateLimitConfig as RateLimitConfig, ServerRateLimitResult as RateLimitResult } from '@donotdev/core';
|
|
2
10
|
export type { RateLimitConfig, RateLimitResult };
|
|
3
11
|
/**
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
-
import * as v from 'valibot';
|
|
10
9
|
import type { CallableRequest } from 'firebase-functions/v2/https';
|
|
11
10
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
11
|
+
import * as v from 'valibot';
|
|
12
12
|
/**
|
|
13
13
|
* Validates request data using a schema with custom override support
|
|
14
14
|
*
|
|
File without changes
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview DRY helpers for Vercel API functions with schema validation
|
|
3
|
+
* @description Provides reusable patterns for Vercel API routes
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
1
9
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
10
|
import type * as v from 'valibot';
|
|
3
11
|
/**
|
package/lib/shared/utils.d.ts
CHANGED
|
@@ -1,54 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Shared utilities for Firebase and Vercel functions
|
|
3
|
-
* @description Common utilities that can be used by both Firebase and Vercel function implementations
|
|
4
|
-
*
|
|
5
|
-
* @version 0.1.0
|
|
6
|
-
* @since 0.0.1
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
|
-
import Stripe from 'stripe';
|
|
10
1
|
import { DoNotDevError } from '@donotdev/core/server';
|
|
11
2
|
import type { UserRole } from '@donotdev/core/server';
|
|
12
3
|
export { DoNotDevError };
|
|
13
|
-
/**
|
|
14
|
-
* Get Firestore instance using @donotdev/firebase/server
|
|
15
|
-
* Provider handles initialization and caching
|
|
16
|
-
*
|
|
17
|
-
* @version 0.1.0
|
|
18
|
-
* @since 0.0.1
|
|
19
|
-
* @author AMBROISE PARK Consulting
|
|
20
|
-
*/
|
|
21
|
-
export declare function getFirestore(): FirebaseFirestore.Firestore;
|
|
22
|
-
/**
|
|
23
|
-
* Get Auth instance using @donotdev/firebase/server
|
|
24
|
-
* Provider handles initialization and caching
|
|
25
|
-
*
|
|
26
|
-
* @version 0.1.0
|
|
27
|
-
* @since 0.0.1
|
|
28
|
-
* @author AMBROISE PARK Consulting
|
|
29
|
-
*/
|
|
30
|
-
export declare function getAuth(): import("firebase-admin/auth").Auth;
|
|
31
|
-
/**
|
|
32
|
-
* Initialize Stripe explicitly (e.g. with a secret from defineSecret)
|
|
33
|
-
* @param apiKey - Stripe secret key
|
|
34
|
-
*/
|
|
35
|
-
export declare function initStripe(apiKey: string): Stripe;
|
|
36
|
-
/**
|
|
37
|
-
* Get Stripe instance with lazy initialization
|
|
38
|
-
*
|
|
39
|
-
* @version 0.1.0
|
|
40
|
-
* @since 0.0.1
|
|
41
|
-
* @author AMBROISE PARK Consulting
|
|
42
|
-
*/
|
|
43
|
-
export declare function getStripe(): Stripe;
|
|
44
|
-
/**
|
|
45
|
-
* Lazy-initialized Stripe instance proxy
|
|
46
|
-
*
|
|
47
|
-
* @version 0.1.0
|
|
48
|
-
* @since 0.0.1
|
|
49
|
-
* @author AMBROISE PARK Consulting
|
|
50
|
-
*/
|
|
51
|
-
export declare const stripe: Stripe;
|
|
52
4
|
/**
|
|
53
5
|
* Assert that a user is authenticated from a Firebase callable auth context.
|
|
54
6
|
*
|
|
@@ -81,14 +33,6 @@ export declare function assertAuthenticated(auth: any): string;
|
|
|
81
33
|
* @author AMBROISE PARK Consulting
|
|
82
34
|
*/
|
|
83
35
|
export declare function getUserRole(auth: any): UserRole;
|
|
84
|
-
/**
|
|
85
|
-
* Validates that required Stripe environment variables are set
|
|
86
|
-
*
|
|
87
|
-
* @version 0.1.0
|
|
88
|
-
* @since 0.0.1
|
|
89
|
-
* @author AMBROISE PARK Consulting
|
|
90
|
-
*/
|
|
91
|
-
export declare function validateStripeEnvironment(): void;
|
|
92
36
|
/**
|
|
93
37
|
* Creates a standardized success response
|
|
94
38
|
*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
1
2
|
import * as v from 'valibot';
|
|
2
3
|
import type { UserRole, SecurityContext } from '@donotdev/core/server';
|
|
3
|
-
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
4
4
|
/**
|
|
5
5
|
* Context passed to Supabase Edge Function business logic
|
|
6
6
|
*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Stripe webhook Supabase Edge Function
|
|
3
|
+
* @description Verifies and routes Stripe webhook events through the shared
|
|
4
|
+
* processWebhook (SSOT). Idempotency is stored in Postgres (`webhook_events`).
|
|
5
|
+
*
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
* @since 0.2.0
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
11
|
+
/**
|
|
12
|
+
* Create a Supabase Edge Function handler for Stripe webhooks.
|
|
13
|
+
* Requires the `webhook_events` migration (see `WEBHOOK_EVENTS_SQL`).
|
|
14
|
+
* Deploy with JWT verification disabled for this function: Stripe authenticates
|
|
15
|
+
* with its signature, not a Supabase JWT.
|
|
16
|
+
* Any failure answers non-2xx so Stripe retries the event.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // supabase/functions/stripe-webhook/index.ts
|
|
21
|
+
* import { createStripeWebhook } from '@donotdev/functions/supabase';
|
|
22
|
+
* import { billingConfig } from '../_shared/billingConfig.ts';
|
|
23
|
+
*
|
|
24
|
+
* Deno.serve(createStripeWebhook(billingConfig));
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param billingConfig - App back config
|
|
28
|
+
* @returns `(req: Request) => Promise<Response>` handler
|
|
29
|
+
*
|
|
30
|
+
* @version 0.2.0
|
|
31
|
+
* @since 0.2.0
|
|
32
|
+
* @author AMBROISE PARK Consulting
|
|
33
|
+
*/
|
|
34
|
+
export declare function createStripeWebhook(billingConfig: StripeBackConfig): (req: Request) => Promise<Response>;
|
|
File without changes
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* @since 0.6.0
|
|
15
15
|
* @author AMBROISE PARK Consulting
|
|
16
16
|
*/
|
|
17
|
-
import * as v from 'valibot';
|
|
17
|
+
import type * as v from 'valibot';
|
|
18
18
|
import type { BulkRequest, EntityAccessConfig } from '@donotdev/core/server';
|
|
19
19
|
/** Request payload accepted by the bulk handler — mirrors {@link BulkRequestSchema}. */
|
|
20
20
|
export type BulkEntityRequest = BulkRequest;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview In-process, entity-aware CRUD for server code (Edge Functions, jobs).
|
|
3
|
+
* @description The HTTP CRUD handlers serve clients. Server code that already holds
|
|
4
|
+
* a Supabase client (usually the service role) reads and writes through this store
|
|
5
|
+
* instead of raw `.from()` queries: entity field names in and out (snake_case
|
|
6
|
+
* columns stay behind the field mapper), unknown fields rejected, and the
|
|
7
|
+
* publication filter applied by default (draft / deleted rows hidden, as the
|
|
8
|
+
* database policy hides them from non-admin users; the service role bypasses that
|
|
9
|
+
* policy, so the store re-applies it on reads).
|
|
10
|
+
*
|
|
11
|
+
* No role or visibility masking: the caller is trusted server code. Atomic
|
|
12
|
+
* multi-table writes stay in SQL functions (`client.rpc`).
|
|
13
|
+
*
|
|
14
|
+
* @version 0.1.0
|
|
15
|
+
* @since 0.5.0
|
|
16
|
+
* @author AMBROISE PARK Consulting
|
|
17
|
+
*/
|
|
18
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
19
|
+
import type { AnyEntity, InferEntityRow } from '@donotdev/core/server';
|
|
20
|
+
/** Filter operators, same vocabulary as the list handler and the client CRUD. */
|
|
21
|
+
export type EntityStoreOperator = '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
|
|
22
|
+
/** `[field, operator, value]`; field is an entity field name. */
|
|
23
|
+
export type EntityStoreCondition = readonly [string, EntityStoreOperator, unknown];
|
|
24
|
+
/** Read options of {@link EntityStore.list} and {@link EntityStore.find}. */
|
|
25
|
+
export interface EntityStoreQuery {
|
|
26
|
+
where?: readonly EntityStoreCondition[];
|
|
27
|
+
/** Entity fields to read (default: every column). `id` is always read. */
|
|
28
|
+
select?: readonly string[];
|
|
29
|
+
orderBy?: readonly (readonly [string, 'asc' | 'desc'])[];
|
|
30
|
+
limit?: number;
|
|
31
|
+
/** Also return draft / deleted rows (default false). */
|
|
32
|
+
includeHidden?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Values written to a row: any subset of its fields; `null` clears a nullable column. */
|
|
35
|
+
export type EntityStoreValues<Row> = {
|
|
36
|
+
[K in keyof Row]?: Row[K] | null;
|
|
37
|
+
};
|
|
38
|
+
/** Entity-aware CRUD bound to one entity and one Supabase client. */
|
|
39
|
+
export interface EntityStore<Row> {
|
|
40
|
+
/** Rows matching the query. */
|
|
41
|
+
list(query?: EntityStoreQuery): Promise<Row[]>;
|
|
42
|
+
/** The single row matching the query, or null; more than one row is an error. */
|
|
43
|
+
find(query: EntityStoreQuery): Promise<Row | null>;
|
|
44
|
+
/** Row by id, or null (hidden rows only with `includeHidden`). */
|
|
45
|
+
get(id: string, options?: Pick<EntityStoreQuery, 'includeHidden' | 'select'>): Promise<Row | null>;
|
|
46
|
+
/** Inserts rows and returns them as stored (database defaults and triggers applied). */
|
|
47
|
+
insert(values: readonly EntityStoreValues<Row>[]): Promise<Row[]>;
|
|
48
|
+
/** Updates the rows matching `where` (hidden rows included) and returns them as stored. */
|
|
49
|
+
update(where: readonly EntityStoreCondition[], patch: EntityStoreValues<Row>): Promise<Row[]>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates an entity-aware CRUD store for server code.
|
|
53
|
+
*
|
|
54
|
+
* @param client - Supabase client the store runs with (service role in Edge Functions)
|
|
55
|
+
* @param entity - Entity from `defineEntity()`; its collection is the table
|
|
56
|
+
* @returns Store whose rows use the entity field names
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { createEntityStore } from '@donotdev/functions/supabase';
|
|
61
|
+
* import { productEntity } from 'entities';
|
|
62
|
+
*
|
|
63
|
+
* const products = createEntityStore(supabaseAdmin, productEntity);
|
|
64
|
+
* // Published products only (draft / deleted hidden by default)
|
|
65
|
+
* const rows = await products.list({ where: [['id', 'in', ids]], select: ['name', 'sku'] });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @version 0.1.0
|
|
69
|
+
* @since 0.5.0
|
|
70
|
+
*/
|
|
71
|
+
export declare function createEntityStore<E extends AnyEntity>(client: SupabaseClient, entity: E): EntityStore<InferEntityRow<E>>;
|
|
File without changes
|
|
@@ -13,6 +13,7 @@ export { createSupabaseDeleteEntity } from './delete.js';
|
|
|
13
13
|
export { createSupabaseListEntities } from './list.js';
|
|
14
14
|
export { createSupabaseAggregateEntities } from './aggregate.js';
|
|
15
15
|
export { createSupabaseBulkEntity } from './bulk.js';
|
|
16
|
+
export { createEntityStore } from './entityStore.js';
|
|
16
17
|
export type { GetEntityRequest } from './get.js';
|
|
17
18
|
export type { CreateEntityRequest } from './create.js';
|
|
18
19
|
export type { UpdateEntityRequest } from './update.js';
|
|
@@ -20,3 +21,4 @@ export type { DeleteEntityRequest, ReferenceMetadata } from './delete.js';
|
|
|
20
21
|
export type { ListEntityRequest } from './list.js';
|
|
21
22
|
export type { AggregateEntityRequest } from './aggregate.js';
|
|
22
23
|
export type { BulkEntityRequest } from './bulk.js';
|
|
24
|
+
export type { EntityStore, EntityStoreCondition, EntityStoreOperator, EntityStoreQuery, EntityStoreValues, } from './entityStore.js';
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Generic handler to list entities from Supabase with pagination, filtering, and sorting.
|
|
3
|
-
* @description Provides a reusable implementation for listing documents from PostgreSQL with advanced query capabilities.
|
|
4
|
-
*
|
|
5
|
-
* @version 0.1.0
|
|
6
|
-
* @since 0.5.0
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
1
|
import * as v from 'valibot';
|
|
10
2
|
import type { EntityOwnershipConfig, UserRole } from '@donotdev/core/server';
|
|
11
3
|
/** Request payload for listing entities with filtering, sorting, and pagination. */
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Supabase Auth Provider for shared billing logic
|
|
3
|
-
* @description Maps Supabase Admin auth to the
|
|
3
|
+
* @description Maps Supabase Admin auth to the core `BillingAuthProvider` interface,
|
|
4
4
|
* bridging `app_metadata` ↔ `customClaims`.
|
|
5
5
|
*
|
|
6
6
|
* @version 0.1.0
|
|
7
7
|
* @since 0.5.0
|
|
8
8
|
* @author AMBROISE PARK Consulting
|
|
9
9
|
*/
|
|
10
|
-
import type { AuthProvider } from '../../shared/billing/helpers/updateUserSubscription.js';
|
|
11
10
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
11
|
+
import type { BillingAuthProvider } from '@donotdev/core/server';
|
|
12
12
|
/**
|
|
13
|
-
* Create
|
|
13
|
+
* Create a BillingAuthProvider backed by Supabase Admin.
|
|
14
14
|
* `app_metadata` is used as the equivalent of Firebase custom claims.
|
|
15
15
|
*
|
|
16
16
|
* @param supabaseAdmin - Supabase client created with the service role key
|
|
17
|
-
* @returns
|
|
17
|
+
* @returns BillingAuthProvider compatible with shared billing helpers
|
|
18
18
|
*
|
|
19
19
|
* @version 0.1.0
|
|
20
20
|
* @since 0.5.0
|
|
21
21
|
*/
|
|
22
|
-
export declare function createSupabaseAuthProvider(supabaseAdmin: SupabaseClient):
|
|
22
|
+
export declare function createSupabaseAuthProvider(supabaseAdmin: SupabaseClient): BillingAuthProvider;
|
package/lib/supabase/index.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export { createGetCustomClaims } from './auth/getCustomClaims.js';
|
|
|
18
18
|
export { createRemoveCustomClaims } from './auth/removeCustomClaims.js';
|
|
19
19
|
export { createGetUserAuthStatus } from './auth/getUserAuthStatus.js';
|
|
20
20
|
export { createCheckoutSession } from './billing/createCheckoutSession.js';
|
|
21
|
+
export { createStripeWebhook } from './billing/stripeWebhook.js';
|
|
22
|
+
export { createSupabaseIdempotencyStore, WEBHOOK_EVENTS_SQL, } from '../shared/billing/supabaseIdempotency.js';
|
|
23
|
+
export { ReservationLostError } from '../shared/billing/idempotencyContract.js';
|
|
24
|
+
export type { IdempotencyStore, ReservationResult, } from '../shared/billing/idempotencyContract.js';
|
|
25
|
+
export { createCheckoutAlgorithm } from '../shared/billing/createCheckout.js';
|
|
26
|
+
export type { StripeSessionProvider } from '../shared/billing/createCheckout.js';
|
|
27
|
+
export { STRIPE_API_VERSION_PIN } from '../shared/billing/apiVersion.js';
|
|
21
28
|
export { createCancelSubscription } from './billing/cancelSubscription.js';
|
|
22
29
|
export { createChangePlan } from './billing/changePlan.js';
|
|
23
30
|
export { createCustomerPortal } from './billing/createCustomerPortal.js';
|
|
@@ -28,9 +35,11 @@ export { resolveModelForTier } from '../shared/ai/resolveModelTier.js';
|
|
|
28
35
|
export { classifyAIError, mapClassifiedToHTTP, } from '../shared/ai/classifyAIError.js';
|
|
29
36
|
export type { AIErrorCode, ClassifiedAIError, } from '../shared/ai/classifyAIError.js';
|
|
30
37
|
export { createEmailFunction } from './email/createEmailFunction.js';
|
|
31
|
-
export {
|
|
38
|
+
export { handleEmailRequest, createResendProvider, } from '../shared/email/index.js';
|
|
39
|
+
export type { EmailProviderAdapter } from '../shared/email/index.js';
|
|
40
|
+
export { createSupabaseGetEntity, createSupabaseCreateEntity, createSupabaseUpdateEntity, createSupabaseDeleteEntity, createSupabaseListEntities, createSupabaseAggregateEntities, createEntityStore, } from './crud/index.js';
|
|
32
41
|
export { createSupabaseCrudFunctions } from './registerCrudFunctions.js';
|
|
33
|
-
export type { GetEntityRequest, CreateEntityRequest, UpdateEntityRequest, DeleteEntityRequest, ListEntityRequest, AggregateEntityRequest, ReferenceMetadata, } from './crud/index.js';
|
|
42
|
+
export type { GetEntityRequest, CreateEntityRequest, UpdateEntityRequest, DeleteEntityRequest, ListEntityRequest, AggregateEntityRequest, ReferenceMetadata, EntityStore, EntityStoreCondition, EntityStoreOperator, EntityStoreQuery, EntityStoreValues, } from './crud/index.js';
|
|
34
43
|
export { checkIdempotency, storeIdempotency, cleanupExpiredIdempotency, } from './utils/idempotency.js';
|
|
35
44
|
export { checkRateLimitWithPostgres, DEFAULT_RATE_LIMITS, } from './utils/rateLimiter.js';
|
|
36
45
|
export type { RateLimitConfig, RateLimitResult } from './utils/rateLimiter.js';
|