blockflow-bridge 0.0.0-stage → 1.0.1
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 +21 -0
- package/README.md +49 -2
- package/cli.d.mts +1 -0
- package/cli.mjs +127 -0
- package/client.d.mts +23 -0
- package/client.mjs +158 -0
- package/framing.d.mts +17 -0
- package/framing.mjs +132 -0
- package/host.d.mts +13 -0
- package/host.mjs +377 -0
- package/index.d.mts +6 -0
- package/index.mjs +25 -0
- package/install.d.mts +31 -0
- package/install.mjs +309 -0
- package/package.json +37 -4
- package/paths.d.mts +7 -0
- package/paths.mjs +95 -0
- package/protocol.d.mts +22 -0
- package/protocol.mjs +24 -0
package/host.mjs
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The native messaging host. The browser starts it when the extension calls
|
|
3
|
+
// `runtime.connectNative('dev.akibh.blockflow')` and talks to it on stdin/stdout (native framing). The host
|
|
4
|
+
// listens on a per-user local socket and relays JSON-RPC between socket clients (MCP server, CLI) and the
|
|
5
|
+
// extension:
|
|
6
|
+
//
|
|
7
|
+
// client --NDJSON, auth first--> host --native frames, ids rewritten--> extension
|
|
8
|
+
// client <--response / run.* notifications, original ids-- host <-- extension
|
|
9
|
+
//
|
|
10
|
+
// stdout is the native channel: everything human goes to stderr. The host lives exactly as long as the
|
|
11
|
+
// extension's port: stdin ends -> clients are told, the socket is removed, the process exits.
|
|
12
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
13
|
+
import { chmodSync, realpathSync, unlinkSync } from 'node:fs';
|
|
14
|
+
import net from 'node:net';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { FrameTooLargeError, createLineSplitter, createNativeDecoder, encodeLine, encodeNative } from './framing.mjs';
|
|
17
|
+
import { readOrCreateToken, socketPath as defaultSocketPath, tokenFile as defaultTokenFile } from './paths.mjs';
|
|
18
|
+
import { BRIDGE_METHODS, BRIDGE_PROTOCOL_VERSION, MAX_MESSAGE_BYTES, RPC_ERRORS } from './protocol.mjs';
|
|
19
|
+
|
|
20
|
+
/** Exit codes of `runHost`. */
|
|
21
|
+
export const EXIT = Object.freeze({ ok: 0, error: 1, socketInUse: 3 });
|
|
22
|
+
|
|
23
|
+
/** Notifications from the extension that belong to one request (`params.requestId`). */
|
|
24
|
+
const ROUTED_NOTIFICATIONS = new Set(['run.started', 'run.step', 'suite.progress']);
|
|
25
|
+
const FORWARDED = new Set(BRIDGE_METHODS.filter((method) => method !== 'auth'));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {{ write(chunk: string | Uint8Array): boolean }} Writable
|
|
29
|
+
* @typedef {{
|
|
30
|
+
* stdin: NodeJS.ReadableStream,
|
|
31
|
+
* stdout: NodeJS.WritableStream,
|
|
32
|
+
* stderr?: Writable,
|
|
33
|
+
* env?: Record<string, string | undefined>,
|
|
34
|
+
* authTimeoutMs?: number,
|
|
35
|
+
* onReady?: (info: { socketPath: string, tokenFile: string }) => void,
|
|
36
|
+
* }} HostOptions
|
|
37
|
+
* @typedef {{ socket: net.Socket, id: number, authed: boolean, name?: string, closed: boolean }} Client
|
|
38
|
+
* @typedef {{ client: Client, originalId: string | number, method: string }} Pending
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Runs the relay until the extension disconnects (stdin ends). Resolves with the exit code:
|
|
43
|
+
* 0 normal end, 1 could not listen, 3 the socket is served by another live host.
|
|
44
|
+
* @param {HostOptions} options
|
|
45
|
+
* @returns {Promise<number>}
|
|
46
|
+
*/
|
|
47
|
+
export async function runHost({ stdin, stdout, stderr = process.stderr, env = process.env, authTimeoutMs = 10_000, onReady }) {
|
|
48
|
+
const log = (/** @type {string} */ text) => stderr.write(`[blockflow-bridge] ${text}\n`);
|
|
49
|
+
const where = defaultSocketPath(env);
|
|
50
|
+
const tokenPath = defaultTokenFile(env);
|
|
51
|
+
const windows = where.startsWith('\\\\.\\pipe\\');
|
|
52
|
+
|
|
53
|
+
let token;
|
|
54
|
+
try {
|
|
55
|
+
token = Buffer.from(readOrCreateToken(tokenPath), 'utf8');
|
|
56
|
+
} catch (error) {
|
|
57
|
+
log(`cannot read or create the token file ${tokenPath}: ${/** @type {Error} */ (error).message}`);
|
|
58
|
+
return EXIT.error;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @type {Set<Client>} */
|
|
62
|
+
const clients = new Set();
|
|
63
|
+
/** Host request id -> who asked. @type {Map<number, Pending>} */
|
|
64
|
+
const pending = new Map();
|
|
65
|
+
let nextHostId = 1;
|
|
66
|
+
let nextClientId = 1;
|
|
67
|
+
// Started by a browser: stdin is a pipe. Started by hand in a terminal: no extension behind it.
|
|
68
|
+
let extensionConnected = !(/** @type {{ isTTY?: boolean }} */ (stdin).isTTY);
|
|
69
|
+
let disabled = false;
|
|
70
|
+
let finished = false;
|
|
71
|
+
/** Set once we listen: only then is the socket file ours to remove. */
|
|
72
|
+
let ownSocket = false;
|
|
73
|
+
/** @type {(code: number) => void} */
|
|
74
|
+
let resolveDone = () => {};
|
|
75
|
+
const done = new Promise((resolve) => (resolveDone = resolve));
|
|
76
|
+
|
|
77
|
+
// ---------- extension side (stdin / stdout) ----------
|
|
78
|
+
|
|
79
|
+
/** @param {unknown} message @returns {boolean} false when the message could not be sent */
|
|
80
|
+
const sendToExtension = (message) => {
|
|
81
|
+
const frame = encodeNative(message);
|
|
82
|
+
try {
|
|
83
|
+
stdout.write(frame);
|
|
84
|
+
return true;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
log(`writing to the extension failed: ${/** @type {Error} */ (error).message}`);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const decoder = createNativeDecoder({
|
|
92
|
+
onMessage: (message) => onExtensionMessage(message),
|
|
93
|
+
onError: (error) => log(`dropped a message from the extension: ${error.message}`),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/** @param {any} message */
|
|
97
|
+
function onExtensionMessage(message) {
|
|
98
|
+
if (!message || typeof message !== 'object') return;
|
|
99
|
+
if (typeof message.method === 'string' && message.id === undefined) {
|
|
100
|
+
if (message.method === 'bridge.disabled') {
|
|
101
|
+
log('outside control was switched off: closing client connections');
|
|
102
|
+
disabled = true;
|
|
103
|
+
failAll(RPC_ERRORS.disabled, 'Outside control was switched off in BlockFlow.');
|
|
104
|
+
for (const client of clients) closeClient(client);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (ROUTED_NOTIFICATIONS.has(message.method)) {
|
|
108
|
+
const route = pending.get(Number(message.params?.requestId));
|
|
109
|
+
if (!route) return;
|
|
110
|
+
send(route.client, { ...message, params: { ...message.params, requestId: route.originalId } });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
log(`ignored notification ${message.method}`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (message.id !== undefined && message.id !== null && ('result' in message || 'error' in message)) {
|
|
117
|
+
const route = pending.get(Number(message.id));
|
|
118
|
+
if (!route) return;
|
|
119
|
+
pending.delete(Number(message.id));
|
|
120
|
+
send(route.client, { ...message, id: route.originalId });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
log('ignored a message from the extension that is neither a response nor a notification');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
stdin.on('data', (chunk) => decoder.push(/** @type {Buffer} */ (chunk)));
|
|
127
|
+
stdin.on('end', () => finish(EXIT.ok, 'the extension disconnected'));
|
|
128
|
+
stdin.on('close', () => finish(EXIT.ok, 'the extension disconnected'));
|
|
129
|
+
stdin.on('error', (error) => finish(EXIT.ok, `stdin error: ${error.message}`));
|
|
130
|
+
stdout.on('error', (error) => finish(EXIT.ok, `stdout error: ${error.message}`));
|
|
131
|
+
|
|
132
|
+
// ---------- socket side ----------
|
|
133
|
+
|
|
134
|
+
/** @param {Client} client @param {unknown} message */
|
|
135
|
+
function send(client, message) {
|
|
136
|
+
if (client.closed) return;
|
|
137
|
+
client.socket.write(encodeLine(message));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** @param {Client} client @param {string | number | null} id @param {number} code @param {string} text @param {object} [data] */
|
|
141
|
+
function sendError(client, id, code, text, data) {
|
|
142
|
+
send(client, { jsonrpc: '2.0', id, error: { code, message: text, ...(data ? { data } : {}) } });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** @param {Client} client */
|
|
146
|
+
function closeClient(client) {
|
|
147
|
+
if (client.closed) return;
|
|
148
|
+
client.closed = true;
|
|
149
|
+
clients.delete(client);
|
|
150
|
+
for (const [hostId, route] of pending) if (route.client === client) pending.delete(hostId);
|
|
151
|
+
client.socket.end();
|
|
152
|
+
// A client that does not read must not keep the host alive.
|
|
153
|
+
setTimeout(() => client.socket.destroy(), 1000).unref();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Answers every request still waiting on the extension. @param {number} code @param {string} text */
|
|
157
|
+
function failAll(code, text) {
|
|
158
|
+
for (const [hostId, route] of pending) {
|
|
159
|
+
pending.delete(hostId);
|
|
160
|
+
sendError(route.client, route.originalId, code, text);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @param {Client} client @param {string} line */
|
|
165
|
+
function onClientLine(client, line) {
|
|
166
|
+
/** @type {any} */
|
|
167
|
+
let message;
|
|
168
|
+
try {
|
|
169
|
+
message = JSON.parse(line);
|
|
170
|
+
} catch {
|
|
171
|
+
sendError(client, null, RPC_ERRORS.parse, 'Not JSON');
|
|
172
|
+
if (!client.authed) closeClient(client);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const id = message && (typeof message.id === 'string' || typeof message.id === 'number') ? message.id : null;
|
|
176
|
+
if (!client.authed) {
|
|
177
|
+
const given = typeof message?.params?.token === 'string' ? Buffer.from(message.params.token, 'utf8') : Buffer.alloc(0);
|
|
178
|
+
const ok = message?.method === 'auth' && given.length === token.length && timingSafeEqual(given, token);
|
|
179
|
+
if (!ok) {
|
|
180
|
+
sendError(client, id, RPC_ERRORS.unauthorized, message?.method === 'auth' ? 'Wrong token' : 'The first message must be auth {token, protocol}');
|
|
181
|
+
closeClient(client);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (message.params.protocol !== BRIDGE_PROTOCOL_VERSION) {
|
|
185
|
+
sendError(client, id, RPC_ERRORS.version, `Protocol ${message.params.protocol} is not supported; this host speaks ${BRIDGE_PROTOCOL_VERSION}`, { protocol: BRIDGE_PROTOCOL_VERSION });
|
|
186
|
+
closeClient(client);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
client.authed = true;
|
|
190
|
+
client.name = typeof message.params.client === 'string' ? message.params.client.slice(0, 80) : undefined;
|
|
191
|
+
log(`client ${client.id}${client.name ? ` (${client.name})` : ''} connected`);
|
|
192
|
+
if (id !== null) send(client, { jsonrpc: '2.0', id, result: { ok: true, extensionConnected: extensionConnected && !disabled } });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (!message || typeof message !== 'object' || message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
|
|
196
|
+
sendError(client, id, RPC_ERRORS.invalidRequest, 'Not a JSON-RPC 2.0 request');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (id === null) return; // a notification from a client: nothing to forward it to
|
|
200
|
+
if (message.method === 'auth') {
|
|
201
|
+
send(client, { jsonrpc: '2.0', id, result: { ok: true, extensionConnected: extensionConnected && !disabled } });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!FORWARDED.has(message.method)) {
|
|
205
|
+
sendError(client, id, RPC_ERRORS.methodNotFound, `Unknown method ${message.method}`);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (disabled) {
|
|
209
|
+
sendError(client, id, RPC_ERRORS.disabled, 'Outside control is switched off in BlockFlow.');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!extensionConnected) {
|
|
213
|
+
sendError(client, id, RPC_ERRORS.notConnected, 'The BlockFlow extension is not connected to this bridge.');
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const hostId = nextHostId++;
|
|
217
|
+
let frame;
|
|
218
|
+
try {
|
|
219
|
+
frame = encodeNative({ jsonrpc: '2.0', id: hostId, method: message.method, params: message.params ?? {} });
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (error instanceof FrameTooLargeError) sendError(client, id, RPC_ERRORS.tooLarge, `Request is ${error.size} bytes; the limit is ${MAX_MESSAGE_BYTES}`);
|
|
222
|
+
else sendError(client, id, RPC_ERRORS.internal, String(error));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
pending.set(hostId, { client, originalId: id, method: message.method });
|
|
226
|
+
try {
|
|
227
|
+
stdout.write(frame);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
pending.delete(hostId);
|
|
230
|
+
sendError(client, id, RPC_ERRORS.notConnected, `Could not reach the extension: ${/** @type {Error} */ (error).message}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const server = net.createServer((socket) => {
|
|
235
|
+
if (finished) return socket.destroy();
|
|
236
|
+
/** @type {Client} */
|
|
237
|
+
const client = { socket, id: nextClientId++, authed: false, closed: false };
|
|
238
|
+
clients.add(client);
|
|
239
|
+
const authTimer = setTimeout(() => {
|
|
240
|
+
if (!client.authed) closeClient(client);
|
|
241
|
+
}, authTimeoutMs);
|
|
242
|
+
authTimer.unref();
|
|
243
|
+
const splitter = createLineSplitter({
|
|
244
|
+
onLine: (line) => onClientLine(client, line),
|
|
245
|
+
onError: (error) => {
|
|
246
|
+
sendError(client, null, RPC_ERRORS.tooLarge, `${error.message}`);
|
|
247
|
+
closeClient(client);
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
socket.on('data', (chunk) => {
|
|
251
|
+
if (!client.closed) splitter.push(chunk);
|
|
252
|
+
});
|
|
253
|
+
socket.on('error', () => {});
|
|
254
|
+
socket.on('close', () => {
|
|
255
|
+
clearTimeout(authTimer);
|
|
256
|
+
if (client.authed) log(`client ${client.id} disconnected`);
|
|
257
|
+
client.closed = true;
|
|
258
|
+
clients.delete(client);
|
|
259
|
+
for (const [hostId, route] of pending) if (route.client === client) pending.delete(hostId);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// ---------- listen (replacing a stale socket, refusing a live one) ----------
|
|
264
|
+
|
|
265
|
+
const listening = await listen(server, where, windows);
|
|
266
|
+
if (listening === 'in-use') {
|
|
267
|
+
log(
|
|
268
|
+
`another BlockFlow bridge is already serving ${where} (outside control is on in another browser or profile). ` +
|
|
269
|
+
'Switch it off there, or give this browser its own BLOCKFLOW_SOCKET. Exiting.',
|
|
270
|
+
);
|
|
271
|
+
stdin.pause();
|
|
272
|
+
return EXIT.socketInUse;
|
|
273
|
+
}
|
|
274
|
+
if (listening instanceof Error) {
|
|
275
|
+
log(`cannot listen on ${where}: ${listening.message}`);
|
|
276
|
+
stdin.pause();
|
|
277
|
+
return EXIT.error;
|
|
278
|
+
}
|
|
279
|
+
ownSocket = true;
|
|
280
|
+
if (!windows) {
|
|
281
|
+
try {
|
|
282
|
+
chmodSync(where, 0o600);
|
|
283
|
+
} catch {}
|
|
284
|
+
}
|
|
285
|
+
// stdin may already have ended while we were setting up.
|
|
286
|
+
if (finished) {
|
|
287
|
+
removeSocket();
|
|
288
|
+
return done;
|
|
289
|
+
}
|
|
290
|
+
log(`listening on ${where}`);
|
|
291
|
+
onReady?.({ socketPath: where, tokenFile: tokenPath });
|
|
292
|
+
|
|
293
|
+
function removeSocket() {
|
|
294
|
+
server.close();
|
|
295
|
+
if (!ownSocket || windows) return;
|
|
296
|
+
ownSocket = false;
|
|
297
|
+
try {
|
|
298
|
+
unlinkSync(where);
|
|
299
|
+
} catch {}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** @param {number} code @param {string} reason */
|
|
303
|
+
function finish(code, reason) {
|
|
304
|
+
if (finished) return;
|
|
305
|
+
finished = true;
|
|
306
|
+
extensionConnected = false;
|
|
307
|
+
log(`${reason}: shutting down`);
|
|
308
|
+
failAll(RPC_ERRORS.notConnected, 'The BlockFlow extension disconnected (the browser closed, or outside control was switched off).');
|
|
309
|
+
for (const client of clients) closeClient(client);
|
|
310
|
+
// Only our own socket: a host that lost the race must not delete the winner's.
|
|
311
|
+
removeSocket();
|
|
312
|
+
resolveDone(code);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return done;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Listens on `where`. A leftover unix socket file nobody answers on is removed first; one a live host
|
|
320
|
+
* answers on (or a Windows pipe already taken) gives 'in-use'.
|
|
321
|
+
* @param {net.Server} server @param {string} where @param {boolean} windows
|
|
322
|
+
* @returns {Promise<'ok' | 'in-use' | Error>}
|
|
323
|
+
*/
|
|
324
|
+
async function listen(server, where, windows) {
|
|
325
|
+
const attempt = () =>
|
|
326
|
+
new Promise((resolve) => {
|
|
327
|
+
const onError = (/** @type {NodeJS.ErrnoException} */ error) => {
|
|
328
|
+
server.off('listening', onListening);
|
|
329
|
+
resolve(error);
|
|
330
|
+
};
|
|
331
|
+
const onListening = () => {
|
|
332
|
+
server.off('error', onError);
|
|
333
|
+
resolve('ok');
|
|
334
|
+
};
|
|
335
|
+
server.once('error', onError);
|
|
336
|
+
server.once('listening', onListening);
|
|
337
|
+
server.listen(where);
|
|
338
|
+
});
|
|
339
|
+
let result = /** @type {'ok' | NodeJS.ErrnoException} */ (await attempt());
|
|
340
|
+
if (result === 'ok') return 'ok';
|
|
341
|
+
if (result.code !== 'EADDRINUSE') return result;
|
|
342
|
+
if (windows) return 'in-use';
|
|
343
|
+
if (await isLive(where)) return 'in-use';
|
|
344
|
+
try {
|
|
345
|
+
unlinkSync(where);
|
|
346
|
+
} catch {}
|
|
347
|
+
result = /** @type {'ok' | NodeJS.ErrnoException} */ (await attempt());
|
|
348
|
+
if (result === 'ok') return 'ok';
|
|
349
|
+
return result.code === 'EADDRINUSE' ? 'in-use' : result;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** True when something accepts connections on the socket. @param {string} where */
|
|
353
|
+
export function isLive(where) {
|
|
354
|
+
return new Promise((resolve) => {
|
|
355
|
+
const probe = net.createConnection(where);
|
|
356
|
+
probe.once('connect', () => {
|
|
357
|
+
probe.destroy();
|
|
358
|
+
resolve(true);
|
|
359
|
+
});
|
|
360
|
+
probe.once('error', () => resolve(false));
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// `node host.mjs` (what the installed launcher runs). Chromium passes the caller's origin as an argument.
|
|
365
|
+
const invokedAs = process.argv[1] ? (() => {
|
|
366
|
+
try {
|
|
367
|
+
return realpathSync(process.argv[1]);
|
|
368
|
+
} catch {
|
|
369
|
+
return process.argv[1];
|
|
370
|
+
}
|
|
371
|
+
})() : '';
|
|
372
|
+
if (invokedAs === fileURLToPath(import.meta.url)) {
|
|
373
|
+
runHost({ stdin: process.stdin, stdout: process.stdout }).then((code) => {
|
|
374
|
+
// Let stdout flush (a final response) before leaving.
|
|
375
|
+
process.stdout.write('', () => process.exit(code));
|
|
376
|
+
});
|
|
377
|
+
}
|
package/index.d.mts
ADDED
package/index.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// blockflow-bridge: the native messaging host and its helpers. `blockflow-bridge/client` is the socket
|
|
2
|
+
// client, `blockflow-bridge/protocol` the shared constants.
|
|
3
|
+
export { EXIT, isLive, runHost } from './host.mjs';
|
|
4
|
+
export { configDir, readOrCreateToken, readToken, socketPath, tokenFile } from './paths.mjs';
|
|
5
|
+
export { FrameTooLargeError, createLineSplitter, createNativeDecoder, encodeLine, encodeNative } from './framing.mjs';
|
|
6
|
+
export { BridgeError, NOT_REACHABLE, connectBridge } from './client.mjs';
|
|
7
|
+
export {
|
|
8
|
+
BROWSERS,
|
|
9
|
+
CHROMIUM_BROWSERS,
|
|
10
|
+
FIREFOX_EXTENSION_ID,
|
|
11
|
+
MANIFEST_FILE,
|
|
12
|
+
browserTarget,
|
|
13
|
+
chromiumExtensionId,
|
|
14
|
+
defaultLauncherDir,
|
|
15
|
+
findManifests,
|
|
16
|
+
hostManifest,
|
|
17
|
+
installHost,
|
|
18
|
+
isolatedHostDirs,
|
|
19
|
+
launcherPath,
|
|
20
|
+
launcherScript,
|
|
21
|
+
registryAddArgs,
|
|
22
|
+
registryDeleteArgs,
|
|
23
|
+
uninstallHost,
|
|
24
|
+
} from './install.mjs';
|
|
25
|
+
export * from './protocol.mjs';
|
package/install.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type Browser = 'chrome' | 'chromium' | 'brave' | 'brave-origin' | 'edge' | 'firefox';
|
|
2
|
+
export type DirTarget = string | { dir: string; kind?: 'chromium' | 'firefox' };
|
|
3
|
+
export type Where = { platform?: NodeJS.Platform; home?: string; localAppData?: string };
|
|
4
|
+
export type InstallOptions = Where & {
|
|
5
|
+
extensionIds?: string[];
|
|
6
|
+
firefox?: boolean;
|
|
7
|
+
browsers?: Browser[];
|
|
8
|
+
dirs?: DirTarget[];
|
|
9
|
+
hostScript?: string;
|
|
10
|
+
launcherDir?: string;
|
|
11
|
+
nodePath?: string;
|
|
12
|
+
exec?: (file: string, args: string[]) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const FIREFOX_EXTENSION_ID: 'blockflow@akibh-dev';
|
|
15
|
+
export declare const MANIFEST_FILE: string;
|
|
16
|
+
export declare const CHROMIUM_BROWSERS: readonly Browser[];
|
|
17
|
+
export declare const BROWSERS: readonly Browser[];
|
|
18
|
+
export declare function chromiumExtensionId(absPath: string, options?: { platform?: NodeJS.Platform }): string;
|
|
19
|
+
export declare function browserTarget(browser: Browser, where?: Where): { dir?: string; registryKey?: string };
|
|
20
|
+
export declare function defaultLauncherDir(where?: Where): string;
|
|
21
|
+
export declare function launcherPath(platform: NodeJS.Platform, dir: string): string;
|
|
22
|
+
export declare function launcherScript(options?: { platform?: NodeJS.Platform; nodePath?: string; hostScript?: string }): string;
|
|
23
|
+
export declare function hostManifest(kind: 'chromium' | 'firefox', launcher: string, extensionIds?: string[]): Record<string, unknown> & { allowed_origins?: string[]; allowed_extensions?: string[] };
|
|
24
|
+
export declare function registryAddArgs(registryKey: string, manifestPath: string): string[];
|
|
25
|
+
export declare function registryDeleteArgs(registryKey: string): string[];
|
|
26
|
+
export declare function installHost(options: InstallOptions): { launcher: string; manifests: string[]; registry: { key: string; manifest: string }[] };
|
|
27
|
+
export declare function uninstallHost(options?: Omit<InstallOptions, 'extensionIds' | 'firefox' | 'hostScript' | 'nodePath'>): { removed: string[]; registry: string[] };
|
|
28
|
+
export declare function findManifests(where?: Where): { browser: Browser; file: string }[];
|
|
29
|
+
|
|
30
|
+
/** `<profile>/NativeMessagingHosts` plus each Chromium-family default folder under `home` (run the browser with HOME=home). */
|
|
31
|
+
export declare function isolatedHostDirs(profile: string, home: string, where?: Where): string[];
|