better-convex 0.0.4 → 0.1.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/dist/auth/index.d.ts +69 -69
- package/dist/auth/index.js +2 -2
- package/dist/auth-client/index.d.ts +4 -1
- package/dist/auth-client/index.js +29 -26
- package/dist/auth-nextjs/index.d.ts +10 -10
- package/dist/auth-nextjs/index.js +17 -13
- package/dist/{auth-store-Bu8XzPRV.js → auth-store-DANFmEdk.js} +12 -1
- package/dist/{error-DwOaXhPE.js → caller-factory-DxmuY355.js} +8 -135
- package/dist/crpc/index.d.ts +4 -2
- package/dist/crpc/index.js +3 -23
- package/dist/error-CsSzFKod.js +32 -0
- package/dist/react/index.d.ts +7 -1
- package/dist/react/index.js +11 -4
- package/dist/rsc/index.d.ts +1 -1
- package/dist/rsc/index.js +1 -1
- package/dist/server/index.d.ts +8 -10
- package/dist/server/index.js +128 -1
- package/package.json +1 -1
- /package/dist/{create-schema-CiLdn4rr.js → create-schema-DzQEFNJW.js} +0 -0
- /package/dist/{query-options-lmbltN6P.js → query-options-sK2n1Ioe.js} +0 -0
- /package/dist/{types-h8_JnBVZ.d.ts → types-CotWvon8.d.ts} +0 -0
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as better_auth_adapters0 from "better-auth/adapters";
|
|
2
2
|
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
3
3
|
import { BetterAuthDBSchema } from "better-auth/db";
|
|
4
|
-
import * as
|
|
4
|
+
import * as convex_server0 from "convex/server";
|
|
5
5
|
import { DocumentByName, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx, GenericSchema, HttpRouter, IdField, PaginationOptions, PaginationResult, SchemaDefinition, SystemFields, TableNamesInDataModel, internalMutationGeneric } from "convex/server";
|
|
6
6
|
import * as convex_values0 from "convex/values";
|
|
7
7
|
import { Infer } from "convex/values";
|
|
@@ -47,28 +47,28 @@ declare const createClient: <DataModel extends GenericDataModel, Schema$1 extend
|
|
|
47
47
|
adapter: (ctx: GenericCtx<DataModel>, createAuthOptions: (ctx: any) => BetterAuthOptions) => better_auth_adapters0.AdapterFactory;
|
|
48
48
|
httpAdapter: (ctx: GenericCtx<DataModel>) => better_auth_adapters0.AdapterFactory;
|
|
49
49
|
triggersApi: () => {
|
|
50
|
-
beforeCreate:
|
|
51
|
-
model: string;
|
|
50
|
+
beforeCreate: convex_server0.RegisteredMutation<"internal", {
|
|
52
51
|
data: any;
|
|
52
|
+
model: string;
|
|
53
53
|
}, Promise<any>>;
|
|
54
|
-
beforeDelete:
|
|
54
|
+
beforeDelete: convex_server0.RegisteredMutation<"internal", {
|
|
55
55
|
model: string;
|
|
56
56
|
doc: any;
|
|
57
57
|
}, Promise<any>>;
|
|
58
|
-
beforeUpdate:
|
|
59
|
-
model: string;
|
|
58
|
+
beforeUpdate: convex_server0.RegisteredMutation<"internal", {
|
|
60
59
|
update: any;
|
|
60
|
+
model: string;
|
|
61
61
|
doc: any;
|
|
62
62
|
}, Promise<any>>;
|
|
63
|
-
onCreate:
|
|
63
|
+
onCreate: convex_server0.RegisteredMutation<"internal", {
|
|
64
64
|
model: string;
|
|
65
65
|
doc: any;
|
|
66
66
|
}, Promise<void>>;
|
|
67
|
-
onDelete:
|
|
67
|
+
onDelete: convex_server0.RegisteredMutation<"internal", {
|
|
68
68
|
model: string;
|
|
69
69
|
doc: any;
|
|
70
70
|
}, Promise<void>>;
|
|
71
|
-
onUpdate:
|
|
71
|
+
onUpdate: convex_server0.RegisteredMutation<"internal", {
|
|
72
72
|
model: string;
|
|
73
73
|
newDoc: any;
|
|
74
74
|
oldDoc: any;
|
|
@@ -163,29 +163,29 @@ declare const dbAdapter: <DataModel extends GenericDataModel, Schema$1 extends S
|
|
|
163
163
|
//#endregion
|
|
164
164
|
//#region src/auth/adapter-utils.d.ts
|
|
165
165
|
declare const adapterWhereValidator: convex_values0.VObject<{
|
|
166
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
166
167
|
connector?: "AND" | "OR" | undefined;
|
|
167
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
168
|
-
field: string;
|
|
169
168
|
value: string | number | boolean | string[] | number[] | null;
|
|
169
|
+
field: string;
|
|
170
170
|
}, {
|
|
171
171
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
172
172
|
field: convex_values0.VString<string, "required">;
|
|
173
|
-
operator: convex_values0.VUnion<"
|
|
173
|
+
operator: convex_values0.VUnion<"eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
174
174
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
175
|
-
}, "required", "
|
|
175
|
+
}, "required", "operator" | "value" | "field" | "connector">;
|
|
176
176
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
177
177
|
limit?: number | undefined;
|
|
178
178
|
offset?: number | undefined;
|
|
179
179
|
select?: string[] | undefined;
|
|
180
180
|
sortBy?: {
|
|
181
|
-
direction: "asc" | "desc";
|
|
182
181
|
field: string;
|
|
182
|
+
direction: "asc" | "desc";
|
|
183
183
|
} | undefined;
|
|
184
184
|
where?: {
|
|
185
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
185
186
|
connector?: "AND" | "OR" | undefined;
|
|
186
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
187
|
-
field: string;
|
|
188
187
|
value: string | number | boolean | string[] | number[] | null;
|
|
188
|
+
field: string;
|
|
189
189
|
}[] | undefined;
|
|
190
190
|
model: string;
|
|
191
191
|
}, {
|
|
@@ -194,29 +194,29 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
194
194
|
offset: convex_values0.VFloat64<number | undefined, "optional">;
|
|
195
195
|
select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
|
|
196
196
|
sortBy: convex_values0.VObject<{
|
|
197
|
-
direction: "asc" | "desc";
|
|
198
197
|
field: string;
|
|
198
|
+
direction: "asc" | "desc";
|
|
199
199
|
} | undefined, {
|
|
200
200
|
direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
|
|
201
201
|
field: convex_values0.VString<string, "required">;
|
|
202
|
-
}, "optional", "
|
|
202
|
+
}, "optional", "field" | "direction">;
|
|
203
203
|
where: convex_values0.VArray<{
|
|
204
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
204
205
|
connector?: "AND" | "OR" | undefined;
|
|
205
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
206
|
-
field: string;
|
|
207
206
|
value: string | number | boolean | string[] | number[] | null;
|
|
207
|
+
field: string;
|
|
208
208
|
}[] | undefined, convex_values0.VObject<{
|
|
209
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
209
210
|
connector?: "AND" | "OR" | undefined;
|
|
210
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
211
|
-
field: string;
|
|
212
211
|
value: string | number | boolean | string[] | number[] | null;
|
|
212
|
+
field: string;
|
|
213
213
|
}, {
|
|
214
214
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
215
215
|
field: convex_values0.VString<string, "required">;
|
|
216
|
-
operator: convex_values0.VUnion<"
|
|
216
|
+
operator: convex_values0.VUnion<"eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
217
217
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
218
|
-
}, "required", "
|
|
219
|
-
}, "required", "limit" | "model" | "offset" | "select" | "sortBy" | "where" | "sortBy.
|
|
218
|
+
}, "required", "operator" | "value" | "field" | "connector">, "optional">;
|
|
219
|
+
}, "required", "limit" | "model" | "offset" | "select" | "sortBy" | "where" | "sortBy.field" | "sortBy.direction">;
|
|
220
220
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
221
221
|
declare const checkUniqueFields: <Schema$1 extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema$1, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
|
|
222
222
|
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => Promise<D | null>;
|
|
@@ -244,7 +244,7 @@ declare const findOneHandler: (ctx: any, args: {
|
|
|
244
244
|
model: string;
|
|
245
245
|
select?: string[];
|
|
246
246
|
where?: any[];
|
|
247
|
-
}, schema: Schema, betterAuthSchema: any) => Promise<
|
|
247
|
+
}, schema: Schema, betterAuthSchema: any) => Promise<convex_server0.GenericDocument | null>;
|
|
248
248
|
declare const findManyHandler: (ctx: any, args: {
|
|
249
249
|
model: string;
|
|
250
250
|
paginationOpts: any;
|
|
@@ -255,7 +255,7 @@ declare const findManyHandler: (ctx: any, args: {
|
|
|
255
255
|
field: string;
|
|
256
256
|
};
|
|
257
257
|
where?: any[];
|
|
258
|
-
}, schema: Schema, betterAuthSchema: any) => Promise<
|
|
258
|
+
}, schema: Schema, betterAuthSchema: any) => Promise<convex_server0.PaginationResult<convex_server0.GenericDocument>>;
|
|
259
259
|
declare const updateOneHandler: (ctx: any, args: {
|
|
260
260
|
input: {
|
|
261
261
|
model: string;
|
|
@@ -278,8 +278,8 @@ declare const updateManyHandler: (ctx: any, args: {
|
|
|
278
278
|
count: number;
|
|
279
279
|
ids: any[];
|
|
280
280
|
isDone: boolean;
|
|
281
|
-
continueCursor:
|
|
282
|
-
splitCursor?:
|
|
281
|
+
continueCursor: convex_server0.Cursor;
|
|
282
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
283
283
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
284
284
|
}>;
|
|
285
285
|
declare const deleteOneHandler: (ctx: any, args: {
|
|
@@ -290,7 +290,7 @@ declare const deleteOneHandler: (ctx: any, args: {
|
|
|
290
290
|
beforeDeleteHandle?: string;
|
|
291
291
|
skipBeforeHooks?: boolean;
|
|
292
292
|
onDeleteHandle?: string;
|
|
293
|
-
}, schema: Schema, betterAuthSchema: any) => Promise<
|
|
293
|
+
}, schema: Schema, betterAuthSchema: any) => Promise<convex_server0.GenericDocument | undefined>;
|
|
294
294
|
declare const deleteManyHandler: (ctx: any, args: {
|
|
295
295
|
input: {
|
|
296
296
|
model: string;
|
|
@@ -304,8 +304,8 @@ declare const deleteManyHandler: (ctx: any, args: {
|
|
|
304
304
|
count: number;
|
|
305
305
|
ids: any[];
|
|
306
306
|
isDone: boolean;
|
|
307
|
-
continueCursor:
|
|
308
|
-
splitCursor?:
|
|
307
|
+
continueCursor: convex_server0.Cursor;
|
|
308
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
309
309
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
310
310
|
}>;
|
|
311
311
|
declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: Schema$1, createAuth: CreateAuth, options?: {
|
|
@@ -313,23 +313,23 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
313
313
|
/** Skip input validation for smaller generated types. Since these are internal functions, validation is optional. */
|
|
314
314
|
skipValidation?: boolean;
|
|
315
315
|
}) => {
|
|
316
|
-
create:
|
|
316
|
+
create: convex_server0.RegisteredMutation<"internal", {
|
|
317
317
|
select?: string[] | undefined;
|
|
318
318
|
beforeCreateHandle?: string | undefined;
|
|
319
319
|
onCreateHandle?: string | undefined;
|
|
320
320
|
input: {
|
|
321
|
-
model: string;
|
|
322
321
|
data: any;
|
|
323
|
-
} | {
|
|
324
322
|
model: string;
|
|
323
|
+
} | {
|
|
325
324
|
data: {
|
|
326
325
|
[x: string]: unknown;
|
|
327
326
|
[x: number]: unknown;
|
|
328
327
|
[x: symbol]: unknown;
|
|
329
328
|
};
|
|
329
|
+
model: string;
|
|
330
330
|
};
|
|
331
331
|
}, Promise<any>>;
|
|
332
|
-
deleteMany:
|
|
332
|
+
deleteMany: convex_server0.RegisteredMutation<"internal", {
|
|
333
333
|
beforeDeleteHandle?: string | undefined;
|
|
334
334
|
onDeleteHandle?: string | undefined;
|
|
335
335
|
paginationOpts: {
|
|
@@ -345,10 +345,10 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
345
345
|
model: string;
|
|
346
346
|
} | {
|
|
347
347
|
where?: {
|
|
348
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
348
349
|
connector?: "AND" | "OR" | undefined;
|
|
349
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
350
|
-
field: string;
|
|
351
350
|
value: string | number | boolean | string[] | number[] | null;
|
|
351
|
+
field: string;
|
|
352
352
|
}[] | undefined;
|
|
353
353
|
model: string;
|
|
354
354
|
};
|
|
@@ -356,11 +356,11 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
356
356
|
count: number;
|
|
357
357
|
ids: any[];
|
|
358
358
|
isDone: boolean;
|
|
359
|
-
continueCursor:
|
|
360
|
-
splitCursor?:
|
|
359
|
+
continueCursor: convex_server0.Cursor;
|
|
360
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
361
361
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
362
362
|
}>>;
|
|
363
|
-
deleteOne:
|
|
363
|
+
deleteOne: convex_server0.RegisteredMutation<"internal", {
|
|
364
364
|
beforeDeleteHandle?: string | undefined;
|
|
365
365
|
onDeleteHandle?: string | undefined;
|
|
366
366
|
input: {
|
|
@@ -368,29 +368,28 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
368
368
|
model: string;
|
|
369
369
|
} | {
|
|
370
370
|
where?: {
|
|
371
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
371
372
|
connector?: "AND" | "OR" | undefined;
|
|
372
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
373
|
-
field: string;
|
|
374
373
|
value: string | number | boolean | string[] | number[] | null;
|
|
374
|
+
field: string;
|
|
375
375
|
}[] | undefined;
|
|
376
376
|
model: string;
|
|
377
377
|
};
|
|
378
|
-
}, Promise<
|
|
379
|
-
findMany:
|
|
380
|
-
limit?: number | undefined;
|
|
378
|
+
}, Promise<convex_server0.GenericDocument | undefined>>;
|
|
379
|
+
findMany: convex_server0.RegisteredQuery<"internal", {
|
|
381
380
|
join?: any;
|
|
381
|
+
limit?: number | undefined;
|
|
382
382
|
offset?: number | undefined;
|
|
383
383
|
sortBy?: {
|
|
384
|
-
direction: "asc" | "desc";
|
|
385
384
|
field: string;
|
|
385
|
+
direction: "asc" | "desc";
|
|
386
386
|
} | undefined;
|
|
387
387
|
where?: {
|
|
388
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
388
389
|
connector?: "AND" | "OR" | undefined;
|
|
389
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
390
|
-
field: string;
|
|
391
390
|
value: string | number | boolean | string[] | number[] | null;
|
|
391
|
+
field: string;
|
|
392
392
|
}[] | undefined;
|
|
393
|
-
model: string;
|
|
394
393
|
paginationOpts: {
|
|
395
394
|
id?: number;
|
|
396
395
|
endCursor?: string | null;
|
|
@@ -399,19 +398,20 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
399
398
|
numItems: number;
|
|
400
399
|
cursor: string | null;
|
|
401
400
|
};
|
|
402
|
-
|
|
403
|
-
|
|
401
|
+
model: string;
|
|
402
|
+
}, Promise<convex_server0.PaginationResult<convex_server0.GenericDocument>>>;
|
|
403
|
+
findOne: convex_server0.RegisteredQuery<"internal", {
|
|
404
404
|
join?: any;
|
|
405
405
|
select?: string[] | undefined;
|
|
406
406
|
where?: {
|
|
407
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
407
408
|
connector?: "AND" | "OR" | undefined;
|
|
408
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
409
|
-
field: string;
|
|
410
409
|
value: string | number | boolean | string[] | number[] | null;
|
|
410
|
+
field: string;
|
|
411
411
|
}[] | undefined;
|
|
412
412
|
model: string;
|
|
413
|
-
}, Promise<
|
|
414
|
-
updateMany:
|
|
413
|
+
}, Promise<convex_server0.GenericDocument | null>>;
|
|
414
|
+
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
415
415
|
beforeUpdateHandle?: string | undefined;
|
|
416
416
|
onUpdateHandle?: string | undefined;
|
|
417
417
|
paginationOpts: {
|
|
@@ -424,54 +424,54 @@ declare const createApi: <Schema$1 extends SchemaDefinition<any, any>>(schema: S
|
|
|
424
424
|
};
|
|
425
425
|
input: {
|
|
426
426
|
where?: any[] | undefined;
|
|
427
|
-
model: string;
|
|
428
427
|
update: any;
|
|
428
|
+
model: string;
|
|
429
429
|
} | {
|
|
430
430
|
where?: {
|
|
431
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
431
432
|
connector?: "AND" | "OR" | undefined;
|
|
432
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
433
|
-
field: string;
|
|
434
433
|
value: string | number | boolean | string[] | number[] | null;
|
|
434
|
+
field: string;
|
|
435
435
|
}[] | undefined;
|
|
436
|
-
model: string;
|
|
437
436
|
update: {
|
|
438
437
|
[x: string]: unknown;
|
|
439
438
|
[x: number]: unknown;
|
|
440
439
|
[x: symbol]: unknown;
|
|
441
440
|
};
|
|
441
|
+
model: string;
|
|
442
442
|
};
|
|
443
443
|
}, Promise<{
|
|
444
444
|
count: number;
|
|
445
445
|
ids: any[];
|
|
446
446
|
isDone: boolean;
|
|
447
|
-
continueCursor:
|
|
448
|
-
splitCursor?:
|
|
447
|
+
continueCursor: convex_server0.Cursor;
|
|
448
|
+
splitCursor?: convex_server0.Cursor | null;
|
|
449
449
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
450
450
|
}>>;
|
|
451
|
-
updateOne:
|
|
451
|
+
updateOne: convex_server0.RegisteredMutation<"internal", {
|
|
452
452
|
beforeUpdateHandle?: string | undefined;
|
|
453
453
|
onUpdateHandle?: string | undefined;
|
|
454
454
|
input: {
|
|
455
455
|
where?: any[] | undefined;
|
|
456
|
-
model: string;
|
|
457
456
|
update: any;
|
|
457
|
+
model: string;
|
|
458
458
|
} | {
|
|
459
459
|
where?: {
|
|
460
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
460
461
|
connector?: "AND" | "OR" | undefined;
|
|
461
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
462
|
-
field: string;
|
|
463
462
|
value: string | number | boolean | string[] | number[] | null;
|
|
463
|
+
field: string;
|
|
464
464
|
}[] | undefined;
|
|
465
|
-
model: string;
|
|
466
465
|
update: {
|
|
467
466
|
[x: string]: unknown;
|
|
468
467
|
[x: number]: unknown;
|
|
469
468
|
[x: symbol]: unknown;
|
|
470
469
|
};
|
|
470
|
+
model: string;
|
|
471
471
|
};
|
|
472
472
|
}, Promise<any>>;
|
|
473
|
-
getLatestJwks:
|
|
474
|
-
rotateKeys:
|
|
473
|
+
getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<any>>;
|
|
474
|
+
rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<any>>;
|
|
475
475
|
};
|
|
476
476
|
//#endregion
|
|
477
477
|
//#region src/auth/helpers.d.ts
|
package/dist/auth/index.js
CHANGED
|
@@ -630,7 +630,7 @@ const httpAdapter = (ctx, { authFunctions, debugLogs, triggers }) => {
|
|
|
630
630
|
});
|
|
631
631
|
},
|
|
632
632
|
createSchema: async ({ file, tables }) => {
|
|
633
|
-
const { createSchema } = await import("../create-schema-
|
|
633
|
+
const { createSchema } = await import("../create-schema-DzQEFNJW.js");
|
|
634
634
|
return createSchema({
|
|
635
635
|
file,
|
|
636
636
|
tables
|
|
@@ -766,7 +766,7 @@ const dbAdapter = (ctx, createAuthOptions, { authFunctions, debugLogs, schema, t
|
|
|
766
766
|
}, schema, betterAuthSchema);
|
|
767
767
|
},
|
|
768
768
|
createSchema: async ({ file, tables }) => {
|
|
769
|
-
const { createSchema } = await import("../create-schema-
|
|
769
|
+
const { createSchema } = await import("../create-schema-DzQEFNJW.js");
|
|
770
770
|
return createSchema({
|
|
771
771
|
file,
|
|
772
772
|
tables
|
|
@@ -19,6 +19,8 @@ type ConvexAuthProviderProps = {
|
|
|
19
19
|
onQueryUnauthorized?: (info: {
|
|
20
20
|
queryName: string;
|
|
21
21
|
}) => void;
|
|
22
|
+
/** Custom function to detect UNAUTHORIZED errors. Default checks code property. */
|
|
23
|
+
isUnauthorized?: (error: unknown) => boolean;
|
|
22
24
|
};
|
|
23
25
|
/**
|
|
24
26
|
* Unified auth provider for Convex + Better Auth.
|
|
@@ -30,7 +32,8 @@ declare function ConvexAuthProvider({
|
|
|
30
32
|
authClient,
|
|
31
33
|
initialToken,
|
|
32
34
|
onMutationUnauthorized,
|
|
33
|
-
onQueryUnauthorized
|
|
35
|
+
onQueryUnauthorized,
|
|
36
|
+
isUnauthorized
|
|
34
37
|
}: ConvexAuthProviderProps): react_jsx_runtime0.JSX.Element;
|
|
35
38
|
//#endregion
|
|
36
39
|
export { type AuthClient, ConvexAuthProvider, ConvexAuthProviderProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { c as persistToken, f as useAuthStore, g as CRPCClientError, p as useAuthValue, s as getPersistedToken, t as AuthProvider } from "../auth-store-
|
|
2
|
+
import { _ as defaultIsUnauthorized, c as persistToken, f as useAuthStore, g as CRPCClientError, p as useAuthValue, s as getPersistedToken, t as AuthProvider } from "../auth-store-DANFmEdk.js";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
4
|
import { ConvexProviderWithAuth } from "convex/react";
|
|
5
5
|
import { useCallback, useEffect, useMemo } from "react";
|
|
@@ -20,8 +20,8 @@ const defaultMutationHandler = () => {
|
|
|
20
20
|
* Handles token sync, HMR persistence, and auth callbacks.
|
|
21
21
|
*/
|
|
22
22
|
function ConvexAuthProvider(t0) {
|
|
23
|
-
const $ = c(
|
|
24
|
-
const { children, client, authClient, initialToken, onMutationUnauthorized, onQueryUnauthorized } = t0;
|
|
23
|
+
const $ = c(17);
|
|
24
|
+
const { children, client, authClient, initialToken, onMutationUnauthorized, onQueryUnauthorized, isUnauthorized } = t0;
|
|
25
25
|
let t1;
|
|
26
26
|
if ($[0] !== initialToken) {
|
|
27
27
|
t1 = initialToken ?? getPersistedToken();
|
|
@@ -43,21 +43,23 @@ function ConvexAuthProvider(t0) {
|
|
|
43
43
|
$[2] = t3;
|
|
44
44
|
$[3] = t4;
|
|
45
45
|
} else t4 = $[3];
|
|
46
|
-
const t5 =
|
|
47
|
-
const t6 =
|
|
48
|
-
|
|
46
|
+
const t5 = isUnauthorized ?? defaultIsUnauthorized;
|
|
47
|
+
const t6 = onMutationUnauthorized ?? defaultMutationHandler;
|
|
48
|
+
const t7 = onQueryUnauthorized ?? _temp;
|
|
49
|
+
let t8;
|
|
49
50
|
if ($[4] !== authClient) {
|
|
50
|
-
|
|
51
|
+
t8 = /* @__PURE__ */ jsx(AuthSyncEffect, { authClient });
|
|
51
52
|
$[4] = authClient;
|
|
52
|
-
$[5] =
|
|
53
|
-
} else
|
|
54
|
-
let
|
|
55
|
-
if ($[6] !== children || $[7] !== t4 || $[8] !== t5 || $[9] !== t6 || $[10] !== t7) {
|
|
56
|
-
|
|
53
|
+
$[5] = t8;
|
|
54
|
+
} else t8 = $[5];
|
|
55
|
+
let t9;
|
|
56
|
+
if ($[6] !== children || $[7] !== t4 || $[8] !== t5 || $[9] !== t6 || $[10] !== t7 || $[11] !== t8) {
|
|
57
|
+
t9 = /* @__PURE__ */ jsxs(AuthProvider, {
|
|
57
58
|
initialValues: t4,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
isUnauthorized: t5,
|
|
60
|
+
onMutationUnauthorized: t6,
|
|
61
|
+
onQueryUnauthorized: t7,
|
|
62
|
+
children: [t8, children]
|
|
61
63
|
});
|
|
62
64
|
$[6] = children;
|
|
63
65
|
$[7] = t4;
|
|
@@ -65,20 +67,21 @@ function ConvexAuthProvider(t0) {
|
|
|
65
67
|
$[9] = t6;
|
|
66
68
|
$[10] = t7;
|
|
67
69
|
$[11] = t8;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
$[12] = t9;
|
|
71
|
+
} else t9 = $[12];
|
|
72
|
+
let t10;
|
|
73
|
+
if ($[13] !== t2 || $[14] !== t9 || $[15] !== useAuth) {
|
|
74
|
+
t10 = /* @__PURE__ */ jsx(ConvexProviderWithAuth, {
|
|
72
75
|
client: t2,
|
|
73
76
|
useAuth,
|
|
74
|
-
children:
|
|
77
|
+
children: t9
|
|
75
78
|
});
|
|
76
|
-
$[
|
|
77
|
-
$[
|
|
78
|
-
$[
|
|
79
|
-
$[
|
|
80
|
-
} else
|
|
81
|
-
return
|
|
79
|
+
$[13] = t2;
|
|
80
|
+
$[14] = t9;
|
|
81
|
+
$[15] = useAuth;
|
|
82
|
+
$[16] = t10;
|
|
83
|
+
} else t10 = $[16];
|
|
84
|
+
return t10;
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
87
|
* Syncs Better Auth session to auth-store.
|
|
@@ -3,20 +3,20 @@ import { GetTokenOptions } from "@convex-dev/better-auth/utils";
|
|
|
3
3
|
|
|
4
4
|
//#region src/auth-nextjs/index.d.ts
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
type
|
|
8
|
-
/** Enable JWT caching
|
|
9
|
-
|
|
6
|
+
/** Auth options for server-side calls. */
|
|
7
|
+
type AuthOptions = {
|
|
8
|
+
/** Enable/disable JWT caching. Default: true */
|
|
9
|
+
jwtCache?: boolean;
|
|
10
|
+
/** Custom function to detect UNAUTHORIZED errors. Default checks code property. */
|
|
11
|
+
isUnauthorized?: (error: unknown) => boolean;
|
|
10
12
|
/** Expiration tolerance in seconds. */
|
|
11
13
|
expirationToleranceSeconds?: number;
|
|
12
|
-
/** Custom function to detect auth errors. Default checks for "auth" in error message. */
|
|
13
|
-
isAuthError?: (error: unknown) => boolean;
|
|
14
14
|
};
|
|
15
15
|
type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
|
|
16
16
|
api: TApi;
|
|
17
17
|
convexSiteUrl: string;
|
|
18
|
-
/** JWT caching
|
|
19
|
-
|
|
18
|
+
/** Auth options. JWT caching is enabled by default (set `auth.jwtCache: false` to disable). */
|
|
19
|
+
auth?: AuthOptions;
|
|
20
20
|
meta: CallerMeta;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
@@ -28,8 +28,8 @@ type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
|
|
|
28
28
|
* export const { createContext, createCaller, handler } = convexBetterAuth({
|
|
29
29
|
* api,
|
|
30
30
|
* convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
|
|
31
|
-
*
|
|
32
|
-
* });
|
|
31
|
+
* meta,
|
|
32
|
+
* }); // JWT caching enabled by default
|
|
33
33
|
*
|
|
34
34
|
* // rsc.tsx
|
|
35
35
|
* const createRSCContext = cache(async () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as defaultIsUnauthorized } from "../error-CsSzFKod.js";
|
|
2
|
+
import { t as createCallerFactory } from "../caller-factory-DxmuY355.js";
|
|
2
3
|
import { getToken } from "@convex-dev/better-auth/utils";
|
|
3
4
|
|
|
4
5
|
//#region src/auth-nextjs/index.ts
|
|
@@ -7,11 +8,6 @@ import { getToken } from "@convex-dev/better-auth/utils";
|
|
|
7
8
|
* Next.js + Better Auth wrapper for Convex caller factory.
|
|
8
9
|
* Uses @convex-dev/better-auth for token management.
|
|
9
10
|
*/
|
|
10
|
-
const AUTH_ERROR_REGEX = /auth/i;
|
|
11
|
-
const defaultIsAuthError = (error) => {
|
|
12
|
-
const message = error instanceof CRPCError && error.message || error instanceof Error && error.message || "";
|
|
13
|
-
return AUTH_ERROR_REGEX.test(String(message));
|
|
14
|
-
};
|
|
15
11
|
const handler = (request, siteUrl) => {
|
|
16
12
|
const requestUrl = new URL(request.url);
|
|
17
13
|
const nextUrl = `${siteUrl}${requestUrl.pathname}${requestUrl.search}`;
|
|
@@ -36,8 +32,8 @@ const nextJsHandler = (siteUrl) => ({
|
|
|
36
32
|
* export const { createContext, createCaller, handler } = convexBetterAuth({
|
|
37
33
|
* api,
|
|
38
34
|
* convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
|
|
39
|
-
*
|
|
40
|
-
* });
|
|
35
|
+
* meta,
|
|
36
|
+
* }); // JWT caching enabled by default
|
|
41
37
|
*
|
|
42
38
|
* // rsc.tsx
|
|
43
39
|
* const createRSCContext = cache(async () => {
|
|
@@ -51,14 +47,22 @@ const nextJsHandler = (siteUrl) => ({
|
|
|
51
47
|
* ```
|
|
52
48
|
*/
|
|
53
49
|
function convexBetterAuth(opts) {
|
|
50
|
+
const auth = opts.auth ?? {};
|
|
51
|
+
const jwtCacheEnabled = auth.jwtCache !== false;
|
|
54
52
|
const { createContext, createCaller } = createCallerFactory({
|
|
55
53
|
api: opts.api,
|
|
56
54
|
convexSiteUrl: opts.convexSiteUrl,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
auth: jwtCacheEnabled ? {
|
|
56
|
+
getToken: (siteUrl, headers, getTokenOpts) => getToken(siteUrl, headers, {
|
|
57
|
+
...getTokenOpts,
|
|
58
|
+
jwtCache: {
|
|
59
|
+
enabled: true,
|
|
60
|
+
expirationToleranceSeconds: auth.expirationToleranceSeconds,
|
|
61
|
+
isAuthError: auth.isUnauthorized ?? defaultIsUnauthorized
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
isUnauthorized: auth.isUnauthorized ?? defaultIsUnauthorized
|
|
65
|
+
} : void 0,
|
|
62
66
|
meta: opts.meta
|
|
63
67
|
});
|
|
64
68
|
return {
|
|
@@ -21,6 +21,16 @@ var CRPCClientError = class extends Error {
|
|
|
21
21
|
};
|
|
22
22
|
/** Type guard for CRPCClientError */
|
|
23
23
|
const isCRPCClientError = (error) => error instanceof CRPCClientError;
|
|
24
|
+
/** Default unauthorized detection - checks UNAUTHORIZED code */
|
|
25
|
+
const defaultIsUnauthorized = (error) => {
|
|
26
|
+
if (!error || typeof error !== "object") return false;
|
|
27
|
+
if ("data" in error) {
|
|
28
|
+
const data = error.data;
|
|
29
|
+
if (data && typeof data === "object" && "code" in data) return data.code === "UNAUTHORIZED";
|
|
30
|
+
}
|
|
31
|
+
if ("code" in error) return error.code === "UNAUTHORIZED";
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
24
34
|
|
|
25
35
|
//#endregion
|
|
26
36
|
//#region src/react/auth-store.tsx
|
|
@@ -90,6 +100,7 @@ const { authStore, AuthProvider, useAuthStore, useAuthState, useAuthValue } = cr
|
|
|
90
100
|
});
|
|
91
101
|
},
|
|
92
102
|
onQueryUnauthorized: () => {},
|
|
103
|
+
isUnauthorized: defaultIsUnauthorized,
|
|
93
104
|
token: getPersistedToken(),
|
|
94
105
|
enabled: false,
|
|
95
106
|
isLoading: false,
|
|
@@ -172,4 +183,4 @@ function Unauthenticated(t0) {
|
|
|
172
183
|
}
|
|
173
184
|
|
|
174
185
|
//#endregion
|
|
175
|
-
export {
|
|
186
|
+
export { defaultIsUnauthorized as _, Unauthenticated as a, persistToken as c, useAuthState as d, useAuthStore as f, CRPCClientError as g, useMaybeAuth as h, MaybeUnauthenticated as i, useAuth as l, useIsAuth as m, Authenticated as n, authStore as o, useAuthValue as p, MaybeAuthenticated as r, getPersistedToken as s, AuthProvider as t, useAuthGuard as u, isCRPCClientError as v };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ConvexError } from "convex/values";
|
|
2
1
|
import { fetchAction, fetchMutation, fetchQuery } from "convex/nextjs";
|
|
3
2
|
|
|
4
3
|
//#region src/server/caller.ts
|
|
@@ -139,22 +138,22 @@ const parseConvexSiteUrl = (url) => {
|
|
|
139
138
|
* const { createContext, createCaller } = createCallerFactory({
|
|
140
139
|
* api,
|
|
141
140
|
* convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
|
|
142
|
-
* getToken,
|
|
143
|
-
*
|
|
141
|
+
* auth: { getToken },
|
|
142
|
+
* meta,
|
|
144
143
|
* });
|
|
145
144
|
* ```
|
|
146
145
|
*/
|
|
147
146
|
const noAuthGetToken = () => Promise.resolve({ token: void 0 });
|
|
148
147
|
function createCallerFactory(opts) {
|
|
149
148
|
const siteUrl = parseConvexSiteUrl(opts.convexSiteUrl);
|
|
150
|
-
const getToken = opts.getToken ?? noAuthGetToken;
|
|
151
|
-
const
|
|
149
|
+
const getToken = opts.auth?.getToken ?? noAuthGetToken;
|
|
150
|
+
const isUnauthorized = opts.auth?.isUnauthorized;
|
|
152
151
|
const callWithTokenAndRetry = async (fn, tokenResult, headers) => {
|
|
153
152
|
try {
|
|
154
153
|
return await fn(tokenResult.token);
|
|
155
154
|
} catch (error) {
|
|
156
|
-
if (
|
|
157
|
-
if (!opts.
|
|
155
|
+
if (isUnauthorized?.(error)) return null;
|
|
156
|
+
if (!opts.auth || tokenResult.isFresh) throw error;
|
|
158
157
|
const newToken = await getToken(siteUrl, headers, {
|
|
159
158
|
...opts,
|
|
160
159
|
forceRefresh: true
|
|
@@ -162,7 +161,7 @@ function createCallerFactory(opts) {
|
|
|
162
161
|
try {
|
|
163
162
|
return await fn(newToken.token);
|
|
164
163
|
} catch (retryError) {
|
|
165
|
-
if (
|
|
164
|
+
if (isUnauthorized?.(retryError)) return null;
|
|
166
165
|
throw retryError;
|
|
167
166
|
}
|
|
168
167
|
}
|
|
@@ -206,130 +205,4 @@ function createCallerFactory(opts) {
|
|
|
206
205
|
}
|
|
207
206
|
|
|
208
207
|
//#endregion
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* CRPC Error - tRPC-style error handling for Convex
|
|
212
|
-
*
|
|
213
|
-
* Extends ConvexError with typed error codes and HTTP status mapping.
|
|
214
|
-
*/
|
|
215
|
-
/** JSON-RPC 2.0 error codes (tRPC-style) */
|
|
216
|
-
const CRPC_ERROR_CODES_BY_KEY = {
|
|
217
|
-
PARSE_ERROR: -32700,
|
|
218
|
-
BAD_REQUEST: -32600,
|
|
219
|
-
INTERNAL_SERVER_ERROR: -32603,
|
|
220
|
-
NOT_IMPLEMENTED: -32603,
|
|
221
|
-
BAD_GATEWAY: -32603,
|
|
222
|
-
SERVICE_UNAVAILABLE: -32603,
|
|
223
|
-
GATEWAY_TIMEOUT: -32603,
|
|
224
|
-
UNAUTHORIZED: -32001,
|
|
225
|
-
PAYMENT_REQUIRED: -32002,
|
|
226
|
-
FORBIDDEN: -32003,
|
|
227
|
-
NOT_FOUND: -32004,
|
|
228
|
-
METHOD_NOT_SUPPORTED: -32005,
|
|
229
|
-
TIMEOUT: -32008,
|
|
230
|
-
CONFLICT: -32009,
|
|
231
|
-
PRECONDITION_FAILED: -32012,
|
|
232
|
-
PAYLOAD_TOO_LARGE: -32013,
|
|
233
|
-
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
234
|
-
UNPROCESSABLE_CONTENT: -32022,
|
|
235
|
-
PRECONDITION_REQUIRED: -32028,
|
|
236
|
-
TOO_MANY_REQUESTS: -32029,
|
|
237
|
-
CLIENT_CLOSED_REQUEST: -32099
|
|
238
|
-
};
|
|
239
|
-
/** Map error codes to HTTP status codes */
|
|
240
|
-
const CRPC_ERROR_CODE_TO_HTTP = {
|
|
241
|
-
PARSE_ERROR: 400,
|
|
242
|
-
BAD_REQUEST: 400,
|
|
243
|
-
UNAUTHORIZED: 401,
|
|
244
|
-
PAYMENT_REQUIRED: 402,
|
|
245
|
-
FORBIDDEN: 403,
|
|
246
|
-
NOT_FOUND: 404,
|
|
247
|
-
METHOD_NOT_SUPPORTED: 405,
|
|
248
|
-
TIMEOUT: 408,
|
|
249
|
-
CONFLICT: 409,
|
|
250
|
-
PRECONDITION_FAILED: 412,
|
|
251
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
252
|
-
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
253
|
-
UNPROCESSABLE_CONTENT: 422,
|
|
254
|
-
PRECONDITION_REQUIRED: 428,
|
|
255
|
-
TOO_MANY_REQUESTS: 429,
|
|
256
|
-
CLIENT_CLOSED_REQUEST: 499,
|
|
257
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
258
|
-
NOT_IMPLEMENTED: 501,
|
|
259
|
-
BAD_GATEWAY: 502,
|
|
260
|
-
SERVICE_UNAVAILABLE: 503,
|
|
261
|
-
GATEWAY_TIMEOUT: 504
|
|
262
|
-
};
|
|
263
|
-
/** Extract Error from unknown cause (from tRPC) */
|
|
264
|
-
function getCauseFromUnknown(cause) {
|
|
265
|
-
if (cause instanceof Error) return cause;
|
|
266
|
-
if (typeof cause === "undefined" || typeof cause === "function" || cause === null) return;
|
|
267
|
-
if (typeof cause !== "object") return new Error(String(cause));
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* tRPC-style error extending ConvexError
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* ```typescript
|
|
274
|
-
* throw new CRPCError({
|
|
275
|
-
* code: 'BAD_REQUEST',
|
|
276
|
-
* message: 'Invalid input',
|
|
277
|
-
* cause: originalError,
|
|
278
|
-
* });
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
var CRPCError = class extends ConvexError {
|
|
282
|
-
code;
|
|
283
|
-
cause;
|
|
284
|
-
constructor(opts) {
|
|
285
|
-
const cause = getCauseFromUnknown(opts.cause);
|
|
286
|
-
const message = opts.message ?? cause?.message ?? opts.code;
|
|
287
|
-
super({
|
|
288
|
-
code: opts.code,
|
|
289
|
-
message
|
|
290
|
-
});
|
|
291
|
-
this.name = "CRPCError";
|
|
292
|
-
this.code = opts.code;
|
|
293
|
-
this.cause = cause;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
/**
|
|
297
|
-
* Wrap unknown error in CRPCError (from tRPC)
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```typescript
|
|
301
|
-
* try {
|
|
302
|
-
* await someOperation();
|
|
303
|
-
* } catch (error) {
|
|
304
|
-
* throw getCRPCErrorFromUnknown(error);
|
|
305
|
-
* }
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
function getCRPCErrorFromUnknown(cause) {
|
|
309
|
-
if (cause instanceof CRPCError) return cause;
|
|
310
|
-
if (cause instanceof Error && cause.name === "CRPCError") return cause;
|
|
311
|
-
const error = new CRPCError({
|
|
312
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
313
|
-
cause
|
|
314
|
-
});
|
|
315
|
-
if (cause instanceof Error && cause.stack) error.stack = cause.stack;
|
|
316
|
-
return error;
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Get HTTP status code from CRPCError
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```typescript
|
|
323
|
-
* const httpStatus = getHTTPStatusCodeFromError(error); // 400
|
|
324
|
-
* ```
|
|
325
|
-
*/
|
|
326
|
-
function getHTTPStatusCodeFromError(error) {
|
|
327
|
-
return CRPC_ERROR_CODE_TO_HTTP[error.code] ?? 500;
|
|
328
|
-
}
|
|
329
|
-
/** Type guard for CRPCError */
|
|
330
|
-
function isCRPCError(error) {
|
|
331
|
-
return error instanceof CRPCError;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
//#endregion
|
|
335
|
-
export { getHTTPStatusCodeFromError as a, createLazyCaller as c, getCRPCErrorFromUnknown as i, createServerCaller as l, CRPC_ERROR_CODES_BY_KEY as n, isCRPCError as o, CRPC_ERROR_CODE_TO_HTTP as r, createCallerFactory as s, CRPCError as t };
|
|
208
|
+
export { createLazyCaller as n, createServerCaller as r, createCallerFactory as t };
|
package/dist/crpc/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as PaginatedFnMeta, S as Meta, _ as ExtractPaginatedItem, a as ConvexInfiniteQueryMeta, b as InfiniteQueryInput, c as ConvexMutationKey, d as ConvexQueryMeta, f as ConvexQueryOptions, g as DecorateQuery, h as DecorateMutation, i as ConvexActionOptions, l as ConvexQueryHookOptions, m as DecorateInfiniteQuery, n as CRPCClient, o as ConvexInfiniteQueryOptions, p as DecorateAction, r as ConvexActionKey, s as ConvexInfiniteQueryOptionsWithRef, t as AuthType, u as ConvexQueryKey, v as FUNC_REF_SYMBOL, w as PaginationOpts, x as InfiniteQueryOptsParam, y as FnMeta } from "../types-
|
|
1
|
+
import { C as PaginatedFnMeta, S as Meta, _ as ExtractPaginatedItem, a as ConvexInfiniteQueryMeta, b as InfiniteQueryInput, c as ConvexMutationKey, d as ConvexQueryMeta, f as ConvexQueryOptions, g as DecorateQuery, h as DecorateMutation, i as ConvexActionOptions, l as ConvexQueryHookOptions, m as DecorateInfiniteQuery, n as CRPCClient, o as ConvexInfiniteQueryOptions, p as DecorateAction, r as ConvexActionKey, s as ConvexInfiniteQueryOptionsWithRef, t as AuthType, u as ConvexQueryKey, v as FUNC_REF_SYMBOL, w as PaginationOpts, x as InfiniteQueryOptsParam, y as FnMeta } from "../types-CotWvon8.js";
|
|
2
2
|
import { FunctionArgs, FunctionReference } from "convex/server";
|
|
3
3
|
|
|
4
4
|
//#region src/crpc/error.d.ts
|
|
@@ -24,6 +24,8 @@ declare class CRPCClientError extends Error {
|
|
|
24
24
|
declare const isCRPCClientError: (error: unknown) => error is CRPCClientError;
|
|
25
25
|
/** Type guard for specific error code */
|
|
26
26
|
declare const isCRPCErrorCode: (error: unknown, code: ClientErrorCode) => error is CRPCClientError;
|
|
27
|
+
/** Default unauthorized detection - checks UNAUTHORIZED code */
|
|
28
|
+
declare const defaultIsUnauthorized: (error: unknown) => boolean;
|
|
27
29
|
//#endregion
|
|
28
30
|
//#region src/crpc/query-options.d.ts
|
|
29
31
|
/**
|
|
@@ -65,4 +67,4 @@ declare function convexAction<T extends FunctionReference<'action'>>(funcRef: T,
|
|
|
65
67
|
*/
|
|
66
68
|
declare function convexInfiniteQueryOptions<T extends FunctionReference<'query'>>(funcRef: T, args: Record<string, unknown> | 'skip', opts?: InfiniteQueryOptsParam<T>, meta?: Meta): ConvexInfiniteQueryOptions<T>;
|
|
67
69
|
//#endregion
|
|
68
|
-
export { AuthType, CRPCClient, CRPCClientError, ConvexActionKey, ConvexActionOptions, ConvexInfiniteQueryMeta, ConvexInfiniteQueryOptions, ConvexInfiniteQueryOptionsWithRef, ConvexMutationKey, ConvexQueryHookOptions, ConvexQueryKey, ConvexQueryMeta, ConvexQueryOptions, DecorateAction, DecorateInfiniteQuery, DecorateMutation, DecorateQuery, ExtractPaginatedItem, FUNC_REF_SYMBOL, FnMeta, InfiniteQueryInput, InfiniteQueryOptsParam, Meta, PaginatedFnMeta, PaginationOpts, convexAction, convexInfiniteQueryOptions, convexQuery, isCRPCClientError, isCRPCErrorCode };
|
|
70
|
+
export { AuthType, CRPCClient, CRPCClientError, ConvexActionKey, ConvexActionOptions, ConvexInfiniteQueryMeta, ConvexInfiniteQueryOptions, ConvexInfiniteQueryOptionsWithRef, ConvexMutationKey, ConvexQueryHookOptions, ConvexQueryKey, ConvexQueryMeta, ConvexQueryOptions, DecorateAction, DecorateInfiniteQuery, DecorateMutation, DecorateQuery, ExtractPaginatedItem, FUNC_REF_SYMBOL, FnMeta, InfiniteQueryInput, InfiniteQueryOptsParam, Meta, PaginatedFnMeta, PaginationOpts, convexAction, convexInfiniteQueryOptions, convexQuery, defaultIsUnauthorized, isCRPCClientError, isCRPCErrorCode };
|
package/dist/crpc/index.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { i as isCRPCErrorCode, n as defaultIsUnauthorized, r as isCRPCClientError, t as CRPCClientError } from "../error-CsSzFKod.js";
|
|
2
|
+
import { n as convexInfiniteQueryOptions, r as convexQuery, t as convexAction } from "../query-options-sK2n1Ioe.js";
|
|
2
3
|
|
|
3
|
-
//#region src/crpc/error.ts
|
|
4
|
-
/**
|
|
5
|
-
* Client-side CRPC error.
|
|
6
|
-
* Mirrors backend CRPCError pattern with typed error codes.
|
|
7
|
-
*/
|
|
8
|
-
var CRPCClientError = class extends Error {
|
|
9
|
-
name = "CRPCClientError";
|
|
10
|
-
code;
|
|
11
|
-
functionName;
|
|
12
|
-
constructor(opts) {
|
|
13
|
-
super(opts.message ?? `${opts.code}: ${opts.functionName}`);
|
|
14
|
-
this.code = opts.code;
|
|
15
|
-
this.functionName = opts.functionName;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
/** Type guard for CRPCClientError */
|
|
19
|
-
const isCRPCClientError = (error) => error instanceof CRPCClientError;
|
|
20
|
-
/** Type guard for specific error code */
|
|
21
|
-
const isCRPCErrorCode = (error, code) => isCRPCClientError(error) && error.code === code;
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
4
|
//#region src/crpc/types.ts
|
|
25
5
|
/** Symbol key for attaching FunctionReference to options (non-serializable) */
|
|
26
6
|
const FUNC_REF_SYMBOL = Symbol.for("convex.funcRef");
|
|
27
7
|
|
|
28
8
|
//#endregion
|
|
29
|
-
export { CRPCClientError, FUNC_REF_SYMBOL, convexAction, convexInfiniteQueryOptions, convexQuery, isCRPCClientError, isCRPCErrorCode };
|
|
9
|
+
export { CRPCClientError, FUNC_REF_SYMBOL, convexAction, convexInfiniteQueryOptions, convexQuery, defaultIsUnauthorized, isCRPCClientError, isCRPCErrorCode };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/crpc/error.ts
|
|
2
|
+
/**
|
|
3
|
+
* Client-side CRPC error.
|
|
4
|
+
* Mirrors backend CRPCError pattern with typed error codes.
|
|
5
|
+
*/
|
|
6
|
+
var CRPCClientError = class extends Error {
|
|
7
|
+
name = "CRPCClientError";
|
|
8
|
+
code;
|
|
9
|
+
functionName;
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts.message ?? `${opts.code}: ${opts.functionName}`);
|
|
12
|
+
this.code = opts.code;
|
|
13
|
+
this.functionName = opts.functionName;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Type guard for CRPCClientError */
|
|
17
|
+
const isCRPCClientError = (error) => error instanceof CRPCClientError;
|
|
18
|
+
/** Type guard for specific error code */
|
|
19
|
+
const isCRPCErrorCode = (error, code) => isCRPCClientError(error) && error.code === code;
|
|
20
|
+
/** Default unauthorized detection - checks UNAUTHORIZED code */
|
|
21
|
+
const defaultIsUnauthorized = (error) => {
|
|
22
|
+
if (!error || typeof error !== "object") return false;
|
|
23
|
+
if ("data" in error) {
|
|
24
|
+
const data = error.data;
|
|
25
|
+
if (data && typeof data === "object" && "code" in data) return data.code === "UNAUTHORIZED";
|
|
26
|
+
}
|
|
27
|
+
if ("code" in error) return error.code === "UNAUTHORIZED";
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { isCRPCErrorCode as i, defaultIsUnauthorized as n, isCRPCClientError as r, CRPCClientError as t };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ type AuthClient = {
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
type AuthMutationsResult<T extends AuthClient> = {
|
|
25
|
-
useSignOutMutationOptions: MutationOptionsHook<Awaited<ReturnType<T['signOut']>>, Parameters<T['signOut']>[0]>;
|
|
25
|
+
useSignOutMutationOptions: MutationOptionsHook<Awaited<ReturnType<T['signOut']>>, Parameters<T['signOut']>[0] | void>;
|
|
26
26
|
useSignInSocialMutationOptions: MutationOptionsHook<Awaited<ReturnType<T['signIn']['social']>>, Parameters<T['signIn']['social']>[0]>;
|
|
27
27
|
useSignInMutationOptions: MutationOptionsHook<Awaited<ReturnType<T['signIn']['email']>>, Parameters<T['signIn']['email']>[0]>;
|
|
28
28
|
useSignUpMutationOptions: MutationOptionsHook<Awaited<ReturnType<T['signUp']['email']>>, Parameters<T['signUp']['email']>[0]>;
|
|
@@ -60,6 +60,8 @@ type AuthStoreState = {
|
|
|
60
60
|
onQueryUnauthorized: (info: {
|
|
61
61
|
queryName: string;
|
|
62
62
|
}) => void;
|
|
63
|
+
/** Custom function to detect UNAUTHORIZED errors. Default checks code or "auth" in message. */
|
|
64
|
+
isUnauthorized: (error: unknown) => boolean;
|
|
63
65
|
/** Current session token */
|
|
64
66
|
token: string | null;
|
|
65
67
|
/** Whether Convex auth is still loading (synced from useConvexAuth) */
|
|
@@ -78,6 +80,7 @@ declare const authStore$1: jotai_x0.StoreApi<AuthStoreState, object, "auth">, Au
|
|
|
78
80
|
onQueryUnauthorized: (info: {
|
|
79
81
|
queryName: string;
|
|
80
82
|
}) => void;
|
|
83
|
+
isUnauthorized: (error: unknown) => boolean;
|
|
81
84
|
token: string | null;
|
|
82
85
|
isLoading: boolean;
|
|
83
86
|
isAuthenticated: boolean;
|
|
@@ -87,6 +90,7 @@ declare const authStore$1: jotai_x0.StoreApi<AuthStoreState, object, "auth">, Au
|
|
|
87
90
|
onQueryUnauthorized: jotai_x0.SimpleWritableAtom<(info: {
|
|
88
91
|
queryName: string;
|
|
89
92
|
}) => void>;
|
|
93
|
+
isUnauthorized: jotai_x0.SimpleWritableAtom<(error: unknown) => boolean>;
|
|
90
94
|
token: jotai_x0.SimpleWritableAtom<string | null>;
|
|
91
95
|
isLoading: jotai_x0.SimpleWritableAtom<boolean>;
|
|
92
96
|
isAuthenticated: jotai_x0.SimpleWritableAtom<boolean>;
|
|
@@ -96,6 +100,7 @@ declare const authStore$1: jotai_x0.StoreApi<AuthStoreState, object, "auth">, Au
|
|
|
96
100
|
onQueryUnauthorized: jotai_x0.SimpleWritableAtom<(info: {
|
|
97
101
|
queryName: string;
|
|
98
102
|
}) => void>;
|
|
103
|
+
isUnauthorized: jotai_x0.SimpleWritableAtom<(error: unknown) => boolean>;
|
|
99
104
|
token: jotai_x0.SimpleWritableAtom<string | null>;
|
|
100
105
|
isLoading: jotai_x0.SimpleWritableAtom<boolean>;
|
|
101
106
|
isAuthenticated: jotai_x0.SimpleWritableAtom<boolean>;
|
|
@@ -106,6 +111,7 @@ declare const authStore$1: jotai_x0.StoreApi<AuthStoreState, object, "auth">, Au
|
|
|
106
111
|
onQueryUnauthorized: jotai_x0.SimpleWritableAtom<(info: {
|
|
107
112
|
queryName: string;
|
|
108
113
|
}) => void>;
|
|
114
|
+
isUnauthorized: jotai_x0.SimpleWritableAtom<(error: unknown) => boolean>;
|
|
109
115
|
token: jotai_x0.SimpleWritableAtom<string | null>;
|
|
110
116
|
isLoading: jotai_x0.SimpleWritableAtom<boolean>;
|
|
111
117
|
isAuthenticated: jotai_x0.SimpleWritableAtom<boolean>;
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { a as Unauthenticated, c as persistToken, d as useAuthState, f as useAuthStore, g as CRPCClientError, h as useMaybeAuth, i as MaybeUnauthenticated, l as useAuth, m as useIsAuth, n as Authenticated, o as authStore, p as useAuthValue, r as MaybeAuthenticated, s as getPersistedToken, t as AuthProvider, u as useAuthGuard, v as isCRPCClientError } from "../auth-store-DANFmEdk.js";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
4
|
import { ConvexProvider, ConvexReactClient, ConvexReactClient as ConvexReactClient$1, useAction, useMutation } from "convex/react";
|
|
5
5
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -1177,7 +1177,8 @@ var ConvexQueryClient = class {
|
|
|
1177
1177
|
return {
|
|
1178
1178
|
isAuthenticated: !!this.authStore.get("token"),
|
|
1179
1179
|
isLoading: this.authStore.get("isLoading"),
|
|
1180
|
-
onUnauthorized: this.authStore.get("onQueryUnauthorized")
|
|
1180
|
+
onUnauthorized: this.authStore.get("onQueryUnauthorized"),
|
|
1181
|
+
isUnauthorized: this.authStore.get("isUnauthorized")
|
|
1181
1182
|
};
|
|
1182
1183
|
}
|
|
1183
1184
|
/** Get QueryClient, throwing if not connected */
|
|
@@ -1273,6 +1274,8 @@ var ConvexQueryClient = class {
|
|
|
1273
1274
|
if (result.value !== null && result.value !== void 0 || !(existingData !== null && existingData !== void 0)) this.queryClient.setQueryData(queryKey, result.value);
|
|
1274
1275
|
} else {
|
|
1275
1276
|
const { error } = result;
|
|
1277
|
+
const authState = this.getAuthState();
|
|
1278
|
+
if (authState?.isLoading && authState.isUnauthorized(error)) return;
|
|
1276
1279
|
query.setState({
|
|
1277
1280
|
error,
|
|
1278
1281
|
errorUpdateCount: query.state.errorUpdateCount + 1,
|
|
@@ -1282,6 +1285,10 @@ var ConvexQueryClient = class {
|
|
|
1282
1285
|
fetchStatus: "idle",
|
|
1283
1286
|
status: "error"
|
|
1284
1287
|
}, { meta: "set by ConvexQueryClient" });
|
|
1288
|
+
if (authState?.isUnauthorized(error)) {
|
|
1289
|
+
const [, funcName] = queryKey;
|
|
1290
|
+
authState.onUnauthorized({ queryName: funcName });
|
|
1291
|
+
}
|
|
1285
1292
|
}
|
|
1286
1293
|
}
|
|
1287
1294
|
/**
|
|
@@ -1948,7 +1955,7 @@ function useInfiniteQuery(infiniteOptions) {
|
|
|
1948
1955
|
$[16] = result.error;
|
|
1949
1956
|
$[17] = t6;
|
|
1950
1957
|
} else t6 = $[17];
|
|
1951
|
-
const
|
|
1958
|
+
const isClientError = t6;
|
|
1952
1959
|
const isSkippedUnauth = isUnauthorized && skipUnauthFinal;
|
|
1953
1960
|
let t7;
|
|
1954
1961
|
if ($[18] !== isSkippedUnauth || $[19] !== result.data) {
|
|
@@ -1979,7 +1986,7 @@ function useInfiniteQuery(infiniteOptions) {
|
|
|
1979
1986
|
$[26] = isSkippedUnauth;
|
|
1980
1987
|
$[27] = t10;
|
|
1981
1988
|
} else t10 = $[27];
|
|
1982
|
-
const t11 = authLoadingApplies && isAuthLoading || !
|
|
1989
|
+
const t11 = authLoadingApplies && isAuthLoading || !isClientError && !authError && !isSkippedUnauth && result.isLoading;
|
|
1983
1990
|
let t12;
|
|
1984
1991
|
if ($[28] !== result || $[29] !== t10 || $[30] !== t11 || $[31] !== t7 || $[32] !== t8 || $[33] !== t9) {
|
|
1985
1992
|
t12 = {
|
package/dist/rsc/index.d.ts
CHANGED
package/dist/rsc/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as convexInfiniteQueryOptions, r as convexQuery } from "../query-options-
|
|
1
|
+
import { n as convexInfiniteQueryOptions, r as convexQuery } from "../query-options-sK2n1Ioe.js";
|
|
2
2
|
import { getFunctionName } from "convex/server";
|
|
3
3
|
import { convexToJson } from "convex/values";
|
|
4
4
|
import { fetchAction, fetchQuery } from "convex/nextjs";
|
package/dist/server/index.d.ts
CHANGED
|
@@ -450,22 +450,20 @@ type TokenResult = {
|
|
|
450
450
|
isFresh?: boolean;
|
|
451
451
|
};
|
|
452
452
|
type GetTokenFn = (siteUrl: string, headers: Headers, opts?: unknown) => Promise<TokenResult>;
|
|
453
|
-
/**
|
|
454
|
-
type
|
|
455
|
-
/**
|
|
456
|
-
|
|
457
|
-
/** Custom function to detect
|
|
458
|
-
|
|
453
|
+
/** Auth options for server-side calls. */
|
|
454
|
+
type AuthOptions = {
|
|
455
|
+
/** Function to extract auth token from request headers. */
|
|
456
|
+
getToken: GetTokenFn;
|
|
457
|
+
/** Custom function to detect UNAUTHORIZED errors. Default checks code property. */
|
|
458
|
+
isUnauthorized?: (error: unknown) => boolean;
|
|
459
459
|
};
|
|
460
460
|
type CreateCallerFactoryOptions<TApi> = {
|
|
461
461
|
/** Your Convex API object. */
|
|
462
462
|
api: TApi;
|
|
463
463
|
/** Convex site URL (must end in `.convex.site`). */
|
|
464
464
|
convexSiteUrl: string;
|
|
465
|
-
/**
|
|
466
|
-
|
|
467
|
-
/** JWT caching options for automatic token refresh. */
|
|
468
|
-
jwtCache?: JwtCacheOptions;
|
|
465
|
+
/** Auth options. Pass to enable authenticated calls with JWT caching. */
|
|
466
|
+
auth?: AuthOptions;
|
|
469
467
|
/** Procedure metadata. */
|
|
470
468
|
meta: CallerMeta;
|
|
471
469
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as createLazyCaller, r as createServerCaller, t as createCallerFactory } from "../caller-factory-DxmuY355.js";
|
|
2
|
+
import { ConvexError } from "convex/values";
|
|
2
3
|
import { customCtx } from "convex-helpers/server/customFunctions";
|
|
3
4
|
import { zCustomAction, zCustomMutation, zCustomQuery } from "convex-helpers/server/zod4";
|
|
4
5
|
import { z } from "zod";
|
|
@@ -400,5 +401,131 @@ const initCRPC = {
|
|
|
400
401
|
}
|
|
401
402
|
};
|
|
402
403
|
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/server/error.ts
|
|
406
|
+
/**
|
|
407
|
+
* CRPC Error - tRPC-style error handling for Convex
|
|
408
|
+
*
|
|
409
|
+
* Extends ConvexError with typed error codes and HTTP status mapping.
|
|
410
|
+
*/
|
|
411
|
+
/** JSON-RPC 2.0 error codes (tRPC-style) */
|
|
412
|
+
const CRPC_ERROR_CODES_BY_KEY = {
|
|
413
|
+
PARSE_ERROR: -32700,
|
|
414
|
+
BAD_REQUEST: -32600,
|
|
415
|
+
INTERNAL_SERVER_ERROR: -32603,
|
|
416
|
+
NOT_IMPLEMENTED: -32603,
|
|
417
|
+
BAD_GATEWAY: -32603,
|
|
418
|
+
SERVICE_UNAVAILABLE: -32603,
|
|
419
|
+
GATEWAY_TIMEOUT: -32603,
|
|
420
|
+
UNAUTHORIZED: -32001,
|
|
421
|
+
PAYMENT_REQUIRED: -32002,
|
|
422
|
+
FORBIDDEN: -32003,
|
|
423
|
+
NOT_FOUND: -32004,
|
|
424
|
+
METHOD_NOT_SUPPORTED: -32005,
|
|
425
|
+
TIMEOUT: -32008,
|
|
426
|
+
CONFLICT: -32009,
|
|
427
|
+
PRECONDITION_FAILED: -32012,
|
|
428
|
+
PAYLOAD_TOO_LARGE: -32013,
|
|
429
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
430
|
+
UNPROCESSABLE_CONTENT: -32022,
|
|
431
|
+
PRECONDITION_REQUIRED: -32028,
|
|
432
|
+
TOO_MANY_REQUESTS: -32029,
|
|
433
|
+
CLIENT_CLOSED_REQUEST: -32099
|
|
434
|
+
};
|
|
435
|
+
/** Map error codes to HTTP status codes */
|
|
436
|
+
const CRPC_ERROR_CODE_TO_HTTP = {
|
|
437
|
+
PARSE_ERROR: 400,
|
|
438
|
+
BAD_REQUEST: 400,
|
|
439
|
+
UNAUTHORIZED: 401,
|
|
440
|
+
PAYMENT_REQUIRED: 402,
|
|
441
|
+
FORBIDDEN: 403,
|
|
442
|
+
NOT_FOUND: 404,
|
|
443
|
+
METHOD_NOT_SUPPORTED: 405,
|
|
444
|
+
TIMEOUT: 408,
|
|
445
|
+
CONFLICT: 409,
|
|
446
|
+
PRECONDITION_FAILED: 412,
|
|
447
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
448
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
449
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
450
|
+
PRECONDITION_REQUIRED: 428,
|
|
451
|
+
TOO_MANY_REQUESTS: 429,
|
|
452
|
+
CLIENT_CLOSED_REQUEST: 499,
|
|
453
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
454
|
+
NOT_IMPLEMENTED: 501,
|
|
455
|
+
BAD_GATEWAY: 502,
|
|
456
|
+
SERVICE_UNAVAILABLE: 503,
|
|
457
|
+
GATEWAY_TIMEOUT: 504
|
|
458
|
+
};
|
|
459
|
+
/** Extract Error from unknown cause (from tRPC) */
|
|
460
|
+
function getCauseFromUnknown(cause) {
|
|
461
|
+
if (cause instanceof Error) return cause;
|
|
462
|
+
if (typeof cause === "undefined" || typeof cause === "function" || cause === null) return;
|
|
463
|
+
if (typeof cause !== "object") return new Error(String(cause));
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* tRPC-style error extending ConvexError
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* throw new CRPCError({
|
|
471
|
+
* code: 'BAD_REQUEST',
|
|
472
|
+
* message: 'Invalid input',
|
|
473
|
+
* cause: originalError,
|
|
474
|
+
* });
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
var CRPCError = class extends ConvexError {
|
|
478
|
+
code;
|
|
479
|
+
cause;
|
|
480
|
+
constructor(opts) {
|
|
481
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
482
|
+
const message = opts.message ?? cause?.message ?? opts.code;
|
|
483
|
+
super({
|
|
484
|
+
code: opts.code,
|
|
485
|
+
message
|
|
486
|
+
});
|
|
487
|
+
this.name = "CRPCError";
|
|
488
|
+
this.code = opts.code;
|
|
489
|
+
this.cause = cause;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* Wrap unknown error in CRPCError (from tRPC)
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* try {
|
|
498
|
+
* await someOperation();
|
|
499
|
+
* } catch (error) {
|
|
500
|
+
* throw getCRPCErrorFromUnknown(error);
|
|
501
|
+
* }
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
function getCRPCErrorFromUnknown(cause) {
|
|
505
|
+
if (cause instanceof CRPCError) return cause;
|
|
506
|
+
if (cause instanceof Error && cause.name === "CRPCError") return cause;
|
|
507
|
+
const error = new CRPCError({
|
|
508
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
509
|
+
cause
|
|
510
|
+
});
|
|
511
|
+
if (cause instanceof Error && cause.stack) error.stack = cause.stack;
|
|
512
|
+
return error;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Get HTTP status code from CRPCError
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* const httpStatus = getHTTPStatusCodeFromError(error); // 400
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
function getHTTPStatusCodeFromError(error) {
|
|
523
|
+
return CRPC_ERROR_CODE_TO_HTTP[error.code] ?? 500;
|
|
524
|
+
}
|
|
525
|
+
/** Type guard for CRPCError */
|
|
526
|
+
function isCRPCError(error) {
|
|
527
|
+
return error instanceof CRPCError;
|
|
528
|
+
}
|
|
529
|
+
|
|
403
530
|
//#endregion
|
|
404
531
|
export { ActionProcedureBuilder, CRPCError, CRPC_ERROR_CODES_BY_KEY, CRPC_ERROR_CODE_TO_HTTP, MutationProcedureBuilder, ProcedureBuilder, QueryProcedureBuilder, createCallerFactory, createLazyCaller, createMiddlewareFactory, createServerCaller, getCRPCErrorFromUnknown, getHTTPStatusCodeFromError, initCRPC, isCRPCError };
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|