@donotdev/functions 0.1.44 → 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
|
@@ -9,18 +9,17 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
13
|
+
|
|
12
14
|
import { HIDDEN_STATUSES } from '@donotdev/core/server';
|
|
13
15
|
import type { ListEntityData } from '@donotdev/core/server';
|
|
14
|
-
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
15
16
|
|
|
16
17
|
import { handleError } from '../../../shared/errorHandling.js';
|
|
17
|
-
import { transformFirestoreData } from '../../../shared/
|
|
18
|
-
import { filterVisibleFields } from '../../../shared/
|
|
18
|
+
import { transformFirestoreData } from '../../../shared/firebase.js';
|
|
19
|
+
import { filterVisibleFields } from '../../../shared/schema.js';
|
|
19
20
|
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
20
21
|
import { validateCollectionName } from '../../../shared/utils.js';
|
|
21
22
|
|
|
22
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
23
|
-
|
|
24
23
|
export default async function handler(
|
|
25
24
|
req: NextApiRequest,
|
|
26
25
|
res: NextApiResponse
|
|
@@ -50,6 +49,8 @@ export default async function handler(
|
|
|
50
49
|
validateCollectionName(schema.metadata.collection);
|
|
51
50
|
|
|
52
51
|
// Get documents from Firestore
|
|
52
|
+
const { getFirebaseAdminFirestore } =
|
|
53
|
+
await import('@donotdev/firebase/server');
|
|
53
54
|
const db = getFirebaseAdminFirestore();
|
|
54
55
|
let query: FirebaseFirestore.Query<FirebaseFirestore.DocumentData> =
|
|
55
56
|
db.collection(schema.metadata.collection);
|
|
@@ -9,24 +9,23 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
13
|
+
|
|
12
14
|
import { DEFAULT_STATUS_VALUE } from '@donotdev/core/server';
|
|
13
15
|
import type { UpdateEntityData } from '@donotdev/core/server';
|
|
14
|
-
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
15
16
|
|
|
16
17
|
import { handleError } from '../../../shared/errorHandling.js';
|
|
17
18
|
import {
|
|
18
19
|
prepareForFirestore,
|
|
19
20
|
transformFirestoreData,
|
|
20
|
-
} from '../../../shared/
|
|
21
|
-
import { updateMetadata } from '../../../shared/
|
|
21
|
+
} from '../../../shared/firebase.js';
|
|
22
|
+
import { updateMetadata } from '../../../shared/metadata.js';
|
|
22
23
|
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
23
24
|
import {
|
|
24
25
|
validateCollectionName,
|
|
25
26
|
validateDocument,
|
|
26
27
|
} from '../../../shared/utils.js';
|
|
27
28
|
|
|
28
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
29
|
-
|
|
30
29
|
export default async function handler(
|
|
31
30
|
req: NextApiRequest,
|
|
32
31
|
res: NextApiResponse
|
|
@@ -48,6 +47,8 @@ export default async function handler(
|
|
|
48
47
|
// W22: Validate collection name from client-supplied schema
|
|
49
48
|
validateCollectionName(schema.metadata.collection);
|
|
50
49
|
|
|
50
|
+
const { getFirebaseAdminFirestore } =
|
|
51
|
+
await import('@donotdev/firebase/server');
|
|
51
52
|
const db = getFirebaseAdminFirestore();
|
|
52
53
|
|
|
53
54
|
// Get current document to merge with payload for status check
|
|
@@ -9,18 +9,17 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
13
|
+
import type * as v from 'valibot';
|
|
14
|
+
|
|
12
15
|
import {
|
|
13
16
|
checkGitHubAccessSchema,
|
|
14
17
|
type CheckGitHubAccessRequest,
|
|
15
18
|
} from '@donotdev/core/server';
|
|
16
|
-
import { getFirebaseAdminAuth } from '@donotdev/firebase/server';
|
|
17
19
|
|
|
18
|
-
import { GitHubApiService } from '../../../shared/
|
|
20
|
+
import { GitHubApiService } from '../../../shared/github.js';
|
|
19
21
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
20
22
|
|
|
21
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
22
|
-
import type * as v from 'valibot';
|
|
23
|
-
|
|
24
23
|
/**
|
|
25
24
|
* Business logic for checking GitHub access
|
|
26
25
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
@@ -63,6 +62,7 @@ async function checkGitHubAccessLogic(
|
|
|
63
62
|
);
|
|
64
63
|
|
|
65
64
|
// Also check custom claims for access record
|
|
65
|
+
const { getFirebaseAdminAuth } = await import('@donotdev/firebase/server');
|
|
66
66
|
const user = await getFirebaseAdminAuth().getUser(userId);
|
|
67
67
|
const customClaims = user.customClaims || {};
|
|
68
68
|
const githubAccess =
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
13
|
+
import type * as v from 'valibot';
|
|
14
|
+
|
|
12
15
|
import {
|
|
13
16
|
OAUTH_PARTNERS,
|
|
14
17
|
exchangeTokenSchema,
|
|
@@ -22,9 +25,6 @@ import {
|
|
|
22
25
|
} from '../../../shared/utils.js';
|
|
23
26
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
24
27
|
|
|
25
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
26
|
-
import type * as v from 'valibot';
|
|
27
|
-
|
|
28
28
|
/** Validate Mastodon instance URL to prevent SSRF */
|
|
29
29
|
function validateInstanceUrl(url: string): void {
|
|
30
30
|
const parsed = new URL(url);
|
|
@@ -9,18 +9,17 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
13
|
+
import type * as v from 'valibot';
|
|
14
|
+
|
|
12
15
|
import {
|
|
13
16
|
grantGitHubAccessSchema,
|
|
14
17
|
type GrantGitHubAccessRequest,
|
|
15
18
|
} from '@donotdev/core/server';
|
|
16
|
-
import { getFirebaseAdminAuth } from '@donotdev/firebase/server';
|
|
17
19
|
|
|
18
|
-
import { GitHubApiService } from '../../../shared/
|
|
20
|
+
import { GitHubApiService } from '../../../shared/github.js';
|
|
19
21
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
20
22
|
|
|
21
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
22
|
-
import type * as v from 'valibot';
|
|
23
|
-
|
|
24
23
|
/**
|
|
25
24
|
* Business logic for granting GitHub access
|
|
26
25
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
@@ -70,6 +69,7 @@ async function grantGitHubAccessLogic(
|
|
|
70
69
|
|
|
71
70
|
// Update user's custom claims if provided
|
|
72
71
|
if (customClaims) {
|
|
72
|
+
const { getFirebaseAdminAuth } = await import('@donotdev/firebase/server');
|
|
73
73
|
const user = await getFirebaseAdminAuth().getUser(userId);
|
|
74
74
|
const updatedClaims = {
|
|
75
75
|
...user.customClaims,
|
|
@@ -9,20 +9,18 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
12
13
|
import * as v from 'valibot';
|
|
13
14
|
|
|
14
15
|
import {
|
|
15
16
|
revokeGitHubAccessSchema,
|
|
16
17
|
type RevokeGitHubAccessRequest,
|
|
17
18
|
} from '@donotdev/core/server';
|
|
18
|
-
import { getFirebaseAdminAuth } from '@donotdev/firebase/server';
|
|
19
19
|
|
|
20
20
|
import { handleError } from '../../../shared/errorHandling.js';
|
|
21
|
-
import { GitHubApiService } from '../../../shared/
|
|
21
|
+
import { GitHubApiService } from '../../../shared/github.js';
|
|
22
22
|
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
23
23
|
|
|
24
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
25
|
-
|
|
26
24
|
export default async function handler(
|
|
27
25
|
req: NextApiRequest,
|
|
28
26
|
res: NextApiResponse,
|
|
@@ -86,6 +84,7 @@ export default async function handler(
|
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
// Remove from user's custom claims
|
|
87
|
+
const { getFirebaseAdminAuth } = await import('@donotdev/firebase/server');
|
|
89
88
|
const user = await getFirebaseAdminAuth().getUser(userId);
|
|
90
89
|
const customClaims = user.customClaims || {};
|
|
91
90
|
|
|
@@ -9,25 +9,32 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
12
13
|
import * as v from 'valibot';
|
|
13
14
|
|
|
14
15
|
import type { SecurityContext } from '@donotdev/core';
|
|
15
16
|
|
|
17
|
+
import { getSupabaseAdmin } from './supabaseAdmin.js';
|
|
16
18
|
import { handleError, DoNotDevError } from '../shared/errorHandling.js';
|
|
17
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
parseAuthBackend,
|
|
21
|
+
verifyAuthToken,
|
|
22
|
+
} from '../shared/utils/internal/auth.js';
|
|
23
|
+
import type { AuthProvider } from '../shared/utils/internal/auth.js';
|
|
18
24
|
import { recordPaymentMetrics } from '../shared/utils/internal/monitoring.js';
|
|
19
25
|
import {
|
|
20
26
|
checkRateLimitWithFirestore,
|
|
21
27
|
DEFAULT_RATE_LIMITS,
|
|
22
28
|
} from '../shared/utils/internal/rateLimiter.js';
|
|
23
|
-
|
|
24
|
-
import type { AuthProvider } from '../shared/utils/internal/auth.js';
|
|
25
|
-
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
29
|
+
import { checkRateLimitWithPostgres } from '../supabase/utils/rateLimiter.js';
|
|
26
30
|
|
|
27
31
|
/**
|
|
28
32
|
* Base Vercel function that handles all common concerns
|
|
29
33
|
* Users just provide their business logic
|
|
30
34
|
*
|
|
35
|
+
* @throws DoNotDevError (`invalid-argument`) at construction when `provider` is
|
|
36
|
+
* neither `'firebase'` nor `'supabase'`
|
|
37
|
+
*
|
|
31
38
|
* @version 0.1.0
|
|
32
39
|
* @since 0.0.1
|
|
33
40
|
* @author AMBROISE PARK Consulting
|
|
@@ -48,6 +55,9 @@ export function createVercelBaseFunction<TRequest, TResponse>(
|
|
|
48
55
|
/** Auth provider for token verification. Auto-detects via provider registry if omitted. */
|
|
49
56
|
provider?: AuthProvider
|
|
50
57
|
) {
|
|
58
|
+
// Fail at route construction: an unknown backend must never run as Firebase
|
|
59
|
+
if (provider !== undefined) parseAuthBackend(provider);
|
|
60
|
+
|
|
51
61
|
return async (
|
|
52
62
|
req: NextApiRequest,
|
|
53
63
|
res: NextApiResponse
|
|
@@ -77,10 +87,15 @@ export function createVercelBaseFunction<TRequest, TResponse>(
|
|
|
77
87
|
const rateLimitKey = `${operation}_${uid}`;
|
|
78
88
|
const rateLimitConfig =
|
|
79
89
|
(DEFAULT_RATE_LIMITS as any)[operation] || DEFAULT_RATE_LIMITS.api;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
// Rate-limit storage follows the auth backend (Postgres for Supabase)
|
|
91
|
+
const rateLimitResult =
|
|
92
|
+
provider === 'supabase'
|
|
93
|
+
? await checkRateLimitWithPostgres(
|
|
94
|
+
await getSupabaseAdmin(),
|
|
95
|
+
rateLimitKey,
|
|
96
|
+
rateLimitConfig
|
|
97
|
+
)
|
|
98
|
+
: await checkRateLimitWithFirestore(rateLimitKey, rateLimitConfig);
|
|
84
99
|
|
|
85
100
|
if (!rateLimitResult.allowed) {
|
|
86
101
|
security?.audit({
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// packages/functions/src/vercel/supabaseAdmin.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Supabase admin client for Vercel functions
|
|
5
|
+
* @description Lazily created service-role client for Vercel functions backed by
|
|
6
|
+
* Supabase. `@supabase/supabase-js` is imported on first use only, so
|
|
7
|
+
* Firebase-backed deployments never load it.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.2.0
|
|
10
|
+
* @since 0.2.0
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
15
|
+
|
|
16
|
+
let cached: SupabaseClient | null = null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get the service-role Supabase client (`SUPABASE_URL` + `SUPABASE_SECRET_KEY`
|
|
20
|
+
* or the legacy `SUPABASE_SERVICE_ROLE_KEY`).
|
|
21
|
+
*
|
|
22
|
+
* @throws When the environment variables are missing
|
|
23
|
+
*
|
|
24
|
+
* @version 0.2.0
|
|
25
|
+
* @since 0.2.0
|
|
26
|
+
* @author AMBROISE PARK Consulting
|
|
27
|
+
*/
|
|
28
|
+
export async function getSupabaseAdmin(): Promise<SupabaseClient> {
|
|
29
|
+
if (cached) return cached;
|
|
30
|
+
|
|
31
|
+
const supabaseUrl = process.env.SUPABASE_URL;
|
|
32
|
+
const secretKey =
|
|
33
|
+
process.env.SUPABASE_SECRET_KEY || process.env.SUPABASE_SERVICE_ROLE_KEY;
|
|
34
|
+
if (!supabaseUrl || !secretKey) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'Missing SUPABASE_URL or SUPABASE_SECRET_KEY/SUPABASE_SERVICE_ROLE_KEY environment variables'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { createClient } = await import('@supabase/supabase-js');
|
|
41
|
+
cached = createClient(supabaseUrl, secretKey, {
|
|
42
|
+
auth: { autoRefreshToken: false, persistSession: false },
|
|
43
|
+
});
|
|
44
|
+
return cached;
|
|
45
|
+
}
|