ti2-ventrata 1.0.7 → 1.0.10

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 +65 -41
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -37,6 +37,8 @@ const doMapCurry = mapObj => item => doMap(item, mapObj);
37
37
  const productMapIn = {
38
38
  productId: R.path(['id']),
39
39
  productName: R.path(['title']),
40
+ availableCurrencies: R.path(['availableCurrencies']),
41
+ defaultCurrency: R.path(['defaultCurrency']),
40
42
  options: e => R.pathOr(undefined, ['options'], e).map(option => doMap(option, optionMapIn, ['id', 'title'])),
41
43
  };
42
44
 
@@ -53,10 +55,11 @@ const rateMap = {
53
55
  };
54
56
 
55
57
  const availabilityMap = {
56
- dateTimeStart: R.path(['localDateTimeStart']),
57
- dateTimeEnd: R.path(['localDateTimeEnd']),
58
+ dateTimeStart: root => R.path(['localDateTimeStart'], root) || R.path(['localDate'], root),
59
+ dateTimeEnd: root => R.path(['localDateTimeEnd']) || R.path(['localDate'], root),
58
60
  allDay: R.path(['allDay']),
59
- pricing: R.path(['pricing']),
61
+ pricing: root => R.path(['pricing'], root) || R.path(['pricingFrom'], root),
62
+ unitPricing: root => R.path(['unitPricing'], root) || R.path(['unitPricingFrom'], root),
60
63
  offer: avail => (avail.offerCode ? doMap(avail, {
61
64
  offerId: R.path(['offerCode']),
62
65
  title: R.pathOr(undefined, ['offerTitle']),
@@ -81,8 +84,9 @@ const capitalize = sParam => {
81
84
  const unitMap = {
82
85
  unitId: R.path(['id']),
83
86
  unitName: R.path(['title']),
87
+ subtitle: R.path(['subtitle']),
84
88
  restrictions: R.path(['restrictions']),
85
- pricing: R.path(['pricing']),
89
+ pricing: root => R.path(['pricing'], root) || R.path(['pricingFrom'], root),
86
90
  };
87
91
 
88
92
  const itineraryMap = {
@@ -103,11 +107,13 @@ const itineraryMap = {
103
107
 
104
108
  const unitItemMap = {
105
109
  unitItemId: R.path(['uuid']),
110
+ unitId: R.path(['unitId']),
111
+ unitName: R.path(['unit', 'title']),
106
112
  supplierId: R.path(['supplierReference']),
107
113
  status: e => capitalize(R.path(['status'], e)),
108
114
  contact: R.path(['contact']),
109
115
  pricing: R.path(['pricing']),
110
- unit: unit => doMap(unit, unitMap),
116
+ unit: root => doMap(root.unit, unitMap),
111
117
  };
112
118
 
113
119
  const contactMapOut = {
@@ -123,11 +129,14 @@ const contactMapOut = {
123
129
 
124
130
  const bookingMap = {
125
131
  id: R.path(['id']),
132
+ orderId: R.path(['orderReference']),
133
+ bookingId: R.path(['supplierReference']),
126
134
  supplierId: R.path(['supplierReference']),
127
135
  status: e => capitalize(R.path(['status'], e)),
128
136
  productId: R.path(['product', 'id']),
129
137
  productName: R.path(['product', 'title']),
130
138
  optionId: R.path(['option', 'id']),
139
+ optionName: R.path(['option', 'title']),
131
140
  itinerary: ({ option: { itinerary } = {} }) =>
132
141
  (isNilOrEmptyArray(itinerary) ? undefined : itinerary.map(doMapCurry(itineraryMap))),
133
142
  duration: booking => doMap(booking, {
@@ -141,7 +150,7 @@ const bookingMap = {
141
150
  start: R.path(['availability', 'localDateTimeStart']),
142
151
  end: R.path(['availability', 'localDateTimeEnd']),
143
152
  allDay: R.path(['availability', 'allDay']),
144
- bookingDate: R.path(['hotel', 'utcCreatedAt']),
153
+ bookingDate: R.path(['utcCreatedAt']),
145
154
  holder: booking => doMap(R.path(['contact'], booking), contactMapOut),
146
155
  telephone: R.pathOr(undefined, ['contact', 'phoneNumber']),
147
156
  notes: R.pathOr(undefined, ['notes']),
@@ -281,6 +290,7 @@ class Plugin {
281
290
  startDate,
282
291
  endDate,
283
292
  dateFormat,
293
+ currency,
284
294
  },
285
295
  }) {
286
296
  assert(this.jwtKey, 'JWT secret should be set');
@@ -323,6 +333,7 @@ class Plugin {
323
333
  optionId: optionIds[rateIx],
324
334
  localDateStart,
325
335
  localDateEnd,
336
+ currency,
326
337
  units: Object.entries(qtys).map(([id, quantity]) => ({
327
338
  id, quantity,
328
339
  })),
@@ -342,6 +353,7 @@ class Plugin {
342
353
  productId: productIds[availsIx],
343
354
  optionId: optionIds[availsIx],
344
355
  availabilityId: avail.id,
356
+ currency,
345
357
  unitItems: rates[availsIx].map(rate => ({ unitId: rate })),
346
358
  }), this.jwtKey),
347
359
  ...doMap(avail, availabilityMap),
@@ -367,7 +379,8 @@ class Plugin {
367
379
  optionIds,
368
380
  occupancies,
369
381
  startDate,
370
- // endDate,
382
+ endDate,
383
+ currency,
371
384
  dateFormat,
372
385
  },
373
386
  }) {
@@ -385,7 +398,7 @@ class Plugin {
385
398
  assert(optionIds.every(Boolean), 'some invalid optionId(s)');
386
399
  assert(occupancies.every(Boolean), 'some invalid occupacies(s)');
387
400
  const localDateStart = moment(startDate, dateFormat).format('YYYY-MM-DD');
388
- const localDateEnd = moment(startDate, dateFormat).format('YYYY-MM-DD');
401
+ const localDateEnd = moment(endDate, dateFormat).format('YYYY-MM-DD');
389
402
  // obtain the rates
390
403
  const { quote } = await this.searchQuote({
391
404
  token,
@@ -403,7 +416,7 @@ class Plugin {
403
416
  acceptLanguage,
404
417
  });
405
418
  const url = `${endpoint || this.endpoint}/availability/calendar`;
406
- const availability = (
419
+ let availability = (
407
420
  await Promise.map(rates, async (rate, rateIx) => {
408
421
  const qtys = R.countBy(x => x)(rate);
409
422
  const data = {
@@ -411,6 +424,7 @@ class Plugin {
411
424
  optionId: optionIds[rateIx],
412
425
  localDateStart,
413
426
  localDateEnd,
427
+ currency,
414
428
  units: Object.entries(qtys).map(([id, quantity]) => ({
415
429
  id, quantity,
416
430
  })),
@@ -423,6 +437,11 @@ class Plugin {
423
437
  });
424
438
  }, { concurrency: CONCURRENCY })
425
439
  ).map(({ data }) => data);
440
+ availability = availability.map(
441
+ (avails, availsIx) => (avails.map(
442
+ avail => doMap(avail, availabilityMap),
443
+ )),
444
+ );
426
445
  return { availability };
427
446
  }
428
447
 
@@ -440,38 +459,43 @@ class Plugin {
440
459
  holder,
441
460
  },
442
461
  }) {
443
- assert(availabilityKey, 'an availability code is required !');
444
- assert(R.path(['name'], holder), 'a holder\' first name is required');
445
- assert(R.path(['surname'], holder), 'a holder\' surname is required');
446
- assert(R.path(['emailAddress'], holder), 'a holder\' email address is required');
447
- const headers = getHeaders({
448
- apiKey,
449
- endpoint,
450
- octoEnv,
451
- acceptLanguage,
452
- });
453
- let url = `${endpoint || this.endpoint}/bookings`;
454
- let data = await jwt.verify(availabilityKey, this.jwtKey);
455
- let booking = R.path(['data'], await axios({
456
- method: 'post',
457
- url,
458
- data: { ...data, notes },
459
- headers,
460
- }));
461
- url = `${endpoint || this.endpoint}/bookings/${booking.uuid}/confirm`;
462
- const contact = doMap(holder, contactMap);
463
- data = {
464
- notes,
465
- contact,
466
- resellerReference: reference,
467
- };
468
- booking = R.path(['data'], await axios({
469
- method: 'post',
470
- url,
471
- data,
472
- headers,
473
- }));
474
- return ({ booking: doMap(booking, bookingMap) });
462
+ try {
463
+ assert(availabilityKey, 'an availability code is required !');
464
+ assert(R.path(['name'], holder), 'a holder\' first name is required');
465
+ assert(R.path(['surname'], holder), 'a holder\' surname is required');
466
+ assert(R.path(['emailAddress'], holder), 'a holder\' email address is required');
467
+ const headers = getHeaders({
468
+ apiKey,
469
+ endpoint,
470
+ octoEnv,
471
+ acceptLanguage,
472
+ });
473
+ let url = `${endpoint || this.endpoint}/bookings`;
474
+ let data = await jwt.verify(availabilityKey, this.jwtKey);
475
+ let booking = R.path(['data'], await axios({
476
+ method: 'post',
477
+ url,
478
+ data: { ...data, notes },
479
+ headers,
480
+ }));
481
+ url = `${endpoint || this.endpoint}/bookings/${booking.uuid}/confirm`;
482
+ const contact = doMap(holder, contactMap);
483
+ data = {
484
+ notes,
485
+ contact,
486
+ resellerReference: reference,
487
+ };
488
+ booking = R.path(['data'], await axios({
489
+ method: 'post',
490
+ url,
491
+ data,
492
+ headers,
493
+ }));
494
+ return ({ booking: doMap(booking, bookingMap) });
495
+ } catch (err) {
496
+ console.log('createBooking-ventrata', err);
497
+ throw Error(err);
498
+ }
475
499
  }
476
500
 
477
501
  async cancelBooking({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {