kitcn 0.33.12 → 0.34.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/CHANGELOG.md +63 -0
- package/dist/aggregate/index.d.ts +1 -1
- package/dist/aggregate/index.js +2 -2
- package/dist/auth/generated/index.d.ts +1 -1
- package/dist/auth/index.d.ts +37 -20
- package/dist/auth/index.js +40 -3
- package/dist/cli.mjs +326 -141
- package/dist/{definitions-n-CgVbZb.js → definitions-moOcjYL-.js} +2 -2
- package/dist/{extensions-Bp0XHanR.js → extensions-CKfn_Qi-.js} +1 -1
- package/dist/{generated-contract-disabled-EEz35c4P.d.ts → generated-contract-disabled-78J7oFCT.d.ts} +42 -42
- package/dist/{index-utils-DvK7P6Q1.js → index-utils-COOY08yW.js} +1 -1
- package/dist/{local-env-nNg6w6m5.mjs → local-env-wuMk1Mo7.mjs} +286 -165
- package/dist/orm/aggregate-index/index.js +4 -4
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js +132 -83
- package/dist/orm/migrations/index.d.ts +1 -1
- package/dist/orm/migrations/index.js +1 -1
- package/dist/{runtime-D60Ss1yA.js → runtime-BDgBpBg4.js} +1 -1
- package/dist/{schema-m04X6AL_.js → schema-CFklsQxQ.js} +5 -5
- package/dist/{schema-DpYdVxNn.js → schema-D0l-RIbL.js} +1 -1
- package/dist/{symbols-DDNAddkd.js → symbols-h1M2uuSB.js} +2 -1
- package/dist/{table-mQfS8B1J.js → table-Bh9i5LCc.js} +200 -108
- package/dist/watcher.mjs +1 -1
- package/dist/{where-clause-compiler-D67bItsZ.d.ts → where-clause-compiler-dGV0ALDz.d.ts} +141 -141
- package/package.json +2 -2
- package/skills/kitcn/references/features/auth.md +9 -0
- package/skills/kitcn/references/setup/index.md +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# kitcn
|
|
2
2
|
|
|
3
|
+
## 0.34.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#494](https://github.com/udecode/kitcn/pull/494) [`182403a`](https://github.com/udecode/kitcn/commit/182403a7c4c6976a96b1fdbaf842bfa98904386e) Thanks [@EfficiencyCorp](https://github.com/EfficiencyCorp)! - ## Breaking changes
|
|
8
|
+
|
|
9
|
+
- Build ORM tables on first use. `convexTable(...)` no longer throws definition errors (invalid indexes, constraints, extra config). They throw when the schema is pushed, when `kitcn codegen` runs, or when `schema.export()` is called.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before: throws here
|
|
13
|
+
const posts = convexTable("posts", { text: text() }, () => [
|
|
14
|
+
searchIndex("s"),
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
// After: throws on push and codegen, or in a test with schema.export()
|
|
18
|
+
const schema = defineSchema({ posts });
|
|
19
|
+
schema.export();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- Reference columns in extra config through the table argument. A column builder variable shared across tables and used directly in an index throws an ownership error at push.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// Before
|
|
26
|
+
const tenantId = text().notNull();
|
|
27
|
+
const a = convexTable("a", { tenantId }, () => [index("a_t").on(tenantId)]);
|
|
28
|
+
|
|
29
|
+
// After
|
|
30
|
+
const a = convexTable("a", { tenantId }, (t) => [
|
|
31
|
+
index("a_t").on(t.tenantId),
|
|
32
|
+
]);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- Require `rlsPolicy(...).link(table)` at module scope, in `schema.ts` or in the module that declares the table. A linked policy applies to its table as soon as it is linked.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// Before: linked inside another table's extra config
|
|
39
|
+
const posts = convexTable("posts", { body: text() }, () => [
|
|
40
|
+
rlsPolicy("read_users", { for: "select" }).link(users),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
// After: link at module scope
|
|
44
|
+
export const readUsers = rlsPolicy("read_users", { for: "select" }).link(
|
|
45
|
+
users
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Patches
|
|
50
|
+
|
|
51
|
+
- Preserve self-referencing foreign keys whose callbacks read table metadata through `getTableConfig`.
|
|
52
|
+
- Preserve foreign-key targets and required fields when column builders are reused across tables or in a discriminator.
|
|
53
|
+
- Improve cold Convex function start: a query or insert builds only the tables it touches, and query contexts no longer build every table's query builder and foreign-key graph. The first update or delete still reads every table's foreign keys, and `createOrm` without the aggregate capability still builds every table.
|
|
54
|
+
- Fix broken `references(() => ...)` callbacks surfacing on the first ORM call instead of on push, and passing on a retry.
|
|
55
|
+
- Improve `kitcn codegen` speed on large projects: a module that many Convex modules import evaluates once per run instead of once per importer.
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- [#495](https://github.com/udecode/kitcn/pull/495) [`a2eb3fe`](https://github.com/udecode/kitcn/commit/a2eb3fee2bfa51191715ae6b99df0980570af47c) Thanks [@EfficiencyCorp](https://github.com/EfficiencyCorp)! - ## Patches
|
|
60
|
+
|
|
61
|
+
- Support Convex 1.50.x and 1.51.x in `kitcn`. New apps install Convex 1.51.0.
|
|
62
|
+
- Support `--env-file` in standalone `kitcn init` and `kitcn codegen` to generate bindings against an existing deployment while keeping the project default.
|
|
63
|
+
- Fix `kitcn dev --env-file` using a different Convex account during initialization or environment sync than during the main dev process.
|
|
64
|
+
- Fix Better Auth creates that carry their own id (`forceAllowId`) failing with `` Unexpected field `_id` ``: organization invitations on Better Auth 1.7.16 with default options, and `reserveVerificationValue` (magic link and email OTP for unverified users, SIWE, SAML). The row now gets its Convex id, and Better Auth reads it back under that id. A second `reserveVerificationValue` for the same identifier is still refused while the first row exists. A forced-id `oauthClientAssertion` create (`private_key_jwt`) is refused, so a replayed assertion cannot get in.
|
|
65
|
+
|
|
3
66
|
## 0.33.12
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Vn as ConvexTextBuilderInitial, Zt as ConvexTableWithColumns } from "../capabilities-Bxzoofl4.js";
|
|
2
|
-
import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-
|
|
2
|
+
import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-dGV0ALDz.js";
|
|
3
3
|
import * as convex_values0 from "convex/values";
|
|
4
4
|
import { GenericId, Infer, Value } from "convex/values";
|
|
5
5
|
import { DocumentByName, GenericDataModel, GenericDatabaseReader, GenericDatabaseWriter, TableNamesInDataModel } from "convex/server";
|
package/dist/aggregate/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as TableAggregate$1, t as DirectAggregate$1 } from "../runtime-
|
|
2
|
-
import { i as aggregateStorageTables } from "../schema-
|
|
1
|
+
import { n as TableAggregate$1, t as DirectAggregate$1 } from "../runtime-BDgBpBg4.js";
|
|
2
|
+
import { i as aggregateStorageTables } from "../schema-D0l-RIbL.js";
|
|
3
3
|
|
|
4
4
|
//#region src/aggregate/index.ts
|
|
5
5
|
const wrapTriggerFactory = (methodName, factory) => ((...args) => {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as GenericAuthTriggerHandlers, S as GenericAuthTriggerChange, T as defineAuth, b as GenericAuthBeforeResult, i as getGeneratedAuthDisabledReason, n as GeneratedAuthDisabledReasonKind, r as createDisabledAuthRuntime, t as AuthRuntime, w as GenericAuthTriggers, x as GenericAuthDefinition, y as BetterAuthOptionsWithoutDatabase } from "../../generated-contract-disabled-
|
|
1
|
+
import { C as GenericAuthTriggerHandlers, S as GenericAuthTriggerChange, T as defineAuth, b as GenericAuthBeforeResult, i as getGeneratedAuthDisabledReason, n as GeneratedAuthDisabledReasonKind, r as createDisabledAuthRuntime, t as AuthRuntime, w as GenericAuthTriggers, x as GenericAuthDefinition, y as BetterAuthOptionsWithoutDatabase } from "../../generated-contract-disabled-78J7oFCT.js";
|
|
2
2
|
export { type AuthRuntime, BetterAuthOptionsWithoutDatabase, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, createDisabledAuthRuntime, defineAuth, getGeneratedAuthDisabledReason };
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as QueryCtxWithPreferredOrmQueryTable, n as LookupByIdResultByCtx, t as DocByCtx } from "../query-context-BkNjkDCk.js";
|
|
2
2
|
import { t as GetAuth } from "../types-ex0-J-SC.js";
|
|
3
3
|
import { t as GenericCtx } from "../context-utils-Cbv4r0AA.js";
|
|
4
|
-
import { C as GenericAuthTriggerHandlers, S as GenericAuthTriggerChange, T as defineAuth, _ as updateManyHandler, a as AuthFunctions, b as GenericAuthBeforeResult, c as consumeOneHandler, d as createHandler, f as deleteManyHandler, g as incrementOneHandler, h as findOneHandler, i as getGeneratedAuthDisabledReason, l as countHandler, m as findManyHandler, n as GeneratedAuthDisabledReasonKind, o as Triggers, p as deleteOneHandler, r as createDisabledAuthRuntime, s as createClient, t as AuthRuntime, u as createApi, v as updateOneHandler, w as GenericAuthTriggers, x as GenericAuthDefinition, y as BetterAuthOptionsWithoutDatabase } from "../generated-contract-disabled-
|
|
4
|
+
import { C as GenericAuthTriggerHandlers, S as GenericAuthTriggerChange, T as defineAuth, _ as updateManyHandler, a as AuthFunctions, b as GenericAuthBeforeResult, c as consumeOneHandler, d as createHandler, f as deleteManyHandler, g as incrementOneHandler, h as findOneHandler, i as getGeneratedAuthDisabledReason, l as countHandler, m as findManyHandler, n as GeneratedAuthDisabledReasonKind, o as Triggers, p as deleteOneHandler, r as createDisabledAuthRuntime, s as createClient, t as AuthRuntime, u as createApi, v as updateOneHandler, w as GenericAuthTriggers, x as GenericAuthDefinition, y as BetterAuthOptionsWithoutDatabase } from "../generated-contract-disabled-78J7oFCT.js";
|
|
5
5
|
import * as convex_values0 from "convex/values";
|
|
6
6
|
import { Infer } from "convex/values";
|
|
7
7
|
import { AuthConfig, DocumentByName, GenericDataModel, GenericMutationCtx, GenericQueryCtx, GenericSchema, PaginationOptions, PaginationResult, SchemaDefinition, TableNamesInDataModel } from "convex/server";
|
|
@@ -109,31 +109,31 @@ type AdapterPaginationOptions = PaginationOptions & {
|
|
|
109
109
|
};
|
|
110
110
|
declare const adapterWhereValidator: convex_values0.VObject<{
|
|
111
111
|
mode?: "sensitive" | "insensitive" | undefined;
|
|
112
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
113
112
|
connector?: "AND" | "OR" | undefined;
|
|
114
|
-
|
|
113
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
115
114
|
field: string;
|
|
115
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
116
116
|
}, {
|
|
117
117
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
118
118
|
field: convex_values0.VString<string, "required">;
|
|
119
119
|
mode: convex_values0.VUnion<"sensitive" | "insensitive" | undefined, [convex_values0.VLiteral<"sensitive", "required">, convex_values0.VLiteral<"insensitive", "required">], "optional", never>;
|
|
120
|
-
operator: convex_values0.VUnion<"
|
|
120
|
+
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>;
|
|
121
121
|
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>;
|
|
122
|
-
}, "required", "mode" | "
|
|
122
|
+
}, "required", "mode" | "connector" | "field" | "operator" | "value">;
|
|
123
123
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
124
|
-
limit?: number | undefined;
|
|
125
124
|
where?: {
|
|
126
125
|
mode?: "sensitive" | "insensitive" | undefined;
|
|
127
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
128
126
|
connector?: "AND" | "OR" | undefined;
|
|
129
|
-
|
|
127
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
130
128
|
field: string;
|
|
129
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
131
130
|
}[] | undefined;
|
|
132
|
-
|
|
131
|
+
limit?: number | undefined;
|
|
133
132
|
offset?: number | undefined;
|
|
133
|
+
select?: string[] | undefined;
|
|
134
134
|
sortBy?: {
|
|
135
|
-
field: string;
|
|
136
135
|
direction: "asc" | "desc";
|
|
136
|
+
field: string;
|
|
137
137
|
} | undefined;
|
|
138
138
|
model: string;
|
|
139
139
|
}, {
|
|
@@ -142,34 +142,51 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
142
142
|
offset: convex_values0.VFloat64<number | undefined, "optional">;
|
|
143
143
|
select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
|
|
144
144
|
sortBy: convex_values0.VObject<{
|
|
145
|
-
field: string;
|
|
146
145
|
direction: "asc" | "desc";
|
|
146
|
+
field: string;
|
|
147
147
|
} | undefined, {
|
|
148
148
|
direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
|
|
149
149
|
field: convex_values0.VString<string, "required">;
|
|
150
|
-
}, "optional", "
|
|
150
|
+
}, "optional", "direction" | "field">;
|
|
151
151
|
where: convex_values0.VArray<{
|
|
152
152
|
mode?: "sensitive" | "insensitive" | undefined;
|
|
153
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
154
153
|
connector?: "AND" | "OR" | undefined;
|
|
155
|
-
|
|
154
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
156
155
|
field: string;
|
|
156
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
157
157
|
}[] | undefined, convex_values0.VObject<{
|
|
158
158
|
mode?: "sensitive" | "insensitive" | undefined;
|
|
159
|
-
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
160
159
|
connector?: "AND" | "OR" | undefined;
|
|
161
|
-
|
|
160
|
+
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
162
161
|
field: string;
|
|
162
|
+
value: string | number | boolean | string[] | number[] | null;
|
|
163
163
|
}, {
|
|
164
164
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
165
165
|
field: convex_values0.VString<string, "required">;
|
|
166
166
|
mode: convex_values0.VUnion<"sensitive" | "insensitive" | undefined, [convex_values0.VLiteral<"sensitive", "required">, convex_values0.VLiteral<"insensitive", "required">], "optional", never>;
|
|
167
|
-
operator: convex_values0.VUnion<"
|
|
167
|
+
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>;
|
|
168
168
|
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>;
|
|
169
|
-
}, "required", "mode" | "
|
|
170
|
-
}, "required", "
|
|
169
|
+
}, "required", "mode" | "connector" | "field" | "operator" | "value">, "optional">;
|
|
170
|
+
}, "required", "model" | "where" | "limit" | "offset" | "select" | "sortBy" | "sortBy.direction" | "sortBy.field">;
|
|
171
171
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
172
172
|
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>;
|
|
173
|
+
/**
|
|
174
|
+
* Better Auth gates single-use work on a forced id: it derives the id from a
|
|
175
|
+
* one-time key, so the first insert wins and every later one fails on the
|
|
176
|
+
* duplicate key. `reserveVerificationValue` does this on the verification
|
|
177
|
+
* model (magic link and email OTP cleanup locks, SIWE email claims, DPoP
|
|
178
|
+
* proofs, SAML assertion ids), and `private_key_jwt` does it on
|
|
179
|
+
* `oauthClientAssertion` with each assertion's `jti`.
|
|
180
|
+
*
|
|
181
|
+
* Convex picks its own ids and cannot store the forced one. On the
|
|
182
|
+
* verification model the identifier stands in for it: a forced-id create is
|
|
183
|
+
* refused while a row with the same identifier exists, as the duplicate key
|
|
184
|
+
* would refuse it. The read and the insert run in one mutation, so concurrent
|
|
185
|
+
* reservations serialize on the identifier index. A schema without that index
|
|
186
|
+
* fails closed. A client assertion row holds nothing but its id, so its
|
|
187
|
+
* forced-id create is refused outright rather than letting every replay in.
|
|
188
|
+
*/
|
|
189
|
+
declare const checkForcedId: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>) => Promise<void>;
|
|
173
190
|
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => D | null;
|
|
174
191
|
declare const paginate: <Doc extends DocumentByName<GenericDataModel, T>, T extends TableNamesInDataModel<GenericDataModel>>(ctx: GenericQueryCtx<GenericDataModel>, schema: SchemaDefinition<any, any>, betterAuthSchema: BetterAuthDBSchema, args: Infer<typeof adapterArgsValidator> & {
|
|
175
192
|
paginationOpts: AdapterPaginationOptions;
|
|
@@ -531,4 +548,4 @@ declare const convex: (opts: {
|
|
|
531
548
|
};
|
|
532
549
|
};
|
|
533
550
|
//#endregion
|
|
534
|
-
export { type AuthFunctions, type AuthRuntime, BetterAuthOptionsWithoutDatabase, ConvexCleanedWhere, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, GetAuth, SessionClientSignals, type Triggers, adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, consumeOneHandler, convex, countHandler, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
|
|
551
|
+
export { type AuthFunctions, type AuthRuntime, BetterAuthOptionsWithoutDatabase, ConvexCleanedWhere, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, GetAuth, SessionClientSignals, type Triggers, adapterArgsValidator, adapterConfig, adapterWhereValidator, checkForcedId, checkUniqueFields, consumeOneHandler, convex, countHandler, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
|
package/dist/auth/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { i as partial } from "../validators-cPSuYAHV.js";
|
|
|
3
3
|
import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason, t as DEFAULT_AUTH_DEFINITION_PATH } from "../generated-contract-disabled-RyPYlwq0.js";
|
|
4
4
|
import { n as createGeneratedFunctionReference, o as isQueryCtx, s as isRunMutationCtx } from "../api-entry-Buvjl9hn.js";
|
|
5
5
|
import { i as customQuery, n as customCtx, r as customMutation } from "../customFunctions-CWs3rEjV.js";
|
|
6
|
-
import { C as eq, o as getAggregateIndexes } from "../index-utils-
|
|
6
|
+
import { C as eq, o as getAggregateIndexes } from "../index-utils-COOY08yW.js";
|
|
7
7
|
import { c as stream, f as unsetToken, s as mergedStream, t as getByIdWithOrmQueryFallback } from "../query-context-DQLv58LH.js";
|
|
8
8
|
import { n as convex } from "../convex-plugin-UGuLZPyQ.js";
|
|
9
9
|
import { v } from "convex/values";
|
|
@@ -168,6 +168,41 @@ const checkUniqueFields = async (ctx, schema, betterAuthSchema, table, input, do
|
|
|
168
168
|
if (existingDoc && existingDoc._id !== doc?._id) throw new Error(`${table} ${uniqueIndex.join(", ")} already exists`);
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Better Auth gates single-use work on a forced id: it derives the id from a
|
|
173
|
+
* one-time key, so the first insert wins and every later one fails on the
|
|
174
|
+
* duplicate key. `reserveVerificationValue` does this on the verification
|
|
175
|
+
* model (magic link and email OTP cleanup locks, SIWE email claims, DPoP
|
|
176
|
+
* proofs, SAML assertion ids), and `private_key_jwt` does it on
|
|
177
|
+
* `oauthClientAssertion` with each assertion's `jti`.
|
|
178
|
+
*
|
|
179
|
+
* Convex picks its own ids and cannot store the forced one. On the
|
|
180
|
+
* verification model the identifier stands in for it: a forced-id create is
|
|
181
|
+
* refused while a row with the same identifier exists, as the duplicate key
|
|
182
|
+
* would refuse it. The read and the insert run in one mutation, so concurrent
|
|
183
|
+
* reservations serialize on the identifier index. A schema without that index
|
|
184
|
+
* fails closed. A client assertion row holds nothing but its id, so its
|
|
185
|
+
* forced-id create is refused outright rather than letting every replay in.
|
|
186
|
+
*/
|
|
187
|
+
const checkForcedId = async (ctx, schema, betterAuthSchema, table, input) => {
|
|
188
|
+
const { modelNameToKey } = getSchemaViews(betterAuthSchema);
|
|
189
|
+
const model = modelNameToKey.get(table) ?? table;
|
|
190
|
+
if (model === "oauthClientAssertion") throw new Error(`${table} needs its forced id to block replays, which Convex cannot store`);
|
|
191
|
+
if (model !== "verification") return;
|
|
192
|
+
const field = betterAuthSchema?.verification?.fields?.identifier?.fieldName ?? "identifier";
|
|
193
|
+
const value = input[field];
|
|
194
|
+
if (typeof value !== "string") throw new Error(`${table} ${field} is required with a forced id`);
|
|
195
|
+
const { index } = findIndex(schema, {
|
|
196
|
+
model: table,
|
|
197
|
+
where: [{
|
|
198
|
+
field,
|
|
199
|
+
operator: "eq",
|
|
200
|
+
value
|
|
201
|
+
}]
|
|
202
|
+
}) || {};
|
|
203
|
+
if (!index) throw new Error(`No index found for ${table} ${field}`);
|
|
204
|
+
if (await ctx.db.query(table).withIndex(index.indexDescriptor, (q) => q.eq(field, value)).first()) throw new Error(`${table} ${field} already exists`);
|
|
205
|
+
};
|
|
171
206
|
const selectFields = (doc, select) => {
|
|
172
207
|
if (!doc) return null;
|
|
173
208
|
if (!select?.length) return doc;
|
|
@@ -581,8 +616,10 @@ const withAuthTimestamps = (data, schema, betterAuthSchema, model) => {
|
|
|
581
616
|
const createHandler = async (ctx, args, schema, betterAuthSchema) => {
|
|
582
617
|
const triggerCtx = args.triggerCtx ?? ctx;
|
|
583
618
|
const tableTriggers = args.tableTriggers;
|
|
584
|
-
const
|
|
619
|
+
const { _id, ...input } = args.input.data;
|
|
620
|
+
const data = serializeDatesForConvex(withAuthTimestamps(await applyBeforeHook(args.input.model, "create", input, tableTriggers?.create?.before, triggerCtx), schema, betterAuthSchema, args.input.model));
|
|
585
621
|
await checkUniqueFields(ctx, schema, betterAuthSchema, args.input.model, data);
|
|
622
|
+
if (_id !== void 0) await checkForcedId(ctx, schema, betterAuthSchema, args.input.model, data);
|
|
586
623
|
const ormTable = resolveOrmTable(ctx, schema, betterAuthSchema, args.input.model);
|
|
587
624
|
const doc = ormTable ? await ormInsert(ctx, ormTable.table, data) : await (async () => {
|
|
588
625
|
const id = await ctx.db.insert(args.input.model, data);
|
|
@@ -1750,4 +1787,4 @@ const getHeaders = async (ctx, session) => {
|
|
|
1750
1787
|
};
|
|
1751
1788
|
|
|
1752
1789
|
//#endregion
|
|
1753
|
-
export { adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, consumeOneHandler, convex, countHandler, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
|
|
1790
|
+
export { adapterArgsValidator, adapterConfig, adapterWhereValidator, checkForcedId, checkUniqueFields, consumeOneHandler, convex, countHandler, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
|