jiren 1.1.1 → 1.2.0
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 +504 -40
- package/components/cache.ts +181 -0
- package/components/client.ts +610 -75
- package/components/index.ts +12 -2
- package/components/native.ts +21 -0
- package/components/types.ts +129 -4
- package/components/worker.ts +6 -1
- package/lib/libcurl-impersonate.dylib +0 -0
- package/lib/libhttpclient.dylib +0 -0
- package/lib/libidn2.0.dylib +0 -0
- package/lib/libintl.8.dylib +0 -0
- package/lib/libunistring.5.dylib +0 -0
- package/lib/libzstd.1.5.7.dylib +0 -0
- package/package.json +1 -1
- package/types/index.ts +6 -0
package/components/index.ts
CHANGED
|
@@ -5,9 +5,19 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// Main client
|
|
8
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
JirenClient,
|
|
10
|
+
type JirenClientOptions,
|
|
11
|
+
type UrlAccessor,
|
|
12
|
+
} from "./client";
|
|
9
13
|
|
|
10
14
|
// Types
|
|
11
|
-
export type {
|
|
15
|
+
export type {
|
|
16
|
+
JirenHttpConfig,
|
|
17
|
+
ParsedUrl,
|
|
18
|
+
WarmupUrlConfig,
|
|
19
|
+
UrlRequestOptions,
|
|
20
|
+
UrlEndpoint,
|
|
21
|
+
} from "./types";
|
|
12
22
|
|
|
13
23
|
// Remove broken exports
|
package/components/native.ts
CHANGED
|
@@ -29,6 +29,7 @@ export const ffiDef = {
|
|
|
29
29
|
FFIType.cstring,
|
|
30
30
|
FFIType.cstring,
|
|
31
31
|
FFIType.u8,
|
|
32
|
+
FFIType.bool,
|
|
32
33
|
],
|
|
33
34
|
returns: FFIType.ptr,
|
|
34
35
|
},
|
|
@@ -56,10 +57,30 @@ export const ffiDef = {
|
|
|
56
57
|
args: [FFIType.ptr],
|
|
57
58
|
returns: FFIType.u64,
|
|
58
59
|
},
|
|
60
|
+
zclient_response_parse_header_offsets: {
|
|
61
|
+
args: [FFIType.ptr],
|
|
62
|
+
returns: FFIType.ptr,
|
|
63
|
+
},
|
|
64
|
+
zclient_header_offsets_free: {
|
|
65
|
+
args: [FFIType.ptr],
|
|
66
|
+
returns: FFIType.void,
|
|
67
|
+
},
|
|
68
|
+
z_find_header_value: {
|
|
69
|
+
args: [FFIType.ptr, FFIType.u64, FFIType.cstring],
|
|
70
|
+
returns: FFIType.ptr,
|
|
71
|
+
},
|
|
72
|
+
zclient_header_value_free: {
|
|
73
|
+
args: [FFIType.ptr],
|
|
74
|
+
returns: FFIType.void,
|
|
75
|
+
},
|
|
59
76
|
zclient_response_free: {
|
|
60
77
|
args: [FFIType.ptr],
|
|
61
78
|
returns: FFIType.void,
|
|
62
79
|
},
|
|
80
|
+
zclient_set_benchmark_mode: {
|
|
81
|
+
args: [FFIType.ptr, FFIType.bool],
|
|
82
|
+
returns: FFIType.void,
|
|
83
|
+
},
|
|
63
84
|
} as const;
|
|
64
85
|
|
|
65
86
|
export const lib = dlopen(libPath, ffiDef);
|
package/components/types.ts
CHANGED
|
@@ -34,16 +34,44 @@ export interface RequestOptions {
|
|
|
34
34
|
timeout?: number;
|
|
35
35
|
/** Maximum number of redirects to follow */
|
|
36
36
|
maxRedirects?: number;
|
|
37
|
+
/** Automatically parse response body */
|
|
38
|
+
responseType?: "json" | "text" | "arraybuffer" | "blob";
|
|
39
|
+
/** Enable anti-bot protection (using curl-impersonate) */
|
|
40
|
+
antibot?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** HTTP Response Body Wrapper */
|
|
44
|
+
export interface JirenResponseBody<T = any> {
|
|
45
|
+
/** Get response as JSON */
|
|
46
|
+
json: <R = T>() => Promise<R>;
|
|
47
|
+
/** Get response as text */
|
|
48
|
+
text: () => Promise<string>;
|
|
49
|
+
/** Get response as ArrayBuffer */
|
|
50
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
51
|
+
/** Get response as Blob */
|
|
52
|
+
blob: () => Promise<Blob>;
|
|
53
|
+
/** Whether the body has been used */
|
|
54
|
+
bodyUsed: boolean;
|
|
37
55
|
}
|
|
38
56
|
|
|
39
57
|
/** HTTP Response */
|
|
40
|
-
export interface
|
|
58
|
+
export interface JirenResponse<T = any> {
|
|
41
59
|
/** HTTP status code */
|
|
42
60
|
status: number;
|
|
43
|
-
/** Response body
|
|
44
|
-
body:
|
|
61
|
+
/** Response body object */
|
|
62
|
+
body: JirenResponseBody<T>;
|
|
45
63
|
/** Response headers */
|
|
46
|
-
headers
|
|
64
|
+
headers: Record<string, string>;
|
|
65
|
+
/** Whether the request was successful (status 200-299) */
|
|
66
|
+
ok: boolean;
|
|
67
|
+
/** The URL of the response */
|
|
68
|
+
url: string;
|
|
69
|
+
/** The status message corresponding to the status code */
|
|
70
|
+
statusText: string;
|
|
71
|
+
/** Whether the response was redirected */
|
|
72
|
+
redirected: boolean;
|
|
73
|
+
/** The type of the response */
|
|
74
|
+
type: "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
|
|
47
75
|
}
|
|
48
76
|
|
|
49
77
|
/** Configuration for JirenHttpClient */
|
|
@@ -61,3 +89,100 @@ export interface ParsedUrl {
|
|
|
61
89
|
port: number;
|
|
62
90
|
path: string;
|
|
63
91
|
}
|
|
92
|
+
|
|
93
|
+
/** Warmup URL with a key for type-safe access */
|
|
94
|
+
export interface WarmupUrlConfig {
|
|
95
|
+
/** Unique key to access this URL via client.url[key] */
|
|
96
|
+
key: string;
|
|
97
|
+
/** The URL to warmup */
|
|
98
|
+
url: string;
|
|
99
|
+
/** Enable response caching for this URL (default: false) */
|
|
100
|
+
cache?: boolean | CacheConfig;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Cache configuration */
|
|
104
|
+
export interface CacheConfig {
|
|
105
|
+
/** Cache TTL in milliseconds (default: 60000 = 1 minute) */
|
|
106
|
+
ttl?: number;
|
|
107
|
+
/** Maximum cache size (default: 100 entries) */
|
|
108
|
+
maxSize?: number;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Options for URL endpoint requests */
|
|
112
|
+
export interface UrlRequestOptions {
|
|
113
|
+
/** Request headers */
|
|
114
|
+
headers?: Record<string, string>;
|
|
115
|
+
/** Path to append to the base URL */
|
|
116
|
+
path?: string;
|
|
117
|
+
/** Maximum number of redirects to follow */
|
|
118
|
+
maxRedirects?: number;
|
|
119
|
+
/** Automatically parse response body */
|
|
120
|
+
responseType?: "json" | "text" | "arraybuffer" | "blob";
|
|
121
|
+
/** Enable anti-bot protection (using curl-impersonate) */
|
|
122
|
+
antibot?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Interface for a URL endpoint with HTTP method helpers */
|
|
126
|
+
export interface UrlEndpoint {
|
|
127
|
+
/** GET request */
|
|
128
|
+
get<T = any>(options?: UrlRequestOptions): Promise<JirenResponse<T>>;
|
|
129
|
+
get<T = any>(
|
|
130
|
+
options?: UrlRequestOptions & { responseType: "json" }
|
|
131
|
+
): Promise<T>;
|
|
132
|
+
get<T = any>(
|
|
133
|
+
options?: UrlRequestOptions & { responseType: "text" }
|
|
134
|
+
): Promise<string>;
|
|
135
|
+
|
|
136
|
+
/** POST request */
|
|
137
|
+
post<T = any>(
|
|
138
|
+
body?: string | null,
|
|
139
|
+
options?: UrlRequestOptions
|
|
140
|
+
): Promise<JirenResponse<T>>;
|
|
141
|
+
post<T = any>(
|
|
142
|
+
body?: string | null,
|
|
143
|
+
options?: UrlRequestOptions & { responseType: "json" }
|
|
144
|
+
): Promise<T>;
|
|
145
|
+
|
|
146
|
+
/** PUT request */
|
|
147
|
+
put<T = any>(
|
|
148
|
+
body?: string | null,
|
|
149
|
+
options?: UrlRequestOptions
|
|
150
|
+
): Promise<JirenResponse<T>>;
|
|
151
|
+
put<T = any>(
|
|
152
|
+
body?: string | null,
|
|
153
|
+
options?: UrlRequestOptions & { responseType: "json" }
|
|
154
|
+
): Promise<T>;
|
|
155
|
+
|
|
156
|
+
/** PATCH request */
|
|
157
|
+
patch<T = any>(
|
|
158
|
+
body?: string | null,
|
|
159
|
+
options?: UrlRequestOptions
|
|
160
|
+
): Promise<JirenResponse<T>>;
|
|
161
|
+
patch<T = any>(
|
|
162
|
+
body?: string | null,
|
|
163
|
+
options?: UrlRequestOptions & { responseType: "json" }
|
|
164
|
+
): Promise<T>;
|
|
165
|
+
|
|
166
|
+
/** DELETE request */
|
|
167
|
+
delete<T = any>(
|
|
168
|
+
body?: string | null,
|
|
169
|
+
options?: UrlRequestOptions
|
|
170
|
+
): Promise<JirenResponse<T>>;
|
|
171
|
+
delete<T = any>(
|
|
172
|
+
body?: string | null,
|
|
173
|
+
options?: UrlRequestOptions & { responseType: "json" }
|
|
174
|
+
): Promise<T>;
|
|
175
|
+
|
|
176
|
+
/** HEAD request */
|
|
177
|
+
head(options?: UrlRequestOptions): Promise<JirenResponse<any>>;
|
|
178
|
+
|
|
179
|
+
/** OPTIONS request */
|
|
180
|
+
options(options?: UrlRequestOptions): Promise<JirenResponse<any>>;
|
|
181
|
+
|
|
182
|
+
/** Prefetch/refresh cache for this URL */
|
|
183
|
+
prefetch(options?: UrlRequestOptions): Promise<void>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Type helper to extract keys from warmup config array */
|
|
187
|
+
export type ExtractWarmupKeys<T extends readonly WarmupUrlConfig[]> =
|
|
188
|
+
T[number]["key"];
|
package/components/worker.ts
CHANGED
|
@@ -75,12 +75,17 @@ if (parentPort) {
|
|
|
75
75
|
bodyBuffer = Buffer.from(bodyStr + "\0");
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
const maxRedirects = options.maxRedirects ?? 5;
|
|
79
|
+
const antibot = options.antibot ?? false;
|
|
80
|
+
|
|
78
81
|
const respPtr = lib.symbols.zclient_request(
|
|
79
82
|
ptr,
|
|
80
83
|
methodBuffer,
|
|
81
84
|
urlBuffer,
|
|
82
85
|
headersBuffer,
|
|
83
|
-
bodyBuffer
|
|
86
|
+
bodyBuffer,
|
|
87
|
+
maxRedirects,
|
|
88
|
+
antibot
|
|
84
89
|
);
|
|
85
90
|
|
|
86
91
|
// Parse Response
|
|
Binary file
|
package/lib/libhttpclient.dylib
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface RequestOptions {
|
|
|
33
33
|
body?: string | object;
|
|
34
34
|
/** Request timeout in milliseconds */
|
|
35
35
|
timeout?: number;
|
|
36
|
+
/** Maximum number of redirects to follow */
|
|
37
|
+
maxRedirects?: number;
|
|
38
|
+
/** Automatically parse response body */
|
|
39
|
+
responseType?: "json" | "text" | "arraybuffer" | "blob";
|
|
40
|
+
/** Enable anti-bot protection (using curl-impersonate) */
|
|
41
|
+
antibot?: boolean;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
/** HTTP Response */
|