@spacelr/sdk 0.17.0 → 0.18.1

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
@@ -1116,8 +1116,18 @@ declare class AuthModule {
1116
1116
  refresh(refreshToken: string): Promise<TokenResponse>;
1117
1117
  getProfile(): Promise<UserProfile>;
1118
1118
  logout(): Promise<void>;
1119
+ /**
1120
+ * Verify an email address with the token from the verification email.
1121
+ *
1122
+ * The token is sent in the request BODY, never the URL (#941): a query
1123
+ * string reaches server, proxy and CDN logs. When the project mints one, the
1124
+ * response carries a one-time `loginCode`; pass it to `exchangeCode` to sign
1125
+ * the user in.
1126
+ */
1119
1127
  verifyEmail(token: string): Promise<{
1120
1128
  message: string;
1129
+ valid: boolean;
1130
+ loginCode?: string;
1121
1131
  }>;
1122
1132
  resendVerification(email: string): Promise<{
1123
1133
  message: string;
@@ -1212,6 +1222,11 @@ declare class AuthModule {
1212
1222
  /**
1213
1223
  * Fetch WebAuthn attestation options to register a new passkey for the
1214
1224
  * currently authenticated user.
1225
+ *
1226
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
1227
+ * server answers 401 `STALE_SESSION` and this throws
1228
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
1229
+ * A token refresh does not help.
1215
1230
  */
1216
1231
  beginPasskeyRegistration(): Promise<PasskeyRegistrationOptionsJSON>;
1217
1232
  /**
@@ -1219,6 +1234,11 @@ declare class AuthModule {
1219
1234
  * against the options returned by `beginPasskeyRegistration()`, saving the
1220
1235
  * new credential under the current user. This does not issue tokens or
1221
1236
  * change auth state — the caller is already authenticated.
1237
+ *
1238
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
1239
+ * server answers 401 `STALE_SESSION` and this throws
1240
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
1241
+ * A token refresh does not help.
1222
1242
  */
1223
1243
  verifyPasskeyRegistration(response: PasskeyRegistrationResponseJSON, label?: string): Promise<PasskeyRegistrationResult>;
1224
1244
  /**
@@ -1298,6 +1318,27 @@ declare class AuthModule {
1298
1318
  * Poll a device link's current state (new device B). UNAUTHENTICATED.
1299
1319
  */
1300
1320
  pollDeviceLinkStatus(linkToken: string): Promise<DeviceLinkStatus>;
1321
+ /**
1322
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
1323
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
1324
+ * the current state — a returned `pending` just means "call again". Prefer
1325
+ * {@link waitForDeviceLinkApproval}, which loops for you.
1326
+ */
1327
+ waitDeviceLinkStatus(linkToken: string, options?: {
1328
+ signal?: AbortSignal;
1329
+ }): Promise<DeviceLinkStatus>;
1330
+ /**
1331
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
1332
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
1333
+ * with the first non-`pending` state (`approved` → continue with
1334
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
1335
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
1336
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
1337
+ * treated as one more `pending` round, not as a failure.
1338
+ */
1339
+ waitForDeviceLinkApproval(linkToken: string, options?: {
1340
+ signal?: AbortSignal;
1341
+ }): Promise<DeviceLinkStatus>;
1301
1342
  /**
1302
1343
  * Fetch WebAuthn registration options to complete the device link (new
1303
1344
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -1326,10 +1367,22 @@ declare class AuthModule {
1326
1367
  /**
1327
1368
  * Approve the pending device link (signed-in device A). Authenticated.
1328
1369
  * Ownership/identity are derived server-side from the JWT.
1370
+ *
1371
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
1372
+ * server answers 401 `STALE_SESSION` and this throws
1373
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
1374
+ * A token refresh does not help.
1329
1375
  */
1330
1376
  approveDeviceLink(code: string): Promise<{
1331
1377
  approved: true;
1332
1378
  }>;
1379
+ /**
1380
+ * Reject the pending device link (signed-in device A). Authenticated. The new
1381
+ * device sees `rejected` immediately instead of waiting for the link to expire.
1382
+ */
1383
+ rejectDeviceLink(code: string): Promise<{
1384
+ rejected: true;
1385
+ }>;
1333
1386
  private storeTokensFromRegister;
1334
1387
  }
1335
1388
 
@@ -2361,4 +2414,4 @@ interface SpacelrClient {
2361
2414
  }
2362
2415
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2363
2416
 
2364
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrStepUpRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
2417
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DeviceLinkCompleteResponse, type DeviceLinkInit, type DeviceLinkStatus, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PasskeySignupResponse, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type SessionSummary, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrStepUpRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
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
@@ -1116,8 +1116,18 @@ declare class AuthModule {
1116
1116
  refresh(refreshToken: string): Promise<TokenResponse>;
1117
1117
  getProfile(): Promise<UserProfile>;
1118
1118
  logout(): Promise<void>;
1119
+ /**
1120
+ * Verify an email address with the token from the verification email.
1121
+ *
1122
+ * The token is sent in the request BODY, never the URL (#941): a query
1123
+ * string reaches server, proxy and CDN logs. When the project mints one, the
1124
+ * response carries a one-time `loginCode`; pass it to `exchangeCode` to sign
1125
+ * the user in.
1126
+ */
1119
1127
  verifyEmail(token: string): Promise<{
1120
1128
  message: string;
1129
+ valid: boolean;
1130
+ loginCode?: string;
1121
1131
  }>;
1122
1132
  resendVerification(email: string): Promise<{
1123
1133
  message: string;
@@ -1212,6 +1222,11 @@ declare class AuthModule {
1212
1222
  /**
1213
1223
  * Fetch WebAuthn attestation options to register a new passkey for the
1214
1224
  * currently authenticated user.
1225
+ *
1226
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
1227
+ * server answers 401 `STALE_SESSION` and this throws
1228
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
1229
+ * A token refresh does not help.
1215
1230
  */
1216
1231
  beginPasskeyRegistration(): Promise<PasskeyRegistrationOptionsJSON>;
1217
1232
  /**
@@ -1219,6 +1234,11 @@ declare class AuthModule {
1219
1234
  * against the options returned by `beginPasskeyRegistration()`, saving the
1220
1235
  * new credential under the current user. This does not issue tokens or
1221
1236
  * change auth state — the caller is already authenticated.
1237
+ *
1238
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
1239
+ * server answers 401 `STALE_SESSION` and this throws
1240
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
1241
+ * A token refresh does not help.
1222
1242
  */
1223
1243
  verifyPasskeyRegistration(response: PasskeyRegistrationResponseJSON, label?: string): Promise<PasskeyRegistrationResult>;
1224
1244
  /**
@@ -1298,6 +1318,27 @@ declare class AuthModule {
1298
1318
  * Poll a device link's current state (new device B). UNAUTHENTICATED.
1299
1319
  */
1300
1320
  pollDeviceLinkStatus(linkToken: string): Promise<DeviceLinkStatus>;
1321
+ /**
1322
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
1323
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
1324
+ * the current state — a returned `pending` just means "call again". Prefer
1325
+ * {@link waitForDeviceLinkApproval}, which loops for you.
1326
+ */
1327
+ waitDeviceLinkStatus(linkToken: string, options?: {
1328
+ signal?: AbortSignal;
1329
+ }): Promise<DeviceLinkStatus>;
1330
+ /**
1331
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
1332
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
1333
+ * with the first non-`pending` state (`approved` → continue with
1334
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
1335
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
1336
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
1337
+ * treated as one more `pending` round, not as a failure.
1338
+ */
1339
+ waitForDeviceLinkApproval(linkToken: string, options?: {
1340
+ signal?: AbortSignal;
1341
+ }): Promise<DeviceLinkStatus>;
1301
1342
  /**
1302
1343
  * Fetch WebAuthn registration options to complete the device link (new
1303
1344
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -1326,10 +1367,22 @@ declare class AuthModule {
1326
1367
  /**
1327
1368
  * Approve the pending device link (signed-in device A). Authenticated.
1328
1369
  * Ownership/identity are derived server-side from the JWT.
1370
+ *
1371
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
1372
+ * server answers 401 `STALE_SESSION` and this throws
1373
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
1374
+ * A token refresh does not help.
1329
1375
  */
1330
1376
  approveDeviceLink(code: string): Promise<{
1331
1377
  approved: true;
1332
1378
  }>;
1379
+ /**
1380
+ * Reject the pending device link (signed-in device A). Authenticated. The new
1381
+ * device sees `rejected` immediately instead of waiting for the link to expire.
1382
+ */
1383
+ rejectDeviceLink(code: string): Promise<{
1384
+ rejected: true;
1385
+ }>;
1333
1386
  private storeTokensFromRegister;
1334
1387
  }
1335
1388
 
@@ -2361,4 +2414,4 @@ interface SpacelrClient {
2361
2414
  }
2362
2415
  declare function createClient(config: SpacelrClientConfig): SpacelrClient;
2363
2416
 
2364
- export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrStepUpRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
2417
+ export { type ApiResponse, type AuthLostReason, type AuthState, type AuthStateListener, type AuthorizationUrlParams, BrowserTokenStorage, CONSUMER_ID_STORAGE_KEY, CodeChallengeMethod, type ConnectionState, CursorInvalidError, type CursorStorage, type DatabaseChangeEvent, type DeviceLinkCompleteResponse, type DeviceLinkInit, type DeviceLinkStatus, type DownloadUrlResponse, type ExchangeCodeParams, type FileInfo, type FileListResponse, FileVisibility, ForbiddenError, type FunctionInvokeOptions, type FunctionInvokeResult, type GapReason, GrantType, type InitMultipartUploadParams, type InitMultipartUploadResponse, type JWK, type JWKSResponse, type ListFilesParams, type LoginParams, type LoginResponse, MemoryTokenStorage, NotFoundError, type OpenIDConfiguration, type PKCEChallenge, type PartEtag, type PasskeyAuthenticationOptionsJSON, type PasskeyAuthenticationResponseJSON, type PasskeyCredential, type PasskeyCredentialDescriptorJSON, type PasskeyLoginResponse, type PasskeyRegistrationOptionsJSON, type PasskeyRegistrationResponseJSON, type PasskeyRegistrationResult, type PasskeySignupResponse, type PushSubscriptionInfo, type QuotaInfo, type RecoveryRedeemResponse, type RecoveryStatusResponse, type RegisterParams, type RegisterResponse, type Schedule, type ScheduleInvokeOptions, type ScheduleListOptions, type ScheduleStatus, type SearchOptions, ServerConfigError, type SessionSummary, type ShareFileParams, SharePermission, SpacelrAuthError, type SpacelrClient, type SpacelrClientConfig, SpacelrEmailVerificationRequiredError, SpacelrError, SpacelrNetworkError, SpacelrScanLimitExceededError, SpacelrSearchFilterRequiredError, SpacelrStepUpRequiredError, SpacelrTimeoutError, SpacelrTwoFactorRequiredError, type StoredTokens, type StreamGapInfo, type StreamSubscription, type SubscribeEventsHandlers, type SubscribeHandlers, type SubscribeWithSnapshotOptions, type TimelineAndFilter, TimelineError, type TimelineFieldFilter, type TimelineFilter, type TimelineLeafFilter, TimelineModule, type TimelineOrderBy, type TimelineQueryOptions, type TimelineQueryResponse, type TimelineScalar, type TimelineSourceStats, TimeoutError, type TokenResponse, type TokenStorage, type TwoFactorResponse, type TwoFactorVerifyParams, type UnshareFileParams, type UploadFileParams, type UploadLargeFileParams, type UploadProgress, type UserInfo, type UserProfile, ValidationError, type VapidKeyResponse, type WhereFilter, type WhereOperator, type WhereScalar, type WhereValue, createClient, generatePKCEChallenge, localStorageCursorStorage, memoryCursorStorage, resolveConsumerId };
package/dist/index.js CHANGED
@@ -2046,11 +2046,19 @@ var AuthModule = class _AuthModule {
2046
2046
  await this.tokenManager.clearTokens();
2047
2047
  this.emitState("unauthenticated");
2048
2048
  }
2049
+ /**
2050
+ * Verify an email address with the token from the verification email.
2051
+ *
2052
+ * The token is sent in the request BODY, never the URL (#941): a query
2053
+ * string reaches server, proxy and CDN logs. When the project mints one, the
2054
+ * response carries a one-time `loginCode`; pass it to `exchangeCode` to sign
2055
+ * the user in.
2056
+ */
2049
2057
  async verifyEmail(token) {
2050
2058
  return this.http.request({
2051
- method: "GET",
2059
+ method: "POST",
2052
2060
  path: "/auth/verify-email",
2053
- query: { token }
2061
+ body: { token }
2054
2062
  });
2055
2063
  }
2056
2064
  async resendVerification(email) {
@@ -2295,6 +2303,11 @@ var AuthModule = class _AuthModule {
2295
2303
  /**
2296
2304
  * Fetch WebAuthn attestation options to register a new passkey for the
2297
2305
  * currently authenticated user.
2306
+ *
2307
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
2308
+ * server answers 401 `STALE_SESSION` and this throws
2309
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
2310
+ * A token refresh does not help.
2298
2311
  */
2299
2312
  async beginPasskeyRegistration() {
2300
2313
  return this.http.request({
@@ -2309,6 +2322,11 @@ var AuthModule = class _AuthModule {
2309
2322
  * against the options returned by `beginPasskeyRegistration()`, saving the
2310
2323
  * new credential under the current user. This does not issue tokens or
2311
2324
  * change auth state — the caller is already authenticated.
2325
+ *
2326
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
2327
+ * server answers 401 `STALE_SESSION` and this throws
2328
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
2329
+ * A token refresh does not help.
2312
2330
  */
2313
2331
  async verifyPasskeyRegistration(response, label) {
2314
2332
  return this.http.request({
@@ -2476,6 +2494,45 @@ var AuthModule = class _AuthModule {
2476
2494
  query: { token: linkToken }
2477
2495
  });
2478
2496
  }
2497
+ /**
2498
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
2499
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
2500
+ * the current state — a returned `pending` just means "call again". Prefer
2501
+ * {@link waitForDeviceLinkApproval}, which loops for you.
2502
+ */
2503
+ async waitDeviceLinkStatus(linkToken, options = {}) {
2504
+ return this.http.request({
2505
+ method: "GET",
2506
+ path: "/auth/device-link/wait",
2507
+ query: { token: linkToken },
2508
+ signal: options.signal
2509
+ });
2510
+ }
2511
+ /**
2512
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
2513
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
2514
+ * with the first non-`pending` state (`approved` → continue with
2515
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
2516
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
2517
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
2518
+ * treated as one more `pending` round, not as a failure.
2519
+ */
2520
+ async waitForDeviceLinkApproval(linkToken, options = {}) {
2521
+ const minRoundMs = 1e3;
2522
+ for (; ; ) {
2523
+ const startedAt = Date.now();
2524
+ try {
2525
+ const status = await this.waitDeviceLinkStatus(linkToken, options);
2526
+ if (status.state !== "pending") return status;
2527
+ } catch (error) {
2528
+ if (!(error instanceof SpacelrTimeoutError)) throw error;
2529
+ }
2530
+ const remainingMs = minRoundMs - (Date.now() - startedAt);
2531
+ if (remainingMs > 0) {
2532
+ await new Promise((resolve) => setTimeout(resolve, remainingMs));
2533
+ }
2534
+ }
2535
+ }
2479
2536
  /**
2480
2537
  * Fetch WebAuthn registration options to complete the device link (new
2481
2538
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -2519,6 +2576,11 @@ var AuthModule = class _AuthModule {
2519
2576
  /**
2520
2577
  * Approve the pending device link (signed-in device A). Authenticated.
2521
2578
  * Ownership/identity are derived server-side from the JWT.
2579
+ *
2580
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
2581
+ * server answers 401 `STALE_SESSION` and this throws
2582
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
2583
+ * A token refresh does not help.
2522
2584
  */
2523
2585
  async approveDeviceLink(code) {
2524
2586
  return this.http.request({
@@ -2528,6 +2590,18 @@ var AuthModule = class _AuthModule {
2528
2590
  body: { code }
2529
2591
  });
2530
2592
  }
2593
+ /**
2594
+ * Reject the pending device link (signed-in device A). Authenticated. The new
2595
+ * device sees `rejected` immediately instead of waiting for the link to expire.
2596
+ */
2597
+ async rejectDeviceLink(code) {
2598
+ return this.http.request({
2599
+ method: "POST",
2600
+ path: "/auth/device-link/reject",
2601
+ authenticated: true,
2602
+ body: { code }
2603
+ });
2604
+ }
2531
2605
  async storeTokensFromRegister(response) {
2532
2606
  if (!response.access_token) return;
2533
2607
  const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;