@eloxiv/client 0.0.0-stage → 0.1.1

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.
Files changed (269) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Account.d.ts +131 -0
  4. package/dist/Account.d.ts.map +1 -0
  5. package/dist/Account.js +169 -0
  6. package/dist/Account.js.map +1 -0
  7. package/dist/Agent.d.ts +496 -0
  8. package/dist/Agent.d.ts.map +1 -0
  9. package/dist/Agent.js +228 -0
  10. package/dist/Agent.js.map +1 -0
  11. package/dist/AgentSync.d.ts +990 -0
  12. package/dist/AgentSync.d.ts.map +1 -0
  13. package/dist/AgentSync.js +46 -0
  14. package/dist/AgentSync.js.map +1 -0
  15. package/dist/AppState.d.ts +127 -0
  16. package/dist/AppState.d.ts.map +1 -0
  17. package/dist/AppState.js +145 -0
  18. package/dist/AppState.js.map +1 -0
  19. package/dist/AppStateSync.d.ts +193 -0
  20. package/dist/AppStateSync.d.ts.map +1 -0
  21. package/dist/AppStateSync.js +23 -0
  22. package/dist/AppStateSync.js.map +1 -0
  23. package/dist/Auth.d.ts +95 -0
  24. package/dist/Auth.d.ts.map +1 -0
  25. package/dist/Auth.js +139 -0
  26. package/dist/Auth.js.map +1 -0
  27. package/dist/Avatars.d.ts +53 -0
  28. package/dist/Avatars.d.ts.map +1 -0
  29. package/dist/Avatars.js +121 -0
  30. package/dist/Avatars.js.map +1 -0
  31. package/dist/BrowserAnalytics.d.ts +56 -0
  32. package/dist/BrowserAnalytics.d.ts.map +1 -0
  33. package/dist/BrowserAnalytics.js +94 -0
  34. package/dist/BrowserAnalytics.js.map +1 -0
  35. package/dist/Chat.d.ts +712 -0
  36. package/dist/Chat.d.ts.map +1 -0
  37. package/dist/Chat.js +883 -0
  38. package/dist/Chat.js.map +1 -0
  39. package/dist/ChatIntegrity.d.ts +63 -0
  40. package/dist/ChatIntegrity.d.ts.map +1 -0
  41. package/dist/ChatIntegrity.js +89 -0
  42. package/dist/ChatIntegrity.js.map +1 -0
  43. package/dist/ChatSends.d.ts +103 -0
  44. package/dist/ChatSends.d.ts.map +1 -0
  45. package/dist/ChatSends.js +157 -0
  46. package/dist/ChatSends.js.map +1 -0
  47. package/dist/Client.d.ts +113 -0
  48. package/dist/Client.d.ts.map +1 -0
  49. package/dist/Client.js +189 -0
  50. package/dist/Client.js.map +1 -0
  51. package/dist/Collab.d.ts +138 -0
  52. package/dist/Collab.d.ts.map +1 -0
  53. package/dist/Collab.js +454 -0
  54. package/dist/Collab.js.map +1 -0
  55. package/dist/CollabTools.d.ts +129 -0
  56. package/dist/CollabTools.d.ts.map +1 -0
  57. package/dist/CollabTools.js +277 -0
  58. package/dist/CollabTools.js.map +1 -0
  59. package/dist/Connections.d.ts +288 -0
  60. package/dist/Connections.d.ts.map +1 -0
  61. package/dist/Connections.js +316 -0
  62. package/dist/Connections.js.map +1 -0
  63. package/dist/Consent.d.ts +338 -0
  64. package/dist/Consent.d.ts.map +1 -0
  65. package/dist/Consent.js +142 -0
  66. package/dist/Consent.js.map +1 -0
  67. package/dist/Desktop.d.ts +61 -0
  68. package/dist/Desktop.d.ts.map +1 -0
  69. package/dist/Desktop.js +101 -0
  70. package/dist/Desktop.js.map +1 -0
  71. package/dist/Directory.d.ts +36 -0
  72. package/dist/Directory.d.ts.map +1 -0
  73. package/dist/Directory.js +42 -0
  74. package/dist/Directory.js.map +1 -0
  75. package/dist/ErrorReporter.d.ts +48 -0
  76. package/dist/ErrorReporter.d.ts.map +1 -0
  77. package/dist/ErrorReporter.js +70 -0
  78. package/dist/ErrorReporter.js.map +1 -0
  79. package/dist/ExpoSqlite.d.ts +7 -0
  80. package/dist/ExpoSqlite.d.ts.map +1 -0
  81. package/dist/ExpoSqlite.js +7 -0
  82. package/dist/ExpoSqlite.js.map +1 -0
  83. package/dist/FileSync.d.ts +265 -0
  84. package/dist/FileSync.d.ts.map +1 -0
  85. package/dist/FileSync.js +29 -0
  86. package/dist/FileSync.js.map +1 -0
  87. package/dist/FileTables.gen.d.ts +109 -0
  88. package/dist/FileTables.gen.d.ts.map +1 -0
  89. package/dist/FileTables.gen.js +23 -0
  90. package/dist/FileTables.gen.js.map +1 -0
  91. package/dist/Foldkit.d.ts +487 -0
  92. package/dist/Foldkit.d.ts.map +1 -0
  93. package/dist/Foldkit.js +617 -0
  94. package/dist/Foldkit.js.map +1 -0
  95. package/dist/History.d.ts +133 -0
  96. package/dist/History.d.ts.map +1 -0
  97. package/dist/History.js +210 -0
  98. package/dist/History.js.map +1 -0
  99. package/dist/InboxSync.d.ts +428 -0
  100. package/dist/InboxSync.d.ts.map +1 -0
  101. package/dist/InboxSync.js +37 -0
  102. package/dist/InboxSync.js.map +1 -0
  103. package/dist/KernelTables.gen.d.ts +1522 -0
  104. package/dist/KernelTables.gen.d.ts.map +1 -0
  105. package/dist/KernelTables.gen.js +307 -0
  106. package/dist/KernelTables.gen.js.map +1 -0
  107. package/dist/Make.d.ts +75 -0
  108. package/dist/Make.d.ts.map +1 -0
  109. package/dist/Make.js +70 -0
  110. package/dist/Make.js.map +1 -0
  111. package/dist/Models.d.ts +88 -0
  112. package/dist/Models.d.ts.map +1 -0
  113. package/dist/Models.js +80 -0
  114. package/dist/Models.js.map +1 -0
  115. package/dist/Optimistic.d.ts +120 -0
  116. package/dist/Optimistic.d.ts.map +1 -0
  117. package/dist/Optimistic.js +231 -0
  118. package/dist/Optimistic.js.map +1 -0
  119. package/dist/PlatformSync.d.ts +273 -0
  120. package/dist/PlatformSync.d.ts.map +1 -0
  121. package/dist/PlatformSync.js +92 -0
  122. package/dist/PlatformSync.js.map +1 -0
  123. package/dist/Poll.d.ts +113 -0
  124. package/dist/Poll.d.ts.map +1 -0
  125. package/dist/Poll.js +179 -0
  126. package/dist/Poll.js.map +1 -0
  127. package/dist/Preferences.d.ts +18 -0
  128. package/dist/Preferences.d.ts.map +1 -0
  129. package/dist/Preferences.js +22 -0
  130. package/dist/Preferences.js.map +1 -0
  131. package/dist/Proposals.d.ts +29 -0
  132. package/dist/Proposals.d.ts.map +1 -0
  133. package/dist/Proposals.js +41 -0
  134. package/dist/Proposals.js.map +1 -0
  135. package/dist/React.d.ts +17 -0
  136. package/dist/React.d.ts.map +1 -0
  137. package/dist/React.js +17 -0
  138. package/dist/React.js.map +1 -0
  139. package/dist/Reader.d.ts +35 -0
  140. package/dist/Reader.d.ts.map +1 -0
  141. package/dist/Reader.js +136 -0
  142. package/dist/Reader.js.map +1 -0
  143. package/dist/Resources.d.ts +98 -0
  144. package/dist/Resources.d.ts.map +1 -0
  145. package/dist/Resources.js +161 -0
  146. package/dist/Resources.js.map +1 -0
  147. package/dist/Rows.d.ts +4 -0
  148. package/dist/Rows.d.ts.map +1 -0
  149. package/dist/Rows.js +16 -0
  150. package/dist/Rows.js.map +1 -0
  151. package/dist/Runtime.d.ts +254 -0
  152. package/dist/Runtime.d.ts.map +1 -0
  153. package/dist/Runtime.js +1283 -0
  154. package/dist/Runtime.js.map +1 -0
  155. package/dist/RuntimeRuns.d.ts +74 -0
  156. package/dist/RuntimeRuns.d.ts.map +1 -0
  157. package/dist/RuntimeRuns.js +118 -0
  158. package/dist/RuntimeRuns.js.map +1 -0
  159. package/dist/ServicesSync.d.ts +286 -0
  160. package/dist/ServicesSync.d.ts.map +1 -0
  161. package/dist/ServicesSync.js +40 -0
  162. package/dist/ServicesSync.js.map +1 -0
  163. package/dist/Session.d.ts +228 -0
  164. package/dist/Session.d.ts.map +1 -0
  165. package/dist/Session.js +792 -0
  166. package/dist/Session.js.map +1 -0
  167. package/dist/ShareGrant.d.ts +47 -0
  168. package/dist/ShareGrant.d.ts.map +1 -0
  169. package/dist/ShareGrant.js +20 -0
  170. package/dist/ShareGrant.js.map +1 -0
  171. package/dist/Sharing.d.ts +203 -0
  172. package/dist/Sharing.d.ts.map +1 -0
  173. package/dist/Sharing.js +520 -0
  174. package/dist/Sharing.js.map +1 -0
  175. package/dist/Skew.d.ts +52 -0
  176. package/dist/Skew.d.ts.map +1 -0
  177. package/dist/Skew.js +77 -0
  178. package/dist/Skew.js.map +1 -0
  179. package/dist/SpacesSync.d.ts +247 -0
  180. package/dist/SpacesSync.d.ts.map +1 -0
  181. package/dist/SpacesSync.js +30 -0
  182. package/dist/SpacesSync.js.map +1 -0
  183. package/dist/Storage.d.ts +51 -0
  184. package/dist/Storage.d.ts.map +1 -0
  185. package/dist/Storage.js +107 -0
  186. package/dist/Storage.js.map +1 -0
  187. package/dist/Sync.d.ts +48 -0
  188. package/dist/Sync.d.ts.map +1 -0
  189. package/dist/Sync.js +48 -0
  190. package/dist/Sync.js.map +1 -0
  191. package/dist/SyncTables.d.ts +13 -0
  192. package/dist/SyncTables.d.ts.map +1 -0
  193. package/dist/SyncTables.js +13 -0
  194. package/dist/SyncTables.js.map +1 -0
  195. package/dist/Tab.d.ts +36 -0
  196. package/dist/Tab.d.ts.map +1 -0
  197. package/dist/Tab.js +44 -0
  198. package/dist/Tab.js.map +1 -0
  199. package/dist/Transport.d.ts +139 -0
  200. package/dist/Transport.d.ts.map +1 -0
  201. package/dist/Transport.js +232 -0
  202. package/dist/Transport.js.map +1 -0
  203. package/dist/Upload.d.ts +41 -0
  204. package/dist/Upload.d.ts.map +1 -0
  205. package/dist/Upload.js +93 -0
  206. package/dist/Upload.js.map +1 -0
  207. package/dist/WebMcp.d.ts +78 -0
  208. package/dist/WebMcp.d.ts.map +1 -0
  209. package/dist/WebMcp.js +204 -0
  210. package/dist/WebMcp.js.map +1 -0
  211. package/dist/index.d.ts +27 -0
  212. package/dist/index.d.ts.map +1 -0
  213. package/dist/index.js +27 -0
  214. package/dist/index.js.map +1 -0
  215. package/package.json +97 -3
  216. package/src/Account.ts +249 -0
  217. package/src/Agent.ts +387 -0
  218. package/src/AgentSync.ts +59 -0
  219. package/src/AppState.ts +222 -0
  220. package/src/AppStateSync.ts +26 -0
  221. package/src/Auth.ts +225 -0
  222. package/src/Avatars.ts +144 -0
  223. package/src/BrowserAnalytics.ts +133 -0
  224. package/src/Chat.ts +1150 -0
  225. package/src/ChatIntegrity.ts +130 -0
  226. package/src/ChatSends.ts +209 -0
  227. package/src/Client.ts +319 -0
  228. package/src/Collab.ts +524 -0
  229. package/src/CollabTools.ts +381 -0
  230. package/src/Connections.ts +517 -0
  231. package/src/Consent.ts +176 -0
  232. package/src/Desktop.ts +139 -0
  233. package/src/Directory.ts +71 -0
  234. package/src/ErrorReporter.ts +112 -0
  235. package/src/ExpoSqlite.ts +6 -0
  236. package/src/FileSync.ts +34 -0
  237. package/src/FileTables.gen.ts +23 -0
  238. package/src/Foldkit.ts +960 -0
  239. package/src/History.ts +337 -0
  240. package/src/InboxSync.ts +47 -0
  241. package/src/KernelTables.gen.ts +329 -0
  242. package/src/Make.ts +120 -0
  243. package/src/Models.ts +134 -0
  244. package/src/Optimistic.ts +364 -0
  245. package/src/PlatformSync.ts +156 -0
  246. package/src/Poll.ts +227 -0
  247. package/src/Preferences.ts +42 -0
  248. package/src/Proposals.ts +57 -0
  249. package/src/React.ts +26 -0
  250. package/src/Reader.ts +180 -0
  251. package/src/Resources.ts +257 -0
  252. package/src/Rows.ts +16 -0
  253. package/src/Runtime.ts +1442 -0
  254. package/src/RuntimeRuns.ts +180 -0
  255. package/src/ServicesSync.ts +58 -0
  256. package/src/Session.ts +844 -0
  257. package/src/ShareGrant.ts +20 -0
  258. package/src/Sharing.ts +696 -0
  259. package/src/Skew.ts +97 -0
  260. package/src/SpacesSync.ts +61 -0
  261. package/src/Storage.ts +167 -0
  262. package/src/Sync.ts +125 -0
  263. package/src/SyncTables.ts +12 -0
  264. package/src/Tab.ts +59 -0
  265. package/src/Transport.ts +321 -0
  266. package/src/Upload.ts +125 -0
  267. package/src/WebMcp.ts +279 -0
  268. package/src/index.ts +26 -0
  269. package/src/web-globals.d.ts +103 -0
@@ -0,0 +1,228 @@
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
+ * `owns`: the caller still holds `token` without a check (an offline start whose check went `unavailable` again
200
+ * while its listing was in flight): the refusal is recorded for it too, judged in turn with the store's writes.
201
+ */
202
+ refuse: (token: string, owns?: () => boolean) => Promise<boolean>;
203
+ /** Whether the kernel refused `token` in this process (it is never reopened, even offline). */
204
+ isRefused: (token: string) => boolean;
205
+ /** Stop the background cleanup's retries (the client stopped). */
206
+ dispose: () => void;
207
+ /** Where the last durable sign-out's revocation stands (always `none` without `revocations`). */
208
+ revocationStatus: () => RevocationStatus;
209
+ subscribeRevocation: (listener: (status: RevocationStatus) => void) => (() => void);
210
+ /**
211
+ * Try every pending revocation once more (at start, on a timer, when the network returns): `revoked` when the
212
+ * kernel confirmed one, `stillPending` while any is left. Calls made together share one round.
213
+ */
214
+ retryRevocations: () => Promise<{
215
+ readonly revoked: boolean;
216
+ readonly stillPending: boolean;
217
+ }>;
218
+ };
219
+ export type SessionController = ReturnType<typeof sessionController>;
220
+ /**
221
+ * A return path that is safe to send a person to after sign-in: a path on `origin` itself (`/inbox?x=1#y`), or
222
+ * `fallback` (default `/`) for anything else: another origin, a scheme (`javascript:`), a protocol-relative or
223
+ * backslashed path (`//evil.example`, `/\evil.example`), or what does not parse.
224
+ */
225
+ export declare const safeReturnPath: (candidate: string | null | undefined, origin: string, fallback?: string) => string;
226
+ /** The sign-in page's path with where to return afterwards (`?returnTo=`), only when that is safe. */
227
+ export declare const signInPath: (signIn: string, returnTo: string | null | undefined, origin: string) => string;
228
+ //# 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;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