@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.d.mts
CHANGED
|
@@ -307,6 +307,52 @@ interface PasskeyCredential {
|
|
|
307
307
|
createdAt: string;
|
|
308
308
|
lastUsedAt?: string;
|
|
309
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* A single active session, as returned by the session-list endpoint (#805).
|
|
312
|
+
* `current` marks the session tied to the caller's own access token.
|
|
313
|
+
*/
|
|
314
|
+
interface SessionSummary {
|
|
315
|
+
sessionId: string;
|
|
316
|
+
current: boolean;
|
|
317
|
+
clientId: string;
|
|
318
|
+
credentialId?: string;
|
|
319
|
+
userAgent?: string;
|
|
320
|
+
ip?: string;
|
|
321
|
+
country?: string;
|
|
322
|
+
createdAt: string;
|
|
323
|
+
lastSeenAt: string;
|
|
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
|
+
}
|
|
310
356
|
|
|
311
357
|
interface TokenStorage {
|
|
312
358
|
getTokens(): Promise<StoredTokens | null>;
|
|
@@ -1222,6 +1268,68 @@ declare class AuthModule {
|
|
|
1222
1268
|
* their recovery phrase. Authenticated.
|
|
1223
1269
|
*/
|
|
1224
1270
|
getRecoveryStatus(): Promise<RecoveryStatusResponse>;
|
|
1271
|
+
/**
|
|
1272
|
+
* List the active sessions for the signed-in user. Each entry is flagged
|
|
1273
|
+
* `current` when it corresponds to the caller's own access token.
|
|
1274
|
+
*/
|
|
1275
|
+
listSessions(): Promise<SessionSummary[]>;
|
|
1276
|
+
/**
|
|
1277
|
+
* Revoke a single session by id, signing it out. The server refuses to
|
|
1278
|
+
* revoke the caller's own current session through this endpoint.
|
|
1279
|
+
*/
|
|
1280
|
+
revokeSession(sessionId: string): Promise<{
|
|
1281
|
+
revoked: true;
|
|
1282
|
+
}>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Sign out every other active session for the current user, keeping the
|
|
1285
|
+
* caller's own session intact.
|
|
1286
|
+
*/
|
|
1287
|
+
signOutOtherSessions(): Promise<{
|
|
1288
|
+
revokedCount: number;
|
|
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
|
+
}>;
|
|
1225
1333
|
private storeTokensFromRegister;
|
|
1226
1334
|
}
|
|
1227
1335
|
|
package/dist/index.d.ts
CHANGED
|
@@ -307,6 +307,52 @@ interface PasskeyCredential {
|
|
|
307
307
|
createdAt: string;
|
|
308
308
|
lastUsedAt?: string;
|
|
309
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* A single active session, as returned by the session-list endpoint (#805).
|
|
312
|
+
* `current` marks the session tied to the caller's own access token.
|
|
313
|
+
*/
|
|
314
|
+
interface SessionSummary {
|
|
315
|
+
sessionId: string;
|
|
316
|
+
current: boolean;
|
|
317
|
+
clientId: string;
|
|
318
|
+
credentialId?: string;
|
|
319
|
+
userAgent?: string;
|
|
320
|
+
ip?: string;
|
|
321
|
+
country?: string;
|
|
322
|
+
createdAt: string;
|
|
323
|
+
lastSeenAt: string;
|
|
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
|
+
}
|
|
310
356
|
|
|
311
357
|
interface TokenStorage {
|
|
312
358
|
getTokens(): Promise<StoredTokens | null>;
|
|
@@ -1222,6 +1268,68 @@ declare class AuthModule {
|
|
|
1222
1268
|
* their recovery phrase. Authenticated.
|
|
1223
1269
|
*/
|
|
1224
1270
|
getRecoveryStatus(): Promise<RecoveryStatusResponse>;
|
|
1271
|
+
/**
|
|
1272
|
+
* List the active sessions for the signed-in user. Each entry is flagged
|
|
1273
|
+
* `current` when it corresponds to the caller's own access token.
|
|
1274
|
+
*/
|
|
1275
|
+
listSessions(): Promise<SessionSummary[]>;
|
|
1276
|
+
/**
|
|
1277
|
+
* Revoke a single session by id, signing it out. The server refuses to
|
|
1278
|
+
* revoke the caller's own current session through this endpoint.
|
|
1279
|
+
*/
|
|
1280
|
+
revokeSession(sessionId: string): Promise<{
|
|
1281
|
+
revoked: true;
|
|
1282
|
+
}>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Sign out every other active session for the current user, keeping the
|
|
1285
|
+
* caller's own session intact.
|
|
1286
|
+
*/
|
|
1287
|
+
signOutOtherSessions(): Promise<{
|
|
1288
|
+
revokedCount: number;
|
|
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
|
+
}>;
|
|
1225
1333
|
private storeTokensFromRegister;
|
|
1226
1334
|
}
|
|
1227
1335
|
|
package/dist/index.js
CHANGED
|
@@ -2412,6 +2412,122 @@ var AuthModule = class _AuthModule {
|
|
|
2412
2412
|
authenticated: true
|
|
2413
2413
|
});
|
|
2414
2414
|
}
|
|
2415
|
+
// ─── Session management (#805 SP1) ───
|
|
2416
|
+
/**
|
|
2417
|
+
* List the active sessions for the signed-in user. Each entry is flagged
|
|
2418
|
+
* `current` when it corresponds to the caller's own access token.
|
|
2419
|
+
*/
|
|
2420
|
+
async listSessions() {
|
|
2421
|
+
const { sessions } = await this.http.request({
|
|
2422
|
+
method: "GET",
|
|
2423
|
+
path: "/auth/sessions",
|
|
2424
|
+
authenticated: true
|
|
2425
|
+
});
|
|
2426
|
+
return sessions;
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Revoke a single session by id, signing it out. The server refuses to
|
|
2430
|
+
* revoke the caller's own current session through this endpoint.
|
|
2431
|
+
*/
|
|
2432
|
+
async revokeSession(sessionId) {
|
|
2433
|
+
return this.http.request({
|
|
2434
|
+
method: "DELETE",
|
|
2435
|
+
path: `/auth/sessions/${encodeURIComponent(sessionId)}`,
|
|
2436
|
+
authenticated: true
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Sign out every other active session for the current user, keeping the
|
|
2441
|
+
* caller's own session intact.
|
|
2442
|
+
*/
|
|
2443
|
+
async signOutOtherSessions() {
|
|
2444
|
+
return this.http.request({
|
|
2445
|
+
method: "POST",
|
|
2446
|
+
path: "/auth/sessions/revoke-others",
|
|
2447
|
+
authenticated: true,
|
|
2448
|
+
body: {}
|
|
2449
|
+
});
|
|
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
|
+
}
|
|
2415
2531
|
async storeTokensFromRegister(response) {
|
|
2416
2532
|
if (!response.access_token) return;
|
|
2417
2533
|
const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
|