cauthy-auth 0.25.0 → 0.27.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/dist/client.d.mts CHANGED
@@ -110,6 +110,30 @@ interface AuthMethods {
110
110
  * found by their work address (`signIn.ssoDiscover`, `signIn.sso`).
111
111
  */
112
112
  sso: boolean;
113
+ /**
114
+ * Set when the workspace asks something of a sign-up: the legal documents
115
+ * to accept (the terms, the privacy policy: show the links and a box, send
116
+ * `acceptLegal: true`) and the consents to ask (one box each, sent as
117
+ * `consents`; a required one must be ticked). The ready-made form shows them.
118
+ */
119
+ legal?: {
120
+ documents: {
121
+ kind: string;
122
+ version: string;
123
+ url: string;
124
+ }[];
125
+ consentPurposes: {
126
+ key: string;
127
+ label: string;
128
+ required: boolean;
129
+ }[];
130
+ };
131
+ }
132
+ /** A legal document the person owes: not yet accepted in its current version. */
133
+ interface PendingLegal {
134
+ kind: string;
135
+ version: string;
136
+ url: string;
113
137
  }
114
138
  /** A company's sign-in (an SSO connection of the workspace). */
115
139
  interface SSOConnection {
@@ -290,6 +314,18 @@ interface AccountClient {
290
314
  }): Promise<AuthResult<'changed', {
291
315
  signedIn: boolean;
292
316
  }>>;
317
+ /**
318
+ * The legal documents the person has not accepted in their current version
319
+ * (a new version of the terms, say): show them and call `acceptLegal`.
320
+ * Nothing stops the person meanwhile; the application decides what waits.
321
+ */
322
+ legal(): Promise<AuthResult<'ok', {
323
+ pending: PendingLegal[];
324
+ }>>;
325
+ /** Records the person's acceptance of the documents in force (the kinds named, or every one). */
326
+ acceptLegal(form?: {
327
+ kinds?: string[];
328
+ }): Promise<AuthResult<'accepted'>>;
293
329
  mfa: {
294
330
  /** Starts turning the second step on: show `secret` (or `otpauthUri` as a QR code) to add to an authenticator app, then call `verify`. */
295
331
  setup(form: {
@@ -430,21 +466,34 @@ interface AuthClient {
430
466
  }): Promise<AuthResult<'signed_in', {
431
467
  session: PublicSession;
432
468
  }>>;
433
- /** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
469
+ /**
470
+ * With address and password. `mfa_required`: ask for the code and call
471
+ * `signIn.mfa`. `method: 'email'` says the code was just mailed to the
472
+ * account's address (it has no factor of its own and the workspace, or
473
+ * the sign-in's risk, asked a second step): say so, and offer
474
+ * `mfaSendEmail` for another.
475
+ */
434
476
  email(form: {
435
477
  email: string;
436
478
  password: string;
437
479
  captchaToken?: string;
438
480
  }): Promise<AuthResult<'signed_in', {
439
481
  session: PublicSession;
440
- }> | AuthResult<'mfa_required'>>;
441
- /** The second step: the code of the authenticator app, or a recovery code. */
482
+ }> | AuthResult<'mfa_required', {
483
+ method?: 'email';
484
+ }>>;
485
+ /** The second step: the code of the authenticator app, the phone, the email, or a recovery code. */
442
486
  mfa(form: {
443
487
  code: string;
444
488
  }): Promise<AuthResult<'signed_in', {
445
489
  session: PublicSession;
446
490
  }>>;
447
- /** 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. */
491
+ /**
492
+ * While the second step is asked for: whether the account has an
493
+ * authenticator app, the phone (masked) a code can be sent to, phones
494
+ * that approve sign-ins, and the address (masked) a code went to when
495
+ * the step is by email.
496
+ */
448
497
  mfaMethods(): Promise<AuthResult<'ok', {
449
498
  totp: boolean;
450
499
  phone: {
@@ -454,6 +503,13 @@ interface AuthClient {
454
503
  push: {
455
504
  devices: number;
456
505
  } | null;
506
+ email: {
507
+ to: string;
508
+ } | null;
509
+ }>>;
510
+ /** Mails the sign-in's code again, when its second step is by email; `mfa` takes it. A few per sign-in. */
511
+ mfaSendEmail(): Promise<AuthResult<'sent', {
512
+ sentTo: string;
457
513
  }>>;
458
514
  /**
459
515
  * Sends a push to the account's phones (the application's app, with
@@ -597,12 +653,17 @@ interface AuthClient {
597
653
  }): string;
598
654
  };
599
655
  signUp: {
600
- /** `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in. */
656
+ /**
657
+ * `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in.
658
+ * `acceptLegal` and `consents` answer what `methods().legal` asks; a sign-up that leaves them out is refused.
659
+ */
601
660
  email(form: {
602
661
  email: string;
603
662
  password: string;
604
663
  name?: string;
605
664
  organization?: string;
665
+ acceptLegal?: boolean;
666
+ consents?: Record<string, boolean>;
606
667
  captchaToken?: string;
607
668
  }): Promise<AuthResult<'signed_in', {
608
669
  session: PublicSession;
@@ -655,4 +716,4 @@ interface AuthClientOptions {
655
716
  }
656
717
  declare function createAuthClient(options?: AuthClientOptions): AuthClient;
657
718
 
658
- 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 };
719
+ 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 PendingLegal, type SSOConnection, type SecondStep, type SessionState, type SessionStore, type SessionStoreOptions, canAutofillPasskeys, canUsePasskeys, createAuthClient, createSessionStore };
package/dist/client.d.ts CHANGED
@@ -110,6 +110,30 @@ interface AuthMethods {
110
110
  * found by their work address (`signIn.ssoDiscover`, `signIn.sso`).
111
111
  */
112
112
  sso: boolean;
113
+ /**
114
+ * Set when the workspace asks something of a sign-up: the legal documents
115
+ * to accept (the terms, the privacy policy: show the links and a box, send
116
+ * `acceptLegal: true`) and the consents to ask (one box each, sent as
117
+ * `consents`; a required one must be ticked). The ready-made form shows them.
118
+ */
119
+ legal?: {
120
+ documents: {
121
+ kind: string;
122
+ version: string;
123
+ url: string;
124
+ }[];
125
+ consentPurposes: {
126
+ key: string;
127
+ label: string;
128
+ required: boolean;
129
+ }[];
130
+ };
131
+ }
132
+ /** A legal document the person owes: not yet accepted in its current version. */
133
+ interface PendingLegal {
134
+ kind: string;
135
+ version: string;
136
+ url: string;
113
137
  }
114
138
  /** A company's sign-in (an SSO connection of the workspace). */
115
139
  interface SSOConnection {
@@ -290,6 +314,18 @@ interface AccountClient {
290
314
  }): Promise<AuthResult<'changed', {
291
315
  signedIn: boolean;
292
316
  }>>;
317
+ /**
318
+ * The legal documents the person has not accepted in their current version
319
+ * (a new version of the terms, say): show them and call `acceptLegal`.
320
+ * Nothing stops the person meanwhile; the application decides what waits.
321
+ */
322
+ legal(): Promise<AuthResult<'ok', {
323
+ pending: PendingLegal[];
324
+ }>>;
325
+ /** Records the person's acceptance of the documents in force (the kinds named, or every one). */
326
+ acceptLegal(form?: {
327
+ kinds?: string[];
328
+ }): Promise<AuthResult<'accepted'>>;
293
329
  mfa: {
294
330
  /** Starts turning the second step on: show `secret` (or `otpauthUri` as a QR code) to add to an authenticator app, then call `verify`. */
295
331
  setup(form: {
@@ -430,21 +466,34 @@ interface AuthClient {
430
466
  }): Promise<AuthResult<'signed_in', {
431
467
  session: PublicSession;
432
468
  }>>;
433
- /** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
469
+ /**
470
+ * With address and password. `mfa_required`: ask for the code and call
471
+ * `signIn.mfa`. `method: 'email'` says the code was just mailed to the
472
+ * account's address (it has no factor of its own and the workspace, or
473
+ * the sign-in's risk, asked a second step): say so, and offer
474
+ * `mfaSendEmail` for another.
475
+ */
434
476
  email(form: {
435
477
  email: string;
436
478
  password: string;
437
479
  captchaToken?: string;
438
480
  }): Promise<AuthResult<'signed_in', {
439
481
  session: PublicSession;
440
- }> | AuthResult<'mfa_required'>>;
441
- /** The second step: the code of the authenticator app, or a recovery code. */
482
+ }> | AuthResult<'mfa_required', {
483
+ method?: 'email';
484
+ }>>;
485
+ /** The second step: the code of the authenticator app, the phone, the email, or a recovery code. */
442
486
  mfa(form: {
443
487
  code: string;
444
488
  }): Promise<AuthResult<'signed_in', {
445
489
  session: PublicSession;
446
490
  }>>;
447
- /** 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. */
491
+ /**
492
+ * While the second step is asked for: whether the account has an
493
+ * authenticator app, the phone (masked) a code can be sent to, phones
494
+ * that approve sign-ins, and the address (masked) a code went to when
495
+ * the step is by email.
496
+ */
448
497
  mfaMethods(): Promise<AuthResult<'ok', {
449
498
  totp: boolean;
450
499
  phone: {
@@ -454,6 +503,13 @@ interface AuthClient {
454
503
  push: {
455
504
  devices: number;
456
505
  } | null;
506
+ email: {
507
+ to: string;
508
+ } | null;
509
+ }>>;
510
+ /** Mails the sign-in's code again, when its second step is by email; `mfa` takes it. A few per sign-in. */
511
+ mfaSendEmail(): Promise<AuthResult<'sent', {
512
+ sentTo: string;
457
513
  }>>;
458
514
  /**
459
515
  * Sends a push to the account's phones (the application's app, with
@@ -597,12 +653,17 @@ interface AuthClient {
597
653
  }): string;
598
654
  };
599
655
  signUp: {
600
- /** `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in. */
656
+ /**
657
+ * `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in.
658
+ * `acceptLegal` and `consents` answer what `methods().legal` asks; a sign-up that leaves them out is refused.
659
+ */
601
660
  email(form: {
602
661
  email: string;
603
662
  password: string;
604
663
  name?: string;
605
664
  organization?: string;
665
+ acceptLegal?: boolean;
666
+ consents?: Record<string, boolean>;
606
667
  captchaToken?: string;
607
668
  }): Promise<AuthResult<'signed_in', {
608
669
  session: PublicSession;
@@ -655,4 +716,4 @@ interface AuthClientOptions {
655
716
  }
656
717
  declare function createAuthClient(options?: AuthClientOptions): AuthClient;
657
718
 
658
- 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 };
719
+ 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 PendingLegal, type SSOConnection, type SecondStep, type SessionState, type SessionStore, type SessionStoreOptions, canAutofillPasskeys, canUsePasskeys, createAuthClient, createSessionStore };
package/dist/client.js CHANGED
@@ -400,6 +400,7 @@ function createAuthClient(options = {}) {
400
400
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
401
401
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
402
402
  mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
403
+ mfaSendEmail: () => post("/sign-in/mfa/email", {}, null),
403
404
  mfaPush: () => post("/sign-in/mfa/push", {}, null),
404
405
  async mfaPushWait(o = {}) {
405
406
  const status = await new Promise((resolve) => {
@@ -518,7 +519,7 @@ function createAuthClient(options = {}) {
518
519
  signUp: {
519
520
  email: (f) => post(
520
521
  "/sign-up/email",
521
- { email: f.email, password: f.password, name: f.name, organization: f.organization },
522
+ { email: f.email, password: f.password, name: f.name, organization: f.organization, acceptLegal: f.acceptLegal, consents: f.consents },
522
523
  firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password), checkOrganization(f.organization)),
523
524
  f.captchaToken
524
525
  )
@@ -551,6 +552,12 @@ function createAuthClient(options = {}) {
551
552
  return body && typeof body.account === "object" ? body.account : null;
552
553
  },
553
554
  update: (f) => post("/me", { name: f.name }, checkName(f.name)),
555
+ async legal() {
556
+ const body = await read("/me/legal");
557
+ if (!body) return { ok: false, error: { code: "not_signed_in", message: "Nobody is signed in." } };
558
+ return { ok: true, status: "ok", pending: Array.isArray(body.pending) ? body.pending : [] };
559
+ },
560
+ acceptLegal: (f = {}) => post("/me/legal/accept", { kinds: f.kinds ?? [] }, null),
554
561
  changePassword: (f) => {
555
562
  const bad = checkNewPassword(f.newPassword);
556
563
  return post("/me/password", { password: f.password, newPassword: f.newPassword }, bad ? { ...bad, field: "newPassword" } : null);