@donotdev/functions 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +1 -1
  2. package/lib/chunks/chunk-522YXGDA.js +23 -0
  3. package/lib/chunks/chunk-522YXGDA.js.map +7 -0
  4. package/lib/chunks/chunk-7ODXXXES.js +151 -0
  5. package/lib/chunks/chunk-7ODXXXES.js.map +7 -0
  6. package/lib/chunks/chunk-CP3NNKO5.js +22 -0
  7. package/lib/chunks/chunk-CP3NNKO5.js.map +7 -0
  8. package/lib/chunks/{chunk-2A4FPYNB.js → chunk-CVYSXC27.js} +2 -2
  9. package/lib/chunks/chunk-CVYSXC27.js.map +7 -0
  10. package/lib/chunks/{chunk-PJCJ5H2O.js → chunk-HZM5X5A7.js} +2 -2
  11. package/lib/chunks/chunk-ICNQCRLV.js +22 -0
  12. package/lib/chunks/chunk-ICNQCRLV.js.map +7 -0
  13. package/lib/chunks/chunk-OAZ2JYSD.js +22 -0
  14. package/lib/chunks/chunk-OAZ2JYSD.js.map +7 -0
  15. package/lib/chunks/chunk-OKRR7ST5.js +22 -0
  16. package/lib/chunks/chunk-OKRR7ST5.js.map +7 -0
  17. package/lib/chunks/chunk-PDBNKSBQ.js +22 -0
  18. package/lib/chunks/chunk-PDBNKSBQ.js.map +7 -0
  19. package/lib/chunks/chunk-TJPJXJEK.js +22 -0
  20. package/lib/chunks/{chunk-OZX5ZG44.js.map → chunk-TJPJXJEK.js.map} +1 -1
  21. package/lib/chunks/chunk-W6W4L44F.js +22 -0
  22. package/lib/chunks/chunk-W6W4L44F.js.map +7 -0
  23. package/lib/chunks/{monitoring-UIDJS2KA.js → monitoring-UCBNPPW2.js} +2 -2
  24. package/lib/chunks/{rateLimiter-WNWHI3B4.js → rateLimiter-XKECWM33.js} +2 -2
  25. package/lib/chunks/{server-RYGEBS2B.js → server-24XGDDO3.js} +2 -2
  26. package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
  27. package/lib/firebase/crud/aggregate.d.ts +1 -1
  28. package/lib/firebase/crud/create.d.ts +22 -1
  29. package/lib/firebase/crud/update.d.ts +27 -3
  30. package/lib/firebase/index.js +1 -1
  31. package/lib/firebase/index.js.map +3 -3
  32. package/lib/shared/billing/checkoutValidation.d.ts +1 -1
  33. package/lib/shared/billing/createCheckout.d.ts +1 -1
  34. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +2 -2
  35. package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -8
  36. package/lib/shared/billing/index.d.ts +2 -0
  37. package/lib/shared/billing/orderWebhook.d.ts +29 -2
  38. package/lib/shared/billing/stripePinned.d.ts +43 -0
  39. package/lib/shared/billing/verifyOrderCheckout.d.ts +53 -0
  40. package/lib/shared/crud/bulkCore.d.ts +38 -10
  41. package/lib/shared/crud/index.d.ts +1 -0
  42. package/lib/shared/crud/written.d.ts +21 -0
  43. package/lib/shared/denoEnv.d.ts +25 -0
  44. package/lib/shared/github.d.ts +0 -8
  45. package/lib/shared/index.d.ts +0 -1
  46. package/lib/shared/index.js +1 -1
  47. package/lib/shared/logger.d.ts +14 -14
  48. package/lib/shared/utils/external/subscription.d.ts +0 -8
  49. package/lib/shared/utils.d.ts +13 -10
  50. package/lib/supabase/auth/deleteAccount.d.ts +34 -2
  51. package/lib/supabase/crud/bulk.d.ts +7 -0
  52. package/lib/supabase/crud/create.d.ts +5 -9
  53. package/lib/supabase/crud/entityStore.d.ts +67 -14
  54. package/lib/supabase/crud/update.d.ts +7 -10
  55. package/lib/supabase/index.d.ts +5 -0
  56. package/lib/supabase/index.js +1 -1
  57. package/lib/supabase/index.js.map +4 -4
  58. package/lib/vercel/api/crud/create.d.ts +6 -1
  59. package/lib/vercel/api/crud/update.d.ts +8 -1
  60. package/lib/vercel/api/index.js +1 -1
  61. package/lib/vercel/api/index.js.map +3 -3
  62. package/package.json +9 -9
  63. package/src/firebase/auth/getCustomClaims.ts +2 -0
  64. package/src/firebase/auth/getUserAuthStatus.ts +2 -0
  65. package/src/firebase/auth/removeCustomClaims.ts +33 -1
  66. package/src/firebase/auth/setCustomClaims.ts +6 -0
  67. package/src/firebase/baseFunction.ts +5 -2
  68. package/src/firebase/billing/changePlan.ts +6 -5
  69. package/src/firebase/billing/createCustomerPortal.ts +6 -4
  70. package/src/firebase/billing/refreshSubscriptionStatus.ts +7 -5
  71. package/src/firebase/billing/webhookHandler.ts +4 -4
  72. package/src/firebase/crud/__tests__/bulk.test.ts +50 -1
  73. package/src/firebase/crud/__tests__/create.test.ts +64 -0
  74. package/src/firebase/crud/__tests__/update.test.ts +97 -0
  75. package/src/firebase/crud/aggregate.ts +37 -19
  76. package/src/firebase/crud/bulk.ts +30 -10
  77. package/src/firebase/crud/create.ts +40 -26
  78. package/src/firebase/crud/delete.ts +6 -1
  79. package/src/firebase/crud/get.ts +12 -14
  80. package/src/firebase/crud/list.ts +23 -12
  81. package/src/firebase/crud/update.ts +49 -25
  82. package/src/firebase/helpers/githubAccessHelper.ts +3 -0
  83. package/src/firebase/helpers/githubTeamAccessHelper.ts +1 -0
  84. package/src/firebase/oauth/exchangeToken.ts +4 -0
  85. package/src/firebase/oauth/getConnections.ts +1 -1
  86. package/src/firebase/oauth/githubAccess.ts +3 -0
  87. package/src/firebase/oauth/refreshToken.ts +1 -0
  88. package/src/firebase/registerCrudFunctions.ts +1 -0
  89. package/src/firebase/scheduled/checkExpiredSubscriptions.ts +4 -1
  90. package/src/shared/__tests__/bulkCore.test.ts +191 -0
  91. package/src/shared/__tests__/removeCustomClaims.test.ts +117 -0
  92. package/src/shared/__tests__/setCustomClaims.test.ts +103 -0
  93. package/src/shared/__tests__/utils.test.ts +0 -30
  94. package/src/shared/ai/classifyAIError.ts +18 -10
  95. package/src/shared/ai/createAIRoute.ts +2 -1
  96. package/src/shared/ai/resolveModelTier.ts +2 -1
  97. package/src/shared/billing/__tests__/createCheckout.test.ts +94 -0
  98. package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +1 -1
  99. package/src/shared/billing/__tests__/updateUserSubscription.test.ts +139 -0
  100. package/src/shared/billing/__tests__/verifyOrderCheckout.exports.test.ts +47 -0
  101. package/src/shared/billing/__tests__/verifyOrderCheckout.supabase.integration.test.ts +107 -0
  102. package/src/shared/billing/__tests__/verifyOrderCheckout.test.ts +233 -0
  103. package/src/shared/billing/__tests__/webhookHandler.test.ts +108 -0
  104. package/src/shared/billing/checkoutValidation.ts +19 -2
  105. package/src/shared/billing/createCheckout.ts +56 -11
  106. package/src/shared/billing/helpers/subscriptionManagement.ts +14 -10
  107. package/src/shared/billing/helpers/updateUserSubscription.ts +10 -14
  108. package/src/shared/billing/index.ts +2 -0
  109. package/src/shared/billing/orderWebhook.ts +69 -1
  110. package/src/shared/billing/stripeClient.ts +2 -1
  111. package/src/shared/billing/stripePinned.ts +71 -0
  112. package/src/shared/billing/tierWebhookEvents.ts +3 -2
  113. package/src/shared/billing/verifyOrderCheckout.ts +142 -0
  114. package/src/shared/billing/webhookHandler.ts +5 -1
  115. package/src/shared/crud/bulkCore.ts +112 -82
  116. package/src/shared/crud/index.ts +1 -0
  117. package/src/shared/crud/written.ts +56 -0
  118. package/src/shared/denoEnv.ts +29 -0
  119. package/src/shared/email/createEmailRoute.ts +2 -2
  120. package/src/shared/errorHandling.ts +8 -8
  121. package/src/shared/firebase.ts +26 -9
  122. package/src/shared/github.ts +15 -5
  123. package/src/shared/index.d.ts +0 -9
  124. package/src/shared/index.ts +0 -1
  125. package/src/shared/logger.ts +37 -38
  126. package/src/shared/utils/external/date.ts +4 -4
  127. package/src/shared/utils/external/subscription.ts +2 -89
  128. package/src/shared/utils/firebaseHelpers.ts +2 -0
  129. package/src/shared/utils/internal/idempotency.ts +3 -0
  130. package/src/shared/utils/internal/monitoring.ts +6 -5
  131. package/src/shared/utils/internal/validation.ts +2 -0
  132. package/src/shared/utils/schemaValidation.ts +1 -0
  133. package/src/shared/utils/validation.ts +10 -20
  134. package/src/shared/utils.ts +4 -42
  135. package/src/supabase/__tests__/aggregate.test.ts +132 -0
  136. package/src/supabase/__tests__/bulk.test.ts +60 -2
  137. package/src/supabase/__tests__/create.test.ts +86 -0
  138. package/src/supabase/__tests__/entityStore.test.ts +91 -25
  139. package/src/supabase/__tests__/update.test.ts +107 -0
  140. package/src/supabase/auth/__tests__/deleteAccount.test.ts +102 -0
  141. package/src/supabase/auth/deleteAccount.ts +72 -5
  142. package/src/supabase/auth/removeCustomClaims.ts +7 -2
  143. package/src/supabase/auth/setCustomClaims.ts +4 -2
  144. package/src/supabase/billing/refreshSubscriptionStatus.ts +6 -5
  145. package/src/supabase/crud/aggregate.ts +85 -72
  146. package/src/supabase/crud/bulk.ts +50 -0
  147. package/src/supabase/crud/create.ts +27 -33
  148. package/src/supabase/crud/delete.ts +2 -1
  149. package/src/supabase/crud/entityStore.ts +107 -18
  150. package/src/supabase/crud/get.ts +5 -13
  151. package/src/supabase/crud/list.ts +28 -21
  152. package/src/supabase/crud/update.ts +29 -24
  153. package/src/supabase/edgeFunction.ts +2 -1
  154. package/src/supabase/email/createEmailFunction.ts +2 -1
  155. package/src/supabase/index.ts +8 -0
  156. package/src/supabase/oauth/exchangeToken.ts +1 -0
  157. package/src/supabase/oauth/getConnections.ts +1 -1
  158. package/src/supabase/oauth/refreshToken.ts +1 -0
  159. package/src/supabase/registerCrudFunctions.ts +1 -0
  160. package/src/supabase/utils/idempotency.ts +1 -1
  161. package/src/supabase/utils/monitoring.ts +1 -0
  162. package/src/vercel/__tests__/bulk.test.ts +16 -8
  163. package/src/vercel/api/billing/change-plan.ts +6 -5
  164. package/src/vercel/api/billing/refresh-subscription-status.ts +3 -1
  165. package/src/vercel/api/crud/bulk.ts +34 -6
  166. package/src/vercel/api/crud/create.ts +22 -21
  167. package/src/vercel/api/crud/delete.ts +5 -2
  168. package/src/vercel/api/crud/get.ts +10 -8
  169. package/src/vercel/api/crud/list.ts +10 -8
  170. package/src/vercel/api/crud/update.ts +25 -20
  171. package/src/vercel/api/oauth/check-github-access.ts +1 -0
  172. package/src/vercel/api/oauth/exchange-token.ts +5 -2
  173. package/src/vercel/api/oauth/grant-github-access.ts +1 -0
  174. package/src/vercel/api/oauth/revoke-github-access.ts +1 -0
  175. package/src/vercel/baseFunction.ts +5 -1
  176. package/lib/chunks/chunk-2A4FPYNB.js.map +0 -7
  177. package/lib/chunks/chunk-2IFFIUFV.js +0 -23
  178. package/lib/chunks/chunk-2IFFIUFV.js.map +0 -7
  179. package/lib/chunks/chunk-FQSQGOBN.js +0 -22
  180. package/lib/chunks/chunk-FQSQGOBN.js.map +0 -7
  181. package/lib/chunks/chunk-G4FO76EA.js +0 -22
  182. package/lib/chunks/chunk-G4FO76EA.js.map +0 -7
  183. package/lib/chunks/chunk-LSM5Y2E5.js +0 -22
  184. package/lib/chunks/chunk-LSM5Y2E5.js.map +0 -7
  185. package/lib/chunks/chunk-M4JV2JCF.js +0 -22
  186. package/lib/chunks/chunk-M4JV2JCF.js.map +0 -7
  187. package/lib/chunks/chunk-OZX5ZG44.js +0 -22
  188. package/lib/chunks/chunk-PWAGW4R6.js +0 -22
  189. package/lib/chunks/chunk-PWAGW4R6.js.map +0 -7
  190. package/lib/chunks/chunk-UYI56E6Q.js +0 -151
  191. package/lib/chunks/chunk-UYI56E6Q.js.map +0 -7
  192. package/lib/chunks/chunk-ZVHC2CAV.js +0 -22
  193. package/lib/chunks/chunk-ZVHC2CAV.js.map +0 -7
  194. package/lib/shared/schema.d.ts +0 -56
  195. package/lib/shared/utils/functionWrapper.d.ts +0 -36
  196. package/src/shared/__tests__/schema.test.ts +0 -219
  197. package/src/shared/schema.ts +0 -192
  198. package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -122
  199. package/src/shared/utils/functionWrapper.ts +0 -73
  200. /package/lib/chunks/{chunk-PJCJ5H2O.js.map → chunk-HZM5X5A7.js.map} +0 -0
  201. /package/lib/chunks/{monitoring-UIDJS2KA.js.map → monitoring-UCBNPPW2.js.map} +0 -0
  202. /package/lib/chunks/{rateLimiter-WNWHI3B4.js.map → rateLimiter-XKECWM33.js.map} +0 -0
  203. /package/lib/chunks/{server-RYGEBS2B.js.map → server-24XGDDO3.js.map} +0 -0
@@ -89,6 +89,7 @@ export function toISOString(timestamp: FirestoreTimestamp): string {
89
89
  * @since 0.0.1
90
90
  * @author AMBROISE PARK Consulting
91
91
  */
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
92
93
  export function isTimestamp(value: any): value is FirestoreTimestamp {
93
94
  return (
94
95
  value &&
@@ -100,6 +101,23 @@ export function isTimestamp(value: any): value is FirestoreTimestamp {
100
101
  );
101
102
  }
102
103
 
104
+ /**
105
+ * Whether a value looks like a Firestore DocumentSnapshot (id, ref, data()).
106
+ */
107
+ function isDocumentSnapshotLike(value: object): value is {
108
+ id: unknown;
109
+ ref: unknown;
110
+ // why: Firestore DocumentSnapshot.data() contract; the return is not checked at runtime
111
+ data: () => Record<string, unknown> | undefined;
112
+ } {
113
+ return (
114
+ 'id' in value &&
115
+ 'ref' in value &&
116
+ 'data' in value &&
117
+ typeof value.data === 'function'
118
+ );
119
+ }
120
+
103
121
  /**
104
122
  * Recursively transforms Firestore data to application format by converting Timestamps to ISO strings.
105
123
  * @param data - The data to transform
@@ -110,6 +128,7 @@ export function isTimestamp(value: any): value is FirestoreTimestamp {
110
128
  * @since 0.0.1
111
129
  * @author AMBROISE PARK Consulting
112
130
  */
131
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
113
132
  export function transformFirestoreData<T = any>(
114
133
  data: T,
115
134
  includeDocumentIds: boolean = false
@@ -121,12 +140,9 @@ export function transformFirestoreData<T = any>(
121
140
  includeDocumentIds &&
122
141
  typeof data === 'object' &&
123
142
  data !== null &&
124
- 'id' in data &&
125
- 'ref' in data &&
126
- 'data' in data &&
127
- typeof (data as any).data === 'function'
143
+ isDocumentSnapshotLike(data)
128
144
  ) {
129
- const doc = data as any;
145
+ const doc = data;
130
146
  const documentData = doc.data();
131
147
  return {
132
148
  id: doc.id,
@@ -146,8 +162,8 @@ export function transformFirestoreData<T = any>(
146
162
 
147
163
  // Handle objects recursively
148
164
  if (typeof data === 'object' && data !== null) {
149
- const transformed: Record<string, any> = {};
150
- for (const [key, value] of Object.entries(data as Record<string, any>)) {
165
+ const transformed: Record<string, unknown> = {};
166
+ for (const [key, value] of Object.entries(data)) {
151
167
  transformed[key] = transformFirestoreData(value);
152
168
  }
153
169
  return transformed as T;
@@ -168,6 +184,7 @@ export function transformFirestoreData<T = any>(
168
184
  * @since 0.0.1
169
185
  * @author AMBROISE PARK Consulting
170
186
  */
187
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
171
188
  export function prepareForFirestore<T = any>(
172
189
  data: T,
173
190
  removeFields: string[] = []
@@ -183,8 +200,8 @@ export function prepareForFirestore<T = any>(
183
200
 
184
201
  // Handle objects recursively
185
202
  if (typeof data === 'object' && data !== null) {
186
- const prepared: Record<string, any> = {};
187
- for (const [key, value] of Object.entries(data as Record<string, any>)) {
203
+ const prepared: Record<string, unknown> = {};
204
+ for (const [key, value] of Object.entries(data)) {
188
205
  // Skip fields that should be removed
189
206
  if (removeFields.includes(key)) {
190
207
  continue;
@@ -9,6 +9,8 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import * as v from 'valibot';
13
+
12
14
  /** Configuration for authenticating with the GitHub API. */
13
15
  export interface GitHubApiConfig {
14
16
  accessToken: string;
@@ -51,6 +53,12 @@ export interface GitHubApiError {
51
53
  status?: number;
52
54
  }
53
55
 
56
+ /** Error body shape returned by the GitHub API on non-2xx responses (untrusted). */
57
+ const GitHubErrorBodySchema = v.object({
58
+ message: v.optional(v.string()),
59
+ documentation_url: v.optional(v.string()),
60
+ });
61
+
54
62
  /** Pattern for valid GitHub usernames, org names, repo names, and team slugs */
55
63
  const SAFE_GITHUB_NAME = /^[a-zA-Z0-9_.-]+$/;
56
64
 
@@ -158,8 +166,8 @@ export class GitHubApiService {
158
166
  method: 'GET',
159
167
  });
160
168
  return true;
161
- } catch (error: any) {
162
- if (error.message?.includes('404')) {
169
+ } catch (error) {
170
+ if (error instanceof Error && error.message.includes('404')) {
163
171
  return false;
164
172
  }
165
173
  console.error('Failed to check collaborator status:', error);
@@ -276,8 +284,8 @@ export class GitHubApiService {
276
284
  }
277
285
  );
278
286
  return true;
279
- } catch (error: any) {
280
- if (error.message?.includes('404')) {
287
+ } catch (error) {
288
+ if (error instanceof Error && error.message.includes('404')) {
281
289
  return false;
282
290
  }
283
291
  console.error('Failed to check team membership:', error);
@@ -310,7 +318,9 @@ export class GitHubApiService {
310
318
  });
311
319
 
312
320
  if (!response.ok) {
313
- const errorData = (await response.json().catch(() => ({}))) as any;
321
+ const errorBody: unknown = await response.json().catch(() => ({}));
322
+ const parsed = v.safeParse(GitHubErrorBodySchema, errorBody);
323
+ const errorData = parsed.success ? parsed.output : {};
314
324
  const error: GitHubApiError = {
315
325
  message:
316
326
  errorData.message ||
@@ -36,15 +36,6 @@ export * from './github.js';
36
36
  */
37
37
  export * from './metadata.js';
38
38
 
39
- /**
40
- * Schema validation utilities
41
- *
42
- * @version 0.1.0
43
- * @since 0.0.1
44
- * @author AMBROISE PARK Consulting
45
- */
46
- export * from './schema.js';
47
-
48
39
  /**
49
40
  * General utility functions
50
41
  *
@@ -12,7 +12,6 @@
12
12
  export * from './errorHandling.js';
13
13
  export * from './github.js';
14
14
  export * from './metadata.js';
15
- export * from './schema.js';
16
15
  export * from './utils/index.js';
17
16
  export * from './crud/index.js';
18
17
  export * from './ai/index.js';
@@ -23,14 +23,15 @@
23
23
  * @author AMBROISE PARK Consulting
24
24
  */
25
25
 
26
- // Node-only metadata (pid, version) is added when running on Node; Deno runtimes
27
- // (Supabase Edge) log without it. Server-only by package: @donotdev/functions is
28
- // never imported by client code, so no runtime browser check (Supabase Edge
29
- // defines `window`, which made such a check throw on every edge function).
30
- const _isNodeEnv = typeof process !== 'undefined' && !!process.versions?.node;
26
+ // Server-only by package: @donotdev/functions is never imported by client code,
27
+ // so no runtime browser check (Supabase Edge defines `window`, which made such a
28
+ // check throw on every edge function).
31
29
 
32
30
  let sentryEnabled = false;
33
- let sentryClient: any = null;
31
+ let sentryClient: Pick<
32
+ typeof import('@sentry/node'),
33
+ 'captureException' | 'captureMessage'
34
+ > | null = null;
34
35
 
35
36
  // Initialize Sentry lazily to avoid Firebase Functions issues
36
37
  let sentryInitialized = false;
@@ -88,9 +89,9 @@ export interface LogEntry {
88
89
  level: LogLevel;
89
90
  message: string;
90
91
  timestamp: string;
91
- context?: Record<string, any>;
92
+ context?: Record<string, unknown>;
92
93
  error?: Error;
93
- metadata?: Record<string, any>;
94
+ metadata?: Record<string, unknown>;
94
95
  }
95
96
 
96
97
  /**
@@ -130,7 +131,7 @@ export const logger = {
130
131
  * @since 0.0.1
131
132
  * @author AMBROISE PARK Consulting
132
133
  */
133
- debug(message: string, context?: Record<string, any>): void {
134
+ debug(message: string, context?: Record<string, unknown>): void {
134
135
  this.log(LogLevel.DEBUG, message, context);
135
136
  },
136
137
 
@@ -143,7 +144,7 @@ export const logger = {
143
144
  * @since 0.0.1
144
145
  * @author AMBROISE PARK Consulting
145
146
  */
146
- info(message: string, context?: Record<string, any>): void {
147
+ info(message: string, context?: Record<string, unknown>): void {
147
148
  this.log(LogLevel.INFO, message, context);
148
149
  },
149
150
 
@@ -156,7 +157,7 @@ export const logger = {
156
157
  * @since 0.0.1
157
158
  * @author AMBROISE PARK Consulting
158
159
  */
159
- warn(message: string, context?: Record<string, any>): void {
160
+ warn(message: string, context?: Record<string, unknown>): void {
160
161
  this.log(LogLevel.WARN, message, context);
161
162
  },
162
163
 
@@ -169,7 +170,10 @@ export const logger = {
169
170
  * @since 0.0.1
170
171
  * @author AMBROISE PARK Consulting
171
172
  */
172
- async error(message: string, context?: Record<string, any>): Promise<void> {
173
+ async error(
174
+ message: string,
175
+ context?: Record<string, unknown>
176
+ ): Promise<void> {
173
177
  this.log(LogLevel.ERROR, message, context);
174
178
 
175
179
  // Initialize Sentry lazily if needed
@@ -201,7 +205,10 @@ export const logger = {
201
205
  * @since 0.0.1
202
206
  * @author AMBROISE PARK Consulting
203
207
  */
204
- async fatal(message: string, context?: Record<string, any>): Promise<void> {
208
+ async fatal(
209
+ message: string,
210
+ context?: Record<string, unknown>
211
+ ): Promise<void> {
205
212
  this.log(LogLevel.FATAL, message, context);
206
213
 
207
214
  // Initialize Sentry lazily if needed
@@ -236,26 +243,12 @@ export const logger = {
236
243
  * @since 0.0.1
237
244
  * @author AMBROISE PARK Consulting
238
245
  */
239
- log(level: LogLevel, message: string, context?: Record<string, any>): void {
246
+ log(
247
+ level: LogLevel,
248
+ message: string,
249
+ context?: Record<string, unknown>
250
+ ): void {
240
251
  const timestamp = new Date().toISOString();
241
- const logEntry: LogEntry = {
242
- level,
243
- message,
244
- timestamp,
245
- context,
246
- error: context?.error,
247
- metadata: {
248
- ...(_isNodeEnv
249
- ? {
250
- pid: process.pid,
251
- nodeVersion: process.version,
252
- platform: process.platform,
253
- }
254
- : {}),
255
- ...context?.metadata,
256
- },
257
- };
258
-
259
252
  // Format log entry for console output
260
253
  const levelName = LogLevel[level];
261
254
  const contextStr = context ? ` ${JSON.stringify(context)}` : '';
@@ -302,21 +295,27 @@ export const logger = {
302
295
  * @param context - Additional context to include in all logs
303
296
  * @returns Child logger instance
304
297
  */
305
- export function createChildLogger(context: Record<string, any>) {
298
+ export function createChildLogger(context: Record<string, unknown>) {
306
299
  return {
307
- debug: (message: string, additionalContext?: Record<string, any>) => {
300
+ debug: (message: string, additionalContext?: Record<string, unknown>) => {
308
301
  logger.debug(message, { ...context, ...additionalContext });
309
302
  },
310
- info: (message: string, additionalContext?: Record<string, any>) => {
303
+ info: (message: string, additionalContext?: Record<string, unknown>) => {
311
304
  logger.info(message, { ...context, ...additionalContext });
312
305
  },
313
- warn: (message: string, additionalContext?: Record<string, any>) => {
306
+ warn: (message: string, additionalContext?: Record<string, unknown>) => {
314
307
  logger.warn(message, { ...context, ...additionalContext });
315
308
  },
316
- error: async (message: string, additionalContext?: Record<string, any>) => {
309
+ error: async (
310
+ message: string,
311
+ additionalContext?: Record<string, unknown>
312
+ ) => {
317
313
  await logger.error(message, { ...context, ...additionalContext });
318
314
  },
319
- fatal: async (message: string, additionalContext?: Record<string, any>) => {
315
+ fatal: async (
316
+ message: string,
317
+ additionalContext?: Record<string, unknown>
318
+ ) => {
320
319
  await logger.fatal(message, { ...context, ...additionalContext });
321
320
  },
322
321
  };
@@ -42,9 +42,8 @@ export function toISOString(date: DateValue): string {
42
42
  return date.toISOString();
43
43
  }
44
44
  if (typeof date === 'object' && date !== null && 'toDate' in date) {
45
- const timestamp = date as any;
46
- if (typeof timestamp.toDate === 'function') {
47
- return timestamp.toDate().toISOString();
45
+ if (typeof date.toDate === 'function') {
46
+ return date.toDate().toISOString();
48
47
  }
49
48
  }
50
49
 
@@ -58,7 +57,8 @@ export function toISOString(date: DateValue): string {
58
57
  }
59
58
 
60
59
  // Fallback for any other type
61
- const parsed = new Date(date as any);
60
+ // why: unreachable for typed callers; keeps the runtime path for untyped values (numbers, plain objects)
61
+ const parsed = new Date(date as unknown as string);
62
62
  if (isNaN(parsed.getTime())) {
63
63
  throw new Error('Invalid date format');
64
64
  }
@@ -9,11 +9,7 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
- import type {
13
- SubscriptionStatus,
14
- SubscriptionClaims,
15
- } from '@donotdev/core/server';
16
- import { SUBSCRIPTION_STATUS } from '@donotdev/core/server';
12
+ import type { SubscriptionClaims } from '@donotdev/core/server';
17
13
  import {
18
14
  getFirebaseAdminAuth,
19
15
  getFirebaseAdminFirestore,
@@ -42,90 +38,6 @@ export function getTierFromPriceId(priceId: string): string {
42
38
  return tierMapping[priceId] || 'free';
43
39
  }
44
40
 
45
- /**
46
- * Validates subscription status and updates Firebase custom claims
47
- *
48
- * @version 0.1.0
49
- * @since 0.0.1
50
- * @author AMBROISE PARK Consulting
51
- */
52
- export async function updateFirebaseUserSubscription(
53
- firebaseUid: string,
54
- subscription: any
55
- ): Promise<void> {
56
- if (!firebaseUid) {
57
- throw new Error('Firebase UID is required to update subscription');
58
- }
59
-
60
- const priceId = subscription.items?.data?.[0]?.price?.id;
61
- const tier = getTierFromPriceId(priceId);
62
-
63
- // Validate status: must be a framework value OR a valid custom consumer value (non-empty string)
64
- // Default to 'incomplete' if invalid/empty
65
- const frameworkStatuses = Object.values(SUBSCRIPTION_STATUS);
66
- const rawStatus = subscription.status || '';
67
- const isValidFrameworkStatus = frameworkStatuses.includes(rawStatus as any);
68
- const isValidCustomStatus =
69
- typeof rawStatus === 'string' && rawStatus.trim().length > 0;
70
-
71
- const status: SubscriptionStatus =
72
- isValidFrameworkStatus || isValidCustomStatus
73
- ? (rawStatus as SubscriptionStatus)
74
- : SUBSCRIPTION_STATUS.INCOMPLETE;
75
-
76
- const subscriptionClaims: SubscriptionClaims = {
77
- tier,
78
- subscriptionId: subscription.id,
79
- customerId: subscription.customer,
80
- status,
81
- subscriptionEnd: subscription.current_period_end
82
- ? new Date(subscription.current_period_end * 1000).toISOString()
83
- : null,
84
- cancelAtPeriodEnd: subscription.cancel_at_period_end || false,
85
- updatedAt: new Date().toISOString(),
86
- };
87
-
88
- try {
89
- const auth = getFirebaseAdminAuth();
90
- const db = getFirebaseAdminFirestore();
91
-
92
- // Read existing claims and merge to avoid overwriting other claims
93
- const user = await auth.getUser(firebaseUid);
94
- const currentClaims = user.customClaims || {};
95
-
96
- // Update Firebase Auth custom claims
97
- await auth.setCustomUserClaims(firebaseUid, {
98
- ...currentClaims,
99
- subscription: subscriptionClaims,
100
- });
101
-
102
- // Also save to Firestore for redundancy and querying
103
- await db
104
- .collection('subscriptions')
105
- .doc(firebaseUid)
106
- .set(
107
- {
108
- ...subscriptionClaims,
109
- priceId,
110
- createdAt: subscription.created
111
- ? new Date(subscription.created * 1000).toISOString()
112
- : new Date().toISOString(),
113
- updatedAt: new Date().toISOString(),
114
- },
115
- { merge: true }
116
- );
117
-
118
- console.log(`Subscription updated for user ${firebaseUid}:`, {
119
- tier,
120
- status: subscription.status,
121
- subscriptionId: subscription.id,
122
- });
123
- } catch (error) {
124
- console.error('Failed to update user subscription:', error);
125
- throw new Error('Failed to update user subscription');
126
- }
127
- }
128
-
129
41
  /**
130
42
  * Cancels user subscription and resets to free tier
131
43
  *
@@ -135,6 +47,7 @@ export async function updateFirebaseUserSubscription(
135
47
  */
136
48
  export async function cancelUserSubscription(
137
49
  firebaseUid: string,
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
138
51
  subscription: any
139
52
  ): Promise<void> {
140
53
  if (!firebaseUid) {
@@ -23,6 +23,7 @@ import { withSchemaValidation } from './schemaValidation.js';
23
23
  * @author AMBROISE PARK Consulting
24
24
  */
25
25
  export function createFirebaseCallable<TRequest, TResponse>(
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
26
27
  config: any,
27
28
  defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>,
28
29
  handler: (
@@ -56,6 +57,7 @@ export function createFirebaseCallable<TRequest, TResponse>(
56
57
  * @author AMBROISE PARK Consulting
57
58
  */
58
59
  export function createFirebaseFunctionExports<TRequest, TResponse>(
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
59
61
  config: any,
60
62
  defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>,
61
63
  handler: (
@@ -14,6 +14,7 @@ import { logger } from 'firebase-functions/v2';
14
14
  import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
15
15
 
16
16
  /** Stored result of a previously processed idempotent operation. */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
17
18
  export interface IdempotencyResult<T = any> {
18
19
  result: T;
19
20
  processedAt: string;
@@ -27,6 +28,7 @@ export interface IdempotencyResult<T = any> {
27
28
  * @since 0.0.1
28
29
  * @author AMBROISE PARK Consulting
29
30
  */
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
30
32
  export async function checkIdempotency<T = any>(
31
33
  key: string,
32
34
  operation: string
@@ -70,6 +72,7 @@ export async function checkIdempotency<T = any>(
70
72
  * @since 0.0.1
71
73
  * @author AMBROISE PARK Consulting
72
74
  */
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
73
76
  export async function storeIdempotencyResult<T = any>(
74
77
  key: string,
75
78
  operation: string,
@@ -35,6 +35,7 @@ export interface PaymentMetrics {
35
35
  currency?: string;
36
36
  status: 'success' | 'failed' | 'pending';
37
37
  timestamp: string;
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
38
39
  metadata?: Record<string, any>;
39
40
  }
40
41
 
@@ -109,7 +110,7 @@ export async function checkPaymentFailureRate(
109
110
 
110
111
  const totalPayments = recentMetrics.size;
111
112
  const failedPayments = recentMetrics.docs.filter(
112
- (doc: any) => doc.data().status === 'failed'
113
+ (doc) => doc.data().status === 'failed'
113
114
  ).length;
114
115
 
115
116
  const failureRate = (failedPayments / totalPayments) * 100;
@@ -157,7 +158,7 @@ export async function checkPaymentVolume(
157
158
  .get();
158
159
 
159
160
  let totalVolume = 0;
160
- todayMetrics.docs.forEach((doc: any) => {
161
+ todayMetrics.docs.forEach((doc) => {
161
162
  const data = doc.data();
162
163
  if (data.amount && data.currency === 'usd') {
163
164
  totalVolume += data.amount / 100; // Convert cents to dollars
@@ -284,7 +285,7 @@ export async function getPaymentMetricsSummary(
284
285
  let failedPayments = 0;
285
286
  let totalVolume = 0;
286
287
 
287
- metrics.docs.forEach((doc: any) => {
288
+ metrics.docs.forEach((doc) => {
288
289
  const data = doc.data();
289
290
  totalPayments++;
290
291
 
@@ -349,7 +350,7 @@ export async function cleanupOldMetrics(
349
350
 
350
351
  if (!oldMetrics.empty) {
351
352
  const batch = db.batch();
352
- oldMetrics.docs.forEach((doc: any) => batch.delete(doc.ref));
353
+ oldMetrics.docs.forEach((doc) => batch.delete(doc.ref));
353
354
  await batch.commit();
354
355
  }
355
356
 
@@ -365,7 +366,7 @@ export async function cleanupOldMetrics(
365
366
 
366
367
  if (!oldAlerts.empty) {
367
368
  const batch = db.batch();
368
- oldAlerts.docs.forEach((doc: any) => batch.delete(doc.ref));
369
+ oldAlerts.docs.forEach((doc) => batch.delete(doc.ref));
369
370
  await batch.commit();
370
371
  }
371
372
 
@@ -20,6 +20,7 @@ import { DoNotDevError } from '@donotdev/core/server';
20
20
  * @since 0.0.1
21
21
  * @author AMBROISE PARK Consulting
22
22
  */
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
23
24
  export function safeJsonParse<T = any>(json: string): T | null {
24
25
  try {
25
26
  return JSON.parse(json);
@@ -64,6 +65,7 @@ export function validateCollectionName(name: string): void {
64
65
  * @since 0.0.1
65
66
  * @author AMBROISE PARK Consulting
66
67
  */
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
67
69
  export function validateDocument(data: any, schema?: any): void {
68
70
  // G63: Throw DoNotDevError instead of plain Error for consistent error handling
69
71
  if (!data || typeof data !== 'object') {
@@ -21,6 +21,7 @@ import * as v from 'valibot';
21
21
  * @author AMBROISE PARK Consulting
22
22
  */
23
23
  export function validateRequestData<T>(
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
24
25
  data: any,
25
26
  defaultSchema: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>,
26
27
  customSchema?: v.BaseSchema<unknown, T, v.BaseIssue<unknown>>
@@ -57,6 +57,7 @@ export const StripeValidationSchemas = {
57
57
  export interface ValidationResult {
58
58
  isValid: boolean;
59
59
  errors: string[];
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
60
61
  data?: any;
61
62
  }
62
63
 
@@ -67,6 +68,7 @@ export interface ValidationResult {
67
68
  * @since 0.0.1
68
69
  * @author AMBROISE PARK Consulting
69
70
  */
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
70
72
  export function validateWebhookEvent(data: any): ValidationResult {
71
73
  try {
72
74
  const validatedData = v.parse(StripeValidationSchemas.webhookEvent, data);
@@ -76,16 +78,9 @@ export function validateWebhookEvent(data: any): ValidationResult {
76
78
  errors: [],
77
79
  };
78
80
  } catch (error) {
79
- if (
80
- error &&
81
- typeof error === 'object' &&
82
- 'issues' in error &&
83
- ((error instanceof Error && error.name === 'ValiError') ||
84
- (error as any).name === 'ValiError')
85
- ) {
86
- const valiError = error as any;
87
- const errors = valiError.issues.map(
88
- (err: v.BaseIssue<unknown>) =>
81
+ if (v.isValiError(error)) {
82
+ const errors = error.issues.map(
83
+ (err) =>
89
84
  `${err.path?.map((p) => p.key).join('.') || ''}: ${err.message}`
90
85
  );
91
86
  logger.warn('Webhook event validation failed', { errors, data });
@@ -108,6 +103,7 @@ export function validateWebhookEvent(data: any): ValidationResult {
108
103
  * @since 0.0.1
109
104
  * @author AMBROISE PARK Consulting
110
105
  */
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
111
107
  export function validatePurchaseRequest(data: any): ValidationResult {
112
108
  try {
113
109
  const validatedData = v.parse(
@@ -120,16 +116,9 @@ export function validatePurchaseRequest(data: any): ValidationResult {
120
116
  errors: [],
121
117
  };
122
118
  } catch (error) {
123
- if (
124
- error &&
125
- typeof error === 'object' &&
126
- 'issues' in error &&
127
- ((error instanceof Error && error.name === 'ValiError') ||
128
- (error as any).name === 'ValiError')
129
- ) {
130
- const valiError = error as any;
131
- const errors = valiError.issues.map(
132
- (err: v.BaseIssue<unknown>) =>
119
+ if (v.isValiError(error)) {
120
+ const errors = error.issues.map(
121
+ (err) =>
133
122
  `${err.path?.map((p) => p.key).join('.') || ''}: ${err.message}`
134
123
  );
135
124
  logger.warn('Purchase request validation failed', { errors, data });
@@ -223,6 +212,7 @@ export function validateUrl(url: string, name: string = 'URL'): string {
223
212
  * @author AMBROISE PARK Consulting
224
213
  */
225
214
  export function validateMetadata(
215
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported signature; narrowing it is a breaking change for importers (deferred to a major, any-audit 2026-11-11)
226
216
  metadata: Record<string, any>
227
217
  ): Record<string, string> {
228
218
  const sanitized: Record<string, string> = {};