ti2-ventrata 1.0.12 → 1.0.13

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 +56 -29
  2. package/index.test.js +14 -0
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -196,7 +196,7 @@ const getHeaders = ({
196
196
  referrer,
197
197
  }) => ({
198
198
  Authorization: `Bearer ${apiKey}`,
199
- 'Octo-Env': octoEnv,
199
+ ...octoEnv ? { 'Octo-Env': octoEnv } : {},
200
200
  ...acceptLanguage ? { 'Accept-Language': acceptLanguage } : {},
201
201
  'Content-Type': 'application/json',
202
202
  ...referrer ? { Referer: referrer } : {},
@@ -209,12 +209,39 @@ class Plugin {
209
209
  });
210
210
  }
211
211
 
212
+ async validateToken({
213
+ token: {
214
+ apiKey,
215
+ endpoint,
216
+ octoEnv,
217
+ acceptLanguage,
218
+ },
219
+ }) {
220
+ const url = `${endpoint || this.endpoint}/supplier`;
221
+ const headers = getHeaders({
222
+ apiKey,
223
+ endpoint,
224
+ octoEnv,
225
+ acceptLanguage,
226
+ });
227
+ try {
228
+ const results = R.path(['data', 'destinations'], await axios({
229
+ method: 'get',
230
+ url,
231
+ headers,
232
+ }));
233
+ return Array.isArray(results);
234
+ } catch (err) {
235
+ return false;
236
+ }
237
+ }
238
+
212
239
  async searchProducts({
213
240
  token: {
214
- apiKey = this.apiKey,
215
- endpoint = this.endpoint,
216
- octoEnv = this.octoEnv,
217
- acceptLanguage = this.acceptLanguage,
241
+ apiKey,
242
+ endpoint,
243
+ octoEnv,
244
+ acceptLanguage,
218
245
  },
219
246
  payload,
220
247
  }) {
@@ -256,10 +283,10 @@ class Plugin {
256
283
 
257
284
  async searchQuote({
258
285
  token: {
259
- apiKey = this.apiKey,
260
- endpoint = this.endpoint,
261
- octoEnv = this.octoEnv,
262
- acceptLanguage = this.acceptLanguage,
286
+ apiKey,
287
+ endpoint,
288
+ octoEnv,
289
+ acceptLanguage,
263
290
  },
264
291
  payload: {
265
292
  productIds,
@@ -301,10 +328,10 @@ class Plugin {
301
328
 
302
329
  async searchAvailability({
303
330
  token: {
304
- apiKey = this.apiKey,
305
- endpoint = this.endpoint,
306
- octoEnv = this.octoEnv,
307
- acceptLanguage = this.acceptLanguage,
331
+ apiKey,
332
+ endpoint,
333
+ octoEnv,
334
+ acceptLanguage,
308
335
  },
309
336
  token,
310
337
  payload: {
@@ -392,10 +419,10 @@ class Plugin {
392
419
 
393
420
  async availabilityCalendar({
394
421
  token: {
395
- apiKey = this.apiKey,
396
- endpoint = this.endpoint,
397
- octoEnv = this.octoEnv,
398
- acceptLanguage = this.acceptLanguage,
422
+ apiKey,
423
+ endpoint,
424
+ octoEnv,
425
+ acceptLanguage,
399
426
  },
400
427
  token,
401
428
  payload: {
@@ -471,10 +498,10 @@ class Plugin {
471
498
 
472
499
  async createBooking({
473
500
  token: {
474
- apiKey = this.apiKey,
475
- endpoint = this.endpoint,
476
- octoEnv = this.octoEnv,
477
- acceptLanguage = this.acceptLanguage,
501
+ apiKey,
502
+ endpoint,
503
+ octoEnv,
504
+ acceptLanguage,
478
505
  },
479
506
  payload: {
480
507
  availabilityKey,
@@ -527,10 +554,10 @@ class Plugin {
527
554
 
528
555
  async cancelBooking({
529
556
  token: {
530
- apiKey = this.apiKey,
531
- endpoint = this.endpoint,
532
- octoEnv = this.octoEnv,
533
- acceptLanguage = this.acceptLanguage,
557
+ apiKey,
558
+ endpoint,
559
+ octoEnv,
560
+ acceptLanguage,
534
561
  },
535
562
  payload: {
536
563
  bookingId,
@@ -557,10 +584,10 @@ class Plugin {
557
584
 
558
585
  async searchBooking({
559
586
  token: {
560
- apiKey = this.apiKey,
561
- endpoint = this.endpoint,
562
- octoEnv = this.octoEnv,
563
- acceptLanguage = this.acceptLanguage,
587
+ apiKey,
588
+ endpoint,
589
+ octoEnv,
590
+ acceptLanguage,
564
591
  },
565
592
  payload: {
566
593
  bookingId,
package/index.test.js CHANGED
@@ -53,6 +53,20 @@ describe('search tests', () => {
53
53
  });
54
54
  it.todo('family + one');
55
55
  });
56
+ describe('validateToken', () => {
57
+ it('valid token', async () => {
58
+ const retVal = await app.validateToken({
59
+ token,
60
+ });
61
+ expect(retVal).toBeTruthy();
62
+ });
63
+ it('invalid token', async () => {
64
+ const retVal = await app.validateToken({
65
+ token: { someRandom: 'thing' },
66
+ });
67
+ expect(retVal).toBeFalsy();
68
+ });
69
+ });
56
70
  });
57
71
  describe('booking process', () => {
58
72
  it('get for all products, a test product should exist', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  "axios-curlirize": "^1.3.7",
32
32
  "bluebird": "^3.7.2",
33
33
  "jsonwebtoken": "^8.5.1",
34
- "moment": "^2.29.1",
34
+ "moment": "^2.29.4",
35
35
  "ramda": "^0.27.1"
36
36
  },
37
37
  "devDependencies": {