@spacelr/sdk 0.16.0 → 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 +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2401,6 +2401,86 @@ var AuthModule = class _AuthModule {
|
|
|
2401
2401
|
body: {}
|
|
2402
2402
|
});
|
|
2403
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
|
+
}
|
|
2404
2484
|
async storeTokensFromRegister(response) {
|
|
2405
2485
|
if (!response.access_token) return;
|
|
2406
2486
|
const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
|