zudello-integration-sdk 1.0.21 → 1.0.23
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 +2 -0
- package/src/sdk/submodules/jobready/Universal.js +107 -103
- package/src/sdk/submodules/retailExpress/Universal.js +107 -103
- package/src/sdk/submodules/xero/Universal.js +2 -2
- package/src/sdk/submodules/zudello/Employee.js +1 -1
- package/src/utils/formHelper.js +86 -0
package/package.json
CHANGED
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
|
};
|
|
@@ -1,107 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
class UniversalModule {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Constructor.
|
|
6
|
+
* @param {class} parentModule Object of JobReady class.
|
|
7
|
+
*/
|
|
8
|
+
constructor(parentModule) {
|
|
9
|
+
this.module = parentModule;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Universal Request By URL and Method.
|
|
14
|
+
* @param {string} url URL of request.
|
|
15
|
+
* @param {string} method Method of request.
|
|
16
|
+
* @param {object} qs Some available filters inside: offset, limit.
|
|
17
|
+
* @param {object} body Some available data inside.
|
|
18
|
+
* @returns {object} Universal Request Response.
|
|
19
|
+
*/
|
|
20
|
+
async request({ url, method, qs = {}, body = {} }) {
|
|
21
|
+
const validateIsEmpty = this.module.validator.isEmpty({ url, method });
|
|
22
|
+
|
|
23
|
+
if (!validateIsEmpty.valid) {
|
|
24
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return await this.module.makeRequest(
|
|
28
|
+
"POST",
|
|
29
|
+
`${this.module.apiURL}/zintegrations/action/107c52fc-0404-4768-8d0d-deb7a348b8a3`,
|
|
30
|
+
{
|
|
31
|
+
mappable_parameters: {
|
|
32
|
+
url: {
|
|
33
|
+
value: url,
|
|
34
|
+
},
|
|
35
|
+
method: {
|
|
36
|
+
value: method,
|
|
37
|
+
},
|
|
38
|
+
qs: {
|
|
39
|
+
isMap: true,
|
|
40
|
+
value: JSON.stringify(qs),
|
|
41
|
+
},
|
|
42
|
+
body: {
|
|
43
|
+
isMap: true,
|
|
44
|
+
value: JSON.stringify(body),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Universal List By URL and Method.
|
|
53
|
+
* @param {string} url URL of listed data.
|
|
54
|
+
* @param {string} method Method of listed data.
|
|
55
|
+
* @param {object} qs Some available filters inside: Page, Limit.
|
|
56
|
+
* @param {object} body Some available data inside.
|
|
57
|
+
* @returns {object} Universal List Response.
|
|
58
|
+
*/
|
|
59
|
+
async list({ url, method, qs = {}, body = {} }) {
|
|
60
|
+
const validateIsEmpty = this.module.validator.isEmpty({ url, method });
|
|
61
|
+
|
|
62
|
+
if (!validateIsEmpty.valid) {
|
|
63
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!qs.page) {
|
|
67
|
+
qs.page = 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!qs.per_page) {
|
|
71
|
+
qs.per_page = 100;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return await this.request({ url, method, qs, body });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Universal Auto Pagination Listing.
|
|
79
|
+
* @param {number} offset Offset of listed data.
|
|
80
|
+
* @param {number} limit Limit of listed data.
|
|
81
|
+
* @param {string} query Query of listed data.
|
|
82
|
+
* @returns {object} Auto Pagination responses.
|
|
83
|
+
*/
|
|
84
|
+
async *autoPaginationList({ url, method, qs = {}, body = {} }) {
|
|
85
|
+
if (!qs.page) {
|
|
86
|
+
qs.page = 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!qs.per_page) {
|
|
90
|
+
qs.per_page = 100;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let response = await this.list({ url, method, qs, body });
|
|
94
|
+
let currentPageCount = response?.data?.data?.length;
|
|
95
|
+
|
|
96
|
+
yield response;
|
|
97
|
+
|
|
98
|
+
if (currentPageCount && currentPageCount === qs.per_page) {
|
|
99
|
+
while (currentPageCount === qs.per_page) {
|
|
100
|
+
qs.page_number = qs.page_number + 1;
|
|
101
|
+
|
|
102
|
+
response = await this.list({ url, method, qs, body });
|
|
103
|
+
currentPageCount = response?.data?.data?.length;
|
|
104
|
+
|
|
105
|
+
yield response;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
module.exports = UniversalModule
|
|
111
|
+
module.exports = UniversalModule;
|
|
@@ -1,107 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
class UniversalModule {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Constructor.
|
|
6
|
+
* @param {class} parentModule Object of RetailExpress class.
|
|
7
|
+
*/
|
|
8
|
+
constructor(parentModule) {
|
|
9
|
+
this.module = parentModule;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Universal Request By URL and Method.
|
|
14
|
+
* @param {string} url URL of request.
|
|
15
|
+
* @param {string} method Method of request.
|
|
16
|
+
* @param {object} qs Some available filters inside: offset, limit.
|
|
17
|
+
* @param {object} body Some available data inside.
|
|
18
|
+
* @returns {object} Universal Request Response.
|
|
19
|
+
*/
|
|
20
|
+
async request({ url, method, qs = {}, body = {} }) {
|
|
21
|
+
const validateIsEmpty = this.module.validator.isEmpty({ url, method });
|
|
22
|
+
|
|
23
|
+
if (!validateIsEmpty.valid) {
|
|
24
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return await this.module.makeRequest(
|
|
28
|
+
"POST",
|
|
29
|
+
`${this.module.apiURL}/zintegrations/action/ae4efc7a-b6ba-4093-8e06-fa9d846e4e29`,
|
|
30
|
+
{
|
|
31
|
+
mappable_parameters: {
|
|
32
|
+
url: {
|
|
33
|
+
value: url,
|
|
34
|
+
},
|
|
35
|
+
method: {
|
|
36
|
+
value: method,
|
|
37
|
+
},
|
|
38
|
+
qs: {
|
|
39
|
+
isMap: true,
|
|
40
|
+
value: JSON.stringify(qs),
|
|
41
|
+
},
|
|
42
|
+
body: {
|
|
43
|
+
isMap: true,
|
|
44
|
+
value: JSON.stringify(body),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Universal List By URL and Method.
|
|
53
|
+
* @param {string} url URL of listed data.
|
|
54
|
+
* @param {string} method Method of listed data.
|
|
55
|
+
* @param {object} qs Some available filters inside: Page, Limit.
|
|
56
|
+
* @param {object} body Some available data inside.
|
|
57
|
+
* @returns {object} Universal List Response.
|
|
58
|
+
*/
|
|
59
|
+
async list({ url, method, qs = {}, body = {} }) {
|
|
60
|
+
const validateIsEmpty = this.module.validator.isEmpty({ url, method });
|
|
61
|
+
|
|
62
|
+
if (!validateIsEmpty.valid) {
|
|
63
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!qs.page_number) {
|
|
67
|
+
qs.page_number = 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!qs.page_size) {
|
|
71
|
+
qs.page_size = 100;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return await this.request({ url, method, qs, body });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Universal Auto Pagination Listing.
|
|
79
|
+
* @param {number} offset Offset of listed data.
|
|
80
|
+
* @param {number} limit Limit of listed data.
|
|
81
|
+
* @param {string} query Query of listed data.
|
|
82
|
+
* @returns {object} Auto Pagination responses.
|
|
83
|
+
*/
|
|
84
|
+
async *autoPaginationList({ url, method, qs = {}, body = {} }) {
|
|
85
|
+
if (!qs.page_number) {
|
|
86
|
+
qs.page_number = 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!qs.page_size) {
|
|
90
|
+
qs.page_size = 100;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let response = await this.list({ url, method, qs, body });
|
|
94
|
+
let currentPageCount = response?.data?.data?.length;
|
|
95
|
+
|
|
96
|
+
yield response;
|
|
97
|
+
|
|
98
|
+
if (currentPageCount && currentPageCount === qs.page_size) {
|
|
99
|
+
while (currentPageCount === qs.page_size) {
|
|
100
|
+
qs.page_number = qs.page_number + 1;
|
|
101
|
+
|
|
102
|
+
response = await this.list({ url, method, qs, body });
|
|
103
|
+
currentPageCount = response?.data?.data?.length;
|
|
104
|
+
|
|
105
|
+
yield response;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
module.exports = UniversalModule
|
|
111
|
+
module.exports = UniversalModule;
|
|
@@ -94,8 +94,8 @@ class UniversalModule {
|
|
|
94
94
|
|
|
95
95
|
yield response;
|
|
96
96
|
|
|
97
|
-
if (currentPageCount && currentPageCount ===
|
|
98
|
-
while (currentPageCount ===
|
|
97
|
+
if (currentPageCount && currentPageCount === 100) {
|
|
98
|
+
while (currentPageCount === 100) {
|
|
99
99
|
qs.page = qs.page + 1;
|
|
100
100
|
|
|
101
101
|
response = await this.list({ url, method, header, qs, body });
|
|
@@ -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
|