@flipstream/sdk 0.13.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.
- package/CHANGELOG.md +120 -0
- package/README.md +143 -21
- package/dist/api/backend.d.ts +7 -0
- package/dist/api/backend.js +7 -0
- package/dist/api/backend.js.map +1 -1
- package/dist/api/credentials.js +4 -4
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/datasets.js +30 -50
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/handoff.d.ts +1 -1
- package/dist/api/handoff.js +7 -0
- package/dist/api/handoff.js.map +1 -1
- package/dist/api/log.d.ts +4 -4
- package/dist/api/log.js +23 -42
- package/dist/api/log.js.map +1 -1
- package/dist/api/me.d.ts +5 -3
- package/dist/api/me.js +3 -3
- package/dist/api/me.js.map +1 -1
- package/dist/api/members.d.ts +40 -17
- package/dist/api/members.js +66 -29
- package/dist/api/members.js.map +1 -1
- package/dist/api/ownRecord.d.ts +46 -0
- package/dist/api/ownRecord.js +57 -0
- package/dist/api/ownRecord.js.map +1 -0
- package/dist/api/refusal.d.ts +14 -0
- package/dist/api/refusal.js +23 -0
- package/dist/api/refusal.js.map +1 -0
- package/dist/api/wallet.d.ts +2 -1
- package/dist/api/wallet.js +18 -24
- package/dist/api/wallet.js.map +1 -1
- package/dist/api/workspaces.d.ts +7 -2
- package/dist/api/workspaces.js +14 -8
- package/dist/api/workspaces.js.map +1 -1
- package/dist/auth/discovery.js +4 -5
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/transport.d.ts +6 -2
- package/dist/auth/transport.js +5 -3
- package/dist/auth/transport.js.map +1 -1
- package/dist/core/call.d.ts +9 -4
- package/dist/core/call.js +12 -8
- package/dist/core/call.js.map +1 -1
- package/dist/core/fetch.d.ts +20 -1
- package/dist/core/fetch.js +50 -3
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/hosts.d.ts +11 -0
- package/dist/core/hosts.js +13 -0
- package/dist/core/hosts.js.map +1 -0
- package/dist/core/identify.d.ts +12 -2
- package/dist/core/identify.js +31 -19
- package/dist/core/identify.js.map +1 -1
- package/dist/core/inPlaceOf.d.ts +6 -0
- package/dist/core/inPlaceOf.js +17 -0
- package/dist/core/inPlaceOf.js.map +1 -0
- package/dist/core/invalid.d.ts +32 -9
- package/dist/core/invalid.js +36 -23
- package/dist/core/invalid.js.map +1 -1
- package/dist/core/notFound.d.ts +2 -2
- package/dist/core/notFound.js.map +1 -1
- package/dist/core/read.d.ts +4 -10
- package/dist/core/read.js +1 -11
- package/dist/core/read.js.map +1 -1
- package/dist/core/result.d.ts +14 -10
- package/dist/core/result.js +1 -0
- package/dist/core/result.js.map +1 -1
- package/dist/core/shared.d.ts +15 -9
- package/dist/core/shared.js +8 -6
- package/dist/core/shared.js.map +1 -1
- package/dist/core/signal.d.ts +7 -0
- package/dist/core/signal.js +9 -0
- package/dist/core/signal.js.map +1 -1
- package/dist/first-party/asPerson.d.ts +13 -0
- package/dist/first-party/asPerson.js +144 -0
- package/dist/first-party/asPerson.js.map +1 -0
- package/dist/first-party/attempts.d.ts +71 -0
- package/dist/first-party/attempts.js +132 -0
- package/dist/first-party/attempts.js.map +1 -0
- package/dist/first-party/authProxyMark.d.ts +7 -0
- package/dist/first-party/authProxyMark.js +8 -0
- package/dist/first-party/authProxyMark.js.map +1 -0
- package/dist/first-party/browser.d.ts +55 -0
- package/dist/first-party/browser.js +137 -0
- package/dist/first-party/browser.js.map +1 -0
- package/dist/first-party/browserSession.d.ts +95 -0
- package/dist/first-party/browserSession.js +242 -0
- package/dist/first-party/browserSession.js.map +1 -0
- package/dist/first-party/calls/consent.d.ts +77 -0
- package/dist/first-party/calls/consent.js +174 -0
- package/dist/first-party/calls/consent.js.map +1 -0
- package/dist/first-party/calls/device.d.ts +75 -0
- package/dist/first-party/calls/device.js +133 -0
- package/dist/first-party/calls/device.js.map +1 -0
- package/dist/first-party/calls/invitation.d.ts +198 -0
- package/dist/first-party/calls/invitation.js +240 -0
- package/dist/first-party/calls/invitation.js.map +1 -0
- package/dist/first-party/calls/logIn.d.ts +41 -0
- package/dist/first-party/calls/logIn.js +48 -0
- package/dist/first-party/calls/logIn.js.map +1 -0
- package/dist/first-party/calls/reset.d.ts +58 -0
- package/dist/first-party/calls/reset.js +163 -0
- package/dist/first-party/calls/reset.js.map +1 -0
- package/dist/first-party/calls/signUp.d.ts +21 -0
- package/dist/first-party/calls/signUp.js +72 -0
- package/dist/first-party/calls/signUp.js.map +1 -0
- package/dist/first-party/calls/twoStepSetup.d.ts +55 -0
- package/dist/first-party/calls/twoStepSetup.js +168 -0
- package/dist/first-party/calls/twoStepSetup.js.map +1 -0
- package/dist/first-party/claims.d.ts +88 -0
- package/dist/first-party/claims.js +181 -0
- package/dist/first-party/claims.js.map +1 -0
- package/dist/first-party/enrollment.d.ts +10 -0
- package/dist/first-party/enrollment.js +44 -0
- package/dist/first-party/enrollment.js.map +1 -0
- package/dist/first-party/entry.d.ts +549 -0
- package/dist/first-party/entry.js +580 -0
- package/dist/first-party/entry.js.map +1 -0
- package/dist/first-party/hooks.d.ts +66 -0
- package/dist/first-party/hooks.js +19 -0
- package/dist/first-party/hooks.js.map +1 -0
- package/dist/first-party/http.d.ts +191 -0
- package/dist/first-party/http.js +364 -0
- package/dist/first-party/http.js.map +1 -0
- package/dist/first-party/index.d.ts +14 -0
- package/dist/first-party/index.js +3 -0
- package/dist/first-party/index.js.map +1 -0
- package/dist/first-party/landed.d.ts +32 -0
- package/dist/first-party/landed.js +50 -0
- package/dist/first-party/landed.js.map +1 -0
- package/dist/first-party/landedProof.d.ts +12 -0
- package/dist/first-party/landedProof.js +20 -0
- package/dist/first-party/landedProof.js.map +1 -0
- package/dist/first-party/linkToken.d.ts +16 -0
- package/dist/first-party/linkToken.js +29 -0
- package/dist/first-party/linkToken.js.map +1 -0
- package/dist/first-party/links.d.ts +100 -0
- package/dist/first-party/links.js +84 -0
- package/dist/first-party/links.js.map +1 -0
- package/dist/first-party/locks.d.ts +36 -0
- package/dist/first-party/locks.js +64 -0
- package/dist/first-party/locks.js.map +1 -0
- package/dist/first-party/personTransport.d.ts +38 -0
- package/dist/first-party/personTransport.js +177 -0
- package/dist/first-party/personTransport.js.map +1 -0
- package/dist/first-party/proxy/app.d.ts +25 -0
- package/dist/first-party/proxy/app.js +94 -0
- package/dist/first-party/proxy/app.js.map +1 -0
- package/dist/first-party/proxy/bound.d.ts +5 -0
- package/dist/first-party/proxy/bound.js +13 -0
- package/dist/first-party/proxy/bound.js.map +1 -0
- package/dist/first-party/proxy/cases.d.ts +54 -0
- package/dist/first-party/proxy/cases.js +412 -0
- package/dist/first-party/proxy/cases.js.map +1 -0
- package/dist/first-party/proxy/decide.d.ts +29 -0
- package/dist/first-party/proxy/decide.js +140 -0
- package/dist/first-party/proxy/decide.js.map +1 -0
- package/dist/first-party/proxy/freeze.d.ts +2 -0
- package/dist/first-party/proxy/freeze.js +10 -0
- package/dist/first-party/proxy/freeze.js.map +1 -0
- package/dist/first-party/proxy/handler.d.ts +23 -0
- package/dist/first-party/proxy/handler.js +190 -0
- package/dist/first-party/proxy/handler.js.map +1 -0
- package/dist/first-party/proxy/headers.d.ts +8 -0
- package/dist/first-party/proxy/headers.js +20 -0
- package/dist/first-party/proxy/headers.js.map +1 -0
- package/dist/first-party/proxy/hop.d.ts +9 -0
- package/dist/first-party/proxy/hop.js +37 -0
- package/dist/first-party/proxy/hop.js.map +1 -0
- package/dist/first-party/proxy/host.d.ts +5 -0
- package/dist/first-party/proxy/host.js +11 -0
- package/dist/first-party/proxy/host.js.map +1 -0
- package/dist/first-party/proxy/index.d.ts +7 -0
- package/dist/first-party/proxy/index.js +6 -0
- package/dist/first-party/proxy/index.js.map +1 -0
- package/dist/first-party/proxy/pass-back.d.ts +21 -0
- package/dist/first-party/proxy/pass-back.js +51 -0
- package/dist/first-party/proxy/pass-back.js.map +1 -0
- package/dist/first-party/proxy/paths.d.ts +17 -0
- package/dist/first-party/proxy/paths.js +36 -0
- package/dist/first-party/proxy/paths.js.map +1 -0
- package/dist/first-party/proxy/shown.d.ts +5 -0
- package/dist/first-party/proxy/shown.js +16 -0
- package/dist/first-party/proxy/shown.js.map +1 -0
- package/dist/first-party/proxy/stand-in.d.ts +47 -0
- package/dist/first-party/proxy/stand-in.js +318 -0
- package/dist/first-party/proxy/stand-in.js.map +1 -0
- package/dist/first-party/report.d.ts +47 -0
- package/dist/first-party/report.js +38 -0
- package/dist/first-party/report.js.map +1 -0
- package/dist/first-party/result.d.ts +82 -0
- package/dist/first-party/result.js +40 -0
- package/dist/first-party/result.js.map +1 -0
- package/dist/first-party/session/cell.d.ts +177 -0
- package/dist/first-party/session/cell.js +89 -0
- package/dist/first-party/session/cell.js.map +1 -0
- package/dist/first-party/session/closed.d.ts +8 -0
- package/dist/first-party/session/closed.js +12 -0
- package/dist/first-party/session/closed.js.map +1 -0
- package/dist/first-party/session/index.d.ts +3 -0
- package/dist/first-party/session/index.js +3 -0
- package/dist/first-party/session/index.js.map +1 -0
- package/dist/first-party/session/logout.d.ts +82 -0
- package/dist/first-party/session/logout.js +328 -0
- package/dist/first-party/session/logout.js.map +1 -0
- package/dist/first-party/session/owed.d.ts +30 -0
- package/dist/first-party/session/owed.js +27 -0
- package/dist/first-party/session/owed.js.map +1 -0
- package/dist/first-party/session/refresh.d.ts +19 -0
- package/dist/first-party/session/refresh.js +229 -0
- package/dist/first-party/session/refresh.js.map +1 -0
- package/dist/first-party/session/results.d.ts +38 -0
- package/dist/first-party/session/results.js +74 -0
- package/dist/first-party/session/results.js.map +1 -0
- package/dist/first-party/session/session.d.ts +2 -0
- package/dist/first-party/session/session.js +379 -0
- package/dist/first-party/session/session.js.map +1 -0
- package/dist/first-party/session/shared.d.ts +34 -0
- package/dist/first-party/session/shared.js +104 -0
- package/dist/first-party/session/shared.js.map +1 -0
- package/dist/first-party/session/sharedSignal.d.ts +27 -0
- package/dist/first-party/session/sharedSignal.js +55 -0
- package/dist/first-party/session/sharedSignal.js.map +1 -0
- package/dist/first-party/session/signIn.d.ts +43 -0
- package/dist/first-party/session/signIn.js +294 -0
- package/dist/first-party/session/signIn.js.map +1 -0
- package/dist/first-party/session/signInThrough.d.ts +5 -0
- package/dist/first-party/session/signInThrough.js +95 -0
- package/dist/first-party/session/signInThrough.js.map +1 -0
- package/dist/first-party/session/sync.d.ts +17 -0
- package/dist/first-party/session/sync.js +143 -0
- package/dist/first-party/session/sync.js.map +1 -0
- package/dist/first-party/session/tokens.d.ts +18 -0
- package/dist/first-party/session/tokens.js +64 -0
- package/dist/first-party/session/tokens.js.map +1 -0
- package/dist/first-party/session/types.d.ts +270 -0
- package/dist/first-party/session/types.js +3 -0
- package/dist/first-party/session/types.js.map +1 -0
- package/dist/first-party/sessionWire.d.ts +31 -0
- package/dist/first-party/sessionWire.js +91 -0
- package/dist/first-party/sessionWire.js.map +1 -0
- package/dist/first-party/signInHooks.d.ts +57 -0
- package/dist/first-party/signInHooks.js +2 -0
- package/dist/first-party/signInHooks.js.map +1 -0
- package/dist/first-party/state.d.ts +51 -0
- package/dist/first-party/state.js +52 -0
- package/dist/first-party/state.js.map +1 -0
- package/dist/first-party/strip.d.ts +1 -0
- package/dist/first-party/strip.js +8 -0
- package/dist/first-party/strip.js.map +1 -0
- package/dist/first-party/twoStepLock.d.ts +26 -0
- package/dist/first-party/twoStepLock.js +58 -0
- package/dist/first-party/twoStepLock.js.map +1 -0
- package/dist/first-party/twoStepSession.d.ts +21 -0
- package/dist/first-party/twoStepSession.js +31 -0
- package/dist/first-party/twoStepSession.js.map +1 -0
- package/dist/first-party/wire.d.ts +63 -0
- package/dist/first-party/wire.js +5 -0
- package/dist/first-party/wire.js.map +1 -0
- package/dist/flipstream.d.ts +132 -36
- package/dist/flipstream.js +94 -47
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/node/keychainChild.js +60 -25
- package/dist/node/keychainChild.js.map +1 -1
- package/dist/node/keychainError.d.ts +4 -1
- package/dist/node/keychainError.js.map +1 -1
- package/dist/node/keychainStore.js +42 -8
- package/dist/node/keychainStore.js.map +1 -1
- package/dist/node/session.js +9 -8
- package/dist/node/session.js.map +1 -1
- package/dist/query/query.d.ts +52 -8
- package/dist/query/query.js +133 -19
- package/dist/query/query.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/admin.md +53 -4
- package/docs/first-party.md +278 -0
- package/docs/node-sign-in.md +8 -4
- package/package.json +34 -5
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { FINAL_UNAVAILABLE } from '../core/call.js';
|
|
2
|
+
import { isLoopbackHttp, keepsNoStore, sendRequest } from '../core/fetch.js';
|
|
3
|
+
import { valueHolds } from '../core/identify.js';
|
|
4
|
+
import { stopListening } from '../core/signal.js';
|
|
5
|
+
import { refusedRedirect } from './http.js';
|
|
6
|
+
const CLOSED = { kind: 'cancelled', reason: 'session-closed' };
|
|
7
|
+
const CHANGED = { kind: 'cancelled', reason: 'principal-changed' };
|
|
8
|
+
const ABORTED = { kind: 'aborted' };
|
|
9
|
+
const UNAVAILABLE = { kind: 'unavailable' };
|
|
10
|
+
const DESTINATION = { kind: 'refused', reason: 'destination' };
|
|
11
|
+
const NO_TOKEN = () => ({ kind: 'no_token', cause: new TypeError('the session has no token') });
|
|
12
|
+
function discard(response) {
|
|
13
|
+
void response.body?.cancel().catch(() => undefined);
|
|
14
|
+
}
|
|
15
|
+
/** The caller can stop waiting for credentials or a shared renewal without aborting that renewal. */
|
|
16
|
+
export async function untilAborted(signal, work) {
|
|
17
|
+
if (signal.aborted)
|
|
18
|
+
return ABORTED;
|
|
19
|
+
let stop = () => undefined;
|
|
20
|
+
const ended = new Promise((resolve) => {
|
|
21
|
+
stop = () => resolve(ABORTED);
|
|
22
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
return await Promise.race([work(), ended]);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
stopListening(signal, stop);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** A page's own proxy never receives a bearer, including when a service shares the page's origin. */
|
|
32
|
+
export function allowsProxyFreePath(url, proxy) {
|
|
33
|
+
if (url.origin !== proxy.origin)
|
|
34
|
+
return true;
|
|
35
|
+
// Routers can decode a path before matching it. Ambiguous escaped separators have no place
|
|
36
|
+
// on a direct SDK route which shares an origin with the cookie proxy.
|
|
37
|
+
if (/%(?:2f|5c|25)/i.test(url.pathname))
|
|
38
|
+
return false;
|
|
39
|
+
try {
|
|
40
|
+
const path = proxyPath(url);
|
|
41
|
+
// Removing parameters or controls can reveal dot segments after URL parsing.
|
|
42
|
+
if (path.split('/').some(segment => segment === '.' || segment === '..'))
|
|
43
|
+
return false;
|
|
44
|
+
const base = proxyPath(proxy);
|
|
45
|
+
return base !== '' && path !== base && !path.startsWith(base + '/');
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Match the path as a router may read it: case-insensitive, without controls, parameters or empty segments.
|
|
52
|
+
function proxyPath(url) {
|
|
53
|
+
return decodeURIComponent(url.pathname).toLowerCase().replace(/\p{Cc}/gu, '').replace(/;[^/]*/g, '')
|
|
54
|
+
.split('/').filter(Boolean).join('/');
|
|
55
|
+
}
|
|
56
|
+
/** A client keeps its pin; each family call has a sender of its own. */
|
|
57
|
+
export function personSender(session, deps) {
|
|
58
|
+
const proxy = deps.origin === 'null' ? null : new URL(deps.authPath || '/', deps.origin);
|
|
59
|
+
const allowed = (service, url) => {
|
|
60
|
+
const host = deps.hosts[service];
|
|
61
|
+
return host !== undefined && url.origin === new URL(host).origin &&
|
|
62
|
+
(url.protocol === 'https:' || (deps.allowLocalhostHttp === true && isLoopbackHttp(url))) &&
|
|
63
|
+
(proxy === null || allowsProxyFreePath(url, proxy));
|
|
64
|
+
};
|
|
65
|
+
return (revision, onRedirect) => {
|
|
66
|
+
const current = () => revision === undefined || session.isCurrent(revision);
|
|
67
|
+
const matchesDisplay = (shown) => {
|
|
68
|
+
revision ??= shown;
|
|
69
|
+
return revision === shown;
|
|
70
|
+
};
|
|
71
|
+
// Admission also runs for tokenless and local client calls. A family goes straight to send.
|
|
72
|
+
const pinAtPress = () => {
|
|
73
|
+
if (revision === undefined) {
|
|
74
|
+
const shown = session.current();
|
|
75
|
+
if (shown.status !== 'signed-in')
|
|
76
|
+
return shown.status;
|
|
77
|
+
revision = shown.revision;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
async function send(call, fetch, checks) {
|
|
82
|
+
for (let attempt = 0;; attempt++) {
|
|
83
|
+
if (session.isClosed())
|
|
84
|
+
return CLOSED;
|
|
85
|
+
if (call.signal.aborted)
|
|
86
|
+
return ABORTED;
|
|
87
|
+
// Capture what the page shows before any await can adopt another tab's session.
|
|
88
|
+
const absent = pinAtPress();
|
|
89
|
+
if (absent !== undefined)
|
|
90
|
+
return absent === 'signed-out' || absent === 'unsupported' ? NO_TOKEN() : FINAL_UNAVAILABLE;
|
|
91
|
+
if (!current())
|
|
92
|
+
return CHANGED;
|
|
93
|
+
// The main client supplies a request factory. Check the URL of the native
|
|
94
|
+
// request snapshot that will be sent, independently of any caller-owned accessors.
|
|
95
|
+
const built = new Request(call.makeRequest());
|
|
96
|
+
if (!allowed(call.service, new URL(built.url)))
|
|
97
|
+
return DESTINATION;
|
|
98
|
+
// The page's Request was checked when the session was made; one swapped since that no
|
|
99
|
+
// longer keeps no-store fails the call closed, before a token is asked: never a bearer
|
|
100
|
+
// request without it (SDK-D2013).
|
|
101
|
+
if (!keepsNoStore())
|
|
102
|
+
return FINAL_UNAVAILABLE;
|
|
103
|
+
const held = await session.getAccessToken();
|
|
104
|
+
if (session.isClosed())
|
|
105
|
+
return CLOSED;
|
|
106
|
+
if (call.signal.aborted)
|
|
107
|
+
return ABORTED;
|
|
108
|
+
if (!current())
|
|
109
|
+
return CHANGED;
|
|
110
|
+
if (held.kind === 'unavailable')
|
|
111
|
+
return UNAVAILABLE;
|
|
112
|
+
if (held.kind === 'signed-out')
|
|
113
|
+
return NO_TOKEN();
|
|
114
|
+
// The stored principal may already have changed while getAccessToken still had an
|
|
115
|
+
// unexpired local token (C2). Check the returned revision even on the first send.
|
|
116
|
+
if (!session.isCurrent(held.revision) || revision !== held.revision) {
|
|
117
|
+
return CHANGED;
|
|
118
|
+
}
|
|
119
|
+
const headers = new Headers(built.headers);
|
|
120
|
+
for (const name of ['user-agent', 'flipstream-client', 'baggage']) {
|
|
121
|
+
if (valueHolds(headers.get(name) ?? '', held.token))
|
|
122
|
+
return { kind: 'refused', reason: 'identification' };
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
headers.set('Authorization', 'Bearer ' + held.token);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// A platform header exception may repeat the value it rejected.
|
|
129
|
+
return NO_TOKEN();
|
|
130
|
+
}
|
|
131
|
+
// The person is checked before the send and before the answer is handed back: no HTTP
|
|
132
|
+
// cache, so the browser can't answer in between with another person's body (SDK-D2013).
|
|
133
|
+
const sent = await sendRequest(fetch, built, headers, call.signal, { noStore: true });
|
|
134
|
+
if (sent.kind !== 'sent')
|
|
135
|
+
return current() ? sent : CHANGED;
|
|
136
|
+
const { response } = sent;
|
|
137
|
+
// Only a successful code-issuing call can specify a recipient across revisions.
|
|
138
|
+
// A 401 still belongs to the revision that sent it, before any renewal or replay.
|
|
139
|
+
if (call.signal.aborted || !(checks?.canDeliver && response.ok ? checks.canDeliver() : current())) {
|
|
140
|
+
discard(response);
|
|
141
|
+
return call.signal.aborted ? ABORTED : CHANGED;
|
|
142
|
+
}
|
|
143
|
+
// The family reports its own invalid answer. A main client reports its bearer redirect here.
|
|
144
|
+
if (refusedRedirect(response.status)) {
|
|
145
|
+
onRedirect?.({ path: new URL(built.url).pathname, status: response.status });
|
|
146
|
+
}
|
|
147
|
+
if (attempt !== 0)
|
|
148
|
+
return { kind: 'response', response };
|
|
149
|
+
if (response.status !== 401) {
|
|
150
|
+
if (response.status !== 200 || !checks?.isUnauthorized || !await checks.isUnauthorized(response)) {
|
|
151
|
+
return { kind: 'response', response };
|
|
152
|
+
}
|
|
153
|
+
// The page can change person while the consent response body is being read.
|
|
154
|
+
if (!current())
|
|
155
|
+
return CHANGED;
|
|
156
|
+
}
|
|
157
|
+
discard(response);
|
|
158
|
+
if (session.isClosed())
|
|
159
|
+
return CLOSED;
|
|
160
|
+
checks?.beforeRenewal?.();
|
|
161
|
+
if (call.signal.aborted)
|
|
162
|
+
return ABORTED;
|
|
163
|
+
const renewed = await session.refreshAfterUnauthorized(held.token);
|
|
164
|
+
if (call.signal.aborted)
|
|
165
|
+
return ABORTED;
|
|
166
|
+
if (!current())
|
|
167
|
+
return CHANGED;
|
|
168
|
+
if (renewed === 'unavailable')
|
|
169
|
+
return UNAVAILABLE;
|
|
170
|
+
if (renewed === 'signed-out')
|
|
171
|
+
return NO_TOKEN();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { current, matchesDisplay, pinAtPress, send: (call, fetch = deps.fetch, checks) => untilAborted(call.signal, () => send(call, fetch, checks)) };
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=personTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personTransport.js","sourceRoot":"","sources":["../../src/first-party/personTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAa3C,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,W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wB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBAClE,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO;oBAAE,OAAO,OAAO,CAAA;gBACvC,IAAI,CAAC,OAAO,EAAE;oBAAE,OAAO,OAAO,CAAA;gBAC9B,IAAI,OAAO,KAAK,aAAa;oBAAE,OAAO,WAAW,CAAA;gBACjD,IAAI,OAAO,KAAK,YAAY;oBAAE,OAAO,QAAQ,EAAE,CAAA;YACjD,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAA;IACxJ,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AUTH_PROXY_COOKIES } from './paths.js';
|
|
2
|
+
/** One name from {@link AUTH_PROXY_COOKIES}. An app lists the ones it passes. */
|
|
3
|
+
export type AuthProxyCookie = (typeof AUTH_PROXY_COOKIES)[number];
|
|
4
|
+
/**
|
|
5
|
+
* The app the proxy is serving. `origin` is what a browser writes in `Origin`. `paths` is what
|
|
6
|
+
* this app forwards: the default is the six paths the session can send. An app leaves out a path its
|
|
7
|
+
* session never sends, and may add a path of its own, where `*` is one whole segment. `cookies` is
|
|
8
|
+
* which of the two refresh names it passes. There is no default.
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthProxyApp {
|
|
11
|
+
/** What a browser writes in `Origin` for this app. */
|
|
12
|
+
readonly origin: string;
|
|
13
|
+
/** What this app forwards. Absent means the six paths the session can send. */
|
|
14
|
+
readonly paths?: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Which of the two refresh names this app passes, on the way up and on the way back.
|
|
17
|
+
* A deployed host with siblings lists only `__Host-refresh_token`.
|
|
18
|
+
*/
|
|
19
|
+
readonly cookies: readonly AuthProxyCookie[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Throw when `app` is not one a browser could be. The message names the value. `caller` is the
|
|
23
|
+
* function the caller used, so the two entries fail the same way.
|
|
24
|
+
*/
|
|
25
|
+
export declare function requireApp(app: AuthProxyApp, caller: string): void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { AUTH_PROXY_COOKIES } from './paths.js';
|
|
2
|
+
import { shown } from './shown.js';
|
|
3
|
+
/** Why `path` cannot be one an app forwards, or undefined when it can. */
|
|
4
|
+
function pathProblem(path) {
|
|
5
|
+
if (path === '')
|
|
6
|
+
return 'it is empty';
|
|
7
|
+
if (path.startsWith('/') || path.endsWith('/'))
|
|
8
|
+
return 'it starts or ends with /';
|
|
9
|
+
if (/[?#%\\]/.test(path))
|
|
10
|
+
return 'it holds ? or # or % or \\';
|
|
11
|
+
for (const segment of path.split('/')) {
|
|
12
|
+
if (segment === '' || segment === '.' || segment === '..')
|
|
13
|
+
return `the segment ${JSON.stringify(segment)} is empty or . or ..`;
|
|
14
|
+
if (segment.includes('*') && segment !== '*')
|
|
15
|
+
return 'a * is not a whole segment';
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
/** A value for an error message, without stringifying an object as `[object Object]`. */
|
|
20
|
+
function named(value) {
|
|
21
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint' || value === null || value === undefined) {
|
|
22
|
+
return String(value);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const text = JSON.stringify(value);
|
|
26
|
+
if (typeof text === 'string')
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// A circular value has no JSON form.
|
|
31
|
+
}
|
|
32
|
+
return 'unprintable';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Throw when `app` is not one a browser could be. The message names the value. `caller` is the
|
|
36
|
+
* function the caller used, so the two entries fail the same way.
|
|
37
|
+
*/
|
|
38
|
+
export function requireApp(app, caller) {
|
|
39
|
+
if (typeof app !== 'object' || app === null || typeof app.origin !== 'string') {
|
|
40
|
+
throw new TypeError(`${caller}: origin is not a browser origin: ${named(app)}`);
|
|
41
|
+
}
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = new URL(app.origin);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new TypeError(`${caller}: origin is not a browser origin: ${shown(app.origin)}`);
|
|
48
|
+
}
|
|
49
|
+
if (parsed.origin !== app.origin) {
|
|
50
|
+
throw new TypeError(`${caller}: origin is not a browser origin: ${shown(app.origin)}`);
|
|
51
|
+
}
|
|
52
|
+
requireCookies(app.cookies, caller);
|
|
53
|
+
if (app.paths === undefined)
|
|
54
|
+
return;
|
|
55
|
+
if (!Array.isArray(app.paths)) {
|
|
56
|
+
throw new TypeError(`${caller}: paths is not a list: ${String(app.paths)}`);
|
|
57
|
+
}
|
|
58
|
+
if (app.paths.length === 0)
|
|
59
|
+
throw new TypeError(`${caller}: paths is empty`);
|
|
60
|
+
for (const entry of app.paths) {
|
|
61
|
+
if (typeof entry !== 'string') {
|
|
62
|
+
throw new TypeError(`${caller}: paths entry is not a proxy path: ${String(entry)}`);
|
|
63
|
+
}
|
|
64
|
+
const problem = pathProblem(entry);
|
|
65
|
+
if (problem !== undefined)
|
|
66
|
+
throw new TypeError(`${caller}: paths entry is not a proxy path: ${entry} (${problem})`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Throw when `cookies` is missing, empty, not one of the two names, or lists a name twice. */
|
|
70
|
+
function requireCookies(cookies, caller) {
|
|
71
|
+
if (cookies === undefined)
|
|
72
|
+
throw new TypeError(`${caller}: cookies is missing`);
|
|
73
|
+
if (!Array.isArray(cookies))
|
|
74
|
+
throw new TypeError(`${caller}: cookies is not a list: ${named(cookies)}`);
|
|
75
|
+
if (cookies.length === 0)
|
|
76
|
+
throw new TypeError(`${caller}: cookies is empty`);
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
for (const entry of cookies) {
|
|
79
|
+
if (!knownCookie(entry))
|
|
80
|
+
throw new TypeError(`${caller}: cookies entry is not a proxy cookie: ${named(entry)}`);
|
|
81
|
+
if (seen.has(entry))
|
|
82
|
+
throw new TypeError(`${caller}: cookies entry is listed twice: ${entry}`);
|
|
83
|
+
seen.add(entry);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function knownCookie(entry) {
|
|
87
|
+
if (typeof entry !== 'string')
|
|
88
|
+
return false;
|
|
89
|
+
for (const cookie of AUTH_PROXY_COOKIES)
|
|
90
|
+
if (cookie === entry)
|
|
91
|
+
return true;
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/first-party/proxy/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAuBlC,0EAA0E;AAC1E,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,aAAa,CAAA;IACrC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,0BAA0B,CAAA;IACjF,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,4BAA4B,CAAA;IAC7D,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,I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,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,MAAM,4BAA4B,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACvG,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,MAAM,oBAAoB,CAAC,CAAA;IAC5E,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,GAAG,MAAM,0CAA0C,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC/G,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,GAAG,MAAM,oCAAoC,KAAK,EAAE,CAAC,CAAA;QAC9F,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACjB,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,KAAK,MAAM,MAAM,IAAI,kBAAkB;QAAE,IAAI,MAAM,KAAK,KAAK;YAAE,OAAO,IAAI,CAAA;IAC1E,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The largest delay `setTimeout` keeps. A larger number, or one that is not finite, becomes 1 ms. */
|
|
2
|
+
const MAX_DELAY_MS = 2_147_483_647;
|
|
3
|
+
/**
|
|
4
|
+
* A delay `setTimeout` will keep. Anything else is a TypeError that names the value.
|
|
5
|
+
* The bound cannot be switched off.
|
|
6
|
+
*/
|
|
7
|
+
export function requireDelay(value, name) {
|
|
8
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > MAX_DELAY_MS) {
|
|
9
|
+
throw new TypeError(`${name} must be a finite number above 0 and at most 2147483647: ${String(value)}`);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=bound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bound.js","sourceRoot":"","sources":["../../../src/first-party/proxy/bound.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,MAAM,YAAY,GAAG,aAAa,CAAA;AAElC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,IAAY;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,YAAY,EAAE,CAAC;QAC/F,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,4DAA4D,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACzG,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type AuthProxyApp } from './app.js';
|
|
2
|
+
/**
|
|
3
|
+
* One row of the agreement. Plain data, so an app can keep it. `upstream_answers` is omitted when
|
|
4
|
+
* the row has no upstream answer: the stand-in then answers 204 with no headers. A record cannot
|
|
5
|
+
* hold one header twice, so two `Set-Cookie` values are checked on `passBack` itself.
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthProxyCase {
|
|
8
|
+
/** What this row is checking, in words. */
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** The request the app's proxy is given. */
|
|
11
|
+
readonly request: {
|
|
12
|
+
readonly method: string;
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
15
|
+
readonly body: 'json' | 'form' | 'none';
|
|
16
|
+
};
|
|
17
|
+
/** The path the stand-in should see, or null when nothing is forwarded. */
|
|
18
|
+
readonly upstream: string | null;
|
|
19
|
+
/** The upstream's answer. Absent: the stand-in answers 204 with no headers. */
|
|
20
|
+
readonly upstream_answers?: readonly (readonly [string, string])[];
|
|
21
|
+
/** What the browser is given, and what the stand-in may see. */
|
|
22
|
+
readonly expect: {
|
|
23
|
+
readonly answer: {
|
|
24
|
+
readonly status: number;
|
|
25
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
26
|
+
readonly absent: readonly string[];
|
|
27
|
+
};
|
|
28
|
+
readonly cookies: Readonly<Record<string, string>>;
|
|
29
|
+
readonly absent: readonly string[];
|
|
30
|
+
readonly not_as_sent: Readonly<Record<string, string>>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A second outcome a correct proxy may give instead, one that normalises the request target
|
|
34
|
+
* as nginx does. The row holds when `upstream` and `expect` hold, or when this does. What the
|
|
35
|
+
* stand-in may see (`expect.cookies`, `expect.absent`, `expect.not_as_sent`) is the same for
|
|
36
|
+
* both. Absent: the row has one outcome.
|
|
37
|
+
*/
|
|
38
|
+
readonly or?: {
|
|
39
|
+
/** The path the stand-in should see, or null when nothing is forwarded. */
|
|
40
|
+
readonly upstream: string | null;
|
|
41
|
+
/** What the browser is given. */
|
|
42
|
+
readonly answer: {
|
|
43
|
+
readonly status: number;
|
|
44
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
45
|
+
readonly absent: readonly string[];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The rows for `app`: one forward for each path it serves, the paths that miss, the guard, the
|
|
51
|
+
* cookies, the headers that are never passed on, and what comes back. A `*` path is sent filled
|
|
52
|
+
* with `abc`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function authProxyCases(app: AuthProxyApp): readonly AuthProxyCase[];
|