@manyos/smileconnect-api 1.59.3 → 1.60.0

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
@@ -2091,9 +2091,11 @@
2091
2091
  "preMapping": [],
2092
2092
  "postMapping": []
2093
2093
  },
2094
- "POST": {
2094
+ "PUT": {
2095
2095
  "preMapping": [],
2096
- "postMapping": []
2096
+ "postMapping": [
2097
+ "notfetchresult"
2098
+ ]
2097
2099
  }
2098
2100
  }
2099
2101
  },
@@ -2289,7 +2291,9 @@
2289
2291
  },
2290
2292
  "PUT": {
2291
2293
  "preMapping": [],
2292
- "postMapping": [],
2294
+ "postMapping": [
2295
+ "notFetchResult"
2296
+ ],
2293
2297
  "afterExecution": []
2294
2298
  },
2295
2299
  "POST": {
@@ -2376,14 +2380,18 @@
2376
2380
  "preMapping": [
2377
2381
  "p2"
2378
2382
  ],
2379
- "postMapping": [],
2383
+ "postMapping": [
2384
+ "notFetchResult"
2385
+ ],
2380
2386
  "afterExecution": [
2381
2387
  "INC_CreateWorklog_OnCreate"
2382
2388
  ]
2383
2389
  },
2384
2390
  "PUT": {
2385
2391
  "preMapping": [],
2386
- "postMapping": [],
2392
+ "postMapping": [
2393
+ "notFetchResult"
2394
+ ],
2387
2395
  "afterExecution": []
2388
2396
  }
2389
2397
  }
@@ -2491,7 +2499,15 @@
2491
2499
  }
2492
2500
  ],
2493
2501
  "basequery": "",
2494
- "scripts": {},
2502
+ "scripts": {
2503
+ "POST": {
2504
+ "preMapping": [],
2505
+ "postMapping": [
2506
+ "notFetchResult"
2507
+ ],
2508
+ "afterExecution": []
2509
+ }
2510
+ },
2495
2511
  "attachmentScripts": {}
2496
2512
  },
2497
2513
  "problemWorklog": {
@@ -2562,7 +2578,22 @@
2562
2578
  "value": "1000"
2563
2579
  }
2564
2580
  ],
2565
- "scripts": {}
2581
+ "scripts": {
2582
+ "POST": {
2583
+ "preMapping": [],
2584
+ "postMapping": [
2585
+ "notFetchResult"
2586
+ ],
2587
+ "afterExecution": []
2588
+ },
2589
+ "PUT": {
2590
+ "preMapping": [],
2591
+ "postMapping": [
2592
+ "notFetchResult"
2593
+ ],
2594
+ "afterExecution": []
2595
+ }
2596
+ }
2566
2597
  },
2567
2598
  "taskWorklog": {
2568
2599
  "fields": [
@@ -2585,7 +2616,22 @@
2585
2616
  }
2586
2617
  ],
2587
2618
  "basequery": "1=1",
2588
- "scripts": {},
2619
+ "scripts": {
2620
+ "POST": {
2621
+ "preMapping": [],
2622
+ "postMapping": [
2623
+ "notFetchResult"
2624
+ ],
2625
+ "afterExecution": []
2626
+ },
2627
+ "PUT": {
2628
+ "preMapping": [],
2629
+ "postMapping": [
2630
+ "notFetchResult"
2631
+ ],
2632
+ "afterExecution": []
2633
+ }
2634
+ },
2589
2635
  "attachmentScripts": {
2590
2636
  "POST": {
2591
2637
  "preMapping": [
@@ -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
  }
@@ -124,7 +124,8 @@ async function handleTicket(ticketConfig, ticket, mapping, clientConfig, include
124
124
  scripts = allScripts.GET || [];
125
125
  }
126
126
 
127
- globalScriptParams.id = ticket[ticketConfig.requestIdField]
127
+ //TODO: Check if needed
128
+ //globalScriptParams.id = ticket[ticketConfig.requestIdField]
128
129
 
129
130
  const requestType = ticketConfig.requestType;
130
131
  if (requestType === 'incident') {
@@ -308,7 +309,6 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData, globalSc
308
309
  if (scripts && scripts.postMapping) {
309
310
  await scriptController.runScripts(scripts.postMapping, ticketData, clientConfig.clientId, globalScriptParams);
310
311
  }
311
-
312
312
  const ticket = await getTicket(ticketConfig, myClientConfig, id, myMapping, undefined, globalScriptParams);
313
313
  log.debug('Ticket to Update', ticket);
314
314
  //keep businessService CI Relation
@@ -322,7 +322,6 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData, globalSc
322
322
  if (scripts && scripts.afterExecution) {
323
323
  await scriptController.runScripts(scripts.afterExecution, ticketData, clientConfig.clientId, globalScriptParams);
324
324
  }
325
-
326
325
  return {updateResult: update, relationErrors};
327
326
  }
328
327
 
@@ -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,6 +1,9 @@
1
1
  # Release Notes
2
2
 
3
3
  ## API
4
+ ### 1.60.0 - 27.09.22
5
+ Add optional parameter "notFetchResult" to globalScriptParams. If set to yes, no object will be returned after POST/PUT requests. This can help to reduce database / server load as request are reduced.
6
+
4
7
  ### 1.59.3 - 10.06.22
5
8
  Collect all ciTicketRelationErrors and return them at the end
6
9
 
@@ -174,6 +177,12 @@ e.g.
174
177
 
175
178
  ## Event Manager
176
179
 
180
+ ### 1.25.0 - 13.09.22
181
+ Improve error logging
182
+
183
+ ### 1.24.0 - 05.07.22
184
+ Added baseQuery option for advanced control
185
+
177
186
  ### 1.22.0 - 03.03.22
178
187
  Add updateScriptReference
179
188
 
package/docs/scripts.md CHANGED
@@ -189,6 +189,8 @@ Full example:
189
189
  }
190
190
  ```
191
191
 
192
+ **notFetchResult**: If set to yes, no object will be returned after POST/PUT requests. This can help to reduce database / server load as request are reduced.
193
+
192
194
  globalScriptParams is not available in Event Manager scripts. Ids are part of requestData there.
193
195
 
194
196
  ## requestData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.59.3",
3
+ "version": "1.60.0",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -187,9 +187,14 @@ module.exports = (function () {
187
187
  const hasAccess = await cmdbobjects.hasAccess(req.user.config, id);
188
188
  if (hasAccess) {
189
189
  const result = await cmdbobjects.updateCmdbObject(req.ticketConfig, req.user.config, id, req.body.data, classId, req.globalScriptParams);
190
- const ci = await cmdbobjects.getCmdbObject(req.user.config, id, includeString, undefined, req.globalScriptParams);
191
- req.result = ci;
192
- next();
190
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
191
+ req.result = {};
192
+ next()
193
+ } else {
194
+ const ci = await cmdbobjects.getCmdbObject(req.user.config, id, includeString, undefined, req.globalScriptParams);
195
+ req.result = ci;
196
+ next();
197
+ }
193
198
  } else {
194
199
  req.errorStatus = 403;
195
200
  next('Access forbidden.')
@@ -219,10 +224,15 @@ module.exports = (function () {
219
224
  const result = [];
220
225
  try {
221
226
  const ciInstanceId = await cmdbobjects.createCmdbObject(req.ticketConfig, req.user.config, classId, req.body.data, req.globalScriptParams);
222
- req.globalScriptParams.id = ciInstanceId
223
- const ci = await cmdbobjects.getCmdbObject(req.user.config, ciInstanceId, includeString, undefined, req.globalScriptParams);
224
- req.result = ci;
225
- next();
227
+ req.globalScriptParams.id = ciInstanceId;
228
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
229
+ req.result = {};
230
+ next()
231
+ } else {
232
+ const ci = await cmdbobjects.getCmdbObject(req.user.config, ciInstanceId, includeString, undefined, req.globalScriptParams);
233
+ req.result = ci;
234
+ next();
235
+ }
226
236
  } catch (e) {
227
237
  next(e);
228
238
  }
@@ -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
  });
@@ -200,18 +210,23 @@ module.exports = (function () {
200
210
  task.createWorklog(req.user.config, taskId, req.body.data, req.globalScriptParams)
201
211
  .then(createResult => {
202
212
  const worklogId = createResult['0'];
203
- task.getTaskWorklog(req.user.config, taskId, worklogId, req.globalScriptParams).then(result => {
204
- const urls = {
205
- "attachmentUrl" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/1`,
206
- "attachmentUrl2" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/2`,
207
- "attachmentUrl3" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/3`,
208
- "self" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}`
209
- };
210
- req.includeObjectsList = result.included;
211
- req.result = {data:result.data || {}};
212
- req.result.urls = urls;
213
- next();
214
- });
213
+ if (req.globalScriptParams && req.globalScriptParams.notFetchResult && req.globalScriptParams.notFetchResult === true) {
214
+ req.result = {};
215
+ next()
216
+ } else {
217
+ task.getTaskWorklog(req.user.config, taskId, worklogId, req.globalScriptParams).then(result => {
218
+ const urls = {
219
+ "attachmentUrl": `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/1`,
220
+ "attachmentUrl2": `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/2`,
221
+ "attachmentUrl3": `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/3`,
222
+ "self": `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}`
223
+ };
224
+ req.includeObjectsList = result.included;
225
+ req.result = {data: result.data || {}};
226
+ req.result.urls = urls;
227
+ next();
228
+ });
229
+ }
215
230
  log.debug('WorkLog created');
216
231
  })
217
232
  .catch(error => {
@@ -73,7 +73,12 @@ module.exports = (function() {
73
73
  eventLog.setTicketId(req, ticketId);
74
74
  req.eventData.ticketNumber = ticketId;
75
75
  //await ticketCIRelationController.updateRelations(req.ticketConfig, req.user.config, ticketId, relations);
76
- getTicket(req, res, next, req.user.config, ticketId, null, includeString, {errors:{ciRelationErrors:relationErrors}});
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
+ }
77
82
  }).catch(function (reason) {
78
83
  next(reason);
79
84
  });
@@ -184,7 +189,12 @@ module.exports = (function() {
184
189
  req.responseStatus = 422;
185
190
  }
186
191
  //await ticketCIRelationController.updateRelations(req.ticketConfig, req.user.config, id, relations);
187
- getTicket(req, res, next, req.user.config, id, null, includeString, {errors:{ciRelationErrors:relationErrors}});
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
+ }
188
198
  }).catch(function (reason) {
189
199
  next(reason);
190
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);