xml-toolkit 1.0.35 → 1.0.37

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/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
- if (typeof code === 'string') code = {localName: code, namespaceURI: 'http://schemas.xmlsoap.org/soap/envelope/'}
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: code,
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
package/lib/SOAPFault.js CHANGED
@@ -12,7 +12,7 @@ const SOAPFault = class {
12
12
  this.message = message
13
13
  }
14
14
 
15
- this.code = 'code' in o ? o.code: 'Server'
15
+ if ('code' in o) this.code = o.code
16
16
 
17
17
  if ('actor' in o) {
18
18
  this.actor = o.actor
@@ -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/lib/XMLParser.js CHANGED
@@ -50,7 +50,7 @@ const XMLReader = class {
50
50
  if (this.text.length === 0) break
51
51
  if (this.stripSpace) this.text = this.text.trim ()
52
52
  if (this.text.length === 0) break
53
- (new XMLNode (this.text, this.entityResolver, SAXEvent.TYPES.CHARACTERS)).parent = this.element
53
+ (new XMLNode (this.text, null, SAXEvent.TYPES.CHARACTERS)).parent = this.element
54
54
  this.text = ''
55
55
 
56
56
  }
package/package.json CHANGED
@@ -1,25 +1,34 @@
1
1
  {
2
2
  "name": "xml-toolkit",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "XML parser, marshaller, SOAP adapter",
5
5
  "main": "index.js",
6
- "files": ["/lib", "/badges"],
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
- "collectCoverageFrom": [
13
- "lib/**/*.js"
14
- ],
15
- "coverageReporters": ["clover", "json", "lcov", "text", "json-summary"],
16
- "verbose": false,
17
- "testPathIgnorePatterns": [
18
- "/node_modules/",
19
- "/__tests__/0ld",
20
- "/__tests__/data",
21
- "/__tests__/lib"
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
  }