@peerbit/server 5.4.16 → 5.5.0-aeb9685

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.
@@ -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-BPdbODjv.js"></script>
26
+ <script type="module" crossorigin src="/assets/index-Dcbn6kSA.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
- "name": "@peerbit/server",
3
- "version": "5.4.16",
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",
70
- "@peerbit/test-utils": "2.1.56",
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.45",
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
- }
2
+ "name": "@peerbit/server",
3
+ "version": "5.5.0-aeb9685",
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-aeb9685",
70
+ "@peerbit/test-utils": "2.1.57-aeb9685",
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-aeb9685",
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/cli.ts CHANGED
@@ -1160,6 +1160,24 @@ export const cli = async (args?: string[]) => {
1160
1160
  }
1161
1161
  },
1162
1162
  })
1163
+ .command({
1164
+ command: "uninstall <package>",
1165
+ describe: "uninstall a previously installed dependency",
1166
+ builder: (yargs: any) => {
1167
+ yargs.positional("package", {
1168
+ type: "string",
1169
+ describe: "NPM package name to uninstall",
1170
+ demandOption: true,
1171
+ });
1172
+ return yargs;
1173
+ },
1174
+ handler: async (args) => {
1175
+ for (const api of apis) {
1176
+ await api.api.dependency.uninstall(args.package);
1177
+ api.log(`Uninstalled ${args.package}`);
1178
+ }
1179
+ },
1180
+ })
1163
1181
 
1164
1182
  .command({
1165
1183
  command: "restart",
@@ -1170,6 +1188,29 @@ export const cli = async (args?: string[]) => {
1170
1188
  }
1171
1189
  },
1172
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
+ })
1173
1214
  .command({
1174
1215
  command: "stop",
1175
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,
@@ -262,6 +263,19 @@ export const createClient = async (
262
263
  }
263
264
  return resp.data;
264
265
  },
266
+ uninstall: async (name: string): Promise<void> => {
267
+ const resp = await axiosInstance.delete(
268
+ endpoint + INSTALL_PATH + "/" + encodeURIComponent(name),
269
+ { validateStatus },
270
+ );
271
+ if (resp.status !== 200 && resp.status !== 404) {
272
+ throw new Error(
273
+ typeof resp.data === "string"
274
+ ? resp.data
275
+ : resp.data?.toString?.() || "Uninstall failed",
276
+ );
277
+ }
278
+ },
265
279
  versions: async (): Promise<Record<string, string>> => {
266
280
  const resp = throwIfNot200(
267
281
  await axiosInstance.get(endpoint + VERSIONS_PATH, {
@@ -288,6 +302,18 @@ export const createClient = async (
288
302
  }),
289
303
  );
290
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
+ },
291
317
  stop: async (): Promise<void> => {
292
318
  throwIfNot200(
293
319
  await axiosInstance.post(endpoint + STOP_PATH, undefined, {
package/src/domain.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  /* eslint-disable no-console */
2
2
  import { waitFor } from "@peerbit/time";
3
3
 
4
- const isNode = typeof window === "undefined";
4
+ const isNode =
5
+ typeof process !== "undefined" &&
6
+ process.versions != null &&
7
+ process.versions.node != null;
5
8
 
6
9
  const validateEmail = (email: any) => {
7
10
  return String(email)
package/src/routes.ts CHANGED
@@ -24,3 +24,4 @@ export const TERMINATE_PATH = "/terminate";
24
24
  export const STOP_PATH = "/stop";
25
25
  export const LOG_PATH = "/log";
26
26
  export const VERSIONS_PATH = "/versions";
27
+ export const SELF_UPDATE_PATH = "/self/update";
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,
@@ -626,6 +627,62 @@ export const startApiServer = async (
626
627
  break;
627
628
  }
628
629
 
630
+ case "DELETE": {
631
+ try {
632
+ // Expecting DELETE /install/<packageName>
633
+ const packageName = getPathValue(req, 1);
634
+
635
+ if (!packageName || packageName.length === 0) {
636
+ res.writeHead(400);
637
+ res.end("Invalid package name");
638
+ return;
639
+ }
640
+
641
+ const installDir = getInstallDir();
642
+ if (!installDir) {
643
+ res.writeHead(400);
644
+ res.end("Missing installation directory");
645
+ return;
646
+ }
647
+
648
+ let permission = "";
649
+ try {
650
+ fs.accessSync(installDir, fs.constants.W_OK);
651
+ } catch (_e) {
652
+ permission = "sudo";
653
+ }
654
+
655
+ try {
656
+ console.log("Uninstalling package: " + packageName);
657
+ execSync(
658
+ `${permission} npm uninstall ${packageName} --prefix ${installDir} --no-save --no-package-lock`,
659
+ );
660
+ } catch (error: any) {
661
+ res.writeHead(400);
662
+ res.end(
663
+ "Failed to uninstall library: " +
664
+ packageName +
665
+ ". " +
666
+ error.toString(),
667
+ );
668
+ return;
669
+ }
670
+
671
+ try {
672
+ await properties?.session?.imports.remove(packageName);
673
+ } catch (e) {
674
+ // ignore persistence errors; uninstall already done
675
+ }
676
+
677
+ res.writeHead(200);
678
+ res.end();
679
+ } catch (error: any) {
680
+ res.writeHead(400);
681
+ res.end(error?.message || "Uninstall error");
682
+ }
683
+ break;
684
+ }
685
+
629
686
  default: {
630
687
  r404();
631
688
  break;
@@ -656,6 +713,73 @@ export const startApiServer = async (
656
713
  }
657
714
 
658
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
+ }
659
783
  } else if (req.url.startsWith(BOOTSTRAP_PATH)) {
660
784
  switch (req.method) {
661
785
  case "POST":