@calimero-network/mero-js 34.0.0 → 34.1.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
@@ -110,7 +110,7 @@ flows and streams a single route cannot be:
110
110
  - **Organization recovery**: `startRecovery(org, seed)` (the seed signs here and never leaves the process); `newRecoverySeed`, `recoveryPublicKey`.
111
111
  - **Blobs**: `downloadBlob(app, id)`, `downloadBlobGranted(app, id, grant)` (bytes; `client.apps.blobDownload` answers a `Blob` with its type).
112
112
  - **Streams**: `events(app, from?, signal?)`, `presenceStream(app, signal?)`.
113
- - **Approvals from an app**: `pendingApprovals(org?)`, `appsReportAll(org)`, then `openConsentPage(request, …)` to send the user to the node's consent page, and `waitForConsent(requestId)`; back on `returnTo`, `resumeConsent()` reads the decision on the request this page started from the node (never from the URL) and refuses a return for another request, one still pending, or one a newer request replaced (`CONSENT_REPLACED`: an account has one undecided request per node). Besides releases, upgrades and outbound hosts, `createOrgConsent`, `createInviteConsent` and `acceptInviteConsent` ask for a new organization, an invite or joining with one; the result's `outcome` (`{ orgId }`, `{ token }`, `{ org }`) is typed by `kind`. Show the answer's `code` to the user before sending them to `url` (`openConsentPage`'s `confirm` hook); they should see the same code on the page (`confirmationCode(requestId)` checks it). See [Ask your users to approve node images and app upgrades](https://calimero-network.github.io/mero-js/guides/user-approvals/).
113
+ - **Approvals from an app**: `pendingApprovals(org?)`, `appsReportAll(org)`, then `openConsentPage(request, …)` to send the user to the node's consent page, and `waitForConsent(requestId)`; back on `returnTo`, `resumeConsent()` reads the decision on the request this page started from the node (never from the URL) and refuses a return for another request, one still pending, or one a newer request replaced (`CONSENT_REPLACED`: an account has one undecided request per node). Besides releases, upgrades and outbound hosts, `createOrgConsent`, `createInviteConsent` and `acceptInviteConsent` ask for a new organization, an invite or joining with one, and `leaveOrgConsent`, `removeMemberConsent`, `setMemberRoleConsent`, `setMemberTeamsConsent`, `removeMemberTeamsConsent`, `revokeInviteConsent`, `renameOrgConsent`, `deleteOrgConsent`, `setCapabilitiesConsent` and `setAllAppsConsent` for managing one; the result's `outcome` (`{ orgId }`, `{ token }`, `{ org }`, a rename's `{ orgId, name }`, a deletion's `{ apps }`) is typed by `kind`. Show the answer's `code` to the user before sending them to `url` (`openConsentPage`'s `confirm` hook); they should see the same code on the page (`confirmationCode(requestId)` checks it). See [Ask your users to approve node images and app upgrades](https://calimero-network.github.io/mero-js/guides/user-approvals/).
114
114
 
115
115
  Refusals are typed (`LoginRequired`, `PasskeyUnknownHere`, `WrongNode`, `NotFound`, `ConfirmRequired`, `ConfirmCancelled`, `ConfirmPromptBlocked`,
116
116
  `ArgsTooLarge`, `IdempotencyMismatch`, `ReleaseDeadlineError`, `RuntimeTooOld`, `ConsentStale`, `AppError`, `TrapError`,
@@ -14,7 +14,8 @@
14
14
  * [consent page](https://calimero-network.github.io/core/protocol/consent-page/)
15
15
  * and [governance](https://calimero-network.github.io/core/protocol/governance/).
16
16
  */
17
- import type { ApiAnswer } from '../routes/types.js';
17
+ import type { ApiAnswer, ApiSchema } from '../routes/types.js';
18
+ import type { operations } from '../generated/api.js';
18
19
  /**
19
20
  * Who holds one decision on a cluster (core's `Authority`), fixed at genesis
20
21
  * and attested by every replica. `owner`: the parties around each app, with a
@@ -115,70 +116,54 @@ export declare function publisherBindingBytes(cluster: string, org: string, sign
115
116
  export type ConsentScope = 'account' | {
116
117
  org: string;
117
118
  };
118
- /** What the app asks its user to approve (`POST /consent/requests`). Unknown fields are refused. */
119
- export type ConsentRequest = {
120
- kind: 'release';
121
- scope: ConsentScope;
122
- /** `withdraw: true` asks to withdraw the release's approval instead of approving it. */
123
- subject: {
124
- version: string;
125
- withdraw?: boolean;
126
- };
127
- /** Where the page sends the person back: the package's frontend origin, or one its manifest names. */
128
- returnTo: string;
129
- } | {
130
- kind: 'upgrade';
131
- subject: {
132
- app: string;
133
- toVersion: string;
134
- };
135
- returnTo: string;
136
- } | {
137
- kind: 'outbound';
138
- scope: ConsentScope;
139
- /** `package`: a package-bound session's own when left out; `prefixes`: every one the latest release declares. */
140
- subject: {
141
- package?: string;
142
- prefixes?: string[];
143
- };
144
- returnTo: string;
145
- } | {
146
- /** A new organization, owned by whoever approves. Outcome: `{ orgId }`. */
147
- kind: 'createOrg';
148
- subject: {
149
- name: string;
150
- };
151
- returnTo: string;
152
- } | {
153
- /** A new invite to `subject.org`. Outcome: `{ token }`. */
154
- kind: 'createInvite';
155
- subject: InviteConsentSubject;
156
- returnTo: string;
157
- } | {
158
- /** Joining an organization with an invite's `token`. Outcome: `{ org }`. */
159
- kind: 'acceptInvite';
160
- subject: {
161
- token: string;
162
- };
163
- returnTo: string;
164
- };
119
+ /**
120
+ * What the app asks its user to approve (`POST /consent/requests`), by
121
+ * `kind`: the route's generated body. Unknown fields are refused. Build one
122
+ * with the helpers below (`releaseConsent`, `createOrgConsent`, ...), each
123
+ * typed as the kind it builds.
124
+ *
125
+ * - `release`, `upgrade`, `outbound`: a release approval (or withdrawal), an
126
+ * app upgrade, outbound prefixes.
127
+ * - `createOrg`, `createInvite`, `acceptInvite` (core#5014): a new
128
+ * organization, an invite, joining with one.
129
+ * - `leaveOrg`, `removeMember`, `setMemberRole`, `setMemberTeams`,
130
+ * `removeMemberTeams`, `revokeInvite`, `renameOrg`, `deleteOrg`,
131
+ * `setCapabilities`, `setAllApps` (core#5018): managing an organization.
132
+ *
133
+ * `returnTo` is where the page sends the person back: the package's frontend
134
+ * origin, or one its manifest names.
135
+ */
136
+ export type ConsentRequest = NonNullable<operations['consent_page_create']['requestBody']>['content']['application/json'];
165
137
  /** A consent request's kind. */
166
138
  export type ConsentKind = ConsentRequest['kind'];
167
- /** A role an invite gives (core's `Role`). */
168
- export type InviteRole = 'guest' | 'member' | 'admin';
169
- /** What a `createInvite` consent request asks for. */
170
- export interface InviteConsentSubject {
171
- org: string;
172
- role: InviteRole;
173
- /** Teams the invite joins its user to. */
174
- teams?: string[];
175
- /** How long the invite lasts, in seconds. */
176
- ttlSecs?: number;
177
- /** How many times it may be used. */
178
- uses?: number;
179
- /** Whether it gives every app of the organization. */
180
- allApps?: boolean;
181
- }
139
+ /** The consent request of kind `K`. */
140
+ type ConsentRequestOf<K extends ConsentKind> = Extract<ConsentRequest, {
141
+ kind: K;
142
+ }>;
143
+ /**
144
+ * What a `createInvite` consent request asks for: `org`, `role`, and
145
+ * optionally `teams` to join, `ttlSecs` it lasts, `uses` it allows and
146
+ * `allApps`, every app of the organization.
147
+ */
148
+ export type InviteConsentSubject = ConsentRequestOf<'createInvite'>['subject'];
149
+ /** A role an invite gives (core's `Role`, short of `owner`). */
150
+ export type InviteRole = InviteConsentSubject['role'];
151
+ /** A member's role in an organization (core's `Role`). */
152
+ export type OrgRole = ApiSchema<'OrgRole'>;
153
+ /** A member's role in a team (core's `TeamRole`). */
154
+ export type TeamRole = ApiSchema<'TeamRole'>;
155
+ /**
156
+ * One team row a `setMemberTeams` consent request sets: `team`, and the
157
+ * member's `role` and `capabilities` bits (`ORG_CAPABILITIES`) there,
158
+ * each the team's default when left out.
159
+ */
160
+ export type MemberTeamConsent = ConsentRequestOf<'setMemberTeams'>['subject']['teams'][number];
161
+ /**
162
+ * Whose capability bits (`ORG_CAPABILITIES`) a `setCapabilities`
163
+ * consent request sets: with `account`, that member's (organization-wide, or
164
+ * in `team`); without, a default (the organization's, or `team`'s).
165
+ */
166
+ export type CapabilitiesConsentSubject = ConsentRequestOf<'setCapabilities'>['subject'];
182
167
  /** The node's answer to a consent request: send the person to `url`. */
183
168
  export type ConsentStarted = ApiAnswer<'consent_page_create'>;
184
169
  /** How {@link CalimeroClient.openConsentPage} sends the person to the page. */
@@ -202,30 +187,35 @@ export interface OpenConsentOptions {
202
187
  export declare function confirmationCode(requestId: string): Promise<string>;
203
188
  /**
204
189
  * What an approval made, by kind (`outcome` on {@link ConsentResult}, once
205
- * approved): `release`, `upgrade` and `outbound` make nothing. An invite's
206
- * `token` is a credential: keep it out of logs.
190
+ * approved): `createOrg`, `createInvite`, `acceptInvite`, `renameOrg` and
191
+ * `deleteOrg` make something; the other kinds nothing. An invite's `token` is
192
+ * a credential: keep it out of logs.
207
193
  */
208
194
  export interface ConsentOutcomes {
209
195
  release: never;
210
196
  upgrade: never;
211
197
  outbound: never;
212
- createOrg: {
213
- orgId: string;
214
- };
215
- createInvite: {
216
- token: string;
217
- };
218
- acceptInvite: {
219
- org: string;
220
- };
198
+ createOrg: Required<Pick<GeneratedOutcome, 'orgId'>>;
199
+ createInvite: Required<Pick<GeneratedOutcome, 'token'>>;
200
+ acceptInvite: Required<Pick<GeneratedOutcome, 'org'>>;
201
+ leaveOrg: never;
202
+ removeMember: never;
203
+ setMemberRole: never;
204
+ setMemberTeams: never;
205
+ removeMemberTeams: never;
206
+ revokeInvite: never;
207
+ renameOrg: Required<Pick<GeneratedOutcome, 'orgId' | 'name'>>;
208
+ /** The apps deleted with the organization. */
209
+ deleteOrg: Required<Pick<GeneratedOutcome, 'apps'>>;
210
+ setCapabilities: never;
211
+ setAllApps: never;
221
212
  }
222
- /** `GET /consent/{id}/result` for a request of kind `K`. */
223
- export interface ConsentResultOf<K extends ConsentKind> {
224
- requestId: string;
213
+ /** The route's generated answer, whose one `outcome` has every kind's fields optional. */
214
+ type GeneratedResult = ApiAnswer<'consent_page_result'>;
215
+ type GeneratedOutcome = NonNullable<GeneratedResult['outcome']>;
216
+ /** `GET /consent/{id}/result` for a request of kind `K`: `requestId`, `status`, and `decidedAt` (Unix seconds; `null` while pending). */
217
+ export interface ConsentResultOf<K extends ConsentKind> extends Omit<GeneratedResult, 'kind' | 'outcome'> {
225
218
  kind: K;
226
- status: 'pending' | 'approved' | 'declined';
227
- /** Unix seconds; `null` while pending. */
228
- decidedAt: number | null;
229
219
  /** What the approval made, once approved, for the kinds that make something. */
230
220
  outcome?: ConsentOutcomes[K];
231
221
  }
@@ -234,8 +224,7 @@ export interface ConsentResultOf<K extends ConsentKind> {
234
224
  * `if (r.kind === 'createOrg') r.outcome?.orgId`. Read `outcome` only from
235
225
  * this sealed answer, never from the page's redirect, which carries none.
236
226
  *
237
- * Typed here by hand: the vendored OpenAPI document does not name the
238
- * organization kinds (core#5014) yet; the next openapi-sync brings them.
227
+ * The generated answer, with `outcome` typed by kind.
239
228
  */
240
229
  export type ConsentResult = {
241
230
  [K in ConsentKind]: ConsentResultOf<K>;
@@ -354,3 +343,44 @@ export declare function createInviteConsent(subject: InviteConsentSubject, retur
354
343
  export declare function acceptInviteConsent(token: string, returnTo: string): ConsentRequest & {
355
344
  kind: 'acceptInvite';
356
345
  };
346
+ /** The consent request that has the person leave `org`. */
347
+ export declare function leaveOrgConsent(org: string, returnTo: string): ConsentRequest & {
348
+ kind: 'leaveOrg';
349
+ };
350
+ /** The consent request that removes `account` from `org`. */
351
+ export declare function removeMemberConsent(org: string, account: string, returnTo: string): ConsentRequest & {
352
+ kind: 'removeMember';
353
+ };
354
+ /** The consent request that gives the member `account` of `org` the role `role`. */
355
+ export declare function setMemberRoleConsent(org: string, account: string, role: OrgRole, returnTo: string): ConsentRequest & {
356
+ kind: 'setMemberRole';
357
+ };
358
+ /** The consent request that sets the member `account`'s rows in teams of `org`. */
359
+ export declare function setMemberTeamsConsent(org: string, account: string, teams: MemberTeamConsent[], returnTo: string): ConsentRequest & {
360
+ kind: 'setMemberTeams';
361
+ };
362
+ /** The consent request that removes the member `account` from `teams` of `org`. */
363
+ export declare function removeMemberTeamsConsent(org: string, account: string, teams: string[], returnTo: string): ConsentRequest & {
364
+ kind: 'removeMemberTeams';
365
+ };
366
+ /** The consent request that revokes the invite `inviteKey` of `org`. */
367
+ export declare function revokeInviteConsent(org: string, inviteKey: string, returnTo: string): ConsentRequest & {
368
+ kind: 'revokeInvite';
369
+ };
370
+ /** The consent request that renames `org` to `name`; its outcome is `{ orgId, name }`. */
371
+ export declare function renameOrgConsent(org: string, name: string, returnTo: string): ConsentRequest & {
372
+ kind: 'renameOrg';
373
+ };
374
+ /** The consent request that deletes `org`; its outcome lists the `apps` deleted with it. */
375
+ export declare function deleteOrgConsent(org: string, returnTo: string): ConsentRequest & {
376
+ kind: 'deleteOrg';
377
+ };
378
+ /** The consent request that sets capability bits in `subject.org` ({@link CapabilitiesConsentSubject}). */
379
+ export declare function setCapabilitiesConsent(subject: CapabilitiesConsentSubject, returnTo: string): ConsentRequest & {
380
+ kind: 'setCapabilities';
381
+ };
382
+ /** The consent request that gives the member `account` of `org` every app (`allApps: true`), or takes it back. */
383
+ export declare function setAllAppsConsent(org: string, account: string, allApps: boolean, returnTo: string): ConsentRequest & {
384
+ kind: 'setAllApps';
385
+ };
386
+ export {};
@@ -212,3 +212,43 @@ export function createInviteConsent(subject, returnTo) {
212
212
  export function acceptInviteConsent(token, returnTo) {
213
213
  return { kind: 'acceptInvite', subject: { token }, returnTo };
214
214
  }
215
+ /** The consent request that has the person leave `org`. */
216
+ export function leaveOrgConsent(org, returnTo) {
217
+ return { kind: 'leaveOrg', subject: { org }, returnTo };
218
+ }
219
+ /** The consent request that removes `account` from `org`. */
220
+ export function removeMemberConsent(org, account, returnTo) {
221
+ return { kind: 'removeMember', subject: { org, account }, returnTo };
222
+ }
223
+ /** The consent request that gives the member `account` of `org` the role `role`. */
224
+ export function setMemberRoleConsent(org, account, role, returnTo) {
225
+ return { kind: 'setMemberRole', subject: { org, account, role }, returnTo };
226
+ }
227
+ /** The consent request that sets the member `account`'s rows in teams of `org`. */
228
+ export function setMemberTeamsConsent(org, account, teams, returnTo) {
229
+ return { kind: 'setMemberTeams', subject: { org, account, teams }, returnTo };
230
+ }
231
+ /** The consent request that removes the member `account` from `teams` of `org`. */
232
+ export function removeMemberTeamsConsent(org, account, teams, returnTo) {
233
+ return { kind: 'removeMemberTeams', subject: { org, account, teams }, returnTo };
234
+ }
235
+ /** The consent request that revokes the invite `inviteKey` of `org`. */
236
+ export function revokeInviteConsent(org, inviteKey, returnTo) {
237
+ return { kind: 'revokeInvite', subject: { org, inviteKey }, returnTo };
238
+ }
239
+ /** The consent request that renames `org` to `name`; its outcome is `{ orgId, name }`. */
240
+ export function renameOrgConsent(org, name, returnTo) {
241
+ return { kind: 'renameOrg', subject: { org, name }, returnTo };
242
+ }
243
+ /** The consent request that deletes `org`; its outcome lists the `apps` deleted with it. */
244
+ export function deleteOrgConsent(org, returnTo) {
245
+ return { kind: 'deleteOrg', subject: { org }, returnTo };
246
+ }
247
+ /** The consent request that sets capability bits in `subject.org` ({@link CapabilitiesConsentSubject}). */
248
+ export function setCapabilitiesConsent(subject, returnTo) {
249
+ return { kind: 'setCapabilities', subject, returnTo };
250
+ }
251
+ /** The consent request that gives the member `account` of `org` every app (`allApps: true`), or takes it back. */
252
+ export function setAllAppsConsent(org, account, allApps, returnTo) {
253
+ return { kind: 'setAllApps', subject: { org, account, allApps }, returnTo };
254
+ }
@@ -521,8 +521,6 @@ export class CalimeroClient {
521
521
  throw new Error('no window to open the consent page in; pass `navigate`');
522
522
  w.location.assign(url);
523
523
  });
524
- // The organization kinds (core#5014) are typed by hand in approvals.ts
525
- // until the vendored OpenAPI document names them.
526
524
  const started = await this.consent.pageCreate({ body: request });
527
525
  if (started.code !== undefined) {
528
526
  const expected = await confirmationCode(started.requestId);
@@ -11,7 +11,7 @@ export type { AttestationDoc, NodePolicy, NodeReleasePolicy } from '../runtime/a
11
11
  export { browserPasskey, b64url, fromB64url, passkeyConfirm } from '../runtime/passkey.js';
12
12
  export { MAX_RECOVERY_NONCE_BYTES, RECOVERY_DOMAIN, newRecoverySeed, parseRecoverySeed, recoveryMessage, recoveryPublicKey, recoverySeedText, signRecovery, } from './recovery-key.js';
13
13
  export type { ConfirmCallback, ConfirmChallenge, PasskeyConfirmOptions, AssertionJSON, PasskeyCreateOptions, PasskeyGetOptions, PasskeyProvider, PasskeyUserVerification, RegistrationJSON, } from '../runtime/passkey.js';
14
- export { CONSENT_STORAGE_KEY, MAX_REPORT_PAGE, RELEASE_VERIFIER, acceptInviteConsent, compareVersions, confirmationCode, consentReturn, createInviteConsent, createOrgConsent, pageQuery, pendingApprovalsFrom, publisherBindingBytes, publisherBindingMessage, releaseConsent, releaseNotesUrl, stalledBy, upgradeConsent, verifyReleaseUrl, withdrawConsent, withoutConsentReturn, } from './approvals.js';
15
- export type { ActorKind, AppsReport, Authority, ConsentKind, ConsentOutcomes, ConsentRequest, ConsentResult, ConsentResultOf, ConsentScope, ConsentStarted, InviteConsentSubject, InviteRole, OpenConsentOptions, ResumeConsentOptions, Governance, LatestBlocked, PageOptions, PendingApprovals, PendingRelease, PendingUpgrade, ReleaseDeadline, ReleaseRules, ReportScope, ReportedApp, ReportedBundle, RuntimeShortNode, } from './approvals.js';
14
+ export { CONSENT_STORAGE_KEY, MAX_REPORT_PAGE, RELEASE_VERIFIER, acceptInviteConsent, compareVersions, confirmationCode, consentReturn, createInviteConsent, createOrgConsent, deleteOrgConsent, leaveOrgConsent, removeMemberConsent, removeMemberTeamsConsent, renameOrgConsent, revokeInviteConsent, setAllAppsConsent, setCapabilitiesConsent, setMemberRoleConsent, setMemberTeamsConsent, pageQuery, pendingApprovalsFrom, publisherBindingBytes, publisherBindingMessage, releaseConsent, releaseNotesUrl, stalledBy, upgradeConsent, verifyReleaseUrl, withdrawConsent, withoutConsentReturn, } from './approvals.js';
15
+ export type { ActorKind, AppsReport, Authority, CapabilitiesConsentSubject, ConsentKind, ConsentOutcomes, ConsentRequest, ConsentResult, ConsentResultOf, ConsentScope, ConsentStarted, InviteConsentSubject, InviteRole, MemberTeamConsent, OrgRole, TeamRole, OpenConsentOptions, ResumeConsentOptions, Governance, LatestBlocked, PageOptions, PendingApprovals, PendingRelease, PendingUpgrade, ReleaseDeadline, ReleaseRules, ReportScope, ReportedApp, ReportedBundle, RuntimeShortNode, } from './approvals.js';
16
16
  export { DEFAULT_ORG_CAPABILITIES, ORG_CAPABILITIES, orgCapabilities } from './capabilities.js';
17
17
  export type { OrgCapability } from './capabilities.js';
@@ -14,5 +14,5 @@ export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ClusterNotUpgraded, C
14
14
  export { claimedRelease, fetchAttestedKey, freshCollateral, MOCK_QUOTE_HEADER } from '../runtime/attestation.js';
15
15
  export { browserPasskey, b64url, fromB64url, passkeyConfirm } from '../runtime/passkey.js';
16
16
  export { MAX_RECOVERY_NONCE_BYTES, RECOVERY_DOMAIN, newRecoverySeed, parseRecoverySeed, recoveryMessage, recoveryPublicKey, recoverySeedText, signRecovery, } from './recovery-key.js';
17
- export { CONSENT_STORAGE_KEY, MAX_REPORT_PAGE, RELEASE_VERIFIER, acceptInviteConsent, compareVersions, confirmationCode, consentReturn, createInviteConsent, createOrgConsent, pageQuery, pendingApprovalsFrom, publisherBindingBytes, publisherBindingMessage, releaseConsent, releaseNotesUrl, stalledBy, upgradeConsent, verifyReleaseUrl, withdrawConsent, withoutConsentReturn, } from './approvals.js';
17
+ export { CONSENT_STORAGE_KEY, MAX_REPORT_PAGE, RELEASE_VERIFIER, acceptInviteConsent, compareVersions, confirmationCode, consentReturn, createInviteConsent, createOrgConsent, deleteOrgConsent, leaveOrgConsent, removeMemberConsent, removeMemberTeamsConsent, renameOrgConsent, revokeInviteConsent, setAllAppsConsent, setCapabilitiesConsent, setMemberRoleConsent, setMemberTeamsConsent, pageQuery, pendingApprovalsFrom, publisherBindingBytes, publisherBindingMessage, releaseConsent, releaseNotesUrl, stalledBy, upgradeConsent, verifyReleaseUrl, withdrawConsent, withoutConsentReturn, } from './approvals.js';
18
18
  export { DEFAULT_ORG_CAPABILITIES, ORG_CAPABILITIES, orgCapabilities } from './capabilities.js';