@calimero-network/mero-js 35.1.0 → 35.2.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/README.md CHANGED
@@ -1,13 +1,31 @@
1
1
  # Mero.js — the JavaScript client for Calimero 1.0
2
2
 
3
- The JavaScript/TypeScript client for [Calimero](https://calimero-network.github.io/core/)
4
- 1.0, the confidential cloud. `CalimeroClient` verifies a node's TDX attestation,
5
- seals every request to it end to end (Noise NK, `calimero/sealed-http/v2`), signs
6
- people in with WebAuthn passkeys and machines with API keys, and calls apps that
7
- each run on their own replicated log. It runs in the browser and Node 18+, and is
8
- byte-compatible with core's `calimero-sealed` and `calimero-client`.
9
-
10
- > **Version 27 is the Calimero 1.0 client only.** The v1 SDK for merod 0.x nodes
3
+ Your app's whole backend, like Firebase. Except nobody can read your data, not even us.
4
+ [Calimero](https://calimero-network.github.io/core/) gives an app auth (passkeys,
5
+ sessions, scoped API keys), a database (replicated app state), functions (Rust app
6
+ methods, compute jobs, timers, pipelines), realtime (events, presence), sealed file
7
+ and blob storage, search, hosting for its frontend and typed clients, all running
8
+ inside attested Intel TDX hardware. Clients check a node's attestation against
9
+ Sigstore-signed releases before they send it anything, then talk to it over a sealed
10
+ Noise channel.
11
+
12
+ This package is the JavaScript/TypeScript client, for the browser and Node 18+.
13
+ `CalimeroClient` verifies the node's TDX attestation, seals every request to it end
14
+ to end (Noise NK, `calimero/sealed-http/v2`), signs people in with WebAuthn passkeys
15
+ and machines with API keys, and calls your app. It is byte-compatible with core's
16
+ `calimero-sealed` and `calimero-client`.
17
+
18
+ What you can do with it:
19
+
20
+ - Connect to a Calimero Cloud cluster by name, with failover between its nodes.
21
+ - Sign up and sign in with passkeys, use API keys, and ask for passkey consent on sensitive calls.
22
+ - Install packages, create app instances, and call and view their methods.
23
+ - Follow an app's events and presence as streams.
24
+ - Upload and download sealed files and blobs.
25
+ - Manage organizations, teams, invites, deployments and every other route of the node, through methods generated from core's OpenAPI document.
26
+ - Build and sign a compute-only pipeline package (`.mpk`).
27
+
28
+ > **From version 27 this is the Calimero 1.0 client only.** The v1 SDK for merod 0.x nodes
11
29
  > (`MeroJs`, the admin and auth API clients, JSON-RPC, contexts and namespaces)
12
30
  > is in 26.x. See [Migrating from v1](https://calimero-network.github.io/mero-js/reference/migrating-from-v1/).
13
31
 
@@ -42,6 +60,7 @@ const client = await CalimeroClient.connect({
42
60
 
43
61
  await client.signUp(browserPasskey(), 'alice'); // or signIn(browserPasskey())
44
62
  await client.packages.install({ package: 'com.example.kv', version: '1.0.0' }); // signed .mpk from the registry
63
+ // No `org`: the instance goes in your personal organization, which sign-up made.
45
64
  const { appId: app } = await client.apps.create({ name: 'kv', package: 'com.example.kv', version: '1.0.0' });
46
65
 
47
66
  await client.apps.call({ app, method: 'set', args: { key: 'a', value: '1' } });
@@ -108,6 +127,7 @@ flows and streams a single route cannot be:
108
127
  - **Credentials**: `signUp(passkey, name, { invite?, origin?, signal? })`, `signIn(passkey, { origin?, signal? })`, `refresh`, `signOut`, `signOutEverywhere`, `useSession`, `useApiKey`, `addPasskey(newPasskey, approver)`.
109
128
  - **Account recovery** (core #4844): signed out, `startAccountRecovery(code, passkey)` and, 72 hours later, `finishAccountRecovery(passkey, accountId?)`. The code itself is `client.auth.recoveryCreate({}, { confirm })`.
110
129
  - **Organization recovery**: `startRecovery(org, seed)` (the seed signs here and never leaves the process); `newRecoverySeed`, `recoveryPublicKey`.
130
+ - **Files**: `uploadFile(app, data)` (a large file goes up in parts), `exportFile(app, id)` and `exportFileTo(app, id, sink)` (the plaintext, checked against its id, size and hash).
111
131
  - **Blobs**: `downloadBlob(app, id)`, `downloadBlobGranted(app, id, grant)` (bytes; `client.apps.blobDownload` answers a `Blob` with its type).
112
132
  - **Streams**: `events(app, from?, signal?)`, `presenceStream(app, signal?)`.
113
133
  - **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/).
@@ -295,9 +315,9 @@ callable (`(await client.packages.list()).packages`).
295
315
  | `upgradeOrg(org, target, passkey)` | `client.orgs.upgrade({ org, ...target }, { confirm: passkeyConfirm(passkey) })` |
296
316
  | `upgradeRun(org, run)` | `client.orgs.upgradeStatus({ org, run })` |
297
317
  | `retryUpgradeRun(org, run, passkey)` | `client.orgs.upgradeRetry({ org, run }, { confirm: passkeyConfirm(passkey) })` |
298
- | `approveRelease(org, version, passkey, approved)` | `client.auth.accountReleaseApproval({ version, approved }, { confirm: passkeyConfirm(passkey) })` or `client.orgs.releaseApproval({ org, version, approved }, { confirm: passkeyConfirm(passkey) })` |
299
- | `approveOutbound(org, pkg, passkey, options)` | `client.auth.accountOutboundApproval({ package: pkg, ...options }, { confirm: passkeyConfirm(passkey) })` or `client.orgs.outboundApproval({ org, package: pkg, ...options }, { confirm: passkeyConfirm(passkey) })` |
300
- | `appsReport(org, page)` | `client.auth.accountApps({ ...page })` or `client.orgs.apps({ org, ...page })` |
318
+ | `approveRelease(org, version, passkey, approved)` | `client.orgs.releaseApproval({ org, version, approved }, { confirm: passkeyConfirm(passkey) })` (an account's own apps are in its personal organization: approve there; core 1.0.0-rc.20 removed the account-level approval) |
319
+ | `approveOutbound(org, pkg, passkey, options)` | `client.orgs.outboundApproval({ org, package: pkg, ...options }, { confirm: passkeyConfirm(passkey) })` (the personal organization's for the account's own apps, as above) |
320
+ | `appsReport(org, page)` | `client.orgs.apps({ org, ...page })`; `client.auth.accountApps({ ...page })` lists the apps the account owns in any organization |
301
321
  | `releaseRules()` | `client.public.releasesPublic()` |
302
322
  | `requestConsent(request)` | `client.consent.pageCreate({ body: request })` |
303
323
  | `consentResult(requestId)` | `client.consent.pageResult({ request: requestId })` |
@@ -365,11 +385,30 @@ run the client against them:
365
385
  MEROD_BINARY=/path/to/merod KV_STORE_WASM=/path/to/kv_store.wasm pnpm test:cluster
366
386
  ```
367
387
 
368
- Without the variables they use `../core/target/debug/merod` and
369
- `../core/target/wasm32-unknown-unknown/app-release/kv_store.wasm` from a sibling
370
- core checkout. `scripts/download-released-merod.sh` fetches the newest released
371
- 1.0 `merod` and its kv-store fixture, which is what CI runs them against; core's
372
- `e2e.yml` runs the same suite against core's own tree.
388
+ `KV_STORE_WASM` is core's kv component (`apps/v2-fixtures/kv`, a `calimero:app`
389
+ component for `wasm32-wasip2`). Without the variables they use
390
+ `../core/target/debug/merod` and `../core/target/app-components/kv.wasm` from a
391
+ sibling core checkout, built there as core's `e2e.yml` builds them:
392
+
393
+ ```bash
394
+ cargo build -p merod
395
+ scripts/install-mero-app-build.sh
396
+ mero-app-build apps/v2-fixtures/kv --out target/app-components/kv.wasm
397
+ ```
398
+
399
+ `scripts/download-released-merod.sh` fetches the newest released 1.0 `merod`
400
+ and the `app.wasm` of its `kv-store-test-fixture.mpk` (as `./merod` and
401
+ `./kv_store.wasm`), which is what CI runs them against; core's `e2e.yml` runs
402
+ the same suite against core's own tree.
403
+
404
+ ## Related repositories
405
+
406
+ - [core](https://github.com/calimero-network/core): the node (`merod`), the Rust SDK and client, `meroctl`, and the [docs](https://calimero-network.github.io/core/).
407
+ - [mero-tee](https://github.com/calimero-network/mero-tee): the TDX node images and the signed releases this client verifies.
408
+ - [app-registry](https://github.com/calimero-network/app-registry): the registry of signed app packages.
409
+ - [mero-react](https://github.com/calimero-network/mero-react): React bindings built on this client.
410
+ - [calimero-client-py](https://github.com/calimero-network/calimero-client-py), [swift-sdk](https://github.com/calimero-network/swift-sdk), [kotlin-sdk](https://github.com/calimero-network/kotlin-sdk): the clients for Python, Swift and Kotlin.
411
+ - [apps](https://github.com/calimero-network/apps): Calimero apps.
373
412
 
374
413
  ## License
375
414
 
@@ -352,6 +352,7 @@ export declare class CalimeroClient {
352
352
  finishAccountRecovery(passkey: PasskeyProvider, accountId?: string): Promise<CalimeroSession>;
353
353
  /** One of `app`'s blobs, by id (base58 or hex). */
354
354
  downloadBlob(app: string, id: string): Promise<Uint8Array>;
355
+ private get exportClient();
355
356
  /**
356
357
  * Write the plaintext of sealed file `id` of component app `app` to `sink`, checked against its id,
357
358
  * size and hash. On rejection, discard what `sink` received: it is authentic but may be a prefix of
@@ -334,17 +334,20 @@ export class CalimeroClient {
334
334
  async downloadBlob(app, id) {
335
335
  return new Uint8Array(await (await this.apps.blobDownload({ app, id })).arrayBuffer());
336
336
  }
337
+ get exportClient() {
338
+ return { exportsExport: this.apps.exportsExport, request: this.transport.request.bind(this.transport) };
339
+ }
337
340
  /**
338
341
  * Write the plaintext of sealed file `id` of component app `app` to `sink`, checked against its id,
339
342
  * size and hash. On rejection, discard what `sink` received: it is authentic but may be a prefix of
340
343
  * the file. A failed check is an `ExportError`; `signal` aborts the download.
341
344
  */
342
345
  exportFileTo(app, id, sink, signal) {
343
- return exportFileTo(this.transport, app, id, sink, signal);
346
+ return exportFileTo(this.exportClient, app, id, sink, signal);
344
347
  }
345
348
  /** The plaintext of sealed file `id` of component app `app`, in memory; use {@link exportFileTo} for a large one. */
346
349
  exportFile(app, id, signal) {
347
- return exportFile(this.transport, app, id, signal);
350
+ return exportFile(this.exportClient, app, id, signal);
348
351
  }
349
352
  /**
350
353
  * Download a component app's blob with a grant one of its runs handed out
@@ -4,6 +4,7 @@
4
4
  * for this call, and nothing it says is believed until it checks out.
5
5
  */
6
6
  import { type Transport } from '../runtime/transport.js';
7
+ import type { AppsRoutes } from '../generated/methods.js';
7
8
  export { ExportError, type ExportErrorCode } from '../sealed/file.js';
8
9
  /** Where an export writes the plaintext, in order. A `WritableStreamDefaultWriter` fits. */
9
10
  export interface FileSink {
@@ -15,7 +16,7 @@ export interface ExportedFile {
15
16
  /** SHA-256 of the plaintext, hex. */
16
17
  sha256: string;
17
18
  }
18
- type ExportTransport = Pick<Transport, 'json' | 'request'>;
19
+ type ExportTransport = Pick<Transport, 'request'> & Pick<AppsRoutes, 'exportsExport'>;
19
20
  /**
20
21
  * Write the plaintext of sealed file `id` (64 hex) of app `app` to `sink`, one
21
22
  * segment at a time. Each segment is checked against its hash before it is
@@ -96,11 +96,7 @@ export async function exportFileTo(transport, app, id, sink, signal, recipientSe
96
96
  }
97
97
  async function exportChecked(transport, app, id, sink, signal, recipientSecret) {
98
98
  const recipient = await x25519KeyPair(recipientSecret);
99
- // shortcut: not in the generated routes until the next openapi sync; they move there then.
100
- const answer = checked(await transport.json('POST', routePath('apps/{app}/files/{id}/export', { app, id }), {
101
- body: { recipient: hex(recipient.publicKey) },
102
- signal,
103
- }));
99
+ const answer = checked(await transport.exportsExport({ app, id, recipient: hex(recipient.publicKey) }, { signal }));
104
100
  const { segments, named } = answer;
105
101
  if (segments.length === 0 || hex(await fileId(segments)) !== hex(named) || hex(named) !== id) {
106
102
  throw new ExportError('NOT_THE_FILE', `the node answered segments that are not the file ${id}`);
@@ -110,6 +106,7 @@ async function exportChecked(transport, app, id, sink, signal, recipientSecret)
110
106
  for (let k = 0; k < segments.length; k += 1) {
111
107
  if (signal?.aborted)
112
108
  throw aborted();
109
+ // The generated segment method buffers the whole body, so this stays on the streaming request.
113
110
  const response = await transport.request('GET', routePath('apps/{app}/files/{id}/segments/{k}', { app, id, k }), {
114
111
  signal,
115
112
  });
@@ -805,6 +805,28 @@ export interface paths {
805
805
  patch?: never;
806
806
  trace?: never;
807
807
  };
808
+ "/apps/{app}/runs/{run}/logs": {
809
+ parameters: {
810
+ query?: never;
811
+ header?: never;
812
+ path?: never;
813
+ cookie?: never;
814
+ };
815
+ /**
816
+ * A compute run's attempt logs
817
+ * @description Each attempt's module log, as a sealed file of the app: `{ attempt, id, size, sha256 }`. Only for those who may handle the app's files; the bytes are a files export.
818
+ *
819
+ * **Who:** signed in (a session or an API key).
820
+ */
821
+ get: operations["app_run_logs"];
822
+ put?: never;
823
+ post?: never;
824
+ delete?: never;
825
+ options?: never;
826
+ head?: never;
827
+ patch?: never;
828
+ trace?: never;
829
+ };
808
830
  "/apps/{app}/storage": {
809
831
  parameters: {
810
832
  query?: never;
@@ -1622,7 +1644,7 @@ export interface paths {
1622
1644
  };
1623
1645
  /**
1624
1646
  * What became of a consent request
1625
- * @description `decidedAt` (Unix seconds) is `null` while it is pending. `outcome`, once approved, is what the approval made: `{ orgId }` for `createOrg`, `{ token }` for `createInvite`, `{ org }` for `acceptInvite`, `{ orgId, name }` for `renameOrg`, `{ apps }` (the apps deleted) for `deleteOrg`; absent for the other kinds.
1647
+ * @description `decidedAt` (Unix seconds) is `null` while it is pending. `outcome`, once approved, is what the approval made: `{ orgId }` for `createOrg` (with `teamId`, the asking app's own team the organization starts with, when an app's frontend asked on a cluster that makes it), `{ token }` for `createInvite`, `{ org }` for `acceptInvite`, `{ orgId, name }` for `renameOrg`, `{ apps }` (the apps deleted) for `deleteOrg`; absent for the other kinds.
1626
1648
  *
1627
1649
  * **Who:** a passkey session (an API key is refused).
1628
1650
  */
@@ -7589,6 +7611,65 @@ export interface operations {
7589
7611
  };
7590
7612
  };
7591
7613
  };
7614
+ app_run_logs: {
7615
+ parameters: {
7616
+ query?: never;
7617
+ header?: never;
7618
+ path: {
7619
+ app: string;
7620
+ run: string;
7621
+ };
7622
+ cookie?: never;
7623
+ };
7624
+ requestBody?: never;
7625
+ responses: {
7626
+ /** @description OK */
7627
+ 200: {
7628
+ headers: {
7629
+ [name: string]: unknown;
7630
+ };
7631
+ content: {
7632
+ "application/json": {
7633
+ logs: {
7634
+ /** Format: int64 */
7635
+ attempt: number;
7636
+ id: string;
7637
+ /** Format: int64 */
7638
+ size: number;
7639
+ sha256: string;
7640
+ }[];
7641
+ };
7642
+ };
7643
+ };
7644
+ /** @description `UNAUTHENTICATED`: no, unknown, expired or revoked credential */
7645
+ 401: {
7646
+ headers: {
7647
+ [name: string]: unknown;
7648
+ };
7649
+ content: {
7650
+ "application/json": components["schemas"]["Error"];
7651
+ };
7652
+ };
7653
+ /** @description `NOT_FOUND`: no such object, or one the caller may not see */
7654
+ 404: {
7655
+ headers: {
7656
+ [name: string]: unknown;
7657
+ };
7658
+ content: {
7659
+ "application/json": components["schemas"]["Error"];
7660
+ };
7661
+ };
7662
+ /** @description `WRONG_NODE`: this node runs a release the account's owners have not approved, so it neither issues nor takes the account's sessions; send it to another node of the cluster (no `details`; nothing was spent) */
7663
+ 421: {
7664
+ headers: {
7665
+ [name: string]: unknown;
7666
+ };
7667
+ content: {
7668
+ "application/json": components["schemas"]["Error"];
7669
+ };
7670
+ };
7671
+ };
7672
+ };
7592
7673
  app_storage: {
7593
7674
  parameters: {
7594
7675
  query?: never;
@@ -10364,6 +10445,7 @@ export interface operations {
10364
10445
  decidedAt: number | null;
10365
10446
  outcome?: {
10366
10447
  orgId?: string;
10448
+ teamId?: string;
10367
10449
  token?: string;
10368
10450
  org?: string;
10369
10451
  name?: string;
@@ -247,6 +247,13 @@ export declare function createRoutes(api: RouteClient): {
247
247
  * A `421 WRONG_NODE` moves the client to the next node of the cluster.
248
248
  */
249
249
  run: (args: operations["app_run"]["parameters"]["path"], options?: MethodOptions) => Promise<operations["app_run"]["responses"][200]["content"]["application/json"]>;
250
+ /**
251
+ * A compute run's attempt logs.
252
+ *
253
+ * `GET /apps/{app}/runs/{run}/logs` (`app_run_logs`). **Who:** signed in (a session or an API key).
254
+ * A `421 WRONG_NODE` moves the client to the next node of the cluster.
255
+ */
256
+ runLogs: (args: operations["app_run_logs"]["parameters"]["path"], options?: MethodOptions) => Promise<operations["app_run_logs"]["responses"][200]["content"]["application/json"]>;
250
257
  /**
251
258
  * An app's compute runs.
252
259
  *
@@ -255,6 +255,13 @@ export function createRoutes(api) {
255
255
  * A `421 WRONG_NODE` moves the client to the next node of the cluster.
256
256
  */
257
257
  run: (args, options) => route(api, { "method": "GET", "path": "/apps/{app}/runs/{run}", "pathParams": ["app", "run"], "query": [], "body": "none", "optionalBody": false, "reply": "json" }, args, options),
258
+ /**
259
+ * A compute run's attempt logs.
260
+ *
261
+ * `GET /apps/{app}/runs/{run}/logs` (`app_run_logs`). **Who:** signed in (a session or an API key).
262
+ * A `421 WRONG_NODE` moves the client to the next node of the cluster.
263
+ */
264
+ runLogs: (args, options) => route(api, { "method": "GET", "path": "/apps/{app}/runs/{run}/logs", "pathParams": ["app", "run"], "query": [], "body": "none", "optionalBody": false, "reply": "json" }, args, options),
258
265
  /**
259
266
  * An app's compute runs.
260
267
  *