@enerlence/suntropy-cli 0.8.0 → 0.8.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.
@@ -139,6 +139,15 @@ function createUnauthClient(baseURL) {
139
139
  headers: { "Content-Type": "application/json" }
140
140
  });
141
141
  }
142
+ function assertFound(data, entity, id) {
143
+ const isEmptyObject = data != null && typeof data === "object" && !Array.isArray(data) && Object.keys(data).length === 0;
144
+ if (data == null || typeof data !== "object" || Array.isArray(data) || isEmptyObject) {
145
+ throw new Error(
146
+ `${entity} not found: ${id}. The backend returned an empty response \u2014 verify the id is correct and belongs to your account and environment (the CLI and the app must point to the same backend).`
147
+ );
148
+ }
149
+ return data;
150
+ }
142
151
  function handleApiError(err) {
143
152
  if (axios.isAxiosError(err)) {
144
153
  const ae = err;
@@ -2184,7 +2193,7 @@ function registerStudyBuilderCommands(studies) {
2184
2193
  const global = getGlobalOpts7(studies);
2185
2194
  const client = createServiceClient("solar", global);
2186
2195
  const res = await client.get(`/solar-study/findById/${studyId}`);
2187
- const study = res.data;
2196
+ const study = assertFound(res.data, "Solar study", studyId);
2188
2197
  const { stepsProgress, missing } = evaluateSteps(study);
2189
2198
  const progress = study.solarStudyProgress || {};
2190
2199
  progress.stepsProgress = stepsProgress;
@@ -3155,7 +3164,8 @@ Example: suntropy studies set data --file study.json --data '{"referenceId":"REF
3155
3164
  replyToName: opts.replyToName
3156
3165
  });
3157
3166
  const res = await client.post(`/solar-study/addSolarStudyComment/${studyId}`, comment);
3158
- output(res.data, global);
3167
+ const saved = assertFound(res.data, "Solar study", studyId);
3168
+ output(saved, global);
3159
3169
  } catch (err) {
3160
3170
  outputError(handleApiError(err));
3161
3171
  }
@@ -3470,7 +3480,7 @@ function registerStudiesCommands(program2) {
3470
3480
  const global = getGlobalOpts8(studies);
3471
3481
  const client = createServiceClient("solar", global);
3472
3482
  const res = await client.get(`/solar-study/findById/${studyId}`);
3473
- const study = res.data;
3483
+ const study = assertFound(res.data, "Solar study", studyId);
3474
3484
  const filtered = global.fields ? study : filterStudy(study, opts.expand);
3475
3485
  if (global.fields) {
3476
3486
  const requested = global.fields.split(",").map((f) => f.trim());
@@ -3492,7 +3502,7 @@ function registerStudiesCommands(program2) {
3492
3502
  const global = getGlobalOpts8(studies);
3493
3503
  const client = createServiceClient("solar", global);
3494
3504
  const res = await client.get(`/solar-study/findById/${studyId}`);
3495
- const study = res.data;
3505
+ const study = assertFound(res.data, "Solar study", studyId);
3496
3506
  let curveData;
3497
3507
  switch (curveName) {
3498
3508
  case "consumption":
@@ -4323,7 +4333,7 @@ function registerGeocodeCommands(program2) {
4323
4333
  }
4324
4334
 
4325
4335
  // src/index.ts
4326
- var CLI_VERSION = true ? "0.8.0" : "0.0.0-dev";
4336
+ var CLI_VERSION = true ? "0.8.1" : "0.0.0-dev";
4327
4337
  function createProgram() {
4328
4338
  const program2 = new Command3();
4329
4339
  program2.name("suntropy").description("Agent-first CLI for Suntropy solar platform. Optimized for programmatic data manipulation and progressive exploration.").version(CLI_VERSION).option("--format <format>", "Output format: json (default), human, csv", "json").option("--fields <fields>", "Comma-separated fields to include in output").option("--server <url>", "Override API server URL").option("--token <jwt>", "Override authentication token").option("--profile <name>", "Use a specific config profile").option("--verbose", "Show HTTP request/response details on stderr").option("--quiet", "Suppress non-data output").option("--save <file>", "Save output to file (also writes to stdout)");