@spacelr/sdk 0.8.0 → 0.9.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/dist/index.d.mts CHANGED
@@ -406,6 +406,14 @@ interface HttpRequestOptions {
406
406
  path: string;
407
407
  body?: unknown;
408
408
  authenticated?: boolean;
409
+ /**
410
+ * Suppress the 401 auto-recovery (forceRefresh + emitAuthLost) for this
411
+ * request. Used by logout: a 401 there means the session is already gone,
412
+ * so triggering a refresh/auth-lost would recurse (auth-lost handlers that
413
+ * call logout re-fire the same 401). The token is still sent so the server
414
+ * can revoke it when it is valid.
415
+ */
416
+ skipAuthRefresh?: boolean;
409
417
  headers?: Record<string, string>;
410
418
  query?: Record<string, string | number | undefined>;
411
419
  /** Send cookies cross-origin (credentials: 'include'). Defaults to true for /auth/ paths. */
@@ -1714,6 +1722,14 @@ interface SpacelrClient {
1714
1722
  onAuthLost(listener: (reason: AuthLostReason) => void): () => void;
1715
1723
  /** Subscribe to successful token refreshes. */
1716
1724
  onTokenRefreshed(listener: (tokens: StoredTokens) => void): () => void;
1725
+ /**
1726
+ * Returns a currently-valid access token for making your own authenticated
1727
+ * requests. Blocks on a refresh only when the stored token is already
1728
+ * expired; within the refresh buffer it returns the current token and
1729
+ * refreshes in the background. Returns null when there is no refreshable
1730
+ * session.
1731
+ */
1732
+ getAccessToken(): Promise<string | null>;
1717
1733
  /**
1718
1734
  * Subscribe to realtime socket connection-state changes. Fires on every
1719
1735
  * transition (dedup: identical consecutive states are skipped). Returns
package/dist/index.d.ts CHANGED
@@ -406,6 +406,14 @@ interface HttpRequestOptions {
406
406
  path: string;
407
407
  body?: unknown;
408
408
  authenticated?: boolean;
409
+ /**
410
+ * Suppress the 401 auto-recovery (forceRefresh + emitAuthLost) for this
411
+ * request. Used by logout: a 401 there means the session is already gone,
412
+ * so triggering a refresh/auth-lost would recurse (auth-lost handlers that
413
+ * call logout re-fire the same 401). The token is still sent so the server
414
+ * can revoke it when it is valid.
415
+ */
416
+ skipAuthRefresh?: boolean;
409
417
  headers?: Record<string, string>;
410
418
  query?: Record<string, string | number | undefined>;
411
419
  /** Send cookies cross-origin (credentials: 'include'). Defaults to true for /auth/ paths. */
@@ -1714,6 +1722,14 @@ interface SpacelrClient {
1714
1722
  onAuthLost(listener: (reason: AuthLostReason) => void): () => void;
1715
1723
  /** Subscribe to successful token refreshes. */
1716
1724
  onTokenRefreshed(listener: (tokens: StoredTokens) => void): () => void;
1725
+ /**
1726
+ * Returns a currently-valid access token for making your own authenticated
1727
+ * requests. Blocks on a refresh only when the stored token is already
1728
+ * expired; within the refresh buffer it returns the current token and
1729
+ * refreshes in the background. Returns null when there is no refreshable
1730
+ * session.
1731
+ */
1732
+ getAccessToken(): Promise<string | null>;
1717
1733
  /**
1718
1734
  * Subscribe to realtime socket connection-state changes. Fires on every
1719
1735
  * transition (dedup: identical consecutive states are skipped). Returns
package/dist/index.js CHANGED
@@ -158,7 +158,7 @@ var HttpClient = class {
158
158
  });
159
159
  const responseBody = await this.parseResponse(response);
160
160
  if (!response.ok) {
161
- if (options.authenticated && response.status === 401) {
161
+ if (options.authenticated && response.status === 401 && !options.skipAuthRefresh) {
162
162
  if (await this.recoverFromAuthFailure(isRetry)) {
163
163
  return this.requestWithRetry(options, true);
164
164
  }
@@ -1438,7 +1438,11 @@ var AuthModule = class {
1438
1438
  await this.http.request({
1439
1439
  method: "POST",
1440
1440
  path: "/auth/logout",
1441
- authenticated: true
1441
+ authenticated: true,
1442
+ // A 401 here means the session is already gone — do not trigger the
1443
+ // refresh/auth-lost recovery, or an auth-lost handler that calls
1444
+ // logout would recurse into an endless 401 loop.
1445
+ skipAuthRefresh: true
1442
1446
  });
1443
1447
  } catch {
1444
1448
  }
@@ -3095,6 +3099,9 @@ function createClient(config) {
3095
3099
  onTokenRefreshed(listener) {
3096
3100
  return tokenManager.onTokenRefreshed(listener);
3097
3101
  },
3102
+ getAccessToken() {
3103
+ return tokenManager.getAccessToken();
3104
+ },
3098
3105
  onConnectionStateChanged(listener) {
3099
3106
  return realtime.onConnectionStateChanged(listener);
3100
3107
  },