@onekeyfe/react-native-sni-connect 1.0.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/LICENSE +20 -0
- package/README.md +37 -0
- package/SniConnect.podspec +36 -0
- package/android/build.gradle +89 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/sniconnect/SniConnectModule.kt +346 -0
- package/android/src/main/java/com/sniconnect/SniConnectPackage.kt +31 -0
- package/ios/SniConnect-Bridging-Header.h +13 -0
- package/ios/SniConnect.mm +141 -0
- package/ios/SniConnect.swift +185 -0
- package/ios/SniConnectClient.swift +490 -0
- package/lib/module/@types/react-native-codegen.d.js +2 -0
- package/lib/module/@types/react-native-codegen.d.js.map +1 -0
- package/lib/module/NativeSniConnect.js +17 -0
- package/lib/module/NativeSniConnect.js.map +1 -0
- package/lib/module/index.js +31 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeSniConnect.d.ts +50 -0
- package/lib/typescript/src/NativeSniConnect.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +19 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +167 -0
- package/src/@types/react-native-codegen.d.ts +8 -0
- package/src/NativeSniConnect.ts +70 -0
- package/src/index.tsx +46 -0
package/package.json
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onekeyfe/react-native-sni-connect",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A React Native library for SNI-based HTTP requests with DNS caching and request management",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace react-native-sni-connect-example",
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"typecheck": "tsc",
|
|
38
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
39
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
40
|
+
"prepare": "bob build",
|
|
41
|
+
"update-version": "release-it --ci --no-npm.publish --no-github.release --no-git.commit --no-git.tag --no-git.push",
|
|
42
|
+
"update-version:patch": "release-it patch --ci --no-npm.publish --no-github.release --no-git.commit --no-git.tag --no-git.push",
|
|
43
|
+
"update-version:minor": "release-it minor --ci --no-npm.publish --no-github.release --no-git.commit --no-git.tag --no-git.push",
|
|
44
|
+
"update-version:major": "release-it major --ci --no-npm.publish --no-github.release --no-git.commit --no-git.tag --no-git.push",
|
|
45
|
+
"release": "release-it --only-version",
|
|
46
|
+
"prepack": "yarn clean && yarn prepare",
|
|
47
|
+
"prepublish": "yarn typecheck && yarn lint"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"react-native",
|
|
51
|
+
"ios",
|
|
52
|
+
"android"
|
|
53
|
+
],
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/OneKeyHQ/react-native-sni-connect.git"
|
|
57
|
+
},
|
|
58
|
+
"author": "OneKey <hi@onekey.so> (https://github.com/OneKeyHQ)",
|
|
59
|
+
"license": "MIT",
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/OneKeyHQ/react-native-sni-connect/issues"
|
|
62
|
+
},
|
|
63
|
+
"homepage": "https://github.com/OneKeyHQ/react-native-sni-connect#readme",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"registry": "https://registry.npmjs.org/"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
69
|
+
"@evilmartians/lefthook": "^1.12.3",
|
|
70
|
+
"@react-native-community/cli": "20.0.1",
|
|
71
|
+
"@react-native/babel-preset": "0.81.1",
|
|
72
|
+
"@react-native/eslint-config": "^0.81.1",
|
|
73
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
74
|
+
"@types/jest": "^29.5.14",
|
|
75
|
+
"@types/react": "^19.1.0",
|
|
76
|
+
"commitlint": "^19.8.1",
|
|
77
|
+
"del-cli": "^6.0.0",
|
|
78
|
+
"eslint": "^8.57.0",
|
|
79
|
+
"eslint-config-prettier": "^10.1.8",
|
|
80
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
81
|
+
"jest": "^29.7.0",
|
|
82
|
+
"prettier": "^3.6.2",
|
|
83
|
+
"react": "19.1.0",
|
|
84
|
+
"react-native": "0.81.1",
|
|
85
|
+
"react-native-builder-bob": "^0.40.13",
|
|
86
|
+
"release-it": "^19.0.4",
|
|
87
|
+
"turbo": "^2.5.6",
|
|
88
|
+
"typescript": "^5.9.2"
|
|
89
|
+
},
|
|
90
|
+
"peerDependencies": {
|
|
91
|
+
"react": "*",
|
|
92
|
+
"react-native": "*"
|
|
93
|
+
},
|
|
94
|
+
"workspaces": [
|
|
95
|
+
"example"
|
|
96
|
+
],
|
|
97
|
+
"packageManager": "yarn@3.6.1",
|
|
98
|
+
"jest": {
|
|
99
|
+
"preset": "react-native",
|
|
100
|
+
"modulePathIgnorePatterns": [
|
|
101
|
+
"<rootDir>/example/node_modules",
|
|
102
|
+
"<rootDir>/lib/"
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"commitlint": {
|
|
106
|
+
"extends": [
|
|
107
|
+
"@commitlint/config-conventional"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"release-it": {
|
|
111
|
+
"git": {
|
|
112
|
+
"commitMessage": "chore: release ${version}",
|
|
113
|
+
"tagName": "v${version}"
|
|
114
|
+
},
|
|
115
|
+
"npm": {
|
|
116
|
+
"publish": true
|
|
117
|
+
},
|
|
118
|
+
"github": {
|
|
119
|
+
"release": true
|
|
120
|
+
},
|
|
121
|
+
"plugins": {
|
|
122
|
+
"@release-it/conventional-changelog": {
|
|
123
|
+
"preset": {
|
|
124
|
+
"name": "angular"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"prettier": {
|
|
130
|
+
"quoteProps": "consistent",
|
|
131
|
+
"singleQuote": true,
|
|
132
|
+
"tabWidth": 2,
|
|
133
|
+
"trailingComma": "es5",
|
|
134
|
+
"useTabs": false
|
|
135
|
+
},
|
|
136
|
+
"react-native-builder-bob": {
|
|
137
|
+
"source": "src",
|
|
138
|
+
"output": "lib",
|
|
139
|
+
"targets": [
|
|
140
|
+
[
|
|
141
|
+
"module",
|
|
142
|
+
{
|
|
143
|
+
"esm": true
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
"typescript",
|
|
148
|
+
{
|
|
149
|
+
"project": "tsconfig.build.json"
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
"codegenConfig": {
|
|
155
|
+
"name": "SniConnectSpec",
|
|
156
|
+
"type": "modules",
|
|
157
|
+
"jsSrcsDir": "src",
|
|
158
|
+
"android": {
|
|
159
|
+
"javaPackageName": "com.sniconnect"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"create-react-native-library": {
|
|
163
|
+
"languages": "kotlin-objc",
|
|
164
|
+
"type": "turbo-module",
|
|
165
|
+
"version": "0.54.8"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare module 'react-native/Libraries/Types/CodegenTypes' {
|
|
2
|
+
export type Int32 = number;
|
|
3
|
+
export type Double = number;
|
|
4
|
+
export type Float = number;
|
|
5
|
+
export type UnsafeObject = Record<string, unknown>;
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
export type WithDefault<Type, Value> = Type;
|
|
8
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
Platform,
|
|
4
|
+
TurboModuleRegistry,
|
|
5
|
+
type TurboModule,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import type { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
8
|
+
|
|
9
|
+
type HeaderMap = {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type SniConnectRequest = {
|
|
14
|
+
requestId?: string;
|
|
15
|
+
ip: string;
|
|
16
|
+
hostname: string;
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
headers: HeaderMap;
|
|
20
|
+
body?: string | null;
|
|
21
|
+
timeout: Double;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type SniConnectResponse = {
|
|
25
|
+
data: string;
|
|
26
|
+
status: Int32;
|
|
27
|
+
statusText: string;
|
|
28
|
+
headers: HeaderMap;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export interface Spec extends TurboModule {
|
|
32
|
+
request(config: SniConnectRequest): Promise<SniConnectResponse>;
|
|
33
|
+
cancelRequest(requestId: string): Promise<{ success: boolean }>;
|
|
34
|
+
cancelAllRequests(): Promise<{ success: boolean }>;
|
|
35
|
+
clearDNSCache(): Promise<{ success: boolean }>;
|
|
36
|
+
|
|
37
|
+
// Event emitter methods required for NativeEventEmitter
|
|
38
|
+
addListener(eventType: string): void;
|
|
39
|
+
removeListeners(count: Int32): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const LINKING_ERROR =
|
|
43
|
+
`The package '@onekeyfe/react-native-sni-connect' doesn't seem to be linked. Make sure:\n\n` +
|
|
44
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
45
|
+
'- You rebuilt the app after installing the package\n' +
|
|
46
|
+
'- You are not using Expo Go; create a custom dev client instead\n';
|
|
47
|
+
|
|
48
|
+
export type SniConnectModule = Spec & {
|
|
49
|
+
request(config: SniConnectRequest): Promise<SniConnectResponse>;
|
|
50
|
+
cancelRequest(requestId: string): Promise<{ success: boolean }>;
|
|
51
|
+
cancelAllRequests(): Promise<{ success: boolean }>;
|
|
52
|
+
clearDNSCache(): Promise<{ success: boolean }>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const turboModuleResult = TurboModuleRegistry.get<Spec>('SniConnect');
|
|
56
|
+
|
|
57
|
+
const turboModule: Spec | null = turboModuleResult ?? null;
|
|
58
|
+
|
|
59
|
+
const bridgeModule: Spec | null =
|
|
60
|
+
(NativeModules.SniConnect as Spec | undefined) ?? null;
|
|
61
|
+
|
|
62
|
+
const nativeModule = (turboModule ?? bridgeModule) as SniConnectModule | null;
|
|
63
|
+
|
|
64
|
+
if (nativeModule == null) {
|
|
65
|
+
throw new Error(LINKING_ERROR);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const NativeSniConnect: SniConnectModule = nativeModule;
|
|
69
|
+
|
|
70
|
+
export default NativeSniConnect;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NativeEventEmitter } from 'react-native';
|
|
2
|
+
import NativeSniConnect, {
|
|
3
|
+
type SniConnectRequest,
|
|
4
|
+
type SniConnectResponse,
|
|
5
|
+
} from './NativeSniConnect';
|
|
6
|
+
|
|
7
|
+
// Log entry type definition
|
|
8
|
+
export type LogEntry = {
|
|
9
|
+
level: string;
|
|
10
|
+
message: string;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Create event emitter instance
|
|
15
|
+
const eventEmitter = new NativeEventEmitter(NativeSniConnect as any);
|
|
16
|
+
|
|
17
|
+
// Simple log subscription function
|
|
18
|
+
export function subscribeToLogs(callback: (log: LogEntry) => void): () => void {
|
|
19
|
+
const subscription = eventEmitter.addListener('SniConnectLog', (log: any) => {
|
|
20
|
+
// Type assertion since we know the structure
|
|
21
|
+
callback(log as LogEntry);
|
|
22
|
+
});
|
|
23
|
+
return () => subscription.remove();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function request(
|
|
27
|
+
config: SniConnectRequest
|
|
28
|
+
): Promise<SniConnectResponse> {
|
|
29
|
+
return NativeSniConnect.request(config);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function cancelRequest(
|
|
33
|
+
requestId: string
|
|
34
|
+
): Promise<{ success: boolean }> {
|
|
35
|
+
return NativeSniConnect.cancelRequest(requestId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function cancelAllRequests(): Promise<{ success: boolean }> {
|
|
39
|
+
return NativeSniConnect.cancelAllRequests();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function clearDNSCache(): Promise<{ success: boolean }> {
|
|
43
|
+
return NativeSniConnect.clearDNSCache();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type { SniConnectRequest, SniConnectResponse } from './NativeSniConnect';
|