@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 +80 -2
- package/dist/index.d.ts +80 -2
- package/dist/index.js +75 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -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
|
}
|
|
@@ -2289,6 +2307,60 @@ var AuthModule = class _AuthModule {
|
|
|
2289
2307
|
});
|
|
2290
2308
|
this.emitState("authenticated");
|
|
2291
2309
|
}
|
|
2310
|
+
// ─── Recover-with-phrase (#784) ───
|
|
2311
|
+
// For an email-less passkey account (#780) that has lost every passkey. The
|
|
2312
|
+
// caller derives an opaque 32-byte base64url secret from a BIP39 phrase and
|
|
2313
|
+
// passes it here — the SDK is transport-only and never sees or generates the
|
|
2314
|
+
// phrase (no wordlist in the bundle).
|
|
2315
|
+
/**
|
|
2316
|
+
* Bind (or rotate) a recovery secret to the signed-in account, so it can be
|
|
2317
|
+
* redeemed later if every passkey is lost. Authenticated — the server rejects
|
|
2318
|
+
* a stale session (fresh-auth), so call this shortly after login/signup. Only
|
|
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.
|
|
2327
|
+
*/
|
|
2328
|
+
async bindRecoveryPhrase(secret) {
|
|
2329
|
+
return this.http.request({
|
|
2330
|
+
method: "POST",
|
|
2331
|
+
path: "/auth/recovery/bind",
|
|
2332
|
+
body: { secret },
|
|
2333
|
+
authenticated: true
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Redeem a recovery secret to restore access to the SAME account without a
|
|
2338
|
+
* passkey/email/password. UNAUTHENTICATED (the caller has no session yet).
|
|
2339
|
+
* Single-use: after a successful redeem the client should bind a fresh phrase
|
|
2340
|
+
* and add a new passkey. Installs the returned tokens into the SDK session,
|
|
2341
|
+
* exactly like a passkey login.
|
|
2342
|
+
*/
|
|
2343
|
+
async redeemRecoveryPhrase(secret) {
|
|
2344
|
+
const result = await this.http.request({
|
|
2345
|
+
method: "POST",
|
|
2346
|
+
path: "/auth/recovery/redeem",
|
|
2347
|
+
body: { secret }
|
|
2348
|
+
});
|
|
2349
|
+
await this.storeTokensFromLogin(result);
|
|
2350
|
+
return result;
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Whether the signed-in account has an active recovery binding, and when it
|
|
2354
|
+
* was last bound/rotated — so the app can prompt the user to set or refresh
|
|
2355
|
+
* their recovery phrase. Authenticated.
|
|
2356
|
+
*/
|
|
2357
|
+
async getRecoveryStatus() {
|
|
2358
|
+
return this.http.request({
|
|
2359
|
+
method: "GET",
|
|
2360
|
+
path: "/auth/recovery/status",
|
|
2361
|
+
authenticated: true
|
|
2362
|
+
});
|
|
2363
|
+
}
|
|
2292
2364
|
async storeTokensFromRegister(response) {
|
|
2293
2365
|
if (!response.access_token) return;
|
|
2294
2366
|
const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
|
|
@@ -4144,6 +4216,7 @@ export {
|
|
|
4144
4216
|
SpacelrNetworkError,
|
|
4145
4217
|
SpacelrScanLimitExceededError,
|
|
4146
4218
|
SpacelrSearchFilterRequiredError,
|
|
4219
|
+
SpacelrStepUpRequiredError,
|
|
4147
4220
|
SpacelrTimeoutError,
|
|
4148
4221
|
SpacelrTwoFactorRequiredError,
|
|
4149
4222
|
TimelineError,
|