@iamnnort/request 1.12.3 → 2.0.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/LICENSE.md +2 -2
- package/README.md +114 -23
- package/dist/index.d.mts +72 -102
- package/dist/index.d.ts +72 -102
- package/dist/index.js +1 -561
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -561
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -31
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Nikita Pavets
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,44 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+
# @iamnnort/request
|
|
2
2
|
|
|
3
3
|
Request handler for Node.js - Fast - Interactive - Simple
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
npm install @iamnnort/request
|
|
9
|
+
# or
|
|
8
10
|
yarn add @iamnnort/request
|
|
9
11
|
```
|
|
10
12
|
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
|
-
```
|
|
14
|
-
import {
|
|
15
|
+
```typescript
|
|
16
|
+
import { LoggerLevels, RequestDataSource } from '@iamnnort/request';
|
|
15
17
|
|
|
16
18
|
const dataSource = new RequestDataSource({
|
|
17
|
-
baseUrl: '
|
|
18
|
-
url: '/
|
|
19
|
+
baseUrl: 'https://dummyjson.com',
|
|
20
|
+
url: '/todos',
|
|
21
|
+
logger: {
|
|
22
|
+
name: 'Todo Api',
|
|
23
|
+
level: LoggerLevels.DEBUG,
|
|
24
|
+
},
|
|
19
25
|
});
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
// Search
|
|
28
|
+
const todos = await dataSource.search({
|
|
29
|
+
params: {
|
|
30
|
+
page: 1,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Get by id
|
|
35
|
+
const todo = await dataSource.get(1);
|
|
36
|
+
|
|
37
|
+
// Create
|
|
38
|
+
const newTodo = await dataSource.create({
|
|
39
|
+
data: {
|
|
40
|
+
todo: 'Test todo',
|
|
41
|
+
completed: false,
|
|
42
|
+
userId: 1,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
22
45
|
|
|
23
|
-
|
|
46
|
+
// Update
|
|
47
|
+
const updatedTodo = await dataSource.update(1, {
|
|
48
|
+
data: {
|
|
49
|
+
completed: true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Delete
|
|
54
|
+
await dataSource.remove(1);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Logging
|
|
58
|
+
|
|
59
|
+
Set the `logger` option to enable it.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { LoggerLevels, RequestDataSource } from '@iamnnort/request';
|
|
63
|
+
|
|
64
|
+
const dataSource = new RequestDataSource({
|
|
65
|
+
baseUrl: 'https://dummyjson.com',
|
|
66
|
+
url: '/todos',
|
|
67
|
+
logger: {
|
|
68
|
+
name: 'Todo Api',
|
|
69
|
+
level: LoggerLevels.DEBUG,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
24
72
|
```
|
|
25
73
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
74
|
+
Log levels: `trace`, `debug`, `info`, `warn`, `error`, `fatal`.
|
|
75
|
+
|
|
76
|
+
Logs include the HTTP method, full URL with query parameters, request body, status code, and duration.
|
|
77
|
+
|
|
78
|
+
When the log level is `trace` or `debug`, response body data is also included in the output.
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
DEBUG (Todo Api): GET https://dummyjson.com/todos?page=1
|
|
82
|
+
INFO (Todo Api): GET https://dummyjson.com/todos?page=1 200 OK (150ms)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Configuration
|
|
86
|
+
|
|
87
|
+
### Base Config
|
|
88
|
+
|
|
89
|
+
| Parameter | Type | Description |
|
|
90
|
+
| ---------------------- | ------------------------ | ------------------------------------------------------------------ |
|
|
91
|
+
| `baseUrl` | `string` | Main part of the server URL that will be used for the request |
|
|
92
|
+
| `url` | `string \| number` | Server URL that will be used for the request |
|
|
93
|
+
| `urlParts` | `(string \| number)[]` | Additional parts of URL that will be used for the request |
|
|
94
|
+
| `baseUrlName` | `string` | Key to look up the base URL from `baseUrlMap` |
|
|
95
|
+
| `baseUrlMap` | `Record<string, string>` | Map of named base URLs |
|
|
96
|
+
| `headers` | `object` | Custom headers to be sent |
|
|
97
|
+
| `auth` | `object` | HTTP Basic auth credentials |
|
|
98
|
+
| `bearerToken` | `string` | Bearer token for Authorization header |
|
|
99
|
+
| `apiKey` | `string` | API key sent via `x-api-key` header |
|
|
100
|
+
| `timeout` | `number` | Request timeout in milliseconds |
|
|
101
|
+
| `responseType` | `string` | Response type (e.g. `json`, `text`, `stream`) |
|
|
102
|
+
| `logger` | `object` | Logger configuration |
|
|
103
|
+
| `logger.name` | `string` | Name used as the logger label |
|
|
104
|
+
| `logger.level` | `string` | Log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`) |
|
|
105
|
+
| `serializer` | `object` | Config that allows you to customize serializing |
|
|
106
|
+
| `serializer.arrayFormat` | `string` | Array format (`indices`, `brackets`, `repeat`, `comma`) |
|
|
107
|
+
|
|
108
|
+
### Request Config
|
|
109
|
+
|
|
110
|
+
| Parameter | Type | Description |
|
|
111
|
+
| ------------ | --------- | ------------------------------------------------ |
|
|
112
|
+
| `params` | `object` | URL parameters to be sent with the request |
|
|
113
|
+
| `data` | `object` | Data to be sent as the request body |
|
|
114
|
+
| `urlencoded` | `boolean` | Send data as `application/x-www-form-urlencoded` |
|
|
115
|
+
| `multipart` | `boolean` | Send data as `multipart/form-data` |
|
|
116
|
+
| `xml` | `boolean` | Send data as `text/xml` |
|
|
117
|
+
|
|
118
|
+
## Methods
|
|
119
|
+
|
|
120
|
+
| Method | HTTP Method | Description |
|
|
121
|
+
| ------------ | ----------- | ------------------------------------------ |
|
|
122
|
+
| `search` | `GET` | Search for entities |
|
|
123
|
+
| `searchOne` | `GET` | Search for a single entity |
|
|
124
|
+
| `bulkSearch` | `GET` | Paginated search returning async generator |
|
|
125
|
+
| `get` | `GET` | Get entity by id |
|
|
126
|
+
| `create` | `POST` | Create entity |
|
|
127
|
+
| `bulkCreate` | `POST` | Create multiple entities |
|
|
128
|
+
| `update` | `PUT` | Update entity by id |
|
|
129
|
+
| `bulkUpdate` | `PUT` | Update multiple entities |
|
|
130
|
+
| `remove` | `DELETE` | Remove entity by id |
|
|
131
|
+
| `common` | any | Execute a custom request |
|
|
41
132
|
|
|
42
133
|
## License
|
|
43
134
|
|
|
44
|
-
|
|
135
|
+
MIT © [Nikita Pavets](https://github.com/iamnnort)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,70 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _iamnnort_config_http from '@iamnnort/config/http';
|
|
2
|
+
import { HttpStatuses, HttpMethods } from '@iamnnort/config/http';
|
|
3
|
+
export { HttpMethods, HttpStatuses } from '@iamnnort/config/http';
|
|
4
|
+
import { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
|
|
5
|
+
|
|
6
|
+
type LoggerConfig = {
|
|
7
|
+
name: string;
|
|
8
|
+
level: LoggerLevels;
|
|
9
|
+
};
|
|
10
|
+
declare enum LoggerLevels {
|
|
11
|
+
FATAL = "fatal",
|
|
12
|
+
ERROR = "error",
|
|
13
|
+
WARN = "warn",
|
|
14
|
+
INFO = "info",
|
|
15
|
+
DEBUG = "debug",
|
|
16
|
+
TRACE = "trace"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare class Logger {
|
|
20
|
+
private logger;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
23
|
+
logRequest(request: AxiosRequestConfig): void;
|
|
24
|
+
logResponse(response: AxiosResponse, duration: number): void;
|
|
25
|
+
logError(request: AxiosRequestConfig, error: AxiosError, duration: number): void;
|
|
26
|
+
makeResponse<T>(response: AxiosResponse): {
|
|
27
|
+
success: boolean;
|
|
28
|
+
status: _iamnnort_config_http.HttpStatuses;
|
|
29
|
+
method: _iamnnort_config_http.HttpMethods;
|
|
30
|
+
data: T;
|
|
31
|
+
};
|
|
32
|
+
makeErrorResponse<T>(error: AxiosError): {
|
|
33
|
+
success: boolean;
|
|
34
|
+
status: _iamnnort_config_http.HttpStatuses;
|
|
35
|
+
method: _iamnnort_config_http.HttpMethods;
|
|
36
|
+
data: T;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type PaginationDto = {
|
|
41
|
+
pagination?: boolean | null;
|
|
42
|
+
page?: number | null;
|
|
43
|
+
pageSize?: number | null;
|
|
44
|
+
bulkSize?: number | null;
|
|
45
|
+
};
|
|
46
|
+
type Pagination = {
|
|
47
|
+
total: number;
|
|
48
|
+
currentPage: number;
|
|
49
|
+
lastPage: number;
|
|
50
|
+
from: number;
|
|
51
|
+
to: number;
|
|
52
|
+
pageSize: number;
|
|
53
|
+
};
|
|
54
|
+
type PaginationResponse<T = unknown> = {
|
|
55
|
+
data: T[];
|
|
56
|
+
pagination: Pagination;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type SerializerConfig = {
|
|
60
|
+
arrayFormat: SerializerArrayFormats;
|
|
61
|
+
};
|
|
62
|
+
declare enum SerializerArrayFormats {
|
|
63
|
+
INDICES = "indices",
|
|
64
|
+
BRACKETS = "brackets",
|
|
65
|
+
REPEAT = "repeat",
|
|
66
|
+
COMMA = "comma"
|
|
67
|
+
}
|
|
2
68
|
|
|
3
69
|
type RequestParams = Pick<AxiosRequestConfig, 'params' | 'data'>;
|
|
4
70
|
type RequestConfigParams = Pick<AxiosRequestConfig, 'params' | 'data'>;
|
|
@@ -15,7 +81,6 @@ type RequestConfig = Omit<AxiosRequestConfig, 'baseURL' | 'url'> & {
|
|
|
15
81
|
xml?: boolean;
|
|
16
82
|
};
|
|
17
83
|
type BaseRequestConfig = Pick<AxiosRequestConfig, 'auth' | 'headers' | 'timeout' | 'responseType'> & {
|
|
18
|
-
name?: string;
|
|
19
84
|
baseUrl?: string;
|
|
20
85
|
baseUrlName?: string;
|
|
21
86
|
baseUrlMap?: Record<string, string>;
|
|
@@ -23,11 +88,8 @@ type BaseRequestConfig = Pick<AxiosRequestConfig, 'auth' | 'headers' | 'timeout'
|
|
|
23
88
|
urlParts?: (number | string)[];
|
|
24
89
|
bearerToken?: string;
|
|
25
90
|
apiKey?: string;
|
|
26
|
-
|
|
27
|
-
logger?:
|
|
28
|
-
serializer?: {
|
|
29
|
-
array?: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
30
|
-
};
|
|
91
|
+
serializer?: Partial<SerializerConfig>;
|
|
92
|
+
logger?: Partial<LoggerConfig>;
|
|
31
93
|
};
|
|
32
94
|
type ResponseConfig = {
|
|
33
95
|
raw?: boolean;
|
|
@@ -44,102 +106,10 @@ type RawResponse<T = unknown> = {
|
|
|
44
106
|
method: HttpMethods;
|
|
45
107
|
data: T;
|
|
46
108
|
};
|
|
47
|
-
declare enum HttpMethods {
|
|
48
|
-
GET = "get",
|
|
49
|
-
POST = "post",
|
|
50
|
-
PUT = "put",
|
|
51
|
-
PATCH = "patch",
|
|
52
|
-
DELETE = "delete"
|
|
53
|
-
}
|
|
54
|
-
declare enum HttpStatuses {
|
|
55
|
-
CONTINUE = 100,
|
|
56
|
-
SWITCHING_PROTOCOLS = 101,
|
|
57
|
-
PROCESSING = 102,
|
|
58
|
-
EARLYHINTS = 103,
|
|
59
|
-
OK = 200,
|
|
60
|
-
CREATED = 201,
|
|
61
|
-
ACCEPTED = 202,
|
|
62
|
-
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
63
|
-
NO_CONTENT = 204,
|
|
64
|
-
RESET_CONTENT = 205,
|
|
65
|
-
PARTIAL_CONTENT = 206,
|
|
66
|
-
AMBIGUOUS = 300,
|
|
67
|
-
MOVED_PERMANENTLY = 301,
|
|
68
|
-
FOUND = 302,
|
|
69
|
-
SEE_OTHER = 303,
|
|
70
|
-
NOT_MODIFIED = 304,
|
|
71
|
-
TEMPORARY_REDIRECT = 307,
|
|
72
|
-
PERMANENT_REDIRECT = 308,
|
|
73
|
-
BAD_REQUEST = 400,
|
|
74
|
-
UNAUTHORIZED = 401,
|
|
75
|
-
PAYMENT_REQUIRED = 402,
|
|
76
|
-
FORBIDDEN = 403,
|
|
77
|
-
NOT_FOUND = 404,
|
|
78
|
-
METHOD_NOT_ALLOWED = 405,
|
|
79
|
-
NOT_ACCEPTABLE = 406,
|
|
80
|
-
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
81
|
-
REQUEST_TIMEOUT = 408,
|
|
82
|
-
CONFLICT = 409,
|
|
83
|
-
GONE = 410,
|
|
84
|
-
LENGTH_REQUIRED = 411,
|
|
85
|
-
PRECONDITION_FAILED = 412,
|
|
86
|
-
PAYLOAD_TOO_LARGE = 413,
|
|
87
|
-
URI_TOO_LONG = 414,
|
|
88
|
-
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
89
|
-
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
90
|
-
EXPECTATION_FAILED = 417,
|
|
91
|
-
I_AM_A_TEAPOT = 418,
|
|
92
|
-
MISDIRECTED = 421,
|
|
93
|
-
UNPROCESSABLE_ENTITY = 422,
|
|
94
|
-
FAILED_DEPENDENCY = 424,
|
|
95
|
-
PRECONDITION_REQUIRED = 428,
|
|
96
|
-
TOO_MANY_REQUESTS = 429,
|
|
97
|
-
INTERNAL_SERVER_ERROR = 500,
|
|
98
|
-
NOT_IMPLEMENTED = 501,
|
|
99
|
-
BAD_GATEWAY = 502,
|
|
100
|
-
SERVICE_UNAVAILABLE = 503,
|
|
101
|
-
GATEWAY_TIMEOUT = 504,
|
|
102
|
-
HTTP_VERSION_NOT_SUPPORTED = 505
|
|
103
|
-
}
|
|
104
|
-
type PaginationDto = {
|
|
105
|
-
pagination?: boolean | null;
|
|
106
|
-
page?: number | null;
|
|
107
|
-
pageSize?: number | null;
|
|
108
|
-
bulkSize?: number | null;
|
|
109
|
-
};
|
|
110
|
-
type Pagination = {
|
|
111
|
-
total: number;
|
|
112
|
-
currentPage: number;
|
|
113
|
-
lastPage: number;
|
|
114
|
-
from: number;
|
|
115
|
-
to: number;
|
|
116
|
-
pageSize: number;
|
|
117
|
-
};
|
|
118
|
-
type PaginationResponse<T = unknown> = {
|
|
119
|
-
data: T[];
|
|
120
|
-
pagination: Pagination;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
declare class RequestBuilder {
|
|
124
|
-
baseConfig: BaseRequestConfig;
|
|
125
|
-
requestConfig: RequestConfig;
|
|
126
|
-
config: AxiosRequestConfig;
|
|
127
|
-
constructor(params: {
|
|
128
|
-
baseConfig: BaseRequestConfig;
|
|
129
|
-
requestConfig: RequestConfig;
|
|
130
|
-
});
|
|
131
|
-
makeContentType(): this;
|
|
132
|
-
makeAuth(): this;
|
|
133
|
-
makeUrl(): this;
|
|
134
|
-
makeMethod(): this;
|
|
135
|
-
makeData(): this;
|
|
136
|
-
makeParams(): this;
|
|
137
|
-
makeSerializer(): this;
|
|
138
|
-
build(): AxiosRequestConfig<any>;
|
|
139
|
-
}
|
|
140
109
|
|
|
141
110
|
declare class RequestDataSource<Entity extends Record<string, any> = any, SearchParams extends RequestConfigParams = any, SearchResponse extends Record<string, any> = any, CreateParams extends RequestConfigParams = any, UpdateParams extends RequestConfigParams = any> {
|
|
142
111
|
baseRequestConfig: BaseRequestConfig;
|
|
112
|
+
logger: Logger;
|
|
143
113
|
constructor(baseRequestConfig: BaseRequestConfig);
|
|
144
114
|
common<T>(requestConfig: RequestConfig, responseConfig?: ResponseConfig): Promise<T>;
|
|
145
115
|
common<T>(requestConfig: RequestConfig, responseConfig: ResponseConfig & {
|
|
@@ -150,7 +120,7 @@ declare class RequestDataSource<Entity extends Record<string, any> = any, Search
|
|
|
150
120
|
raw: true;
|
|
151
121
|
}): AsyncGenerator<PaginationResponse<T>>;
|
|
152
122
|
search(config?: SearchParams): Promise<SearchResponse>;
|
|
153
|
-
bulkSearch(config?: SearchParams): AsyncGenerator<Entity[], any,
|
|
123
|
+
bulkSearch(config?: SearchParams): AsyncGenerator<Entity[], any, any>;
|
|
154
124
|
searchOne(config?: SearchParams): Promise<Entity>;
|
|
155
125
|
get(id: number | string, config?: SearchParams): Promise<Entity>;
|
|
156
126
|
create(config: CreateParams): Promise<Entity>;
|
|
@@ -168,4 +138,4 @@ declare class RequestHelper {
|
|
|
168
138
|
static sleep(seconds: number): Promise<unknown>;
|
|
169
139
|
}
|
|
170
140
|
|
|
171
|
-
export { type BaseRequestConfig,
|
|
141
|
+
export { type BaseRequestConfig, Logger, type LoggerConfig, LoggerLevels, type Pagination, type PaginationDto, type PaginationResponse, type RawResponse, type RequestConfig, type RequestConfigParams, RequestDataSource, RequestHelper, type RequestParams, type Response, type ResponseConfig, SerializerArrayFormats, type SerializerConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,70 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _iamnnort_config_http from '@iamnnort/config/http';
|
|
2
|
+
import { HttpStatuses, HttpMethods } from '@iamnnort/config/http';
|
|
3
|
+
export { HttpMethods, HttpStatuses } from '@iamnnort/config/http';
|
|
4
|
+
import { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
|
|
5
|
+
|
|
6
|
+
type LoggerConfig = {
|
|
7
|
+
name: string;
|
|
8
|
+
level: LoggerLevels;
|
|
9
|
+
};
|
|
10
|
+
declare enum LoggerLevels {
|
|
11
|
+
FATAL = "fatal",
|
|
12
|
+
ERROR = "error",
|
|
13
|
+
WARN = "warn",
|
|
14
|
+
INFO = "info",
|
|
15
|
+
DEBUG = "debug",
|
|
16
|
+
TRACE = "trace"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare class Logger {
|
|
20
|
+
private logger;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
23
|
+
logRequest(request: AxiosRequestConfig): void;
|
|
24
|
+
logResponse(response: AxiosResponse, duration: number): void;
|
|
25
|
+
logError(request: AxiosRequestConfig, error: AxiosError, duration: number): void;
|
|
26
|
+
makeResponse<T>(response: AxiosResponse): {
|
|
27
|
+
success: boolean;
|
|
28
|
+
status: _iamnnort_config_http.HttpStatuses;
|
|
29
|
+
method: _iamnnort_config_http.HttpMethods;
|
|
30
|
+
data: T;
|
|
31
|
+
};
|
|
32
|
+
makeErrorResponse<T>(error: AxiosError): {
|
|
33
|
+
success: boolean;
|
|
34
|
+
status: _iamnnort_config_http.HttpStatuses;
|
|
35
|
+
method: _iamnnort_config_http.HttpMethods;
|
|
36
|
+
data: T;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type PaginationDto = {
|
|
41
|
+
pagination?: boolean | null;
|
|
42
|
+
page?: number | null;
|
|
43
|
+
pageSize?: number | null;
|
|
44
|
+
bulkSize?: number | null;
|
|
45
|
+
};
|
|
46
|
+
type Pagination = {
|
|
47
|
+
total: number;
|
|
48
|
+
currentPage: number;
|
|
49
|
+
lastPage: number;
|
|
50
|
+
from: number;
|
|
51
|
+
to: number;
|
|
52
|
+
pageSize: number;
|
|
53
|
+
};
|
|
54
|
+
type PaginationResponse<T = unknown> = {
|
|
55
|
+
data: T[];
|
|
56
|
+
pagination: Pagination;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type SerializerConfig = {
|
|
60
|
+
arrayFormat: SerializerArrayFormats;
|
|
61
|
+
};
|
|
62
|
+
declare enum SerializerArrayFormats {
|
|
63
|
+
INDICES = "indices",
|
|
64
|
+
BRACKETS = "brackets",
|
|
65
|
+
REPEAT = "repeat",
|
|
66
|
+
COMMA = "comma"
|
|
67
|
+
}
|
|
2
68
|
|
|
3
69
|
type RequestParams = Pick<AxiosRequestConfig, 'params' | 'data'>;
|
|
4
70
|
type RequestConfigParams = Pick<AxiosRequestConfig, 'params' | 'data'>;
|
|
@@ -15,7 +81,6 @@ type RequestConfig = Omit<AxiosRequestConfig, 'baseURL' | 'url'> & {
|
|
|
15
81
|
xml?: boolean;
|
|
16
82
|
};
|
|
17
83
|
type BaseRequestConfig = Pick<AxiosRequestConfig, 'auth' | 'headers' | 'timeout' | 'responseType'> & {
|
|
18
|
-
name?: string;
|
|
19
84
|
baseUrl?: string;
|
|
20
85
|
baseUrlName?: string;
|
|
21
86
|
baseUrlMap?: Record<string, string>;
|
|
@@ -23,11 +88,8 @@ type BaseRequestConfig = Pick<AxiosRequestConfig, 'auth' | 'headers' | 'timeout'
|
|
|
23
88
|
urlParts?: (number | string)[];
|
|
24
89
|
bearerToken?: string;
|
|
25
90
|
apiKey?: string;
|
|
26
|
-
|
|
27
|
-
logger?:
|
|
28
|
-
serializer?: {
|
|
29
|
-
array?: 'indices' | 'brackets' | 'repeat' | 'comma';
|
|
30
|
-
};
|
|
91
|
+
serializer?: Partial<SerializerConfig>;
|
|
92
|
+
logger?: Partial<LoggerConfig>;
|
|
31
93
|
};
|
|
32
94
|
type ResponseConfig = {
|
|
33
95
|
raw?: boolean;
|
|
@@ -44,102 +106,10 @@ type RawResponse<T = unknown> = {
|
|
|
44
106
|
method: HttpMethods;
|
|
45
107
|
data: T;
|
|
46
108
|
};
|
|
47
|
-
declare enum HttpMethods {
|
|
48
|
-
GET = "get",
|
|
49
|
-
POST = "post",
|
|
50
|
-
PUT = "put",
|
|
51
|
-
PATCH = "patch",
|
|
52
|
-
DELETE = "delete"
|
|
53
|
-
}
|
|
54
|
-
declare enum HttpStatuses {
|
|
55
|
-
CONTINUE = 100,
|
|
56
|
-
SWITCHING_PROTOCOLS = 101,
|
|
57
|
-
PROCESSING = 102,
|
|
58
|
-
EARLYHINTS = 103,
|
|
59
|
-
OK = 200,
|
|
60
|
-
CREATED = 201,
|
|
61
|
-
ACCEPTED = 202,
|
|
62
|
-
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
63
|
-
NO_CONTENT = 204,
|
|
64
|
-
RESET_CONTENT = 205,
|
|
65
|
-
PARTIAL_CONTENT = 206,
|
|
66
|
-
AMBIGUOUS = 300,
|
|
67
|
-
MOVED_PERMANENTLY = 301,
|
|
68
|
-
FOUND = 302,
|
|
69
|
-
SEE_OTHER = 303,
|
|
70
|
-
NOT_MODIFIED = 304,
|
|
71
|
-
TEMPORARY_REDIRECT = 307,
|
|
72
|
-
PERMANENT_REDIRECT = 308,
|
|
73
|
-
BAD_REQUEST = 400,
|
|
74
|
-
UNAUTHORIZED = 401,
|
|
75
|
-
PAYMENT_REQUIRED = 402,
|
|
76
|
-
FORBIDDEN = 403,
|
|
77
|
-
NOT_FOUND = 404,
|
|
78
|
-
METHOD_NOT_ALLOWED = 405,
|
|
79
|
-
NOT_ACCEPTABLE = 406,
|
|
80
|
-
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
81
|
-
REQUEST_TIMEOUT = 408,
|
|
82
|
-
CONFLICT = 409,
|
|
83
|
-
GONE = 410,
|
|
84
|
-
LENGTH_REQUIRED = 411,
|
|
85
|
-
PRECONDITION_FAILED = 412,
|
|
86
|
-
PAYLOAD_TOO_LARGE = 413,
|
|
87
|
-
URI_TOO_LONG = 414,
|
|
88
|
-
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
89
|
-
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
90
|
-
EXPECTATION_FAILED = 417,
|
|
91
|
-
I_AM_A_TEAPOT = 418,
|
|
92
|
-
MISDIRECTED = 421,
|
|
93
|
-
UNPROCESSABLE_ENTITY = 422,
|
|
94
|
-
FAILED_DEPENDENCY = 424,
|
|
95
|
-
PRECONDITION_REQUIRED = 428,
|
|
96
|
-
TOO_MANY_REQUESTS = 429,
|
|
97
|
-
INTERNAL_SERVER_ERROR = 500,
|
|
98
|
-
NOT_IMPLEMENTED = 501,
|
|
99
|
-
BAD_GATEWAY = 502,
|
|
100
|
-
SERVICE_UNAVAILABLE = 503,
|
|
101
|
-
GATEWAY_TIMEOUT = 504,
|
|
102
|
-
HTTP_VERSION_NOT_SUPPORTED = 505
|
|
103
|
-
}
|
|
104
|
-
type PaginationDto = {
|
|
105
|
-
pagination?: boolean | null;
|
|
106
|
-
page?: number | null;
|
|
107
|
-
pageSize?: number | null;
|
|
108
|
-
bulkSize?: number | null;
|
|
109
|
-
};
|
|
110
|
-
type Pagination = {
|
|
111
|
-
total: number;
|
|
112
|
-
currentPage: number;
|
|
113
|
-
lastPage: number;
|
|
114
|
-
from: number;
|
|
115
|
-
to: number;
|
|
116
|
-
pageSize: number;
|
|
117
|
-
};
|
|
118
|
-
type PaginationResponse<T = unknown> = {
|
|
119
|
-
data: T[];
|
|
120
|
-
pagination: Pagination;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
declare class RequestBuilder {
|
|
124
|
-
baseConfig: BaseRequestConfig;
|
|
125
|
-
requestConfig: RequestConfig;
|
|
126
|
-
config: AxiosRequestConfig;
|
|
127
|
-
constructor(params: {
|
|
128
|
-
baseConfig: BaseRequestConfig;
|
|
129
|
-
requestConfig: RequestConfig;
|
|
130
|
-
});
|
|
131
|
-
makeContentType(): this;
|
|
132
|
-
makeAuth(): this;
|
|
133
|
-
makeUrl(): this;
|
|
134
|
-
makeMethod(): this;
|
|
135
|
-
makeData(): this;
|
|
136
|
-
makeParams(): this;
|
|
137
|
-
makeSerializer(): this;
|
|
138
|
-
build(): AxiosRequestConfig<any>;
|
|
139
|
-
}
|
|
140
109
|
|
|
141
110
|
declare class RequestDataSource<Entity extends Record<string, any> = any, SearchParams extends RequestConfigParams = any, SearchResponse extends Record<string, any> = any, CreateParams extends RequestConfigParams = any, UpdateParams extends RequestConfigParams = any> {
|
|
142
111
|
baseRequestConfig: BaseRequestConfig;
|
|
112
|
+
logger: Logger;
|
|
143
113
|
constructor(baseRequestConfig: BaseRequestConfig);
|
|
144
114
|
common<T>(requestConfig: RequestConfig, responseConfig?: ResponseConfig): Promise<T>;
|
|
145
115
|
common<T>(requestConfig: RequestConfig, responseConfig: ResponseConfig & {
|
|
@@ -150,7 +120,7 @@ declare class RequestDataSource<Entity extends Record<string, any> = any, Search
|
|
|
150
120
|
raw: true;
|
|
151
121
|
}): AsyncGenerator<PaginationResponse<T>>;
|
|
152
122
|
search(config?: SearchParams): Promise<SearchResponse>;
|
|
153
|
-
bulkSearch(config?: SearchParams): AsyncGenerator<Entity[], any,
|
|
123
|
+
bulkSearch(config?: SearchParams): AsyncGenerator<Entity[], any, any>;
|
|
154
124
|
searchOne(config?: SearchParams): Promise<Entity>;
|
|
155
125
|
get(id: number | string, config?: SearchParams): Promise<Entity>;
|
|
156
126
|
create(config: CreateParams): Promise<Entity>;
|
|
@@ -168,4 +138,4 @@ declare class RequestHelper {
|
|
|
168
138
|
static sleep(seconds: number): Promise<unknown>;
|
|
169
139
|
}
|
|
170
140
|
|
|
171
|
-
export { type BaseRequestConfig,
|
|
141
|
+
export { type BaseRequestConfig, Logger, type LoggerConfig, LoggerLevels, type Pagination, type PaginationDto, type PaginationResponse, type RawResponse, type RequestConfig, type RequestConfigParams, RequestDataSource, RequestHelper, type RequestParams, type Response, type ResponseConfig, SerializerArrayFormats, type SerializerConfig };
|