@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.mjs CHANGED
@@ -1999,11 +1999,19 @@ var AuthModule = class _AuthModule {
1999
1999
  await this.tokenManager.clearTokens();
2000
2000
  this.emitState("unauthenticated");
2001
2001
  }
2002
+ /**
2003
+ * Verify an email address with the token from the verification email.
2004
+ *
2005
+ * The token is sent in the request BODY, never the URL (#941): a query
2006
+ * string reaches server, proxy and CDN logs. When the project mints one, the
2007
+ * response carries a one-time `loginCode`; pass it to `exchangeCode` to sign
2008
+ * the user in.
2009
+ */
2002
2010
  async verifyEmail(token) {
2003
2011
  return this.http.request({
2004
- method: "GET",
2012
+ method: "POST",
2005
2013
  path: "/auth/verify-email",
2006
- query: { token }
2014
+ body: { token }
2007
2015
  });
2008
2016
  }
2009
2017
  async resendVerification(email) {
@@ -2248,6 +2256,11 @@ var AuthModule = class _AuthModule {
2248
2256
  /**
2249
2257
  * Fetch WebAuthn attestation options to register a new passkey for the
2250
2258
  * currently authenticated user.
2259
+ *
2260
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
2261
+ * server answers 401 `STALE_SESSION` and this throws
2262
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
2263
+ * A token refresh does not help.
2251
2264
  */
2252
2265
  async beginPasskeyRegistration() {
2253
2266
  return this.http.request({
@@ -2262,6 +2275,11 @@ var AuthModule = class _AuthModule {
2262
2275
  * against the options returned by `beginPasskeyRegistration()`, saving the
2263
2276
  * new credential under the current user. This does not issue tokens or
2264
2277
  * change auth state — the caller is already authenticated.
2278
+ *
2279
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
2280
+ * server answers 401 `STALE_SESSION` and this throws
2281
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
2282
+ * A token refresh does not help.
2265
2283
  */
2266
2284
  async verifyPasskeyRegistration(response, label) {
2267
2285
  return this.http.request({
@@ -2429,6 +2447,45 @@ var AuthModule = class _AuthModule {
2429
2447
  query: { token: linkToken }
2430
2448
  });
2431
2449
  }
2450
+ /**
2451
+ * Long-poll a device link once (new device B). UNAUTHENTICATED. The server
2452
+ * holds the request until the link leaves `pending` or ~25s pass, then returns
2453
+ * the current state — a returned `pending` just means "call again". Prefer
2454
+ * {@link waitForDeviceLinkApproval}, which loops for you.
2455
+ */
2456
+ async waitDeviceLinkStatus(linkToken, options = {}) {
2457
+ return this.http.request({
2458
+ method: "GET",
2459
+ path: "/auth/device-link/wait",
2460
+ query: { token: linkToken },
2461
+ signal: options.signal
2462
+ });
2463
+ }
2464
+ /**
2465
+ * Wait until the signed-in device decides (new device B). UNAUTHENTICATED.
2466
+ * Replaces a hand-written poll loop on {@link pollDeviceLinkStatus}: resolves
2467
+ * with the first non-`pending` state (`approved` → continue with
2468
+ * {@link getDeviceLinkOptions}; `rejected` → start over). Rejects when the link
2469
+ * expires (404 after its ~5 min TTL), on a throttle (429), or when `signal`
2470
+ * aborts. A client-side request timeout shorter than the server's ~25s hold is
2471
+ * treated as one more `pending` round, not as a failure.
2472
+ */
2473
+ async waitForDeviceLinkApproval(linkToken, options = {}) {
2474
+ const minRoundMs = 1e3;
2475
+ for (; ; ) {
2476
+ const startedAt = Date.now();
2477
+ try {
2478
+ const status = await this.waitDeviceLinkStatus(linkToken, options);
2479
+ if (status.state !== "pending") return status;
2480
+ } catch (error) {
2481
+ if (!(error instanceof SpacelrTimeoutError)) throw error;
2482
+ }
2483
+ const remainingMs = minRoundMs - (Date.now() - startedAt);
2484
+ if (remainingMs > 0) {
2485
+ await new Promise((resolve) => setTimeout(resolve, remainingMs));
2486
+ }
2487
+ }
2488
+ }
2432
2489
  /**
2433
2490
  * Fetch WebAuthn registration options to complete the device link (new
2434
2491
  * device B). UNAUTHENTICATED — requires BOTH the displayed `linkToken` AND
@@ -2472,6 +2529,11 @@ var AuthModule = class _AuthModule {
2472
2529
  /**
2473
2530
  * Approve the pending device link (signed-in device A). Authenticated.
2474
2531
  * Ownership/identity are derived server-side from the JWT.
2532
+ *
2533
+ * Requires a recent interactive login (within 5 minutes). Otherwise the
2534
+ * server answers 401 `STALE_SESSION` and this throws
2535
+ * {@link SpacelrStepUpRequiredError}: sign the user in again, then retry.
2536
+ * A token refresh does not help.
2475
2537
  */
2476
2538
  async approveDeviceLink(code) {
2477
2539
  return this.http.request({
@@ -2481,6 +2543,18 @@ var AuthModule = class _AuthModule {
2481
2543
  body: { code }
2482
2544
  });
2483
2545
  }
2546
+ /**
2547
+ * Reject the pending device link (signed-in device A). Authenticated. The new
2548
+ * device sees `rejected` immediately instead of waiting for the link to expire.
2549
+ */
2550
+ async rejectDeviceLink(code) {
2551
+ return this.http.request({
2552
+ method: "POST",
2553
+ path: "/auth/device-link/reject",
2554
+ authenticated: true,
2555
+ body: { code }
2556
+ });
2557
+ }
2484
2558
  async storeTokensFromRegister(response) {
2485
2559
  if (!response.access_token) return;
2486
2560
  const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;