n8n-nodes-prestashop8 1.2.2 → 1.2.4
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.
|
@@ -28,31 +28,18 @@ const n8n_workflow_1 = require("n8n-workflow");
|
|
|
28
28
|
const PrestaShop8_node_description_1 = require("./PrestaShop8.node.description");
|
|
29
29
|
const types_1 = require("./types");
|
|
30
30
|
const utils_1 = require("./utils");
|
|
31
|
-
|
|
32
|
-
function buildHeaders(rawMode) {
|
|
33
|
-
const headers = {};
|
|
34
|
-
if (rawMode) {
|
|
35
|
-
// En mode Raw, demandons explicitement le XML
|
|
36
|
-
headers['Output-Format'] = 'XML';
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
headers['Output-Format'] = 'JSON';
|
|
40
|
-
}
|
|
41
|
-
return headers;
|
|
42
|
-
}
|
|
31
|
+
const fieldMappings_1 = require("./fieldMappings");
|
|
43
32
|
/**
|
|
44
|
-
* Build
|
|
33
|
+
* Build HTTP request options with appropriate headers (consolidated)
|
|
45
34
|
*/
|
|
46
35
|
function buildHttpOptions(method, url, credentials, rawMode, timeout, body) {
|
|
47
36
|
const headers = {};
|
|
48
|
-
//
|
|
49
|
-
if (body &&
|
|
37
|
+
// Add Content-Type for requests with body (POST, PATCH, PUT)
|
|
38
|
+
if (body && ['POST', 'PATCH', 'PUT'].includes(method)) {
|
|
50
39
|
headers['Content-Type'] = 'application/xml';
|
|
51
40
|
}
|
|
52
|
-
// Add Output-Format
|
|
53
|
-
|
|
54
|
-
headers['Output-Format'] = 'JSON';
|
|
55
|
-
}
|
|
41
|
+
// Add Output-Format header based on mode
|
|
42
|
+
headers['Output-Format'] = rawMode ? 'XML' : 'JSON';
|
|
56
43
|
return {
|
|
57
44
|
method,
|
|
58
45
|
url,
|
|
@@ -108,35 +95,7 @@ async function executeHttpRequest(helpers, options, credentials, rawMode, operat
|
|
|
108
95
|
*/
|
|
109
96
|
function collectRequiredFields(executeFunctions, resource, itemIndex) {
|
|
110
97
|
const fieldsToCreate = [];
|
|
111
|
-
const
|
|
112
|
-
products: {
|
|
113
|
-
productName: 'name-1',
|
|
114
|
-
productPrice: 'price',
|
|
115
|
-
productCategoryId: 'id_category_default'
|
|
116
|
-
},
|
|
117
|
-
categories: {
|
|
118
|
-
categoryName: 'name-1',
|
|
119
|
-
categoryParentId: 'id_parent'
|
|
120
|
-
},
|
|
121
|
-
customers: {
|
|
122
|
-
customerFirstname: 'firstname',
|
|
123
|
-
customerLastname: 'lastname',
|
|
124
|
-
customerEmail: 'email'
|
|
125
|
-
},
|
|
126
|
-
addresses: {
|
|
127
|
-
addressFirstname: 'firstname',
|
|
128
|
-
addressLastname: 'lastname',
|
|
129
|
-
addressAddress1: 'address1',
|
|
130
|
-
addressCity: 'city',
|
|
131
|
-
addressCountryId: 'id_country',
|
|
132
|
-
addressCustomerId: 'id_customer'
|
|
133
|
-
},
|
|
134
|
-
manufacturers: {
|
|
135
|
-
manufacturerName: 'name',
|
|
136
|
-
manufacturerActive: 'active'
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const mappings = fieldMappings[resource];
|
|
98
|
+
const mappings = (0, fieldMappings_1.getFieldMappingsForResource)(resource);
|
|
140
99
|
if (mappings) {
|
|
141
100
|
for (const [inputName, fieldName] of Object.entries(mappings)) {
|
|
142
101
|
const value = executeFunctions.getNodeParameter(inputName, itemIndex, '');
|
|
@@ -339,7 +298,7 @@ class PrestaShop8 {
|
|
|
339
298
|
username: credentials.apiKey,
|
|
340
299
|
password: ''
|
|
341
300
|
},
|
|
342
|
-
headers:
|
|
301
|
+
headers: buildHttpOptions('GET', requestUrl, credentials, rawMode, timeout || 30000).headers,
|
|
343
302
|
timeout: timeout || 30000,
|
|
344
303
|
transformResponse: [(data) => data],
|
|
345
304
|
validateStatus: neverError ? () => true : undefined // Accept all status codes if neverError is true
|
|
@@ -347,7 +306,7 @@ class PrestaShop8 {
|
|
|
347
306
|
requestDebugInfo = captureRequestDebugInfo({
|
|
348
307
|
method: 'GET',
|
|
349
308
|
url: requestUrl,
|
|
350
|
-
headers:
|
|
309
|
+
headers: buildHttpOptions('GET', requestUrl, credentials, rawMode, timeout || 30000).headers,
|
|
351
310
|
timeout: timeout
|
|
352
311
|
}, credentials, rawMode, operation, resource);
|
|
353
312
|
requestHeaders = requestDebugInfo.headers;
|
|
@@ -693,7 +652,7 @@ class PrestaShop8 {
|
|
|
693
652
|
username: credentials.apiKey,
|
|
694
653
|
password: ''
|
|
695
654
|
},
|
|
696
|
-
headers:
|
|
655
|
+
headers: buildHttpOptions('GET', requestUrl, credentials, rawMode, timeout || 30000).headers,
|
|
697
656
|
timeout: timeout || 30000,
|
|
698
657
|
transformResponse: [(data) => data],
|
|
699
658
|
validateStatus: neverError ? () => true : undefined // Accept all status codes if neverError is true
|
|
@@ -701,7 +660,7 @@ class PrestaShop8 {
|
|
|
701
660
|
requestDebugInfo = captureRequestDebugInfo({
|
|
702
661
|
method: 'GET',
|
|
703
662
|
url: requestUrl,
|
|
704
|
-
headers:
|
|
663
|
+
headers: buildHttpOptions('GET', requestUrl, credentials, rawMode, timeout || 30000).headers,
|
|
705
664
|
timeout: timeout
|
|
706
665
|
}, credentials, rawMode, operation, resource);
|
|
707
666
|
requestHeaders = requestDebugInfo.headers;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized field mappings for PrestaShop resources
|
|
3
|
+
* Eliminates duplication between node and utils files
|
|
4
|
+
*/
|
|
5
|
+
export interface FieldMapping {
|
|
6
|
+
[inputName: string]: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ResourceFieldMappings {
|
|
9
|
+
[resource: string]: FieldMapping;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Input field name to PrestaShop field name mappings for CREATE operations
|
|
13
|
+
*/
|
|
14
|
+
export declare const CREATE_FIELD_MAPPINGS: ResourceFieldMappings;
|
|
15
|
+
/**
|
|
16
|
+
* CamelCase to PrestaShop field name mappings for UPDATE operations
|
|
17
|
+
*/
|
|
18
|
+
export declare const CAMELCASE_TO_PRESTASHOP_MAPPINGS: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Convert camelCase field name to PrestaShop format
|
|
23
|
+
*/
|
|
24
|
+
export declare function convertFromCamelCase(fieldName: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get field mappings for a specific resource
|
|
27
|
+
*/
|
|
28
|
+
export declare function getFieldMappingsForResource(resource: string): FieldMapping | null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Centralized field mappings for PrestaShop resources
|
|
4
|
+
* Eliminates duplication between node and utils files
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getFieldMappingsForResource = exports.convertFromCamelCase = exports.CAMELCASE_TO_PRESTASHOP_MAPPINGS = exports.CREATE_FIELD_MAPPINGS = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Input field name to PrestaShop field name mappings for CREATE operations
|
|
10
|
+
*/
|
|
11
|
+
exports.CREATE_FIELD_MAPPINGS = {
|
|
12
|
+
products: {
|
|
13
|
+
productName: 'name-1',
|
|
14
|
+
productPrice: 'price',
|
|
15
|
+
productCategoryId: 'id_category_default'
|
|
16
|
+
},
|
|
17
|
+
categories: {
|
|
18
|
+
categoryName: 'name-1',
|
|
19
|
+
categoryParentId: 'id_parent'
|
|
20
|
+
},
|
|
21
|
+
customers: {
|
|
22
|
+
customerFirstname: 'firstname',
|
|
23
|
+
customerLastname: 'lastname',
|
|
24
|
+
customerEmail: 'email'
|
|
25
|
+
},
|
|
26
|
+
addresses: {
|
|
27
|
+
addressFirstname: 'firstname',
|
|
28
|
+
addressLastname: 'lastname',
|
|
29
|
+
addressAddress1: 'address1',
|
|
30
|
+
addressCity: 'city',
|
|
31
|
+
addressCountryId: 'id_country',
|
|
32
|
+
addressCustomerId: 'id_customer'
|
|
33
|
+
},
|
|
34
|
+
manufacturers: {
|
|
35
|
+
manufacturerName: 'name',
|
|
36
|
+
manufacturerActive: 'active'
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* CamelCase to PrestaShop field name mappings for UPDATE operations
|
|
41
|
+
*/
|
|
42
|
+
exports.CAMELCASE_TO_PRESTASHOP_MAPPINGS = {
|
|
43
|
+
'manufacturerId': 'id_manufacturer',
|
|
44
|
+
'categoryId': 'id_category',
|
|
45
|
+
'supplierId': 'id_supplier',
|
|
46
|
+
'customerId': 'id_customer',
|
|
47
|
+
'addressId': 'id_address',
|
|
48
|
+
'countryId': 'id_country',
|
|
49
|
+
'stateId': 'id_state',
|
|
50
|
+
'zoneId': 'id_zone',
|
|
51
|
+
'currencyId': 'id_currency',
|
|
52
|
+
'languageId': 'id_language',
|
|
53
|
+
'groupId': 'id_group',
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Convert camelCase field name to PrestaShop format
|
|
57
|
+
*/
|
|
58
|
+
function convertFromCamelCase(fieldName) {
|
|
59
|
+
// Check specific mappings first
|
|
60
|
+
if (exports.CAMELCASE_TO_PRESTASHOP_MAPPINGS[fieldName]) {
|
|
61
|
+
return exports.CAMELCASE_TO_PRESTASHOP_MAPPINGS[fieldName];
|
|
62
|
+
}
|
|
63
|
+
// Generic camelCase to snake_case conversion
|
|
64
|
+
return fieldName
|
|
65
|
+
.replace(/([A-Z])/g, '_$1')
|
|
66
|
+
.toLowerCase()
|
|
67
|
+
.replace(/^_/, ''); // Remove leading underscore
|
|
68
|
+
}
|
|
69
|
+
exports.convertFromCamelCase = convertFromCamelCase;
|
|
70
|
+
/**
|
|
71
|
+
* Get field mappings for a specific resource
|
|
72
|
+
*/
|
|
73
|
+
function getFieldMappingsForResource(resource) {
|
|
74
|
+
return exports.CREATE_FIELD_MAPPINGS[resource] || null;
|
|
75
|
+
}
|
|
76
|
+
exports.getFieldMappingsForResource = getFieldMappingsForResource;
|
|
@@ -41,7 +41,7 @@ export declare function buildCreateXml(resource: string, fields: Array<{
|
|
|
41
41
|
/**
|
|
42
42
|
* Builds PrestaShop XML for Update operations using key-value pairs
|
|
43
43
|
*/
|
|
44
|
-
export declare function buildUpdateXml(resource: string, id: string, fields: Array<{
|
|
44
|
+
export declare function buildUpdateXml(resource: string, id: string | number, fields: Array<{
|
|
45
45
|
name: string;
|
|
46
46
|
value: string;
|
|
47
47
|
}>): string;
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.validateDataForResource = exports.validateFieldsForCreate = exports.REQUIRED_FIELDS_BY_RESOURCE = exports.buildUpdateXml = exports.buildCreateXml = exports.buildUrlWithFilters = exports.parseXmlToJson = exports.buildPrestashopXml = exports.simplifyPrestashopResponse = exports.processResponseForMode = exports.processDisplayParameter = exports.processSortParameter = exports.extractPrestashopError = void 0;
|
|
27
27
|
const xml2js = __importStar(require("xml2js"));
|
|
28
28
|
const js2xmlparser = __importStar(require("js2xmlparser"));
|
|
29
|
+
const fieldMappings_1 = require("./fieldMappings");
|
|
29
30
|
/**
|
|
30
31
|
* Clean error message by removing PHP warnings and debug info
|
|
31
32
|
*/
|
|
@@ -67,10 +68,8 @@ function extractPrestashopError(error) {
|
|
|
67
68
|
// If it's an axios error with response
|
|
68
69
|
if (error.response && error.response.data) {
|
|
69
70
|
const data = error.response.data;
|
|
70
|
-
// Debug logging for complex error structures
|
|
71
|
-
|
|
72
|
-
console.log('PrestaShop Error Structure:', JSON.stringify(data, null, 2));
|
|
73
|
-
}
|
|
71
|
+
// Debug logging for complex error structures (only in debug mode)
|
|
72
|
+
// Note: Removed console.log to prevent production log pollution
|
|
74
73
|
// Try to parse XML error response
|
|
75
74
|
if (typeof data === 'string' && data.includes('<error>')) {
|
|
76
75
|
const errorMatch = data.match(/<error><!\[CDATA\[(.+?)\]\]><\/error>/);
|
|
@@ -342,7 +341,7 @@ function convertSimplifiedToPrestaShop(data, resource) {
|
|
|
342
341
|
const converted = {};
|
|
343
342
|
const associations = {};
|
|
344
343
|
for (const [key, value] of Object.entries(data)) {
|
|
345
|
-
const prestashopKey = convertFromCamelCase(key);
|
|
344
|
+
const prestashopKey = (0, fieldMappings_1.convertFromCamelCase)(key);
|
|
346
345
|
// Detect associations (arrays of IDs)
|
|
347
346
|
if (Array.isArray(value) && value.every(v => typeof v === 'number' || typeof v === 'string')) {
|
|
348
347
|
associations[prestashopKey] = {
|
|
@@ -359,38 +358,7 @@ function convertSimplifiedToPrestaShop(data, resource) {
|
|
|
359
358
|
}
|
|
360
359
|
return converted;
|
|
361
360
|
}
|
|
362
|
-
|
|
363
|
-
* Converts camelCase to snake_case with PrestaShop prefixes
|
|
364
|
-
*/
|
|
365
|
-
function convertFromCamelCase(fieldName) {
|
|
366
|
-
// Map certain special fields
|
|
367
|
-
const fieldMappings = {
|
|
368
|
-
'manufacturerId': 'id_manufacturer',
|
|
369
|
-
'categoryId': 'id_category',
|
|
370
|
-
'supplierId': 'id_supplier',
|
|
371
|
-
'customerId': 'id_customer',
|
|
372
|
-
'orderId': 'id_order',
|
|
373
|
-
'productId': 'id_product',
|
|
374
|
-
'carrierId': 'id_carrier',
|
|
375
|
-
'currencyId': 'id_currency',
|
|
376
|
-
'languageId': 'id_language',
|
|
377
|
-
'shopId': 'id_shop',
|
|
378
|
-
'taxId': 'id_tax',
|
|
379
|
-
'zoneId': 'id_zone',
|
|
380
|
-
'countryId': 'id_country',
|
|
381
|
-
'stateId': 'id_state',
|
|
382
|
-
'addressId': 'id_address',
|
|
383
|
-
'groupId': 'id_group',
|
|
384
|
-
};
|
|
385
|
-
if (fieldMappings[fieldName]) {
|
|
386
|
-
return fieldMappings[fieldName];
|
|
387
|
-
}
|
|
388
|
-
// Generic camelCase to snake_case conversion
|
|
389
|
-
return fieldName
|
|
390
|
-
.replace(/([A-Z])/g, '_$1')
|
|
391
|
-
.toLowerCase()
|
|
392
|
-
.replace(/^_/, '');
|
|
393
|
-
}
|
|
361
|
+
// convertFromCamelCase function moved to fieldMappings.ts for centralization
|
|
394
362
|
/**
|
|
395
363
|
* Obtient tous les champs string pour CDATA
|
|
396
364
|
*/
|
|
@@ -459,7 +427,9 @@ exports.buildUrlWithFilters = buildUrlWithFilters;
|
|
|
459
427
|
* Escapes XML special characters
|
|
460
428
|
*/
|
|
461
429
|
function escapeXml(unsafe) {
|
|
462
|
-
|
|
430
|
+
// Convert to string if not already
|
|
431
|
+
const str = unsafe !== null && unsafe !== undefined ? String(unsafe) : '';
|
|
432
|
+
return str.replace(/[<>&'"]/g, function (c) {
|
|
463
433
|
switch (c) {
|
|
464
434
|
case '<': return '<';
|
|
465
435
|
case '>': return '>';
|
package/package.json
CHANGED