@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,71 @@
1
+ import type { StorageLike } from './browser.js';
2
+ /** A login link lives 10 minutes at pulse-auth: an attempt redeems for as long. */
3
+ export declare const ATTEMPT_TTL_MS: number;
4
+ /**
5
+ * How long an attempt is kept: a day, only so a link opened late, or again after it was
6
+ * used, says "doesn't work any more" here, not "asked for in another browser" (24m, 1).
7
+ * Two times on this browser's clock are compared, never the token's own expiry.
8
+ */
9
+ export declare const ATTEMPT_KEEP_MS: number;
10
+ export interface Attempt {
11
+ /** Normalised, as it was sent: the address typed in this browser. */
12
+ readonly email: string;
13
+ /** The page to go to afterwards, returned as stored by `openedLink()`; the app checks it against its routes. */
14
+ readonly next: string | null;
15
+ /** When it was made, on this browser's clock. */
16
+ readonly at: number;
17
+ /** Which form asked: a sign-up link opens as "Finish signing up" (24k). */
18
+ readonly purpose: 'log-in' | 'sign-up';
19
+ /** Its link signed someone in here: opened again, it doesn't work any more. */
20
+ readonly used: boolean;
21
+ }
22
+ export type AttemptLookup = {
23
+ readonly kind: 'found';
24
+ readonly attempt: Attempt;
25
+ }
26
+ /** This browser asked, but over 10 minutes ago, or its link was used: dead either way. */
27
+ | {
28
+ readonly kind: 'spent';
29
+ readonly attempt: Attempt;
30
+ }
31
+ /** Not asked for in this browser in the last day (or the id isn't one we make). */
32
+ | {
33
+ readonly kind: 'missing';
34
+ };
35
+ /**
36
+ * Stores a new attempt under its own key and returns its id, or null when the browser
37
+ * refused the write: then no link may be asked for, as it could never be redeemed. One key
38
+ * per attempt: no shared map two tabs could each read and write back, so no attempt erases
39
+ * another. Expired ones are pruned on every write.
40
+ */
41
+ export declare function createAttempt(storage: StorageLike, attempt: Attempt, random: (bytes: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>): string | null;
42
+ export declare function findAttempt(storage: StorageLike, id: string, now: number): AttemptLookup;
43
+ /** A link that didn't go out: its attempt goes. */
44
+ export declare function removeAttempt(storage: StorageLike, id: string): void;
45
+ /**
46
+ * Its link signed someone in: the attempt is kept, marked used, so the link opened again
47
+ * says it doesn't work any more. Removed instead when the browser refuses the write.
48
+ */
49
+ export declare function spendAttempt(storage: StorageLike, id: string): void;
50
+ /**
51
+ * What `checkLanding` asks of a path, in the words its RangeErrors use: the landings', `authPath`'s
52
+ * and its own. Never a value: a landing names where a login token goes.
53
+ */
54
+ export declare const PLAIN_PATH_RULE = "a plain path on the page\u2019s own origin, as the browser writes it: starting with /, no query, no fragment, no . or .. segment, percent-encoded";
55
+ /**
56
+ * A landing is a plain path on the page's own origin (#464's review): one `/` first, never `//`
57
+ * or `/\` (which URL reads as another host), and no query or fragment, since pulse-auth appends
58
+ * the token to the query and a fragment would leave it out of the part `strip()` reads. And it is
59
+ * its own pathname: one the URL parser rewrites (`/vérifier`, `/log in`, `/a/../b`, `/a/./b`)
60
+ * would never equal the path the link lands on, so every link would read `no_token` (#475's
61
+ * round 1, finding 8). Anything else is a RangeError, since the link it builds carries a login
62
+ * token.
63
+ */
64
+ export declare function checkLanding(landing: string): void;
65
+ /**
66
+ * Where the mailed link lands: `<origin><landing>?attempt=<id>&email=<email>`, to which
67
+ * pulse-auth appends `token`. Built with URL and searchParams, never by joining strings: a
68
+ * `+` in an address must arrive as `%2B`, not as a space. The origin is the page's own, and
69
+ * `landing` a plain path on it (the console's is `/login/confirm`, see `checkLanding`).
70
+ */
71
+ export declare function continueUrl(origin: string, landing: string, attemptId: string, email: string): string;
@@ -0,0 +1,132 @@
1
+ import { z } from 'zod';
2
+ /*
3
+ * A login attempt (A5, docs/architecture.md 2.2): asking for a link stores which address
4
+ * this browser asked for, and where to go afterwards. A link is redeemed only in the browser
5
+ * that holds its attempt, which closes login CSRF: an attacker can mail a victim their own
6
+ * link, but can't put their attempt in the victim's browser. `next` stays here and is never
7
+ * mailed.
8
+ */
9
+ const PREFIX = 'flipstream-auth:attempt:';
10
+ /** A login link lives 10 minutes at pulse-auth: an attempt redeems for as long. */
11
+ export const ATTEMPT_TTL_MS = 10 * 60_000;
12
+ /**
13
+ * How long an attempt is kept: a day, only so a link opened late, or again after it was
14
+ * used, says "doesn't work any more" here, not "asked for in another browser" (24m, 1).
15
+ * Two times on this browser's clock are compared, never the token's own expiry.
16
+ */
17
+ export const ATTEMPT_KEEP_MS = 24 * 3_600_000;
18
+ /** 128 random bits, as 32 lower-case hex digits. */
19
+ const ATTEMPT_ID = /^[0-9a-f]{32}$/;
20
+ const AttemptSchema = z.object({
21
+ email: z.string(),
22
+ next: z.string().nullable(),
23
+ at: z.number(),
24
+ purpose: z.enum(['log-in', 'sign-up']).default('log-in'),
25
+ used: z.boolean().default(false),
26
+ });
27
+ /**
28
+ * Stores a new attempt under its own key and returns its id, or null when the browser
29
+ * refused the write: then no link may be asked for, as it could never be redeemed. One key
30
+ * per attempt: no shared map two tabs could each read and write back, so no attempt erases
31
+ * another. Expired ones are pruned on every write.
32
+ */
33
+ export function createAttempt(storage, attempt, random) {
34
+ pruneAttempts(storage, attempt.at);
35
+ const id = Array.from(random(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, '0')).join('');
36
+ return storage.setItem(PREFIX + id, JSON.stringify(attempt)) ? id : null;
37
+ }
38
+ export function findAttempt(storage, id, now) {
39
+ if (!ATTEMPT_ID.test(id))
40
+ return { kind: 'missing' };
41
+ const attempt = parseAttempt(storage.getItem(PREFIX + id));
42
+ if (attempt === null || forgotten(attempt, now))
43
+ return { kind: 'missing' };
44
+ if (attempt.used || expired(attempt, now))
45
+ return { kind: 'spent', attempt };
46
+ return { kind: 'found', attempt };
47
+ }
48
+ /** A link that didn't go out: its attempt goes. */
49
+ export function removeAttempt(storage, id) {
50
+ if (ATTEMPT_ID.test(id))
51
+ storage.removeItem(PREFIX + id);
52
+ }
53
+ /**
54
+ * Its link signed someone in: the attempt is kept, marked used, so the link opened again
55
+ * says it doesn't work any more. Removed instead when the browser refuses the write.
56
+ */
57
+ export function spendAttempt(storage, id) {
58
+ if (!ATTEMPT_ID.test(id))
59
+ return;
60
+ const attempt = parseAttempt(storage.getItem(PREFIX + id));
61
+ if (attempt === null)
62
+ return;
63
+ if (!storage.setItem(PREFIX + id, JSON.stringify({ ...attempt, used: true }))) {
64
+ storage.removeItem(PREFIX + id);
65
+ }
66
+ }
67
+ function pruneAttempts(storage, now) {
68
+ for (const key of storage.keys()) {
69
+ if (!key.startsWith(PREFIX))
70
+ continue;
71
+ const attempt = parseAttempt(storage.getItem(key));
72
+ if (attempt === null || forgotten(attempt, now))
73
+ storage.removeItem(key);
74
+ }
75
+ }
76
+ /** Past its 10 minutes. A clock that went back counts too: an attempt from the future proves nothing. */
77
+ function expired(attempt, now) {
78
+ return now - attempt.at >= ATTEMPT_TTL_MS || attempt.at > now;
79
+ }
80
+ /** Past the day it is kept for. */
81
+ function forgotten(attempt, now) {
82
+ return now - attempt.at >= ATTEMPT_KEEP_MS;
83
+ }
84
+ function parseAttempt(raw) {
85
+ if (raw === null)
86
+ return null;
87
+ let json;
88
+ try {
89
+ json = JSON.parse(raw);
90
+ }
91
+ catch {
92
+ return null;
93
+ }
94
+ const parsed = AttemptSchema.safeParse(json);
95
+ return parsed.success ? parsed.data : null;
96
+ }
97
+ /**
98
+ * What `checkLanding` asks of a path, in the words its RangeErrors use: the landings', `authPath`'s
99
+ * and its own. Never a value: a landing names where a login token goes.
100
+ */
101
+ export const PLAIN_PATH_RULE = 'a plain path on the page’s own origin, as the browser writes it: starting with /, no query, no fragment, no . or .. segment, percent-encoded';
102
+ /**
103
+ * A landing is a plain path on the page's own origin (#464's review): one `/` first, never `//`
104
+ * or `/\` (which URL reads as another host), and no query or fragment, since pulse-auth appends
105
+ * the token to the query and a fragment would leave it out of the part `strip()` reads. And it is
106
+ * its own pathname: one the URL parser rewrites (`/vérifier`, `/log in`, `/a/../b`, `/a/./b`)
107
+ * would never equal the path the link lands on, so every link would read `no_token` (#475's
108
+ * round 1, finding 8). Anything else is a RangeError, since the link it builds carries a login
109
+ * token.
110
+ */
111
+ export function checkLanding(landing) {
112
+ if (!/^\/(?![/\\])[^?#\\\t\n\r]*$/.test(landing) || new URL(landing, 'https://x.invalid').pathname !== landing) {
113
+ throw new RangeError(`A link lands on ${PLAIN_PATH_RULE}.`);
114
+ }
115
+ }
116
+ /**
117
+ * Where the mailed link lands: `<origin><landing>?attempt=<id>&email=<email>`, to which
118
+ * pulse-auth appends `token`. Built with URL and searchParams, never by joining strings: a
119
+ * `+` in an address must arrive as `%2B`, not as a space. The origin is the page's own, and
120
+ * `landing` a plain path on it (the console's is `/login/confirm`, see `checkLanding`).
121
+ */
122
+ export function continueUrl(origin, landing, attemptId, email) {
123
+ checkLanding(landing);
124
+ const url = new URL(landing, origin);
125
+ if (url.origin !== new URL(origin).origin) {
126
+ throw new RangeError('A link lands on a path of the page’s own origin.');
127
+ }
128
+ url.searchParams.set('attempt', attemptId);
129
+ url.searchParams.set('email', email);
130
+ return url.toString();
131
+ }
132
+ //# sourceMappingURL=attempts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempts.js","sourceRoot":"","sources":["../../src/first-party/attempts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;;;;GAMG;AAEH,MAAM,MAAM,GAAG,0BAA0B,CAAA;AAEzC,mFAAmF;AACnF,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,GAAG,MAAM,CAAA;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,SAAS,CAAA;AAE7C,oDAAoD;AACpD,MAAM,UAAU,GAAG,gBAAgB,CAAA;AAenC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACxD,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CACjC,CAAC,CAAA;AASF;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAoB,EACpB,OAAgB,EAChB,MAAmE;IAEnE,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;IAClC,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CACzD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC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;IACb,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,8IAA8I,CAAA;AAEhJ;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,IAAI,CAAC,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC/G,MAAM,IAAI,UAAU,CAAC,mBAAmB,eAAe,GAAG,CAAC,CAAA;IAC7D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,OAAe,EACf,SAAiB,EACjB,KAAa;IAEb,YAAY,CAAC,OAAO,CAAC,CAAA;IACrB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACpC,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,IAAI,UAAU,CAAC,kDAAkD,CAAC,CAAA;IAC1E,CAAC;IACD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAC1C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACpC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The mark on a refusal of the proxy's own, so the session never reads it as pulse-auth's.
3
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#decideauthproxy
4
+ */
5
+ export declare const AUTH_PROXY_REFUSAL: "X-Auth-Proxy";
6
+ /**
7
+ * The only value of `AUTH_PROXY_REFUSAL` the session treats as the proxy's own refusal.
8
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#decideauthproxy
9
+ */
10
+ export declare const AUTH_PROXY_REFUSAL_VALUE: "refused";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The mark on a refusal of the proxy's own, so the session never reads it as pulse-auth's.
3
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#decideauthproxy
4
+ */
5
+ export const AUTH_PROXY_REFUSAL = 'X-Auth-Proxy';
6
+ /**
7
+ * The only value of `AUTH_PROXY_REFUSAL` the session treats as the proxy's own refusal.
8
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#decideauthproxy
9
+ */
10
+ export const AUTH_PROXY_REFUSAL_VALUE = 'refused';
11
+ //# sourceMappingURL=authProxyMark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authProxyMark.js","sourceRoot":"","sources":["../../src/first-party/authProxyMark.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAuB,CAAA;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAkB,CAAA"}
@@ -0,0 +1,55 @@
1
+ /** The slice of `navigator.locks` the session uses. */
2
+ export interface LockManagerLike {
3
+ request<T>(name: string, options: {
4
+ readonly signal: AbortSignal;
5
+ }, callback: () => Promise<T>): Promise<T>;
6
+ }
7
+ /** The slice of `localStorage` the session uses. It never throws (private mode, quota). */
8
+ export interface StorageLike {
9
+ getItem(key: string): string | null;
10
+ /** Whether the browser took the write: a full quota or blocked site data refuse it. */
11
+ setItem(key: string, value: string): boolean;
12
+ removeItem(key: string): void;
13
+ /** Every key, for pruning expired attempts. */
14
+ keys(): readonly string[];
15
+ }
16
+ /** The slice of a `BroadcastChannel` the session uses. */
17
+ export interface ChannelLike {
18
+ postMessage(message: unknown): void;
19
+ addEventListener(type: 'message', listener: (event: {
20
+ readonly data: unknown;
21
+ }) => void): void;
22
+ removeEventListener(type: 'message', listener: (event: {
23
+ readonly data: unknown;
24
+ }) => void): void;
25
+ close(): void;
26
+ }
27
+ /**
28
+ * Where a page subscriber's exception goes. A page has `reportError`, which is also what a
29
+ * listener that throws does there. Outside a page there is none, so the same exception is
30
+ * thrown again from a fresh microtask, as Node does for a listener (SDK-D1915). Either way
31
+ * it stays out of the session's own report.
32
+ */
33
+ export declare function subscriberErrorReporter(host: {
34
+ reportError?: (cause: unknown) => void;
35
+ queueMicrotask: (task: () => void) => void;
36
+ }): (cause: unknown) => void;
37
+ /**
38
+ * localStorage behind StorageLike, or null when this browser won't let the page use it
39
+ * (blocked site data, or none at all): such a browser can't sign in (§2.3).
40
+ */
41
+ export declare function browserStorage(): StorageLike | null;
42
+ /**
43
+ * This tab's sessionStorage behind StorageLike, or null without it: where a staff member's
44
+ * choice of customer is kept, per tab (§2.7). A blocked getter is null, as localStorage is.
45
+ */
46
+ export declare function browserTabStorage(): StorageLike | null;
47
+ /** `navigator.locks`, or null where there are no Web Locks (Safari before 15.4). */
48
+ export declare function browserLocks(): LockManagerLike | null;
49
+ /**
50
+ * The tabs' channel, or null when this browser has no BroadcastChannel or refuses to open
51
+ * one. Firefox throws SecurityError from the constructor when storage is denied. That is
52
+ * no channel, the same as a missing BroadcastChannel: the shared state still works, and
53
+ * creating the session does not throw (SDK-D1940).
54
+ */
55
+ export declare function browserChannel(name: string): ChannelLike | null;
@@ -0,0 +1,137 @@
1
+ /*
2
+ * The browser's pieces the session needs, as small interfaces: tests hand in fakes (a lock
3
+ * manager several tabs share, a slow channel, one storage), never `vi.mock` (the testing
4
+ * skill, hard rule 1), and a browser without them is `unsupported`.
5
+ */
6
+ /**
7
+ * Where a page subscriber's exception goes. A page has `reportError`, which is also what a
8
+ * listener that throws does there. Outside a page there is none, so the same exception is
9
+ * thrown again from a fresh microtask, as Node does for a listener (SDK-D1915). Either way
10
+ * it stays out of the session's own report.
11
+ */
12
+ export function subscriberErrorReporter(host) {
13
+ const reportError = host.reportError;
14
+ if (typeof reportError === 'function')
15
+ return reportError.bind(host);
16
+ return (cause) => {
17
+ host.queueMicrotask(() => {
18
+ throw cause;
19
+ });
20
+ };
21
+ }
22
+ /**
23
+ * The page's storage, or null when this browser won't let the page use it (blocked site
24
+ * data, or none at all). `typeof` only shields a name that isn't there. Where site data is
25
+ * blocked the getter itself throws, and that is the same answer: no storage (SDK-D1940).
26
+ */
27
+ function openStorage(read) {
28
+ try {
29
+ const storage = read();
30
+ return storage === undefined ? null : wrap(storage);
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ /**
37
+ * localStorage behind StorageLike, or null when this browser won't let the page use it
38
+ * (blocked site data, or none at all): such a browser can't sign in (§2.3).
39
+ */
40
+ export function browserStorage() {
41
+ return openStorage(() => globalThis.localStorage);
42
+ }
43
+ /**
44
+ * This tab's sessionStorage behind StorageLike, or null without it: where a staff member's
45
+ * choice of customer is kept, per tab (§2.7). A blocked getter is null, as localStorage is.
46
+ */
47
+ export function browserTabStorage() {
48
+ return openStorage(() => globalThis.sessionStorage);
49
+ }
50
+ function wrap(storage) {
51
+ try {
52
+ const probe = 'flipstream-auth:probe';
53
+ storage.setItem(probe, '1');
54
+ storage.removeItem(probe);
55
+ }
56
+ catch {
57
+ return null;
58
+ }
59
+ return {
60
+ getItem(key) {
61
+ try {
62
+ return storage.getItem(key);
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ },
68
+ setItem(key, value) {
69
+ try {
70
+ storage.setItem(key, value);
71
+ return true;
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ },
77
+ removeItem(key) {
78
+ try {
79
+ storage.removeItem(key);
80
+ }
81
+ catch {
82
+ // A removal that failed leaves an entry that expires or is overwritten.
83
+ }
84
+ },
85
+ keys() {
86
+ try {
87
+ return Array.from({ length: storage.length }, (_, i) => storage.key(i)).filter((key) => key !== null);
88
+ }
89
+ catch {
90
+ return [];
91
+ }
92
+ },
93
+ };
94
+ }
95
+ /** `navigator.locks`, or null where there are no Web Locks (Safari before 15.4). */
96
+ export function browserLocks() {
97
+ if (typeof navigator === 'undefined' || !('locks' in navigator))
98
+ return null;
99
+ const locks = navigator.locks;
100
+ return {
101
+ // TypeScript 5.9's DOM types say `request` answers a promise of the callback's promise;
102
+ // the browser flattens it, and `await` says so to the compiler (os builds on 6.0, whose
103
+ // types need nothing here).
104
+ request: async (name, options, callback) => await locks.request(name, options, callback),
105
+ };
106
+ }
107
+ /**
108
+ * The tabs' channel, or null when this browser has no BroadcastChannel or refuses to open
109
+ * one. Firefox throws SecurityError from the constructor when storage is denied. That is
110
+ * no channel, the same as a missing BroadcastChannel: the shared state still works, and
111
+ * creating the session does not throw (SDK-D1940).
112
+ */
113
+ export function browserChannel(name) {
114
+ if (typeof BroadcastChannel === 'undefined')
115
+ return null;
116
+ try {
117
+ const channel = new BroadcastChannel(name);
118
+ return {
119
+ postMessage: (message) => {
120
+ channel.postMessage(message);
121
+ },
122
+ addEventListener: (type, listener) => {
123
+ channel.addEventListener(type, listener);
124
+ },
125
+ removeEventListener: (type, listener) => {
126
+ channel.removeEventListener(type, listener);
127
+ },
128
+ close: () => {
129
+ channel.close();
130
+ },
131
+ };
132
+ }
133
+ catch {
134
+ return null;
135
+ }
136
+ }
137
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/first-party/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmCH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAGvC;IACC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;IACpC,IAAI,OAAO,WAAW,KAAK,UAAU;QAAE,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpE,OAAO,CAAC,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OAAO;YACL,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE;gBACvB,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YAC9B,CAAC;YACD,gBAAgB,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACnC,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC1C,CAAC;YACD,mBAAmB,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACtC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC7C,CAAC;YACD,KAAK,EAAE,GAAG,EAAE;gBACV,OAAO,CAAC,KAAK,EAAE,CAAA;YACjB,CAAC;SACF,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { type ChannelLike, type LockManagerLike, type StorageLike } from './browser.js';
2
+ import type { SessionReport } from './report.js';
3
+ import { type LoginLinkRequest, type OpenedLink, type SignupAttemptDeps } from './links.js';
4
+ import { type AuthSession, type RedeemResult, type SessionView } from './session/index.js';
5
+ import { type OwedSlot } from './session/owed.js';
6
+ export interface FirstPartyDeps {
7
+ /** The one network edge. Tests serve recorded answers through it. */
8
+ readonly fetch: typeof fetch;
9
+ readonly locks: LockManagerLike | null;
10
+ readonly storage: StorageLike | null;
11
+ readonly channel: ChannelLike | null;
12
+ /** What the app's operator should know (report.ts): never a body, a token or a message's content. */
13
+ readonly report: (report: SessionReport) => void;
14
+ /** A subscriber's exception, sent where the page's uncaught errors go (SDK-D1915). */
15
+ readonly reportError: (cause: unknown) => void;
16
+ readonly now: () => number;
17
+ readonly random: (bytes: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
18
+ /** The page's own origin: where login links land. */
19
+ readonly origin: string;
20
+ /** The path on it a login link lands on (the console's is `/login/confirm`). */
21
+ readonly landing: string;
22
+ /** The same-origin path the page's own server forwards to pulse-auth (the console's is `/auth`). */
23
+ readonly authPath: string;
24
+ /** The login link's token, which the page's first script took out of the address. */
25
+ readonly linkToken: string | null;
26
+ /**
27
+ * The page's slot for a logout a closed session owed, which storage never took (owed.ts,
28
+ * sdk#483): one per page and auth path, shared by every session made there.
29
+ */
30
+ readonly owed: OwedSlot | null;
31
+ }
32
+ type ReadyLink = Extract<OpenedLink, {
33
+ readonly kind: 'ready';
34
+ }>;
35
+ /** What a page holds: the session's state and actions, and the links. Never a token. */
36
+ export interface BrowserSession {
37
+ readonly session: SessionView;
38
+ /** Asks for a login link, remembering in this tab's memory which address it went to. */
39
+ requestLink(email: string, next: string | null, signal?: AbortSignal): Promise<LoginLinkRequest>;
40
+ /** The address this tab last sent a link to, typed here, never read from an address bar. */
41
+ lastSent(): {
42
+ readonly email: string;
43
+ readonly next: string | null;
44
+ readonly at: number;
45
+ } | null;
46
+ /** Checks the link this page was opened with, before anyone clicks; never its token. */
47
+ checkLink(link: {
48
+ readonly attempt: unknown;
49
+ readonly email: unknown;
50
+ readonly invite?: unknown;
51
+ }): OpenedLink;
52
+ /** Redeems a checked link, on a click, checking it again first. */
53
+ redeem(link: ReadyLink, signal?: AbortSignal): Promise<RedeemResult>;
54
+ }
55
+ /**
56
+ * Whether a link can land on the page's own origin: only an http or https origin (scheme, host
57
+ * and port, nothing more) can. Anything else (`'null'`, what an opaque origin reads as; `file://`;
58
+ * an extension's; a string that doesn't parse) is a session nobody can sign in to. Never a
59
+ * RangeError: the origin is the page's, not an option the developer gives (SDK-D1934).
60
+ */
61
+ export declare function linkCanLand(origin: string): boolean;
62
+ /**
63
+ * The browser session and its whole session beside it, credentials included: for this module's
64
+ * browser events and the tests. os's createAuthInternals, without the console's own parts.
65
+ */
66
+ export declare function createFirstPartyInternals(deps: FirstPartyDeps): {
67
+ readonly browser: BrowserSession;
68
+ readonly session: AuthSession;
69
+ readonly linkDeps: SignupAttemptDeps;
70
+ };
71
+ export type BrowserOptions = Pick<FirstPartyDeps, 'report' | 'origin' | 'landing' | 'authPath' | 'linkToken'>;
72
+ /**
73
+ * The real browser's edges: localStorage, Web Locks and a BroadcastChannel (either of the first
74
+ * two missing makes the session `unsupported`), with the console's names, so its tabs and the
75
+ * console's take turns; this page's fetch, the wall clock and the browser's random bytes.
76
+ * An unsupported session opens no channel. Firefox throws from the constructor when storage
77
+ * is denied, and there is then nothing to close (SDK-D1940).
78
+ */
79
+ export declare function browserDeps(options: BrowserOptions): FirstPartyDeps;
80
+ /**
81
+ * The browser session in a real browser (browserDeps), and the events that keep its tabs in
82
+ * step. `start()` is the caller's, after it has subscribed.
83
+ */
84
+ export declare function createBrowserSession(options: BrowserOptions): BrowserSession;
85
+ /**
86
+ * `createBrowserSession`, with its whole session beside it, for the entry's hooks (#465): what
87
+ * only the families read (the set-up challenge, the signed-in address), never the page.
88
+ * `browser.session.close()` also takes the browser's events off.
89
+ */
90
+ export declare function createBrowserInternals(options: BrowserOptions): {
91
+ readonly browser: BrowserSession;
92
+ readonly session: AuthSession;
93
+ readonly linkDeps: SignupAttemptDeps;
94
+ };
95
+ export {};