@api3/commons 0.13.1 → 0.13.3
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/http/index.d.ts +2 -1
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.js.map +1 -1
- package/package.json +7 -7
- package/src/http/index.ts +16 -11
package/dist/http/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type GoAsyncOptions } from '@api3/promise-utils';
|
|
1
2
|
import { type Method, type AxiosError } from 'axios';
|
|
2
3
|
export interface Request {
|
|
3
4
|
readonly method: Method;
|
|
@@ -26,6 +27,6 @@ interface ExecuteRequestError {
|
|
|
26
27
|
statusCode: number | undefined;
|
|
27
28
|
}
|
|
28
29
|
export type ExecuteRequestResult<T> = ExecuteRequestError | ExecuteRequestSuccess<T>;
|
|
29
|
-
export declare function executeRequest<T>(request: Request): Promise<ExecuteRequestResult<T>>;
|
|
30
|
+
export declare function executeRequest<T>(request: Request, options?: GoAsyncOptions<AxiosError>): Promise<ExecuteRequestResult<T>>;
|
|
30
31
|
export {};
|
|
31
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/http/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAc,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAsB,MAAM,OAAO,CAAC;AAIhF,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,eAAO,MAAM,qBAAqB,UAAW,UAAU,KAAG,aAOzD,CAAC;AAEF,UAAU,qBAAqB,CAAC,CAAC;IAC/B,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,UAAU,mBAAmB;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,aAAa,CAAC;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,mBAAmB,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAErF,wBAAsB,cAAc,CAAC,CAAC,EACpC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,GACnC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CA0BlC"}
|
package/dist/http/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const extractAxiosErrorData = (error) => {
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
exports.extractAxiosErrorData = extractAxiosErrorData;
|
|
20
|
-
async function executeRequest(request) {
|
|
20
|
+
async function executeRequest(request, options) {
|
|
21
21
|
const { url, method, body, headers = {}, queryParams = {}, timeout = DEFAULT_TIMEOUT_MS } = request;
|
|
22
22
|
const goAxios = await (0, promise_utils_1.go)(async () => (0, axios_1.default)({
|
|
23
23
|
url,
|
|
@@ -26,7 +26,7 @@ async function executeRequest(request) {
|
|
|
26
26
|
data: body,
|
|
27
27
|
params: queryParams,
|
|
28
28
|
timeout,
|
|
29
|
-
}));
|
|
29
|
+
}), options);
|
|
30
30
|
if (!goAxios.success) {
|
|
31
31
|
return {
|
|
32
32
|
success: false,
|
package/dist/http/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;;;;AA4CA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;;;;AA4CA,wCA6BC;AAzED,uDAA8D;AAC9D,kDAAgF;AAEhF,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAiB3B,MAAM,qBAAqB,GAAG,CAAC,KAAiB,EAAiB,EAAE;IACxE,2DAA2D;IAC3D,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,qBAAqB,yBAOhC;AAiBK,KAAK,UAAU,cAAc,CAClC,OAAgB,EAChB,OAAoC;IAEpC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,OAAO,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC;IAEpG,MAAM,OAAO,GAAG,MAAM,IAAA,kBAAE,EACtB,KAAK,IAAI,EAAE,CACT,IAAA,eAAK,EAAC;QACJ,GAAG;QACH,MAAM;QACN,OAAO;QACP,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,WAAW;QACnB,OAAO;KACR,CAAC,EACJ,OAAO,CACR,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,IAAA,6BAAqB,EAAC,OAAO,CAAC,KAAK,CAAC;YAC/C,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;SACjC,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AACnG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@api3/commons",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"zod": "^3.23.8"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@api3/eslint-plugin-commons": "^
|
|
41
|
-
"@types/jest": "^29.5.
|
|
42
|
-
"@types/lodash": "^4.17.
|
|
43
|
-
"@types/node": "^20.16.
|
|
44
|
-
"eslint": "^8.57.
|
|
45
|
-
"husky": "^9.1.
|
|
40
|
+
"@api3/eslint-plugin-commons": "^3.0.0",
|
|
41
|
+
"@types/jest": "^29.5.13",
|
|
42
|
+
"@types/lodash": "^4.17.9",
|
|
43
|
+
"@types/node": "^20.16.7",
|
|
44
|
+
"eslint": "^8.57.1",
|
|
45
|
+
"husky": "^9.1.6",
|
|
46
46
|
"jest": "^29.7.0",
|
|
47
47
|
"prettier": "^3.3.3",
|
|
48
48
|
"ts-jest": "^29.2.5",
|
package/src/http/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { go } from '@api3/promise-utils';
|
|
1
|
+
import { go, type GoAsyncOptions } from '@api3/promise-utils';
|
|
2
2
|
import axios, { type Method, type AxiosError, type AxiosResponse } from 'axios';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
@@ -42,18 +42,23 @@ interface ExecuteRequestError {
|
|
|
42
42
|
|
|
43
43
|
export type ExecuteRequestResult<T> = ExecuteRequestError | ExecuteRequestSuccess<T>;
|
|
44
44
|
|
|
45
|
-
export async function executeRequest<T>(
|
|
45
|
+
export async function executeRequest<T>(
|
|
46
|
+
request: Request,
|
|
47
|
+
options?: GoAsyncOptions<AxiosError>
|
|
48
|
+
): Promise<ExecuteRequestResult<T>> {
|
|
46
49
|
const { url, method, body, headers = {}, queryParams = {}, timeout = DEFAULT_TIMEOUT_MS } = request;
|
|
47
50
|
|
|
48
|
-
const goAxios = await go<Promise<AxiosResponse<T>>, AxiosError>(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const goAxios = await go<Promise<AxiosResponse<T>>, AxiosError>(
|
|
52
|
+
async () =>
|
|
53
|
+
axios({
|
|
54
|
+
url,
|
|
55
|
+
method,
|
|
56
|
+
headers,
|
|
57
|
+
data: body,
|
|
58
|
+
params: queryParams,
|
|
59
|
+
timeout,
|
|
60
|
+
}),
|
|
61
|
+
options
|
|
57
62
|
);
|
|
58
63
|
if (!goAxios.success) {
|
|
59
64
|
return {
|