import { ServiceNowInstance } from "./ServiceNowInstance.js"; import { ServiceNowRequest } from "../comm/http/ServiceNowRequest.js"; import { Logger } from "../util/Logger.js"; export declare class BackgroundScriptExecutor { snRequest: ServiceNowRequest; instance: ServiceNowInstance; scope: string; private _tableAPI; private _scopeCache; _logger: Logger; constructor(instance: ServiceNowInstance, scope: string); /** * Refuses a script the policy does not permit, before it is sent anywhere. * * Running caller-supplied code always needs `execute`; the scan decides whether it * also needs `write`. The scan is unsound by design and leans toward `write` on * anything it cannot resolve — see ScanScript for what it cannot see at all. * * Pass the script that will ACTUALLY be sent. Callers doing `{param}` substitution * must substitute first, or a parameter value of `gr.insert()` walks straight past. */ private assertScriptPermitted; /** @returns what this script needs, for the HTTP layer to agree with. */ executeScript(script: string, scope?: string, instance?: ServiceNowInstance): Promise; parseScriptResult(responseXML: string): BackgroundScriptExecutionResult; getBackgroundScriptCSRFToken(): Promise; /** * Execute a script by creating a sys_trigger record. * This is an alternative to the background script page approach. * Creates a scheduled job that runs the script once and optionally deletes itself. * * @param script The script to execute * @param description Optional description for the trigger * @param autoDelete If true, wraps the script in try/finally to delete the trigger after execution * @returns TriggerExecutionResult with details about the created trigger */ executeScriptViaTrigger(script: string, description?: string, autoDelete?: boolean): Promise; /** * Execute a script using the best available method. * First tries the standard executeScript() (background script page), * and on failure falls back to executeScriptViaTrigger(). * * @param script The script to execute * @param scope Optional scope for the background script execution * @returns Either a BackgroundScriptExecutionResult or TriggerExecutionResult */ executeScriptAuto(script: string, scope?: string): Promise; /** * Format a Date object into ServiceNow datetime format: YYYY-MM-DD HH:MM:SS */ private _formatDateForServiceNow; /** * Resolve a scope value to a sys_id for use with /sys.scripts.do. * ServiceNow's background script form expects a sys_id in the sys_scope field, * not a scope name. This method handles: * - 32-char hex strings: passed through as-is (already a sys_id) * - Scope names (e.g., "global", "x_myapp_custom"): looked up in sys_scope table * Results are cached per executor instance to avoid repeated lookups. */ private _resolveScopeToSysId; /** * Strips closing tags for HTML void elements that fast-xml-parser cannot handle. * ServiceNow's /sys.scripts.do returns malformed HTML with closing tags for * void elements like , ,
, , , etc. */ private fixMalformedHTML; private _parseBGScriptResult; private _parseAffectedRecords; } export type CompositeScriptExecutionResult = { consoleResult: string[]; rawResult: string; scriptResults: ScriptExecutionOutputLine[]; }; export type BackgroundScriptExecutionResult = { raw: string; result: string; affectedRecords: string; consoleResult: string[]; rawResult: string; scriptResults: ScriptExecutionOutputLine[]; }; export declare class ScriptExecutionOutputLine { private _line; private _isDebug; private _isSystem; private _isScript; constructor(line: string); get line(): string; set line(val: string); asDebugLine(isDebugLine?: boolean): ScriptExecutionOutputLine; asSystemLine(isSystemLine?: boolean): ScriptExecutionOutputLine; asScriptLine(isScriptLine?: boolean): ScriptExecutionOutputLine; } export interface BackgroundScriptExecutorOptions { instance?: ServiceNowInstance; scope?: string; } export interface TriggerExecutionResult { success: boolean; triggerSysId: string; triggerName: string; nextAction: string; autoDelete: boolean; message: string; }