@peerbit/server 5.5.0 → 5.6.0-1c918e0
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/src/aws.d.ts.map +1 -1
- package/dist/src/aws.js +40 -26
- package/dist/src/aws.js.map +1 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +17 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +7 -1
- package/dist/src/client.js.map +1 -1
- package/dist/src/routes.d.ts +1 -0
- package/dist/src/routes.d.ts.map +1 -1
- package/dist/src/routes.js +1 -0
- package/dist/src/routes.js.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +64 -1
- package/dist/src/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui/assets/{index-C8bxNrXj.js → index-BeFPnrza.js} +3 -3
- package/dist/ui/index.html +1 -1
- package/package.json +89 -89
- package/src/aws.ts +49 -31
- package/src/cli.ts +23 -0
- package/src/client.ts +13 -0
- package/src/routes.ts +1 -0
- package/src/server.ts +68 -0
package/dist/ui/index.html
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
Learn how to configure a non-root public URL by running `npm run build`.
|
|
24
24
|
-->
|
|
25
25
|
<title>Peerbit</title>
|
|
26
|
-
<script type="module" crossorigin src="/assets/index-
|
|
26
|
+
<script type="module" crossorigin src="/assets/index-BeFPnrza.js"></script>
|
|
27
27
|
<link rel="stylesheet" crossorigin href="/assets/index-CIfVvUo9.css">
|
|
28
28
|
</head>
|
|
29
29
|
|
package/package.json
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
2
|
+
"name": "@peerbit/server",
|
|
3
|
+
"version": "5.6.0-1c918e0",
|
|
4
|
+
"author": "dao.xyz",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/dao-xyz/peerbit"
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"bin": {
|
|
13
|
+
"peerbit": "./dist/src/bin.js"
|
|
14
|
+
},
|
|
15
|
+
"module": "dist/src/index.js",
|
|
16
|
+
"types": "dist/src/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"import": "./dist/src/index.js"
|
|
19
|
+
},
|
|
20
|
+
"browser": {
|
|
21
|
+
"./dist/src/server.js": "./dist/src/server.browser.js",
|
|
22
|
+
"./server.js": "./dist/src/server.browser.js",
|
|
23
|
+
"./dist/src/config.js": "./dist/src/config.browser.js",
|
|
24
|
+
"./config.js": "./dist/src/config.browser.js",
|
|
25
|
+
"./dist/src/remotes.js": "./dist/src/remotes.browser.js",
|
|
26
|
+
"./remotes.js": "./dist/src/remotes.browser.js",
|
|
27
|
+
"./dist/src/docker.js": "./dist/src/docker.browser.js",
|
|
28
|
+
"./docker.js": "./dist/src/docker.browser.js",
|
|
29
|
+
"./dist/src/aws.js": "./dist/src/aws.browser.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src",
|
|
34
|
+
"src/nginx-template.conf",
|
|
35
|
+
"!src/test",
|
|
36
|
+
"!src/**/__tests__",
|
|
37
|
+
"!lib/**/__tests__",
|
|
38
|
+
"patches",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"eslintConfig": {
|
|
48
|
+
"extends": "peerbit",
|
|
49
|
+
"parserOptions": {
|
|
50
|
+
"project": true,
|
|
51
|
+
"sourceType": "module"
|
|
52
|
+
},
|
|
53
|
+
"ignorePatterns": [
|
|
54
|
+
"!.aegir.js",
|
|
55
|
+
"test/ts-use",
|
|
56
|
+
"*.d.ts"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"clean": "shx rm -rf lib/*",
|
|
61
|
+
"build": "yarn clean && yarn build-lib && yarn build-ui",
|
|
62
|
+
"build-lib": "tsc -p tsconfig.json",
|
|
63
|
+
"build-ui": "cd ../frontend && yarn build && cd ../node",
|
|
64
|
+
"postbuild": "cp src/nginx-template.conf dist/src/ && cp -r ../frontend/dist/. dist/ui",
|
|
65
|
+
"test": "aegir test --t node",
|
|
66
|
+
"lint": "aegir lint"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@peerbit/test-lib": "0.0.1-1c918e0",
|
|
70
|
+
"@peerbit/test-utils": "2.1.57-1c918e0",
|
|
71
|
+
"@types/yargs": "17.0.24",
|
|
72
|
+
"aws-sdk": "^2.1259.0",
|
|
73
|
+
"dotenv": "^16.1.4",
|
|
74
|
+
"@types/tmp": "^0.2.3",
|
|
75
|
+
"@types/tar-stream": "^3.1.3",
|
|
76
|
+
"shx": "^0.3.4"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"axios": "^1.4.0",
|
|
80
|
+
"chalk": "^5.3.0",
|
|
81
|
+
"peerbit": "4.1.46-1c918e0",
|
|
82
|
+
"yargs": "^17.7.2",
|
|
83
|
+
"tar-stream": "^3.1.7",
|
|
84
|
+
"tmp": "^0.2.1",
|
|
85
|
+
"tty-table": "^4.2.1"
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"@aws-sdk/client-ec2": "^3.390.0",
|
|
89
|
+
"@aws-sdk/client-route-53": "^3.391.0"
|
|
90
|
+
}
|
|
91
91
|
}
|
package/src/aws.ts
CHANGED
|
@@ -249,40 +249,58 @@ export const launchNodes = async (properties: {
|
|
|
249
249
|
);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
// wait for instance
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const foundIps: string[] = [];
|
|
262
|
-
for (const out of instanceOut.Instances) {
|
|
263
|
-
const foundInstance = foundInstances.find(
|
|
264
|
-
(x) => x!.InstanceId === out.InstanceId!,
|
|
265
|
-
);
|
|
266
|
-
if (!foundInstance!.PublicIpAddress) {
|
|
267
|
-
await delay(3000);
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
foundIps.push(foundInstance!.PublicIpAddress!);
|
|
271
|
-
}
|
|
272
|
-
let publicIps: string[] = foundIps;
|
|
252
|
+
// wait for AWS to recognize the new instance IDs and for public IPs to be assigned
|
|
253
|
+
const instanceIds = instanceOut.Instances.map((x) => x.InstanceId!);
|
|
254
|
+
const timeoutMs = 3 * 60 * 1000; // 3 minutes
|
|
255
|
+
const pollIntervalMs = 5000;
|
|
256
|
+
const start = Date.now();
|
|
257
|
+
let foundInstances: Array<{
|
|
258
|
+
InstanceId?: string;
|
|
259
|
+
PublicIpAddress?: string;
|
|
260
|
+
}> = [];
|
|
273
261
|
|
|
274
|
-
|
|
275
|
-
|
|
262
|
+
while (Date.now() - start < timeoutMs) {
|
|
263
|
+
try {
|
|
264
|
+
const info = await client.send(
|
|
265
|
+
new DescribeInstancesCommand({ InstanceIds: instanceIds }),
|
|
266
|
+
);
|
|
267
|
+
foundInstances =
|
|
268
|
+
info.Reservations?.flatMap((r) => r.Instances || []) || [];
|
|
269
|
+
const allPresent = foundInstances.length >= instanceIds.length;
|
|
270
|
+
const ips = new Map(
|
|
271
|
+
foundInstances
|
|
272
|
+
.filter((i) => i.InstanceId && i.PublicIpAddress)
|
|
273
|
+
.map((i) => [i.InstanceId!, i.PublicIpAddress!]),
|
|
274
|
+
);
|
|
275
|
+
const allHaveIp = instanceIds.every((id) => ips.has(id));
|
|
276
|
+
if (allPresent && allHaveIp) {
|
|
277
|
+
// reorder to original order
|
|
278
|
+
var publicIps = instanceIds.map((id) => ips.get(id)!);
|
|
279
|
+
if (publicIps.length > 0) {
|
|
280
|
+
// success
|
|
281
|
+
return publicIps.map((v, ix) => {
|
|
282
|
+
return {
|
|
283
|
+
instanceId: instanceOut.Instances![ix].InstanceId!,
|
|
284
|
+
publicIp: v,
|
|
285
|
+
name: names[ix],
|
|
286
|
+
region: regionString,
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
} catch (e: any) {
|
|
292
|
+
// AWS eventual consistency: sometimes returns InvalidInstanceID.NotFound immediately after RunInstances
|
|
293
|
+
const code = e?.Code || e?.name || e?.code;
|
|
294
|
+
if (code !== "InvalidInstanceID.NotFound") {
|
|
295
|
+
throw e;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
await delay(pollIntervalMs);
|
|
276
299
|
}
|
|
277
300
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
publicIp: v,
|
|
282
|
-
name: names[ix],
|
|
283
|
-
region: regionString,
|
|
284
|
-
};
|
|
285
|
-
}); // TODO types
|
|
301
|
+
throw new Error(
|
|
302
|
+
"Timed out waiting for instances to be describe-able with public IPs",
|
|
303
|
+
);
|
|
286
304
|
};
|
|
287
305
|
|
|
288
306
|
export const terminateNode = async (properties: {
|
package/src/cli.ts
CHANGED
|
@@ -1188,6 +1188,29 @@ export const cli = async (args?: string[]) => {
|
|
|
1188
1188
|
}
|
|
1189
1189
|
},
|
|
1190
1190
|
})
|
|
1191
|
+
.command({
|
|
1192
|
+
command: "self-update [version]",
|
|
1193
|
+
describe:
|
|
1194
|
+
"Update @peerbit/server on the target node to [version] (default latest) and restart",
|
|
1195
|
+
builder: (yargs) => {
|
|
1196
|
+
yargs.positional("version", {
|
|
1197
|
+
describe:
|
|
1198
|
+
"Version spec for @peerbit/server (e.g. 5.4.16)",
|
|
1199
|
+
type: "string",
|
|
1200
|
+
});
|
|
1201
|
+
return yargs;
|
|
1202
|
+
},
|
|
1203
|
+
handler: async (args) => {
|
|
1204
|
+
for (const api of apis) {
|
|
1205
|
+
const { version } = await api.api.selfUpdate(
|
|
1206
|
+
args.version as string | undefined,
|
|
1207
|
+
);
|
|
1208
|
+
api.log(
|
|
1209
|
+
`Self-update to @peerbit/server@${version} initiated`,
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
},
|
|
1213
|
+
})
|
|
1191
1214
|
.command({
|
|
1192
1215
|
command: "stop",
|
|
1193
1216
|
describe: "Stop the server",
|
package/src/client.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
PROGRAM_VARIANTS_PATH,
|
|
23
23
|
REMOTE_API_PORT,
|
|
24
24
|
RESTART_PATH,
|
|
25
|
+
SELF_UPDATE_PATH,
|
|
25
26
|
STOP_PATH,
|
|
26
27
|
TRUST_PATH,
|
|
27
28
|
VERSIONS_PATH,
|
|
@@ -301,6 +302,18 @@ export const createClient = async (
|
|
|
301
302
|
}),
|
|
302
303
|
);
|
|
303
304
|
},
|
|
305
|
+
selfUpdate: async (version?: string): Promise<{ version: string }> => {
|
|
306
|
+
const resp = throwIfNot200(
|
|
307
|
+
await axiosInstance.post(
|
|
308
|
+
endpoint + SELF_UPDATE_PATH,
|
|
309
|
+
version ? JSON.stringify({ version }) : undefined,
|
|
310
|
+
{
|
|
311
|
+
validateStatus,
|
|
312
|
+
},
|
|
313
|
+
),
|
|
314
|
+
);
|
|
315
|
+
return resp.data as { version: string };
|
|
316
|
+
},
|
|
304
317
|
stop: async (): Promise<void> => {
|
|
305
318
|
throwIfNot200(
|
|
306
319
|
await axiosInstance.post(endpoint + STOP_PATH, undefined, {
|
package/src/routes.ts
CHANGED
package/src/server.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
PROGRAM_PATH,
|
|
36
36
|
PROGRAM_VARIANTS_PATH,
|
|
37
37
|
RESTART_PATH,
|
|
38
|
+
SELF_UPDATE_PATH,
|
|
38
39
|
STOP_PATH,
|
|
39
40
|
TRUST_PATH,
|
|
40
41
|
VERSIONS_PATH,
|
|
@@ -712,6 +713,73 @@ export const startApiServer = async (
|
|
|
712
713
|
}
|
|
713
714
|
|
|
714
715
|
/* keep the remaining else-if blocks (PEER_ID_PATH, etc.) unchanged */
|
|
716
|
+
} else if (req.url.startsWith(SELF_UPDATE_PATH)) {
|
|
717
|
+
if (req.method === "POST") {
|
|
718
|
+
try {
|
|
719
|
+
// version is optional; default to latest
|
|
720
|
+
let versionSpec: string | undefined;
|
|
721
|
+
try {
|
|
722
|
+
const parsed = JSON.parse(body || "{}");
|
|
723
|
+
versionSpec = parsed?.version;
|
|
724
|
+
} catch (_e) {}
|
|
725
|
+
|
|
726
|
+
let resolvedVersion = "latest";
|
|
727
|
+
try {
|
|
728
|
+
const spec = `@peerbit/server${versionSpec ? "@" + versionSpec : ""}`;
|
|
729
|
+
const out = execSync(`npm view ${spec} version --json`, {
|
|
730
|
+
encoding: "utf8",
|
|
731
|
+
});
|
|
732
|
+
resolvedVersion = JSON.parse(out);
|
|
733
|
+
} catch (_e) {
|
|
734
|
+
resolvedVersion = versionSpec || "latest";
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
console.log(
|
|
738
|
+
"Self-updating @peerbit/server to version: " +
|
|
739
|
+
resolvedVersion,
|
|
740
|
+
);
|
|
741
|
+
res.setHeader("Content-Type", "application/json");
|
|
742
|
+
res.writeHead(200);
|
|
743
|
+
res.end(JSON.stringify({ version: resolvedVersion }));
|
|
744
|
+
|
|
745
|
+
process.nextTick(() => {
|
|
746
|
+
try {
|
|
747
|
+
const installDir = getInstallDir();
|
|
748
|
+
let permission = "";
|
|
749
|
+
if (installDir) {
|
|
750
|
+
try {
|
|
751
|
+
fs.accessSync(installDir, fs.constants.W_OK);
|
|
752
|
+
} catch (_e) {
|
|
753
|
+
permission = "sudo";
|
|
754
|
+
}
|
|
755
|
+
try {
|
|
756
|
+
execSync(
|
|
757
|
+
`${permission} npm install -g @peerbit/server@${resolvedVersion}`,
|
|
758
|
+
);
|
|
759
|
+
} catch (_globalErr) {
|
|
760
|
+
execSync(
|
|
761
|
+
`${permission} npm install @peerbit/server@${resolvedVersion} --prefix ${installDir} --no-save --no-package-lock`,
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
execSync(
|
|
766
|
+
`npm install -g @peerbit/server@${resolvedVersion}`,
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
} catch (e) {
|
|
770
|
+
console.error("Self-update installation failed:", e);
|
|
771
|
+
}
|
|
772
|
+
restart();
|
|
773
|
+
});
|
|
774
|
+
} catch (error: any) {
|
|
775
|
+
res.writeHead(500);
|
|
776
|
+
res.end(
|
|
777
|
+
"Unexpected self-update error: " + (error?.message || ""),
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
} else {
|
|
781
|
+
r404();
|
|
782
|
+
}
|
|
715
783
|
} else if (req.url.startsWith(BOOTSTRAP_PATH)) {
|
|
716
784
|
switch (req.method) {
|
|
717
785
|
case "POST":
|