@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
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { logger } from 'firebase-functions/v2';
|
|
18
|
-
import
|
|
18
|
+
import type {
|
|
19
|
+
CallableFunction,
|
|
20
|
+
CallableRequest,
|
|
21
|
+
} from 'firebase-functions/v2/https';
|
|
22
|
+
import type * as v from 'valibot';
|
|
19
23
|
|
|
20
24
|
import { BulkRequestSchema, DEFAULT_STATUS_VALUE } from '@donotdev/core/server';
|
|
21
25
|
import type {
|
|
@@ -34,11 +38,6 @@ import {
|
|
|
34
38
|
import { createBaseFunction } from '../baseFunction.js';
|
|
35
39
|
import { CRUD_CONFIG } from '../config/constants.js';
|
|
36
40
|
|
|
37
|
-
import type {
|
|
38
|
-
CallableFunction,
|
|
39
|
-
CallableRequest,
|
|
40
|
-
} from 'firebase-functions/v2/https';
|
|
41
|
-
|
|
42
41
|
/**
|
|
43
42
|
* Request type for the bulk endpoint. Identical to the wire schema; kept as a
|
|
44
43
|
* named alias for parity with `CreateEntityRequest`, `UpdateEntityRequest`, etc.
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { Query, DocumentData } from 'firebase-admin/firestore';
|
|
12
13
|
import { logger } from 'firebase-functions/v2';
|
|
14
|
+
import type {
|
|
15
|
+
CallableFunction,
|
|
16
|
+
CallableRequest,
|
|
17
|
+
} from 'firebase-functions/v2/https';
|
|
13
18
|
import * as v from 'valibot';
|
|
14
19
|
|
|
15
20
|
import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
|
|
@@ -24,12 +29,6 @@ import { DoNotDevError, validateDocument } from '../../shared/utils.js';
|
|
|
24
29
|
import { createBaseFunction } from '../baseFunction.js';
|
|
25
30
|
import { CRUD_CONFIG } from '../config/constants.js';
|
|
26
31
|
|
|
27
|
-
import type { Query, DocumentData } from 'firebase-admin/firestore';
|
|
28
|
-
import type {
|
|
29
|
-
CallableFunction,
|
|
30
|
-
CallableRequest,
|
|
31
|
-
} from 'firebase-functions/v2/https';
|
|
32
|
-
|
|
33
32
|
export type CreateEntityRequest = {
|
|
34
33
|
payload: Record<string, any>;
|
|
35
34
|
idempotencyKey?: string;
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { logger } from 'firebase-functions/v2';
|
|
13
|
+
import type {
|
|
14
|
+
CallableFunction,
|
|
15
|
+
CallableRequest,
|
|
16
|
+
} from 'firebase-functions/v2/https';
|
|
13
17
|
import * as v from 'valibot';
|
|
14
18
|
|
|
15
19
|
import type { UserRole } from '@donotdev/core/server';
|
|
@@ -19,11 +23,6 @@ import { DoNotDevError, findReferences } from '../../shared/utils.js';
|
|
|
19
23
|
import { createBaseFunction } from '../baseFunction.js';
|
|
20
24
|
import { CRUD_CONFIG } from '../config/constants.js';
|
|
21
25
|
|
|
22
|
-
import type {
|
|
23
|
-
CallableFunction,
|
|
24
|
-
CallableRequest,
|
|
25
|
-
} from 'firebase-functions/v2/https';
|
|
26
|
-
|
|
27
26
|
export type DeleteEntityRequest = { id: string };
|
|
28
27
|
|
|
29
28
|
/**
|
package/src/firebase/crud/get.ts
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type {
|
|
13
|
+
CallableFunction,
|
|
14
|
+
CallableRequest,
|
|
15
|
+
} from 'firebase-functions/v2/https';
|
|
12
16
|
import * as v from 'valibot';
|
|
13
17
|
|
|
14
18
|
import {
|
|
@@ -24,11 +28,6 @@ import { DoNotDevError } from '../../shared/utils.js';
|
|
|
24
28
|
import { createBaseFunction } from '../baseFunction.js';
|
|
25
29
|
import { CRUD_READ_CONFIG } from '../config/constants.js';
|
|
26
30
|
|
|
27
|
-
import type {
|
|
28
|
-
CallableFunction,
|
|
29
|
-
CallableRequest,
|
|
30
|
-
} from 'firebase-functions/v2/https';
|
|
31
|
-
|
|
32
31
|
export type GetEntityRequest = { id: string };
|
|
33
32
|
|
|
34
33
|
/**
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { logger } from 'firebase-functions/v2';
|
|
13
|
+
import type {
|
|
14
|
+
CallableFunction,
|
|
15
|
+
CallableRequest,
|
|
16
|
+
} from 'firebase-functions/v2/https';
|
|
13
17
|
import * as v from 'valibot';
|
|
14
18
|
|
|
15
19
|
import {
|
|
@@ -30,11 +34,6 @@ import { DoNotDevError } from '../../shared/utils.js';
|
|
|
30
34
|
import { createBaseFunction } from '../baseFunction.js';
|
|
31
35
|
import { CRUD_READ_CONFIG } from '../config/constants.js';
|
|
32
36
|
|
|
33
|
-
import type {
|
|
34
|
-
CallableFunction,
|
|
35
|
-
CallableRequest,
|
|
36
|
-
} from 'firebase-functions/v2/https';
|
|
37
|
-
|
|
38
37
|
export interface ListEntityRequest {
|
|
39
38
|
where?: Array<[string, any, any]>;
|
|
40
39
|
orderBy?: Array<[string, 'asc' | 'desc']>;
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { Query, DocumentData } from 'firebase-admin/firestore';
|
|
13
|
+
import type {
|
|
14
|
+
CallableFunction,
|
|
15
|
+
CallableRequest,
|
|
16
|
+
} from 'firebase-functions/v2/https';
|
|
12
17
|
import * as v from 'valibot';
|
|
13
18
|
|
|
14
19
|
import { DEFAULT_STATUS_VALUE } from '@donotdev/core/server';
|
|
@@ -24,12 +29,6 @@ import { DoNotDevError, validateDocument } from '../../shared/utils.js';
|
|
|
24
29
|
import { createBaseFunction } from '../baseFunction.js';
|
|
25
30
|
import { CRUD_CONFIG } from '../config/constants.js';
|
|
26
31
|
|
|
27
|
-
import type { Query, DocumentData } from 'firebase-admin/firestore';
|
|
28
|
-
import type {
|
|
29
|
-
CallableFunction,
|
|
30
|
-
CallableRequest,
|
|
31
|
-
} from 'firebase-functions/v2/https';
|
|
32
|
-
|
|
33
32
|
export type UpdateEntityRequest = {
|
|
34
33
|
id: string;
|
|
35
34
|
payload: Record<string, any>;
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
import { logger } from 'firebase-functions/v2';
|
|
13
13
|
import { onCall } from 'firebase-functions/v2/https';
|
|
14
|
+
import type { CallableRequest } from 'firebase-functions/v2/https';
|
|
15
|
+
import type { CallableFunction } from 'firebase-functions/v2/https';
|
|
14
16
|
import * as v from 'valibot';
|
|
15
17
|
|
|
16
18
|
import {
|
|
@@ -29,9 +31,6 @@ import { assertAuthenticated } from '../../shared/utils.js';
|
|
|
29
31
|
import { AUTH_CONFIG } from '../config/constants.js';
|
|
30
32
|
import { githubPersonalAccessToken } from '../config/secrets.js';
|
|
31
33
|
|
|
32
|
-
import type { CallableRequest } from 'firebase-functions/v2/https';
|
|
33
|
-
import type { CallableFunction } from 'firebase-functions/v2/https';
|
|
34
|
-
|
|
35
34
|
const OAUTH_CONFIG = {
|
|
36
35
|
...AUTH_CONFIG,
|
|
37
36
|
secrets: [githubPersonalAccessToken],
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { HttpsFunction } from 'firebase-functions/v2/https';
|
|
13
|
+
|
|
12
14
|
import { createSchemas, getListCardFieldNames } from '@donotdev/core/server';
|
|
13
15
|
import type { Entity } from '@donotdev/core/server';
|
|
14
16
|
|
|
@@ -21,8 +23,6 @@ import {
|
|
|
21
23
|
listEntities,
|
|
22
24
|
} from './crud/index.js';
|
|
23
25
|
|
|
24
|
-
import type { HttpsFunction } from 'firebase-functions/v2/https';
|
|
25
|
-
|
|
26
26
|
interface RegisterOptions {
|
|
27
27
|
prefix?: string;
|
|
28
28
|
}
|
|
@@ -5,9 +5,6 @@ vi.mock('@donotdev/core/server', () => ({
|
|
|
5
5
|
hasProvider: vi.fn(() => false),
|
|
6
6
|
getProvider: vi.fn(),
|
|
7
7
|
}));
|
|
8
|
-
vi.mock('@donotdev/firebase/server', () => ({
|
|
9
|
-
getFirebaseAdminAuth: vi.fn(),
|
|
10
|
-
}));
|
|
11
8
|
|
|
12
9
|
import { assertAuthenticated } from '../utils/internal/auth';
|
|
13
10
|
|
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
* firing once with counts.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
13
12
|
import * as v from 'valibot';
|
|
13
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
14
14
|
|
|
15
|
-
import { executeBulk } from '../crud/bulkCore.js';
|
|
16
15
|
import { BulkCollisionError } from '@donotdev/core/server';
|
|
17
16
|
import { DoNotDevError } from '@donotdev/core/server';
|
|
18
17
|
import { DEFAULT_STATUS_VALUE } from '@donotdev/core/server';
|
|
19
18
|
|
|
19
|
+
import { executeBulk } from '../crud/bulkCore.js';
|
|
20
|
+
|
|
20
21
|
// ---------------------------------------------------------------------------
|
|
21
22
|
// Fixtures
|
|
22
23
|
// ---------------------------------------------------------------------------
|
|
@@ -66,14 +66,14 @@ describe('handleError', () => {
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it('throws DoNotDevError with code "internal" for generic Error', () => {
|
|
69
|
+
it('throws DoNotDevError with code "internal" and a generic message for generic Error', () => {
|
|
70
70
|
try {
|
|
71
71
|
handleError(new Error('Something broke'));
|
|
72
72
|
expect.fail('should have thrown');
|
|
73
73
|
} catch (error) {
|
|
74
74
|
expect(error).toBeInstanceOf(DoNotDevError);
|
|
75
75
|
expect((error as DoNotDevError).code).toBe('internal');
|
|
76
|
-
expect((error as DoNotDevError).message).toBe('
|
|
76
|
+
expect((error as DoNotDevError).message).toBe('An unexpected error occurred');
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
|
|
@@ -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, beforeEach, afterEach } from 'vitest';
|
|
3
3
|
|
|
4
4
|
// Mock external deps
|
|
5
5
|
vi.mock('@donotdev/core/server', () => {
|
|
@@ -16,6 +16,8 @@ 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,
|
|
@@ -23,8 +25,6 @@ import {
|
|
|
23
25
|
validateStripeEnvironment,
|
|
24
26
|
} from '../utils/internal/validation';
|
|
25
27
|
|
|
26
|
-
import { DoNotDevError } from '@donotdev/core/server';
|
|
27
|
-
|
|
28
28
|
// ---------------------------------------------------------------------------
|
|
29
29
|
// safeJsonParse
|
|
30
30
|
// ---------------------------------------------------------------------------
|
|
@@ -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,
|