alado 2.5.3 → 2.6.1
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/README.md +15 -0
- package/dist/constants/content-type.d.ts +3 -1
- package/dist/constants/content-type.js +2 -0
- package/dist/constants/content-type.js.map +1 -1
- package/dist/helpers/parser/body-parser.js +12 -0
- package/dist/helpers/parser/body-parser.js.map +1 -1
- package/dist/helpers/parser/xml-parser.d.ts +6 -0
- package/dist/helpers/parser/xml-parser.js +189 -0
- package/dist/helpers/parser/xml-parser.js.map +1 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1122,6 +1122,21 @@ public getAvatar(req: Request) {
|
|
|
1122
1122
|
}
|
|
1123
1123
|
```
|
|
1124
1124
|
|
|
1125
|
+
## XML Request Body (>=2.6.0)
|
|
1126
|
+
|
|
1127
|
+
When a request arrives with a `Content-Type` of `text/xml` or `application/xml`, Alado automatically parses the raw body into a plain JavaScript object before your handler runs — no configuration needed, and no external XML library involved. `req.body` behaves the same way it does for JSON requests.
|
|
1128
|
+
|
|
1129
|
+
### How the conversion works
|
|
1130
|
+
|
|
1131
|
+
- **Elements become object keys.** Each XML tag becomes a key in the resulting object, with its children nested underneath.
|
|
1132
|
+
- **Repeated sibling tags collapse into an array.** `<item>a</item><item>b</item>` becomes `item: ['a', 'b']` rather than overwriting the key.
|
|
1133
|
+
- **Leaf elements become plain strings.** `<name>Daniel</name>` becomes `name: 'Daniel'` — no wrapper object, no type coercion (numeric-looking text like `"10000.00"` is kept exactly as written, since silently converting it to a JS number would lose precision on monetary values).
|
|
1134
|
+
- **Attributes are namespaced under `@attrs`.** An element like `<amount currency="USD">100</amount>` becomes `{ '@attrs': { currency: 'USD' }, '#text': '100' }`, keeping attribute data separate from element data and text content.
|
|
1135
|
+
- **CDATA sections are unwrapped automatically**, and their contents treated as plain text.
|
|
1136
|
+
- **Namespaces resolve to local names.** For SOAP envelopes or ISO 20022 style payment messages, elements are keyed by their local name regardless of which prefix the sender used (`soapenv:Body` and `soap:Body` parse identically if they share a namespace). Each element also carries an `@ns` field with its resolved namespace URI, so elements sharing a local name across different namespaces stay distinguishable.
|
|
1137
|
+
|
|
1138
|
+
Because the contract is identical to JSON, everything documented under [`defineRequest`](#definerequest) and [DTOs](#dtos) — `@validateProperty`, `@documentProperty`, `@transformProperty`, auto-generated OpenAPI schemas applies to XML bodies without any extra setup.
|
|
1139
|
+
|
|
1125
1140
|
---
|
|
1126
1141
|
|
|
1127
1142
|
## OpenAPI / Swagger
|
|
@@ -2,5 +2,7 @@ export declare enum ContentType {
|
|
|
2
2
|
TEXT_PLAIN = "text/plain",
|
|
3
3
|
JSON = "application/json",
|
|
4
4
|
FORM_DATA = "multipart/form-data",
|
|
5
|
-
X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"
|
|
5
|
+
X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded",
|
|
6
|
+
XML = "application/xml",
|
|
7
|
+
TEXT_XML = "text/xml"
|
|
6
8
|
}
|
|
@@ -7,5 +7,7 @@ var ContentType;
|
|
|
7
7
|
ContentType["JSON"] = "application/json";
|
|
8
8
|
ContentType["FORM_DATA"] = "multipart/form-data";
|
|
9
9
|
ContentType["X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
|
|
10
|
+
ContentType["XML"] = "application/xml";
|
|
11
|
+
ContentType["TEXT_XML"] = "text/xml";
|
|
10
12
|
})(ContentType || (exports.ContentType = ContentType = {}));
|
|
11
13
|
//# sourceMappingURL=content-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.js","sourceRoot":"","sources":["../../src/constants/content-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"content-type.js","sourceRoot":"","sources":["../../src/constants/content-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0EAA2D,CAAA;IAC3D,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;AACvB,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.bodyParser = bodyParser;
|
|
4
4
|
const _const_1 = require("../../constants");
|
|
5
5
|
const stream_1 = require("stream");
|
|
6
|
+
const xml_parser_1 = require("./xml-parser");
|
|
6
7
|
async function bodyParser(req, res, limit) {
|
|
7
8
|
const contentType = req.headers['content-type'];
|
|
8
9
|
const result = {
|
|
@@ -102,6 +103,17 @@ async function bodyParser(req, res, limit) {
|
|
|
102
103
|
});
|
|
103
104
|
resolve();
|
|
104
105
|
}
|
|
106
|
+
else if ([
|
|
107
|
+
_const_1.ContentType.XML.toString(),
|
|
108
|
+
_const_1.ContentType.TEXT_XML.toString(),
|
|
109
|
+
].includes(contentType)) {
|
|
110
|
+
try {
|
|
111
|
+
result.body = (0, xml_parser_1.xmlParser)(body);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
reject({ statusCode: 400, message: `Invalid XML body: ${e.message}` });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
105
117
|
else {
|
|
106
118
|
result.body = body;
|
|
107
119
|
resolve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/body-parser.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/body-parser.ts"],"names":[],"mappings":";;AAMA,gCAuHC;AA5HD,mCAAkG;AAClG,mCAAkC;AAElC,6CAAyC;AAElC,KAAK,UAAU,UAAU,CAAC,GAAoB,EAAE,GAAoB,EAAE,KAAa;IACxF,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,MAAM,GAAQ;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0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.xmlParser = xmlParser;
|
|
4
|
+
function xmlParser(xmlInput) {
|
|
5
|
+
let xml = xmlInput;
|
|
6
|
+
let pos = 0;
|
|
7
|
+
xml = xml.replace(/<\?xml[^?]*\?>/g, '');
|
|
8
|
+
xml = xml.replace(/<!--[\s\S]*?-->/g, '');
|
|
9
|
+
xml = xml.trim();
|
|
10
|
+
if (!xml) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
function skipWhitespace() {
|
|
14
|
+
while (pos < xml.length && /\s/.test(xml[pos])) {
|
|
15
|
+
pos++;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function parseAttributes(tagContent) {
|
|
19
|
+
const attrs = {};
|
|
20
|
+
const attrRegex = /([a-zA-Z_:][\w:.-]*)\s*=\s*"([^"]*)"|([a-zA-Z_:][\w:.-]*)\s*=\s*'([^']*)'/g;
|
|
21
|
+
let match;
|
|
22
|
+
match = attrRegex.exec(tagContent);
|
|
23
|
+
while (match !== null) {
|
|
24
|
+
const name = match[1] || match[3];
|
|
25
|
+
const value = match[2] !== undefined ? match[2] : match[4];
|
|
26
|
+
attrs[name] = decodeEntities(value);
|
|
27
|
+
match = attrRegex.exec(tagContent);
|
|
28
|
+
}
|
|
29
|
+
return attrs;
|
|
30
|
+
}
|
|
31
|
+
function decodeEntities(str) {
|
|
32
|
+
return str
|
|
33
|
+
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
|
|
34
|
+
.replace(/</g, '<')
|
|
35
|
+
.replace(/>/g, '>')
|
|
36
|
+
.replace(/"/g, '"')
|
|
37
|
+
.replace(/'/g, "'")
|
|
38
|
+
.replace(/&/g, '&');
|
|
39
|
+
}
|
|
40
|
+
function resolveScope(rawAttrs, parentScope) {
|
|
41
|
+
const scope = {
|
|
42
|
+
defaultUri: parentScope.defaultUri,
|
|
43
|
+
prefixes: { ...parentScope.prefixes },
|
|
44
|
+
};
|
|
45
|
+
const dataAttrs = {};
|
|
46
|
+
for (const [key, value,] of Object.entries(rawAttrs)) {
|
|
47
|
+
if (key === 'xmlns') {
|
|
48
|
+
scope.defaultUri = value;
|
|
49
|
+
}
|
|
50
|
+
else if (key.startsWith('xmlns:')) {
|
|
51
|
+
const prefix = key.slice('xmlns:'.length);
|
|
52
|
+
scope.prefixes[prefix] = value;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
dataAttrs[key] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { scope, dataAttrs };
|
|
59
|
+
}
|
|
60
|
+
function resolveTagNamespace(tagName, scope) {
|
|
61
|
+
const colonIndex = tagName.indexOf(':');
|
|
62
|
+
if (colonIndex === -1) {
|
|
63
|
+
return { localName: tagName, namespaceUri: scope.defaultUri };
|
|
64
|
+
}
|
|
65
|
+
const prefix = tagName.slice(0, colonIndex);
|
|
66
|
+
const localName = tagName.slice(colonIndex + 1);
|
|
67
|
+
const namespaceUri = scope.prefixes[prefix] ?? null;
|
|
68
|
+
return { localName, namespaceUri };
|
|
69
|
+
}
|
|
70
|
+
function addChild(parent, key, value) {
|
|
71
|
+
if (Object.prototype.hasOwnProperty.call(parent, key)) {
|
|
72
|
+
const existing = parent[key];
|
|
73
|
+
if (Array.isArray(existing)) {
|
|
74
|
+
existing.push(value);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
parent[key] = [
|
|
78
|
+
existing,
|
|
79
|
+
value,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
parent[key] = value;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function parseElement(parentScope) {
|
|
88
|
+
skipWhitespace();
|
|
89
|
+
if (xml[pos] !== '<') {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const tagMatch = /^<([a-zA-Z_:][\w:.-]*)((?:\s+[^>]*?)?)(\/?)>/.exec(xml.slice(pos));
|
|
93
|
+
if (!tagMatch) {
|
|
94
|
+
throw new Error(`Malformed XML near position ${pos}: ${xml.slice(pos, pos + 40)}`);
|
|
95
|
+
}
|
|
96
|
+
const fullMatch = tagMatch[0];
|
|
97
|
+
const rawTagName = tagMatch[1];
|
|
98
|
+
const rawAttrsText = tagMatch[2];
|
|
99
|
+
const selfClosing = tagMatch[3];
|
|
100
|
+
pos += fullMatch.length;
|
|
101
|
+
const rawAttrs = parseAttributes(rawAttrsText);
|
|
102
|
+
const { scope, dataAttrs } = resolveScope(rawAttrs, parentScope);
|
|
103
|
+
const { localName, namespaceUri } = resolveTagNamespace(rawTagName, scope);
|
|
104
|
+
const hasAttrs = Object.keys(dataAttrs).length > 0;
|
|
105
|
+
if (selfClosing === '/') {
|
|
106
|
+
const value = { '@ns': namespaceUri };
|
|
107
|
+
if (hasAttrs) {
|
|
108
|
+
value['@attrs'] = dataAttrs;
|
|
109
|
+
}
|
|
110
|
+
return [
|
|
111
|
+
localName,
|
|
112
|
+
value,
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
const children = {};
|
|
116
|
+
let textContent = '';
|
|
117
|
+
let sawChildElement = false;
|
|
118
|
+
while (pos < xml.length) {
|
|
119
|
+
skipWhitespace();
|
|
120
|
+
const closeMatch = new RegExp(`^</${rawTagName}\\s*>`).exec(xml.slice(pos));
|
|
121
|
+
if (closeMatch) {
|
|
122
|
+
pos += closeMatch[0].length;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (xml[pos] === '<') {
|
|
126
|
+
if (xml.slice(pos, pos + 9) === '<![CDATA[') {
|
|
127
|
+
const end = xml.indexOf(']]>', pos);
|
|
128
|
+
if (end === -1) {
|
|
129
|
+
throw new Error('Unterminated CDATA section');
|
|
130
|
+
}
|
|
131
|
+
textContent += xml.slice(pos + 9, end);
|
|
132
|
+
pos = end + 3;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const child = parseElement(scope);
|
|
136
|
+
if (child) {
|
|
137
|
+
const [childName, childValue,] = child;
|
|
138
|
+
sawChildElement = true;
|
|
139
|
+
addChild(children, childName, childValue);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const nextTag = xml.indexOf('<', pos);
|
|
144
|
+
const end = nextTag === -1 ? xml.length : nextTag;
|
|
145
|
+
textContent += xml.slice(pos, end);
|
|
146
|
+
pos = end;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const trimmedText = decodeEntities(textContent.trim());
|
|
150
|
+
if (sawChildElement) {
|
|
151
|
+
children['@ns'] = namespaceUri;
|
|
152
|
+
if (hasAttrs) {
|
|
153
|
+
children['@attrs'] = dataAttrs;
|
|
154
|
+
}
|
|
155
|
+
return [
|
|
156
|
+
localName,
|
|
157
|
+
children,
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
// Leaf node (no child elements). If there are no attributes, return a plain
|
|
161
|
+
// string for ergonomics — the common case for payment-message field values
|
|
162
|
+
// like <IBAN>...</IBAN> or <MsgId>...</MsgId>. Namespace on a plain-string
|
|
163
|
+
// leaf is recoverable from its parent's "@ns", since a leaf can't redeclare
|
|
164
|
+
// scope for anything beneath it (it has no children).
|
|
165
|
+
if (!hasAttrs) {
|
|
166
|
+
return [
|
|
167
|
+
localName,
|
|
168
|
+
trimmedText,
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
const leaf = { '@ns': namespaceUri, '@attrs': dataAttrs };
|
|
172
|
+
if (trimmedText) {
|
|
173
|
+
leaf['#text'] = trimmedText;
|
|
174
|
+
}
|
|
175
|
+
return [
|
|
176
|
+
localName,
|
|
177
|
+
leaf,
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
const rootScope = { defaultUri: null, prefixes: {} };
|
|
181
|
+
const root = {};
|
|
182
|
+
const rootElement = parseElement(rootScope);
|
|
183
|
+
if (rootElement) {
|
|
184
|
+
const [rootName, rootValue,] = rootElement;
|
|
185
|
+
root[rootName] = rootValue;
|
|
186
|
+
}
|
|
187
|
+
return root;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=xml-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-parser.js","sourceRoot":"","sources":["../../../src/helpers/parser/xml-parser.ts"],"names":[],"mappings":";;AAQA,8BAwOC;AAxOD,SAAgB,SAAS,CAAC,QAAgB;IACxC,IAAI,GAAG,GAAW,QAAQ,CAAC;IAC3B,IAAI,GAAG,GAAW,CAAC,CAAC;IAEpB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACzC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAC1C,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAEjB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,SAAS,cAAc;QACrB,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/C,GAAG,EAAE,CAAC;QACR,CAAC;IACH,CAAC;IAED,SAAS,eAAe,CAAC,UAAkB;QACzC,MAAM,KAAK,GAA8B,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAW,4EAA4E,CAAC;QACvG,IAAI,KAA6B,CAAC;QAElC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnC,OAAO,KAAK,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,GAAW,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,KAAK,GAAW,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CA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,EACR,SAAS,EACV,GAAG,WAAW,CAAC;QAChB,IAAI,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alado",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Extremely fast, lightweight, robust framework for HTTP applications written in Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"HTTP",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"@eslint/js": "^10.0.1",
|
|
31
31
|
"@types/node": "24.13.1",
|
|
32
32
|
"@types/prettier": "3.0.0",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
34
|
-
"@typescript-eslint/parser": "8.
|
|
35
|
-
"eslint": "10.
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "8.64.0",
|
|
34
|
+
"@typescript-eslint/parser": "8.64.0",
|
|
35
|
+
"eslint": "10.7.0",
|
|
36
36
|
"husky": "9.1.7",
|
|
37
|
-
"prettier": "3.9.
|
|
38
|
-
"prettier-plugin-multiline-arrays": "4.1.
|
|
39
|
-
"tsc-alias": "1.
|
|
37
|
+
"prettier": "3.9.5",
|
|
38
|
+
"prettier-plugin-multiline-arrays": "4.1.10",
|
|
39
|
+
"tsc-alias": "1.9.1",
|
|
40
40
|
"typescript": "5.9.3",
|
|
41
|
-
"typescript-eslint": "^8.
|
|
41
|
+
"typescript-eslint": "^8.64.0"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|