@donotdev/functions 0.2.1 → 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 (184) hide show
  1. package/README.md +2 -2
  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-EZKRLLSQ.js.map +7 -0
  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-5IPULSUX.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-3F4BWKQD.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-E7JBYBHQ.js → monitoring-LXNVBD3G.js} +2 -2
  24. package/lib/chunks/{rateLimiter-SQISLOP5.js → rateLimiter-GG5LPWXJ.js} +2 -2
  25. package/lib/chunks/server-NODQAE3F.js +22 -0
  26. package/lib/firebase/billing/index.d.ts +2 -2
  27. package/lib/firebase/crud/aggregate.d.ts +1 -1
  28. package/lib/firebase/index.d.ts +1 -1
  29. package/lib/firebase/index.js +1 -1
  30. package/lib/firebase/index.js.map +4 -4
  31. package/lib/firebase/registerCrudFunctions.d.ts +0 -5
  32. package/lib/shared/billing/checkoutPrice.d.ts +3 -6
  33. package/lib/shared/billing/checkoutValidation.d.ts +1 -1
  34. package/lib/shared/billing/createCheckout.d.ts +4 -4
  35. package/lib/shared/billing/firestoreIdempotency.d.ts +2 -2
  36. package/lib/shared/billing/helpers/subscriptionManagement.d.ts +2 -2
  37. package/lib/shared/billing/idempotency.d.ts +3 -23
  38. package/lib/shared/billing/idempotencyContract.d.ts +0 -20
  39. package/lib/shared/billing/orderWebhook.d.ts +29 -2
  40. package/lib/shared/billing/stripePinned.d.ts +43 -0
  41. package/lib/shared/denoEnv.d.ts +25 -0
  42. package/lib/shared/github.d.ts +0 -8
  43. package/lib/shared/index.js +1 -1
  44. package/lib/shared/logger.d.ts +14 -14
  45. package/lib/shared/utils/external/subscription.d.ts +0 -8
  46. package/lib/shared/utils/internal/auth.d.ts +1 -5
  47. package/lib/shared/utils.d.ts +12 -83
  48. package/lib/supabase/auth/deleteAccount.d.ts +34 -2
  49. package/lib/supabase/crud/create.d.ts +0 -8
  50. package/lib/supabase/crud/entityStore.d.ts +13 -0
  51. package/lib/supabase/crud/update.d.ts +0 -8
  52. package/lib/supabase/index.d.ts +1 -0
  53. package/lib/supabase/index.js +1 -1
  54. package/lib/supabase/index.js.map +4 -4
  55. package/lib/vercel/api/index.js +1 -1
  56. package/lib/vercel/api/index.js.map +3 -3
  57. package/package.json +9 -9
  58. package/src/firebase/auth/getCustomClaims.ts +2 -0
  59. package/src/firebase/auth/getUserAuthStatus.ts +2 -0
  60. package/src/firebase/auth/removeCustomClaims.ts +2 -0
  61. package/src/firebase/auth/setCustomClaims.ts +3 -0
  62. package/src/firebase/baseFunction.ts +8 -4
  63. package/src/firebase/billing/changePlan.ts +6 -5
  64. package/src/firebase/billing/createCustomerPortal.ts +6 -4
  65. package/src/firebase/billing/index.d.ts +0 -12
  66. package/src/firebase/billing/index.ts +0 -3
  67. package/src/firebase/billing/refreshSubscriptionStatus.ts +7 -5
  68. package/src/firebase/billing/webhookHandler.ts +4 -4
  69. package/src/firebase/crud/aggregate.ts +41 -12
  70. package/src/firebase/crud/bulk.ts +7 -0
  71. package/src/firebase/crud/create.ts +21 -8
  72. package/src/firebase/crud/delete.ts +6 -1
  73. package/src/firebase/crud/get.ts +9 -2
  74. package/src/firebase/crud/list.ts +18 -8
  75. package/src/firebase/crud/update.ts +15 -7
  76. package/src/firebase/helpers/githubAccessHelper.ts +3 -0
  77. package/src/firebase/helpers/githubTeamAccessHelper.ts +1 -0
  78. package/src/firebase/index.ts +0 -1
  79. package/src/firebase/oauth/disconnect.ts +2 -2
  80. package/src/firebase/oauth/exchangeToken.ts +6 -2
  81. package/src/firebase/oauth/getConnections.ts +3 -3
  82. package/src/firebase/oauth/githubAccess.ts +7 -4
  83. package/src/firebase/oauth/refreshToken.ts +3 -2
  84. package/src/firebase/registerCrudFunctions.ts +0 -19
  85. package/src/firebase/scheduled/checkExpiredSubscriptions.ts +4 -1
  86. package/src/shared/__tests__/idempotency.test.ts +0 -32
  87. package/src/shared/__tests__/utils.test.ts +0 -25
  88. package/src/shared/ai/classifyAIError.ts +18 -10
  89. package/src/shared/ai/createAIRoute.ts +2 -1
  90. package/src/shared/ai/resolveModelTier.ts +2 -1
  91. package/src/shared/billing/__tests__/createCheckout.compat.test.ts +4 -110
  92. package/src/shared/billing/__tests__/createCheckout.test.ts +94 -0
  93. package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +1 -1
  94. package/src/shared/billing/__tests__/webhookHandler.test.ts +108 -0
  95. package/src/shared/billing/checkoutPrice.ts +7 -42
  96. package/src/shared/billing/checkoutValidation.ts +19 -2
  97. package/src/shared/billing/createCheckout.ts +59 -30
  98. package/src/shared/billing/firestoreIdempotency.ts +2 -21
  99. package/src/shared/billing/helpers/subscriptionManagement.ts +14 -10
  100. package/src/shared/billing/idempotency.ts +4 -54
  101. package/src/shared/billing/idempotencyContract.ts +0 -21
  102. package/src/shared/billing/orderWebhook.ts +69 -1
  103. package/src/shared/billing/stripeClient.ts +2 -1
  104. package/src/shared/billing/stripePinned.ts +71 -0
  105. package/src/shared/billing/tierWebhookEvents.ts +3 -2
  106. package/src/shared/billing/webhookHandler.ts +5 -1
  107. package/src/shared/crud/bulkCore.ts +3 -2
  108. package/src/shared/denoEnv.ts +29 -0
  109. package/src/shared/email/createEmailRoute.ts +2 -2
  110. package/src/shared/errorHandling.ts +8 -8
  111. package/src/shared/firebase.ts +26 -9
  112. package/src/shared/github.ts +15 -5
  113. package/src/shared/logger.ts +37 -38
  114. package/src/shared/schema.ts +6 -10
  115. package/src/shared/utils/external/date.ts +4 -4
  116. package/src/shared/utils/external/subscription.ts +2 -89
  117. package/src/shared/utils/firebaseHelpers.ts +2 -0
  118. package/src/shared/utils/internal/auth.ts +1 -6
  119. package/src/shared/utils/internal/idempotency.ts +3 -0
  120. package/src/shared/utils/internal/monitoring.ts +6 -5
  121. package/src/shared/utils/internal/validation.ts +2 -0
  122. package/src/shared/utils/schemaValidation.ts +1 -0
  123. package/src/shared/utils/validation.ts +10 -20
  124. package/src/shared/utils.ts +12 -138
  125. package/src/supabase/__tests__/aggregate.test.ts +132 -0
  126. package/src/supabase/auth/__tests__/deleteAccount.test.ts +102 -0
  127. package/src/supabase/auth/deleteAccount.ts +72 -5
  128. package/src/supabase/billing/refreshSubscriptionStatus.ts +6 -5
  129. package/src/supabase/crud/aggregate.ts +85 -72
  130. package/src/supabase/crud/bulk.ts +3 -0
  131. package/src/supabase/crud/create.ts +13 -9
  132. package/src/supabase/crud/delete.ts +2 -1
  133. package/src/supabase/crud/entityStore.ts +1 -1
  134. package/src/supabase/crud/get.ts +2 -1
  135. package/src/supabase/crud/list.ts +23 -17
  136. package/src/supabase/crud/update.ts +9 -6
  137. package/src/supabase/edgeFunction.ts +2 -1
  138. package/src/supabase/email/createEmailFunction.ts +2 -1
  139. package/src/supabase/index.ts +1 -0
  140. package/src/supabase/oauth/exchangeToken.ts +1 -0
  141. package/src/supabase/oauth/getConnections.ts +1 -1
  142. package/src/supabase/oauth/refreshToken.ts +1 -0
  143. package/src/supabase/utils/idempotency.ts +1 -1
  144. package/src/supabase/utils/monitoring.ts +1 -0
  145. package/src/vercel/api/billing/change-plan.ts +6 -5
  146. package/src/vercel/api/billing/refresh-subscription-status.ts +3 -1
  147. package/src/vercel/api/crud/bulk.ts +7 -2
  148. package/src/vercel/api/crud/create.ts +6 -3
  149. package/src/vercel/api/crud/delete.ts +5 -2
  150. package/src/vercel/api/crud/get.ts +5 -2
  151. package/src/vercel/api/crud/list.ts +6 -3
  152. package/src/vercel/api/crud/update.ts +6 -3
  153. package/src/vercel/api/oauth/check-github-access.ts +1 -0
  154. package/src/vercel/api/oauth/exchange-token.ts +5 -2
  155. package/src/vercel/api/oauth/grant-github-access.ts +1 -0
  156. package/src/vercel/api/oauth/revoke-github-access.ts +1 -0
  157. package/src/vercel/baseFunction.ts +5 -1
  158. package/lib/chunks/chunk-5IPULSUX.js.map +0 -7
  159. package/lib/chunks/chunk-6USHTJED.js +0 -22
  160. package/lib/chunks/chunk-6USHTJED.js.map +0 -7
  161. package/lib/chunks/chunk-CXBSROEW.js +0 -23
  162. package/lib/chunks/chunk-CXBSROEW.js.map +0 -7
  163. package/lib/chunks/chunk-GYTCWMXV.js +0 -22
  164. package/lib/chunks/chunk-GYTCWMXV.js.map +0 -7
  165. package/lib/chunks/chunk-LCDLG4VG.js +0 -151
  166. package/lib/chunks/chunk-LCDLG4VG.js.map +0 -7
  167. package/lib/chunks/chunk-MQANUSY3.js +0 -22
  168. package/lib/chunks/chunk-MQANUSY3.js.map +0 -7
  169. package/lib/chunks/chunk-OFQVO3FD.js +0 -22
  170. package/lib/chunks/chunk-OFQVO3FD.js.map +0 -7
  171. package/lib/chunks/chunk-PWAGW4R6.js +0 -22
  172. package/lib/chunks/chunk-PWAGW4R6.js.map +0 -7
  173. package/lib/chunks/chunk-US2VOP4S.js +0 -22
  174. package/lib/chunks/chunk-US2VOP4S.js.map +0 -7
  175. package/lib/chunks/chunk-YTKDNZNW.js +0 -22
  176. package/lib/chunks/chunk-YTKDNZNW.js.map +0 -7
  177. package/lib/chunks/server-IQ5JNJOM.js +0 -22
  178. package/lib/shared/utils/functionWrapper.d.ts +0 -36
  179. package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -122
  180. package/src/shared/utils/functionWrapper.ts +0 -73
  181. /package/lib/chunks/{chunk-3F4BWKQD.js.map → chunk-UH445BGK.js.map} +0 -0
  182. /package/lib/chunks/{monitoring-E7JBYBHQ.js.map → monitoring-LXNVBD3G.js.map} +0 -0
  183. /package/lib/chunks/{rateLimiter-SQISLOP5.js.map → rateLimiter-GG5LPWXJ.js.map} +0 -0
  184. /package/lib/chunks/{server-IQ5JNJOM.js.map → server-NODQAE3F.js.map} +0 -0
@@ -9,6 +9,7 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import type { SupabaseClient } from '@supabase/supabase-js';
12
13
  import * as v from 'valibot';
13
14
 
14
15
  import { filterVisibleFields } from '@donotdev/core/server';
@@ -24,6 +25,7 @@ const mapper = defaultFieldMapper;
24
25
 
25
26
  /** Request payload for creating an entity with optional idempotency. */
26
27
  export type CreateEntityRequest = {
28
+ // 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)
27
29
  payload: Record<string, any>;
28
30
  idempotencyKey?: string;
29
31
  };
@@ -42,9 +44,9 @@ function normalizeValue(value: unknown): unknown {
42
44
  * Normalize unique key fields in payload to lowercase (for strings)
43
45
  */
44
46
  function normalizePayloadForUniqueKeys(
45
- payload: Record<string, any>,
47
+ payload: Record<string, unknown>,
46
48
  uniqueKeys: UniqueKeyDefinition[]
47
- ): Record<string, any> {
49
+ ): Record<string, unknown> {
48
50
  const normalized = { ...payload };
49
51
  for (const uniqueKey of uniqueKeys) {
50
52
  for (const field of uniqueKey.fields) {
@@ -61,13 +63,13 @@ function normalizePayloadForUniqueKeys(
61
63
  */
62
64
  async function checkUniqueKeys(
63
65
  collection: string,
64
- payload: Record<string, any>,
66
+ payload: Record<string, unknown>,
65
67
  uniqueKeys: UniqueKeyDefinition[],
66
68
  isDraft: boolean,
67
- supabaseAdmin: any
69
+ supabaseAdmin: SupabaseClient
68
70
  ): Promise<
69
71
  | { found: false }
70
- | { found: true; existingDoc: Record<string, any>; findOrCreate: boolean }
72
+ | { found: true; existingDoc: Record<string, unknown>; findOrCreate: boolean }
71
73
  > {
72
74
  for (const uniqueKey of uniqueKeys) {
73
75
  // Skip validation for drafts only if explicitly opted in
@@ -92,7 +94,7 @@ async function checkUniqueKeys(
92
94
  if (!error && existing && existing.length > 0) {
93
95
  const existingDoc = mapper.fromBackendRow(existing[0]) as Record<
94
96
  string,
95
- any
97
+ unknown
96
98
  >;
97
99
 
98
100
  if (uniqueKey.findOrCreate) {
@@ -127,12 +129,14 @@ async function checkUniqueKeys(
127
129
  */
128
130
  export function createSupabaseCreateEntity(
129
131
  collection: string,
132
+ // 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)
130
133
  createDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
134
+ // 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)
131
135
  draftDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
132
136
  requiredRole: UserRole
133
137
  ) {
134
138
  const requestSchema = v.object({
135
- payload: v.record(v.string(), v.any()),
139
+ payload: v.record(v.string(), v.unknown()),
136
140
  idempotencyKey: v.optional(v.string()),
137
141
  });
138
142
 
@@ -145,7 +149,7 @@ export function createSupabaseCreateEntity(
145
149
 
146
150
  // Idempotency check if key provided
147
151
  if (idempotencyKey) {
148
- const cachedResult = await checkIdempotency<any>(
152
+ const cachedResult = await checkIdempotency<unknown>(
149
153
  supabaseAdmin,
150
154
  idempotencyKey,
151
155
  'create'
@@ -233,7 +237,7 @@ export function createSupabaseCreateEntity(
233
237
 
234
238
  const result = mapper.fromBackendRow(
235
239
  inserted as Record<string, unknown>
236
- ) as Record<string, any>;
240
+ ) as Record<string, unknown>;
237
241
 
238
242
  // Store result for idempotency if key provided
239
243
  if (idempotencyKey) {
@@ -9,6 +9,7 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import type { SupabaseClient } from '@supabase/supabase-js';
12
13
  import * as v from 'valibot';
13
14
 
14
15
  import type { UserRole } from '@donotdev/core/server';
@@ -47,7 +48,7 @@ export interface ReferenceMetadata {
47
48
  * @returns Array of reference information
48
49
  */
49
50
  async function findReferences(
50
- supabaseAdmin: any,
51
+ supabaseAdmin: SupabaseClient,
51
52
  collection: string,
52
53
  docId: string,
53
54
  referenceMetadata?: ReferenceMetadata
@@ -73,7 +73,7 @@ export interface EntityStore<Row> {
73
73
  const SAFE_FIELD_NAME = /^[a-zA-Z][a-zA-Z0-9_]*$/;
74
74
 
75
75
  /** The PostgREST filter builder methods the store uses. */
76
- interface Filterable {
76
+ export interface Filterable {
77
77
  eq(column: string, value: unknown): this;
78
78
  neq(column: string, value: unknown): this;
79
79
  gt(column: string, value: unknown): this;
@@ -40,6 +40,7 @@ export type GetEntityRequest = { id: string };
40
40
  */
41
41
  export function createSupabaseGetEntity(
42
42
  collection: string,
43
+ // 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)
43
44
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
44
45
  requiredRole: UserRole,
45
46
  ownership?: EntityOwnershipConfig
@@ -84,7 +85,7 @@ export function createSupabaseGetEntity(
84
85
  : defaultFieldMapper;
85
86
  const normalized = entityMapper.fromBackendRow(row) as Record<
86
87
  string,
87
- any
88
+ unknown
88
89
  >;
89
90
 
90
91
  const visibilityOptions =
@@ -31,6 +31,7 @@ import {
31
31
 
32
32
  import { DoNotDevError } from '../../shared/utils.js';
33
33
  import { createSupabaseHandler } from '../baseFunction.js';
34
+ import type { Filterable } from './entityStore.js';
34
35
 
35
36
  /** Field mapper: app (camelCase) ↔ backend (snake_case). Single boundary for list handler. */
36
37
  const mapper = defaultFieldMapper;
@@ -44,6 +45,7 @@ function toBackendColumn(field: unknown): string {
44
45
 
45
46
  /** Request payload for listing entities with filtering, sorting, and pagination. */
46
47
  export interface ListEntityRequest {
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: exported request type; consumers reading where values would get unknown (breaking)
47
49
  where?: Array<[string, any, any]>;
48
50
  orderBy?: Array<[string, 'asc' | 'desc']>;
49
51
  limit?: number;
@@ -58,7 +60,7 @@ export interface ListEntityRequest {
58
60
  /**
59
61
  * Encode cursor for keyset pagination
60
62
  */
61
- function encodeCursor(id: string, orderBy: Record<string, any>): string {
63
+ function encodeCursor(id: unknown, orderBy: Record<string, unknown>): string {
62
64
  const cursor = { id, orderBy };
63
65
  return Buffer.from(JSON.stringify(cursor)).toString('base64');
64
66
  }
@@ -68,7 +70,7 @@ function encodeCursor(id: string, orderBy: Record<string, any>): string {
68
70
  */
69
71
  function decodeCursor(cursor: string): {
70
72
  id: string;
71
- orderBy: Record<string, any>;
73
+ orderBy: Record<string, unknown>;
72
74
  } {
73
75
  try {
74
76
  const parsed = JSON.parse(Buffer.from(cursor, 'base64').toString());
@@ -95,12 +97,12 @@ function decodeCursor(cursor: string): {
95
97
  const SAFE_FIELD_NAME = /^[a-zA-Z][a-zA-Z0-9_]*$/;
96
98
 
97
99
  /** Apply operator; column must already be backend (snake_case) name. */
98
- function applyOperator(
99
- query: any,
100
+ function applyOperator<Q extends Filterable>(
101
+ query: Q,
100
102
  column: string,
101
103
  operator: string,
102
- value: any
103
- ): any {
104
+ value: unknown
105
+ ): Q {
104
106
  if (!SAFE_FIELD_NAME.test(column)) {
105
107
  throw new DoNotDevError(
106
108
  `Invalid field name: '${column}'`,
@@ -133,10 +135,10 @@ function applyOperator(
133
135
  }
134
136
  }
135
137
 
136
- function applyPublicCondition(
137
- query: any,
138
+ function applyPublicCondition<Q extends Filterable>(
139
+ query: Q,
138
140
  publicCondition: EntityOwnershipPublicCondition[]
139
- ): any {
141
+ ): Q {
140
142
  let q = query;
141
143
  for (const c of publicCondition) {
142
144
  q = applyOperator(q, toBackendColumn(c.field), c.op, c.value);
@@ -157,6 +159,7 @@ function applyPublicCondition(
157
159
  */
158
160
  export function createSupabaseListEntities(
159
161
  collection: string,
162
+ // 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)
160
163
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
161
164
  requiredRole: UserRole,
162
165
  listFields?: string[],
@@ -164,7 +167,7 @@ export function createSupabaseListEntities(
164
167
  isListCard?: boolean
165
168
  ) {
166
169
  const requestSchema = v.object({
167
- where: v.optional(v.array(v.tuple([v.string(), v.any(), v.any()]))),
170
+ where: v.optional(v.array(v.tuple([v.string(), v.unknown(), v.unknown()]))),
168
171
  orderBy: v.optional(
169
172
  v.array(
170
173
  v.tuple([
@@ -339,7 +342,8 @@ export function createSupabaseListEntities(
339
342
  );
340
343
  }
341
344
 
342
- let items = (rows || []) as Record<string, any>[];
345
+ // why: non-literal select string types rows as GenericStringError[]; rows are plain objects
346
+ let items = (rows || []) as unknown as Record<string, unknown>[];
343
347
 
344
348
  // Filter out cursor item for keyset pagination.
345
349
  // Note: items are still raw DB rows here (pre-normalization), so mapper.toBackendField
@@ -362,7 +366,9 @@ export function createSupabaseListEntities(
362
366
  }
363
367
 
364
368
  // Helper: Check if value is a Picture object
365
- const isPictureObject = (value: any): boolean => {
369
+ const isPictureObject = (
370
+ value: unknown
371
+ ): value is { thumbUrl: unknown; fullUrl: unknown } => {
366
372
  return (
367
373
  typeof value === 'object' &&
368
374
  value !== null &&
@@ -372,7 +378,7 @@ export function createSupabaseListEntities(
372
378
  };
373
379
 
374
380
  // Helper: Optimize picture fields for listCard (only return first picture's thumbUrl)
375
- const optimizePictureField = (value: any): any => {
381
+ const optimizePictureField = (value: unknown): unknown => {
376
382
  if (Array.isArray(value) && value.length > 0) {
377
383
  const firstPicture = value[0];
378
384
  if (isPictureObject(firstPicture)) {
@@ -402,7 +408,7 @@ export function createSupabaseListEntities(
402
408
  const filteredItems = items.map((row) => {
403
409
  const camelRow = entityMapper.fromBackendRow(row) as Record<
404
410
  string,
405
- any
411
+ unknown
406
412
  >;
407
413
  const visibleData = filterVisibleFields(
408
414
  camelRow,
@@ -415,7 +421,7 @@ export function createSupabaseListEntities(
415
421
 
416
422
  // If listFields specified, filter to only those fields (plus id always)
417
423
  if (safeListFields && safeListFields.length > 0) {
418
- const filtered: Record<string, any> = { id: camelRow.id };
424
+ const filtered: Record<string, unknown> = { id: camelRow.id };
419
425
  for (const field of safeListFields) {
420
426
  if (field in visibleData) {
421
427
  const value = visibleData[field];
@@ -426,7 +432,7 @@ export function createSupabaseListEntities(
426
432
  }
427
433
 
428
434
  // No listFields restriction, return all visible fields (optimize pictures)
429
- const optimizedData: Record<string, any> = { id: camelRow.id };
435
+ const optimizedData: Record<string, unknown> = { id: camelRow.id };
430
436
  for (const [key, value] of Object.entries(visibleData)) {
431
437
  optimizedData[key] = optimizePictureField(value);
432
438
  }
@@ -442,7 +448,7 @@ export function createSupabaseListEntities(
442
448
  if (useKeysetPagination && orderBy.length > 0) {
443
449
  // Create cursor from last item's orderBy field + id
444
450
  const firstOrderField = orderBy[0][0];
445
- const orderByValue: Record<string, any> = {};
451
+ const orderByValue: Record<string, unknown> = {};
446
452
  orderByValue[firstOrderField] = lastItem[firstOrderField];
447
453
  lastVisible = encodeCursor(lastItem.id, orderByValue);
448
454
  } else if (useKeysetPagination) {
@@ -9,6 +9,7 @@
9
9
  * @author AMBROISE PARK Consulting
10
10
  */
11
11
 
12
+ import type { SupabaseClient } from '@supabase/supabase-js';
12
13
  import * as v from 'valibot';
13
14
 
14
15
  import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
@@ -24,6 +25,7 @@ const mapper = defaultFieldMapper;
24
25
  /** Request payload for updating an entity by ID with optional idempotency. */
25
26
  export type UpdateEntityRequest = {
26
27
  id: string;
28
+ // 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)
27
29
  payload: Record<string, any>;
28
30
  idempotencyKey?: string;
29
31
  };
@@ -44,10 +46,10 @@ function normalizeValue(value: unknown): unknown {
44
46
  async function checkUniqueKeys(
45
47
  collection: string,
46
48
  id: string,
47
- payload: Record<string, any>,
49
+ payload: Record<string, unknown>,
48
50
  uniqueKeys: UniqueKeyDefinition[],
49
51
  isDraft: boolean,
50
- supabaseAdmin: any
52
+ supabaseAdmin: SupabaseClient
51
53
  ): Promise<void> {
52
54
  for (const uniqueKey of uniqueKeys) {
53
55
  if (isDraft && uniqueKey.skipForDrafts === true) continue;
@@ -100,12 +102,13 @@ async function checkUniqueKeys(
100
102
  */
101
103
  export function createSupabaseUpdateEntity(
102
104
  collection: string,
105
+ // 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
106
  documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
104
107
  requiredRole: UserRole
105
108
  ) {
106
109
  const requestSchema = v.object({
107
110
  id: v.pipe(v.string(), v.minLength(1)),
108
- payload: v.record(v.string(), v.any()),
111
+ payload: v.record(v.string(), v.unknown()),
109
112
  idempotencyKey: v.optional(v.string()),
110
113
  });
111
114
 
@@ -118,7 +121,7 @@ export function createSupabaseUpdateEntity(
118
121
 
119
122
  // Idempotency check if key provided
120
123
  if (idempotencyKey) {
121
- const cachedResult = await checkIdempotency<any>(
124
+ const cachedResult = await checkIdempotency<unknown>(
122
125
  supabaseAdmin,
123
126
  idempotencyKey,
124
127
  'update'
@@ -143,7 +146,7 @@ export function createSupabaseUpdateEntity(
143
146
  // `payload` arrives from the client in camelCase. The merge produces a camelCase object
144
147
  // which is later converted back to snake_case via toBackendKeys before the UPDATE query.
145
148
  const merged = {
146
- ...(mapper.fromBackendRow(existing) as Record<string, any>),
149
+ ...(mapper.fromBackendRow(existing) as Record<string, unknown>),
147
150
  ...payload,
148
151
  };
149
152
  const status = merged.status ?? existing.status;
@@ -204,7 +207,7 @@ export function createSupabaseUpdateEntity(
204
207
  );
205
208
  }
206
209
 
207
- const result = mapper.fromBackendRow(updated) as Record<string, any>;
210
+ const result = mapper.fromBackendRow(updated) as Record<string, unknown>;
208
211
 
209
212
  // Store result for idempotency if key provided
210
213
  if (idempotencyKey) {
@@ -15,6 +15,7 @@
15
15
 
16
16
  import { createClient } from '@supabase/supabase-js';
17
17
  import type { SupabaseClient } from '@supabase/supabase-js';
18
+ import { getDenoEnv } from '../shared/denoEnv.js';
18
19
 
19
20
  // =============================================================================
20
21
  // Types
@@ -190,7 +191,7 @@ function jsonResponse(
190
191
 
191
192
  function getEnv(key: string): string {
192
193
  if (typeof globalThis !== 'undefined' && 'Deno' in globalThis) {
193
- return (globalThis as any).Deno?.env?.get(key) ?? '';
194
+ return getDenoEnv()?.get(key) ?? '';
194
195
  }
195
196
  return typeof process !== 'undefined' ? (process.env[key] ?? '') : '';
196
197
  }
@@ -16,6 +16,7 @@ import { SendEmailRequestSchema } from '@donotdev/core/server';
16
16
  import { handleEmailRequest } from '../../shared/email/index.js';
17
17
  import { createResendProvider } from '../../shared/email/resendProvider.js';
18
18
  import { createSupabaseHandler } from '../baseFunction.js';
19
+ import { getDenoEnv } from '../../shared/denoEnv.js';
19
20
 
20
21
  /**
21
22
  * Create a Supabase Edge Function handler for sending emails.
@@ -66,7 +67,7 @@ export function createEmailFunction(config: EmailRouteConfig) {
66
67
 
67
68
  function getEnv(name: string): string | undefined {
68
69
  if (typeof globalThis !== 'undefined' && 'Deno' in globalThis) {
69
- return (globalThis as any).Deno?.env?.get(name);
70
+ return getDenoEnv()?.get(name);
70
71
  }
71
72
  return typeof process !== 'undefined' ? process.env[name] : undefined;
72
73
  }
@@ -23,6 +23,7 @@ export { createSupabaseAuthProvider } from './helpers/authProvider.js';
23
23
 
24
24
  // Auth
25
25
  export { createDeleteAccount } from './auth/deleteAccount.js';
26
+ export type { DeleteAccountOptions } from './auth/deleteAccount.js';
26
27
  export { createSetCustomClaims } from './auth/setCustomClaims.js';
27
28
  export type { SetCustomClaimsOptions } from './auth/setCustomClaims.js';
28
29
  export { createGetCustomClaims } from './auth/getCustomClaims.js';
@@ -122,6 +122,7 @@ export function createExchangeToken() {
122
122
  );
123
123
  }
124
124
 
125
+ // 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)
125
126
  const tokenData = (await tokenResponse.json()) as any;
126
127
 
127
128
  // Format credentials
@@ -58,7 +58,7 @@ export function createGetConnections() {
58
58
  throw new Error(`Failed to get connections: ${error.message}`);
59
59
  }
60
60
 
61
- const connections = (rows || []).map((row: any) => {
61
+ const connections = (rows || []).map((row) => {
62
62
  const isExpired = row.credentials?.expiresAt
63
63
  ? row.credentials.expiresAt < Math.floor(Date.now() / 1000)
64
64
  : false;
@@ -94,6 +94,7 @@ export function createRefreshToken() {
94
94
  throw new Error(`Failed to refresh token: ${response.status}`);
95
95
  }
96
96
 
97
+ // 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)
97
98
  const tokenData = (await response.json()) as any;
98
99
 
99
100
  const credentials = {
@@ -95,7 +95,7 @@ export async function storeIdempotency<T>(
95
95
  id,
96
96
  operation,
97
97
  idempotency_key: idempotencyKey,
98
- result: result as any,
98
+ result,
99
99
  processed_by: uid,
100
100
  expires_at: expiresAt.toISOString(),
101
101
  },
@@ -19,6 +19,7 @@ export interface OperationMetrics {
19
19
  userId?: string;
20
20
  status: 'success' | 'failed' | 'pending';
21
21
  durationMs?: number;
22
+ // 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)
22
23
  metadata?: Record<string, any>;
23
24
  errorCode?: string;
24
25
  errorMessage?: string;
@@ -19,6 +19,7 @@ import { updateUserSubscription } from '../../../shared/billing/helpers/updateUs
19
19
  import { handleError } from '../../../shared/errorHandling.js';
20
20
  import { stripe, validateStripeEnvironment } from '../../../shared/billing/stripeClient.js';
21
21
  import { createVercelBaseFunction } from '../../baseFunction.js';
22
+ import { isOneOf, pinnedSubscriptionPeriod } from '../../../shared/billing/stripePinned.js';
22
23
 
23
24
  const changePlanSchema = v.object({
24
25
  userId: v.string(),
@@ -86,8 +87,8 @@ async function changePlanLogic(
86
87
  'trialing',
87
88
  'incomplete',
88
89
  ] as const;
89
- const status = validStatuses.includes(updatedSubscription.status as any)
90
- ? (updatedSubscription.status as (typeof validStatuses)[number])
90
+ const status = isOneOf(validStatuses, updatedSubscription.status)
91
+ ? updatedSubscription.status
91
92
  : 'incomplete';
92
93
 
93
94
  // Update Firebase Auth
@@ -97,9 +98,9 @@ async function changePlanLogic(
97
98
  tier: billingItem.tier,
98
99
  status,
99
100
  subscriptionEnd: new Date(
100
- (updatedSubscription as any).current_period_end * 1000
101
+ pinnedSubscriptionPeriod(updatedSubscription).current_period_end * 1000
101
102
  ).toISOString(),
102
- cancelAtPeriodEnd: (updatedSubscription as any).cancel_at_period_end,
103
+ cancelAtPeriodEnd: updatedSubscription.cancel_at_period_end,
103
104
  subscriptionId: updatedSubscription.id,
104
105
  customerId: updatedSubscription.customer as string,
105
106
  },
@@ -107,7 +108,7 @@ async function changePlanLogic(
107
108
  async getUser(uid: string) {
108
109
  return getFirebaseAdminAuth().getUser(uid);
109
110
  },
110
- async setCustomUserClaims(uid: string, claims: Record<string, any>) {
111
+ async setCustomUserClaims(uid: string, claims: Record<string, unknown>) {
111
112
  await getFirebaseAdminAuth().setCustomUserClaims(uid, claims);
112
113
  },
113
114
  }
@@ -17,6 +17,7 @@ import type { RefreshSubscriptionRequest } from '@donotdev/core/server';
17
17
 
18
18
  import { stripe, validateStripeEnvironment } from '../../../shared/billing/stripeClient.js';
19
19
  import { createVercelBaseFunction } from '../../baseFunction.js';
20
+ import { pinnedSubscriptionPeriod } from '../../../shared/billing/stripePinned.js';
20
21
 
21
22
  const refreshSubscriptionStatusSchema = v.object({
22
23
  userId: v.pipe(v.string(), v.minLength(1, 'User ID is required')),
@@ -76,7 +77,7 @@ async function refreshSubscriptionStatusLogic(
76
77
  customerId: subscription.customer,
77
78
  status: subscription.status,
78
79
  currentPeriodEnd: new Date(
79
- (subscription as any).current_period_end * 1000
80
+ pinnedSubscriptionPeriod(subscription).current_period_end * 1000
80
81
  ).toISOString(),
81
82
  };
82
83
 
@@ -113,6 +114,7 @@ async function refreshSubscriptionStatusLogic(
113
114
  * @author AMBROISE PARK Consulting
114
115
  */
115
116
  const refreshSubscriptionStatus = (
117
+ // 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)
116
118
  customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
117
119
  ) => {
118
120
  const schema = customSchema || refreshSubscriptionStatusSchema;
@@ -29,7 +29,10 @@ import {
29
29
  import type { BulkRequest, BulkResponse } from '@donotdev/core/server';
30
30
 
31
31
  import { executeBulk } from '../../../shared/crud/bulkCore.js';
32
- import { handleError } from '../../../shared/errorHandling.js';
32
+ import {
33
+ DoNotDevError,
34
+ handleError,
35
+ } from '../../../shared/errorHandling.js';
33
36
  import { prepareForFirestore } from '../../../shared/firebase.js';
34
37
  import { createMetadata, updateMetadata } from '../../../shared/metadata.js';
35
38
  import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
@@ -199,7 +202,9 @@ export default async function handler(
199
202
  } catch (error) {
200
203
  try {
201
204
  handleError(error);
202
- } catch (handledError: any) {
205
+ } catch (handledError) {
206
+ // handleError always throws DoNotDevError; narrow for typed access
207
+ if (!(handledError instanceof DoNotDevError)) throw handledError;
203
208
  // BulkCollisionError surfaces as 400 (invalid-argument) because the
204
209
  // caller sent an incoherent payload — same class as schema failure.
205
210
  const isCollision = error instanceof BulkCollisionError;
@@ -13,7 +13,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
13
13
 
14
14
  import type { CreateEntityData } from '@donotdev/core/server';
15
15
 
16
- import { handleError } from '../../../shared/errorHandling.js';
16
+ import { DoNotDevError, handleError } from '../../../shared/errorHandling.js';
17
17
  import {
18
18
  prepareForFirestore,
19
19
  transformFirestoreData,
@@ -37,6 +37,7 @@ export default async function handler(
37
37
  // C1: verify JWT — previously only checked header presence.
38
38
  const uid = await verifyAuthToken(req);
39
39
 
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: the client supplies the validation schema (known limitation W22); typing needs a server-side entity registry
40
41
  const { schema, payload } = req.body as CreateEntityData<any>;
41
42
 
42
43
  if (!schema || !payload) {
@@ -53,7 +54,7 @@ export default async function handler(
53
54
  // Draft handling is schema-driven: `schemas.draft` must convert required
54
55
  // fields into nullish/optional, so we still validate drafts.
55
56
  const payloadForValidation = {
56
- ...(payload as Record<string, any>),
57
+ ...payload,
57
58
  status,
58
59
  };
59
60
  validateDocument(payloadForValidation, schema);
@@ -87,7 +88,9 @@ export default async function handler(
87
88
  } catch (error) {
88
89
  try {
89
90
  handleError(error);
90
- } catch (handledError: any) {
91
+ } catch (handledError) {
92
+ // handleError always throws DoNotDevError; narrow for typed access
93
+ if (!(handledError instanceof DoNotDevError)) throw handledError;
91
94
  const status = handledError.code === 'invalid-argument' ? 400 : 500;
92
95
  return res
93
96
  .status(status)
@@ -13,7 +13,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
13
13
 
14
14
  import type { GetEntityData } from '@donotdev/core/server';
15
15
 
16
- import { handleError } from '../../../shared/errorHandling.js';
16
+ import { DoNotDevError, handleError } from '../../../shared/errorHandling.js';
17
17
  import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
18
18
  import { validateCollectionName } from '../../../shared/utils.js';
19
19
 
@@ -29,6 +29,7 @@ export default async function handler(
29
29
  // C1: verify JWT — previously only checked header presence.
30
30
  const uid = await verifyAuthToken(req);
31
31
 
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: the client supplies the validation schema (known limitation W22); typing needs a server-side entity registry
32
33
  const { schema, id } = req.body as { schema: any; id: string };
33
34
 
34
35
  if (!schema || !id) {
@@ -59,7 +60,9 @@ export default async function handler(
59
60
  } catch (error) {
60
61
  try {
61
62
  handleError(error);
62
- } catch (handledError: any) {
63
+ } catch (handledError) {
64
+ // handleError always throws DoNotDevError; narrow for typed access
65
+ if (!(handledError instanceof DoNotDevError)) throw handledError;
63
66
  const status = handledError.code === 'invalid-argument' ? 400 : 500;
64
67
  return res
65
68
  .status(status)
@@ -14,7 +14,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
14
14
  import { HIDDEN_STATUSES } from '@donotdev/core/server';
15
15
  import type { GetEntityData } from '@donotdev/core/server';
16
16
 
17
- import { handleError } from '../../../shared/errorHandling.js';
17
+ import { DoNotDevError, handleError } from '../../../shared/errorHandling.js';
18
18
  import { transformFirestoreData } from '../../../shared/firebase.js';
19
19
  import { filterVisibleFields } from '../../../shared/schema.js';
20
20
  import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
@@ -32,6 +32,7 @@ export default async function handler(
32
32
  // C1: verify JWT — previously only checked header presence.
33
33
  const uid = await verifyAuthToken(req);
34
34
 
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: the client supplies the validation schema (known limitation W22); typing needs a server-side entity registry
35
36
  const { schema, id } = req.query as unknown as GetEntityData<any>;
36
37
 
37
38
  // G71: Validate query params are strings (Next.js can pass string[] for repeated params)
@@ -78,7 +79,9 @@ export default async function handler(
78
79
  } catch (error) {
79
80
  try {
80
81
  handleError(error);
81
- } catch (handledError: any) {
82
+ } catch (handledError) {
83
+ // handleError always throws DoNotDevError; narrow for typed access
84
+ if (!(handledError instanceof DoNotDevError)) throw handledError;
82
85
  const status = handledError.code === 'invalid-argument' ? 400 : 500;
83
86
  return res
84
87
  .status(status)
@@ -14,7 +14,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
14
14
  import { HIDDEN_STATUSES } from '@donotdev/core/server';
15
15
  import type { ListEntityData } from '@donotdev/core/server';
16
16
 
17
- import { handleError } from '../../../shared/errorHandling.js';
17
+ import { DoNotDevError, handleError } from '../../../shared/errorHandling.js';
18
18
  import { transformFirestoreData } from '../../../shared/firebase.js';
19
19
  import { filterVisibleFields } from '../../../shared/schema.js';
20
20
  import { verifyAuthToken } from '../../../shared/utils/internal/auth.js';
@@ -36,6 +36,7 @@ export default async function handler(
36
36
  schema,
37
37
  limit = 10,
38
38
  offset = 0,
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- why: the client supplies the validation schema (known limitation W22); typing needs a server-side entity registry
39
40
  } = req.query as unknown as ListEntityData<any> & {
40
41
  limit?: string;
41
42
  offset?: string;
@@ -69,7 +70,7 @@ export default async function handler(
69
70
  const snapshot = await query.get();
70
71
 
71
72
  // Transform the documents
72
- const documents = snapshot.docs.map((doc: any) => {
73
+ const documents = snapshot.docs.map((doc) => {
73
74
  const documentData = transformFirestoreData({
74
75
  id: doc.id,
75
76
  ...doc.data(),
@@ -86,7 +87,9 @@ export default async function handler(
86
87
  } catch (error) {
87
88
  try {
88
89
  handleError(error);
89
- } catch (handledError: any) {
90
+ } catch (handledError) {
91
+ // handleError always throws DoNotDevError; narrow for typed access
92
+ if (!(handledError instanceof DoNotDevError)) throw handledError;
90
93
  const status = handledError.code === 'invalid-argument' ? 400 : 500;
91
94
  return res
92
95
  .status(status)