@peerbit/server 5.0.33-efee9d3 → 5.0.34-2bc15a6

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 (170) hide show
  1. package/dist/src/aws.d.ts.map +1 -0
  2. package/{lib/esm → dist/src}/aws.js +43 -45
  3. package/dist/src/aws.js.map +1 -0
  4. package/{lib/esm → dist/src}/bin.js.map +1 -1
  5. package/dist/src/cli.d.ts.map +1 -0
  6. package/{lib/esm → dist/src}/cli.js +106 -107
  7. package/dist/src/cli.js.map +1 -0
  8. package/{lib/esm → dist/src}/client.d.ts +3 -3
  9. package/dist/src/client.d.ts.map +1 -0
  10. package/{lib/esm → dist/src}/client.js +28 -28
  11. package/dist/src/client.js.map +1 -0
  12. package/dist/src/config.d.ts.map +1 -0
  13. package/{lib/esm → dist/src}/config.js +6 -6
  14. package/dist/src/config.js.map +1 -0
  15. package/{lib/esm → dist/src}/docker.js +1 -1
  16. package/{lib/esm → dist/src}/docker.js.map +1 -1
  17. package/{lib/esm → dist/src}/domain.d.ts +2 -9
  18. package/dist/src/domain.d.ts.map +1 -0
  19. package/{lib/esm → dist/src}/domain.js +6 -12
  20. package/dist/src/domain.js.map +1 -0
  21. package/{lib/esm → dist/src}/peerbit.d.ts +1 -1
  22. package/dist/src/peerbit.d.ts.map +1 -0
  23. package/{lib/esm → dist/src}/peerbit.js +10 -10
  24. package/dist/src/peerbit.js.map +1 -0
  25. package/{lib/esm → dist/src}/remotes.d.ts +2 -2
  26. package/{lib/esm → dist/src}/remotes.js +1 -1
  27. package/{lib/esm → dist/src}/server.d.ts +2 -3
  28. package/dist/src/server.d.ts.map +1 -0
  29. package/{lib/esm → dist/src}/server.js +25 -27
  30. package/dist/src/server.js.map +1 -0
  31. package/{lib/esm → dist/src}/session.d.ts +1 -2
  32. package/dist/src/session.d.ts.map +1 -0
  33. package/{lib/esm → dist/src}/session.js +2 -3
  34. package/dist/src/session.js.map +1 -0
  35. package/{lib/esm → dist/src}/signed-request.d.ts +2 -3
  36. package/dist/src/signed-request.d.ts.map +1 -0
  37. package/{lib/esm → dist/src}/signed-request.js +2 -3
  38. package/dist/src/signed-request.js.map +1 -0
  39. package/dist/test/api.spec.d.ts +2 -0
  40. package/dist/test/api.spec.d.ts.map +1 -0
  41. package/dist/test/api.spec.js +223 -0
  42. package/dist/test/api.spec.js.map +1 -0
  43. package/dist/test/cli.spec.d.ts +2 -0
  44. package/dist/test/cli.spec.d.ts.map +1 -0
  45. package/dist/test/cli.spec.js +264 -0
  46. package/dist/test/cli.spec.js.map +1 -0
  47. package/dist/test/client.spec.d.ts +2 -0
  48. package/dist/test/client.spec.d.ts.map +1 -0
  49. package/dist/test/client.spec.js +23 -0
  50. package/dist/test/client.spec.js.map +1 -0
  51. package/dist/test/config.spec.d.ts +2 -0
  52. package/dist/test/config.spec.d.ts.map +1 -0
  53. package/dist/test/config.spec.js +12 -0
  54. package/dist/test/config.spec.js.map +1 -0
  55. package/dist/test/domain.integration.spec.d.ts +2 -0
  56. package/dist/test/domain.integration.spec.d.ts.map +1 -0
  57. package/dist/test/domain.integration.spec.js +101 -0
  58. package/dist/test/domain.integration.spec.js.map +1 -0
  59. package/dist/test/launch.spec.d.ts +1 -0
  60. package/dist/test/launch.spec.d.ts.map +1 -0
  61. package/dist/test/launch.spec.js +23 -0
  62. package/dist/test/launch.spec.js.map +1 -0
  63. package/dist/test/signed-request.spec.d.ts +2 -0
  64. package/dist/test/signed-request.spec.d.ts.map +1 -0
  65. package/dist/test/signed-request.spec.js +35 -0
  66. package/dist/test/signed-request.spec.js.map +1 -0
  67. package/dist/test/utils.d.ts +3 -0
  68. package/dist/test/utils.d.ts.map +1 -0
  69. package/dist/test/utils.js +6 -0
  70. package/dist/test/utils.js.map +1 -0
  71. package/dist/tsconfig.tsbuildinfo +1 -0
  72. package/dist/ui/assets/index-fCy8gbsO.js +128 -0
  73. package/dist/ui/assets/index-q5H34Jar.js +6 -0
  74. package/{lib → dist}/ui/index.html +3 -3
  75. package/package.json +33 -20
  76. package/src/aws.ts +57 -58
  77. package/src/bin.ts +1 -0
  78. package/src/cli.ts +158 -152
  79. package/src/client.ts +88 -88
  80. package/src/config.ts +9 -9
  81. package/src/docker.ts +2 -2
  82. package/src/domain.ts +15 -21
  83. package/src/peerbit.ts +14 -13
  84. package/src/remotes.ts +2 -2
  85. package/src/server.ts +62 -70
  86. package/src/session.ts +7 -7
  87. package/src/signed-request.ts +7 -7
  88. package/src/trust.ts +1 -1
  89. package/lib/esm/aws.d.ts.map +0 -1
  90. package/lib/esm/aws.js.map +0 -1
  91. package/lib/esm/cli.d.ts.map +0 -1
  92. package/lib/esm/cli.js.map +0 -1
  93. package/lib/esm/client.d.ts.map +0 -1
  94. package/lib/esm/client.js.map +0 -1
  95. package/lib/esm/config.d.ts.map +0 -1
  96. package/lib/esm/config.js.map +0 -1
  97. package/lib/esm/domain.d.ts.map +0 -1
  98. package/lib/esm/domain.js.map +0 -1
  99. package/lib/esm/peerbit.d.ts.map +0 -1
  100. package/lib/esm/peerbit.js.map +0 -1
  101. package/lib/esm/server.d.ts.map +0 -1
  102. package/lib/esm/server.js.map +0 -1
  103. package/lib/esm/session.d.ts.map +0 -1
  104. package/lib/esm/session.js.map +0 -1
  105. package/lib/esm/signed-request.d.ts.map +0 -1
  106. package/lib/esm/signed-request.js.map +0 -1
  107. package/lib/tsconfig.tsbuildinfo +0 -1
  108. package/lib/ui/assets/index-BC4oCu-g.js +0 -6
  109. package/lib/ui/assets/index-CvfEshgH.js +0 -79
  110. package/lib/ui/assets/manifest-DSoGU8T2.json +0 -25
  111. /package/{lib/esm → dist}/nginx-template.conf +0 -0
  112. /package/{lib/esm → dist/src}/aws.browser.d.ts +0 -0
  113. /package/{lib/esm → dist/src}/aws.browser.d.ts.map +0 -0
  114. /package/{lib/esm → dist/src}/aws.browser.js +0 -0
  115. /package/{lib/esm → dist/src}/aws.browser.js.map +0 -0
  116. /package/{lib/esm → dist/src}/aws.d.ts +0 -0
  117. /package/{lib/esm → dist/src}/bin.d.ts +0 -0
  118. /package/{lib/esm → dist/src}/bin.d.ts.map +0 -0
  119. /package/{lib/esm → dist/src}/bin.js +0 -0
  120. /package/{lib/esm → dist/src}/cli.d.ts +0 -0
  121. /package/{lib/esm → dist/src}/config.browser.d.ts +0 -0
  122. /package/{lib/esm → dist/src}/config.browser.d.ts.map +0 -0
  123. /package/{lib/esm → dist/src}/config.browser.js +0 -0
  124. /package/{lib/esm → dist/src}/config.browser.js.map +0 -0
  125. /package/{lib/esm → dist/src}/config.d.ts +0 -0
  126. /package/{lib/esm → dist/src}/docker.browser.d.ts +0 -0
  127. /package/{lib/esm → dist/src}/docker.browser.d.ts.map +0 -0
  128. /package/{lib/esm → dist/src}/docker.browser.js +0 -0
  129. /package/{lib/esm → dist/src}/docker.browser.js.map +0 -0
  130. /package/{lib/esm → dist/src}/docker.d.ts +0 -0
  131. /package/{lib/esm → dist/src}/docker.d.ts.map +0 -0
  132. /package/{lib/esm → dist/src}/index.d.ts +0 -0
  133. /package/{lib/esm → dist/src}/index.d.ts.map +0 -0
  134. /package/{lib/esm → dist/src}/index.js +0 -0
  135. /package/{lib/esm → dist/src}/index.js.map +0 -0
  136. /package/{lib/esm → dist/src}/remotes.browser.d.ts +0 -0
  137. /package/{lib/esm → dist/src}/remotes.browser.d.ts.map +0 -0
  138. /package/{lib/esm → dist/src}/remotes.browser.js +0 -0
  139. /package/{lib/esm → dist/src}/remotes.browser.js.map +0 -0
  140. /package/{lib/esm → dist/src}/remotes.d.ts.map +0 -0
  141. /package/{lib/esm → dist/src}/remotes.js.map +0 -0
  142. /package/{lib/esm → dist/src}/routes.d.ts +0 -0
  143. /package/{lib/esm → dist/src}/routes.d.ts.map +0 -0
  144. /package/{lib/esm → dist/src}/routes.js +0 -0
  145. /package/{lib/esm → dist/src}/routes.js.map +0 -0
  146. /package/{lib/esm → dist/src}/server.browser.d.ts +0 -0
  147. /package/{lib/esm → dist/src}/server.browser.d.ts.map +0 -0
  148. /package/{lib/esm → dist/src}/server.browser.js +0 -0
  149. /package/{lib/esm → dist/src}/server.browser.js.map +0 -0
  150. /package/{lib/esm → dist/src}/trust.browser.d.ts +0 -0
  151. /package/{lib/esm → dist/src}/trust.browser.d.ts.map +0 -0
  152. /package/{lib/esm → dist/src}/trust.browser.js +0 -0
  153. /package/{lib/esm → dist/src}/trust.browser.js.map +0 -0
  154. /package/{lib/esm → dist/src}/trust.d.ts +0 -0
  155. /package/{lib/esm → dist/src}/trust.d.ts.map +0 -0
  156. /package/{lib/esm → dist/src}/trust.js +0 -0
  157. /package/{lib/esm → dist/src}/trust.js.map +0 -0
  158. /package/{lib/esm → dist/src}/types.d.ts +0 -0
  159. /package/{lib/esm → dist/src}/types.d.ts.map +0 -0
  160. /package/{lib/esm → dist/src}/types.js +0 -0
  161. /package/{lib/esm → dist/src}/types.js.map +0 -0
  162. /package/{lib → dist}/ui/android-chrome-192x192.png +0 -0
  163. /package/{lib → dist}/ui/android-chrome-512x512.png +0 -0
  164. /package/{lib → dist}/ui/assets/favicon-BYZpRdSr.ico +0 -0
  165. /package/{lib → dist}/ui/assets/index-BDBx6C_I.css +0 -0
  166. /package/{lib → dist}/ui/favicon-16x16.png +0 -0
  167. /package/{lib → dist}/ui/favicon-32x32.png +0 -0
  168. /package/{lib → dist}/ui/favicon.ico +0 -0
  169. /package/{lib → dist}/ui/manifest.json +0 -0
  170. /package/{lib → dist}/ui/robots.txt +0 -0
package/src/client.ts CHANGED
@@ -1,37 +1,37 @@
1
- import type { InstallDependency, StartProgram } from "./types.js";
1
+ import { type PeerId } from "@libp2p/interface";
2
+ import { multiaddr } from "@multiformats/multiaddr";
3
+ import {
4
+ Ed25519Keypair,
5
+ type Ed25519PublicKey,
6
+ type Identity,
7
+ PublicSignKey,
8
+ getPublicKeyFromPeerId,
9
+ } from "@peerbit/crypto";
10
+ import type { Address } from "@peerbit/program";
11
+ import { waitForResolved } from "@peerbit/time";
12
+ import type { RemoteOrigin } from "./remotes.js";
2
13
  import {
3
14
  ADDRESS_PATH,
4
15
  BOOTSTRAP_PATH,
5
- STOP_PATH,
6
16
  INSTALL_PATH,
7
17
  LOCAL_API_PORT,
8
18
  PEER_ID_PATH,
9
19
  PROGRAMS_PATH,
10
20
  PROGRAM_PATH,
21
+ PROGRAM_VARIANTS_PATH,
22
+ REMOTE_API_PORT,
11
23
  RESTART_PATH,
24
+ STOP_PATH,
12
25
  TRUST_PATH,
13
- REMOTE_API_PORT,
14
- PROGRAM_VARIANTS_PATH
15
26
  } from "./routes.js";
16
- import { multiaddr } from "@multiformats/multiaddr";
17
27
  import { signRequest } from "./signed-request.js";
18
- import {
19
- Ed25519Keypair,
20
- Ed25519PublicKey,
21
- type Identity,
22
- PublicSignKey,
23
- getPublicKeyFromPeerId
24
- } from "@peerbit/crypto";
25
- import { type PeerId } from "@libp2p/interface";
26
- import { waitForResolved } from "@peerbit/time";
27
- import type { RemoteOrigin } from "./remotes.js";
28
- import type { Address } from "@peerbit/program";
28
+ import type { InstallDependency, StartProgram } from "./types.js";
29
29
 
30
30
  export const createClient = async (
31
31
  keypair: Identity<Ed25519PublicKey>,
32
32
  remote: { address: string; origin?: RemoteOrigin } = {
33
- address: "http://localhost:" + LOCAL_API_PORT
34
- }
33
+ address: "http://localhost:" + LOCAL_API_PORT,
34
+ },
35
35
  ) => {
36
36
  // Add missing protocol
37
37
  let endpoint = remote.address;
@@ -62,13 +62,13 @@ export const createClient = async (
62
62
  config.method!,
63
63
  url.pathname + url.search,
64
64
  config.data,
65
- keypair
65
+ keypair,
66
66
  );
67
67
  return config;
68
68
  });
69
69
 
70
70
  const validateStatus = (status: number) => {
71
- return (status >= 200 && status < 300) || status == 404;
71
+ return (status >= 200 && status < 300) || status === 404;
72
72
  };
73
73
 
74
74
  const throwIfNot200 = (resp: { status: number; data: any }) => {
@@ -82,43 +82,43 @@ export const createClient = async (
82
82
  throwIfNot200(
83
83
  await axiosInstance.get(endpoint + PEER_ID_PATH, {
84
84
  validateStatus,
85
- timeout: 5000
86
- })
85
+ timeout: 5000,
86
+ }),
87
87
  ).data;
88
88
 
89
89
  return {
90
90
  peer: {
91
91
  id: {
92
- get: getId
92
+ get: getId,
93
93
  },
94
94
  addresses: {
95
95
  get: async () => {
96
96
  return (
97
97
  throwIfNot200(
98
98
  await axiosInstance.get(endpoint + ADDRESS_PATH, {
99
- validateStatus
100
- })
99
+ validateStatus,
100
+ }),
101
101
  ).data as string[]
102
102
  ).map((x) => multiaddr(x));
103
- }
104
- }
103
+ },
104
+ },
105
105
  },
106
106
 
107
107
  access: {
108
108
  allow: async (key: PublicSignKey | PeerId | string) => {
109
109
  const result = await axiosInstance.put(
110
110
  endpoint +
111
- TRUST_PATH +
112
- "/" +
113
- encodeURIComponent(
114
- typeof key === "string"
115
- ? key
116
- : key instanceof PublicSignKey
117
- ? key.hashcode()
118
- : getPublicKeyFromPeerId(key).hashcode()
119
- ),
111
+ TRUST_PATH +
112
+ "/" +
113
+ encodeURIComponent(
114
+ typeof key === "string"
115
+ ? key
116
+ : key instanceof PublicSignKey
117
+ ? key.hashcode()
118
+ : getPublicKeyFromPeerId(key).hashcode(),
119
+ ),
120
120
  undefined,
121
- { validateStatus }
121
+ { validateStatus },
122
122
  );
123
123
  if (result.status !== 200 && result.status !== 404) {
124
124
  throw new Error(result.data);
@@ -128,29 +128,29 @@ export const createClient = async (
128
128
  deny: async (key: PublicSignKey | PeerId) => {
129
129
  const result = await axiosInstance.delete(
130
130
  endpoint +
131
- TRUST_PATH +
132
- "/" +
133
- encodeURIComponent(
134
- key instanceof PublicSignKey
135
- ? key.hashcode()
136
- : getPublicKeyFromPeerId(key).hashcode()
137
- ),
138
- { validateStatus }
131
+ TRUST_PATH +
132
+ "/" +
133
+ encodeURIComponent(
134
+ key instanceof PublicSignKey
135
+ ? key.hashcode()
136
+ : getPublicKeyFromPeerId(key).hashcode(),
137
+ ),
138
+ { validateStatus },
139
139
  );
140
140
  if (result.status !== 200 && result.status !== 404) {
141
141
  throw new Error(result.data);
142
142
  }
143
143
  return result.status === 200 ? true : false;
144
- }
144
+ },
145
145
  },
146
146
  program: {
147
147
  has: async (address: Address | string): Promise<boolean> => {
148
148
  const result = await axiosInstance.head(
149
149
  endpoint +
150
- PROGRAM_PATH +
151
- "/" +
152
- encodeURIComponent(address.toString()),
153
- { validateStatus }
150
+ PROGRAM_PATH +
151
+ "/" +
152
+ encodeURIComponent(address.toString()),
153
+ { validateStatus },
154
154
  );
155
155
  if (result.status !== 200 && result.status !== 404) {
156
156
  throw new Error(result.data);
@@ -164,9 +164,9 @@ export const createClient = async (
164
164
  endpoint + PROGRAM_PATH,
165
165
  JSON.stringify(program),
166
166
  {
167
- validateStatus
168
- }
169
- )
167
+ validateStatus,
168
+ },
169
+ ),
170
170
  );
171
171
  return resp.data as string;
172
172
  },
@@ -175,13 +175,13 @@ export const createClient = async (
175
175
  throwIfNot200(
176
176
  await axiosInstance.delete(
177
177
  endpoint +
178
- PROGRAM_PATH +
179
- "/" +
180
- encodeURIComponent(address.toString()),
178
+ PROGRAM_PATH +
179
+ "/" +
180
+ encodeURIComponent(address.toString()),
181
181
  {
182
- validateStatus
183
- }
184
- )
182
+ validateStatus,
183
+ },
184
+ ),
185
185
  );
186
186
  },
187
187
 
@@ -189,33 +189,33 @@ export const createClient = async (
189
189
  throwIfNot200(
190
190
  await axiosInstance.delete(
191
191
  endpoint +
192
- PROGRAM_PATH +
193
- "/" +
194
- encodeURIComponent(address.toString()) +
195
- "?delete=true",
192
+ PROGRAM_PATH +
193
+ "/" +
194
+ encodeURIComponent(address.toString()) +
195
+ "?delete=true",
196
196
  {
197
- validateStatus
198
- }
199
- )
197
+ validateStatus,
198
+ },
199
+ ),
200
200
  );
201
201
  },
202
202
 
203
203
  list: async (): Promise<string[]> => {
204
204
  const resp = throwIfNot200(
205
205
  await axiosInstance.get(endpoint + PROGRAMS_PATH, {
206
- validateStatus
207
- })
206
+ validateStatus,
207
+ }),
208
208
  );
209
209
  return resp.data as string[];
210
210
  },
211
211
  variants: async (): Promise<string[]> => {
212
212
  const resp = throwIfNot200(
213
213
  await axiosInstance.get(endpoint + PROGRAM_VARIANTS_PATH, {
214
- validateStatus
215
- })
214
+ validateStatus,
215
+ }),
216
216
  );
217
217
  return resp.data as string[];
218
- }
218
+ },
219
219
  },
220
220
  dependency: {
221
221
  install: async (instruction: InstallDependency): Promise<string[]> => {
@@ -223,39 +223,39 @@ export const createClient = async (
223
223
  endpoint + INSTALL_PATH,
224
224
  JSON.stringify(instruction),
225
225
  {
226
- validateStatus
227
- }
226
+ validateStatus,
227
+ },
228
228
  );
229
229
  if (resp.status !== 200) {
230
230
  throw new Error(
231
- typeof resp.data === "string" ? resp.data : resp.data.toString()
231
+ typeof resp.data === "string" ? resp.data : resp.data.toString(),
232
232
  );
233
233
  }
234
234
  return resp.data;
235
- }
235
+ },
236
236
  },
237
237
  network: {
238
238
  bootstrap: async (): Promise<void> => {
239
239
  throwIfNot200(
240
240
  await axiosInstance.post(endpoint + BOOTSTRAP_PATH, undefined, {
241
- validateStatus
242
- })
241
+ validateStatus,
242
+ }),
243
243
  );
244
- }
244
+ },
245
245
  },
246
246
 
247
247
  restart: async (): Promise<void> => {
248
248
  throwIfNot200(
249
249
  await axiosInstance.post(endpoint + RESTART_PATH, undefined, {
250
- validateStatus
251
- })
250
+ validateStatus,
251
+ }),
252
252
  );
253
253
  },
254
254
  stop: async (): Promise<void> => {
255
255
  throwIfNot200(
256
256
  await axiosInstance.post(endpoint + STOP_PATH, undefined, {
257
- validateStatus
258
- })
257
+ validateStatus,
258
+ }),
259
259
  );
260
260
  },
261
261
  terminate: async () => {
@@ -263,19 +263,19 @@ export const createClient = async (
263
263
  if (remote.origin?.type === "aws") {
264
264
  await terminateNode({
265
265
  instanceId: remote.origin.instanceId,
266
- region: remote.origin.region
266
+ region: remote.origin.region,
267
267
  });
268
268
  }
269
- }
269
+ },
270
270
  };
271
271
  };
272
272
 
273
273
  export const waitForDomain = async (
274
274
  ip: string,
275
- timeout: number = 5 * 60 * 1000
275
+ timeout: number = 5 * 60 * 1000,
276
276
  ): Promise<string> => {
277
277
  const c = await createClient(await Ed25519Keypair.create(), {
278
- address: "http://" + ip + ":" + LOCAL_API_PORT
278
+ address: "http://" + ip + ":" + LOCAL_API_PORT,
279
279
  });
280
280
  const result = await waitForResolved(
281
281
  async () => {
@@ -288,8 +288,8 @@ export const waitForDomain = async (
288
288
  },
289
289
  {
290
290
  delayInterval: 5000,
291
- timeout
292
- }
291
+ timeout,
292
+ },
293
293
  );
294
294
  if (!result) {
295
295
  throw new Error("Failed to resolve domain");
package/src/config.ts CHANGED
@@ -1,10 +1,10 @@
1
- import path from "path";
2
- import os from "os";
3
- import fs from "fs";
1
+ // Native Node Module
4
2
  import { deserialize, serialize } from "@dao-xyz/borsh";
5
- import { Duplex } from "stream"; // Native Node Module
6
3
  import { Ed25519Keypair } from "@peerbit/crypto";
7
- import { dirname } from "path";
4
+ import fs from "fs";
5
+ import os from "os";
6
+ import path, { dirname } from "path";
7
+ import { Duplex } from "stream";
8
8
 
9
9
  const bufferToStream = (myBuffer: any) => {
10
10
  const tmp = new Duplex();
@@ -39,7 +39,7 @@ const getKeysPath = (configDir: string): string => {
39
39
  };
40
40
 
41
41
  export const getKeypair = async (
42
- configDir: string
42
+ configDir: string,
43
43
  ): Promise<Ed25519Keypair> => {
44
44
  const keypath = getKeysPath(configDir);
45
45
  if (!fs.existsSync(keypath)) {
@@ -69,7 +69,7 @@ export const checkExistPath = async (path: string) => {
69
69
  };
70
70
 
71
71
  export const getPackageName = async (
72
- path: string | Uint8Array
72
+ path: string | Uint8Array,
73
73
  ): Promise<string> => {
74
74
  const tar = await import("tar-stream");
75
75
  const zlib = await import("zlib");
@@ -86,7 +86,7 @@ export const getPackageName = async (
86
86
 
87
87
  extract.on("entry", function (header: any, stream: any, cb: any) {
88
88
  stream.on("data", function (chunk: any) {
89
- if (header.name == "package/package.json") data += chunk;
89
+ if (header.name === "package/package.json") data += chunk;
90
90
  });
91
91
 
92
92
  stream.on("end", function () {
@@ -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
@@ -33,7 +33,7 @@ export const installDocker = async () => {
33
33
  try {
34
34
  await waitFor(() => dockerExist(), {
35
35
  timeout: 30 * 1000,
36
- delayInterval: 1000
36
+ delayInterval: 1000,
37
37
  });
38
38
  } catch (error) {
39
39
  throw new Error("Failed to install docker");
@@ -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
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  import { waitFor } from "@peerbit/time";
2
3
 
3
4
  const isNode = typeof window === "undefined";
@@ -6,18 +7,18 @@ const validateEmail = (email: any) => {
6
7
  return String(email)
7
8
  .toLowerCase()
8
9
  .match(
9
- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
10
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
10
11
  );
11
12
  };
12
13
 
13
14
  const getConfigFileTemplate = async (): Promise<string> => {
14
15
  const url = await import("url");
15
- const __filename = url.fileURLToPath(import.meta.url);
16
+ const filename = url.fileURLToPath(import.meta.url);
16
17
  const fs = await import("fs");
17
18
  const path = await import("path");
18
19
  const file = fs.readFileSync(
19
- path.join(__filename, "../nginx-template.conf"),
20
- "utf-8"
20
+ path.join(filename, "../nginx-template.conf"),
21
+ "utf-8",
21
22
  );
22
23
  return file;
23
24
  };
@@ -45,7 +46,7 @@ const getNginxConfigPath = async (folder: string) => {
45
46
 
46
47
  const createConfig = async (
47
48
  outputPath: string,
48
- domain: string
49
+ domain: string,
49
50
  ): Promise<{ domain: string }> => {
50
51
  if (!isNode) {
51
52
  throw new Error("Config can only be created with node");
@@ -85,15 +86,15 @@ export const getDomainFromConfig = async (config: string) => {
85
86
  const getUIPath = async (): Promise<string> => {
86
87
  const url = await import("url");
87
88
  const path = await import("path");
88
- const __filename = url.fileURLToPath(import.meta.url);
89
- const p1 = path.join(__filename, "../../", "ui");
89
+ const filename = url.fileURLToPath(import.meta.url);
90
+ const p1 = path.join(filename, "../../", "ui");
90
91
 
91
92
  const fs = await import("fs");
92
93
 
93
94
  if (fs.existsSync(p1) && fs.lstatSync(p1).isDirectory()) {
94
95
  return p1; // build
95
96
  } else {
96
- const p2 = path.join(__filename, "../../", "lib/ui");
97
+ const p2 = path.join(filename, "../../", "dist/ui");
97
98
  if (fs.existsSync(p2) && fs.lstatSync(p2).isDirectory()) {
98
99
  return p2;
99
100
  }
@@ -110,7 +111,7 @@ export const getMyIp = async (): Promise<string> => {
110
111
  reject("DNS lookup failed");
111
112
  }
112
113
  resolve(stdout.trimEnd());
113
- }
114
+ },
114
115
  );
115
116
  });
116
117
  return ipv4;
@@ -122,24 +123,17 @@ export const createTestDomain = async () => {
122
123
  await axios.post(
123
124
  "https://bfbbnhwpfj2ptcmurz6lit4xlu0vjajw.lambda-url.us-east-1.on.aws",
124
125
  await getMyIp(),
125
- { headers: { "Content-Type": "application/json" } }
126
+ { headers: { "Content-Type": "application/json" } },
126
127
  )
127
128
  ).data.domain;
128
129
  return domain;
129
130
  };
130
131
 
131
- /**
132
- *
133
- * @param email
134
- * @param nginxConfigPath
135
- * @param dockerProcessName
136
- * @returns domain
137
- */
138
132
  export const startCertbot = async (
139
133
  domain: string,
140
134
  email: string,
141
135
  waitForUp = false,
142
- dockerProcessName = "nginx-certbot"
136
+ dockerProcessName = "nginx-certbot",
143
137
  ): Promise<void> => {
144
138
  if (!validateEmail(email)) {
145
139
  throw new Error("Email for SSL renenewal is invalid");
@@ -168,7 +162,7 @@ export const startCertbot = async (
168
162
  // try two times with some delay, because sometimes the docker daemon is not available immidatel
169
163
  await startContainer(
170
164
  certbotDockerCommand,
171
- "Failed to start certbot container"
165
+ "Failed to start certbot container",
172
166
  );
173
167
 
174
168
  console.log("Certbot started succesfully!");
@@ -187,12 +181,12 @@ export const startCertbot = async (
187
181
  return false;
188
182
  }
189
183
  },
190
- { timeout: 5 * 60 * 10000, delayInterval: 5000 }
184
+ { timeout: 5 * 60 * 10000, delayInterval: 5000 },
191
185
  );
192
186
  console.log("Domain is ready");
193
187
  } else {
194
188
  console.log(
195
- "The domain is not available immediately as it takes some time to request SSL certificate."
189
+ "The domain is not available immediately as it takes some time to request SSL certificate.",
196
190
  );
197
191
  }
198
192
  };
package/src/peerbit.ts CHANGED
@@ -1,8 +1,8 @@
1
+ import { type PeerId } from "@libp2p/interface";
1
2
  import { DirectBlock } from "@peerbit/blocks";
2
3
  import { DirectSub } from "@peerbit/pubsub";
3
- import { Peerbit } from "peerbit";
4
4
  import path from "path";
5
- import { type PeerId } from "@libp2p/interface";
5
+ import { Peerbit } from "peerbit";
6
6
 
7
7
  export const LIBP2P_LISTEN_PORT = 8001;
8
8
  export const create = (properties: {
@@ -23,29 +23,30 @@ 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/${listenPort !== 0 ? listenPort + 1 : listenPort
33
- }/ws`
34
- ]
32
+ `/ip4/127.0.0.1/tcp/${
33
+ listenPort !== 0 ? listenPort + 1 : listenPort
34
+ }/ws`,
35
+ ],
35
36
  },
36
37
  connectionManager: {
37
38
  maxConnections: Infinity,
38
- minConnections: 0
39
+ minConnections: 0,
39
40
  },
40
41
  services: {
41
42
  blocks: (c) =>
42
43
  new DirectBlock(c, {
43
44
  directory: blocksDirectory,
44
- canRelayMessage: true
45
+ canRelayMessage: true,
45
46
  }),
46
- pubsub: (c) => new DirectSub(c, { canRelayMessage: true })
47
- }
47
+ pubsub: (c) => new DirectSub(c, { canRelayMessage: true }),
48
+ },
48
49
  },
49
- directory: properties.directory
50
+ directory: properties.directory,
50
51
  });
51
52
  };
package/src/remotes.ts CHANGED
@@ -27,11 +27,11 @@ export class Remotes {
27
27
  constructor(readonly path: string) {
28
28
  if (fs.existsSync(path)) {
29
29
  this.data = JSON.parse(
30
- fs.readFileSync(path).toString("utf-8")
30
+ fs.readFileSync(path).toString("utf-8"),
31
31
  ) as RemotesObject;
32
32
  } else {
33
33
  this.data = {
34
- remotes: []
34
+ remotes: [],
35
35
  };
36
36
  }
37
37
  }