better-convex 0.6.1 → 0.6.2
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 +16 -16
- package/dist/auth/index.js +41 -2
- package/dist/orm/index.d.ts +6 -6
- package/package.json +1 -1
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as GenericCtx } from "../context-utils-DSuX99Da.js";
|
|
2
2
|
import { convex } from "@convex-dev/better-auth/plugins";
|
|
3
|
-
import * as
|
|
3
|
+
import * as better_auth_adapters1 from "better-auth/adapters";
|
|
4
4
|
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
5
5
|
import { BetterAuthDBSchema } from "better-auth/db";
|
|
6
6
|
import * as convex_server24 from "convex/server";
|
|
@@ -45,19 +45,19 @@ declare const createClient: <DataModel extends GenericDataModel, Schema extends
|
|
|
45
45
|
}) => {
|
|
46
46
|
authFunctions: AuthFunctions;
|
|
47
47
|
triggers: Triggers<DataModel, Schema, TriggerCtx> | undefined;
|
|
48
|
-
adapter: (ctx: GenericCtx<DataModel>, getAuthOptions: (ctx: any) => BetterAuthOptions) =>
|
|
48
|
+
adapter: (ctx: GenericCtx<DataModel>, getAuthOptions: (ctx: any) => BetterAuthOptions) => better_auth_adapters1.AdapterFactory;
|
|
49
49
|
triggersApi: () => {
|
|
50
50
|
beforeCreate: convex_server24.RegisteredMutation<"internal", {
|
|
51
|
-
model: string;
|
|
52
51
|
data: any;
|
|
52
|
+
model: string;
|
|
53
53
|
}, Promise<any>>;
|
|
54
54
|
beforeDelete: convex_server24.RegisteredMutation<"internal", {
|
|
55
55
|
model: string;
|
|
56
56
|
doc: any;
|
|
57
57
|
}, Promise<any>>;
|
|
58
58
|
beforeUpdate: convex_server24.RegisteredMutation<"internal", {
|
|
59
|
-
model: string;
|
|
60
59
|
update: any;
|
|
60
|
+
model: string;
|
|
61
61
|
doc: any;
|
|
62
62
|
}, Promise<any>>;
|
|
63
63
|
onCreate: convex_server24.RegisteredMutation<"internal", {
|
|
@@ -150,7 +150,7 @@ declare const httpAdapter: <DataModel extends GenericDataModel, Schema extends S
|
|
|
150
150
|
debugLogs?: DBAdapterDebugLogOption;
|
|
151
151
|
schema?: Schema;
|
|
152
152
|
triggers?: Triggers<DataModel, Schema>;
|
|
153
|
-
}) =>
|
|
153
|
+
}) => better_auth_adapters1.AdapterFactory;
|
|
154
154
|
declare const dbAdapter: <DataModel extends GenericDataModel, Schema extends SchemaDefinition<any, any>>(ctx: GenericCtx<DataModel>, getAuthOptions: (ctx: any) => BetterAuthOptions, {
|
|
155
155
|
authFunctions,
|
|
156
156
|
debugLogs,
|
|
@@ -161,7 +161,7 @@ declare const dbAdapter: <DataModel extends GenericDataModel, Schema extends Sch
|
|
|
161
161
|
schema: Schema;
|
|
162
162
|
debugLogs?: DBAdapterDebugLogOption;
|
|
163
163
|
triggers?: Triggers<DataModel, Schema>;
|
|
164
|
-
}) =>
|
|
164
|
+
}) => better_auth_adapters1.AdapterFactory;
|
|
165
165
|
//#endregion
|
|
166
166
|
//#region src/auth/adapter-utils.d.ts
|
|
167
167
|
type AdapterPaginationOptions = PaginationOptions & {
|
|
@@ -181,8 +181,8 @@ declare const adapterWhereValidator: convex_values0.VObject<{
|
|
|
181
181
|
}, "required", "connector" | "field" | "operator" | "value">;
|
|
182
182
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
183
183
|
limit?: number | undefined;
|
|
184
|
-
offset?: number | undefined;
|
|
185
184
|
select?: string[] | undefined;
|
|
185
|
+
offset?: number | undefined;
|
|
186
186
|
sortBy?: {
|
|
187
187
|
field: string;
|
|
188
188
|
direction: "asc" | "desc";
|
|
@@ -222,7 +222,7 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
222
222
|
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "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>;
|
|
223
223
|
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>;
|
|
224
224
|
}, "required", "connector" | "field" | "operator" | "value">, "optional">;
|
|
225
|
-
}, "required", "limit" | "model" | "
|
|
225
|
+
}, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.field" | "sortBy.direction">;
|
|
226
226
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
227
227
|
declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
|
|
228
228
|
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => Promise<D | null>;
|
|
@@ -324,15 +324,15 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
324
324
|
beforeCreateHandle?: string | undefined;
|
|
325
325
|
onCreateHandle?: string | undefined;
|
|
326
326
|
input: {
|
|
327
|
-
model: string;
|
|
328
327
|
data: any;
|
|
329
|
-
} | {
|
|
330
328
|
model: string;
|
|
329
|
+
} | {
|
|
331
330
|
data: {
|
|
332
331
|
[x: string]: unknown;
|
|
333
332
|
[x: number]: unknown;
|
|
334
333
|
[x: symbol]: unknown;
|
|
335
334
|
};
|
|
335
|
+
model: string;
|
|
336
336
|
};
|
|
337
337
|
}, Promise<any>>;
|
|
338
338
|
deleteMany: convex_server24.RegisteredMutation<"internal", {
|
|
@@ -383,8 +383,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
383
383
|
};
|
|
384
384
|
}, Promise<convex_server24.GenericDocument | undefined>>;
|
|
385
385
|
findMany: convex_server24.RegisteredQuery<"internal", {
|
|
386
|
-
join?: any;
|
|
387
386
|
limit?: number | undefined;
|
|
387
|
+
join?: any;
|
|
388
388
|
offset?: number | undefined;
|
|
389
389
|
sortBy?: {
|
|
390
390
|
field: string;
|
|
@@ -396,7 +396,6 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
396
396
|
field: string;
|
|
397
397
|
value: string | number | boolean | string[] | number[] | null;
|
|
398
398
|
}[] | undefined;
|
|
399
|
-
model: string;
|
|
400
399
|
paginationOpts: {
|
|
401
400
|
id?: number;
|
|
402
401
|
endCursor?: string | null;
|
|
@@ -405,6 +404,7 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
405
404
|
numItems: number;
|
|
406
405
|
cursor: string | null;
|
|
407
406
|
};
|
|
407
|
+
model: string;
|
|
408
408
|
}, Promise<convex_server24.PaginationResult<convex_server24.GenericDocument>>>;
|
|
409
409
|
findOne: convex_server24.RegisteredQuery<"internal", {
|
|
410
410
|
join?: any;
|
|
@@ -430,8 +430,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
430
430
|
};
|
|
431
431
|
input: {
|
|
432
432
|
where?: any[] | undefined;
|
|
433
|
-
model: string;
|
|
434
433
|
update: any;
|
|
434
|
+
model: string;
|
|
435
435
|
} | {
|
|
436
436
|
where?: {
|
|
437
437
|
connector?: "AND" | "OR" | undefined;
|
|
@@ -439,12 +439,12 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
439
439
|
field: string;
|
|
440
440
|
value: string | number | boolean | string[] | number[] | null;
|
|
441
441
|
}[] | undefined;
|
|
442
|
-
model: string;
|
|
443
442
|
update: {
|
|
444
443
|
[x: string]: unknown;
|
|
445
444
|
[x: number]: unknown;
|
|
446
445
|
[x: symbol]: unknown;
|
|
447
446
|
};
|
|
447
|
+
model: string;
|
|
448
448
|
};
|
|
449
449
|
}, Promise<{
|
|
450
450
|
count: number;
|
|
@@ -459,8 +459,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
459
459
|
onUpdateHandle?: string | undefined;
|
|
460
460
|
input: {
|
|
461
461
|
where?: any[] | undefined;
|
|
462
|
-
model: string;
|
|
463
462
|
update: any;
|
|
463
|
+
model: string;
|
|
464
464
|
} | {
|
|
465
465
|
where?: {
|
|
466
466
|
connector?: "AND" | "OR" | undefined;
|
|
@@ -468,12 +468,12 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>>(schema: Sch
|
|
|
468
468
|
field: string;
|
|
469
469
|
value: string | number | boolean | string[] | number[] | null;
|
|
470
470
|
}[] | undefined;
|
|
471
|
-
model: string;
|
|
472
471
|
update: {
|
|
473
472
|
[x: string]: unknown;
|
|
474
473
|
[x: number]: unknown;
|
|
475
474
|
[x: symbol]: unknown;
|
|
476
475
|
};
|
|
476
|
+
model: string;
|
|
477
477
|
};
|
|
478
478
|
}, Promise<any>>;
|
|
479
479
|
getLatestJwks: convex_server24.RegisteredAction<"internal", {}, Promise<any>>;
|
package/dist/auth/index.js
CHANGED
|
@@ -1098,6 +1098,29 @@ const getHeaders = async (ctx, session) => {
|
|
|
1098
1098
|
});
|
|
1099
1099
|
};
|
|
1100
1100
|
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/auth/error-response.ts
|
|
1103
|
+
const isApiErrorLike = (error) => !!error && typeof error === "object" && (error.name === "APIError" && "statusCode" in error || typeof error.statusCode === "number");
|
|
1104
|
+
const toResponseInit = (error) => {
|
|
1105
|
+
const init = {
|
|
1106
|
+
headers: new Headers(error.headers ?? {}),
|
|
1107
|
+
status: typeof error.statusCode === "number" ? error.statusCode : 500
|
|
1108
|
+
};
|
|
1109
|
+
if (typeof error.status === "string") init.statusText = error.status;
|
|
1110
|
+
return init;
|
|
1111
|
+
};
|
|
1112
|
+
const toAuthErrorResponse = (error) => {
|
|
1113
|
+
if (!isApiErrorLike(error)) return null;
|
|
1114
|
+
const init = toResponseInit(error);
|
|
1115
|
+
const { body } = error;
|
|
1116
|
+
if (body === void 0) return new Response(null, init);
|
|
1117
|
+
if (typeof body === "string") {
|
|
1118
|
+
if (init.headers instanceof Headers && !init.headers.has("content-type")) init.headers.set("content-type", "text/plain");
|
|
1119
|
+
return new Response(body, init);
|
|
1120
|
+
}
|
|
1121
|
+
return Response.json(body, init);
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1101
1124
|
//#endregion
|
|
1102
1125
|
//#region src/auth/middleware.ts
|
|
1103
1126
|
/**
|
|
@@ -1123,7 +1146,15 @@ function authMiddleware(getAuth, opts = {}) {
|
|
|
1123
1146
|
if (c.req.path === "/.well-known/openid-configuration") return c.redirect(`${process.env.CONVEX_SITE_URL}${basePath}/convex/.well-known/openid-configuration`);
|
|
1124
1147
|
if (c.req.path.startsWith(basePath)) {
|
|
1125
1148
|
if (opts.verbose) console.log("request headers", c.req.raw.headers);
|
|
1126
|
-
const
|
|
1149
|
+
const auth = getAuth(c.env);
|
|
1150
|
+
let response;
|
|
1151
|
+
try {
|
|
1152
|
+
response = await auth.handler(c.req.raw);
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
const errorResponse = toAuthErrorResponse(error);
|
|
1155
|
+
if (errorResponse) return errorResponse;
|
|
1156
|
+
throw error;
|
|
1157
|
+
}
|
|
1127
1158
|
if (opts.verbose) console.log("response headers", response.headers);
|
|
1128
1159
|
return response;
|
|
1129
1160
|
}
|
|
@@ -1395,7 +1426,15 @@ const registerRoutes = (http, getAuth, opts = {}) => {
|
|
|
1395
1426
|
console.log("options.baseURL", staticAuth.options.baseURL);
|
|
1396
1427
|
console.log("request headers", request.headers);
|
|
1397
1428
|
}
|
|
1398
|
-
const
|
|
1429
|
+
const auth = getAuth(ctx);
|
|
1430
|
+
let response;
|
|
1431
|
+
try {
|
|
1432
|
+
response = await auth.handler(request);
|
|
1433
|
+
} catch (error) {
|
|
1434
|
+
const errorResponse = toAuthErrorResponse(error);
|
|
1435
|
+
if (errorResponse) return errorResponse;
|
|
1436
|
+
throw error;
|
|
1437
|
+
}
|
|
1399
1438
|
if (opts?.verbose) console.log("response headers", response.headers);
|
|
1400
1439
|
return response;
|
|
1401
1440
|
});
|
package/dist/orm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as ReturnTypeOrValue, i as KnownKeysOnly, o as Simplify, t as Assume } from "../types-jftzhhuc.js";
|
|
2
2
|
import { DefineSchemaOptions, DefineSchemaOptions as DefineSchemaOptions$1, FilterExpression as FilterExpression$1, GenericDatabaseReader, GenericDatabaseWriter, GenericIndexFields, GenericSchema, GenericSchema as GenericSchema$1, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IndexRange, IndexRangeBuilder, SchedulableFunctionReference, Scheduler, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, TableDefinition, VectorFilterBuilder, internalMutationGeneric } from "convex/server";
|
|
3
|
-
import * as
|
|
3
|
+
import * as convex_values63 from "convex/values";
|
|
4
4
|
import { GenericId, Validator, Value } from "convex/values";
|
|
5
5
|
|
|
6
6
|
//#region src/orm/builders/column-builder.d.ts
|
|
@@ -390,7 +390,7 @@ declare function custom<TName extends string, TValidator extends AnyValidator>(n
|
|
|
390
390
|
*
|
|
391
391
|
* Note: This is Convex JSON (runtime `v.any()`), not SQL JSON/JSONB.
|
|
392
392
|
*/
|
|
393
|
-
declare function json<T = Value>(): $Type<ConvexCustomBuilderInitial<"",
|
|
393
|
+
declare function json<T = Value>(): $Type<ConvexCustomBuilderInitial<"", convex_values63.VAny<any, "required", string>>, T>;
|
|
394
394
|
//#endregion
|
|
395
395
|
//#region src/orm/builders/date.d.ts
|
|
396
396
|
type ConvexDateMode = 'string' | 'date';
|
|
@@ -523,12 +523,12 @@ declare class ConvexSystemIdBuilder<_TTableName extends string> extends ColumnBu
|
|
|
523
523
|
static readonly [entityKind]: string;
|
|
524
524
|
readonly [entityKind]: string;
|
|
525
525
|
constructor();
|
|
526
|
-
build():
|
|
526
|
+
build(): convex_values63.VString<string, "required">;
|
|
527
527
|
/**
|
|
528
528
|
* Convex validator - runtime access
|
|
529
529
|
* System fields use v.string() for _id
|
|
530
530
|
*/
|
|
531
|
-
get convexValidator():
|
|
531
|
+
get convexValidator(): convex_values63.VString<string, "required">;
|
|
532
532
|
}
|
|
533
533
|
type ConvexSystemCreatedAtConfig = ColumnBuilderBaseConfig<'number', 'ConvexSystemCreatedAt'> & {
|
|
534
534
|
data: number;
|
|
@@ -541,8 +541,8 @@ declare class ConvexSystemCreatedAtBuilder extends ColumnBuilder<ConvexSystemCre
|
|
|
541
541
|
static readonly [entityKind]: string;
|
|
542
542
|
readonly [entityKind]: string;
|
|
543
543
|
constructor();
|
|
544
|
-
build():
|
|
545
|
-
get convexValidator():
|
|
544
|
+
build(): convex_values63.VFloat64<number, "required">;
|
|
545
|
+
get convexValidator(): convex_values63.VFloat64<number, "required">;
|
|
546
546
|
}
|
|
547
547
|
/**
|
|
548
548
|
* Create system field builders for a table
|