@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.
Files changed (68) hide show
  1. package/dist/comm/http/RequestHandler.js +7 -11
  2. package/dist/comm/http/RequestHandler.js.map +1 -1
  3. package/dist/comm/http/TableAPIRequest.js +3 -10
  4. package/dist/comm/http/TableAPIRequest.js.map +1 -1
  5. package/dist/index.d.ts +18 -0
  6. package/dist/index.js +18 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/sn/BackgroundScriptExecutor.d.ts +34 -0
  9. package/dist/sn/BackgroundScriptExecutor.js +96 -0
  10. package/dist/sn/BackgroundScriptExecutor.js.map +1 -1
  11. package/dist/sn/application/ApplicationManager.d.ts +58 -1
  12. package/dist/sn/application/ApplicationManager.js +202 -11
  13. package/dist/sn/application/ApplicationManager.js.map +1 -1
  14. package/dist/sn/application/StoreApplicationModels.d.ts +99 -0
  15. package/dist/sn/application/StoreApplicationModels.js +2 -0
  16. package/dist/sn/application/StoreApplicationModels.js.map +1 -0
  17. package/dist/sn/attachment/AttachmentManager.d.ts +32 -0
  18. package/dist/sn/attachment/AttachmentManager.js +87 -0
  19. package/dist/sn/attachment/AttachmentManager.js.map +1 -0
  20. package/dist/sn/attachment/AttachmentModels.d.ts +28 -0
  21. package/dist/sn/attachment/AttachmentModels.js +2 -0
  22. package/dist/sn/attachment/AttachmentModels.js.map +1 -0
  23. package/dist/sn/batch/BatchModels.d.ts +90 -0
  24. package/dist/sn/batch/BatchModels.js +5 -0
  25. package/dist/sn/batch/BatchModels.js.map +1 -0
  26. package/dist/sn/batch/BatchOperations.d.ts +40 -0
  27. package/dist/sn/batch/BatchOperations.js +169 -0
  28. package/dist/sn/batch/BatchOperations.js.map +1 -0
  29. package/dist/sn/schema/SchemaDiscovery.d.ts +68 -0
  30. package/dist/sn/schema/SchemaDiscovery.js +346 -0
  31. package/dist/sn/schema/SchemaDiscovery.js.map +1 -0
  32. package/dist/sn/schema/SchemaModels.d.ts +277 -0
  33. package/dist/sn/schema/SchemaModels.js +5 -0
  34. package/dist/sn/schema/SchemaModels.js.map +1 -0
  35. package/dist/sn/scope/ScopeManager.d.ts +51 -0
  36. package/dist/sn/scope/ScopeManager.js +177 -0
  37. package/dist/sn/scope/ScopeManager.js.map +1 -0
  38. package/dist/sn/scope/ScopeModels.d.ts +66 -0
  39. package/dist/sn/scope/ScopeModels.js +5 -0
  40. package/dist/sn/scope/ScopeModels.js.map +1 -0
  41. package/dist/sn/scriptsync/ScriptSync.d.ts +38 -0
  42. package/dist/sn/scriptsync/ScriptSync.js +266 -0
  43. package/dist/sn/scriptsync/ScriptSync.js.map +1 -0
  44. package/dist/sn/scriptsync/ScriptSyncModels.d.ts +55 -0
  45. package/dist/sn/scriptsync/ScriptSyncModels.js +8 -0
  46. package/dist/sn/scriptsync/ScriptSyncModels.js.map +1 -0
  47. package/dist/sn/scriptsync/ScriptWatcher.d.ts +30 -0
  48. package/dist/sn/scriptsync/ScriptWatcher.js +74 -0
  49. package/dist/sn/scriptsync/ScriptWatcher.js.map +1 -0
  50. package/dist/sn/task/TaskModels.d.ts +85 -0
  51. package/dist/sn/task/TaskModels.js +5 -0
  52. package/dist/sn/task/TaskModels.js.map +1 -0
  53. package/dist/sn/task/TaskOperations.d.ts +63 -0
  54. package/dist/sn/task/TaskOperations.js +195 -0
  55. package/dist/sn/task/TaskOperations.js.map +1 -0
  56. package/dist/sn/updateset/UpdateSetManager.d.ts +78 -0
  57. package/dist/sn/updateset/UpdateSetManager.js +391 -0
  58. package/dist/sn/updateset/UpdateSetManager.js.map +1 -0
  59. package/dist/sn/updateset/UpdateSetModels.d.ts +177 -0
  60. package/dist/sn/updateset/UpdateSetModels.js +5 -0
  61. package/dist/sn/updateset/UpdateSetModels.js.map +1 -0
  62. package/dist/sn/workflow/WorkflowManager.d.ts +81 -0
  63. package/dist/sn/workflow/WorkflowManager.js +388 -0
  64. package/dist/sn/workflow/WorkflowManager.js.map +1 -0
  65. package/dist/sn/workflow/WorkflowModels.d.ts +242 -0
  66. package/dist/sn/workflow/WorkflowModels.js +5 -0
  67. package/dist/sn/workflow/WorkflowModels.js.map +1 -0
  68. package/package.json +5 -5
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Models for batch operations against ServiceNow tables.
3
+ */
4
+ /**
5
+ * A single create operation within a batch.
6
+ */
7
+ export interface BatchCreateOperation {
8
+ /** The target table name (e.g., "incident", "sys_user") */
9
+ table: string;
10
+ /** The field data to create the record with */
11
+ data: Record<string, unknown>;
12
+ /**
13
+ * Optional key to save the resulting sys_id under.
14
+ * Other operations can reference this via ${saveAs} in their data values.
15
+ */
16
+ saveAs?: string;
17
+ }
18
+ /**
19
+ * Options for a batch create operation.
20
+ */
21
+ export interface BatchCreateOptions {
22
+ /** The ordered list of create operations to execute */
23
+ operations: BatchCreateOperation[];
24
+ /**
25
+ * When true (default), stops on first error (transactional behavior).
26
+ * When false, continues past errors.
27
+ */
28
+ transaction?: boolean;
29
+ /** Optional progress callback invoked after each operation */
30
+ onProgress?: (message: string) => void;
31
+ }
32
+ /**
33
+ * Result of a batch create operation.
34
+ */
35
+ export interface BatchCreateResult {
36
+ /** True if all operations completed without error */
37
+ success: boolean;
38
+ /** Number of records successfully created */
39
+ createdCount: number;
40
+ /** Map of saveAs keys to their created sys_ids */
41
+ sysIds: Record<string, string>;
42
+ /** Details of any errors encountered */
43
+ errors: Array<{
44
+ operationIndex: number;
45
+ table: string;
46
+ error: string;
47
+ }>;
48
+ /** Total execution time in milliseconds */
49
+ executionTimeMs: number;
50
+ }
51
+ /**
52
+ * A single update operation within a batch.
53
+ */
54
+ export interface BatchUpdateOperation {
55
+ /** The target table name */
56
+ table: string;
57
+ /** The sys_id of the record to update */
58
+ sysId: string;
59
+ /** The field data to update */
60
+ data: Record<string, unknown>;
61
+ }
62
+ /**
63
+ * Options for a batch update operation.
64
+ */
65
+ export interface BatchUpdateOptions {
66
+ /** The ordered list of update operations to execute */
67
+ updates: BatchUpdateOperation[];
68
+ /** When true, stops on first error. Defaults to false. */
69
+ stopOnError?: boolean;
70
+ /** Optional progress callback invoked after each operation */
71
+ onProgress?: (message: string) => void;
72
+ }
73
+ /**
74
+ * Result of a batch update operation.
75
+ */
76
+ export interface BatchUpdateResult {
77
+ /** True if all updates completed without error */
78
+ success: boolean;
79
+ /** Number of records successfully updated */
80
+ updatedCount: number;
81
+ /** Details of any errors encountered */
82
+ errors: Array<{
83
+ updateIndex: number;
84
+ table: string;
85
+ sysId: string;
86
+ error: string;
87
+ }>;
88
+ /** Total execution time in milliseconds */
89
+ executionTimeMs: number;
90
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Models for batch operations against ServiceNow tables.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=BatchModels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchModels.js","sourceRoot":"","sources":["../../../src/sn/batch/BatchModels.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,40 @@
1
+ import { ServiceNowInstance } from "../ServiceNowInstance.js";
2
+ import { BatchCreateOptions, BatchCreateResult, BatchUpdateOptions, BatchUpdateResult } from './BatchModels.js';
3
+ /**
4
+ * Provides batch create and update operations against ServiceNow tables.
5
+ * Operations are executed sequentially, with optional transactional (stop-on-error) behavior
6
+ * and variable reference resolution between operations.
7
+ */
8
+ export declare class BatchOperations {
9
+ private _logger;
10
+ private _req;
11
+ private _tableAPI;
12
+ private _instance;
13
+ constructor(instance: ServiceNowInstance);
14
+ /**
15
+ * Execute a batch of create operations sequentially.
16
+ * Supports variable references: if an operation has saveAs="myKey", later operations
17
+ * can reference ${myKey} in their data values to substitute the created sys_id.
18
+ *
19
+ * @param options Batch create options including operations list and transaction flag
20
+ * @returns BatchCreateResult with counts, sys_ids, errors, and timing
21
+ */
22
+ batchCreate(options: BatchCreateOptions): Promise<BatchCreateResult>;
23
+ /**
24
+ * Execute a batch of update operations sequentially.
25
+ *
26
+ * @param options Batch update options including updates list and stopOnError flag
27
+ * @returns BatchUpdateResult with counts, errors, and timing
28
+ */
29
+ batchUpdate(options: BatchUpdateOptions): Promise<BatchUpdateResult>;
30
+ /**
31
+ * Resolve ${variable} references in data values using the sysIds map.
32
+ * Serializes the data to JSON, replaces all ${key} patterns with the
33
+ * corresponding sys_id value, then deserializes back.
34
+ *
35
+ * @param data The record data that may contain variable references
36
+ * @param sysIds Map of variable names to sys_id values
37
+ * @returns A new data object with all references resolved
38
+ */
39
+ private resolveVariableReferences;
40
+ }
@@ -0,0 +1,169 @@
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 batch create and update operations against ServiceNow tables.
6
+ * Operations are executed sequentially, with optional transactional (stop-on-error) behavior
7
+ * and variable reference resolution between operations.
8
+ */
9
+ export class BatchOperations {
10
+ _logger = new Logger("BatchOperations");
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
+ * Execute a batch of create operations sequentially.
21
+ * Supports variable references: if an operation has saveAs="myKey", later operations
22
+ * can reference ${myKey} in their data values to substitute the created sys_id.
23
+ *
24
+ * @param options Batch create options including operations list and transaction flag
25
+ * @returns BatchCreateResult with counts, sys_ids, errors, and timing
26
+ */
27
+ async batchCreate(options) {
28
+ const startTime = Date.now();
29
+ const transaction = options.transaction !== undefined ? options.transaction : true;
30
+ const sysIds = {};
31
+ const errors = [];
32
+ let createdCount = 0;
33
+ this._logger.info(`Starting batch create with ${options.operations.length} operations (transaction=${transaction})`);
34
+ for (let i = 0; i < options.operations.length; i++) {
35
+ const op = options.operations[i];
36
+ try {
37
+ // Resolve variable references in the data using previously saved sys_ids
38
+ const resolvedData = this.resolveVariableReferences(op.data, sysIds);
39
+ if (options.onProgress) {
40
+ options.onProgress(`Creating record ${i + 1}/${options.operations.length} in table '${op.table}'`);
41
+ }
42
+ this._logger.info(`Batch create [${i + 1}/${options.operations.length}]: POST to '${op.table}'`);
43
+ const response = await this._tableAPI.post(op.table, {}, resolvedData);
44
+ if (response && (response.status === 200 || response.status === 201) && response.bodyObject?.result?.sys_id) {
45
+ const createdSysId = response.bodyObject.result.sys_id;
46
+ createdCount++;
47
+ if (op.saveAs) {
48
+ sysIds[op.saveAs] = createdSysId;
49
+ }
50
+ this._logger.info(`Batch create [${i + 1}]: Created sys_id=${createdSysId} in '${op.table}'`);
51
+ }
52
+ else {
53
+ const errorMsg = `Failed to create record in '${op.table}'. Status: ${response?.status ?? 'unknown'}`;
54
+ this._logger.error(errorMsg);
55
+ errors.push({ operationIndex: i, table: op.table, error: errorMsg });
56
+ if (transaction) {
57
+ if (options.onProgress) {
58
+ options.onProgress(`Stopping batch: error at operation ${i + 1}`);
59
+ }
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ catch (err) {
65
+ const errorMsg = err instanceof Error ? err.message : String(err);
66
+ this._logger.error(`Batch create [${i + 1}] exception: ${errorMsg}`);
67
+ errors.push({ operationIndex: i, table: op.table, error: errorMsg });
68
+ if (transaction) {
69
+ if (options.onProgress) {
70
+ options.onProgress(`Stopping batch: error at operation ${i + 1}`);
71
+ }
72
+ break;
73
+ }
74
+ }
75
+ }
76
+ const executionTimeMs = Date.now() - startTime;
77
+ if (options.onProgress) {
78
+ options.onProgress(`Batch create complete: ${createdCount} created, ${errors.length} errors`);
79
+ }
80
+ return {
81
+ success: errors.length === 0,
82
+ createdCount,
83
+ sysIds,
84
+ errors,
85
+ executionTimeMs
86
+ };
87
+ }
88
+ /**
89
+ * Execute a batch of update operations sequentially.
90
+ *
91
+ * @param options Batch update options including updates list and stopOnError flag
92
+ * @returns BatchUpdateResult with counts, errors, and timing
93
+ */
94
+ async batchUpdate(options) {
95
+ const startTime = Date.now();
96
+ const stopOnError = options.stopOnError ?? false;
97
+ const errors = [];
98
+ let updatedCount = 0;
99
+ this._logger.info(`Starting batch update with ${options.updates.length} updates (stopOnError=${stopOnError})`);
100
+ for (let i = 0; i < options.updates.length; i++) {
101
+ const update = options.updates[i];
102
+ try {
103
+ if (options.onProgress) {
104
+ options.onProgress(`Updating record ${i + 1}/${options.updates.length} in table '${update.table}'`);
105
+ }
106
+ this._logger.info(`Batch update [${i + 1}/${options.updates.length}]: PUT to '${update.table}/${update.sysId}'`);
107
+ const response = await this._tableAPI.put(update.table, update.sysId, update.data);
108
+ if (response && response.status === 200 && response.bodyObject?.result) {
109
+ updatedCount++;
110
+ this._logger.info(`Batch update [${i + 1}]: Updated '${update.table}/${update.sysId}'`);
111
+ }
112
+ else {
113
+ const errorMsg = `Failed to update record '${update.sysId}' in '${update.table}'. Status: ${response?.status ?? 'unknown'}`;
114
+ this._logger.error(errorMsg);
115
+ errors.push({ updateIndex: i, table: update.table, sysId: update.sysId, error: errorMsg });
116
+ if (stopOnError) {
117
+ if (options.onProgress) {
118
+ options.onProgress(`Stopping batch: error at update ${i + 1}`);
119
+ }
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ catch (err) {
125
+ const errorMsg = err instanceof Error ? err.message : String(err);
126
+ this._logger.error(`Batch update [${i + 1}] exception: ${errorMsg}`);
127
+ errors.push({ updateIndex: i, table: update.table, sysId: update.sysId, error: errorMsg });
128
+ if (stopOnError) {
129
+ if (options.onProgress) {
130
+ options.onProgress(`Stopping batch: error at update ${i + 1}`);
131
+ }
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ const executionTimeMs = Date.now() - startTime;
137
+ if (options.onProgress) {
138
+ options.onProgress(`Batch update complete: ${updatedCount} updated, ${errors.length} errors`);
139
+ }
140
+ return {
141
+ success: errors.length === 0,
142
+ updatedCount,
143
+ errors,
144
+ executionTimeMs
145
+ };
146
+ }
147
+ /**
148
+ * Resolve ${variable} references in data values using the sysIds map.
149
+ * Serializes the data to JSON, replaces all ${key} patterns with the
150
+ * corresponding sys_id value, then deserializes back.
151
+ *
152
+ * @param data The record data that may contain variable references
153
+ * @param sysIds Map of variable names to sys_id values
154
+ * @returns A new data object with all references resolved
155
+ */
156
+ resolveVariableReferences(data, sysIds) {
157
+ if (Object.keys(sysIds).length === 0) {
158
+ return data;
159
+ }
160
+ let json = JSON.stringify(data);
161
+ for (const [key, value] of Object.entries(sysIds)) {
162
+ // Use a global regex to replace all occurrences of ${key}
163
+ const pattern = new RegExp('\\$\\{' + key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\}', 'g');
164
+ json = json.replace(pattern, value);
165
+ }
166
+ return JSON.parse(json);
167
+ }
168
+ }
169
+ //# sourceMappingURL=BatchOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchOperations.js","sourceRoot":"","sources":["../../../src/sn/batch/BatchOperations.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;AASlE;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAChB,OAAO,GAAW,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAChD,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;;;;;;;OAOG;IACI,KAAK,CAAC,WAAW,CAAC,OAA2B;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,WAA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,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAChD,0DAA0D;YAC1D,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;YAC/F,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;IACvD,CAAC;CACJ"}
@@ -0,0 +1,68 @@
1
+ import { ServiceNowInstance } from "../ServiceNowInstance.js";
2
+ import { TableSchemaOptions, TableSchema, FieldExplanation, CatalogValidationResult } from './SchemaModels.js';
3
+ /**
4
+ * SchemaDiscovery provides operations for discovering ServiceNow table schemas,
5
+ * explaining fields, and validating catalog configurations.
6
+ */
7
+ export declare class SchemaDiscovery {
8
+ private static readonly SYS_DB_OBJECT_TABLE;
9
+ private static readonly SYS_DICTIONARY_TABLE;
10
+ private static readonly SYS_CHOICE_TABLE;
11
+ private static readonly ITEM_OPTION_NEW_TABLE;
12
+ private static readonly CATALOG_UI_POLICY_TABLE;
13
+ private _logger;
14
+ private _req;
15
+ private _tableAPI;
16
+ private _instance;
17
+ constructor(instance: ServiceNowInstance);
18
+ /**
19
+ * Discover the schema for a ServiceNow table.
20
+ * Queries sys_db_object for table info and sys_dictionary for field definitions.
21
+ * Optionally includes choice tables, relationships, UI policies, and business rules.
22
+ *
23
+ * @param tableName The name of the table to discover
24
+ * @param options Optional flags to include additional information
25
+ * @returns TableSchema with all discovered information
26
+ * @throws Error if tableName is empty or the table is not found
27
+ */
28
+ discoverTableSchema(tableName: string, options?: TableSchemaOptions): Promise<TableSchema>;
29
+ /**
30
+ * Explain a specific field on a table.
31
+ * Queries sys_dictionary for the field definition and sys_choice for available choices.
32
+ *
33
+ * @param tableName The table containing the field
34
+ * @param fieldName The field name to explain
35
+ * @returns Detailed FieldExplanation
36
+ * @throws Error if tableName or fieldName is empty, or the field is not found
37
+ */
38
+ explainField(tableName: string, fieldName: string): Promise<FieldExplanation>;
39
+ /**
40
+ * Validate a catalog item configuration.
41
+ * Checks variables (item_option_new) and UI policies (catalog_ui_policy) for integrity issues.
42
+ *
43
+ * @param catalogItemSysId The sys_id of the catalog item to validate
44
+ * @returns Validation result with issues, warnings, and errors
45
+ * @throws Error if catalogItemSysId is empty
46
+ */
47
+ validateCatalogConfiguration(catalogItemSysId: string): Promise<CatalogValidationResult>;
48
+ /**
49
+ * Get choice values for all fields on a table.
50
+ * @private
51
+ */
52
+ private _getChoicesForTable;
53
+ /**
54
+ * Extract relationship information from field schemas (reference fields).
55
+ * @private
56
+ */
57
+ private _extractRelationships;
58
+ /**
59
+ * Get UI policies for a table.
60
+ * @private
61
+ */
62
+ private _getUIPoliciesForTable;
63
+ /**
64
+ * Get business rules for a table.
65
+ * @private
66
+ */
67
+ private _getBusinessRulesForTable;
68
+ }