@xapi-js/adaptor-express 1.1.0 → 1.2.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.cjs +53 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +29 -0
- package/package.json +3 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let __xapi_js_core = require("@xapi-js/core");
|
|
25
|
+
__xapi_js_core = __toESM(__xapi_js_core);
|
|
26
|
+
|
|
27
|
+
//#region src/index.ts
|
|
28
|
+
/**
|
|
29
|
+
* Express middleware to handle X-API XML requests and responses.
|
|
30
|
+
* It parses incoming XML into an XapiRoot object, passes it to the provided handler function,
|
|
31
|
+
* and then serializes the handler's XapiRoot response back into XML.
|
|
32
|
+
*
|
|
33
|
+
* @param handler - An asynchronous function that takes an XapiRoot object and returns a Promise of an XapiRoot object.
|
|
34
|
+
* @returns An Express middleware function.
|
|
35
|
+
*/
|
|
36
|
+
const xapiExpress = (handler) => {
|
|
37
|
+
return async (req, res, next) => {
|
|
38
|
+
if (req.headers["content-type"] !== "application/xml") return next();
|
|
39
|
+
try {
|
|
40
|
+
const xapiReq = (0, __xapi_js_core.parse)(req.body);
|
|
41
|
+
const xapiRes = await handler(xapiReq);
|
|
42
|
+
const xml = (0, __xapi_js_core.write)(xapiRes);
|
|
43
|
+
res.setHeader("Content-Type", "application/xml");
|
|
44
|
+
res.write(xml);
|
|
45
|
+
res.end();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
next(error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.xapiExpress = xapiExpress;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { XapiRoot } from "@xapi-js/core";
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Type definition for an X-API Express handler function.
|
|
8
|
+
* This function receives an XapiRoot object (parsed from the request body) and should return a Promise resolving to an XapiRoot object (for the response).
|
|
9
|
+
*/
|
|
10
|
+
type XapiExpressHandler = (xapi: XapiRoot) => Promise<XapiRoot>;
|
|
11
|
+
/**
|
|
12
|
+
* Express middleware to handle X-API XML requests and responses.
|
|
13
|
+
* It parses incoming XML into an XapiRoot object, passes it to the provided handler function,
|
|
14
|
+
* and then serializes the handler's XapiRoot response back into XML.
|
|
15
|
+
*
|
|
16
|
+
* @param handler - An asynchronous function that takes an XapiRoot object and returns a Promise of an XapiRoot object.
|
|
17
|
+
* @returns An Express middleware function.
|
|
18
|
+
*/
|
|
19
|
+
declare const xapiExpress: (handler: XapiExpressHandler) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { xapiExpress };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { XapiRoot } from "@xapi-js/core";
|
|
2
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Type definition for an X-API Express handler function.
|
|
8
|
+
* This function receives an XapiRoot object (parsed from the request body) and should return a Promise resolving to an XapiRoot object (for the response).
|
|
9
|
+
*/
|
|
10
|
+
type XapiExpressHandler = (xapi: XapiRoot) => Promise<XapiRoot>;
|
|
11
|
+
/**
|
|
12
|
+
* Express middleware to handle X-API XML requests and responses.
|
|
13
|
+
* It parses incoming XML into an XapiRoot object, passes it to the provided handler function,
|
|
14
|
+
* and then serializes the handler's XapiRoot response back into XML.
|
|
15
|
+
*
|
|
16
|
+
* @param handler - An asynchronous function that takes an XapiRoot object and returns a Promise of an XapiRoot object.
|
|
17
|
+
* @returns An Express middleware function.
|
|
18
|
+
*/
|
|
19
|
+
declare const xapiExpress: (handler: XapiExpressHandler) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { xapiExpress };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { parse, write } from "@xapi-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Express middleware to handle X-API XML requests and responses.
|
|
6
|
+
* It parses incoming XML into an XapiRoot object, passes it to the provided handler function,
|
|
7
|
+
* and then serializes the handler's XapiRoot response back into XML.
|
|
8
|
+
*
|
|
9
|
+
* @param handler - An asynchronous function that takes an XapiRoot object and returns a Promise of an XapiRoot object.
|
|
10
|
+
* @returns An Express middleware function.
|
|
11
|
+
*/
|
|
12
|
+
const xapiExpress = (handler) => {
|
|
13
|
+
return async (req, res, next) => {
|
|
14
|
+
if (req.headers["content-type"] !== "application/xml") return next();
|
|
15
|
+
try {
|
|
16
|
+
const xapiReq = parse(req.body);
|
|
17
|
+
const xapiRes = await handler(xapiReq);
|
|
18
|
+
const xml = write(xapiRes);
|
|
19
|
+
res.setHeader("Content-Type", "application/xml");
|
|
20
|
+
res.write(xml);
|
|
21
|
+
res.end();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
next(error);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { xapiExpress };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xapi-js/adaptor-express",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"express": "^5.1.0",
|
|
34
|
-
"@xapi-js/core": "1.
|
|
34
|
+
"@xapi-js/core": "1.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/express": "^5.0.3",
|
|
38
38
|
"node-mocks-http": "^1.17.2"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
41
|
+
"build": "tsdown",
|
|
42
42
|
"test": "vitest run",
|
|
43
43
|
"test:watch": "vitest",
|
|
44
44
|
"coverage": "vitest run --coverage"
|