ti2 1.0.46 → 1.0.48

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.
@@ -15,8 +15,22 @@ const typeDefs = `
15
15
  title: String
16
16
  description: String
17
17
  }
18
+ type PickupPoint {
19
+ id: ID
20
+ name: String
21
+ pickupAvail: Boolean
22
+ directions: String
23
+ latitude: Float
24
+ longitude: Float
25
+ street: String
26
+ postal: String
27
+ city: String
28
+ state: String
29
+ country: String
30
+ localDateTime: String
31
+ }
18
32
  type Query {
19
- key(productId: String, optionId: String, currency: String, unitsWithQuantity: [UnitWithQuantity], jwtKey: String): String
33
+ key(productId: ID, optionId: ID, currency: String, unitsWithQuantity: [UnitWithQuantity], jwtKey: String): String
20
34
  dateTimeStart: String
21
35
  dateTimeEnd: String
22
36
  allDay: Boolean
@@ -25,16 +39,35 @@ const typeDefs = `
25
39
  pricing: Pricing
26
40
  unitPricing: [Pricing]
27
41
  offer: Offer
42
+ pickupAvailable: Boolean
43
+ pickupRequired: Boolean
44
+ pickupPoints: [PickupPoint]
28
45
  }
29
46
  `;
30
47
 
31
- const query = `query getAvailability ($pId: String, $oId: String, $currency: String, $unitsWithQuantity: [UnitWithQuantity], $jwtKey: String) {
32
- key (productId: $pId, optionId: $oId, currency: $currency, unitsWithQuantity: $unitsWithQuantity, jwtKey: $jwtKey)
48
+ const query = `query getAvailability ($productId: ID, $optionId: ID, $currency: String, $unitsWithQuantity: [UnitWithQuantity], $jwtKey: String) {
49
+ key (productId: $productId, optionId: $optionId, currency: $currency, unitsWithQuantity: $unitsWithQuantity, jwtKey: $jwtKey)
33
50
  dateTimeStart
34
51
  dateTimeEnd
35
52
  allDay
36
53
  vacancies
37
54
  available
55
+ pickupAvailable
56
+ pickupRequired
57
+ pickupPoints {
58
+ id
59
+ name
60
+ pickupAvail
61
+ directions
62
+ latitude
63
+ longitude
64
+ street
65
+ postal
66
+ city
67
+ state
68
+ country
69
+ localDateTime
70
+ }
38
71
  pricing {
39
72
  ...pricingFields
40
73
  }
@@ -26,6 +26,19 @@ const typeDefs = `
26
26
  id: Int
27
27
  name: String
28
28
  }
29
+ type PickupPoint {
30
+ id: ID
31
+ name: String
32
+ directions: String
33
+ latitude: Float
34
+ longitude: Float
35
+ street: String
36
+ postal: String
37
+ city: String
38
+ state: String
39
+ country: String
40
+ localDateTime: String
41
+ }
29
42
  type Query {
30
43
  id: ID
31
44
  orderId: ID
@@ -52,6 +65,11 @@ const typeDefs = `
52
65
  privateUrl: String
53
66
  agent: Agent
54
67
  desk: Desk
68
+ pickupRequested: Boolean
69
+ pickupPointId: ID
70
+ pickupHotel: String
71
+ pickupHotelRoom: String
72
+ pickupPoint: PickupPoint
55
73
  }
56
74
  `;
57
75
 
@@ -104,6 +122,23 @@ const query = `{
104
122
  id
105
123
  name
106
124
  }
125
+ pickupRequested
126
+ pickupPointId
127
+ pickupHotel
128
+ pickupHotelRoom
129
+ pickupPoint {
130
+ id
131
+ name
132
+ directions
133
+ latitude
134
+ longitude
135
+ street
136
+ postal
137
+ city
138
+ state
139
+ country
140
+ localDateTime
141
+ }
107
142
  }`;
108
143
 
109
144
  module.exports = {
@@ -13,7 +13,7 @@ const typeDefs = `
13
13
  type Unit {
14
14
  unitId: ID
15
15
  unitName: String
16
- subtitle: String!
16
+ subtitle: String
17
17
  restrictions: Restriction
18
18
  type: String
19
19
  pricing: [Pricing]
@@ -23,7 +23,11 @@ const getAllFuncs = toCheck => {
23
23
  } while (obj = Object.getPrototypeOf(obj));
24
24
 
25
25
  return props.sort().filter((e, i, arr) => {
26
- if (e !== arr[i + 1] && typeof toCheck[e] === 'function') return true;
26
+ try {
27
+ if (e !== arr[i + 1] && typeof toCheck[e] === 'function') return true;
28
+ } catch {
29
+ return undefined;
30
+ }
27
31
  return undefined;
28
32
  });
29
33
  };
@@ -42,6 +46,7 @@ const getAppMethods = plugins => async (req, res, next) => {
42
46
  };
43
47
 
44
48
  module.exports = plugins => ({
45
- userAppList,
49
+ getAllFuncs,
46
50
  getAppMethods: getAppMethods(plugins),
51
+ userAppList,
47
52
  });
package/index.js CHANGED
@@ -8,6 +8,7 @@ const { pickBy } = require('ramda');
8
8
  const bb = require('bluebird');
9
9
  const { Op } = require('sequelize');
10
10
  const R = require('ramda');
11
+ const { v4: uuidv4 } = require('uuid');
11
12
 
12
13
  const schema = yaml.load(fs.readFileSync(`${__dirname}/api.yml`));
13
14
 
@@ -29,8 +30,6 @@ const isNumber = value => !Number.isNaN(Number(value));
29
30
 
30
31
  module.exports = async ({
31
32
  apiDocs = true,
32
- elasticLogIndex = 'apilog_ti2',
33
- elasticLogsClient,
34
33
  plugins: pluginsParam = {},
35
34
  port: portParam,
36
35
  startServer = true,
@@ -129,77 +128,15 @@ module.exports = async ({
129
128
  notFound: (req, res) => res.sendStatus(404),
130
129
  notImplemented: (req, res) => res.sendStatus(501),
131
130
  });
132
- if (elasticLogsClient) { // API request logs are saved on elastic
133
- const mappings = {
134
- dynamic: true,
135
- properties: {
136
- body: { type: 'object' },
137
- client: { type: 'keyword' },
138
- date: { type: 'long' },
139
- method: { type: 'keyword' },
140
- operationId: { type: 'keyword' },
141
- params: { type: 'object' },
142
- query: { type: 'object' },
143
- url: { type: 'text' },
144
- responseStatusCode: { type: 'long' },
145
- responseTimeInMs: { type: 'long' },
146
- },
147
- };
148
- // setup the index
149
- elasticLogsClient.indices.existsTemplate({
150
- name: 'apilog',
151
- }).then(async ({ body }) => {
152
- if (!body) {
153
- // the template has to be created
154
- console.log('=- creating index template -=');
155
- await elasticLogsClient.indices.putTemplate({
156
- name: 'apilog',
157
- body: {
158
- index_patterns: [`${elasticLogIndex}*`],
159
- settings: {
160
- number_of_shards: 1,
161
- },
162
- mappings,
163
- },
164
- });
165
- console.log('index template created');
166
- } else {
167
- // index exists, we might have to updated it
168
- const current = R.path(
169
- ['body', 'apilog', 'mappings'],
170
- await elasticLogsClient.indices.getTemplate({
171
- name: 'apilog',
172
- }),
173
- );
174
- if (!R.equals(current, mappings)) {
175
- console.log('=- updating index template -=');
176
- await elasticLogsClient.indices.putTemplate({
177
- name: 'apilog',
178
- body: {
179
- index_patterns: [`${elasticLogIndex}*`],
180
- settings: {
181
- number_of_shards: 1,
182
- },
183
- mappings,
184
- },
185
- });
186
- console.log('updated');
187
- }
188
- }
189
- const exists = await elasticLogsClient.indices.exists({
190
- index: elasticLogIndex,
191
- });
192
- if (!exists || !exists.body) {
193
- console.log('=- creating index =-');
194
- await elasticLogsClient.indices.create({
195
- index: elasticLogIndex,
196
- });
197
- console.log('index created');
198
- }
199
- }).catch(console.log);
131
+ const onRequestStartPlugins = plugins.filter(currentPlugin => (api.getAllFuncs(currentPlugin).indexOf('onRequestStart') > -1));
132
+ const onRequestEndPlugins = plugins.filter(currentPlugin => (api.getAllFuncs(currentPlugin).indexOf('onRequestEnd') > -1));
133
+
134
+ if (onRequestStartPlugins.length > 0) {
200
135
  app.use((req, res, next) => {
201
136
  const startHrTime = process.hrtime();
137
+ const requestId = uuidv4();
202
138
  const body = {
139
+ requestId,
203
140
  date: Math.floor(Date.now() / 1e3),
204
141
  url: req.url,
205
142
  // body: req.body,
@@ -210,29 +147,37 @@ module.exports = async ({
210
147
  operationId: R.path(['openapi', 'operation', 'operationId'], req),
211
148
  client: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
212
149
  };
213
- elasticLogsClient.index({
214
- index: elasticLogIndex,
215
- body,
216
- }).then(({ body: { _id } }) => {
150
+ bb.each(onRequestStartPlugins, async startPlugin => {
151
+ try {
152
+ await startPlugin.onRequestStart(body);
153
+ } catch (err) {
154
+ console.log(`unable to log to ${startPlugin.name}`, err);
155
+ }
156
+ }).then();
157
+ if (onRequestEndPlugins.length > 0) {
217
158
  res.on('finish', () => {
218
159
  const elapsedHrTime = process.hrtime(startHrTime);
219
- const responseTimeInMs = parseInt(elapsedHrTime[0] * 1e3 + elapsedHrTime[1] / 1e6, 10);
220
- elasticLogsClient.index({
221
- index: elasticLogIndex,
222
- id: _id,
223
- body: {
224
- ...body,
225
- ...{
160
+ const responseTimeInMs = parseInt(
161
+ elapsedHrTime[0] * 1e3 + elapsedHrTime[1] / 1e6,
162
+ 10,
163
+ );
164
+ bb.each(onRequestEndPlugins, async endPlugin => {
165
+ try {
166
+ await endPlugin.onRequestEnd({
167
+ ...body,
226
168
  responseTimeInMs,
227
169
  responseStatusCode: res.statusCode,
228
- },
229
- },
230
- }).catch((err, response) => console.log(err, response));
170
+ });
171
+ } catch (err) {
172
+ console.log(`unable to log to ${endPlugin.name}`, err);
173
+ }
174
+ }).then();
231
175
  });
232
- }).catch((err, response) => console.log(err, response));
176
+ }
233
177
  next();
234
178
  });
235
179
  }
180
+
236
181
  connect(app);
237
182
  app.use(middleware.mock());
238
183
  // global error Handling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -44,7 +44,7 @@
44
44
  "swagger-ui-express": "4.3.0",
45
45
  "throng": "^5.0.0",
46
46
  "umzug": "^3.1.1",
47
- "uninstall": "^0.0.0"
47
+ "uuid": "^9.0.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@salvador/minami": "^1.2.3",