@zcatalyst/transport 0.0.1 → 0.0.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/LICENCE +55 -1
- package/README.md +266 -0
- package/dist-cjs/fetch-handler.js +269 -0
- package/dist-cjs/http-handler.js +404 -0
- package/dist-cjs/index.browser.js +23 -0
- package/dist-cjs/index.js +34 -0
- package/dist-cjs/utils/clonable-stream.js +107 -0
- package/dist-cjs/utils/constants.js +55 -0
- package/dist-cjs/utils/enums.js +22 -0
- package/dist-cjs/utils/errors.js +10 -0
- package/dist-cjs/utils/form-data.js +223 -0
- package/dist-cjs/utils/helpers.js +10 -0
- package/dist-cjs/utils/interfaces.js +2 -0
- package/dist-cjs/utils/request-agent.js +22 -0
- package/dist-cjs/utils/request-timeout.js +14 -0
- package/dist-es/fetch-handler.js +261 -0
- package/dist-es/http-handler.js +362 -0
- package/dist-es/index.browser.js +13 -0
- package/dist-es/index.js +21 -0
- package/dist-es/utils/clonable-stream.js +104 -0
- package/dist-es/utils/constants.js +52 -0
- package/dist-es/utils/enums.js +19 -0
- package/dist-es/utils/errors.js +6 -0
- package/dist-es/utils/form-data.js +218 -0
- package/dist-es/utils/helpers.js +7 -0
- package/dist-es/utils/interfaces.js +1 -0
- package/dist-es/utils/request-agent.js +19 -0
- package/dist-es/utils/request-timeout.js +11 -0
- package/dist-types/fetch-handler.d.ts +149 -0
- package/dist-types/http-handler.d.ts +79 -0
- package/dist-types/index.browser.d.ts +29 -0
- package/dist-types/index.d.ts +36 -0
- package/dist-types/ts3.4/fetch-handler.d.ts +149 -0
- package/dist-types/ts3.4/http-handler.d.ts +79 -0
- package/dist-types/ts3.4/index.browser.d.ts +29 -0
- package/dist-types/ts3.4/index.d.ts +36 -0
- package/dist-types/ts3.4/utils/clonable-stream.d.ts +75 -0
- package/dist-types/ts3.4/utils/constants.d.ts +11 -0
- package/dist-types/ts3.4/utils/enums.d.ts +16 -0
- package/dist-types/ts3.4/utils/errors.d.ts +11 -0
- package/dist-types/ts3.4/utils/form-data.d.ts +285 -0
- package/dist-types/ts3.4/utils/helpers.d.ts +13 -0
- package/dist-types/ts3.4/utils/interfaces.d.ts +68 -0
- package/dist-types/ts3.4/utils/request-agent.d.ts +12 -0
- package/dist-types/ts3.4/utils/request-timeout.d.ts +13 -0
- package/dist-types/utils/clonable-stream.d.ts +75 -0
- package/dist-types/utils/constants.d.ts +11 -0
- package/dist-types/utils/enums.d.ts +16 -0
- package/dist-types/utils/errors.d.ts +11 -0
- package/dist-types/utils/form-data.d.ts +285 -0
- package/dist-types/utils/helpers.d.ts +13 -0
- package/dist-types/utils/interfaces.d.ts +68 -0
- package/dist-types/utils/request-agent.d.ts +12 -0
- package/dist-types/utils/request-timeout.d.ts +13 -0
- package/package.json +37 -7
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { CoreType, IRequestConfig, jwtAccessTokenResponse, RequestHandlerOptions } from './utils/interfaces';
|
|
2
|
+
type ICatalystDataRes = Record<string, string> | string | Blob | ArrayBuffer | ReadableStreamDefaultReader<Uint8Array> | FormData;
|
|
3
|
+
export interface ICatalystClientRes {
|
|
4
|
+
request: RequestInit;
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
headers: HeadersInit;
|
|
7
|
+
data?: ICatalystDataRes;
|
|
8
|
+
buffer?: Buffer;
|
|
9
|
+
blob?: Blob;
|
|
10
|
+
config: RequestHandlerOptions;
|
|
11
|
+
stream?: ArrayBuffer;
|
|
12
|
+
}
|
|
13
|
+
export declare class DefaultHttpResponse {
|
|
14
|
+
statusCode: number;
|
|
15
|
+
headers: HeadersInit;
|
|
16
|
+
config: RequestHandlerOptions;
|
|
17
|
+
resp: ICatalystClientRes;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a DefaultHttpResponse instance.
|
|
20
|
+
* @param resp - The resp value.
|
|
21
|
+
*/
|
|
22
|
+
constructor(resp: ICatalystClientRes);
|
|
23
|
+
/*
|
|
24
|
+
* Returns the data value for this DefaultHttpResponse instance.
|
|
25
|
+
*
|
|
26
|
+
* @returns The response payload.
|
|
27
|
+
* @throws {CatalystAPIError} when the request or response cannot be processed.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
32
|
+
* const result = undefined;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
readonly data: ICatalystDataRes;
|
|
36
|
+
}
|
|
37
|
+
export declare class ResponseHandler {
|
|
38
|
+
private "ResponseHandler.#private";
|
|
39
|
+
static apiDomain: string;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a ResponseHandler instance.
|
|
42
|
+
*/
|
|
43
|
+
constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Sends a browser fetch request with SDK authentication, timeout and response handling.
|
|
46
|
+
*
|
|
47
|
+
* @param options - The initialization or request options.
|
|
48
|
+
* @param options.requestCore - The Fetch API request configuration.
|
|
49
|
+
* @param options.url - The URL to update or request.
|
|
50
|
+
* @param requestOptions - The request handling options.
|
|
51
|
+
* @returns The fire general request result.
|
|
52
|
+
* @throws {CatalystAPIError} when the request or response cannot be processed.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
57
|
+
* const response = await ResponseHandler.fireGeneralRequest({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
static fireGeneralRequest({ requestCore, url }: {
|
|
61
|
+
requestCore: RequestInit;
|
|
62
|
+
url: string;
|
|
63
|
+
}, requestOptions?: RequestHandlerOptions): Promise<DefaultHttpResponse | void>;
|
|
64
|
+
/**
|
|
65
|
+
* Wraps a Fetch API response in the SDK response object.
|
|
66
|
+
*
|
|
67
|
+
* @param response - The response to wrap.
|
|
68
|
+
* @param options - The initialization or request options.
|
|
69
|
+
* @returns The wrap response result.
|
|
70
|
+
* @throws {CatalystAPIError} when the request or response cannot be processed.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
75
|
+
* const response = await ResponseHandler.wrapResponse({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
static wrapResponse(response: Response, options?: RequestHandlerOptions): Promise<DefaultHttpResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Sends a browser fetch request without retry handling.
|
|
81
|
+
*
|
|
82
|
+
* @param requestCore - The Fetch API request configuration.
|
|
83
|
+
* @param reqOptions - The raw request handling options.
|
|
84
|
+
* @returns The fire raw request result.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
89
|
+
* const response = await ResponseHandler.fireRawRequest({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
static fireRawRequest(requestCore: CoreType, reqOptions: RequestHandlerOptions): Promise<DefaultHttpResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Attaches browser authentication headers according to the configured auth protocol.
|
|
95
|
+
*
|
|
96
|
+
* @param headers - The headers object to mutate or extend.
|
|
97
|
+
* @returns The attach zcauth headers result.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
102
|
+
* const response = await ResponseHandler.attachZCAuthHeaders({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
static attachZCAuthHeaders(headers: HeadersInit): Promise<HeadersInit>;
|
|
106
|
+
/**
|
|
107
|
+
* Builds the browser JWT authorization token from the configured cookie.
|
|
108
|
+
*
|
|
109
|
+
* @returns The get jwtzcauth token result.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
114
|
+
* const response = await ResponseHandler.getJWTZCAuthToken({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
static getJWTZCAuthToken(): Promise<jwtAccessTokenResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Appends query parameters to a URL.
|
|
120
|
+
*
|
|
121
|
+
* @param url - The URL to update or request.
|
|
122
|
+
* @param qs - The query string values to append.
|
|
123
|
+
* @returns The URL with encoded query parameters.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
128
|
+
* const response = await ResponseHandler.appendQueryString({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
static appendQueryString(url: string, qs?: Record<string, string | number | boolean | undefined>): string;
|
|
132
|
+
/**
|
|
133
|
+
* Sends a Catalyst HTTP request and returns the wrapped response.
|
|
134
|
+
*
|
|
135
|
+
* @param options - The initialization or request options.
|
|
136
|
+
* @param componentName - The component name for user-agent metadata.
|
|
137
|
+
* @param componentVersion - The component version for user-agent metadata.
|
|
138
|
+
* @returns The send result.
|
|
139
|
+
* @throws {CatalystAPIError} when the request or response cannot be processed.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
144
|
+
* const response = await ResponseHandler.send({ url: '/baas/v1/project/123', method: 'GET', headers: {} });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
static send(options: IRequestConfig, componentName?: string, componentVersion?: string): Promise<DefaultHttpResponse | void>;
|
|
148
|
+
}
|
|
149
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { CatalystApp } from '@zcatalyst/auth-admin';
|
|
2
|
+
import { ClientRequest, IncomingHttpHeaders, IncomingMessage } from 'http';
|
|
3
|
+
import { Component, IRequestConfig } from './utils/interfaces';
|
|
4
|
+
export interface IAPIResponse {
|
|
5
|
+
request: ClientRequest;
|
|
6
|
+
statusCode?: number;
|
|
7
|
+
headers: IncomingHttpHeaders;
|
|
8
|
+
data?: string;
|
|
9
|
+
buffer?: Buffer;
|
|
10
|
+
config: IRequestConfig;
|
|
11
|
+
stream?: IncomingMessage;
|
|
12
|
+
}
|
|
13
|
+
export declare class DefaultHttpResponse {
|
|
14
|
+
statusCode: number;
|
|
15
|
+
headers: IncomingHttpHeaders;
|
|
16
|
+
config: IRequestConfig;
|
|
17
|
+
resp: IAPIResponse;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a DefaultHttpResponse instance.
|
|
20
|
+
* @param resp - The resp value.
|
|
21
|
+
*/
|
|
22
|
+
constructor(resp: IAPIResponse);
|
|
23
|
+
/*
|
|
24
|
+
* Returns the parsed response payload.
|
|
25
|
+
*
|
|
26
|
+
* @returns The data result.
|
|
27
|
+
* @throws {CatalystAPIError} when the operation cannot be completed.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
32
|
+
* // Use DefaultHttpResponse.data while preparing or sending an SDK request.
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
readonly data: any;
|
|
36
|
+
}
|
|
37
|
+
export declare class HttpClient {
|
|
38
|
+
app?: CatalystApp;
|
|
39
|
+
/** * @param app - The app used to fetch access tokens to sign API requests. */
|
|
40
|
+
constructor(app?: CatalystApp);
|
|
41
|
+
/**
|
|
42
|
+
* Sends a Catalyst HTTP request and returns the wrapped response.
|
|
43
|
+
*
|
|
44
|
+
* @param req - The req value.
|
|
45
|
+
* @param apmTrackerName - The apmTrackerName value.
|
|
46
|
+
* @param componentVersion - The componentVersion value.
|
|
47
|
+
* @returns The send result.
|
|
48
|
+
* @throws {CatalystAPIError} when the operation cannot be completed.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
53
|
+
* // Use HttpClient.send while preparing or sending an SDK request.
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
send(req: IRequestConfig, apmTrackerName?: string, componentVersion?: string): Promise<DefaultHttpResponse>;
|
|
57
|
+
}
|
|
58
|
+
export declare class AuthorizedHttpClient extends HttpClient {
|
|
59
|
+
readonly componentName?: string;
|
|
60
|
+
readonly componentVersion?: string;
|
|
61
|
+
/**
|
|
62
|
+
* @param app - The app used to fetch access tokens to sign API requests.
|
|
63
|
+
* @param component - Optional component metadata used to attach version headers.
|
|
64
|
+
*/
|
|
65
|
+
constructor(app?: CatalystApp, component?: Component);
|
|
66
|
+
/**
|
|
67
|
+
* Sends a Catalyst HTTP request and returns the wrapped response.
|
|
68
|
+
*
|
|
69
|
+
* @param request - The request value.
|
|
70
|
+
* @returns The send result.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
75
|
+
* // Use AuthorizedHttpClient.send while preparing or sending an SDK request.
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
send(request: IRequestConfig): Promise<DefaultHttpResponse>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ICatalystClientRes } from './fetch-handler';
|
|
2
|
+
import { Component, IRequestConfig } from './utils/interfaces';
|
|
3
|
+
export { CatalystService, Component, CONSTANTS } from '@zcatalyst/utils';
|
|
4
|
+
export { PrefixedCatalystError } from '@zcatalyst/utils';
|
|
5
|
+
export declare class Handler {
|
|
6
|
+
component?: Component;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Handler instance.
|
|
9
|
+
* @param app - The app value.
|
|
10
|
+
* @param component - The component value.
|
|
11
|
+
*/
|
|
12
|
+
constructor(app?: unknown, component?: Component);
|
|
13
|
+
/**
|
|
14
|
+
* Sends a Catalyst HTTP request and returns the wrapped response.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The initialization or request options.
|
|
17
|
+
* @returns The send result.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
22
|
+
* const result = undefined;
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
send(options: IRequestConfig): Promise<ICatalystClientRes>;
|
|
26
|
+
}
|
|
27
|
+
export { RequestType, ResponseType } from './utils/enums';
|
|
28
|
+
export { CatalystAPIError } from './utils/errors';
|
|
29
|
+
export { IRequestConfig };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal HTTP / fetch transport layer used by every Catalyst component package.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { DefaultHttpResponse } from './http-handler';
|
|
7
|
+
import FormData from './utils/form-data';
|
|
8
|
+
import { Component, IRequestConfig } from './utils/interfaces';
|
|
9
|
+
export { CatalystService, Component, CONSTANTS } from '@zcatalyst/utils';
|
|
10
|
+
export { PrefixedCatalystError } from '@zcatalyst/utils';
|
|
11
|
+
export declare class Handler {
|
|
12
|
+
component?: Component;
|
|
13
|
+
app?: any;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Handler instance.
|
|
16
|
+
* @param app - The app value.
|
|
17
|
+
* @param component - The component value.
|
|
18
|
+
*/
|
|
19
|
+
constructor(app?: unknown, component?: Component);
|
|
20
|
+
/**
|
|
21
|
+
* Sends a Catalyst HTTP request through the Node transport handler.
|
|
22
|
+
*
|
|
23
|
+
* @param options - The request configuration to send.
|
|
24
|
+
* @returns The wrapped HTTP response.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
29
|
+
* const response = await new Handler(app).send({ method: 'GET', url: 'https://example.com' });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
send(options: IRequestConfig): Promise<DefaultHttpResponse>;
|
|
33
|
+
}
|
|
34
|
+
export { RequestType, ResponseType } from './utils/enums';
|
|
35
|
+
export { CatalystAPIError } from './utils/errors';
|
|
36
|
+
export { FormData, IRequestConfig };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { PassThrough, Readable } from 'stream';
|
|
2
|
+
declare class StreamClone extends PassThrough {
|
|
3
|
+
parent: CloneableStream;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a StreamClone instance.
|
|
6
|
+
* @param parent - The parent value.
|
|
7
|
+
*/
|
|
8
|
+
constructor(parent: CloneableStream);
|
|
9
|
+
private onDataClone;
|
|
10
|
+
private onResumeClone;
|
|
11
|
+
/**
|
|
12
|
+
* Performs clone for the transport package.
|
|
13
|
+
*
|
|
14
|
+
* @returns The clone result.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
19
|
+
* const result = undefined;
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
clone(): StreamClone;
|
|
23
|
+
/**
|
|
24
|
+
* Performs is cloneable for the transport package.
|
|
25
|
+
*
|
|
26
|
+
* @param stream - The stream value.
|
|
27
|
+
* @returns The is cloneable result.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
32
|
+
* const result = undefined;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
isCloneable(stream: unknown): stream is CloneableStream | StreamClone;
|
|
36
|
+
}
|
|
37
|
+
export default class CloneableStream extends PassThrough {
|
|
38
|
+
_original: Readable | undefined;
|
|
39
|
+
_clonesCount: number;
|
|
40
|
+
_internalPipe: boolean;
|
|
41
|
+
_hasListener: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a CloneableStream instance.
|
|
44
|
+
* @param stream - The stream value.
|
|
45
|
+
*/
|
|
46
|
+
constructor(stream: Readable);
|
|
47
|
+
private onData;
|
|
48
|
+
private onResume;
|
|
49
|
+
/**
|
|
50
|
+
* Performs resume for the transport package.
|
|
51
|
+
*
|
|
52
|
+
* @returns The resume result.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
57
|
+
* const result = undefined;
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
resume(): this;
|
|
61
|
+
/**
|
|
62
|
+
* Performs clone for the transport package.
|
|
63
|
+
*
|
|
64
|
+
* @returns The clone result.
|
|
65
|
+
* @throws {Error} when validation fails.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
70
|
+
* const result = undefined;
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
clone(): StreamClone;
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTTP_CODE_MAP_TYPE, HTTP_CODE_REV_MAP_TYPE } from './interfaces';
|
|
2
|
+
export declare const HTTP_CODE_MAP: HTTP_CODE_MAP_TYPE;
|
|
3
|
+
export declare const HTTP_HEADER_MAP: {
|
|
4
|
+
CONTENT_JSON: string;
|
|
5
|
+
AUTHORIZATION_KEY: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const REQUEST_PROPERTY: unknown;
|
|
8
|
+
export declare const X_ZCSRF_TOKEN = "X-ZCSRF-TOKEN";
|
|
9
|
+
export declare const ZD_CSRPARAM = "zd_csrparam";
|
|
10
|
+
declare const HTTP_CODE_REV_MAP: HTTP_CODE_REV_MAP_TYPE;
|
|
11
|
+
export { HTTP_CODE_REV_MAP };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const enum ResponseType {
|
|
2
|
+
RAW = "raw",
|
|
3
|
+
JSON = "json",
|
|
4
|
+
STRING = "string",
|
|
5
|
+
BUFFER = "buffer"
|
|
6
|
+
}
|
|
7
|
+
export declare const enum RequestType {
|
|
8
|
+
FILE = "file",
|
|
9
|
+
JSON = "json",
|
|
10
|
+
URL_ENCODED = "url_encoded",
|
|
11
|
+
RAW = "raw"
|
|
12
|
+
}
|
|
13
|
+
export declare const enum FormDataKeys {
|
|
14
|
+
CODE = "code",
|
|
15
|
+
FILE_NAME = "file_name"
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PrefixedCatalystError } from '@zcatalyst/utils';
|
|
2
|
+
export declare class CatalystAPIError extends PrefixedCatalystError {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a CatalystAPIError instance.
|
|
5
|
+
* @param code - The code value.
|
|
6
|
+
* @param message - The message value.
|
|
7
|
+
* @param value - The value value.
|
|
8
|
+
* @param statusCode - The statusCode value.
|
|
9
|
+
*/
|
|
10
|
+
constructor(code: string, message: string, value?: unknown, statusCode?: number);
|
|
11
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { IncomingMessage } from 'http';
|
|
2
|
+
import { PassThrough, Readable, Stream } from 'stream';
|
|
3
|
+
export type formDataType = string | Buffer | Readable | IncomingMessage | PassThrough | Record<string, string>;
|
|
4
|
+
export default class FormData extends Stream {
|
|
5
|
+
writable: boolean;
|
|
6
|
+
readable: boolean;
|
|
7
|
+
released: boolean;
|
|
8
|
+
streams: Array<formDataType>;
|
|
9
|
+
currentStream: undefined | formDataType;
|
|
10
|
+
insideLoop: boolean;
|
|
11
|
+
pendingNext: boolean;
|
|
12
|
+
boundary: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a FormData instance.
|
|
15
|
+
* @param streams - The streams value.
|
|
16
|
+
*/
|
|
17
|
+
constructor(streams?: Array<formDataType>);
|
|
18
|
+
static LINE_BREAK: string;
|
|
19
|
+
static CONTENT_TYPE: string;
|
|
20
|
+
/**
|
|
21
|
+
* Performs is stream for the transport package.
|
|
22
|
+
*
|
|
23
|
+
* @param value - The value to validate.
|
|
24
|
+
* @returns The is stream result.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
29
|
+
* const result = undefined;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
isStream(value: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Performs multi part header for the transport package.
|
|
35
|
+
*
|
|
36
|
+
* @param field - The field value.
|
|
37
|
+
* @param value - The value to validate.
|
|
38
|
+
* @returns The multi part header result.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
43
|
+
* const result = undefined;
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
_multiPartHeader(field: string, value: formDataType): string;
|
|
47
|
+
/**
|
|
48
|
+
* Performs get content disposition for the transport package.
|
|
49
|
+
*
|
|
50
|
+
* @param value - The value to validate.
|
|
51
|
+
* @returns The get content disposition result.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
56
|
+
* const result = undefined;
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
_getContentDisposition(value: unknown): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Performs get content type for the transport package.
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to validate.
|
|
64
|
+
* @returns The get content type result.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
69
|
+
* const result = undefined;
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
_getContentType(value: formDataType): string;
|
|
73
|
+
/**
|
|
74
|
+
* Performs last boundary for the transport package.
|
|
75
|
+
*
|
|
76
|
+
* @returns The last boundary result.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
81
|
+
* const result = undefined;
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
_lastBoundary(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Performs generate boundary for the transport package.
|
|
87
|
+
*
|
|
88
|
+
* @returns The generate boundary result.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
93
|
+
* const result = undefined;
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
_generateBoundary(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Performs error for the transport package.
|
|
99
|
+
*
|
|
100
|
+
* @param err - The err value.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
105
|
+
* const result = undefined;
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
_error(err: Error): void;
|
|
109
|
+
/**
|
|
110
|
+
* Performs handle stream errors for the transport package.
|
|
111
|
+
*
|
|
112
|
+
* @param stream - The stream value.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
117
|
+
* const result = undefined;
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
_handleStreamErrors(stream: Stream): void;
|
|
121
|
+
/**
|
|
122
|
+
* Performs pipe next for the transport package.
|
|
123
|
+
*
|
|
124
|
+
* @param stream - The stream value.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
129
|
+
* const result = undefined;
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
_pipeNext(stream: formDataType): void;
|
|
133
|
+
/**
|
|
134
|
+
* Performs get next for the transport package.
|
|
135
|
+
*
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
140
|
+
* const result = undefined;
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
_getNext(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Performs reset for the transport package.
|
|
146
|
+
*
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
151
|
+
* const result = undefined;
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
_reset(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Performs create clone for the transport package.
|
|
157
|
+
*
|
|
158
|
+
* @returns The create clone result.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
163
|
+
* const result = undefined;
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
createClone(): FormData;
|
|
167
|
+
/**
|
|
168
|
+
* Performs append for the transport package.
|
|
169
|
+
*
|
|
170
|
+
* @param field - The field value.
|
|
171
|
+
* @param value - The value to validate.
|
|
172
|
+
* @returns The append result.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
177
|
+
* const result = undefined;
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
append(field: string, value: unknown): this;
|
|
181
|
+
/**
|
|
182
|
+
* Performs get headers for the transport package.
|
|
183
|
+
*
|
|
184
|
+
* @param userHeaders - The user headers value.
|
|
185
|
+
* @returns The get headers result.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
190
|
+
* const result = undefined;
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
getHeaders(userHeaders: {
|
|
194
|
+
[x: string]: string;
|
|
195
|
+
}): {
|
|
196
|
+
[x: string]: string;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Performs get boundary for the transport package.
|
|
200
|
+
*
|
|
201
|
+
* @returns The get boundary result.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
206
|
+
* const result = undefined;
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
getBoundary(): string;
|
|
210
|
+
/**
|
|
211
|
+
* Performs pipe for the transport package.
|
|
212
|
+
*
|
|
213
|
+
* @param dest - The dest value.
|
|
214
|
+
* @param options - The initialization or request options.
|
|
215
|
+
* @returns The pipe result.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
220
|
+
* const result = undefined;
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
pipe<T extends NodeJS.WritableStream>(dest: T, options?: {
|
|
224
|
+
end?: boolean;
|
|
225
|
+
}): T;
|
|
226
|
+
/**
|
|
227
|
+
* Performs write for the transport package.
|
|
228
|
+
*
|
|
229
|
+
* @param data - The data value.
|
|
230
|
+
* @returns The write result.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
235
|
+
* const result = undefined;
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
write(data: Uint8Array | string): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Performs pause for the transport package.
|
|
241
|
+
*
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
246
|
+
* const result = undefined;
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
pause(): void;
|
|
250
|
+
/**
|
|
251
|
+
* Performs resume for the transport package.
|
|
252
|
+
*
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
257
|
+
* const result = undefined;
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
resume(): void;
|
|
261
|
+
/**
|
|
262
|
+
* Performs end for the transport package.
|
|
263
|
+
*
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
268
|
+
* const result = undefined;
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
end(): void;
|
|
272
|
+
/**
|
|
273
|
+
* Performs destroy for the transport package.
|
|
274
|
+
*
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* import { Handler } from '@zcatalyst/transport';
|
|
279
|
+
* const result = undefined;
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
destroy(): void;
|
|
283
|
+
/** function toString() { [native code] } */
|
|
284
|
+
toString(): string;
|
|
285
|
+
}
|