@erdoai/cli 0.157.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 +95 -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) {
@@ -275,10 +277,22 @@ var ErdoClient = class {
275
277
  input
276
278
  );
277
279
  }
280
+ listPaidMediaAudiences(customerId, provider = "google_ads") {
281
+ const query = new URLSearchParams({ provider });
282
+ if (customerId) query.set("customer_id", customerId);
283
+ return this.request("GET", `/v1/paid-media/audiences?${query}`);
284
+ }
278
285
  listPaidMediaCampaigns(customerId) {
279
286
  const query = customerId ? `?customer_id=${encodeURIComponent(customerId)}` : "";
280
287
  return this.request("GET", `/v1/paid-media/campaigns${query}`);
281
288
  }
289
+ setPaidMediaAudienceMode(campaignId, input) {
290
+ return this.request(
291
+ "POST",
292
+ `/v1/paid-media/campaigns/${encodeURIComponent(campaignId)}/audience-mode`,
293
+ input
294
+ );
295
+ }
282
296
  setPaidMediaCampaignConversionGoals(campaignId, input) {
283
297
  return this.request(
284
298
  "POST",
@@ -318,6 +332,28 @@ var ErdoClient = class {
318
332
  me() {
319
333
  return this.request("GET", "/v1/me");
320
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
+ }
321
357
  listOrganizations() {
322
358
  return this.request("GET", "/v1/organizations");
323
359
  }
@@ -2667,6 +2703,27 @@ function compactEvalRunAttribution(run) {
2667
2703
  var program = new Command2();
2668
2704
  program.name("erdo").description("Erdo CLI").version(pkg.version);
2669
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
+ });
2670
2727
  async function doLogin(opts) {
2671
2728
  let token;
2672
2729
  let me;
@@ -2779,7 +2836,45 @@ program.command(REFRESH_COMMAND, { hidden: true }).description("Internal: refres
2779
2836
  await refreshVersionCache();
2780
2837
  });
2781
2838
  var paidMedia = program.command("paid-media").description("Paid media setup and operations");
2839
+ paidMedia.command("audiences").description("Read live audience lists, eligibility, attachments and targeting mode").option("--provider <provider>", "ad platform", "google_ads").option("--customer-id <id>", "Google Ads customer id (defaults to the selected account)").option("--json", "print the raw JSON result, including partial-read errors").action(async (opts) => {
2840
+ try {
2841
+ const result = await new ErdoClient().listPaidMediaAudiences(opts.customerId, opts.provider);
2842
+ if (opts.json) {
2843
+ print(result);
2844
+ return;
2845
+ }
2846
+ console.log(`${result.provider} customer ${result.customer_id}: ${result.status}`);
2847
+ console.log(`lists: ${result.list_presence}; attachments: ${result.attachment_state}`);
2848
+ for (const list of result.lists) {
2849
+ console.log(`${list.id} ${list.name} ${list.type} ${list.membership_status} ${list.population_state} search=${list.size_for_search ?? "unknown"} display=${list.size_for_display ?? "unknown"}`);
2850
+ }
2851
+ for (const link of result.attachments) {
2852
+ console.log(`${link.campaign_id}${link.ad_group_id ? "/" + link.ad_group_id : ""} ${link.user_list_resource_name} ${link.negative ? "EXCLUSION" : link.mode} ${link.enabled ? "enabled" : "inactive"}`);
2853
+ }
2854
+ for (const read of result.reads) {
2855
+ if (read.status !== "available") console.log(`${read.resource}: ${read.status} \u2014 ${read.error}`);
2856
+ }
2857
+ console.log(`Customer Match: ${result.customer_match.status} \u2014 ${result.customer_match.detail}`);
2858
+ for (const fact of result.facts) console.log(fact);
2859
+ } catch (e) {
2860
+ fail(e);
2861
+ }
2862
+ });
2782
2863
  var paidMediaCampaigns = paidMedia.command("campaigns").description("Google Ads campaigns and their conversion goals");
2864
+ paidMedia.command("audience-mode <campaignId>").description("Set audience Observation or Targeting, preserving other targeting dimensions (approval-gated)").requiredOption("--customer-id <id>", "Google Ads customer ID").requiredOption("--mode <mode>", "observation or targeting").option("--adgroup-id <id>", "update this ad group instead of its parent campaign").option("--reason <text>", "reason shown on the approval card").action(async (campaignId, opts) => {
2865
+ try {
2866
+ if (opts.mode !== "observation" && opts.mode !== "targeting") throw new Error("--mode must be observation or targeting");
2867
+ print(await new ErdoClient().setPaidMediaAudienceMode(campaignId, {
2868
+ provider: "google_ads",
2869
+ customer_id: opts.customerId,
2870
+ adgroup_id: opts.adgroupId,
2871
+ mode: opts.mode,
2872
+ reason: opts.reason
2873
+ }));
2874
+ } catch (e) {
2875
+ fail(e);
2876
+ }
2877
+ });
2783
2878
  paidMediaCampaigns.command("list").description("List the organization's owned Google Ads campaigns and owned conversion actions").option("--customer-id <id>", "Google Ads customer id (defaults to the selected account)").option("--json", "print the raw JSON result").action(async (opts) => {
2784
2879
  try {
2785
2880
  const result = await new ErdoClient().listPaidMediaCampaigns(opts.customerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.157.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": {