@xyo-network/xl1-cli 1.7.0 → 1.7.1

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 (74) hide show
  1. package/dist/cli-min.mjs +8 -8
  2. package/dist/node/commands/producer/runProducer.d.ts +2 -0
  3. package/dist/node/commands/producer/runProducer.d.ts.map +1 -1
  4. package/dist/node/config/Api.d.ts +12 -0
  5. package/dist/node/config/Api.d.ts.map +1 -0
  6. package/dist/node/config/App.d.ts +9 -0
  7. package/dist/node/config/App.d.ts.map +1 -0
  8. package/dist/node/config/Config.d.ts +141 -0
  9. package/dist/node/config/Config.d.ts.map +1 -0
  10. package/dist/node/config/Log.d.ts +9 -0
  11. package/dist/node/config/Log.d.ts.map +1 -0
  12. package/dist/node/config/Producer.d.ts +12 -0
  13. package/dist/node/config/Producer.d.ts.map +1 -0
  14. package/dist/node/config/index.d.ts +2 -0
  15. package/dist/node/config/index.d.ts.map +1 -0
  16. package/dist/node/config/storage/Storage.d.ts +40 -0
  17. package/dist/node/config/storage/Storage.d.ts.map +1 -0
  18. package/dist/node/config/storage/driver/Mongo.d.ts +22 -0
  19. package/dist/node/config/storage/driver/Mongo.d.ts.map +1 -0
  20. package/dist/node/config/storage/driver/index.d.ts +2 -0
  21. package/dist/node/config/storage/driver/index.d.ts.map +1 -0
  22. package/dist/node/config/storage/index.d.ts +2 -0
  23. package/dist/node/config/storage/index.d.ts.map +1 -0
  24. package/dist/node/config/validation/Address.d.ts +2 -0
  25. package/dist/node/config/validation/Address.d.ts.map +1 -0
  26. package/dist/node/config/validation/Mnemonic.d.ts +13 -0
  27. package/dist/node/config/validation/Mnemonic.d.ts.map +1 -0
  28. package/dist/node/config/validation/index.d.ts +3 -0
  29. package/dist/node/config/validation/index.d.ts.map +1 -0
  30. package/dist/node/images.d.ts +2 -0
  31. package/dist/node/images.d.ts.map +1 -0
  32. package/dist/node/initConfig.d.ts +3 -0
  33. package/dist/node/initConfig.d.ts.map +1 -0
  34. package/dist/node/initLogger.d.ts +2 -1
  35. package/dist/node/initLogger.d.ts.map +1 -1
  36. package/dist/node/optionsFromZodSchema.d.ts +4 -0
  37. package/dist/node/optionsFromZodSchema.d.ts.map +1 -0
  38. package/dist/node/orchestration/initServices.d.ts +7 -1
  39. package/dist/node/orchestration/initServices.d.ts.map +1 -1
  40. package/dist/node/runCLI.d.ts +2 -0
  41. package/dist/node/runCLI.d.ts.map +1 -1
  42. package/dist/node/start.d.ts.map +1 -1
  43. package/dist/node/waitForHostPort.d.ts +2 -0
  44. package/dist/node/waitForHostPort.d.ts.map +1 -0
  45. package/lib/node/index.d.ts +130 -1
  46. package/lib/node/index.mjs +209 -61
  47. package/lib/node/index.mjs.map +1 -1
  48. package/lib/node/xl1.mjs +210 -62
  49. package/lib/node/xl1.mjs.map +1 -1
  50. package/package.json +23 -22
  51. package/rollup.config.mjs +14 -8
  52. package/src/commands/producer/runProducer.ts +3 -1
  53. package/src/config/Api.ts +8 -0
  54. package/src/config/App.ts +3 -0
  55. package/src/config/Config.ts +19 -0
  56. package/src/config/Log.ts +6 -0
  57. package/src/config/Producer.ts +8 -0
  58. package/src/config/index.ts +1 -0
  59. package/src/config/storage/Storage.ts +10 -0
  60. package/src/config/storage/driver/Mongo.ts +12 -0
  61. package/src/config/storage/driver/index.ts +1 -0
  62. package/src/config/storage/index.ts +1 -0
  63. package/src/config/validation/Address.ts +1 -0
  64. package/src/config/validation/Mnemonic.ts +20 -0
  65. package/src/config/validation/index.ts +2 -0
  66. package/src/images.ts +19 -0
  67. package/src/initConfig.ts +6 -0
  68. package/src/initLogger.ts +7 -5
  69. package/src/optionsFromZodSchema.ts +69 -0
  70. package/src/orchestration/initServices.ts +9 -2
  71. package/src/runCLI.ts +54 -72
  72. package/src/start.ts +6 -2
  73. package/src/waitForHostPort.ts +26 -0
  74. package/src/xl1.ts +2 -1
package/lib/node/xl1.mjs CHANGED
@@ -1,6 +1,89 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/config/Config.ts
5
+ import { z as z8 } from "zod";
6
+
7
+ // src/config/Api.ts
8
+ import z2 from "zod";
9
+
10
+ // src/config/validation/Mnemonic.ts
11
+ import { z } from "zod";
12
+ var MnemonicStringSchema = z.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine((s) => [
13
+ 12,
14
+ 15,
15
+ 18,
16
+ 21,
17
+ 24
18
+ ].includes(s.split(" ").length), {
19
+ message: "Mnemonic must contain 12, 15, 18, 21, or 24 words."
20
+ }).describe("BIP-39 mnemonic string");
21
+
22
+ // src/config/Api.ts
23
+ var ApiConfigSchema = z2.object({
24
+ mnemonic: MnemonicStringSchema.optional().describe("Mnemonic for the API wallet"),
25
+ port: z2.coerce.number().default(8080).describe("Port for the API")
26
+ });
27
+
28
+ // src/config/App.ts
29
+ import z3 from "zod";
30
+ var AppConfigSchema = z3.object({
31
+ port: z3.coerce.number().default(3e3).describe("Port for the application")
32
+ });
33
+
34
+ // src/config/Log.ts
35
+ import { LogLevel } from "@xylabs/logger";
36
+ import z4 from "zod";
37
+ var LogLevels = Object.keys(LogLevel);
38
+ var LogConfigSchema = z4.object({
39
+ level: z4.enum(LogLevels).default("info").describe("Desired process verbosity")
40
+ });
41
+
42
+ // src/config/Producer.ts
43
+ import z5 from "zod";
44
+ var ProducerConfigSchema = z5.object({
45
+ mnemonic: MnemonicStringSchema.optional().describe("Mnemonic for the Producer wallet"),
46
+ port: z5.coerce.number().default(8081).describe("Port for the Producer")
47
+ });
48
+
49
+ // src/config/storage/Storage.ts
50
+ import z7 from "zod";
51
+
52
+ // src/config/storage/driver/Mongo.ts
53
+ import z6 from "zod";
54
+ var MongoConfigSchema = z6.object({
55
+ // TODO: Create from other arguments
56
+ connectionString: z6.string().min(1).max(1024).optional().describe("MongoDB connection string"),
57
+ database: z6.string().min(1).max(128).optional().describe("MongoDB database name"),
58
+ domain: z6.string().min(1).max(128).optional().describe("MongoDB domain"),
59
+ password: z6.string().min(1).max(128).optional().describe("MongoDB password"),
60
+ username: z6.string().min(1).max(128).optional().describe("MongoDB username")
61
+ });
62
+
63
+ // src/config/storage/Storage.ts
64
+ var StorageConfigSchema = z7.object({
65
+ // NOTE: Other storage drivers can be added here in the future
66
+ mongo: MongoConfigSchema.optional().describe("Configuration for the MongoDBstorage driver")
67
+ }).describe("Storage configuration options");
68
+
69
+ // src/config/Config.ts
70
+ var Xl1ConfigSchema = z8.object({
71
+ log: LogConfigSchema.default({})
72
+ }).describe("XL1 configuration options");
73
+ var ConfigSchema = z8.object({
74
+ ...Xl1ConfigSchema.shape,
75
+ api: ApiConfigSchema.default({}).describe("Configuration for the API node"),
76
+ app: AppConfigSchema.default({}).describe("Configuration for the application"),
77
+ producer: ProducerConfigSchema.default({}).describe("Configuration for the producer"),
78
+ storage: StorageConfigSchema.default({}).describe("Configuration for the storage")
79
+ });
80
+
81
+ // src/initConfig.ts
82
+ var initConfig = /* @__PURE__ */ __name(() => {
83
+ const config2 = ConfigSchema.parse({});
84
+ return config2;
85
+ }, "initConfig");
86
+
4
87
  // src/initEnv.ts
5
88
  import dotenv from "dotenv";
6
89
  var initEnv = /* @__PURE__ */ __name(() => {
@@ -17,12 +100,12 @@ var initEnv = /* @__PURE__ */ __name(() => {
17
100
 
18
101
  // src/initLogger.ts
19
102
  import { Base } from "@xylabs/base";
20
- import { ConsoleLogger, LogLevel } from "@xylabs/logger";
103
+ import { ConsoleLogger, LogLevel as LogLevel2 } from "@xylabs/logger";
21
104
  import { isDefined } from "@xylabs/typeof";
22
- var initLogger = /* @__PURE__ */ __name(() => {
23
- let level = LogLevel.info;
24
- if (isDefined(process.env.LOG_LEVEL)) {
25
- const parsed = LogLevel[process.env.LOG_LEVEL.toLowerCase()];
105
+ var initLogger = /* @__PURE__ */ __name((config2) => {
106
+ let level;
107
+ if (isDefined(config2?.log?.level)) {
108
+ const parsed = LogLevel2[config2.log.level.toLowerCase()];
26
109
  if (isDefined(parsed)) level = parsed;
27
110
  }
28
111
  const logger = new ConsoleLogger(level);
@@ -923,8 +1006,8 @@ var getChainId = /* @__PURE__ */ __name(() => {
923
1006
 
924
1007
  // src/orchestration/services/implementation/evm/initGanacheProvider.ts
925
1008
  var initJsonRpcProvider = /* @__PURE__ */ __name(() => {
926
- const config = getJsonRpcProviderConfig();
927
- return Promise.resolve(new JsonRpcProvider(...config));
1009
+ const config2 = getJsonRpcProviderConfig();
1010
+ return Promise.resolve(new JsonRpcProvider(...config2));
928
1011
  }, "initJsonRpcProvider");
929
1012
  var canUseJsonRpcProvider = /* @__PURE__ */ __name(() => {
930
1013
  return canUseChainId() && process.env.XYO_JSON_RPC_URL !== void 0;
@@ -943,8 +1026,8 @@ import { InfuraProvider } from "ethers/providers";
943
1026
  var instance;
944
1027
  var initInfuraProvider = /* @__PURE__ */ __name(() => {
945
1028
  if (instance) return instance;
946
- const config = getInfuraProviderConfig();
947
- instance = Promise.resolve(new InfuraProvider(...config));
1029
+ const config2 = getInfuraProviderConfig();
1030
+ instance = Promise.resolve(new InfuraProvider(...config2));
948
1031
  return instance;
949
1032
  }, "initInfuraProvider");
950
1033
  var canUseInfuraProvider = /* @__PURE__ */ __name(() => {
@@ -1215,7 +1298,8 @@ var telemetryConfig = {
1215
1298
  var isStartable = /* @__PURE__ */ __name((value) => {
1216
1299
  return isDefined6(value.start) && typeof value.start === "function";
1217
1300
  }, "isStartable");
1218
- var initServices = /* @__PURE__ */ __name(async (logger) => {
1301
+ var initServices = /* @__PURE__ */ __name(async (context) => {
1302
+ const { config: config2, logger } = context;
1219
1303
  const statusReporter = new RuntimeStatusMonitor(logger);
1220
1304
  statusReporter.onGlobalTransition({
1221
1305
  to: "started"
@@ -1354,9 +1438,9 @@ var initServices = /* @__PURE__ */ __name(async (logger) => {
1354
1438
  }, "initServices");
1355
1439
 
1356
1440
  // src/runCLI.ts
1357
- import net from "net";
1358
1441
  import yargs from "yargs";
1359
1442
  import { hideBin } from "yargs/helpers";
1443
+ import { ZodError } from "zod";
1360
1444
 
1361
1445
  // src/commands/api/runApi.ts
1362
1446
  import { getServer } from "@xyo-network/chain-api";
@@ -1370,7 +1454,7 @@ __name(runApi, "runApi");
1370
1454
  var runProducer = /* @__PURE__ */ __name(async (context) => {
1371
1455
  const { logger, orchestrator } = context;
1372
1456
  logger?.log("Services: Initializing...");
1373
- const services = await initServices(logger);
1457
+ const services = await initServices(context);
1374
1458
  logger?.log("Services: Initialized");
1375
1459
  const chainHeadUpdate = await ChainHeadUpdateActor.create(services);
1376
1460
  const producer = await ProducerActor.create(services);
@@ -1386,16 +1470,78 @@ var runProducer = /* @__PURE__ */ __name(async (context) => {
1386
1470
  await orchestrator.start();
1387
1471
  }, "runProducer");
1388
1472
 
1389
- // src/commands/validator/runValidator.ts
1390
- var runValidator = /* @__PURE__ */ __name(async (context) => {
1391
- const { orchestrator } = context;
1392
- const myActor = new Actor("Validator", "Validator", {});
1393
- await orchestrator.registerActor(myActor);
1394
- await orchestrator.start();
1395
- }, "runValidator");
1396
-
1397
- // src/runCLI.ts
1398
- function waitForPort(host, port) {
1473
+ // src/images.ts
1474
+ var XL1LogoColorizedAscii = `\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;118;111;144m_\x1B[0m
1475
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;72;32;223m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m
1476
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\u2560\u2560\x1B[0m\x1B[38;2;103;85;170m_\x1B[0m
1477
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;79;121;152m\u2566\x1B[0m\x1B[38;2;82;121;151m\u2566\x1B[0m\x1B[38;2;112;125;136m_\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;88;59;196m[\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;73;34;221m\u2592\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;121;121;127m_\x1B[0m\x1B[38;2;100;101;128m\u2554\x1B[0m\x1B[38;2;93;94;127m\u2566\x1B[0m
1478
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;82;121;151m\xB2\x1B[0m\x1B[38;2;44;116;170m\u2560\x1B[0m\x1B[38;2;44;116;171m\u2592\x1B[0m\x1B[38;2;51;117;167mD\x1B[0m\x1B[38;2;80;121;152m\u2566\x1B[0m\x1B[38;2;111;125;136m_\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;67;23;232m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;120;121;128m_\x1B[0m\x1B[38;2;100;101;127m\u2554\x1B[0m\x1B[38;2;79;81;127mR\x1B[0m\x1B[38;2;71;73;128m\u2592\x1B[0m\x1B[38;2;71;73;128m\u2592\x1B[0m\x1B[38;2;88;90;127m\u2559\x1B[0m
1479
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;55;117;165m\u255A\x1B[0m\x1B[38;2;44;116;171m\u2592\x1B[0m\x1B[38;2;44;116;171m\u2592\u2592\x1B[0m\x1B[38;2;50;116;167mD\x1B[0m\x1B[38;2;80;121;152m\u2566\xA0\x1B[0m\x1B[38;2;106;90;165mj\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\x1B[0m\x1B[38;2;89;61;194mH\xA0\x1B[0m\x1B[38;2;99;100;127m\u2554\x1B[0m\x1B[38;2;79;80;127mD\x1B[0m\x1B[38;2;71;73;128m\u2592\x1B[0m\x1B[38;2;71;73;128m\u2592\u2592\u2560\x1B[0m
1480
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;83;121;150m\xB2\x1B[0m\x1B[38;2;44;116;170m\u2592\x1B[0m\x1B[38;2;44;116;171m\u2592\u2592\u2592\xA0\x1B[0m\x1B[38;2;76;38;217m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\xA0\x1B[0m\x1B[38;2;74;76;128m\u2560\x1B[0m\x1B[38;2;71;73;128m\u2592\u2592\u2592\x1B[0m\x1B[38;2;89;90;128m\u2559\x1B[0m
1481
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;90;118;148m\`\x1B[0m\x1B[38;2;89;107;153m_\x1B[0m\x1B[38;2;93;97;154m,\x1B[0m\x1B[38;2;105;89;166m\u2553\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;95;72;183m\u2553\x1B[0m\x1B[38;2;106;96;152m_\x1B[0m\x1B[38;2;100;94;143m\`\x1B[0m\x1B[38;2;101;100;133m\`\x1B[0m
1482
+ \x1B[38;2;128;128;128m\xA0\x1B[0m\x1B[38;2;122;118;137m_\x1B[0m\x1B[38;2;113;102;153m,\x1B[0m\x1B[38;2;108;94;161m\u2553\x1B[0m\x1B[38;2;104;86;169m\u2553\x1B[0m\x1B[38;2;98;77;178m\u2554\x1B[0m\x1B[38;2;93;67;188m\u2557\x1B[0m\x1B[38;2;88;59;196m\u03C6\x1B[0m\x1B[38;2;83;51;204m@\x1B[0m\x1B[38;2;78;42;213mD\x1B[0m\x1B[38;2;72;32;223m\u2592\x1B[0m\x1B[38;2;68;24;231m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;71;30;225m\u2592\x1B[0m\x1B[38;2;77;40;215m\u2592\x1B[0m\x1B[38;2;82;49;206mK\x1B[0m\x1B[38;2;87;57;198m\u03C6\x1B[0m\x1B[38;2;91;65;190m\u2557\x1B[0m\x1B[38;2;97;75;180m\u2566\x1B[0m\x1B[38;2;103;84;171m\u2556\x1B[0m\x1B[38;2;107;92;163m\xB2\x1B[0m\x1B[38;2;112;101;154m_\x1B[0m\x1B[38;2;119;112;143m_\x1B[0m
1483
+ \x1B[38;2;128;128;128m\xA0\x1B[0m\x1B[38;2;106;91;164m\`\x1B[0m\x1B[38;2;94;70;185m^\x1B[0m\x1B[38;2;89;62;193m\u2559\x1B[0m\x1B[38;2;85;54;201m\u2559\x1B[0m\x1B[38;2;80;45;210m\u255A\x1B[0m\x1B[38;2;74;35;220m\u255D\x1B[0m\x1B[38;2;69;26;229m\u2560\x1B[0m\x1B[38;2;66;22;233m\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;73;33;222m\u255D\x1B[0m\x1B[38;2;79;43;212m\u2569\x1B[0m\x1B[38;2;84;52;203m\u255C\x1B[0m\x1B[38;2;88;60;195m\u2559\x1B[0m\x1B[38;2;93;68;187m^\x1B[0m\x1B[38;2;100;80;175m\`\x1B[0m
1484
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;113;84;152m\`\x1B[0m\x1B[38;2;103;79;169m'\x1B[0m\x1B[38;2;95;72;183m"\x1B[0m\x1B[38;2;87;57;198m\u2559\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;80;46;209m\u255C\x1B[0m\x1B[38;2;94;70;185m^\x1B[0m\x1B[38;2;102;77;175m^\x1B[0m\x1B[38;2;112;81;162m\`\x1B[0m\x1B[38;2;115;92;155m\`\x1B[0m
1485
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;145;116;107m,\x1B[0m\x1B[38;2;199;82;45m\u2560\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;207;77;35m\u2592\u2560\xA0\x1B[0m\x1B[38;2;70;28;227m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\xA0\x1B[0m\x1B[38;2;189;49;97m\xE5\x1B[0m\x1B[38;2;203;32;90m\u2560\x1B[0m\x1B[38;2;203;32;90m\u2560\u2560\x1B[0m\x1B[38;2;155;92;114m,\x1B[0m
1486
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;175;98;73m\u2554\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;207;77;35m\u2592\u2592\u2592\x1B[0m\x1B[38;2;197;83;47m\u2569\xA0\x1B[0m\x1B[38;2;98;76;179m[\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\x1B[0m\x1B[38;2;81;48;207mH\xA0\x1B[0m\x1B[38;2;188;51;98m\u255A\x1B[0m\x1B[38;2;203;32;90m\u2560\x1B[0m\x1B[38;2;203;32;90m\u2560\u2560\u2560\x1B[0m\x1B[38;2;183;57;100mH\x1B[0m
1487
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;146;116;106m,\x1B[0m\x1B[38;2;199;82;44m\u2560\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;196;84;48m\u2569\x1B[0m\x1B[38;2;168;102;81m^\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;160;87;111m'\x1B[0m\x1B[38;2;187;52;98m\u255A\x1B[0m\x1B[38;2;203;32;90m\u2560\x1B[0m\x1B[38;2;203;32;90m\u2560\u2560\x1B[0m\x1B[38;2;156;91;113m,\x1B[0m
1488
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;198;83;46m\u2569\x1B[0m\x1B[38;2;194;85;50m\u2569\x1B[0m\x1B[38;2;167;102;82m^\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;81;46;209m\u255A\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;159;88;112m'\x1B[0m\x1B[38;2;186;53;98m\u255A\x1B[0m\x1B[38;2;197;40;93m\u2569\x1B[0m
1489
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;110;97;158m'\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;94;69;186mH\x1B[0m
1490
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;68;25;230m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m
1491
+ \x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;108;93;162m\xB2\x1B[0m\x1B[38;2;99;79;176m^\x1B[0m`;
1492
+
1493
+ // src/optionsFromZodSchema.ts
1494
+ import { ZodBoolean, ZodDefault, ZodEnum, ZodNumber, ZodObject, ZodOptional } from "zod";
1495
+ var collectOptions = /* @__PURE__ */ __name((zodType, path = [], out = {}) => {
1496
+ if (zodType instanceof ZodObject) {
1497
+ const shape = zodType.shape;
1498
+ for (const [k, v] of Object.entries(shape)) {
1499
+ collectOptions(v, [
1500
+ ...path,
1501
+ k
1502
+ ], out);
1503
+ }
1504
+ return out;
1505
+ }
1506
+ const def = zodType._def;
1507
+ if (def?.innerType instanceof ZodObject) {
1508
+ const shape = def.innerType.shape;
1509
+ for (const [k, v] of Object.entries(shape)) {
1510
+ collectOptions(v, [
1511
+ ...path,
1512
+ k
1513
+ ], out);
1514
+ }
1515
+ return out;
1516
+ }
1517
+ const options = {};
1518
+ options.describe = def.description;
1519
+ options.default = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
1520
+ let type = "string";
1521
+ const typeName = def.typeName === ZodDefault.name || def.typeName === ZodOptional.name ? def.innerType._def.typeName : def.typeName;
1522
+ if (typeName === ZodBoolean.name) type = "boolean";
1523
+ if (typeName === ZodNumber.name || def.coerce) type = "number";
1524
+ if (typeName === ZodEnum.name) {
1525
+ options.choices = Object.values(def.innerType.enum);
1526
+ }
1527
+ options.type = type;
1528
+ const key = path.join(".");
1529
+ out[key] = options;
1530
+ return out;
1531
+ }, "collectOptions");
1532
+ var optionsFromZodSchema = /* @__PURE__ */ __name((schema) => {
1533
+ const opts = {};
1534
+ for (const [rootKey, zodType] of Object.entries(schema)) {
1535
+ collectOptions(zodType, [
1536
+ rootKey
1537
+ ], opts);
1538
+ }
1539
+ return opts;
1540
+ }, "optionsFromZodSchema");
1541
+
1542
+ // src/waitForHostPort.ts
1543
+ import net from "net";
1544
+ var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
1399
1545
  return new Promise((resolve) => {
1400
1546
  const tryConnect = /* @__PURE__ */ __name(() => {
1401
1547
  const socket = new net.Socket();
@@ -1412,48 +1558,48 @@ function waitForPort(host, port) {
1412
1558
  }, "tryConnect");
1413
1559
  tryConnect();
1414
1560
  });
1415
- }
1416
- __name(waitForPort, "waitForPort");
1561
+ }, "waitForHostPort");
1562
+
1563
+ // src/runCLI.ts
1564
+ var config;
1417
1565
  async function runCLI(context) {
1418
- async function validateTransaction() {
1419
- await Promise.reject("Not implemented yet");
1420
- }
1421
- __name(validateTransaction, "validateTransaction");
1422
- async function submitTransaction() {
1423
- await Promise.reject("Not implemented yet");
1424
- }
1425
- __name(submitTransaction, "submitTransaction");
1426
- async function checkBalance() {
1427
- await Promise.reject("Not implemented yet");
1428
- }
1429
- __name(checkBalance, "checkBalance");
1430
- const argv = yargs(hideBin(process.argv)).command("validator", "Run the XL1 validator", (yargs2) => {
1431
- return yargs2.command("$0", "Run as a XL1 validator node", () => {
1432
- }, () => runValidator(context));
1433
- }).command("producer", "Run the XL1 producer", (yargs2) => {
1434
- return yargs2.command("$0", "Run as a XL1 producer node", () => {
1566
+ const y = yargs(hideBin(process.argv));
1567
+ const argv = y.usage(`
1568
+ \u{1F680} XL1 Node CLI (${__VERSION__})
1569
+ ${XL1LogoColorizedAscii}
1570
+ Run various components of the XL1 ecosystem.
1571
+
1572
+ Usage:
1573
+ $0 <command> [options]`).parserConfiguration({
1574
+ "dot-notation": true
1575
+ }).env("XL1").scriptName("xl1").config().version(__VERSION__).middleware((argv2) => {
1576
+ try {
1577
+ config = ConfigSchema.parse(argv2);
1578
+ } catch (err) {
1579
+ if (err instanceof ZodError) {
1580
+ for (const issue of err.errors) {
1581
+ console.error(`${issue.path.join(".")} \u2192 ${issue.message}`);
1582
+ }
1583
+ }
1584
+ throw new Error("Invalid configuration");
1585
+ }
1586
+ }).options(optionsFromZodSchema(ConfigSchema.shape)).wrap(y.terminalWidth()).command("api", "Run a XL1 API", (yargs2) => {
1587
+ return yargs2.command("$0", "Run a XL1 API", () => {
1588
+ }, () => runApi(context));
1589
+ }).command("producer", "Run a XL1 Producer Node", (yargs2) => {
1590
+ return yargs2.command("$0", "Run a XL1 Producer Node", () => {
1435
1591
  }, () => runProducer(context));
1436
- }).command("client", "Client-related operations", (yargs2) => {
1437
- return yargs2.command("transaction", "Transaction-related operations", (yargs3) => {
1438
- return yargs3.command("validate", "Validate a transaction", () => {
1439
- }, validateTransaction).command("submit", "Submit a transaction", () => {
1440
- }, submitTransaction);
1592
+ }).command("$0", "Run a full XL1 Node", () => {
1593
+ }, async () => {
1594
+ runApi({
1595
+ ...context
1441
1596
  });
1442
- }).command("api", "Run as a api node", (yargs2) => {
1443
- return yargs2.command("$0", "Run as a api node", () => {
1444
- }, () => runApi(context)).command("run", "Run as a api node", () => {
1445
- }, () => runApi(context));
1446
- }).command("$0", "Run a full XL1 deployment", (yargs2) => {
1447
- return yargs2.command("$0", "Start the API and a producer", () => {
1448
- }, async () => {
1449
- runApi(context);
1450
- await waitForPort("localhost", 8080);
1451
- await runProducer(context);
1597
+ await waitForHostPort("localhost", config.api.port);
1598
+ await runProducer({
1599
+ ...context,
1600
+ config
1452
1601
  });
1453
- }).command("account", "Account-related operations", (yargs2) => {
1454
- return yargs2.command("balance", "Check account balance", () => {
1455
- }, checkBalance);
1456
- }).help().alias("help", "h").env("XL1").argv;
1602
+ }).help().alias("help", "h").argv;
1457
1603
  await argv;
1458
1604
  }
1459
1605
  __name(runCLI, "runCLI");
@@ -1461,7 +1607,8 @@ __name(runCLI, "runCLI");
1461
1607
  // src/start.ts
1462
1608
  var start = /* @__PURE__ */ __name(async () => {
1463
1609
  initEnv();
1464
- const logger = initLogger();
1610
+ const config2 = initConfig();
1611
+ const logger = initLogger(config2);
1465
1612
  const orchestrator = new Orchestrator(logger);
1466
1613
  process.on("SIGINT", () => {
1467
1614
  void (async () => {
@@ -1477,6 +1624,7 @@ var start = /* @__PURE__ */ __name(async () => {
1477
1624
  })();
1478
1625
  });
1479
1626
  await runCLI({
1627
+ config: config2,
1480
1628
  logger,
1481
1629
  orchestrator
1482
1630
  });
@@ -1484,7 +1632,7 @@ var start = /* @__PURE__ */ __name(async () => {
1484
1632
 
1485
1633
  // src/xl1.ts
1486
1634
  start().catch((err) => {
1487
- console.error("An error occurred during startup:", err);
1635
+ if (process.env.NODE_ENV === "development") console.error("An error occurred during startup:", err);
1488
1636
  process.exit(1);
1489
1637
  });
1490
1638
  //# sourceMappingURL=xl1.mjs.map