@spacelr/sdk 0.7.0 → 0.8.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
@@ -115,7 +115,7 @@ var HttpClient = class {
115
115
  });
116
116
  const responseBody = await this.parseResponse(response);
117
117
  if (!response.ok) {
118
- if (options.authenticated && response.status === 401) {
118
+ if (options.authenticated && response.status === 401 && !options.skipAuthRefresh) {
119
119
  if (await this.recoverFromAuthFailure(isRetry)) {
120
120
  return this.requestWithRetry(options, true);
121
121
  }
@@ -1395,7 +1395,11 @@ var AuthModule = class {
1395
1395
  await this.http.request({
1396
1396
  method: "POST",
1397
1397
  path: "/auth/logout",
1398
- authenticated: true
1398
+ authenticated: true,
1399
+ // A 401 here means the session is already gone — do not trigger the
1400
+ // refresh/auth-lost recovery, or an auth-lost handler that calls
1401
+ // logout would recurse into an endless 401 loop.
1402
+ skipAuthRefresh: true
1399
1403
  });
1400
1404
  } catch {
1401
1405
  }
@@ -1547,6 +1551,88 @@ var AuthModule = class {
1547
1551
  await this.storeTokensFromLogin(response);
1548
1552
  return response;
1549
1553
  }
1554
+ /**
1555
+ * Fetch WebAuthn assertion options to start a passkey login.
1556
+ * Pass `email` to scope the challenge to a known user's registered
1557
+ * credentials; omit it for a discoverable-credential (usernameless) flow.
1558
+ */
1559
+ async beginPasskeyLogin(email) {
1560
+ return this.http.request({
1561
+ method: "POST",
1562
+ path: "/auth/passkey/login/options",
1563
+ body: email ? { email } : {}
1564
+ });
1565
+ }
1566
+ /**
1567
+ * Verify a WebAuthn assertion produced by `navigator.credentials.get()`
1568
+ * against the options returned by `beginPasskeyLogin()`, completing login.
1569
+ */
1570
+ async verifyPasskeyLogin(response) {
1571
+ const result = await this.http.request({
1572
+ method: "POST",
1573
+ path: "/auth/passkey/login/verify",
1574
+ body: { response }
1575
+ });
1576
+ await this.storeTokensFromLogin(result);
1577
+ return result;
1578
+ }
1579
+ /**
1580
+ * Fetch WebAuthn attestation options to register a new passkey for the
1581
+ * currently authenticated user.
1582
+ */
1583
+ async beginPasskeyRegistration() {
1584
+ return this.http.request({
1585
+ method: "POST",
1586
+ path: "/auth/passkey/register/options",
1587
+ authenticated: true,
1588
+ body: {}
1589
+ });
1590
+ }
1591
+ /**
1592
+ * Verify a WebAuthn attestation produced by `navigator.credentials.create()`
1593
+ * against the options returned by `beginPasskeyRegistration()`, saving the
1594
+ * new credential under the current user. This does not issue tokens or
1595
+ * change auth state — the caller is already authenticated.
1596
+ */
1597
+ async verifyPasskeyRegistration(response, label) {
1598
+ return this.http.request({
1599
+ method: "POST",
1600
+ path: "/auth/passkey/register/verify",
1601
+ authenticated: true,
1602
+ body: { response, label }
1603
+ });
1604
+ }
1605
+ /**
1606
+ * List the WebAuthn passkey credentials registered for the current user.
1607
+ */
1608
+ async listPasskeys() {
1609
+ return this.http.request({
1610
+ method: "GET",
1611
+ path: "/auth/passkey/credentials",
1612
+ authenticated: true
1613
+ });
1614
+ }
1615
+ /**
1616
+ * Rename a registered passkey credential (e.g. "My Laptop").
1617
+ */
1618
+ async renamePasskey(credentialId, label) {
1619
+ return this.http.request({
1620
+ method: "PATCH",
1621
+ path: `/auth/passkey/credentials/${encodeURIComponent(credentialId)}`,
1622
+ authenticated: true,
1623
+ body: { label }
1624
+ });
1625
+ }
1626
+ /**
1627
+ * Delete a registered passkey credential.
1628
+ */
1629
+ async deletePasskey(credentialId) {
1630
+ return this.http.request({
1631
+ method: "DELETE",
1632
+ path: `/auth/passkey/credentials/${encodeURIComponent(credentialId)}`,
1633
+ authenticated: true
1634
+ });
1635
+ }
1550
1636
  async storeTokensFromLogin(response) {
1551
1637
  const expiresAt = response.expires_in ? Math.floor(Date.now() / 1e3) + response.expires_in : void 0;
1552
1638
  await this.tokenManager.setTokens({