@calimero-network/mero-js 28.0.0 → 28.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/dist/cloud-v2/approvals.d.ts +4 -0
- package/dist/cloud-v2/client.d.ts +245 -3
- package/dist/cloud-v2/client.js +163 -6
- package/dist/cloud-v2/index.d.ts +2 -2
- package/dist/cloud-v2/index.js +1 -1
- package/dist/index.browser.mjs +4 -4
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +148 -6
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +148 -6
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1648,6 +1648,26 @@ function upgradeConsent(app, toVersion, returnTo) {
|
|
|
1648
1648
|
}
|
|
1649
1649
|
|
|
1650
1650
|
// src/cloud-v2/client.ts
|
|
1651
|
+
function deployerKey(deployer) {
|
|
1652
|
+
return "account" in deployer ? `account:${deployer.account}` : `org:${deployer.org}`;
|
|
1653
|
+
}
|
|
1654
|
+
async function frontendManifest(origin, fetcher = fetch) {
|
|
1655
|
+
const base = origin ?? globalThis.location?.origin;
|
|
1656
|
+
if (!base) throw new Error("no page origin to read the frontend manifest from; pass `origin`");
|
|
1657
|
+
const response = await fetcher(new URL("/.well-known/calimero.json", base).toString());
|
|
1658
|
+
if (!response.ok) throw await refusal(response);
|
|
1659
|
+
const manifest = await response.json();
|
|
1660
|
+
return { ...manifest, deployments: manifest.deployments ?? [] };
|
|
1661
|
+
}
|
|
1662
|
+
function pageDeployment(href) {
|
|
1663
|
+
const at = href ?? globalThis.location?.href;
|
|
1664
|
+
if (!at) return null;
|
|
1665
|
+
try {
|
|
1666
|
+
return new URL(at).searchParams.get("deployment") || null;
|
|
1667
|
+
} catch {
|
|
1668
|
+
return null;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1651
1671
|
function seg(value) {
|
|
1652
1672
|
return encodeURIComponent(value);
|
|
1653
1673
|
}
|
|
@@ -2106,14 +2126,41 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2106
2126
|
const { hash } = await this.json("POST", "bundles", void 0, wasm);
|
|
2107
2127
|
return hash;
|
|
2108
2128
|
}
|
|
2109
|
-
/**
|
|
2110
|
-
|
|
2111
|
-
|
|
2129
|
+
/**
|
|
2130
|
+
* Upload a blob for `app`: `blobId` is base58 (what apps print), `id` hex.
|
|
2131
|
+
* `contentType` (default `application/octet-stream`; printable ASCII, the
|
|
2132
|
+
* node refuses another with `400`) is sent as the upload's `Content-Type`:
|
|
2133
|
+
* a component app records it and serves downloads with it. A component
|
|
2134
|
+
* app holding as many blobs as it may answers `429 QUOTA_EXCEEDED`.
|
|
2135
|
+
*/
|
|
2136
|
+
uploadBlob(app, data, contentType = {}) {
|
|
2137
|
+
const mime = (typeof contentType === "string" ? contentType : contentType.contentType) ?? "application/octet-stream";
|
|
2138
|
+
return this.json("POST", `apps/${seg(app)}/blobs`, void 0, data, mime);
|
|
2112
2139
|
}
|
|
2113
2140
|
/** One of `app`'s blobs, by id (base58 or hex). */
|
|
2114
2141
|
async downloadBlob(app, id) {
|
|
2115
|
-
|
|
2116
|
-
|
|
2142
|
+
return (await this.blobContent(app, id)).data;
|
|
2143
|
+
}
|
|
2144
|
+
/**
|
|
2145
|
+
* Download a component app's blob with a grant one of its runs handed out
|
|
2146
|
+
* (`BlobRef::grant`, up to 24 h). No session needed: the grant is the
|
|
2147
|
+
* permission. A bad or expired grant answers `NotFound`, as a missing blob.
|
|
2148
|
+
*/
|
|
2149
|
+
async downloadBlobGranted(app, id, grant) {
|
|
2150
|
+
return (await this.blobContent(app, id, { grant })).data;
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* {@link downloadBlob} (or, with `grant`, {@link downloadBlobGranted}) with
|
|
2154
|
+
* the content type the node serves it as: the uploader's, for a component
|
|
2155
|
+
* app; `application/octet-stream` otherwise.
|
|
2156
|
+
*/
|
|
2157
|
+
async blobContent(app, id, options = {}) {
|
|
2158
|
+
const query = options.grant === void 0 ? "" : `?grant=${encodeURIComponent(options.grant)}`;
|
|
2159
|
+
const response = await this.send("GET", `apps/${seg(app)}/blobs/${seg(id)}${query}`);
|
|
2160
|
+
return {
|
|
2161
|
+
data: new Uint8Array(await response.arrayBuffer()),
|
|
2162
|
+
contentType: response.headers.get("content-type") ?? "application/octet-stream"
|
|
2163
|
+
};
|
|
2117
2164
|
}
|
|
2118
2165
|
/** `app`'s blobs. */
|
|
2119
2166
|
async listBlobs(app) {
|
|
@@ -2175,6 +2222,15 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2175
2222
|
async setAppMetadata(app, metadata) {
|
|
2176
2223
|
await this.post(`apps/${seg(app)}/metadata`, { metadata });
|
|
2177
2224
|
}
|
|
2225
|
+
/**
|
|
2226
|
+
* A component app's xcalls: how many messages wait in its outbox, and the
|
|
2227
|
+
* dead letters (never delivered), newest last. Its owner's or an org
|
|
2228
|
+
* admin's (`403` to anyone else); `409 NOT_SUPPORTED` for an app on the
|
|
2229
|
+
* wasmer runtime, whose xcalls are follow-ups.
|
|
2230
|
+
*/
|
|
2231
|
+
appXcalls(app) {
|
|
2232
|
+
return this.get(`apps/${seg(app)}/xcalls`);
|
|
2233
|
+
}
|
|
2178
2234
|
/** What the app's storage holds: `{ keys, bytes, blobs, blobBytes }`. */
|
|
2179
2235
|
appStorage(app) {
|
|
2180
2236
|
return this.get(`apps/${seg(app)}/storage`);
|
|
@@ -2242,7 +2298,13 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2242
2298
|
/**
|
|
2243
2299
|
* Create an app instance from a bundle hash, or from a package release
|
|
2244
2300
|
* (`{ package, version?, service? }`, installed from the registry first if
|
|
2245
|
-
* the cluster lacks it).
|
|
2301
|
+
* the cluster lacks it). With `deployment`, the instance runs the release
|
|
2302
|
+
* that deployment offers for `package` (`version`, if given, must be it)
|
|
2303
|
+
* and records the deployment; no install, no deployer grant. A package or
|
|
2304
|
+
* version it does not offer answers `400 NOT_OFFERED`, several offered
|
|
2305
|
+
* releases with no `version` `400 VERSION_REQUIRED`, and an unknown
|
|
2306
|
+
* `service` `400 NO_SUCH_SERVICE`. A page opened through `/d/{deployment}/`
|
|
2307
|
+
* finds its deployment with {@link pageDeployment}.
|
|
2246
2308
|
*/
|
|
2247
2309
|
async createApp(name, bundle, options = {}) {
|
|
2248
2310
|
const target = typeof bundle === "string" ? { bundle } : bundle;
|
|
@@ -2614,6 +2676,83 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
2614
2676
|
redeemInvite(token) {
|
|
2615
2677
|
return this.post(`invites/${seg(token)}/redeem`);
|
|
2616
2678
|
}
|
|
2679
|
+
// ---------------------------------------------------------------- deployers
|
|
2680
|
+
/**
|
|
2681
|
+
* Let an account or organization install apps where the cluster's
|
|
2682
|
+
* deployments are `granted`, until `until` (RFC 3339 or a `Date`; absent,
|
|
2683
|
+
* the grant does not end). The cluster's owner grants it, approved with
|
|
2684
|
+
* `passkey`, where governance says `deployers: owner`; elsewhere the
|
|
2685
|
+
* operator grants with its key, and this is refused `403`.
|
|
2686
|
+
*/
|
|
2687
|
+
grantDeployer(deployer, passkey, options = {}) {
|
|
2688
|
+
const until = options.until instanceof Date ? options.until.toISOString() : options.until;
|
|
2689
|
+
return this.postConfirmed("deployers", { deployer, ...until === void 0 ? {} : { until } }, passkey);
|
|
2690
|
+
}
|
|
2691
|
+
/**
|
|
2692
|
+
* Who may install apps on the cluster: its deployments rule, who grants
|
|
2693
|
+
* deployers, its owner and every grant. For the cluster's owner, or the
|
|
2694
|
+
* operator (its token, `useApiKey`).
|
|
2695
|
+
*/
|
|
2696
|
+
deployers() {
|
|
2697
|
+
return this.get("deployers");
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* End a deployer's grant (`deployer`, or its key `account:{id}` /
|
|
2701
|
+
* `org:{id}`), as the cluster's owner, approved with `passkey`. Apps it
|
|
2702
|
+
* installed, and the apps running them, stay.
|
|
2703
|
+
*/
|
|
2704
|
+
async revokeDeployer(deployer, passkey) {
|
|
2705
|
+
const key = typeof deployer === "string" ? deployer : deployerKey(deployer);
|
|
2706
|
+
await this.deleteConfirmed(`deployers/${seg(key)}`, passkey);
|
|
2707
|
+
}
|
|
2708
|
+
// ---------------------------------------------------------------- deployments
|
|
2709
|
+
/**
|
|
2710
|
+
* Create a deployment: `owner`'s (the caller's own account, or an
|
|
2711
|
+
* organization where it holds `MANAGE_APPLICATION` org-wide) list of the
|
|
2712
|
+
* apps it offers, named `name` (1 to 64 characters, one line) for
|
|
2713
|
+
* customers. Approved with `passkey`; where deployments are `granted` the
|
|
2714
|
+
* caller needs a deployer grant. Answers the deployment's id.
|
|
2715
|
+
*/
|
|
2716
|
+
async createDeployment(name, owner, passkey) {
|
|
2717
|
+
const { id } = await this.postConfirmed("deployments", { name, owner }, passkey);
|
|
2718
|
+
return id;
|
|
2719
|
+
}
|
|
2720
|
+
/** The deployments the caller manages: its account's, and its organizations' where it holds `MANAGE_APPLICATION`. */
|
|
2721
|
+
async deployments() {
|
|
2722
|
+
const { deployments } = await this.get("deployments");
|
|
2723
|
+
return deployments;
|
|
2724
|
+
}
|
|
2725
|
+
/** A deployment as anyone may read it: its name, its owner's kind and name, and the apps it offers. Public. */
|
|
2726
|
+
deployment(id) {
|
|
2727
|
+
return this.get(`deployments/${seg(id)}`);
|
|
2728
|
+
}
|
|
2729
|
+
/** Delete a deployment that offers nothing and has no instances, approved with `passkey`. */
|
|
2730
|
+
async deleteDeployment(id, passkey) {
|
|
2731
|
+
await this.deleteConfirmed(`deployments/${seg(id)}`, passkey);
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Offer `package@version` (installed, and seen by the caller) as `app`
|
|
2735
|
+
* (1 to 64 letters, digits, `.`, `_`, `-`) in deployment `id`, or move an
|
|
2736
|
+
* offered app to another release of its package. Approved with `passkey`.
|
|
2737
|
+
*/
|
|
2738
|
+
offerApp(id, offer, passkey) {
|
|
2739
|
+
return this.postConfirmed(`deployments/${seg(id)}/apps`, { ...offer }, passkey);
|
|
2740
|
+
}
|
|
2741
|
+
/**
|
|
2742
|
+
* Withdraw `app` from deployment `id`, approved with `passkey`; refused
|
|
2743
|
+
* while an instance created from the deployment still runs it.
|
|
2744
|
+
*/
|
|
2745
|
+
async withdrawApp(id, app, passkey) {
|
|
2746
|
+
await this.deleteConfirmed(`deployments/${seg(id)}/apps/${seg(app)}`, passkey);
|
|
2747
|
+
}
|
|
2748
|
+
/**
|
|
2749
|
+
* The organizations with instances created from deployment `id`, for its
|
|
2750
|
+
* managers: each one's id, name, instance count, apps and releases, and
|
|
2751
|
+
* first instance. Never members, teams or app data.
|
|
2752
|
+
*/
|
|
2753
|
+
deploymentOrgs(id) {
|
|
2754
|
+
return this.get(`deployments/${seg(id)}/orgs`);
|
|
2755
|
+
}
|
|
2617
2756
|
};
|
|
2618
2757
|
|
|
2619
2758
|
// src/cloud-v2/capabilities.ts
|
|
@@ -3133,15 +3272,18 @@ export {
|
|
|
3133
3272
|
createQuoteVerifier,
|
|
3134
3273
|
createSealedFetch,
|
|
3135
3274
|
createSignedReleaseVerifier,
|
|
3275
|
+
deployerKey,
|
|
3136
3276
|
errorFrom,
|
|
3137
3277
|
fetchAttestedKey,
|
|
3138
3278
|
fetchGithubNodeRelease,
|
|
3139
3279
|
fetchNodeRelease,
|
|
3140
3280
|
freshCollateral,
|
|
3141
3281
|
fromB64url,
|
|
3282
|
+
frontendManifest,
|
|
3142
3283
|
generateOwnerKey,
|
|
3143
3284
|
orgCapabilities,
|
|
3144
3285
|
ownerPublicKey,
|
|
3286
|
+
pageDeployment,
|
|
3145
3287
|
pageQuery,
|
|
3146
3288
|
pendingApprovalsFrom,
|
|
3147
3289
|
provisionAgent,
|