@manyos/smileconnect-api 1.59.2 → 1.59.4

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/app.js CHANGED
@@ -371,6 +371,7 @@ app.use('/v1/:requestType/:parentId/tasks', function(req, res, next) {
371
371
  }, taskRoutes);
372
372
 
373
373
  app.use(relatedObjectsController.getRelatedObjects);
374
+ app.use(relatedObjectsController.addLinks);
374
375
 
375
376
  app.use(responseHandler.eventQueueHandler);
376
377
 
package/conf/clients.json CHANGED
@@ -2289,7 +2289,9 @@
2289
2289
  },
2290
2290
  "PUT": {
2291
2291
  "preMapping": [],
2292
- "postMapping": [],
2292
+ "postMapping": [
2293
+ "notFetchResult"
2294
+ ],
2293
2295
  "afterExecution": []
2294
2296
  },
2295
2297
  "POST": {
@@ -2376,14 +2378,18 @@
2376
2378
  "preMapping": [
2377
2379
  "p2"
2378
2380
  ],
2379
- "postMapping": [],
2381
+ "postMapping": [
2382
+ "notFetchResult"
2383
+ ],
2380
2384
  "afterExecution": [
2381
2385
  "INC_CreateWorklog_OnCreate"
2382
2386
  ]
2383
2387
  },
2384
2388
  "PUT": {
2385
2389
  "preMapping": [],
2386
- "postMapping": [],
2390
+ "postMapping": [
2391
+ "notFetchResult"
2392
+ ],
2387
2393
  "afterExecution": []
2388
2394
  }
2389
2395
  }
@@ -2491,7 +2497,15 @@
2491
2497
  }
2492
2498
  ],
2493
2499
  "basequery": "",
2494
- "scripts": {},
2500
+ "scripts": {
2501
+ "POST": {
2502
+ "preMapping": [],
2503
+ "postMapping": [
2504
+ "notFetchResult"
2505
+ ],
2506
+ "afterExecution": []
2507
+ }
2508
+ },
2495
2509
  "attachmentScripts": {}
2496
2510
  },
2497
2511
  "problemWorklog": {
@@ -2562,7 +2576,22 @@
2562
2576
  "value": "1000"
2563
2577
  }
2564
2578
  ],
2565
- "scripts": {}
2579
+ "scripts": {
2580
+ "POST": {
2581
+ "preMapping": [],
2582
+ "postMapping": [
2583
+ "notFetchResult"
2584
+ ],
2585
+ "afterExecution": []
2586
+ },
2587
+ "PUT": {
2588
+ "preMapping": [],
2589
+ "postMapping": [
2590
+ "notFetchResult"
2591
+ ],
2592
+ "afterExecution": []
2593
+ }
2594
+ }
2566
2595
  },
2567
2596
  "taskWorklog": {
2568
2597
  "fields": [
@@ -155,7 +155,11 @@ async function handleRecord(formConfig, record, mapping, clientConfig, includeAr
155
155
 
156
156
  async function getRecord(formConfig, clientConfig, id, mapping, includeString, globalScriptParams) {
157
157
  const idField = getIdField(formConfig)
158
- const query = `'${idField}'=\"${id}\"`;
158
+ let query = `'${idField}'=\"${id}\"`;
159
+ if (globalScriptParams.recordQuery) {
160
+ query = globalScriptParams.recordQuery;
161
+ log.debug('Set custom record query to', globalScriptParams.recordQuery);
162
+ }
159
163
  const returnValue = await queryRecords(formConfig, clientConfig, query, mapping, null, {limit:1}, includeString, globalScriptParams);
160
164
  const record = returnValue.data[0];
161
165
  return {data: record};
@@ -10,6 +10,7 @@ const config = require('../util/config');
10
10
  async function getRelatedObjects(req, res, next) {
11
11
  log.debug('include Data', req.includeArray);
12
12
  log.debug('include Objects', req.includeObjectsList);
13
+
13
14
  if (req.result && req.includeObjectsList && req.includeArray) {
14
15
  let result = {};
15
16
  const includedObjects = req.includeObjectsList;
@@ -195,6 +196,29 @@ function replaceObjectKeys(item) {
195
196
  }
196
197
  }
197
198
 
199
+ async function addLinks(req, res, next) {
200
+ if (!req.globalScriptParams) {
201
+ req.globalScriptParams = {};
202
+ }
203
+ const id = req.globalScriptParams.id2 || req.globalScriptParams.id;
204
+ const urlStart = req.url.split('?')[0];
205
+ if (req.result && id) {
206
+ let selfUrl = '';
207
+ if (urlStart.endsWith(id)) {
208
+ selfUrl = urlStart;
209
+ } else {
210
+ selfUrl = urlStart + '/' + id;
211
+ }
212
+ req.result.links = {
213
+ self: {
214
+ id: id,
215
+ href: selfUrl
216
+ }
217
+ }
218
+ }
219
+ next();
220
+ }
221
+
198
222
  module.exports = {
199
- getRelatedObjects
223
+ getRelatedObjects, addLinks
200
224
  }
@@ -440,7 +440,7 @@ async function updateRelations(ticketConfig, userConfig, ticketId, relations) {
440
440
  }
441
441
 
442
442
  //Set error array
443
- const errors = [];
443
+ let errors = [];
444
444
 
445
445
  //Check CI Relations
446
446
  if (relations && relations.ciRelations && Array.isArray(relations.ciRelations)) {
@@ -515,6 +515,9 @@ async function updateRelations(ticketConfig, userConfig, ticketId, relations) {
515
515
  }
516
516
  }
517
517
  }
518
+ if (errors && errors.length > 0) {
519
+ errors = errors.map(item => item.message)
520
+ }
518
521
  return errors;
519
522
  }
520
523
 
@@ -20,6 +20,7 @@ function getTickets(ticketConfig, config, includeString, customOptions, globalSc
20
20
  }
21
21
 
22
22
  async function createTicket(ticketConfig, clientConfig, data, globalScriptParams) {
23
+ let relationErrors;
23
24
  const scripts = clientConfig[ticketConfig.requestType].scripts.POST;
24
25
  const relations = data.relations || {}
25
26
  //run preScripts
@@ -57,11 +58,7 @@ async function createTicket(ticketConfig, clientConfig, data, globalScriptParams
57
58
  if (data[ticketConfig.businessServiceReconIdField] && relations) {
58
59
  relations.keepCIs = [data[ticketConfig.businessServiceReconIdField]]
59
60
  }
60
- const relationErrors = await ticketCIRelationController.updateRelations(ticketConfig, clientConfig, ticketId, relations);
61
- if (relationErrors && relationErrors.length > 0) {
62
- log.error(relationErrors)
63
- throw relationErrors;
64
- }
61
+ relationErrors = await ticketCIRelationController.updateRelations(ticketConfig, clientConfig, ticketId, relations);
65
62
 
66
63
  } else {
67
64
  log.error('Cannot create Ticket', resultInterfaceCreate);
@@ -72,7 +69,7 @@ async function createTicket(ticketConfig, clientConfig, data, globalScriptParams
72
69
  if (scripts && scripts.afterExecution) {
73
70
  await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId, globalScriptParams);
74
71
  }
75
- return resultInterfaceCreate;
72
+ return {createResult: resultInterfaceCreate, relationErrors};
76
73
  }
77
74
 
78
75
  function queryTickets(ticketConfig, clientConfig, query, mapping, customFields, customOptions, includeString, globalScriptParams) {
@@ -127,7 +124,8 @@ async function handleTicket(ticketConfig, ticket, mapping, clientConfig, include
127
124
  scripts = allScripts.GET || [];
128
125
  }
129
126
 
130
- globalScriptParams.id = ticket[ticketConfig.requestIdField]
127
+ //TODO: Check if needed
128
+ //globalScriptParams.id = ticket[ticketConfig.requestIdField]
131
129
 
132
130
  const requestType = ticketConfig.requestType;
133
131
  if (requestType === 'incident') {
@@ -287,6 +285,7 @@ async function getTicket(ticketConfig, config, id, mapping, includeString, globa
287
285
  }
288
286
 
289
287
  async function updateTicket(ticketConfig, clientConfig, id, ticketData, globalScriptParams) {
288
+ let relationErrors;
290
289
  const scripts = clientConfig[ticketConfig.requestType].scripts.PUT;
291
290
  const fields = clientConfig[ticketConfig.requestType].fields
292
291
  const relations = ticketData.relations || {}
@@ -310,7 +309,6 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData, globalSc
310
309
  if (scripts && scripts.postMapping) {
311
310
  await scriptController.runScripts(scripts.postMapping, ticketData, clientConfig.clientId, globalScriptParams);
312
311
  }
313
-
314
312
  const ticket = await getTicket(ticketConfig, myClientConfig, id, myMapping, undefined, globalScriptParams);
315
313
  log.debug('Ticket to Update', ticket);
316
314
  //keep businessService CI Relation
@@ -319,17 +317,12 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData, globalSc
319
317
  }
320
318
  //todo Abfangen wenn getTicket nichts liefert.
321
319
  const update = await arquery.updateEntry(ticketConfig.forms.regular, ticket.data.internalId, ticketData, clientConfig.options);
322
- const relationErrors = await ticketCIRelationController.updateRelations(ticketConfig, clientConfig, id, relations);
323
- if (relationErrors && relationErrors.length > 0) {
324
- log.error(relationErrors)
325
- throw relationErrors;
326
- }
320
+ relationErrors = await ticketCIRelationController.updateRelations(ticketConfig, clientConfig, id, relations);
327
321
  //run afterExecution
328
322
  if (scripts && scripts.afterExecution) {
329
323
  await scriptController.runScripts(scripts.afterExecution, ticketData, clientConfig.clientId, globalScriptParams);
330
324
  }
331
-
332
- return update;
325
+ return {updateResult: update, relationErrors};
333
326
  }
334
327
 
335
328
  function searchTicket(ticketConfig, clientConfig, searchString, fields, options, includeString, globalScriptParams) {
@@ -49,6 +49,9 @@ async function createWorklog(ticketConfig, clientConfig, ticketId, data, globalS
49
49
  )
50
50
  }
51
51
 
52
+ //todo Hier prüfen ob das Ticket existiert
53
+
54
+
52
55
  const clientConstants = clientConfig[ticketConfig.requestTypeWorkLog].constants;
53
56
  const viewAccessConstant = clientConstants.find(element => element.name === "View Access")
54
57
  //run only if isPublic is set and no Constant is defined
@@ -249,6 +249,18 @@ Sample:
249
249
 
250
250
  *AR_PASSWORD=password*
251
251
 
252
+ ### BASEQUERY
253
+
254
+ Allows advanced control of the events that are handled by this Event Manager Engine.
255
+
256
+ e.g. Add a delay before events are processed
257
+
258
+ *BASEQUERY='Create Date' + 60 < $TIMESTAMP$*
259
+
260
+ e.g. Handle specific client events only
261
+
262
+ *BASEQUERY='VendorID' = "abc123"*
263
+
252
264
  ## SSO Connection
253
265
 
254
266
  For a minimum configuration only the SSO Public Key is required.
package/docs/releases.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Release Notes
2
2
 
3
3
  ## API
4
- ### 1.59.2 - 10.06.22
4
+ ### 1.59.3 - 10.06.22
5
5
  Collect all ciTicketRelationErrors and return them at the end
6
6
 
7
7
  ### 1.58.0 - 31.03.22
@@ -174,6 +174,12 @@ e.g.
174
174
 
175
175
  ## Event Manager
176
176
 
177
+ ### 1.25.0 - 13.09.22
178
+ Improve error logging
179
+
180
+ ### 1.24.0 - 05.07.22
181
+ Added baseQuery option for advanced control
182
+
177
183
  ### 1.22.0 - 03.03.22
178
184
  Add updateScriptReference
179
185
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.59.2",
3
+ "version": "1.59.4",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -63,7 +63,12 @@ module.exports = (function() {
63
63
  const recordId = createResult;
64
64
  eventLog.setTicketId(req, recordId);
65
65
  req.eventData.ticketNumber = recordId;
66
- getRecord(req, res, next, req.user.config, recordId, null, includeString);
66
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
67
+ req.result = {};
68
+ next()
69
+ } else {
70
+ getRecord(req, res, next, req.user.config, recordId, null, includeString);
71
+ }
67
72
  }).catch(function (reason) {
68
73
  next(reason);
69
74
  });
@@ -164,7 +169,12 @@ module.exports = (function() {
164
169
  } else {
165
170
  customFormController.updateRecord(req.formConfig, req.user.config, id, req.body.data, req.globalScriptParams)
166
171
  .then(async function (updateResult) {
167
- getRecord(req, res, next, req.user.config, id, null, includeString);
172
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
173
+ req.result = {};
174
+ next()
175
+ } else {
176
+ getRecord(req, res, next, req.user.config, id, null, includeString);
177
+ }
168
178
  }).catch(function (reason) {
169
179
  next(reason);
170
180
  });
@@ -76,13 +76,18 @@ module.exports = (function () {
76
76
  log.debug('Add ciRelations to task', taskId, taskInstanceId, relations)
77
77
  await ticketCIRelationController.updateRelations(req.ticketConfig, req.user.config, taskInstanceId, relations);
78
78
  }
79
- task.getTaskByRootRequest(req.user.config, req.parentId, taskId, req.globalScriptParams, includeString).then(function (result) {
80
- req.includeObjectsList = result.included;
81
- req.result = {data:result.data || {}};
82
- next();
83
- }).catch(function (reason) {
84
- next(reason);
85
- })
79
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
80
+ req.result = {};
81
+ next()
82
+ } else {
83
+ task.getTaskByRootRequest(req.user.config, req.parentId, taskId, req.globalScriptParams, includeString).then(function (result) {
84
+ req.includeObjectsList = result.included;
85
+ req.result = {data: result.data || {}};
86
+ next();
87
+ }).catch(function (reason) {
88
+ next(reason);
89
+ })
90
+ }
86
91
  }
87
92
  }).catch(function (reason) {
88
93
  next(reason);
@@ -139,13 +144,18 @@ module.exports = (function () {
139
144
  log.debug('Add ciRelations to task', taskId, taskInstanceId, relations)
140
145
  await ticketCIRelationController.updateRelations(req.ticketConfig, req.user.config, taskInstanceId, relations);
141
146
  }
142
- task.getTaskByRootRequest(req.user.config, req.parentId, taskId, req.globalScriptParams, includeString).then(function (result) {
143
- req.includeObjectsList = result.included;
144
- req.result = {data:result.data || {}};
145
- next();
146
- }).catch(function (reason) {
147
- next(reason);
148
- })
147
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
148
+ req.result = {};
149
+ next()
150
+ } else {
151
+ task.getTaskByRootRequest(req.user.config, req.parentId, taskId, req.globalScriptParams, includeString).then(function (result) {
152
+ req.includeObjectsList = result.included;
153
+ req.result = {data: result.data || {}};
154
+ next();
155
+ }).catch(function (reason) {
156
+ next(reason);
157
+ })
158
+ }
149
159
  }).catch(function (reason) {
150
160
  next(reason);
151
161
  });
@@ -63,12 +63,22 @@ module.exports = (function() {
63
63
  next(errors.array());
64
64
  } else {
65
65
  //const relations = req.body.data.relations;
66
- ticketController.createTicket(req.ticketConfig, req.user.config, req.body.data, req.globalScriptParams).then(async function (createResult) {
66
+ ticketController.createTicket(req.ticketConfig, req.user.config, req.body.data, req.globalScriptParams).then(async function (result) {
67
+ const createResult = result.createResult;
68
+ const relationErrors = result.relationErrors;
69
+ if (relationErrors && Array.isArray(relationErrors) && relationErrors.length > 0) {
70
+ req.responseStatus = 422;
71
+ }
67
72
  const ticketId = createResult.data[0][req.ticketConfig.ticketIdField];
68
73
  eventLog.setTicketId(req, ticketId);
69
74
  req.eventData.ticketNumber = ticketId;
70
75
  //await ticketCIRelationController.updateRelations(req.ticketConfig, req.user.config, ticketId, relations);
71
- getTicket(req, res, next, req.user.config, ticketId, null, includeString);
76
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
77
+ req.result = {};
78
+ next()
79
+ } else {
80
+ getTicket(req, res, next, req.user.config, ticketId, null, includeString, {errors: {ciRelationErrors: relationErrors}});
81
+ }
72
82
  }).catch(function (reason) {
73
83
  next(reason);
74
84
  });
@@ -135,12 +145,15 @@ module.exports = (function() {
135
145
 
136
146
  });
137
147
 
138
- function getTicket(req, res, next, clientConfig, id, mapping, includeString) {
148
+ function getTicket(req, res, next, clientConfig, id, mapping, includeString, additionalData) {
139
149
  req.globalScriptParams.id = id
140
150
  ticketController.getTicket(req.ticketConfig, clientConfig, id, mapping, includeString, req.globalScriptParams).then(function (result) {
141
151
  log.debug('result', result);
142
152
  req.includeObjectsList = result.included;
143
153
  req.result = {data:result.data || {}};
154
+ if (additionalData) {
155
+ req.result = {...req.result, ...additionalData};
156
+ }
144
157
  if (!result.data) {
145
158
  req.responseStatus = 404;
146
159
  }
@@ -170,9 +183,18 @@ module.exports = (function() {
170
183
  } else {
171
184
  const relations = req.body.data.relations;
172
185
  ticketController.updateTicket(req.ticketConfig, req.user.config, id, req.body.data, req.globalScriptParams)
173
- .then(async function (updateResult) {
186
+ .then(async function (result) {
187
+ const relationErrors = result.relationErrors;
188
+ if (relationErrors && Array.isArray(relationErrors) && relationErrors.length > 0) {
189
+ req.responseStatus = 422;
190
+ }
174
191
  //await ticketCIRelationController.updateRelations(req.ticketConfig, req.user.config, id, relations);
175
- getTicket(req, res, next, req.user.config, id, null, includeString);
192
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
193
+ req.result = {};
194
+ next()
195
+ } else {
196
+ getTicket(req, res, next, req.user.config, id, null, includeString, {errors: {ciRelationErrors: relationErrors}});
197
+ }
176
198
  }).catch(function (reason) {
177
199
  next(reason);
178
200
  });
@@ -173,10 +173,15 @@ module.exports = (function() {
173
173
  req.globalScriptParams.id = ticketId
174
174
  req.globalScriptParams.id2 = worklogId
175
175
  log.debug('WorkLog created', worklogId);
176
- ticketWorkLogController.getWorklog(req.ticketConfig, req.user.config, ticketId, worklogId, undefined, req.globalScriptParams).then(worklogResult => {
177
- req.result = worklogResult;
178
- next();
179
- });
176
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
177
+ req.result = {};
178
+ next()
179
+ } else {
180
+ ticketWorkLogController.getWorklog(req.ticketConfig, req.user.config, ticketId, worklogId, undefined, req.globalScriptParams).then(worklogResult => {
181
+ req.result = worklogResult;
182
+ next();
183
+ });
184
+ }
180
185
  })
181
186
  .catch(error => {
182
187
  next(error);