n8n-nodes-centum 0.1.3 → 0.2.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 (35) hide show
  1. package/README.md +1 -1
  2. package/dist/nodes/Centum/Centum.node.d.ts +1 -1
  3. package/dist/nodes/Centum/Centum.node.js +190 -116
  4. package/dist/nodes/Centum/Centum.node.js.map +1 -1
  5. package/dist/nodes/Centum/CentumDescription.d.ts +1 -0
  6. package/dist/nodes/Centum/CentumDescription.js +180 -106
  7. package/dist/nodes/Centum/CentumDescription.js.map +1 -1
  8. package/dist/nodes/Centum/helpers/api.backup.d.ts +14 -0
  9. package/dist/nodes/Centum/helpers/api.backup.js +111 -0
  10. package/dist/nodes/Centum/helpers/api.backup.js.map +1 -0
  11. package/dist/nodes/Centum/helpers/functions.d.ts +26 -3
  12. package/dist/nodes/Centum/helpers/functions.js +197 -6
  13. package/dist/nodes/Centum/helpers/functions.js.map +1 -1
  14. package/dist/nodes/Centum/interfaces/{customers.d.ts → clientes.d.ts} +3 -3
  15. package/dist/nodes/Centum/interfaces/{customers.js → clientes.js} +49 -49
  16. package/dist/nodes/Centum/interfaces/clientes.js.map +1 -0
  17. package/dist/nodes/Centum/interfaces/index.d.ts +3 -3
  18. package/dist/nodes/Centum/interfaces/index.js +3 -3
  19. package/dist/nodes/Centum/interfaces/index.js.map +1 -1
  20. package/dist/nodes/Centum/interfaces/newCobro.d.ts +1 -1
  21. package/dist/nodes/Centum/interfaces/{newCustomer.d.ts → nuevoCliente.d.ts} +17 -5
  22. package/dist/nodes/Centum/interfaces/{newCustomer.js → nuevoCliente.js} +1 -1
  23. package/dist/nodes/Centum/interfaces/nuevoCliente.js.map +1 -0
  24. package/dist/nodes/Centum/interfaces/{newPedidoVenta.d.ts → nuevoPedidoVenta.d.ts} +1 -1
  25. package/dist/nodes/Centum/interfaces/{newPedidoVenta.js → nuevoPedidoVenta.js} +1 -1
  26. package/dist/nodes/Centum/interfaces/nuevoPedidoVenta.js.map +1 -0
  27. package/dist/package.json +1 -1
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +10 -10
  30. package/dist/nodes/Centum/helpers/api.d.ts +0 -10
  31. package/dist/nodes/Centum/helpers/api.js +0 -48
  32. package/dist/nodes/Centum/helpers/api.js.map +0 -1
  33. package/dist/nodes/Centum/interfaces/customers.js.map +0 -1
  34. package/dist/nodes/Centum/interfaces/newCustomer.js.map +0 -1
  35. package/dist/nodes/Centum/interfaces/newPedidoVenta.js.map +0 -1
package/README.md CHANGED
@@ -21,7 +21,7 @@ This node uses authenticated requests to the Centum API, ensuring secure and eff
21
21
  To use this node, ensure you have the following installed on your development machine:
22
22
 
23
23
  - **n8n**: Version 1.75.2 or higher (latest version recommended for compatibility).
24
- - **Node.js**: Version 18.x or higher.
24
+ - **Node.js**: Version 20.x or higher.
25
25
  - **npm**: Required for installing and building the plugin.
26
26
  - **Git**: For cloning the repository.
27
27
  - **Centum API Access**: Valid credentials (`centumUrl`, `consumerApiPublicId`, `publicAccessKey`) provided by your Centum provider.
@@ -1,4 +1,4 @@
1
- import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
1
+ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
2
  export declare class Centum implements INodeType {
3
3
  description: INodeTypeDescription;
4
4
  execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Centum = void 0;
4
- const api_1 = require("./helpers/api");
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
5
  const CentumDescription_1 = require("./CentumDescription");
6
6
  const functions_1 = require("./helpers/functions");
7
7
  class Centum {
@@ -25,31 +25,30 @@ class Centum {
25
25
  required: true,
26
26
  },
27
27
  ],
28
- properties: [...CentumDescription_1.CentumOperations, ...CentumDescription_1.CentumFields],
28
+ properties: [...CentumDescription_1.CentumOperations, ...CentumDescription_1.CentumFields, ...CentumDescription_1.HttpOptions],
29
29
  };
30
30
  }
31
31
  async execute() {
32
32
  const centumApiCredentials = await this.getCredentials('centumApi');
33
33
  let centumUrl = centumApiCredentials.centumUrl;
34
34
  let consumerApiPublicId = centumApiCredentials.consumerApiPublicId;
35
- const centumSuiteAccessToken = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
36
35
  const headers = {
37
36
  CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
38
- CentumSuiteAccessToken: centumSuiteAccessToken,
37
+ publicAccessKey: centumApiCredentials.publicAccessKey,
39
38
  };
40
39
  const resource = this.getNodeParameter('resource', 0);
41
40
  switch (resource) {
42
41
  case 'activity':
43
42
  try {
44
- const dataActividad = await (0, api_1.apiRequest)(`${centumUrl}/PedidosVenta/27231`, { headers }, this);
43
+ const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/27231`, { headers });
45
44
  return [this.helpers.returnJsonArray(dataActividad)];
46
45
  }
47
46
  catch (error) {
48
47
  console.log(error);
49
48
  return [this.helpers.returnJsonArray([])];
50
49
  }
51
- case 'article':
52
- const clientId = this.getNodeParameter('clientId', 0);
50
+ case 'articulo':
51
+ const clientId = this.getNodeParameter('clienteId', 0);
53
52
  const documentDate = this.getNodeParameter('documentDate', 0);
54
53
  const IdsRubro = this.getNodeParameter('idsRubros', 0);
55
54
  const completeMigration = this.getNodeParameter('migracionCompleta', 0);
@@ -65,18 +64,18 @@ class Centum {
65
64
  IdsRubro: IdsRubro ? [IdsRubro] : [],
66
65
  IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [''],
67
66
  fechaModificacionDesde: dateModified ? dateModified : '',
68
- fechaModificacionImagenesDEsde: dateModifiedImage ? dateModifiedImage : '',
67
+ fechaModificacionImagenesDesde: dateModifiedImage ? dateModifiedImage : '',
69
68
  fechaPrecioActualizadoDesde: priceDateModified,
70
69
  };
71
70
  try {
72
- const dataArticulos = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
71
+ const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
73
72
  method: 'POST',
74
73
  body: bodyToSend,
75
74
  headers,
76
75
  queryParams: { tipoOrdenArticulos: 'Codigo' }
77
- }, this);
78
- if (dataArticulos.Articulos.Items.length > 0) {
79
- const items = dataArticulos.Articulos.Items;
76
+ });
77
+ if (response.Articulos.Items.length > 0) {
78
+ const items = response.Articulos.Items;
80
79
  if (!completeMigration) {
81
80
  const acc = [];
82
81
  for (const item of items) {
@@ -98,14 +97,14 @@ class Centum {
98
97
  IdGrupoArticulo: groupArticle.IdGrupoArticulo
99
98
  };
100
99
  try {
101
- const data = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
100
+ const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
102
101
  method: 'POST',
103
102
  headers: requestHeaders,
104
103
  body,
105
104
  queryParams: { tipoOrdenArticulos: 'Codigo' },
106
- }, this);
107
- if (data.Articulos.Items.length > 0) {
108
- acc.push(...data.Articulos.Items);
105
+ });
106
+ if (response.Articulos.Items.length > 0) {
107
+ acc.push(...response.Articulos.Items);
109
108
  }
110
109
  }
111
110
  catch (error) {
@@ -130,22 +129,22 @@ class Centum {
130
129
  console.log('Error en solicitud de artículos', error);
131
130
  return [this.helpers.returnJsonArray([])];
132
131
  }
133
- case 'stockArticle':
132
+ case 'articulosExistencia':
134
133
  const branchOfficeIds = String(this.getNodeParameter('branchOfficeIds', 0));
135
134
  try {
136
- const dataArticulosExistencias = await (0, api_1.apiRequest)(`${centumUrl}/ArticulosExistencias`, {
135
+ const dataArticulosExistencia = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosExistencias`, {
137
136
  headers,
138
137
  queryParams: {
139
138
  idsSucursalesFisicas: branchOfficeIds,
140
139
  },
141
140
  });
142
- return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
141
+ return [this.helpers.returnJsonArray(dataArticulosExistencia.Items)];
143
142
  }
144
143
  catch (error) {
145
144
  console.log(error);
146
145
  return [this.helpers.returnJsonArray([])];
147
146
  }
148
- case 'stockArticleByPhysicalBranch':
147
+ case 'articulosSucursalesFisicas':
149
148
  const IdSucursalFisica = this.getNodeParameter('IdSucursalFisica', 0);
150
149
  const queryParams = {
151
150
  Codigo: 'R06SR0601P00010007',
@@ -154,23 +153,23 @@ class Centum {
154
153
  queryParams.idsSucursalesFisicas = IdSucursalFisica;
155
154
  }
156
155
  try {
157
- const dataArticulosExistencias = await (0, api_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
156
+ const dataArticulosExistencias = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
158
157
  headers,
159
158
  queryParams,
160
- }, this);
159
+ });
161
160
  return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
162
161
  }
163
162
  catch (error) {
164
163
  console.log(error);
165
164
  return [this.helpers.returnJsonArray([])];
166
165
  }
167
- case 'priceArticle':
166
+ case 'precioArticulo':
168
167
  const paramsPrice = {
169
- Cantidad: this.getNodeParameter('quantity', 0),
168
+ Cantidad: this.getNodeParameter('articuloCantidad', 0),
170
169
  FechaDocumento: this.getNodeParameter('documentDate', 0),
171
170
  };
172
171
  try {
173
- const dataArticulosPrecios = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/PrecioArticulo`, {
172
+ const dataArticulosPrecios = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/PrecioArticulo`, {
174
173
  method: 'POST',
175
174
  headers,
176
175
  queryParams: paramsPrice,
@@ -182,14 +181,14 @@ class Centum {
182
181
  Nombre: 'ADHESIVO ACRILICO KEKOL K-645 1 KG',
183
182
  NombreFantasia: '',
184
183
  },
185
- }, this);
184
+ });
186
185
  return [this.helpers.returnJsonArray(dataArticulosPrecios)];
187
186
  }
188
187
  catch (error) {
189
188
  console.log(error);
190
189
  return [this.helpers.returnJsonArray([])];
191
190
  }
192
- case 'articleImg':
191
+ case 'articulosImagenes':
193
192
  const arrResult = [];
194
193
  const inputData = this.getInputData();
195
194
  const requestUrl = `${centumUrl}/ArticulosImagenes`;
@@ -202,7 +201,7 @@ class Centum {
202
201
  };
203
202
  const allArticleImages = await (0, functions_1.centumGetArticleImages)(1, element.json.IdArticulo, { consumerApiPublicId, publicAccessKey: String(centumApiCredentials.publicAccessKey) }, requestUrl);
204
203
  if (allArticleImages instanceof Error) {
205
- console.error(`Falló la descarga de imágenes para artículo ${element.json.IdArticulo}`, allArticleImages);
204
+ console.error(`Failed to download images for article ${element.json.IdArticulo}`, allArticleImages);
206
205
  continue;
207
206
  }
208
207
  if (allArticleImages.length > 0) {
@@ -229,7 +228,7 @@ class Centum {
229
228
  }
230
229
  }
231
230
  return [this.helpers.returnJsonArray(arrResult)];
232
- case 'processImage':
231
+ case 'procesarImagenes':
233
232
  const dataImages = this.getNodeParameter('dataImg', 0);
234
233
  const db = this.getNodeParameter('lastModifiedImg', 0);
235
234
  const result = [];
@@ -254,28 +253,57 @@ class Centum {
254
253
  result.push([]);
255
254
  }
256
255
  return [this.helpers.returnJsonArray(result)];
257
- case 'customers':
256
+ case 'clientes':
258
257
  try {
259
- const dataClientes = await (0, api_1.apiRequest)(`${centumUrl}/Clientes`, {
258
+ const ajustesHTTP = functions_1.getHttpSettings.call(this);
259
+ const fetchOptions = {
260
+ method: ajustesHTTP.method,
261
+ pagination: ajustesHTTP.pagination,
262
+ cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
263
+ itemsField: 'Items',
264
+ context: this,
260
265
  headers,
261
- }, this);
262
- return [this.helpers.returnJsonArray(dataClientes.Items)];
266
+ };
267
+ console.log(fetchOptions);
268
+ const clientes = await (0, functions_1.apiGetRequest)(`${centumUrl}/Clientes`, fetchOptions);
269
+ return [this.helpers.returnJsonArray(clientes)];
263
270
  }
264
271
  catch (error) {
265
- console.log(error);
272
+ console.error('Error al obtener clientes:', error);
266
273
  return [this.helpers.returnJsonArray([])];
267
274
  }
268
- case 'newCustomer':
269
- const body = this.getNodeParameter('body', 0);
270
- const customerDNI = this.getNodeParameter('dni', 0);
271
- const customerBody = (0, functions_1.createCustomerJson)(body, customerDNI);
275
+ case 'contribuyenteNuevo': {
276
+ const bodyJson = this.getNodeParameter('cuerpoHTTP', 0);
277
+ const cuit = this.getNodeParameter('cuit', 0);
278
+ const contribuyenteJSON = (0, functions_1.createContribuyenteJson)(bodyJson, cuit);
272
279
  try {
273
- const newCustomer = await (0, api_1.apiRequest)(`${centumUrl}/Clientes`, {
280
+ const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
274
281
  method: 'POST',
275
- body: customerBody,
282
+ body: contribuyenteJSON,
276
283
  headers,
277
- }, this);
278
- return [this.helpers.returnJsonArray(newCustomer)];
284
+ });
285
+ return [this.helpers.returnJsonArray([crearCliente])];
286
+ }
287
+ catch (error) {
288
+ console.log(error);
289
+ const obj = {
290
+ ...error.response?.data,
291
+ IdCliente: -1,
292
+ };
293
+ return [this.helpers.returnJsonArray([obj])];
294
+ }
295
+ }
296
+ case 'clienteNuevo':
297
+ const datosCliente = this.getNodeParameter('cuerpoHTTP', 0);
298
+ const clienteDNI = this.getNodeParameter('dni', 0);
299
+ const datosJSON = (0, functions_1.createCustomerJson)(datosCliente, clienteDNI);
300
+ try {
301
+ const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
302
+ method: 'POST',
303
+ body: datosJSON,
304
+ headers,
305
+ });
306
+ return [this.helpers.returnJsonArray(crearCliente)];
279
307
  }
280
308
  catch (error) {
281
309
  console.log(error);
@@ -285,29 +313,29 @@ class Centum {
285
313
  };
286
314
  return [this.helpers.returnJsonArray(obj)];
287
315
  }
288
- case 'putCustomer':
289
- const bodyPut = this.getNodeParameter('body', 0);
316
+ case 'clientesActualizar':
317
+ const nuevosDatos = this.getNodeParameter('cuerpoHTTP', 0);
290
318
  try {
291
- const updateCustomer = await (0, api_1.apiRequest)(`${centumUrl}/Clientes/Actualizar`, {
319
+ const updateCustomer = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes/Actualizar`, {
292
320
  method: 'POST',
293
- body: bodyPut,
321
+ body: nuevosDatos,
294
322
  headers,
295
- }, this);
323
+ });
296
324
  return [this.helpers.returnJsonArray(updateCustomer)];
297
325
  }
298
326
  catch (error) {
299
327
  console.log(error);
300
328
  return [this.helpers.returnJsonArray([])];
301
329
  }
302
- case 'salesOrder': {
303
- const customerSalesOrder = this.getNodeParameter('customer', 0);
304
- const articlesSalesOrder = this.getNodeParameter('article', 0);
305
- const shippingSalesOrder = this.getNodeParameter('shipping', 0);
306
- const cobroId = this.getNodeParameter('cobroId', 0);
330
+ case 'crearPedidoVenta': {
331
+ const customerSalesOrder = this.getNodeParameter('cliente', 0);
332
+ const articlesSalesOrder = this.getNodeParameter('articulo', 0);
333
+ const shippingSalesOrder = this.getNodeParameter('envio', 0);
334
+ const idCobro = this.getNodeParameter('idCobro', 0);
307
335
  const date = new Date().toISOString();
308
336
  const formattedDate = date.replace(/\..+/, '');
309
337
  try {
310
- const arrArticles = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
338
+ const arrArticles = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
311
339
  method: 'POST',
312
340
  headers,
313
341
  body: {
@@ -316,116 +344,161 @@ class Centum {
316
344
  Habilitado: true,
317
345
  ActivoWeb: true,
318
346
  },
319
- }, this);
320
- const bodyPedidoVenta = (0, functions_1.createOrderSaleJson)(arrArticles.Articulos.Items, customerSalesOrder, articlesSalesOrder, shippingSalesOrder, cobroId);
347
+ });
348
+ const bodyPedidoVenta = (0, functions_1.createOrderSaleJson)(arrArticles.Articulos.Items, customerSalesOrder, articlesSalesOrder, shippingSalesOrder, idCobro);
321
349
  const centumSuiteAccessTokenSalesOrder = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
322
350
  const headersSalesOrder = {
323
351
  CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
324
352
  CentumSuiteAccessToken: centumSuiteAccessTokenSalesOrder,
325
353
  };
326
- const dataPedidosVenta = await (0, api_1.apiRequest)(`${centumUrl}/PedidosVenta`, {
354
+ const dataPedidosVenta = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta`, {
327
355
  method: 'POST',
328
356
  headers: headersSalesOrder,
329
357
  body: bodyPedidoVenta,
330
- }, this);
331
- dataPedidosVenta.IdCobro = cobroId;
358
+ });
359
+ dataPedidosVenta.IdCobro = idCobro;
332
360
  return [this.helpers.returnJsonArray(dataPedidosVenta)];
333
361
  }
334
362
  catch (error) {
335
- console.log('Error en creación de pedido de venta:', error);
363
+ console.log('Error creating sales order:', error);
336
364
  return [this.helpers.returnJsonArray([])];
337
365
  }
338
366
  }
339
- case 'charge':
340
- const customerCharge = this.getNodeParameter('customer', 0);
341
- const articlesCharge = this.getNodeParameter('article', 0);
342
- const shippingChargeOrder = this.getNodeParameter('shipping', 0);
343
- const bodyCharge = (0, functions_1.createChargeJson)(customerCharge, articlesCharge, shippingChargeOrder);
367
+ case 'cobros':
368
+ const ordenCliente = this.getNodeParameter('cliente', 0);
369
+ const ordenArticulo = this.getNodeParameter('articulo', 0);
370
+ const ordenEnvio = this.getNodeParameter('envio', 0);
371
+ const bodyCharge = (0, functions_1.createChargeJson)(ordenCliente, ordenArticulo, ordenEnvio);
344
372
  try {
345
- const dataCobros = await (0, api_1.apiRequest)(`${centumUrl}/Cobros`, {
373
+ const dataCobros = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros`, {
374
+ method: 'POST',
346
375
  body: bodyCharge,
347
376
  headers,
348
- }, this);
377
+ });
349
378
  return [this.helpers.returnJsonArray(dataCobros)];
350
379
  }
351
380
  catch (error) {
352
381
  console.log(error);
353
382
  return [this.helpers.returnJsonArray([])];
354
383
  }
355
- case 'searchCustomer':
356
- const customerEmail = String(this.getNodeParameter('email', 0));
357
- const tipoDocumento = this.getNodeParameter('tipoDocumento', 0);
358
- const dni = this.getNodeParameter('dni', 0, '');
384
+ case 'buscarContribuyente': {
359
385
  const cuit = this.getNodeParameter('cuit', 0, '');
360
- const razonSocial = String(this.getNodeParameter('razonSocial', 0));
386
+ const razonSocial = this.getNodeParameter('razonSocial', 0, '');
387
+ if (!cuit && !razonSocial) {
388
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Debe proporcionar al menos CUIT o Razón Social para buscar contribuyentes.');
389
+ }
390
+ const queryParams = {};
391
+ if (cuit)
392
+ queryParams.Cuit = cuit;
393
+ if (razonSocial)
394
+ queryParams.razonSocial = razonSocial;
395
+ const requestDetails = {
396
+ url: `${centumUrl}/Clientes`,
397
+ headers,
398
+ queryParams,
399
+ };
361
400
  try {
362
- const searches = [
363
- { queryParams: { email: customerEmail }, description: 'email' },
364
- ...(tipoDocumento === 'dni' && dni
365
- ? [{ queryParams: { Codigo: `web-${dni}` }, description: 'DNI (Código)' }]
366
- : tipoDocumento === 'cuit' && cuit
367
- ? [{ queryParams: { CUIT: cuit }, description: 'CUIT' }]
368
- : []),
369
- ...(razonSocial ? [{ queryParams: { RazonSocial: razonSocial }, description: 'razón social' }] : []),
370
- ];
371
- let user = null;
372
- for (const search of searches) {
373
- const prepareHeaders = {
374
- CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
375
- CentumSuiteAccessToken: centumSuiteAccessToken,
376
- };
377
- const paramValue = Object.values(search.queryParams)[0];
378
- if (!paramValue || paramValue === 'undefined') {
379
- console.log(`Saltando búsqueda por ${search.description}: parámetro no válido`, search.queryParams);
380
- continue;
401
+ console.log(`[BuscarContribuyente] Request:`, JSON.stringify(requestDetails, null, 2));
402
+ const response = await (0, functions_1.apiRequest)(requestDetails.url, {
403
+ method: 'GET',
404
+ headers: requestDetails.headers,
405
+ queryParams: requestDetails.queryParams,
406
+ });
407
+ console.log(`[BuscarContribuyente] Response:`, JSON.stringify(response, null, 2));
408
+ if (response.CantidadTotalItems === 1) {
409
+ return [this.helpers.returnJsonArray(response.Items)];
410
+ }
411
+ return [this.helpers.returnJsonArray(response)];
412
+ }
413
+ catch (error) {
414
+ console.log(`[BuscarContribuyente] Error:`, error);
415
+ return [this.helpers.returnJsonArray([])];
416
+ }
417
+ }
418
+ case 'clientesBusqueda': {
419
+ const customerEmail = this.getNodeParameter('email', 0, '');
420
+ const dni = this.getNodeParameter('dni', 0, '');
421
+ const buildQuery = (campo, valor) => valor ? { [campo]: valor } : {};
422
+ let clientResponse = null;
423
+ try {
424
+ if (customerEmail) {
425
+ try {
426
+ console.log('[email] Buscando cliente por email...');
427
+ const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
428
+ method: 'GET',
429
+ headers,
430
+ queryParams: buildQuery('Email', customerEmail),
431
+ });
432
+ console.log('[email] Resultado:', response);
433
+ clientResponse = response;
434
+ if (response.CantidadTotalItems === 1) {
435
+ return [this.helpers.returnJsonArray(response.Items)];
436
+ }
381
437
  }
382
- console.log(`Intentando búsqueda por ${search.description}`, {
383
- url: `${centumUrl}/Clientes`,
384
- headers: prepareHeaders,
385
- queryParams: search.queryParams,
386
- });
438
+ catch (error) {
439
+ console.log('[email] Error en búsqueda por email:', error);
440
+ }
441
+ }
442
+ if (!clientResponse && dni) {
387
443
  try {
388
- const response = await (0, api_1.apiRequest)(`${centumUrl}/Clientes`, { headers: prepareHeaders, queryParams: search.queryParams }, this);
389
- console.log(`Resultado búsqueda por ${search.description}`, {
390
- CantidadTotalItems: response.CantidadTotalItems,
444
+ console.log('[dni] Buscando cliente por Código: web-{dni}...');
445
+ const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
446
+ method: 'GET',
447
+ headers,
448
+ queryParams: buildQuery('Codigo', `web-${dni}`),
391
449
  });
450
+ console.log('[dni] Resultado:', response);
451
+ clientResponse = response;
392
452
  if (response.CantidadTotalItems === 1) {
393
- user = response;
394
- break;
453
+ return [this.helpers.returnJsonArray(response.Items)];
395
454
  }
396
455
  }
397
456
  catch (error) {
398
- console.log(`Error en búsqueda de cliente por ${search.description}`, {
399
- error,
400
- headers: prepareHeaders,
401
- queryParams: search.queryParams,
457
+ console.log('[dni] Error con Código web-{dni}:', error);
458
+ }
459
+ }
460
+ if (!clientResponse && dni) {
461
+ try {
462
+ console.log('[dni-alt] Buscando cliente por Código simple (dni sin "web-")...');
463
+ const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
464
+ method: 'GET',
465
+ headers,
466
+ queryParams: buildQuery('Codigo', dni),
402
467
  });
403
- continue;
468
+ console.log('[dni-alt] Resultado:', response);
469
+ clientResponse = response;
470
+ if (response.CantidadTotalItems === 1) {
471
+ return [this.helpers.returnJsonArray(response.Items)];
472
+ }
473
+ }
474
+ catch (error) {
475
+ console.log('[dni-alt] Error con Código sin "web-":', error);
404
476
  }
405
477
  }
406
- const result = user && user.CantidadTotalItems === 1 ? user.Items : [];
407
- return [this.helpers.returnJsonArray(result)];
478
+ return [this.helpers.returnJsonArray(clientResponse)];
408
479
  }
409
480
  catch (error) {
410
- console.log('Error general en búsqueda de cliente:', error);
411
- return [this.helpers.returnJsonArray(error.response?.data?.Items || [])];
481
+ console.log('General error during customer search:', error);
482
+ return [this.helpers.returnJsonArray([{ error: 'Búsqueda fallida', detalle: error }])];
412
483
  }
413
- case 'listBranches':
484
+ }
485
+ case 'sucursalesLista':
414
486
  try {
415
- const dataListBranches = await (0, api_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
487
+ const dataListBranches = await (0, functions_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
488
+ method: 'GET',
416
489
  headers,
417
- }, this);
490
+ });
418
491
  return [this.helpers.returnJsonArray(dataListBranches)];
419
492
  }
420
493
  catch (error) {
421
494
  console.log(error);
422
495
  return [this.helpers.returnJsonArray(error.response.data)];
423
496
  }
424
- case 'json':
497
+ case 'generarProductosWoo':
425
498
  const data = this.getInputData();
426
499
  const json = (0, functions_1.createJsonProducts)(data);
427
500
  return [this.helpers.returnJsonArray(json)];
428
- case 'productList':
501
+ case 'obtenerProductos':
429
502
  try {
430
503
  const payload = {
431
504
  "IdCliente": 47924,
@@ -433,11 +506,11 @@ class Centum {
433
506
  "Habilitado": true,
434
507
  "ActivoWeb": true
435
508
  };
436
- const dataProductos = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
509
+ const dataProductos = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
437
510
  method: 'POST',
438
511
  body: payload,
439
512
  headers
440
- }, this);
513
+ });
441
514
  const items = dataProductos.Articulos?.Items || [];
442
515
  const formateoObjeto = items.map((item) => ({
443
516
  IdArticulo: item.IdArticulo,
@@ -470,6 +543,7 @@ class Centum {
470
543
  return [this.helpers.returnJsonArray(formateoObjeto)];
471
544
  }
472
545
  catch (error) {
546
+ console.log(error);
473
547
  return [this.helpers.returnJsonArray([])];
474
548
  }
475
549
  default: