@calimero-network/mero-js 18.0.0 → 18.1.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/dist/index.cjs CHANGED
@@ -928,16 +928,7 @@ var AdminApiClient = class {
928
928
  const body = { ...request, initializationParams: request.initializationParams ?? [] };
929
929
  return unwrap(await this.httpClient.post("/admin-api/contexts", body));
930
930
  }
931
- async deleteContext(contextId, request) {
932
- if (request) {
933
- return unwrap(
934
- await this.httpClient.request(`/admin-api/contexts/${contextId}`, {
935
- method: "DELETE",
936
- body: JSON.stringify(request),
937
- headers: { "Content-Type": "application/json" }
938
- })
939
- );
940
- }
931
+ async deleteContext(contextId) {
941
932
  return unwrap(await this.httpClient.delete(`/admin-api/contexts/${contextId}`));
942
933
  }
943
934
  async getContexts() {
@@ -1193,17 +1184,14 @@ var AdminApiClient = class {
1193
1184
  }
1194
1185
  async createNamespace(request) {
1195
1186
  return unwrap(
1196
- await this.httpClient.post("/admin-api/namespaces", {
1197
- upgradePolicy: "LazyOnAccess",
1198
- ...request
1199
- })
1187
+ await this.httpClient.post("/admin-api/namespaces", request)
1200
1188
  );
1201
1189
  }
1202
- async deleteNamespace(namespaceId, request) {
1190
+ async deleteNamespace(namespaceId) {
1203
1191
  return unwrap(
1204
1192
  await this.httpClient.request(`/admin-api/namespaces/${namespaceId}`, {
1205
1193
  method: "DELETE",
1206
- body: JSON.stringify(request ?? {}),
1194
+ body: "{}",
1207
1195
  headers: { "Content-Type": "application/json" }
1208
1196
  })
1209
1197
  );
@@ -1266,6 +1254,128 @@ var AdminApiClient = class {
1266
1254
  async listNamespaceGroups(namespaceId) {
1267
1255
  return unwrap(await this.httpClient.get(`/admin-api/namespaces/${namespaceId}/groups`));
1268
1256
  }
1257
+ // ---- Account Devices & Pairing ----
1258
+ /**
1259
+ * Mint this node a device for an account that already lives somewhere else -
1260
+ * the first half of pairing, run on the joining node.
1261
+ *
1262
+ * Publishes nothing and needs no key: it produces the device id, the two
1263
+ * public keys and the signature that the account holder's
1264
+ * {@link completeAccountPairing} certifies, plus a code to read out to them
1265
+ * over a channel the payload does not travel on. Until that second half runs,
1266
+ * the device this mints is inert.
1267
+ *
1268
+ * Takes a set of namespaces rather than one, and takes it from the caller
1269
+ * because this node cannot discover it: a node that is a member of nothing can
1270
+ * neither read the account's namespace set off a DAG nor derive it. One device
1271
+ * covers however many are named - the certificate is over the account, not a
1272
+ * scope - so there is one id and one code to hand over regardless.
1273
+ */
1274
+ async initAccountPairing(request) {
1275
+ return unwrap(
1276
+ await this.httpClient.post("/admin-api/account/pair-init", request)
1277
+ );
1278
+ }
1279
+ /**
1280
+ * Certify a device another node minted, link it, and deliver its scope keys -
1281
+ * the second half of pairing, run on the node that holds the account root.
1282
+ *
1283
+ * Every field but `applications` is copied verbatim out of that node's
1284
+ * {@link initAccountPairing} answer. Only this side can complete it: the
1285
+ * certificate is signed by the account root, which never leaves the node that
1286
+ * holds it.
1287
+ *
1288
+ * The scope is named in applications, not namespaces, because that is the
1289
+ * question a person can answer - a namespace is an implementation unit they
1290
+ * never chose. Leave it out to grant every application.
1291
+ */
1292
+ async completeAccountPairing(request) {
1293
+ return unwrap(
1294
+ await this.httpClient.post("/admin-api/account/pair-complete", request)
1295
+ );
1296
+ }
1297
+ /**
1298
+ * Re-run the pairing fan-out for a device this account already certified,
1299
+ * against the namespaces this node takes part in now.
1300
+ *
1301
+ * Pairing is a snapshot, and this is how it is repeated. A namespace created
1302
+ * or joined afterwards holds no binding for a device paired before it, and the
1303
+ * symptom is silence - the device simply never sees that namespace. Nothing
1304
+ * but the id is needed to repair it: the certificate is already held here,
1305
+ * root-signed and naming no namespace, so a fresh endorsement and a key wrap
1306
+ * are all a later namespace is missing. The device does not have to be online.
1307
+ *
1308
+ * Passing `applications` widens the device's stored scope as well as
1309
+ * repairing. Passing none - or an empty list - repairs against the scope
1310
+ * already stored, which is deliberately NOT the "every application" that an
1311
+ * empty list means on {@link completeAccountPairing}: overloading it here
1312
+ * would make the accidental request the widest one.
1313
+ */
1314
+ async relinkAccountDevice(deviceId, request) {
1315
+ return unwrap(
1316
+ await this.httpClient.post(
1317
+ `/admin-api/account/devices/${deviceId}/relink`,
1318
+ request ?? {}
1319
+ )
1320
+ );
1321
+ }
1322
+ /**
1323
+ * Every device of this account, as this node sees them - its own included.
1324
+ *
1325
+ * Joined from the node-local certificate cache and the live bindings of every
1326
+ * namespace this node takes part in, so it is this node's view rather than a
1327
+ * global one: a device certified by another holder appears with an empty
1328
+ * `applications`, because the certificate that would name its scope is not
1329
+ * cached here.
1330
+ *
1331
+ * The wire wraps this in `devices` rather than the usual `data`; the array is
1332
+ * what a caller wants, so that wrapper is not passed on.
1333
+ */
1334
+ async listAccountDevices() {
1335
+ const response = await this.httpClient.get("/admin-api/account/devices");
1336
+ return response.devices;
1337
+ }
1338
+ /**
1339
+ * Every application this account speaks in, with the namespaces targeting each.
1340
+ *
1341
+ * What a device-scoping UI lists: {@link completeAccountPairing} and
1342
+ * {@link relinkAccountDevice} both take applications, and this is where the
1343
+ * ids they take come from. Derived from the namespaces this node takes part
1344
+ * in, so an application installed with no namespace yet is absent - it has
1345
+ * nothing to scope a device to until one exists.
1346
+ *
1347
+ * Wrapped in `applications` on the wire rather than `data`, unwrapped here for
1348
+ * the same reason {@link listAccountDevices} unwraps `devices`.
1349
+ */
1350
+ async listAccountApplications() {
1351
+ const response = await this.httpClient.get(
1352
+ "/admin-api/account/applications"
1353
+ );
1354
+ return response.applications;
1355
+ }
1356
+ /**
1357
+ * Withdraw a device from this account, terminally.
1358
+ *
1359
+ * Two authorities reach the same endpoint. An admin may revoke any device and
1360
+ * rotates the scope key as it goes. The account holder may revoke its own with
1361
+ * a root-signed `proof`, which does not rotate - so read
1362
+ * {@link RevokeAccountDeviceResponseData.revokedIn} rather than assuming the
1363
+ * device lost its access: a namespace reporting `keyRotated: false` has
1364
+ * stopped the device writing but leaves it able to read until an admin
1365
+ * rotates.
1366
+ *
1367
+ * `namespaceId` names where to publish from, not the extent of the revocation:
1368
+ * a device belongs to the account, so every namespace holding a binding for it
1369
+ * is withdrawn from and reported back.
1370
+ */
1371
+ async revokeAccountDevice(namespaceId, request) {
1372
+ return unwrap(
1373
+ await this.httpClient.post(
1374
+ `/admin-api/namespaces/${namespaceId}/account/revoke`,
1375
+ request
1376
+ )
1377
+ );
1378
+ }
1269
1379
  // ---- Group Management ----
1270
1380
  async getGroupInfo(groupId) {
1271
1381
  return unwrap(await this.httpClient.get(`/admin-api/groups/${groupId}`));
@@ -1278,11 +1388,11 @@ var AdminApiClient = class {
1278
1388
  async getSubgroupVisibility(groupId) {
1279
1389
  return (await this.getGroupInfo(groupId)).subgroupVisibility;
1280
1390
  }
1281
- async deleteGroup(groupId, request) {
1391
+ async deleteGroup(groupId) {
1282
1392
  return unwrap(
1283
1393
  await this.httpClient.request(`/admin-api/groups/${groupId}`, {
1284
1394
  method: "DELETE",
1285
- body: JSON.stringify(request ?? {}),
1395
+ body: "{}",
1286
1396
  headers: { "Content-Type": "application/json" }
1287
1397
  })
1288
1398
  );
@@ -1382,8 +1492,8 @@ var AdminApiClient = class {
1382
1492
  );
1383
1493
  return response?.data ?? null;
1384
1494
  }
1385
- async syncGroup(groupId, request) {
1386
- return unwrap(await this.httpClient.post(`/admin-api/groups/${groupId}/sync`, request ?? {}));
1495
+ async syncGroup(groupId) {
1496
+ return unwrap(await this.httpClient.post(`/admin-api/groups/${groupId}/sync`, {}));
1387
1497
  }
1388
1498
  async upgradeGroup(groupId, request) {
1389
1499
  return unwrap(await this.httpClient.post(`/admin-api/groups/${groupId}/upgrade`, request));
@@ -1409,11 +1519,11 @@ var AdminApiClient = class {
1409
1519
  await this.httpClient.get(`/admin-api/groups/${id}/cascade-status`)
1410
1520
  );
1411
1521
  }
1412
- async retryGroupUpgrade(groupId, request) {
1522
+ async retryGroupUpgrade(groupId) {
1413
1523
  return unwrap(
1414
1524
  await this.httpClient.post(
1415
1525
  `/admin-api/groups/${groupId}/upgrade/retry`,
1416
- request ?? {}
1526
+ {}
1417
1527
  )
1418
1528
  );
1419
1529
  }
@@ -1428,8 +1538,8 @@ var AdminApiClient = class {
1428
1538
  );
1429
1539
  return response.subgroups ?? response.data ?? [];
1430
1540
  }
1431
- async detachContextFromGroup(groupId, contextId, request) {
1432
- await this.httpClient.post(`/admin-api/groups/${groupId}/contexts/${contextId}/remove`, request ?? {});
1541
+ async detachContextFromGroup(groupId, contextId) {
1542
+ await this.httpClient.post(`/admin-api/groups/${groupId}/contexts/${contextId}/remove`, {});
1433
1543
  }
1434
1544
  // ---- Group Invitation & Join ----
1435
1545
  async createGroupInvitation(groupId, request) {
@@ -1485,33 +1595,33 @@ var AdminApiClient = class {
1485
1595
  /** Create a standalone group (POST /admin-api/groups). */
1486
1596
  async createGroup(request) {
1487
1597
  return unwrap(
1488
- await this.httpClient.post("/admin-api/groups", {
1489
- upgradePolicy: "LazyOnAccess",
1490
- ...request
1491
- })
1598
+ await this.httpClient.post("/admin-api/groups", request)
1492
1599
  );
1493
1600
  }
1494
1601
  /** Leave a group (POST /admin-api/groups/:group_id/leave). */
1495
- async leaveGroup(groupId, request) {
1496
- await this.httpClient.post(`/admin-api/groups/${groupId}/leave`, request ?? {});
1602
+ async leaveGroup(groupId) {
1603
+ await this.httpClient.post(`/admin-api/groups/${groupId}/leave`, {});
1497
1604
  }
1498
1605
  /** Leave a context (POST /admin-api/contexts/:context_id/leave). */
1499
- async leaveContext(contextId, request) {
1500
- await this.httpClient.post(`/admin-api/contexts/${contextId}/leave`, request ?? {});
1606
+ async leaveContext(contextId) {
1607
+ await this.httpClient.post(`/admin-api/contexts/${contextId}/leave`, {});
1501
1608
  }
1502
1609
  /** Leave a namespace (POST /admin-api/namespaces/:namespace_id/leave). */
1503
- async leaveNamespace(namespaceId, request) {
1504
- await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/leave`, request ?? {});
1610
+ async leaveNamespace(namespaceId) {
1611
+ await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/leave`, {});
1505
1612
  }
1506
1613
  /** Issue a group ownership proof (POST /admin-api/groups/:group_id/issue-ownership-proof). */
1507
1614
  async issueOwnershipProof(groupId, request) {
1508
- return this.httpClient.post(`/admin-api/groups/${groupId}/issue-ownership-proof`, request ?? {});
1615
+ return this.httpClient.post(
1616
+ `/admin-api/groups/${groupId}/issue-ownership-proof`,
1617
+ request
1618
+ );
1509
1619
  }
1510
1620
  /** Issue a namespace ownership proof (POST /admin-api/groups/:group_id/issue-namespace-ownership-proof). */
1511
1621
  async issueNamespaceOwnershipProof(groupId, request) {
1512
1622
  return this.httpClient.post(
1513
1623
  `/admin-api/groups/${groupId}/issue-namespace-ownership-proof`,
1514
- request ?? {}
1624
+ request
1515
1625
  );
1516
1626
  }
1517
1627
  /**
@@ -1526,11 +1636,8 @@ var AdminApiClient = class {
1526
1636
  await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/auto-follow`, request);
1527
1637
  }
1528
1638
  /** Abort a namespace migration (POST /admin-api/groups/:namespace_id/migration/abort). */
1529
- async abortMigration(namespaceId, request) {
1530
- return this.httpClient.post(
1531
- `/admin-api/groups/${namespaceId}/migration/abort`,
1532
- request ?? {}
1533
- );
1639
+ async abortMigration(namespaceId) {
1640
+ return this.httpClient.post(`/admin-api/groups/${namespaceId}/migration/abort`, {});
1534
1641
  }
1535
1642
  };
1536
1643