cauthy-auth 0.20.0 → 0.22.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 +111 -2
  4. package/dist/client.d.ts +111 -2
  5. package/dist/client.js +25 -0
  6. package/dist/client.js.map +1 -1
  7. package/dist/client.mjs +25 -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 +133 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +133 -4
  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 +145 -1
  24. package/dist/react.d.ts +145 -1
  25. package/dist/react.js +200 -2
  26. package/dist/react.js.map +1 -1
  27. package/dist/react.mjs +199 -2
  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 +25 -0
  32. package/dist/svelte.js.map +1 -1
  33. package/dist/svelte.mjs +25 -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 +25 -0
  40. package/dist/vue.js.map +1 -1
  41. package/dist/vue.mjs +25 -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;
@@ -493,6 +600,8 @@ interface AuthClient {
493
600
  signOut(): Promise<AuthResult<'signed_out'>>;
494
601
  /** The signed-in person's own account. */
495
602
  account: AccountClient;
603
+ /** The signed-in person's organizations, and their people. */
604
+ organizations: OrganizationsClient;
496
605
  /** Who is signed in, or null. */
497
606
  getSession(): Promise<PublicSession | null>;
498
607
  methods(): Promise<AuthMethods>;
@@ -516,4 +625,4 @@ interface AuthClientOptions {
516
625
  }
517
626
  declare function createAuthClient(options?: AuthClientOptions): AuthClient;
518
627
 
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 };
628
+ 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;
@@ -493,6 +600,8 @@ interface AuthClient {
493
600
  signOut(): Promise<AuthResult<'signed_out'>>;
494
601
  /** The signed-in person's own account. */
495
602
  account: AccountClient;
603
+ /** The signed-in person's organizations, and their people. */
604
+ organizations: OrganizationsClient;
496
605
  /** Who is signed in, or null. */
497
606
  getSession(): Promise<PublicSession | null>;
498
607
  methods(): Promise<AuthMethods>;
@@ -516,4 +625,4 @@ interface AuthClientOptions {
516
625
  }
517
626
  declare function createAuthClient(options?: AuthClientOptions): AuthClient;
518
627
 
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 };
628
+ 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,6 +381,7 @@ 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),
@@ -477,6 +479,24 @@ function createAuthClient(options = {}) {
477
479
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
478
480
  verifyEmail: (f) => post("/verify-email", { token: f.token }, null),
479
481
  signOut: () => post("/sign-out", {}, null),
482
+ organizations: {
483
+ async list(system) {
484
+ const body = await read(`/me/organizations${system ? `?system=${encodeURIComponent(system)}` : ""}`);
485
+ return body && Array.isArray(body.organizations) ? body.organizations : [];
486
+ },
487
+ async members(id) {
488
+ const body = await read(`/me/organizations/members?id=${encodeURIComponent(id)}`);
489
+ return body && Array.isArray(body.members) ? body.members : null;
490
+ },
491
+ async roles(id) {
492
+ const body = await read(`/me/organizations/roles?id=${encodeURIComponent(id)}`);
493
+ return body && Array.isArray(body.roles) ? body.roles : null;
494
+ },
495
+ 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)),
496
+ setRole: (id, userId, role) => post("/me/organizations/members/role", { organizationId: id, userId, role }, null),
497
+ remove: (id, userId) => post("/me/organizations/members/remove", { organizationId: id, userId }, null),
498
+ inviteAgain: (id, userId, f = {}) => post("/me/organizations/members/invite", { organizationId: id, userId, locale: f.locale ?? "" }, null)
499
+ },
480
500
  account: {
481
501
  async get() {
482
502
  const body = await read("/me");
@@ -515,6 +535,11 @@ function createAuthClient(options = {}) {
515
535
  return body && Array.isArray(body.sessions) ? body.sessions : [];
516
536
  },
517
537
  signOutEverywhere: () => post("/me/sessions/end", {}, null),
538
+ upgrade: (f) => post("/me/upgrade", { email: f.email, password: f.password, name: f.name ?? "" }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password))),
539
+ upgradeUrl,
540
+ upgradeWith(provider, o) {
541
+ window.location.assign(upgradeUrl(provider, o));
542
+ },
518
543
  async agents() {
519
544
  const body = await read("/me/agents");
520
545
  return body && Array.isArray(body.agents) ? body.agents : [];