@onekeyfe/react-native-sni-connect 6.8.0-15 → 6.8.0-16
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 +82 -27
- package/android/src/main/java/com/sniconnect/SniConnectModule.kt +42 -3
- package/android/src/main/java/com/sniconnect/SniPinnedTransport.kt +3 -0
- package/android/src/test/java/com/sniconnect/SniConnectValidationTest.kt +15 -0
- package/ios/SniConnect.mm +15 -0
- package/ios/SniConnect.swift +28 -2
- package/ios/SniConnectClient.swift +37 -2
- package/ios/SniConnectCore.swift +24 -0
- package/ios/Tests/SniConnectValidationTests/SniConnectValidationTests.swift +11 -0
- package/lib/commonjs/@types/react-native-codegen.d.js +2 -0
- package/lib/commonjs/NativeSniConnect.js +26 -0
- package/lib/commonjs/index.js +49 -0
- package/lib/commonjs/node/index.js +1395 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/node/index.js +1372 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/{src → commonjs/src}/NativeSniConnect.d.ts +5 -0
- package/lib/typescript/{src → commonjs/src}/index.d.ts +3 -2
- package/lib/typescript/commonjs/src/node/index.d.ts +186 -0
- package/lib/typescript/module/src/NativeSniConnect.d.ts +91 -0
- package/lib/typescript/module/src/index.d.ts +18 -0
- package/lib/typescript/module/src/node/index.d.ts +186 -0
- package/package.json +31 -5
- package/src/NativeSniConnect.ts +8 -0
- package/src/index.tsx +8 -0
- package/src/node/index.ts +2059 -0
- /package/lib/typescript/{package.json → module/package.json} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -53,6 +53,10 @@ export type SniConnectResponse = {
|
|
|
53
53
|
headers: HeaderMap;
|
|
54
54
|
multiValueHeaders?: MultiValueHeaderMap;
|
|
55
55
|
};
|
|
56
|
+
export type SniConnectUploadProgress = {
|
|
57
|
+
bytesSent: Double;
|
|
58
|
+
totalBytes: Double;
|
|
59
|
+
};
|
|
56
60
|
export type SniConnectDebugTarget = {
|
|
57
61
|
ip: string;
|
|
58
62
|
hostname: string;
|
|
@@ -68,6 +72,7 @@ export type SniConnectDebugSnapshot = {
|
|
|
68
72
|
export interface Spec extends TurboModule {
|
|
69
73
|
request(config: NativeSniConnectRequest): Promise<SniConnectResponse>;
|
|
70
74
|
uploadFile(config: NativeSniConnectUploadFileRequest): Promise<SniConnectResponse>;
|
|
75
|
+
getUploadProgress(requestId: string): Promise<SniConnectUploadProgress | null>;
|
|
71
76
|
cancelRequest(requestId: string): Promise<{
|
|
72
77
|
success: boolean;
|
|
73
78
|
}>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type SniConnectDebugSnapshot, type SniConnectDebugTarget, type SniConnectRequest, type SniConnectResponse, type SniConnectUploadFileRequest } from './NativeSniConnect';
|
|
1
|
+
import { type SniConnectDebugSnapshot, type SniConnectDebugTarget, type SniConnectRequest, type SniConnectResponse, type SniConnectUploadFileRequest, type SniConnectUploadProgress } from './NativeSniConnect';
|
|
2
2
|
export declare function request(config: SniConnectRequest): Promise<SniConnectResponse>;
|
|
3
3
|
export declare function isUploadFileSupported(): boolean;
|
|
4
4
|
export declare function uploadFile(config: SniConnectUploadFileRequest): Promise<SniConnectResponse>;
|
|
5
|
+
export declare function getUploadProgress(requestId: string): Promise<SniConnectUploadProgress | null>;
|
|
5
6
|
export declare function cancelRequest(requestId: string): Promise<{
|
|
6
7
|
success: boolean;
|
|
7
8
|
}>;
|
|
@@ -13,5 +14,5 @@ export declare function clearDNSCache(): Promise<{
|
|
|
13
14
|
}>;
|
|
14
15
|
export declare function getDebugSnapshot(target: SniConnectDebugTarget): Promise<SniConnectDebugSnapshot>;
|
|
15
16
|
export declare function isProxyActiveForUrl(url: string): Promise<boolean>;
|
|
16
|
-
export type { SniConnectBodylessMethod, SniConnectDebugSnapshot, SniConnectDebugTarget, SniConnectMethod, SniConnectOptionalBodyMethod, SniConnectRequest, SniConnectRequiredBodyMethod, SniConnectResponse, SniConnectUploadFileMethod, SniConnectUploadFileRequest, } from './NativeSniConnect';
|
|
17
|
+
export type { SniConnectBodylessMethod, SniConnectDebugSnapshot, SniConnectDebugTarget, SniConnectMethod, SniConnectOptionalBodyMethod, SniConnectRequest, SniConnectRequiredBodyMethod, SniConnectResponse, SniConnectUploadFileMethod, SniConnectUploadFileRequest, SniConnectUploadProgress, } from './NativeSniConnect';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { ClientRequest } from 'http';
|
|
2
|
+
import https, { type RequestOptions } from 'https';
|
|
3
|
+
export declare const DEFAULT_LOGGER_UPLOAD_PATH = "/wallet/v1/client/log";
|
|
4
|
+
export declare const DEFAULT_LOGGER_UPLOAD_ORIGINS: Set<string>;
|
|
5
|
+
export interface SniNodeRequestConfig {
|
|
6
|
+
requestId?: string;
|
|
7
|
+
ip: string;
|
|
8
|
+
hostname: string;
|
|
9
|
+
path: string;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
method: string;
|
|
12
|
+
body: string | null;
|
|
13
|
+
timeout: number;
|
|
14
|
+
port?: number | null;
|
|
15
|
+
}
|
|
16
|
+
export interface SniNodeUploadFileConfig {
|
|
17
|
+
requestId?: string;
|
|
18
|
+
ip: string;
|
|
19
|
+
hostname: string;
|
|
20
|
+
path: string;
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
method: 'POST' | 'PUT';
|
|
23
|
+
filePath: string;
|
|
24
|
+
timeout: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SniNodeResponse {
|
|
27
|
+
data: string;
|
|
28
|
+
status: number;
|
|
29
|
+
statusText: string;
|
|
30
|
+
statusCode: number;
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
multiValueHeaders?: Record<string, string[]>;
|
|
33
|
+
body: string;
|
|
34
|
+
}
|
|
35
|
+
export interface SniNodeDebugSnapshot {
|
|
36
|
+
activeRequests: number;
|
|
37
|
+
activeRequestsForPair: number;
|
|
38
|
+
pendingRequests: number;
|
|
39
|
+
pendingRequestsForPair: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SniNodeLogSink {
|
|
42
|
+
info?: (message: string) => void;
|
|
43
|
+
warn?: (message: string) => void;
|
|
44
|
+
error?: (message: string) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface SniNodeUploadProgress {
|
|
47
|
+
bytesSent: number;
|
|
48
|
+
totalBytes: number;
|
|
49
|
+
}
|
|
50
|
+
export interface SniNodeUploadProgressEvent extends SniNodeUploadProgress {
|
|
51
|
+
requestId: string;
|
|
52
|
+
progressPercent: number;
|
|
53
|
+
}
|
|
54
|
+
export interface SniNodeUploadValidationOptions {
|
|
55
|
+
allowedUploadOrigins?: ReadonlySet<string> | readonly string[];
|
|
56
|
+
allowedUploadPath?: string | null;
|
|
57
|
+
requiredFileExtension?: string | null;
|
|
58
|
+
requireDirectChildOfRoot?: boolean;
|
|
59
|
+
getAllowedUploadRoots?: () => Promise<readonly string[]> | readonly string[];
|
|
60
|
+
verifyUploadFile?: (realPath: string, sizeBytes: number) => Promise<boolean> | boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface SniNodeClientOptions extends SniNodeUploadValidationOptions {
|
|
63
|
+
logger?: SniNodeLogSink;
|
|
64
|
+
logPrefix?: string;
|
|
65
|
+
resolveProxy?: (url: string) => Promise<string>;
|
|
66
|
+
onUploadProgress?: (event: SniNodeUploadProgressEvent) => void;
|
|
67
|
+
}
|
|
68
|
+
export type NormalizedSniRequestConfig = Omit<SniNodeRequestConfig, 'body' | 'headers' | 'method' | 'path' | 'port'> & {
|
|
69
|
+
body: string | null;
|
|
70
|
+
bodyFile?: {
|
|
71
|
+
filePath: string;
|
|
72
|
+
sizeBytes: number;
|
|
73
|
+
};
|
|
74
|
+
headers: Record<string, string>;
|
|
75
|
+
method: string;
|
|
76
|
+
path: string;
|
|
77
|
+
};
|
|
78
|
+
export type SniAgentState = {
|
|
79
|
+
agent: https.Agent;
|
|
80
|
+
activeRequests: Set<ClientRequest>;
|
|
81
|
+
destroyed: boolean;
|
|
82
|
+
};
|
|
83
|
+
declare const SniRequestErrorClass: {
|
|
84
|
+
new (code: string, message: string, failClosed?: boolean): {
|
|
85
|
+
code: string;
|
|
86
|
+
failClosed: boolean;
|
|
87
|
+
name: string;
|
|
88
|
+
message: string;
|
|
89
|
+
stack?: string;
|
|
90
|
+
cause?: unknown;
|
|
91
|
+
};
|
|
92
|
+
isError(error: unknown): error is Error;
|
|
93
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
94
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
95
|
+
stackTraceLimit: number;
|
|
96
|
+
};
|
|
97
|
+
export declare const SniRequestError: {
|
|
98
|
+
new (code: string, message: string, failClosed?: boolean): {
|
|
99
|
+
code: string;
|
|
100
|
+
failClosed: boolean;
|
|
101
|
+
name: string;
|
|
102
|
+
message: string;
|
|
103
|
+
stack?: string;
|
|
104
|
+
cause?: unknown;
|
|
105
|
+
};
|
|
106
|
+
isError(error: unknown): error is Error;
|
|
107
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
108
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
109
|
+
stackTraceLimit: number;
|
|
110
|
+
};
|
|
111
|
+
export type SniRequestError = InstanceType<typeof SniRequestErrorClass>;
|
|
112
|
+
export declare function isSniFailClosedError(error: unknown): boolean;
|
|
113
|
+
export declare function redactIpLiterals(value: string): string;
|
|
114
|
+
export declare function sanitizeSniDiagnosticText(value: string, maxLength?: number): string;
|
|
115
|
+
export declare function safeSniLogValue(value: unknown): string;
|
|
116
|
+
export declare function formatNativeLogEvent(event: string, fields: Record<string, unknown>): string;
|
|
117
|
+
export declare function canonicalizeSniDestinationIp(ip: string): string;
|
|
118
|
+
export declare function getProxyRuleType(proxyRules: string): 'direct' | 'proxy' | 'mixed' | 'unknown';
|
|
119
|
+
export declare function classifyTransportError(error: Error, isUpload?: boolean): Error;
|
|
120
|
+
export declare function validateSniUploadFileConfig(config: SniNodeUploadFileConfig, options?: SniNodeUploadValidationOptions, signal?: AbortSignal): Promise<NormalizedSniRequestConfig>;
|
|
121
|
+
export declare function validatePublicIp(ip: string): void;
|
|
122
|
+
export declare function validateSniRequestConfig(config: SniNodeRequestConfig): NormalizedSniRequestConfig;
|
|
123
|
+
export declare function isProxyRouteActive(proxyRules: string): boolean;
|
|
124
|
+
export declare function buildSniRequestOptions(config: NormalizedSniRequestConfig, agent: https.Agent): RequestOptions;
|
|
125
|
+
export declare function headersToMaps(rawHeaders: string[]): {
|
|
126
|
+
headers: Record<string, string>;
|
|
127
|
+
multiValueHeaders: Record<string, string[]>;
|
|
128
|
+
};
|
|
129
|
+
type SniLimiterLog = (level: 'info' | 'warn' | 'error', event: string, fields: Record<string, unknown>) => void;
|
|
130
|
+
export declare class SniRequestLimiter {
|
|
131
|
+
private maxActiveRequests;
|
|
132
|
+
private maxActiveRequestsPerPair;
|
|
133
|
+
private maxPendingRequests;
|
|
134
|
+
private onLog;
|
|
135
|
+
constructor(maxActiveRequests?: number, maxActiveRequestsPerPair?: number, maxPendingRequests?: number, onLog?: SniLimiterLog);
|
|
136
|
+
private activeRequests;
|
|
137
|
+
private activeRequestsByPair;
|
|
138
|
+
private pendingRequests;
|
|
139
|
+
private getKey;
|
|
140
|
+
private hasCapacity;
|
|
141
|
+
private reserveSlot;
|
|
142
|
+
private dispatchPendingRequests;
|
|
143
|
+
private getCancellationError;
|
|
144
|
+
snapshot(hostname?: string, ip?: string): SniNodeDebugSnapshot;
|
|
145
|
+
acquire(hostname: string, ip: string, options?: {
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
onLog?: SniLimiterLog;
|
|
148
|
+
}): Promise<() => void>;
|
|
149
|
+
}
|
|
150
|
+
export declare class SniNodeClient {
|
|
151
|
+
private options;
|
|
152
|
+
private logPrefix;
|
|
153
|
+
private agentState;
|
|
154
|
+
private requestsById;
|
|
155
|
+
private allRequests;
|
|
156
|
+
private allActiveRequests;
|
|
157
|
+
private requestAgentStates;
|
|
158
|
+
private requestLimiter;
|
|
159
|
+
constructor(options?: SniNodeClientOptions);
|
|
160
|
+
getRequestLimiter(): SniRequestLimiter;
|
|
161
|
+
setRequestLimiter(limiter: SniRequestLimiter): void;
|
|
162
|
+
getAgentState(): SniAgentState;
|
|
163
|
+
private writeNativeLog;
|
|
164
|
+
private maybeDestroyIdleAgentState;
|
|
165
|
+
private removeRequestState;
|
|
166
|
+
isProxyActiveForUrl(url: string): Promise<boolean>;
|
|
167
|
+
private logInvalidConfig;
|
|
168
|
+
private createRequestState;
|
|
169
|
+
request(config: SniNodeRequestConfig): Promise<SniNodeResponse>;
|
|
170
|
+
uploadFile(config: SniNodeUploadFileConfig): Promise<SniNodeResponse>;
|
|
171
|
+
getUploadProgress(requestId: string): Promise<SniNodeUploadProgress | null>;
|
|
172
|
+
private execute;
|
|
173
|
+
cancelRequest(requestId: string): Promise<{
|
|
174
|
+
success: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
getDebugSnapshot({ hostname, ip, }: Pick<SniNodeRequestConfig, 'hostname' | 'ip'>): Promise<SniNodeDebugSnapshot>;
|
|
177
|
+
cancelAllRequests(): Promise<{
|
|
178
|
+
success: boolean;
|
|
179
|
+
}>;
|
|
180
|
+
clearDNSCache(): Promise<{
|
|
181
|
+
success: boolean;
|
|
182
|
+
}>;
|
|
183
|
+
isSupported(): Promise<boolean>;
|
|
184
|
+
}
|
|
185
|
+
export default SniNodeClient;
|
|
186
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
import type { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
type HeaderMap = {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
};
|
|
6
|
+
type MultiValueHeaderMap = {
|
|
7
|
+
[key: string]: string[];
|
|
8
|
+
};
|
|
9
|
+
type SniConnectRequestBase = {
|
|
10
|
+
requestId?: string;
|
|
11
|
+
ip: string;
|
|
12
|
+
hostname: string;
|
|
13
|
+
path: string;
|
|
14
|
+
headers: HeaderMap;
|
|
15
|
+
timeout: Double;
|
|
16
|
+
};
|
|
17
|
+
type NativeSniConnectRequest = SniConnectRequestBase & {
|
|
18
|
+
method: string;
|
|
19
|
+
body?: string | null;
|
|
20
|
+
};
|
|
21
|
+
type NativeSniConnectUploadFileRequest = SniConnectRequestBase & {
|
|
22
|
+
method: string;
|
|
23
|
+
filePath: string;
|
|
24
|
+
};
|
|
25
|
+
export type SniConnectUploadFileMethod = 'POST' | 'PUT';
|
|
26
|
+
/**
|
|
27
|
+
* Sends the raw bytes of an app-sandbox file as the request body over the same
|
|
28
|
+
* pinned-IP/SNI transport as `request()`. Set `content-type` in `headers`.
|
|
29
|
+
*/
|
|
30
|
+
export type SniConnectUploadFileRequest = SniConnectRequestBase & {
|
|
31
|
+
method: SniConnectUploadFileMethod;
|
|
32
|
+
/** Absolute path or `file://` URL inside the app sandbox, at most 20 MiB. */
|
|
33
|
+
filePath: string;
|
|
34
|
+
};
|
|
35
|
+
export type SniConnectBodylessMethod = 'GET' | 'HEAD';
|
|
36
|
+
export type SniConnectRequiredBodyMethod = 'POST' | 'PUT' | 'PATCH';
|
|
37
|
+
export type SniConnectOptionalBodyMethod = 'DELETE' | 'OPTIONS';
|
|
38
|
+
export type SniConnectMethod = SniConnectBodylessMethod | SniConnectRequiredBodyMethod | SniConnectOptionalBodyMethod;
|
|
39
|
+
export type SniConnectRequest = (SniConnectRequestBase & {
|
|
40
|
+
method: SniConnectBodylessMethod;
|
|
41
|
+
body?: never;
|
|
42
|
+
}) | (SniConnectRequestBase & {
|
|
43
|
+
method: SniConnectRequiredBodyMethod;
|
|
44
|
+
body: string;
|
|
45
|
+
}) | (SniConnectRequestBase & {
|
|
46
|
+
method: SniConnectOptionalBodyMethod;
|
|
47
|
+
body?: string | null;
|
|
48
|
+
});
|
|
49
|
+
export type SniConnectResponse = {
|
|
50
|
+
data: string;
|
|
51
|
+
status: Int32;
|
|
52
|
+
statusText: string;
|
|
53
|
+
headers: HeaderMap;
|
|
54
|
+
multiValueHeaders?: MultiValueHeaderMap;
|
|
55
|
+
};
|
|
56
|
+
export type SniConnectUploadProgress = {
|
|
57
|
+
bytesSent: Double;
|
|
58
|
+
totalBytes: Double;
|
|
59
|
+
};
|
|
60
|
+
export type SniConnectDebugTarget = {
|
|
61
|
+
ip: string;
|
|
62
|
+
hostname: string;
|
|
63
|
+
};
|
|
64
|
+
export type SniConnectDebugSnapshot = {
|
|
65
|
+
activeRequests: Int32;
|
|
66
|
+
activeRequestsForPair: Int32;
|
|
67
|
+
pendingRequests: Int32;
|
|
68
|
+
pendingRequestsForPair: Int32;
|
|
69
|
+
activeRequestIdsForPair: string[];
|
|
70
|
+
pendingRequestIdsForPair: string[];
|
|
71
|
+
};
|
|
72
|
+
export interface Spec extends TurboModule {
|
|
73
|
+
request(config: NativeSniConnectRequest): Promise<SniConnectResponse>;
|
|
74
|
+
uploadFile(config: NativeSniConnectUploadFileRequest): Promise<SniConnectResponse>;
|
|
75
|
+
getUploadProgress(requestId: string): Promise<SniConnectUploadProgress | null>;
|
|
76
|
+
cancelRequest(requestId: string): Promise<{
|
|
77
|
+
success: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
cancelAllRequests(): Promise<{
|
|
80
|
+
success: boolean;
|
|
81
|
+
}>;
|
|
82
|
+
clearDNSCache(): Promise<{
|
|
83
|
+
success: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
getDebugSnapshot(target: SniConnectDebugTarget): Promise<SniConnectDebugSnapshot>;
|
|
86
|
+
isProxyActiveForUrl(url: string): Promise<boolean>;
|
|
87
|
+
}
|
|
88
|
+
export type SniConnectModule = Spec;
|
|
89
|
+
declare const NativeSniConnect: SniConnectModule;
|
|
90
|
+
export default NativeSniConnect;
|
|
91
|
+
//# sourceMappingURL=NativeSniConnect.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type SniConnectDebugSnapshot, type SniConnectDebugTarget, type SniConnectRequest, type SniConnectResponse, type SniConnectUploadFileRequest, type SniConnectUploadProgress } from './NativeSniConnect';
|
|
2
|
+
export declare function request(config: SniConnectRequest): Promise<SniConnectResponse>;
|
|
3
|
+
export declare function isUploadFileSupported(): boolean;
|
|
4
|
+
export declare function uploadFile(config: SniConnectUploadFileRequest): Promise<SniConnectResponse>;
|
|
5
|
+
export declare function getUploadProgress(requestId: string): Promise<SniConnectUploadProgress | null>;
|
|
6
|
+
export declare function cancelRequest(requestId: string): Promise<{
|
|
7
|
+
success: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function cancelAllRequests(): Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function clearDNSCache(): Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function getDebugSnapshot(target: SniConnectDebugTarget): Promise<SniConnectDebugSnapshot>;
|
|
16
|
+
export declare function isProxyActiveForUrl(url: string): Promise<boolean>;
|
|
17
|
+
export type { SniConnectBodylessMethod, SniConnectDebugSnapshot, SniConnectDebugTarget, SniConnectMethod, SniConnectOptionalBodyMethod, SniConnectRequest, SniConnectRequiredBodyMethod, SniConnectResponse, SniConnectUploadFileMethod, SniConnectUploadFileRequest, SniConnectUploadProgress, } from './NativeSniConnect';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { ClientRequest } from 'http';
|
|
2
|
+
import https, { type RequestOptions } from 'https';
|
|
3
|
+
export declare const DEFAULT_LOGGER_UPLOAD_PATH = "/wallet/v1/client/log";
|
|
4
|
+
export declare const DEFAULT_LOGGER_UPLOAD_ORIGINS: Set<string>;
|
|
5
|
+
export interface SniNodeRequestConfig {
|
|
6
|
+
requestId?: string;
|
|
7
|
+
ip: string;
|
|
8
|
+
hostname: string;
|
|
9
|
+
path: string;
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
method: string;
|
|
12
|
+
body: string | null;
|
|
13
|
+
timeout: number;
|
|
14
|
+
port?: number | null;
|
|
15
|
+
}
|
|
16
|
+
export interface SniNodeUploadFileConfig {
|
|
17
|
+
requestId?: string;
|
|
18
|
+
ip: string;
|
|
19
|
+
hostname: string;
|
|
20
|
+
path: string;
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
method: 'POST' | 'PUT';
|
|
23
|
+
filePath: string;
|
|
24
|
+
timeout: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SniNodeResponse {
|
|
27
|
+
data: string;
|
|
28
|
+
status: number;
|
|
29
|
+
statusText: string;
|
|
30
|
+
statusCode: number;
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
multiValueHeaders?: Record<string, string[]>;
|
|
33
|
+
body: string;
|
|
34
|
+
}
|
|
35
|
+
export interface SniNodeDebugSnapshot {
|
|
36
|
+
activeRequests: number;
|
|
37
|
+
activeRequestsForPair: number;
|
|
38
|
+
pendingRequests: number;
|
|
39
|
+
pendingRequestsForPair: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SniNodeLogSink {
|
|
42
|
+
info?: (message: string) => void;
|
|
43
|
+
warn?: (message: string) => void;
|
|
44
|
+
error?: (message: string) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface SniNodeUploadProgress {
|
|
47
|
+
bytesSent: number;
|
|
48
|
+
totalBytes: number;
|
|
49
|
+
}
|
|
50
|
+
export interface SniNodeUploadProgressEvent extends SniNodeUploadProgress {
|
|
51
|
+
requestId: string;
|
|
52
|
+
progressPercent: number;
|
|
53
|
+
}
|
|
54
|
+
export interface SniNodeUploadValidationOptions {
|
|
55
|
+
allowedUploadOrigins?: ReadonlySet<string> | readonly string[];
|
|
56
|
+
allowedUploadPath?: string | null;
|
|
57
|
+
requiredFileExtension?: string | null;
|
|
58
|
+
requireDirectChildOfRoot?: boolean;
|
|
59
|
+
getAllowedUploadRoots?: () => Promise<readonly string[]> | readonly string[];
|
|
60
|
+
verifyUploadFile?: (realPath: string, sizeBytes: number) => Promise<boolean> | boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface SniNodeClientOptions extends SniNodeUploadValidationOptions {
|
|
63
|
+
logger?: SniNodeLogSink;
|
|
64
|
+
logPrefix?: string;
|
|
65
|
+
resolveProxy?: (url: string) => Promise<string>;
|
|
66
|
+
onUploadProgress?: (event: SniNodeUploadProgressEvent) => void;
|
|
67
|
+
}
|
|
68
|
+
export type NormalizedSniRequestConfig = Omit<SniNodeRequestConfig, 'body' | 'headers' | 'method' | 'path' | 'port'> & {
|
|
69
|
+
body: string | null;
|
|
70
|
+
bodyFile?: {
|
|
71
|
+
filePath: string;
|
|
72
|
+
sizeBytes: number;
|
|
73
|
+
};
|
|
74
|
+
headers: Record<string, string>;
|
|
75
|
+
method: string;
|
|
76
|
+
path: string;
|
|
77
|
+
};
|
|
78
|
+
export type SniAgentState = {
|
|
79
|
+
agent: https.Agent;
|
|
80
|
+
activeRequests: Set<ClientRequest>;
|
|
81
|
+
destroyed: boolean;
|
|
82
|
+
};
|
|
83
|
+
declare const SniRequestErrorClass: {
|
|
84
|
+
new (code: string, message: string, failClosed?: boolean): {
|
|
85
|
+
code: string;
|
|
86
|
+
failClosed: boolean;
|
|
87
|
+
name: string;
|
|
88
|
+
message: string;
|
|
89
|
+
stack?: string;
|
|
90
|
+
cause?: unknown;
|
|
91
|
+
};
|
|
92
|
+
isError(error: unknown): error is Error;
|
|
93
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
94
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
95
|
+
stackTraceLimit: number;
|
|
96
|
+
};
|
|
97
|
+
export declare const SniRequestError: {
|
|
98
|
+
new (code: string, message: string, failClosed?: boolean): {
|
|
99
|
+
code: string;
|
|
100
|
+
failClosed: boolean;
|
|
101
|
+
name: string;
|
|
102
|
+
message: string;
|
|
103
|
+
stack?: string;
|
|
104
|
+
cause?: unknown;
|
|
105
|
+
};
|
|
106
|
+
isError(error: unknown): error is Error;
|
|
107
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
108
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
109
|
+
stackTraceLimit: number;
|
|
110
|
+
};
|
|
111
|
+
export type SniRequestError = InstanceType<typeof SniRequestErrorClass>;
|
|
112
|
+
export declare function isSniFailClosedError(error: unknown): boolean;
|
|
113
|
+
export declare function redactIpLiterals(value: string): string;
|
|
114
|
+
export declare function sanitizeSniDiagnosticText(value: string, maxLength?: number): string;
|
|
115
|
+
export declare function safeSniLogValue(value: unknown): string;
|
|
116
|
+
export declare function formatNativeLogEvent(event: string, fields: Record<string, unknown>): string;
|
|
117
|
+
export declare function canonicalizeSniDestinationIp(ip: string): string;
|
|
118
|
+
export declare function getProxyRuleType(proxyRules: string): 'direct' | 'proxy' | 'mixed' | 'unknown';
|
|
119
|
+
export declare function classifyTransportError(error: Error, isUpload?: boolean): Error;
|
|
120
|
+
export declare function validateSniUploadFileConfig(config: SniNodeUploadFileConfig, options?: SniNodeUploadValidationOptions, signal?: AbortSignal): Promise<NormalizedSniRequestConfig>;
|
|
121
|
+
export declare function validatePublicIp(ip: string): void;
|
|
122
|
+
export declare function validateSniRequestConfig(config: SniNodeRequestConfig): NormalizedSniRequestConfig;
|
|
123
|
+
export declare function isProxyRouteActive(proxyRules: string): boolean;
|
|
124
|
+
export declare function buildSniRequestOptions(config: NormalizedSniRequestConfig, agent: https.Agent): RequestOptions;
|
|
125
|
+
export declare function headersToMaps(rawHeaders: string[]): {
|
|
126
|
+
headers: Record<string, string>;
|
|
127
|
+
multiValueHeaders: Record<string, string[]>;
|
|
128
|
+
};
|
|
129
|
+
type SniLimiterLog = (level: 'info' | 'warn' | 'error', event: string, fields: Record<string, unknown>) => void;
|
|
130
|
+
export declare class SniRequestLimiter {
|
|
131
|
+
private maxActiveRequests;
|
|
132
|
+
private maxActiveRequestsPerPair;
|
|
133
|
+
private maxPendingRequests;
|
|
134
|
+
private onLog;
|
|
135
|
+
constructor(maxActiveRequests?: number, maxActiveRequestsPerPair?: number, maxPendingRequests?: number, onLog?: SniLimiterLog);
|
|
136
|
+
private activeRequests;
|
|
137
|
+
private activeRequestsByPair;
|
|
138
|
+
private pendingRequests;
|
|
139
|
+
private getKey;
|
|
140
|
+
private hasCapacity;
|
|
141
|
+
private reserveSlot;
|
|
142
|
+
private dispatchPendingRequests;
|
|
143
|
+
private getCancellationError;
|
|
144
|
+
snapshot(hostname?: string, ip?: string): SniNodeDebugSnapshot;
|
|
145
|
+
acquire(hostname: string, ip: string, options?: {
|
|
146
|
+
signal?: AbortSignal;
|
|
147
|
+
onLog?: SniLimiterLog;
|
|
148
|
+
}): Promise<() => void>;
|
|
149
|
+
}
|
|
150
|
+
export declare class SniNodeClient {
|
|
151
|
+
private options;
|
|
152
|
+
private logPrefix;
|
|
153
|
+
private agentState;
|
|
154
|
+
private requestsById;
|
|
155
|
+
private allRequests;
|
|
156
|
+
private allActiveRequests;
|
|
157
|
+
private requestAgentStates;
|
|
158
|
+
private requestLimiter;
|
|
159
|
+
constructor(options?: SniNodeClientOptions);
|
|
160
|
+
getRequestLimiter(): SniRequestLimiter;
|
|
161
|
+
setRequestLimiter(limiter: SniRequestLimiter): void;
|
|
162
|
+
getAgentState(): SniAgentState;
|
|
163
|
+
private writeNativeLog;
|
|
164
|
+
private maybeDestroyIdleAgentState;
|
|
165
|
+
private removeRequestState;
|
|
166
|
+
isProxyActiveForUrl(url: string): Promise<boolean>;
|
|
167
|
+
private logInvalidConfig;
|
|
168
|
+
private createRequestState;
|
|
169
|
+
request(config: SniNodeRequestConfig): Promise<SniNodeResponse>;
|
|
170
|
+
uploadFile(config: SniNodeUploadFileConfig): Promise<SniNodeResponse>;
|
|
171
|
+
getUploadProgress(requestId: string): Promise<SniNodeUploadProgress | null>;
|
|
172
|
+
private execute;
|
|
173
|
+
cancelRequest(requestId: string): Promise<{
|
|
174
|
+
success: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
getDebugSnapshot({ hostname, ip, }: Pick<SniNodeRequestConfig, 'hostname' | 'ip'>): Promise<SniNodeDebugSnapshot>;
|
|
177
|
+
cancelAllRequests(): Promise<{
|
|
178
|
+
success: boolean;
|
|
179
|
+
}>;
|
|
180
|
+
clearDNSCache(): Promise<{
|
|
181
|
+
success: boolean;
|
|
182
|
+
}>;
|
|
183
|
+
isSupported(): Promise<boolean>;
|
|
184
|
+
}
|
|
185
|
+
export default SniNodeClient;
|
|
186
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-sni-connect",
|
|
3
|
-
"version": "6.8.0-
|
|
3
|
+
"version": "6.8.0-16",
|
|
4
4
|
"description": "A React Native library for SNI-based HTTP requests with DNS caching and request management",
|
|
5
|
-
"main": "./lib/
|
|
6
|
-
"
|
|
5
|
+
"main": "./lib/commonjs/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
8
|
+
"react-native": "./src/index.tsx",
|
|
9
|
+
"source": "./src/index.tsx",
|
|
7
10
|
"exports": {
|
|
8
11
|
".": {
|
|
9
12
|
"source": "./src/index.tsx",
|
|
10
|
-
"
|
|
11
|
-
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
15
|
+
"default": "./lib/module/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
19
|
+
"default": "./lib/commonjs/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"./node": {
|
|
23
|
+
"source": "./src/node/index.ts",
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./lib/typescript/module/src/node/index.d.ts",
|
|
26
|
+
"default": "./lib/module/node/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./lib/typescript/commonjs/src/node/index.d.ts",
|
|
30
|
+
"default": "./lib/commonjs/node/index.js"
|
|
31
|
+
}
|
|
12
32
|
},
|
|
13
33
|
"./package.json": "./package.json"
|
|
14
34
|
},
|
|
@@ -93,6 +113,12 @@
|
|
|
93
113
|
"source": "src",
|
|
94
114
|
"output": "lib",
|
|
95
115
|
"targets": [
|
|
116
|
+
[
|
|
117
|
+
"commonjs",
|
|
118
|
+
{
|
|
119
|
+
"esm": true
|
|
120
|
+
}
|
|
121
|
+
],
|
|
96
122
|
[
|
|
97
123
|
"module",
|
|
98
124
|
{
|
package/src/NativeSniConnect.ts
CHANGED
|
@@ -75,6 +75,11 @@ export type SniConnectResponse = {
|
|
|
75
75
|
multiValueHeaders?: MultiValueHeaderMap;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
+
export type SniConnectUploadProgress = {
|
|
79
|
+
bytesSent: Double;
|
|
80
|
+
totalBytes: Double;
|
|
81
|
+
};
|
|
82
|
+
|
|
78
83
|
export type SniConnectDebugTarget = {
|
|
79
84
|
ip: string;
|
|
80
85
|
hostname: string;
|
|
@@ -94,6 +99,9 @@ export interface Spec extends TurboModule {
|
|
|
94
99
|
uploadFile(
|
|
95
100
|
config: NativeSniConnectUploadFileRequest
|
|
96
101
|
): Promise<SniConnectResponse>;
|
|
102
|
+
getUploadProgress(
|
|
103
|
+
requestId: string
|
|
104
|
+
): Promise<SniConnectUploadProgress | null>;
|
|
97
105
|
cancelRequest(requestId: string): Promise<{ success: boolean }>;
|
|
98
106
|
cancelAllRequests(): Promise<{ success: boolean }>;
|
|
99
107
|
clearDNSCache(): Promise<{ success: boolean }>;
|
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import NativeSniConnect, {
|
|
|
4
4
|
type SniConnectRequest,
|
|
5
5
|
type SniConnectResponse,
|
|
6
6
|
type SniConnectUploadFileRequest,
|
|
7
|
+
type SniConnectUploadProgress,
|
|
7
8
|
} from './NativeSniConnect';
|
|
8
9
|
|
|
9
10
|
export function request(
|
|
@@ -27,6 +28,12 @@ export async function uploadFile(
|
|
|
27
28
|
return NativeSniConnect.uploadFile(config);
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
export function getUploadProgress(
|
|
32
|
+
requestId: string
|
|
33
|
+
): Promise<SniConnectUploadProgress | null> {
|
|
34
|
+
return NativeSniConnect.getUploadProgress(requestId);
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
export function cancelRequest(
|
|
31
38
|
requestId: string
|
|
32
39
|
): Promise<{ success: boolean }> {
|
|
@@ -62,4 +69,5 @@ export type {
|
|
|
62
69
|
SniConnectResponse,
|
|
63
70
|
SniConnectUploadFileMethod,
|
|
64
71
|
SniConnectUploadFileRequest,
|
|
72
|
+
SniConnectUploadProgress,
|
|
65
73
|
} from './NativeSniConnect';
|