moeralib 0.19.0 → 0.19.2
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/AGENTS.md +5 -0
- package/lib/index.js +3 -0
- package/lib/node/caller.js +28 -2
- package/lib/node/fingerprints.js +16 -0
- package/lib/node/node.js +3 -58
- package/lib/node/types.js +1 -2
- package/lib/node/validators.js +17948 -16825
- package/lib/node-source-uri.js +110 -0
- package/package.json +5 -3
- package/typings/index.d.ts +2 -0
- package/typings/index.d.ts.map +1 -1
- package/typings/node/caller.d.ts +14 -0
- package/typings/node/caller.d.ts.map +1 -1
- package/typings/node/fingerprints.d.ts +1 -0
- package/typings/node/fingerprints.d.ts.map +1 -1
- package/typings/node/node.d.ts +3 -30
- package/typings/node/node.d.ts.map +1 -1
- package/typings/node/types.d.ts +180 -130
- package/typings/node/types.d.ts.map +1 -1
- package/typings/node/validators.d.ts +0 -10
- package/typings/node/validators.d.ts.map +1 -1
- package/typings/node-source-uri.d.ts +31 -0
- package/typings/node-source-uri.d.ts.map +1 -0
package/AGENTS.md
ADDED
package/lib/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeSourceUri = void 0;
|
|
4
|
+
var node_source_uri_1 = require("./node-source-uri");
|
|
5
|
+
Object.defineProperty(exports, "NodeSourceUri", { enumerable: true, get: function () { return node_source_uri_1.NodeSourceUri; } });
|
package/lib/node/caller.js
CHANGED
|
@@ -15,9 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.Caller = exports.MoeraNodeCallError = exports.MoeraNodeConnectionError = exports.MoeraNodeApiError = exports.MoeraNodeError = void 0;
|
|
16
16
|
exports.moeraRoot = moeraRoot;
|
|
17
17
|
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
18
|
+
const undici_1 = require("undici");
|
|
18
19
|
const validate_1 = require("./validate");
|
|
19
20
|
const util_1 = require("../util");
|
|
20
21
|
const schema_1 = require("../schema");
|
|
22
|
+
const { version: packageVersion } = require("../../package.json");
|
|
23
|
+
const insecureDispatcher = new undici_1.Agent({ connect: { rejectUnauthorized: false } });
|
|
21
24
|
/**
|
|
22
25
|
* Generic node error.
|
|
23
26
|
*/
|
|
@@ -201,6 +204,8 @@ class Caller {
|
|
|
201
204
|
this._carte = null;
|
|
202
205
|
this._carteSource = null;
|
|
203
206
|
this._authMethod = "none";
|
|
207
|
+
this._userAgent = null;
|
|
208
|
+
this._verifySsl = true;
|
|
204
209
|
}
|
|
205
210
|
/**
|
|
206
211
|
* Set node URL.
|
|
@@ -210,6 +215,14 @@ class Caller {
|
|
|
210
215
|
nodeUrl(url) {
|
|
211
216
|
this.root = moeraRoot(url);
|
|
212
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Enable or disable SSL certificate verification.
|
|
220
|
+
*
|
|
221
|
+
* @param {boolean} verifySsl
|
|
222
|
+
*/
|
|
223
|
+
verifySsl(verifySsl) {
|
|
224
|
+
this._verifySsl = verifySsl;
|
|
225
|
+
}
|
|
213
226
|
/**
|
|
214
227
|
* Set root secret for authentication.
|
|
215
228
|
*
|
|
@@ -274,6 +287,14 @@ class Caller {
|
|
|
274
287
|
authRootAdmin() {
|
|
275
288
|
this.authMethod("root-admin");
|
|
276
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Set the User-Agent string.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} agent
|
|
294
|
+
*/
|
|
295
|
+
userAgent(agent) {
|
|
296
|
+
this._userAgent = agent;
|
|
297
|
+
}
|
|
277
298
|
/**
|
|
278
299
|
* Generic method for making node API requests.
|
|
279
300
|
*
|
|
@@ -304,7 +325,8 @@ class Caller {
|
|
|
304
325
|
}
|
|
305
326
|
const headers = {
|
|
306
327
|
"Accept": "application/json",
|
|
307
|
-
"Content-Type": contentType !== null && contentType !== void 0 ? contentType : "application/json"
|
|
328
|
+
"Content-Type": contentType !== null && contentType !== void 0 ? contentType : "application/json",
|
|
329
|
+
"User-Agent": this._userAgent || `moeralib/${packageVersion}`
|
|
308
330
|
};
|
|
309
331
|
let bearer = null;
|
|
310
332
|
if (auth) {
|
|
@@ -344,7 +366,11 @@ class Caller {
|
|
|
344
366
|
const signal = abortSignal(method, bodyEncoded);
|
|
345
367
|
let response;
|
|
346
368
|
try {
|
|
347
|
-
|
|
369
|
+
const options = { method, headers, body: bodyEncoded, signal };
|
|
370
|
+
if (!this._verifySsl) {
|
|
371
|
+
options.dispatcher = insecureDispatcher;
|
|
372
|
+
}
|
|
373
|
+
response = yield fetch(url, options);
|
|
348
374
|
}
|
|
349
375
|
catch (e) {
|
|
350
376
|
throw new MoeraNodeConnectionError(String(e));
|
package/lib/node/fingerprints.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.createCommentFingerprint1 = createCommentFingerprint1;
|
|
|
10
10
|
exports.createCommentFingerprint0 = createCommentFingerprint0;
|
|
11
11
|
exports.createMediaGrantFingerprint1 = createMediaGrantFingerprint1;
|
|
12
12
|
exports.createMediaGrantFingerprint0 = createMediaGrantFingerprint0;
|
|
13
|
+
exports.createNotificationPacketFingerprint2 = createNotificationPacketFingerprint2;
|
|
13
14
|
exports.createNotificationPacketFingerprint1 = createNotificationPacketFingerprint1;
|
|
14
15
|
exports.createNotificationPacketFingerprint0 = createNotificationPacketFingerprint0;
|
|
15
16
|
exports.createPostingFingerprint1 = createPostingFingerprint1;
|
|
@@ -151,6 +152,21 @@ function createMediaGrantFingerprint0(nodeName, postingId, commentId, mediaId, e
|
|
|
151
152
|
return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "MEDIA_GRANT", nodeName, postingId, commentId, mediaId, expires, download, fileName,
|
|
152
153
|
salt }, MEDIA_GRANT_FINGERPRINT0_SCHEMA);
|
|
153
154
|
}
|
|
155
|
+
const NOTIFICATION_PACKET_FINGERPRINT2_SCHEMA = [
|
|
156
|
+
["version", "number"],
|
|
157
|
+
["objectType", "string"],
|
|
158
|
+
["id", "string"],
|
|
159
|
+
["nodeName", "string"],
|
|
160
|
+
["fullName", "string"],
|
|
161
|
+
["nodeSourceUri", "string"],
|
|
162
|
+
["createdAt", "number"],
|
|
163
|
+
["type", "string"],
|
|
164
|
+
["notification", "string"],
|
|
165
|
+
];
|
|
166
|
+
function createNotificationPacketFingerprint2(id, nodeName, fullName, nodeSourceUri, createdAt, type, notification) {
|
|
167
|
+
return (0, crypto_1.fingerprintBytes)({ "version": 2, "objectType": "NOTIFICATION_PACKET", id, nodeName, fullName, nodeSourceUri, createdAt, type,
|
|
168
|
+
notification }, NOTIFICATION_PACKET_FINGERPRINT2_SCHEMA);
|
|
169
|
+
}
|
|
154
170
|
const NOTIFICATION_PACKET_FINGERPRINT1_SCHEMA = [
|
|
155
171
|
["version", "number"],
|
|
156
172
|
["objectType", "string"],
|
package/lib/node/node.js
CHANGED
|
@@ -1715,62 +1715,6 @@ class MoeraNode extends caller_1.Caller {
|
|
|
1715
1715
|
});
|
|
1716
1716
|
});
|
|
1717
1717
|
}
|
|
1718
|
-
/**
|
|
1719
|
-
* Register the plugin. If the plugin authenticates as root admin, the plugin is registered at the server level. If
|
|
1720
|
-
* the plugin authenticates as node admin, the plugin is registered at the node level.
|
|
1721
|
-
*
|
|
1722
|
-
* @param {API.PluginDescription} plugin
|
|
1723
|
-
* @return {Promise<API.PluginInfo>}
|
|
1724
|
-
*/
|
|
1725
|
-
registerPlugin(plugin) {
|
|
1726
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1727
|
-
const location = "/plugins";
|
|
1728
|
-
return yield this.call("registerPlugin", location, {
|
|
1729
|
-
method: "POST", body: plugin, schema: "PluginInfo"
|
|
1730
|
-
});
|
|
1731
|
-
});
|
|
1732
|
-
}
|
|
1733
|
-
/**
|
|
1734
|
-
* Get information about all plugins registered for the node and server.
|
|
1735
|
-
*
|
|
1736
|
-
* @return {Promise<API.PluginInfo[]>}
|
|
1737
|
-
*/
|
|
1738
|
-
getPlugins() {
|
|
1739
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1740
|
-
const location = "/plugins";
|
|
1741
|
-
return yield this.call("getPlugins", location, {
|
|
1742
|
-
method: "GET", schema: "PluginInfoArray"
|
|
1743
|
-
});
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Get information about the plugin.
|
|
1748
|
-
*
|
|
1749
|
-
* @param {string} pluginName - name of the plugin
|
|
1750
|
-
* @return {Promise<API.PluginInfo>}
|
|
1751
|
-
*/
|
|
1752
|
-
getPlugin(pluginName) {
|
|
1753
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1754
|
-
const location = (0, util_1.ut) `/plugins/${pluginName}`;
|
|
1755
|
-
return yield this.call("getPlugin", location, {
|
|
1756
|
-
method: "GET", schema: "PluginInfo"
|
|
1757
|
-
});
|
|
1758
|
-
});
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* Unregister the plugin.
|
|
1762
|
-
*
|
|
1763
|
-
* @param {string} pluginName - name of the plugin
|
|
1764
|
-
* @return {Promise<API.Result>}
|
|
1765
|
-
*/
|
|
1766
|
-
unregisterPlugin(pluginName) {
|
|
1767
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1768
|
-
const location = (0, util_1.ut) `/plugins/${pluginName}`;
|
|
1769
|
-
return yield this.call("unregisterPlugin", location, {
|
|
1770
|
-
method: "DELETE", schema: "Result"
|
|
1771
|
-
});
|
|
1772
|
-
});
|
|
1773
|
-
}
|
|
1774
1718
|
/**
|
|
1775
1719
|
* Create a new posting from the text given and publish it in the given feeds (if any). The heading and the preview
|
|
1776
1720
|
* of the posting are created automatically, if needed. The posting owner must authenticate in some way. If the
|
|
@@ -2073,8 +2017,9 @@ class MoeraNode extends caller_1.Caller {
|
|
|
2073
2017
|
});
|
|
2074
2018
|
}
|
|
2075
2019
|
/**
|
|
2076
|
-
*
|
|
2077
|
-
*
|
|
2020
|
+
* To update a profile attribute, include the field with its new value. For a partial update, include only the
|
|
2021
|
+
* fields to be changed; omitted fields remain unchanged. To delete an attribute, include the field with an empty
|
|
2022
|
+
* value, which resets it to its default.
|
|
2078
2023
|
*
|
|
2079
2024
|
* @param {API.ProfileAttributes} profile
|
|
2080
2025
|
* @return {Promise<API.ProfileInfo>}
|
package/lib/node/types.js
CHANGED
|
@@ -22,7 +22,6 @@ exports.SCOPE_VALUES = {
|
|
|
22
22
|
"view-feeds": 0x00008000,
|
|
23
23
|
"update-feeds": 0x00010000,
|
|
24
24
|
"name": 0x00020000,
|
|
25
|
-
"plugins": 0x00040000,
|
|
26
25
|
"view-profile": 0x00080000,
|
|
27
26
|
"update-profile": 0x00100000,
|
|
28
27
|
"sheriff": 0x00200000,
|
|
@@ -36,5 +35,5 @@ exports.SCOPE_VALUES = {
|
|
|
36
35
|
"upload-private-media": 0x20000000,
|
|
37
36
|
"lease-media": 0x40000000,
|
|
38
37
|
"view-all": 0x00088404,
|
|
39
|
-
"all":
|
|
38
|
+
"all": 0x7ffbfffd,
|
|
40
39
|
};
|