@celljs/http 4.3.0 → 4.4.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/README.md +66 -1
- package/cell.schema.json +17 -0
- package/cell.yml +4 -5
- package/esm/common/client/client-protocol.d.ts +51 -5
- package/esm/common/client/client-protocol.js.map +1 -1
- package/esm/common/client/default-rest-operations.d.ts +30 -0
- package/esm/common/client/default-rest-operations.js +224 -0
- package/esm/common/client/default-rest-operations.js.map +1 -0
- package/esm/common/client/http-client-error.d.ts +25 -0
- package/esm/common/client/http-client-error.js +22 -0
- package/esm/common/client/http-client-error.js.map +1 -0
- package/esm/common/client/index.d.ts +3 -0
- package/esm/common/client/index.js +3 -0
- package/esm/common/client/index.js.map +1 -1
- package/esm/common/client/interceptor-manager.d.ts +14 -0
- package/esm/common/client/interceptor-manager.js +27 -0
- package/esm/common/client/interceptor-manager.js.map +1 -0
- package/esm/common/client/rest-operations-factory.d.ts +2 -3
- package/esm/common/client/rest-operations-factory.js +4 -4
- package/esm/common/client/rest-operations-factory.js.map +1 -1
- package/lib/common/client/client-protocol.d.ts +51 -5
- package/lib/common/client/client-protocol.d.ts.map +1 -1
- package/lib/common/client/client-protocol.js.map +1 -1
- package/lib/common/client/default-rest-operations.d.ts +31 -0
- package/lib/common/client/default-rest-operations.d.ts.map +1 -0
- package/lib/common/client/default-rest-operations.js +228 -0
- package/lib/common/client/default-rest-operations.js.map +1 -0
- package/lib/common/client/default-rest-operations.spec.d.ts +2 -0
- package/lib/common/client/default-rest-operations.spec.d.ts.map +1 -0
- package/lib/common/client/default-rest-operations.spec.js +168 -0
- package/lib/common/client/default-rest-operations.spec.js.map +1 -0
- package/lib/common/client/http-client-error.d.ts +26 -0
- package/lib/common/client/http-client-error.d.ts.map +1 -0
- package/lib/common/client/http-client-error.js +26 -0
- package/lib/common/client/http-client-error.js.map +1 -0
- package/lib/common/client/index.d.ts +3 -0
- package/lib/common/client/index.d.ts.map +1 -1
- package/lib/common/client/index.js +3 -0
- package/lib/common/client/index.js.map +1 -1
- package/lib/common/client/interceptor-manager.d.ts +15 -0
- package/lib/common/client/interceptor-manager.d.ts.map +1 -0
- package/lib/common/client/interceptor-manager.js +31 -0
- package/lib/common/client/interceptor-manager.js.map +1 -0
- package/lib/common/client/rest-operations-factory.d.ts +2 -3
- package/lib/common/client/rest-operations-factory.d.ts.map +1 -1
- package/lib/common/client/rest-operations-factory.js +4 -7
- package/lib/common/client/rest-operations-factory.js.map +1 -1
- package/package.json +4 -4
- package/src/common/client/client-protocol.ts +53 -5
- package/src/common/client/default-rest-operations.spec.ts +190 -0
- package/src/common/client/default-rest-operations.ts +237 -0
- package/src/common/client/http-client-error.ts +31 -0
- package/src/common/client/index.ts +3 -0
- package/src/common/client/interceptor-manager.ts +33 -0
- package/src/common/client/rest-operations-factory.ts +5 -5
package/README.md
CHANGED
|
@@ -1 +1,66 @@
|
|
|
1
|
-
# Cell - Http Component
|
|
1
|
+
# Cell - Http Component
|
|
2
|
+
|
|
3
|
+
The shared HTTP vocabulary of Cell and an HTTP client for calling other services, in the frontend and the backend.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @celljs/http
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Constants
|
|
10
|
+
|
|
11
|
+
`HttpStatus` (`HttpStatus.NOT_FOUND`, ...), `HttpMethod`, `MediaType` (`MediaType.APPLICATION_JSON`, ...) and `HttpHeaders` (`HttpHeaders.AUTHORIZATION`, ...), used by `@celljs/web`, `@celljs/mvc` and `@celljs/security`.
|
|
12
|
+
|
|
13
|
+
## HTTP client
|
|
14
|
+
|
|
15
|
+
`RestOperations` is an HTTP client on the `fetch` of the runtime (Node.js 18+, Bun, Deno, workerd, browsers), with no third-party dependency. Its API is the familiar subset of axios: `get`, `delete`, `head`, `options`, `post`, `put`, `patch` and `request` resolve to `{ status, statusText, headers, data, config }`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Autowired, Component } from '@celljs/core';
|
|
19
|
+
import { RestOperations } from '@celljs/http';
|
|
20
|
+
|
|
21
|
+
@Component()
|
|
22
|
+
export class WeatherClient {
|
|
23
|
+
@Autowired(RestOperations)
|
|
24
|
+
protected readonly rest: RestOperations;
|
|
25
|
+
|
|
26
|
+
async today(city: string) {
|
|
27
|
+
const { data } = await this.rest.get('https://api.example.com/weather', { params: { city } });
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The request config (`RequestConfig`):
|
|
34
|
+
|
|
35
|
+
| Option | Meaning |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `url`, `method`, `baseURL` | `baseURL` is prefixed to `url` unless `url` is absolute |
|
|
38
|
+
| `headers` | merged with the default headers, case-insensitively; `undefined` leaves a header out |
|
|
39
|
+
| `params` | the query string; an array repeats the key (`tag=a&tag=b`), `undefined` / `null` are left out |
|
|
40
|
+
| `data` | the body: a string, `URLSearchParams`, `FormData`, `Blob`, binary data or a stream is sent as is, anything else as JSON (`content-type: application/json` unless set). `GET` and `HEAD` send no body |
|
|
41
|
+
| `timeout` | milliseconds; no limit by default |
|
|
42
|
+
| `signal` | an `AbortSignal` that cancels the request |
|
|
43
|
+
| `responseType` | `json` (default: JSON is parsed, anything else stays text), `text`, `arraybuffer`, `blob` or `stream` (the `ReadableStream` of the body) |
|
|
44
|
+
| `validateStatus` | which statuses resolve, default 2xx; `null` resolves every status |
|
|
45
|
+
| `withCredentials` | in the browser, sends cookies cross-origin too (`credentials: 'include'`) |
|
|
46
|
+
|
|
47
|
+
Answer headers have lower-case names. A failed request rejects with an `HttpClientError` whose `code` says why: `CELL_HTTP_BAD_STATUS` (the status did not pass `validateStatus`; `error.response` holds the answer), `CELL_HTTP_TIMEOUT`, `CELL_HTTP_ABORTED` or `CELL_HTTP_NETWORK` (`error.cause` is the error of `fetch`). `HttpClientError.is(error, 'CELL_HTTP_BAD_STATUS')` tests for one.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
try {
|
|
51
|
+
await this.rest.post('/orders', order);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (HttpClientError.is(error, 'CELL_HTTP_BAD_STATUS') && error.response!.status === 409) {
|
|
54
|
+
// ...
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`http.client` in `cell.yml` holds the defaults of every request, with the options above; the frontend receives it too. The defaults send `X-Requested-With: XMLHttpRequest`, which tells `@celljs/security` to answer `401` instead of redirecting to the login page, and `withCredentials: true`, which only the browser uses.
|
|
61
|
+
|
|
62
|
+
Interceptors work as in axios, except that both kinds run in the order they were added: `rest.interceptors.request.use(config => config)` changes the config before the request is sent, `rest.interceptors.response.use(onAnswer, onError)` the answer or the failure; `use` returns an id for `eject`. To add them to the shared instance, inject `RestOperations` in a component and call `use` in a `@PostConstruct` method, or bind your own `RestOperationsFactory` (`rebind: true`). `new DefaultRestOperations(config)` gives a separate client.
|
|
63
|
+
|
|
64
|
+
On the server, URLs must be absolute (or relative to `baseURL`). Behind an HTTP proxy, the `fetch` of Node.js ignores `HTTP_PROXY` / `HTTPS_PROXY` unless `NODE_USE_ENV_PROXY=1` is set, which only recent Node.js versions support; Bun and Deno read them by themselves.
|
|
65
|
+
|
|
66
|
+
For calls between Cell applications, [`@celljs/rpc`](../rpc) gives typed proxies instead.
|
package/cell.schema.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"properties": {
|
|
4
|
+
"http": {
|
|
5
|
+
"type": "object",
|
|
6
|
+
"description": "HTTP client.",
|
|
7
|
+
"properties": {
|
|
8
|
+
"client": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"description": "Default request options of the HTTP client (axios-style: headers, timeout, withCredentials...).",
|
|
11
|
+
"additionalProperties": true
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"x-cell-public": true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/cell.yml
CHANGED
|
@@ -1,18 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { InterceptorManager } from './interceptor-manager.js';
|
|
2
2
|
export declare const RestOperations: unique symbol;
|
|
3
3
|
export declare const RestOperationsFactory: unique symbol;
|
|
4
|
-
|
|
4
|
+
/** How the body of a response is read; by default it is parsed as JSON when it is JSON and kept as text otherwise. */
|
|
5
|
+
export type ResponseType = 'json' | 'text' | 'arraybuffer' | 'blob' | 'stream';
|
|
6
|
+
export interface RequestConfig {
|
|
7
|
+
url?: string;
|
|
8
|
+
method?: string;
|
|
9
|
+
/** Prefixed to `url` unless `url` is absolute. */
|
|
10
|
+
baseURL?: string;
|
|
11
|
+
headers?: Record<string, string | number | boolean | undefined>;
|
|
12
|
+
/** Appended to the query string; an array repeats the key, `undefined` and `null` are left out. */
|
|
13
|
+
params?: Record<string, unknown> | URLSearchParams;
|
|
14
|
+
/** Sent as is when it is a string, `URLSearchParams`, `FormData`, `Blob`, binary data or a stream, as JSON otherwise. */
|
|
15
|
+
data?: unknown;
|
|
16
|
+
/** Milliseconds before the request is aborted with `CELL_HTTP_TIMEOUT`; no limit by default. */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
/** Sends cookies cross-origin in the browser (`credentials: 'include'`). */
|
|
19
|
+
withCredentials?: boolean;
|
|
20
|
+
responseType?: ResponseType;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
/** Which statuses resolve; the others reject with `CELL_HTTP_BAD_STATUS`. `null` resolves every status. Default: 2xx. */
|
|
23
|
+
validateStatus?: ((status: number) => boolean) | null;
|
|
24
|
+
}
|
|
25
|
+
export interface RestResponse<T = any> {
|
|
26
|
+
status: number;
|
|
27
|
+
statusText: string;
|
|
28
|
+
/** Lower-case header names. */
|
|
29
|
+
headers: Record<string, string>;
|
|
30
|
+
data: T;
|
|
31
|
+
config: RequestConfig;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An HTTP client on `fetch` with the axios-style API: `get`, `post`, ... resolve to a `RestResponse`
|
|
35
|
+
* and reject with an `HttpClientError` when the status is not 2xx.
|
|
36
|
+
*/
|
|
37
|
+
export interface RestOperations {
|
|
38
|
+
readonly defaults: RequestConfig;
|
|
39
|
+
readonly interceptors: {
|
|
40
|
+
request: InterceptorManager<RequestConfig>;
|
|
41
|
+
response: InterceptorManager<RestResponse>;
|
|
42
|
+
};
|
|
43
|
+
request<T = any>(config: RequestConfig): Promise<RestResponse<T>>;
|
|
44
|
+
get<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
45
|
+
delete<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
46
|
+
head<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
47
|
+
options<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
48
|
+
post<T = any>(url: string, data?: unknown, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
49
|
+
put<T = any>(url: string, data?: unknown, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
50
|
+
patch<T = any>(url: string, data?: unknown, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
5
51
|
}
|
|
6
52
|
export interface RestOperationsFactory {
|
|
7
53
|
create(): RestOperations;
|
|
8
54
|
}
|
|
9
55
|
export interface ResponseEntity<T> {
|
|
10
56
|
status: number;
|
|
11
|
-
headers:
|
|
57
|
+
headers: Record<string, string>;
|
|
12
58
|
body: T;
|
|
13
59
|
}
|
|
14
60
|
export declare class ResponseEntityUtil {
|
|
15
|
-
static ok<T>(body: T, headers?:
|
|
16
|
-
static created<T>(body: T, headers?:
|
|
61
|
+
static ok<T>(body: T, headers?: Record<string, string>): ResponseEntity<T>;
|
|
62
|
+
static created<T>(body: T, headers?: Record<string, string>): ResponseEntity<T>;
|
|
17
63
|
static noContent(): ResponseEntity<void>;
|
|
18
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-protocol.js","sourceRoot":"","sources":["../../../src/common/client/client-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"client-protocol.js","sourceRoot":"","sources":["../../../src/common/client/client-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAgErE,MAAM,OAAO,kBAAkB;IAC3B,MAAM,CAAC,EAAE,CAAI,IAAO,EAAE,OAAgC;QAClD,OAAO;YACH,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,IAAI;SACP,CAAC;IACN,CAAC;IAED,MAAM,CAAC,OAAO,CAAI,IAAO,EAAE,OAAgC;QACvD,OAAO;YACH,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,IAAI;SACP,CAAC;IACN,CAAC;IAED,MAAM,CAAC,SAAS;QACZ,OAAO;YACH,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,SAAS;SAClB,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RequestConfig, RestOperations, RestResponse } from './client-protocol.js';
|
|
2
|
+
import { HttpClientError } from './http-client-error.js';
|
|
3
|
+
import { InterceptorManager } from './interceptor-manager.js';
|
|
4
|
+
/** `RestOperations` on the global `fetch` of the runtime (Node.js 18+, Bun, Deno, workerd, browsers). */
|
|
5
|
+
export declare class DefaultRestOperations implements RestOperations {
|
|
6
|
+
readonly defaults: RequestConfig;
|
|
7
|
+
readonly interceptors: {
|
|
8
|
+
request: InterceptorManager<RequestConfig>;
|
|
9
|
+
response: InterceptorManager<RestResponse<any>>;
|
|
10
|
+
};
|
|
11
|
+
constructor(defaults?: RequestConfig);
|
|
12
|
+
request<T = any>(config: RequestConfig): Promise<RestResponse<T>>;
|
|
13
|
+
get<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
14
|
+
delete<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
15
|
+
head<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
16
|
+
options<T = any>(url: string, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
17
|
+
post<T = any>(url: string, data?: unknown, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
18
|
+
put<T = any>(url: string, data?: unknown, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
19
|
+
patch<T = any>(url: string, data?: unknown, config?: RequestConfig): Promise<RestResponse<T>>;
|
|
20
|
+
protected merge(config: RequestConfig): RequestConfig;
|
|
21
|
+
protected send(config: RequestConfig): Promise<RestResponse>;
|
|
22
|
+
protected toError(error: unknown, config: RequestConfig, request: string, timedOut: boolean): HttpClientError;
|
|
23
|
+
protected buildURL(config: RequestConfig): string;
|
|
24
|
+
protected serializeParams(params: RequestConfig['params']): string;
|
|
25
|
+
protected buildHeaders(config: RequestConfig): Headers;
|
|
26
|
+
protected serialize(data: unknown, headers: Headers): BodyInit | undefined;
|
|
27
|
+
protected parse(response: Response, config: RequestConfig): Promise<any>;
|
|
28
|
+
protected readHeaders(headers: Headers): Record<string, string>;
|
|
29
|
+
protected static isSuccess(status: number): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { HttpClientError } from './http-client-error.js';
|
|
2
|
+
import { InterceptorManager } from './interceptor-manager.js';
|
|
3
|
+
const ABSOLUTE_URL = /^([a-z][a-z\d+\-.]*:)?\/\//i;
|
|
4
|
+
/** `RestOperations` on the global `fetch` of the runtime (Node.js 18+, Bun, Deno, workerd, browsers). */
|
|
5
|
+
export class DefaultRestOperations {
|
|
6
|
+
constructor(defaults = {}) {
|
|
7
|
+
this.defaults = defaults;
|
|
8
|
+
this.interceptors = {
|
|
9
|
+
request: new InterceptorManager(),
|
|
10
|
+
response: new InterceptorManager()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
request(config) {
|
|
14
|
+
const sent = this.interceptors.request.apply(Promise.resolve(this.merge(config))).then(merged => this.send(merged));
|
|
15
|
+
return this.interceptors.response.apply(sent);
|
|
16
|
+
}
|
|
17
|
+
get(url, config) {
|
|
18
|
+
return this.request({ ...config, url, method: 'GET' });
|
|
19
|
+
}
|
|
20
|
+
delete(url, config) {
|
|
21
|
+
return this.request({ ...config, url, method: 'DELETE' });
|
|
22
|
+
}
|
|
23
|
+
head(url, config) {
|
|
24
|
+
return this.request({ ...config, url, method: 'HEAD' });
|
|
25
|
+
}
|
|
26
|
+
options(url, config) {
|
|
27
|
+
return this.request({ ...config, url, method: 'OPTIONS' });
|
|
28
|
+
}
|
|
29
|
+
post(url, data, config) {
|
|
30
|
+
return this.request({ ...config, url, data, method: 'POST' });
|
|
31
|
+
}
|
|
32
|
+
put(url, data, config) {
|
|
33
|
+
return this.request({ ...config, url, data, method: 'PUT' });
|
|
34
|
+
}
|
|
35
|
+
patch(url, data, config) {
|
|
36
|
+
return this.request({ ...config, url, data, method: 'PATCH' });
|
|
37
|
+
}
|
|
38
|
+
merge(config) {
|
|
39
|
+
return { ...this.defaults, ...config, headers: { ...this.defaults.headers, ...config.headers } };
|
|
40
|
+
}
|
|
41
|
+
async send(config) {
|
|
42
|
+
var _a;
|
|
43
|
+
var _b;
|
|
44
|
+
const method = (config.method || 'GET').toUpperCase();
|
|
45
|
+
const url = this.buildURL(config);
|
|
46
|
+
const headers = this.buildHeaders(config);
|
|
47
|
+
const init = { method, headers };
|
|
48
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
49
|
+
init.body = this.serialize(config.data, headers);
|
|
50
|
+
if (typeof ReadableStream !== 'undefined' && init.body instanceof ReadableStream) {
|
|
51
|
+
init.duplex = 'half';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Only browsers send cookies by credentials; some server runtimes (workerd) reject the field.
|
|
55
|
+
if (config.withCredentials !== undefined && typeof window !== 'undefined') {
|
|
56
|
+
init.credentials = config.withCredentials ? 'include' : 'same-origin';
|
|
57
|
+
}
|
|
58
|
+
const controller = config.timeout ? new AbortController() : undefined;
|
|
59
|
+
let timedOut = false;
|
|
60
|
+
const timer = controller && setTimeout(() => {
|
|
61
|
+
timedOut = true;
|
|
62
|
+
controller.abort();
|
|
63
|
+
}, config.timeout);
|
|
64
|
+
const forward = () => controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
65
|
+
if (controller && config.signal) {
|
|
66
|
+
if (config.signal.aborted) {
|
|
67
|
+
controller.abort();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
config.signal.addEventListener('abort', forward, { once: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
init.signal = (_b = controller === null || controller === void 0 ? void 0 : controller.signal) !== null && _b !== void 0 ? _b : config.signal;
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(url, init);
|
|
76
|
+
const result = {
|
|
77
|
+
status: response.status,
|
|
78
|
+
statusText: response.statusText,
|
|
79
|
+
headers: this.readHeaders(response.headers),
|
|
80
|
+
data: await this.parse(response, config),
|
|
81
|
+
config
|
|
82
|
+
};
|
|
83
|
+
const validate = config.validateStatus === undefined ? DefaultRestOperations.isSuccess : config.validateStatus;
|
|
84
|
+
if (validate && !validate(result.status)) {
|
|
85
|
+
throw new HttpClientError({
|
|
86
|
+
code: 'CELL_HTTP_BAD_STATUS',
|
|
87
|
+
message: `${method} ${url} answered ${result.status} ${result.statusText}`.trimEnd(),
|
|
88
|
+
hint: 'error.response holds the status, headers and body of the answer; pass validateStatus to resolve such statuses instead.',
|
|
89
|
+
config,
|
|
90
|
+
response: result
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw this.toError(error, config, `${method} ${url}`, timedOut);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
(_a = config.signal) === null || _a === void 0 ? void 0 : _a.removeEventListener('abort', forward);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
toError(error, config, request, timedOut) {
|
|
104
|
+
var _a;
|
|
105
|
+
var _b;
|
|
106
|
+
if (error instanceof HttpClientError) {
|
|
107
|
+
return error;
|
|
108
|
+
}
|
|
109
|
+
if (timedOut) {
|
|
110
|
+
return new HttpClientError({
|
|
111
|
+
code: 'CELL_HTTP_TIMEOUT',
|
|
112
|
+
message: `${request} took longer than ${config.timeout} ms`,
|
|
113
|
+
hint: 'Raise timeout in the request config or http.client in cell.yml, or check why the server is slow.',
|
|
114
|
+
config,
|
|
115
|
+
cause: error
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if ((_a = config.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
119
|
+
return new HttpClientError({
|
|
120
|
+
code: 'CELL_HTTP_ABORTED',
|
|
121
|
+
message: `${request} was aborted`,
|
|
122
|
+
hint: 'The signal passed in the request config was aborted; nothing to fix unless that was not intended.',
|
|
123
|
+
config,
|
|
124
|
+
cause: error
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return new HttpClientError({
|
|
128
|
+
code: 'CELL_HTTP_NETWORK',
|
|
129
|
+
message: `${request} failed: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`,
|
|
130
|
+
hint: 'Check that the host is reachable and, on the server, that the URL is absolute; behind a proxy, Node.js uses HTTP_PROXY / HTTPS_PROXY only with NODE_USE_ENV_PROXY=1.',
|
|
131
|
+
config,
|
|
132
|
+
cause: error
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
buildURL(config) {
|
|
136
|
+
let url = config.url || '';
|
|
137
|
+
if (config.baseURL && !ABSOLUTE_URL.test(url)) {
|
|
138
|
+
url = url ? `${config.baseURL.replace(/\/+$/, '')}/${url.replace(/^\/+/, '')}` : config.baseURL;
|
|
139
|
+
}
|
|
140
|
+
const query = this.serializeParams(config.params);
|
|
141
|
+
if (!query) {
|
|
142
|
+
return url;
|
|
143
|
+
}
|
|
144
|
+
const hash = url.indexOf('#');
|
|
145
|
+
if (hash !== -1) {
|
|
146
|
+
url = url.slice(0, hash);
|
|
147
|
+
}
|
|
148
|
+
return url + (url.includes('?') ? '&' : '?') + query;
|
|
149
|
+
}
|
|
150
|
+
serializeParams(params) {
|
|
151
|
+
if (!params) {
|
|
152
|
+
return '';
|
|
153
|
+
}
|
|
154
|
+
if (params instanceof URLSearchParams) {
|
|
155
|
+
return params.toString();
|
|
156
|
+
}
|
|
157
|
+
const search = new URLSearchParams();
|
|
158
|
+
for (const [key, value] of Object.entries(params)) {
|
|
159
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
160
|
+
if (item !== undefined && item !== null) {
|
|
161
|
+
search.append(key, item instanceof Date ? item.toISOString() : typeof item === 'object' ? JSON.stringify(item) : String(item));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return search.toString();
|
|
166
|
+
}
|
|
167
|
+
buildHeaders(config) {
|
|
168
|
+
const headers = new Headers();
|
|
169
|
+
for (const [name, value] of Object.entries(config.headers || {})) {
|
|
170
|
+
if (value !== undefined && value !== null) {
|
|
171
|
+
headers.set(name, String(value));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return headers;
|
|
175
|
+
}
|
|
176
|
+
serialize(data, headers) {
|
|
177
|
+
if (data === undefined || data === null) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
if (typeof data === 'string' || data instanceof URLSearchParams || data instanceof ArrayBuffer || ArrayBuffer.isView(data)
|
|
181
|
+
|| (typeof FormData !== 'undefined' && data instanceof FormData)
|
|
182
|
+
|| (typeof Blob !== 'undefined' && data instanceof Blob)
|
|
183
|
+
|| (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream)) {
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
if (!headers.has('content-type')) {
|
|
187
|
+
headers.set('content-type', 'application/json');
|
|
188
|
+
}
|
|
189
|
+
return JSON.stringify(data);
|
|
190
|
+
}
|
|
191
|
+
async parse(response, config) {
|
|
192
|
+
switch (config.responseType) {
|
|
193
|
+
case 'stream':
|
|
194
|
+
return response.body;
|
|
195
|
+
case 'arraybuffer':
|
|
196
|
+
return response.arrayBuffer();
|
|
197
|
+
case 'blob':
|
|
198
|
+
return response.blob();
|
|
199
|
+
case 'text':
|
|
200
|
+
return response.text();
|
|
201
|
+
}
|
|
202
|
+
const text = await response.text();
|
|
203
|
+
if (!text) {
|
|
204
|
+
return text;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
return JSON.parse(text);
|
|
208
|
+
}
|
|
209
|
+
catch (_a) {
|
|
210
|
+
return text;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
readHeaders(headers) {
|
|
214
|
+
const result = {};
|
|
215
|
+
headers.forEach((value, name) => {
|
|
216
|
+
result[name] = result[name] === undefined ? value : `${result[name]}, ${value}`;
|
|
217
|
+
});
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
static isSuccess(status) {
|
|
221
|
+
return status >= 200 && status < 300;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=default-rest-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-rest-operations.js","sourceRoot":"","sources":["../../../src/common/client/default-rest-operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,kBAAk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
+
import type { RequestConfig, RestResponse } from './client-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Why a request of `RestOperations` failed. `code` is stable and `hint` says how to fix it in one
|
|
4
|
+
* sentence (docs/design/agent-first.md R5); `response` is there when the server answered.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpClientError extends Error {
|
|
7
|
+
readonly name = "HttpClientError";
|
|
8
|
+
readonly code: HttpClientError.Code;
|
|
9
|
+
readonly hint: string;
|
|
10
|
+
readonly config: RequestConfig;
|
|
11
|
+
readonly response?: RestResponse;
|
|
12
|
+
readonly cause?: unknown;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
code: HttpClientError.Code;
|
|
15
|
+
message: string;
|
|
16
|
+
hint: string;
|
|
17
|
+
config: RequestConfig;
|
|
18
|
+
response?: RestResponse;
|
|
19
|
+
cause?: unknown;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export declare namespace HttpClientError {
|
|
23
|
+
type Code = 'CELL_HTTP_BAD_STATUS' | 'CELL_HTTP_TIMEOUT' | 'CELL_HTTP_ABORTED' | 'CELL_HTTP_NETWORK';
|
|
24
|
+
function is(error: unknown, code?: Code): error is HttpClientError;
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a request of `RestOperations` failed. `code` is stable and `hint` says how to fix it in one
|
|
3
|
+
* sentence (docs/design/agent-first.md R5); `response` is there when the server answered.
|
|
4
|
+
*/
|
|
5
|
+
export class HttpClientError extends Error {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options.message);
|
|
8
|
+
this.name = 'HttpClientError';
|
|
9
|
+
this.code = options.code;
|
|
10
|
+
this.hint = options.hint;
|
|
11
|
+
this.config = options.config;
|
|
12
|
+
this.response = options.response;
|
|
13
|
+
this.cause = options.cause;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
(function (HttpClientError) {
|
|
17
|
+
function is(error, code) {
|
|
18
|
+
return error instanceof HttpClientError && (code === undefined || error.code === code);
|
|
19
|
+
}
|
|
20
|
+
HttpClientError.is = is;
|
|
21
|
+
})(HttpClientError || (HttpClientError = {}));
|
|
22
|
+
//# sourceMappingURL=http-client-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client-error.js","sourceRoot":"","sources":["../../../src/common/client/http-client-error.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAQtC,YAAY,OAAuI;QAC/I,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QART,SAAI,GAAG,iBAAiB,CAAC;QASvC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC/B,CAAC;CACJ;AAED,WAAiB,eAAe;IAG5B,SAAgB,EAAE,CAAC,KAAc,EAAE,IAAW;QAC1C,OAAO,KAAK,YAAY,eAAe,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC3F,CAAC;IAFe,gBAAA,EAAE,KAEjB,CAAA;AACL,CAAC,EANgB,eAAe,KAAf,eAAe,QAM/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Interceptor<V> {
|
|
2
|
+
fulfilled?: (value: V) => V | Promise<V>;
|
|
3
|
+
rejected?: (error: any) => any;
|
|
4
|
+
}
|
|
5
|
+
/** Interceptors run in the order they were added, each one on the result of the previous one. */
|
|
6
|
+
export declare class InterceptorManager<V> {
|
|
7
|
+
protected readonly handlers: Map<number, Interceptor<V>>;
|
|
8
|
+
protected nextId: number;
|
|
9
|
+
/** Returns the id to `eject` the interceptor with. */
|
|
10
|
+
use(fulfilled?: Interceptor<V>['fulfilled'], rejected?: Interceptor<V>['rejected']): number;
|
|
11
|
+
eject(id: number): void;
|
|
12
|
+
clear(): void;
|
|
13
|
+
apply(value: Promise<V>): Promise<V>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Interceptors run in the order they were added, each one on the result of the previous one. */
|
|
2
|
+
export class InterceptorManager {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.handlers = new Map();
|
|
5
|
+
this.nextId = 0;
|
|
6
|
+
}
|
|
7
|
+
/** Returns the id to `eject` the interceptor with. */
|
|
8
|
+
use(fulfilled, rejected) {
|
|
9
|
+
const id = this.nextId++;
|
|
10
|
+
this.handlers.set(id, { fulfilled, rejected });
|
|
11
|
+
return id;
|
|
12
|
+
}
|
|
13
|
+
eject(id) {
|
|
14
|
+
this.handlers.delete(id);
|
|
15
|
+
}
|
|
16
|
+
clear() {
|
|
17
|
+
this.handlers.clear();
|
|
18
|
+
}
|
|
19
|
+
apply(value) {
|
|
20
|
+
let result = value;
|
|
21
|
+
for (const { fulfilled, rejected } of this.handlers.values()) {
|
|
22
|
+
result = result.then(fulfilled, rejected);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=interceptor-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor-manager.js","sourceRoot":"","sources":["../../../src/common/client/interceptor-manager.ts"],"names":[],"mappings":"AAKA,iGAAiG;AACjG,MAAM,OAAO,kBAAkB;IAA/B;QACuB,aAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;QACtD,WAAM,GAAG,CAAC,CAAC;IAwBzB,CAAC;IAtBG,sDAAsD;IACtD,GAAG,CAAC,SAAuC,EAAE,QAAqC;QAC9E,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC/C,OAAO,EAAE,CAAC;IACd,CAAC;IAED,KAAK,CAAC,EAAU;QACZ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAiB;QACnB,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,KAAK,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3D,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AxiosRequestConfig } from 'axios';
|
|
1
|
+
import { RequestConfig, RestOperations, RestOperationsFactory } from './client-protocol.js';
|
|
3
2
|
export declare class DefaultRestOperationsFactory implements RestOperationsFactory {
|
|
4
|
-
protected readonly clientConfig
|
|
3
|
+
protected readonly clientConfig?: RequestConfig;
|
|
5
4
|
create(): RestOperations;
|
|
6
5
|
}
|
|
@@ -7,16 +7,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { RestOperationsFactory } from './client-protocol.js';
|
|
11
|
-
import axios from 'axios';
|
|
12
10
|
import { Component, Value } from '@celljs/core';
|
|
11
|
+
import { RestOperationsFactory } from './client-protocol.js';
|
|
12
|
+
import { DefaultRestOperations } from './default-rest-operations.js';
|
|
13
13
|
let DefaultRestOperationsFactory = class DefaultRestOperationsFactory {
|
|
14
14
|
create() {
|
|
15
|
-
return
|
|
15
|
+
return new DefaultRestOperations(this.clientConfig);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
__decorate([
|
|
19
|
-
Value('
|
|
19
|
+
Value('http.client'),
|
|
20
20
|
__metadata("design:type", Object)
|
|
21
21
|
], DefaultRestOperationsFactory.prototype, "clientConfig", void 0);
|
|
22
22
|
DefaultRestOperationsFactory = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-operations-factory.js","sourceRoot":"","sources":["../../../src/common/client/rest-operations-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"rest-operations-factory.js","sourceRoot":"","sources":["../../../src/common/client/rest-operations-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAiC,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAG3D,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAKrC,MAAM;QACF,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxD,CAAC;CAEJ,CAAA;AANsB;IADlB,KAAK,CAAC,aAAa,CAAC;;kEAC2B;AAHvC,4BAA4B;IADxC,SAAS,CAAC,qBAAqB,CAAC;GACpB,4BAA4B,CASxC"}
|