@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,105 @@
|
|
|
1
|
+
import type { AuthState } from '../state.js';
|
|
2
|
+
/**
|
|
3
|
+
* What an unrecorded sign-out (one storage refused) was made against, and whose cookie its logout
|
|
4
|
+
* is owed for. `stored`, `serial` and `basePerson` are the record then: the stored generation
|
|
5
|
+
* (0: no record), that record's serial, and that record's person (null when there was no record,
|
|
6
|
+
* or the record named none). `person` is whose cookie the logout is owed for, the same fingerprint
|
|
7
|
+
* of the `uid` claim the shared record stores as `person` (claims.ts), never a token or a claim.
|
|
8
|
+
* A ride renames `person` and leaves `basePerson` (`revokedOn`). `person` null: not known here, as
|
|
9
|
+
* in a tab that only heard the sign-out (the console's `signed-out` message carries only the
|
|
10
|
+
* generation, and its format stays). That heard entry still has the record's person as
|
|
11
|
+
* `basePerson`, so the write matches that record. `serial` null: two entries left against this
|
|
12
|
+
* stored generation named different serials, or different base persons, so which record it was is
|
|
13
|
+
* unknown. A null serial writes only over a lower record that is not signed in and owes no logout
|
|
14
|
+
* (SDK-D2053).
|
|
15
|
+
*/
|
|
16
|
+
export type OwedFor = {
|
|
17
|
+
readonly stored: number;
|
|
18
|
+
readonly serial: number | null;
|
|
19
|
+
readonly basePerson: string | null;
|
|
20
|
+
} & Owner;
|
|
21
|
+
/**
|
|
22
|
+
* Whom an unrecorded sign-out is owed for. `revoke`: whether the person is a refused sign-in's,
|
|
23
|
+
* whose revoke couldn't be sent, and how: `'rode'`, on a sign-out already pending here
|
|
24
|
+
* (`revokedOn`); `'made'`, recorded as its own sign-out (`recordSignOut`). Null: a sign-out's
|
|
25
|
+
* person. It decides the slot's merge at the same stored generation (`ownerAt`, sdk#559, PR 566
|
|
26
|
+
* S1). No person known, no revoke: an entry that names nobody can't outrank one that does (PR 566
|
|
27
|
+
* round 2 R2).
|
|
28
|
+
*/
|
|
29
|
+
export type Owner = {
|
|
30
|
+
readonly person: string;
|
|
31
|
+
readonly revoke: Revoke;
|
|
32
|
+
} | {
|
|
33
|
+
readonly person: null;
|
|
34
|
+
readonly revoke: null;
|
|
35
|
+
};
|
|
36
|
+
/** How a revoke's person came to be owed (`OwedFor.revoke`). */
|
|
37
|
+
export type Revoke = 'rode' | 'made' | null;
|
|
38
|
+
/**
|
|
39
|
+
* A sign-out a closed session made that storage never took (sdk#483): only that object knew of
|
|
40
|
+
* it, so without this a session made after it (a remount, a hot reload) would restore with the
|
|
41
|
+
* cookie its logout was owed for. It holds the person's fingerprint (`OwedFor`), never a token or
|
|
42
|
+
* a claim.
|
|
43
|
+
*/
|
|
44
|
+
export type OwedLogout = OwedFor & {
|
|
45
|
+
/** The signed-out generation the closed session counted in memory: its logout's generation. */
|
|
46
|
+
readonly generation: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* One page's slot for an owed logout: the browser entry keeps one per page and auth path and hands
|
|
50
|
+
* it to every session made there. A session leaves its owed sign-out here when it can't be written
|
|
51
|
+
* down; any session in the page reads it whenever it looks at the shared state.
|
|
52
|
+
*/
|
|
53
|
+
export interface OwedSlot {
|
|
54
|
+
left: OwedLogout | null;
|
|
55
|
+
}
|
|
56
|
+
export declare const owedSlot: () => OwedSlot;
|
|
57
|
+
/**
|
|
58
|
+
* Leaves `owed`, keeping whatever an earlier object left that still speaks. The person the logout
|
|
59
|
+
* is owed for goes with the higher stored generation, since that is what the slot is read against
|
|
60
|
+
* (`ownerAt` against the same one). The serial and the record's person go with that generation
|
|
61
|
+
* too. Two entries against one stored generation that name different serials, or different base
|
|
62
|
+
* persons, leave the serial unknown: a null serial writes only over a lower record that is not
|
|
63
|
+
* signed in and owes no logout (SDK-D2053).
|
|
64
|
+
*/
|
|
65
|
+
export declare function leaveOwed(slot: OwedSlot, owed: OwedLogout): void;
|
|
66
|
+
/**
|
|
67
|
+
* What an unrecorded sign-out is owed for once `person`'s revoke rode on its pending logout, while
|
|
68
|
+
* storage records generation `recorded`: that sign-in's cookie replaced the one it was owed for, so
|
|
69
|
+
* it is owed for that person now (PR 558 S1/R2). The rename changes `person` only. `basePerson`
|
|
70
|
+
* stays the person of the record the entry was made against. A rename never makes a sign-out that
|
|
71
|
+
* stands give way, so it is unchanged:
|
|
72
|
+
* - when the revoke names nobody (its answer couldn't be read): an unknown person never erases a
|
|
73
|
+
* known one, and a refresh naming someone else gives way all the same (PR 558 round 2 S1);
|
|
74
|
+
* - when storage records anything past the stored generation it was made against: then it stands
|
|
75
|
+
* past a refresh's record only because that record named the person it was owed for, a check
|
|
76
|
+
* already made, and any later record ends it whoever it names (`standingAt`).
|
|
77
|
+
*/
|
|
78
|
+
export declare function revokedOn<T extends OwedFor>(owed: T, person: string | null, recorded: number): T;
|
|
79
|
+
/**
|
|
80
|
+
* The same for the page's slot, on the entry the revoke rode on only (the same generation and stored
|
|
81
|
+
* generation): an entry merged from another object's sign-out is left as it is (PR 558 round 2 S5).
|
|
82
|
+
*/
|
|
83
|
+
export declare function owedNowFor(slot: OwedSlot, rodeOn: Pick<OwedLogout, 'generation' | 'stored'>, person: string | null, recorded: number): void;
|
|
84
|
+
/**
|
|
85
|
+
* The generation an unrecorded sign-out stands at now that storage reads `stored`, or null when it
|
|
86
|
+
* is over: one rule for a tab's memory (shared.ts) and a page's slot, so the two never disagree.
|
|
87
|
+
* `generation`: what it counted in memory; `owedFor`: what it was made against.
|
|
88
|
+
* - Storage reads that stored generation or a lower one (a lower one: the record was lost): it
|
|
89
|
+
* stands, as it was counted.
|
|
90
|
+
* - Storage reads a record a refresh made at one past it, naming the very person the sign-out was
|
|
91
|
+
* owed for: that refresh used the cookie the logout was owed for (a refused sign-in's, or a
|
|
92
|
+
* session signed out after its record was lost), so it still stands, past that record, and is
|
|
93
|
+
* written down there (sdk#552, sdk#543, SDK-D2025 as narrowed by the lead).
|
|
94
|
+
* - Storage reads any other higher record: a sign-in, a sign-out, a record without its maker,
|
|
95
|
+
* anything at two or more past, or a refresh's naming another person or with the person not
|
|
96
|
+
* known on either side. A record written since speaks for the cookie, and it is over (SDK-D1967,
|
|
97
|
+
* SDK-D1977, sdk#510). A refresh that found another person found the cookie changed owner, so no
|
|
98
|
+
* logout from it could reach the person signed out (PR 551 S4).
|
|
99
|
+
*/
|
|
100
|
+
export declare function standingAt(generation: number, owedFor: OwedFor, stored: AuthState): number | null;
|
|
101
|
+
/**
|
|
102
|
+
* The sign-out the slot stands for, as a state newer than `stored`, while it stands
|
|
103
|
+
* (`standingAt`); dropped once a record written since speaks for the cookie (SDK-D1967).
|
|
104
|
+
*/
|
|
105
|
+
export declare function owedState(slot: OwedSlot, stored: AuthState): AuthState | null;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export const owedSlot = () => ({ left: null });
|
|
2
|
+
/**
|
|
3
|
+
* Leaves `owed`, keeping whatever an earlier object left that still speaks. The person the logout
|
|
4
|
+
* is owed for goes with the higher stored generation, since that is what the slot is read against
|
|
5
|
+
* (`ownerAt` against the same one). The serial and the record's person go with that generation
|
|
6
|
+
* too. Two entries against one stored generation that name different serials, or different base
|
|
7
|
+
* persons, leave the serial unknown: a null serial writes only over a lower record that is not
|
|
8
|
+
* signed in and owes no logout (SDK-D2053).
|
|
9
|
+
*/
|
|
10
|
+
export function leaveOwed(slot, owed) {
|
|
11
|
+
const earlier = slot.left;
|
|
12
|
+
if (earlier === null) {
|
|
13
|
+
slot.left = owed;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const stored = Math.max(earlier.stored, owed.stored);
|
|
17
|
+
const higher = earlier.stored === owed.stored ? null : earlier.stored > owed.stored ? earlier : owed;
|
|
18
|
+
const sameRecord = earlier.serial === owed.serial && earlier.basePerson === owed.basePerson;
|
|
19
|
+
slot.left = {
|
|
20
|
+
generation: Math.max(earlier.generation, owed.generation),
|
|
21
|
+
stored,
|
|
22
|
+
serial: higher === null ? (sameRecord ? earlier.serial : null) : higher.serial,
|
|
23
|
+
basePerson: higher === null ? (earlier.basePerson === owed.basePerson ? earlier.basePerson : null) : higher.basePerson,
|
|
24
|
+
...(higher === null ? ownerAt(earlier, owed) : owner(higher)),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const owner = (owed) => owed.person === null ? { person: null, revoke: null } : { person: owed.person, revoke: owed.revoke };
|
|
28
|
+
const NONE = { person: null, revoke: null };
|
|
29
|
+
/** Which entry's person is the later cookie's: a rider's, then a maker's, then a sign-out's. */
|
|
30
|
+
const RANK = { rode: 2, made: 1 };
|
|
31
|
+
const rank = (revoke) => (revoke === null ? 0 : RANK[revoke]);
|
|
32
|
+
/**
|
|
33
|
+
* Whose cookie two entries left against the same stored generation are owed for: a browser holds
|
|
34
|
+
* one cookie, so the later one's person. The person either knows, when only one knows, or both name
|
|
35
|
+
* the same (the higher-ranked `revoke` kept). Two different persons, highest first (sdk#559, PR 566
|
|
36
|
+
* S1, SDK-D2025 as changed by sdk#559):
|
|
37
|
+
* - **A revoke's over a sign-out's.** A refused sign-in's cookie is never recorded or posted, so no
|
|
38
|
+
* tab can name it in a sign-out. A sign-out against the same stored generation names a cookie its
|
|
39
|
+
* tab knew from before, which that sign-in replaced, whichever was made first.
|
|
40
|
+
* - **A rider's over a maker's,** among objects that heard the sign-out the rider rode on. A revoke
|
|
41
|
+
* that rode on a sign-out pending here was sent under the cookie lock after that pending logout
|
|
42
|
+
* went, and the page's objects that existed then hear a revoke recorded as a sign-out in order, so
|
|
43
|
+
* a maker's sign-in among them can't come after a rider's at the same generation. An object made
|
|
44
|
+
* after that sign-out never hears it: its refused sign-in, later, is recorded as a maker and loses
|
|
45
|
+
* to the rider, or leaves none against another maker. That revoke is lost, as it was at main (PR
|
|
46
|
+
* 566 round 2 R1; the `close()` row lists it).
|
|
47
|
+
* - **Two of the same kind** (two riders, two makers, two sign-outs) leave none known, and the slot
|
|
48
|
+
* then gives way to a refresh's record, as before (`standingAt`).
|
|
49
|
+
*/
|
|
50
|
+
function ownerAt(a, b) {
|
|
51
|
+
if (a.person === null)
|
|
52
|
+
return owner(b);
|
|
53
|
+
if (b.person === null)
|
|
54
|
+
return owner(a);
|
|
55
|
+
if (a.person === b.person)
|
|
56
|
+
return owner(rank(a.revoke) >= rank(b.revoke) ? a : b);
|
|
57
|
+
if (rank(a.revoke) !== rank(b.revoke))
|
|
58
|
+
return owner(rank(a.revoke) > rank(b.revoke) ? a : b);
|
|
59
|
+
return NONE;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What an unrecorded sign-out is owed for once `person`'s revoke rode on its pending logout, while
|
|
63
|
+
* storage records generation `recorded`: that sign-in's cookie replaced the one it was owed for, so
|
|
64
|
+
* it is owed for that person now (PR 558 S1/R2). The rename changes `person` only. `basePerson`
|
|
65
|
+
* stays the person of the record the entry was made against. A rename never makes a sign-out that
|
|
66
|
+
* stands give way, so it is unchanged:
|
|
67
|
+
* - when the revoke names nobody (its answer couldn't be read): an unknown person never erases a
|
|
68
|
+
* known one, and a refresh naming someone else gives way all the same (PR 558 round 2 S1);
|
|
69
|
+
* - when storage records anything past the stored generation it was made against: then it stands
|
|
70
|
+
* past a refresh's record only because that record named the person it was owed for, a check
|
|
71
|
+
* already made, and any later record ends it whoever it names (`standingAt`).
|
|
72
|
+
*/
|
|
73
|
+
export function revokedOn(owed, person, recorded) {
|
|
74
|
+
return person === null || recorded > owed.stored ? owed : { ...owed, person, revoke: 'rode' };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The same for the page's slot, on the entry the revoke rode on only (the same generation and stored
|
|
78
|
+
* generation): an entry merged from another object's sign-out is left as it is (PR 558 round 2 S5).
|
|
79
|
+
*/
|
|
80
|
+
export function owedNowFor(slot, rodeOn, person, recorded) {
|
|
81
|
+
const left = slot.left;
|
|
82
|
+
if (left === null || left.generation !== rodeOn.generation || left.stored !== rodeOn.stored)
|
|
83
|
+
return;
|
|
84
|
+
slot.left = revokedOn(left, person, recorded);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The generation an unrecorded sign-out stands at now that storage reads `stored`, or null when it
|
|
88
|
+
* is over: one rule for a tab's memory (shared.ts) and a page's slot, so the two never disagree.
|
|
89
|
+
* `generation`: what it counted in memory; `owedFor`: what it was made against.
|
|
90
|
+
* - Storage reads that stored generation or a lower one (a lower one: the record was lost): it
|
|
91
|
+
* stands, as it was counted.
|
|
92
|
+
* - Storage reads a record a refresh made at one past it, naming the very person the sign-out was
|
|
93
|
+
* owed for: that refresh used the cookie the logout was owed for (a refused sign-in's, or a
|
|
94
|
+
* session signed out after its record was lost), so it still stands, past that record, and is
|
|
95
|
+
* written down there (sdk#552, sdk#543, SDK-D2025 as narrowed by the lead).
|
|
96
|
+
* - Storage reads any other higher record: a sign-in, a sign-out, a record without its maker,
|
|
97
|
+
* anything at two or more past, or a refresh's naming another person or with the person not
|
|
98
|
+
* known on either side. A record written since speaks for the cookie, and it is over (SDK-D1967,
|
|
99
|
+
* SDK-D1977, sdk#510). A refresh that found another person found the cookie changed owner, so no
|
|
100
|
+
* logout from it could reach the person signed out (PR 551 S4).
|
|
101
|
+
*/
|
|
102
|
+
export function standingAt(generation, owedFor, stored) {
|
|
103
|
+
if (stored.generation <= owedFor.stored)
|
|
104
|
+
return generation;
|
|
105
|
+
if (stored.madeBy === 'refresh' &&
|
|
106
|
+
stored.generation === owedFor.stored + 1 &&
|
|
107
|
+
stored.person !== null &&
|
|
108
|
+
stored.person === owedFor.person) {
|
|
109
|
+
return Math.max(generation, stored.generation + 1);
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The sign-out the slot stands for, as a state newer than `stored`, while it stands
|
|
115
|
+
* (`standingAt`); dropped once a record written since speaks for the cookie (SDK-D1967).
|
|
116
|
+
*/
|
|
117
|
+
export function owedState(slot, stored) {
|
|
118
|
+
const left = slot.left;
|
|
119
|
+
if (left === null)
|
|
120
|
+
return null;
|
|
121
|
+
const generation = standingAt(left.generation, left, stored);
|
|
122
|
+
if (generation === null) {
|
|
123
|
+
slot.left = null;
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return { ...stored, generation, signedIn: false, logoutPending: { generation }, principal: null, person: null, madeBy: 'sign-out' };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=owed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owed.js","sourceRoot":"","sources":["../../../src/first-party/session/owed.ts"],"names":[],"mappings":"AAyDA,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;AAExD;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,IAAgB;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;IACzB,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,OAAM;IACR,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACpD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;IACpG,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAA;IAC3F,IAAI,CAAC,IAAI,GAAG;QACV,UAAU,EAAE,I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|
@@ -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;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { unhandled as unhandledError } from '../report.js';
|
|
2
|
+
import { ABANDON_AFTER_MS } from '../http.js';
|
|
3
|
+
import { endTwoStep } from './cell.js';
|
|
4
|
+
const AFTER_PASSWORD_RESET = Symbol('after password reset');
|
|
5
|
+
export function createRefresher(deps, cell, { shared, withState, withCookie, broadcast }, { publish, hold, release, nextBackoff }, { sendLogout, notConfirmed }) {
|
|
6
|
+
const { http, report } = deps;
|
|
7
|
+
/**
|
|
8
|
+
* The refresh's outcome, or `unavailable` after 15 s, so no caller (a page load, every API
|
|
9
|
+
* request) waits on a pulse-auth that never answers. The request itself goes on: pulse-auth
|
|
10
|
+
* may have rotated the cookie already, and a later answer is still adopted.
|
|
11
|
+
*/
|
|
12
|
+
const answerWithin = (attempt) => new Promise((resolve) => {
|
|
13
|
+
const timer = setTimeout(() => {
|
|
14
|
+
resolve('unavailable');
|
|
15
|
+
}, ABANDON_AFTER_MS);
|
|
16
|
+
void attempt.then((outcome) => {
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
resolve(outcome);
|
|
19
|
+
}, (cause) => {
|
|
20
|
+
// Refresh attempts settle and browser storage absorbs throws. If a future check rejects,
|
|
21
|
+
// report it here and release its caller without waiting for the deadline.
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
resolve('unavailable');
|
|
24
|
+
report({ kind: 'threw', step: 'refresh', cause });
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
const startRefresh = (stale) => {
|
|
28
|
+
if (!cell.supported)
|
|
29
|
+
return Promise.resolve('signed-out');
|
|
30
|
+
if (cell.refreshInFlight !== null)
|
|
31
|
+
return cell.refreshInFlight;
|
|
32
|
+
const attempt = withCookie(async () => {
|
|
33
|
+
// Closed while this waited for the lock: nothing new is sent, neither the refresh nor a
|
|
34
|
+
// logout owed; another tab does that work (SDK-D1930). What is owed stays recorded.
|
|
35
|
+
if (cell.closed)
|
|
36
|
+
return 'unavailable';
|
|
37
|
+
const state = shared();
|
|
38
|
+
if (stale !== AFTER_PASSWORD_RESET &&
|
|
39
|
+
cell.held !== null &&
|
|
40
|
+
cell.held.access.token !== stale &&
|
|
41
|
+
cell.held.generation === state.generation) {
|
|
42
|
+
return 'ok';
|
|
43
|
+
}
|
|
44
|
+
if (state.logoutPending !== null &&
|
|
45
|
+
state.logoutPending.generation === state.generation) {
|
|
46
|
+
// Signed out, but pulse-auth never heard: finish that instead of quietly signing
|
|
47
|
+
// back in with a cookie that may still be valid; one that doesn't get through stays owed
|
|
48
|
+
// (SDK-D1963).
|
|
49
|
+
const answer = await sendLogout(state.generation);
|
|
50
|
+
if (answer.kind !== 'confirmed')
|
|
51
|
+
notConfirmed(answer, state.generation, state.serial);
|
|
52
|
+
if (cell.held !== null)
|
|
53
|
+
release({ status: 'signed-out' });
|
|
54
|
+
return 'signed-out';
|
|
55
|
+
}
|
|
56
|
+
const pinned = state.generation;
|
|
57
|
+
const answer = await http.refresh();
|
|
58
|
+
switch (answer.kind) {
|
|
59
|
+
case 'token': {
|
|
60
|
+
const decided = await withState((state) => {
|
|
61
|
+
// A sign-in or sign-out moved the state while this was in flight: the answer
|
|
62
|
+
// is stale. The rotated cookie it left is the signed-out session's, which that
|
|
63
|
+
// generation's pending logout revokes next.
|
|
64
|
+
if (state.generation !== pinned)
|
|
65
|
+
return { write: null, result: 'stale' };
|
|
66
|
+
// The same person, whatever their claims now (sdk#535). A record with no person (written
|
|
67
|
+
// before it was kept, or by a console) is compared with the token this tab holds at the
|
|
68
|
+
// pinned generation, a person this tab knows. With neither, nothing is assumed
|
|
69
|
+
// (SDK-D2023, amended in PR 551 S2).
|
|
70
|
+
const held = cell.held;
|
|
71
|
+
const known = state.person ?? (held !== null && held.generation === pinned ? held.access.person : null);
|
|
72
|
+
const samePerson = known === null || known === answer.access.person;
|
|
73
|
+
const next = state.signedIn && samePerson
|
|
74
|
+
? {
|
|
75
|
+
...state,
|
|
76
|
+
serial: state.serial + 1,
|
|
77
|
+
principal: answer.access.fingerprint,
|
|
78
|
+
person: answer.access.person,
|
|
79
|
+
}
|
|
80
|
+
: // A session the shared state doesn't know yet (a new browser, or Local
|
|
81
|
+
// Storage cleared while the cookie stayed), or another person behind the same
|
|
82
|
+
// cookie (sdk#535): it becomes the current one, at a new generation. Nothing is owed
|
|
83
|
+
// in the record. No logout owed for the old person's cookie is lost: the browser's one
|
|
84
|
+
// cookie is this person's now, so none could reach that session. Marked as a
|
|
85
|
+
// refresh's: an unrecorded sign-out made one generation before it (in another tab's
|
|
86
|
+
// or another page's memory) and owed for the person this record names (a refused
|
|
87
|
+
// sign-in's revoke, or a sign-out made after the record was lost) was owed for this
|
|
88
|
+
// very cookie, so it stands past this record and its logout still goes. One owed for
|
|
89
|
+
// another person gives way: the cookie changed owner (sdk#552, sdk#543, SDK-D2025 as
|
|
90
|
+
// narrowed, PR 551 S4).
|
|
91
|
+
{
|
|
92
|
+
generation: state.generation + 1,
|
|
93
|
+
signedIn: true,
|
|
94
|
+
serial: state.serial + 1,
|
|
95
|
+
logoutPending: null,
|
|
96
|
+
principal: answer.access.fingerprint,
|
|
97
|
+
person: answer.access.person,
|
|
98
|
+
madeBy: 'refresh',
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
write: next,
|
|
102
|
+
result: 'ok',
|
|
103
|
+
then: () => {
|
|
104
|
+
// A new generation ends this tab's own code screen as the other tabs end theirs: a
|
|
105
|
+
// code typed after it reads superseded (PR 551 S3, round 2 S1).
|
|
106
|
+
if (next.generation !== state.generation)
|
|
107
|
+
endTwoStep(cell);
|
|
108
|
+
hold(answer.access, next.generation, next.serial, 'here');
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
return decided.ran ? decided.value : 'unavailable';
|
|
113
|
+
}
|
|
114
|
+
case 'signed-out': {
|
|
115
|
+
const decided = await withState((state) => {
|
|
116
|
+
if (state.generation !== pinned)
|
|
117
|
+
return { write: null, result: 'stale' };
|
|
118
|
+
const write = state.signedIn
|
|
119
|
+
? {
|
|
120
|
+
...state,
|
|
121
|
+
generation: state.generation + 1,
|
|
122
|
+
signedIn: false,
|
|
123
|
+
logoutPending: null,
|
|
124
|
+
principal: null,
|
|
125
|
+
person: null,
|
|
126
|
+
// A refresh's: the cookie was dead. It names no person, so an unrecorded sign-out
|
|
127
|
+
// never stands past it and gives way, as before (`standingAt`).
|
|
128
|
+
madeBy: 'refresh',
|
|
129
|
+
}
|
|
130
|
+
: null;
|
|
131
|
+
return {
|
|
132
|
+
write,
|
|
133
|
+
result: 'signed-out',
|
|
134
|
+
then: () => {
|
|
135
|
+
release({ status: 'signed-out' });
|
|
136
|
+
if (write !== null) {
|
|
137
|
+
broadcast({ type: 'signed-out', generation: write.generation });
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
return decided.ran ? decided.value : 'unavailable';
|
|
143
|
+
}
|
|
144
|
+
case 'unavailable':
|
|
145
|
+
return 'unavailable';
|
|
146
|
+
case 'broken':
|
|
147
|
+
report({ kind: 'answer', path: '/refresh', status: answer.httpStatus });
|
|
148
|
+
// The cookie and the shared state are left alone: one bad answer shouldn't
|
|
149
|
+
// throw away a session that may be fine. This tab just can't use it now.
|
|
150
|
+
release({ status: 'broken', httpStatus: answer.httpStatus });
|
|
151
|
+
return 'broken';
|
|
152
|
+
default: {
|
|
153
|
+
const unhandled = answer;
|
|
154
|
+
throw unhandledError('refresh answer', unhandled);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}).then((locked) => (locked.ran ? locked.value : 'unavailable'), (error) => {
|
|
158
|
+
// Not expected: the run handles its own answers. A refresh never rejects, or a
|
|
159
|
+
// page load would wait on it forever.
|
|
160
|
+
report({ kind: 'threw', step: 'refresh', cause: error });
|
|
161
|
+
return 'unavailable';
|
|
162
|
+
});
|
|
163
|
+
cell.refreshInFlight = attempt;
|
|
164
|
+
void attempt.finally(() => {
|
|
165
|
+
if (cell.refreshInFlight === attempt)
|
|
166
|
+
cell.refreshInFlight = null;
|
|
167
|
+
});
|
|
168
|
+
return attempt;
|
|
169
|
+
};
|
|
170
|
+
const refresh = (stale) => answerWithin(startRefresh(stale));
|
|
171
|
+
const checkAfterReset = async () => {
|
|
172
|
+
// Earlier refreshes can predate the reset, including a restore that first discovers a session.
|
|
173
|
+
while (cell.refreshInFlight !== null)
|
|
174
|
+
await cell.refreshInFlight;
|
|
175
|
+
if (cell.closed || !cell.supported || (cell.held === null && !shared().signedIn))
|
|
176
|
+
return 'signed-out';
|
|
177
|
+
return startRefresh(AFTER_PASSWORD_RESET);
|
|
178
|
+
};
|
|
179
|
+
const runRestore = async (tries) => {
|
|
180
|
+
clearTimeout(cell.restoreTimer);
|
|
181
|
+
const outcome = await refresh(cell.held?.access.token ?? null);
|
|
182
|
+
// A token that arrived meanwhile (another tab's, by message) already said so.
|
|
183
|
+
if (cell.held !== null && outcome !== 'broken')
|
|
184
|
+
return;
|
|
185
|
+
switch (outcome) {
|
|
186
|
+
case 'ok':
|
|
187
|
+
return;
|
|
188
|
+
case 'signed-out':
|
|
189
|
+
if (cell.status.status !== 'signed-out')
|
|
190
|
+
publish({ status: 'signed-out' });
|
|
191
|
+
return;
|
|
192
|
+
case 'broken':
|
|
193
|
+
return;
|
|
194
|
+
case 'stale':
|
|
195
|
+
// The state moved while the answer was in flight: ask again, for the state as it
|
|
196
|
+
// is now. A few times at most; then this is just "can't reach".
|
|
197
|
+
// Closed meanwhile: nothing more is started.
|
|
198
|
+
if (cell.closed)
|
|
199
|
+
break;
|
|
200
|
+
if (tries < 3) {
|
|
201
|
+
await restore(tries + 1);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case 'unavailable':
|
|
206
|
+
break;
|
|
207
|
+
default: {
|
|
208
|
+
const unhandled = outcome;
|
|
209
|
+
throw new Error(`unhandled outcome ${String(unhandled)}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const retryInMs = nextBackoff();
|
|
213
|
+
publish({ status: 'unavailable', retryInMs });
|
|
214
|
+
// Two restores that overlap each get here: the later one's timer replaces the earlier one's,
|
|
215
|
+
// or close() could clear only the handle it can see.
|
|
216
|
+
clearTimeout(cell.restoreTimer);
|
|
217
|
+
if (cell.closed)
|
|
218
|
+
return;
|
|
219
|
+
cell.restoreTimer = setTimeout(() => {
|
|
220
|
+
if (!cell.closed)
|
|
221
|
+
void restore();
|
|
222
|
+
}, retryInMs);
|
|
223
|
+
};
|
|
224
|
+
let activeRestores = 0;
|
|
225
|
+
const restore = async (tries = 0) => {
|
|
226
|
+
activeRestores++;
|
|
227
|
+
try {
|
|
228
|
+
await runRestore(tries);
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
activeRestores--;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
return { refresh, refreshAfterPasswordReset: () => answerWithin(checkAfterReset()), restore, restoring: () => activeRestores > 0 };
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.js","sourceRoot":"","sources":["../../../src/first-party/session/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAyC,MAAM,WAAW,CAAA;AAM7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAA;AAgB3D,MAAM,UAAU,eAAe,CAC7B,IAAiB,EACjB,IAAiB,EACjB,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAe,EACzD,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAU,EAC/C,EAAE,UAAU,EAAE,YAAY,EAAU;IAEpC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAE7B;;;;OAIG;IACH,MAAM,YAAY,GAAG,CAAC,OAAgC,EAA2B,EAAE,CACjF,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACtB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,OAAO,CAAC,aAAa,CAAC,CAAA;QACxB,CAAC,EAAE,gBAAgB,CAAC,CAAA;QACpB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO,CAAC,OAAO,CAAC,CAAA;QAClB,CAAC,EAAE,CAAC,KAAc,EAAE,EAAE;YACpB,yFAAyF;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,CAAC,CAAA;IAED,IAAI,cAAc,GAAG,CAAC,CAAA;IACtB,MAAM,OAAO,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC,EAAiB,EAAE;QACjD,cAAc,EAAE,CAAA;QAChB,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC;gBAAS,CAAC;YACT,cAAc,EAAE,CAAA;QAClB,CAAC;IACH,CAAC,CAAA;IAED,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,GAAG,CAAC,EAAE,CAAA;AACpI,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SignInSetup } from '../hooks.js';
|
|
2
|
+
import type { RedeemResult, SupersededVerify, TwoStepResult } from './types.js';
|
|
3
|
+
/** What a redeem or a verify came to, inside the lock: every case either can meet. */
|
|
4
|
+
export type Settled = {
|
|
5
|
+
readonly kind: 'signed-in';
|
|
6
|
+
readonly backupCodes: readonly string[] | null;
|
|
7
|
+
} | SupersededVerify | {
|
|
8
|
+
readonly kind: 'two-step';
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'two-step-setup';
|
|
11
|
+
readonly setup: SignInSetup;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'dead-link';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'wrong-code';
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'locked';
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'expired';
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'no-account';
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'inactive';
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'proxy-refused';
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'unavailable';
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: 'unknown';
|
|
30
|
+
readonly status: number;
|
|
31
|
+
};
|
|
32
|
+
export declare function redeemResultOf(settled: Settled): RedeemResult;
|
|
33
|
+
/**
|
|
34
|
+
* `answeredAt`: this tab's clock when pulse-auth answered. `keptUntil`: the end of a lock this
|
|
35
|
+
* browser was already told about for the address, while still ahead (`twoStepLock.ts`): a
|
|
36
|
+
* lock isn't moved by a code tried during it, so that end stands.
|
|
37
|
+
*/
|
|
38
|
+
export declare function twoStepResultOf(settled: Settled, answeredAt: number, keptUntil: number | null): TwoStepResult;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { firstLockEnd, MINUTE_MS, TWO_STEP_LOCKOUT_MS } from '../twoStepLock.js';
|
|
2
|
+
import { unhandled as unhandledError } from '../report.js';
|
|
3
|
+
export function redeemResultOf(settled) {
|
|
4
|
+
switch (settled.kind) {
|
|
5
|
+
// A link's redeem never sets two-step up, so it never has backup codes to carry.
|
|
6
|
+
case 'signed-in':
|
|
7
|
+
return { kind: 'signed-in' };
|
|
8
|
+
case 'two-step-setup':
|
|
9
|
+
return settled;
|
|
10
|
+
case 'superseded':
|
|
11
|
+
case 'two-step':
|
|
12
|
+
case 'dead-link':
|
|
13
|
+
case 'no-account':
|
|
14
|
+
case 'inactive':
|
|
15
|
+
case 'proxy-refused':
|
|
16
|
+
case 'unavailable':
|
|
17
|
+
return { kind: settled.kind };
|
|
18
|
+
case 'unknown':
|
|
19
|
+
return { kind: 'unknown', status: settled.status };
|
|
20
|
+
// A code's refusal can't answer a link: outside pulse-auth's contract.
|
|
21
|
+
case 'wrong-code':
|
|
22
|
+
case 'locked':
|
|
23
|
+
case 'expired':
|
|
24
|
+
return { kind: 'unknown', status: 400 };
|
|
25
|
+
default: {
|
|
26
|
+
const unhandled = settled;
|
|
27
|
+
throw unhandledError('result', unhandled);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `answeredAt`: this tab's clock when pulse-auth answered. `keptUntil`: the end of a lock this
|
|
33
|
+
* browser was already told about for the address, while still ahead (`twoStepLock.ts`): a
|
|
34
|
+
* lock isn't moved by a code tried during it, so that end stands.
|
|
35
|
+
*/
|
|
36
|
+
export function twoStepResultOf(settled, answeredAt, keptUntil) {
|
|
37
|
+
switch (settled.kind) {
|
|
38
|
+
case 'locked':
|
|
39
|
+
return keptUntil === null
|
|
40
|
+
? {
|
|
41
|
+
kind: 'locked',
|
|
42
|
+
minutes: TWO_STEP_LOCKOUT_MS / MINUTE_MS,
|
|
43
|
+
until: firstLockEnd(answeredAt),
|
|
44
|
+
}
|
|
45
|
+
: {
|
|
46
|
+
kind: 'locked',
|
|
47
|
+
minutes: Math.ceil((keptUntil - answeredAt) / MINUTE_MS),
|
|
48
|
+
until: keptUntil,
|
|
49
|
+
};
|
|
50
|
+
case 'signed-in':
|
|
51
|
+
return { kind: 'signed-in', backupCodes: settled.backupCodes };
|
|
52
|
+
case 'superseded':
|
|
53
|
+
return settled;
|
|
54
|
+
case 'wrong-code':
|
|
55
|
+
case 'expired':
|
|
56
|
+
case 'no-account':
|
|
57
|
+
case 'inactive':
|
|
58
|
+
case 'proxy-refused':
|
|
59
|
+
case 'unavailable':
|
|
60
|
+
return { kind: settled.kind };
|
|
61
|
+
case 'unknown':
|
|
62
|
+
return { kind: 'unknown', status: settled.status };
|
|
63
|
+
// A link's answers can't answer a code: outside pulse-auth's contract.
|
|
64
|
+
case 'two-step':
|
|
65
|
+
case 'two-step-setup':
|
|
66
|
+
case 'dead-link':
|
|
67
|
+
return { kind: 'unknown', status: 200 };
|
|
68
|
+
default: {
|
|
69
|
+
const unhandled = settled;
|
|
70
|
+
throw unhandledError('result', unhandled);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../../src/first-party/session/results.ts"],"names":[],"mappings":"AAC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