@nxgt/janus 0.14.0 → 0.15.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 (48) hide show
  1. package/README.md +80 -14
  2. package/dist/auth/config/janus-config.d.ts +2 -0
  3. package/dist/auth/config/janus-config.d.ts.map +1 -1
  4. package/dist/auth/config/resolved-config.d.ts +1 -0
  5. package/dist/auth/config/resolved-config.d.ts.map +1 -1
  6. package/dist/auth/email-sign-in.d.ts +40 -0
  7. package/dist/auth/email-sign-in.d.ts.map +1 -0
  8. package/dist/auth/events.d.ts +3 -2
  9. package/dist/auth/events.d.ts.map +1 -1
  10. package/dist/auth/index.d.ts +1 -1
  11. package/dist/auth/index.d.ts.map +1 -1
  12. package/dist/auth/magic-link.d.ts +22 -0
  13. package/dist/auth/magic-link.d.ts.map +1 -0
  14. package/dist/auth/port/types/tokens.d.ts +6 -3
  15. package/dist/auth/port/types/tokens.d.ts.map +1 -1
  16. package/dist/auth/sign-in-code.d.ts +1 -3
  17. package/dist/auth/sign-in-code.d.ts.map +1 -1
  18. package/dist/auth/types/email-flows.d.ts +3 -3
  19. package/dist/auth/types/index.d.ts +1 -0
  20. package/dist/auth/types/index.d.ts.map +1 -1
  21. package/dist/auth/types/janus.d.ts +8 -1
  22. package/dist/auth/types/janus.d.ts.map +1 -1
  23. package/dist/auth/types/magic-link.d.ts +46 -0
  24. package/dist/auth/types/magic-link.d.ts.map +1 -0
  25. package/dist/auth/users/any-type-api.d.ts +2 -2
  26. package/dist/auth/users/any-type-api.d.ts.map +1 -1
  27. package/dist/auth/users/type-api.d.ts +2 -1
  28. package/dist/auth/users/type-api.d.ts.map +1 -1
  29. package/dist/conformance/cases/tokens/kinds.d.ts +4 -1
  30. package/dist/conformance/cases/tokens/kinds.d.ts.map +1 -1
  31. package/dist/conformance/index.js +23 -1
  32. package/dist/conformance/index.js.map +3 -3
  33. package/dist/index.js +71 -16
  34. package/dist/index.js.map +9 -7
  35. package/docs/README.md +2 -1
  36. package/docs/guide/adapters.md +11 -7
  37. package/docs/guide/email-flows.md +11 -7
  38. package/docs/guide/errors.md +2 -2
  39. package/docs/guide/events.md +2 -2
  40. package/docs/guide/magic-link.md +411 -0
  41. package/docs/guide/passwords.md +5 -4
  42. package/docs/guide/second-factor.md +2 -1
  43. package/docs/guide/sign-in-code.md +14 -6
  44. package/docs/guide/users.md +2 -1
  45. package/docs/guide/vocabulary.md +5 -4
  46. package/docs/roadmap.md +10 -5
  47. package/docs/troubleshooting.md +149 -8
  48. package/package.json +1 -1
package/README.md CHANGED
@@ -46,7 +46,7 @@ a published entry point is a promise.
46
46
  ## Three ways to use it
47
47
 
48
48
  Janus has two sides. **Identities** answers *who is this?* — users, their
49
- logins and passwords, codes sent by e-mail, a TOTP second factor, sessions, one-time tokens. **Permissions** answers *may
49
+ logins and passwords, codes and links sent by e-mail, a TOTP second factor, sessions, one-time tokens. **Permissions** answers *may
50
50
  they?* — a model, the tuples stored against it, and `can`. Each side is usable
51
51
  alone, and neither loads the other's code: a spec reads the import graph of
52
52
  each entry point and fails if one reaches into the other.
@@ -324,6 +324,8 @@ await auth.resetPassword.request(email); // … | null
324
324
  await auth.resetPassword.confirm(token, newPassword);
325
325
  await auth.signInCode.request(email); // { code, challenge, email, expiresAt, user } | null
326
326
  await auth.signInCode.confirm(challenge, code); // { status: 'signedIn', user, session, token }
327
+ await auth.magicLink.request(email); // { token, email, expiresAt, user } | null
328
+ await auth.magicLink.confirm(token); // { status: 'signedIn', user, session, token }
327
329
  await auth.stepUp.request(user); // { via: 'email', code, challenge, email, expiresAt, user }
328
330
  await auth.stepUp.confirm(request, challenge, code); // the request's session, authenticatedAt: now
329
331
 
@@ -366,8 +368,8 @@ else reaches the store and is asynchronous.
366
368
  compile error on `login`, and the message lists the fields you could have
367
369
  meant. It is normalised with `'lowercaseTrim'` unless you say otherwise.
368
370
  - **`email`** defaults to the field named `email`. A type without one has no
369
- `verifyEmail`, no `resetPassword` and no `signInCode` — they are absent from
370
- its type, not failing at run time. Changing the e-mail sets `emailVerified`
371
+ `verifyEmail`, no `resetPassword`, no `signInCode` and no `magicLink` — they
372
+ are absent from its type, not failing at run time. Changing the e-mail sets `emailVerified`
371
373
  back to `false`.
372
374
  - **Per type**: `create`, `find` (or `null`), `get` (or `NOT_FOUND`), `list`,
373
375
  `update(user, patch)` — merged over the stored fields, then validated whole —
@@ -502,7 +504,11 @@ await sessions.reauthenticateSession(session.id, new Date()); // { …, authenti
502
504
  ```
503
505
 
504
506
  A token of kind `stepUp` is that confirmation's challenge: kept apart from
505
- `signInCode`, so neither is ever redeemed as the other.
507
+ `signInCode`, so neither is ever redeemed as the other. A token of kind
508
+ `magicLink`, new in 0.15, is a sign-in link's, kept apart from `signInCode`
509
+ the same way: a sign-in code's challenge is held by whoever asked for it,
510
+ and must never sign anyone in as a link. A store that lists the kinds — a
511
+ `CHECK`, a validator's enum — adds `magicLink`.
506
512
 
507
513
  An adapter written against `@nxgt/janus` 0.3 does not compile against this
508
514
  port until it implements `countAttempt`, nor one written against 0.6 until it
@@ -634,6 +640,43 @@ A six-digit code sent to the user's e-mail signs them in, with no password.
634
640
  [The sign-in code guide](docs/guide/sign-in-code.md) has the request that
635
641
  tells nobody who exists, the challenge in a cookie, every error, and a test.
636
642
 
643
+ ### Sign-in links — `magicLink`
644
+
645
+ ```ts
646
+ const issued = await auth.magicLink.request(email); // null for nobody, or an inactive user
647
+ if (issued !== null) {
648
+ const link = `https://app.example/sign-in/link?token=${issued.token}`; // a page of yours
649
+ await sendMail(issued.email, `Sign in: ${link}`); // the token in the e-mail, and nowhere else
650
+ }
651
+ // answer the same page either way: nothing reaches the visitor, so there is nothing to forge
652
+
653
+ // the page's button POSTs the token back — never confirm on the link's GET
654
+ const signedIn = await auth.magicLink.confirm(token); // { status: 'signedIn', user, session, token }
655
+ ```
656
+
657
+ A link sent to the user's e-mail signs them in: a sign-in code with nothing
658
+ to type.
659
+
660
+ - **On every user type with an e-mail**, with a password or without one, as
661
+ `signInCode`. A type with no e-mail has no `magicLink` at all.
662
+ - **`request(email)` answers `null`** when nobody of this type holds that
663
+ e-mail, or the user is inactive — never say which. It answers a `token` of
664
+ 32 random bytes, base64url, for a link; only its hash is stored. One link
665
+ is live per user: a new `request` spends the ones before. A link and a
666
+ code are separate: asking for one leaves the other live.
667
+ - **`confirm(token)`** spends the token in one conditional write — of two
668
+ confirmations at once, one signs in — marks the e-mail verified and opens
669
+ the session. A link lives `'15m'` (`tokens.magicLink`); there are no
670
+ attempts, since there is nothing to guess. `TOKEN_STALE`, `USER_INACTIVE`
671
+ and an active second factor are handled as for a code.
672
+ - **Not ended by a password write, nor limited by the sign-in throttle**:
673
+ the password proves nothing a link does, and the throttle counts
674
+ passwords. Rate-limit `request` per address and per client.
675
+
676
+ [The sign-in link guide](docs/guide/magic-link.md) has the page that
677
+ confirms from a `POST` so mail scanners spend nothing, every error, routes
678
+ and a test.
679
+
637
680
  ### Step-up — `stepUp` and `assertFresh`
638
681
 
639
682
  ```ts
@@ -699,7 +742,7 @@ await auth.signUp({ email, password }); // the listener has the event before thi
699
742
  | `type` | Sent by |
700
743
  | --- | --- |
701
744
  | `user.created` | `create`, `signUp` |
702
- | `user.emailVerified` | `verifyEmail.confirm`; `resetPassword.confirm` and `signInCode.confirm`, whose link or code proves the e-mail too — never for an e-mail already verified |
745
+ | `user.emailVerified` | `verifyEmail.confirm`; `resetPassword.confirm`, `magicLink.confirm` and `signInCode.confirm`, whose link or code proves the e-mail too — never for an e-mail already verified |
703
746
  | `user.passwordReset` | `resetPassword.confirm` |
704
747
  | `user.passwordChanged` | `changePassword`, `setPassword` — never a reset, which is `user.passwordReset` alone |
705
748
  | `user.emailChanged` | `update`, when it changed the e-mail — carrying `formerEmail`, the address before (`null` for none) |
@@ -878,7 +921,7 @@ describeJanusStores({
878
921
  });
879
922
  ```
880
923
 
881
- There are 54 cases. They cover:
924
+ There are 55 cases. They cover:
882
925
  - round-trip, byte for byte — including every edge character the core lets
883
926
  through (control characters, U+FFFF, a surrogate pair);
884
927
  - uniqueness, as a constraint: of twenty concurrent inserts of one login,
@@ -891,8 +934,9 @@ There are 54 cases. They cover:
891
934
  and never brings back a revoked session, even one revoked at the same
892
935
  moment;
893
936
  - one-time tokens: a token of every kind the port names is stored, counted
894
- and spent — a `CHECK` or an enum that forgot `stepUp` fails here — and a
895
- step-up is never counted, spent nor answered as a sign-in code; of twenty
937
+ and spent — a `CHECK` or an enum that forgot `stepUp` or `magicLink` fails
938
+ here — and neither a step-up nor a sign-in link is ever counted, spent nor
939
+ answered as a sign-in code; of twenty
896
940
  concurrent redemptions, exactly one succeeds; of twenty concurrent
897
941
  `countAttempt` calls, each answers a distinct count, and none is counted
898
942
  once a racing redemption spent the token;
@@ -938,9 +982,9 @@ runner-less layer.
938
982
  ## Traps
939
983
 
940
984
  **Once `secondFactor` is configured, switch on `signIn`'s `status`** — and
941
- on `signInCode.confirm`'s. A user whose factor is active gets
985
+ on `signInCode.confirm`'s and `magicLink.confirm`'s. A user whose factor is active gets
942
986
  `{ status: 'secondFactor', challenge, expiresAt, userId }`, with no `token`
943
- and no `session`: an e-mailed code proves the e-mail, not the factor.
987
+ and no `session`: an e-mailed code or link proves the e-mail, not the factor.
944
988
  `userId` is for your logs and rate limits — answer the visitor the
945
989
  challenge alone.
946
990
  `if (result.status === 'secondFactor') …` before anything reads them.
@@ -973,6 +1017,27 @@ address**: at most one code is live per user — a new `request` spends the one
973
1017
  before — so without a limit anyone who knows an address can fill its inbox,
974
1018
  or cancel its owner's code before they type it.
975
1019
 
1020
+ **Confirm a sign-in link from a `POST`, never from its `GET`.** Mail
1021
+ scanners open every link in an e-mail before the user does: a route that
1022
+ calls `magicLink.confirm` on the link's `GET` spends it for the scanner, and
1023
+ the user's click answers `TOKEN_SPENT`. Link to a page that spends nothing,
1024
+ whose button posts the token — and echo into that page only a token of the
1025
+ token's shape. Refuse that `POST` from another site — check its `Origin`,
1026
+ or `Sec-Fetch-Site: same-origin` — or any page can sign a visitor into an
1027
+ account whose link it holds. Whoever opens the link signs in, on the device
1028
+ that opened it: where the sign-in must complete in the browser that asked,
1029
+ send a code.
1030
+
1031
+ **A link or a code proves an e-mail someone else may have registered.**
1032
+ `signUp` does not wait for the address to be proved, and `signIn` does not
1033
+ ask whether it was: whoever registered the address with a password of theirs
1034
+ keeps that password, and their session, after its owner signs in by link or
1035
+ code and the e-mail turns verified. Where a password signs in before the
1036
+ e-mail is verified, require `verifyEmail` before `signIn` — or, on the
1037
+ `user.emailVerified` those confirmations send, sign the user out everywhere
1038
+ — the listener runs before the new session opens — and have them set a
1039
+ password of their own.
1040
+
976
1041
  **Every `janus()` that signs users in needs the same `secondFactor`.** An
977
1042
  instance without keys never signs in a user whose factor is active: `signIn`
978
1043
  throws a `TypeError` rather than open a session on the password alone. Build
@@ -1065,7 +1130,7 @@ seconds rather than that the password is wrong. `CredentialRefusal` gained
1065
1130
  test that tries more than ten wrong passwords at one login over a
1066
1131
  `fixedClock` is throttled too: advance the clock past `retryAfter`, or wire
1067
1132
  `signIn: { throttle: false }`. **Somebody who knows a login can keep its
1068
- password sign-in shut**, ten tries a window; a sign-in code, when you wire them, still opens it.
1133
+ password sign-in shut**, ten tries a window; a sign-in code or link, when you wire them, still opens it — the throttle counts passwords, never those.
1069
1134
  On PostgreSQL, delete lapsed tokens on a schedule: every login tried adds a
1070
1135
  row per window. One password tried against
1071
1136
  many logins is not counted: rate-limit `signIn` per client address yourself
@@ -1151,7 +1216,7 @@ that sends one, since it is awaited: queue the event and return.
1151
1216
 
1152
1217
  ## Type safety, counted
1153
1218
 
1154
- **One hundred and thirty-seven plausible mistakes, one hundred and thirty-seven refused at compile time — and
1219
+ **One hundred and forty-one plausible mistakes, one hundred and forty-one refused at compile time — and
1155
1220
  two gaps, named.**
1156
1221
 
1157
1222
  The lists are typechecked and never run, with one `@ts-expect-error` per
@@ -1159,9 +1224,10 @@ mistake beside the shapes that must keep compiling. One is a single file:
1159
1224
  `test/types/refusals.ts` (fifteen, on the shared vocabulary). The other three
1160
1225
  are folders with one file per behaviour: `test/types/port/` (twenty-four, on
1161
1226
  the identity stores' port, from the point of view of the person implementing
1162
- it), `test/types/auth/` (fifty, on `janus()`, from the point of view of
1227
+ it), `test/types/auth/` (fifty-four, on `janus()`, from the point of view of
1163
1228
  the application — twelve of them on the second factor, three on sign-in codes,
1164
- five on user events, four on step-ups, six on the sign-in throttle) and `test/types/permissions/` (forty-eight, on the
1229
+ five on user events, four on step-ups, six on the sign-in throttle, four on
1230
+ sign-in links) and `test/types/permissions/` (forty-eight, on the
1165
1231
  permission model and the questions asked of it). The rule comes from
1166
1232
  `nxgt-data`, and so does the reason to distrust the claim without the files:
1167
1233
  when it was last measured on `@nxgt/mongo`, *seven of twelve plausible
@@ -48,6 +48,8 @@ interface SharedConfig {
48
48
  readonly resetPassword?: Duration;
49
49
  /** How long an e-mailed sign-in code waits. `'10m'` when absent. */
50
50
  readonly signInCode?: Duration;
51
+ /** How long an e-mailed sign-in link waits. `'15m'` when absent. */
52
+ readonly magicLink?: Duration;
51
53
  /** How long a step-up's challenge waits, e-mailed or not. `'10m'` when absent. */
52
54
  readonly stepUp?: Duration;
53
55
  };
@@ -1 +1 @@
1
- {"version":3,"file":"janus-config.d.ts","sourceRoot":"","sources":["../../../src/auth/config/janus-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,O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IAAI,EAAE,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC;IACtD,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,+DAA+D;AAC/D,MAAM,WAAW,gBAChB,SAAQ,YAAY,EACnB,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACvB;AAED,mEAAmE;AACnE,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACpD,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;KAAE,CAAC;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC;CAC/B;AAED,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,eAAe,CAAC"}
@@ -25,6 +25,7 @@ export interface ResolvedConfig {
25
25
  readonly verifyEmail: number;
26
26
  readonly resetPassword: number;
27
27
  readonly signInCode: number;
28
+ readonly magicLink: number;
28
29
  readonly stepUp: number;
29
30
  };
30
31
  /** `null` when `signIn.throttle` is `false`. */
@@ -1 +1 @@
1
- {"version":3,"file":"resolved-config.d.ts","sourceRoot":"","sources":["../../../src/auth/config/resolved-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,oFAAoF;AACpF,MAAM,WAAW,YA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,MAAM,CAAC;QAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,gDAAgD;IAChD,QAAQ,CAAC,cAAc,EAAE;QACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC1B,GAAG,IAAI,CAAC;IACT,QAAQ,CAAC,YAAY,EAAE;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;KAChC,GAAG,IAAI,CAAC;IACT,QAAQ,CAAC,MAAM,EAAE;QAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;QAC7C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;KACzB,CAAC;CACF"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * What the two sign-ins by e-mail share — a code typed back
3
+ * (`sign-in-code.ts`) and a link followed (`magic-link.ts`): who may be sent
4
+ * one, keeping only the last one live, and how a redeemed one ends — the
5
+ * e-mail proved, then the same session or second-factor challenge a
6
+ * password opens.
7
+ */
8
+ import type { ResolvedType } from './config';
9
+ import { type AnyUser, type Context } from './context';
10
+ import type { TokenKind, TokenRecord, UserRecord } from './port/types';
11
+ import type { SignInResult } from './types';
12
+ /** What a sign-in answers once the user proved who they are: `secondFactor.finish`. */
13
+ export type Finish = (record: UserRecord, where: string) => Promise<SignInResult<AnyUser>>;
14
+ /**
15
+ * The user of this type holding `email`, when they may be sent a sign-in:
16
+ * `null` for nobody, and for an inactive user — the same answer, so the
17
+ * caller cannot tell them apart either.
18
+ */
19
+ export declare function signInHolder(context: Context, type: ResolvedType, email: string): Promise<UserRecord | null>;
20
+ /**
21
+ * Spends every other unspent token of this kind the user holds, sparing the
22
+ * one just issued. Issued first, spent after, so requests that race leave
23
+ * at most one live — maybe none, and the visitor asks again — never one each.
24
+ */
25
+ export declare function keepOnlyLatest(context: Context, userId: string, kind: TokenKind, secret: string): Promise<void>;
26
+ /**
27
+ * Ends a sign-in by e-mail whose token is spent: refuses an e-mail changed
28
+ * since it was sent and an inactive user, proves the e-mail — it reached the
29
+ * inbox — and finishes as a password would.
30
+ *
31
+ * The proof is written under the version read, so an address changed since
32
+ * is not the one proved: a `VERSION_CONFLICT` then, with the token spent.
33
+ */
34
+ export declare function finishEmailSignIn(context: Context, type: ResolvedType, finish: Finish, signIn: {
35
+ readonly user: UserRecord;
36
+ readonly token: TokenRecord;
37
+ readonly where: string;
38
+ readonly noun: 'token' | 'code';
39
+ }): Promise<SignInResult<AnyUser>>;
40
+ //# sourceMappingURL=email-sign-in.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-sign-in.d.ts","sourceRoot":"","sources":["../../src/auth/email-sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EAGZ,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,uFAAuF;AACvF,MAAM,MAAM,MAAM,GAAG,CACpB,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,KACT,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AAEpC;;;;GAIG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAG5B;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CACnC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE;IACP,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;CAChC,GACC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAqBhC"}
@@ -5,8 +5,9 @@ import type { Context } from './context';
5
5
  *
6
6
  * - `user.created` — by `create` or `signUp`;
7
7
  * - `user.emailVerified` — by `verifyEmail.confirm`, or by the link of
8
- * `resetPassword.confirm` or the code of `signInCode.confirm`, which prove
9
- * the e-mail too; never for an e-mail already verified;
8
+ * `resetPassword.confirm` or `magicLink.confirm`, or the code of
9
+ * `signInCode.confirm`, which prove the e-mail too; never for an e-mail
10
+ * already verified;
10
11
  * - `user.passwordReset` — by `resetPassword.confirm`;
11
12
  * - `user.passwordChanged` — by `changePassword` and `setPassword`; never by a
12
13
  * reset, which is `user.passwordReset` alone;
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/auth/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAChD,UAAU,EAAE,IAAI,EAChB,MAAM,GAAE,WAAgB,GACtB,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -8,5 +8,5 @@ export type { JanusStores, Json, JsonObject, PasswordRecord, SecondFactorRecord,
8
8
  export type { SealingKey } from './sealing';
9
9
  export { assertFresh } from './sessions/fresh';
10
10
  export type { StandardSchemaV1 } from './standard-schema';
11
- export type { Authenticated, Checked, EmailOf, HeaderRecord, IssuedCode, IssuedToken, Janus, LoginOf, PasswordApi, RecoveredSignIn, RecoveryCodesIssued, RequestLike, RequiredStringKeys, ResetPasswordApi, SecondFactorApi, SecondFactorEnrolment, SecondFactorRequired, Session, SharedApi, SignedIn, SignInCodeApi, SignInResult, StepUpApi, StepUpByApp, StepUpByEmail, TypeApi, TypesOf, User, UserBase, UserOf, UserRef, UserTypeApi, VerifyEmailApi, WriteOptions, } from './types';
11
+ export type { Authenticated, Checked, EmailOf, HeaderRecord, IssuedCode, IssuedToken, Janus, LoginOf, MagicLinkApi, PasswordApi, RecoveredSignIn, RecoveryCodesIssued, RequestLike, RequiredStringKeys, ResetPasswordApi, SecondFactorApi, SecondFactorEnrolment, SecondFactorRequired, Session, SharedApi, SignedIn, SignInCodeApi, SignInResult, StepUpApi, StepUpByApp, StepUpByEmail, TypeApi, TypesOf, User, UserBase, UserOf, UserRef, UserTypeApi, VerifyEmailApi, WriteOptions, } from './types';
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,UAAU,CAAC;AAClB,YAAY,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EACX,WAAW,EACX,IAAI,EACJ,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,UAAU,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EACX,aAAa,EACb,OAAO,EACP,OAAO,EACP,YAAY,EACZ,UAAU,EACV,WAAW,EACX,KAAK,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,SAAS,EACT,WAAW,EACX,aAAa,EACb,OAAO,EACP,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,cAAc,EACd,YAAY,GACZ,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ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ACd,YAAY,GACZ,MAAM,SAAS,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { At } from './at';
2
+ import type { ResolvedType } from './config';
3
+ import { type AnyUser, type Context } from './context';
4
+ import { type Finish } from './email-sign-in';
5
+ import type { MagicLinkApi, SignInResult } from './types';
6
+ /**
7
+ * Signing in with a link sent to the user's e-mail: no password, and the
8
+ * link proves the address — a sign-in code with nothing to type.
9
+ *
10
+ * The token is 32 random bytes, so there is nothing to guess and no attempt
11
+ * to count: redeeming it is one conditional write, and of two redemptions
12
+ * at once exactly one signs in. **At most one link is live per user**, as
13
+ * for a sign-in code: `request` spends every other once it issued its own.
14
+ * A token of its own kind, `magicLink`, so a sign-in code's challenge — which
15
+ * the visitor holds — is never a link, nor a link a challenge.
16
+ *
17
+ * Whoever opens the link signs in, in the browser that opened it: the
18
+ * application confirms it from a `POST`, never from the `GET` of the link,
19
+ * which a mail scanner follows too.
20
+ */
21
+ export declare function magicLinkFlows(context: Context, type: ResolvedType, at: At, finish: Finish): MagicLinkApi<AnyUser, SignInResult<AnyUser>>['magicLink'];
22
+ //# sourceMappingURL=magic-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"magic-link.d.ts","sourceRoot":"","sources":["../../src/auth/magic-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,WAAW,CAAC;AAE/D,OAAO,EACN,KAAK,MAAM,EAIX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAe,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC7B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,EAAE,EACN,MAAM,EAAE,MAAM,GACZ,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAgB3D"}
@@ -16,12 +16,15 @@ import type { Id } from '../../../ids/id';
16
16
  * attempts at `regenerateRecoveryCodes`, a token of this kind whose secret
17
17
  * nobody is given, never redeemed, only counted.
18
18
  * - `signInCode`: a code sent by e-mail to sign in without a password.
19
+ * - `magicLink`: a link sent by e-mail to sign in without a password. A kind
20
+ * of its own, so a sign-in code's challenge — which the visitor holds —
21
+ * never signs anyone in as a link, nor a link's token as a challenge.
19
22
  * - `stepUp`: a signed-in user's confirmation of a sensitive action — a code
20
23
  * sent by e-mail, or, with an active second factor, a code from their app.
21
24
  * A kind of its own, so a sign-in code never confirms an action nor an
22
25
  * action's code signs anyone in.
23
26
  */
24
- export type TokenKind = 'verifyEmail' | 'resetPassword' | 'secondFactor' | 'signInCode' | 'stepUp';
27
+ export type TokenKind = 'verifyEmail' | 'resetPassword' | 'secondFactor' | 'signInCode' | 'magicLink' | 'stepUp';
25
28
  /** A one-time token, as a store holds it: its hash, never its secret. */
26
29
  export interface TokenRecord {
27
30
  /** `sha256` of the token's secret, hex. Unique across the store. */
@@ -104,8 +107,8 @@ export interface TokenStore {
104
107
  * Spends every **unspent** token of one user and one `kind` at `at` —
105
108
  * but the one whose hash is `except`, when given — and answers how many
106
109
  * it spent. What issuing a sign-in code calls, sparing the code it just
107
- * issued, so only the last code sent works — and so for a reset link and
108
- * a step-up; and what writing a password calls, so no reset link and no
110
+ * issued, so only the last code sent works — and so for a sign-in link,
111
+ * a reset link and a step-up; and what writing a password calls, so no reset link and no
109
112
  * second-factor challenge opened with the old one survives.
110
113
  *
111
114
  * - A spent token keeps its `spentAt`: it never changes once set.
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../../src/auth/port/types/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,EAAE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AO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAE/B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAE9E;;;;;;;;;;;;;;;;;OAiBG;IACH,eAAe,CACd,MAAM,EAAE,EAAE,EACV,IAAI,EAAE,SAAS,EACf,EAAE,EAAE,IAAI,EACR,MAAM,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C"}
@@ -1,7 +1,7 @@
1
1
  import type { At } from './at';
2
2
  import type { ResolvedType } from './config';
3
3
  import { type AnyUser, type Context } from './context';
4
- import type { UserRecord } from './port/types';
4
+ import { type Finish } from './email-sign-in';
5
5
  import type { SignInCodeApi, SignInResult } from './types';
6
6
  /**
7
7
  * Signing in with a code sent to the user's e-mail: no password, and the
@@ -18,6 +18,4 @@ import type { SignInCodeApi, SignInResult } from './types';
18
18
  * tokens alone do not reveal it.
19
19
  */
20
20
  export declare function signInCodeFlows(context: Context, type: ResolvedType, at: At, finish: Finish): SignInCodeApi<AnyUser, SignInResult<AnyUser>>['signInCode'];
21
- type Finish = (record: UserRecord, where: string) => Promise<SignInResult<AnyUser>>;
22
- export {};
23
21
  //# sourceMappingURL=sign-in-code.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign-in-code.d.ts","sourceRoot":"","sources":["../../src/auth/sign-in-code.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EAKZ,MAAM,WAAW,CAAC;AAanB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAc,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,EAAE,EACN,MAAM,EAAE,MAAM,GACZ,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAU7D;AAED,KAAK,MAAM,GAAG,CACb,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,KACT,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"sign-in-code.d.ts","sourceRoot":"","sources":["../../src/auth/sign-in-code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,OAAO,EAAsB,MAAM,WAAW,CAAC;AAC3E,OAAO,EACN,KAAK,MAAM,EAIX,MAAM,iBAAiB,CAAC;AAWzB,OAAO,KAAK,EAAc,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,EAAE,EACN,MAAM,EAAE,MAAM,GACZ,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAU7D"}
@@ -44,9 +44,9 @@ export interface SignInCodeApi<U, Answer = SignedIn<U>> {
44
44
  * time — send the e-mail off the request's path.
45
45
  *
46
46
  * **Rate-limit it, per e-mail and per client.** Every call issues a new
47
- * challenge with five attempts of its own, and the earlier ones stay
48
- * valid until they lapse: the five attempts bound one challenge, not
49
- * one account.
47
+ * challenge with five attempts of its own, and spends the earlier ones:
48
+ * only the last code sent works, and a new `request` is five guesses
49
+ * more — the five attempts bound one challenge, not one account.
50
50
  */
51
51
  request(email: string): Promise<IssuedCode<U> | null>;
52
52
  /**
@@ -11,6 +11,7 @@ export type { Checked } from './checks';
11
11
  export type { IssuedCode, IssuedToken, ResetPasswordApi, SignInCodeApi, VerifyEmailApi, } from './email-flows';
12
12
  export type { EmailOf, LoginOf, RequiredStringKeys, TypesOf, UserOf, } from './inference';
13
13
  export type { Janus, SharedApi, TypeApi } from './janus';
14
+ export type { MagicLinkApi } from './magic-link';
14
15
  export type { PasswordApi } from './password';
15
16
  export type { RecoveredSignIn, RecoveryCodesIssued, SecondFactorApi, SecondFactorEnrolment, } from './second-factor';
16
17
  export type { Authenticated, HeaderRecord, RequestLike, Session, } from './session';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EACX,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,cAAc,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EACX,OAAO,EACP,OAAO,EACP,kBAAkB,EAClB,OAAO,EACP,MAAM,GACN,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EACX,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,qBAAqB,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,OAAO,GACP,MAAM,WAAW,CAAC;AACnB,YAAY,EACX,oBAAoB,EACpB,QAAQ,EACR,YAAY,GACZ,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACvE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EACX,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,cAAc,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EACX,OAAO,EACP,OAAO,EACP,kBAAkB,EAClB,OAAO,EACP,MAAM,GACN,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EACX,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,qBAAqB,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACX,OAAO,GACP,MAAM,WAAW,CAAC;AACnB,YAAY,EACX,oBAAoB,EACpB,QAAQ,EACR,YAAY,GACZ,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACvE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
@@ -7,6 +7,7 @@
7
7
  import type { JanusConfig, MultiTypeConfig, SingleTypeConfig } from '../config';
8
8
  import type { ResetPasswordApi, SignInCodeApi, VerifyEmailApi } from './email-flows';
9
9
  import type { EmailOf, FieldsInput, LoginOf, SingleAsType, UserOf, UserOfType } from './inference';
10
+ import type { MagicLinkApi } from './magic-link';
10
11
  import type { PasswordApi } from './password';
11
12
  import type { SecondFactorApi } from './second-factor';
12
13
  import type { Authenticated, RequestLike, Session } from './session';
@@ -14,11 +15,17 @@ import type { SignedIn, SignInResult } from './sign-in';
14
15
  import type { StepUpApi, StepUpByApp, StepUpByEmail } from './step-up';
15
16
  import type { UserRef } from './user';
16
17
  import type { UserTypeApi } from './user-type';
18
+ /**
19
+ * What a sign-in by e-mail — a code or a link — answers: a session, or a
20
+ * challenge when the type has a password in an instance given a
21
+ * `secondFactor`, since the e-mail proves the address and not the factor.
22
+ */
23
+ type EmailSignInAnswer<Name extends string, Def, TwoFactor extends boolean> = TwoFactor extends true ? [LoginOf<Def>] extends [never] ? SignedIn<UserOfType<Name, Def>> : SignInResult<UserOfType<Name, Def>> : SignedIn<UserOfType<Name, Def>>;
17
24
  /**
18
25
  * The whole surface of one user type, with only the flows its configuration
19
26
  * allows. `TwoFactor` is whether `janus()` was given a `secondFactor`.
20
27
  */
21
- export type TypeApi<Name extends string, Def, TwoFactor extends boolean = false> = UserTypeApi<UserOfType<Name, Def>, FieldsInput<Def>> & ([LoginOf<Def>] extends [never] ? unknown : TwoFactor extends true ? PasswordApi<UserOfType<Name, Def>, FieldsInput<Def>, LoginOf<Def>, SignInResult<UserOfType<Name, Def>>> & SecondFactorApi<UserOfType<Name, Def>> : PasswordApi<UserOfType<Name, Def>, FieldsInput<Def>, LoginOf<Def>>) & ([EmailOf<Def>] extends [never] ? unknown : VerifyEmailApi<UserOfType<Name, Def>> & SignInCodeApi<UserOfType<Name, Def>, TwoFactor extends true ? [LoginOf<Def>] extends [never] ? SignedIn<UserOfType<Name, Def>> : SignInResult<UserOfType<Name, Def>> : SignedIn<UserOfType<Name, Def>>> & StepUpApi<UserOfType<Name, Def>, TwoFactor extends true ? [LoginOf<Def>] extends [never] ? StepUpByEmail<UserOfType<Name, Def>> : StepUpByEmail<UserOfType<Name, Def>> | StepUpByApp<UserOfType<Name, Def>> : StepUpByEmail<UserOfType<Name, Def>>>) & ([LoginOf<Def>] extends [never] ? unknown : [EmailOf<Def>] extends [never] ? unknown : ResetPasswordApi<UserOfType<Name, Def>>);
28
+ export type TypeApi<Name extends string, Def, TwoFactor extends boolean = false> = UserTypeApi<UserOfType<Name, Def>, FieldsInput<Def>> & ([LoginOf<Def>] extends [never] ? unknown : TwoFactor extends true ? PasswordApi<UserOfType<Name, Def>, FieldsInput<Def>, LoginOf<Def>, SignInResult<UserOfType<Name, Def>>> & SecondFactorApi<UserOfType<Name, Def>> : PasswordApi<UserOfType<Name, Def>, FieldsInput<Def>, LoginOf<Def>>) & ([EmailOf<Def>] extends [never] ? unknown : VerifyEmailApi<UserOfType<Name, Def>> & SignInCodeApi<UserOfType<Name, Def>, EmailSignInAnswer<Name, Def, TwoFactor>> & MagicLinkApi<UserOfType<Name, Def>, EmailSignInAnswer<Name, Def, TwoFactor>> & StepUpApi<UserOfType<Name, Def>, TwoFactor extends true ? [LoginOf<Def>] extends [never] ? StepUpByEmail<UserOfType<Name, Def>> : StepUpByEmail<UserOfType<Name, Def>> | StepUpByApp<UserOfType<Name, Def>> : StepUpByEmail<UserOfType<Name, Def>>>) & ([LoginOf<Def>] extends [never] ? unknown : [EmailOf<Def>] extends [never] ? unknown : ResetPasswordApi<UserOfType<Name, Def>>);
22
29
  /** What every configuration answers, whatever its user types. */
23
30
  export interface SharedApi<U extends {
24
31
  readonly type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"janus.d.ts","sourceRoot":"","sources":["../../../src/auth/types/janus.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,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C,MAAM,CAAC,CAAC,CAAC,CAAC,GAC9D,CAAC,CAAC,SAAS,eAAe,GACvB;IACA,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,OAAO,CACjD,CAAC,EACD,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACb,WAAW,CAAC,CAAC,CAAC,CACd;CACD,GACA,CAAC,SAAS,gBAAgB,GACzB,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GAChD,KAAK,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * What a user type with an e-mail answers besides: signing in with a link
3
+ * sent to it.
4
+ *
5
+ * Part of what `janus()` hands back; `./index` gathers it.
6
+ */
7
+ import type { IssuedToken } from './email-flows';
8
+ import type { SignedIn } from './sign-in';
9
+ /**
10
+ * Signing in with a link sent to the user's e-mail, no password needed —
11
+ * a sign-in code with nothing to type.
12
+ *
13
+ * `Answer` is `SignInResult` when the type may have a second factor: the
14
+ * link proves the e-mail, and an active factor is still asked for.
15
+ */
16
+ export interface MagicLinkApi<U, Answer = SignedIn<U>> {
17
+ readonly magicLink: {
18
+ /**
19
+ * Issues a link's token for the user of this type holding this e-mail,
20
+ * or answers `null` when there is none, or they are inactive. **Never
21
+ * tell the visitor which**: answer the same page either way, and in the
22
+ * same time — send the e-mail off the request's path.
23
+ *
24
+ * Put `token` in a link to a page of yours, and **only in the e-mail**.
25
+ * The user's earlier links are spent: only the last one sent works.
26
+ * **Rate-limit it, per e-mail and per client**: every call sends an
27
+ * e-mail.
28
+ */
29
+ request(email: string): Promise<(IssuedToken & {
30
+ readonly user: U;
31
+ }) | null>;
32
+ /**
33
+ * Spends the link's token, marks the e-mail verified — the link reached
34
+ * the inbox — and signs the user in.
35
+ *
36
+ * **Call it from a `POST`**, never from the `GET` of the link: a mail
37
+ * scanner that opens the link would spend it. An unknown, spent or
38
+ * lapsed token is `TOKEN_UNKNOWN`, `TOKEN_SPENT` or `TOKEN_EXPIRED`; an
39
+ * e-mail the user changed since is `TOKEN_STALE`; an inactive user is
40
+ * `USER_INACTIVE`. The first call spends the token, whether it signs
41
+ * in or is refused.
42
+ */
43
+ confirm(token: string): Promise<Answer>;
44
+ };
45
+ }
46
+ //# sourceMappingURL=magic-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"magic-link.d.ts","sourceRoot":"","sources":["../../../src/auth/types/magic-link.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,SAAS,EAAE;QACnB;;;;;;;;;;WAUG;QACH,OAAO,CACN,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,WAAW,GAAG;YAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;SAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACxD;;;;;;;;;;WAUG;QACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;KACxC,CAAC;CACF"}
@@ -1,6 +1,6 @@
1
1
  import type { AnyUser } from '../context';
2
- import type { PasswordApi, ResetPasswordApi, SecondFactorApi, SignInCodeApi, SignInResult, StepUpApi, StepUpByApp, StepUpByEmail, UserTypeApi, VerifyEmailApi } from '../types';
2
+ import type { MagicLinkApi, PasswordApi, ResetPasswordApi, SecondFactorApi, SignInCodeApi, SignInResult, StepUpApi, StepUpByApp, StepUpByEmail, UserTypeApi, VerifyEmailApi } from '../types';
3
3
  import type { Input } from './flow-types';
4
4
  /** Everything one user type answers. Which flows it has is decided by its types; all are built. */
5
- export type AnyTypeApi = UserTypeApi<AnyUser, Input> & PasswordApi<AnyUser, Input, string, SignInResult<AnyUser>> & SecondFactorApi<AnyUser> & SignInCodeApi<AnyUser, SignInResult<AnyUser>> & StepUpApi<AnyUser, StepUpByEmail<AnyUser> | StepUpByApp<AnyUser>> & VerifyEmailApi<AnyUser> & ResetPasswordApi<AnyUser>;
5
+ export type AnyTypeApi = UserTypeApi<AnyUser, Input> & PasswordApi<AnyUser, Input, string, SignInResult<AnyUser>> & SecondFactorApi<AnyUser> & SignInCodeApi<AnyUser, SignInResult<AnyUser>> & MagicLinkApi<AnyUser, SignInResult<AnyUser>> & StepUpApi<AnyUser, StepUpByEmail<AnyUser> | StepUpByApp<AnyUser>> & VerifyEmailApi<AnyUser> & ResetPasswordApi<AnyUser>;
6
6
  //# sourceMappingURL=any-type-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"any-type-api.d.ts","sourceRoot":"","sources":["../../../src/auth/users/any-type-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EACX,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,SAAS,EACT,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,mGAAmG;AACnG,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,GACnD,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,GAC1D,eAAe,CAAC,OAAO,CAAC,GACxB,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,GAC7C,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GACjE,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"any-type-api.d.ts","sourceRoot":"","sources":["../../../src/auth/users/any-type-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,SAAS,EACT,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,mGAAmG;AACnG,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,GACnD,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,GAC1D,eAAe,CAAC,OAAO,CAAC,GACxB,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,GAC7C,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,GAC5C,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GACjE,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,OAAO,CAAC,CAAC"}
@@ -3,7 +3,8 @@ import type { Context } from '../context';
3
3
  import type { AnyTypeApi } from './any-type-api';
4
4
  /**
5
5
  * Everything one user type answers, gathered from its flows: its records,
6
- * its password, its second factor, its sign-in code, its step-up and its e-mails.
6
+ * its password, its second factor, its sign-in code and link, its step-up
7
+ * and its e-mails.
7
8
  */
8
9
  export declare function typeApi(context: Context, type: ResolvedType): AnyTypeApi;
9
10
  //# sourceMappingURL=type-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-api.d.ts","sourceRoot":"","sources":["../../../src/auth/users/type-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,CAgBxE"}
1
+ {"version":3,"file":"type-api.d.ts","sourceRoot":"","sources":["../../../src/auth/users/type-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAM1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,CAiBxE"}
@@ -1,4 +1,7 @@
1
1
  import type { ConformanceCase } from '../../types';
2
- /** Each kind stored and redeemed as itself, and the two codes kept apart. */
2
+ /**
3
+ * Each kind stored and redeemed as itself, a step-up kept apart from a
4
+ * sign-in code, and a sign-in link from both.
5
+ */
3
6
  export declare const tokenKindCases: readonly ConformanceCase[];
4
7
  //# sourceMappingURL=kinds.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../../../src/conformance/cases/tokens/kinds.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAkBnD,6EAA6E;AAC7E,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EA4DpD,CAAC"}
1
+ {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../../../src/conformance/cases/tokens/kinds.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmBnD;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EAkGpD,CAAC"}