@spacelr/sdk 0.14.0 → 0.15.1

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
@@ -21,6 +21,12 @@ var SpacelrAuthError = class extends SpacelrError {
21
21
  this.name = "SpacelrAuthError";
22
22
  }
23
23
  };
24
+ var SpacelrStepUpRequiredError = class extends SpacelrError {
25
+ constructor(message, details) {
26
+ super(message, "STEP_UP_REQUIRED", 401, details);
27
+ this.name = "SpacelrStepUpRequiredError";
28
+ }
29
+ };
24
30
  var SpacelrNetworkError = class extends SpacelrError {
25
31
  constructor(message, details) {
26
32
  super(message, "NETWORK_ERROR", void 0, details);
@@ -78,6 +84,13 @@ var SpacelrEmailVerificationRequiredError = class extends SpacelrError {
78
84
  };
79
85
 
80
86
  // libs/sdk/src/core/http-client.ts
87
+ function isStaleSessionBody(body) {
88
+ if (typeof body !== "object" || body === null) {
89
+ return false;
90
+ }
91
+ const flat = body;
92
+ return flat["code"] === "STALE_SESSION" || flat["message"] === "stale_session";
93
+ }
81
94
  var HttpClient = class {
82
95
  constructor(config, tokenManager) {
83
96
  this.config = config;
@@ -121,7 +134,13 @@ var HttpClient = class {
121
134
  });
122
135
  const responseBody = await this.parseResponse(response);
123
136
  if (!response.ok) {
124
- if (options.authenticated && response.status === 401 && !options.skipAuthRefresh) {
137
+ if (options.authenticated && response.status === 401 && !options.skipAuthRefresh && // #793: a `stale_session` 401 means "valid session, this action needs
138
+ // a fresh interactive login" — NOT an auth loss. Refresh cannot fix it
139
+ // (a refreshed token keeps the original auth_time, #789), so skip the
140
+ // refresh/retry/onAuthLost recovery entirely and let throwHttpError
141
+ // surface the typed step-up error below. Route-agnostic on purpose:
142
+ // any fresh-auth-gated route emitting this marker gets correct handling.
143
+ !isStaleSessionBody(responseBody)) {
125
144
  if (await this.recoverFromAuthFailure(isRetry)) {
126
145
  return this.requestWithRetry(options, true);
127
146
  }
@@ -342,6 +361,9 @@ var HttpClient = class {
342
361
  const flatMessage2 = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
343
362
  throw new SpacelrScanLimitExceededError(flatMessage2);
344
363
  }
364
+ if (statusCode === 401 && isStaleSessionBody(flatBody)) {
365
+ throw new SpacelrStepUpRequiredError(message, details);
366
+ }
345
367
  if (statusCode === 401 || statusCode === 403) {
346
368
  throw new SpacelrAuthError(message, statusCode, details);
347
369
  }
@@ -2299,6 +2321,13 @@ var AuthModule = class _AuthModule {
2299
2321
  * redeemed later if every passkey is lost. Authenticated — the server rejects
2300
2322
  * a stale session (fresh-auth), so call this shortly after login/signup. Only
2301
2323
  * email-less accounts may bind. `secret` is a 43-char base64url string.
2324
+ *
2325
+ * #793: when the session is valid but not fresh enough (e.g. rotating the
2326
+ * phrase more than 5 min after the interactive login), this throws
2327
+ * {@link SpacelrStepUpRequiredError} — a step-up signal, NOT an auth loss. The
2328
+ * SDK does not refresh, retry, or fire `onAuthLost` for it (a refresh cannot
2329
+ * make the session fresh again). Catch it, prompt a fresh interactive login
2330
+ * (re-auth), then retry the bind.
2302
2331
  */
2303
2332
  async bindRecoveryPhrase(secret) {
2304
2333
  return this.http.request({
@@ -4191,6 +4220,7 @@ export {
4191
4220
  SpacelrNetworkError,
4192
4221
  SpacelrScanLimitExceededError,
4193
4222
  SpacelrSearchFilterRequiredError,
4223
+ SpacelrStepUpRequiredError,
4194
4224
  SpacelrTimeoutError,
4195
4225
  SpacelrTwoFactorRequiredError,
4196
4226
  TimelineError,