@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.
- package/README.md +2 -2
- package/lib/chunks/chunk-6NXIK35R.js +23 -0
- package/lib/chunks/chunk-6NXIK35R.js.map +7 -0
- package/lib/chunks/chunk-EZKRLLSQ.js +22 -0
- package/lib/chunks/chunk-EZKRLLSQ.js.map +7 -0
- package/lib/chunks/chunk-F3PHE627.js +22 -0
- package/lib/chunks/chunk-F3PHE627.js.map +7 -0
- package/lib/chunks/chunk-F3WBFWPO.js +151 -0
- package/lib/chunks/chunk-F3WBFWPO.js.map +7 -0
- package/lib/chunks/chunk-G5DRV3DH.js +22 -0
- package/lib/chunks/chunk-G5DRV3DH.js.map +7 -0
- package/lib/chunks/{chunk-5IPULSUX.js → chunk-GDIUOJMD.js} +2 -2
- package/lib/chunks/chunk-GDIUOJMD.js.map +7 -0
- package/lib/chunks/chunk-Q2WLRFOE.js +22 -0
- package/lib/chunks/chunk-Q2WLRFOE.js.map +7 -0
- package/lib/chunks/chunk-QXIOO2RL.js +22 -0
- package/lib/chunks/chunk-QXIOO2RL.js.map +7 -0
- package/lib/chunks/{chunk-3F4BWKQD.js → chunk-UH445BGK.js} +2 -2
- package/lib/chunks/chunk-W6W4L44F.js +22 -0
- package/lib/chunks/chunk-W6W4L44F.js.map +7 -0
- package/lib/chunks/chunk-W74UL7AY.js +22 -0
- package/lib/chunks/chunk-W74UL7AY.js.map +7 -0
- package/lib/chunks/{monitoring-E7JBYBHQ.js → monitoring-LXNVBD3G.js} +2 -2
- package/lib/chunks/{rateLimiter-SQISLOP5.js → rateLimiter-GG5LPWXJ.js} +2 -2
- package/lib/chunks/server-NODQAE3F.js +22 -0
- package/lib/firebase/billing/index.d.ts +2 -2
- package/lib/firebase/crud/aggregate.d.ts +1 -1
- package/lib/firebase/index.d.ts +1 -1
- package/lib/firebase/index.js +1 -1
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/registerCrudFunctions.d.ts +0 -5
- package/lib/shared/billing/checkoutPrice.d.ts +3 -6
- package/lib/shared/billing/checkoutValidation.d.ts +1 -1
- package/lib/shared/billing/createCheckout.d.ts +4 -4
- package/lib/shared/billing/firestoreIdempotency.d.ts +2 -2
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +2 -2
- package/lib/shared/billing/idempotency.d.ts +3 -23
- package/lib/shared/billing/idempotencyContract.d.ts +0 -20
- package/lib/shared/billing/orderWebhook.d.ts +29 -2
- package/lib/shared/billing/stripePinned.d.ts +43 -0
- package/lib/shared/denoEnv.d.ts +25 -0
- package/lib/shared/github.d.ts +0 -8
- 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/internal/auth.d.ts +1 -5
- package/lib/shared/utils.d.ts +12 -83
- package/lib/supabase/auth/deleteAccount.d.ts +34 -2
- package/lib/supabase/crud/create.d.ts +0 -8
- package/lib/supabase/crud/entityStore.d.ts +13 -0
- package/lib/supabase/crud/update.d.ts +0 -8
- package/lib/supabase/index.d.ts +1 -0
- package/lib/supabase/index.js +1 -1
- package/lib/supabase/index.js.map +4 -4
- 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 +2 -0
- package/src/firebase/auth/setCustomClaims.ts +3 -0
- package/src/firebase/baseFunction.ts +8 -4
- package/src/firebase/billing/changePlan.ts +6 -5
- package/src/firebase/billing/createCustomerPortal.ts +6 -4
- package/src/firebase/billing/index.d.ts +0 -12
- package/src/firebase/billing/index.ts +0 -3
- package/src/firebase/billing/refreshSubscriptionStatus.ts +7 -5
- package/src/firebase/billing/webhookHandler.ts +4 -4
- package/src/firebase/crud/aggregate.ts +41 -12
- package/src/firebase/crud/bulk.ts +7 -0
- package/src/firebase/crud/create.ts +21 -8
- package/src/firebase/crud/delete.ts +6 -1
- package/src/firebase/crud/get.ts +9 -2
- package/src/firebase/crud/list.ts +18 -8
- package/src/firebase/crud/update.ts +15 -7
- package/src/firebase/helpers/githubAccessHelper.ts +3 -0
- package/src/firebase/helpers/githubTeamAccessHelper.ts +1 -0
- package/src/firebase/index.ts +0 -1
- package/src/firebase/oauth/disconnect.ts +2 -2
- package/src/firebase/oauth/exchangeToken.ts +6 -2
- package/src/firebase/oauth/getConnections.ts +3 -3
- package/src/firebase/oauth/githubAccess.ts +7 -4
- package/src/firebase/oauth/refreshToken.ts +3 -2
- package/src/firebase/registerCrudFunctions.ts +0 -19
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +4 -1
- package/src/shared/__tests__/idempotency.test.ts +0 -32
- package/src/shared/__tests__/utils.test.ts +0 -25
- 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.compat.test.ts +4 -110
- 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__/webhookHandler.test.ts +108 -0
- package/src/shared/billing/checkoutPrice.ts +7 -42
- package/src/shared/billing/checkoutValidation.ts +19 -2
- package/src/shared/billing/createCheckout.ts +59 -30
- package/src/shared/billing/firestoreIdempotency.ts +2 -21
- package/src/shared/billing/helpers/subscriptionManagement.ts +14 -10
- package/src/shared/billing/idempotency.ts +4 -54
- package/src/shared/billing/idempotencyContract.ts +0 -21
- 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/webhookHandler.ts +5 -1
- package/src/shared/crud/bulkCore.ts +3 -2
- 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/logger.ts +37 -38
- package/src/shared/schema.ts +6 -10
- 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/auth.ts +1 -6
- 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 +12 -138
- package/src/supabase/__tests__/aggregate.test.ts +132 -0
- package/src/supabase/auth/__tests__/deleteAccount.test.ts +102 -0
- package/src/supabase/auth/deleteAccount.ts +72 -5
- package/src/supabase/billing/refreshSubscriptionStatus.ts +6 -5
- package/src/supabase/crud/aggregate.ts +85 -72
- package/src/supabase/crud/bulk.ts +3 -0
- package/src/supabase/crud/create.ts +13 -9
- package/src/supabase/crud/delete.ts +2 -1
- package/src/supabase/crud/entityStore.ts +1 -1
- package/src/supabase/crud/get.ts +2 -1
- package/src/supabase/crud/list.ts +23 -17
- package/src/supabase/crud/update.ts +9 -6
- package/src/supabase/edgeFunction.ts +2 -1
- package/src/supabase/email/createEmailFunction.ts +2 -1
- package/src/supabase/index.ts +1 -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/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -0
- 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 +7 -2
- package/src/vercel/api/crud/create.ts +6 -3
- package/src/vercel/api/crud/delete.ts +5 -2
- package/src/vercel/api/crud/get.ts +5 -2
- package/src/vercel/api/crud/list.ts +6 -3
- package/src/vercel/api/crud/update.ts +6 -3
- 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-5IPULSUX.js.map +0 -7
- package/lib/chunks/chunk-6USHTJED.js +0 -22
- package/lib/chunks/chunk-6USHTJED.js.map +0 -7
- package/lib/chunks/chunk-CXBSROEW.js +0 -23
- package/lib/chunks/chunk-CXBSROEW.js.map +0 -7
- package/lib/chunks/chunk-GYTCWMXV.js +0 -22
- package/lib/chunks/chunk-GYTCWMXV.js.map +0 -7
- package/lib/chunks/chunk-LCDLG4VG.js +0 -151
- package/lib/chunks/chunk-LCDLG4VG.js.map +0 -7
- package/lib/chunks/chunk-MQANUSY3.js +0 -22
- package/lib/chunks/chunk-MQANUSY3.js.map +0 -7
- package/lib/chunks/chunk-OFQVO3FD.js +0 -22
- package/lib/chunks/chunk-OFQVO3FD.js.map +0 -7
- package/lib/chunks/chunk-PWAGW4R6.js +0 -22
- package/lib/chunks/chunk-PWAGW4R6.js.map +0 -7
- package/lib/chunks/chunk-US2VOP4S.js +0 -22
- package/lib/chunks/chunk-US2VOP4S.js.map +0 -7
- package/lib/chunks/chunk-YTKDNZNW.js +0 -22
- package/lib/chunks/chunk-YTKDNZNW.js.map +0 -7
- package/lib/chunks/server-IQ5JNJOM.js +0 -22
- package/lib/shared/utils/functionWrapper.d.ts +0 -36
- package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -122
- package/src/shared/utils/functionWrapper.ts +0 -73
- /package/lib/chunks/{chunk-3F4BWKQD.js.map → chunk-UH445BGK.js.map} +0 -0
- /package/lib/chunks/{monitoring-E7JBYBHQ.js.map → monitoring-LXNVBD3G.js.map} +0 -0
- /package/lib/chunks/{rateLimiter-SQISLOP5.js.map → rateLimiter-GG5LPWXJ.js.map} +0 -0
- /package/lib/chunks/{server-IQ5JNJOM.js.map → server-NODQAE3F.js.map} +0 -0
|
@@ -19,6 +19,7 @@ import { getFirebaseAdminAuth } from '@donotdev/firebase/server';
|
|
|
19
19
|
import { stripe, validateStripeEnvironment } from '../../shared/billing/stripeClient.js';
|
|
20
20
|
import { createBaseFunction } from '../baseFunction.js';
|
|
21
21
|
import { STRIPE_CONFIG } from '../config/constants.js';
|
|
22
|
+
import { pinnedSubscriptionPeriod } from '../../shared/billing/stripePinned.js';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Schema for refreshing subscription status
|
|
@@ -70,12 +71,12 @@ async function refreshSubscriptionStatusLogic(
|
|
|
70
71
|
...currentClaims.subscription,
|
|
71
72
|
status: subscription.status,
|
|
72
73
|
currentPeriodStart: new Date(
|
|
73
|
-
(subscription
|
|
74
|
+
pinnedSubscriptionPeriod(subscription).current_period_start * 1000
|
|
74
75
|
).toISOString(),
|
|
75
76
|
currentPeriodEnd: new Date(
|
|
76
|
-
(subscription
|
|
77
|
+
pinnedSubscriptionPeriod(subscription).current_period_end * 1000
|
|
77
78
|
).toISOString(),
|
|
78
|
-
cancelAtPeriodEnd:
|
|
79
|
+
cancelAtPeriodEnd: subscription.cancel_at_period_end,
|
|
79
80
|
},
|
|
80
81
|
};
|
|
81
82
|
|
|
@@ -86,9 +87,9 @@ async function refreshSubscriptionStatusLogic(
|
|
|
86
87
|
userId,
|
|
87
88
|
status: subscription.status,
|
|
88
89
|
currentPeriodEnd: new Date(
|
|
89
|
-
(subscription
|
|
90
|
+
pinnedSubscriptionPeriod(subscription).current_period_end * 1000
|
|
90
91
|
).toISOString(),
|
|
91
|
-
cancelAtPeriodEnd:
|
|
92
|
+
cancelAtPeriodEnd: subscription.cancel_at_period_end,
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -101,6 +102,7 @@ async function refreshSubscriptionStatusLogic(
|
|
|
101
102
|
* @author AMBROISE PARK Consulting
|
|
102
103
|
*/
|
|
103
104
|
export const refreshSubscriptionStatus = (
|
|
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)
|
|
104
106
|
customSchema?: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>
|
|
105
107
|
) => {
|
|
106
108
|
const schema = customSchema || refreshSubscriptionStatusSchema;
|
|
@@ -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:
|
|
34
|
+
async function getRawBody(req: Request): Promise<Buffer> {
|
|
35
35
|
// If rawBody is already available, use it
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
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:
|
|
81
|
+
schema: unknown,
|
|
79
82
|
fieldName: string
|
|
80
|
-
):
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
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:
|
|
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
|
-
|
|
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,
|
|
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.
|
|
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,
|
|
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,
|
|
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.
|
|
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
|
-
| {
|
|
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,
|
|
75
|
+
payload: Record<string, unknown>,
|
|
71
76
|
uniqueKeys: UniqueKeyDefinition[]
|
|
72
|
-
): Record<string,
|
|
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,
|
|
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.
|
|
152
|
-
draftDocumentSchema: v.
|
|
156
|
+
createDocumentSchema: v.GenericSchema,
|
|
157
|
+
draftDocumentSchema: v.GenericSchema
|
|
153
158
|
) {
|
|
154
159
|
return async function createEntityLogic(
|
|
155
160
|
data: CreateEntityRequest,
|
|
156
|
-
context: {
|
|
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.
|
|
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: {
|
|
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
|
@@ -36,12 +36,16 @@ export type GetEntityRequest = { id: string };
|
|
|
36
36
|
*/
|
|
37
37
|
function getEntityLogicFactory(
|
|
38
38
|
collection: string,
|
|
39
|
-
documentSchema: v.
|
|
39
|
+
documentSchema: v.GenericSchema,
|
|
40
40
|
ownership?: EntityOwnershipConfig
|
|
41
41
|
) {
|
|
42
42
|
return async function getEntityLogic(
|
|
43
43
|
data: GetEntityRequest,
|
|
44
|
-
context: {
|
|
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
|
-
|
|
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
|
|
@@ -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 = (
|
|
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:
|
|
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
|
|
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,
|
|
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,
|
|
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(
|
|
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,
|
|
55
|
+
payload: Record<string, unknown>,
|
|
55
56
|
uniqueKeys: UniqueKeyDefinition[]
|
|
56
|
-
): Record<string,
|
|
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,
|
|
84
|
-
payload: Record<string,
|
|
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.
|
|
145
|
+
documentSchema: v.GenericSchema
|
|
145
146
|
) {
|
|
146
147
|
return async function updateEntityLogic(
|
|
147
148
|
data: UpdateEntityRequest,
|
|
148
|
-
context: {
|
|
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.
|
|
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 {
|
package/src/firebase/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { OAUTH_PARTNERS } from '@donotdev/core/server';
|
|
|
15
15
|
import type { OAuthPartnerId, OAuthPurpose } from '@donotdev/core/server';
|
|
16
16
|
import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
|
|
17
17
|
|
|
18
|
-
import { assertAuthenticated } from '../../shared/utils.js';
|
|
18
|
+
import { assertAuthenticated } from '../../shared/utils/internal/auth.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Disconnect a provider
|
|
@@ -29,7 +29,7 @@ export const disconnect = onCall<{
|
|
|
29
29
|
purpose: OAuthPurpose;
|
|
30
30
|
}>(async (request) => {
|
|
31
31
|
// Verify authentication
|
|
32
|
-
const uid = assertAuthenticated(request.auth);
|
|
32
|
+
const uid = assertAuthenticated(request.auth?.uid);
|
|
33
33
|
|
|
34
34
|
const { provider, purpose } = request.data;
|
|
35
35
|
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
FieldValue,
|
|
22
22
|
} from '@donotdev/firebase/server';
|
|
23
23
|
|
|
24
|
-
import { assertAuthenticated } from '../../shared/utils.js';
|
|
24
|
+
import { assertAuthenticated } from '../../shared/utils/internal/auth.js';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Exchange OAuth authorization code for access token
|
|
@@ -32,7 +32,7 @@ import { assertAuthenticated } from '../../shared/utils.js';
|
|
|
32
32
|
*/
|
|
33
33
|
export const exchangeToken = onCall<ExchangeTokenRequest>(async (request) => {
|
|
34
34
|
// Verify authentication
|
|
35
|
-
const uid = assertAuthenticated(request.auth);
|
|
35
|
+
const uid = assertAuthenticated(request.auth?.uid);
|
|
36
36
|
|
|
37
37
|
const { provider, purpose, code, redirectUri, codeVerifier, idempotencyKey } =
|
|
38
38
|
request.data;
|
|
@@ -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 {
|