@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.d.mts
CHANGED
|
@@ -322,6 +322,37 @@ interface SessionSummary {
|
|
|
322
322
|
createdAt: string;
|
|
323
323
|
lastSeenAt: string;
|
|
324
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Result of starting a device link (new device B). The ONLY time all three
|
|
327
|
+
* secrets exist in the clear together — `linkToken`/`shortCode` are shown to
|
|
328
|
+
* the user to relay to device A, `completionSecret` is never displayed and
|
|
329
|
+
* must be kept on device B to call `getDeviceLinkOptions`/`completeDeviceLink`.
|
|
330
|
+
*/
|
|
331
|
+
interface DeviceLinkInit {
|
|
332
|
+
linkToken: string;
|
|
333
|
+
shortCode: string;
|
|
334
|
+
completionSecret: string;
|
|
335
|
+
expiresAt: string;
|
|
336
|
+
}
|
|
337
|
+
/** Current state of a device link, as polled by the new device (B). */
|
|
338
|
+
interface DeviceLinkStatus {
|
|
339
|
+
state: 'pending' | 'approved' | 'completed';
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Tokens returned by completing a device link (#805 SP2). Same shape as
|
|
343
|
+
* {@link PasskeyLoginResponse} (the newly-linked device authenticates via a
|
|
344
|
+
* fresh passkey, not email/password) — kept as a distinct name for clarity.
|
|
345
|
+
*/
|
|
346
|
+
interface DeviceLinkCompleteResponse {
|
|
347
|
+
user: {
|
|
348
|
+
id: string;
|
|
349
|
+
email: string | null;
|
|
350
|
+
roles: string[];
|
|
351
|
+
};
|
|
352
|
+
access_token: string;
|
|
353
|
+
refresh_token?: string;
|
|
354
|
+
expires_in?: number;
|
|
355
|
+
}
|
|
325
356
|
|
|
326
357
|
interface TokenStorage {
|
|
327
358
|
getTokens(): Promise<StoredTokens | null>;
|
|
@@ -1256,6 +1287,49 @@ declare class AuthModule {
|
|
|
1256
1287
|
signOutOtherSessions(): Promise<{
|
|
1257
1288
|
revokedCount: number;
|
|
1258
1289
|
}>;
|
|
1290
|
+
/**
|
|
1291
|
+
* Start a device-link handshake (new device B). UNAUTHENTICATED. Returns a
|
|
1292
|
+
* displayed `linkToken`/`shortCode` (to relay to the already-signed-in
|
|
1293
|
+
* device A for approval) and a never-displayed `completionSecret` (kept on
|
|
1294
|
+
* this device to call {@link getDeviceLinkOptions} / {@link completeDeviceLink}).
|
|
1295
|
+
*/
|
|
1296
|
+
startDeviceLink(): Promise<DeviceLinkInit>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Poll a device link's current state (new device B). UNAUTHENTICATED.
|
|
1299
|
+
*/
|
|
1300
|
+
pollDeviceLinkStatus(linkToken: string): Promise<DeviceLinkStatus>;
|
|
1301
|
+
/**
|
|
1302
|
+
* Fetch WebAuthn registration options to complete the device link (new
|
|
1303
|
+
* device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
|
|
1304
|
+
* the never-displayed `completionSecret` returned by {@link startDeviceLink}.
|
|
1305
|
+
*/
|
|
1306
|
+
getDeviceLinkOptions(linkToken: string, completionSecret: string): Promise<PasskeyRegistrationOptionsJSON>;
|
|
1307
|
+
/**
|
|
1308
|
+
* Verify the WebAuthn registration ceremony against the options from
|
|
1309
|
+
* {@link getDeviceLinkOptions}, completing the device link. UNAUTHENTICATED
|
|
1310
|
+
* — requires BOTH secrets, like `getDeviceLinkOptions`. Installs the
|
|
1311
|
+
* returned tokens into the SDK session, exactly like a passkey login, so
|
|
1312
|
+
* the caller is authenticated as the linked account afterwards.
|
|
1313
|
+
*/
|
|
1314
|
+
completeDeviceLink(linkToken: string, completionSecret: string, response: PasskeyRegistrationResponseJSON, label?: string): Promise<DeviceLinkCompleteResponse>;
|
|
1315
|
+
/**
|
|
1316
|
+
* Review the device pending approval (signed-in device A). Authenticated.
|
|
1317
|
+
* `code` is the displayed `linkToken` or `shortCode` relayed from device B.
|
|
1318
|
+
*/
|
|
1319
|
+
getPendingDeviceLink(code: string): Promise<{
|
|
1320
|
+
deviceInfo: {
|
|
1321
|
+
userAgent?: string;
|
|
1322
|
+
ip?: string;
|
|
1323
|
+
country?: string;
|
|
1324
|
+
};
|
|
1325
|
+
}>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Approve the pending device link (signed-in device A). Authenticated.
|
|
1328
|
+
* Ownership/identity are derived server-side from the JWT.
|
|
1329
|
+
*/
|
|
1330
|
+
approveDeviceLink(code: string): Promise<{
|
|
1331
|
+
approved: true;
|
|
1332
|
+
}>;
|
|
1259
1333
|
private storeTokensFromRegister;
|
|
1260
1334
|
}
|
|
1261
1335
|
|
package/dist/index.d.ts
CHANGED
|
@@ -322,6 +322,37 @@ interface SessionSummary {
|
|
|
322
322
|
createdAt: string;
|
|
323
323
|
lastSeenAt: string;
|
|
324
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Result of starting a device link (new device B). The ONLY time all three
|
|
327
|
+
* secrets exist in the clear together — `linkToken`/`shortCode` are shown to
|
|
328
|
+
* the user to relay to device A, `completionSecret` is never displayed and
|
|
329
|
+
* must be kept on device B to call `getDeviceLinkOptions`/`completeDeviceLink`.
|
|
330
|
+
*/
|
|
331
|
+
interface DeviceLinkInit {
|
|
332
|
+
linkToken: string;
|
|
333
|
+
shortCode: string;
|
|
334
|
+
completionSecret: string;
|
|
335
|
+
expiresAt: string;
|
|
336
|
+
}
|
|
337
|
+
/** Current state of a device link, as polled by the new device (B). */
|
|
338
|
+
interface DeviceLinkStatus {
|
|
339
|
+
state: 'pending' | 'approved' | 'completed';
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Tokens returned by completing a device link (#805 SP2). Same shape as
|
|
343
|
+
* {@link PasskeyLoginResponse} (the newly-linked device authenticates via a
|
|
344
|
+
* fresh passkey, not email/password) — kept as a distinct name for clarity.
|
|
345
|
+
*/
|
|
346
|
+
interface DeviceLinkCompleteResponse {
|
|
347
|
+
user: {
|
|
348
|
+
id: string;
|
|
349
|
+
email: string | null;
|
|
350
|
+
roles: string[];
|
|
351
|
+
};
|
|
352
|
+
access_token: string;
|
|
353
|
+
refresh_token?: string;
|
|
354
|
+
expires_in?: number;
|
|
355
|
+
}
|
|
325
356
|
|
|
326
357
|
interface TokenStorage {
|
|
327
358
|
getTokens(): Promise<StoredTokens | null>;
|
|
@@ -1256,6 +1287,49 @@ declare class AuthModule {
|
|
|
1256
1287
|
signOutOtherSessions(): Promise<{
|
|
1257
1288
|
revokedCount: number;
|
|
1258
1289
|
}>;
|
|
1290
|
+
/**
|
|
1291
|
+
* Start a device-link handshake (new device B). UNAUTHENTICATED. Returns a
|
|
1292
|
+
* displayed `linkToken`/`shortCode` (to relay to the already-signed-in
|
|
1293
|
+
* device A for approval) and a never-displayed `completionSecret` (kept on
|
|
1294
|
+
* this device to call {@link getDeviceLinkOptions} / {@link completeDeviceLink}).
|
|
1295
|
+
*/
|
|
1296
|
+
startDeviceLink(): Promise<DeviceLinkInit>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Poll a device link's current state (new device B). UNAUTHENTICATED.
|
|
1299
|
+
*/
|
|
1300
|
+
pollDeviceLinkStatus(linkToken: string): Promise<DeviceLinkStatus>;
|
|
1301
|
+
/**
|
|
1302
|
+
* Fetch WebAuthn registration options to complete the device link (new
|
|
1303
|
+
* device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
|
|
1304
|
+
* the never-displayed `completionSecret` returned by {@link startDeviceLink}.
|
|
1305
|
+
*/
|
|
1306
|
+
getDeviceLinkOptions(linkToken: string, completionSecret: string): Promise<PasskeyRegistrationOptionsJSON>;
|
|
1307
|
+
/**
|
|
1308
|
+
* Verify the WebAuthn registration ceremony against the options from
|
|
1309
|
+
* {@link getDeviceLinkOptions}, completing the device link. UNAUTHENTICATED
|
|
1310
|
+
* — requires BOTH secrets, like `getDeviceLinkOptions`. Installs the
|
|
1311
|
+
* returned tokens into the SDK session, exactly like a passkey login, so
|
|
1312
|
+
* the caller is authenticated as the linked account afterwards.
|
|
1313
|
+
*/
|
|
1314
|
+
completeDeviceLink(linkToken: string, completionSecret: string, response: PasskeyRegistrationResponseJSON, label?: string): Promise<DeviceLinkCompleteResponse>;
|
|
1315
|
+
/**
|
|
1316
|
+
* Review the device pending approval (signed-in device A). Authenticated.
|
|
1317
|
+
* `code` is the displayed `linkToken` or `shortCode` relayed from device B.
|
|
1318
|
+
*/
|
|
1319
|
+
getPendingDeviceLink(code: string): Promise<{
|
|
1320
|
+
deviceInfo: {
|
|
1321
|
+
userAgent?: string;
|
|
1322
|
+
ip?: string;
|
|
1323
|
+
country?: string;
|
|
1324
|
+
};
|
|
1325
|
+
}>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Approve the pending device link (signed-in device A). Authenticated.
|
|
1328
|
+
* Ownership/identity are derived server-side from the JWT.
|
|
1329
|
+
*/
|
|
1330
|
+
approveDeviceLink(code: string): Promise<{
|
|
1331
|
+
approved: true;
|
|
1332
|
+
}>;
|
|
1259
1333
|
private storeTokensFromRegister;
|
|
1260
1334
|
}
|
|
1261
1335
|
|
package/dist/index.js
CHANGED
|
@@ -2448,6 +2448,86 @@ var AuthModule = class _AuthModule {
|
|
|
2448
2448
|
body: {}
|
|
2449
2449
|
});
|
|
2450
2450
|
}
|
|
2451
|
+
// ─── Device-link (#805 SP2) ───
|
|
2452
|
+
// WhatsApp-style "link a new device": the unauthenticated new device (B)
|
|
2453
|
+
// starts/polls/completes the link; the signed-in device (A) reviews and
|
|
2454
|
+
// approves it. Identity is always derived server-side from tenant headers
|
|
2455
|
+
// / the JWT — the SDK never sends userId/projectId/clientId in these bodies.
|
|
2456
|
+
/**
|
|
2457
|
+
* Start a device-link handshake (new device B). UNAUTHENTICATED. Returns a
|
|
2458
|
+
* displayed `linkToken`/`shortCode` (to relay to the already-signed-in
|
|
2459
|
+
* device A for approval) and a never-displayed `completionSecret` (kept on
|
|
2460
|
+
* this device to call {@link getDeviceLinkOptions} / {@link completeDeviceLink}).
|
|
2461
|
+
*/
|
|
2462
|
+
async startDeviceLink() {
|
|
2463
|
+
return this.http.request({
|
|
2464
|
+
method: "POST",
|
|
2465
|
+
path: "/auth/device-link/init",
|
|
2466
|
+
body: {}
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
/**
|
|
2470
|
+
* Poll a device link's current state (new device B). UNAUTHENTICATED.
|
|
2471
|
+
*/
|
|
2472
|
+
async pollDeviceLinkStatus(linkToken) {
|
|
2473
|
+
return this.http.request({
|
|
2474
|
+
method: "GET",
|
|
2475
|
+
path: "/auth/device-link/status",
|
|
2476
|
+
query: { token: linkToken }
|
|
2477
|
+
});
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Fetch WebAuthn registration options to complete the device link (new
|
|
2481
|
+
* device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
|
|
2482
|
+
* the never-displayed `completionSecret` returned by {@link startDeviceLink}.
|
|
2483
|
+
*/
|
|
2484
|
+
async getDeviceLinkOptions(linkToken, completionSecret) {
|
|
2485
|
+
return this.http.request({
|
|
2486
|
+
method: "POST",
|
|
2487
|
+
path: "/auth/device-link/options",
|
|
2488
|
+
body: { linkToken, completionSecret }
|
|
2489
|
+
});
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Verify the WebAuthn registration ceremony against the options from
|
|
2493
|
+
* {@link getDeviceLinkOptions}, completing the device link. UNAUTHENTICATED
|
|
2494
|
+
* — requires BOTH secrets, like `getDeviceLinkOptions`. Installs the
|
|
2495
|
+
* returned tokens into the SDK session, exactly like a passkey login, so
|
|
2496
|
+
* the caller is authenticated as the linked account afterwards.
|
|
2497
|
+
*/
|
|
2498
|
+
async completeDeviceLink(linkToken, completionSecret, response, label) {
|
|
2499
|
+
const result = await this.http.request({
|
|
2500
|
+
method: "POST",
|
|
2501
|
+
path: "/auth/device-link/complete",
|
|
2502
|
+
body: { linkToken, completionSecret, response, label }
|
|
2503
|
+
});
|
|
2504
|
+
await this.storeTokensFromLogin(result);
|
|
2505
|
+
return result;
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Review the device pending approval (signed-in device A). Authenticated.
|
|
2509
|
+
* `code` is the displayed `linkToken` or `shortCode` relayed from device B.
|
|
2510
|
+
*/
|
|
2511
|
+
async getPendingDeviceLink(code) {
|
|
2512
|
+
return this.http.request({
|
|
2513
|
+
method: "GET",
|
|
2514
|
+
path: "/auth/device-link/pending",
|
|
2515
|
+
query: { code },
|
|
2516
|
+
authenticated: true
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
/**
|
|
2520
|
+
* Approve the pending device link (signed-in device A). Authenticated.
|
|
2521
|
+
* Ownership/identity are derived server-side from the JWT.
|
|
2522
|
+
*/
|
|
2523
|
+
async approveDeviceLink(code) {
|
|
2524
|
+
return this.http.request({
|
|
2525
|
+
method: "POST",
|
|
2526
|
+
path: "/auth/device-link/approve",
|
|
2527
|
+
authenticated: true,
|
|
2528
|
+
body: { code }
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2451
2531
|
async storeTokensFromRegister(response) {
|
|
2452
2532
|
if (!response.access_token) return;
|
|
2453
2533
|
const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
|