@sonisoft/now-sdk-ext-core 3.3.0 → 3.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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/sn/flow/FlowManager.d.ts +69 -0
- package/dist/sn/flow/FlowManager.js +571 -0
- package/dist/sn/flow/FlowManager.js.map +1 -0
- package/dist/sn/flow/FlowModels.d.ts +146 -0
- package/dist/sn/flow/FlowModels.js +7 -0
- package/dist/sn/flow/FlowModels.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export * from './sn/codesearch/CodeSearch.js';
|
|
|
57
57
|
export * from './sn/codesearch/CodeSearchModels.js';
|
|
58
58
|
export * from './sn/discovery/DiscoveryModels.js';
|
|
59
59
|
export * from './sn/discovery/InstanceDiscovery.js';
|
|
60
|
+
export * from './sn/flow/FlowManager.js';
|
|
61
|
+
export * from './sn/flow/FlowModels.js';
|
|
60
62
|
export * from './sn/health/HealthModels.js';
|
|
61
63
|
export * from './sn/health/InstanceHealth.js';
|
|
62
64
|
export * from './sn/knowledge/KnowledgeManager.js';
|
package/dist/index.js
CHANGED
|
@@ -57,6 +57,8 @@ export * from './sn/codesearch/CodeSearch.js';
|
|
|
57
57
|
export * from './sn/codesearch/CodeSearchModels.js';
|
|
58
58
|
export * from './sn/discovery/DiscoveryModels.js';
|
|
59
59
|
export * from './sn/discovery/InstanceDiscovery.js';
|
|
60
|
+
export * from './sn/flow/FlowManager.js';
|
|
61
|
+
export * from './sn/flow/FlowModels.js';
|
|
60
62
|
export * from './sn/health/HealthModels.js';
|
|
61
63
|
export * from './sn/health/InstanceHealth.js';
|
|
62
64
|
export * from './sn/knowledge/KnowledgeManager.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"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AAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ServiceNowInstance } from "../ServiceNowInstance.js";
|
|
2
|
+
import { BackgroundScriptExecutionResult } from "../BackgroundScriptExecutor.js";
|
|
3
|
+
import { ExecuteFlowOptions, ExecuteFlowByNameOptions, ExecuteSubflowOptions, ExecuteActionOptions, FlowExecutionResult, FlowScriptResultEnvelope, FlowContextStatusResult, FlowOutputsResult, FlowErrorResult, FlowCancelResult, FlowSendMessageResult } from './FlowModels.js';
|
|
4
|
+
/**
|
|
5
|
+
* Provides operations for executing ServiceNow Flow Designer flows,
|
|
6
|
+
* subflows, and actions remotely via BackgroundScriptExecutor.
|
|
7
|
+
*
|
|
8
|
+
* Uses the sn_fd.FlowAPI.getRunner() (ScriptableFlowRunner) API
|
|
9
|
+
* on the server side to execute and capture results.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FlowManager {
|
|
12
|
+
private _logger;
|
|
13
|
+
private _bgExecutor;
|
|
14
|
+
private _instance;
|
|
15
|
+
private _defaultScope;
|
|
16
|
+
/**
|
|
17
|
+
* @param instance ServiceNow instance connection
|
|
18
|
+
* @param scope Default scope for script execution (default: "global")
|
|
19
|
+
*/
|
|
20
|
+
constructor(instance: ServiceNowInstance, scope?: string);
|
|
21
|
+
/** Execute any flow object (flow, subflow, or action). */
|
|
22
|
+
execute(options: ExecuteFlowOptions): Promise<FlowExecutionResult>;
|
|
23
|
+
/** Execute a flow by scoped name. */
|
|
24
|
+
executeFlow(options: ExecuteFlowByNameOptions): Promise<FlowExecutionResult>;
|
|
25
|
+
/** Execute a subflow by scoped name. */
|
|
26
|
+
executeSubflow(options: ExecuteSubflowOptions): Promise<FlowExecutionResult>;
|
|
27
|
+
/** Execute an action by scoped name. */
|
|
28
|
+
executeAction(options: ExecuteActionOptions): Promise<FlowExecutionResult>;
|
|
29
|
+
/** Query the status of a flow context by its sys_id. */
|
|
30
|
+
getFlowContextStatus(contextId: string): Promise<FlowContextStatusResult>;
|
|
31
|
+
/** Retrieve outputs from a completed flow/subflow/action by context ID. */
|
|
32
|
+
getFlowOutputs(contextId: string): Promise<FlowOutputsResult>;
|
|
33
|
+
/** Retrieve error messages from a flow/subflow/action by context ID. */
|
|
34
|
+
getFlowError(contextId: string): Promise<FlowErrorResult>;
|
|
35
|
+
/** Cancel a running or paused flow/subflow/action. */
|
|
36
|
+
cancelFlow(contextId: string, reason?: string): Promise<FlowCancelResult>;
|
|
37
|
+
/** Send a message to a paused flow to resume it (for Wait for Message actions). */
|
|
38
|
+
sendFlowMessage(contextId: string, message: string, payload?: string): Promise<FlowSendMessageResult>;
|
|
39
|
+
/** Build the ServiceNow server-side script string. */
|
|
40
|
+
_buildFlowScript(options: ExecuteFlowOptions): string;
|
|
41
|
+
/** Serialize inputs for embedding in the generated script. */
|
|
42
|
+
_serializeInputs(inputs: Record<string, unknown>): string;
|
|
43
|
+
/**
|
|
44
|
+
* Decode HTML entities and strip HTML tags from a string.
|
|
45
|
+
* ServiceNow's background script output encodes quotes as "
|
|
46
|
+
* and appends <BR/> tags that must be removed before JSON parsing.
|
|
47
|
+
*/
|
|
48
|
+
_decodeHtmlEntities(str: string): string;
|
|
49
|
+
/** Try to parse a line containing the result marker into a FlowScriptResultEnvelope. */
|
|
50
|
+
private _tryParseEnvelopeFromLine;
|
|
51
|
+
/** Extract the JSON envelope from script output lines. */
|
|
52
|
+
_extractResultEnvelope(bgResult: BackgroundScriptExecutionResult): FlowScriptResultEnvelope | null;
|
|
53
|
+
/** Parse BackgroundScriptExecutionResult into FlowExecutionResult. */
|
|
54
|
+
_parseFlowResult(bgResult: BackgroundScriptExecutionResult, options: ExecuteFlowOptions): FlowExecutionResult;
|
|
55
|
+
/** Validate that a context ID is non-empty. */
|
|
56
|
+
private _validateContextId;
|
|
57
|
+
/** Escape a string for embedding in a generated SN script single-quoted string. */
|
|
58
|
+
private _escapeForScript;
|
|
59
|
+
/** Build script to query sys_flow_context status. */
|
|
60
|
+
_buildContextStatusScript(contextId: string): string;
|
|
61
|
+
/** Build script to retrieve flow outputs via FlowAPI.getOutputs(). */
|
|
62
|
+
_buildGetOutputsScript(contextId: string): string;
|
|
63
|
+
/** Build script to retrieve flow error via FlowAPI.getErrorMessage(). */
|
|
64
|
+
_buildGetErrorScript(contextId: string): string;
|
|
65
|
+
/** Build script to cancel a flow via FlowAPI.cancel(). */
|
|
66
|
+
_buildCancelScript(contextId: string, reason: string): string;
|
|
67
|
+
/** Build script to send a message to a paused flow via FlowAPI.sendMessage(). */
|
|
68
|
+
_buildSendMessageScript(contextId: string, message: string, payload: string): string;
|
|
69
|
+
}
|
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { BackgroundScriptExecutor } from "../BackgroundScriptExecutor.js";
|
|
2
|
+
import { Logger } from "../../util/Logger.js";
|
|
3
|
+
const RESULT_MARKER = '___FLOW_EXEC_RESULT___';
|
|
4
|
+
const VALID_TYPES = ['flow', 'subflow', 'action'];
|
|
5
|
+
/**
|
|
6
|
+
* Provides operations for executing ServiceNow Flow Designer flows,
|
|
7
|
+
* subflows, and actions remotely via BackgroundScriptExecutor.
|
|
8
|
+
*
|
|
9
|
+
* Uses the sn_fd.FlowAPI.getRunner() (ScriptableFlowRunner) API
|
|
10
|
+
* on the server side to execute and capture results.
|
|
11
|
+
*/
|
|
12
|
+
export class FlowManager {
|
|
13
|
+
_logger = new Logger("FlowManager");
|
|
14
|
+
_bgExecutor;
|
|
15
|
+
_instance;
|
|
16
|
+
_defaultScope;
|
|
17
|
+
/**
|
|
18
|
+
* @param instance ServiceNow instance connection
|
|
19
|
+
* @param scope Default scope for script execution (default: "global")
|
|
20
|
+
*/
|
|
21
|
+
constructor(instance, scope = 'global') {
|
|
22
|
+
this._instance = instance;
|
|
23
|
+
this._defaultScope = scope;
|
|
24
|
+
this._bgExecutor = new BackgroundScriptExecutor(instance, scope);
|
|
25
|
+
}
|
|
26
|
+
// ================================================================
|
|
27
|
+
// Public API
|
|
28
|
+
// ================================================================
|
|
29
|
+
/** Execute any flow object (flow, subflow, or action). */
|
|
30
|
+
async execute(options) {
|
|
31
|
+
if (!options.scopedName || options.scopedName.trim().length === 0) {
|
|
32
|
+
throw new Error('Flow scoped name is required (e.g. "global.my_flow")');
|
|
33
|
+
}
|
|
34
|
+
if (!options.type) {
|
|
35
|
+
throw new Error('Flow object type is required ("flow", "subflow", or "action")');
|
|
36
|
+
}
|
|
37
|
+
if (!VALID_TYPES.includes(options.type)) {
|
|
38
|
+
throw new Error(`Invalid flow object type "${options.type}". Must be one of: ${VALID_TYPES.join(', ')}`);
|
|
39
|
+
}
|
|
40
|
+
this._logger.info(`Executing ${options.type}: ${options.scopedName}`);
|
|
41
|
+
const script = this._buildFlowScript(options);
|
|
42
|
+
const scope = options.scope || this._defaultScope;
|
|
43
|
+
try {
|
|
44
|
+
const bgResult = await this._bgExecutor.executeScript(script, scope, this._instance);
|
|
45
|
+
const flowResult = this._parseFlowResult(bgResult, options);
|
|
46
|
+
this._logger.info(`${options.type} execution complete: ${flowResult.success ? 'SUCCESS' : 'FAILED'}`);
|
|
47
|
+
return flowResult;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const err = error;
|
|
51
|
+
this._logger.error(`Error executing ${options.type} "${options.scopedName}": ${err.message}`);
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
flowObjectName: options.scopedName,
|
|
55
|
+
flowObjectType: options.type,
|
|
56
|
+
errorMessage: `Script execution error: ${err.message}`,
|
|
57
|
+
rawScriptResult: null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Execute a flow by scoped name. */
|
|
62
|
+
async executeFlow(options) {
|
|
63
|
+
return this.execute({ ...options, type: 'flow' });
|
|
64
|
+
}
|
|
65
|
+
/** Execute a subflow by scoped name. */
|
|
66
|
+
async executeSubflow(options) {
|
|
67
|
+
return this.execute({ ...options, type: 'subflow' });
|
|
68
|
+
}
|
|
69
|
+
/** Execute an action by scoped name. */
|
|
70
|
+
async executeAction(options) {
|
|
71
|
+
return this.execute({ ...options, type: 'action' });
|
|
72
|
+
}
|
|
73
|
+
// ================================================================
|
|
74
|
+
// Flow Context Lifecycle API
|
|
75
|
+
// ================================================================
|
|
76
|
+
/** Query the status of a flow context by its sys_id. */
|
|
77
|
+
async getFlowContextStatus(contextId) {
|
|
78
|
+
this._validateContextId(contextId);
|
|
79
|
+
this._logger.info(`Getting context status: ${contextId}`);
|
|
80
|
+
const script = this._buildContextStatusScript(contextId);
|
|
81
|
+
try {
|
|
82
|
+
const bgResult = await this._bgExecutor.executeScript(script, this._defaultScope, this._instance);
|
|
83
|
+
const envelope = this._extractResultEnvelope(bgResult);
|
|
84
|
+
if (envelope) {
|
|
85
|
+
return {
|
|
86
|
+
success: envelope.success,
|
|
87
|
+
contextId,
|
|
88
|
+
found: envelope.found ?? false,
|
|
89
|
+
state: envelope.state ?? undefined,
|
|
90
|
+
name: envelope.name ?? undefined,
|
|
91
|
+
started: envelope.started ?? undefined,
|
|
92
|
+
ended: envelope.ended ?? undefined,
|
|
93
|
+
errorMessage: envelope.errorMessage ?? undefined,
|
|
94
|
+
rawScriptResult: bgResult
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
success: false, contextId, found: false,
|
|
99
|
+
errorMessage: 'Could not parse context status result from script output.',
|
|
100
|
+
rawScriptResult: bgResult
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
const err = error;
|
|
105
|
+
return {
|
|
106
|
+
success: false, contextId, found: false,
|
|
107
|
+
errorMessage: `Script execution error: ${err.message}`,
|
|
108
|
+
rawScriptResult: null
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Retrieve outputs from a completed flow/subflow/action by context ID. */
|
|
113
|
+
async getFlowOutputs(contextId) {
|
|
114
|
+
this._validateContextId(contextId);
|
|
115
|
+
this._logger.info(`Getting outputs for context: ${contextId}`);
|
|
116
|
+
const script = this._buildGetOutputsScript(contextId);
|
|
117
|
+
try {
|
|
118
|
+
const bgResult = await this._bgExecutor.executeScript(script, this._defaultScope, this._instance);
|
|
119
|
+
const envelope = this._extractResultEnvelope(bgResult);
|
|
120
|
+
if (envelope) {
|
|
121
|
+
return {
|
|
122
|
+
success: envelope.success,
|
|
123
|
+
contextId,
|
|
124
|
+
outputs: envelope.outputs ?? undefined,
|
|
125
|
+
errorMessage: envelope.errorMessage ?? undefined,
|
|
126
|
+
rawScriptResult: bgResult
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
success: false, contextId,
|
|
131
|
+
errorMessage: 'Could not parse outputs result from script output.',
|
|
132
|
+
rawScriptResult: bgResult
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const err = error;
|
|
137
|
+
return {
|
|
138
|
+
success: false, contextId,
|
|
139
|
+
errorMessage: `Script execution error: ${err.message}`,
|
|
140
|
+
rawScriptResult: null
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Retrieve error messages from a flow/subflow/action by context ID. */
|
|
145
|
+
async getFlowError(contextId) {
|
|
146
|
+
this._validateContextId(contextId);
|
|
147
|
+
this._logger.info(`Getting error for context: ${contextId}`);
|
|
148
|
+
const script = this._buildGetErrorScript(contextId);
|
|
149
|
+
try {
|
|
150
|
+
const bgResult = await this._bgExecutor.executeScript(script, this._defaultScope, this._instance);
|
|
151
|
+
const envelope = this._extractResultEnvelope(bgResult);
|
|
152
|
+
if (envelope) {
|
|
153
|
+
return {
|
|
154
|
+
success: envelope.success,
|
|
155
|
+
contextId,
|
|
156
|
+
flowErrorMessage: envelope.flowErrorMessage ?? undefined,
|
|
157
|
+
errorMessage: envelope.errorMessage ?? undefined,
|
|
158
|
+
rawScriptResult: bgResult
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
success: false, contextId,
|
|
163
|
+
errorMessage: 'Could not parse error result from script output.',
|
|
164
|
+
rawScriptResult: bgResult
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
const err = error;
|
|
169
|
+
return {
|
|
170
|
+
success: false, contextId,
|
|
171
|
+
errorMessage: `Script execution error: ${err.message}`,
|
|
172
|
+
rawScriptResult: null
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** Cancel a running or paused flow/subflow/action. */
|
|
177
|
+
async cancelFlow(contextId, reason) {
|
|
178
|
+
this._validateContextId(contextId);
|
|
179
|
+
this._logger.info(`Cancelling context: ${contextId}`);
|
|
180
|
+
const script = this._buildCancelScript(contextId, reason || 'Cancelled via FlowManager');
|
|
181
|
+
try {
|
|
182
|
+
const bgResult = await this._bgExecutor.executeScript(script, this._defaultScope, this._instance);
|
|
183
|
+
const envelope = this._extractResultEnvelope(bgResult);
|
|
184
|
+
if (envelope) {
|
|
185
|
+
return {
|
|
186
|
+
success: envelope.success,
|
|
187
|
+
contextId,
|
|
188
|
+
errorMessage: envelope.errorMessage ?? undefined,
|
|
189
|
+
rawScriptResult: bgResult
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
success: false, contextId,
|
|
194
|
+
errorMessage: 'Could not parse cancel result from script output.',
|
|
195
|
+
rawScriptResult: bgResult
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
const err = error;
|
|
200
|
+
return {
|
|
201
|
+
success: false, contextId,
|
|
202
|
+
errorMessage: `Script execution error: ${err.message}`,
|
|
203
|
+
rawScriptResult: null
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Send a message to a paused flow to resume it (for Wait for Message actions). */
|
|
208
|
+
async sendFlowMessage(contextId, message, payload) {
|
|
209
|
+
this._validateContextId(contextId);
|
|
210
|
+
if (!message || message.trim().length === 0) {
|
|
211
|
+
throw new Error('Message is required');
|
|
212
|
+
}
|
|
213
|
+
this._logger.info(`Sending message to context: ${contextId}`);
|
|
214
|
+
const script = this._buildSendMessageScript(contextId, message, payload || '');
|
|
215
|
+
try {
|
|
216
|
+
const bgResult = await this._bgExecutor.executeScript(script, this._defaultScope, this._instance);
|
|
217
|
+
const envelope = this._extractResultEnvelope(bgResult);
|
|
218
|
+
if (envelope) {
|
|
219
|
+
return {
|
|
220
|
+
success: envelope.success,
|
|
221
|
+
contextId,
|
|
222
|
+
errorMessage: envelope.errorMessage ?? undefined,
|
|
223
|
+
rawScriptResult: bgResult
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
success: false, contextId,
|
|
228
|
+
errorMessage: 'Could not parse send message result from script output.',
|
|
229
|
+
rawScriptResult: bgResult
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
const err = error;
|
|
234
|
+
return {
|
|
235
|
+
success: false, contextId,
|
|
236
|
+
errorMessage: `Script execution error: ${err.message}`,
|
|
237
|
+
rawScriptResult: null
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// ================================================================
|
|
242
|
+
// Internal Methods
|
|
243
|
+
// ================================================================
|
|
244
|
+
/** Build the ServiceNow server-side script string. */
|
|
245
|
+
_buildFlowScript(options) {
|
|
246
|
+
const mode = options.mode || 'foreground';
|
|
247
|
+
const modeMethod = mode === 'background' ? 'inBackground' : 'inForeground';
|
|
248
|
+
const inputsJson = options.inputs ? this._serializeInputs(options.inputs) : '{}';
|
|
249
|
+
const scopedName = options.scopedName.replace(/'/g, "\\'");
|
|
250
|
+
const type = options.type;
|
|
251
|
+
let optionalChain = '';
|
|
252
|
+
if (options.timeout !== undefined && options.timeout !== null) {
|
|
253
|
+
optionalChain += `\n .timeout(${options.timeout})`;
|
|
254
|
+
}
|
|
255
|
+
if (options.quick === true) {
|
|
256
|
+
optionalChain += `\n .quick()`;
|
|
257
|
+
}
|
|
258
|
+
const hasInputs = options.inputs && Object.keys(options.inputs).length > 0;
|
|
259
|
+
const inputsChain = hasInputs ? `\n .withInputs(inputs)` : '';
|
|
260
|
+
return `(function() {
|
|
261
|
+
var __RESULT_MARKER = '${RESULT_MARKER}';
|
|
262
|
+
try {
|
|
263
|
+
var inputs = ${inputsJson};
|
|
264
|
+
|
|
265
|
+
var result = sn_fd.FlowAPI.getRunner()
|
|
266
|
+
.${type}('${scopedName}')
|
|
267
|
+
.${modeMethod}()${optionalChain}${inputsChain}
|
|
268
|
+
.run();
|
|
269
|
+
|
|
270
|
+
var envelope = {
|
|
271
|
+
__flowResult: true,
|
|
272
|
+
success: true,
|
|
273
|
+
flowObjectName: '' + result.getFlowObjectName(),
|
|
274
|
+
flowObjectType: '' + result.getFlowObjectType(),
|
|
275
|
+
contextId: result.getContextId() ? '' + result.getContextId() : null,
|
|
276
|
+
executionDate: result.getDate() ? '' + result.getDate() : null,
|
|
277
|
+
domainId: result.getDomainId() ? '' + result.getDomainId() : null,
|
|
278
|
+
outputs: null,
|
|
279
|
+
debugOutput: '' + result.debug(),
|
|
280
|
+
errorMessage: null
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
var rawOutputs = result.getOutputs();
|
|
285
|
+
if (rawOutputs) {
|
|
286
|
+
var outputObj = {};
|
|
287
|
+
for (var key in rawOutputs) {
|
|
288
|
+
if (rawOutputs.hasOwnProperty(key)) {
|
|
289
|
+
outputObj[key] = '' + rawOutputs[key];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
envelope.outputs = outputObj;
|
|
293
|
+
}
|
|
294
|
+
} catch (outErr) {
|
|
295
|
+
envelope.outputs = null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
gs.info(__RESULT_MARKER + JSON.stringify(envelope));
|
|
299
|
+
} catch (ex) {
|
|
300
|
+
var errorEnvelope = {
|
|
301
|
+
__flowResult: true,
|
|
302
|
+
success: false,
|
|
303
|
+
flowObjectName: '${scopedName}',
|
|
304
|
+
flowObjectType: '${type}',
|
|
305
|
+
contextId: null,
|
|
306
|
+
executionDate: null,
|
|
307
|
+
domainId: null,
|
|
308
|
+
outputs: null,
|
|
309
|
+
debugOutput: '',
|
|
310
|
+
errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
|
|
311
|
+
};
|
|
312
|
+
gs.info(__RESULT_MARKER + JSON.stringify(errorEnvelope));
|
|
313
|
+
}
|
|
314
|
+
})();`;
|
|
315
|
+
}
|
|
316
|
+
/** Serialize inputs for embedding in the generated script. */
|
|
317
|
+
_serializeInputs(inputs) {
|
|
318
|
+
const cleanInputs = {};
|
|
319
|
+
for (const [key, value] of Object.entries(inputs)) {
|
|
320
|
+
if (value !== undefined) {
|
|
321
|
+
cleanInputs[key] = value;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return JSON.stringify(cleanInputs);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Decode HTML entities and strip HTML tags from a string.
|
|
328
|
+
* ServiceNow's background script output encodes quotes as "
|
|
329
|
+
* and appends <BR/> tags that must be removed before JSON parsing.
|
|
330
|
+
*/
|
|
331
|
+
_decodeHtmlEntities(str) {
|
|
332
|
+
return str
|
|
333
|
+
.replace(/<BR\s*\/?>/gi, '')
|
|
334
|
+
.replace(/"/g, '"')
|
|
335
|
+
.replace(/&/g, '&')
|
|
336
|
+
.replace(/</g, '<')
|
|
337
|
+
.replace(/>/g, '>')
|
|
338
|
+
.replace(/'/g, "'")
|
|
339
|
+
.replace(/'/g, "'")
|
|
340
|
+
.trim();
|
|
341
|
+
}
|
|
342
|
+
/** Try to parse a line containing the result marker into a FlowScriptResultEnvelope. */
|
|
343
|
+
_tryParseEnvelopeFromLine(line) {
|
|
344
|
+
if (!line || !line.includes(RESULT_MARKER)) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
const afterMarker = line.substring(line.indexOf(RESULT_MARKER) + RESULT_MARKER.length);
|
|
348
|
+
const jsonStr = this._decodeHtmlEntities(afterMarker);
|
|
349
|
+
try {
|
|
350
|
+
const parsed = JSON.parse(jsonStr);
|
|
351
|
+
if (parsed && parsed.__flowResult === true) {
|
|
352
|
+
return parsed;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
this._logger.warn(`Failed to parse flow result JSON: ${jsonStr.substring(0, 200)}`);
|
|
357
|
+
}
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
/** Extract the JSON envelope from script output lines. */
|
|
361
|
+
_extractResultEnvelope(bgResult) {
|
|
362
|
+
// Search through scriptResults for our marker line
|
|
363
|
+
if (bgResult.scriptResults && bgResult.scriptResults.length > 0) {
|
|
364
|
+
for (const outputLine of bgResult.scriptResults) {
|
|
365
|
+
const envelope = this._tryParseEnvelopeFromLine(outputLine.line);
|
|
366
|
+
if (envelope)
|
|
367
|
+
return envelope;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Fallback: search through consoleResult string array
|
|
371
|
+
if (bgResult.consoleResult && bgResult.consoleResult.length > 0) {
|
|
372
|
+
for (const line of bgResult.consoleResult) {
|
|
373
|
+
const envelope = this._tryParseEnvelopeFromLine(line);
|
|
374
|
+
if (envelope)
|
|
375
|
+
return envelope;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
/** Parse BackgroundScriptExecutionResult into FlowExecutionResult. */
|
|
381
|
+
_parseFlowResult(bgResult, options) {
|
|
382
|
+
const envelope = this._extractResultEnvelope(bgResult);
|
|
383
|
+
if (envelope) {
|
|
384
|
+
return {
|
|
385
|
+
success: envelope.success,
|
|
386
|
+
flowObjectName: envelope.flowObjectName || options.scopedName,
|
|
387
|
+
flowObjectType: envelope.flowObjectType || options.type,
|
|
388
|
+
contextId: envelope.contextId || undefined,
|
|
389
|
+
executionDate: envelope.executionDate || undefined,
|
|
390
|
+
domainId: envelope.domainId || undefined,
|
|
391
|
+
outputs: envelope.outputs || undefined,
|
|
392
|
+
debugOutput: envelope.debugOutput || undefined,
|
|
393
|
+
errorMessage: envelope.errorMessage || undefined,
|
|
394
|
+
rawScriptResult: bgResult
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
this._logger.warn('Could not extract flow result envelope from script output');
|
|
398
|
+
return {
|
|
399
|
+
success: false,
|
|
400
|
+
flowObjectName: options.scopedName,
|
|
401
|
+
flowObjectType: options.type,
|
|
402
|
+
errorMessage: 'Could not parse flow execution result from script output. ' +
|
|
403
|
+
'The script may have failed before producing output.',
|
|
404
|
+
rawScriptResult: bgResult
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
// ================================================================
|
|
408
|
+
// Lifecycle Script Builders
|
|
409
|
+
// ================================================================
|
|
410
|
+
/** Validate that a context ID is non-empty. */
|
|
411
|
+
_validateContextId(contextId) {
|
|
412
|
+
if (!contextId || contextId.trim().length === 0) {
|
|
413
|
+
throw new Error('Context ID is required');
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/** Escape a string for embedding in a generated SN script single-quoted string. */
|
|
417
|
+
_escapeForScript(str) {
|
|
418
|
+
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
419
|
+
}
|
|
420
|
+
/** Build script to query sys_flow_context status. */
|
|
421
|
+
_buildContextStatusScript(contextId) {
|
|
422
|
+
const escapedId = this._escapeForScript(contextId);
|
|
423
|
+
return `(function() {
|
|
424
|
+
var __RESULT_MARKER = '${RESULT_MARKER}';
|
|
425
|
+
try {
|
|
426
|
+
var gr = new GlideRecord('sys_flow_context');
|
|
427
|
+
if (gr.get('${escapedId}')) {
|
|
428
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
429
|
+
__flowResult: true,
|
|
430
|
+
success: true,
|
|
431
|
+
contextId: '${escapedId}',
|
|
432
|
+
found: true,
|
|
433
|
+
state: '' + gr.getValue('state'),
|
|
434
|
+
name: '' + gr.getValue('name'),
|
|
435
|
+
started: gr.getValue('started') ? '' + gr.getValue('started') : null,
|
|
436
|
+
ended: gr.getValue('ended') ? '' + gr.getValue('ended') : null,
|
|
437
|
+
errorMessage: null
|
|
438
|
+
}));
|
|
439
|
+
} else {
|
|
440
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
441
|
+
__flowResult: true,
|
|
442
|
+
success: true,
|
|
443
|
+
contextId: '${escapedId}',
|
|
444
|
+
found: false,
|
|
445
|
+
state: null,
|
|
446
|
+
name: null,
|
|
447
|
+
started: null,
|
|
448
|
+
ended: null,
|
|
449
|
+
errorMessage: null
|
|
450
|
+
}));
|
|
451
|
+
}
|
|
452
|
+
} catch (ex) {
|
|
453
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
454
|
+
__flowResult: true,
|
|
455
|
+
success: false,
|
|
456
|
+
contextId: '${escapedId}',
|
|
457
|
+
found: false,
|
|
458
|
+
errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
|
|
459
|
+
}));
|
|
460
|
+
}
|
|
461
|
+
})();`;
|
|
462
|
+
}
|
|
463
|
+
/** Build script to retrieve flow outputs via FlowAPI.getOutputs(). */
|
|
464
|
+
_buildGetOutputsScript(contextId) {
|
|
465
|
+
const escapedId = this._escapeForScript(contextId);
|
|
466
|
+
return `(function() {
|
|
467
|
+
var __RESULT_MARKER = '${RESULT_MARKER}';
|
|
468
|
+
try {
|
|
469
|
+
var outputs = sn_fd.FlowAPI.getOutputs('${escapedId}');
|
|
470
|
+
var outputObj = {};
|
|
471
|
+
if (outputs) {
|
|
472
|
+
for (var key in outputs) {
|
|
473
|
+
if (outputs.hasOwnProperty(key)) {
|
|
474
|
+
outputObj[key] = '' + outputs[key];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
479
|
+
__flowResult: true,
|
|
480
|
+
success: true,
|
|
481
|
+
contextId: '${escapedId}',
|
|
482
|
+
outputs: outputObj,
|
|
483
|
+
errorMessage: null
|
|
484
|
+
}));
|
|
485
|
+
} catch (ex) {
|
|
486
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
487
|
+
__flowResult: true,
|
|
488
|
+
success: false,
|
|
489
|
+
contextId: '${escapedId}',
|
|
490
|
+
outputs: null,
|
|
491
|
+
errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
})();`;
|
|
495
|
+
}
|
|
496
|
+
/** Build script to retrieve flow error via FlowAPI.getErrorMessage(). */
|
|
497
|
+
_buildGetErrorScript(contextId) {
|
|
498
|
+
const escapedId = this._escapeForScript(contextId);
|
|
499
|
+
return `(function() {
|
|
500
|
+
var __RESULT_MARKER = '${RESULT_MARKER}';
|
|
501
|
+
try {
|
|
502
|
+
var errorMsg = sn_fd.FlowAPI.getErrorMessage('${escapedId}');
|
|
503
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
504
|
+
__flowResult: true,
|
|
505
|
+
success: true,
|
|
506
|
+
contextId: '${escapedId}',
|
|
507
|
+
flowErrorMessage: errorMsg ? '' + errorMsg : null,
|
|
508
|
+
errorMessage: null
|
|
509
|
+
}));
|
|
510
|
+
} catch (ex) {
|
|
511
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
512
|
+
__flowResult: true,
|
|
513
|
+
success: false,
|
|
514
|
+
contextId: '${escapedId}',
|
|
515
|
+
flowErrorMessage: null,
|
|
516
|
+
errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
|
|
517
|
+
}));
|
|
518
|
+
}
|
|
519
|
+
})();`;
|
|
520
|
+
}
|
|
521
|
+
/** Build script to cancel a flow via FlowAPI.cancel(). */
|
|
522
|
+
_buildCancelScript(contextId, reason) {
|
|
523
|
+
const escapedId = this._escapeForScript(contextId);
|
|
524
|
+
const escapedReason = this._escapeForScript(reason);
|
|
525
|
+
return `(function() {
|
|
526
|
+
var __RESULT_MARKER = '${RESULT_MARKER}';
|
|
527
|
+
try {
|
|
528
|
+
sn_fd.FlowAPI.cancel('${escapedId}', '${escapedReason}');
|
|
529
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
530
|
+
__flowResult: true,
|
|
531
|
+
success: true,
|
|
532
|
+
contextId: '${escapedId}',
|
|
533
|
+
errorMessage: null
|
|
534
|
+
}));
|
|
535
|
+
} catch (ex) {
|
|
536
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
537
|
+
__flowResult: true,
|
|
538
|
+
success: false,
|
|
539
|
+
contextId: '${escapedId}',
|
|
540
|
+
errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
|
|
541
|
+
}));
|
|
542
|
+
}
|
|
543
|
+
})();`;
|
|
544
|
+
}
|
|
545
|
+
/** Build script to send a message to a paused flow via FlowAPI.sendMessage(). */
|
|
546
|
+
_buildSendMessageScript(contextId, message, payload) {
|
|
547
|
+
const escapedId = this._escapeForScript(contextId);
|
|
548
|
+
const escapedMessage = this._escapeForScript(message);
|
|
549
|
+
const escapedPayload = this._escapeForScript(payload);
|
|
550
|
+
return `(function() {
|
|
551
|
+
var __RESULT_MARKER = '${RESULT_MARKER}';
|
|
552
|
+
try {
|
|
553
|
+
sn_fd.FlowAPI.sendMessage('${escapedId}', '${escapedMessage}', '${escapedPayload}');
|
|
554
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
555
|
+
__flowResult: true,
|
|
556
|
+
success: true,
|
|
557
|
+
contextId: '${escapedId}',
|
|
558
|
+
errorMessage: null
|
|
559
|
+
}));
|
|
560
|
+
} catch (ex) {
|
|
561
|
+
gs.info(__RESULT_MARKER + JSON.stringify({
|
|
562
|
+
__flowResult: true,
|
|
563
|
+
success: false,
|
|
564
|
+
contextId: '${escapedId}',
|
|
565
|
+
errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
|
|
566
|
+
}));
|
|
567
|
+
}
|
|
568
|
+
})();`;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
//# sourceMappingURL=FlowManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowManager.js","sourceRoot":"","sources":["../../../src/sn/flow/FlowManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAmC,MAAM,6BAA6B,CAAC;AACxG,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAiB3C,MAAM,aAAa,GAAG,wBAAw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,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACnD,OAAO;6BACc,aAAa;;kDAEQ,SAAS;;;;;;;;;;;;0BAYjC,SAAS;;;;;;;;0BAQT,SAAS;;;;;MAK7B,CAAC;IACH,CAAC;IAED,yEAAyE;IACzE,oBAAoB,CAAC,SAAiB;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACnD,OAAO;6BACc,aAAa;;wDAEc,SAAS;;;;0BAIvC,SAAS;;;;;;;;0BAQT,SAAS;;;;;MAK7B,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,kBAAkB,CAAC,SAAiB,EAAE,MAAc;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACpD,OAAO;6BACc,aAAa;;gCAEV,SAAS,OAAO,aAAa;;;;0BAInC,SAAS;;;;;;;0BAOT,SAAS;;;;MAI7B,CAAC;IACH,CAAC;IAED,iFAAiF;IACjF,uBAAuB,CAAC,SAAiB,EAAE,OAAe,EAAE,OAAe;QACvE,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACtD,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO;6BACc,aAAa;;qCAEL,SAAS,OAAO,cAAc,OAAO,cAAc;;;;0BAI9D,SAAS;;;;;;;0BAOT,SAAS;;;;MAI7B,CAAC;IACH,CAAC;CACJ"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Models for Flow Designer execution operations.
|
|
3
|
+
* Supports executing flows, subflows, and actions via BackgroundScriptExecutor
|
|
4
|
+
* using the sn_fd.FlowAPI.getRunner() (ScriptableFlowRunner) API.
|
|
5
|
+
*/
|
|
6
|
+
/** Type of Flow Designer object to execute. */
|
|
7
|
+
export type FlowObjectType = 'flow' | 'subflow' | 'action';
|
|
8
|
+
/** Execution mode: synchronous (foreground) or asynchronous (background). */
|
|
9
|
+
export type FlowExecutionMode = 'foreground' | 'background';
|
|
10
|
+
/** Options for executing a Flow Designer object (flow, subflow, or action). */
|
|
11
|
+
export interface ExecuteFlowOptions {
|
|
12
|
+
/** Scoped name of the flow/subflow/action, e.g. "global.my_flow" */
|
|
13
|
+
scopedName: string;
|
|
14
|
+
/** Type of object to execute */
|
|
15
|
+
type: FlowObjectType;
|
|
16
|
+
/** Input name-value pairs to pass to the flow/subflow/action */
|
|
17
|
+
inputs?: Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Execution mode: 'foreground' (sync) or 'background' (async).
|
|
20
|
+
* Default: 'foreground'
|
|
21
|
+
*/
|
|
22
|
+
mode?: FlowExecutionMode;
|
|
23
|
+
/** Timeout in milliseconds (optional, SN default is 30s) */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Quick mode: skip execution detail records for better performance.
|
|
27
|
+
* Default: false
|
|
28
|
+
*/
|
|
29
|
+
quick?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Scope context for BackgroundScriptExecutor.
|
|
32
|
+
* Can be a scope name ("global", "x_myapp_custom") or a 32-character sys_id.
|
|
33
|
+
* Default: uses the FlowManager's default scope.
|
|
34
|
+
*/
|
|
35
|
+
scope?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Convenience options for executing a flow (type is implied). */
|
|
38
|
+
export interface ExecuteFlowByNameOptions extends Omit<ExecuteFlowOptions, 'type'> {
|
|
39
|
+
}
|
|
40
|
+
/** Convenience options for executing a subflow (type is implied). */
|
|
41
|
+
export interface ExecuteSubflowOptions extends Omit<ExecuteFlowOptions, 'type'> {
|
|
42
|
+
}
|
|
43
|
+
/** Convenience options for executing an action (type is implied). */
|
|
44
|
+
export interface ExecuteActionOptions extends Omit<ExecuteFlowOptions, 'type'> {
|
|
45
|
+
}
|
|
46
|
+
/** Structured result from executing a flow/subflow/action. */
|
|
47
|
+
export interface FlowExecutionResult {
|
|
48
|
+
/** Whether the execution completed without error */
|
|
49
|
+
success: boolean;
|
|
50
|
+
/** The scoped name of the executed flow object, e.g. "global.my_flow" */
|
|
51
|
+
flowObjectName: string;
|
|
52
|
+
/** Type of flow object that was executed */
|
|
53
|
+
flowObjectType: FlowObjectType;
|
|
54
|
+
/** sys_id of the execution context record (if not quick mode) */
|
|
55
|
+
contextId?: string;
|
|
56
|
+
/** Execution date/time as a string from the SN server */
|
|
57
|
+
executionDate?: string;
|
|
58
|
+
/** Domain sys_id (for domain-separated instances) */
|
|
59
|
+
domainId?: string;
|
|
60
|
+
/** Output name-value pairs returned by the flow/subflow/action */
|
|
61
|
+
outputs?: Record<string, unknown>;
|
|
62
|
+
/** Raw debug() output from ScriptableFlowRunnerResult */
|
|
63
|
+
debugOutput?: string;
|
|
64
|
+
/** Error message if execution failed */
|
|
65
|
+
errorMessage?: string;
|
|
66
|
+
/** The raw BackgroundScriptExecutionResult for advanced inspection */
|
|
67
|
+
rawScriptResult?: unknown;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* JSON envelope structure used for communication between
|
|
71
|
+
* the generated SN server-side script and the FlowManager parser.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export interface FlowScriptResultEnvelope {
|
|
75
|
+
__flowResult: true;
|
|
76
|
+
success: boolean;
|
|
77
|
+
flowObjectName: string;
|
|
78
|
+
flowObjectType: string;
|
|
79
|
+
contextId: string | null;
|
|
80
|
+
executionDate: string | null;
|
|
81
|
+
domainId: string | null;
|
|
82
|
+
outputs: Record<string, unknown> | null;
|
|
83
|
+
debugOutput: string;
|
|
84
|
+
errorMessage: string | null;
|
|
85
|
+
}
|
|
86
|
+
/** Known states of a flow context record in sys_flow_context. */
|
|
87
|
+
export type FlowContextState = 'QUEUED' | 'IN_PROGRESS' | 'WAITING' | 'COMPLETE' | 'CANCELLED' | 'ERROR' | string;
|
|
88
|
+
/** Result from querying a flow context's status. */
|
|
89
|
+
export interface FlowContextStatusResult {
|
|
90
|
+
success: boolean;
|
|
91
|
+
contextId: string;
|
|
92
|
+
found: boolean;
|
|
93
|
+
state?: FlowContextState;
|
|
94
|
+
name?: string;
|
|
95
|
+
started?: string;
|
|
96
|
+
ended?: string;
|
|
97
|
+
errorMessage?: string;
|
|
98
|
+
rawScriptResult?: unknown;
|
|
99
|
+
}
|
|
100
|
+
/** Result from retrieving outputs of a completed flow context. */
|
|
101
|
+
export interface FlowOutputsResult {
|
|
102
|
+
success: boolean;
|
|
103
|
+
contextId: string;
|
|
104
|
+
outputs?: Record<string, unknown>;
|
|
105
|
+
errorMessage?: string;
|
|
106
|
+
rawScriptResult?: unknown;
|
|
107
|
+
}
|
|
108
|
+
/** Result from retrieving error messages of a flow context. */
|
|
109
|
+
export interface FlowErrorResult {
|
|
110
|
+
success: boolean;
|
|
111
|
+
contextId: string;
|
|
112
|
+
flowErrorMessage?: string;
|
|
113
|
+
errorMessage?: string;
|
|
114
|
+
rawScriptResult?: unknown;
|
|
115
|
+
}
|
|
116
|
+
/** Result from cancelling a flow context. */
|
|
117
|
+
export interface FlowCancelResult {
|
|
118
|
+
success: boolean;
|
|
119
|
+
contextId: string;
|
|
120
|
+
errorMessage?: string;
|
|
121
|
+
rawScriptResult?: unknown;
|
|
122
|
+
}
|
|
123
|
+
/** Result from sending a message to a paused flow. */
|
|
124
|
+
export interface FlowSendMessageResult {
|
|
125
|
+
success: boolean;
|
|
126
|
+
contextId: string;
|
|
127
|
+
errorMessage?: string;
|
|
128
|
+
rawScriptResult?: unknown;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* JSON envelope for lifecycle operations (status, outputs, errors, cancel, message).
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
export interface FlowLifecycleEnvelope {
|
|
135
|
+
__flowResult: true;
|
|
136
|
+
success: boolean;
|
|
137
|
+
contextId: string;
|
|
138
|
+
errorMessage: string | null;
|
|
139
|
+
found?: boolean;
|
|
140
|
+
state?: string | null;
|
|
141
|
+
name?: string | null;
|
|
142
|
+
started?: string | null;
|
|
143
|
+
ended?: string | null;
|
|
144
|
+
outputs?: Record<string, unknown> | null;
|
|
145
|
+
flowErrorMessage?: string | null;
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowModels.js","sourceRoot":"","sources":["../../../src/sn/flow/FlowModels.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonisoft/now-sdk-ext-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Comprehensive TypeScript library extending ServiceNow SDK with application management, ATF testing, real-time log monitoring, AMB event subscriptions, and automation tools",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"servicenow",
|