ti2-ventrata 1.0.25 → 1.0.27

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 (3) hide show
  1. package/index.js +20 -64
  2. package/index.test.js +16 -0
  3. package/package.json +2 -3
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
- const axiosRaw = require('axios');
2
- const curlirize = require('axios-curlirize');
3
1
  const R = require('ramda');
4
2
  const Promise = require('bluebird');
5
3
  const assert = require('assert');
@@ -12,9 +10,6 @@ const { translateBooking } = require('./resolvers/booking');
12
10
  const { translatePickupPoint } = require('./resolvers/pickup-point');
13
11
 
14
12
  const CONCURRENCY = 3; // is this ok ?
15
- if (process.env.debug) {
16
- curlirize(axiosRaw);
17
- }
18
13
 
19
14
  const isNilOrEmpty = R.either(R.isNil, R.isEmpty);
20
15
 
@@ -23,7 +18,6 @@ const getHeaders = ({
23
18
  acceptLanguage,
24
19
  octoEnv,
25
20
  resellerId,
26
- requestId,
27
21
  }) => ({
28
22
  Authorization: `Bearer ${apiKey}`,
29
23
  ...octoEnv ? { 'Octo-Env': octoEnv } : {},
@@ -31,44 +25,14 @@ const getHeaders = ({
31
25
  'Content-Type': 'application/json',
32
26
  ...resellerId ? { Referer: resellerId } : {},
33
27
  'Octo-Capabilities': 'octo/pricing,octo/pickups,octo/cart',
34
- ...requestId ? { requestId } : {},
35
28
  // 'Octo-Capabilities': 'octo/pricing',
36
29
  });
37
30
 
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
-
45
31
  class Plugin {
46
32
  constructor(params) { // we get the env variables from here
47
33
  Object.entries(params).forEach(([attr, value]) => {
48
34
  this[attr] = value;
49
35
  });
50
- if (this.events) {
51
- axiosRaw.interceptors.request.use(request => {
52
- this.events.emit(`${this.name}.axios.request`, axiosSafeRequest(request));
53
- return request;
54
- });
55
- axiosRaw.interceptors.response.use(response => {
56
- this.events.emit(`${this.name}.axios.response`, axiosSafeResponse(response));
57
- return response;
58
- });
59
- }
60
- const pluginObj = this;
61
- this.axios = async (...args) => axiosRaw(...args).catch(err => {
62
- const errMsg = R.omit(['config'], err.toJSON());
63
- console.log(`error in ${this.name}`, args[0], errMsg);
64
- if (pluginObj.events) {
65
- pluginObj.events.emit(`${this.name}.axios.error`, {
66
- request: args[0],
67
- err: errMsg,
68
- });
69
- }
70
- throw R.pathOr(err, ['response', 'data', 'errorMessage'], err);
71
- });
72
36
 
73
37
  this.tokenTemplate = () => ({
74
38
  apiKey: {
@@ -104,6 +68,7 @@ class Plugin {
104
68
  }
105
69
 
106
70
  async validateToken({
71
+ axios,
107
72
  token: {
108
73
  apiKey,
109
74
  endpoint,
@@ -111,7 +76,6 @@ class Plugin {
111
76
  acceptLanguage,
112
77
  resellerId,
113
78
  },
114
- requestId,
115
79
  }) {
116
80
  const url = `${endpoint || this.endpoint}/whoami?token=${apiKey}`;
117
81
  const headers = getHeaders({
@@ -120,10 +84,9 @@ class Plugin {
120
84
  octoEnv,
121
85
  acceptLanguage,
122
86
  resellerId,
123
- requestId,
124
87
  });
125
88
  try {
126
- const connectionId = R.path(['data', 'connection', 'id'], await this.axios({
89
+ const connectionId = R.path(['data', 'connection', 'id'], await axios({
127
90
  method: 'get',
128
91
  url,
129
92
  headers,
@@ -135,6 +98,7 @@ class Plugin {
135
98
  }
136
99
 
137
100
  async searchProducts({
101
+ axios,
138
102
  token: {
139
103
  apiKey,
140
104
  endpoint,
@@ -147,7 +111,6 @@ class Plugin {
147
111
  productTypeDefs,
148
112
  productQuery,
149
113
  },
150
- requestId,
151
114
  }) {
152
115
  let url = `${endpoint || this.endpoint}/products`;
153
116
  if (!isNilOrEmpty(payload)) {
@@ -161,9 +124,8 @@ class Plugin {
161
124
  octoEnv,
162
125
  acceptLanguage,
163
126
  resellerId,
164
- requestId,
165
127
  });
166
- let results = R.pathOr([], ['data'], await this.axios({
128
+ let results = R.pathOr([], ['data'], await axios({
167
129
  method: 'get',
168
130
  url,
169
131
  headers,
@@ -212,6 +174,7 @@ class Plugin {
212
174
  }
213
175
 
214
176
  async searchAvailability({
177
+ axios,
215
178
  token: {
216
179
  apiKey,
217
180
  endpoint,
@@ -232,7 +195,6 @@ class Plugin {
232
195
  availTypeDefs,
233
196
  availQuery,
234
197
  },
235
- requestId,
236
198
  }) {
237
199
  assert(this.jwtKey, 'JWT secret should be set');
238
200
  assert(
@@ -253,7 +215,6 @@ class Plugin {
253
215
  octoEnv,
254
216
  acceptLanguage,
255
217
  resellerId,
256
- requestId,
257
218
  });
258
219
  const url = `${endpoint || this.endpoint}/availability`;
259
220
  const availability = (
@@ -266,7 +227,7 @@ class Plugin {
266
227
  units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
267
228
  };
268
229
  if (currency) data.currency = currency;
269
- const result = R.path(['data'], await this.axios({
230
+ const result = R.path(['data'], await axios({
270
231
  method: 'post',
271
232
  url,
272
233
  data,
@@ -290,6 +251,7 @@ class Plugin {
290
251
  }
291
252
 
292
253
  async availabilityCalendar({
254
+ axios,
293
255
  token: {
294
256
  apiKey,
295
257
  endpoint,
@@ -310,7 +272,6 @@ class Plugin {
310
272
  availTypeDefs,
311
273
  availQuery,
312
274
  },
313
- requestId,
314
275
  }) {
315
276
  assert(this.jwtKey, 'JWT secret should be set');
316
277
  assert(
@@ -331,7 +292,6 @@ class Plugin {
331
292
  octoEnv,
332
293
  acceptLanguage,
333
294
  resellerId,
334
- requestId,
335
295
  });
336
296
  const url = `${endpoint || this.endpoint}/availability/calendar`;
337
297
  const availability = (
@@ -345,7 +305,7 @@ class Plugin {
345
305
  units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
346
306
  };
347
307
  if (currency) data.currency = currency;
348
- const result = await this.axios({
308
+ const result = await axios({
349
309
  method: 'post',
350
310
  url,
351
311
  data,
@@ -362,6 +322,7 @@ class Plugin {
362
322
  }
363
323
 
364
324
  async createBooking({
325
+ axios,
365
326
  token: {
366
327
  apiKey,
367
328
  endpoint,
@@ -382,7 +343,6 @@ class Plugin {
382
343
  bookingTypeDefs,
383
344
  bookingQuery,
384
345
  },
385
- requestId,
386
346
  }) {
387
347
  assert(availabilityKey, 'an availability code is required !');
388
348
  assert(R.path(['name'], holder), 'first name is required');
@@ -393,10 +353,9 @@ class Plugin {
393
353
  octoEnv,
394
354
  acceptLanguage,
395
355
  resellerId,
396
- requestId,
397
356
  });
398
357
  const dataForCreateBooking = await jwt.verify(availabilityKey, this.jwtKey);
399
- let booking = R.path(['data'], await this.axios({
358
+ let booking = R.path(['data'], await axios({
400
359
  method: rebookingId ? 'patch' : 'post',
401
360
  url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
402
361
  data: {
@@ -421,7 +380,7 @@ class Plugin {
421
380
  resellerReference: reference,
422
381
  settlementMethod,
423
382
  };
424
- booking = R.path(['data'], await this.axios({
383
+ booking = R.path(['data'], await axios({
425
384
  method: 'post',
426
385
  url: `${endpoint || this.endpoint}/bookings/${booking.uuid}/confirm`,
427
386
  data: dataForConfirmBooking,
@@ -438,6 +397,7 @@ class Plugin {
438
397
  }
439
398
 
440
399
  async cancelBooking({
400
+ axios,
441
401
  token: {
442
402
  apiKey,
443
403
  endpoint,
@@ -454,7 +414,6 @@ class Plugin {
454
414
  bookingTypeDefs,
455
415
  bookingQuery,
456
416
  },
457
- requestId,
458
417
  }) {
459
418
  assert(!isNilOrEmpty(bookingId) || !isNilOrEmpty(id), 'Invalid booking id');
460
419
  const headers = getHeaders({
@@ -463,10 +422,9 @@ class Plugin {
463
422
  octoEnv,
464
423
  acceptLanguage,
465
424
  resellerId,
466
- requestId,
467
425
  });
468
426
  const url = `${endpoint || this.endpoint}/bookings/${bookingId || id}`;
469
- const booking = R.path(['data'], await this.axios({
427
+ const booking = R.path(['data'], await axios({
470
428
  method: 'delete',
471
429
  url,
472
430
  data: { reason },
@@ -482,6 +440,7 @@ class Plugin {
482
440
  }
483
441
 
484
442
  async searchBooking({
443
+ axios,
485
444
  token: {
486
445
  apiKey,
487
446
  endpoint,
@@ -501,7 +460,6 @@ class Plugin {
501
460
  bookingTypeDefs,
502
461
  bookingQuery,
503
462
  },
504
- requestId,
505
463
  }) {
506
464
  assert(
507
465
  !isNilOrEmpty(bookingId)
@@ -518,11 +476,10 @@ class Plugin {
518
476
  octoEnv,
519
477
  acceptLanguage,
520
478
  resellerId,
521
- requestId,
522
479
  });
523
480
  const searchByUrl = async url => {
524
481
  try {
525
- return R.path(['data'], await this.axios({
482
+ return R.path(['data'], await axios({
526
483
  method: 'get',
527
484
  url,
528
485
  headers,
@@ -542,7 +499,7 @@ class Plugin {
542
499
  }
543
500
  if (!isNilOrEmpty(resellerReference)) {
544
501
  url = `${endpoint || this.endpoint}/bookings?resellerReference=${resellerReference}`;
545
- return R.path(['data'], await this.axios({
502
+ return R.path(['data'], await axios({
546
503
  method: 'get',
547
504
  url,
548
505
  headers,
@@ -550,7 +507,7 @@ class Plugin {
550
507
  }
551
508
  if (!isNilOrEmpty(supplierBookingId)) {
552
509
  url = `${endpoint || this.endpoint}/bookings?supplierReference=${supplierBookingId}`;
553
- return R.path(['data'], await this.axios({
510
+ return R.path(['data'], await axios({
554
511
  method: 'get',
555
512
  url,
556
513
  headers,
@@ -560,7 +517,7 @@ class Plugin {
560
517
  const localDateStart = moment(travelDateStart, dateFormat).format();
561
518
  const localDateEnd = moment(travelDateEnd, dateFormat).format();
562
519
  url = `${endpoint || this.endpoint}/bookings?localDateStart=${encodeURIComponent(localDateStart)}&localDateEnd=${encodeURIComponent(localDateEnd)}`;
563
- return R.path(['data'], await this.axios({
520
+ return R.path(['data'], await axios({
564
521
  method: 'get',
565
522
  url,
566
523
  headers,
@@ -578,6 +535,7 @@ class Plugin {
578
535
  }
579
536
 
580
537
  async getPickupPoints({
538
+ axios,
581
539
  token: {
582
540
  apiKey,
583
541
  endpoint,
@@ -589,7 +547,6 @@ class Plugin {
589
547
  pickupTypeDefs,
590
548
  pickupQuery,
591
549
  },
592
- requestId,
593
550
  }) {
594
551
  const url = `${endpoint || this.endpoint}/products`;
595
552
  const headers = getHeaders({
@@ -598,9 +555,8 @@ class Plugin {
598
555
  octoEnv,
599
556
  acceptLanguage,
600
557
  resellerId,
601
- requestId,
602
558
  });
603
- const products = R.pathOr([], ['data'], await this.axios({
559
+ const products = R.pathOr([], ['data'], await axios({
604
560
  method: 'get',
605
561
  url,
606
562
  headers,
package/index.test.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const R = require('ramda');
3
3
  const moment = require('moment');
4
4
  const faker = require('faker');
5
+ const axios = require('axios');
5
6
 
6
7
  const Plugin = require('./index');
7
8
 
@@ -48,12 +49,14 @@ describe('search tests', () => {
48
49
  describe('validateToken', () => {
49
50
  it('valid token', async () => {
50
51
  const retVal = await app.validateToken({
52
+ axios,
51
53
  token,
52
54
  });
53
55
  expect(retVal).toBeTruthy();
54
56
  });
55
57
  it('invalid token', async () => {
56
58
  const retVal = await app.validateToken({
59
+ axios,
57
60
  token: { someRandom: 'thing' },
58
61
  });
59
62
  expect(retVal).toBeFalsy();
@@ -94,6 +97,7 @@ describe('search tests', () => {
94
97
  describe('booking process', () => {
95
98
  it('get for all products, a test product should exist', async () => {
96
99
  const retVal = await app.searchProducts({
100
+ axios,
97
101
  token,
98
102
  typeDefsAndQueries,
99
103
  });
@@ -110,6 +114,7 @@ describe('search tests', () => {
110
114
  });
111
115
  it('should be able to get a single product', async () => {
112
116
  const retVal = await app.searchProducts({
117
+ axios,
113
118
  token,
114
119
  payload: {
115
120
  productId: testProduct.productId,
@@ -122,6 +127,7 @@ describe('search tests', () => {
122
127
  let busProducts = [];
123
128
  it('should be able to get a product by name', async () => {
124
129
  const retVal = await app.searchProducts({
130
+ axios,
125
131
  token,
126
132
  payload: {
127
133
  productName: '*bus*',
@@ -134,6 +140,7 @@ describe('search tests', () => {
134
140
  });
135
141
  it('should be able to get an availability calendar', async () => {
136
142
  const retVal = await app.availabilityCalendar({
143
+ axios,
137
144
  token,
138
145
  payload: {
139
146
  startDate: moment().add(6, 'M').format(dateFormat),
@@ -160,6 +167,7 @@ describe('search tests', () => {
160
167
  let availabilityKey;
161
168
  it('should be able to get availability', async () => {
162
169
  const retVal = await app.searchAvailability({
170
+ axios,
163
171
  token,
164
172
  typeDefsAndQueries,
165
173
  payload: {
@@ -189,6 +197,7 @@ describe('search tests', () => {
189
197
  it('should be able to create a booking', async () => {
190
198
  const fullName = faker.name.findName().split(' ');
191
199
  const retVal = await app.createBooking({
200
+ axios,
192
201
  token,
193
202
  typeDefsAndQueries,
194
203
  payload: {
@@ -216,6 +225,7 @@ describe('search tests', () => {
216
225
  });
217
226
  it('should be able to cancel the booking', async () => {
218
227
  const retVal = await app.cancelBooking({
228
+ axios,
219
229
  token,
220
230
  typeDefsAndQueries,
221
231
  payload: {
@@ -232,6 +242,7 @@ describe('search tests', () => {
232
242
  let bookings = [];
233
243
  it('it should be able to search bookings by id', async () => {
234
244
  const retVal = await app.searchBooking({
245
+ axios,
235
246
  token,
236
247
  typeDefsAndQueries,
237
248
  payload: {
@@ -244,6 +255,7 @@ describe('search tests', () => {
244
255
  });
245
256
  it('it should be able to search bookings by reference', async () => {
246
257
  const retVal = await app.searchBooking({
258
+ axios,
247
259
  token,
248
260
  typeDefsAndQueries,
249
261
  payload: {
@@ -256,6 +268,7 @@ describe('search tests', () => {
256
268
  });
257
269
  it('it should be able to search bookings by supplierBookingId', async () => {
258
270
  const retVal = await app.searchBooking({
271
+ axios,
259
272
  token,
260
273
  typeDefsAndQueries,
261
274
  payload: {
@@ -268,6 +281,7 @@ describe('search tests', () => {
268
281
  });
269
282
  it('it should be able to search bookings by travelDate', async () => {
270
283
  const retVal = await app.searchBooking({
284
+ axios,
271
285
  token,
272
286
  typeDefsAndQueries,
273
287
  payload: {
@@ -283,6 +297,7 @@ describe('search tests', () => {
283
297
  it('should be able to create a booking for a referrer', async () => {
284
298
  const fullName = faker.name.findName().split(' ');
285
299
  const retVal = await app.createBooking({
300
+ axios,
286
301
  token,
287
302
  typeDefsAndQueries,
288
303
  payload: {
@@ -310,6 +325,7 @@ describe('search tests', () => {
310
325
  });
311
326
  it('should be able to get a list of pickuppoints', async () => {
312
327
  const retVal = await app.getPickupPoints({
328
+ axios,
313
329
  token,
314
330
  typeDefsAndQueries,
315
331
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,8 +28,6 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@graphql-tools/schema": "^9.0.12",
31
- "axios": "^0.24.0",
32
- "axios-curlirize": "^1.3.7",
33
31
  "bluebird": "^3.7.2",
34
32
  "graphql": "^16.6.0",
35
33
  "jsonwebtoken": "^8.5.1",
@@ -37,6 +35,7 @@
37
35
  "ramda": "^0.27.1"
38
36
  },
39
37
  "devDependencies": {
38
+ "axios": "^0.27.2",
40
39
  "chalk": "^4.1.2",
41
40
  "eslint": "^8.4.1",
42
41
  "eslint-config-airbnb": "^19.0.2",