@spacelr/sdk 0.17.0 → 0.18.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 CHANGED
@@ -336,7 +336,7 @@ interface DeviceLinkInit {
336
336
  }
337
337
  /** Current state of a device link, as polled by the new device (B). */
338
338
  interface DeviceLinkStatus {
339
- state: 'pending' | 'approved' | 'completed';
339
+ state: 'pending' | 'approved' | 'completed' | 'rejected';
340
340
  }
341
341
  /**
342
342
  * Tokens returned by completing a device link (#805 SP2). Same shape as
@@ -1298,6 +1298,27 @@ declare class AuthModule {
1298
1298
  * Poll a device link's current state (new device B). UNAUTHENTICATED.
1299
1299
  */
1300
1300
  pollDeviceLinkStatus(linkToken: string): Promise<DeviceLinkStatus>;
1301
+ /**
1302
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
1303
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
1304
+ * the current state — a returned `pending` just means "call again". Prefer
1305
+ * {@link waitForDeviceLinkApproval}, which loops for you.
1306
+ */
1307
+ waitDeviceLinkStatus(linkToken: string, options?: {
1308
+ signal?: AbortSignal;
1309
+ }): Promise<DeviceLinkStatus>;
1310
+ /**
1311
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
1312
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
1313
+ * with the first non-`pending` state (`approved` → continue with
1314
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
1315
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
1316
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
1317
+ * treated as one more `pending` round, not as a failure.
1318
+ */
1319
+ waitForDeviceLinkApproval(linkToken: string, options?: {
1320
+ signal?: AbortSignal;
1321
+ }): Promise<DeviceLinkStatus>;
1301
1322
  /**
1302
1323
  * Fetch WebAuthn registration options to complete the device link (new
1303
1324
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -1330,6 +1351,13 @@ declare class AuthModule {
1330
1351
  approveDeviceLink(code: string): Promise<{
1331
1352
  approved: true;
1332
1353
  }>;
1354
+ /**
1355
+ * Reject the pending device link (signed-in device A). Authenticated. The new
1356
+ * device sees `rejected` immediately instead of waiting for the link to expire.
1357
+ */
1358
+ rejectDeviceLink(code: string): Promise<{
1359
+ rejected: true;
1360
+ }>;
1333
1361
  private storeTokensFromRegister;
1334
1362
  }
1335
1363
 
package/dist/index.d.ts CHANGED
@@ -336,7 +336,7 @@ interface DeviceLinkInit {
336
336
  }
337
337
  /** Current state of a device link, as polled by the new device (B). */
338
338
  interface DeviceLinkStatus {
339
- state: 'pending' | 'approved' | 'completed';
339
+ state: 'pending' | 'approved' | 'completed' | 'rejected';
340
340
  }
341
341
  /**
342
342
  * Tokens returned by completing a device link (#805 SP2). Same shape as
@@ -1298,6 +1298,27 @@ declare class AuthModule {
1298
1298
  * Poll a device link's current state (new device B). UNAUTHENTICATED.
1299
1299
  */
1300
1300
  pollDeviceLinkStatus(linkToken: string): Promise<DeviceLinkStatus>;
1301
+ /**
1302
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
1303
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
1304
+ * the current state — a returned `pending` just means "call again". Prefer
1305
+ * {@link waitForDeviceLinkApproval}, which loops for you.
1306
+ */
1307
+ waitDeviceLinkStatus(linkToken: string, options?: {
1308
+ signal?: AbortSignal;
1309
+ }): Promise<DeviceLinkStatus>;
1310
+ /**
1311
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
1312
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
1313
+ * with the first non-`pending` state (`approved` → continue with
1314
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
1315
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
1316
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
1317
+ * treated as one more `pending` round, not as a failure.
1318
+ */
1319
+ waitForDeviceLinkApproval(linkToken: string, options?: {
1320
+ signal?: AbortSignal;
1321
+ }): Promise<DeviceLinkStatus>;
1301
1322
  /**
1302
1323
  * Fetch WebAuthn registration options to complete the device link (new
1303
1324
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -1330,6 +1351,13 @@ declare class AuthModule {
1330
1351
  approveDeviceLink(code: string): Promise<{
1331
1352
  approved: true;
1332
1353
  }>;
1354
+ /**
1355
+ * Reject the pending device link (signed-in device A). Authenticated. The new
1356
+ * device sees `rejected` immediately instead of waiting for the link to expire.
1357
+ */
1358
+ rejectDeviceLink(code: string): Promise<{
1359
+ rejected: true;
1360
+ }>;
1333
1361
  private storeTokensFromRegister;
1334
1362
  }
1335
1363
 
package/dist/index.js CHANGED
@@ -2476,6 +2476,45 @@ var AuthModule = class _AuthModule {
2476
2476
  query: { token: linkToken }
2477
2477
  });
2478
2478
  }
2479
+ /**
2480
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
2481
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
2482
+ * the current state — a returned `pending` just means "call again". Prefer
2483
+ * {@link waitForDeviceLinkApproval}, which loops for you.
2484
+ */
2485
+ async waitDeviceLinkStatus(linkToken, options = {}) {
2486
+ return this.http.request({
2487
+ method: "GET",
2488
+ path: "/auth/device-link/wait",
2489
+ query: { token: linkToken },
2490
+ signal: options.signal
2491
+ });
2492
+ }
2493
+ /**
2494
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
2495
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
2496
+ * with the first non-`pending` state (`approved` → continue with
2497
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
2498
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
2499
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
2500
+ * treated as one more `pending` round, not as a failure.
2501
+ */
2502
+ async waitForDeviceLinkApproval(linkToken, options = {}) {
2503
+ const minRoundMs = 1e3;
2504
+ for (; ; ) {
2505
+ const startedAt = Date.now();
2506
+ try {
2507
+ const status = await this.waitDeviceLinkStatus(linkToken, options);
2508
+ if (status.state !== "pending") return status;
2509
+ } catch (error) {
2510
+ if (!(error instanceof SpacelrTimeoutError)) throw error;
2511
+ }
2512
+ const remainingMs = minRoundMs - (Date.now() - startedAt);
2513
+ if (remainingMs > 0) {
2514
+ await new Promise((resolve) => setTimeout(resolve, remainingMs));
2515
+ }
2516
+ }
2517
+ }
2479
2518
  /**
2480
2519
  * Fetch WebAuthn registration options to complete the device link (new
2481
2520
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -2528,6 +2567,18 @@ var AuthModule = class _AuthModule {
2528
2567
  body: { code }
2529
2568
  });
2530
2569
  }
2570
+ /**
2571
+ * Reject the pending device link (signed-in device A). Authenticated. The new
2572
+ * device sees `rejected` immediately instead of waiting for the link to expire.
2573
+ */
2574
+ async rejectDeviceLink(code) {
2575
+ return this.http.request({
2576
+ method: "POST",
2577
+ path: "/auth/device-link/reject",
2578
+ authenticated: true,
2579
+ body: { code }
2580
+ });
2581
+ }
2531
2582
  async storeTokensFromRegister(response) {
2532
2583
  if (!response.access_token) return;
2533
2584
  const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;