@manyos/smileconnect-api 1.34.0 → 1.36.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
@@ -147,12 +147,15 @@ passport.use(
147
147
  clientId = requestedClientId
148
148
  }
149
149
 
150
+ const clientConfig = config.getClientConfig(clientId)
151
+ clientConfig.clientId = clientId
152
+
150
153
  const user = {
151
154
  'id': jwt_payload.sub,
152
155
  'azp': jwt_payload.azp,
153
156
  'scope': jwt_payload.scope,
154
157
  'exp': jwt_payload.exp,
155
- 'config': config.getClientConfig(clientId),
158
+ 'config': clientConfig,
156
159
  'username': jwt_payload.preferred_username
157
160
  }
158
161
  log.debug('Passport User', jwt_payload);
@@ -9,6 +9,13 @@ const adapterParams = {
9
9
  cacheTime: env.AR_CACHE_TTL || 300,
10
10
  limitDefault: env.LIMIT_DEFAULT || 100,
11
11
  limitMax: env.LIMIT_MAX
12
+ },
13
+ smileconnect: {
14
+ type: "SMILEconnect",
15
+ clientId: env.SC_CLIENT,
16
+ secret: env.SC_SECRET,
17
+ ssoUrl: env.SC_SSO_URL,
18
+ smileConnectUrl: env.SC_SMILECONNECT_URL
12
19
  }
13
20
  };
14
21
 
@@ -8,5 +8,8 @@ if (remedyResult) {
8
8
  if (weatherResponse) {
9
9
  requestData.weather = await weatherResponse.json()
10
10
  }
11
+ log.debug('testMessage')
12
+
13
+ requestData.scResults = await adapter.smileconnect.getTicket('incidents', requestData.id, {clientId:'idm'})
11
14
 
12
15
  resolve();
@@ -12,6 +12,7 @@ const ticketCIRelationController = require('../controller/ticketCIRelationContro
12
12
  const mappingUtil = require('../util/mappingUtil');
13
13
  const { v4 } = require('uuid');
14
14
  const CMDBOBJECT = 'cmdbobject';
15
+ const scriptController = require('./scriptController');
15
16
 
16
17
  const cmdbCache = new CacheService(process.env.CACHETTL_CMDB || 600); // Create a new cache service instance
17
18
  const schemaCache = new CacheService(process.env.CACHETTL_SCHEMANAMES || 3600); // Create a new cache service instance
@@ -299,7 +300,7 @@ async function updateCmdbObject(ticketConfig, clientConfig, id, ciData, classId)
299
300
 
300
301
  //run preScripts
301
302
  if (scripts && scripts.preMapping) {
302
- await scriptController.runScripts(scripts.preMapping, ciData);
303
+ await scriptController.runScripts(scripts.preMapping, ciData, clientConfig.clientId);
303
304
  }
304
305
 
305
306
  const myClientConfig = {};
@@ -323,14 +324,14 @@ async function updateCmdbObject(ticketConfig, clientConfig, id, ciData, classId)
323
324
 
324
325
  //run postMapping
325
326
  if (scripts && scripts.postMapping) {
326
- await scriptController.runScripts(scripts.postMapping, ciData);
327
+ await scriptController.runScripts(scripts.postMapping, ciData, clientConfig.clientId);
327
328
  }
328
329
 
329
330
  const update = await arquery.updateEntry(formName, ci['Request ID'], ciData);
330
331
 
331
332
  //run afterExecution
332
333
  if (scripts && scripts.afterExecution) {
333
- await scriptController.runScripts(scripts.afterExecution, ciData);
334
+ await scriptController.runScripts(scripts.afterExecution, ciData, clientConfig.clientId);
334
335
  }
335
336
 
336
337
  return update;
@@ -365,7 +366,7 @@ async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
365
366
 
366
367
  //run preScripts
367
368
  if (scripts && scripts.preMapping) {
368
- await scriptController.runScripts(scripts.preMapping, ciData);
369
+ await scriptController.runScripts(scripts.preMapping, ciData, clientConfig.clientId);
369
370
  }
370
371
 
371
372
  const mapping = getClassMapping(classId);
@@ -377,7 +378,7 @@ async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
377
378
 
378
379
  //run postMapping
379
380
  if (scripts && scripts.postMapping) {
380
- await scriptController.runScripts(scripts.postMapping, ciData);
381
+ await scriptController.runScripts(scripts.postMapping, ciData, clientConfig.clientId);
381
382
  }
382
383
 
383
384
  ciData['Data Set Id'] = "BMC.ASSET"
@@ -388,7 +389,7 @@ async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
388
389
 
389
390
  //run afterExecution
390
391
  if (scripts && scripts.afterExecution) {
391
- await scriptController.runScripts(scripts.afterExecution, ciData);
392
+ await scriptController.runScripts(scripts.afterExecution, ciData, clientConfig.clientId);
392
393
  }
393
394
 
394
395
  return instanceId;
@@ -45,7 +45,7 @@ function recFindByExt(base,ext,files,result) {
45
45
  return result
46
46
  }
47
47
 
48
- async function executeScriptInternal(scriptId, requestData, params, executedByScript) {
48
+ async function executeScriptInternal(scriptId, requestData, params, executedByScript, clientId) {
49
49
 
50
50
  const code = await getGlobalScript(scriptId);
51
51
 
@@ -53,14 +53,15 @@ async function executeScriptInternal(scriptId, requestData, params, executedBySc
53
53
  throw (`Script ${scriptId} does not exist!`);
54
54
  }
55
55
 
56
- return executeCode(code, requestData, params, null, executedByScript);
56
+ return executeCode(code, requestData, params, null, executedByScript, clientId, scriptId);
57
57
  }
58
58
 
59
- async function executeScript(scriptId, requestData, params) {
60
- return executeScriptInternal(scriptId, requestData, params, false)
59
+ async function executeScript(scriptId, requestData, params, clientId) {
60
+ return executeScriptInternal(scriptId, requestData, params, false, clientId)
61
61
  }
62
62
 
63
- async function executeCode(code, requestData, params, logStream, executedByScript) {
63
+ async function executeCode(code, requestData, params, logStream, executedByScript, clientId, scriptId) {
64
+ const log = require('@manyos/logger').setupLog('SMILEcatalog_Script_' + scriptId);
64
65
  //todo should only be added once
65
66
  /*if (logStream) {
66
67
  log.addStream(logStream);
@@ -69,7 +70,7 @@ async function executeCode(code, requestData, params, logStream, executedByScrip
69
70
  //try to set user data for sandbox
70
71
 
71
72
  async function executeScriptByScript(scriptId, requestData, params) {
72
- return executeScriptInternal(scriptId, requestData, params, true)
73
+ return executeScriptInternal(scriptId, requestData, params, true, clientId)
73
74
  }
74
75
 
75
76
  const sandbox = {
@@ -77,6 +78,7 @@ async function executeCode(code, requestData, params, logStream, executedByScrip
77
78
  params,
78
79
  adapter,
79
80
  log,
81
+ clientId,
80
82
  script:executeScriptByScript,
81
83
  env: process.env,
82
84
  fetch:fetch
@@ -243,10 +245,10 @@ async function getGlobalScripts() {
243
245
  return getScripts(path);
244
246
  }
245
247
 
246
- async function runScripts(scripts, data) {
248
+ async function runScripts(scripts, data, clientId) {
247
249
  try {
248
250
  for (let x = 0; x < scripts.length; x++) {
249
- await executeScript(scripts[x], data);
251
+ await executeScript(scripts[x], data, undefined, clientId);
250
252
  }
251
253
  } catch (error) {
252
254
  throw error;
@@ -70,21 +70,21 @@ async function createTask(clientConfig, rootForm, rootRequestId, taskData, creat
70
70
 
71
71
  //run preScripts
72
72
  if (scripts && scripts.preMapping) {
73
- await scriptController.runScripts(scripts.preMapping, taskData);
73
+ await scriptController.runScripts(scripts.preMapping, taskData, clientConfig.clientId);
74
74
  }
75
75
 
76
76
  taskData = mappingUtil.applyMapping2Remedy(taskData, mapping, clientConfig.task.constants, fields);
77
77
 
78
78
  //run postScripts
79
79
  if (scripts && scripts.postMapping) {
80
- await scriptController.runScripts(scripts.postMapping, taskData);
80
+ await scriptController.runScripts(scripts.postMapping, taskData, clientConfig.clientId);
81
81
  }
82
82
 
83
83
  const taskResult = await arquery.createEntry('TMS:Task', taskData, clientConfig.options)
84
84
 
85
85
  //run afterExecution
86
86
  if (scripts && scripts.afterExecution) {
87
- await scriptController.runScripts(scripts.afterExecution, data);
87
+ await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId);
88
88
  }
89
89
 
90
90
  log.debug('Create Task Result', taskResult);
@@ -140,21 +140,21 @@ async function createWorklog(clientConfig, taskId, summary, text, attachment) {
140
140
 
141
141
  //run preScripts
142
142
  if (scripts && scripts.preMapping) {
143
- await scriptController.runScripts(scripts.preMapping, data);
143
+ await scriptController.runScripts(scripts.preMapping, data, clientConfig.clientId);
144
144
  }
145
145
 
146
146
  data = mappingUtil.applyMapping2Remedy(data, mapping, clientConfig.taskWorklog.constants, fields);
147
147
 
148
148
  //run postScripts
149
149
  if (scripts && scripts.postMapping) {
150
- await scriptController.runScripts(scripts.postMapping, data);
150
+ await scriptController.runScripts(scripts.postMapping, data, clientConfig.clientId);
151
151
  }
152
152
 
153
153
  const result = await arquery.createEntry('TMS:WorkInfo', data, clientConfig.options)
154
154
 
155
155
  //run afterExecution
156
156
  if (scripts && scripts.afterExecution) {
157
- await scriptController.runScripts(scripts.afterExecution, data);
157
+ await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId);
158
158
  }
159
159
 
160
160
  return(result);
@@ -196,7 +196,7 @@ function queryTasks(clientConfig, query) {
196
196
 
197
197
  //run preScripts
198
198
  if (scripts && scripts.preMapping) {
199
- await scriptController.runScripts(scripts.preMapping, element);
199
+ await scriptController.runScripts(scripts.preMapping, element, clientConfig.clientId);
200
200
  }
201
201
 
202
202
  //Apply mapping
@@ -212,7 +212,7 @@ function queryTasks(clientConfig, query) {
212
212
 
213
213
  //run preScripts
214
214
  if (scripts && scripts.postMapping) {
215
- await scriptController.runScripts(scripts.postMapping, element);
215
+ await scriptController.runScripts(scripts.postMapping, element, clientConfig.clientId);
216
216
  }
217
217
  }
218
218
  return ({
@@ -252,7 +252,7 @@ async function queryWorklogs(clientConfig, query, mapping) {
252
252
 
253
253
  //run preScripts
254
254
  if (scripts && scripts.preMapping) {
255
- await scriptController.runScripts(scripts.preMapping, element);
255
+ await scriptController.runScripts(scripts.preMapping, element, clientConfig.clientId);
256
256
  }
257
257
 
258
258
  //Apply mapping
@@ -268,7 +268,7 @@ async function queryWorklogs(clientConfig, query, mapping) {
268
268
 
269
269
  //run postScripts
270
270
  if (scripts && scripts.postMapping) {
271
- await scriptController.runScripts(scripts.postMapping, element);
271
+ await scriptController.runScripts(scripts.postMapping, element, clientConfig.clientId);
272
272
  }
273
273
  }
274
274
  return {
@@ -314,21 +314,21 @@ async function updateTask(clientConfig, id, taskData) {
314
314
 
315
315
  //run preScripts
316
316
  if (scripts && scripts.preMapping) {
317
- await scriptController.runScripts(scripts.preMapping, taskData);
317
+ await scriptController.runScripts(scripts.preMapping, taskData, clientConfig.clientId);
318
318
  }
319
319
 
320
320
  taskData = mappingUtil.applyMapping2Remedy(taskData, mapping, taskConstants, fields);
321
321
 
322
322
  //run postScripts
323
323
  if (scripts && scripts.postMapping) {
324
- await scriptController.runScripts(scripts.postMapping, taskData);
324
+ await scriptController.runScripts(scripts.postMapping, taskData, clientConfig.clientId);
325
325
  }
326
326
 
327
327
  const result = await arquery.updateEntry('TMS:Task', id, taskData);
328
328
 
329
329
  //run afterExecution
330
330
  if (scripts && scripts.afterExecution) {
331
- await scriptController.runScripts(scripts.afterExecution, taskData);
331
+ await scriptController.runScripts(scripts.afterExecution, taskData, clientConfig.clientId);
332
332
  }
333
333
  return result;
334
334
  }
@@ -24,7 +24,7 @@ async function createTicket(ticketConfig, clientConfig, data) {
24
24
 
25
25
  //run preScripts
26
26
  if (scripts && scripts.preMapping) {
27
- await scriptController.runScripts(scripts.preMapping, data);
27
+ await scriptController.runScripts(scripts.preMapping, data, clientConfig.clientId);
28
28
  }
29
29
 
30
30
  const requestType = ticketConfig.requestType;
@@ -39,7 +39,7 @@ async function createTicket(ticketConfig, clientConfig, data) {
39
39
 
40
40
  //run postScripts
41
41
  if (scripts && scripts.postMapping) {
42
- await scriptController.runScripts(scripts.postMapping, data);
42
+ await scriptController.runScripts(scripts.postMapping, data, clientConfig.clientId);
43
43
  }
44
44
 
45
45
  const result = await arquery.createEntry(ticketConfig.forms.new, data, clientConfig.options)
@@ -63,7 +63,7 @@ async function createTicket(ticketConfig, clientConfig, data) {
63
63
 
64
64
  //run afterExecution
65
65
  if (scripts && scripts.afterExecution) {
66
- await scriptController.runScripts(scripts.afterExecution, data);
66
+ await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId);
67
67
  }
68
68
  return resultInterfaceCreate;
69
69
  }
@@ -136,7 +136,7 @@ async function handleTicket(ticketConfig, ticket, mapping, clientConfig, include
136
136
  const preScripts = scripts.preMapping;
137
137
  try {
138
138
  for (let x = 0; x < preScripts.length; x++) {
139
- const result = await scriptController.executeScript(preScripts[x], ticket);
139
+ const result = await scriptController.executeScript(preScripts[x], ticket, null, clientConfig.clientId);
140
140
  }
141
141
  } catch (error) {
142
142
  throw error;
@@ -160,7 +160,7 @@ async function handleTicket(ticketConfig, ticket, mapping, clientConfig, include
160
160
  const postScripts = scripts.postMapping;
161
161
  try {
162
162
  for (let x = 0; x < postScripts.length; x++) {
163
- const result = await scriptController.executeScript(postScripts[x], ticket);
163
+ const result = await scriptController.executeScript(postScripts[x], ticket, null, clientConfig.clientId);
164
164
  }
165
165
  } catch (error) {
166
166
  throw error;
@@ -283,16 +283,14 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData) {
283
283
 
284
284
  //run preScripts
285
285
  if (scripts && scripts.preMapping) {
286
- await scriptController.runScripts(scripts.preMapping, ticketData);
286
+ await scriptController.runScripts(scripts.preMapping, ticketData, clientConfig.clientId);
287
287
  }
288
288
 
289
289
  log.debug(clientConfig[ticketConfig.requestType]);
290
290
  const myClientConfig = {};
291
291
  myClientConfig[ticketConfig.requestType] = {baseQuery: clientConfig[ticketConfig.requestType].baseQuery, fields: [1]};
292
292
  const myMapping = [{"oldName":ticketConfig.requestIdField, "newName" : "internalId"}];
293
- const ticket = await getTicket(ticketConfig, myClientConfig, id, myMapping);
294
- log.debug('Ticket to Update', ticket);
295
- //todo Abfangen wenn getTicket nichts liefert.
293
+
296
294
  const mapping = config.getMapping(ticketConfig.requestType);
297
295
 
298
296
  //Constants work only on new.
@@ -300,14 +298,17 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData) {
300
298
 
301
299
  //run postMapping
302
300
  if (scripts && scripts.postMapping) {
303
- await scriptController.runScripts(scripts.postMapping, ticketData);
301
+ await scriptController.runScripts(scripts.postMapping, ticketData, clientConfig.clientId);
304
302
  }
305
303
 
304
+ const ticket = await getTicket(ticketConfig, myClientConfig, id, myMapping);
305
+ log.debug('Ticket to Update', ticket);
306
+ //todo Abfangen wenn getTicket nichts liefert.
306
307
  const update = await arquery.updateEntry(ticketConfig.forms.regular, ticket.data.internalId, ticketData);
307
308
 
308
309
  //run afterExecution
309
310
  if (scripts && scripts.afterExecution) {
310
- await scriptController.runScripts(scripts.afterExecution, ticketData);
311
+ await scriptController.runScripts(scripts.afterExecution, ticketData, clientConfig.clientId);
311
312
  }
312
313
 
313
314
  return update;
@@ -61,21 +61,21 @@ async function createWorklog(ticketConfig, clientConfig, ticketId, summary, text
61
61
 
62
62
  //run preScripts
63
63
  if (scripts && scripts.preMapping) {
64
- await scriptController.runScripts(scripts.preMapping, data);
64
+ await scriptController.runScripts(scripts.preMapping, data, clientConfig.clientId);
65
65
  }
66
66
 
67
67
  data = mappingUtil.applyMapping2Remedy(data, mapping, clientConstants, fields);
68
68
 
69
69
  //run postScripts
70
70
  if (scripts && scripts.postMapping) {
71
- await scriptController.runScripts(scripts.postMapping, data);
71
+ await scriptController.runScripts(scripts.postMapping, data, clientConfig.clientId);
72
72
  }
73
73
 
74
74
  const result = arquery.createEntry(ticketConfig.forms.workLog, data, clientConfig.options)
75
75
 
76
76
  //run afterExecution
77
77
  if (scripts && scripts.afterExecution) {
78
- await scriptController.runScripts(scripts.afterExecution, data);
78
+ await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId);
79
79
  }
80
80
 
81
81
  return result;
@@ -169,12 +169,12 @@ async function queryWorklogs(ticketConfig, clientConfig, query, mapping) {
169
169
  const element = result.data[x];
170
170
  //run preScripts
171
171
  if (scripts && scripts.preMapping) {
172
- await scriptController.runScripts(scripts.preMapping, result.data);
172
+ await scriptController.runScripts(scripts.preMapping, result.data, clientConfig.clientId);
173
173
  }
174
174
  applyMapping(element, mapping, 'Entry ID');
175
175
  //run postScripts
176
176
  if (scripts && scripts.postMapping) {
177
- await scriptController.runScripts(scripts.postMapping, result.data);
177
+ await scriptController.runScripts(scripts.postMapping, result.data, clientConfig.clientId);
178
178
  }
179
179
  }
180
180
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.34.0",
3
+ "version": "1.36.0",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -46,9 +46,9 @@ describe('Integration Tests - Incidents', function () {
46
46
  })
47
47
 
48
48
  it ('it should get all incidents', function (done) {
49
- this.timeout(5000);
49
+ this.timeout(25000);
50
50
  chai.request(server)
51
- .get('/v1/incidents')
51
+ .get('/v1/incidents?limit=10')
52
52
  .set('Authorization', 'Bearer ' + authUser.access_token)
53
53
  .end(function(err, res) {
54
54
  res.should.have.status(200);