xml-toolkit 1.0.36 → 1.0.38
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/index.js +1 -0
- package/lib/SOAP11.js +10 -5
- package/lib/SOAP12.js +6 -1
- package/lib/SOAPEncoding.js +79 -0
- package/lib/SOAPFault.js +1 -1
- package/lib/XMLMarshaller.js +4 -4
- package/package.json +23 -13
package/index.js
CHANGED
package/lib/SOAP11.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require ('fs')
|
|
2
2
|
const path = require ('path')
|
|
3
|
+
const createError = require ('http-errors')
|
|
3
4
|
|
|
4
5
|
const XMLSchemata = require ('./XMLSchemata.js')
|
|
5
6
|
const XMLReader = require ('./XMLReader.js')
|
|
@@ -22,15 +23,17 @@ const get_xs = () => {
|
|
|
22
23
|
|
|
23
24
|
const _fault_xml = ({code, message, actor, detail}) => {
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
let faultcode = code ?? 'Server'
|
|
27
|
+
|
|
28
|
+
if (typeof faultcode === 'string') faultcode = {localName: faultcode, namespaceURI: 'http://schemas.xmlsoap.org/soap/envelope/'}
|
|
26
29
|
|
|
27
30
|
const Fault = {
|
|
28
|
-
faultstring: message,
|
|
29
|
-
faultcode
|
|
30
|
-
faultactor: actor,
|
|
31
|
+
faultstring: message,
|
|
32
|
+
faultcode,
|
|
33
|
+
faultactor: actor,
|
|
31
34
|
detail
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
|
|
34
37
|
return get_xs ().stringify ({Fault})
|
|
35
38
|
|
|
36
39
|
}
|
|
@@ -172,6 +175,8 @@ SOAP11.fromFile = async function (fn, options = {}) {
|
|
|
172
175
|
|
|
173
176
|
}
|
|
174
177
|
|
|
178
|
+
SOAP11.createError = fault => createError (500, SOAP11.message (fault), {expose: true, headers: {'Content-Type': _contentType}})
|
|
179
|
+
|
|
175
180
|
SOAP11.message = _message
|
|
176
181
|
|
|
177
182
|
module.exports = SOAP11
|
package/lib/SOAP12.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require ('path')
|
|
2
2
|
const XMLSchemata = require ('./XMLSchemata.js')
|
|
3
3
|
const SOAPFault = require ('./SOAPFault.js')
|
|
4
|
+
const createError = require ('http-errors')
|
|
4
5
|
|
|
5
6
|
let _xs = null
|
|
6
7
|
|
|
@@ -16,6 +17,8 @@ const get_xs = () => {
|
|
|
16
17
|
|
|
17
18
|
const _fault_xml = ({code, message, actor, detail, lang}) => {
|
|
18
19
|
|
|
20
|
+
if (!code) code = 'Receiver'
|
|
21
|
+
|
|
19
22
|
if (typeof code === 'string') code = {localName: code, namespaceURI: 'http://www.w3.org/2003/05/soap-envelope'}
|
|
20
23
|
|
|
21
24
|
const Fault = {
|
|
@@ -24,7 +27,7 @@ const _fault_xml = ({code, message, actor, detail, lang}) => {
|
|
|
24
27
|
Role: actor,
|
|
25
28
|
Detail: detail
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
|
|
28
31
|
return get_xs ().stringify ({Fault})
|
|
29
32
|
|
|
30
33
|
}
|
|
@@ -75,4 +78,6 @@ SOAP12.contentType = _contentType
|
|
|
75
78
|
|
|
76
79
|
SOAP12.message = _message
|
|
77
80
|
|
|
81
|
+
SOAP12.createError = fault => createError (500, SOAP12.message (fault), {expose: true, headers: {'Content-Type': _contentType}})
|
|
82
|
+
|
|
78
83
|
module.exports = SOAP12
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const util = require ('util')
|
|
2
|
+
|
|
3
|
+
const NS_XSD = 'http://www.w3.org/2001/XMLSchema'
|
|
4
|
+
const NS_XSI = 'http://www.w3.org/2001/XMLSchema-instance'
|
|
5
|
+
const NS_SOAP = 'http://xml.apache.org/xml-soap'
|
|
6
|
+
const NS_SOAPENC = 'http://schemas.xmlsoap.org/soap/encoding/'
|
|
7
|
+
|
|
8
|
+
const SOAPEncoding = class {
|
|
9
|
+
|
|
10
|
+
constructor (options = {}) {
|
|
11
|
+
|
|
12
|
+
this.emptyScalar = options.emptyScalar
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
decodeMap ({children}) {
|
|
17
|
+
|
|
18
|
+
const result = {}
|
|
19
|
+
|
|
20
|
+
for (const {children: [{children: [{src}]}, value]} of children) {
|
|
21
|
+
|
|
22
|
+
const v = this.decode (value)
|
|
23
|
+
|
|
24
|
+
if (v === undefined) continue
|
|
25
|
+
|
|
26
|
+
result [src] = v
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
decodeArray ({children}) {
|
|
35
|
+
|
|
36
|
+
return children.map (value => this.decode (value))
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
decodeScalar ({children}) {
|
|
41
|
+
|
|
42
|
+
if (children.length === 0) return this.emptyScalar
|
|
43
|
+
|
|
44
|
+
return children [0].src
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
decode (node) {
|
|
49
|
+
|
|
50
|
+
const {attributes} = node; if (!attributes) throw Error ('no attributes at all: ' + util.inspect(node))
|
|
51
|
+
|
|
52
|
+
const nil = attributes.get ('nil', NS_XSI); if (nil === 'true' || nil === '1') return null
|
|
53
|
+
|
|
54
|
+
const type = attributes.get ('type', NS_XSI); if (!type) throw Error ('xsi:type not defined: ' + util.inspect(node))
|
|
55
|
+
|
|
56
|
+
const [namespacePrefix, localName] = type.split (':'), namespaceURI = attributes._nsMap.get (namespacePrefix)
|
|
57
|
+
|
|
58
|
+
switch (namespaceURI) {
|
|
59
|
+
|
|
60
|
+
case NS_XSD: return this.decodeScalar (node)
|
|
61
|
+
|
|
62
|
+
case NS_SOAP:
|
|
63
|
+
if (localName !== 'Map') throw Error (`Don't know how to decode ${localName} from ${namespaceURI}`)
|
|
64
|
+
return this.decodeMap (node)
|
|
65
|
+
|
|
66
|
+
case NS_SOAPENC:
|
|
67
|
+
if (localName !== 'Array') throw Error (`Don't know how to decode ${localName} from ${namespaceURI}`)
|
|
68
|
+
return this.decodeArray (node)
|
|
69
|
+
|
|
70
|
+
default:
|
|
71
|
+
throw Error (`Don't know how to decode ${localName} from ${namespaceURI}`)
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = SOAPEncoding
|
package/lib/SOAPFault.js
CHANGED
package/lib/XMLMarshaller.js
CHANGED
|
@@ -133,11 +133,11 @@ const XMLMarshaller = class {
|
|
|
133
133
|
this.buf += `<${qName} xsi:nil="true" />`
|
|
134
134
|
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
appendScalar (node, data, restriction = {}) {
|
|
138
138
|
|
|
139
139
|
for (const {localName, attributes, children} of node.children) {
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
if (localName === 'restriction') {
|
|
142
142
|
|
|
143
143
|
for (const {localName, attributes: {value}} of children) restriction [localName] = value
|
|
@@ -247,8 +247,8 @@ const XMLMarshaller = class {
|
|
|
247
247
|
|
|
248
248
|
case 'simpleType':
|
|
249
249
|
|
|
250
|
-
if (data !== null && typeof data === 'object' && !(data instanceof Date)) data = data [null]
|
|
251
|
-
|
|
250
|
+
if (data !== null && typeof data === 'object' && !(data instanceof Date) && node.attributes.name !== 'QName') data = data [null]
|
|
251
|
+
|
|
252
252
|
if (data != null) this.appendScalar (node, data)
|
|
253
253
|
|
|
254
254
|
return
|
package/package.json
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xml-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "XML parser, marshaller, SOAP adapter",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"files": [
|
|
6
|
+
"files": [
|
|
7
|
+
"/lib",
|
|
8
|
+
"/badges"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"test": "jest",
|
|
9
12
|
"test-ci": "jest --ci --coverage"
|
|
10
13
|
},
|
|
11
14
|
"jest": {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
"collectCoverageFrom": [
|
|
16
|
+
"lib/**/*.js"
|
|
17
|
+
],
|
|
18
|
+
"coverageReporters": [
|
|
19
|
+
"clover",
|
|
20
|
+
"json",
|
|
21
|
+
"lcov",
|
|
22
|
+
"text",
|
|
23
|
+
"json-summary"
|
|
24
|
+
],
|
|
25
|
+
"verbose": false,
|
|
26
|
+
"testPathIgnorePatterns": [
|
|
27
|
+
"/node_modules/",
|
|
28
|
+
"/__tests__/0ld",
|
|
29
|
+
"/__tests__/data",
|
|
30
|
+
"/__tests__/lib"
|
|
31
|
+
]
|
|
23
32
|
},
|
|
24
33
|
"repository": {
|
|
25
34
|
"type": "git",
|
|
@@ -42,6 +51,7 @@
|
|
|
42
51
|
"jest": "^29.3.1"
|
|
43
52
|
},
|
|
44
53
|
"dependencies": {
|
|
54
|
+
"http-errors": "^2.0.0",
|
|
45
55
|
"string-escape-map": "^1.0.0"
|
|
46
56
|
}
|
|
47
57
|
}
|