@donotdev/functions 0.1.44 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -14
- package/lib/chunks/chunk-3F4BWKQD.js +22 -0
- package/lib/chunks/chunk-3F4BWKQD.js.map +7 -0
- package/lib/chunks/chunk-5IPULSUX.js +22 -0
- package/lib/chunks/chunk-5IPULSUX.js.map +7 -0
- package/lib/chunks/chunk-6USHTJED.js +22 -0
- package/lib/chunks/chunk-6USHTJED.js.map +7 -0
- package/lib/chunks/chunk-AYY7UXNI.js +22 -0
- package/lib/chunks/chunk-AYY7UXNI.js.map +7 -0
- package/lib/chunks/chunk-CXBSROEW.js +23 -0
- package/lib/chunks/chunk-CXBSROEW.js.map +7 -0
- package/lib/chunks/chunk-GYTCWMXV.js +22 -0
- package/lib/chunks/chunk-GYTCWMXV.js.map +7 -0
- package/lib/chunks/chunk-HLNYUAZH.js +22 -0
- package/lib/chunks/chunk-HLNYUAZH.js.map +7 -0
- package/lib/chunks/chunk-LCDLG4VG.js +151 -0
- package/lib/chunks/chunk-LCDLG4VG.js.map +7 -0
- package/lib/chunks/chunk-MQANUSY3.js +22 -0
- package/lib/chunks/chunk-MQANUSY3.js.map +7 -0
- package/lib/chunks/chunk-OFQVO3FD.js +22 -0
- package/lib/chunks/chunk-OFQVO3FD.js.map +7 -0
- package/lib/chunks/chunk-PWAGW4R6.js +22 -0
- package/lib/chunks/chunk-PWAGW4R6.js.map +7 -0
- package/lib/chunks/chunk-US2VOP4S.js +22 -0
- package/lib/chunks/chunk-US2VOP4S.js.map +7 -0
- package/lib/chunks/chunk-YTKDNZNW.js +22 -0
- package/lib/chunks/chunk-YTKDNZNW.js.map +7 -0
- package/lib/chunks/monitoring-E7JBYBHQ.js +22 -0
- package/lib/chunks/monitoring-E7JBYBHQ.js.map +7 -0
- package/lib/chunks/rateLimiter-SQISLOP5.js +22 -0
- package/lib/chunks/rateLimiter-SQISLOP5.js.map +7 -0
- package/lib/chunks/server-IQ5JNJOM.js +22 -0
- package/lib/chunks/server-IQ5JNJOM.js.map +7 -0
- package/lib/firebase/auth/getCustomClaims.d.ts +1 -1
- package/lib/firebase/auth/getUserAuthStatus.d.ts +1 -1
- package/lib/firebase/auth/index.d.ts +0 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/firebase/auth/setCustomClaims.d.ts +1 -1
- package/lib/firebase/baseFunction.d.ts +1 -1
- package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
- package/lib/firebase/billing/changePlan.d.ts +0 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +2 -2
- package/lib/firebase/billing/createCustomerPortal.d.ts +1 -1
- package/lib/firebase/billing/healthCheck.d.ts +0 -0
- package/lib/firebase/billing/index.d.ts +2 -1
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -8
- package/lib/firebase/billing/webhookHandler.d.ts +17 -2
- package/lib/firebase/config/constants.d.ts +0 -0
- package/lib/firebase/config/index.d.ts +0 -0
- package/lib/firebase/config/secrets.d.ts +0 -0
- package/lib/firebase/crud/aggregate.d.ts +0 -9
- package/lib/firebase/crud/bulk.d.ts +2 -2
- package/lib/firebase/crud/create.d.ts +1 -1
- package/lib/firebase/crud/delete.d.ts +1 -1
- package/lib/firebase/crud/get.d.ts +1 -1
- package/lib/firebase/crud/index.d.ts +0 -0
- package/lib/firebase/crud/list.d.ts +1 -1
- package/lib/firebase/crud/update.d.ts +1 -9
- package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/index.d.ts +0 -0
- package/lib/firebase/index.d.ts +0 -0
- package/lib/firebase/index.js +1 -5
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +0 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
- package/lib/firebase/oauth/getConnections.d.ts +0 -0
- package/lib/firebase/oauth/githubAccess.d.ts +2 -2
- package/lib/firebase/oauth/index.d.ts +0 -0
- package/lib/firebase/oauth/refreshToken.d.ts +0 -0
- package/lib/firebase/registerCrudFunctions.d.ts +9 -1
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
- package/lib/firebase/scheduled/index.d.ts +0 -0
- package/lib/shared/ai/classifyAIError.d.ts +0 -0
- package/lib/shared/ai/costTracker.d.ts +0 -0
- package/lib/shared/ai/createAIRoute.d.ts +0 -0
- package/lib/shared/ai/index.d.ts +0 -0
- package/lib/shared/ai/resolveModelTier.d.ts +0 -0
- package/lib/shared/billing/apiVersion.d.ts +22 -0
- package/lib/shared/billing/checkoutPrice.d.ts +27 -0
- package/lib/shared/billing/checkoutValidation.d.ts +89 -0
- package/lib/shared/billing/createCheckout.d.ts +73 -24
- package/lib/shared/billing/firestoreIdempotency.d.ts +13 -0
- package/lib/shared/billing/helpers/index.d.ts +0 -1
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +4 -4
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -29
- package/lib/shared/billing/idempotency.d.ts +21 -10
- package/lib/shared/billing/idempotencyContract.d.ts +121 -0
- package/lib/shared/billing/index.d.ts +2 -0
- package/lib/shared/billing/orderWebhook.d.ts +75 -0
- package/lib/shared/billing/stripeClient.d.ts +45 -0
- package/lib/shared/billing/supabaseIdempotency.d.ts +32 -0
- package/lib/shared/billing/tierWebhookEvents.d.ts +54 -0
- package/lib/shared/billing/webhookHandler.d.ts +29 -20
- package/lib/shared/email/createEmailRoute.d.ts +0 -0
- package/lib/shared/email/index.d.ts +0 -0
- package/lib/shared/email/provider.d.ts +0 -0
- package/lib/shared/email/resendProvider.d.ts +0 -0
- package/lib/shared/errorHandling.d.ts +0 -0
- package/lib/shared/firebase.d.ts +0 -0
- package/lib/shared/github.d.ts +0 -0
- package/lib/shared/index.d.ts +0 -0
- package/lib/shared/index.js +1 -6
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +0 -0
- package/lib/shared/metadata.d.ts +0 -0
- package/lib/shared/oauth/exchangeToken.d.ts +0 -0
- package/lib/shared/oauth/grantAccess.d.ts +0 -0
- package/lib/shared/oauth/index.d.ts +0 -0
- package/lib/shared/schema.d.ts +0 -0
- package/lib/shared/utils/detectFirestore.d.ts +0 -0
- package/lib/shared/utils/external/date.d.ts +0 -0
- package/lib/shared/utils/external/index.d.ts +0 -0
- package/lib/shared/utils/external/references.d.ts +0 -0
- package/lib/shared/utils/external/subscription.d.ts +0 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
- package/lib/shared/utils/functionWrapper.d.ts +1 -1
- package/lib/shared/utils/index.d.ts +0 -0
- package/lib/shared/utils/internal/auth.d.ts +38 -1
- package/lib/shared/utils/internal/firebase.d.ts +0 -0
- package/lib/shared/utils/internal/idempotency.d.ts +0 -0
- package/lib/shared/utils/internal/index.d.ts +0 -0
- package/lib/shared/utils/internal/monitoring.d.ts +0 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +8 -0
- package/lib/shared/utils/internal/validation.d.ts +0 -8
- package/lib/shared/utils/schemaValidation.d.ts +1 -1
- package/lib/shared/utils/validation.d.ts +0 -0
- package/lib/shared/utils/vercelHelpers.d.ts +8 -0
- package/lib/shared/utils.d.ts +0 -56
- package/lib/shared/validation.d.ts +0 -0
- package/lib/supabase/ai/createAIFunction.d.ts +0 -0
- package/lib/supabase/auth/deleteAccount.d.ts +0 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +0 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +0 -0
- package/lib/supabase/baseFunction.d.ts +1 -1
- package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
- package/lib/supabase/billing/changePlan.d.ts +0 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
- package/lib/supabase/billing/stripeWebhook.d.ts +34 -0
- package/lib/supabase/crud/aggregate.d.ts +0 -0
- package/lib/supabase/crud/bulk.d.ts +1 -1
- package/lib/supabase/crud/create.d.ts +0 -0
- package/lib/supabase/crud/delete.d.ts +0 -0
- package/lib/supabase/crud/entityStore.d.ts +71 -0
- package/lib/supabase/crud/get.d.ts +0 -0
- package/lib/supabase/crud/index.d.ts +2 -0
- package/lib/supabase/crud/list.d.ts +0 -8
- package/lib/supabase/crud/update.d.ts +0 -0
- package/lib/supabase/edgeFunction.d.ts +0 -0
- package/lib/supabase/email/createEmailFunction.d.ts +0 -0
- package/lib/supabase/helpers/authProvider.d.ts +5 -5
- package/lib/supabase/index.d.ts +11 -2
- package/lib/supabase/index.js +1 -3
- package/lib/supabase/index.js.map +4 -4
- package/lib/supabase/oauth/disconnect.d.ts +0 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
- package/lib/supabase/oauth/getConnections.d.ts +0 -0
- package/lib/supabase/oauth/index.d.ts +0 -0
- package/lib/supabase/oauth/refreshToken.d.ts +0 -0
- package/lib/supabase/registerCrudFunctions.d.ts +0 -0
- package/lib/supabase/utils/idempotency.d.ts +0 -0
- package/lib/supabase/utils/monitoring.d.ts +0 -0
- package/lib/supabase/utils/rateLimiter.d.ts +1 -1
- package/lib/vercel/api/ai/chat.d.ts +0 -9
- package/lib/vercel/api/ai/index.d.ts +0 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +8 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +8 -0
- package/lib/vercel/api/auth/index.d.ts +0 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +8 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +8 -0
- package/lib/vercel/api/billing/backend.d.ts +39 -0
- package/lib/vercel/api/billing/cancel.d.ts +8 -0
- package/lib/vercel/api/billing/change-plan.d.ts +9 -1
- package/lib/vercel/api/billing/create-checkout-session.d.ts +25 -6
- package/lib/vercel/api/billing/customer-portal.d.ts +8 -0
- package/lib/vercel/api/billing/index.d.ts +4 -2
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +19 -3
- package/lib/vercel/api/billing/webhook-handler.d.ts +25 -4
- package/lib/vercel/api/config/constants.d.ts +0 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +8 -0
- package/lib/vercel/api/config/index.d.ts +0 -0
- package/lib/vercel/api/crud/bulk.d.ts +17 -0
- package/lib/vercel/api/crud/create.d.ts +8 -0
- package/lib/vercel/api/crud/delete.d.ts +8 -0
- package/lib/vercel/api/crud/get.d.ts +8 -0
- package/lib/vercel/api/crud/index.d.ts +0 -0
- package/lib/vercel/api/crud/list.d.ts +8 -0
- package/lib/vercel/api/crud/update.d.ts +8 -0
- package/lib/vercel/api/index.d.ts +0 -0
- package/lib/vercel/api/index.js +1 -3
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +8 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +8 -0
- package/lib/vercel/api/oauth/index.d.ts +0 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +1 -1
- package/lib/vercel/api/utils/cors.d.ts +0 -0
- package/lib/vercel/baseFunction.d.ts +4 -1
- package/lib/vercel/supabaseAdmin.d.ts +22 -0
- package/package.json +25 -26
- package/src/firebase/auth/getCustomClaims.ts +4 -5
- package/src/firebase/auth/getUserAuthStatus.ts +4 -5
- package/src/firebase/auth/removeCustomClaims.ts +4 -5
- package/src/firebase/auth/setCustomClaims.ts +4 -5
- package/src/firebase/baseFunction.ts +4 -5
- package/src/firebase/billing/cancelSubscription.ts +2 -3
- package/src/firebase/billing/changePlan.ts +3 -8
- package/src/firebase/billing/createCheckoutSession.ts +31 -61
- package/src/firebase/billing/createCustomerPortal.ts +5 -6
- package/src/firebase/billing/healthCheck.ts +1 -1
- package/src/firebase/billing/index.ts +8 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -4
- package/src/firebase/billing/webhookHandler.ts +21 -5
- package/src/firebase/crud/__tests__/bulk.test.ts +11 -1
- package/src/firebase/crud/aggregate.ts +1 -2
- package/src/firebase/crud/bulk.ts +5 -6
- package/src/firebase/crud/create.ts +5 -6
- package/src/firebase/crud/delete.ts +4 -5
- package/src/firebase/crud/get.ts +4 -5
- package/src/firebase/crud/list.ts +4 -5
- package/src/firebase/crud/update.ts +5 -6
- package/src/firebase/oauth/githubAccess.ts +2 -3
- package/src/firebase/registerCrudFunctions.ts +2 -2
- package/src/shared/__tests__/auth.test.ts +0 -3
- package/src/shared/__tests__/bulkCore.test.ts +3 -2
- package/src/shared/__tests__/errorHandling.test.ts +2 -2
- package/src/shared/__tests__/idempotency.test.ts +282 -55
- package/src/shared/__tests__/internalValidation.test.ts +3 -42
- package/src/shared/__tests__/logger.test.ts +31 -0
- package/src/shared/__tests__/rateLimiter.test.ts +2 -8
- package/src/shared/__tests__/schemaValidation.test.ts +1 -1
- package/src/shared/__tests__/utils.test.ts +3 -2
- package/src/shared/__tests__/validation-env.test.ts +0 -0
- package/src/shared/ai/createAIRoute.ts +53 -30
- package/src/shared/billing/__tests__/checkoutValidation.test.ts +219 -0
- package/src/shared/billing/__tests__/createCheckout.compat.test.ts +349 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +454 -411
- package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +92 -0
- package/src/shared/billing/__tests__/webhookCorrectness.test.ts +387 -0
- package/src/shared/billing/__tests__/webhookHandler.test.ts +370 -23
- package/src/shared/billing/apiVersion.ts +25 -0
- package/src/shared/billing/checkoutPrice.ts +125 -0
- package/src/shared/billing/checkoutValidation.ts +284 -0
- package/src/shared/billing/createCheckout.ts +332 -196
- package/src/shared/billing/firestoreIdempotency.ts +189 -0
- package/src/shared/billing/helpers/index.ts +0 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +8 -10
- package/src/shared/billing/helpers/updateUserSubscription.ts +3 -36
- package/src/shared/billing/idempotency.ts +104 -168
- package/src/shared/billing/idempotencyContract.ts +135 -0
- package/src/shared/billing/index.ts +2 -0
- package/src/shared/billing/orderWebhook.ts +269 -0
- package/src/shared/billing/stripeClient.ts +91 -0
- package/src/shared/billing/supabaseIdempotency.ts +228 -0
- package/src/shared/billing/tierWebhookEvents.ts +432 -0
- package/src/shared/billing/webhookHandler.ts +189 -386
- package/src/shared/logger.ts +4 -6
- package/src/shared/utils/external/subscription.ts +0 -0
- package/src/shared/utils/firebaseHelpers.ts +2 -3
- package/src/shared/utils/functionWrapper.ts +1 -2
- package/src/shared/utils/internal/auth.ts +55 -7
- package/src/shared/utils/internal/monitoring.ts +17 -9
- package/src/shared/utils/internal/rateLimiter.ts +14 -5
- package/src/shared/utils/internal/validation.ts +0 -18
- package/src/shared/utils/schemaValidation.ts +1 -2
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +5 -99
- package/src/shared/validation.ts +1 -1
- package/src/supabase/__tests__/bulk.test.ts +3 -1
- package/src/supabase/__tests__/entityStore.test.ts +90 -0
- package/src/supabase/baseFunction.ts +1 -2
- package/src/supabase/billing/cancelSubscription.ts +1 -1
- package/src/supabase/billing/changePlan.ts +1 -1
- package/src/supabase/billing/createCheckoutSession.ts +11 -41
- package/src/supabase/billing/createCustomerPortal.ts +1 -1
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -7
- package/src/supabase/billing/stripeWebhook.ts +79 -0
- package/src/supabase/crud/aggregate.ts +1 -1
- package/src/supabase/crud/bulk.ts +3 -7
- package/src/supabase/crud/create.ts +1 -1
- package/src/supabase/crud/entityStore.ts +240 -0
- package/src/supabase/crud/index.ts +8 -0
- package/src/supabase/crud/list.ts +2 -0
- package/src/supabase/crud/update.ts +1 -1
- package/src/supabase/helpers/authProvider.ts +6 -5
- package/src/supabase/index.ts +26 -0
- package/src/supabase/utils/rateLimiter.ts +2 -2
- package/src/vercel/__tests__/bulk.test.ts +24 -21
- package/src/vercel/__tests__/firebaseOptional.test.ts +64 -0
- package/src/vercel/api/ai/chat.ts +2 -1
- package/src/vercel/api/auth/get-custom-claims.ts +2 -3
- package/src/vercel/api/auth/get-user-auth-status.ts +2 -3
- package/src/vercel/api/auth/remove-custom-claims.ts +2 -3
- package/src/vercel/api/auth/set-custom-claims.ts +3 -3
- package/src/vercel/api/billing/backend.ts +72 -0
- package/src/vercel/api/billing/cancel.ts +2 -4
- package/src/vercel/api/billing/change-plan.ts +4 -5
- package/src/vercel/api/billing/create-checkout-session.ts +43 -73
- package/src/vercel/api/billing/customer-portal.ts +3 -5
- package/src/vercel/api/billing/index.ts +4 -2
- package/src/vercel/api/billing/refresh-subscription-status.ts +22 -7
- package/src/vercel/api/billing/webhook-handler.ts +32 -26
- package/src/vercel/api/config/firebase-admin.ts +2 -2
- package/src/vercel/api/crud/bulk.ts +6 -9
- package/src/vercel/api/crud/create.ts +6 -5
- package/src/vercel/api/crud/delete.ts +4 -3
- package/src/vercel/api/crud/get.ts +6 -5
- package/src/vercel/api/crud/list.ts +6 -5
- package/src/vercel/api/crud/update.ts +6 -5
- package/src/vercel/api/oauth/check-github-access.ts +5 -5
- package/src/vercel/api/oauth/exchange-token.ts +3 -3
- package/src/vercel/api/oauth/grant-github-access.ts +5 -5
- package/src/vercel/api/oauth/revoke-github-access.ts +3 -4
- package/src/vercel/baseFunction.ts +23 -8
- package/src/vercel/supabaseAdmin.ts +45 -0
- package/lib/shared/ai/createAIHandler.d.ts +0 -39
- package/lib/shared/ai/providers/anthropic.d.ts +0 -12
- package/lib/shared/ai/providers/google.d.ts +0 -10
- package/lib/shared/ai/providers/index.d.ts +0 -23
- package/lib/shared/ai/providers/openai.d.ts +0 -10
- package/lib/shared/ai/utils/parseSSE.d.ts +0 -22
|
@@ -1,95 +1,322 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/functions/src/shared/__tests__/idempotency.test.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Tests for webhook idempotency stores
|
|
5
|
+
* @description Three-state reservation and owner token for the in-memory,
|
|
6
|
+
* Firestore (mocked Firestore) and Supabase (mocked RPC) stores; the shipped
|
|
7
|
+
* migration must equal WEBHOOK_EVENTS_SQL.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.2.0
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
|
|
2
18
|
|
|
3
|
-
// Mock detectFirestore to return false (force in-memory)
|
|
4
19
|
vi.mock('../utils/detectFirestore.js', () => ({
|
|
5
20
|
isFirestoreConfigured: vi.fn(() => false),
|
|
6
21
|
}));
|
|
7
22
|
|
|
23
|
+
/** Minimal Firestore Timestamp double (only what the store uses). */
|
|
24
|
+
class FakeTimestamp {
|
|
25
|
+
constructor(private readonly millis: number) {}
|
|
26
|
+
static fromMillis(millis: number) {
|
|
27
|
+
return new FakeTimestamp(millis);
|
|
28
|
+
}
|
|
29
|
+
toMillis() {
|
|
30
|
+
return this.millis;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** In-memory Firestore double: docs map + serial transactions. */
|
|
35
|
+
const docs = new Map<string, Record<string, unknown>>();
|
|
36
|
+
function makeRef(id: string) {
|
|
37
|
+
return {
|
|
38
|
+
id,
|
|
39
|
+
async get() {
|
|
40
|
+
const data = docs.get(id);
|
|
41
|
+
return { exists: data !== undefined, data: () => data };
|
|
42
|
+
},
|
|
43
|
+
async set(data: Record<string, unknown>) {
|
|
44
|
+
docs.set(id, data);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const fakeFirestore = {
|
|
49
|
+
collection: vi.fn(() => ({ doc: (id: string) => makeRef(id) })),
|
|
50
|
+
async runTransaction<T>(fn: (tx: any) => Promise<T>): Promise<T> {
|
|
51
|
+
const tx = {
|
|
52
|
+
get: (ref: ReturnType<typeof makeRef>) => ref.get(),
|
|
53
|
+
set: (ref: ReturnType<typeof makeRef>, data: Record<string, unknown>) =>
|
|
54
|
+
docs.set(ref.id, data),
|
|
55
|
+
delete: (ref: ReturnType<typeof makeRef>) => docs.delete(ref.id),
|
|
56
|
+
};
|
|
57
|
+
return fn(tx);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
vi.mock('@donotdev/firebase/server', () => ({
|
|
62
|
+
getFirebaseAdminFirestore: () => fakeFirestore,
|
|
63
|
+
Timestamp: FakeTimestamp,
|
|
64
|
+
}));
|
|
65
|
+
|
|
8
66
|
import {
|
|
67
|
+
RESERVATION_LEASE_MS,
|
|
68
|
+
ReservationLostError,
|
|
69
|
+
WEBHOOK_EVENT_RETENTION_MS,
|
|
70
|
+
WEBHOOK_EVENTS_SQL,
|
|
71
|
+
createFirestoreIdempotencyStore,
|
|
9
72
|
createIdempotencyStore,
|
|
73
|
+
createInMemoryIdempotencyStore,
|
|
74
|
+
createSupabaseIdempotencyStore,
|
|
10
75
|
resetIdempotencyStore,
|
|
11
76
|
} from '../billing/idempotency';
|
|
77
|
+
import type { IdempotencyStore } from '../billing/idempotency';
|
|
12
78
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
79
|
+
async function reservedToken(store: IdempotencyStore, eventId: string) {
|
|
80
|
+
const result = await store.reserve(eventId);
|
|
81
|
+
if (result.state !== 'reserved') throw new Error(`expected reserved, got ${result.state}`);
|
|
82
|
+
return result.ownerToken;
|
|
83
|
+
}
|
|
19
84
|
|
|
20
|
-
|
|
21
|
-
|
|
85
|
+
/** Contract shared by the in-memory and Firestore stores. */
|
|
86
|
+
function storeContract(name: string, make: () => IdempotencyStore) {
|
|
87
|
+
describe(`${name} store contract`, () => {
|
|
88
|
+
afterEach(() => {
|
|
89
|
+
vi.restoreAllMocks();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('reserves a new event with an owner token', async () => {
|
|
93
|
+
const result = await make().reserve('evt_1');
|
|
94
|
+
expect(result.state).toBe('reserved');
|
|
95
|
+
expect(result.state === 'reserved' && result.ownerToken).toMatch(/^[0-9a-f-]{36}$/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('answers in_progress under a live lease', async () => {
|
|
99
|
+
const store = make();
|
|
100
|
+
await store.reserve('evt_2');
|
|
101
|
+
expect(await store.reserve('evt_2')).toEqual({ state: 'in_progress' });
|
|
102
|
+
});
|
|
22
103
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
104
|
+
it('answers processed after markProcessed by the owner (repeatable)', async () => {
|
|
105
|
+
const store = make();
|
|
106
|
+
const token = await reservedToken(store, 'evt_3');
|
|
107
|
+
await store.markProcessed('evt_3', token);
|
|
108
|
+
await store.markProcessed('evt_3', token);
|
|
109
|
+
expect(await store.reserve('evt_3')).toEqual({ state: 'processed' });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('re-reserves a released event (retry after failure)', async () => {
|
|
113
|
+
const store = make();
|
|
114
|
+
const token = await reservedToken(store, 'evt_4');
|
|
115
|
+
expect(await store.release('evt_4', token)).toBe(true);
|
|
116
|
+
expect((await store.reserve('evt_4')).state).toBe('reserved');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('release does not drop a processed event', async () => {
|
|
120
|
+
const store = make();
|
|
121
|
+
const token = await reservedToken(store, 'evt_5');
|
|
122
|
+
await store.markProcessed('evt_5', token);
|
|
123
|
+
expect(await store.release('evt_5', token)).toBe(false);
|
|
124
|
+
expect(await store.reserve('evt_5')).toEqual({ state: 'processed' });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('retakes an abandoned reservation after the lease; the stale owner can no longer change it', async () => {
|
|
128
|
+
const store = make();
|
|
129
|
+
const start = Date.now();
|
|
130
|
+
const now = vi.spyOn(Date, 'now').mockReturnValue(start);
|
|
131
|
+
const stale = await reservedToken(store, 'evt_6');
|
|
132
|
+
now.mockReturnValue(start + RESERVATION_LEASE_MS + 1);
|
|
133
|
+
const fresh = await reservedToken(store, 'evt_6');
|
|
134
|
+
expect(fresh).not.toBe(stale);
|
|
135
|
+
|
|
136
|
+
expect(await store.release('evt_6', stale)).toBe(false);
|
|
137
|
+
await expect(store.markProcessed('evt_6', stale)).rejects.toBeInstanceOf(
|
|
138
|
+
ReservationLostError
|
|
139
|
+
);
|
|
140
|
+
expect(await store.reserve('evt_6')).toEqual({ state: 'in_progress' });
|
|
141
|
+
await store.markProcessed('evt_6', fresh);
|
|
142
|
+
expect(await store.reserve('evt_6')).toEqual({ state: 'processed' });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('a foreign token cannot release or mark a live reservation', async () => {
|
|
146
|
+
const store = make();
|
|
147
|
+
await reservedToken(store, 'evt_7');
|
|
148
|
+
expect(await store.release('evt_7', 'not-the-owner')).toBe(false);
|
|
149
|
+
await expect(store.markProcessed('evt_7', 'not-the-owner')).rejects.toBeInstanceOf(
|
|
150
|
+
ReservationLostError
|
|
151
|
+
);
|
|
152
|
+
expect(await store.reserve('evt_7')).toEqual({ state: 'in_progress' });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('markProcessed without any reservation fails loud', async () => {
|
|
156
|
+
await expect(make().markProcessed('evt_none', 'tok')).rejects.toBeInstanceOf(
|
|
157
|
+
ReservationLostError
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('keeps events independent', async () => {
|
|
162
|
+
const store = make();
|
|
163
|
+
const token = await reservedToken(store, 'evt_a');
|
|
164
|
+
await store.markProcessed('evt_a', token);
|
|
165
|
+
expect((await store.reserve('evt_b')).state).toBe('reserved');
|
|
166
|
+
});
|
|
26
167
|
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
storeContract('in-memory', () => createInMemoryIdempotencyStore());
|
|
27
171
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
172
|
+
beforeEach(() => {
|
|
173
|
+
docs.clear();
|
|
174
|
+
});
|
|
175
|
+
storeContract('firestore (mocked)', () => createFirestoreIdempotencyStore());
|
|
31
176
|
|
|
32
|
-
|
|
177
|
+
describe('firestore store: documents', () => {
|
|
178
|
+
afterEach(() => {
|
|
179
|
+
vi.restoreAllMocks();
|
|
33
180
|
});
|
|
34
181
|
|
|
35
|
-
it('
|
|
36
|
-
const
|
|
182
|
+
it('writes expiresAt as a Firestore Timestamp 30 days out (TTL-eligible)', async () => {
|
|
183
|
+
const start = 1_800_000_000_000;
|
|
184
|
+
vi.spyOn(Date, 'now').mockReturnValue(start);
|
|
185
|
+
const store = createFirestoreIdempotencyStore();
|
|
186
|
+
const token = await reservedToken(store, 'evt_ttl');
|
|
187
|
+
const reserved = docs.get('evt_ttl')!;
|
|
188
|
+
expect(reserved.expiresAt).toBeInstanceOf(FakeTimestamp);
|
|
189
|
+
expect((reserved.expiresAt as FakeTimestamp).toMillis()).toBe(
|
|
190
|
+
start + WEBHOOK_EVENT_RETENTION_MS
|
|
191
|
+
);
|
|
192
|
+
expect(reserved).toMatchObject({ status: 'processing', ownerToken: token, reservedAt: start });
|
|
37
193
|
|
|
38
|
-
|
|
39
|
-
|
|
194
|
+
await store.markProcessed('evt_ttl', token);
|
|
195
|
+
const processed = docs.get('evt_ttl')!;
|
|
196
|
+
expect(processed).toMatchObject({ status: 'processed', ownerToken: token });
|
|
197
|
+
expect(processed.expiresAt).toBeInstanceOf(FakeTimestamp);
|
|
198
|
+
expect(WEBHOOK_EVENT_RETENTION_MS).toBe(30 * 24 * 60 * 60 * 1000);
|
|
40
199
|
});
|
|
41
200
|
|
|
42
|
-
it('
|
|
43
|
-
const store =
|
|
201
|
+
it('treats a 0.1.x document (no status, numeric expiresAt) as processed until it expires', async () => {
|
|
202
|
+
const store = createFirestoreIdempotencyStore();
|
|
203
|
+
docs.set('evt_old', { eventId: 'evt_old', processedAt: 1, expiresAt: Date.now() + 60_000 });
|
|
204
|
+
expect(await store.reserve('evt_old')).toEqual({ state: 'processed' });
|
|
205
|
+
docs.set('evt_old2', { eventId: 'evt_old2', processedAt: 1, expiresAt: Date.now() - 1 });
|
|
206
|
+
expect((await store.reserve('evt_old2')).state).toBe('reserved');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('fails loud on a malformed document', async () => {
|
|
210
|
+
docs.set('evt_bad', { status: 'weird' });
|
|
211
|
+
await expect(createFirestoreIdempotencyStore().reserve('evt_bad')).rejects.toThrow();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
44
214
|
|
|
45
|
-
|
|
46
|
-
|
|
215
|
+
describe('supabase idempotency store', () => {
|
|
216
|
+
function makeSupabase(data: unknown, error: unknown = null) {
|
|
217
|
+
return { rpc: vi.fn(async () => ({ data, error })) };
|
|
218
|
+
}
|
|
47
219
|
|
|
48
|
-
|
|
220
|
+
it('reserve calls webhook_event_reserve with a fresh owner token and the lease', async () => {
|
|
221
|
+
const client = makeSupabase('reserved');
|
|
222
|
+
const result = await createSupabaseIdempotencyStore(client as any).reserve('evt_s1');
|
|
223
|
+
expect(result.state).toBe('reserved');
|
|
224
|
+
const [fn, args] = (client.rpc.mock.calls as any[])[0];
|
|
225
|
+
expect(fn).toBe('webhook_event_reserve');
|
|
226
|
+
expect(args).toEqual({
|
|
227
|
+
p_event_id: 'evt_s1',
|
|
228
|
+
p_owner_token: result.state === 'reserved' ? result.ownerToken : null,
|
|
229
|
+
p_lease_seconds: RESERVATION_LEASE_MS / 1000,
|
|
230
|
+
});
|
|
49
231
|
});
|
|
50
232
|
|
|
51
|
-
it('
|
|
52
|
-
const store =
|
|
233
|
+
it.each(['processed', 'in_progress'] as const)('maps %s', async (state) => {
|
|
234
|
+
const store = createSupabaseIdempotencyStore(makeSupabase(state) as any);
|
|
235
|
+
expect(await store.reserve('evt_s2')).toEqual({ state });
|
|
236
|
+
});
|
|
53
237
|
|
|
54
|
-
|
|
238
|
+
it('throws on RPC error (fail closed)', async () => {
|
|
239
|
+
const store = createSupabaseIdempotencyStore(
|
|
240
|
+
makeSupabase(null, new Error('function webhook_event_reserve does not exist')) as any
|
|
241
|
+
);
|
|
242
|
+
await expect(store.reserve('evt_s3')).rejects.toThrow();
|
|
243
|
+
});
|
|
55
244
|
|
|
56
|
-
|
|
57
|
-
|
|
245
|
+
it('throws on an unexpected RPC result', async () => {
|
|
246
|
+
const store = createSupabaseIdempotencyStore(makeSupabase(true) as any);
|
|
247
|
+
await expect(store.reserve('evt_s3b')).rejects.toThrow();
|
|
58
248
|
});
|
|
59
249
|
|
|
60
|
-
it('
|
|
61
|
-
const
|
|
62
|
-
|
|
250
|
+
it('markProcessed passes the owner token and succeeds when the row is owned', async () => {
|
|
251
|
+
const client = makeSupabase(true);
|
|
252
|
+
await createSupabaseIdempotencyStore(client as any).markProcessed('evt_s4', 'tok');
|
|
253
|
+
expect(client.rpc).toHaveBeenCalledWith('webhook_event_mark_processed', {
|
|
254
|
+
p_event_id: 'evt_s4',
|
|
255
|
+
p_owner_token: 'tok',
|
|
256
|
+
});
|
|
257
|
+
});
|
|
63
258
|
|
|
64
|
-
|
|
65
|
-
|
|
259
|
+
it('markProcessed fails loud when 0 rows are owned', async () => {
|
|
260
|
+
const store = createSupabaseIdempotencyStore(makeSupabase(false) as any);
|
|
261
|
+
await expect(store.markProcessed('evt_s5', 'tok')).rejects.toBeInstanceOf(
|
|
262
|
+
ReservationLostError
|
|
263
|
+
);
|
|
264
|
+
});
|
|
66
265
|
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
266
|
+
it('release returns whether the owner released', async () => {
|
|
267
|
+
const client = makeSupabase(false);
|
|
268
|
+
expect(await createSupabaseIdempotencyStore(client as any).release('evt_s6', 'tok')).toBe(
|
|
269
|
+
false
|
|
70
270
|
);
|
|
71
|
-
expect(
|
|
271
|
+
expect(client.rpc).toHaveBeenCalledWith('webhook_event_release', {
|
|
272
|
+
p_event_id: 'evt_s6',
|
|
273
|
+
p_owner_token: 'tok',
|
|
274
|
+
});
|
|
72
275
|
});
|
|
73
276
|
|
|
74
|
-
it('
|
|
75
|
-
const
|
|
277
|
+
it('the CLI template migration ships WEBHOOK_EVENTS_SQL verbatim', () => {
|
|
278
|
+
const migration = readFileSync(
|
|
279
|
+
fileURLToPath(
|
|
280
|
+
new URL(
|
|
281
|
+
'../../../../cli/templates/functions-supabase/supabase/migrations/20250101000005_webhook_events.sql',
|
|
282
|
+
import.meta.url
|
|
283
|
+
)
|
|
284
|
+
),
|
|
285
|
+
'utf8'
|
|
286
|
+
);
|
|
287
|
+
const body = migration.slice(migration.indexOf('\n\n') + 2);
|
|
288
|
+
expect(WEBHOOK_EVENTS_SQL.trim()).toBe(body.trim());
|
|
289
|
+
expect(body).not.toContain('REVOKE');
|
|
290
|
+
expect(body).toContain("cron.schedule(\n 'cleanup-webhook-events'");
|
|
291
|
+
});
|
|
292
|
+
});
|
|
76
293
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
294
|
+
describe('0.1.x API (deprecated)', () => {
|
|
295
|
+
afterEach(() => {
|
|
296
|
+
resetIdempotencyStore();
|
|
297
|
+
vi.restoreAllMocks();
|
|
298
|
+
});
|
|
81
299
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(
|
|
300
|
+
it('auto-detects in-memory without Firestore and caches the instance', () => {
|
|
301
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
302
|
+
const store = createIdempotencyStore();
|
|
303
|
+
expect(createIdempotencyStore()).toBe(store);
|
|
86
304
|
});
|
|
87
305
|
|
|
88
|
-
it('
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
306
|
+
it('keeps checkAndReserve / isProcessed / tokenless markProcessed working', async () => {
|
|
307
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
308
|
+
const store = createIdempotencyStore();
|
|
309
|
+
expect(await store.checkAndReserve('evt_l1')).toBe(false);
|
|
310
|
+
expect(await store.checkAndReserve('evt_l1')).toBe(true);
|
|
311
|
+
expect(await store.isProcessed('evt_l1')).toBe(false);
|
|
312
|
+
await store.markProcessed('evt_l1');
|
|
313
|
+
expect(await store.isProcessed('evt_l1')).toBe(true);
|
|
314
|
+
});
|
|
92
315
|
|
|
93
|
-
|
|
316
|
+
it('firestore: tokenless markProcessed writes unconditionally', async () => {
|
|
317
|
+
const store = createFirestoreIdempotencyStore();
|
|
318
|
+
await store.markProcessed('evt_l2');
|
|
319
|
+
expect(await store.isProcessed('evt_l2')).toBe(true);
|
|
320
|
+
expect(await store.checkAndReserve('evt_l2')).toBe(true);
|
|
94
321
|
});
|
|
95
322
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
1
|
import * as v from 'valibot';
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
3
|
|
|
4
4
|
// Mock external deps
|
|
5
5
|
vi.mock('@donotdev/core/server', () => {
|
|
@@ -16,15 +16,14 @@ vi.mock('@donotdev/core/server', () => {
|
|
|
16
16
|
return { DoNotDevError };
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
import { DoNotDevError } from '@donotdev/core/server';
|
|
20
|
+
|
|
19
21
|
import {
|
|
20
22
|
safeJsonParse,
|
|
21
23
|
validateCollectionName,
|
|
22
24
|
validateDocument,
|
|
23
|
-
validateStripeEnvironment,
|
|
24
25
|
} from '../utils/internal/validation';
|
|
25
26
|
|
|
26
|
-
import { DoNotDevError } from '@donotdev/core/server';
|
|
27
|
-
|
|
28
27
|
// ---------------------------------------------------------------------------
|
|
29
28
|
// safeJsonParse
|
|
30
29
|
// ---------------------------------------------------------------------------
|
|
@@ -156,41 +155,3 @@ describe('validateDocument (internal)', () => {
|
|
|
156
155
|
expect(() => validateDocument({ anything: 'goes' })).not.toThrow();
|
|
157
156
|
});
|
|
158
157
|
});
|
|
159
|
-
|
|
160
|
-
// ---------------------------------------------------------------------------
|
|
161
|
-
// validateStripeEnvironment (internal version)
|
|
162
|
-
// ---------------------------------------------------------------------------
|
|
163
|
-
|
|
164
|
-
describe('validateStripeEnvironment (internal)', () => {
|
|
165
|
-
const originalEnv = { ...process.env };
|
|
166
|
-
|
|
167
|
-
beforeEach(() => {
|
|
168
|
-
delete process.env.STRIPE_SECRET_KEY;
|
|
169
|
-
delete process.env.STRIPE_WEBHOOK_SECRET;
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
afterEach(() => {
|
|
173
|
-
process.env = { ...originalEnv };
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('throws when both vars missing', () => {
|
|
177
|
-
expect(() => validateStripeEnvironment()).toThrow(
|
|
178
|
-
'Missing required environment variables'
|
|
179
|
-
);
|
|
180
|
-
expect(() => validateStripeEnvironment()).toThrow('STRIPE_SECRET_KEY');
|
|
181
|
-
expect(() => validateStripeEnvironment()).toThrow('STRIPE_WEBHOOK_SECRET');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('throws when STRIPE_WEBHOOK_SECRET missing', () => {
|
|
185
|
-
process.env.STRIPE_SECRET_KEY = 'sk_test_x';
|
|
186
|
-
|
|
187
|
-
expect(() => validateStripeEnvironment()).toThrow('STRIPE_WEBHOOK_SECRET');
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('passes when all vars set', () => {
|
|
191
|
-
process.env.STRIPE_SECRET_KEY = 'sk_test_x';
|
|
192
|
-
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_x';
|
|
193
|
-
|
|
194
|
-
expect(() => validateStripeEnvironment()).not.toThrow();
|
|
195
|
-
});
|
|
196
|
-
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Regression: Supabase Edge Runtime defines `window` (= globalThis) but no
|
|
5
|
+
* `document`. A module-level `'window' in globalThis` guard made the logger
|
|
6
|
+
* throw on import, failing every Supabase edge function with WORKER_ERROR.
|
|
7
|
+
*/
|
|
8
|
+
describe('logger on a runtime that defines window (Supabase Edge shape)', () => {
|
|
9
|
+
const g = globalThis as Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
delete g.window;
|
|
13
|
+
vi.restoreAllMocks();
|
|
14
|
+
vi.resetModules();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('imports and logs when window is defined and document is not', async () => {
|
|
18
|
+
g.window = globalThis;
|
|
19
|
+
expect(typeof (globalThis as { document?: unknown }).document).toBe(
|
|
20
|
+
'undefined'
|
|
21
|
+
);
|
|
22
|
+
vi.resetModules();
|
|
23
|
+
|
|
24
|
+
const { logger } = await import('../logger');
|
|
25
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
26
|
+
|
|
27
|
+
logger.error('edge boot ok');
|
|
28
|
+
|
|
29
|
+
expect(spy).toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
|
|
3
|
-
// Mock
|
|
4
|
-
vi.mock('
|
|
3
|
+
// Mock the framework logger (in-memory path logs on block/reset)
|
|
4
|
+
vi.mock('../logger.js', () => ({
|
|
5
5
|
logger: {
|
|
6
6
|
warn: vi.fn(),
|
|
7
7
|
info: vi.fn(),
|
|
8
8
|
error: vi.fn(),
|
|
9
|
-
log: vi.fn(),
|
|
10
9
|
},
|
|
11
10
|
}));
|
|
12
11
|
|
|
13
|
-
// Mock @donotdev/firebase/server (not used in in-memory path, but imported)
|
|
14
|
-
vi.mock('@donotdev/firebase/server', () => ({
|
|
15
|
-
getFirebaseAdminFirestore: vi.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
12
|
import {
|
|
19
13
|
checkRateLimit,
|
|
20
14
|
resetRateLimit,
|
|
@@ -38,6 +38,8 @@ vi.mock('../utils/internal/auth.js', () => ({
|
|
|
38
38
|
assertAdmin: vi.fn((uid: string) => Promise.resolve(uid)),
|
|
39
39
|
}));
|
|
40
40
|
|
|
41
|
+
import { DoNotDevError } from '@donotdev/core/server';
|
|
42
|
+
|
|
41
43
|
import {
|
|
42
44
|
getUserRole,
|
|
43
45
|
createSuccessResponse,
|
|
@@ -45,11 +47,10 @@ import {
|
|
|
45
47
|
validateDocument,
|
|
46
48
|
validateCollectionName,
|
|
47
49
|
assertAuthenticated,
|
|
48
|
-
validateStripeEnvironment,
|
|
49
50
|
} from '../utils';
|
|
51
|
+
import { validateStripeEnvironment } from '../billing/stripeClient';
|
|
50
52
|
|
|
51
53
|
// Need to import DoNotDevError from the mocked module for instanceof checks
|
|
52
|
-
import { DoNotDevError } from '@donotdev/core/server';
|
|
53
54
|
|
|
54
55
|
// ---------------------------------------------------------------------------
|
|
55
56
|
// getUserRole
|
|
File without changes
|