@donotdev/functions 0.1.42 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -14
- package/lib/chunks/chunk-2JL3GDTO.js +151 -0
- package/lib/chunks/chunk-2JL3GDTO.js.map +7 -0
- package/lib/chunks/chunk-4TVLH2W2.js +22 -0
- package/lib/chunks/chunk-4TVLH2W2.js.map +7 -0
- package/lib/chunks/chunk-4U7QQWYG.js +22 -0
- package/lib/chunks/chunk-4U7QQWYG.js.map +7 -0
- package/lib/chunks/chunk-5DTPEM64.js +22 -0
- package/lib/chunks/chunk-5DTPEM64.js.map +7 -0
- package/lib/chunks/chunk-6CQXHNVL.js +22 -0
- package/lib/chunks/chunk-6CQXHNVL.js.map +7 -0
- package/lib/chunks/chunk-6DSCPZC6.js +22 -0
- package/lib/chunks/chunk-6DSCPZC6.js.map +7 -0
- package/lib/chunks/chunk-7E6TGWHU.js +22 -0
- package/lib/chunks/chunk-7E6TGWHU.js.map +7 -0
- package/lib/chunks/chunk-7LT32OWE.js +22 -0
- package/lib/chunks/chunk-7LT32OWE.js.map +7 -0
- package/lib/chunks/chunk-7VH2GJXT.js +151 -0
- package/lib/chunks/chunk-7VH2GJXT.js.map +7 -0
- package/lib/chunks/chunk-API5A4BV.js +22 -0
- package/lib/chunks/chunk-API5A4BV.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-BUP7SXPV.js +23 -0
- package/lib/chunks/chunk-BUP7SXPV.js.map +7 -0
- package/lib/chunks/chunk-BXKRI3JJ.js +22 -0
- package/lib/chunks/chunk-BXKRI3JJ.js.map +7 -0
- package/lib/chunks/chunk-FSLGZD7A.js +21 -0
- package/lib/chunks/chunk-FSLGZD7A.js.map +7 -0
- package/lib/chunks/chunk-GVLSPWDD.js +151 -0
- package/lib/chunks/chunk-GVLSPWDD.js.map +7 -0
- package/lib/chunks/chunk-GXQVWEFT.js +22 -0
- package/lib/chunks/chunk-GXQVWEFT.js.map +7 -0
- package/lib/chunks/chunk-HB7EGXVI.js +22 -0
- package/lib/chunks/chunk-HB7EGXVI.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-HM7XCMWW.js +22 -0
- package/lib/chunks/chunk-HM7XCMWW.js.map +7 -0
- package/lib/chunks/chunk-I7IOIL6U.js +151 -0
- package/lib/chunks/chunk-I7IOIL6U.js.map +7 -0
- package/lib/chunks/chunk-IFOYVSPU.js +22 -0
- package/lib/chunks/chunk-IFOYVSPU.js.map +7 -0
- package/lib/chunks/chunk-JTAGPPPL.js +22 -0
- package/lib/chunks/chunk-JTAGPPPL.js.map +7 -0
- package/lib/chunks/chunk-MZ232FUE.js +22 -0
- package/lib/chunks/chunk-MZ232FUE.js.map +7 -0
- package/lib/chunks/chunk-NE5ZTUUZ.js +22 -0
- package/lib/chunks/chunk-NE5ZTUUZ.js.map +7 -0
- package/lib/chunks/chunk-NP2AN2TV.js +22 -0
- package/lib/chunks/chunk-NP2AN2TV.js.map +7 -0
- package/lib/chunks/chunk-QJAU2MWV.js +22 -0
- package/lib/chunks/chunk-QJAU2MWV.js.map +7 -0
- package/lib/chunks/chunk-RM7DV6IQ.js +23 -0
- package/lib/chunks/chunk-RM7DV6IQ.js.map +7 -0
- package/lib/chunks/chunk-RQZGIZHD.js +151 -0
- package/lib/chunks/chunk-RQZGIZHD.js.map +7 -0
- package/lib/chunks/chunk-TBEDQLOB.js +23 -0
- package/lib/chunks/chunk-TBEDQLOB.js.map +7 -0
- package/lib/chunks/chunk-TMHBP3HB.js +22 -0
- package/lib/chunks/chunk-TMHBP3HB.js.map +7 -0
- package/lib/chunks/chunk-UH4L3EF3.js +151 -0
- package/lib/chunks/chunk-UH4L3EF3.js.map +7 -0
- package/lib/chunks/chunk-UJBIU6TL.js +22 -0
- package/lib/chunks/chunk-UJBIU6TL.js.map +7 -0
- package/lib/chunks/chunk-VKEYW3NT.js +22 -0
- package/lib/chunks/chunk-VKEYW3NT.js.map +7 -0
- package/lib/chunks/chunk-XGXBMXJ6.js +22 -0
- package/lib/chunks/chunk-XGXBMXJ6.js.map +7 -0
- package/lib/chunks/chunk-Y44NEQQG.js +22 -0
- package/lib/chunks/chunk-Y44NEQQG.js.map +7 -0
- package/lib/chunks/chunk-ZVU3KPXI.js +22 -0
- package/lib/chunks/chunk-ZVU3KPXI.js.map +7 -0
- package/lib/chunks/monitoring-AGCSU3FI.js +22 -0
- package/lib/chunks/monitoring-AGCSU3FI.js.map +7 -0
- package/lib/chunks/monitoring-PVQMFL34.js +22 -0
- package/lib/chunks/monitoring-PVQMFL34.js.map +7 -0
- package/lib/chunks/monitoring-V7FZXTTW.js +22 -0
- package/lib/chunks/monitoring-V7FZXTTW.js.map +7 -0
- package/lib/chunks/rateLimiter-6KO7AIZP.js +22 -0
- package/lib/chunks/rateLimiter-6KO7AIZP.js.map +7 -0
- package/lib/chunks/rateLimiter-OXVBFW5C.js +22 -0
- package/lib/chunks/rateLimiter-OXVBFW5C.js.map +7 -0
- package/lib/chunks/rateLimiter-U45OMTWR.js +22 -0
- package/lib/chunks/rateLimiter-U45OMTWR.js.map +7 -0
- package/lib/chunks/server-32A5RH4C.js +22 -0
- package/lib/chunks/server-32A5RH4C.js.map +7 -0
- package/lib/chunks/server-7HDAP5DL.js +22 -0
- package/lib/chunks/server-7HDAP5DL.js.map +7 -0
- package/lib/chunks/server-S2IMFOY7.js +22 -0
- package/lib/chunks/server-S2IMFOY7.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/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/createCheckoutSession.d.ts +2 -2
- package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
- 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/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/list.d.ts +1 -1
- package/lib/firebase/crud/update.d.ts +1 -9
- package/lib/firebase/index.js +1 -5
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/githubAccess.d.ts +2 -2
- package/lib/firebase/registerCrudFunctions.d.ts +9 -1
- 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/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 +32 -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/supabaseIdempotency.d.ts +32 -0
- package/lib/shared/billing/tierWebhookEvents.d.ts +54 -0
- package/lib/shared/billing/webhookHandler.d.ts +28 -20
- package/lib/shared/index.js +1 -6
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/utils/functionWrapper.d.ts +1 -1
- package/lib/shared/utils/internal/auth.d.ts +38 -1
- package/lib/shared/utils/internal/rateLimiter.d.ts +8 -0
- package/lib/shared/utils/schemaValidation.d.ts +1 -1
- package/lib/shared/utils/vercelHelpers.d.ts +8 -0
- package/lib/shared/utils.d.ts +4 -17
- package/lib/supabase/baseFunction.d.ts +1 -1
- package/lib/supabase/billing/stripeWebhook.d.ts +34 -0
- package/lib/supabase/crud/bulk.d.ts +1 -1
- package/lib/supabase/crud/entityStore.d.ts +71 -0
- package/lib/supabase/crud/index.d.ts +2 -0
- package/lib/supabase/helpers/authProvider.d.ts +5 -5
- package/lib/supabase/index.d.ts +10 -2
- package/lib/supabase/index.js +1 -3
- package/lib/supabase/index.js.map +4 -4
- package/lib/supabase/utils/rateLimiter.d.ts +1 -1
- package/lib/vercel/api/ai/chat.d.ts +0 -9
- 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/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/firebase-admin.d.ts +8 -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/list.d.ts +8 -0
- package/lib/vercel/api/crud/update.d.ts +8 -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/revoke-github-access.d.ts +1 -1
- 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 +1 -2
- package/src/firebase/billing/changePlan.ts +2 -3
- package/src/firebase/billing/createCheckoutSession.ts +30 -56
- package/src/firebase/billing/createCustomerPortal.ts +4 -5
- package/src/firebase/billing/healthCheck.ts +0 -0
- package/src/firebase/billing/index.ts +8 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +2 -3
- package/src/firebase/billing/webhookHandler.ts +20 -4
- 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 -3
- 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 +2 -1
- 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 +407 -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/helpers/index.ts +0 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +7 -9
- package/src/shared/billing/helpers/updateUserSubscription.ts +3 -36
- package/src/shared/billing/idempotency.ts +253 -150
- 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/supabaseIdempotency.ts +228 -0
- package/src/shared/billing/tierWebhookEvents.ts +432 -0
- package/src/shared/billing/webhookHandler.ts +188 -385
- 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/schemaValidation.ts +1 -2
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +14 -31
- 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/createCheckoutSession.ts +10 -36
- package/src/supabase/billing/refreshSubscriptionStatus.ts +1 -2
- 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/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 +3 -4
- package/src/vercel/api/billing/create-checkout-session.ts +42 -68
- package/src/vercel/api/billing/customer-portal.ts +2 -4
- package/src/vercel/api/billing/index.ts +4 -2
- package/src/vercel/api/billing/refresh-subscription-status.ts +21 -6
- package/src/vercel/api/billing/webhook-handler.ts +31 -25
- 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
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
* @since 0.5.0
|
|
21
21
|
* @author AMBROISE PARK Consulting
|
|
22
22
|
*/
|
|
23
|
-
import type { ServerRateLimitConfig as RateLimitConfig, ServerRateLimitResult as RateLimitResult } from '@donotdev/core';
|
|
24
23
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
24
|
+
import type { ServerRateLimitConfig as RateLimitConfig, ServerRateLimitResult as RateLimitResult } from '@donotdev/core';
|
|
25
25
|
export type { RateLimitConfig, RateLimitResult };
|
|
26
26
|
/**
|
|
27
27
|
* PostgreSQL function required for atomic rate limiting.
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview AI Chat - Vercel Route Handler
|
|
3
|
-
* @description Next.js App Router route handler for AI chat.
|
|
4
|
-
* Uses Vercel AI SDK via shared handleAIRequest.
|
|
5
|
-
*
|
|
6
|
-
* @version 0.1.0
|
|
7
|
-
* @since 0.1.0
|
|
8
|
-
* @author AMBROISE PARK Consulting
|
|
9
|
-
*/
|
|
10
1
|
import type { AIRouteConfig } from '@donotdev/core/server';
|
|
11
2
|
/**
|
|
12
3
|
* Create a Next.js App Router POST handler for AI chat.
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Get custom claims API handler
|
|
3
|
+
* @description Vercel API route for retrieving custom user claims
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Get user authentication status API handler
|
|
3
|
+
* @description Vercel API route for retrieving user authentication status
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Remove custom claims API handler
|
|
3
|
+
* @description Vercel API route for removing custom user claims
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Set custom claims API handler
|
|
3
|
+
* @description Vercel API route for setting custom user claims
|
|
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
|
export interface SetCustomClaimsHandlerOptions {
|
|
3
11
|
/** Explicit allowlist of claim keys users may set on themselves. Required. */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Backend wiring for Vercel billing handlers
|
|
3
|
+
* @description Vercel functions run against either Firebase or Supabase. The
|
|
4
|
+
* backend decides token verification, rate limiting, user claims and webhook
|
|
5
|
+
* idempotency storage. It is always explicit: there is no auto-detection.
|
|
6
|
+
* Firebase modules are imported on the Firebase path only: `firebase-admin`
|
|
7
|
+
* and `firebase-functions` are optional peers a Supabase app does not install.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.2.0
|
|
10
|
+
* @since 0.2.0
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
import type { BillingAuthProvider } from '@donotdev/core/server';
|
|
14
|
+
import type { IdempotencyStore } from '../../../shared/billing/idempotency.js';
|
|
15
|
+
import type { AuthProvider as AuthBackend } from '../../../shared/utils/internal/auth.js';
|
|
16
|
+
/**
|
|
17
|
+
* Options of the Vercel billing handler factories.
|
|
18
|
+
*
|
|
19
|
+
* @version 0.2.0
|
|
20
|
+
* @since 0.2.0
|
|
21
|
+
* @author AMBROISE PARK Consulting
|
|
22
|
+
*/
|
|
23
|
+
export interface VercelBillingOptions {
|
|
24
|
+
/** Auth and data backend of the app (validated at runtime) */
|
|
25
|
+
backend: AuthBackend;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the user-claims provider and the webhook idempotency store of a backend.
|
|
29
|
+
*
|
|
30
|
+
* @throws DoNotDevError (`invalid-argument`) when `backend` is not `'firebase'` or `'supabase'`
|
|
31
|
+
*
|
|
32
|
+
* @version 0.2.0
|
|
33
|
+
* @since 0.2.0
|
|
34
|
+
* @author AMBROISE PARK Consulting
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveBillingBackend(backend: VercelBillingOptions['backend']): Promise<{
|
|
37
|
+
authProvider: BillingAuthProvider;
|
|
38
|
+
idempotencyStore: IdempotencyStore;
|
|
39
|
+
}>;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Vercel Cancel Subscription Handler
|
|
3
|
+
* @description Next.js API route wrapper for cancelSubscription
|
|
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
|
/**
|
|
3
11
|
* Cancel subscription function
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Vercel Change Plan Handler
|
|
3
|
+
* @description Next.js API route wrapper for changePlan
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
2
9
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
10
|
+
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
3
11
|
/**
|
|
4
12
|
* Change subscription plan function
|
|
5
13
|
*
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Create checkout session API handler
|
|
3
|
+
* @description Vercel API route for creating Stripe checkout sessions.
|
|
4
|
+
* Delegates to the shared createCheckoutAlgorithm (SSOT).
|
|
5
|
+
*
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
2
10
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
3
|
-
import type
|
|
11
|
+
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
12
|
+
import type { VercelBillingOptions } from './backend.js';
|
|
4
13
|
/**
|
|
5
14
|
* Vercel API handler for creating checkout sessions
|
|
6
|
-
* Base function handles all common concerns automatically
|
|
7
15
|
*
|
|
8
|
-
* @
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // api/billing/create-checkout-session.ts
|
|
19
|
+
* import { createCheckoutSession } from '@donotdev/functions/vercel';
|
|
20
|
+
* import { billingConfig } from '../../config/billing';
|
|
21
|
+
*
|
|
22
|
+
* export default createCheckoutSession(billingConfig, { backend: 'supabase' });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param billingConfig - App back config
|
|
26
|
+
* @param options - Backend of the app (token verification, rate limiting, user lookup)
|
|
27
|
+
*
|
|
28
|
+
* @version 0.2.0
|
|
9
29
|
* @since 0.0.1
|
|
10
30
|
* @author AMBROISE PARK Consulting
|
|
11
31
|
*/
|
|
12
|
-
declare
|
|
13
|
-
export default createCheckoutSession;
|
|
32
|
+
export declare function createCheckoutSession(billingConfig: StripeBackConfig, options: VercelBillingOptions): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Vercel Customer Portal Handler
|
|
3
|
+
* @description Next.js API route wrapper for createCustomerPortal
|
|
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
|
declare const createCustomerPortal: () => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
3
11
|
export default createCustomerPortal;
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export { createCheckoutSession } from './create-checkout-session.js';
|
|
10
|
+
export { createStripeWebhook } from './webhook-handler.js';
|
|
11
|
+
export type { VercelBillingOptions } from './backend.js';
|
|
12
|
+
export { default as refreshSubscriptionStatus } from './refresh-subscription-status.js';
|
|
11
13
|
export * from '../../../shared/billing/helpers/index.js';
|
|
12
14
|
export { default as cancelSubscription } from './cancel.js';
|
|
13
15
|
export { default as changePlan } from './change-plan.js';
|
|
@@ -6,12 +6,28 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
-
import * as v from 'valibot';
|
|
10
9
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
11
10
|
import type Stripe from 'stripe';
|
|
11
|
+
import * as v from 'valibot';
|
|
12
12
|
/**
|
|
13
|
-
* Vercel API handler for refreshing subscription
|
|
14
|
-
*
|
|
13
|
+
* Vercel API handler factory for refreshing the caller's subscription claims
|
|
14
|
+
* from Stripe. Firebase backend only (reads and writes Firebase Auth custom
|
|
15
|
+
* claims); `firebase-admin` is loaded on the first request.
|
|
16
|
+
* Base function handles validation, auth, rate limiting and monitoring.
|
|
17
|
+
*
|
|
18
|
+
* @param customSchema - Optional request body schema (default: `{ userId: string }`)
|
|
19
|
+
* @returns Next.js API route handler
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { refreshSubscriptionStatus } from '@donotdev/functions/vercel';
|
|
24
|
+
*
|
|
25
|
+
* export default refreshSubscriptionStatus();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @version 0.1.0
|
|
29
|
+
* @since 0.0.1
|
|
30
|
+
* @author AMBROISE PARK Consulting
|
|
15
31
|
*/
|
|
16
32
|
declare const refreshSubscriptionStatus: (customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>) => (req: NextApiRequest, res: NextApiResponse) => Promise<{
|
|
17
33
|
success: boolean;
|
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Stripe webhook handler API
|
|
3
|
+
* @description Vercel API route for handling Stripe webhook events
|
|
4
|
+
*
|
|
5
|
+
* @version 0.2.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
2
9
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
10
|
+
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
11
|
+
import type { VercelBillingOptions } from './backend.js';
|
|
3
12
|
/**
|
|
4
|
-
* Create Vercel webhook handler from billing config
|
|
13
|
+
* Create Vercel webhook handler from billing config.
|
|
14
|
+
* Idempotency storage and user claims follow `options.backend`.
|
|
15
|
+
* Any failure answers non-2xx so Stripe retries the event.
|
|
5
16
|
*
|
|
6
|
-
* @
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // api/billing/stripe-webhook.ts
|
|
20
|
+
* import { createStripeWebhook } from '@donotdev/functions/vercel';
|
|
21
|
+
* import { billingConfig } from '../../config/billing';
|
|
22
|
+
*
|
|
23
|
+
* export const config = { api: { bodyParser: false } };
|
|
24
|
+
* export default createStripeWebhook(billingConfig, { backend: 'supabase' });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @version 0.2.0
|
|
7
28
|
* @since 0.0.1
|
|
8
29
|
* @author AMBROISE PARK Consulting
|
|
9
30
|
*/
|
|
10
|
-
export declare function createStripeWebhook(billingConfig: StripeBackConfig): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
31
|
+
export declare function createStripeWebhook(billingConfig: StripeBackConfig, options: VercelBillingOptions): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
11
32
|
/**
|
|
12
33
|
* Next.js API route configuration
|
|
13
34
|
*
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Firebase Admin SDK initialization for Vercel functions
|
|
3
|
+
* @description Re-exports provider functions for Vercel-specific access
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
1
9
|
import type { App } from 'firebase-admin/app';
|
|
2
10
|
/**
|
|
3
11
|
* Initialize Firebase Admin SDK for Vercel environment
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Vercel bulk / transactional CRUD API handler.
|
|
3
|
+
* @description Vercel Pages-Router API route for `POST /api/crud/:collection/bulk`.
|
|
4
|
+
* Thin HTTP adapter on top of the shared `executeBulk` orchestrator —
|
|
5
|
+
* assembles a firebase-admin `runTransaction` as the target `transact`
|
|
6
|
+
* callback.
|
|
7
|
+
*
|
|
8
|
+
* Unlike the Firebase Callable and Supabase Edge variants, this endpoint
|
|
9
|
+
* does not carry entity schemas on the wire (the REST-CRUD client hits
|
|
10
|
+
* `${baseUrl}/${collection}/bulk` with raw ops only). The wire contract
|
|
11
|
+
* is still frozen: structural parsing via `BulkRequestSchema`, collision
|
|
12
|
+
* rejection, empty no-op, id preservation in input order.
|
|
13
|
+
*
|
|
14
|
+
* @version 0.2.0
|
|
15
|
+
* @since 0.2.0
|
|
16
|
+
* @author AMBROISE PARK Consulting
|
|
17
|
+
*/
|
|
1
18
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
19
|
/**
|
|
3
20
|
* HTTP handler for `POST /api/crud/:collection/bulk`.
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Create entity API handler
|
|
3
|
+
* @description Vercel API route for creating entities
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Delete entity API handler
|
|
3
|
+
* @description Vercel API route for deleting entities
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Get entity API handler
|
|
3
|
+
* @description Vercel API route for retrieving entities
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview List entities API handler
|
|
3
|
+
* @description Vercel API route for listing entities
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Update entity API handler
|
|
3
|
+
* @description Vercel API route for updating entities
|
|
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
|
export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|