@peerbit/server 4.0.13 → 4.1.0
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/lib/esm/cli.js +15 -0
- package/lib/esm/cli.js.map +1 -1
- package/lib/esm/client.d.ts +1 -0
- package/lib/esm/client.js +7 -1
- package/lib/esm/client.js.map +1 -1
- package/lib/esm/routes.d.ts +1 -0
- package/lib/esm/routes.js +1 -0
- package/lib/esm/routes.js.map +1 -1
- package/lib/esm/server.js +25 -2
- package/lib/esm/server.js.map +1 -1
- package/lib/ui/assets/{index-156b377f.js → index-878b5ffe.js} +2 -2
- package/lib/ui/index.html +1 -1
- package/package.json +2 -2
- package/src/cli.ts +15 -1
- package/src/client.ts +10 -1
- package/src/routes.ts +1 -0
- package/src/server.ts +29 -7
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-
|
|
26
|
+
<script type="module" crossorigin src="/assets/index-878b5ffe.js"></script>
|
|
27
27
|
<link rel="stylesheet" href="/assets/index-5265c558.css">
|
|
28
28
|
</head>
|
|
29
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/server",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"author": "dao.xyz",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"@aws-sdk/client-ec2": "^3.390.0",
|
|
77
77
|
"@aws-sdk/client-route-53": "^3.391.0"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "e976ac33eb57f4b8f953938e68cfedec188521b8"
|
|
80
80
|
}
|
package/src/cli.ts
CHANGED
|
@@ -627,6 +627,7 @@ export const cli = async (args?: string[]) => {
|
|
|
627
627
|
console.log(
|
|
628
628
|
chalk.green("Removed remote with name: " + args.name)
|
|
629
629
|
);
|
|
630
|
+
remotes.save();
|
|
630
631
|
} else {
|
|
631
632
|
console.log(
|
|
632
633
|
chalk.red("Did not find any remote with name: " + args.name)
|
|
@@ -984,7 +985,20 @@ export const cli = async (args?: string[]) => {
|
|
|
984
985
|
}
|
|
985
986
|
}
|
|
986
987
|
})
|
|
987
|
-
|
|
988
|
+
.command({
|
|
989
|
+
command: "variants",
|
|
990
|
+
describe: "List all programs variants",
|
|
991
|
+
aliases: "v",
|
|
992
|
+
handler: async (args) => {
|
|
993
|
+
for (const api of apis) {
|
|
994
|
+
const list = await api.api.program.variants();
|
|
995
|
+
api.log(`Program variants (${list.length}):`);
|
|
996
|
+
list.forEach((p) => {
|
|
997
|
+
api.log(chalk.green(p));
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
})
|
|
988
1002
|
.command({
|
|
989
1003
|
command: "open [program]",
|
|
990
1004
|
describe: "Open program",
|
package/src/client.ts
CHANGED
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
PROGRAM_PATH,
|
|
11
11
|
RESTART_PATH,
|
|
12
12
|
TRUST_PATH,
|
|
13
|
-
REMOTE_API_PORT
|
|
13
|
+
REMOTE_API_PORT,
|
|
14
|
+
PROGRAM_VARIANTS_PATH
|
|
14
15
|
} from "./routes.js";
|
|
15
16
|
import { Address } from "@peerbit/program";
|
|
16
17
|
import { multiaddr } from "@multiformats/multiaddr";
|
|
@@ -221,6 +222,14 @@ export const createClient = async (
|
|
|
221
222
|
})
|
|
222
223
|
);
|
|
223
224
|
return resp.data as string[];
|
|
225
|
+
},
|
|
226
|
+
variants: async (): Promise<string[]> => {
|
|
227
|
+
const resp = throwIfNot200(
|
|
228
|
+
await axiosInstance.get(endpoint + PROGRAM_VARIANTS_PATH, {
|
|
229
|
+
validateStatus
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
return resp.data as string[];
|
|
224
233
|
}
|
|
225
234
|
},
|
|
226
235
|
dependency: {
|
package/src/routes.ts
CHANGED
|
@@ -16,6 +16,7 @@ export const PEER_ID_PATH = "/peer/id";
|
|
|
16
16
|
export const ADDRESS_PATH = "/peer/address";
|
|
17
17
|
export const PROGRAM_PATH = "/program";
|
|
18
18
|
export const PROGRAMS_PATH = "/programs";
|
|
19
|
+
export const PROGRAM_VARIANTS_PATH = "/program/variants";
|
|
19
20
|
export const INSTALL_PATH = "/install";
|
|
20
21
|
export const BOOTSTRAP_PATH = "/network/bootstrap";
|
|
21
22
|
export const RESTART_PATH = "/restart";
|
package/src/server.ts
CHANGED
|
@@ -39,7 +39,8 @@ import {
|
|
|
39
39
|
PROGRAM_PATH,
|
|
40
40
|
RESTART_PATH,
|
|
41
41
|
TRUST_PATH,
|
|
42
|
-
STOP_PATH
|
|
42
|
+
STOP_PATH,
|
|
43
|
+
PROGRAM_VARIANTS_PATH
|
|
43
44
|
} from "./routes.js";
|
|
44
45
|
import { Session } from "./session.js";
|
|
45
46
|
import fs from "fs";
|
|
@@ -320,6 +321,32 @@ export const startApiServer = async (
|
|
|
320
321
|
}
|
|
321
322
|
break;
|
|
322
323
|
|
|
324
|
+
default:
|
|
325
|
+
r404();
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
} else if (req.url.startsWith(PROGRAM_VARIANTS_PATH)) {
|
|
329
|
+
if (client instanceof Peerbit === false) {
|
|
330
|
+
res.writeHead(400);
|
|
331
|
+
res.end("Server node is not running a native client");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
switch (req.method) {
|
|
335
|
+
case "GET":
|
|
336
|
+
try {
|
|
337
|
+
res.setHeader("Content-Type", "application/json");
|
|
338
|
+
res.writeHead(200);
|
|
339
|
+
res.end(
|
|
340
|
+
JSON.stringify(
|
|
341
|
+
getProgramFromVariants().map((x) => getSchema(x).variant)
|
|
342
|
+
)
|
|
343
|
+
);
|
|
344
|
+
} catch (error: any) {
|
|
345
|
+
res.writeHead(404);
|
|
346
|
+
res.end(error.message);
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
|
|
323
350
|
default:
|
|
324
351
|
r404();
|
|
325
352
|
break;
|
|
@@ -409,12 +436,6 @@ export const startApiServer = async (
|
|
|
409
436
|
.open(program) // TODO all users to pass args
|
|
410
437
|
.then(async (program) => {
|
|
411
438
|
// TODO what if this is a reopen?
|
|
412
|
-
console.log(
|
|
413
|
-
"OPEN ADDRESS",
|
|
414
|
-
program.address,
|
|
415
|
-
(client as Peerbit).directory,
|
|
416
|
-
await client.services.blocks.has(program.address)
|
|
417
|
-
);
|
|
418
439
|
await properties?.session?.programs.add(
|
|
419
440
|
program.address,
|
|
420
441
|
new Uint8Array()
|
|
@@ -428,6 +449,7 @@ export const startApiServer = async (
|
|
|
428
449
|
});
|
|
429
450
|
} catch (error: any) {
|
|
430
451
|
res.writeHead(400);
|
|
452
|
+
console.error(error);
|
|
431
453
|
res.end(error.toString());
|
|
432
454
|
}
|
|
433
455
|
break;
|