@enerlence/suntropy-cli 0.11.4 → 0.11.5

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
+ var OBJECT_ID_RE = /^[a-f0-9]{24}$/i;
143
+ function assertStudyObjectId(id) {
144
+ if (OBJECT_ID_RE.test(id)) return id;
145
+ const looksLikeUuid = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(id);
146
+ const hint = looksLikeUuid ? `It looks like a UUID (e.g. a chat or shareable uid), not a study _id.` : `A study _id is a 24-character hex MongoDB ObjectId.`;
147
+ throw new Error(
148
+ `Invalid study id: "${id}". ${hint} Get the correct id from \`suntropy studies list\` (the \`solarStudyId\` field).`
149
+ );
150
+ }
142
151
  function assertFound(data, entity, id) {
143
152
  const isEmptyObject = data != null && typeof data === "object" && !Array.isArray(data) && Object.keys(data).length === 0;
144
153
  if (data == null || typeof data !== "object" || Array.isArray(data) || isEmptyObject) {
@@ -2275,6 +2284,7 @@ function registerStudyBuilderCommands(studies) {
2275
2284
  "Download an existing study from the backend into a local file.\nExample: suntropy studies pull abc123 --file /tmp/study.json"
2276
2285
  ).option("--file <path>", "Output file path").action(async (studyId, opts) => {
2277
2286
  try {
2287
+ assertStudyObjectId(studyId);
2278
2288
  const filePath = resolveFile(opts);
2279
2289
  const global = getGlobalOpts7(studies);
2280
2290
  const client = createServiceClient("solar", global);
@@ -3270,6 +3280,7 @@ Example: suntropy studies set data --file study.json --data '{"referenceId":"REF
3270
3280
  'Add a comment to an existing study via API.\nExample: suntropy studies comment abc123 --content "Revisado por agente"'
3271
3281
  ).requiredOption("--content <text>", "Comment text").addOption(new Option("--as-alexandria").hideHelp()).addOption(new Option("--reply-to-user <userUID>").hideHelp()).addOption(new Option("--reply-to-name <name>").hideHelp()).action(async (studyId, opts) => {
3272
3282
  try {
3283
+ assertStudyObjectId(studyId);
3273
3284
  const global = getGlobalOpts7(studies);
3274
3285
  const client = createServiceClient("solar", global);
3275
3286
  const comment = createComment("commented", opts.content, {
@@ -3593,6 +3604,7 @@ function registerStudiesCommands(program2) {
3593
3604
  });
3594
3605
  studies.command("metadata <id>").description("Get solar study metadata by metadata ID (relational). Full MySQL record with state, costs, versions.").option("--by-study-id", "Interpret <id> as MongoDB solarStudyId instead of metadata ID").action(async (id, opts) => {
3595
3606
  try {
3607
+ if (opts.byStudyId) assertStudyObjectId(id);
3596
3608
  const global = getGlobalOpts8(studies);
3597
3609
  const client = createServiceClient("solar", global);
3598
3610
  const path = opts.byStudyId ? `/solar-study/metadata/solar-study-id/${id}` : `/solar-study/findSolarStudyMetadataById/${id}`;
@@ -3606,6 +3618,7 @@ function registerStudiesCommands(program2) {
3606
3618
  "Get solar study by MongoDB ID. By default returns summary (no heavy curves).\nExpand sections: surfaces, results, economics, batteries, consumption, equipment, client, location\nExamples:\n suntropy studies get abc123\n suntropy studies get abc123 --expand surfaces,results\n suntropy studies get abc123 --expand all\n suntropy studies get abc123 --fields name,market (bypasses expand filter)"
3607
3619
  ).option("--expand <sections>", 'Comma-separated sections to expand (or "all")').action(async (studyId, opts) => {
3608
3620
  try {
3621
+ assertStudyObjectId(studyId);
3609
3622
  const global = getGlobalOpts8(studies);
3610
3623
  const client = createServiceClient("solar", global);
3611
3624
  const res = await client.get(`/solar-study/findById/${studyId}`);
@@ -3628,6 +3641,7 @@ function registerStudiesCommands(program2) {
3628
3641
  "Extract and analyze a PowerCurve from a study.\nCurve names: consumption, production, net-consumption, excesses\nDefault: --stats. Use --raw for full hourly data (8760 values).\nUse --monthly for monthly aggregates, --daily for daily totals."
3629
3642
  ).option("--stats", "Show statistics (default if no other flag)").option("--monthly", "Monthly accumulated values").option("--daily", "Daily accumulated values").option("--raw", "Full hourly DayCurve[] data").option("--total", "Just the total accumulated value").option("--surface-index <n>", "Surface index for production curve", "0").option("--save <file>", "Save curve data to file").action(async (studyId, curveName, opts) => {
3630
3643
  try {
3644
+ assertStudyObjectId(studyId);
3631
3645
  const global = getGlobalOpts8(studies);
3632
3646
  const client = createServiceClient("solar", global);
3633
3647
  const res = await client.get(`/solar-study/findById/${studyId}`);
@@ -4622,7 +4636,7 @@ function registerCommandProfileCommand(program2) {
4622
4636
  }
4623
4637
 
4624
4638
  // src/index.ts
4625
- var CLI_VERSION = true ? "0.11.4" : "0.0.0-dev";
4639
+ var CLI_VERSION = true ? "0.11.5" : "0.0.0-dev";
4626
4640
  function createProgram() {
4627
4641
  const program2 = new Command3();
4628
4642
  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)");