@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,44 @@
|
|
|
1
|
+
import { stopped } from './result.js';
|
|
2
|
+
import { stopListening } from '../core/signal.js';
|
|
3
|
+
/** Each enrollment replaces the pending secret. Keep one attempt for its person or challenge
|
|
4
|
+
* through its answer, even when a screen unmounts and immediately asks again. */
|
|
5
|
+
export function shareEnrollment() {
|
|
6
|
+
let current;
|
|
7
|
+
return (owner, signal, start) => {
|
|
8
|
+
if (signal?.aborted)
|
|
9
|
+
return Promise.resolve(stopped({ kind: 'aborted' }));
|
|
10
|
+
const earlier = current;
|
|
11
|
+
const attempt = earlier?.owner === owner && !earlier.controller.signal.aborted
|
|
12
|
+
? earlier : { owner, sent: false, callers: new Set(), controller: new AbortController() };
|
|
13
|
+
current = attempt;
|
|
14
|
+
const answer = new Promise(resolve => {
|
|
15
|
+
const receive = (result) => {
|
|
16
|
+
stopListening(signal, leave);
|
|
17
|
+
resolve(result);
|
|
18
|
+
};
|
|
19
|
+
const leave = () => {
|
|
20
|
+
attempt.callers.delete(receive);
|
|
21
|
+
if (attempt.callers.size === 0 && !attempt.sent)
|
|
22
|
+
attempt.controller.abort();
|
|
23
|
+
resolve(stopped({ kind: 'aborted' }));
|
|
24
|
+
};
|
|
25
|
+
attempt.callers.add(receive);
|
|
26
|
+
signal?.addEventListener('abort', leave, { once: true });
|
|
27
|
+
});
|
|
28
|
+
if (attempt !== earlier) {
|
|
29
|
+
const result = start(attempt.controller.signal, () => {
|
|
30
|
+
attempt.sent = true;
|
|
31
|
+
});
|
|
32
|
+
const finish = () => {
|
|
33
|
+
if (current === attempt)
|
|
34
|
+
current = undefined;
|
|
35
|
+
for (const receive of attempt.callers)
|
|
36
|
+
receive(result);
|
|
37
|
+
attempt.callers.clear();
|
|
38
|
+
};
|
|
39
|
+
void result.then(finish, finish);
|
|
40
|
+
}
|
|
41
|
+
return answer;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=enrollment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrollment.js","sourceRoot":"","sources":["../../src/first-party/enrollment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAMjD;iFACiF;AACjF,MAAM,UAAU,eAAe;IAO7B,IAAI,OAA4B,CAAA;IAEhC,OAAO,CAAC,KAAY,EAAE,MAA+B,EAAE,KAAe,EAAwB,EAAE;QAC9F,IAAI,MAAM,EAAE,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;QACzE,MAAM,OAAO,GAAG,OAAO,CAAA;QACvB,MAAM,OAAO,GAAY,OAAO,EAAE,KAAK,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO;YACrF,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,eAAe,EAAE,EAAE,CAAA;QAC3F,OAAO,GAAG,OAAO,CAAA;QACjB,MAAM,MAAM,GAAG,IAAI,OAAO,CAAc,OAAO,CAAC,EAAE;YAChD,MAAM,OAAO,GAAG,CAAC,MAAkB,EAAQ,EAAE;gBAC3C,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;gBAC5B,OAAO,CAAC,MAAM,CAAC,CAAA;YACjB,CAAC,CAAA;YACD,MAAM,KAAK,GAAG,GAAS,EAAE;gBACvB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;gBAC/B,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI;oBAAE,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;gBAC3E,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;YACvC,CAAC,CAAA;YACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC5B,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QAC1D,CAAC,CAAC,CAAA;QACF,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;YACxB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;gBACnD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;YACrB,CAAC,CAAC,CAAA;YACF,MAAM,MAAM,GAAG,GAAS,EAAE;gBACxB,IAAI,OAAO,KAAK,OAAO;oBAAE,OAAO,GAAG,SAAS,CAAA;gBAC5C,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,OAAO;oBAAE,OAAO,CAAC,MAAM,CAAC,CAAA;gBACtD,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;YACzB,CAAC,CAAA;YACD,KAAK,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAClC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import type { TwoStepSetup, TwoStepStatus } from './calls/twoStepSetup.js';
|
|
2
|
+
import type { Flipstream, Hosts } from '../flipstream.js';
|
|
3
|
+
import { type BrowserSession as Internal } from './browserSession.js';
|
|
4
|
+
import { type AskingConsent, type ConsentRequest, type ConsentStop } from './calls/consent.js';
|
|
5
|
+
import { type LogInRequest, type LogInStop } from './calls/logIn.js';
|
|
6
|
+
import { type OpenedReset } from './calls/reset.js';
|
|
7
|
+
import { type AcceptInvitation, type Invitation, type OpenedInvitation } from './calls/invitation.js';
|
|
8
|
+
import { type SignInSetup, type SignInStep } from './hooks.js';
|
|
9
|
+
import { type LandedTokens } from './landed.js';
|
|
10
|
+
import { type SignupAttemptDeps } from './links.js';
|
|
11
|
+
import { type SessionReport } from './report.js';
|
|
12
|
+
import { type AsPerson, type CallOptions, type Refused, type Result, type Sent, type ThroughProxy } from './result.js';
|
|
13
|
+
import type { AuthSession } from './session/index.js';
|
|
14
|
+
import { type DeviceAnswerStop, type DeviceRequest, type DeviceStop } from './calls/device.js';
|
|
15
|
+
import type { Wire } from './wire.js';
|
|
16
|
+
/** What is known about the person in this browser, one meaning per kind. */
|
|
17
|
+
export type SessionState =
|
|
18
|
+
/**
|
|
19
|
+
* The first answer isn't in yet: the refresh cookie decides. Once `start()` was called, the
|
|
20
|
+
* session leaves it within 60 s, ordinarily 15: a try waits at most 15 s for pulse-auth, and one
|
|
21
|
+
* whose answer came for a state another tab moved meanwhile is asked again, at most three more
|
|
22
|
+
* times. Its own timed retry after `unavailable` doesn't come back to it; the browser coming back
|
|
23
|
+
* online does: an `unavailable` tab goes to `restoring`, then the answer, within the same bound.
|
|
24
|
+
* A signed-in tab comes back to it when another tab signed in and this one missed the message: it
|
|
25
|
+
* asks the cookie again.
|
|
26
|
+
*/
|
|
27
|
+
{
|
|
28
|
+
readonly kind: 'restoring';
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'signed_out';
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: 'signed_in';
|
|
33
|
+
readonly user_id: string;
|
|
34
|
+
readonly email: string;
|
|
35
|
+
/**
|
|
36
|
+
* Rises each time who is signed in, or what their token says they are (organization,
|
|
37
|
+
* roles), changes, and with each new sign-in. A renewed token that says the same leaves it.
|
|
38
|
+
*/
|
|
39
|
+
readonly revision: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* pulse-auth can't be reached now. The session asks again by itself after `retry_in_ms` and
|
|
43
|
+
* stays `unavailable` while it asks. `retry_in_ms` counts from when the state was published; the
|
|
44
|
+
* ask itself can take up to 15 s, and the tab stays `unavailable` until it answers. The browser
|
|
45
|
+
* coming back online asks at once, through `restoring`.
|
|
46
|
+
*/
|
|
47
|
+
| {
|
|
48
|
+
readonly kind: 'unavailable';
|
|
49
|
+
readonly retry_in_ms: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* pulse-auth answered outside its contract, or the app's own proxy refused: reported.
|
|
53
|
+
* `status` is the answer's. A redirect in a browser reads 0.
|
|
54
|
+
*/
|
|
55
|
+
| {
|
|
56
|
+
readonly kind: 'broken';
|
|
57
|
+
readonly status: number;
|
|
58
|
+
}
|
|
59
|
+
/** This browser lacks what the session needs (Web Locks, localStorage): nobody can sign in. */
|
|
60
|
+
| {
|
|
61
|
+
readonly kind: 'unsupported';
|
|
62
|
+
};
|
|
63
|
+
/** Not a result: read from the address and this browser's attempt, with nothing sent. */
|
|
64
|
+
export type OpenedLink = {
|
|
65
|
+
readonly kind: 'ready';
|
|
66
|
+
readonly email: string;
|
|
67
|
+
readonly purpose: 'sign_in' | 'sign_up';
|
|
68
|
+
/** Where the person was going, as given to `requestLink`. The app checks it against its routes. */
|
|
69
|
+
readonly next: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** This browser already used this link, or asked for it over 10 minutes ago. */
|
|
72
|
+
| {
|
|
73
|
+
readonly kind: 'spent';
|
|
74
|
+
readonly email: string;
|
|
75
|
+
readonly purpose: 'sign_in' | 'sign_up';
|
|
76
|
+
readonly next: string | null;
|
|
77
|
+
}
|
|
78
|
+
/** Asked for in another browser, or not asked for at all. */
|
|
79
|
+
| {
|
|
80
|
+
readonly kind: 'other_browser';
|
|
81
|
+
}
|
|
82
|
+
/** The token's address, the address shown and the attempt's differ. */
|
|
83
|
+
| {
|
|
84
|
+
readonly kind: 'invalid';
|
|
85
|
+
}
|
|
86
|
+
/** No link's token on this page: off the landing, or a reload after the token was taken. */
|
|
87
|
+
| {
|
|
88
|
+
readonly kind: 'no_token';
|
|
89
|
+
}
|
|
90
|
+
/** An invitation's login link: send the person to the invitation page. */
|
|
91
|
+
| {
|
|
92
|
+
readonly kind: 'invitation';
|
|
93
|
+
};
|
|
94
|
+
/** A link `redeem` takes: only one `openedLink()` gave. */
|
|
95
|
+
export type ReadyLink = Extract<OpenedLink, {
|
|
96
|
+
readonly kind: 'ready';
|
|
97
|
+
}>;
|
|
98
|
+
/** A link this browser asked for that no longer works: `requestLinkAgain` sends a new one to its address. */
|
|
99
|
+
export type SpentLink = Extract<OpenedLink, {
|
|
100
|
+
readonly kind: 'spent';
|
|
101
|
+
}>;
|
|
102
|
+
/** Where a redeem stops, short of a sign-in step. */
|
|
103
|
+
export type RedeemStop = ThroughProxy
|
|
104
|
+
/**
|
|
105
|
+
* The link is used up: pulse-auth refused it (expired, or used elsewhere), or its code step ran
|
|
106
|
+
* out or locked. `requestLinkAgain` takes the same link.
|
|
107
|
+
*/
|
|
108
|
+
| {
|
|
109
|
+
readonly kind: 'dead_link';
|
|
110
|
+
} | {
|
|
111
|
+
readonly kind: 'no_account';
|
|
112
|
+
} | {
|
|
113
|
+
readonly kind: 'inactive';
|
|
114
|
+
}
|
|
115
|
+
/** A sign-in or sign-out overtook this press. Read `current()`. If the link was still waiting to be sent, pressing it again sends it, unless the sign-in that overtook it used this link: then `current()` is `signed_in` and the link reads `spent`. If it was sent and the sign-in was lost, every later press in this page keeps `superseded`. Ask for a new link. */
|
|
116
|
+
| {
|
|
117
|
+
readonly kind: 'superseded';
|
|
118
|
+
};
|
|
119
|
+
/** A code's own refusals. */
|
|
120
|
+
export type TwoStepStop = {
|
|
121
|
+
readonly kind: 'wrong_code';
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Too many wrong codes. `until`: epoch ms, the LATEST the lock can end: pulse-auth locks at the
|
|
125
|
+
* fifth wrong code but says so only at the sixth (pulse-auth#126).
|
|
126
|
+
*/
|
|
127
|
+
| {
|
|
128
|
+
readonly kind: 'locked';
|
|
129
|
+
readonly until: number;
|
|
130
|
+
};
|
|
131
|
+
/** What a code's check can stop at. `not_sent` is the caller's signal ending it before the send. */
|
|
132
|
+
export type TwoStepVerifyStop = Exclude<ThroughProxy, {
|
|
133
|
+
readonly kind: 'aborted';
|
|
134
|
+
}> | Refused | TwoStepStop
|
|
135
|
+
/** The code was not sent, so press again. Before 0.15.0 this was `aborted`. */
|
|
136
|
+
| {
|
|
137
|
+
readonly kind: 'not_sent';
|
|
138
|
+
}
|
|
139
|
+
/** The challenge ran out, or none is pending (a reload): start the sign-in again. */
|
|
140
|
+
| {
|
|
141
|
+
readonly kind: 'expired';
|
|
142
|
+
} | {
|
|
143
|
+
readonly kind: 'no_account';
|
|
144
|
+
} | {
|
|
145
|
+
readonly kind: 'inactive';
|
|
146
|
+
}
|
|
147
|
+
/** Issued setup codes are returned only for a signed-out browser or the same confirmed user. */
|
|
148
|
+
| {
|
|
149
|
+
readonly kind: 'superseded';
|
|
150
|
+
readonly backup_codes: readonly string[] | null;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* What pulse-auth said about a sign-out (SDK-D1904). A 200 with no cookie behind it proves
|
|
154
|
+
* nothing (#28 Q3).
|
|
155
|
+
*/
|
|
156
|
+
export type SignOutTold =
|
|
157
|
+
/** pulse-auth ended the session: told by this tab, or by another tab first. */
|
|
158
|
+
{
|
|
159
|
+
readonly kind: 'confirmed';
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Not confirmed: the sign-out stays pending and is sent again when the browser next reaches
|
|
163
|
+
* pulse-auth. `unavailable`: no answer; `refused`: a 401 or 403, which proves nothing about the
|
|
164
|
+
* cookie; `invalid`: an answer outside the contract, reported.
|
|
165
|
+
*/
|
|
166
|
+
| {
|
|
167
|
+
readonly kind: 'unconfirmed';
|
|
168
|
+
readonly reason: 'unavailable' | 'refused' | 'invalid';
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The record moved on since this sign-out: a sign-in, in any tab, or rarely a renewal by a tab
|
|
172
|
+
* that hadn't heard of it. That tab's cookie replaced the old one; it sent this logout first when
|
|
173
|
+
* it knew it was owed, and this call isn't told whether pulse-auth confirmed it. Nothing is
|
|
174
|
+
* pending for this sign-out; a sign-out made since is owed and sent on its own. Read
|
|
175
|
+
* `current()`. Another sign-out with no sign-in between is not `superseded`: this call is told
|
|
176
|
+
* what pulse-auth answered.
|
|
177
|
+
*/
|
|
178
|
+
| {
|
|
179
|
+
readonly kind: 'superseded';
|
|
180
|
+
}
|
|
181
|
+
/** This browser lacks what the session needs: nobody was signed in, nothing was sent. */
|
|
182
|
+
| {
|
|
183
|
+
readonly kind: 'unsupported';
|
|
184
|
+
};
|
|
185
|
+
/** `createBrowserSession`'s options, each checked when the session is made. */
|
|
186
|
+
export interface BrowserSessionOptions {
|
|
187
|
+
/**
|
|
188
|
+
* Which app this is: `{ name, version }`, each 1 to 64 of RFC 9110's token characters, as the
|
|
189
|
+
* main entry's `createFlipstream` takes it. Checked here and sent as Flipstream-Client on main SDK calls to the deployed query host.
|
|
190
|
+
*/
|
|
191
|
+
readonly app: {
|
|
192
|
+
readonly name: string;
|
|
193
|
+
readonly version: string;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* The same-origin path the app's own server forwards to pulse-auth, `/auth` by default: the
|
|
197
|
+
* calls that read or set the session's cookie go there (docs/first-party.md has the contract).
|
|
198
|
+
*/
|
|
199
|
+
readonly authPath?: string;
|
|
200
|
+
/** Where a mailed login link lands: a plain path of this page's origin, such as `/login-link`. */
|
|
201
|
+
readonly landing: string;
|
|
202
|
+
/**
|
|
203
|
+
* Where an invitation's link lands. pulse-auth builds those links on `/invite`, so that is the
|
|
204
|
+
* value that works today. Absent: this app has no invitation page, and no token is ever taken
|
|
205
|
+
* as an invitation's.
|
|
206
|
+
*/
|
|
207
|
+
readonly invitationLanding?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Where a reset link lands. pulse-auth builds those links on `/reset-password`, so that is the
|
|
210
|
+
* value that works today. Absent: this app has no reset page, and no token is ever taken as a
|
|
211
|
+
* reset's.
|
|
212
|
+
*/
|
|
213
|
+
readonly resetLanding?: string;
|
|
214
|
+
/**
|
|
215
|
+
* Every host the main client can use is checked here, including the console for hand-offs.
|
|
216
|
+
* Each must be https, or http on this machine, with no query, fragment or credentials.
|
|
217
|
+
*/
|
|
218
|
+
readonly hosts?: Hosts;
|
|
219
|
+
/**
|
|
220
|
+
* What the app's operator should know: an answer outside the contract, a browser fault, a bug.
|
|
221
|
+
* Never a body, a token or a query. By default printed with `console.warn`; `() => {}`
|
|
222
|
+
* silences it; one that throws is caught.
|
|
223
|
+
*/
|
|
224
|
+
readonly onReport?: (report: SessionReport) => void;
|
|
225
|
+
}
|
|
226
|
+
/** The session and the calls a person signs in and out with. Never a token. */
|
|
227
|
+
export interface BrowserSession {
|
|
228
|
+
/** Reads the authorisation request from this page's current address, including after close(). A callback outside HTTP or HTTPS reads as `invalid`. */
|
|
229
|
+
readonly consentRequest: () => ConsentRequest;
|
|
230
|
+
/**
|
|
231
|
+
* Approves the request this session showed. On success, the app can navigate to `redirect_to`.
|
|
232
|
+
* After the send, `aborted`, `signed_out` or `unavailable` may leave the request approved as the person who pressed.
|
|
233
|
+
* A code may have been issued and a dynamically registered client claimed for that person’s account.
|
|
234
|
+
*/
|
|
235
|
+
readonly approveConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
|
|
236
|
+
readonly redirect_to: string;
|
|
237
|
+
}, ConsentStop>>;
|
|
238
|
+
/**
|
|
239
|
+
* Denies the request this session showed and returns the checked callback carrying the refusal.
|
|
240
|
+
* After the send, `aborted`, `signed_out` or `unavailable` may leave the request denied as the person who pressed.
|
|
241
|
+
*/
|
|
242
|
+
readonly denyConsent: (request: AskingConsent, options?: CallOptions) => Promise<Result<{
|
|
243
|
+
readonly redirect_to: string;
|
|
244
|
+
}, ConsentStop>>;
|
|
245
|
+
/** Reads the signed-in person's two-step settings and remaining backup-code count. */
|
|
246
|
+
readonly twoStepStatus: (options?: CallOptions) => Promise<Result<TwoStepStatus, AsPerson>>;
|
|
247
|
+
/** Starts authenticator enrollment for the signed-in person on the Security page. */
|
|
248
|
+
readonly startTwoStepSetup: (options?: CallOptions) => Promise<Result<TwoStepSetup, AsPerson | {
|
|
249
|
+
readonly kind: 'already_on';
|
|
250
|
+
}>>;
|
|
251
|
+
/** Starts enrollment for the exact setup returned by this session's logIn or redeem. */
|
|
252
|
+
readonly startSignInTwoStepSetup: (setup: SignInSetup, options?: CallOptions) => Promise<Result<TwoStepSetup, Sent | {
|
|
253
|
+
readonly kind: 'expired';
|
|
254
|
+
} | {
|
|
255
|
+
readonly kind: 'superseded';
|
|
256
|
+
}>>;
|
|
257
|
+
/** The first code turns two-step on and gives ten backup codes once. After dispatch, await the answer even if the signal aborts. */
|
|
258
|
+
readonly confirmTwoStepSetup: (entry: {
|
|
259
|
+
readonly code: string;
|
|
260
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
261
|
+
readonly backup_codes: readonly string[];
|
|
262
|
+
}, AsPerson | Refused | TwoStepStop | {
|
|
263
|
+
readonly kind: 'not_started';
|
|
264
|
+
}>>;
|
|
265
|
+
/** A current code replaces the old set. After dispatch, await the answer even if the signal aborts. */
|
|
266
|
+
readonly newBackupCodes: (entry: {
|
|
267
|
+
readonly code: string;
|
|
268
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
269
|
+
readonly backup_codes: readonly string[];
|
|
270
|
+
}, AsPerson | Refused | TwoStepStop | {
|
|
271
|
+
readonly kind: 'not_on';
|
|
272
|
+
}>>;
|
|
273
|
+
/** Turns off two-step for the signed-in person with a current code, when the deployment permits it. */
|
|
274
|
+
readonly turnOffTwoStep: (entry: {
|
|
275
|
+
readonly code: string;
|
|
276
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
277
|
+
readonly kind: 'off';
|
|
278
|
+
}, AsPerson | Refused | TwoStepStop | {
|
|
279
|
+
readonly kind: 'not_on';
|
|
280
|
+
} | {
|
|
281
|
+
readonly kind: 'required';
|
|
282
|
+
}>>;
|
|
283
|
+
/**
|
|
284
|
+
* The main SDK as the person this page shows. Read the getter for each piece of work. A call
|
|
285
|
+
* uses the person displayed when made. With nobody shown, a bearer call answers immediately.
|
|
286
|
+
* A kept client or scope answers `cancelled` after the person or rights change. After close
|
|
287
|
+
* the getter stays readable, and calls on the client reject with SessionClosedError.
|
|
288
|
+
*/
|
|
289
|
+
readonly flipstream: Flipstream;
|
|
290
|
+
/**
|
|
291
|
+
* Requests a sign-up link from pulse-admin. The form supplies the versions of the terms and
|
|
292
|
+
* privacy policy the person accepted. A nonblank version with surrounding whitespace rejects
|
|
293
|
+
* with a TypeError naming the field. The link opens in this browser with purpose
|
|
294
|
+
* `sign_up` and `next: null`. Pulse-admin must allow the page's origin.
|
|
295
|
+
* Aborting after the send answers `aborted`. The organization may already exist and the link may
|
|
296
|
+
* have been mailed. The browser keeps the attempt so that link still works here.
|
|
297
|
+
*/
|
|
298
|
+
readonly requestSignUp: (request: {
|
|
299
|
+
readonly email: string;
|
|
300
|
+
readonly first_name: string;
|
|
301
|
+
readonly last_name: string;
|
|
302
|
+
readonly organization: string;
|
|
303
|
+
readonly accepted: {
|
|
304
|
+
readonly terms_version: string;
|
|
305
|
+
readonly privacy_version: string;
|
|
306
|
+
};
|
|
307
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
308
|
+
readonly email: string;
|
|
309
|
+
}, Sent | Refused |
|
|
310
|
+
/** The browser could not store this attempt. If current() also says unsupported, the browser lacks a session dependency. Otherwise storage refused this write. */
|
|
311
|
+
{
|
|
312
|
+
readonly kind: 'unsupported';
|
|
313
|
+
}>>;
|
|
314
|
+
/**
|
|
315
|
+
* pulse-auth answers the same for a known and an unknown address. The link lands on
|
|
316
|
+
* /reset-password. An abort after the request was sent may still leave the email on its way.
|
|
317
|
+
*/
|
|
318
|
+
readonly requestPasswordReset: (request: {
|
|
319
|
+
readonly email: string;
|
|
320
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
321
|
+
readonly email: string;
|
|
322
|
+
}, Sent | Refused>>;
|
|
323
|
+
/** Reads the reset link on this page, including after close(). Reads `no_token` after `password_set` or `dead_link`. */
|
|
324
|
+
readonly openedReset: () => OpenedReset;
|
|
325
|
+
/**
|
|
326
|
+
* Sets the link owner's password as typed and ends their sessions. An abort after dispatch may
|
|
327
|
+
* leave the password set and the sessions ended. After `password_set` or `dead_link`, openedReset()
|
|
328
|
+
* reads `no_token`. Keep the form's submitted state while waiting. After `unavailable`, the reset
|
|
329
|
+
* may have reached pulse-auth and a retry can answer `dead_link` even though the password was set.
|
|
330
|
+
* In that case, ask the person to try signing in with the new password before requesting a new link.
|
|
331
|
+
* If the link's owner is signed in here and pulse-auth confirms revocation, current() already
|
|
332
|
+
* reads `signed_out` when this call settles. Another person signed in here stays signed in.
|
|
333
|
+
* An abort during the check or a wait of 15 seconds returns the known reset outcome while
|
|
334
|
+
* the check continues.
|
|
335
|
+
*/
|
|
336
|
+
readonly setPassword: (
|
|
337
|
+
/** The types allow other ready links here. The session checks this proof by identity. */
|
|
338
|
+
reset: Extract<OpenedReset, {
|
|
339
|
+
readonly kind: 'ready';
|
|
340
|
+
}>, entry: {
|
|
341
|
+
readonly password: string;
|
|
342
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
343
|
+
readonly kind: 'password_set';
|
|
344
|
+
}, Sent | Refused
|
|
345
|
+
/** Expired, or used before. */
|
|
346
|
+
| {
|
|
347
|
+
readonly kind: 'dead_link';
|
|
348
|
+
}
|
|
349
|
+
/** pulse-auth wants at least 8 characters. */
|
|
350
|
+
| {
|
|
351
|
+
readonly kind: 'password_too_short';
|
|
352
|
+
} | {
|
|
353
|
+
readonly kind: 'inactive';
|
|
354
|
+
}>>;
|
|
355
|
+
/**
|
|
356
|
+
* Signs in with an address and a password (sdk#467): `signed_in`, or a two-step code wanted.
|
|
357
|
+
* Only on a press. Empty fields are `refused`, with nothing sent. A request that is not an
|
|
358
|
+
* object, `null` included, is a TypeError; an array is an object here, so it is `refused` with
|
|
359
|
+
* the fields it lacks. A `signal` that is not an AbortSignal is a TypeError too, nothing sent
|
|
360
|
+
* either way. The same request
|
|
361
|
+
* pressed again while one is under way joins it; a different one is its own attempt. `aborted`:
|
|
362
|
+
* the sign-in may still complete, and `current()` tells; a code asked for once every caller of
|
|
363
|
+
* that request has left is dropped, and the next press asks again.
|
|
364
|
+
*/
|
|
365
|
+
readonly logIn: (request: LogInRequest, options?: CallOptions) => Promise<Result<SignInStep, LogInStop>>;
|
|
366
|
+
/**
|
|
367
|
+
* Whether the page was opened on `invitationLanding` with an invitation's token (sdk#472).
|
|
368
|
+
* Nothing sent; readable after close(). Reads `no_token` once this page is done with the
|
|
369
|
+
* invitation: pulse-auth answered an accept with a 2xx, or the invitation was found dead.
|
|
370
|
+
*/
|
|
371
|
+
readonly openedInvitation: () => OpenedInvitation;
|
|
372
|
+
/**
|
|
373
|
+
* What the invitation is for: `personal` (it names its recipient) or `shared`. An open read,
|
|
374
|
+
* with no cookie and no token; the first one marks the invitation as opened at pulse-auth.
|
|
375
|
+
* `dead_link`: unknown, revoked, expired or spent, and openedInvitation() reads `no_token`.
|
|
376
|
+
*/
|
|
377
|
+
readonly previewInvitation: (
|
|
378
|
+
/** The types allow other ready proofs here. The session checks this proof by identity. */
|
|
379
|
+
opened: Extract<OpenedInvitation, {
|
|
380
|
+
readonly kind: 'ready';
|
|
381
|
+
}>, options?: CallOptions) => Promise<Result<Invitation, Sent | {
|
|
382
|
+
readonly kind: 'dead_link';
|
|
383
|
+
}>>;
|
|
384
|
+
/**
|
|
385
|
+
* Accepting makes the account and signs the person in, as `logIn` does: `signed_in` with
|
|
386
|
+
* `continue_to`, or a two-step code or set-up wanted. Only on a press. Takes the invitation
|
|
387
|
+
* previewInvitation() returned, as it is (a copy is a TypeError), narrowed on its `kind`: a
|
|
388
|
+
* personal one with no address and an optional password, a shared one with both. Empty names,
|
|
389
|
+
* and a shared accept's empty address or password, are `refused`; a privacy policy not
|
|
390
|
+
* accepted is `privacy_policy_required`; nothing is sent then. Once pulse-auth answers the
|
|
391
|
+
* request with a 2xx (an accepted answer, or `superseded` or `invalid` after it), or `dead_link`,
|
|
392
|
+
* openedInvitation() reads `no_token`, also when this caller aborted after the send; while such
|
|
393
|
+
* a request is out, and when it ends otherwise, `ready`. `dead_link` also covers an invitation
|
|
394
|
+
* edited to another address since its link was sent: ask for it to be sent again. After
|
|
395
|
+
* `unavailable`, or an abort after the send that left `ready`, the account may already exist: a
|
|
396
|
+
* later `dead_link` then means "log in", with the password or by a login link. A second press
|
|
397
|
+
* with a different entry while one is out is its own attempt (SDK-D1908), and can find the
|
|
398
|
+
* invitation used (sdk#549). `changed`:
|
|
399
|
+
* preview it again. `superseded`: read `current()`. On `signed_in`, `continue_to` null: send
|
|
400
|
+
* the person to `continue.login_url` when the invitation has a `continue`; otherwise they are
|
|
401
|
+
* signed in here.
|
|
402
|
+
*/
|
|
403
|
+
readonly acceptInvitation: AcceptInvitation;
|
|
404
|
+
/**
|
|
405
|
+
* Looks up a device's code as typed (sdk#471): the request to show the person, or
|
|
406
|
+
* `unknown_code` (unknown, expired or already used; pulse-auth says the same for all three) or `already_denied`.
|
|
407
|
+
* An open read straight to pulse-auth, with no cookie and no token: it changes nothing, so it
|
|
408
|
+
* may run on load, and works whoever is signed in. An empty code is `refused`, with nothing
|
|
409
|
+
* sent. A request that is not an object, or a `signal` that is not an AbortSignal, is a
|
|
410
|
+
* TypeError, nothing sent.
|
|
411
|
+
*/
|
|
412
|
+
readonly lookUpDevice: (request: {
|
|
413
|
+
readonly user_code: string;
|
|
414
|
+
}, options?: CallOptions) => Promise<Result<DeviceRequest, Sent | Refused | DeviceStop>>;
|
|
415
|
+
/**
|
|
416
|
+
* Approves the request `lookUpDevice()` answered on this session, as the signed-in person, only
|
|
417
|
+
* on a press. Any other object, a copy of it or one from another session included, is a
|
|
418
|
+
* TypeError, nothing sent. Nobody signed in, or another person by the time it would be sent:
|
|
419
|
+
* `signed_out`, nothing sent. `unknown_code`: the code is unknown, expired or already used
|
|
420
|
+
* (pulse-auth says the same for all three); a press on it would be sent again, but pulse-auth no
|
|
421
|
+
* longer holds it: ask the device for a new code. `answered`: a press from this page on this code (looked up again included) is still
|
|
422
|
+
* out, or may already have acted on it, for the person signed in now; nothing was sent. Once the
|
|
423
|
+
* first settles, a press is sent again if nothing was sent, or after a 429, which arrives as
|
|
424
|
+
* `unavailable`. After the send, `signed_out`, `aborted`, `invalid` or any other `unavailable`
|
|
425
|
+
* may leave the device answered as the person who pressed: another press answers `answered`, and
|
|
426
|
+
* a fresh look-up doesn't change that. Only signing in again lets a press be sent. An answer that
|
|
427
|
+
* isn't the decision pressed is `invalid` and reported.
|
|
428
|
+
*/
|
|
429
|
+
readonly approveDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
|
|
430
|
+
readonly kind: 'approved';
|
|
431
|
+
}, AsPerson | DeviceAnswerStop>>;
|
|
432
|
+
/** Denies the request `lookUpDevice()` answered on this session, as `approveDevice` approves it. */
|
|
433
|
+
readonly denyDevice: (device: DeviceRequest, options?: CallOptions) => Promise<Result<{
|
|
434
|
+
readonly kind: 'denied';
|
|
435
|
+
}, AsPerson | DeviceAnswerStop>>;
|
|
436
|
+
/** The same object until something changes, so it fits `useSyncExternalStore`. Frozen. */
|
|
437
|
+
readonly current: () => SessionState;
|
|
438
|
+
/**
|
|
439
|
+
* `listener` runs on every change of `current()`. Returns the unsubscribe. The call that
|
|
440
|
+
* published finishes; a listener's throw goes to the page's `error` event through
|
|
441
|
+
* `reportError`, and on a host without one (a server render, Node) it is thrown again from
|
|
442
|
+
* a microtask, which Node raises as an uncaughtException, as its own `EventTarget` does.
|
|
443
|
+
*/
|
|
444
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
445
|
+
/** Once, on page load, after subscribing: the refresh cookie decides. */
|
|
446
|
+
readonly start: () => void;
|
|
447
|
+
/**
|
|
448
|
+
* Ends this session object: its listeners, timers and channel, for tests and hot reloading. A
|
|
449
|
+
* request already sent settles with its real outcome (a sign-in already sent that then loses, to
|
|
450
|
+
* a sign-out in another tab or with an answer that can't be read, is still revoked with a
|
|
451
|
+
* `/logout`), but nothing new is sent: a call still waiting to send answers `unavailable`, and a
|
|
452
|
+
* sign-out whose first try hadn't gone out is told `unconfirmed`, its logout left pending for
|
|
453
|
+
* another tab or the next page load. A call made after it throws, or rejects, with a
|
|
454
|
+
* `SessionClosedError`, `subscribe` and `start` included. The local reads `current`, `consentRequest`,
|
|
455
|
+
* `openedLink`, `openedReset`, `openedInvitation` and the `flipstream` getter stay readable, and a previous unsubscribe stays safe to call. Not a
|
|
456
|
+
* sign-out: the person stays signed in, in every tab.
|
|
457
|
+
*/
|
|
458
|
+
readonly close: () => void;
|
|
459
|
+
/**
|
|
460
|
+
* Stores this browser's attempt, then asks for a login link. `next`: a same-origin path, or
|
|
461
|
+
* null; it comes back on the opened link and never travels in the mail. Anything else, left
|
|
462
|
+
* out or `undefined` included, is a TypeError, with nothing stored or sent: a `next` lost on the
|
|
463
|
+
* way would otherwise mail a link this browser can't redeem. "Send again" is the same call
|
|
464
|
+
* again. `aborted`: the mail may still have gone out.
|
|
465
|
+
*/
|
|
466
|
+
readonly requestLink: (request: {
|
|
467
|
+
readonly email: string;
|
|
468
|
+
readonly next: string | null;
|
|
469
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
470
|
+
readonly email: string;
|
|
471
|
+
}, ThroughProxy | Refused>>;
|
|
472
|
+
/**
|
|
473
|
+
* The login link this page was opened with, checked against this browser's attempt. It only
|
|
474
|
+
* reads: nothing is sent and nothing stored, so it may be called again (React's StrictMode
|
|
475
|
+
* renders twice). Each call answers an equal answer in a new, frozen object, and every object
|
|
476
|
+
* it gave works for `redeem` and `requestLinkAgain`.
|
|
477
|
+
*/
|
|
478
|
+
readonly openedLink: () => OpenedLink;
|
|
479
|
+
/**
|
|
480
|
+
* Signs in with a ready link, checking it again first. Only on a press. Takes only the object
|
|
481
|
+
* `openedLink()` gave, so the check can't be skipped; anything else is a TypeError. `aborted`:
|
|
482
|
+
* the sign-in may still complete, and `current()` tells.
|
|
483
|
+
*/
|
|
484
|
+
readonly redeem: (link: ReadyLink, options?: CallOptions) => Promise<Result<SignInStep, RedeemStop>>;
|
|
485
|
+
/**
|
|
486
|
+
* A new login link to the address of a link this browser asked for, with its `next`. Always a
|
|
487
|
+
* plain login link, also after a sign-up: the account exists by then.
|
|
488
|
+
*/
|
|
489
|
+
readonly requestLinkAgain: (link: ReadyLink | SpentLink, options?: CallOptions) => Promise<Result<{
|
|
490
|
+
readonly email: string;
|
|
491
|
+
}, ThroughProxy>>;
|
|
492
|
+
/**
|
|
493
|
+
* The code the person typed, a backup code (xxxxx-xxxxx) included: pulse-auth tells them apart.
|
|
494
|
+
* `backup_codes`: the ten codes, once, when this sign-in also set two-step up; otherwise null.
|
|
495
|
+
* They exist nowhere else, and the state turns `signed_in` before this call answers, so a
|
|
496
|
+
* screen that leaves on `signed_in` takes this answer first. Once the code is sent, an abort is
|
|
497
|
+
* ignored and the call answers what pulse-auth said. `not_sent`: the code was not sent, so press
|
|
498
|
+
* again. Before 0.15.0, this was `aborted`.
|
|
499
|
+
*/
|
|
500
|
+
readonly verifyTwoStep: (entry: {
|
|
501
|
+
readonly code: string;
|
|
502
|
+
}, options?: CallOptions) => Promise<Result<{
|
|
503
|
+
readonly kind: 'signed_in';
|
|
504
|
+
readonly backup_codes: readonly string[] | null;
|
|
505
|
+
}, TwoStepVerifyStop>>;
|
|
506
|
+
/**
|
|
507
|
+
* Only on a press. Signed out here, in every tab, at once; `told` settles what pulse-auth said.
|
|
508
|
+
* An unconfirmed sign-out stays pending and is sent again when the browser next reaches pulse-auth.
|
|
509
|
+
*/
|
|
510
|
+
readonly signOut: () => {
|
|
511
|
+
readonly told: Promise<SignOutTold>;
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
/** The page's link parameters and its path, read when `openedLink()` is called; null outside a page. */
|
|
515
|
+
export type Address = () => {
|
|
516
|
+
readonly path: string;
|
|
517
|
+
readonly attempt: unknown;
|
|
518
|
+
readonly email: unknown;
|
|
519
|
+
readonly invite: unknown;
|
|
520
|
+
} | null;
|
|
521
|
+
/** What the entry wraps: the session's parts, made by `createBrowserSession` or a test. */
|
|
522
|
+
export interface EntryParts {
|
|
523
|
+
readonly browser: Internal;
|
|
524
|
+
readonly session: AuthSession;
|
|
525
|
+
readonly landed: LandedTokens;
|
|
526
|
+
readonly wire: Wire;
|
|
527
|
+
readonly flipstream: () => Flipstream;
|
|
528
|
+
readonly linkDeps: SignupAttemptDeps;
|
|
529
|
+
readonly report: (report: SessionReport) => void;
|
|
530
|
+
readonly landing: string;
|
|
531
|
+
readonly address: Address;
|
|
532
|
+
readonly href: () => string;
|
|
533
|
+
}
|
|
534
|
+
/** The session's wrapping, for `createBrowserSession` and the tests. */
|
|
535
|
+
export declare function entryOver(parts: EntryParts): BrowserSession;
|
|
536
|
+
/**
|
|
537
|
+
* The browser session, for a page on the app's own origin. Takes the link's token the page's
|
|
538
|
+
* first module took out of the address (`@flipstream/sdk/first-party/link-token`'s `strip`), once:
|
|
539
|
+
* a second session made in the same page load gets no token, so its `openedLink()` says
|
|
540
|
+
* `no_token`. Make one session per page load, and keep it (outside React's render). Every option is checked here, so a wrong one
|
|
541
|
+
* fails when the session is made, not on a person's first click.
|
|
542
|
+
*
|
|
543
|
+
* ```ts
|
|
544
|
+
* const session = createBrowserSession({ app: { name: 'account', version: '1.4.0' }, landing: '/login-link' })
|
|
545
|
+
* session.subscribe(render)
|
|
546
|
+
* session.start()
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
export declare function createBrowserSession(options: BrowserSessionOptions): BrowserSession;
|