ti2-ventrata 1.0.13 → 1.0.15

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 +29 -8
  2. package/index.test.js +31 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -207,30 +207,51 @@ 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
+ });
210
236
  }
211
237
 
212
238
  async validateToken({
213
239
  token: {
214
240
  apiKey,
215
241
  endpoint,
216
- octoEnv,
217
- acceptLanguage,
218
242
  },
219
243
  }) {
220
- const url = `${endpoint || this.endpoint}/supplier`;
244
+ const url = `${endpoint || this.endpoint}/whoami?token=${apiKey}`;
221
245
  const headers = getHeaders({
222
246
  apiKey,
223
- endpoint,
224
- octoEnv,
225
- acceptLanguage,
226
247
  });
227
248
  try {
228
- const results = R.path(['data', 'destinations'], await axios({
249
+ const connectionId = R.path(['data', 'connection', 'id'], await axios({
229
250
  method: 'get',
230
251
  url,
231
252
  headers,
232
253
  }));
233
- return Array.isArray(results);
254
+ return /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/.test(connectionId);
234
255
  } catch (err) {
235
256
  return false;
236
257
  }
package/index.test.js CHANGED
@@ -67,6 +67,37 @@ describe('search tests', () => {
67
67
  expect(retVal).toBeFalsy();
68
68
  });
69
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
+ });
70
101
  });
71
102
  describe('booking process', () => {
72
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.13",
3
+ "version": "1.0.15",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {