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.
Files changed (129) hide show
  1. package/README.md +130 -0
  2. package/index.js +350 -0
  3. package/package.json +52 -0
  4. package/src/auth/handler.js +3 -0
  5. package/src/common/MondelezCastOrder.js +449 -0
  6. package/src/common/utils/AuthSecurity.js +46 -0
  7. package/src/common/utils/account-error-handler.js +279 -0
  8. package/src/common/utils/account-error-helper.js +231 -0
  9. package/src/common/utils/account-properties-handler.js +355 -0
  10. package/src/common/utils/api-response.js +62 -0
  11. package/src/common/utils/aws-services.js +186 -0
  12. package/src/common/utils/constants/account-error-codes.json +801 -0
  13. package/src/common/utils/constants.js +37 -0
  14. package/src/common/utils/convert/MondelezClientsItemsCast.js +52 -0
  15. package/src/common/utils/convert/MondelezInventoryItemsCast.js +15 -0
  16. package/src/common/utils/convert/MondelezOrderStatusCast.js +34 -0
  17. package/src/common/utils/convert/MondelezPricesItemsCast.js +37 -0
  18. package/src/common/utils/cron-ftp-get.js +143 -0
  19. package/src/common/utils/data-tables-helper.js +213 -0
  20. package/src/common/utils/date-range-calculator.js +113 -0
  21. package/src/common/utils/delay.js +17 -0
  22. package/src/common/utils/ftp-sftp.js +320 -0
  23. package/src/common/utils/logger.js +126 -0
  24. package/src/common/utils/nodemailerLib.js +61 -0
  25. package/src/common/utils/product-unit-converter.js +168 -0
  26. package/src/common/utils/schemas-utils.js +101 -0
  27. package/src/common/utils/seller-email-sharing-service.js +441 -0
  28. package/src/common/utils/sftp-utils.js +202 -0
  29. package/src/common/utils/status.js +15 -0
  30. package/src/common/utils/util.js +236 -0
  31. package/src/common/utils/validate-state-order.js +35 -0
  32. package/src/common/utils/validateProviders.js +67 -0
  33. package/src/common/utils/validation-data.js +45 -0
  34. package/src/common/utils/vtex/save-hooks.js +65 -0
  35. package/src/common/utils/vtex/save-schemas.js +65 -0
  36. package/src/common/utils/vtex-hook-handler.js +71 -0
  37. package/src/common/validation/AccountCoordinatesValidation.js +350 -0
  38. package/src/common/validation/GeneralErrorValidation.js +11 -0
  39. package/src/common/validation/MainErrorValidation.js +8 -0
  40. package/src/entities/account.js +639 -0
  41. package/src/entities/clients.js +104 -0
  42. package/src/entities/controlprice.js +196 -0
  43. package/src/entities/controlstock.js +206 -0
  44. package/src/entities/cron.js +77 -0
  45. package/src/entities/cronjob.js +71 -0
  46. package/src/entities/orders.js +195 -0
  47. package/src/entities/sftp-inbound.js +88 -0
  48. package/src/entities/sku.js +220 -0
  49. package/src/entities/taxpromotion.js +249 -0
  50. package/src/functions/account/account-get.js +262 -0
  51. package/src/functions/account/account-handler.js +299 -0
  52. package/src/functions/account/clients.js +10 -0
  53. package/src/functions/account/index.js +208 -0
  54. package/src/functions/actions/save-promotions-order-history.js +324 -0
  55. package/src/functions/affiliates/affiliates-hook-consumer.js +87 -0
  56. package/src/functions/affiliates/affiliates-hook-producer.js +45 -0
  57. package/src/functions/clients/clients-audience.js +62 -0
  58. package/src/functions/clients/clients-consumer.js +648 -0
  59. package/src/functions/clients/clients-producer.js +362 -0
  60. package/src/functions/clients/clients-suggested-product-consumer.js +166 -0
  61. package/src/functions/clients/helpers/suggested-product-mdlz.js +233 -0
  62. package/src/functions/clients_peru/email.html +129 -0
  63. package/src/functions/clients_peru/splitfile.js +357 -0
  64. package/src/functions/clients_peru/updateClients.js +1334 -0
  65. package/src/functions/clients_peru/utils.js +243 -0
  66. package/src/functions/cronjobs/cron-jobs-manager.js +40 -0
  67. package/src/functions/cronjobs/cron-jobs.js +171 -0
  68. package/src/functions/crons/cron.js +39 -0
  69. package/src/functions/distributors/distributor-handler.js +81 -0
  70. package/src/functions/distributors/distributor.js +535 -0
  71. package/src/functions/distributors/index.js +60 -0
  72. package/src/functions/financialpolicy/assign-financialpolicy.js +111 -0
  73. package/src/functions/financialpolicy/get-financialpolicy.js +91 -0
  74. package/src/functions/financialpolicy/index.js +28 -0
  75. package/src/functions/inventory/catalog-sync-consumer.js +17 -0
  76. package/src/functions/inventory/catalog-sync-handler.js +311 -0
  77. package/src/functions/inventory/inventory-consumer.js +119 -0
  78. package/src/functions/inventory/inventory-producer.js +197 -0
  79. package/src/functions/multiPresentation/multipre-queue.js +155 -0
  80. package/src/functions/multiPresentation/multipres.js +459 -0
  81. package/src/functions/nodeflow/index.js +83 -0
  82. package/src/functions/nodeflow/nodeflow-cron.js +200 -0
  83. package/src/functions/nodeflow/nodeflow-pub.js +203 -0
  84. package/src/functions/nodeflow/nodeflow-pvt.js +266 -0
  85. package/src/functions/notifications/download-leads-handler.js +67 -0
  86. package/src/functions/notifications/new-leads-notification-consumer.js +17 -0
  87. package/src/functions/notifications/new-leads-notification-handler.js +359 -0
  88. package/src/functions/notifications/order-status-notification-handler.js +482 -0
  89. package/src/functions/notifications/promotion-notification-handler.js +193 -0
  90. package/src/functions/orders/index.js +32 -0
  91. package/src/functions/orders/orders-cancel-handler.js +74 -0
  92. package/src/functions/orders/orders-handler.js +280 -0
  93. package/src/functions/orders/orders-hook-consumer.js +137 -0
  94. package/src/functions/orders/orders-hook-producer.js +170 -0
  95. package/src/functions/orders/orders-notifications-handler.js +137 -0
  96. package/src/functions/orders/orders-status-consumer.js +461 -0
  97. package/src/functions/orders/orders-status-producer.js +443 -0
  98. package/src/functions/prices/index.js +75 -0
  99. package/src/functions/prices/prices-consumer.js +236 -0
  100. package/src/functions/prices/prices-producer.js +323 -0
  101. package/src/functions/prices/promotion-and-tax.js +1284 -0
  102. package/src/functions/routesflow/assign-routeflow-queue.js +77 -0
  103. package/src/functions/schemas/vtex/handle-schemas.js +102 -0
  104. package/src/functions/security/process_gas.js +221 -0
  105. package/src/functions/security/security-handler.js +950 -0
  106. package/src/functions/sftp/sftp-consumer.js +453 -0
  107. package/src/functions/sftpIntegrations/processes/redirectServices.js +184 -0
  108. package/src/functions/sftpIntegrations/processes/validateFileSchema.js +226 -0
  109. package/src/functions/sftpIntegrations/schemas/credential-schema.js +123 -0
  110. package/src/functions/sftpIntegrations/schemas/record-schema.js +131 -0
  111. package/src/functions/sftpIntegrations/schemas/sftp_required_fields.json +3 -0
  112. package/src/functions/sftpIntegrations/sftp-config-producer.js +112 -0
  113. package/src/functions/sftpIntegrations/sftp-consumer.js +700 -0
  114. package/src/functions/sftpIntegrations/test/validateFile.test.js +122 -0
  115. package/src/functions/sftpIntegrations/utils/connect-dynamo.js +29 -0
  116. package/src/functions/sftpIntegrations/utils/split-data.js +25 -0
  117. package/src/functions/utils/index.js +130 -0
  118. package/src/functions/vtex/vtex-helpers.js +694 -0
  119. package/src/integrations/accountErrors/AccountErrorManager.js +437 -0
  120. package/src/integrations/audience/Audience.js +70 -0
  121. package/src/integrations/financialPolicy/FinancialPolicyApi.js +377 -0
  122. package/src/integrations/index.js +0 -0
  123. package/src/integrations/mobilvendor/MobilvendorApi.js +405 -0
  124. package/src/integrations/productmultipresentation/ProductMultiPresentation.js +200 -0
  125. package/src/mdlz/auth/SecretManagerApi.js +77 -0
  126. package/src/mdlz/client/MdlzApi.js +70 -0
  127. package/src/vtex/clients/ProvidersApi.js +51 -0
  128. package/src/vtex/clients/VtexApi.js +511 -0
  129. package/src/vtex/models/VtexOrder.js +87 -0
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+
3
+ const ClientsData = require("../../entities/clients");
4
+ const AccountData = require("../../entities/account");
5
+ const ApiResponse = require("../../common/utils/api-response");
6
+ const SftpInbound = require("../../entities/sftp-inbound");
7
+ const Validation = require("../../common/utils/validation-data");
8
+ const Constants = require("../../common/utils/constants");
9
+ const { handleGetRecordSchema } = require('../../common/utils/schemas-utils')
10
+ const { handleSchemaVtexMD2 } = require('../../common/utils/vtex/save-schemas.js')
11
+ const { handleHookVtexMD2 } = require('../../common/utils/vtex/save-hooks.js')
12
+ const { SCHEMAS_VTEX_TABLE, HOOKS_VTEX_TABLE } = process?.env ?? {};
13
+ const Logger = require("../../common/utils/logger");
14
+ const AccountCoordinatesValidation = require("../../common/validation/AccountCoordinatesValidation.js");
15
+ const SellerEmailSharingService = require("../../common/utils/seller-email-sharing-service.js");
16
+ const AccountErrors = require("../../common/utils/account-error-helper.js"); // Importar helper de errores
17
+
18
+ /**
19
+ * @param {import("aws-lambda")} event
20
+ */
21
+ const create = async (event) => {
22
+ try {
23
+ let message = "Client and Account created successfully";
24
+ Logger.log("Event: ", event);
25
+ if (!event.body) {
26
+ return await AccountErrors.createError('ACCOUNT_001'); // CAMBIO
27
+ }
28
+ const body = JSON.parse(event.body);
29
+ const { ClientId, AccountName } = body;
30
+ if (!AccountName || AccountName === "") {
31
+ return await AccountErrors.createError('ACCOUNT_002'); // CAMBIO
32
+ }
33
+ if (ClientId && ClientId !== "" && typeof ClientId == 'string') {
34
+ let client = await ClientsData.addClient(ClientId, AccountName);
35
+ if (!client) {
36
+ return await AccountErrors.createError('ACCOUNT_003'); // CAMBIO
37
+ }
38
+ } else if (ClientId && ClientId !== "" && typeof ClientId == 'object') {
39
+ for (var i = 0; i < ClientId.length; i++) {
40
+ let client = await ClientsData.addClient(ClientId[i], AccountName);
41
+ if (!client) {
42
+ return await AccountErrors.createError('ACCOUNT_003'); // CAMBIO
43
+ }
44
+ }
45
+ } else {
46
+ message = "Only the account was created";
47
+ }
48
+ const account = await AccountData.addAccountDataConfig(body);
49
+ if (!account) {
50
+ return await AccountErrors.createError('ACCOUNT_004'); // CAMBIO
51
+ }
52
+
53
+ // Validación de AllowEmailSharing
54
+ const hasSavePriceAudience = body.SavePriceAudience === true;
55
+ const hasSavePriceTableCLWL = body.SavePriceTableCLWL === true;
56
+
57
+ if (hasSavePriceAudience || hasSavePriceTableCLWL) {
58
+ Logger.debug("Account requires AllowEmailSharing validation");
59
+ const sellerEmailSharingService = new SellerEmailSharingService();
60
+ const validationResult = await sellerEmailSharingService.validateBeforeAccountCreation(body);
61
+ if (!validationResult.success) {
62
+ if (validationResult.message.includes('ParentAccountName is required')) {
63
+ return await AccountErrors.createError('ACCOUNT_011'); // CAMBIO
64
+ } else if (validationResult.message.includes('Parent account configuration not found')) {
65
+ return await AccountErrors.createError('ACCOUNT_012', { ParentAccountName: body.ParentAccountName }); // CAMBIO
66
+ } else if (validationResult.message.includes('VTEX credentials not found')) {
67
+ return await AccountErrors.createError('ACCOUNT_013', { ParentAccountName: body.ParentAccountName }); // CAMBIO
68
+ } else if (validationResult.message.includes('Seller not found')) {
69
+ return await AccountErrors.createError('ACCOUNT_014', { SellerId: body.SellerId || body.AccountName }); // CAMBIO
70
+ } else {
71
+ return await AccountErrors.createWithLogging('ACCOUNT_026', new Error(validationResult.message)); // CAMBIO
72
+ }
73
+ }
74
+ Logger.debug("AllowEmailSharing validation passed");
75
+ } else {
76
+ Logger.debug("Account does not require AllowEmailSharing validation");
77
+ }
78
+ Logger.setAccount(account);
79
+ // Validación de coordenadas geográficas
80
+ if (account.SetGeoCoordinatesGlobal === true || account.SetGeoCoordinatesApp === true) {
81
+ try {
82
+ Logger.debug("Starting coordinates validation for account:", account.AccountName);
83
+ const coordinatesValidation = await AccountCoordinatesValidation.validate(account);
84
+ if (!coordinatesValidation.isValid) {
85
+ const firstError = coordinatesValidation.errors[0] || '';
86
+ if (firstError.includes('CodeCountry')) {
87
+ return await AccountErrors.createError('ACCOUNT_005'); // CAMBIO
88
+ } else if (firstError.includes('Default coordinates are not configured')) {
89
+ return await AccountErrors.createError('ACCOUNT_006'); // CAMBIO
90
+ } else if (firstError.includes('Invalid') && firstError.includes('format')) {
91
+ return await AccountErrors.createError('ACCOUNT_007'); // CAMBIO
92
+ } else if (firstError.includes('VTEX regions API')) {
93
+ return await AccountErrors.createError('ACCOUNT_008', { status: 'unknown', context: firstError }); // CAMBIO
94
+ } else if (firstError.includes('No regions found')) {
95
+ return await AccountErrors.createError('ACCOUNT_009', { context: 'coordinates', latitude: 'N/A', longitude: 'N/A' }); // CAMBIO
96
+ } else if (firstError.includes('not found as seller')) {
97
+ return await AccountErrors.createError('ACCOUNT_010', { AccountName: account.AccountName, context: 'coordinates', latitude: 'N/A', longitude: 'N/A' }); // CAMBIO
98
+ } else {
99
+ return await AccountErrors.createError('ACCOUNT_007'); // CAMBIO
100
+ }
101
+ }
102
+ if (coordinatesValidation.warnings && coordinatesValidation.warnings.length > 0) {
103
+ Logger.warn("Coordinates validation warnings:", coordinatesValidation.warnings);
104
+ }
105
+ Logger.debug("✓ Coordinates validation passed successfully");
106
+ } catch (coordinatesError) {
107
+ Logger.error("Error during coordinates validation:", coordinatesError);
108
+ return await AccountErrors.createWithLogging('ACCOUNT_008', coordinatesError, { status: 'unknown', context: coordinatesError.message }); // CAMBIO
109
+ }
110
+ }
111
+ const listSchemas = account?.ListsSchemasVtexMDv2 ?? [];
112
+ if (Array.isArray(listSchemas) && listSchemas.length > 0) {
113
+ Logger.debug('LIST SCHEMAS TO SAVE', listSchemas);
114
+ const schemaResult = await saveSchemasVTEX(listSchemas, account);
115
+ if (schemaResult.error) {
116
+ return schemaResult.error;
117
+ }
118
+ }
119
+ const idOrderHook = account?.HookOrderVtexMDv2 ?? '';
120
+ if (idOrderHook !== '') {
121
+ Logger.debug('ID ORDER HOOK', idOrderHook);
122
+ const hookResult = await saveOrderHookVTEX(idOrderHook, account);
123
+ if (hookResult.error) {
124
+ return hookResult.error;
125
+ }
126
+ }
127
+ if (hasSavePriceAudience || hasSavePriceTableCLWL) {
128
+ try {
129
+ Logger.debug("Configuring AllowEmailSharing after account creation");
130
+ const emailSharingService = new SellerEmailSharingService();
131
+ const emailSharingResult = await emailSharingService.configureEmailSharing(AccountName);
132
+ if (emailSharingResult.success) {
133
+ Logger.info("AllowEmailSharing configured successfully");
134
+ message += " and AllowEmailSharing configured";
135
+ } else {
136
+ Logger.warn("AllowEmailSharing configuration warning:", emailSharingResult.message);
137
+ message += " (AllowEmailSharing configuration pending - check seller configuration)";
138
+ }
139
+ } catch (emailSharingError) {
140
+ Logger.error("Error during AllowEmailSharing configuration:", emailSharingError);
141
+ message += " (AllowEmailSharing configuration failed - can be configured manually later)";
142
+ }
143
+ }
144
+ return ApiResponse.response(200, { message: message, data: account });
145
+ } catch (error) {
146
+ Logger.error(error);
147
+ return await AccountErrors.createWithLogging('ACCOUNT_026', error); // CAMBIO
148
+ }
149
+ };
150
+
151
+ const saveSchemasVTEX = async (listSchemas, account) => {
152
+ for (const schemaName of listSchemas) {
153
+ try {
154
+ const responseData = await handleGetRecordSchema({ id: schemaName, tableName: SCHEMAS_VTEX_TABLE, identifier:'schemas' });
155
+ Logger.debug('response data', responseData);
156
+
157
+ if (responseData?.statusCode === 200) {
158
+ const bodyParse = JSON.parse(responseData?.body);
159
+ const schemaResult = bodyParse?.result;
160
+
161
+ if (!schemaResult?.Properties || !schemaResult?.VTriggers) {
162
+ Logger.error(`Schema ${schemaName} is missing required fields.`);
163
+ return { error: await AccountErrors.createError('ACCOUNT_022') }; // CAMBIO
164
+ }
165
+
166
+ const response = await handleSchemaVtexMD2({
167
+ id: schemaName,
168
+ entityName: schemaResult?.EntityName,
169
+ data: {
170
+ 'title': schemaResult?.Title,
171
+ 'properties': schemaResult?.Properties,
172
+ 'v-cache': schemaResult?.VCache,
173
+ 'v-default-fields': schemaResult?.VDefaultFields,
174
+ 'required': schemaResult?.Required,
175
+ 'v-indexed': schemaResult?.VIndexed,
176
+ 'v-security': schemaResult?.VSecurity,
177
+ 'v-triggers': schemaResult?.VTriggers,
178
+ 'v-immediate-indexing': schemaResult?.VImmediateIndexing
179
+ },
180
+ origin: {
181
+ AccountName: account?.AccountName,
182
+ AppKey: account?.Credentials?.key,
183
+ AppToken: account?.Credentials?.token,
184
+ },
185
+ httpMethod: 'PUT',
186
+ });
187
+
188
+ if (!response) {
189
+ Logger.error('Error saving schema', schemaName);
190
+ continue;
191
+ }
192
+ } else {
193
+ Logger.error(`Failed to retrieve schema ${schemaName}:`, responseData);
194
+ return { error: await AccountErrors.createError('ACCOUNT_023') }; // CAMBIO
195
+ }
196
+ } catch (error) {
197
+ Logger.error(error);
198
+ return { error: await AccountErrors.createWithLogging('ACCOUNT_023', error) }; // CAMBIO
199
+ }
200
+ }
201
+
202
+ return { success: true };
203
+ };
204
+
205
+ const saveOrderHookVTEX = async (idOrderHook, account) => {
206
+ Logger.debug('ENTRANDO a saveOrderHookVTEX', { idOrderHook, account });
207
+
208
+ try {
209
+ const responseData = await handleGetRecordSchema({ id: idOrderHook, tableName: HOOKS_VTEX_TABLE, identifier:'hooks' });
210
+
211
+ if (responseData?.statusCode === 200) {
212
+ const bodyParse = JSON.parse(responseData?.body);
213
+ const hookResult = bodyParse?.result;
214
+ Logger.debug('response data', hookResult);
215
+
216
+ if (!hookResult?.Filter || !hookResult?.Hook) {
217
+ Logger.error(`Hook ${idOrderHook} is missing required fields.`);
218
+ return { error: await AccountErrors.createError('ACCOUNT_024') }; // CAMBIO
219
+ }
220
+
221
+ const response = await handleHookVtexMD2({
222
+ id: idOrderHook,
223
+ data: {
224
+ 'filter': hookResult?.Filter,
225
+ 'hook': hookResult?.Hook,
226
+ 'queue': hookResult?.Queue ?? '',
227
+ 'aproximateAgeOfOldestMessageInSeconds': hookResult?.AproximateAgeOfOldestMessageInSeconds ?? 0,
228
+ 'quantity': hookResult?.Quantity ?? 0,
229
+ },
230
+ origin: {
231
+ AccountName: account?.AccountName,
232
+ AppKey: account?.Credentials?.key,
233
+ AppToken: account?.Credentials?.token,
234
+ },
235
+ httpMethod: 'POST',
236
+ });
237
+
238
+ if (!response) {
239
+ Logger.error(`Failed to save hook for ${idOrderHook}`);
240
+ return { error: await AccountErrors.createError('ACCOUNT_025') }; // CAMBIO
241
+ }
242
+ } else {
243
+ Logger.error(`Failed to retrieve hook ${idOrderHook}:`, responseData);
244
+ return { error: await AccountErrors.createError('ACCOUNT_025') }; // CAMBIO
245
+ }
246
+ } catch (error) {
247
+ Logger.error(`Error processing hook ${idOrderHook}:`, error);
248
+ return { error: await AccountErrors.createWithLogging('ACCOUNT_025', error) }; // CAMBIO
249
+ }
250
+
251
+ return { success: true };
252
+ };
253
+
254
+ const sftpConfig = async (event) => {
255
+ try {
256
+ if (!event.body) {
257
+ return await AccountErrors.createError('ACCOUNT_001'); // CAMBIO
258
+ }
259
+ const body = Validation.transformFirstKeysToUpperCaseValue(JSON.parse(event.body));
260
+ const { AccountName } = body;
261
+ if (!AccountName || AccountName === "") {
262
+ return await AccountErrors.createError('ACCOUNT_002'); // CAMBIO
263
+ }
264
+ if (!body.ProcessExecute) {
265
+ return await AccountErrors.createError('ACCOUNT_016'); // CAMBIO
266
+ }
267
+ if (!Constants.SFTP_ALL_PROCESSES_CONSUMED.includes(body.ProcessExecute)) {
268
+ return await AccountErrors.createError('ACCOUNT_017', { VALID_PROCESSES: Constants.SFTP_ALL_PROCESSES_CONSUMED.join(', ') }); // CAMBIO
269
+ }
270
+ const accountConfig = await AccountData.getAccountDataByAccountName(AccountName);
271
+ if (!accountConfig) {
272
+ Logger.error("Account not found: ", AccountName);
273
+ return await AccountErrors.createError('ACCOUNT_018', { accountName: AccountName }); // CAMBIO
274
+ }
275
+ Logger.setAccount(accountConfig);
276
+ if (body.ProcessExecute === Constants.SFTP_PROCESS_INVENTORY) {
277
+ if (!body.Warehouse) {
278
+ return await AccountErrors.createError('ACCOUNT_019'); // CAMBIO
279
+ }
280
+ if (!accountConfig.ChannelWarehouse || !Object.values(accountConfig.ChannelWarehouse).includes(body.Warehouse)) {
281
+ return await AccountErrors.createError('ACCOUNT_020'); // CAMBIO
282
+ }
283
+ }
284
+ const sftpConfig = await SftpInbound.addSftpInboundConfig(body);
285
+ Logger.debug("SFTP Config: ", sftpConfig);
286
+ if (!sftpConfig) {
287
+ return await AccountErrors.createError('ACCOUNT_021'); // CAMBIO
288
+ }
289
+ return ApiResponse.response(200, { message: "SFTP Config created successfully", data: sftpConfig });
290
+ } catch (error) {
291
+ Logger.error(error);
292
+ return await AccountErrors.createWithLogging('ACCOUNT_026', error); // CAMBIO
293
+ }
294
+ };
295
+
296
+ module.exports = {
297
+ create,
298
+ sftpConfig,
299
+ };
@@ -0,0 +1,10 @@
1
+ const client = require('../../entities/clients');
2
+ const ApiResponse = require("../../common/utils/api-response");
3
+
4
+ const handler = async (event) => {
5
+ const clientId = event?.requestContext?.authorizer?.claims?.client_id;
6
+ const listAccounts = await client.getListAccountByClient(clientId);
7
+ return ApiResponse.responseNoCors(200, listAccounts);
8
+ };
9
+
10
+ module.exports = { handler };
@@ -0,0 +1,208 @@
1
+ const ApiResponse = require("../../common/utils/api-response");
2
+ const accountHandler = require("./account-handler");
3
+ const cronFlow = require("../crons/cron");
4
+ const cronJob = require("../cronjobs/cron-jobs-manager");
5
+ const accountGet = require("./account-get");
6
+ const getHandlers = require("../../common/utils/cron-ftp-get");
7
+ const sftp_schemas_file = require("../sftpIntegrations/schemas/record-schema");
8
+ const credential_schema = require("../sftpIntegrations/schemas/credential-schema");
9
+ const handle_schemas = require("../schemas/vtex/handle-schemas");
10
+ const clientauthadmin = require("../../auth/handler");
11
+
12
+ module.exports.handler = async (req, res) => {
13
+ const resource = req?.resource ?? null;
14
+ const method = req?.httpMethod ? String(req?.httpMethod).toUpperCase() : null;
15
+
16
+ if (resource && method) {
17
+ switch (resource) {
18
+ case "/account/create":
19
+ switch (method) {
20
+ case "POST":
21
+ return await accountHandler.create(req, res);
22
+ default:
23
+ return ApiResponse.response(400, { error: "Method not allowed." });
24
+ }
25
+ case "/account":
26
+ switch (method) {
27
+ case "GET":
28
+ return await accountGet.getAccounts(req, res);
29
+ default:
30
+ return ApiResponse.response(400, { error: "Method not allowed." });
31
+ }
32
+ case "/account/{an}":
33
+ switch (method) {
34
+ case "GET":
35
+ return await accountGet.getAccount(req, res);
36
+ case "DELETE":
37
+ return await accountGet.deleteAccount(req, res);
38
+ default:
39
+ return ApiResponse.response(400, { error: "Method not allowed." });
40
+ }
41
+ // admin cron_flow_sett
42
+ case "/crons":
43
+ switch (method) {
44
+ case "GET":
45
+ return await getHandlers.getAllCrons(req, res);
46
+ default:
47
+ return ApiResponse.response(400, { error: "Method not allowed." });
48
+ }
49
+ case "/crons/{cronId}":
50
+ switch (method) {
51
+ case "GET":
52
+ return await getHandlers.getCronById(req, res);
53
+ default:
54
+ return ApiResponse.response(400, { error: "Method not allowed." });
55
+ }
56
+ case "/crons/createorupdate/{cronId}":
57
+ switch (method) {
58
+ case "POST":
59
+ return await cronFlow.create(req, res);
60
+ default:
61
+ return ApiResponse.response(400, { error: "Method not allowed." });
62
+ }
63
+ case "/cronjobs/createorupdate/{cronId}":
64
+ switch (method) {
65
+ case "POST":
66
+ return await cronJob.create(req, res);
67
+ default:
68
+ return ApiResponse.response(400, { error: "Method not allowed." });
69
+ }
70
+ // account sftp config
71
+ case "/account/sftp":
72
+ switch (method) {
73
+ case "GET":
74
+ // NUEVO: Obtener TODAS las credenciales SFTP
75
+ return await getHandlers.getAllSftpCredentials(req, res);
76
+ case "POST":
77
+ return await accountHandler.sftpConfig(req, res);
78
+ default:
79
+ return ApiResponse.response(400, { error: "Method not allowed." });
80
+ }
81
+ case "/account/sftp/{ftpId}":
82
+ switch (method) {
83
+ case "GET":
84
+ return await getHandlers.getSftpCredentialById(req, res);
85
+ default:
86
+ return ApiResponse.response(400, { error: "Method not allowed." });
87
+ }
88
+ case "/account/sftp":
89
+ switch (method) {
90
+ case "POST":
91
+ return await accountHandler.sftpConfig(req, res);
92
+ default:
93
+ return ApiResponse.response(400, { error: "Method not allowed." });
94
+ }
95
+
96
+ // # sftp-schemas-file Schemas file
97
+ case "/sftpfile/schemas":
98
+ switch (method) {
99
+ case "GET":
100
+ return await sftp_schemas_file.handler(req, res);
101
+ default:
102
+ return ApiResponse.response(400, { error: "Method not allowed." });
103
+ }
104
+ case "/sftpfile/schema/{SchemaId}":
105
+ switch (method) {
106
+ case "GET":
107
+ return await sftp_schemas_file.handler(req, res);
108
+ case "PUT":
109
+ return await sftp_schemas_file.handler(req, res);
110
+ case "DELETE":
111
+ return await sftp_schemas_file.handler(req, res);
112
+ default:
113
+ return ApiResponse.response(400, { error: "Method not allowed." });
114
+ }
115
+ case "/sftp/config":
116
+ switch (method) {
117
+ case "POST":
118
+ return await sftp_schemas_file.handler(req, res);
119
+ default:
120
+ return ApiResponse.response(400, { error: "Method not allowed." });
121
+ }
122
+ // # sftp-credentiales SFTP credentials
123
+ case "/sftpcredentials/schemas":
124
+ switch (method) {
125
+ case "GET":
126
+ return await credential_schema.handler(req, res);
127
+ default:
128
+ return ApiResponse.response(400, { error: "Method not allowed." });
129
+ }
130
+ case "/sftpcredentials/schema/{FtpId}":
131
+ switch (method) {
132
+ case "GET":
133
+ return await credential_schema.handler(req, res);
134
+ case "PUT":
135
+ return await credential_schema.handler(req, res);
136
+ case "DELETE":
137
+ return await credential_schema.handler(req, res);
138
+ default:
139
+ return ApiResponse.response(400, { error: "Method not allowed." });
140
+ }
141
+ // # handle-schemas-vtex Schemas VTEX
142
+ case "/resource/schemas/vtex":
143
+ switch (method) {
144
+ case "GET":
145
+ return await handle_schemas.handler(req, res);
146
+ default:
147
+ return ApiResponse.response(400, { error: "Method not allowed." });
148
+ }
149
+ case "/resource/schemas/vtex/{SchemaName}":
150
+ switch (method) {
151
+ case "GET":
152
+ return await handle_schemas.handler(req, res);
153
+ case "PUT":
154
+ return await handle_schemas.handler(req, res);
155
+ case "DELETE":
156
+ return await handle_schemas.handler(req, res);
157
+ default:
158
+ return ApiResponse.response(400, { error: "Method not allowed." });
159
+ }
160
+ case "/resource/hooks/vtex":
161
+ switch (method) {
162
+ case "GET":
163
+ return await handle_schemas.handler(req, res);
164
+ default:
165
+ return ApiResponse.response(400, { error: "Method not allowed." });
166
+ }
167
+ case "/resource/hooks/vtex/{HookName}":
168
+ switch (method) {
169
+ case "GET":
170
+ return await handle_schemas.handler(req, res);
171
+ case "PUT":
172
+ return await handle_schemas.handler(req, res);
173
+ case "DELETE":
174
+ return await handle_schemas.handler(req, res);
175
+ default:
176
+ return ApiResponse.response(400, { error: "Method not allowed." });
177
+ }
178
+ // # Admin Servicios autenticacion
179
+ case "/oauth2/pvt/client":
180
+ switch (method) {
181
+ case "PATCH":
182
+ return await clientauthadmin.handler(req, res);
183
+ default:
184
+ return ApiResponse.response(400, { error: "Method not allowed." });
185
+ }
186
+ case "/oauth2/pvt/client/{clientId}":
187
+ switch (method) {
188
+ case "GET":
189
+ return await clientauthadmin.handler(req, res);
190
+ case "DELETE":
191
+ return await clientauthadmin.handler(req, res);
192
+ default:
193
+ return ApiResponse.response(400, { error: "Method not allowed." });
194
+ }
195
+ case "/oauth2/pvt/clients":
196
+ switch (method) {
197
+ case "GET":
198
+ return await clientauthadmin.handler(req, res);
199
+ default:
200
+ return ApiResponse.response(400, { error: "Method not allowed." });
201
+ }
202
+ default:
203
+ return ApiResponse.response(400, { error: "Resource not found." });
204
+ }
205
+ } else {
206
+ return ApiResponse.response(400, { error: "Invalid request parameters." });
207
+ }
208
+ };