moeralib 0.18.1 → 0.18.6

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateNamingSchema = exports.shorten = exports.resolve = exports.expand = exports.parseNodeName = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.MoeraNaming = void 0;
3
+ exports.validateNamingSchema = exports.shorten = exports.resolve = exports.expand = exports.parseNodeName = exports.ANONYMOUS_NODE_PRIVATE_KEY = exports.ANONYMOUS_NODE_PUBLIC_KEY = exports.ANONYMOUS_NODE_NAME = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.MoeraNaming = void 0;
4
4
  var naming_1 = require("./naming");
5
5
  Object.defineProperty(exports, "MoeraNaming", { enumerable: true, get: function () { return naming_1.MoeraNaming; } });
6
6
  Object.defineProperty(exports, "MoeraNamingError", { enumerable: true, get: function () { return naming_1.MoeraNamingError; } });
@@ -8,6 +8,9 @@ Object.defineProperty(exports, "MoeraNamingApiError", { enumerable: true, get: f
8
8
  Object.defineProperty(exports, "MoeraNamingConnectionError", { enumerable: true, get: function () { return naming_1.MoeraNamingConnectionError; } });
9
9
  Object.defineProperty(exports, "MAIN_NAMING_SERVER", { enumerable: true, get: function () { return naming_1.MAIN_NAMING_SERVER; } });
10
10
  Object.defineProperty(exports, "DEV_NAMING_SERVER", { enumerable: true, get: function () { return naming_1.DEV_NAMING_SERVER; } });
11
+ Object.defineProperty(exports, "ANONYMOUS_NODE_NAME", { enumerable: true, get: function () { return naming_1.ANONYMOUS_NODE_NAME; } });
12
+ Object.defineProperty(exports, "ANONYMOUS_NODE_PUBLIC_KEY", { enumerable: true, get: function () { return naming_1.ANONYMOUS_NODE_PUBLIC_KEY; } });
13
+ Object.defineProperty(exports, "ANONYMOUS_NODE_PRIVATE_KEY", { enumerable: true, get: function () { return naming_1.ANONYMOUS_NODE_PRIVATE_KEY; } });
11
14
  Object.defineProperty(exports, "parseNodeName", { enumerable: true, get: function () { return naming_1.parseNodeName; } });
12
15
  Object.defineProperty(exports, "expand", { enumerable: true, get: function () { return naming_1.expand; } });
13
16
  Object.defineProperty(exports, "resolve", { enumerable: true, get: function () { return naming_1.resolve; } });
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MoeraNaming = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = void 0;
12
+ exports.MoeraNaming = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.ANONYMOUS_NODE_PRIVATE_KEY = exports.ANONYMOUS_NODE_PUBLIC_KEY = exports.ANONYMOUS_NODE_NAME = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = void 0;
13
13
  exports.parseNodeName = parseNodeName;
14
14
  exports.shorten = shorten;
15
15
  exports.expand = expand;
@@ -25,6 +25,18 @@ exports.MAIN_NAMING_SERVER = "https://naming.moera.org/moera-naming";
25
25
  * Moera developers' naming server.
26
26
  */
27
27
  exports.DEV_NAMING_SERVER = "https://naming-dev.moera.org/moera-naming";
28
+ /**
29
+ * Node name used to represent anonymous content author.
30
+ */
31
+ exports.ANONYMOUS_NODE_NAME = "unk_0";
32
+ /**
33
+ * Public key used to verify signatures of anonymous content.
34
+ */
35
+ exports.ANONYMOUS_NODE_PUBLIC_KEY = Buffer.from("VNKYmrV8b1XR7phWvrTUbkfnxsPTKvHIcvJLGrBZQr0Z8eKVdTooBkIWS0CECPjLxPGaQkcKkMcZ6M6wEsJm9A==", "base64");
36
+ /**
37
+ * Private key used to sign anonymous content.
38
+ */
39
+ exports.ANONYMOUS_NODE_PRIVATE_KEY = Buffer.from("tCb+02pUSC6FLdQLPvrUhSBjD0xiV5Q+fQmZY3PKybo=", "base64");
28
40
  /**
29
41
  * Generic naming server error.
30
42
  */
@@ -84,6 +84,9 @@ function encodeBodies(data) {
84
84
  return data.map(item => encodeBodies(item));
85
85
  }
86
86
  const encoded = (0, lodash_clonedeep_1.default)(data);
87
+ if (data.mediaCaptions != null) {
88
+ encoded.mediaCaptions = data.mediaCaptions.map((item) => encodeBodies(item));
89
+ }
87
90
  if (data.body != null) {
88
91
  encoded.body = encodeBody(data.body, data.bodyFormat);
89
92
  }
@@ -93,6 +96,9 @@ function encodeBodies(data) {
93
96
  if (data.bodySrc != null) {
94
97
  encoded.bodySrc = encodeBody(data.bodySrc, data.bodySrcFormat);
95
98
  }
99
+ if (data.captionSrc != null) {
100
+ encoded.captionSrc = encodeBody(data.captionSrc, data.captionSrcFormat);
101
+ }
96
102
  return encoded;
97
103
  }
98
104
  function decodeBody(name, encoded, format) {
@@ -126,6 +132,9 @@ function decodeBodies(name, data) {
126
132
  if (data.comments != null) {
127
133
  decoded.comments = data.comments.map((item) => decodeBodies(name, item));
128
134
  }
135
+ if (data.mediaCaptions != null) {
136
+ decoded.mediaCaptions = data.mediaCaptions.map((item) => decodeBodies(name, item));
137
+ }
129
138
  if (data.comment != null) {
130
139
  decoded.comment = decodeBodies(name, data.comment);
131
140
  }
@@ -141,6 +150,9 @@ function decodeBodies(name, data) {
141
150
  if (data.bodySrc != null) {
142
151
  decoded.bodySrc = decodeBody(name, data.bodySrc, data.bodySrcFormat);
143
152
  }
153
+ if (data.captionSrc != null) {
154
+ decoded.captionSrc = decodeBody(name, data.captionSrc, data.captionSrcFormat);
155
+ }
144
156
  return decoded;
145
157
  }
146
158
  /**
@@ -116,8 +116,9 @@ function generateCarte(ownerName_1, signingKey_1, beginning_1) {
116
116
  if (Array.isArray(adminScope)) {
117
117
  adminScope = toScopeMask(adminScope);
118
118
  }
119
+ const addresses = address == null ? null : Array.isArray(address) ? address : [address];
119
120
  const salt = yield (0, util_1.promisify)(crypto_1.default.randomBytes)(8);
120
- const fingerprint = (0, fingerprints_1.createCarteFingerprint2)(ownerName, address, beginning, beginning + ttl, nodeName, clientScope, adminScope, salt);
121
+ const fingerprint = (0, fingerprints_1.createCarteFingerprint3)(ownerName, addresses, beginning, beginning + ttl, nodeName, clientScope, adminScope, salt);
121
122
  const signature = (0, crypto_2.signFingerprint)(fingerprint, signingKey);
122
123
  return Buffer.concat([fingerprint, signature]).toString("base64url");
123
124
  });
@@ -8,6 +8,8 @@ exports.createCarteFingerprint1 = createCarteFingerprint1;
8
8
  exports.createCarteFingerprint0 = createCarteFingerprint0;
9
9
  exports.createCommentFingerprint1 = createCommentFingerprint1;
10
10
  exports.createCommentFingerprint0 = createCommentFingerprint0;
11
+ exports.createMediaGrantFingerprint1 = createMediaGrantFingerprint1;
12
+ exports.createMediaGrantFingerprint0 = createMediaGrantFingerprint0;
11
13
  exports.createNotificationPacketFingerprint1 = createNotificationPacketFingerprint1;
12
14
  exports.createNotificationPacketFingerprint0 = createNotificationPacketFingerprint0;
13
15
  exports.createPostingFingerprint1 = createPostingFingerprint1;
@@ -120,6 +122,35 @@ function createCommentFingerprint0(ownerName, postingFingerprint, repliedToFinge
120
122
  return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "COMMENT", ownerName, postingFingerprint, repliedToFingerprint, bodySrcHash,
121
123
  bodySrcFormat, body, bodyFormat, createdAt, permissions, attachments }, COMMENT_FINGERPRINT0_SCHEMA);
122
124
  }
125
+ const MEDIA_GRANT_FINGERPRINT1_SCHEMA = [
126
+ ["version", "number"],
127
+ ["objectType", "string"],
128
+ ["nodeName", "string"],
129
+ ["mediaId", "string"],
130
+ ["expires", "number"],
131
+ ["download", "boolean"],
132
+ ["fileName", "string"],
133
+ ["salt", "bytes"],
134
+ ];
135
+ function createMediaGrantFingerprint1(nodeName, mediaId, expires, download, fileName, salt) {
136
+ return (0, crypto_1.fingerprintBytes)({ "version": 1, "objectType": "MEDIA_GRANT", nodeName, mediaId, expires, download, fileName, salt }, MEDIA_GRANT_FINGERPRINT1_SCHEMA);
137
+ }
138
+ const MEDIA_GRANT_FINGERPRINT0_SCHEMA = [
139
+ ["version", "number"],
140
+ ["objectType", "string"],
141
+ ["nodeName", "string"],
142
+ ["postingId", "string"],
143
+ ["commentId", "string"],
144
+ ["mediaId", "string"],
145
+ ["expires", "number"],
146
+ ["download", "boolean"],
147
+ ["fileName", "string"],
148
+ ["salt", "bytes"],
149
+ ];
150
+ function createMediaGrantFingerprint0(nodeName, postingId, commentId, mediaId, expires, download, fileName, salt) {
151
+ return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "MEDIA_GRANT", nodeName, postingId, commentId, mediaId, expires, download, fileName,
152
+ salt }, MEDIA_GRANT_FINGERPRINT0_SCHEMA);
153
+ }
123
154
  const NOTIFICATION_PACKET_FINGERPRINT1_SCHEMA = [
124
155
  ["version", "number"],
125
156
  ["objectType", "string"],
package/lib/node/node.js CHANGED
@@ -1360,31 +1360,15 @@ class MoeraNode extends caller_1.Caller {
1360
1360
  });
1361
1361
  }
1362
1362
  /**
1363
- * Upload a new media file owned by the node admin. The content of the file is passed in the request body.
1363
+ * Upload a new private media file. The content of the file is passed in the request body.
1364
1364
  *
1365
1365
  * @param {Buffer} body
1366
1366
  * @param {string} contentType - content-type of ``body``
1367
1367
  * @return {Promise<API.PrivateMediaFileInfo>}
1368
1368
  */
1369
- uploadAdminMedia(body, contentType) {
1369
+ uploadPrivateMedia(body, contentType) {
1370
1370
  return __awaiter(this, void 0, void 0, function* () {
1371
1371
  const location = "/media/private";
1372
- return yield this.call("uploadAdminMedia", location, {
1373
- method: "POST", body, contentType, schema: "PrivateMediaFileInfo"
1374
- });
1375
- });
1376
- }
1377
- /**
1378
- * Upload a new media file owned by the given node. The content of the file is passed in the request body.
1379
- *
1380
- * @param {string} clientName - name of the node owning the media file
1381
- * @param {Buffer} body
1382
- * @param {string} contentType - content-type of ``body``
1383
- * @return {Promise<API.PrivateMediaFileInfo>}
1384
- */
1385
- uploadPrivateMedia(clientName, body, contentType) {
1386
- return __awaiter(this, void 0, void 0, function* () {
1387
- const location = (0, util_1.ut) `/media/private/${clientName}`;
1388
1372
  return yield this.call("uploadPrivateMedia", location, {
1389
1373
  method: "POST", body, contentType, schema: "PrivateMediaFileInfo"
1390
1374
  });
@@ -1398,12 +1382,15 @@ class MoeraNode extends caller_1.Caller {
1398
1382
  * the smallest in size, but the best in quality variant of the media, according to the width provided
1399
1383
  * @param {boolean | null} download - if ``true``, the node will add ``Content-Disposition: attachment`` header to
1400
1384
  * the output
1385
+ * @param {string | null} grant - media grant allowing access to the media file
1386
+ * @param {boolean | null} ignoremalware - if ``true``, the node will ignore malware detection and return the media
1387
+ * file; only admin may use this option
1401
1388
  * @return {Promise<Blob>}
1402
1389
  */
1403
1390
  getPrivateMedia(id_1) {
1404
- return __awaiter(this, arguments, void 0, function* (id, width = null, download = null) {
1391
+ return __awaiter(this, arguments, void 0, function* (id, width = null, download = null, grant = null, ignoremalware = null) {
1405
1392
  const location = (0, util_1.ut) `/media/private/${id}/data`;
1406
- const params = { width, download };
1393
+ const params = { width, download, grant, ignoremalware };
1407
1394
  return yield this.call("getPrivateMedia", location, {
1408
1395
  method: "GET", params, schema: "blob"
1409
1396
  });
@@ -1413,27 +1400,30 @@ class MoeraNode extends caller_1.Caller {
1413
1400
  * Get media file details.
1414
1401
  *
1415
1402
  * @param {string} id - media file ID
1403
+ * @param {string | null} grant - media grant allowing access to the media file
1416
1404
  * @return {Promise<API.PrivateMediaFileInfo>}
1417
1405
  */
1418
- getPrivateMediaInfo(id) {
1419
- return __awaiter(this, void 0, void 0, function* () {
1406
+ getPrivateMediaInfo(id_1) {
1407
+ return __awaiter(this, arguments, void 0, function* (id, grant = null) {
1420
1408
  const location = (0, util_1.ut) `/media/private/${id}/info`;
1409
+ const params = { grant };
1421
1410
  return yield this.call("getPrivateMediaInfo", location, {
1422
- method: "GET", schema: "PrivateMediaFileInfo"
1411
+ method: "GET", params, schema: "PrivateMediaFileInfo"
1423
1412
  });
1424
1413
  });
1425
1414
  }
1426
1415
  /**
1427
- * Get the list of all postings and comments the media file is attached to.
1416
+ * Update media file details.
1428
1417
  *
1429
1418
  * @param {string} id - media file ID
1430
- * @return {Promise<API.EntryInfo[]>}
1419
+ * @param {API.PrivateMediaFileAttributes} attributes
1420
+ * @return {Promise<API.PrivateMediaFileInfo>}
1431
1421
  */
1432
- getPrivateMediaParentEntry(id) {
1422
+ updatePrivateMediaInfo(id, attributes) {
1433
1423
  return __awaiter(this, void 0, void 0, function* () {
1434
- const location = (0, util_1.ut) `/media/private/${id}/parent`;
1435
- return yield this.call("getPrivateMediaParentEntry", location, {
1436
- method: "GET", schema: "EntryInfoArray", bodies: true
1424
+ const location = (0, util_1.ut) `/media/private/${id}/info`;
1425
+ return yield this.call("updatePrivateMediaInfo", location, {
1426
+ method: "PUT", body: attributes, schema: "PrivateMediaFileInfo"
1437
1427
  });
1438
1428
  });
1439
1429
  }
@@ -1485,6 +1475,34 @@ class MoeraNode extends caller_1.Caller {
1485
1475
  });
1486
1476
  });
1487
1477
  }
1478
+ /**
1479
+ * Create a lease for a media file stored on the node.
1480
+ *
1481
+ * @param {API.MediaLeaseAttributes} attributes
1482
+ * @return {Promise<API.MediaLeaseInfo>}
1483
+ */
1484
+ createMediaLease(attributes) {
1485
+ return __awaiter(this, void 0, void 0, function* () {
1486
+ const location = "/media/leases";
1487
+ return yield this.call("createMediaLease", location, {
1488
+ method: "POST", body: attributes, schema: "MediaLeaseInfo"
1489
+ });
1490
+ });
1491
+ }
1492
+ /**
1493
+ * Delete the lease.
1494
+ *
1495
+ * @param {string} id - ID of the lease
1496
+ * @return {Promise<API.Result>}
1497
+ */
1498
+ deleteMediaLease(id) {
1499
+ return __awaiter(this, void 0, void 0, function* () {
1500
+ const location = (0, util_1.ut) `/media/leases/${id}`;
1501
+ return yield this.call("deleteMediaLease", location, {
1502
+ method: "DELETE", schema: "Result"
1503
+ });
1504
+ });
1505
+ }
1488
1506
  /**
1489
1507
  * Get the name of the node. Admin user receives the current status of the latest operation with the node name.
1490
1508
  *
@@ -2355,6 +2373,22 @@ class MoeraNode extends caller_1.Caller {
2355
2373
  });
2356
2374
  });
2357
2375
  }
2376
+ /**
2377
+ * Download the private media file from the remote node and store it at the home node.
2378
+ *
2379
+ * @param {string} remoteNodeName - name of the remote node
2380
+ * @param {string} id - id of the media file
2381
+ * @param {API.MediaDownloadAttributes} attributes
2382
+ * @return {Promise<API.PrivateMediaFileInfo>}
2383
+ */
2384
+ downloadRemoteMedia(remoteNodeName, id, attributes) {
2385
+ return __awaiter(this, void 0, void 0, function* () {
2386
+ const location = (0, util_1.ut) `/nodes/${remoteNodeName}/media/private/${id}/download`;
2387
+ return yield this.call("downloadRemoteMedia", location, {
2388
+ method: "POST", body: attributes, schema: "PrivateMediaFileInfo"
2389
+ });
2390
+ });
2391
+ }
2358
2392
  /**
2359
2393
  * Add a posting to the remote node and register it in the registry at the local node.
2360
2394
  *
@@ -3105,6 +3139,20 @@ class MoeraNode extends caller_1.Caller {
3105
3139
  });
3106
3140
  });
3107
3141
  }
3142
+ /**
3143
+ * Record a visit to a posting, comment or media.
3144
+ *
3145
+ * @param {API.VisitDetails} visit
3146
+ * @return {Promise<API.Result>}
3147
+ */
3148
+ recordVisit(visit) {
3149
+ return __awaiter(this, void 0, void 0, function* () {
3150
+ const location = "/visits";
3151
+ return yield this.call("recordVisit", location, {
3152
+ method: "POST", body: visit, schema: "Result"
3153
+ });
3154
+ });
3155
+ }
3108
3156
  /**
3109
3157
  * Get brief information about the node.
3110
3158
  *
package/lib/node/types.js CHANGED
@@ -6,7 +6,6 @@ exports.SCOPE_VALUES = {
6
6
  "none": 0x00000000,
7
7
  "identify": 0x00000000,
8
8
  "other": 0x00000001,
9
- "view-media": 0x00000002,
10
9
  "view-content": 0x00000004,
11
10
  "add-post": 0x00000008,
12
11
  "update-post": 0x00000010,
@@ -35,6 +34,7 @@ exports.SCOPE_VALUES = {
35
34
  "grant": 0x08000000,
36
35
  "upload-public-media": 0x10000000,
37
36
  "upload-private-media": 0x20000000,
38
- "view-all": 0x00088406,
39
- "all": 0x3fffffff,
37
+ "lease-media": 0x40000000,
38
+ "view-all": 0x00088404,
39
+ "all": 0x7ffffffd,
40
40
  };