@donotdev/functions 0.0.19 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -3
- package/lib/firebase/auth/getCustomClaims.d.ts +25 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +29 -0
- package/lib/firebase/auth/index.d.ts +12 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +28 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +34 -0
- package/lib/firebase/baseFunction.d.ts +26 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +10 -0
- package/lib/firebase/billing/changePlan.d.ts +13 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +21 -0
- package/lib/firebase/billing/createCustomerPortal.d.ts +19 -0
- package/lib/firebase/billing/healthCheck.d.ts +5 -0
- package/lib/firebase/billing/index.d.ts +18 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +19 -0
- package/lib/firebase/billing/webhookHandler.d.ts +6 -0
- package/lib/firebase/config/constants.d.ts +89 -0
- package/lib/firebase/config/index.d.ts +9 -0
- package/lib/firebase/config/secrets.d.ts +15 -0
- package/lib/firebase/crud/aggregate.d.ts +98 -0
- package/lib/firebase/crud/create.d.ts +16 -0
- package/lib/firebase/crud/delete.d.ts +20 -0
- package/lib/firebase/crud/get.d.ts +24 -0
- package/lib/firebase/crud/index.d.ts +14 -0
- package/lib/firebase/crud/list.d.ts +25 -0
- package/lib/firebase/crud/update.d.ts +25 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +30 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +36 -0
- package/lib/firebase/helpers/index.d.ts +10 -0
- package/lib/firebase/index.d.ts +17 -0
- package/lib/firebase/index.js +25 -9110
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +12 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +9 -0
- package/lib/firebase/oauth/getConnections.d.ts +11 -0
- package/lib/firebase/oauth/githubAccess.d.ts +83 -0
- package/lib/firebase/oauth/index.d.ts +13 -0
- package/lib/firebase/oauth/refreshToken.d.ts +9 -0
- package/lib/firebase/registerCrudFunctions.d.ts +32 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +14 -0
- package/lib/firebase/scheduled/index.d.ts +9 -0
- package/lib/shared/billing/createCheckout.d.ts +50 -0
- package/lib/shared/billing/helpers/index.d.ts +10 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +34 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +45 -0
- package/lib/shared/billing/idempotency.d.ts +22 -0
- package/lib/shared/billing/index.d.ts +11 -0
- package/lib/shared/billing/webhookHandler.d.ts +37 -0
- package/lib/shared/errorHandling.d.ts +14 -0
- package/lib/shared/firebase.d.ts +73 -0
- package/lib/shared/github.d.ts +128 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +25 -6927
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +133 -0
- package/lib/shared/metadata.d.ts +36 -0
- package/lib/shared/oauth/exchangeToken.d.ts +24 -0
- package/lib/shared/oauth/grantAccess.d.ts +30 -0
- package/lib/shared/oauth/index.d.ts +10 -0
- package/lib/shared/schema.d.ts +56 -0
- package/lib/shared/utils/detectFirestore.d.ts +31 -0
- package/lib/shared/utils/external/date.d.ts +36 -0
- package/lib/shared/utils/external/index.d.ts +11 -0
- package/lib/shared/utils/external/references.d.ts +12 -0
- package/lib/shared/utils/external/subscription.d.ts +41 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +23 -0
- package/lib/shared/utils/functionWrapper.d.ts +36 -0
- package/lib/shared/utils/index.d.ts +14 -0
- package/lib/shared/utils/internal/auth.d.ts +57 -0
- package/lib/shared/utils/internal/firebase.d.ts +5 -0
- package/lib/shared/utils/internal/idempotency.d.ts +21 -0
- package/lib/shared/utils/internal/index.d.ts +14 -0
- package/lib/shared/utils/internal/monitoring.d.ts +80 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +82 -0
- package/lib/shared/utils/internal/validation.d.ts +43 -0
- package/lib/shared/utils/schemaValidation.d.ts +60 -0
- package/lib/shared/utils/validation.d.ts +98 -0
- package/lib/shared/utils/vercelHelpers.d.ts +18 -0
- package/lib/shared/utils.d.ts +234 -0
- package/lib/shared/validation.d.ts +16 -0
- package/lib/supabase/auth/deleteAccount.d.ts +16 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +18 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +18 -0
- package/lib/supabase/baseFunction.d.ts +43 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +9 -0
- package/lib/supabase/billing/changePlan.d.ts +11 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +11 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +9 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +9 -0
- package/lib/supabase/crud/aggregate.d.ts +27 -0
- package/lib/supabase/crud/create.d.ts +23 -0
- package/lib/supabase/crud/delete.d.ts +30 -0
- package/lib/supabase/crud/get.d.ts +23 -0
- package/lib/supabase/crud/index.d.ts +20 -0
- package/lib/supabase/crud/list.d.ts +33 -0
- package/lib/supabase/crud/update.d.ts +24 -0
- package/lib/supabase/helpers/authProvider.d.ts +22 -0
- package/lib/supabase/index.d.ts +30 -0
- package/lib/supabase/index.js +23 -0
- package/lib/supabase/index.js.map +7 -0
- package/lib/supabase/oauth/disconnect.d.ts +13 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +13 -0
- package/lib/supabase/oauth/getConnections.d.ts +13 -0
- package/lib/supabase/oauth/index.d.ts +12 -0
- package/lib/supabase/oauth/refreshToken.d.ts +13 -0
- package/lib/supabase/registerCrudFunctions.d.ts +24 -0
- package/lib/supabase/utils/idempotency.d.ts +36 -0
- package/lib/supabase/utils/monitoring.d.ts +59 -0
- package/lib/supabase/utils/rateLimiter.d.ts +56 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +2 -0
- package/lib/vercel/api/auth/index.d.ts +12 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +10 -0
- package/lib/vercel/api/billing/cancel.d.ts +10 -0
- package/lib/vercel/api/billing/change-plan.d.ts +11 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +13 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +3 -0
- package/lib/vercel/api/billing/index.d.ts +14 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +31 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +22 -0
- package/lib/vercel/api/config/constants.d.ts +103 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +19 -0
- package/lib/vercel/api/config/index.d.ts +10 -0
- package/lib/vercel/api/crud/create.d.ts +2 -0
- package/lib/vercel/api/crud/delete.d.ts +2 -0
- package/lib/vercel/api/crud/get.d.ts +2 -0
- package/lib/vercel/api/crud/index.d.ts +13 -0
- package/lib/vercel/api/crud/list.d.ts +2 -0
- package/lib/vercel/api/crud/update.d.ts +2 -0
- package/lib/vercel/api/index.d.ts +13 -0
- package/lib/vercel/api/index.js +22 -4790
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/index.d.ts +12 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +11 -0
- package/lib/vercel/api/utils/cors.d.ts +49 -0
- package/lib/vercel/baseFunction.d.ts +25 -0
- package/package.json +4 -4
- package/src/firebase/auth/getCustomClaims.ts +3 -3
- package/src/firebase/auth/getUserAuthStatus.ts +3 -3
- package/src/firebase/auth/index.ts +1 -1
- package/src/firebase/auth/removeCustomClaims.ts +3 -3
- package/src/firebase/auth/setCustomClaims.ts +130 -84
- package/src/firebase/baseFunction.ts +2 -2
- package/src/firebase/billing/cancelSubscription.ts +3 -3
- package/src/firebase/billing/changePlan.ts +3 -3
- package/src/firebase/billing/createCheckoutSession.ts +1 -1
- package/src/firebase/billing/createCustomerPortal.ts +1 -1
- package/src/firebase/billing/healthCheck.ts +8 -24
- package/src/firebase/billing/index.d.ts +11 -11
- package/src/firebase/billing/index.ts +1 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -3
- package/src/firebase/billing/webhookHandler.ts +1 -2
- package/src/firebase/config/constants.ts +4 -4
- package/src/firebase/config/index.ts +1 -1
- package/src/firebase/config/secrets.ts +1 -1
- package/src/firebase/crud/aggregate.ts +2 -2
- package/src/firebase/crud/create.ts +19 -4
- package/src/firebase/crud/delete.ts +3 -3
- package/src/firebase/crud/get.ts +1 -1
- package/src/firebase/crud/index.ts +1 -1
- package/src/firebase/crud/list.ts +1 -1
- package/src/firebase/crud/update.ts +2 -2
- package/src/firebase/helpers/githubAccessHelper.ts +4 -4
- package/src/firebase/helpers/githubTeamAccessHelper.ts +3 -3
- package/src/firebase/helpers/index.ts +1 -1
- package/src/firebase/index.d.ts +9 -9
- package/src/firebase/index.ts +1 -1
- package/src/firebase/oauth/disconnect.ts +2 -2
- package/src/firebase/oauth/exchangeToken.ts +7 -7
- package/src/firebase/oauth/getConnections.ts +2 -2
- package/src/firebase/oauth/githubAccess.ts +10 -10
- package/src/firebase/oauth/index.ts +1 -1
- package/src/firebase/oauth/refreshToken.ts +2 -2
- package/src/firebase/registerCrudFunctions.ts +1 -1
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +1 -1
- package/src/firebase/scheduled/index.ts +1 -1
- package/src/shared/__tests__/auth.test.ts +46 -0
- package/src/shared/__tests__/errorHandling.test.ts +66 -1
- package/src/shared/__tests__/firebase.test.ts +293 -0
- package/src/shared/__tests__/internalValidation.test.ts +190 -0
- package/src/shared/__tests__/metadata.test.ts +66 -0
- package/src/shared/__tests__/schema.test.ts +219 -0
- package/src/shared/__tests__/schemaValidation.test.ts +72 -0
- package/src/shared/__tests__/subscription.test.ts +45 -0
- package/src/shared/__tests__/utils.test.ts +281 -0
- package/src/shared/__tests__/validation-env.test.ts +73 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +1 -1
- package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -1
- package/src/shared/billing/createCheckout.ts +10 -5
- package/src/shared/billing/helpers/index.ts +1 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +4 -4
- package/src/shared/billing/helpers/updateUserSubscription.ts +4 -4
- package/src/shared/billing/idempotency.ts +4 -4
- package/src/shared/billing/index.ts +1 -1
- package/src/shared/billing/webhookHandler.ts +7 -7
- package/src/shared/errorHandling.ts +2 -2
- package/src/shared/firebase.ts +7 -7
- package/src/shared/github.ts +11 -11
- package/src/shared/index.d.ts +9 -9
- package/src/shared/index.ts +1 -1
- package/src/shared/logger.ts +8 -8
- package/src/shared/metadata.ts +3 -3
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +1 -1
- package/src/shared/oauth/exchangeToken.ts +2 -2
- package/src/shared/oauth/grantAccess.ts +2 -2
- package/src/shared/oauth/index.ts +1 -1
- package/src/shared/schema.ts +4 -4
- package/src/shared/utils/__tests__/functionWrapper.test.ts +1 -1
- package/src/shared/utils/detectFirestore.ts +3 -3
- package/src/shared/utils/external/date.ts +5 -5
- package/src/shared/utils/external/index.ts +1 -1
- package/src/shared/utils/external/references.ts +2 -2
- package/src/shared/utils/external/subscription.ts +5 -5
- package/src/shared/utils/firebaseHelpers.ts +3 -3
- package/src/shared/utils/functionWrapper.ts +4 -4
- package/src/shared/utils/index.ts +1 -1
- package/src/shared/utils/internal/auth.ts +7 -7
- package/src/shared/utils/internal/firebase.ts +1 -1
- package/src/shared/utils/internal/idempotency.ts +3 -3
- package/src/shared/utils/internal/index.ts +1 -1
- package/src/shared/utils/internal/monitoring.ts +8 -8
- package/src/shared/utils/internal/rateLimiter.ts +6 -6
- package/src/shared/utils/internal/validation.ts +6 -6
- package/src/shared/utils/schemaValidation.ts +6 -6
- package/src/shared/utils/validation.ts +10 -10
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +19 -19
- package/src/shared/validation.ts +2 -2
- package/src/supabase/auth/deleteAccount.ts +2 -2
- package/src/supabase/auth/getCustomClaims.ts +2 -2
- package/src/supabase/auth/getUserAuthStatus.ts +2 -2
- package/src/supabase/auth/removeCustomClaims.ts +2 -2
- package/src/supabase/auth/setCustomClaims.ts +2 -2
- package/src/supabase/baseFunction.ts +3 -3
- package/src/supabase/billing/cancelSubscription.ts +2 -2
- package/src/supabase/billing/changePlan.ts +2 -2
- package/src/supabase/billing/createCheckoutSession.ts +2 -2
- package/src/supabase/billing/createCustomerPortal.ts +2 -2
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -2
- package/src/supabase/crud/aggregate.ts +11 -8
- package/src/supabase/crud/create.ts +2 -2
- package/src/supabase/crud/delete.ts +1 -1
- package/src/supabase/crud/get.ts +2 -2
- package/src/supabase/crud/index.ts +1 -1
- package/src/supabase/crud/list.ts +2 -2
- package/src/supabase/crud/update.ts +2 -2
- package/src/supabase/helpers/authProvider.ts +2 -2
- package/src/supabase/index.ts +10 -2
- package/src/supabase/oauth/disconnect.ts +104 -0
- package/src/supabase/oauth/exchangeToken.ts +152 -0
- package/src/supabase/oauth/getConnections.ts +85 -0
- package/src/supabase/oauth/index.ts +15 -0
- package/src/supabase/oauth/refreshToken.ts +131 -0
- package/src/supabase/registerCrudFunctions.ts +1 -1
- package/src/supabase/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -1
- package/src/supabase/utils/rateLimiter.ts +1 -1
- package/src/vercel/api/auth/get-custom-claims.ts +1 -1
- package/src/vercel/api/auth/get-user-auth-status.ts +1 -1
- package/src/vercel/api/auth/index.ts +1 -1
- package/src/vercel/api/auth/remove-custom-claims.ts +1 -1
- package/src/vercel/api/auth/set-custom-claims.ts +69 -24
- package/src/vercel/api/billing/cancel.ts +3 -3
- package/src/vercel/api/billing/change-plan.ts +3 -3
- package/src/vercel/api/billing/create-checkout-session.ts +3 -3
- package/src/vercel/api/billing/customer-portal.ts +1 -1
- package/src/vercel/api/billing/index.ts +1 -1
- package/src/vercel/api/billing/refresh-subscription-status.ts +1 -1
- package/src/vercel/api/billing/webhook-handler.ts +3 -3
- package/src/vercel/api/config/constants.ts +9 -9
- package/src/vercel/api/config/firebase-admin.ts +3 -3
- package/src/vercel/api/config/index.ts +1 -1
- package/src/vercel/api/crud/create.ts +1 -1
- package/src/vercel/api/crud/delete.ts +1 -1
- package/src/vercel/api/crud/get.ts +1 -1
- package/src/vercel/api/crud/index.ts +1 -1
- package/src/vercel/api/crud/list.ts +1 -1
- package/src/vercel/api/crud/update.ts +1 -1
- package/src/vercel/api/index.d.ts +1 -1
- package/src/vercel/api/index.ts +1 -1
- package/src/vercel/api/oauth/check-github-access.ts +3 -3
- package/src/vercel/api/oauth/exchange-token.ts +1 -1
- package/src/vercel/api/oauth/grant-github-access.ts +3 -3
- package/src/vercel/api/oauth/index.ts +1 -1
- package/src/vercel/api/oauth/revoke-github-access.ts +1 -1
- package/src/vercel/api/utils/cors.ts +4 -4
- package/src/vercel/baseFunction.ts +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import type * as v from 'valibot';
|
|
3
|
+
/**
|
|
4
|
+
* Vercel API handler for checking GitHub access
|
|
5
|
+
* Base function handles all common concerns automatically
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.0.1
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
declare const checkGitHubAccess: (customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
12
|
+
export default checkGitHubAccess;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import type * as v from 'valibot';
|
|
3
|
+
/**
|
|
4
|
+
* Vercel API handler for exchanging OAuth tokens
|
|
5
|
+
* Base function handles all common concerns automatically
|
|
6
|
+
*/
|
|
7
|
+
declare const exchangeToken: (customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
8
|
+
export default exchangeToken;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import type * as v from 'valibot';
|
|
3
|
+
/**
|
|
4
|
+
* Vercel API handler for granting GitHub access
|
|
5
|
+
* Base function handles all common concerns automatically
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.0.1
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
declare const grantGitHubAccess: (customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
12
|
+
export default grantGitHubAccess;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Vercel API OAuth barrel exports
|
|
3
|
+
* @description Centralized exports for Vercel API OAuth functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
export * from './check-github-access.js';
|
|
10
|
+
export * from './exchange-token.js';
|
|
11
|
+
export * from './grant-github-access.js';
|
|
12
|
+
export * from './revoke-github-access.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Revoke GitHub access API handler
|
|
3
|
+
* @description Vercel API route for revoking GitHub access
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import * as v from 'valibot';
|
|
10
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
11
|
+
export default function handler(req: NextApiRequest, res: NextApiResponse, customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview CORS utilities for Vercel API
|
|
3
|
+
* @description CORS configuration and handling for Vercel functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
10
|
+
/**
|
|
11
|
+
* CORS configuration for Vercel functions.
|
|
12
|
+
*
|
|
13
|
+
* **Architecture decision — CORS wildcard (`*`) as framework default:**
|
|
14
|
+
* The wildcard origin is an intentional development-convenience default, not a
|
|
15
|
+
* security oversight. Consumer apps MUST override `allowedOrigins` in their
|
|
16
|
+
* deployment configuration for production environments. The framework provides
|
|
17
|
+
* `configureCors({ allowedOrigins: ['https://myapp.example'] })` for this purpose.
|
|
18
|
+
*
|
|
19
|
+
* C2: Allow-Credentials:true is incompatible with wildcard origin per the Fetch spec.
|
|
20
|
+
* Credentialed requests require an explicit origin. Removed Allow-Credentials header so
|
|
21
|
+
* the wildcard origin remains valid. Consumers that need credentialed cross-origin requests
|
|
22
|
+
* must replace '*' with their specific origin and re-add Allow-Credentials:true.
|
|
23
|
+
*
|
|
24
|
+
* @version 0.1.0
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
* @author AMBROISE PARK Consulting
|
|
27
|
+
*/
|
|
28
|
+
export declare const corsHeaders: {
|
|
29
|
+
'Access-Control-Allow-Origin': string;
|
|
30
|
+
'Access-Control-Allow-Methods': string;
|
|
31
|
+
'Access-Control-Allow-Headers': string;
|
|
32
|
+
'Access-Control-Max-Age': string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Handle CORS preflight requests
|
|
36
|
+
*
|
|
37
|
+
* @version 0.1.0
|
|
38
|
+
* @since 0.0.1
|
|
39
|
+
* @author AMBROISE PARK Consulting
|
|
40
|
+
*/
|
|
41
|
+
export declare function handleCors(req: NextApiRequest, res: NextApiResponse): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Wrapper for Vercel API functions to automatically handle CORS
|
|
44
|
+
*
|
|
45
|
+
* @version 0.1.0
|
|
46
|
+
* @since 0.0.1
|
|
47
|
+
* @author AMBROISE PARK Consulting
|
|
48
|
+
*/
|
|
49
|
+
export declare function withCors(handler: (req: NextApiRequest, res: NextApiResponse) => Promise<void>): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Base Vercel function that handles all common concerns
|
|
3
|
+
* @description Rate limiting, monitoring, authentication, validation - all in one place
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import * as v from 'valibot';
|
|
10
|
+
import type { SecurityContext } from '@donotdev/core';
|
|
11
|
+
import type { AuthProvider } from '../shared/utils/internal/auth.js';
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
13
|
+
/**
|
|
14
|
+
* Base Vercel function that handles all common concerns
|
|
15
|
+
* Users just provide their business logic
|
|
16
|
+
*
|
|
17
|
+
* @version 0.1.0
|
|
18
|
+
* @since 0.0.1
|
|
19
|
+
* @author AMBROISE PARK Consulting
|
|
20
|
+
*/
|
|
21
|
+
export declare function createVercelBaseFunction<TRequest, TResponse>(method: string, schema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, operation: string, businessLogic: (req: NextApiRequest, res: NextApiResponse, data: TRequest, context: {
|
|
22
|
+
uid: string;
|
|
23
|
+
}) => Promise<TResponse>, security?: SecurityContext,
|
|
24
|
+
/** Auth provider for token verification. Auto-detects via provider registry if omitted. */
|
|
25
|
+
provider?: AuthProvider): (req: NextApiRequest, res: NextApiResponse) => Promise<TResponse>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/functions",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Backend functions for DoNotDev Framework - Firebase, Vercel, and platform-agnostic implementations for auth, billing, CRUD, and OAuth",
|
|
6
6
|
"main": "./lib/firebase/index.js",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"serve": "firebase emulators:start --only functions"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@donotdev/core": "^0.0
|
|
51
|
-
"@donotdev/firebase": "^0.0
|
|
52
|
-
"@donotdev/supabase": "^0.0
|
|
50
|
+
"@donotdev/core": "^0.1.0",
|
|
51
|
+
"@donotdev/firebase": "^0.1.0",
|
|
52
|
+
"@donotdev/supabase": "^0.1.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@sentry/node": "^10.39.0",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Get custom claims Firebase function
|
|
5
5
|
* @description Firebase callable function for retrieving 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
|
*/
|
|
@@ -30,7 +30,7 @@ type GetCustomClaimsResponse = { customClaims: Record<string, any> };
|
|
|
30
30
|
* Business logic for getting custom claims
|
|
31
31
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
32
32
|
*
|
|
33
|
-
* @version 0.0
|
|
33
|
+
* @version 0.1.0
|
|
34
34
|
* @since 0.0.1
|
|
35
35
|
* @author AMBROISE PARK Consulting
|
|
36
36
|
*/
|
|
@@ -49,7 +49,7 @@ async function getCustomClaimsLogic(
|
|
|
49
49
|
* Gets user's custom claims
|
|
50
50
|
* Base function handles all common concerns automatically
|
|
51
51
|
*
|
|
52
|
-
* @version 0.0
|
|
52
|
+
* @version 0.1.0
|
|
53
53
|
* @since 0.0.1
|
|
54
54
|
* @author AMBROISE PARK Consulting
|
|
55
55
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Get user auth status Firebase function
|
|
5
5
|
* @description Firebase callable function for retrieving user authentication 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
|
*/
|
|
@@ -38,7 +38,7 @@ export type GetUserAuthStatusResponse = {
|
|
|
38
38
|
* Business logic for getting user auth status
|
|
39
39
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
40
40
|
*
|
|
41
|
-
* @version 0.0
|
|
41
|
+
* @version 0.1.0
|
|
42
42
|
* @since 0.0.1
|
|
43
43
|
* @author AMBROISE PARK Consulting
|
|
44
44
|
*/
|
|
@@ -64,7 +64,7 @@ async function getUserAuthStatusLogic(
|
|
|
64
64
|
* Gets user authentication status
|
|
65
65
|
* Base function handles all common concerns automatically
|
|
66
66
|
*
|
|
67
|
-
* @version 0.0
|
|
67
|
+
* @version 0.1.0
|
|
68
68
|
* @since 0.0.1
|
|
69
69
|
* @author AMBROISE PARK Consulting
|
|
70
70
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Remove custom claims Firebase function
|
|
5
5
|
* @description Firebase callable function for removing 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
|
*/
|
|
@@ -40,7 +40,7 @@ export type RemoveCustomClaimsResponse = {
|
|
|
40
40
|
* Business logic for removing custom claims
|
|
41
41
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
42
42
|
*
|
|
43
|
-
* @version 0.0
|
|
43
|
+
* @version 0.1.0
|
|
44
44
|
* @since 0.0.1
|
|
45
45
|
* @author AMBROISE PARK Consulting
|
|
46
46
|
*/
|
|
@@ -71,7 +71,7 @@ async function removeCustomClaimsLogic(
|
|
|
71
71
|
* Removes user's custom claims
|
|
72
72
|
* Base function handles all common concerns automatically
|
|
73
73
|
*
|
|
74
|
-
* @version 0.0
|
|
74
|
+
* @version 0.1.0
|
|
75
75
|
* @since 0.0.1
|
|
76
76
|
* @author AMBROISE PARK Consulting
|
|
77
77
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Set custom claims Firebase function
|
|
5
5
|
* @description Firebase callable function 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
|
*/
|
|
@@ -24,6 +24,23 @@ import type {
|
|
|
24
24
|
CallableRequest,
|
|
25
25
|
} from 'firebase-functions/v2/https';
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Claim keys that must NEVER be self-assignable — privilege escalation vectors.
|
|
29
|
+
*/
|
|
30
|
+
const BLOCKED_CLAIM_KEYS = new Set([
|
|
31
|
+
'admin',
|
|
32
|
+
'isAdmin',
|
|
33
|
+
'isSuper',
|
|
34
|
+
'isSuperAdmin',
|
|
35
|
+
'role',
|
|
36
|
+
'roles',
|
|
37
|
+
'permissions',
|
|
38
|
+
'superuser',
|
|
39
|
+
'moderator',
|
|
40
|
+
'staff',
|
|
41
|
+
'elevated',
|
|
42
|
+
]);
|
|
43
|
+
|
|
27
44
|
const setCustomClaimsSchema = v.object({
|
|
28
45
|
customClaims: v.record(v.string(), v.any()),
|
|
29
46
|
idempotencyKey: v.optional(v.string()),
|
|
@@ -37,121 +54,150 @@ export type SetCustomClaimsResponse = {
|
|
|
37
54
|
customClaims: Record<string, any>;
|
|
38
55
|
};
|
|
39
56
|
|
|
57
|
+
export interface SetCustomClaimsOptions {
|
|
58
|
+
/** Explicit allowlist of claim keys users may set on themselves. Required. */
|
|
59
|
+
allowedClaimKeys: string[];
|
|
60
|
+
customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>;
|
|
61
|
+
}
|
|
62
|
+
|
|
40
63
|
/**
|
|
41
64
|
* Business logic for setting custom claims
|
|
42
65
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
43
66
|
*
|
|
44
|
-
* @version 0.0
|
|
67
|
+
* @version 0.1.0
|
|
45
68
|
* @since 0.0.1
|
|
46
69
|
* @author AMBROISE PARK Consulting
|
|
47
70
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!customClaims || typeof customClaims !== 'object') {
|
|
58
|
-
throw new Error('customClaims must be an object');
|
|
59
|
-
}
|
|
71
|
+
function createSetCustomClaimsLogic(allowedKeys: Set<string>) {
|
|
72
|
+
return async function setCustomClaimsLogic(
|
|
73
|
+
data: SetCustomClaimsRequest,
|
|
74
|
+
context: {
|
|
75
|
+
uid: string;
|
|
76
|
+
request: CallableRequest<SetCustomClaimsRequest>;
|
|
77
|
+
}
|
|
78
|
+
) {
|
|
79
|
+
const { customClaims, idempotencyKey } = data;
|
|
60
80
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
typeof idempotencyKey !== 'string' ||
|
|
65
|
-
idempotencyKey.length === 0 ||
|
|
66
|
-
idempotencyKey.length > 256
|
|
67
|
-
) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
'idempotencyKey must be a non-empty string of at most 256 characters'
|
|
70
|
-
);
|
|
81
|
+
if (!customClaims || typeof customClaims !== 'object') {
|
|
82
|
+
throw new Error('customClaims must be an object');
|
|
71
83
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
|
|
85
|
+
const disallowedKeys = Object.keys(customClaims).filter(
|
|
86
|
+
(k) => !allowedKeys.has(k)
|
|
87
|
+
);
|
|
88
|
+
if (disallowedKeys.length > 0) {
|
|
89
|
+
throw new Error(`Claim keys not allowed: ${disallowedKeys.join(', ')}`);
|
|
76
90
|
}
|
|
77
|
-
}
|
|
78
91
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return;
|
|
92
|
+
// W17: Validate idempotency key to prevent oversized or malformed inputs.
|
|
93
|
+
if (idempotencyKey !== undefined) {
|
|
94
|
+
if (
|
|
95
|
+
typeof idempotencyKey !== 'string' ||
|
|
96
|
+
idempotencyKey.length === 0 ||
|
|
97
|
+
idempotencyKey.length > 256
|
|
98
|
+
) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'idempotencyKey must be a non-empty string of at most 256 characters'
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (!/^[\w\-.:@]+$/.test(idempotencyKey)) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
'idempotencyKey contains invalid characters (allowed: alphanumeric, -, _, ., :, @)'
|
|
106
|
+
);
|
|
95
107
|
}
|
|
96
|
-
tx.set(idempotencyRef, {
|
|
97
|
-
processing: true,
|
|
98
|
-
reservedAt: new Date().toISOString(),
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
if (alreadyProcessed) {
|
|
103
|
-
return existingResult as {
|
|
104
|
-
success: boolean;
|
|
105
|
-
customClaims: Record<string, any>;
|
|
106
|
-
};
|
|
107
108
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const user = await getFirebaseAdminAuth().getUser(context.uid);
|
|
111
|
-
const currentClaims = user.customClaims || {};
|
|
112
|
-
|
|
113
|
-
// Merge with existing claims
|
|
114
|
-
const updatedClaims = { ...currentClaims, ...customClaims };
|
|
115
109
|
|
|
116
|
-
|
|
110
|
+
// C9: Atomic idempotency check — reserve key in a transaction to eliminate TOCTOU race.
|
|
111
|
+
if (idempotencyKey) {
|
|
112
|
+
const db = getFirebaseAdminFirestore();
|
|
113
|
+
const idempotencyRef = db
|
|
114
|
+
.collection('idempotency')
|
|
115
|
+
.doc(`claims_${idempotencyKey}`);
|
|
116
|
+
|
|
117
|
+
let existingResult: unknown = undefined;
|
|
118
|
+
let alreadyProcessed = false;
|
|
119
|
+
|
|
120
|
+
await db.runTransaction(async (tx) => {
|
|
121
|
+
const idempotencyDoc = await tx.get(idempotencyRef);
|
|
122
|
+
if (idempotencyDoc.exists) {
|
|
123
|
+
existingResult = idempotencyDoc.data()?.result;
|
|
124
|
+
alreadyProcessed = true;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
tx.set(idempotencyRef, {
|
|
128
|
+
processing: true,
|
|
129
|
+
reservedAt: new Date().toISOString(),
|
|
130
|
+
});
|
|
131
|
+
});
|
|
117
132
|
|
|
118
|
-
|
|
133
|
+
if (alreadyProcessed) {
|
|
134
|
+
return existingResult as {
|
|
135
|
+
success: boolean;
|
|
136
|
+
customClaims: Record<string, any>;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
119
140
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
await
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
const user = await getFirebaseAdminAuth().getUser(context.uid);
|
|
142
|
+
const currentClaims = user.customClaims || {};
|
|
143
|
+
|
|
144
|
+
// Merge with existing claims
|
|
145
|
+
const updatedClaims = { ...currentClaims, ...customClaims };
|
|
146
|
+
|
|
147
|
+
await getFirebaseAdminAuth().setCustomUserClaims(
|
|
148
|
+
context.uid,
|
|
149
|
+
updatedClaims
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const result = { success: true, customClaims: updatedClaims };
|
|
153
|
+
|
|
154
|
+
// Store result for idempotency if key provided
|
|
155
|
+
if (idempotencyKey) {
|
|
156
|
+
const db = getFirebaseAdminFirestore();
|
|
157
|
+
const idempotencyRef = db
|
|
158
|
+
.collection('idempotency')
|
|
159
|
+
.doc(`claims_${idempotencyKey}`);
|
|
160
|
+
await idempotencyRef.set({
|
|
161
|
+
result,
|
|
162
|
+
processedAt: new Date().toISOString(),
|
|
163
|
+
processedBy: context.uid,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
132
166
|
|
|
133
|
-
|
|
167
|
+
return result;
|
|
168
|
+
};
|
|
134
169
|
}
|
|
135
170
|
|
|
136
171
|
/**
|
|
137
|
-
* Sets custom claims for a user
|
|
138
|
-
*
|
|
172
|
+
* Sets custom claims for a user, restricted to allowed keys.
|
|
173
|
+
* Consumers MUST specify which claim keys are self-assignable.
|
|
139
174
|
*
|
|
140
|
-
* @version 0.0
|
|
175
|
+
* @version 0.1.0
|
|
141
176
|
* @since 0.0.1
|
|
142
177
|
* @author AMBROISE PARK Consulting
|
|
143
178
|
*/
|
|
144
179
|
export const setCustomClaims = (
|
|
145
|
-
|
|
180
|
+
options: SetCustomClaimsOptions
|
|
146
181
|
): CallableFunction<
|
|
147
182
|
SetCustomClaimsRequest,
|
|
148
183
|
Promise<SetCustomClaimsResponse>
|
|
149
184
|
> => {
|
|
150
|
-
const
|
|
185
|
+
const allowedKeys = new Set(options.allowedClaimKeys);
|
|
186
|
+
|
|
187
|
+
// Fail fast if consumer accidentally allows a privilege key
|
|
188
|
+
for (const key of allowedKeys) {
|
|
189
|
+
if (BLOCKED_CLAIM_KEYS.has(key)) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`Claim key "${key}" is blocked — it is a privilege-escalation vector and cannot be self-assigned.`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const schema = options.customSchema || setCustomClaimsSchema;
|
|
151
197
|
return createBaseFunction(
|
|
152
198
|
AUTH_CONFIG,
|
|
153
199
|
schema,
|
|
154
200
|
'set_custom_claims',
|
|
155
|
-
|
|
201
|
+
createSetCustomClaimsLogic(allowedKeys)
|
|
156
202
|
);
|
|
157
203
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Base Firebase 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
|
*/
|
|
@@ -111,7 +111,7 @@ function getClientIp(request: CallableRequest<unknown>): string {
|
|
|
111
111
|
* @param businessLogic - The actual business logic to execute
|
|
112
112
|
* @param requiredRole - Minimum role required (default: 'user' for backwards compatibility)
|
|
113
113
|
*
|
|
114
|
-
* @version 0.0
|
|
114
|
+
* @version 0.1.0
|
|
115
115
|
* @since 0.0.1
|
|
116
116
|
* @author AMBROISE PARK Consulting
|
|
117
117
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Cancel Subscription Function
|
|
5
5
|
* @description Cancels user's subscription at period end (doesn't delete immediately)
|
|
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
|
*/
|
|
@@ -29,7 +29,7 @@ const cancelSubscriptionSchema = v.object({
|
|
|
29
29
|
* Business logic for canceling subscription
|
|
30
30
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
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
|
*/
|
|
@@ -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 Change Subscription Plan Function
|
|
5
5
|
* @description Upgrades or downgrades user's subscription plan with prorated billing
|
|
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
|
*/
|
|
@@ -38,7 +38,7 @@ const changePlanSchema = v.object({
|
|
|
38
38
|
* Business logic for changing subscription plan
|
|
39
39
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
40
40
|
*
|
|
41
|
-
* @version 0.0
|
|
41
|
+
* @version 0.1.0
|
|
42
42
|
* @since 0.0.1
|
|
43
43
|
* @author AMBROISE PARK Consulting
|
|
44
44
|
*/
|
|
@@ -140,7 +140,7 @@ async function changePlanLogic(
|
|
|
140
140
|
/**
|
|
141
141
|
* Change subscription plan function
|
|
142
142
|
*
|
|
143
|
-
* @version 0.0
|
|
143
|
+
* @version 0.1.0
|
|
144
144
|
* @since 0.0.1
|
|
145
145
|
* @author AMBROISE PARK Consulting
|
|
146
146
|
*/
|