@xapi-js/adaptor-fetch 1.1.0 → 1.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.cjs +53 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -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
|
+
* Sends an X-API request using the Fetch API and parses the XML response.
|
|
30
|
+
*
|
|
31
|
+
* @param url - The URL to send the request to.
|
|
32
|
+
* @param xapi - The XapiRoot object to be serialized into the request body.
|
|
33
|
+
* @param options - Optional Fetch API request initialization options.
|
|
34
|
+
* @returns A Promise that resolves to an XapiRoot object parsed from the response.
|
|
35
|
+
* @throws {Error} if the response body is empty.
|
|
36
|
+
*/
|
|
37
|
+
async function xapiFetch(url, xapi, options) {
|
|
38
|
+
const xml = (0, __xapi_js_core.write)(xapi);
|
|
39
|
+
const response = await fetch(url, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
...options,
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/xml",
|
|
44
|
+
...options?.headers
|
|
45
|
+
},
|
|
46
|
+
body: xml
|
|
47
|
+
});
|
|
48
|
+
if (!response.body) throw new Error("Response body is empty");
|
|
49
|
+
return (0, __xapi_js_core.parse)(await response.text());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.xapiFetch = xapiFetch;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { XapiRoot } from "@xapi-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sends an X-API request using the Fetch API and parses the XML response.
|
|
7
|
+
*
|
|
8
|
+
* @param url - The URL to send the request to.
|
|
9
|
+
* @param xapi - The XapiRoot object to be serialized into the request body.
|
|
10
|
+
* @param options - Optional Fetch API request initialization options.
|
|
11
|
+
* @returns A Promise that resolves to an XapiRoot object parsed from the response.
|
|
12
|
+
* @throws {Error} if the response body is empty.
|
|
13
|
+
*/
|
|
14
|
+
declare function xapiFetch(url: string, xapi: XapiRoot, options?: RequestInit): Promise<XapiRoot>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { xapiFetch };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { XapiRoot } from "@xapi-js/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sends an X-API request using the Fetch API and parses the XML response.
|
|
7
|
+
*
|
|
8
|
+
* @param url - The URL to send the request to.
|
|
9
|
+
* @param xapi - The XapiRoot object to be serialized into the request body.
|
|
10
|
+
* @param options - Optional Fetch API request initialization options.
|
|
11
|
+
* @returns A Promise that resolves to an XapiRoot object parsed from the response.
|
|
12
|
+
* @throws {Error} if the response body is empty.
|
|
13
|
+
*/
|
|
14
|
+
declare function xapiFetch(url: string, xapi: XapiRoot, options?: RequestInit): Promise<XapiRoot>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { xapiFetch };
|
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
|
+
* Sends an X-API request using the Fetch API and parses the XML response.
|
|
6
|
+
*
|
|
7
|
+
* @param url - The URL to send the request to.
|
|
8
|
+
* @param xapi - The XapiRoot object to be serialized into the request body.
|
|
9
|
+
* @param options - Optional Fetch API request initialization options.
|
|
10
|
+
* @returns A Promise that resolves to an XapiRoot object parsed from the response.
|
|
11
|
+
* @throws {Error} if the response body is empty.
|
|
12
|
+
*/
|
|
13
|
+
async function xapiFetch(url, xapi, options) {
|
|
14
|
+
const xml = write(xapi);
|
|
15
|
+
const response = await fetch(url, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
...options,
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/xml",
|
|
20
|
+
...options?.headers
|
|
21
|
+
},
|
|
22
|
+
body: xml
|
|
23
|
+
});
|
|
24
|
+
if (!response.body) throw new Error("Response body is empty");
|
|
25
|
+
return parse(await response.text());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { xapiFetch };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xapi-js/adaptor-fetch",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.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
|
"author": "Clickin <josh87786@gmail.com>",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"vitest": "^3.2.4",
|
|
34
|
-
"@xapi-js/core": "1.
|
|
34
|
+
"@xapi-js/core": "1.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.0.0",
|
|
38
38
|
"vitest-fetch-mock": "^0.4.5"
|
|
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"
|