@mintlify/http-client 0.0.5 → 0.0.8
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/LICENSE +93 -0
- package/README.md +16 -16
- package/dist/client/baseClient.d.ts +63 -63
- package/dist/client/baseClient.js +93 -93
- package/dist/client/clientError.d.ts +32 -32
- package/dist/client/clientError.js +88 -88
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js +7 -7
- package/dist/client/interfaces.d.ts +93 -93
- package/dist/client/interfaces.js +2 -2
- package/dist/client/types.d.ts +9 -9
- package/dist/client/types.js +2 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -18
- package/dist/leaves-client/constants.d.ts +21 -18
- package/dist/leaves-client/constants.d.ts.map +1 -1
- package/dist/leaves-client/constants.js +19 -16
- package/dist/leaves-client/constants.js.map +1 -1
- package/dist/leaves-client/index.d.ts +5 -5
- package/dist/leaves-client/index.js +23 -23
- package/dist/leaves-client/interfaces.d.ts +18 -16
- package/dist/leaves-client/interfaces.d.ts.map +1 -1
- package/dist/leaves-client/interfaces.js +2 -2
- package/dist/leaves-client/leavesClient.d.ts +7 -7
- package/dist/leaves-client/leavesClient.d.ts.map +1 -1
- package/dist/leaves-client/leavesClient.js +95 -92
- package/dist/leaves-client/leavesClient.js.map +1 -1
- package/dist/leaves-client/types.d.ts +7 -11
- package/dist/leaves-client/types.d.ts.map +1 -1
- package/dist/leaves-client/types.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +78 -77
- package/dist/setup-jest.d.ts +0 -1
- package/dist/setup-jest.js +0 -5
- package/dist/src/client/baseClient.d.ts +0 -63
- package/dist/src/client/baseClient.js +0 -180
- package/dist/src/client/clientError.d.ts +0 -32
- package/dist/src/client/clientError.js +0 -160
- package/dist/src/client/index.d.ts +0 -6
- package/dist/src/client/index.js +0 -7
- package/dist/src/client/interfaces.d.ts +0 -93
- package/dist/src/client/interfaces.js +0 -2
- package/dist/src/client/types.d.ts +0 -9
- package/dist/src/client/types.js +0 -2
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -18
- package/dist/src/leaves-client/constants.d.ts +0 -18
- package/dist/src/leaves-client/constants.js +0 -16
- package/dist/src/leaves-client/index.d.ts +0 -4
- package/dist/src/leaves-client/index.js +0 -8
- package/dist/src/leaves-client/interfaces.d.ts +0 -15
- package/dist/src/leaves-client/interfaces.js +0 -2
- package/dist/src/leaves-client/leavesClient.d.ts +0 -7
- package/dist/src/leaves-client/leavesClient.js +0 -157
- package/dist/src/leaves-client/types.d.ts +0 -11
- package/dist/src/leaves-client/types.js +0 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright (c) 2022 Mintlify, Inc.
|
|
2
|
+
|
|
3
|
+
Elastic License 2.0
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
_As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
+
legal claim._
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion
|
|
77
|
+
of it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over,
|
|
83
|
+
are under the control of, or are under common control with that
|
|
84
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
+
otherwise. Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
+
these terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# @mintlify/http-clients
|
|
2
|
-
|
|
3
|
-
Reusable Mintlify http clients [npm package](https://www.npmjs.com/package/@mintlify/http-client). See [mintlify](../../README.md) for more documentation.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
npm install @mintlify-http-client
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
const client = getLeavesClient(subdomain);
|
|
15
|
-
navPromise = client.getNavigation();
|
|
16
|
-
```
|
|
1
|
+
# @mintlify/http-clients
|
|
2
|
+
|
|
3
|
+
Reusable Mintlify http clients [npm package](https://www.npmjs.com/package/@mintlify/http-client). See [mintlify](../../README.md) for more documentation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install @mintlify-http-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const client = getLeavesClient(subdomain);
|
|
15
|
+
navPromise = client.getNavigation();
|
|
16
|
+
```
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { IBaseClient } from './interfaces';
|
|
2
|
-
import { HttpMethods, QueryType, RequestInitType } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* BaseClient serves as the base class for API clients.
|
|
5
|
-
* Provides basic functionalities for making HTTP requests to a server.
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class BaseClient implements IBaseClient {
|
|
8
|
-
readonly host: string;
|
|
9
|
-
protected readonly reqInit: RequestInit | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* @param host - The server's address.
|
|
12
|
-
* @param reqInit - Optional default request initializer.
|
|
13
|
-
*/
|
|
14
|
-
protected constructor(host: string, reqInit?: RequestInit | undefined);
|
|
15
|
-
fetch(path: string, query?: QueryType, init?: RequestInit): Promise<{
|
|
16
|
-
uri: string;
|
|
17
|
-
res: Response;
|
|
18
|
-
req: RequestInit;
|
|
19
|
-
}>;
|
|
20
|
-
get(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
21
|
-
put(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
22
|
-
delete(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
23
|
-
post(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
24
|
-
text(path: string, query?: QueryType, init?: RequestInit): Promise<string>;
|
|
25
|
-
json<T extends object>(path: string, query?: QueryType, init?: RequestInit): Promise<T>;
|
|
26
|
-
method(method: HttpMethods, path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
27
|
-
/**
|
|
28
|
-
* Constructs a URI path by joining URI components.
|
|
29
|
-
* @param paths - Paths to encode and join.
|
|
30
|
-
* @returns encoded URI path.
|
|
31
|
-
*/
|
|
32
|
-
getPath(...paths: string[]): string;
|
|
33
|
-
/**
|
|
34
|
-
* Constructs a URI by appending a path to the host.
|
|
35
|
-
* @param path - The path to append to the host.
|
|
36
|
-
* @returns URI string.
|
|
37
|
-
*/
|
|
38
|
-
getUri(path: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Handles text responses from the server.
|
|
41
|
-
* @param req - The request object.
|
|
42
|
-
* @param res - The response object.
|
|
43
|
-
* @param uri - The request URI.
|
|
44
|
-
* @returns Promise that resolves with the text data.
|
|
45
|
-
*/
|
|
46
|
-
protected handleText({ req, res, uri, }: {
|
|
47
|
-
req: RequestInit;
|
|
48
|
-
res: Response;
|
|
49
|
-
uri: string;
|
|
50
|
-
}): Promise<string>;
|
|
51
|
-
/**
|
|
52
|
-
* Handles JSON responses from the server.
|
|
53
|
-
* @param req - The request object.
|
|
54
|
-
* @param res - The response object.
|
|
55
|
-
* @param uri - The request URI.
|
|
56
|
-
* @returns Promise that resolves with the JSON data.
|
|
57
|
-
*/
|
|
58
|
-
protected handleJson<T>({ req, res, uri, }: {
|
|
59
|
-
req: RequestInit;
|
|
60
|
-
res: Response;
|
|
61
|
-
uri: string;
|
|
62
|
-
}): Promise<T>;
|
|
63
|
-
}
|
|
1
|
+
import { IBaseClient } from './interfaces';
|
|
2
|
+
import { HttpMethods, QueryType, RequestInitType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* BaseClient serves as the base class for API clients.
|
|
5
|
+
* Provides basic functionalities for making HTTP requests to a server.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseClient implements IBaseClient {
|
|
8
|
+
readonly host: string;
|
|
9
|
+
protected readonly reqInit: RequestInit | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* @param host - The server's address.
|
|
12
|
+
* @param reqInit - Optional default request initializer.
|
|
13
|
+
*/
|
|
14
|
+
protected constructor(host: string, reqInit?: RequestInit | undefined);
|
|
15
|
+
fetch(path: string, query?: QueryType, init?: RequestInit): Promise<{
|
|
16
|
+
uri: string;
|
|
17
|
+
res: Response;
|
|
18
|
+
req: RequestInit;
|
|
19
|
+
}>;
|
|
20
|
+
get(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
21
|
+
put(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
22
|
+
delete(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
23
|
+
post(path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
24
|
+
text(path: string, query?: QueryType, init?: RequestInit): Promise<string>;
|
|
25
|
+
json<T extends object>(path: string, query?: QueryType, init?: RequestInit): Promise<T>;
|
|
26
|
+
method(method: HttpMethods, path: string, query?: QueryType, init?: RequestInitType): Promise<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a URI path by joining URI components.
|
|
29
|
+
* @param paths - Paths to encode and join.
|
|
30
|
+
* @returns encoded URI path.
|
|
31
|
+
*/
|
|
32
|
+
getPath(...paths: string[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Constructs a URI by appending a path to the host.
|
|
35
|
+
* @param path - The path to append to the host.
|
|
36
|
+
* @returns URI string.
|
|
37
|
+
*/
|
|
38
|
+
getUri(path: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Handles text responses from the server.
|
|
41
|
+
* @param req - The request object.
|
|
42
|
+
* @param res - The response object.
|
|
43
|
+
* @param uri - The request URI.
|
|
44
|
+
* @returns Promise that resolves with the text data.
|
|
45
|
+
*/
|
|
46
|
+
protected handleText({ req, res, uri, }: {
|
|
47
|
+
req: RequestInit;
|
|
48
|
+
res: Response;
|
|
49
|
+
uri: string;
|
|
50
|
+
}): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Handles JSON responses from the server.
|
|
53
|
+
* @param req - The request object.
|
|
54
|
+
* @param res - The response object.
|
|
55
|
+
* @param uri - The request URI.
|
|
56
|
+
* @returns Promise that resolves with the JSON data.
|
|
57
|
+
*/
|
|
58
|
+
protected handleJson<T>({ req, res, uri, }: {
|
|
59
|
+
req: RequestInit;
|
|
60
|
+
res: Response;
|
|
61
|
+
uri: string;
|
|
62
|
+
}): Promise<T>;
|
|
63
|
+
}
|
|
64
64
|
//# sourceMappingURL=baseClient.d.ts.map
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseClient = void 0;
|
|
4
|
-
const clientError_1 = require("./clientError");
|
|
5
|
-
/**
|
|
6
|
-
* BaseClient serves as the base class for API clients.
|
|
7
|
-
* Provides basic functionalities for making HTTP requests to a server.
|
|
8
|
-
*/
|
|
9
|
-
class BaseClient {
|
|
10
|
-
/**
|
|
11
|
-
* @param host - The server's address.
|
|
12
|
-
* @param reqInit - Optional default request initializer.
|
|
13
|
-
*/
|
|
14
|
-
constructor(host, reqInit = undefined) {
|
|
15
|
-
this.host = host;
|
|
16
|
-
this.reqInit = reqInit;
|
|
17
|
-
}
|
|
18
|
-
async fetch(path, query, init) {
|
|
19
|
-
const req = {
|
|
20
|
-
...this.reqInit,
|
|
21
|
-
...init,
|
|
22
|
-
headers: {
|
|
23
|
-
...this.reqInit?.headers,
|
|
24
|
-
...init?.headers,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
let uri = this.getUri(path);
|
|
28
|
-
uri = query ? `${uri}?${new URLSearchParams(query)}` : uri;
|
|
29
|
-
return { uri, res: await fetch(uri, req), req };
|
|
30
|
-
}
|
|
31
|
-
get(path, query, init) {
|
|
32
|
-
return this.method('get', path, query, init);
|
|
33
|
-
}
|
|
34
|
-
put(path, query, init) {
|
|
35
|
-
return this.method('put', path, query, init);
|
|
36
|
-
}
|
|
37
|
-
delete(path, query, init) {
|
|
38
|
-
return this.method('delete', path, query, init);
|
|
39
|
-
}
|
|
40
|
-
post(path, query, init) {
|
|
41
|
-
return this.method('post', path, query, init);
|
|
42
|
-
}
|
|
43
|
-
async text(path, query, init) {
|
|
44
|
-
const result = await this.fetch(path, query, init);
|
|
45
|
-
return this.handleText(result);
|
|
46
|
-
}
|
|
47
|
-
async json(path, query, init) {
|
|
48
|
-
const result = await this.fetch(path, query, init);
|
|
49
|
-
return this.handleJson(result);
|
|
50
|
-
}
|
|
51
|
-
async method(method, path, query, init) {
|
|
52
|
-
const result = await this.fetch(path, query, { ...init, method });
|
|
53
|
-
return result.res;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Constructs a URI path by joining URI components.
|
|
57
|
-
* @param paths - Paths to encode and join.
|
|
58
|
-
* @returns encoded URI path.
|
|
59
|
-
*/
|
|
60
|
-
getPath(...paths) {
|
|
61
|
-
return paths.map(encodeURIComponent).join('/');
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Constructs a URI by appending a path to the host.
|
|
65
|
-
* @param path - The path to append to the host.
|
|
66
|
-
* @returns URI string.
|
|
67
|
-
*/
|
|
68
|
-
getUri(path) {
|
|
69
|
-
return encodeURI(`${this.host}/${path}`);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Handles text responses from the server.
|
|
73
|
-
* @param req - The request object.
|
|
74
|
-
* @param res - The response object.
|
|
75
|
-
* @param uri - The request URI.
|
|
76
|
-
* @returns Promise that resolves with the text data.
|
|
77
|
-
*/
|
|
78
|
-
handleText({ req, res, uri, }) {
|
|
79
|
-
return clientError_1.handleText.bind(this)(req, res, uri);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Handles JSON responses from the server.
|
|
83
|
-
* @param req - The request object.
|
|
84
|
-
* @param res - The response object.
|
|
85
|
-
* @param uri - The request URI.
|
|
86
|
-
* @returns Promise that resolves with the JSON data.
|
|
87
|
-
*/
|
|
88
|
-
handleJson({ req, res, uri, }) {
|
|
89
|
-
const handle = (clientError_1.handleJson);
|
|
90
|
-
return handle.bind(this)(req, res, uri);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.BaseClient = BaseClient;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
const clientError_1 = require("./clientError");
|
|
5
|
+
/**
|
|
6
|
+
* BaseClient serves as the base class for API clients.
|
|
7
|
+
* Provides basic functionalities for making HTTP requests to a server.
|
|
8
|
+
*/
|
|
9
|
+
class BaseClient {
|
|
10
|
+
/**
|
|
11
|
+
* @param host - The server's address.
|
|
12
|
+
* @param reqInit - Optional default request initializer.
|
|
13
|
+
*/
|
|
14
|
+
constructor(host, reqInit = undefined) {
|
|
15
|
+
this.host = host;
|
|
16
|
+
this.reqInit = reqInit;
|
|
17
|
+
}
|
|
18
|
+
async fetch(path, query, init) {
|
|
19
|
+
const req = {
|
|
20
|
+
...this.reqInit,
|
|
21
|
+
...init,
|
|
22
|
+
headers: {
|
|
23
|
+
...this.reqInit?.headers,
|
|
24
|
+
...init?.headers,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
let uri = this.getUri(path);
|
|
28
|
+
uri = query ? `${uri}?${new URLSearchParams(query)}` : uri;
|
|
29
|
+
return { uri, res: await fetch(uri, req), req };
|
|
30
|
+
}
|
|
31
|
+
get(path, query, init) {
|
|
32
|
+
return this.method('get', path, query, init);
|
|
33
|
+
}
|
|
34
|
+
put(path, query, init) {
|
|
35
|
+
return this.method('put', path, query, init);
|
|
36
|
+
}
|
|
37
|
+
delete(path, query, init) {
|
|
38
|
+
return this.method('delete', path, query, init);
|
|
39
|
+
}
|
|
40
|
+
post(path, query, init) {
|
|
41
|
+
return this.method('post', path, query, init);
|
|
42
|
+
}
|
|
43
|
+
async text(path, query, init) {
|
|
44
|
+
const result = await this.fetch(path, query, init);
|
|
45
|
+
return this.handleText(result);
|
|
46
|
+
}
|
|
47
|
+
async json(path, query, init) {
|
|
48
|
+
const result = await this.fetch(path, query, init);
|
|
49
|
+
return this.handleJson(result);
|
|
50
|
+
}
|
|
51
|
+
async method(method, path, query, init) {
|
|
52
|
+
const result = await this.fetch(path, query, { ...init, method });
|
|
53
|
+
return result.res;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Constructs a URI path by joining URI components.
|
|
57
|
+
* @param paths - Paths to encode and join.
|
|
58
|
+
* @returns encoded URI path.
|
|
59
|
+
*/
|
|
60
|
+
getPath(...paths) {
|
|
61
|
+
return paths.map(encodeURIComponent).join('/');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Constructs a URI by appending a path to the host.
|
|
65
|
+
* @param path - The path to append to the host.
|
|
66
|
+
* @returns URI string.
|
|
67
|
+
*/
|
|
68
|
+
getUri(path) {
|
|
69
|
+
return encodeURI(`${this.host}/${path}`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Handles text responses from the server.
|
|
73
|
+
* @param req - The request object.
|
|
74
|
+
* @param res - The response object.
|
|
75
|
+
* @param uri - The request URI.
|
|
76
|
+
* @returns Promise that resolves with the text data.
|
|
77
|
+
*/
|
|
78
|
+
handleText({ req, res, uri, }) {
|
|
79
|
+
return clientError_1.handleText.bind(this)(req, res, uri);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Handles JSON responses from the server.
|
|
83
|
+
* @param req - The request object.
|
|
84
|
+
* @param res - The response object.
|
|
85
|
+
* @param uri - The request URI.
|
|
86
|
+
* @returns Promise that resolves with the JSON data.
|
|
87
|
+
*/
|
|
88
|
+
handleJson({ req, res, uri, }) {
|
|
89
|
+
const handle = (clientError_1.handleJson);
|
|
90
|
+
return handle.bind(this)(req, res, uri);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.BaseClient = BaseClient;
|
|
94
94
|
//# sourceMappingURL=baseClient.js.map
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { BaseClient } from './baseClient';
|
|
2
|
-
import { IClientError } from './interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* Type guard for ClientError.
|
|
5
|
-
* @param object - The object to check.
|
|
6
|
-
* @returns True if the object is a ClientError; otherwise, false.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isClientError(object: any): object is IClientError;
|
|
9
|
-
/**
|
|
10
|
-
* Fetches a resource as text.
|
|
11
|
-
* @param req - The request object.
|
|
12
|
-
* @param res - The response object.
|
|
13
|
-
* @param uri - The URI to fetch from.
|
|
14
|
-
* @throws ClientError - If the response is not ok.
|
|
15
|
-
* @returns The fetched text.
|
|
16
|
-
*/
|
|
17
|
-
export declare function handleText(this: BaseClient, req: RequestInit, res: Response, uri: string): Promise<string>;
|
|
18
|
-
/**
|
|
19
|
-
* Fetches a resource as JSON.
|
|
20
|
-
* @param req - The request object.
|
|
21
|
-
* @param res - The response object.
|
|
22
|
-
* @param uri - The URI to fetch from.
|
|
23
|
-
* @throws ClientError - If the response is not ok.
|
|
24
|
-
* @returns The fetched JSON data.
|
|
25
|
-
*/
|
|
26
|
-
export declare function handleJson<T>(this: BaseClient, req: RequestInit, res: Response, uri: string): Promise<T>;
|
|
27
|
-
/**
|
|
28
|
-
* Checks if a client has access to a resource.
|
|
29
|
-
* @param accessCondition - The condition to check to get access.
|
|
30
|
-
* @throws ClientError - If the condition is true.
|
|
31
|
-
*/
|
|
32
|
-
export declare function handleAccess<TClient extends BaseClient>(this: TClient, accessCondition: boolean): void;
|
|
1
|
+
import { BaseClient } from './baseClient';
|
|
2
|
+
import { IClientError } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Type guard for ClientError.
|
|
5
|
+
* @param object - The object to check.
|
|
6
|
+
* @returns True if the object is a ClientError; otherwise, false.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isClientError(object: any): object is IClientError;
|
|
9
|
+
/**
|
|
10
|
+
* Fetches a resource as text.
|
|
11
|
+
* @param req - The request object.
|
|
12
|
+
* @param res - The response object.
|
|
13
|
+
* @param uri - The URI to fetch from.
|
|
14
|
+
* @throws ClientError - If the response is not ok.
|
|
15
|
+
* @returns The fetched text.
|
|
16
|
+
*/
|
|
17
|
+
export declare function handleText(this: BaseClient, req: RequestInit, res: Response, uri: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Fetches a resource as JSON.
|
|
20
|
+
* @param req - The request object.
|
|
21
|
+
* @param res - The response object.
|
|
22
|
+
* @param uri - The URI to fetch from.
|
|
23
|
+
* @throws ClientError - If the response is not ok.
|
|
24
|
+
* @returns The fetched JSON data.
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleJson<T>(this: BaseClient, req: RequestInit, res: Response, uri: string): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a client has access to a resource.
|
|
29
|
+
* @param accessCondition - The condition to check to get access.
|
|
30
|
+
* @throws ClientError - If the condition is true.
|
|
31
|
+
*/
|
|
32
|
+
export declare function handleAccess<TClient extends BaseClient>(this: TClient, accessCondition: boolean): void;
|
|
33
33
|
//# sourceMappingURL=clientError.d.ts.map
|