zudello-integration-sdk 1.0.45 → 1.0.47
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 +1 -1
- package/src/index.js +6 -0
- package/src/utils/ai.js +20 -0
- package/src/utils/apiInstance.js +10 -2
- package/src/utils/bucket.js +118 -0
- package/src/utils/ediBucket.js +11 -0
- package/src/utils/fileBucket.js +11 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -24,6 +24,9 @@ const GPSDK = require('./sdk/GP')
|
|
|
24
24
|
const EDISDK = require('./sdk/EDI')
|
|
25
25
|
const SunSystemsSDK = require('./sdk/SunSystems')
|
|
26
26
|
|
|
27
|
+
const AI = require('./utils/ai')
|
|
28
|
+
const FileBucket = require('./utils/fileBucket')
|
|
29
|
+
const EDIBucket = require('./utils/ediBucket')
|
|
27
30
|
const Logger = require('./utils/logger')
|
|
28
31
|
const Metadata = require('./utils/metadata')
|
|
29
32
|
const Message = require('./utils/message')
|
|
@@ -55,6 +58,9 @@ const S3Client = {
|
|
|
55
58
|
|
|
56
59
|
module.exports = {
|
|
57
60
|
Auth,
|
|
61
|
+
AI,
|
|
62
|
+
FileBucket,
|
|
63
|
+
EDIBucket,
|
|
58
64
|
ZudelloSDK,
|
|
59
65
|
ZudelloAuthSDK,
|
|
60
66
|
NetsuiteSDK,
|
package/src/utils/ai.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
class AI {
|
|
4
|
+
constructor(apiInstance = null, teamUUID = null) {
|
|
5
|
+
this.apiInstance = apiInstance
|
|
6
|
+
this.teamUUID = teamUUID
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async prompt(data = {}) {
|
|
10
|
+
if (!this.apiInstance || !this.teamUUID || !process.env.ZUDELLO_API_URL) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/ai/prompt`, data, {
|
|
15
|
+
'x-team': this.teamUUID
|
|
16
|
+
}, {}, () => {}, 0, false)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = AI
|
package/src/utils/apiInstance.js
CHANGED
|
@@ -144,7 +144,7 @@ class ApiInstance {
|
|
|
144
144
|
* @param {object} params Request Params.
|
|
145
145
|
* @returns {object} Response Data.
|
|
146
146
|
*/
|
|
147
|
-
async post (url, data, headers, params = {}, callback = () => {}, retryCount = 0) {
|
|
147
|
+
async post (url, data, headers, params = {}, callback = () => {}, retryCount = 0, handleResponse = true) {
|
|
148
148
|
try {
|
|
149
149
|
const response = await this.axiosInstance.post(url, data, { headers, params })
|
|
150
150
|
|
|
@@ -156,6 +156,10 @@ class ApiInstance {
|
|
|
156
156
|
body: data
|
|
157
157
|
})
|
|
158
158
|
|
|
159
|
+
if (!handleResponse) {
|
|
160
|
+
return response?.data
|
|
161
|
+
}
|
|
162
|
+
|
|
159
163
|
if (Object.prototype.hasOwnProperty.call(params, '_debug') && params._debug) {
|
|
160
164
|
return this.responseHandler.success(response?.data?.data || null)
|
|
161
165
|
}
|
|
@@ -175,7 +179,11 @@ class ApiInstance {
|
|
|
175
179
|
|
|
176
180
|
if (this.shouldRetry(error) && retryCount === 0) {
|
|
177
181
|
await this.sleep(20000)
|
|
178
|
-
return await this.post(url, data, headers, params, callback, retryCount + 1)
|
|
182
|
+
return await this.post(url, data, headers, params, callback, retryCount + 1, handleResponse)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!handleResponse) {
|
|
186
|
+
return error?.response?.data
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
if (error?.response?.status === 500) {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
class Bucket {
|
|
4
|
+
constructor(apiInstance = null, teamUUID = null, type = null) {
|
|
5
|
+
this.apiInstance = apiInstance
|
|
6
|
+
this.teamUUID = teamUUID
|
|
7
|
+
this.type = type
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async list(path, recursive = false, page = 1, limit = 1000) {
|
|
11
|
+
if (!this._canPerformOperation()) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/list`, {
|
|
16
|
+
path,
|
|
17
|
+
recursive,
|
|
18
|
+
page,
|
|
19
|
+
limit
|
|
20
|
+
}, {
|
|
21
|
+
'x-team': this.teamUUID
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async get(path, fileName) {
|
|
26
|
+
if (!this._canPerformOperation()) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/get`, {
|
|
31
|
+
path,
|
|
32
|
+
fileName
|
|
33
|
+
}, {
|
|
34
|
+
'x-team': this.teamUUID
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async getSignedUrl(path, fileName, expiresIn = 300) {
|
|
39
|
+
if (!this._canPerformOperation()) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/signed`, {
|
|
44
|
+
path,
|
|
45
|
+
fileName,
|
|
46
|
+
expiresIn
|
|
47
|
+
}, {
|
|
48
|
+
'x-team': this.teamUUID
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async create(path, fileName, contents, contentType, overwrite = false) {
|
|
53
|
+
if (!this._canPerformOperation()) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/create`, {
|
|
58
|
+
path,
|
|
59
|
+
fileName,
|
|
60
|
+
contents,
|
|
61
|
+
contentType,
|
|
62
|
+
overwrite
|
|
63
|
+
}, {
|
|
64
|
+
'x-team': this.teamUUID
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async update(path, fileName, contents, contentType = null) {
|
|
69
|
+
if (!this._canPerformOperation()) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let data = {
|
|
74
|
+
path,
|
|
75
|
+
fileName,
|
|
76
|
+
contents
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (contentType) {
|
|
80
|
+
data.contentType = contentType
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/update`, data, {
|
|
84
|
+
'x-team': this.teamUUID
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async deleteFolder(path) {
|
|
89
|
+
if (!this._canPerformOperation()) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/delete-folder`, {
|
|
94
|
+
path
|
|
95
|
+
}, {
|
|
96
|
+
'x-team': this.teamUUID
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async deleteFile(path, fileName) {
|
|
101
|
+
if (!this._canPerformOperation()) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return await this.apiInstance.post(`${process.env.ZUDELLO_API_URL}/s3/${this.type}/delete-file`, {
|
|
106
|
+
path,
|
|
107
|
+
fileName
|
|
108
|
+
}, {
|
|
109
|
+
'x-team': this.teamUUID
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_canPerformOperation() {
|
|
114
|
+
return this.apiInstance && this.teamUUID && process.env.ZUDELLO_API_URL && this.type
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = Bucket
|