@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,341 @@
1
+ /** This entry is Node only. It holds the stand-in and the dev and preview handler. */
2
+ import { createServer, request as send } from 'node:http';
3
+ import { requireDelay } from './bound.js';
4
+ import { requestHost } from './host.js';
5
+ import { shown } from './shown.js';
6
+ export { AUTH_PROXY_COOKIES } from './paths.js';
7
+ export { authProxyHandler } from './handler.js';
8
+ const EMPTY = { status: 204, headers: [] };
9
+ function copyHeaders(headers) {
10
+ const copy = {};
11
+ for (const [name, value] of Object.entries(headers)) {
12
+ if (typeof value === 'string')
13
+ copy[name] = value;
14
+ else if (value !== undefined)
15
+ copy[name] = Object.freeze([...value]);
16
+ }
17
+ return Object.freeze(copy);
18
+ }
19
+ function readBody(request) {
20
+ return new Promise((resolve, reject) => {
21
+ const chunks = [];
22
+ request.on('data', (chunk) => chunks.push(chunk));
23
+ request.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
24
+ request.on('error', reject);
25
+ });
26
+ }
27
+ function valuesOf(value) {
28
+ if (value === undefined)
29
+ return [];
30
+ return typeof value === 'string' ? [value] : value;
31
+ }
32
+ function headerOf(headers, name) {
33
+ const key = Object.keys(headers).find((each) => each.toLowerCase() === name.toLowerCase());
34
+ return key === undefined ? undefined : headers[key];
35
+ }
36
+ /** The cookies in one `Cookie` header. A name that arrives twice is listed again. */
37
+ function readCookies(header) {
38
+ if (header === undefined)
39
+ return { map: {}, repeated: [] };
40
+ const text = typeof header === 'string' ? header : header.join('; ');
41
+ const map = {};
42
+ const repeated = [];
43
+ for (const part of text.split(';')) {
44
+ const pair = part.trim();
45
+ if (pair === '')
46
+ continue;
47
+ const equals = pair.indexOf('=');
48
+ if (equals <= 0)
49
+ continue;
50
+ const name = pair.slice(0, equals);
51
+ if (Object.hasOwn(map, name))
52
+ repeated.push(name);
53
+ map[name] = pair.slice(equals + 1);
54
+ }
55
+ return { map, repeated };
56
+ }
57
+ function bodyOf(kind) {
58
+ if (kind === 'json')
59
+ return '{}';
60
+ if (kind === 'form')
61
+ return 'a=1';
62
+ return '';
63
+ }
64
+ function judged(row, outcome, arrivals, answer) {
65
+ const found = [];
66
+ if (answer.status !== outcome.answer.status)
67
+ found.push(`status is ${answer.status}, the row says ${outcome.answer.status}`);
68
+ for (const [name, expected] of Object.entries(outcome.answer.headers)) {
69
+ const actual = valuesOf(headerOf(answer.headers, name));
70
+ if (name.toLowerCase() === 'set-cookie') {
71
+ if (actual.length !== 1 || actual[0] !== expected)
72
+ found.push(`set-cookie is ${actual.join(' | ') || 'absent'}, the row says ${expected}`);
73
+ continue;
74
+ }
75
+ if (actual.length !== 1 || actual[0] !== expected)
76
+ found.push(`header ${name} is ${actual[0] ?? 'absent'}, the row says ${expected}`);
77
+ }
78
+ for (const name of outcome.answer.absent) {
79
+ if (valuesOf(headerOf(answer.headers, name)).length > 0)
80
+ found.push(`header ${name} is present, the row says it is absent`);
81
+ }
82
+ if (outcome.upstream === null) {
83
+ if (arrivals.length > 0)
84
+ found.push('the stand-in was called, the row says nothing is forwarded');
85
+ return found;
86
+ }
87
+ if (arrivals.length !== 1) {
88
+ found.push(`the stand-in saw ${arrivals.length} requests, the row says one`);
89
+ return found;
90
+ }
91
+ const arrival = arrivals[0];
92
+ if (arrival === undefined)
93
+ return found;
94
+ const url = arrival.url;
95
+ const queryAt = url.indexOf('?');
96
+ const path = queryAt === -1 ? url : url.slice(0, queryAt);
97
+ const query = queryAt === -1 ? '' : url.slice(queryAt + 1);
98
+ if (path !== outcome.upstream)
99
+ found.push(`path is ${path}, the row says ${outcome.upstream}`);
100
+ if (query !== '')
101
+ found.push(`query is ${query}, the row says it is empty`);
102
+ const cookies = readCookies(headerOf(arrival.headers, 'cookie'));
103
+ for (const name of cookies.repeated)
104
+ found.push(`cookie ${name} arrived more than once`);
105
+ const wanted = Object.entries(row.expect.cookies);
106
+ for (const [name, value] of wanted) {
107
+ if (cookies.map[name] !== value)
108
+ found.push(`cookie ${name} is ${cookies.map[name] ?? 'absent'}, the row says ${value}`);
109
+ }
110
+ for (const name of Object.keys(cookies.map)) {
111
+ if (!wanted.some(([wantedName]) => wantedName === name))
112
+ found.push(`cookie ${name} arrived, the row does not name it`);
113
+ }
114
+ for (const name of row.expect.absent) {
115
+ if (valuesOf(headerOf(arrival.headers, name)).length > 0)
116
+ found.push(`header ${name} arrived, the row says it is absent`);
117
+ }
118
+ for (const [name, forbidden] of Object.entries(row.expect.not_as_sent)) {
119
+ const actual = valuesOf(headerOf(arrival.headers, name));
120
+ if (actual.some((value) => value === forbidden))
121
+ found.push(`header ${name} arrived as the browser sent it`);
122
+ }
123
+ const body = bodyOf(row.request.body);
124
+ if (arrival.body !== body)
125
+ found.push(`body is ${JSON.stringify(arrival.body)}, the row says ${JSON.stringify(body)}`);
126
+ return found;
127
+ }
128
+ /**
129
+ * The 400 a front server may give for a target holding `#`, or undefined when this row has no
130
+ * such outcome. Nothing may be forwarded. The headers stay the row's.
131
+ */
132
+ function frontServer400(row, arrivals, answer) {
133
+ if (row.upstream !== null || row.expect.answer.status !== 404 || !row.request.path.includes('#'))
134
+ return undefined;
135
+ return judged(row, { upstream: null, answer: { status: 400, headers: row.expect.answer.headers, absent: row.expect.answer.absent } }, arrivals, answer);
136
+ }
137
+ /**
138
+ * The first outcome, or the second when the first does not hold. When neither holds, both are
139
+ * named. A target holding `#` that already expects 404 with nothing forwarded also holds on a
140
+ * 400 with nothing forwarded. When that fails too, the report names it `front-server 400`, and
141
+ * the first outcome is named too, even when the row has no second outcome.
142
+ */
143
+ function mismatches(row, arrivals, answer) {
144
+ const first = judged(row, { upstream: row.upstream, answer: row.expect.answer }, arrivals, answer);
145
+ if (first.length === 0)
146
+ return first;
147
+ const second = row.or === undefined ? undefined : judged(row, row.or, arrivals, answer);
148
+ if (second !== undefined && second.length === 0)
149
+ return second;
150
+ const front = frontServer400(row, arrivals, answer);
151
+ if (front !== undefined && front.length === 0)
152
+ return [];
153
+ const named = second !== undefined || front !== undefined;
154
+ const lines = named
155
+ ? [...first.map((line) => `first outcome: ${line}`), ...(second === undefined ? [] : second.map((line) => `second outcome: ${line}`))]
156
+ : [...first];
157
+ if (front === undefined)
158
+ return lines;
159
+ return [...lines, ...front.map((line) => `front-server 400: ${line}`)];
160
+ }
161
+ /**
162
+ * Listen on 127.0.0.1 for what a proxy forwards. Before any `answerWith`, the answer is 204 with
163
+ * no headers. The body is always empty. Node may still add `Connection` on the way out.
164
+ */
165
+ export function startAuthStandIn() {
166
+ const seen = [];
167
+ let pending = EMPTY;
168
+ const server = createServer((request, response) => {
169
+ void readBody(request)
170
+ .then((body) => {
171
+ seen.push(Object.freeze({ method: request.method ?? 'GET', url: request.url ?? '', headers: copyHeaders(request.headers), body }));
172
+ const answer = pending;
173
+ response.sendDate = false;
174
+ response.writeHead(answer.status, grouped(answer.headers));
175
+ response.end();
176
+ })
177
+ .catch((error) => {
178
+ response.destroy(error instanceof Error ? error : new Error('the stand-in could not read the request'));
179
+ });
180
+ });
181
+ return new Promise((resolve, reject) => {
182
+ server.once('error', reject);
183
+ server.listen({ host: '127.0.0.1', port: 0 }, () => {
184
+ server.off('error', reject);
185
+ const address = server.address();
186
+ if (address === null || typeof address === 'string') {
187
+ reject(new Error('the stand-in has no port'));
188
+ return;
189
+ }
190
+ let busy = false;
191
+ resolve({
192
+ url: `http://127.0.0.1:${address.port}`,
193
+ received: () => {
194
+ const snapshot = Object.freeze([...seen]);
195
+ seen.length = 0;
196
+ return snapshot;
197
+ },
198
+ answerWith: (status, headers) => {
199
+ pending = { status, headers };
200
+ },
201
+ run: (row, proxy, options) => {
202
+ if (busy)
203
+ return Promise.reject(new Error('rows run one at a time'));
204
+ busy = true;
205
+ return Promise.resolve()
206
+ .then(() => runRow(row, proxy, seen, (next) => {
207
+ pending = next;
208
+ }, options))
209
+ .finally(() => {
210
+ busy = false;
211
+ });
212
+ },
213
+ close: () => new Promise((done, failed) => {
214
+ server.closeAllConnections();
215
+ server.close((error) => (error === undefined ? done() : failed(error)));
216
+ }),
217
+ });
218
+ });
219
+ });
220
+ }
221
+ function grouped(headers) {
222
+ const back = {};
223
+ for (const [name, value] of headers) {
224
+ const already = back[name];
225
+ if (already === undefined)
226
+ back[name] = value;
227
+ else if (typeof already === 'string')
228
+ back[name] = [already, value];
229
+ else
230
+ already.push(value);
231
+ }
232
+ return back;
233
+ }
234
+ function requireProxy(proxy) {
235
+ let url;
236
+ try {
237
+ url = new URL(proxy);
238
+ }
239
+ catch {
240
+ throw new TypeError(`run: proxy is not an http address: ${shown(proxy)}`);
241
+ }
242
+ if (url.protocol !== 'http:')
243
+ throw new TypeError(`run: the rows run over http only, never at a deployed proxy: ${shown(proxy)}`);
244
+ if (url.username !== '' || url.password !== '')
245
+ throw new TypeError(`run: proxy has userinfo: ${shown(proxy)}`);
246
+ if (url.search !== '')
247
+ throw new TypeError(`run: proxy has a query: ${shown(proxy)}`);
248
+ if (url.hash !== '')
249
+ throw new TypeError(`run: proxy has a hash: ${shown(proxy)}`);
250
+ return url;
251
+ }
252
+ /** The proxy's path in front of the row's path. A pathname of `/` adds nothing. */
253
+ function joinedPath(pathname, rowPath) {
254
+ const base = pathname.length > 1 && pathname.endsWith('/') ? pathname.slice(0, -1) : pathname;
255
+ const rest = rowPath.startsWith('/') ? rowPath : `/${rowPath}`;
256
+ if (base === '' || base === '/')
257
+ return rest;
258
+ return `${base}${rest}`;
259
+ }
260
+ /** Wait until `seen` has been the same length for `quietMs`, or `maxWaits` times. */
261
+ function untilQuiet(seen, quietMs, maxWaits) {
262
+ const wait = (ms) => new Promise((resolve) => {
263
+ setTimeout(resolve, ms);
264
+ });
265
+ const step = async () => {
266
+ for (let waits = 0; waits < maxWaits; waits += 1) {
267
+ const count = seen.length;
268
+ await wait(quietMs);
269
+ if (seen.length === count)
270
+ return;
271
+ }
272
+ };
273
+ return step();
274
+ }
275
+ function runRow(row, proxy, seen, setPending, options) {
276
+ const target = requireProxy(proxy);
277
+ const held = seen.splice(0, seen.length);
278
+ const late = held.map((arrival) => `a request arrived after its row had ended: ${arrival.method} ${arrival.url}`);
279
+ const giveBack = () => {
280
+ if (held.length === 0)
281
+ return;
282
+ seen.unshift(...held);
283
+ held.length = 0;
284
+ };
285
+ const answers = row.upstream_answers;
286
+ setPending(answers === undefined ? EMPTY : { status: row.expect.answer.status, headers: answers });
287
+ const path = joinedPath(target.pathname, row.request.path);
288
+ const body = bodyOf(row.request.body);
289
+ const headers = { ...row.request.headers };
290
+ if (body !== '')
291
+ headers['content-length'] = String(Buffer.byteLength(body));
292
+ const timeoutMs = requireDelay(options?.timeoutMs ?? 2000, 'timeoutMs');
293
+ return new Promise((resolve, reject) => {
294
+ let settled = false;
295
+ const sent = send({ hostname: requestHost(target), port: target.port, path, method: row.request.method, headers }, (response) => {
296
+ void readBody(response)
297
+ .then(async () => {
298
+ if (settled)
299
+ return;
300
+ clearTimeout(timer);
301
+ // A late forward has to be visible to whichever outcome says nothing is forwarded.
302
+ if (row.upstream === null || row.or?.upstream === null)
303
+ await untilQuiet(seen, 50, Math.max(1, Math.floor(timeoutMs / 50)));
304
+ if (settled)
305
+ return;
306
+ settled = true;
307
+ clearTimeout(timer);
308
+ const arrivals = seen.splice(0, seen.length);
309
+ resolve(Object.freeze([...late, ...mismatches(row, arrivals, { status: response.statusCode ?? 0, headers: response.headers })]));
310
+ })
311
+ .catch((error) => {
312
+ if (settled)
313
+ return;
314
+ settled = true;
315
+ clearTimeout(timer);
316
+ giveBack();
317
+ reject(error instanceof Error ? error : new Error('the stand-in could not read the answer'));
318
+ });
319
+ });
320
+ const timer = setTimeout(() => {
321
+ if (settled)
322
+ return;
323
+ settled = true;
324
+ sent.destroy();
325
+ resolve(Object.freeze([...late, `no answer within ${timeoutMs} ms`]));
326
+ }, timeoutMs);
327
+ sent.on('error', (error) => {
328
+ if (settled)
329
+ return;
330
+ settled = true;
331
+ clearTimeout(timer);
332
+ giveBack();
333
+ reject(error);
334
+ });
335
+ if (body === '')
336
+ sent.end();
337
+ else
338
+ sent.end(body);
339
+ });
340
+ }
341
+ //# sourceMappingURL=stand-in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stand-in.js","sourceRoot":"","sources":["../../../src/first-party/proxy/stand-in.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,OAAO,EAAE,YAAY,EAAE,OAAO,IAAI,IAAI,EAAwB,MAAM,WAAW,CAAA;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAgC,MAAM,cAAc,CAAA;AAiD7E,MA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EAAE,EAAE;YACzB,IAAI,OAAO;gBAAE,OAAM;YACnB,OAAO,GAAG,IAAI,CAAA;YACd,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,QAAQ,EAAE,CAAA;YACV,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;QACF,IAAI,IAAI,KAAK,EAAE;YAAE,IAAI,CAAC,GAAG,EAAE,CAAA;;YACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * What the session tells the app's operator, through `onReport`: that this browser's storage refuses, that its lock manager threw, that another tab runs a version this one can't read, or that a server answered outside its contract.
3
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#createbrowsersession
4
+ */
5
+ export type SessionReport =
6
+ /**
7
+ * A server answered outside the contract.
8
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#createbrowsersession
9
+ */
10
+ {
11
+ readonly kind: 'answer';
12
+ readonly path: string;
13
+ readonly status: number;
14
+ }
15
+ /**
16
+ * The browser's lock manager threw.
17
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#createbrowsersession
18
+ */
19
+ | {
20
+ readonly kind: 'lock';
21
+ readonly cause: unknown;
22
+ }
23
+ /**
24
+ * Storage refused the shared record's write.
25
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#createbrowsersession
26
+ */
27
+ | {
28
+ readonly kind: 'storage';
29
+ }
30
+ /**
31
+ * Another tab sent a token this version can't read.
32
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#createbrowsersession
33
+ */
34
+ | {
35
+ readonly kind: 'message';
36
+ }
37
+ /**
38
+ * Something threw where nothing should: a bug.
39
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#createbrowsersession
40
+ */
41
+ | {
42
+ readonly kind: 'threw';
43
+ readonly step: 'refresh' | 'logout';
44
+ readonly cause: unknown;
45
+ };
46
+ /**
47
+ * The app's `onReport`, made safe to call: by default each report is printed with `console.warn`,
48
+ * a no-op silences it, and one that throws is caught there, so the call that reported goes on.
49
+ */
50
+ export declare function reporter(onReport: ((report: SessionReport) => void) | undefined): (report: SessionReport) => void;
51
+ /**
52
+ * The error a never-branch throws, should the types ever be wrong: it names the value's `kind`
53
+ * when that is a string, and nothing else. The value may be an answer, with a body or a token,
54
+ * and this error can reach the app as a `threw` report's cause.
55
+ */
56
+ export declare function unhandled(what: string, value: unknown): Error;
@@ -0,0 +1,38 @@
1
+ /*
2
+ * What the browser session reports to the app's operator (#465, SDK-D1903): the one place an app
3
+ * learns that this browser's storage is refusing, that two versions of it run in two tabs, or that
4
+ * a server answers outside its contract. Never a body, a token, a message's content or a query: the
5
+ * promise is public, so it holds for a bug's `cause` too (see `unhandled`).
6
+ */
7
+ /**
8
+ * The app's `onReport`, made safe to call: by default each report is printed with `console.warn`,
9
+ * a no-op silences it, and one that throws is caught there, so the call that reported goes on.
10
+ */
11
+ export function reporter(onReport) {
12
+ const send = onReport ??
13
+ ((report) => {
14
+ console.warn('@flipstream/sdk/first-party:', report);
15
+ });
16
+ return (report) => {
17
+ try {
18
+ // Frozen itself, as all the entry hands out (SDK-D1922); a cause is what was thrown, never
19
+ // the SDK's to change, so it is passed on as it is.
20
+ send(Object.freeze({ ...report }));
21
+ }
22
+ catch {
23
+ // The app's own reporter threw: nothing to do with the session, which goes on.
24
+ }
25
+ };
26
+ }
27
+ /**
28
+ * The error a never-branch throws, should the types ever be wrong: it names the value's `kind`
29
+ * when that is a string, and nothing else. The value may be an answer, with a body or a token,
30
+ * and this error can reach the app as a `threw` report's cause.
31
+ */
32
+ export function unhandled(what, value) {
33
+ const kind = typeof value === 'object' && value !== null && 'kind' in value && typeof value.kind === 'string'
34
+ ? value.kind
35
+ : null;
36
+ return new Error(kind === null ? `unhandled ${what}` : `unhandled ${what} ${kind}`);
37
+ }
38
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/first-party/report.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmCH;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAuD;IAC9E,MAAM,IAAI,GACR,QAAQ;QACR,CAAC,CAAC,MAAqB,EAAQ,EAAE;YAC/B,OAAO,CAAC,IAAI,CAAC,8BAA8B,EAAE,MAAM,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;IACJ,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAI,CAAC;YACH,2FAA2F;YAC3F,oDAAoD;YACpD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAA;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,+EAA+E;QACjF,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,KAAc;IACpD,MAAM,IAAI,GACR,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9F,CAAC,CAAC,KAAK,CAAC,IAAI;QACZ,CAAC,CAAC,IAAI,CAAA;IACV,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,CAAC,aAAa,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;AACrF,CAAC"}
@@ -0,0 +1,150 @@
1
+ /**
2
+ * A call that went through: `data` is its answer.
3
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
4
+ */
5
+ export type Ok<D> = {
6
+ /**
7
+ * The call went through.
8
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
9
+ */
10
+ readonly ok: true;
11
+ /**
12
+ * The call's answer.
13
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
14
+ */
15
+ readonly data: D;
16
+ };
17
+ /**
18
+ * A call that stopped short: `error.kind` says why, one meaning per kind.
19
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
20
+ */
21
+ export type Stopped<E extends {
22
+ readonly kind: string;
23
+ }> = {
24
+ /**
25
+ * The call stopped short.
26
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
27
+ */
28
+ readonly ok: false;
29
+ /**
30
+ * Why it stopped, one meaning per `kind`.
31
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
32
+ */
33
+ readonly error: E;
34
+ };
35
+ /**
36
+ * Every call of the entry settles into one of these.
37
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
38
+ */
39
+ export type Result<D, E extends {
40
+ readonly kind: string;
41
+ }> = Ok<D> | Stopped<E>;
42
+ /**
43
+ * `value`, frozen with every plain object and array inside it (SDK-D1922): what a first-party call
44
+ * hands out is read-only all the way down, as its type says, so one holder of a result shared
45
+ * among several can't change it under another. The walk enters only plain objects and arrays, the
46
+ * shapes the SDK builds, and stops at anything already frozen.
47
+ */
48
+ export declare function frozen<T>(value: T): T;
49
+ export declare const ok: <D>(data: D) => Ok<D>;
50
+ export declare const stopped: <E extends {
51
+ readonly kind: string;
52
+ }>(error: E) => Stopped<E>;
53
+ /**
54
+ * The last argument of every call that sends.
55
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
56
+ */
57
+ export interface CallOptions {
58
+ /**
59
+ * The caller's own: once it aborts, the call answers `aborted` at once, never a rejection, unless the call's own doc says an abort is ignored once it is sent.
60
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
61
+ */
62
+ readonly signal?: AbortSignal;
63
+ }
64
+ /**
65
+ * Every call that sends can end in one of these.
66
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
67
+ */
68
+ export type Sent =
69
+ /**
70
+ * Offline, a 5xx, or a 429 the call has no rule of its own for.
71
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
72
+ */
73
+ {
74
+ readonly kind: 'unavailable';
75
+ }
76
+ /**
77
+ * An answer outside the contract.
78
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
79
+ */
80
+ | {
81
+ readonly kind: 'invalid';
82
+ }
83
+ /**
84
+ * The caller's own signal ended it.
85
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
86
+ */
87
+ | {
88
+ readonly kind: 'aborted';
89
+ };
90
+ /**
91
+ * A call through the app's own /auth proxy, inside the session's cookie lock.
92
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
93
+ */
94
+ export type ThroughProxy = Sent
95
+ /**
96
+ * The app's own server refused the request (the proxy's own refusal mark): a deployment fault.
97
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
98
+ */
99
+ | {
100
+ readonly kind: 'proxy_refused';
101
+ }
102
+ /**
103
+ * This browser lacks what the session needs (locks, storage).
104
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
105
+ */
106
+ | {
107
+ readonly kind: 'unsupported';
108
+ };
109
+ /**
110
+ * A call made as the signed-in person, straight to the auth host.
111
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#twostepstatus
112
+ */
113
+ export type AsPerson = Sent
114
+ /**
115
+ * Nobody is signed in here, or the session ended while the call ran.
116
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#twostepstatus
117
+ */
118
+ | {
119
+ readonly kind: 'signed_out';
120
+ };
121
+ /**
122
+ * Nothing was sent: required text was empty.
123
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
124
+ */
125
+ export type Refused = {
126
+ /**
127
+ * Nothing was sent.
128
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
129
+ */
130
+ readonly kind: 'refused';
131
+ /**
132
+ * The required text was empty.
133
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
134
+ */
135
+ readonly reason: 'empty';
136
+ /**
137
+ * Which fields were empty, in the request's own names.
138
+ * @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#requestlink
139
+ */
140
+ readonly fields: readonly string[];
141
+ };
142
+ /**
143
+ * The names of the fields that are empty: not a string, or nothing but whitespace. In the order
144
+ * given. A family refuses with `{ kind: 'refused', reason: 'empty', fields }` when this isn't empty.
145
+ *
146
+ * `asTyped` names the fields sent exactly as typed, which are empty only when they are `''`: a
147
+ * password. pulse-auth doesn't strip one and only counts its characters, so the SDK never trims
148
+ * or judges it (2 Dec 23:30).
149
+ */
150
+ export declare function emptyFields(input: Readonly<Record<string, unknown>>, required: readonly string[], asTyped?: readonly string[]): readonly string[];
@@ -0,0 +1,40 @@
1
+ // The shapes every call of the first-party entry answers in: the seam between the session and
2
+ // the call families (#465; the lead's seam, part 1, verbatim).
3
+ /**
4
+ * `value`, frozen with every plain object and array inside it (SDK-D1922): what a first-party call
5
+ * hands out is read-only all the way down, as its type says, so one holder of a result shared
6
+ * among several can't change it under another. The walk enters only plain objects and arrays, the
7
+ * shapes the SDK builds, and stops at anything already frozen.
8
+ */
9
+ export function frozen(value) {
10
+ if (typeof value !== 'object' || value === null || Object.isFrozen(value))
11
+ return value;
12
+ const prototype = Object.getPrototypeOf(value);
13
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
14
+ return value;
15
+ // Frozen before the walk, so a cycle ends where it began.
16
+ Object.freeze(value);
17
+ const inside = Object.values(value);
18
+ for (const each of inside)
19
+ frozen(each);
20
+ return value;
21
+ }
22
+ export const ok = (data) => frozen({ ok: true, data });
23
+ export const stopped = (error) => frozen({ ok: false, error });
24
+ /**
25
+ * The names of the fields that are empty: not a string, or nothing but whitespace. In the order
26
+ * given. A family refuses with `{ kind: 'refused', reason: 'empty', fields }` when this isn't empty.
27
+ *
28
+ * `asTyped` names the fields sent exactly as typed, which are empty only when they are `''`: a
29
+ * password. pulse-auth doesn't strip one and only counts its characters, so the SDK never trims
30
+ * or judges it (2 Dec 23:30).
31
+ */
32
+ export function emptyFields(input, required, asTyped = []) {
33
+ return required.filter((name) => {
34
+ const value = input[name];
35
+ if (typeof value !== 'string')
36
+ return true;
37
+ return asTyped.includes(name) ? value === '' : value.trim() === '';
38
+ });
39
+ }
40
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/first-party/result.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,+DAA+D;AAwC/D;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAI,KAAQ;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACvF,MAAM,SAAS,GAAY,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAC/F,0DAA0D;IAC1D,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACpB,MAAM,MAAM,GAAuB,MAA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