@tikoci/centrs 0.1.2 → 0.1.3

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 (82) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/GLOSSARY.txt +71 -0
  3. package/README.md +24 -8
  4. package/SECURITY.md +3 -3
  5. package/commands/api/README.md +27 -9
  6. package/commands/api/examples.md +109 -6
  7. package/commands/check/README.md +371 -53
  8. package/commands/check/examples.md +390 -0
  9. package/commands/devices/README.md +177 -37
  10. package/commands/devices/examples.md +148 -0
  11. package/commands/execute/README.md +39 -4
  12. package/commands/execute/examples.md +90 -6
  13. package/commands/retrieve/README.md +36 -50
  14. package/commands/retrieve/examples.md +40 -9
  15. package/commands/settings/README.md +286 -22
  16. package/commands/settings/examples.md +408 -0
  17. package/commands/terminal/README.md +6 -0
  18. package/commands/transfer/README.md +32 -2
  19. package/commands/transfer/examples.md +66 -0
  20. package/docs/CONSTITUTION.md +36 -11
  21. package/docs/MATRIX.md +68 -172
  22. package/docs/errors/README.md +2 -1
  23. package/docs/errors/cdb/empty-selection.md +19 -0
  24. package/docs/errors/input/incomplete-gps.md +9 -0
  25. package/docs/errors/input/invalid-altitude.md +9 -0
  26. package/docs/errors/input/invalid-bbox.md +9 -0
  27. package/docs/errors/input/invalid-coordinate.md +9 -0
  28. package/docs/errors/input/invalid-radius.md +9 -0
  29. package/docs/errors/internal/settings-failed.md +9 -0
  30. package/docs/errors/settings/consequential-value.md +26 -0
  31. package/docs/errors/settings/invalid-boolean.md +21 -3
  32. package/docs/errors/settings/invalid-format.md +18 -3
  33. package/docs/errors/settings/invalid-integer.md +18 -3
  34. package/docs/errors/settings/invalid-timeout.md +20 -3
  35. package/docs/errors/settings/invalid-via.md +22 -3
  36. package/docs/errors/settings/reserved-key.md +29 -0
  37. package/docs/errors/settings/skip-env-file-active.md +25 -0
  38. package/docs/errors/settings/unknown-key.md +25 -0
  39. package/docs/errors/usage/fanout-not-supported.md +16 -0
  40. package/package.json +6 -6
  41. package/src/api-fanout.ts +454 -0
  42. package/src/api.ts +91 -19
  43. package/src/cli/api.ts +135 -11
  44. package/src/cli/btest.ts +20 -2
  45. package/src/cli/common.ts +11 -0
  46. package/src/cli/devices.ts +235 -6
  47. package/src/cli/discover.ts +3 -1
  48. package/src/cli/execute.ts +107 -6
  49. package/src/cli/mcp.ts +8 -1
  50. package/src/cli/retrieve.ts +135 -90
  51. package/src/cli/selection.ts +200 -0
  52. package/src/cli/settings.ts +286 -0
  53. package/src/cli/terminal.ts +22 -7
  54. package/src/cli/transfer.ts +171 -47
  55. package/src/cli.ts +7 -0
  56. package/src/core/error-catalog.ts +55 -0
  57. package/src/core/fanout.ts +143 -2
  58. package/src/devices.ts +212 -20
  59. package/src/discover.ts +7 -2
  60. package/src/execute-fanout.ts +438 -0
  61. package/src/execute.ts +120 -23
  62. package/src/index.ts +105 -1
  63. package/src/mcp/config.ts +12 -2
  64. package/src/mcp/tools.ts +137 -2
  65. package/src/protocols/adapter.ts +38 -18
  66. package/src/protocols/index.ts +11 -5
  67. package/src/resolver/cdb.ts +10 -2
  68. package/src/resolver/comment-kv.ts +58 -4
  69. package/src/resolver/config-file.ts +136 -0
  70. package/src/resolver/facts.ts +78 -0
  71. package/src/resolver/geo.ts +453 -0
  72. package/src/resolver/index.ts +46 -0
  73. package/src/resolver/mac.ts +12 -3
  74. package/src/resolver/selection.ts +304 -0
  75. package/src/resolver/settings.ts +54 -5
  76. package/src/resolver/target.ts +20 -2
  77. package/src/retrieve-fanout.ts +225 -133
  78. package/src/retrieve.ts +39 -7
  79. package/src/settings.ts +1078 -0
  80. package/src/terminal.ts +11 -1
  81. package/src/transfer-fanout.ts +527 -0
  82. package/src/transfer.ts +61 -11
package/src/retrieve.ts CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  import {
29
29
  type CdbResolution,
30
30
  isIpTransport,
31
+ loadEnvFileDefaults,
31
32
  parseDuration,
32
33
  parseResolvePolicy,
33
34
  type ResolvedAuth,
@@ -618,9 +619,10 @@ export function buildResolvedRetrieve(
618
619
  cdbResolution: CdbResolution | undefined,
619
620
  attributeSelections: readonly string[],
620
621
  macResolution?: { mac: string; ip: string },
622
+ config: Record<string, string | undefined> = {},
621
623
  ): ResolvedRetrieveRequest {
622
- const via = resolveProtocol(request, env, cdbResolution);
623
- const format = resolveFormat(request, env);
624
+ const via = resolveProtocol(request, env, cdbResolution, config);
625
+ const format = resolveFormat(request, env, config);
624
626
  const validate = resolveBooleanSetting(
625
627
  request.validate,
626
628
  env,
@@ -628,18 +630,22 @@ export function buildResolvedRetrieve(
628
630
  true,
629
631
  "validate",
630
632
  cdbResolution?.overrides.validate,
633
+ config,
631
634
  );
632
635
  const timeoutMs = resolveTimeoutSetting(
633
636
  request.timeout,
634
637
  env,
635
638
  via.value,
636
639
  cdbResolution?.overrides.timeoutMs,
640
+ config,
637
641
  );
638
642
  const maxResultsBytes = resolveOptionalIntegerSetting(
639
643
  request.maxResultsBytes,
640
644
  env,
641
645
  "CENTRS_MAX_RESULTS",
642
646
  "max-results",
647
+ undefined,
648
+ config,
643
649
  );
644
650
  const target = resolveTarget(
645
651
  {
@@ -691,22 +697,33 @@ export function resolveRetrieveGlobalContext(
691
697
  request: RetrieveRequest,
692
698
  env: Record<string, string | undefined>,
693
699
  attributeSelections: readonly string[],
700
+ config: Record<string, string | undefined> = {},
694
701
  ): RetrieveGlobalContext {
695
- const via = resolveProtocol(request, env);
696
- const format = resolveFormat(request, env);
702
+ const via = resolveProtocol(request, env, undefined, config);
703
+ const format = resolveFormat(request, env, config);
697
704
  const validate = resolveBooleanSetting(
698
705
  request.validate,
699
706
  env,
700
707
  "CENTRS_VALIDATE",
701
708
  true,
702
709
  "validate",
710
+ undefined,
711
+ config,
712
+ );
713
+ const timeoutMs = resolveTimeoutSetting(
714
+ request.timeout,
715
+ env,
716
+ via.value,
717
+ undefined,
718
+ config,
703
719
  );
704
- const timeoutMs = resolveTimeoutSetting(request.timeout, env, via.value);
705
720
  const maxResultsBytes = resolveOptionalIntegerSetting(
706
721
  request.maxResultsBytes,
707
722
  env,
708
723
  "CENTRS_MAX_RESULTS",
709
724
  "max-results",
725
+ undefined,
726
+ config,
710
727
  );
711
728
 
712
729
  return {
@@ -739,6 +756,7 @@ export async function resolveRetrieveRequest(
739
756
  env: Record<string, string | undefined>,
740
757
  ): Promise<ResolvedRetrieveRequest> {
741
758
  const attributeSelections = validateRetrieveRequestShape(request);
759
+ const config = await loadEnvFileDefaults(env);
742
760
 
743
761
  const cdbResolution = await resolveCdb(
744
762
  {
@@ -747,12 +765,14 @@ export async function resolveRetrieveRequest(
747
765
  cdbPassword: request.cdbPassword,
748
766
  },
749
767
  env,
768
+ config,
750
769
  );
751
770
 
752
771
  const macResolution = await resolveMacForRetrieve(
753
772
  request,
754
773
  env,
755
774
  cdbResolution,
775
+ config,
756
776
  );
757
777
 
758
778
  return buildResolvedRetrieve(
@@ -761,6 +781,7 @@ export async function resolveRetrieveRequest(
761
781
  cdbResolution,
762
782
  attributeSelections,
763
783
  macResolution,
784
+ config,
764
785
  );
765
786
  }
766
787
 
@@ -774,8 +795,9 @@ export async function resolveMacForRetrieve(
774
795
  request: RetrieveRequest,
775
796
  env: Record<string, string | undefined>,
776
797
  cdb?: CdbResolution,
798
+ config: Record<string, string | undefined> = {},
777
799
  ): Promise<{ mac: string; ip: string } | undefined> {
778
- if (!isIpTransport(resolveProtocol(request, env, cdb).value)) {
800
+ if (!isIpTransport(resolveProtocol(request, env, cdb, config).value)) {
779
801
  return undefined;
780
802
  }
781
803
  return resolveMacTarget({
@@ -783,7 +805,10 @@ export async function resolveMacForRetrieve(
783
805
  targetInput: request.targetInput,
784
806
  cdbTarget: cdb?.target,
785
807
  env,
786
- policy: parseResolvePolicy(request.resolve ?? env["CENTRS_RESOLVE"]),
808
+ config,
809
+ policy: parseResolvePolicy(
810
+ request.resolve ?? env["CENTRS_RESOLVE"] ?? config["CENTRS_RESOLVE"],
811
+ ),
787
812
  operation: "retrieve",
788
813
  });
789
814
  }
@@ -792,6 +817,7 @@ function resolveProtocol(
792
817
  request: RetrieveRequest,
793
818
  env: Record<string, string | undefined>,
794
819
  cdb?: CdbResolution,
820
+ config: Record<string, string | undefined> = {},
795
821
  ): ResolvedSetting<RouterOsProtocol> {
796
822
  const via = resolveStringSetting(
797
823
  request.via,
@@ -801,6 +827,7 @@ function resolveProtocol(
801
827
  "via",
802
828
  undefined,
803
829
  cdb?.overrides.via,
830
+ config,
804
831
  );
805
832
  if (!via) {
806
833
  throw new CentrsError({
@@ -859,6 +886,7 @@ function resolveProtocol(
859
886
  function resolveFormat(
860
887
  request: RetrieveRequest,
861
888
  env: Record<string, string | undefined>,
889
+ config: Record<string, string | undefined> = {},
862
890
  ): ResolvedSetting<RetrieveOutputFormat> {
863
891
  return resolveStringSetting(
864
892
  request.format,
@@ -867,6 +895,8 @@ function resolveFormat(
867
895
  "text",
868
896
  "format",
869
897
  parseOutputFormat,
898
+ undefined,
899
+ config,
870
900
  ) as ResolvedSetting<RetrieveOutputFormat>;
871
901
  }
872
902
 
@@ -990,6 +1020,7 @@ function resolveTimeoutSetting(
990
1020
  env: Record<string, string | undefined>,
991
1021
  via: RouterOsProtocol,
992
1022
  commentKv?: ResolvedSetting<number>,
1023
+ config: Record<string, string | undefined> = {},
993
1024
  ): ResolvedSetting<number> {
994
1025
  const resolved = resolveStringSetting(
995
1026
  timeout === undefined ? undefined : String(timeout),
@@ -1010,6 +1041,7 @@ function resolveTimeoutSetting(
1010
1041
  return parsed;
1011
1042
  },
1012
1043
  commentKv,
1044
+ config,
1013
1045
  );
1014
1046
  if (!resolved) {
1015
1047
  throw new Error("timeout resolution produced no value");