@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,12 @@
1
+ import type { OAuthPartnerId, OAuthPurpose } from '@donotdev/core/server';
2
+ /**
3
+ * Disconnect a provider
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export declare const disconnect: import("firebase-functions/https").CallableFunction<{
10
+ provider: OAuthPartnerId;
11
+ purpose: OAuthPurpose;
12
+ }, any, unknown>;
@@ -0,0 +1,9 @@
1
+ import { type ExchangeTokenRequest } from '@donotdev/core/server';
2
+ /**
3
+ * Exchange OAuth authorization code for access token
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export declare const exchangeToken: import("firebase-functions/https").CallableFunction<ExchangeTokenRequest, any, unknown>;
@@ -0,0 +1,11 @@
1
+ import type { OAuthPurpose } from '@donotdev/core/server';
2
+ /**
3
+ * Get a user's OAuth connections
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export declare const getConnections: import("firebase-functions/https").CallableFunction<{
10
+ purpose?: OAuthPurpose;
11
+ }, any, unknown>;
@@ -0,0 +1,83 @@
1
+ import * as v from 'valibot';
2
+ import { type GrantGitHubAccessRequest, type RevokeGitHubAccessRequest, type CheckGitHubAccessRequest } from '@donotdev/core/server';
3
+ import type { CallableRequest } from 'firebase-functions/v2/https';
4
+ import type { CallableFunction } from 'firebase-functions/v2/https';
5
+ /**
6
+ * Grant GitHub repository access to a user
7
+ *
8
+ * @version 0.0.1
9
+ * @since 0.0.1
10
+ * @author AMBROISE PARK Consulting
11
+ */
12
+ export declare const grantGitHubAccess: CallableFunction<GrantGitHubAccessRequest, Promise<any>>;
13
+ /**
14
+ * Grant GitHub repository access with custom validation schema
15
+ *
16
+ * @version 0.0.1
17
+ * @since 0.0.1
18
+ * @author AMBROISE PARK Consulting
19
+ */
20
+ export declare function grantGitHubAccessWithSchema(request: CallableRequest<GrantGitHubAccessRequest>, customSchema: v.BaseSchema<unknown, GrantGitHubAccessRequest, v.BaseIssue<unknown>>): Promise<{
21
+ success: boolean;
22
+ userId: string;
23
+ githubUsername: string;
24
+ repoConfig: {
25
+ owner: string;
26
+ repo: string;
27
+ };
28
+ permission: string;
29
+ message: string;
30
+ }>;
31
+ /**
32
+ * Revoke GitHub repository access from a user
33
+ *
34
+ * @version 0.0.1
35
+ * @since 0.0.1
36
+ * @author AMBROISE PARK Consulting
37
+ */
38
+ export declare const revokeGitHubAccess: CallableFunction<RevokeGitHubAccessRequest, Promise<any>>;
39
+ /**
40
+ * Revoke GitHub repository access with custom validation schema
41
+ *
42
+ * @version 0.0.1
43
+ * @since 0.0.1
44
+ * @author AMBROISE PARK Consulting
45
+ */
46
+ export declare function revokeGitHubAccessWithSchema(request: CallableRequest<RevokeGitHubAccessRequest>, customSchema: v.BaseSchema<unknown, RevokeGitHubAccessRequest, v.BaseIssue<unknown>>): Promise<{
47
+ success: boolean;
48
+ userId: string;
49
+ githubUsername: string;
50
+ repoConfig: {
51
+ owner: string;
52
+ repo: string;
53
+ };
54
+ message: string;
55
+ }>;
56
+ /**
57
+ * Check GitHub repository access for a user
58
+ *
59
+ * @version 0.0.1
60
+ * @since 0.0.1
61
+ * @author AMBROISE PARK Consulting
62
+ */
63
+ export declare const checkGitHubAccess: CallableFunction<CheckGitHubAccessRequest, Promise<any>>;
64
+ /**
65
+ * Check GitHub repository access with custom validation schema
66
+ *
67
+ * @version 0.0.1
68
+ * @since 0.0.1
69
+ * @author AMBROISE PARK Consulting
70
+ */
71
+ export declare function checkGitHubAccessWithSchema(request: CallableRequest<CheckGitHubAccessRequest>, customSchema: v.BaseSchema<unknown, CheckGitHubAccessRequest, v.BaseIssue<unknown>>): Promise<{
72
+ success: boolean;
73
+ userId: string;
74
+ githubUsername: string;
75
+ repoConfig: {
76
+ owner: string;
77
+ repo: string;
78
+ };
79
+ hasAccess: boolean;
80
+ customClaimsAccess: boolean;
81
+ accessDetails: any;
82
+ message: string;
83
+ }>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @fileoverview Firebase OAuth functions barrel exports
3
+ * @description Centralized exports for Firebase OAuth functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './disconnect.js';
10
+ export * from './exchangeToken.js';
11
+ export * from './getConnections.js';
12
+ export * from './githubAccess.js';
13
+ export * from './refreshToken.js';
@@ -0,0 +1,9 @@
1
+ import { type OAuthRefreshRequest } from '@donotdev/core/server';
2
+ /**
3
+ * Refresh an OAuth token
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export declare const refreshToken: import("firebase-functions/https").CallableFunction<OAuthRefreshRequest, any, unknown>;
@@ -0,0 +1,32 @@
1
+ import type { Entity } from '@donotdev/core/server';
2
+ import type { HttpsFunction } from 'firebase-functions/v2/https';
3
+ interface RegisterOptions {
4
+ prefix?: string;
5
+ }
6
+ /** CRUD functions object returned by createCrudFunctions */
7
+ export type CrudFunctions = Record<string, HttpsFunction>;
8
+ /**
9
+ * Create CRUD functions for all entities (ESM-friendly)
10
+ * Returns an object of functions that can be spread/exported
11
+ *
12
+ * @param entities - Object of { key: Entity } (from `import * as entities from 'entities'`)
13
+ * @param options - Optional configuration
14
+ * @returns Object of CRUD functions keyed by name
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // ESM pattern - use with build-time export generation
19
+ * import * as entities from 'entities';
20
+ * import { createCrudFunctions } from '@donotdev/functions/firebase';
21
+ *
22
+ * export const crud = createCrudFunctions(entities);
23
+ * // Build process generates: export const { create_cars, ... } = crud;
24
+ * ```
25
+ */
26
+ export declare function createCrudFunctions(entities: Record<string, Entity | unknown>, options?: RegisterOptions): CrudFunctions;
27
+ /**
28
+ * @deprecated Use createCrudFunctions() for ESM. This mutates target which doesn't work in ESM.
29
+ * Auto-register CRUD functions for all entities (CJS pattern)
30
+ */
31
+ export declare function registerCrudFunctions(entities: Record<string, Entity | unknown>, target?: Record<string, any>, options?: RegisterOptions): CrudFunctions;
32
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Scheduled function that runs daily to check for expired subscriptions
3
+ * and update custom claims with expired status.
4
+ *
5
+ * **Architecture decision — opt-in scheduled function:**
6
+ * This function is not automatically deployed. Consumer apps opt in by
7
+ * exporting it from their functions entry point (e.g. `index.ts`). If not
8
+ * exported, Firebase never schedules it.
9
+ *
10
+ * The `users` collection path defaults to `'users'` but is configurable via
11
+ * the `USERS_COLLECTION_PATH` environment variable, allowing consumers to
12
+ * use their own collection structure (e.g. `'app_users'`, `'tenants/{id}/users'`).
13
+ */
14
+ export declare const checkExpiredSubscriptions: import("firebase-functions/scheduler").ScheduleFunction;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @fileoverview Firebase scheduled functions barrel exports
3
+ * @description Centralized exports for Firebase scheduled functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './checkExpiredSubscriptions.js';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @fileoverview Create Checkout Session Algorithm
3
+ * @description Platform-agnostic algorithm for creating Stripe checkout sessions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import type { CreateCheckoutSessionRequest, CreateCheckoutSessionResponse, StripeBackConfig } from '@donotdev/core/server';
10
+ /**
11
+ * Provider interface for Stripe checkout operations
12
+ *
13
+ * @version 0.0.1
14
+ * @since 0.0.1
15
+ * @author AMBROISE PARK Consulting
16
+ */
17
+ export interface StripeCheckoutProvider {
18
+ createCheckoutSession(params: {
19
+ priceId: string;
20
+ customerEmail?: string;
21
+ metadata: Record<string, string>;
22
+ allowPromotionCodes: boolean;
23
+ successUrl: string;
24
+ cancelUrl: string;
25
+ mode?: 'payment' | 'subscription';
26
+ }): Promise<{
27
+ id: string;
28
+ url: string | null;
29
+ }>;
30
+ }
31
+ /**
32
+ * Provider interface for authentication operations
33
+ *
34
+ * @version 0.0.1
35
+ * @since 0.0.1
36
+ * @author AMBROISE PARK Consulting
37
+ */
38
+ export interface AuthCheckoutProvider {
39
+ getUser(userId: string): Promise<{
40
+ customClaims?: Record<string, any>;
41
+ }>;
42
+ }
43
+ /**
44
+ * Create checkout session algorithm
45
+ *
46
+ * @version 0.0.1
47
+ * @since 0.0.1
48
+ * @author AMBROISE PARK Consulting
49
+ */
50
+ export declare function createCheckoutAlgorithm(request: CreateCheckoutSessionRequest, stripeProvider: StripeCheckoutProvider, authProvider: AuthCheckoutProvider, billingConfig: StripeBackConfig): Promise<CreateCheckoutSessionResponse>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @fileoverview Billing helpers barrel exports
3
+ * @description Centralized exports for billing helper functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export { updateUserSubscription } from './updateUserSubscription.js';
10
+ export type { SubscriptionData } from './updateUserSubscription.js';
@@ -0,0 +1,34 @@
1
+ import { type AuthProvider } from './updateUserSubscription.js';
2
+ /**
3
+ * Cancel user subscription at period end
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export declare function cancelUserSubscription(userId: string, authProvider: AuthProvider): Promise<{
10
+ success: boolean;
11
+ endsAt: string;
12
+ }>;
13
+ /**
14
+ * Change user subscription plan
15
+ *
16
+ * @version 0.0.1
17
+ * @since 0.0.1
18
+ * @author AMBROISE PARK Consulting
19
+ */
20
+ export declare function changeUserPlan(userId: string, newPriceId: string, billingConfigKey: string, billingConfig: Record<string, any>, authProvider: AuthProvider): Promise<{
21
+ success: boolean;
22
+ newTier: string;
23
+ newPrice: number;
24
+ }>;
25
+ /**
26
+ * Create Stripe Customer Portal session
27
+ *
28
+ * @version 0.0.1
29
+ * @since 0.0.1
30
+ * @author AMBROISE PARK Consulting
31
+ */
32
+ export declare function createCustomerPortalSession(userId: string, authProvider: AuthProvider, returnUrl?: string): Promise<{
33
+ url: string;
34
+ }>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @fileoverview User subscription update utilities
3
+ * @description Functions for updating user subscription data
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ /**
10
+ * Subscription data structure
11
+ *
12
+ * @version 0.0.1
13
+ * @since 0.0.1
14
+ * @author AMBROISE PARK Consulting
15
+ */
16
+ export interface SubscriptionData {
17
+ tier: string;
18
+ status: 'active' | 'canceled' | 'past_due' | 'trialing' | 'incomplete';
19
+ subscriptionEnd: string | null;
20
+ cancelAtPeriodEnd?: boolean;
21
+ subscriptionId?: string | null;
22
+ customerId?: string;
23
+ }
24
+ /**
25
+ * Platform-agnostic auth provider interface
26
+ *
27
+ * @version 0.0.1
28
+ * @since 0.0.1
29
+ * @author AMBROISE PARK Consulting
30
+ */
31
+ export interface AuthProvider {
32
+ getUser(userId: string): Promise<{
33
+ customClaims?: Record<string, unknown>;
34
+ }>;
35
+ setCustomUserClaims(userId: string, claims: Record<string, unknown>): Promise<void>;
36
+ }
37
+ /**
38
+ * Platform-agnostic subscription update using dependency injection
39
+ * Works on Firebase Functions, Vercel, AWS Lambda, etc.
40
+ *
41
+ * @version 0.0.1
42
+ * @since 0.0.1
43
+ * @author AMBROISE PARK Consulting
44
+ */
45
+ export declare function updateUserSubscription(userId: string, subscriptionData: SubscriptionData, authProvider: AuthProvider): Promise<void>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Idempotency store interface
3
+ *
4
+ * @version 0.0.1
5
+ * @since 0.0.1
6
+ * @author AMBROISE PARK Consulting
7
+ */
8
+ export interface IdempotencyStore {
9
+ isProcessed(eventId: string): Promise<boolean>;
10
+ markProcessed(eventId: string): Promise<void>;
11
+ /** Atomic check-and-reserve: returns true if already processed, false if reserved for processing */
12
+ checkAndReserve(eventId: string): Promise<boolean>;
13
+ }
14
+ export declare function createIdempotencyStore(): IdempotencyStore;
15
+ /**
16
+ * Reset cached store (for testing only)
17
+ *
18
+ * @version 0.0.1
19
+ * @since 0.0.1
20
+ * @author AMBROISE PARK Consulting
21
+ */
22
+ export declare function resetIdempotencyStore(): void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @fileoverview Billing utilities barrel exports
3
+ * @description Centralized exports for billing-related functions
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './createCheckout.js';
10
+ export * from './helpers/index.js';
11
+ export * from './webhookHandler.js';
@@ -0,0 +1,37 @@
1
+ import type { SubscriptionData, AuthProvider } from './helpers/updateUserSubscription.js';
2
+ import type Stripe from 'stripe';
3
+ /**
4
+ * Platform-agnostic auth provider interface for webhook handlers
5
+ */
6
+ export interface WebhookAuthProvider {
7
+ getUser(userId: string): Promise<{
8
+ customClaims?: Record<string, unknown>;
9
+ }>;
10
+ setCustomUserClaims(userId: string, claims: Record<string, unknown>): Promise<void>;
11
+ }
12
+ /**
13
+ * Subscription update function type
14
+ */
15
+ export type UpdateSubscriptionFn = (userId: string, data: SubscriptionData, authProvider: AuthProvider) => Promise<void>;
16
+ /**
17
+ * Process webhook with automatic idempotency detection
18
+ *
19
+ * @param rawBody - Raw request body
20
+ * @param signature - Stripe signature
21
+ * @param webhookSecret - Stripe webhook secret
22
+ * @param stripe - Stripe instance
23
+ * @param billingConfig - Billing configuration
24
+ * @param updateSubscription - Function to update user subscription
25
+ *
26
+ * @version 0.0.1
27
+ * @since 0.0.1
28
+ * @author AMBROISE PARK Consulting
29
+ */
30
+ export declare function processWebhook(rawBody: string | Buffer, signature: string, webhookSecret: string, stripe: Stripe, billingConfig: unknown, updateSubscription: UpdateSubscriptionFn, authProvider: WebhookAuthProvider | null): Promise<{
31
+ success: boolean;
32
+ message: string;
33
+ }>;
34
+ /**
35
+ * Calculate subscription end date with proper edge case handling
36
+ * Fixes issues like Jan 31 + 1 month = March 3 (should be Feb 28/29)
37
+ */
@@ -0,0 +1,14 @@
1
+ import { DoNotDevError } from '@donotdev/core/server';
2
+ export { DoNotDevError };
3
+ /**
4
+ * Classify and throw a DoNotDevError from any unknown error.
5
+ * Pure classification — no platform imports, no env detection.
6
+ *
7
+ * @param error - The error to handle
8
+ * @throws DoNotDevError always
9
+ *
10
+ * @version 0.0.2
11
+ * @since 0.0.1
12
+ * @author AMBROISE PARK Consulting
13
+ */
14
+ export declare function handleError(error: unknown): never;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @fileoverview Firebase data transformation utilities for functions
3
+ * @description Server-safe functions for converting data between Firebase and application formats
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ import type { FirestoreTimestamp } from '@donotdev/core/server';
10
+ /**
11
+ * Create a server-safe version of the Timestamp creation
12
+ * @param date - The Date object to convert
13
+ * @returns A representation of the timestamp
14
+ *
15
+ * @version 0.0.1
16
+ * @since 0.0.1
17
+ * @author AMBROISE PARK Consulting
18
+ */
19
+ export declare function createTimestamp(date: Date): FirestoreTimestamp;
20
+ /**
21
+ * Converts a Date or ISO string to a Firestore Timestamp.
22
+ * @param date - The date to convert (string or Date)
23
+ * @returns The Firestore Timestamp
24
+ * @throws Error if the date is invalid
25
+ *
26
+ * @version 0.0.1
27
+ * @since 0.0.1
28
+ * @author AMBROISE PARK Consulting
29
+ */
30
+ export declare function toTimestamp(date: string | Date): FirestoreTimestamp;
31
+ /**
32
+ * Converts a Firestore Timestamp to an ISO string.
33
+ * @param timestamp - The Firestore Timestamp
34
+ * @returns The ISO string representation
35
+ *
36
+ * @version 0.0.1
37
+ * @since 0.0.1
38
+ * @author AMBROISE PARK Consulting
39
+ */
40
+ export declare function toISOString(timestamp: FirestoreTimestamp): string;
41
+ /**
42
+ * Checks if a value is a Firestore Timestamp.
43
+ * @param value - The value to check
44
+ * @returns True if the value is a Timestamp
45
+ *
46
+ * @version 0.0.1
47
+ * @since 0.0.1
48
+ * @author AMBROISE PARK Consulting
49
+ */
50
+ export declare function isTimestamp(value: any): value is FirestoreTimestamp;
51
+ /**
52
+ * Recursively transforms Firestore data to application format by converting Timestamps to ISO strings.
53
+ * @param data - The data to transform
54
+ * @param includeDocumentIds - Whether to include document IDs
55
+ * @returns The transformed data
56
+ *
57
+ * @version 0.0.1
58
+ * @since 0.0.1
59
+ * @author AMBROISE PARK Consulting
60
+ */
61
+ export declare function transformFirestoreData<T = any>(data: T, includeDocumentIds?: boolean): T;
62
+ /**
63
+ * Recursively prepares data for Firestore by converting Date objects to ISO strings.
64
+ * ISO strings are kept as-is (no conversion needed).
65
+ * @param data - The data to prepare
66
+ * @param removeFields - Optional array of field names to remove
67
+ * @returns The prepared data
68
+ *
69
+ * @version 0.0.1
70
+ * @since 0.0.1
71
+ * @author AMBROISE PARK Consulting
72
+ */
73
+ export declare function prepareForFirestore<T = any>(data: T, removeFields?: string[]): T;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @fileoverview GitHub API Service for functions
3
+ * @description Server-safe GitHub API utilities for repository management
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export interface GitHubApiConfig {
10
+ accessToken: string;
11
+ baseUrl?: string;
12
+ }
13
+ export interface GitHubUser {
14
+ id: number;
15
+ login: string;
16
+ email: string;
17
+ name?: string;
18
+ avatar_url: string;
19
+ }
20
+ export interface GitHubRepository {
21
+ id: number;
22
+ name: string;
23
+ full_name: string;
24
+ private: boolean;
25
+ owner: {
26
+ login: string;
27
+ id: number;
28
+ };
29
+ }
30
+ export interface AddCollaboratorRequest {
31
+ owner: string;
32
+ repo: string;
33
+ username: string;
34
+ permission?: 'pull' | 'triage' | 'push' | 'maintain' | 'admin';
35
+ }
36
+ export interface GitHubApiError {
37
+ message: string;
38
+ documentation_url?: string;
39
+ status?: number;
40
+ }
41
+ /**
42
+ * GitHub API Service for server-side operations
43
+ *
44
+ * @version 0.0.1
45
+ * @since 0.0.1
46
+ * @author AMBROISE PARK Consulting
47
+ */
48
+ export declare class GitHubApiService {
49
+ private config;
50
+ constructor(config: GitHubApiConfig);
51
+ /**
52
+ * Get the current authenticated user
53
+ *
54
+ * @version 0.0.1
55
+ * @since 0.0.1
56
+ * @author AMBROISE PARK Consulting
57
+ */
58
+ getCurrentUser(): Promise<GitHubUser>;
59
+ /**
60
+ * Get user repositories
61
+ *
62
+ * @version 0.0.1
63
+ * @since 0.0.1
64
+ * @author AMBROISE PARK Consulting
65
+ */
66
+ getUserRepositories(username?: string): Promise<GitHubRepository[]>;
67
+ /**
68
+ * Add a collaborator to a repository
69
+ *
70
+ * @version 0.0.1
71
+ * @since 0.0.1
72
+ * @author AMBROISE PARK Consulting
73
+ */
74
+ addCollaborator(request: AddCollaboratorRequest): Promise<boolean>;
75
+ /**
76
+ * Check if a user is a collaborator on a repository
77
+ * Uses GitHub's direct API endpoint for efficiency
78
+ *
79
+ * @version 0.0.1
80
+ * @since 0.0.1
81
+ * @author AMBROISE PARK Consulting
82
+ */
83
+ isCollaborator(owner: string, repo: string, username: string): Promise<boolean>;
84
+ /**
85
+ * Remove a collaborator from a repository
86
+ *
87
+ * @version 0.0.1
88
+ * @since 0.0.1
89
+ * @author AMBROISE PARK Consulting
90
+ */
91
+ removeCollaborator(owner: string, repo: string, username: string): Promise<boolean>;
92
+ /**
93
+ * Add a user to an organization team
94
+ *
95
+ * @version 0.0.1
96
+ * @since 0.0.1
97
+ * @author AMBROISE PARK Consulting
98
+ */
99
+ addTeamMember(org: string, teamSlug: string, username: string, role?: 'member' | 'maintainer'): Promise<boolean>;
100
+ /**
101
+ * Remove a user from an organization team
102
+ *
103
+ * @version 0.0.1
104
+ * @since 0.0.1
105
+ * @author AMBROISE PARK Consulting
106
+ */
107
+ removeTeamMember(org: string, teamSlug: string, username: string): Promise<boolean>;
108
+ /**
109
+ * Check if a user is a member of an organization team
110
+ *
111
+ * @version 0.0.1
112
+ * @since 0.0.1
113
+ * @author AMBROISE PARK Consulting
114
+ */
115
+ isTeamMember(org: string, teamSlug: string, username: string): Promise<boolean>;
116
+ /**
117
+ * Make an authenticated request to the GitHub API
118
+ *
119
+ * @version 0.0.1
120
+ * @since 0.0.1
121
+ * @author AMBROISE PARK Consulting
122
+ */
123
+ private request;
124
+ }
125
+ /**
126
+ * Create a GitHub API service instance
127
+ */
128
+ export declare function createGitHubApiService(accessToken: string): GitHubApiService;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview Shared utilities barrel exports
3
+ * @description Centralized exports for shared function utilities
4
+ *
5
+ * @version 0.0.1
6
+ * @since 0.0.1
7
+ * @author AMBROISE PARK Consulting
8
+ */
9
+ export * from './errorHandling.js';
10
+ export * from './github.js';
11
+ export * from './metadata.js';
12
+ export * from './schema.js';
13
+ export * from './utils/index.js';
14
+ export * from './billing/index.js';
15
+ export * from './oauth/index.js';
16
+ export { createTimestamp, toTimestamp, isTimestamp, transformFirestoreData, prepareForFirestore, } from './firebase.js';