@erdoai/cli 0.158.0 → 0.159.0

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 (2) hide show
  1. package/dist/index.js +45 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -197,6 +197,8 @@ async function rawRequest(baseURL, token, orgId, projectId, method, path, body,
197
197
  res = await fetch(`${baseURL}${path}`, {
198
198
  method,
199
199
  headers,
200
+ // A 307/308 redirect would replay a non-idempotent mutation too.
201
+ redirect: retryNetworkFailures ? "follow" : "error",
200
202
  body: body !== void 0 ? JSON.stringify(body) : void 0
201
203
  });
202
204
  } catch (err) {
@@ -330,6 +332,28 @@ var ErdoClient = class {
330
332
  me() {
331
333
  return this.request("GET", "/v1/me");
332
334
  }
335
+ creditBalance() {
336
+ return this.request("GET", "/v1/credits/balance");
337
+ }
338
+ async grantCredits(organization, amount, reason) {
339
+ try {
340
+ const result = await this.request(
341
+ "POST",
342
+ "/v1/admin/credits/grant",
343
+ { organization, amount, reason },
344
+ false
345
+ );
346
+ if (!result || typeof result.organization_id !== "string" || !result.organization_id.trim() || result.amount !== amount || !Number.isInteger(result.balance)) {
347
+ throw new Error("Grant response did not include the committed target, amount, and balance.");
348
+ }
349
+ return result;
350
+ } catch (error) {
351
+ if (!(error instanceof ErdoApiError) || error.status >= 500 || error.status === 408) {
352
+ throw new Error(`Credit grant outcome unknown. Do not repeat the grant. Inspect the target organization's credit ledger in the staff billing UI first. ${error instanceof Error ? error.message : String(error)}`);
353
+ }
354
+ throw error;
355
+ }
356
+ }
333
357
  listOrganizations() {
334
358
  return this.request("GET", "/v1/organizations");
335
359
  }
@@ -2679,6 +2703,27 @@ function compactEvalRunAttribution(run) {
2679
2703
  var program = new Command2();
2680
2704
  program.name("erdo").description("Erdo CLI").version(pkg.version);
2681
2705
  bindScopeFlags(program);
2706
+ var credits = program.command("credits").description("Read organization credits");
2707
+ credits.command("balance").description("Read the current organization's credit balance (use --org to select)").action(async () => {
2708
+ try {
2709
+ print(await new ErdoClient().creditBalance());
2710
+ } catch (error) {
2711
+ fail(error);
2712
+ }
2713
+ });
2714
+ var admin = program.command("admin").description("Erdo staff administration");
2715
+ admin.command("credits").description("Staff-only manual credit grants").command("grant <orgSlugOrId>").description("Grant non-expiring credits without payment; requires an authenticated staff user").requiredOption("--amount <integer>", "Positive integer credits to grant").requiredOption("--reason <text>", "Audit reason").action(async (organization, options) => {
2716
+ try {
2717
+ if (!/^[0-9]+$/.test(options.amount) || Number(options.amount) <= 0 || Number(options.amount) > 2147483647) {
2718
+ throw new Error("--amount must be a positive integer no greater than 2147483647");
2719
+ }
2720
+ if (!organization.trim()) throw new Error("Target organization is required");
2721
+ if (!options.reason.trim()) throw new Error("--reason must not be empty");
2722
+ print(await new ErdoClient().grantCredits(organization.trim(), Number(options.amount), options.reason.trim()));
2723
+ } catch (error) {
2724
+ fail(error);
2725
+ }
2726
+ });
2682
2727
  async function doLogin(opts) {
2683
2728
  let token;
2684
2729
  let me;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.158.0",
3
+ "version": "0.159.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {