zudello-integration-sdk 1.0.0
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/README.md +1 -0
- package/package.json +23 -0
- package/src/index.js +62 -0
- package/src/integrations/samples/bc-zudello/account.js +40 -0
- package/src/integrations/samples/bc-zudello/accountingPeriod.js +52 -0
- package/src/integrations/samples/bc-zudello/currency.js +42 -0
- package/src/integrations/samples/bc-zudello/customer.js +45 -0
- package/src/integrations/samples/bc-zudello/dimension.js +85 -0
- package/src/integrations/samples/bc-zudello/employee.js +38 -0
- package/src/integrations/samples/bc-zudello/fixedAsset.js +48 -0
- package/src/integrations/samples/bc-zudello/item.js +45 -0
- package/src/integrations/samples/bc-zudello/itemCategory.js +37 -0
- package/src/integrations/samples/bc-zudello/location.js +37 -0
- package/src/integrations/samples/bc-zudello/paymentMethod.js +38 -0
- package/src/integrations/samples/bc-zudello/paymentTerm.js +41 -0
- package/src/integrations/samples/bc-zudello/project.js +38 -0
- package/src/integrations/samples/bc-zudello/purchaseCredit.js +109 -0
- package/src/integrations/samples/bc-zudello/purchaseInvoice.js +138 -0
- package/src/integrations/samples/bc-zudello/purchaseOrder.js +150 -0
- package/src/integrations/samples/bc-zudello/purchaseOrderFetch.js +100 -0
- package/src/integrations/samples/bc-zudello/supplier.js +40 -0
- package/src/integrations/samples/bc-zudello/taxRate.js +39 -0
- package/src/integrations/samples/bc-zudello/uom.js +42 -0
- package/src/integrations/samples/dear-zudello/account.js +20 -0
- package/src/integrations/samples/dear-zudello/customer.js +23 -0
- package/src/integrations/samples/dear-zudello/item.js +30 -0
- package/src/integrations/samples/dear-zudello/location.js +19 -0
- package/src/integrations/samples/dear-zudello/salesOrder.js +126 -0
- package/src/integrations/samples/dear-zudello/supplier.js +23 -0
- package/src/integrations/samples/dear-zudello/taxRate.js +19 -0
- package/src/integrations/samples/fo-zudello/account.js +20 -0
- package/src/integrations/samples/fo-zudello/costCentre.js +20 -0
- package/src/integrations/samples/fo-zudello/department.js +20 -0
- package/src/integrations/samples/fo-zudello/item.js +21 -0
- package/src/integrations/samples/fo-zudello/location.js +20 -0
- package/src/integrations/samples/fo-zudello/project.js +18 -0
- package/src/integrations/samples/fo-zudello/subsidiary.js +20 -0
- package/src/integrations/samples/fo-zudello/supplier.js +23 -0
- package/src/integrations/samples/fo-zudello/taxRate.js +20 -0
- package/src/integrations/samples/intacct-zudello/account.js +56 -0
- package/src/integrations/samples/intacct-zudello/accountGroup.js +54 -0
- package/src/integrations/samples/intacct-zudello/accountingPeriod.js +67 -0
- package/src/integrations/samples/intacct-zudello/apBill.js +146 -0
- package/src/integrations/samples/intacct-zudello/apBillFetch.js +195 -0
- package/src/integrations/samples/intacct-zudello/costCentre.js +54 -0
- package/src/integrations/samples/intacct-zudello/costType.js +54 -0
- package/src/integrations/samples/intacct-zudello/customerCategory.js +54 -0
- package/src/integrations/samples/intacct-zudello/customerGroup.js +54 -0
- package/src/integrations/samples/intacct-zudello/department.js +54 -0
- package/src/integrations/samples/intacct-zudello/employee.js +51 -0
- package/src/integrations/samples/intacct-zudello/expense-create.js +156 -0
- package/src/integrations/samples/intacct-zudello/item.js +64 -0
- package/src/integrations/samples/intacct-zudello/itemCategory.js +54 -0
- package/src/integrations/samples/intacct-zudello/itemGroup.js +54 -0
- package/src/integrations/samples/intacct-zudello/location.js +54 -0
- package/src/integrations/samples/intacct-zudello/paymentTerm.js +56 -0
- package/src/integrations/samples/intacct-zudello/project.js +54 -0
- package/src/integrations/samples/intacct-zudello/projectGroup.js +54 -0
- package/src/integrations/samples/intacct-zudello/projectTask.js +40 -0
- package/src/integrations/samples/intacct-zudello/subsidiary.js +54 -0
- package/src/integrations/samples/intacct-zudello/supplier.js +168 -0
- package/src/integrations/samples/intacct-zudello/supplierCategory.js +54 -0
- package/src/integrations/samples/intacct-zudello/supplierGroup.js +54 -0
- package/src/integrations/samples/intacct-zudello/supplierV2.js +64 -0
- package/src/integrations/samples/intacct-zudello/taxRate.js +34 -0
- package/src/integrations/samples/intacct-zudello/taxSolution.js +35 -0
- package/src/integrations/samples/intacct-zudello/uom.js +37 -0
- package/src/integrations/samples/intacct-zudello/warehouse.js +54 -0
- package/src/integrations/samples/intacct-zudello/zone.js +54 -0
- package/src/integrations/samples/nexvia-zudello/account.js +20 -0
- package/src/integrations/samples/nexvia-zudello/costCentre.js +19 -0
- package/src/integrations/samples/nexvia-zudello/costType.js +19 -0
- package/src/integrations/samples/nexvia-zudello/currency.js +20 -0
- package/src/integrations/samples/nexvia-zudello/department.js +20 -0
- package/src/integrations/samples/nexvia-zudello/itemCategory.js +19 -0
- package/src/integrations/samples/nexvia-zudello/location.js +20 -0
- package/src/integrations/samples/nexvia-zudello/project.js +20 -0
- package/src/integrations/samples/nexvia-zudello/supplier.js +21 -0
- package/src/integrations/samples/nexvia-zudello/taxRate.js +21 -0
- package/src/integrations/samples/nexvia-zudello/uom.js +19 -0
- package/src/integrations/samples/nexvia-zudello/zone.js +20 -0
- package/src/integrations/samples/zenoti-zudello/location.js +20 -0
- package/src/integrations/samples/zenoti-zudello/product.js +32 -0
- package/src/integrations/samples/zenoti-zudello/purchaseOrder.js +193 -0
- package/src/sdk/Auth.js +42 -0
- package/src/sdk/Base.js +118 -0
- package/src/sdk/BusinessCentral.js +31 -0
- package/src/sdk/Dear.js +31 -0
- package/src/sdk/Fo.js +31 -0
- package/src/sdk/Intacct.js +103 -0
- package/src/sdk/JobReady.js +31 -0
- package/src/sdk/MYOBAcumatica.js +33 -0
- package/src/sdk/Netsuite.js +31 -0
- package/src/sdk/NetsuiteSOAP.js +92 -0
- package/src/sdk/Nexvia.js +31 -0
- package/src/sdk/RetailExpress.js +31 -0
- package/src/sdk/Sybiz.js +31 -0
- package/src/sdk/Zenoti.js +31 -0
- package/src/sdk/Zudello.js +206 -0
- package/src/sdk/submodules/bc/Universal.js +109 -0
- package/src/sdk/submodules/dear/Universal.js +110 -0
- package/src/sdk/submodules/fo/Universal.js +111 -0
- package/src/sdk/submodules/intacct/Account.js +31 -0
- package/src/sdk/submodules/intacct/AccountGroup.js +31 -0
- package/src/sdk/submodules/intacct/AccountingPeriod.js +31 -0
- package/src/sdk/submodules/intacct/ApAdjustment.js +35 -0
- package/src/sdk/submodules/intacct/ApBill.js +52 -0
- package/src/sdk/submodules/intacct/ApTerm.js +31 -0
- package/src/sdk/submodules/intacct/ArAdjustment.js +35 -0
- package/src/sdk/submodules/intacct/ArInvoice.js +35 -0
- package/src/sdk/submodules/intacct/ArTerm.js +31 -0
- package/src/sdk/submodules/intacct/Budget.js +31 -0
- package/src/sdk/submodules/intacct/Class.js +31 -0
- package/src/sdk/submodules/intacct/CostType.js +31 -0
- package/src/sdk/submodules/intacct/Customer.js +31 -0
- package/src/sdk/submodules/intacct/CustomerGroup.js +31 -0
- package/src/sdk/submodules/intacct/CustomerType.js +31 -0
- package/src/sdk/submodules/intacct/Department.js +31 -0
- package/src/sdk/submodules/intacct/Employee.js +31 -0
- package/src/sdk/submodules/intacct/Entity.js +31 -0
- package/src/sdk/submodules/intacct/File.js +26 -0
- package/src/sdk/submodules/intacct/Item.js +31 -0
- package/src/sdk/submodules/intacct/ItemGroup.js +31 -0
- package/src/sdk/submodules/intacct/Location.js +31 -0
- package/src/sdk/submodules/intacct/PoDocument.js +52 -0
- package/src/sdk/submodules/intacct/ProductLine.js +31 -0
- package/src/sdk/submodules/intacct/Project.js +31 -0
- package/src/sdk/submodules/intacct/ProjectGroup.js +31 -0
- package/src/sdk/submodules/intacct/Task.js +31 -0
- package/src/sdk/submodules/intacct/TaxDetail.js +31 -0
- package/src/sdk/submodules/intacct/TaxGroups.js +31 -0
- package/src/sdk/submodules/intacct/TaxSolution.js +31 -0
- package/src/sdk/submodules/intacct/Universal.js +139 -0
- package/src/sdk/submodules/intacct/Uom.js +31 -0
- package/src/sdk/submodules/intacct/Vendor.js +31 -0
- package/src/sdk/submodules/intacct/VendorGroup.js +31 -0
- package/src/sdk/submodules/intacct/VendorTypes.js +31 -0
- package/src/sdk/submodules/intacct/Warehouse.js +31 -0
- package/src/sdk/submodules/intacct/Zone.js +31 -0
- package/src/sdk/submodules/intacct/apAdjustment/Item.js +31 -0
- package/src/sdk/submodules/intacct/apBill/Item.js +31 -0
- package/src/sdk/submodules/intacct/arAdjustment/Item.js +31 -0
- package/src/sdk/submodules/intacct/arInvoice/Item.js +31 -0
- package/src/sdk/submodules/intacct/poDocument/Item.js +31 -0
- package/src/sdk/submodules/jobready/Universal.js +107 -0
- package/src/sdk/submodules/myobAcumatica/OData.js +109 -0
- package/src/sdk/submodules/myobAcumatica/Universal.js +109 -0
- package/src/sdk/submodules/netsuite/Universal.js +97 -0
- package/src/sdk/submodules/netsuite-soap/PurchaseOrder.js +39 -0
- package/src/sdk/submodules/netsuite-soap/Receipt.js +39 -0
- package/src/sdk/submodules/netsuite-soap/Universal.js +124 -0
- package/src/sdk/submodules/netsuite-soap/UniversalTransaction.js +138 -0
- package/src/sdk/submodules/netsuite-soap/VendorBill.js +41 -0
- package/src/sdk/submodules/netsuite-soap/VendorCredit.js +39 -0
- package/src/sdk/submodules/nexvia/Universal.js +108 -0
- package/src/sdk/submodules/retailExpress/Universal.js +107 -0
- package/src/sdk/submodules/sybiz/Universal.js +108 -0
- package/src/sdk/submodules/zenoti/Universal.js +110 -0
- package/src/sdk/submodules/zudello/Account.js +63 -0
- package/src/sdk/submodules/zudello/AccountGroup.js +63 -0
- package/src/sdk/submodules/zudello/AccountingPeriod.js +63 -0
- package/src/sdk/submodules/zudello/CostCentre.js +63 -0
- package/src/sdk/submodules/zudello/CostType.js +63 -0
- package/src/sdk/submodules/zudello/Currency.js +63 -0
- package/src/sdk/submodules/zudello/Customer.js +63 -0
- package/src/sdk/submodules/zudello/CustomerCategory.js +63 -0
- package/src/sdk/submodules/zudello/CustomerGroup.js +63 -0
- package/src/sdk/submodules/zudello/Department.js +63 -0
- package/src/sdk/submodules/zudello/Employee.js +63 -0
- package/src/sdk/submodules/zudello/FixedAsset.js +63 -0
- package/src/sdk/submodules/zudello/Item.js +63 -0
- package/src/sdk/submodules/zudello/ItemCategory.js +63 -0
- package/src/sdk/submodules/zudello/ItemGroup.js +63 -0
- package/src/sdk/submodules/zudello/Location.js +63 -0
- package/src/sdk/submodules/zudello/PaymentMethod.js +63 -0
- package/src/sdk/submodules/zudello/PaymentTerm.js +63 -0
- package/src/sdk/submodules/zudello/Project.js +63 -0
- package/src/sdk/submodules/zudello/ProjectGroup.js +63 -0
- package/src/sdk/submodules/zudello/ProjectTask.js +63 -0
- package/src/sdk/submodules/zudello/PurchaseOrder.js +63 -0
- package/src/sdk/submodules/zudello/Subsidiary.js +63 -0
- package/src/sdk/submodules/zudello/Supplier.js +63 -0
- package/src/sdk/submodules/zudello/SupplierCategory.js +63 -0
- package/src/sdk/submodules/zudello/SupplierGroup.js +63 -0
- package/src/sdk/submodules/zudello/Universal.js +31 -0
- package/src/sdk/submodules/zudello/Uom.js +63 -0
- package/src/sdk/submodules/zudello/Warehouse.js +63 -0
- package/src/sdk/submodules/zudello/Zone.js +63 -0
- package/src/sdk/submodules/zudello/tax/Rate.js +63 -0
- package/src/sdk/submodules/zudello/tax/Solution.js +63 -0
- package/src/utils/apiInstance.js +198 -0
- package/src/utils/config.js +18 -0
- package/src/utils/logger.js +122 -0
- package/src/utils/metadata.js +102 -0
- package/src/utils/miscHelper.js +24 -0
- package/src/utils/modelHelper.js +140 -0
- package/src/utils/properties.js +32 -0
- package/src/utils/responseHandler.js +28 -0
- package/src/utils/s3Client.js +128 -0
- package/src/utils/tags.js +32 -0
- package/src/utils/validator.js +73 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
class Logger {
|
|
4
|
+
/**
|
|
5
|
+
* Constructor.
|
|
6
|
+
*/
|
|
7
|
+
constructor(mode = 'PRODUCTION') {
|
|
8
|
+
this.mode = mode
|
|
9
|
+
this.productionMode = 'PRODUCTION'
|
|
10
|
+
this.logs = []
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base logging function.
|
|
15
|
+
* @param {string} status - The status level of the log (e.g., 'warn', 'info').
|
|
16
|
+
* @param {string} title - The title or summary of the log.
|
|
17
|
+
* @param {any} content - The detailed content of the log.
|
|
18
|
+
*/
|
|
19
|
+
_log(status, title, content) {
|
|
20
|
+
let formattedContent = content
|
|
21
|
+
|
|
22
|
+
// If content is an Error (exception), format it into an object
|
|
23
|
+
if (content instanceof Error) {
|
|
24
|
+
formattedContent = {
|
|
25
|
+
name: content.name,
|
|
26
|
+
message: content.message,
|
|
27
|
+
stack: content.stack,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Create the log entry object
|
|
32
|
+
const logEntry = { status, title, content: formattedContent }
|
|
33
|
+
|
|
34
|
+
if (this.mode === this.productionMode) {
|
|
35
|
+
this.logs.push(logEntry)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Output the log message
|
|
39
|
+
if (content instanceof Error) {
|
|
40
|
+
console.log(`[${status.toUpperCase()}] ${title}:`)
|
|
41
|
+
console.error(content.stack)
|
|
42
|
+
} else if (Array.isArray(content) || (typeof content === 'object' && content !== null)) {
|
|
43
|
+
console.log(`[${status.toUpperCase()}] ${title}:`)
|
|
44
|
+
console.log(JSON.stringify(content, null, 2))
|
|
45
|
+
} else {
|
|
46
|
+
console.log(`[${status.toUpperCase()}] ${title}: ${content}`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Log a warning message.
|
|
52
|
+
* @param {string} title
|
|
53
|
+
* @param {any} content
|
|
54
|
+
*/
|
|
55
|
+
warn(title, content) {
|
|
56
|
+
this._log('warn', title, content)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Log an informational message.
|
|
61
|
+
* @param {string} title
|
|
62
|
+
* @param {any} content
|
|
63
|
+
*/
|
|
64
|
+
info(title, content) {
|
|
65
|
+
this._log('info', title, content)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Log a debug message.
|
|
70
|
+
* @param {string} title
|
|
71
|
+
* @param {any} content
|
|
72
|
+
*/
|
|
73
|
+
debug(title, content) {
|
|
74
|
+
this._log('debug', title, content)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Log a general message.
|
|
79
|
+
* @param {string} title
|
|
80
|
+
* @param {any} content
|
|
81
|
+
*/
|
|
82
|
+
log(content, title = 'Script Log') {
|
|
83
|
+
this._log('log', title, content)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Log an error message.
|
|
88
|
+
* @param {string} title
|
|
89
|
+
* @param {any} content
|
|
90
|
+
*/
|
|
91
|
+
error(title, content) {
|
|
92
|
+
this._log('error', title, content)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Log a success message.
|
|
97
|
+
* @param {string} title
|
|
98
|
+
* @param {any} content
|
|
99
|
+
*/
|
|
100
|
+
success(title, content) {
|
|
101
|
+
this._log('success', title, content)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Log a request message.
|
|
106
|
+
* @param {string} title
|
|
107
|
+
* @param {any} content
|
|
108
|
+
*/
|
|
109
|
+
request(title, content) {
|
|
110
|
+
this._log('request', title, content)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Retrieve all logs.
|
|
115
|
+
* @return {Array} Array of log objects.
|
|
116
|
+
*/
|
|
117
|
+
getLogs() {
|
|
118
|
+
return this.logs
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = Logger
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Metadata class to handle operations on metadata and global metadata.
|
|
5
|
+
* This class provides methods to get, set, and delete metadata properties.
|
|
6
|
+
*/
|
|
7
|
+
class Metadata {
|
|
8
|
+
/**
|
|
9
|
+
* Constructor to initialize the Metadata instance.
|
|
10
|
+
*
|
|
11
|
+
* @param {Array} metadata - Array of metadata objects (each object should have `property` and `value`).
|
|
12
|
+
* @param {Array} globalMetadata - Array of global metadata objects (each object should have `property` and `value`).
|
|
13
|
+
*/
|
|
14
|
+
constructor(metadata = [], globalMetadata = []) {
|
|
15
|
+
this.metadata = metadata
|
|
16
|
+
this.globalMetadata = globalMetadata
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the value associated with the specified key.
|
|
21
|
+
*
|
|
22
|
+
* The method first checks the instance's metadata for the key.
|
|
23
|
+
* If not found, it checks the global metadata.
|
|
24
|
+
* If the key is not found in either, it returns the specified default value.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} key - The property key to search for.
|
|
27
|
+
* @param {*} defaultValue - The default value to return if the key is not found (default is `null`).
|
|
28
|
+
* @returns {*} The value associated with the key, or the default value if not found.
|
|
29
|
+
*/
|
|
30
|
+
get(key, defaultValue = null) {
|
|
31
|
+
const item = this.metadata.find(obj => obj.property === key)
|
|
32
|
+
|
|
33
|
+
if (item) {
|
|
34
|
+
return item.value
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const globalItem = this.globalMetadata.find(obj => obj.property === key)
|
|
38
|
+
|
|
39
|
+
if (globalItem) {
|
|
40
|
+
return globalItem.value
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return defaultValue
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves all metadata and global metadata.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Object} An object containing both metadata and globalMetadata arrays.
|
|
50
|
+
*/
|
|
51
|
+
getAll() {
|
|
52
|
+
return {
|
|
53
|
+
metadata: this.metadata,
|
|
54
|
+
globalMetadata: this.globalMetadata
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sets the value for a specified key in either metadata or global metadata.
|
|
60
|
+
*
|
|
61
|
+
* If the key already exists, it updates the value. Otherwise, it adds a new key-value pair.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} key - The property key to set or update.
|
|
64
|
+
* @param {*} value - The value to associate with the key.
|
|
65
|
+
* @param {boolean} isGlobal - Flag indicating whether to set the key in global metadata (default is `false`).
|
|
66
|
+
*/
|
|
67
|
+
set(key, value, isGlobal = false) {
|
|
68
|
+
const index = isGlobal
|
|
69
|
+
? this.globalMetadata.findIndex(obj => obj.property === key)
|
|
70
|
+
: this.metadata.findIndex(obj => obj.property === key)
|
|
71
|
+
|
|
72
|
+
if (isGlobal) {
|
|
73
|
+
if (index !== -1) {
|
|
74
|
+
this.globalMetadata[index].value = value
|
|
75
|
+
} else {
|
|
76
|
+
this.globalMetadata.push({ property: key, value })
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
if (index !== -1) {
|
|
80
|
+
this.metadata[index].value = value
|
|
81
|
+
} else {
|
|
82
|
+
this.metadata.push({ property: key, value })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Deletes a specified key from either metadata or global metadata.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} key - The property key to delete.
|
|
91
|
+
* @param {boolean} isGlobal - Flag indicating whether to delete the key from global metadata (default is `false`).
|
|
92
|
+
*/
|
|
93
|
+
delete(key, isGlobal = false) {
|
|
94
|
+
if (isGlobal) {
|
|
95
|
+
this.globalMetadata = this.globalMetadata.filter(obj => obj.property !== key)
|
|
96
|
+
} else {
|
|
97
|
+
this.metadata = this.metadata.filter(obj => obj.property !== key)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = Metadata
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const moment = require('moment-timezone')
|
|
4
|
+
|
|
5
|
+
class MiscHelper {
|
|
6
|
+
constructor() {}
|
|
7
|
+
|
|
8
|
+
getFileNameFromUrl(url) {
|
|
9
|
+
const regex = /[^/?#]+(?=\?|$)/
|
|
10
|
+
const matches = url.match(regex)
|
|
11
|
+
|
|
12
|
+
return matches
|
|
13
|
+
? matches[0]
|
|
14
|
+
: null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
formatDate(date, format = 'MM/DD/YYYY') {
|
|
18
|
+
return date && format
|
|
19
|
+
? moment(date).format(format)
|
|
20
|
+
: null
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = MiscHelper
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash')
|
|
4
|
+
|
|
5
|
+
class ModelHelper {
|
|
6
|
+
constructor(zudello, logger, data = null, model = null, uuid = null) {
|
|
7
|
+
this.zudello = zudello
|
|
8
|
+
this.logger = logger
|
|
9
|
+
|
|
10
|
+
this.modelData = data
|
|
11
|
+
this.model = model
|
|
12
|
+
this.uuid = uuid
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async load(payload = {}, failCallback) {
|
|
16
|
+
failCallback = failCallback || ((data) => this.defaultFailCallback(data))
|
|
17
|
+
|
|
18
|
+
const model = payload?.model || null
|
|
19
|
+
const uuid = payload?.uuid || null
|
|
20
|
+
|
|
21
|
+
this.logger.info('payload', payload)
|
|
22
|
+
|
|
23
|
+
return await this.get(model, uuid, failCallback)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async get(model, uuid, failCallback) {
|
|
27
|
+
failCallback = failCallback || ((data) => this.defaultFailCallback(data))
|
|
28
|
+
|
|
29
|
+
if (!model || !uuid) {
|
|
30
|
+
return failCallback({ model, uuid })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.logger.info('model', model)
|
|
34
|
+
this.logger.info('uuid', uuid)
|
|
35
|
+
|
|
36
|
+
const fetchedModel = await this.zudello.fetch({ model, uuid })
|
|
37
|
+
|
|
38
|
+
this.logger.debug('Fetched Model', fetchedModel)
|
|
39
|
+
|
|
40
|
+
if (fetchedModel && fetchedModel.data) {
|
|
41
|
+
const data = fetchedModel.data?.data || null
|
|
42
|
+
|
|
43
|
+
if (data) {
|
|
44
|
+
return new ModelHelper(this.zudello, this.logger, data, model, uuid)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return failCallback({ model, uuid })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
data() {
|
|
52
|
+
return this.modelData
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lines(mapping = null, filter = null) {
|
|
56
|
+
const data = this.data()
|
|
57
|
+
|
|
58
|
+
if (!data) {
|
|
59
|
+
return []
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let lines = _.get(data, 'lines') ?? []
|
|
63
|
+
|
|
64
|
+
if (filter) {
|
|
65
|
+
lines = _.filter(lines, filter)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (mapping) {
|
|
69
|
+
lines = _.map(lines, mapping)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return lines
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async response({ status = 'COMPLETE', message = '', external_id = null, properties = {}, exit = false }) {
|
|
76
|
+
if (!this.modelData || !this.model || !this.uuid) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const responsePayload = {
|
|
81
|
+
model: this.model,
|
|
82
|
+
module: this.modelData.module,
|
|
83
|
+
submodule: this.modelData.submodule,
|
|
84
|
+
data: {
|
|
85
|
+
uuid: this.uuid,
|
|
86
|
+
status,
|
|
87
|
+
external_id,
|
|
88
|
+
...properties,
|
|
89
|
+
log_messages: message.length > 0 ? {
|
|
90
|
+
replace: true,
|
|
91
|
+
items: [{
|
|
92
|
+
create: true,
|
|
93
|
+
data: {
|
|
94
|
+
status_code: status === 'UNABLE' ? 400 : 200,
|
|
95
|
+
body: JSON.stringify({ message }),
|
|
96
|
+
parse_as: 'SENTENCE_ERROR'
|
|
97
|
+
}
|
|
98
|
+
}]
|
|
99
|
+
} : null
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.logger.debug('Response Payload', responsePayload)
|
|
104
|
+
|
|
105
|
+
const zudelloUpdateResponse = await this.zudello.update(responsePayload)
|
|
106
|
+
|
|
107
|
+
this.logger.debug('Zudello Update Response', zudelloUpdateResponse)
|
|
108
|
+
|
|
109
|
+
if (exit) {
|
|
110
|
+
throw new Error('Script Exit')
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async complete({ message = '', external_id = null, properties = {}, exit = false }) {
|
|
115
|
+
await this.response({ status: 'COMPLETE', message, external_id, properties, exit })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async fail({ message = '', external_id = null, properties = {}, exit = false }) {
|
|
119
|
+
await this.response({ status: 'UNABLE', message, external_id, properties, exit })
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async completeIf(condition, { message = '', external_id = null, properties = {}, exit = false }) {
|
|
123
|
+
if (condition) {
|
|
124
|
+
await this.complete({ message, external_id, properties, exit })
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async failIf(condition, { message = '', external_id = null, properties = {}, exit = false }) {
|
|
129
|
+
if (condition) {
|
|
130
|
+
await this.fail({ message, external_id, properties, exit })
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
defaultFailCallback(data) {
|
|
135
|
+
this.logger.error('Unable to find Model', data)
|
|
136
|
+
throw new Error('Unable to find Model')
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = ModelHelper
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A class representing a collection of properties.
|
|
5
|
+
*/
|
|
6
|
+
class Properties {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor for the Properties class.
|
|
9
|
+
* @param {Array} properties - An array of property objects. Each object is expected to have a `payload` property, which itself contains a `name` and `value`.
|
|
10
|
+
*/
|
|
11
|
+
constructor(properties = []) {
|
|
12
|
+
this.properties = properties
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve the value associated with a given key.
|
|
17
|
+
* @param {string} key - The name of the property to retrieve.
|
|
18
|
+
* @param {*} defaultValue - The value to return if the key is not found. Defaults to null.
|
|
19
|
+
* @returns {*} The value associated with the key, or the defaultValue if the key is not found.
|
|
20
|
+
*/
|
|
21
|
+
get(key, defaultValue = null) {
|
|
22
|
+
const item = this.properties.find(obj => obj.payload?.name === key)
|
|
23
|
+
|
|
24
|
+
if (item) {
|
|
25
|
+
return item.payload?.value?.value
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return defaultValue
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = Properties
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
class ResponseHandler {
|
|
4
|
+
/**
|
|
5
|
+
* Handle success response.
|
|
6
|
+
* @param {any} data Data to return.
|
|
7
|
+
* @returns {object} Response Data.
|
|
8
|
+
*/
|
|
9
|
+
success (data) {
|
|
10
|
+
return { success: true, data }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Handle error response.
|
|
15
|
+
* @param {array} errors Errors to return.
|
|
16
|
+
* @returns {object} Response Data.
|
|
17
|
+
*/
|
|
18
|
+
error (errors) {
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
error: {
|
|
22
|
+
messages: errors
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = ResponseHandler
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const {
|
|
2
|
+
S3Client,
|
|
3
|
+
GetObjectCommand,
|
|
4
|
+
PutObjectCommand,
|
|
5
|
+
ListObjectsV2Command,
|
|
6
|
+
DeleteObjectCommand,
|
|
7
|
+
DeleteObjectsCommand
|
|
8
|
+
} = require('@aws-sdk/client-s3')
|
|
9
|
+
|
|
10
|
+
const s3 = new S3Client({
|
|
11
|
+
credentials: {
|
|
12
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
13
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
14
|
+
},
|
|
15
|
+
region: process.env.AWS_REGION
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the content of a file from an S3 bucket.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
22
|
+
* @param {string} key - The key of the file to retrieve.
|
|
23
|
+
* @returns {Promise<Buffer>} A promise that resolves to the content of the file.
|
|
24
|
+
* @throws Will throw an error if the S3 getObject operation fails.
|
|
25
|
+
*/
|
|
26
|
+
const getFileContent = async (bucketName, key) => {
|
|
27
|
+
const params = {
|
|
28
|
+
Bucket: bucketName,
|
|
29
|
+
Key: key
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const data = await s3.send(new GetObjectCommand(params))
|
|
33
|
+
return data.Body.transformToString()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Uploads a file to an S3 bucket.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
40
|
+
* @param {string} key - The key of the file to upload.
|
|
41
|
+
* @param {Buffer|string} body - The content of the file to upload.
|
|
42
|
+
* @param {string|null} contentType - The Content Type.
|
|
43
|
+
* @returns {Promise<Object>} A promise that resolves to the data returned by S3.
|
|
44
|
+
* @throws Will throw an error if the S3 upload operation fails.
|
|
45
|
+
*/
|
|
46
|
+
const uploadFile = async (bucketName, key, body, contentType = null) => {
|
|
47
|
+
const params = {
|
|
48
|
+
Bucket: bucketName,
|
|
49
|
+
Key: key,
|
|
50
|
+
Body: body
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (contentType) {
|
|
54
|
+
params.ContentType = contentType
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return await s3.send(new PutObjectCommand(params))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Lists the files in an S3 bucket under a specific prefix.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
64
|
+
* @param {string} prefix - The prefix (directory path) to list files from.
|
|
65
|
+
* @param {string} continuationToken - Token for paginated results.
|
|
66
|
+
* @returns {Promise<Object>} A promise that resolves to an object containing file keys and pagination info.
|
|
67
|
+
* @throws Will throw an error if the S3 listObjectsV2 operation fails.
|
|
68
|
+
*/
|
|
69
|
+
const listFiles = async (bucketName, prefix = '', continuationToken = undefined) => {
|
|
70
|
+
const params = {
|
|
71
|
+
Bucket: bucketName,
|
|
72
|
+
Prefix: prefix,
|
|
73
|
+
ContinuationToken: continuationToken
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const data = await s3.send(new ListObjectsV2Command(params))
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
keys: data.Contents ? data.Contents.map((item) => item.Key) : [],
|
|
80
|
+
isTruncated: data.IsTruncated,
|
|
81
|
+
nextContinuationToken: data.NextContinuationToken
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Deletes a file from an S3 bucket.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
89
|
+
* @param {string} key - The key of the file to delete.
|
|
90
|
+
* @returns {Promise<Object>} A promise that resolves to the data returned by S3.
|
|
91
|
+
* @throws Will throw an error if the S3 deleteObject operation fails.
|
|
92
|
+
*/
|
|
93
|
+
const deleteFile = async (bucketName, key) => {
|
|
94
|
+
const params = {
|
|
95
|
+
Bucket: bucketName,
|
|
96
|
+
Key: key
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return await s3.send(new DeleteObjectCommand(params))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Deletes multiple files from an S3 bucket.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
106
|
+
* @param {string[]} keys - The keys of the files to delete.
|
|
107
|
+
* @returns {Promise<Object>} A promise that resolves to the data returned by S3.
|
|
108
|
+
* @throws Will throw an error if the S3 deleteObjects operation fails.
|
|
109
|
+
*/
|
|
110
|
+
const deleteFiles = async (bucketName, keys) => {
|
|
111
|
+
const params = {
|
|
112
|
+
Bucket: bucketName,
|
|
113
|
+
Delete: {
|
|
114
|
+
Objects: keys.map((key) => ({ Key: key })),
|
|
115
|
+
Quiet: true
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return await s3.send(new DeleteObjectsCommand(params))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = {
|
|
123
|
+
getFileContent,
|
|
124
|
+
uploadFile,
|
|
125
|
+
listFiles,
|
|
126
|
+
deleteFile,
|
|
127
|
+
deleteFiles
|
|
128
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a collection of tags.
|
|
5
|
+
*/
|
|
6
|
+
class Tags {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new Tags instance.
|
|
9
|
+
* @param {Array} tags - An optional array of initial tags.
|
|
10
|
+
*/
|
|
11
|
+
constructor(tags = []) {
|
|
12
|
+
this.tags = tags
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Add a new tag to the tags array.
|
|
17
|
+
* @param {string} tag - The tag to add.
|
|
18
|
+
*/
|
|
19
|
+
set(tag) {
|
|
20
|
+
this.tags.push(tag)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Retrieve all tags.
|
|
25
|
+
* @returns {Array} An array of all tags.
|
|
26
|
+
*/
|
|
27
|
+
getAll() {
|
|
28
|
+
return this.tags
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = Tags
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash')
|
|
4
|
+
|
|
5
|
+
class Validator {
|
|
6
|
+
/**
|
|
7
|
+
* Validate is some of object params are empty.
|
|
8
|
+
* @param {object} params Object with params.
|
|
9
|
+
* @returns {object} Validate result.
|
|
10
|
+
*/
|
|
11
|
+
isEmpty (params) {
|
|
12
|
+
const emptyParams = []
|
|
13
|
+
|
|
14
|
+
_.keys(params).forEach(key => {
|
|
15
|
+
const value = params[key]
|
|
16
|
+
|
|
17
|
+
if ((value == null || _.isEmpty(value)) && !_.isNumber(value) && !_.isBoolean(value)) {
|
|
18
|
+
emptyParams.push(key)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
if (emptyParams.length) {
|
|
23
|
+
return {
|
|
24
|
+
valid: false,
|
|
25
|
+
errors: _.map(emptyParams, param => {
|
|
26
|
+
return `The following param are missed or empty: ${param}.`
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { valid: true }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validate is parameter has type array.
|
|
36
|
+
* @param {array} param Parameter to validate.
|
|
37
|
+
* @param {string} paramName Name of parameter.
|
|
38
|
+
* @returns {object} Validate result.
|
|
39
|
+
*/
|
|
40
|
+
isArray (param, paramName = 'Param') {
|
|
41
|
+
const isArray = _.isArray(param)
|
|
42
|
+
|
|
43
|
+
if (!isArray) {
|
|
44
|
+
return {
|
|
45
|
+
valid: false,
|
|
46
|
+
errors: [`${paramName} must be an array.`]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { valid: true }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Validate is array or object includes value.
|
|
55
|
+
* @param {array|object} entities Array or Object with entities.
|
|
56
|
+
* @param {number|string} value What we are searching for.
|
|
57
|
+
* @returns {object} Validate result.
|
|
58
|
+
*/
|
|
59
|
+
includes (entities, value) {
|
|
60
|
+
const includes = _.includes(entities, value)
|
|
61
|
+
|
|
62
|
+
if (!includes) {
|
|
63
|
+
return {
|
|
64
|
+
valid: false,
|
|
65
|
+
errors: [`${value} is missed in allowed properties.`]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return { valid: true }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = Validator
|