@donotdev/functions 0.0.16 → 0.0.18
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/lib/firebase/index.js +558 -1515
- package/lib/firebase/index.js.map +4 -4
- package/lib/shared/index.js +163 -333
- package/lib/shared/index.js.map +4 -4
- package/lib/vercel/api/index.js +190 -325
- package/lib/vercel/api/index.js.map +4 -4
- package/package.json +4 -4
- package/src/firebase/baseFunction.ts +4 -5
- package/src/firebase/billing/changePlan.ts +1 -1
- package/src/firebase/billing/createCheckoutSession.ts +4 -4
- package/src/firebase/billing/refreshSubscriptionStatus.ts +1 -1
- package/src/firebase/crud/create.ts +16 -6
- package/src/firebase/crud/delete.ts +0 -6
- package/src/firebase/crud/list.ts +12 -8
- package/src/firebase/crud/update.ts +1 -1
- package/src/firebase/oauth/exchangeToken.ts +7 -2
- package/src/firebase/oauth/getConnections.ts +2 -1
- package/src/shared/billing/__tests__/createCheckout.test.ts +7 -5
- package/src/shared/billing/__tests__/webhookHandler.test.ts +1 -0
- package/src/shared/billing/createCheckout.ts +2 -2
- package/src/shared/billing/helpers/subscriptionManagement.ts +2 -2
- package/src/shared/billing/idempotency.ts +39 -0
- package/src/shared/billing/webhookHandler.ts +19 -17
- package/src/shared/errorHandling.ts +2 -1
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +2 -1
- package/src/shared/schema.ts +1 -1
- package/src/shared/utils/__tests__/functionWrapper.test.ts +1 -1
- package/src/shared/utils/firebaseHelpers.ts +1 -1
- package/src/shared/utils/internal/auth.ts +1 -1
- package/src/shared/utils/internal/idempotency.ts +4 -72
- package/src/shared/utils/internal/rateLimiter.ts +1 -1
- package/src/shared/utils/internal/validation.ts +4 -1
- package/src/shared/utils/vercelHelpers.ts +1 -2
- package/src/shared/validation.ts +1 -1
- package/src/supabase/baseFunction.ts +7 -5
- package/src/supabase/billing/createCheckoutSession.ts +2 -3
- package/src/supabase/billing/refreshSubscriptionStatus.ts +2 -1
- package/src/supabase/crud/aggregate.ts +0 -1
- package/src/supabase/crud/create.ts +4 -2
- package/src/supabase/crud/get.ts +0 -1
- package/src/supabase/crud/list.ts +1 -2
- package/src/supabase/crud/update.ts +0 -1
- package/src/supabase/helpers/authProvider.ts +0 -1
- package/src/supabase/utils/rateLimiter.ts +4 -2
- package/src/vercel/api/billing/change-plan.ts +1 -1
- package/src/vercel/api/billing/create-checkout-session.ts +1 -2
- package/src/vercel/api/billing/refresh-subscription-status.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/list.ts +3 -3
- package/src/vercel/api/crud/update.ts +1 -1
- package/src/vercel/api/oauth/check-github-access.ts +1 -2
- package/src/vercel/api/oauth/exchange-token.ts +1 -2
- package/src/vercel/api/oauth/grant-github-access.ts +1 -2
- package/src/vercel/baseFunction.ts +3 -2
|
@@ -9,14 +9,13 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import * as v from 'valibot';
|
|
13
|
-
|
|
14
12
|
import {
|
|
15
13
|
withVercelSchemaValidation,
|
|
16
14
|
validateRequestData,
|
|
17
15
|
} from './schemaValidation.js';
|
|
18
16
|
|
|
19
17
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
18
|
+
import type * as v from 'valibot';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Creates a Vercel API handler with schema validation
|
package/src/shared/validation.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function validateEnvironment(): void {
|
|
|
52
52
|
if (!secretKey.startsWith('sk_')) {
|
|
53
53
|
throw new Error(
|
|
54
54
|
`❌ Invalid STRIPE_SECRET_KEY format\n` +
|
|
55
|
-
`Secret keys must start with "sk_" (found: "${secretKey.substring(0,
|
|
55
|
+
`Secret keys must start with "sk_" (found: "${secretKey.substring(0, 3)}...")`
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -15,14 +15,15 @@ import * as v from 'valibot';
|
|
|
15
15
|
|
|
16
16
|
import { hasRoleAccess } from '@donotdev/core/server';
|
|
17
17
|
import type { UserRole, SecurityContext } from '@donotdev/core/server';
|
|
18
|
-
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
19
18
|
|
|
19
|
+
import { recordOperationMetrics } from './utils/monitoring.js';
|
|
20
20
|
import {
|
|
21
21
|
checkRateLimitWithPostgres,
|
|
22
22
|
DEFAULT_RATE_LIMITS,
|
|
23
23
|
} from './utils/rateLimiter.js';
|
|
24
|
+
|
|
24
25
|
import type { RateLimitConfig } from './utils/rateLimiter.js';
|
|
25
|
-
import {
|
|
26
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
26
27
|
|
|
27
28
|
// =============================================================================
|
|
28
29
|
// Types
|
|
@@ -206,7 +207,9 @@ export function createSupabaseHandler<TReq, TRes>(
|
|
|
206
207
|
const MAX_BODY_SIZE = 1_048_576; // 1MB
|
|
207
208
|
if (contentLength && parseInt(contentLength, 10) > MAX_BODY_SIZE) {
|
|
208
209
|
return respond(
|
|
209
|
-
{
|
|
210
|
+
{
|
|
211
|
+
error: `Request body too large. Maximum size: ${MAX_BODY_SIZE} bytes`,
|
|
212
|
+
},
|
|
210
213
|
413
|
|
211
214
|
);
|
|
212
215
|
}
|
|
@@ -304,8 +307,7 @@ function getEnv(key: string, defaultValue: string = ''): string {
|
|
|
304
307
|
}
|
|
305
308
|
|
|
306
309
|
// G65: Basic IP format validation (IPv4 or IPv6 pattern)
|
|
307
|
-
const IP_PATTERN =
|
|
308
|
-
/^(?:\d{1,3}\.){3}\d{1,3}$|^[0-9a-fA-F:]{2,45}$/;
|
|
310
|
+
const IP_PATTERN = /^(?:\d{1,3}\.){3}\d{1,3}$|^[0-9a-fA-F:]{2,45}$/;
|
|
309
311
|
|
|
310
312
|
function isValidIp(ip: string): boolean {
|
|
311
313
|
return IP_PATTERN.test(ip);
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
13
12
|
import { CreateCheckoutSessionRequestSchema } from '@donotdev/core/server';
|
|
13
|
+
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
14
|
+
import type { CreateCheckoutSessionRequest } from '@donotdev/core/server';
|
|
14
15
|
|
|
15
16
|
import { createCheckoutAlgorithm } from '../../shared/billing/createCheckout.js';
|
|
16
17
|
import {
|
|
@@ -21,8 +22,6 @@ import {
|
|
|
21
22
|
import { createSupabaseHandler } from '../baseFunction.js';
|
|
22
23
|
import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
|
|
23
24
|
|
|
24
|
-
import type { CreateCheckoutSessionRequest } from '@donotdev/core/server';
|
|
25
|
-
|
|
26
25
|
// =============================================================================
|
|
27
26
|
// Factory
|
|
28
27
|
// =============================================================================
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import Stripe from 'stripe';
|
|
13
12
|
import * as v from 'valibot';
|
|
14
13
|
|
|
15
14
|
import {
|
|
@@ -20,6 +19,8 @@ import {
|
|
|
20
19
|
import { createSupabaseHandler } from '../baseFunction.js';
|
|
21
20
|
import { createSupabaseAuthProvider } from '../helpers/authProvider.js';
|
|
22
21
|
|
|
22
|
+
import type Stripe from 'stripe';
|
|
23
|
+
|
|
23
24
|
// =============================================================================
|
|
24
25
|
// Schema
|
|
25
26
|
// =============================================================================
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
import * as v from 'valibot';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_STATUS_VALUE,
|
|
16
|
+
filterVisibleFields,
|
|
17
|
+
} from '@donotdev/core/server';
|
|
15
18
|
import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
|
|
16
|
-
|
|
17
19
|
import { defaultFieldMapper } from '@donotdev/supabase';
|
|
18
20
|
|
|
19
21
|
import { createMetadata } from '../../shared/index.js';
|
package/src/supabase/crud/get.ts
CHANGED
|
@@ -21,7 +21,6 @@ import type {
|
|
|
21
21
|
EntityOwnershipPublicCondition,
|
|
22
22
|
UserRole,
|
|
23
23
|
} from '@donotdev/core/server';
|
|
24
|
-
|
|
25
24
|
import {
|
|
26
25
|
createEntityAwareMapper,
|
|
27
26
|
defaultFieldMapper,
|
|
@@ -189,7 +188,7 @@ export function createSupabaseListEntities(
|
|
|
189
188
|
const {
|
|
190
189
|
where = [],
|
|
191
190
|
orderBy = [],
|
|
192
|
-
limit =
|
|
191
|
+
limit = 1000,
|
|
193
192
|
startAfterId,
|
|
194
193
|
startAfterCursor,
|
|
195
194
|
search,
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
* @author AMBROISE PARK Consulting
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
27
26
|
import type {
|
|
28
27
|
ServerRateLimitConfig as RateLimitConfig,
|
|
29
28
|
ServerRateLimitResult as RateLimitResult,
|
|
30
29
|
} from '@donotdev/core';
|
|
31
30
|
|
|
31
|
+
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
32
|
+
|
|
32
33
|
export type { RateLimitConfig, RateLimitResult };
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -203,7 +204,8 @@ export async function checkRateLimitWithPostgres(
|
|
|
203
204
|
// G70: Distinguish missing function from network/other errors for clearer diagnostics
|
|
204
205
|
const isNotFound =
|
|
205
206
|
error.code === '42883' ||
|
|
206
|
-
error.message?.includes('function') &&
|
|
207
|
+
(error.message?.includes('function') &&
|
|
208
|
+
error.message?.includes('does not exist'));
|
|
207
209
|
if (isNotFound) {
|
|
208
210
|
console.error(
|
|
209
211
|
'[rateLimit] rate_limit_check function not found. ' +
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import Stripe from 'stripe';
|
|
13
12
|
import * as v from 'valibot';
|
|
14
13
|
|
|
15
14
|
import type { StripeBackConfig } from '@donotdev/core/server';
|
|
@@ -21,6 +20,7 @@ import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
|
|
|
21
20
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
22
21
|
|
|
23
22
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
23
|
+
import type Stripe from 'stripe';
|
|
24
24
|
|
|
25
25
|
const changePlanSchema = v.object({
|
|
26
26
|
userId: v.string(),
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import * as v from 'valibot';
|
|
13
|
-
|
|
14
12
|
import { CreateCheckoutSessionRequestSchema } from '@donotdev/core/server';
|
|
15
13
|
import type {
|
|
16
14
|
CreateCheckoutSessionRequest,
|
|
@@ -23,6 +21,7 @@ import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
|
|
|
23
21
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
24
22
|
|
|
25
23
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
24
|
+
import type * as v from 'valibot';
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Business logic for creating checkout sessions
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import Stripe from 'stripe';
|
|
13
12
|
import * as v from 'valibot';
|
|
14
13
|
|
|
15
14
|
import type { RefreshSubscriptionRequest } from '@donotdev/core/server';
|
|
@@ -19,6 +18,7 @@ import { stripe, validateStripeEnvironment } from '../../../shared/utils.js';
|
|
|
19
18
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
20
19
|
|
|
21
20
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
21
|
+
import type Stripe from 'stripe';
|
|
22
22
|
|
|
23
23
|
const refreshSubscriptionStatusSchema = v.object({
|
|
24
24
|
userId: v.pipe(v.string(), v.minLength(1, 'User ID is required')),
|
|
@@ -19,11 +19,11 @@ import {
|
|
|
19
19
|
transformFirestoreData,
|
|
20
20
|
} from '../../../shared/index.js';
|
|
21
21
|
import { createMetadata } from '../../../shared/index.js';
|
|
22
|
+
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
22
23
|
import {
|
|
23
24
|
validateCollectionName,
|
|
24
25
|
validateDocument,
|
|
25
26
|
} from '../../../shared/utils.js';
|
|
26
|
-
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
27
27
|
|
|
28
28
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
29
29
|
|
|
@@ -13,8 +13,8 @@ import type { GetEntityData } from '@donotdev/core/server';
|
|
|
13
13
|
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
14
14
|
|
|
15
15
|
import { handleError } from '../../../shared/errorHandling.js';
|
|
16
|
-
import { validateCollectionName } from '../../../shared/utils.js';
|
|
17
16
|
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
17
|
+
import { validateCollectionName } from '../../../shared/utils.js';
|
|
18
18
|
|
|
19
19
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
20
20
|
|
|
@@ -16,8 +16,8 @@ import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
|
16
16
|
import { handleError } from '../../../shared/errorHandling.js';
|
|
17
17
|
import { transformFirestoreData } from '../../../shared/index.js';
|
|
18
18
|
import { filterVisibleFields } from '../../../shared/index.js';
|
|
19
|
-
import { validateCollectionName } from '../../../shared/utils.js';
|
|
20
19
|
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
20
|
+
import { validateCollectionName } from '../../../shared/utils.js';
|
|
21
21
|
|
|
22
22
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
23
23
|
|
|
@@ -16,8 +16,8 @@ import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
|
16
16
|
import { handleError } from '../../../shared/errorHandling.js';
|
|
17
17
|
import { transformFirestoreData } from '../../../shared/index.js';
|
|
18
18
|
import { filterVisibleFields } from '../../../shared/index.js';
|
|
19
|
-
import { validateCollectionName } from '../../../shared/utils.js';
|
|
20
19
|
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
20
|
+
import { validateCollectionName } from '../../../shared/utils.js';
|
|
21
21
|
|
|
22
22
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
23
23
|
|
|
@@ -57,8 +57,8 @@ export default async function handler(
|
|
|
57
57
|
// Filter out hidden statuses (Vercel routes treat all requests as non-admin)
|
|
58
58
|
query = query.where('status', 'not-in', [...HIDDEN_STATUSES]);
|
|
59
59
|
|
|
60
|
-
//
|
|
61
|
-
const parsedLimit = Math.min(parseInt(limit as string) ||
|
|
60
|
+
// Clamp limit to prevent unbounded queries (max 1000, default 1000)
|
|
61
|
+
const parsedLimit = Math.min(parseInt(limit as string) || 1000, 1000);
|
|
62
62
|
const parsedOffset = parseInt(offset as string) || 0;
|
|
63
63
|
|
|
64
64
|
// Apply limit and offset
|
|
@@ -19,11 +19,11 @@ import {
|
|
|
19
19
|
transformFirestoreData,
|
|
20
20
|
} from '../../../shared/index.js';
|
|
21
21
|
import { updateMetadata } from '../../../shared/index.js';
|
|
22
|
+
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
22
23
|
import {
|
|
23
24
|
validateCollectionName,
|
|
24
25
|
validateDocument,
|
|
25
26
|
} from '../../../shared/utils.js';
|
|
26
|
-
import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
|
|
27
27
|
|
|
28
28
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
29
29
|
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import * as v from 'valibot';
|
|
13
|
-
|
|
14
12
|
import {
|
|
15
13
|
checkGitHubAccessSchema,
|
|
16
14
|
type CheckGitHubAccessRequest,
|
|
@@ -21,6 +19,7 @@ import { GitHubApiService } from '../../../shared/index.js';
|
|
|
21
19
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
22
20
|
|
|
23
21
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
22
|
+
import type * as v from 'valibot';
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Business logic for checking GitHub access
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import * as v from 'valibot';
|
|
13
|
-
|
|
14
12
|
import {
|
|
15
13
|
OAUTH_PARTNERS,
|
|
16
14
|
exchangeTokenSchema,
|
|
@@ -25,6 +23,7 @@ import {
|
|
|
25
23
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
26
24
|
|
|
27
25
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
26
|
+
import type * as v from 'valibot';
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* Business logic for exchanging OAuth tokens
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import * as v from 'valibot';
|
|
13
|
-
|
|
14
12
|
import {
|
|
15
13
|
grantGitHubAccessSchema,
|
|
16
14
|
type GrantGitHubAccessRequest,
|
|
@@ -21,6 +19,7 @@ import { GitHubApiService } from '../../../shared/index.js';
|
|
|
21
19
|
import { createVercelBaseFunction } from '../../baseFunction.js';
|
|
22
20
|
|
|
23
21
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
22
|
+
import type * as v from 'valibot';
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Business logic for granting GitHub access
|
|
@@ -11,14 +11,15 @@
|
|
|
11
11
|
|
|
12
12
|
import * as v from 'valibot';
|
|
13
13
|
|
|
14
|
+
import type { SecurityContext } from '@donotdev/core';
|
|
15
|
+
|
|
14
16
|
import { handleError, DoNotDevError } from '../shared/errorHandling.js';
|
|
17
|
+
import { verifyAuthToken } from '../shared/utils/internal/auth.js';
|
|
15
18
|
import { recordPaymentMetrics } from '../shared/utils/internal/monitoring.js';
|
|
16
19
|
import {
|
|
17
20
|
checkRateLimitWithFirestore,
|
|
18
21
|
DEFAULT_RATE_LIMITS,
|
|
19
22
|
} from '../shared/utils/internal/rateLimiter.js';
|
|
20
|
-
import { verifyAuthToken } from '../shared/utils/internal/auth.js';
|
|
21
|
-
import type { SecurityContext } from '@donotdev/core';
|
|
22
23
|
|
|
23
24
|
import type { AuthProvider } from '../shared/utils/internal/auth.js';
|
|
24
25
|
import type { NextApiRequest, NextApiResponse } from 'next';
|