ti2 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.
package/README.md CHANGED
@@ -4,6 +4,12 @@ Ti2 (Tourism Information Interchange) is an open source integration framework, b
4
4
 
5
5
  Core functions of Ti2 are currently focused on content, rates, and bookings.
6
6
 
7
+ ### Why use it ?
8
+
9
+ Ti2 gives a free, open source solution to building integrations across our industry. In addition, tools can be built on top of Ti2, that add additional value to these integrations - whether for the good of our industry or for profit.
10
+
11
+ **Become part of the community, start building on Ti2 today!**
12
+
7
13
  ## About this Project
8
14
 
9
15
  ### How it Works
@@ -16,57 +22,27 @@ App Plugins are value added tools that only speak to Ti2 and other plugins. For
16
22
 
17
23
  Ti2 can be deployed on your own servers, or you can connect to a Ti2 instance that another company is hosting.
18
24
 
19
- ### Why use Ti2 ?
20
-
21
- Ti2 gives a free, open source solution to building integrations across our industry. In addition, tools can be built on top of Ti2, that add additional value to these integrations - whether for the good of our industry or for profit.
22
-
23
- **Become part of the community, start building on Ti2 today!**
24
-
25
- ## Getting Started
25
+ ### Security
26
26
 
27
- ### Requirements
27
+ An admin api key is set trough an environment variable called adminKey; using this API key is possible to create Users and/or application authentications.
28
28
 
29
- Some environment variables are required for ti2 to start
29
+ A new User / User Authentication can be created using the endpoint [createUserToken](https://ti2.tourconnect.dev/api-docs/#/admin/createUserToken); the return value consists of a JWT token for further user intraction with the App; the admin API key is required; no password is saved on the server side.
30
30
 
31
- - DB_URL (mysql connection in url format)
32
- - dbCryptoKey (integration details encription key, should be a 32 chars random string base64 encoded)
33
- - adminKey (a key for admin related requests)
34
- - jwtKey (a key to encrypt user sessions request)
35
- - frontendKey (an additional optional key to validate the origin of the requests)
36
- - PORT (an optional port to run the http server, in case a port is not specified as a parameter)
31
+ Apps / Integrations can be created using the admin API Key; this after the plugin had been added to the codebase; the app can be created using the endpoint [createApp](https://ti2.tourconnect.dev/api-docs/#/admin/createApp); such endpoint returns a key that can be used by the app to interact with user Ids; such interactions allow the app to push for changes related to user integrations, the app can list the users currently configured for it using the endpoint [listAppTokens](https://ti2.tourconnect.dev/api-docs/#/app/listAppTokens); the passwords for Apps are encripted onde the database using aes-256-cbc, more details can be found on the [``models/integrations.js``](https://github.com/ti2travel/ti2/blob/main/models/integration.js) file.
37
32
 
38
- ### Starting your server
33
+ User + app integration credentials can be added after the app has been added to the system; these can be added by either the user, admin or the app itself using the endpoint [createAppToken](https://ti2.tourconnect.dev/api-docs/#/app/createAppToken). These keys are saved in JWT format on the database.
39
34
 
40
- You can start your own instance by instlling ti2 and any aplugin syou may want to use on your own nodejs project root folter:
35
+ ## Getting Started
41
36
 
42
- ```bash
43
- $ npm i ti2 ti2-travelgate ti2-ventrata ti2-tourconnect
44
- ```
37
+ You can start follow [this guide]{@tutorial setup-your-instance} to create an instance, if you want to add an integration (like for your own backend) or add a new internal funtionality you can [create a plugin]{@tutorial plugin-development} for your system.
45
38
 
46
- To start the server with default values use the following:
39
+ By default a ti2 instance serves a documentation page on the url (http://[yourinstance]/api-docs/) that serves the available API restfull methods, you can review the [swagger documentation page online](https://ti2-staging.tourconnect.com/api-docs/) .
47
40
 
48
- ```javascript
49
- const ti2 = require('ti2')({
50
- plugins: {
51
- travelgate: require('ti2-travelgate'),
52
- ventrata: require('ti2-ventrata'),
53
- tourconnect: require('ti2-tourconnect'),
54
- },
55
- });
56
- ```
57
41
 
58
42
  ## Plugins
59
43
 
60
44
  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.
61
45
 
62
- 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.
63
-
64
- Plugin ENV variable name convention: ti2_pluginName_environmenVariableName, for example:
65
-
66
- ```env
67
- ti2_tourconnect_apiUrl=http://backend:8080
68
- ```
69
-
70
46
  ### Plugin Library
71
47
 
72
48
  | Methods | [Ventrata](https://github.com/TourConnect/ti2-ventrata) | [TravelGateX](https://github.com/TourConnect/ti2-travelgate) | [Didgigo](https://github.com/TourConnect/ti2-didgigo) | [TourConnect](https://github.com/TourConnect/ti2-tourconnect)
@@ -93,27 +69,6 @@ ti2_tourconnect_apiUrl=http://backend:8080
93
69
  |createBooking|✓|✓|
94
70
  |cancelBooking|✓|✓|
95
71
 
96
- ## API logging
97
-
98
- Currently logging is supported via elastic search, an elasticLogClient value can ben passed down, example:
99
-
100
- ```javascript
101
- const { Client } = require('@elastic/elasticsearch');
102
- const elasticLogsClient = (() => {
103
- if (!elasticLogs) return null;
104
- return new Client({ node: elasticLogs });
105
- })();
106
-
107
- const ti2 = require('ti2')({
108
- elasticLogsClient,
109
- plugins: {
110
- ventrata: require('ti2-ventrata'),
111
- travelgate: require('ti2-travelgate'),
112
- tourconnect: require('ti2-tourconnect'),
113
- },
114
- });
115
- ```
116
-
117
72
  ## Contributing
118
73
 
119
74
  Contributions are welcome and ecouraged.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
8
  "sequelize": "sequelize-cli",
9
- "doc": "jsdoc -c jsdoc.conf.json"
9
+ "doc": "jsdoc -c jsdoc.conf.json -u tutorials"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
package/test/plugin.js CHANGED
@@ -3,24 +3,9 @@ const chance = require('chance').Chance();
3
3
 
4
4
  class Plugin {
5
5
  /**
6
- * **General** Methods:
7
- * * [validateToken](#validateToken).
6
+ * For a comprehensive list of mehtods visit the
7
+ * [Plugin Development]{@tutorial plugin-development} page.
8
8
  *
9
- * **Content Methods**:
10
- * * [getProfile](#getProfile)
11
- * * [updateProfile](#updateProfile)
12
- * * [createLocation](#createLocation)
13
- * * [updateLocation](#updateLocation)
14
- * * [getProducts](#getProducts)
15
- * * [createProduct](#createProduct)
16
- * * [updateProduct](#updateProduct)
17
- *
18
- * **Booking Methods**:
19
- * * [searchBooking](#searchBooking)
20
- * * [searchProducts](#searchProducts)
21
- * * [searchAvailability](#searchAvailability)
22
- * * [searchQuote](#searchQuote)
23
- * * [createBooking](#createBooking)
24
9
  * ---
25
10
  *
26
11
  * @param {Object} args - New / Overwriting attributes for the Plugin.
@@ -61,7 +46,7 @@ class Plugin {
61
46
  }
62
47
 
63
48
  /**
64
- * Check the vailidity of an integration token. *part of **General** Methods*
49
+ * Check the vailidity of an integration token.
65
50
  * @async
66
51
  * @param {Object} args - Availability search arguments.
67
52
  * @param {Object} args.token - A token definition, it's content varies between integrations.
@@ -0,0 +1,8 @@
1
+ {
2
+ "setup-your-instance": {
3
+ "title": "Setting up your instancce"
4
+ },
5
+ "plugin-development": {
6
+ "title": "Plugin Development"
7
+ }
8
+ }
@@ -0,0 +1,220 @@
1
+ ## Environment values
2
+
3
+ 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.
4
+
5
+ Plugin ENV variable name convention: ti2_pluginName_environmenVariableName, for example:
6
+
7
+ ```env
8
+ ti2_tourconnect_apiUrl=http://backend:8080
9
+ ```
10
+
11
+ ## Methods
12
+
13
+ In oorder for an integration or system apps, we must use a set of standirzed methods to matain a compatibility; there are following methods are available, more can be supported but should be a part of the API TI2 spec to maximize it's compatibility.
14
+
15
+ **General Methods** (should always be included):
16
+ * [validateToken]{@link Plugin#validateToken}
17
+
18
+ **Content Methods** (related to marketing information update for profile, locations and/or products):
19
+ * [getProfile]{@link Plugin#getProfile}
20
+ * [updateProfile]{@link Plugin#updateProfile}
21
+ * [createLocation]{@link Plugin#createLocation}
22
+ * [updateLocation]{@link Plugin#updateLocation}
23
+ * [getProducts]{@link Plugin#getProducts}
24
+ * [createProduct]{@link Plugin#createProduct}
25
+ * [updateProduct]{@link Plugin#updateProduct}
26
+
27
+ **Booking Methods** (all related to bookings and operations):
28
+ * [searchBooking]{@link Plugin#searchBooking}
29
+ * [searchProducts]{@link Plugin#searchProducts}
30
+ * [searchAvailability]{@link Plugin#searchAvailability}
31
+ * [searchQuote]{@link Plugin#searchQuote}
32
+ * [createBooking]{@link Plugin#createBooking}
33
+
34
+ ---
35
+
36
+
37
+ ## Codebase setup
38
+
39
+ You can review some of the plugins previously developed and use them as a guide, plugin methods are encourage to include tests and return results on the same format, however the return values can include additional information, currently Ti2 is expected to run on node version 12.22.8; we suggest you use the same for your codebase.
40
+
41
+
42
+ After initializing your git environment for development; you can initialize your node project; we recommend naming your repo ti2-\<pluginname\> but it is not required.
43
+
44
+ ```bash
45
+ $ node init .
46
+ ```
47
+
48
+ ## Entry file / constructor
49
+
50
+ The plugin is expected to have an index.js file that exports a Plugin Class like so:
51
+
52
+ ```javascript
53
+ // index.js
54
+ class Plugin {
55
+ constructor(params = {}) { // we get the env variables from here
56
+ Object.entries(params).forEach(([attr, value]) => {
57
+ this[attr] = value;
58
+ });
59
+ }
60
+ }
61
+ module.exports = Plugin;
62
+ ```
63
+
64
+ The constructor of the plugins should extend the attributes with the received params, this allows the plugin to receive configurations or settings that are to be used by any user; that is settings that are shared across accounts.
65
+
66
+ By default Ti2 will pass down all environment variables that match the plugin name to it's constructor; for example, if the following environment variables are defined:
67
+
68
+ ```
69
+ ti2_ventrata_acceptLanguage=en
70
+ ti2_travelgate_clientCode=tourconnect
71
+ ti2_tourconnect_apiUrl=http://backend:8080
72
+ ```
73
+
74
+ The plugin named ti2-ventrata would receive acceptLanguage variable and it's value, ti2-travelgate the clientCode variable and ti-touconnect the apiUrl value.
75
+
76
+ ## Method calling
77
+
78
+ On the previous example code we are declaring a validateToken method; we are normally expected to receive two parameters one is token and the second one payload.
79
+
80
+ ```javascript
81
+ // index.js
82
+ class Plugin {
83
+ constructor(params = {}) { // we get the env variables from here
84
+ Object.entries(params).forEach(([attr, value]) => {
85
+ this[attr] = value;
86
+ });
87
+ }
88
+ async validateToken({
89
+ token: {
90
+ apiKey = this.apiKey,
91
+ apiUrl = this.apiUrl,
92
+ },
93
+ }) {
94
+ // TODO: actually test the apiKey against the integration.
95
+ return assert(apiKey);
96
+ }
97
+ }
98
+ module.exports = Plugin;
99
+ ```
100
+
101
+ The token parameter includes all the settings for the current configured user; on these example we are defauring this settings to the ones configured to the pluging when it was instanced; so if the user settings do not include an apiUrl it will fall back to the environment variable on the running server.
102
+
103
+ ## Testing Suite
104
+
105
+ The plugin should contain a test file, for the following example assumes we will be using jest as the testing platform.
106
+
107
+ ```bash
108
+ $ npm i -D jest
109
+ ```
110
+
111
+ ```javascript
112
+ // index.test.js
113
+ const Plugin = require('./index');
114
+
115
+ const app = new Plugin({
116
+ jwtKey: process.env.ti2_ventrata_jwtKey,
117
+ });
118
+
119
+ describe('Base Tests', () => {
120
+ const token = { // a valid token to run tests
121
+ apiKey: process.env.ti2_ventrata_apiKey,
122
+ endpoint: process.env.ti2_ventrata_endpoint,
123
+ };
124
+ it('should not validate an invalid api key', async () => {
125
+ const isValid = await app.validateToken({
126
+ token: { apiKey: 'some Randomg Text' }
127
+ });
128
+ expect(isValid).toBeFalsy();
129
+ });
130
+ it('should not validate an invalid api key', async () => {
131
+ const isValid = await app.validateToken({
132
+ token,
133
+ });
134
+ expect(isValid).toBeTruthy();
135
+ });
136
+ });
137
+
138
+ ```
139
+
140
+ ```bash
141
+ $ npx jest
142
+ ```
143
+
144
+ ## Adding the folder to a ti2 instance
145
+
146
+ After setting up a [Ti2 instance]{@tutorial setup-your-instance} you can add your development folder as a package on your instance's npm repo (not on the plugin's instance), like so:
147
+
148
+ ```json
149
+ "dependencies": {
150
+ "ti2-myplugin": "file:../ti2-myplugin"
151
+ }
152
+ ```
153
+
154
+ ## Extending the base API
155
+
156
+ Ti2 uses the [Swagger API specification](https://swagger.io/specification/) standard to define it's own methods, you can review the base methods [here](https://ti2-staging.tourconnect.com/api-docs/); these methods can be extender using the same format; this allows any plugin to extend the base API endpoints that are linked to any plugin method (part of the base methods or new ones).
157
+
158
+ All the extender methods would be availble under the /\[plugin name] namespace, i.e.: /ti2-greatPlugin/ping.
159
+
160
+ For Ti2 to pickup the extender definition one must create a new file on the root of the plugin named api.yml, such file would contain only the methods to be extender and it must comply with the current swagger version used on ti2.
161
+
162
+ ```yaml
163
+ # api.yml
164
+ openapi: '3.0.0'
165
+ info:
166
+ description: My amazing ti2-plugin
167
+ version: 0.0.1
168
+ title: Ti2's new plugin
169
+ components:
170
+ securitySchemes:
171
+ bearerAuth:
172
+ type: http
173
+ scheme: bearer
174
+ bearerFormat: JWT
175
+ schemas:
176
+ ServerInfo:
177
+ type: object
178
+ properties:
179
+ name:
180
+ type: string
181
+ description:
182
+ type: string
183
+ version:
184
+ type: string
185
+ uptime:
186
+ type: string
187
+ paths:
188
+ /ping:
189
+ get:
190
+ tags:
191
+ - public
192
+ summary: Should return basic system status
193
+ operationId: ping
194
+ responses:
195
+ '200':
196
+ description: success
197
+ content:
198
+ application/json:
199
+ schema:
200
+ $ref: '#/components/schemas/ServerInfo'
201
+ ```
202
+
203
+ ## Database Migrations (plugin's own database tables)
204
+
205
+ Ti2 uses [Sequelize v6.13](https://sequelize.org/v6) and is the database ORM we ecourage to use, you can add your own tables via migrations that should be placed under a migrations folder on the root of the plugin folder.
206
+
207
+ Migrations should be run after the fact, from the root of ti2 instance like so:
208
+
209
+
210
+ ```
211
+ $ npm explore ti2<pluginName> -- npx sequelize db:migrate"
212
+ ```
213
+
214
+ We strongly encourage all the plugin's table names are predicated with the plugin name (i.e. ti2-pluginName-cacheTable).
215
+
216
+ This should be executed ater the ti2 project migrations have been executed.
217
+
218
+ ## Scheduled Task (to be released on v2)
219
+
220
+ TBD.
@@ -0,0 +1,77 @@
1
+ ## Initializing your new Repo
2
+
3
+ We suggest creating a folder with your instance name+i2 (i.e acme-ti2); then initialize an node's npm package and install ti2 along with any plugins to be used.
4
+
5
+ ```bash
6
+ $ mkdir acme-ti2
7
+ $ cd acmme-ti2
8
+ $ npm init .
9
+ $ npm i ti2 ti2-tourconnect
10
+ ```
11
+
12
+ ## Requirements
13
+
14
+ A MySQl instance is required and the following environment variables are required:
15
+
16
+ - DB_URL (mysql connection in url format)
17
+ - dbCryptoKey (integration details encription key, should be a 32 chars base64 encoded random string)
18
+ - adminKey (a key for admin related requests)
19
+ - jwtKey (a key to encrypt user sessions request)
20
+ - frontendKey (an additional optional key to validate the origin of the requests)
21
+ - PORT (an optional port to run the http server, in case a port is not specified as a parameter)
22
+
23
+ ```
24
+ DB_URL=mysql://root:@mysqlserver/ti2development
25
+ dbCryptoKey=cG9VYmJyQ2tlSDVHeXQ4RUN4VlNieEJRejNYWDlZU0g=
26
+ jwtSecret=C8k0mrHVfWVTP7pIoZEHRrvFgTULhw3E4swDq1aoDH4P
27
+ frontendKey=IpOiLahrGQxsQimwoK7Z
28
+ adminKey=bCviyz7iKyuEBoOVlODn
29
+ ```
30
+
31
+ After installing the ti2 package you need to run the datbase migrations for ti2:
32
+
33
+ ```
34
+ $ npm explore ti2<pluginName> -- npx sequelize db:migrate"
35
+ ```
36
+
37
+ ## Entry File
38
+
39
+ then just create an entry file like this :
40
+
41
+ ```javascript
42
+ // index.js
43
+ const ti2 = require('ti2')({
44
+ plugins: {
45
+ travelgate: require('ti2-travelgate'),
46
+ ventrata: require('ti2-ventrata'),
47
+ tourconnect: require('ti2-tourconnect'),
48
+ },
49
+ });
50
+ ```
51
+
52
+ and stat the server using node:
53
+
54
+ ```
55
+ $ node index.js
56
+ ```
57
+
58
+ ## API logging
59
+
60
+ Currently logging is supported via elastic search, an elasticLogClient value can ben passed down, example:
61
+
62
+ ```javascript
63
+ const { Client } = require('@elastic/elasticsearch');
64
+ const elasticLogsClient = (() => {
65
+ if (!elasticLogs) return null;
66
+ return new Client({ node: elasticLogs });
67
+ })();
68
+
69
+ const ti2 = require('ti2')({
70
+ elasticLogsClient,
71
+ plugins: {
72
+ ventrata: require('ti2-ventrata'),
73
+ travelgate: require('ti2-travelgate'),
74
+ tourconnect: require('ti2-tourconnect'),
75
+ },
76
+ });
77
+ ```