@manyos/smileconnect-api 1.38.0 → 1.39.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 +9 -0
- package/conf/clients.json +1 -2
- package/conf/scripts/checkGlobalParams.js +3 -0
- package/controller/cmdbobjectController.js +21 -21
- package/controller/customFormController.js +19 -19
- package/controller/relatedObjectsController.js +5 -5
- package/controller/scriptController.js +10 -9
- package/controller/taskController.js +31 -30
- package/controller/ticketController.js +18 -24
- package/controller/ticketWorkLogController.js +11 -11
- package/docs/openapi.json +949 -833
- package/package.json +1 -1
- package/routes/cmdbObjectRoutes.js +7 -7
- package/routes/customFormRoutes.js +5 -5
- package/routes/taskRoutes.js +11 -11
- package/routes/ticketRoutes.js +5 -5
- package/routes/ticketWorkLogRoutes.js +4 -4
package/app.js
CHANGED
|
@@ -233,6 +233,15 @@ app.get('/debug', function (req, res, next) {
|
|
|
233
233
|
//global authentication
|
|
234
234
|
app.use(passport.authenticate('jwt', {session: false}), responseHandler.logRequest);
|
|
235
235
|
|
|
236
|
+
//set globalscript params
|
|
237
|
+
app.use(function (req, res, next) {
|
|
238
|
+
req.globalScriptParams = {
|
|
239
|
+
query: req.query,
|
|
240
|
+
params: req.params
|
|
241
|
+
}
|
|
242
|
+
next()
|
|
243
|
+
});
|
|
244
|
+
|
|
236
245
|
// setup routes
|
|
237
246
|
|
|
238
247
|
app.use('/v1/cmdbobjects', function(req, res, next) {
|
package/conf/clients.json
CHANGED
|
@@ -21,7 +21,7 @@ function getRandomId() {
|
|
|
21
21
|
return v4();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function getCmdbObjects(config, category, ciIds, includeString, options) {
|
|
24
|
+
function getCmdbObjects(config, category, ciIds, includeString, options, globalScriptParams) {
|
|
25
25
|
let query = '1=1';
|
|
26
26
|
if (category)
|
|
27
27
|
query = `'Category' = \"${category}\"`;
|
|
@@ -37,7 +37,7 @@ function getCmdbObjects(config, category, ciIds, includeString, options) {
|
|
|
37
37
|
query = query + ciQuery + ')';
|
|
38
38
|
log.error('query', query);
|
|
39
39
|
}
|
|
40
|
-
return queryCMDBObject(config, query, null, options, includeString);
|
|
40
|
+
return queryCMDBObject(config, query, null, options, includeString, undefined, globalScriptParams);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function getCIRelations(clientConfig, id) {
|
|
@@ -121,7 +121,7 @@ function getSchemaName(classId) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function queryCMDBObject(clientConfig, query, customFields, customOptions, includeString, mapping) {
|
|
124
|
+
function queryCMDBObject(clientConfig, query, customFields, customOptions, includeString, mapping, globalScriptParams) {
|
|
125
125
|
let fields = clientConfig.cmdbobject.fields;
|
|
126
126
|
let deleteClassId = false;
|
|
127
127
|
|
|
@@ -158,7 +158,7 @@ function queryCMDBObject(clientConfig, query, customFields, customOptions, inclu
|
|
|
158
158
|
if (result && result.data && result.data.length) {
|
|
159
159
|
let x = 0;
|
|
160
160
|
for (x=0; x< result.data.length; x++) {
|
|
161
|
-
const cmdbObject = await handleCMDBObjectResult(result.data[x], mapping, clientConfig, includeArray, globalRelationObjects, deleteClassId);
|
|
161
|
+
const cmdbObject = await handleCMDBObjectResult(result.data[x], mapping, clientConfig, includeArray, globalRelationObjects, deleteClassId, globalScriptParams);
|
|
162
162
|
cmdbObjects.push(cmdbObject);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
@@ -170,7 +170,7 @@ function queryCMDBObject(clientConfig, query, customFields, customOptions, inclu
|
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
async function handleCMDBObjectResult(cmdbObject, mapping, clientConfig, includeArray, globalRelationObjects, deleteClassId) {
|
|
173
|
+
async function handleCMDBObjectResult(cmdbObject, mapping, clientConfig, includeArray, globalRelationObjects, deleteClassId, globalScriptParams) {
|
|
174
174
|
//get class form
|
|
175
175
|
const classId = cmdbObject['Class Id'];
|
|
176
176
|
if (deleteClassId === true) {
|
|
@@ -182,7 +182,7 @@ async function handleCMDBObjectResult(cmdbObject, mapping, clientConfig, include
|
|
|
182
182
|
|
|
183
183
|
//run preScripts
|
|
184
184
|
if (scripts && scripts.preMapping) {
|
|
185
|
-
await scriptController.runScripts(scripts.preMapping, cmdbObject, clientConfig.clientId);
|
|
185
|
+
await scriptController.runScripts(scripts.preMapping, cmdbObject, clientConfig.clientId, globalScriptParams);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
//Apply mapping
|
|
@@ -236,7 +236,7 @@ async function handleCMDBObjectResult(cmdbObject, mapping, clientConfig, include
|
|
|
236
236
|
|
|
237
237
|
//run preScripts
|
|
238
238
|
if (scripts && scripts.postMapping) {
|
|
239
|
-
await scriptController.runScripts(scripts.postMapping, cmdbObject, clientConfig.clientId);
|
|
239
|
+
await scriptController.runScripts(scripts.postMapping, cmdbObject, clientConfig.clientId, globalScriptParams);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
return cmdbObject;
|
|
@@ -272,9 +272,9 @@ async function getCMDBObjectClassAttributes(id, classId, clientConfig, mapping)
|
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
async function getCmdbObject(config, id, includeString, mapping) {
|
|
275
|
+
async function getCmdbObject(config, id, includeString, mapping, globalScriptParams) {
|
|
276
276
|
const query = `'Instance Id'=\"${id}\"`;
|
|
277
|
-
const returnValue = await queryCMDBObject(config, query, null, null, includeString, mapping);
|
|
277
|
+
const returnValue = await queryCMDBObject(config, query, null, null, includeString, mapping, globalScriptParams);
|
|
278
278
|
log.debug (returnValue);
|
|
279
279
|
const cmdbObject = returnValue.data[0];
|
|
280
280
|
return {data: cmdbObject, included: returnValue.included};
|
|
@@ -293,20 +293,20 @@ async function applyMapping(clientConfig, data) {
|
|
|
293
293
|
return mappedRecord;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
function searchCmdbObjectByName(config, name, includeString) {
|
|
296
|
+
function searchCmdbObjectByName(config, name, includeString, globalScriptParams) {
|
|
297
297
|
const query = `'Name'LIKE\"%${name}%\"`;
|
|
298
|
-
return queryCMDBObject(config, query, null, null, includeString);
|
|
298
|
+
return queryCMDBObject(config, query, null, null, includeString, globalScriptParams);
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
function searchCmdbObject(clientConfig, searchString, fields, options, includeString) {
|
|
301
|
+
function searchCmdbObject(clientConfig, searchString, fields, options, includeString, globalScriptParams) {
|
|
302
302
|
const mapping = config.getMapping(CMDBOBJECT);
|
|
303
303
|
const mappedString = searchUtil.applyMapping(searchString, mapping);
|
|
304
304
|
const customFields = searchUtil.getCustomFields(clientConfig.cmdbobject.fields, mapping, fields);
|
|
305
305
|
options.sort = searchUtil.applySortMapping(options.sort, mapping);
|
|
306
|
-
return queryCMDBObject(clientConfig, mappedString, customFields, options, includeString);
|
|
306
|
+
return queryCMDBObject(clientConfig, mappedString, customFields, options, includeString, undefined, globalScriptParams);
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
async function updateCmdbObject(ticketConfig, clientConfig, id, ciData, classId) {
|
|
309
|
+
async function updateCmdbObject(ticketConfig, clientConfig, id, ciData, classId, globalScriptParams) {
|
|
310
310
|
const formName = classId || 'AST:BaseElement';
|
|
311
311
|
|
|
312
312
|
const scripts = clientConfig[CMDBOBJECT].scripts.PUT;
|
|
@@ -314,7 +314,7 @@ async function updateCmdbObject(ticketConfig, clientConfig, id, ciData, classId)
|
|
|
314
314
|
|
|
315
315
|
//run preScripts
|
|
316
316
|
if (scripts && scripts.preMapping) {
|
|
317
|
-
await scriptController.runScripts(scripts.preMapping, ciData, clientConfig.clientId);
|
|
317
|
+
await scriptController.runScripts(scripts.preMapping, ciData, clientConfig.clientId, globalScriptParams);
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
const myClientConfig = {};
|
|
@@ -338,14 +338,14 @@ async function updateCmdbObject(ticketConfig, clientConfig, id, ciData, classId)
|
|
|
338
338
|
|
|
339
339
|
//run postMapping
|
|
340
340
|
if (scripts && scripts.postMapping) {
|
|
341
|
-
await scriptController.runScripts(scripts.postMapping, ciData, clientConfig.clientId);
|
|
341
|
+
await scriptController.runScripts(scripts.postMapping, ciData, clientConfig.clientId, globalScriptParams);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
const update = await arquery.updateEntry(formName, ci['Request ID'], ciData);
|
|
345
345
|
|
|
346
346
|
//run afterExecution
|
|
347
347
|
if (scripts && scripts.afterExecution) {
|
|
348
|
-
await scriptController.runScripts(scripts.afterExecution, ciData, clientConfig.clientId);
|
|
348
|
+
await scriptController.runScripts(scripts.afterExecution, ciData, clientConfig.clientId, globalScriptParams);
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
return update;
|
|
@@ -371,7 +371,7 @@ function getClassMapping(classId) {
|
|
|
371
371
|
return mappings;
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
|
|
374
|
+
async function createCmdbObject(assetConfig, clientConfig, classId, ciData, globalScriptParams) {
|
|
375
375
|
const reconId = getRandomId();
|
|
376
376
|
const instanceId = getRandomId();
|
|
377
377
|
|
|
@@ -380,7 +380,7 @@ async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
|
|
|
380
380
|
|
|
381
381
|
//run preScripts
|
|
382
382
|
if (scripts && scripts.preMapping) {
|
|
383
|
-
await scriptController.runScripts(scripts.preMapping, ciData, clientConfig.clientId);
|
|
383
|
+
await scriptController.runScripts(scripts.preMapping, ciData, clientConfig.clientId, globalScriptParams);
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
const mapping = getClassMapping(classId);
|
|
@@ -392,7 +392,7 @@ async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
|
|
|
392
392
|
|
|
393
393
|
//run postMapping
|
|
394
394
|
if (scripts && scripts.postMapping) {
|
|
395
|
-
await scriptController.runScripts(scripts.postMapping, ciData, clientConfig.clientId);
|
|
395
|
+
await scriptController.runScripts(scripts.postMapping, ciData, clientConfig.clientId, globalScriptParams);
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
ciData['Data Set Id'] = "BMC.ASSET"
|
|
@@ -403,7 +403,7 @@ async function createCmdbObject(assetConfig, clientConfig, classId, ciData) {
|
|
|
403
403
|
|
|
404
404
|
//run afterExecution
|
|
405
405
|
if (scripts && scripts.afterExecution) {
|
|
406
|
-
await scriptController.runScripts(scripts.afterExecution, ciData, clientConfig.clientId);
|
|
406
|
+
await scriptController.runScripts(scripts.afterExecution, ciData, clientConfig.clientId, globalScriptParams);
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
return instanceId;
|
|
@@ -12,12 +12,12 @@ const mappingUtil = require('../util/mappingUtil');
|
|
|
12
12
|
|
|
13
13
|
const ticketCache = new CacheService(process.env.CACHETTL_TICKETS || 1); // Create a new cache service instance
|
|
14
14
|
|
|
15
|
-
function getRecords(formConfig, clientConfig, includeString, customOptions) {
|
|
15
|
+
function getRecords(formConfig, clientConfig, includeString, customOptions, globalScriptParams) {
|
|
16
16
|
let query = '1=1';
|
|
17
|
-
return queryRecords(formConfig, clientConfig, query, null, null, customOptions, includeString);
|
|
17
|
+
return queryRecords(formConfig, clientConfig, query, null, null, customOptions, includeString, globalScriptParams);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
async function createRecord(formConfig, clientConfig, data) {
|
|
20
|
+
async function createRecord(formConfig, clientConfig, data, globalScriptParams) {
|
|
21
21
|
const allScripts = clientConfig[formConfig.configName].scripts;
|
|
22
22
|
let scripts
|
|
23
23
|
if (allScripts) {
|
|
@@ -26,7 +26,7 @@ async function createRecord(formConfig, clientConfig, data) {
|
|
|
26
26
|
|
|
27
27
|
//run preScripts
|
|
28
28
|
if (scripts && scripts.preMapping) {
|
|
29
|
-
await scriptController.runScripts(scripts.preMapping, data, clientConfig.clientId);
|
|
29
|
+
await scriptController.runScripts(scripts.preMapping, data, clientConfig.clientId, globalScriptParams);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const requestType = formConfig.requestType;
|
|
@@ -40,7 +40,7 @@ async function createRecord(formConfig, clientConfig, data) {
|
|
|
40
40
|
|
|
41
41
|
//run postScripts
|
|
42
42
|
if (scripts && scripts.postMapping) {
|
|
43
|
-
await scriptController.runScripts(scripts.postMapping, data, clientConfig.clientId);
|
|
43
|
+
await scriptController.runScripts(scripts.postMapping, data, clientConfig.clientId, globalScriptParams);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const result = await arquery.createEntry(formConfig.formName, data, clientConfig.options)
|
|
@@ -58,12 +58,12 @@ async function createRecord(formConfig, clientConfig, data) {
|
|
|
58
58
|
|
|
59
59
|
//run afterExecution
|
|
60
60
|
if (scripts && scripts.afterExecution) {
|
|
61
|
-
await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId);
|
|
61
|
+
await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId, globalScriptParams);
|
|
62
62
|
}
|
|
63
63
|
return recordCreateId;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function queryRecords(formConfig, clientConfig, query, mapping, customFields, customOptions, includeString) {
|
|
66
|
+
function queryRecords(formConfig, clientConfig, query, mapping, customFields, customOptions, includeString, globalScriptParams) {
|
|
67
67
|
const includeArray = getIncludeArray(includeString);
|
|
68
68
|
log.debug('Get config for', formConfig.configName)
|
|
69
69
|
let fields = clientConfig[formConfig.configName].fields;
|
|
@@ -94,7 +94,7 @@ function queryRecords(formConfig, clientConfig, query, mapping, customFields, cu
|
|
|
94
94
|
if (result && result.data && result.data.length) {
|
|
95
95
|
let x = 0;
|
|
96
96
|
for (x=0; x< result.data.length; x++) {
|
|
97
|
-
const ticket = await handleRecord(formConfig, result.data[x], mapping, clientConfig, includeArray);
|
|
97
|
+
const ticket = await handleRecord(formConfig, result.data[x], mapping, clientConfig, includeArray, globalScriptParams);
|
|
98
98
|
records.push(ticket);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -105,7 +105,7 @@ function queryRecords(formConfig, clientConfig, query, mapping, customFields, cu
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
async function handleRecord(formConfig, record, mapping, clientConfig, includeArray,
|
|
108
|
+
async function handleRecord(formConfig, record, mapping, clientConfig, includeArray, globalScriptParams) {
|
|
109
109
|
const allScripts = clientConfig[formConfig.configName].scripts;
|
|
110
110
|
let scripts = [];
|
|
111
111
|
if (allScripts) {
|
|
@@ -117,7 +117,7 @@ async function handleRecord(formConfig, record, mapping, clientConfig, includeAr
|
|
|
117
117
|
const preScripts = scripts.preMapping;
|
|
118
118
|
try {
|
|
119
119
|
for (let x = 0; x < preScripts.length; x++) {
|
|
120
|
-
const result = await scriptController.executeScript(preScripts[x], record, null, clientConfig.clientId);
|
|
120
|
+
const result = await scriptController.executeScript(preScripts[x], record, null, clientConfig.clientId, globalScriptParams);
|
|
121
121
|
}
|
|
122
122
|
} catch (error) {
|
|
123
123
|
throw error;
|
|
@@ -131,7 +131,7 @@ async function handleRecord(formConfig, record, mapping, clientConfig, includeAr
|
|
|
131
131
|
const postScripts = scripts.postMapping;
|
|
132
132
|
try {
|
|
133
133
|
for (let x = 0; x < postScripts.length; x++) {
|
|
134
|
-
const result = await scriptController.executeScript(postScripts[x], record, null, clientConfig.clientId);
|
|
134
|
+
const result = await scriptController.executeScript(postScripts[x], record, null, clientConfig.clientId, globalScriptParams);
|
|
135
135
|
}
|
|
136
136
|
} catch (error) {
|
|
137
137
|
throw error;
|
|
@@ -140,14 +140,14 @@ async function handleRecord(formConfig, record, mapping, clientConfig, includeAr
|
|
|
140
140
|
return record;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
async function getRecord(formConfig, clientConfig, id, mapping, includeString) {
|
|
143
|
+
async function getRecord(formConfig, clientConfig, id, mapping, includeString, globalScriptParams) {
|
|
144
144
|
const query = `'1'=\"${id}\"`;
|
|
145
|
-
const returnValue = await queryRecords(formConfig, clientConfig, query, mapping, null, null, includeString);
|
|
145
|
+
const returnValue = await queryRecords(formConfig, clientConfig, query, mapping, null, null, includeString, globalScriptParams);
|
|
146
146
|
const record = returnValue.data[0];
|
|
147
147
|
return {data: record};
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
async function updateRecord(formConfig, clientConfig, id, recordData) {
|
|
150
|
+
async function updateRecord(formConfig, clientConfig, id, recordData, globalScriptParams) {
|
|
151
151
|
const allScripts = clientConfig[formConfig.configName].scripts;
|
|
152
152
|
let scripts
|
|
153
153
|
if (allScripts) {
|
|
@@ -157,7 +157,7 @@ async function updateRecord(formConfig, clientConfig, id, recordData) {
|
|
|
157
157
|
|
|
158
158
|
//run preScripts
|
|
159
159
|
if (scripts && scripts.preMapping) {
|
|
160
|
-
await scriptController.runScripts(scripts.preMapping, recordData, clientConfig.clientId);
|
|
160
|
+
await scriptController.runScripts(scripts.preMapping, recordData, clientConfig.clientId, globalScriptParams);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
const mapping = config.getMapping(formConfig.configName);
|
|
@@ -166,25 +166,25 @@ async function updateRecord(formConfig, clientConfig, id, recordData) {
|
|
|
166
166
|
|
|
167
167
|
//run postMapping
|
|
168
168
|
if (scripts && scripts.postMapping) {
|
|
169
|
-
await scriptController.runScripts(scripts.postMapping, recordData, clientConfig.clientId);
|
|
169
|
+
await scriptController.runScripts(scripts.postMapping, recordData, clientConfig.clientId, globalScriptParams);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
const update = await arquery.updateEntry(formConfig.formName, id, recordData);
|
|
173
173
|
|
|
174
174
|
//run afterExecution
|
|
175
175
|
if (scripts && scripts.afterExecution) {
|
|
176
|
-
await scriptController.runScripts(scripts.afterExecution, recordData, clientConfig.clientId);
|
|
176
|
+
await scriptController.runScripts(scripts.afterExecution, recordData, clientConfig.clientId, globalScriptParams);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
return update;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
function searchRecords(formConfig, clientConfig, searchString, fields, options, includeString) {
|
|
182
|
+
function searchRecords(formConfig, clientConfig, searchString, fields, options, includeString, globalScriptParams) {
|
|
183
183
|
const mapping = config.getMapping(formConfig.configName);
|
|
184
184
|
const mappedString = searchUtil.applyMapping(searchString, mapping);
|
|
185
185
|
const customFields = searchUtil.getCustomFields(clientConfig[formConfig.configName].fields, mapping, fields);
|
|
186
186
|
options.sort = searchUtil.applySortMapping(options.sort, mapping);
|
|
187
|
-
return queryRecords(formConfig, clientConfig, mappedString, null, customFields, options, includeString);
|
|
187
|
+
return queryRecords(formConfig, clientConfig, mappedString, null, customFields, options, includeString, globalScriptParams);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
module.exports = {
|
|
@@ -72,7 +72,7 @@ async function getRelatedObjects(req, res, next) {
|
|
|
72
72
|
for (x=0; x < cmdbObjectArray.length; x++) {
|
|
73
73
|
const ciId = cmdbObjectArray[x];
|
|
74
74
|
log.debug('searchCMDBObject', ciId);
|
|
75
|
-
const cmdbObject = await cmdbObjectController.getCmdbObject(clientConfig, ciId);
|
|
75
|
+
const cmdbObject = await cmdbObjectController.getCmdbObject(clientConfig, ciId, undefined, undefined, req.globalScriptParams);
|
|
76
76
|
if (cmdbObjects !== null && cmdbObjects !== undefined && cmdbObject && cmdbObject.data) {
|
|
77
77
|
cmdbObjects.push(cmdbObject.data);
|
|
78
78
|
}
|
|
@@ -88,7 +88,7 @@ async function getRelatedObjects(req, res, next) {
|
|
|
88
88
|
const id = incidentArray[x];
|
|
89
89
|
log.debug('searchIncident', id);
|
|
90
90
|
const ticketConfig = config.ticketConfig["incidents"];
|
|
91
|
-
const result = await ticketController.getTicket(ticketConfig, clientConfig, id);
|
|
91
|
+
const result = await ticketController.getTicket(ticketConfig, clientConfig, id, undefined, undefined, req.globalScriptParams);
|
|
92
92
|
if (result && result.data) {
|
|
93
93
|
incidents.push(result.data);
|
|
94
94
|
}
|
|
@@ -104,7 +104,7 @@ async function getRelatedObjects(req, res, next) {
|
|
|
104
104
|
const id = ticketIdArray[x];
|
|
105
105
|
log.debug('searchWorkOrder', id);
|
|
106
106
|
const ticketConfig = config.ticketConfig["workorders"];
|
|
107
|
-
const result = await ticketController.getTicket(ticketConfig, clientConfig, id)
|
|
107
|
+
const result = await ticketController.getTicket(ticketConfig, clientConfig, id, undefined, undefined, req.globalScriptParams)
|
|
108
108
|
if (result && result.data) {
|
|
109
109
|
tickets.push(result.data);
|
|
110
110
|
}
|
|
@@ -120,7 +120,7 @@ async function getRelatedObjects(req, res, next) {
|
|
|
120
120
|
const id = ticketIdArray[x];
|
|
121
121
|
log.debug('searchProblem', id);
|
|
122
122
|
const ticketConfig = config.ticketConfig["problems"];
|
|
123
|
-
const result = await ticketController.getTicket(ticketConfig, clientConfig, id)
|
|
123
|
+
const result = await ticketController.getTicket(ticketConfig, clientConfig, id, undefined, undefined, req.globalScriptParams)
|
|
124
124
|
if (result && result.data) {
|
|
125
125
|
tickets.push(result.data);
|
|
126
126
|
}
|
|
@@ -136,7 +136,7 @@ async function getRelatedObjects(req, res, next) {
|
|
|
136
136
|
const id = ticketIdArray[x];
|
|
137
137
|
log.debug('searchChange', id);
|
|
138
138
|
const ticketConfig = config.ticketConfig["changes"];
|
|
139
|
-
const result = await ticketController.getTicket(ticketConfig, clientConfig, id)
|
|
139
|
+
const result = await ticketController.getTicket(ticketConfig, clientConfig, id, undefined, undefined, req.globalScriptParams)
|
|
140
140
|
if (result && result.data) {
|
|
141
141
|
tickets.push(result.data);
|
|
142
142
|
}
|
|
@@ -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, clientId) {
|
|
48
|
+
async function executeScriptInternal(scriptId, requestData, params, executedByScript, clientId, globalScriptParams) {
|
|
49
49
|
|
|
50
50
|
const code = await getGlobalScript(scriptId);
|
|
51
51
|
|
|
@@ -53,14 +53,14 @@ 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, clientId, scriptId);
|
|
56
|
+
return executeCode(code, requestData, params, null, executedByScript, clientId, scriptId, globalScriptParams);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
async function executeScript(scriptId, requestData, params, clientId) {
|
|
60
|
-
return executeScriptInternal(scriptId, requestData, params, false, clientId)
|
|
59
|
+
async function executeScript(scriptId, requestData, params, clientId, globalScriptParams) {
|
|
60
|
+
return executeScriptInternal(scriptId, requestData, params, false, clientId, globalScriptParams)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
async function executeCode(code, requestData, params, logStream, executedByScript, clientId, scriptId) {
|
|
63
|
+
async function executeCode(code, requestData, params, logStream, executedByScript, clientId, scriptId, globalScriptParams) {
|
|
64
64
|
const log = require('@manyos/logger').setupLog('SMILEcatalog_Script_' + scriptId);
|
|
65
65
|
//todo should only be added once
|
|
66
66
|
/*if (logStream) {
|
|
@@ -70,7 +70,7 @@ async function executeCode(code, requestData, params, logStream, executedByScrip
|
|
|
70
70
|
//try to set user data for sandbox
|
|
71
71
|
|
|
72
72
|
async function executeScriptByScript(scriptId, requestData, params) {
|
|
73
|
-
return executeScriptInternal(scriptId, requestData, params, true, clientId)
|
|
73
|
+
return executeScriptInternal(scriptId, requestData, params, true, clientId, globalScriptParams)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const sandbox = {
|
|
@@ -80,6 +80,7 @@ async function executeCode(code, requestData, params, logStream, executedByScrip
|
|
|
80
80
|
log,
|
|
81
81
|
clientId,
|
|
82
82
|
script:executeScriptByScript,
|
|
83
|
+
globalScriptParams,
|
|
83
84
|
env: process.env,
|
|
84
85
|
fetch:fetch
|
|
85
86
|
};
|
|
@@ -102,7 +103,7 @@ async function executeCode(code, requestData, params, logStream, executedByScrip
|
|
|
102
103
|
try {
|
|
103
104
|
const result = await vm.run(
|
|
104
105
|
`return new Promise(async function(resolve, reject) {try {${code}} catch (error) {reject(error);}});`,
|
|
105
|
-
'vm.js');
|
|
106
|
+
scriptId || 'vm.js');
|
|
106
107
|
log.debug('script ended', result);
|
|
107
108
|
return result;
|
|
108
109
|
} catch (e) {
|
|
@@ -245,10 +246,10 @@ async function getGlobalScripts() {
|
|
|
245
246
|
return getScripts(path);
|
|
246
247
|
}
|
|
247
248
|
|
|
248
|
-
async function runScripts(scripts, data, clientId) {
|
|
249
|
+
async function runScripts(scripts, data, clientId, globalScriptParams) {
|
|
249
250
|
try {
|
|
250
251
|
for (let x = 0; x < scripts.length; x++) {
|
|
251
|
-
await executeScript(scripts[x], data, undefined, clientId);
|
|
252
|
+
await executeScript(scripts[x], data, undefined, clientId, globalScriptParams);
|
|
252
253
|
}
|
|
253
254
|
} catch (error) {
|
|
254
255
|
throw error;
|
|
@@ -11,19 +11,19 @@ const scriptController = require('./scriptController');
|
|
|
11
11
|
|
|
12
12
|
const taskCache = new CacheService(process.env.CACHETTL_TASK || 0); // Create a new cache service instance
|
|
13
13
|
|
|
14
|
-
function getTasks(config, category) {
|
|
14
|
+
function getTasks(config, category, globalScriptParams) {
|
|
15
15
|
let query = '1=1';
|
|
16
16
|
if (category)
|
|
17
17
|
query = `'Category' = \"${category}\"`;
|
|
18
|
-
return queryTasks(config, query);
|
|
18
|
+
return queryTasks(config, query, globalScriptParams);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function getTasksByRootRequest(config, rootRequestId, rootRequestForm) {
|
|
21
|
+
function getTasksByRootRequest(config, rootRequestId, rootRequestForm, globalScriptParams) {
|
|
22
22
|
const query = `'RootRequestID' = \"${rootRequestId}\" AND 'RootRequestFormName' = \"${rootRequestForm}\"`;
|
|
23
|
-
return queryTasks(config, query);
|
|
23
|
+
return queryTasks(config, query, globalScriptParams);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
async function createTask(clientConfig, rootForm, rootRequestId, taskData, createTaskFlow) {
|
|
26
|
+
async function createTask(clientConfig, rootForm, rootRequestId, taskData, createTaskFlow, globalScriptParams) {
|
|
27
27
|
const scripts = clientConfig.task.scripts.POST;
|
|
28
28
|
const fields = clientConfig.task.fields;
|
|
29
29
|
|
|
@@ -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, clientConfig.clientId);
|
|
73
|
+
await scriptController.runScripts(scripts.preMapping, taskData, clientConfig.clientId, globalScriptParams);
|
|
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, clientConfig.clientId);
|
|
80
|
+
await scriptController.runScripts(scripts.postMapping, taskData, clientConfig.clientId, globalScriptParams);
|
|
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, clientConfig.clientId);
|
|
87
|
+
await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId, globalScriptParams);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
log.debug('Create Task Result', taskResult);
|
|
@@ -113,7 +113,7 @@ async function createTask(clientConfig, rootForm, rootRequestId, taskData, creat
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
//Todo make dynamic
|
|
116
|
-
async function createWorklog(clientConfig, taskId, summary, text, attachment) {
|
|
116
|
+
async function createWorklog(clientConfig, taskId, summary, text, attachment, globalScriptParams) {
|
|
117
117
|
const task = await getTask(clientConfig,taskId)
|
|
118
118
|
const fields = clientConfig.taskWorklog.fields;
|
|
119
119
|
|
|
@@ -140,28 +140,28 @@ 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, clientConfig.clientId);
|
|
143
|
+
await scriptController.runScripts(scripts.preMapping, data, clientConfig.clientId, globalScriptParams);
|
|
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, clientConfig.clientId);
|
|
150
|
+
await scriptController.runScripts(scripts.postMapping, data, clientConfig.clientId, globalScriptParams);
|
|
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, clientConfig.clientId);
|
|
157
|
+
await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId, globalScriptParams);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
return(result);
|
|
161
161
|
//todo add attachment handling
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
function queryTasks(clientConfig, query) {
|
|
164
|
+
function queryTasks(clientConfig, query, globalScriptParams) {
|
|
165
165
|
const scripts = clientConfig.task.scripts.GET;
|
|
166
166
|
|
|
167
167
|
const key = clientConfig.task.basequery + clientConfig.task.fields.toString() + query;
|
|
@@ -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, clientConfig.clientId);
|
|
199
|
+
await scriptController.runScripts(scripts.preMapping, element, clientConfig.clientId, globalScriptParams);
|
|
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, clientConfig.clientId);
|
|
215
|
+
await scriptController.runScripts(scripts.postMapping, element, clientConfig.clientId, globalScriptParams);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
return ({
|
|
@@ -229,7 +229,7 @@ function queryTasks(clientConfig, query) {
|
|
|
229
229
|
})
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
async function queryWorklogs(clientConfig, query, mapping) {
|
|
232
|
+
async function queryWorklogs(clientConfig, query, mapping, globalScriptParams) {
|
|
233
233
|
|
|
234
234
|
const scripts = clientConfig.taskWorklog.scripts.GET;
|
|
235
235
|
|
|
@@ -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, clientConfig.clientId);
|
|
255
|
+
await scriptController.runScripts(scripts.preMapping, element, clientConfig.clientId, globalScriptParams);
|
|
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, clientConfig.clientId);
|
|
271
|
+
await scriptController.runScripts(scripts.postMapping, element, clientConfig.clientId, globalScriptParams);
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
return {
|
|
@@ -280,33 +280,34 @@ async function queryWorklogs(clientConfig, query, mapping) {
|
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
async function getTask(clientConfig, id) {
|
|
283
|
+
async function getTask(clientConfig, id, globalScriptParams) {
|
|
284
284
|
const query = `'Task ID'=\"${id}\"`;
|
|
285
|
-
const tasks = await queryTasks(clientConfig, query);
|
|
285
|
+
const tasks = await queryTasks(clientConfig, query, globalScriptParams);
|
|
286
286
|
return tasks.data[0];
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
async function getTaskByRootRequest(config, rootRequestId, taskId) {
|
|
289
|
+
async function getTaskByRootRequest(config, rootRequestId, taskId, globalScriptParams) {
|
|
290
290
|
const query = `'Task ID'=\"${taskId}\" AND 'RootRequestID' = \"${rootRequestId}\"`;
|
|
291
|
-
const returnValue = await queryTasks(config, query);
|
|
291
|
+
const returnValue = await queryTasks(config, query, globalScriptParams);
|
|
292
292
|
const task = returnValue.data[0];
|
|
293
293
|
return {data: task, included: returnValue.included};
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
function getTaskWorklogs(config, taskId) {
|
|
296
|
+
function getTaskWorklogs(config, taskId, globalScriptParams) {
|
|
297
297
|
const query = `'TaskOrTaskGroupID'=\"${taskId}\"`;
|
|
298
|
-
return queryWorklogs(config, query);
|
|
298
|
+
return queryWorklogs(config, query, undefined, globalScriptParams);
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
//todo add scripts an
|
|
302
|
+
async function getTaskWorklog(config, taskId, worklogId, globalScriptParams) {
|
|
302
303
|
const query = `'TaskOrTaskGroupID'=\"${taskId}\" AND 'Work Info ID'=\"${worklogId}\"`;
|
|
303
|
-
const returnValue = await queryWorklogs(config, query);
|
|
304
|
+
const returnValue = await queryWorklogs(config, query, undefined, globalScriptParams);
|
|
304
305
|
log.debug ('rtn', returnValue);
|
|
305
306
|
const worklog = returnValue.data[0];
|
|
306
307
|
return {data: worklog, included: returnValue.included};
|
|
307
308
|
}
|
|
308
309
|
|
|
309
|
-
async function updateTask(clientConfig, id, taskData) {
|
|
310
|
+
async function updateTask(clientConfig, id, taskData, globalScriptParams) {
|
|
310
311
|
const mapping = config.getMapping('task');
|
|
311
312
|
const taskConstants = clientConfig.task.constants;
|
|
312
313
|
const scripts = clientConfig.task.scripts.PUT;
|
|
@@ -314,21 +315,21 @@ async function updateTask(clientConfig, id, taskData) {
|
|
|
314
315
|
|
|
315
316
|
//run preScripts
|
|
316
317
|
if (scripts && scripts.preMapping) {
|
|
317
|
-
await scriptController.runScripts(scripts.preMapping, taskData, clientConfig.clientId);
|
|
318
|
+
await scriptController.runScripts(scripts.preMapping, taskData, clientConfig.clientId, globalScriptParams);
|
|
318
319
|
}
|
|
319
320
|
|
|
320
321
|
taskData = mappingUtil.applyMapping2Remedy(taskData, mapping, taskConstants, fields);
|
|
321
322
|
|
|
322
323
|
//run postScripts
|
|
323
324
|
if (scripts && scripts.postMapping) {
|
|
324
|
-
await scriptController.runScripts(scripts.postMapping, taskData, clientConfig.clientId);
|
|
325
|
+
await scriptController.runScripts(scripts.postMapping, taskData, clientConfig.clientId, globalScriptParams);
|
|
325
326
|
}
|
|
326
327
|
|
|
327
328
|
const result = await arquery.updateEntry('TMS:Task', id, taskData);
|
|
328
329
|
|
|
329
330
|
//run afterExecution
|
|
330
331
|
if (scripts && scripts.afterExecution) {
|
|
331
|
-
await scriptController.runScripts(scripts.afterExecution, taskData, clientConfig.clientId);
|
|
332
|
+
await scriptController.runScripts(scripts.afterExecution, taskData, clientConfig.clientId, globalScriptParams);
|
|
332
333
|
}
|
|
333
334
|
return result;
|
|
334
335
|
}
|