@sonisoft/now-sdk-ext-core 3.0.1 → 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.
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/sn/BackgroundScriptExecutor.d.ts +10 -0
- package/dist/sn/BackgroundScriptExecutor.js +41 -5
- package/dist/sn/BackgroundScriptExecutor.js.map +1 -1
- package/dist/sn/catalog/CatalogManager.d.ts +101 -0
- package/dist/sn/catalog/CatalogManager.js +352 -0
- package/dist/sn/catalog/CatalogManager.js.map +1 -0
- package/dist/sn/catalog/CatalogModels.d.ts +177 -0
- package/dist/sn/catalog/CatalogModels.js +6 -0
- package/dist/sn/catalog/CatalogModels.js.map +1 -0
- package/dist/sn/knowledge/KnowledgeManager.d.ts +93 -0
- package/dist/sn/knowledge/KnowledgeManager.js +316 -0
- package/dist/sn/knowledge/KnowledgeManager.js.map +1 -0
- package/dist/sn/knowledge/KnowledgeModels.d.ts +234 -0
- package/dist/sn/knowledge/KnowledgeModels.js +6 -0
- package/dist/sn/knowledge/KnowledgeModels.js.map +1 -0
- package/dist/sn/xml/XMLRecordManager.d.ts +35 -0
- package/dist/sn/xml/XMLRecordManager.js +157 -0
- package/dist/sn/xml/XMLRecordManager.js.map +1 -0
- package/dist/sn/xml/XMLRecordModels.d.ts +42 -0
- package/dist/sn/xml/XMLRecordModels.js +2 -0
- package/dist/sn/xml/XMLRecordModels.js.map +1 -0
- package/dist/util/CSRFTokenHelper.d.ts +16 -0
- package/dist/util/CSRFTokenHelper.js +23 -0
- package/dist/util/CSRFTokenHelper.js.map +1 -0
- package/package.json +1 -1
|
@@ -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,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAQ7D,MAAM,eAAe,GAAG,YAAY,CAAC;AACrC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACjB,UAAU,CAAoB;IAC9B,OAAO,GAAW,IAAI,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEzD,YAAmB,QAA4B;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,OAA4B;QAClD,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,C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,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 @@
|
|
|
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
|
|
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",
|