@peerbit/server 4.0.2 → 4.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
- import { createTestDomain, getDomainFromConfig, loadConfig, startCertbot, } from "./domain.js";
1
+ import { createTestDomain, getDomainFromConfig, loadConfig, startCertbot } from "./domain.js";
2
2
  import { startServerWithNode } from "./server.js";
3
- import { AWS_LINUX_ARM_AMIs, createRecord, launchNodes, terminateNode, } from "./aws.js";
4
- import { getHomeConfigDir, getKeypair, getPackageName, getRemotesPath, } from "./config.js";
3
+ import { AWS_LINUX_ARM_AMIs, createRecord, launchNodes, terminateNode } from "./aws.js";
4
+ import { getHomeConfigDir, getKeypair, getPackageName, getRemotesPath } from "./config.js";
5
5
  import chalk from "chalk";
6
6
  import { createClient, waitForDomain } from "./client.js";
7
7
  import { exit } from "process";
@@ -76,7 +76,7 @@ const colors = [
76
76
  "#A5FFD2",
77
77
  "#FFB167",
78
78
  "#009BFF",
79
- "#E85EBE",
79
+ "#E85EBE"
80
80
  ];
81
81
  const padString = function (string, padding, padChar = " ", stringLength = string.valueOf().length) {
82
82
  const val = string.valueOf();
@@ -107,35 +107,35 @@ export const cli = async (args) => {
107
107
  defaultDescription: "~.peerbit",
108
108
  type: "string",
109
109
  alias: "d",
110
- default: getHomeConfigDir(),
110
+ default: getHomeConfigDir()
111
111
  })
112
112
  .option("bootstrap", {
113
113
  describe: "Whether to connect to bootstap nodes on startup",
114
114
  type: "boolean",
115
- default: false,
115
+ default: false
116
116
  })
117
117
  .option("grant-access", {
118
118
  describe: "Grant access to public keys on start",
119
119
  defaultDescription: "The publickey of this device located in 'directory'",
120
120
  type: "string",
121
121
  array: true,
122
- alias: "ga",
122
+ alias: "ga"
123
123
  })
124
124
  .option("reset", {
125
125
  describe: "If true, then programs opened during last session will not be opened",
126
126
  type: "boolean",
127
127
  default: false,
128
- alias: "r",
128
+ alias: "r"
129
129
  })
130
130
  .option("port-api", {
131
131
  describe: "Set API server port. Only modify this when testing locally, since NGINX config depends on the default value",
132
132
  type: "number",
133
- default: undefined,
133
+ default: undefined
134
134
  })
135
135
  .option("port-node", {
136
136
  describe: "Set Libp2p listen port. Only modify this when testing locally, since NGINX config depends on the default value",
137
137
  type: "number",
138
- default: undefined,
138
+ default: undefined
139
139
  });
140
140
  return yargs;
141
141
  },
@@ -146,9 +146,9 @@ export const cli = async (args) => {
146
146
  ports: { api: args["port-api"], node: args["port-node"] },
147
147
  bootstrap: args.bootstrap,
148
148
  newSession: args.reset,
149
- grantAccess: args["grant-access"],
149
+ grantAccess: args["grant-access"]
150
150
  });
151
- },
151
+ }
152
152
  })
153
153
  .command({
154
154
  command: "id",
@@ -159,14 +159,14 @@ export const cli = async (args) => {
159
159
  defaultDescription: "~.peerbit",
160
160
  type: "string",
161
161
  alias: "d",
162
- default: getHomeConfigDir(),
162
+ default: getHomeConfigDir()
163
163
  });
164
164
  return yargs;
165
165
  },
166
166
  handler: async (args) => {
167
167
  const kp = await getKeypair(args.directory);
168
168
  console.log((await kp.toPeerId()).toString());
169
- },
169
+ }
170
170
  })
171
171
  .command("domain", "Setup a domain and certificate for this node", (yargs) => {
172
172
  yargs
@@ -177,25 +177,25 @@ export const cli = async (args) => {
177
177
  email: {
178
178
  describe: "Email for Lets encrypt autorenewal messages",
179
179
  type: "string",
180
- demandOption: true,
180
+ demandOption: true
181
181
  },
182
182
  outdir: {
183
183
  describe: "Output path for Nginx config",
184
184
  type: "string",
185
- alias: "o",
185
+ alias: "o"
186
186
  },
187
187
  wait: {
188
188
  alias: "w",
189
189
  describe: "Wait for setup to succeed (or fail)",
190
190
  type: "boolean",
191
- default: false,
192
- },
191
+ default: false
192
+ }
193
193
  },
194
194
  handler: async (args) => {
195
195
  const domain = await createTestDomain();
196
196
  await startCertbot(domain, args.email, args.outdir, args.wait);
197
197
  exit();
198
- },
198
+ }
199
199
  })
200
200
  .command({
201
201
  command: "aws",
@@ -205,45 +205,45 @@ export const cli = async (args) => {
205
205
  describe: "domain, e.g. abc.example.com, example.com",
206
206
  alias: "d",
207
207
  type: "string",
208
- demandOption: true,
208
+ demandOption: true
209
209
  },
210
210
  hostedZoneId: {
211
211
  describe: 'The id of the hosted zone "HostedZoneId"',
212
212
  alias: "hz",
213
213
  type: "string",
214
- require: true,
214
+ require: true
215
215
  },
216
216
  accessKeyId: {
217
217
  describe: "Access key id of the AWS user",
218
218
  alias: "ak",
219
- type: "string",
219
+ type: "string"
220
220
  },
221
221
  region: {
222
222
  describe: "AWS region",
223
223
  alias: "r",
224
- type: "string",
224
+ type: "string"
225
225
  },
226
226
  secretAccessKey: {
227
227
  describe: "Secret key id of the AWS user",
228
228
  alias: "sk",
229
- type: "string",
229
+ type: "string"
230
230
  },
231
231
  email: {
232
232
  describe: "Email for Lets encrypt auto-renewal messages",
233
233
  type: "string",
234
- demandOption: true,
234
+ demandOption: true
235
235
  },
236
236
  outdir: {
237
237
  describe: "Output path for Nginx config",
238
238
  type: "string",
239
- alias: "o",
239
+ alias: "o"
240
240
  },
241
241
  wait: {
242
242
  alias: "w",
243
243
  describe: "Wait for setup to succeed (or fail)",
244
244
  type: "boolean",
245
- default: false,
246
- },
245
+ default: false
246
+ }
247
247
  },
248
248
  handler: async (args) => {
249
249
  if (!!args.accessKeyId !== !!args.secretAccessKey ||
@@ -257,13 +257,13 @@ export const cli = async (args) => {
257
257
  credentials: args.accessKeyId
258
258
  ? {
259
259
  accessKeyId: args.accessKeyId,
260
- secretAccessKey: args.secretAccessKey,
260
+ secretAccessKey: args.secretAccessKey
261
261
  }
262
- : undefined,
262
+ : undefined
263
263
  });
264
264
  await startCertbot(args.domain, args.email, args.outdir, args.wait);
265
265
  exit();
266
- },
266
+ }
267
267
  })
268
268
  .strict()
269
269
  .demandCommand();
@@ -281,19 +281,19 @@ export const cli = async (args) => {
281
281
  defaultDescription: "One node",
282
282
  type: "number",
283
283
  alias: "c",
284
- default: 1,
284
+ default: 1
285
285
  });
286
286
  awsArgs.option("region", {
287
287
  describe: "Region",
288
288
  type: "string",
289
289
  defaultDescription: "Region defined in ~.aws/config",
290
- choices: Object.keys(AWS_LINUX_ARM_AMIs),
290
+ choices: Object.keys(AWS_LINUX_ARM_AMIs)
291
291
  });
292
292
  awsArgs.option("group", {
293
293
  describe: "Remote group to launch nodes in",
294
294
  type: "string",
295
295
  alias: "g",
296
- default: DEFAULT_REMOTE_GROUP,
296
+ default: DEFAULT_REMOTE_GROUP
297
297
  });
298
298
  awsArgs.option("size", {
299
299
  describe: "Instance size",
@@ -305,29 +305,29 @@ export const cli = async (args) => {
305
305
  "medium",
306
306
  "large",
307
307
  "xlarge",
308
- "2xlarge",
308
+ "2xlarge"
309
309
  ],
310
- default: "micro",
310
+ default: "micro"
311
311
  });
312
312
  awsArgs.option("name", {
313
313
  describe: "Name prefix for spawned nodes",
314
314
  type: "string",
315
315
  alias: "n",
316
- default: "peerbit-node",
316
+ default: "peerbit-node"
317
317
  });
318
318
  awsArgs.option("grant-access", {
319
319
  describe: "Grant access to public keys on start",
320
320
  defaultDescription: "The publickey of this device located in 'directory'",
321
321
  type: "string",
322
322
  array: true,
323
- alias: "ga",
323
+ alias: "ga"
324
324
  });
325
325
  awsArgs.option("directory", {
326
326
  describe: "Peerbit directory",
327
327
  defaultDescription: "~.peerbit",
328
328
  type: "string",
329
329
  alias: "d",
330
- default: getHomeConfigDir(),
330
+ default: getHomeConfigDir()
331
331
  });
332
332
  return awsArgs;
333
333
  },
@@ -335,7 +335,7 @@ export const cli = async (args) => {
335
335
  const accessGrant = args.access?.length > 0
336
336
  ? args.access.map((x) => peerIdFromString(x))
337
337
  : [
338
- await (await getKeypair(args.directory)).publicKey.toPeerId(),
338
+ await (await getKeypair(args.directory)).publicKey.toPeerId()
339
339
  ];
340
340
  const nodes = await launchNodes({
341
341
  email: "marcus@dao.xyz",
@@ -343,7 +343,7 @@ export const cli = async (args) => {
343
343
  namePrefix: args.name,
344
344
  region: args.region,
345
345
  grantAccess: accessGrant,
346
- size: args.size,
346
+ size: args.size
347
347
  });
348
348
  console.log(`Waiting for ${args.count} ${args.count > 1 ? "nodes" : "node"} to spawn. This might take a few minutes. You can watch the progress in your AWS console.`);
349
349
  const twirlTimer = (function () {
@@ -365,8 +365,8 @@ export const cli = async (args) => {
365
365
  origin: {
366
366
  type: "aws",
367
367
  instanceId: node.instanceId,
368
- region: node.region,
369
- },
368
+ region: node.region
369
+ }
370
370
  });
371
371
  }
372
372
  catch (error) {
@@ -380,7 +380,7 @@ export const cli = async (args) => {
380
380
  for (const node of nodes) {
381
381
  console.log(chalk.green(node.name));
382
382
  }
383
- },
383
+ }
384
384
  })
385
385
  .strict()
386
386
  .demandCommand();
@@ -392,21 +392,21 @@ export const cli = async (args) => {
392
392
  killArgs.option("all", {
393
393
  describe: "Kill all nodes",
394
394
  type: "boolean",
395
- default: false,
395
+ default: false
396
396
  });
397
397
  killArgs.positional("name", {
398
398
  type: "string",
399
399
  describe: "Remote name",
400
400
  default: "localhost",
401
401
  demandOption: false,
402
- array: true,
402
+ array: true
403
403
  });
404
404
  killArgs.option("directory", {
405
405
  describe: "Peerbit directory",
406
406
  defaultDescription: "~.peerbit",
407
407
  type: "string",
408
408
  alias: "d",
409
- default: getHomeConfigDir(),
409
+ default: getHomeConfigDir()
410
410
  });
411
411
  return killArgs;
412
412
  },
@@ -418,12 +418,12 @@ export const cli = async (args) => {
418
418
  if (remote.origin?.type === "aws") {
419
419
  await terminateNode({
420
420
  instanceId: remote.origin.instanceId,
421
- region: remote.origin.region,
421
+ region: remote.origin.region
422
422
  });
423
423
  }
424
424
  }
425
425
  }
426
- },
426
+ }
427
427
  })
428
428
  .command({
429
429
  command: "list",
@@ -435,7 +435,7 @@ export const cli = async (args) => {
435
435
  defaultDescription: "~.peerbit",
436
436
  type: "string",
437
437
  alias: "d",
438
- default: getHomeConfigDir(),
438
+ default: getHomeConfigDir()
439
439
  });
440
440
  return yargs;
441
441
  },
@@ -457,7 +457,7 @@ export const cli = async (args) => {
457
457
  resolvedOrRejected[ix].status === "fulfilled"
458
458
  ? chalk.green("Y")
459
459
  : chalk.red("N"),
460
- remote.address,
460
+ remote.address
461
461
  ];
462
462
  rows.push(row);
463
463
  }
@@ -469,7 +469,7 @@ export const cli = async (args) => {
469
469
  else {
470
470
  console.log("No remotes found!");
471
471
  }
472
- },
472
+ }
473
473
  })
474
474
  .command({
475
475
  command: "add <name> <address>",
@@ -479,25 +479,25 @@ export const cli = async (args) => {
479
479
  .positional("name", {
480
480
  type: "string",
481
481
  describe: "Remote address",
482
- demandOption: true,
482
+ demandOption: true
483
483
  })
484
484
  .positional("address", {
485
485
  type: "string",
486
486
  describe: "Remote name",
487
- demandOption: true,
487
+ demandOption: true
488
488
  })
489
489
  .option("group", {
490
490
  describe: "Group name",
491
491
  type: "string",
492
492
  alias: "g",
493
- default: DEFAULT_REMOTE_GROUP,
493
+ default: DEFAULT_REMOTE_GROUP
494
494
  })
495
495
  .option("directory", {
496
496
  describe: "Peerbit directory",
497
497
  defaultDescription: "~.peerbit",
498
498
  type: "string",
499
499
  alias: "d",
500
- default: getHomeConfigDir(),
500
+ default: getHomeConfigDir()
501
501
  });
502
502
  return yargs;
503
503
  },
@@ -506,7 +506,7 @@ export const cli = async (args) => {
506
506
  throw new Error("Remote can not be named 'localhost'");
507
507
  }
508
508
  const api = await createClient(await getKeypair(args.directory), {
509
- address: args.address,
509
+ address: args.address
510
510
  });
511
511
  try {
512
512
  await api.program.list();
@@ -521,9 +521,9 @@ export const cli = async (args) => {
521
521
  remotes.add({
522
522
  name: args.name,
523
523
  address: args.address,
524
- group: args.group,
524
+ group: args.group
525
525
  });
526
- },
526
+ }
527
527
  })
528
528
  .command({
529
529
  command: "remove <name>",
@@ -533,14 +533,14 @@ export const cli = async (args) => {
533
533
  .positional("name", {
534
534
  type: "string",
535
535
  describe: "Remote address",
536
- demandOption: true,
536
+ demandOption: true
537
537
  })
538
538
  .option("directory", {
539
539
  describe: "Peerbit directory",
540
540
  defaultDescription: "~.peerbit",
541
541
  type: "string",
542
542
  alias: "d",
543
- default: getHomeConfigDir(),
543
+ default: getHomeConfigDir()
544
544
  });
545
545
  return yargs;
546
546
  },
@@ -552,7 +552,7 @@ export const cli = async (args) => {
552
552
  else {
553
553
  console.log(chalk.red("Did not find any remote with name: " + args.name));
554
554
  }
555
- },
555
+ }
556
556
  })
557
557
  .command({
558
558
  command: "connect [name...]",
@@ -564,26 +564,26 @@ export const cli = async (args) => {
564
564
  describe: "Remote name",
565
565
  default: "localhost",
566
566
  demandOption: false,
567
- array: true,
567
+ array: true
568
568
  })
569
569
  .option("all", {
570
570
  type: "boolean",
571
571
  describe: "Connect to all nodes",
572
- default: false,
572
+ default: false
573
573
  })
574
574
  .option("group", {
575
575
  type: "string",
576
576
  describe: "Remote group name",
577
577
  alias: "g",
578
578
  default: [],
579
- array: true,
579
+ array: true
580
580
  })
581
581
  .option("directory", {
582
582
  describe: "Peerbit directory",
583
583
  defaultDescription: "~.peerbit",
584
584
  type: "string",
585
585
  alias: "d",
586
- default: getHomeConfigDir(),
586
+ default: getHomeConfigDir()
587
587
  });
588
588
  return yargs;
589
589
  },
@@ -605,7 +605,7 @@ export const cli = async (args) => {
605
605
  selectedRemotes.push({
606
606
  address: "http://localhost:" + LOCAL_API_PORT,
607
607
  name: "localhost",
608
- group: DEFAULT_REMOTE_GROUP,
608
+ group: DEFAULT_REMOTE_GROUP
609
609
  });
610
610
  }
611
611
  else {
@@ -640,7 +640,7 @@ export const cli = async (args) => {
640
640
  apis.push({
641
641
  log: logFn,
642
642
  name: remote.name,
643
- api: await createClient(keypair, remote),
643
+ api: await createClient(keypair, remote)
644
644
  });
645
645
  }
646
646
  // try if authenticated
@@ -656,7 +656,7 @@ export const cli = async (args) => {
656
656
  input: process.stdin,
657
657
  output: process.stdout,
658
658
  terminal: true,
659
- historySize: 100,
659
+ historySize: 100
660
660
  });
661
661
  console.log("Write 'help' to show commands.\n");
662
662
  rl.prompt(false);
@@ -671,7 +671,7 @@ export const cli = async (args) => {
671
671
  for (const api of apis) {
672
672
  api.log((await api.api.peer.id.get()).toString());
673
673
  }
674
- },
674
+ }
675
675
  })
676
676
  .command({
677
677
  command: "address",
@@ -680,7 +680,7 @@ export const cli = async (args) => {
680
680
  for (const api of apis) {
681
681
  (await api.api.peer.addresses.get()).forEach((x) => api.log(x.toString()));
682
682
  }
683
- },
683
+ }
684
684
  })
685
685
  .strict()
686
686
  .demandCommand();
@@ -695,7 +695,7 @@ export const cli = async (args) => {
695
695
  yargs.positional("peer-id", {
696
696
  describe: "Peer id",
697
697
  type: "string",
698
- demandOption: true,
698
+ demandOption: true
699
699
  });
700
700
  return yargs;
701
701
  },
@@ -704,7 +704,7 @@ export const cli = async (args) => {
704
704
  for (const api of apis) {
705
705
  await api.api.access.allow(peerId);
706
706
  }
707
- },
707
+ }
708
708
  })
709
709
  .command({
710
710
  command: "deny <peer-id>",
@@ -712,7 +712,7 @@ export const cli = async (args) => {
712
712
  builder: (yargs) => {
713
713
  yargs.positional("peer-id", {
714
714
  describe: "Peer id",
715
- demandOption: true,
715
+ demandOption: true
716
716
  });
717
717
  return yargs;
718
718
  },
@@ -721,7 +721,7 @@ export const cli = async (args) => {
721
721
  for (const api of apis) {
722
722
  await api.api.access.deny(peerId);
723
723
  }
724
- },
724
+ }
725
725
  })
726
726
  .strict()
727
727
  .demandCommand();
@@ -735,7 +735,7 @@ export const cli = async (args) => {
735
735
  for (const api of apis) {
736
736
  await api.api.network.bootstrap();
737
737
  }
738
- },
738
+ }
739
739
  })
740
740
  .strict()
741
741
  .demandCommand();
@@ -751,7 +751,7 @@ export const cli = async (args) => {
751
751
  type: "boolean",
752
752
  describe: "Replicate data on this topic",
753
753
  aliases: "r",
754
- default: false,
754
+ default: false
755
755
  });
756
756
  return yargs;
757
757
  },
@@ -767,7 +767,7 @@ export const cli = async (args) => {
767
767
  console.log("Not subscribed to any topics");
768
768
  } */
769
769
  console.error("Not implemented");
770
- },
770
+ }
771
771
  })
772
772
  .strict()
773
773
  .demandCommand();
@@ -782,7 +782,7 @@ export const cli = async (args) => {
782
782
  yargs.positional("address", {
783
783
  type: "string",
784
784
  describe: "Program address",
785
- demandOption: true,
785
+ demandOption: true
786
786
  });
787
787
  return yargs;
788
788
  },
@@ -796,7 +796,7 @@ export const cli = async (args) => {
796
796
  api.log(chalk.green("Open"));
797
797
  }
798
798
  }
799
- },
799
+ }
800
800
  })
801
801
  .command({
802
802
  command: "drop <address>",
@@ -805,7 +805,7 @@ export const cli = async (args) => {
805
805
  yargs.positional("address", {
806
806
  type: "string",
807
807
  describe: "Program address",
808
- demandOption: true,
808
+ demandOption: true
809
809
  });
810
810
  return yargs;
811
811
  },
@@ -818,7 +818,7 @@ export const cli = async (args) => {
818
818
  api.log(chalk.red(`Failed to drop ${args.address}: ${error.toString()}`));
819
819
  }
820
820
  }
821
- },
821
+ }
822
822
  })
823
823
  .command({
824
824
  command: "close <address>",
@@ -827,7 +827,7 @@ export const cli = async (args) => {
827
827
  yargs.positional("address", {
828
828
  type: "string",
829
829
  describe: "Program address",
830
- demandOption: true,
830
+ demandOption: true
831
831
  });
832
832
  return yargs;
833
833
  },
@@ -835,7 +835,7 @@ export const cli = async (args) => {
835
835
  for (const api of apis) {
836
836
  await api.api.program.close(args.address);
837
837
  }
838
- },
838
+ }
839
839
  })
840
840
  .command({
841
841
  command: "list",
@@ -849,7 +849,7 @@ export const cli = async (args) => {
849
849
  api.log(chalk.green(p));
850
850
  });
851
851
  }
852
- },
852
+ }
853
853
  })
854
854
  .command({
855
855
  command: "open [program]",
@@ -858,17 +858,17 @@ export const cli = async (args) => {
858
858
  yargs.positional("program", {
859
859
  type: "string",
860
860
  describe: "Identifier",
861
- demandOption: true,
861
+ demandOption: true
862
862
  });
863
863
  yargs.option("base64", {
864
864
  type: "string",
865
865
  describe: "Base64 encoded serialized",
866
- aliases: "b",
866
+ aliases: "b"
867
867
  });
868
868
  yargs.option("variant", {
869
869
  type: "string",
870
870
  describe: "Variant name",
871
- aliases: "v",
871
+ aliases: "v"
872
872
  });
873
873
  return yargs;
874
874
  },
@@ -879,12 +879,12 @@ export const cli = async (args) => {
879
879
  let startArg;
880
880
  if (args.base64) {
881
881
  startArg = {
882
- base64: args.base64,
882
+ base64: args.base64
883
883
  };
884
884
  }
885
885
  else {
886
886
  startArg = {
887
- variant: args.variant,
887
+ variant: args.variant
888
888
  };
889
889
  }
890
890
  for (const api of apis) {
@@ -892,7 +892,7 @@ export const cli = async (args) => {
892
892
  api.log("Started program with address: ");
893
893
  api.log(chalk.green(address.toString()));
894
894
  }
895
- },
895
+ }
896
896
  })
897
897
  .strict()
898
898
  .demandCommand();
@@ -905,7 +905,7 @@ export const cli = async (args) => {
905
905
  yargs.positional("package-spec", {
906
906
  type: "string",
907
907
  describe: "Installed dependency will be loaded with js import(...)",
908
- demandOption: true,
908
+ demandOption: true
909
909
  });
910
910
  return yargs;
911
911
  },
@@ -922,7 +922,7 @@ export const cli = async (args) => {
922
922
  installCommand = {
923
923
  type: "tgz",
924
924
  name: await getPackageName(packageName),
925
- base64,
925
+ base64
926
926
  };
927
927
  }
928
928
  else {
@@ -935,7 +935,7 @@ export const cli = async (args) => {
935
935
  api.log(chalk.green(p));
936
936
  });
937
937
  }
938
- },
938
+ }
939
939
  })
940
940
  .command({
941
941
  command: "restart",
@@ -944,7 +944,7 @@ export const cli = async (args) => {
944
944
  for (const api of apis) {
945
945
  await api.api.restart();
946
946
  }
947
- },
947
+ }
948
948
  })
949
949
  .command({
950
950
  command: "stop",
@@ -953,7 +953,7 @@ export const cli = async (args) => {
953
953
  for (const api of apis) {
954
954
  await api.api.stop();
955
955
  }
956
- },
956
+ }
957
957
  })
958
958
  .help()
959
959
  .strict()
@@ -972,7 +972,7 @@ export const cli = async (args) => {
972
972
  rl.prompt(true);
973
973
  });
974
974
  }
975
- },
975
+ }
976
976
  })
977
977
  .help()
978
978
  .strict()