ti2 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Ti2
2
+ Tourism Industry Interchange
3
+
4
+ ## Getting Started
5
+
6
+ ### Requirements
7
+
8
+ Some environment variables are required for ti2 to start
9
+
10
+ - DB_URL (mysql connection in url format)
11
+ - dbCryptoKey (integration details encription key)
12
+ - adminKey (a key for admin related requests)
13
+ - jwtKey (a key to encrypt user sessions request)
14
+ - frontendKey (an additional optional key to validate the origin of the requests)
15
+ - PORT (an optional port to run the http server, in case a port is not specified as a parameter)
16
+
17
+ ### Starting your server
18
+
19
+ You can start your own instance by adding a requirement on your own nodejs project as follows:
20
+
21
+ ```bash
22
+ $ npm i ti2
23
+ ```
24
+
25
+ To start the server with default values use the following:
26
+
27
+ ```javascript
28
+ const ti2 = require('ti2')({
29
+ plugins: {
30
+ travelgate: require('ti2-travelgate'),
31
+ ventrata: require('ti2-ventrata'),
32
+ tourconnect: require('ti2-tourconnect'),
33
+ },
34
+ });
35
+ ```
36
+
37
+ ## Plugins
38
+
39
+ Plugins are the connectores to other systems and/or features you intent to use; by default the server will start an API service on port 10010 and the swagger documentation on the path //api-docs, (you can disable wither by passing the startServer param as False or the apiDocs as False.
40
+
41
+ Plugin environment keys are passed down to the instance while is being created, this is the preferred way of accesing environmen keys from the plugins, such values are not design to hold client / user's API keys or specific data, they are to be stored on the database itself via the AppKey collection.
42
+
43
+ Plugin ENV variable name convention: ti2_pluginName_environmenVariableName, for example:
44
+
45
+ ```env
46
+ ti2_tourconnect_apiUrl=http://backend:8080
47
+ ```
48
+
49
+ ### Available Plugins
50
+
51
+ | Repo | Features | Maintainer |
52
+ | ---- | -------- | ---------- |
53
+ | [ti2-ventrata](https://github.com/TourConnect/ti2-ventrata) | Bookings: Search, Cancellation | TourConnect |
54
+ | [ti2-travelgate](https://github.com/TourConnect/ti2-travelgate) | Bookings: Search, Cancellation | TourConnect |
55
+
56
+ ## API logging
57
+
58
+ Currently logging is supported via elastic search, an elasticLogClient value can ben passed down, example:
59
+
60
+ ```javascript
61
+ const { Client } = require('@elastic/elasticsearch');
62
+ const elasticLogsClient = (() => {
63
+ if (!elasticLogs) return null;
64
+ return new Client({ node: elasticLogs });
65
+ })();
66
+
67
+ const ti2 = require('ti2')({
68
+ elasticLogsClient,
69
+ plugins: {
70
+ ventrata: require('ti2-ventrata'),
71
+ travelgate: require('ti2-travelgate'),
72
+ tourconnect: require('ti2-tourconnect'),
73
+ },
74
+ });
75
+ ```
76
+
77
+ ## Contributing
78
+
79
+ Contributions are welcome and ecouraged.
80
+
81
+ If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
82
+
83
+ - Fork the Project
84
+ - Create your Feature Branch (git checkout -b feature/AmazingFeature)
85
+ - Commit your Changes (git commit -m 'Add some AmazingFeature')
86
+ - Push to the Branch (git push origin feature/AmazingFeature)
87
+ - Open a Pull Request
88
+
89
+ Feel free to check the [Issues Page](https://github.com/TourConnect/ti2/issues).
90
+
91
+ ## License
92
+
93
+ Distributed under the GPL-3 License. See LICENSE.txt for more information.
94
+
95
+ TL;DR Here's what the license entails:
96
+
97
+ 1. Anyone can copy, modify and distribute this software.
98
+ 2. You have to include the license and copyright notice with each and every distribution.
99
+ 3. You can use this software privately.
100
+ 4. You can use this software for commercial purposes.
101
+ 5. If you dare build your business solely from this code, you risk open-sourcing the whole code base.
102
+ 6. If you modify it, you have to indicate changes made to the code.
103
+ 7. Any modifications of this code base MUST be distributed with the same license, GPLv3.
104
+ 8. This software is provided without warranty.
105
+ 9. The software author or license can not be held liable for any damages inflicted by the software.
106
+
package/api.yml ADDED
@@ -0,0 +1,614 @@
1
+ # swagger configuration file
2
+ openapi: '3.0.0'
3
+ info:
4
+ description: TourConnect's Ti2 sync service
5
+ version: 0.0.1
6
+ title: Ti2
7
+ contact:
8
+ email: engineering@tourconnect.com
9
+ components:
10
+ securitySchemes:
11
+ bearerAuth:
12
+ type: http
13
+ scheme: bearer
14
+ bearerFormat: JWT
15
+ schemas:
16
+ ServerInfo:
17
+ type: object
18
+ properties:
19
+ name:
20
+ type: string
21
+ description:
22
+ type: string
23
+ version:
24
+ type: string
25
+ uptime:
26
+ type: string
27
+ Message:
28
+ type: object
29
+ properties:
30
+ value:
31
+ type: string
32
+ App:
33
+ type: object
34
+ properties:
35
+ name:
36
+ type: string
37
+ example: expedia
38
+ packageName:
39
+ type: string
40
+ example: ti2-expedia
41
+ adminEmail:
42
+ type: string
43
+ example: ti2+expedia@tourconnect.com
44
+ AnyValue:
45
+ description: Can be anything
46
+ type: object
47
+ properties:
48
+ payload:
49
+ type: object
50
+ example: random lorem
51
+ UserApp:
52
+ description: A user + App configuration
53
+ type: object
54
+ properties:
55
+ tokenHint:
56
+ type: string
57
+ description: An identifier for this token, it should NOT be the token itself but a short description of it
58
+ example: 'expediaTestLocation-23'
59
+ token:
60
+ type: object
61
+ description: this is the secret payload that is passed doen to the plugin
62
+ example: { endpoint: 'http://expedia.penguin.local', apiKey: 'this is a secret key' }
63
+ UserAppDelete:
64
+ description: A user + App configuration to delete
65
+ type: object
66
+ properties:
67
+ tokenHint:
68
+ type: string
69
+ description: An identifier for this token, it should NOT be the token itself but a short safe version of it
70
+ example: 'expediaTestLocation-23'
71
+ UserId:
72
+ description: userId to create the token for
73
+ type: object
74
+ properties:
75
+ userId:
76
+ type: string
77
+ description: the userId to create the token for
78
+ example: '536830b6ed19afa44a000002'
79
+ IntegrationList:
80
+ type: object
81
+ properties:
82
+ integrations:
83
+ type: array
84
+ items:
85
+ type: object
86
+ properties:
87
+ adminEmail:
88
+ type: string
89
+ createdAt:
90
+ type: string
91
+ lastSeen:
92
+ type: string
93
+ name:
94
+ type: string
95
+ packageName:
96
+ type: string
97
+ updatedAt:
98
+ type: string
99
+ AppTokenList:
100
+ type: object
101
+ properties:
102
+ userAppKeys:
103
+ type: array
104
+ items:
105
+ type: object
106
+ properties:
107
+ integrationId:
108
+ type: string
109
+ userId:
110
+ type: string
111
+ hint:
112
+ type: string
113
+ createdAt:
114
+ type: string
115
+ updatedAt:
116
+ type: string
117
+ appRequest:
118
+ type: object
119
+ properties:
120
+ tokenHint:
121
+ type: string
122
+ example: 'expediaTestLocation-23'
123
+ required: true
124
+ entity:
125
+ type: string
126
+ required: true
127
+ entityId:
128
+ type: string
129
+ required: false
130
+ default: null
131
+ entityParentId:
132
+ type: string
133
+ required: false
134
+ default: null
135
+ appMethods:
136
+ type: object
137
+ properties:
138
+ methods:
139
+ type: array
140
+ items:
141
+ type: string
142
+ bookingSearchQuery:
143
+ type: object
144
+ properties:
145
+ bookingId:
146
+ type: string
147
+ required: false
148
+ default: null
149
+ name:
150
+ type: string
151
+ required: false
152
+ default: null
153
+ purchaseDateStart:
154
+ type: string
155
+ required: false
156
+ default: null
157
+ purchaseDateEnd:
158
+ type: string
159
+ required: false
160
+ default: null
161
+ travelDateStart:
162
+ type: string
163
+ required: false
164
+ default: "01/04/2021"
165
+ travelDateEnd:
166
+ type: string
167
+ required: false
168
+ default: "10/04/2021"
169
+ dateFormat:
170
+ type: string
171
+ required: false
172
+ default: "DD/MM/YYYY"
173
+ bookingDetail:
174
+ type: object
175
+ properties:
176
+ id:
177
+ type: string
178
+ required: true
179
+ description: The booking Id
180
+ status:
181
+ type: string
182
+ required: true
183
+ description: The booking status
184
+
185
+ bookingDetailsForCancel:
186
+ allOf: # Combines the BasicErrorModel and the inline model
187
+ - $ref: '#/components/schemas/bookingDetail'
188
+ type: object
189
+ properties:
190
+ clicked:
191
+ type: integer
192
+ required: true
193
+ description: The unix time the cancellation was sent
194
+ paths:
195
+ /ping:
196
+ get:
197
+ tags:
198
+ - public
199
+ summary: Should return basic system status
200
+ operationId: ping
201
+ responses:
202
+ '200':
203
+ description: success
204
+ content:
205
+ application/json:
206
+ schema:
207
+ $ref: '#/components/schemas/ServerInfo'
208
+ /app:
209
+ post:
210
+ security:
211
+ - bearerAuth: ['admin']
212
+ tags:
213
+ - admin
214
+ summary: Should create a new App, the name of the app should be url safe (no spaces)
215
+ operationId: createApp
216
+ requestBody:
217
+ description: App name to create, should be urlsafe and have a correspondant npm package already in the required npm modules as ti2-appName
218
+ required: true
219
+ content:
220
+ application/json:
221
+ schema:
222
+ $ref: '#/components/schemas/App'
223
+ responses:
224
+ 200:
225
+ description: success
226
+ content:
227
+ application/json:
228
+ schema:
229
+ $ref: '#/components/schemas/Message'
230
+ /apps:
231
+ get:
232
+ security:
233
+ - bearerAuth: ['admin']
234
+ tags:
235
+ - admin
236
+ summary: list all previously created apps
237
+ operationId: listApps
238
+ responses:
239
+ 200:
240
+ description: success
241
+ content:
242
+ application/json:
243
+ schema:
244
+ $ref: '#/components/schemas/IntegrationList'
245
+ /app/resetAppKey/{appKey}:
246
+ get:
247
+ security:
248
+ - bearerAuth: ['admin']
249
+ tags:
250
+ - admin
251
+ summary:
252
+ reset an auth token for an integration
253
+ operationId: resetIntegrationToken
254
+ parameters:
255
+ - name: appKey
256
+ in: path
257
+ description: name of the app to reset the apiKey
258
+ required: true
259
+ example: 'expedia'
260
+ schema:
261
+ type: string
262
+ responses:
263
+ 200:
264
+ description: success
265
+ content:
266
+ application/json:
267
+ schema:
268
+ $ref: '#/components/schemas/Message'
269
+ /user:
270
+ post:
271
+ security:
272
+ - bearerAuth: ['admin']
273
+ tags:
274
+ - admin
275
+ summary: Create a new user authentication token
276
+ operationId: createUserToken
277
+ requestBody:
278
+ required: true
279
+ content:
280
+ application/json:
281
+ schema:
282
+ $ref: '#/components/schemas/UserId'
283
+ responses:
284
+ 200:
285
+ description: success
286
+ content:
287
+ application/json:
288
+ schema:
289
+ $ref: '#/components/schemas/Message'
290
+ /app/encode/{app}:
291
+ security:
292
+ - bearerAuth: ['app']
293
+ put:
294
+ tags:
295
+ - app
296
+ summary: Should encode an arbitriary field body into a hash
297
+ security:
298
+ - bearerAuth: ['app']
299
+ operationId: jwtEncode
300
+ parameters:
301
+ - name: app
302
+ in: path
303
+ description: name of the requesting app
304
+ required: true
305
+ example: 'expedia'
306
+ schema:
307
+ type: string
308
+ requestBody:
309
+ description: Payload to encode
310
+ required: true
311
+ content:
312
+ application/json:
313
+ schema:
314
+ $ref: '#/components/schemas/AnyValue'
315
+ responses:
316
+ 200:
317
+ description: success
318
+ content:
319
+ application/json:
320
+ schema:
321
+ $ref: '#/components/schemas/Message'
322
+ /app/tokens/{app}:
323
+ get:
324
+ security:
325
+ - bearerAuth: ['app']
326
+ tags:
327
+ - app
328
+ summary: List all users/tokens for this app
329
+ operationId: listAppTokens
330
+ parameters:
331
+ - name: app
332
+ in: path
333
+ description: app name to list the users for
334
+ example: 'expedia'
335
+ required: true
336
+ schema:
337
+ type: string
338
+ responses:
339
+ 200:
340
+ description: success
341
+ content:
342
+ application/json:
343
+ schema: '#/components/schemas/AppTokenList'
344
+ /{app}/{userId}:
345
+ security:
346
+ - bearerAuth: ['app']
347
+ post:
348
+ tags:
349
+ - app
350
+ - user
351
+ - admin
352
+ summary: Create a user app+Token configuration, the authorization can be either from the app or the user
353
+ security:
354
+ - bearerAuth: ['app', 'user', 'admin']
355
+ operationId: createAppToken
356
+ parameters:
357
+ - name: app
358
+ in: path
359
+ description: app name to create the userId for (must match app token)
360
+ example: 'expedia'
361
+ required: true
362
+ schema:
363
+ type: string
364
+ - name: userId
365
+ in: path
366
+ description: user to create the app for
367
+ example: '536830b6ed19afa44a000002'
368
+ required: true
369
+ schema:
370
+ type: string
371
+ requestBody:
372
+ description: A new User+App configuration
373
+ required: true
374
+ content:
375
+ application/json:
376
+ schema:
377
+ $ref: '#/components/schemas/UserApp'
378
+ responses:
379
+ 200:
380
+ description: success
381
+ content:
382
+ application/json:
383
+ schema: '#/components/schemas/Message'
384
+ delete:
385
+ tags:
386
+ - app
387
+ - user
388
+ summary: Should delete a user+appToken configuration, the auth token can be from an app or a user
389
+ security:
390
+ - bearerAuth: ['admin', 'app', 'user']
391
+ operationId: deleteAppToken
392
+ parameters:
393
+ - name: app
394
+ in: path
395
+ description: app name to create the userId for (must match app token)
396
+ example: 'expedia'
397
+ required: true
398
+ schema:
399
+ type: string
400
+ - name: userId
401
+ in: path
402
+ description: user to delete the app for
403
+ example: '536830b6ed19afa44a000002'
404
+ required: true
405
+ schema:
406
+ type: string
407
+ requestBody:
408
+ description: The User+App configuration to remove
409
+ required: true
410
+ content:
411
+ application/json:
412
+ schema:
413
+ $ref: '#/components/schemas/UserAppDelete'
414
+ responses:
415
+ 200:
416
+ description: success
417
+ content:
418
+ application/json:
419
+ schema: '#/components/schemas/Message'
420
+ /user/{userId}/apps:
421
+ get:
422
+ security:
423
+ - bearerAuth: ['admin', 'user']
424
+ tags:
425
+ - user
426
+ - admin
427
+ summary: Should get a list of app keys tokens that belong to a user
428
+ operationId: userAppList
429
+ parameters:
430
+ - name: userId
431
+ in: path
432
+ description: id of the owner
433
+ example: '536830b6ed19afa44a000002'
434
+ required: true
435
+ schema:
436
+ type: string
437
+ responses:
438
+ 200:
439
+ description: success
440
+ content:
441
+ application/json:
442
+ schema: '#/components/schemas/AppTokenList'
443
+ /app/{appKey}/methods:
444
+ get:
445
+ security:
446
+ - bearerAuth: ['admin', 'user']
447
+ tags:
448
+ - user
449
+ summary: Should get the methods available for an app
450
+ operationId: getAppMethods
451
+ parameters:
452
+ - name: appKey
453
+ in: path
454
+ description: name of the app to get the methods for
455
+ required: true
456
+ example: 'expedia'
457
+ schema:
458
+ type: string
459
+ responses:
460
+ 200:
461
+ description: the methods available
462
+ content:
463
+ appication/json:
464
+ schema: '#/components/schemas/appMethods'
465
+ /bookings/{appKey}/{userId}/search:
466
+ post:
467
+ security:
468
+ - bearerAuth: ['admin', 'user']
469
+ tags:
470
+ - bookings
471
+ summary: Gets all Bookings related to the search
472
+ operationId: bookingsSearch
473
+ parameters:
474
+ - name: appKey
475
+ in: path
476
+ description: name of the app to search the bookings for (defaults to first token found
477
+ required: true
478
+ example: 'travelgate'
479
+ schema:
480
+ type: string
481
+ - name: userId
482
+ in: path
483
+ description: the user/company that the appKey belongs to
484
+ required: true
485
+ schema:
486
+ type: string
487
+ requestBody:
488
+ description: both app details
489
+ required: true
490
+ content:
491
+ application/json:
492
+ schema:
493
+ $ref: '#/components/schemas/bookingSearchQuery'
494
+ responses:
495
+ description: search results
496
+ content:
497
+ application/json:
498
+ schema: '#/components/schemas/AnyValue'
499
+ /bookings/{appKey}/{userId}/{hint}/search:
500
+ post:
501
+ security:
502
+ - bearerAuth: ['admin', 'user']
503
+ tags:
504
+ - bookings
505
+ summary: Gets all Bookings related to the search for a specific hint
506
+ operationId: bookingsSearch
507
+ parameters:
508
+ - name: appKey
509
+ in: path
510
+ description: name of the app to get the methods for
511
+ required: true
512
+ example: 'travelgate'
513
+ schema:
514
+ type: string
515
+ - name: userId
516
+ in: path
517
+ description: the user/company that the appKey belogs to
518
+ required: true
519
+ schema:
520
+ type: string
521
+ - name: hint
522
+ in: path
523
+ description: a specific token hint to be used
524
+ required: true
525
+ example: 'travelgate-australia'
526
+ schema:
527
+ type: string
528
+ requestBody:
529
+ description: booking search parameters
530
+ required: true
531
+ content:
532
+ application/json:
533
+ schema:
534
+ $ref: '#/components/schemas/bookingSearchQuery'
535
+ responses:
536
+ description: search results
537
+ content:
538
+ application/json:
539
+ schema: '#/components/schemas/AnyValue'
540
+ /bookings/{appKey}/{userId}/cancel:
541
+ post:
542
+ security:
543
+ - bearerAuth: ['admin', 'user']
544
+ tags:
545
+ - bookings
546
+ summary: Sends a Booking cancellation
547
+ operationId: bookingsCancel
548
+ parameters:
549
+ - name: appKey
550
+ in: path
551
+ description: app to cancel the booking for, defaults to first token
552
+ required: true
553
+ example: 'travelgate-hotelx'
554
+ schema:
555
+ type: string
556
+ - name: userId
557
+ in: path
558
+ description: the user/company that the appKey belongs to
559
+ required: true
560
+ schema:
561
+ type: string
562
+ requestBody:
563
+ description: both app details
564
+ required: true
565
+ content:
566
+ application/json:
567
+ schema:
568
+ $ref: '#/components/schemas/bookingDetailsForCancel'
569
+ responses:
570
+ description: search results
571
+ content:
572
+ application/json:
573
+ schema: '#/components/schemas/AnyValue'
574
+ /bookings/{appKey}/{userId}/{hint}/cancel:
575
+ post:
576
+ security:
577
+ - bearerAuth: ['admin', 'user']
578
+ tags:
579
+ - bookings
580
+ summary: Sends a Booking cancellation for an specific hint
581
+ operationId: bookingsCancel
582
+ parameters:
583
+ - name: appKey
584
+ in: path
585
+ description: app to cancel the booking for
586
+ required: true
587
+ example: 'travelgate'
588
+ schema:
589
+ type: string
590
+ - name: userId
591
+ in: path
592
+ description: the user/company that the appKey belongs to
593
+ required: true
594
+ schema:
595
+ type: string
596
+ - name: hint
597
+ in: path
598
+ description: a specific token hint to be used
599
+ required: true
600
+ example: 'travelgate-australia'
601
+ schema:
602
+ type: string
603
+ requestBody:
604
+ description: both app details
605
+ required: true
606
+ content:
607
+ application/json:
608
+ schema:
609
+ $ref: '#/components/schemas/bookingDetailsForCancel'
610
+ responses:
611
+ description: search results
612
+ content:
613
+ application/json:
614
+ schema: '#/components/schemas/AnyValue'