@spacelr/sdk 0.14.0 → 0.15.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
@@ -592,6 +592,26 @@ declare class SpacelrError extends Error {
592
592
  declare class SpacelrAuthError extends SpacelrError {
593
593
  constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
594
594
  }
595
+ /**
596
+ * #793 — A fresh-auth-gated action (e.g. `bindRecoveryPhrase`, the recovery
597
+ * phrase rotate) was called with a valid but stale session: the server accepts
598
+ * the session yet requires a recent interactive login for THIS action and
599
+ * returns `401 stale_session`.
600
+ *
601
+ * This is a **step-up signal, not an auth loss.** The session is still good —
602
+ * so the SDK does NOT refresh, retry, or fire `onAuthLost` for it (a refresh
603
+ * cannot help: the refreshed token preserves the original `auth_time`, #789).
604
+ * It deliberately does NOT extend {@link SpacelrAuthError}, so handlers that
605
+ * treat every `SpacelrAuthError` as "session over" won't misclassify a
606
+ * step-up. Mirrors {@link SpacelrTwoFactorRequiredError} ("do this extra step",
607
+ * not "you're logged out").
608
+ *
609
+ * Typical caller reaction: prompt a fresh interactive login (re-auth), then
610
+ * retry the action. The full flat error body is preserved in `details`.
611
+ */
612
+ declare class SpacelrStepUpRequiredError extends SpacelrError {
613
+ constructor(message: string, details?: Record<string, unknown>);
614
+ }
595
615
  declare class SpacelrNetworkError extends SpacelrError {
596
616
  constructor(message: string, details?: Record<string, unknown>);
597
617
  }
@@ -1177,6 +1197,13 @@ declare class AuthModule {
1177
1197
  * redeemed later if every passkey is lost. Authenticated — the server rejects
1178
1198
  * a stale session (fresh-auth), so call this shortly after login/signup. Only
1179
1199
  * email-less accounts may bind. `secret` is a 43-char base64url string.
1200
+ *
1201
+ * #793: when the session is valid but not fresh enough (e.g. rotating the
1202
+ * phrase more than 5 min after the interactive login), this throws
1203
+ * {@link SpacelrStepUpRequiredError} — a step-up signal, NOT an auth loss. The
1204
+ * SDK does not refresh, retry, or fire `onAuthLost` for it (a refresh cannot
1205
+ * make the session fresh again). Catch it, prompt a fresh interactive login
1206
+ * (re-auth), then retry the bind.
1180
1207
  */
1181
1208
  bindRecoveryPhrase(secret: string): Promise<{
1182
1209
  bound: true;
@@ -2171,7 +2198,10 @@ interface SpacelrClient {
2171
2198
  * session genuinely cannot be recovered: there was no refresh token to
2172
2199
  * try, or the retry after a successful refresh was itself 401. A 401 whose
2173
2200
  * refresh merely failed *transiently* (network) does NOT fire this — see
2174
- * below.
2201
+ * below. A `stale_session` 401 from a fresh-auth-gated action (e.g.
2202
+ * recovery-phrase bind/rotate, #793) also does NOT fire this: the session
2203
+ * is still valid, only the action needs a fresh login. That surfaces as a
2204
+ * `SpacelrStepUpRequiredError` on the call itself, not an auth loss.
2175
2205
  *
2176
2206
  * A **transient refresh failure does NOT fire this** — the SDK keeps the
2177
2207
  * session and the next request retries. That covers a network/transport
@@ -2223,4 +2253,4 @@ interface SpacelrClient {
2223
2253
  }
2224
2254
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2225
2255
 
2226
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
2256
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrStepUpRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
package/dist/index.d.ts CHANGED
@@ -592,6 +592,26 @@ declare class SpacelrError extends Error {
592
592
  declare class SpacelrAuthError extends SpacelrError {
593
593
  constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
594
594
  }
595
+ /**
596
+ * #793 — A fresh-auth-gated action (e.g. `bindRecoveryPhrase`, the recovery
597
+ * phrase rotate) was called with a valid but stale session: the server accepts
598
+ * the session yet requires a recent interactive login for THIS action and
599
+ * returns `401 stale_session`.
600
+ *
601
+ * This is a **step-up signal, not an auth loss.** The session is still good —
602
+ * so the SDK does NOT refresh, retry, or fire `onAuthLost` for it (a refresh
603
+ * cannot help: the refreshed token preserves the original `auth_time`, #789).
604
+ * It deliberately does NOT extend {@link SpacelrAuthError}, so handlers that
605
+ * treat every `SpacelrAuthError` as "session over" won't misclassify a
606
+ * step-up. Mirrors {@link SpacelrTwoFactorRequiredError} ("do this extra step",
607
+ * not "you're logged out").
608
+ *
609
+ * Typical caller reaction: prompt a fresh interactive login (re-auth), then
610
+ * retry the action. The full flat error body is preserved in `details`.
611
+ */
612
+ declare class SpacelrStepUpRequiredError extends SpacelrError {
613
+ constructor(message: string, details?: Record<string, unknown>);
614
+ }
595
615
  declare class SpacelrNetworkError extends SpacelrError {
596
616
  constructor(message: string, details?: Record<string, unknown>);
597
617
  }
@@ -1177,6 +1197,13 @@ declare class AuthModule {
1177
1197
  * redeemed later if every passkey is lost. Authenticated — the server rejects
1178
1198
  * a stale session (fresh-auth), so call this shortly after login/signup. Only
1179
1199
  * email-less accounts may bind. `secret` is a 43-char base64url string.
1200
+ *
1201
+ * #793: when the session is valid but not fresh enough (e.g. rotating the
1202
+ * phrase more than 5 min after the interactive login), this throws
1203
+ * {@link SpacelrStepUpRequiredError} — a step-up signal, NOT an auth loss. The
1204
+ * SDK does not refresh, retry, or fire `onAuthLost` for it (a refresh cannot
1205
+ * make the session fresh again). Catch it, prompt a fresh interactive login
1206
+ * (re-auth), then retry the bind.
1180
1207
  */
1181
1208
  bindRecoveryPhrase(secret: string): Promise<{
1182
1209
  bound: true;
@@ -2171,7 +2198,10 @@ interface SpacelrClient {
2171
2198
  * session genuinely cannot be recovered: there was no refresh token to
2172
2199
  * try, or the retry after a successful refresh was itself 401. A 401 whose
2173
2200
  * refresh merely failed *transiently* (network) does NOT fire this — see
2174
- * below.
2201
+ * below. A `stale_session` 401 from a fresh-auth-gated action (e.g.
2202
+ * recovery-phrase bind/rotate, #793) also does NOT fire this: the session
2203
+ * is still valid, only the action needs a fresh login. That surfaces as a
2204
+ * `SpacelrStepUpRequiredError` on the call itself, not an auth loss.
2175
2205
  *
2176
2206
  * A **transient refresh failure does NOT fire this** — the SDK keeps the
2177
2207
  * session and the next request retries. That covers a network/transport
@@ -2223,4 +2253,4 @@ interface SpacelrClient {
2223
2253
  }
2224
2254
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2225
2255
 
2226
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
2256
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrStepUpRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ __export(index_exports, {
37
37
  SpacelrNetworkError: () => SpacelrNetworkError,
38
38
  SpacelrScanLimitExceededError: () => SpacelrScanLimitExceededError,
39
39
  SpacelrSearchFilterRequiredError: () => SpacelrSearchFilterRequiredError,
40
+ SpacelrStepUpRequiredError: () => SpacelrStepUpRequiredError,
40
41
  SpacelrTimeoutError: () => SpacelrTimeoutError,
41
42
  SpacelrTwoFactorRequiredError: () => SpacelrTwoFactorRequiredError,
42
43
  TimelineError: () => TimelineError,
@@ -67,6 +68,12 @@ var SpacelrAuthError = class extends SpacelrError {
67
68
  this.name = "SpacelrAuthError";
68
69
  }
69
70
  };
71
+ var SpacelrStepUpRequiredError = class extends SpacelrError {
72
+ constructor(message, details) {
73
+ super(message, "STEP_UP_REQUIRED", 401, details);
74
+ this.name = "SpacelrStepUpRequiredError";
75
+ }
76
+ };
70
77
  var SpacelrNetworkError = class extends SpacelrError {
71
78
  constructor(message, details) {
72
79
  super(message, "NETWORK_ERROR", void 0, details);
@@ -124,6 +131,9 @@ var SpacelrEmailVerificationRequiredError = class extends SpacelrError {
124
131
  };
125
132
 
126
133
  // libs/sdk/src/core/http-client.ts
134
+ function isStaleSessionBody(body) {
135
+ return typeof body === "object" && body !== null && body["message"] === "stale_session";
136
+ }
127
137
  var HttpClient = class {
128
138
  constructor(config, tokenManager) {
129
139
  this.config = config;
@@ -167,7 +177,13 @@ var HttpClient = class {
167
177
  });
168
178
  const responseBody = await this.parseResponse(response);
169
179
  if (!response.ok) {
170
- if (options.authenticated && response.status === 401 && !options.skipAuthRefresh) {
180
+ if (options.authenticated && response.status === 401 && !options.skipAuthRefresh && // #793: a `stale_session` 401 means "valid session, this action needs
181
+ // a fresh interactive login" — NOT an auth loss. Refresh cannot fix it
182
+ // (a refreshed token keeps the original auth_time, #789), so skip the
183
+ // refresh/retry/onAuthLost recovery entirely and let throwHttpError
184
+ // surface the typed step-up error below. Route-agnostic on purpose:
185
+ // any fresh-auth-gated route emitting this marker gets correct handling.
186
+ !isStaleSessionBody(responseBody)) {
171
187
  if (await this.recoverFromAuthFailure(isRetry)) {
172
188
  return this.requestWithRetry(options, true);
173
189
  }
@@ -388,6 +404,9 @@ var HttpClient = class {
388
404
  const flatMessage2 = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
389
405
  throw new SpacelrScanLimitExceededError(flatMessage2);
390
406
  }
407
+ if (statusCode === 401 && isStaleSessionBody(flatBody)) {
408
+ throw new SpacelrStepUpRequiredError(message, details);
409
+ }
391
410
  if (statusCode === 401 || statusCode === 403) {
392
411
  throw new SpacelrAuthError(message, statusCode, details);
393
412
  }
@@ -2345,6 +2364,13 @@ var AuthModule = class _AuthModule {
2345
2364
  * redeemed later if every passkey is lost. Authenticated — the server rejects
2346
2365
  * a stale session (fresh-auth), so call this shortly after login/signup. Only
2347
2366
  * email-less accounts may bind. `secret` is a 43-char base64url string.
2367
+ *
2368
+ * #793: when the session is valid but not fresh enough (e.g. rotating the
2369
+ * phrase more than 5 min after the interactive login), this throws
2370
+ * {@link SpacelrStepUpRequiredError} — a step-up signal, NOT an auth loss. The
2371
+ * SDK does not refresh, retry, or fire `onAuthLost` for it (a refresh cannot
2372
+ * make the session fresh again). Catch it, prompt a fresh interactive login
2373
+ * (re-auth), then retry the bind.
2348
2374
  */
2349
2375
  async bindRecoveryPhrase(secret) {
2350
2376
  return this.http.request({
@@ -4238,6 +4264,7 @@ function createClient(config) {
4238
4264
  SpacelrNetworkError,
4239
4265
  SpacelrScanLimitExceededError,
4240
4266
  SpacelrSearchFilterRequiredError,
4267
+ SpacelrStepUpRequiredError,
4241
4268
  SpacelrTimeoutError,
4242
4269
  SpacelrTwoFactorRequiredError,
4243
4270
  TimelineError,