@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.
- package/CHANGELOG.md +125 -0
- package/README.md +95 -1
- package/dist/api/datasets.js +8 -8
- package/dist/api/datasets.js.map +1 -1
- package/dist/api/log.js +6 -10
- package/dist/api/log.js.map +1 -1
- package/dist/api/pathArgument.d.ts +7 -0
- package/dist/api/pathArgument.js +12 -0
- package/dist/api/pathArgument.js.map +1 -0
- 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 +4 -0
- package/dist/core/call.js +7 -1
- 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 +6 -2
- package/dist/core/identify.js +16 -12
- package/dist/core/identify.js.map +1 -1
- package/dist/core/result.d.ts +1 -1
- package/dist/core/shared.d.ts +2 -0
- package/dist/core/shared.js +1 -0
- 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 +10 -0
- package/dist/first-party/authProxyMark.js +11 -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 +89 -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 +97 -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 +244 -0
- package/dist/first-party/calls/invitation.js +258 -0
- package/dist/first-party/calls/invitation.js.map +1 -0
- package/dist/first-party/calls/logIn.d.ts +61 -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 +61 -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 +78 -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 +573 -0
- package/dist/first-party/entry.js +582 -0
- package/dist/first-party/entry.js.map +1 -0
- package/dist/first-party/hooks.d.ts +81 -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 +15 -0
- package/dist/first-party/linkToken.js +28 -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 +32 -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 +71 -0
- package/dist/first-party/proxy/cases.js +411 -0
- package/dist/first-party/proxy/cases.js.map +1 -0
- package/dist/first-party/proxy/decide.d.ts +31 -0
- package/dist/first-party/proxy/decide.js +139 -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 +7 -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 +26 -0
- package/dist/first-party/proxy/pass-back.js +47 -0
- package/dist/first-party/proxy/pass-back.js.map +1 -0
- package/dist/first-party/proxy/paths.d.ts +15 -0
- package/dist/first-party/proxy/paths.js +34 -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 +49 -0
- package/dist/first-party/proxy/stand-in.js +341 -0
- package/dist/first-party/proxy/stand-in.js.map +1 -0
- package/dist/first-party/report.d.ts +56 -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 +150 -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 +201 -0
- package/dist/first-party/session/cell.js +103 -0
- package/dist/first-party/session/cell.js.map +1 -0
- package/dist/first-party/session/closed.d.ts +11 -0
- package/dist/first-party/session/closed.js +15 -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 +102 -0
- package/dist/first-party/session/logout.js +526 -0
- package/dist/first-party/session/logout.js.map +1 -0
- package/dist/first-party/session/owed.d.ts +105 -0
- package/dist/first-party/session/owed.js +128 -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 +236 -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 +376 -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 +145 -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 +48 -0
- package/dist/first-party/session/signIn.js +340 -0
- package/dist/first-party/session/signIn.js.map +1 -0
- package/dist/first-party/session/signInThrough.d.ts +6 -0
- package/dist/first-party/session/signInThrough.js +144 -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 +174 -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 +85 -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 +71 -0
- package/dist/first-party/state.js +55 -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 +80 -19
- package/dist/flipstream.js +121 -36
- package/dist/flipstream.js.map +1 -1
- package/dist/node/session.js +3 -1
- package/dist/node/session.js.map +1 -1
- package/dist/version.gen.js +1 -1
- package/docs/first-party.md +300 -0
- package/package.json +34 -5
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { wallClock } from '../core/deadline.js';
|
|
2
|
+
import { keepsNoStore } from '../core/fetch.js';
|
|
3
|
+
import { browserChannel, browserLocks, browserStorage, subscriberErrorReporter, } from './browser.js';
|
|
4
|
+
import { checkLanding } from './attempts.js';
|
|
5
|
+
import { checkCookieCalls, createAuthHttp } from './http.js';
|
|
6
|
+
import { checkLink, requestLink, } from './links.js';
|
|
7
|
+
import { createAuthSession, } from './session/index.js';
|
|
8
|
+
import { SessionClosedError } from './session/closed.js';
|
|
9
|
+
import { owedSlot } from './session/owed.js';
|
|
10
|
+
import { STATE_KEY } from './state.js';
|
|
11
|
+
/**
|
|
12
|
+
* Whether a link can land on the page's own origin: only an http or https origin (scheme, host
|
|
13
|
+
* and port, nothing more) can. Anything else (`'null'`, what an opaque origin reads as; `file://`;
|
|
14
|
+
* an extension's; a string that doesn't parse) is a session nobody can sign in to. Never a
|
|
15
|
+
* RangeError: the origin is the page's, not an option the developer gives (SDK-D1934).
|
|
16
|
+
*/
|
|
17
|
+
export function linkCanLand(origin) {
|
|
18
|
+
let url;
|
|
19
|
+
try {
|
|
20
|
+
url = new URL(origin);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return (url.protocol === 'https:' || url.protocol === 'http:') && url.origin === origin;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The browser session and its whole session beside it, credentials included: for this module's
|
|
29
|
+
* browser events and the tests. os's createAuthInternals, without the console's own parts.
|
|
30
|
+
*/
|
|
31
|
+
export function createFirstPartyInternals(deps) {
|
|
32
|
+
// A wrong address fails here, where the session is made, not on a person's first click, with
|
|
33
|
+
// an attempt left behind (#464's round 2, finding 4).
|
|
34
|
+
checkLanding(deps.landing);
|
|
35
|
+
const opaque = !linkCanLand(deps.origin);
|
|
36
|
+
// A page whose origin is opaque, or not http (a sandboxed frame, a file, an extension), has no
|
|
37
|
+
// address a link can land on: nobody can sign in there, as in a browser without locks or storage.
|
|
38
|
+
const storage = opaque ? null : deps.storage;
|
|
39
|
+
const locks = opaque ? null : deps.locks;
|
|
40
|
+
// An origin the page cannot land on is not given to the cookie client. createAuthHttp throws
|
|
41
|
+
// on one that does not parse, and this session is the inert one instead (SDK-D1934).
|
|
42
|
+
const http = createAuthHttp(deps.fetch, deps.now, deps.authPath, opaque ? undefined : deps.origin);
|
|
43
|
+
const session = createAuthSession({
|
|
44
|
+
http,
|
|
45
|
+
locks,
|
|
46
|
+
storage,
|
|
47
|
+
channel: deps.channel,
|
|
48
|
+
report: deps.report,
|
|
49
|
+
reportError: deps.reportError,
|
|
50
|
+
now: deps.now,
|
|
51
|
+
owed: opaque ? null : deps.owed,
|
|
52
|
+
});
|
|
53
|
+
const links = {
|
|
54
|
+
http,
|
|
55
|
+
// A browser without locks is unsupported: a link mailed from it could never be redeemed here,
|
|
56
|
+
// so no attempt is stored and nothing is asked (the Codex read of 254279c, 1).
|
|
57
|
+
storage: locks === null ? null : storage,
|
|
58
|
+
origin: deps.origin,
|
|
59
|
+
landing: deps.landing,
|
|
60
|
+
now: deps.now,
|
|
61
|
+
random: deps.random,
|
|
62
|
+
};
|
|
63
|
+
let sent = null;
|
|
64
|
+
// The page's calls that send follow the session's close(): a closed one sends nothing.
|
|
65
|
+
let closed = false;
|
|
66
|
+
const stillOpen = (call) => {
|
|
67
|
+
if (closed)
|
|
68
|
+
throw new SessionClosedError(call);
|
|
69
|
+
};
|
|
70
|
+
// Its own object, not the session narrowed by a type: what the page holds has no credential
|
|
71
|
+
// to reach, whatever it does with it.
|
|
72
|
+
const view = {
|
|
73
|
+
current: () => session.current(),
|
|
74
|
+
subscribe: (listener) => session.subscribe(listener),
|
|
75
|
+
ready: () => session.ready(),
|
|
76
|
+
start: () => {
|
|
77
|
+
session.start();
|
|
78
|
+
},
|
|
79
|
+
retry: () => {
|
|
80
|
+
session.retry();
|
|
81
|
+
},
|
|
82
|
+
twoStepPending: () => session.twoStepPending(),
|
|
83
|
+
twoStepEndedByTab: () => session.twoStepEndedByTab(),
|
|
84
|
+
verifyTwoStep: (code, signal, onSend) => session.verifyTwoStep(code, signal, onSend),
|
|
85
|
+
signOut: () => session.signOut(),
|
|
86
|
+
sync: () => session.sync(),
|
|
87
|
+
stateWritten: () => session.stateWritten(),
|
|
88
|
+
close: () => {
|
|
89
|
+
closed = true;
|
|
90
|
+
session.close();
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const browser = {
|
|
94
|
+
session: view,
|
|
95
|
+
async requestLink(email, next, signal) {
|
|
96
|
+
stillOpen('requestLink()');
|
|
97
|
+
const result = await requestLink(links, email, next, signal);
|
|
98
|
+
if (result.kind === 'sent')
|
|
99
|
+
sent = { email: result.email, next, at: deps.now() };
|
|
100
|
+
return result;
|
|
101
|
+
},
|
|
102
|
+
lastSent: () => sent,
|
|
103
|
+
checkLink: (link) => {
|
|
104
|
+
const check = checkLink(storage, { ...link, token: deps.linkToken }, deps.now());
|
|
105
|
+
if (check.kind !== 'ready')
|
|
106
|
+
return check;
|
|
107
|
+
return {
|
|
108
|
+
kind: 'ready',
|
|
109
|
+
email: check.email,
|
|
110
|
+
attemptId: check.attemptId,
|
|
111
|
+
attempt: check.attempt,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
redeem: (link, signal) => {
|
|
115
|
+
if (closed)
|
|
116
|
+
return Promise.reject(new SessionClosedError('redeem()'));
|
|
117
|
+
const check = checkLink(storage, { token: deps.linkToken, attempt: link.attemptId, email: link.email }, deps.now());
|
|
118
|
+
if (check.kind !== 'ready')
|
|
119
|
+
return Promise.resolve({ kind: 'dead-link' });
|
|
120
|
+
return session.redeem(check.token, check.attemptId, signal);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
return { browser, session, linkDeps: links };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* This page's slots for an owed logout, by origin and auth path (sdk#483): a module lives as long
|
|
127
|
+
* as its page, so a session made after another closed (a remount, a hot reload) finds what it left.
|
|
128
|
+
*/
|
|
129
|
+
const pageSlots = new Map();
|
|
130
|
+
function pageSlot(key) {
|
|
131
|
+
const known = pageSlots.get(key);
|
|
132
|
+
if (known !== undefined)
|
|
133
|
+
return known;
|
|
134
|
+
const slot = owedSlot();
|
|
135
|
+
pageSlots.set(key, slot);
|
|
136
|
+
return slot;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The real browser's edges: localStorage, Web Locks and a BroadcastChannel (either of the first
|
|
140
|
+
* two missing makes the session `unsupported`), with the console's names, so its tabs and the
|
|
141
|
+
* console's take turns; this page's fetch, the wall clock and the browser's random bytes.
|
|
142
|
+
* An unsupported session opens no channel. Firefox throws from the constructor when storage
|
|
143
|
+
* is denied, and there is then nothing to close (SDK-D1940).
|
|
144
|
+
*/
|
|
145
|
+
export function browserDeps(options) {
|
|
146
|
+
const locks = browserLocks();
|
|
147
|
+
const storage = browserStorage();
|
|
148
|
+
return {
|
|
149
|
+
...options,
|
|
150
|
+
owed: pageSlot(`${options.origin}${options.authPath}`),
|
|
151
|
+
reportError: subscriberErrorReporter(globalThis),
|
|
152
|
+
// A wrapper, so the browser's own fetch is called with its own `this`.
|
|
153
|
+
fetch: (input, init) => fetch(input, init),
|
|
154
|
+
locks,
|
|
155
|
+
storage,
|
|
156
|
+
channel: locks === null || storage === null ? null : browserChannel('flipstream-auth'),
|
|
157
|
+
now: wallClock,
|
|
158
|
+
random: (bytes) => crypto.getRandomValues(bytes),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The browser session in a real browser (browserDeps), and the events that keep its tabs in
|
|
163
|
+
* step. `start()` is the caller's, after it has subscribed.
|
|
164
|
+
*/
|
|
165
|
+
export function createBrowserSession(options) {
|
|
166
|
+
return createBrowserInternals(options).browser;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* `createBrowserSession`, with its whole session beside it, for the entry's hooks (#465): what
|
|
170
|
+
* only the families read (the set-up challenge, the signed-in address), never the page.
|
|
171
|
+
* `browser.session.close()` also takes the browser's events off.
|
|
172
|
+
*/
|
|
173
|
+
export function createBrowserInternals(options) {
|
|
174
|
+
// Before anything is opened: a wrong landing must not leave a channel
|
|
175
|
+
// behind (SDK-D1934). A cookie path that would leave the page is checked once the page can
|
|
176
|
+
// take a link, still before the channel, because that is the path which opens one.
|
|
177
|
+
checkLanding(options.landing);
|
|
178
|
+
// Outside a page (a server render, a prerender, a worker), or in a page whose origin can't take
|
|
179
|
+
// a link (a sandboxed frame or a data: page, whose origin is null; a file; an extension): an
|
|
180
|
+
// unsupported session, with no channel and no listener, so nothing holds the process and nothing
|
|
181
|
+
// needs closing. Its storage is never read: a sandboxed frame throws on localStorage.
|
|
182
|
+
// So is a page whose global Request doesn't keep `cache: 'no-store'` (one with no native fetch,
|
|
183
|
+
// where a polyfill such as whatwg-fetch fills it in): the person's bearer requests would go where
|
|
184
|
+
// its HTTP cache can answer them, and such a fetch can't keep `redirect: 'manual'` either
|
|
185
|
+
// (SDK-D2013, SDK-D1953). The check reads `Request`, not `fetch`; the person sender asks it again
|
|
186
|
+
// at each send.
|
|
187
|
+
if (typeof window === 'undefined' || typeof document === 'undefined' || !linkCanLand(options.origin) || !keepsNoStore()) {
|
|
188
|
+
return createFirstPartyInternals({
|
|
189
|
+
...options,
|
|
190
|
+
reportError: subscriberErrorReporter(globalThis),
|
|
191
|
+
fetch: (input, init) => fetch(input, init),
|
|
192
|
+
locks: null,
|
|
193
|
+
storage: null,
|
|
194
|
+
channel: null,
|
|
195
|
+
now: wallClock,
|
|
196
|
+
random: (bytes) => crypto.getRandomValues(bytes),
|
|
197
|
+
owed: null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// The cookie client throws when the path would leave this page. Prove that before the
|
|
201
|
+
// channel is opened, so the throw leaves nothing to close (SDK-D1934).
|
|
202
|
+
checkCookieCalls(options.authPath, options.origin);
|
|
203
|
+
const { browser, session, linkDeps } = createFirstPartyInternals(browserDeps(options));
|
|
204
|
+
// Another tab changed the shared state: catch up at once, even if its message never comes.
|
|
205
|
+
const stored = (event) => {
|
|
206
|
+
if (event.key === STATE_KEY || event.key === null)
|
|
207
|
+
void session.stateWritten();
|
|
208
|
+
};
|
|
209
|
+
// A laptop waking up can hold an expired token whose timer fired late, or have missed a
|
|
210
|
+
// sign-out in another tab: check on the way back.
|
|
211
|
+
const shown = () => {
|
|
212
|
+
if (document.visibilityState === 'visible')
|
|
213
|
+
void session.getAccessToken();
|
|
214
|
+
};
|
|
215
|
+
// Back online: don't wait out the backoff, and send a logout still owed.
|
|
216
|
+
const online = () => {
|
|
217
|
+
if (session.current().status === 'unavailable')
|
|
218
|
+
session.retry();
|
|
219
|
+
else
|
|
220
|
+
void session.sync();
|
|
221
|
+
};
|
|
222
|
+
window.addEventListener('storage', stored);
|
|
223
|
+
document.addEventListener('visibilitychange', shown);
|
|
224
|
+
window.addEventListener('online', online);
|
|
225
|
+
return {
|
|
226
|
+
session,
|
|
227
|
+
linkDeps,
|
|
228
|
+
browser: {
|
|
229
|
+
...browser,
|
|
230
|
+
session: {
|
|
231
|
+
...browser.session,
|
|
232
|
+
close: () => {
|
|
233
|
+
window.removeEventListener('storage', stored);
|
|
234
|
+
document.removeEventListener('visibilitychange', shown);
|
|
235
|
+
window.removeEventListener('online', online);
|
|
236
|
+
browser.session.close();
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=browserSession.js.map
|
|
@@ -0,0 +1 @@
|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Answer, type WireRequest } from '../wire.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read from the page's own address, with nothing sent.
|
|
5
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#consentrequest
|
|
6
|
+
*/
|
|
7
|
+
export type ConsentRequest = {
|
|
8
|
+
readonly kind: 'asking';
|
|
9
|
+
readonly client_id: string;
|
|
10
|
+
/**
|
|
11
|
+
* The host of `redirect_uri`, worked out by the SDK: `URL.host`, so with its port when that isn't the scheme's own (`localhost:5173`).
|
|
12
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#consentrequest
|
|
13
|
+
*/
|
|
14
|
+
readonly redirect_host: string;
|
|
15
|
+
readonly scopes: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The address holds no authorize request, or one that can't be read.
|
|
19
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#consentrequest
|
|
20
|
+
*/
|
|
21
|
+
| {
|
|
22
|
+
readonly kind: 'invalid';
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The request this session showed, which the page can pass back to approve or deny.
|
|
26
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#consentrequest
|
|
27
|
+
*/
|
|
28
|
+
export type AskingConsent = Extract<ConsentRequest, {
|
|
29
|
+
readonly kind: 'asking';
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* What can stop an approval or a denial.
|
|
33
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approveconsent-denyconsent
|
|
34
|
+
*/
|
|
35
|
+
export type ConsentStop = AsPerson
|
|
36
|
+
/**
|
|
37
|
+
* pulse-auth cannot identify the app, resolve its metadata, or match its registered return address.
|
|
38
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approveconsent-denyconsent
|
|
39
|
+
*/
|
|
40
|
+
| {
|
|
41
|
+
readonly kind: 'unknown_client';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A scope this app may not ask for.
|
|
45
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approveconsent-denyconsent
|
|
46
|
+
*/
|
|
47
|
+
| {
|
|
48
|
+
readonly kind: 'invalid_scope';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A resource pulse-auth will not issue a token for.
|
|
52
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approveconsent-denyconsent
|
|
53
|
+
*/
|
|
54
|
+
| {
|
|
55
|
+
readonly kind: 'invalid_target';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A press is pending or may already have answered this request.
|
|
59
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approveconsent-denyconsent
|
|
60
|
+
*/
|
|
61
|
+
| {
|
|
62
|
+
readonly kind: 'answered';
|
|
63
|
+
};
|
|
64
|
+
interface ConsentCalls {
|
|
65
|
+
readonly consentRequest: () => ConsentRequest;
|
|
66
|
+
/** `redirect_to`: where the browser goes next, the app's own return address with its code. */
|
|
67
|
+
readonly approveConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
|
|
68
|
+
readonly redirect_to: string;
|
|
69
|
+
}, ConsentStop>>;
|
|
70
|
+
/** `redirect_to` carries the refusal back to the app. */
|
|
71
|
+
readonly denyConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
|
|
72
|
+
readonly redirect_to: string;
|
|
73
|
+
}, ConsentStop>>;
|
|
74
|
+
}
|
|
75
|
+
interface AuthorizeFields {
|
|
76
|
+
readonly client_id: string;
|
|
77
|
+
readonly redirect_uri: string;
|
|
78
|
+
readonly scope: string;
|
|
79
|
+
readonly state?: string;
|
|
80
|
+
readonly code_challenge?: string;
|
|
81
|
+
readonly code_challenge_method?: string;
|
|
82
|
+
readonly resource?: string;
|
|
83
|
+
}
|
|
84
|
+
type ConsentResult = Awaited<ReturnType<ConsentCalls['approveConsent']>>;
|
|
85
|
+
export declare function readConsentRequest(href: string): ConsentRequest;
|
|
86
|
+
export declare function consentPost(fields: AuthorizeFields, consent: boolean): WireRequest;
|
|
87
|
+
export declare function readConsentAnswer(answer: WireAnswer, fields: AuthorizeFields, consent: boolean): ConsentResult;
|
|
88
|
+
export declare function createConsentCalls(wire: Wire, href: () => string, shownRevision: () => number | 'signed_out' | undefined): ConsentCalls;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { checkSignal } from '../../core/signal.js';
|
|
3
|
+
import { emptyFields, ok, stopped } from '../result.js';
|
|
4
|
+
import { isUnavailable } from '../wire.js';
|
|
5
|
+
const PATH = '/oauth/authorize';
|
|
6
|
+
function absoluteUrl(value) {
|
|
7
|
+
try {
|
|
8
|
+
return new URL(value);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// oauth_internal/__init__.py:1931-1983. Only the callback itself identifies the host on screen.
|
|
15
|
+
function readAddress(href) {
|
|
16
|
+
const page = absoluteUrl(href);
|
|
17
|
+
if (page === null)
|
|
18
|
+
return null;
|
|
19
|
+
const query = page.searchParams;
|
|
20
|
+
const client_id = query.get('client_id') ?? '';
|
|
21
|
+
const redirect_uri = query.get('redirect_uri') ?? '';
|
|
22
|
+
const scope = query.get('scope') ?? '';
|
|
23
|
+
if (emptyFields({ client_id, redirect_uri, scope }, ['client_id', 'redirect_uri', 'scope']).length > 0)
|
|
24
|
+
return null;
|
|
25
|
+
// Check the raw authority before URL normalizes whitespace, slashes or empty userinfo.
|
|
26
|
+
const authority = /^https?:\/\/([^/?#]+)/i.exec(redirect_uri)?.[1];
|
|
27
|
+
if (!authority || authority.includes('@') || /[\\\s\p{Cc}]/u.test(redirect_uri))
|
|
28
|
+
return null;
|
|
29
|
+
const redirect = absoluteUrl(redirect_uri);
|
|
30
|
+
if (redirect === null || (redirect.protocol !== 'https:' && redirect.protocol !== 'http:') || redirect_uri.includes('#'))
|
|
31
|
+
return null;
|
|
32
|
+
const optional = {};
|
|
33
|
+
for (const key of ['state', 'code_challenge', 'code_challenge_method', 'resource']) {
|
|
34
|
+
const value = query.get(key);
|
|
35
|
+
if (value !== null)
|
|
36
|
+
optional[key] = value;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
request: Object.freeze({ kind: 'asking', client_id, redirect_host: redirect.host, scopes: Object.freeze(scope.split(' ').filter(Boolean)) }),
|
|
40
|
+
fields: { client_id, redirect_uri, scope, ...optional },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const invalidRequest = Object.freeze({ kind: 'invalid' });
|
|
44
|
+
export function readConsentRequest(href) {
|
|
45
|
+
return readAddress(href)?.request ?? invalidRequest;
|
|
46
|
+
}
|
|
47
|
+
// oauth/ingress/fastapi/__init__.py:315-331, 689-716. Both presses send consent explicitly.
|
|
48
|
+
export function consentPost(fields, consent) {
|
|
49
|
+
return { method: 'POST', path: PATH, body: { ...fields, consent } };
|
|
50
|
+
}
|
|
51
|
+
const Redirect = z.object({ redirect_url: z.string() });
|
|
52
|
+
const UnknownClient = z.object({ error: z.enum(['invalid_request', 'invalid_client']) });
|
|
53
|
+
export function readConsentAnswer(answer, fields, consent) {
|
|
54
|
+
// oauth_internal/__init__.py:587-596 checks the client and its registered callback.
|
|
55
|
+
if (answer.status === 400 && UnknownClient.safeParse(answer.body).success)
|
|
56
|
+
return stopped({ kind: 'unknown_client' });
|
|
57
|
+
if (isUnavailable(answer))
|
|
58
|
+
return stopped({ kind: 'unavailable' });
|
|
59
|
+
const invalid = stopped({ kind: 'invalid' });
|
|
60
|
+
if (answer.status !== 200)
|
|
61
|
+
return invalid;
|
|
62
|
+
const parsed = Redirect.safeParse(answer.body);
|
|
63
|
+
if (!parsed.success)
|
|
64
|
+
return invalid;
|
|
65
|
+
const url = absoluteUrl(parsed.data.redirect_url);
|
|
66
|
+
const target = absoluteUrl(fields.redirect_uri);
|
|
67
|
+
if (url === null || target === null || url.origin !== target.origin || url.pathname !== target.pathname)
|
|
68
|
+
return invalid;
|
|
69
|
+
// oauth_internal/__init__.py:602-681 appends '?' even to a callback with a query.
|
|
70
|
+
// Its last field then absorbs the response and a pre-existing code could look newly issued.
|
|
71
|
+
if (target.search !== '' && url.search.startsWith(target.search + '?'))
|
|
72
|
+
return invalid;
|
|
73
|
+
// oauth_internal/__init__.py:602,608,645,655,681 echoes state on every redirect.
|
|
74
|
+
const states = url.searchParams.getAll('state');
|
|
75
|
+
if (fields.state !== undefined && (states.length !== 1 || states[0] !== fields.state))
|
|
76
|
+
return invalid;
|
|
77
|
+
const codes = url.searchParams.getAll('code');
|
|
78
|
+
const errors = url.searchParams.getAll('error');
|
|
79
|
+
const redirect = { redirect_to: parsed.data.redirect_url };
|
|
80
|
+
if (errors.length === 0) {
|
|
81
|
+
// oauth_internal/__init__.py:657-681 issues exactly one code after approval.
|
|
82
|
+
return consent && codes.length === 1 && codes[0]?.trim() ? ok(redirect) : invalid;
|
|
83
|
+
}
|
|
84
|
+
if (codes.length !== 0 || errors.length !== 1)
|
|
85
|
+
return invalid;
|
|
86
|
+
switch (errors[0]) {
|
|
87
|
+
case 'access_denied': return consent ? invalid : ok(redirect); // oauth_internal/__init__.py:600-602
|
|
88
|
+
case 'login_required': return consent ? stopped({ kind: 'signed_out' }) : invalid; // oauth_internal/__init__.py:604-608
|
|
89
|
+
case 'invalid_scope': return stopped({ kind: 'invalid_scope' }); // oauth_internal/__init__.py:640-645
|
|
90
|
+
case 'invalid_target': return stopped({ kind: 'invalid_target' }); // oauth_internal/__init__.py:647-655
|
|
91
|
+
default: return invalid;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function createConsentCalls(wire, href, shownRevision) {
|
|
95
|
+
// Bind each view to the exact parameters it showed, even across a later read of the address.
|
|
96
|
+
const shown = new WeakMap();
|
|
97
|
+
let owner;
|
|
98
|
+
let taken = new Set();
|
|
99
|
+
async function send(request, consent, options) {
|
|
100
|
+
const fields = shown.get(request);
|
|
101
|
+
const call = consent ? 'approveConsent' : 'denyConsent';
|
|
102
|
+
if (fields === undefined)
|
|
103
|
+
throw new TypeError(call + '() takes the request consentRequest() returned, as it is');
|
|
104
|
+
checkSignal(call, options);
|
|
105
|
+
if (options?.signal?.aborted)
|
|
106
|
+
return stopped({ kind: 'aborted' });
|
|
107
|
+
const revision = shownRevision();
|
|
108
|
+
if (revision === 'signed_out')
|
|
109
|
+
return stopped({ kind: 'signed_out' });
|
|
110
|
+
if (revision !== undefined && revision !== owner) {
|
|
111
|
+
taken = new Set();
|
|
112
|
+
owner = revision;
|
|
113
|
+
}
|
|
114
|
+
const key = JSON.stringify([fields.client_id, fields.redirect_uri, fields.state, fields.code_challenge,
|
|
115
|
+
fields.code_challenge_method, fields.resource, fields.scope]);
|
|
116
|
+
// A later sign-in has its own set, even if an earlier press is still settling.
|
|
117
|
+
const reservations = revision === undefined ? undefined : taken;
|
|
118
|
+
if (reservations?.has(key))
|
|
119
|
+
return stopped({ kind: 'answered' });
|
|
120
|
+
reservations?.add(key);
|
|
121
|
+
let keepReservation = false;
|
|
122
|
+
const onSend = () => { keepReservation = true; };
|
|
123
|
+
try {
|
|
124
|
+
const answer = await wire.asPerson(consentPost(fields, consent), options, consent ? {
|
|
125
|
+
onSend,
|
|
126
|
+
isUnauthorized(reply) {
|
|
127
|
+
const result = readConsentAnswer(reply, fields, true);
|
|
128
|
+
if (result.ok || result.error.kind !== 'signed_out')
|
|
129
|
+
return false;
|
|
130
|
+
// The anonymous request did nothing. Keep the reservation until the replay settles.
|
|
131
|
+
keepReservation = false;
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
} : { onSend });
|
|
135
|
+
if (answer.kind !== 'answer')
|
|
136
|
+
return stopped(answer);
|
|
137
|
+
const result = readConsentAnswer(answer, fields, consent);
|
|
138
|
+
if (!result.ok) {
|
|
139
|
+
switch (result.error.kind) {
|
|
140
|
+
case 'unknown_client':
|
|
141
|
+
case 'invalid_scope':
|
|
142
|
+
case 'invalid_target':
|
|
143
|
+
case 'signed_out': // A checked login_required on approve. Neither a code nor a denial was issued.
|
|
144
|
+
keepReservation = false;
|
|
145
|
+
break;
|
|
146
|
+
case 'unavailable':
|
|
147
|
+
if (answer.status === 429)
|
|
148
|
+
keepReservation = false;
|
|
149
|
+
break;
|
|
150
|
+
case 'invalid':
|
|
151
|
+
wire.report({ path: PATH, status: answer.status });
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
if (!keepReservation)
|
|
159
|
+
reservations?.delete(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
consentRequest() {
|
|
164
|
+
const read = readAddress(href());
|
|
165
|
+
if (read === null)
|
|
166
|
+
return invalidRequest;
|
|
167
|
+
shown.set(read.request, read.fields);
|
|
168
|
+
return read.request;
|
|
169
|
+
},
|
|
170
|
+
approveConsent: (request, options) => send(request, true, options),
|
|
171
|
+
denyConsent: (request, options) => send(request, false, options),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.js","sourceRoot":"","sources":["../../../src/first-party/calls/consent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAgD,MAAM,cAAc,CAAA;AACrG,OAAO,EAAE,aAAa,EAAgD,MAAM,YAAY,CAAA;AAsExF,MAAM,IAAI,GAAG,kBAAkB,CAAA;AAe/B,SA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E,KAAK,EAAE,OAAO,CAAC;KACjE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type AsPerson, type CallOptions, type Refused, type Result, type Sent } from '../result.js';
|
|
2
|
+
import { type Wire, type WireAnswer, type WireRequest } from '../wire.js';
|
|
3
|
+
/**
|
|
4
|
+
* The request a device made, as pulse-auth holds it: what the person is asked to approve.
|
|
5
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
6
|
+
*/
|
|
7
|
+
export interface DeviceRequest {
|
|
8
|
+
/**
|
|
9
|
+
* As pulse-auth formats it.
|
|
10
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
11
|
+
*/
|
|
12
|
+
readonly user_code: string;
|
|
13
|
+
/**
|
|
14
|
+
* The OAuth client the device signs in to.
|
|
15
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
16
|
+
*/
|
|
17
|
+
readonly client_id: string;
|
|
18
|
+
/**
|
|
19
|
+
* The name the client declares for itself: for a client registered by metadata document or dynamically, nobody has checked it, so show `client_id` beside it.
|
|
20
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
21
|
+
*/
|
|
22
|
+
readonly client_name: string | null;
|
|
23
|
+
/**
|
|
24
|
+
* What the device asks to be allowed, as pulse-auth names it.
|
|
25
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
26
|
+
*/
|
|
27
|
+
readonly scopes: readonly string[];
|
|
28
|
+
/**
|
|
29
|
+
* When the code runs out, epoch ms.
|
|
30
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
31
|
+
*/
|
|
32
|
+
readonly expires_at: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* What stops a look-up.
|
|
36
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
37
|
+
*/
|
|
38
|
+
export type DeviceStop =
|
|
39
|
+
/**
|
|
40
|
+
* The code is unknown, expired or already used: pulse-auth says one thing for all three.
|
|
41
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
42
|
+
*/
|
|
43
|
+
{
|
|
44
|
+
readonly kind: 'unknown_code';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This request was already denied.
|
|
48
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#lookupdevice
|
|
49
|
+
*/
|
|
50
|
+
| {
|
|
51
|
+
readonly kind: 'already_denied';
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* What stops an approval or a denial.
|
|
55
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approvedevice-denydevice
|
|
56
|
+
*/
|
|
57
|
+
export type DeviceAnswerStop =
|
|
58
|
+
/**
|
|
59
|
+
* The code is unknown, expired or already used: pulse-auth says one thing for all three.
|
|
60
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approvedevice-denydevice
|
|
61
|
+
*/
|
|
62
|
+
{
|
|
63
|
+
readonly kind: 'unknown_code';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A press from this page on this code (looked up again included) is still out, or may already have acted on it, for the person signed in now.
|
|
67
|
+
* @see https://github.com/flipstream-io/sdk/blob/main/sdks/typescript/docs/first-party.md#approvedevice-denydevice
|
|
68
|
+
*/
|
|
69
|
+
| {
|
|
70
|
+
readonly kind: 'answered';
|
|
71
|
+
};
|
|
72
|
+
export interface DeviceCalls {
|
|
73
|
+
readonly lookUpDevice: (request: {
|
|
74
|
+
readonly user_code: string;
|
|
75
|
+
}, options?: CallOptions) => Promise<Result<DeviceRequest, Sent | Refused | DeviceStop>>;
|
|
76
|
+
readonly approveDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
|
|
77
|
+
readonly kind: 'approved';
|
|
78
|
+
}, AsPerson | DeviceAnswerStop>>;
|
|
79
|
+
readonly denyDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
|
|
80
|
+
readonly kind: 'denied';
|
|
81
|
+
}, AsPerson | DeviceAnswerStop>>;
|
|
82
|
+
}
|
|
83
|
+
export declare function deviceLookupRequest(input: {
|
|
84
|
+
readonly user_code: string;
|
|
85
|
+
}): WireRequest | Refused;
|
|
86
|
+
export declare function deviceAnswerRequest(device: DeviceRequest, consent: boolean): WireRequest;
|
|
87
|
+
export declare function readDeviceLookup(answer: WireAnswer): Result<DeviceRequest, Sent | DeviceStop>;
|
|
88
|
+
type Decision = 'approved' | 'denied';
|
|
89
|
+
export declare function readDeviceAnswer<D extends Decision>(answer: WireAnswer, expected: D): Result<{
|
|
90
|
+
readonly kind: D;
|
|
91
|
+
}, Sent | DeviceAnswerStop>;
|
|
92
|
+
/**
|
|
93
|
+
* `signedIn` is the revision the page shows, or undefined when nobody is signed in: read at the
|
|
94
|
+
* press, as the wire pins the person there.
|
|
95
|
+
*/
|
|
96
|
+
export declare function createDeviceCalls(wire: Pick<Wire, 'open' | 'asPerson' | 'report'>, signedIn: () => number | undefined): DeviceCalls;
|
|
97
|
+
export {};
|