@manyos/smileconnect-api 1.48.0 → 1.49.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/conf/clients.json CHANGED
@@ -18,7 +18,8 @@
18
18
  "basequery": "1=2",
19
19
  "fields": [],
20
20
  "constants": [],
21
- "scripts": {}
21
+ "scripts": {},
22
+ "attachmentScripts": {}
22
23
  },
23
24
  "incident": {
24
25
  "basequery": "1=1",
@@ -32,7 +33,8 @@
32
33
  "basequery": "1=2",
33
34
  "fields": [],
34
35
  "constants": [],
35
- "scripts": {}
36
+ "scripts": {},
37
+ "attachmentScripts": {}
36
38
  },
37
39
  "person": {
38
40
  "basequery": "1=2",
@@ -50,7 +52,8 @@
50
52
  "basequery": "1=2",
51
53
  "fields": [],
52
54
  "constants": [],
53
- "scripts": {}
55
+ "scripts": {},
56
+ "attachmentScripts": {}
54
57
  },
55
58
  "supportGroup": {
56
59
  "basequery": "1=2",
@@ -74,7 +77,8 @@
74
77
  "basequery": "1=2",
75
78
  "fields": [],
76
79
  "constants": [],
77
- "scripts": {}
80
+ "scripts": {},
81
+ "attachmentScripts": {}
78
82
  },
79
83
  "task": {
80
84
  "basequery": "1=2",
@@ -86,7 +90,8 @@
86
90
  "basequery": "1=2",
87
91
  "fields": [],
88
92
  "constants": [],
89
- "scripts": {}
93
+ "scripts": {},
94
+ "attachmentScripts": {}
90
95
  },
91
96
  "flowBuilder": {
92
97
  "basequery": "1=2",
@@ -303,7 +308,14 @@
303
308
  "scripts": {
304
309
  "POST": {
305
310
  "preMapping": [
306
- "reject"
311
+ "attachi"
312
+ ]
313
+ }
314
+ },
315
+ "attachmentScripts": {
316
+ "POST": {
317
+ "preMapping": [
318
+ "attachi"
307
319
  ]
308
320
  }
309
321
  }
@@ -523,7 +535,8 @@
523
535
  }
524
536
  ],
525
537
  "basequery": "",
526
- "scripts": {}
538
+ "scripts": {},
539
+ "attachmentScripts": {}
527
540
  },
528
541
  "incidentWorklog": {
529
542
  "fields": [
@@ -545,7 +558,8 @@
545
558
  }
546
559
  ],
547
560
  "basequery": "",
548
- "scripts": {}
561
+ "scripts": {},
562
+ "attachmentScripts": {}
549
563
  },
550
564
  "problemWorklog": {
551
565
  "fields": [
@@ -567,7 +581,8 @@
567
581
  }
568
582
  ],
569
583
  "basequery": "",
570
- "scripts": {}
584
+ "scripts": {},
585
+ "attachmentScripts": {}
571
586
  },
572
587
  "task": {
573
588
  "basequery": "1=1",
@@ -636,8 +651,15 @@
636
651
  "value": "Other"
637
652
  }
638
653
  ],
639
- "basequery": "",
640
- "scripts": {}
654
+ "basequery": "1=1",
655
+ "scripts": {},
656
+ "attachmentScripts": {
657
+ "POST": {
658
+ "preMapping": [
659
+ "attachi"
660
+ ]
661
+ }
662
+ }
641
663
  },
642
664
  "flowBuilder": {
643
665
  "constants": [
@@ -828,7 +850,8 @@
828
850
  }
829
851
  ],
830
852
  "basequery": "",
831
- "scripts": {}
853
+ "scripts": {},
854
+ "attachmentScripts": {}
832
855
  },
833
856
  "workOrder": {
834
857
  "fields": [
@@ -1004,7 +1027,8 @@
1004
1027
  }
1005
1028
  ],
1006
1029
  "basequery": "",
1007
- "scripts": {}
1030
+ "scripts": {},
1031
+ "attachmentScripts": {}
1008
1032
  },
1009
1033
  "incidentWorklog": {
1010
1034
  "fields": [
@@ -1026,7 +1050,8 @@
1026
1050
  }
1027
1051
  ],
1028
1052
  "basequery": "",
1029
- "scripts": {}
1053
+ "scripts": {},
1054
+ "attachmentScripts": {}
1030
1055
  },
1031
1056
  "problemWorklog": {
1032
1057
  "fields": [
@@ -1048,7 +1073,8 @@
1048
1073
  }
1049
1074
  ],
1050
1075
  "basequery": "",
1051
- "scripts": {}
1076
+ "scripts": {},
1077
+ "attachmentScripts": {}
1052
1078
  },
1053
1079
  "task": {
1054
1080
  "basequery": "1=1",
@@ -1119,7 +1145,8 @@
1119
1145
  }
1120
1146
  ],
1121
1147
  "basequery": "",
1122
- "scripts": {}
1148
+ "scripts": {},
1149
+ "attachmentScripts": {}
1123
1150
  },
1124
1151
  "flowBuilder": {
1125
1152
  "constants": [
@@ -1276,7 +1303,8 @@
1276
1303
  }
1277
1304
  ],
1278
1305
  "basequery": "",
1279
- "scripts": {}
1306
+ "scripts": {},
1307
+ "attachmentScripts": {}
1280
1308
  },
1281
1309
  "workOrder": {
1282
1310
  "basequery": "",
@@ -1453,7 +1481,8 @@
1453
1481
  }
1454
1482
  ],
1455
1483
  "basequery": "",
1456
- "scripts": {}
1484
+ "scripts": {},
1485
+ "attachmentScripts": {}
1457
1486
  },
1458
1487
  "incidentWorklog": {
1459
1488
  "fields": [
@@ -1475,7 +1504,8 @@
1475
1504
  }
1476
1505
  ],
1477
1506
  "basequery": "",
1478
- "scripts": {}
1507
+ "scripts": {},
1508
+ "attachmentScripts": {}
1479
1509
  },
1480
1510
  "problemWorklog": {
1481
1511
  "fields": [
@@ -1497,7 +1527,8 @@
1497
1527
  }
1498
1528
  ],
1499
1529
  "basequery": "",
1500
- "scripts": {}
1530
+ "scripts": {},
1531
+ "attachmentScripts": {}
1501
1532
  },
1502
1533
  "task": {
1503
1534
  "basequery": "1=1",
@@ -1568,7 +1599,8 @@
1568
1599
  }
1569
1600
  ],
1570
1601
  "basequery": "",
1571
- "scripts": {}
1602
+ "scripts": {},
1603
+ "attachmentScripts": {}
1572
1604
  },
1573
1605
  "flowBuilder": {
1574
1606
  "constants": [
@@ -1731,7 +1763,8 @@
1731
1763
  }
1732
1764
  ],
1733
1765
  "basequery": "",
1734
- "scripts": {}
1766
+ "scripts": {},
1767
+ "attachmentScripts": {}
1735
1768
  },
1736
1769
  "workOrder": {
1737
1770
  "basequery": "",
@@ -1907,7 +1940,8 @@
1907
1940
  }
1908
1941
  ],
1909
1942
  "basequery": "",
1910
- "scripts": {}
1943
+ "scripts": {},
1944
+ "attachmentScripts": {}
1911
1945
  },
1912
1946
  "incidentWorklog": {
1913
1947
  "fields": [
@@ -1929,7 +1963,8 @@
1929
1963
  }
1930
1964
  ],
1931
1965
  "basequery": "",
1932
- "scripts": {}
1966
+ "scripts": {},
1967
+ "attachmentScripts": {}
1933
1968
  },
1934
1969
  "problemWorklog": {
1935
1970
  "fields": [
@@ -1951,7 +1986,8 @@
1951
1986
  }
1952
1987
  ],
1953
1988
  "basequery": "",
1954
- "scripts": {}
1989
+ "scripts": {},
1990
+ "attachmentScripts": {}
1955
1991
  },
1956
1992
  "task": {
1957
1993
  "basequery": "1=1",
@@ -2022,7 +2058,8 @@
2022
2058
  }
2023
2059
  ],
2024
2060
  "basequery": "",
2025
- "scripts": {}
2061
+ "scripts": {},
2062
+ "attachmentScripts": {}
2026
2063
  },
2027
2064
  "flowBuilder": {
2028
2065
  "constants": [
@@ -2185,7 +2222,8 @@
2185
2222
  }
2186
2223
  ],
2187
2224
  "basequery": "",
2188
- "scripts": {}
2225
+ "scripts": {},
2226
+ "attachmentScripts": {}
2189
2227
  },
2190
2228
  "workOrder": {
2191
2229
  "basequery": "",
@@ -2361,7 +2399,8 @@
2361
2399
  }
2362
2400
  ],
2363
2401
  "basequery": "",
2364
- "scripts": {}
2402
+ "scripts": {},
2403
+ "attachmentScripts": {}
2365
2404
  },
2366
2405
  "incidentWorklog": {
2367
2406
  "fields": [
@@ -2383,7 +2422,8 @@
2383
2422
  }
2384
2423
  ],
2385
2424
  "basequery": "",
2386
- "scripts": {}
2425
+ "scripts": {},
2426
+ "attachmentScripts": {}
2387
2427
  },
2388
2428
  "problemWorklog": {
2389
2429
  "fields": [
@@ -2405,7 +2445,8 @@
2405
2445
  }
2406
2446
  ],
2407
2447
  "basequery": "",
2408
- "scripts": {}
2448
+ "scripts": {},
2449
+ "attachmentScripts": {}
2409
2450
  },
2410
2451
  "task": {
2411
2452
  "basequery": "1=1",
@@ -2476,7 +2517,8 @@
2476
2517
  }
2477
2518
  ],
2478
2519
  "basequery": "",
2479
- "scripts": {}
2520
+ "scripts": {},
2521
+ "attachmentScripts": {}
2480
2522
  },
2481
2523
  "flowBuilder": {
2482
2524
  "constants": [
@@ -0,0 +1,2 @@
1
+ log.debug('globalScriptParams', globalScriptParams)
2
+ log.debug('file', requestData)
@@ -62,7 +62,7 @@ async function executeScript(scriptId, requestData, params, clientId, globalScri
62
62
  }
63
63
 
64
64
  async function executeCode(code, requestData, params, logStream, executedByScript, clientId, scriptId, globalScriptParams) {
65
- const log = require('@manyos/logger').setupLog('SMILEcatalog_Script_' + scriptId);
65
+ const log = require('@manyos/logger').setupLog('SMILEconnect_Script_' + scriptId);
66
66
  //todo should only be added once
67
67
  /*if (logStream) {
68
68
  log.addStream(logStream);
@@ -104,7 +104,7 @@ async function executeCode(code, requestData, params, logStream, executedByScrip
104
104
  //todo Add timeout
105
105
  try {
106
106
  const result = await vm.run(
107
- `return new Promise(async function(resolve, reject) {try {${code}} catch (error) {reject(error);}});`,
107
+ `return new Promise(async function(resolve, reject) {try {{${code}}resolve()} catch (error) {reject(error);}});`,
108
108
  scriptId || 'vm.js');
109
109
  log.debug('script ended', result);
110
110
  return result;
@@ -445,14 +445,41 @@ async function updateTask(clientConfig, id, taskData, globalScriptParams) {
445
445
  return result;
446
446
  }
447
447
 
448
- function setWorklogAttachment(clientConfig, worklogId, file, attachmentId) {
448
+ async function setWorklogAttachment(clientConfig, worklogId, file, attachmentId, globalScriptParams) {
449
+ const scripts = clientConfig.taskWorklog.attachmentScripts.POST;
450
+ if (!globalScriptParams) {
451
+ globalScriptParams = {}
452
+ }
453
+ globalScriptParams.isAttachment = true
454
+ globalScriptParams.attachmentId = attachmentId
455
+ //run preScripts
456
+ if (scripts && scripts.preMapping) {
457
+ await scriptController.runScripts(scripts.preMapping, file, clientConfig.clientId, globalScriptParams);
458
+ }
449
459
  const fieldId = getAttachmentFieldId(attachmentId);
450
- return arquery.setAttachment(CONSTANTS.FORM_TASK_WORKLOG, worklogId, fieldId, file);
460
+ const result = await arquery.setAttachment(CONSTANTS.FORM_TASK_WORKLOG, worklogId, fieldId, file);
461
+
462
+ return result
451
463
  }
452
464
 
453
- function getWorklogAttachment(clientConfig, worklogId, attachmentId) {
465
+ async function getWorklogAttachment(clientConfig, worklogId, attachmentId, globalScriptParams) {
466
+ const scripts = clientConfig.taskWorklog.attachmentScripts.GET;
467
+ if (!globalScriptParams) {
468
+ globalScriptParams = {}
469
+ }
470
+ globalScriptParams.isAttachment = true
471
+ globalScriptParams.attachmentId = attachmentId
472
+ //run preScripts
473
+ if (scripts && scripts.preMapping) {
474
+ await scriptController.runScripts(scripts.preMapping, undefined, clientConfig.clientId, globalScriptParams);
475
+ }
454
476
  const fieldId = getAttachmentFieldId(attachmentId);
455
- return arquery.getAttachment(CONSTANTS.FORM_TASK_WORKLOG, worklogId, fieldId);
477
+ const result = await arquery.getAttachment(CONSTANTS.FORM_TASK_WORKLOG, worklogId, fieldId);
478
+ //run afterExecution
479
+ if (scripts && scripts.afterExecution) {
480
+ await scriptController.runScripts(scripts.afterExecution, result, clientConfig.clientId, globalScriptParams);
481
+ }
482
+ return result
456
483
  }
457
484
 
458
485
  function getAttachmentFieldId(attachmentId) {
@@ -84,14 +84,43 @@ async function createWorklog(ticketConfig, clientConfig, ticketId, data, globalS
84
84
  return result;
85
85
  }
86
86
 
87
- function setWorklogAttachment(ticketConfig, clientConfig, worklogId, file, attachmentId) {
87
+ async function setWorklogAttachment(ticketConfig, clientConfig, worklogId, file, attachmentId, globalScriptParams) {
88
+ const scripts = clientConfig[ticketConfig.requestTypeWorkLog].attachmentScripts.POST;
89
+ if (!globalScriptParams) {
90
+ globalScriptParams = {}
91
+ }
92
+ globalScriptParams.isAttachment = true
93
+ globalScriptParams.attachmentId = attachmentId
94
+ //run preScripts
95
+ if (scripts && scripts.preMapping) {
96
+ await scriptController.runScripts(scripts.preMapping, file, clientConfig.clientId, globalScriptParams);
97
+ }
88
98
  const fieldId = getAttachmentFieldId(attachmentId);
89
- return arquery.setAttachment(ticketConfig.forms.workLog, worklogId, fieldId, file);
99
+ const result = await arquery.setAttachment(ticketConfig.forms.workLog, worklogId, fieldId, file);
100
+ //run afterExecution
101
+ if (scripts && scripts.afterExecution) {
102
+ await scriptController.runScripts(scripts.afterExecution, file, clientConfig.clientId, globalScriptParams);
103
+ }
104
+ return result
90
105
  }
91
106
 
92
- function getWorklogAttachment(ticketConfig, clientConfig, worklogId, attachmentId) {
107
+ async function getWorklogAttachment(ticketConfig, clientConfig, worklogId, attachmentId, globalScriptParams) {
108
+ const scripts = clientConfig[ticketConfig.requestTypeWorkLog].attachmentScripts.GET;
109
+ if (!globalScriptParams) {
110
+ globalScriptParams = {}
111
+ }
112
+ globalScriptParams.isAttachment = true
113
+ globalScriptParams.attachmentId = attachmentId
114
+ //run preScripts
115
+ if (scripts && scripts.preMapping) {
116
+ await scriptController.runScripts(scripts.preMapping, undefined, clientConfig.clientId, globalScriptParams);
117
+ }
93
118
  const fieldId = getAttachmentFieldId(attachmentId);
94
- return arquery.getAttachment(ticketConfig.forms.workLog, worklogId, fieldId);
119
+ const result = await arquery.getAttachment(ticketConfig.forms.workLog, worklogId, fieldId);
120
+ if (scripts && scripts.afterExecution) {
121
+ await scriptController.runScripts(scripts.afterExecution, result, clientConfig.clientId, globalScriptParams);
122
+ }
123
+ return result
95
124
  }
96
125
 
97
126
  function getAttachmentFieldId(attachmentId) {
package/docs/releases.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## API
4
4
 
5
+ ### 1.49.0 - 04.11.21
6
+ Add attachmentScripts to Worklogs
7
+
5
8
  ### 1.48.0 - 03.11.21
6
9
  Add parameter SSO_USERNAME_ATTRIBUTE to config.
7
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.48.0",
3
+ "version": "1.49.0",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -287,7 +287,7 @@ module.exports = (function () {
287
287
  };
288
288
  } else {
289
289
  //fileContent = JSON.parse(file.data);
290
- task.setWorklogAttachment(req.user.config, worklogId, file, attachmentId).then(
290
+ task.setWorklogAttachment(req.user.config, worklogId, file, attachmentId, req.globalScriptParams).then(
291
291
  uploadResult => {
292
292
  req.result = uploadResult;
293
293
  next();
@@ -318,7 +318,7 @@ module.exports = (function () {
318
318
  );
319
319
 
320
320
  //fileContent = JSON.parse(file.data);
321
- task.getWorklogAttachment(req.user.config, worklogId, attachmentId).then(
321
+ task.getWorklogAttachment(req.user.config, worklogId, attachmentId, req.globalScriptParams).then(
322
322
  downloadResult => {
323
323
  req.downloadResult = downloadResult;
324
324
  next();
@@ -91,7 +91,7 @@ module.exports = (function() {
91
91
  };
92
92
  } else {
93
93
  //fileContent = JSON.parse(file.data);
94
- ticketWorkLogController.setWorklogAttachment(req.ticketConfig, req.user.config, worklogId, file, attachmentId).then(
94
+ ticketWorkLogController.setWorklogAttachment(req.ticketConfig, req.user.config, worklogId, file, attachmentId, req.globalScriptParams).then(
95
95
  uploadResult => {
96
96
  req.result = uploadResult;
97
97
  next();
@@ -123,7 +123,7 @@ module.exports = (function() {
123
123
  );
124
124
 
125
125
  //fileContent = JSON.parse(file.data);
126
- ticketWorkLogController.getWorklogAttachment(req.ticketConfig, req.user.config, worklogId, attachmentId).then(
126
+ ticketWorkLogController.getWorklogAttachment(req.ticketConfig, req.user.config, worklogId, attachmentId, req.globalScriptParams).then(
127
127
  downloadResult => {
128
128
  req.downloadResult = downloadResult;
129
129
  next();
package/util/config.js CHANGED
@@ -261,6 +261,10 @@ function checkClientConfig(client) {
261
261
  clientConfig[key].scripts = {};
262
262
  log.info('add scripts', key);
263
263
  }
264
+ if (key.endsWith('Worklog') && !clientConfig[key].attachmentScripts) {
265
+ clientConfig[key].attachmentScripts = {};
266
+ log.info('add attachmentScripts', key);
267
+ }
264
268
  }
265
269
  });
266
270
  //add too less