@spacelr/sdk 0.13.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
@@ -268,6 +268,31 @@ interface PasskeySignupResponse {
268
268
  refresh_token?: string;
269
269
  expires_in?: number;
270
270
  }
271
+ /**
272
+ * Response returned by redeeming a recovery phrase (#784). A recovery account is
273
+ * email-less by construction, so `email` is null — same shape as
274
+ * {@link PasskeyLoginResponse}, kept as a distinct name for clarity. Redeeming
275
+ * installs the returned tokens into the SDK session, exactly like a passkey login.
276
+ */
277
+ interface RecoveryRedeemResponse {
278
+ user: {
279
+ id: string;
280
+ email: string | null;
281
+ roles: string[];
282
+ };
283
+ access_token: string;
284
+ refresh_token?: string;
285
+ expires_in?: number;
286
+ }
287
+ /**
288
+ * Whether the signed-in account has an active recovery-phrase binding (#784),
289
+ * and when it was last bound or rotated. Used to prompt the user to set or
290
+ * refresh their recovery phrase.
291
+ */
292
+ interface RecoveryStatusResponse {
293
+ hasBinding: boolean;
294
+ boundAt?: string;
295
+ }
271
296
  /** Result of verifying a passkey registration attestation. */
272
297
  interface PasskeyRegistrationResult {
273
298
  verified: boolean;
@@ -567,6 +592,26 @@ declare class SpacelrError extends Error {
567
592
  declare class SpacelrAuthError extends SpacelrError {
568
593
  constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
569
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
+ }
570
615
  declare class SpacelrNetworkError extends SpacelrError {
571
616
  constructor(message: string, details?: Record<string, unknown>);
572
617
  }
@@ -1147,6 +1192,36 @@ declare class AuthModule {
1147
1192
  deleted: true;
1148
1193
  }>;
1149
1194
  private storeTokensFromLogin;
1195
+ /**
1196
+ * Bind (or rotate) a recovery secret to the signed-in account, so it can be
1197
+ * redeemed later if every passkey is lost. Authenticated — the server rejects
1198
+ * a stale session (fresh-auth), so call this shortly after login/signup. Only
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.
1207
+ */
1208
+ bindRecoveryPhrase(secret: string): Promise<{
1209
+ bound: true;
1210
+ }>;
1211
+ /**
1212
+ * Redeem a recovery secret to restore access to the SAME account without a
1213
+ * passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
1214
+ * Single-use: after a successful redeem the client should bind a fresh phrase
1215
+ * and add a new passkey. Installs the returned tokens into the SDK session,
1216
+ * exactly like a passkey login.
1217
+ */
1218
+ redeemRecoveryPhrase(secret: string): Promise<RecoveryRedeemResponse>;
1219
+ /**
1220
+ * Whether the signed-in account has an active recovery binding, and when it
1221
+ * was last bound/rotated — so the app can prompt the user to set or refresh
1222
+ * their recovery phrase. Authenticated.
1223
+ */
1224
+ getRecoveryStatus(): Promise<RecoveryStatusResponse>;
1150
1225
  private storeTokensFromRegister;
1151
1226
  }
1152
1227
 
@@ -2123,7 +2198,10 @@ interface SpacelrClient {
2123
2198
  * session genuinely cannot be recovered: there was no refresh token to
2124
2199
  * try, or the retry after a successful refresh was itself 401. A 401 whose
2125
2200
  * refresh merely failed *transiently* (network) does NOT fire this — see
2126
- * 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.
2127
2205
  *
2128
2206
  * A **transient refresh failure does NOT fire this** — the SDK keeps the
2129
2207
  * session and the next request retries. That covers a network/transport
@@ -2175,4 +2253,4 @@ interface SpacelrClient {
2175
2253
  }
2176
2254
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2177
2255
 
2178
- 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 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
@@ -268,6 +268,31 @@ interface PasskeySignupResponse {
268
268
  refresh_token?: string;
269
269
  expires_in?: number;
270
270
  }
271
+ /**
272
+ * Response returned by redeeming a recovery phrase (#784). A recovery account is
273
+ * email-less by construction, so `email` is null — same shape as
274
+ * {@link PasskeyLoginResponse}, kept as a distinct name for clarity. Redeeming
275
+ * installs the returned tokens into the SDK session, exactly like a passkey login.
276
+ */
277
+ interface RecoveryRedeemResponse {
278
+ user: {
279
+ id: string;
280
+ email: string | null;
281
+ roles: string[];
282
+ };
283
+ access_token: string;
284
+ refresh_token?: string;
285
+ expires_in?: number;
286
+ }
287
+ /**
288
+ * Whether the signed-in account has an active recovery-phrase binding (#784),
289
+ * and when it was last bound or rotated. Used to prompt the user to set or
290
+ * refresh their recovery phrase.
291
+ */
292
+ interface RecoveryStatusResponse {
293
+ hasBinding: boolean;
294
+ boundAt?: string;
295
+ }
271
296
  /** Result of verifying a passkey registration attestation. */
272
297
  interface PasskeyRegistrationResult {
273
298
  verified: boolean;
@@ -567,6 +592,26 @@ declare class SpacelrError extends Error {
567
592
  declare class SpacelrAuthError extends SpacelrError {
568
593
  constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
569
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
+ }
570
615
  declare class SpacelrNetworkError extends SpacelrError {
571
616
  constructor(message: string, details?: Record<string, unknown>);
572
617
  }
@@ -1147,6 +1192,36 @@ declare class AuthModule {
1147
1192
  deleted: true;
1148
1193
  }>;
1149
1194
  private storeTokensFromLogin;
1195
+ /**
1196
+ * Bind (or rotate) a recovery secret to the signed-in account, so it can be
1197
+ * redeemed later if every passkey is lost. Authenticated — the server rejects
1198
+ * a stale session (fresh-auth), so call this shortly after login/signup. Only
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.
1207
+ */
1208
+ bindRecoveryPhrase(secret: string): Promise<{
1209
+ bound: true;
1210
+ }>;
1211
+ /**
1212
+ * Redeem a recovery secret to restore access to the SAME account without a
1213
+ * passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
1214
+ * Single-use: after a successful redeem the client should bind a fresh phrase
1215
+ * and add a new passkey. Installs the returned tokens into the SDK session,
1216
+ * exactly like a passkey login.
1217
+ */
1218
+ redeemRecoveryPhrase(secret: string): Promise<RecoveryRedeemResponse>;
1219
+ /**
1220
+ * Whether the signed-in account has an active recovery binding, and when it
1221
+ * was last bound/rotated — so the app can prompt the user to set or refresh
1222
+ * their recovery phrase. Authenticated.
1223
+ */
1224
+ getRecoveryStatus(): Promise<RecoveryStatusResponse>;
1150
1225
  private storeTokensFromRegister;
1151
1226
  }
1152
1227
 
@@ -2123,7 +2198,10 @@ interface SpacelrClient {
2123
2198
  * session genuinely cannot be recovered: there was no refresh token to
2124
2199
  * try, or the retry after a successful refresh was itself 401. A 401 whose
2125
2200
  * refresh merely failed *transiently* (network) does NOT fire this — see
2126
- * 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.
2127
2205
  *
2128
2206
  * A **transient refresh failure does NOT fire this** — the SDK keeps the
2129
2207
  * session and the next request retries. That covers a network/transport
@@ -2175,4 +2253,4 @@ interface SpacelrClient {
2175
2253
  }
2176
2254
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2177
2255
 
2178
- 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 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
  }
@@ -2335,6 +2354,60 @@ var AuthModule = class _AuthModule {
2335
2354
  });
2336
2355
  this.emitState("authenticated");
2337
2356
  }
2357
+ // ─── Recover-with-phrase (#784) ───
2358
+ // For an email-less passkey account (#780) that has lost every passkey. The
2359
+ // caller derives an opaque 32-byte base64url secret from a BIP39 phrase and
2360
+ // passes it here — the SDK is transport-only and never sees or generates the
2361
+ // phrase (no wordlist in the bundle).
2362
+ /**
2363
+ * Bind (or rotate) a recovery secret to the signed-in account, so it can be
2364
+ * redeemed later if every passkey is lost. Authenticated — the server rejects
2365
+ * a stale session (fresh-auth), so call this shortly after login/signup. Only
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.
2374
+ */
2375
+ async bindRecoveryPhrase(secret) {
2376
+ return this.http.request({
2377
+ method: "POST",
2378
+ path: "/auth/recovery/bind",
2379
+ body: { secret },
2380
+ authenticated: true
2381
+ });
2382
+ }
2383
+ /**
2384
+ * Redeem a recovery secret to restore access to the SAME account without a
2385
+ * passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
2386
+ * Single-use: after a successful redeem the client should bind a fresh phrase
2387
+ * and add a new passkey. Installs the returned tokens into the SDK session,
2388
+ * exactly like a passkey login.
2389
+ */
2390
+ async redeemRecoveryPhrase(secret) {
2391
+ const result = await this.http.request({
2392
+ method: "POST",
2393
+ path: "/auth/recovery/redeem",
2394
+ body: { secret }
2395
+ });
2396
+ await this.storeTokensFromLogin(result);
2397
+ return result;
2398
+ }
2399
+ /**
2400
+ * Whether the signed-in account has an active recovery binding, and when it
2401
+ * was last bound/rotated — so the app can prompt the user to set or refresh
2402
+ * their recovery phrase. Authenticated.
2403
+ */
2404
+ async getRecoveryStatus() {
2405
+ return this.http.request({
2406
+ method: "GET",
2407
+ path: "/auth/recovery/status",
2408
+ authenticated: true
2409
+ });
2410
+ }
2338
2411
  async storeTokensFromRegister(response) {
2339
2412
  if (!response.access_token) return;
2340
2413
  const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
@@ -4191,6 +4264,7 @@ function createClient(config) {
4191
4264
  SpacelrNetworkError,
4192
4265
  SpacelrScanLimitExceededError,
4193
4266
  SpacelrSearchFilterRequiredError,
4267
+ SpacelrStepUpRequiredError,
4194
4268
  SpacelrTimeoutError,
4195
4269
  SpacelrTwoFactorRequiredError,
4196
4270
  TimelineError,