zudello-integration-sdk 1.0.22 → 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/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
|
};
|
|
@@ -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
|