@sonisoft/now-sdk-ext-core 3.0.2 → 3.3.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.
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Models for Knowledge Base management operations against ServiceNow tables:
3
+ * kb_knowledge_base, kb_category, and kb_knowledge.
4
+ */
5
+ /**
6
+ * A knowledge base record from the kb_knowledge_base table.
7
+ */
8
+ export interface KnowledgeBaseRecord {
9
+ sys_id: string;
10
+ title: string;
11
+ description?: string;
12
+ owner?: string;
13
+ active?: string;
14
+ kb_version?: string;
15
+ application?: string;
16
+ kb_managers?: string;
17
+ sys_created_on?: string;
18
+ sys_updated_on?: string;
19
+ sys_created_by?: string;
20
+ sys_updated_by?: string;
21
+ [key: string]: unknown;
22
+ }
23
+ /**
24
+ * A knowledge category record from the kb_category table.
25
+ * Note: kb_category uses "label" (not "title") and "value" for the KB reference.
26
+ */
27
+ export interface KnowledgeCategoryRecord {
28
+ sys_id: string;
29
+ /** Category display name */
30
+ label: string;
31
+ /** Knowledge base sys_id reference */
32
+ value: string;
33
+ /** Parent category sys_id */
34
+ parent_id?: string;
35
+ /** Full category path */
36
+ full_category?: string;
37
+ active?: string;
38
+ sys_created_on?: string;
39
+ sys_updated_on?: string;
40
+ sys_created_by?: string;
41
+ sys_updated_by?: string;
42
+ [key: string]: unknown;
43
+ }
44
+ /**
45
+ * A full knowledge article record from the kb_knowledge table,
46
+ * including body content fields (text, wiki).
47
+ */
48
+ export interface KnowledgeArticleRecord {
49
+ sys_id: string;
50
+ number?: string;
51
+ short_description: string;
52
+ /** Article body in HTML */
53
+ text?: string;
54
+ /** Article body in wiki markup */
55
+ wiki?: string;
56
+ description?: string;
57
+ /** Reference to kb_knowledge_base */
58
+ kb_knowledge_base: string;
59
+ /** Reference to kb_category */
60
+ kb_category?: string;
61
+ category?: string;
62
+ workflow_state?: string;
63
+ author?: string;
64
+ article_type?: string;
65
+ published?: string;
66
+ active?: string;
67
+ valid_to?: string;
68
+ version?: string;
69
+ display_number?: string;
70
+ meta_description?: string;
71
+ keywords?: string;
72
+ sys_view_count?: string;
73
+ use_count?: string;
74
+ rating?: string;
75
+ sys_created_on?: string;
76
+ sys_updated_on?: string;
77
+ sys_created_by?: string;
78
+ sys_updated_by?: string;
79
+ [key: string]: unknown;
80
+ }
81
+ /**
82
+ * A lightweight article summary for list operations (excludes large body fields).
83
+ */
84
+ export interface KnowledgeArticleSummary {
85
+ sys_id: string;
86
+ number?: string;
87
+ short_description: string;
88
+ kb_knowledge_base: string;
89
+ kb_category?: string;
90
+ workflow_state?: string;
91
+ author?: string;
92
+ article_type?: string;
93
+ published?: string;
94
+ active?: string;
95
+ sys_view_count?: string;
96
+ sys_created_on?: string;
97
+ sys_updated_on?: string;
98
+ [key: string]: unknown;
99
+ }
100
+ /**
101
+ * Options for listing knowledge bases.
102
+ */
103
+ export interface ListKnowledgeBasesOptions {
104
+ /** Encoded query string for filtering */
105
+ query?: string;
106
+ /** Filter by active status */
107
+ active?: boolean;
108
+ /** Maximum number of records to return (default 20) */
109
+ limit?: number;
110
+ /** Offset for pagination (default 0) */
111
+ offset?: number;
112
+ }
113
+ /**
114
+ * Options for listing knowledge categories.
115
+ */
116
+ export interface ListCategoriesOptions {
117
+ /** Filter by knowledge base sys_id (kb_category.value field) */
118
+ knowledgeBaseSysId?: string;
119
+ /** Filter by parent category sys_id */
120
+ parentCategory?: string;
121
+ /** Encoded query string for additional filtering */
122
+ query?: string;
123
+ /** Filter by active status */
124
+ active?: boolean;
125
+ /** Maximum number of records (default 20) */
126
+ limit?: number;
127
+ /** Offset for pagination (default 0) */
128
+ offset?: number;
129
+ }
130
+ /**
131
+ * Options for creating a knowledge category.
132
+ */
133
+ export interface CreateCategoryOptions {
134
+ /** Category label (display name) */
135
+ label: string;
136
+ /** Knowledge base sys_id (stored in kb_category.value) */
137
+ knowledgeBaseSysId: string;
138
+ /** Parent category sys_id (stored in kb_category.parent_id) */
139
+ parentCategory?: string;
140
+ /** Whether the category is active (default true) */
141
+ active?: boolean;
142
+ }
143
+ /**
144
+ * Options for listing knowledge articles.
145
+ */
146
+ export interface ListArticlesOptions {
147
+ /** Filter by knowledge base sys_id */
148
+ knowledgeBaseSysId?: string;
149
+ /** Filter by category sys_id */
150
+ categorySysId?: string;
151
+ /** Filter by workflow state (e.g. "published", "draft", "retired") */
152
+ workflowState?: string;
153
+ /** Text search term (searches short_description) */
154
+ textSearch?: string;
155
+ /** Encoded query string for additional filtering */
156
+ query?: string;
157
+ /** Maximum number of records (default 20) */
158
+ limit?: number;
159
+ /** Offset for pagination (default 0) */
160
+ offset?: number;
161
+ }
162
+ /**
163
+ * Options for creating a knowledge article.
164
+ */
165
+ export interface CreateArticleOptions {
166
+ /** Article short description / title */
167
+ shortDescription: string;
168
+ /** Article body in HTML */
169
+ text?: string;
170
+ /** Article body in wiki markup */
171
+ wiki?: string;
172
+ /** Knowledge base sys_id */
173
+ knowledgeBaseSysId: string;
174
+ /** Category sys_id */
175
+ categorySysId?: string;
176
+ /** Workflow state (default "draft") */
177
+ workflowState?: string;
178
+ /** Article type */
179
+ articleType?: string;
180
+ /** Additional fields to set on the record */
181
+ additionalFields?: Record<string, string>;
182
+ }
183
+ /**
184
+ * Options for updating a knowledge article.
185
+ */
186
+ export interface UpdateArticleOptions {
187
+ /** Updated short description */
188
+ shortDescription?: string;
189
+ /** Updated article body in HTML */
190
+ text?: string;
191
+ /** Updated article body in wiki markup */
192
+ wiki?: string;
193
+ /** Updated knowledge base sys_id */
194
+ knowledgeBaseSysId?: string;
195
+ /** Updated category sys_id */
196
+ categorySysId?: string;
197
+ /** Updated workflow state */
198
+ workflowState?: string;
199
+ /** Updated article type */
200
+ articleType?: string;
201
+ /** Updated active status */
202
+ active?: boolean;
203
+ /** Additional fields to update */
204
+ additionalFields?: Record<string, string>;
205
+ }
206
+ /**
207
+ * Enriched knowledge base detail including article and category counts.
208
+ */
209
+ export interface KnowledgeBaseDetail {
210
+ knowledgeBase: KnowledgeBaseRecord;
211
+ articleCount: number;
212
+ categoryCount: number;
213
+ }
214
+ export interface KnowledgeBaseResponse {
215
+ result: KnowledgeBaseRecord[];
216
+ }
217
+ export interface KnowledgeBaseSingleResponse {
218
+ result: KnowledgeBaseRecord;
219
+ }
220
+ export interface KnowledgeCategoryResponse {
221
+ result: KnowledgeCategoryRecord[];
222
+ }
223
+ export interface KnowledgeCategorySingleResponse {
224
+ result: KnowledgeCategoryRecord;
225
+ }
226
+ export interface KnowledgeArticleResponse {
227
+ result: KnowledgeArticleRecord[];
228
+ }
229
+ export interface KnowledgeArticleSummaryResponse {
230
+ result: KnowledgeArticleSummary[];
231
+ }
232
+ export interface KnowledgeArticleSingleResponse {
233
+ result: KnowledgeArticleRecord;
234
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Models for Knowledge Base management operations against ServiceNow tables:
3
+ * kb_knowledge_base, kb_category, and kb_knowledge.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=KnowledgeModels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnowledgeModels.js","sourceRoot":"","sources":["../../../src/sn/knowledge/KnowledgeModels.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,35 @@
1
+ import { ServiceNowInstance } from '../ServiceNowInstance.js';
2
+ import { ExportRecordOptions, ExportRecordResult, ImportRecordsOptions, ImportRecordsResult } from './XMLRecordModels.js';
3
+ /**
4
+ * Manages XML record export (unload) and import (upload) operations
5
+ * against ServiceNow `.do` processor endpoints.
6
+ */
7
+ export declare class XMLRecordManager {
8
+ private _snRequest;
9
+ private _logger;
10
+ constructor(instance: ServiceNowInstance);
11
+ /**
12
+ * Export a single record as XML (ServiceNow unload format).
13
+ *
14
+ * @param options - Table name and sys_id of the record to export
15
+ * @returns The raw XML string plus parsed metadata (table, sysId, unloadDate)
16
+ */
17
+ exportRecord(options: ExportRecordOptions): Promise<ExportRecordResult>;
18
+ /**
19
+ * Import XML records into ServiceNow via the sys_upload.do processor.
20
+ *
21
+ * Acquires a CSRF token first, then POSTs a multipart form with the XML content.
22
+ *
23
+ * @param options - XML content and target table name
24
+ * @returns Success status and the target table
25
+ */
26
+ importRecords(options: ImportRecordsOptions): Promise<ImportRecordsResult>;
27
+ /**
28
+ * Fetch the CSRF token from /upload.do by parsing the sysparm_ck hidden input.
29
+ */
30
+ private _getUploadCSRFToken;
31
+ /**
32
+ * Parse ServiceNow unload XML to extract metadata (table name, sys_id, unload_date).
33
+ */
34
+ private _parseUnloadXml;
35
+ }
@@ -0,0 +1,157 @@
1
+ import { Parser } from 'xml2js';
2
+ import { ServiceNowRequest } from '../../comm/http/ServiceNowRequest.js';
3
+ import { Logger } from '../../util/Logger.js';
4
+ import { CSRFTokenHelper } from '../../util/CSRFTokenHelper.js';
5
+ const UPLOAD_ENDPOINT = '/upload.do';
6
+ const SYS_UPLOAD_ENDPOINT = '/sys_upload.do';
7
+ /**
8
+ * Manages XML record export (unload) and import (upload) operations
9
+ * against ServiceNow `.do` processor endpoints.
10
+ */
11
+ export class XMLRecordManager {
12
+ _snRequest;
13
+ _logger = new Logger('XMLRecordManager');
14
+ constructor(instance) {
15
+ this._snRequest = new ServiceNowRequest(instance);
16
+ }
17
+ /**
18
+ * Export a single record as XML (ServiceNow unload format).
19
+ *
20
+ * @param options - Table name and sys_id of the record to export
21
+ * @returns The raw XML string plus parsed metadata (table, sysId, unloadDate)
22
+ */
23
+ async exportRecord(options) {
24
+ if (!options.table || !options.table.trim()) {
25
+ throw new Error('table is required for exportRecord');
26
+ }
27
+ if (!options.sysId || !options.sysId.trim()) {
28
+ throw new Error('sysId is required for exportRecord');
29
+ }
30
+ const path = `/${options.table}.do`;
31
+ const request = {
32
+ path,
33
+ headers: null,
34
+ query: {
35
+ UNL: '',
36
+ sysparm_query: `sys_id=${options.sysId}`
37
+ },
38
+ body: null
39
+ };
40
+ this._logger.debug(`Exporting record: ${options.table}/${options.sysId}`);
41
+ const response = await this._snRequest.get(request);
42
+ if (response.status !== 200 || !response.data) {
43
+ throw new Error(`Failed to export record ${options.table}/${options.sysId}. ` +
44
+ `Status: ${response.status}`);
45
+ }
46
+ const xml = response.data;
47
+ const metadata = await this._parseUnloadXml(xml);
48
+ return {
49
+ xml,
50
+ table: metadata.table || options.table,
51
+ sysId: metadata.sysId || options.sysId,
52
+ unloadDate: metadata.unloadDate
53
+ };
54
+ }
55
+ /**
56
+ * Import XML records into ServiceNow via the sys_upload.do processor.
57
+ *
58
+ * Acquires a CSRF token first, then POSTs a multipart form with the XML content.
59
+ *
60
+ * @param options - XML content and target table name
61
+ * @returns Success status and the target table
62
+ */
63
+ async importRecords(options) {
64
+ if (!options.xmlContent || !options.xmlContent.trim()) {
65
+ throw new Error('xmlContent is required for importRecords');
66
+ }
67
+ if (!options.targetTable || !options.targetTable.trim()) {
68
+ throw new Error('targetTable is required for importRecords');
69
+ }
70
+ // Step 1: Get CSRF token
71
+ const csrfToken = await this._getUploadCSRFToken();
72
+ if (!csrfToken) {
73
+ throw new Error('Failed to obtain CSRF token from /upload.do. ' +
74
+ 'This may indicate an authentication failure or insufficient permissions.');
75
+ }
76
+ // Step 2: Build multipart form
77
+ const formData = new FormData();
78
+ formData.append('sysparm_ck', csrfToken);
79
+ formData.append('sysparm_upload_prefix', '');
80
+ formData.append('sysparm_referring_url', '');
81
+ formData.append('sysparm_target', options.targetTable);
82
+ const blob = new Blob([options.xmlContent], { type: 'text/xml' });
83
+ formData.append('attachFile', blob, 'upload.xml');
84
+ // Step 3: POST to sys_upload.do
85
+ // Do NOT set Content-Type header — let fetch auto-set it with the multipart boundary
86
+ const request = {
87
+ path: SYS_UPLOAD_ENDPOINT,
88
+ headers: {},
89
+ query: null,
90
+ body: formData
91
+ };
92
+ this._logger.debug(`Importing records to table: ${options.targetTable}`);
93
+ const response = await this._snRequest.post(request);
94
+ if (response.status !== 200) {
95
+ throw new Error(`Failed to import records to ${options.targetTable}. ` +
96
+ `Status: ${response.status}`);
97
+ }
98
+ return {
99
+ success: true,
100
+ targetTable: options.targetTable,
101
+ responseBody: response.data || undefined
102
+ };
103
+ }
104
+ /**
105
+ * Fetch the CSRF token from /upload.do by parsing the sysparm_ck hidden input.
106
+ */
107
+ async _getUploadCSRFToken() {
108
+ const request = {
109
+ path: UPLOAD_ENDPOINT,
110
+ headers: null,
111
+ query: null,
112
+ body: null
113
+ };
114
+ const response = await this._snRequest.get(request);
115
+ if (response.status === 200 && response.data) {
116
+ const token = CSRFTokenHelper.extractCSRFToken(response.data);
117
+ this._logger.debug('CSRF Token Received', { token });
118
+ return token;
119
+ }
120
+ this._logger.error('Failed to fetch CSRF token from /upload.do', { status: response.status });
121
+ return null;
122
+ }
123
+ /**
124
+ * Parse ServiceNow unload XML to extract metadata (table name, sys_id, unload_date).
125
+ */
126
+ async _parseUnloadXml(xml) {
127
+ try {
128
+ const parser = new Parser({ explicitArray: false });
129
+ const result = await new Promise((resolve, reject) => {
130
+ parser.parseString(xml, (err, parsed) => {
131
+ if (err)
132
+ reject(err);
133
+ else
134
+ resolve(parsed);
135
+ });
136
+ });
137
+ if (!result?.unload) {
138
+ return {};
139
+ }
140
+ const unloadDate = result.unload.$?.unload_date;
141
+ // Find the first child element that is the record (not $ which holds attributes)
142
+ const recordKeys = Object.keys(result.unload).filter(k => k !== '$');
143
+ if (recordKeys.length === 0) {
144
+ return { unloadDate };
145
+ }
146
+ const tableName = recordKeys[0];
147
+ const record = result.unload[tableName];
148
+ const sysId = record?.sys_id;
149
+ return { table: tableName, sysId, unloadDate };
150
+ }
151
+ catch (err) {
152
+ this._logger.warn('Failed to parse unload XML for metadata', { error: err });
153
+ return {};
154
+ }
155
+ }
156
+ }
157
+ //# sourceMappingURL=XMLRecordManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XMLRecordManager.js","sourceRoot":"","sources":["../../../src/sn/xml/XMLRecordManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,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C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;YACrE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,OAAO,EAAE,UAAU,EAAE,CAAC;YAC1B,CAAC;YAED,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACxC,MAAM,KAAK,GAAG,MAAM,EAAE,MAAM,CAAC;YAE7B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QACnD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,yCAAyC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7E,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Options for exporting a single ServiceNow record as XML (unload).
3
+ */
4
+ export interface ExportRecordOptions {
5
+ /** The table name (e.g. 'incident', 'kb_knowledge') */
6
+ table: string;
7
+ /** The sys_id of the record to export */
8
+ sysId: string;
9
+ }
10
+ /**
11
+ * Result of an XML record export operation.
12
+ */
13
+ export interface ExportRecordResult {
14
+ /** The raw XML string returned by the platform */
15
+ xml: string;
16
+ /** The table name extracted from the XML envelope */
17
+ table: string;
18
+ /** The sys_id extracted from the XML record */
19
+ sysId: string;
20
+ /** The unload_date attribute from the XML envelope, if present */
21
+ unloadDate?: string;
22
+ }
23
+ /**
24
+ * Options for importing XML records into ServiceNow.
25
+ */
26
+ export interface ImportRecordsOptions {
27
+ /** The raw XML content to upload (ServiceNow unload format) */
28
+ xmlContent: string;
29
+ /** The target table name (e.g. 'kb_knowledge') */
30
+ targetTable: string;
31
+ }
32
+ /**
33
+ * Result of an XML record import operation.
34
+ */
35
+ export interface ImportRecordsResult {
36
+ /** Whether the upload request completed successfully (HTTP 200) */
37
+ success: boolean;
38
+ /** The target table the XML was uploaded to */
39
+ targetTable: string;
40
+ /** The raw response body from the upload confirmation page, if available */
41
+ responseBody?: string;
42
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=XMLRecordModels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XMLRecordModels.js","sourceRoot":"","sources":["../../../src/sn/xml/XMLRecordModels.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shared utility for extracting CSRF tokens (sysparm_ck) from ServiceNow HTML pages.
3
+ *
4
+ * ServiceNow embeds CSRF tokens as hidden input fields in `.do` processor pages.
5
+ * The HTML attribute order can vary between pages and platform versions, so a regex
6
+ * approach is more robust than fixed-string substring matching.
7
+ */
8
+ export declare class CSRFTokenHelper {
9
+ /**
10
+ * Extracts the `sysparm_ck` CSRF token value from an HTML string.
11
+ *
12
+ * @param html - Raw HTML response from a ServiceNow `.do` page
13
+ * @returns The token string, or `null` if not found
14
+ */
15
+ static extractCSRFToken(html: string): string | null;
16
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Shared utility for extracting CSRF tokens (sysparm_ck) from ServiceNow HTML pages.
3
+ *
4
+ * ServiceNow embeds CSRF tokens as hidden input fields in `.do` processor pages.
5
+ * The HTML attribute order can vary between pages and platform versions, so a regex
6
+ * approach is more robust than fixed-string substring matching.
7
+ */
8
+ export class CSRFTokenHelper {
9
+ /**
10
+ * Extracts the `sysparm_ck` CSRF token value from an HTML string.
11
+ *
12
+ * @param html - Raw HTML response from a ServiceNow `.do` page
13
+ * @returns The token string, or `null` if not found
14
+ */
15
+ static extractCSRFToken(html) {
16
+ if (!html) {
17
+ return null;
18
+ }
19
+ const match = html.match(/name="sysparm_ck"[^>]*value="([^"]+)"/);
20
+ return match ? match[1] : null;
21
+ }
22
+ }
23
+ //# sourceMappingURL=CSRFTokenHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CSRFTokenHelper.js","sourceRoot":"","sources":["../../src/util/CSRFTokenHelper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IAExB;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAY;QAChC,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAClE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnC,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonisoft/now-sdk-ext-core",
3
- "version": "3.0.2",
3
+ "version": "3.3.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",