@calimero-network/mero-js 29.4.0 → 29.6.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.cjs CHANGED
@@ -37,6 +37,7 @@ __export(index_exports, {
37
37
  BadOrigin: () => BadOrigin,
38
38
  CalimeroClient: () => CalimeroClient,
39
39
  CalimeroError: () => CalimeroError,
40
+ ClusterNotUpgraded: () => ClusterNotUpgraded,
40
41
  ConfirmCancelled: () => ConfirmCancelled,
41
42
  ConfirmRequired: () => ConfirmRequired,
42
43
  ConsentStale: () => ConsentStale,
@@ -55,6 +56,7 @@ __export(index_exports, {
55
56
  MOCK_QUOTE_HEADER: () => MOCK_QUOTE_HEADER,
56
57
  NODE_RELEASE_SIGNER: () => NODE_RELEASE_SIGNER,
57
58
  NotFound: () => NotFound,
59
+ NotServing: () => NotServing,
58
60
  ORG_CAPABILITIES: () => ORG_CAPABILITIES,
59
61
  OriginNotRegistered: () => OriginNotRegistered,
60
62
  OriginTaken: () => OriginTaken,
@@ -62,6 +64,7 @@ __export(index_exports, {
62
64
  QuotaExceeded: () => QuotaExceeded,
63
65
  RECOVERY_DOMAIN: () => RECOVERY_DOMAIN,
64
66
  RELEASE_VERIFIER: () => RELEASE_VERIFIER,
67
+ RecoveryNotReady: () => RecoveryNotReady,
65
68
  ReleaseDeadlineError: () => ReleaseDeadlineError,
66
69
  SEALED_CONTENT_TYPE: () => SEALED_CONTENT_TYPE,
67
70
  SEALED_PATH: () => SEALED_PATH,
@@ -71,6 +74,7 @@ __export(index_exports, {
71
74
  TrapError: () => TrapError,
72
75
  UnavailableError: () => UnavailableError,
73
76
  WrongNode: () => WrongNode,
77
+ WrongRecoveryCode: () => WrongRecoveryCode,
74
78
  agentKeyBinding: () => agentKeyBinding,
75
79
  agentQuoteVerifier: () => agentQuoteVerifier,
76
80
  attestAgent: () => attestAgent,
@@ -1545,6 +1549,31 @@ var OriginTaken = class extends CalimeroError {
1545
1549
  this.name = "OriginTaken";
1546
1550
  }
1547
1551
  };
1552
+ var NotServing = class extends CalimeroError {
1553
+ constructor(message, details = {}) {
1554
+ super(400, "NOT_SERVING", message, details);
1555
+ this.name = "NotServing";
1556
+ }
1557
+ };
1558
+ var ClusterNotUpgraded = class extends CalimeroError {
1559
+ constructor(message, details = {}) {
1560
+ super(409, "CLUSTER_NOT_UPGRADED", message, details);
1561
+ this.name = "ClusterNotUpgraded";
1562
+ }
1563
+ };
1564
+ var RecoveryNotReady = class extends CalimeroError {
1565
+ constructor(message, details = {}) {
1566
+ super(409, "RECOVERY_NOT_READY", message, details);
1567
+ this.name = "RecoveryNotReady";
1568
+ this.readyAt = typeof details.readyAt === "number" ? details.readyAt : void 0;
1569
+ }
1570
+ };
1571
+ var WrongRecoveryCode = class extends CalimeroError {
1572
+ constructor(message, details = {}) {
1573
+ super(401, "UNAUTHENTICATED", message || "unknown or used recovery code", details);
1574
+ this.name = "WrongRecoveryCode";
1575
+ }
1576
+ };
1548
1577
  var SignUpRefused = class extends CalimeroError {
1549
1578
  constructor(message, details = {}) {
1550
1579
  super(403, "SIGN_UP_REFUSED", message, details);
@@ -1632,8 +1661,14 @@ function errorFrom(status, body, retryAfterHeader) {
1632
1661
  return new BadOrigin(code, message, details);
1633
1662
  case "409 ORIGIN_TAKEN":
1634
1663
  return new OriginTaken(message, details);
1664
+ case "400 NOT_SERVING":
1665
+ return new NotServing(message, details);
1666
+ case "409 CLUSTER_NOT_UPGRADED":
1667
+ return new ClusterNotUpgraded(message, details);
1635
1668
  case "429 QUOTA_EXCEEDED":
1636
1669
  return new QuotaExceeded(message, details);
1670
+ case "409 RECOVERY_NOT_READY":
1671
+ return new RecoveryNotReady(message, details);
1637
1672
  case "403 SIGN_UP_REFUSED":
1638
1673
  return new SignUpRefused(message, details);
1639
1674
  case "412 CONFIRM_REQUIRED":
@@ -1980,8 +2015,9 @@ function retryDelayMs(retry, options) {
1980
2015
  return Math.min(options.baseDelayMs * 2 ** retry, options.maxDelayMs);
1981
2016
  }
1982
2017
  function ceremony(path) {
1983
- return path === "auth/refresh" || path.startsWith("auth/passkey/");
2018
+ return path === "auth/refresh" || path.startsWith("auth/passkey/") || RECOVERY_CEREMONIES.has(path);
1984
2019
  }
2020
+ var RECOVERY_CEREMONIES = /* @__PURE__ */ new Set(["auth/recovery/begin", "auth/recovery/start", "auth/recovery/finish"]);
1985
2021
  var CalimeroClient = class _CalimeroClient {
1986
2022
  constructor(options) {
1987
2023
  /** The one in use: an index into {@link nodeUrls}. */
@@ -2004,7 +2040,13 @@ var CalimeroClient = class _CalimeroClient {
2004
2040
  add: (pkg, origin, passkey, options = {}) => this.confirmed(
2005
2041
  "POST",
2006
2042
  `package-origins/${seg(pkg)}`,
2007
- options.rpId === void 0 ? { origin } : { origin, rpId: options.rpId },
2043
+ // Only the fields set: the node refuses unknown ones, and one that
2044
+ // predates served origins takes a plain add unchanged.
2045
+ {
2046
+ origin,
2047
+ ...options.rpId === void 0 ? {} : { rpId: options.rpId },
2048
+ ...options.served ? { served: true } : {}
2049
+ },
2008
2050
  passkey
2009
2051
  ),
2010
2052
  remove: (pkg, origin, passkey) => this.confirmed("DELETE", `package-origins/${seg(pkg)}`, { origin }, passkey)
@@ -2416,6 +2458,71 @@ var CalimeroClient = class _CalimeroClient {
2416
2458
  async labelPasskey(credentialId, label) {
2417
2459
  await this.post(`auth/passkeys/${seg(credentialId)}`, { label });
2418
2460
  }
2461
+ // ---------------------------------------------------------------- account recovery
2462
+ //
2463
+ // core #4844 (`docs/specs/account-recovery.md`): a recovery code, made with
2464
+ // a passkey and shown once, lets someone who lost every passkey register a
2465
+ // new one; it is added, and the account signed in, 72 hours later unless a
2466
+ // passkey the account still has cancels it first.
2467
+ /**
2468
+ * Make the account's recovery code (replacing any it had), approved with
2469
+ * `passkey` (`412 CONFIRM_REQUIRED`). Answers the code, once: show it to
2470
+ * the person to keep offline; the node keeps only its public key. A passkey
2471
+ * session on the cluster's own origin only (never an API key or a
2472
+ * package-bound session).
2473
+ */
2474
+ async createRecoveryCode(passkey) {
2475
+ const { code } = await this.postConfirmed("auth/recovery", {}, passkey);
2476
+ return code;
2477
+ }
2478
+ /** Remove the account's recovery code, approved with `passkey`. */
2479
+ async removeRecoveryCode(passkey) {
2480
+ await this.deleteConfirmed("auth/recovery", passkey);
2481
+ }
2482
+ /**
2483
+ * Signed out: start recovering the account `code` names. `passkey` makes a
2484
+ * new passkey for it (the browser's create prompt, user verified); the
2485
+ * node spends the code and keeps the passkey as pending. Nothing is added
2486
+ * and no session opens: finish with {@link finishAccountRecovery} at
2487
+ * `readyAt`. A code the cluster does not hold (mistyped, replaced or
2488
+ * spent) is {@link WrongRecoveryCode}; an account with a recovery already
2489
+ * under way `409 RECOVERY_PENDING`.
2490
+ */
2491
+ async startAccountRecovery(code, passkey) {
2492
+ try {
2493
+ const begin = await this.post("auth/recovery/begin", { code });
2494
+ const registration = await passkey.create(begin.options);
2495
+ return await this.post("auth/recovery/start", { challengeId: begin.challengeId, code, registration });
2496
+ } catch (error) {
2497
+ if (error instanceof LoginRequired) throw new WrongRecoveryCode(error.message.replace(/^401 UNAUTHENTICATED: /, ""), error.details);
2498
+ throw error;
2499
+ }
2500
+ }
2501
+ /**
2502
+ * Cancel the recovery of the signed-in account under way, approved with
2503
+ * `passkey` (one the account already has). The code stays spent: make a
2504
+ * new one.
2505
+ */
2506
+ async cancelAccountRecovery(passkey) {
2507
+ await this.postConfirmed("auth/recovery/cancel", {}, passkey);
2508
+ }
2509
+ /**
2510
+ * Signed out, once the delay passed: finish the recovery with the passkey
2511
+ * it registered (`passkey` signs the node's sign-in challenge). The passkey
2512
+ * joins the account, every other session of the account ends, and this
2513
+ * client is signed in. `accountId` (from the start) lets the node refuse
2514
+ * early and offer only that passkey; before `readyAt` it is
2515
+ * {@link RecoveryNotReady}, with no recovery under way {@link NotFound}.
2516
+ */
2517
+ async finishAccountRecovery(passkey, accountId) {
2518
+ const session = await this.postConfirmed(
2519
+ "auth/recovery/finish",
2520
+ accountId ? { accountId } : {},
2521
+ passkey
2522
+ );
2523
+ this.useSession(session);
2524
+ return session;
2525
+ }
2419
2526
  /** What this account uses (apps, bundle bytes, API keys, owned orgs), with the cluster's quotas. */
2420
2527
  usage() {
2421
2528
  return this.get("auth/usage");
@@ -2975,6 +3082,14 @@ var CalimeroClient = class _CalimeroClient {
2975
3082
  opsOrgs(page = {}) {
2976
3083
  return this.get(`ops/orgs${pageQuery(page)}`);
2977
3084
  }
3085
+ /**
3086
+ * `GET /ops/served-origins`: every served origin (custom domain) the
3087
+ * cluster's log holds, with its package's label and no package name or
3088
+ * account. Operator token.
3089
+ */
3090
+ opsServedOrigins() {
3091
+ return this.get("ops/served-origins");
3092
+ }
2978
3093
  /**
2979
3094
  * Announce when work on images older than `version` ends: from `after` on,
2980
3095
  * a scope that has not approved it (or newer) starts no new work. Operator