ti2-tourplan 1.0.25 → 1.0.27

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.
Files changed (2) hide show
  1. package/index.js +60 -260
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const axiosRaw = require('axios');
2
- // const Promise = require('bluebird');
2
+ const Promise = require('bluebird');
3
3
  const R = require('ramda');
4
4
  const assert = require('assert');
5
5
  const moment = require('moment');
@@ -364,14 +364,7 @@ class Plugin {
364
364
  xmlOptions: hostConnectXmlOptions,
365
365
  };
366
366
  // use cache if we are getting the full list
367
- const replyObj = optionId
368
- ? await this.callTourplan(payload)
369
- : await this.cache.getOrExec({
370
- fnParams: [model],
371
- fn: () => this.callTourplan(payload),
372
- ttl: 60 * 60 * 24, // 24 hours
373
- forceRefresh: Boolean(forceRefresh),
374
- });
367
+ const replyObj = await this.callTourplan(payload);
375
368
  let products = [];
376
369
  if (replyObj === 'useFixture') {
377
370
  products = require('./__fixtures__/fullacoptionlist.json');
@@ -470,256 +463,6 @@ class Plugin {
470
463
  };
471
464
  }
472
465
 
473
- async getProductPackages() {
474
- return [
475
- {
476
- packageId: 'a1b2c3d4-e8e8-11ec-8fea-0242ac120002',
477
- packageName: "Afternoon at St Paul's Cathedral and Kensington Palace (half day)",
478
- items: [],
479
- },
480
- {
481
- packageId: 'a1b2c3d4-e8e8-11ec-8feb-0242ac120002',
482
- packageName: 'Beefeater Day Out',
483
- items: [],
484
- },
485
- {
486
- packageId: 'a1b2c3d4-e8e8-11ec-8fec-0242ac120002',
487
- packageName: 'Brighton and Hove tour',
488
- items: [],
489
- },
490
- {
491
- packageId: 'a1b2c3d4-e8e8-11ec-8fed-0242ac120002',
492
- packageName: 'Buckingham Palace & Kensington Palace (full day)',
493
- items: [],
494
- },
495
- {
496
- packageId: 'a1b2c3d4-e8e8-11ec-8fee-0242ac120002',
497
- packageName: 'Buckingham Palace and Hampton Court Palace (full day)',
498
- items: [],
499
- },
500
- {
501
- packageId: 'a1b2c3d4-e8e8-11ec-8fef-0242ac120002',
502
- packageName: 'Buckingham Palace and Windsor Castle (full day)',
503
- items: [],
504
- },
505
- {
506
- packageId: 'a1b2c3d4-e8e8-11ec-8ff0-0242ac120002',
507
- packageName: 'Canterbury & Dover day trip',
508
- items: [],
509
- },
510
- {
511
- packageId: 'a1b2c3d4-e8e8-11ec-8ff1-0242ac120002',
512
- packageName: 'Canterbury day trip',
513
- items: [],
514
- },
515
- {
516
- packageId: 'a1b2c3d4-e8e8-11ec-8ff2-0242ac120002',
517
- packageName: 'Churchill War Rooms and the Imperial War Museum',
518
- items: [],
519
- },
520
- {
521
- packageId: 'a1b2c3d4-e8e8-11ec-8ff3-0242ac120002',
522
- packageName: 'Churchill War Rooms, the Changing of the Guards & the Tower of London',
523
- items: [],
524
- },
525
- {
526
- packageId: 'a1b2c3d4-e8e8-11ec-8ff4-0242ac120002',
527
- packageName: "City walking tour, St Paul's Cathedral and theatre performance at the Globe",
528
- items: [],
529
- },
530
- {
531
- packageId: 'a1b2c3d4-e8e8-11ec-8ff5-0242ac120002',
532
- packageName: 'Downton Abbey day trip',
533
- items: [],
534
- },
535
- {
536
- packageId: 'a1b2c3d4-e8e8-11ec-8ff6-0242ac120002',
537
- packageName: "Guided tour of St Paul's Cathedral",
538
- items: [],
539
- },
540
- {
541
- packageId: 'a1b2c3d4-e8e8-11ec-8ff7-0242ac120002',
542
- packageName: 'Hampton Court Palace (half day)',
543
- items: [],
544
- },
545
- {
546
- packageId: 'a1b2c3d4-e8e8-11ec-8ff8-0242ac120002',
547
- packageName: 'Hampton Court Palace and Windsor Castle (full day)',
548
- items: [],
549
- },
550
- {
551
- packageId: 'a1b2c3d4-e8e8-11ec-8ff9-0242ac120002',
552
- packageName: 'Kensington Palace and the Tower of London (full day)',
553
- items: [
554
- {
555
- itemId: 'LONGUACLUXELONFDG',
556
- itemType: 'option',
557
- },
558
- {
559
- itemId: 'LONEFKENPALFIKENI',
560
- itemType: 'option',
561
- },
562
- {
563
- itemId: 'LONEFTOWLONFITOWL',
564
- itemType: 'option',
565
- },
566
- ],
567
- },
568
- {
569
- packageId: 'a1b2c3d4-e8e8-11ec-8ffa-0242ac120002',
570
- packageName: 'Kensington Palace and Westminster Abbey (half day)',
571
- items: [],
572
- },
573
- {
574
- packageId: 'a1b2c3d4-e8e8-11ec-8ffb-0242ac120002',
575
- packageName: "Late afternoon visit to St Paul's Cathedral",
576
- items: [],
577
- },
578
- {
579
- packageId: 'a1b2c3d4-e8e8-11ec-8ffc-0242ac120002',
580
- packageName: "St Paul's Cathedral & Kensington Palace (half day)",
581
- items: [],
582
- },
583
- {
584
- packageId: 'a1b2c3d4-e8e8-11ec-8ffd-0242ac120002',
585
- packageName: "St Paul's Cathedral and the Churchill War Rooms (half day)",
586
- items: [],
587
- },
588
- {
589
- packageId: 'a1b2c3d4-e8e8-11ec-8ffe-0242ac120002',
590
- packageName: "St Paul's Cathedral and Westminster Abbey (half day)",
591
- items: [
592
- {
593
- itemId: 'LONGUACLUXELONHDG',
594
- itemType: 'option',
595
- },
596
- {
597
- itemId: 'LONEFSTPCATFITSPC',
598
- itemType: 'option',
599
- },
600
- {
601
- itemId: 'LONSSGOLTOUGTWAP',
602
- itemType: 'option',
603
- },
604
- ],
605
- },
606
- {
607
- packageId: 'a1b2c3d4-e8e8-11ec-8fff-0242ac120002',
608
- packageName: "St Paul's Cathedral, Changing of the Guard and Tower of London (full day)",
609
- items: [
610
- {
611
- itemId: 'LONGUACLUXELONFDG',
612
- itemType: 'option',
613
- },
614
- {
615
- itemId: 'LONEFTOWLONFITOWL',
616
- itemType: 'option',
617
- },
618
- {
619
- itemId: 'LONEFGOLTOUGT105N',
620
- itemType: 'option',
621
- },
622
- ],
623
- },
624
- {
625
- packageId: 'a1b2c3d4-e8e8-11ec-9000-0242ac120002',
626
- packageName: "St Paul's Cathedral, Kensington Palace and Westminster Abbey (full day)",
627
- items: [],
628
- },
629
- {
630
- packageId: 'a1b2c3d4-e8e8-11ec-9001-0242ac120002',
631
- packageName: 'St Pauls and Tower of London',
632
- items: [],
633
- },
634
- {
635
- packageId: 'a1b2c3d4-e8e8-11ec-9002-0242ac120002',
636
- packageName: 'Stonehenge (Full Day from London)',
637
- items: [],
638
- },
639
- {
640
- packageId: 'a1b2c3d4-e8e8-11ec-9003-0242ac120002',
641
- packageName: 'Stonehenge, Lacock and Avebury (full day)',
642
- items: [],
643
- },
644
- {
645
- packageId: 'a1b2c3d4-e8e8-11ec-9004-0242ac120002',
646
- packageName: 'The White Cliffs of Dover, Dover Castle, & military tunnels (full day)',
647
- items: [],
648
- },
649
- {
650
- packageId: 'a1b2c3d4-e8e8-11ec-9005-0242ac120002',
651
- packageName: 'Tower of London by boat',
652
- items: [
653
- {
654
- itemId: 'LONGUACLUXELONHDG',
655
- itemType: 'option',
656
- },
657
- {
658
- itemId: 'LONSSTHACLISINLON',
659
- itemType: 'option',
660
- },
661
- {
662
- itemId: 'LONEFTOWLONFITOWL',
663
- itemType: 'option',
664
- },
665
- ],
666
- },
667
- {
668
- packageId: 'a1b2c3d4-e8e8-11ec-9006-0242ac120002',
669
- packageName: 'Warner Bros.- The Making of Harry Potter (non refundable)',
670
- items: [],
671
- },
672
- {
673
- packageId: 'a1b2c3d4-e8e8-11ec-9007-0242ac120002',
674
- packageName: 'Westminster Abbey and Buckingham Palace (half day)',
675
- items: [],
676
- },
677
- {
678
- packageId: 'a1b2c3d4-e8e8-11ec-9008-0242ac120002',
679
- packageName: 'Westminster Abbey and Changing of the Guard',
680
- items: [
681
- {
682
- itemId: 'LONGUACLUXELONHDG',
683
- itemType: 'option',
684
- },
685
- {
686
- itemId: 'LONEFWESABBWESABB',
687
- itemType: 'option',
688
- },
689
- ],
690
- },
691
- {
692
- packageId: 'a1b2c3d4-e8e8-11ec-9009-0242ac120002',
693
- packageName: 'Westminster Abbey and the Tower by boat (full day)',
694
- items: [],
695
- },
696
- {
697
- packageId: 'a1b2c3d4-e8e8-11ec-900a-0242ac120002',
698
- packageName: 'Westminster Abbey, Changing of the Guard & Kensington Palace (full day)',
699
- items: [],
700
- },
701
- {
702
- packageId: 'a1b2c3d4-e8e8-11ec-900b-0242ac120002',
703
- packageName: 'Westminster Abbey, Changing of the Guard and Buckingham Palace',
704
- items: [],
705
- },
706
- {
707
- packageId: 'a1b2c3d4-e8e8-11ec-900c-0242ac120002',
708
- packageName: 'Westminster and the Tower of London (half day)',
709
- items: [],
710
- },
711
- {
712
- packageId: 'a1b2c3d4-e8e8-11ec-900d-0242ac120002',
713
- packageName: 'Westminster, Changing of the Guard and the Tower of London (full day)',
714
- items: [],
715
- },
716
- {
717
- packageId: 'a1b2c3d4-e8e8-11ec-900e-0242ac120002',
718
- packageName: 'Windsor Castle (half day)',
719
- items: [],
720
- },
721
- ];
722
- }
723
466
 
724
467
  async searchQuote({
725
468
  axios,
@@ -787,7 +530,6 @@ class Plugin {
787
530
  axios,
788
531
  xmlOptions: hostConnectXmlOptions,
789
532
  });
790
- console.log('replyObj', replyObj);
791
533
  return {
792
534
  message: R.path(['AddServiceReply', 'Status'], replyObj)
793
535
  === 'NO' ? 'Service cannot be added to quote' : '',
@@ -815,6 +557,64 @@ class Plugin {
815
557
  customFields,
816
558
  };
817
559
  }
560
+
561
+ async searchBooking({
562
+ token: {
563
+ hostConnectAgentID,
564
+ hostConnectAgentPassword,
565
+ hostConnectEndpoint,
566
+ },
567
+ axios,
568
+ payload: {
569
+ purchaseDateStart,
570
+ purchaseDateEnd,
571
+ bookingId,
572
+ },
573
+ }) {
574
+ const getPayload = (RequestType, RequestInput) => ({
575
+ model: {
576
+ [RequestType]: {
577
+ AgentID: hostConnectAgentID,
578
+ Password: hostConnectAgentPassword,
579
+ ...RequestInput,
580
+ },
581
+ },
582
+ endpoint: hostConnectEndpoint,
583
+ axios,
584
+ xmlOptions: hostConnectXmlOptions,
585
+ });
586
+ const listBookingPayload = getPayload('ListBookingsRequest', {
587
+ EnteredDateFrom: purchaseDateStart || moment().subtract(6, 'month').format('YYYY-MM-DD'),
588
+ EnteredDateTo: purchaseDateEnd || moment().format('YYYY-MM-DD'),
589
+ });
590
+ const allSearches = bookingId
591
+ ? ['BookingId', 'Ref', 'AgentRef'].map(async key => {
592
+ let reply;
593
+ try {
594
+ reply = await this.callTourplan(getPayload('ListBookingsRequest', { [key]: bookingId }));
595
+ } catch (err) {
596
+ if (err.message.indexOf('not found') > -1) {
597
+ reply = { ListBookingsReply: { BookingHeaders: { BookingHeader: [] } } };
598
+ } else {
599
+ throw err;
600
+ }
601
+ }
602
+ return reply;
603
+ })
604
+ : [this.callTourplan(listBookingPayload)];
605
+ const replyObjs = await Promise.all(allSearches);
606
+ const bookingHeaders = R.flatten(replyObjs.map(o => R.pathOr([], ['ListBookingsReply', 'BookingHeaders', 'BookingHeader'], o)));
607
+ const bookings = await Promise.map(bookingHeaders, async bookingHeader => {
608
+ const getBookingPayload = getPayload('GetBookingRequest', {
609
+ BookingId: R.prop('BookingId', bookingHeader),
610
+ });
611
+ const bookingReply = await this.callTourplan(getBookingPayload);
612
+ return R.path(['GetBookingReply'], bookingReply);
613
+ }, { concurrency: 10 });
614
+ return {
615
+ bookings,
616
+ };
617
+ }
818
618
  }
819
619
 
820
620
  module.exports = Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {