ti2-tourplan 1.0.21 → 1.0.23
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 +59 -26
- package/package.json +1 -1
- package/resolvers/product.js +3 -0
package/index.js
CHANGED
|
@@ -37,6 +37,37 @@ const wildcardMatch = (wildcard, str) => {
|
|
|
37
37
|
const re = new RegExp(`${w.replace(/\*/g, '.*').replace(/\?/g, '.')}`, 'i');
|
|
38
38
|
return re.test(str.replace(/\s/g, ''));
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
const convertProductFilters = (productFilters = []) => {
|
|
42
|
+
/*
|
|
43
|
+
productFilters: [
|
|
44
|
+
{
|
|
45
|
+
place: 'London',
|
|
46
|
+
filters: ['ACLUXE'],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
place: 'Cambridge',
|
|
50
|
+
filters: ['LONEFBLEPARFITENT', 'ACLUXE'],
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
result: {
|
|
54
|
+
filters: ['ACLUXE', 'LONEFBLEPARFITENT'],
|
|
55
|
+
filterPlaceMap: {
|
|
56
|
+
ACLUXE: ['London','Cambridge'],
|
|
57
|
+
LONEFBLEPARFITENT: ['Cambridge'],
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
*/
|
|
61
|
+
const groupedByfilter = R.call(R.compose(
|
|
62
|
+
R.groupBy(R.prop('filter')),
|
|
63
|
+
R.flatten,
|
|
64
|
+
R.map(obj => obj.filters.map(str => ({ filter: str, place: obj.place }))),
|
|
65
|
+
), productFilters);
|
|
66
|
+
return {
|
|
67
|
+
filters: R.keys(groupedByfilter),
|
|
68
|
+
filterPlaceMap: R.map(arr => arr.map(o => o.place), groupedByfilter),
|
|
69
|
+
};
|
|
70
|
+
};
|
|
40
71
|
class Plugin {
|
|
41
72
|
constructor(params = {}) { // we get the env variables from here
|
|
42
73
|
Object.entries(params).forEach(([attr, value]) => {
|
|
@@ -316,7 +347,7 @@ class Plugin {
|
|
|
316
347
|
hostConnectAgentPassword,
|
|
317
348
|
configuration,
|
|
318
349
|
},
|
|
319
|
-
payload: { optionId,
|
|
350
|
+
payload: { optionId, skipFilter, forceRefresh },
|
|
320
351
|
}) {
|
|
321
352
|
const model = {
|
|
322
353
|
OptionInfoRequest: {
|
|
@@ -339,23 +370,27 @@ class Plugin {
|
|
|
339
370
|
fnParams: [model],
|
|
340
371
|
fn: () => this.callTourplan(payload),
|
|
341
372
|
ttl: 60 * 60 * 24, // 24 hours
|
|
342
|
-
forceRefresh:
|
|
373
|
+
forceRefresh: Boolean(forceRefresh),
|
|
343
374
|
});
|
|
344
375
|
let products = [];
|
|
345
376
|
if (replyObj === 'useFixture') {
|
|
346
377
|
products = require('./__fixtures__/fullacoptionlist.json');
|
|
347
378
|
} else {
|
|
348
|
-
const shouldFilter = Boolean(
|
|
349
|
-
productName
|
|
350
|
-
|| (!skipFilter
|
|
379
|
+
const shouldFilter = Boolean(!skipFilter
|
|
351
380
|
&& configuration
|
|
352
|
-
&& configuration.productFilters)
|
|
353
|
-
|
|
381
|
+
&& configuration.productFilters);
|
|
382
|
+
const {
|
|
383
|
+
filters: productFilters,
|
|
384
|
+
filterPlaceMap,
|
|
385
|
+
} = convertProductFilters(configuration ? configuration.productFilters : []);
|
|
354
386
|
products = R.call(R.compose(
|
|
355
387
|
R.map(optionsGroupedBySupplierId => {
|
|
388
|
+
const OptGeneral = R.pathOr({}, [0, 'OptGeneral'], optionsGroupedBySupplierId);
|
|
356
389
|
const supplierData = {
|
|
357
|
-
supplierId: R.path([
|
|
358
|
-
supplierName: R.path([
|
|
390
|
+
supplierId: R.path(['SupplierId'], OptGeneral),
|
|
391
|
+
supplierName: R.path(['SupplierName'], OptGeneral),
|
|
392
|
+
supplierAddress: `${R.pathOr('', ['Address1'], OptGeneral)}, ${R.pathOr('', ['Address2'], OptGeneral)}, ${R.pathOr('', ['Address3'], OptGeneral)}, ${R.pathOr('', ['Address4'], OptGeneral)}, ${R.pathOr('', ['Address5'], OptGeneral)}`,
|
|
393
|
+
supplierPlaces: R.pathOr([], [0, 'supplierPlaces'], optionsGroupedBySupplierId).join(';'),
|
|
359
394
|
};
|
|
360
395
|
return translateTPOption({
|
|
361
396
|
supplierData,
|
|
@@ -366,23 +401,21 @@ class Plugin {
|
|
|
366
401
|
}),
|
|
367
402
|
R.values,
|
|
368
403
|
R.groupBy(R.path(['OptGeneral', 'SupplierId'])),
|
|
369
|
-
shouldFilter ? R.filter(o =>
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
return true;
|
|
404
|
+
shouldFilter ? R.filter(o => o.supplierPlaces || o.optionPlaces) : R.identity,
|
|
405
|
+
shouldFilter ? R.map(o => {
|
|
406
|
+
const str = o.Opt;
|
|
407
|
+
let supplierCodeMatch;
|
|
408
|
+
let optionCodeMatch;
|
|
409
|
+
productFilters.forEach(filter => {
|
|
410
|
+
const doesMatch = wildcardMatch(filter, str);
|
|
411
|
+
if (filter.length < 10 && doesMatch) supplierCodeMatch = filter;
|
|
412
|
+
if (filter.length > 10 && doesMatch) optionCodeMatch = filter;
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
...o,
|
|
416
|
+
supplierPlaces: filterPlaceMap[supplierCodeMatch],
|
|
417
|
+
optionPlaces: filterPlaceMap[optionCodeMatch],
|
|
418
|
+
};
|
|
386
419
|
}) : R.identity,
|
|
387
420
|
root => {
|
|
388
421
|
const options = R.pathOr([], ['OptionInfoReply', 'Option'], root);
|
package/package.json
CHANGED
package/resolvers/product.js
CHANGED
|
@@ -38,6 +38,8 @@ const translateTPOption = ({ optionsGroupedBySupplierId, supplierData }) => {
|
|
|
38
38
|
return {
|
|
39
39
|
productId: supplierData.supplierId,
|
|
40
40
|
productName: supplierData.supplierName,
|
|
41
|
+
address: supplierData.supplierAddress,
|
|
42
|
+
forPlaces: supplierData.supplierPlaces,
|
|
41
43
|
// Guides, Accommodation, Transfers, Entrance Fees, Meals, Other
|
|
42
44
|
// category: R.path([0, 'OptGeneral', 'ButtonName'], optionsGroupedBySupplierId),
|
|
43
45
|
options: optionsGroupedBySupplierId.map(option => {
|
|
@@ -47,6 +49,7 @@ const translateTPOption = ({ optionsGroupedBySupplierId, supplierData }) => {
|
|
|
47
49
|
optionName: `${R.path(['OptGeneral', 'Description'], option)}${
|
|
48
50
|
comment ? `-${comment}` : ''
|
|
49
51
|
}`,
|
|
52
|
+
forPlaces: R.pathOr([], ['optionPlaces'], option).join(', ') || supplierData.supplierPlaces,
|
|
50
53
|
};
|
|
51
54
|
/*
|
|
52
55
|
SType: One character that specifies the service type of the
|