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,20 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Nexvia.universal.autoPaginationList({ url: 'locations', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"code": _.get(item, "name"),
|
|
9
|
+
"name": _.get(item, "name"),
|
|
10
|
+
"status": "ACTIVE"
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
logger.log(data)
|
|
15
|
+
|
|
16
|
+
const result = await Zudello.location.updateOrCreate({ data })
|
|
17
|
+
|
|
18
|
+
logger.log(result)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Nexvia.universal.autoPaginationList({ url: 'jobs', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"code": _.get(item, "number"),
|
|
9
|
+
"name": _.get(item, "name"),
|
|
10
|
+
"status": (_.get(item, "statusId") == 1) ? "ACTIVE" : "INACTIVE"
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
logger.log(data)
|
|
15
|
+
|
|
16
|
+
const result = await Zudello.project.updateOrCreate({ data })
|
|
17
|
+
|
|
18
|
+
logger.log(result)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Nexvia.universal.autoPaginationList({ url: 'suppliers', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"legal_name": _.get(item, "name"),
|
|
9
|
+
"trading_name": _.get(item, "name"),
|
|
10
|
+
"tax_number": _.get(item, "taxNumber"),
|
|
11
|
+
"status": (!_.get(item, "disabled", false)) ? "ACTIVE" : "INACTIVE"
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
logger.log(data)
|
|
16
|
+
|
|
17
|
+
const result = await Zudello.supplier.updateOrCreate({ data })
|
|
18
|
+
|
|
19
|
+
logger.log(result)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Nexvia.universal.autoPaginationList({ url: 'tax-rates', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"code": _.get(item, "code"),
|
|
9
|
+
"name": _.get(item, "name"),
|
|
10
|
+
"rate": _.get(item, "rate"),
|
|
11
|
+
"status": (_.get(item, "status") == "active") ? "ACTIVE" : "INACTIVE"
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
logger.log(data)
|
|
16
|
+
|
|
17
|
+
const result = await Zudello.tax.rate.updateOrCreate({ data })
|
|
18
|
+
|
|
19
|
+
logger.log(result)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Nexvia.universal.autoPaginationList({ url: 'measures', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"name": _.get(item, "description"),
|
|
9
|
+
"status": (_.get(item, "active")) ? "ACTIVE" : "INACTIVE"
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
logger.log(data)
|
|
14
|
+
|
|
15
|
+
const result = await Zudello.uom.updateOrCreate({ data })
|
|
16
|
+
|
|
17
|
+
logger.log(result)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Nexvia.universal.autoPaginationList({ url: 'labour-types', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"code": _.get(item, "shortName"),
|
|
9
|
+
"name": _.get(item, "name"),
|
|
10
|
+
"status": (!_.get(item, "disabled", false)) ? "ACTIVE" : "INACTIVE"
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
logger.log(data)
|
|
15
|
+
|
|
16
|
+
const result = await Zudello.zone.updateOrCreate({ data })
|
|
17
|
+
|
|
18
|
+
logger.log(result)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const items of Zenoti.universal.autoPaginationList({ url: 'centers', method: 'GET' })) {
|
|
3
|
+
logger.log(items)
|
|
4
|
+
|
|
5
|
+
const data = _.map(items.data.centers, (item) => {
|
|
6
|
+
return {
|
|
7
|
+
"external_id": _.get(item, "id"),
|
|
8
|
+
"code": _.get(item, "code"),
|
|
9
|
+
"name": _.get(item, "display_name"),
|
|
10
|
+
"status": (_.get(item, "STATUS", "is_fbe_enabled")) ? "ACTIVE" : "INACTIVE"
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
logger.log(data)
|
|
15
|
+
|
|
16
|
+
const result = await Zudello.location.updateOrCreate({ data })
|
|
17
|
+
|
|
18
|
+
logger.log(result)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const centers of Zenoti.universal.autoPaginationList({ url: 'centers', method: 'GET' })) {
|
|
3
|
+
for (center of centers.data.centers) {
|
|
4
|
+
for await (const items of Zenoti.universal.autoPaginationList({
|
|
5
|
+
url: `centers/${center.id}/products`,
|
|
6
|
+
method: 'GET',
|
|
7
|
+
body: {
|
|
8
|
+
show_in_catalog: true,
|
|
9
|
+
expand: ["centers", "tags", "catalog_info", "preferences", "barcodes"]
|
|
10
|
+
}
|
|
11
|
+
})) {
|
|
12
|
+
logger.log(items)
|
|
13
|
+
|
|
14
|
+
const data = _.map(items.data.products, (item) => {
|
|
15
|
+
return {
|
|
16
|
+
"external_id": _.get(item, "code"),
|
|
17
|
+
"sku": _.get(item, "code"),
|
|
18
|
+
"description": _.get(item, "description"),
|
|
19
|
+
"short_description": _.get(item, "name"),
|
|
20
|
+
"status": "ACTIVE"
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
logger.log(data)
|
|
25
|
+
|
|
26
|
+
const result = await Zudello.item.updateOrCreate({ data })
|
|
27
|
+
|
|
28
|
+
logger.log(result)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const handler = async (providedData) => {
|
|
2
|
+
for await (const centers of Zenoti.universal.autoPaginationList({ url: 'centers', method: 'GET' })) {
|
|
3
|
+
for (center of centers.data.centers) {
|
|
4
|
+
logger.log(center.id)
|
|
5
|
+
|
|
6
|
+
for await (const items of Zenoti.universal.autoPaginationList({
|
|
7
|
+
url: 'inventory/purchase_orders',
|
|
8
|
+
method: 'GET',
|
|
9
|
+
qs: {
|
|
10
|
+
center_id: center.id,
|
|
11
|
+
start_date: moment().startOf('month').format('YYYY-MM-DD'),
|
|
12
|
+
end_date: moment().endOf('month').format('YYYY-MM-DD'),
|
|
13
|
+
show_delivery_details: true,
|
|
14
|
+
date_criteria: 1,
|
|
15
|
+
status: 2
|
|
16
|
+
}
|
|
17
|
+
})) {
|
|
18
|
+
logger.log(items)
|
|
19
|
+
|
|
20
|
+
const data = await Promise.all(_.map(items.data.orders, async (item) => {
|
|
21
|
+
logger.log(item)
|
|
22
|
+
|
|
23
|
+
const productCodes = _.flatten(
|
|
24
|
+
_.map(_.get(item, 'partials'), (partial, invoiceID) => {
|
|
25
|
+
return _.map(_.get(partial, 'line_items'), (lineItem, lineID) => {
|
|
26
|
+
return _.get(lineItem, 'product_code');
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const zudelloItems = await Zudello.search({
|
|
32
|
+
"model": "Item",
|
|
33
|
+
"offset": 0,
|
|
34
|
+
"limit": 30,
|
|
35
|
+
"select": [
|
|
36
|
+
"unit_of_measure_conversions__factor",
|
|
37
|
+
"unit_of_measure_conversions__operation",
|
|
38
|
+
"sku"
|
|
39
|
+
],
|
|
40
|
+
"order_by": [
|
|
41
|
+
"-created_at"
|
|
42
|
+
],
|
|
43
|
+
"filter": {
|
|
44
|
+
"sku__in": productCodes,
|
|
45
|
+
"module": "INVENTORY",
|
|
46
|
+
"submodule": "CATALOGUE",
|
|
47
|
+
"status": "ACTIVE"
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
logger.log(zudelloItems);
|
|
52
|
+
|
|
53
|
+
const zudelloItemsData = zudelloItems?.data?.data ?? [];
|
|
54
|
+
|
|
55
|
+
const tax = _.reduce(item.partials, (acc, partial) => {
|
|
56
|
+
const partialTax = _.reduce(partial.line_items, (partialAcc, lineItem) => {
|
|
57
|
+
return partialAcc + (lineItem.ordered_tax_amount * lineItem.ordered_retail_quantity)
|
|
58
|
+
}, 0)
|
|
59
|
+
|
|
60
|
+
return acc + partialTax
|
|
61
|
+
}, 0)
|
|
62
|
+
|
|
63
|
+
const total = _.reduce(item.partials, (acc, partial) => {
|
|
64
|
+
const partialTotal = _.reduce(partial.line_items, (partialAcc, lineItem) => {
|
|
65
|
+
return partialAcc + (lineItem.ordered_unit_price * lineItem.ordered_retail_quantity)
|
|
66
|
+
}, 0)
|
|
67
|
+
|
|
68
|
+
return acc + partialTotal
|
|
69
|
+
}, 0)
|
|
70
|
+
|
|
71
|
+
const transactionData = {
|
|
72
|
+
model: "Transaction",
|
|
73
|
+
data: {
|
|
74
|
+
module: "PURCHASING",
|
|
75
|
+
submodule: "ORDER",
|
|
76
|
+
document_type: "PURCHASE_ORDER",
|
|
77
|
+
"external_id": _.get(item, "order_id"),
|
|
78
|
+
"supplier": {
|
|
79
|
+
"fetch": true,
|
|
80
|
+
"create": true,
|
|
81
|
+
"update": false,
|
|
82
|
+
"data": {
|
|
83
|
+
"external_id": _.get(item, 'vendor.code')
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"company_name": _.get(item, 'vendor_name'),
|
|
87
|
+
"company_tax": _.get(item, 'vendor.tin'),
|
|
88
|
+
"document_number": _.get(item, "order_number"),
|
|
89
|
+
"subtotal": total - tax,
|
|
90
|
+
"tax": tax,
|
|
91
|
+
"total": total,
|
|
92
|
+
"status": "READY",
|
|
93
|
+
"lines": {
|
|
94
|
+
"replace": false,
|
|
95
|
+
"items": _.flatten(_.map(_.get(item, 'partials'), (partial, invoiceID) => {
|
|
96
|
+
return _.map(_.get(partial, 'line_items'), (lineItem, lineID) => {
|
|
97
|
+
const productCode = _.get(lineItem, 'product_code');
|
|
98
|
+
const location = _.get(item, 'center.code');
|
|
99
|
+
|
|
100
|
+
const productCodeItem = zudelloItemsData.find(item => item.sku === productCode);
|
|
101
|
+
|
|
102
|
+
let itemDataQty = _.get(lineItem, "ordered_retail_quantity")
|
|
103
|
+
|
|
104
|
+
logger.log('---------------------')
|
|
105
|
+
logger.log(itemDataQty)
|
|
106
|
+
|
|
107
|
+
if (productCodeItem) {
|
|
108
|
+
const factor = productCodeItem.unit_of_measure_conversions?.factor ? Number(productCodeItem.unit_of_measure_conversions?.factor) : null
|
|
109
|
+
const operation = productCodeItem.unit_of_measure_conversions?.operation ?? null
|
|
110
|
+
|
|
111
|
+
if (operation === 'MULTIPLY' && factor) {
|
|
112
|
+
logger.log('MULTIPLY')
|
|
113
|
+
logger.log(factor)
|
|
114
|
+
|
|
115
|
+
itemDataQty = itemDataQty * factor
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (operation === 'DIVIDE' && factor) {
|
|
119
|
+
logger.log('DIVIDE')
|
|
120
|
+
logger.log(factor)
|
|
121
|
+
|
|
122
|
+
itemDataQty = itemDataQty / factor
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
logger.log(itemDataQty)
|
|
127
|
+
logger.log('---------------------')
|
|
128
|
+
|
|
129
|
+
const itemData = {
|
|
130
|
+
"create": true,
|
|
131
|
+
"update": true,
|
|
132
|
+
"data": {
|
|
133
|
+
"external_id": _.get(item, "order_id") + "-" + invoiceID + "-" + lineID,
|
|
134
|
+
"description": _.get(lineItem, 'product_name'),
|
|
135
|
+
"quantity": itemDataQty,
|
|
136
|
+
"unit_price": _.get(lineItem, "ordered_unit_price"),
|
|
137
|
+
"total": _.get(lineItem, "ordered_retail_quantity") * _.get(lineItem, "ordered_unit_price"),
|
|
138
|
+
"note": _.get(lineItem, "notes")
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
if (productCode) {
|
|
143
|
+
itemData.data.item = {
|
|
144
|
+
"fetch": true,
|
|
145
|
+
"create": true,
|
|
146
|
+
"update": false,
|
|
147
|
+
"data": {
|
|
148
|
+
"external_id": productCode
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (location) {
|
|
154
|
+
itemData.data.location = {
|
|
155
|
+
"fetch": true,
|
|
156
|
+
"create": true,
|
|
157
|
+
"update": false,
|
|
158
|
+
"data": {
|
|
159
|
+
"external_id": location
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return itemData;
|
|
165
|
+
});
|
|
166
|
+
}))
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"enrich": false,
|
|
170
|
+
"submit": false,
|
|
171
|
+
"create": true,
|
|
172
|
+
"update": true,
|
|
173
|
+
"update_status": false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const orderedDate = _.get(item, 'ordered_date');
|
|
177
|
+
|
|
178
|
+
if (orderedDate) {
|
|
179
|
+
transactionData.data.date_issued = moment(orderedDate).format('YYYY-MM-DD')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return transactionData
|
|
183
|
+
}))
|
|
184
|
+
|
|
185
|
+
logger.log(data)
|
|
186
|
+
|
|
187
|
+
const result = await Zudello.updateOrCreate({ data })
|
|
188
|
+
|
|
189
|
+
logger.log(result)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
package/src/sdk/Auth.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const ApiInstance = require('../utils/apiInstance')
|
|
4
|
+
|
|
5
|
+
class Auth {
|
|
6
|
+
/**
|
|
7
|
+
* Constructor.
|
|
8
|
+
* @param {string} teamUUID The UUID of the Team we're working on.
|
|
9
|
+
* @param {string|null} token JWT Token.
|
|
10
|
+
*/
|
|
11
|
+
constructor ({ teamUUID, token }) {
|
|
12
|
+
this.teamUUID = teamUUID
|
|
13
|
+
this.token = token
|
|
14
|
+
|
|
15
|
+
this.apiInstance = new ApiInstance()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Getter function for teamUUID.
|
|
20
|
+
* @returns {string} Team UUID.
|
|
21
|
+
*/
|
|
22
|
+
getTeamUUID () {
|
|
23
|
+
return this.teamUUID
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Getter function for apiInstance.
|
|
28
|
+
* @returns {class} Api Instance Class Object.
|
|
29
|
+
*/
|
|
30
|
+
getApiInstance () {
|
|
31
|
+
return this.apiInstance
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Makes an auth based on provided keys and stores the Bearer Token.
|
|
36
|
+
*/
|
|
37
|
+
async authenticate () {
|
|
38
|
+
this.apiInstance.setBearerToken(this.token)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = Auth
|
package/src/sdk/Base.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const config = require('../utils/config')
|
|
4
|
+
const Validator = require('../utils/validator')
|
|
5
|
+
const Logger = require('../utils/logger')
|
|
6
|
+
|
|
7
|
+
class BaseSDK {
|
|
8
|
+
/**
|
|
9
|
+
* Constructor.
|
|
10
|
+
* @param {class} auth Auth class object with authorized api instance.
|
|
11
|
+
* @param {string|null} connectionUUID The UUID of the Connection we're working on.
|
|
12
|
+
* @param {string|null} appUUIDKey The Key of UUID of the App we're working on.
|
|
13
|
+
* @param {boolean} isExternal Is Connection external.
|
|
14
|
+
* @param {string} organizationUUID The UUID of the Organization.
|
|
15
|
+
* @param {string} apiURL The URL of the API.
|
|
16
|
+
* @param {string} apiVersion The Version of the API.
|
|
17
|
+
*/
|
|
18
|
+
constructor ({
|
|
19
|
+
auth,
|
|
20
|
+
connectionUUID = null,
|
|
21
|
+
appUUIDKey = null,
|
|
22
|
+
isExternal = true,
|
|
23
|
+
organizationUUID,
|
|
24
|
+
apiURL,
|
|
25
|
+
apiVersion = 'v1',
|
|
26
|
+
integrationName = '',
|
|
27
|
+
loggerClass = null
|
|
28
|
+
}) {
|
|
29
|
+
this.config = config
|
|
30
|
+
this.connectionUUID = connectionUUID
|
|
31
|
+
this.isExternal = isExternal
|
|
32
|
+
this.organizationUUID = organizationUUID
|
|
33
|
+
this.integrationName = integrationName
|
|
34
|
+
|
|
35
|
+
this.validator = new Validator()
|
|
36
|
+
this.logger = loggerClass ? loggerClass : new Logger()
|
|
37
|
+
|
|
38
|
+
this.teamUUID = auth.getTeamUUID()
|
|
39
|
+
this.apiInstance = auth.getApiInstance()
|
|
40
|
+
|
|
41
|
+
this.responseHandler = this.apiInstance.responseHandler
|
|
42
|
+
|
|
43
|
+
this.apiVersion = apiVersion
|
|
44
|
+
this.apiURL = apiURL
|
|
45
|
+
|
|
46
|
+
this.appUUID = appUUIDKey
|
|
47
|
+
? this.config.appUUIDs[appUUIDKey]
|
|
48
|
+
: null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async makeRequest (method, url, data, params = {}, returnHeaders = false) {
|
|
52
|
+
const callback = ({ status, response, body, params, headers }) => {
|
|
53
|
+
this.logger.request(`${this.integrationName} - ${method} ${url}`, {
|
|
54
|
+
status,
|
|
55
|
+
request: {
|
|
56
|
+
url,
|
|
57
|
+
method,
|
|
58
|
+
body,
|
|
59
|
+
params,
|
|
60
|
+
headers
|
|
61
|
+
},
|
|
62
|
+
response
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
switch (method.toLowerCase()) {
|
|
67
|
+
case 'get':
|
|
68
|
+
return await this.apiInstance.get(url, this.populateStaticParams(data), this.getStaticHeaders(), returnHeaders, callback)
|
|
69
|
+
case 'post':
|
|
70
|
+
return await this.apiInstance.post(url, data, this.getStaticHeaders(), this.populateStaticParams(params), callback)
|
|
71
|
+
case 'put':
|
|
72
|
+
return await this.apiInstance.put(url, data, this.getStaticHeaders(), this.populateStaticParams(params), callback)
|
|
73
|
+
case 'delete':
|
|
74
|
+
return await this.apiInstance.delete(url, callback)
|
|
75
|
+
default:
|
|
76
|
+
return this.responseHandler.error(['Request method not found.'])
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get static object of headers for all requests.
|
|
82
|
+
* @returns {object} Object with static headers.
|
|
83
|
+
*/
|
|
84
|
+
getStaticHeaders () {
|
|
85
|
+
return {
|
|
86
|
+
'x-team': this.teamUUID,
|
|
87
|
+
'X-Organization': this.organizationUUID,
|
|
88
|
+
'Content-Type': 'application/json'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get static object of params for all requests.
|
|
94
|
+
* @returns {object} Object with static params.
|
|
95
|
+
*/
|
|
96
|
+
getStaticParams () {
|
|
97
|
+
return this.isExternal ? {
|
|
98
|
+
_debug: false,
|
|
99
|
+
connection: this.connectionUUID,
|
|
100
|
+
team: this.teamUUID,
|
|
101
|
+
app: this.appUUID
|
|
102
|
+
} : {}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Populate dynamic params with static ones.
|
|
107
|
+
* @param {object} params The dynamic params.
|
|
108
|
+
* @returns {object} Populated object of static and dynamic params.
|
|
109
|
+
*/
|
|
110
|
+
populateStaticParams (params) {
|
|
111
|
+
return {
|
|
112
|
+
...this.getStaticParams(),
|
|
113
|
+
...params
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = BaseSDK
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const BaseSDK = require('./Base')
|
|
4
|
+
const UniversalModule = require('./submodules/bc/Universal')
|
|
5
|
+
|
|
6
|
+
class BusinessCentralSDK extends BaseSDK {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor.
|
|
9
|
+
* @param {class} auth Auth class object with authorized api instance.
|
|
10
|
+
* @param {string} connectionUUID The UUID of the Connection we're working on.
|
|
11
|
+
*/
|
|
12
|
+
constructor (auth, connectionUUID, organizationUUID, apiURL, apiVersion, loggerClass = null) {
|
|
13
|
+
super({
|
|
14
|
+
auth,
|
|
15
|
+
connectionUUID,
|
|
16
|
+
organizationUUID,
|
|
17
|
+
apiURL,
|
|
18
|
+
apiVersion,
|
|
19
|
+
appUUIDKey: 'bc',
|
|
20
|
+
integrationName: 'BC',
|
|
21
|
+
loggerClass
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create submodule instances.
|
|
26
|
+
*/
|
|
27
|
+
this.universal = new UniversalModule(this)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = BusinessCentralSDK
|
package/src/sdk/Dear.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const BaseSDK = require('./Base')
|
|
4
|
+
const UniversalModule = require('./submodules/dear/Universal')
|
|
5
|
+
|
|
6
|
+
class DearSDK extends BaseSDK {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor.
|
|
9
|
+
* @param {class} auth Auth class object with authorized api instance.
|
|
10
|
+
* @param {string} connectionUUID The UUID of the Connection we're working on.
|
|
11
|
+
*/
|
|
12
|
+
constructor (auth, connectionUUID, organizationUUID, apiURL, apiVersion, loggerClass = null) {
|
|
13
|
+
super({
|
|
14
|
+
auth,
|
|
15
|
+
connectionUUID,
|
|
16
|
+
organizationUUID,
|
|
17
|
+
apiURL,
|
|
18
|
+
apiVersion,
|
|
19
|
+
appUUIDKey: 'dear',
|
|
20
|
+
integrationName: 'Dear',
|
|
21
|
+
loggerClass
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create submodule instances.
|
|
26
|
+
*/
|
|
27
|
+
this.universal = new UniversalModule(this)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = DearSDK
|
package/src/sdk/Fo.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const BaseSDK = require('./Base')
|
|
4
|
+
const UniversalModule = require('./submodules/fo/Universal')
|
|
5
|
+
|
|
6
|
+
class FoSDK extends BaseSDK {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor.
|
|
9
|
+
* @param {class} auth Auth class object with authorized api instance.
|
|
10
|
+
* @param {string} connectionUUID The UUID of the Connection we're working on.
|
|
11
|
+
*/
|
|
12
|
+
constructor (auth, connectionUUID, organizationUUID, apiURL, apiVersion, loggerClass = null) {
|
|
13
|
+
super({
|
|
14
|
+
auth,
|
|
15
|
+
connectionUUID,
|
|
16
|
+
organizationUUID,
|
|
17
|
+
apiURL,
|
|
18
|
+
apiVersion,
|
|
19
|
+
appUUIDKey: 'fo',
|
|
20
|
+
integrationName: 'FO',
|
|
21
|
+
loggerClass
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create submodule instances.
|
|
26
|
+
*/
|
|
27
|
+
this.universal = new UniversalModule(this)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = FoSDK
|