@erdoai/cli 0.198.0 → 0.199.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.
Files changed (2) hide show
  1. package/dist/index.js +98 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14,6 +14,23 @@ function advertiserVerificationAction(container) {
14
14
  }
15
15
 
16
16
  // src/refresh.ts
17
+ function keepRunningCommand(state) {
18
+ return `erdo datasets refresh keep-running ${state.dataset_slug || "<slug>"}`;
19
+ }
20
+ function day(stamp) {
21
+ return stamp ? stamp.slice(0, 10) : void 0;
22
+ }
23
+ function describeAutoPause(state) {
24
+ if (state.job_state !== "auto_paused") return void 0;
25
+ const since = day(state.dormant_since);
26
+ const evidence = since ? `dormant since ${since}${state.days_without_reads !== void 0 ? `, no reads for ${state.days_without_reads} days` : ""}` : "nothing read, opened or ran its data for 14 days";
27
+ return `auto-paused (${evidence}) \u2014 reading the dataset, running it, or \`${keepRunningCommand(state)}\` resumes it`;
28
+ }
29
+ function describePendingPause(state) {
30
+ if (state.job_state !== "active" || state.keep_running || !state.pauses_after) return void 0;
31
+ const since = day(state.dormant_since);
32
+ return `pauses after ${state.pauses_after} unless its data is read or run${since ? ` (unused since ${since})` : ""} \u2014 keep it with \`${keepRunningCommand(state)}\``;
33
+ }
17
34
  function describeRefreshTrigger(state) {
18
35
  const event = describeEventTriggers(state);
19
36
  if (state.disarmed) return event ? `disarmed \u2014 the experiment has settled; ${event}` : "disarmed \u2014 the experiment has settled";
@@ -21,6 +38,8 @@ function describeRefreshTrigger(state) {
21
38
  if (state.strategy === "live_native_poll") return event ? `not running \u2014 native polling is unavailable; ${event}` : "not running \u2014 native polling is unavailable; configure script_js with a schedule or live_webhook";
22
39
  if (!state.job_id) return event ? `not running \u2014 no linked job; ${event}` : "not running \u2014 no linked job; configure the refresh again";
23
40
  if (state.activation_pending) return event ? `not running \u2014 activation pending; retry the complete configuration; ${event}` : "not running \u2014 activation pending; retry the complete configuration";
41
+ const autoPaused = describeAutoPause(state);
42
+ if (state.job_enabled === false && autoPaused) return event ? `not running \u2014 ${autoPaused}; ${event}` : `not running \u2014 ${autoPaused}`;
24
43
  if (state.job_enabled === false) return event ? `not running \u2014 the linked job is disabled; ${event}` : "not running \u2014 the linked job is disabled";
25
44
  const trigger = state.schedule ? state.schedule_enabled === false ? `cron ${state.schedule} is disabled` : `cron: ${state.schedule}` : state.refresh_on_view_enabled !== false ? "runs on view \u2014 when a bound page is opened and the data is stale" : event ? void 0 : "manual only \u2014 page views do not trigger this refresh";
26
45
  return [trigger, event, state.test_run_success === false ? "configuration test failed" : void 0].filter(Boolean).join("; ");
@@ -53,6 +72,13 @@ function describeRefreshWrites(strategy, mode, key, liveMode) {
53
72
  if (strategy?.startsWith("live_")) return liveMode === "append" ? "append \u2014 each incoming event adds rows" : "replace \u2014 each incoming event replaces the current rows";
54
73
  return mode === "upsert" ? `upsert${key ? ` on ${key}` : ""} \u2014 rows outside what the recipe returns are kept` : "replace \u2014 rows the recipe does not return are deleted";
55
74
  }
75
+ function formatRefreshJobRow(r) {
76
+ const notes = [];
77
+ if (r.state === "auto_paused") notes.push(`auto-paused${r.auto_paused_at ? ` since ${r.auto_paused_at.slice(0, 10)}` : ""} for being unread`);
78
+ if (r.state === "active" && r.pauses_after && !r.keep_running) notes.push(`pauses after ${r.pauses_after}`);
79
+ if (r.keep_running) notes.push("keep-running");
80
+ return `${r.id} ${r.state} ${r.name} refresh${notes.length ? ` ${notes.join("; ")}` : ""}`;
81
+ }
56
82
 
57
83
  // src/index.ts
58
84
  import { readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
@@ -1840,6 +1866,14 @@ var ErdoClient = class {
1840
1866
  `/v1/datasets/${encodeURIComponent(slug)}/refresh/run`
1841
1867
  );
1842
1868
  }
1869
+ // Mark the refresh keep-running so the dormancy pause never stands it down,
1870
+ // and resume it if it is already auto-paused. Idempotent.
1871
+ keepDatasetRefreshRunning(slug) {
1872
+ return this.request(
1873
+ "POST",
1874
+ `/v1/datasets/${encodeURIComponent(slug)}/refresh/keep-running`
1875
+ );
1876
+ }
1843
1877
  // --- lead identity ---
1844
1878
  // Preview or perform a dataset's permanent-lead-identity migration: give every
1845
1879
  // pipeline writer the producer contract, backfill the IDs, and publish the
@@ -2119,8 +2153,8 @@ var ErdoClient = class {
2119
2153
  return this.request("GET", `/v1/knowledge/${encodeURIComponent(objectID)}/attachments`);
2120
2154
  }
2121
2155
  // --- automations (heartbeats) ---
2122
- listHeartbeats() {
2123
- return this.request("GET", "/v1/heartbeats");
2156
+ listHeartbeats(opts = {}) {
2157
+ return this.request("GET", opts.includeRefresh ? "/v1/heartbeats?include_refresh=true" : "/v1/heartbeats");
2124
2158
  }
2125
2159
  createHeartbeat(body) {
2126
2160
  return this.request("POST", "/v1/heartbeats", body);
@@ -3162,13 +3196,21 @@ paidMedia.command("audiences").description("Read live audience lists, eligibilit
3162
3196
  fail(e);
3163
3197
  }
3164
3198
  });
3165
- paidMedia.command("negative-coverage").description("Read live Google Ads negative keyword coverage. Does not add or remove keywords").option("--provider <provider>", "ad platform", "google_ads").option("--customer-id <id>", "Google Ads customer id (defaults to the selected account)").option("--campaign-id <id>", "one Search campaign; omit to read Search campaigns in the account").option("--json", "print the raw JSON result, including unreadable scopes").action(async (opts) => {
3199
+ paidMedia.command("negative-coverage").description("Read live Google Ads negative keyword coverage. Does not add or remove keywords").option("--provider <provider>", "ad platform", "google_ads").option("--customer-id <id>", "Google Ads customer id (defaults to the selected account)").option("--campaign-id <id>", "one Search campaign; omit to read Search campaigns in the account").option(
3200
+ "--negative-plan <json|@file>",
3201
+ "compare one campaign against a plan: {classes:[{id,label,terms:[{text,match_type}]}],protected_queries:[...]} from the offer's industry skill"
3202
+ ).option("--json", "print the raw JSON result, including unreadable scopes").action(async (opts) => {
3166
3203
  try {
3167
- const result = await new ErdoClient().auditPaidMediaNegativeCoverage({
3204
+ const input = {
3168
3205
  provider: opts.provider,
3169
3206
  customer_id: opts.customerId,
3170
3207
  campaign_id: opts.campaignId
3171
- });
3208
+ };
3209
+ if (opts.negativePlan !== void 0) {
3210
+ if (!opts.campaignId) throw new Error("--negative-plan compares one campaign; pass --campaign-id");
3211
+ input.negative_plan = parseNegativePlan(readMaybeFile(opts.negativePlan) ?? "");
3212
+ }
3213
+ const result = await new ErdoClient().auditPaidMediaNegativeCoverage(input);
3172
3214
  if (opts.json) {
3173
3215
  print(result);
3174
3216
  return;
@@ -3225,6 +3267,18 @@ paidMediaCampaigns.command("list").description("List the organization's owned Go
3225
3267
  fail(e);
3226
3268
  }
3227
3269
  });
3270
+ function parseNegativePlan(raw) {
3271
+ let parsed;
3272
+ try {
3273
+ parsed = JSON.parse(raw);
3274
+ } catch {
3275
+ throw new Error("--negative-plan must be JSON or @file containing JSON");
3276
+ }
3277
+ if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.classes)) {
3278
+ throw new Error("--negative-plan must be an object with a classes array");
3279
+ }
3280
+ return parsed;
3281
+ }
3228
3282
  function parsePaidMediaBool(value, name) {
3229
3283
  if (value === "true") return true;
3230
3284
  if (value === "false") return false;
@@ -3313,16 +3367,16 @@ paidMediaCampaigns.command("conversion-goals <campaignId>").description("Set a c
3313
3367
  fail(e);
3314
3368
  }
3315
3369
  });
3316
- paidMedia.command("conversion-actions").command("ensure").description("Find or approval-gate creation of an offline lead conversion action").requiredOption("--name <name>", "exact Google Ads conversion action name").option("--category <category>", "QUALIFIED_LEAD or SUBMIT_LEAD_FORM", "QUALIFIED_LEAD").option("--customer-id <id>", "Google Ads customer id (defaults to the selected account)").option("--json", "print the raw JSON result").action(async (opts) => {
3370
+ paidMedia.command("conversion-actions").command("ensure").description("Find or approval-gate creation of an offline conversion upload action").requiredOption("--name <name>", "exact Google Ads conversion action name").option(
3371
+ "--category <category>",
3372
+ "Google Ads conversion category for the outcome, e.g. PURCHASE, SIGNUP, SUBSCRIBE_PAID, SUBMIT_LEAD_FORM or QUALIFIED_LEAD (server default QUALIFIED_LEAD)"
3373
+ ).option("--customer-id <id>", "Google Ads customer id (defaults to the selected account)").option("--json", "print the raw JSON result").action(async (opts) => {
3317
3374
  try {
3318
- if (opts.category && opts.category !== "QUALIFIED_LEAD" && opts.category !== "SUBMIT_LEAD_FORM") {
3319
- fail(new Error("--category must be QUALIFIED_LEAD or SUBMIT_LEAD_FORM"));
3320
- }
3321
3375
  const body = {
3322
3376
  name: opts.name,
3323
3377
  type: "UPLOAD_CLICKS"
3324
3378
  };
3325
- if (opts.category) body.category = opts.category;
3379
+ if (opts.category) body.category = opts.category.trim().toUpperCase();
3326
3380
  if (opts.customerId) body.customer_id = opts.customerId;
3327
3381
  const result = await new ErdoClient().ensurePaidMediaConversionAction(body);
3328
3382
  if (opts.json) {
@@ -3825,8 +3879,8 @@ managed.command("performance").description(
3825
3879
  const cell = (v, digits = 0) => v === null ? "-" : v.toFixed(digits);
3826
3880
  const total = (days, pick) => {
3827
3881
  let sum = 0;
3828
- for (const day of days) {
3829
- const v = pick(day);
3882
+ for (const day2 of days) {
3883
+ const v = pick(day2);
3830
3884
  if (v === null) return null;
3831
3885
  sum += v;
3832
3886
  }
@@ -3835,16 +3889,16 @@ managed.command("performance").description(
3835
3889
  if (opts.daily) {
3836
3890
  const rows = [];
3837
3891
  for (const org2 of res.organizations) {
3838
- for (const day of org2.days) {
3892
+ for (const day2 of org2.days) {
3839
3893
  rows.push([
3840
3894
  org2.organization_slug,
3841
- day.date,
3842
- cell(day.spend, 2),
3843
- cell(day.clicks),
3844
- cell(day.visits),
3845
- cell(day.form_starts),
3846
- cell(day.leads_on_page),
3847
- cell(day.leads_captured)
3895
+ day2.date,
3896
+ cell(day2.spend, 2),
3897
+ cell(day2.clicks),
3898
+ cell(day2.visits),
3899
+ cell(day2.form_starts),
3900
+ cell(day2.leads_on_page),
3901
+ cell(day2.leads_captured)
3848
3902
  ]);
3849
3903
  }
3850
3904
  }
@@ -8933,6 +8987,9 @@ refreshCmd.command("show <slug>").description(
8933
8987
  if (res.experiment_run_id) rows.push(["experiment", res.experiment_run_id]);
8934
8988
  rows.push(["writes", describeRefreshWrites(res.strategy, res.refresh_mode, res.key_column, res.live_write_mode)]);
8935
8989
  rows.push(["trigger", describeRefreshTrigger(res)]);
8990
+ const pendingPause = describePendingPause(res);
8991
+ if (pendingPause) rows.push(["pause warning", pendingPause]);
8992
+ if (res.keep_running) rows.push(["keep running", "yes \u2014 never paused for being unread"]);
8936
8993
  const eventTriggers = describeEventTriggers(res);
8937
8994
  if (eventTriggers) rows.push(["event triggers", eventTriggers]);
8938
8995
  if (res.schedule) {
@@ -9212,6 +9269,22 @@ refreshCmd.command("run <slug>").description(
9212
9269
  fail(e);
9213
9270
  }
9214
9271
  });
9272
+ refreshCmd.command("keep-running <slug>").description(
9273
+ "Mark a dataset's scheduled refresh keep-running, so Erdo never pauses it for being unread, and resume it now if it was auto-paused. Use it when the data is used somewhere Erdo cannot see. Erdo otherwise pauses a scheduled refresh after 14 days in which nothing read, opened or ran its data, following a 3-day warning."
9274
+ ).option("--json", "print the raw JSON result instead of a summary").action(async (slug, opts) => {
9275
+ try {
9276
+ const res = await new ErdoClient().keepDatasetRefreshRunning(slug);
9277
+ if (opts.json) {
9278
+ print(res);
9279
+ return;
9280
+ }
9281
+ console.log(`${res.dataset_slug}: refresh marked keep-running \u2014 it will not be paused for being unread`);
9282
+ if (res.resumed) console.log("It was auto-paused and has been resumed.");
9283
+ console.log(`job: ${res.job_id} (${res.state})`);
9284
+ } catch (e) {
9285
+ fail(e);
9286
+ }
9287
+ });
9215
9288
  var analytics = program.command("analytics").description("Page analytics \u2014 what is tracking your published pages, and how they perform with real visitors");
9216
9289
  analytics.command("query <hogql>").description("Run a read-only HogQL query against this org's page-analytics events").option("--json", "print the raw JSON result instead of a table").action(async (hogql, opts) => {
9217
9290
  try {
@@ -10608,10 +10681,13 @@ autoCmd.command("create <name>").description(
10608
10681
  }
10609
10682
  }
10610
10683
  );
10611
- autoCmd.command("list").description("List automations").action(async () => {
10684
+ autoCmd.command("list").description("List automations").option("--include-refresh", "Also list dataset refresh jobs with their state, including auto-paused ones and any that will pause soon").action(async (opts) => {
10612
10685
  try {
10613
- const { heartbeats } = await new ErdoClient().listHeartbeats();
10686
+ const { heartbeats, refreshes } = await new ErdoClient().listHeartbeats({ includeRefresh: opts.includeRefresh });
10614
10687
  for (const h of heartbeats) console.log(`${h.id} ${h.state} ${h.name} ${h.kind === "script" ? "script" : h.thread_id ? `thread:${h.thread_id}` : h.conversation ?? "new"}${h.persona_id ? ` persona:${h.persona_id}` : ""}${h.model ? ` model:${h.model}` : ""}${heartbeatBounds(h)}`);
10688
+ if (opts.includeRefresh) {
10689
+ for (const r of refreshes ?? []) console.log(formatRefreshJobRow(r));
10690
+ }
10615
10691
  } catch (e) {
10616
10692
  fail(e);
10617
10693
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.198.0",
3
+ "version": "0.199.1",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {