ti2-tourplan 1.0.20 → 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 +19 -6
- 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
|
|
@@ -314,8 +314,9 @@ class Plugin {
|
|
|
314
314
|
hostConnectEndpoint,
|
|
315
315
|
hostConnectAgentID,
|
|
316
316
|
hostConnectAgentPassword,
|
|
317
|
+
configuration,
|
|
317
318
|
},
|
|
318
|
-
payload: { optionId, productName },
|
|
319
|
+
payload: { optionId, productName, skipFilter },
|
|
319
320
|
}) {
|
|
320
321
|
const model = {
|
|
321
322
|
OptionInfoRequest: {
|
|
@@ -344,6 +345,12 @@ class Plugin {
|
|
|
344
345
|
if (replyObj === 'useFixture') {
|
|
345
346
|
products = require('./__fixtures__/fullacoptionlist.json');
|
|
346
347
|
} else {
|
|
348
|
+
const shouldFilter = Boolean(
|
|
349
|
+
productName
|
|
350
|
+
|| (!skipFilter
|
|
351
|
+
&& configuration
|
|
352
|
+
&& configuration.productFilters),
|
|
353
|
+
);
|
|
347
354
|
products = R.call(R.compose(
|
|
348
355
|
R.map(optionsGroupedBySupplierId => {
|
|
349
356
|
const supplierData = {
|
|
@@ -359,7 +366,7 @@ class Plugin {
|
|
|
359
366
|
}),
|
|
360
367
|
R.values,
|
|
361
368
|
R.groupBy(R.path(['OptGeneral', 'SupplierId'])),
|
|
362
|
-
|
|
369
|
+
shouldFilter ? R.filter(o => {
|
|
363
370
|
const str = `${
|
|
364
371
|
R.path(['OptGeneral', 'Description'], o)
|
|
365
372
|
} ${
|
|
@@ -369,7 +376,13 @@ class Plugin {
|
|
|
369
376
|
} ${
|
|
370
377
|
R.path(['OptGeneral', 'SupplierName'], o)
|
|
371
378
|
}`;
|
|
372
|
-
|
|
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;
|
|
373
386
|
}) : R.identity,
|
|
374
387
|
root => {
|
|
375
388
|
const options = R.pathOr([], ['OptionInfoReply', 'Option'], root);
|