dcos-core-monalisav2-latam 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 +130 -0
- package/index.js +350 -0
- package/package.json +52 -0
- package/src/auth/handler.js +3 -0
- package/src/common/MondelezCastOrder.js +449 -0
- package/src/common/utils/AuthSecurity.js +46 -0
- package/src/common/utils/account-error-handler.js +279 -0
- package/src/common/utils/account-error-helper.js +231 -0
- package/src/common/utils/account-properties-handler.js +355 -0
- package/src/common/utils/api-response.js +62 -0
- package/src/common/utils/aws-services.js +186 -0
- package/src/common/utils/constants/account-error-codes.json +801 -0
- package/src/common/utils/constants.js +37 -0
- package/src/common/utils/convert/MondelezClientsItemsCast.js +52 -0
- package/src/common/utils/convert/MondelezInventoryItemsCast.js +15 -0
- package/src/common/utils/convert/MondelezOrderStatusCast.js +34 -0
- package/src/common/utils/convert/MondelezPricesItemsCast.js +37 -0
- package/src/common/utils/cron-ftp-get.js +143 -0
- package/src/common/utils/data-tables-helper.js +213 -0
- package/src/common/utils/date-range-calculator.js +113 -0
- package/src/common/utils/delay.js +17 -0
- package/src/common/utils/ftp-sftp.js +320 -0
- package/src/common/utils/logger.js +126 -0
- package/src/common/utils/nodemailerLib.js +61 -0
- package/src/common/utils/product-unit-converter.js +168 -0
- package/src/common/utils/schemas-utils.js +101 -0
- package/src/common/utils/seller-email-sharing-service.js +441 -0
- package/src/common/utils/sftp-utils.js +202 -0
- package/src/common/utils/status.js +15 -0
- package/src/common/utils/util.js +236 -0
- package/src/common/utils/validate-state-order.js +35 -0
- package/src/common/utils/validateProviders.js +67 -0
- package/src/common/utils/validation-data.js +45 -0
- package/src/common/utils/vtex/save-hooks.js +65 -0
- package/src/common/utils/vtex/save-schemas.js +65 -0
- package/src/common/utils/vtex-hook-handler.js +71 -0
- package/src/common/validation/AccountCoordinatesValidation.js +350 -0
- package/src/common/validation/GeneralErrorValidation.js +11 -0
- package/src/common/validation/MainErrorValidation.js +8 -0
- package/src/entities/account.js +639 -0
- package/src/entities/clients.js +104 -0
- package/src/entities/controlprice.js +196 -0
- package/src/entities/controlstock.js +206 -0
- package/src/entities/cron.js +77 -0
- package/src/entities/cronjob.js +71 -0
- package/src/entities/orders.js +195 -0
- package/src/entities/sftp-inbound.js +88 -0
- package/src/entities/sku.js +220 -0
- package/src/entities/taxpromotion.js +249 -0
- package/src/functions/account/account-get.js +262 -0
- package/src/functions/account/account-handler.js +299 -0
- package/src/functions/account/clients.js +10 -0
- package/src/functions/account/index.js +208 -0
- package/src/functions/actions/save-promotions-order-history.js +324 -0
- package/src/functions/affiliates/affiliates-hook-consumer.js +87 -0
- package/src/functions/affiliates/affiliates-hook-producer.js +45 -0
- package/src/functions/clients/clients-audience.js +62 -0
- package/src/functions/clients/clients-consumer.js +648 -0
- package/src/functions/clients/clients-producer.js +362 -0
- package/src/functions/clients/clients-suggested-product-consumer.js +166 -0
- package/src/functions/clients/helpers/suggested-product-mdlz.js +233 -0
- package/src/functions/clients_peru/email.html +129 -0
- package/src/functions/clients_peru/splitfile.js +357 -0
- package/src/functions/clients_peru/updateClients.js +1334 -0
- package/src/functions/clients_peru/utils.js +243 -0
- package/src/functions/cronjobs/cron-jobs-manager.js +40 -0
- package/src/functions/cronjobs/cron-jobs.js +171 -0
- package/src/functions/crons/cron.js +39 -0
- package/src/functions/distributors/distributor-handler.js +81 -0
- package/src/functions/distributors/distributor.js +535 -0
- package/src/functions/distributors/index.js +60 -0
- package/src/functions/financialpolicy/assign-financialpolicy.js +111 -0
- package/src/functions/financialpolicy/get-financialpolicy.js +91 -0
- package/src/functions/financialpolicy/index.js +28 -0
- package/src/functions/inventory/catalog-sync-consumer.js +17 -0
- package/src/functions/inventory/catalog-sync-handler.js +311 -0
- package/src/functions/inventory/inventory-consumer.js +119 -0
- package/src/functions/inventory/inventory-producer.js +197 -0
- package/src/functions/multiPresentation/multipre-queue.js +155 -0
- package/src/functions/multiPresentation/multipres.js +459 -0
- package/src/functions/nodeflow/index.js +83 -0
- package/src/functions/nodeflow/nodeflow-cron.js +200 -0
- package/src/functions/nodeflow/nodeflow-pub.js +203 -0
- package/src/functions/nodeflow/nodeflow-pvt.js +266 -0
- package/src/functions/notifications/download-leads-handler.js +67 -0
- package/src/functions/notifications/new-leads-notification-consumer.js +17 -0
- package/src/functions/notifications/new-leads-notification-handler.js +359 -0
- package/src/functions/notifications/order-status-notification-handler.js +482 -0
- package/src/functions/notifications/promotion-notification-handler.js +193 -0
- package/src/functions/orders/index.js +32 -0
- package/src/functions/orders/orders-cancel-handler.js +74 -0
- package/src/functions/orders/orders-handler.js +280 -0
- package/src/functions/orders/orders-hook-consumer.js +137 -0
- package/src/functions/orders/orders-hook-producer.js +170 -0
- package/src/functions/orders/orders-notifications-handler.js +137 -0
- package/src/functions/orders/orders-status-consumer.js +461 -0
- package/src/functions/orders/orders-status-producer.js +443 -0
- package/src/functions/prices/index.js +75 -0
- package/src/functions/prices/prices-consumer.js +236 -0
- package/src/functions/prices/prices-producer.js +323 -0
- package/src/functions/prices/promotion-and-tax.js +1284 -0
- package/src/functions/routesflow/assign-routeflow-queue.js +77 -0
- package/src/functions/schemas/vtex/handle-schemas.js +102 -0
- package/src/functions/security/process_gas.js +221 -0
- package/src/functions/security/security-handler.js +950 -0
- package/src/functions/sftp/sftp-consumer.js +453 -0
- package/src/functions/sftpIntegrations/processes/redirectServices.js +184 -0
- package/src/functions/sftpIntegrations/processes/validateFileSchema.js +226 -0
- package/src/functions/sftpIntegrations/schemas/credential-schema.js +123 -0
- package/src/functions/sftpIntegrations/schemas/record-schema.js +131 -0
- package/src/functions/sftpIntegrations/schemas/sftp_required_fields.json +3 -0
- package/src/functions/sftpIntegrations/sftp-config-producer.js +112 -0
- package/src/functions/sftpIntegrations/sftp-consumer.js +700 -0
- package/src/functions/sftpIntegrations/test/validateFile.test.js +122 -0
- package/src/functions/sftpIntegrations/utils/connect-dynamo.js +29 -0
- package/src/functions/sftpIntegrations/utils/split-data.js +25 -0
- package/src/functions/utils/index.js +130 -0
- package/src/functions/vtex/vtex-helpers.js +694 -0
- package/src/integrations/accountErrors/AccountErrorManager.js +437 -0
- package/src/integrations/audience/Audience.js +70 -0
- package/src/integrations/financialPolicy/FinancialPolicyApi.js +377 -0
- package/src/integrations/index.js +0 -0
- package/src/integrations/mobilvendor/MobilvendorApi.js +405 -0
- package/src/integrations/productmultipresentation/ProductMultiPresentation.js +200 -0
- package/src/mdlz/auth/SecretManagerApi.js +77 -0
- package/src/mdlz/client/MdlzApi.js +70 -0
- package/src/vtex/clients/ProvidersApi.js +51 -0
- package/src/vtex/clients/VtexApi.js +511 -0
- package/src/vtex/models/VtexOrder.js +87 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
const Logger = require("./utils/logger");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ajuste decimal de un número.
|
|
5
|
+
*
|
|
6
|
+
* @param {String} tipo El tipo de ajuste.
|
|
7
|
+
* @param {Number} valor El numero.
|
|
8
|
+
* @param {Integer} exp El exponente (el logaritmo 10 del ajuste base).
|
|
9
|
+
* @returns {Number} El valor ajustado.
|
|
10
|
+
*/
|
|
11
|
+
function decimalAdjust(type, value, exp) {
|
|
12
|
+
// Si el exp no está definido o es cero...
|
|
13
|
+
if (typeof exp === "undefined" || +exp === 0) {
|
|
14
|
+
return Math[type](value);
|
|
15
|
+
}
|
|
16
|
+
value = +value;
|
|
17
|
+
exp = +exp;
|
|
18
|
+
// Si el valor no es un número o el exp no es un entero...
|
|
19
|
+
if (isNaN(value) || !(typeof exp === "number" && exp % 1 === 0)) {
|
|
20
|
+
return NaN;
|
|
21
|
+
}
|
|
22
|
+
// Shift
|
|
23
|
+
value = value.toString().split("e");
|
|
24
|
+
value = Math[type](+(value[0] + "e" + (value[1] ? +value[1] - exp : -exp)));
|
|
25
|
+
// Shift back
|
|
26
|
+
value = value.toString().split("e");
|
|
27
|
+
return +(value[0] + "e" + (value[1] ? +value[1] + exp : exp));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* get sum Benefits VTEX
|
|
32
|
+
* @param item - object
|
|
33
|
+
**/
|
|
34
|
+
const getSumBenefitsVTEX= (item)=>{
|
|
35
|
+
try{
|
|
36
|
+
if(!item){
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
let sumBenefits= 0;
|
|
40
|
+
for (var i = 0; i < item?.priceTags?.length; i++) {
|
|
41
|
+
if(item?.priceTags[i]?.name?.indexOf("discount@price") > -1){
|
|
42
|
+
sumBenefits+= parseFloat(item?.priceTags[i]?.value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return sumBenefits;
|
|
46
|
+
}catch(e){
|
|
47
|
+
Logger.error("error getSumBenefitsVTEX", e);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const setPorcentItmsPricetags= (item, ratesAndBenefitsData=null)=>{
|
|
54
|
+
let priceTags=[];
|
|
55
|
+
let valueItem= (parseFloat(item?.price)*(parseFloat(item?.quantity)*parseFloat(item?.unitMultiplier)));
|
|
56
|
+
let sumTaxes= 0, sumDiscounts= 0;
|
|
57
|
+
let sumBenefits= getSumBenefitsVTEX(item);
|
|
58
|
+
let subtotalItem= valueItem;
|
|
59
|
+
|
|
60
|
+
for (var i = 0; i < item?.priceTags?.length; i++) {
|
|
61
|
+
if(item?.priceTags[i]?.name?.indexOf("tax@price") > -1){
|
|
62
|
+
// logica calculo impuestos
|
|
63
|
+
let calc= ( ((parseFloat(subtotalItem)/100) + (parseFloat(sumBenefits)/100) ) * (parseFloat(item?.priceTags[i]?.value)/100) );
|
|
64
|
+
let pricetaxRound= item?.sellingPrice === 0 ? 0 : decimalAdjust("round",(parseFloat(calc)),-2)*100;
|
|
65
|
+
let rawValueNominal= item?.sellingPrice === 0 ? 0 : Number(parseFloat(calc)).toFixed(9);
|
|
66
|
+
|
|
67
|
+
sumTaxes+= parseFloat(rawValueNominal);
|
|
68
|
+
|
|
69
|
+
priceTags=[...priceTags, {
|
|
70
|
+
"name": item?.priceTags[i]?.name,
|
|
71
|
+
"value": item?.priceTags[i]?.value,
|
|
72
|
+
"isPercentual": item?.priceTags[i]?.isPercentual,
|
|
73
|
+
"valueNominal": pricetaxRound,
|
|
74
|
+
"rawValueNominal": parseFloat(rawValueNominal),
|
|
75
|
+
"identifier": item?.priceTags[i]?.identifier,
|
|
76
|
+
"rawValue": item?.priceTags[i]?.rawValue,
|
|
77
|
+
"rate": item?.priceTags[i]?.rate,
|
|
78
|
+
"jurisCode": item?.priceTags[i]?.jurisCode,
|
|
79
|
+
"jurisType": item?.priceTags[i]?.jurisType,
|
|
80
|
+
"jurisName": item?.priceTags[i]?.jurisName
|
|
81
|
+
}];
|
|
82
|
+
|
|
83
|
+
}else{
|
|
84
|
+
let porcent= item?.priceTags[i]?.isPercentual === false ? ((parseFloat(item?.priceTags[i]?.value) / parseFloat(valueItem))*-100) : item?.priceTags[i]?.value;
|
|
85
|
+
let rawPorcent= item?.priceTags[i]?.isPercentual === false ? (( parseFloat(item?.priceTags[i]?.value) / parseFloat(valueItem) )*-100 ) : ( (parseFloat(item?.priceTags[i]?.value)) );
|
|
86
|
+
rawPorcent= Number((parseFloat(rawPorcent)/100)).toFixed(4);
|
|
87
|
+
|
|
88
|
+
if(item?.priceTags[i]?.name?.indexOf("DISCOUNT@GIFT") > -1){
|
|
89
|
+
sumDiscounts+= (parseFloat(valueItem)*-1);
|
|
90
|
+
item.priceTags[i].value= (parseFloat(valueItem)*-1);
|
|
91
|
+
item.priceTags[i].rawValue= ((parseFloat(valueItem)/100)*-1);
|
|
92
|
+
}else{
|
|
93
|
+
sumDiscounts+= item?.priceTags[i]?.value;
|
|
94
|
+
valueItem= parseFloat(valueItem)+parseFloat(item?.priceTags[i]?.value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let benefitsSearch= selectedBenefitsData(item?.priceTags[i]?.identifier, ratesAndBenefitsData);
|
|
98
|
+
priceTags=[...priceTags, {
|
|
99
|
+
"name": item?.priceTags[i]?.name,
|
|
100
|
+
"discountName": benefitsSearch?.name,
|
|
101
|
+
"discountDescription": benefitsSearch?.description,
|
|
102
|
+
"IdExternalPromotion": benefitsSearch?.IdExternalPromotion,
|
|
103
|
+
"value": item?.priceTags[i]?.value,
|
|
104
|
+
"isPercentual": item?.priceTags[i]?.isPercentual,
|
|
105
|
+
"percent": decimalAdjust("round", porcent, -1),
|
|
106
|
+
"rawPercent": decimalAdjust("round", parseFloat(rawPorcent), -3),
|
|
107
|
+
"identifier": item?.priceTags[i]?.identifier,
|
|
108
|
+
"rawValue": item?.priceTags[i]?.rawValue,
|
|
109
|
+
"rate": item?.priceTags[i]?.rate,
|
|
110
|
+
"jurisCode": item?.priceTags[i]?.jurisCode,
|
|
111
|
+
"jurisType": item?.priceTags[i]?.jurisType,
|
|
112
|
+
"jurisName": item?.priceTags[i]?.jurisName
|
|
113
|
+
}];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {priceTags, sumTaxes, sumDiscounts};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Datos beneficio
|
|
122
|
+
**/
|
|
123
|
+
const selectedBenefitsData= (identifier, ratesAndBenefitsData=[])=>{
|
|
124
|
+
let benefits= ratesAndBenefitsData?.find(it=>(it?.id === identifier));
|
|
125
|
+
return benefits ?? {};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Calulo total
|
|
130
|
+
**/
|
|
131
|
+
const setTotal= (item, taxTotal=0)=>{
|
|
132
|
+
let total = item?.priceDefinition?.total || item?.sellingPrice * item?.quantity;
|
|
133
|
+
total = parseFloat(total)/100;
|
|
134
|
+
|
|
135
|
+
let calTotalTax= parseFloat(total)+parseFloat(taxTotal),
|
|
136
|
+
totalT= Math.round(parseFloat(calTotalTax)*100),
|
|
137
|
+
totalTRaw= parseFloat(total)+parseFloat(taxTotal);
|
|
138
|
+
|
|
139
|
+
return {totalT,totalTRaw};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Funcion para seteo de custom data VTEX y politicas financieras
|
|
144
|
+
**/
|
|
145
|
+
const setJsonFinancialPolicy = ({customData= null, configAccount=null})=>{
|
|
146
|
+
if(configAccount?.FinancialPolicyEcu?.isActive === true && configAccount?.FinancialPolicyEcu?.configVtex?.id){
|
|
147
|
+
let customDataFP = null, customDataReturn= {"customApps":[]};
|
|
148
|
+
if(customData){
|
|
149
|
+
customDataReturn.customApps= customData?.customApps;
|
|
150
|
+
if(!customDataReturn?.customApps.find(fp=> (fp?.id == configAccount?.FinancialPolicyEcu?.configVtex?.id) ) ){
|
|
151
|
+
customDataFP= configAccount?.FinancialPolicyEcu?.jsonDefault ?? null;
|
|
152
|
+
}
|
|
153
|
+
}else {
|
|
154
|
+
customDataFP= configAccount?.FinancialPolicyEcu?.jsonDefault ?? null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if(customDataFP){
|
|
158
|
+
customDataReturn.customApps= [...customDataReturn.customApps, customDataFP];
|
|
159
|
+
return customDataReturn;
|
|
160
|
+
}else{
|
|
161
|
+
return customDataReturn;
|
|
162
|
+
}
|
|
163
|
+
}else{
|
|
164
|
+
return customData;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
function orderToJson(vtexOrder, parentVtexOrder, configAccount= null) {
|
|
169
|
+
const marketingDataTm= {
|
|
170
|
+
"id": "marketingData",
|
|
171
|
+
"utmSource": null,
|
|
172
|
+
"utmPartner": null,
|
|
173
|
+
"utmMedium": null,
|
|
174
|
+
"utmCampaign": null,
|
|
175
|
+
"coupon": null,
|
|
176
|
+
"utmiCampaign": null,
|
|
177
|
+
"utmipage": null,
|
|
178
|
+
"utmiPart": null,
|
|
179
|
+
"marketingTags": []
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const mondelezOrder = {
|
|
183
|
+
id: vtexOrder?.orderId,
|
|
184
|
+
accountName: vtexOrder?.merchantName || vtexOrder?.hostname,
|
|
185
|
+
status: vtexOrder?.status,
|
|
186
|
+
statusDescription: vtexOrder?.statusDescription,
|
|
187
|
+
value: vtexOrder?.value,
|
|
188
|
+
creationDate: vtexOrder?.creationDate,
|
|
189
|
+
lastChange: vtexOrder?.lastChange,
|
|
190
|
+
allowCancellation: vtexOrder?.allowCancellation,
|
|
191
|
+
cancelReason: vtexOrder?.cancelReason,
|
|
192
|
+
totals: vtexOrder?.totals,
|
|
193
|
+
items: parentVtexOrder?.items?.map((item) => {
|
|
194
|
+
let calcDiscountTaxes= setPorcentItmsPricetags(item, parentVtexOrder?.ratesAndBenefitsData?.rateAndBenefitsIdentifiers);
|
|
195
|
+
let subtotal= (parseFloat(item?.price) * parseFloat(item?.quantity) * parseFloat(item?.unitMultiplier));
|
|
196
|
+
let subtotalWithDiscounts= (parseFloat(calcDiscountTaxes?.sumDiscounts)*parseFloat(-1));
|
|
197
|
+
|
|
198
|
+
let percentCalc= ((parseFloat(subtotalWithDiscounts)*100)/parseFloat(subtotal));
|
|
199
|
+
let porcent= parseFloat(percentCalc);
|
|
200
|
+
let rawPorcent= Number((parseFloat(percentCalc)/100)).toFixed(4);
|
|
201
|
+
|
|
202
|
+
return ({
|
|
203
|
+
uniqueId: item?.uniqueId,
|
|
204
|
+
sku: item?.refId || item?.ean,
|
|
205
|
+
ean: item?.ean,
|
|
206
|
+
name: item?.name,
|
|
207
|
+
quantitySelected: item?.quantity,
|
|
208
|
+
quantity: (parseFloat(item?.quantity) * parseFloat(item?.unitMultiplier)),
|
|
209
|
+
unitMultiplier: item?.unitMultiplier,
|
|
210
|
+
listPrice: item?.listPrice,
|
|
211
|
+
price: item?.price,
|
|
212
|
+
sellingPrice: item?.sellingPrice,
|
|
213
|
+
sellingPriceUnit: (parseFloat(item?.sellingPrice)/parseFloat(item?.unitMultiplier)),
|
|
214
|
+
subtotal: subtotal,
|
|
215
|
+
subtotalRaw: (parseFloat(subtotal) / 100),
|
|
216
|
+
discount: calcDiscountTaxes?.sumDiscounts,
|
|
217
|
+
discountRaw: (parseFloat(calcDiscountTaxes?.sumDiscounts)/100),
|
|
218
|
+
porcent: porcent,
|
|
219
|
+
rawPorcent: parseFloat(rawPorcent),
|
|
220
|
+
roundPorcent: decimalAdjust("round", porcent, 0),
|
|
221
|
+
tax: item?.tax,
|
|
222
|
+
taxes: decimalAdjust("round",(parseFloat(calcDiscountTaxes?.sumTaxes)),-2)*100,
|
|
223
|
+
taxesRaw: calcDiscountTaxes?.sumTaxes,
|
|
224
|
+
total: setTotal(item, calcDiscountTaxes?.sumTaxes)?.totalT,
|
|
225
|
+
totalRaw: setTotal(item, calcDiscountTaxes?.sumTaxes)?.totalTRaw,
|
|
226
|
+
priceTags: calcDiscountTaxes?.priceTags,
|
|
227
|
+
imageUrl: item?.imageUrl,
|
|
228
|
+
isGift: item?.isGift,
|
|
229
|
+
components: item?.components
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
}),
|
|
233
|
+
marketingData: parentVtexOrder?.marketingData || marketingDataTm,
|
|
234
|
+
customData: setJsonFinancialPolicy({customData: parentVtexOrder?.customData, configAccount:configAccount}),
|
|
235
|
+
clientProfileData: {
|
|
236
|
+
id: parentVtexOrder?.clientProfileData?.userProfileId,
|
|
237
|
+
email: parentVtexOrder?.clientProfileData?.email,
|
|
238
|
+
firstName: vtexOrder?.clientProfileData?.firstName,
|
|
239
|
+
lastName: vtexOrder?.clientProfileData?.lastName,
|
|
240
|
+
documentType: vtexOrder?.clientProfileData?.documentType,
|
|
241
|
+
document: vtexOrder?.clientProfileData?.document,
|
|
242
|
+
phone: vtexOrder?.clientProfileData?.phone,
|
|
243
|
+
corporateName: parentVtexOrder?.clientProfileData?.corporateName,
|
|
244
|
+
corporateDocument: parentVtexOrder?.clientProfileData?.corporateDocument,
|
|
245
|
+
tradeName: parentVtexOrder?.clientProfileData?.tradeName,
|
|
246
|
+
customerClass: parentVtexOrder?.clientProfileData?.customerClass,
|
|
247
|
+
},
|
|
248
|
+
shippingAddress: {
|
|
249
|
+
address: {
|
|
250
|
+
addressType: vtexOrder?.shippingData?.address?.addressType,
|
|
251
|
+
receiverName: vtexOrder?.shippingData?.address?.receiverName,
|
|
252
|
+
street: vtexOrder?.shippingData?.address?.street,
|
|
253
|
+
number: vtexOrder?.shippingData?.address?.number,
|
|
254
|
+
complement: vtexOrder?.shippingData?.address?.complement,
|
|
255
|
+
reference: vtexOrder?.shippingData?.address?.reference,
|
|
256
|
+
postalCode: vtexOrder?.shippingData?.address?.postalCode,
|
|
257
|
+
city: vtexOrder?.shippingData?.address?.city,
|
|
258
|
+
state: vtexOrder?.shippingData?.address?.state,
|
|
259
|
+
country: vtexOrder?.shippingData?.address?.country,
|
|
260
|
+
geoCoordinates: vtexOrder?.shippingData?.address?.geoCoordinates,
|
|
261
|
+
},
|
|
262
|
+
logisticsInfo: vtexOrder?.shippingData?.logisticsInfo[0]
|
|
263
|
+
},
|
|
264
|
+
ratesAndBenefitsData: parentVtexOrder?.ratesAndBenefitsData,
|
|
265
|
+
packageAttachment: parentVtexOrder?.packageAttachment,
|
|
266
|
+
changesAttachment: parentVtexOrder?.changesAttachment,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
return mondelezOrder;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function convertJsonOrderToCsv(jsonData) {
|
|
273
|
+
const csvData = [];
|
|
274
|
+
|
|
275
|
+
const csvHeaders = [
|
|
276
|
+
"orderId",
|
|
277
|
+
"status",
|
|
278
|
+
"creationDate",
|
|
279
|
+
"value",
|
|
280
|
+
"totalsItems",
|
|
281
|
+
"totalDiscounts",
|
|
282
|
+
"totalShipping",
|
|
283
|
+
"totalTax",
|
|
284
|
+
"clientId",
|
|
285
|
+
"clientEmail",
|
|
286
|
+
"clientFirstName",
|
|
287
|
+
"clientLastName",
|
|
288
|
+
"clientDocumentType",
|
|
289
|
+
"clientDocument",
|
|
290
|
+
"clientPhone",
|
|
291
|
+
"clientCorporateName",
|
|
292
|
+
"clientCorporateDocument",
|
|
293
|
+
"clientTradeName",
|
|
294
|
+
"clientCustomerClass",
|
|
295
|
+
"clientAddressStreet",
|
|
296
|
+
"clientAddressumber",
|
|
297
|
+
"clientAddressComplement",
|
|
298
|
+
"clientAddressReference",
|
|
299
|
+
"clientAddressPostalCode",
|
|
300
|
+
"clientAddressNeighborhood",
|
|
301
|
+
"clientAddressCity",
|
|
302
|
+
"clientAddressState",
|
|
303
|
+
"clientAddressCountry",
|
|
304
|
+
"clientAddressLatitude",
|
|
305
|
+
"clientAddressLongitude",
|
|
306
|
+
"logisticsDeliveryChannel",
|
|
307
|
+
"logsiticsSla",
|
|
308
|
+
"logsiticsCourierId",
|
|
309
|
+
"logsiticsCourierName",
|
|
310
|
+
"logisticsPickupPointId",
|
|
311
|
+
"logisticsShippingEstimateDate",
|
|
312
|
+
"logisticsDeliveryEstimateDateStart",
|
|
313
|
+
"logisticsDeliveryEstimateDateEnd",
|
|
314
|
+
"itemsSku",
|
|
315
|
+
"itemsEan",
|
|
316
|
+
"itemsName",
|
|
317
|
+
"itemsQty",
|
|
318
|
+
"itemsListPrice",
|
|
319
|
+
"itemsPrice",
|
|
320
|
+
"itemsSellingPrice",
|
|
321
|
+
"itemsTotal",
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
const orderId = jsonData.id || "";
|
|
325
|
+
const status = jsonData.status || "";
|
|
326
|
+
const creationDate = jsonData.creationDate || "";
|
|
327
|
+
const value = jsonData.value || "";
|
|
328
|
+
|
|
329
|
+
let totalsItems = 0;
|
|
330
|
+
let totalDiscounts = 0;
|
|
331
|
+
let totalShipping = 0;
|
|
332
|
+
let totalTax = 0;
|
|
333
|
+
|
|
334
|
+
for (const total of jsonData.totals) {
|
|
335
|
+
if (total.id === "Items") {
|
|
336
|
+
totalsItems = total.value || "";
|
|
337
|
+
} else if (total.id === "Discounts") {
|
|
338
|
+
totalDiscounts = total.value || "";
|
|
339
|
+
} else if (total.id === "Shipping") {
|
|
340
|
+
totalShipping = total.value || "";
|
|
341
|
+
} else if (total.id === "Tax") {
|
|
342
|
+
totalTax = total.value || "";
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const clientId = jsonData.clientProfileData.id || "";
|
|
347
|
+
const clientEmail = jsonData.clientProfileData.email || "";
|
|
348
|
+
const clientFirstName = jsonData.clientProfileData.firstName || "";
|
|
349
|
+
const clientLastName = jsonData.clientProfileData.lastName || "";
|
|
350
|
+
const clientDocumentType = jsonData.clientProfileData.documentType || "";
|
|
351
|
+
const clientDocument = jsonData.clientProfileData.document || "";
|
|
352
|
+
const clientPhone = jsonData.clientProfileData.phone || "";
|
|
353
|
+
const clientCorporateDocument = jsonData.clientProfileData.corporateDocument || "";
|
|
354
|
+
const clientCorporateName = jsonData.clientProfileData.corporateName || "";
|
|
355
|
+
const clientTradeName = jsonData.clientProfileData.tradeName || "";
|
|
356
|
+
const clientCustomerClass = jsonData.clientProfileData.customerClass || "";
|
|
357
|
+
|
|
358
|
+
const clientAddress = jsonData.shippingAddress.address || "";
|
|
359
|
+
const clientAddressStreet = clientAddress.street || "";
|
|
360
|
+
const clientAddressNumber = clientAddress.number || "";
|
|
361
|
+
const clientAddressComplement = clientAddress.complement || "";
|
|
362
|
+
const clientAddressReference = clientAddress.reference || "";
|
|
363
|
+
const clientAddressPostalCode = clientAddress.postalCode || "";
|
|
364
|
+
const clientAddressNeighborhood = clientAddress.neighborhood || "";
|
|
365
|
+
const clientAddressCity = clientAddress.city || "";
|
|
366
|
+
const clientAddressState = clientAddress.state || "";
|
|
367
|
+
const clientAddressCountry = clientAddress.country || "";
|
|
368
|
+
const clientAddressLatitude = clientAddress.geoCoordinates[1] || "";
|
|
369
|
+
const clientAddressLongitude = clientAddress.geoCoordinates[0] || "";
|
|
370
|
+
|
|
371
|
+
const logisticsDeliveryChannel = jsonData.shippingAddress.logisticsInfo.deliveryChannel || "";
|
|
372
|
+
const logisticsSla = jsonData.shippingAddress.logisticsInfo.selectedSla || "";
|
|
373
|
+
const logisticsCourierId = jsonData.shippingAddress.logisticsInfo.courierId || "";
|
|
374
|
+
const logisticsCourierName = jsonData.shippingAddress.logisticsInfo.courierName || "";
|
|
375
|
+
const logisticsPickupPointId = jsonData.shippingAddress.logisticsInfo.pickupPointId || "";
|
|
376
|
+
const logisticsShippingEstimateDate = jsonData.shippingAddress.logisticsInfo.shippingEstimateDate || "";
|
|
377
|
+
const logisticsDeliveryEstimateDateStart = jsonData.shippingAddress.logisticsInfo.deliveryEstimateDateStart || "";
|
|
378
|
+
const logisticsDeliveryEstimateDateEnd = jsonData.shippingAddress.logisticsInfo.deliveryEstimateDateEnd || "";
|
|
379
|
+
|
|
380
|
+
const items = jsonData.items;
|
|
381
|
+
|
|
382
|
+
for (const item of items) {
|
|
383
|
+
const itemSku = item.sku || "";
|
|
384
|
+
const itemEan = item.ean || "";
|
|
385
|
+
const itemName = item.name || "";
|
|
386
|
+
const itemQty = item.quantity || "";
|
|
387
|
+
const itemListPrice = item.listPrice || "";
|
|
388
|
+
const itemPrice = item.price || "";
|
|
389
|
+
const itemSellingPrice = item.sellingPrice || "";
|
|
390
|
+
const itemTotal = item.total || "";
|
|
391
|
+
|
|
392
|
+
const row = [
|
|
393
|
+
orderId,
|
|
394
|
+
status,
|
|
395
|
+
creationDate,
|
|
396
|
+
value,
|
|
397
|
+
totalsItems,
|
|
398
|
+
totalDiscounts,
|
|
399
|
+
totalShipping,
|
|
400
|
+
totalTax,
|
|
401
|
+
clientId,
|
|
402
|
+
clientEmail,
|
|
403
|
+
clientFirstName,
|
|
404
|
+
clientLastName,
|
|
405
|
+
clientDocumentType,
|
|
406
|
+
clientDocument,
|
|
407
|
+
clientPhone,
|
|
408
|
+
clientCorporateName,
|
|
409
|
+
clientCorporateDocument,
|
|
410
|
+
clientTradeName,
|
|
411
|
+
clientCustomerClass,
|
|
412
|
+
clientAddressStreet,
|
|
413
|
+
clientAddressNumber,
|
|
414
|
+
clientAddressComplement,
|
|
415
|
+
clientAddressReference,
|
|
416
|
+
clientAddressPostalCode,
|
|
417
|
+
clientAddressNeighborhood,
|
|
418
|
+
clientAddressCity,
|
|
419
|
+
clientAddressState,
|
|
420
|
+
clientAddressCountry,
|
|
421
|
+
clientAddressLatitude,
|
|
422
|
+
clientAddressLongitude,
|
|
423
|
+
logisticsDeliveryChannel,
|
|
424
|
+
logisticsSla,
|
|
425
|
+
logisticsCourierId,
|
|
426
|
+
logisticsCourierName,
|
|
427
|
+
logisticsPickupPointId,
|
|
428
|
+
logisticsShippingEstimateDate,
|
|
429
|
+
logisticsDeliveryEstimateDateStart,
|
|
430
|
+
logisticsDeliveryEstimateDateEnd,
|
|
431
|
+
itemSku,
|
|
432
|
+
itemEan,
|
|
433
|
+
itemName,
|
|
434
|
+
itemQty,
|
|
435
|
+
itemListPrice,
|
|
436
|
+
itemPrice,
|
|
437
|
+
itemSellingPrice,
|
|
438
|
+
itemTotal,
|
|
439
|
+
];
|
|
440
|
+
|
|
441
|
+
csvData.push(row);
|
|
442
|
+
}
|
|
443
|
+
return { csvHeaders, csvData };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
module.exports = {
|
|
447
|
+
orderToJson,
|
|
448
|
+
convertJsonOrderToCsv,
|
|
449
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const AUTHORIZATION_BASE_URL = process.env.AUTHORIZATION_BASE_URL;
|
|
3
|
+
|
|
4
|
+
class AuthSecurity {
|
|
5
|
+
|
|
6
|
+
constructor(username, password, grantType, scope) {
|
|
7
|
+
if (!username || !password || !grantType || !scope) {
|
|
8
|
+
throw new Error("Invalid Authentication Credentials");
|
|
9
|
+
}
|
|
10
|
+
this.username = username;
|
|
11
|
+
this.password = password;
|
|
12
|
+
this.grantType = grantType;
|
|
13
|
+
this.scope = scope;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Excute a request authentication to Cognito
|
|
18
|
+
* @param {string} url
|
|
19
|
+
* @param {import("axios").AxiosRequestConfig} options
|
|
20
|
+
* @returns {Promise<import("axios").AxiosResponse>}
|
|
21
|
+
*/
|
|
22
|
+
fetchAuthToken(url, options) {
|
|
23
|
+
const params =
|
|
24
|
+
{
|
|
25
|
+
url: `${AUTHORIZATION_BASE_URL}${url}`,
|
|
26
|
+
...options,
|
|
27
|
+
auth: {
|
|
28
|
+
username: this.username,
|
|
29
|
+
password: this.password
|
|
30
|
+
},
|
|
31
|
+
headers: {
|
|
32
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
33
|
+
...options.headers,
|
|
34
|
+
},
|
|
35
|
+
data: {
|
|
36
|
+
"grant_type": this.grantType,
|
|
37
|
+
"scope": this.scope
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return axios.request(params);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = AuthSecurity;
|