@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,379 @@
|
|
|
1
|
+
import { createSignInThrough } from './signInThrough.js';
|
|
2
|
+
import { createCell, FORBIDDEN_REFRESH_EVERY_MS } from './cell.js';
|
|
3
|
+
import { SessionClosedError } from './closed.js';
|
|
4
|
+
import { createLogout } from './logout.js';
|
|
5
|
+
import { createRefresher } from './refresh.js';
|
|
6
|
+
import { redeemResultOf, twoStepResultOf } from './results.js';
|
|
7
|
+
import { attemptEmail, forgetLockEnd, keepLockEnd, keptLockEnd } from '../twoStepLock.js';
|
|
8
|
+
import { createSharedState } from './shared.js';
|
|
9
|
+
import { sharedSignal } from './sharedSignal.js';
|
|
10
|
+
import { createSignIn } from './signIn.js';
|
|
11
|
+
import { createSync } from './sync.js';
|
|
12
|
+
import { createTokens } from './tokens.js';
|
|
13
|
+
import { REFRESH_MARGIN_MS, } from './types.js';
|
|
14
|
+
/*
|
|
15
|
+
* The browser's session with pulse-auth (docs/architecture.md 2.3, A3): pulse-fe's rules,
|
|
16
|
+
* carried over. The access token lives in this tab's memory only; the httpOnly refresh
|
|
17
|
+
* cookie is shared by every tab of the origin, so:
|
|
18
|
+
* - every request that sets or clears the cookie runs under one lock across tabs, and
|
|
19
|
+
* decides inside it, and again after the answer;
|
|
20
|
+
* - the shared state in localStorage says which session is current; the channel only makes
|
|
21
|
+
* a change quick;
|
|
22
|
+
* - "can't reach sign-in" is never "signed out".
|
|
23
|
+
*
|
|
24
|
+
* Its parts share one cell (cell.ts): the shared state and the locks (shared.ts), the held
|
|
25
|
+
* token (tokens.ts), logout (logout.ts), refresh (refresh.ts), sign-in (signIn.ts) and
|
|
26
|
+
* keeping in step with the other tabs (sync.ts). This file wires them, and is what the
|
|
27
|
+
* console calls.
|
|
28
|
+
*/
|
|
29
|
+
export function createAuthSession(deps) {
|
|
30
|
+
const { http, channel, now } = deps;
|
|
31
|
+
const cell = createCell(deps.locks !== null && deps.storage !== null);
|
|
32
|
+
const sharedState = createSharedState(deps, cell);
|
|
33
|
+
const { shared } = sharedState;
|
|
34
|
+
// The held token's timer refreshes through the refresher, which holds its answer in turn:
|
|
35
|
+
// made just below, and called only once a token is held.
|
|
36
|
+
const tokens = createTokens(deps, cell, sharedState, (stale) => refresher.refresh(stale));
|
|
37
|
+
const { publish } = tokens;
|
|
38
|
+
const logout = createLogout(deps, cell, sharedState, tokens);
|
|
39
|
+
const { tryLogout, recordSignOut } = logout;
|
|
40
|
+
const refresher = createRefresher(deps, cell, sharedState, tokens, logout);
|
|
41
|
+
const { refresh, restore } = refresher;
|
|
42
|
+
const signIn = createSignIn(deps, cell, sharedState, tokens, logout);
|
|
43
|
+
/**
|
|
44
|
+
* A kept redeem answers its challenge only while no other sign-in in this tab has taken a
|
|
45
|
+
* challenge or signed in since that challenge was last installed: from then on it is
|
|
46
|
+
* `superseded`, for every later press of the link, whatever is pending by then (SDK-D1948,
|
|
47
|
+
* SDK-D1976, SDK-D2007). The link is spent, and the session's state says what is true now.
|
|
48
|
+
*/
|
|
49
|
+
const ownChallenge = (record) => record.attempt.then((result) => (result.kind === 'two-step' || result.kind === 'two-step-setup') && record.overtaken
|
|
50
|
+
? { kind: 'superseded' }
|
|
51
|
+
: result);
|
|
52
|
+
const { sync, onMessage, stateWritten } = createSync(deps, cell, sharedState, tokens, refresher, logout, signIn);
|
|
53
|
+
const heard = (event) => {
|
|
54
|
+
onMessage(event.data);
|
|
55
|
+
};
|
|
56
|
+
// No storage or no locks: nothing this tab can sign in with. Hearing a peer would show
|
|
57
|
+
// that peer's sign-in and schedule a renewal for a token this tab cannot keep.
|
|
58
|
+
if (cell.supported)
|
|
59
|
+
channel?.addEventListener('message', heard);
|
|
60
|
+
let readyWaiters = [];
|
|
61
|
+
cell.listeners.add(() => {
|
|
62
|
+
if (cell.status.status === 'restoring')
|
|
63
|
+
return;
|
|
64
|
+
const waiters = readyWaiters;
|
|
65
|
+
readyWaiters = [];
|
|
66
|
+
for (const { resolve } of waiters)
|
|
67
|
+
resolve(cell.status);
|
|
68
|
+
});
|
|
69
|
+
// The app's own listeners, apart from ready()'s: close() takes them off, so a former screen
|
|
70
|
+
// hears nothing more, while a ready() already waiting still settles.
|
|
71
|
+
const subscribers = new Set();
|
|
72
|
+
/** A call made after close() is a programming error: it throws before anything is sent. */
|
|
73
|
+
const stillOpen = (call) => {
|
|
74
|
+
if (cell.closed)
|
|
75
|
+
throw new SessionClosedError(call);
|
|
76
|
+
};
|
|
77
|
+
const through = createSignInThrough(cell, shared, signIn);
|
|
78
|
+
function isCurrent(revision) {
|
|
79
|
+
if (cell.status.status !== 'signed-in' ||
|
|
80
|
+
cell.status.revision !== revision ||
|
|
81
|
+
cell.held === null) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const state = shared();
|
|
85
|
+
if (!state.signedIn || state.generation !== cell.held.generation)
|
|
86
|
+
return false;
|
|
87
|
+
// Another tab adopted a token for a different principal (a changed role).
|
|
88
|
+
return !(state.serial > cell.held.serial &&
|
|
89
|
+
state.principal !== null &&
|
|
90
|
+
state.principal !== cell.held.access.fingerprint);
|
|
91
|
+
}
|
|
92
|
+
function enrollmentChallenge() {
|
|
93
|
+
const pending = cell.twoStep;
|
|
94
|
+
if (pending === null || pending.purpose !== 'setup')
|
|
95
|
+
return null;
|
|
96
|
+
// A peer may have changed the shared record before its channel message was delivered.
|
|
97
|
+
if (shared().generation !== pending.generation) {
|
|
98
|
+
signIn.endTwoStep();
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return { challenge: pending.challenge.challenge, expiresAt: pending.challenge.expiresAt };
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
async signInThrough(request, how, options) {
|
|
105
|
+
stillOpen('signInThrough()');
|
|
106
|
+
return through(request, how, options);
|
|
107
|
+
},
|
|
108
|
+
current: () => cell.status,
|
|
109
|
+
subscribe(listener) {
|
|
110
|
+
// A copy of its own, so the same function subscribed twice is taken off once each time.
|
|
111
|
+
const heardBy = () => {
|
|
112
|
+
// The page's own exception: the next listener and the call that notified them still
|
|
113
|
+
// finish, and the text never becomes a session report (SDK-D1910).
|
|
114
|
+
try {
|
|
115
|
+
listener();
|
|
116
|
+
}
|
|
117
|
+
catch (cause) {
|
|
118
|
+
deps.reportError(cause);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
if (!cell.closed) {
|
|
122
|
+
subscribers.add(heardBy);
|
|
123
|
+
cell.listeners.add(heardBy);
|
|
124
|
+
}
|
|
125
|
+
return () => {
|
|
126
|
+
subscribers.delete(heardBy);
|
|
127
|
+
cell.listeners.delete(heardBy);
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
ready() {
|
|
131
|
+
if (cell.closed)
|
|
132
|
+
return Promise.reject(new SessionClosedError('ready()'));
|
|
133
|
+
if (cell.status.status !== 'restoring')
|
|
134
|
+
return Promise.resolve(cell.status);
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
readyWaiters.push({ resolve, reject });
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
start() {
|
|
140
|
+
stillOpen('start()');
|
|
141
|
+
if (!cell.supported) {
|
|
142
|
+
publish({ status: 'unsupported' });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
void restore();
|
|
146
|
+
},
|
|
147
|
+
retry() {
|
|
148
|
+
stillOpen('retry()');
|
|
149
|
+
if (!cell.supported)
|
|
150
|
+
return;
|
|
151
|
+
cell.backoffStep = 0;
|
|
152
|
+
if (cell.status.status !== 'signed-in')
|
|
153
|
+
publish({ status: 'restoring' });
|
|
154
|
+
void restore();
|
|
155
|
+
},
|
|
156
|
+
async getAccessToken() {
|
|
157
|
+
stillOpen('getAccessToken()');
|
|
158
|
+
if (!cell.supported)
|
|
159
|
+
return { kind: 'signed-out' };
|
|
160
|
+
await sync();
|
|
161
|
+
if (cell.held !== null && cell.held.expiresAt - now() < REFRESH_MARGIN_MS) {
|
|
162
|
+
await refresh(cell.held.access.token);
|
|
163
|
+
}
|
|
164
|
+
// An expired token is never sent: pulse-auth couldn't be asked for a new one.
|
|
165
|
+
// An unexpired one is withheld too once it isn't current: the shared state names other rights
|
|
166
|
+
// and this tab couldn't fetch its own, or the session ended in another tab while this call's refresh was out.
|
|
167
|
+
if (cell.held !== null && cell.held.expiresAt > now() && isCurrent(cell.revision)) {
|
|
168
|
+
return { kind: 'token', token: cell.held.access.token, revision: cell.revision };
|
|
169
|
+
}
|
|
170
|
+
return cell.status.status === 'signed-out'
|
|
171
|
+
? { kind: 'signed-out' }
|
|
172
|
+
: { kind: 'unavailable' };
|
|
173
|
+
},
|
|
174
|
+
async refreshAfterUnauthorized(sent) {
|
|
175
|
+
stillOpen('refreshAfterUnauthorized()');
|
|
176
|
+
if (!cell.supported)
|
|
177
|
+
return 'signed-out';
|
|
178
|
+
await sync();
|
|
179
|
+
if (cell.held !== null && cell.held.access.token !== sent)
|
|
180
|
+
return 'retry';
|
|
181
|
+
const outcome = await refresh(sent);
|
|
182
|
+
if (outcome === 'ok' && cell.held !== null)
|
|
183
|
+
return 'retry';
|
|
184
|
+
return cell.status.status === 'signed-out' ? 'signed-out' : 'unavailable';
|
|
185
|
+
},
|
|
186
|
+
async refreshAfterForbidden() {
|
|
187
|
+
stillOpen('refreshAfterForbidden()');
|
|
188
|
+
if (!cell.supported || cell.held === null)
|
|
189
|
+
return;
|
|
190
|
+
if (now() - cell.lastForcedRefresh < FORBIDDEN_REFRESH_EVERY_MS)
|
|
191
|
+
return;
|
|
192
|
+
cell.lastForcedRefresh = now();
|
|
193
|
+
await refresh(cell.held.access.token);
|
|
194
|
+
},
|
|
195
|
+
redeem(linkToken, attemptId, signal) {
|
|
196
|
+
if (cell.closed)
|
|
197
|
+
return Promise.reject(new SessionClosedError('redeem()'));
|
|
198
|
+
if (!cell.supported)
|
|
199
|
+
return Promise.resolve({ kind: 'unsupported' });
|
|
200
|
+
// A link is single use: a redeem in flight, or with a final answer, is never sent
|
|
201
|
+
// again. One that may work when tried again is forgotten, so Try again really does.
|
|
202
|
+
// One given up (every caller left before the send) is never joined: it sends nothing, but
|
|
203
|
+
// may stay stored until it settles, while another tab holds the cookie lock or its owed
|
|
204
|
+
// logout is out. A new attempt takes its place; its cleanup below then leaves the new one.
|
|
205
|
+
const earlier = cell.redeems.get(linkToken);
|
|
206
|
+
const generation = shared().generation;
|
|
207
|
+
const localSignOuts = cell.localSignOuts;
|
|
208
|
+
// An unsent redeem from an older generation cannot dispatch: signIn checks its pin again
|
|
209
|
+
// under the cookie lock. A press at this generation may therefore queue its own attempt.
|
|
210
|
+
if (earlier !== undefined && !earlier.callers.givenUp() &&
|
|
211
|
+
(earlier.callers.wasSent() || earlier.generation === generation)) {
|
|
212
|
+
earlier.callers.join(signal);
|
|
213
|
+
return ownChallenge(earlier);
|
|
214
|
+
}
|
|
215
|
+
const callers = sharedSignal();
|
|
216
|
+
callers.join(signal);
|
|
217
|
+
const attempt = signIn
|
|
218
|
+
.signIn(() => http.redeem(linkToken), { attemptId, email: null }, 'redeem', generation, callers.signal, callers.sent, localSignOuts)
|
|
219
|
+
.then(redeemResultOf);
|
|
220
|
+
const record = { attempt, attemptId, generation, callers, overtaken: false };
|
|
221
|
+
cell.redeems.set(linkToken, record);
|
|
222
|
+
void attempt.then((result) => {
|
|
223
|
+
callers.settled();
|
|
224
|
+
if ((result.kind === 'unavailable' || result.kind === 'unknown') &&
|
|
225
|
+
cell.redeems.get(linkToken) === record) {
|
|
226
|
+
cell.redeems.delete(linkToken);
|
|
227
|
+
}
|
|
228
|
+
}, () => {
|
|
229
|
+
callers.settled();
|
|
230
|
+
// A redeem that rejected (a bug, never an answer) is the caller's to see, through
|
|
231
|
+
// `attempt`; this chain only forgets it, so it isn't also an unhandled rejection.
|
|
232
|
+
if (cell.redeems.get(linkToken) === record)
|
|
233
|
+
cell.redeems.delete(linkToken);
|
|
234
|
+
});
|
|
235
|
+
return ownChallenge(record);
|
|
236
|
+
},
|
|
237
|
+
signInSetupChallenge(setup) {
|
|
238
|
+
if (!cell.setupSteps.has(setup)) {
|
|
239
|
+
throw new TypeError('startSignInTwoStepSetup() takes the setup returned by this session, as it is');
|
|
240
|
+
}
|
|
241
|
+
const pending = cell.twoStep;
|
|
242
|
+
if (pending?.purpose === 'setup' && pending.setup === setup) {
|
|
243
|
+
if (shared().generation !== pending.generation)
|
|
244
|
+
signIn.endTwoStep();
|
|
245
|
+
else if (now() < setup.expires_at)
|
|
246
|
+
return { kind: 'pending', challenge: pending.challenge.challenge };
|
|
247
|
+
}
|
|
248
|
+
return { kind: cell.setupSteps.get(setup) === 'superseded' ? 'superseded' : 'expired' };
|
|
249
|
+
},
|
|
250
|
+
setupChallenge() {
|
|
251
|
+
const pending = enrollmentChallenge();
|
|
252
|
+
if (pending !== null && now() >= pending.expiresAt) {
|
|
253
|
+
cell.twoStep = null;
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return pending;
|
|
257
|
+
},
|
|
258
|
+
twoStepEndedByTab() {
|
|
259
|
+
return cell.twoStepEndedByTab;
|
|
260
|
+
},
|
|
261
|
+
twoStepPending() {
|
|
262
|
+
if (cell.twoStep === null)
|
|
263
|
+
return null;
|
|
264
|
+
if (now() >= cell.twoStep.challenge.expiresAt) {
|
|
265
|
+
cell.twoStep = null;
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return { expiresAt: cell.twoStep.challenge.expiresAt };
|
|
269
|
+
},
|
|
270
|
+
async verifyTwoStep(code, signal, onSend) {
|
|
271
|
+
stillOpen('verifyTwoStep()');
|
|
272
|
+
if (!cell.supported)
|
|
273
|
+
return { kind: 'unsupported' };
|
|
274
|
+
// A sign-out or sign-in elsewhere ended it: the code is never sent.
|
|
275
|
+
if (cell.twoStepSuperseded) {
|
|
276
|
+
cell.twoStepSuperseded = false;
|
|
277
|
+
return { kind: 'superseded' };
|
|
278
|
+
}
|
|
279
|
+
const pending = cell.twoStep;
|
|
280
|
+
// The challenge is past its five minutes: pulse-auth would refuse it, so don't ask.
|
|
281
|
+
if (pending === null || now() >= pending.challenge.expiresAt) {
|
|
282
|
+
cell.twoStep = null;
|
|
283
|
+
return { kind: 'expired' };
|
|
284
|
+
}
|
|
285
|
+
const settled = await signIn.signIn(() => http.verifyTwoStep(pending.challenge.challenge, code), pending, 'two-step', pending.generation, signal, onSend);
|
|
286
|
+
const answeredAt = now();
|
|
287
|
+
// Supported, so this browser has its storage. Three answers speak of a lock: locked
|
|
288
|
+
// keeps its end; a code counted as wrong, or taken, proves it over.
|
|
289
|
+
const storage = deps.storage;
|
|
290
|
+
const email = storage !== null &&
|
|
291
|
+
(settled.kind === 'locked' ||
|
|
292
|
+
settled.kind === 'wrong-code' ||
|
|
293
|
+
settled.kind === 'signed-in')
|
|
294
|
+
? pending.attemptId === null ? pending.email : attemptEmail(storage, pending.attemptId, answeredAt)
|
|
295
|
+
: null;
|
|
296
|
+
const result = twoStepResultOf(settled, answeredAt, storage === null || email === null
|
|
297
|
+
? null
|
|
298
|
+
: keptLockEnd(storage, email, answeredAt));
|
|
299
|
+
if (storage !== null && email !== null) {
|
|
300
|
+
if (result.kind === 'locked')
|
|
301
|
+
keepLockEnd(storage, email, result.until, answeredAt);
|
|
302
|
+
else
|
|
303
|
+
forgetLockEnd(storage, email);
|
|
304
|
+
}
|
|
305
|
+
// A challenge that can't take another code ends here: past its time, overtaken, or
|
|
306
|
+
// locked (pulse-auth's lock outlasts what is left of its five minutes).
|
|
307
|
+
// A local sign-in or sign-out may already have cleared this challenge, or another
|
|
308
|
+
// sign-in may have installed its replacement while this verify was pending.
|
|
309
|
+
if (cell.twoStep === pending) {
|
|
310
|
+
if (result.kind === 'superseded')
|
|
311
|
+
signIn.endTwoStep();
|
|
312
|
+
else if (result.kind === 'expired' || result.kind === 'locked')
|
|
313
|
+
cell.twoStep = null;
|
|
314
|
+
}
|
|
315
|
+
return result;
|
|
316
|
+
},
|
|
317
|
+
async signOut() {
|
|
318
|
+
stillOpen('signOut()');
|
|
319
|
+
cell.localSignOuts++;
|
|
320
|
+
cell.twoStep = null;
|
|
321
|
+
if (!cell.supported) {
|
|
322
|
+
// Nobody can sign in in this browser, so there is no cookie to end: nothing is asked,
|
|
323
|
+
// and nothing is published, so `current()` stays `unsupported` (SDK-D1919).
|
|
324
|
+
return { told: Promise.resolve({ kind: 'unsupported' }) };
|
|
325
|
+
}
|
|
326
|
+
clearTimeout(cell.restoreTimer);
|
|
327
|
+
// A challenge may have arrived while this sign-out waited for the state lock (#481).
|
|
328
|
+
const { serial } = await recordSignOut(() => { cell.twoStep = null; });
|
|
329
|
+
// The first try now; an answer that isn't a confirmation earns what `notConfirmed` decides:
|
|
330
|
+
// the back-off only when pulse-auth was unreachable, kept with no timer when it refused or
|
|
331
|
+
// answered outside the contract. A record that moved on since (its serial: a sign-in, or
|
|
332
|
+
// rarely a renewal by a tab that hadn't heard of this sign-out) replaced this logout's
|
|
333
|
+
// cookie, and this sign-out is told `superseded` (SDK-D2022).
|
|
334
|
+
cell.logoutBackoffStep = 0;
|
|
335
|
+
return { told: tryLogout(serial) };
|
|
336
|
+
},
|
|
337
|
+
async askPulseAuthAgain() {
|
|
338
|
+
await refresher.refreshAfterPasswordReset();
|
|
339
|
+
},
|
|
340
|
+
sync: async () => {
|
|
341
|
+
stillOpen('sync()');
|
|
342
|
+
await sync();
|
|
343
|
+
},
|
|
344
|
+
stateWritten: async () => {
|
|
345
|
+
stillOpen('stateWritten()');
|
|
346
|
+
await stateWritten();
|
|
347
|
+
},
|
|
348
|
+
isClosed() {
|
|
349
|
+
return cell.closed;
|
|
350
|
+
},
|
|
351
|
+
close() {
|
|
352
|
+
if (cell.closed)
|
|
353
|
+
return;
|
|
354
|
+
cell.closed = true;
|
|
355
|
+
if (!refresher.restoring()) {
|
|
356
|
+
for (const waiter of readyWaiters)
|
|
357
|
+
waiter.reject(new SessionClosedError('ready()'));
|
|
358
|
+
readyWaiters = [];
|
|
359
|
+
}
|
|
360
|
+
for (const timer of [cell.refreshTimer, cell.restoreTimer, cell.logoutRetryTimer]) {
|
|
361
|
+
clearTimeout(timer);
|
|
362
|
+
}
|
|
363
|
+
cell.refreshTimer = undefined;
|
|
364
|
+
cell.restoreTimer = undefined;
|
|
365
|
+
cell.logoutRetryTimer = undefined;
|
|
366
|
+
// A logout owed in memory only, which storage never took: whichever session in this page
|
|
367
|
+
// looks next sends it first (owed.ts, sdk#483).
|
|
368
|
+
logout.leaveIfOwed();
|
|
369
|
+
channel?.removeEventListener('message', heard);
|
|
370
|
+
channel?.close();
|
|
371
|
+
for (const listener of subscribers)
|
|
372
|
+
cell.listeners.delete(listener);
|
|
373
|
+
subscribers.clear();
|
|
374
|
+
},
|
|
375
|
+
canDeliverCodes: sharedState.canDeliverCodes,
|
|
376
|
+
isCurrent,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/first-party/session/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAqB,MAAM,WAAW,CAAA;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,YAAY,EA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yFAAyF;YACzF,gDAAgD;YAChD,MAAM,CAAC,WAAW,EAAE,CAAA;YACpB,OAAO,EAAE,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;YAC9C,OAAO,EAAE,KAAK,EAAE,CAAA;YAChB,KAAK,MAAM,QAAQ,IAAI,WAAW;gBAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YACnE,WAAW,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC;QAED,eAAe,EAAE,WAAW,CAAC,eAAe;QAC5C,SAAS;KACV,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Locked } from '../locks.js';
|
|
2
|
+
import { type AuthState } from '../state.js';
|
|
3
|
+
import { type Message, type SessionCell } from './cell.js';
|
|
4
|
+
import type { SessionDeps } from './types.js';
|
|
5
|
+
export declare const isNewer: (a: AuthState, b: AuthState) => boolean;
|
|
6
|
+
/** The shared state every tab reads, the two locks, and the channel to the other tabs. */
|
|
7
|
+
export interface SharedState {
|
|
8
|
+
/**
|
|
9
|
+
* The shared state. A single read of one key is atomic, so this needs no lock to read;
|
|
10
|
+
* every decision that writes runs under the state lock (`withState`). On a tie the stored
|
|
11
|
+
* record wins: it is the authority, a message only came first. A sign-out a closed session in
|
|
12
|
+
* this page owed, which storage never took, is read here every time (owed.ts, SDK-D1967).
|
|
13
|
+
*/
|
|
14
|
+
readonly shared: () => AuthState;
|
|
15
|
+
/** SDK-D2018 and SDK-D2019. A readable signed-out record, or the same confirmed token user. */
|
|
16
|
+
readonly canDeliverCodes: (userId: string, minimumGeneration?: number) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Runs `decide` under the state lock with the state as it is now: it returns the state to
|
|
19
|
+
* write (or null for none), its result, and what to do once that is written (adopt,
|
|
20
|
+
* release, broadcast). Synchronous inside, so nothing interleaves between the check, the
|
|
21
|
+
* write and its effects. A write the browser refuses (a full quota, blocked site data)
|
|
22
|
+
* runs no effect and counts as not run: a change the other tabs can't see is never acted
|
|
23
|
+
* on here.
|
|
24
|
+
*/
|
|
25
|
+
readonly withState: <T>(decide: (state: AuthState) => {
|
|
26
|
+
readonly write: AuthState | null;
|
|
27
|
+
readonly result: T;
|
|
28
|
+
readonly then?: () => void;
|
|
29
|
+
}) => Promise<Locked<T>>;
|
|
30
|
+
/** `signal`: a caller's own, which ends the wait for the lock, never a run holding it (#465). */
|
|
31
|
+
readonly withCookie: <T>(run: () => Promise<T>, signal?: AbortSignal) => Promise<Locked<T>>;
|
|
32
|
+
readonly broadcast: (message: Message) => void;
|
|
33
|
+
}
|
|
34
|
+
export declare function createSharedState(deps: SessionDeps, cell: SessionCell): SharedState;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { COOKIE_LOCK, STATE_LOCK, withLock } from '../locks.js';
|
|
2
|
+
import { NO_RECORD, readState, writeState } from '../state.js';
|
|
3
|
+
import { adoptNewer, dropUnrecordedSignOut } from './cell.js';
|
|
4
|
+
import { owedState } from './owed.js';
|
|
5
|
+
export const isNewer = (a, b) => a.generation > b.generation || (a.generation === b.generation && a.serial > b.serial);
|
|
6
|
+
export function createSharedState(deps, cell) {
|
|
7
|
+
const { channel, report } = deps;
|
|
8
|
+
const locks = deps.locks;
|
|
9
|
+
const storage = deps.storage;
|
|
10
|
+
/**
|
|
11
|
+
* The record as this tab reads it: a flag whose logout pulse-auth confirmed to this tab, which
|
|
12
|
+
* storage refused to clear, reads as cleared while the record is still that one, the same
|
|
13
|
+
* generation and serial (sdk#506). A record that moved on, a new flag at that generation (its
|
|
14
|
+
* serial moved), or one that lost the flag, ends the mark.
|
|
15
|
+
*/
|
|
16
|
+
const unpaid = (stored) => {
|
|
17
|
+
const paid = cell.paidLogout;
|
|
18
|
+
if (paid === null)
|
|
19
|
+
return stored;
|
|
20
|
+
if (stored.generation === paid.generation &&
|
|
21
|
+
stored.serial === paid.serial &&
|
|
22
|
+
stored.logoutPending?.generation === paid.generation) {
|
|
23
|
+
return { ...stored, logoutPending: null };
|
|
24
|
+
}
|
|
25
|
+
cell.paidLogout = null;
|
|
26
|
+
return stored;
|
|
27
|
+
};
|
|
28
|
+
const reconcile = (record) => {
|
|
29
|
+
const stored = unpaid(record);
|
|
30
|
+
const owed = deps.owed === null ? null : owedState(deps.owed, stored);
|
|
31
|
+
// Storage caught up with this tab (its sign-out written down, or a logout confirmed at the same
|
|
32
|
+
// generation), or a newer record speaks for the cookie now: what this tab owed is over (SDK-D2005).
|
|
33
|
+
// Whether an unrecorded sign-out still stands is read from the stored generation when it was made
|
|
34
|
+
// against the stored generation now: a record written since speaks for the cookie, whatever this
|
|
35
|
+
// tab's memory-only count says (SDK-D1967, SDK-D1977, sdk#510). A lower one is a lost record: the
|
|
36
|
+
// sign-out stands, as the page's slot is taken.
|
|
37
|
+
const recordedSince = cell.owedStored !== null && stored.generation > cell.owedStored;
|
|
38
|
+
if (recordedSince)
|
|
39
|
+
dropUnrecordedSignOut(cell);
|
|
40
|
+
if (recordedSince || !isNewer(cell.known, stored))
|
|
41
|
+
adoptNewer(cell, stored);
|
|
42
|
+
// The page's slot is an unrecorded sign-out a closed object left: adopted, it leaves the number.
|
|
43
|
+
if (owed !== null && isNewer(owed, cell.known))
|
|
44
|
+
cell.known = owed;
|
|
45
|
+
return cell.known;
|
|
46
|
+
};
|
|
47
|
+
const shared = () => storage === null ? cell.known : reconcile(readState(storage));
|
|
48
|
+
const canDeliverCodes = (userId, minimumGeneration = 0) => {
|
|
49
|
+
const record = storage === null ? NO_RECORD : readState(storage);
|
|
50
|
+
if (record === NO_RECORD)
|
|
51
|
+
return false;
|
|
52
|
+
const state = reconcile(record);
|
|
53
|
+
if (state.generation < minimumGeneration)
|
|
54
|
+
return false;
|
|
55
|
+
if (!state.signedIn)
|
|
56
|
+
return true;
|
|
57
|
+
const held = cell.held;
|
|
58
|
+
if (held === null || held.generation !== state.generation || held.access.principal.userId !== userId)
|
|
59
|
+
return false;
|
|
60
|
+
// A record that names a person delivers only to that person: a peer's renewal of the same person,
|
|
61
|
+
// a changed role included, keeps the generation, though this tab may not have the newer token
|
|
62
|
+
// yet (sdk#535). The person is compared, not taken as proof: a generation begun under a record
|
|
63
|
+
// with no person can name another person by now (PR 551 S1). A record with none (a console's
|
|
64
|
+
// write, or an older tab's) says nothing of the person, so the principal's fingerprint decides,
|
|
65
|
+
// as before (SDK-D2019, SDK-D2023).
|
|
66
|
+
return state.person !== null
|
|
67
|
+
? held.access.person === state.person
|
|
68
|
+
: held.access.fingerprint === state.principal;
|
|
69
|
+
};
|
|
70
|
+
const withState = (decide) => {
|
|
71
|
+
if (locks === null || storage === null)
|
|
72
|
+
return Promise.resolve({ ran: false });
|
|
73
|
+
return withLock(locks, STATE_LOCK, () => {
|
|
74
|
+
const { write, result, then } = decide(shared());
|
|
75
|
+
if (write !== null) {
|
|
76
|
+
if (!writeState(storage, write)) {
|
|
77
|
+
report({ kind: 'storage' });
|
|
78
|
+
return Promise.resolve({ ran: false });
|
|
79
|
+
}
|
|
80
|
+
// The record now holds this tab's state, so a sign-out of its own that storage refused
|
|
81
|
+
// before is written down, or a newer state replaced it (SDK-D1977).
|
|
82
|
+
adoptNewer(cell, write);
|
|
83
|
+
}
|
|
84
|
+
then?.();
|
|
85
|
+
return Promise.resolve({ ran: true, value: result });
|
|
86
|
+
}, (error) => {
|
|
87
|
+
report({ kind: 'lock', cause: error });
|
|
88
|
+
}).then((locked) => (locked.ran ? locked.value : { ran: false }));
|
|
89
|
+
};
|
|
90
|
+
const withCookie = (run, signal) => {
|
|
91
|
+
if (locks === null)
|
|
92
|
+
return Promise.resolve({ ran: false });
|
|
93
|
+
return withLock(locks, COOKIE_LOCK, run, (error) => {
|
|
94
|
+
report({ kind: 'lock', cause: error });
|
|
95
|
+
}, signal);
|
|
96
|
+
};
|
|
97
|
+
const broadcast = (message) => {
|
|
98
|
+
// A closed channel refuses to send.
|
|
99
|
+
if (!cell.closed)
|
|
100
|
+
channel?.postMessage(message);
|
|
101
|
+
};
|
|
102
|
+
return { shared, canDeliverCodes, withState, withCookie, broadcast };
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/first-party/session/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAkC,MAAM,WAAW,CAAA;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAY,EAAE,CAAY,EAAW,EAAE,CAC7D,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;AAiCvF,MAAM,UAAU,iBAAiB,CAAC,IAAiB,EAAE,IAAiB;IACpE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;IACxB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;IAE5B;;;;;OAKG;IACH,MAAM,MAAM,GAAG,CAAC,MAAiB,EAAa,EAAE;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAA;QAC5B,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,MAAM,CAAA;QAChC,IACE,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU;YACrC,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;YAC7B,MAAM,CAAC,aAAa,EAAE,UAAU,KAAK,IAAI,C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AQ,EAAE;QAC3C,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IACjD,CAAC,CAAA;IAED,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA;AACtE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signal of a sign-in that several callers share (SDK-D1932): a redeem, a log-in or an accept.
|
|
3
|
+
* It aborts only once every caller that joined has aborted, and a caller without a signal means it
|
|
4
|
+
* never does. Each caller's own `aborted` comes at once and for that caller only: from the entry
|
|
5
|
+
* for a redeem, from `signInThrough` for a family's call.
|
|
6
|
+
*/
|
|
7
|
+
export interface SharedSignal {
|
|
8
|
+
readonly signal: AbortSignal;
|
|
9
|
+
readonly join: (signal: AbortSignal | undefined) => void;
|
|
10
|
+
/** Called right before the request is sent. */
|
|
11
|
+
readonly sent: () => void;
|
|
12
|
+
/** Only a request that went out may have spent a link or set a cookie. */
|
|
13
|
+
readonly wasSent: () => boolean;
|
|
14
|
+
/** Every caller left before the send: the request won't go out, so nobody may join it. */
|
|
15
|
+
readonly givenUp: () => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Every caller has left, as of now: read at the last look before the send, so a press aborted in
|
|
18
|
+
* the turn it was made sends nothing, though `signal` aborts only a microtask later.
|
|
19
|
+
*/
|
|
20
|
+
readonly gone: () => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The request settled: every listener `join` put on a caller's signal comes off, and a later join
|
|
23
|
+
* adds none, so a long-lived signal handed to every press keeps nothing of a settled request.
|
|
24
|
+
*/
|
|
25
|
+
readonly settled: () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare function sharedSignal(): SharedSignal;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { stopListening } from '../../core/signal.js';
|
|
2
|
+
export function sharedSignal() {
|
|
3
|
+
const controller = new AbortController();
|
|
4
|
+
let open = 0;
|
|
5
|
+
let forever = false;
|
|
6
|
+
let out = false;
|
|
7
|
+
let done = false;
|
|
8
|
+
const listening = [];
|
|
9
|
+
const leave = () => {
|
|
10
|
+
open -= 1;
|
|
11
|
+
// React's StrictMode unmounts an effect with an abort and runs it again in the same turn:
|
|
12
|
+
// the check waits a microtask, so that second caller joins before the request is given up.
|
|
13
|
+
queueMicrotask(() => {
|
|
14
|
+
if (open === 0 && !forever)
|
|
15
|
+
controller.abort();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const join = (signal) => {
|
|
19
|
+
if (signal === undefined) {
|
|
20
|
+
forever = true;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
open += 1;
|
|
24
|
+
if (signal.aborted) {
|
|
25
|
+
leave();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (done)
|
|
29
|
+
return;
|
|
30
|
+
// A listener of its own for each join: the same function added twice to one signal is
|
|
31
|
+
// added once, so two callers sharing a signal would leave once.
|
|
32
|
+
const listener = () => {
|
|
33
|
+
leave();
|
|
34
|
+
};
|
|
35
|
+
listening.push({ signal, listener });
|
|
36
|
+
signal.addEventListener('abort', listener, { once: true });
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
signal: controller.signal,
|
|
40
|
+
join,
|
|
41
|
+
sent: () => {
|
|
42
|
+
out = true;
|
|
43
|
+
},
|
|
44
|
+
wasSent: () => out,
|
|
45
|
+
givenUp: () => controller.signal.aborted && !out,
|
|
46
|
+
gone: () => open === 0 && !forever,
|
|
47
|
+
settled: () => {
|
|
48
|
+
done = true;
|
|
49
|
+
// A signal with no removeEventListener (a minimal polyfill's) keeps its listener: never a throw.
|
|
50
|
+
for (const { signal, listener } of listening.splice(0))
|
|
51
|
+
stopListening(signal, listener);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=sharedSignal.js.map
|
|
@@ -0,0 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