@flipstream/sdk 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -0
- package/README.md +95 -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 +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 +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 +51 -9
- package/dist/flipstream.js +58 -22
- 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 +278 -0
- package/package.json +34 -5
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { readState } from '../state.js';
|
|
2
|
+
import { BACKOFF_MS, isKeptFor } from './cell.js';
|
|
3
|
+
import { leaveOwed } from './owed.js';
|
|
4
|
+
import { isNewer } from './shared.js';
|
|
5
|
+
const CONFIRMED = { kind: 'confirmed' };
|
|
6
|
+
const NOT_ASKED = { kind: 'unconfirmed', reason: 'unavailable' };
|
|
7
|
+
const SUPERSEDED = { kind: 'superseded' };
|
|
8
|
+
function toldBy(answer) {
|
|
9
|
+
switch (answer.kind) {
|
|
10
|
+
case 'confirmed':
|
|
11
|
+
return CONFIRMED;
|
|
12
|
+
case 'unconfirmed':
|
|
13
|
+
return { kind: 'unconfirmed', reason: answer.reason };
|
|
14
|
+
case 'broken':
|
|
15
|
+
return { kind: 'unconfirmed', reason: 'invalid' };
|
|
16
|
+
default: {
|
|
17
|
+
const exhaustive = answer;
|
|
18
|
+
return exhaustive;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const NOT_SENT = { kind: 'not-asked' };
|
|
23
|
+
const WAITING = { kind: 'waiting' };
|
|
24
|
+
/** Whether a call that sees `owed` shares a try that has read `read`. */
|
|
25
|
+
function shares(read, owed) {
|
|
26
|
+
switch (read.kind) {
|
|
27
|
+
case 'waiting':
|
|
28
|
+
return true;
|
|
29
|
+
case 'sends':
|
|
30
|
+
return read.generation === owed;
|
|
31
|
+
case 'nothing-owed':
|
|
32
|
+
return false;
|
|
33
|
+
default: {
|
|
34
|
+
const exhaustive = read;
|
|
35
|
+
return exhaustive;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What a try tells one caller (SDK-D1933, SDK-D2022). `pinnedSerial` is the record's serial as the
|
|
41
|
+
* caller's sign-out landed (`SignedOut`). `superseded` means the record moved on since that
|
|
42
|
+
* sign-out: a sign-in, or rarely a renewal by a tab that hadn't heard of it. That tab's cookie
|
|
43
|
+
* replaced the old one; it sent this logout first when it knew it was owed, and this try isn't
|
|
44
|
+
* told whether pulse-auth confirmed it. No pin (`sync()`, the timer): the try's own answer.
|
|
45
|
+
* - `answered`: `superseded` when the serial moved past the pin. Otherwise the try's own answer,
|
|
46
|
+
* whatever the generation: a second sign-out with no sign-in between ends the same cookie, and
|
|
47
|
+
* since #542 the generation can also go back.
|
|
48
|
+
* - `nothing-owed`: `confirmed` only on the pinned serial, where a confirmed logout cleared this
|
|
49
|
+
* sign-out's flag, so pulse-auth confirmed it to another tab. Any other serial is `superseded`.
|
|
50
|
+
*/
|
|
51
|
+
function toldTo(outcome, pinnedSerial) {
|
|
52
|
+
switch (outcome.kind) {
|
|
53
|
+
case 'answered':
|
|
54
|
+
// Greater than, not different: a lost record reads serial 0, and one rebuilt from it starts
|
|
55
|
+
// again below the pin. That is no proof of a sign-in, and the answer is pulse-auth's own to a
|
|
56
|
+
// logout this try sent, so the caller is told it (SDK-D2022, PR 546 round 1).
|
|
57
|
+
return pinnedSerial !== undefined && outcome.serial > pinnedSerial ? SUPERSEDED : toldBy(outcome.answer);
|
|
58
|
+
case 'nothing-owed':
|
|
59
|
+
// Equal, not "not past the pin": nothing owed proves a confirmation only on this sign-out's own
|
|
60
|
+
// record. A lower serial is a record lost and rebuilt by another tab, which confirmed nothing
|
|
61
|
+
// (SDK-D2022, PR 546 round 2).
|
|
62
|
+
return pinnedSerial === undefined || outcome.serial === pinnedSerial ? CONFIRMED : SUPERSEDED;
|
|
63
|
+
case 'not-asked':
|
|
64
|
+
return NOT_ASKED;
|
|
65
|
+
default: {
|
|
66
|
+
const exhaustive = outcome;
|
|
67
|
+
return exhaustive;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function createLogout(deps, cell, { shared, withState, withCookie, broadcast }, { release }) {
|
|
72
|
+
const { http, report } = deps;
|
|
73
|
+
const storage = deps.storage;
|
|
74
|
+
const sendLogout = async (generation) => {
|
|
75
|
+
const answer = await http.logout();
|
|
76
|
+
if (answer.kind === 'broken') {
|
|
77
|
+
report({ kind: 'answer', path: '/logout', status: answer.httpStatus });
|
|
78
|
+
}
|
|
79
|
+
if (answer.kind === 'confirmed') {
|
|
80
|
+
// Sent under the cookie lock, so it revoked whatever cookie any sign-in left before it:
|
|
81
|
+
// the slot's included, whatever generation an object counted for it.
|
|
82
|
+
if (deps.owed !== null)
|
|
83
|
+
deps.owed.left = null;
|
|
84
|
+
const cleared = await withState((state) => ({
|
|
85
|
+
write: state.logoutPending?.generation === generation
|
|
86
|
+
? { ...state, logoutPending: null }
|
|
87
|
+
: null,
|
|
88
|
+
result: undefined,
|
|
89
|
+
}));
|
|
90
|
+
// Storage refused: the confirmation is kept in memory, so this tab, and the slot it would
|
|
91
|
+
// leave when closed, don't owe it again (sdk#483). A flag storage holds is remembered as paid
|
|
92
|
+
// by its stored generation and serial, so a tie with the record doesn't bring it back (sdk#506).
|
|
93
|
+
if (!cleared.ran) {
|
|
94
|
+
// Read after the refused write let go of the state lock, so another tab may have written
|
|
95
|
+
// since. Safe: the only write that sets a flag at the same generation (a redeem's revoke)
|
|
96
|
+
// runs under the cookie lock, which every caller of sendLogout holds now.
|
|
97
|
+
const stored = storage === null ? null : readState(storage);
|
|
98
|
+
if (stored?.generation === generation && stored.logoutPending?.generation === generation) {
|
|
99
|
+
cell.paidLogout = { generation, serial: stored.serial };
|
|
100
|
+
}
|
|
101
|
+
if (cell.known.logoutPending?.generation === generation)
|
|
102
|
+
cell.known = { ...cell.known, logoutPending: null };
|
|
103
|
+
}
|
|
104
|
+
cell.owedStored = null;
|
|
105
|
+
cell.logoutKept = null;
|
|
106
|
+
}
|
|
107
|
+
return answer;
|
|
108
|
+
};
|
|
109
|
+
const notConfirmed = (answer, generation, serial) => {
|
|
110
|
+
const keep = (kept) => {
|
|
111
|
+
clearTimeout(cell.logoutRetryTimer);
|
|
112
|
+
cell.logoutRetryTimer = undefined;
|
|
113
|
+
cell.logoutBackoffStep = 0;
|
|
114
|
+
cell.logoutKept = { generation, serial, answer: kept };
|
|
115
|
+
};
|
|
116
|
+
switch (answer.kind) {
|
|
117
|
+
case 'unconfirmed':
|
|
118
|
+
if (answer.reason === 'unavailable') {
|
|
119
|
+
// The newest send for this cookie went unanswered: an earlier refusal no longer stands
|
|
120
|
+
// for it, so neither a queued try nor `sync()` reads it (PR 547 round 1).
|
|
121
|
+
if (isKeptFor(cell.logoutKept, { generation, serial }))
|
|
122
|
+
cell.logoutKept = null;
|
|
123
|
+
scheduleLogoutRetry();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
keep({ kind: 'unconfirmed', reason: answer.reason });
|
|
127
|
+
return;
|
|
128
|
+
case 'broken':
|
|
129
|
+
keep(answer);
|
|
130
|
+
return;
|
|
131
|
+
default: {
|
|
132
|
+
const exhaustive = answer;
|
|
133
|
+
return exhaustive;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const recordSignOut = async (landed) => {
|
|
138
|
+
const signedOut = (state) => {
|
|
139
|
+
const generation = state.generation + 1;
|
|
140
|
+
return { ...state, generation, signedIn: false, logoutPending: { generation }, principal: null, person: null };
|
|
141
|
+
};
|
|
142
|
+
const told = (generation) => {
|
|
143
|
+
landed?.();
|
|
144
|
+
release({ status: 'signed-out' });
|
|
145
|
+
broadcast({ type: 'signed-out', generation });
|
|
146
|
+
};
|
|
147
|
+
// One write: a new signed-out generation and its pending logout together.
|
|
148
|
+
const decided = await withState((state) => {
|
|
149
|
+
const next = signedOut(state);
|
|
150
|
+
return { write: next, result: { generation: next.generation, serial: next.serial }, then: () => { told(next.generation); } };
|
|
151
|
+
});
|
|
152
|
+
if (decided.ran)
|
|
153
|
+
return decided.value;
|
|
154
|
+
// The shared state can't record it (storage refused, or the state lock couldn't be had). This
|
|
155
|
+
// tab keeps the signed-out state in memory and tells the others, which learn the same, so until
|
|
156
|
+
// pulse-auth confirms the logout every one of them sends it instead of refreshing. After
|
|
157
|
+
// close() the channel is closed: the sign-out reaches this page's slot and no other tab.
|
|
158
|
+
// What storage read now is what the slot carries if this object closes first (SDK-D1977).
|
|
159
|
+
// Read before the number is set: shared() adopting a record ends any earlier one (SDK-D2005).
|
|
160
|
+
const next = signedOut(shared());
|
|
161
|
+
cell.owedStored ??= storage === null ? 0 : readState(storage).generation;
|
|
162
|
+
cell.known = next;
|
|
163
|
+
told(cell.known.generation);
|
|
164
|
+
// Closed already (a sign-in answered after close(), or a signOut() that waited for the state
|
|
165
|
+
// lock): close() left nothing, so this does (sdk#483 finding 1).
|
|
166
|
+
if (cell.closed)
|
|
167
|
+
leaveIfOwed();
|
|
168
|
+
return { generation: cell.known.generation, serial: cell.known.serial };
|
|
169
|
+
};
|
|
170
|
+
// Exactly while this tab's known state is the unrecorded, unconfirmed sign-out the number was read
|
|
171
|
+
// for, with that number: a sign-in recorded since then drops the slot (SDK-D1977). Memory against
|
|
172
|
+
// memory, never the count against a stored number (SDK-D1967, SDK-D2005).
|
|
173
|
+
const leaveIfOwed = () => {
|
|
174
|
+
if (deps.owed === null || cell.owedStored === null)
|
|
175
|
+
return;
|
|
176
|
+
const known = cell.known;
|
|
177
|
+
if (known.signedIn || known.logoutPending?.generation !== known.generation)
|
|
178
|
+
return;
|
|
179
|
+
leaveOwed(deps.owed, { generation: cell.known.generation, stored: cell.owedStored });
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Clears a paid logout's flag in storage, at the first write it takes: no request (sdk#506).
|
|
183
|
+
* What is written is what this tab knows: the paid record with its flag cleared, or a newer
|
|
184
|
+
* state only memory holds (a sign-out storage refused, or one heard from another tab), which
|
|
185
|
+
* `writeDown` would write at the same moment. Only while the stored record is still the paid one.
|
|
186
|
+
*/
|
|
187
|
+
const writeDownPaid = async () => {
|
|
188
|
+
if (cell.paidLogout === null)
|
|
189
|
+
return;
|
|
190
|
+
await withState((state) => ({ write: cell.paidLogout === null ? null : state, result: undefined }));
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Writes down a state only this tab's memory holds (a sign-out storage refused, or one
|
|
194
|
+
* another tab announced), once storage takes it, so a page load knows it too.
|
|
195
|
+
*/
|
|
196
|
+
const persistKnown = async () => {
|
|
197
|
+
if (storage === null || !isNewer(cell.known, readState(storage)))
|
|
198
|
+
return;
|
|
199
|
+
await withState((state) => ({
|
|
200
|
+
write: isNewer(state, readState(storage)) ? state : null,
|
|
201
|
+
result: undefined,
|
|
202
|
+
}));
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Sends the logout the shared state still owes, under the cookie lock. `answered`: what
|
|
206
|
+
* pulse-auth said to the logout `generation` owed, or, for a try queued behind this tab's own send
|
|
207
|
+
* of that same logout, what it said to that send (sdk#531). `nothing-owed`: pulse-auth confirmed it, or a
|
|
208
|
+
* new sign-in replaced the cookie, and `generation` is the state's now. `not-asked`: the lock
|
|
209
|
+
* wasn't had, or the session closed, which is tried again. `read` hears what the try found once
|
|
210
|
+
* it has read the state inside the lock.
|
|
211
|
+
*/
|
|
212
|
+
const flushPendingLogout = async (read) => {
|
|
213
|
+
// The mark as this try starts: one set later is a send this try queued behind.
|
|
214
|
+
const before = cell.logoutKept;
|
|
215
|
+
const locked = await withCookie(async () => {
|
|
216
|
+
await persistKnown();
|
|
217
|
+
// Closed while this waited for the lock: nothing new is sent (SDK-D1930). The flag stays
|
|
218
|
+
// recorded, for another tab or the next page load; close() set no retry timer.
|
|
219
|
+
if (cell.closed)
|
|
220
|
+
return NOT_SENT;
|
|
221
|
+
const state = shared();
|
|
222
|
+
const owed = state.logoutPending;
|
|
223
|
+
if (owed !== null && owed.generation === state.generation) {
|
|
224
|
+
read({ kind: 'sends', generation: owed.generation });
|
|
225
|
+
// Kept while this waited for the lock, for this same cookie (this tab's restore or sign-in
|
|
226
|
+
// sent it): pulse-auth's answer stands, and is this try's too. Sending it again would ask
|
|
227
|
+
// the same question (sdk#531). A mark this try saw as it started is an older send: the
|
|
228
|
+
// timer's try and any later one send, as before (PR 547 round 1).
|
|
229
|
+
const kept = cell.logoutKept;
|
|
230
|
+
if (kept !== before && isKeptFor(kept, state))
|
|
231
|
+
return { kind: 'answered', answer: kept.answer, generation: owed.generation, serial: state.serial };
|
|
232
|
+
return { kind: 'answered', answer: await sendLogout(owed.generation), generation: owed.generation, serial: state.serial };
|
|
233
|
+
}
|
|
234
|
+
read({ kind: 'nothing-owed' });
|
|
235
|
+
return { kind: 'nothing-owed', generation: state.generation, serial: state.serial };
|
|
236
|
+
});
|
|
237
|
+
return locked.ran ? locked.value : NOT_SENT;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* What became of one try, once: the timer and the kept mark are set here, for every
|
|
241
|
+
* caller the try is told to.
|
|
242
|
+
*/
|
|
243
|
+
const settle = (outcome) => {
|
|
244
|
+
switch (outcome.kind) {
|
|
245
|
+
case 'answered':
|
|
246
|
+
if (outcome.answer.kind === 'confirmed')
|
|
247
|
+
stopRetrying();
|
|
248
|
+
else
|
|
249
|
+
notConfirmed(outcome.answer, outcome.generation, outcome.serial);
|
|
250
|
+
return outcome;
|
|
251
|
+
case 'nothing-owed':
|
|
252
|
+
stopRetrying();
|
|
253
|
+
return outcome;
|
|
254
|
+
case 'not-asked':
|
|
255
|
+
scheduleLogoutRetry();
|
|
256
|
+
return outcome;
|
|
257
|
+
default: {
|
|
258
|
+
const exhaustive = outcome;
|
|
259
|
+
return exhaustive;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const stopRetrying = () => {
|
|
264
|
+
clearTimeout(cell.logoutRetryTimer);
|
|
265
|
+
cell.logoutRetryTimer = undefined;
|
|
266
|
+
cell.logoutBackoffStep = 0;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* The try still out in this tab, and what it has read inside the cookie lock (sdk#517). A check
|
|
270
|
+
* of the shared state (`sync()`) or a sign-out shares it: nothing more is sent, and its outcome
|
|
271
|
+
* is theirs. While it waits for the lock every call shares it, whatever generation that call
|
|
272
|
+
* sees owed, since it reads the state there and sends for the newest one owed. Once it has read
|
|
273
|
+
* it, only a call that sees owed the generation it sends for shares it; a call that sees another
|
|
274
|
+
* one owed, or one after it found nothing owed, starts its own try.
|
|
275
|
+
*/
|
|
276
|
+
let inFlight = null;
|
|
277
|
+
/** A try that threw: reported, and tried again on the back-off. */
|
|
278
|
+
const threw = (error) => {
|
|
279
|
+
report({ kind: 'threw', step: 'logout', cause: error });
|
|
280
|
+
scheduleLogoutRetry();
|
|
281
|
+
return NOT_SENT;
|
|
282
|
+
};
|
|
283
|
+
const startTry = () => {
|
|
284
|
+
let found = WAITING;
|
|
285
|
+
const outcome = flushPendingLogout((read) => {
|
|
286
|
+
found = read;
|
|
287
|
+
}).then(settle, threw);
|
|
288
|
+
const mark = { read: () => found, outcome };
|
|
289
|
+
inFlight = mark;
|
|
290
|
+
// Ended however the try ends, a rejection included, so a marker never outlives its try.
|
|
291
|
+
const clear = () => {
|
|
292
|
+
if (inFlight === mark)
|
|
293
|
+
inFlight = null;
|
|
294
|
+
};
|
|
295
|
+
void outcome.then(clear, clear);
|
|
296
|
+
return outcome;
|
|
297
|
+
};
|
|
298
|
+
// A call that shares a try still writes down what only memory holds, as the try it would have
|
|
299
|
+
// started does first: a sign-out storage refused is written once storage takes writes again, so
|
|
300
|
+
// a reload in between doesn't restore the session (SDK-D2012). No request is sent. A write-down
|
|
301
|
+
// that throws is reported, and the call still takes the shared try's outcome: that try's settle
|
|
302
|
+
// owns the timer and the kept mark, so a sharer never arms the back-off (SDK-D1963).
|
|
303
|
+
const share = (outcome) => persistKnown().then(() => outcome, (error) => {
|
|
304
|
+
report({ kind: 'threw', step: 'logout', cause: error });
|
|
305
|
+
return outcome;
|
|
306
|
+
});
|
|
307
|
+
const tryLogout = (pinnedSerial) => {
|
|
308
|
+
const state = shared();
|
|
309
|
+
const owed = state.logoutPending !== null && state.logoutPending.generation === state.generation
|
|
310
|
+
? state.logoutPending.generation
|
|
311
|
+
: null;
|
|
312
|
+
const outcome = inFlight !== null && shares(inFlight.read(), owed) ? share(inFlight.outcome) : startTry();
|
|
313
|
+
return outcome.then((settled) => toldTo(settled, pinnedSerial));
|
|
314
|
+
};
|
|
315
|
+
const scheduleLogoutRetry = () => {
|
|
316
|
+
const delay = BACKOFF_MS[Math.min(cell.logoutBackoffStep, BACKOFF_MS.length - 1)] ?? 30_000;
|
|
317
|
+
cell.logoutBackoffStep += 1;
|
|
318
|
+
clearTimeout(cell.logoutRetryTimer);
|
|
319
|
+
if (cell.closed)
|
|
320
|
+
return;
|
|
321
|
+
cell.logoutRetryTimer = setTimeout(() => {
|
|
322
|
+
cell.logoutRetryTimer = undefined;
|
|
323
|
+
void tryLogout();
|
|
324
|
+
}, delay);
|
|
325
|
+
};
|
|
326
|
+
return { sendLogout, recordSignOut, leaveIfOwed, tryLogout, notConfirmed, scheduleLogoutRetry, writeDown: persistKnown, writeDownPaid };
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../../src/first-party/session/logout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAqC,MAAM,WAAW,CAAA;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,OAAO,EAAoB,MAAM,aAAa,CAAA;AAIvD,MAAM,SAAS,GAAS,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;AAC7C,MAAM,SAAS,GAAS,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;AACtE,MAAM,UAAU,GAAS,EAAE,IAAI,EAAE,YAAY,EAAE,CAAA;AAE/C,SAAS,MAAM,CAAC,MAAoB;IAClC,QAAQ,MAAM,C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I,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;QACzG,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;IACjE,CAAC,CAAA;IAED,MAAM,mBAAmB,GAAG,GAAS,EAAE;QACrC,MAAM,KAAK,GACT,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,CAAA;QAC/E,IAAI,CAAC,iBAAiB,IAAI,CAAC,CAAA;QAC3B,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QACnC,IAAI,IAAI,CAAC,MAAM;YAAE,OAAM;QACvB,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE;YACtC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAA;YACjC,KAAK,SAAS,EAAE,CAAA;QAClB,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC,CAAA;IAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,CAAA;AACzI,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AuthState } from '../state.js';
|
|
2
|
+
/**
|
|
3
|
+
* A sign-out a closed session made that storage never took (sdk#483): only that object knew of
|
|
4
|
+
* it, so without this a session made after it (a remount, a hot reload) would restore with the
|
|
5
|
+
* cookie its logout was owed for. Never a token or anything of the person.
|
|
6
|
+
*/
|
|
7
|
+
export interface OwedLogout {
|
|
8
|
+
/** The signed-out generation the closed session counted in memory: its logout's generation. */
|
|
9
|
+
readonly generation: number;
|
|
10
|
+
/** The stored generation when it was left (0: no record). It decides whether the slot still speaks (SDK-D1967). */
|
|
11
|
+
readonly stored: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One page's slot for an owed logout: the browser entry keeps one per page and auth path and hands
|
|
15
|
+
* it to every session made there. A session leaves its owed sign-out here when it can't be written
|
|
16
|
+
* down; any session in the page reads it whenever it looks at the shared state.
|
|
17
|
+
*/
|
|
18
|
+
export interface OwedSlot {
|
|
19
|
+
left: OwedLogout | null;
|
|
20
|
+
}
|
|
21
|
+
export declare const owedSlot: () => OwedSlot;
|
|
22
|
+
/** Leaves `owed`, keeping whatever an earlier object left that still speaks. */
|
|
23
|
+
export declare function leaveOwed(slot: OwedSlot, owed: OwedLogout): void;
|
|
24
|
+
/**
|
|
25
|
+
* The sign-out the slot stands for, as a state newer than `stored`, while storage reads the
|
|
26
|
+
* generation it was left under or a lower one (a lower one: the record was lost, and the logout
|
|
27
|
+
* still goes). Storage reading a higher one means a sign-in or a sign-out was recorded since,
|
|
28
|
+
* and that record speaks for the cookie now: the slot is dropped (SDK-D1967).
|
|
29
|
+
*/
|
|
30
|
+
export declare function owedState(slot: OwedSlot, stored: AuthState): AuthState | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const owedSlot = () => ({ left: null });
|
|
2
|
+
/** Leaves `owed`, keeping whatever an earlier object left that still speaks. */
|
|
3
|
+
export function leaveOwed(slot, owed) {
|
|
4
|
+
const earlier = slot.left;
|
|
5
|
+
slot.left = earlier === null ? owed : {
|
|
6
|
+
generation: Math.max(earlier.generation, owed.generation),
|
|
7
|
+
stored: Math.max(earlier.stored, owed.stored),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The sign-out the slot stands for, as a state newer than `stored`, while storage reads the
|
|
12
|
+
* generation it was left under or a lower one (a lower one: the record was lost, and the logout
|
|
13
|
+
* still goes). Storage reading a higher one means a sign-in or a sign-out was recorded since,
|
|
14
|
+
* and that record speaks for the cookie now: the slot is dropped (SDK-D1967).
|
|
15
|
+
*/
|
|
16
|
+
export function owedState(slot, stored) {
|
|
17
|
+
const left = slot.left;
|
|
18
|
+
if (left === null)
|
|
19
|
+
return null;
|
|
20
|
+
if (stored.generation > left.stored) {
|
|
21
|
+
slot.left = null;
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const generation = left.generation;
|
|
25
|
+
return { ...stored, generation, signedIn: false, logoutPending: { generation }, principal: null, person: null };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=owed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owed.js","sourceRoot":"","sources":["../../../src/first-party/session/owed.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;AAExD,gFAAgF;AAChF,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,IAAgB;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;IACzB,IAAI,CAAC,IAAI,GAAG,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC;QACzD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;KAC9C,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,MAAiB;IACzD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IACtB,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9B,IAAI,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;IAClC,OAAO,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;AACjH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RefreshOutcome, type SessionCell } from './cell.js';
|
|
2
|
+
import type { Logout } from './logout.js';
|
|
3
|
+
import type { SharedState } from './shared.js';
|
|
4
|
+
import type { Tokens } from './tokens.js';
|
|
5
|
+
import type { SessionDeps } from './types.js';
|
|
6
|
+
/** Asking pulse-auth for a new token with the refresh cookie, on load and before expiry. */
|
|
7
|
+
export interface Refresher {
|
|
8
|
+
/**
|
|
9
|
+
* Replaces `stale` with a fresh token. Callers arriving while a refresh runs share it.
|
|
10
|
+
* Inside the lock a different token of the current generation means another caller (or
|
|
11
|
+
* tab) already refreshed, so the cookie isn't spent again.
|
|
12
|
+
*/
|
|
13
|
+
readonly refresh: (stale: string | null) => Promise<RefreshOutcome>;
|
|
14
|
+
/** Waits for earlier work and then checks the cookie with pulse-auth after a reset. */
|
|
15
|
+
readonly refreshAfterPasswordReset: () => Promise<RefreshOutcome>;
|
|
16
|
+
readonly restoring: () => boolean;
|
|
17
|
+
readonly restore: (tries?: number) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createRefresher(deps: SessionDeps, cell: SessionCell, { shared, withState, withCookie, broadcast }: SharedState, { publish, hold, release, nextBackoff }: Tokens, { sendLogout, notConfirmed }: Logout): Refresher;
|