@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,23 @@
1
+ import { type IncomingMessage, type ServerResponse } from 'node:http';
2
+ import { type AuthProxyApp } from './app.js';
3
+ /** How the dev and preview handler is bounded. */
4
+ export interface AuthProxyHandlerOptions {
5
+ /**
6
+ * How long the upstream call may take, in milliseconds. A finite number above 0 and at most
7
+ * 2147483647. The default is 30 seconds. The bound cannot be switched off.
8
+ */
9
+ readonly boundMs?: number;
10
+ }
11
+ /**
12
+ * A dev and preview handler. Production is nginx, in both apps. `https:` goes out through TLS
13
+ * and `http:` in clear, each on its own default port. The bound is for the whole call, its body
14
+ * included: 504 when nothing was written in time, the response destroyed when the body does not
15
+ * finish in time or the upstream breaks after the head, 502 when the upstream fails before the
16
+ * head. It sets no client address.
17
+ */
18
+ export declare function authProxyHandler(app: AuthProxyApp, upstream: string, options?: AuthProxyHandlerOptions): (request: IncomingMessage, response: ServerResponse) => void;
19
+ /** Listen on 127.0.0.1 and serve {@link authProxyHandler} at `/auth`. Anything else is 404. */
20
+ export declare function startReferenceProxy(app: AuthProxyApp, upstream: string): Promise<{
21
+ readonly url: string;
22
+ close(): Promise<void>;
23
+ }>;
@@ -0,0 +1,190 @@
1
+ import { createServer, request as forwardHttp } from 'node:http';
2
+ import { request as forwardHttps } from 'node:https';
3
+ import { requireApp } from './app.js';
4
+ import { requireDelay } from './bound.js';
5
+ import { decideAuthProxy } from './decide.js';
6
+ import { requestHost } from './host.js';
7
+ import { passBack } from './pass-back.js';
8
+ import { shown } from './shown.js';
9
+ const DEFAULT_BOUND_MS = 30_000;
10
+ /**
11
+ * An origin a dev handler may call: `http:` or `https:`, no path beyond `/`, no query, hash or
12
+ * userinfo. The message names the value.
13
+ */
14
+ function requireUpstream(upstream) {
15
+ let url;
16
+ try {
17
+ url = new URL(upstream);
18
+ }
19
+ catch {
20
+ throw new TypeError(`authProxyHandler: upstream is not an origin: ${shown(upstream)}`);
21
+ }
22
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
23
+ throw new TypeError(`authProxyHandler: upstream is not an http or https origin: ${shown(upstream)}`);
24
+ }
25
+ if (url.username !== '' || url.password !== '')
26
+ throw new TypeError(`authProxyHandler: upstream has userinfo: ${shown(upstream)}`);
27
+ if (url.pathname !== '/' && url.pathname !== '')
28
+ throw new TypeError(`authProxyHandler: upstream has a path: ${shown(upstream)}`);
29
+ if (url.search !== '' || url.hash !== '')
30
+ throw new TypeError(`authProxyHandler: upstream has a query or a hash: ${shown(upstream)}`);
31
+ return url;
32
+ }
33
+ /**
34
+ * A dev and preview handler. Production is nginx, in both apps. `https:` goes out through TLS
35
+ * and `http:` in clear, each on its own default port. The bound is for the whole call, its body
36
+ * included: 504 when nothing was written in time, the response destroyed when the body does not
37
+ * finish in time or the upstream breaks after the head, 502 when the upstream fails before the
38
+ * head. It sets no client address.
39
+ */
40
+ export function authProxyHandler(app, upstream, options) {
41
+ requireApp(app, 'authProxyHandler');
42
+ const target = requireUpstream(upstream);
43
+ const boundMs = requireDelay(options?.boundMs ?? DEFAULT_BOUND_MS, 'boundMs');
44
+ const forward = target.protocol === 'https:' ? forwardHttps : forwardHttp;
45
+ return (request, response) => {
46
+ response.sendDate = false;
47
+ const decision = decideAuthProxy({ method: request.method ?? 'GET', path: request.url ?? '/', headers: request.headersDistinct }, app);
48
+ if (decision.kind === 'not_found') {
49
+ request.resume();
50
+ response.writeHead(decision.status);
51
+ response.end();
52
+ return;
53
+ }
54
+ if (decision.kind === 'refuse') {
55
+ request.resume();
56
+ response.writeHead(decision.status, decision.headers);
57
+ response.end();
58
+ return;
59
+ }
60
+ const headers = {};
61
+ for (const [name, value] of Object.entries(request.headersDistinct)) {
62
+ if (value === undefined || value.length === 0)
63
+ continue;
64
+ const only = value[0];
65
+ headers[name] = value.length === 1 && only !== undefined ? only : [...value];
66
+ }
67
+ for (const name of decision.remove)
68
+ delete headers[name];
69
+ for (const [name, value] of Object.entries(decision.set))
70
+ headers[name] = value;
71
+ let answered = false;
72
+ const cut = () => {
73
+ answered = true;
74
+ clearTimeout(timer);
75
+ sent.destroy();
76
+ if (!response.writableEnded)
77
+ response.destroy();
78
+ };
79
+ const sent = forward({ hostname: requestHost(target), port: target.port, path: decision.path, method: request.method ?? 'POST', headers }, (answer) => {
80
+ if (answered || response.headersSent) {
81
+ answer.resume();
82
+ return;
83
+ }
84
+ if (answer.statusCode === undefined) {
85
+ answer.resume();
86
+ cut();
87
+ return;
88
+ }
89
+ const passed = passBack({ status: answer.statusCode, headers: answer.headers }, app);
90
+ const back = {};
91
+ for (const [name, value] of passed.headers) {
92
+ const already = back[name];
93
+ if (already === undefined)
94
+ back[name] = value;
95
+ else if (typeof already === 'string')
96
+ back[name] = [already, value];
97
+ else
98
+ already.push(value);
99
+ }
100
+ response.writeHead(passed.status, back);
101
+ answer.on('error', cut);
102
+ answer.on('aborted', () => {
103
+ if (!answer.complete)
104
+ cut();
105
+ });
106
+ answer.on('data', (chunk) => {
107
+ if (!response.writableEnded)
108
+ response.write(chunk);
109
+ });
110
+ answer.on('end', () => {
111
+ if (answer.complete) {
112
+ clearTimeout(timer);
113
+ if (!response.writableEnded)
114
+ response.end();
115
+ return;
116
+ }
117
+ cut();
118
+ });
119
+ });
120
+ const timer = setTimeout(() => {
121
+ answered = true;
122
+ sent.destroy();
123
+ if (!response.headersSent) {
124
+ request.resume();
125
+ response.writeHead(504);
126
+ response.end();
127
+ return;
128
+ }
129
+ if (!response.writableEnded)
130
+ response.destroy();
131
+ }, boundMs);
132
+ sent.on('error', () => {
133
+ if (answered || response.writableEnded)
134
+ return;
135
+ answered = true;
136
+ clearTimeout(timer);
137
+ if (response.headersSent) {
138
+ response.destroy();
139
+ return;
140
+ }
141
+ request.resume();
142
+ response.writeHead(502);
143
+ response.end();
144
+ });
145
+ request.on('error', () => sent.destroy());
146
+ response.on('close', () => {
147
+ answered = true;
148
+ if (timer !== undefined)
149
+ clearTimeout(timer);
150
+ if (!response.writableFinished)
151
+ sent.destroy();
152
+ });
153
+ request.pipe(sent);
154
+ };
155
+ }
156
+ /** Listen on 127.0.0.1 and serve {@link authProxyHandler} at `/auth`. Anything else is 404. */
157
+ export function startReferenceProxy(app, upstream) {
158
+ const handle = authProxyHandler(app, upstream);
159
+ const server = createServer((request, response) => {
160
+ const url = request.url ?? '/';
161
+ if (url === '/auth' || url.startsWith('/auth/')) {
162
+ const rest = url.slice('/auth'.length);
163
+ request.url = rest === '' ? '/' : rest;
164
+ handle(request, response);
165
+ return;
166
+ }
167
+ request.resume();
168
+ response.writeHead(404);
169
+ response.end();
170
+ });
171
+ return new Promise((resolve, reject) => {
172
+ server.once('error', reject);
173
+ server.listen({ host: '127.0.0.1', port: 0 }, () => {
174
+ server.off('error', reject);
175
+ const address = server.address();
176
+ if (address === null || typeof address === 'string') {
177
+ reject(new Error('the reference proxy has no port'));
178
+ return;
179
+ }
180
+ resolve({
181
+ url: `http://127.0.0.1:${address.port}/auth`,
182
+ close: () => new Promise((done, failed) => {
183
+ server.closeAllConnections();
184
+ server.close((error) => (error === undefined ? done() : failed(error)));
185
+ }),
186
+ });
187
+ });
188
+ });
189
+ }
190
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/first-party/proxy/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,IAAI,WAAW,EAA6C,MAAM,WAAW,CAAA;AAC3G,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,UAAU,EAAqB,MAAM,UAAU,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAWlC,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAE/B;;;GAGG;AACH,SAAS,eAAe,CAAC,QAAgB;IACvC,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,SAAS,CAAC,gDAAgD,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACxF,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1D,MAAM,IAAI,SAAS,CAAC,8DAA8D,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACtG,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,4CAA4C,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAClI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able:
3
+ * it yields each `Set-Cookie` on its own, which `get('set-cookie')` cannot, because that joins
4
+ * them into one string. Node's `req.headers` and `res.headers` are the record.
5
+ */
6
+ export type HeadersLike = Iterable<readonly [string, string]> | Readonly<Record<string, string | readonly string[] | undefined>>;
7
+ /** Every header pair, in the order given. A record's array value is one pair per element. */
8
+ export declare function headerPairs(headers: HeadersLike): readonly (readonly [string, string])[];
@@ -0,0 +1,20 @@
1
+ /** Every header pair, in the order given. A record's array value is one pair per element. */
2
+ export function headerPairs(headers) {
3
+ if (Symbol.iterator in headers) {
4
+ const pairs = [];
5
+ for (const pair of headers)
6
+ pairs.push([pair[0], pair[1]]);
7
+ return pairs;
8
+ }
9
+ const pairs = [];
10
+ for (const name of Object.keys(headers)) {
11
+ const value = headers[name];
12
+ if (typeof value === 'string')
13
+ pairs.push([name, value]);
14
+ else if (value !== undefined)
15
+ for (const each of value)
16
+ pairs.push([name, each]);
17
+ }
18
+ return pairs;
19
+ }
20
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../src/first-party/proxy/headers.ts"],"names":[],"mappings":"AASA,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,OAAoB;IAC9C,IAAI,MAAM,CAAC,QAAQ,IAAI,OAAO,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAkC,EAAE,CAAA;QAC/C,KAAK,MAAM,IAAI,IAAI,OAAO;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1D,OAAO,KAAK,CAAA;IACd,CAAC;IACD,MAAM,KAAK,GAAkC,EAAE,CAAA;IAC/C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;aACnD,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAClF,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** Hop-by-hop names, compared without case. One list, on the way up and on the way back. */
2
+ export declare const HOP_BY_HOP: readonly ["connection", "keep-alive", "proxy-authenticate", "proxy-connection", "te", "trailer", "transfer-encoding", "upgrade"];
3
+ /** Whether `name` is hop-by-hop, without case. */
4
+ export declare function isHop(name: string): boolean;
5
+ /**
6
+ * Header names a `Connection` value lists, without case, in the order written. A hop may name
7
+ * a further header there, and that header is the hop's too.
8
+ */
9
+ export declare function namedByConnection(pairs: readonly (readonly [string, string])[]): readonly string[];
@@ -0,0 +1,37 @@
1
+ /** Hop-by-hop names, compared without case. One list, on the way up and on the way back. */
2
+ export const HOP_BY_HOP = [
3
+ 'connection',
4
+ 'keep-alive',
5
+ 'proxy-authenticate',
6
+ 'proxy-connection',
7
+ 'te',
8
+ 'trailer',
9
+ 'transfer-encoding',
10
+ 'upgrade',
11
+ ];
12
+ /** Whether `name` is hop-by-hop, without case. */
13
+ export function isHop(name) {
14
+ const key = name.toLowerCase();
15
+ for (const hop of HOP_BY_HOP)
16
+ if (hop === key)
17
+ return true;
18
+ return false;
19
+ }
20
+ /**
21
+ * Header names a `Connection` value lists, without case, in the order written. A hop may name
22
+ * a further header there, and that header is the hop's too.
23
+ */
24
+ export function namedByConnection(pairs) {
25
+ const named = [];
26
+ for (const [name, value] of pairs) {
27
+ if (name.toLowerCase() !== 'connection')
28
+ continue;
29
+ for (const token of value.split(',')) {
30
+ const header = token.trim().toLowerCase();
31
+ if (header !== '' && !named.includes(header))
32
+ named.push(header);
33
+ }
34
+ }
35
+ return named;
36
+ }
37
+ //# sourceMappingURL=hop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hop.js","sourceRoot":"","sources":["../../../src/first-party/proxy/hop.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,YAAY;IACZ,YAAY;IACZ,oBAAoB;IACpB,kBAAkB;IAClB,IAAI;IACJ,SAAS;IACT,mBAAmB;IACnB,SAAS;CACD,CAAA;AAEV,kDAAkD;AAClD,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAC9B,KAAK,MAAM,GAAG,IAAI,UAAU;QAAE,IAAI,GAAG,KAAK,GAAG;YAAE,OAAO,IAAI,CAAA;IAC1D,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6C;IAC7E,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY;YAAE,SAAQ;QACjD,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;YACzC,IAAI,MAAM,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The host of a URL as Node's `request` takes it.
3
+ * The brackets of an IPv6 literal come off. Anything else is unchanged.
4
+ */
5
+ export declare function requestHost(url: URL): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The host of a URL as Node's `request` takes it.
3
+ * The brackets of an IPv6 literal come off. Anything else is unchanged.
4
+ */
5
+ export function requestHost(url) {
6
+ const host = url.hostname;
7
+ if (host.startsWith('[') && host.endsWith(']'))
8
+ return host.slice(1, -1);
9
+ return host;
10
+ }
11
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../../src/first-party/proxy/host.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAQ;IAClC,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAA;IACzB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACxE,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { type AuthProxyApp, type AuthProxyCookie } from './app.js';
2
+ export { authProxyCases, type AuthProxyCase } from './cases.js';
3
+ export { decideAuthProxy, type AuthProxyDecision } from './decide.js';
4
+ export { type HeadersLike } from './headers.js';
5
+ export { passBack, type AuthProxyAnswer } from './pass-back.js';
6
+ export { AUTH_PROXY_REFUSAL, AUTH_PROXY_REFUSAL_VALUE } from '../authProxyMark.js';
7
+ export { AUTH_PROXY_COOKIES, AUTH_PROXY_NEVER_PASSED, AUTH_PROXY_PATHS } from './paths.js';
@@ -0,0 +1,6 @@
1
+ export { authProxyCases } from './cases.js';
2
+ export { decideAuthProxy } from './decide.js';
3
+ export { passBack } from './pass-back.js';
4
+ export { AUTH_PROXY_REFUSAL, AUTH_PROXY_REFUSAL_VALUE } from '../authProxyMark.js';
5
+ export { AUTH_PROXY_COOKIES, AUTH_PROXY_NEVER_PASSED, AUTH_PROXY_PATHS } from './paths.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/first-party/proxy/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAA;AAErE,OAAO,EAAE,QAAQ,EAAwB,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAClF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { type AuthProxyApp } from './app.js';
2
+ import { type HeadersLike } from './headers.js';
3
+ /** What of pulse-auth's answer goes back to the browser. A header may repeat, so pairs. */
4
+ export interface AuthProxyAnswer {
5
+ /** The status, unchanged. */
6
+ readonly status: number;
7
+ /** The headers a browser can be given. A name may repeat, so each is a pair. */
8
+ readonly headers: readonly (readonly [string, string])[];
9
+ }
10
+ /**
11
+ * The status unchanged, and the headers a browser can be given. `Set-Cookie` is filtered.
12
+ * The refusal mark is dropped, so a forwarded answer never carries it.
13
+ * Every hop-by-hop header is dropped, by name without case, and so is any header the upstream
14
+ * `Connection` value names. `Content-Length` and `Content-Encoding` are kept: the body is piped
15
+ * through undecoded, and those two describe those bytes. Nothing is added, a CORS header included.
16
+ * A `Set-Cookie` for a name the app does not list is dropped.
17
+ */
18
+ export declare function passBack(answer: {
19
+ readonly status: number;
20
+ readonly headers: HeadersLike;
21
+ }, app: AuthProxyApp): AuthProxyAnswer;
@@ -0,0 +1,51 @@
1
+ import { AUTH_PROXY_REFUSAL } from '../authProxyMark.js';
2
+ import { requireApp } from './app.js';
3
+ import { freezeDeep } from './freeze.js';
4
+ import { headerPairs } from './headers.js';
5
+ import { isHop, namedByConnection } from './hop.js';
6
+ function isListedCookie(name, cookies) {
7
+ for (const cookie of cookies)
8
+ if (cookie === name)
9
+ return true;
10
+ return false;
11
+ }
12
+ /**
13
+ * `Set-Cookie` is kept for a name the app lists, an empty value included: that is how a cookie is
14
+ * cleared. The kept value, attributes included, is the bytes that arrived.
15
+ */
16
+ function keepSetCookie(value, cookies) {
17
+ const semi = value.indexOf(';');
18
+ const pair = (semi === -1 ? value : value.slice(0, semi)).trim();
19
+ const equals = pair.indexOf('=');
20
+ // An empty value is how a cookie is cleared. The empty-pair rule is the way up only.
21
+ if (equals <= 0)
22
+ return false;
23
+ return isListedCookie(pair.slice(0, equals).trim(), cookies);
24
+ }
25
+ /**
26
+ * The status unchanged, and the headers a browser can be given. `Set-Cookie` is filtered.
27
+ * The refusal mark is dropped, so a forwarded answer never carries it.
28
+ * Every hop-by-hop header is dropped, by name without case, and so is any header the upstream
29
+ * `Connection` value names. `Content-Length` and `Content-Encoding` are kept: the body is piped
30
+ * through undecoded, and those two describe those bytes. Nothing is added, a CORS header included.
31
+ * A `Set-Cookie` for a name the app does not list is dropped.
32
+ */
33
+ export function passBack(answer, app) {
34
+ requireApp(app, 'passBack');
35
+ const pairs = [...headerPairs(answer.headers)];
36
+ const named = new Set(namedByConnection(pairs));
37
+ const headers = [];
38
+ for (const [name, value] of pairs) {
39
+ const key = name.toLowerCase();
40
+ if (key === AUTH_PROXY_REFUSAL.toLowerCase() || isHop(key) || named.has(key))
41
+ continue;
42
+ if (key === 'set-cookie') {
43
+ if (keepSetCookie(value, app.cookies))
44
+ headers.push([key, value]);
45
+ continue;
46
+ }
47
+ headers.push([key, value]);
48
+ }
49
+ return freezeDeep({ status: answer.status, headers });
50
+ }
51
+ //# sourceMappingURL=pass-back.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pass-back.js","sourceRoot":"","sources":["../../../src/first-party/proxy/pass-back.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAqB,MAAM,UAAU,CAAA;AACxD,OAAO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,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;QAClC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAC9B,IAAI,GAAG,KAAK,kBAAkB,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAQ;QACtF,IAAI,GAAG,KAAK,YAAY,EAAE,CAAC;YACzB,IAAI,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;YACjE,SAAQ;QACV,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;AACvD,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The paths the session can send, all POST, relative to the proxy's own path. Data, so an nginx
3
+ * config can be rendered from it. `login` is `logIn`'s. `invitations/accept` is
4
+ * `acceptInvitation`'s (sdk#472).
5
+ */
6
+ export declare const AUTH_PROXY_PATHS: readonly ["refresh", "login-link", "logout", "mfa/verify", "login", "invitations/accept"];
7
+ /**
8
+ * The cookie names that exist. An app's own list says which of them it passes. A name that is
9
+ * not here is never a proxy cookie.
10
+ */
11
+ export declare const AUTH_PROXY_COOKIES: readonly ["refresh_token", "__Host-refresh_token"];
12
+ /**
13
+ * Header names a browser can write that must not reach pulse-auth as the browser wrote them.
14
+ * Any name starting with `x-forwarded-` is the same rule and is not listed, because it is a
15
+ * pattern. `host` and `cookie` are removed on every forward and are not listed either.
16
+ */
17
+ export declare const AUTH_PROXY_NEVER_PASSED: readonly ["authorization", "proxy-authorization", "forwarded", "x-real-ip", "cf-connecting-ip", "true-client-ip", "x-client-ip", "x-cluster-client-ip", "fastly-client-ip"];
@@ -0,0 +1,36 @@
1
+ import { freezeDeep } from './freeze.js';
2
+ /**
3
+ * The paths the session can send, all POST, relative to the proxy's own path. Data, so an nginx
4
+ * config can be rendered from it. `login` is `logIn`'s. `invitations/accept` is
5
+ * `acceptInvitation`'s (sdk#472).
6
+ */
7
+ export const AUTH_PROXY_PATHS = freezeDeep([
8
+ 'refresh',
9
+ 'login-link',
10
+ 'logout',
11
+ 'mfa/verify',
12
+ 'login',
13
+ 'invitations/accept',
14
+ ]);
15
+ /**
16
+ * The cookie names that exist. An app's own list says which of them it passes. A name that is
17
+ * not here is never a proxy cookie.
18
+ */
19
+ export const AUTH_PROXY_COOKIES = freezeDeep(['refresh_token', '__Host-refresh_token']);
20
+ /**
21
+ * Header names a browser can write that must not reach pulse-auth as the browser wrote them.
22
+ * Any name starting with `x-forwarded-` is the same rule and is not listed, because it is a
23
+ * pattern. `host` and `cookie` are removed on every forward and are not listed either.
24
+ */
25
+ export const AUTH_PROXY_NEVER_PASSED = freezeDeep([
26
+ 'authorization',
27
+ 'proxy-authorization',
28
+ 'forwarded',
29
+ 'x-real-ip',
30
+ 'cf-connecting-ip',
31
+ 'true-client-ip',
32
+ 'x-client-ip',
33
+ 'x-cluster-client-ip',
34
+ 'fastly-client-ip',
35
+ ]);
36
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/first-party/proxy/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;IACzC,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,OAAO;IACP,oBAAoB;CACZ,CAAC,CAAA;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,CAAC,eAAe,EAAE,sBAAsB,CAAU,CAAC,CAAA;AAEhG;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;IAChD,eAAe;IACf,qBAAqB;IACrB,WAAW;IACX,WAAW;IACX,kBAAkB;IAClB,gBAAgB;IAChB,aAAa;IACb,qBAAqB;IACrB,kBAAkB;CACV,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * How a value is named in an error.
3
+ * A URL with a user name or a password is its scheme and host. Anything else is unchanged.
4
+ */
5
+ export declare function shown(value: string): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * How a value is named in an error.
3
+ * A URL with a user name or a password is its scheme and host. Anything else is unchanged.
4
+ */
5
+ export function shown(value) {
6
+ try {
7
+ const url = new URL(value);
8
+ if (url.username !== '' || url.password !== '')
9
+ return `${url.protocol}//${url.host}`;
10
+ }
11
+ catch {
12
+ // Not a URL: the value is shown as it was given.
13
+ }
14
+ return value;
15
+ }
16
+ //# sourceMappingURL=shown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shown.js","sourceRoot":"","sources":["../../../src/first-party/proxy/shown.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE;YAAE,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,EAAE,CAAA;IACvF,CAAC;IAAC,MAAM,CAAC;QACP,iDAAiD;IACnD,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type AuthProxyCase } from './cases.js';
2
+ export type { AuthProxyCase };
3
+ export type { AuthProxyApp, AuthProxyCookie } from './app.js';
4
+ export { AUTH_PROXY_COOKIES } from './paths.js';
5
+ export { authProxyHandler, type AuthProxyHandlerOptions } from './handler.js';
6
+ /** How long `run` waits. The default is 2000 ms, and a slow row is a mismatch, not a rejection. */
7
+ export interface AuthProxyRunOptions {
8
+ /**
9
+ * Raise the wait, in milliseconds. A finite number above 0 and at most 2147483647. The default
10
+ * is 2000. The bound cannot be switched off.
11
+ */
12
+ readonly timeoutMs?: number;
13
+ }
14
+ /** One request the stand-in saw, frozen. `received` returns these and then forgets them. */
15
+ export interface AuthStandInRequest {
16
+ /** The method, as it arrived. */
17
+ readonly method: string;
18
+ /** The target, query included, as it arrived. */
19
+ readonly url: string;
20
+ /** The headers, names as Node spells them. */
21
+ readonly headers: Readonly<Record<string, string | readonly string[]>>;
22
+ /** The body, decoded as UTF-8. Empty when there was none. */
23
+ readonly body: string;
24
+ }
25
+ /** A stand-in for pulse-auth, bound to 127.0.0.1 only. */
26
+ export interface AuthStandIn {
27
+ /** The origin the proxy forwards to. */
28
+ readonly url: string;
29
+ /** What has arrived since the last read. Reading clears it. */
30
+ received(): readonly AuthStandInRequest[];
31
+ /** The next answer. It holds until the next call, or until `run` sets the row's own. */
32
+ answerWith(status: number, headers: readonly (readonly [string, string])[]): void;
33
+ /**
34
+ * Send `row` to `proxy` and return what does not match. An empty list means the row holds.
35
+ * Rows run one at a time. `proxy` is an `http:` address with its path, on this machine: never
36
+ * a deployed proxy. The stand-in answers the row's upstream headers, or 204 with none when the
37
+ * row has no upstream answer, before the request is sent. No answer in time is a mismatch.
38
+ */
39
+ run(row: AuthProxyCase, proxy: string, options?: AuthProxyRunOptions): Promise<readonly string[]>;
40
+ /** Stop listening, so the port can be taken again. */
41
+ close(): Promise<void>;
42
+ }
43
+ /**
44
+ * Listen on 127.0.0.1 for what a proxy forwards. Before any `answerWith`, the answer is 204 with
45
+ * no headers. The body is always empty. Node may still add `Connection` on the way out.
46
+ */
47
+ export declare function startAuthStandIn(): Promise<AuthStandIn>;