@peerbit/server 5.4.15-d333491 → 5.4.16-6611d7c

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-C8bxNrXj.js"></script>
27
27
  <link rel="stylesheet" crossorigin href="/assets/index-CIfVvUo9.css">
28
28
  </head>
29
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/server",
3
- "version": "5.4.15-d333491",
3
+ "version": "5.4.16-6611d7c",
4
4
  "author": "dao.xyz",
5
5
  "repository": {
6
6
  "type": "git",
@@ -66,8 +66,8 @@
66
66
  "lint": "aegir lint"
67
67
  },
68
68
  "devDependencies": {
69
- "@peerbit/test-lib": "0.0.1-d333491",
70
- "@peerbit/test-utils": "2.1.56-d333491",
69
+ "@peerbit/test-lib": "0.0.1-6611d7c",
70
+ "@peerbit/test-utils": "2.1.56-6611d7c",
71
71
  "@types/yargs": "17.0.24",
72
72
  "aws-sdk": "^2.1259.0",
73
73
  "dotenv": "^16.1.4",
@@ -78,7 +78,7 @@
78
78
  "dependencies": {
79
79
  "axios": "^1.4.0",
80
80
  "chalk": "^5.3.0",
81
- "peerbit": "4.1.45-d333491",
81
+ "peerbit": "4.1.45-6611d7c",
82
82
  "yargs": "^17.7.2",
83
83
  "tar-stream": "^3.1.7",
84
84
  "tmp": "^0.2.1",
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",
package/src/client.ts CHANGED
@@ -262,6 +262,19 @@ export const createClient = async (
262
262
  }
263
263
  return resp.data;
264
264
  },
265
+ uninstall: async (name: string): Promise<void> => {
266
+ const resp = await axiosInstance.delete(
267
+ endpoint + INSTALL_PATH + "/" + encodeURIComponent(name),
268
+ { validateStatus },
269
+ );
270
+ if (resp.status !== 200 && resp.status !== 404) {
271
+ throw new Error(
272
+ typeof resp.data === "string"
273
+ ? resp.data
274
+ : resp.data?.toString?.() || "Uninstall failed",
275
+ );
276
+ }
277
+ },
265
278
  versions: async (): Promise<Record<string, string>> => {
266
279
  const resp = throwIfNot200(
267
280
  await axiosInstance.get(endpoint + VERSIONS_PATH, {
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/server.ts CHANGED
@@ -626,6 +626,62 @@ export const startApiServer = async (
626
626
  break;
627
627
  }
628
628
 
629
+ case "DELETE": {
630
+ try {
631
+ // Expecting DELETE /install/<packageName>
632
+ const packageName = getPathValue(req, 1);
633
+
634
+ if (!packageName || packageName.length === 0) {
635
+ res.writeHead(400);
636
+ res.end("Invalid package name");
637
+ return;
638
+ }
639
+
640
+ const installDir = getInstallDir();
641
+ if (!installDir) {
642
+ res.writeHead(400);
643
+ res.end("Missing installation directory");
644
+ return;
645
+ }
646
+
647
+ let permission = "";
648
+ try {
649
+ fs.accessSync(installDir, fs.constants.W_OK);
650
+ } catch (_e) {
651
+ permission = "sudo";
652
+ }
653
+
654
+ try {
655
+ console.log("Uninstalling package: " + packageName);
656
+ execSync(
657
+ `${permission} npm uninstall ${packageName} --prefix ${installDir} --no-save --no-package-lock`,
658
+ );
659
+ } catch (error: any) {
660
+ res.writeHead(400);
661
+ res.end(
662
+ "Failed to uninstall library: " +
663
+ packageName +
664
+ ". " +
665
+ error.toString(),
666
+ );
667
+ return;
668
+ }
669
+
670
+ try {
671
+ await properties?.session?.imports.remove(packageName);
672
+ } catch (e) {
673
+ // ignore persistence errors; uninstall already done
674
+ }
675
+
676
+ res.writeHead(200);
677
+ res.end();
678
+ } catch (error: any) {
679
+ res.writeHead(400);
680
+ res.end(error?.message || "Uninstall error");
681
+ }
682
+ break;
683
+ }
684
+
629
685
  default: {
630
686
  r404();
631
687
  break;