@zcatalyst/transport 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/fetch-handler.js +266 -0
- package/dist-cjs/http-handler.js +402 -0
- package/dist-cjs/index.browser.js +18 -0
- package/dist-cjs/index.js +32 -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 +217 -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 +361 -0
- package/dist-es/index.browser.js +12 -0
- package/dist-es/index.js +23 -0
- package/dist-es/utils/clonable-stream.js +105 -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 +213 -0
- package/dist-es/utils/helpers.js +7 -0
- package/dist-es/utils/interfaces.js +1 -0
- package/dist-es/utils/request-agent.js +20 -0
- package/dist-es/utils/request-timeout.js +11 -0
- package/dist-types/fetch-handler.d.ts +40 -0
- package/dist-types/http-handler.d.ts +39 -0
- package/dist-types/index.browser.d.ts +13 -0
- package/dist-types/index.d.ts +16 -0
- package/dist-types/ts3.4/fetch-handler.d.ts +40 -0
- package/dist-types/ts3.4/http-handler.d.ts +39 -0
- package/dist-types/ts3.4/index.browser.d.ts +13 -0
- package/dist-types/ts3.4/index.d.ts +16 -0
- package/dist-types/ts3.4/utils/clonable-stream.d.ts +21 -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 +4 -0
- package/dist-types/ts3.4/utils/form-data.d.ts +44 -0
- package/dist-types/ts3.4/utils/helpers.d.ts +1 -0
- package/dist-types/ts3.4/utils/interfaces.d.ts +64 -0
- package/dist-types/ts3.4/utils/request-agent.d.ts +6 -0
- package/dist-types/ts3.4/utils/request-timeout.d.ts +1 -0
- package/dist-types/utils/clonable-stream.d.ts +21 -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 +4 -0
- package/dist-types/utils/form-data.d.ts +44 -0
- package/dist-types/utils/helpers.d.ts +1 -0
- package/dist-types/utils/interfaces.d.ts +64 -0
- package/dist-types/utils/request-agent.d.ts +6 -0
- package/dist-types/utils/request-timeout.d.ts +1 -0
- package/package.json +10 -5
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PassThrough, Readable } from 'stream';
|
|
2
|
+
declare class StreamClone extends PassThrough {
|
|
3
|
+
parent: CloneableStream;
|
|
4
|
+
constructor(parent: CloneableStream);
|
|
5
|
+
private onDataClone;
|
|
6
|
+
private onResumeClone;
|
|
7
|
+
clone(): StreamClone;
|
|
8
|
+
isCloneable(stream: unknown): stream is CloneableStream | StreamClone;
|
|
9
|
+
}
|
|
10
|
+
export default class CloneableStream extends PassThrough {
|
|
11
|
+
_original: Readable | undefined;
|
|
12
|
+
_clonesCount: number;
|
|
13
|
+
_internalPipe: boolean;
|
|
14
|
+
_hasListener: boolean;
|
|
15
|
+
constructor(stream: Readable);
|
|
16
|
+
private onData;
|
|
17
|
+
private onResume;
|
|
18
|
+
resume(): this;
|
|
19
|
+
clone(): StreamClone;
|
|
20
|
+
}
|
|
21
|
+
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,44 @@
|
|
|
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
|
+
constructor(streams?: Array<formDataType>);
|
|
14
|
+
static LINE_BREAK: string;
|
|
15
|
+
static CONTENT_TYPE: string;
|
|
16
|
+
isStream(value: unknown): boolean;
|
|
17
|
+
_multiPartHeader(field: string, value: formDataType): string;
|
|
18
|
+
_getContentDisposition(value: any): string | undefined;
|
|
19
|
+
_getContentType(value: formDataType): string;
|
|
20
|
+
_lastBoundary(): string;
|
|
21
|
+
_generateBoundary(): string;
|
|
22
|
+
_error(err: Error): void;
|
|
23
|
+
_handleStreamErrors(stream: Stream): void;
|
|
24
|
+
_pipeNext(stream: formDataType): void;
|
|
25
|
+
_getNext(): void;
|
|
26
|
+
_reset(): void;
|
|
27
|
+
createClone(): FormData;
|
|
28
|
+
append(field: string, value: unknown): this;
|
|
29
|
+
getHeaders(userHeaders: {
|
|
30
|
+
[x: string]: string;
|
|
31
|
+
}): {
|
|
32
|
+
[x: string]: string;
|
|
33
|
+
};
|
|
34
|
+
getBoundary(): string;
|
|
35
|
+
pipe<T extends NodeJS.WritableStream>(dest: T, options?: {
|
|
36
|
+
end?: boolean;
|
|
37
|
+
}): T;
|
|
38
|
+
write(data: Uint8Array | string): boolean;
|
|
39
|
+
pause(): void;
|
|
40
|
+
resume(): void;
|
|
41
|
+
end(): void;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
toString(): string;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isHttps(url?: string | URL): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { CatalystService } from '@zcatalyst/utils';
|
|
2
|
+
import { RequestType, ResponseType } from './enums';
|
|
3
|
+
export interface Component {
|
|
4
|
+
getComponentName(): string;
|
|
5
|
+
}
|
|
6
|
+
export interface jwtAccessTokenResponse {
|
|
7
|
+
access_token: string;
|
|
8
|
+
}
|
|
9
|
+
export type SimpleType = {
|
|
10
|
+
url: string;
|
|
11
|
+
body: object | string | null;
|
|
12
|
+
};
|
|
13
|
+
export interface FileType {
|
|
14
|
+
url: string;
|
|
15
|
+
body: FormData;
|
|
16
|
+
}
|
|
17
|
+
export interface CoreType {
|
|
18
|
+
url: string;
|
|
19
|
+
body?: BodyInit | string | null;
|
|
20
|
+
method?: string;
|
|
21
|
+
headers: Record<string, string> | HeadersInit;
|
|
22
|
+
}
|
|
23
|
+
export interface RequestHandlerOptions {
|
|
24
|
+
request?: RequestInit;
|
|
25
|
+
retry?: number;
|
|
26
|
+
abortSignal?: AbortSignal;
|
|
27
|
+
requestTimeout?: number;
|
|
28
|
+
expecting?: ResponseType;
|
|
29
|
+
auth?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface HTTP_CODE_MAP_BODY_TYPE {
|
|
32
|
+
CODE: number;
|
|
33
|
+
TEXT: string;
|
|
34
|
+
}
|
|
35
|
+
export interface HTTP_CODE_MAP_TYPE {
|
|
36
|
+
[code: string]: HTTP_CODE_MAP_BODY_TYPE;
|
|
37
|
+
}
|
|
38
|
+
export interface HTTP_CODE_REV_MAP_TYPE {
|
|
39
|
+
[code: number]: HTTP_CODE_MAP_BODY_TYPE;
|
|
40
|
+
}
|
|
41
|
+
export interface FORMDATA {
|
|
42
|
+
code: string;
|
|
43
|
+
name: string;
|
|
44
|
+
}
|
|
45
|
+
export interface IRequestConfig {
|
|
46
|
+
data?: string | Array<{
|
|
47
|
+
[x: string]: unknown;
|
|
48
|
+
}> | Array<string | number> | Record<string, unknown> | ReadableStream | NodeJS.ReadableStream;
|
|
49
|
+
type?: RequestType;
|
|
50
|
+
qs?: Record<string, string | number | boolean | undefined>;
|
|
51
|
+
path?: string;
|
|
52
|
+
origin?: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
method?: string;
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
user?: string;
|
|
57
|
+
service?: CatalystService;
|
|
58
|
+
auth?: boolean;
|
|
59
|
+
track?: boolean;
|
|
60
|
+
external?: boolean;
|
|
61
|
+
abortSignal?: AbortSignal;
|
|
62
|
+
expecting?: ResponseType;
|
|
63
|
+
retry?: boolean;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function requestTimeout(timeoutInMs?: number): Promise<never>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PassThrough, Readable } from 'stream';
|
|
2
|
+
declare class StreamClone extends PassThrough {
|
|
3
|
+
parent: CloneableStream;
|
|
4
|
+
constructor(parent: CloneableStream);
|
|
5
|
+
private onDataClone;
|
|
6
|
+
private onResumeClone;
|
|
7
|
+
clone(): StreamClone;
|
|
8
|
+
isCloneable(stream: unknown): stream is CloneableStream | StreamClone;
|
|
9
|
+
}
|
|
10
|
+
export default class CloneableStream extends PassThrough {
|
|
11
|
+
_original: Readable | undefined;
|
|
12
|
+
_clonesCount: number;
|
|
13
|
+
_internalPipe: boolean;
|
|
14
|
+
_hasListener: boolean;
|
|
15
|
+
constructor(stream: Readable);
|
|
16
|
+
private onData;
|
|
17
|
+
private onResume;
|
|
18
|
+
resume(): this;
|
|
19
|
+
clone(): StreamClone;
|
|
20
|
+
}
|
|
21
|
+
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,44 @@
|
|
|
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
|
+
constructor(streams?: Array<formDataType>);
|
|
14
|
+
static LINE_BREAK: string;
|
|
15
|
+
static CONTENT_TYPE: string;
|
|
16
|
+
isStream(value: unknown): boolean;
|
|
17
|
+
_multiPartHeader(field: string, value: formDataType): string;
|
|
18
|
+
_getContentDisposition(value: any): string | undefined;
|
|
19
|
+
_getContentType(value: formDataType): string;
|
|
20
|
+
_lastBoundary(): string;
|
|
21
|
+
_generateBoundary(): string;
|
|
22
|
+
_error(err: Error): void;
|
|
23
|
+
_handleStreamErrors(stream: Stream): void;
|
|
24
|
+
_pipeNext(stream: formDataType): void;
|
|
25
|
+
_getNext(): void;
|
|
26
|
+
_reset(): void;
|
|
27
|
+
createClone(): FormData;
|
|
28
|
+
append(field: string, value: unknown): this;
|
|
29
|
+
getHeaders(userHeaders: {
|
|
30
|
+
[x: string]: string;
|
|
31
|
+
}): {
|
|
32
|
+
[x: string]: string;
|
|
33
|
+
};
|
|
34
|
+
getBoundary(): string;
|
|
35
|
+
pipe<T extends NodeJS.WritableStream>(dest: T, options?: {
|
|
36
|
+
end?: boolean;
|
|
37
|
+
}): T;
|
|
38
|
+
write(data: Uint8Array | string): boolean;
|
|
39
|
+
pause(): void;
|
|
40
|
+
resume(): void;
|
|
41
|
+
end(): void;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
toString(): string;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isHttps(url?: string | URL): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { CatalystService } from '@zcatalyst/utils';
|
|
2
|
+
import { RequestType, ResponseType } from './enums';
|
|
3
|
+
export interface Component {
|
|
4
|
+
getComponentName(): string;
|
|
5
|
+
}
|
|
6
|
+
export interface jwtAccessTokenResponse {
|
|
7
|
+
access_token: string;
|
|
8
|
+
}
|
|
9
|
+
export type SimpleType = {
|
|
10
|
+
url: string;
|
|
11
|
+
body: object | string | null;
|
|
12
|
+
};
|
|
13
|
+
export interface FileType {
|
|
14
|
+
url: string;
|
|
15
|
+
body: FormData;
|
|
16
|
+
}
|
|
17
|
+
export interface CoreType {
|
|
18
|
+
url: string;
|
|
19
|
+
body?: BodyInit | string | null;
|
|
20
|
+
method?: string;
|
|
21
|
+
headers: Record<string, string> | HeadersInit;
|
|
22
|
+
}
|
|
23
|
+
export interface RequestHandlerOptions {
|
|
24
|
+
request?: RequestInit;
|
|
25
|
+
retry?: number;
|
|
26
|
+
abortSignal?: AbortSignal;
|
|
27
|
+
requestTimeout?: number;
|
|
28
|
+
expecting?: ResponseType;
|
|
29
|
+
auth?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface HTTP_CODE_MAP_BODY_TYPE {
|
|
32
|
+
CODE: number;
|
|
33
|
+
TEXT: string;
|
|
34
|
+
}
|
|
35
|
+
export interface HTTP_CODE_MAP_TYPE {
|
|
36
|
+
[code: string]: HTTP_CODE_MAP_BODY_TYPE;
|
|
37
|
+
}
|
|
38
|
+
export interface HTTP_CODE_REV_MAP_TYPE {
|
|
39
|
+
[code: number]: HTTP_CODE_MAP_BODY_TYPE;
|
|
40
|
+
}
|
|
41
|
+
export interface FORMDATA {
|
|
42
|
+
code: string;
|
|
43
|
+
name: string;
|
|
44
|
+
}
|
|
45
|
+
export interface IRequestConfig {
|
|
46
|
+
data?: string | Array<{
|
|
47
|
+
[x: string]: unknown;
|
|
48
|
+
}> | Array<string | number> | Record<string, unknown> | ReadableStream | NodeJS.ReadableStream;
|
|
49
|
+
type?: RequestType;
|
|
50
|
+
qs?: Record<string, string | number | boolean | undefined>;
|
|
51
|
+
path?: string;
|
|
52
|
+
origin?: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
method?: string;
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
user?: string;
|
|
57
|
+
service?: CatalystService;
|
|
58
|
+
auth?: boolean;
|
|
59
|
+
track?: boolean;
|
|
60
|
+
external?: boolean;
|
|
61
|
+
abortSignal?: AbortSignal;
|
|
62
|
+
expecting?: ResponseType;
|
|
63
|
+
retry?: boolean;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function requestTimeout(timeoutInMs?: number): Promise<never>;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zcatalyst/transport",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"main": "./dist-cjs/index.js",
|
|
5
5
|
"module": "./dist-es/index.js",
|
|
6
6
|
"types": "./dist-types/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@zcatalyst/auth": "^0.0.
|
|
10
|
-
"@zcatalyst/
|
|
11
|
-
"@zcatalyst/
|
|
9
|
+
"@zcatalyst/auth": "^0.0.2",
|
|
10
|
+
"@zcatalyst/auth-client": "^0.0.2",
|
|
11
|
+
"@zcatalyst/utils": "^0.0.2"
|
|
12
12
|
},
|
|
13
13
|
"browser": {
|
|
14
14
|
"./dist-cjs/index.js": "./dist-cjs/index.browser.js",
|
|
@@ -16,11 +16,16 @@
|
|
|
16
16
|
"./dist-types/index.d.ts": "./dist-types/index.browser.d.ts"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">=20"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist-*/**"
|
|
23
23
|
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"transport",
|
|
26
|
+
"zcatalyst",
|
|
27
|
+
"catalyst"
|
|
28
|
+
],
|
|
24
29
|
"scripts": {
|
|
25
30
|
"build": "concurrently 'pnpm:build:cjs' 'pnpm:build:es' 'pnpm:build:types && pnpm build:types:downlevel'",
|
|
26
31
|
"build:cjs": "pnpm tsc -p tsconfig.cjs.json",
|