@stackfactor/client-api 1.0.32 → 1.0.34

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/utils.js CHANGED
@@ -1,48 +1,44 @@
1
- const dotenv = require("dotenv");
1
+ import dotenv from "dotenv";
2
2
  // Load environment variables from .env file
3
3
  dotenv.config();
4
4
 
5
- const utils = {
6
- /**
7
- * Convert object to array
8
- * @param {Object} data
9
- * @returns {Array}
10
- */
11
- objectToArray: (data) => {
12
- if (typeof data === "object") {
13
- return [...data];
14
- } else throw new Error("Invalid type");
15
- },
16
-
17
- /**
18
- * Returns the backend base API URL
19
- * @returns {String}
20
- */
21
- getBaseUrl: () => {
22
- if (!process.env.NODE_ENV || process.env.NODE_ENV === "production") {
23
- return "https://api.stackfactor.io/";
24
- } else {
25
- return "http://localhost:3100/";
26
- }
27
- },
5
+ /**
6
+ * Convert object to array
7
+ * @param {Object} data
8
+ * @returns {Array}
9
+ */
10
+ export const objectToArray = (data) => {
11
+ if (typeof data === "object") {
12
+ return [...data];
13
+ } else throw new Error("Invalid type");
14
+ };
28
15
 
29
- /**
30
- * Remove null properties
31
- * @param {Object} object
32
- * @returns {Object}
33
- */
34
- removeNullProperties: (object) => {
35
- Object.keys(object).forEach((key) => {
36
- let value = object[key.toString()];
37
- let hasProperties = value && Object.keys(value).length > 0;
38
- if (value === null) {
39
- delete object[key.toString()];
40
- } else if (typeof value !== "string" && hasProperties) {
41
- removeNullProperties(value);
42
- }
43
- });
44
- return object;
45
- },
16
+ /**
17
+ * Returns the backend base API URL
18
+ * @returns {String}
19
+ */
20
+ export const getBaseUrl = () => {
21
+ if (!process.env.NODE_ENV || process.env.NODE_ENV === "production") {
22
+ return "https://api.stackfactor.io/";
23
+ } else {
24
+ return "http://localhost:3100/";
25
+ }
46
26
  };
47
27
 
48
- module.exports = utils;
28
+ /**
29
+ * Remove null properties
30
+ * @param {Object} object
31
+ * @returns {Object}
32
+ */
33
+ export const removeNullProperties = (object) => {
34
+ Object.keys(object).forEach((key) => {
35
+ let value = object[key.toString()];
36
+ let hasProperties = value && Object.keys(value).length > 0;
37
+ if (value === null) {
38
+ delete object[key.toString()];
39
+ } else if (typeof value !== "string" && hasProperties) {
40
+ removeNullProperties(value);
41
+ }
42
+ });
43
+ return object;
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackfactor/client-api",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "Node.js library for the StackFactor API",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -10,6 +10,7 @@
10
10
  "default": "./index.js"
11
11
  }
12
12
  },
13
+ "type": "module",
13
14
  "scripts": {
14
15
  "test": "echo \"Error: no test specified\" && exit 1"
15
16
  },
package/lib/templates.js DELETED
@@ -1,148 +0,0 @@
1
- import { axios } from "./axiosClient";
2
-
3
- module.exports = {
4
- axios: axios,
5
-
6
- /**
7
- * Create template and set information
8
- * @param {Object} data New template data information
9
- * @param {String} token Authorization token
10
- */
11
- createTemplate: (data, token) => {
12
- return new Promise(function (resolve, reject) {
13
- const requestData = {
14
- data: data,
15
- };
16
- let confirmationRequest = axios.put("api/v1/templates", requestData, {
17
- headers: { authorization: token },
18
- });
19
- confirmationRequest
20
- .then((response) => {
21
- resolve(response.data);
22
- })
23
- .catch((error) => {
24
- reject(error);
25
- });
26
- });
27
- },
28
-
29
- /**
30
- * Delete template
31
- * @param {number} id The id of the template to be deleted
32
- * @param {String} token Authorization token
33
- */
34
- deleteTemplate: (id, token) => {
35
- return new Promise(function (resolve, reject) {
36
- const requestData = {
37
- id: id,
38
- };
39
- let confirmationRequest = axios.delete(`api/v1/templates/`, {
40
- headers: { authorization: token },
41
- data: requestData,
42
- });
43
- confirmationRequest
44
- .then((response) => {
45
- resolve(response);
46
- })
47
- .catch((error) => {
48
- reject(error);
49
- });
50
- });
51
- },
52
-
53
- /**
54
- * Get template information
55
- * @param {number} id The id of the template
56
- * @param {String} token Authorization token
57
- */
58
- getTemplateInformationById: (id, version, token) => {
59
- return new Promise(function (resolve, reject) {
60
- let confirmationRequest = axios.get(`api/v1/templates/${id}/${version}`, {
61
- headers: { authorization: token },
62
- });
63
- confirmationRequest
64
- .then((response) => {
65
- resolve(response.data);
66
- })
67
- .catch((error) => {
68
- reject(error);
69
- });
70
- });
71
- },
72
-
73
- /**
74
- * Get template information
75
- * @param {Object} filter The filter used to select the template
76
- * @param {String} token Authorization token
77
- */
78
- getTemplateList: (filter, version, token) => {
79
- return new Promise(function (resolve, reject) {
80
- const requestData = {
81
- filter: filter ? filter : "",
82
- version: version,
83
- };
84
- let confirmationRequest = axios.post(`api/v1/templates`, requestData, {
85
- headers: { authorization: token },
86
- });
87
- confirmationRequest
88
- .then((response) => {
89
- resolve(response.data);
90
- })
91
- .catch((error) => {
92
- reject(error);
93
- });
94
- });
95
- },
96
-
97
- /**
98
- * Publish template
99
- * @param {number} id The id of the template to be published
100
- * @param {String} token Authorization token
101
- */
102
- publishTemplate: (id, token) => {
103
- return new Promise(function (resolve, reject) {
104
- let confirmationRequest = axios.post(
105
- `api/v1/templates/publish/${id}`,
106
- {},
107
- {
108
- headers: { authorization: token },
109
- }
110
- );
111
- confirmationRequest
112
- .then((response) => {
113
- resolve(response.data);
114
- })
115
- .catch((error) => {
116
- reject(error);
117
- });
118
- });
119
- },
120
-
121
- /**
122
- * Set template profile information
123
- * @param {String} id The id of the template to be updated
124
- * @param {Object} data Data used to update the template
125
- * @param {String} token Authorization token
126
- */
127
- setTemplateInformation: (id, data, token) => {
128
- return new Promise(function (resolve, reject) {
129
- const requestData = {
130
- data: data,
131
- };
132
- let confirmationRequest = axios.post(
133
- `api/v1/templates/${id}`,
134
- requestData,
135
- {
136
- headers: { authorization: token },
137
- }
138
- );
139
- confirmationRequest
140
- .then((response) => {
141
- resolve(response.data);
142
- })
143
- .catch((error) => {
144
- reject(error);
145
- });
146
- });
147
- },
148
- };