zudello-integration-sdk 1.0.4 → 1.0.6
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 +21 -21
- package/src/sdk/Zudello.js +221 -202
- package/src/sdk/submodules/myobAcumatica/Universal.js +138 -105
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
"name": "zudello-integration-sdk",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Zudello Integrations SDK",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/zudello/integration-sdk.git"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@aws-sdk/client-s3": "^3.658.0",
|
|
15
|
+
"axios": "^1.6.7",
|
|
16
|
+
"dotenv": "^16.4.5",
|
|
17
|
+
"lodash": "^4.17.21",
|
|
18
|
+
"moment-timezone": "^0.5.45",
|
|
19
|
+
"perf_hooks": "^0.0.1",
|
|
20
|
+
"standard": "^17.1.0"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT"
|
|
23
23
|
}
|
package/src/sdk/Zudello.js
CHANGED
|
@@ -1,206 +1,225 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const _ = require(
|
|
4
|
-
|
|
5
|
-
const BaseSDK = require(
|
|
6
|
-
const AccountModule = require(
|
|
7
|
-
const AccountGroupModule = require(
|
|
8
|
-
const AccountingPeriodModule = require(
|
|
9
|
-
const CostCentreModule = require(
|
|
10
|
-
const CostTypeModule = require(
|
|
11
|
-
const CustomerModule = require(
|
|
12
|
-
const CustomerCategoryModule = require(
|
|
13
|
-
const CustomerGroupModule = require(
|
|
14
|
-
const CurrencyModule = require(
|
|
15
|
-
const DepartmentModule = require(
|
|
16
|
-
const EmployeeModule = require(
|
|
17
|
-
const SubsidiaryModule = require(
|
|
18
|
-
const LocationModule = require(
|
|
19
|
-
const TaxRateModule = require(
|
|
20
|
-
const TaxSolutionModule = require(
|
|
21
|
-
const ItemModule = require(
|
|
22
|
-
const ItemCategoryModule = require(
|
|
23
|
-
const ItemGroupModule = require(
|
|
24
|
-
const PurchaseOrderModule = require(
|
|
25
|
-
const PaymentTermModule = require(
|
|
26
|
-
const PaymentMethodModule = require(
|
|
27
|
-
const ProjectModule = require(
|
|
28
|
-
const ProjectGroupModule = require(
|
|
29
|
-
const ProjectTaskModule = require(
|
|
30
|
-
const SupplierCategoryModule = require(
|
|
31
|
-
const SupplierGroupModule = require(
|
|
32
|
-
const UomModule = require(
|
|
33
|
-
const WarehouseModule = require(
|
|
34
|
-
const ZoneModule = require(
|
|
35
|
-
const SupplierModule = require(
|
|
36
|
-
const FixedAssetModule = require(
|
|
37
|
-
const UniversalModule = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
|
|
5
|
+
const BaseSDK = require("./Base");
|
|
6
|
+
const AccountModule = require("./submodules/zudello/Account");
|
|
7
|
+
const AccountGroupModule = require("./submodules/zudello/AccountGroup");
|
|
8
|
+
const AccountingPeriodModule = require("./submodules/zudello/AccountingPeriod");
|
|
9
|
+
const CostCentreModule = require("./submodules/zudello/CostCentre");
|
|
10
|
+
const CostTypeModule = require("./submodules/zudello/CostType");
|
|
11
|
+
const CustomerModule = require("./submodules/zudello/Customer");
|
|
12
|
+
const CustomerCategoryModule = require("./submodules/zudello/CustomerCategory");
|
|
13
|
+
const CustomerGroupModule = require("./submodules/zudello/CustomerGroup");
|
|
14
|
+
const CurrencyModule = require("./submodules/zudello/Currency");
|
|
15
|
+
const DepartmentModule = require("./submodules/zudello/Department");
|
|
16
|
+
const EmployeeModule = require("./submodules/zudello/Employee");
|
|
17
|
+
const SubsidiaryModule = require("./submodules/zudello/Subsidiary");
|
|
18
|
+
const LocationModule = require("./submodules/zudello/Location");
|
|
19
|
+
const TaxRateModule = require("./submodules/zudello/tax/Rate");
|
|
20
|
+
const TaxSolutionModule = require("./submodules/zudello/tax/Solution");
|
|
21
|
+
const ItemModule = require("./submodules/zudello/Item");
|
|
22
|
+
const ItemCategoryModule = require("./submodules/zudello/ItemCategory");
|
|
23
|
+
const ItemGroupModule = require("./submodules/zudello/ItemGroup");
|
|
24
|
+
const PurchaseOrderModule = require("./submodules/zudello/PurchaseOrder");
|
|
25
|
+
const PaymentTermModule = require("./submodules/zudello/PaymentTerm");
|
|
26
|
+
const PaymentMethodModule = require("./submodules/zudello/PaymentMethod");
|
|
27
|
+
const ProjectModule = require("./submodules/zudello/Project");
|
|
28
|
+
const ProjectGroupModule = require("./submodules/zudello/ProjectGroup");
|
|
29
|
+
const ProjectTaskModule = require("./submodules/zudello/ProjectTask");
|
|
30
|
+
const SupplierCategoryModule = require("./submodules/zudello/SupplierCategory");
|
|
31
|
+
const SupplierGroupModule = require("./submodules/zudello/SupplierGroup");
|
|
32
|
+
const UomModule = require("./submodules/zudello/Uom");
|
|
33
|
+
const WarehouseModule = require("./submodules/zudello/Warehouse");
|
|
34
|
+
const ZoneModule = require("./submodules/zudello/Zone");
|
|
35
|
+
const SupplierModule = require("./submodules/zudello/Supplier");
|
|
36
|
+
const FixedAssetModule = require("./submodules/zudello/FixedAsset");
|
|
37
|
+
const UniversalModule = require("./submodules/zudello/Universal");
|
|
38
38
|
|
|
39
39
|
class ZudelloSDK extends BaseSDK {
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Constructor.
|
|
42
|
+
* @param {class} auth Auth class object with authorized api instance.
|
|
43
|
+
* @param {string} connectionUUID The UUID of the Connection we're working on.
|
|
44
|
+
*/
|
|
45
|
+
constructor(auth, organizationUUID, apiURL, apiVersion, loggerClass = null) {
|
|
46
|
+
super({
|
|
47
|
+
auth,
|
|
48
|
+
organizationUUID,
|
|
49
|
+
apiURL,
|
|
50
|
+
apiVersion,
|
|
51
|
+
isExternal: false,
|
|
52
|
+
integrationName: "Zudello",
|
|
53
|
+
loggerClass,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
this.staticFieldsForUpdate = {
|
|
57
|
+
enrich: false,
|
|
58
|
+
extractedEvent: false,
|
|
59
|
+
update: true,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create submodule instances.
|
|
64
|
+
*/
|
|
65
|
+
this.account = new AccountModule(this);
|
|
66
|
+
this.accountGroup = new AccountGroupModule(this);
|
|
67
|
+
this.accountingPeriod = new AccountingPeriodModule(this);
|
|
68
|
+
this.costCentre = new CostCentreModule(this);
|
|
69
|
+
this.costType = new CostTypeModule(this);
|
|
70
|
+
this.customer = new CustomerModule(this);
|
|
71
|
+
this.customerCategory = new CustomerCategoryModule(this);
|
|
72
|
+
this.customerGroup = new CustomerGroupModule(this);
|
|
73
|
+
this.currency = new CurrencyModule(this);
|
|
74
|
+
this.department = new DepartmentModule(this);
|
|
75
|
+
this.employee = new EmployeeModule(this);
|
|
76
|
+
this.subsidiary = new SubsidiaryModule(this);
|
|
77
|
+
this.location = new LocationModule(this);
|
|
78
|
+
this.item = new ItemModule(this);
|
|
79
|
+
this.itemCategory = new ItemCategoryModule(this);
|
|
80
|
+
this.itemGroup = new ItemGroupModule(this);
|
|
81
|
+
this.purchaseOrder = new PurchaseOrderModule(this);
|
|
82
|
+
this.paymentTerm = new PaymentTermModule(this);
|
|
83
|
+
this.paymentMethod = new PaymentMethodModule(this);
|
|
84
|
+
this.project = new ProjectModule(this);
|
|
85
|
+
this.projectGroup = new ProjectGroupModule(this);
|
|
86
|
+
this.projectTask = new ProjectTaskModule(this);
|
|
87
|
+
this.supplierCategory = new SupplierCategoryModule(this);
|
|
88
|
+
this.supplierGroup = new SupplierGroupModule(this);
|
|
89
|
+
this.warehouse = new WarehouseModule(this);
|
|
90
|
+
this.uom = new UomModule(this);
|
|
91
|
+
this.zone = new ZoneModule(this);
|
|
92
|
+
this.supplier = new SupplierModule(this);
|
|
93
|
+
this.fixedAsset = new FixedAssetModule(this);
|
|
94
|
+
this.universal = new UniversalModule(this);
|
|
95
|
+
this.tax = {
|
|
96
|
+
rate: new TaxRateModule(this),
|
|
97
|
+
solution: new TaxSolutionModule(this),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async search({ model, select, filter, orderBy = ["-created_at"], offset = 0, limit = 100 }) {
|
|
102
|
+
const validateIsEmpty = this.validator.isEmpty({ model, select, filter });
|
|
103
|
+
|
|
104
|
+
if (!validateIsEmpty.valid) {
|
|
105
|
+
return this.responseHandler.error(validateIsEmpty.errors);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return await this.makeRequest(
|
|
109
|
+
"POST",
|
|
110
|
+
`${this.apiURL}/team-data/${this.apiVersion}/resources/search`,
|
|
111
|
+
{
|
|
112
|
+
model,
|
|
113
|
+
offset,
|
|
114
|
+
limit,
|
|
115
|
+
select,
|
|
116
|
+
order_by: orderBy,
|
|
117
|
+
filter,
|
|
118
|
+
exclude: {},
|
|
119
|
+
annotate: {},
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async fetch({ model, uuid, fetchDetails = true, simplified = true }) {
|
|
125
|
+
const validateIsEmpty = this.validator.isEmpty({ model, uuid });
|
|
126
|
+
|
|
127
|
+
if (!validateIsEmpty.valid) {
|
|
128
|
+
return this.responseHandler.error(validateIsEmpty.errors);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return await this.makeRequest("GET", `${this.apiURL}/team-data/${this.apiVersion}/resources`, {
|
|
132
|
+
model,
|
|
133
|
+
uuid,
|
|
134
|
+
fetch_details: fetchDetails,
|
|
135
|
+
simplified,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async getFileAttachment({ uuid, type }) {
|
|
140
|
+
const validateIsEmpty = this.validator.isEmpty({ uuid, type });
|
|
141
|
+
|
|
142
|
+
if (!validateIsEmpty.valid) {
|
|
143
|
+
return this.responseHandler.error(validateIsEmpty.errors);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return await this.makeRequest(
|
|
147
|
+
"GET",
|
|
148
|
+
`${this.apiURL}/team-data/${this.apiVersion}/files/download/Transaction/${uuid}/${type}`,
|
|
149
|
+
{},
|
|
150
|
+
{},
|
|
151
|
+
true
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async update({
|
|
156
|
+
model,
|
|
157
|
+
module = null,
|
|
158
|
+
submodule = null,
|
|
159
|
+
data,
|
|
160
|
+
clearNulls = true,
|
|
161
|
+
simplified = false,
|
|
162
|
+
submit = false,
|
|
163
|
+
updateStatus = false,
|
|
164
|
+
}) {
|
|
165
|
+
const validateIsEmpty = this.validator.isEmpty({ model, data });
|
|
166
|
+
|
|
167
|
+
if (!validateIsEmpty.valid) {
|
|
168
|
+
return this.responseHandler.error(validateIsEmpty.errors);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
data = this.mapUpdateOrCreateData({
|
|
172
|
+
data: [data],
|
|
173
|
+
staticFields: {
|
|
174
|
+
...this.staticFieldsForUpdate,
|
|
175
|
+
model,
|
|
176
|
+
module,
|
|
177
|
+
submodule,
|
|
178
|
+
},
|
|
179
|
+
submit,
|
|
180
|
+
updateStatus,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return await this.updateOrCreate({ data, clearNulls, simplified });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async updateOrCreate({ data, clearNulls = true, simplified = false }) {
|
|
187
|
+
const validateIsEmpty = this.validator.isEmpty({ data });
|
|
188
|
+
|
|
189
|
+
if (!validateIsEmpty.valid) {
|
|
190
|
+
return this.responseHandler.error(validateIsEmpty.errors);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return await this.makeRequest(
|
|
194
|
+
"POST",
|
|
195
|
+
`${this.apiURL}/team-data/${this.apiVersion}/resources/update_or_create`,
|
|
196
|
+
{
|
|
197
|
+
simplified,
|
|
198
|
+
clear_nulls: clearNulls,
|
|
199
|
+
data,
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
mapUpdateOrCreateData({ data = [], staticFields = {}, submit = false, updateStatus = false }) {
|
|
205
|
+
return _.map(data, (item) => {
|
|
206
|
+
return {
|
|
207
|
+
data: {
|
|
208
|
+
module: staticFields.module,
|
|
209
|
+
submodule: staticFields.submodule,
|
|
210
|
+
document_type: staticFields.documentType,
|
|
211
|
+
...item,
|
|
212
|
+
},
|
|
213
|
+
model: staticFields.model,
|
|
214
|
+
submit: submit,
|
|
215
|
+
enrich: staticFields.enrich,
|
|
216
|
+
extracted_event: staticFields.extractedEvent,
|
|
217
|
+
update_status: updateStatus,
|
|
218
|
+
update: staticFields.update,
|
|
219
|
+
create: staticFields.create,
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
204
223
|
}
|
|
205
224
|
|
|
206
|
-
module.exports = ZudelloSDK
|
|
225
|
+
module.exports = ZudelloSDK;
|
|
@@ -1,109 +1,142 @@
|
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Constructor.
|
|
6
|
+
* @param {class} parentModule Object of MYOBAccumatica 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
|
+
"GET",
|
|
29
|
+
`${this.module.apiURL}/zintegrations/action/5f752f97-03f9-4893-8245-7d03cf217e37`,
|
|
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: $top, $skip, $filter, $extend.
|
|
56
|
+
* @returns {object} Universal List Response.
|
|
57
|
+
*/
|
|
58
|
+
async list({ url, method, qs = {} }) {
|
|
59
|
+
const validateIsEmpty = this.module.validator.isEmpty({ url, method });
|
|
60
|
+
|
|
61
|
+
if (!validateIsEmpty.valid) {
|
|
62
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!qs.$skip) {
|
|
66
|
+
qs.$skip = 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!qs.$top) {
|
|
70
|
+
qs.$top = 100;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return await this.request({ url, method, qs });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Universal Auto Pagination Listing By URL and Method.
|
|
78
|
+
* @param {string} url URL of listed data.
|
|
79
|
+
* @param {string} method Method of listed data.
|
|
80
|
+
* @param {object} qs Some available filters inside: $top, $skip, $filter, $extend.
|
|
81
|
+
* @returns {object} Auto Pagination responses.
|
|
82
|
+
*/
|
|
83
|
+
async *autoPaginationList({ url, method, qs = {} }) {
|
|
84
|
+
if (!qs.$skip) {
|
|
85
|
+
qs.$skip = 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!qs.$top) {
|
|
89
|
+
qs.$top = 100;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let response = await this.list({ url, method, qs });
|
|
93
|
+
let currentPageCount = response?.data?.length;
|
|
94
|
+
let currentOffset = qs.$skip;
|
|
95
|
+
|
|
96
|
+
yield response;
|
|
97
|
+
|
|
98
|
+
if (currentPageCount && currentPageCount === qs.$top) {
|
|
99
|
+
while (currentPageCount === qs.$top) {
|
|
100
|
+
currentOffset = currentOffset + qs.$top;
|
|
101
|
+
|
|
102
|
+
qs.$skip = currentOffset;
|
|
103
|
+
|
|
104
|
+
response = await this.list({ url, method, qs });
|
|
105
|
+
currentPageCount = response?.data?.length;
|
|
106
|
+
|
|
107
|
+
yield response;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Attachment Request By URL and Method.
|
|
114
|
+
* @param {string} url URL of request.
|
|
115
|
+
* @param {string} attachment URL of the attachment.
|
|
116
|
+
* @returns {object} Universal Request Response.
|
|
117
|
+
*/
|
|
118
|
+
async attach({ url, method, qs = {}, body = {} }) {
|
|
119
|
+
const validateIsEmpty = this.module.validator.isEmpty({ url, attachment });
|
|
120
|
+
|
|
121
|
+
if (!validateIsEmpty.valid) {
|
|
122
|
+
return this.module.responseHandler.error(validateIsEmpty.errors);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return await this.module.makeRequest(
|
|
126
|
+
"GET",
|
|
127
|
+
`${this.module.apiURL}/zintegrations/action/086840ce-942c-44ee-b2dd-ca66e5dd7b02`,
|
|
128
|
+
{
|
|
129
|
+
mappable_parameters: {
|
|
130
|
+
url: {
|
|
131
|
+
value: url,
|
|
132
|
+
},
|
|
133
|
+
attachment: {
|
|
134
|
+
value: attachment,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
107
140
|
}
|
|
108
141
|
|
|
109
|
-
module.exports = UniversalModule
|
|
142
|
+
module.exports = UniversalModule;
|