@rebasepro/types 0.30.0 → 0.31.0-canary.g902a0ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -18
- package/dist/call_context.d.ts +3 -3
- package/dist/controllers/client.d.ts +29 -0
- package/dist/controllers/data.d.ts +85 -332
- package/dist/controllers/data_driver.d.ts +47 -57
- package/dist/controllers/index.d.ts +0 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2567 -1151
- package/dist/index.es.js.map +1 -1
- package/dist/schema/column_options.d.ts +336 -0
- package/dist/schema/column_type.d.ts +116 -0
- package/dist/schema/columns.d.ts +646 -0
- package/dist/schema/compiled.d.ts +114 -0
- package/dist/schema/descriptor.d.ts +349 -0
- package/dist/schema/hooks.d.ts +164 -0
- package/dist/schema/index.d.ts +13 -0
- package/dist/schema/infer.d.ts +340 -0
- package/dist/schema/json.d.ts +237 -0
- package/dist/schema/relations.d.ts +205 -0
- package/dist/schema/table.d.ts +304 -0
- package/dist/schema/table_options.d.ts +103 -0
- package/dist/schema/table_patch.d.ts +338 -0
- package/dist/types/auth_adapter.d.ts +12 -6
- package/dist/types/auth_hooks.d.ts +65 -0
- package/dist/types/backend.d.ts +85 -96
- package/dist/types/data_source.d.ts +4 -9
- package/dist/types/database_adapter.d.ts +30 -31
- package/dist/types/entities.d.ts +0 -162
- package/dist/types/filter-operators.d.ts +2 -26
- package/dist/types/history.d.ts +6 -9
- package/dist/types/index.d.ts +3 -9
- package/dist/types/mcp_app_modules.d.ts +0 -2
- package/dist/types/policy.d.ts +85 -10
- package/dist/types/project_manifest.d.ts +113 -46
- package/dist/types/read_query.d.ts +98 -0
- package/dist/types/register.d.ts +35 -5
- package/dist/types/relations.d.ts +0 -430
- package/dist/types/schema_editing.d.ts +54 -2
- package/dist/types/schema_version.d.ts +24 -4
- package/dist/types/security_rules.d.ts +225 -15
- package/dist/types/storage_authorize.d.ts +2 -2
- package/dist/types/tenancy.d.ts +3 -3
- package/dist/types/ui_preferences.d.ts +228 -0
- package/package.json +3 -2
- package/dist/controllers/auth_state.d.ts +0 -23
- package/dist/controllers/collection_registry.d.ts +0 -67
- package/dist/controllers/effective_role.d.ts +0 -4
- package/dist/types/admin_block.d.ts +0 -96
- package/dist/types/chips.d.ts +0 -16
- package/dist/types/collection_contract.d.ts +0 -43
- package/dist/types/collection_patch.d.ts +0 -74
- package/dist/types/collections.d.ts +0 -783
- package/dist/types/component_ref.d.ts +0 -81
- package/dist/types/conditions-contract.types.d.ts +0 -14
- package/dist/types/entity_callbacks.d.ts +0 -393
- package/dist/types/indexes.d.ts +0 -179
- package/dist/types/properties.d.ts +0 -1640
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import type { SecurityRule } from "../types/security_rules.js";
|
|
2
|
+
import type { SearchConfig } from "../types/search.js";
|
|
3
|
+
import type { ColumnDef } from "./columns.js";
|
|
4
|
+
import type { TableDescriptor } from "./descriptor.js";
|
|
5
|
+
import type { JsonShape } from "./json.js";
|
|
6
|
+
import type { BelongsToOptions, HasManyOptions, HasOptions, ManyToManyOptions, ViaOptions } from "./relations.js";
|
|
7
|
+
import type { RlsPosture, TableIndex, TableTenant } from "./table_options.js";
|
|
8
|
+
/**
|
|
9
|
+
* The edits the Studio's schema editor sends the server, one operation at a
|
|
10
|
+
* time.
|
|
11
|
+
*
|
|
12
|
+
* Every operation names the table it edits by **slug** and carries only
|
|
13
|
+
* wire-safe values: a column as its definition without functions, a relation
|
|
14
|
+
* with its target as a slug, a posture or a rule as data. The server applies
|
|
15
|
+
* the operations to `backend/schema/*.ts` — the `defineTable` call, its
|
|
16
|
+
* `columns`, `relations`, `rls` and table-level keys — and nothing else:
|
|
17
|
+
* presentation (labels, icons, column widths, view modes) is not a server edit.
|
|
18
|
+
*
|
|
19
|
+
* Whatever an operation does not name is left exactly as written: comments,
|
|
20
|
+
* hooks, `.transform()` bodies, the other columns and rules.
|
|
21
|
+
*
|
|
22
|
+
* @group Schema
|
|
23
|
+
*/
|
|
24
|
+
export type TablePatch = CreateTablePatch | AdoptTablePatch | DeleteTablePatch | AddColumnPatch | ChangeColumnPatch | RenameColumnPatch | RemoveColumnPatch | MoveColumnPatch | AddRelationPatch | ChangeRelationPatch | RemoveRelationPatch | SetRlsPatch | AddRulePatch | ReplaceRulePatch | RemoveRulePatch | SetTableOptionPatch;
|
|
25
|
+
/**
|
|
26
|
+
* The operation names of {@link TablePatch}.
|
|
27
|
+
*
|
|
28
|
+
* @group Schema
|
|
29
|
+
*/
|
|
30
|
+
export type TablePatchOp = TablePatch["op"];
|
|
31
|
+
/**
|
|
32
|
+
* A column as the wire carries it: its definition without field-level hooks
|
|
33
|
+
* (`.transform()` is code, and stays where it is written), the flags that are
|
|
34
|
+
* `false` by default optional.
|
|
35
|
+
*
|
|
36
|
+
* @group Schema
|
|
37
|
+
*/
|
|
38
|
+
export type WireColumnDef = Omit<ColumnDef, "transform" | "element" | "json" | "notNull" | "primaryKey" | "unique" | "readOnly" | "private"> & {
|
|
39
|
+
notNull?: boolean;
|
|
40
|
+
primaryKey?: boolean;
|
|
41
|
+
unique?: boolean;
|
|
42
|
+
readOnly?: boolean;
|
|
43
|
+
private?: boolean;
|
|
44
|
+
/** An array column's item. */
|
|
45
|
+
element?: WireColumnDef;
|
|
46
|
+
/** The shape of a `json`/`jsonb` document, without hooks. */
|
|
47
|
+
json?: JsonShape;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A relation as the wire carries it: the `rel.*` builder's options, its kind,
|
|
51
|
+
* and its target table by slug. `manyToMany` pivot columns are
|
|
52
|
+
* {@link WireColumnDef}s, in the order they are declared.
|
|
53
|
+
*
|
|
54
|
+
* @group Schema
|
|
55
|
+
*/
|
|
56
|
+
export type WireRelation = (BelongsToOptions & {
|
|
57
|
+
kind: "belongsTo";
|
|
58
|
+
target: string;
|
|
59
|
+
}) | (HasOptions & {
|
|
60
|
+
kind: "hasOne";
|
|
61
|
+
target: string;
|
|
62
|
+
}) | (HasManyOptions & {
|
|
63
|
+
kind: "hasMany";
|
|
64
|
+
target: string;
|
|
65
|
+
}) | (Omit<ManyToManyOptions, "pivot"> & {
|
|
66
|
+
kind: "manyToMany";
|
|
67
|
+
target: string;
|
|
68
|
+
pivot?: Record<string, WireColumnDef>;
|
|
69
|
+
}) | (ViaOptions & {
|
|
70
|
+
kind: "via";
|
|
71
|
+
target: string;
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* The table-level keys an edit may set or remove after creation, with the
|
|
75
|
+
* value each takes. `slug`, `table`, `schema` and the table's name are not
|
|
76
|
+
* here: renaming them moves data, which is a migration, not an edit.
|
|
77
|
+
*
|
|
78
|
+
* @group Schema
|
|
79
|
+
*/
|
|
80
|
+
export interface TableOptionValues {
|
|
81
|
+
description: string;
|
|
82
|
+
tenant: TableTenant;
|
|
83
|
+
softDelete: boolean | {
|
|
84
|
+
field?: string;
|
|
85
|
+
};
|
|
86
|
+
history: boolean;
|
|
87
|
+
search: SearchConfig;
|
|
88
|
+
indexes: readonly TableIndex[];
|
|
89
|
+
strictWrites: false;
|
|
90
|
+
defaultPolicies: boolean;
|
|
91
|
+
metadata: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A key of {@link TableOptionValues}.
|
|
95
|
+
*
|
|
96
|
+
* @group Schema
|
|
97
|
+
*/
|
|
98
|
+
export type TableOptionKey = keyof TableOptionValues;
|
|
99
|
+
/** The keys of {@link TableOptionValues}, in the order a table prints them. */
|
|
100
|
+
export declare const TABLE_OPTION_KEYS: readonly TableOptionKey[];
|
|
101
|
+
/**
|
|
102
|
+
* A new table: what its `defineTable(name, { … })` call says. Columns and
|
|
103
|
+
* relations print in the order given.
|
|
104
|
+
*
|
|
105
|
+
* @group Schema
|
|
106
|
+
*/
|
|
107
|
+
export interface NewTable extends Partial<TableOptionValues> {
|
|
108
|
+
/** The name `defineTable` takes; also the file it is written to (`backend/schema/<name>.ts`). */
|
|
109
|
+
name: string;
|
|
110
|
+
/** The slug, when it is not the name. Fixed from here on: renaming a slug moves data. */
|
|
111
|
+
slug?: string;
|
|
112
|
+
/** The SQL table, when it is not the name. */
|
|
113
|
+
table?: string;
|
|
114
|
+
/** The Postgres schema, when it is not `public`. */
|
|
115
|
+
schema?: string;
|
|
116
|
+
columns: Record<string, WireColumnDef>;
|
|
117
|
+
relations?: Record<string, WireRelation>;
|
|
118
|
+
rls: RlsPosture;
|
|
119
|
+
}
|
|
120
|
+
/** Create `backend/schema/<name>.ts` holding the table, and export it from the index. @group Schema */
|
|
121
|
+
export interface CreateTablePatch {
|
|
122
|
+
op: "createTable";
|
|
123
|
+
table: NewTable;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Adopt a table the database already has and `backend/schema` does not
|
|
127
|
+
* declare ("Import an existing table"): write `backend/schema/<name>.ts` from
|
|
128
|
+
* the table's description as introspection reads it — what
|
|
129
|
+
* `GET /api/admin/schema-editor/unmapped-tables/:schema/:table` serves —
|
|
130
|
+
* through the one printer, and export it from the index.
|
|
131
|
+
*
|
|
132
|
+
* The description states the table exactly as the database has it (column
|
|
133
|
+
* types, defaults, keys, foreign keys as `belongsTo`, enums, types Rebase does
|
|
134
|
+
* not create as `col.custom()`), so planning the adopted table changes nothing
|
|
135
|
+
* in the database. Edits the person made on top of it follow as their own
|
|
136
|
+
* operations, naming the adopted table by its slug.
|
|
137
|
+
*
|
|
138
|
+
* @group Schema
|
|
139
|
+
*/
|
|
140
|
+
export interface AdoptTablePatch {
|
|
141
|
+
op: "adoptTable";
|
|
142
|
+
table: TableDescriptor;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Delete a table's definition (its file, or its statement in a file holding
|
|
146
|
+
* others) and its export from the index. Refused while another table's
|
|
147
|
+
* relation targets it. The SQL table and its rows are not dropped.
|
|
148
|
+
*
|
|
149
|
+
* @group Schema
|
|
150
|
+
*/
|
|
151
|
+
export interface DeleteTablePatch {
|
|
152
|
+
op: "deleteTable";
|
|
153
|
+
table: string;
|
|
154
|
+
}
|
|
155
|
+
/** Add a column, before the column named by `before`, or last. @group Schema */
|
|
156
|
+
export interface AddColumnPatch {
|
|
157
|
+
op: "addColumn";
|
|
158
|
+
table: string;
|
|
159
|
+
key: string;
|
|
160
|
+
column: WireColumnDef;
|
|
161
|
+
before?: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Rewrite one column's builder chain. A `.transform()` already written on it
|
|
165
|
+
* is kept as written.
|
|
166
|
+
*
|
|
167
|
+
* @group Schema
|
|
168
|
+
*/
|
|
169
|
+
export interface ChangeColumnPatch {
|
|
170
|
+
op: "changeColumn";
|
|
171
|
+
table: string;
|
|
172
|
+
key: string;
|
|
173
|
+
column: WireColumnDef;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Rename a column's key, in place, with its new definition. To keep the SQL
|
|
177
|
+
* column, the definition carries `column` with the old SQL name.
|
|
178
|
+
*
|
|
179
|
+
* @group Schema
|
|
180
|
+
*/
|
|
181
|
+
export interface RenameColumnPatch {
|
|
182
|
+
op: "renameColumn";
|
|
183
|
+
table: string;
|
|
184
|
+
key: string;
|
|
185
|
+
to: string;
|
|
186
|
+
column: WireColumnDef;
|
|
187
|
+
}
|
|
188
|
+
/** Remove a column from `columns`. @group Schema */
|
|
189
|
+
export interface RemoveColumnPatch {
|
|
190
|
+
op: "removeColumn";
|
|
191
|
+
table: string;
|
|
192
|
+
key: string;
|
|
193
|
+
}
|
|
194
|
+
/** Move a column before the column named by `before`, or last. @group Schema */
|
|
195
|
+
export interface MoveColumnPatch {
|
|
196
|
+
op: "moveColumn";
|
|
197
|
+
table: string;
|
|
198
|
+
key: string;
|
|
199
|
+
before?: string;
|
|
200
|
+
}
|
|
201
|
+
/** Add a relation; the target's import is added to the file. @group Schema */
|
|
202
|
+
export interface AddRelationPatch {
|
|
203
|
+
op: "addRelation";
|
|
204
|
+
table: string;
|
|
205
|
+
name: string;
|
|
206
|
+
relation: WireRelation;
|
|
207
|
+
}
|
|
208
|
+
/** Rewrite one relation. @group Schema */
|
|
209
|
+
export interface ChangeRelationPatch {
|
|
210
|
+
op: "changeRelation";
|
|
211
|
+
table: string;
|
|
212
|
+
name: string;
|
|
213
|
+
relation: WireRelation;
|
|
214
|
+
}
|
|
215
|
+
/** Remove a relation; an import nothing else uses is removed with it. @group Schema */
|
|
216
|
+
export interface RemoveRelationPatch {
|
|
217
|
+
op: "removeRelation";
|
|
218
|
+
table: string;
|
|
219
|
+
name: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Replace the whole `rls`: a posture, or a list of rules. Prefer the rule
|
|
223
|
+
* operations for a change to one rule — a policy's name is a hash of its rule
|
|
224
|
+
* as written, and they leave every other rule's text alone.
|
|
225
|
+
*
|
|
226
|
+
* @group Schema
|
|
227
|
+
*/
|
|
228
|
+
export interface SetRlsPatch {
|
|
229
|
+
op: "setRls";
|
|
230
|
+
table: string;
|
|
231
|
+
rls: RlsPosture;
|
|
232
|
+
}
|
|
233
|
+
/** Insert a rule at `index` (last when omitted) of a table whose `rls` is a list of rules. @group Schema */
|
|
234
|
+
export interface AddRulePatch {
|
|
235
|
+
op: "addRule";
|
|
236
|
+
table: string;
|
|
237
|
+
rule: SecurityRule;
|
|
238
|
+
index?: number;
|
|
239
|
+
}
|
|
240
|
+
/** Replace the rule at `index`; every other rule's text stays byte-identical. @group Schema */
|
|
241
|
+
export interface ReplaceRulePatch {
|
|
242
|
+
op: "replaceRule";
|
|
243
|
+
table: string;
|
|
244
|
+
index: number;
|
|
245
|
+
rule: SecurityRule;
|
|
246
|
+
}
|
|
247
|
+
/** Remove the rule at `index`. The last rule cannot be removed: set `"admin-only"` instead. @group Schema */
|
|
248
|
+
export interface RemoveRulePatch {
|
|
249
|
+
op: "removeRule";
|
|
250
|
+
table: string;
|
|
251
|
+
index: number;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Set a table-level key, or remove it with `value: null`.
|
|
255
|
+
*
|
|
256
|
+
* @group Schema
|
|
257
|
+
*/
|
|
258
|
+
export type SetTableOptionPatch = {
|
|
259
|
+
[K in TableOptionKey]: {
|
|
260
|
+
op: "setOption";
|
|
261
|
+
table: string;
|
|
262
|
+
option: K;
|
|
263
|
+
value: TableOptionValues[K] | null;
|
|
264
|
+
};
|
|
265
|
+
}[TableOptionKey];
|
|
266
|
+
/**
|
|
267
|
+
* What is wrong with one operation of a {@link TablePatch} list, reported the
|
|
268
|
+
* way a schema problem is: the table, the key when there is one, and what to
|
|
269
|
+
* send instead.
|
|
270
|
+
*
|
|
271
|
+
* @group Schema
|
|
272
|
+
*/
|
|
273
|
+
export interface TablePatchProblem {
|
|
274
|
+
/** The index of the operation in the list sent. */
|
|
275
|
+
index: number;
|
|
276
|
+
/** The table it names, as sent ("" when none was). */
|
|
277
|
+
table: string;
|
|
278
|
+
/** The column, relation or option key, when the problem is about one. */
|
|
279
|
+
key?: string;
|
|
280
|
+
/** What is wrong and what to send instead. */
|
|
281
|
+
message: string;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* A list of table edits that cannot be applied, with every problem found.
|
|
285
|
+
*
|
|
286
|
+
* @group Schema
|
|
287
|
+
*/
|
|
288
|
+
export declare class TablePatchError extends Error {
|
|
289
|
+
/** Every problem found, in operation order. */
|
|
290
|
+
readonly problems: readonly TablePatchProblem[];
|
|
291
|
+
readonly code = "TABLE_PATCH_INVALID";
|
|
292
|
+
constructor(
|
|
293
|
+
/** Every problem found, in operation order. */
|
|
294
|
+
problems: readonly TablePatchProblem[]);
|
|
295
|
+
private static describe;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Every problem with a list of table edits as it arrived, in operation order.
|
|
299
|
+
* Empty when the list is well formed — which says nothing about whether the
|
|
300
|
+
* result compiles: the server compiles it before writing anything.
|
|
301
|
+
*
|
|
302
|
+
* @group Schema
|
|
303
|
+
*/
|
|
304
|
+
export declare function tablePatchProblems(value: unknown): TablePatchProblem[];
|
|
305
|
+
/**
|
|
306
|
+
* Whether a value is a well-formed list of {@link TablePatch} operations.
|
|
307
|
+
*
|
|
308
|
+
* @group Schema
|
|
309
|
+
*/
|
|
310
|
+
export declare function isTablePatchList(value: unknown): value is TablePatch[];
|
|
311
|
+
/**
|
|
312
|
+
* A list of edits as it arrived, checked: the list, or a
|
|
313
|
+
* {@link TablePatchError} naming every problem.
|
|
314
|
+
*
|
|
315
|
+
* @group Schema
|
|
316
|
+
*/
|
|
317
|
+
export declare function parseTablePatches(value: unknown): TablePatch[];
|
|
318
|
+
/**
|
|
319
|
+
* The column definition a {@link WireColumnDef} stands for, the flags it left
|
|
320
|
+
* out `false`.
|
|
321
|
+
*
|
|
322
|
+
* @group Schema
|
|
323
|
+
*/
|
|
324
|
+
export declare function columnDefFromWire(column: WireColumnDef): ColumnDef;
|
|
325
|
+
/**
|
|
326
|
+
* The rule operations that turn one list of rules into another, touching only
|
|
327
|
+
* the rules that changed.
|
|
328
|
+
*
|
|
329
|
+
* A policy's name is a hash of its rule as written, so an editor that sends
|
|
330
|
+
* the whole list back (one `setRls`) would rewrite every rule's text and risk
|
|
331
|
+
* renaming policies it never changed. This pairs the lists by position: an
|
|
332
|
+
* equal rule is left alone, a different one is replaced, a longer list adds
|
|
333
|
+
* rules and a shorter one removes from the end. Positions are those of the
|
|
334
|
+
* list as it is when each operation runs.
|
|
335
|
+
*
|
|
336
|
+
* @group Schema
|
|
337
|
+
*/
|
|
338
|
+
export declare function rulePatches(table: string, before: readonly SecurityRule[], after: readonly SecurityRule[]): TablePatch[];
|
|
@@ -278,6 +278,12 @@ export interface AuthAdapterCapabilities {
|
|
|
278
278
|
* that has never heard of the flow means.
|
|
279
279
|
*/
|
|
280
280
|
emailOtp?: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Supports device sign-in (`POST /auth/device`): a terminal shows a code
|
|
283
|
+
* and a link, and the person approves it in a browser where they are
|
|
284
|
+
* signed in. Optional, as `emailOtp` is; absent reads as "no".
|
|
285
|
+
*/
|
|
286
|
+
deviceLogin?: boolean;
|
|
281
287
|
/** Whether `POST /auth/anonymous` will mint a credential-less session. */
|
|
282
288
|
anonymousLogin: boolean;
|
|
283
289
|
/** List of enabled OAuth provider IDs (e.g. `["google", "github"]`). */
|
|
@@ -512,7 +518,7 @@ export interface TransformAuthResponseContext {
|
|
|
512
518
|
/** The authenticated user's ID. */
|
|
513
519
|
uid: string;
|
|
514
520
|
/** The auth method that triggered this response. */
|
|
515
|
-
method: "login" | "register" | "oauth" | "refresh" | "anonymous" | "magic-link" | "otp" | "mfa";
|
|
521
|
+
method: "login" | "register" | "oauth" | "refresh" | "anonymous" | "magic-link" | "otp" | "mfa" | "device";
|
|
516
522
|
/** The raw HTTP request (for reading headers, IP, etc.). */
|
|
517
523
|
request: Request;
|
|
518
524
|
}
|
|
@@ -641,12 +647,14 @@ export interface AuthAdapter {
|
|
|
641
647
|
* A chosen `password` is held to the password policy unless the body says
|
|
642
648
|
* `skipPasswordPolicy: true` and `options.mayWaivePasswordPolicy` is set.
|
|
643
649
|
*
|
|
650
|
+
* The auth table's own hooks (`onCreateUser`) are the adapter's to know: the
|
|
651
|
+
* built-in adapter is configured with them (`authTableHooks`).
|
|
652
|
+
*
|
|
644
653
|
* @param values - Raw request body from the client.
|
|
645
|
-
* @param collectionAuth - The parsed `AuthCollectionConfig` from the collection (if `auth` is an object).
|
|
646
654
|
* @param options - What the door knows about its caller.
|
|
647
655
|
* @returns Processed values ready for `driver.save()`, plus metadata for the post-save step.
|
|
648
656
|
*/
|
|
649
|
-
prepareUserCreation?(values: Record<string, unknown>,
|
|
657
|
+
prepareUserCreation?(values: Record<string, unknown>, options?: UserCreationOptions): Promise<UserCreationPrepareResult>;
|
|
650
658
|
/**
|
|
651
659
|
* Describe what a create body for this auth collection is allowed to name,
|
|
652
660
|
* so unknown-field validation can run on it.
|
|
@@ -667,10 +675,8 @@ export interface AuthAdapter {
|
|
|
667
675
|
* the hook accepts.
|
|
668
676
|
*
|
|
669
677
|
* If not implemented, validation is skipped — the pre-existing behaviour.
|
|
670
|
-
*
|
|
671
|
-
* @param collectionAuth - The parsed `AuthCollectionConfig` from the collection (if `auth` is an object).
|
|
672
678
|
*/
|
|
673
|
-
describeUserCreationContract?(
|
|
679
|
+
describeUserCreationContract?(): UserCreationWriteContract;
|
|
674
680
|
/**
|
|
675
681
|
* Finalize a user creation after the entity has been persisted.
|
|
676
682
|
*
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the user store's auth hooks (`defineAuthTable`'s `onCreateUser` /
|
|
3
|
+
* `onResetPassword`) receive and return.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { EmailSendResult } from "../controllers/email.js";
|
|
8
|
+
/**
|
|
9
|
+
* Context provided to collection-level auth hooks.
|
|
10
|
+
*
|
|
11
|
+
* This is a simplified facade over the server internals —
|
|
12
|
+
* it exposes only what's needed for custom auth flows without
|
|
13
|
+
* coupling collection config to internal interfaces.
|
|
14
|
+
*
|
|
15
|
+
* @group Models
|
|
16
|
+
*/
|
|
17
|
+
export interface AuthCollectionContext {
|
|
18
|
+
/** Hash a password using the configured algorithm (scrypt by default). */
|
|
19
|
+
hashPassword: (password: string) => Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Send an email. Only available when email service is configured.
|
|
22
|
+
*
|
|
23
|
+
* Resolves with what the provider reported — the assigned Message-ID, most
|
|
24
|
+
* usefully — so a hook that sends a message can store the id and later
|
|
25
|
+
* thread a reply back to it. Callers that do not care may ignore it.
|
|
26
|
+
*/
|
|
27
|
+
sendEmail?: (options: {
|
|
28
|
+
to: string;
|
|
29
|
+
subject: string;
|
|
30
|
+
html: string;
|
|
31
|
+
text?: string;
|
|
32
|
+
}) => Promise<EmailSendResult>;
|
|
33
|
+
/** Whether the email service is configured and available. */
|
|
34
|
+
emailConfigured: boolean;
|
|
35
|
+
/** The app name from email config (for templates). */
|
|
36
|
+
appName: string;
|
|
37
|
+
/** The base URL for password reset links. */
|
|
38
|
+
resetPasswordUrl: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Result of a collection-level `onCreateUser` hook.
|
|
42
|
+
* @group Models
|
|
43
|
+
*/
|
|
44
|
+
export interface AuthCollectionCreateResult {
|
|
45
|
+
/** Processed values to persist (must include passwordHash, NOT raw password). */
|
|
46
|
+
values: Record<string, unknown>;
|
|
47
|
+
/** If set, shown to the admin in the creation result dialog. */
|
|
48
|
+
temporaryPassword?: string;
|
|
49
|
+
/** Whether an invitation email was sent. */
|
|
50
|
+
invitationSent?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Result of a collection-level `onResetPassword` hook.
|
|
54
|
+
* @group Models
|
|
55
|
+
*/
|
|
56
|
+
export interface AuthCollectionResetResult {
|
|
57
|
+
/**
|
|
58
|
+
* The account's new password. Rebase hashes and saves it, then shows it to
|
|
59
|
+
* the admin; leave it unset when the account keeps its password for now
|
|
60
|
+
* (for example, because the hook emailed a link).
|
|
61
|
+
*/
|
|
62
|
+
temporaryPassword?: string;
|
|
63
|
+
/** Whether a reset email was sent. */
|
|
64
|
+
invitationSent?: boolean;
|
|
65
|
+
}
|