ti2-ventrata 1.0.22 → 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 +54 -33
- package/index.test.js +0 -25
- package/package.json +1 -1
- package/resolvers/booking.js +2 -2
- package/resolvers/pickup-point.js +28 -0
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,11 +30,18 @@ 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
|
});
|
|
36
37
|
|
|
38
|
+
const axiosSafeRequest = R.pick(['headers', 'method', 'url', 'data']);
|
|
39
|
+
const axiosSafeResponse = response => {
|
|
40
|
+
const retVal = R.pick(['data', 'status', 'statusText', 'headers', 'request'], response);
|
|
41
|
+
retVal.request = axiosSafeRequest(retVal.request);
|
|
42
|
+
return retVal;
|
|
43
|
+
};
|
|
44
|
+
|
|
37
45
|
class Plugin {
|
|
38
46
|
constructor(params) { // we get the env variables from here
|
|
39
47
|
Object.entries(params).forEach(([attr, value]) => {
|
|
@@ -41,27 +49,25 @@ class Plugin {
|
|
|
41
49
|
});
|
|
42
50
|
if (this.events) {
|
|
43
51
|
axiosRaw.interceptors.request.use(request => {
|
|
44
|
-
this.events.emit(`${this.name}.axios.request`,
|
|
52
|
+
this.events.emit(`${this.name}.axios.request`, axiosSafeRequest(request));
|
|
45
53
|
return request;
|
|
46
54
|
});
|
|
47
55
|
axiosRaw.interceptors.response.use(response => {
|
|
48
|
-
this.events.emit(`${this.name}.axios.response`,
|
|
56
|
+
this.events.emit(`${this.name}.axios.response`, axiosSafeResponse(response));
|
|
49
57
|
return response;
|
|
50
58
|
});
|
|
51
59
|
}
|
|
52
60
|
const pluginObj = this;
|
|
53
61
|
this.axios = async (...args) => axiosRaw(...args).catch(err => {
|
|
54
|
-
const errMsg = R.
|
|
55
|
-
console.log(`error in ${this.name}`, args[0], errMsg
|
|
62
|
+
const errMsg = R.omit(['config'], err.toJSON());
|
|
63
|
+
console.log(`error in ${this.name}`, args[0], errMsg);
|
|
56
64
|
if (pluginObj.events) {
|
|
57
65
|
pluginObj.events.emit(`${this.name}.axios.error`, {
|
|
58
66
|
request: args[0],
|
|
59
|
-
err:
|
|
60
|
-
errMsg,
|
|
67
|
+
err: errMsg,
|
|
61
68
|
});
|
|
62
69
|
}
|
|
63
|
-
|
|
64
|
-
throw err;
|
|
70
|
+
throw R.pathOr(err, ['response', 'data', 'errorMessage'], err);
|
|
65
71
|
});
|
|
66
72
|
|
|
67
73
|
this.tokenTemplate = () => ({
|
|
@@ -570,32 +576,47 @@ class Plugin {
|
|
|
570
576
|
})),
|
|
571
577
|
});
|
|
572
578
|
}
|
|
573
|
-
}
|
|
574
579
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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,
|
|
592
600
|
});
|
|
593
|
-
|
|
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
|
+
};
|
|
594
619
|
}
|
|
595
|
-
|
|
596
|
-
.filter(unit => R.path(['restrictions', 'paxCount'], unit) === 1)
|
|
597
|
-
.find(unit => evalOne(unit, pax))); // individual units
|
|
598
|
-
};
|
|
620
|
+
}
|
|
599
621
|
|
|
600
622
|
module.exports = Plugin;
|
|
601
|
-
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
package/resolvers/booking.js
CHANGED
|
@@ -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
|
+
};
|