@arbidocs/client 0.5.25 → 0.5.27

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/dist/index.d.cts CHANGED
@@ -40451,6 +40451,19 @@ interface ArbiClient {
40451
40451
  openAllWorkspaces(): Promise<void>;
40452
40452
  /** Subscribe to "the session could not be recovered" (see `relogin`). Returns an unsubscribe. */
40453
40453
  onSessionExpired(listener: () => void): () => void;
40454
+ /**
40455
+ * Subscribe to "the session is ending" (`logout`): called once nothing new can start on it and
40456
+ * before what is in flight is aborted and the server revokes the token, so a host stops its
40457
+ * own work on it (cancels its queries, closes its socket). Returns an unsubscribe.
40458
+ */
40459
+ onSigningOut(listener: () => void): () => void;
40460
+ /** A `logout` is under way: no request starts and no re-login runs until it is done. */
40461
+ isSigningOut(): boolean;
40462
+ /**
40463
+ * The current session's signal: aborted when a `logout` begins, before the server revokes the
40464
+ * token. Hand it to work that must stop with the session (a socket, a stream).
40465
+ */
40466
+ sessionSignal(): AbortSignal;
40454
40467
  };
40455
40468
  /** Crypto utilities */
40456
40469
  crypto: {
@@ -40481,6 +40494,24 @@ interface ArbiClient {
40481
40494
  }
40482
40495
  declare function createArbiClient(options: ArbiClientOptions): ArbiClient;
40483
40496
 
40497
+ /**
40498
+ * The session gate: every authenticated request of a client runs under it, so a sign-out can stop
40499
+ * them all before the server revokes the token.
40500
+ *
40501
+ * A sign-out `close`s the gate: from then on no request starts (it fails at once with an
40502
+ * `AbortError`, without reaching the network) and no re-login runs; then it `abort`s what is in
40503
+ * flight. Only then does the server end the session, so nothing still running on the old token
40504
+ * comes back 401, and nothing a 401 would set off (a re-login, a workspace re-open, a retry) starts
40505
+ * a new server session behind the sign-out. Once the session is cleared the gate `reopen`s, for the
40506
+ * next sign-in.
40507
+ */
40508
+
40509
+ /**
40510
+ * Whether `error` is a request (or work) that was aborted rather than one that failed: callers
40511
+ * treat it as nothing to report. Looks through `cause`, for an error wrapped by the SDK.
40512
+ */
40513
+ declare function isAbortError(error: unknown): boolean;
40514
+
40484
40515
  /**
40485
40516
  * Bearer Auth Middleware
40486
40517
  *
@@ -40629,4 +40660,4 @@ interface OpenAllDeps {
40629
40660
  */
40630
40661
  declare function createAllWorkspacesOpener(deps: OpenAllDeps): () => Promise<void>;
40631
40662
 
40632
- export { type $defs, ACCESS_TOKEN_STORAGE_KEY, API_PREFIX, type ArbiClient, type ArbiClientOptions, type AuthStateProvider, type AutoReloginMiddlewareConfig, type BearerAuthMiddlewareConfig, CALL_KEY_BYTES, CHAT_KEY_BYTES, type CallPeer, type ChangePasswordParams, type ChangePasswordRequest, type ChangePasswordResult, type CryptoProvider, type DisconnectSsoParams, ENCRYPTED_RECOVERY_KEY_SIZE, type KeyLoginCredentials, type KeyPair, type ListedWorkspaceKey, type LoginCredentials, type LoginParams, type LoginProfile, type LoginProvider, type LoginRequest, type LoginResponse, type LoginResult, type LoginWithKeyParams, type OfflineSealer, type OfflineSealerOptions, type OnReloginSuccess, type OpenAllDeps, type ParsedRecoveryUrl, type PasswordChangeCredentials, RECOVERY_KEY_ERRORS, type RecoveryKeyParams, type RecoveryKeyValidationResult, type RegisterParams, type RegisterRequest, type RegisterResult, type RegistrationCredentials, type ReloginDeps, type ReloginFailure, type ReloginHandler, type ReopenDeps, SECURE_MAIL_KEY_BYTES, type SealedSecureMail, type SecureMailCiphertexts, type SecureMailClaim, type SessionClaims, type SessionData, type SessionKeys, type SessionManager, type SessionManagerOptions, type SessionPersistence, type SessionSignIn, type SessionState, type SessionStateStorage, type SessionUser, type SignInHooks, type SsoTokenSource, type StoredSessionState, type TokenProvider, UNENCRYPTED_RECOVERY_KEY_SIZE, type UserKeypairs, type WebSocketClientMessage, type WebSocketServerMessage, type WorkspaceKeyRefreshProvider, type WorkspaceKeys, type WorkspaceOpenProvider, type WorkspaceOpens, type WsAgentDmStatusMessage, type WsAuthMessage, type WsAuthResultMessage, type WsBatchCompleteMessage, type WsChatMessageMessage, type WsChatReadMessage, type WsChatUpdatedMessage, type WsConnectionClosedMessage, type WsConversationMessagePostedMessage, type WsErrorMessage, type WsNotificationResponse, type WsPresenceUpdateMessage, type WsResponseCompleteMessage, type WsTaskUpdateMessage, authRequestError, base64Decode, base64Encode, base64ToBytes, base64UrlToBytes, browserSessionStateStorage, buildCallFragment, buildCallLink, buildWebSocketUrl, bytesToBase64, bytesToBase64Url, canPersistSession, changePassword, clearAllData, clearSession, type components, computeSharedSecret, createAllWorkspacesOpener, createArbiClient, createAuthMessage, createAutoReloginMiddleware, createBearerAuthMiddleware, createContentHash, createOfflineSealer, createRecoveryFile, createRecoveryUrl, createReloginHandler, createSessionManager, createWorkspaceKeys, createWorkspaceOpens, createWorkspaceReopener, decodeCallKey, decodeSecureMailKey, decryptCallTitle, decryptFile, decryptMessage, decryptMessageWithSharedSecret, decryptRecoveryKey, decryptWithChatKey, deriveDirectChatKey, deriveEncryptionKeypairFromSigning, derivePublicKey, disconnectSso, encodeCallKey, encryptCallTitle, encryptFile, encryptMessage, encryptMessageWithSharedSecret, encryptRecoveryKey, encryptWithChatKey, encryptionKeypairFromSigningKey, generateCallKey, generateChatKey, generateIdentityKeypair, generateKeyPairs, generateLoginCredentials, generateLoginCredentialsFromKey, generatePasswordChangeCredentials, generateRandomSigningKeypair, generateRegistrationCredentials, generateUserKeypairs, getRecoveryKeyFilename, getSession, getUserEncryptionKeypair, hasSession, identityFromLoginResponse, initSodium, initializeDatabase, isEncryptedRecoveryKey, isMessageType, openCallKeyOf, openSealedCallKey, openSealedChatKey, openSecureMail, type operations, parseCallFragment, parseRecoveryUrl, parseServerMessage, passwordChangeErrorMessage, type paths, prewarmKeyPairs, readSessionClaims, requestSsoDisconnectCode, saveSession, sealCallKey, sealCallKeyForPeers, sealChatKey, sealKeyForSession, sealSecureMail, sealedBoxDecrypt, sealedBoxEncrypt, secureMailClaim, signMessage, unlockIdentityWithPassword, unwrapIdentityKey, unwrapWorkspaceKey, updateWrappedIdentityKey, validateRecoveryKeyFile, type webhooks, workspaceKeyRequiredOf, wrapIdentityKey };
40663
+ export { type $defs, ACCESS_TOKEN_STORAGE_KEY, API_PREFIX, type ArbiClient, type ArbiClientOptions, type AuthStateProvider, type AutoReloginMiddlewareConfig, type BearerAuthMiddlewareConfig, CALL_KEY_BYTES, CHAT_KEY_BYTES, type CallPeer, type ChangePasswordParams, type ChangePasswordRequest, type ChangePasswordResult, type CryptoProvider, type DisconnectSsoParams, ENCRYPTED_RECOVERY_KEY_SIZE, type KeyLoginCredentials, type KeyPair, type ListedWorkspaceKey, type LoginCredentials, type LoginParams, type LoginProfile, type LoginProvider, type LoginRequest, type LoginResponse, type LoginResult, type LoginWithKeyParams, type OfflineSealer, type OfflineSealerOptions, type OnReloginSuccess, type OpenAllDeps, type ParsedRecoveryUrl, type PasswordChangeCredentials, RECOVERY_KEY_ERRORS, type RecoveryKeyParams, type RecoveryKeyValidationResult, type RegisterParams, type RegisterRequest, type RegisterResult, type RegistrationCredentials, type ReloginDeps, type ReloginFailure, type ReloginHandler, type ReopenDeps, SECURE_MAIL_KEY_BYTES, type SealedSecureMail, type SecureMailCiphertexts, type SecureMailClaim, type SessionClaims, type SessionData, type SessionKeys, type SessionManager, type SessionManagerOptions, type SessionPersistence, type SessionSignIn, type SessionState, type SessionStateStorage, type SessionUser, type SignInHooks, type SsoTokenSource, type StoredSessionState, type TokenProvider, UNENCRYPTED_RECOVERY_KEY_SIZE, type UserKeypairs, type WebSocketClientMessage, type WebSocketServerMessage, type WorkspaceKeyRefreshProvider, type WorkspaceKeys, type WorkspaceOpenProvider, type WorkspaceOpens, type WsAgentDmStatusMessage, type WsAuthMessage, type WsAuthResultMessage, type WsBatchCompleteMessage, type WsChatMessageMessage, type WsChatReadMessage, type WsChatUpdatedMessage, type WsConnectionClosedMessage, type WsConversationMessagePostedMessage, type WsErrorMessage, type WsNotificationResponse, type WsPresenceUpdateMessage, type WsResponseCompleteMessage, type WsTaskUpdateMessage, authRequestError, base64Decode, base64Encode, base64ToBytes, base64UrlToBytes, browserSessionStateStorage, buildCallFragment, buildCallLink, buildWebSocketUrl, bytesToBase64, bytesToBase64Url, canPersistSession, changePassword, clearAllData, clearSession, type components, computeSharedSecret, createAllWorkspacesOpener, createArbiClient, createAuthMessage, createAutoReloginMiddleware, createBearerAuthMiddleware, createContentHash, createOfflineSealer, createRecoveryFile, createRecoveryUrl, createReloginHandler, createSessionManager, createWorkspaceKeys, createWorkspaceOpens, createWorkspaceReopener, decodeCallKey, decodeSecureMailKey, decryptCallTitle, decryptFile, decryptMessage, decryptMessageWithSharedSecret, decryptRecoveryKey, decryptWithChatKey, deriveDirectChatKey, deriveEncryptionKeypairFromSigning, derivePublicKey, disconnectSso, encodeCallKey, encryptCallTitle, encryptFile, encryptMessage, encryptMessageWithSharedSecret, encryptRecoveryKey, encryptWithChatKey, encryptionKeypairFromSigningKey, generateCallKey, generateChatKey, generateIdentityKeypair, generateKeyPairs, generateLoginCredentials, generateLoginCredentialsFromKey, generatePasswordChangeCredentials, generateRandomSigningKeypair, generateRegistrationCredentials, generateUserKeypairs, getRecoveryKeyFilename, getSession, getUserEncryptionKeypair, hasSession, identityFromLoginResponse, initSodium, initializeDatabase, isAbortError, isEncryptedRecoveryKey, isMessageType, openCallKeyOf, openSealedCallKey, openSealedChatKey, openSecureMail, type operations, parseCallFragment, parseRecoveryUrl, parseServerMessage, passwordChangeErrorMessage, type paths, prewarmKeyPairs, readSessionClaims, requestSsoDisconnectCode, saveSession, sealCallKey, sealCallKeyForPeers, sealChatKey, sealKeyForSession, sealSecureMail, sealedBoxDecrypt, sealedBoxEncrypt, secureMailClaim, signMessage, unlockIdentityWithPassword, unwrapIdentityKey, unwrapWorkspaceKey, updateWrappedIdentityKey, validateRecoveryKeyFile, type webhooks, workspaceKeyRequiredOf, wrapIdentityKey };
package/dist/index.d.ts CHANGED
@@ -40451,6 +40451,19 @@ interface ArbiClient {
40451
40451
  openAllWorkspaces(): Promise<void>;
40452
40452
  /** Subscribe to "the session could not be recovered" (see `relogin`). Returns an unsubscribe. */
40453
40453
  onSessionExpired(listener: () => void): () => void;
40454
+ /**
40455
+ * Subscribe to "the session is ending" (`logout`): called once nothing new can start on it and
40456
+ * before what is in flight is aborted and the server revokes the token, so a host stops its
40457
+ * own work on it (cancels its queries, closes its socket). Returns an unsubscribe.
40458
+ */
40459
+ onSigningOut(listener: () => void): () => void;
40460
+ /** A `logout` is under way: no request starts and no re-login runs until it is done. */
40461
+ isSigningOut(): boolean;
40462
+ /**
40463
+ * The current session's signal: aborted when a `logout` begins, before the server revokes the
40464
+ * token. Hand it to work that must stop with the session (a socket, a stream).
40465
+ */
40466
+ sessionSignal(): AbortSignal;
40454
40467
  };
40455
40468
  /** Crypto utilities */
40456
40469
  crypto: {
@@ -40481,6 +40494,24 @@ interface ArbiClient {
40481
40494
  }
40482
40495
  declare function createArbiClient(options: ArbiClientOptions): ArbiClient;
40483
40496
 
40497
+ /**
40498
+ * The session gate: every authenticated request of a client runs under it, so a sign-out can stop
40499
+ * them all before the server revokes the token.
40500
+ *
40501
+ * A sign-out `close`s the gate: from then on no request starts (it fails at once with an
40502
+ * `AbortError`, without reaching the network) and no re-login runs; then it `abort`s what is in
40503
+ * flight. Only then does the server end the session, so nothing still running on the old token
40504
+ * comes back 401, and nothing a 401 would set off (a re-login, a workspace re-open, a retry) starts
40505
+ * a new server session behind the sign-out. Once the session is cleared the gate `reopen`s, for the
40506
+ * next sign-in.
40507
+ */
40508
+
40509
+ /**
40510
+ * Whether `error` is a request (or work) that was aborted rather than one that failed: callers
40511
+ * treat it as nothing to report. Looks through `cause`, for an error wrapped by the SDK.
40512
+ */
40513
+ declare function isAbortError(error: unknown): boolean;
40514
+
40484
40515
  /**
40485
40516
  * Bearer Auth Middleware
40486
40517
  *
@@ -40629,4 +40660,4 @@ interface OpenAllDeps {
40629
40660
  */
40630
40661
  declare function createAllWorkspacesOpener(deps: OpenAllDeps): () => Promise<void>;
40631
40662
 
40632
- export { type $defs, ACCESS_TOKEN_STORAGE_KEY, API_PREFIX, type ArbiClient, type ArbiClientOptions, type AuthStateProvider, type AutoReloginMiddlewareConfig, type BearerAuthMiddlewareConfig, CALL_KEY_BYTES, CHAT_KEY_BYTES, type CallPeer, type ChangePasswordParams, type ChangePasswordRequest, type ChangePasswordResult, type CryptoProvider, type DisconnectSsoParams, ENCRYPTED_RECOVERY_KEY_SIZE, type KeyLoginCredentials, type KeyPair, type ListedWorkspaceKey, type LoginCredentials, type LoginParams, type LoginProfile, type LoginProvider, type LoginRequest, type LoginResponse, type LoginResult, type LoginWithKeyParams, type OfflineSealer, type OfflineSealerOptions, type OnReloginSuccess, type OpenAllDeps, type ParsedRecoveryUrl, type PasswordChangeCredentials, RECOVERY_KEY_ERRORS, type RecoveryKeyParams, type RecoveryKeyValidationResult, type RegisterParams, type RegisterRequest, type RegisterResult, type RegistrationCredentials, type ReloginDeps, type ReloginFailure, type ReloginHandler, type ReopenDeps, SECURE_MAIL_KEY_BYTES, type SealedSecureMail, type SecureMailCiphertexts, type SecureMailClaim, type SessionClaims, type SessionData, type SessionKeys, type SessionManager, type SessionManagerOptions, type SessionPersistence, type SessionSignIn, type SessionState, type SessionStateStorage, type SessionUser, type SignInHooks, type SsoTokenSource, type StoredSessionState, type TokenProvider, UNENCRYPTED_RECOVERY_KEY_SIZE, type UserKeypairs, type WebSocketClientMessage, type WebSocketServerMessage, type WorkspaceKeyRefreshProvider, type WorkspaceKeys, type WorkspaceOpenProvider, type WorkspaceOpens, type WsAgentDmStatusMessage, type WsAuthMessage, type WsAuthResultMessage, type WsBatchCompleteMessage, type WsChatMessageMessage, type WsChatReadMessage, type WsChatUpdatedMessage, type WsConnectionClosedMessage, type WsConversationMessagePostedMessage, type WsErrorMessage, type WsNotificationResponse, type WsPresenceUpdateMessage, type WsResponseCompleteMessage, type WsTaskUpdateMessage, authRequestError, base64Decode, base64Encode, base64ToBytes, base64UrlToBytes, browserSessionStateStorage, buildCallFragment, buildCallLink, buildWebSocketUrl, bytesToBase64, bytesToBase64Url, canPersistSession, changePassword, clearAllData, clearSession, type components, computeSharedSecret, createAllWorkspacesOpener, createArbiClient, createAuthMessage, createAutoReloginMiddleware, createBearerAuthMiddleware, createContentHash, createOfflineSealer, createRecoveryFile, createRecoveryUrl, createReloginHandler, createSessionManager, createWorkspaceKeys, createWorkspaceOpens, createWorkspaceReopener, decodeCallKey, decodeSecureMailKey, decryptCallTitle, decryptFile, decryptMessage, decryptMessageWithSharedSecret, decryptRecoveryKey, decryptWithChatKey, deriveDirectChatKey, deriveEncryptionKeypairFromSigning, derivePublicKey, disconnectSso, encodeCallKey, encryptCallTitle, encryptFile, encryptMessage, encryptMessageWithSharedSecret, encryptRecoveryKey, encryptWithChatKey, encryptionKeypairFromSigningKey, generateCallKey, generateChatKey, generateIdentityKeypair, generateKeyPairs, generateLoginCredentials, generateLoginCredentialsFromKey, generatePasswordChangeCredentials, generateRandomSigningKeypair, generateRegistrationCredentials, generateUserKeypairs, getRecoveryKeyFilename, getSession, getUserEncryptionKeypair, hasSession, identityFromLoginResponse, initSodium, initializeDatabase, isEncryptedRecoveryKey, isMessageType, openCallKeyOf, openSealedCallKey, openSealedChatKey, openSecureMail, type operations, parseCallFragment, parseRecoveryUrl, parseServerMessage, passwordChangeErrorMessage, type paths, prewarmKeyPairs, readSessionClaims, requestSsoDisconnectCode, saveSession, sealCallKey, sealCallKeyForPeers, sealChatKey, sealKeyForSession, sealSecureMail, sealedBoxDecrypt, sealedBoxEncrypt, secureMailClaim, signMessage, unlockIdentityWithPassword, unwrapIdentityKey, unwrapWorkspaceKey, updateWrappedIdentityKey, validateRecoveryKeyFile, type webhooks, workspaceKeyRequiredOf, wrapIdentityKey };
40663
+ export { type $defs, ACCESS_TOKEN_STORAGE_KEY, API_PREFIX, type ArbiClient, type ArbiClientOptions, type AuthStateProvider, type AutoReloginMiddlewareConfig, type BearerAuthMiddlewareConfig, CALL_KEY_BYTES, CHAT_KEY_BYTES, type CallPeer, type ChangePasswordParams, type ChangePasswordRequest, type ChangePasswordResult, type CryptoProvider, type DisconnectSsoParams, ENCRYPTED_RECOVERY_KEY_SIZE, type KeyLoginCredentials, type KeyPair, type ListedWorkspaceKey, type LoginCredentials, type LoginParams, type LoginProfile, type LoginProvider, type LoginRequest, type LoginResponse, type LoginResult, type LoginWithKeyParams, type OfflineSealer, type OfflineSealerOptions, type OnReloginSuccess, type OpenAllDeps, type ParsedRecoveryUrl, type PasswordChangeCredentials, RECOVERY_KEY_ERRORS, type RecoveryKeyParams, type RecoveryKeyValidationResult, type RegisterParams, type RegisterRequest, type RegisterResult, type RegistrationCredentials, type ReloginDeps, type ReloginFailure, type ReloginHandler, type ReopenDeps, SECURE_MAIL_KEY_BYTES, type SealedSecureMail, type SecureMailCiphertexts, type SecureMailClaim, type SessionClaims, type SessionData, type SessionKeys, type SessionManager, type SessionManagerOptions, type SessionPersistence, type SessionSignIn, type SessionState, type SessionStateStorage, type SessionUser, type SignInHooks, type SsoTokenSource, type StoredSessionState, type TokenProvider, UNENCRYPTED_RECOVERY_KEY_SIZE, type UserKeypairs, type WebSocketClientMessage, type WebSocketServerMessage, type WorkspaceKeyRefreshProvider, type WorkspaceKeys, type WorkspaceOpenProvider, type WorkspaceOpens, type WsAgentDmStatusMessage, type WsAuthMessage, type WsAuthResultMessage, type WsBatchCompleteMessage, type WsChatMessageMessage, type WsChatReadMessage, type WsChatUpdatedMessage, type WsConnectionClosedMessage, type WsConversationMessagePostedMessage, type WsErrorMessage, type WsNotificationResponse, type WsPresenceUpdateMessage, type WsResponseCompleteMessage, type WsTaskUpdateMessage, authRequestError, base64Decode, base64Encode, base64ToBytes, base64UrlToBytes, browserSessionStateStorage, buildCallFragment, buildCallLink, buildWebSocketUrl, bytesToBase64, bytesToBase64Url, canPersistSession, changePassword, clearAllData, clearSession, type components, computeSharedSecret, createAllWorkspacesOpener, createArbiClient, createAuthMessage, createAutoReloginMiddleware, createBearerAuthMiddleware, createContentHash, createOfflineSealer, createRecoveryFile, createRecoveryUrl, createReloginHandler, createSessionManager, createWorkspaceKeys, createWorkspaceOpens, createWorkspaceReopener, decodeCallKey, decodeSecureMailKey, decryptCallTitle, decryptFile, decryptMessage, decryptMessageWithSharedSecret, decryptRecoveryKey, decryptWithChatKey, deriveDirectChatKey, deriveEncryptionKeypairFromSigning, derivePublicKey, disconnectSso, encodeCallKey, encryptCallTitle, encryptFile, encryptMessage, encryptMessageWithSharedSecret, encryptRecoveryKey, encryptWithChatKey, encryptionKeypairFromSigningKey, generateCallKey, generateChatKey, generateIdentityKeypair, generateKeyPairs, generateLoginCredentials, generateLoginCredentialsFromKey, generatePasswordChangeCredentials, generateRandomSigningKeypair, generateRegistrationCredentials, generateUserKeypairs, getRecoveryKeyFilename, getSession, getUserEncryptionKeypair, hasSession, identityFromLoginResponse, initSodium, initializeDatabase, isAbortError, isEncryptedRecoveryKey, isMessageType, openCallKeyOf, openSealedCallKey, openSealedChatKey, openSecureMail, type operations, parseCallFragment, parseRecoveryUrl, parseServerMessage, passwordChangeErrorMessage, type paths, prewarmKeyPairs, readSessionClaims, requestSsoDisconnectCode, saveSession, sealCallKey, sealCallKeyForPeers, sealChatKey, sealKeyForSession, sealSecureMail, sealedBoxDecrypt, sealedBoxEncrypt, secureMailClaim, signMessage, unlockIdentityWithPassword, unwrapIdentityKey, unwrapWorkspaceKey, updateWrappedIdentityKey, validateRecoveryKeyFile, type webhooks, workspaceKeyRequiredOf, wrapIdentityKey };
package/dist/index.js CHANGED
@@ -1109,6 +1109,67 @@ function createBearerAuthMiddleware(config) {
1109
1109
  };
1110
1110
  }
1111
1111
 
1112
+ // src/session-gate.ts
1113
+ function abortError() {
1114
+ return new DOMException("The session ended.", "AbortError");
1115
+ }
1116
+ function isAbortError(error) {
1117
+ for (let e = error, depth = 0; e && typeof e === "object" && depth < 5; depth++) {
1118
+ if (e.name === "AbortError") return true;
1119
+ e = e.cause;
1120
+ }
1121
+ return false;
1122
+ }
1123
+ function eitherSignal(a, b) {
1124
+ if (!b) return a;
1125
+ if (typeof AbortSignal.any === "function") return AbortSignal.any([a, b]);
1126
+ const controller = new AbortController();
1127
+ const abort = (signal) => () => controller.abort(signal.reason);
1128
+ if (a.aborted || b.aborted) controller.abort((a.aborted ? a : b).reason);
1129
+ else {
1130
+ a.addEventListener("abort", abort(a), { once: true });
1131
+ b.addEventListener("abort", abort(b), { once: true });
1132
+ }
1133
+ return controller.signal;
1134
+ }
1135
+ function createSessionGate() {
1136
+ let controller = new AbortController();
1137
+ let closed = false;
1138
+ return {
1139
+ get signal() {
1140
+ return controller.signal;
1141
+ },
1142
+ get closed() {
1143
+ return closed;
1144
+ },
1145
+ close() {
1146
+ closed = true;
1147
+ },
1148
+ abort() {
1149
+ controller.abort(abortError());
1150
+ },
1151
+ reopen() {
1152
+ if (controller.signal.aborted) controller = new AbortController();
1153
+ closed = false;
1154
+ }
1155
+ };
1156
+ }
1157
+ function gatedFetch(gate, fetch2) {
1158
+ return (input, init) => {
1159
+ if (gate.closed) return Promise.reject(abortError());
1160
+ const own = init?.signal ?? (input instanceof Request ? input.signal : void 0);
1161
+ return fetch2(input, { ...init, signal: eitherSignal(gate.signal, own) });
1162
+ };
1163
+ }
1164
+ function createSessionGateMiddleware(gate) {
1165
+ return {
1166
+ onRequest({ request }) {
1167
+ const signal = gate.closed ? AbortSignal.abort(abortError()) : gate.signal;
1168
+ return new Request(request, { signal: eitherSignal(signal, request.signal) });
1169
+ }
1170
+ };
1171
+ }
1172
+
1112
1173
  // src/workspace-keys.ts
1113
1174
  function createWorkspaceKeys(deps) {
1114
1175
  const wrapped = /* @__PURE__ */ new Map();
@@ -1905,6 +1966,8 @@ function createTransport(options) {
1905
1966
  const baseUrlOption = options.baseUrl;
1906
1967
  const base = typeof baseUrlOption === "function" ? baseUrlOption : () => baseUrlOption;
1907
1968
  const retryFetch = createRetryFetch();
1969
+ const gate = createSessionGate();
1970
+ const sessionFetch = gatedFetch(gate, retryFetch);
1908
1971
  const session = options.session ?? createSessionManager();
1909
1972
  if (userEmail) session.setUser(userEmail);
1910
1973
  const tokenProvider = createTokenProvider(session);
@@ -1922,7 +1985,7 @@ function createTransport(options) {
1922
1985
  const rawFetch = createFetchClient({
1923
1986
  baseUrl: base(),
1924
1987
  credentials,
1925
- fetch: retryFetch
1988
+ fetch: sessionFetch
1926
1989
  });
1927
1990
  let response;
1928
1991
  try {
@@ -1935,7 +1998,7 @@ function createTransport(options) {
1935
1998
  }
1936
1999
  });
1937
2000
  } catch (error) {
1938
- console.warn("[API] Login call unreachable:", error);
2001
+ if (!isAbortError(error)) console.warn("[API] Login call unreachable:", error);
1939
2002
  return "unreachable";
1940
2003
  }
1941
2004
  if (response.error || !response.data) {
@@ -1952,7 +2015,7 @@ function createTransport(options) {
1952
2015
  }
1953
2016
  };
1954
2017
  async function listWorkspaces(accessToken) {
1955
- const response = await retryFetch(`${base()}${API_PREFIX}/user/workspaces`, {
2018
+ const response = await sessionFetch(`${base()}${API_PREFIX}/user/workspaces`, {
1956
2019
  method: "GET",
1957
2020
  headers: {
1958
2021
  Authorization: `Bearer ${accessToken}`,
@@ -1970,7 +2033,7 @@ function createTransport(options) {
1970
2033
  getServerSessionKey: () => session.getState().serverSessionKey,
1971
2034
  listWorkspaces,
1972
2035
  async primeKey(accessToken, workspaceId, sealedKey) {
1973
- const response = await retryFetch(
2036
+ const response = await sessionFetch(
1974
2037
  `${base()}${API_PREFIX}/workspace/${workspaceId}/prime-key`,
1975
2038
  {
1976
2039
  method: "POST",
@@ -2001,7 +2064,7 @@ function createTransport(options) {
2001
2064
  async openWorkspace(accessToken, workspaceId, encryptedWorkspaceKey) {
2002
2065
  const query = "?include_documents=false&include_conversations=false&include_tags=false";
2003
2066
  try {
2004
- const response = await retryFetch(
2067
+ const response = await sessionFetch(
2005
2068
  `${base()}${API_PREFIX}/workspace/${workspaceId}/open${query}`,
2006
2069
  {
2007
2070
  method: "POST",
@@ -2031,6 +2094,7 @@ function createTransport(options) {
2031
2094
  };
2032
2095
  let lastFailure = null;
2033
2096
  const expiredListeners = /* @__PURE__ */ new Set();
2097
+ const signingOutListeners = /* @__PURE__ */ new Set();
2034
2098
  const rawRelogin = createReloginHandler({
2035
2099
  crypto: cryptoProvider,
2036
2100
  persistence,
@@ -2050,6 +2114,7 @@ function createTransport(options) {
2050
2114
  }
2051
2115
  });
2052
2116
  async function relogin() {
2117
+ if (gate.closed) return null;
2053
2118
  const tokenBefore = session.getState().accessToken;
2054
2119
  const token = await rawRelogin();
2055
2120
  if (token) return token;
@@ -2071,7 +2136,7 @@ function createTransport(options) {
2071
2136
  workspaceOpenProvider: rawWorkspaceOpenProvider
2072
2137
  });
2073
2138
  let reopening = null;
2074
- const reopenWorkspace = () => reopening ??= workspaceOpens.run(() => authState.getSelectedWorkspaceId(), reopenSelected).finally(() => {
2139
+ const reopenWorkspace = () => gate.closed ? Promise.resolve(false) : reopening ??= workspaceOpens.run(() => authState.getSelectedWorkspaceId(), reopenSelected).finally(() => {
2075
2140
  reopening = null;
2076
2141
  });
2077
2142
  const openEveryWorkspace = createAllWorkspacesOpener({
@@ -2094,6 +2159,7 @@ function createTransport(options) {
2094
2159
  fetch: retryFetch
2095
2160
  });
2096
2161
  if (typeof baseUrlOption === "function") readBaseUrlPerRequest(fetchClient, base);
2162
+ fetchClient.use(createSessionGateMiddleware(gate));
2097
2163
  fetchClient.use(createBearerAuthMiddleware({ tokenProvider }));
2098
2164
  for (const m of middleware) fetchClient.use(m);
2099
2165
  fetchClient.use(
@@ -2121,18 +2187,39 @@ function createTransport(options) {
2121
2187
  relogin,
2122
2188
  reopenWorkspace,
2123
2189
  openAllWorkspaces,
2190
+ onSigningOut(listener) {
2191
+ signingOutListeners.add(listener);
2192
+ return () => {
2193
+ signingOutListeners.delete(listener);
2194
+ };
2195
+ },
2196
+ isSigningOut: () => gate.closed,
2197
+ sessionSignal: () => gate.signal,
2124
2198
  async logout({ everywhere = false } = {}) {
2125
- if (session.getState().accessToken) {
2199
+ gate.close();
2200
+ for (const listener of [...signingOutListeners]) {
2126
2201
  try {
2127
- await fetchClient.POST("/v1/user/logout", {
2128
- params: { query: { all_sessions: everywhere } }
2129
- });
2202
+ listener();
2130
2203
  } catch (error) {
2131
- console.warn("[API] Server logout failed:", error);
2204
+ console.warn("[API] A sign-out listener failed:", error);
2132
2205
  }
2133
2206
  }
2134
- session.clear();
2135
- if (everywhere) await clearAllData();
2207
+ gate.abort();
2208
+ try {
2209
+ const accessToken = session.getState().accessToken;
2210
+ if (accessToken) {
2211
+ const query = `?all_sessions=${everywhere}`;
2212
+ await retryFetch(`${base()}${API_PREFIX}/user/logout${query}`, {
2213
+ method: "POST",
2214
+ headers: { Authorization: `Bearer ${accessToken}` },
2215
+ credentials
2216
+ }).catch((error) => console.warn("[API] Server logout failed:", error));
2217
+ }
2218
+ session.clear();
2219
+ if (everywhere) await clearAllData();
2220
+ } finally {
2221
+ gate.reopen();
2222
+ }
2136
2223
  },
2137
2224
  async unlock({ email, password }) {
2138
2225
  const saved = await persistence.getSession();
@@ -2212,6 +2299,6 @@ function isMessageType(msg, type) {
2212
2299
  return msg.type === type;
2213
2300
  }
2214
2301
 
2215
- export { ACCESS_TOKEN_STORAGE_KEY, API_PREFIX, CALL_KEY_BYTES, CHAT_KEY_BYTES, ENCRYPTED_RECOVERY_KEY_SIZE, RECOVERY_KEY_ERRORS, SECURE_MAIL_KEY_BYTES, UNENCRYPTED_RECOVERY_KEY_SIZE, authRequestError, base64Decode, base64Encode, base64ToBytes, base64UrlToBytes, browserSessionStateStorage, buildCallFragment, buildCallLink, buildWebSocketUrl, bytesToBase64, bytesToBase64Url, canPersistSession, changePassword, clearAllData, clearSession, computeSharedSecret, createAllWorkspacesOpener, createArbiClient, createAuthMessage, createAutoReloginMiddleware, createBearerAuthMiddleware, createContentHash, createOfflineSealer, createRecoveryFile, createRecoveryUrl, createReloginHandler, createSessionManager, createWorkspaceKeys, createWorkspaceOpens, createWorkspaceReopener, decodeCallKey, decodeSecureMailKey, decryptCallTitle, decryptFile, decryptMessage, decryptMessageWithSharedSecret, decryptRecoveryKey, decryptWithChatKey, deriveDirectChatKey, deriveEncryptionKeypairFromSigning, derivePublicKey, disconnectSso, encodeCallKey, encryptCallTitle, encryptFile, encryptMessage, encryptMessageWithSharedSecret, encryptRecoveryKey, encryptWithChatKey, encryptionKeypairFromSigningKey, generateCallKey, generateChatKey, generateIdentityKeypair, generateKeyPairs, generateLoginCredentials, generateLoginCredentialsFromKey, generatePasswordChangeCredentials, generateRandomSigningKeypair, generateRegistrationCredentials, generateUserKeypairs, getRecoveryKeyFilename, getSession, getUserEncryptionKeypair, hasSession, identityFromLoginResponse, initSodium, initializeDatabase, isEncryptedRecoveryKey, isMessageType, openCallKeyOf, openSealedCallKey, openSealedChatKey, openSecureMail, parseCallFragment, parseRecoveryUrl, parseServerMessage, passwordChangeErrorMessage, prewarmKeyPairs, readSessionClaims, requestSsoDisconnectCode, saveSession, sealCallKey, sealCallKeyForPeers, sealChatKey, sealKeyForSession, sealSecureMail, sealedBoxDecrypt, sealedBoxEncrypt, secureMailClaim, signMessage, unlockIdentityWithPassword, unwrapIdentityKey, unwrapWorkspaceKey, updateWrappedIdentityKey, validateRecoveryKeyFile, workspaceKeyRequiredOf, wrapIdentityKey };
2302
+ export { ACCESS_TOKEN_STORAGE_KEY, API_PREFIX, CALL_KEY_BYTES, CHAT_KEY_BYTES, ENCRYPTED_RECOVERY_KEY_SIZE, RECOVERY_KEY_ERRORS, SECURE_MAIL_KEY_BYTES, UNENCRYPTED_RECOVERY_KEY_SIZE, authRequestError, base64Decode, base64Encode, base64ToBytes, base64UrlToBytes, browserSessionStateStorage, buildCallFragment, buildCallLink, buildWebSocketUrl, bytesToBase64, bytesToBase64Url, canPersistSession, changePassword, clearAllData, clearSession, computeSharedSecret, createAllWorkspacesOpener, createArbiClient, createAuthMessage, createAutoReloginMiddleware, createBearerAuthMiddleware, createContentHash, createOfflineSealer, createRecoveryFile, createRecoveryUrl, createReloginHandler, createSessionManager, createWorkspaceKeys, createWorkspaceOpens, createWorkspaceReopener, decodeCallKey, decodeSecureMailKey, decryptCallTitle, decryptFile, decryptMessage, decryptMessageWithSharedSecret, decryptRecoveryKey, decryptWithChatKey, deriveDirectChatKey, deriveEncryptionKeypairFromSigning, derivePublicKey, disconnectSso, encodeCallKey, encryptCallTitle, encryptFile, encryptMessage, encryptMessageWithSharedSecret, encryptRecoveryKey, encryptWithChatKey, encryptionKeypairFromSigningKey, generateCallKey, generateChatKey, generateIdentityKeypair, generateKeyPairs, generateLoginCredentials, generateLoginCredentialsFromKey, generatePasswordChangeCredentials, generateRandomSigningKeypair, generateRegistrationCredentials, generateUserKeypairs, getRecoveryKeyFilename, getSession, getUserEncryptionKeypair, hasSession, identityFromLoginResponse, initSodium, initializeDatabase, isAbortError, isEncryptedRecoveryKey, isMessageType, openCallKeyOf, openSealedCallKey, openSealedChatKey, openSecureMail, parseCallFragment, parseRecoveryUrl, parseServerMessage, passwordChangeErrorMessage, prewarmKeyPairs, readSessionClaims, requestSsoDisconnectCode, saveSession, sealCallKey, sealCallKeyForPeers, sealChatKey, sealKeyForSession, sealSecureMail, sealedBoxDecrypt, sealedBoxEncrypt, secureMailClaim, signMessage, unlockIdentityWithPassword, unwrapIdentityKey, unwrapWorkspaceKey, updateWrappedIdentityKey, validateRecoveryKeyFile, workspaceKeyRequiredOf, wrapIdentityKey };
2216
2303
  //# sourceMappingURL=index.js.map
2217
2304
  //# sourceMappingURL=index.js.map