n8n-nodes-centum 0.1.2
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/LICENSE.md +19 -0
- package/README.md +56 -0
- package/dist/credentials/CentumApi.credentials.d.ts +8 -0
- package/dist/credentials/CentumApi.credentials.js +42 -0
- package/dist/credentials/CentumApi.credentials.js.map +1 -0
- package/dist/nodes/Centum/Centum.node.d.ts +5 -0
- package/dist/nodes/Centum/Centum.node.js +482 -0
- package/dist/nodes/Centum/Centum.node.js.map +1 -0
- package/dist/nodes/Centum/Centum.node.json +0 -0
- package/dist/nodes/Centum/CentumDescription.d.ts +3 -0
- package/dist/nodes/Centum/CentumDescription.js +434 -0
- package/dist/nodes/Centum/CentumDescription.js.map +1 -0
- package/dist/nodes/Centum/centum.png +0 -0
- package/dist/nodes/Centum/constants/index.d.ts +2 -0
- package/dist/nodes/Centum/constants/index.js +19 -0
- package/dist/nodes/Centum/constants/index.js.map +1 -0
- package/dist/nodes/Centum/constants/provincias.d.ts +5 -0
- package/dist/nodes/Centum/constants/provincias.js +131 -0
- package/dist/nodes/Centum/constants/provincias.js.map +1 -0
- package/dist/nodes/Centum/constants/zonas.d.ts +15 -0
- package/dist/nodes/Centum/constants/zonas.js +2046 -0
- package/dist/nodes/Centum/constants/zonas.js.map +1 -0
- package/dist/nodes/Centum/helpers/api.d.ts +10 -0
- package/dist/nodes/Centum/helpers/api.js +48 -0
- package/dist/nodes/Centum/helpers/api.js.map +1 -0
- package/dist/nodes/Centum/helpers/functions.d.ts +19 -0
- package/dist/nodes/Centum/helpers/functions.js +540 -0
- package/dist/nodes/Centum/helpers/functions.js.map +1 -0
- package/dist/nodes/Centum/images-last-modified.json +1636 -0
- package/dist/nodes/Centum/interfaces/articulos.d.ts +270 -0
- package/dist/nodes/Centum/interfaces/articulos.js +118 -0
- package/dist/nodes/Centum/interfaces/articulos.js.map +1 -0
- package/dist/nodes/Centum/interfaces/articulosExistencias.d.ts +13 -0
- package/dist/nodes/Centum/interfaces/articulosExistencias.js +3 -0
- package/dist/nodes/Centum/interfaces/articulosExistencias.js.map +1 -0
- package/dist/nodes/Centum/interfaces/articulosMerge.d.ts +232 -0
- package/dist/nodes/Centum/interfaces/articulosMerge.js +86 -0
- package/dist/nodes/Centum/interfaces/articulosMerge.js.map +1 -0
- package/dist/nodes/Centum/interfaces/customers.d.ts +427 -0
- package/dist/nodes/Centum/interfaces/customers.js +226 -0
- package/dist/nodes/Centum/interfaces/customers.js.map +1 -0
- package/dist/nodes/Centum/interfaces/index.d.ts +9 -0
- package/dist/nodes/Centum/interfaces/index.js +26 -0
- package/dist/nodes/Centum/interfaces/index.js.map +1 -0
- package/dist/nodes/Centum/interfaces/newCobro.d.ts +74 -0
- package/dist/nodes/Centum/interfaces/newCobro.js +3 -0
- package/dist/nodes/Centum/interfaces/newCobro.js.map +1 -0
- package/dist/nodes/Centum/interfaces/newCustomer.d.ts +168 -0
- package/dist/nodes/Centum/interfaces/newCustomer.js +3 -0
- package/dist/nodes/Centum/interfaces/newCustomer.js.map +1 -0
- package/dist/nodes/Centum/interfaces/newPedidoVenta.d.ts +60 -0
- package/dist/nodes/Centum/interfaces/newPedidoVenta.js +3 -0
- package/dist/nodes/Centum/interfaces/newPedidoVenta.js.map +1 -0
- package/dist/nodes/Centum/interfaces/wooArticle.d.ts +32 -0
- package/dist/nodes/Centum/interfaces/wooArticle.js +3 -0
- package/dist/nodes/Centum/interfaces/wooArticle.js.map +1 -0
- package/dist/nodes/Centum/interfaces/woocommerce.d.ts +130 -0
- package/dist/nodes/Centum/interfaces/woocommerce.js +3 -0
- package/dist/nodes/Centum/interfaces/woocommerce.js.map +1 -0
- package/dist/nodes/Centum/products-migration-run.json +1 -0
- package/dist/package.json +56 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/index.js +0 -0
- package/package.json +56 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2022 n8n
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# n8n-nodes-centum
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This is a custom node for [n8n](https://n8n.io/), an open-source workflow automation platform, designed to integrate with the **Centum API**, a system for managing customers, charges, and other business resources. The `Centum` node simplifies interaction with Centum's API endpoints, enabling operations such as searching for customers, creating charges, and more, directly within your n8n workflows.
|
|
6
|
+
|
|
7
|
+
The node is built to be extensible, allowing for easy addition of new operations to meet specific integration needs with Centum.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
The `Centum` node supports the following operations:
|
|
12
|
+
|
|
13
|
+
- **Search Customers (`searchCustomer`)**: Search for customers in Centum using parameters like `email`, `Code`, or `Business Name`. Returns customer data if a single match is found.
|
|
14
|
+
- **Create Charges (`charge`)**: Create a new charge in Centum by sending customer details, articles, and shipping information.
|
|
15
|
+
- **Extensibility**: The node is designed to support additional operations (e.g., managing articles, activities, or inventory) as needed.
|
|
16
|
+
|
|
17
|
+
This node uses authenticated requests to the Centum API, ensuring secure and efficient integration with your Centum system.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
To use this node, ensure you have the following installed on your development machine:
|
|
22
|
+
|
|
23
|
+
- **n8n**: Version 1.75.2 or higher (latest version recommended for compatibility).
|
|
24
|
+
- **Node.js**: Version 18.x or higher.
|
|
25
|
+
- **npm**: Required for installing and building the plugin.
|
|
26
|
+
- **Git**: For cloning the repository.
|
|
27
|
+
- **Centum API Access**: Valid credentials (`centumUrl`, `consumerApiPublicId`, `publicAccessKey`) provided by your Centum provider.
|
|
28
|
+
|
|
29
|
+
Recommended: Follow n8n's guide to [set up your development environment](https://docs.n8n.io/integrations/creating-nodes/build/node-development-environment/).
|
|
30
|
+
|
|
31
|
+
## Using this starter
|
|
32
|
+
|
|
33
|
+
These are the basic steps for working with the starter. For detailed guidance on creating and publishing nodes, refer to the [documentation](https://docs.n8n.io/integrations/creating-nodes/).
|
|
34
|
+
|
|
35
|
+
1. [Generate a new repository](https://github.com/n8n-io/n8n-nodes-starter/generate) from this template repository.
|
|
36
|
+
2. git clone https://github.com//.git
|
|
37
|
+
3. Run npm i to install dependencies.
|
|
38
|
+
4. Open the project in your editor.
|
|
39
|
+
5. Browse the examples in /nodes and /credentials. Modify the examples, or replace them with your own nodes.
|
|
40
|
+
6. Update the package.json to match your details.
|
|
41
|
+
7. Run npm run lint to check for errors or npm run lintfix to automatically fix errors when possible.
|
|
42
|
+
8. Test your node locally. Refer to [Run your node locally](https://docs.n8n.io/integrations/creating-nodes/test/run-node-locally/) for guidance.
|
|
43
|
+
9. Replace this README with documentation for your node. Use the [README\_TEMPLATE](/broobe/n8n/n8n-nodes-blocky-nodes/-/blob/main/README_TEMPLATE.md) to get started.
|
|
44
|
+
10. Update the LICENSE file to use your details.
|
|
45
|
+
11. [Publish](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry) your package to npm.
|
|
46
|
+
|
|
47
|
+
## Support
|
|
48
|
+
|
|
49
|
+
For issues or questions:
|
|
50
|
+
- Open an **issue** on the [GitHub repository](https://github.com/your-username/n8n-nodes-centum).
|
|
51
|
+
- Contact your Centum provider for API-related support.
|
|
52
|
+
- Refer to the [n8n documentation](https://docs.n8n.io/) for help with workflow integration.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
This project is licensed under the [MIT License](LICENSE). See the `LICENSE` file for details.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAuthenticateGeneric, ICredentialType, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
export declare class CentumApi implements ICredentialType {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
documentationUrl: string;
|
|
6
|
+
properties: INodeProperties[];
|
|
7
|
+
authenticate: IAuthenticateGeneric;
|
|
8
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CentumApi = void 0;
|
|
4
|
+
class CentumApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'centumApi';
|
|
7
|
+
this.displayName = 'Centum API';
|
|
8
|
+
this.documentationUrl = 'http://www.centum.com.ar/ApiPublica.pdf';
|
|
9
|
+
this.properties = [
|
|
10
|
+
{
|
|
11
|
+
displayName: 'Public Access Key',
|
|
12
|
+
name: 'publicAccessKey',
|
|
13
|
+
type: 'string',
|
|
14
|
+
typeOptions: { password: true },
|
|
15
|
+
default: '',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
displayName: 'CentumSuiteConsumidorApiPublicaId',
|
|
19
|
+
name: 'consumerApiPublicId',
|
|
20
|
+
type: 'number',
|
|
21
|
+
default: 0,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
displayName: 'Centum URL',
|
|
25
|
+
name: 'centumUrl',
|
|
26
|
+
type: 'string',
|
|
27
|
+
default: 'https://plataforma1.centum.com.ar:23990/BL2',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
this.authenticate = {
|
|
31
|
+
type: 'generic',
|
|
32
|
+
properties: {
|
|
33
|
+
headers: {
|
|
34
|
+
CentumSuiteAccessToken: '={{$credentials.publicAccessKey}}',
|
|
35
|
+
CentumSuiteConsumidorApiPublicaId: '={{credentials.consumerApiPublicId}}',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.CentumApi = CentumApi;
|
|
42
|
+
//# sourceMappingURL=CentumApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CentumApi.credentials.js","sourceRoot":"","sources":["../../credentials/CentumApi.credentials.ts"],"names":[],"mappings":";;;AAEA,MAAa,SAAS;IAAtB;QACC,SAAI,GAAG,WAAW,CAAC;QACnB,gBAAW,GAAG,YAAY,CAAC;QAC3B,qBAAgB,GAAG,yCAAyC,CAAC;QAC7D,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,mBAAmB;gBAChC,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;aACX;YACD;gBACC,WAAW,EAAE,mCAAmC;gBAChD,IAAI,EAAE,qBAAqB;gBAC3B,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,CAAC;aACV;YACD;gBACC,WAAW,EAAE,YAAY;gBACzB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,QAAQ;gBAEd,OAAO,EAAE,6CAA6C;aACtD;SACD,CAAC;QACF,iBAAY,GAAyB;YACpC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE;gBACX,OAAO,EAAE;oBACR,sBAAsB,EAAE,mCAAmC;oBAC3D,iCAAiC,EAAE,sCAAsC;iBACzE;aACD;SACD,CAAC;IAOH,CAAC;CAAA;AAzCD,8BAyCC"}
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Centum = void 0;
|
|
4
|
+
const api_1 = require("./helpers/api");
|
|
5
|
+
const CentumDescription_1 = require("./CentumDescription");
|
|
6
|
+
const functions_1 = require("./helpers/functions");
|
|
7
|
+
class Centum {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.description = {
|
|
10
|
+
displayName: 'Centum',
|
|
11
|
+
name: 'centum',
|
|
12
|
+
icon: 'file:centum.png',
|
|
13
|
+
group: ['transform'],
|
|
14
|
+
version: 1,
|
|
15
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
16
|
+
description: 'Consumes Centum API',
|
|
17
|
+
defaults: {
|
|
18
|
+
name: 'Centum',
|
|
19
|
+
},
|
|
20
|
+
inputs: ['main'],
|
|
21
|
+
outputs: ['main'],
|
|
22
|
+
credentials: [
|
|
23
|
+
{
|
|
24
|
+
name: 'centumApi',
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
properties: [...CentumDescription_1.CentumOperations, ...CentumDescription_1.CentumFields],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async execute() {
|
|
32
|
+
const centumApiCredentials = await this.getCredentials('centumApi');
|
|
33
|
+
let centumUrl = centumApiCredentials.centumUrl;
|
|
34
|
+
let consumerApiPublicId = centumApiCredentials.consumerApiPublicId;
|
|
35
|
+
const centumSuiteAccessToken = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
|
|
36
|
+
const headers = {
|
|
37
|
+
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
38
|
+
CentumSuiteAccessToken: centumSuiteAccessToken,
|
|
39
|
+
};
|
|
40
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
41
|
+
switch (resource) {
|
|
42
|
+
case 'activity':
|
|
43
|
+
try {
|
|
44
|
+
const dataActividad = await (0, api_1.apiRequest)(`${centumUrl}/PedidosVenta/27231`, { headers }, this);
|
|
45
|
+
return [this.helpers.returnJsonArray(dataActividad)];
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.log(error);
|
|
49
|
+
return [this.helpers.returnJsonArray([])];
|
|
50
|
+
}
|
|
51
|
+
case 'article':
|
|
52
|
+
const clientId = this.getNodeParameter('clientId', 0);
|
|
53
|
+
const documentDate = this.getNodeParameter('documentDate', 0);
|
|
54
|
+
const IdsRubro = this.getNodeParameter('idsRubros', 0);
|
|
55
|
+
const completeMigration = this.getNodeParameter('migracionCompleta', 0);
|
|
56
|
+
const IdsSubRubro = this.getNodeParameter('idsSubRubros', 0);
|
|
57
|
+
const formattedDocumentDate = documentDate.replace(/\..+/, '');
|
|
58
|
+
const dateModified = this.getNodeParameter('dateModified', 0);
|
|
59
|
+
const dateModifiedImage = this.getNodeParameter('dateModifiedImage', 0);
|
|
60
|
+
const priceDateModified = this.getNodeParameter('priceDateModified', 0);
|
|
61
|
+
const bodyToSend = {
|
|
62
|
+
idCliente: clientId,
|
|
63
|
+
FechaDocumento: formattedDocumentDate,
|
|
64
|
+
incluirAtributosArticulos: true,
|
|
65
|
+
IdsRubro: IdsRubro ? [IdsRubro] : [],
|
|
66
|
+
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [''],
|
|
67
|
+
fechaModificacionDesde: dateModified ? dateModified : '',
|
|
68
|
+
fechaModificacionImagenesDEsde: dateModifiedImage ? dateModifiedImage : '',
|
|
69
|
+
fechaPrecioActualizadoDesde: priceDateModified,
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const dataArticulos = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta?tipoOrdenArticulos=Codigo`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
body: bodyToSend,
|
|
75
|
+
responseType: 'json',
|
|
76
|
+
headers,
|
|
77
|
+
}, this);
|
|
78
|
+
if (dataArticulos.Articulos.Items.length > 0) {
|
|
79
|
+
const items = dataArticulos.Articulos.Items;
|
|
80
|
+
if (!completeMigration) {
|
|
81
|
+
const acc = [];
|
|
82
|
+
for (const item of items) {
|
|
83
|
+
const groupArticle = item.GrupoArticulo;
|
|
84
|
+
if (!groupArticle)
|
|
85
|
+
continue;
|
|
86
|
+
const centumSuiteAccessToken = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
|
|
87
|
+
const requestHeaders = {
|
|
88
|
+
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
89
|
+
CentumSuiteAccessToken: centumSuiteAccessToken,
|
|
90
|
+
};
|
|
91
|
+
const body = {
|
|
92
|
+
IdCliente: clientId,
|
|
93
|
+
FechaDocumento: formattedDocumentDate,
|
|
94
|
+
IncluirAtributosArticulos: true,
|
|
95
|
+
IdsRubro: IdsRubro ? [IdsRubro] : [],
|
|
96
|
+
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [''],
|
|
97
|
+
NombreGrupoArticulo: groupArticle.Nombre,
|
|
98
|
+
IdGrupoArticulo: groupArticle.IdGrupoArticulo
|
|
99
|
+
};
|
|
100
|
+
try {
|
|
101
|
+
const data = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: requestHeaders,
|
|
104
|
+
body,
|
|
105
|
+
queryParams: { tipoOrdenArticulos: 'Codigo' },
|
|
106
|
+
}, this);
|
|
107
|
+
if (data.Articulos.Items.length > 0) {
|
|
108
|
+
acc.push(...data.Articulos.Items);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.log('Error en solicitud de grupo de artículos', { error });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const combinedArrays = [...acc, ...items];
|
|
116
|
+
const filteredArray = Array.from(new Map(combinedArrays.map(obj => [obj.IdArticulo, obj])).values());
|
|
117
|
+
const itemsArray = filteredArray.map((item) => ({
|
|
118
|
+
...item,
|
|
119
|
+
AtributosArticulo: item.Habilitado && item.ActivoWeb ? item.AtributosArticulo : [],
|
|
120
|
+
}));
|
|
121
|
+
return [this.helpers.returnJsonArray(itemsArray)];
|
|
122
|
+
}
|
|
123
|
+
return [this.helpers.returnJsonArray(items)];
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return [this.helpers.returnJsonArray({ json: {} })];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.log('Error en solicitud de artículos', error);
|
|
131
|
+
return [this.helpers.returnJsonArray([])];
|
|
132
|
+
}
|
|
133
|
+
case 'stockArticle':
|
|
134
|
+
const branchOfficeIds = String(this.getNodeParameter('branchOfficeIds', 0));
|
|
135
|
+
try {
|
|
136
|
+
const dataArticulosExistencias = await (0, api_1.apiRequest)(`${centumUrl}/ArticulosExistencias`, {
|
|
137
|
+
headers,
|
|
138
|
+
queryParams: {
|
|
139
|
+
idsSucursalesFisicas: branchOfficeIds,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.log(error);
|
|
146
|
+
return [this.helpers.returnJsonArray([])];
|
|
147
|
+
}
|
|
148
|
+
case 'stockArticleByPhysicalBranch':
|
|
149
|
+
const IdSucursalFisica = this.getNodeParameter('IdSucursalFisica', 0);
|
|
150
|
+
const queryParams = {
|
|
151
|
+
Codigo: 'R06SR0601P00010007',
|
|
152
|
+
};
|
|
153
|
+
if (IdSucursalFisica) {
|
|
154
|
+
queryParams.idsSucursalesFisicas = IdSucursalFisica;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const dataArticulosExistencias = await (0, api_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
|
|
158
|
+
headers,
|
|
159
|
+
queryParams,
|
|
160
|
+
}, this);
|
|
161
|
+
return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.log(error);
|
|
165
|
+
return [this.helpers.returnJsonArray([])];
|
|
166
|
+
}
|
|
167
|
+
case 'priceArticle':
|
|
168
|
+
const paramsPrice = {
|
|
169
|
+
Cantidad: this.getNodeParameter('quantity', 0),
|
|
170
|
+
FechaDocumento: this.getNodeParameter('documentDate', 0),
|
|
171
|
+
};
|
|
172
|
+
try {
|
|
173
|
+
const dataArticulosPrecios = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/PrecioArticulo`, {
|
|
174
|
+
method: 'POST',
|
|
175
|
+
headers,
|
|
176
|
+
queryParams: paramsPrice,
|
|
177
|
+
body: {
|
|
178
|
+
IdArticulo: 1507,
|
|
179
|
+
Codigo: 'R02SR0206P00070007',
|
|
180
|
+
CodigoAuxiliar: '',
|
|
181
|
+
CodigoPropioProveedor: '',
|
|
182
|
+
Nombre: 'ADHESIVO ACRILICO KEKOL K-645 1 KG',
|
|
183
|
+
NombreFantasia: '',
|
|
184
|
+
},
|
|
185
|
+
}, this);
|
|
186
|
+
return [this.helpers.returnJsonArray(dataArticulosPrecios)];
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
console.log(error);
|
|
190
|
+
return [this.helpers.returnJsonArray([])];
|
|
191
|
+
}
|
|
192
|
+
case 'articleImg':
|
|
193
|
+
const arrResult = [];
|
|
194
|
+
const inputData = this.getInputData();
|
|
195
|
+
const requestUrl = `${centumUrl}/ArticulosImagenes`;
|
|
196
|
+
for (let i = 0; i < inputData.length; i++) {
|
|
197
|
+
const element = inputData[i];
|
|
198
|
+
const dataObj = {
|
|
199
|
+
idArticulo: element.json.IdArticulo,
|
|
200
|
+
images: [],
|
|
201
|
+
infoImages: [],
|
|
202
|
+
};
|
|
203
|
+
const allArticleImages = await (0, functions_1.centumGetArticleImages)(1, element.json.IdArticulo, { consumerApiPublicId, publicAccessKey: String(centumApiCredentials.publicAccessKey) }, requestUrl);
|
|
204
|
+
if (allArticleImages instanceof Error) {
|
|
205
|
+
console.error(`Falló la descarga de imágenes para artículo ${element.json.IdArticulo}`, allArticleImages);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (allArticleImages.length > 0) {
|
|
209
|
+
for (let j = 0; j < allArticleImages.length; j++) {
|
|
210
|
+
const binary = {};
|
|
211
|
+
const dataImage = allArticleImages[j];
|
|
212
|
+
const buffer = Buffer.from(dataImage.buffer);
|
|
213
|
+
binary['data'] = await this.helpers.prepareBinaryData(buffer);
|
|
214
|
+
binary.data.fileName = `${element.json.Codigo}_${j + 1}.${binary.data.fileExtension}`;
|
|
215
|
+
dataObj.images.push(binary);
|
|
216
|
+
dataObj.infoImages.push({
|
|
217
|
+
lastModified: dataImage.lastModified,
|
|
218
|
+
orderNumber: dataImage.orderNumber,
|
|
219
|
+
});
|
|
220
|
+
const existObj = arrResult.find((obj) => obj.idArticulo === element.json.IdArticulo);
|
|
221
|
+
if (!existObj) {
|
|
222
|
+
arrResult.push(dataObj);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
dataObj.images = null;
|
|
228
|
+
arrResult.push(dataObj);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return [this.helpers.returnJsonArray(arrResult)];
|
|
232
|
+
case 'processImage':
|
|
233
|
+
const dataImages = this.getNodeParameter('dataImg', 0);
|
|
234
|
+
const db = this.getNodeParameter('lastModifiedImg', 0);
|
|
235
|
+
const result = [];
|
|
236
|
+
for (let i = 0; i < dataImages.length; i++) {
|
|
237
|
+
const element = dataImages[i];
|
|
238
|
+
for (let j = 0; j < element.json.images?.length; j++) {
|
|
239
|
+
const currentData = element.json.images[j];
|
|
240
|
+
const currentInfoImage = element.json.infoImages[j];
|
|
241
|
+
const articleInDB = db.find((dbData) => dbData.articleId === element.json.idArticulo);
|
|
242
|
+
if (!articleInDB) {
|
|
243
|
+
result.push({ json: {}, binary: currentData });
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
const currentImageInDB = articleInDB.dataImage.find((dataImageDB) => dataImageDB.orderNumber === currentInfoImage.orderNumber);
|
|
247
|
+
if (currentImageInDB?.lastModified !== currentInfoImage.lastModified) {
|
|
248
|
+
result.push({ json: {}, binary: currentData });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (result.length === 0) {
|
|
254
|
+
result.push([]);
|
|
255
|
+
}
|
|
256
|
+
return [this.helpers.returnJsonArray(result)];
|
|
257
|
+
case 'customers':
|
|
258
|
+
try {
|
|
259
|
+
const dataClientes = await (0, api_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
260
|
+
headers,
|
|
261
|
+
}, this);
|
|
262
|
+
return [this.helpers.returnJsonArray(dataClientes.Items)];
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.log(error);
|
|
266
|
+
return [this.helpers.returnJsonArray([])];
|
|
267
|
+
}
|
|
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);
|
|
272
|
+
try {
|
|
273
|
+
const newCustomer = await (0, api_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
274
|
+
method: 'POST',
|
|
275
|
+
body: customerBody,
|
|
276
|
+
headers,
|
|
277
|
+
}, this);
|
|
278
|
+
return [this.helpers.returnJsonArray(newCustomer)];
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
console.log(error);
|
|
282
|
+
const obj = {
|
|
283
|
+
...error.response.data,
|
|
284
|
+
IdCliente: -1,
|
|
285
|
+
};
|
|
286
|
+
return [this.helpers.returnJsonArray(obj)];
|
|
287
|
+
}
|
|
288
|
+
case 'putCustomer':
|
|
289
|
+
const bodyPut = this.getNodeParameter('body', 0);
|
|
290
|
+
try {
|
|
291
|
+
const updateCustomer = await (0, api_1.apiRequest)(`${centumUrl}/Clientes/Actualizar`, {
|
|
292
|
+
method: 'POST',
|
|
293
|
+
body: bodyPut,
|
|
294
|
+
headers,
|
|
295
|
+
}, this);
|
|
296
|
+
return [this.helpers.returnJsonArray(updateCustomer)];
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
console.log(error);
|
|
300
|
+
return [this.helpers.returnJsonArray([])];
|
|
301
|
+
}
|
|
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);
|
|
307
|
+
const date = new Date().toISOString();
|
|
308
|
+
const formattedDate = date.replace(/\..+/, '');
|
|
309
|
+
try {
|
|
310
|
+
const arrArticles = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
311
|
+
method: 'POST',
|
|
312
|
+
headers,
|
|
313
|
+
body: {
|
|
314
|
+
idCliente: 1,
|
|
315
|
+
FechaDocumento: formattedDate,
|
|
316
|
+
Habilitado: true,
|
|
317
|
+
ActivoWeb: true,
|
|
318
|
+
},
|
|
319
|
+
}, this);
|
|
320
|
+
const bodyPedidoVenta = (0, functions_1.createOrderSaleJson)(arrArticles.Articulos.Items, customerSalesOrder, articlesSalesOrder, shippingSalesOrder, cobroId);
|
|
321
|
+
const centumSuiteAccessTokenSalesOrder = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
|
|
322
|
+
const headersSalesOrder = {
|
|
323
|
+
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
324
|
+
CentumSuiteAccessToken: centumSuiteAccessTokenSalesOrder,
|
|
325
|
+
};
|
|
326
|
+
const dataPedidosVenta = await (0, api_1.apiRequest)(`${centumUrl}/PedidosVenta`, {
|
|
327
|
+
method: 'POST',
|
|
328
|
+
headers: headersSalesOrder,
|
|
329
|
+
body: bodyPedidoVenta,
|
|
330
|
+
}, this);
|
|
331
|
+
dataPedidosVenta.IdCobro = cobroId;
|
|
332
|
+
return [this.helpers.returnJsonArray(dataPedidosVenta)];
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
console.log('Error en creación de pedido de venta:', error);
|
|
336
|
+
return [this.helpers.returnJsonArray([])];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
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);
|
|
344
|
+
try {
|
|
345
|
+
const dataCobros = await (0, api_1.apiRequest)(`${centumUrl}/Cobros`, {
|
|
346
|
+
body: bodyCharge,
|
|
347
|
+
headers,
|
|
348
|
+
}, this);
|
|
349
|
+
return [this.helpers.returnJsonArray(dataCobros)];
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
console.log(error);
|
|
353
|
+
return [this.helpers.returnJsonArray([])];
|
|
354
|
+
}
|
|
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, '');
|
|
359
|
+
const cuit = this.getNodeParameter('cuit', 0, '');
|
|
360
|
+
const razonSocial = String(this.getNodeParameter('razonSocial', 0));
|
|
361
|
+
try {
|
|
362
|
+
console.log("SEARCH CUSTOMER RESULT: ", razonSocial, customerEmail, dni);
|
|
363
|
+
const searches = [
|
|
364
|
+
{ queryParams: { email: customerEmail }, description: 'email' },
|
|
365
|
+
...(tipoDocumento === 'dni' && dni
|
|
366
|
+
? [{ queryParams: { Codigo: `web-${dni}` }, description: 'DNI (Código)' }]
|
|
367
|
+
: tipoDocumento === 'cuit' && cuit
|
|
368
|
+
? [{ queryParams: { CUIT: cuit }, description: 'CUIT' }]
|
|
369
|
+
: []),
|
|
370
|
+
...(razonSocial ? [{ queryParams: { RazonSocial: razonSocial }, description: 'razón social' }] : []),
|
|
371
|
+
];
|
|
372
|
+
let user = null;
|
|
373
|
+
for (const search of searches) {
|
|
374
|
+
const prepareHeaders = {
|
|
375
|
+
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
376
|
+
CentumSuiteAccessToken: centumSuiteAccessToken,
|
|
377
|
+
};
|
|
378
|
+
const paramValue = Object.values(search.queryParams)[0];
|
|
379
|
+
if (!paramValue || paramValue === 'undefined') {
|
|
380
|
+
console.log(`Saltando búsqueda por ${search.description}: parámetro no válido`, search.queryParams);
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
console.log(`Intentando búsqueda por ${search.description}`, {
|
|
384
|
+
url: `${centumUrl}/Clientes`,
|
|
385
|
+
headers: prepareHeaders,
|
|
386
|
+
queryParams: search.queryParams,
|
|
387
|
+
});
|
|
388
|
+
try {
|
|
389
|
+
const response = await (0, api_1.apiRequest)(`${centumUrl}/Clientes`, { headers: prepareHeaders, queryParams: search.queryParams }, this);
|
|
390
|
+
console.log(`Resultado búsqueda por ${search.description}`, {
|
|
391
|
+
CantidadTotalItems: response.CantidadTotalItems,
|
|
392
|
+
});
|
|
393
|
+
if (response.CantidadTotalItems === 1) {
|
|
394
|
+
user = response;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
console.log(`Error en búsqueda de cliente por ${search.description}`, {
|
|
400
|
+
error,
|
|
401
|
+
headers: prepareHeaders,
|
|
402
|
+
queryParams: search.queryParams,
|
|
403
|
+
});
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
const result = user && user.CantidadTotalItems === 1 ? user.Items : [];
|
|
408
|
+
return [this.helpers.returnJsonArray(result)];
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
console.log('💥 Error general en búsqueda de cliente:', error);
|
|
412
|
+
return [this.helpers.returnJsonArray(error.response?.data?.Items || [])];
|
|
413
|
+
}
|
|
414
|
+
case 'listBranches':
|
|
415
|
+
try {
|
|
416
|
+
const dataListBranches = await (0, api_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
|
|
417
|
+
headers,
|
|
418
|
+
}, this);
|
|
419
|
+
return [this.helpers.returnJsonArray(dataListBranches)];
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
console.log(error);
|
|
423
|
+
return [this.helpers.returnJsonArray(error.response.data)];
|
|
424
|
+
}
|
|
425
|
+
case 'json':
|
|
426
|
+
const data = this.getInputData();
|
|
427
|
+
const json = (0, functions_1.createJsonProducts)(data);
|
|
428
|
+
return [this.helpers.returnJsonArray(json)];
|
|
429
|
+
case 'productList':
|
|
430
|
+
try {
|
|
431
|
+
const payload = {
|
|
432
|
+
"IdCliente": 47924,
|
|
433
|
+
"FechaDocumento": "2024-05-31",
|
|
434
|
+
"Habilitado": true,
|
|
435
|
+
"ActivoWeb": true
|
|
436
|
+
};
|
|
437
|
+
const dataProductos = await (0, api_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
438
|
+
method: 'POST',
|
|
439
|
+
body: payload,
|
|
440
|
+
headers
|
|
441
|
+
}, this);
|
|
442
|
+
const items = dataProductos.Articulos?.Items || [];
|
|
443
|
+
const formateoObjeto = items.map((item) => ({
|
|
444
|
+
IdArticulo: item.IdArticulo,
|
|
445
|
+
Codigo: item.Codigo,
|
|
446
|
+
Nombre: item.Nombre,
|
|
447
|
+
NombreFantasia: item.NombreFantasia,
|
|
448
|
+
Habilitado: item.Habilitado,
|
|
449
|
+
ActivoWeb: item.ActivoWeb,
|
|
450
|
+
Precio: item.Precio,
|
|
451
|
+
FechaUltimaActualizacionPrecio: item.FechaUltimaActualizacionPrecio,
|
|
452
|
+
StockDisponible: item.StockDisponible,
|
|
453
|
+
Rubro: item.Rubro ? {
|
|
454
|
+
IdRubro: item.Rubro.IdRubro,
|
|
455
|
+
Codigo: item.Rubro.Codigo,
|
|
456
|
+
Nombre: item.Rubro.Nombre
|
|
457
|
+
} : null,
|
|
458
|
+
SubRubro: item.SubRubro ? {
|
|
459
|
+
IdSubRubro: item.SubRubro.IdSubRubro,
|
|
460
|
+
Codigo: item.SubRubro.Codigo,
|
|
461
|
+
Nombre: item.SubRubro.Nombre,
|
|
462
|
+
IdRubro: item.SubRubro.IdRubro
|
|
463
|
+
} : null,
|
|
464
|
+
CategoriaArticulo: item.CategoriaArticulo ? {
|
|
465
|
+
IdCategoriaArticulo: item.CategoriaArticulo.IdCategoriaArticulo,
|
|
466
|
+
Codigo: item.CategoriaArticulo.Codigo,
|
|
467
|
+
Nombre: item.CategoriaArticulo.Nombre,
|
|
468
|
+
IdSubRubro: item.CategoriaArticulo.IdSubRubro
|
|
469
|
+
} : null
|
|
470
|
+
}));
|
|
471
|
+
return [this.helpers.returnJsonArray(formateoObjeto)];
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
return [this.helpers.returnJsonArray([])];
|
|
475
|
+
}
|
|
476
|
+
default:
|
|
477
|
+
return [this.helpers.returnJsonArray([])];
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
exports.Centum = Centum;
|
|
482
|
+
//# sourceMappingURL=Centum.node.js.map
|