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