ti2-ventrata 1.0.26 → 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 -65
  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,45 +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', 'config'], response);
41
- retVal.request = axiosSafeRequest(retVal.request);
42
- retVal.config = axiosSafeRequest(retVal.config);
43
- return retVal;
44
- };
45
-
46
31
  class Plugin {
47
32
  constructor(params) { // we get the env variables from here
48
33
  Object.entries(params).forEach(([attr, value]) => {
49
34
  this[attr] = value;
50
35
  });
51
- if (this.events) {
52
- axiosRaw.interceptors.request.use(request => {
53
- this.events.emit(`${this.name}.axios.request`, axiosSafeRequest(request));
54
- return request;
55
- });
56
- axiosRaw.interceptors.response.use(response => {
57
- this.events.emit(`${this.name}.axios.response`, axiosSafeResponse(response));
58
- return response;
59
- });
60
- }
61
- const pluginObj = this;
62
- this.axios = async (...args) => axiosRaw(...args).catch(err => {
63
- const errMsg = R.omit(['config'], err.toJSON());
64
- console.log(`error in ${this.name}`, args[0], errMsg);
65
- if (pluginObj.events) {
66
- pluginObj.events.emit(`${this.name}.axios.error`, {
67
- request: args[0],
68
- err: errMsg,
69
- });
70
- }
71
- throw R.pathOr(err, ['response', 'data', 'errorMessage'], err);
72
- });
73
36
 
74
37
  this.tokenTemplate = () => ({
75
38
  apiKey: {
@@ -105,6 +68,7 @@ class Plugin {
105
68
  }
106
69
 
107
70
  async validateToken({
71
+ axios,
108
72
  token: {
109
73
  apiKey,
110
74
  endpoint,
@@ -112,7 +76,6 @@ class Plugin {
112
76
  acceptLanguage,
113
77
  resellerId,
114
78
  },
115
- requestId,
116
79
  }) {
117
80
  const url = `${endpoint || this.endpoint}/whoami?token=${apiKey}`;
118
81
  const headers = getHeaders({
@@ -121,10 +84,9 @@ class Plugin {
121
84
  octoEnv,
122
85
  acceptLanguage,
123
86
  resellerId,
124
- requestId,
125
87
  });
126
88
  try {
127
- const connectionId = R.path(['data', 'connection', 'id'], await this.axios({
89
+ const connectionId = R.path(['data', 'connection', 'id'], await axios({
128
90
  method: 'get',
129
91
  url,
130
92
  headers,
@@ -136,6 +98,7 @@ class Plugin {
136
98
  }
137
99
 
138
100
  async searchProducts({
101
+ axios,
139
102
  token: {
140
103
  apiKey,
141
104
  endpoint,
@@ -148,7 +111,6 @@ class Plugin {
148
111
  productTypeDefs,
149
112
  productQuery,
150
113
  },
151
- requestId,
152
114
  }) {
153
115
  let url = `${endpoint || this.endpoint}/products`;
154
116
  if (!isNilOrEmpty(payload)) {
@@ -162,9 +124,8 @@ class Plugin {
162
124
  octoEnv,
163
125
  acceptLanguage,
164
126
  resellerId,
165
- requestId,
166
127
  });
167
- let results = R.pathOr([], ['data'], await this.axios({
128
+ let results = R.pathOr([], ['data'], await axios({
168
129
  method: 'get',
169
130
  url,
170
131
  headers,
@@ -213,6 +174,7 @@ class Plugin {
213
174
  }
214
175
 
215
176
  async searchAvailability({
177
+ axios,
216
178
  token: {
217
179
  apiKey,
218
180
  endpoint,
@@ -233,7 +195,6 @@ class Plugin {
233
195
  availTypeDefs,
234
196
  availQuery,
235
197
  },
236
- requestId,
237
198
  }) {
238
199
  assert(this.jwtKey, 'JWT secret should be set');
239
200
  assert(
@@ -254,7 +215,6 @@ class Plugin {
254
215
  octoEnv,
255
216
  acceptLanguage,
256
217
  resellerId,
257
- requestId,
258
218
  });
259
219
  const url = `${endpoint || this.endpoint}/availability`;
260
220
  const availability = (
@@ -267,7 +227,7 @@ class Plugin {
267
227
  units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
268
228
  };
269
229
  if (currency) data.currency = currency;
270
- const result = R.path(['data'], await this.axios({
230
+ const result = R.path(['data'], await axios({
271
231
  method: 'post',
272
232
  url,
273
233
  data,
@@ -291,6 +251,7 @@ class Plugin {
291
251
  }
292
252
 
293
253
  async availabilityCalendar({
254
+ axios,
294
255
  token: {
295
256
  apiKey,
296
257
  endpoint,
@@ -311,7 +272,6 @@ class Plugin {
311
272
  availTypeDefs,
312
273
  availQuery,
313
274
  },
314
- requestId,
315
275
  }) {
316
276
  assert(this.jwtKey, 'JWT secret should be set');
317
277
  assert(
@@ -332,7 +292,6 @@ class Plugin {
332
292
  octoEnv,
333
293
  acceptLanguage,
334
294
  resellerId,
335
- requestId,
336
295
  });
337
296
  const url = `${endpoint || this.endpoint}/availability/calendar`;
338
297
  const availability = (
@@ -346,7 +305,7 @@ class Plugin {
346
305
  units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
347
306
  };
348
307
  if (currency) data.currency = currency;
349
- const result = await this.axios({
308
+ const result = await axios({
350
309
  method: 'post',
351
310
  url,
352
311
  data,
@@ -363,6 +322,7 @@ class Plugin {
363
322
  }
364
323
 
365
324
  async createBooking({
325
+ axios,
366
326
  token: {
367
327
  apiKey,
368
328
  endpoint,
@@ -383,7 +343,6 @@ class Plugin {
383
343
  bookingTypeDefs,
384
344
  bookingQuery,
385
345
  },
386
- requestId,
387
346
  }) {
388
347
  assert(availabilityKey, 'an availability code is required !');
389
348
  assert(R.path(['name'], holder), 'first name is required');
@@ -394,10 +353,9 @@ class Plugin {
394
353
  octoEnv,
395
354
  acceptLanguage,
396
355
  resellerId,
397
- requestId,
398
356
  });
399
357
  const dataForCreateBooking = await jwt.verify(availabilityKey, this.jwtKey);
400
- let booking = R.path(['data'], await this.axios({
358
+ let booking = R.path(['data'], await axios({
401
359
  method: rebookingId ? 'patch' : 'post',
402
360
  url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
403
361
  data: {
@@ -422,7 +380,7 @@ class Plugin {
422
380
  resellerReference: reference,
423
381
  settlementMethod,
424
382
  };
425
- booking = R.path(['data'], await this.axios({
383
+ booking = R.path(['data'], await axios({
426
384
  method: 'post',
427
385
  url: `${endpoint || this.endpoint}/bookings/${booking.uuid}/confirm`,
428
386
  data: dataForConfirmBooking,
@@ -439,6 +397,7 @@ class Plugin {
439
397
  }
440
398
 
441
399
  async cancelBooking({
400
+ axios,
442
401
  token: {
443
402
  apiKey,
444
403
  endpoint,
@@ -455,7 +414,6 @@ class Plugin {
455
414
  bookingTypeDefs,
456
415
  bookingQuery,
457
416
  },
458
- requestId,
459
417
  }) {
460
418
  assert(!isNilOrEmpty(bookingId) || !isNilOrEmpty(id), 'Invalid booking id');
461
419
  const headers = getHeaders({
@@ -464,10 +422,9 @@ class Plugin {
464
422
  octoEnv,
465
423
  acceptLanguage,
466
424
  resellerId,
467
- requestId,
468
425
  });
469
426
  const url = `${endpoint || this.endpoint}/bookings/${bookingId || id}`;
470
- const booking = R.path(['data'], await this.axios({
427
+ const booking = R.path(['data'], await axios({
471
428
  method: 'delete',
472
429
  url,
473
430
  data: { reason },
@@ -483,6 +440,7 @@ class Plugin {
483
440
  }
484
441
 
485
442
  async searchBooking({
443
+ axios,
486
444
  token: {
487
445
  apiKey,
488
446
  endpoint,
@@ -502,7 +460,6 @@ class Plugin {
502
460
  bookingTypeDefs,
503
461
  bookingQuery,
504
462
  },
505
- requestId,
506
463
  }) {
507
464
  assert(
508
465
  !isNilOrEmpty(bookingId)
@@ -519,11 +476,10 @@ class Plugin {
519
476
  octoEnv,
520
477
  acceptLanguage,
521
478
  resellerId,
522
- requestId,
523
479
  });
524
480
  const searchByUrl = async url => {
525
481
  try {
526
- return R.path(['data'], await this.axios({
482
+ return R.path(['data'], await axios({
527
483
  method: 'get',
528
484
  url,
529
485
  headers,
@@ -543,7 +499,7 @@ class Plugin {
543
499
  }
544
500
  if (!isNilOrEmpty(resellerReference)) {
545
501
  url = `${endpoint || this.endpoint}/bookings?resellerReference=${resellerReference}`;
546
- return R.path(['data'], await this.axios({
502
+ return R.path(['data'], await axios({
547
503
  method: 'get',
548
504
  url,
549
505
  headers,
@@ -551,7 +507,7 @@ class Plugin {
551
507
  }
552
508
  if (!isNilOrEmpty(supplierBookingId)) {
553
509
  url = `${endpoint || this.endpoint}/bookings?supplierReference=${supplierBookingId}`;
554
- return R.path(['data'], await this.axios({
510
+ return R.path(['data'], await axios({
555
511
  method: 'get',
556
512
  url,
557
513
  headers,
@@ -561,7 +517,7 @@ class Plugin {
561
517
  const localDateStart = moment(travelDateStart, dateFormat).format();
562
518
  const localDateEnd = moment(travelDateEnd, dateFormat).format();
563
519
  url = `${endpoint || this.endpoint}/bookings?localDateStart=${encodeURIComponent(localDateStart)}&localDateEnd=${encodeURIComponent(localDateEnd)}`;
564
- return R.path(['data'], await this.axios({
520
+ return R.path(['data'], await axios({
565
521
  method: 'get',
566
522
  url,
567
523
  headers,
@@ -579,6 +535,7 @@ class Plugin {
579
535
  }
580
536
 
581
537
  async getPickupPoints({
538
+ axios,
582
539
  token: {
583
540
  apiKey,
584
541
  endpoint,
@@ -590,7 +547,6 @@ class Plugin {
590
547
  pickupTypeDefs,
591
548
  pickupQuery,
592
549
  },
593
- requestId,
594
550
  }) {
595
551
  const url = `${endpoint || this.endpoint}/products`;
596
552
  const headers = getHeaders({
@@ -599,9 +555,8 @@ class Plugin {
599
555
  octoEnv,
600
556
  acceptLanguage,
601
557
  resellerId,
602
- requestId,
603
558
  });
604
- const products = R.pathOr([], ['data'], await this.axios({
559
+ const products = R.pathOr([], ['data'], await axios({
605
560
  method: 'get',
606
561
  url,
607
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.26",
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",