ti2-ventrata 1.0.12 → 1.0.14

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 +82 -29
  2. package/index.test.js +45 -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 } : {},
@@ -207,14 +207,67 @@ class Plugin {
207
207
  Object.entries(params).forEach(([attr, value]) => {
208
208
  this[attr] = value;
209
209
  });
210
+ this.tokenTemplate = () => ({
211
+ apiKey: {
212
+ type: 'text',
213
+ regExp: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,
214
+ description: 'the Api Key provided from Ventrata, should be in uuid format',
215
+ },
216
+ endpoint: {
217
+ type: 'text',
218
+ regExp: /^(?!mailto:)(?:(?:http|https|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:(\/|\?|#)[^\s]*)?$/i,
219
+ default: 'https://api.ventrata.com/octo',
220
+ description: 'The url api endpoint from Ventata',
221
+ },
222
+ octoEnv: {
223
+ type: 'text',
224
+ list: ['live', 'test'],
225
+ regExp: /^(live|test)$/,
226
+ description: 'If on test it will not consume any availability, the barcodes will not work, and you will not be invoiced for it',
227
+ default: 'live',
228
+ },
229
+ acceptLanguage: {
230
+ type: 'text',
231
+ regExp: /^[a-z]{2}$/,
232
+ description: 'This conforms to the regular HTTP specification for language but if the supplier has translated their content it will return the content in the specified language if possible',
233
+ default: 'en',
234
+ },
235
+ });
236
+ }
237
+
238
+ async validateToken({
239
+ token: {
240
+ apiKey,
241
+ endpoint,
242
+ octoEnv,
243
+ acceptLanguage,
244
+ },
245
+ }) {
246
+ const url = `${endpoint || this.endpoint}/supplier`;
247
+ const headers = getHeaders({
248
+ apiKey,
249
+ endpoint,
250
+ octoEnv,
251
+ acceptLanguage,
252
+ });
253
+ try {
254
+ const results = R.path(['data', 'destinations'], await axios({
255
+ method: 'get',
256
+ url,
257
+ headers,
258
+ }));
259
+ return Array.isArray(results);
260
+ } catch (err) {
261
+ return false;
262
+ }
210
263
  }
211
264
 
212
265
  async searchProducts({
213
266
  token: {
214
- apiKey = this.apiKey,
215
- endpoint = this.endpoint,
216
- octoEnv = this.octoEnv,
217
- acceptLanguage = this.acceptLanguage,
267
+ apiKey,
268
+ endpoint,
269
+ octoEnv,
270
+ acceptLanguage,
218
271
  },
219
272
  payload,
220
273
  }) {
@@ -256,10 +309,10 @@ class Plugin {
256
309
 
257
310
  async searchQuote({
258
311
  token: {
259
- apiKey = this.apiKey,
260
- endpoint = this.endpoint,
261
- octoEnv = this.octoEnv,
262
- acceptLanguage = this.acceptLanguage,
312
+ apiKey,
313
+ endpoint,
314
+ octoEnv,
315
+ acceptLanguage,
263
316
  },
264
317
  payload: {
265
318
  productIds,
@@ -301,10 +354,10 @@ class Plugin {
301
354
 
302
355
  async searchAvailability({
303
356
  token: {
304
- apiKey = this.apiKey,
305
- endpoint = this.endpoint,
306
- octoEnv = this.octoEnv,
307
- acceptLanguage = this.acceptLanguage,
357
+ apiKey,
358
+ endpoint,
359
+ octoEnv,
360
+ acceptLanguage,
308
361
  },
309
362
  token,
310
363
  payload: {
@@ -392,10 +445,10 @@ class Plugin {
392
445
 
393
446
  async availabilityCalendar({
394
447
  token: {
395
- apiKey = this.apiKey,
396
- endpoint = this.endpoint,
397
- octoEnv = this.octoEnv,
398
- acceptLanguage = this.acceptLanguage,
448
+ apiKey,
449
+ endpoint,
450
+ octoEnv,
451
+ acceptLanguage,
399
452
  },
400
453
  token,
401
454
  payload: {
@@ -471,10 +524,10 @@ class Plugin {
471
524
 
472
525
  async createBooking({
473
526
  token: {
474
- apiKey = this.apiKey,
475
- endpoint = this.endpoint,
476
- octoEnv = this.octoEnv,
477
- acceptLanguage = this.acceptLanguage,
527
+ apiKey,
528
+ endpoint,
529
+ octoEnv,
530
+ acceptLanguage,
478
531
  },
479
532
  payload: {
480
533
  availabilityKey,
@@ -527,10 +580,10 @@ class Plugin {
527
580
 
528
581
  async cancelBooking({
529
582
  token: {
530
- apiKey = this.apiKey,
531
- endpoint = this.endpoint,
532
- octoEnv = this.octoEnv,
533
- acceptLanguage = this.acceptLanguage,
583
+ apiKey,
584
+ endpoint,
585
+ octoEnv,
586
+ acceptLanguage,
534
587
  },
535
588
  payload: {
536
589
  bookingId,
@@ -557,10 +610,10 @@ class Plugin {
557
610
 
558
611
  async searchBooking({
559
612
  token: {
560
- apiKey = this.apiKey,
561
- endpoint = this.endpoint,
562
- octoEnv = this.octoEnv,
563
- acceptLanguage = this.acceptLanguage,
613
+ apiKey,
614
+ endpoint,
615
+ octoEnv,
616
+ acceptLanguage,
564
617
  },
565
618
  payload: {
566
619
  bookingId,
package/index.test.js CHANGED
@@ -53,6 +53,51 @@ 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
+ });
70
+ describe('template tests', () => {
71
+ let template;
72
+ it('get the template', async () => {
73
+ template = await app.tokenTemplate();
74
+ const rules = Object.keys(template);
75
+ expect(rules).toContain('apiKey');
76
+ expect(rules).toContain('endpoint');
77
+ expect(rules).toContain('octoEnv');
78
+ expect(rules).toContain('acceptLanguage');
79
+ });
80
+ it('apiKey', () => {
81
+ const apiKey = template.apiKey.regExp;
82
+ expect(apiKey.test('something')).toBeFalsy();
83
+ expect(apiKey.test('f5eb2e1f-4b8f-4b43-a858-4a12d77b8299')).toBeTruthy();
84
+ });
85
+ it('endpoint', () => {
86
+ const endpoint = template.endpoint.regExp;
87
+ expect(endpoint.test('something')).toBeFalsy();
88
+ expect(endpoint.test('https://www.google.com')).toBeTruthy();
89
+ });
90
+ it('octoEnv', () => {
91
+ const octoEnv = template.octoEnv.regExp;
92
+ expect(octoEnv.test('something')).toBeFalsy();
93
+ expect(octoEnv.test('live')).toBeTruthy();
94
+ });
95
+ it('acceptLanguage', () => {
96
+ const acceptLanguage = template.acceptLanguage.regExp;
97
+ expect(acceptLanguage.test('something')).toBeFalsy();
98
+ expect(acceptLanguage.test('en')).toBeTruthy();
99
+ });
100
+ });
56
101
  });
57
102
  describe('booking process', () => {
58
103
  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.14",
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": {