@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.mjs CHANGED
@@ -851,16 +851,7 @@ var AdminApiClient = class {
851
851
  const body = { ...request, initializationParams: request.initializationParams ?? [] };
852
852
  return unwrap(await this.httpClient.post("/admin-api/contexts", body));
853
853
  }
854
- async deleteContext(contextId, request) {
855
- if (request) {
856
- return unwrap(
857
- await this.httpClient.request(`/admin-api/contexts/${contextId}`, {
858
- method: "DELETE",
859
- body: JSON.stringify(request),
860
- headers: { "Content-Type": "application/json" }
861
- })
862
- );
863
- }
854
+ async deleteContext(contextId) {
864
855
  return unwrap(await this.httpClient.delete(`/admin-api/contexts/${contextId}`));
865
856
  }
866
857
  async getContexts() {
@@ -1116,17 +1107,14 @@ var AdminApiClient = class {
1116
1107
  }
1117
1108
  async createNamespace(request) {
1118
1109
  return unwrap(
1119
- await this.httpClient.post("/admin-api/namespaces", {
1120
- upgradePolicy: "LazyOnAccess",
1121
- ...request
1122
- })
1110
+ await this.httpClient.post("/admin-api/namespaces", request)
1123
1111
  );
1124
1112
  }
1125
- async deleteNamespace(namespaceId, request) {
1113
+ async deleteNamespace(namespaceId) {
1126
1114
  return unwrap(
1127
1115
  await this.httpClient.request(`/admin-api/namespaces/${namespaceId}`, {
1128
1116
  method: "DELETE",
1129
- body: JSON.stringify(request ?? {}),
1117
+ body: "{}",
1130
1118
  headers: { "Content-Type": "application/json" }
1131
1119
  })
1132
1120
  );
@@ -1189,6 +1177,128 @@ var AdminApiClient = class {
1189
1177
  async listNamespaceGroups(namespaceId) {
1190
1178
  return unwrap(await this.httpClient.get(`/admin-api/namespaces/${namespaceId}/groups`));
1191
1179
  }
1180
+ // ---- Account Devices & Pairing ----
1181
+ /**
1182
+ * Mint this node a device for an account that already lives somewhere else -
1183
+ * the first half of pairing, run on the joining node.
1184
+ *
1185
+ * Publishes nothing and needs no key: it produces the device id, the two
1186
+ * public keys and the signature that the account holder's
1187
+ * {@link completeAccountPairing} certifies, plus a code to read out to them
1188
+ * over a channel the payload does not travel on. Until that second half runs,
1189
+ * the device this mints is inert.
1190
+ *
1191
+ * Takes a set of namespaces rather than one, and takes it from the caller
1192
+ * because this node cannot discover it: a node that is a member of nothing can
1193
+ * neither read the account's namespace set off a DAG nor derive it. One device
1194
+ * covers however many are named - the certificate is over the account, not a
1195
+ * scope - so there is one id and one code to hand over regardless.
1196
+ */
1197
+ async initAccountPairing(request) {
1198
+ return unwrap(
1199
+ await this.httpClient.post("/admin-api/account/pair-init", request)
1200
+ );
1201
+ }
1202
+ /**
1203
+ * Certify a device another node minted, link it, and deliver its scope keys -
1204
+ * the second half of pairing, run on the node that holds the account root.
1205
+ *
1206
+ * Every field but `applications` is copied verbatim out of that node's
1207
+ * {@link initAccountPairing} answer. Only this side can complete it: the
1208
+ * certificate is signed by the account root, which never leaves the node that
1209
+ * holds it.
1210
+ *
1211
+ * The scope is named in applications, not namespaces, because that is the
1212
+ * question a person can answer - a namespace is an implementation unit they
1213
+ * never chose. Leave it out to grant every application.
1214
+ */
1215
+ async completeAccountPairing(request) {
1216
+ return unwrap(
1217
+ await this.httpClient.post("/admin-api/account/pair-complete", request)
1218
+ );
1219
+ }
1220
+ /**
1221
+ * Re-run the pairing fan-out for a device this account already certified,
1222
+ * against the namespaces this node takes part in now.
1223
+ *
1224
+ * Pairing is a snapshot, and this is how it is repeated. A namespace created
1225
+ * or joined afterwards holds no binding for a device paired before it, and the
1226
+ * symptom is silence - the device simply never sees that namespace. Nothing
1227
+ * but the id is needed to repair it: the certificate is already held here,
1228
+ * root-signed and naming no namespace, so a fresh endorsement and a key wrap
1229
+ * are all a later namespace is missing. The device does not have to be online.
1230
+ *
1231
+ * Passing `applications` widens the device's stored scope as well as
1232
+ * repairing. Passing none - or an empty list - repairs against the scope
1233
+ * already stored, which is deliberately NOT the "every application" that an
1234
+ * empty list means on {@link completeAccountPairing}: overloading it here
1235
+ * would make the accidental request the widest one.
1236
+ */
1237
+ async relinkAccountDevice(deviceId, request) {
1238
+ return unwrap(
1239
+ await this.httpClient.post(
1240
+ `/admin-api/account/devices/${deviceId}/relink`,
1241
+ request ?? {}
1242
+ )
1243
+ );
1244
+ }
1245
+ /**
1246
+ * Every device of this account, as this node sees them - its own included.
1247
+ *
1248
+ * Joined from the node-local certificate cache and the live bindings of every
1249
+ * namespace this node takes part in, so it is this node's view rather than a
1250
+ * global one: a device certified by another holder appears with an empty
1251
+ * `applications`, because the certificate that would name its scope is not
1252
+ * cached here.
1253
+ *
1254
+ * The wire wraps this in `devices` rather than the usual `data`; the array is
1255
+ * what a caller wants, so that wrapper is not passed on.
1256
+ */
1257
+ async listAccountDevices() {
1258
+ const response = await this.httpClient.get("/admin-api/account/devices");
1259
+ return response.devices;
1260
+ }
1261
+ /**
1262
+ * Every application this account speaks in, with the namespaces targeting each.
1263
+ *
1264
+ * What a device-scoping UI lists: {@link completeAccountPairing} and
1265
+ * {@link relinkAccountDevice} both take applications, and this is where the
1266
+ * ids they take come from. Derived from the namespaces this node takes part
1267
+ * in, so an application installed with no namespace yet is absent - it has
1268
+ * nothing to scope a device to until one exists.
1269
+ *
1270
+ * Wrapped in `applications` on the wire rather than `data`, unwrapped here for
1271
+ * the same reason {@link listAccountDevices} unwraps `devices`.
1272
+ */
1273
+ async listAccountApplications() {
1274
+ const response = await this.httpClient.get(
1275
+ "/admin-api/account/applications"
1276
+ );
1277
+ return response.applications;
1278
+ }
1279
+ /**
1280
+ * Withdraw a device from this account, terminally.
1281
+ *
1282
+ * Two authorities reach the same endpoint. An admin may revoke any device and
1283
+ * rotates the scope key as it goes. The account holder may revoke its own with
1284
+ * a root-signed `proof`, which does not rotate - so read
1285
+ * {@link RevokeAccountDeviceResponseData.revokedIn} rather than assuming the
1286
+ * device lost its access: a namespace reporting `keyRotated: false` has
1287
+ * stopped the device writing but leaves it able to read until an admin
1288
+ * rotates.
1289
+ *
1290
+ * `namespaceId` names where to publish from, not the extent of the revocation:
1291
+ * a device belongs to the account, so every namespace holding a binding for it
1292
+ * is withdrawn from and reported back.
1293
+ */
1294
+ async revokeAccountDevice(namespaceId, request) {
1295
+ return unwrap(
1296
+ await this.httpClient.post(
1297
+ `/admin-api/namespaces/${namespaceId}/account/revoke`,
1298
+ request
1299
+ )
1300
+ );
1301
+ }
1192
1302
  // ---- Group Management ----
1193
1303
  async getGroupInfo(groupId) {
1194
1304
  return unwrap(await this.httpClient.get(`/admin-api/groups/${groupId}`));
@@ -1201,11 +1311,11 @@ var AdminApiClient = class {
1201
1311
  async getSubgroupVisibility(groupId) {
1202
1312
  return (await this.getGroupInfo(groupId)).subgroupVisibility;
1203
1313
  }
1204
- async deleteGroup(groupId, request) {
1314
+ async deleteGroup(groupId) {
1205
1315
  return unwrap(
1206
1316
  await this.httpClient.request(`/admin-api/groups/${groupId}`, {
1207
1317
  method: "DELETE",
1208
- body: JSON.stringify(request ?? {}),
1318
+ body: "{}",
1209
1319
  headers: { "Content-Type": "application/json" }
1210
1320
  })
1211
1321
  );
@@ -1305,8 +1415,8 @@ var AdminApiClient = class {
1305
1415
  );
1306
1416
  return response?.data ?? null;
1307
1417
  }
1308
- async syncGroup(groupId, request) {
1309
- return unwrap(await this.httpClient.post(`/admin-api/groups/${groupId}/sync`, request ?? {}));
1418
+ async syncGroup(groupId) {
1419
+ return unwrap(await this.httpClient.post(`/admin-api/groups/${groupId}/sync`, {}));
1310
1420
  }
1311
1421
  async upgradeGroup(groupId, request) {
1312
1422
  return unwrap(await this.httpClient.post(`/admin-api/groups/${groupId}/upgrade`, request));
@@ -1332,11 +1442,11 @@ var AdminApiClient = class {
1332
1442
  await this.httpClient.get(`/admin-api/groups/${id}/cascade-status`)
1333
1443
  );
1334
1444
  }
1335
- async retryGroupUpgrade(groupId, request) {
1445
+ async retryGroupUpgrade(groupId) {
1336
1446
  return unwrap(
1337
1447
  await this.httpClient.post(
1338
1448
  `/admin-api/groups/${groupId}/upgrade/retry`,
1339
- request ?? {}
1449
+ {}
1340
1450
  )
1341
1451
  );
1342
1452
  }
@@ -1351,8 +1461,8 @@ var AdminApiClient = class {
1351
1461
  );
1352
1462
  return response.subgroups ?? response.data ?? [];
1353
1463
  }
1354
- async detachContextFromGroup(groupId, contextId, request) {
1355
- await this.httpClient.post(`/admin-api/groups/${groupId}/contexts/${contextId}/remove`, request ?? {});
1464
+ async detachContextFromGroup(groupId, contextId) {
1465
+ await this.httpClient.post(`/admin-api/groups/${groupId}/contexts/${contextId}/remove`, {});
1356
1466
  }
1357
1467
  // ---- Group Invitation & Join ----
1358
1468
  async createGroupInvitation(groupId, request) {
@@ -1408,33 +1518,33 @@ var AdminApiClient = class {
1408
1518
  /** Create a standalone group (POST /admin-api/groups). */
1409
1519
  async createGroup(request) {
1410
1520
  return unwrap(
1411
- await this.httpClient.post("/admin-api/groups", {
1412
- upgradePolicy: "LazyOnAccess",
1413
- ...request
1414
- })
1521
+ await this.httpClient.post("/admin-api/groups", request)
1415
1522
  );
1416
1523
  }
1417
1524
  /** Leave a group (POST /admin-api/groups/:group_id/leave). */
1418
- async leaveGroup(groupId, request) {
1419
- await this.httpClient.post(`/admin-api/groups/${groupId}/leave`, request ?? {});
1525
+ async leaveGroup(groupId) {
1526
+ await this.httpClient.post(`/admin-api/groups/${groupId}/leave`, {});
1420
1527
  }
1421
1528
  /** Leave a context (POST /admin-api/contexts/:context_id/leave). */
1422
- async leaveContext(contextId, request) {
1423
- await this.httpClient.post(`/admin-api/contexts/${contextId}/leave`, request ?? {});
1529
+ async leaveContext(contextId) {
1530
+ await this.httpClient.post(`/admin-api/contexts/${contextId}/leave`, {});
1424
1531
  }
1425
1532
  /** Leave a namespace (POST /admin-api/namespaces/:namespace_id/leave). */
1426
- async leaveNamespace(namespaceId, request) {
1427
- await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/leave`, request ?? {});
1533
+ async leaveNamespace(namespaceId) {
1534
+ await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/leave`, {});
1428
1535
  }
1429
1536
  /** Issue a group ownership proof (POST /admin-api/groups/:group_id/issue-ownership-proof). */
1430
1537
  async issueOwnershipProof(groupId, request) {
1431
- return this.httpClient.post(`/admin-api/groups/${groupId}/issue-ownership-proof`, request ?? {});
1538
+ return this.httpClient.post(
1539
+ `/admin-api/groups/${groupId}/issue-ownership-proof`,
1540
+ request
1541
+ );
1432
1542
  }
1433
1543
  /** Issue a namespace ownership proof (POST /admin-api/groups/:group_id/issue-namespace-ownership-proof). */
1434
1544
  async issueNamespaceOwnershipProof(groupId, request) {
1435
1545
  return this.httpClient.post(
1436
1546
  `/admin-api/groups/${groupId}/issue-namespace-ownership-proof`,
1437
- request ?? {}
1547
+ request
1438
1548
  );
1439
1549
  }
1440
1550
  /**
@@ -1449,11 +1559,8 @@ var AdminApiClient = class {
1449
1559
  await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/auto-follow`, request);
1450
1560
  }
1451
1561
  /** Abort a namespace migration (POST /admin-api/groups/:namespace_id/migration/abort). */
1452
- async abortMigration(namespaceId, request) {
1453
- return this.httpClient.post(
1454
- `/admin-api/groups/${namespaceId}/migration/abort`,
1455
- request ?? {}
1456
- );
1562
+ async abortMigration(namespaceId) {
1563
+ return this.httpClient.post(`/admin-api/groups/${namespaceId}/migration/abort`, {});
1457
1564
  }
1458
1565
  };
1459
1566