@flipstream/sdk 0.14.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 (225) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/README.md +95 -1
  3. package/dist/api/datasets.js +8 -8
  4. package/dist/api/datasets.js.map +1 -1
  5. package/dist/api/log.js +6 -10
  6. package/dist/api/log.js.map +1 -1
  7. package/dist/api/pathArgument.d.ts +7 -0
  8. package/dist/api/pathArgument.js +12 -0
  9. package/dist/api/pathArgument.js.map +1 -0
  10. package/dist/auth/transport.d.ts +6 -2
  11. package/dist/auth/transport.js +5 -3
  12. package/dist/auth/transport.js.map +1 -1
  13. package/dist/core/call.d.ts +4 -0
  14. package/dist/core/call.js +7 -1
  15. package/dist/core/call.js.map +1 -1
  16. package/dist/core/fetch.d.ts +20 -1
  17. package/dist/core/fetch.js +50 -3
  18. package/dist/core/fetch.js.map +1 -1
  19. package/dist/core/hosts.d.ts +11 -0
  20. package/dist/core/hosts.js +13 -0
  21. package/dist/core/hosts.js.map +1 -0
  22. package/dist/core/identify.d.ts +6 -2
  23. package/dist/core/identify.js +16 -12
  24. package/dist/core/identify.js.map +1 -1
  25. package/dist/core/result.d.ts +1 -1
  26. package/dist/core/shared.d.ts +2 -0
  27. package/dist/core/shared.js +1 -0
  28. package/dist/core/shared.js.map +1 -1
  29. package/dist/core/signal.d.ts +7 -0
  30. package/dist/core/signal.js +9 -0
  31. package/dist/core/signal.js.map +1 -1
  32. package/dist/first-party/asPerson.d.ts +13 -0
  33. package/dist/first-party/asPerson.js +144 -0
  34. package/dist/first-party/asPerson.js.map +1 -0
  35. package/dist/first-party/attempts.d.ts +71 -0
  36. package/dist/first-party/attempts.js +132 -0
  37. package/dist/first-party/attempts.js.map +1 -0
  38. package/dist/first-party/authProxyMark.d.ts +10 -0
  39. package/dist/first-party/authProxyMark.js +11 -0
  40. package/dist/first-party/authProxyMark.js.map +1 -0
  41. package/dist/first-party/browser.d.ts +55 -0
  42. package/dist/first-party/browser.js +137 -0
  43. package/dist/first-party/browser.js.map +1 -0
  44. package/dist/first-party/browserSession.d.ts +95 -0
  45. package/dist/first-party/browserSession.js +242 -0
  46. package/dist/first-party/browserSession.js.map +1 -0
  47. package/dist/first-party/calls/consent.d.ts +89 -0
  48. package/dist/first-party/calls/consent.js +174 -0
  49. package/dist/first-party/calls/consent.js.map +1 -0
  50. package/dist/first-party/calls/device.d.ts +97 -0
  51. package/dist/first-party/calls/device.js +133 -0
  52. package/dist/first-party/calls/device.js.map +1 -0
  53. package/dist/first-party/calls/invitation.d.ts +244 -0
  54. package/dist/first-party/calls/invitation.js +258 -0
  55. package/dist/first-party/calls/invitation.js.map +1 -0
  56. package/dist/first-party/calls/logIn.d.ts +61 -0
  57. package/dist/first-party/calls/logIn.js +48 -0
  58. package/dist/first-party/calls/logIn.js.map +1 -0
  59. package/dist/first-party/calls/reset.d.ts +61 -0
  60. package/dist/first-party/calls/reset.js +163 -0
  61. package/dist/first-party/calls/reset.js.map +1 -0
  62. package/dist/first-party/calls/signUp.d.ts +21 -0
  63. package/dist/first-party/calls/signUp.js +72 -0
  64. package/dist/first-party/calls/signUp.js.map +1 -0
  65. package/dist/first-party/calls/twoStepSetup.d.ts +78 -0
  66. package/dist/first-party/calls/twoStepSetup.js +168 -0
  67. package/dist/first-party/calls/twoStepSetup.js.map +1 -0
  68. package/dist/first-party/claims.d.ts +88 -0
  69. package/dist/first-party/claims.js +181 -0
  70. package/dist/first-party/claims.js.map +1 -0
  71. package/dist/first-party/enrollment.d.ts +10 -0
  72. package/dist/first-party/enrollment.js +44 -0
  73. package/dist/first-party/enrollment.js.map +1 -0
  74. package/dist/first-party/entry.d.ts +573 -0
  75. package/dist/first-party/entry.js +582 -0
  76. package/dist/first-party/entry.js.map +1 -0
  77. package/dist/first-party/hooks.d.ts +81 -0
  78. package/dist/first-party/hooks.js +19 -0
  79. package/dist/first-party/hooks.js.map +1 -0
  80. package/dist/first-party/http.d.ts +191 -0
  81. package/dist/first-party/http.js +364 -0
  82. package/dist/first-party/http.js.map +1 -0
  83. package/dist/first-party/index.d.ts +14 -0
  84. package/dist/first-party/index.js +3 -0
  85. package/dist/first-party/index.js.map +1 -0
  86. package/dist/first-party/landed.d.ts +32 -0
  87. package/dist/first-party/landed.js +50 -0
  88. package/dist/first-party/landed.js.map +1 -0
  89. package/dist/first-party/landedProof.d.ts +12 -0
  90. package/dist/first-party/landedProof.js +20 -0
  91. package/dist/first-party/landedProof.js.map +1 -0
  92. package/dist/first-party/linkToken.d.ts +15 -0
  93. package/dist/first-party/linkToken.js +28 -0
  94. package/dist/first-party/linkToken.js.map +1 -0
  95. package/dist/first-party/links.d.ts +100 -0
  96. package/dist/first-party/links.js +84 -0
  97. package/dist/first-party/links.js.map +1 -0
  98. package/dist/first-party/locks.d.ts +36 -0
  99. package/dist/first-party/locks.js +64 -0
  100. package/dist/first-party/locks.js.map +1 -0
  101. package/dist/first-party/personTransport.d.ts +38 -0
  102. package/dist/first-party/personTransport.js +177 -0
  103. package/dist/first-party/personTransport.js.map +1 -0
  104. package/dist/first-party/proxy/app.d.ts +32 -0
  105. package/dist/first-party/proxy/app.js +94 -0
  106. package/dist/first-party/proxy/app.js.map +1 -0
  107. package/dist/first-party/proxy/bound.d.ts +5 -0
  108. package/dist/first-party/proxy/bound.js +13 -0
  109. package/dist/first-party/proxy/bound.js.map +1 -0
  110. package/dist/first-party/proxy/cases.d.ts +71 -0
  111. package/dist/first-party/proxy/cases.js +411 -0
  112. package/dist/first-party/proxy/cases.js.map +1 -0
  113. package/dist/first-party/proxy/decide.d.ts +31 -0
  114. package/dist/first-party/proxy/decide.js +139 -0
  115. package/dist/first-party/proxy/decide.js.map +1 -0
  116. package/dist/first-party/proxy/freeze.d.ts +2 -0
  117. package/dist/first-party/proxy/freeze.js +10 -0
  118. package/dist/first-party/proxy/freeze.js.map +1 -0
  119. package/dist/first-party/proxy/handler.d.ts +23 -0
  120. package/dist/first-party/proxy/handler.js +190 -0
  121. package/dist/first-party/proxy/handler.js.map +1 -0
  122. package/dist/first-party/proxy/headers.d.ts +7 -0
  123. package/dist/first-party/proxy/headers.js +20 -0
  124. package/dist/first-party/proxy/headers.js.map +1 -0
  125. package/dist/first-party/proxy/hop.d.ts +9 -0
  126. package/dist/first-party/proxy/hop.js +37 -0
  127. package/dist/first-party/proxy/hop.js.map +1 -0
  128. package/dist/first-party/proxy/host.d.ts +5 -0
  129. package/dist/first-party/proxy/host.js +11 -0
  130. package/dist/first-party/proxy/host.js.map +1 -0
  131. package/dist/first-party/proxy/index.d.ts +7 -0
  132. package/dist/first-party/proxy/index.js +6 -0
  133. package/dist/first-party/proxy/index.js.map +1 -0
  134. package/dist/first-party/proxy/pass-back.d.ts +26 -0
  135. package/dist/first-party/proxy/pass-back.js +47 -0
  136. package/dist/first-party/proxy/pass-back.js.map +1 -0
  137. package/dist/first-party/proxy/paths.d.ts +15 -0
  138. package/dist/first-party/proxy/paths.js +34 -0
  139. package/dist/first-party/proxy/paths.js.map +1 -0
  140. package/dist/first-party/proxy/shown.d.ts +5 -0
  141. package/dist/first-party/proxy/shown.js +16 -0
  142. package/dist/first-party/proxy/shown.js.map +1 -0
  143. package/dist/first-party/proxy/stand-in.d.ts +49 -0
  144. package/dist/first-party/proxy/stand-in.js +341 -0
  145. package/dist/first-party/proxy/stand-in.js.map +1 -0
  146. package/dist/first-party/report.d.ts +56 -0
  147. package/dist/first-party/report.js +38 -0
  148. package/dist/first-party/report.js.map +1 -0
  149. package/dist/first-party/result.d.ts +150 -0
  150. package/dist/first-party/result.js +40 -0
  151. package/dist/first-party/result.js.map +1 -0
  152. package/dist/first-party/session/cell.d.ts +201 -0
  153. package/dist/first-party/session/cell.js +103 -0
  154. package/dist/first-party/session/cell.js.map +1 -0
  155. package/dist/first-party/session/closed.d.ts +11 -0
  156. package/dist/first-party/session/closed.js +15 -0
  157. package/dist/first-party/session/closed.js.map +1 -0
  158. package/dist/first-party/session/index.d.ts +3 -0
  159. package/dist/first-party/session/index.js +3 -0
  160. package/dist/first-party/session/index.js.map +1 -0
  161. package/dist/first-party/session/logout.d.ts +102 -0
  162. package/dist/first-party/session/logout.js +526 -0
  163. package/dist/first-party/session/logout.js.map +1 -0
  164. package/dist/first-party/session/owed.d.ts +105 -0
  165. package/dist/first-party/session/owed.js +128 -0
  166. package/dist/first-party/session/owed.js.map +1 -0
  167. package/dist/first-party/session/refresh.d.ts +19 -0
  168. package/dist/first-party/session/refresh.js +236 -0
  169. package/dist/first-party/session/refresh.js.map +1 -0
  170. package/dist/first-party/session/results.d.ts +38 -0
  171. package/dist/first-party/session/results.js +74 -0
  172. package/dist/first-party/session/results.js.map +1 -0
  173. package/dist/first-party/session/session.d.ts +2 -0
  174. package/dist/first-party/session/session.js +376 -0
  175. package/dist/first-party/session/session.js.map +1 -0
  176. package/dist/first-party/session/shared.d.ts +34 -0
  177. package/dist/first-party/session/shared.js +145 -0
  178. package/dist/first-party/session/shared.js.map +1 -0
  179. package/dist/first-party/session/sharedSignal.d.ts +27 -0
  180. package/dist/first-party/session/sharedSignal.js +55 -0
  181. package/dist/first-party/session/sharedSignal.js.map +1 -0
  182. package/dist/first-party/session/signIn.d.ts +48 -0
  183. package/dist/first-party/session/signIn.js +340 -0
  184. package/dist/first-party/session/signIn.js.map +1 -0
  185. package/dist/first-party/session/signInThrough.d.ts +6 -0
  186. package/dist/first-party/session/signInThrough.js +144 -0
  187. package/dist/first-party/session/signInThrough.js.map +1 -0
  188. package/dist/first-party/session/sync.d.ts +17 -0
  189. package/dist/first-party/session/sync.js +174 -0
  190. package/dist/first-party/session/sync.js.map +1 -0
  191. package/dist/first-party/session/tokens.d.ts +18 -0
  192. package/dist/first-party/session/tokens.js +64 -0
  193. package/dist/first-party/session/tokens.js.map +1 -0
  194. package/dist/first-party/session/types.d.ts +270 -0
  195. package/dist/first-party/session/types.js +3 -0
  196. package/dist/first-party/session/types.js.map +1 -0
  197. package/dist/first-party/sessionWire.d.ts +31 -0
  198. package/dist/first-party/sessionWire.js +91 -0
  199. package/dist/first-party/sessionWire.js.map +1 -0
  200. package/dist/first-party/signInHooks.d.ts +85 -0
  201. package/dist/first-party/signInHooks.js +2 -0
  202. package/dist/first-party/signInHooks.js.map +1 -0
  203. package/dist/first-party/state.d.ts +71 -0
  204. package/dist/first-party/state.js +55 -0
  205. package/dist/first-party/state.js.map +1 -0
  206. package/dist/first-party/strip.d.ts +1 -0
  207. package/dist/first-party/strip.js +8 -0
  208. package/dist/first-party/strip.js.map +1 -0
  209. package/dist/first-party/twoStepLock.d.ts +26 -0
  210. package/dist/first-party/twoStepLock.js +58 -0
  211. package/dist/first-party/twoStepLock.js.map +1 -0
  212. package/dist/first-party/twoStepSession.d.ts +21 -0
  213. package/dist/first-party/twoStepSession.js +31 -0
  214. package/dist/first-party/twoStepSession.js.map +1 -0
  215. package/dist/first-party/wire.d.ts +63 -0
  216. package/dist/first-party/wire.js +5 -0
  217. package/dist/first-party/wire.js.map +1 -0
  218. package/dist/flipstream.d.ts +80 -19
  219. package/dist/flipstream.js +121 -36
  220. package/dist/flipstream.js.map +1 -1
  221. package/dist/node/session.js +3 -1
  222. package/dist/node/session.js.map +1 -1
  223. package/dist/version.gen.js +1 -1
  224. package/docs/first-party.md +300 -0
  225. package/package.json +34 -5
@@ -0,0 +1,91 @@
1
+ import { refusedRedirect } from './http.js';
2
+ /*
3
+ * The wire (wire.ts) on a browser session (#465): how a family's request reaches a server. `open`
4
+ * goes straight to pulse-auth or pulse-admin without a cookie or token. createPersonAccess adds
5
+ * the signed-in sender. The family uses the wire's clock and reports a redirect through the
6
+ * wire's reporter. The open sender returns the redirect status without following it (SDK-D1962).
7
+ */
8
+ /** A call straight to a host gives up after this long, as the main entry's calls do (30 s). */
9
+ export const OPEN_DEADLINE_MS = 30_000;
10
+ /** A path a family sends to, on its host: '/oauth/device/verify'. Anything else is a programming error. */
11
+ export function checkPath(path) {
12
+ if (!/^\/(?!\/)[^?#]*$/.test(path)) {
13
+ throw new TypeError('a wire request’s path starts with one /, and has no query or fragment');
14
+ }
15
+ }
16
+ /** The JSON a body holds, or undefined when there is none, or it isn't JSON. */
17
+ export function parsed(text) {
18
+ if (text === '')
19
+ return undefined;
20
+ try {
21
+ const value = JSON.parse(text);
22
+ return value;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ export function createSessionWire(deps) {
29
+ const open = async (host, request, options) => {
30
+ checkPath(request.path);
31
+ const caller = options?.signal;
32
+ // A function, so the compiler doesn't keep the answer it gave before the await.
33
+ const abortedByCaller = () => caller?.aborted === true;
34
+ if (abortedByCaller())
35
+ return { kind: 'aborted' };
36
+ if (deps.closed())
37
+ return { kind: 'unavailable' };
38
+ const url = new URL(`${deps.hosts[host]}${request.path}`);
39
+ for (const [name, value] of Object.entries(request.query ?? {}))
40
+ url.searchParams.set(name, value);
41
+ const giveUp = new AbortController();
42
+ const timer = setTimeout(() => {
43
+ giveUp.abort();
44
+ }, OPEN_DEADLINE_MS);
45
+ const cut = () => {
46
+ giveUp.abort();
47
+ };
48
+ caller?.addEventListener('abort', cut, { once: true });
49
+ try {
50
+ const response = await deps.fetch(url, {
51
+ method: request.method,
52
+ credentials: 'omit',
53
+ // A redirect is a misconfigured host, not an outage (SDK-D1953): never followed,
54
+ // because a 307 would send the body again.
55
+ redirect: 'manual',
56
+ signal: giveUp.signal,
57
+ headers: request.method === 'POST'
58
+ ? { Accept: 'application/json', 'Content-Type': 'application/json' }
59
+ : { Accept: 'application/json' },
60
+ ...(request.method === 'POST' ? { body: JSON.stringify(request.body ?? {}) } : {}),
61
+ });
62
+ // Nothing to parse, and Node's 3xx may carry a body, so it is cancelled at once.
63
+ // This call goes to another origin. The page sees the redirect only when the browser
64
+ // lets it see the answer; otherwise fetch rejects and the call is unavailable.
65
+ // The family reports a status outside its table. The wire does not (SDK-D1962).
66
+ if (refusedRedirect(response.status)) {
67
+ await response.body?.cancel().catch(() => undefined);
68
+ return { kind: 'answer', status: response.status, body: undefined };
69
+ }
70
+ const text = await response.text();
71
+ return { kind: 'answer', status: response.status, body: parsed(text) };
72
+ }
73
+ catch {
74
+ // fetch rejects only when no answer came, or its body broke off: offline, the deadline,
75
+ // or the caller's own signal.
76
+ return abortedByCaller() ? { kind: 'aborted' } : { kind: 'unavailable' };
77
+ }
78
+ finally {
79
+ clearTimeout(timer);
80
+ caller?.removeEventListener('abort', cut);
81
+ }
82
+ };
83
+ return {
84
+ open,
85
+ report: (answer) => {
86
+ deps.report({ path: answer.path, status: answer.status });
87
+ },
88
+ now: deps.now,
89
+ };
90
+ }
91
+ //# sourceMappingURL=sessionWire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionWire.js","sourceRoot":"","sources":["../../src/first-party/sessionWire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAI3C;;;;;GAKG;AAEH,+FAA+F;AAC/F,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAqBtC,2GAA2G;AAC3G,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CAAC,uEAAuE,CAAC,CAAA;IAC9F,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,SAAS,CAAA;IACjC,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO,KAAK,CAAA;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAc;IAC9C,MAAM,IAAI,GAAG,KAAK,EAChB,IAAsB,EACtB,OAAoB,EACpB,OAAgC,EACA,EAAE;QAClC,SAAS,CAAC,OAAO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;QAC3C,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QAC3D,CAAC;QACD,GAAG,EAAE,IAAI,CAAC,GAAG;KACd,CAAA;AACH,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { SignInStep } from './hooks.js';
2
+ import type { CallOptions, ThroughProxy } from './result.js';
3
+ import type { WireAnswer, WireRequest } from './wire.js';
4
+ /**
5
+ * sdk#467 (password sign-in): a call that answers a TokenResponse, run as a redeem runs. logIn is
6
+ * its first user; the invitation's accept (sdk#472) the second.
7
+ */
8
+ export interface SignInHooks {
9
+ /**
10
+ * Through the proxy, pinned to the press, inside the cookie lock (a pending logout sent
11
+ * first), the other tabs told. `superseded` when a sign-in or sign-out, in any tab, came after
12
+ * the press (read `current()`): before the send, nothing is sent; after it, only for an answer
13
+ * that would have signed in (that session is revoked) or opened a challenge (dropped). Once sent, a refusal, no answer or the proxy's
14
+ * is answered as it is (SDK-D1946). Sent once however often it is asked while one is under way.
15
+ * The session reads every 2xx: a token signs in, a challenge is kept (its two-step lock under
16
+ * `email`) while a caller is left to answer it, and dropped once every caller has left
17
+ * (SDK-D1975), a 2xx it can't use is `invalid` and its logout recorded. `extra`: the fields of
18
+ * that 200 the session lets out for this step, by a list it owns: for `accept` exactly
19
+ * `continue_link`, for `log-in` nothing; and `{}` with any two-step step. Never a token, a
20
+ * challenge or a backup code, and never a field pulse-auth adds later (SDK-D1907, 3 Dec). The
21
+ * family reads every answer that is not a 2xx (`refused`), with its own rules. A route that is
22
+ * not the step's own POST rejects with a `TypeError` after the closed check, before anything
23
+ * else, nothing sent (SDK-D1929).
24
+ * `onRefused`: called once per request with an answer that is not a 2xx, on the request's own
25
+ * result, whatever its callers did; where the family reports one outside its contract (one
26
+ * request, one report: SDK-D1949, SDK-D1976). Only the press that started the request is asked.
27
+ * `onSettled`: called once per request, after `onRefused`, with the request's own result,
28
+ * whatever its callers did (one that left after the send was told `aborted`, and a joined caller
29
+ * shares the request), and before any caller is answered. `received`: pulse-auth answered this
30
+ * request a 2xx (not an HTML page, which is the app's own), whatever the session made of it
31
+ * (`step`, `superseded` because the session it made was revoked, `invalid` because it couldn't
32
+ * be read, `unavailable` because every caller left before a challenge was taken). false: no 2xx
33
+ * (a refusal, no answer, the proxy's, or a stop before the send). A request whose result rejects
34
+ * calls neither hook: that is a fault in this session, possibly after pulse-auth answered. The
35
+ * invitation's token is then kept, and a retry answers `dead_link` if it was used. Where a
36
+ * family keeps what lives as long as the request (sdk#472: the invitation's token).
37
+ * `sendable`, an accept's only (sdk#549): asked at most once per request, inside the cookie
38
+ * lock, after the owed logout and before the last look, once every earlier accept on this page
39
+ * has run its hooks. Not asked when the turn isn't had, the session closed or the generation
40
+ * moved. `null`: go, which can still end with nothing sent (the last look). A stop: the request
41
+ * settles with it, nothing sent; the family decides which, inside the lock (`superseded`: an
42
+ * accept on this page used the invitation; `dead_link`: the invitation is dead). An accept
43
+ * without a `sendable` function is a `TypeError` at the press, nothing waited for or sent.
44
+ */
45
+ readonly signInThrough: SignInThrough;
46
+ }
47
+ /** A log-in's answers, and an accept's, which can also be its own `sendable`'s stop. */
48
+ export interface SignInThrough {
49
+ (request: WireRequest, how: LogInHow, options: CallOptions | undefined): Promise<SignInThroughAnswer>;
50
+ (request: WireRequest, how: AcceptHow, options: CallOptions | undefined): Promise<SignInThroughAnswer | AcceptGone>;
51
+ }
52
+ /** What a family is told and asked about its request; `A` is what the request can answer. */
53
+ export interface HowBase<A> {
54
+ readonly email: string | null;
55
+ readonly onRefused: (answer: WireAnswer) => void;
56
+ readonly onSettled: (answer: A, heard: {
57
+ readonly received: boolean;
58
+ }) => void;
59
+ }
60
+ /** Why an accept's `sendable` stops its request, nothing sent (sdk#549). */
61
+ export type AcceptGone = {
62
+ readonly kind: 'superseded';
63
+ } | {
64
+ readonly kind: 'dead_link';
65
+ };
66
+ export type LogInHow = HowBase<SignInThroughAnswer> & {
67
+ readonly step: 'log-in';
68
+ };
69
+ export type AcceptHow = HowBase<SignInThroughAnswer | AcceptGone> & {
70
+ readonly step: 'accept';
71
+ readonly sendable: () => AcceptGone | null;
72
+ };
73
+ /** How a family's request signs in: a log-in, or an accept, which also says whether it may still go. */
74
+ export type SignInHow = LogInHow | AcceptHow;
75
+ /** What `signInThrough` answers a caller, and tells `onSettled` of the request. */
76
+ export type SignInThroughAnswer = {
77
+ readonly kind: 'step';
78
+ readonly step: SignInStep;
79
+ readonly extra: Readonly<Record<string, unknown>>;
80
+ } | {
81
+ readonly kind: 'refused';
82
+ readonly answer: WireAnswer;
83
+ } | {
84
+ readonly kind: 'superseded';
85
+ } | ThroughProxy;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=signInHooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signInHooks.js","sourceRoot":"","sources":["../../src/first-party/signInHooks.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import type { StorageLike } from './browser.js';
2
+ /**
3
+ * Which session is current in this browser, shared by its tabs: the authority. The
4
+ * BroadcastChannel only makes changes quick (docs/architecture.md 2.3). It never holds a
5
+ * token.
6
+ */
7
+ export declare const STATE_KEY = "flipstream-auth:state";
8
+ export interface AuthState {
9
+ /**
10
+ * Moves on every sign-in and sign-out, and on a refresh that returns another person (sdk#535),
11
+ * never on a refresh of the same person. A generation begun under a record with no person, and
12
+ * renewed by a tab that knew nobody, can name another person by the end: so code delivery
13
+ * compares the person, not only the generation (PR 551 S1).
14
+ */
15
+ readonly generation: number;
16
+ readonly signedIn: boolean;
17
+ /** Moves every time a refresh or sign-in adopts a token, so a late token never rolls a tab back. */
18
+ readonly serial: number;
19
+ /**
20
+ * A sign-out pulse-auth hasn't confirmed, for the generation the sign-out made. Inside
21
+ * this record, so one write changes both: no tab can read a signed-out generation
22
+ * without its pending logout.
23
+ */
24
+ readonly logoutPending: {
25
+ readonly generation: number;
26
+ } | null;
27
+ /**
28
+ * A fingerprint of the principal the latest adopted token carries (claims.ts, never the
29
+ * claims themselves), null when signed out. A tab that missed a token message finds out
30
+ * from here that who is signed in, or what they may do, changed, and refreshes; the same
31
+ * principal at a newer serial needs nothing, so tabs never refresh each other in turn.
32
+ */
33
+ readonly principal: string | null;
34
+ /**
35
+ * A fingerprint of the person alone (the `uid` claim, claims.ts), null when signed out. A
36
+ * refresh compares it: another person starts a new generation, a changed role doesn't. On a
37
+ * signed-in record without one (written before it was kept, or by a console), the refresh
38
+ * compares the token its tab holds at that generation instead. With neither, nothing is known:
39
+ * it keeps the generation, as before, and writes the person from then on (sdk#535, SDK-D2023 as
40
+ * amended in PR 551).
41
+ */
42
+ readonly person: string | null;
43
+ /**
44
+ * Which kind of write made this generation (sdk#552, SDK-D2025): `sign-in`, `refresh` (a restore,
45
+ * another person behind the cookie, or a dead cookie read as signed out) or `sign-out`. A write
46
+ * that keeps the generation keeps it. Null on a record without it (a console's, or an older SDK
47
+ * tab's) or with a value this version doesn't know, and read exactly as before this field.
48
+ *
49
+ * It decides one thing: whether an unrecorded sign-out (a sign-out storage refused, kept in a tab's
50
+ * memory or a page's slot) still stands once storage reads a newer record. A record written since
51
+ * speaks for the cookie and ends it, except a record a refresh made at exactly one past the stored
52
+ * generation the sign-out was made against, naming the very person the sign-out was owed for: that
53
+ * refresh used the cookie the logout was owed for, so the sign-out stands and its logout still goes
54
+ * (`standingAt`, owed.ts). Another person, or a person not known, means the cookie changed owner,
55
+ * and the record is read as before (PR 551 S4; the lead's narrowing of SDK-D2025). Only that one
56
+ * generation: the record keeps only its latest maker, so at two or more past, a sign-in may
57
+ * have come between (a sign-in, then another person's refresh) and the record is read as before
58
+ * (reading (ii), the lead's ruling on sdk#552).
59
+ */
60
+ readonly madeBy: MadeBy | null;
61
+ }
62
+ /** The kinds of write that start a generation (`AuthState.madeBy`). */
63
+ export type MadeBy = 'sign-in' | 'refresh' | 'sign-out';
64
+ /** No record at all: a new browser, or Local Storage cleared. Never "signed out" by itself: the cookie decides (§2.3). */
65
+ export declare const NO_RECORD: AuthState;
66
+ /** The record in storage, or NO_RECORD when there is none or it can't be read. */
67
+ export declare function readState(storage: StorageLike): AuthState;
68
+ /** Whether the browser took the write. */
69
+ export declare function writeState(storage: StorageLike, state: AuthState): boolean;
70
+ /** The newer of two states: the higher generation, then the higher serial. */
71
+ export declare function newer(a: AuthState, b: AuthState): AuthState;
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Which session is current in this browser, shared by its tabs: the authority. The
4
+ * BroadcastChannel only makes changes quick (docs/architecture.md 2.3). It never holds a
5
+ * token.
6
+ */
7
+ export const STATE_KEY = 'flipstream-auth:state';
8
+ /** No record at all: a new browser, or Local Storage cleared. Never "signed out" by itself: the cookie decides (§2.3). */
9
+ export const NO_RECORD = {
10
+ generation: 0,
11
+ signedIn: false,
12
+ serial: 0,
13
+ logoutPending: null,
14
+ principal: null,
15
+ person: null,
16
+ madeBy: null,
17
+ };
18
+ const Generation = z.int().min(0);
19
+ const StateSchema = z.object({
20
+ generation: Generation,
21
+ signedIn: z.boolean(),
22
+ serial: Generation,
23
+ logoutPending: z.object({ generation: Generation }).nullable(),
24
+ // A record from before the fingerprint has none: nothing to compare, nothing assumed.
25
+ principal: z.string().nullable().default(null),
26
+ person: z.string().nullable().default(null),
27
+ // A maker this version doesn't know reads as none, so the record stays readable (sdk#552).
28
+ madeBy: z.enum(['sign-in', 'refresh', 'sign-out']).nullable().catch(null),
29
+ });
30
+ /** The record in storage, or NO_RECORD when there is none or it can't be read. */
31
+ export function readState(storage) {
32
+ const raw = storage.getItem(STATE_KEY);
33
+ if (raw === null)
34
+ return NO_RECORD;
35
+ let json;
36
+ try {
37
+ json = JSON.parse(raw);
38
+ }
39
+ catch {
40
+ return NO_RECORD;
41
+ }
42
+ const parsed = StateSchema.safeParse(json);
43
+ return parsed.success ? parsed.data : NO_RECORD;
44
+ }
45
+ /** Whether the browser took the write. */
46
+ export function writeState(storage, state) {
47
+ return storage.setItem(STATE_KEY, JSON.stringify(state));
48
+ }
49
+ /** The newer of two states: the higher generation, then the higher serial. */
50
+ export function newer(a, b) {
51
+ if (a.generation !== b.generation)
52
+ return a.generation > b.generation ? a : b;
53
+ return a.serial >= b.serial ? a : b;
54
+ }
55
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/first-party/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAuB,CAAA;AA0DhD,0HAA0H;AAC1H,MAAM,CAAC,MAAM,SAAS,GAAc;IAClC,UAAU,EAAE,CAAC;IACb,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;CACb,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAEjC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,UAAU,EAAE,UAAU;IACtB,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,MAAM,EAAE,UAAU;IAClB,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC9D,sFAAsF;IACtF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,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
@@ -0,0 +1 @@
1
+ export { strip } from './linkToken.js';
@@ -0,0 +1,8 @@
1
+ // @flipstream/sdk/first-party/link-token (#465): what the app's boot module calls, before anything
2
+ // else is evaluated: `const cleaned = strip(location.href)`, then
3
+ // `if (cleaned !== null) history.replaceState(history.state, '', cleaned)`, which keeps the entry's
4
+ // state. The boot module holds only that, and the app's entry module imports it first.
5
+ // The same module the session reads (linkToken.ts), so the token it keeps is the one the session
6
+ // takes. Nothing else: no session, no network.
7
+ export { strip } from './linkToken.js';
8
+ //# sourceMappingURL=strip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip.js","sourceRoot":"","sources":["../../src/first-party/strip.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,kEAAkE;AAClE,oGAAoG;AACpG,uFAAuF;AACvF,iGAAiG;AACjG,+CAA+C;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,26 @@
1
+ import type { StorageLike } from './browser.js';
2
+ /** The address the code screen's link was asked for, from this browser's attempt. */
3
+ export declare function attemptEmail(storage: StorageLike, attemptId: string, now: number): string | null;
4
+ /** The kept end for `email` while it is still ahead of `now`: null when there is none ahead. */
5
+ export declare function keptLockEnd(storage: StorageLike, email: string, now: number): number | null;
6
+ /**
7
+ * Keeps `end` for `email`, and drops the ends already past. A write the browser refuses keeps
8
+ * nothing: the next lock then counts its own five minutes, as it did before.
9
+ */
10
+ export declare function keepLockEnd(storage: StorageLike, email: string, end: number, now: number): void;
11
+ /**
12
+ * Drops the kept end for `email`: pulse-auth counted a code as wrong, or took one, so its lock
13
+ * is over, and a later lock is a new one with its own five minutes. The kept end is only the
14
+ * latest the old lock could end, up to five minutes past the real end.
15
+ */
16
+ export declare function forgetLockEnd(storage: StorageLike, email: string): void;
17
+ /**
18
+ * How long pulse-auth refuses codes after the fifth wrong one in a row (`mfa.py`, LOCKOUT).
19
+ * Its answer says neither when the lock began nor when it ends, and the fifth wrong code is
20
+ * still answered as a wrong code: counted from the answer that says "locked", the end is
21
+ * the latest it can be. Up to the whole minute, as people read it: the minute shown is never
22
+ * before the lock ends.
23
+ */
24
+ export declare const TWO_STEP_LOCKOUT_MS: number;
25
+ export declare const MINUTE_MS = 60000;
26
+ export declare function firstLockEnd(answeredAt: number): number;
@@ -0,0 +1,58 @@
1
+ import { findAttempt } from './attempts.js';
2
+ import { normalizeEmail } from './claims.js';
3
+ /*
4
+ * The end of a two-step lock this browser was told about, per address (Michel, 17 Oct).
5
+ * pulse-auth's lock isn't moved by a code tried during it (`mfa.py`: `_check_lock` refuses
6
+ * before anything is counted), so an end still ahead stays the end, and a new link must not
7
+ * start the five minutes over. An address and a time only: never a token or a code.
8
+ */
9
+ const PREFIX = 'flipstream-auth:two-step-lock:';
10
+ const END = /^\d{13}$/;
11
+ /** The address the code screen's link was asked for, from this browser's attempt. */
12
+ export function attemptEmail(storage, attemptId, now) {
13
+ const lookup = findAttempt(storage, attemptId, now);
14
+ return lookup.kind === 'missing' ? null : normalizeEmail(lookup.attempt.email);
15
+ }
16
+ /** The kept end for `email` while it is still ahead of `now`: null when there is none ahead. */
17
+ export function keptLockEnd(storage, email, now) {
18
+ const end = endOf(storage.getItem(PREFIX + email));
19
+ return end !== null && end > now ? end : null;
20
+ }
21
+ /**
22
+ * Keeps `end` for `email`, and drops the ends already past. A write the browser refuses keeps
23
+ * nothing: the next lock then counts its own five minutes, as it did before.
24
+ */
25
+ export function keepLockEnd(storage, email, end, now) {
26
+ for (const key of storage.keys()) {
27
+ if (!key.startsWith(PREFIX))
28
+ continue;
29
+ const kept = endOf(storage.getItem(key));
30
+ if (kept === null || kept <= now)
31
+ storage.removeItem(key);
32
+ }
33
+ storage.setItem(PREFIX + email, String(end));
34
+ }
35
+ /**
36
+ * Drops the kept end for `email`: pulse-auth counted a code as wrong, or took one, so its lock
37
+ * is over, and a later lock is a new one with its own five minutes. The kept end is only the
38
+ * latest the old lock could end, up to five minutes past the real end.
39
+ */
40
+ export function forgetLockEnd(storage, email) {
41
+ storage.removeItem(PREFIX + email);
42
+ }
43
+ function endOf(value) {
44
+ return value !== null && END.test(value) ? Number(value) : null;
45
+ }
46
+ /**
47
+ * How long pulse-auth refuses codes after the fifth wrong one in a row (`mfa.py`, LOCKOUT).
48
+ * Its answer says neither when the lock began nor when it ends, and the fifth wrong code is
49
+ * still answered as a wrong code: counted from the answer that says "locked", the end is
50
+ * the latest it can be. Up to the whole minute, as people read it: the minute shown is never
51
+ * before the lock ends.
52
+ */
53
+ export const TWO_STEP_LOCKOUT_MS = 5 * 60_000;
54
+ export const MINUTE_MS = 60_000;
55
+ export function firstLockEnd(answeredAt) {
56
+ return Math.ceil((answeredAt + TWO_STEP_LOCKOUT_MS) / MINUTE_MS) * MINUTE_MS;
57
+ }
58
+ //# sourceMappingURL=twoStepLock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twoStepLock.js","sourceRoot":"","sources":["../../src/first-party/twoStepLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C;;;;;GAKG;AAEH,MAAM,MAAM,GAAG,gCAAgC,CAAA;AAC/C,MAAM,GAAG,GAAG,UAAU,CAAA;AAEtB,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAC1B,OAAoB,EACpB,SAAiB,EACjB,GAAW;IAEX,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAA;IACnD,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAChF,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CACzB,OAAoB,EACpB,KAAa,EACb,GAAW;IAEX,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OA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AAmB,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;AAC9E,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { StorageLike } from './browser.js';
2
+ import type { AuthSession } from './session/types.js';
3
+ import type { Wire } from './wire.js';
4
+ type Session = Pick<AuthSession, 'current' | 'isCurrent' | 'signInSetupChallenge' | 'canDeliverCodes'>;
5
+ export declare function setupHooks(session: Session, storage: StorageLike | null): {
6
+ setupRevision(): number | null;
7
+ signInSetupChallenge: (setup: import("./hooks.js").SignInSetup) => {
8
+ readonly kind: "pending";
9
+ readonly challenge: string;
10
+ } | {
11
+ readonly kind: "expired" | "superseded";
12
+ };
13
+ codeRecipient(): () => boolean;
14
+ addressLock(): {
15
+ keptLockEnd: (now: number) => number | null;
16
+ keepLockEnd: (end: number, now: number) => void;
17
+ forgetLockEnd: () => void;
18
+ } | null;
19
+ };
20
+ export declare function twoStepForSession(wire: Wire, session: Session, storage: StorageLike | null): import("./calls/twoStepSetup.js").TwoStepSetupCalls;
21
+ export {};
@@ -0,0 +1,31 @@
1
+ import { createTwoStepSetupCalls } from './calls/twoStepSetup.js';
2
+ import { normalizeEmail } from './claims.js';
3
+ import { keptLockEnd, keepLockEnd, forgetLockEnd } from './twoStepLock.js';
4
+ export function setupHooks(session, storage) {
5
+ return {
6
+ setupRevision() {
7
+ const current = session.current();
8
+ return current.status === 'signed-in' && session.isCurrent(current.revision) ? current.revision : null;
9
+ },
10
+ signInSetupChallenge: session.signInSetupChallenge,
11
+ codeRecipient() {
12
+ const pressed = session.current();
13
+ return () => pressed.status === 'signed-in' && session.canDeliverCodes(pressed.principal.userId);
14
+ },
15
+ addressLock() {
16
+ const current = session.current();
17
+ if (storage === null || current.status !== 'signed-in' || !session.isCurrent(current.revision))
18
+ return null;
19
+ const email = normalizeEmail(current.principal.email);
20
+ return {
21
+ keptLockEnd: (now) => keptLockEnd(storage, email, now),
22
+ keepLockEnd: (end, now) => keepLockEnd(storage, email, end, now),
23
+ forgetLockEnd: () => forgetLockEnd(storage, email),
24
+ };
25
+ },
26
+ };
27
+ }
28
+ export function twoStepForSession(wire, session, storage) {
29
+ return createTwoStepSetupCalls(wire, setupHooks(session, storage));
30
+ }
31
+ //# sourceMappingURL=twoStepSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twoStepSession.js","sourceRoot":"","sources":["../../src/first-party/twoStepSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAK1E,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,OAA2B;IACtE,OAAO;QACL,aAAa;YACX,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;YACjC,OAAO,OAAO,CAAC,MAAM,KAAK,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;QACxG,CAAC;QACD,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,aAAa;YACX,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;YACjC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAClG,CAAC;QACD,WAAW;YACT,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;YACjC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAAE,OAAO,IAAI,CAAA;YAC3G,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACrD,OAAO;gBACL,WAAW,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;gBAC9D,WAAW,EAAE,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC;gBAChF,aAAa,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC;aACnD,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAU,EAAE,OAAgB,EAAE,OAA2B;IACzF,OAAO,uBAAuB,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;AACpE,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { CallOptions } from './result.js';
2
+ export interface WireRequest {
3
+ readonly method: 'GET' | 'POST';
4
+ /** The server's own path, starting with '/': '/oauth/device/verify'. Never a full URL. */
5
+ readonly path: string;
6
+ /** Query pairs. The wire encodes them. */
7
+ readonly query?: Readonly<Record<string, string>>;
8
+ /** Sent as JSON. A POST without one sends `{}`, as the session's own calls do. */
9
+ readonly body?: Readonly<Record<string, unknown>>;
10
+ }
11
+ /** A server answered. `body`: the parsed JSON, or `undefined` when the answer isn't JSON. */
12
+ export interface WireAnswer {
13
+ readonly kind: 'answer';
14
+ readonly status: number;
15
+ readonly body: unknown;
16
+ }
17
+ /** No answer to read. */
18
+ export type WireStop =
19
+ /** Nothing came back in time: offline, a failed connection, the call's own time limit. */
20
+ {
21
+ readonly kind: 'unavailable';
22
+ } | {
23
+ readonly kind: 'aborted';
24
+ };
25
+ /**
26
+ * Every request the wire sends says `Accept: application/json`, and a body goes as
27
+ * `Content-Type: application/json`. So a family never sets a header.
28
+ *
29
+ * There is no way through the app's /auth proxy here (the lead, 2 Dec, on #465): every path it forwards
30
+ * sets or reads the session's cookie and answers a token the session must adopt, so a family
31
+ * goes through it only by the session's `signInThrough` (part 3), never raw.
32
+ */
33
+ export interface Wire {
34
+ /** Straight to a host, with no cookie and no token (`credentials: 'omit'`). */
35
+ readonly open: (host: 'auth' | 'admin', request: WireRequest, options: CallOptions | undefined) => Promise<WireAnswer | WireStop>;
36
+ /**
37
+ * Straight to pulse-auth as the signed-in person. Nobody signed in: `signed_out`, with nothing
38
+ * sent. A 401 renews the token once and sends again; refused again: `signed_out`.
39
+ */
40
+ readonly asPerson: (request: WireRequest, options: CallOptions | undefined,
41
+ /** Enrollment observes its dispatch. Calls issuing backup codes keep the sent answer across a caller abort. */
42
+ dispatch?: {
43
+ readonly onSend: () => void;
44
+ /** An anonymous approval can be a checked 200. Renew it once like a 401. */
45
+ readonly isUnauthorized?: (answer: WireAnswer) => boolean;
46
+ } | 'keep_sent_answer',
47
+ /** For successful keep_sent_answer responses only, including after the body has been read. */
48
+ canDeliver?: () => boolean) => Promise<WireAnswer | WireStop | {
49
+ readonly kind: 'signed_out';
50
+ }>;
51
+ /**
52
+ * An answer outside the contract: the path and the status, never a body. The family calls this
53
+ * once per call. `open` does not report a redirect (SDK-D1962).
54
+ */
55
+ readonly report: (answer: {
56
+ readonly path: string;
57
+ readonly status: number;
58
+ }) => void;
59
+ /** The clock, epoch ms. A family never reads `Date`: the lint refuses it. */
60
+ readonly now: () => number;
61
+ }
62
+ /** A 5xx, or a 429. A family asks this only after its own rules for that status. */
63
+ export declare function isUnavailable(answer: WireAnswer): boolean;
@@ -0,0 +1,5 @@
1
+ /** A 5xx, or a 429. A family asks this only after its own rules for that status. */
2
+ export function isUnavailable(answer) {
3
+ return answer.status === 429 || answer.status >= 500;
4
+ }
5
+ //# sourceMappingURL=wire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../src/first-party/wire.ts"],"names":[],"mappings":"AAoEA,oFAAoF;AACpF,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC9C,OAAO,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,IAAI,GAAG,CAAA;AACtD,CAAC"}