@peerbit/server 5.4.15 → 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,91 +1,91 @@
1
1
  {
2
- "name": "@peerbit/server",
3
- "version": "5.4.15",
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.4.16-6611d7c",
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-6611d7c",
70
+ "@peerbit/test-utils": "2.1.56-6611d7c",
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-6611d7c",
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",
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)
@@ -152,12 +155,12 @@ export const startCertbot = async (
152
155
 
153
156
  // copy ui from node_modules to home for permission reasons (volume will not work otherwise)
154
157
  const certbotDockerCommand = `cp -r ${uiPath} $(pwd)/ui && docker pull jonasal/nginx-certbot:latest && docker run -d --net=host \
155
- --env CERTBOT_EMAIL=${email} ${isTest ? "--env STAGING=1" : ""}\
158
+ --restart unless-stopped \
159
+ --env CERTBOT_EMAIL=${email} ${isTest ? "--env STAGING=1" : ""}\
156
160
  -v $(pwd)/nginx_secrets:/etc/letsencrypt \
157
161
  -v ${nginxConfigPath}:/etc/nginx/user_conf.d:ro \
158
162
  -v $(pwd)/ui:/usr/share/nginx/html:ro \
159
- --name ${dockerProcessName} jonasal/nginx-certbot:latest \
160
- --restart unless-stopped`;
163
+ --name ${dockerProcessName} jonasal/nginx-certbot:latest`;
161
164
 
162
165
  console.log("Starting Certbot");
163
166
  // try two times with some delay, because sometimes the docker daemon is not available immidatel
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;