ti2 1.0.37 → 1.0.39

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/api.yml CHANGED
@@ -132,6 +132,20 @@ components:
132
132
  type: string
133
133
  updatedAt:
134
134
  type: string
135
+ UserList:
136
+ type: object
137
+ properties:
138
+ users:
139
+ type: array
140
+ items:
141
+ type: object
142
+ properties:
143
+ userId:
144
+ type: string
145
+ createdAt:
146
+ type: string
147
+ updatedAt:
148
+ type: string
135
149
  AppTokenList:
136
150
  type: object
137
151
  properties:
@@ -419,6 +433,21 @@ paths:
419
433
  application/json:
420
434
  schema:
421
435
  $ref: '#/components/schemas/IntegrationList'
436
+ /users:
437
+ get:
438
+ security:
439
+ - bearerAuth: ['admin']
440
+ tags:
441
+ - admin
442
+ summary: list all created users
443
+ operationId: listUsers
444
+ responses:
445
+ 200:
446
+ description: success
447
+ content:
448
+ application/json:
449
+ schema:
450
+ $ref: '#/components/schemas/UserList'
422
451
  /app/resetAppKey/{appKey}:
423
452
  get:
424
453
  security:
@@ -59,4 +59,11 @@ describe('admin', () => {
59
59
  });
60
60
  expect(value).toBeTruthy();
61
61
  });
62
+ it('the created user should be on the user list', async () => {
63
+ const { users } = await doApiGet({
64
+ url: '/users',
65
+ token: adminKey,
66
+ });
67
+ expect(users.find(currentUser => currentUser.userId === userId)).toBeTruthy();
68
+ });
62
69
  });
@@ -60,6 +60,15 @@ const listApps = async (req, res, next) => {
60
60
  }
61
61
  };
62
62
 
63
+ const listUsers = async (req, res, next) => {
64
+ try {
65
+ const users = await sqldb.User.findAll();
66
+ return res.json({ users });
67
+ } catch (err) {
68
+ return next(err);
69
+ }
70
+ };
71
+
63
72
  const createUserToken = async (req, res, next) => {
64
73
  const {
65
74
  body: {
@@ -140,6 +149,7 @@ module.exports = {
140
149
  createUserToken,
141
150
  deleteApp,
142
151
  listApps,
152
+ listUsers,
143
153
  migrate,
144
154
  resetIntegrationToken,
145
155
  };
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.39",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {