@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.
- package/README.md +1 -1
- package/lib/chunks/chunk-522YXGDA.js +23 -0
- package/lib/chunks/chunk-522YXGDA.js.map +7 -0
- package/lib/chunks/chunk-7ODXXXES.js +151 -0
- package/lib/chunks/chunk-7ODXXXES.js.map +7 -0
- package/lib/chunks/chunk-CP3NNKO5.js +22 -0
- package/lib/chunks/chunk-CP3NNKO5.js.map +7 -0
- package/lib/chunks/{chunk-2A4FPYNB.js → chunk-CVYSXC27.js} +2 -2
- package/lib/chunks/chunk-CVYSXC27.js.map +7 -0
- package/lib/chunks/{chunk-PJCJ5H2O.js → chunk-HZM5X5A7.js} +2 -2
- package/lib/chunks/chunk-ICNQCRLV.js +22 -0
- package/lib/chunks/chunk-ICNQCRLV.js.map +7 -0
- package/lib/chunks/chunk-OAZ2JYSD.js +22 -0
- package/lib/chunks/chunk-OAZ2JYSD.js.map +7 -0
- package/lib/chunks/chunk-OKRR7ST5.js +22 -0
- package/lib/chunks/chunk-OKRR7ST5.js.map +7 -0
- package/lib/chunks/chunk-PDBNKSBQ.js +22 -0
- package/lib/chunks/chunk-PDBNKSBQ.js.map +7 -0
- package/lib/chunks/chunk-TJPJXJEK.js +22 -0
- package/lib/chunks/{chunk-OZX5ZG44.js.map → chunk-TJPJXJEK.js.map} +1 -1
- package/lib/chunks/chunk-W6W4L44F.js +22 -0
- package/lib/chunks/chunk-W6W4L44F.js.map +7 -0
- package/lib/chunks/{monitoring-UIDJS2KA.js → monitoring-UCBNPPW2.js} +2 -2
- package/lib/chunks/{rateLimiter-WNWHI3B4.js → rateLimiter-XKECWM33.js} +2 -2
- package/lib/chunks/{server-RYGEBS2B.js → server-24XGDDO3.js} +2 -2
- package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/firebase/crud/aggregate.d.ts +1 -1
- package/lib/firebase/crud/create.d.ts +22 -1
- package/lib/firebase/crud/update.d.ts +27 -3
- package/lib/firebase/index.js +1 -1
- package/lib/firebase/index.js.map +3 -3
- package/lib/shared/billing/checkoutValidation.d.ts +1 -1
- package/lib/shared/billing/createCheckout.d.ts +1 -1
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +2 -2
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -8
- package/lib/shared/billing/index.d.ts +2 -0
- package/lib/shared/billing/orderWebhook.d.ts +29 -2
- package/lib/shared/billing/stripePinned.d.ts +43 -0
- package/lib/shared/billing/verifyOrderCheckout.d.ts +53 -0
- package/lib/shared/crud/bulkCore.d.ts +38 -10
- package/lib/shared/crud/index.d.ts +1 -0
- package/lib/shared/crud/written.d.ts +21 -0
- package/lib/shared/denoEnv.d.ts +25 -0
- package/lib/shared/github.d.ts +0 -8
- package/lib/shared/index.d.ts +0 -1
- package/lib/shared/index.js +1 -1
- package/lib/shared/logger.d.ts +14 -14
- package/lib/shared/utils/external/subscription.d.ts +0 -8
- package/lib/shared/utils.d.ts +13 -10
- package/lib/supabase/auth/deleteAccount.d.ts +34 -2
- package/lib/supabase/crud/bulk.d.ts +7 -0
- package/lib/supabase/crud/create.d.ts +5 -9
- package/lib/supabase/crud/entityStore.d.ts +67 -14
- package/lib/supabase/crud/update.d.ts +7 -10
- package/lib/supabase/index.d.ts +5 -0
- package/lib/supabase/index.js +1 -1
- package/lib/supabase/index.js.map +4 -4
- package/lib/vercel/api/crud/create.d.ts +6 -1
- package/lib/vercel/api/crud/update.d.ts +8 -1
- package/lib/vercel/api/index.js +1 -1
- package/lib/vercel/api/index.js.map +3 -3
- package/package.json +9 -9
- package/src/firebase/auth/getCustomClaims.ts +2 -0
- package/src/firebase/auth/getUserAuthStatus.ts +2 -0
- package/src/firebase/auth/removeCustomClaims.ts +33 -1
- package/src/firebase/auth/setCustomClaims.ts +6 -0
- package/src/firebase/baseFunction.ts +5 -2
- package/src/firebase/billing/changePlan.ts +6 -5
- package/src/firebase/billing/createCustomerPortal.ts +6 -4
- package/src/firebase/billing/refreshSubscriptionStatus.ts +7 -5
- package/src/firebase/billing/webhookHandler.ts +4 -4
- package/src/firebase/crud/__tests__/bulk.test.ts +50 -1
- package/src/firebase/crud/__tests__/create.test.ts +64 -0
- package/src/firebase/crud/__tests__/update.test.ts +97 -0
- package/src/firebase/crud/aggregate.ts +37 -19
- package/src/firebase/crud/bulk.ts +30 -10
- package/src/firebase/crud/create.ts +40 -26
- package/src/firebase/crud/delete.ts +6 -1
- package/src/firebase/crud/get.ts +12 -14
- package/src/firebase/crud/list.ts +23 -12
- package/src/firebase/crud/update.ts +49 -25
- package/src/firebase/helpers/githubAccessHelper.ts +3 -0
- package/src/firebase/helpers/githubTeamAccessHelper.ts +1 -0
- package/src/firebase/oauth/exchangeToken.ts +4 -0
- package/src/firebase/oauth/getConnections.ts +1 -1
- package/src/firebase/oauth/githubAccess.ts +3 -0
- package/src/firebase/oauth/refreshToken.ts +1 -0
- package/src/firebase/registerCrudFunctions.ts +1 -0
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +4 -1
- package/src/shared/__tests__/bulkCore.test.ts +191 -0
- package/src/shared/__tests__/removeCustomClaims.test.ts +117 -0
- package/src/shared/__tests__/setCustomClaims.test.ts +103 -0
- package/src/shared/__tests__/utils.test.ts +0 -30
- package/src/shared/ai/classifyAIError.ts +18 -10
- package/src/shared/ai/createAIRoute.ts +2 -1
- package/src/shared/ai/resolveModelTier.ts +2 -1
- package/src/shared/billing/__tests__/createCheckout.test.ts +94 -0
- package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +1 -1
- package/src/shared/billing/__tests__/updateUserSubscription.test.ts +139 -0
- package/src/shared/billing/__tests__/verifyOrderCheckout.exports.test.ts +47 -0
- package/src/shared/billing/__tests__/verifyOrderCheckout.supabase.integration.test.ts +107 -0
- package/src/shared/billing/__tests__/verifyOrderCheckout.test.ts +233 -0
- package/src/shared/billing/__tests__/webhookHandler.test.ts +108 -0
- package/src/shared/billing/checkoutValidation.ts +19 -2
- package/src/shared/billing/createCheckout.ts +56 -11
- package/src/shared/billing/helpers/subscriptionManagement.ts +14 -10
- package/src/shared/billing/helpers/updateUserSubscription.ts +10 -14
- package/src/shared/billing/index.ts +2 -0
- package/src/shared/billing/orderWebhook.ts +69 -1
- package/src/shared/billing/stripeClient.ts +2 -1
- package/src/shared/billing/stripePinned.ts +71 -0
- package/src/shared/billing/tierWebhookEvents.ts +3 -2
- package/src/shared/billing/verifyOrderCheckout.ts +142 -0
- package/src/shared/billing/webhookHandler.ts +5 -1
- package/src/shared/crud/bulkCore.ts +112 -82
- package/src/shared/crud/index.ts +1 -0
- package/src/shared/crud/written.ts +56 -0
- package/src/shared/denoEnv.ts +29 -0
- package/src/shared/email/createEmailRoute.ts +2 -2
- package/src/shared/errorHandling.ts +8 -8
- package/src/shared/firebase.ts +26 -9
- package/src/shared/github.ts +15 -5
- package/src/shared/index.d.ts +0 -9
- package/src/shared/index.ts +0 -1
- package/src/shared/logger.ts +37 -38
- package/src/shared/utils/external/date.ts +4 -4
- package/src/shared/utils/external/subscription.ts +2 -89
- package/src/shared/utils/firebaseHelpers.ts +2 -0
- package/src/shared/utils/internal/idempotency.ts +3 -0
- package/src/shared/utils/internal/monitoring.ts +6 -5
- package/src/shared/utils/internal/validation.ts +2 -0
- package/src/shared/utils/schemaValidation.ts +1 -0
- package/src/shared/utils/validation.ts +10 -20
- package/src/shared/utils.ts +4 -42
- package/src/supabase/__tests__/aggregate.test.ts +132 -0
- package/src/supabase/__tests__/bulk.test.ts +60 -2
- package/src/supabase/__tests__/create.test.ts +86 -0
- package/src/supabase/__tests__/entityStore.test.ts +91 -25
- package/src/supabase/__tests__/update.test.ts +107 -0
- package/src/supabase/auth/__tests__/deleteAccount.test.ts +102 -0
- package/src/supabase/auth/deleteAccount.ts +72 -5
- package/src/supabase/auth/removeCustomClaims.ts +7 -2
- package/src/supabase/auth/setCustomClaims.ts +4 -2
- package/src/supabase/billing/refreshSubscriptionStatus.ts +6 -5
- package/src/supabase/crud/aggregate.ts +85 -72
- package/src/supabase/crud/bulk.ts +50 -0
- package/src/supabase/crud/create.ts +27 -33
- package/src/supabase/crud/delete.ts +2 -1
- package/src/supabase/crud/entityStore.ts +107 -18
- package/src/supabase/crud/get.ts +5 -13
- package/src/supabase/crud/list.ts +28 -21
- package/src/supabase/crud/update.ts +29 -24
- package/src/supabase/edgeFunction.ts +2 -1
- package/src/supabase/email/createEmailFunction.ts +2 -1
- package/src/supabase/index.ts +8 -0
- package/src/supabase/oauth/exchangeToken.ts +1 -0
- package/src/supabase/oauth/getConnections.ts +1 -1
- package/src/supabase/oauth/refreshToken.ts +1 -0
- package/src/supabase/registerCrudFunctions.ts +1 -0
- package/src/supabase/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -0
- package/src/vercel/__tests__/bulk.test.ts +16 -8
- package/src/vercel/api/billing/change-plan.ts +6 -5
- package/src/vercel/api/billing/refresh-subscription-status.ts +3 -1
- package/src/vercel/api/crud/bulk.ts +34 -6
- package/src/vercel/api/crud/create.ts +22 -21
- package/src/vercel/api/crud/delete.ts +5 -2
- package/src/vercel/api/crud/get.ts +10 -8
- package/src/vercel/api/crud/list.ts +10 -8
- package/src/vercel/api/crud/update.ts +25 -20
- package/src/vercel/api/oauth/check-github-access.ts +1 -0
- package/src/vercel/api/oauth/exchange-token.ts +5 -2
- package/src/vercel/api/oauth/grant-github-access.ts +1 -0
- package/src/vercel/api/oauth/revoke-github-access.ts +1 -0
- package/src/vercel/baseFunction.ts +5 -1
- package/lib/chunks/chunk-2A4FPYNB.js.map +0 -7
- package/lib/chunks/chunk-2IFFIUFV.js +0 -23
- package/lib/chunks/chunk-2IFFIUFV.js.map +0 -7
- package/lib/chunks/chunk-FQSQGOBN.js +0 -22
- package/lib/chunks/chunk-FQSQGOBN.js.map +0 -7
- package/lib/chunks/chunk-G4FO76EA.js +0 -22
- package/lib/chunks/chunk-G4FO76EA.js.map +0 -7
- package/lib/chunks/chunk-LSM5Y2E5.js +0 -22
- package/lib/chunks/chunk-LSM5Y2E5.js.map +0 -7
- package/lib/chunks/chunk-M4JV2JCF.js +0 -22
- package/lib/chunks/chunk-M4JV2JCF.js.map +0 -7
- package/lib/chunks/chunk-OZX5ZG44.js +0 -22
- package/lib/chunks/chunk-PWAGW4R6.js +0 -22
- package/lib/chunks/chunk-PWAGW4R6.js.map +0 -7
- package/lib/chunks/chunk-UYI56E6Q.js +0 -151
- package/lib/chunks/chunk-UYI56E6Q.js.map +0 -7
- package/lib/chunks/chunk-ZVHC2CAV.js +0 -22
- package/lib/chunks/chunk-ZVHC2CAV.js.map +0 -7
- package/lib/shared/schema.d.ts +0 -56
- package/lib/shared/utils/functionWrapper.d.ts +0 -36
- package/src/shared/__tests__/schema.test.ts +0 -219
- package/src/shared/schema.ts +0 -192
- package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -122
- package/src/shared/utils/functionWrapper.ts +0 -73
- /package/lib/chunks/{chunk-PJCJ5H2O.js.map → chunk-HZM5X5A7.js.map} +0 -0
- /package/lib/chunks/{monitoring-UIDJS2KA.js.map → monitoring-UCBNPPW2.js.map} +0 -0
- /package/lib/chunks/{rateLimiter-WNWHI3B4.js.map → rateLimiter-XKECWM33.js.map} +0 -0
- /package/lib/chunks/{server-RYGEBS2B.js.map → server-24XGDDO3.js.map} +0 -0
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
} from 'firebase-functions/v2/https';
|
|
18
18
|
import * as v from 'valibot';
|
|
19
19
|
|
|
20
|
+
import { prepareCreate } from '@donotdev/core/server';
|
|
20
21
|
import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
|
|
21
22
|
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
22
23
|
|
|
@@ -25,11 +26,13 @@ import {
|
|
|
25
26
|
transformFirestoreData,
|
|
26
27
|
} from '../../shared/index.js';
|
|
27
28
|
import { createMetadata } from '../../shared/index.js';
|
|
28
|
-
import {
|
|
29
|
+
import { writtenOf } from '../../shared/crud/written.js';
|
|
30
|
+
import { DoNotDevError } from '../../shared/utils.js';
|
|
29
31
|
import { createBaseFunction } from '../baseFunction.js';
|
|
30
32
|
import { CRUD_CONFIG } from '../config/constants.js';
|
|
31
33
|
|
|
32
34
|
export type CreateEntityRequest = {
|
|
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)
|
|
33
36
|
payload: Record<string, any>;
|
|
34
37
|
idempotencyKey?: string;
|
|
35
38
|
};
|
|
@@ -39,7 +42,11 @@ export type CreateEntityRequest = {
|
|
|
39
42
|
*/
|
|
40
43
|
type UniqueKeyCheckResult =
|
|
41
44
|
| { found: false }
|
|
42
|
-
| {
|
|
45
|
+
| {
|
|
46
|
+
found: true;
|
|
47
|
+
existingDoc: Record<string, unknown>;
|
|
48
|
+
findOrCreate: boolean;
|
|
49
|
+
};
|
|
43
50
|
|
|
44
51
|
/**
|
|
45
52
|
* Checks unique key constraints against existing documents
|
|
@@ -67,9 +74,9 @@ function normalizeValue(value: unknown): unknown {
|
|
|
67
74
|
* Returns a new object with normalized values for unique key fields
|
|
68
75
|
*/
|
|
69
76
|
function normalizePayloadForUniqueKeys(
|
|
70
|
-
payload: Record<string,
|
|
77
|
+
payload: Record<string, unknown>,
|
|
71
78
|
uniqueKeys: UniqueKeyDefinition[]
|
|
72
|
-
): Record<string,
|
|
79
|
+
): Record<string, unknown> {
|
|
73
80
|
const normalized = { ...payload };
|
|
74
81
|
for (const uniqueKey of uniqueKeys) {
|
|
75
82
|
for (const field of uniqueKey.fields) {
|
|
@@ -83,7 +90,7 @@ function normalizePayloadForUniqueKeys(
|
|
|
83
90
|
|
|
84
91
|
async function checkUniqueKeys(
|
|
85
92
|
collection: string,
|
|
86
|
-
payload: Record<string,
|
|
93
|
+
payload: Record<string, unknown>,
|
|
87
94
|
uniqueKeys: UniqueKeyDefinition[],
|
|
88
95
|
isDraft: boolean
|
|
89
96
|
): Promise<UniqueKeyCheckResult> {
|
|
@@ -142,18 +149,30 @@ async function checkUniqueKeys(
|
|
|
142
149
|
* Generic business logic for creating entities
|
|
143
150
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
144
151
|
*
|
|
145
|
-
*
|
|
152
|
+
* Status rule: a create without status gets `DEFAULT_STATUS_VALUE`; the CRUD rules
|
|
153
|
+
* picks the draft or create schema; the parse output is written, never the raw payload.
|
|
154
|
+
*
|
|
155
|
+
* @param collection - The Firestore collection name
|
|
156
|
+
* @param createDocumentSchema - The create schema (`createSchemas(entity).create`)
|
|
157
|
+
* @param draftDocumentSchema - The draft schema (`createSchemas(entity).draft`)
|
|
158
|
+
* @returns The callable logic (exported for unit tests)
|
|
159
|
+
*
|
|
160
|
+
* @version 0.2.0
|
|
146
161
|
* @since 0.0.1
|
|
147
162
|
* @author AMBROISE PARK Consulting
|
|
148
163
|
*/
|
|
149
|
-
function createEntityLogicFactory(
|
|
164
|
+
export function createEntityLogicFactory(
|
|
150
165
|
collection: string,
|
|
151
|
-
createDocumentSchema: v.
|
|
152
|
-
draftDocumentSchema: v.
|
|
166
|
+
createDocumentSchema: v.GenericSchema,
|
|
167
|
+
draftDocumentSchema: v.GenericSchema
|
|
153
168
|
) {
|
|
154
169
|
return async function createEntityLogic(
|
|
155
170
|
data: CreateEntityRequest,
|
|
156
|
-
context: {
|
|
171
|
+
context: {
|
|
172
|
+
uid: string;
|
|
173
|
+
userRole: UserRole;
|
|
174
|
+
request: CallableRequest<CreateEntityRequest>;
|
|
175
|
+
}
|
|
157
176
|
) {
|
|
158
177
|
const { payload, idempotencyKey } = data;
|
|
159
178
|
const { uid } = context;
|
|
@@ -208,9 +227,9 @@ function createEntityLogicFactory(
|
|
|
208
227
|
}
|
|
209
228
|
}
|
|
210
229
|
|
|
211
|
-
//
|
|
212
|
-
const
|
|
213
|
-
const isDraft =
|
|
230
|
+
// CRUD create rules (core/schemas crud/create), as on the client.
|
|
231
|
+
const schemas = { create: createDocumentSchema, draft: draftDocumentSchema };
|
|
232
|
+
const isDraft = prepareCreate(schemas, payload).schemaKey === 'draft';
|
|
214
233
|
|
|
215
234
|
// Check unique keys if schema has metadata with uniqueKeys
|
|
216
235
|
// This handles findOrCreate behavior and duplicate prevention
|
|
@@ -247,21 +266,12 @@ function createEntityLogicFactory(
|
|
|
247
266
|
? normalizePayloadForUniqueKeys(payload, uniqueKeys)
|
|
248
267
|
: payload;
|
|
249
268
|
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
// nullish/optional (so `null` empties don't fail strict `schemas.create`).
|
|
253
|
-
const payloadForValidation = { ...normalizedPayload, status };
|
|
254
|
-
if (isDraft) {
|
|
255
|
-
validateDocument(payloadForValidation, draftDocumentSchema);
|
|
256
|
-
} else {
|
|
257
|
-
validateDocument(payloadForValidation, createDocumentSchema);
|
|
258
|
-
}
|
|
269
|
+
// Store the rules' `written` (resulting status included), never the raw payload.
|
|
270
|
+
const written = writtenOf(prepareCreate(schemas, normalizedPayload), collection, 'create');
|
|
259
271
|
|
|
260
272
|
// Prepare the document for Firestore and add metadata
|
|
261
|
-
// Always ensure status is set
|
|
262
273
|
const documentData = {
|
|
263
|
-
...prepareForFirestore(
|
|
264
|
-
status, // Ensure status is always present
|
|
274
|
+
...prepareForFirestore(written),
|
|
265
275
|
...createMetadata(uid),
|
|
266
276
|
};
|
|
267
277
|
|
|
@@ -304,15 +314,19 @@ function createEntityLogicFactory(
|
|
|
304
314
|
*/
|
|
305
315
|
export const createEntity = (
|
|
306
316
|
collection: string,
|
|
317
|
+
// 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
318
|
createDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
319
|
+
// 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
320
|
draftDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
309
321
|
requiredRole: UserRole,
|
|
322
|
+
// 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
323
|
customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
|
|
324
|
+
// 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
325
|
): CallableFunction<CreateEntityRequest, Promise<any>> => {
|
|
312
326
|
const requestSchema =
|
|
313
327
|
customSchema ||
|
|
314
328
|
v.object({
|
|
315
|
-
payload: v.record(v.string(), v.
|
|
329
|
+
payload: v.record(v.string(), v.unknown()),
|
|
316
330
|
idempotencyKey: v.optional(v.string()),
|
|
317
331
|
});
|
|
318
332
|
|
|
@@ -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: {
|
|
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 =
|
package/src/firebase/crud/get.ts
CHANGED
|
@@ -15,11 +15,7 @@ import type {
|
|
|
15
15
|
} from 'firebase-functions/v2/https';
|
|
16
16
|
import * as v from 'valibot';
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
filterVisibleFields,
|
|
20
|
-
hasRoleAccess,
|
|
21
|
-
HIDDEN_STATUSES,
|
|
22
|
-
} from '@donotdev/core/server';
|
|
18
|
+
import { filterVisibleFields, isReadableBy } from '@donotdev/core/server';
|
|
23
19
|
import type { EntityOwnershipConfig, UserRole } from '@donotdev/core/server';
|
|
24
20
|
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
25
21
|
|
|
@@ -36,12 +32,16 @@ export type GetEntityRequest = { id: string };
|
|
|
36
32
|
*/
|
|
37
33
|
function getEntityLogicFactory(
|
|
38
34
|
collection: string,
|
|
39
|
-
documentSchema: v.
|
|
35
|
+
documentSchema: v.GenericSchema,
|
|
40
36
|
ownership?: EntityOwnershipConfig
|
|
41
37
|
) {
|
|
42
38
|
return async function getEntityLogic(
|
|
43
39
|
data: GetEntityRequest,
|
|
44
|
-
context: {
|
|
40
|
+
context: {
|
|
41
|
+
uid: string;
|
|
42
|
+
userRole: UserRole;
|
|
43
|
+
request: CallableRequest<GetEntityRequest>;
|
|
44
|
+
}
|
|
45
45
|
) {
|
|
46
46
|
const { id } = data;
|
|
47
47
|
const { userRole, uid } = context;
|
|
@@ -58,14 +58,9 @@ function getEntityLogicFactory(
|
|
|
58
58
|
throw new DoNotDevError('Entity not found', 'not-found');
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Hide drafts/deleted from non-admin users (security: hidden statuses never reach public)
|
|
61
|
+
// CRUD rule 4 (core/schemas crud/read): hidden statuses never reach non-admins
|
|
64
62
|
const docData = doc.data();
|
|
65
|
-
if (
|
|
66
|
-
!isAdmin &&
|
|
67
|
-
(HIDDEN_STATUSES as readonly string[]).includes(docData?.status)
|
|
68
|
-
) {
|
|
63
|
+
if (!isReadableBy(docData, userRole)) {
|
|
69
64
|
throw new DoNotDevError('Entity not found', 'not-found');
|
|
70
65
|
}
|
|
71
66
|
|
|
@@ -100,10 +95,13 @@ function getEntityLogicFactory(
|
|
|
100
95
|
*/
|
|
101
96
|
export const getEntity = (
|
|
102
97
|
collection: string,
|
|
98
|
+
// 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
99
|
documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
104
100
|
requiredRole: UserRole,
|
|
101
|
+
// 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
102
|
customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
106
103
|
ownership?: EntityOwnershipConfig
|
|
104
|
+
// 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
105
|
): CallableFunction<GetEntityRequest, Promise<any>> => {
|
|
108
106
|
const requestSchema =
|
|
109
107
|
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,
|
|
@@ -19,7 +20,7 @@ import * as v from 'valibot';
|
|
|
19
20
|
import {
|
|
20
21
|
filterVisibleFields,
|
|
21
22
|
hasRoleAccess,
|
|
22
|
-
|
|
23
|
+
hiddenStatusesFor,
|
|
23
24
|
} from '@donotdev/core/server';
|
|
24
25
|
import type {
|
|
25
26
|
EntityOwnershipConfig,
|
|
@@ -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
|
-
|
|
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.
|
|
71
|
+
documentSchema: v.GenericSchema,
|
|
69
72
|
listFields?: string[],
|
|
70
73
|
ownership?: EntityOwnershipConfig,
|
|
71
74
|
isListCard?: boolean
|
|
@@ -88,9 +91,10 @@ function listEntitiesLogicFactory(
|
|
|
88
91
|
const db = getFirebaseAdminFirestore();
|
|
89
92
|
let query: Query = db.collection(collection);
|
|
90
93
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
// CRUD rule 4 (core/schemas crud/read): hidden statuses never reach non-admins
|
|
95
|
+
const hidden = hiddenStatusesFor(userRole);
|
|
96
|
+
if (hidden.length > 0) {
|
|
97
|
+
query = query.where('status', 'not-in', [...hidden]);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
// Ownership: when set and not admin, listCard = public condition, list = mine filter
|
|
@@ -201,7 +205,9 @@ function listEntitiesLogicFactory(
|
|
|
201
205
|
const snapshot = await query.get();
|
|
202
206
|
|
|
203
207
|
// Helper: Check if value is a Picture object (has thumbUrl and fullUrl)
|
|
204
|
-
const isPictureObject = (
|
|
208
|
+
const isPictureObject = (
|
|
209
|
+
value: unknown
|
|
210
|
+
): value is { thumbUrl: unknown; fullUrl: unknown } => {
|
|
205
211
|
return (
|
|
206
212
|
typeof value === 'object' &&
|
|
207
213
|
value !== null &&
|
|
@@ -211,7 +217,7 @@ function listEntitiesLogicFactory(
|
|
|
211
217
|
};
|
|
212
218
|
|
|
213
219
|
// Helper: Optimize picture fields for listCard (only return first picture's thumbUrl)
|
|
214
|
-
const optimizePictureField = (value:
|
|
220
|
+
const optimizePictureField = (value: unknown): unknown => {
|
|
215
221
|
if (Array.isArray(value) && value.length > 0) {
|
|
216
222
|
// Array of pictures - return just the first picture's thumbUrl
|
|
217
223
|
const firstPicture = value[0];
|
|
@@ -233,7 +239,7 @@ function listEntitiesLogicFactory(
|
|
|
233
239
|
const visibilityOptions = ownership && uid ? { uid, ownership } : undefined;
|
|
234
240
|
|
|
235
241
|
// Filter document fields based on visibility and user role (uid/userRole from context, once)
|
|
236
|
-
const docs = snapshot.docs.map((doc
|
|
242
|
+
const docs = snapshot.docs.map((doc) => {
|
|
237
243
|
const rawData = doc.data() || {};
|
|
238
244
|
const visibleData = filterVisibleFields(
|
|
239
245
|
rawData,
|
|
@@ -246,7 +252,7 @@ function listEntitiesLogicFactory(
|
|
|
246
252
|
|
|
247
253
|
// If listFields specified, filter to only those fields (plus id always)
|
|
248
254
|
if (listFields && listFields.length > 0) {
|
|
249
|
-
const filtered: Record<string,
|
|
255
|
+
const filtered: Record<string, unknown> = { id: doc.id };
|
|
250
256
|
for (const field of listFields) {
|
|
251
257
|
if (field in visibleData) {
|
|
252
258
|
const value = visibleData[field];
|
|
@@ -259,7 +265,7 @@ function listEntitiesLogicFactory(
|
|
|
259
265
|
|
|
260
266
|
// No listFields restriction, return all visible fields
|
|
261
267
|
// Still optimize picture fields for all list queries (datatables only need thumbUrl)
|
|
262
|
-
const optimizedData: Record<string,
|
|
268
|
+
const optimizedData: Record<string, unknown> = { id: doc.id };
|
|
263
269
|
for (const [key, value] of Object.entries(visibleData)) {
|
|
264
270
|
optimizedData[key] = optimizePictureField(value);
|
|
265
271
|
}
|
|
@@ -289,17 +295,22 @@ function listEntitiesLogicFactory(
|
|
|
289
295
|
*/
|
|
290
296
|
export const listEntities = (
|
|
291
297
|
collection: string,
|
|
298
|
+
// 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
299
|
documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
293
300
|
requiredRole: UserRole,
|
|
301
|
+
// 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
302
|
customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
295
303
|
listFields?: string[],
|
|
296
304
|
ownership?: EntityOwnershipConfig,
|
|
297
305
|
isListCard?: boolean
|
|
306
|
+
// 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
307
|
): CallableFunction<ListEntityRequest, Promise<any>> => {
|
|
299
308
|
const requestSchema =
|
|
300
309
|
customSchema ||
|
|
301
310
|
v.object({
|
|
302
|
-
where: v.optional(
|
|
311
|
+
where: v.optional(
|
|
312
|
+
v.array(v.tuple([v.string(), v.unknown(), v.unknown()]))
|
|
313
|
+
),
|
|
303
314
|
orderBy: v.optional(
|
|
304
315
|
v.array(v.tuple([v.string(), v.picklist(['asc', 'desc'])]))
|
|
305
316
|
),
|
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
} from 'firebase-functions/v2/https';
|
|
17
17
|
import * as v from 'valibot';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { prepareUpdate } from '@donotdev/core/server';
|
|
20
20
|
import type { UserRole, UniqueKeyDefinition } from '@donotdev/core/server';
|
|
21
21
|
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
22
22
|
|
|
@@ -25,12 +25,14 @@ import {
|
|
|
25
25
|
transformFirestoreData,
|
|
26
26
|
} from '../../shared/index.js';
|
|
27
27
|
import { updateMetadata } from '../../shared/index.js';
|
|
28
|
-
import {
|
|
28
|
+
import { writtenOf } from '../../shared/crud/written.js';
|
|
29
|
+
import { DoNotDevError } from '../../shared/utils.js';
|
|
29
30
|
import { createBaseFunction } from '../baseFunction.js';
|
|
30
31
|
import { CRUD_CONFIG } from '../config/constants.js';
|
|
31
32
|
|
|
32
33
|
export type UpdateEntityRequest = {
|
|
33
34
|
id: string;
|
|
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)
|
|
34
36
|
payload: Record<string, any>;
|
|
35
37
|
idempotencyKey?: string;
|
|
36
38
|
};
|
|
@@ -51,9 +53,9 @@ function normalizeValue(value: unknown): unknown {
|
|
|
51
53
|
* Returns a new object with normalized values for unique key fields
|
|
52
54
|
*/
|
|
53
55
|
function normalizePayloadForUniqueKeys(
|
|
54
|
-
payload: Record<string,
|
|
56
|
+
payload: Record<string, unknown>,
|
|
55
57
|
uniqueKeys: UniqueKeyDefinition[]
|
|
56
|
-
): Record<string,
|
|
58
|
+
): Record<string, unknown> {
|
|
57
59
|
const normalized = { ...payload };
|
|
58
60
|
for (const uniqueKey of uniqueKeys) {
|
|
59
61
|
for (const field of uniqueKey.fields) {
|
|
@@ -80,8 +82,8 @@ function normalizePayloadForUniqueKeys(
|
|
|
80
82
|
async function checkUniqueKeysForUpdate(
|
|
81
83
|
collection: string,
|
|
82
84
|
currentDocId: string,
|
|
83
|
-
mergedData: Record<string,
|
|
84
|
-
payload: Record<string,
|
|
85
|
+
mergedData: Record<string, unknown>,
|
|
86
|
+
payload: Record<string, unknown>,
|
|
85
87
|
uniqueKeys: UniqueKeyDefinition[],
|
|
86
88
|
isDraft: boolean
|
|
87
89
|
): Promise<void> {
|
|
@@ -135,17 +137,32 @@ async function checkUniqueKeysForUpdate(
|
|
|
135
137
|
* Generic business logic for updating entities
|
|
136
138
|
* Base function handles: validation, auth, rate limiting, monitoring
|
|
137
139
|
*
|
|
138
|
-
*
|
|
140
|
+
* Status rule: `prepareUpdate` (core/schemas crud/update). An update
|
|
141
|
+
* entering a visible status (`updateCheck`, e.g. a draft published) is checked
|
|
142
|
+
* whole: the merged document against the update schema (`validateWholeDocument`). The
|
|
143
|
+
* parse output of the sent keys is written, never the raw payload.
|
|
144
|
+
*
|
|
145
|
+
* @param collection - The Firestore collection name
|
|
146
|
+
* @param documentSchema - The update schema: validates `{ ...payload, id }` of a non-draft update (the whole merged document when it enters a visible status)
|
|
147
|
+
* @param draftDocumentSchema - The draft schema: validates the merged document of a draft
|
|
148
|
+
* @returns The callable logic (exported for unit tests)
|
|
149
|
+
*
|
|
150
|
+
* @version 0.2.0
|
|
139
151
|
* @since 0.0.1
|
|
140
152
|
* @author AMBROISE PARK Consulting
|
|
141
153
|
*/
|
|
142
|
-
function updateEntityLogicFactory(
|
|
154
|
+
export function updateEntityLogicFactory(
|
|
143
155
|
collection: string,
|
|
144
|
-
documentSchema: v.
|
|
156
|
+
documentSchema: v.GenericSchema,
|
|
157
|
+
draftDocumentSchema: v.GenericSchema
|
|
145
158
|
) {
|
|
146
159
|
return async function updateEntityLogic(
|
|
147
160
|
data: UpdateEntityRequest,
|
|
148
|
-
context: {
|
|
161
|
+
context: {
|
|
162
|
+
uid: string;
|
|
163
|
+
userRole: UserRole;
|
|
164
|
+
request: CallableRequest<UpdateEntityRequest>;
|
|
165
|
+
}
|
|
149
166
|
) {
|
|
150
167
|
const { id, payload, idempotencyKey } = data;
|
|
151
168
|
const { uid } = context;
|
|
@@ -204,18 +221,22 @@ function updateEntityLogicFactory(
|
|
|
204
221
|
|
|
205
222
|
// Check if the document exists
|
|
206
223
|
const doc = await docRef.get();
|
|
207
|
-
|
|
224
|
+
const storedData = doc.data();
|
|
225
|
+
if (!doc.exists || storedData === undefined) {
|
|
208
226
|
throw new DoNotDevError('Entity not found', 'not-found');
|
|
209
227
|
}
|
|
210
228
|
|
|
211
229
|
// Get the current data and merge with the update payload.
|
|
212
230
|
// Note: simple spread merge — concurrent partial updates use last-write-wins, no conflict detection.
|
|
213
|
-
const currentData = transformFirestoreData(
|
|
231
|
+
const currentData = transformFirestoreData(storedData);
|
|
214
232
|
const mergedData = { ...currentData, ...payload };
|
|
215
233
|
|
|
216
|
-
//
|
|
217
|
-
const
|
|
218
|
-
|
|
234
|
+
// CRUD update rules (core/schemas crud/update) on the stored row, as on the client.
|
|
235
|
+
const prepared = prepareUpdate(
|
|
236
|
+
{ draft: draftDocumentSchema, update: documentSchema },
|
|
237
|
+
{ id, patch: payload, stored: currentData }
|
|
238
|
+
);
|
|
239
|
+
const isDraft = prepared.schemaKey === 'draft';
|
|
219
240
|
|
|
220
241
|
// Check unique keys if schema has metadata with uniqueKeys
|
|
221
242
|
// Only checks fields that are being updated
|
|
@@ -235,17 +256,14 @@ function updateEntityLogicFactory(
|
|
|
235
256
|
);
|
|
236
257
|
}
|
|
237
258
|
|
|
238
|
-
//
|
|
239
|
-
|
|
240
|
-
if (!isDraft) {
|
|
241
|
-
validateDocument(mergedData, documentSchema);
|
|
242
|
-
}
|
|
259
|
+
// The rules' `written` (parsed sent keys), never the raw payload.
|
|
260
|
+
const written = writtenOf(prepared, collection, 'update');
|
|
243
261
|
|
|
244
262
|
// Normalize unique key fields to lowercase for case-insensitive storage
|
|
245
263
|
const normalizedPayload =
|
|
246
264
|
uniqueKeys && uniqueKeys.length > 0
|
|
247
|
-
? normalizePayloadForUniqueKeys(
|
|
248
|
-
:
|
|
265
|
+
? normalizePayloadForUniqueKeys(written, uniqueKeys)
|
|
266
|
+
: written;
|
|
249
267
|
|
|
250
268
|
// Prepare the update data for Firestore and add metadata
|
|
251
269
|
const updateData = {
|
|
@@ -284,22 +302,28 @@ function updateEntityLogicFactory(
|
|
|
284
302
|
/**
|
|
285
303
|
* Generic function to update entities in any Firestore collection
|
|
286
304
|
* @param collection - The Firestore collection name
|
|
287
|
-
* @param documentSchema - The
|
|
305
|
+
* @param documentSchema - The update schema (`createSchemas(entity).update`): validates what a non-draft update writes
|
|
306
|
+
* @param draftDocumentSchema - The draft schema (`createSchemas(entity).draft`): validates the resulting document of a draft
|
|
288
307
|
* @param requiredRole - Minimum role required for this operation
|
|
289
308
|
* @param customSchema - Optional custom request schema
|
|
290
309
|
* @returns Firebase callable function
|
|
291
310
|
*/
|
|
292
311
|
export const updateEntity = (
|
|
293
312
|
collection: string,
|
|
313
|
+
// 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
314
|
documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
315
|
+
// 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)
|
|
316
|
+
draftDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>,
|
|
295
317
|
requiredRole: UserRole,
|
|
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)
|
|
296
319
|
customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
|
|
320
|
+
// 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
321
|
): CallableFunction<UpdateEntityRequest, Promise<any>> => {
|
|
298
322
|
const requestSchema =
|
|
299
323
|
customSchema ||
|
|
300
324
|
v.object({
|
|
301
325
|
id: v.pipe(v.string(), v.minLength(1)),
|
|
302
|
-
payload: v.record(v.string(), v.
|
|
326
|
+
payload: v.record(v.string(), v.unknown()),
|
|
303
327
|
idempotencyKey: v.optional(v.string()),
|
|
304
328
|
});
|
|
305
329
|
|
|
@@ -307,7 +331,7 @@ export const updateEntity = (
|
|
|
307
331
|
CRUD_CONFIG,
|
|
308
332
|
requestSchema,
|
|
309
333
|
'update_entity',
|
|
310
|
-
updateEntityLogicFactory(collection, documentSchema),
|
|
334
|
+
updateEntityLogicFactory(collection, documentSchema, draftDocumentSchema),
|
|
311
335
|
requiredRole
|
|
312
336
|
);
|
|
313
337
|
};
|
|
@@ -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
|
|
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(
|
|
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);
|