@donotdev/functions 0.0.19 → 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,24 @@
1
+ import type { Entity } from '@donotdev/core/server';
2
+ type SupabaseHandler = (req: Request) => Promise<Response>;
3
+ interface CrudHandlers {
4
+ handlers: Record<string, SupabaseHandler>;
5
+ serve: (req: Request) => Promise<Response>;
6
+ }
7
+ /**
8
+ * Create CRUD handlers for all entities (Supabase Edge Functions)
9
+ * Returns handlers object + serve dispatcher function
10
+ *
11
+ * @param entities - Object of { key: Entity } (from `import * as entities from 'entities'`)
12
+ * @returns Object with handlers and serve dispatcher
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import * as entities from '../_shared/entities.ts';
17
+ * import { createSupabaseCrudFunctions } from '@donotdev/functions/supabase';
18
+ *
19
+ * const { serve } = createSupabaseCrudFunctions(entities);
20
+ * Deno.serve(serve);
21
+ * ```
22
+ */
23
+ export declare function createSupabaseCrudFunctions(entities: Record<string, Entity | unknown>): CrudHandlers;
24
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @fileoverview Idempotency utilities for Supabase Edge Functions
3
+ * @description Provides idempotency checking and storage using Postgres table
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.5.0
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import type { SupabaseClient } from '@supabase/supabase-js';
10
+ /**
11
+ * Check if an operation has already been processed (idempotency check)
12
+ *
13
+ * @param supabaseAdmin - Supabase admin client
14
+ * @param idempotencyKey - Client-provided idempotency key
15
+ * @param operation - Operation name (e.g., 'create', 'update')
16
+ * @returns Cached result if found, null otherwise
17
+ */
18
+ export declare function checkIdempotency<T>(supabaseAdmin: SupabaseClient, idempotencyKey: string, operation: string): Promise<T | null>;
19
+ /**
20
+ * Store the result of an operation for idempotency
21
+ *
22
+ * @param supabaseAdmin - Supabase admin client
23
+ * @param idempotencyKey - Client-provided idempotency key
24
+ * @param operation - Operation name (e.g., 'create', 'update')
25
+ * @param result - Operation result to cache
26
+ * @param uid - User ID who processed the operation
27
+ * @param ttlHours - Optional TTL override (defaults to operation-specific TTL)
28
+ */
29
+ export declare function storeIdempotency<T>(supabaseAdmin: SupabaseClient, idempotencyKey: string, operation: string, result: T, uid: string, ttlHours?: number): Promise<void>;
30
+ /**
31
+ * Clean up expired idempotency records
32
+ *
33
+ * @param supabaseAdmin - Supabase admin client
34
+ * @returns Number of deleted records
35
+ */
36
+ export declare function cleanupExpiredIdempotency(supabaseAdmin: SupabaseClient): Promise<number>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @fileoverview Monitoring and metrics utilities for Supabase Edge Functions
3
+ * @description Provides metrics collection and analytics queries using Postgres table
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.5.0
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import type { SupabaseClient } from '@supabase/supabase-js';
10
+ /**
11
+ * Operation metrics data structure
12
+ */
13
+ export interface OperationMetrics {
14
+ operation: string;
15
+ userId?: string;
16
+ status: 'success' | 'failed' | 'pending';
17
+ durationMs?: number;
18
+ metadata?: Record<string, any>;
19
+ errorCode?: string;
20
+ errorMessage?: string;
21
+ }
22
+ /**
23
+ * Record operation metrics for monitoring
24
+ *
25
+ * @param supabaseAdmin - Supabase admin client
26
+ * @param metrics - Operation metrics to record
27
+ */
28
+ export declare function recordOperationMetrics(supabaseAdmin: SupabaseClient, metrics: OperationMetrics): Promise<void>;
29
+ /**
30
+ * Get failure rate for an operation
31
+ *
32
+ * @param supabaseAdmin - Supabase admin client
33
+ * @param operation - Operation name
34
+ * @param hours - Time window in hours (default: 24)
35
+ * @returns Failure rate (0-100)
36
+ */
37
+ export declare function getFailureRate(supabaseAdmin: SupabaseClient, operation: string, hours?: number): Promise<number>;
38
+ /**
39
+ * Get operation counts by user
40
+ *
41
+ * @param supabaseAdmin - Supabase admin client
42
+ * @param userId - User ID
43
+ * @param hours - Time window in hours (default: 24)
44
+ * @returns Record of operation names to counts
45
+ */
46
+ export declare function getOperationCounts(supabaseAdmin: SupabaseClient, userId: string, hours?: number): Promise<Record<string, number>>;
47
+ /**
48
+ * Get slow operations (above threshold)
49
+ *
50
+ * @param supabaseAdmin - Supabase admin client
51
+ * @param thresholdMs - Duration threshold in milliseconds
52
+ * @param hours - Time window in hours (default: 24)
53
+ * @returns Array of operations with average duration
54
+ */
55
+ export declare function getSlowOperations(supabaseAdmin: SupabaseClient, thresholdMs: number, hours?: number): Promise<Array<{
56
+ operation: string;
57
+ avgDuration: number;
58
+ count: number;
59
+ }>>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @fileoverview Rate limiting utilities for Supabase Edge Functions
3
+ * @description Postgres-based rate limiting via an atomic PostgreSQL function (RPC).
4
+ *
5
+ * **Why RPC?**
6
+ * The previous SELECT → UPDATE pattern had a TOCTOU race condition: two concurrent
7
+ * requests could both read `attempts < maxAttempts`, both increment, and both be allowed —
8
+ * effectively bypassing the rate limit under load. The PostgreSQL function executes as a
9
+ * single atomic transaction, eliminating the race.
10
+ *
11
+ * **Required migration:**
12
+ * Deploy `RATE_LIMIT_CHECK_SQL` to your Supabase project before using this function.
13
+ * Run: `supabase migration new rate_limit_check` then paste the SQL into the file.
14
+ *
15
+ * **Fail behaviour:**
16
+ * On RPC error or unexpected failure, this function FAILS CLOSED (blocks the request).
17
+ * A broken rate limiter must not silently allow unlimited access to protected resources.
18
+ *
19
+ * @version 0.0.2
20
+ * @since 0.5.0
21
+ * @author AMBROISE PARK Consulting
22
+ */
23
+ import type { ServerRateLimitConfig as RateLimitConfig, ServerRateLimitResult as RateLimitResult } from '@donotdev/core';
24
+ import type { SupabaseClient } from '@supabase/supabase-js';
25
+ export type { RateLimitConfig, RateLimitResult };
26
+ /**
27
+ * PostgreSQL function required for atomic rate limiting.
28
+ * Deploy this SQL to your Supabase project via a migration.
29
+ *
30
+ * The function uses `INSERT … ON CONFLICT DO UPDATE` which executes as a single
31
+ * atomic statement — no TOCTOU race between SELECT and UPDATE.
32
+ *
33
+ * @example
34
+ * ```bash
35
+ * supabase migration new rate_limit_check
36
+ * # Paste RATE_LIMIT_CHECK_SQL into the generated migration file
37
+ * supabase db push
38
+ * ```
39
+ */
40
+ export declare const RATE_LIMIT_CHECK_SQL = "\n-- Required table (create once if not already present)\nCREATE TABLE IF NOT EXISTS public.rate_limits (\n key TEXT PRIMARY KEY,\n attempts INT NOT NULL DEFAULT 0,\n window_start TIMESTAMPTZ NOT NULL DEFAULT now(),\n block_until TIMESTAMPTZ,\n last_updated TIMESTAMPTZ NOT NULL DEFAULT now()\n);\n\n-- Required atomic rate-limit function\nCREATE OR REPLACE FUNCTION public.rate_limit_check(\n p_key TEXT,\n p_max_attempts INT,\n p_window_ms BIGINT,\n p_block_duration_ms BIGINT\n)\nRETURNS jsonb\nLANGUAGE plpgsql\nSECURITY DEFINER\nAS $$\nDECLARE\n v_now TIMESTAMPTZ := clock_timestamp();\n v_window_interval INTERVAL := (p_window_ms || ' milliseconds')::INTERVAL;\n v_block_interval INTERVAL := (p_block_duration_ms || ' milliseconds')::INTERVAL;\n v_row public.rate_limits%ROWTYPE;\nBEGIN\n -- Single atomic upsert: INSERT on first call, conditional UPDATE thereafter.\n -- No separate SELECT \u2192 eliminates the TOCTOU race of the previous implementation.\n INSERT INTO public.rate_limits (key, attempts, window_start, block_until, last_updated)\n VALUES (p_key, 1, v_now, NULL, v_now)\n ON CONFLICT (key) DO UPDATE SET\n window_start = CASE\n WHEN rate_limits.window_start + v_window_interval <= v_now THEN v_now\n ELSE rate_limits.window_start\n END,\n attempts = CASE\n -- Currently blocked: do not increment (request will be rejected below)\n WHEN rate_limits.block_until IS NOT NULL AND v_now < rate_limits.block_until\n THEN rate_limits.attempts\n -- Window expired: reset counter\n WHEN rate_limits.window_start + v_window_interval <= v_now\n THEN 1\n -- Within window: increment\n ELSE rate_limits.attempts + 1\n END,\n block_until = CASE\n -- Preserve existing block\n WHEN rate_limits.block_until IS NOT NULL AND v_now < rate_limits.block_until\n THEN rate_limits.block_until\n -- Window just reset \u2014 no block\n WHEN rate_limits.window_start + v_window_interval <= v_now\n THEN NULL\n -- Threshold just exceeded \u2014 apply block\n WHEN rate_limits.attempts + 1 >= p_max_attempts\n THEN v_now + v_block_interval\n ELSE NULL\n END,\n last_updated = v_now\n RETURNING * INTO v_row;\n\n -- Blocked?\n IF v_row.block_until IS NOT NULL AND v_now < v_row.block_until THEN\n RETURN jsonb_build_object(\n 'allowed', false,\n 'remaining', 0,\n 'reset_at_epoch_ms', EXTRACT(EPOCH FROM v_row.block_until)::BIGINT * 1000,\n 'block_remaining_seconds', CEIL(EXTRACT(EPOCH FROM (v_row.block_until - v_now)))::INT\n );\n END IF;\n\n RETURN jsonb_build_object(\n 'allowed', true,\n 'remaining', GREATEST(0, p_max_attempts - v_row.attempts),\n 'reset_at_epoch_ms', EXTRACT(EPOCH FROM (v_row.window_start + v_window_interval))::BIGINT * 1000,\n 'block_remaining_seconds', NULL\n );\nEND;\n$$;\n";
41
+ /**
42
+ * Default rate limits (same as Firebase equivalent).
43
+ */
44
+ export declare const DEFAULT_RATE_LIMITS: Record<string, RateLimitConfig>;
45
+ /**
46
+ * Atomically check and increment a rate limit counter using the `rate_limit_check`
47
+ * PostgreSQL function. Requires the function to be deployed (see `RATE_LIMIT_CHECK_SQL`).
48
+ *
49
+ * **Fail behaviour:** FAILS CLOSED on any error — a broken rate limiter must not
50
+ * allow unlimited access. Log the error and alert your team; do not suppress it.
51
+ *
52
+ * @param supabaseAdmin - Supabase admin client (service role key — never expose to clients)
53
+ * @param key - Rate limit key, e.g. `"create_userId"` or `"api_ip"`
54
+ * @param config - Rate limit configuration
55
+ */
56
+ export declare function checkRateLimitWithPostgres(supabaseAdmin: SupabaseClient, key: string, config: RateLimitConfig): Promise<RateLimitResult>;
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Vercel API auth barrel exports
3
+ * @description Centralized exports for Vercel API authentication functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './get-custom-claims.js';
10
+ export * from './get-user-auth-status.js';
11
+ export * from './remove-custom-claims.js';
12
+ export * from './set-custom-claims.js';
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export interface SetCustomClaimsHandlerOptions {
3
+ /** Explicit allowlist of claim keys users may set on themselves. Required. */
4
+ allowedClaimKeys: string[];
5
+ }
6
+ /**
7
+ * Factory that returns a set-custom-claims handler scoped to allowed keys.
8
+ * Consumers MUST specify which claim keys are self-assignable.
9
+ */
10
+ export declare function createSetCustomClaimsHandler(options: SetCustomClaimsHandlerOptions): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ /**
3
+ * Cancel subscription function
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ declare const cancelSubscription: () => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
10
+ export default cancelSubscription;
@@ -0,0 +1,11 @@
1
+ import type { StripeBackConfig } from '@donotdev/core/server';
2
+ import type { NextApiRequest, NextApiResponse } from 'next';
3
+ /**
4
+ * Change subscription plan function
5
+ *
6
+ * @version 0.0.1
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ declare const changePlan: (billingConfig: StripeBackConfig) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
11
+ export default changePlan;
@@ -0,0 +1,13 @@
1
+ import type { StripeBackConfig } from '@donotdev/core/server';
2
+ import type { NextApiRequest, NextApiResponse } from 'next';
3
+ import type * as v from 'valibot';
4
+ /**
5
+ * Vercel API handler for creating checkout sessions
6
+ * Base function handles all common concerns automatically
7
+ *
8
+ * @version 0.0.1
9
+ * @since 0.0.1
10
+ * @author AMBROISE PARK Consulting
11
+ */
12
+ declare const createCheckoutSession: (billingConfig: StripeBackConfig, customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
13
+ export default createCheckoutSession;
@@ -0,0 +1,3 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ declare const createCustomerPortal: () => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
3
+ export default createCustomerPortal;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @fileoverview Vercel API billing barrel exports
3
+ * @description Centralized exports for Vercel API billing functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './create-checkout-session.js';
10
+ export * from './refresh-subscription-status.js';
11
+ export * from '../../../shared/billing/helpers/index.js';
12
+ export { default as cancelSubscription } from './cancel.js';
13
+ export { default as changePlan } from './change-plan.js';
14
+ export { default as createCustomerPortal } from './customer-portal.js';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @fileoverview Refresh subscription status API handler
3
+ * @description Vercel API route for refreshing user subscription status
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 { NextApiRequest, NextApiResponse } from 'next';
11
+ import type Stripe from 'stripe';
12
+ /**
13
+ * Vercel API handler for refreshing subscription status
14
+ * Base function handles all common concerns automatically
15
+ */
16
+ declare const refreshSubscriptionStatus: (customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>) => (req: NextApiRequest, res: NextApiResponse) => Promise<{
17
+ success: boolean;
18
+ subscription: null;
19
+ message: string;
20
+ } | {
21
+ success: boolean;
22
+ subscription: {
23
+ tier: string;
24
+ subscriptionId: string;
25
+ customerId: string | Stripe.Customer | Stripe.DeletedCustomer;
26
+ status: Stripe.Subscription.Status;
27
+ currentPeriodEnd: string;
28
+ };
29
+ message: string;
30
+ }>;
31
+ export default refreshSubscriptionStatus;
@@ -0,0 +1,22 @@
1
+ import type { StripeBackConfig } from '@donotdev/core/server';
2
+ import type { NextApiRequest, NextApiResponse } from 'next';
3
+ /**
4
+ * Create Vercel webhook handler from billing config
5
+ *
6
+ * @version 0.0.1
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ export declare function createStripeWebhook(billingConfig: StripeBackConfig): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
11
+ /**
12
+ * Next.js API route configuration
13
+ *
14
+ * @version 0.0.1
15
+ * @since 0.0.1
16
+ * @author AMBROISE PARK Consulting
17
+ */
18
+ export declare const config: {
19
+ api: {
20
+ bodyParser: boolean;
21
+ };
22
+ };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fileoverview Firebase Functions configuration constants
3
+ * @description DRY configuration for regions, timeouts, and other function settings
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ /**
10
+ * Firebase Functions regions
11
+ * Default to eu-west1 for European users (France)
12
+ * Override with FIREBASE_REGION environment variable
13
+ *
14
+ * @version 0.0.1
15
+ * @since 0.0.1
16
+ * @author AMBROISE PARK Consulting
17
+ */
18
+ export declare const FIREBASE_REGION: string;
19
+ /**
20
+ * Common function configuration options
21
+ *
22
+ * @version 0.0.1
23
+ * @since 0.0.1
24
+ * @author AMBROISE PARK Consulting
25
+ */
26
+ export declare const FUNCTION_CONFIG: {
27
+ readonly region: string;
28
+ readonly memory: "1GiB";
29
+ readonly timeoutSeconds: 60;
30
+ };
31
+ /**
32
+ * Stripe-specific configuration
33
+ *
34
+ * @version 0.0.1
35
+ * @since 0.0.1
36
+ * @author AMBROISE PARK Consulting
37
+ */
38
+ export declare const STRIPE_CONFIG: {
39
+ readonly region: string;
40
+ readonly memory: "512MiB";
41
+ readonly timeoutSeconds: 30;
42
+ };
43
+ /**
44
+ * Auth-specific configuration
45
+ *
46
+ * @version 0.0.1
47
+ * @since 0.0.1
48
+ * @author AMBROISE PARK Consulting
49
+ */
50
+ export declare const AUTH_CONFIG: {
51
+ readonly region: string;
52
+ readonly memory: "256MiB";
53
+ readonly timeoutSeconds: 20;
54
+ };
55
+ /**
56
+ * Generic CRUD configuration
57
+ *
58
+ * @version 0.0.1
59
+ * @since 0.0.1
60
+ * @author AMBROISE PARK Consulting
61
+ */
62
+ export declare const CRUD_CONFIG: {
63
+ readonly region: string;
64
+ readonly memory: "256MiB";
65
+ readonly timeoutSeconds: 15;
66
+ };
67
+ /**
68
+ * Available Firebase regions for reference
69
+ *
70
+ * @version 0.0.1
71
+ * @since 0.0.1
72
+ * @author AMBROISE PARK Consulting
73
+ */
74
+ export declare const AVAILABLE_REGIONS: {
75
+ readonly 'europe-west1': "Belgium";
76
+ readonly 'europe-west2': "London";
77
+ readonly 'europe-west3': "Frankfurt";
78
+ readonly 'europe-west6': "Zurich";
79
+ readonly 'europe-central2': "Warsaw";
80
+ readonly 'us-central1': "Iowa";
81
+ readonly 'us-east1': "South Carolina";
82
+ readonly 'us-east4': "Northern Virginia";
83
+ readonly 'us-west1': "Oregon";
84
+ readonly 'asia-east1': "Taiwan";
85
+ readonly 'asia-northeast1': "Tokyo";
86
+ readonly 'asia-southeast1': "Singapore";
87
+ };
88
+ /**
89
+ * Environment validation
90
+ *
91
+ * @version 0.0.1
92
+ * @since 0.0.1
93
+ * @author AMBROISE PARK Consulting
94
+ */
95
+ export declare const validateEnvironment: () => void;
96
+ /**
97
+ * Type for Firebase region keys
98
+ *
99
+ * @version 0.0.1
100
+ * @since 0.0.1
101
+ * @author AMBROISE PARK Consulting
102
+ */
103
+ export type FirebaseRegion = keyof typeof AVAILABLE_REGIONS;
@@ -0,0 +1,19 @@
1
+ import type { App } from 'firebase-admin/app';
2
+ /**
3
+ * Initialize Firebase Admin SDK for Vercel environment
4
+ * Uses provider which handles service account credentials from environment variables
5
+ *
6
+ * @version 0.0.1
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ export declare function initializeFirebaseAdmin(): Promise<App>;
11
+ /**
12
+ * Get the initialized Firebase Admin app
13
+ * Initializes if not already done
14
+ *
15
+ * @version 0.0.1
16
+ * @since 0.0.1
17
+ * @author AMBROISE PARK Consulting
18
+ */
19
+ export declare function getFirebaseAdmin(): Promise<App>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @fileoverview Vercel API config barrel exports
3
+ * @description Centralized exports for Vercel API configuration functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './constants.js';
10
+ export * from './firebase-admin.js';
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @fileoverview Vercel API CRUD barrel exports
3
+ * @description Centralized exports for Vercel API CRUD functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './create.js';
10
+ export * from './delete.js';
11
+ export * from './get.js';
12
+ export * from './list.js';
13
+ export * from './update.js';
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { NextApiRequest, NextApiResponse } from 'next';
2
+ export default function handler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @fileoverview Vercel API barrel exports
3
+ * @description Centralized exports for Vercel API functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './auth/index.js';
10
+ export * from './billing/index.js';
11
+ export * from './config/index.js';
12
+ export * from './crud/index.js';
13
+ export * from './oauth/index.js';