@sonisoft/now-sdk-ext-core 2.2.1 → 2.4.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/dist/comm/http/RequestHandler.js +7 -11
- package/dist/comm/http/RequestHandler.js.map +1 -1
- package/dist/comm/http/TableAPIRequest.js +3 -10
- package/dist/comm/http/TableAPIRequest.js.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/sn/BackgroundScriptExecutor.d.ts +34 -0
- package/dist/sn/BackgroundScriptExecutor.js +96 -0
- package/dist/sn/BackgroundScriptExecutor.js.map +1 -1
- package/dist/sn/application/ApplicationManager.d.ts +58 -1
- package/dist/sn/application/ApplicationManager.js +202 -11
- package/dist/sn/application/ApplicationManager.js.map +1 -1
- package/dist/sn/application/StoreApplicationModels.d.ts +99 -0
- package/dist/sn/application/StoreApplicationModels.js +2 -0
- package/dist/sn/application/StoreApplicationModels.js.map +1 -0
- package/dist/sn/attachment/AttachmentManager.d.ts +32 -0
- package/dist/sn/attachment/AttachmentManager.js +87 -0
- package/dist/sn/attachment/AttachmentManager.js.map +1 -0
- package/dist/sn/attachment/AttachmentModels.d.ts +28 -0
- package/dist/sn/attachment/AttachmentModels.js +2 -0
- package/dist/sn/attachment/AttachmentModels.js.map +1 -0
- package/dist/sn/batch/BatchModels.d.ts +90 -0
- package/dist/sn/batch/BatchModels.js +5 -0
- package/dist/sn/batch/BatchModels.js.map +1 -0
- package/dist/sn/batch/BatchOperations.d.ts +40 -0
- package/dist/sn/batch/BatchOperations.js +169 -0
- package/dist/sn/batch/BatchOperations.js.map +1 -0
- package/dist/sn/schema/SchemaDiscovery.d.ts +68 -0
- package/dist/sn/schema/SchemaDiscovery.js +346 -0
- package/dist/sn/schema/SchemaDiscovery.js.map +1 -0
- package/dist/sn/schema/SchemaModels.d.ts +277 -0
- package/dist/sn/schema/SchemaModels.js +5 -0
- package/dist/sn/schema/SchemaModels.js.map +1 -0
- package/dist/sn/scope/ScopeManager.d.ts +51 -0
- package/dist/sn/scope/ScopeManager.js +177 -0
- package/dist/sn/scope/ScopeManager.js.map +1 -0
- package/dist/sn/scope/ScopeModels.d.ts +66 -0
- package/dist/sn/scope/ScopeModels.js +5 -0
- package/dist/sn/scope/ScopeModels.js.map +1 -0
- package/dist/sn/scriptsync/ScriptSync.d.ts +38 -0
- package/dist/sn/scriptsync/ScriptSync.js +266 -0
- package/dist/sn/scriptsync/ScriptSync.js.map +1 -0
- package/dist/sn/scriptsync/ScriptSyncModels.d.ts +55 -0
- package/dist/sn/scriptsync/ScriptSyncModels.js +8 -0
- package/dist/sn/scriptsync/ScriptSyncModels.js.map +1 -0
- package/dist/sn/scriptsync/ScriptWatcher.d.ts +30 -0
- package/dist/sn/scriptsync/ScriptWatcher.js +74 -0
- package/dist/sn/scriptsync/ScriptWatcher.js.map +1 -0
- package/dist/sn/task/TaskModels.d.ts +85 -0
- package/dist/sn/task/TaskModels.js +5 -0
- package/dist/sn/task/TaskModels.js.map +1 -0
- package/dist/sn/task/TaskOperations.d.ts +63 -0
- package/dist/sn/task/TaskOperations.js +195 -0
- package/dist/sn/task/TaskOperations.js.map +1 -0
- package/dist/sn/updateset/UpdateSetManager.d.ts +78 -0
- package/dist/sn/updateset/UpdateSetManager.js +391 -0
- package/dist/sn/updateset/UpdateSetManager.js.map +1 -0
- package/dist/sn/updateset/UpdateSetModels.d.ts +177 -0
- package/dist/sn/updateset/UpdateSetModels.js +5 -0
- package/dist/sn/updateset/UpdateSetModels.js.map +1 -0
- package/dist/sn/workflow/WorkflowManager.d.ts +81 -0
- package/dist/sn/workflow/WorkflowManager.js +388 -0
- package/dist/sn/workflow/WorkflowManager.js.map +1 -0
- package/dist/sn/workflow/WorkflowModels.d.ts +242 -0
- package/dist/sn/workflow/WorkflowModels.js +5 -0
- package/dist/sn/workflow/WorkflowModels.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface ScriptTypeConfig {
|
|
2
|
+
table: string;
|
|
3
|
+
label: string;
|
|
4
|
+
nameField: string;
|
|
5
|
+
scriptField: string;
|
|
6
|
+
extension: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const SCRIPT_TYPES: Record<string, ScriptTypeConfig>;
|
|
9
|
+
export interface SyncScriptOptions {
|
|
10
|
+
scriptName: string;
|
|
11
|
+
scriptType: string;
|
|
12
|
+
filePath: string;
|
|
13
|
+
direction?: 'push' | 'pull';
|
|
14
|
+
}
|
|
15
|
+
export interface SyncResult {
|
|
16
|
+
scriptName: string;
|
|
17
|
+
scriptType: string;
|
|
18
|
+
filePath: string;
|
|
19
|
+
direction: 'push' | 'pull';
|
|
20
|
+
success: boolean;
|
|
21
|
+
sysId?: string;
|
|
22
|
+
message: string;
|
|
23
|
+
error?: string;
|
|
24
|
+
timestamp: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SyncAllOptions {
|
|
27
|
+
directory: string;
|
|
28
|
+
scriptTypes?: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface SyncAllResult {
|
|
31
|
+
directory: string;
|
|
32
|
+
scriptTypes: string[];
|
|
33
|
+
totalFiles: number;
|
|
34
|
+
synced: number;
|
|
35
|
+
failed: number;
|
|
36
|
+
scripts: SyncResult[];
|
|
37
|
+
timestamp: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ParsedFileName {
|
|
40
|
+
isValid: boolean;
|
|
41
|
+
scriptName?: string;
|
|
42
|
+
scriptType?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ScriptRecord {
|
|
45
|
+
sys_id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
script: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
export interface ScriptRecordResponse {
|
|
51
|
+
result: ScriptRecord;
|
|
52
|
+
}
|
|
53
|
+
export interface ScriptRecordListResponse {
|
|
54
|
+
result: ScriptRecord[];
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const SCRIPT_TYPES = {
|
|
2
|
+
sys_script_include: { table: 'sys_script_include', label: 'Script Include', nameField: 'name', scriptField: 'script', extension: '.js' },
|
|
3
|
+
sys_script: { table: 'sys_script', label: 'Business Rule', nameField: 'name', scriptField: 'script', extension: '.js' },
|
|
4
|
+
sys_ui_script: { table: 'sys_ui_script', label: 'UI Script', nameField: 'name', scriptField: 'script', extension: '.js' },
|
|
5
|
+
sys_ui_action: { table: 'sys_ui_action', label: 'UI Action', nameField: 'name', scriptField: 'script', extension: '.js' },
|
|
6
|
+
sys_script_client: { table: 'sys_script_client', label: 'Client Script', nameField: 'name', scriptField: 'script', extension: '.js' },
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=ScriptSyncModels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScriptSyncModels.js","sourceRoot":"","sources":["../../../src/sn/scriptsync/ScriptSyncModels.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,YAAY,GAAqC;IAC1D,kBAAkB,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE;IACxI,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE;IACvH,aAAa,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE;IACzH,aAAa,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE;IACzH,iBAAiB,EAAE,EAAE,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE;CACxI,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ScriptSync } from './ScriptSync.js';
|
|
2
|
+
import { SyncResult } from './ScriptSyncModels.js';
|
|
3
|
+
export interface WatchOptions {
|
|
4
|
+
directory: string;
|
|
5
|
+
scriptType?: string;
|
|
6
|
+
autoSync?: boolean;
|
|
7
|
+
onSync?: (result: SyncResult) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* ScriptWatcher watches a directory for file changes and automatically
|
|
11
|
+
* pushes updated scripts to ServiceNow using ScriptSync.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ScriptWatcher {
|
|
14
|
+
private _logger;
|
|
15
|
+
private _scriptSync;
|
|
16
|
+
private _watcher;
|
|
17
|
+
constructor(scriptSync: ScriptSync);
|
|
18
|
+
/**
|
|
19
|
+
* Start watching a directory for file changes.
|
|
20
|
+
* On 'change' events, auto-pushes the changed file to ServiceNow.
|
|
21
|
+
* Returns an object with a stop() function to close the watcher.
|
|
22
|
+
*/
|
|
23
|
+
start(options: WatchOptions): {
|
|
24
|
+
stop: () => void;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Stop the file watcher.
|
|
28
|
+
*/
|
|
29
|
+
stop(): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { Logger } from "../../util/Logger.js";
|
|
4
|
+
import { ScriptSync } from './ScriptSync.js';
|
|
5
|
+
/**
|
|
6
|
+
* ScriptWatcher watches a directory for file changes and automatically
|
|
7
|
+
* pushes updated scripts to ServiceNow using ScriptSync.
|
|
8
|
+
*/
|
|
9
|
+
export class ScriptWatcher {
|
|
10
|
+
_logger = new Logger("ScriptWatcher");
|
|
11
|
+
_scriptSync;
|
|
12
|
+
_watcher = null;
|
|
13
|
+
constructor(scriptSync) {
|
|
14
|
+
this._scriptSync = scriptSync;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Start watching a directory for file changes.
|
|
18
|
+
* On 'change' events, auto-pushes the changed file to ServiceNow.
|
|
19
|
+
* Returns an object with a stop() function to close the watcher.
|
|
20
|
+
*/
|
|
21
|
+
start(options) {
|
|
22
|
+
const { directory, scriptType, autoSync = true, onSync } = options;
|
|
23
|
+
this._logger.info(`Starting file watcher on directory: ${directory}`);
|
|
24
|
+
this._watcher = fs.watch(directory, (eventType, filename) => {
|
|
25
|
+
if (eventType !== 'change' || !filename || !autoSync) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const parsed = ScriptSync.parseFileName(filename);
|
|
29
|
+
if (!parsed.isValid) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// If scriptType filter is set, only sync matching types
|
|
33
|
+
if (scriptType && parsed.scriptType !== scriptType) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const filePath = path.join(directory, filename);
|
|
37
|
+
this._logger.info(`File changed: ${filename}, pushing to ServiceNow...`);
|
|
38
|
+
this._scriptSync.pushScript({
|
|
39
|
+
scriptName: parsed.scriptName,
|
|
40
|
+
scriptType: parsed.scriptType,
|
|
41
|
+
filePath
|
|
42
|
+
}).then((result) => {
|
|
43
|
+
if (onSync) {
|
|
44
|
+
onSync(result);
|
|
45
|
+
}
|
|
46
|
+
if (result.success) {
|
|
47
|
+
this._logger.info(`Auto-sync succeeded for ${filename}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this._logger.error(`Auto-sync failed for ${filename}: ${result.error || result.message}`);
|
|
51
|
+
}
|
|
52
|
+
}).catch((error) => {
|
|
53
|
+
this._logger.error(`Auto-sync error for ${filename}: ${error.message}`);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
const self = this;
|
|
57
|
+
return {
|
|
58
|
+
stop: () => {
|
|
59
|
+
self.stop();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Stop the file watcher.
|
|
65
|
+
*/
|
|
66
|
+
stop() {
|
|
67
|
+
if (this._watcher) {
|
|
68
|
+
this._logger.info('Stopping file watcher');
|
|
69
|
+
this._watcher.close();
|
|
70
|
+
this._watcher = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=ScriptWatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScriptWatcher.js","sourceRoot":"","sources":["../../../src/sn/scriptsync/ScriptWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAU1C;;;GAGG;AACH,MAAM,OAAO,aAAa;IACd,OAAO,GAAW,IAAI,MAAM,CAAC,eAAe,CAAC,CAAC;IAC9C,WAAW,CAAa;IACxB,QAAQ,GAAwB,IAAI,CAAC;IAE7C,YAAmB,UAAsB;QACrC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAqB;QAC9B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;QAEtE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,SAAiB,EAAE,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CAAC,CAAC;YAC5E,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,GAAG,EAAE;gBACP,IAAI,CAAC,IAAI,EAAE,CAAC;YAChB,CAAC;SACJ,CAAC;IACN,CAAC;IAED;;OAEG;IACI,IAAI;QACP,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;YAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACzB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Models for task convenience operations against ServiceNow tables.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Options for adding a comment or work note to a task record.
|
|
6
|
+
*/
|
|
7
|
+
export interface AddCommentOptions {
|
|
8
|
+
/** The table name (e.g., "incident", "change_request") */
|
|
9
|
+
table: string;
|
|
10
|
+
/** The sys_id of the record to add the comment to */
|
|
11
|
+
recordSysId: string;
|
|
12
|
+
/** The comment text */
|
|
13
|
+
comment: string;
|
|
14
|
+
/** When true, adds a work note instead of a customer-visible comment. Defaults to false. */
|
|
15
|
+
isWorkNote?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for assigning a task to a user or group.
|
|
19
|
+
*/
|
|
20
|
+
export interface AssignTaskOptions {
|
|
21
|
+
/** The table name (e.g., "incident", "sc_task") */
|
|
22
|
+
table: string;
|
|
23
|
+
/** The sys_id of the record to assign */
|
|
24
|
+
recordSysId: string;
|
|
25
|
+
/** The sys_id or user_name of the user to assign to */
|
|
26
|
+
assignedTo: string;
|
|
27
|
+
/** Optional sys_id of the assignment group */
|
|
28
|
+
assignmentGroup?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for resolving an incident.
|
|
32
|
+
*/
|
|
33
|
+
export interface ResolveIncidentOptions {
|
|
34
|
+
/** The sys_id of the incident to resolve */
|
|
35
|
+
sysId: string;
|
|
36
|
+
/** Resolution notes describing how the incident was resolved */
|
|
37
|
+
resolutionNotes: string;
|
|
38
|
+
/** The close code (e.g., "Solved (Work Around)", "Solved (Permanently)") */
|
|
39
|
+
closeCode?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for closing an incident.
|
|
43
|
+
*/
|
|
44
|
+
export interface CloseIncidentOptions {
|
|
45
|
+
/** The sys_id of the incident to close */
|
|
46
|
+
sysId: string;
|
|
47
|
+
/** Close notes describing why the incident is being closed */
|
|
48
|
+
closeNotes: string;
|
|
49
|
+
/** The close code (e.g., "Solved (Work Around)", "Solved (Permanently)") */
|
|
50
|
+
closeCode?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for approving a change request.
|
|
54
|
+
*/
|
|
55
|
+
export interface ApproveChangeOptions {
|
|
56
|
+
/** The sys_id of the change request to approve */
|
|
57
|
+
sysId: string;
|
|
58
|
+
/** Optional comments to include with the approval */
|
|
59
|
+
comments?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A task record from ServiceNow.
|
|
63
|
+
*/
|
|
64
|
+
export interface TaskRecord {
|
|
65
|
+
/** System ID of the record */
|
|
66
|
+
sys_id: string;
|
|
67
|
+
/** The task number (e.g., "INC0010001") */
|
|
68
|
+
number?: string;
|
|
69
|
+
/** The task state */
|
|
70
|
+
state?: string;
|
|
71
|
+
/** Additional fields */
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Response containing a single task record.
|
|
76
|
+
*/
|
|
77
|
+
export interface TaskRecordResponse {
|
|
78
|
+
result: TaskRecord;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Response containing a list of task records.
|
|
82
|
+
*/
|
|
83
|
+
export interface TaskRecordListResponse {
|
|
84
|
+
result: TaskRecord[];
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskModels.js","sourceRoot":"","sources":["../../../src/sn/task/TaskModels.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ServiceNowInstance } from "../ServiceNowInstance.js";
|
|
2
|
+
import { AddCommentOptions, AssignTaskOptions, ResolveIncidentOptions, CloseIncidentOptions, ApproveChangeOptions, TaskRecord } from './TaskModels.js';
|
|
3
|
+
/**
|
|
4
|
+
* Provides convenience operations for common task-related actions in ServiceNow,
|
|
5
|
+
* such as adding comments, assigning tasks, resolving/closing incidents,
|
|
6
|
+
* and approving change requests.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TaskOperations {
|
|
9
|
+
private _logger;
|
|
10
|
+
private _req;
|
|
11
|
+
private _tableAPI;
|
|
12
|
+
private _instance;
|
|
13
|
+
constructor(instance: ServiceNowInstance);
|
|
14
|
+
/**
|
|
15
|
+
* Add a comment or work note to a task record.
|
|
16
|
+
*
|
|
17
|
+
* @param options The comment options including table, record sys_id, and comment text
|
|
18
|
+
* @returns The updated task record
|
|
19
|
+
* @throws Error if the API call fails
|
|
20
|
+
*/
|
|
21
|
+
addComment(options: AddCommentOptions): Promise<TaskRecord>;
|
|
22
|
+
/**
|
|
23
|
+
* Assign a task record to a user and optionally to an assignment group.
|
|
24
|
+
*
|
|
25
|
+
* @param options The assignment options
|
|
26
|
+
* @returns The updated task record
|
|
27
|
+
* @throws Error if the API call fails
|
|
28
|
+
*/
|
|
29
|
+
assignTask(options: AssignTaskOptions): Promise<TaskRecord>;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve an incident by setting its state to 6 (Resolved).
|
|
32
|
+
*
|
|
33
|
+
* @param options The resolve options including sys_id and resolution notes
|
|
34
|
+
* @returns The updated incident record
|
|
35
|
+
* @throws Error if the API call fails
|
|
36
|
+
*/
|
|
37
|
+
resolveIncident(options: ResolveIncidentOptions): Promise<TaskRecord>;
|
|
38
|
+
/**
|
|
39
|
+
* Close an incident by setting its state to 7 (Closed).
|
|
40
|
+
*
|
|
41
|
+
* @param options The close options including sys_id and close notes
|
|
42
|
+
* @returns The updated incident record
|
|
43
|
+
* @throws Error if the API call fails
|
|
44
|
+
*/
|
|
45
|
+
closeIncident(options: CloseIncidentOptions): Promise<TaskRecord>;
|
|
46
|
+
/**
|
|
47
|
+
* Approve a change request by setting its approval field to 'approved'.
|
|
48
|
+
*
|
|
49
|
+
* @param options The approval options including sys_id and optional comments
|
|
50
|
+
* @returns The updated change request record
|
|
51
|
+
* @throws Error if the API call fails
|
|
52
|
+
*/
|
|
53
|
+
approveChange(options: ApproveChangeOptions): Promise<TaskRecord>;
|
|
54
|
+
/**
|
|
55
|
+
* Find a task record by its number field (e.g., "INC0010001").
|
|
56
|
+
*
|
|
57
|
+
* @param table The table to search in
|
|
58
|
+
* @param number The task number to find
|
|
59
|
+
* @returns The matching TaskRecord, or null if not found
|
|
60
|
+
* @throws Error if the API call fails
|
|
61
|
+
*/
|
|
62
|
+
findByNumber(table: string, number: string): Promise<TaskRecord | null>;
|
|
63
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Logger } from "../../util/Logger.js";
|
|
2
|
+
import { ServiceNowRequest } from "../../comm/http/ServiceNowRequest.js";
|
|
3
|
+
import { TableAPIRequest } from "../../comm/http/TableAPIRequest.js";
|
|
4
|
+
/**
|
|
5
|
+
* Provides convenience operations for common task-related actions in ServiceNow,
|
|
6
|
+
* such as adding comments, assigning tasks, resolving/closing incidents,
|
|
7
|
+
* and approving change requests.
|
|
8
|
+
*/
|
|
9
|
+
export class TaskOperations {
|
|
10
|
+
_logger = new Logger("TaskOperations");
|
|
11
|
+
_req;
|
|
12
|
+
_tableAPI;
|
|
13
|
+
_instance;
|
|
14
|
+
constructor(instance) {
|
|
15
|
+
this._instance = instance;
|
|
16
|
+
this._req = new ServiceNowRequest(instance);
|
|
17
|
+
this._tableAPI = new TableAPIRequest(instance);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Add a comment or work note to a task record.
|
|
21
|
+
*
|
|
22
|
+
* @param options The comment options including table, record sys_id, and comment text
|
|
23
|
+
* @returns The updated task record
|
|
24
|
+
* @throws Error if the API call fails
|
|
25
|
+
*/
|
|
26
|
+
async addComment(options) {
|
|
27
|
+
if (!options.table || options.table.trim().length === 0) {
|
|
28
|
+
throw new Error('Table name is required');
|
|
29
|
+
}
|
|
30
|
+
if (!options.recordSysId || options.recordSysId.trim().length === 0) {
|
|
31
|
+
throw new Error('Record sys_id is required');
|
|
32
|
+
}
|
|
33
|
+
if (!options.comment || options.comment.trim().length === 0) {
|
|
34
|
+
throw new Error('Comment text is required');
|
|
35
|
+
}
|
|
36
|
+
const fieldName = options.isWorkNote ? 'work_notes' : 'comments';
|
|
37
|
+
this._logger.info(`Adding ${fieldName} to ${options.table}/${options.recordSysId}`);
|
|
38
|
+
const body = {
|
|
39
|
+
[fieldName]: options.comment
|
|
40
|
+
};
|
|
41
|
+
const response = await this._tableAPI.put(options.table, options.recordSysId, body);
|
|
42
|
+
if (response && response.status === 200 && response.bodyObject?.result) {
|
|
43
|
+
this._logger.info(`Successfully added ${fieldName} to ${options.table}/${options.recordSysId}`);
|
|
44
|
+
return response.bodyObject.result;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Failed to add ${fieldName} to ${options.table}/${options.recordSysId}. Status: ${response?.status ?? 'unknown'}`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Assign a task record to a user and optionally to an assignment group.
|
|
50
|
+
*
|
|
51
|
+
* @param options The assignment options
|
|
52
|
+
* @returns The updated task record
|
|
53
|
+
* @throws Error if the API call fails
|
|
54
|
+
*/
|
|
55
|
+
async assignTask(options) {
|
|
56
|
+
if (!options.table || options.table.trim().length === 0) {
|
|
57
|
+
throw new Error('Table name is required');
|
|
58
|
+
}
|
|
59
|
+
if (!options.recordSysId || options.recordSysId.trim().length === 0) {
|
|
60
|
+
throw new Error('Record sys_id is required');
|
|
61
|
+
}
|
|
62
|
+
if (!options.assignedTo || options.assignedTo.trim().length === 0) {
|
|
63
|
+
throw new Error('Assigned to value is required');
|
|
64
|
+
}
|
|
65
|
+
this._logger.info(`Assigning ${options.table}/${options.recordSysId} to ${options.assignedTo}`);
|
|
66
|
+
const body = {
|
|
67
|
+
assigned_to: options.assignedTo
|
|
68
|
+
};
|
|
69
|
+
if (options.assignmentGroup) {
|
|
70
|
+
body.assignment_group = options.assignmentGroup;
|
|
71
|
+
}
|
|
72
|
+
const response = await this._tableAPI.put(options.table, options.recordSysId, body);
|
|
73
|
+
if (response && response.status === 200 && response.bodyObject?.result) {
|
|
74
|
+
this._logger.info(`Successfully assigned ${options.table}/${options.recordSysId}`);
|
|
75
|
+
return response.bodyObject.result;
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Failed to assign ${options.table}/${options.recordSysId}. Status: ${response?.status ?? 'unknown'}`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve an incident by setting its state to 6 (Resolved).
|
|
81
|
+
*
|
|
82
|
+
* @param options The resolve options including sys_id and resolution notes
|
|
83
|
+
* @returns The updated incident record
|
|
84
|
+
* @throws Error if the API call fails
|
|
85
|
+
*/
|
|
86
|
+
async resolveIncident(options) {
|
|
87
|
+
if (!options.sysId || options.sysId.trim().length === 0) {
|
|
88
|
+
throw new Error('Incident sys_id is required');
|
|
89
|
+
}
|
|
90
|
+
if (!options.resolutionNotes || options.resolutionNotes.trim().length === 0) {
|
|
91
|
+
throw new Error('Resolution notes are required');
|
|
92
|
+
}
|
|
93
|
+
this._logger.info(`Resolving incident ${options.sysId}`);
|
|
94
|
+
const body = {
|
|
95
|
+
state: '6',
|
|
96
|
+
close_notes: options.resolutionNotes
|
|
97
|
+
};
|
|
98
|
+
if (options.closeCode) {
|
|
99
|
+
body.close_code = options.closeCode;
|
|
100
|
+
}
|
|
101
|
+
const response = await this._tableAPI.put('incident', options.sysId, body);
|
|
102
|
+
if (response && response.status === 200 && response.bodyObject?.result) {
|
|
103
|
+
this._logger.info(`Successfully resolved incident ${options.sysId}`);
|
|
104
|
+
return response.bodyObject.result;
|
|
105
|
+
}
|
|
106
|
+
throw new Error(`Failed to resolve incident ${options.sysId}. Status: ${response?.status ?? 'unknown'}`);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Close an incident by setting its state to 7 (Closed).
|
|
110
|
+
*
|
|
111
|
+
* @param options The close options including sys_id and close notes
|
|
112
|
+
* @returns The updated incident record
|
|
113
|
+
* @throws Error if the API call fails
|
|
114
|
+
*/
|
|
115
|
+
async closeIncident(options) {
|
|
116
|
+
if (!options.sysId || options.sysId.trim().length === 0) {
|
|
117
|
+
throw new Error('Incident sys_id is required');
|
|
118
|
+
}
|
|
119
|
+
if (!options.closeNotes || options.closeNotes.trim().length === 0) {
|
|
120
|
+
throw new Error('Close notes are required');
|
|
121
|
+
}
|
|
122
|
+
this._logger.info(`Closing incident ${options.sysId}`);
|
|
123
|
+
const body = {
|
|
124
|
+
state: '7',
|
|
125
|
+
close_notes: options.closeNotes
|
|
126
|
+
};
|
|
127
|
+
if (options.closeCode) {
|
|
128
|
+
body.close_code = options.closeCode;
|
|
129
|
+
}
|
|
130
|
+
const response = await this._tableAPI.put('incident', options.sysId, body);
|
|
131
|
+
if (response && response.status === 200 && response.bodyObject?.result) {
|
|
132
|
+
this._logger.info(`Successfully closed incident ${options.sysId}`);
|
|
133
|
+
return response.bodyObject.result;
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`Failed to close incident ${options.sysId}. Status: ${response?.status ?? 'unknown'}`);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Approve a change request by setting its approval field to 'approved'.
|
|
139
|
+
*
|
|
140
|
+
* @param options The approval options including sys_id and optional comments
|
|
141
|
+
* @returns The updated change request record
|
|
142
|
+
* @throws Error if the API call fails
|
|
143
|
+
*/
|
|
144
|
+
async approveChange(options) {
|
|
145
|
+
if (!options.sysId || options.sysId.trim().length === 0) {
|
|
146
|
+
throw new Error('Change request sys_id is required');
|
|
147
|
+
}
|
|
148
|
+
this._logger.info(`Approving change request ${options.sysId}`);
|
|
149
|
+
const body = {
|
|
150
|
+
approval: 'approved'
|
|
151
|
+
};
|
|
152
|
+
if (options.comments) {
|
|
153
|
+
body.comments = options.comments;
|
|
154
|
+
}
|
|
155
|
+
const response = await this._tableAPI.put('change_request', options.sysId, body);
|
|
156
|
+
if (response && response.status === 200 && response.bodyObject?.result) {
|
|
157
|
+
this._logger.info(`Successfully approved change request ${options.sysId}`);
|
|
158
|
+
return response.bodyObject.result;
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`Failed to approve change request ${options.sysId}. Status: ${response?.status ?? 'unknown'}`);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Find a task record by its number field (e.g., "INC0010001").
|
|
164
|
+
*
|
|
165
|
+
* @param table The table to search in
|
|
166
|
+
* @param number The task number to find
|
|
167
|
+
* @returns The matching TaskRecord, or null if not found
|
|
168
|
+
* @throws Error if the API call fails
|
|
169
|
+
*/
|
|
170
|
+
async findByNumber(table, number) {
|
|
171
|
+
if (!table || table.trim().length === 0) {
|
|
172
|
+
throw new Error('Table name is required');
|
|
173
|
+
}
|
|
174
|
+
if (!number || number.trim().length === 0) {
|
|
175
|
+
throw new Error('Task number is required');
|
|
176
|
+
}
|
|
177
|
+
this._logger.info(`Finding ${table} record with number=${number}`);
|
|
178
|
+
const query = {
|
|
179
|
+
sysparm_query: `number=${number}`,
|
|
180
|
+
sysparm_limit: 1
|
|
181
|
+
};
|
|
182
|
+
const response = await this._tableAPI.get(table, query);
|
|
183
|
+
if (response && response.status === 200 && response.bodyObject?.result) {
|
|
184
|
+
const results = response.bodyObject.result;
|
|
185
|
+
if (results.length > 0) {
|
|
186
|
+
this._logger.info(`Found ${table} record: ${results[0].sys_id}`);
|
|
187
|
+
return results[0];
|
|
188
|
+
}
|
|
189
|
+
this._logger.info(`No ${table} record found with number=${number}`);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
throw new Error(`Failed to query ${table} for number=${number}. Status: ${response?.status ?? 'unknown'}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=TaskOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskOperations.js","sourceRoot":"","sources":["../../../src/sn/task/TaskOperations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAalE;;;;GAIG;AACH,MAAM,OAAO,cAAc;IACf,OAAO,GAAW,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC/C,IAAI,CAAoB;IACxB,SAAS,CAAkB;IAC3B,SAAS,CAAqB;IAEtC,YAAmB,QAA4B;QAC3C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,UAAU,CAAC,OAA0B;QAC9C,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EA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pdateSetOptions, MoveRecordsOptions, MoveRecordsResult, CloneUpdateSetResult, InspectUpdateSetResult, UpdateSetRecord } from './UpdateSetModels.js';
|
|
3
|
+
/**
|
|
4
|
+
* UpdateSetManager provides operations for managing ServiceNow update sets.
|
|
5
|
+
* Supports setting/getting the current update set, listing, creating,
|
|
6
|
+
* moving records between update sets, cloning, and inspecting update sets.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UpdateSetManager {
|
|
9
|
+
private static readonly UI_UPDATESET_PATH;
|
|
10
|
+
private static readonly UI_PREF_UPDATESET_PATH;
|
|
11
|
+
private static readonly UPDATE_SET_TABLE;
|
|
12
|
+
private static readonly UPDATE_XML_TABLE;
|
|
13
|
+
private _logger;
|
|
14
|
+
private _req;
|
|
15
|
+
private _tableAPI;
|
|
16
|
+
private _instance;
|
|
17
|
+
constructor(instance: ServiceNowInstance);
|
|
18
|
+
/**
|
|
19
|
+
* Set the current update set for the session.
|
|
20
|
+
* Uses PUT /api/now/ui/concoursepicker/updateset
|
|
21
|
+
*
|
|
22
|
+
* @param options The update set name and sysId to set as current
|
|
23
|
+
* @throws Error if name or sysId is empty or if the API call fails
|
|
24
|
+
*/
|
|
25
|
+
setCurrentUpdateSet(options: SetUpdateSetOptions): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the current update set from the session preferences.
|
|
28
|
+
* Uses GET /api/now/ui/preferences/sys_update_set
|
|
29
|
+
*
|
|
30
|
+
* @returns The current update set record or null if not set
|
|
31
|
+
*/
|
|
32
|
+
getCurrentUpdateSet(): Promise<UpdateSetRecord | null>;
|
|
33
|
+
/**
|
|
34
|
+
* List update sets from the sys_update_set table.
|
|
35
|
+
* Uses Table API GET on sys_update_set.
|
|
36
|
+
*
|
|
37
|
+
* @param options Optional query, limit, and fields options
|
|
38
|
+
* @returns Array of UpdateSetRecord
|
|
39
|
+
*/
|
|
40
|
+
listUpdateSets(options?: ListUpdateSetsOptions): Promise<UpdateSetRecord[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new update set.
|
|
43
|
+
* Uses Table API POST on sys_update_set.
|
|
44
|
+
*
|
|
45
|
+
* @param options The update set name and optional description, application, state
|
|
46
|
+
* @returns The created UpdateSetRecord
|
|
47
|
+
* @throws Error if name is empty or if the API call fails
|
|
48
|
+
*/
|
|
49
|
+
createUpdateSet(options: CreateUpdateSetOptions): Promise<UpdateSetRecord>;
|
|
50
|
+
/**
|
|
51
|
+
* Move records to a target update set.
|
|
52
|
+
* Queries sys_update_xml records based on options and updates each to the target update set.
|
|
53
|
+
*
|
|
54
|
+
* @param targetUpdateSetId The sys_id of the target update set
|
|
55
|
+
* @param options Options for selecting which records to move
|
|
56
|
+
* @returns Result summary of the move operation
|
|
57
|
+
* @throws Error if targetUpdateSetId is empty or no selection criteria provided
|
|
58
|
+
*/
|
|
59
|
+
moveRecordsToUpdateSet(targetUpdateSetId: string, options?: MoveRecordsOptions): Promise<MoveRecordsResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Clone an update set by creating a new update set and copying all sys_update_xml records.
|
|
62
|
+
*
|
|
63
|
+
* @param sourceUpdateSetId The sys_id of the source update set to clone
|
|
64
|
+
* @param newName The name for the new cloned update set
|
|
65
|
+
* @param onProgress Optional callback for progress updates
|
|
66
|
+
* @returns Result of the clone operation
|
|
67
|
+
* @throws Error if sourceUpdateSetId or newName is empty
|
|
68
|
+
*/
|
|
69
|
+
cloneUpdateSet(sourceUpdateSetId: string, newName: string, onProgress?: (message: string) => void): Promise<CloneUpdateSetResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Inspect an update set by querying its sys_update_xml records and grouping by type.
|
|
72
|
+
*
|
|
73
|
+
* @param updateSetSysId The sys_id of the update set to inspect
|
|
74
|
+
* @returns Inspection result with grouped components
|
|
75
|
+
* @throws Error if updateSetSysId is empty or the update set is not found
|
|
76
|
+
*/
|
|
77
|
+
inspectUpdateSet(updateSetSysId: string): Promise<InspectUpdateSetResult>;
|
|
78
|
+
}
|