@stackfactor/client-api 1.0.30 → 1.0.32

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,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/address.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,10 +1,10 @@
1
- const axios = require("axios");
2
- const https = require("https");
3
- const utils = require("./utils");
1
+ import client from "axios";
2
+ import https from "https";
3
+ import utils from "./utils";
4
4
 
5
5
  const baseUrl = utils.getBaseUrl();
6
6
 
7
- let instance = axios.create({
7
+ export const axios = client.create({
8
8
  baseURL: baseUrl,
9
9
  httpsAgent: new https.Agent({
10
10
  rejectUnauthorized: false,
@@ -12,71 +12,65 @@ let instance = axios.create({
12
12
  });
13
13
 
14
14
  /**
15
- * Server response type
15
+ * Returns the error as a string
16
+ * @param {Object} error
16
17
  */
17
- module.exports = {
18
- axios: instance,
19
- /**
20
- * Returns the error as a string
21
- * @param {Object} error
22
- */
23
- errorToString: (error) => {
24
- if (error != null) {
25
- if (error?.response?.data) {
26
- let asString = "";
27
- if (Array.isArray(error.response.data.errors)) {
28
- error.response.data.errors.forEach((item, index) => {
29
- asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
30
- item.param
31
- } ${item.value ? `value ${item.value.toString()}` : ""}`;
32
- });
33
- return asString;
34
- } else if (error.response.data.error) {
35
- return error.response.data.error.toString();
36
- } else if (error.response.statusText) {
37
- return error.response.statusText.toString();
38
- } else {
39
- return error.response.data.toString();
40
- }
18
+ export const errorToString = (error) => {
19
+ if (error != null) {
20
+ if (error?.response?.data) {
21
+ let asString = "";
22
+ if (Array.isArray(error.response.data.errors)) {
23
+ error.response.data.errors.forEach((item, index) => {
24
+ asString += `${index > 0 ? ", " : ""} ${item.msg} param ${
25
+ item.param
26
+ } ${item.value ? `value ${item.value.toString()}` : ""}`;
27
+ });
28
+ return asString;
29
+ } else if (error.response.data.error) {
30
+ return error.response.data.error.toString();
31
+ } else if (error.response.statusText) {
32
+ return error.response.statusText.toString();
41
33
  } else {
42
- return error.message ? error.message : "Unknown error";
34
+ return error.response.data.toString();
43
35
  }
36
+ } else {
37
+ return error.message ? error.message : "Unknown error";
44
38
  }
45
- },
39
+ }
40
+ };
46
41
 
47
- /**
48
- * Returns the code of the error as a number
49
- * @param {Object} error
50
- * @returns {Number} The error code
51
- */
52
- getErrorType: (error) => {
53
- if (error?.response?.status) {
54
- return error.response.status;
55
- } else return responseType.SERVICE_UNAVAILABLE;
56
- },
42
+ /**
43
+ * Returns the code of the error as a number
44
+ * @param {Object} error
45
+ * @returns {Number} The error code
46
+ */
47
+ export const getErrorType = (error) => {
48
+ if (error?.response?.status) {
49
+ return error.response.status;
50
+ } else return responseType.SERVICE_UNAVAILABLE;
51
+ };
57
52
 
58
- /**
59
- * Return the error information to include just the status and the message
60
- * @param {Object} error
61
- * @returns Object
62
- */
63
- getErrorInformation: (error) => {
64
- return {
65
- status: getErrorType(error),
66
- message: errorToString(error),
67
- };
68
- },
53
+ /**
54
+ * Return the error information to include just the status and the message
55
+ * @param {Object} error
56
+ * @returns Object
57
+ */
58
+ export const getErrorInformation = (error) => {
59
+ return {
60
+ status: getErrorType(error),
61
+ message: errorToString(error),
62
+ };
63
+ };
69
64
 
70
- /**
71
- * Returns true if an exception should be handled to the business and presentation layer
72
- * @param {Boolean} returnAllExceptions - If set true all exceptions will be passed
73
- * @param {Object} error - The error returned by the server
74
- */
75
- shouldReturnError: (returnAllExceptions, error) => {
76
- if (getErrorType(error) === responseType.UNAUTHORIZED) {
77
- return returnAllExceptions;
78
- } else {
79
- return true;
80
- }
81
- },
65
+ /**
66
+ * Returns true if an exception should be handled to the business and presentation layer
67
+ * @param {Boolean} returnAllExceptions - If set true all exceptions will be passed
68
+ * @param {Object} error - The error returned by the server
69
+ */
70
+ export const shouldReturnError = (returnAllExceptions, error) => {
71
+ if (getErrorType(error) === responseType.UNAUTHORIZED) {
72
+ return returnAllExceptions;
73
+ } else {
74
+ return true;
75
+ }
82
76
  };
package/lib/config.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/dashboard.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/groups.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
  const errorToString = axios.errorToString;
3
3
  const axiosLib = require("axios");
4
4
  const htmlParser = require("node-html-parser");
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/logger.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/role.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/skill.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  // eslint-disable-next-line no-undef
4
4
  module.exports = {
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/teams.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/templates.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/tenants.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
 
3
3
  module.exports = {
4
4
  axios: axios,
package/lib/users.js CHANGED
@@ -1,4 +1,4 @@
1
- const { axios } = require("./axiosClient");
1
+ import { axios } from "./axiosClient";
2
2
  const { removeNullProperties } = require("./utils");
3
3
 
4
4
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackfactor/client-api",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Node.js library for the StackFactor API",
5
5
  "main": "index.js",
6
6
  "exports": {