@donotdev/functions 0.0.19 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -3
- package/lib/firebase/auth/getCustomClaims.d.ts +25 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +29 -0
- package/lib/firebase/auth/index.d.ts +12 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +28 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +34 -0
- package/lib/firebase/baseFunction.d.ts +26 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +10 -0
- package/lib/firebase/billing/changePlan.d.ts +13 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +21 -0
- package/lib/firebase/billing/createCustomerPortal.d.ts +19 -0
- package/lib/firebase/billing/healthCheck.d.ts +5 -0
- package/lib/firebase/billing/index.d.ts +18 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +19 -0
- package/lib/firebase/billing/webhookHandler.d.ts +6 -0
- package/lib/firebase/config/constants.d.ts +89 -0
- package/lib/firebase/config/index.d.ts +9 -0
- package/lib/firebase/config/secrets.d.ts +15 -0
- package/lib/firebase/crud/aggregate.d.ts +98 -0
- package/lib/firebase/crud/create.d.ts +16 -0
- package/lib/firebase/crud/delete.d.ts +20 -0
- package/lib/firebase/crud/get.d.ts +24 -0
- package/lib/firebase/crud/index.d.ts +14 -0
- package/lib/firebase/crud/list.d.ts +25 -0
- package/lib/firebase/crud/update.d.ts +25 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +30 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +36 -0
- package/lib/firebase/helpers/index.d.ts +10 -0
- package/lib/firebase/index.d.ts +17 -0
- package/lib/firebase/index.js +25 -9110
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +12 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +9 -0
- package/lib/firebase/oauth/getConnections.d.ts +11 -0
- package/lib/firebase/oauth/githubAccess.d.ts +83 -0
- package/lib/firebase/oauth/index.d.ts +13 -0
- package/lib/firebase/oauth/refreshToken.d.ts +9 -0
- package/lib/firebase/registerCrudFunctions.d.ts +32 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +14 -0
- package/lib/firebase/scheduled/index.d.ts +9 -0
- package/lib/shared/billing/createCheckout.d.ts +50 -0
- package/lib/shared/billing/helpers/index.d.ts +10 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +34 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +45 -0
- package/lib/shared/billing/idempotency.d.ts +22 -0
- package/lib/shared/billing/index.d.ts +11 -0
- package/lib/shared/billing/webhookHandler.d.ts +37 -0
- package/lib/shared/errorHandling.d.ts +14 -0
- package/lib/shared/firebase.d.ts +73 -0
- package/lib/shared/github.d.ts +128 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +25 -6927
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +133 -0
- package/lib/shared/metadata.d.ts +36 -0
- package/lib/shared/oauth/exchangeToken.d.ts +24 -0
- package/lib/shared/oauth/grantAccess.d.ts +30 -0
- package/lib/shared/oauth/index.d.ts +10 -0
- package/lib/shared/schema.d.ts +56 -0
- package/lib/shared/utils/detectFirestore.d.ts +31 -0
- package/lib/shared/utils/external/date.d.ts +36 -0
- package/lib/shared/utils/external/index.d.ts +11 -0
- package/lib/shared/utils/external/references.d.ts +12 -0
- package/lib/shared/utils/external/subscription.d.ts +41 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +23 -0
- package/lib/shared/utils/functionWrapper.d.ts +36 -0
- package/lib/shared/utils/index.d.ts +14 -0
- package/lib/shared/utils/internal/auth.d.ts +57 -0
- package/lib/shared/utils/internal/firebase.d.ts +5 -0
- package/lib/shared/utils/internal/idempotency.d.ts +21 -0
- package/lib/shared/utils/internal/index.d.ts +14 -0
- package/lib/shared/utils/internal/monitoring.d.ts +80 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +82 -0
- package/lib/shared/utils/internal/validation.d.ts +43 -0
- package/lib/shared/utils/schemaValidation.d.ts +60 -0
- package/lib/shared/utils/validation.d.ts +98 -0
- package/lib/shared/utils/vercelHelpers.d.ts +18 -0
- package/lib/shared/utils.d.ts +234 -0
- package/lib/shared/validation.d.ts +16 -0
- package/lib/supabase/auth/deleteAccount.d.ts +16 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +18 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +18 -0
- package/lib/supabase/baseFunction.d.ts +43 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +9 -0
- package/lib/supabase/billing/changePlan.d.ts +11 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +11 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +9 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +9 -0
- package/lib/supabase/crud/aggregate.d.ts +27 -0
- package/lib/supabase/crud/create.d.ts +23 -0
- package/lib/supabase/crud/delete.d.ts +30 -0
- package/lib/supabase/crud/get.d.ts +23 -0
- package/lib/supabase/crud/index.d.ts +20 -0
- package/lib/supabase/crud/list.d.ts +33 -0
- package/lib/supabase/crud/update.d.ts +24 -0
- package/lib/supabase/helpers/authProvider.d.ts +22 -0
- package/lib/supabase/index.d.ts +30 -0
- package/lib/supabase/index.js +23 -0
- package/lib/supabase/index.js.map +7 -0
- package/lib/supabase/oauth/disconnect.d.ts +13 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +13 -0
- package/lib/supabase/oauth/getConnections.d.ts +13 -0
- package/lib/supabase/oauth/index.d.ts +12 -0
- package/lib/supabase/oauth/refreshToken.d.ts +13 -0
- package/lib/supabase/registerCrudFunctions.d.ts +24 -0
- package/lib/supabase/utils/idempotency.d.ts +36 -0
- package/lib/supabase/utils/monitoring.d.ts +59 -0
- package/lib/supabase/utils/rateLimiter.d.ts +56 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +2 -0
- package/lib/vercel/api/auth/index.d.ts +12 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +10 -0
- package/lib/vercel/api/billing/cancel.d.ts +10 -0
- package/lib/vercel/api/billing/change-plan.d.ts +11 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +13 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +3 -0
- package/lib/vercel/api/billing/index.d.ts +14 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +31 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +22 -0
- package/lib/vercel/api/config/constants.d.ts +103 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +19 -0
- package/lib/vercel/api/config/index.d.ts +10 -0
- package/lib/vercel/api/crud/create.d.ts +2 -0
- package/lib/vercel/api/crud/delete.d.ts +2 -0
- package/lib/vercel/api/crud/get.d.ts +2 -0
- package/lib/vercel/api/crud/index.d.ts +13 -0
- package/lib/vercel/api/crud/list.d.ts +2 -0
- package/lib/vercel/api/crud/update.d.ts +2 -0
- package/lib/vercel/api/index.d.ts +13 -0
- package/lib/vercel/api/index.js +22 -4790
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/index.d.ts +12 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +11 -0
- package/lib/vercel/api/utils/cors.d.ts +49 -0
- package/lib/vercel/baseFunction.d.ts +25 -0
- package/package.json +4 -4
- package/src/firebase/auth/getCustomClaims.ts +3 -3
- package/src/firebase/auth/getUserAuthStatus.ts +3 -3
- package/src/firebase/auth/index.ts +1 -1
- package/src/firebase/auth/removeCustomClaims.ts +3 -3
- package/src/firebase/auth/setCustomClaims.ts +130 -84
- package/src/firebase/baseFunction.ts +2 -2
- package/src/firebase/billing/cancelSubscription.ts +3 -3
- package/src/firebase/billing/changePlan.ts +3 -3
- package/src/firebase/billing/createCheckoutSession.ts +1 -1
- package/src/firebase/billing/createCustomerPortal.ts +1 -1
- package/src/firebase/billing/healthCheck.ts +8 -24
- package/src/firebase/billing/index.d.ts +11 -11
- package/src/firebase/billing/index.ts +1 -1
- package/src/firebase/billing/refreshSubscriptionStatus.ts +3 -3
- package/src/firebase/billing/webhookHandler.ts +1 -2
- package/src/firebase/config/constants.ts +4 -4
- package/src/firebase/config/index.ts +1 -1
- package/src/firebase/config/secrets.ts +1 -1
- package/src/firebase/crud/aggregate.ts +2 -2
- package/src/firebase/crud/create.ts +19 -4
- package/src/firebase/crud/delete.ts +3 -3
- package/src/firebase/crud/get.ts +1 -1
- package/src/firebase/crud/index.ts +1 -1
- package/src/firebase/crud/list.ts +1 -1
- package/src/firebase/crud/update.ts +2 -2
- package/src/firebase/helpers/githubAccessHelper.ts +4 -4
- package/src/firebase/helpers/githubTeamAccessHelper.ts +3 -3
- package/src/firebase/helpers/index.ts +1 -1
- package/src/firebase/index.d.ts +9 -9
- package/src/firebase/index.ts +1 -1
- package/src/firebase/oauth/disconnect.ts +2 -2
- package/src/firebase/oauth/exchangeToken.ts +7 -7
- package/src/firebase/oauth/getConnections.ts +2 -2
- package/src/firebase/oauth/githubAccess.ts +10 -10
- package/src/firebase/oauth/index.ts +1 -1
- package/src/firebase/oauth/refreshToken.ts +2 -2
- package/src/firebase/registerCrudFunctions.ts +1 -1
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +1 -1
- package/src/firebase/scheduled/index.ts +1 -1
- package/src/shared/__tests__/auth.test.ts +46 -0
- package/src/shared/__tests__/errorHandling.test.ts +66 -1
- package/src/shared/__tests__/firebase.test.ts +293 -0
- package/src/shared/__tests__/internalValidation.test.ts +190 -0
- package/src/shared/__tests__/metadata.test.ts +66 -0
- package/src/shared/__tests__/schema.test.ts +219 -0
- package/src/shared/__tests__/schemaValidation.test.ts +72 -0
- package/src/shared/__tests__/subscription.test.ts +45 -0
- package/src/shared/__tests__/utils.test.ts +281 -0
- package/src/shared/__tests__/validation-env.test.ts +73 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +1 -1
- package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -1
- package/src/shared/billing/createCheckout.ts +10 -5
- package/src/shared/billing/helpers/index.ts +1 -1
- package/src/shared/billing/helpers/subscriptionManagement.ts +4 -4
- package/src/shared/billing/helpers/updateUserSubscription.ts +4 -4
- package/src/shared/billing/idempotency.ts +4 -4
- package/src/shared/billing/index.ts +1 -1
- package/src/shared/billing/webhookHandler.ts +7 -7
- package/src/shared/errorHandling.ts +2 -2
- package/src/shared/firebase.ts +7 -7
- package/src/shared/github.ts +11 -11
- package/src/shared/index.d.ts +9 -9
- package/src/shared/index.ts +1 -1
- package/src/shared/logger.ts +8 -8
- package/src/shared/metadata.ts +3 -3
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +1 -1
- package/src/shared/oauth/exchangeToken.ts +2 -2
- package/src/shared/oauth/grantAccess.ts +2 -2
- package/src/shared/oauth/index.ts +1 -1
- package/src/shared/schema.ts +4 -4
- package/src/shared/utils/__tests__/functionWrapper.test.ts +1 -1
- package/src/shared/utils/detectFirestore.ts +3 -3
- package/src/shared/utils/external/date.ts +5 -5
- package/src/shared/utils/external/index.ts +1 -1
- package/src/shared/utils/external/references.ts +2 -2
- package/src/shared/utils/external/subscription.ts +5 -5
- package/src/shared/utils/firebaseHelpers.ts +3 -3
- package/src/shared/utils/functionWrapper.ts +4 -4
- package/src/shared/utils/index.ts +1 -1
- package/src/shared/utils/internal/auth.ts +7 -7
- package/src/shared/utils/internal/firebase.ts +1 -1
- package/src/shared/utils/internal/idempotency.ts +3 -3
- package/src/shared/utils/internal/index.ts +1 -1
- package/src/shared/utils/internal/monitoring.ts +8 -8
- package/src/shared/utils/internal/rateLimiter.ts +6 -6
- package/src/shared/utils/internal/validation.ts +6 -6
- package/src/shared/utils/schemaValidation.ts +6 -6
- package/src/shared/utils/validation.ts +10 -10
- package/src/shared/utils/vercelHelpers.ts +3 -3
- package/src/shared/utils.ts +19 -19
- package/src/shared/validation.ts +2 -2
- package/src/supabase/auth/deleteAccount.ts +2 -2
- package/src/supabase/auth/getCustomClaims.ts +2 -2
- package/src/supabase/auth/getUserAuthStatus.ts +2 -2
- package/src/supabase/auth/removeCustomClaims.ts +2 -2
- package/src/supabase/auth/setCustomClaims.ts +2 -2
- package/src/supabase/baseFunction.ts +3 -3
- package/src/supabase/billing/cancelSubscription.ts +2 -2
- package/src/supabase/billing/changePlan.ts +2 -2
- package/src/supabase/billing/createCheckoutSession.ts +2 -2
- package/src/supabase/billing/createCustomerPortal.ts +2 -2
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -2
- package/src/supabase/crud/aggregate.ts +11 -8
- package/src/supabase/crud/create.ts +2 -2
- package/src/supabase/crud/delete.ts +1 -1
- package/src/supabase/crud/get.ts +2 -2
- package/src/supabase/crud/index.ts +1 -1
- package/src/supabase/crud/list.ts +2 -2
- package/src/supabase/crud/update.ts +2 -2
- package/src/supabase/helpers/authProvider.ts +2 -2
- package/src/supabase/index.ts +10 -2
- package/src/supabase/oauth/disconnect.ts +104 -0
- package/src/supabase/oauth/exchangeToken.ts +152 -0
- package/src/supabase/oauth/getConnections.ts +85 -0
- package/src/supabase/oauth/index.ts +15 -0
- package/src/supabase/oauth/refreshToken.ts +131 -0
- package/src/supabase/registerCrudFunctions.ts +1 -1
- package/src/supabase/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -1
- package/src/supabase/utils/rateLimiter.ts +1 -1
- package/src/vercel/api/auth/get-custom-claims.ts +1 -1
- package/src/vercel/api/auth/get-user-auth-status.ts +1 -1
- package/src/vercel/api/auth/index.ts +1 -1
- package/src/vercel/api/auth/remove-custom-claims.ts +1 -1
- package/src/vercel/api/auth/set-custom-claims.ts +69 -24
- package/src/vercel/api/billing/cancel.ts +3 -3
- package/src/vercel/api/billing/change-plan.ts +3 -3
- package/src/vercel/api/billing/create-checkout-session.ts +3 -3
- package/src/vercel/api/billing/customer-portal.ts +1 -1
- package/src/vercel/api/billing/index.ts +1 -1
- package/src/vercel/api/billing/refresh-subscription-status.ts +1 -1
- package/src/vercel/api/billing/webhook-handler.ts +3 -3
- package/src/vercel/api/config/constants.ts +9 -9
- package/src/vercel/api/config/firebase-admin.ts +3 -3
- package/src/vercel/api/config/index.ts +1 -1
- package/src/vercel/api/crud/create.ts +1 -1
- package/src/vercel/api/crud/delete.ts +1 -1
- package/src/vercel/api/crud/get.ts +1 -1
- package/src/vercel/api/crud/index.ts +1 -1
- package/src/vercel/api/crud/list.ts +1 -1
- package/src/vercel/api/crud/update.ts +1 -1
- package/src/vercel/api/index.d.ts +1 -1
- package/src/vercel/api/index.ts +1 -1
- package/src/vercel/api/oauth/check-github-access.ts +3 -3
- package/src/vercel/api/oauth/exchange-token.ts +1 -1
- package/src/vercel/api/oauth/grant-github-access.ts +3 -3
- package/src/vercel/api/oauth/index.ts +1 -1
- package/src/vercel/api/oauth/revoke-github-access.ts +1 -1
- package/src/vercel/api/utils/cors.ts +4 -4
- package/src/vercel/baseFunction.ts +2 -2
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock external dependencies that utils.ts imports at module level
|
|
4
|
+
vi.mock('stripe', () => ({
|
|
5
|
+
default: vi.fn(),
|
|
6
|
+
}));
|
|
7
|
+
vi.mock('@donotdev/firebase/server', () => ({
|
|
8
|
+
getFirebaseAdminAuth: vi.fn(),
|
|
9
|
+
getFirebaseAdminFirestore: vi.fn(),
|
|
10
|
+
initFirebaseAdmin: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
vi.mock('@donotdev/core/server', () => {
|
|
13
|
+
class DoNotDevError extends Error {
|
|
14
|
+
code: string;
|
|
15
|
+
details: any;
|
|
16
|
+
constructor(message: string, code: string = 'internal', opts?: any) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'DoNotDevError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.details = opts?.details;
|
|
21
|
+
}
|
|
22
|
+
toString() {
|
|
23
|
+
return `DoNotDevError [${this.code}]: ${this.message}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { DoNotDevError };
|
|
27
|
+
});
|
|
28
|
+
vi.mock('../utils/internal/auth.js', () => ({
|
|
29
|
+
assertAuthenticated: vi.fn((uid: string) => uid),
|
|
30
|
+
assertAdmin: vi.fn((uid: string) => Promise.resolve(uid)),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
getUserRole,
|
|
35
|
+
createSuccessResponse,
|
|
36
|
+
createErrorResponse,
|
|
37
|
+
validateDocument,
|
|
38
|
+
validateCollectionName,
|
|
39
|
+
assertAuthenticated,
|
|
40
|
+
validateStripeEnvironment,
|
|
41
|
+
} from '../utils';
|
|
42
|
+
|
|
43
|
+
// Need to import DoNotDevError from the mocked module for instanceof checks
|
|
44
|
+
import { DoNotDevError } from '@donotdev/core/server';
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// getUserRole
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
describe('getUserRole', () => {
|
|
51
|
+
it('returns "guest" when auth is null', () => {
|
|
52
|
+
expect(getUserRole(null)).toBe('guest');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('returns "guest" when auth is undefined', () => {
|
|
56
|
+
expect(getUserRole(undefined)).toBe('guest');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('returns "guest" when auth.uid is missing', () => {
|
|
60
|
+
expect(getUserRole({})).toBe('guest');
|
|
61
|
+
expect(getUserRole({ uid: '' })).toBe('guest');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('returns "super" when token.role is "super"', () => {
|
|
65
|
+
expect(getUserRole({ uid: 'u1', token: { role: 'super' } })).toBe('super');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('returns "admin" when token.role is "admin"', () => {
|
|
69
|
+
expect(getUserRole({ uid: 'u1', token: { role: 'admin' } })).toBe('admin');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('returns "super" via legacy isSuper flag', () => {
|
|
73
|
+
expect(getUserRole({ uid: 'u1', token: { isSuper: true } })).toBe('super');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('returns "admin" via legacy isAdmin flag', () => {
|
|
77
|
+
expect(getUserRole({ uid: 'u1', token: { isAdmin: true } })).toBe('admin');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('returns "user" for authenticated user without special claims', () => {
|
|
81
|
+
expect(getUserRole({ uid: 'u1', token: {} })).toBe('user');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('returns "user" when token is missing', () => {
|
|
85
|
+
expect(getUserRole({ uid: 'u1' })).toBe('user');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('prefers role string over legacy flags', () => {
|
|
89
|
+
expect(
|
|
90
|
+
getUserRole({ uid: 'u1', token: { role: 'admin', isSuper: true } })
|
|
91
|
+
).toBe('admin');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// createSuccessResponse
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
describe('createSuccessResponse', () => {
|
|
100
|
+
it('wraps data in success envelope', () => {
|
|
101
|
+
const result = createSuccessResponse({ id: '123' });
|
|
102
|
+
|
|
103
|
+
expect(result).toEqual({ success: true, data: { id: '123' } });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('handles null data', () => {
|
|
107
|
+
const result = createSuccessResponse(null);
|
|
108
|
+
|
|
109
|
+
expect(result).toEqual({ success: true, data: null });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('handles array data', () => {
|
|
113
|
+
const result = createSuccessResponse([1, 2, 3]);
|
|
114
|
+
|
|
115
|
+
expect(result).toEqual({ success: true, data: [1, 2, 3] });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// createErrorResponse
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
|
|
123
|
+
describe('createErrorResponse', () => {
|
|
124
|
+
it('formats DoNotDevError with code and details', () => {
|
|
125
|
+
const error = new DoNotDevError('Bad input', 'invalid-argument', {
|
|
126
|
+
details: { field: 'email' },
|
|
127
|
+
});
|
|
128
|
+
const result = createErrorResponse(error);
|
|
129
|
+
|
|
130
|
+
expect(result.success).toBe(false);
|
|
131
|
+
expect(result.error.code).toBe('invalid-argument');
|
|
132
|
+
expect(result.error.message).toBe('Bad input');
|
|
133
|
+
expect(result.error.details).toEqual({ field: 'email' });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('formats generic Error as internal', () => {
|
|
137
|
+
const result = createErrorResponse(new Error('oops'));
|
|
138
|
+
|
|
139
|
+
expect(result.success).toBe(false);
|
|
140
|
+
expect(result.error.code).toBe('internal');
|
|
141
|
+
expect(result.error.message).toBe('oops');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('formats non-Error as internal with generic message', () => {
|
|
145
|
+
const result = createErrorResponse('some string');
|
|
146
|
+
|
|
147
|
+
expect(result.success).toBe(false);
|
|
148
|
+
expect(result.error.code).toBe('internal');
|
|
149
|
+
expect(result.error.message).toBe('An unexpected error occurred');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('formats null as internal with generic message', () => {
|
|
153
|
+
const result = createErrorResponse(null);
|
|
154
|
+
|
|
155
|
+
expect(result.success).toBe(false);
|
|
156
|
+
expect(result.error.code).toBe('internal');
|
|
157
|
+
expect(result.error.message).toBe('An unexpected error occurred');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
// validateDocument
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
describe('validateDocument', () => {
|
|
166
|
+
it('accepts valid object data', () => {
|
|
167
|
+
expect(() => validateDocument({ name: 'test' })).not.toThrow();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('rejects null', () => {
|
|
171
|
+
expect(() => validateDocument(null)).toThrow('Invalid document data');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('rejects undefined', () => {
|
|
175
|
+
expect(() => validateDocument(undefined)).toThrow('Invalid document data');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('rejects non-object', () => {
|
|
179
|
+
expect(() => validateDocument('string')).toThrow('Invalid document data');
|
|
180
|
+
expect(() => validateDocument(123)).toThrow('Invalid document data');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('rejects arrays', () => {
|
|
184
|
+
expect(() => validateDocument([1, 2])).toThrow(
|
|
185
|
+
'Document data cannot be an array'
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
// validateCollectionName
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
describe('validateCollectionName', () => {
|
|
195
|
+
it('accepts valid collection names', () => {
|
|
196
|
+
expect(() => validateCollectionName('users')).not.toThrow();
|
|
197
|
+
expect(() => validateCollectionName('myCollection')).not.toThrow();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('rejects empty string', () => {
|
|
201
|
+
expect(() => validateCollectionName('')).toThrow(
|
|
202
|
+
'Collection name is required'
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('rejects names with slashes (path traversal)', () => {
|
|
207
|
+
expect(() => validateCollectionName('users/admin')).toThrow(
|
|
208
|
+
'Invalid collection name'
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('rejects names with double dots (path traversal)', () => {
|
|
213
|
+
expect(() => validateCollectionName('..users')).toThrow(
|
|
214
|
+
'Invalid collection name'
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('rejects names starting with underscore (internal collections)', () => {
|
|
219
|
+
expect(() => validateCollectionName('_internal')).toThrow(
|
|
220
|
+
'Invalid collection name'
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
// assertAuthenticated
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
|
|
229
|
+
describe('assertAuthenticated', () => {
|
|
230
|
+
it('returns uid when auth has uid', () => {
|
|
231
|
+
const result = assertAuthenticated({ uid: 'user-123' });
|
|
232
|
+
|
|
233
|
+
expect(result).toBe('user-123');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('throws when auth is null', () => {
|
|
237
|
+
expect(() => assertAuthenticated(null)).toThrow(
|
|
238
|
+
'User must be authenticated'
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('throws when auth has no uid', () => {
|
|
243
|
+
expect(() => assertAuthenticated({})).toThrow(
|
|
244
|
+
'User must be authenticated'
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('throws when auth.uid is empty string', () => {
|
|
249
|
+
expect(() => assertAuthenticated({ uid: '' })).toThrow(
|
|
250
|
+
'User must be authenticated'
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// ---------------------------------------------------------------------------
|
|
256
|
+
// validateStripeEnvironment
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
|
|
259
|
+
describe('validateStripeEnvironment', () => {
|
|
260
|
+
const originalEnv = { ...process.env };
|
|
261
|
+
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
delete process.env.STRIPE_SECRET_KEY;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
afterAll(() => {
|
|
267
|
+
process.env = { ...originalEnv };
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('throws when STRIPE_SECRET_KEY is missing', () => {
|
|
271
|
+
expect(() => validateStripeEnvironment()).toThrow(
|
|
272
|
+
'Missing STRIPE_SECRET_KEY'
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('does not throw when STRIPE_SECRET_KEY is set', () => {
|
|
277
|
+
process.env.STRIPE_SECRET_KEY = 'sk_test_123';
|
|
278
|
+
|
|
279
|
+
expect(() => validateStripeEnvironment()).not.toThrow();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { validateEnvironment } from '../validation';
|
|
4
|
+
|
|
5
|
+
describe('validateEnvironment', () => {
|
|
6
|
+
const originalEnv = { ...process.env };
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
delete process.env.STRIPE_SECRET_KEY;
|
|
10
|
+
delete process.env.STRIPE_WEBHOOK_SECRET;
|
|
11
|
+
delete process.env.STRIPE_API_VERSION;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
process.env = { ...originalEnv };
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('throws listing all missing env vars', () => {
|
|
19
|
+
expect(() => validateEnvironment()).toThrow('Missing required environment variables');
|
|
20
|
+
expect(() => validateEnvironment()).toThrow('STRIPE_SECRET_KEY');
|
|
21
|
+
expect(() => validateEnvironment()).toThrow('STRIPE_WEBHOOK_SECRET');
|
|
22
|
+
expect(() => validateEnvironment()).toThrow('STRIPE_API_VERSION');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('throws for missing single env var', () => {
|
|
26
|
+
process.env.STRIPE_SECRET_KEY = 'sk_test_abc';
|
|
27
|
+
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
|
|
28
|
+
|
|
29
|
+
expect(() => validateEnvironment()).toThrow('STRIPE_API_VERSION');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('throws for invalid STRIPE_API_VERSION format', () => {
|
|
33
|
+
process.env.STRIPE_SECRET_KEY = 'sk_test_abc';
|
|
34
|
+
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
|
|
35
|
+
process.env.STRIPE_API_VERSION = 'bad-format';
|
|
36
|
+
|
|
37
|
+
expect(() => validateEnvironment()).toThrow('Invalid STRIPE_API_VERSION format');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('throws for invalid STRIPE_SECRET_KEY format', () => {
|
|
41
|
+
process.env.STRIPE_SECRET_KEY = 'pk_test_abc';
|
|
42
|
+
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
|
|
43
|
+
process.env.STRIPE_API_VERSION = '2025-09-30.clover';
|
|
44
|
+
|
|
45
|
+
expect(() => validateEnvironment()).toThrow('Invalid STRIPE_SECRET_KEY format');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('passes with all valid env vars', () => {
|
|
49
|
+
process.env.STRIPE_SECRET_KEY = 'sk_test_abc';
|
|
50
|
+
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
|
|
51
|
+
process.env.STRIPE_API_VERSION = '2025-09-30.clover';
|
|
52
|
+
|
|
53
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
54
|
+
|
|
55
|
+
expect(() => validateEnvironment()).not.toThrow();
|
|
56
|
+
|
|
57
|
+
consoleSpy.mockRestore();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('accepts various valid API version formats', () => {
|
|
61
|
+
process.env.STRIPE_SECRET_KEY = 'sk_live_abc';
|
|
62
|
+
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_abc';
|
|
63
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
64
|
+
|
|
65
|
+
process.env.STRIPE_API_VERSION = '2024-12-18.acacia';
|
|
66
|
+
expect(() => validateEnvironment()).not.toThrow();
|
|
67
|
+
|
|
68
|
+
process.env.STRIPE_API_VERSION = '2025-09-30.clover';
|
|
69
|
+
expect(() => validateEnvironment()).not.toThrow();
|
|
70
|
+
|
|
71
|
+
consoleSpy.mockRestore();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Create Checkout Session Algorithm
|
|
5
5
|
* @description Platform-agnostic algorithm for creating Stripe checkout sessions
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
/**
|
|
19
19
|
* Provider interface for Stripe checkout operations
|
|
20
20
|
*
|
|
21
|
-
* @version 0.0
|
|
21
|
+
* @version 0.1.0
|
|
22
22
|
* @since 0.0.1
|
|
23
23
|
* @author AMBROISE PARK Consulting
|
|
24
24
|
*/
|
|
@@ -40,7 +40,7 @@ export interface StripeCheckoutProvider {
|
|
|
40
40
|
/**
|
|
41
41
|
* Provider interface for authentication operations
|
|
42
42
|
*
|
|
43
|
-
* @version 0.0
|
|
43
|
+
* @version 0.1.0
|
|
44
44
|
* @since 0.0.1
|
|
45
45
|
* @author AMBROISE PARK Consulting
|
|
46
46
|
*/
|
|
@@ -53,7 +53,7 @@ export interface AuthCheckoutProvider {
|
|
|
53
53
|
/**
|
|
54
54
|
* Create checkout session algorithm
|
|
55
55
|
*
|
|
56
|
-
* @version 0.0
|
|
56
|
+
* @version 0.1.0
|
|
57
57
|
* @since 0.0.1
|
|
58
58
|
* @author AMBROISE PARK Consulting
|
|
59
59
|
*/
|
|
@@ -91,6 +91,11 @@ export async function createCheckoutAlgorithm(
|
|
|
91
91
|
throw new Error('Price ID mismatch with configuration');
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
// ✅ VALIDATE: userId exists
|
|
95
|
+
if (!userId) {
|
|
96
|
+
throw new Error('Missing userId in request');
|
|
97
|
+
}
|
|
98
|
+
|
|
94
99
|
// Verify user exists
|
|
95
100
|
await authProvider.getUser(userId);
|
|
96
101
|
|
|
@@ -101,7 +106,7 @@ export async function createCheckoutAlgorithm(
|
|
|
101
106
|
metadata: {
|
|
102
107
|
...metadata,
|
|
103
108
|
userId,
|
|
104
|
-
billingConfigKey: configKey, // ✅ Server values AFTER spread — cannot be overwritten by client
|
|
109
|
+
billingConfigKey: configKey as string, // ✅ Server values AFTER spread — cannot be overwritten by client
|
|
105
110
|
},
|
|
106
111
|
allowPromotionCodes,
|
|
107
112
|
successUrl: successUrl || `${process.env.FRONTEND_URL}/billing/success`,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Shared Subscription Management Logic
|
|
5
5
|
* @description Platform-agnostic subscription management functions
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -23,7 +23,7 @@ import type Stripe from 'stripe';
|
|
|
23
23
|
/**
|
|
24
24
|
* Cancel user subscription at period end
|
|
25
25
|
*
|
|
26
|
-
* @version 0.0
|
|
26
|
+
* @version 0.1.0
|
|
27
27
|
* @since 0.0.1
|
|
28
28
|
* @author AMBROISE PARK Consulting
|
|
29
29
|
*/
|
|
@@ -92,7 +92,7 @@ export async function cancelUserSubscription(
|
|
|
92
92
|
/**
|
|
93
93
|
* Change user subscription plan
|
|
94
94
|
*
|
|
95
|
-
* @version 0.0
|
|
95
|
+
* @version 0.1.0
|
|
96
96
|
* @since 0.0.1
|
|
97
97
|
* @author AMBROISE PARK Consulting
|
|
98
98
|
*/
|
|
@@ -185,7 +185,7 @@ export async function changeUserPlan(
|
|
|
185
185
|
/**
|
|
186
186
|
* Create Stripe Customer Portal session
|
|
187
187
|
*
|
|
188
|
-
* @version 0.0
|
|
188
|
+
* @version 0.1.0
|
|
189
189
|
* @since 0.0.1
|
|
190
190
|
* @author AMBROISE PARK Consulting
|
|
191
191
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview User subscription update utilities
|
|
5
5
|
* @description Functions for updating user subscription data
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* Subscription data structure
|
|
16
16
|
*
|
|
17
|
-
* @version 0.0
|
|
17
|
+
* @version 0.1.0
|
|
18
18
|
* @since 0.0.1
|
|
19
19
|
* @author AMBROISE PARK Consulting
|
|
20
20
|
*/
|
|
@@ -30,7 +30,7 @@ export interface SubscriptionData {
|
|
|
30
30
|
/**
|
|
31
31
|
* Platform-agnostic auth provider interface
|
|
32
32
|
*
|
|
33
|
-
* @version 0.0
|
|
33
|
+
* @version 0.1.0
|
|
34
34
|
* @since 0.0.1
|
|
35
35
|
* @author AMBROISE PARK Consulting
|
|
36
36
|
*/
|
|
@@ -48,7 +48,7 @@ export interface AuthProvider {
|
|
|
48
48
|
* Platform-agnostic subscription update using dependency injection
|
|
49
49
|
* Works on Firebase Functions, Vercel, AWS Lambda, etc.
|
|
50
50
|
*
|
|
51
|
-
* @version 0.0
|
|
51
|
+
* @version 0.1.0
|
|
52
52
|
* @since 0.0.1
|
|
53
53
|
* @author AMBROISE PARK Consulting
|
|
54
54
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Adaptive Idempotency for Billing Webhooks
|
|
5
5
|
* @description Auto-detects Firestore, gracefully degrades to in-memory
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -15,7 +15,7 @@ import { isFirestoreConfigured } from '../utils/detectFirestore.js';
|
|
|
15
15
|
/**
|
|
16
16
|
* Idempotency store interface
|
|
17
17
|
*
|
|
18
|
-
* @version 0.0
|
|
18
|
+
* @version 0.1.0
|
|
19
19
|
* @since 0.0.1
|
|
20
20
|
* @author AMBROISE PARK Consulting
|
|
21
21
|
*/
|
|
@@ -172,7 +172,7 @@ class FirestoreIdempotency implements IdempotencyStore {
|
|
|
172
172
|
*
|
|
173
173
|
* Falls back to in-memory if Firestore not available
|
|
174
174
|
*
|
|
175
|
-
* @version 0.0
|
|
175
|
+
* @version 0.1.0
|
|
176
176
|
* @since 0.0.1
|
|
177
177
|
* @author AMBROISE PARK Consulting
|
|
178
178
|
*/
|
|
@@ -196,7 +196,7 @@ export function createIdempotencyStore(): IdempotencyStore {
|
|
|
196
196
|
/**
|
|
197
197
|
* Reset cached store (for testing only)
|
|
198
198
|
*
|
|
199
|
-
* @version 0.0
|
|
199
|
+
* @version 0.1.0
|
|
200
200
|
* @since 0.0.1
|
|
201
201
|
* @author AMBROISE PARK Consulting
|
|
202
202
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Stripe webhook handler
|
|
5
5
|
* @description Handles Stripe webhook events for subscription management
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -70,7 +70,7 @@ export type UpdateSubscriptionFn = (
|
|
|
70
70
|
* @param billingConfig - Billing configuration
|
|
71
71
|
* @param updateSubscription - Function to update user subscription
|
|
72
72
|
*
|
|
73
|
-
* @version 0.0
|
|
73
|
+
* @version 0.1.0
|
|
74
74
|
* @since 0.0.1
|
|
75
75
|
* @author AMBROISE PARK Consulting
|
|
76
76
|
*/
|
|
@@ -130,7 +130,7 @@ export async function processWebhook(
|
|
|
130
130
|
/**
|
|
131
131
|
* Route events to appropriate handlers
|
|
132
132
|
*
|
|
133
|
-
* @version 0.0
|
|
133
|
+
* @version 0.1.0
|
|
134
134
|
* @since 0.0.1
|
|
135
135
|
* @author AMBROISE PARK Consulting
|
|
136
136
|
*/
|
|
@@ -183,7 +183,7 @@ async function routeEvent(
|
|
|
183
183
|
/**
|
|
184
184
|
* Handle checkout completed with graceful hook execution
|
|
185
185
|
*
|
|
186
|
-
* @version 0.0
|
|
186
|
+
* @version 0.1.0
|
|
187
187
|
* @since 0.0.1
|
|
188
188
|
* @author AMBROISE PARK Consulting
|
|
189
189
|
*/
|
|
@@ -297,7 +297,7 @@ async function handleCheckoutCompleted(
|
|
|
297
297
|
/**
|
|
298
298
|
* Handle subscription renewal
|
|
299
299
|
*
|
|
300
|
-
* @version 0.0
|
|
300
|
+
* @version 0.1.0
|
|
301
301
|
* @since 0.0.1
|
|
302
302
|
* @author AMBROISE PARK Consulting
|
|
303
303
|
*/
|
|
@@ -378,7 +378,7 @@ async function handleInvoicePaymentSucceeded(
|
|
|
378
378
|
/**
|
|
379
379
|
* Handle subscription cancellation
|
|
380
380
|
*
|
|
381
|
-
* @version 0.0
|
|
381
|
+
* @version 0.1.0
|
|
382
382
|
* @since 0.0.1
|
|
383
383
|
* @author AMBROISE PARK Consulting
|
|
384
384
|
*/
|
|
@@ -443,7 +443,7 @@ async function handleSubscriptionDeleted(
|
|
|
443
443
|
/**
|
|
444
444
|
* Handle payment failure
|
|
445
445
|
*
|
|
446
|
-
* @version 0.0
|
|
446
|
+
* @version 0.1.0
|
|
447
447
|
* @since 0.0.1
|
|
448
448
|
* @author AMBROISE PARK Consulting
|
|
449
449
|
*/
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @description Platform-agnostic error classification. Always throws DoNotDevError.
|
|
6
6
|
* Platform adapters (Firebase baseFunction, Vercel route handler) catch and convert.
|
|
7
7
|
*
|
|
8
|
-
* @version 0.0
|
|
8
|
+
* @version 0.1.0
|
|
9
9
|
* @since 0.0.1
|
|
10
10
|
* @author AMBROISE PARK Consulting
|
|
11
11
|
*/
|
|
@@ -23,7 +23,7 @@ export { DoNotDevError };
|
|
|
23
23
|
* @param error - The error to handle
|
|
24
24
|
* @throws DoNotDevError always
|
|
25
25
|
*
|
|
26
|
-
* @version 0.0
|
|
26
|
+
* @version 0.1.0
|
|
27
27
|
* @since 0.0.1
|
|
28
28
|
* @author AMBROISE PARK Consulting
|
|
29
29
|
*/
|
package/src/shared/firebase.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @fileoverview Firebase data transformation utilities for functions
|
|
5
5
|
* @description Server-safe functions for converting data between Firebase and application formats
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -16,7 +16,7 @@ import type { DateValue, FirestoreTimestamp } from '@donotdev/core/server';
|
|
|
16
16
|
* @param date - The Date object to convert
|
|
17
17
|
* @returns A representation of the timestamp
|
|
18
18
|
*
|
|
19
|
-
* @version 0.0
|
|
19
|
+
* @version 0.1.0
|
|
20
20
|
* @since 0.0.1
|
|
21
21
|
* @author AMBROISE PARK Consulting
|
|
22
22
|
*/
|
|
@@ -40,7 +40,7 @@ export function createTimestamp(date: Date): FirestoreTimestamp {
|
|
|
40
40
|
* @returns The Firestore Timestamp
|
|
41
41
|
* @throws Error if the date is invalid
|
|
42
42
|
*
|
|
43
|
-
* @version 0.0
|
|
43
|
+
* @version 0.1.0
|
|
44
44
|
* @since 0.0.1
|
|
45
45
|
* @author AMBROISE PARK Consulting
|
|
46
46
|
*/
|
|
@@ -72,7 +72,7 @@ export function toTimestamp(date: string | Date): FirestoreTimestamp {
|
|
|
72
72
|
* @param timestamp - The Firestore Timestamp
|
|
73
73
|
* @returns The ISO string representation
|
|
74
74
|
*
|
|
75
|
-
* @version 0.0
|
|
75
|
+
* @version 0.1.0
|
|
76
76
|
* @since 0.0.1
|
|
77
77
|
* @author AMBROISE PARK Consulting
|
|
78
78
|
*/
|
|
@@ -85,7 +85,7 @@ export function toISOString(timestamp: FirestoreTimestamp): string {
|
|
|
85
85
|
* @param value - The value to check
|
|
86
86
|
* @returns True if the value is a Timestamp
|
|
87
87
|
*
|
|
88
|
-
* @version 0.0
|
|
88
|
+
* @version 0.1.0
|
|
89
89
|
* @since 0.0.1
|
|
90
90
|
* @author AMBROISE PARK Consulting
|
|
91
91
|
*/
|
|
@@ -106,7 +106,7 @@ export function isTimestamp(value: any): value is FirestoreTimestamp {
|
|
|
106
106
|
* @param includeDocumentIds - Whether to include document IDs
|
|
107
107
|
* @returns The transformed data
|
|
108
108
|
*
|
|
109
|
-
* @version 0.0
|
|
109
|
+
* @version 0.1.0
|
|
110
110
|
* @since 0.0.1
|
|
111
111
|
* @author AMBROISE PARK Consulting
|
|
112
112
|
*/
|
|
@@ -164,7 +164,7 @@ export function transformFirestoreData<T = any>(
|
|
|
164
164
|
* @param removeFields - Optional array of field names to remove
|
|
165
165
|
* @returns The prepared data
|
|
166
166
|
*
|
|
167
|
-
* @version 0.0
|
|
167
|
+
* @version 0.1.0
|
|
168
168
|
* @since 0.0.1
|
|
169
169
|
* @author AMBROISE PARK Consulting
|
|
170
170
|
*/
|