ti2-ventrata 1.0.19 → 1.0.21
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 +52 -20
- package/package.json +1 -1
- package/resolvers/availability.js +2 -2
- package/resolvers/booking.js +1 -1
package/index.js
CHANGED
|
@@ -15,13 +15,6 @@ if (process.env.debug) {
|
|
|
15
15
|
curlirize(axiosRaw);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const axios = async (...args) => axiosRaw(...args)
|
|
19
|
-
.catch(err => {
|
|
20
|
-
const errMsg = R.path(['response', 'data', 'errorMessage'], err);
|
|
21
|
-
console.log('error in ti2-ventrata', args[0], errMsg);
|
|
22
|
-
if (errMsg) throw new Error(errMsg);
|
|
23
|
-
throw err;
|
|
24
|
-
});
|
|
25
18
|
const isNilOrEmpty = R.either(R.isNil, R.isEmpty);
|
|
26
19
|
|
|
27
20
|
const getHeaders = ({
|
|
@@ -29,14 +22,16 @@ const getHeaders = ({
|
|
|
29
22
|
acceptLanguage,
|
|
30
23
|
octoEnv,
|
|
31
24
|
resellerId,
|
|
25
|
+
requestId,
|
|
32
26
|
}) => ({
|
|
33
27
|
Authorization: `Bearer ${apiKey}`,
|
|
34
28
|
...octoEnv ? { 'Octo-Env': octoEnv } : {},
|
|
35
29
|
...acceptLanguage ? { 'Accept-Language': acceptLanguage } : {},
|
|
36
30
|
'Content-Type': 'application/json',
|
|
37
31
|
...resellerId ? { Referer: resellerId } : {},
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
'Octo-Capabilities': 'octo/pricing,octo/pickups',
|
|
33
|
+
...requestId ? { requestId } : {},
|
|
34
|
+
// 'Octo-Capabilities': 'octo/pricing',
|
|
40
35
|
});
|
|
41
36
|
|
|
42
37
|
class Plugin {
|
|
@@ -44,6 +39,27 @@ class Plugin {
|
|
|
44
39
|
Object.entries(params).forEach(([attr, value]) => {
|
|
45
40
|
this[attr] = value;
|
|
46
41
|
});
|
|
42
|
+
if (this.events) {
|
|
43
|
+
axiosRaw.interceptors.request.use(request => {
|
|
44
|
+
this.events.emit(`${this.name}.axios.request`, JSON.parse(JSON.stringify(request)));
|
|
45
|
+
return request;
|
|
46
|
+
});
|
|
47
|
+
axiosRaw.interceptors.response.use(response => {
|
|
48
|
+
this.events.emit(`${this.name}.axios.response`, JSON.parse(JSON.stringify(response)));
|
|
49
|
+
return response;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const pluginObj = this;
|
|
53
|
+
this.axios = async (...args) => axiosRaw(...args).catch(err => {
|
|
54
|
+
const errMsg = R.path(['response', 'data', 'errorMessage'], err);
|
|
55
|
+
console.log('error in ti2-ventrata', args[0], errMsg);
|
|
56
|
+
if (pluginObj.events) {
|
|
57
|
+
pluginObj.events.emit(`${this.name}.axios.error`, { request: args[0], err, errMsg });
|
|
58
|
+
}
|
|
59
|
+
if (errMsg) throw new Error(errMsg);
|
|
60
|
+
throw err;
|
|
61
|
+
});
|
|
62
|
+
|
|
47
63
|
this.tokenTemplate = () => ({
|
|
48
64
|
apiKey: {
|
|
49
65
|
type: 'text',
|
|
@@ -85,6 +101,7 @@ class Plugin {
|
|
|
85
101
|
acceptLanguage,
|
|
86
102
|
resellerId,
|
|
87
103
|
},
|
|
104
|
+
requestId,
|
|
88
105
|
}) {
|
|
89
106
|
const url = `${endpoint || this.endpoint}/whoami?token=${apiKey}`;
|
|
90
107
|
const headers = getHeaders({
|
|
@@ -93,9 +110,10 @@ class Plugin {
|
|
|
93
110
|
octoEnv,
|
|
94
111
|
acceptLanguage,
|
|
95
112
|
resellerId,
|
|
113
|
+
requestId,
|
|
96
114
|
});
|
|
97
115
|
try {
|
|
98
|
-
const connectionId = R.path(['data', 'connection', 'id'], await axios({
|
|
116
|
+
const connectionId = R.path(['data', 'connection', 'id'], await this.axios({
|
|
99
117
|
method: 'get',
|
|
100
118
|
url,
|
|
101
119
|
headers,
|
|
@@ -119,6 +137,7 @@ class Plugin {
|
|
|
119
137
|
productTypeDefs,
|
|
120
138
|
productQuery,
|
|
121
139
|
},
|
|
140
|
+
requestId,
|
|
122
141
|
}) {
|
|
123
142
|
let url = `${endpoint || this.endpoint}/products`;
|
|
124
143
|
if (!isNilOrEmpty(payload)) {
|
|
@@ -132,8 +151,9 @@ class Plugin {
|
|
|
132
151
|
octoEnv,
|
|
133
152
|
acceptLanguage,
|
|
134
153
|
resellerId,
|
|
154
|
+
requestId,
|
|
135
155
|
});
|
|
136
|
-
let results = R.pathOr([], ['data'], await axios({
|
|
156
|
+
let results = R.pathOr([], ['data'], await this.axios({
|
|
137
157
|
method: 'get',
|
|
138
158
|
url,
|
|
139
159
|
headers,
|
|
@@ -202,6 +222,7 @@ class Plugin {
|
|
|
202
222
|
availTypeDefs,
|
|
203
223
|
availQuery,
|
|
204
224
|
},
|
|
225
|
+
requestId,
|
|
205
226
|
}) {
|
|
206
227
|
assert(this.jwtKey, 'JWT secret should be set');
|
|
207
228
|
assert(
|
|
@@ -222,6 +243,7 @@ class Plugin {
|
|
|
222
243
|
octoEnv,
|
|
223
244
|
acceptLanguage,
|
|
224
245
|
resellerId,
|
|
246
|
+
requestId,
|
|
225
247
|
});
|
|
226
248
|
const url = `${endpoint || this.endpoint}/availability`;
|
|
227
249
|
const availability = (
|
|
@@ -234,7 +256,7 @@ class Plugin {
|
|
|
234
256
|
units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
|
|
235
257
|
};
|
|
236
258
|
if (currency) data.currency = currency;
|
|
237
|
-
const result = R.path(['data'], await axios({
|
|
259
|
+
const result = R.path(['data'], await this.axios({
|
|
238
260
|
method: 'post',
|
|
239
261
|
url,
|
|
240
262
|
data,
|
|
@@ -278,6 +300,7 @@ class Plugin {
|
|
|
278
300
|
availTypeDefs,
|
|
279
301
|
availQuery,
|
|
280
302
|
},
|
|
303
|
+
requestId,
|
|
281
304
|
}) {
|
|
282
305
|
assert(this.jwtKey, 'JWT secret should be set');
|
|
283
306
|
assert(
|
|
@@ -298,6 +321,7 @@ class Plugin {
|
|
|
298
321
|
octoEnv,
|
|
299
322
|
acceptLanguage,
|
|
300
323
|
resellerId,
|
|
324
|
+
requestId,
|
|
301
325
|
});
|
|
302
326
|
const url = `${endpoint || this.endpoint}/availability/calendar`;
|
|
303
327
|
const availability = (
|
|
@@ -311,7 +335,7 @@ class Plugin {
|
|
|
311
335
|
units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
|
|
312
336
|
};
|
|
313
337
|
if (currency) data.currency = currency;
|
|
314
|
-
const result = await axios({
|
|
338
|
+
const result = await this.axios({
|
|
315
339
|
method: 'post',
|
|
316
340
|
url,
|
|
317
341
|
data,
|
|
@@ -342,11 +366,13 @@ class Plugin {
|
|
|
342
366
|
notes,
|
|
343
367
|
reference,
|
|
344
368
|
settlementMethod,
|
|
369
|
+
pickupPoint,
|
|
345
370
|
},
|
|
346
371
|
typeDefsAndQueries: {
|
|
347
372
|
bookingTypeDefs,
|
|
348
373
|
bookingQuery,
|
|
349
374
|
},
|
|
375
|
+
requestId,
|
|
350
376
|
}) {
|
|
351
377
|
assert(availabilityKey, 'an availability code is required !');
|
|
352
378
|
assert(R.path(['name'], holder), 'first name is required');
|
|
@@ -357,15 +383,17 @@ class Plugin {
|
|
|
357
383
|
octoEnv,
|
|
358
384
|
acceptLanguage,
|
|
359
385
|
resellerId,
|
|
386
|
+
requestId,
|
|
360
387
|
});
|
|
361
388
|
const dataForCreateBooking = await jwt.verify(availabilityKey, this.jwtKey);
|
|
362
|
-
let booking = R.path(['data'], await axios({
|
|
389
|
+
let booking = R.path(['data'], await this.axios({
|
|
363
390
|
method: rebookingId ? 'patch' : 'post',
|
|
364
391
|
url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
|
|
365
392
|
data: {
|
|
366
393
|
settlementMethod,
|
|
367
394
|
...dataForCreateBooking,
|
|
368
395
|
notes,
|
|
396
|
+
...(pickupPoint ? { pickupRequested: true, pickupPointId: pickupPoint } : {}),
|
|
369
397
|
},
|
|
370
398
|
headers,
|
|
371
399
|
}));
|
|
@@ -383,7 +411,7 @@ class Plugin {
|
|
|
383
411
|
resellerReference: reference,
|
|
384
412
|
settlementMethod,
|
|
385
413
|
};
|
|
386
|
-
booking = R.path(['data'], await axios({
|
|
414
|
+
booking = R.path(['data'], await this.axios({
|
|
387
415
|
method: 'post',
|
|
388
416
|
url: `${endpoint || this.endpoint}/bookings/${booking.uuid}/confirm`,
|
|
389
417
|
data: dataForConfirmBooking,
|
|
@@ -416,6 +444,7 @@ class Plugin {
|
|
|
416
444
|
bookingTypeDefs,
|
|
417
445
|
bookingQuery,
|
|
418
446
|
},
|
|
447
|
+
requestId,
|
|
419
448
|
}) {
|
|
420
449
|
assert(!isNilOrEmpty(bookingId) || !isNilOrEmpty(id), 'Invalid booking id');
|
|
421
450
|
const headers = getHeaders({
|
|
@@ -424,9 +453,10 @@ class Plugin {
|
|
|
424
453
|
octoEnv,
|
|
425
454
|
acceptLanguage,
|
|
426
455
|
resellerId,
|
|
456
|
+
requestId,
|
|
427
457
|
});
|
|
428
458
|
const url = `${endpoint || this.endpoint}/bookings/${bookingId || id}`;
|
|
429
|
-
const booking = R.path(['data'], await axios({
|
|
459
|
+
const booking = R.path(['data'], await this.axios({
|
|
430
460
|
method: 'delete',
|
|
431
461
|
url,
|
|
432
462
|
data: { reason },
|
|
@@ -461,6 +491,7 @@ class Plugin {
|
|
|
461
491
|
bookingTypeDefs,
|
|
462
492
|
bookingQuery,
|
|
463
493
|
},
|
|
494
|
+
requestId,
|
|
464
495
|
}) {
|
|
465
496
|
assert(
|
|
466
497
|
!isNilOrEmpty(bookingId)
|
|
@@ -477,10 +508,11 @@ class Plugin {
|
|
|
477
508
|
octoEnv,
|
|
478
509
|
acceptLanguage,
|
|
479
510
|
resellerId,
|
|
511
|
+
requestId,
|
|
480
512
|
});
|
|
481
513
|
const searchByUrl = async url => {
|
|
482
514
|
try {
|
|
483
|
-
return R.path(['data'], await axios({
|
|
515
|
+
return R.path(['data'], await this.axios({
|
|
484
516
|
method: 'get',
|
|
485
517
|
url,
|
|
486
518
|
headers,
|
|
@@ -500,7 +532,7 @@ class Plugin {
|
|
|
500
532
|
}
|
|
501
533
|
if (!isNilOrEmpty(resellerReference)) {
|
|
502
534
|
url = `${endpoint || this.endpoint}/bookings?resellerReference=${resellerReference}`;
|
|
503
|
-
return R.path(['data'], await axios({
|
|
535
|
+
return R.path(['data'], await this.axios({
|
|
504
536
|
method: 'get',
|
|
505
537
|
url,
|
|
506
538
|
headers,
|
|
@@ -508,7 +540,7 @@ class Plugin {
|
|
|
508
540
|
}
|
|
509
541
|
if (!isNilOrEmpty(supplierBookingId)) {
|
|
510
542
|
url = `${endpoint || this.endpoint}/bookings?supplierReference=${supplierBookingId}`;
|
|
511
|
-
return R.path(['data'], await axios({
|
|
543
|
+
return R.path(['data'], await this.axios({
|
|
512
544
|
method: 'get',
|
|
513
545
|
url,
|
|
514
546
|
headers,
|
|
@@ -518,7 +550,7 @@ class Plugin {
|
|
|
518
550
|
const localDateStart = moment(travelDateStart, dateFormat).format();
|
|
519
551
|
const localDateEnd = moment(travelDateEnd, dateFormat).format();
|
|
520
552
|
url = `${endpoint || this.endpoint}/bookings?localDateStart=${encodeURIComponent(localDateStart)}&localDateEnd=${encodeURIComponent(localDateEnd)}`;
|
|
521
|
-
return R.path(['data'], await axios({
|
|
553
|
+
return R.path(['data'], await this.axios({
|
|
522
554
|
method: 'get',
|
|
523
555
|
url,
|
|
524
556
|
headers,
|
package/package.json
CHANGED
|
@@ -30,8 +30,8 @@ const resolvers = {
|
|
|
30
30
|
vacancies: R.prop('vacancies'),
|
|
31
31
|
available: root => root.status !== 'SOLD_OUT',
|
|
32
32
|
// get the starting price
|
|
33
|
-
pricing: R.prop('pricingFrom'),
|
|
34
|
-
unitPricing: R.prop('unitPricingFrom'),
|
|
33
|
+
pricing: root => R.prop('pricingFrom', root) || R.prop('pricing', root),
|
|
34
|
+
unitPricing: root => R.prop('unitPricingFrom', root) || R.prop('unitPricing', root),
|
|
35
35
|
pickupAvailable: R.prop('pickupAvailable'),
|
|
36
36
|
pickupRequired: R.prop('pickupRequired'),
|
|
37
37
|
pickupPoints: root => R.pathOr([], ['pickupPoints'], root)
|
package/resolvers/booking.js
CHANGED
|
@@ -11,7 +11,7 @@ const resolvers = {
|
|
|
11
11
|
Query: {
|
|
12
12
|
id: R.path(['id']),
|
|
13
13
|
orderId: R.path(['orderReference']),
|
|
14
|
-
bookingId: R.path(['
|
|
14
|
+
bookingId: R.path(['id']),
|
|
15
15
|
supplierBookingId: R.path(['supplierReference']),
|
|
16
16
|
status: e => capitalize(R.path(['status'], e)),
|
|
17
17
|
productId: R.path(['product', 'id']),
|