@donotdev/functions 0.0.18 → 0.0.20

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.
Files changed (149) hide show
  1. package/lib/firebase/auth/getCustomClaims.d.ts +25 -0
  2. package/lib/firebase/auth/getUserAuthStatus.d.ts +29 -0
  3. package/lib/firebase/auth/index.d.ts +12 -0
  4. package/lib/firebase/auth/removeCustomClaims.d.ts +28 -0
  5. package/lib/firebase/auth/setCustomClaims.d.ts +34 -0
  6. package/lib/firebase/baseFunction.d.ts +26 -0
  7. package/lib/firebase/billing/cancelSubscription.d.ts +10 -0
  8. package/lib/firebase/billing/changePlan.d.ts +13 -0
  9. package/lib/firebase/billing/createCheckoutSession.d.ts +21 -0
  10. package/lib/firebase/billing/createCustomerPortal.d.ts +19 -0
  11. package/lib/firebase/billing/healthCheck.d.ts +5 -0
  12. package/lib/firebase/billing/index.d.ts +18 -0
  13. package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +19 -0
  14. package/lib/firebase/billing/webhookHandler.d.ts +6 -0
  15. package/lib/firebase/config/constants.d.ts +89 -0
  16. package/lib/firebase/config/index.d.ts +9 -0
  17. package/lib/firebase/config/secrets.d.ts +15 -0
  18. package/lib/firebase/crud/aggregate.d.ts +98 -0
  19. package/lib/firebase/crud/create.d.ts +16 -0
  20. package/lib/firebase/crud/delete.d.ts +20 -0
  21. package/lib/firebase/crud/get.d.ts +24 -0
  22. package/lib/firebase/crud/index.d.ts +14 -0
  23. package/lib/firebase/crud/list.d.ts +25 -0
  24. package/lib/firebase/crud/update.d.ts +25 -0
  25. package/lib/firebase/helpers/githubAccessHelper.d.ts +30 -0
  26. package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +36 -0
  27. package/lib/firebase/helpers/index.d.ts +10 -0
  28. package/lib/firebase/index.d.ts +17 -0
  29. package/lib/firebase/index.js +25 -9110
  30. package/lib/firebase/index.js.map +4 -4
  31. package/lib/firebase/oauth/disconnect.d.ts +12 -0
  32. package/lib/firebase/oauth/exchangeToken.d.ts +9 -0
  33. package/lib/firebase/oauth/getConnections.d.ts +11 -0
  34. package/lib/firebase/oauth/githubAccess.d.ts +83 -0
  35. package/lib/firebase/oauth/index.d.ts +13 -0
  36. package/lib/firebase/oauth/refreshToken.d.ts +9 -0
  37. package/lib/firebase/registerCrudFunctions.d.ts +32 -0
  38. package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +14 -0
  39. package/lib/firebase/scheduled/index.d.ts +9 -0
  40. package/lib/shared/billing/createCheckout.d.ts +50 -0
  41. package/lib/shared/billing/helpers/index.d.ts +10 -0
  42. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +34 -0
  43. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +45 -0
  44. package/lib/shared/billing/idempotency.d.ts +22 -0
  45. package/lib/shared/billing/index.d.ts +11 -0
  46. package/lib/shared/billing/webhookHandler.d.ts +37 -0
  47. package/lib/shared/errorHandling.d.ts +14 -0
  48. package/lib/shared/firebase.d.ts +73 -0
  49. package/lib/shared/github.d.ts +128 -0
  50. package/lib/shared/index.d.ts +16 -0
  51. package/lib/shared/index.js +25 -6927
  52. package/lib/shared/index.js.map +4 -4
  53. package/lib/shared/logger.d.ts +133 -0
  54. package/lib/shared/metadata.d.ts +36 -0
  55. package/lib/shared/oauth/exchangeToken.d.ts +24 -0
  56. package/lib/shared/oauth/grantAccess.d.ts +30 -0
  57. package/lib/shared/oauth/index.d.ts +10 -0
  58. package/lib/shared/schema.d.ts +56 -0
  59. package/lib/shared/utils/detectFirestore.d.ts +31 -0
  60. package/lib/shared/utils/external/date.d.ts +36 -0
  61. package/lib/shared/utils/external/index.d.ts +11 -0
  62. package/lib/shared/utils/external/references.d.ts +12 -0
  63. package/lib/shared/utils/external/subscription.d.ts +41 -0
  64. package/lib/shared/utils/firebaseHelpers.d.ts +23 -0
  65. package/lib/shared/utils/functionWrapper.d.ts +36 -0
  66. package/lib/shared/utils/index.d.ts +14 -0
  67. package/lib/shared/utils/internal/auth.d.ts +57 -0
  68. package/lib/shared/utils/internal/firebase.d.ts +5 -0
  69. package/lib/shared/utils/internal/idempotency.d.ts +21 -0
  70. package/lib/shared/utils/internal/index.d.ts +14 -0
  71. package/lib/shared/utils/internal/monitoring.d.ts +80 -0
  72. package/lib/shared/utils/internal/rateLimiter.d.ts +82 -0
  73. package/lib/shared/utils/internal/validation.d.ts +43 -0
  74. package/lib/shared/utils/schemaValidation.d.ts +60 -0
  75. package/lib/shared/utils/validation.d.ts +98 -0
  76. package/lib/shared/utils/vercelHelpers.d.ts +18 -0
  77. package/lib/shared/utils.d.ts +234 -0
  78. package/lib/shared/validation.d.ts +16 -0
  79. package/lib/supabase/auth/deleteAccount.d.ts +16 -0
  80. package/lib/supabase/auth/getCustomClaims.d.ts +16 -0
  81. package/lib/supabase/auth/getUserAuthStatus.d.ts +18 -0
  82. package/lib/supabase/auth/removeCustomClaims.d.ts +16 -0
  83. package/lib/supabase/auth/setCustomClaims.d.ts +18 -0
  84. package/lib/supabase/baseFunction.d.ts +43 -0
  85. package/lib/supabase/billing/cancelSubscription.d.ts +9 -0
  86. package/lib/supabase/billing/changePlan.d.ts +11 -0
  87. package/lib/supabase/billing/createCheckoutSession.d.ts +11 -0
  88. package/lib/supabase/billing/createCustomerPortal.d.ts +9 -0
  89. package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +9 -0
  90. package/lib/supabase/crud/aggregate.d.ts +27 -0
  91. package/lib/supabase/crud/create.d.ts +23 -0
  92. package/lib/supabase/crud/delete.d.ts +30 -0
  93. package/lib/supabase/crud/get.d.ts +23 -0
  94. package/lib/supabase/crud/index.d.ts +20 -0
  95. package/lib/supabase/crud/list.d.ts +33 -0
  96. package/lib/supabase/crud/update.d.ts +24 -0
  97. package/lib/supabase/helpers/authProvider.d.ts +22 -0
  98. package/lib/supabase/index.d.ts +29 -0
  99. package/lib/supabase/index.js +23 -0
  100. package/lib/supabase/index.js.map +7 -0
  101. package/lib/supabase/registerCrudFunctions.d.ts +24 -0
  102. package/lib/supabase/utils/idempotency.d.ts +36 -0
  103. package/lib/supabase/utils/monitoring.d.ts +59 -0
  104. package/lib/supabase/utils/rateLimiter.d.ts +56 -0
  105. package/lib/vercel/api/auth/get-custom-claims.d.ts +2 -0
  106. package/lib/vercel/api/auth/get-user-auth-status.d.ts +2 -0
  107. package/lib/vercel/api/auth/index.d.ts +12 -0
  108. package/lib/vercel/api/auth/remove-custom-claims.d.ts +2 -0
  109. package/lib/vercel/api/auth/set-custom-claims.d.ts +10 -0
  110. package/lib/vercel/api/billing/cancel.d.ts +10 -0
  111. package/lib/vercel/api/billing/change-plan.d.ts +11 -0
  112. package/lib/vercel/api/billing/create-checkout-session.d.ts +13 -0
  113. package/lib/vercel/api/billing/customer-portal.d.ts +3 -0
  114. package/lib/vercel/api/billing/index.d.ts +14 -0
  115. package/lib/vercel/api/billing/refresh-subscription-status.d.ts +31 -0
  116. package/lib/vercel/api/billing/webhook-handler.d.ts +22 -0
  117. package/lib/vercel/api/config/constants.d.ts +103 -0
  118. package/lib/vercel/api/config/firebase-admin.d.ts +19 -0
  119. package/lib/vercel/api/config/index.d.ts +10 -0
  120. package/lib/vercel/api/crud/create.d.ts +2 -0
  121. package/lib/vercel/api/crud/delete.d.ts +2 -0
  122. package/lib/vercel/api/crud/get.d.ts +2 -0
  123. package/lib/vercel/api/crud/index.d.ts +13 -0
  124. package/lib/vercel/api/crud/list.d.ts +2 -0
  125. package/lib/vercel/api/crud/update.d.ts +2 -0
  126. package/lib/vercel/api/index.d.ts +13 -0
  127. package/lib/vercel/api/index.js +22 -4790
  128. package/lib/vercel/api/index.js.map +4 -4
  129. package/lib/vercel/api/oauth/check-github-access.d.ts +12 -0
  130. package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
  131. package/lib/vercel/api/oauth/grant-github-access.d.ts +12 -0
  132. package/lib/vercel/api/oauth/index.d.ts +12 -0
  133. package/lib/vercel/api/oauth/revoke-github-access.d.ts +11 -0
  134. package/lib/vercel/api/utils/cors.d.ts +49 -0
  135. package/lib/vercel/baseFunction.d.ts +25 -0
  136. package/package.json +4 -4
  137. package/src/firebase/auth/setCustomClaims.ts +61 -16
  138. package/src/firebase/billing/healthCheck.ts +7 -23
  139. package/src/firebase/billing/webhookHandler.ts +0 -1
  140. package/src/firebase/crud/create.ts +17 -2
  141. package/src/firebase/oauth/exchangeToken.ts +5 -5
  142. package/src/shared/billing/createCheckout.ts +6 -1
  143. package/src/shared/utils/internal/validation.ts +1 -1
  144. package/src/supabase/crud/aggregate.ts +10 -7
  145. package/src/supabase/crud/create.ts +1 -1
  146. package/src/supabase/crud/get.ts +1 -1
  147. package/src/supabase/crud/list.ts +1 -1
  148. package/src/supabase/crud/update.ts +1 -1
  149. package/src/vercel/api/auth/set-custom-claims.ts +70 -23
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Payment metrics data structure
3
+ *
4
+ * @version 0.0.1
5
+ * @since 0.0.1
6
+ * @author AMBROISE PARK Consulting
7
+ */
8
+ export interface PaymentMetrics {
9
+ operation: string;
10
+ userId?: string;
11
+ amount?: number;
12
+ currency?: string;
13
+ status: 'success' | 'failed' | 'pending';
14
+ timestamp: string;
15
+ metadata?: Record<string, any>;
16
+ }
17
+ /**
18
+ * Alert threshold configuration
19
+ *
20
+ * @version 0.0.1
21
+ * @since 0.0.1
22
+ * @author AMBROISE PARK Consulting
23
+ */
24
+ export interface AlertThresholds {
25
+ paymentFailureRate: number;
26
+ paymentVolumeThreshold: number;
27
+ errorRateThreshold: number;
28
+ }
29
+ /**
30
+ * Record payment metrics for monitoring
31
+ *
32
+ * @version 0.0.1
33
+ * @since 0.0.1
34
+ * @author AMBROISE PARK Consulting
35
+ */
36
+ export declare function recordPaymentMetrics(metrics: PaymentMetrics): Promise<void>;
37
+ /**
38
+ * Check payment failure rate and trigger alerts if needed
39
+ *
40
+ * @version 0.0.1
41
+ * @since 0.0.1
42
+ * @author AMBROISE PARK Consulting
43
+ */
44
+ export declare function checkPaymentFailureRate(timeWindowHours?: number): Promise<{
45
+ failureRate: number;
46
+ shouldAlert: boolean;
47
+ }>;
48
+ /**
49
+ * Check daily payment volume and trigger alerts if needed
50
+ *
51
+ * @version 0.0.1
52
+ * @since 0.0.1
53
+ * @author AMBROISE PARK Consulting
54
+ */
55
+ export declare function checkPaymentVolume(volumeThreshold?: number): Promise<{
56
+ totalVolume: number;
57
+ shouldAlert: boolean;
58
+ }>;
59
+ /**
60
+ * Get payment metrics summary for a time period
61
+ *
62
+ * @version 0.0.1
63
+ * @since 0.0.1
64
+ * @author AMBROISE PARK Consulting
65
+ */
66
+ export declare function getPaymentMetricsSummary(startDate: Date, endDate: Date): Promise<{
67
+ totalPayments: number;
68
+ successfulPayments: number;
69
+ failedPayments: number;
70
+ totalVolume: number;
71
+ averageAmount: number;
72
+ }>;
73
+ /**
74
+ * Clean up old metrics and alerts (call periodically)
75
+ *
76
+ * @version 0.0.1
77
+ * @since 0.0.1
78
+ * @author AMBROISE PARK Consulting
79
+ */
80
+ export declare function cleanupOldMetrics(metricsRetentionDays?: number, alertsRetentionDays?: number): Promise<void>;
@@ -0,0 +1,82 @@
1
+ import type { ServerRateLimitConfig as RateLimitConfig, ServerRateLimitResult as RateLimitResult } from '@donotdev/core';
2
+ export type { RateLimitConfig, RateLimitResult };
3
+ /**
4
+ * Check rate limit for a given key using in-memory storage
5
+ * For production, this should be replaced with Redis or Firestore
6
+ *
7
+ * @version 0.0.1
8
+ * @since 0.0.1
9
+ * @author AMBROISE PARK Consulting
10
+ */
11
+ export declare function checkRateLimit(key: string, config: RateLimitConfig): Promise<RateLimitResult>;
12
+ /**
13
+ * Check rate limit using Firestore for persistent storage.
14
+ * This is the recommended approach for production.
15
+ *
16
+ * **Architecture decision — Firestore transaction for rate limiting:**
17
+ * The read-modify-write cycle is wrapped in a Firestore transaction to
18
+ * eliminate TOCTOU races. While transactions add some latency, rate limiting
19
+ * is a best-effort abuse-prevention mechanism, not a hard security boundary.
20
+ * The window-based approach (maxAttempts per windowMs) tolerates minor
21
+ * timing variations. If transaction contention becomes an issue under extreme
22
+ * load, the catch block fails open (allows the request) to avoid blocking
23
+ * legitimate traffic — this is an intentional trade-off favoring availability
24
+ * over strict enforcement.
25
+ *
26
+ * For stricter rate limiting (e.g. payment endpoints), consumers can use
27
+ * Redis-backed rate limiters or API gateway-level throttling.
28
+ *
29
+ * @version 0.0.1
30
+ * @since 0.0.1
31
+ * @author AMBROISE PARK Consulting
32
+ */
33
+ export declare function checkRateLimitWithFirestore(key: string, config: RateLimitConfig): Promise<RateLimitResult>;
34
+ /**
35
+ * Reset rate limit for a given key
36
+ *
37
+ * @version 0.0.1
38
+ * @since 0.0.1
39
+ * @author AMBROISE PARK Consulting
40
+ */
41
+ export declare function resetRateLimit(key: string): void;
42
+ /**
43
+ * Reset rate limit in Firestore
44
+ *
45
+ * @version 0.0.1
46
+ * @since 0.0.1
47
+ * @author AMBROISE PARK Consulting
48
+ */
49
+ export declare function resetRateLimitInFirestore(key: string): Promise<void>;
50
+ /**
51
+ * Get rate limit status without consuming an attempt
52
+ *
53
+ * @version 0.0.1
54
+ * @since 0.0.1
55
+ * @author AMBROISE PARK Consulting
56
+ */
57
+ export declare function getRateLimitStatus(key: string, config: RateLimitConfig): RateLimitResult;
58
+ /**
59
+ * Default rate limit configurations for common operations
60
+ */
61
+ export declare const DEFAULT_RATE_LIMITS: {
62
+ readonly checkout: {
63
+ readonly maxAttempts: 5;
64
+ readonly windowMs: number;
65
+ readonly blockDurationMs: number;
66
+ };
67
+ readonly webhook: {
68
+ readonly maxAttempts: 100;
69
+ readonly windowMs: number;
70
+ readonly blockDurationMs: number;
71
+ };
72
+ readonly auth: {
73
+ readonly maxAttempts: 10;
74
+ readonly windowMs: number;
75
+ readonly blockDurationMs: number;
76
+ };
77
+ readonly api: {
78
+ readonly maxAttempts: 100;
79
+ readonly windowMs: number;
80
+ readonly blockDurationMs: number;
81
+ };
82
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Validates environment variables required for Stripe
3
+ *
4
+ * @version 0.0.1
5
+ * @since 0.0.1
6
+ * @author AMBROISE PARK Consulting
7
+ */
8
+ export declare function validateStripeEnvironment(): void;
9
+ /**
10
+ * Safely parses JSON with error handling
11
+ *
12
+ * @version 0.0.1
13
+ * @since 0.0.1
14
+ * @author AMBROISE PARK Consulting
15
+ */
16
+ export declare function safeJsonParse<T = any>(json: string): T | null;
17
+ /**
18
+ * Validates a Firestore collection name from client-supplied schema.
19
+ *
20
+ * W22: Vercel CRUD handlers accept `schema` (including collection name) from
21
+ * the client. This is a known design limitation. As a defense-in-depth measure,
22
+ * reject collection names that could be used for path traversal or access to
23
+ * internal collections.
24
+ *
25
+ * @param name - Collection name to validate
26
+ * @throws Error if the name is unsafe
27
+ *
28
+ * @version 0.0.1
29
+ * @since 0.0.1
30
+ * @author AMBROISE PARK Consulting
31
+ */
32
+ export declare function validateCollectionName(name: string): void;
33
+ /**
34
+ * Validates document data against an optional Valibot schema.
35
+ *
36
+ * W1: Previous stub ignored the schema parameter entirely. Now performs
37
+ * actual schema validation when a schema is provided.
38
+ *
39
+ * @version 0.0.2
40
+ * @since 0.0.1
41
+ * @author AMBROISE PARK Consulting
42
+ */
43
+ export declare function validateDocument(data: any, schema?: any): void;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @fileoverview DRY utilities for schema validation across all functions
3
+ * @description Provides reusable patterns for Firebase and Vercel functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import * as v from 'valibot';
10
+ import type { CallableRequest } from 'firebase-functions/v2/https';
11
+ import type { NextApiRequest, NextApiResponse } from 'next';
12
+ /**
13
+ * Validates request data using a schema with custom override support
14
+ *
15
+ * @version 0.0.1
16
+ * @since 0.0.1
17
+ * @author AMBROISE PARK Consulting
18
+ */
19
+ export declare function validateRequestData<T>(data: any, defaultSchema: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>, customSchema?: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>): {
20
+ success: true;
21
+ data: T;
22
+ } | {
23
+ success: false;
24
+ error: string;
25
+ };
26
+ /**
27
+ * Firebase function wrapper that adds schema validation
28
+ *
29
+ * @version 0.0.1
30
+ * @since 0.0.1
31
+ * @author AMBROISE PARK Consulting
32
+ */
33
+ export declare function withSchemaValidation<TRequest, TResponse>(defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (request: CallableRequest<TRequest>, validatedData: TRequest) => Promise<TResponse>): (request: CallableRequest<TRequest>, customSchema?: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>) => Promise<TResponse>;
34
+ /**
35
+ * Vercel function wrapper that adds schema validation
36
+ *
37
+ * @version 0.0.1
38
+ * @since 0.0.1
39
+ * @author AMBROISE PARK Consulting
40
+ */
41
+ export declare function withVercelSchemaValidation<TRequest, TResponse>(defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (req: NextApiRequest, res: NextApiResponse, validatedData: TRequest) => Promise<TResponse>): (req: NextApiRequest, res: NextApiResponse, customSchema?: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>) => Promise<TResponse>;
42
+ /**
43
+ * Creates both standard and custom schema versions of a Firebase function
44
+ *
45
+ * @version 0.0.1
46
+ * @since 0.0.1
47
+ * @author AMBROISE PARK Consulting
48
+ */
49
+ export declare function createFirebaseFunction<TRequest, TResponse>(defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (request: CallableRequest<TRequest>, validatedData: TRequest) => Promise<TResponse>): {
50
+ standard: (request: CallableRequest<TRequest>) => Promise<TResponse>;
51
+ withSchema: (request: CallableRequest<TRequest>, customSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>) => Promise<TResponse>;
52
+ };
53
+ /**
54
+ * Creates a Vercel function with schema validation
55
+ *
56
+ * @version 0.0.1
57
+ * @since 0.0.1
58
+ * @author AMBROISE PARK Consulting
59
+ */
60
+ export declare function createVercelFunction<TRequest, TResponse>(defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (req: NextApiRequest, res: NextApiResponse, validatedData: TRequest) => Promise<TResponse>): (req: NextApiRequest, res: NextApiResponse, customSchema?: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>> | undefined) => Promise<TResponse>;
@@ -0,0 +1,98 @@
1
+ import * as v from 'valibot';
2
+ /**
3
+ * Validation schemas for Stripe operations
4
+ */
5
+ export declare const StripeValidationSchemas: {
6
+ webhookEvent: v.ObjectSchema<{
7
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "Event ID is required">]>;
8
+ readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "Event type is required">]>;
9
+ readonly data: v.ObjectSchema<{
10
+ readonly object: v.AnySchema;
11
+ }, undefined>;
12
+ readonly created: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, "Valid timestamp required">]>;
13
+ }, undefined>;
14
+ purchaseRequest: v.ObjectSchema<{
15
+ readonly userId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "User ID is required">]>;
16
+ readonly productType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "Product type is required">]>;
17
+ readonly githubUsername: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "Invalid GitHub username">]>, undefined>;
18
+ readonly sessionId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "Session ID is required">]>;
19
+ readonly amount: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, "Amount must be positive">]>, undefined>;
20
+ readonly currency: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.LengthAction<string, 3, "Currency must be 3 characters">]>, undefined>;
21
+ }, undefined>;
22
+ };
23
+ /**
24
+ * Validation result interface
25
+ *
26
+ * @version 0.0.1
27
+ * @since 0.0.1
28
+ * @author AMBROISE PARK Consulting
29
+ */
30
+ export interface ValidationResult {
31
+ isValid: boolean;
32
+ errors: string[];
33
+ data?: any;
34
+ }
35
+ /**
36
+ * Validate webhook event
37
+ *
38
+ * @version 0.0.1
39
+ * @since 0.0.1
40
+ * @author AMBROISE PARK Consulting
41
+ */
42
+ export declare function validateWebhookEvent(data: any): ValidationResult;
43
+ /**
44
+ * Validate purchase request
45
+ *
46
+ * @version 0.0.1
47
+ * @since 0.0.1
48
+ * @author AMBROISE PARK Consulting
49
+ */
50
+ export declare function validatePurchaseRequest(data: any): ValidationResult;
51
+ /**
52
+ * Validate GitHub username format
53
+ *
54
+ * @version 0.0.1
55
+ * @since 0.0.1
56
+ * @author AMBROISE PARK Consulting
57
+ */
58
+ export declare function validateGitHubUsername(username: string): boolean;
59
+ /**
60
+ * Validate email format
61
+ *
62
+ * @version 0.0.1
63
+ * @since 0.0.1
64
+ * @author AMBROISE PARK Consulting
65
+ */
66
+ export declare function validateEmail(email: string): boolean;
67
+ /**
68
+ * Validate price ID format (Stripe price IDs start with 'price_')
69
+ *
70
+ * @version 0.0.1
71
+ * @since 0.0.1
72
+ * @author AMBROISE PARK Consulting
73
+ */
74
+ export declare function validateStripePriceId(priceId: string): boolean;
75
+ /**
76
+ * Validate session ID format (Stripe session IDs start with 'cs_')
77
+ *
78
+ * @version 0.0.1
79
+ * @since 0.0.1
80
+ * @author AMBROISE PARK Consulting
81
+ */
82
+ export declare function validateStripeSessionId(sessionId: string): boolean;
83
+ /**
84
+ * Validate URL format
85
+ *
86
+ * @version 0.0.1
87
+ * @since 0.0.1
88
+ * @author AMBROISE PARK Consulting
89
+ */
90
+ export declare function validateUrl(url: string, name?: string): string;
91
+ /**
92
+ * Validate and sanitize metadata object
93
+ *
94
+ * @version 0.0.1
95
+ * @since 0.0.1
96
+ * @author AMBROISE PARK Consulting
97
+ */
98
+ export declare function validateMetadata(metadata: Record<string, any>): Record<string, string>;
@@ -0,0 +1,18 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ import type * as v from 'valibot';
3
+ /**
4
+ * Creates a Vercel API handler with schema validation
5
+ *
6
+ * @version 0.0.1
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ export declare function createVercelHandler<TRequest, TResponse>(defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (req: NextApiRequest, res: NextApiResponse, validatedData: TRequest) => Promise<TResponse>): (req: NextApiRequest, res: NextApiResponse, customSchema?: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>> | undefined) => Promise<TResponse>;
11
+ /**
12
+ * Creates a Vercel API handler with method validation and schema validation
13
+ *
14
+ * @version 0.0.1
15
+ * @since 0.0.1
16
+ * @author AMBROISE PARK Consulting
17
+ */
18
+ export declare function createVercelApiHandler<TRequest, TResponse>(method: string, defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (req: NextApiRequest, res: NextApiResponse, validatedData: TRequest) => Promise<TResponse>): (req: NextApiRequest, res: NextApiResponse, customSchema?: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>) => Promise<TResponse>;
@@ -0,0 +1,234 @@
1
+ /**
2
+ * @fileoverview Shared utilities for Firebase and Vercel functions
3
+ * @description Common utilities that can be used by both Firebase and Vercel function implementations
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import Stripe from 'stripe';
10
+ import { DoNotDevError } from '@donotdev/core/server';
11
+ import type { UserRole } from '@donotdev/core/server';
12
+ export { DoNotDevError };
13
+ /**
14
+ * Get Firestore instance using @donotdev/firebase/server
15
+ * Provider handles initialization and caching
16
+ *
17
+ * @version 0.0.1
18
+ * @since 0.0.1
19
+ * @author AMBROISE PARK Consulting
20
+ */
21
+ export declare function getFirestore(): FirebaseFirestore.Firestore;
22
+ /**
23
+ * Get Auth instance using @donotdev/firebase/server
24
+ * Provider handles initialization and caching
25
+ *
26
+ * @version 0.0.1
27
+ * @since 0.0.1
28
+ * @author AMBROISE PARK Consulting
29
+ */
30
+ export declare function getAuth(): import("firebase-admin/auth").Auth;
31
+ /**
32
+ * Initialize Stripe explicitly (e.g. with a secret from defineSecret)
33
+ * @param apiKey - Stripe secret key
34
+ */
35
+ export declare function initStripe(apiKey: string): Stripe;
36
+ /**
37
+ * Get Stripe instance with lazy initialization
38
+ *
39
+ * @version 0.0.1
40
+ * @since 0.0.1
41
+ * @author AMBROISE PARK Consulting
42
+ */
43
+ export declare function getStripe(): Stripe;
44
+ /**
45
+ * Lazy-initialized Stripe instance proxy
46
+ *
47
+ * @version 0.0.1
48
+ * @since 0.0.1
49
+ * @author AMBROISE PARK Consulting
50
+ */
51
+ export declare const stripe: Stripe;
52
+ /**
53
+ * Assert that a user is authenticated from a Firebase callable auth context.
54
+ *
55
+ * @deprecated Import `assertAuthenticated` from `@donotdev/functions/shared/utils/internal/auth` instead.
56
+ * This wrapper extracts uid from a Firebase callable auth context and delegates
57
+ * to the canonical version.
58
+ *
59
+ * @param auth - Firebase callable request auth context (object with `.uid`)
60
+ * @returns The authenticated user's uid
61
+ *
62
+ * @version 0.0.3
63
+ * @since 0.0.1
64
+ * @author AMBROISE PARK Consulting
65
+ */
66
+ export declare function assertAuthenticated(auth: any): string;
67
+ /**
68
+ * Get user role from Firebase auth context
69
+ *
70
+ * Determines the user's role for visibility filtering based on:
71
+ * - auth.uid: If missing → 'guest'
72
+ * - auth.token.isSuper: If true → 'super'
73
+ * - auth.token.isAdmin: If true → 'admin'
74
+ * - Otherwise → 'user' (authenticated)
75
+ *
76
+ * @param auth - Firebase auth context from callable function
77
+ * @returns UserRole for visibility filtering
78
+ *
79
+ * @version 0.0.1
80
+ * @since 0.0.1
81
+ * @author AMBROISE PARK Consulting
82
+ */
83
+ export declare function getUserRole(auth: any): UserRole;
84
+ /**
85
+ * Validates that required Stripe environment variables are set
86
+ *
87
+ * @version 0.0.1
88
+ * @since 0.0.1
89
+ * @author AMBROISE PARK Consulting
90
+ */
91
+ export declare function validateStripeEnvironment(): void;
92
+ /**
93
+ * Creates a standardized success response
94
+ *
95
+ * @version 0.0.1
96
+ * @since 0.0.1
97
+ * @author AMBROISE PARK Consulting
98
+ */
99
+ export declare function createSuccessResponse<T>(data: T): {
100
+ success: true;
101
+ data: T;
102
+ };
103
+ /**
104
+ * Creates a standardized error response
105
+ *
106
+ * @version 0.0.1
107
+ * @since 0.0.1
108
+ * @author AMBROISE PARK Consulting
109
+ */
110
+ export declare function createErrorResponse(error: unknown): {
111
+ success: false;
112
+ error: {
113
+ code: string;
114
+ message: string;
115
+ details?: any;
116
+ };
117
+ };
118
+ /**
119
+ * Updates user subscription in Firebase.
120
+ *
121
+ * **Architecture decision — throwing stubs for billing functions:**
122
+ * These subscription functions (`updateUserSubscription`, `getUserSubscription`,
123
+ * `cancelUserSubscription`, `handleSubscriptionCancellation`) are intentional
124
+ * placeholder implementations. They exist so the framework compiles and
125
+ * type-checks out of the box, but throw at runtime to surface missing
126
+ * integration early. Consumer apps replace them with their billing provider
127
+ * integration (Stripe, Paddle, LemonSqueezy, etc.) via the documented
128
+ * `shared/billing/helpers/` modules.
129
+ *
130
+ * C10: This was a silent no-op stub. It now throws to surface the missing
131
+ * implementation at startup rather than silently dropping webhook events.
132
+ * Use `updateUserSubscription` from `shared/billing/helpers/updateUserSubscription.ts`
133
+ * (which requires an authProvider) instead.
134
+ *
135
+ * @deprecated Import `updateUserSubscription` from `@donotdev/functions/shared/billing/helpers/updateUserSubscription`.
136
+ * @version 0.0.2
137
+ * @since 0.0.1
138
+ * @author AMBROISE PARK Consulting
139
+ */
140
+ export declare function updateUserSubscription(_firebaseUid: string, _subscription: any): Promise<void>;
141
+ /**
142
+ * Gets user subscription from Firebase.
143
+ *
144
+ * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
145
+ *
146
+ * @deprecated Import from `@donotdev/functions/shared/billing/helpers` or implement directly using Firebase Admin SDK / Stripe API.
147
+ * @version 0.0.2
148
+ * @since 0.0.1
149
+ * @author AMBROISE PARK Consulting
150
+ */
151
+ export declare function getUserSubscription(_firebaseUid: string): Promise<any>;
152
+ /**
153
+ * Cancels user subscription.
154
+ *
155
+ * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
156
+ *
157
+ * @deprecated Import `cancelUserSubscription` from `@donotdev/functions/shared/billing/helpers/subscriptionManagement`.
158
+ * @version 0.0.2
159
+ * @since 0.0.1
160
+ * @author AMBROISE PARK Consulting
161
+ */
162
+ export declare function cancelUserSubscription(_firebaseUid: string, _subscription: any): Promise<void>;
163
+ /**
164
+ * Handles subscription cancellation.
165
+ *
166
+ * C10: This was a silent no-op stub. Now throws to surface the missing implementation.
167
+ *
168
+ * @deprecated Handle via Stripe webhook events. Use `processWebhook` from `@donotdev/functions/shared/billing/webhookHandler`.
169
+ * @version 0.0.2
170
+ * @since 0.0.1
171
+ * @author AMBROISE PARK Consulting
172
+ */
173
+ export declare function handleSubscriptionCancellation(_firebaseUid: string, _subscription: any): Promise<void>;
174
+ /**
175
+ * Asserts that a user has admin privileges
176
+ * Uses role hierarchy: super > admin > user > guest
177
+ *
178
+ * @deprecated Import `assertAdmin` from `@donotdev/functions/shared/utils/internal/auth` instead.
179
+ * This is a thin wrapper that delegates to the canonical provider-agnostic version.
180
+ *
181
+ * @version 0.0.3
182
+ * @since 0.0.1
183
+ * @author AMBROISE PARK Consulting
184
+ */
185
+ export declare function assertAdmin(uid: string): Promise<string>;
186
+ /**
187
+ * Validates document data
188
+ *
189
+ * @version 0.0.1
190
+ * @since 0.0.1
191
+ * @author AMBROISE PARK Consulting
192
+ */
193
+ export declare function validateDocument(data: any, schema?: any): void;
194
+ /**
195
+ * Validates a Firestore collection name from client-supplied schema.
196
+ *
197
+ * W22: Vercel CRUD handlers accept `schema` (including collection name) from
198
+ * the client. This is a known design limitation. As a defense-in-depth measure,
199
+ * reject collection names that could be used for path traversal or access to
200
+ * internal collections.
201
+ *
202
+ * @param name - Collection name to validate
203
+ * @throws Error if the name is unsafe
204
+ *
205
+ * @version 0.0.1
206
+ * @since 0.0.1
207
+ * @author AMBROISE PARK Consulting
208
+ */
209
+ export declare function validateCollectionName(name: string): void;
210
+ /**
211
+ * Verifies Firebase auth token
212
+ *
213
+ * @version 0.0.1
214
+ * @since 0.0.1
215
+ * @author AMBROISE PARK Consulting
216
+ */
217
+ export declare function verifyFirebaseAuthToken(token: string): Promise<string>;
218
+ /**
219
+ * Finds references to a document
220
+ *
221
+ * @version 0.0.1
222
+ * @since 0.0.1
223
+ * @author AMBROISE PARK Consulting
224
+ */
225
+ export declare function findReferences(collection: string, docId: string, referenceMetadata?: {
226
+ incoming?: Array<{
227
+ sourceCollection: string;
228
+ sourceField: string;
229
+ }>;
230
+ }): Promise<Array<{
231
+ collection: string;
232
+ field: string;
233
+ count: number;
234
+ }>>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview Environment validation utilities
3
+ * @description Validate required environment variables on module load
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ /**
10
+ * Validates required environment variables
11
+ *
12
+ * @version 0.0.1
13
+ * @since 0.0.1
14
+ * @author AMBROISE PARK Consulting
15
+ */
16
+ export declare function validateEnvironment(): void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Create a Supabase Edge Function handler for account deletion.
3
+ *
4
+ * @returns `(req: Request) => Promise<Response>` handler
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // supabase/functions/delete-account/index.ts
9
+ * import { createDeleteAccount } from '@donotdev/functions/supabase';
10
+ * Deno.serve(createDeleteAccount());
11
+ * ```
12
+ *
13
+ * @version 0.0.1
14
+ * @since 0.5.0
15
+ */
16
+ export declare function createDeleteAccount(): (req: Request) => Promise<Response>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Create a Supabase Edge Function handler for retrieving custom claims (app_metadata).
3
+ *
4
+ * @returns `(req: Request) => Promise<Response>` handler
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // supabase/functions/get-custom-claims/index.ts
9
+ * import { createGetCustomClaims } from '@donotdev/functions/supabase';
10
+ * Deno.serve(createGetCustomClaims());
11
+ * ```
12
+ *
13
+ * @version 0.0.1
14
+ * @since 0.6.0
15
+ */
16
+ export declare function createGetCustomClaims(): (req: Request) => Promise<Response>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Create a Supabase Edge Function handler for retrieving user auth status.
3
+ *
4
+ * Returns uid, email, verification status, custom claims, and ban status.
5
+ *
6
+ * @returns `(req: Request) => Promise<Response>` handler
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // supabase/functions/get-user-auth-status/index.ts
11
+ * import { createGetUserAuthStatus } from '@donotdev/functions/supabase';
12
+ * Deno.serve(createGetUserAuthStatus());
13
+ * ```
14
+ *
15
+ * @version 0.0.1
16
+ * @since 0.6.0
17
+ */
18
+ export declare function createGetUserAuthStatus(): (req: Request) => Promise<Response>;