@eloxiv/client 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/Account.d.ts +131 -0
- package/dist/Account.d.ts.map +1 -0
- package/dist/Account.js +169 -0
- package/dist/Account.js.map +1 -0
- package/dist/Agent.d.ts +496 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +228 -0
- package/dist/Agent.js.map +1 -0
- package/dist/AgentSync.d.ts +990 -0
- package/dist/AgentSync.d.ts.map +1 -0
- package/dist/AgentSync.js +46 -0
- package/dist/AgentSync.js.map +1 -0
- package/dist/AppState.d.ts +127 -0
- package/dist/AppState.d.ts.map +1 -0
- package/dist/AppState.js +145 -0
- package/dist/AppState.js.map +1 -0
- package/dist/AppStateSync.d.ts +193 -0
- package/dist/AppStateSync.d.ts.map +1 -0
- package/dist/AppStateSync.js +23 -0
- package/dist/AppStateSync.js.map +1 -0
- package/dist/Auth.d.ts +95 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +139 -0
- package/dist/Auth.js.map +1 -0
- package/dist/Avatars.d.ts +53 -0
- package/dist/Avatars.d.ts.map +1 -0
- package/dist/Avatars.js +121 -0
- package/dist/Avatars.js.map +1 -0
- package/dist/BrowserAnalytics.d.ts +56 -0
- package/dist/BrowserAnalytics.d.ts.map +1 -0
- package/dist/BrowserAnalytics.js +94 -0
- package/dist/BrowserAnalytics.js.map +1 -0
- package/dist/Chat.d.ts +712 -0
- package/dist/Chat.d.ts.map +1 -0
- package/dist/Chat.js +883 -0
- package/dist/Chat.js.map +1 -0
- package/dist/ChatIntegrity.d.ts +63 -0
- package/dist/ChatIntegrity.d.ts.map +1 -0
- package/dist/ChatIntegrity.js +89 -0
- package/dist/ChatIntegrity.js.map +1 -0
- package/dist/ChatSends.d.ts +103 -0
- package/dist/ChatSends.d.ts.map +1 -0
- package/dist/ChatSends.js +157 -0
- package/dist/ChatSends.js.map +1 -0
- package/dist/Client.d.ts +113 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +189 -0
- package/dist/Client.js.map +1 -0
- package/dist/Collab.d.ts +138 -0
- package/dist/Collab.d.ts.map +1 -0
- package/dist/Collab.js +454 -0
- package/dist/Collab.js.map +1 -0
- package/dist/CollabTools.d.ts +129 -0
- package/dist/CollabTools.d.ts.map +1 -0
- package/dist/CollabTools.js +277 -0
- package/dist/CollabTools.js.map +1 -0
- package/dist/Connections.d.ts +288 -0
- package/dist/Connections.d.ts.map +1 -0
- package/dist/Connections.js +316 -0
- package/dist/Connections.js.map +1 -0
- package/dist/Consent.d.ts +338 -0
- package/dist/Consent.d.ts.map +1 -0
- package/dist/Consent.js +142 -0
- package/dist/Consent.js.map +1 -0
- package/dist/Desktop.d.ts +61 -0
- package/dist/Desktop.d.ts.map +1 -0
- package/dist/Desktop.js +101 -0
- package/dist/Desktop.js.map +1 -0
- package/dist/Directory.d.ts +36 -0
- package/dist/Directory.d.ts.map +1 -0
- package/dist/Directory.js +42 -0
- package/dist/Directory.js.map +1 -0
- package/dist/ErrorReporter.d.ts +48 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +70 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/ExpoSqlite.d.ts +7 -0
- package/dist/ExpoSqlite.d.ts.map +1 -0
- package/dist/ExpoSqlite.js +7 -0
- package/dist/ExpoSqlite.js.map +1 -0
- package/dist/FileSync.d.ts +265 -0
- package/dist/FileSync.d.ts.map +1 -0
- package/dist/FileSync.js +29 -0
- package/dist/FileSync.js.map +1 -0
- package/dist/FileTables.gen.d.ts +109 -0
- package/dist/FileTables.gen.d.ts.map +1 -0
- package/dist/FileTables.gen.js +23 -0
- package/dist/FileTables.gen.js.map +1 -0
- package/dist/Foldkit.d.ts +487 -0
- package/dist/Foldkit.d.ts.map +1 -0
- package/dist/Foldkit.js +617 -0
- package/dist/Foldkit.js.map +1 -0
- package/dist/History.d.ts +133 -0
- package/dist/History.d.ts.map +1 -0
- package/dist/History.js +210 -0
- package/dist/History.js.map +1 -0
- package/dist/InboxSync.d.ts +428 -0
- package/dist/InboxSync.d.ts.map +1 -0
- package/dist/InboxSync.js +37 -0
- package/dist/InboxSync.js.map +1 -0
- package/dist/KernelTables.gen.d.ts +1522 -0
- package/dist/KernelTables.gen.d.ts.map +1 -0
- package/dist/KernelTables.gen.js +307 -0
- package/dist/KernelTables.gen.js.map +1 -0
- package/dist/Make.d.ts +75 -0
- package/dist/Make.d.ts.map +1 -0
- package/dist/Make.js +70 -0
- package/dist/Make.js.map +1 -0
- package/dist/Models.d.ts +88 -0
- package/dist/Models.d.ts.map +1 -0
- package/dist/Models.js +80 -0
- package/dist/Models.js.map +1 -0
- package/dist/Optimistic.d.ts +120 -0
- package/dist/Optimistic.d.ts.map +1 -0
- package/dist/Optimistic.js +231 -0
- package/dist/Optimistic.js.map +1 -0
- package/dist/PlatformSync.d.ts +273 -0
- package/dist/PlatformSync.d.ts.map +1 -0
- package/dist/PlatformSync.js +92 -0
- package/dist/PlatformSync.js.map +1 -0
- package/dist/Poll.d.ts +113 -0
- package/dist/Poll.d.ts.map +1 -0
- package/dist/Poll.js +179 -0
- package/dist/Poll.js.map +1 -0
- package/dist/Preferences.d.ts +18 -0
- package/dist/Preferences.d.ts.map +1 -0
- package/dist/Preferences.js +22 -0
- package/dist/Preferences.js.map +1 -0
- package/dist/Proposals.d.ts +29 -0
- package/dist/Proposals.d.ts.map +1 -0
- package/dist/Proposals.js +41 -0
- package/dist/Proposals.js.map +1 -0
- package/dist/React.d.ts +17 -0
- package/dist/React.d.ts.map +1 -0
- package/dist/React.js +17 -0
- package/dist/React.js.map +1 -0
- package/dist/Reader.d.ts +35 -0
- package/dist/Reader.d.ts.map +1 -0
- package/dist/Reader.js +136 -0
- package/dist/Reader.js.map +1 -0
- package/dist/Resources.d.ts +98 -0
- package/dist/Resources.d.ts.map +1 -0
- package/dist/Resources.js +161 -0
- package/dist/Resources.js.map +1 -0
- package/dist/Rows.d.ts +4 -0
- package/dist/Rows.d.ts.map +1 -0
- package/dist/Rows.js +16 -0
- package/dist/Rows.js.map +1 -0
- package/dist/Runtime.d.ts +254 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +1249 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/RuntimeRuns.d.ts +74 -0
- package/dist/RuntimeRuns.d.ts.map +1 -0
- package/dist/RuntimeRuns.js +118 -0
- package/dist/RuntimeRuns.js.map +1 -0
- package/dist/ServicesSync.d.ts +286 -0
- package/dist/ServicesSync.d.ts.map +1 -0
- package/dist/ServicesSync.js +40 -0
- package/dist/ServicesSync.js.map +1 -0
- package/dist/Session.d.ts +226 -0
- package/dist/Session.d.ts.map +1 -0
- package/dist/Session.js +763 -0
- package/dist/Session.js.map +1 -0
- package/dist/ShareGrant.d.ts +47 -0
- package/dist/ShareGrant.d.ts.map +1 -0
- package/dist/ShareGrant.js +20 -0
- package/dist/ShareGrant.js.map +1 -0
- package/dist/Sharing.d.ts +203 -0
- package/dist/Sharing.d.ts.map +1 -0
- package/dist/Sharing.js +520 -0
- package/dist/Sharing.js.map +1 -0
- package/dist/Skew.d.ts +52 -0
- package/dist/Skew.d.ts.map +1 -0
- package/dist/Skew.js +77 -0
- package/dist/Skew.js.map +1 -0
- package/dist/SpacesSync.d.ts +247 -0
- package/dist/SpacesSync.d.ts.map +1 -0
- package/dist/SpacesSync.js +30 -0
- package/dist/SpacesSync.js.map +1 -0
- package/dist/Storage.d.ts +51 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +107 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Sync.d.ts +48 -0
- package/dist/Sync.d.ts.map +1 -0
- package/dist/Sync.js +48 -0
- package/dist/Sync.js.map +1 -0
- package/dist/SyncTables.d.ts +13 -0
- package/dist/SyncTables.d.ts.map +1 -0
- package/dist/SyncTables.js +13 -0
- package/dist/SyncTables.js.map +1 -0
- package/dist/Tab.d.ts +36 -0
- package/dist/Tab.d.ts.map +1 -0
- package/dist/Tab.js +44 -0
- package/dist/Tab.js.map +1 -0
- package/dist/Transport.d.ts +139 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +232 -0
- package/dist/Transport.js.map +1 -0
- package/dist/Upload.d.ts +41 -0
- package/dist/Upload.d.ts.map +1 -0
- package/dist/Upload.js +93 -0
- package/dist/Upload.js.map +1 -0
- package/dist/WebMcp.d.ts +78 -0
- package/dist/WebMcp.d.ts.map +1 -0
- package/dist/WebMcp.js +204 -0
- package/dist/WebMcp.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/package.json +97 -3
- package/src/Account.ts +249 -0
- package/src/Agent.ts +387 -0
- package/src/AgentSync.ts +59 -0
- package/src/AppState.ts +222 -0
- package/src/AppStateSync.ts +26 -0
- package/src/Auth.ts +225 -0
- package/src/Avatars.ts +144 -0
- package/src/BrowserAnalytics.ts +133 -0
- package/src/Chat.ts +1150 -0
- package/src/ChatIntegrity.ts +130 -0
- package/src/ChatSends.ts +209 -0
- package/src/Client.ts +319 -0
- package/src/Collab.ts +524 -0
- package/src/CollabTools.ts +381 -0
- package/src/Connections.ts +517 -0
- package/src/Consent.ts +176 -0
- package/src/Desktop.ts +139 -0
- package/src/Directory.ts +71 -0
- package/src/ErrorReporter.ts +112 -0
- package/src/ExpoSqlite.ts +6 -0
- package/src/FileSync.ts +34 -0
- package/src/FileTables.gen.ts +23 -0
- package/src/Foldkit.ts +960 -0
- package/src/History.ts +337 -0
- package/src/InboxSync.ts +47 -0
- package/src/KernelTables.gen.ts +329 -0
- package/src/Make.ts +120 -0
- package/src/Models.ts +134 -0
- package/src/Optimistic.ts +364 -0
- package/src/PlatformSync.ts +156 -0
- package/src/Poll.ts +227 -0
- package/src/Preferences.ts +42 -0
- package/src/Proposals.ts +57 -0
- package/src/React.ts +26 -0
- package/src/Reader.ts +180 -0
- package/src/Resources.ts +257 -0
- package/src/Rows.ts +16 -0
- package/src/Runtime.ts +1409 -0
- package/src/RuntimeRuns.ts +180 -0
- package/src/ServicesSync.ts +58 -0
- package/src/Session.ts +814 -0
- package/src/ShareGrant.ts +20 -0
- package/src/Sharing.ts +696 -0
- package/src/Skew.ts +97 -0
- package/src/SpacesSync.ts +61 -0
- package/src/Storage.ts +167 -0
- package/src/Sync.ts +125 -0
- package/src/SyncTables.ts +12 -0
- package/src/Tab.ts +59 -0
- package/src/Transport.ts +321 -0
- package/src/Upload.ts +125 -0
- package/src/WebMcp.ts +279 -0
- package/src/index.ts +26 -0
- package/src/web-globals.d.ts +103 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in session, headless: one controller per app (or per window) that every view shares, so the page has
|
|
3
|
+
* one verified read of who is signed in, one sign-out, and one place that hears a session ended. Framework-free: a
|
|
4
|
+
* Foldkit program subscribes to it with a Subscription, any other UI with `subscribe`.
|
|
5
|
+
*
|
|
6
|
+
* States: `loading` (the stored session not checked yet), `authenticated` (checked with the kernel, `token` and
|
|
7
|
+
* `account`), `unauthenticated`, `unavailable` (the kernel could not be reached to check it: the stored session is
|
|
8
|
+
* kept, and `refresh` checks again; the client core may open the replica its store remembers for it meanwhile,
|
|
9
|
+
* `SessionStore.recall`), `signing-out`.
|
|
10
|
+
*
|
|
11
|
+
* Guarantees:
|
|
12
|
+
* - **One verified read.** `start`, `refresh` and `invalidate` share one check in flight; a stored token is never
|
|
13
|
+
* reported `authenticated` before the kernel accepted it.
|
|
14
|
+
* - **A session is stored only once adopted.** `adopt` (and the sign-ins through it) checks the account before it
|
|
15
|
+
* stores the token; an adoption overtaken by a sign-out or another adoption, or whose check fails, stores
|
|
16
|
+
* nothing and revokes the session it was given, unless something else holds that token: the current or the
|
|
17
|
+
* stored session, or another adoption of it still running or accepted.
|
|
18
|
+
* - **One writer at a time.** A check's answer, an adoption's acceptance or cleanup and a sign-out's end change
|
|
19
|
+
* the store and the state one at a time, in order; a check that began before a session was adopted or a
|
|
20
|
+
* sign-out began changes neither (it cannot restore the previous session or forget the new one), and a session
|
|
21
|
+
* is forgotten only while the store still holds it (`SessionStore.clearIf`).
|
|
22
|
+
* - **A session the kernel refuses is forgotten.** A 401 (on the check, or one the client core heard elsewhere:
|
|
23
|
+
* `refuse`) reports `unauthenticated` first, so the views close before any storage is touched, and then clears
|
|
24
|
+
* the store in the background, retried until it succeeds (its remembered context forgotten meanwhile). The refused
|
|
25
|
+
* token is remembered in memory for the store it came from, so no later check in this process reports it or lets
|
|
26
|
+
* it be reopened offline, even while the store still holds it. A network failure or a 5xx retries with backoff
|
|
27
|
+
* and then reports `unavailable`, keeping it. The first check of a token with a remembered context makes one
|
|
28
|
+
* attempt within `offlineProbeMs`, so an offline start is not held up by a stalled connection; a late refusal is
|
|
29
|
+
* applied at once (a newer check still in flight cannot replace it), a late acceptance is checked again.
|
|
30
|
+
* - **Sign-out stops reads first.** `signOut` reports `signing-out` and `token()` returns nothing before the
|
|
31
|
+
* revocation is sent, so no view issues another authenticated read; the stored session is kept until the kernel
|
|
32
|
+
* confirms the revocation (retried with backoff), then cleared. The token it revokes is refused to an adoption
|
|
33
|
+
* from before the revocation is sent (a changed password's unrotated token), so no revoked session is reported.
|
|
34
|
+
* - **A durable sign-out survives the page** (with `revocations`, a browser's storage). The revocation is kept in
|
|
35
|
+
* that store (read back) and the stored session forgotten before the person is reported `unauthenticated`, so an
|
|
36
|
+
* interruption at any instant after the signed-out state shows (a reload, a closed tab) finds the revocation, never
|
|
37
|
+
* the session. When the store will not keep it, the token stays in memory, the stored session stays (a reload finds
|
|
38
|
+
* a session the kernel still accepts, never a token nobody holds) with its remembered context forgotten, so an
|
|
39
|
+
* offline restart reopens nothing (`SignOutNotSaved` when that cannot be saved either), and a sign-in or adoption
|
|
40
|
+
* is refused
|
|
41
|
+
* (`UnsavedSignOut`) until the revocation is stored or confirmed. Pending revocations are retried
|
|
42
|
+
* (`retryRevocations`, each attempt with a timeout) and leave the store only when the kernel confirms them (revoked
|
|
43
|
+
* now, or refused already: 401) and the session's slot or its remembered context is gone (cleared first, retried
|
|
44
|
+
* while it fails); `revocationStatus` says where the last sign-out stands. A stored session whose token is pending
|
|
45
|
+
* there (its slot survived the sign-out) is never checked or reported, and its slot is forgotten. A slot that
|
|
46
|
+
* cannot be read at sign-out is a failure (`SignOutNotSaved`), never "nobody signed in", unless the caller knows
|
|
47
|
+
* the token (an offline start's); a sign-out that failed keeps its token, so trying again revokes the same one.
|
|
48
|
+
*/
|
|
49
|
+
import { verifyTwoFactor, type Account } from "./Account.ts";
|
|
50
|
+
import { type Session } from "./Auth.ts";
|
|
51
|
+
export type SessionState = {
|
|
52
|
+
readonly status: "loading";
|
|
53
|
+
} | {
|
|
54
|
+
readonly status: "authenticated";
|
|
55
|
+
readonly token: string;
|
|
56
|
+
readonly account: Account;
|
|
57
|
+
} | {
|
|
58
|
+
readonly status: "unauthenticated";
|
|
59
|
+
} | {
|
|
60
|
+
readonly status: "unavailable";
|
|
61
|
+
readonly reason: string;
|
|
62
|
+
} | {
|
|
63
|
+
readonly status: "signing-out";
|
|
64
|
+
readonly error?: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
/** Where the session's token is kept between launches (secure storage, the browser's storage, memory). */
|
|
67
|
+
export interface SessionStore {
|
|
68
|
+
readonly load: () => Promise<string | undefined>;
|
|
69
|
+
/** Keep `token`; `account` is the account the kernel answered for it (a store may keep it beside the token). */
|
|
70
|
+
readonly save: (token: string, account?: Account) => Promise<void>;
|
|
71
|
+
readonly clear: () => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Clear the stored token only while it is `token`, atomically with the store's other writes (optional). The
|
|
74
|
+
* controller forgets a session this way, so a token another writer of the same store saved meanwhile (another
|
|
75
|
+
* window's controller) is kept. Without it the controller loads, compares and clears: atomic with its own writes,
|
|
76
|
+
* which it runs one at a time, but not with another writer's.
|
|
77
|
+
*/
|
|
78
|
+
readonly clearIf?: (token: string) => Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* The context last open with `token` (optional, with `remember`): the person and the organisation whose replica the
|
|
81
|
+
* client core opens when it starts while the kernel cannot be reached to check the stored session (an offline
|
|
82
|
+
* start). Answers only for the token it was kept with; a store forgets it with that token (`clear`, `clearIf`).
|
|
83
|
+
*/
|
|
84
|
+
readonly recall?: (token: string) => Promise<RememberedContext | undefined>;
|
|
85
|
+
/** Keep the context now open with `token`, replacing the one kept before (optional, with `recall`). */
|
|
86
|
+
readonly remember?: (token: string, context: RememberedContext) => Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Forget the context remembered with `token`, keeping the session (optional, with `recall`): nothing is recalled
|
|
89
|
+
* for it again until a context is remembered anew. The client core calls it when the kernel's listing leaves the
|
|
90
|
+
* person in no organisation or without the remembered one, and when a sign-out's revocation could not be kept.
|
|
91
|
+
*/
|
|
92
|
+
readonly forgetContext?: (token: string) => Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/** The person and organisation a session's replica was last open for (`SessionStore.recall`): never a credential. */
|
|
95
|
+
export interface RememberedContext {
|
|
96
|
+
readonly user: {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly email: string;
|
|
99
|
+
readonly name: string;
|
|
100
|
+
};
|
|
101
|
+
readonly organization: {
|
|
102
|
+
readonly orgId: string;
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly roles: ReadonlyArray<string>;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** A store in memory only (nothing survives a reload). */
|
|
108
|
+
export declare const memorySessionStore: () => SessionStore;
|
|
109
|
+
/**
|
|
110
|
+
* Where the revocations the kernel has not confirmed yet are kept between launches (a durable sign-out): appended
|
|
111
|
+
* to, and an entry leaves only when the kernel confirms it. Never rewritten by a sign-in or a session write.
|
|
112
|
+
*/
|
|
113
|
+
export interface RevocationStore {
|
|
114
|
+
readonly load: () => Promise<ReadonlyArray<string>>;
|
|
115
|
+
/** Keep `token` among them: resolves whether the store holds it now (read back, not assumed). */
|
|
116
|
+
readonly keep: (token: string) => Promise<boolean>;
|
|
117
|
+
/** The kernel confirmed `token`'s revocation: it leaves the store. */
|
|
118
|
+
readonly drop: (token: string) => Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
/** Where the last sign-out's revocation stands: none, being sent, unconfirmed (and retried), or confirmed. */
|
|
121
|
+
export type RevocationStatus = "none" | "revoking" | "pending" | "confirmed";
|
|
122
|
+
/** A sign-in refused while a sign-out's revocation exists only in memory (the revocation store would not keep it). */
|
|
123
|
+
export declare class UnsavedSignOut extends Error {
|
|
124
|
+
readonly name = "UnsavedSignOut";
|
|
125
|
+
constructor();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A sign-out that could not be saved on this device (a durable sign-out whose revocation the store would not keep, and
|
|
129
|
+
* whose remembered context could not be forgotten either): the session stays signed out of in memory and its
|
|
130
|
+
* revocation is retried, but a restart could find it. The person should try signing out again.
|
|
131
|
+
*/
|
|
132
|
+
export declare class SignOutNotSaved extends Error {
|
|
133
|
+
readonly name = "SignOutNotSaved";
|
|
134
|
+
constructor();
|
|
135
|
+
}
|
|
136
|
+
export interface SessionControllerOptions {
|
|
137
|
+
readonly baseUrl: string;
|
|
138
|
+
readonly store: SessionStore;
|
|
139
|
+
/** Attempts of a check or a revocation before it gives up (default 4), and the first backoff (default 250 ms). */
|
|
140
|
+
readonly retry?: {
|
|
141
|
+
readonly attempts?: number;
|
|
142
|
+
readonly baseMs?: number;
|
|
143
|
+
} | undefined;
|
|
144
|
+
/** A durable sign-out: pending revocations kept here (a browser's storage) and retried until confirmed. */
|
|
145
|
+
readonly revocations?: RevocationStore | undefined;
|
|
146
|
+
/** How long one attempt of a durable revocation waits for the kernel before it counts as unanswered (10 s). */
|
|
147
|
+
readonly revocationTimeoutMs?: number | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* How long the first check of a stored session with a remembered context (`SessionStore.recall`) waits for the
|
|
150
|
+
* kernel before it reports `unavailable` (3 s), so a stalled connection does not hold up an offline start; the
|
|
151
|
+
* check goes on in the background, and a refusal it then hears is acted on at once.
|
|
152
|
+
*/
|
|
153
|
+
readonly offlineProbeMs?: number | undefined;
|
|
154
|
+
}
|
|
155
|
+
export declare const sessionController: (options: SessionControllerOptions) => {
|
|
156
|
+
state: () => SessionState;
|
|
157
|
+
/** The token to make authenticated calls with: only while `authenticated`. */
|
|
158
|
+
token: () => string | undefined;
|
|
159
|
+
subscribe: (listener: (state: SessionState) => void) => (() => void);
|
|
160
|
+
/** Check the stored session (once at launch). */
|
|
161
|
+
start: () => Promise<SessionState>;
|
|
162
|
+
/** Check it again (after `unavailable`, or when the app regains focus). */
|
|
163
|
+
refresh: () => Promise<SessionState>;
|
|
164
|
+
/** A call was refused with 401: check the session again (calls made together share the check). */
|
|
165
|
+
invalidate: () => Promise<SessionState>;
|
|
166
|
+
/**
|
|
167
|
+
* Sign in with a password; rejects with `TwoFactorRequired` when a second factor is needed, and (a durable
|
|
168
|
+
* sign-out) with `UnsavedSignOut`, before asking the kernel, while a revocation only memory holds is left.
|
|
169
|
+
*/
|
|
170
|
+
signIn: (credentials: {
|
|
171
|
+
readonly email: string;
|
|
172
|
+
readonly password: string;
|
|
173
|
+
}, guard?: {
|
|
174
|
+
readonly current: () => boolean;
|
|
175
|
+
}) => Promise<boolean>;
|
|
176
|
+
/** Finish a sign-in `TwoFactorRequired` interrupted. */
|
|
177
|
+
completeTwoFactor: (input: Parameters<typeof verifyTwoFactor>[1], guard?: {
|
|
178
|
+
readonly current: () => boolean;
|
|
179
|
+
}) => Promise<boolean>;
|
|
180
|
+
/**
|
|
181
|
+
* Adopt a session obtained otherwise (a sign-up, a changed password's new token, a desktop sign-in): `false` when
|
|
182
|
+
* it was overtaken (then revoked, nothing stored); `guard.current` lets the caller abandon it while it is checked.
|
|
183
|
+
*/
|
|
184
|
+
adopt: (session: Session, guard?: {
|
|
185
|
+
readonly current: () => boolean;
|
|
186
|
+
}) => Promise<boolean>;
|
|
187
|
+
/**
|
|
188
|
+
* Sign out: reads stop at once (`signing-out`; checks answer the state without reading until it ends), then the
|
|
189
|
+
* revocation is sent and retried; the revoked session is forgotten from the store only once the kernel confirms
|
|
190
|
+
* it. Rejects (staying `signing-out`, the session kept) when it could not be confirmed; call it again. A session
|
|
191
|
+
* adopted after it began is kept, unless it is the session being revoked: that adoption resolves `false`.
|
|
192
|
+
* `known`: the token of a session the caller holds without a check (an offline start), so a slot that cannot be
|
|
193
|
+
* read does not lose it.
|
|
194
|
+
*/
|
|
195
|
+
signOut: (known?: string) => Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* The kernel refused `token` with 401 on another call (the client core's organisation listing): while it is the
|
|
198
|
+
* checked session, it is torn down as a refused check's would be (published first, the store cleaned up after).
|
|
199
|
+
*/
|
|
200
|
+
refuse: (token: string) => Promise<boolean>;
|
|
201
|
+
/** Whether the kernel refused `token` in this process (it is never reopened, even offline). */
|
|
202
|
+
isRefused: (token: string) => boolean;
|
|
203
|
+
/** Stop the background cleanup's retries (the client stopped). */
|
|
204
|
+
dispose: () => void;
|
|
205
|
+
/** Where the last durable sign-out's revocation stands (always `none` without `revocations`). */
|
|
206
|
+
revocationStatus: () => RevocationStatus;
|
|
207
|
+
subscribeRevocation: (listener: (status: RevocationStatus) => void) => (() => void);
|
|
208
|
+
/**
|
|
209
|
+
* Try every pending revocation once more (at start, on a timer, when the network returns): `revoked` when the
|
|
210
|
+
* kernel confirmed one, `stillPending` while any is left. Calls made together share one round.
|
|
211
|
+
*/
|
|
212
|
+
retryRevocations: () => Promise<{
|
|
213
|
+
readonly revoked: boolean;
|
|
214
|
+
readonly stillPending: boolean;
|
|
215
|
+
}>;
|
|
216
|
+
};
|
|
217
|
+
export type SessionController = ReturnType<typeof sessionController>;
|
|
218
|
+
/**
|
|
219
|
+
* A return path that is safe to send a person to after sign-in: a path on `origin` itself (`/inbox?x=1#y`), or
|
|
220
|
+
* `fallback` (default `/`) for anything else: another origin, a scheme (`javascript:`), a protocol-relative or
|
|
221
|
+
* backslashed path (`//evil.example`, `/\evil.example`), or what does not parse.
|
|
222
|
+
*/
|
|
223
|
+
export declare const safeReturnPath: (candidate: string | null | undefined, origin: string, fallback?: string) => string;
|
|
224
|
+
/** The sign-in page's path with where to return afterwards (`?returnTo=`), only when that is safe. */
|
|
225
|
+
export declare const signInPath: (signIn: string, returnTo: string | null | undefined, origin: string) => string;
|
|
226
|
+
//# sourceMappingURL=Session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../src/Session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,OAAO,EAAc,eAAe,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AACxE,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,WAAW,CAAA;AAEpE,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,GAC9B;IAAE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GACvF;IAAE,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,GACtC;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAE3E,0GAA0G;AAC1G,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,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