@raisindb/client 0.5.12 → 0.5.14

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.mjs CHANGED
@@ -6754,7 +6754,14 @@ var IdentityAuthApi = class {
6754
6754
  skipAuth: true
6755
6755
  });
6756
6756
  }
6757
- /** Sign in with email and password, where the repository enables it. */
6757
+ /**
6758
+ * Sign in with email and password, where the repository enables it.
6759
+ *
6760
+ * `rememberMe` chooses the lifetime of the sign-in: the session AND its refresh
6761
+ * token last 30 days with it and 24 hours without (both configurable per tenant:
6762
+ * `refresh_token_duration_days`, `refresh_token_session_hours`). Refreshing never
6763
+ * extends a session past that.
6764
+ */
6758
6765
  async login(email, password, options) {
6759
6766
  return this.transport({
6760
6767
  method: "POST",
@@ -8137,6 +8144,7 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
8137
8144
  tenantId: options.tenantId ?? this.extractTenantFromUrl(connectionUrl),
8138
8145
  defaultBranch: options.defaultBranch ?? "main"
8139
8146
  };
8147
+ this._tokenRefresher = options.tokenRefresher;
8140
8148
  this._httpBaseUrl = options.httpBaseUrl ?? this.deriveHttpUrl(connectionUrl);
8141
8149
  this._repository = options.repository ?? this.extractRepositoryFromUrl(connectionUrl);
8142
8150
  this._context = {
@@ -8904,6 +8912,7 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
8904
8912
  return this._refreshInFlight;
8905
8913
  }
8906
8914
  async _refreshToken() {
8915
+ if (this._tokenRefresher) return this._refreshViaHook(this._tokenRefresher);
8907
8916
  const refreshToken = this.authManager.storage.getRefreshToken();
8908
8917
  if (!refreshToken) {
8909
8918
  logger.warn("[refreshToken] No refresh token available");
@@ -8960,6 +8969,31 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
8960
8969
  return null;
8961
8970
  }
8962
8971
  }
8972
+ /** `refreshToken()` through `ClientOptions.tokenRefresher` (the session is not the page's to renew). */
8973
+ async _refreshViaHook(hook) {
8974
+ try {
8975
+ const res = await hook();
8976
+ const accessToken = typeof res === "string" ? res : res?.accessToken;
8977
+ if (!accessToken) {
8978
+ this.authManager.clear();
8979
+ this._currentUser = null;
8980
+ this.emit("auth_error", new Error("Token refresh failed - session expired"));
8981
+ return null;
8982
+ }
8983
+ this.authManager.storage.setAccessToken(accessToken);
8984
+ this.authManager.adoptToken(accessToken);
8985
+ const exp = typeof res === "object" && res?.expiresAt ? _RaisinClient.expiresAtToMs(res.expiresAt) : (AuthManager.parseToken(accessToken)?.exp ?? 0) * 1e3;
8986
+ const inMs = exp - Date.now() - 6e4;
8987
+ if (exp && inMs > 0) this.scheduleAutoRefresh(inMs);
8988
+ const user = this._currentUser ? { id: this._currentUser.userId, email: "", displayName: null, avatarUrl: null, emailVerified: false, home: null } : { id: "", email: "", displayName: null, avatarUrl: null, emailVerified: false, home: null };
8989
+ this._emitAuthEvent("TOKEN_REFRESHED");
8990
+ this.emit("token_refreshed", user);
8991
+ return user;
8992
+ } catch (err) {
8993
+ logger.error("[refreshToken] tokenRefresher failed:", err);
8994
+ return null;
8995
+ }
8996
+ }
8963
8997
  /**
8964
8998
  * Fetch with a timeout derived from `requestTimeout`.
8965
8999
  *