zudello-integration-sdk 1.0.22 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudello-integration-sdk",
3
- "version": "1.0.22",
3
+ "version": "1.0.25",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
@@ -13,6 +13,7 @@
13
13
  "dependencies": {
14
14
  "@aws-sdk/client-s3": "^3.658.0",
15
15
  "axios": "^1.6.7",
16
+ "circular-json": "^0.5.9",
16
17
  "dotenv": "^16.4.5",
17
18
  "lodash": "^4.17.21",
18
19
  "moment-timezone": "^0.5.45",
package/src/index.js CHANGED
@@ -24,6 +24,7 @@ const Properties = require("./utils/properties");
24
24
  const MiscHelper = require("./utils/miscHelper");
25
25
  const ModelHelper = require("./utils/modelHelper");
26
26
  const DatasetHelper = require("./utils/datasetHelper");
27
+ const FormHelper = require("./utils/formHelper");
27
28
  const {
28
29
  getFileContent,
29
30
  uploadFile,
@@ -64,5 +65,6 @@ module.exports = {
64
65
  MiscHelper,
65
66
  ModelHelper,
66
67
  DatasetHelper,
68
+ FormHelper,
67
69
  S3Client,
68
70
  };
package/src/sdk/Base.js CHANGED
@@ -49,18 +49,22 @@ class BaseSDK {
49
49
  }
50
50
 
51
51
  async makeRequest (method, url, data, params = {}, returnHeaders = false) {
52
- const callback = ({ status, response, body, params, headers }) => {
53
- this.logger.request(`${this.integrationName} - ${method} ${url}`, {
54
- status,
55
- request: {
56
- url,
57
- method,
58
- body,
59
- params,
60
- headers
61
- },
62
- response
63
- })
52
+ // const callback = ({ status, response, body, params, headers }) => {
53
+ // this.logger.request(`${this.integrationName} - ${method} ${url}`, {
54
+ // status,
55
+ // request: {
56
+ // url,
57
+ // method,
58
+ // body,
59
+ // params,
60
+ // headers
61
+ // },
62
+ // response
63
+ // })
64
+ // }
65
+
66
+ const callback = (data) => {
67
+ this.logger.request(`${this.integrationName} - ${method} ${url}`, data)
64
68
  }
65
69
 
66
70
  switch (method.toLowerCase()) {
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const axios = require('axios')
4
+ const CircularJSON = require('circular-json')
4
5
  const ResponseHandler = require('./responseHandler')
5
6
 
6
7
  class ApiInstance {
@@ -61,12 +62,15 @@ class ApiInstance {
61
62
  ? this.responseHandler.success(response.headers || null)
62
63
  : this.responseHandler.success(response.data || null)
63
64
  } catch (error) {
64
- callback({
65
- status: error?.response?.status,
66
- response: error?.response?.data,
67
- params,
68
- headers
69
- })
65
+ // callback({
66
+ // status: error?.response?.status,
67
+ // response: error?.response?.data,
68
+ // params,
69
+ // headers
70
+ // })
71
+
72
+ callback(CircularJSON.stringify(error, null, 2))
73
+ callback(CircularJSON.stringify(error.response, null, 2))
70
74
 
71
75
  if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
72
76
  await this.sleep(20000)
@@ -117,13 +121,16 @@ class ApiInstance {
117
121
 
118
122
  return this.responseHandler.success(response.data || null)
119
123
  } catch (error) {
120
- callback({
121
- status: error?.response?.status,
122
- response: error?.response?.data,
123
- params,
124
- headers,
125
- body: data
126
- })
124
+ // callback({
125
+ // status: error?.response?.status,
126
+ // response: error?.response?.data,
127
+ // params,
128
+ // headers,
129
+ // body: data
130
+ // })
131
+
132
+ callback(CircularJSON.stringify(error, null, 2))
133
+ callback(CircularJSON.stringify(error.response, null, 2))
127
134
 
128
135
  if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
129
136
  await this.sleep(20000)
@@ -160,13 +167,15 @@ class ApiInstance {
160
167
 
161
168
  return this.responseHandler.success(response.data || null)
162
169
  } catch (error) {
163
- callback({
164
- status: error?.response?.status,
165
- response: error?.response?.data,
166
- params,
167
- headers,
168
- body: data
169
- })
170
+ // callback({
171
+ // status: error?.response?.status,
172
+ // response: error?.response?.data,
173
+ // params,
174
+ // headers,
175
+ // body: data
176
+ // })
177
+
178
+ callback(error?.response)
170
179
 
171
180
  if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
172
181
  await this.sleep(20000)
@@ -197,10 +206,12 @@ class ApiInstance {
197
206
 
198
207
  return response.data
199
208
  } catch (error) {
200
- callback({
201
- status: error?.response?.status,
202
- response: error?.response?.data
203
- })
209
+ // callback({
210
+ // status: error?.response?.status,
211
+ // response: error?.response?.data
212
+ // })
213
+
214
+ callback(error?.response)
204
215
 
205
216
  if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
206
217
  await this.sleep(20000)
@@ -0,0 +1,86 @@
1
+ 'use strict'
2
+
3
+ const _ = require('lodash')
4
+
5
+ class FormHelper {
6
+ constructor(apiInstance, apiUrl, logger, teamUUID, executionUUID, data) {
7
+ this.apiInstance = apiInstance
8
+ this.apiUrl = apiUrl
9
+
10
+ this.logger = logger
11
+ this.teamUUID = teamUUID
12
+ this.executionUUID = executionUUID
13
+
14
+ this.data = data
15
+ }
16
+
17
+ async load(uuid, failCallback) {
18
+ failCallback = failCallback || ((data) => this.defaultFailCallback(data))
19
+
20
+ this.logger.info('Form UUID', uuid)
21
+
22
+ return await this.get(uuid, failCallback)
23
+ }
24
+
25
+ async get(uuid, failCallback) {
26
+ failCallback = failCallback || ((data) => this.defaultFailCallback(data))
27
+
28
+ if (!uuid) {
29
+ return failCallback({ uuid })
30
+ }
31
+
32
+ const fetchedForm = await this.apiInstance.get(`${this.apiUrl}/form/${uuid}`, {}, {
33
+ 'x-team': this.teamUUID
34
+ })
35
+
36
+ this.logger.debug('Fetched Form', fetchedForm)
37
+
38
+ if (fetchedForm && fetchedForm.data) {
39
+ const data = fetchedForm.data?.data || null
40
+
41
+ if (data) {
42
+ return new FormHelper(this.apiInstance, this.apiUrl, this.logger, this.teamUUID, this.executionUUID, data)
43
+ }
44
+ }
45
+
46
+ return failCallback({ uuid })
47
+ }
48
+
49
+ async createRequest(data) {
50
+ if (!this.data) {
51
+ return
52
+ }
53
+
54
+ if (data.resource) {
55
+ data.resource_model = data.resource.model
56
+ data.resource_uuid = data.resource.uuid
57
+
58
+ delete data.resource
59
+ }
60
+
61
+ this.logger.debug('Create Request Data', data)
62
+
63
+ const request = await this.apiInstance.post(`${this.apiUrl}/request`, {
64
+ ...data,
65
+ form_uuid: this.data.uuid,
66
+ execution_uuid: this.executionUUID
67
+ }, {
68
+ 'x-team': this.teamUUID
69
+ })
70
+
71
+ this.logger.debug('Create Request Response', request)
72
+
73
+ return request
74
+ }
75
+
76
+ data() {
77
+ return this.data
78
+ }
79
+
80
+ defaultFailCallback(data) {
81
+ this.logger.error('Unable to find Form', data)
82
+ throw new Error('Unable to find Form')
83
+ }
84
+ }
85
+
86
+ module.exports = FormHelper