ti2 1.0.37 → 1.0.38

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 (2) hide show
  1. package/index.js +41 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -130,6 +130,21 @@ module.exports = async ({
130
130
  notImplemented: (req, res) => res.sendStatus(501),
131
131
  });
132
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
+ };
133
148
  // setup the index
134
149
  elasticLogsClient.indices.existsTemplate({
135
150
  name: 'apilog',
@@ -144,22 +159,32 @@ module.exports = async ({
144
159
  settings: {
145
160
  number_of_shards: 1,
146
161
  },
147
- mappings: {
148
- dynamic: true,
149
- properties: {
150
- body: { type: 'object' },
151
- client: { type: 'keyword' },
152
- date: { type: 'long' },
153
- method: { type: 'keyword' },
154
- params: { type: 'object' },
155
- query: { type: 'object' },
156
- url: { type: 'text' },
157
- responseStatusCode: { type: 'long' },
158
- responseTimeInMs: { type: 'long' },
159
- },
160
- },
162
+ mappings,
161
163
  },
162
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
+ }
163
188
  }
164
189
  const exists = await elasticLogsClient.indices.exists({
165
190
  index: elasticLogIndex,
@@ -169,6 +194,7 @@ module.exports = async ({
169
194
  await elasticLogsClient.indices.create({
170
195
  index: elasticLogIndex,
171
196
  });
197
+ console.log('index created');
172
198
  }
173
199
  }).catch(console.log);
174
200
  app.use((req, res, next) => {
@@ -181,6 +207,7 @@ module.exports = async ({
181
207
  query: req.query,
182
208
  appRecord: req.appRecord,
183
209
  method: req.method,
210
+ operationId: R.path(['openapi', 'operation', 'operationId'], req),
184
211
  client: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
185
212
  };
186
213
  elasticLogsClient.index({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {