@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/README.md CHANGED
@@ -97,7 +97,7 @@ Pinned measurements go through `policy.verifyQuote` (`createQuoteVerifier`).
97
97
 
98
98
  ## The API
99
99
 
100
- - **Credentials**: `signUp`, `signIn`, `refresh`, `signOut`, `signOutEverywhere`, `useSession`, `useApiKey`, `me`, `usage`, `addPasskey`, `labelPasskey`, `removePasskey`, `createApiKey`, `listApiKeys`, `revokeApiKey`. Adding or removing a passkey and creating an API key are approved with a passkey the account already has.
100
+ - **Credentials**: `signUp` (with an `invite`, on a cluster that takes new accounts by invite; `signUpPolicy` reads which), `signIn`, `refresh`, `signOut`, `signOutEverywhere`, `useSession`, `useApiKey`, `me`, `usage`, `addPasskey`, `labelPasskey`, `removePasskey`, `createApiKey`, `listApiKeys`, `revokeApiKey`. Adding or removing a passkey and creating an API key are approved with a passkey the account already has.
101
101
  - **Package origins**: `packageOrigins.list`, `packageOrigins.add`, `packageOrigins.remove`. A package's managers register the web origins of a frontend they host themselves (approved with a passkey); `signUp` and `signIn` on such a page send its origin, sign for that origin's relying-party id, and open a session bound to the package (`me()` answers its `app` and `origin`). An unregistered origin is refused with `OriginNotRegistered`.
102
102
  - **Packages**: `installPackage`, `uploadPackage`, `packages`, `package`, `uninstallPackage`; `uploadBundle` (raw WASM, development clusters only).
103
103
  - **Apps**: `createApp`, `listApps`, `getApp`, `deleteApp`, `setAccess`, `setAppMetadata`, `appStorage`, `appAbi`, `upgradeApp`, `transferApp`.
@@ -12,8 +12,8 @@
12
12
  import { type AttestationDoc, type CloudPolicy } from './attestation.js';
13
13
  import { type PasskeyProvider } from './passkey.js';
14
14
  import { type AppsReport, type ConsentRequest, type ConsentResult, type ConsentStarted, type OpenConsentOptions, type OpsAppsReport, type OpsOrgsReport, type PageOptions, type PendingApprovals, type PublisherBindingInfo, type PublisherProof, type ReleaseRules } from './approvals.js';
15
- export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
16
- export type { Committed } from './errors.js';
15
+ export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, SignUpRefused, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
16
+ export type { Committed, SignUpRefusal } from './errors.js';
17
17
  export interface CalimeroSession {
18
18
  accountId: string;
19
19
  sessionToken: string;
@@ -338,6 +338,30 @@ export interface PackageOrigins {
338
338
  export interface SignInOptions {
339
339
  origin?: string | null;
340
340
  }
341
+ /**
342
+ * {@link SignInOptions} for a sign-up, and the invite it is made with: an
343
+ * organization invite's token (the new account joins the organization at
344
+ * the invite's role) or a cluster sign-up invite's. A cluster whose policy
345
+ * is `invite` or `closed` ({@link CalimeroClient.signUpPolicy}) needs one.
346
+ */
347
+ export interface SignUpOptions extends SignInOptions {
348
+ invite?: string;
349
+ }
350
+ /**
351
+ * `GET /sign-up`: who may create an account on the cluster (core's sign-up
352
+ * policy, read without a session), so a page can say "invite only" before
353
+ * any passkey prompt.
354
+ */
355
+ export interface SignUpPolicy {
356
+ /** `open` (anyone), `invite` (an organization or sign-up invite), `closed` (a sign-up invite only). */
357
+ policy: 'open' | 'invite' | 'closed';
358
+ /** Whether an organization invite lets a new person sign up (and join it). */
359
+ orgInvites: boolean;
360
+ /** Whether a cluster sign-up invite does (always). */
361
+ signUpInvites: boolean;
362
+ /** Whether a sign-up without an invite is refused. */
363
+ inviteRequired: boolean;
364
+ }
341
365
  /**
342
366
  * How a call or a view is sent again while the node is unavailable (D70): with
343
367
  * the same key, after a backoff that starts at `baseDelayMs` and doubles up to
@@ -520,8 +544,15 @@ export declare class CalimeroClient {
520
544
  * origin's relying party (the confirmation's `rpId` is that origin's too)
521
545
  * and binds the session to the package the origin is registered for; an
522
546
  * unregistered origin is refused with {@link OriginNotRegistered}.
547
+ *
548
+ * `invite` ({@link SignUpOptions}) goes on both halves and on the retry,
549
+ * as the node judges it on each before it spends anything; a sign-up the
550
+ * cluster's policy refuses, or an unknown, expired or used invite, is
551
+ * {@link SignUpRefused} (from `begin`, before any passkey is made).
523
552
  */
524
- signUp(passkey: PasskeyProvider, name: string, options?: SignInOptions): Promise<CalimeroSession>;
553
+ signUp(passkey: PasskeyProvider, name: string, options?: SignUpOptions): Promise<CalimeroSession>;
554
+ /** Who may create an account on the cluster (`GET /sign-up`); needs no session. */
555
+ signUpPolicy(): Promise<SignUpPolicy>;
525
556
  /**
526
557
  * Sign in with an existing passkey. On a page whose origin is not the
527
558
  * cluster's ({@link SignInOptions}), the assertion is made for that
@@ -576,6 +607,12 @@ export declare class CalimeroClient {
576
607
  * Create an API key for an agent or server, approved with the account's
577
608
  * `passkey` (`412 CONFIRM_REQUIRED`); needs a passkey session (an API key
578
609
  * is refused `403`). The key is returned once.
610
+ *
611
+ * `upgrades: { app, package? }` makes an upgrade key, for CI: it upgrades
612
+ * that one app to signed releases of its package (default: the one the app
613
+ * runs, by that package's pinned signer) with {@link upgradeApp} and no
614
+ * passkey, and every other request with it is refused
615
+ * `403 UPGRADE_KEY_ONLY`. It takes no other scope field.
579
616
  */
580
617
  createApiKey(options: {
581
618
  label?: string;
@@ -584,6 +621,10 @@ export declare class CalimeroClient {
584
621
  readOnly?: boolean;
585
622
  allowConfirm?: boolean;
586
623
  ttlSecs?: number;
624
+ upgrades?: {
625
+ app: string;
626
+ package?: string;
627
+ };
587
628
  }, passkey: PasskeyProvider): Promise<{
588
629
  keyId: string;
589
630
  key: string;
@@ -673,6 +714,8 @@ export declare class CalimeroClient {
673
714
  * `passkey` gives. Refused (`403`) to a session opened on an app's
674
715
  * frontend: an app asks its user with {@link requestConsent} instead. Past
675
716
  * a release deadline its approver has not met: {@link ReleaseDeadlineError}.
717
+ * With an upgrade key ({@link createApiKey} `upgrades`) pass no passkey and
718
+ * a `version` of the key's package: the key's own proof stands in for it.
676
719
  */
677
720
  upgradeApp(app: string, target: {
678
721
  version?: string;
@@ -15,7 +15,7 @@ import { DEFAULT_DIRECTORY, orderNodes, readDirectory } from './directory.js';
15
15
  import { CalimeroError, ConfirmCancelled, ConfirmRequired, LoginRequired, OriginNotRegistered, UnavailableError, WrongNode, errorFrom, } from './errors.js';
16
16
  import { b64url, fromB64url } from './passkey.js';
17
17
  import { confirmationCode, pageQuery, pendingApprovalsFrom, } from './approvals.js';
18
- export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
18
+ export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, SignUpRefused, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
19
19
  /** A deployer's key, as `GET /deployers` lists it and `DELETE /deployers/{key}` takes it. */
20
20
  export function deployerKey(deployer) {
21
21
  return 'account' in deployer ? `account:${deployer.account}` : `org:${deployer.org}`;
@@ -462,15 +462,25 @@ export class CalimeroClient {
462
462
  * origin's relying party (the confirmation's `rpId` is that origin's too)
463
463
  * and binds the session to the package the origin is registered for; an
464
464
  * unregistered origin is refused with {@link OriginNotRegistered}.
465
+ *
466
+ * `invite` ({@link SignUpOptions}) goes on both halves and on the retry,
467
+ * as the node judges it on each before it spends anything; a sign-up the
468
+ * cluster's policy refuses, or an unknown, expired or used invite, is
469
+ * {@link SignUpRefused} (from `begin`, before any passkey is made).
465
470
  */
466
471
  async signUp(passkey, name, options = {}) {
467
472
  const origin = this.pageOrigin(options);
468
- const begin = await this.begin('auth/passkey/register/begin', origin === undefined ? { name } : { name, origin }, origin);
473
+ const invite = options.invite ? { invite: options.invite } : {};
474
+ const begin = await this.begin('auth/passkey/register/begin', origin === undefined ? { name, ...invite } : { name, origin, ...invite }, origin);
469
475
  const registration = await passkey.create(begin.options);
470
- const session = await this.postConfirmed('auth/passkey/register/finish', { challengeId: begin.challengeId, registration }, passkey);
476
+ const session = await this.postConfirmed('auth/passkey/register/finish', { challengeId: begin.challengeId, registration, ...invite }, passkey);
471
477
  this.useSession(session);
472
478
  return session;
473
479
  }
480
+ /** Who may create an account on the cluster (`GET /sign-up`); needs no session. */
481
+ signUpPolicy() {
482
+ return this.get('sign-up');
483
+ }
474
484
  /**
475
485
  * Sign in with an existing passkey. On a page whose origin is not the
476
486
  * cluster's ({@link SignInOptions}), the assertion is made for that
@@ -625,6 +635,12 @@ export class CalimeroClient {
625
635
  * Create an API key for an agent or server, approved with the account's
626
636
  * `passkey` (`412 CONFIRM_REQUIRED`); needs a passkey session (an API key
627
637
  * is refused `403`). The key is returned once.
638
+ *
639
+ * `upgrades: { app, package? }` makes an upgrade key, for CI: it upgrades
640
+ * that one app to signed releases of its package (default: the one the app
641
+ * runs, by that package's pinned signer) with {@link upgradeApp} and no
642
+ * passkey, and every other request with it is refused
643
+ * `403 UPGRADE_KEY_ONLY`. It takes no other scope field.
628
644
  */
629
645
  createApiKey(options, passkey) {
630
646
  return this.postConfirmed('auth/apikeys', { ...options }, passkey);
@@ -766,6 +782,8 @@ export class CalimeroClient {
766
782
  * `passkey` gives. Refused (`403`) to a session opened on an app's
767
783
  * frontend: an app asks its user with {@link requestConsent} instead. Past
768
784
  * a release deadline its approver has not met: {@link ReleaseDeadlineError}.
785
+ * With an upgrade key ({@link createApiKey} `upgrades`) pass no passkey and
786
+ * a `version` of the key's package: the key's own proof stands in for it.
769
787
  */
770
788
  upgradeApp(app, target, passkey) {
771
789
  const path = `apps/${seg(app)}/upgrade`;
@@ -126,6 +126,26 @@ export declare class BadOrigin extends CalimeroError {
126
126
  export declare class OriginTaken extends CalimeroError {
127
127
  constructor(message: string, details?: Record<string, unknown>);
128
128
  }
129
+ /** Why a sign-up was refused ({@link SignUpRefused.reason}), read from what the node said. */
130
+ export type SignUpRefusal = 'invite-only' | 'closed' | 'unknown-invite' | 'expired-invite' | 'org-gone' | 'other';
131
+ /**
132
+ * `403 SIGN_UP_REFUSED`: the cluster's sign-up policy does not take this
133
+ * sign-up (core `SystemState::admits`), answered by `register/begin` before a
134
+ * passkey is made and by `register/finish` before its challenge is spent.
135
+ * `reason` says why, so a page can say "invite only" or "this invite has
136
+ * expired" instead of the node's sentence:
137
+ *
138
+ * - `invite-only`: the cluster takes new accounts with an invite only.
139
+ * - `closed`: only a cluster sign-up invite (the operator's or the owner's) admits.
140
+ * - `unknown-invite`: the invite is not one the cluster knows (mistyped, revoked,
141
+ * or used up: a spent invite is gone).
142
+ * - `expired-invite`: past its expiry, or no use left.
143
+ * - `org-gone`: the organization the invite was for was deleted.
144
+ */
145
+ export declare class SignUpRefused extends CalimeroError {
146
+ readonly reason: SignUpRefusal;
147
+ constructor(message: string, details?: Record<string, unknown>);
148
+ }
129
149
  /** `429 QUOTA_EXCEEDED`: the caller holds as many of something (origins, blobs, ...) as it may. */
130
150
  export declare class QuotaExceeded extends CalimeroError {
131
151
  constructor(message: string, details?: Record<string, unknown>);
@@ -165,6 +165,40 @@ export class OriginTaken extends CalimeroError {
165
165
  this.name = 'OriginTaken';
166
166
  }
167
167
  }
168
+ /**
169
+ * `403 SIGN_UP_REFUSED`: the cluster's sign-up policy does not take this
170
+ * sign-up (core `SystemState::admits`), answered by `register/begin` before a
171
+ * passkey is made and by `register/finish` before its challenge is spent.
172
+ * `reason` says why, so a page can say "invite only" or "this invite has
173
+ * expired" instead of the node's sentence:
174
+ *
175
+ * - `invite-only`: the cluster takes new accounts with an invite only.
176
+ * - `closed`: only a cluster sign-up invite (the operator's or the owner's) admits.
177
+ * - `unknown-invite`: the invite is not one the cluster knows (mistyped, revoked,
178
+ * or used up: a spent invite is gone).
179
+ * - `expired-invite`: past its expiry, or no use left.
180
+ * - `org-gone`: the organization the invite was for was deleted.
181
+ */
182
+ export class SignUpRefused extends CalimeroError {
183
+ constructor(message, details = {}) {
184
+ super(403, 'SIGN_UP_REFUSED', message, details);
185
+ this.name = 'SignUpRefused';
186
+ this.reason = signUpRefusal(message);
187
+ }
188
+ }
189
+ function signUpRefusal(message) {
190
+ if (/invite only/.test(message))
191
+ return 'invite-only';
192
+ if (/pre-authorized|sign-up invite/.test(message))
193
+ return 'closed';
194
+ if (/unknown invite/.test(message))
195
+ return 'unknown-invite';
196
+ if (/invite has expired/.test(message))
197
+ return 'expired-invite';
198
+ if (/organization is gone/.test(message))
199
+ return 'org-gone';
200
+ return 'other';
201
+ }
168
202
  /** `429 QUOTA_EXCEEDED`: the caller holds as many of something (origins, blobs, ...) as it may. */
169
203
  export class QuotaExceeded extends CalimeroError {
170
204
  constructor(message, details = {}) {
@@ -265,6 +299,8 @@ export function errorFrom(status, body, retryAfterHeader) {
265
299
  return new OriginTaken(message, details);
266
300
  case '429 QUOTA_EXCEEDED':
267
301
  return new QuotaExceeded(message, details);
302
+ case '403 SIGN_UP_REFUSED':
303
+ return new SignUpRefused(message, details);
268
304
  case '412 CONFIRM_REQUIRED':
269
305
  return new ConfirmRequired(message, details);
270
306
  case '413 ARGS_TOO_LARGE':
@@ -1,9 +1,9 @@
1
1
  export { CalimeroClient, deployerKey, frontendManifest, pageDeployment } from './client.js';
2
2
  export { DEFAULT_DIRECTORY, DirectoryError } from './directory.js';
3
3
  export type { DirectoryFailure } from './directory.js';
4
- export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
5
- export type { Committed } from './errors.js';
6
- export type { AppInfo, AppXcalls, BlobContent, BlobInfo, DeadLetter, Deployer, DeployerGrant, DeployersInfo, DeploymentInfo, DeploymentOffer, DeploymentOrgs, FrontendManifest, MeInfo, PackageOrigin, PackageOriginAdded, PackageOriginRemoved, PackageOrigins, SignInOptions, PublicDeployment, CallResult, CalimeroClientOptions, CalimeroConnectOptions, CloudEvent, CalimeroSession, PackageInfo, PackageInstalled, CloudRetryOptions, OrgInfo, OrgUpgradeTarget, PresenceEntry, UpgradeRun, ViewResult, } from './client.js';
4
+ export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, SignUpRefused, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
5
+ export type { Committed, SignUpRefusal } from './errors.js';
6
+ export type { AppInfo, AppXcalls, BlobContent, BlobInfo, DeadLetter, Deployer, DeployerGrant, DeployersInfo, DeploymentInfo, DeploymentOffer, DeploymentOrgs, FrontendManifest, MeInfo, PackageOrigin, PackageOriginAdded, PackageOriginRemoved, PackageOrigins, SignInOptions, SignUpOptions, SignUpPolicy, PublicDeployment, CallResult, CalimeroClientOptions, CalimeroConnectOptions, CloudEvent, CalimeroSession, PackageInfo, PackageInstalled, CloudRetryOptions, OrgInfo, OrgUpgradeTarget, PresenceEntry, UpgradeRun, ViewResult, } from './client.js';
7
7
  export { claimedRelease, fetchAttestedKey, freshCollateral, MOCK_QUOTE_HEADER } from './attestation.js';
8
8
  export type { AttestationDoc, CloudPolicy, CloudReleasePolicy } from './attestation.js';
9
9
  export { browserPasskey, b64url, fromB64url } from './passkey.js';
@@ -1,6 +1,6 @@
1
1
  export { CalimeroClient, deployerKey, frontendManifest, pageDeployment } from './client.js';
2
2
  export { DEFAULT_DIRECTORY, DirectoryError } from './directory.js';
3
- export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
3
+ export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, NotFound, OriginNotRegistered, OriginTaken, QuotaExceeded, ReleaseDeadlineError, SignUpRefused, TrapError, UnavailableError, WrongNode, errorFrom, } from './errors.js';
4
4
  export { claimedRelease, fetchAttestedKey, freshCollateral, MOCK_QUOTE_HEADER } from './attestation.js';
5
5
  export { browserPasskey, b64url, fromB64url } from './passkey.js';
6
6
  export { MAX_REPORT_PAGE, RELEASE_VERIFIER, compareVersions, confirmationCode, consentReturn, pageQuery, pendingApprovalsFrom, publisherBindingBytes, publisherBindingMessage, releaseConsent, releaseNotesUrl, stalledBy, upgradeConsent, verifyReleaseUrl, withdrawConsent, } from './approvals.js';