@flipstream/sdk 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +95 -1
  3. package/dist/auth/transport.d.ts +6 -2
  4. package/dist/auth/transport.js +5 -3
  5. package/dist/auth/transport.js.map +1 -1
  6. package/dist/core/call.d.ts +4 -0
  7. package/dist/core/call.js +7 -1
  8. package/dist/core/call.js.map +1 -1
  9. package/dist/core/fetch.d.ts +20 -1
  10. package/dist/core/fetch.js +50 -3
  11. package/dist/core/fetch.js.map +1 -1
  12. package/dist/core/hosts.d.ts +11 -0
  13. package/dist/core/hosts.js +13 -0
  14. package/dist/core/hosts.js.map +1 -0
  15. package/dist/core/identify.d.ts +6 -2
  16. package/dist/core/identify.js +16 -12
  17. package/dist/core/identify.js.map +1 -1
  18. package/dist/core/result.d.ts +1 -1
  19. package/dist/core/shared.d.ts +2 -0
  20. package/dist/core/shared.js +1 -0
  21. package/dist/core/shared.js.map +1 -1
  22. package/dist/core/signal.d.ts +7 -0
  23. package/dist/core/signal.js +9 -0
  24. package/dist/core/signal.js.map +1 -1
  25. package/dist/first-party/asPerson.d.ts +13 -0
  26. package/dist/first-party/asPerson.js +144 -0
  27. package/dist/first-party/asPerson.js.map +1 -0
  28. package/dist/first-party/attempts.d.ts +71 -0
  29. package/dist/first-party/attempts.js +132 -0
  30. package/dist/first-party/attempts.js.map +1 -0
  31. package/dist/first-party/authProxyMark.d.ts +7 -0
  32. package/dist/first-party/authProxyMark.js +8 -0
  33. package/dist/first-party/authProxyMark.js.map +1 -0
  34. package/dist/first-party/browser.d.ts +55 -0
  35. package/dist/first-party/browser.js +137 -0
  36. package/dist/first-party/browser.js.map +1 -0
  37. package/dist/first-party/browserSession.d.ts +95 -0
  38. package/dist/first-party/browserSession.js +242 -0
  39. package/dist/first-party/browserSession.js.map +1 -0
  40. package/dist/first-party/calls/consent.d.ts +77 -0
  41. package/dist/first-party/calls/consent.js +174 -0
  42. package/dist/first-party/calls/consent.js.map +1 -0
  43. package/dist/first-party/calls/device.d.ts +75 -0
  44. package/dist/first-party/calls/device.js +133 -0
  45. package/dist/first-party/calls/device.js.map +1 -0
  46. package/dist/first-party/calls/invitation.d.ts +198 -0
  47. package/dist/first-party/calls/invitation.js +240 -0
  48. package/dist/first-party/calls/invitation.js.map +1 -0
  49. package/dist/first-party/calls/logIn.d.ts +41 -0
  50. package/dist/first-party/calls/logIn.js +48 -0
  51. package/dist/first-party/calls/logIn.js.map +1 -0
  52. package/dist/first-party/calls/reset.d.ts +58 -0
  53. package/dist/first-party/calls/reset.js +163 -0
  54. package/dist/first-party/calls/reset.js.map +1 -0
  55. package/dist/first-party/calls/signUp.d.ts +21 -0
  56. package/dist/first-party/calls/signUp.js +72 -0
  57. package/dist/first-party/calls/signUp.js.map +1 -0
  58. package/dist/first-party/calls/twoStepSetup.d.ts +55 -0
  59. package/dist/first-party/calls/twoStepSetup.js +168 -0
  60. package/dist/first-party/calls/twoStepSetup.js.map +1 -0
  61. package/dist/first-party/claims.d.ts +88 -0
  62. package/dist/first-party/claims.js +181 -0
  63. package/dist/first-party/claims.js.map +1 -0
  64. package/dist/first-party/enrollment.d.ts +10 -0
  65. package/dist/first-party/enrollment.js +44 -0
  66. package/dist/first-party/enrollment.js.map +1 -0
  67. package/dist/first-party/entry.d.ts +549 -0
  68. package/dist/first-party/entry.js +580 -0
  69. package/dist/first-party/entry.js.map +1 -0
  70. package/dist/first-party/hooks.d.ts +66 -0
  71. package/dist/first-party/hooks.js +19 -0
  72. package/dist/first-party/hooks.js.map +1 -0
  73. package/dist/first-party/http.d.ts +191 -0
  74. package/dist/first-party/http.js +364 -0
  75. package/dist/first-party/http.js.map +1 -0
  76. package/dist/first-party/index.d.ts +14 -0
  77. package/dist/first-party/index.js +3 -0
  78. package/dist/first-party/index.js.map +1 -0
  79. package/dist/first-party/landed.d.ts +32 -0
  80. package/dist/first-party/landed.js +50 -0
  81. package/dist/first-party/landed.js.map +1 -0
  82. package/dist/first-party/landedProof.d.ts +12 -0
  83. package/dist/first-party/landedProof.js +20 -0
  84. package/dist/first-party/landedProof.js.map +1 -0
  85. package/dist/first-party/linkToken.d.ts +16 -0
  86. package/dist/first-party/linkToken.js +29 -0
  87. package/dist/first-party/linkToken.js.map +1 -0
  88. package/dist/first-party/links.d.ts +100 -0
  89. package/dist/first-party/links.js +84 -0
  90. package/dist/first-party/links.js.map +1 -0
  91. package/dist/first-party/locks.d.ts +36 -0
  92. package/dist/first-party/locks.js +64 -0
  93. package/dist/first-party/locks.js.map +1 -0
  94. package/dist/first-party/personTransport.d.ts +38 -0
  95. package/dist/first-party/personTransport.js +177 -0
  96. package/dist/first-party/personTransport.js.map +1 -0
  97. package/dist/first-party/proxy/app.d.ts +25 -0
  98. package/dist/first-party/proxy/app.js +94 -0
  99. package/dist/first-party/proxy/app.js.map +1 -0
  100. package/dist/first-party/proxy/bound.d.ts +5 -0
  101. package/dist/first-party/proxy/bound.js +13 -0
  102. package/dist/first-party/proxy/bound.js.map +1 -0
  103. package/dist/first-party/proxy/cases.d.ts +54 -0
  104. package/dist/first-party/proxy/cases.js +412 -0
  105. package/dist/first-party/proxy/cases.js.map +1 -0
  106. package/dist/first-party/proxy/decide.d.ts +29 -0
  107. package/dist/first-party/proxy/decide.js +140 -0
  108. package/dist/first-party/proxy/decide.js.map +1 -0
  109. package/dist/first-party/proxy/freeze.d.ts +2 -0
  110. package/dist/first-party/proxy/freeze.js +10 -0
  111. package/dist/first-party/proxy/freeze.js.map +1 -0
  112. package/dist/first-party/proxy/handler.d.ts +23 -0
  113. package/dist/first-party/proxy/handler.js +190 -0
  114. package/dist/first-party/proxy/handler.js.map +1 -0
  115. package/dist/first-party/proxy/headers.d.ts +8 -0
  116. package/dist/first-party/proxy/headers.js +20 -0
  117. package/dist/first-party/proxy/headers.js.map +1 -0
  118. package/dist/first-party/proxy/hop.d.ts +9 -0
  119. package/dist/first-party/proxy/hop.js +37 -0
  120. package/dist/first-party/proxy/hop.js.map +1 -0
  121. package/dist/first-party/proxy/host.d.ts +5 -0
  122. package/dist/first-party/proxy/host.js +11 -0
  123. package/dist/first-party/proxy/host.js.map +1 -0
  124. package/dist/first-party/proxy/index.d.ts +7 -0
  125. package/dist/first-party/proxy/index.js +6 -0
  126. package/dist/first-party/proxy/index.js.map +1 -0
  127. package/dist/first-party/proxy/pass-back.d.ts +21 -0
  128. package/dist/first-party/proxy/pass-back.js +51 -0
  129. package/dist/first-party/proxy/pass-back.js.map +1 -0
  130. package/dist/first-party/proxy/paths.d.ts +17 -0
  131. package/dist/first-party/proxy/paths.js +36 -0
  132. package/dist/first-party/proxy/paths.js.map +1 -0
  133. package/dist/first-party/proxy/shown.d.ts +5 -0
  134. package/dist/first-party/proxy/shown.js +16 -0
  135. package/dist/first-party/proxy/shown.js.map +1 -0
  136. package/dist/first-party/proxy/stand-in.d.ts +47 -0
  137. package/dist/first-party/proxy/stand-in.js +318 -0
  138. package/dist/first-party/proxy/stand-in.js.map +1 -0
  139. package/dist/first-party/report.d.ts +47 -0
  140. package/dist/first-party/report.js +38 -0
  141. package/dist/first-party/report.js.map +1 -0
  142. package/dist/first-party/result.d.ts +82 -0
  143. package/dist/first-party/result.js +40 -0
  144. package/dist/first-party/result.js.map +1 -0
  145. package/dist/first-party/session/cell.d.ts +177 -0
  146. package/dist/first-party/session/cell.js +89 -0
  147. package/dist/first-party/session/cell.js.map +1 -0
  148. package/dist/first-party/session/closed.d.ts +8 -0
  149. package/dist/first-party/session/closed.js +12 -0
  150. package/dist/first-party/session/closed.js.map +1 -0
  151. package/dist/first-party/session/index.d.ts +3 -0
  152. package/dist/first-party/session/index.js +3 -0
  153. package/dist/first-party/session/index.js.map +1 -0
  154. package/dist/first-party/session/logout.d.ts +82 -0
  155. package/dist/first-party/session/logout.js +328 -0
  156. package/dist/first-party/session/logout.js.map +1 -0
  157. package/dist/first-party/session/owed.d.ts +30 -0
  158. package/dist/first-party/session/owed.js +27 -0
  159. package/dist/first-party/session/owed.js.map +1 -0
  160. package/dist/first-party/session/refresh.d.ts +19 -0
  161. package/dist/first-party/session/refresh.js +229 -0
  162. package/dist/first-party/session/refresh.js.map +1 -0
  163. package/dist/first-party/session/results.d.ts +38 -0
  164. package/dist/first-party/session/results.js +74 -0
  165. package/dist/first-party/session/results.js.map +1 -0
  166. package/dist/first-party/session/session.d.ts +2 -0
  167. package/dist/first-party/session/session.js +379 -0
  168. package/dist/first-party/session/session.js.map +1 -0
  169. package/dist/first-party/session/shared.d.ts +34 -0
  170. package/dist/first-party/session/shared.js +104 -0
  171. package/dist/first-party/session/shared.js.map +1 -0
  172. package/dist/first-party/session/sharedSignal.d.ts +27 -0
  173. package/dist/first-party/session/sharedSignal.js +55 -0
  174. package/dist/first-party/session/sharedSignal.js.map +1 -0
  175. package/dist/first-party/session/signIn.d.ts +43 -0
  176. package/dist/first-party/session/signIn.js +294 -0
  177. package/dist/first-party/session/signIn.js.map +1 -0
  178. package/dist/first-party/session/signInThrough.d.ts +5 -0
  179. package/dist/first-party/session/signInThrough.js +95 -0
  180. package/dist/first-party/session/signInThrough.js.map +1 -0
  181. package/dist/first-party/session/sync.d.ts +17 -0
  182. package/dist/first-party/session/sync.js +143 -0
  183. package/dist/first-party/session/sync.js.map +1 -0
  184. package/dist/first-party/session/tokens.d.ts +18 -0
  185. package/dist/first-party/session/tokens.js +64 -0
  186. package/dist/first-party/session/tokens.js.map +1 -0
  187. package/dist/first-party/session/types.d.ts +270 -0
  188. package/dist/first-party/session/types.js +3 -0
  189. package/dist/first-party/session/types.js.map +1 -0
  190. package/dist/first-party/sessionWire.d.ts +31 -0
  191. package/dist/first-party/sessionWire.js +91 -0
  192. package/dist/first-party/sessionWire.js.map +1 -0
  193. package/dist/first-party/signInHooks.d.ts +57 -0
  194. package/dist/first-party/signInHooks.js +2 -0
  195. package/dist/first-party/signInHooks.js.map +1 -0
  196. package/dist/first-party/state.d.ts +51 -0
  197. package/dist/first-party/state.js +52 -0
  198. package/dist/first-party/state.js.map +1 -0
  199. package/dist/first-party/strip.d.ts +1 -0
  200. package/dist/first-party/strip.js +8 -0
  201. package/dist/first-party/strip.js.map +1 -0
  202. package/dist/first-party/twoStepLock.d.ts +26 -0
  203. package/dist/first-party/twoStepLock.js +58 -0
  204. package/dist/first-party/twoStepLock.js.map +1 -0
  205. package/dist/first-party/twoStepSession.d.ts +21 -0
  206. package/dist/first-party/twoStepSession.js +31 -0
  207. package/dist/first-party/twoStepSession.js.map +1 -0
  208. package/dist/first-party/wire.d.ts +63 -0
  209. package/dist/first-party/wire.js +5 -0
  210. package/dist/first-party/wire.js.map +1 -0
  211. package/dist/flipstream.d.ts +51 -9
  212. package/dist/flipstream.js +58 -22
  213. package/dist/flipstream.js.map +1 -1
  214. package/dist/node/session.js +3 -1
  215. package/dist/node/session.js.map +1 -1
  216. package/dist/version.gen.js +1 -1
  217. package/docs/first-party.md +278 -0
  218. package/package.json +34 -5
@@ -0,0 +1,174 @@
1
+ import { z } from 'zod';
2
+ import { checkSignal } from '../../core/signal.js';
3
+ import { emptyFields, ok, stopped } from '../result.js';
4
+ import { isUnavailable } from '../wire.js';
5
+ const PATH = '/oauth/authorize';
6
+ function absoluteUrl(value) {
7
+ try {
8
+ return new URL(value);
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
14
+ // oauth_internal/__init__.py:1931-1983. Only the callback itself identifies the host on screen.
15
+ function readAddress(href) {
16
+ const page = absoluteUrl(href);
17
+ if (page === null)
18
+ return null;
19
+ const query = page.searchParams;
20
+ const client_id = query.get('client_id') ?? '';
21
+ const redirect_uri = query.get('redirect_uri') ?? '';
22
+ const scope = query.get('scope') ?? '';
23
+ if (emptyFields({ client_id, redirect_uri, scope }, ['client_id', 'redirect_uri', 'scope']).length > 0)
24
+ return null;
25
+ // Check the raw authority before URL normalizes whitespace, slashes or empty userinfo.
26
+ const authority = /^https?:\/\/([^/?#]+)/i.exec(redirect_uri)?.[1];
27
+ if (!authority || authority.includes('@') || /[\\\s\p{Cc}]/u.test(redirect_uri))
28
+ return null;
29
+ const redirect = absoluteUrl(redirect_uri);
30
+ if (redirect === null || (redirect.protocol !== 'https:' && redirect.protocol !== 'http:') || redirect_uri.includes('#'))
31
+ return null;
32
+ const optional = {};
33
+ for (const key of ['state', 'code_challenge', 'code_challenge_method', 'resource']) {
34
+ const value = query.get(key);
35
+ if (value !== null)
36
+ optional[key] = value;
37
+ }
38
+ return {
39
+ request: Object.freeze({ kind: 'asking', client_id, redirect_host: redirect.host, scopes: Object.freeze(scope.split(' ').filter(Boolean)) }),
40
+ fields: { client_id, redirect_uri, scope, ...optional },
41
+ };
42
+ }
43
+ const invalidRequest = Object.freeze({ kind: 'invalid' });
44
+ export function readConsentRequest(href) {
45
+ return readAddress(href)?.request ?? invalidRequest;
46
+ }
47
+ // oauth/ingress/fastapi/__init__.py:315-331, 689-716. Both presses send consent explicitly.
48
+ export function consentPost(fields, consent) {
49
+ return { method: 'POST', path: PATH, body: { ...fields, consent } };
50
+ }
51
+ const Redirect = z.object({ redirect_url: z.string() });
52
+ const UnknownClient = z.object({ error: z.enum(['invalid_request', 'invalid_client']) });
53
+ export function readConsentAnswer(answer, fields, consent) {
54
+ // oauth_internal/__init__.py:587-596 checks the client and its registered callback.
55
+ if (answer.status === 400 && UnknownClient.safeParse(answer.body).success)
56
+ return stopped({ kind: 'unknown_client' });
57
+ if (isUnavailable(answer))
58
+ return stopped({ kind: 'unavailable' });
59
+ const invalid = stopped({ kind: 'invalid' });
60
+ if (answer.status !== 200)
61
+ return invalid;
62
+ const parsed = Redirect.safeParse(answer.body);
63
+ if (!parsed.success)
64
+ return invalid;
65
+ const url = absoluteUrl(parsed.data.redirect_url);
66
+ const target = absoluteUrl(fields.redirect_uri);
67
+ if (url === null || target === null || url.origin !== target.origin || url.pathname !== target.pathname)
68
+ return invalid;
69
+ // oauth_internal/__init__.py:602-681 appends '?' even to a callback with a query.
70
+ // Its last field then absorbs the response and a pre-existing code could look newly issued.
71
+ if (target.search !== '' && url.search.startsWith(target.search + '?'))
72
+ return invalid;
73
+ // oauth_internal/__init__.py:602,608,645,655,681 echoes state on every redirect.
74
+ const states = url.searchParams.getAll('state');
75
+ if (fields.state !== undefined && (states.length !== 1 || states[0] !== fields.state))
76
+ return invalid;
77
+ const codes = url.searchParams.getAll('code');
78
+ const errors = url.searchParams.getAll('error');
79
+ const redirect = { redirect_to: parsed.data.redirect_url };
80
+ if (errors.length === 0) {
81
+ // oauth_internal/__init__.py:657-681 issues exactly one code after approval.
82
+ return consent && codes.length === 1 && codes[0]?.trim() ? ok(redirect) : invalid;
83
+ }
84
+ if (codes.length !== 0 || errors.length !== 1)
85
+ return invalid;
86
+ switch (errors[0]) {
87
+ case 'access_denied': return consent ? invalid : ok(redirect); // oauth_internal/__init__.py:600-602
88
+ case 'login_required': return consent ? stopped({ kind: 'signed_out' }) : invalid; // oauth_internal/__init__.py:604-608
89
+ case 'invalid_scope': return stopped({ kind: 'invalid_scope' }); // oauth_internal/__init__.py:640-645
90
+ case 'invalid_target': return stopped({ kind: 'invalid_target' }); // oauth_internal/__init__.py:647-655
91
+ default: return invalid;
92
+ }
93
+ }
94
+ export function createConsentCalls(wire, href, shownRevision) {
95
+ // Bind each view to the exact parameters it showed, even across a later read of the address.
96
+ const shown = new WeakMap();
97
+ let owner;
98
+ let taken = new Set();
99
+ async function send(request, consent, options) {
100
+ const fields = shown.get(request);
101
+ const call = consent ? 'approveConsent' : 'denyConsent';
102
+ if (fields === undefined)
103
+ throw new TypeError(call + '() takes the request consentRequest() returned, as it is');
104
+ checkSignal(call, options);
105
+ if (options?.signal?.aborted)
106
+ return stopped({ kind: 'aborted' });
107
+ const revision = shownRevision();
108
+ if (revision === 'signed_out')
109
+ return stopped({ kind: 'signed_out' });
110
+ if (revision !== undefined && revision !== owner) {
111
+ taken = new Set();
112
+ owner = revision;
113
+ }
114
+ const key = JSON.stringify([fields.client_id, fields.redirect_uri, fields.state, fields.code_challenge,
115
+ fields.code_challenge_method, fields.resource, fields.scope]);
116
+ // A later sign-in has its own set, even if an earlier press is still settling.
117
+ const reservations = revision === undefined ? undefined : taken;
118
+ if (reservations?.has(key))
119
+ return stopped({ kind: 'answered' });
120
+ reservations?.add(key);
121
+ let keepReservation = false;
122
+ const onSend = () => { keepReservation = true; };
123
+ try {
124
+ const answer = await wire.asPerson(consentPost(fields, consent), options, consent ? {
125
+ onSend,
126
+ isUnauthorized(reply) {
127
+ const result = readConsentAnswer(reply, fields, true);
128
+ if (result.ok || result.error.kind !== 'signed_out')
129
+ return false;
130
+ // The anonymous request did nothing. Keep the reservation until the replay settles.
131
+ keepReservation = false;
132
+ return true;
133
+ },
134
+ } : { onSend });
135
+ if (answer.kind !== 'answer')
136
+ return stopped(answer);
137
+ const result = readConsentAnswer(answer, fields, consent);
138
+ if (!result.ok) {
139
+ switch (result.error.kind) {
140
+ case 'unknown_client':
141
+ case 'invalid_scope':
142
+ case 'invalid_target':
143
+ case 'signed_out': // A checked login_required on approve. Neither a code nor a denial was issued.
144
+ keepReservation = false;
145
+ break;
146
+ case 'unavailable':
147
+ if (answer.status === 429)
148
+ keepReservation = false;
149
+ break;
150
+ case 'invalid':
151
+ wire.report({ path: PATH, status: answer.status });
152
+ break;
153
+ }
154
+ }
155
+ return result;
156
+ }
157
+ finally {
158
+ if (!keepReservation)
159
+ reservations?.delete(key);
160
+ }
161
+ }
162
+ return {
163
+ consentRequest() {
164
+ const read = readAddress(href());
165
+ if (read === null)
166
+ return invalidRequest;
167
+ shown.set(read.request, read.fields);
168
+ return read.request;
169
+ },
170
+ approveConsent: (request, options) => send(request, true, options),
171
+ denyConsent: (request, options) => send(request, false, options),
172
+ };
173
+ }
174
+ //# sourceMappingURL=consent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.js","sourceRoot":"","sources":["../../../src/first-party/calls/consent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAA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,OAAO,CAAA;QACrB,CAAC;QACD,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;QAClE,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;KACjE,CAAA;AACH,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type AsPerson, type CallOptions, type Refused, type Result, type Sent } from '../result.js';
2
+ import { type Wire, type WireAnswer, type WireRequest } from '../wire.js';
3
+ /** The request a device made, as pulse-auth holds it: what the person is asked to approve. */
4
+ export interface DeviceRequest {
5
+ /** As pulse-auth formats it. */
6
+ readonly user_code: string;
7
+ /** The OAuth client the device signs in to. */
8
+ readonly client_id: string;
9
+ /**
10
+ * The name the client declares for itself: for a client registered by metadata document or
11
+ * dynamically, nobody has checked it, so show `client_id` beside it. Null when pulse-auth can't
12
+ * resolve the client.
13
+ */
14
+ readonly client_name: string | null;
15
+ /** What the device asks to be allowed, as pulse-auth names it. */
16
+ readonly scopes: readonly string[];
17
+ /** When the code runs out, epoch ms. */
18
+ readonly expires_at: number;
19
+ }
20
+ /** What stops a look-up. */
21
+ export type DeviceStop =
22
+ /** The code is unknown, expired or already used: pulse-auth says one thing for all three. */
23
+ {
24
+ readonly kind: 'unknown_code';
25
+ }
26
+ /** This request was already denied. Only a look-up says so. */
27
+ | {
28
+ readonly kind: 'already_denied';
29
+ };
30
+ /** What stops an approval or a denial. */
31
+ export type DeviceAnswerStop =
32
+ /**
33
+ * The code is unknown, expired or already used: pulse-auth says one thing for all three. A press
34
+ * on it would be sent again, but pulse-auth no longer holds the code: ask the device for a new one.
35
+ */
36
+ {
37
+ readonly kind: 'unknown_code';
38
+ }
39
+ /**
40
+ * A press from this page on this code (looked up again included) is still out, or may already
41
+ * have acted on it, for the person signed in now. Nothing was sent. Once the first settles, a
42
+ * press is sent again if nothing was sent, or after a 429, which arrives as `unavailable`. After
43
+ * a sent press ends as `signed_out`, `aborted`, `invalid` or any other `unavailable`, another
44
+ * press answers `answered`, and a fresh look-up doesn't change that: only signing in again lets
45
+ * a press be sent.
46
+ */
47
+ | {
48
+ readonly kind: 'answered';
49
+ };
50
+ export interface DeviceCalls {
51
+ readonly lookUpDevice: (request: {
52
+ readonly user_code: string;
53
+ }, options?: CallOptions) => Promise<Result<DeviceRequest, Sent | Refused | DeviceStop>>;
54
+ readonly approveDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
55
+ readonly kind: 'approved';
56
+ }, AsPerson | DeviceAnswerStop>>;
57
+ readonly denyDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
58
+ readonly kind: 'denied';
59
+ }, AsPerson | DeviceAnswerStop>>;
60
+ }
61
+ export declare function deviceLookupRequest(input: {
62
+ readonly user_code: string;
63
+ }): WireRequest | Refused;
64
+ export declare function deviceAnswerRequest(device: DeviceRequest, consent: boolean): WireRequest;
65
+ export declare function readDeviceLookup(answer: WireAnswer): Result<DeviceRequest, Sent | DeviceStop>;
66
+ type Decision = 'approved' | 'denied';
67
+ export declare function readDeviceAnswer<D extends Decision>(answer: WireAnswer, expected: D): Result<{
68
+ readonly kind: D;
69
+ }, Sent | DeviceAnswerStop>;
70
+ /**
71
+ * `signedIn` is the revision the page shows, or undefined when nobody is signed in: read at the
72
+ * press, as the wire pins the person there.
73
+ */
74
+ export declare function createDeviceCalls(wire: Pick<Wire, 'open' | 'asPerson' | 'report'>, signedIn: () => number | undefined): DeviceCalls;
75
+ export {};
@@ -0,0 +1,133 @@
1
+ // Device sign-in (sdk#471): a device shows a code; the person types it on an account page, sees the
2
+ // request, and approves or denies it. The look-up is open and the answer goes as the person, both
3
+ // straight to pulse-auth (SDK-D595). Rows written from source cite pulse-auth f3bf89c (SDK-D593).
4
+ import { z } from 'zod';
5
+ import { instant } from '../../api/time.js';
6
+ import { checkSignal } from '../../core/signal.js';
7
+ import { emptyFields, ok, stopped } from '../result.js';
8
+ import { isUnavailable } from '../wire.js';
9
+ const LOOKUP = '/oauth/device/verify';
10
+ const PRESS = '/oauth/device/approve';
11
+ export function deviceLookupRequest(input) {
12
+ const fields = emptyFields(input, ['user_code']);
13
+ if (fields.length > 0)
14
+ return { kind: 'refused', reason: 'empty', fields };
15
+ // oauth/ingress/fastapi/__init__.py:879-887. The service formats the code, so it goes as typed.
16
+ return { path: LOOKUP, method: 'GET', query: { user_code: input.user_code } };
17
+ }
18
+ export function deviceAnswerRequest(device, consent) {
19
+ // oauth/ingress/fastapi/__init__.py:307-312,889-903. A missing consent means true: always sent.
20
+ return { path: PRESS, method: 'POST', body: { user_code: device.user_code, consent } };
21
+ }
22
+ const ErrorBody = z.object({ error: z.string() });
23
+ const LookupBody = z.object({
24
+ user_code: z.string().min(1),
25
+ client_id: z.string().min(1),
26
+ client_name: z.string().transform((name) => (name === '' ? null : name)),
27
+ scopes: z.array(z.string()).readonly(),
28
+ // oauth_internal/__init__.py:782-783,834: the stored UTC time, microseconds included.
29
+ expires_at: instant.pipe(z.coerce.date()).transform((value) => value.getTime()),
30
+ }).readonly();
31
+ function errorCode(answer) {
32
+ if (answer.status !== 400)
33
+ return undefined;
34
+ return ErrorBody.safeParse(answer.body).data?.error;
35
+ }
36
+ export function readDeviceLookup(answer) {
37
+ if (answer.status === 200) {
38
+ // oauth_internal/__init__.py:819-835. An unresolved client has an empty name.
39
+ const parsed = LookupBody.safeParse(answer.body);
40
+ return parsed.success ? ok(parsed.data) : stopped({ kind: 'invalid' });
41
+ }
42
+ switch (errorCode(answer)) {
43
+ case 'invalid_grant':
44
+ return stopped({ kind: 'unknown_code' }); // oauth_internal/__init__.py:811-815
45
+ case 'access_denied':
46
+ return stopped({ kind: 'already_denied' }); // oauth_internal/__init__.py:816-817
47
+ default:
48
+ return stopped({ kind: isUnavailable(answer) ? 'unavailable' : 'invalid' });
49
+ }
50
+ }
51
+ export function readDeviceAnswer(answer, expected) {
52
+ // oauth_internal/__init__.py:859-874. Only the decision pressed confirms it.
53
+ if (answer.status === 200 && z.object({ status: z.literal(expected) }).safeParse(answer.body).success) {
54
+ return ok({ kind: expected });
55
+ }
56
+ if (errorCode(answer) === 'invalid_grant')
57
+ return stopped({ kind: 'unknown_code' }); // oauth_internal/__init__.py:852-856
58
+ // oauth_internal/__init__.py:848-851 answers access_denied on this route for a missing person: the
59
+ // wire sent one, so it is outside the contract.
60
+ return stopped({ kind: isUnavailable(answer) ? 'unavailable' : 'invalid' });
61
+ }
62
+ /**
63
+ * `signedIn` is the revision the page shows, or undefined when nobody is signed in: read at the
64
+ * press, as the wire pins the person there.
65
+ */
66
+ export function createDeviceCalls(wire, signedIn) {
67
+ // Only a request this session's look-up answered (frozen, SDK-D1922) can be answered: a copy, a
68
+ // forged one or another session's could approve a device the person never saw.
69
+ const shown = new WeakSet();
70
+ // One answer per code from this page, for one signed-in person (sdk#536 S2, K1, K2): pulse-auth
71
+ // f3bf89c's device_approve checks no earlier answer (oauth_internal/__init__.py:837-874), so a
72
+ // deny then an approve would answer `approved` while the device's poll is refused. A grant is
73
+ // its user_code, as pulse-auth formats it, so two look-ups of one code share one take. A press
74
+ // takes the code at once, for the revision shown then. It gives it back when it ended before its
75
+ // dispatch, or pulse-auth answered 429 or its unknown, expired or used code answer (sdk#539): each
76
+ // proves nothing was done. Any other press that went out may have acted (S1), so the code stays
77
+ // taken, and a press on it answers `answered`, until another person is signed in.
78
+ const taken = new Map();
79
+ async function answer(name, device, expected, options) {
80
+ if (!shown.has(device))
81
+ throw new TypeError(`${name}() takes the request lookUpDevice() answered on this session`);
82
+ checkSignal(name, options);
83
+ if (options?.signal?.aborted === true)
84
+ return stopped({ kind: 'aborted' });
85
+ const revision = signedIn();
86
+ const held = taken.get(device.user_code);
87
+ if (held !== undefined && held.revision === revision)
88
+ return stopped({ kind: 'answered' });
89
+ const take = { revision };
90
+ taken.set(device.user_code, take);
91
+ let doneNothing = true;
92
+ try {
93
+ const sent = await wire.asPerson(deviceAnswerRequest(device, expected === 'approved'), options, { onSend: () => { doneNothing = false; } });
94
+ if (sent.kind !== 'answer')
95
+ return stopped(sent);
96
+ if (sent.status === 429)
97
+ doneNothing = true;
98
+ const result = readDeviceAnswer(sent, expected);
99
+ if (!result.ok && result.error.kind === 'unknown_code')
100
+ doneNothing = true;
101
+ if (!result.ok && result.error.kind === 'invalid')
102
+ wire.report({ path: PRESS, status: sent.status });
103
+ return result;
104
+ }
105
+ finally {
106
+ // Only this press's own take: a press for a later person may have taken the code since.
107
+ if (doneNothing && taken.get(device.user_code) === take)
108
+ taken.delete(device.user_code);
109
+ }
110
+ }
111
+ return {
112
+ async lookUpDevice(input, options) {
113
+ checkSignal('lookUpDevice', options);
114
+ const request = deviceLookupRequest(input);
115
+ if ('kind' in request)
116
+ return stopped(request);
117
+ if (options?.signal?.aborted === true)
118
+ return stopped({ kind: 'aborted' });
119
+ const sent = await wire.open('auth', request, options);
120
+ if (sent.kind !== 'answer')
121
+ return stopped(sent);
122
+ const result = readDeviceLookup(sent);
123
+ if (result.ok)
124
+ shown.add(result.data);
125
+ else if (result.error.kind === 'invalid')
126
+ wire.report({ path: LOOKUP, status: sent.status });
127
+ return result;
128
+ },
129
+ approveDevice: (device, options) => answer('approveDevice', device, 'approved', options),
130
+ denyDevice: (device, options) => answer('denyDevice', device, 'denied', options),
131
+ };
132
+ }
133
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../../../src/first-party/calls/device.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,kGAAkG;AAClG,kGAAkG;AAClG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAyE,MAAM,cAAc,CAAA;AAC9H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aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC;QACxF,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC;KACjF,CAAA;AACH,CAAC"}
@@ -0,0 +1,198 @@
1
+ import type { SignInStep } from '../hooks.js';
2
+ import type { LandedTokens } from '../landed.js';
3
+ import { type CallOptions, type Refused, type Result, type Sent, type ThroughProxy } from '../result.js';
4
+ import type { SignInHooks } from '../signInHooks.js';
5
+ import { type Wire, type WireAnswer, type WireRequest } from '../wire.js';
6
+ /** Whether the page was opened with an invitation's token. Nothing sent. */
7
+ export type OpenedInvitation = {
8
+ readonly kind: 'ready';
9
+ } | {
10
+ readonly kind: 'no_token';
11
+ };
12
+ /**
13
+ * What pulse-auth tells about a usable invitation. It gives no member-or-guest kind and no
14
+ * workspace (pulse-auth#51 is open), so the page works from `roles` and `app_name`.
15
+ */
16
+ export interface InvitationShown {
17
+ /**
18
+ * The organisation the person joins; '' when pulse-auth could not read its name, or its
19
+ * deployment doesn't say (the hook that adds it is optional).
20
+ */
21
+ readonly organization_name: string;
22
+ /** The deployment's own name, as pulse-auth calls itself. */
23
+ readonly app_name: string;
24
+ /** The roles the account is made with. */
25
+ readonly roles: readonly string[];
26
+ /** null when this deployment has no privacy policy to accept. */
27
+ readonly privacy_policy_url: string | null;
28
+ /**
29
+ * Where pulse-auth says this invitation goes on to after the accept; null when it names no app.
30
+ * It sets the three together or not at all. `name`: what to call it ("Pulse"). `url`: the SDK
31
+ * sends it back with the accept, and pulse-auth answers with a fresh link into that page, the
32
+ * result's `continue_to`. `login_url`: that app's own sign-in page, for when `continue_to` is
33
+ * null.
34
+ */
35
+ readonly continue: {
36
+ readonly name: string;
37
+ readonly url: string;
38
+ readonly login_url: string;
39
+ } | null;
40
+ }
41
+ /**
42
+ * It names its recipient: mailed to that address, or handed over as a link made for it. The
43
+ * account is made for `email`, whatever anyone types.
44
+ */
45
+ export interface PersonalInvitation extends InvitationShown {
46
+ /** It names its recipient. */
47
+ readonly kind: 'personal';
48
+ /** The address it names, as pulse-auth holds it. */
49
+ readonly email: string;
50
+ }
51
+ /** It names nobody: whoever opens the link gives their own address and a password. */
52
+ export interface SharedInvitation extends InvitationShown {
53
+ /** It names nobody. */
54
+ readonly kind: 'shared';
55
+ }
56
+ /** What `previewInvitation` answers: narrow on `kind` before `acceptInvitation`. */
57
+ export type Invitation = PersonalInvitation | SharedInvitation;
58
+ /** What every accept gives. pulse-auth refuses an accept without both names (a 400). */
59
+ export interface AcceptEntry {
60
+ /** Required: an empty one is `refused`. */
61
+ readonly first_name: string;
62
+ /** Required: an empty one is `refused`. */
63
+ readonly last_name: string;
64
+ /** Must be true when the invitation has a `privacy_policy_url`. */
65
+ readonly privacy_policy_accepted: boolean;
66
+ }
67
+ /**
68
+ * In every arm the account exists, and this page is done with the invitation (spent, unless it
69
+ * allows more than one use). The two two-step arms come where
70
+ * the deployment requires two-step: the sign-in goes on as after `logIn` (a `two_step_setup`'s
71
+ * `setup` goes to `startSignInTwoStepSetup`), and pulse-auth gives no fresh link then.
72
+ */
73
+ export type Accepted = {
74
+ readonly kind: 'signed_in';
75
+ /** pulse-auth's fresh link into the app the invitation is for, or null. */
76
+ readonly continue_to: string | null;
77
+ } | Exclude<SignInStep, {
78
+ readonly kind: 'signed_in';
79
+ }>;
80
+ /**
81
+ * Why `acceptInvitation` didn't sign the person in or ask for a code. After `unavailable`,
82
+ * pulse-auth may already have made the account and used the invitation: nothing says so, so
83
+ * `openedInvitation()` stays `ready`. After `aborted` once the accept was sent, the request goes
84
+ * on: `openedInvitation()` reads `ready` while it is out, then `no_token` if pulse-auth answered
85
+ * it a 2xx or `dead_link`, and `ready` otherwise. While it stays `ready` the account may already
86
+ * exist: a later `dead_link` then means "log in", with the password or by a login link.
87
+ */
88
+ export type AcceptStop = ThroughProxy | Refused
89
+ /**
90
+ * The invitation is unknown, revoked, expired or spent: pulse-auth says one thing for all. It
91
+ * also covers an invitation edited to another address since this link was sent: ask for it to
92
+ * be sent again. After an earlier `unavailable`, or an abort after the send that left the token,
93
+ * the account may already exist: then log in, with the password or by a login link. A second
94
+ * press with a different entry while one is out is its own attempt (SDK-D1908), and can find the
95
+ * invitation used (sdk#549).
96
+ */
97
+ | {
98
+ readonly kind: 'dead_link';
99
+ } | {
100
+ readonly kind: 'privacy_policy_required';
101
+ }
102
+ /**
103
+ * The invitation was edited after it was previewed, and now needs an address or a password this
104
+ * call didn't carry. Preview it again.
105
+ */
106
+ | {
107
+ readonly kind: 'changed';
108
+ }
109
+ /** pulse-auth wants at least 8 characters, for any password given here. */
110
+ | {
111
+ readonly kind: 'password_too_short';
112
+ }
113
+ /** The address already has an account: log in first. */
114
+ | {
115
+ readonly kind: 'account_exists';
116
+ }
117
+ /**
118
+ * A sign-in or sign-out, in any tab, came after the press; read `current()`. Before the send
119
+ * nothing was sent; after it, pulse-auth's answer would have signed in (that session is revoked)
120
+ * or asked for a code (dropped): the account exists, and `openedInvitation()` reads `no_token`.
121
+ */
122
+ | {
123
+ readonly kind: 'superseded';
124
+ };
125
+ /** A personal accept: no address (the invitation's own wins), a password only if one is given. */
126
+ export type PersonalAcceptEntry = AcceptEntry & {
127
+ readonly password?: string;
128
+ };
129
+ /** A shared accept: an address and a password, both required. */
130
+ export type SharedAcceptEntry = AcceptEntry & {
131
+ readonly email: string;
132
+ readonly password: string;
133
+ };
134
+ /**
135
+ * Accepting signs the person in. Two forms, one per kind, so a caller narrows on
136
+ * `invitation.kind` first and a wrong call doesn't compile.
137
+ */
138
+ export interface AcceptInvitation {
139
+ /** A personal invitation: no address (its own wins); without a password, sign-in by link only. */
140
+ (invitation: PersonalInvitation, entry: PersonalAcceptEntry, options?: CallOptions): Promise<Result<Accepted, AcceptStop>>;
141
+ /** A shared invitation: the person's own address and a password, both required. */
142
+ (invitation: SharedInvitation, entry: SharedAcceptEntry, options?: CallOptions): Promise<Result<Accepted, AcceptStop>>;
143
+ }
144
+ /** Either form's entry, as the one implementation takes it. */
145
+ export type EitherAcceptEntry = AcceptEntry & {
146
+ readonly email?: string;
147
+ readonly password?: string;
148
+ };
149
+ /** What the calls need from the session beyond the wire. */
150
+ export interface InvitationSession {
151
+ readonly landedToken: LandedTokens['token'];
152
+ readonly forgetLanded: LandedTokens['forget'];
153
+ readonly signInThrough: SignInHooks['signInThrough'];
154
+ }
155
+ export declare function previewRequest(token: string): WireRequest;
156
+ export declare function readPreview(answer: WireAnswer): Result<Invitation, Sent | {
157
+ readonly kind: 'dead_link';
158
+ }>;
159
+ /**
160
+ * The accept's request, or why nothing is sent. Empty names, and a shared accept's empty address
161
+ * or password, are `refused`; a policy not accepted is `privacy_policy_required`.
162
+ */
163
+ export declare function acceptRequest(invitation: Invitation, entry: EitherAcceptEntry, token: string): Result<{
164
+ request: WireRequest;
165
+ email: string;
166
+ }, Refused | {
167
+ readonly kind: 'privacy_policy_required';
168
+ }>;
169
+ /**
170
+ * An accept's answer that is not a 2xx, for the invitation as it was previewed. pulse-auth reads its
171
+ * privacy setting live (hooks.py:98-99): its refusal to one previewed without a policy means the
172
+ * deployment changed since, so preview again.
173
+ */
174
+ export declare function acceptRefusal(answer: WireAnswer, previewed: Pick<InvitationShown, 'privacy_policy_url'>): AcceptStop;
175
+ /**
176
+ * The accept's `continue_link` (routes.py:47-53): '' or absent is null. One that is not an http or
177
+ * https link on the sent `continue_url`'s origin, with no username or password, is outside the
178
+ * contract: null, and reported.
179
+ */
180
+ export declare function continueTo(extra: Readonly<Record<string, unknown>>, sent: string | null): {
181
+ readonly kind: 'link';
182
+ readonly to: string | null;
183
+ } | {
184
+ readonly kind: 'outside';
185
+ };
186
+ export declare function createInvitationCalls(wire: Pick<Wire, 'open' | 'report'>, session: InvitationSession): {
187
+ openedInvitation: () => Readonly<{
188
+ readonly kind: "no_token";
189
+ }> | Readonly<{
190
+ readonly kind: "ready";
191
+ }>;
192
+ previewInvitation(opened: Extract<OpenedInvitation, {
193
+ readonly kind: "ready";
194
+ }>, options?: CallOptions): Promise<Result<Invitation, Sent | {
195
+ readonly kind: "dead_link";
196
+ }>>;
197
+ acceptInvitation: (invitation: Invitation, entry: EitherAcceptEntry, options?: CallOptions) => Promise<Result<Accepted, AcceptStop>>;
198
+ };