@enerlence/suntropy-cli 0.1.1 → 0.1.2

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.
@@ -632,6 +632,35 @@ function registerKitsCommands(inventory) {
632
632
  batchDeletePath: "delete-batch-solar-kits",
633
633
  getViaFilter: true
634
634
  });
635
+ const kitsCreate = kits.commands.find((c) => c.name() === "create");
636
+ if (kitsCreate) {
637
+ kitsCreate.description(
638
+ `Create a solar kit via raw JSON. Prefer "assemble" for guided creation.
639
+
640
+ Required fields:
641
+ identifier (string) \u2014 Kit name (NOT "name")
642
+ price (number) \u2014 Kit price in EUR
643
+ panelNumber (number) \u2014 Number of panels
644
+ inverterNumber (number) \u2014 Number of inverters
645
+ phaseNumber (string) \u2014 "single_phase" or "three_phase"
646
+
647
+ Component relations (use kit-specific IDs, NOT inventory IDs):
648
+ kitSolarPanel: {"idKitSolarPanel": <id>} \u2014 from "kits panels list/create"
649
+ kitInverter: {"idKitInverter": <id>} \u2014 from "kits inverters list/create"
650
+ battery: {"batteryId": <id>} \u2014 from "inventory batteries list"
651
+
652
+ Optional fields:
653
+ peakPower, coplanar, defaultTaxesPercentage, active, batteriesNumber,
654
+ useTotalKitCostAsPrice, manufacturingWarranty, materialsWarranty,
655
+ imageUrl, referenceId, buyUrl
656
+
657
+ Custom assets array:
658
+ solarKitCustomAssets: [{"customAsset": {"idCustomAsset": <id>}, "units": <n>}]
659
+
660
+ Example:
661
+ suntropy inventory kits create --data '{"identifier":"Kit 5kW","kitSolarPanel":{"idKitSolarPanel":123},"kitInverter":{"idKitInverter":456},"panelNumber":12,"inverterNumber":1,"peakPower":5.4,"price":6500,"phaseNumber":"single_phase"}'`
662
+ );
663
+ }
635
664
  kits.command("archive <kitId>").description("Archive a solar kit (soft-disable)").action(async (kitId) => {
636
665
  try {
637
666
  const global = getGlobalOpts3(kits);
@@ -788,10 +817,71 @@ function registerKitsCommands(inventory) {
788
817
  });
789
818
  kits.command("assemble").description(
790
819
  'Assemble a solar kit from existing components by ID.\nReferences kit panels, inverters, batteries, and custom assets by their IDs.\n\nCustom assets format: --custom-asset <assetId>:<units> (repeatable)\n\nExamples:\n suntropy inventory kits assemble --name "Kit 5kW" --panel 123 --inverter 456 --panels-count 12 --price 6500\n suntropy inventory kits assemble --name "Kit Premium" --panel 123 --inverter 456 --battery 789 \\\n --panels-count 12 --inverters-count 1 --batteries-count 1 --peak-power 5.4 --price 8500 \\\n --custom-asset 100:12 --custom-asset 200:1 --phase single_phase'
791
- ).requiredOption("--name <identifier>", "Kit name/identifier").option("--panel <kitPanelId>", "Kit panel ID (idKitSolarPanel)").option("--inverter <kitInverterId>", "Kit inverter ID (idKitInverter)").option("--battery <batteryId>", "Battery ID from inventory (batteryId)").option("--panels-count <n>", "Number of panels", "12").option("--inverters-count <n>", "Number of inverters", "1").option("--batteries-count <n>", "Number of batteries", "0").option("--peak-power <kW>", "Total peak power in kW").option("--price <eur>", "Kit price in EUR").option("--phase <type>", "Phase: single_phase or three_phase", "single_phase").option("--coplanar", "Coplanar mounting").option("--taxes <pct>", "Default tax percentage", "21").option("--custom-asset <id:units>", "Custom asset as id:units (repeatable)", collectCustomAssets, []).action(async (opts) => {
820
+ ).requiredOption("--name <identifier>", "Kit name/identifier").option("--panel <kitPanelId>", "Kit panel ID (idKitSolarPanel)").option("--inverter <kitInverterId>", "Kit inverter ID (idKitInverter)").option("--battery <batteryId>", "Battery ID from inventory (batteryId)").option("--panels-count <n>", "Number of panels", "12").option("--inverters-count <n>", "Number of inverters", "1").option("--batteries-count <n>", "Number of batteries", "0").option("--peak-power <kW>", "Total peak power in kW").requiredOption("--price <eur>", "Kit price in EUR (required)").option("--phase <type>", "Phase: single_phase or three_phase", "single_phase").option("--coplanar", "Coplanar mounting").option("--taxes <pct>", "Default tax percentage", "21").option("--custom-asset <id:units>", "Custom asset as id:units (repeatable)", collectCustomAssets, []).action(async (opts) => {
792
821
  try {
793
822
  const global = getGlobalOpts3(kits);
794
823
  const client = createServiceClient("solar", global);
824
+ const validationErrors = [];
825
+ if (opts.panel) {
826
+ try {
827
+ const res2 = await client.post("/solar-kits/solar-panels/filter", { idKitSolarPanel: parseInt(opts.panel) });
828
+ const data = Array.isArray(res2.data) ? res2.data : res2.data?.data || [];
829
+ if (data.length === 0) {
830
+ validationErrors.push(
831
+ `Panel ID ${opts.panel} is not a KitSolarPanel. Use "suntropy inventory kits panels list" to see available kit panels, or "suntropy inventory kits panels create --data '{...}'" to create one first.`
832
+ );
833
+ }
834
+ } catch {
835
+ validationErrors.push(
836
+ `Could not validate panel ID ${opts.panel}. Make sure it is a KitSolarPanel ID (not a regular inventory panel). Use "suntropy inventory kits panels list" to see available kit panels.`
837
+ );
838
+ }
839
+ }
840
+ if (opts.inverter) {
841
+ try {
842
+ const res2 = await client.get("/solar-kits/inverters", { params: { limit: 200 } });
843
+ const inverters = Array.isArray(res2.data) ? res2.data : res2.data?.data || [];
844
+ const found = inverters.find(
845
+ (inv) => String(inv.idKitInverter) === String(opts.inverter)
846
+ );
847
+ if (!found) {
848
+ validationErrors.push(
849
+ `Inverter ID ${opts.inverter} is not a KitInverter. Use "suntropy inventory kits inverters list" to see available kit inverters, or "suntropy inventory kits inverters create --data '{...}'" to create one first.`
850
+ );
851
+ }
852
+ } catch {
853
+ validationErrors.push(
854
+ `Could not validate inverter ID ${opts.inverter}. Make sure it is a KitInverter ID (not a regular inventory inverter). Use "suntropy inventory kits inverters list" to see available kit inverters.`
855
+ );
856
+ }
857
+ }
858
+ if (opts.battery) {
859
+ try {
860
+ const res2 = await client.get("/solar-kits/batteries", { params: { limit: 200 } });
861
+ const batteries = Array.isArray(res2.data) ? res2.data : res2.data?.data || [];
862
+ const found = batteries.find(
863
+ (bat) => String(bat.idKitBattery) === String(opts.battery)
864
+ );
865
+ if (!found) {
866
+ validationErrors.push(
867
+ `Battery ID ${opts.battery} is not a KitBattery. Use "suntropy inventory kits batteries list" to see available kit batteries, or "suntropy inventory kits batteries create --data '{...}'" to create one first.`
868
+ );
869
+ }
870
+ } catch {
871
+ validationErrors.push(
872
+ `Could not validate battery ID ${opts.battery}. Make sure it is a KitBattery ID (not a regular inventory battery). Use "suntropy inventory kits batteries list" to see available kit batteries.`
873
+ );
874
+ }
875
+ }
876
+ if (validationErrors.length > 0) {
877
+ outputError({
878
+ error: true,
879
+ message: "Kit assembly validation failed",
880
+ issues: validationErrors,
881
+ hint: "The assemble command requires KitSolarPanel, KitInverter, and KitBattery IDs \u2014 these are kit-specific entities, not regular inventory items."
882
+ });
883
+ return;
884
+ }
795
885
  const body = {
796
886
  identifier: opts.name,
797
887
  panelNumber: parseInt(opts.panelsCount),
@@ -805,7 +895,7 @@ function registerKitsCommands(inventory) {
805
895
  if (opts.inverter) body.kitInverter = { idKitInverter: parseInt(opts.inverter) };
806
896
  if (opts.battery) body.battery = { batteryId: parseInt(opts.battery) };
807
897
  if (opts.peakPower) body.peakPower = parseFloat(opts.peakPower);
808
- if (opts.price) body.price = parseFloat(opts.price);
898
+ body.price = parseFloat(opts.price);
809
899
  if (opts.coplanar) body.coplanar = true;
810
900
  if (opts.customAsset && opts.customAsset.length > 0) {
811
901
  body.solarKitCustomAssets = opts.customAsset.map((ca) => ({