@flipstream/sdk 0.15.0 → 0.16.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 (98) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/api/datasets.js +8 -8
  3. package/dist/api/datasets.js.map +1 -1
  4. package/dist/api/log.js +6 -10
  5. package/dist/api/log.js.map +1 -1
  6. package/dist/api/pathArgument.d.ts +7 -0
  7. package/dist/api/pathArgument.js +12 -0
  8. package/dist/api/pathArgument.js.map +1 -0
  9. package/dist/first-party/attempts.d.ts +1 -1
  10. package/dist/first-party/authProxyMark.d.ts +5 -2
  11. package/dist/first-party/authProxyMark.js +5 -2
  12. package/dist/first-party/authProxyMark.js.map +1 -1
  13. package/dist/first-party/calls/consent.d.ts +30 -18
  14. package/dist/first-party/calls/consent.js.map +1 -1
  15. package/dist/first-party/calls/device.d.ts +42 -20
  16. package/dist/first-party/calls/device.js.map +1 -1
  17. package/dist/first-party/calls/invitation.d.ts +99 -53
  18. package/dist/first-party/calls/invitation.js +23 -5
  19. package/dist/first-party/calls/invitation.js.map +1 -1
  20. package/dist/first-party/calls/logIn.d.ts +30 -10
  21. package/dist/first-party/calls/logIn.js.map +1 -1
  22. package/dist/first-party/calls/reset.d.ts +4 -1
  23. package/dist/first-party/calls/reset.js.map +1 -1
  24. package/dist/first-party/calls/signUp.d.ts +1 -1
  25. package/dist/first-party/calls/signUp.js +1 -1
  26. package/dist/first-party/calls/signUp.js.map +1 -1
  27. package/dist/first-party/calls/twoStepSetup.d.ts +28 -5
  28. package/dist/first-party/calls/twoStepSetup.js.map +1 -1
  29. package/dist/first-party/entry.d.ts +223 -199
  30. package/dist/first-party/entry.js +21 -19
  31. package/dist/first-party/entry.js.map +1 -1
  32. package/dist/first-party/hooks.d.ts +22 -7
  33. package/dist/first-party/hooks.js.map +1 -1
  34. package/dist/first-party/linkToken.d.ts +2 -3
  35. package/dist/first-party/linkToken.js +2 -3
  36. package/dist/first-party/linkToken.js.map +1 -1
  37. package/dist/first-party/links.d.ts +3 -3
  38. package/dist/first-party/links.js +4 -4
  39. package/dist/first-party/links.js.map +1 -1
  40. package/dist/first-party/proxy/app.d.ts +15 -8
  41. package/dist/first-party/proxy/app.js.map +1 -1
  42. package/dist/first-party/proxy/cases.d.ts +34 -17
  43. package/dist/first-party/proxy/cases.js +2 -3
  44. package/dist/first-party/proxy/cases.js.map +1 -1
  45. package/dist/first-party/proxy/decide.d.ts +6 -4
  46. package/dist/first-party/proxy/decide.js +2 -3
  47. package/dist/first-party/proxy/decide.js.map +1 -1
  48. package/dist/first-party/proxy/headers.d.ts +2 -3
  49. package/dist/first-party/proxy/headers.js.map +1 -1
  50. package/dist/first-party/proxy/pass-back.d.ts +14 -9
  51. package/dist/first-party/proxy/pass-back.js +2 -6
  52. package/dist/first-party/proxy/pass-back.js.map +1 -1
  53. package/dist/first-party/proxy/paths.d.ts +5 -7
  54. package/dist/first-party/proxy/paths.js +5 -7
  55. package/dist/first-party/proxy/paths.js.map +1 -1
  56. package/dist/first-party/proxy/stand-in.d.ts +2 -0
  57. package/dist/first-party/proxy/stand-in.js +28 -5
  58. package/dist/first-party/proxy/stand-in.js.map +1 -1
  59. package/dist/first-party/report.d.ts +20 -11
  60. package/dist/first-party/report.js.map +1 -1
  61. package/dist/first-party/result.d.ts +86 -18
  62. package/dist/first-party/result.js.map +1 -1
  63. package/dist/first-party/session/cell.d.ts +29 -5
  64. package/dist/first-party/session/cell.js +16 -2
  65. package/dist/first-party/session/cell.js.map +1 -1
  66. package/dist/first-party/session/closed.d.ts +6 -3
  67. package/dist/first-party/session/closed.js +6 -3
  68. package/dist/first-party/session/closed.js.map +1 -1
  69. package/dist/first-party/session/logout.d.ts +25 -5
  70. package/dist/first-party/session/logout.js +241 -43
  71. package/dist/first-party/session/logout.js.map +1 -1
  72. package/dist/first-party/session/owed.d.ts +85 -10
  73. package/dist/first-party/session/owed.js +111 -10
  74. package/dist/first-party/session/owed.js.map +1 -1
  75. package/dist/first-party/session/refresh.js +13 -6
  76. package/dist/first-party/session/refresh.js.map +1 -1
  77. package/dist/first-party/session/session.js +3 -6
  78. package/dist/first-party/session/session.js.map +1 -1
  79. package/dist/first-party/session/shared.js +49 -8
  80. package/dist/first-party/session/shared.js.map +1 -1
  81. package/dist/first-party/session/signIn.d.ts +10 -5
  82. package/dist/first-party/session/signIn.js +56 -10
  83. package/dist/first-party/session/signIn.js.map +1 -1
  84. package/dist/first-party/session/signInThrough.d.ts +2 -1
  85. package/dist/first-party/session/signInThrough.js +67 -18
  86. package/dist/first-party/session/signInThrough.js.map +1 -1
  87. package/dist/first-party/session/sync.js +39 -8
  88. package/dist/first-party/session/sync.js.map +1 -1
  89. package/dist/first-party/signInHooks.d.ts +43 -15
  90. package/dist/first-party/state.d.ts +20 -0
  91. package/dist/first-party/state.js +3 -0
  92. package/dist/first-party/state.js.map +1 -1
  93. package/dist/flipstream.d.ts +29 -10
  94. package/dist/flipstream.js +69 -20
  95. package/dist/flipstream.js.map +1 -1
  96. package/dist/version.gen.js +1 -1
  97. package/docs/first-party.md +52 -30
  98. package/package.json +1 -1
@@ -17,6 +17,10 @@ const cleaned = strip(location.href)
17
17
  if (cleaned !== null) history.replaceState(history.state, '', cleaned)
18
18
  ```
19
19
 
20
+ | Call | What it does |
21
+ | --- | --- |
22
+ | <a id="strip"></a>`strip(href)` | Takes a link's token out of an address and keeps it with the path, for `history.replaceState`. Returns the address without the token, or null when there was none. Every other parameter stays. |
23
+
20
24
  ```ts
21
25
  // main.ts, the app's entry module. A module's imports are all evaluated before its first
22
26
  // statement, so ./boot goes first: the token is gone before the SDK or anything else is evaluated.
@@ -48,33 +52,38 @@ document.querySelector('#sign-in')?.addEventListener('click', () => {
48
52
 
49
53
  | Call | What it does |
50
54
  | --- | --- |
51
- | `current()`, `subscribe(listener)` | The session's state (`restoring`, `signed_out`, `signed_in`, `unavailable`, `broken`, `unsupported`), the same object until it changes, for `useSyncExternalStore`. `restoring` ends within 60 s of `start()`, ordinarily 15. `unavailable` carries `retry_in_ms`. The session asks pulse-auth again by itself after that wait, and stays `unavailable` while it asks. `retry_in_ms` counts from when the state was published; the ask itself can take up to 15 s, and the tab stays `unavailable` until it answers. Its answer moves the tab on, or to `unavailable` again with the next wait. A tab shows `restoring` again only when the browser comes back online, which asks at once without waiting out `retry_in_ms`, or, when it is signed in, when another tab signed in and this one missed the message. The call that published finishes; a listener's throw goes to the page's `error` event through `reportError`, and on a host without one (a server render, Node) it is thrown again from a microtask, which Node raises as an uncaughtException, as its own `EventTarget` does. |
52
- | `flipstream` | The main SDK as the signed-in person. Read the getter for each piece of work, for example `await session.flipstream.me()`. |
53
- | `requestLink({ email, next }, { signal })` | Mails a login link. Empty text is `refused`, with nothing sent. `next` is a path or `null`; anything else, left out included, is a `TypeError`. |
54
- | `openedLink()` | On the landing: whether a link's token was there, and for whom (`ready`, `spent`, `other_browser`, `invalid`, `no_token`, `invitation`). |
55
- | `redeem(link, { signal })` | Signs in with the `ready` link `openedLink()` gave: `signed_in`, or a two-step code wanted. Call it only on a press, never as the page loads: a prerender, a speculative load or a restored tab runs the page's script without one, and the link works once. If redeem answers `superseded`, read `current()`. If the press was overtaken before the link was sent, pressing it again sends it, unless the sign-in that overtook it used this link: then `current()` is `signed_in` and the link reads `spent`. If it was sent and the sign-in was lost, every later press in this page keeps `superseded`. Ask for a new link. |
56
- | `requestLinkAgain(link, { signal })` | A new link for the same address and next page. |
57
- | `twoStepStatus({ signal })` | Reads whether two-step is enabled or required and how many backup codes remain. |
58
- | `startTwoStepSetup({ signal })` | Starts enrollment for the signed-in person on the Security page. Returns the manual-entry `secret` and the `otpauth_uri` for a QR code. |
59
- | `startSignInTwoStepSetup(setup, { signal })` | Starts enrollment for the `two_step_setup` returned by this session's `logIn` or `redeem`. Pass its frozen `setup` object unchanged. A copy or an object from another session rejects with a TypeError before sending. A sign-in ended by another tab gives `superseded`. An elapsed challenge gives `expired`. |
60
- | `confirmTwoStepSetup({ code }, { signal })` | On the signed-in security page, confirms setup with the first authenticator code and returns ten backup codes. |
61
- | `newBackupCodes({ code }, { signal })` | Replaces the old backup codes with ten new ones. Show the codes from this answer while the person can save them. |
62
- | `turnOffTwoStep({ code }, { signal })` | Turns off two-step for the signed-in person. A deployment that requires it answers `required`. |
63
- | `verifyTwoStep({ code }, { signal })` | The code, or a backup code, as typed. The state turns `signed_in` before this call answers, so a screen that leaves on `signed_in` takes this answer first: the backup codes exist nowhere else. Once the code is sent an abort is ignored. `not_sent`: the code was not sent, so press again. Before 0.15.0, this was `aborted`. When a sign-in or sign-out overtakes setup verification, `error.kind` is `superseded`. It also answers `superseded` if this tab cannot write its session state. Its `backup_codes` contains the ten issued codes only if the browser is signed out or the session can confirm the same user ID at delivery. Otherwise the field is `null`, including for a plain verify. |
64
- | `signOut()` | Signed out here and in every tab at once; `told` settles with what pulse-auth said. `superseded`: the record moved on since this sign-out: a sign-in, in any tab, or rarely a renewal by a tab that hadn't heard of it. That tab's cookie replaced the old one; it sent this logout first when it knew it was owed, and this call isn't told whether pulse-auth confirmed it. Nothing is pending for this sign-out; a sign-out made since is owed and sent on its own. Read `current()`. Another sign-out with no sign-in between (a second press, or one in another tab) is not `superseded`: this call is told what pulse-auth answered. A logout pulse-auth didn't confirm stays owed, and this tab stays signed out: it is retried, backing off, while the service is unreachable (no network, a 5xx, a 429); when it was refused (a 401 or 403) or answered outside the contract, it is kept, not retried on a timer: each tab that holds it sends it once, and a check of the shared state while that try is out sends nothing more; it is sent again at the next page load, the next sign-in, or a restore the tab runs: its own timed retry after `unavailable`, the browser coming back online while the tab is `unavailable`, or `start()`. It is still written down as owed once storage takes writes, so a reload owes it too. |
65
- | `requestSignUp({ email, first_name, last_name, organization, accepted: { terms_version, privacy_version } }, { signal })` | Asks pulse-admin to email a sign-up link that opens in this browser. Success acknowledges the request. It says nothing about mail delivery, whether the address already has an account or whether the person can sign in. Disable the submit button while the call is pending because each press starts another request. For `refused`, check the named form fields, including `accepted.terms_version` and `accepted.privacy_version`. A nonblank version with surrounding whitespace rejects with a `TypeError` naming the field. For `unsupported`, read `current()`: an unsupported state means a browser dependency is missing, any other state means storage refused this write. A timeout, connection or CORS failure, 429 or 5xx gives `unavailable`. An unexpected response gives `invalid` and is reported. An abort after sending gives `aborted`: the organization may exist and the link may have been mailed. The stored attempt lets that link work here. |
66
- | `requestPasswordReset({ email }, { signal })` | Asks for a reset link. Known and unknown addresses get the same answer. The email may still arrive after an abort. |
67
- | `openedReset()` | Reads the reset proof on the configured reset landing, including after close. |
68
- | `setPassword(proof, { password }, { signal })` | Sets the link owner's password and ends their sessions. Stops include `dead_link`, `password_too_short` and `inactive`. An abort after dispatch may leave the password set and the sessions ended. After `password_set` or `dead_link`, `openedReset()` reads `no_token`. After `unavailable`, the reset may have reached pulse-auth and a retry can answer `dead_link` even though the password was set. In that case, ask the person to try signing in with the new password before requesting a new link. Keep the form's submitted state while `setPassword` is pending. If the link's owner is signed in here and pulse-auth confirms revocation, `current()` already reads `signed_out` when this call settles. Another person signed in here stays signed in. An abort during that check or a wait of 15 seconds returns the known reset outcome while the check continues. |
69
- | `close()` | Ends this session object: its listeners, timers and channel. A request already sent settles with its real outcome (a sign-in already sent that then loses, to a sign-out in another tab or with an answer that can't be read, is still revoked with a `/logout`), but nothing new is sent: a call still waiting to send answers `unavailable`, and a sign-out whose first try hadn't gone out is told `unconfirmed`, its logout left pending. A logout storage refused to record is left for the next session in this page that looks, made before or after the close, which sends it before it restores. It is lost, and the person's own sign-in may restore, when it was never written down: the page closed while storage still refused; the shared record read signed out or was lost, and another tab that never heard of it restored the cookie first; or storage came back too shortly before to have taken it: a logout retried on the back-off is written at its next try, 30 seconds later at most, and one kept without a timer at the tab's next check of the shared state (another tab's write, the tab shown again or back online, a token asked for). A sign-out made after `close()` (a sign-in answered after it, or a `signOut()` racing it) reaches only this page, not the other tabs. If the stored record is lost while the cookie stays, the page can't tell whose cookie it is, and the logout still goes, even when someone signed in since. A session left open with a sign-out it couldn't write down gives way as the slot does: a sign-in or a sign-out another tab recorded after that sign-out speaks for the cookie, so the session drops its own sign-out. After a sign-in it sends no logout and restores that person; after a sign-out it sends that one's logout. The same holds when the shared record read signed out or was lost, and another tab that never heard of the sign-out restored the cookie first: that restore is recorded at a new generation, so the sign-out is lost and the person it signed out is restored, as with the slot. A restore against a record that still reads signed in keeps its generation, so the sign-out stands and its logout goes, unless the refresh answers another person. Then a new generation starts, and the sign-out is told `superseded`, with no logout sent: the browser's one cookie is that person's now, so no logout from it could reach the person signed out. The same new generation also ends a sign-in this browser refused to keep, whose revoke storage couldn't record: when a tab that never heard of it refreshes with that sign-in's cookie and gets another person, the revoke is lost and that sign-in's session lives on. This is a known limit, fixed by sdk#552. Every call after it throws or rejects with `SessionClosedError`, `subscribe` and `start` included, except the reads: `consentRequest()`, `current()`, `openedLink()`, `openedReset()`, `openedInvitation()` and the `flipstream` getter stay readable, and an unsubscribe handed out before stays safe to call. |
70
- | `consentRequest()` | Reads the current page address, including after close. A callback outside HTTP or HTTPS reads as `invalid`. For `asking`, show the client ID, callback host and requested scopes. To return here after sign-in, pass this page's path and query to `requestLink` as `next`. |
71
- | `approveConsent(request, { signal })`, `denyConsent(request, { signal })` | On a press, send the choice as the signed-in person. Pass the exact request this session showed. A copy or a request issued by another session rejects with a TypeError. On success, navigate to the checked `redirect_to`. With nobody signed in, `signed_out` sends nothing. A second press returns `answered` while the first is pending. Once it settles, try again if nothing was sent, or after a 429, which arrives as `unavailable`, or after `unknown_client`, `invalid_scope` or `invalid_target`. Approve renews once on `login_required`. If its retry never goes out or again gets `login_required`, the page can press again. `unknown_client` means the app or callback could not be identified. `invalid_scope` and `invalid_target` mean the app may not ask for that scope or resource. An answer outside the contract gives `invalid` and is reported. After the send, `aborted`, `signed_out` or `unavailable` may leave the request answered as the person who pressed. When the outcome is uncertain, another press returns `answered`. Reload or sign in again to make a fresh press. Approval may have issued a code and claimed a dynamically registered client for that person’s account. |
72
- | `logIn({ email, password }, { signal })` | Signs in with an address and the password as typed: `signed_in`, or a two-step code wanted (`two_step`, `two_step_setup`). Only on a press. Empty fields are `refused`, with nothing sent. `invalid_credentials` covers a wrong password, no such account and no password set: pulse-auth says one thing for all. `too_many_attempts` comes with no end time, because pulse-auth has none to give. `superseded`: a sign-in or sign-out, in any tab, came after the press; read `current()`. A refusal is never folded into it. `aborted`: the sign-in may still complete, and `current()` tells; a code asked for once every caller of that request has left is dropped, and the next press asks again. A `signal` that is not an AbortSignal is a TypeError, with nothing sent. |
73
- | `openedInvitation()` | On `invitationLanding`: whether the page was opened with an invitation's token (`ready`, `no_token`). Nothing sent, and readable after `close()`. It reads `no_token` once this page is done with the invitation: pulse-auth answered an accept with a 2xx, or the invitation was found dead. |
74
- | `previewInvitation(opened, { signal })` | What the `ready` invitation is for, straight from pulse-auth with no cookie: `personal` (it names its recipient, `email`) or `shared` (it names nobody), with `organization_name` (`''` when the deployment doesn't say), `app_name`, `roles`, `privacy_policy_url` (or `null`) and `continue` (`{ name, url, login_url }` of the app it goes on to, or `null`). The first preview marks the invitation as opened at pulse-auth. `dead_link`: unknown, revoked, expired or spent; pulse-auth says one thing for all. |
75
- | `acceptInvitation(invitation, entry, { signal })` | Makes the account and signs the person in, through the proxy, as `logIn` does. Pass the invitation `previewInvitation` returned, as it is (a copy is a `TypeError`), narrowed on its `kind`: a personal one takes `{ first_name, last_name, privacy_policy_accepted }` and an optional `password` (without one the account signs in by link only), a shared one also `email` and `password`. Empty names, and a shared accept's empty address or password, are `refused`; a privacy policy not accepted is `privacy_policy_required`; nothing is sent then. `signed_in` carries `continue_to`, a fresh one-time link into the invitation's app, or `null`: then, when the invitation has a `continue`, send the person to `continue.login_url`; without one, they are signed in here. A deployment that requires two-step answers `two_step` or `two_step_setup`, as `logIn` does, and `verifyTwoStep` then ends it the same way: to `continue.login_url` when there is a `continue`, otherwise signed in here. `changed`: the invitation was edited since the preview; preview it again. `dead_link`: unknown, revoked, expired or spent, or edited to another address since its link was sent: ask for it to be sent again. `password_too_short`, `account_exists` (log in first) and `superseded` (read `current()`) are as their names say. Once pulse-auth answers the accept with a 2xx (an accepted answer, or `superseded` or `invalid` after it), or `dead_link`, `openedInvitation()` reads `no_token`, also when the caller aborted after the send: this page is done with the invitation (spent, unless it allows more than one use). After `unavailable` the account may already exist and `openedInvitation()` stays `ready`. After `aborted` once the accept was sent, the request goes on: `openedInvitation()` reads `ready` while it is out, then `no_token` if pulse-auth answered a 2xx or `dead_link`, and `ready` otherwise. While it stays `ready` the account may already exist: a later `dead_link` then means "log in", with the password or by a login link. A second press with a different entry while one is out is its own attempt, not joined to the first, and can find the invitation used (sdk#549). With no privacy policy at the preview, pulse-auth's privacy refusal is `changed`: preview again. |
76
- | `lookUpDevice({ user_code }, { signal })` | Device sign-in: looks up the code a device shows, as typed, and answers the request to show the person: `user_code` as pulse-auth formats it, `client_id`, `client_name` (the name the client declares for itself: for a client registered by metadata document or dynamically, nobody has checked it, so show `client_id` beside it; `null` when pulse-auth can't resolve the client), `scopes` and `expires_at` (epoch ms). An open read straight to pulse-auth, with no cookie and no token: it changes nothing, so it may run on load, and works whoever is signed in, or nobody. `unknown_code`: unknown, expired or already used, which pulse-auth doesn't tell apart. `already_denied`: the request was denied before; only a look-up says so. An empty code is `refused`, with nothing sent. A request that is not an object, or a `signal` that is not an AbortSignal, is a TypeError, with nothing sent. |
77
- | `approveDevice(request, { signal })`, `denyDevice(request, { signal })` | Answers the request `lookUpDevice()` answered on this session, straight to pulse-auth as the signed-in person, only on a press: `approved` or `denied`. Any other object, a copy of it or one from another session included, is a TypeError, with nothing sent. Nobody signed in, or another person by the time it would be sent: `signed_out`, with nothing sent. `unknown_code`: the code is unknown, expired or already used (pulse-auth says the same for all three); a press on it would be sent again, but pulse-auth no longer holds it: ask the device for a new code. `answered`: a press from this page on this code (looked up again included) is still out, or may already have acted on it, for the person signed in now; nothing was sent. Once the first settles, a press is sent again if nothing was sent, or after a 429, which arrives as `unavailable`. After the send, `signed_out`, `aborted`, `invalid` or any other `unavailable` may leave the device answered as the person who pressed: another press answers `answered`, and a fresh look-up doesn't change that. Only signing in again lets a press be sent. An answer that isn't the decision pressed is `invalid` and reported. |
55
+ | <a id="createbrowsersession"></a>`createBrowserSession(options)` | The browser session for a page on the app's own origin. One session per page load: a second one in the same page gets no token. Every option is checked when the session is made, so a wrong one fails then, not on a person's first click. `app` is a name and a version, each 1 to 64 token characters, sent as Flipstream-Client. `invitationLanding` is the path pulse-auth builds invitation links on, `/invite`, and `resetLanding` is `/reset-password`; leave one out and no token is taken as that kind. Each `hosts` entry is https, or http on this machine, with no query, fragment or credentials. `onReport` defaults to `console.warn` and is never given a body, a token or a query. The session never hands the page a token. Keep that session outside React's render. `() => {}` silences `onReport`, and a handler that throws is caught. A report never carries a message's content, a bug's `cause` included. `answer.path` is the server's own path, never under `authPath`. `lock` and `storage` mean the call in hand ended `unavailable`. A `lock` report means the browser lock manager threw. `message`: another tab sent a token this version can't read, so it was ignored and this tab asked the server itself. `authPath` defaults to `/auth`, the path the app's server forwards to pulse-auth. `landing` is the path a mailed login link lands on. `hosts` includes the console, for hand-offs. `onReport` is what the operator should know: an answer outside the contract, a browser fault, or a bug. A `storage` report is a refused write of the shared record. A `threw` report is a bug, and `cause` is what was thrown. `answer`'s `status` is the answer's: 403 when the app's own proxy refused, and a redirect in a browser reads 0. |
56
+ | <a id="start"></a>`start()` | Restores the session from the refresh cookie, once, after subscribing. |
57
+
58
+ | Call | What it does |
59
+ | --- | --- |
60
+ | <a id="current-subscribe"></a>`current()`, `subscribe(listener)` | The session's state (`restoring`, `signed_out`, `signed_in`, `unavailable`, `broken`, `unsupported`), the same object until it changes, for `useSyncExternalStore`. `signed_in` carries `revision`, which rises by one when who is signed in, or what their token says, changes (every claim but `iat`, `nbf`, `exp`, `jti` and `sid`: the person, the organization, the roles, or a claim pulse-auth adds later); with each new generation, that is a new sign-in or a refresh that answers another person; and once when the tab stops being signed in (signed out, `broken`, or `restoring` after a sign-in it missed). A renewal that says the same leaves it. It counts within one tab, from 0 at each page load, so two tabs' revisions aren't comparable. `restoring` ends within 60 s of `start()`, ordinarily 15. `unavailable` carries `retry_in_ms`. `unavailable`: pulse-auth cannot be reached now. The session asks pulse-auth again by itself after that wait, and stays `unavailable` while it asks. `retry_in_ms` counts from when the state was published; the ask itself can take up to 15 s, and the tab stays `unavailable` until it answers. Its answer moves the tab on, or to `unavailable` again with the next wait. A tab shows `restoring` again only when the browser comes back online, which asks at once without waiting out `retry_in_ms`, or, when it is signed in, when another tab signed in and this one missed the message. The call that published finishes; a listener's throw goes to the page's `error` event through `reportError`, and on a host without one (a server render, Node) it is thrown again from a microtask, which Node raises as an uncaughtException, as its own `EventTarget` does. A try whose answer came for a state another tab moved is asked again, at most three more times. `current()` is frozen. `subscribe` returns the unsubscribe. Until the first answer, the refresh cookie decides. Without Web Locks or localStorage nobody can sign in. `broken`: pulse-auth answered outside its contract, or the app's own proxy refused, and it is reported. `broken`'s `status` is the answer's, and a redirect in a browser reads 0. |
61
+ | <a id="flipstream"></a>`flipstream` | The main SDK as the signed-in person. Read the getter for each piece of work, for example `await session.flipstream.me()`. A call uses the person displayed when it is made. With nobody shown, a bearer call answers at once. A kept client or scope answers `cancelled` after the person or rights change. After `close()` the getter stays readable, and a call on the client rejects with `SessionClosedError`. |
62
+ | <a id="requestlink"></a>`requestLink({ email, next }, { signal })` | Mails a login link. Empty text is `refused`, with nothing sent. `next` is a string or `null`. Anything else, left out included, is a `TypeError`, with nothing stored or sent. An absolute URL or a `//` URL is stored as given. The app checks it against its routes. `next` comes back on the opened link and never travels in the mail. "Send again" is the same call. `aborted`: the mail may still have gone out. Every sending call answers `{ ok: true, data }` or `{ ok: false, error }` and rejects only on a programming error. The last argument is the caller's own signal. The entry sets each call's own time limit. `unavailable` means trying again later may work, and `invalid` was reported, so trying again won't help. `unavailable` is offline, a 5xx, or a 429 the call has no rule for. `invalid` is an answer outside the contract. The call stores this browser's attempt, then asks. An answer is frozen, all the way down. `refused` names the empty fields. `proxy_refused` is the app's own server refusing, a deployment fault, and `unsupported` is a browser without locks or storage. Once the caller's signal aborts, the call answers `aborted`, unless its own row says an abort is ignored once it is sent. `error.kind` says why a call stopped short. A call through the app's own proxy runs inside the session's cookie lock. |
63
+ | <a id="openedlink"></a>`openedLink()` | On the landing: whether a link's token was there, and for whom (`ready`, `spent`, `other_browser`, `invalid`, `no_token`, `invitation`). It only reads: nothing is sent and nothing stored, so it is safe in a render and when called twice (React's StrictMode renders twice). Each call gives a new, frozen object, equal in content while nothing has changed. `redeem` and `requestLinkAgain` take any object it gave, and refuse a copy, or one made by hand, with a `TypeError`. The app checks `next` against its routes. `next` is where the person was going. `spent` means this browser already used the link or asked over 10 minutes ago. `other_browser` means it was asked for somewhere else, or not at all. `invalid`: the token's address, the address shown and the attempt's differ. `no_token`: off the landing, or a reload after the token was taken. `invitation` means send the person to the invitation page. |
64
+ | <a id="redeem"></a>`redeem(link, { signal })` | Signs in with the `ready` link `openedLink()` gave: `signed_in`, or a two-step code wanted. Call it only on a press, never as the page loads: a prerender, a speculative load or a restored tab runs the page's script without one, and the link works once. If redeem answers `superseded`, read `current()`. If the press was overtaken before the link was sent, pressing it again sends it, unless the sign-in that overtook it used this link: then `current()` is `signed_in` and the link reads `spent`. If it was sent and the sign-in was lost, every later press in this page keeps `superseded`. Ask for a new link. `requestLinkAgain` takes the same link after `dead_link`. It takes only the object `openedLink()` gave. `aborted`: the sign-in may still complete, and `current()` tells. `dead_link`: the link is used up, because pulse-auth refused it (expired, or used elsewhere), or its code step ran out or locked. |
65
+ | <a id="requestlinkagain"></a>`requestLinkAgain(link, { signal })` | A new link for the same address and next page. Always a plain login link, also after a sign-up, because the account exists by then. It sends a new link to the address of a link this browser asked for, with its `next`. |
66
+ | <a id="twostepstatus"></a>`twoStepStatus({ signal })` | Reads whether two-step is enabled or required and how many backup codes remain. Made as the signed-in person: nobody signed in answers `signed_out`. A deployment that requires two-step does not allow turning it off. |
67
+ | <a id="starttwostepsetup"></a>`startTwoStepSetup({ signal })` | Starts enrollment for the signed-in person on the Security page. Returns the manual-entry `secret` and the `otpauth_uri` for a QR code. pulse-auth's own SVG is not passed on. The secret is what the person types into an authenticator, and the app draws the QR itself. |
68
+ | <a id="startsignintwostepsetup"></a>`startSignInTwoStepSetup(setup, { signal })` | Starts enrollment for the `two_step_setup` returned by this session's `logIn` or `redeem`. Pass its frozen `setup` object unchanged. A copy or an object from another session rejects with a TypeError before sending. A sign-in ended by another tab gives `superseded`. An elapsed challenge gives `expired`. |
69
+ | <a id="confirmtwostepsetup"></a>`confirmTwoStepSetup({ code }, { signal })` | On the signed-in security page, confirms setup with the first authenticator code and returns ten backup codes. After dispatch, await the answer even if the signal aborts. |
70
+ | <a id="newbackupcodes"></a>`newBackupCodes({ code }, { signal })` | Replaces the old backup codes with ten new ones. Show the codes from this answer while the person can save them. After dispatch, await the answer even if the signal aborts. A current code replaces the old set. |
71
+ | <a id="turnofftwostep"></a>`turnOffTwoStep({ code }, { signal })` | Turns off two-step for the signed-in person. A deployment that requires it answers `required`. |
72
+ | <a id="verifytwostep"></a>`verifyTwoStep({ code }, { signal })` | Sends the person's two-step or backup code and finishes the sign-in. The code, or a backup code, as typed. The state turns `signed_in` before this call answers, so a screen that leaves on `signed_in` takes this answer first: the backup codes exist nowhere else. Once the code is sent an abort is ignored. `not_sent`: the code was not sent, so press again. Before 0.15.0, this was `aborted`. When a sign-in or sign-out overtakes setup verification, `error.kind` is `superseded`. It also answers `superseded` if this tab cannot write its session state. Its `backup_codes` contains the ten issued codes only if the browser is signed out or the session can confirm the same user ID at delivery. Otherwise the field is `null`, including for a plain verify. A backup code is typed `xxxxx-xxxxx`. A code's own refusals are `locked`, and what a check can stop at includes `not_sent`, `expired` and `superseded`. pulse-auth locks at the fifth wrong code and says so at the sixth. `expired`: the challenge ran out, or none is pending: start the sign-in again. |
73
+ | <a id="signout"></a>`signOut()` | Only on a press. Signed out here and in every tab at once; `told` settles with what pulse-auth said. `superseded`: the record moved on since this sign-out: a sign-in, in any tab, or rarely a renewal by a tab that hadn't heard of it. That tab's cookie replaced the old one; it sent this logout first when it knew it was owed, and this call isn't told whether pulse-auth confirmed it. Nothing is pending for this sign-out; a sign-out made since is owed and sent on its own. Read `current()`. Another sign-out with no sign-in between (a second press, or one in another tab) is not `superseded`: this call is told what pulse-auth answered. A logout pulse-auth didn't confirm stays owed, and this tab stays signed out: it is retried, backing off, while the service is unreachable (no network, a 5xx, a 429); when it was refused (a 401 or 403) or answered outside the contract, it is kept, not retried on a timer: each tab that holds it sends it once, and a check of the shared state while that try is out sends nothing more; it is sent again at the next page load, the next sign-in, or a restore the tab runs: its own timed retry after `unavailable`, the browser coming back online while the tab is `unavailable`, or `start()`. It is still written down as owed once storage takes writes, so a reload owes it too. A 200 with no cookie behind it proves nothing. An unconfirmed sign-out's reason is `unavailable` when there was no answer, `refused` for a 401 or 403 (which proves nothing about the cookie), or `invalid` when the answer was reported. `confirmed`: pulse-auth ended the session, told by this tab or by another tab first. `unsupported`: this browser lacks what the session needs, so nobody was signed in and nothing was sent. |
74
+ | <a id="requestsignup"></a>`requestSignUp({ email, first_name, last_name, organization, accepted: { terms_version, privacy_version }, next }, { signal })` | Asks pulse-admin to email a sign-up link that opens in this browser. Success acknowledges the request. It says nothing about mail delivery, whether the address already has an account or whether the person can sign in. Disable the submit button while the call is pending because each press starts another request. For `refused`, check the named form fields, including `accepted.terms_version` and `accepted.privacy_version`. A nonblank version with surrounding whitespace rejects with a `TypeError` naming the field. For `unsupported`, the browser could not store the attempt. Read `current()`: an unsupported state means a browser dependency is missing, any other state means storage refused this write. A timeout, connection or CORS failure, 429 or 5xx gives `unavailable`. An unexpected response gives `invalid` and is reported. An abort after sending gives `aborted`: the organization may exist and the link may have been mailed. The stored attempt lets that link work here. The link opens in this browser with purpose `sign_up` and the `next` given. `next` is a string or `null`. Anything else, left out included, is a `TypeError`, with nothing stored or sent. An absolute URL or a `//` URL is stored as given. The app checks it against its routes. pulse-admin must allow this page's origin. |
75
+ | <a id="requestpasswordreset"></a>`requestPasswordReset({ email }, { signal })` | Asks for a reset link. The link lands on `/reset-password`. Known and unknown addresses get the same answer. The email may still arrive after an abort.|
76
+ | <a id="openedreset"></a>`openedReset()` | Reads the reset proof on the configured reset landing, including after close. It reads `no_token` after `password_set` or `dead_link`. Nothing is sent. Whether this page was opened with a reset link's token. |
77
+ | <a id="setpassword"></a>`setPassword(proof, { password }, { signal })` | Sets the link owner's password and ends their sessions. Stops include `dead_link` means expired or used before. `password_too_short` and `inactive` are as their names say. An abort after dispatch may leave the password set and the sessions ended. After `password_set` or `dead_link`, `openedReset()` reads `no_token`. After `unavailable`, the reset may have reached pulse-auth and a retry can answer `dead_link` even though the password was set. In that case, ask the person to try signing in with the new password before requesting a new link. Keep the form's submitted state while `setPassword` is pending. If the link's owner is signed in here and pulse-auth confirms revocation, `current()` already reads `signed_out` when this call settles. Another person signed in here stays signed in. An abort during that check or a wait of 15 seconds returns the known reset outcome while the check continues. pulse-auth wants at least 8 characters. The types allow other ready links; the session checks this proof by identity.|
78
+ | <a id="close"></a>`close()` | Ends this session object: its listeners, timers and channel. A request already sent settles with its real outcome (a sign-in already sent that then loses, to a sign-out in another tab or with an answer that can't be read, is still revoked with a `/logout`), but nothing new is sent: a call still waiting to send answers `unavailable`, and a sign-out whose first try hadn't gone out is told `unconfirmed`, its logout left pending. A logout storage refused to record is left for the next session in this page that looks, made before or after the close, which sends it before it restores. It is lost, and the person's own sign-in may restore, when it was never written down: the page closed while storage still refused, or storage came back too shortly before to have taken it: a logout retried on the back-off is written at its next try, 30 seconds later at most, and one kept without a timer at the tab's next check of the shared state (another tab's write, the tab shown again or back online, a token asked for). A sign-out made after `close()` (a sign-in answered after it, or a `signOut()` racing it) reaches only this page, not the other tabs. If the stored record is lost while the cookie stays, the page can't tell whose cookie it is, and the logout still goes, even when someone signed in since. A session left open with a sign-out it couldn't write down gives way as the slot does: a sign-in or a sign-out another tab recorded after that sign-out speaks for the cookie, so the session drops its own sign-out. After a sign-in it sends no logout and restores that person; after a sign-out it sends that one's logout. When the shared record read signed out or was lost, and another tab that never heard of the sign-out restored the cookie first, that restore is recorded at a new generation, made by a refresh and naming the person signed out: the sign-out stands past it, its logout goes, and every tab ends signed out, from an open session or the slot alike. Only the tab that made the sign-out, or the slot its page keeps, knows whose cookie it was owed for: a tab that only heard of it gives way to that record, as before. A restore against a record that still reads signed in keeps its generation, so the sign-out stands and its logout goes, unless the refresh answers another person. Then a new generation starts, and the sign-out is told `superseded`, with no logout sent: the browser's one cookie is that person's now, so no logout from it could reach the person signed out. A sign-in this browser refused to keep, whose revoke storage couldn't record, is owed for the person that sign-in named: when a tab that never heard of it refreshes with that sign-in's cookie and gets that person, the new generation names the very person the revoke was owed for, so the revoke stands past it, goes, and ends that sign-in's session, also when it rode on a sign-out this tab already owed. Either is still lost, and the session it was owed for lives on, when nothing knows whose cookie it was or the record moved further on: a slot left by a page whose tabs only heard of the sign-out; a revoke after an answer this tab couldn't read; two refused sign-ins of different persons that both rode, in two of the page's objects, once both have closed; a refused sign-in in an object made after another object of the page signed out or was revoked, once both have closed; or a restore recorded two or more generations past the one the sign-out was made against, since a sign-in may have come between. A closed session rejects before anything is sent, so it never comes back signed in with no timer. Every call after it throws or rejects with `SessionClosedError`, `subscribe` and `start` included, except the reads: `consentRequest()`, `current()`, `openedLink()`, `openedReset()`, `openedInvitation()` and the `flipstream` getter stay readable, and an unsubscribe handed out before stays safe to call. Not a sign-out: the person stays signed in, in every tab. |
79
+ | <a id="consentrequest"></a>`consentRequest()` | Reads the current page address, including after close. A callback outside HTTP or HTTPS reads as `invalid`. For `asking`, show the client ID, callback host and requested scopes. To return here after sign-in, pass this page's path and query to `requestLink` as `next`. There is no second way to keep a request across a sign-in. The approval verifies `redirect_host`, the host of `redirect_uri`, port included when it is not the scheme's own. The SDK refuses a `redirect_to` whose origin or path is not the `redirect_uri`'s. `invalid`: the address holds no authorize request, or one that can't be read. |
80
+ | <a id="approveconsent-denyconsent"></a>`approveConsent(request, { signal })`, `denyConsent(request, { signal })` | On a press, send the choice as the signed-in person. Pass the exact request this session showed. A copy or a request issued by another session rejects with a TypeError. On success, navigate to the checked `redirect_to`. A denial returns the checked callback carrying the refusal. With nobody signed in, `signed_out` sends nothing. A second press returns `answered` while the first is pending. Once it settles, try again if nothing was sent, or after a 429, which arrives as `unavailable`, or after `unknown_client`, `invalid_scope` or `invalid_target`. Approve renews once on `login_required`. If its retry never goes out or again gets `login_required`, the page can press again. `unknown_client` means the app or callback could not be identified. `invalid_scope` and `invalid_target` mean the app may not ask for that scope or resource. An answer outside the contract gives `invalid` and is reported. After the send, `aborted`, `signed_out` or `unavailable` may leave the request answered as the person who pressed. When the outcome is uncertain, another press returns `answered`. Reload or sign in again to make a fresh press. Approval may have issued a code and claimed a dynamically registered client for that person’s account. The SDK refuses a `redirect_to` whose origin or path is not the `redirect_uri`'s, and the approval verifies `redirect_host`. |
81
+ | <a id="login"></a>`logIn({ email, password }, { signal })` | Signs in with an address and the password as typed: `signed_in`, or a two-step code wanted (`two_step`, `two_step_setup`). Only on a press. Empty fields are `refused`, with nothing sent. `invalid_credentials` covers a wrong password, no such account and no password set: pulse-auth says one thing for all. `too_many_attempts` comes with no end time, because pulse-auth has none to give. `superseded`: a sign-in or sign-out, in any tab, came after the press; read `current()`. A refusal is never folded into it. `aborted`: the sign-in may still complete, and `current()` tells; a code asked for once every caller of that request has left is dropped, and the next press asks again. A `signal` that is not an AbortSignal is a TypeError, with nothing sent. A request that is not an object, `null` included, is a TypeError; an array is an object, so it is `refused` for the fields it lacks. The password is never stored, reported or put in a key. The same request pressed again while one is under way joins it; a different one is its own attempt. On `superseded`, before the send nothing was sent, and after it pulse-auth's answer would have signed in (that session is revoked) or asked for a code (that code is dropped). `expires_at` on a two-step step is when the challenge ends, in epoch milliseconds. The address is trimmed and lower-cased before it is sent. `inactive`: the account is deactivated. Pass the setup object unchanged to `startSignInTwoStepSetup`. Two-step must be set up before that sign-in can finish.The password is sent exactly as typed, spaces included. |
82
+ | <a id="openedinvitation"></a>`openedInvitation()` | On `invitationLanding`: whether the page was opened with an invitation's token (`ready`, `no_token`). Nothing sent, and readable after `close()`. It reads `no_token` once this page is done with the invitation: pulse-auth answered an accept with a 2xx, or the invitation was found dead. The token, and any code screen the accept leads to, live in this page's memory only, never in storage: after a reload `openedInvitation()` reads `no_token`, and the code screen is gone. |
83
+ | <a id="previewinvitation"></a>`previewInvitation(opened, { signal })` | What the `ready` invitation is for, straight from pulse-auth with no cookie: `personal` (it names its recipient, `email`) or `shared` (it names nobody), with `organization_name` (`''` when the deployment doesn't say), `app_name`, `roles`, `privacy_policy_url` (or `null`) and `continue` (`{ name, url, login_url }` of the app it goes on to, or `null`). The first preview marks the invitation as opened at pulse-auth. `dead_link`: unknown, revoked, expired or spent; pulse-auth says one thing for all. The types allow other ready proofs; the session checks this proof by identity. It gives no member-or-guest kind and no workspace, so the page works from `roles` and `app_name`. `continue` sets `name`, `url` and `login_url` together or not at all, and `url` is sent back with the accept. `continue.login_url` is where to send the person when `continue_to` is null. For a personal invitation, the account is made for its `email`, whatever anyone types. |
84
+ | <a id="acceptinvitation"></a>`acceptInvitation(invitation, entry, { signal })` | Only on a press. Makes the account and signs the person in, through the proxy, as `logIn` does. Pass the invitation `previewInvitation` returned, as it is (a copy is a `TypeError`), narrowed on its `kind`: a personal one takes `{ first_name, last_name, privacy_policy_accepted }` and an optional `password` (without one the account signs in by link only), a shared one also `email` and `password`. pulse-auth itself refuses an accept without both names, a 400, so the SDK stops it first. Empty names, and a shared accept's empty address or password, are `refused`; a privacy policy not accepted is `privacy_policy_required`; nothing is sent then. `privacy_policy_accepted` must be true only when the invitation has a `privacy_policy_url`. `signed_in` carries `continue_to`, a fresh one-time link into the invitation's app, or `null`: then, when the invitation has a `continue`, send the person to `continue.login_url`; without one, they are signed in here. A deployment that requires two-step answers `two_step` or `two_step_setup`, as `logIn` does, and `verifyTwoStep` then ends it the same way: to `continue.login_url` when there is a `continue`, otherwise signed in here. `changed`: the invitation was edited since the preview, and now needs an address or a password this call didn't carry; preview it again. `dead_link`: unknown, revoked, expired or spent, or edited to another address since its link was sent: ask for it to be sent again. `password_too_short`: pulse-auth wants at least 8 characters, for any password given here. `account_exists`: log in first. `superseded`: a sign-in or sign-out, in any tab, came after the press; read `current()`. Once pulse-auth answers the accept with a 2xx (an accepted answer, or `superseded` or `invalid` after it), or `dead_link`, `openedInvitation()` reads `no_token`, also when the caller aborted after the send: this page is done with the invitation (spent, unless it allows more than one use). After `unavailable` the account may already exist and `openedInvitation()` stays `ready`. After `aborted` once the accept was sent, the request goes on: `openedInvitation()` reads `ready` while it is out, then `no_token` if pulse-auth answered a 2xx or `dead_link`, and `ready` otherwise. While it stays `ready` the account may already exist: a later `dead_link` then means "log in", with the password or by a login link. A second press with a different entry while one is out is its own attempt, not joined to the first; right before it is sent it reads the invitation again: if the first used it, the second answers `superseded`, and if the first, or a preview, found it dead, `dead_link`, with nothing sent either way. The first's answer stands, with its code screen if it still has one. With no privacy policy at the preview, pulse-auth's privacy refusal is `changed`: preview again. On `superseded`, before the send nothing was sent, and after it pulse-auth's answer would have signed in (that session is revoked) or asked for a code (that code is dropped). For a personal invitation, the account is made for its `email`, whatever anyone types.Two forms, one per kind, so the caller narrows on `kind` first. |
85
+ | <a id="lookupdevice"></a>`lookUpDevice({ user_code }, { signal })` | Device sign-in: looks up the code a device shows, as typed, and answers the request to show the person: `user_code` as pulse-auth formats it, `client_id`, `client_name` (the name the client declares for itself: for a client registered by metadata document or dynamically, nobody has checked it, so show `client_id` beside it; `null` when pulse-auth can't resolve the client), `scopes` and `expires_at` (epoch ms). An open read straight to pulse-auth, with no cookie and no token: it changes nothing, so it may run on load, and works whoever is signed in, or nobody. `unknown_code`: unknown, expired or already used, which pulse-auth doesn't tell apart. `already_denied`: the request was denied before; only a look-up says so. An empty code is `refused`, with nothing sent. A request that is not an object, or a `signal` that is not an AbortSignal, is a TypeError, with nothing sent.|
86
+ | <a id="approvedevice-denydevice"></a>`approveDevice(request, { signal })`, `denyDevice(request, { signal })` | Answers the request `lookUpDevice()` answered on this session, straight to pulse-auth as the signed-in person, only on a press: `approved` or `denied`. Any other object, a copy of it or one from another session included, is a TypeError, with nothing sent. Nobody signed in, or another person by the time it would be sent: `signed_out`, with nothing sent. `unknown_code`: the code is unknown, expired or already used (pulse-auth says the same for all three); a press on it would be sent again, but pulse-auth no longer holds it: ask the device for a new code. `answered`: a press from this page on this code (looked up again included) is still out, or may already have acted on it, for the person signed in now; nothing was sent. Once the first settles, a press is sent again if nothing was sent, or after a 429, which arrives as `unavailable`. After the send, `signed_out`, `aborted`, `invalid` or any other `unavailable` may leave the device answered as the person who pressed: another press answers `answered`, and a fresh look-up doesn't change that. Only signing in again lets a press be sent. An answer that isn't the decision pressed is `invalid` and reported. |
78
87
 
79
88
  Every call that asks a server answers `{ ok: true, data }` or `{ ok: false, error }` and rejects
80
89
  only on a programming error. A call whose `signal` aborts answers `aborted` at once (`verifyTwoStep`: `not_sent` before its send), which always means it may have happened: read `current()`. Once `verifyTwoStep` sends its code, it answers what pulse-auth said. The code-delivery exceptions are described below. Once the service confirms a password reset, an abort ends only that caller's wait for the session check.
@@ -131,6 +140,12 @@ that carries their token; health, which carries none, keeps the default.
131
140
 
132
141
  ## The proxy's contract
133
142
 
143
+ | Call | What it does |
144
+ | --- | --- |
145
+ | <a id="decideauthproxy"></a>`decideAuthProxy(request, app)` | Whether the proxy forwards this request, refuses it, or answers 404. `AUTH_PROXY_PATHS` is the paths the session can send, all POST, and it is data, so an nginx config can be rendered from it. `login` is `logIn`'s, and `invitations/accept` is `acceptInvitation`'s. `AUTH_PROXY_NEVER_PASSED` leaves out any name starting with `x-forwarded-`, and `host` and `cookie`, which are removed on every forward. A path that is not one of the app's is a 404 with no mark, and a path that matches is then guarded. The refusal mark is one module the session and the proxy both import, and that module imports nothing. `refused` is the only `X-Auth-Proxy` value the session treats as the proxy refusal. Those names are ones a browser can write that must not reach pulse-auth as the browser wrote them. |
146
+ | <a id="passback"></a>`passBack(answer, app)` | The status unchanged, and the headers a browser can be given. Each `Set-Cookie` is its own pair, because `get('set-cookie')` would join them. `Content-Length` and `Content-Encoding` are kept, because the body is piped through undecoded. `Set-Cookie` is kept only for a name the app lists. The refusal mark and every hop-by-hop header are dropped, and nothing is added. A `Headers` object and Node's header record both work. |
147
+ | <a id="authproxycases"></a>`authProxyCases(app)` | The rows for `app`: one forward for each path it serves, the paths that miss, the guard, the cookies, the headers that are never passed on, and what comes back. `or.answer` is what the browser is given. An absent `upstream_answers` means the stand-in answers 204 with no headers. Two `Set-Cookie` values are checked on `passBack`, because a record cannot hold one header twice. `or` is a second outcome a correct proxy may give, and a `*` path is filled with `abc`. `expect.cookies`, `expect.absent` and `expect.not_as_sent` are the same for both outcomes of `or`. An absent `paths` means the six paths the session can send. There is no default cookie list: an app names which of the two it passes, and a deployed host with siblings lists only `__Host-refresh_token`. A target that holds `#` and expects 404 also holds when the answer is 400 and nothing is forwarded. `upstream` is the path the stand-in should see, or null when nothing is forwarded. A row is plain data an app can keep. |
148
+
134
149
  The calls that read or set the refresh cookie go to the app's own server at `authPath`, which
135
150
  passes them to pulse-auth. Everything else goes straight to its host with `credentials: 'omit'`.
136
151
  Direct requests omit cookies. Direct bearer requests and health use manual redirects. A redirect on the request itself answers `invalid` and is reported once, with status 0 for an opaque browser redirect. Open family requests also use manual redirects. The wire returns the status and the family reports it once. On a service host sharing the page's origin, a bearer cannot go to or below `authPath`. Escaped slash, backslash and percent on that origin are refused.
@@ -152,7 +167,9 @@ header. A proxy may answer 404 to a target that is not byte for byte a listed pa
152
167
  it and forward exactly the path it becomes. Normalising cuts the target at `#`, drops the query,
153
168
  decodes `%XX` once, resolves `.` and `..`, and merges repeated slashes. A final `.` or `..` keeps
154
169
  the slash, and a `..` above the root is not a target. It does not fold case and
155
- it does not drop a trailing slash, so `REFRESH` and `refresh/` stay a 404. It never forwards a
170
+ it does not drop a trailing slash, so `REFRESH` and `refresh/` stay a 404. For a target holding
171
+ `#`, the rows also accept a 400 with nothing forwarded (a front server may refuse it first,
172
+ SDK-D2026). The other targets get no 400: a 404, or the normalised forward. A normalising proxy never forwards a
156
173
  query. On a normalised target the rows check the Origin and the method. The rest of the guard
157
174
  (Content-Type, `Sec-Fetch-Site`, a header given twice) is the app's to keep, as on the listed path. `/login` is for password sign-in; `/invitations/accept`
158
175
  is for accepting an invitation. A proxy must not answer these paths with a
@@ -182,7 +199,7 @@ is refused when:
182
199
  pulse-auth's answers. The session reads it before the status, so a refusal is never read as
183
200
  pulse-auth's own 403: a call answers `proxy_refused`, the state is `broken` with status 403, and
184
201
  `onReport` hears `{ kind: 'answer', path, status: 403 }`, with `path` the server's own path. It is
185
- a deployment fault: nothing the person can fix.
202
+ a deployment fault: nothing the person can fix. The mark is one module the session and the proxy both import, and that module imports nothing.
186
203
 
187
204
  **What it passes on.** `AUTH_PROXY_COOKIES` names the cookies that exist, `refresh_token` and
188
205
  `__Host-refresh_token`. The app lists which of them it passes, in `cookies`, and there is no
@@ -214,7 +231,12 @@ Nothing is added, a CORS header included. A redirect is not followed. Every prox
214
231
  **What it never keeps.** No query string in its logs: a link's token travels in one.
215
232
 
216
233
  Production is nginx, in both apps. For dev and preview, `authProxyHandler` is the handler, and
217
- what it accepts it does right. Its bound is for the whole call, its body included. Vite mounts it with `server.middlewares.use('/auth', authProxyHandler(app, upstream))`.
234
+ what it accepts it does right. Its bound is for the whole call, its body included. Vite mounts it
235
+ with `cors: false` on `server` and `preview`, then `server.middlewares.use('/auth', authProxyHandler(app, upstream))`.
236
+ Vite's `cors` middleware answers OPTIONS with a 204 and adds `Access-Control-Allow-Origin` to `/auth`
237
+ answers before the handler runs; the page is same-origin. Vite's dev server answers a target holding
238
+ `#` with a 400 itself, which the rows accept. `vite preview` passes that target to the handler, which
239
+ answers 404.
218
240
  A server that does not strip the mount must. The handler below strips `/auth` and leaves everything else at 404.
219
241
 
220
242
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipstream/sdk",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "TypeScript SDK for the Flipstream APIs: typed requests and checked answers, in Node and in browsers.",
5
5
  "keywords": [
6
6
  "flipstream",