ti2-tourplan 1.0.19 → 1.0.21
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/index.js +37 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -33,9 +33,9 @@ const getHeaders = ({ length }) => ({
|
|
|
33
33
|
'Content-Length': length,
|
|
34
34
|
});
|
|
35
35
|
const wildcardMatch = (wildcard, str) => {
|
|
36
|
-
const w = wildcard.replace(/[.+^${}()|[\]\\]/g, '\\$&'); // regexp escape
|
|
37
|
-
const re = new RegExp(
|
|
38
|
-
return re.test(str
|
|
36
|
+
const w = wildcard.replace(/\s/g, '').replace(/[.+^${}()|[\]\\]/g, '\\$&'); // regexp escape
|
|
37
|
+
const re = new RegExp(`${w.replace(/\*/g, '.*').replace(/\?/g, '.')}`, 'i');
|
|
38
|
+
return re.test(str.replace(/\s/g, ''));
|
|
39
39
|
};
|
|
40
40
|
class Plugin {
|
|
41
41
|
constructor(params = {}) { // we get the env variables from here
|
|
@@ -85,23 +85,24 @@ class Plugin {
|
|
|
85
85
|
data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
|
|
86
86
|
let replyObj;
|
|
87
87
|
let errorStr;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
88
|
+
// can't use proxy because of the static IP thing, darn
|
|
89
|
+
// if (this.xmlProxyUrl) {
|
|
90
|
+
// // use pyfilematch xmlproxy
|
|
91
|
+
// try {
|
|
92
|
+
// replyObj = R.path(['data'], await axios({
|
|
93
|
+
// method: 'post',
|
|
94
|
+
// url: `${this.xmlProxyUrl}/xmlproxy`,
|
|
95
|
+
// data: {
|
|
96
|
+
// url: endpoint,
|
|
97
|
+
// data,
|
|
98
|
+
// headers: getHeaders({ length: `${data.length}` }),
|
|
99
|
+
// },
|
|
100
|
+
// }));
|
|
101
|
+
// } catch (err) {
|
|
102
|
+
// console.log('error in calling pyfilematch xmlproxy', err);
|
|
103
|
+
// errorStr = `error in calling pyfilematch xmlproxy: ${err}`;
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
105
106
|
if (!replyObj) {
|
|
106
107
|
// in case of error /xmlproxy, fallback to call tourplan directly
|
|
107
108
|
// and then use pyfilematch xml2json to parse the xml
|
|
@@ -313,8 +314,9 @@ class Plugin {
|
|
|
313
314
|
hostConnectEndpoint,
|
|
314
315
|
hostConnectAgentID,
|
|
315
316
|
hostConnectAgentPassword,
|
|
317
|
+
configuration,
|
|
316
318
|
},
|
|
317
|
-
payload: { optionId, productName },
|
|
319
|
+
payload: { optionId, productName, skipFilter },
|
|
318
320
|
}) {
|
|
319
321
|
const model = {
|
|
320
322
|
OptionInfoRequest: {
|
|
@@ -343,6 +345,12 @@ class Plugin {
|
|
|
343
345
|
if (replyObj === 'useFixture') {
|
|
344
346
|
products = require('./__fixtures__/fullacoptionlist.json');
|
|
345
347
|
} else {
|
|
348
|
+
const shouldFilter = Boolean(
|
|
349
|
+
productName
|
|
350
|
+
|| (!skipFilter
|
|
351
|
+
&& configuration
|
|
352
|
+
&& configuration.productFilters),
|
|
353
|
+
);
|
|
346
354
|
products = R.call(R.compose(
|
|
347
355
|
R.map(optionsGroupedBySupplierId => {
|
|
348
356
|
const supplierData = {
|
|
@@ -358,7 +366,7 @@ class Plugin {
|
|
|
358
366
|
}),
|
|
359
367
|
R.values,
|
|
360
368
|
R.groupBy(R.path(['OptGeneral', 'SupplierId'])),
|
|
361
|
-
|
|
369
|
+
shouldFilter ? R.filter(o => {
|
|
362
370
|
const str = `${
|
|
363
371
|
R.path(['OptGeneral', 'Description'], o)
|
|
364
372
|
} ${
|
|
@@ -368,7 +376,13 @@ class Plugin {
|
|
|
368
376
|
} ${
|
|
369
377
|
R.path(['OptGeneral', 'SupplierName'], o)
|
|
370
378
|
}`;
|
|
371
|
-
|
|
379
|
+
if (productName) {
|
|
380
|
+
return wildcardMatch(productName, str);
|
|
381
|
+
}
|
|
382
|
+
if (configuration && configuration.productFilters) {
|
|
383
|
+
return configuration.productFilters.some(filter => wildcardMatch(filter, str));
|
|
384
|
+
}
|
|
385
|
+
return true;
|
|
372
386
|
}) : R.identity,
|
|
373
387
|
root => {
|
|
374
388
|
const options = R.pathOr([], ['OptionInfoReply', 'Option'], root);
|