@spacelr/sdk 0.15.1 → 0.17.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 +108 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +116 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2365,6 +2365,122 @@ var AuthModule = class _AuthModule {
|
|
|
2365
2365
|
authenticated: true
|
|
2366
2366
|
});
|
|
2367
2367
|
}
|
|
2368
|
+
// ─── Session management (#805 SP1) ───
|
|
2369
|
+
/**
|
|
2370
|
+
* List the active sessions for the signed-in user. Each entry is flagged
|
|
2371
|
+
* `current` when it corresponds to the caller's own access token.
|
|
2372
|
+
*/
|
|
2373
|
+
async listSessions() {
|
|
2374
|
+
const { sessions } = await this.http.request({
|
|
2375
|
+
method: "GET",
|
|
2376
|
+
path: "/auth/sessions",
|
|
2377
|
+
authenticated: true
|
|
2378
|
+
});
|
|
2379
|
+
return sessions;
|
|
2380
|
+
}
|
|
2381
|
+
/**
|
|
2382
|
+
* Revoke a single session by id, signing it out. The server refuses to
|
|
2383
|
+
* revoke the caller's own current session through this endpoint.
|
|
2384
|
+
*/
|
|
2385
|
+
async revokeSession(sessionId) {
|
|
2386
|
+
return this.http.request({
|
|
2387
|
+
method: "DELETE",
|
|
2388
|
+
path: `/auth/sessions/${encodeURIComponent(sessionId)}`,
|
|
2389
|
+
authenticated: true
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* Sign out every other active session for the current user, keeping the
|
|
2394
|
+
* caller's own session intact.
|
|
2395
|
+
*/
|
|
2396
|
+
async signOutOtherSessions() {
|
|
2397
|
+
return this.http.request({
|
|
2398
|
+
method: "POST",
|
|
2399
|
+
path: "/auth/sessions/revoke-others",
|
|
2400
|
+
authenticated: true,
|
|
2401
|
+
body: {}
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
// ─── Device-link (#805 SP2) ───
|
|
2405
|
+
// WhatsApp-style "link a new device": the unauthenticated new device (B)
|
|
2406
|
+
// starts/polls/completes the link; the signed-in device (A) reviews and
|
|
2407
|
+
// approves it. Identity is always derived server-side from tenant headers
|
|
2408
|
+
// / the JWT — the SDK never sends userId/projectId/clientId in these bodies.
|
|
2409
|
+
/**
|
|
2410
|
+
* Start a device-link handshake (new device B). UNAUTHENTICATED. Returns a
|
|
2411
|
+
* displayed `linkToken`/`shortCode` (to relay to the already-signed-in
|
|
2412
|
+
* device A for approval) and a never-displayed `completionSecret` (kept on
|
|
2413
|
+
* this device to call {@link getDeviceLinkOptions} / {@link completeDeviceLink}).
|
|
2414
|
+
*/
|
|
2415
|
+
async startDeviceLink() {
|
|
2416
|
+
return this.http.request({
|
|
2417
|
+
method: "POST",
|
|
2418
|
+
path: "/auth/device-link/init",
|
|
2419
|
+
body: {}
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Poll a device link's current state (new device B). UNAUTHENTICATED.
|
|
2424
|
+
*/
|
|
2425
|
+
async pollDeviceLinkStatus(linkToken) {
|
|
2426
|
+
return this.http.request({
|
|
2427
|
+
method: "GET",
|
|
2428
|
+
path: "/auth/device-link/status",
|
|
2429
|
+
query: { token: linkToken }
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* Fetch WebAuthn registration options to complete the device link (new
|
|
2434
|
+
* device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
|
|
2435
|
+
* the never-displayed `completionSecret` returned by {@link startDeviceLink}.
|
|
2436
|
+
*/
|
|
2437
|
+
async getDeviceLinkOptions(linkToken, completionSecret) {
|
|
2438
|
+
return this.http.request({
|
|
2439
|
+
method: "POST",
|
|
2440
|
+
path: "/auth/device-link/options",
|
|
2441
|
+
body: { linkToken, completionSecret }
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Verify the WebAuthn registration ceremony against the options from
|
|
2446
|
+
* {@link getDeviceLinkOptions}, completing the device link. UNAUTHENTICATED
|
|
2447
|
+
* — requires BOTH secrets, like `getDeviceLinkOptions`. Installs the
|
|
2448
|
+
* returned tokens into the SDK session, exactly like a passkey login, so
|
|
2449
|
+
* the caller is authenticated as the linked account afterwards.
|
|
2450
|
+
*/
|
|
2451
|
+
async completeDeviceLink(linkToken, completionSecret, response, label) {
|
|
2452
|
+
const result = await this.http.request({
|
|
2453
|
+
method: "POST",
|
|
2454
|
+
path: "/auth/device-link/complete",
|
|
2455
|
+
body: { linkToken, completionSecret, response, label }
|
|
2456
|
+
});
|
|
2457
|
+
await this.storeTokensFromLogin(result);
|
|
2458
|
+
return result;
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* Review the device pending approval (signed-in device A). Authenticated.
|
|
2462
|
+
* `code` is the displayed `linkToken` or `shortCode` relayed from device B.
|
|
2463
|
+
*/
|
|
2464
|
+
async getPendingDeviceLink(code) {
|
|
2465
|
+
return this.http.request({
|
|
2466
|
+
method: "GET",
|
|
2467
|
+
path: "/auth/device-link/pending",
|
|
2468
|
+
query: { code },
|
|
2469
|
+
authenticated: true
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Approve the pending device link (signed-in device A). Authenticated.
|
|
2474
|
+
* Ownership/identity are derived server-side from the JWT.
|
|
2475
|
+
*/
|
|
2476
|
+
async approveDeviceLink(code) {
|
|
2477
|
+
return this.http.request({
|
|
2478
|
+
method: "POST",
|
|
2479
|
+
path: "/auth/device-link/approve",
|
|
2480
|
+
authenticated: true,
|
|
2481
|
+
body: { code }
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2368
2484
|
async storeTokensFromRegister(response) {
|
|
2369
2485
|
if (!response.access_token) return;
|
|
2370
2486
|
const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
|