moeralib 0.18.7 → 0.19.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.
@@ -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
- response = yield fetch(url, { method, headers, body: bodyEncoded, signal });
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/node.js CHANGED
@@ -1382,8 +1382,9 @@ class MoeraNode extends caller_1.Caller {
1382
1382
  *
1383
1383
  * @param {string | null} upload - ID of the media upload to be used instead of the request body
1384
1384
  * @param {string | null} url - URL of the media to be used instead of the request body
1385
- * @param {boolean | null} downsize - `true` to scale the uploaded image down to the size recommended by the node,
1386
- * if possible; the default is `false`
1385
+ * @param {boolean | null} downsize - `true` to scale the uploaded image down to the size recommended by the node
1386
+ * or asynchronously compress an uploaded video to the recommended playback format and size, if possible; the
1387
+ * default is `false`
1387
1388
  * @param {Buffer | null} body - optional
1388
1389
  * @param {string | null} contentType - optional content-type of ``body``
1389
1390
  * @return {Promise<API.PrivateMediaFileInfo>}