@tool-bridge/server 0.26.2 → 0.28.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/dist/admin.js +1 -1
- package/dist/{chunk-KTWFYFDL.js → chunk-A5VV3P2S.js} +47 -34
- package/dist/{chunk-VKZYPURU.js → chunk-WR4IHUDC.js} +980 -249
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -2
- package/dist/main.js +5 -3
- package/package.json +1 -1
package/dist/admin.js
CHANGED
|
@@ -25,6 +25,11 @@ var stateSchema = z.strictObject({
|
|
|
25
25
|
port: z.number().int().min(0).max(65535).default(8787),
|
|
26
26
|
host: z.string().default("0.0.0.0")
|
|
27
27
|
});
|
|
28
|
+
var BootstrapLockBusyError = class extends TBError {
|
|
29
|
+
constructor() {
|
|
30
|
+
super("conflict", "another local maintenance operation is running");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
28
33
|
var BootstrapStateStore = class {
|
|
29
34
|
constructor(directory) {
|
|
30
35
|
this.directory = directory;
|
|
@@ -41,7 +46,7 @@ var BootstrapStateStore = class {
|
|
|
41
46
|
update: 1e4
|
|
42
47
|
}).catch((error) => {
|
|
43
48
|
if (error.code === "ELOCKED") {
|
|
44
|
-
throw new
|
|
49
|
+
throw new BootstrapLockBusyError();
|
|
45
50
|
}
|
|
46
51
|
throw error;
|
|
47
52
|
});
|
|
@@ -78,38 +83,45 @@ var BootstrapStateStore = class {
|
|
|
78
83
|
return value === void 0 ? void 0 : stateSchema.parse(value);
|
|
79
84
|
}
|
|
80
85
|
async initialize() {
|
|
81
|
-
return this.exclusive(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
return this.exclusive(() => this.readOrInitialize(), 5);
|
|
87
|
+
}
|
|
88
|
+
/** Keep bootstrap reads, including the first initialization, locked through admission. */
|
|
89
|
+
async withStartupState(initializedInstanceId, admit) {
|
|
90
|
+
return this.exclusive(async () => admit(await this.readOrInitialize(initializedInstanceId)));
|
|
91
|
+
}
|
|
92
|
+
async readOrInitialize(initializedInstanceId) {
|
|
93
|
+
const current = await this.state();
|
|
94
|
+
if (initializedInstanceId && current?.instanceId !== initializedInstanceId)
|
|
95
|
+
throw new TBError("conflict", "bootstrap identity changed during handoff");
|
|
96
|
+
if (current) {
|
|
97
|
+
if (initializedInstanceId || await this.read("initialized.json"))
|
|
98
|
+
return { ...current, phase: "initialized" };
|
|
99
|
+
return current;
|
|
100
|
+
}
|
|
101
|
+
if (await this.read("identity.json"))
|
|
102
|
+
throw new TBError(
|
|
103
|
+
"unavailable",
|
|
104
|
+
"bootstrap state requires local recovery"
|
|
105
|
+
);
|
|
106
|
+
const state = {
|
|
107
|
+
instanceId: randomUUID(),
|
|
108
|
+
revision: 1,
|
|
109
|
+
phase: "setup",
|
|
110
|
+
port: 8787,
|
|
111
|
+
host: "0.0.0.0"
|
|
112
|
+
};
|
|
113
|
+
await this.write("identity.json", { instanceId: state.instanceId });
|
|
114
|
+
await this.write("keys.json", {
|
|
115
|
+
keyring: createEncryptionKeyring(randomBytes(32).toString("base64url")),
|
|
116
|
+
storeTokenKeyring: createEncryptionKeyring(
|
|
117
|
+
randomBytes(32).toString("base64url")
|
|
118
|
+
),
|
|
119
|
+
oauthKey: randomBytes(32).toString("base64url"),
|
|
120
|
+
adminSk: `tb_sk_${randomBytes(32).toString("base64url")}`
|
|
121
|
+
});
|
|
122
|
+
await this.write("bootstrap.json", state);
|
|
123
|
+
await this.pair(state.instanceId, "setup");
|
|
124
|
+
return state;
|
|
113
125
|
}
|
|
114
126
|
async pair(instanceId, mode) {
|
|
115
127
|
const token = randomBytes(32).toString("base64url");
|
|
@@ -216,7 +228,7 @@ var BootstrapStateStore = class {
|
|
|
216
228
|
// package.json
|
|
217
229
|
var package_default = {
|
|
218
230
|
name: "@tool-bridge/server",
|
|
219
|
-
version: "0.
|
|
231
|
+
version: "0.28.0",
|
|
220
232
|
description: "Self-hosted Tool Bridge Node server with PostgreSQL, S3 object storage and WebSocket device channels",
|
|
221
233
|
type: "module",
|
|
222
234
|
license: "MIT",
|
|
@@ -299,6 +311,7 @@ var package_default = {
|
|
|
299
311
|
};
|
|
300
312
|
|
|
301
313
|
export {
|
|
314
|
+
BootstrapLockBusyError,
|
|
302
315
|
BootstrapStateStore,
|
|
303
316
|
package_default
|
|
304
317
|
};
|