@koda-sl/baker-cli 0.23.0 → 0.25.0-dev.55a07065
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.
- package/README.md +96 -0
- package/dist/cli.js +1 -1
- package/dist/commands/ads/index.d.ts.map +1 -1
- package/dist/commands/ads/index.js +8 -2
- package/dist/commands/ads/index.js.map +1 -1
- package/dist/commands/ads/meta/account.d.ts +11 -0
- package/dist/commands/ads/meta/account.d.ts.map +1 -0
- package/dist/commands/ads/meta/account.js +32 -0
- package/dist/commands/ads/meta/account.js.map +1 -0
- package/dist/commands/ads/meta/accounts.d.ts +20 -0
- package/dist/commands/ads/meta/accounts.d.ts.map +1 -0
- package/dist/commands/ads/meta/accounts.js +55 -0
- package/dist/commands/ads/meta/accounts.js.map +1 -0
- package/dist/commands/ads/meta/activities.d.ts +24 -0
- package/dist/commands/ads/meta/activities.d.ts.map +1 -0
- package/dist/commands/ads/meta/activities.js +44 -0
- package/dist/commands/ads/meta/activities.js.map +1 -0
- package/dist/commands/ads/meta/ads.d.ts +36 -0
- package/dist/commands/ads/meta/ads.d.ts.map +1 -0
- package/dist/commands/ads/meta/ads.js +57 -0
- package/dist/commands/ads/meta/ads.js.map +1 -0
- package/dist/commands/ads/meta/adsets.d.ts +32 -0
- package/dist/commands/ads/meta/adsets.d.ts.map +1 -0
- package/dist/commands/ads/meta/adsets.js +50 -0
- package/dist/commands/ads/meta/adsets.js.map +1 -0
- package/dist/commands/ads/meta/audiences.d.ts +20 -0
- package/dist/commands/ads/meta/audiences.d.ts.map +1 -0
- package/dist/commands/ads/meta/audiences.js +41 -0
- package/dist/commands/ads/meta/audiences.js.map +1 -0
- package/dist/commands/ads/meta/businesses.d.ts +12 -0
- package/dist/commands/ads/meta/businesses.d.ts.map +1 -0
- package/dist/commands/ads/meta/businesses.js +35 -0
- package/dist/commands/ads/meta/businesses.js.map +1 -0
- package/dist/commands/ads/meta/campaigns.d.ts +28 -0
- package/dist/commands/ads/meta/campaigns.d.ts.map +1 -0
- package/dist/commands/ads/meta/campaigns.js +51 -0
- package/dist/commands/ads/meta/campaigns.js.map +1 -0
- package/dist/commands/ads/meta/catalogs.d.ts +17 -0
- package/dist/commands/ads/meta/catalogs.d.ts.map +1 -0
- package/dist/commands/ads/meta/catalogs.js +37 -0
- package/dist/commands/ads/meta/catalogs.js.map +1 -0
- package/dist/commands/ads/meta/creatives.d.ts +24 -0
- package/dist/commands/ads/meta/creatives.d.ts.map +1 -0
- package/dist/commands/ads/meta/creatives.js +51 -0
- package/dist/commands/ads/meta/creatives.js.map +1 -0
- package/dist/commands/ads/meta/currency.d.ts +11 -0
- package/dist/commands/ads/meta/currency.d.ts.map +1 -0
- package/dist/commands/ads/meta/currency.js +31 -0
- package/dist/commands/ads/meta/currency.js.map +1 -0
- package/dist/commands/ads/meta/high-demand-periods.d.ts +17 -0
- package/dist/commands/ads/meta/high-demand-periods.d.ts.map +1 -0
- package/dist/commands/ads/meta/high-demand-periods.js +33 -0
- package/dist/commands/ads/meta/high-demand-periods.js.map +1 -0
- package/dist/commands/ads/meta/images.d.ts +24 -0
- package/dist/commands/ads/meta/images.d.ts.map +1 -0
- package/dist/commands/ads/meta/images.js +45 -0
- package/dist/commands/ads/meta/images.js.map +1 -0
- package/dist/commands/ads/meta/index.d.ts +17 -0
- package/dist/commands/ads/meta/index.d.ts.map +1 -0
- package/dist/commands/ads/meta/index.js +79 -0
- package/dist/commands/ads/meta/index.js.map +1 -0
- package/dist/commands/ads/meta/insights.d.ts +93 -0
- package/dist/commands/ads/meta/insights.d.ts.map +1 -0
- package/dist/commands/ads/meta/insights.js +254 -0
- package/dist/commands/ads/meta/insights.js.map +1 -0
- package/dist/commands/ads/meta/labels.d.ts +16 -0
- package/dist/commands/ads/meta/labels.d.ts.map +1 -0
- package/dist/commands/ads/meta/labels.js +34 -0
- package/dist/commands/ads/meta/labels.js.map +1 -0
- package/dist/commands/ads/meta/pixels.d.ts +33 -0
- package/dist/commands/ads/meta/pixels.d.ts.map +1 -0
- package/dist/commands/ads/meta/pixels.js +69 -0
- package/dist/commands/ads/meta/pixels.js.map +1 -0
- package/dist/commands/ads/meta/presets.d.ts +30 -0
- package/dist/commands/ads/meta/presets.d.ts.map +1 -0
- package/dist/commands/ads/meta/presets.js +86 -0
- package/dist/commands/ads/meta/presets.js.map +1 -0
- package/dist/commands/ads/meta/preview.d.ts +32 -0
- package/dist/commands/ads/meta/preview.d.ts.map +1 -0
- package/dist/commands/ads/meta/preview.js +90 -0
- package/dist/commands/ads/meta/preview.js.map +1 -0
- package/dist/commands/ads/meta/shared.d.ts +18 -0
- package/dist/commands/ads/meta/shared.d.ts.map +1 -0
- package/dist/commands/ads/meta/shared.js +74 -0
- package/dist/commands/ads/meta/shared.js.map +1 -0
- package/dist/commands/ads/meta/studies.d.ts +24 -0
- package/dist/commands/ads/meta/studies.d.ts.map +1 -0
- package/dist/commands/ads/meta/studies.js +56 -0
- package/dist/commands/ads/meta/studies.js.map +1 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +1 -0
- package/dist/env.js.map +1 -1
- package/dist/error-handler.d.ts +1 -1
- package/dist/error-handler.d.ts.map +1 -1
- package/dist/error-handler.js +3 -0
- package/dist/error-handler.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export declare const insightsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly object: {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "Object ID — act_<id> for account, or a campaign/adset/ad ID";
|
|
5
|
+
readonly required: true;
|
|
6
|
+
};
|
|
7
|
+
readonly level: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "account|campaign|adset|ad (default: account)";
|
|
10
|
+
};
|
|
11
|
+
readonly intent: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
readonly description: "baseline|revenue|funnel|ranking|video|identity (default: baseline)";
|
|
14
|
+
};
|
|
15
|
+
readonly fields: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
readonly description: "Comma-separated field list (overrides --intent bundle)";
|
|
18
|
+
};
|
|
19
|
+
readonly "list-intents": {
|
|
20
|
+
readonly type: "boolean";
|
|
21
|
+
readonly description: "Print available intents and exit";
|
|
22
|
+
};
|
|
23
|
+
readonly "date-preset": {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly description: "Meta date preset (last_7d, last_28d, today, ...)";
|
|
26
|
+
};
|
|
27
|
+
readonly since: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly description: "Custom start date YYYY-MM-DD";
|
|
30
|
+
};
|
|
31
|
+
readonly until: {
|
|
32
|
+
readonly type: "string";
|
|
33
|
+
readonly description: "Custom end date YYYY-MM-DD";
|
|
34
|
+
};
|
|
35
|
+
readonly "time-increment": {
|
|
36
|
+
readonly type: "string";
|
|
37
|
+
readonly description: "1 (day) | monthly | all_days";
|
|
38
|
+
};
|
|
39
|
+
readonly breakdowns: {
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
readonly description: "Comma-separated breakdowns (e.g. publisher_platform,age)";
|
|
42
|
+
};
|
|
43
|
+
readonly "action-breakdowns": {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
readonly description: "Slice the actions[] array (default: action_type for revenue/funnel)";
|
|
46
|
+
};
|
|
47
|
+
readonly filtering: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
readonly description: "Override default filter — JSON array of {field,operator,value}";
|
|
50
|
+
};
|
|
51
|
+
readonly "include-undelivered": {
|
|
52
|
+
readonly type: "boolean";
|
|
53
|
+
readonly description: "Keep rows where impressions=0 (off by default)";
|
|
54
|
+
};
|
|
55
|
+
readonly "attribution-windows": {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
readonly description: "Override default 7d_click,1d_view (only 1d_view, 1d_click, 7d_click, 28d_click work post Jan 2026)";
|
|
58
|
+
};
|
|
59
|
+
readonly "use-account-attribution": {
|
|
60
|
+
readonly type: "boolean";
|
|
61
|
+
readonly description: "Use account-saved attribution setting";
|
|
62
|
+
};
|
|
63
|
+
readonly "use-unified-attribution": {
|
|
64
|
+
readonly type: "boolean";
|
|
65
|
+
readonly description: "Use ad-set unified attribution setting";
|
|
66
|
+
};
|
|
67
|
+
readonly limit: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
readonly description: "Max rows (default 1000)";
|
|
70
|
+
};
|
|
71
|
+
readonly async: {
|
|
72
|
+
readonly type: "boolean";
|
|
73
|
+
readonly description: "Force async submit-and-poll path";
|
|
74
|
+
};
|
|
75
|
+
readonly "no-async": {
|
|
76
|
+
readonly type: "boolean";
|
|
77
|
+
readonly description: "Refuse the auto-async fallback for heavy queries";
|
|
78
|
+
};
|
|
79
|
+
readonly "no-sort": {
|
|
80
|
+
readonly type: "boolean";
|
|
81
|
+
readonly description: "Skip default spend-desc sort";
|
|
82
|
+
};
|
|
83
|
+
readonly "skip-cache": {
|
|
84
|
+
readonly type: "boolean";
|
|
85
|
+
readonly description: "Bypass server-side cache";
|
|
86
|
+
};
|
|
87
|
+
readonly output: {
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
readonly description: "Output format";
|
|
90
|
+
readonly default: "json";
|
|
91
|
+
};
|
|
92
|
+
}>;
|
|
93
|
+
//# sourceMappingURL=insights.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insights.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/meta/insights.ts"],"names":[],"mappings":"AAwLA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiG1B,CAAC"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { apiPost } from "../../../client.js";
|
|
3
|
+
import { writeAdsJson, writeAdsOutput } from "../output.js";
|
|
4
|
+
import { composeFields, getIntent, listIntents } from "./presets.js";
|
|
5
|
+
import { csvOrJson, getDateRange, handleMetaError } from "./shared.js";
|
|
6
|
+
const POLL_INTERVAL_MS = 5_000;
|
|
7
|
+
const POLL_MAX_MS = 10 * 60_000;
|
|
8
|
+
/** Default attribution windows — only these still work as of Jan 2026 (1d_view + 28d_click also valid but rarely used). */
|
|
9
|
+
const DEFAULT_ATTRIBUTION_WINDOWS = ["7d_click", "1d_view"];
|
|
10
|
+
/** Default filter — strip rows that didn't deliver. Almost always what we want. */
|
|
11
|
+
const DEFAULT_FILTERING = [{ field: "impressions", operator: "GREATER_THAN", value: 0 }];
|
|
12
|
+
function commaSplit(input) {
|
|
13
|
+
if (!input)
|
|
14
|
+
return undefined;
|
|
15
|
+
return input
|
|
16
|
+
.split(",")
|
|
17
|
+
.map((s) => s.trim())
|
|
18
|
+
.filter(Boolean);
|
|
19
|
+
}
|
|
20
|
+
function parseFiltering(raw) {
|
|
21
|
+
if (!raw)
|
|
22
|
+
return undefined;
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
handleMetaError(new Error("Invalid --filtering JSON"));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function pickIntent(name) {
|
|
31
|
+
if (!name)
|
|
32
|
+
return "baseline";
|
|
33
|
+
const found = getIntent(name);
|
|
34
|
+
if (!found) {
|
|
35
|
+
handleMetaError(new Error(`Unknown --intent: ${name}. Use --list-intents to see options.`));
|
|
36
|
+
}
|
|
37
|
+
return found.name;
|
|
38
|
+
}
|
|
39
|
+
function pickLevel(args) {
|
|
40
|
+
const raw = args.level;
|
|
41
|
+
if (!raw)
|
|
42
|
+
return "account";
|
|
43
|
+
if (raw !== "account" && raw !== "campaign" && raw !== "adset" && raw !== "ad") {
|
|
44
|
+
handleMetaError(new Error("--level must be one of: account|campaign|adset|ad"));
|
|
45
|
+
}
|
|
46
|
+
return raw;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Auto-async heuristic. Heavy queries that would time out as sync go async
|
|
50
|
+
* automatically — the user shouldn't have to think about it.
|
|
51
|
+
*
|
|
52
|
+
* - level=ad with breakdowns
|
|
53
|
+
* - >2 breakdowns at any level
|
|
54
|
+
* - explicit time range > 90 days
|
|
55
|
+
* - level=ad over an account-level object with a wide window
|
|
56
|
+
*/
|
|
57
|
+
function shouldAutoAsync(body) {
|
|
58
|
+
const breakdownCount = (body.breakdowns ?? []).length;
|
|
59
|
+
if (body.level === "ad" && breakdownCount > 0 && body.object.startsWith("act_")) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (breakdownCount > 2) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (body.since && body.until) {
|
|
66
|
+
const days = (Date.parse(body.until) - Date.parse(body.since)) / 86_400_000;
|
|
67
|
+
if (days > 90) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
function applyDateRange(body, args) {
|
|
74
|
+
const range = getDateRange(args);
|
|
75
|
+
if (range.datePreset)
|
|
76
|
+
body.datePreset = range.datePreset;
|
|
77
|
+
if (range.since)
|
|
78
|
+
body.since = range.since;
|
|
79
|
+
if (range.until)
|
|
80
|
+
body.until = range.until;
|
|
81
|
+
if (!body.datePreset && !(body.since && body.until)) {
|
|
82
|
+
body.datePreset = "last_7d";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function buildFiltering(args) {
|
|
86
|
+
const explicit = parseFiltering(args.filtering);
|
|
87
|
+
if (explicit)
|
|
88
|
+
return explicit;
|
|
89
|
+
if (args["include-undelivered"])
|
|
90
|
+
return undefined;
|
|
91
|
+
return DEFAULT_FILTERING;
|
|
92
|
+
}
|
|
93
|
+
function buildAttributionWindows(args) {
|
|
94
|
+
const explicit = commaSplit(args["attribution-windows"]);
|
|
95
|
+
if (explicit)
|
|
96
|
+
return explicit;
|
|
97
|
+
return DEFAULT_ATTRIBUTION_WINDOWS;
|
|
98
|
+
}
|
|
99
|
+
function buildBody(args) {
|
|
100
|
+
const intent = pickIntent(args.intent);
|
|
101
|
+
const level = pickLevel(args);
|
|
102
|
+
const intentDef = getIntent(intent);
|
|
103
|
+
const explicitFields = commaSplit(args.fields);
|
|
104
|
+
const fields = explicitFields ?? composeFields(intent, level);
|
|
105
|
+
const breakdowns = commaSplit(args.breakdowns);
|
|
106
|
+
const actionBreakdowns = commaSplit(args["action-breakdowns"]) ?? intentDef?.actionBreakdowns;
|
|
107
|
+
const body = {
|
|
108
|
+
object: args.object,
|
|
109
|
+
level,
|
|
110
|
+
fields,
|
|
111
|
+
timeIncrement: args["time-increment"],
|
|
112
|
+
breakdowns,
|
|
113
|
+
actionBreakdowns,
|
|
114
|
+
filtering: buildFiltering(args),
|
|
115
|
+
attributionWindows: buildAttributionWindows(args),
|
|
116
|
+
useAccountAttributionSetting: Boolean(args["use-account-attribution"]),
|
|
117
|
+
useUnifiedAttributionSetting: Boolean(args["use-unified-attribution"]),
|
|
118
|
+
limit: args.limit ? Number(args.limit) : 1000,
|
|
119
|
+
skipCache: Boolean(args["skip-cache"]),
|
|
120
|
+
};
|
|
121
|
+
applyDateRange(body, args);
|
|
122
|
+
return body;
|
|
123
|
+
}
|
|
124
|
+
async function pollAsync(reportRunId) {
|
|
125
|
+
const start = Date.now();
|
|
126
|
+
while (Date.now() - start < POLL_MAX_MS) {
|
|
127
|
+
const status = await apiPost(`/api/ads/meta/insights/async/status?report-run-id=${encodeURIComponent(reportRunId)}`, {});
|
|
128
|
+
if (status.async_status === "Job Completed")
|
|
129
|
+
return;
|
|
130
|
+
if (status.async_status === "Job Failed" || status.async_status === "Job Skipped") {
|
|
131
|
+
handleMetaError(new Error(`Async insights job ${status.async_status}`));
|
|
132
|
+
}
|
|
133
|
+
process.stderr.write(`Async insights ${status.async_status ?? "queued"} (${Math.round(status.async_percent_completion ?? 0)}%)…\n`);
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
135
|
+
}
|
|
136
|
+
handleMetaError(new Error("Async insights polling timed out after 10 minutes"));
|
|
137
|
+
}
|
|
138
|
+
async function runAsync(body) {
|
|
139
|
+
const submit = await apiPost("/api/ads/meta/insights/async", body);
|
|
140
|
+
process.stderr.write(`Async insights job: ${submit.reportRunId}\n`);
|
|
141
|
+
await pollAsync(submit.reportRunId);
|
|
142
|
+
return apiPost("/api/ads/meta/insights/async/result", {
|
|
143
|
+
reportRunId: submit.reportRunId,
|
|
144
|
+
fields: body.fields,
|
|
145
|
+
limit: body.limit,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/** Insights rows have nested `actions[]` arrays. Sort by the named action_type's value descending. */
|
|
149
|
+
function sortRowsBySpendDesc(rows) {
|
|
150
|
+
return [...rows].sort((a, b) => {
|
|
151
|
+
const sa = Number(a.spend ?? 0);
|
|
152
|
+
const sb = Number(b.spend ?? 0);
|
|
153
|
+
if (Number.isNaN(sa) || Number.isNaN(sb))
|
|
154
|
+
return 0;
|
|
155
|
+
return sb - sa;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export const insightsCommand = defineCommand({
|
|
159
|
+
meta: {
|
|
160
|
+
name: "insights",
|
|
161
|
+
description: `Performance reporting — the main Meta tool for AI agents.
|
|
162
|
+
|
|
163
|
+
Smart defaults so the AI doesn't have to remember every flag:
|
|
164
|
+
--level account (set --level campaign|adset|ad to drill in)
|
|
165
|
+
--intent baseline (or revenue|funnel|ranking|video|identity)
|
|
166
|
+
--date-preset last_7d (override with --since/--until)
|
|
167
|
+
--attribution-windows 7d_click,1d_view (the only ones still working post Jan 2026)
|
|
168
|
+
filter: impressions > 0 (skip undelivered rows; --include-undelivered to keep)
|
|
169
|
+
sort: spend descending (when result fits in memory)
|
|
170
|
+
auto-async when query is heavy (level=ad + breakdowns, big date ranges, etc.)
|
|
171
|
+
|
|
172
|
+
Identity fields (campaign_name, ad_name etc.) are appended automatically based on --level so rows
|
|
173
|
+
are self-describing.
|
|
174
|
+
|
|
175
|
+
Examples — common AI questions:
|
|
176
|
+
# "How is GreenLeaf doing this week?"
|
|
177
|
+
baker ads meta insights --object act_123
|
|
178
|
+
|
|
179
|
+
# "Which campaigns are profitable?"
|
|
180
|
+
baker ads meta insights --object act_123 --level campaign --intent revenue --date-preset last_28d
|
|
181
|
+
|
|
182
|
+
# "Which creatives need a refresh?"
|
|
183
|
+
baker ads meta insights --object act_123 --level ad --intent ranking --date-preset last_14d
|
|
184
|
+
|
|
185
|
+
# "Where do users drop off the funnel?"
|
|
186
|
+
baker ads meta insights --object act_123 --intent funnel
|
|
187
|
+
|
|
188
|
+
# "Should we shift budget to Instagram?"
|
|
189
|
+
baker ads meta insights --object act_123 --level adset --breakdowns publisher_platform,platform_position
|
|
190
|
+
|
|
191
|
+
# Custom field set (escape hatch)
|
|
192
|
+
baker ads meta insights --object act_123 --fields impressions,spend,actions
|
|
193
|
+
|
|
194
|
+
Async is automatic for heavy queries; pass --async to force it, or --no-async to refuse fallback.`,
|
|
195
|
+
},
|
|
196
|
+
args: {
|
|
197
|
+
object: {
|
|
198
|
+
type: "string",
|
|
199
|
+
description: "Object ID — act_<id> for account, or a campaign/adset/ad ID",
|
|
200
|
+
required: true,
|
|
201
|
+
},
|
|
202
|
+
level: { type: "string", description: "account|campaign|adset|ad (default: account)" },
|
|
203
|
+
intent: { type: "string", description: "baseline|revenue|funnel|ranking|video|identity (default: baseline)" },
|
|
204
|
+
fields: { type: "string", description: "Comma-separated field list (overrides --intent bundle)" },
|
|
205
|
+
"list-intents": { type: "boolean", description: "Print available intents and exit" },
|
|
206
|
+
"date-preset": { type: "string", description: "Meta date preset (last_7d, last_28d, today, ...)" },
|
|
207
|
+
since: { type: "string", description: "Custom start date YYYY-MM-DD" },
|
|
208
|
+
until: { type: "string", description: "Custom end date YYYY-MM-DD" },
|
|
209
|
+
"time-increment": { type: "string", description: "1 (day) | monthly | all_days" },
|
|
210
|
+
breakdowns: { type: "string", description: "Comma-separated breakdowns (e.g. publisher_platform,age)" },
|
|
211
|
+
"action-breakdowns": {
|
|
212
|
+
type: "string",
|
|
213
|
+
description: "Slice the actions[] array (default: action_type for revenue/funnel)",
|
|
214
|
+
},
|
|
215
|
+
filtering: { type: "string", description: "Override default filter — JSON array of {field,operator,value}" },
|
|
216
|
+
"include-undelivered": { type: "boolean", description: "Keep rows where impressions=0 (off by default)" },
|
|
217
|
+
"attribution-windows": {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "Override default 7d_click,1d_view (only 1d_view, 1d_click, 7d_click, 28d_click work post Jan 2026)",
|
|
220
|
+
},
|
|
221
|
+
"use-account-attribution": { type: "boolean", description: "Use account-saved attribution setting" },
|
|
222
|
+
"use-unified-attribution": { type: "boolean", description: "Use ad-set unified attribution setting" },
|
|
223
|
+
limit: { type: "string", description: "Max rows (default 1000)" },
|
|
224
|
+
async: { type: "boolean", description: "Force async submit-and-poll path" },
|
|
225
|
+
"no-async": { type: "boolean", description: "Refuse the auto-async fallback for heavy queries" },
|
|
226
|
+
"no-sort": { type: "boolean", description: "Skip default spend-desc sort" },
|
|
227
|
+
"skip-cache": { type: "boolean", description: "Bypass server-side cache" },
|
|
228
|
+
output: { type: "string", description: "Output format", default: "json" },
|
|
229
|
+
},
|
|
230
|
+
run: async ({ args }) => {
|
|
231
|
+
if (args["list-intents"]) {
|
|
232
|
+
writeAdsJson({ ok: true, data: listIntents() });
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const body = buildBody(args);
|
|
236
|
+
const fmt = csvOrJson(args);
|
|
237
|
+
const wantAsync = Boolean(args.async) || (!args["no-async"] && shouldAutoAsync(body));
|
|
238
|
+
try {
|
|
239
|
+
const rows = wantAsync
|
|
240
|
+
? await runAsync(body)
|
|
241
|
+
: await apiPost("/api/ads/meta/insights", body);
|
|
242
|
+
const sorted = args["no-sort"] ? rows : sortRowsBySpendDesc(rows);
|
|
243
|
+
if (fmt !== "json") {
|
|
244
|
+
writeAdsOutput(sorted, fmt, body.fields);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
writeAdsJson({ ok: true, data: sorted });
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
handleMetaError(err);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
//# sourceMappingURL=insights.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insights.js","sourceRoot":"","sources":["../../../../src/commands/ads/meta/insights.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAA2C,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvE,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,WAAW,GAAG,EAAE,GAAG,MAAM,CAAC;AAEhC,2HAA2H;AAC3H,MAAM,2BAA2B,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAE5D,mFAAmF;AACnF,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AAoBzF,SAAS,UAAU,CAAC,KAAyB;IAC3C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC;AAED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16 @@
|
|
|
1
|
+
export declare const labelsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "account-id": {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "Meta ad account ID";
|
|
5
|
+
};
|
|
6
|
+
readonly "skip-cache": {
|
|
7
|
+
readonly type: "boolean";
|
|
8
|
+
readonly description: "Bypass server-side cache";
|
|
9
|
+
};
|
|
10
|
+
readonly output: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly description: "Output format";
|
|
13
|
+
readonly default: "json";
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/meta/labels.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;EA0BxB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { apiGet } from "../../../client.js";
|
|
3
|
+
import { writeAdsJson, writeAdsOutput } from "../output.js";
|
|
4
|
+
import { csvOrJson, handleMetaError, resolveAccountIdArg } from "./shared.js";
|
|
5
|
+
export const labelsCommand = defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "labels",
|
|
8
|
+
description: `List ad labels for a Meta ad account.`,
|
|
9
|
+
},
|
|
10
|
+
args: {
|
|
11
|
+
"account-id": { type: "string", description: "Meta ad account ID" },
|
|
12
|
+
"skip-cache": { type: "boolean", description: "Bypass server-side cache" },
|
|
13
|
+
output: { type: "string", description: "Output format", default: "json" },
|
|
14
|
+
},
|
|
15
|
+
run: async ({ args }) => {
|
|
16
|
+
const accountId = resolveAccountIdArg(args);
|
|
17
|
+
try {
|
|
18
|
+
const params = { "account-id": accountId };
|
|
19
|
+
if (args["skip-cache"])
|
|
20
|
+
params["skip-cache"] = "true";
|
|
21
|
+
const data = await apiGet("/api/ads/meta/labels", params);
|
|
22
|
+
const fmt = csvOrJson(args);
|
|
23
|
+
if (fmt !== "json") {
|
|
24
|
+
writeAdsOutput(data, fmt);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
writeAdsJson({ ok: true, data });
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
handleMetaError(err);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","sourceRoot":"","sources":["../../../../src/commands/ads/meta/labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE9E,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;IACzC,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,uCAAuC;KACrD;IACD,IAAI,EAAE;QACJ,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,oBAAoB,EAAE;QACnE,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,0BAA0B,EAAE;QAC1E,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE;KAC1E;IACD,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACtB,MAAM,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,MAAM,GAA2B,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;YACnE,IAAI,IAAI,CAAC,YAAY,CAAC;gBAAE,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC;YACtD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAiC,sBAAsB,EAAE,MAAM,CAAC,CAAC;YAC1F,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;gBACnB,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;gBAC1B,OAAO;YACT,CAAC;YACD,YAAY,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,eAAe,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const pixelsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "account-id": {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "Meta ad account ID";
|
|
5
|
+
};
|
|
6
|
+
readonly "pixel-id": {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly description: "Pixel ID for --stats";
|
|
9
|
+
};
|
|
10
|
+
readonly stats: {
|
|
11
|
+
readonly type: "boolean";
|
|
12
|
+
readonly description: "Fetch firing stats for the pixel";
|
|
13
|
+
};
|
|
14
|
+
readonly aggregation: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
readonly description: "stats aggregation: event|browser_type|host|pixel_fire";
|
|
17
|
+
readonly default: "event";
|
|
18
|
+
};
|
|
19
|
+
readonly days: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
readonly description: "Lookback days for --stats (default 7)";
|
|
22
|
+
};
|
|
23
|
+
readonly "skip-cache": {
|
|
24
|
+
readonly type: "boolean";
|
|
25
|
+
readonly description: "Bypass server-side cache";
|
|
26
|
+
};
|
|
27
|
+
readonly output: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly description: "Output format";
|
|
30
|
+
readonly default: "json";
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
33
|
+
//# sourceMappingURL=pixels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixels.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/meta/pixels.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4DxB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { apiGet } from "../../../client.js";
|
|
3
|
+
import { writeAdsJson, writeAdsOutput } from "../output.js";
|
|
4
|
+
import { csvOrJson, daysAgoIso, handleMetaError, resolveAccountIdArg, todayIso } from "./shared.js";
|
|
5
|
+
export const pixelsCommand = defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "pixels",
|
|
8
|
+
description: `List Meta Pixels for an ad account, or fetch firing stats for one pixel.
|
|
9
|
+
|
|
10
|
+
Examples:
|
|
11
|
+
baker ads meta pixels --account-id act_123
|
|
12
|
+
baker ads meta pixels --account-id act_123 --pixel-id 9876 --stats --days 7`,
|
|
13
|
+
},
|
|
14
|
+
args: {
|
|
15
|
+
"account-id": { type: "string", description: "Meta ad account ID" },
|
|
16
|
+
"pixel-id": { type: "string", description: "Pixel ID for --stats" },
|
|
17
|
+
stats: { type: "boolean", description: "Fetch firing stats for the pixel" },
|
|
18
|
+
aggregation: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "stats aggregation: event|browser_type|host|pixel_fire",
|
|
21
|
+
default: "event",
|
|
22
|
+
},
|
|
23
|
+
days: { type: "string", description: "Lookback days for --stats (default 7)" },
|
|
24
|
+
"skip-cache": { type: "boolean", description: "Bypass server-side cache" },
|
|
25
|
+
output: { type: "string", description: "Output format", default: "json" },
|
|
26
|
+
},
|
|
27
|
+
run: async ({ args }) => {
|
|
28
|
+
try {
|
|
29
|
+
if (args.stats) {
|
|
30
|
+
const pixelId = args["pixel-id"];
|
|
31
|
+
if (!pixelId) {
|
|
32
|
+
handleMetaError(new Error("--pixel-id is required when --stats is set"));
|
|
33
|
+
}
|
|
34
|
+
const days = args.days ? Number(args.days) : 7;
|
|
35
|
+
const params = {
|
|
36
|
+
"pixel-id": pixelId,
|
|
37
|
+
aggregation: args.aggregation ?? "event",
|
|
38
|
+
"start-time": daysAgoIso(days),
|
|
39
|
+
"end-time": todayIso(),
|
|
40
|
+
};
|
|
41
|
+
if (args["skip-cache"])
|
|
42
|
+
params["skip-cache"] = "true";
|
|
43
|
+
const data = await apiGet("/api/ads/meta/pixel-stats", params);
|
|
44
|
+
const fmt = csvOrJson(args);
|
|
45
|
+
if (fmt !== "json") {
|
|
46
|
+
writeAdsOutput(data, fmt);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
writeAdsJson({ ok: true, data });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const accountId = resolveAccountIdArg(args);
|
|
53
|
+
const params = { "account-id": accountId };
|
|
54
|
+
if (args["skip-cache"])
|
|
55
|
+
params["skip-cache"] = "true";
|
|
56
|
+
const data = await apiGet("/api/ads/meta/pixels", params);
|
|
57
|
+
const fmt = csvOrJson(args);
|
|
58
|
+
if (fmt !== "json") {
|
|
59
|
+
writeAdsOutput(data, fmt);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
writeAdsJson({ ok: true, data });
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
handleMetaError(err);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=pixels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixels.js","sourceRoot":"","sources":["../../../../src/commands/ads/meta/pixels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CA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AE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,eAAe,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Insights field bundles. Picked for AI agent ergonomics: small, focused field
|
|
3
|
+
* lists that answer one specific question without forcing the AI to enumerate
|
|
4
|
+
* Meta's 500+ insights fields.
|
|
5
|
+
*
|
|
6
|
+
* Two-axis design:
|
|
7
|
+
* --intent (field bundle, default: baseline) — what data to ask for
|
|
8
|
+
* --level (object granularity, default: account) — at what granularity
|
|
9
|
+
*
|
|
10
|
+
* Intents are independent of level — pass `--intent ranking --level ad` to flag
|
|
11
|
+
* creatives, or `--intent revenue --level campaign` for ROAS by campaign.
|
|
12
|
+
*
|
|
13
|
+
* Identity fields (campaign_name etc.) are appended automatically based on
|
|
14
|
+
* level so the AI can read rows without joining.
|
|
15
|
+
*/
|
|
16
|
+
export type InsightsLevel = "account" | "campaign" | "adset" | "ad";
|
|
17
|
+
export type InsightsIntent = "baseline" | "revenue" | "funnel" | "ranking" | "video" | "identity";
|
|
18
|
+
interface IntentDefinition {
|
|
19
|
+
name: InsightsIntent;
|
|
20
|
+
description: string;
|
|
21
|
+
fields: string[];
|
|
22
|
+
/** Action breakdowns to slice the actions[] array — empty if not needed. */
|
|
23
|
+
actionBreakdowns?: string[];
|
|
24
|
+
}
|
|
25
|
+
/** Compose final field list: intent metrics + level-specific identity fields, deduplicated. */
|
|
26
|
+
export declare function composeFields(intent: InsightsIntent, level: InsightsLevel): string[];
|
|
27
|
+
export declare function getIntent(name: string): IntentDefinition | undefined;
|
|
28
|
+
export declare function listIntents(): IntentDefinition[];
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/meta/presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;AAEpE,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAElG,UAAU,gBAAgB;IACxB,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAsDD,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAYpF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAEpE;AAED,wBAAgB,WAAW,IAAI,gBAAgB,EAAE,CAEhD"}
|