kokorobox-native 0.1.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.
Files changed (4) hide show
  1. package/README.md +12 -0
  2. package/index.d.ts +58 -0
  3. package/index.js +88 -0
  4. package/package.json +61 -0
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # kokorobox-native
2
+
3
+ Native Node.js APIs used by KokoroBox Desktop.
4
+
5
+ The package currently exposes file/icon helpers, rule conversion, Windows elevation and SID
6
+ queries, and Windows Firewall rule management. Platform-specific N-API binaries are selected at
7
+ runtime.
8
+
9
+ This project is derived from
10
+ [`UruhaLushia/sparkle-native`](https://github.com/UruhaLushia/sparkle-native) and remains licensed
11
+ under GPL-3.0-only. KokoroBox maintains its own package and release lifecycle so the bridge can
12
+ evolve with product-specific APIs.
package/index.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export interface FirewallRule {
2
+ name: string;
3
+ applicationPath: string;
4
+ }
5
+
6
+ export interface RuleConvertOptions {
7
+ inputTarget?: "mihomo" | "general" | "egern" | "sing-box";
8
+ inputFormat?:
9
+ | "yaml"
10
+ | "mrs"
11
+ | "text"
12
+ | "json"
13
+ | "srs"
14
+ | "domainset"
15
+ | "ruleset"
16
+ | "ipset";
17
+ inputBehavior?: "auto" | "domain" | "ip" | "classical";
18
+ outputTarget?: "mihomo" | "general" | "egern" | "sing-box";
19
+ outputFormat?:
20
+ | "mrs"
21
+ | "text"
22
+ | "yaml"
23
+ | "json"
24
+ | "srs"
25
+ | "domainset"
26
+ | "ruleset"
27
+ | "ipset";
28
+ outputBehavior?: "auto" | "domain" | "ip" | "classical";
29
+ }
30
+
31
+ export interface RuleOutputInfo {
32
+ behavior?: string;
33
+ format: string;
34
+ count: number;
35
+ }
36
+
37
+ export interface RuleSkippedItem {
38
+ rule: string;
39
+ reason: string;
40
+ }
41
+
42
+ export interface RuleStringResult {
43
+ kind: "rules";
44
+ outputs: Record<string, string>;
45
+ info: Record<string, RuleOutputInfo>;
46
+ skipped: RuleSkippedItem[];
47
+ }
48
+
49
+ export function fileToDataUrl(path: string): string;
50
+ export function fileToStr(
51
+ path: string,
52
+ options?: RuleConvertOptions | null,
53
+ ): RuleStringResult;
54
+ export function getAppName(path: string): string;
55
+ export function getCurrentUserSid(): string;
56
+ export function isRunningAsAdmin(): boolean;
57
+ export function runElevated(command: string, args?: string[]): number;
58
+ export function setupFirewallRules(rules: FirewallRule[]): void;
package/index.js ADDED
@@ -0,0 +1,88 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+
5
+ import { existsSync } from 'node:fs'
6
+ import { join } from "node:path";
7
+ import { createRequire } from "node:module";
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const __dirname = new URL(".", import.meta.url).pathname.replace(
11
+ /^\/([A-Za-z]:)/,
12
+ "$1",
13
+ );
14
+
15
+ const packageName = "kokorobox-native";
16
+ const binaryName = "kokorobox-native";
17
+ const loadErrors = [];
18
+
19
+ function requireLocal(tuple) {
20
+ const filename = join(__dirname, `${binaryName}.${tuple}.node`);
21
+ if (!existsSync(filename)) return null;
22
+ try {
23
+ return require(filename);
24
+ } catch (err) {
25
+ loadErrors.push(err);
26
+ return null;
27
+ }
28
+ }
29
+
30
+ function requirePackage(tuple) {
31
+ try {
32
+ return require(`${packageName}-${tuple}`);
33
+ } catch (err) {
34
+ loadErrors.push(err);
35
+ return null;
36
+ }
37
+ }
38
+
39
+ function requireBinding(tuple) {
40
+ return requireLocal(tuple) || requirePackage(tuple);
41
+ }
42
+
43
+ function requireNative() {
44
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
45
+ try {
46
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
47
+ } catch (err) {
48
+ loadErrors.push(err);
49
+ }
50
+ }
51
+
52
+ if (process.platform === "win32") {
53
+ if (process.arch === "x64") return requireBinding("win32-x64-msvc");
54
+ if (process.arch === "arm64") return requireBinding("win32-arm64-msvc");
55
+ if (process.arch === "ia32") return requireBinding("win32-ia32-msvc");
56
+ } else if (process.platform === "darwin") {
57
+ if (process.arch === "x64") return requireBinding("darwin-x64");
58
+ if (process.arch === "arm64") return requireBinding("darwin-arm64");
59
+ } else if (process.platform === "linux") {
60
+ if (process.arch === "x64") return requireBinding("linux-x64-gnu");
61
+ if (process.arch === "arm64") return requireBinding("linux-arm64-gnu");
62
+ if (process.arch === "loong64") return requireBinding("linux-loong64-gnu");
63
+ }
64
+
65
+ loadErrors.push(
66
+ new Error(
67
+ `Unsupported OS or architecture: ${process.platform} ${process.arch}`,
68
+ ),
69
+ );
70
+ return null;
71
+ }
72
+
73
+ const nativeBinding = requireNative();
74
+
75
+ if (!nativeBinding) {
76
+ const error = new Error("Failed to load kokorobox-native binding");
77
+ error.cause = loadErrors;
78
+ throw error;
79
+ }
80
+
81
+ export default nativeBinding;
82
+ export const fileToDataUrl = nativeBinding.fileToDataUrl;
83
+ export const fileToStr = nativeBinding.fileToStr;
84
+ export const getAppName = nativeBinding.getAppName;
85
+ export const getCurrentUserSid = nativeBinding.getCurrentUserSid;
86
+ export const isRunningAsAdmin = nativeBinding.isRunningAsAdmin;
87
+ export const runElevated = nativeBinding.runElevated;
88
+ export const setupFirewallRules = nativeBinding.setupFirewallRules;
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "kokorobox-native",
3
+ "version": "0.1.0",
4
+ "description": "KokoroBox native bridge",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "packageManager": "pnpm@11.3.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/amamiyakokoro/kokorobox-native.git"
12
+ },
13
+ "homepage": "https://github.com/amamiyakokoro/kokorobox-native",
14
+ "bugs": {
15
+ "url": "https://github.com/amamiyakokoro/kokorobox-native/issues"
16
+ },
17
+ "license": "GPL-3.0-only",
18
+ "files": [
19
+ "index.js",
20
+ "index.d.ts",
21
+ "README.md"
22
+ ],
23
+ "napi": {
24
+ "binaryName": "kokorobox-native",
25
+ "targets": [
26
+ "x86_64-pc-windows-msvc",
27
+ "i686-pc-windows-msvc",
28
+ "aarch64-pc-windows-msvc",
29
+ "x86_64-apple-darwin",
30
+ "aarch64-apple-darwin",
31
+ "x86_64-unknown-linux-gnu",
32
+ "aarch64-unknown-linux-gnu",
33
+ "loongarch64-unknown-linux-gnu"
34
+ ]
35
+ },
36
+ "scripts": {
37
+ "build": "napi build --platform --release --strip --no-js --dts napi.generated.d.ts",
38
+ "build:debug": "napi build --platform --no-js --dts napi.generated.d.ts",
39
+ "create-npm-dirs": "napi create-npm-dirs",
40
+ "artifacts": "napi artifacts"
41
+ },
42
+ "devDependencies": {
43
+ "@napi-rs/cli": "^3.8.6"
44
+ },
45
+ "engines": {
46
+ "node": ">=16"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "optionalDependencies": {
52
+ "kokorobox-native-win32-x64-msvc": "0.1.0",
53
+ "kokorobox-native-win32-ia32-msvc": "0.1.0",
54
+ "kokorobox-native-win32-arm64-msvc": "0.1.0",
55
+ "kokorobox-native-darwin-x64": "0.1.0",
56
+ "kokorobox-native-darwin-arm64": "0.1.0",
57
+ "kokorobox-native-linux-x64-gnu": "0.1.0",
58
+ "kokorobox-native-linux-arm64-gnu": "0.1.0",
59
+ "kokorobox-native-linux-loong64-gnu": "0.1.0"
60
+ }
61
+ }