ti2-ventrata 1.0.23 → 1.0.24

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
@@ -9,6 +9,7 @@ const wildcardMatch = require('./utils/wildcardMatch');
9
9
  const { translateProduct } = require('./resolvers/product');
10
10
  const { translateAvailability } = require('./resolvers/availability');
11
11
  const { translateBooking } = require('./resolvers/booking');
12
+ const { translatePickupPoint } = require('./resolvers/pickup-point');
12
13
 
13
14
  const CONCURRENCY = 3; // is this ok ?
14
15
  if (process.env.debug) {
@@ -29,7 +30,7 @@ const getHeaders = ({
29
30
  ...acceptLanguage ? { 'Accept-Language': acceptLanguage } : {},
30
31
  'Content-Type': 'application/json',
31
32
  ...resellerId ? { Referer: resellerId } : {},
32
- 'Octo-Capabilities': 'octo/pricing,octo/pickups',
33
+ 'Octo-Capabilities': 'octo/pricing,octo/pickups,octo/cart',
33
34
  ...requestId ? { requestId } : {},
34
35
  // 'Octo-Capabilities': 'octo/pricing',
35
36
  });
@@ -575,32 +576,47 @@ class Plugin {
575
576
  })),
576
577
  });
577
578
  }
578
- }
579
579
 
580
- const pickUnit = (units, paxs) => {
581
- const evalOne = (unit, pax) => {
582
- if (pax.age < R.path(['restrictions', 'minAge'], unit)) {
583
- return false;
584
- }
585
- if (pax.age > R.path(['restrictions', 'maxAge'], unit)) {
586
- return false;
587
- }
588
- return true;
589
- };
590
- if (paxs.length > 1) { // find group units
591
- const group = units.filter(({ restrictions }) => Boolean(restrictions)).find(unit => {
592
- if (
593
- R.path(['restrictions', 'paxCount'], unit) === paxs.length
594
- && paxs.every(pax => evalOne(unit, pax))
595
- ) return true;
596
- return false;
580
+ async getPickupPoints({
581
+ token: {
582
+ apiKey,
583
+ endpoint,
584
+ octoEnv,
585
+ acceptLanguage,
586
+ resellerId,
587
+ },
588
+ typeDefsAndQueries: {
589
+ pickupTypeDefs,
590
+ pickupQuery,
591
+ },
592
+ }) {
593
+ const url = `${endpoint || this.endpoint}/products`;
594
+ const headers = getHeaders({
595
+ apiKey,
596
+ endpoint,
597
+ octoEnv,
598
+ acceptLanguage,
599
+ resellerId,
597
600
  });
598
- if (group) return [group];
601
+ const products = R.pathOr([], ['data'], await axios({
602
+ method: 'get',
603
+ url,
604
+ headers,
605
+ }));
606
+ const pickupPoints = R.call(R.compose(
607
+ R.uniqBy(R.prop('id')),
608
+ R.chain(R.propOr([], 'pickupPoints')),
609
+ R.filter(o => o.pickupPoints && o.pickupPoints.length),
610
+ R.chain(R.propOr([], 'options')),
611
+ ), products);
612
+ return {
613
+ pickupPoints: await Promise.map(pickupPoints, async pickup => translatePickupPoint({
614
+ rootValue: pickup,
615
+ typeDefs: pickupTypeDefs,
616
+ query: pickupQuery,
617
+ })),
618
+ };
599
619
  }
600
- return paxs.map(pax => units
601
- .filter(unit => R.path(['restrictions', 'paxCount'], unit) === 1)
602
- .find(unit => evalOne(unit, pax))); // individual units
603
- };
620
+ }
604
621
 
605
622
  module.exports = Plugin;
606
- module.exports.pickUnit = pickUnit;
package/index.test.js CHANGED
@@ -43,31 +43,6 @@ describe('search tests', () => {
43
43
  // nada
44
44
  });
45
45
  describe('utilities', () => {
46
- describe('pickUnit', () => {
47
- it('adult', () => {
48
- const result = Plugin.pickUnit(fixtureUnits, [{ age: 40 }]);
49
- expect(result.length).toBe(1);
50
- expect(result[0]).toContainObject([{ id: 'adult' }]);
51
- });
52
- it('child', () => {
53
- const result = Plugin.pickUnit(fixtureUnits, [{ age: 10 }]);
54
- expect(result.length).toBe(1);
55
- expect(result[0]).toContainObject([{ id: 'child' }]);
56
- });
57
- it('senior', () => {
58
- const result = Plugin.pickUnit(fixtureUnits, [{ age: 70 }]);
59
- expect(result.length).toBe(1);
60
- expect(result[0]).toContainObject([{ id: 'senior' }]);
61
- });
62
- it('family', () => {
63
- const result = Plugin.pickUnit(fixtureUnits, [
64
- { age: 70 }, { age: 32 }, { age: 32 }, { age: 14 },
65
- ]);
66
- expect(result.length).toBe(1);
67
- expect(result[0]).toContainObject([{ id: 'family' }]);
68
- });
69
- it.todo('family + one');
70
- });
71
46
  describe('validateToken', () => {
72
47
  it('valid token', async () => {
73
48
  const retVal = await app.validateToken({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,9 +10,10 @@ const capitalize = sParam => {
10
10
  const resolvers = {
11
11
  Query: {
12
12
  id: R.path(['id']),
13
- orderId: R.path(['orderReference']),
14
13
  bookingId: R.path(['id']),
14
+ orderId: R.path(['orderReference']),
15
15
  supplierBookingId: R.path(['supplierReference']),
16
+ resellerReference: R.propOr('', 'resellerReference'),
16
17
  status: e => capitalize(R.path(['status'], e)),
17
18
  productId: R.path(['product', 'id']),
18
19
  productName: root => R.path(['product', 'title'], root) || R.path(['product', 'internalName'], root),
@@ -44,7 +45,6 @@ const resolvers = {
44
45
  },
45
46
  optionId: R.path(['option', 'id']),
46
47
  optionName: root => R.path(['option', 'title'], root) || R.path(['option', 'internalName'], root),
47
- resellerReference: R.propOr('', 'resellerReference'),
48
48
  publicUrl: () => null,
49
49
  privateUrl: () => null,
50
50
  pickupRequested: R.prop('pickupRequested'),
@@ -0,0 +1,28 @@
1
+ const { makeExecutableSchema } = require('@graphql-tools/schema');
2
+ const R = require('ramda');
3
+ const { graphql } = require('graphql');
4
+
5
+ const resolvers = {
6
+ Query: {
7
+ id: R.path(['id']),
8
+ name: R.path(['name']),
9
+ },
10
+ };
11
+
12
+ const translatePickupPoint = async ({ rootValue, typeDefs, query }) => {
13
+ const schema = makeExecutableSchema({
14
+ typeDefs,
15
+ resolvers,
16
+ });
17
+ const retVal = await graphql({
18
+ schema,
19
+ rootValue,
20
+ source: query,
21
+ });
22
+ if (retVal.errors) throw new Error(retVal.errors);
23
+ return retVal.data;
24
+ };
25
+
26
+ module.exports = {
27
+ translatePickupPoint,
28
+ };