dcos-core-monalisav2-latam 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/functions/clients_peru/updateClients.js +1 -1
- package/src/functions/multiPresentation/multipres.js +2 -1
- package/src/functions/orders/orders-status-producer.js +1 -1
- package/src/functions/security/security-handler.js +27 -27
- package/src/functions/utils/index.js +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dcos-core-monalisav2-latam",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
},
|
|
6
6
|
"scripts": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"csv": "^6.3.0",
|
|
31
31
|
"csv-parser": "^3.0.0",
|
|
32
32
|
"csvtojson": "^2.0.10",
|
|
33
|
+
"dcos-sls-auth-app": "^1.0.1",
|
|
33
34
|
"dotenv": "^10.0.0",
|
|
34
35
|
"ftp": "^0.3.10",
|
|
35
36
|
"json-2-csv": "^5.5.1",
|
|
@@ -45,7 +45,7 @@ module.exports.consumer = async (event, context) => {
|
|
|
45
45
|
try {
|
|
46
46
|
let { body } = event;
|
|
47
47
|
body = JSON.parse(body);
|
|
48
|
-
|
|
48
|
+
return this.handleConsumer(ACCOUNTNAME, { process: processName, params: body });
|
|
49
49
|
} catch (ex) {
|
|
50
50
|
return ApiResponse.response(400, ex.message ?? 'Error in request');
|
|
51
51
|
}
|
|
@@ -423,6 +423,7 @@ const producer = async (event) => {
|
|
|
423
423
|
let statusCode = 200;
|
|
424
424
|
let message;
|
|
425
425
|
|
|
426
|
+
Logger.log('Context', event?.requestContext);
|
|
426
427
|
try {
|
|
427
428
|
const clientId = event?.requestContext?.authorizer?.claims?.client_id;
|
|
428
429
|
const scope = event?.requestContext?.authorizer?.claims?.scope;
|
|
@@ -431,7 +432,7 @@ const producer = async (event) => {
|
|
|
431
432
|
if (!accountName) {
|
|
432
433
|
return errorResponse(404, "AccountName not found");
|
|
433
434
|
}
|
|
434
|
-
if (!scope
|
|
435
|
+
if (scope && !scope?.includes("admin")) {
|
|
435
436
|
const validateAccount = await ClientData.validateAccount(clientId, accountName);
|
|
436
437
|
if (!validateAccount) {
|
|
437
438
|
Logger.error("Account not found: ", accountName, ". ClientId: ", clientId);
|
|
@@ -324,7 +324,7 @@ const validDocuments = async ({ event = null, orderClientVtexResponse = null })
|
|
|
324
324
|
const validReturnedItems = async (request, orderClientVtexResponse) => {
|
|
325
325
|
const { invoiceValue, returnItems } = request.documents;
|
|
326
326
|
|
|
327
|
-
if (returnItems
|
|
327
|
+
if (returnItems?.length == 0) {
|
|
328
328
|
return [`Return items must have at least one item`];
|
|
329
329
|
}
|
|
330
330
|
|
|
@@ -22,7 +22,7 @@ const producer = async (event) => {
|
|
|
22
22
|
try {
|
|
23
23
|
// Determinar el tipo de operación basado en la ruta
|
|
24
24
|
const operationType = getOperationType(event);
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
// Conexión a la API de Secret Manager
|
|
27
27
|
const configAuth = await AWSServices.getSecretValue(MANAGER_STORE_KEYS);
|
|
28
28
|
const auth = JSON.parse(configAuth);
|
|
@@ -265,19 +265,19 @@ function validateSenderAuthorizationAdmin(email, authorizedUsers, isAvailable) {
|
|
|
265
265
|
function getFormData(event, availableExtensions) {
|
|
266
266
|
const formData = parse(event, true);
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
'
|
|
272
|
-
'
|
|
268
|
+
const { email, file } = formData;
|
|
269
|
+
const { type, filename, contentType } = file;
|
|
270
|
+
let errors = validate({ email, type, filename, contentType }, {
|
|
271
|
+
'email': { presence: { allowEmpty: true }, email: true },
|
|
272
|
+
'type': { presence: { allowEmpty: false } },
|
|
273
|
+
'filename': { presence: { allowEmpty: false } },
|
|
274
|
+
'contentType': {
|
|
273
275
|
presence: { allowEmpty: false },
|
|
274
276
|
inclusion: {
|
|
275
277
|
within: availableExtensions,
|
|
276
278
|
message: `^El archivo debe tener una extensión .csv o .txt. Verifique el formato de su archivo e inténtelo nuevamente.`
|
|
277
279
|
}
|
|
278
|
-
}
|
|
279
|
-
'file.content': { presence: { allowEmpty: false } },
|
|
280
|
-
'email': { presence: { allowEmpty: true }, email: true }
|
|
280
|
+
}
|
|
281
281
|
});
|
|
282
282
|
|
|
283
283
|
if (errors) {
|
|
@@ -312,18 +312,18 @@ async function getSecretDataAccount(auth) {
|
|
|
312
312
|
throw new Error(`Information from SM API not defined`);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
const {
|
|
316
|
-
isAvailable = false,
|
|
317
|
-
authorizedUsers = {},
|
|
318
|
-
availableExtensions = ['text/csv', 'text/plain'],
|
|
319
|
-
accounts = []
|
|
315
|
+
const {
|
|
316
|
+
isAvailable = false,
|
|
317
|
+
authorizedUsers = {},
|
|
318
|
+
availableExtensions = ['text/csv', 'text/plain'],
|
|
319
|
+
accounts = []
|
|
320
320
|
} = smData[0].value;
|
|
321
321
|
|
|
322
322
|
// 1. Procesar cuentas: Mantener como ARRAY para usar .some()
|
|
323
323
|
const accountsData = accounts
|
|
324
|
-
.filter(account =>
|
|
325
|
-
account.accountName &&
|
|
326
|
-
account.vtexAppkey &&
|
|
324
|
+
.filter(account =>
|
|
325
|
+
account.accountName &&
|
|
326
|
+
account.vtexAppkey &&
|
|
327
327
|
account.vtexAppToken
|
|
328
328
|
);
|
|
329
329
|
|
|
@@ -331,7 +331,7 @@ async function getSecretDataAccount(auth) {
|
|
|
331
331
|
Object.keys(authorizedUsers).forEach(email => {
|
|
332
332
|
const hasWildcard = authorizedUsers[email].hasOwnProperty('*');
|
|
333
333
|
const { '*': wildcardUser, ...remainPerms } = authorizedUsers[email];
|
|
334
|
-
|
|
334
|
+
|
|
335
335
|
Object.keys(remainPerms).forEach(account => {
|
|
336
336
|
if (remainPerms[account] === (hasWildcard ? wildcardUser : isAvailable)) {
|
|
337
337
|
delete authorizedUsers[email][account];
|
|
@@ -339,11 +339,11 @@ async function getSecretDataAccount(auth) {
|
|
|
339
339
|
});
|
|
340
340
|
});
|
|
341
341
|
|
|
342
|
-
return {
|
|
342
|
+
return {
|
|
343
343
|
accountsData, // Ahora es un array filtrado y mapeado
|
|
344
|
-
isAvailable,
|
|
345
|
-
authorizedUsers,
|
|
346
|
-
availableExtensions
|
|
344
|
+
isAvailable,
|
|
345
|
+
authorizedUsers,
|
|
346
|
+
availableExtensions
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
349
|
|
|
@@ -413,14 +413,14 @@ async function processAccountsCsv(fileData, accountsData, auth) {
|
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
const csvRows = csvDataString.trim().split(/\r?\n/);
|
|
416
|
-
|
|
416
|
+
|
|
417
417
|
// 2. Validación de headers
|
|
418
418
|
if (csvRows.length === 0) {
|
|
419
419
|
throw new Error("El archivo no contiene datos");
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
const headerRow = csvRows.shift();
|
|
423
|
-
|
|
423
|
+
|
|
424
424
|
// 3. Validación de existencia de headers
|
|
425
425
|
if (!headerRow) {
|
|
426
426
|
throw new Error("El archivo no contiene encabezados. Debe incluir la primera línea con los nombres de columna.");
|
|
@@ -435,7 +435,7 @@ async function processAccountsCsv(fileData, accountsData, auth) {
|
|
|
435
435
|
const headers = headerRow.split(';').map(h => h.trim().toLowerCase());
|
|
436
436
|
const expectedHeaders = ['action', 'accountname', 'appkey', 'apptoken'];
|
|
437
437
|
const missingHeaders = expectedHeaders.filter(h => !headers.includes(h));
|
|
438
|
-
|
|
438
|
+
|
|
439
439
|
if (missingHeaders.length > 0) {
|
|
440
440
|
throw new Error(`Encabezados incorrectos. Faltan: ${missingHeaders.join(', ')}. Formato esperado: ACTION;ACCOUNTNAME;APPKEY;APPTOKEN`);
|
|
441
441
|
}
|
|
@@ -448,7 +448,7 @@ async function processAccountsCsv(fileData, accountsData, auth) {
|
|
|
448
448
|
|
|
449
449
|
// Obtener configuración actual del Secret Manager
|
|
450
450
|
const { currentConfig, secretManagerApi } = await getCurrentSecretManagerConfig(auth);
|
|
451
|
-
|
|
451
|
+
|
|
452
452
|
if (!Array.isArray(currentConfig.value.accounts)) {
|
|
453
453
|
currentConfig.value.accounts = [];
|
|
454
454
|
}
|
|
@@ -463,7 +463,7 @@ async function processAccountsCsv(fileData, accountsData, auth) {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
const rowData = row.split(';');
|
|
466
|
-
|
|
466
|
+
|
|
467
467
|
// 6. Validación de campos vacíos
|
|
468
468
|
const action = (rowData[columnIndices.action]?.trim() || 'add').toLowerCase();
|
|
469
469
|
const accountName = rowData[columnIndices.accountname]?.trim();
|
|
@@ -50,7 +50,7 @@ module.exports.handler = async (req, res) => {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
break;
|
|
53
|
-
|
|
53
|
+
// route notification new leads
|
|
54
54
|
case "/new-leads/notification/{an}":
|
|
55
55
|
switch (method) {
|
|
56
56
|
case "POST":
|
|
@@ -96,7 +96,7 @@ module.exports.handler = async (req, res) => {
|
|
|
96
96
|
}
|
|
97
97
|
break;
|
|
98
98
|
case "/errors/{errorCode}":
|
|
99
|
-
|
|
99
|
+
return await AccountErrorsHandler.handler(req, res);
|
|
100
100
|
break;
|
|
101
101
|
case "/accounts/properties":
|
|
102
102
|
case "/accounts/properties/required":
|
|
@@ -104,15 +104,15 @@ module.exports.handler = async (req, res) => {
|
|
|
104
104
|
break;
|
|
105
105
|
// Multi presentations INIT
|
|
106
106
|
case "/multipresentation/{accountName}":
|
|
107
|
-
|
|
107
|
+
return await multiPresentation?.producer(req, res);
|
|
108
108
|
break;
|
|
109
109
|
// Multi presentations END
|
|
110
110
|
// Roles Security INIT
|
|
111
111
|
case "/batch/users":
|
|
112
|
-
|
|
112
|
+
return await securityHandler?.producer(req, res);
|
|
113
113
|
break;
|
|
114
114
|
case "/batch/accounts":
|
|
115
|
-
|
|
115
|
+
return await securityHandler?.producer(req, res);
|
|
116
116
|
break;
|
|
117
117
|
// Roles Security END
|
|
118
118
|
default:
|