@donotdev/functions 0.0.20 → 0.1.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/LICENSE.md +3 -3
- package/guidelines/FUNCTIONS.md +9 -0
- package/guidelines/VERCEL.md +260 -0
- package/lib/firebase/auth/getCustomClaims.d.ts +2 -2
- package/lib/firebase/auth/getUserAuthStatus.d.ts +2 -2
- package/lib/firebase/auth/index.d.ts +1 -1
- package/lib/firebase/auth/removeCustomClaims.d.ts +2 -2
- package/lib/firebase/auth/setCustomClaims.d.ts +2 -2
- package/lib/firebase/baseFunction.d.ts +1 -1
- package/lib/firebase/billing/cancelSubscription.d.ts +1 -1
- package/lib/firebase/billing/changePlan.d.ts +1 -1
- package/lib/firebase/billing/createCheckoutSession.d.ts +10 -13
- package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
- package/lib/firebase/billing/index.d.ts +1 -1
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +2 -2
- package/lib/firebase/config/constants.d.ts +4 -4
- package/lib/firebase/config/index.d.ts +1 -1
- package/lib/firebase/crud/aggregate.d.ts +2 -2
- 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 +1 -1
- package/lib/firebase/crud/update.d.ts +1 -1
- package/lib/firebase/helpers/githubAccessHelper.d.ts +3 -3
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +2 -2
- package/lib/firebase/helpers/index.d.ts +1 -1
- package/lib/firebase/index.d.ts +1 -1
- package/lib/firebase/index.js +3 -3
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +1 -1
- package/lib/firebase/oauth/exchangeToken.d.ts +1 -1
- package/lib/firebase/oauth/getConnections.d.ts +1 -1
- package/lib/firebase/oauth/githubAccess.d.ts +6 -6
- package/lib/firebase/oauth/index.d.ts +1 -1
- package/lib/firebase/oauth/refreshToken.d.ts +1 -1
- package/lib/firebase/scheduled/index.d.ts +1 -1
- package/lib/shared/ai/classifyAIError.d.ts +35 -0
- package/lib/shared/ai/costTracker.d.ts +20 -0
- package/lib/shared/ai/createAIRoute.d.ts +20 -0
- package/lib/shared/ai/index.d.ts +6 -0
- package/lib/shared/ai/resolveModelTier.d.ts +14 -0
- package/lib/shared/billing/createCheckout.d.ts +11 -5
- package/lib/shared/billing/helpers/index.d.ts +1 -1
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +3 -3
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +4 -4
- package/lib/shared/billing/idempotency.d.ts +2 -2
- package/lib/shared/billing/index.d.ts +1 -1
- package/lib/shared/billing/webhookHandler.d.ts +1 -1
- package/lib/shared/email/createEmailRoute.d.ts +30 -0
- package/lib/shared/email/index.d.ts +3 -0
- package/lib/shared/email/provider.d.ts +30 -0
- package/lib/shared/email/resendProvider.d.ts +22 -0
- package/lib/shared/errorHandling.d.ts +1 -1
- package/lib/shared/firebase.d.ts +7 -7
- package/lib/shared/github.d.ts +16 -11
- package/lib/shared/index.d.ts +3 -1
- package/lib/shared/index.js +4 -3
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +8 -6
- package/lib/shared/metadata.d.ts +3 -3
- package/lib/shared/oauth/exchangeToken.d.ts +3 -2
- package/lib/shared/oauth/grantAccess.d.ts +3 -2
- package/lib/shared/oauth/index.d.ts +1 -1
- package/lib/shared/schema.d.ts +2 -2
- package/lib/shared/utils/detectFirestore.d.ts +3 -3
- package/lib/shared/utils/external/date.d.ts +2 -2
- package/lib/shared/utils/external/index.d.ts +1 -1
- package/lib/shared/utils/external/references.d.ts +1 -1
- package/lib/shared/utils/external/subscription.d.ts +5 -5
- package/lib/shared/utils/firebaseHelpers.d.ts +2 -2
- package/lib/shared/utils/functionWrapper.d.ts +4 -4
- package/lib/shared/utils/index.d.ts +1 -1
- package/lib/shared/utils/internal/auth.d.ts +4 -4
- package/lib/shared/utils/internal/idempotency.d.ts +3 -2
- package/lib/shared/utils/internal/index.d.ts +1 -1
- package/lib/shared/utils/internal/monitoring.d.ts +7 -7
- package/lib/shared/utils/internal/rateLimiter.d.ts +5 -5
- package/lib/shared/utils/internal/validation.d.ts +4 -4
- package/lib/shared/utils/schemaValidation.d.ts +6 -6
- package/lib/shared/utils/validation.d.ts +9 -9
- package/lib/shared/utils/vercelHelpers.d.ts +2 -2
- package/lib/shared/utils.d.ts +19 -19
- package/lib/shared/validation.d.ts +2 -2
- package/lib/supabase/ai/createAIFunction.d.ts +30 -0
- package/lib/supabase/auth/deleteAccount.d.ts +1 -1
- package/lib/supabase/auth/getCustomClaims.d.ts +1 -1
- package/lib/supabase/auth/getUserAuthStatus.d.ts +1 -1
- package/lib/supabase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/supabase/auth/setCustomClaims.d.ts +12 -4
- package/lib/supabase/baseFunction.d.ts +2 -2
- package/lib/supabase/billing/cancelSubscription.d.ts +1 -1
- package/lib/supabase/billing/changePlan.d.ts +2 -2
- package/lib/supabase/billing/createCheckoutSession.d.ts +1 -1
- package/lib/supabase/billing/createCustomerPortal.d.ts +1 -1
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +1 -1
- package/lib/supabase/crud/aggregate.d.ts +2 -1
- package/lib/supabase/crud/create.d.ts +2 -1
- package/lib/supabase/crud/delete.d.ts +1 -0
- package/lib/supabase/crud/get.d.ts +2 -1
- package/lib/supabase/crud/index.d.ts +1 -1
- package/lib/supabase/crud/list.d.ts +2 -1
- package/lib/supabase/crud/update.d.ts +2 -1
- package/lib/supabase/edgeFunction.d.ts +56 -0
- package/lib/supabase/email/createEmailFunction.d.ts +31 -0
- package/lib/supabase/helpers/authProvider.d.ts +2 -2
- package/lib/supabase/index.d.ts +11 -2
- package/lib/supabase/index.js +3 -2
- package/lib/supabase/index.js.map +4 -4
- 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/utils/idempotency.d.ts +1 -1
- package/lib/supabase/utils/monitoring.d.ts +1 -1
- package/lib/supabase/utils/rateLimiter.d.ts +1 -1
- package/lib/vercel/api/ai/chat.d.ts +29 -0
- package/lib/vercel/api/ai/index.d.ts +1 -0
- package/lib/vercel/api/auth/index.d.ts +1 -1
- package/lib/vercel/api/billing/cancel.d.ts +1 -1
- package/lib/vercel/api/billing/change-plan.d.ts +1 -1
- package/lib/vercel/api/billing/create-checkout-session.d.ts +1 -1
- package/lib/vercel/api/billing/index.d.ts +1 -1
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +1 -1
- package/lib/vercel/api/billing/webhook-handler.d.ts +2 -2
- package/lib/vercel/api/config/constants.d.ts +9 -9
- package/lib/vercel/api/config/firebase-admin.d.ts +2 -2
- package/lib/vercel/api/config/index.d.ts +1 -1
- package/lib/vercel/api/crud/index.d.ts +1 -1
- package/lib/vercel/api/index.d.ts +2 -1
- package/lib/vercel/api/index.js +3 -2
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +1 -1
- package/lib/vercel/api/oauth/grant-github-access.d.ts +1 -1
- package/lib/vercel/api/oauth/index.d.ts +1 -1
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +1 -1
- package/lib/vercel/api/utils/cors.d.ts +4 -4
- package/lib/vercel/baseFunction.d.ts +2 -2
- package/package.json +38 -5
- 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 +70 -69
- 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 +79 -187
- package/src/firebase/billing/createCustomerPortal.ts +1 -1
- package/src/firebase/billing/healthCheck.ts +1 -1
- 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 -1
- 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 +2 -2
- 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 +6 -6
- 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 +6 -6
- 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/ai/__tests__/costTracker.test.ts +121 -0
- package/src/shared/ai/classifyAIError.ts +163 -0
- package/src/shared/ai/costTracker.ts +51 -0
- package/src/shared/ai/createAIRoute.ts +397 -0
- package/src/shared/ai/index.ts +8 -0
- package/src/shared/ai/resolveModelTier.ts +58 -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 +156 -11
- package/src/shared/billing/helpers/index.ts +1 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +13 -4
- package/src/shared/billing/helpers/updateUserSubscription.ts +4 -4
- package/src/shared/billing/idempotency.ts +9 -4
- package/src/shared/billing/index.ts +1 -1
- package/src/shared/billing/webhookHandler.ts +7 -7
- package/src/shared/email/createEmailRoute.ts +81 -0
- package/src/shared/email/index.ts +5 -0
- package/src/shared/email/provider.ts +31 -0
- package/src/shared/email/resendProvider.ts +56 -0
- package/src/shared/errorHandling.ts +12 -6
- package/src/shared/firebase.ts +7 -7
- package/src/shared/github.ts +49 -11
- package/src/shared/index.d.ts +9 -9
- package/src/shared/index.ts +3 -1
- package/src/shared/logger.ts +10 -8
- package/src/shared/metadata.ts +3 -3
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +1 -1
- package/src/shared/oauth/exchangeToken.ts +3 -2
- package/src/shared/oauth/grantAccess.ts +3 -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 +4 -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 +12 -9
- package/src/shared/utils/internal/validation.ts +5 -5
- 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 +3 -3
- package/src/supabase/ai/createAIFunction.ts +75 -0
- 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 +38 -2
- package/src/supabase/auth/setCustomClaims.ts +66 -5
- package/src/supabase/baseFunction.ts +29 -5
- package/src/supabase/billing/cancelSubscription.ts +2 -2
- package/src/supabase/billing/changePlan.ts +8 -3
- package/src/supabase/billing/createCheckoutSession.ts +18 -4
- package/src/supabase/billing/createCustomerPortal.ts +2 -2
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -2
- package/src/supabase/crud/aggregate.ts +2 -1
- package/src/supabase/crud/create.ts +2 -1
- package/src/supabase/crud/delete.ts +2 -1
- package/src/supabase/crud/get.ts +2 -1
- package/src/supabase/crud/index.ts +1 -1
- package/src/supabase/crud/list.ts +2 -1
- package/src/supabase/crud/update.ts +2 -1
- package/src/supabase/edgeFunction.ts +195 -0
- package/src/supabase/email/createEmailFunction.ts +75 -0
- package/src/supabase/helpers/authProvider.ts +2 -2
- package/src/supabase/index.ts +22 -2
- package/src/supabase/oauth/disconnect.ts +104 -0
- package/src/supabase/oauth/exchangeToken.ts +183 -0
- package/src/supabase/oauth/getConnections.ts +85 -0
- package/src/supabase/oauth/index.ts +15 -0
- package/src/supabase/oauth/refreshToken.ts +130 -0
- package/src/supabase/registerCrudFunctions.ts +30 -42
- package/src/supabase/utils/idempotency.ts +7 -3
- package/src/supabase/utils/monitoring.ts +1 -1
- package/src/supabase/utils/rateLimiter.ts +1 -1
- package/src/vercel/api/ai/chat.ts +77 -0
- package/src/vercel/api/ai/index.ts +1 -0
- 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 +2 -4
- 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 +30 -7
- 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 +11 -4
- 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 +2 -1
- package/src/vercel/api/oauth/check-github-access.ts +3 -3
- package/src/vercel/api/oauth/exchange-token.ts +25 -2
- 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 +10 -4
- package/src/vercel/baseFunction.ts +2 -2
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Set custom claims API handler
|
|
5
5
|
* @description Vercel API route for setting custom user claims
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -74,9 +74,7 @@ export function createSetCustomClaimsHandler(
|
|
|
74
74
|
);
|
|
75
75
|
if (disallowedKeys.length > 0) {
|
|
76
76
|
throw handleError(
|
|
77
|
-
new Error(
|
|
78
|
-
`Claim keys not allowed: ${disallowedKeys.join(', ')}`
|
|
79
|
-
)
|
|
77
|
+
new Error(`Claim keys not allowed: ${disallowedKeys.join(', ')}`)
|
|
80
78
|
);
|
|
81
79
|
}
|
|
82
80
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Vercel Cancel Subscription Handler
|
|
5
5
|
* @description Next.js API route wrapper for cancelSubscription
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -26,7 +26,7 @@ const cancelSubscriptionSchema = v.object({
|
|
|
26
26
|
* Business logic for canceling subscription
|
|
27
27
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
28
28
|
*
|
|
29
|
-
* @version 0.0
|
|
29
|
+
* @version 0.1.0
|
|
30
30
|
* @since 0.0.1
|
|
31
31
|
* @author AMBROISE PARK Consulting
|
|
32
32
|
*/
|
|
@@ -60,7 +60,7 @@ async function cancelSubscriptionLogic(
|
|
|
60
60
|
/**
|
|
61
61
|
* Cancel subscription function
|
|
62
62
|
*
|
|
63
|
-
* @version 0.0
|
|
63
|
+
* @version 0.1.0
|
|
64
64
|
* @since 0.0.1
|
|
65
65
|
* @author AMBROISE PARK Consulting
|
|
66
66
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Vercel Change Plan Handler
|
|
5
5
|
* @description Next.js API route wrapper for changePlan
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -32,7 +32,7 @@ const changePlanSchema = v.object({
|
|
|
32
32
|
* Business logic for changing subscription plan
|
|
33
33
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
34
34
|
*
|
|
35
|
-
* @version 0.0
|
|
35
|
+
* @version 0.1.0
|
|
36
36
|
* @since 0.0.1
|
|
37
37
|
* @author AMBROISE PARK Consulting
|
|
38
38
|
*/
|
|
@@ -124,7 +124,7 @@ async function changePlanLogic(
|
|
|
124
124
|
/**
|
|
125
125
|
* Change subscription plan function
|
|
126
126
|
*
|
|
127
|
-
* @version 0.0
|
|
127
|
+
* @version 0.1.0
|
|
128
128
|
* @since 0.0.1
|
|
129
129
|
* @author AMBROISE PARK Consulting
|
|
130
130
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Create checkout session API handler
|
|
5
5
|
* @description Vercel API route for creating Stripe checkout sessions
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
import { getFirebaseAdminAuth } from '@donotdev/firebase/server';
|
|
18
18
|
|
|
19
19
|
import { createCheckoutAlgorithm } from '../../../shared/billing/createCheckout.js';
|
|
20
|
-
import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
|
|
20
|
+
import { initStripe, stripe, validateStripeEnvironment } from '../../../shared/utils.js';
|
|
21
21
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
22
22
|
|
|
23
23
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
@@ -27,7 +27,7 @@ import type * as v from 'valibot';
|
|
|
27
27
|
* Business logic for creating checkout sessions
|
|
28
28
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
29
29
|
*
|
|
30
|
-
* @version 0.0
|
|
30
|
+
* @version 0.1.0
|
|
31
31
|
* @since 0.0.1
|
|
32
32
|
* @author AMBROISE PARK Consulting
|
|
33
33
|
*/
|
|
@@ -38,15 +38,38 @@ async function createCheckoutSessionLogic(
|
|
|
38
38
|
context: { uid: string },
|
|
39
39
|
billingConfig: StripeBackConfig
|
|
40
40
|
) {
|
|
41
|
-
//
|
|
41
|
+
// Initialize Stripe with env var
|
|
42
|
+
initStripe(process.env.STRIPE_SECRET_KEY || '');
|
|
42
43
|
validateStripeEnvironment();
|
|
43
44
|
|
|
44
45
|
// Create Stripe provider
|
|
45
46
|
const stripeProvider = {
|
|
46
|
-
async createCheckoutSession(params:
|
|
47
|
+
async createCheckoutSession(params: {
|
|
48
|
+
priceId?: string;
|
|
49
|
+
unitAmount?: number;
|
|
50
|
+
productName?: string;
|
|
51
|
+
currency?: string;
|
|
52
|
+
customerEmail?: string;
|
|
53
|
+
metadata: Record<string, string>;
|
|
54
|
+
allowPromotionCodes: boolean;
|
|
55
|
+
successUrl: string;
|
|
56
|
+
cancelUrl: string;
|
|
57
|
+
mode?: 'payment' | 'subscription';
|
|
58
|
+
}) {
|
|
47
59
|
const session = await stripe.checkout.sessions.create({
|
|
48
60
|
payment_method_types: ['card'],
|
|
49
|
-
line_items: [
|
|
61
|
+
line_items: [
|
|
62
|
+
params.priceId
|
|
63
|
+
? { price: params.priceId, quantity: 1 }
|
|
64
|
+
: {
|
|
65
|
+
price_data: {
|
|
66
|
+
currency: params.currency || 'eur',
|
|
67
|
+
unit_amount: params.unitAmount!,
|
|
68
|
+
product_data: { name: params.productName! },
|
|
69
|
+
},
|
|
70
|
+
quantity: 1,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
50
73
|
mode: params.mode || 'payment',
|
|
51
74
|
allow_promotion_codes: params.allowPromotionCodes,
|
|
52
75
|
success_url: params.successUrl,
|
|
@@ -81,7 +104,7 @@ async function createCheckoutSessionLogic(
|
|
|
81
104
|
* Vercel API handler for creating checkout sessions
|
|
82
105
|
* Base function handles all common concerns automatically
|
|
83
106
|
*
|
|
84
|
-
* @version 0.0
|
|
107
|
+
* @version 0.1.0
|
|
85
108
|
* @since 0.0.1
|
|
86
109
|
* @author AMBROISE PARK Consulting
|
|
87
110
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Stripe webhook handler API
|
|
5
5
|
* @description Vercel API route for handling Stripe webhook events
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -23,7 +23,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
23
23
|
/**
|
|
24
24
|
* Create Vercel webhook handler from billing config
|
|
25
25
|
*
|
|
26
|
-
* @version 0.0
|
|
26
|
+
* @version 0.1.0
|
|
27
27
|
* @since 0.0.1
|
|
28
28
|
* @author AMBROISE PARK Consulting
|
|
29
29
|
*/
|
|
@@ -45,6 +45,13 @@ export function createStripeWebhook(billingConfig: StripeBackConfig) {
|
|
|
45
45
|
throw new Error('STRIPE_WEBHOOK_SECRET not configured');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// Content-Length pre-check before streaming body
|
|
49
|
+
const contentLength = parseInt(req.headers['content-length'] || '0', 10);
|
|
50
|
+
if (contentLength > MAX_BODY_BYTES) {
|
|
51
|
+
res.status(413).json({ error: 'Payload too large' });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
// Get raw body
|
|
49
56
|
const rawBody = await getRawBody(req);
|
|
50
57
|
|
|
@@ -80,7 +87,7 @@ export function createStripeWebhook(billingConfig: StripeBackConfig) {
|
|
|
80
87
|
error: error instanceof Error ? error.message : String(error),
|
|
81
88
|
});
|
|
82
89
|
res.status(400).json({
|
|
83
|
-
error:
|
|
90
|
+
error: 'Webhook processing failed',
|
|
84
91
|
});
|
|
85
92
|
}
|
|
86
93
|
};
|
|
@@ -107,7 +114,7 @@ async function getRawBody(req: NextApiRequest): Promise<Buffer> {
|
|
|
107
114
|
/**
|
|
108
115
|
* Next.js API route configuration
|
|
109
116
|
*
|
|
110
|
-
* @version 0.0
|
|
117
|
+
* @version 0.1.0
|
|
111
118
|
* @since 0.0.1
|
|
112
119
|
* @author AMBROISE PARK Consulting
|
|
113
120
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Firebase Functions configuration constants
|
|
5
5
|
* @description DRY configuration for regions, timeouts, and other function settings
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* Default to eu-west1 for European users (France)
|
|
15
15
|
* Override with FIREBASE_REGION environment variable
|
|
16
16
|
*
|
|
17
|
-
* @version 0.0
|
|
17
|
+
* @version 0.1.0
|
|
18
18
|
* @since 0.0.1
|
|
19
19
|
* @author AMBROISE PARK Consulting
|
|
20
20
|
*/
|
|
@@ -23,7 +23,7 @@ export const FIREBASE_REGION = process.env.FIREBASE_REGION || 'europe-west1';
|
|
|
23
23
|
/**
|
|
24
24
|
* Common function configuration options
|
|
25
25
|
*
|
|
26
|
-
* @version 0.0
|
|
26
|
+
* @version 0.1.0
|
|
27
27
|
* @since 0.0.1
|
|
28
28
|
* @author AMBROISE PARK Consulting
|
|
29
29
|
*/
|
|
@@ -39,7 +39,7 @@ export const FUNCTION_CONFIG = {
|
|
|
39
39
|
/**
|
|
40
40
|
* Stripe-specific configuration
|
|
41
41
|
*
|
|
42
|
-
* @version 0.0
|
|
42
|
+
* @version 0.1.0
|
|
43
43
|
* @since 0.0.1
|
|
44
44
|
* @author AMBROISE PARK Consulting
|
|
45
45
|
*/
|
|
@@ -52,7 +52,7 @@ export const STRIPE_CONFIG = {
|
|
|
52
52
|
/**
|
|
53
53
|
* Auth-specific configuration
|
|
54
54
|
*
|
|
55
|
-
* @version 0.0
|
|
55
|
+
* @version 0.1.0
|
|
56
56
|
* @since 0.0.1
|
|
57
57
|
* @author AMBROISE PARK Consulting
|
|
58
58
|
*/
|
|
@@ -65,7 +65,7 @@ export const AUTH_CONFIG = {
|
|
|
65
65
|
/**
|
|
66
66
|
* Generic CRUD configuration
|
|
67
67
|
*
|
|
68
|
-
* @version 0.0
|
|
68
|
+
* @version 0.1.0
|
|
69
69
|
* @since 0.0.1
|
|
70
70
|
* @author AMBROISE PARK Consulting
|
|
71
71
|
*/
|
|
@@ -78,7 +78,7 @@ export const CRUD_CONFIG = {
|
|
|
78
78
|
/**
|
|
79
79
|
* Available Firebase regions for reference
|
|
80
80
|
*
|
|
81
|
-
* @version 0.0
|
|
81
|
+
* @version 0.1.0
|
|
82
82
|
* @since 0.0.1
|
|
83
83
|
* @author AMBROISE PARK Consulting
|
|
84
84
|
*/
|
|
@@ -105,7 +105,7 @@ export const AVAILABLE_REGIONS = {
|
|
|
105
105
|
/**
|
|
106
106
|
* Environment validation
|
|
107
107
|
*
|
|
108
|
-
* @version 0.0
|
|
108
|
+
* @version 0.1.0
|
|
109
109
|
* @since 0.0.1
|
|
110
110
|
* @author AMBROISE PARK Consulting
|
|
111
111
|
*/
|
|
@@ -127,7 +127,7 @@ export const validateEnvironment = () => {
|
|
|
127
127
|
/**
|
|
128
128
|
* Type for Firebase region keys
|
|
129
129
|
*
|
|
130
|
-
* @version 0.0
|
|
130
|
+
* @version 0.1.0
|
|
131
131
|
* @since 0.0.1
|
|
132
132
|
* @author AMBROISE PARK Consulting
|
|
133
133
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Firebase Admin SDK initialization for Vercel functions
|
|
5
5
|
* @description Re-exports provider functions for Vercel-specific access
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -17,7 +17,7 @@ import type { App } from 'firebase-admin/app';
|
|
|
17
17
|
* Initialize Firebase Admin SDK for Vercel environment
|
|
18
18
|
* Uses provider which handles service account credentials from environment variables
|
|
19
19
|
*
|
|
20
|
-
* @version 0.0
|
|
20
|
+
* @version 0.1.0
|
|
21
21
|
* @since 0.0.1
|
|
22
22
|
* @author AMBROISE PARK Consulting
|
|
23
23
|
*/
|
|
@@ -29,7 +29,7 @@ export async function initializeFirebaseAdmin(): Promise<App> {
|
|
|
29
29
|
* Get the initialized Firebase Admin app
|
|
30
30
|
* Initializes if not already done
|
|
31
31
|
*
|
|
32
|
-
* @version 0.0
|
|
32
|
+
* @version 0.1.0
|
|
33
33
|
* @since 0.0.1
|
|
34
34
|
* @author AMBROISE PARK Consulting
|
|
35
35
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Vercel API Functions
|
|
5
5
|
* @description Barrel exports for Vercel API route handlers. Provides centralized access to all Vercel API function modules.
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
package/src/vercel/api/index.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* @fileoverview Vercel API barrel exports
|
|
5
5
|
* @description Centralized exports for Vercel API functions
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
export * from './ai/index.js';
|
|
12
13
|
export * from './auth/index.js';
|
|
13
14
|
export * from './billing/index.js';
|
|
14
15
|
export * from './config/index.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Check GitHub access API handler
|
|
5
5
|
* @description Vercel API route for checking GitHub access status
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ import type * as v from 'valibot';
|
|
|
25
25
|
* Business logic for checking GitHub access
|
|
26
26
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
27
27
|
*
|
|
28
|
-
* @version 0.0
|
|
28
|
+
* @version 0.1.0
|
|
29
29
|
* @since 0.0.1
|
|
30
30
|
* @author AMBROISE PARK Consulting
|
|
31
31
|
*/
|
|
@@ -88,7 +88,7 @@ async function checkGitHubAccessLogic(
|
|
|
88
88
|
* Vercel API handler for checking GitHub access
|
|
89
89
|
* Base function handles all common concerns automatically
|
|
90
90
|
*
|
|
91
|
-
* @version 0.0
|
|
91
|
+
* @version 0.1.0
|
|
92
92
|
* @since 0.0.1
|
|
93
93
|
* @author AMBROISE PARK Consulting
|
|
94
94
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview OAuth token exchange API route
|
|
5
5
|
* @description Vercel API route for exchanging OAuth codes for tokens
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -25,6 +25,28 @@ import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
|
25
25
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
26
26
|
import type * as v from 'valibot';
|
|
27
27
|
|
|
28
|
+
/** Validate Mastodon instance URL to prevent SSRF */
|
|
29
|
+
function validateInstanceUrl(url: string): void {
|
|
30
|
+
const parsed = new URL(url);
|
|
31
|
+
if (parsed.protocol !== 'https:') {
|
|
32
|
+
throw new Error('Instance URL must use HTTPS');
|
|
33
|
+
}
|
|
34
|
+
const hostname = parsed.hostname;
|
|
35
|
+
if (
|
|
36
|
+
hostname === 'localhost' ||
|
|
37
|
+
hostname === '127.0.0.1' ||
|
|
38
|
+
hostname === '::1' ||
|
|
39
|
+
hostname.startsWith('10.') ||
|
|
40
|
+
hostname.startsWith('192.168.') ||
|
|
41
|
+
hostname.startsWith('172.') ||
|
|
42
|
+
hostname === '169.254.169.254' ||
|
|
43
|
+
hostname.endsWith('.internal') ||
|
|
44
|
+
hostname.endsWith('.local')
|
|
45
|
+
) {
|
|
46
|
+
throw new Error('Instance URL must not point to internal addresses');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
28
50
|
/**
|
|
29
51
|
* Business logic for exchanging OAuth tokens
|
|
30
52
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
@@ -42,6 +64,7 @@ async function exchangeTokenLogic(
|
|
|
42
64
|
|
|
43
65
|
// Special handling for Mastodon instances
|
|
44
66
|
if (provider === 'mastodon' && instance) {
|
|
67
|
+
validateInstanceUrl(instance);
|
|
45
68
|
tokenUrl = `${instance.replace(/\/$/, '')}/oauth/token` as any;
|
|
46
69
|
}
|
|
47
70
|
|
|
@@ -131,7 +154,7 @@ async function exchangeTokenLogic(
|
|
|
131
154
|
|
|
132
155
|
// Validate required fields
|
|
133
156
|
if (!tokenData.access_token) {
|
|
134
|
-
console.error(`Invalid token response`, { provider, tokenData });
|
|
157
|
+
console.error(`Invalid token response`, { provider, hasAccessToken: !!tokenData?.access_token });
|
|
135
158
|
throw new Error('Provider returned invalid token format');
|
|
136
159
|
}
|
|
137
160
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Grant GitHub access API handler
|
|
5
5
|
* @description Vercel API route for granting GitHub access
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ import type * as v from 'valibot';
|
|
|
25
25
|
* Business logic for granting GitHub access
|
|
26
26
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
27
27
|
*
|
|
28
|
-
* @version 0.0
|
|
28
|
+
* @version 0.1.0
|
|
29
29
|
* @since 0.0.1
|
|
30
30
|
* @author AMBROISE PARK Consulting
|
|
31
31
|
*/
|
|
@@ -106,7 +106,7 @@ async function grantGitHubAccessLogic(
|
|
|
106
106
|
* Vercel API handler for granting GitHub access
|
|
107
107
|
* Base function handles all common concerns automatically
|
|
108
108
|
*
|
|
109
|
-
* @version 0.0
|
|
109
|
+
* @version 0.1.0
|
|
110
110
|
* @since 0.0.1
|
|
111
111
|
* @author AMBROISE PARK Consulting
|
|
112
112
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview CORS utilities for Vercel API
|
|
5
5
|
* @description CORS configuration and handling for Vercel functions
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
25
25
|
* the wildcard origin remains valid. Consumers that need credentialed cross-origin requests
|
|
26
26
|
* must replace '*' with their specific origin and re-add Allow-Credentials:true.
|
|
27
27
|
*
|
|
28
|
-
* @version 0.0
|
|
28
|
+
* @version 0.1.0
|
|
29
29
|
* @since 0.0.1
|
|
30
30
|
* @author AMBROISE PARK Consulting
|
|
31
31
|
*/
|
|
@@ -41,7 +41,7 @@ export const corsHeaders = {
|
|
|
41
41
|
/**
|
|
42
42
|
* Handle CORS preflight requests
|
|
43
43
|
*
|
|
44
|
-
* @version 0.0
|
|
44
|
+
* @version 0.1.0
|
|
45
45
|
* @since 0.0.1
|
|
46
46
|
* @author AMBROISE PARK Consulting
|
|
47
47
|
*/
|
|
@@ -51,6 +51,12 @@ export function handleCors(req: NextApiRequest, res: NextApiResponse): boolean {
|
|
|
51
51
|
res.setHeader(key, value);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
// Warn if wildcard origin is used in production — consumers should override
|
|
55
|
+
const origin = corsHeaders['Access-Control-Allow-Origin'];
|
|
56
|
+
if (process.env.NODE_ENV === 'production' && origin === '*') {
|
|
57
|
+
console.warn('[DoNotDev] CORS origin is set to wildcard (*) in production. Override in your cors config.');
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
// Handle preflight OPTIONS request
|
|
55
61
|
if (req.method === 'OPTIONS') {
|
|
56
62
|
res.status(200).end();
|
|
@@ -63,7 +69,7 @@ export function handleCors(req: NextApiRequest, res: NextApiResponse): boolean {
|
|
|
63
69
|
/**
|
|
64
70
|
* Wrapper for Vercel API functions to automatically handle CORS
|
|
65
71
|
*
|
|
66
|
-
* @version 0.0
|
|
72
|
+
* @version 0.1.0
|
|
67
73
|
* @since 0.0.1
|
|
68
74
|
* @author AMBROISE PARK Consulting
|
|
69
75
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Base Vercel function that handles all common concerns
|
|
5
5
|
* @description Rate limiting, monitoring, authentication, validation - all in one place
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -28,7 +28,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
28
28
|
* Base Vercel function that handles all common concerns
|
|
29
29
|
* Users just provide their business logic
|
|
30
30
|
*
|
|
31
|
-
* @version 0.0
|
|
31
|
+
* @version 0.1.0
|
|
32
32
|
* @since 0.0.1
|
|
33
33
|
* @author AMBROISE PARK Consulting
|
|
34
34
|
*/
|