@donotdev/functions 0.2.2 → 0.2.3

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 (161) hide show
  1. package/README.md +1 -1
  2. package/lib/chunks/chunk-6NXIK35R.js +23 -0
  3. package/lib/chunks/chunk-6NXIK35R.js.map +7 -0
  4. package/lib/chunks/chunk-EZKRLLSQ.js +22 -0
  5. package/lib/chunks/{chunk-OZX5ZG44.js.map → chunk-EZKRLLSQ.js.map} +1 -1
  6. package/lib/chunks/chunk-F3PHE627.js +22 -0
  7. package/lib/chunks/chunk-F3PHE627.js.map +7 -0
  8. package/lib/chunks/chunk-F3WBFWPO.js +151 -0
  9. package/lib/chunks/chunk-F3WBFWPO.js.map +7 -0
  10. package/lib/chunks/chunk-G5DRV3DH.js +22 -0
  11. package/lib/chunks/chunk-G5DRV3DH.js.map +7 -0
  12. package/lib/chunks/{chunk-2A4FPYNB.js → chunk-GDIUOJMD.js} +2 -2
  13. package/lib/chunks/chunk-GDIUOJMD.js.map +7 -0
  14. package/lib/chunks/chunk-Q2WLRFOE.js +22 -0
  15. package/lib/chunks/chunk-Q2WLRFOE.js.map +7 -0
  16. package/lib/chunks/chunk-QXIOO2RL.js +22 -0
  17. package/lib/chunks/chunk-QXIOO2RL.js.map +7 -0
  18. package/lib/chunks/{chunk-PJCJ5H2O.js → chunk-UH445BGK.js} +2 -2
  19. package/lib/chunks/chunk-W6W4L44F.js +22 -0
  20. package/lib/chunks/chunk-W6W4L44F.js.map +7 -0
  21. package/lib/chunks/chunk-W74UL7AY.js +22 -0
  22. package/lib/chunks/chunk-W74UL7AY.js.map +7 -0
  23. package/lib/chunks/{monitoring-UIDJS2KA.js → monitoring-LXNVBD3G.js} +2 -2
  24. package/lib/chunks/{rateLimiter-WNWHI3B4.js → rateLimiter-GG5LPWXJ.js} +2 -2
  25. package/lib/chunks/{server-RYGEBS2B.js → server-NODQAE3F.js} +2 -2
  26. package/lib/firebase/crud/aggregate.d.ts +1 -1
  27. package/lib/firebase/index.js +1 -1
  28. package/lib/firebase/index.js.map +3 -3
  29. package/lib/shared/billing/checkoutValidation.d.ts +1 -1
  30. package/lib/shared/billing/createCheckout.d.ts +1 -1
  31. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +2 -2
  32. package/lib/shared/billing/orderWebhook.d.ts +29 -2
  33. package/lib/shared/billing/stripePinned.d.ts +43 -0
  34. package/lib/shared/denoEnv.d.ts +25 -0
  35. package/lib/shared/github.d.ts +0 -8
  36. package/lib/shared/index.js +1 -1
  37. package/lib/shared/logger.d.ts +14 -14
  38. package/lib/shared/utils/external/subscription.d.ts +0 -8
  39. package/lib/shared/utils.d.ts +15 -3
  40. package/lib/supabase/auth/deleteAccount.d.ts +34 -2
  41. package/lib/supabase/crud/create.d.ts +0 -8
  42. package/lib/supabase/crud/entityStore.d.ts +13 -0
  43. package/lib/supabase/crud/update.d.ts +0 -8
  44. package/lib/supabase/index.d.ts +1 -0
  45. package/lib/supabase/index.js +1 -1
  46. package/lib/supabase/index.js.map +4 -4
  47. package/lib/vercel/api/index.js +1 -1
  48. package/lib/vercel/api/index.js.map +3 -3
  49. package/package.json +9 -9
  50. package/src/firebase/auth/getCustomClaims.ts +2 -0
  51. package/src/firebase/auth/getUserAuthStatus.ts +2 -0
  52. package/src/firebase/auth/removeCustomClaims.ts +2 -0
  53. package/src/firebase/auth/setCustomClaims.ts +3 -0
  54. package/src/firebase/baseFunction.ts +5 -2
  55. package/src/firebase/billing/changePlan.ts +6 -5
  56. package/src/firebase/billing/createCustomerPortal.ts +6 -4
  57. package/src/firebase/billing/refreshSubscriptionStatus.ts +7 -5
  58. package/src/firebase/billing/webhookHandler.ts +4 -4
  59. package/src/firebase/crud/aggregate.ts +41 -12
  60. package/src/firebase/crud/bulk.ts +7 -0
  61. package/src/firebase/crud/create.ts +21 -8
  62. package/src/firebase/crud/delete.ts +6 -1
  63. package/src/firebase/crud/get.ts +9 -2
  64. package/src/firebase/crud/list.ts +18 -8
  65. package/src/firebase/crud/update.ts +15 -7
  66. package/src/firebase/helpers/githubAccessHelper.ts +3 -0
  67. package/src/firebase/helpers/githubTeamAccessHelper.ts +1 -0
  68. package/src/firebase/oauth/exchangeToken.ts +4 -0
  69. package/src/firebase/oauth/getConnections.ts +1 -1
  70. package/src/firebase/oauth/githubAccess.ts +3 -0
  71. package/src/firebase/oauth/refreshToken.ts +1 -0
  72. package/src/firebase/scheduled/checkExpiredSubscriptions.ts +4 -1
  73. package/src/shared/ai/classifyAIError.ts +18 -10
  74. package/src/shared/ai/createAIRoute.ts +2 -1
  75. package/src/shared/ai/resolveModelTier.ts +2 -1
  76. package/src/shared/billing/__tests__/createCheckout.test.ts +94 -0
  77. package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +1 -1
  78. package/src/shared/billing/__tests__/webhookHandler.test.ts +108 -0
  79. package/src/shared/billing/checkoutValidation.ts +19 -2
  80. package/src/shared/billing/createCheckout.ts +56 -11
  81. package/src/shared/billing/helpers/subscriptionManagement.ts +14 -10
  82. package/src/shared/billing/orderWebhook.ts +69 -1
  83. package/src/shared/billing/stripeClient.ts +2 -1
  84. package/src/shared/billing/stripePinned.ts +71 -0
  85. package/src/shared/billing/tierWebhookEvents.ts +3 -2
  86. package/src/shared/billing/webhookHandler.ts +5 -1
  87. package/src/shared/crud/bulkCore.ts +3 -2
  88. package/src/shared/denoEnv.ts +29 -0
  89. package/src/shared/email/createEmailRoute.ts +2 -2
  90. package/src/shared/errorHandling.ts +8 -8
  91. package/src/shared/firebase.ts +26 -9
  92. package/src/shared/github.ts +15 -5
  93. package/src/shared/logger.ts +37 -38
  94. package/src/shared/schema.ts +6 -10
  95. package/src/shared/utils/external/date.ts +4 -4
  96. package/src/shared/utils/external/subscription.ts +2 -89
  97. package/src/shared/utils/firebaseHelpers.ts +2 -0
  98. package/src/shared/utils/internal/idempotency.ts +3 -0
  99. package/src/shared/utils/internal/monitoring.ts +6 -5
  100. package/src/shared/utils/internal/validation.ts +2 -0
  101. package/src/shared/utils/schemaValidation.ts +1 -0
  102. package/src/shared/utils/validation.ts +10 -20
  103. package/src/shared/utils.ts +12 -7
  104. package/src/supabase/__tests__/aggregate.test.ts +132 -0
  105. package/src/supabase/auth/__tests__/deleteAccount.test.ts +102 -0
  106. package/src/supabase/auth/deleteAccount.ts +72 -5
  107. package/src/supabase/billing/refreshSubscriptionStatus.ts +6 -5
  108. package/src/supabase/crud/aggregate.ts +85 -72
  109. package/src/supabase/crud/bulk.ts +3 -0
  110. package/src/supabase/crud/create.ts +13 -9
  111. package/src/supabase/crud/delete.ts +2 -1
  112. package/src/supabase/crud/entityStore.ts +1 -1
  113. package/src/supabase/crud/get.ts +2 -1
  114. package/src/supabase/crud/list.ts +23 -17
  115. package/src/supabase/crud/update.ts +9 -6
  116. package/src/supabase/edgeFunction.ts +2 -1
  117. package/src/supabase/email/createEmailFunction.ts +2 -1
  118. package/src/supabase/index.ts +1 -0
  119. package/src/supabase/oauth/exchangeToken.ts +1 -0
  120. package/src/supabase/oauth/getConnections.ts +1 -1
  121. package/src/supabase/oauth/refreshToken.ts +1 -0
  122. package/src/supabase/utils/idempotency.ts +1 -1
  123. package/src/supabase/utils/monitoring.ts +1 -0
  124. package/src/vercel/api/billing/change-plan.ts +6 -5
  125. package/src/vercel/api/billing/refresh-subscription-status.ts +3 -1
  126. package/src/vercel/api/crud/bulk.ts +7 -2
  127. package/src/vercel/api/crud/create.ts +6 -3
  128. package/src/vercel/api/crud/delete.ts +5 -2
  129. package/src/vercel/api/crud/get.ts +5 -2
  130. package/src/vercel/api/crud/list.ts +6 -3
  131. package/src/vercel/api/crud/update.ts +6 -3
  132. package/src/vercel/api/oauth/check-github-access.ts +1 -0
  133. package/src/vercel/api/oauth/exchange-token.ts +5 -2
  134. package/src/vercel/api/oauth/grant-github-access.ts +1 -0
  135. package/src/vercel/api/oauth/revoke-github-access.ts +1 -0
  136. package/src/vercel/baseFunction.ts +5 -1
  137. package/lib/chunks/chunk-2A4FPYNB.js.map +0 -7
  138. package/lib/chunks/chunk-2IFFIUFV.js +0 -23
  139. package/lib/chunks/chunk-2IFFIUFV.js.map +0 -7
  140. package/lib/chunks/chunk-FQSQGOBN.js +0 -22
  141. package/lib/chunks/chunk-FQSQGOBN.js.map +0 -7
  142. package/lib/chunks/chunk-G4FO76EA.js +0 -22
  143. package/lib/chunks/chunk-G4FO76EA.js.map +0 -7
  144. package/lib/chunks/chunk-LSM5Y2E5.js +0 -22
  145. package/lib/chunks/chunk-LSM5Y2E5.js.map +0 -7
  146. package/lib/chunks/chunk-M4JV2JCF.js +0 -22
  147. package/lib/chunks/chunk-M4JV2JCF.js.map +0 -7
  148. package/lib/chunks/chunk-OZX5ZG44.js +0 -22
  149. package/lib/chunks/chunk-PWAGW4R6.js +0 -22
  150. package/lib/chunks/chunk-PWAGW4R6.js.map +0 -7
  151. package/lib/chunks/chunk-UYI56E6Q.js +0 -151
  152. package/lib/chunks/chunk-UYI56E6Q.js.map +0 -7
  153. package/lib/chunks/chunk-ZVHC2CAV.js +0 -22
  154. package/lib/chunks/chunk-ZVHC2CAV.js.map +0 -7
  155. package/lib/shared/utils/functionWrapper.d.ts +0 -36
  156. package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -122
  157. package/src/shared/utils/functionWrapper.ts +0 -73
  158. /package/lib/chunks/{chunk-PJCJ5H2O.js.map → chunk-UH445BGK.js.map} +0 -0
  159. /package/lib/chunks/{monitoring-UIDJS2KA.js.map → monitoring-LXNVBD3G.js.map} +0 -0
  160. /package/lib/chunks/{rateLimiter-WNWHI3B4.js.map → rateLimiter-GG5LPWXJ.js.map} +0 -0
  161. /package/lib/chunks/{server-RYGEBS2B.js.map → server-NODQAE3F.js.map} +0 -0
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  import { logger } from 'firebase-functions/v2';
13
- import { onRequest } from 'firebase-functions/v2/https';
13
+ import { onRequest, type Request } from 'firebase-functions/v2/https';
14
14
  import type { HttpsFunction } from 'firebase-functions/v2/https';
15
15
 
16
16
  import type { StripeBackConfig } from '@donotdev/core/server';
@@ -31,10 +31,10 @@ import { stripeSecretKey, stripeWebhookSecret } from '../config/secrets.js'; //
31
31
  /**
32
32
  * Read raw body from request stream
33
33
  */
34
- async function getRawBody(req: any): Promise<Buffer> {
34
+ async function getRawBody(req: Request): Promise<Buffer> {
35
35
  // If rawBody is already available, use it
36
- if ((req as any).rawBody && Buffer.isBuffer((req as any).rawBody)) {
37
- return (req as any).rawBody;
36
+ if (req.rawBody && Buffer.isBuffer(req.rawBody)) {
37
+ return req.rawBody;
38
38
  }
39
39
 
40
40
  // Otherwise, read from stream
@@ -37,6 +37,7 @@ export interface MetricDefinition {
37
37
  filter?: {
38
38
  field: string;
39
39
  operator: '==' | '!=' | '>' | '<' | '>=' | '<=';
40
+ // 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)
40
41
  value: any;
41
42
  };
42
43
  }
@@ -56,12 +57,14 @@ export interface AggregateConfig {
56
57
  /** Group by configurations */
57
58
  groupBy?: GroupByDefinition[];
58
59
  /** Optional global filters */
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported request type; consumers reading where values would get unknown (breaking)
59
61
  where?: Array<[string, any, any]>;
60
62
  }
61
63
 
62
64
  /** Request schema for aggregate function */
63
65
  interface AggregateRequest {
64
66
  /** Optional runtime filters (merged with config filters) */
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported request type; consumers reading where values would get unknown (breaking)
65
68
  where?: Array<[string, any, any]>;
66
69
  /** Optional date range filter */
67
70
  dateRange?: {
@@ -75,12 +78,34 @@ interface AggregateRequest {
75
78
  * Extracts visibility from a Valibot field schema
76
79
  */
77
80
  function getFieldVisibilityFromSchema(
78
- schema: any,
81
+ schema: unknown,
79
82
  fieldName: string
80
- ): string | undefined {
81
- if (!schema?.entries?.[fieldName]) return undefined;
82
- const field = schema.entries[fieldName];
83
- return field?.visibility;
83
+ ): unknown {
84
+ if (typeof schema !== 'object' || schema === null) return undefined;
85
+ if (!('entries' in schema)) return undefined;
86
+ const { entries } = schema;
87
+ if (typeof entries !== 'object' || entries === null) return undefined;
88
+ const field: unknown = (entries as Record<string, unknown>)[fieldName];
89
+ if (!field || (typeof field !== 'object' && typeof field !== 'function')) {
90
+ return undefined;
91
+ }
92
+ return 'visibility' in field ? field.visibility : undefined;
93
+ }
94
+
95
+ /** Visibility levels understood by {@link isFieldVisible}. */
96
+ type FieldVisibility = NonNullable<Parameters<typeof isFieldVisible>[1]>;
97
+
98
+ const FIELD_VISIBILITY_LEVELS: readonly string[] = [
99
+ 'guest',
100
+ 'user',
101
+ 'admin',
102
+ 'technical',
103
+ 'hidden',
104
+ 'owner',
105
+ ] satisfies readonly FieldVisibility[];
106
+
107
+ function isFieldVisibility(value: unknown): value is FieldVisibility {
108
+ return typeof value === 'string' && FIELD_VISIBILITY_LEVELS.includes(value);
84
109
  }
85
110
 
86
111
  /**
@@ -88,14 +113,16 @@ function getFieldVisibilityFromSchema(
88
113
  */
89
114
  function canAggregateField(
90
115
  fieldName: string,
91
- schema: any,
116
+ schema: unknown,
92
117
  isAdmin: boolean
93
118
  ): boolean {
94
119
  // '*' is always allowed (count all)
95
120
  if (fieldName === '*') return true;
96
121
 
97
122
  const visibility = getFieldVisibilityFromSchema(schema, fieldName);
98
- return isFieldVisible(fieldName, visibility as any, isAdmin);
123
+ // Unknown visibility levels are denied (same as isFieldVisible's fallback)
124
+ if (visibility !== undefined && !isFieldVisibility(visibility)) return false;
125
+ return isFieldVisible(fieldName, visibility, isAdmin);
99
126
  }
100
127
 
101
128
  /**
@@ -122,13 +149,14 @@ function getPriceOrNumberValue(raw: unknown): number {
122
149
  * For structured price fields uses effective (discounted) price (expected revenue).
123
150
  * Plain numbers are used as-is.
124
151
  */
125
- function getNumericValue(doc: Record<string, any>, field: string): number {
152
+ function getNumericValue(doc: Record<string, unknown>, field: string): number {
126
153
  return getPriceOrNumberValue(doc[field]);
127
154
  }
128
155
 
129
156
  /**
130
157
  * Computes a single metric on a dataset
131
158
  */
159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: filter comparisons rely on JS relational coercion over mixed DB values (null/number/string), which TS rejects on unknown
132
160
  function computeMetric(docs: any[], metric: MetricDefinition): number | null {
133
161
  // Apply metric-level filter if specified
134
162
  let filtered = docs;
@@ -214,7 +242,7 @@ function computeMetric(docs: any[], metric: MetricDefinition): number | null {
214
242
  */
215
243
  function aggregateEntitiesLogicFactory(
216
244
  collection: string,
217
- documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
245
+ documentSchema: v.GenericSchema,
218
246
  config: AggregateConfig
219
247
  ) {
220
248
  return async function aggregateEntitiesLogic(
@@ -282,7 +310,7 @@ function aggregateEntitiesLogicFactory(
282
310
  // Functions (default 256MB memory).
283
311
  const MAX_AGGREGATE_DOCS = 10_000;
284
312
  const snapshot = await query.limit(MAX_AGGREGATE_DOCS).get();
285
- const docs: Record<string, any>[] = snapshot.docs.map((doc) => ({
313
+ const docs: Record<string, unknown>[] = snapshot.docs.map((doc) => ({
286
314
  id: doc.id,
287
315
  ...doc.data(),
288
316
  }));
@@ -302,7 +330,7 @@ function aggregateEntitiesLogicFactory(
302
330
  > = {};
303
331
  if (config.groupBy) {
304
332
  for (const groupConfig of config.groupBy) {
305
- const groupedDocs = new Map<string, any[]>();
333
+ const groupedDocs = new Map<string, Record<string, unknown>[]>();
306
334
 
307
335
  // Group documents by field value
308
336
  for (const doc of docs) {
@@ -390,11 +418,12 @@ function aggregateEntitiesLogicFactory(
390
418
  */
391
419
  export const aggregateEntities = (
392
420
  collection: string,
421
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
393
422
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
394
423
  config: AggregateConfig
395
424
  ) => {
396
425
  const requestSchema = v.object({
397
- where: v.optional(v.array(v.tuple([v.string(), v.any(), v.any()]))),
426
+ where: v.optional(v.array(v.tuple([v.string(), v.unknown(), v.unknown()]))),
398
427
  dateRange: v.optional(
399
428
  v.object({
400
429
  field: v.string(),
@@ -84,13 +84,17 @@ interface BulkAccess {
84
84
  */
85
85
  export function bulkEntityLogicFactory(
86
86
  collection: string,
87
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
87
88
  createSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
88
90
  draftCreateSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
89
92
  updateSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
90
93
  access: BulkAccess
91
94
  ) {
92
95
  return async function bulkEntityLogic(
93
96
  data: BulkEntityRequest,
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: request data is validated by the bulk schema before use; the callable payload type is erased here
94
98
  context: { uid: string; userRole: UserRole; request: CallableRequest<any> }
95
99
  ): Promise<BulkResponse> {
96
100
  const { uid, userRole } = context;
@@ -229,8 +233,11 @@ export function bulkEntityLogicFactory(
229
233
  */
230
234
  export const bulkEntity = (
231
235
  collection: string,
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
232
237
  createSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
238
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
233
239
  draftCreateSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
240
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
234
241
  updateSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
235
242
  access: BulkAccess
236
243
  ): CallableFunction<BulkEntityRequest, Promise<BulkResponse>> => {
@@ -30,6 +30,7 @@ import { createBaseFunction } from '../baseFunction.js';
30
30
  import { CRUD_CONFIG } from '../config/constants.js';
31
31
 
32
32
  export type CreateEntityRequest = {
33
+ // 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)
33
34
  payload: Record<string, any>;
34
35
  idempotencyKey?: string;
35
36
  };
@@ -39,7 +40,11 @@ export type CreateEntityRequest = {
39
40
  */
40
41
  type UniqueKeyCheckResult =
41
42
  | { found: false }
42
- | { found: true; existingDoc: Record<string, any>; findOrCreate: boolean };
43
+ | {
44
+ found: true;
45
+ existingDoc: Record<string, unknown>;
46
+ findOrCreate: boolean;
47
+ };
43
48
 
44
49
  /**
45
50
  * Checks unique key constraints against existing documents
@@ -67,9 +72,9 @@ function normalizeValue(value: unknown): unknown {
67
72
  * Returns a new object with normalized values for unique key fields
68
73
  */
69
74
  function normalizePayloadForUniqueKeys(
70
- payload: Record<string, any>,
75
+ payload: Record<string, unknown>,
71
76
  uniqueKeys: UniqueKeyDefinition[]
72
- ): Record<string, any> {
77
+ ): Record<string, unknown> {
73
78
  const normalized = { ...payload };
74
79
  for (const uniqueKey of uniqueKeys) {
75
80
  for (const field of uniqueKey.fields) {
@@ -83,7 +88,7 @@ function normalizePayloadForUniqueKeys(
83
88
 
84
89
  async function checkUniqueKeys(
85
90
  collection: string,
86
- payload: Record<string, any>,
91
+ payload: Record<string, unknown>,
87
92
  uniqueKeys: UniqueKeyDefinition[],
88
93
  isDraft: boolean
89
94
  ): Promise<UniqueKeyCheckResult> {
@@ -148,12 +153,16 @@ async function checkUniqueKeys(
148
153
  */
149
154
  function createEntityLogicFactory(
150
155
  collection: string,
151
- createDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
152
- draftDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
156
+ createDocumentSchema: v.GenericSchema,
157
+ draftDocumentSchema: v.GenericSchema
153
158
  ) {
154
159
  return async function createEntityLogic(
155
160
  data: CreateEntityRequest,
156
- context: { uid: string; userRole: UserRole; request: CallableRequest<any> }
161
+ context: {
162
+ uid: string;
163
+ userRole: UserRole;
164
+ request: CallableRequest<CreateEntityRequest>;
165
+ }
157
166
  ) {
158
167
  const { payload, idempotencyKey } = data;
159
168
  const { uid } = context;
@@ -304,15 +313,19 @@ function createEntityLogicFactory(
304
313
  */
305
314
  export const createEntity = (
306
315
  collection: string,
316
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
307
317
  createDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
318
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
308
319
  draftDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
309
320
  requiredRole: UserRole,
321
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
310
322
  customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
323
+ // 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)
311
324
  ): CallableFunction<CreateEntityRequest, Promise<any>> => {
312
325
  const requestSchema =
313
326
  customSchema ||
314
327
  v.object({
315
- payload: v.record(v.string(), v.any()),
328
+ payload: v.record(v.string(), v.unknown()),
316
329
  idempotencyKey: v.optional(v.string()),
317
330
  });
318
331
 
@@ -36,7 +36,11 @@ export type DeleteEntityRequest = { id: string };
36
36
  function deleteEntityLogicFactory(collection: string) {
37
37
  return async function deleteEntityLogic(
38
38
  data: DeleteEntityRequest,
39
- context: { uid: string; userRole: UserRole; request: CallableRequest<any> }
39
+ context: {
40
+ uid: string;
41
+ userRole: UserRole;
42
+ request: CallableRequest<DeleteEntityRequest>;
43
+ }
40
44
  ) {
41
45
  const { id } = data;
42
46
 
@@ -74,6 +78,7 @@ function deleteEntityLogicFactory(collection: string) {
74
78
  export const deleteEntity = (
75
79
  collection: string,
76
80
  requiredRole: UserRole,
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
77
82
  customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
78
83
  ): CallableFunction<DeleteEntityRequest, Promise<{ success: boolean }>> => {
79
84
  const requestSchema =
@@ -36,12 +36,16 @@ export type GetEntityRequest = { id: string };
36
36
  */
37
37
  function getEntityLogicFactory(
38
38
  collection: string,
39
- documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
39
+ documentSchema: v.GenericSchema,
40
40
  ownership?: EntityOwnershipConfig
41
41
  ) {
42
42
  return async function getEntityLogic(
43
43
  data: GetEntityRequest,
44
- context: { uid: string; userRole: UserRole; request: CallableRequest<any> }
44
+ context: {
45
+ uid: string;
46
+ userRole: UserRole;
47
+ request: CallableRequest<GetEntityRequest>;
48
+ }
45
49
  ) {
46
50
  const { id } = data;
47
51
  const { userRole, uid } = context;
@@ -100,10 +104,13 @@ function getEntityLogicFactory(
100
104
  */
101
105
  export const getEntity = (
102
106
  collection: string,
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
103
108
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
104
109
  requiredRole: UserRole,
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
105
111
  customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
106
112
  ownership?: EntityOwnershipConfig
113
+ // 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)
107
114
  ): CallableFunction<GetEntityRequest, Promise<any>> => {
108
115
  const requestSchema =
109
116
  customSchema ||
@@ -9,6 +9,7 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import type { WhereFilterOp } from 'firebase-admin/firestore';
12
13
  import { logger } from 'firebase-functions/v2';
13
14
  import type {
14
15
  CallableFunction,
@@ -35,6 +36,7 @@ import { createBaseFunction } from '../baseFunction.js';
35
36
  import { CRUD_READ_CONFIG } from '../config/constants.js';
36
37
 
37
38
  export interface ListEntityRequest {
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported request type; consumers reading where values would get unknown (breaking)
38
40
  where?: Array<[string, any, any]>;
39
41
  orderBy?: Array<[string, 'asc' | 'desc']>;
40
42
  limit?: number;
@@ -54,7 +56,8 @@ function applyPublicCondition(
54
56
  ): Query {
55
57
  let q = query;
56
58
  for (const c of publicCondition) {
57
- q = q.where(c.field, c.op as any, c.value);
59
+ // why: core types publicCondition.op as string; Firestore validates the operator at runtime
60
+ q = q.where(c.field, c.op as WhereFilterOp, c.value);
58
61
  }
59
62
  return q;
60
63
  }
@@ -65,7 +68,7 @@ function applyPublicCondition(
65
68
  */
66
69
  function listEntitiesLogicFactory(
67
70
  collection: string,
68
- documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
71
+ documentSchema: v.GenericSchema,
69
72
  listFields?: string[],
70
73
  ownership?: EntityOwnershipConfig,
71
74
  isListCard?: boolean
@@ -201,7 +204,9 @@ function listEntitiesLogicFactory(
201
204
  const snapshot = await query.get();
202
205
 
203
206
  // Helper: Check if value is a Picture object (has thumbUrl and fullUrl)
204
- const isPictureObject = (value: any): boolean => {
207
+ const isPictureObject = (
208
+ value: unknown
209
+ ): value is { thumbUrl: unknown; fullUrl: unknown } => {
205
210
  return (
206
211
  typeof value === 'object' &&
207
212
  value !== null &&
@@ -211,7 +216,7 @@ function listEntitiesLogicFactory(
211
216
  };
212
217
 
213
218
  // Helper: Optimize picture fields for listCard (only return first picture's thumbUrl)
214
- const optimizePictureField = (value: any): any => {
219
+ const optimizePictureField = (value: unknown): unknown => {
215
220
  if (Array.isArray(value) && value.length > 0) {
216
221
  // Array of pictures - return just the first picture's thumbUrl
217
222
  const firstPicture = value[0];
@@ -233,7 +238,7 @@ function listEntitiesLogicFactory(
233
238
  const visibilityOptions = ownership && uid ? { uid, ownership } : undefined;
234
239
 
235
240
  // Filter document fields based on visibility and user role (uid/userRole from context, once)
236
- const docs = snapshot.docs.map((doc: any) => {
241
+ const docs = snapshot.docs.map((doc) => {
237
242
  const rawData = doc.data() || {};
238
243
  const visibleData = filterVisibleFields(
239
244
  rawData,
@@ -246,7 +251,7 @@ function listEntitiesLogicFactory(
246
251
 
247
252
  // If listFields specified, filter to only those fields (plus id always)
248
253
  if (listFields && listFields.length > 0) {
249
- const filtered: Record<string, any> = { id: doc.id };
254
+ const filtered: Record<string, unknown> = { id: doc.id };
250
255
  for (const field of listFields) {
251
256
  if (field in visibleData) {
252
257
  const value = visibleData[field];
@@ -259,7 +264,7 @@ function listEntitiesLogicFactory(
259
264
 
260
265
  // No listFields restriction, return all visible fields
261
266
  // Still optimize picture fields for all list queries (datatables only need thumbUrl)
262
- const optimizedData: Record<string, any> = { id: doc.id };
267
+ const optimizedData: Record<string, unknown> = { id: doc.id };
263
268
  for (const [key, value] of Object.entries(visibleData)) {
264
269
  optimizedData[key] = optimizePictureField(value);
265
270
  }
@@ -289,17 +294,22 @@ function listEntitiesLogicFactory(
289
294
  */
290
295
  export const listEntities = (
291
296
  collection: string,
297
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
292
298
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
293
299
  requiredRole: UserRole,
300
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
294
301
  customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
295
302
  listFields?: string[],
296
303
  ownership?: EntityOwnershipConfig,
297
304
  isListCard?: boolean
305
+ // 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)
298
306
  ): CallableFunction<ListEntityRequest, Promise<any>> => {
299
307
  const requestSchema =
300
308
  customSchema ||
301
309
  v.object({
302
- where: v.optional(v.array(v.tuple([v.string(), v.any(), v.any()]))),
310
+ where: v.optional(
311
+ v.array(v.tuple([v.string(), v.unknown(), v.unknown()]))
312
+ ),
303
313
  orderBy: v.optional(
304
314
  v.array(v.tuple([v.string(), v.picklist(['asc', 'desc'])]))
305
315
  ),
@@ -31,6 +31,7 @@ import { CRUD_CONFIG } from '../config/constants.js';
31
31
 
32
32
  export type UpdateEntityRequest = {
33
33
  id: string;
34
+ // 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)
34
35
  payload: Record<string, any>;
35
36
  idempotencyKey?: string;
36
37
  };
@@ -51,9 +52,9 @@ function normalizeValue(value: unknown): unknown {
51
52
  * Returns a new object with normalized values for unique key fields
52
53
  */
53
54
  function normalizePayloadForUniqueKeys(
54
- payload: Record<string, any>,
55
+ payload: Record<string, unknown>,
55
56
  uniqueKeys: UniqueKeyDefinition[]
56
- ): Record<string, any> {
57
+ ): Record<string, unknown> {
57
58
  const normalized = { ...payload };
58
59
  for (const uniqueKey of uniqueKeys) {
59
60
  for (const field of uniqueKey.fields) {
@@ -80,8 +81,8 @@ function normalizePayloadForUniqueKeys(
80
81
  async function checkUniqueKeysForUpdate(
81
82
  collection: string,
82
83
  currentDocId: string,
83
- mergedData: Record<string, any>,
84
- payload: Record<string, any>,
84
+ mergedData: Record<string, unknown>,
85
+ payload: Record<string, unknown>,
85
86
  uniqueKeys: UniqueKeyDefinition[],
86
87
  isDraft: boolean
87
88
  ): Promise<void> {
@@ -141,11 +142,15 @@ async function checkUniqueKeysForUpdate(
141
142
  */
142
143
  function updateEntityLogicFactory(
143
144
  collection: string,
144
- documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
145
+ documentSchema: v.GenericSchema
145
146
  ) {
146
147
  return async function updateEntityLogic(
147
148
  data: UpdateEntityRequest,
148
- context: { uid: string; userRole: UserRole; request: CallableRequest<any> }
149
+ context: {
150
+ uid: string;
151
+ userRole: UserRole;
152
+ request: CallableRequest<UpdateEntityRequest>;
153
+ }
149
154
  ) {
150
155
  const { id, payload, idempotencyKey } = data;
151
156
  const { uid } = context;
@@ -291,15 +296,18 @@ function updateEntityLogicFactory(
291
296
  */
292
297
  export const updateEntity = (
293
298
  collection: string,
299
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
294
300
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
295
301
  requiredRole: UserRole,
302
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: accepts schemas of any output type; v.GenericSchema would make InferOutput unknown for callers (breaking)
296
303
  customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
304
+ // 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)
297
305
  ): CallableFunction<UpdateEntityRequest, Promise<any>> => {
298
306
  const requestSchema =
299
307
  customSchema ||
300
308
  v.object({
301
309
  id: v.pipe(v.string(), v.minLength(1)),
302
- payload: v.record(v.string(), v.any()),
310
+ payload: v.record(v.string(), v.unknown()),
303
311
  idempotencyKey: v.optional(v.string()),
304
312
  });
305
313
 
@@ -32,6 +32,7 @@ export async function grantGitHubAccessHelper(
32
32
  githubUsername: string,
33
33
  repoConfig: { owner: string; repo: string },
34
34
  permission: 'pull' | 'triage' | 'push' | 'maintain' | 'admin' = 'pull',
35
+ // 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)
35
36
  customClaims?: Record<string, any>
36
37
  ): Promise<void> {
37
38
  // Get GitHub Personal Access Token
@@ -113,6 +114,7 @@ export async function grantGitHubAccessHelper(
113
114
  export async function getCustomClaimsHelper(
114
115
  userId: string,
115
116
  claimKeys?: string[]
117
+ // 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)
116
118
  ): Promise<Record<string, any>> {
117
119
  // Get user and claims
118
120
  const user = await getFirebaseAdminAuth().getUser(userId);
@@ -140,6 +142,7 @@ export async function getCustomClaimsHelper(
140
142
  */
141
143
  export async function setCustomClaimsHelper(
142
144
  userId: string,
145
+ // 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)
143
146
  claims: Record<string, any>,
144
147
  merge: boolean = true
145
148
  ): Promise<void> {
@@ -196,6 +196,7 @@ export async function checkGitHubTeamAccessHelper(
196
196
  ): Promise<{
197
197
  hasTeamAccess: boolean;
198
198
  hasCustomClaimsAccess: boolean;
199
+ // 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)
199
200
  accessDetails: any;
200
201
  }> {
201
202
  try {
@@ -142,6 +142,7 @@ export const exchangeToken = onCall<ExchangeTokenRequest>(async (request) => {
142
142
  );
143
143
  }
144
144
 
145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: untrusted OAuth token response; needs a valibot schema (strict vs loose expires_in is an open owner decision)
145
146
  const tokenData = (await tokenResponse.json()) as any;
146
147
 
147
148
  // Format the credentials
@@ -210,6 +211,7 @@ export const exchangeToken = onCall<ExchangeTokenRequest>(async (request) => {
210
211
  async function fetchUserProfile(
211
212
  provider: string,
212
213
  accessToken: string
214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: not yet narrowed (any-audit 2026-11-11 follow-up)
213
215
  ): Promise<any> {
214
216
  try {
215
217
  const endpoints = OAUTH_PARTNERS[provider as OAuthPartnerId];
@@ -243,7 +245,9 @@ async function saveOAuthConnection(data: {
243
245
  uid: string;
244
246
  provider: string;
245
247
  purpose: string;
248
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: not yet narrowed (any-audit 2026-11-11 follow-up)
246
249
  credentials: any;
250
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: not yet narrowed (any-audit 2026-11-11 follow-up)
247
251
  profile: any;
248
252
  }): Promise<void> {
249
253
  try {
@@ -44,7 +44,7 @@ export const getConnections = onCall<{ purpose?: OAuthPurpose }>(
44
44
  const snapshot = await query.get();
45
45
 
46
46
  // Format connections
47
- const connections = snapshot.docs.map((doc: any) => {
47
+ const connections = snapshot.docs.map((doc) => {
48
48
  const data = doc.data();
49
49
 
50
50
  // Check if the token is expired
@@ -151,6 +151,7 @@ async function grantGitHubAccessInternal(
151
151
  */
152
152
  export const grantGitHubAccess: CallableFunction<
153
153
  GrantGitHubAccessRequest,
154
+ // 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)
154
155
  Promise<any>
155
156
  > = onCall<GrantGitHubAccessRequest>(
156
157
  OAUTH_CONFIG,
@@ -282,6 +283,7 @@ async function revokeGitHubAccessInternal(
282
283
  */
283
284
  export const revokeGitHubAccess: CallableFunction<
284
285
  RevokeGitHubAccessRequest,
286
+ // 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)
285
287
  Promise<any>
286
288
  > = onCall<RevokeGitHubAccessRequest>(
287
289
  OAUTH_CONFIG,
@@ -393,6 +395,7 @@ async function checkGitHubAccessInternal(
393
395
  */
394
396
  export const checkGitHubAccess: CallableFunction<
395
397
  CheckGitHubAccessRequest,
398
+ // 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)
396
399
  Promise<any>
397
400
  > = onCall<CheckGitHubAccessRequest>(
398
401
  OAUTH_CONFIG,
@@ -85,6 +85,7 @@ export const refreshToken = onCall<OAuthRefreshRequest>(async (request) => {
85
85
  );
86
86
  }
87
87
 
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: untrusted OAuth token response; needs a valibot schema (strict vs loose expires_in is an open owner decision)
88
89
  const tokenData = (await response.json()) as any;
89
90
 
90
91
  // Update the connection in Firestore
@@ -108,7 +108,10 @@ export const checkExpiredSubscriptions = onSchedule(
108
108
  /**
109
109
  * Revoke expired subscription access and clean up claims
110
110
  */
111
- async function revokeExpiredSubscription(userId: string, subscription: any) {
111
+ async function revokeExpiredSubscription(
112
+ userId: string,
113
+ subscription: Record<string, unknown>
114
+ ) {
112
115
  try {
113
116
  const auth = getFirebaseAdminAuth();
114
117
  const user = await auth.getUser(userId);