diff --git a/CHANGELOG.md b/CHANGELOG.md index b971c3c..0a9e112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes +## 1.9.7 + +* added `AsyncApi` to implement the async version of the `.doCall` method + ## 1.9.6 * added type `"taxonomy"` to `TableBuilder` diff --git a/docs/Api.html b/docs/Api.html new file mode 100644 index 0000000..e137020 --- /dev/null +++ b/docs/Api.html @@ -0,0 +1,241 @@ + + + + + Api - Documentation + + + + + + + + + + + + + + + + +
+ +

Api

+ + + + + + + +
+ +
+ +

+ Api +

+ + +
+ +
+
+ + + + + +

new Api(baseUrl, options)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
baseUrl + + +string + + + +
options + + +ApiOptions + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ + + + + + + \ No newline at end of file diff --git a/docs/Api.js.html b/docs/Api.js.html new file mode 100644 index 0000000..d302c61 --- /dev/null +++ b/docs/Api.js.html @@ -0,0 +1,95 @@ + + + + + Api.js - Documentation + + + + + + + + + + + + + + + + +
+ +

Api.js

+ + + + + + + +
+
+
"use strict";
+
+const _ = require("lodash");
+
+/**
+ * @typedef {object} ApiOptions
+ * @property cookies {object}
+ */
+
+class Api {
+
+  /**
+   *
+   * @param baseUrl {string}
+   * @param options {ApiOptions}
+   */
+  constructor(baseUrl, options) {
+    if (this.constructor === Api) {
+      throw new Error("Abstract class 'Api' cannot be instantiated!");
+    }
+
+    this.baseUrl = baseUrl;
+    this.cookies = _.get(options, ["cookies"], {});
+    this.headers = _.get(options, ["headers"], {});
+  }
+
+  _getRequestHeaders() {
+    return {
+      "Cookie": _.map(this.cookies, ({value}, name) => {
+        return name + "=" + value || "undefined";
+      }).join("; "),
+      ...this.headers
+    };
+  }
+}
+
+module.exports = Api;
+
+
+
+ + + + +
+ +
+ + + + + + + diff --git a/docs/AsyncApi.html b/docs/AsyncApi.html new file mode 100644 index 0000000..b3e6343 --- /dev/null +++ b/docs/AsyncApi.html @@ -0,0 +1,481 @@ + + + + + AsyncApi - Documentation + + + + + + + + + + + + + + + + +
+ +

AsyncApi

+ + + + + + + +
+ +
+ +

+ AsyncApi +

+ + +
+ +
+
+ + + + + +

new AsyncApi(baseUrl, options)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
baseUrl + + +string + + + +
options + + +ApiOptions + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(async) doCall(method, url, jsonopt, nonceopt)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
method + + +string + + + + + + + + + +
url + + +string + + + + + + + + + +
json + + +object + + + + + + <optional>
+ + + + + +
nonce + + +string + + + + + + <optional>
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ + + + + + + \ No newline at end of file diff --git a/docs/AsyncApi.js.html b/docs/AsyncApi.js.html new file mode 100644 index 0000000..07b3721 --- /dev/null +++ b/docs/AsyncApi.js.html @@ -0,0 +1,104 @@ + + + + + AsyncApi.js - Documentation + + + + + + + + + + + + + + + + +
+ +

AsyncApi.js

+ + + + + + + +
+
+
"use strict";
+
+const fetch = require("node-fetch");
+
+const Api = require("./Api");
+
+/**
+ *
+ */
+class AsyncApi extends Api {
+
+  /**
+   *
+   * @param baseUrl {string}
+   * @param options {ApiOptions}
+   */
+  // eslint-disable-next-line no-useless-constructor
+  constructor(baseUrl, options) {
+    super(baseUrl, options);
+  }
+
+  /**
+   *
+   * @param method {string}
+   * @param url {string}
+   * @param [json] {object}
+   * @param [nonce] {string}
+   */
+  async doCall(method, url, json, nonce) {
+    const fullUrl = nonce
+      ? this.baseUrl + url + "?" + new URLSearchParams({nonce})
+      : this.baseUrl + url;
+
+    const options = {
+      method: method,
+      headers: this._getRequestHeaders(),
+      body: json ? JSON.stringify(json) : undefined
+    };
+
+    const response = await fetch(fullUrl, options);
+
+    return response.json();
+  }
+}
+
+module.exports = AsyncApi;
+
+
+
+ + + + +
+ +
+ + + + + + + diff --git a/docs/ColumnBuilder.html b/docs/ColumnBuilder.html index d48b1b7..c8bb3bb 100644 --- a/docs/ColumnBuilder.html +++ b/docs/ColumnBuilder.html @@ -22,7 +22,7 @@
@@ -65,7 +65,7 @@

new Colu
Source:
@@ -235,7 +235,7 @@

addConst
Source:
@@ -385,7 +385,7 @@

descriptio
Source:
@@ -544,7 +544,7 @@

displayNam
Source:
@@ -703,7 +703,7 @@

formatPa
Source:
@@ -850,7 +850,7 @@

groupsSource:
@@ -997,7 +997,7 @@

hiddenSource:
@@ -1164,7 +1164,7 @@

identifier<
Source:
@@ -1331,7 +1331,7 @@

languageT
Source:
@@ -1521,7 +1521,7 @@