ti2-tourplan 1.0.20 → 1.0.22

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 CHANGED
@@ -33,9 +33,40 @@ 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(`^${w.replace(/\*/g, '.*').replace(/\?/g, '.')}$`, 'i');
38
- return re.test(str); // remove last 'i' above to have case sensitive
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
+ };
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
+ };
39
70
  };
40
71
  class Plugin {
41
72
  constructor(params = {}) { // we get the env variables from here
@@ -314,8 +345,9 @@ class Plugin {
314
345
  hostConnectEndpoint,
315
346
  hostConnectAgentID,
316
347
  hostConnectAgentPassword,
348
+ configuration,
317
349
  },
318
- payload: { optionId, productName },
350
+ payload: { optionId, skipFilter, forceRefresh },
319
351
  }) {
320
352
  const model = {
321
353
  OptionInfoRequest: {
@@ -338,17 +370,27 @@ class Plugin {
338
370
  fnParams: [model],
339
371
  fn: () => this.callTourplan(payload),
340
372
  ttl: 60 * 60 * 24, // 24 hours
341
- forceRefresh: false,
373
+ forceRefresh: Boolean(forceRefresh),
342
374
  });
343
375
  let products = [];
344
376
  if (replyObj === 'useFixture') {
345
377
  products = require('./__fixtures__/fullacoptionlist.json');
346
378
  } else {
379
+ const shouldFilter = Boolean(!skipFilter
380
+ && configuration
381
+ && configuration.productFilters);
382
+ const {
383
+ filters: productFilters,
384
+ filterPlaceMap,
385
+ } = convertProductFilters(configuration.productFilters);
347
386
  products = R.call(R.compose(
348
387
  R.map(optionsGroupedBySupplierId => {
388
+ const OptGeneral = R.pathOr({}, [0, 'OptGeneral'], optionsGroupedBySupplierId);
349
389
  const supplierData = {
350
- supplierId: R.path([0, 'OptGeneral', 'SupplierId'], optionsGroupedBySupplierId),
351
- supplierName: R.path([0, 'OptGeneral', 'SupplierName'], optionsGroupedBySupplierId),
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(';'),
352
394
  };
353
395
  return translateTPOption({
354
396
  supplierData,
@@ -359,17 +401,21 @@ class Plugin {
359
401
  }),
360
402
  R.values,
361
403
  R.groupBy(R.path(['OptGeneral', 'SupplierId'])),
362
- productName ? R.filter(o => {
363
- const str = `${
364
- R.path(['OptGeneral', 'Description'], o)
365
- } ${
366
- R.path(['Opt'], o)
367
- } ${
368
- R.path(['OptGeneral', 'SupplierId'], o)
369
- } ${
370
- R.path(['OptGeneral', 'SupplierName'], o)
371
- }`;
372
- return wildcardMatch(productName, str);
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
+ };
373
419
  }) : R.identity,
374
420
  root => {
375
421
  const options = R.pathOr([], ['OptionInfoReply', 'Option'], root);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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