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,122 @@
|
|
|
1
|
+
const { validateFile } = require('../processes/validateFileSchema')
|
|
2
|
+
const AWS = require('aws-sdk')
|
|
3
|
+
const dynamoDB = new AWS.DynamoDB.DocumentClient()
|
|
4
|
+
|
|
5
|
+
// Mock de DynamoDB
|
|
6
|
+
jest.mock('aws-sdk', () => {
|
|
7
|
+
const mDocumentClient = { get: jest.fn() }
|
|
8
|
+
return {
|
|
9
|
+
DynamoDB: {
|
|
10
|
+
DocumentClient: jest.fn(() => mDocumentClient),
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('validateFile', () => {
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.clearAllMocks()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// test case
|
|
22
|
+
it('deberia validar correctamente un archivo CSV', async () => {
|
|
23
|
+
const schemaData = {
|
|
24
|
+
Item: {
|
|
25
|
+
SchemaId: 'test-schema',
|
|
26
|
+
StartName: 'test',
|
|
27
|
+
Ext: 'csv',
|
|
28
|
+
Separator: ',',
|
|
29
|
+
Schema: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
name: { type: 'string', pattern: '^[a-zA-Z]+$', },
|
|
33
|
+
age: { type: 'number', pattern: '^[0-9]+$' },
|
|
34
|
+
},
|
|
35
|
+
required: ["name", "age"]
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
dynamoDB.get.mockReturnValue({
|
|
40
|
+
promise: jest.fn().mockResolvedValue(schemaData),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// Archivo CSV simulado
|
|
44
|
+
const file = {
|
|
45
|
+
filename: 'test_file.csv',
|
|
46
|
+
content: `name,age\nJohn,25\nJane,30`,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const result = await validateFile(file, 'test-schema')
|
|
50
|
+
|
|
51
|
+
expect(result.valid).toBe(true)
|
|
52
|
+
expect(result.errors).toEqual([])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// test case
|
|
56
|
+
it('deberia devolver error si el archivo JSON tiene un campo faltante', async () => {
|
|
57
|
+
const schemaData = {
|
|
58
|
+
Item: {
|
|
59
|
+
SchemaId: 'test-schema',
|
|
60
|
+
StartName: 'test',
|
|
61
|
+
Ext: 'json',
|
|
62
|
+
Schema: {
|
|
63
|
+
properties: {
|
|
64
|
+
name: { type: 'string', pattern: '^[a-zA-Z]+$' },
|
|
65
|
+
age: { type: 'number', pattern: '^[0-9]+$' },
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
dynamoDB.get.mockReturnValue({
|
|
71
|
+
promise: jest.fn().mockResolvedValue(schemaData),
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const file = {
|
|
75
|
+
filename: 'test_file.json',
|
|
76
|
+
content: JSON.stringify([{ name: "John" }]),
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const result = await validateFile(file, 'test-schema')
|
|
80
|
+
|
|
81
|
+
expect(result.valid).toBe(false)
|
|
82
|
+
expect(result.errors).toContain("El campo age es requerido")
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// test case
|
|
86
|
+
it('debería devolver error si el archivo XML no cumple con el esquema', async () => {
|
|
87
|
+
|
|
88
|
+
const schemaData = {
|
|
89
|
+
Item: {
|
|
90
|
+
SchemaId: 'test-schema',
|
|
91
|
+
StartName: 'test',
|
|
92
|
+
Ext: 'xml',
|
|
93
|
+
Schema: {
|
|
94
|
+
properties: {
|
|
95
|
+
name: { type: 'string', pattern: '^[a-zA-Z]+$' },
|
|
96
|
+
age: { type: 'number', pattern: '^[0-9]+$' }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
dynamoDB.get.mockReturnValue({
|
|
103
|
+
promise: jest.fn().mockResolvedValue(schemaData),
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const file = {
|
|
107
|
+
filename: 'test_file.xml',
|
|
108
|
+
content: `
|
|
109
|
+
<root>
|
|
110
|
+
<item>
|
|
111
|
+
<name>John</name>
|
|
112
|
+
</item>
|
|
113
|
+
</root>
|
|
114
|
+
`,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const result = await validateFile(file, 'test-schema')
|
|
118
|
+
|
|
119
|
+
expect(result.valid).toBe(false)
|
|
120
|
+
expect(result.errors).toContain("El campo age es requerido")
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const AWS = require('aws-sdk');
|
|
2
|
+
const Logger = require("../../../common/utils/logger");
|
|
3
|
+
|
|
4
|
+
class DynamoDBConnector {
|
|
5
|
+
constructor(tableName) {
|
|
6
|
+
this.dynamoDB = new AWS.DynamoDB.DocumentClient();
|
|
7
|
+
this.tableName = tableName;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async getItem(key) {
|
|
11
|
+
const params = {
|
|
12
|
+
TableName: this.tableName,
|
|
13
|
+
Key: key,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const data = await this.dynamoDB.get(params).promise();
|
|
18
|
+
if (!data.Item) {
|
|
19
|
+
throw new Error(`No se encontró el elemento con la clave: ${JSON.stringify(key)}`);
|
|
20
|
+
}
|
|
21
|
+
return data.Item;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
Logger.error('Error al obtener el elemento de DynamoDB:', error.message);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = DynamoDBConnector;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function splitData(data) {
|
|
2
|
+
const documents = data.map((item) => ({
|
|
3
|
+
orderId: item.orderId,
|
|
4
|
+
documentsType: item.documentsType,
|
|
5
|
+
documentsIssuanceDate: item.documentsIssuanceDate,
|
|
6
|
+
documentsInvoiceNumber: item.documentsInvoiceNumber,
|
|
7
|
+
documentsInvoiceValue: item.documentsInvoiceValue,
|
|
8
|
+
documentsInvoiceUrl: item.documentsInvoiceUrl
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const changes = data.map((item) => ({
|
|
12
|
+
orderId: item.orderId,
|
|
13
|
+
changesReason: item.changesReason,
|
|
14
|
+
changesDiscountValue: item.changesDiscountValue,
|
|
15
|
+
changesItemsRemoved: item.changesItemsRemoved
|
|
16
|
+
.split('|')
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.map((change) => {
|
|
19
|
+
const [sku, price, quantity] = change.split(',');
|
|
20
|
+
return { sku, price: Number(price), quantity: Number(quantity) };
|
|
21
|
+
})
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
return { documents, changes };
|
|
25
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const ApiResponse = require("../../common/utils/api-response");
|
|
2
|
+
const clientsAudience = require("../clients/clients-audience");
|
|
3
|
+
const downloadleadshandler = require("../notifications/download-leads-handler");
|
|
4
|
+
const newleadsnotificationhandler = require("../notifications/new-leads-notification-handler");
|
|
5
|
+
const catalogSyncHandler = require("../inventory/catalog-sync-handler");
|
|
6
|
+
const clients = require("../account/clients");
|
|
7
|
+
const promotionNotificationHandler = require("../notifications/promotion-notification-handler");
|
|
8
|
+
const vtexHookHandler = require("../../common/utils/vtex-hook-handler");
|
|
9
|
+
const AccountErrorsHandler = require("../../common/utils/account-error-handler");
|
|
10
|
+
const AccountPropertiesHandler = require("../../common/utils/account-properties-handler");
|
|
11
|
+
const multiPresentation = require("../multiPresentation/multipres");
|
|
12
|
+
const securityHandler = require("../security/security-handler");
|
|
13
|
+
const Logger = require("../../common/utils/logger");
|
|
14
|
+
|
|
15
|
+
module.exports.handler = async (req, res) => {
|
|
16
|
+
const resource = req?.resource ?? null;
|
|
17
|
+
const method = req?.httpMethod ? String(req?.httpMethod).toUpperCase() : null;
|
|
18
|
+
|
|
19
|
+
if (resource && method) {
|
|
20
|
+
switch (resource) {
|
|
21
|
+
case "/audience/get":
|
|
22
|
+
switch (method) {
|
|
23
|
+
case "GET":
|
|
24
|
+
return await clientsAudience?.handler(req, res);
|
|
25
|
+
default:
|
|
26
|
+
Logger.error("error method!.");
|
|
27
|
+
return ApiResponse.response(400, {
|
|
28
|
+
error: "error method!."
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
case "/distributors/get/accounts":
|
|
33
|
+
switch (method) {
|
|
34
|
+
case "GET":
|
|
35
|
+
return await clients?.handler(req, res);
|
|
36
|
+
default:
|
|
37
|
+
return ApiResponse.response(400, {
|
|
38
|
+
error: "error method!."
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case "/orders/notify_promotion":
|
|
43
|
+
switch (method) {
|
|
44
|
+
case "POST":
|
|
45
|
+
return await promotionNotificationHandler?.handler(req, res);
|
|
46
|
+
default:
|
|
47
|
+
Logger.error("error method!.");
|
|
48
|
+
return ApiResponse.response(400, {
|
|
49
|
+
error: "error method!."
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
// route notification new leads
|
|
54
|
+
case "/new-leads/notification/{an}":
|
|
55
|
+
switch (method) {
|
|
56
|
+
case "POST":
|
|
57
|
+
return await newleadsnotificationhandler?.handler(req, res);
|
|
58
|
+
default:
|
|
59
|
+
Logger.error("error method!.");
|
|
60
|
+
return ApiResponse.response(400, {
|
|
61
|
+
error: "error method!."
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case "/new-leads/download":
|
|
66
|
+
switch (method) {
|
|
67
|
+
case "GET":
|
|
68
|
+
return await downloadleadshandler?.handler(req, res);
|
|
69
|
+
default:
|
|
70
|
+
Logger.error("error method!.");
|
|
71
|
+
return ApiResponse.response(400, {
|
|
72
|
+
error: "error method!."
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case "/catalog/sync/{accountName}":
|
|
77
|
+
switch (method) {
|
|
78
|
+
case "POST":
|
|
79
|
+
return await catalogSyncHandler.handler(req, res);
|
|
80
|
+
default:
|
|
81
|
+
Logger.error("error method!.");
|
|
82
|
+
return ApiResponse.response(400, {
|
|
83
|
+
error: "error method!."
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case "/vtex/hook/{accountName}":
|
|
88
|
+
switch (method) {
|
|
89
|
+
case "GET":
|
|
90
|
+
return await vtexHookHandler?.handler(req, res);
|
|
91
|
+
default:
|
|
92
|
+
Logger.error("error method!.");
|
|
93
|
+
return ApiResponse.response(400, {
|
|
94
|
+
error: "error method!."
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
case "/errors/{errorCode}":
|
|
99
|
+
return await AccountErrorsHandler.handler(req, res);
|
|
100
|
+
break;
|
|
101
|
+
case "/accounts/properties":
|
|
102
|
+
case "/accounts/properties/required":
|
|
103
|
+
return await AccountPropertiesHandler.handler(req, res);
|
|
104
|
+
break;
|
|
105
|
+
// Multi presentations INIT
|
|
106
|
+
case "/multipresentation/{accountName}":
|
|
107
|
+
return await multiPresentation?.producer(req, res);
|
|
108
|
+
break;
|
|
109
|
+
// Multi presentations END
|
|
110
|
+
// Roles Security INIT
|
|
111
|
+
case "/batch/users":
|
|
112
|
+
return await securityHandler?.producer(req, res);
|
|
113
|
+
break;
|
|
114
|
+
case "/batch/accounts":
|
|
115
|
+
return await securityHandler?.producer(req, res);
|
|
116
|
+
break;
|
|
117
|
+
// Roles Security END
|
|
118
|
+
default:
|
|
119
|
+
Logger.error("error resource!.");
|
|
120
|
+
return ApiResponse.response(400, {
|
|
121
|
+
error: "error resource!."
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
Logger.error("error resource!.");
|
|
126
|
+
return ApiResponse.response(400, {
|
|
127
|
+
error: "error resource!."
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|