influx 5.10.0 → 5.11.0

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/lib/src/index.js CHANGED
@@ -858,11 +858,12 @@ class InfluxDB {
858
858
  path: "/write",
859
859
  query: {
860
860
  db: database,
861
- p: this._options.password,
862
861
  precision,
863
862
  rp: retentionPolicy,
864
- u: this._options.username,
865
863
  },
864
+ auth: typeof this._options.username === "string"
865
+ ? `${this._options.username}:${this._options.password || ""}`
866
+ : undefined,
866
867
  });
867
868
  }
868
869
  /**
@@ -1040,15 +1041,15 @@ class InfluxDB {
1040
1041
  * @private
1041
1042
  */
1042
1043
  _getQueryOpts(params, method = "GET", partOfBody = false) {
1043
- const authCredentials = {
1044
- u: this._options.username,
1045
- p: this._options.password,
1046
- };
1044
+ let auth = undefined;
1045
+ if (typeof this._options.username === "string") {
1046
+ auth = `${this._options.username}:${this._options.password || ""}`;
1047
+ }
1047
1048
  if (method === "POST" && partOfBody) {
1048
1049
  return {
1049
1050
  method,
1050
1051
  path: "/query",
1051
- query: authCredentials,
1052
+ auth,
1052
1053
  body: querystring.stringify(params),
1053
1054
  };
1054
1055
  }
@@ -1056,7 +1057,8 @@ class InfluxDB {
1056
1057
  return {
1057
1058
  method,
1058
1059
  path: "/query",
1059
- query: Object.assign(Object.assign({}, authCredentials), params)
1060
+ auth,
1061
+ query: Object.assign({}, params),
1060
1062
  };
1061
1063
  }
1062
1064
  }
package/lib/src/pool.d.ts CHANGED
@@ -43,6 +43,15 @@ export interface IPoolRequestOptions {
43
43
  * running this request.
44
44
  */
45
45
  retries?: number;
46
+ /**
47
+ * Optional Basic auth in the form `username:password`.
48
+ * When provided, Pool will set the `Authorization: Basic ...` header.
49
+ */
50
+ auth?: string;
51
+ /**
52
+ * Optional extra headers to include in the request.
53
+ */
54
+ headers?: http.OutgoingHttpHeaders;
46
55
  }
47
56
  /**
48
57
  * An ServiceNotAvailableError is returned as an error from requests that
package/lib/src/pool.js CHANGED
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.Pool = exports.RequestError = exports.ServiceNotAvailableError = void 0;
4
15
  const exponential_1 = require("./backoff/exponential");
@@ -241,9 +252,18 @@ class Pool {
241
252
  if (options.query) {
242
253
  path += "?" + querystring.stringify(options.query);
243
254
  }
244
- const req = request(Object.assign({ headers: Object.assign({ "content-length": options.body ? Buffer.from(options.body).length : 0 }, (options.body && options.path === "/query"
245
- ? { "Content-Type": "application/x-www-form-urlencoded" }
246
- : {})), hostname: host.url.hostname, method: options.method, path, port: Number(host.url.port), protocol: host.url.protocol, timeout: this._timeout }, host.options), once((res) => {
255
+ // Merge headers from defaults, host options, and call options.
256
+ const hostHeaders = (host.options && host.options.headers) || {};
257
+ const defaultHeaders = Object.assign({ "content-length": options.body ? Buffer.from(options.body).length : 0 }, (options.body && options.path === "/query"
258
+ ? { "Content-Type": "application/x-www-form-urlencoded" }
259
+ : {}));
260
+ const mergedHeaders = Object.assign(Object.assign(Object.assign({}, hostHeaders), defaultHeaders), (options.headers || {}));
261
+ if (typeof options.auth !== "undefined") {
262
+ const encodedAuth = Buffer.from(options.auth).toString("base64");
263
+ mergedHeaders["Authorization"] = `Basic ${encodedAuth}`;
264
+ }
265
+ const _a = (host.options || {}), { headers: _ignoredHostHeaders } = _a, hostReqOptions = __rest(_a, ["headers"]);
266
+ const req = request(Object.assign({ headers: mergedHeaders, hostname: host.url.hostname, method: options.method, path, port: Number(host.url.port), protocol: host.url.protocol, timeout: this._timeout }, hostReqOptions), once((res) => {
247
267
  res.setEncoding("utf8");
248
268
  if (res.statusCode >= 500) {
249
269
  res.on("data", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "influx",
3
- "version": "5.10.0",
3
+ "version": "5.11.0",
4
4
  "description": "InfluxDB Client",
5
5
  "main": "./lib/src/index.js",
6
6
  "typings": "./lib/src/index",