kokorobox-native 0.16.1 → 0.16.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/README.md +14 -0
- package/diagnostics.js +125 -0
- package/index.d.ts +11 -0
- package/index.js +91 -43
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -29,6 +29,20 @@ const app = await inspectApplication("/Applications/KokoroBox.app");
|
|
|
29
29
|
|
|
30
30
|
Check `getNativeCapabilities()` before using optional platform features.
|
|
31
31
|
|
|
32
|
+
## Diagnostics
|
|
33
|
+
|
|
34
|
+
`drainNativeLogs()` returns English JSON-compatible records with `ts`, `level`,
|
|
35
|
+
`target`, and `msg`. Use one consumer to periodically drain the queue into the
|
|
36
|
+
application's log. It retains at most 500 records; overflow produces a warning.
|
|
37
|
+
`setNativeLogLevel("debug" | "info" | "warn" | "error")` changes recording
|
|
38
|
+
severity (default: `info`). Healthy polling is only recorded at `debug`. Operation failures retain
|
|
39
|
+
their original exceptions and causes; lifecycle successes record the operation
|
|
40
|
+
name without arguments, keys, or signatures.
|
|
41
|
+
|
|
42
|
+
The traffic presenter emits JSON Lines to stderr. The Windows portable updater
|
|
43
|
+
also saves its last run in `%TEMP%/kokorobox-portable-updater.log` because Desktop
|
|
44
|
+
exits before extraction. These sidecars include Unix milliseconds in `timestamp`.
|
|
45
|
+
|
|
32
46
|
## Documentation
|
|
33
47
|
|
|
34
48
|
- [JavaScript API guide](../docs/api.md)
|
package/diagnostics.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Diagnostics belong to the calling application. Do not open a log file or
|
|
2
|
+
// retain operation arguments (which may contain keys or signatures).
|
|
3
|
+
const maxEntries = 500;
|
|
4
|
+
const maxMessageLength = 4096;
|
|
5
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
6
|
+
const lifecycleOperations = new Set([
|
|
7
|
+
"runServiceLifecycleElevated",
|
|
8
|
+
"registerMacosManagedService",
|
|
9
|
+
"unregisterMacosManagedService",
|
|
10
|
+
"reloadMacosManagedService",
|
|
11
|
+
"cleanupLegacyMacosService",
|
|
12
|
+
"stopMacosManagedService",
|
|
13
|
+
"repairManagedFilePermissions",
|
|
14
|
+
"setCorePrivileges",
|
|
15
|
+
"applyMacosApplicationRouting",
|
|
16
|
+
"stopMacosApplicationRouting",
|
|
17
|
+
"setLaunchAtLogin",
|
|
18
|
+
"setUwpLoopbackExemption",
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
function boundedMessage(value) {
|
|
22
|
+
const text = String(value);
|
|
23
|
+
if (text.length <= maxMessageLength) return text;
|
|
24
|
+
let end = maxMessageLength;
|
|
25
|
+
if (/^[\uDC00-\uDFFF]$/.test(text[end])) end--;
|
|
26
|
+
return text.slice(0, end) + "…";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function nativeErrorMessage(error) {
|
|
30
|
+
const parts = [];
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
function visit(value, depth = 0) {
|
|
33
|
+
if (depth > 4 || seen.has(value)) return;
|
|
34
|
+
seen.add(value);
|
|
35
|
+
const message = value instanceof Error ? value.message : String(value);
|
|
36
|
+
if (message && !parts.includes(message))
|
|
37
|
+
parts.push(boundedMessage(message));
|
|
38
|
+
if (value && typeof value === "object" && value.cause != null) {
|
|
39
|
+
if (Array.isArray(value.cause))
|
|
40
|
+
value.cause.slice(0, 4).forEach((item) => visit(item, depth + 1));
|
|
41
|
+
else visit(value.cause, depth + 1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
visit(error);
|
|
45
|
+
return boundedMessage(parts.join(": "));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createNativeDiagnostics() {
|
|
49
|
+
let minimum = "info";
|
|
50
|
+
let entries = [];
|
|
51
|
+
let dropped = 0;
|
|
52
|
+
const record = (level, target, msg) => {
|
|
53
|
+
if (levels.indexOf(level) < levels.indexOf(minimum)) return;
|
|
54
|
+
entries.push({
|
|
55
|
+
ts: new Date().toISOString(),
|
|
56
|
+
level,
|
|
57
|
+
target,
|
|
58
|
+
msg: boundedMessage(msg),
|
|
59
|
+
});
|
|
60
|
+
if (entries.length > maxEntries) {
|
|
61
|
+
entries.shift();
|
|
62
|
+
dropped++;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
setLevel(level) {
|
|
67
|
+
if (!levels.includes(level))
|
|
68
|
+
throw new TypeError(
|
|
69
|
+
"Invalid Native log level: expected debug, info, warn, or error",
|
|
70
|
+
);
|
|
71
|
+
minimum = level;
|
|
72
|
+
},
|
|
73
|
+
drain() {
|
|
74
|
+
const result = entries;
|
|
75
|
+
entries = [];
|
|
76
|
+
if (dropped) {
|
|
77
|
+
result.unshift({
|
|
78
|
+
ts: new Date().toISOString(),
|
|
79
|
+
level: "warn",
|
|
80
|
+
target: "diagnostics",
|
|
81
|
+
msg: `Dropped ${dropped} older Native log entries`,
|
|
82
|
+
});
|
|
83
|
+
dropped = 0;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
},
|
|
87
|
+
wrap(target, operation) {
|
|
88
|
+
if (typeof operation !== "function") return operation;
|
|
89
|
+
const failed = (error) => {
|
|
90
|
+
record("error", target, nativeErrorMessage(error));
|
|
91
|
+
throw error;
|
|
92
|
+
};
|
|
93
|
+
const completed = (value) => {
|
|
94
|
+
if (value && value.state === "error")
|
|
95
|
+
record(
|
|
96
|
+
"error",
|
|
97
|
+
target,
|
|
98
|
+
typeof value.message === "string"
|
|
99
|
+
? value.message
|
|
100
|
+
: "Native operation returned an error status",
|
|
101
|
+
);
|
|
102
|
+
else if (lifecycleOperations.has(target))
|
|
103
|
+
record("info", target, "Native operation completed");
|
|
104
|
+
else record("debug", target, "Native operation completed");
|
|
105
|
+
return value;
|
|
106
|
+
};
|
|
107
|
+
return function (...args) {
|
|
108
|
+
let result;
|
|
109
|
+
try {
|
|
110
|
+
result = Reflect.apply(operation, this, args);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return failed(error);
|
|
113
|
+
}
|
|
114
|
+
if (result && typeof result.then === "function")
|
|
115
|
+
return result.then(completed, failed);
|
|
116
|
+
return completed(result);
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const diagnostics = createNativeDiagnostics();
|
|
123
|
+
export const wrapNativeOperation = diagnostics.wrap;
|
|
124
|
+
export const drainNativeLogs = diagnostics.drain;
|
|
125
|
+
export const setNativeLogLevel = diagnostics.setLevel;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
export interface NativeLogEntry {
|
|
2
|
+
ts: string;
|
|
3
|
+
level: "debug" | "info" | "warn" | "error";
|
|
4
|
+
target: string;
|
|
5
|
+
msg: string;
|
|
6
|
+
}
|
|
7
|
+
/** Drains at most 500 entries and an optional overflow warning; use one consumer. */
|
|
8
|
+
export declare function drainNativeLogs(): NativeLogEntry[];
|
|
9
|
+
/** Controls recording, independently from display language. Defaults to info. */
|
|
10
|
+
export declare function setNativeLogLevel(level: NativeLogEntry["level"]): void;
|
|
11
|
+
|
|
1
12
|
export interface UwpLoopbackApp {
|
|
2
13
|
/** Opaque identifier used only when changing this app's loopback exemption. */
|
|
3
14
|
id: string;
|
package/index.js
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
import { existsSync } from 'node:fs'
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
+
import {
|
|
9
|
+
nativeErrorMessage,
|
|
10
|
+
wrapNativeOperation,
|
|
11
|
+
drainNativeLogs,
|
|
12
|
+
setNativeLogLevel,
|
|
13
|
+
} from "./diagnostics.js";
|
|
14
|
+
export { drainNativeLogs, setNativeLogLevel };
|
|
8
15
|
|
|
9
16
|
const require = createRequire(import.meta.url);
|
|
10
17
|
const __dirname = new URL(".", import.meta.url).pathname.replace(
|
|
@@ -71,7 +78,9 @@ export function getPortableUpdaterPath() {
|
|
|
71
78
|
const packagedPath = join(dirname(packageEntry), filename);
|
|
72
79
|
if (existsSync(packagedPath)) return packagedPath;
|
|
73
80
|
}
|
|
74
|
-
throw new Error(
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Portable updater is missing for ${process.platform} ${process.arch}`,
|
|
83
|
+
);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
function requireNative() {
|
|
@@ -105,49 +114,88 @@ function requireNative() {
|
|
|
105
114
|
const nativeBinding = requireNative();
|
|
106
115
|
|
|
107
116
|
if (!nativeBinding) {
|
|
108
|
-
const
|
|
117
|
+
const detail = nativeErrorMessage({
|
|
118
|
+
cause: loadErrors,
|
|
119
|
+
toString: () => "Failed to load kokorobox-native binding",
|
|
120
|
+
});
|
|
121
|
+
const error = new Error(detail);
|
|
109
122
|
error.cause = loadErrors;
|
|
110
123
|
throw error;
|
|
111
124
|
}
|
|
112
125
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export
|
|
127
|
-
export const
|
|
128
|
-
export const
|
|
129
|
-
export const
|
|
130
|
-
export const
|
|
131
|
-
export const
|
|
132
|
-
|
|
133
|
-
export const
|
|
134
|
-
export const
|
|
135
|
-
|
|
136
|
-
export const
|
|
137
|
-
|
|
138
|
-
export const
|
|
139
|
-
export const
|
|
140
|
-
export const
|
|
141
|
-
export const
|
|
142
|
-
export const
|
|
143
|
-
|
|
144
|
-
export const
|
|
145
|
-
|
|
146
|
-
export const
|
|
147
|
-
|
|
148
|
-
export const
|
|
149
|
-
|
|
150
|
-
export const
|
|
151
|
-
|
|
152
|
-
export const
|
|
153
|
-
|
|
126
|
+
// Preserve native classes and unsupported exports; wrap callable operations
|
|
127
|
+
// for both named imports and the default binding without changing arguments.
|
|
128
|
+
const diagnosticBinding = {};
|
|
129
|
+
for (const [name, descriptor] of Object.entries(
|
|
130
|
+
Object.getOwnPropertyDescriptors(nativeBinding),
|
|
131
|
+
)) {
|
|
132
|
+
if (/^[a-z]/.test(name) && typeof descriptor.value === "function") {
|
|
133
|
+
descriptor.value = wrapNativeOperation(name, descriptor.value);
|
|
134
|
+
}
|
|
135
|
+
Object.defineProperty(diagnosticBinding, name, descriptor);
|
|
136
|
+
}
|
|
137
|
+
diagnosticBinding.drainNativeLogs = drainNativeLogs;
|
|
138
|
+
diagnosticBinding.setNativeLogLevel = setNativeLogLevel;
|
|
139
|
+
export default diagnosticBinding;
|
|
140
|
+
export const fileToDataUrl = diagnosticBinding.fileToDataUrl;
|
|
141
|
+
export const fileToStr = diagnosticBinding.fileToStr;
|
|
142
|
+
export const getAppName = diagnosticBinding.getAppName;
|
|
143
|
+
export const getNativeCapabilities = diagnosticBinding.getNativeCapabilities;
|
|
144
|
+
export const getWindowsServiceStatus =
|
|
145
|
+
diagnosticBinding.getWindowsServiceStatus;
|
|
146
|
+
export const getLinuxServiceStatus = diagnosticBinding.getLinuxServiceStatus;
|
|
147
|
+
export const setTerminalProxyEnvironment =
|
|
148
|
+
diagnosticBinding.setTerminalProxyEnvironment;
|
|
149
|
+
export const clearTerminalProxyEnvironment =
|
|
150
|
+
diagnosticBinding.clearTerminalProxyEnvironment;
|
|
151
|
+
export const findExecutables = diagnosticBinding.findExecutables;
|
|
152
|
+
export const getLaunchAtLogin = diagnosticBinding.getLaunchAtLogin;
|
|
153
|
+
export const setLaunchAtLogin = diagnosticBinding.setLaunchAtLogin;
|
|
154
|
+
export const getNetworkContext = diagnosticBinding.getNetworkContext;
|
|
155
|
+
export const waitForNetworkContextChange =
|
|
156
|
+
diagnosticBinding.waitForNetworkContextChange;
|
|
157
|
+
export const getMacosManagedServiceStatus =
|
|
158
|
+
diagnosticBinding.getMacosManagedServiceStatus;
|
|
159
|
+
export const getMacosServiceProcessStatus =
|
|
160
|
+
diagnosticBinding.getMacosServiceProcessStatus;
|
|
161
|
+
export const registerMacosManagedService =
|
|
162
|
+
diagnosticBinding.registerMacosManagedService;
|
|
163
|
+
export const unregisterMacosManagedService =
|
|
164
|
+
diagnosticBinding.unregisterMacosManagedService;
|
|
165
|
+
export const reloadMacosManagedService =
|
|
166
|
+
diagnosticBinding.reloadMacosManagedService;
|
|
167
|
+
export const openMacosLoginItemsSettings =
|
|
168
|
+
diagnosticBinding.openMacosLoginItemsSettings;
|
|
169
|
+
export const applyMacosApplicationRouting =
|
|
170
|
+
diagnosticBinding.applyMacosApplicationRouting;
|
|
171
|
+
export const getMacosApplicationRoutingStatus =
|
|
172
|
+
diagnosticBinding.getMacosApplicationRoutingStatus;
|
|
173
|
+
export const stopMacosApplicationRouting =
|
|
174
|
+
diagnosticBinding.stopMacosApplicationRouting;
|
|
175
|
+
export const openMacosApplicationRoutingSettings =
|
|
176
|
+
diagnosticBinding.openMacosApplicationRoutingSettings;
|
|
177
|
+
export const runServiceLifecycleElevated =
|
|
178
|
+
diagnosticBinding.runServiceLifecycleElevated;
|
|
179
|
+
export const cleanupLegacyMacosService =
|
|
180
|
+
diagnosticBinding.cleanupLegacyMacosService;
|
|
181
|
+
export const stopMacosManagedService =
|
|
182
|
+
diagnosticBinding.stopMacosManagedService;
|
|
183
|
+
export const repairManagedFilePermissions =
|
|
184
|
+
diagnosticBinding.repairManagedFilePermissions;
|
|
185
|
+
export const relaunchCurrentApplicationWithPrivilege =
|
|
186
|
+
diagnosticBinding.relaunchCurrentApplicationWithPrivilege;
|
|
187
|
+
export const getCorePrivilegeStatus = diagnosticBinding.getCorePrivilegeStatus;
|
|
188
|
+
export const setCorePrivileges = diagnosticBinding.setCorePrivileges;
|
|
189
|
+
export const inspectApplication = diagnosticBinding.inspectApplication;
|
|
190
|
+
export const scanWindowsApplications =
|
|
191
|
+
diagnosticBinding.scanWindowsApplications;
|
|
192
|
+
export const getCurrentUserSid = diagnosticBinding.getCurrentUserSid;
|
|
193
|
+
export const isRunningAsAdmin = diagnosticBinding.isRunningAsAdmin;
|
|
194
|
+
export const ensureKokoroBoxCoreFirewall =
|
|
195
|
+
diagnosticBinding.ensureKokoroBoxCoreFirewall;
|
|
196
|
+
export const listUwpLoopbackApps = diagnosticBinding.listUwpLoopbackApps;
|
|
197
|
+
export const setUwpLoopbackExemption =
|
|
198
|
+
diagnosticBinding.setUwpLoopbackExemption;
|
|
199
|
+
export const ServiceIdentity = diagnosticBinding.ServiceIdentity;
|
|
200
|
+
export const openServiceIdentity = diagnosticBinding.openServiceIdentity;
|
|
201
|
+
export const deleteServiceIdentity = diagnosticBinding.deleteServiceIdentity;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokorobox-native",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "KokoroBox native bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"license": "GPL-3.0-only",
|
|
18
18
|
"files": [
|
|
19
19
|
"index.js",
|
|
20
|
+
"diagnostics.js",
|
|
20
21
|
"index.d.ts",
|
|
21
22
|
"README.md"
|
|
22
23
|
],
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
]
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
36
|
+
"test:logs": "node --test tests/diagnostics.test.mjs",
|
|
35
37
|
"build": "napi build --platform --release --strip --no-js --dts napi.generated.d.ts",
|
|
36
38
|
"build:debug": "napi build --platform --no-js --dts napi.generated.d.ts",
|
|
37
39
|
"create-npm-dirs": "napi create-npm-dirs",
|
|
@@ -48,11 +50,11 @@
|
|
|
48
50
|
"access": "public"
|
|
49
51
|
},
|
|
50
52
|
"optionalDependencies": {
|
|
51
|
-
"kokorobox-native-win32-x64-msvc": "0.16.
|
|
52
|
-
"kokorobox-native-win32-arm64-msvc": "0.16.
|
|
53
|
-
"kokorobox-native-darwin-x64": "0.16.
|
|
54
|
-
"kokorobox-native-darwin-arm64": "0.16.
|
|
55
|
-
"kokorobox-native-linux-x64-gnu": "0.16.
|
|
56
|
-
"kokorobox-native-linux-arm64-gnu": "0.16.
|
|
53
|
+
"kokorobox-native-win32-x64-msvc": "0.16.2",
|
|
54
|
+
"kokorobox-native-win32-arm64-msvc": "0.16.2",
|
|
55
|
+
"kokorobox-native-darwin-x64": "0.16.2",
|
|
56
|
+
"kokorobox-native-darwin-arm64": "0.16.2",
|
|
57
|
+
"kokorobox-native-linux-x64-gnu": "0.16.2",
|
|
58
|
+
"kokorobox-native-linux-arm64-gnu": "0.16.2"
|
|
57
59
|
}
|
|
58
60
|
}
|