ti2-ventrata 1.0.20 → 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 +48 -18
- package/package.json +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,6 +22,7 @@ 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 } : {},
|
|
@@ -36,6 +30,7 @@ const getHeaders = ({
|
|
|
36
30
|
'Content-Type': 'application/json',
|
|
37
31
|
...resellerId ? { Referer: resellerId } : {},
|
|
38
32
|
'Octo-Capabilities': 'octo/pricing,octo/pickups',
|
|
33
|
+
...requestId ? { requestId } : {},
|
|
39
34
|
// 'Octo-Capabilities': 'octo/pricing',
|
|
40
35
|
});
|
|
41
36
|
|
|
@@ -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,
|
|
@@ -348,6 +372,7 @@ class Plugin {
|
|
|
348
372
|
bookingTypeDefs,
|
|
349
373
|
bookingQuery,
|
|
350
374
|
},
|
|
375
|
+
requestId,
|
|
351
376
|
}) {
|
|
352
377
|
assert(availabilityKey, 'an availability code is required !');
|
|
353
378
|
assert(R.path(['name'], holder), 'first name is required');
|
|
@@ -358,9 +383,10 @@ class Plugin {
|
|
|
358
383
|
octoEnv,
|
|
359
384
|
acceptLanguage,
|
|
360
385
|
resellerId,
|
|
386
|
+
requestId,
|
|
361
387
|
});
|
|
362
388
|
const dataForCreateBooking = await jwt.verify(availabilityKey, this.jwtKey);
|
|
363
|
-
let booking = R.path(['data'], await axios({
|
|
389
|
+
let booking = R.path(['data'], await this.axios({
|
|
364
390
|
method: rebookingId ? 'patch' : 'post',
|
|
365
391
|
url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
|
|
366
392
|
data: {
|
|
@@ -385,7 +411,7 @@ class Plugin {
|
|
|
385
411
|
resellerReference: reference,
|
|
386
412
|
settlementMethod,
|
|
387
413
|
};
|
|
388
|
-
booking = R.path(['data'], await axios({
|
|
414
|
+
booking = R.path(['data'], await this.axios({
|
|
389
415
|
method: 'post',
|
|
390
416
|
url: `${endpoint || this.endpoint}/bookings/${booking.uuid}/confirm`,
|
|
391
417
|
data: dataForConfirmBooking,
|
|
@@ -418,6 +444,7 @@ class Plugin {
|
|
|
418
444
|
bookingTypeDefs,
|
|
419
445
|
bookingQuery,
|
|
420
446
|
},
|
|
447
|
+
requestId,
|
|
421
448
|
}) {
|
|
422
449
|
assert(!isNilOrEmpty(bookingId) || !isNilOrEmpty(id), 'Invalid booking id');
|
|
423
450
|
const headers = getHeaders({
|
|
@@ -426,9 +453,10 @@ class Plugin {
|
|
|
426
453
|
octoEnv,
|
|
427
454
|
acceptLanguage,
|
|
428
455
|
resellerId,
|
|
456
|
+
requestId,
|
|
429
457
|
});
|
|
430
458
|
const url = `${endpoint || this.endpoint}/bookings/${bookingId || id}`;
|
|
431
|
-
const booking = R.path(['data'], await axios({
|
|
459
|
+
const booking = R.path(['data'], await this.axios({
|
|
432
460
|
method: 'delete',
|
|
433
461
|
url,
|
|
434
462
|
data: { reason },
|
|
@@ -463,6 +491,7 @@ class Plugin {
|
|
|
463
491
|
bookingTypeDefs,
|
|
464
492
|
bookingQuery,
|
|
465
493
|
},
|
|
494
|
+
requestId,
|
|
466
495
|
}) {
|
|
467
496
|
assert(
|
|
468
497
|
!isNilOrEmpty(bookingId)
|
|
@@ -479,10 +508,11 @@ class Plugin {
|
|
|
479
508
|
octoEnv,
|
|
480
509
|
acceptLanguage,
|
|
481
510
|
resellerId,
|
|
511
|
+
requestId,
|
|
482
512
|
});
|
|
483
513
|
const searchByUrl = async url => {
|
|
484
514
|
try {
|
|
485
|
-
return R.path(['data'], await axios({
|
|
515
|
+
return R.path(['data'], await this.axios({
|
|
486
516
|
method: 'get',
|
|
487
517
|
url,
|
|
488
518
|
headers,
|
|
@@ -502,7 +532,7 @@ class Plugin {
|
|
|
502
532
|
}
|
|
503
533
|
if (!isNilOrEmpty(resellerReference)) {
|
|
504
534
|
url = `${endpoint || this.endpoint}/bookings?resellerReference=${resellerReference}`;
|
|
505
|
-
return R.path(['data'], await axios({
|
|
535
|
+
return R.path(['data'], await this.axios({
|
|
506
536
|
method: 'get',
|
|
507
537
|
url,
|
|
508
538
|
headers,
|
|
@@ -510,7 +540,7 @@ class Plugin {
|
|
|
510
540
|
}
|
|
511
541
|
if (!isNilOrEmpty(supplierBookingId)) {
|
|
512
542
|
url = `${endpoint || this.endpoint}/bookings?supplierReference=${supplierBookingId}`;
|
|
513
|
-
return R.path(['data'], await axios({
|
|
543
|
+
return R.path(['data'], await this.axios({
|
|
514
544
|
method: 'get',
|
|
515
545
|
url,
|
|
516
546
|
headers,
|
|
@@ -520,7 +550,7 @@ class Plugin {
|
|
|
520
550
|
const localDateStart = moment(travelDateStart, dateFormat).format();
|
|
521
551
|
const localDateEnd = moment(travelDateEnd, dateFormat).format();
|
|
522
552
|
url = `${endpoint || this.endpoint}/bookings?localDateStart=${encodeURIComponent(localDateStart)}&localDateEnd=${encodeURIComponent(localDateEnd)}`;
|
|
523
|
-
return R.path(['data'], await axios({
|
|
553
|
+
return R.path(['data'], await this.axios({
|
|
524
554
|
method: 'get',
|
|
525
555
|
url,
|
|
526
556
|
headers,
|