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