@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,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The browser's pieces the session needs, as small interfaces: tests hand in fakes (a lock
|
|
3
|
+
* manager several tabs share, a slow channel, one storage), never `vi.mock` (the testing
|
|
4
|
+
* skill, hard rule 1), and a browser without them is `unsupported`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Where a page subscriber's exception goes. A page has `reportError`, which is also what a
|
|
8
|
+
* listener that throws does there. Outside a page there is none, so the same exception is
|
|
9
|
+
* thrown again from a fresh microtask, as Node does for a listener (SDK-D1915). Either way
|
|
10
|
+
* it stays out of the session's own report.
|
|
11
|
+
*/
|
|
12
|
+
export function subscriberErrorReporter(host) {
|
|
13
|
+
const reportError = host.reportError;
|
|
14
|
+
if (typeof reportError === 'function')
|
|
15
|
+
return reportError.bind(host);
|
|
16
|
+
return (cause) => {
|
|
17
|
+
host.queueMicrotask(() => {
|
|
18
|
+
throw cause;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The page's storage, or null when this browser won't let the page use it (blocked site
|
|
24
|
+
* data, or none at all). `typeof` only shields a name that isn't there. Where site data is
|
|
25
|
+
* blocked the getter itself throws, and that is the same answer: no storage (SDK-D1940).
|
|
26
|
+
*/
|
|
27
|
+
function openStorage(read) {
|
|
28
|
+
try {
|
|
29
|
+
const storage = read();
|
|
30
|
+
return storage === undefined ? null : wrap(storage);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* localStorage behind StorageLike, or null when this browser won't let the page use it
|
|
38
|
+
* (blocked site data, or none at all): such a browser can't sign in (§2.3).
|
|
39
|
+
*/
|
|
40
|
+
export function browserStorage() {
|
|
41
|
+
return openStorage(() => globalThis.localStorage);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This tab's sessionStorage behind StorageLike, or null without it: where a staff member's
|
|
45
|
+
* choice of customer is kept, per tab (§2.7). A blocked getter is null, as localStorage is.
|
|
46
|
+
*/
|
|
47
|
+
export function browserTabStorage() {
|
|
48
|
+
return openStorage(() => globalThis.sessionStorage);
|
|
49
|
+
}
|
|
50
|
+
function wrap(storage) {
|
|
51
|
+
try {
|
|
52
|
+
const probe = 'flipstream-auth:probe';
|
|
53
|
+
storage.setItem(probe, '1');
|
|
54
|
+
storage.removeItem(probe);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
getItem(key) {
|
|
61
|
+
try {
|
|
62
|
+
return storage.getItem(key);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
setItem(key, value) {
|
|
69
|
+
try {
|
|
70
|
+
storage.setItem(key, value);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
removeItem(key) {
|
|
78
|
+
try {
|
|
79
|
+
storage.removeItem(key);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// A removal that failed leaves an entry that expires or is overwritten.
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
keys() {
|
|
86
|
+
try {
|
|
87
|
+
return Array.from({ length: storage.length }, (_, i) => storage.key(i)).filter((key) => key !== null);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** `navigator.locks`, or null where there are no Web Locks (Safari before 15.4). */
|
|
96
|
+
export function browserLocks() {
|
|
97
|
+
if (typeof navigator === 'undefined' || !('locks' in navigator))
|
|
98
|
+
return null;
|
|
99
|
+
const locks = navigator.locks;
|
|
100
|
+
return {
|
|
101
|
+
// TypeScript 5.9's DOM types say `request` answers a promise of the callback's promise;
|
|
102
|
+
// the browser flattens it, and `await` says so to the compiler (os builds on 6.0, whose
|
|
103
|
+
// types need nothing here).
|
|
104
|
+
request: async (name, options, callback) => await locks.request(name, options, callback),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The tabs' channel, or null when this browser has no BroadcastChannel or refuses to open
|
|
109
|
+
* one. Firefox throws SecurityError from the constructor when storage is denied. That is
|
|
110
|
+
* no channel, the same as a missing BroadcastChannel: the shared state still works, and
|
|
111
|
+
* creating the session does not throw (SDK-D1940).
|
|
112
|
+
*/
|
|
113
|
+
export function browserChannel(name) {
|
|
114
|
+
if (typeof BroadcastChannel === 'undefined')
|
|
115
|
+
return null;
|
|
116
|
+
try {
|
|
117
|
+
const channel = new BroadcastChannel(name);
|
|
118
|
+
return {
|
|
119
|
+
postMessage: (message) => {
|
|
120
|
+
channel.postMessage(message);
|
|
121
|
+
},
|
|
122
|
+
addEventListener: (type, listener) => {
|
|
123
|
+
channel.addEventListener(type, listener);
|
|
124
|
+
},
|
|
125
|
+
removeEventListener: (type, listener) => {
|
|
126
|
+
channel.removeEventListener(type, listener);
|
|
127
|
+
},
|
|
128
|
+
close: () => {
|
|
129
|
+
channel.close();
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/first-party/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmCH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAGvC;IACC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;IACpC,IAAI,OAAO,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AA;IACxD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAA;QAC1C,OAAO;YACL,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE;gBACvB,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YAC9B,CAAC;YACD,gBAAgB,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACnC,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC1C,CAAC;YACD,mBAAmB,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACtC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC7C,CAAC;YACD,KAAK,EAAE,GAAG,EAAE;gBACV,OAAO,CAAC,KAAK,EAAE,CAAA;YACjB,CAAC;SACF,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type ChannelLike, type LockManagerLike, type StorageLike } from './browser.js';
|
|
2
|
+
import type { SessionReport } from './report.js';
|
|
3
|
+
import { type LoginLinkRequest, type OpenedLink, type SignupAttemptDeps } from './links.js';
|
|
4
|
+
import { type AuthSession, type RedeemResult, type SessionView } from './session/index.js';
|
|
5
|
+
import { type OwedSlot } from './session/owed.js';
|
|
6
|
+
export interface FirstPartyDeps {
|
|
7
|
+
/** The one network edge. Tests serve recorded answers through it. */
|
|
8
|
+
readonly fetch: typeof fetch;
|
|
9
|
+
readonly locks: LockManagerLike | null;
|
|
10
|
+
readonly storage: StorageLike | null;
|
|
11
|
+
readonly channel: ChannelLike | null;
|
|
12
|
+
/** What the app's operator should know (report.ts): never a body, a token or a message's content. */
|
|
13
|
+
readonly report: (report: SessionReport) => void;
|
|
14
|
+
/** A subscriber's exception, sent where the page's uncaught errors go (SDK-D1915). */
|
|
15
|
+
readonly reportError: (cause: unknown) => void;
|
|
16
|
+
readonly now: () => number;
|
|
17
|
+
readonly random: (bytes: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
|
|
18
|
+
/** The page's own origin: where login links land. */
|
|
19
|
+
readonly origin: string;
|
|
20
|
+
/** The path on it a login link lands on (the console's is `/login/confirm`). */
|
|
21
|
+
readonly landing: string;
|
|
22
|
+
/** The same-origin path the page's own server forwards to pulse-auth (the console's is `/auth`). */
|
|
23
|
+
readonly authPath: string;
|
|
24
|
+
/** The login link's token, which the page's first script took out of the address. */
|
|
25
|
+
readonly linkToken: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* The page's slot for a logout a closed session owed, which storage never took (owed.ts,
|
|
28
|
+
* sdk#483): one per page and auth path, shared by every session made there.
|
|
29
|
+
*/
|
|
30
|
+
readonly owed: OwedSlot | null;
|
|
31
|
+
}
|
|
32
|
+
type ReadyLink = Extract<OpenedLink, {
|
|
33
|
+
readonly kind: 'ready';
|
|
34
|
+
}>;
|
|
35
|
+
/** What a page holds: the session's state and actions, and the links. Never a token. */
|
|
36
|
+
export interface BrowserSession {
|
|
37
|
+
readonly session: SessionView;
|
|
38
|
+
/** Asks for a login link, remembering in this tab's memory which address it went to. */
|
|
39
|
+
requestLink(email: string, next: string | null, signal?: AbortSignal): Promise<LoginLinkRequest>;
|
|
40
|
+
/** The address this tab last sent a link to, typed here, never read from an address bar. */
|
|
41
|
+
lastSent(): {
|
|
42
|
+
readonly email: string;
|
|
43
|
+
readonly next: string | null;
|
|
44
|
+
readonly at: number;
|
|
45
|
+
} | null;
|
|
46
|
+
/** Checks the link this page was opened with, before anyone clicks; never its token. */
|
|
47
|
+
checkLink(link: {
|
|
48
|
+
readonly attempt: unknown;
|
|
49
|
+
readonly email: unknown;
|
|
50
|
+
readonly invite?: unknown;
|
|
51
|
+
}): OpenedLink;
|
|
52
|
+
/** Redeems a checked link, on a click, checking it again first. */
|
|
53
|
+
redeem(link: ReadyLink, signal?: AbortSignal): Promise<RedeemResult>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether a link can land on the page's own origin: only an http or https origin (scheme, host
|
|
57
|
+
* and port, nothing more) can. Anything else (`'null'`, what an opaque origin reads as; `file://`;
|
|
58
|
+
* an extension's; a string that doesn't parse) is a session nobody can sign in to. Never a
|
|
59
|
+
* RangeError: the origin is the page's, not an option the developer gives (SDK-D1934).
|
|
60
|
+
*/
|
|
61
|
+
export declare function linkCanLand(origin: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The browser session and its whole session beside it, credentials included: for this module's
|
|
64
|
+
* browser events and the tests. os's createAuthInternals, without the console's own parts.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createFirstPartyInternals(deps: FirstPartyDeps): {
|
|
67
|
+
readonly browser: BrowserSession;
|
|
68
|
+
readonly session: AuthSession;
|
|
69
|
+
readonly linkDeps: SignupAttemptDeps;
|
|
70
|
+
};
|
|
71
|
+
export type BrowserOptions = Pick<FirstPartyDeps, 'report' | 'origin' | 'landing' | 'authPath' | 'linkToken'>;
|
|
72
|
+
/**
|
|
73
|
+
* The real browser's edges: localStorage, Web Locks and a BroadcastChannel (either of the first
|
|
74
|
+
* two missing makes the session `unsupported`), with the console's names, so its tabs and the
|
|
75
|
+
* console's take turns; this page's fetch, the wall clock and the browser's random bytes.
|
|
76
|
+
* An unsupported session opens no channel. Firefox throws from the constructor when storage
|
|
77
|
+
* is denied, and there is then nothing to close (SDK-D1940).
|
|
78
|
+
*/
|
|
79
|
+
export declare function browserDeps(options: BrowserOptions): FirstPartyDeps;
|
|
80
|
+
/**
|
|
81
|
+
* The browser session in a real browser (browserDeps), and the events that keep its tabs in
|
|
82
|
+
* step. `start()` is the caller's, after it has subscribed.
|
|
83
|
+
*/
|
|
84
|
+
export declare function createBrowserSession(options: BrowserOptions): BrowserSession;
|
|
85
|
+
/**
|
|
86
|
+
* `createBrowserSession`, with its whole session beside it, for the entry's hooks (#465): what
|
|
87
|
+
* only the families read (the set-up challenge, the signed-in address), never the page.
|
|
88
|
+
* `browser.session.close()` also takes the browser's events off.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createBrowserInternals(options: BrowserOptions): {
|
|
91
|
+
readonly browser: BrowserSession;
|
|
92
|
+
readonly session: AuthSession;
|
|
93
|
+
readonly linkDeps: SignupAttemptDeps;
|
|
94
|
+
};
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { wallClock } from '../core/deadline.js';
|
|
2
|
+
import { keepsNoStore } from '../core/fetch.js';
|
|
3
|
+
import { browserChannel, browserLocks, browserStorage, subscriberErrorReporter, } from './browser.js';
|
|
4
|
+
import { checkLanding } from './attempts.js';
|
|
5
|
+
import { checkCookieCalls, createAuthHttp } from './http.js';
|
|
6
|
+
import { checkLink, requestLink, } from './links.js';
|
|
7
|
+
import { createAuthSession, } from './session/index.js';
|
|
8
|
+
import { SessionClosedError } from './session/closed.js';
|
|
9
|
+
import { owedSlot } from './session/owed.js';
|
|
10
|
+
import { STATE_KEY } from './state.js';
|
|
11
|
+
/**
|
|
12
|
+
* Whether a link can land on the page's own origin: only an http or https origin (scheme, host
|
|
13
|
+
* and port, nothing more) can. Anything else (`'null'`, what an opaque origin reads as; `file://`;
|
|
14
|
+
* an extension's; a string that doesn't parse) is a session nobody can sign in to. Never a
|
|
15
|
+
* RangeError: the origin is the page's, not an option the developer gives (SDK-D1934).
|
|
16
|
+
*/
|
|
17
|
+
export function linkCanLand(origin) {
|
|
18
|
+
let url;
|
|
19
|
+
try {
|
|
20
|
+
url = new URL(origin);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return (url.protocol === 'https:' || url.protocol === 'http:') && url.origin === origin;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The browser session and its whole session beside it, credentials included: for this module's
|
|
29
|
+
* browser events and the tests. os's createAuthInternals, without the console's own parts.
|
|
30
|
+
*/
|
|
31
|
+
export function createFirstPartyInternals(deps) {
|
|
32
|
+
// A wrong address fails here, where the session is made, not on a person's first click, with
|
|
33
|
+
// an attempt left behind (#464's round 2, finding 4).
|
|
34
|
+
checkLanding(deps.landing);
|
|
35
|
+
const opaque = !linkCanLand(deps.origin);
|
|
36
|
+
// A page whose origin is opaque, or not http (a sandboxed frame, a file, an extension), has no
|
|
37
|
+
// address a link can land on: nobody can sign in there, as in a browser without locks or storage.
|
|
38
|
+
const storage = opaque ? null : deps.storage;
|
|
39
|
+
const locks = opaque ? null : deps.locks;
|
|
40
|
+
// An origin the page cannot land on is not given to the cookie client. createAuthHttp throws
|
|
41
|
+
// on one that does not parse, and this session is the inert one instead (SDK-D1934).
|
|
42
|
+
const http = createAuthHttp(deps.fetch, deps.now, deps.authPath, opaque ? undefined : deps.origin);
|
|
43
|
+
const session = createAuthSession({
|
|
44
|
+
http,
|
|
45
|
+
locks,
|
|
46
|
+
storage,
|
|
47
|
+
channel: deps.channel,
|
|
48
|
+
report: deps.report,
|
|
49
|
+
reportError: deps.reportError,
|
|
50
|
+
now: deps.now,
|
|
51
|
+
owed: opaque ? null : deps.owed,
|
|
52
|
+
});
|
|
53
|
+
const links = {
|
|
54
|
+
http,
|
|
55
|
+
// A browser without locks is unsupported: a link mailed from it could never be redeemed here,
|
|
56
|
+
// so no attempt is stored and nothing is asked (the Codex read of 254279c, 1).
|
|
57
|
+
storage: locks === null ? null : storage,
|
|
58
|
+
origin: deps.origin,
|
|
59
|
+
landing: deps.landing,
|
|
60
|
+
now: deps.now,
|
|
61
|
+
random: deps.random,
|
|
62
|
+
};
|
|
63
|
+
let sent = null;
|
|
64
|
+
// The page's calls that send follow the session's close(): a closed one sends nothing.
|
|
65
|
+
let closed = false;
|
|
66
|
+
const stillOpen = (call) => {
|
|
67
|
+
if (closed)
|
|
68
|
+
throw new SessionClosedError(call);
|
|
69
|
+
};
|
|
70
|
+
// Its own object, not the session narrowed by a type: what the page holds has no credential
|
|
71
|
+
// to reach, whatever it does with it.
|
|
72
|
+
const view = {
|
|
73
|
+
current: () => session.current(),
|
|
74
|
+
subscribe: (listener) => session.subscribe(listener),
|
|
75
|
+
ready: () => session.ready(),
|
|
76
|
+
start: () => {
|
|
77
|
+
session.start();
|
|
78
|
+
},
|
|
79
|
+
retry: () => {
|
|
80
|
+
session.retry();
|
|
81
|
+
},
|
|
82
|
+
twoStepPending: () => session.twoStepPending(),
|
|
83
|
+
twoStepEndedByTab: () => session.twoStepEndedByTab(),
|
|
84
|
+
verifyTwoStep: (code, signal, onSend) => session.verifyTwoStep(code, signal, onSend),
|
|
85
|
+
signOut: () => session.signOut(),
|
|
86
|
+
sync: () => session.sync(),
|
|
87
|
+
stateWritten: () => session.stateWritten(),
|
|
88
|
+
close: () => {
|
|
89
|
+
closed = true;
|
|
90
|
+
session.close();
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const browser = {
|
|
94
|
+
session: view,
|
|
95
|
+
async requestLink(email, next, signal) {
|
|
96
|
+
stillOpen('requestLink()');
|
|
97
|
+
const result = await requestLink(links, email, next, signal);
|
|
98
|
+
if (result.kind === 'sent')
|
|
99
|
+
sent = { email: result.email, next, at: deps.now() };
|
|
100
|
+
return result;
|
|
101
|
+
},
|
|
102
|
+
lastSent: () => sent,
|
|
103
|
+
checkLink: (link) => {
|
|
104
|
+
const check = checkLink(storage, { ...link, token: deps.linkToken }, deps.now());
|
|
105
|
+
if (check.kind !== 'ready')
|
|
106
|
+
return check;
|
|
107
|
+
return {
|
|
108
|
+
kind: 'ready',
|
|
109
|
+
email: check.email,
|
|
110
|
+
attemptId: check.attemptId,
|
|
111
|
+
attempt: check.attempt,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
redeem: (link, signal) => {
|
|
115
|
+
if (closed)
|
|
116
|
+
return Promise.reject(new SessionClosedError('redeem()'));
|
|
117
|
+
const check = checkLink(storage, { token: deps.linkToken, attempt: link.attemptId, email: link.email }, deps.now());
|
|
118
|
+
if (check.kind !== 'ready')
|
|
119
|
+
return Promise.resolve({ kind: 'dead-link' });
|
|
120
|
+
return session.redeem(check.token, check.attemptId, signal);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
return { browser, session, linkDeps: links };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* This page's slots for an owed logout, by origin and auth path (sdk#483): a module lives as long
|
|
127
|
+
* as its page, so a session made after another closed (a remount, a hot reload) finds what it left.
|
|
128
|
+
*/
|
|
129
|
+
const pageSlots = new Map();
|
|
130
|
+
function pageSlot(key) {
|
|
131
|
+
const known = pageSlots.get(key);
|
|
132
|
+
if (known !== undefined)
|
|
133
|
+
return known;
|
|
134
|
+
const slot = owedSlot();
|
|
135
|
+
pageSlots.set(key, slot);
|
|
136
|
+
return slot;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The real browser's edges: localStorage, Web Locks and a BroadcastChannel (either of the first
|
|
140
|
+
* two missing makes the session `unsupported`), with the console's names, so its tabs and the
|
|
141
|
+
* console's take turns; this page's fetch, the wall clock and the browser's random bytes.
|
|
142
|
+
* An unsupported session opens no channel. Firefox throws from the constructor when storage
|
|
143
|
+
* is denied, and there is then nothing to close (SDK-D1940).
|
|
144
|
+
*/
|
|
145
|
+
export function browserDeps(options) {
|
|
146
|
+
const locks = browserLocks();
|
|
147
|
+
const storage = browserStorage();
|
|
148
|
+
return {
|
|
149
|
+
...options,
|
|
150
|
+
owed: pageSlot(`${options.origin}${options.authPath}`),
|
|
151
|
+
reportError: subscriberErrorReporter(globalThis),
|
|
152
|
+
// A wrapper, so the browser's own fetch is called with its own `this`.
|
|
153
|
+
fetch: (input, init) => fetch(input, init),
|
|
154
|
+
locks,
|
|
155
|
+
storage,
|
|
156
|
+
channel: locks === null || storage === null ? null : browserChannel('flipstream-auth'),
|
|
157
|
+
now: wallClock,
|
|
158
|
+
random: (bytes) => crypto.getRandomValues(bytes),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The browser session in a real browser (browserDeps), and the events that keep its tabs in
|
|
163
|
+
* step. `start()` is the caller's, after it has subscribed.
|
|
164
|
+
*/
|
|
165
|
+
export function createBrowserSession(options) {
|
|
166
|
+
return createBrowserInternals(options).browser;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* `createBrowserSession`, with its whole session beside it, for the entry's hooks (#465): what
|
|
170
|
+
* only the families read (the set-up challenge, the signed-in address), never the page.
|
|
171
|
+
* `browser.session.close()` also takes the browser's events off.
|
|
172
|
+
*/
|
|
173
|
+
export function createBrowserInternals(options) {
|
|
174
|
+
// Before anything is opened: a wrong landing must not leave a channel
|
|
175
|
+
// behind (SDK-D1934). A cookie path that would leave the page is checked once the page can
|
|
176
|
+
// take a link, still before the channel, because that is the path which opens one.
|
|
177
|
+
checkLanding(options.landing);
|
|
178
|
+
// Outside a page (a server render, a prerender, a worker), or in a page whose origin can't take
|
|
179
|
+
// a link (a sandboxed frame or a data: page, whose origin is null; a file; an extension): an
|
|
180
|
+
// unsupported session, with no channel and no listener, so nothing holds the process and nothing
|
|
181
|
+
// needs closing. Its storage is never read: a sandboxed frame throws on localStorage.
|
|
182
|
+
// So is a page whose global Request doesn't keep `cache: 'no-store'` (one with no native fetch,
|
|
183
|
+
// where a polyfill such as whatwg-fetch fills it in): the person's bearer requests would go where
|
|
184
|
+
// its HTTP cache can answer them, and such a fetch can't keep `redirect: 'manual'` either
|
|
185
|
+
// (SDK-D2013, SDK-D1953). The check reads `Request`, not `fetch`; the person sender asks it again
|
|
186
|
+
// at each send.
|
|
187
|
+
if (typeof window === 'undefined' || typeof document === 'undefined' || !linkCanLand(options.origin) || !keepsNoStore()) {
|
|
188
|
+
return createFirstPartyInternals({
|
|
189
|
+
...options,
|
|
190
|
+
reportError: subscriberErrorReporter(globalThis),
|
|
191
|
+
fetch: (input, init) => fetch(input, init),
|
|
192
|
+
locks: null,
|
|
193
|
+
storage: null,
|
|
194
|
+
channel: null,
|
|
195
|
+
now: wallClock,
|
|
196
|
+
random: (bytes) => crypto.getRandomValues(bytes),
|
|
197
|
+
owed: null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// The cookie client throws when the path would leave this page. Prove that before the
|
|
201
|
+
// channel is opened, so the throw leaves nothing to close (SDK-D1934).
|
|
202
|
+
checkCookieCalls(options.authPath, options.origin);
|
|
203
|
+
const { browser, session, linkDeps } = createFirstPartyInternals(browserDeps(options));
|
|
204
|
+
// Another tab changed the shared state: catch up at once, even if its message never comes.
|
|
205
|
+
const stored = (event) => {
|
|
206
|
+
if (event.key === STATE_KEY || event.key === null)
|
|
207
|
+
void session.stateWritten();
|
|
208
|
+
};
|
|
209
|
+
// A laptop waking up can hold an expired token whose timer fired late, or have missed a
|
|
210
|
+
// sign-out in another tab: check on the way back.
|
|
211
|
+
const shown = () => {
|
|
212
|
+
if (document.visibilityState === 'visible')
|
|
213
|
+
void session.getAccessToken();
|
|
214
|
+
};
|
|
215
|
+
// Back online: don't wait out the backoff, and send a logout still owed.
|
|
216
|
+
const online = () => {
|
|
217
|
+
if (session.current().status === 'unavailable')
|
|
218
|
+
session.retry();
|
|
219
|
+
else
|
|
220
|
+
void session.sync();
|
|
221
|
+
};
|
|
222
|
+
window.addEventListener('storage', stored);
|
|
223
|
+
document.addEventListener('visibilitychange', shown);
|
|
224
|
+
window.addEventListener('online', online);
|
|
225
|
+
return {
|
|
226
|
+
session,
|
|
227
|
+
linkDeps,
|
|
228
|
+
browser: {
|
|
229
|
+
...browser,
|
|
230
|
+
session: {
|
|
231
|
+
...browser.session,
|
|
232
|
+
close: () => {
|
|
233
|
+
window.removeEventListener('storage', stored);
|
|
234
|
+
document.removeEventListener('visibilitychange', shown);
|
|
235
|
+
window.removeEventListener('online', online);
|
|
236
|
+
browser.session.close();
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=browserSession.js.map
|
|
@@ -0,0 +1 @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type WireAnswer, type WireRequest } from '../wire.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read from the page's own address, with nothing sent. To keep a request across a sign-in, pass
|
|
5
|
+
* the consent page's own path and query as `next` to `requestLink`: Confirm then lands back here
|
|
6
|
+
* and this reads the address again. There is no second mechanism.
|
|
7
|
+
*/
|
|
8
|
+
export type ConsentRequest = {
|
|
9
|
+
readonly kind: 'asking';
|
|
10
|
+
readonly client_id: string;
|
|
11
|
+
/**
|
|
12
|
+
* The host of `redirect_uri`, worked out by the SDK: `URL.host`, so with its port when that
|
|
13
|
+
* isn't the scheme's own (`localhost:5173`). The approval verifies it (AFE-D31). The SDK also
|
|
14
|
+
* refuses an answer whose `redirect_to` doesn't have `redirect_uri`'s origin and path.
|
|
15
|
+
*/
|
|
16
|
+
readonly redirect_host: string;
|
|
17
|
+
readonly scopes: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/** The address holds no authorize request, or one that can't be read. */
|
|
20
|
+
| {
|
|
21
|
+
readonly kind: 'invalid';
|
|
22
|
+
};
|
|
23
|
+
/** The request this session showed, which the page can pass back to approve or deny. */
|
|
24
|
+
export type AskingConsent = Extract<ConsentRequest, {
|
|
25
|
+
readonly kind: 'asking';
|
|
26
|
+
}>;
|
|
27
|
+
/** What can stop an approval or a denial. */
|
|
28
|
+
export type ConsentStop = AsPerson
|
|
29
|
+
/** pulse-auth cannot identify the app, resolve its metadata, or match its registered return address. */
|
|
30
|
+
| {
|
|
31
|
+
readonly kind: 'unknown_client';
|
|
32
|
+
}
|
|
33
|
+
/** A scope this app may not ask for. */
|
|
34
|
+
| {
|
|
35
|
+
readonly kind: 'invalid_scope';
|
|
36
|
+
}
|
|
37
|
+
/** A resource pulse-auth will not issue a token for. */
|
|
38
|
+
| {
|
|
39
|
+
readonly kind: 'invalid_target';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A press is pending or may already have answered this request. Once it settles, the page can try
|
|
43
|
+
* again if nothing was sent, or after a 429, which arrives as `unavailable`, or after
|
|
44
|
+
* `unknown_client`, `invalid_scope` or `invalid_target`.
|
|
45
|
+
* Approval renews once on `login_required`. If its retry never goes out or again gets `login_required`,
|
|
46
|
+
* the request is available again. If a sent press ends as `unavailable`, `signed_out` or `aborted`
|
|
47
|
+
* and may have acted, another press returns `answered`. Reload or sign in again to make a fresh press.
|
|
48
|
+
*/
|
|
49
|
+
| {
|
|
50
|
+
readonly kind: 'answered';
|
|
51
|
+
};
|
|
52
|
+
interface ConsentCalls {
|
|
53
|
+
readonly consentRequest: () => ConsentRequest;
|
|
54
|
+
/** `redirect_to`: where the browser goes next, the app's own return address with its code. */
|
|
55
|
+
readonly approveConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
|
|
56
|
+
readonly redirect_to: string;
|
|
57
|
+
}, ConsentStop>>;
|
|
58
|
+
/** `redirect_to` carries the refusal back to the app. */
|
|
59
|
+
readonly denyConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
|
|
60
|
+
readonly redirect_to: string;
|
|
61
|
+
}, ConsentStop>>;
|
|
62
|
+
}
|
|
63
|
+
interface AuthorizeFields {
|
|
64
|
+
readonly client_id: string;
|
|
65
|
+
readonly redirect_uri: string;
|
|
66
|
+
readonly scope: string;
|
|
67
|
+
readonly state?: string;
|
|
68
|
+
readonly code_challenge?: string;
|
|
69
|
+
readonly code_challenge_method?: string;
|
|
70
|
+
readonly resource?: string;
|
|
71
|
+
}
|
|
72
|
+
type ConsentResult = Awaited<ReturnType<ConsentCalls['approveConsent']>>;
|
|
73
|
+
export declare function readConsentRequest(href: string): ConsentRequest;
|
|
74
|
+
export declare function consentPost(fields: AuthorizeFields, consent: boolean): WireRequest;
|
|
75
|
+
export declare function readConsentAnswer(answer: WireAnswer, fields: AuthorizeFields, consent: boolean): ConsentResult;
|
|
76
|
+
export declare function createConsentCalls(wire: Wire, href: () => string, shownRevision: () => number | 'signed_out' | undefined): ConsentCalls;
|
|
77
|
+
export {};
|