zudello-integration-sdk 1.0.31 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudello-integration-sdk",
3
- "version": "1.0.31",
3
+ "version": "1.0.34",
4
4
  "description": "Zudello Integrations SDK",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
@@ -36,6 +36,7 @@ const PoDocumentModule = require("./submodules/intacct/PoDocument");
36
36
  const ArTermModule = require("./submodules/intacct/ArTerm");
37
37
  const ArInvoiceModule = require("./submodules/intacct/ArInvoice");
38
38
  const ArAdjustmentModule = require("./submodules/intacct/ArAdjustment");
39
+ const JournalModule = require("./submodules/intacct/Journal");
39
40
  const FileModule = require("./submodules/intacct/File");
40
41
  const ZoneModule = require("./submodules/intacct/Zone");
41
42
 
@@ -95,6 +96,7 @@ class IntacctSDK extends BaseSDK {
95
96
  this.arTerm = new ArTermModule(this);
96
97
  this.arInvoice = new ArInvoiceModule(this);
97
98
  this.arAdjustment = new ArAdjustmentModule(this);
99
+ this.journal = new JournalModule(this);
98
100
  this.zone = new ZoneModule(this);
99
101
  this.file = new FileModule(this);
100
102
  }
@@ -13,6 +13,23 @@ class ApAdjustmentModule {
13
13
  this.item = new ApAdjustmentItemModule(parentModule)
14
14
  }
15
15
 
16
+ /**
17
+ * Creates AP Adjustment.
18
+ * @returns {object} Create AP Adjustmnet Response.
19
+ */
20
+ async create ({ ...fields }) {
21
+ return await this.module.makeRequest('POST', `${this.module.apiURL}/zintegrations/action/c1da53d1-140f-4476-8d74-42558d1d8fab`, {
22
+ mappable_parameters: {
23
+ debug: {
24
+ value: false
25
+ },
26
+ ...fields
27
+ }
28
+ }, {
29
+ _debug: true
30
+ })
31
+ }
32
+
16
33
  /**
17
34
  * Reuse Universal Listing with type APADJUSTMENT.
18
35
  * @returns {object} List Response.
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ class JournalModule {
4
+ /**
5
+ * Constructor.
6
+ * @param {class} parentModule Object of Intacct class.
7
+ */
8
+ constructor (parentModule) {
9
+ this.module = parentModule
10
+ }
11
+
12
+ /**
13
+ * Creates Journal.
14
+ * @returns {object} Create Journal Response.
15
+ */
16
+ async create ({ ...fields }) {
17
+ return await this.module.makeRequest('POST', `${this.module.apiURL}/zintegrations/action/3b8a9f62-0a3f-472e-b7ad-c01af6b5c6e3`, {
18
+ mappable_parameters: {
19
+ debug: {
20
+ value: false
21
+ },
22
+ ...fields
23
+ }
24
+ }, {
25
+ _debug: true
26
+ })
27
+ }
28
+
29
+ /**
30
+ * Reuse Universal Listing with type JOURNAL.
31
+ * @returns {object} List Response.
32
+ */
33
+ async list ({ include = [], exclude = [], filters, orderBy = null, entity = null, showPrivate = false, pageSize = 1000, offset = 0, returnFormat = 'json' }) {
34
+ return await this.module.universal.list({ type: 'GLBATCH', include, exclude, filters, orderBy, entity, showPrivate, pageSize, offset, returnFormat })
35
+ }
36
+
37
+ /**
38
+ * Reuse Universal Auto Pagination Listing with type GLACCOUNT.
39
+ * @returns {object} Auto Pagination responses.
40
+ */
41
+ async * autoPaginationList ({ include = [], exclude = [], filters, orderBy = null, entity = null, showPrivate = false, pageSize = 1000, offset = 0, returnFormat = 'json' }) {
42
+ for await (const response of this.module.universal.autoPaginationList({ type: 'GLBATCH', include, exclude, filters, orderBy, entity, showPrivate, pageSize, offset, returnFormat })) {
43
+ yield response
44
+ }
45
+ }
46
+ }
47
+
48
+ module.exports = JournalModule
@@ -11,13 +11,20 @@ class ApiInstance {
11
11
  */
12
12
  constructor () {
13
13
  this.bearerToken = null
14
- this.retryStatuses = [502, 504]
14
+ this.retryStatuses = [502, 504, 408, 429, 500]
15
15
 
16
16
  this.responseHandler = new ResponseHandler()
17
17
 
18
18
  this.axiosInstance = axios.create({
19
- httpsAgent: new https.Agent({ keepAlive: true })
19
+ httpsAgent: new https.Agent({
20
+ keepAlive: true,
21
+ timeout: 60000, // 60 seconds timeout
22
+ maxSockets: 100,
23
+ maxFreeSockets: 10,
24
+ }),
25
+ timeout: 30000, // 30 seconds timeout for the request itself
20
26
  })
27
+
21
28
  this.axiosInstance.interceptors.request.use((config) => {
22
29
  if (this.bearerToken) {
23
30
  config.headers.Authorization = `Bearer ${this.bearerToken}`
@@ -27,6 +34,35 @@ class ApiInstance {
27
34
  }, (error) => {
28
35
  return Promise.reject(error)
29
36
  })
37
+
38
+ // Add response interceptor for global error handling
39
+ this.axiosInstance.interceptors.response.use(
40
+ response => response,
41
+ error => {
42
+ // Check if the error is a network error or ECONNRESET
43
+ if (error.code === 'ECONNRESET' || error.code === 'ECONNABORTED' || error.message === 'socket hang up') {
44
+ error.shouldRetry = true
45
+ }
46
+
47
+ return Promise.reject(error)
48
+ }
49
+ )
50
+ }
51
+
52
+ /**
53
+ * Determines if a request should be retried based on the error
54
+ * @param {Error} error The error that occurred
55
+ * @returns {boolean} Whether to retry the request
56
+ */
57
+ shouldRetry(error) {
58
+ // Retry on network errors and specific HTTP status codes
59
+ return (
60
+ error.shouldRetry || // Set by our interceptor for network errors
61
+ this.retryStatuses.includes(error?.response?.status) ||
62
+ (error.code === 'ECONNRESET') ||
63
+ (error.message === 'socket hang up') ||
64
+ (error.code === 'ECONNABORTED')
65
+ )
30
66
  }
31
67
 
32
68
  /**
@@ -75,7 +111,7 @@ class ApiInstance {
75
111
  callback(CircularJSON.stringify(error, null, 2))
76
112
  callback(CircularJSON.stringify(error.response, null, 2))
77
113
 
78
- if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
114
+ if (this.shouldRetry(error) && retryCount === 0) {
79
115
  await this.sleep(20000)
80
116
  return await this.get(url, params, headers, returnHeaders, callback, retryCount + 1)
81
117
  }
@@ -135,7 +171,7 @@ class ApiInstance {
135
171
  callback(CircularJSON.stringify(error, null, 2))
136
172
  callback(CircularJSON.stringify(error.response, null, 2))
137
173
 
138
- if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
174
+ if (this.shouldRetry(error) && retryCount === 0) {
139
175
  await this.sleep(20000)
140
176
  return await this.post(url, data, headers, params, callback, retryCount + 1)
141
177
  }
@@ -180,7 +216,7 @@ class ApiInstance {
180
216
 
181
217
  callback(error?.response)
182
218
 
183
- if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
219
+ if (this.shouldRetry(error) && retryCount === 0) {
184
220
  await this.sleep(20000)
185
221
  return await this.put(url, data, headers, params, callback, retryCount + 1)
186
222
  }
@@ -216,7 +252,7 @@ class ApiInstance {
216
252
 
217
253
  callback(error?.response)
218
254
 
219
- if (this.retryStatuses.includes(error?.response?.status) && retryCount === 0) {
255
+ if (this.shouldRetry(error) && retryCount === 0) {
220
256
  await this.sleep(20000)
221
257
  return await this.delete(url, callback, retryCount + 1)
222
258
  }