@peerbit/server 5.0.32 → 5.0.33-0691c73

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.
Files changed (78) hide show
  1. package/lib/esm/aws.browser.d.ts +1 -0
  2. package/lib/esm/aws.browser.d.ts.map +1 -0
  3. package/lib/esm/aws.d.ts +1 -0
  4. package/lib/esm/aws.d.ts.map +1 -0
  5. package/lib/esm/aws.js +1 -0
  6. package/lib/esm/aws.js.map +1 -1
  7. package/lib/esm/bin.d.ts +1 -0
  8. package/lib/esm/bin.d.ts.map +1 -0
  9. package/lib/esm/cli.d.ts +1 -0
  10. package/lib/esm/cli.d.ts.map +1 -0
  11. package/lib/esm/cli.js +3 -1
  12. package/lib/esm/cli.js.map +1 -1
  13. package/lib/esm/client.d.ts +6 -5
  14. package/lib/esm/client.d.ts.map +1 -0
  15. package/lib/esm/client.js +3 -11
  16. package/lib/esm/client.js.map +1 -1
  17. package/lib/esm/config.browser.d.ts +1 -0
  18. package/lib/esm/config.browser.d.ts.map +1 -0
  19. package/lib/esm/config.d.ts +1 -0
  20. package/lib/esm/config.d.ts.map +1 -0
  21. package/lib/esm/config.js.map +1 -1
  22. package/lib/esm/docker.browser.d.ts +1 -0
  23. package/lib/esm/docker.browser.d.ts.map +1 -0
  24. package/lib/esm/docker.d.ts +1 -0
  25. package/lib/esm/docker.d.ts.map +1 -0
  26. package/lib/esm/docker.js +1 -1
  27. package/lib/esm/docker.js.map +1 -1
  28. package/lib/esm/domain.d.ts +3 -2
  29. package/lib/esm/domain.d.ts.map +1 -0
  30. package/lib/esm/domain.js +0 -1
  31. package/lib/esm/domain.js.map +1 -1
  32. package/lib/esm/index.d.ts +1 -0
  33. package/lib/esm/index.d.ts.map +1 -0
  34. package/lib/esm/peerbit.d.ts +2 -1
  35. package/lib/esm/peerbit.d.ts.map +1 -0
  36. package/lib/esm/peerbit.js +1 -0
  37. package/lib/esm/peerbit.js.map +1 -1
  38. package/lib/esm/remotes.browser.d.ts +1 -0
  39. package/lib/esm/remotes.browser.d.ts.map +1 -0
  40. package/lib/esm/remotes.d.ts +3 -2
  41. package/lib/esm/remotes.d.ts.map +1 -0
  42. package/lib/esm/routes.d.ts +1 -0
  43. package/lib/esm/routes.d.ts.map +1 -0
  44. package/lib/esm/server.browser.d.ts +1 -0
  45. package/lib/esm/server.browser.d.ts.map +1 -0
  46. package/lib/esm/server.d.ts +3 -2
  47. package/lib/esm/server.d.ts.map +1 -0
  48. package/lib/esm/server.js +5 -1
  49. package/lib/esm/server.js.map +1 -1
  50. package/lib/esm/session.d.ts +1 -0
  51. package/lib/esm/session.d.ts.map +1 -0
  52. package/lib/esm/session.js +1 -0
  53. package/lib/esm/session.js.map +1 -1
  54. package/lib/esm/{signes-request.d.ts → signed-request.d.ts} +2 -1
  55. package/lib/esm/signed-request.d.ts.map +1 -0
  56. package/lib/esm/{signes-request.js → signed-request.js} +3 -2
  57. package/lib/esm/signed-request.js.map +1 -0
  58. package/lib/esm/trust.browser.d.ts +1 -0
  59. package/lib/esm/trust.browser.d.ts.map +1 -0
  60. package/lib/esm/trust.d.ts +1 -0
  61. package/lib/esm/trust.d.ts.map +1 -0
  62. package/lib/esm/types.d.ts +1 -0
  63. package/lib/esm/types.d.ts.map +1 -0
  64. package/lib/tsconfig.tsbuildinfo +1 -0
  65. package/lib/ui/assets/{index-BSyx7bor.js → index-BC4oCu-g.js} +1 -1
  66. package/lib/ui/assets/index-CvfEshgH.js +79 -0
  67. package/lib/ui/index.html +1 -1
  68. package/package.json +77 -78
  69. package/src/cli.ts +16 -19
  70. package/src/client.ts +33 -48
  71. package/src/config.ts +5 -5
  72. package/src/docker.ts +2 -2
  73. package/src/domain.ts +1 -2
  74. package/src/peerbit.ts +5 -6
  75. package/src/server.ts +19 -14
  76. package/src/{signes-request.ts → signed-request.ts} +1 -1
  77. package/lib/esm/signes-request.js.map +0 -1
  78. package/lib/ui/assets/index-Dg4BL3Lz.js +0 -77
package/lib/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-Dg4BL3Lz.js"></script>
26
+ <script type="module" crossorigin src="/assets/index-CvfEshgH.js"></script>
27
27
  <link rel="stylesheet" crossorigin href="/assets/index-BDBx6C_I.css">
28
28
  </head>
29
29
 
package/package.json CHANGED
@@ -1,80 +1,79 @@
1
1
  {
2
- "name": "@peerbit/server",
3
- "version": "5.0.32",
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": "./lib/esm/bin.js"
14
- },
15
- "module": "lib/esm/index.js",
16
- "types": "lib/esm/index.d.ts",
17
- "exports": {
18
- "import": "./lib/esm/index.js"
19
- },
20
- "browser": {
21
- "./lib/esm/server.js": "./lib/esm/server.browser.js",
22
- "./server.js": "./lib/esm/server.browser.js",
23
- "./lib/esm/config.js": "./lib/esm/config.browser.js",
24
- "./config.js": "./lib/esm/config.browser.js",
25
- "./lib/esm/remotes.js": "./lib/esm/remotes.browser.js",
26
- "./remotes.js": "./lib/esm/remotes.browser.js",
27
- "./lib/esm/docker.js": "./lib/esm/docker.browser.js",
28
- "./docker.js": "./lib/esm/docker.browser.js",
29
- "./lib/esm/aws.js": "./lib/esm/aws.browser.js"
30
- },
31
- "files": [
32
- "lib",
33
- "src",
34
- "src/nginx-template.conf",
35
- "!src/**/__tests__",
36
- "!lib/**/__tests__",
37
- "patches",
38
- "LICENSE"
39
- ],
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
- "engines": {
44
- "node": ">=18"
45
- },
46
- "scripts": {
47
- "clean": "shx rm -rf lib/*",
48
- "build": "yarn clean && yarn build-lib && yarn build-ui",
49
- "build-lib": "tsc -p tsconfig.json",
50
- "build-ui": "cd ../frontend && yarn build && cd ../node",
51
- "postbuild": "cp src/nginx-template.conf lib/esm/ && cp -r ../frontend/dist lib/ui",
52
- "test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
53
- "test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
54
- "test:integration": "node ../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit"
55
- },
56
- "devDependencies": {
57
- "@peerbit/test-lib": "^0.0.1",
58
- "@peerbit/test-utils": "2.0.32",
59
- "@types/tmp": "^0.2.3",
60
- "@types/yargs": "17.0.24",
61
- "aws-sdk": "^2.1259.0",
62
- "dotenv": "^16.1.4"
63
- },
64
- "dependencies": {
65
- "@dao-xyz/libp2p-noise": "^14.1.2",
66
- "axios": "^1.4.0",
67
- "chalk": "^5.3.0",
68
- "peerbit": "4.0.6",
69
- "tar-stream": "^3.1.6",
70
- "tmp": "^0.2.1",
71
- "tty-table": "^4.2.1",
72
- "yargs": "^17.7.2",
73
- "zlib": "^1.0.5"
74
- },
75
- "optionalDependencies": {
76
- "@aws-sdk/client-ec2": "^3.390.0",
77
- "@aws-sdk/client-route-53": "^3.391.0"
78
- },
79
- "gitHead": "eaabc8746086d126df86d4308ca1c4f65ac20f32"
2
+ "name": "@peerbit/server",
3
+ "version": "5.0.33-0691c73",
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": "./lib/esm/bin.js"
14
+ },
15
+ "module": "lib/esm/index.js",
16
+ "types": "lib/esm/index.d.ts",
17
+ "exports": {
18
+ "import": "./lib/esm/index.js"
19
+ },
20
+ "browser": {
21
+ "./lib/esm/server.js": "./lib/esm/server.browser.js",
22
+ "./server.js": "./lib/esm/server.browser.js",
23
+ "./lib/esm/config.js": "./lib/esm/config.browser.js",
24
+ "./config.js": "./lib/esm/config.browser.js",
25
+ "./lib/esm/remotes.js": "./lib/esm/remotes.browser.js",
26
+ "./remotes.js": "./lib/esm/remotes.browser.js",
27
+ "./lib/esm/docker.js": "./lib/esm/docker.browser.js",
28
+ "./docker.js": "./lib/esm/docker.browser.js",
29
+ "./lib/esm/aws.js": "./lib/esm/aws.browser.js"
30
+ },
31
+ "files": [
32
+ "lib",
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
+ "scripts": {
48
+ "clean": "shx rm -rf lib/*",
49
+ "build": "yarn clean && yarn build-lib && yarn build-ui",
50
+ "build-lib": "tsc -p tsconfig.json",
51
+ "build-ui": "cd ../frontend && yarn build && cd ../node",
52
+ "postbuild": "cp src/nginx-template.conf lib/esm/ && cp -r ../frontend/dist lib/ui",
53
+ "test": "aegir test"
54
+ },
55
+ "devDependencies": {
56
+ "@peerbit/test-lib": "0.0.1-0691c73",
57
+ "@peerbit/test-utils": "2.0.33-0691c73",
58
+ "@types/yargs": "17.0.24",
59
+ "aws-sdk": "^2.1259.0",
60
+ "dotenv": "^16.1.4",
61
+ "@types/tmp": "^0.2.3",
62
+ "@types/tar-stream": "^3.1.3",
63
+ "shx": "^0.3.4"
64
+ },
65
+ "dependencies": {
66
+ "@dao-xyz/libp2p-noise": "^14.1.2",
67
+ "axios": "^1.4.0",
68
+ "chalk": "^5.3.0",
69
+ "peerbit": "4.0.7-0691c73",
70
+ "yargs": "^17.7.2",
71
+ "tar-stream": "^3.1.7",
72
+ "tmp": "^0.2.1",
73
+ "tty-table": "^4.2.1"
74
+ },
75
+ "optionalDependencies": {
76
+ "@aws-sdk/client-ec2": "^3.390.0",
77
+ "@aws-sdk/client-route-53": "^3.391.0"
78
+ }
80
79
  }
package/src/cli.ts CHANGED
@@ -19,14 +19,14 @@ import {
19
19
  } from "./config.js";
20
20
  import chalk from "chalk";
21
21
  import { createClient, waitForDomain } from "./client.js";
22
- import { InstallDependency, StartProgram } from "./types.js";
22
+ import type { InstallDependency, StartProgram } from "./types.js";
23
23
  import { exit } from "process";
24
24
  import yargs from "yargs";
25
25
  import readline from "readline";
26
26
  import fs from "fs";
27
27
  import path from "path";
28
28
  import { toBase64 } from "@peerbit/crypto";
29
- import { DEFAULT_REMOTE_GROUP, RemoteObject, Remotes } from "./remotes.js";
29
+ import { DEFAULT_REMOTE_GROUP, type RemoteObject, Remotes } from "./remotes.js";
30
30
  import { peerIdFromString } from "@libp2p/peer-id";
31
31
  import { LOCAL_API_PORT } from "./routes.js";
32
32
  import { type PeerId } from "@libp2p/interface";
@@ -299,9 +299,9 @@ export const cli = async (args?: string[]) => {
299
299
  region: args.region,
300
300
  credentials: args.accessKeyId
301
301
  ? {
302
- accessKeyId: args.accessKeyId,
303
- secretAccessKey: args.secretAccessKey
304
- }
302
+ accessKeyId: args.accessKeyId,
303
+ secretAccessKey: args.secretAccessKey
304
+ }
305
305
  : undefined
306
306
  });
307
307
  await startCertbot(
@@ -385,12 +385,12 @@ export const cli = async (args?: string[]) => {
385
385
  handler: async (args) => {
386
386
  const accessGrant: PeerId[] =
387
387
  args.access?.length > 0
388
- ? args.access.map((x) => peerIdFromString(x))
388
+ ? args.access.map((x: any) => peerIdFromString(x))
389
389
  : [
390
- await (
391
- await getKeypair(args.directory)
392
- ).publicKey.toPeerId()
393
- ];
390
+ await (
391
+ await getKeypair(args.directory)
392
+ ).publicKey.toPeerId()
393
+ ];
394
394
  const nodes = await launchNodes({
395
395
  email: "marcus@dao.xyz",
396
396
  count: args.count,
@@ -401,8 +401,7 @@ export const cli = async (args?: string[]) => {
401
401
  });
402
402
 
403
403
  console.log(
404
- `Waiting for ${args.count} ${
405
- args.count > 1 ? "nodes" : "node"
404
+ `Waiting for ${args.count} ${args.count > 1 ? "nodes" : "node"
406
405
  } to spawn. This might take a few minutes. You can watch the progress in your AWS console.`
407
406
  );
408
407
  const twirlTimer = (function () {
@@ -432,8 +431,7 @@ export const cli = async (args?: string[]) => {
432
431
  } catch (error: any) {
433
432
  process.stdout.write("\r");
434
433
  console.error(
435
- `Error waiting for domain for ip: ${
436
- node.publicIp
434
+ `Error waiting for domain for ip: ${node.publicIp
437
435
  } to be available: ${error?.toString()}`
438
436
  );
439
437
  }
@@ -690,7 +688,7 @@ export const cli = async (args?: string[]) => {
690
688
 
691
689
  const selectedRemotes: RemoteObject[] = [];
692
690
  if (names.length > 0) {
693
- for (const [ix, name] of names.entries()) {
691
+ for (const [_ix, name] of names.entries()) {
694
692
  if (name === "localhost") {
695
693
  selectedRemotes.push({
696
694
  address: "http://localhost:" + LOCAL_API_PORT,
@@ -740,8 +738,8 @@ export const cli = async (args?: string[]) => {
740
738
  " ",
741
739
  remote.name.length
742
740
  ) +
743
- ": " +
744
- string
741
+ ": " +
742
+ string
745
743
  );
746
744
 
747
745
  apis.push({
@@ -944,8 +942,7 @@ export const cli = async (args?: string[]) => {
944
942
  } catch (error: any) {
945
943
  api.log(
946
944
  chalk.red(
947
- `Failed to drop ${
948
- args.address
945
+ `Failed to drop ${args.address
949
946
  }: ${error.toString()}`
950
947
  )
951
948
  );
package/src/client.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { InstallDependency, StartProgram } from "./types.js";
1
+ import type { InstallDependency, StartProgram } from "./types.js";
2
2
  import {
3
3
  ADDRESS_PATH,
4
4
  BOOTSTRAP_PATH,
@@ -13,19 +13,19 @@ import {
13
13
  REMOTE_API_PORT,
14
14
  PROGRAM_VARIANTS_PATH
15
15
  } from "./routes.js";
16
- import { Address } from "@peerbit/program";
17
16
  import { multiaddr } from "@multiformats/multiaddr";
18
- import { signRequest } from "./signes-request.js";
17
+ import { signRequest } from "./signed-request.js";
19
18
  import {
20
19
  Ed25519Keypair,
21
20
  Ed25519PublicKey,
22
- Identity,
21
+ type Identity,
23
22
  PublicSignKey,
24
23
  getPublicKeyFromPeerId
25
24
  } from "@peerbit/crypto";
26
- import { PeerId } from "@libp2p/interface";
25
+ import { type PeerId } from "@libp2p/interface";
27
26
  import { waitForResolved } from "@peerbit/time";
28
- import { RemoteOrigin } from "./remotes.js";
27
+ import type { RemoteOrigin } from "./remotes.js";
28
+ import type { Address } from "@peerbit/program";
29
29
 
30
30
  export const createClient = async (
31
31
  keypair: Identity<Ed25519PublicKey>,
@@ -77,22 +77,7 @@ export const createClient = async (
77
77
  }
78
78
  return resp;
79
79
  };
80
- const getBodyByStatus = <
81
- D extends { toString(): string },
82
- T extends { status: number; data: D }
83
- >(
84
- resp: T
85
- ): D | undefined => {
86
- if (resp.status === 404) {
87
- return;
88
- }
89
- if (resp.status == 200) {
90
- return resp.data;
91
- }
92
- throw new Error(
93
- typeof resp.data === "string" ? resp.data : resp.data.toString()
94
- );
95
- };
80
+
96
81
  const getId = async () =>
97
82
  throwIfNot200(
98
83
  await axiosInstance.get(endpoint + PEER_ID_PATH, {
@@ -123,15 +108,15 @@ export const createClient = async (
123
108
  allow: async (key: PublicSignKey | PeerId | string) => {
124
109
  const result = await axiosInstance.put(
125
110
  endpoint +
126
- TRUST_PATH +
127
- "/" +
128
- encodeURIComponent(
129
- typeof key === "string"
130
- ? key
131
- : key instanceof PublicSignKey
132
- ? key.hashcode()
133
- : getPublicKeyFromPeerId(key).hashcode()
134
- ),
111
+ TRUST_PATH +
112
+ "/" +
113
+ encodeURIComponent(
114
+ typeof key === "string"
115
+ ? key
116
+ : key instanceof PublicSignKey
117
+ ? key.hashcode()
118
+ : getPublicKeyFromPeerId(key).hashcode()
119
+ ),
135
120
  undefined,
136
121
  { validateStatus }
137
122
  );
@@ -143,13 +128,13 @@ export const createClient = async (
143
128
  deny: async (key: PublicSignKey | PeerId) => {
144
129
  const result = await axiosInstance.delete(
145
130
  endpoint +
146
- TRUST_PATH +
147
- "/" +
148
- encodeURIComponent(
149
- key instanceof PublicSignKey
150
- ? key.hashcode()
151
- : getPublicKeyFromPeerId(key).hashcode()
152
- ),
131
+ TRUST_PATH +
132
+ "/" +
133
+ encodeURIComponent(
134
+ key instanceof PublicSignKey
135
+ ? key.hashcode()
136
+ : getPublicKeyFromPeerId(key).hashcode()
137
+ ),
153
138
  { validateStatus }
154
139
  );
155
140
  if (result.status !== 200 && result.status !== 404) {
@@ -162,9 +147,9 @@ export const createClient = async (
162
147
  has: async (address: Address | string): Promise<boolean> => {
163
148
  const result = await axiosInstance.head(
164
149
  endpoint +
165
- PROGRAM_PATH +
166
- "/" +
167
- encodeURIComponent(address.toString()),
150
+ PROGRAM_PATH +
151
+ "/" +
152
+ encodeURIComponent(address.toString()),
168
153
  { validateStatus }
169
154
  );
170
155
  if (result.status !== 200 && result.status !== 404) {
@@ -190,9 +175,9 @@ export const createClient = async (
190
175
  throwIfNot200(
191
176
  await axiosInstance.delete(
192
177
  endpoint +
193
- PROGRAM_PATH +
194
- "/" +
195
- encodeURIComponent(address.toString()),
178
+ PROGRAM_PATH +
179
+ "/" +
180
+ encodeURIComponent(address.toString()),
196
181
  {
197
182
  validateStatus
198
183
  }
@@ -204,10 +189,10 @@ export const createClient = async (
204
189
  throwIfNot200(
205
190
  await axiosInstance.delete(
206
191
  endpoint +
207
- PROGRAM_PATH +
208
- "/" +
209
- encodeURIComponent(address.toString()) +
210
- "?delete=true",
192
+ PROGRAM_PATH +
193
+ "/" +
194
+ encodeURIComponent(address.toString()) +
195
+ "?delete=true",
211
196
  {
212
197
  validateStatus
213
198
  }
package/src/config.ts CHANGED
@@ -6,7 +6,7 @@ import { Duplex } from "stream"; // Native Node Module
6
6
  import { Ed25519Keypair } from "@peerbit/crypto";
7
7
  import { dirname } from "path";
8
8
 
9
- const bufferToStream = (myBuffer) => {
9
+ const bufferToStream = (myBuffer: any) => {
10
10
  const tmp = new Duplex();
11
11
  tmp.push(myBuffer);
12
12
  tmp.push(null);
@@ -84,8 +84,8 @@ export const getPackageName = async (
84
84
  const extract = tar.extract();
85
85
  let data = "";
86
86
 
87
- extract.on("entry", function (header, stream, cb) {
88
- stream.on("data", function (chunk) {
87
+ extract.on("entry", function (header: any, stream: any, cb: any) {
88
+ stream.on("data", function (chunk: any) {
89
89
  if (header.name == "package/package.json") data += chunk;
90
90
  });
91
91
 
@@ -105,7 +105,7 @@ export const getPackageName = async (
105
105
  }
106
106
  });
107
107
 
108
- extract.on("error", (e) => {
108
+ extract.on("error", (e: any) => {
109
109
  reject(e);
110
110
  });
111
111
 
@@ -120,4 +120,4 @@ export const getPackageName = async (
120
120
  });
121
121
  };
122
122
 
123
- export class NotFoundError extends Error {}
123
+ export class NotFoundError extends Error { }
package/src/docker.ts CHANGED
@@ -6,7 +6,7 @@ export const installDocker = async () => {
6
6
  // check if docker is installed
7
7
  const dockerExist = async () => {
8
8
  try {
9
- const out = await new Promise((resolve, reject) => {
9
+ await new Promise((resolve, reject) => {
10
10
  exec("docker --version", (error, stdout, stderr) => {
11
11
  if (error || stderr) {
12
12
  reject();
@@ -49,7 +49,7 @@ export const startContainer = async (cmd: string, errorMessage?: string) => {
49
49
  if (error) {
50
50
  reject(
51
51
  (errorMessage || "Failed to start docker container: ") +
52
- error.message
52
+ error.message
53
53
  );
54
54
  }
55
55
  resolve(stdout);
package/src/domain.ts CHANGED
@@ -2,7 +2,7 @@ import { waitFor } from "@peerbit/time";
2
2
 
3
3
  const isNode = typeof window === "undefined";
4
4
 
5
- const validateEmail = (email) => {
5
+ const validateEmail = (email: any) => {
6
6
  return String(email)
7
7
  .toLowerCase()
8
8
  .match(
@@ -55,7 +55,6 @@ const createConfig = async (
55
55
  file = file.replaceAll("%DOMAIN%", domain);
56
56
 
57
57
  const fs = await import("fs");
58
- const path = await import("path");
59
58
 
60
59
  fs.mkdir(outputPath, { recursive: true }, (err) => {
61
60
  if (err) throw err;
package/src/peerbit.ts CHANGED
@@ -2,7 +2,7 @@ import { DirectBlock } from "@peerbit/blocks";
2
2
  import { DirectSub } from "@peerbit/pubsub";
3
3
  import { Peerbit } from "peerbit";
4
4
  import path from "path";
5
- import { PeerId } from "@libp2p/interface";
5
+ import { type PeerId } from "@libp2p/interface";
6
6
 
7
7
  export const LIBP2P_LISTEN_PORT = 8001;
8
8
  export const create = (properties: {
@@ -23,14 +23,13 @@ export const create = (properties: {
23
23
  addresses: {
24
24
  announce: properties.domain
25
25
  ? [
26
- `/dns4/${properties.domain}/tcp/4002`,
27
- `/dns4/${properties.domain}/tcp/4003/wss`
28
- ]
26
+ `/dns4/${properties.domain}/tcp/4002`,
27
+ `/dns4/${properties.domain}/tcp/4003/wss`
28
+ ]
29
29
  : undefined,
30
30
  listen: [
31
31
  `/ip4/127.0.0.1/tcp/${listenPort}`,
32
- `/ip4/127.0.0.1/tcp/${
33
- listenPort !== 0 ? listenPort + 1 : listenPort
32
+ `/ip4/127.0.0.1/tcp/${listenPort !== 0 ? listenPort + 1 : listenPort
34
33
  }/ws`
35
34
  ]
36
35
  },
package/src/server.ts CHANGED
@@ -1,20 +1,18 @@
1
1
  import http from "http";
2
2
  import {
3
3
  fromBase64,
4
- getKeypairFromPeerId,
5
4
  getPublicKeyFromPeerId
6
5
  } from "@peerbit/crypto";
7
6
  import { deserialize } from "@dao-xyz/borsh";
8
7
  import {
9
8
  Program,
10
- ProgramClient,
9
+ type ProgramClient,
11
10
  getProgramFromVariant,
12
11
  getProgramFromVariants
13
12
  } from "@peerbit/program";
14
13
  import { waitFor } from "@peerbit/time";
15
14
  import { v4 as uuid } from "uuid";
16
15
  import {
17
- getHomeConfigDir,
18
16
  getNodePath,
19
17
  getKeypair,
20
18
  getTrustPath
@@ -23,7 +21,7 @@ import { setMaxListeners } from "events";
23
21
  import { create } from "./peerbit.js";
24
22
  import { Peerbit } from "peerbit";
25
23
  import { getSchema } from "@dao-xyz/borsh";
26
- import {
24
+ import type {
27
25
  InstallDependency,
28
26
  StartByBase64,
29
27
  StartByVariant,
@@ -54,7 +52,7 @@ import { fileURLToPath } from "url";
54
52
  import { Level } from "level";
55
53
  import { MemoryLevel } from "memory-level";
56
54
  import { Trust } from "./trust.js";
57
- import { getBody, verifyRequest } from "./signes-request.js";
55
+ import { getBody, verifyRequest } from "./signed-request.js";
58
56
  import { peerIdFromString } from "@libp2p/peer-id";
59
57
 
60
58
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -109,9 +107,9 @@ export const startServerWithNode = async (properties: {
109
107
  const session = new Session(
110
108
  sessionDirectory
111
109
  ? new Level<string, Uint8Array>(sessionDirectory, {
112
- valueEncoding: "view",
113
- keyEncoding: "utf-8"
114
- })
110
+ valueEncoding: "view",
111
+ keyEncoding: "utf-8"
112
+ })
115
113
  : new MemoryLevel({ valueEncoding: "view", keyEncoding: "utf-8" })
116
114
  );
117
115
  if (!properties.newSession) {
@@ -161,9 +159,15 @@ export const startServerWithNode = async (properties: {
161
159
  exit();
162
160
  });
163
161
  });
162
+
163
+ process.on("uncaughtException", (err) => {
164
+ console.error("Uncaught exception", err);
165
+ });
166
+
164
167
  process.on("exit", async () => {
165
168
  if (server.listening) {
166
169
  console.log("Shutting down node (exit)");
170
+
167
171
  await stopAndWait(server);
168
172
  await controller.stop();
169
173
  }
@@ -291,7 +295,7 @@ export const startApiServer = async (
291
295
  try {
292
296
  body =
293
297
  req.url.startsWith(PEER_ID_PATH) ||
294
- req.url.startsWith(ADDRESS_PATH)
298
+ req.url.startsWith(ADDRESS_PATH)
295
299
  ? await getBody(req)
296
300
  : await getVerifiedBody(req);
297
301
  } catch (error: any) {
@@ -309,7 +313,7 @@ export const startApiServer = async (
309
313
  switch (req.method) {
310
314
  case "GET":
311
315
  try {
312
- const ref = (client as Peerbit).handler?.items?.keys() || [];
316
+ const ref: any = (client as Peerbit).handler?.items?.keys() || [];
313
317
  const keys = JSON.stringify([...ref]);
314
318
  res.setHeader("Content-Type", "application/json");
315
319
  res.writeHead(200);
@@ -420,7 +424,7 @@ export const startApiServer = async (
420
424
  res.writeHead(400);
421
425
  res.end(
422
426
  "Missing program with variant: " +
423
- (startArguments as StartByVariant).variant
427
+ (startArguments as StartByVariant).variant
424
428
  );
425
429
  return;
426
430
  }
@@ -443,6 +447,7 @@ export const startApiServer = async (
443
447
  res.end(program.address.toString());
444
448
  })
445
449
  .catch((error) => {
450
+ console.error(error);
446
451
  res.writeHead(400);
447
452
  res.end("Failed to open program: " + error.toString());
448
453
  });
@@ -509,9 +514,9 @@ export const startApiServer = async (
509
514
  res.writeHead(400);
510
515
  res.end(
511
516
  "Failed to install library: " +
512
- packageName +
513
- ". " +
514
- error.toString()
517
+ packageName +
518
+ ". " +
519
+ error.toString()
515
520
  );
516
521
  clear?.();
517
522
  return;
@@ -1,5 +1,5 @@
1
1
  import {
2
- Identity,
2
+ type Identity,
3
3
  PublicSignKey,
4
4
  SignatureWithKey,
5
5
  fromBase64,
@@ -1 +0,0 @@
1
- {"version":3,"file":"signes-request.js","sourceRoot":"","sources":["../../src/signes-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,MAAM,EAEN,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGtE,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC/B,OAA+B,EAC/B,MAAc,EACd,IAAY,EACZ,IAAwB,EACxB,OAAmC,EAClC,EAAE;IACH,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxE,MAAM,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;IACjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,CAAC,IAAI,EAAE,CAAC;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