cauthy-auth 0.20.0 → 0.23.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.
Files changed (43) hide show
  1. package/dist/{cauthy-Bn3iv50y.d.ts → cauthy-DGAy45G2.d.ts} +1 -1
  2. package/dist/{cauthy-C29HCvag.d.mts → cauthy-XkIbG5gE.d.mts} +1 -1
  3. package/dist/client.d.mts +133 -3
  4. package/dist/client.d.ts +133 -3
  5. package/dist/client.js +54 -0
  6. package/dist/client.js.map +1 -1
  7. package/dist/client.mjs +54 -0
  8. package/dist/client.mjs.map +1 -1
  9. package/dist/express.d.mts +2 -2
  10. package/dist/express.d.ts +2 -2
  11. package/dist/fastify.d.mts +2 -2
  12. package/dist/fastify.d.ts +2 -2
  13. package/dist/hono.d.mts +2 -2
  14. package/dist/hono.d.ts +2 -2
  15. package/dist/index.d.mts +2 -2
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +178 -5
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +178 -5
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/next.d.mts +2 -2
  22. package/dist/next.d.ts +2 -2
  23. package/dist/react.d.mts +171 -2
  24. package/dist/react.d.ts +171 -2
  25. package/dist/react.js +261 -3
  26. package/dist/react.js.map +1 -1
  27. package/dist/react.mjs +260 -3
  28. package/dist/react.mjs.map +1 -1
  29. package/dist/svelte.d.mts +2 -2
  30. package/dist/svelte.d.ts +2 -2
  31. package/dist/svelte.js +54 -0
  32. package/dist/svelte.js.map +1 -1
  33. package/dist/svelte.mjs +54 -0
  34. package/dist/svelte.mjs.map +1 -1
  35. package/dist/{system-ZD_Wa8Bm.d.mts → system-BxMsSIu1.d.mts} +2 -0
  36. package/dist/{system-DhRr_WxR.d.ts → system-DTIeDXDP.d.ts} +2 -0
  37. package/dist/vue.d.mts +2 -2
  38. package/dist/vue.d.ts +2 -2
  39. package/dist/vue.js +54 -0
  40. package/dist/vue.js.map +1 -1
  41. package/dist/vue.mjs +54 -0
  42. package/dist/vue.mjs.map +1 -1
  43. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-DhRr_WxR.js';
1
+ import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-DTIeDXDP.js';
2
2
  import { JWTVerifyGetKey } from 'jose';
3
3
 
4
4
  /** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
@@ -1,4 +1,4 @@
1
- import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-ZD_Wa8Bm.mjs';
1
+ import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-BxMsSIu1.mjs';
2
2
  import { JWTVerifyGetKey } from 'jose';
3
3
 
4
4
  /** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
package/dist/client.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CauthyTheme } from './theme.mjs';
2
- import { i as PublicSession } from './system-ZD_Wa8Bm.mjs';
2
+ import { i as PublicSession } from './system-BxMsSIu1.mjs';
3
3
  import { A as AuthField } from './validate-B_iC-4y8.mjs';
4
4
  export { F as FieldProblem, M as MIN_PASSWORD, c as checkCode, a as checkEmail, b as checkName, d as checkNewPassword, e as checkPassword } from './validate-B_iC-4y8.mjs';
5
5
  import 'jose';
@@ -163,6 +163,82 @@ interface ConnectedAgent {
163
163
  connectedAt: string;
164
164
  lastUsedAt: string;
165
165
  }
166
+ /** An organization the person belongs to, with what their role lets them do with its people. */
167
+ interface OrganizationSeat {
168
+ id: string;
169
+ /** The client system it is of (`pondari`). */
170
+ system: string;
171
+ name: string;
172
+ kind: string;
173
+ /** The person's role in it. */
174
+ role: string;
175
+ /** Cauthy's member powers, from the system's catalog: cauthy:members read and manage. */
176
+ can: {
177
+ readMembers: boolean;
178
+ manageMembers: boolean;
179
+ };
180
+ }
181
+ /** A person of an organization, as a member who may see them reads it. */
182
+ interface OrganizationPerson {
183
+ userId: string;
184
+ email: string;
185
+ name: string;
186
+ role: string;
187
+ /** The account's: `active`, `suspended`… A disabled member is still listed. */
188
+ status: string;
189
+ /** Invited and not yet accepted. */
190
+ invited: boolean;
191
+ /** Manages the organization's members. */
192
+ manager: boolean;
193
+ /** The signed-in person. */
194
+ you: boolean;
195
+ /** UTC, ISO 8601. */
196
+ since: string;
197
+ }
198
+ /** A role of the organization's system, as the catalog names it. */
199
+ interface OrganizationRoleChoice {
200
+ role: string;
201
+ name: string;
202
+ description: string;
203
+ /** Holding it manages the organization's members. */
204
+ manager: boolean;
205
+ }
206
+ /**
207
+ * The signed-in person's organizations, and their people. Seeing them needs
208
+ * cauthy:members read in the person's role; changing them needs manage. Cauthy
209
+ * decides, with the person's own session: the application authorizes nothing.
210
+ */
211
+ interface OrganizationsClient {
212
+ /** The organizations the person belongs to; one system's only with `system`. */
213
+ list(system?: string): Promise<OrganizationSeat[]>;
214
+ /** The people of one, or null when the person may not see them. */
215
+ members(organizationId: string): Promise<OrganizationPerson[] | null>;
216
+ /** The roles a member may be given, or null when the person may not see them. */
217
+ roles(organizationId: string): Promise<OrganizationRoleChoice[] | null>;
218
+ /** Adds a person by their address; an address with no account gets one and its invitation. */
219
+ add(organizationId: string, form: {
220
+ email: string;
221
+ role: string;
222
+ name?: string;
223
+ locale?: string;
224
+ }): Promise<AuthResult<'added', {
225
+ member: OrganizationPerson;
226
+ }>>;
227
+ setRole(organizationId: string, userId: string, role: string): Promise<AuthResult<'changed', {
228
+ userId: string;
229
+ role: string;
230
+ }>>;
231
+ /** Removes a member; the person themself may always leave. */
232
+ remove(organizationId: string, userId: string): Promise<AuthResult<'removed', {
233
+ userId: string;
234
+ }>>;
235
+ /** Sends a member's invitation again. */
236
+ inviteAgain(organizationId: string, userId: string, form?: {
237
+ locale?: string;
238
+ }): Promise<AuthResult<'sent', {
239
+ userId: string;
240
+ }>>;
241
+ }
166
242
  interface AccountSession {
167
243
  /** "Mac · Chrome", or "" when the browser did not say. */
168
244
  device: string;
@@ -285,6 +361,26 @@ interface AccountClient {
285
361
  unlink(provider: string): Promise<AuthResult<'unlinked', {
286
362
  provider: string;
287
363
  }>>;
364
+ /**
365
+ * A guest becomes an account of their own with an address and a password —
366
+ * the same id, so what they did stays theirs. `email_taken`: the address has
367
+ * an account already; offer to sign in with it.
368
+ */
369
+ upgrade(form: {
370
+ email: string;
371
+ password: string;
372
+ name?: string;
373
+ }): Promise<AuthResult<'signed_in', {
374
+ session: PublicSession;
375
+ }>>;
376
+ /** Where a guest goes to become the account of a provider's address (Google…). */
377
+ upgradeUrl(provider: string, options?: {
378
+ returnTo?: string;
379
+ }): string;
380
+ /** Sends a guest to `upgradeUrl`; they come back signed in as the account. */
381
+ upgradeWith(provider: string, options?: {
382
+ returnTo?: string;
383
+ }): void;
288
384
  /** Where the account is signed in. */
289
385
  sessions(): Promise<AccountSession[]>;
290
386
  /** Signs the account out everywhere, here too. */
@@ -318,6 +414,17 @@ interface AccountClient {
318
414
  }
319
415
  interface AuthClient {
320
416
  signIn: {
417
+ /**
418
+ * A guest session, before the visitor signs up: the application keeps what
419
+ * they do under `session.user.id`, and `account.upgrade` (or
420
+ * `account.upgradeWith`) makes it their account, same id. Only where the
421
+ * workspace allows guests (`anonymous_disabled` otherwise).
422
+ */
423
+ anonymously(form?: {
424
+ captchaToken?: string;
425
+ }): Promise<AuthResult<'signed_in', {
426
+ session: PublicSession;
427
+ }>>;
321
428
  /** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
322
429
  email(form: {
323
430
  email: string;
@@ -332,13 +439,34 @@ interface AuthClient {
332
439
  }): Promise<AuthResult<'signed_in', {
333
440
  session: PublicSession;
334
441
  }>>;
335
- /** While the second step is asked for: whether the account has an authenticator app, and the phone (masked) a code can be sent to. */
442
+ /** While the second step is asked for: whether the account has an authenticator app, the phone (masked) a code can be sent to, and phones that approve sign-ins. */
336
443
  mfaMethods(): Promise<AuthResult<'ok', {
337
444
  totp: boolean;
338
445
  phone: {
339
446
  number: string;
340
447
  channel: string;
341
448
  } | null;
449
+ push: {
450
+ devices: number;
451
+ } | null;
452
+ }>>;
453
+ /**
454
+ * Sends a push to the account's phones (the application's app, with
455
+ * cauthy-expo): show `number`, which the person picks on the phone, then
456
+ * call `mfaPushWait`.
457
+ */
458
+ mfaPush(): Promise<AuthResult<'sent', {
459
+ number: number;
460
+ }>>;
461
+ /**
462
+ * Waits for the phone's answer, listening (server-sent events) rather than
463
+ * asking again and again, and signs in when it approves. `denied`: turned
464
+ * down on the phone; `expired`: nobody answered in time.
465
+ */
466
+ mfaPushWait(o?: {
467
+ signal?: AbortSignal;
468
+ }): Promise<AuthResult<'signed_in', {
469
+ session: PublicSession;
342
470
  }>>;
343
471
  /** Sends a code to the account's phone, by SMS or WhatsApp; `mfa` takes it. A few per sign-in. */
344
472
  mfaSendCode(): Promise<AuthResult<'sent', {
@@ -493,6 +621,8 @@ interface AuthClient {
493
621
  signOut(): Promise<AuthResult<'signed_out'>>;
494
622
  /** The signed-in person's own account. */
495
623
  account: AccountClient;
624
+ /** The signed-in person's organizations, and their people. */
625
+ organizations: OrganizationsClient;
496
626
  /** Who is signed in, or null. */
497
627
  getSession(): Promise<PublicSession | null>;
498
628
  methods(): Promise<AuthMethods>;
@@ -516,4 +646,4 @@ interface AuthClientOptions {
516
646
  }
517
647
  declare function createAuthClient(options?: AuthClientOptions): AuthClient;
518
648
 
519
- export { type Account, type AccountClient, type AccountSession, type AuthClient, type AuthClientOptions, type AuthError, AuthField, type AuthMethods, type AuthResult, type ConnectedAgent, type LinkedIdentity, type Passkey, type PasskeyKind, type SSOConnection, type SecondStep, type SessionState, type SessionStore, type SessionStoreOptions, canAutofillPasskeys, canUsePasskeys, createAuthClient, createSessionStore };
649
+ export { type Account, type AccountClient, type AccountSession, type AuthClient, type AuthClientOptions, type AuthError, AuthField, type AuthMethods, type AuthResult, type ConnectedAgent, type LinkedIdentity, type OrganizationPerson, type OrganizationRoleChoice, type OrganizationSeat, type OrganizationsClient, type Passkey, type PasskeyKind, type SSOConnection, type SecondStep, type SessionState, type SessionStore, type SessionStoreOptions, canAutofillPasskeys, canUsePasskeys, createAuthClient, createSessionStore };
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CauthyTheme } from './theme.js';
2
- import { i as PublicSession } from './system-DhRr_WxR.js';
2
+ import { i as PublicSession } from './system-DTIeDXDP.js';
3
3
  import { A as AuthField } from './validate-B_iC-4y8.js';
4
4
  export { F as FieldProblem, M as MIN_PASSWORD, c as checkCode, a as checkEmail, b as checkName, d as checkNewPassword, e as checkPassword } from './validate-B_iC-4y8.js';
5
5
  import 'jose';
@@ -163,6 +163,82 @@ interface ConnectedAgent {
163
163
  connectedAt: string;
164
164
  lastUsedAt: string;
165
165
  }
166
+ /** An organization the person belongs to, with what their role lets them do with its people. */
167
+ interface OrganizationSeat {
168
+ id: string;
169
+ /** The client system it is of (`pondari`). */
170
+ system: string;
171
+ name: string;
172
+ kind: string;
173
+ /** The person's role in it. */
174
+ role: string;
175
+ /** Cauthy's member powers, from the system's catalog: cauthy:members read and manage. */
176
+ can: {
177
+ readMembers: boolean;
178
+ manageMembers: boolean;
179
+ };
180
+ }
181
+ /** A person of an organization, as a member who may see them reads it. */
182
+ interface OrganizationPerson {
183
+ userId: string;
184
+ email: string;
185
+ name: string;
186
+ role: string;
187
+ /** The account's: `active`, `suspended`… A disabled member is still listed. */
188
+ status: string;
189
+ /** Invited and not yet accepted. */
190
+ invited: boolean;
191
+ /** Manages the organization's members. */
192
+ manager: boolean;
193
+ /** The signed-in person. */
194
+ you: boolean;
195
+ /** UTC, ISO 8601. */
196
+ since: string;
197
+ }
198
+ /** A role of the organization's system, as the catalog names it. */
199
+ interface OrganizationRoleChoice {
200
+ role: string;
201
+ name: string;
202
+ description: string;
203
+ /** Holding it manages the organization's members. */
204
+ manager: boolean;
205
+ }
206
+ /**
207
+ * The signed-in person's organizations, and their people. Seeing them needs
208
+ * cauthy:members read in the person's role; changing them needs manage. Cauthy
209
+ * decides, with the person's own session: the application authorizes nothing.
210
+ */
211
+ interface OrganizationsClient {
212
+ /** The organizations the person belongs to; one system's only with `system`. */
213
+ list(system?: string): Promise<OrganizationSeat[]>;
214
+ /** The people of one, or null when the person may not see them. */
215
+ members(organizationId: string): Promise<OrganizationPerson[] | null>;
216
+ /** The roles a member may be given, or null when the person may not see them. */
217
+ roles(organizationId: string): Promise<OrganizationRoleChoice[] | null>;
218
+ /** Adds a person by their address; an address with no account gets one and its invitation. */
219
+ add(organizationId: string, form: {
220
+ email: string;
221
+ role: string;
222
+ name?: string;
223
+ locale?: string;
224
+ }): Promise<AuthResult<'added', {
225
+ member: OrganizationPerson;
226
+ }>>;
227
+ setRole(organizationId: string, userId: string, role: string): Promise<AuthResult<'changed', {
228
+ userId: string;
229
+ role: string;
230
+ }>>;
231
+ /** Removes a member; the person themself may always leave. */
232
+ remove(organizationId: string, userId: string): Promise<AuthResult<'removed', {
233
+ userId: string;
234
+ }>>;
235
+ /** Sends a member's invitation again. */
236
+ inviteAgain(organizationId: string, userId: string, form?: {
237
+ locale?: string;
238
+ }): Promise<AuthResult<'sent', {
239
+ userId: string;
240
+ }>>;
241
+ }
166
242
  interface AccountSession {
167
243
  /** "Mac · Chrome", or "" when the browser did not say. */
168
244
  device: string;
@@ -285,6 +361,26 @@ interface AccountClient {
285
361
  unlink(provider: string): Promise<AuthResult<'unlinked', {
286
362
  provider: string;
287
363
  }>>;
364
+ /**
365
+ * A guest becomes an account of their own with an address and a password —
366
+ * the same id, so what they did stays theirs. `email_taken`: the address has
367
+ * an account already; offer to sign in with it.
368
+ */
369
+ upgrade(form: {
370
+ email: string;
371
+ password: string;
372
+ name?: string;
373
+ }): Promise<AuthResult<'signed_in', {
374
+ session: PublicSession;
375
+ }>>;
376
+ /** Where a guest goes to become the account of a provider's address (Google…). */
377
+ upgradeUrl(provider: string, options?: {
378
+ returnTo?: string;
379
+ }): string;
380
+ /** Sends a guest to `upgradeUrl`; they come back signed in as the account. */
381
+ upgradeWith(provider: string, options?: {
382
+ returnTo?: string;
383
+ }): void;
288
384
  /** Where the account is signed in. */
289
385
  sessions(): Promise<AccountSession[]>;
290
386
  /** Signs the account out everywhere, here too. */
@@ -318,6 +414,17 @@ interface AccountClient {
318
414
  }
319
415
  interface AuthClient {
320
416
  signIn: {
417
+ /**
418
+ * A guest session, before the visitor signs up: the application keeps what
419
+ * they do under `session.user.id`, and `account.upgrade` (or
420
+ * `account.upgradeWith`) makes it their account, same id. Only where the
421
+ * workspace allows guests (`anonymous_disabled` otherwise).
422
+ */
423
+ anonymously(form?: {
424
+ captchaToken?: string;
425
+ }): Promise<AuthResult<'signed_in', {
426
+ session: PublicSession;
427
+ }>>;
321
428
  /** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
322
429
  email(form: {
323
430
  email: string;
@@ -332,13 +439,34 @@ interface AuthClient {
332
439
  }): Promise<AuthResult<'signed_in', {
333
440
  session: PublicSession;
334
441
  }>>;
335
- /** While the second step is asked for: whether the account has an authenticator app, and the phone (masked) a code can be sent to. */
442
+ /** While the second step is asked for: whether the account has an authenticator app, the phone (masked) a code can be sent to, and phones that approve sign-ins. */
336
443
  mfaMethods(): Promise<AuthResult<'ok', {
337
444
  totp: boolean;
338
445
  phone: {
339
446
  number: string;
340
447
  channel: string;
341
448
  } | null;
449
+ push: {
450
+ devices: number;
451
+ } | null;
452
+ }>>;
453
+ /**
454
+ * Sends a push to the account's phones (the application's app, with
455
+ * cauthy-expo): show `number`, which the person picks on the phone, then
456
+ * call `mfaPushWait`.
457
+ */
458
+ mfaPush(): Promise<AuthResult<'sent', {
459
+ number: number;
460
+ }>>;
461
+ /**
462
+ * Waits for the phone's answer, listening (server-sent events) rather than
463
+ * asking again and again, and signs in when it approves. `denied`: turned
464
+ * down on the phone; `expired`: nobody answered in time.
465
+ */
466
+ mfaPushWait(o?: {
467
+ signal?: AbortSignal;
468
+ }): Promise<AuthResult<'signed_in', {
469
+ session: PublicSession;
342
470
  }>>;
343
471
  /** Sends a code to the account's phone, by SMS or WhatsApp; `mfa` takes it. A few per sign-in. */
344
472
  mfaSendCode(): Promise<AuthResult<'sent', {
@@ -493,6 +621,8 @@ interface AuthClient {
493
621
  signOut(): Promise<AuthResult<'signed_out'>>;
494
622
  /** The signed-in person's own account. */
495
623
  account: AccountClient;
624
+ /** The signed-in person's organizations, and their people. */
625
+ organizations: OrganizationsClient;
496
626
  /** Who is signed in, or null. */
497
627
  getSession(): Promise<PublicSession | null>;
498
628
  methods(): Promise<AuthMethods>;
@@ -516,4 +646,4 @@ interface AuthClientOptions {
516
646
  }
517
647
  declare function createAuthClient(options?: AuthClientOptions): AuthClient;
518
648
 
519
- export { type Account, type AccountClient, type AccountSession, type AuthClient, type AuthClientOptions, type AuthError, AuthField, type AuthMethods, type AuthResult, type ConnectedAgent, type LinkedIdentity, type Passkey, type PasskeyKind, type SSOConnection, type SecondStep, type SessionState, type SessionStore, type SessionStoreOptions, canAutofillPasskeys, canUsePasskeys, createAuthClient, createSessionStore };
649
+ export { type Account, type AccountClient, type AccountSession, type AuthClient, type AuthClientOptions, type AuthError, AuthField, type AuthMethods, type AuthResult, type ConnectedAgent, type LinkedIdentity, type OrganizationPerson, type OrganizationRoleChoice, type OrganizationSeat, type OrganizationsClient, type Passkey, type PasskeyKind, type SSOConnection, type SecondStep, type SessionState, type SessionStore, type SessionStoreOptions, canAutofillPasskeys, canUsePasskeys, createAuthClient, createSessionStore };
package/dist/client.js CHANGED
@@ -343,6 +343,7 @@ function createAuthClient(options = {}) {
343
343
  return null;
344
344
  }
345
345
  }
346
+ const upgradeUrl = (provider, o = {}) => `${base}/me/upgrade/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
346
347
  const linkUrl = (provider, o = {}) => `${base}/me/identities/link/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
347
348
  const socialUrl = (provider, o = {}) => `${base}/sign-in/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
348
349
  const ssoUrl = (target, o = {}) => {
@@ -380,10 +381,40 @@ function createAuthClient(options = {}) {
380
381
  }
381
382
  return {
382
383
  signIn: {
384
+ anonymously: (f = {}) => post("/sign-in/anonymous", {}, null, f.captchaToken),
383
385
  email: (f) => post("/sign-in/email", { email: f.email, password: f.password }, firstProblem(checkEmail(f.email), checkPassword(f.password)), f.captchaToken),
384
386
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
385
387
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
386
388
  mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
389
+ mfaPush: () => post("/sign-in/mfa/push", {}, null),
390
+ async mfaPushWait(o = {}) {
391
+ const status = await new Promise((resolve) => {
392
+ if (typeof EventSource !== "function") return resolve("approved");
393
+ const source = new EventSource(`${base}/sign-in/mfa/push/events`, { withCredentials: true });
394
+ const stop = (st) => {
395
+ source.close();
396
+ resolve(st);
397
+ };
398
+ o.signal?.addEventListener("abort", () => stop("aborted"));
399
+ source.addEventListener("status", (e) => {
400
+ const st = (() => {
401
+ try {
402
+ return String(JSON.parse(e.data).status);
403
+ } catch {
404
+ return "";
405
+ }
406
+ })();
407
+ if (st && st !== "pending") stop(st);
408
+ });
409
+ source.onerror = () => {
410
+ if (source.readyState === EventSource.CLOSED) stop("expired");
411
+ };
412
+ });
413
+ if (status === "aborted") return { ok: false, error: { code: "aborted", message: "Stopped waiting." } };
414
+ if (status === "denied") return { ok: false, error: { code: "push_denied", message: "The sign-in was turned down on the phone." } };
415
+ if (status === "expired") return { ok: false, error: { code: "push_expired", message: "Nobody answered on the phone in time." } };
416
+ return post("/sign-in/mfa/push/finish", {}, null);
417
+ },
387
418
  magicLink: (f) => post("/sign-in/magic-link", { email: f.email, ...f.create ? { create: true } : {}, ...f.returnTo ? { returnTo: f.returnTo } : {} }, checkEmail(f.email), f.captchaToken),
388
419
  magicLinkVerify: (f) => post("/sign-in/magic-link/verify", { token: f.token }, null),
389
420
  emailCode: (f) => post("/sign-in/email-code", { code: f.code }, checkCode(f.code)),
@@ -477,6 +508,24 @@ function createAuthClient(options = {}) {
477
508
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
478
509
  verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
479
510
  signOut: () => post("/sign-out", {}, null),
511
+ organizations: {
512
+ async list(system) {
513
+ const body = await read(`/me/organizations${system ? `?system=${encodeURIComponent(system)}` : ""}`);
514
+ return body && Array.isArray(body.organizations) ? body.organizations : [];
515
+ },
516
+ async members(id) {
517
+ const body = await read(`/me/organizations/members?id=${encodeURIComponent(id)}`);
518
+ return body && Array.isArray(body.members) ? body.members : null;
519
+ },
520
+ async roles(id) {
521
+ const body = await read(`/me/organizations/roles?id=${encodeURIComponent(id)}`);
522
+ return body && Array.isArray(body.roles) ? body.roles : null;
523
+ },
524
+ add: (id, f) => post("/me/organizations/members/add", { organizationId: id, email: f.email, role: f.role, name: f.name ?? "", locale: f.locale ?? "" }, checkEmail(f.email)),
525
+ setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
526
+ remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
527
+ inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
528
+ },
480
529
  account: {
481
530
  async get() {
482
531
  const body = await read("/me");
@@ -515,6 +564,11 @@ function createAuthClient(options = {}) {
515
564
  return body && Array.isArray(body.sessions) ? body.sessions : [];
516
565
  },
517
566
  signOutEverywhere: () => post("/me/sessions/end", {}, null),
567
+ upgrade: (f) => post("/me/upgrade", { email: f.email, password: f.password, name: f.name ?? "" }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password))),
568
+ upgradeUrl,
569
+ upgradeWith(provider, o) {
570
+ window.location.assign(upgradeUrl(provider, o));
571
+ },
518
572
  async agents() {
519
573
  const body = await read("/me/agents");
520
574
  return body && Array.isArray(body.agents) ? body.agents : [];