cauthy-auth 0.5.2 → 0.8.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/README.md +68 -3
- package/dist/{cauthy-BCTCqubt.d.ts → cauthy-Bn3iv50y.d.ts} +1 -1
- package/dist/{cauthy-hswMoS7B.d.mts → cauthy-C29HCvag.d.mts} +1 -1
- package/dist/cli.js +490 -25
- package/dist/client.d.mts +236 -0
- package/dist/client.d.ts +236 -0
- package/dist/client.js +331 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +297 -0
- package/dist/client.mjs.map +1 -0
- package/dist/express.d.mts +24 -0
- package/dist/express.d.ts +24 -0
- package/dist/express.js +102 -0
- package/dist/express.js.map +1 -0
- package/dist/express.mjs +76 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify.d.mts +2 -2
- package/dist/fastify.d.ts +2 -2
- package/dist/fastify.js +3 -1
- package/dist/fastify.js.map +1 -1
- package/dist/fastify.mjs +3 -1
- package/dist/fastify.mjs.map +1 -1
- package/dist/hono.d.mts +23 -0
- package/dist/hono.d.ts +23 -0
- package/dist/hono.js +50 -0
- package/dist/hono.js.map +1 -0
- package/dist/hono.mjs +24 -0
- package/dist/hono.mjs.map +1 -0
- package/dist/index.d.mts +44 -6
- package/dist/index.d.ts +44 -6
- package/dist/index.js +668 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +656 -37
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +24 -0
- package/dist/next.d.ts +24 -0
- package/dist/next.js +77 -0
- package/dist/next.js.map +1 -0
- package/dist/next.mjs +52 -0
- package/dist/next.mjs.map +1 -0
- package/dist/react.d.mts +546 -7
- package/dist/react.d.ts +546 -7
- package/dist/react.js +925 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +913 -10
- package/dist/react.mjs.map +1 -1
- package/dist/styles.css +271 -0
- package/dist/svelte.d.mts +26 -0
- package/dist/svelte.d.ts +26 -0
- package/dist/svelte.js +402 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +373 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/{system-DvcQjORr.d.ts → system-DhRr_WxR.d.ts} +139 -1
- package/dist/{system-CR8p4BjB.d.mts → system-ZD_Wa8Bm.d.mts} +139 -1
- package/dist/theme.d.mts +56 -1
- package/dist/theme.d.ts +56 -1
- package/dist/theme.js +181 -5
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +176 -4
- package/dist/theme.mjs.map +1 -1
- package/dist/validate-B_iC-4y8.d.mts +19 -0
- package/dist/validate-B_iC-4y8.d.ts +19 -0
- package/dist/vue.d.mts +28 -0
- package/dist/vue.d.ts +28 -0
- package/dist/vue.js +420 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +391 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +68 -7
- package/dist/permissions-B-a3eN0h.d.mts +0 -52
- package/dist/permissions-B-a3eN0h.d.ts +0 -52
package/dist/react.d.mts
CHANGED
|
@@ -1,10 +1,537 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { ComponentType, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/** How an application looks on Cauthy's hosted pages. Every value is optional. */
|
|
5
|
+
/** One font file the application serves: a family in one weight (or a range) and one style. */
|
|
6
|
+
interface ThemeFont {
|
|
7
|
+
family: string;
|
|
8
|
+
/** An https address of a `.woff2` file. It must answer with `Access-Control-Allow-Origin` for Cauthy's origin. */
|
|
9
|
+
url: string;
|
|
10
|
+
/** `400`, or `"100 900"` for a variable font. Default: 400. */
|
|
11
|
+
weight?: number | string;
|
|
12
|
+
style?: 'normal' | 'italic';
|
|
13
|
+
}
|
|
14
|
+
/** What an application says on its sign-in page, in one language. */
|
|
15
|
+
interface ThemeTexts {
|
|
16
|
+
/** Replaces "Sign in". */
|
|
17
|
+
heading?: string;
|
|
18
|
+
/** Replaces "to continue to …". */
|
|
19
|
+
subheading?: string;
|
|
20
|
+
/** The messages of the split layout's panel, shown one at a time (up to 5). */
|
|
21
|
+
panel?: string[];
|
|
22
|
+
/** Links at the foot of the split layout: privacy, terms (up to 4). */
|
|
23
|
+
links?: {
|
|
24
|
+
label: string;
|
|
25
|
+
url: string;
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
interface CauthyTheme {
|
|
29
|
+
/** The page. Colours are `#rrggbb` or `rgba(r, g, b, a)`. */
|
|
30
|
+
background?: string;
|
|
31
|
+
/** The card, and inputs. */
|
|
32
|
+
surface?: string;
|
|
33
|
+
/** Headings and what is typed. */
|
|
34
|
+
text?: string;
|
|
35
|
+
/** Paragraphs, labels, small print. */
|
|
36
|
+
textMuted?: string;
|
|
37
|
+
border?: string;
|
|
38
|
+
/** The fields and the secondary buttons, when they are not the card's colours. */
|
|
39
|
+
inputBackground?: string;
|
|
40
|
+
inputBorder?: string;
|
|
41
|
+
/** The main button, and what is written on it. */
|
|
42
|
+
primary?: string;
|
|
43
|
+
primaryText?: string;
|
|
44
|
+
/** Links, and the focus ring. */
|
|
45
|
+
accent?: string;
|
|
46
|
+
error?: string;
|
|
47
|
+
errorBackground?: string;
|
|
48
|
+
success?: string;
|
|
49
|
+
successBackground?: string;
|
|
50
|
+
/** Corners of cards and inputs, in pixels (0–40). */
|
|
51
|
+
radius?: number;
|
|
52
|
+
/** Corners of buttons, in pixels (0–40). */
|
|
53
|
+
buttonRadius?: number;
|
|
54
|
+
/** A CSS font-family list: the application's typeface first, a system font after it. */
|
|
55
|
+
fontFamily?: string;
|
|
56
|
+
/** The files of the typefaces `fontFamily` names, for people who do not have them installed. */
|
|
57
|
+
fonts?: ThemeFont[];
|
|
58
|
+
/** An image shown where "Cauthy" is, over https. */
|
|
59
|
+
logoUrl?: string;
|
|
60
|
+
/**
|
|
61
|
+
* How the sign-in pages are laid out: `card` (the default, one card in the
|
|
62
|
+
* middle) or `split` (the form on one side, a panel that presents the
|
|
63
|
+
* application on the other).
|
|
64
|
+
*/
|
|
65
|
+
layout?: 'card' | 'split';
|
|
66
|
+
/** The colours the split layout's backdrop blends, one to four. */
|
|
67
|
+
panelColors?: string[];
|
|
68
|
+
/** The colour of what is written on the panel. */
|
|
69
|
+
panelText?: string;
|
|
70
|
+
/** An https image shown over the panel's messages. */
|
|
71
|
+
panelIconUrl?: string;
|
|
72
|
+
/** The application's own words on the sign-in page, by language (`en`, `es`). */
|
|
73
|
+
texts?: Record<string, ThemeTexts>;
|
|
74
|
+
/**
|
|
75
|
+
* The application's Stackmyth tokens (`--sm-*`), from `tokensFromStackmyth`.
|
|
76
|
+
* Cauthy's pages are drawn with Stackmyth's components, so these make its
|
|
77
|
+
* buttons and fields the application's own. They are laid over the named values.
|
|
78
|
+
*/
|
|
79
|
+
tokens?: Record<string, string>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The part of an organization that says what its member may do. */
|
|
83
|
+
interface Permitted {
|
|
84
|
+
/** "resource:action" entries the person is allowed; "*" is any. Absent when the system keeps no catalog in Cauthy. */
|
|
85
|
+
permissions?: string[];
|
|
86
|
+
/** Entries the person is denied whatever else allows them. */
|
|
87
|
+
denied?: string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether the person may do an action on a resource in an organization:
|
|
91
|
+
* allowed by some entry, and denied by none. A denial wins.
|
|
92
|
+
*
|
|
93
|
+
* An organization of a system that keeps no catalog in Cauthy carries no
|
|
94
|
+
* permissions, and the answer is `false`: decide by its `role` instead.
|
|
95
|
+
*
|
|
96
|
+
* if (!can(organization, 'invoicing', 'write')) return forbidden()
|
|
97
|
+
*/
|
|
98
|
+
declare function can(organization: Permitted | null | undefined, resource: string, action: string): boolean;
|
|
99
|
+
/** Something a role may do: an action on a resource, in organizations of a kind ("*", the default, is every kind). */
|
|
100
|
+
interface PolicyPermission {
|
|
101
|
+
kind?: string;
|
|
102
|
+
resource: string;
|
|
103
|
+
action: string;
|
|
104
|
+
}
|
|
105
|
+
interface PolicyRole {
|
|
106
|
+
role: string;
|
|
107
|
+
name?: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
/** Roles whose permissions this one has as well. */
|
|
110
|
+
inherits?: string[];
|
|
111
|
+
permissions?: PolicyPermission[];
|
|
112
|
+
}
|
|
113
|
+
/** A role as `definePolicy` reads it: any `PolicyRole`, kept as written. */
|
|
114
|
+
type RoleShape = {
|
|
115
|
+
readonly role: string;
|
|
116
|
+
readonly name?: string;
|
|
117
|
+
readonly description?: string;
|
|
118
|
+
readonly inherits?: readonly string[];
|
|
119
|
+
readonly permissions?: readonly {
|
|
120
|
+
readonly kind?: string;
|
|
121
|
+
readonly resource: string;
|
|
122
|
+
readonly action: string;
|
|
123
|
+
}[];
|
|
124
|
+
};
|
|
125
|
+
type Named<S extends string> = S extends '*' ? string : S;
|
|
126
|
+
type PermissionsIn<R> = R extends {
|
|
127
|
+
readonly permissions: readonly (infer P)[];
|
|
128
|
+
} ? P extends {
|
|
129
|
+
readonly resource: infer Res extends string;
|
|
130
|
+
readonly action: infer Act extends string;
|
|
131
|
+
} ? `${Named<Res>}:${Named<Act>}` : never : never;
|
|
132
|
+
/** The roles a catalog names: `RoleOf<typeof policy>`. */
|
|
133
|
+
type RoleOf<P> = P extends Policy<infer R, string> ? R : never;
|
|
134
|
+
/** The "resource:action" permissions a catalog names: `PermissionOf<typeof policy>`. */
|
|
135
|
+
type PermissionOf<P> = P extends Policy<string, infer X> ? X : never;
|
|
136
|
+
interface Policy<Role extends string = string, Permission extends string = string> {
|
|
137
|
+
/** The catalog as Cauthy takes it: `pushPolicy({ roles: policy.roles })`. */
|
|
138
|
+
roles: PolicyRole[];
|
|
139
|
+
/** Every role's name. */
|
|
140
|
+
roleNames: Role[];
|
|
141
|
+
/** Every permission some role has, as "resource:action". */
|
|
142
|
+
permissions: Permission[];
|
|
143
|
+
/**
|
|
144
|
+
* Whether the person may do this in the organization: `can(org, 'ledger:write')`.
|
|
145
|
+
* It reads what Cauthy sent with the session, so a catalog edited in Cauthy
|
|
146
|
+
* since this file was written is still what decides.
|
|
147
|
+
*/
|
|
148
|
+
can(organization: Permitted | null | undefined, permission: Permission): boolean;
|
|
149
|
+
/** Whether the person's role in the organization is one of these. */
|
|
150
|
+
hasRole(organization: {
|
|
151
|
+
role: string;
|
|
152
|
+
} | null | undefined, ...roles: Role[]): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* What a role may do by this catalog, with what it inherits: for showing a
|
|
155
|
+
* role, never for deciding about a person (their exceptions are not here).
|
|
156
|
+
*/
|
|
157
|
+
permissionsOf(role: Role): Permission[];
|
|
158
|
+
}
|
|
159
|
+
/** Gives a catalog of roles its types. See the top of this section. */
|
|
160
|
+
declare function definePolicy<const T extends readonly RoleShape[]>(roles: T): Policy<T[number]['role'], PermissionsIn<T[number]>>;
|
|
161
|
+
|
|
162
|
+
/** The person signed in. Every moment is UTC. */
|
|
163
|
+
interface SessionUser {
|
|
164
|
+
id: string;
|
|
165
|
+
email: string;
|
|
166
|
+
name: string;
|
|
167
|
+
emailVerified: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
170
|
+
* and refuse its writes.
|
|
171
|
+
*/
|
|
172
|
+
restricted: boolean;
|
|
173
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
174
|
+
emailVerifyBy?: string;
|
|
175
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
176
|
+
locale?: string;
|
|
177
|
+
}
|
|
178
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
179
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
180
|
+
[key: string]: JsonValue;
|
|
181
|
+
};
|
|
182
|
+
/** An organization the person belongs to, with their role in it. */
|
|
183
|
+
interface SessionOrganization {
|
|
184
|
+
id: string;
|
|
185
|
+
system: string;
|
|
186
|
+
name: string;
|
|
187
|
+
kind: string;
|
|
188
|
+
externalId?: string;
|
|
189
|
+
role: string;
|
|
190
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
191
|
+
metadata: Record<string, JsonValue>;
|
|
192
|
+
/**
|
|
193
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
194
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
195
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
196
|
+
* Check with `can(organization, resource, action)`.
|
|
197
|
+
*/
|
|
198
|
+
permissions?: string[];
|
|
199
|
+
/** What the person is denied here, whatever else allows it. */
|
|
200
|
+
denied?: string[];
|
|
201
|
+
}
|
|
202
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
203
|
+
interface PublicSession {
|
|
204
|
+
user: SessionUser;
|
|
205
|
+
tenantId: string;
|
|
206
|
+
roles: string[];
|
|
207
|
+
organizations: SessionOrganization[];
|
|
208
|
+
expiresAt: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code';
|
|
212
|
+
|
|
213
|
+
/** What went wrong, in a form the screen can show. */
|
|
214
|
+
interface AuthError {
|
|
215
|
+
/** Stable, for translating: `invalid_credentials`, `invalid_email`, `too_short`, `email_taken`, `unavailable`… */
|
|
216
|
+
code: string;
|
|
217
|
+
message: string;
|
|
218
|
+
/** The input it is about, when it is about one. */
|
|
219
|
+
field?: AuthField;
|
|
220
|
+
}
|
|
221
|
+
type AuthResult<S extends string, More = unknown> = ({
|
|
222
|
+
ok: true;
|
|
223
|
+
status: S;
|
|
224
|
+
} & More) | {
|
|
225
|
+
ok: false;
|
|
226
|
+
error: AuthError;
|
|
227
|
+
};
|
|
228
|
+
/** What the screen may offer. */
|
|
229
|
+
interface AuthMethods {
|
|
230
|
+
/** The providers the workspace signs people in with: `{ id: 'google', name: 'Google' }`. */
|
|
231
|
+
providers: {
|
|
232
|
+
id: string;
|
|
233
|
+
name: string;
|
|
234
|
+
}[];
|
|
235
|
+
/** Whether people may create an account themselves. */
|
|
236
|
+
signUp: boolean;
|
|
237
|
+
magicLink: boolean;
|
|
238
|
+
/** Whether to offer a passkey. It is asked for on Cauthy's page: the person goes there for that step and comes back signed in. */
|
|
239
|
+
passkey: boolean;
|
|
240
|
+
}
|
|
241
|
+
/** A person's own account, as their account screen shows it. */
|
|
242
|
+
interface Account$1 {
|
|
243
|
+
id: string;
|
|
244
|
+
email: string;
|
|
245
|
+
name: string;
|
|
246
|
+
emailVerified: boolean;
|
|
247
|
+
/** False for an account that only signs in through a provider: it has no current password to ask for. */
|
|
248
|
+
hasPassword: boolean;
|
|
249
|
+
mfaEnabled: boolean;
|
|
250
|
+
}
|
|
251
|
+
/** Somewhere the person is signed in. Moments are UTC. */
|
|
252
|
+
interface AccountSession {
|
|
253
|
+
/** "Mac · Chrome", or "" when the browser did not say. */
|
|
254
|
+
device: string;
|
|
255
|
+
ip: string;
|
|
256
|
+
createdAt: string;
|
|
257
|
+
expiresAt: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The signed-in person's own account. What weakens it — the password, the
|
|
261
|
+
* second step, its recovery codes — asks for the current password again.
|
|
262
|
+
*/
|
|
263
|
+
interface AccountClient {
|
|
264
|
+
/** The account, or null when nobody is signed in. */
|
|
265
|
+
get(): Promise<Account$1 | null>;
|
|
266
|
+
update(form: {
|
|
267
|
+
name: string;
|
|
268
|
+
}): Promise<AuthResult<'saved', {
|
|
269
|
+
account: Account$1;
|
|
270
|
+
}>>;
|
|
271
|
+
/** Ends every other session of the account; this one stays signed in. */
|
|
272
|
+
changePassword(form: {
|
|
273
|
+
password: string;
|
|
274
|
+
newPassword: string;
|
|
275
|
+
}): Promise<AuthResult<'changed', {
|
|
276
|
+
signedIn: boolean;
|
|
277
|
+
}>>;
|
|
278
|
+
mfa: {
|
|
279
|
+
/** Starts turning the second step on: show `secret` (or `otpauthUri` as a QR code) to add to an authenticator app, then call `verify`. */
|
|
280
|
+
setup(form: {
|
|
281
|
+
password: string;
|
|
282
|
+
}): Promise<AuthResult<'started', {
|
|
283
|
+
secret: string;
|
|
284
|
+
otpauthUri: string;
|
|
285
|
+
}>>;
|
|
286
|
+
/** Turns it on with a code from the app. `recoveryCodes` are shown this once. */
|
|
287
|
+
verify(form: {
|
|
288
|
+
code: string;
|
|
289
|
+
}): Promise<AuthResult<'enabled', {
|
|
290
|
+
recoveryCodes: string[];
|
|
291
|
+
}>>;
|
|
292
|
+
disable(form: {
|
|
293
|
+
password: string;
|
|
294
|
+
}): Promise<AuthResult<'disabled'>>;
|
|
295
|
+
/** New recovery codes; the earlier ones stop working. */
|
|
296
|
+
recoveryCodes(form: {
|
|
297
|
+
password: string;
|
|
298
|
+
}): Promise<AuthResult<'renewed', {
|
|
299
|
+
recoveryCodes: string[];
|
|
300
|
+
}>>;
|
|
301
|
+
};
|
|
302
|
+
/** Where the account is signed in. */
|
|
303
|
+
sessions(): Promise<AccountSession[]>;
|
|
304
|
+
/** Signs the account out everywhere, here too. */
|
|
305
|
+
signOutEverywhere(): Promise<AuthResult<'signed_out'>>;
|
|
306
|
+
}
|
|
307
|
+
interface AuthClient {
|
|
308
|
+
signIn: {
|
|
309
|
+
/** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
|
|
310
|
+
email(form: {
|
|
311
|
+
email: string;
|
|
312
|
+
password: string;
|
|
313
|
+
}): Promise<AuthResult<'signed_in', {
|
|
314
|
+
session: PublicSession;
|
|
315
|
+
}> | AuthResult<'mfa_required'>>;
|
|
316
|
+
/** The second step: the code of the authenticator app, or a recovery code. */
|
|
317
|
+
mfa(form: {
|
|
318
|
+
code: string;
|
|
319
|
+
}): Promise<AuthResult<'signed_in', {
|
|
320
|
+
session: PublicSession;
|
|
321
|
+
}>>;
|
|
322
|
+
/** Mails a link that signs the person in. The answer is the same whether or not the address has an account. */
|
|
323
|
+
magicLink(form: {
|
|
324
|
+
email: string;
|
|
325
|
+
}): Promise<AuthResult<'sent'>>;
|
|
326
|
+
/** Signs in with the token the mailed link opened the page with (`ml_token`). */
|
|
327
|
+
magicLinkVerify(form: {
|
|
328
|
+
token: string;
|
|
329
|
+
}): Promise<AuthResult<'signed_in', {
|
|
330
|
+
session: PublicSession;
|
|
331
|
+
}>>;
|
|
332
|
+
/** Signs in with the code that came in the same mail as the link, for somebody reading it on another device. */
|
|
333
|
+
emailCode(form: {
|
|
334
|
+
code: string;
|
|
335
|
+
}): Promise<AuthResult<'signed_in', {
|
|
336
|
+
session: PublicSession;
|
|
337
|
+
}>>;
|
|
338
|
+
/** Sends the browser to Cauthy's page to use a passkey; it comes back signed in, at `returnTo`. */
|
|
339
|
+
passkey(options?: {
|
|
340
|
+
returnTo?: string;
|
|
341
|
+
locale?: string;
|
|
342
|
+
}): void;
|
|
343
|
+
/** Where `passkey` sends the browser, for a plain link. */
|
|
344
|
+
passkeyUrl(options?: {
|
|
345
|
+
returnTo?: string;
|
|
346
|
+
locale?: string;
|
|
347
|
+
}): string;
|
|
348
|
+
/** Sends the browser to the provider; it comes back signed in, at `returnTo`. */
|
|
349
|
+
social(provider: string, options?: {
|
|
350
|
+
returnTo?: string;
|
|
351
|
+
}): void;
|
|
352
|
+
/** Where `social` sends the browser, for a plain link. */
|
|
353
|
+
socialUrl(provider: string, options?: {
|
|
354
|
+
returnTo?: string;
|
|
355
|
+
}): string;
|
|
356
|
+
};
|
|
357
|
+
signUp: {
|
|
358
|
+
/** `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in. */
|
|
359
|
+
email(form: {
|
|
360
|
+
email: string;
|
|
361
|
+
password: string;
|
|
362
|
+
name?: string;
|
|
363
|
+
}): Promise<AuthResult<'signed_in', {
|
|
364
|
+
session: PublicSession;
|
|
365
|
+
}> | AuthResult<'verification_required', {
|
|
366
|
+
email: string;
|
|
367
|
+
}>>;
|
|
368
|
+
};
|
|
369
|
+
/** Mails a link to choose a new password. The answer is the same whether or not the address has an account. */
|
|
370
|
+
forgotPassword(form: {
|
|
371
|
+
email: string;
|
|
372
|
+
}): Promise<AuthResult<'sent'>>;
|
|
373
|
+
/** Sets the new password, with the token the mailed link opened the page with (`token`). */
|
|
374
|
+
resetPassword(form: {
|
|
375
|
+
token: string;
|
|
376
|
+
password: string;
|
|
377
|
+
}): Promise<AuthResult<'changed'>>;
|
|
378
|
+
/** Confirms the address, with the token the mailed link opened the page with (`token`). */
|
|
379
|
+
verifyEmail(form: {
|
|
380
|
+
token: string;
|
|
381
|
+
}): Promise<AuthResult<'verified'>>;
|
|
382
|
+
signOut(): Promise<AuthResult<'signed_out'>>;
|
|
383
|
+
/** The signed-in person's own account. */
|
|
384
|
+
account: AccountClient;
|
|
385
|
+
/** Who is signed in, or null. */
|
|
386
|
+
getSession(): Promise<PublicSession | null>;
|
|
387
|
+
methods(): Promise<AuthMethods>;
|
|
388
|
+
/**
|
|
389
|
+
* How the workspace's forms look — colours, corners, typeface — as a person
|
|
390
|
+
* set it in Cauthy's dashboard. Read once per page; null when Cauthy cannot say.
|
|
391
|
+
*/
|
|
392
|
+
look(): Promise<CauthyTheme | null>;
|
|
393
|
+
}
|
|
394
|
+
interface AuthClientOptions {
|
|
395
|
+
/** Where the server mounted the routes. Default: `/api/auth`. */
|
|
396
|
+
basePath?: string;
|
|
397
|
+
fetch?: typeof fetch;
|
|
398
|
+
}
|
|
399
|
+
declare function createAuthClient(options?: AuthClientOptions): AuthClient;
|
|
400
|
+
|
|
401
|
+
/** Every sentence the forms show. Give any of them to change it. */
|
|
402
|
+
interface AuthTexts {
|
|
403
|
+
email: string;
|
|
404
|
+
password: string;
|
|
405
|
+
name: string;
|
|
406
|
+
code: string;
|
|
407
|
+
signIn: string;
|
|
408
|
+
signUp: string;
|
|
409
|
+
continueWith: string;
|
|
410
|
+
orWithEmail: string;
|
|
411
|
+
forgotPassword: string;
|
|
412
|
+
noAccount: string;
|
|
413
|
+
createAccount: string;
|
|
414
|
+
haveAccount: string;
|
|
415
|
+
sendLink: string;
|
|
416
|
+
linkSent: string;
|
|
417
|
+
codeHelp: string;
|
|
418
|
+
verify: string;
|
|
419
|
+
checkEmail: string;
|
|
420
|
+
backToSignIn: string;
|
|
421
|
+
emailMeALink: string;
|
|
422
|
+
usePasskey: string;
|
|
423
|
+
codeFromMail: string;
|
|
424
|
+
signInLinkSent: string;
|
|
425
|
+
newPassword: string;
|
|
426
|
+
savePassword: string;
|
|
427
|
+
passwordChanged: string;
|
|
428
|
+
confirming: string;
|
|
429
|
+
emailConfirmed: string;
|
|
430
|
+
profile: string;
|
|
431
|
+
save: string;
|
|
432
|
+
saved: string;
|
|
433
|
+
currentPassword: string;
|
|
434
|
+
changePassword: string;
|
|
435
|
+
passwordChangedHere: string;
|
|
436
|
+
secondStep: string;
|
|
437
|
+
secondStepOn: string;
|
|
438
|
+
secondStepOff: string;
|
|
439
|
+
turnOn: string;
|
|
440
|
+
turnOff: string;
|
|
441
|
+
addToApp: string;
|
|
442
|
+
openInApp: string;
|
|
443
|
+
recoveryCodes: string;
|
|
444
|
+
newRecoveryCodes: string;
|
|
445
|
+
keepCodes: string;
|
|
446
|
+
passkeys: string;
|
|
447
|
+
managePasskeys: string;
|
|
448
|
+
sessions: string;
|
|
449
|
+
signOutEverywhere: string;
|
|
450
|
+
unknownDevice: string;
|
|
451
|
+
/** By error code; one missing shows what the server said. */
|
|
452
|
+
errors: Record<string, string>;
|
|
453
|
+
}
|
|
454
|
+
type Slot = 'form' | 'field' | 'label' | 'input' | 'button' | 'providerButton' | 'link' | 'error' | 'fieldError' | 'notice' | 'separator' | 'footer' | 'account' | 'section' | 'heading' | 'secret' | 'codes' | 'sessions' | 'session';
|
|
455
|
+
interface AuthFormProps {
|
|
456
|
+
/** The language of the built-in sentences. Default: `en`. */
|
|
457
|
+
locale?: 'en' | 'es';
|
|
458
|
+
/** Sentences of the application's own, over the built-in ones. */
|
|
459
|
+
texts?: Partial<Omit<AuthTexts, 'errors'>> & {
|
|
460
|
+
errors?: Record<string, string>;
|
|
461
|
+
};
|
|
462
|
+
/** Called once the person is signed in. Default: go to `returnTo`. */
|
|
463
|
+
onSuccess?: () => void;
|
|
464
|
+
/** Where to go after signing in, and where a provider returns to. Default: `/`. */
|
|
465
|
+
returnTo?: string;
|
|
466
|
+
/** Paths of the application's other screens, for the links between them. */
|
|
467
|
+
links?: {
|
|
468
|
+
signIn?: string;
|
|
469
|
+
signUp?: string;
|
|
470
|
+
forgotPassword?: string;
|
|
471
|
+
};
|
|
472
|
+
/** A class for each part the form renders. A part given one is left to it by `styles.css`. */
|
|
473
|
+
classNames?: Partial<Record<Slot, string>>;
|
|
474
|
+
/**
|
|
475
|
+
* No look of Cauthy's at all: `styles.css` leaves the form alone and the
|
|
476
|
+
* workspace's colours are not read. For a form drawn wholly with the
|
|
477
|
+
* application's own `components` or `classNames`.
|
|
478
|
+
*/
|
|
479
|
+
unstyled?: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Take the colours, corners and typeface a person set for the workspace in
|
|
482
|
+
* Cauthy's dashboard. Default: true. False keeps `styles.css`'s own, and
|
|
483
|
+
* whatever `--cauthy-*` variables the application sets.
|
|
484
|
+
*/
|
|
485
|
+
workspaceLook?: boolean;
|
|
486
|
+
/**
|
|
487
|
+
* The application's own button and input, to draw the form with. Each is
|
|
488
|
+
* given what a `<button>` or an `<input>` would be.
|
|
489
|
+
*/
|
|
490
|
+
components?: {
|
|
491
|
+
Button?: ComponentType<{
|
|
492
|
+
type: 'submit' | 'button';
|
|
493
|
+
disabled?: boolean;
|
|
494
|
+
className?: string;
|
|
495
|
+
onClick?: () => void;
|
|
496
|
+
children: ReactNode;
|
|
497
|
+
}>;
|
|
498
|
+
Input?: ComponentType<{
|
|
499
|
+
id: string;
|
|
500
|
+
name: string;
|
|
501
|
+
type: string;
|
|
502
|
+
value: string;
|
|
503
|
+
autoComplete?: string;
|
|
504
|
+
required?: boolean;
|
|
505
|
+
className?: string;
|
|
506
|
+
'aria-invalid'?: boolean;
|
|
507
|
+
'aria-describedby'?: string;
|
|
508
|
+
onChange: (e: {
|
|
509
|
+
target: {
|
|
510
|
+
value: string;
|
|
511
|
+
};
|
|
512
|
+
}) => void;
|
|
513
|
+
}>;
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
declare function SignIn(props: AuthFormProps): react.JSX.Element;
|
|
517
|
+
declare function SignUp(props: AuthFormProps): react.JSX.Element;
|
|
518
|
+
declare function ForgotPassword(props: AuthFormProps): react.JSX.Element;
|
|
519
|
+
/** The page a "choose a new password" link opens: `pages.resetPassword`. */
|
|
520
|
+
declare function ResetPassword(props: AuthFormProps): react.JSX.Element;
|
|
521
|
+
/** The page a "confirm your address" link opens: `pages.verifyEmail`. It confirms as it opens. */
|
|
522
|
+
declare function VerifyEmail(props: AuthFormProps): react.JSX.Element;
|
|
523
|
+
interface AccountProps extends Omit<AuthFormProps, 'links' | 'returnTo' | 'onSuccess'> {
|
|
524
|
+
/** Called after "sign out everywhere". Default: go to `/`. */
|
|
525
|
+
onSignedOut?: () => void;
|
|
526
|
+
/** The moment of a session, as the application writes dates. Default: the browser's own way, in the reader's time zone. */
|
|
527
|
+
formatDate?: (iso: string) => string;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* The signed-in person's account, in the application: their name, their
|
|
531
|
+
* password, the second step, and where they are signed in. Each part saves on
|
|
532
|
+
* its own. Like the other forms, it carries no styles.
|
|
533
|
+
*/
|
|
534
|
+
declare function Account(props: AccountProps): react.JSX.Element;
|
|
8
535
|
|
|
9
536
|
interface SessionContext {
|
|
10
537
|
/** The signed-in person and their organizations, or null. */
|
|
@@ -22,6 +549,8 @@ interface SessionContext {
|
|
|
22
549
|
refresh(): Promise<PublicSession | null>;
|
|
23
550
|
/** Where the person looks after their account: password, second step, passkeys. */
|
|
24
551
|
accountUrl(returnTo?: string): string;
|
|
552
|
+
/** Where the server mounted the routes. */
|
|
553
|
+
basePath: string;
|
|
25
554
|
}
|
|
26
555
|
interface CauthyProviderProps {
|
|
27
556
|
children: ReactNode;
|
|
@@ -36,5 +565,15 @@ interface CauthyProviderProps {
|
|
|
36
565
|
}
|
|
37
566
|
declare function CauthyProvider({ children, basePath, initialSession }: CauthyProviderProps): react.JSX.Element;
|
|
38
567
|
declare function useSession(): SessionContext;
|
|
568
|
+
/**
|
|
569
|
+
* The application's own sign-in screens: the functions a form calls.
|
|
570
|
+
*
|
|
571
|
+
* const { signIn, signUp, forgotPassword, signOut, session } = useAuth()
|
|
572
|
+
* const r = await signIn.email({ email, password })
|
|
573
|
+
*
|
|
574
|
+
* They are `createAuthClient()`'s, and what is on screen follows them: after
|
|
575
|
+
* a sign-in or a sign-out, `session` is the new one with no reload.
|
|
576
|
+
*/
|
|
577
|
+
declare function useAuth(): AuthClient & Pick<SessionContext, 'session' | 'status' | 'refresh'>;
|
|
39
578
|
|
|
40
|
-
export { CauthyProvider, type CauthyProviderProps, PublicSession, type SessionContext, useSession };
|
|
579
|
+
export { Account, type AccountClient, type Account$1 as AccountDetails, type AccountProps, type AccountSession, type AuthClient, type AuthError, type AuthFormProps, type AuthMethods, type AuthResult, type AuthTexts, CauthyProvider, type CauthyProviderProps, ForgotPassword, type JsonValue, type PermissionOf, type Policy, type PublicSession, ResetPassword, type RoleOf, type SessionContext, type SessionOrganization, type SessionUser, SignIn, SignUp, VerifyEmail, can, createAuthClient, definePolicy, useAuth, useSession };
|