@calimero-network/mero-js 29.1.0 → 29.3.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.mjs CHANGED
@@ -1418,6 +1418,21 @@ var OriginTaken = class extends CalimeroError {
1418
1418
  this.name = "OriginTaken";
1419
1419
  }
1420
1420
  };
1421
+ var SignUpRefused = class extends CalimeroError {
1422
+ constructor(message, details = {}) {
1423
+ super(403, "SIGN_UP_REFUSED", message, details);
1424
+ this.name = "SignUpRefused";
1425
+ this.reason = signUpRefusal(message);
1426
+ }
1427
+ };
1428
+ function signUpRefusal(message) {
1429
+ if (/invite only/.test(message)) return "invite-only";
1430
+ if (/pre-authorized|sign-up invite/.test(message)) return "closed";
1431
+ if (/unknown invite/.test(message)) return "unknown-invite";
1432
+ if (/invite has expired/.test(message)) return "expired-invite";
1433
+ if (/organization is gone/.test(message)) return "org-gone";
1434
+ return "other";
1435
+ }
1421
1436
  var QuotaExceeded = class extends CalimeroError {
1422
1437
  constructor(message, details = {}) {
1423
1438
  super(429, "QUOTA_EXCEEDED", message, details);
@@ -1492,6 +1507,8 @@ function errorFrom(status, body, retryAfterHeader) {
1492
1507
  return new OriginTaken(message, details);
1493
1508
  case "429 QUOTA_EXCEEDED":
1494
1509
  return new QuotaExceeded(message, details);
1510
+ case "403 SIGN_UP_REFUSED":
1511
+ return new SignUpRefused(message, details);
1495
1512
  case "412 CONFIRM_REQUIRED":
1496
1513
  return new ConfirmRequired(message, details);
1497
1514
  case "413 ARGS_TOO_LARGE":
@@ -2060,23 +2077,33 @@ var CalimeroClient = class _CalimeroClient {
2060
2077
  * origin's relying party (the confirmation's `rpId` is that origin's too)
2061
2078
  * and binds the session to the package the origin is registered for; an
2062
2079
  * unregistered origin is refused with {@link OriginNotRegistered}.
2080
+ *
2081
+ * `invite` ({@link SignUpOptions}) goes on both halves and on the retry,
2082
+ * as the node judges it on each before it spends anything; a sign-up the
2083
+ * cluster's policy refuses, or an unknown, expired or used invite, is
2084
+ * {@link SignUpRefused} (from `begin`, before any passkey is made).
2063
2085
  */
2064
2086
  async signUp(passkey, name, options = {}) {
2065
2087
  const origin = this.pageOrigin(options);
2088
+ const invite = options.invite ? { invite: options.invite } : {};
2066
2089
  const begin = await this.begin(
2067
2090
  "auth/passkey/register/begin",
2068
- origin === void 0 ? { name } : { name, origin },
2091
+ origin === void 0 ? { name, ...invite } : { name, origin, ...invite },
2069
2092
  origin
2070
2093
  );
2071
2094
  const registration = await passkey.create(begin.options);
2072
2095
  const session = await this.postConfirmed(
2073
2096
  "auth/passkey/register/finish",
2074
- { challengeId: begin.challengeId, registration },
2097
+ { challengeId: begin.challengeId, registration, ...invite },
2075
2098
  passkey
2076
2099
  );
2077
2100
  this.useSession(session);
2078
2101
  return session;
2079
2102
  }
2103
+ /** Who may create an account on the cluster (`GET /sign-up`); needs no session. */
2104
+ signUpPolicy() {
2105
+ return this.get("sign-up");
2106
+ }
2080
2107
  /**
2081
2108
  * Sign in with an existing passkey. On a page whose origin is not the
2082
2109
  * cluster's ({@link SignInOptions}), the assertion is made for that
@@ -2223,6 +2250,12 @@ var CalimeroClient = class _CalimeroClient {
2223
2250
  * Create an API key for an agent or server, approved with the account's
2224
2251
  * `passkey` (`412 CONFIRM_REQUIRED`); needs a passkey session (an API key
2225
2252
  * is refused `403`). The key is returned once.
2253
+ *
2254
+ * `upgrades: { app, package? }` makes an upgrade key, for CI: it upgrades
2255
+ * that one app to signed releases of its package (default: the one the app
2256
+ * runs, by that package's pinned signer) with {@link upgradeApp} and no
2257
+ * passkey, and every other request with it is refused
2258
+ * `403 UPGRADE_KEY_ONLY`. It takes no other scope field.
2226
2259
  */
2227
2260
  createApiKey(options, passkey) {
2228
2261
  return this.postConfirmed("auth/apikeys", { ...options }, passkey);
@@ -2362,6 +2395,8 @@ var CalimeroClient = class _CalimeroClient {
2362
2395
  * `passkey` gives. Refused (`403`) to a session opened on an app's
2363
2396
  * frontend: an app asks its user with {@link requestConsent} instead. Past
2364
2397
  * a release deadline its approver has not met: {@link ReleaseDeadlineError}.
2398
+ * With an upgrade key ({@link createApiKey} `upgrades`) pass no passkey and
2399
+ * a `version` of the key's package: the key's own proof stands in for it.
2365
2400
  */
2366
2401
  upgradeApp(app, target, passkey) {
2367
2402
  const path = `apps/${seg(app)}/upgrade`;
@@ -3365,6 +3400,7 @@ export {
3365
3400
  SEALED_CONTENT_TYPE,
3366
3401
  SEALED_PATH,
3367
3402
  SealedTransportError,
3403
+ SignUpRefused,
3368
3404
  StaleTransportKeyError,
3369
3405
  TrapError,
3370
3406
  UnavailableError,