@manyos/smileconnect-api 1.63.4 → 1.64.1

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 (44) hide show
  1. package/app.js +11 -3
  2. package/conf/clients.json +8 -33
  3. package/controller/cmdbobjectController.js +2 -2
  4. package/controller/customFormController.js +1 -1
  5. package/controller/eventLogController.js +6 -8
  6. package/controller/orgdataController.js +1 -1
  7. package/controller/relatedObjectsController.js +3 -1
  8. package/controller/scriptController.js +2 -2
  9. package/controller/taskController.js +2 -2
  10. package/controller/templateController.js +1 -1
  11. package/controller/ticketCIRelationController.js +31 -22
  12. package/controller/ticketController.js +26 -22
  13. package/controller/ticketWorkLogController.js +1 -1
  14. package/docs/releases.md +7 -0
  15. package/package.json +1 -1
  16. package/routes/appConfigRoutes.js +13 -7
  17. package/routes/ciRelationRoutes.js +1 -1
  18. package/routes/cmdbObjectRoutes.js +1 -1
  19. package/routes/customFormRoutes.js +1 -1
  20. package/routes/organisationRoutes.js +1 -1
  21. package/routes/peopleRelationRoutes.js +1 -1
  22. package/routes/personRoutes.js +1 -1
  23. package/routes/scriptRoutes.js +1 -1
  24. package/routes/supportgroupRoutes.js +1 -1
  25. package/routes/taskRoutes.js +1 -1
  26. package/routes/templateRoutes.js +1 -1
  27. package/routes/ticketRoutes.js +16 -6
  28. package/routes/ticketWorkLogRoutes.js +1 -1
  29. package/test/changeTest.js +2 -2
  30. package/test/incidentTest.js +2 -2
  31. package/test/problemTest.js +2 -2
  32. package/test/workorderTest.js +2 -2
  33. package/util/arquery.js +16 -5
  34. package/util/auth.js +1 -1
  35. package/util/cache.service.js +1 -1
  36. package/util/config.js +1 -1
  37. package/util/eventLog.js +16 -0
  38. package/util/mappingUtil.js +11 -7
  39. package/util/paramHelper.js +1 -1
  40. package/util/relationUtil.js +1 -1
  41. package/util/responsehandler.js +11 -3
  42. package/util/searchUtil.js +1 -1
  43. package/util/ticketValidationUtil.js +1 -1
  44. package/screwdriver.yaml +0 -52
package/docs/releases.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Release Notes
2
2
 
3
3
  ## API
4
+ ### 1.64.0 - 19.07.23
5
+ Introduce Enhanced Logging for Tickets. More objects in later releases.
6
+
4
7
  ### 1.63.0 - 10.01.23
5
8
  Security fix for jsonwebtoken https://github.com/advisories/GHSA-27h2-hvpr-p74q
9
+ Please use RAPI 23.05.09 or later since this release.
6
10
 
7
11
  ### 1.62.0 - 18.11.22
8
12
  Add Deepl Translation Adapter
@@ -185,6 +189,9 @@ e.g.
185
189
  */v1/incidents?impersonateUser=abc123
186
190
 
187
191
  ## Event Manager
192
+ ### 1.31.0 - 18.07.23
193
+ Introduce advanced logging for events. Each event log record will contain details about the associated event. (e.g. Event Id, Ticketnumber, etc.)
194
+
188
195
  ### 1.29.1 - 10.01.23
189
196
  Security fix for jsonwebtoken https://github.com/advisories/GHSA-27h2-hvpr-p74q
190
197
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.63.4",
3
+ "version": "1.64.1",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const {body, validationResult, oneOf, checkSchema} = require('express-validator/check');
4
4
  const {setEventData} = require('../controller/eventLogController');
5
5
  const CONSTANTS = require('../util/constants');
@@ -142,13 +142,14 @@ module.exports = (function() {
142
142
  checkSchema(fieldMappingSchemas.customFormMappingItemSchema),
143
143
  async function (req, res, next) {
144
144
  const id = req.params.id;
145
+ const origData = JSON.parse(JSON.stringify(req.body));
145
146
  setEventData(
146
147
  req,
147
148
  CONSTANTS.EVENT_BASE_APC,
148
149
  CONSTANTS.EVENT_ACTION_MODIFY,
149
150
  CONSTANTS.FORM_APC_MAPPING_CUSTOMFORM,
150
151
  id,
151
- req.body
152
+ origData
152
153
  );
153
154
  const errors = validationResult(req);
154
155
  if (!errors.isEmpty()) {
@@ -169,13 +170,14 @@ module.exports = (function() {
169
170
 
170
171
  routes.put('/mappings/customForms', isAuthorizedAdmin,
171
172
  async function (req, res, next) {
173
+ const origData = JSON.parse(JSON.stringify(req.body));
172
174
  setEventData(
173
175
  req,
174
176
  CONSTANTS.EVENT_BASE_APC,
175
177
  CONSTANTS.EVENT_ACTION_MODIFY,
176
178
  CONSTANTS.FORM_APC_MAPPING_CUSTOMFORM,
177
179
  undefined,
178
- req.body
180
+ origData
179
181
  );
180
182
  try {
181
183
  const data = await config.setCustomFormMapping(req.body.data)
@@ -192,13 +194,14 @@ module.exports = (function() {
192
194
  checkSchema(fieldMappingSchemas.fieldMappingItemSchema),
193
195
  function (req, res, next) {
194
196
  const id = req.params.id;
197
+ const origData = JSON.parse(JSON.stringify(req.body));
195
198
  setEventData(
196
199
  req,
197
200
  CONSTANTS.EVENT_BASE_APC,
198
201
  CONSTANTS.EVENT_ACTION_MODIFY,
199
202
  CONSTANTS.FORM_APC_MAPPING_FIELDS,
200
203
  id,
201
- req.body
204
+ origData
202
205
  );
203
206
  log.debug('do');
204
207
  const errors = validationResult(req);
@@ -234,13 +237,14 @@ module.exports = (function() {
234
237
  checkSchema(fieldMappingSchemas.fieldMappingSchema),
235
238
  function (req, res, next) {
236
239
  const id = req.params.id;
240
+ const origData = JSON.parse(JSON.stringify(req.body));
237
241
  setEventData(
238
242
  req,
239
243
  CONSTANTS.EVENT_BASE_APC,
240
244
  CONSTANTS.EVENT_ACTION_MODIFY,
241
245
  CONSTANTS.FORM_APC_MAPPING_FIELDS,
242
246
  null,
243
- req.body
247
+ origData
244
248
  );
245
249
  log.debug('do');
246
250
  const errors = validationResult(req);
@@ -314,13 +318,14 @@ module.exports = (function() {
314
318
  routes.post('/clients', isAuthorizedAdmin,
315
319
  checkSchema(clientConfigSchema),
316
320
  function (req, res, next) {
321
+ const origData = JSON.parse(JSON.stringify(req.body));
317
322
  setEventData(
318
323
  req,
319
324
  CONSTANTS.EVENT_BASE_APC,
320
325
  CONSTANTS.EVENT_ACTION_CREATE,
321
326
  CONSTANTS.FORM_APC_CLIENTS,
322
327
  null,
323
- req.body
328
+ origData
324
329
  );
325
330
  const errors = validationResult(req);
326
331
  if (!errors.isEmpty()) {
@@ -348,13 +353,14 @@ module.exports = (function() {
348
353
  checkSchema(clientConfigSchema),
349
354
  function (req, res, next) {
350
355
  const id = req.params.id;
356
+ const origData = JSON.parse(JSON.stringify(req.body));
351
357
  setEventData(
352
358
  req,
353
359
  CONSTANTS.EVENT_BASE_APC,
354
360
  CONSTANTS.EVENT_ACTION_MODIFY,
355
361
  CONSTANTS.FORM_APC_CLIENTS,
356
362
  id,
357
- req.body
363
+ origData
358
364
  );
359
365
  const errors = validationResult(req);
360
366
  if (!errors.isEmpty()) {
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog(path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const passport = require('passport');
4
4
  const {body, validationResult, oneOf} = require('express-validator/check');
5
5
  const cmdbobjects = require('../controller/cmdbobjectController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const passport = require('passport');
4
4
  const {body, validationResult, checkSchema} = require('express-validator/check');
5
5
  const cmdbobjects = require('../controller/cmdbobjectController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const {body, validationResult, oneOf} = require('express-validator/check');
4
4
  const customFormController = require('../controller/customFormController');
5
5
  const eventLog = require('../controller/eventLogController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const passport = require('passport');
4
4
  const {body, validationResult, oneOf} = require('express-validator/check');
5
5
  const orgdata = require('../controller/orgdataController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const passport = require('passport');
4
4
  const {body, validationResult, oneOf} = require('express-validator/check');
5
5
  const cmdbobjects = require('../controller/cmdbobjectController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const passport = require('passport');
4
4
  const {body, validationResult, oneOf} = require('express-validator/check');
5
5
  const orgdata = require('../controller/orgdataController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const scriptController = require('../controller/scriptController');
4
4
  const eventLog = require('../controller/eventLogController');
5
5
  const CONSTANTS = require('../util/constants');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const passport = require('passport');
4
4
  const {body, validationResult, oneOf} = require('express-validator/check');
5
5
  const orgdata = require('../controller/orgdataController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const {body, validationResult, oneOf} = require('express-validator/check');
4
4
  const task = require('../controller/taskController');
5
5
  const eventLog = require('../controller/eventLogController');
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const templateController = require('../controller/templateController');
4
4
  const eventLog = require('../controller/eventLogController');
5
5
  const CONSTANTS = require('../util/constants');
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ let log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
+ const {getEventLog} = require('../util/eventLog');
3
4
  const {body, validationResult, oneOf} = require('express-validator/check');
4
5
  const ticketController = require('../controller/ticketController');
5
6
  const templateController = require('../controller/templateController');
@@ -15,7 +16,13 @@ module.exports = (function() {
15
16
  return `${location}[${param}]: ${msg}`;
16
17
  };
17
18
 
19
+ ticketRoutes.use(function (req, res, next) {
20
+ log = getEventLog(req.log, path.basename(__filename))
21
+ next();
22
+ });
23
+
18
24
  ticketRoutes.get('/', function (req, res, next) {
25
+ log = getEventLog(req.log, path.basename(__filename));
19
26
  eventLog.setEventData(
20
27
  req,
21
28
  req.parentEventBase,
@@ -46,6 +53,7 @@ module.exports = (function() {
46
53
  });
47
54
 
48
55
  ticketRoutes.post('/', function (req, res, next) {
56
+ log = getEventLog(req.log, path.basename(__filename));
49
57
  //todo Errorhandling prüfen. Wenn parameter fehlen, wird nicht zurückgegeben welche
50
58
  const origData = JSON.parse(JSON.stringify(req.body));
51
59
  const includeString = req.query.include;
@@ -63,7 +71,7 @@ module.exports = (function() {
63
71
  next(errors.array());
64
72
  } else {
65
73
  //const relations = req.body.data.relations;
66
- ticketController.createTicket(req.ticketConfig, req.user.config, req.body.data, req.globalScriptParams).then(async function (result) {
74
+ ticketController.createTicket(req.ticketConfig, req.user.config, req.body.data, req.globalScriptParams, req.log).then(async function (result) {
67
75
  const createResult = result.createResult;
68
76
  const relationErrors = result.relationErrors;
69
77
  if (relationErrors && Array.isArray(relationErrors) && relationErrors.length > 0) {
@@ -88,7 +96,7 @@ module.exports = (function() {
88
96
  ticketRoutes.post('/search', [
89
97
  body('searchString').isLength({ min: 1})
90
98
  ], function (req, res, next) {
91
-
99
+ log = getEventLog(req.log, path.basename(__filename));
92
100
  const origData = JSON.parse(JSON.stringify(req.body));
93
101
  const includeString = req.query.include;
94
102
  eventLog.setEventData(
@@ -119,7 +127,7 @@ module.exports = (function() {
119
127
  if (!valResult.isEmpty()) {
120
128
  next(valResult.array());
121
129
  } else {
122
- ticketController.searchTicket(req.ticketConfig, req.user.config, req.body.searchString, req.body.fields, options, includeString, req.globalScriptParams).then(function (result) {
130
+ ticketController.searchTicket(req.ticketConfig, req.user.config, req.body.searchString, req.body.fields, options, includeString, req.globalScriptParams, req.log).then(function (result) {
123
131
  log.debug('result', result);
124
132
  req.includeObjectsList = result.included;
125
133
  req.result = {data:result.data};
@@ -146,8 +154,9 @@ module.exports = (function() {
146
154
  });
147
155
 
148
156
  function getTicket(req, res, next, clientConfig, id, mapping, includeString, additionalData) {
157
+ log = getEventLog(req.log, path.basename(__filename));
149
158
  req.globalScriptParams.id = id
150
- ticketController.getTicket(req.ticketConfig, clientConfig, id, mapping, includeString, req.globalScriptParams).then(function (result) {
159
+ ticketController.getTicket(req.ticketConfig, clientConfig, id, mapping, includeString, req.globalScriptParams, log).then(function (result) {
151
160
  log.debug('result', result);
152
161
  req.includeObjectsList = result.included;
153
162
  req.result = {data:result.data || {}};
@@ -164,6 +173,7 @@ module.exports = (function() {
164
173
  }
165
174
 
166
175
  ticketRoutes.put('/:id', function (req, res, next) {
176
+ log = getEventLog(req.log, path.basename(__filename));
167
177
  const id = req.params.id;
168
178
  req.globalScriptParams.id = id
169
179
  const origData = JSON.parse(JSON.stringify(req.body));
@@ -182,7 +192,7 @@ module.exports = (function() {
182
192
  next(errors.array());
183
193
  } else {
184
194
  const relations = req.body.data.relations;
185
- ticketController.updateTicket(req.ticketConfig, req.user.config, id, req.body.data, req.globalScriptParams)
195
+ ticketController.updateTicket(req.ticketConfig, req.user.config, id, req.body.data, req.globalScriptParams, log)
186
196
  .then(async function (result) {
187
197
  const relationErrors = result.relationErrors;
188
198
  if (relationErrors && Array.isArray(relationErrors) && relationErrors.length > 0) {
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const {body, validationResult, oneOf} = require('express-validator/check');
4
4
  const ticketWorkLogController = require('../controller/ticketWorkLogController');
5
5
  const ticketValidationUtil = require('../util/ticketValidationUtil');
@@ -209,7 +209,7 @@ describe('Integration Tests - Change', function () {
209
209
  }
210
210
  })
211
211
  .end(function(err, res) {
212
- res.should.have.status(500);
212
+ res.should.have.status(422);
213
213
  done();
214
214
  })
215
215
  })
@@ -232,7 +232,7 @@ describe('Integration Tests - Change', function () {
232
232
  }
233
233
  })
234
234
  .end(function(err, res) {
235
- res.should.have.status(500);
235
+ res.should.have.status(422);
236
236
  done();
237
237
  })
238
238
  })
@@ -158,7 +158,7 @@ describe('Integration Tests - Incidents', function () {
158
158
  }
159
159
  })
160
160
  .end(function(err, res) {
161
- res.should.have.status(500);
161
+ res.should.have.status(422);
162
162
  done();
163
163
  })
164
164
  })
@@ -181,7 +181,7 @@ describe('Integration Tests - Incidents', function () {
181
181
  }
182
182
  })
183
183
  .end(function(err, res) {
184
- res.should.have.status(500);
184
+ res.should.have.status(422);
185
185
  done();
186
186
  })
187
187
  })
@@ -181,7 +181,7 @@ describe('Integration Tests - Problems', function () {
181
181
  }
182
182
  })
183
183
  .end(function(err, res) {
184
- res.should.have.status(500);
184
+ res.should.have.status(422);
185
185
  done();
186
186
  })
187
187
  })
@@ -204,7 +204,7 @@ describe('Integration Tests - Problems', function () {
204
204
  }
205
205
  })
206
206
  .end(function(err, res) {
207
- res.should.have.status(500);
207
+ res.should.have.status(422);
208
208
  done();
209
209
  })
210
210
  })
@@ -199,7 +199,7 @@ describe('Integration Tests - Workorders', function () {
199
199
  }
200
200
  })
201
201
  .end(function(err, res) {
202
- res.should.have.status(500);
202
+ res.should.have.status(422);
203
203
  done();
204
204
  })
205
205
  })
@@ -222,7 +222,7 @@ describe('Integration Tests - Workorders', function () {
222
222
  }
223
223
  })
224
224
  .end(function(err, res) {
225
- res.should.have.status(500);
225
+ res.should.have.status(422);
226
226
  done();
227
227
  })
228
228
  })
package/util/arquery.js CHANGED
@@ -1,7 +1,8 @@
1
1
  require('dotenv').config();
2
2
  const request = require('request-promise-native');
3
3
  const path = require('path');
4
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
4
+ const {getEventLog} = require("./eventLog");
5
+ let log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
5
6
 
6
7
  async function deleteEntries(form, baseQuery, query) {
7
8
  let fullQuery = query;
@@ -36,7 +37,9 @@ async function deleteEntries(form, baseQuery, query) {
36
37
  return value;
37
38
  }
38
39
 
39
- async function executeARQuery(form, baseQuery, query, fields, options) {
40
+ async function executeARQuery(form, baseQuery, query, fields, options, eventLog) {
41
+ log = getEventLog(eventLog, path.basename(__filename));
42
+ log = log.child({form});
40
43
  let fullQuery = query;
41
44
  if (baseQuery)
42
45
  fullQuery = "(" + baseQuery + ") AND " + query;
@@ -178,7 +181,9 @@ function prepareSortString(sortOptions) {
178
181
  }
179
182
 
180
183
  //todo add impersonate
181
- function createEntry(form, entryData, clientOptions) {
184
+ function createEntry(form, entryData, clientOptions, eventLog) {
185
+ log = getEventLog(eventLog, path.basename(__filename));
186
+ log = log.child({form});
182
187
  let port = 0;
183
188
  if (process.env.AR_PORT && process.env.AR_PORT != undefined)
184
189
  port = process.env.AR_PORT;
@@ -362,7 +367,9 @@ function applyMapping(entryData, mapping, constants) {
362
367
  return entryData;
363
368
  }
364
369
 
365
- function updateEntry(form, id, entryData, clientOptions) {
370
+ function updateEntry(form, id, entryData, clientOptions, eventLog) {
371
+ log = getEventLog(eventLog, path.basename(__filename));
372
+ log = log.child({form});
366
373
  let port = 0;
367
374
  if (process.env.AR_PORT && process.env.AR_PORT != undefined)
368
375
  port = process.env.AR_PORT;
@@ -405,7 +412,11 @@ function updateEntry(form, id, entryData, clientOptions) {
405
412
  }
406
413
  }
407
414
  //TODO check for status and reject if Error
408
- resolve(response);
415
+ if (response && response.startsWith('[message:error')) {
416
+ reject ('Could not update entry: ' + response);
417
+ } else {
418
+ resolve(response);
419
+ }
409
420
  })
410
421
  .catch(function (error) {
411
422
  log.error(error);
package/util/auth.js CHANGED
@@ -1,6 +1,6 @@
1
1
  require('dotenv').config();
2
2
  const path = require('path');
3
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
4
4
 
5
5
  function isAuthorizedAdmin(req, res, next) {
6
6
  log.debug(req.user);
@@ -1,6 +1,6 @@
1
1
  const NodeCache = require ('node-cache/index');
2
2
  const path = require('path');
3
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
4
4
 
5
5
  class Cache {
6
6
 
package/util/config.js CHANGED
@@ -2,7 +2,7 @@ const fs = require('fs');
2
2
  const fsPromises = require('fs').promises;
3
3
 
4
4
  const path = require('path');
5
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
5
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
6
6
 
7
7
  const clientConfigFile = 'conf/clients.json';
8
8
  const arquery = require('../util/arquery');
@@ -0,0 +1,16 @@
1
+ const path = require("path");
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
+
4
+ function getEventLog(eventLog, file, options) {
5
+ if (!eventLog) {
6
+ eventLog = log;
7
+ }
8
+ eventLog = eventLog.child({
9
+ file
10
+ });
11
+ return eventLog;
12
+ }
13
+
14
+ module.exports = {
15
+ getEventLog
16
+ };
@@ -1,12 +1,13 @@
1
1
  const path = require('path');
2
2
  const {getFields} = require("./config");
3
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
4
-
5
- function applyMapping2Remedy(entryData, mapping, constants, fields) {
3
+ const {getEventLog} = require("./eventLog");
4
+ let log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
6
5
 
6
+ function applyMapping2Remedy(entryData, mapping, constants, fields, eventLog) {
7
+ log = getEventLog(eventLog, path.basename(__filename));
7
8
  //todo add array handling
8
9
  if (!Array.isArray(entryData)) {
9
- return applyMappingInternal(entryData, mapping, constants, fields);
10
+ return applyMappingInternal(entryData, mapping, constants, fields, log);
10
11
  } else {
11
12
  const entries = [];
12
13
  entryData.forEach(entry => {
@@ -17,7 +18,8 @@ function applyMapping2Remedy(entryData, mapping, constants, fields) {
17
18
  }
18
19
  }
19
20
 
20
- function applyMappingInternal(entryData, mapping, constants, fields) {
21
+ function applyMappingInternal(entryData, mapping, constants, fields, eventLog) {
22
+ log = getEventLog(eventLog, path.basename(__filename));
21
23
  Object.keys(entryData).forEach(function (objectKey) {
22
24
  const found = mapping.find(function(element) {
23
25
  return element.newName === objectKey;
@@ -105,7 +107,8 @@ function getFieldsForCreate(mapping, mappingNew, clientFields) {
105
107
  return remedyField;
106
108
  }*/
107
109
 
108
- function applyCustomFormMapping(object, mapping, requestIdField) {
110
+ function applyCustomFormMapping(object, mapping, requestIdField, eventLog) {
111
+ log = getEventLog(eventLog, path.basename(__filename));
109
112
  //log.debug('apply mapping', object, mapping)
110
113
  //Apply mapping
111
114
  Object.keys(mapping).forEach(remedyName => {
@@ -128,7 +131,8 @@ function applyCustomFormMapping(object, mapping, requestIdField) {
128
131
  }
129
132
  }
130
133
 
131
- function applyCustomFormMapping2Remedy(entryData, mapping, constants, fields) {
134
+ function applyCustomFormMapping2Remedy(entryData, mapping, constants, fields, eventLog) {
135
+ log = getEventLog(eventLog, path.basename(__filename));
132
136
  //delete unmapped entries
133
137
  const mappedFields = Object.values(mapping)
134
138
 
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
 
4
4
  function getIncludeArray(includeString) {
5
5
  log.debug('transform includeString', includeString);
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
 
4
4
  const CONSTANTS = require('../util/constants');
5
5
 
@@ -1,6 +1,7 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ let log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
  const eventLog = require('../controller/eventLogController');
4
+ const {getEventLog} = require("./eventLog");
4
5
 
5
6
  const VERSION = process.env.version;
6
7
 
@@ -21,6 +22,7 @@ function logRequest (req, res, next) {
21
22
  }
22
23
 
23
24
  function logErrors(err, req, res, next) {
25
+ log = getEventLog(req.log, path.basename(__filename));
24
26
  /*log.error({
25
27
  smileId : req.smileId,
26
28
  error : err.stack || String(err)
@@ -39,13 +41,15 @@ function logErrors(err, req, res, next) {
39
41
  JSON.stringify(err, null, 2) || String(err),
40
42
  eventData.jsonData,
41
43
  eventData.ticketNumber2,
42
- eventData.ticketNumber3);
44
+ eventData.ticketNumber3,
45
+ req.log);
43
46
  }
44
47
 
45
48
  next(err);
46
49
  }
47
50
 
48
51
  function errorHandler(err, req, res, next) {
52
+ log = getEventLog(req.log, path.basename(__filename));
49
53
  const errorStack = err.stack;
50
54
  const errorStatus = err.status || req.errorStatus || 500;
51
55
  if (errorStatus == 401) {
@@ -66,6 +70,7 @@ function errorHandler(err, req, res, next) {
66
70
 
67
71
  //createSuccessLog(client, ticketNumber, schemaName, eventName, url, jsonData) {
68
72
  function eventQueueHandler(req, res, next) {
73
+ log = getEventLog(req.log, path.basename(__filename));
69
74
  //add version to header as debug info
70
75
  res.setHeader('x-smileconnect-version', VERSION || '0.0.0');
71
76
  log.debug({req:req}, 'start');
@@ -93,7 +98,10 @@ function eventQueueHandler(req, res, next) {
93
98
  eventData.event,
94
99
  req.method + ':' + req.url,
95
100
  eventData.jsonData,
96
- eventData.ticketNumber2).then( success => {
101
+ eventData.ticketNumber2,
102
+ eventData.ticketNumber3,
103
+ req.log
104
+ ).then( success => {
97
105
  if (req.downloadResult) {
98
106
  res.set('Content-disposition', 'attachment; filename=' + req.downloadResult.fileName);
99
107
  res.status(200).send(req.downloadResult.data);
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
3
3
 
4
4
  function applyMapping(searchString, mapping) {
5
5
  log.debug('Apply mapping on', searchString, mapping);
@@ -1,6 +1,6 @@
1
1
  const path = require('path');
2
2
  const ticketController = require("../controller/ticketController");
3
- const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const log = require('@manyos/logger').setupLog('SMILEconnect', path.basename(__filename));
4
4
 
5
5
 
6
6
  async function checkTicket(ticketConfig, id, globalScriptParams) {