@koda-sl/baker-cli 0.879.0 → 0.881.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.
- package/README.md +5 -1
- package/dist/{account-6EJ22A7X.js → account-AIW3XGWG.js} +2 -2
- package/dist/{account-assets-ZY4UYCHQ.js → account-assets-FJFPB7KD.js} +54 -46
- package/dist/account-assets-FJFPB7KD.js.map +1 -0
- package/dist/{account-level-Z4Z5PUA6.js → account-level-CB6I4X5W.js} +4 -4
- package/dist/{accounts-JILEWVP6.js → accounts-2USPMXA2.js} +2 -2
- package/dist/{activities-JHKNRR3M.js → activities-DYI25TF4.js} +21 -12
- package/dist/activities-DYI25TF4.js.map +1 -0
- package/dist/{ads-7NUK2UOG.js → ads-G3N76HWA.js} +27 -19
- package/dist/ads-G3N76HWA.js.map +1 -0
- package/dist/{ads-SWRPUDVK.js → ads-WERB3QK5.js} +2 -2
- package/dist/{adsets-JF3CBKOU.js → adsets-2HV6TJJP.js} +48 -30
- package/dist/adsets-2HV6TJJP.js.map +1 -0
- package/dist/{asset-writes-HXFRHFWF.js → asset-writes-ZOVD5O5X.js} +4 -4
- package/dist/{audience-writes-PT6RLJAK.js → audience-writes-36E6ECON.js} +29 -15
- package/dist/audience-writes-36E6ECON.js.map +1 -0
- package/dist/{audiences-G3PRPIY4.js → audiences-65JSGH4L.js} +27 -15
- package/dist/audiences-65JSGH4L.js.map +1 -0
- package/dist/{businesses-3N6CTZ2Q.js → businesses-5AEHP23G.js} +2 -2
- package/dist/{campaigns-FN56B6B7.js → campaigns-PP3MFPJR.js} +29 -18
- package/dist/campaigns-PP3MFPJR.js.map +1 -0
- package/dist/{catalogs-N2I2GNHS.js → catalogs-UYYPZRFW.js} +3 -3
- package/dist/{chunk-SNQKL66G.js → chunk-3F6AXSPB.js} +2 -2
- package/dist/{chunk-6MFVGM3F.js → chunk-AMCW2IG7.js} +14 -3
- package/dist/chunk-AMCW2IG7.js.map +1 -0
- package/dist/{chunk-6XXKYTD5.js → chunk-BRHYK4HQ.js} +2 -2
- package/dist/{chunk-2W6ILA5Z.js → chunk-LDL5VBBD.js} +87 -8
- package/dist/chunk-LDL5VBBD.js.map +1 -0
- package/dist/{chunk-JV6O52V6.js → chunk-ZGYIG6OM.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{copy-writes-YXVKXBQC.js → copy-writes-TEJRR2W2.js} +4 -4
- package/dist/{creatives-3AQ3EEUL.js → creatives-ZYY5OF5U.js} +32 -19
- package/dist/creatives-ZYY5OF5U.js.map +1 -0
- package/dist/{custom-conversions-XNYZOJYY.js → custom-conversions-YQPOB2IR.js} +27 -15
- package/dist/custom-conversions-YQPOB2IR.js.map +1 -0
- package/dist/{draft-3P2XHRWX.js → draft-OHAOBGVP.js} +2 -2
- package/dist/{insights-VD4QINO7.js → insights-PBJODKMY.js} +129 -28
- package/dist/insights-PBJODKMY.js.map +1 -0
- package/dist/{instant-experiences-KCAH5ONN.js → instant-experiences-YXH2AHFI.js} +3 -3
- package/dist/{leads-HU4GA6T4.js → leads-IGOXMIEW.js} +3 -3
- package/dist/{media-NHO7QT2A.js → media-QOGVG6CU.js} +3 -3
- package/dist/{meta-SOPDFYYK.js → meta-RJH5COPE.js} +40 -40
- package/dist/{page-photos-6PRIPJJE.js → page-photos-P2XMKTVF.js} +3 -3
- package/dist/{pages-Q4W64A3N.js → pages-O7NXGSBG.js} +2 -2
- package/dist/{pixels-HOOILVHZ.js → pixels-I7S5N76B.js} +26 -12
- package/dist/pixels-I7S5N76B.js.map +1 -0
- package/dist/{preview-3TA3ILQ5.js → preview-5CK5INGO.js} +2 -2
- package/dist/{rule-writes-TKNWMP3S.js → rule-writes-MSMVQDQO.js} +3 -3
- package/dist/{rules-BNNJXDYI.js → rules-UEKJOZTV.js} +41 -24
- package/dist/rules-UEKJOZTV.js.map +1 -0
- package/dist/{shared-3C5ZX44Q.js → shared-PPAWDMRF.js} +16 -4
- package/dist/{studies-5YCUBVK5.js → studies-TIF7PYEB.js} +33 -16
- package/dist/studies-TIF7PYEB.js.map +1 -0
- package/dist/{study-writes-CD3D23LK.js → study-writes-RGKBOOJ6.js} +3 -3
- package/dist/{targeting-BNJVE7XS.js → targeting-YWOOD6YL.js} +3 -3
- package/dist/{videos-RS3G65UV.js → videos-OF6PAPP2.js} +2 -2
- package/dist/{write-commands-PD3BEWWZ.js → write-commands-REUTFNJ3.js} +7 -7
- package/package.json +1 -1
- package/dist/account-assets-ZY4UYCHQ.js.map +0 -1
- package/dist/activities-JHKNRR3M.js.map +0 -1
- package/dist/ads-7NUK2UOG.js.map +0 -1
- package/dist/adsets-JF3CBKOU.js.map +0 -1
- package/dist/audience-writes-PT6RLJAK.js.map +0 -1
- package/dist/audiences-G3PRPIY4.js.map +0 -1
- package/dist/campaigns-FN56B6B7.js.map +0 -1
- package/dist/chunk-2W6ILA5Z.js.map +0 -1
- package/dist/chunk-6MFVGM3F.js.map +0 -1
- package/dist/creatives-3AQ3EEUL.js.map +0 -1
- package/dist/custom-conversions-XNYZOJYY.js.map +0 -1
- package/dist/insights-VD4QINO7.js.map +0 -1
- package/dist/pixels-HOOILVHZ.js.map +0 -1
- package/dist/rules-BNNJXDYI.js.map +0 -1
- package/dist/studies-5YCUBVK5.js.map +0 -1
- /package/dist/{account-6EJ22A7X.js.map → account-AIW3XGWG.js.map} +0 -0
- /package/dist/{account-level-Z4Z5PUA6.js.map → account-level-CB6I4X5W.js.map} +0 -0
- /package/dist/{accounts-JILEWVP6.js.map → accounts-2USPMXA2.js.map} +0 -0
- /package/dist/{ads-SWRPUDVK.js.map → ads-WERB3QK5.js.map} +0 -0
- /package/dist/{asset-writes-HXFRHFWF.js.map → asset-writes-ZOVD5O5X.js.map} +0 -0
- /package/dist/{businesses-3N6CTZ2Q.js.map → businesses-5AEHP23G.js.map} +0 -0
- /package/dist/{catalogs-N2I2GNHS.js.map → catalogs-UYYPZRFW.js.map} +0 -0
- /package/dist/{chunk-SNQKL66G.js.map → chunk-3F6AXSPB.js.map} +0 -0
- /package/dist/{chunk-6XXKYTD5.js.map → chunk-BRHYK4HQ.js.map} +0 -0
- /package/dist/{chunk-JV6O52V6.js.map → chunk-ZGYIG6OM.js.map} +0 -0
- /package/dist/{copy-writes-YXVKXBQC.js.map → copy-writes-TEJRR2W2.js.map} +0 -0
- /package/dist/{draft-3P2XHRWX.js.map → draft-OHAOBGVP.js.map} +0 -0
- /package/dist/{instant-experiences-KCAH5ONN.js.map → instant-experiences-YXH2AHFI.js.map} +0 -0
- /package/dist/{leads-HU4GA6T4.js.map → leads-IGOXMIEW.js.map} +0 -0
- /package/dist/{media-NHO7QT2A.js.map → media-QOGVG6CU.js.map} +0 -0
- /package/dist/{meta-SOPDFYYK.js.map → meta-RJH5COPE.js.map} +0 -0
- /package/dist/{page-photos-6PRIPJJE.js.map → page-photos-P2XMKTVF.js.map} +0 -0
- /package/dist/{pages-Q4W64A3N.js.map → pages-O7NXGSBG.js.map} +0 -0
- /package/dist/{preview-3TA3ILQ5.js.map → preview-5CK5INGO.js.map} +0 -0
- /package/dist/{rule-writes-TKNWMP3S.js.map → rule-writes-MSMVQDQO.js.map} +0 -0
- /package/dist/{shared-3C5ZX44Q.js.map → shared-PPAWDMRF.js.map} +0 -0
- /package/dist/{study-writes-CD3D23LK.js.map → study-writes-RGKBOOJ6.js.map} +0 -0
- /package/dist/{targeting-BNJVE7XS.js.map → targeting-YWOOD6YL.js.map} +0 -0
- /package/dist/{videos-RS3G65UV.js.map → videos-OF6PAPP2.js.map} +0 -0
- /package/dist/{write-commands-PD3BEWWZ.js.map → write-commands-REUTFNJ3.js.map} +0 -0
|
@@ -14,16 +14,20 @@ import {
|
|
|
14
14
|
registerMetaListSchema,
|
|
15
15
|
shapeMetaListRows,
|
|
16
16
|
writeMetaListRows
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-AMCW2IG7.js";
|
|
18
18
|
import "./chunk-PRPSV4VB.js";
|
|
19
19
|
import {
|
|
20
|
+
LISTING_ACCOUNT_ARG,
|
|
20
21
|
NAME_CONTAINS_ARG,
|
|
22
|
+
accountsInScope,
|
|
21
23
|
csvOrJson,
|
|
22
24
|
handleMetaError,
|
|
23
|
-
|
|
25
|
+
listingLimit,
|
|
26
|
+
readEachAccount,
|
|
24
27
|
resolveEffectiveStatus,
|
|
25
|
-
statusFilterHints
|
|
26
|
-
|
|
28
|
+
statusFilterHints,
|
|
29
|
+
withAccountColumn
|
|
30
|
+
} from "./chunk-LDL5VBBD.js";
|
|
27
31
|
import {
|
|
28
32
|
rememberedJev
|
|
29
33
|
} from "./chunk-4DURENF2.js";
|
|
@@ -62,7 +66,7 @@ import "./chunk-YQSBHWOI.js";
|
|
|
62
66
|
import path from "path";
|
|
63
67
|
import { defineCommand } from "citty";
|
|
64
68
|
var listArgs = {
|
|
65
|
-
"account-id":
|
|
69
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
66
70
|
"campaign-id": { type: "string", alias: "campaign", description: "Filter to one campaign" },
|
|
67
71
|
"effective-status": { type: "string", description: "Comma-separated effective_status filter (overrides default)" },
|
|
68
72
|
"all-statuses": { type: "boolean", description: "Drop the default ACTIVE filter" },
|
|
@@ -85,11 +89,19 @@ async function readOrEmpty(path2, params, label, hints) {
|
|
|
85
89
|
return [];
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
|
-
async function writeAdSetViewers(adSets,
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
async function writeAdSetViewers(adSets, accountIds, noCache, format, hints, accountOf) {
|
|
93
|
+
const audiences = [];
|
|
94
|
+
const campaigns = [];
|
|
95
|
+
for (const accountId of accountIds) {
|
|
96
|
+
const accountParams = { "account-id": accountId };
|
|
97
|
+
if (noCache) accountParams["skip-cache"] = "true";
|
|
98
|
+
const [listed, objectives] = await Promise.all([
|
|
99
|
+
readOrEmpty("/api/ads/meta/audiences", accountParams, "audiences", hints),
|
|
100
|
+
readOrEmpty("/api/ads/meta/campaigns", accountParams, "campaigns", hints)
|
|
101
|
+
]);
|
|
102
|
+
audiences.push(...listed);
|
|
103
|
+
campaigns.push(...objectives);
|
|
104
|
+
}
|
|
93
105
|
const root = findWorkspaceRoot(process.cwd()) ?? process.cwd();
|
|
94
106
|
const cacheDir = path.join(root, "canvas", ".cache");
|
|
95
107
|
const spent = [];
|
|
@@ -105,14 +117,15 @@ async function writeAdSetViewers(adSets, accountParams, format, hints) {
|
|
|
105
117
|
);
|
|
106
118
|
}
|
|
107
119
|
if (format === "md" || format === "csv") {
|
|
108
|
-
|
|
120
|
+
const columns = accountOf ? ["account_id", ...VIEWER_TABLE_COLUMNS] : [...VIEWER_TABLE_COLUMNS];
|
|
121
|
+
writeAdsOutput(withAccountColumn(flattenViewerRows(rows), accountOf), format, columns, hints);
|
|
109
122
|
return;
|
|
110
123
|
}
|
|
111
|
-
writeAdsOutput(rows, format, void 0, hints);
|
|
124
|
+
writeAdsOutput(withAccountColumn(rows, accountOf), format, void 0, hints);
|
|
112
125
|
}
|
|
113
126
|
registerMetaListSchema(
|
|
114
127
|
"adsets",
|
|
115
|
-
"List ad sets in a Meta ad account, as a table by default: id, name, campaign_id, effective_status, optimization_goal, billing_event, bid_strategy, budgets, destination_type, is_dynamic_creative, learning_stage, end_time, created_time, optimizes_to (the event or custom conversion a conversion ad set bids for). Targeting is not in the compact row \u2014 ask for it with --fields id,name,targeting (or --full). --audience replaces the row with who each ad set reaches (a viewer: temperature, what they already know, placements, reasons) \u2014 read it before writing an ad for an ad set. Start here: baker ads meta adsets --campaign-id 6123 --all-statuses. --output json returns the rows in the envelope.",
|
|
128
|
+
"List ad sets in a Meta ad account, as a table by default: id, name, campaign_id, effective_status, optimization_goal, billing_event, bid_strategy, budgets, destination_type, is_dynamic_creative, learning_stage, end_time, created_time, optimizes_to (the event or custom conversion a conversion ad set bids for). Targeting is not in the compact row \u2014 ask for it with --fields id,name,targeting (or --full). --audience replaces the row with who each ad set reaches (a viewer: temperature, what they already know, placements, reasons) \u2014 read it before writing an ad for an ad set. Start here: baker ads meta adsets --campaign-id 6123 --all-statuses. --output json returns the rows in the envelope. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.",
|
|
116
129
|
listArgs,
|
|
117
130
|
// The `--audience` viewer reads the account's audiences and campaigns beside the ad sets.
|
|
118
131
|
["GET /api/ads/meta/audiences", "GET /api/ads/meta/campaigns"]
|
|
@@ -124,10 +137,10 @@ var listCommand = defineCommand({
|
|
|
124
137
|
},
|
|
125
138
|
args: listArgs,
|
|
126
139
|
run: async ({ args }) => {
|
|
127
|
-
const accountId = await resolveAccountIdArg(args);
|
|
128
140
|
const effectiveStatus = resolveEffectiveStatus(args);
|
|
141
|
+
const accounts = await accountsInScope(args);
|
|
129
142
|
try {
|
|
130
|
-
const params = {
|
|
143
|
+
const params = {};
|
|
131
144
|
if (args["campaign-id"]) params["campaign-id"] = args["campaign-id"];
|
|
132
145
|
if (effectiveStatus) params["effective-status"] = effectiveStatus;
|
|
133
146
|
if (args["name-contains"]) params["name-contains"] = args["name-contains"];
|
|
@@ -136,16 +149,21 @@ var listCommand = defineCommand({
|
|
|
136
149
|
if (fields) params.fields = fields;
|
|
137
150
|
if (args.limit) params.limit = args.limit;
|
|
138
151
|
if (args["no-cache"]) params["skip-cache"] = "true";
|
|
139
|
-
const
|
|
152
|
+
const read = await readEachAccount(
|
|
153
|
+
accounts,
|
|
154
|
+
(id) => apiGet("/api/ads/meta/adsets", { ...params, "account-id": id }),
|
|
155
|
+
{ byParent: Boolean(args["campaign-id"]), limit: listingLimit(args, 1e3) }
|
|
156
|
+
);
|
|
157
|
+
const data = read.rows;
|
|
140
158
|
if (args.audience) {
|
|
141
|
-
const hints = statusFilterHints(data, effectiveStatus, "ad sets");
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
await writeAdSetViewers(data, accountParams, csvOrJson(args), hints);
|
|
159
|
+
const hints = [...read.hints, ...statusFilterHints(data, effectiveStatus, "ad sets")];
|
|
160
|
+
const accountIds = read.accountOf ? [...new Set(read.accountOf)] : accounts.map((account) => account.id);
|
|
161
|
+
await writeAdSetViewers(data, accountIds, Boolean(args["no-cache"]), csvOrJson(args), hints, read.accountOf);
|
|
145
162
|
return;
|
|
146
163
|
}
|
|
147
|
-
const shaped = shapeMetaListRows("adsets", data, args);
|
|
164
|
+
const shaped = shapeMetaListRows("adsets", data, args, read.accountOf);
|
|
148
165
|
writeMetaListRows("adsets", shaped, csvOrJson(args), [
|
|
166
|
+
...read.hints,
|
|
149
167
|
...statusFilterHints(data, effectiveStatus, "ad sets"),
|
|
150
168
|
...largeListingHints("adsets", data.length),
|
|
151
169
|
...budgetUnitHints(data)
|
|
@@ -176,14 +194,14 @@ Examples:
|
|
|
176
194
|
},
|
|
177
195
|
subCommands: {
|
|
178
196
|
list: listCommand,
|
|
179
|
-
create: () => import("./write-commands-
|
|
180
|
-
update: () => import("./write-commands-
|
|
181
|
-
pause: () => import("./write-commands-
|
|
182
|
-
resume: () => import("./write-commands-
|
|
183
|
-
archive: () => import("./write-commands-
|
|
184
|
-
delete: () => import("./write-commands-
|
|
185
|
-
duplicate: () => import("./write-commands-
|
|
186
|
-
copy: () => import("./copy-writes-
|
|
197
|
+
create: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsCreateCommand),
|
|
198
|
+
update: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsUpdateCommand),
|
|
199
|
+
pause: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsPauseCommand),
|
|
200
|
+
resume: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsResumeCommand),
|
|
201
|
+
archive: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsArchiveCommand),
|
|
202
|
+
delete: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsDeleteCommand),
|
|
203
|
+
duplicate: () => import("./write-commands-REUTFNJ3.js").then((m) => m.adSetsDuplicateCommand),
|
|
204
|
+
copy: () => import("./copy-writes-TEJRR2W2.js").then((m) => m.adSetsCopyCommand)
|
|
187
205
|
},
|
|
188
206
|
// `args` stays even though the parent has no `run`: citty scans rawArgs for the
|
|
189
207
|
// subcommand name using THIS command's arg defs, so without them `--account-id act_1`
|
|
@@ -195,4 +213,4 @@ Examples:
|
|
|
195
213
|
export {
|
|
196
214
|
adsetsCommand
|
|
197
215
|
};
|
|
198
|
-
//# sourceMappingURL=adsets-
|
|
216
|
+
//# sourceMappingURL=adsets-2HV6TJJP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/meta/adsets.ts"],"sourcesContent":["import path from \"node:path\";\nimport { defineCommand } from \"citty\";\nimport { readAudienceNames } from \"../../../audience-names.ts\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport { rememberedJev } from \"../../../engine/lib/remembered-nouls.ts\";\nimport type { ReviewUsage } from \"../../../engine/nodes/local/lib/render-review.ts\";\nimport { findWorkspaceRoot } from \"../../canvas/normalize-paths.ts\";\nimport { holdUnbilledSpend } from \"../../canvas/unbilled-spend.ts\";\nimport { writeAdsOutput } from \"../output.ts\";\nimport { adSetViewerRows, audienceNamesOf, flattenViewerRows, VIEWER_TABLE_COLUMNS } from \"./adset-viewers.ts\";\nimport {\n budgetUnitHints,\n IDS_ARG,\n largeListingHints,\n META_LIST_SHAPE_ARGS,\n metaListFields,\n registerMetaListSchema,\n shapeMetaListRows,\n writeMetaListRows,\n} from \"./list-rows.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n listingLimit,\n NAME_CONTAINS_ARG,\n readEachAccount,\n resolveEffectiveStatus,\n statusFilterHints,\n withAccountColumn,\n} from \"./shared.ts\";\n\nconst listArgs = {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"campaign-id\": { type: \"string\", alias: \"campaign\", description: \"Filter to one campaign\" },\n \"effective-status\": { type: \"string\", description: \"Comma-separated effective_status filter (overrides default)\" },\n \"all-statuses\": { type: \"boolean\", description: \"Drop the default ACTIVE filter\" },\n \"name-contains\": NAME_CONTAINS_ARG,\n ids: IDS_ARG,\n limit: { type: \"string\", description: \"Max rows (default 1000)\" },\n \"no-cache\": NO_CACHE_ARG,\n audience: {\n type: \"boolean\",\n description:\n \"Who each ad set reaches, instead of the compact row: a viewer per ad set — temperature (cold|warm|hot), what they already know (brand/offer/product), placements, and the reasons, read from its targeting, the account's audiences and the campaign objective. Start here before writing an ad for an ad set: baker ads meta adsets --campaign-id 6123 --audience --output json\",\n },\n ...META_LIST_SHAPE_ARGS,\n} as const;\n\ntype MetaRow = Record<string, unknown>;\n\n/**\n * The audience list and the campaign objectives only sharpen the read: without them\n * each audience is read from its name and the objective is left out, so a refused\n * read degrades the viewer rather than failing the listing.\n */\nasync function readOrEmpty(path: string, params: Record<string, string>, label: string, hints: string[]) {\n try {\n return await apiGet<MetaRow[]>(path, params);\n } catch (err) {\n const message = err instanceof Error ? err.message : \"unknown error\";\n hints.push(`Could not read the account's ${label} (${message}); the viewer was read without them.`);\n return [];\n }\n}\n\n/**\n * Who each ad set reaches. The audiences and campaign objectives are read for\n * every account the ad sets came from and looked up by id, so ad sets read from\n * several accounts (or under a parent whose account is not named) each find\n * their own account's audiences and campaign.\n */\nasync function writeAdSetViewers(\n adSets: MetaRow[],\n accountIds: readonly string[],\n noCache: boolean,\n format: string,\n hints: string[],\n accountOf?: readonly string[],\n): Promise<void> {\n const audiences: MetaRow[] = [];\n const campaigns: MetaRow[] = [];\n for (const accountId of accountIds) {\n const accountParams: Record<string, string> = { \"account-id\": accountId };\n if (noCache) accountParams[\"skip-cache\"] = \"true\";\n const [listed, objectives] = await Promise.all([\n readOrEmpty(\"/api/ads/meta/audiences\", accountParams, \"audiences\", hints),\n readOrEmpty(\"/api/ads/meta/campaigns\", accountParams, \"campaigns\", hints),\n ]);\n audiences.push(...listed);\n campaigns.push(...objectives);\n }\n const root = findWorkspaceRoot(process.cwd()) ?? process.cwd();\n const cacheDir = path.join(root, \"canvas\", \".cache\");\n const spent: ReviewUsage[] = [];\n const readName = await readAudienceNames(\n audienceNamesOf(adSets, audiences),\n rememberedJev(path.join(cacheDir, \"audience-names.json\"), (u) => spent.push(u)),\n );\n await holdUnbilledSpend(cacheDir, spent).catch(() => undefined);\n const rows = adSetViewerRows(adSets, audiences, campaigns, readName);\n if (rows.length > 0) {\n hints.push(\n 'Write each ad for the viewer of the ad set it will run in, then record it in the creative\\'s _definition.md: targetAdSet: \"<ad set id>\" and viewer: { temperature, knows, placements, source }.',\n );\n }\n if (format === \"md\" || format === \"csv\") {\n const columns = accountOf ? [\"account_id\", ...VIEWER_TABLE_COLUMNS] : [...VIEWER_TABLE_COLUMNS];\n writeAdsOutput(withAccountColumn(flattenViewerRows(rows), accountOf), format, columns, hints);\n return;\n }\n writeAdsOutput(withAccountColumn(rows as unknown as MetaRow[], accountOf), format, undefined, hints);\n}\n\nregisterMetaListSchema(\n \"adsets\",\n \"List ad sets in a Meta ad account, as a table by default: id, name, campaign_id, effective_status, optimization_goal, billing_event, bid_strategy, budgets, destination_type, is_dynamic_creative, learning_stage, end_time, created_time, optimizes_to (the event or custom conversion a conversion ad set bids for). Targeting is not in the compact row — ask for it with --fields id,name,targeting (or --full). --audience replaces the row with who each ad set reaches (a viewer: temperature, what they already know, placements, reasons) — read it before writing an ad for an ad set. Start here: baker ads meta adsets --campaign-id 6123 --all-statuses. --output json returns the rows in the envelope. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n listArgs,\n // The `--audience` viewer reads the account's audiences and campaigns beside the ad sets.\n [\"GET /api/ads/meta/audiences\", \"GET /api/ads/meta/campaigns\"],\n);\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"List ad sets in a Meta ad account. Runs by default when no subcommand is given. Example: baker ads meta adsets --account-id act_123\",\n },\n args: listArgs,\n run: async ({ args }) => {\n const effectiveStatus = resolveEffectiveStatus(args);\n const accounts = await accountsInScope(args);\n try {\n const params: Record<string, string> = {};\n if (args[\"campaign-id\"]) params[\"campaign-id\"] = args[\"campaign-id\"] as string;\n if (effectiveStatus) params[\"effective-status\"] = effectiveStatus;\n if (args[\"name-contains\"]) params[\"name-contains\"] = args[\"name-contains\"] as string;\n if (args.ids) params.ids = args.ids as string;\n const fields = args.audience ? undefined : metaListFields(\"adsets\", args);\n if (fields) params.fields = fields;\n if (args.limit) params.limit = args.limit as string;\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const read = await readEachAccount(\n accounts,\n (id) => apiGet<Array<Record<string, unknown>>>(\"/api/ads/meta/adsets\", { ...params, \"account-id\": id }),\n { byParent: Boolean(args[\"campaign-id\"]), limit: listingLimit(args, 1000) },\n );\n const data = read.rows;\n if (args.audience) {\n const hints = [...read.hints, ...statusFilterHints(data, effectiveStatus, \"ad sets\")];\n // Ad sets read under a parent carry no account, so every connected account's audiences are looked up.\n const accountIds = read.accountOf ? [...new Set(read.accountOf)] : accounts.map((account) => account.id);\n await writeAdSetViewers(data, accountIds, Boolean(args[\"no-cache\"]), csvOrJson(args), hints, read.accountOf);\n return;\n }\n const shaped = shapeMetaListRows(\"adsets\", data, args, read.accountOf);\n writeMetaListRows(\"adsets\", shaped, csvOrJson(args), [\n ...read.hints,\n ...statusFilterHints(data, effectiveStatus, \"ad sets\"),\n ...largeListingHints(\"adsets\", data.length),\n ...budgetUnitHints(data),\n ]);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nexport const adsetsCommand = defineCommand({\n meta: {\n name: \"adsets\",\n description: `List ad sets in a Meta ad account, or stage writes (create/update/pause/resume/archive/delete/duplicate/copy).\nDefaults to ACTIVE only. Write subcommands stage ops on this chat's draft.\n\nListings print a table by default: id, name, campaign_id, effective_status, optimization_goal, billing_event,\nbid_strategy, budgets, destination_type, is_dynamic_creative, learning_stage, end_time, created_time, optimizes_to\n(the conversion it bids for). Targeting is not in the compact row — ask for it with --fields (dotted paths) or --full. --output json returns the rows as JSON.\n\nExamples:\n baker ads meta adsets --account-id act_123\n baker ads meta adsets --campaign-id 6123456789\n baker ads meta adsets --account-id act_123 --all-statuses --name-contains retargeting — find one ad set by name\n baker ads meta adsets --campaign-id 6123456789 --fields id,name,targeting.geo_locations\n baker ads meta adsets --ids 6123,6124 — the ad sets you have ids for, any status\n baker ads meta adsets --campaign-id 6123456789 --audience --output json — who each ad set reaches (viewer per ad set)\n baker ads meta adsets create --campaign meta_temp_ab12 --name \"US 25-54\" --optimization-goal LINK_CLICKS --billing-event IMPRESSIONS --daily-budget 50 --targeting-file t.json`,\n },\n subCommands: {\n list: listCommand,\n create: () => import(\"./write-commands.ts\").then((m) => m.adSetsCreateCommand),\n update: () => import(\"./write-commands.ts\").then((m) => m.adSetsUpdateCommand),\n pause: () => import(\"./write-commands.ts\").then((m) => m.adSetsPauseCommand),\n resume: () => import(\"./write-commands.ts\").then((m) => m.adSetsResumeCommand),\n archive: () => import(\"./write-commands.ts\").then((m) => m.adSetsArchiveCommand),\n delete: () => import(\"./write-commands.ts\").then((m) => m.adSetsDeleteCommand),\n duplicate: () => import(\"./write-commands.ts\").then((m) => m.adSetsDuplicateCommand),\n copy: () => import(\"./copy-writes.ts\").then((m) => m.adSetsCopyCommand),\n },\n // `args` stays even though the parent has no `run`: citty scans rawArgs for the\n // subcommand name using THIS command's arg defs, so without them `--account-id act_1`\n // would read `act_1` as a subcommand. `default` (not `run`) dispatches the bare\n // invocation — citty falls through to `run` after a subcommand, double-executing it.\n args: listArgs,\n default: \"list\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAiC9B,IAAM,WAAW;AAAA,EACf,cAAc;AAAA,EACd,eAAe,EAAE,MAAM,UAAU,OAAO,YAAY,aAAa,yBAAyB;AAAA,EAC1F,oBAAoB,EAAE,MAAM,UAAU,aAAa,8DAA8D;AAAA,EACjH,gBAAgB,EAAE,MAAM,WA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,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB;AAAA,IAC3E,QAAQ,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,mBAAmB;AAAA,IAC7E,SAAS,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,oBAAoB;AAAA,IAC/E,QAAQ,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,mBAAmB;AAAA,IAC7E,WAAW,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,sBAAsB;AAAA,IACnF,MAAM,MAAM,OAAO,2BAAkB,EAAE,KAAK,CAAC,MAAM,EAAE,iBAAiB;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM;AAAA,EACN,SAAS;AACX,CAAC;","names":["path"]}
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
labelsDetachCommand,
|
|
10
10
|
labelsRenameCommand,
|
|
11
11
|
mediaDeleteCommand
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-3F6AXSPB.js";
|
|
13
|
+
import "./chunk-BRHYK4HQ.js";
|
|
14
14
|
import "./chunk-3R62EYYX.js";
|
|
15
15
|
import "./chunk-GDFJOCDO.js";
|
|
16
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-LDL5VBBD.js";
|
|
17
17
|
import "./chunk-S7J2JP3U.js";
|
|
18
18
|
import "./chunk-UKENQSZ2.js";
|
|
19
19
|
import "./chunk-D5FY4FAK.js";
|
|
@@ -51,4 +51,4 @@ export {
|
|
|
51
51
|
labelsRenameCommand,
|
|
52
52
|
mediaDeleteCommand
|
|
53
53
|
};
|
|
54
|
-
//# sourceMappingURL=asset-writes-
|
|
54
|
+
//# sourceMappingURL=asset-writes-ZOVD5O5X.js.map
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
repeatedListFlag,
|
|
11
11
|
requireTarget,
|
|
12
12
|
stageOp
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-BRHYK4HQ.js";
|
|
14
14
|
import {
|
|
15
15
|
CUSTOMER_LIST_BATCH_ROWS,
|
|
16
16
|
CUSTOMER_LIST_MAX_BATCHES,
|
|
@@ -18,10 +18,14 @@ import {
|
|
|
18
18
|
} from "./chunk-3R62EYYX.js";
|
|
19
19
|
import "./chunk-GDFJOCDO.js";
|
|
20
20
|
import {
|
|
21
|
+
LISTING_ACCOUNT_ARG,
|
|
22
|
+
accountsInScope,
|
|
21
23
|
csvOrJson,
|
|
22
24
|
handleMetaError,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
readEachAccount,
|
|
26
|
+
resolveAccountIdArg,
|
|
27
|
+
withAccountColumn
|
|
28
|
+
} from "./chunk-LDL5VBBD.js";
|
|
25
29
|
import "./chunk-S7J2JP3U.js";
|
|
26
30
|
import "./chunk-UKENQSZ2.js";
|
|
27
31
|
import "./chunk-D5FY4FAK.js";
|
|
@@ -253,9 +257,9 @@ var audiencesDeleteCommand = defineCommand({
|
|
|
253
257
|
});
|
|
254
258
|
registerSchema({
|
|
255
259
|
command: "ads.meta.audiences.saved",
|
|
256
|
-
description: "List the ad account's saved audiences (targeting saved in Ads Manager), or one with --saved-audience-id. Read-only \u2014 Meta's API cannot create or change one. Use one on a new ad set with `adsets create --saved-audience <id>`.",
|
|
260
|
+
description: "List the ad account's saved audiences (targeting saved in Ads Manager), or one with --saved-audience-id. Read-only \u2014 Meta's API cannot create or change one. Use one on a new ad set with `adsets create --saved-audience <id>`. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.",
|
|
257
261
|
args: {
|
|
258
|
-
"account-id": {
|
|
262
|
+
"account-id": { ...LISTING_ACCOUNT_ARG, required: false },
|
|
259
263
|
"saved-audience-id": {
|
|
260
264
|
type: "string",
|
|
261
265
|
description: "One saved audience, with its full targeting",
|
|
@@ -271,22 +275,32 @@ var savedAudiencesCommand = defineCommand({
|
|
|
271
275
|
description: "Saved audiences on the account (read-only). Example: baker ads meta audiences saved --account-id act_123; use one with `adsets create --saved-audience <id>`"
|
|
272
276
|
},
|
|
273
277
|
args: {
|
|
274
|
-
"account-id":
|
|
278
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
275
279
|
"saved-audience-id": { type: "string", description: "One saved audience, with its full targeting" },
|
|
276
280
|
full: { type: "boolean", description: "Include each audience's whole targeting spec" },
|
|
277
281
|
output: { type: "string", description: "json|csv|jsonl|md", default: "json" }
|
|
278
282
|
},
|
|
279
283
|
run: async ({ args }) => {
|
|
280
|
-
const
|
|
284
|
+
const accounts = args["saved-audience-id"] ? [{ id: await resolveAccountIdArg(args) }] : await accountsInScope(args);
|
|
281
285
|
try {
|
|
282
|
-
const params = {
|
|
286
|
+
const params = {};
|
|
283
287
|
if (args["saved-audience-id"]) params["saved-audience-id"] = String(args["saved-audience-id"]);
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
const read = await readEachAccount(
|
|
289
|
+
accounts,
|
|
290
|
+
(accountId) => apiGet("/api/ads/meta/saved-audiences", { ...params, "account-id": accountId })
|
|
291
|
+
);
|
|
292
|
+
const rows = read.rows;
|
|
293
|
+
const shown = withAccountColumn(
|
|
294
|
+
args.full || args["saved-audience-id"] ? rows : rows.map(({ targeting: _targeting, ...row }) => row),
|
|
295
|
+
read.accountOf
|
|
296
|
+
);
|
|
297
|
+
const hints = [
|
|
298
|
+
...read.hints,
|
|
299
|
+
...rows.length === 0 ? [
|
|
300
|
+
"This account has no saved audiences \u2014 Meta's API cannot create one; build the targeting on the ad set instead."
|
|
301
|
+
] : [
|
|
302
|
+
"Use one on a new ad set: `baker ads meta adsets create \u2026 --saved-audience <id>` (its targeting is copied)."
|
|
303
|
+
]
|
|
290
304
|
];
|
|
291
305
|
const fmt = csvOrJson(args);
|
|
292
306
|
if (fmt !== "json") {
|
|
@@ -328,4 +342,4 @@ export {
|
|
|
328
342
|
savedAudiencesCommand,
|
|
329
343
|
targetingFromSavedAudience
|
|
330
344
|
};
|
|
331
|
-
//# sourceMappingURL=audience-writes-
|
|
345
|
+
//# sourceMappingURL=audience-writes-36E6ECON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/meta/audience-writes.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { brandSafetyTargetingFields } from \"@baker/api/ads-meta/brandSafety\";\nimport {\n CUSTOMER_LIST_BATCH_ROWS,\n CUSTOMER_LIST_MAX_BATCHES,\n type CustomerListAction,\n type CustomerListBatchResponse,\n} from \"@baker/api/ads-meta/customerList\";\nimport { defineCommand } from \"citty\";\nimport { apiGet, apiPost } from \"../../../client.ts\";\nimport { requireChatId } from \"../../../env.ts\";\nimport { registerSchema } from \"../../../schemas.ts\";\nimport { writeAdsOutput, writeJsonEnvelope } from \"../output.ts\";\nimport {\n customerListBatches,\n customerListFromFile,\n customerListUploadRefusal,\n DATE_ORDERS,\n type DateOrder,\n type HashedCustomerList,\n} from \"./customer-list.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n readEachAccount,\n resolveAccountIdArg,\n withAccountColumn,\n} from \"./shared.ts\";\nimport { bareAccountId, failWriteValidation, repeatedListFlag, requireTarget, stageOp } from \"./write-shared.ts\";\n\n/**\n * Staged writes on who is in a customer list, deleting an audience, and the\n * saved audiences an ad set can copy. The people are read from a file in the\n * workspace and hashed here; only their digests are held by Baker until the\n * chat publishes, and only counts are ever printed.\n */\n\nconst STAGED_NOTE = \"Staged until publish — review with `baker ads meta draft`.\";\n\nconst membersArgs = {\n id: {\n type: \"positional\",\n description: \"Customer-list audience id, or a meta_temp_* ref created in this chat\",\n required: true,\n },\n \"account-id\": { type: \"string\", description: \"Meta ad account ID (act_123)\" },\n file: {\n type: \"string\",\n description:\n \"CSV (or ;/tab separated) in the workspace with a header row: email, phone, first name, last name, city, state, zip, country, birthday, gender, madid, external id\",\n },\n country: {\n type: \"string\",\n description:\n \"Two-letter country for phones written without their country code (when the row has no country column)\",\n },\n \"value-column\": {\n type: \"string\",\n description: \"Value-based list only: the column with each person's value (e.g. revenue)\",\n },\n columns: {\n type: \"string\",\n description:\n \"For a file without a header row: what each column is, in order (email,phone,country — comma-separated or repeated)\",\n },\n \"date-format\": {\n type: \"string\",\n description:\n \"How birthdays like 03/07/1990 are written: DMY (day first) or MDY (month first, US). Needed only when no date in the file shows it\",\n },\n} as const;\n\nfunction schemaArgs<T extends Record<string, { type: string; description: string; required?: boolean }>>(args: T) {\n return Object.fromEntries(\n Object.entries(args).map(([key, arg]) => [\n key,\n { type: arg.type, description: arg.description, required: arg.required === true },\n ]),\n );\n}\n\nconst ACTION_NOTES: Record<CustomerListAction, string> = {\n add: \"Adds the people in the file to the list; those already in it stay.\",\n remove: \"Removes the people in the file from the list.\",\n replace:\n \"Replaces the whole list with the file — everyone not in it leaves. Runs alone: not beside another change to the same list in this chat.\",\n};\n\nfunction dateFormatFlag(value: unknown): DateOrder | undefined {\n if (value === undefined) return undefined;\n const upperValue = String(value).toUpperCase();\n if (!(DATE_ORDERS as readonly string[]).includes(upperValue)) {\n failWriteValidation(`--date-format takes ${DATE_ORDERS.join(\" or \")}, not ${String(value)}`);\n }\n return upperValue as DateOrder;\n}\n\nfunction readList(args: Record<string, unknown>, rawArgs: readonly string[] | undefined): HashedCustomerList {\n const path = typeof args.file === \"string\" ? args.file : \"\";\n if (!path) {\n failWriteValidation(\"pass --file with the customer list (CSV in the workspace)\");\n }\n let content: string;\n try {\n content = readFileSync(path, \"utf8\");\n } catch (err) {\n failWriteValidation(`could not read ${path}: ${err instanceof Error ? err.message : String(err)}`);\n }\n try {\n return customerListFromFile(content, {\n defaultCountry: typeof args.country === \"string\" ? args.country : undefined,\n valueColumn: typeof args[\"value-column\"] === \"string\" ? args[\"value-column\"] : undefined,\n columns: repeatedListFlag(rawArgs, \"columns\", args.columns),\n dateFormat: dateFormatFlag(args[\"date-format\"]),\n });\n } catch (err) {\n failWriteValidation(err instanceof Error ? err.message : String(err));\n }\n}\n\n/** What the agent learns about the file: counts only. */\nfunction listHints(list: HashedCustomerList): string[] {\n const hints = [`${list.rows.length.toLocaleString(\"en-US\")} people read from the file, hashed before upload`];\n const unreadable = Object.entries(list.unreadable).map(([key, count]) => `${count} ${key}`);\n if (unreadable.length > 0) {\n hints.push(`values that could not be read and were left out: ${unreadable.join(\", \")}`);\n }\n if (list.skippedRows > 0) {\n hints.push(\n `${list.skippedRows} rows had nothing Meta can match on (no readable email, phone or id${list.schema.includes(\"LOOKALIKE_VALUE\") ? \", or no readable value\" : \"\"}) and were left out`,\n );\n }\n if (list.ignoredColumns.length > 0) {\n hints.push(`columns not sent (Meta does not match on them): ${list.ignoredColumns.join(\", \")}`);\n }\n if (list.rows.length < 100) {\n hints.push(\"Meta needs about 100 matched people before a list can be used for ads or as a lookalike seed\");\n }\n return hints;\n}\n\nasync function stageMembers(\n action: CustomerListAction,\n args: Record<string, unknown>,\n rawArgs: readonly string[] | undefined,\n): Promise<void> {\n const accountId = await bareAccountId(args);\n const audienceId = requireTarget(args, \"audience\");\n const list = readList(args, rawArgs);\n if (list.rows.length === 0) {\n failWriteValidation(\"no one in this file can be matched — check the columns (email, phone, …) and their values\");\n }\n const batches = customerListBatches(list);\n if (batches.length > CUSTOMER_LIST_MAX_BATCHES) {\n failWriteValidation(\n `this file holds ${list.rows.length.toLocaleString(\"en-US\")} people; one change carries at most ${(CUSTOMER_LIST_BATCH_ROWS * CUSTOMER_LIST_MAX_BATCHES).toLocaleString(\"en-US\")} — split the file and stage one add per part`,\n );\n }\n const refusal = customerListUploadRefusal(audienceId, action, list);\n if (refusal) {\n failWriteValidation(refusal);\n }\n const stored: CustomerListBatchResponse[] = [];\n try {\n const chatId = requireChatId();\n for (const batch of batches) {\n const response = await apiPost<{ ok: true; data: CustomerListBatchResponse }>(\n \"/api/ads/meta/draft/customer-list-batch\",\n { chatId, accountId, batch },\n { timeoutMs: 120_000 },\n );\n stored.push(response.data);\n }\n } catch (err) {\n handleMetaError(err);\n }\n await stageOp(\n {\n kind: \"customAudience.members\",\n accountId,\n payload: { audience_id: audienceId, action, schema: list.schema, batches: stored },\n },\n listHints(list),\n );\n}\n\nfunction membersCommand(action: CustomerListAction) {\n registerSchema({\n command: `ads.meta.audiences.members.${action}`,\n description: `Stage ${action === \"add\" ? \"adding people to\" : action === \"remove\" ? \"removing people from\" : \"replacing everyone in\"} a Meta customer list from a CSV in the workspace. ${ACTION_NOTES[action]} Every value is normalized and SHA-256 hashed on this machine before upload, as Meta asks, with a masked copy of each person (l***@empresa.com) for the review; only counts are printed. Applied at publish; Meta takes up to 24h to match.`,\n args: schemaArgs(membersArgs),\n });\n return defineCommand({\n meta: {\n name: action,\n description: `${ACTION_NOTES[action]} ${STAGED_NOTE}\nExample: baker ads meta audiences members ${action} 120249492603650208 --file customers.csv --country ES`,\n },\n args: membersArgs,\n run: async ({ args, rawArgs }) => {\n await stageMembers(action, args as Record<string, unknown>, rawArgs);\n },\n });\n}\n\nexport const audiencesMembersCommand = defineCommand({\n meta: {\n name: \"members\",\n description: `Change who is in a customer-list audience, from a CSV in the workspace. Hashed here before upload. ${STAGED_NOTE}\n baker ads meta audiences members add <audienceId|meta_temp_…> --file customers.csv [--country ES]\n baker ads meta audiences members remove <audienceId> --file unsubscribed.csv\n baker ads meta audiences members replace <audienceId> --file customers.csv\n value-based list: add --value-column revenue`,\n },\n subCommands: {\n add: membersCommand(\"add\"),\n remove: membersCommand(\"remove\"),\n replace: membersCommand(\"replace\"),\n },\n});\n\n// --- Delete ---\n\nregisterSchema({\n command: \"ads.meta.audiences.delete\",\n description:\n \"Stage deleting a Meta custom audience — permanent, applied at publish. Every ad that targets it stops and cannot be restarted; Meta refuses while a lookalike is built from it (delete the lookalike first).\",\n args: {\n id: { type: \"positional\", description: \"Audience id\", required: true },\n \"account-id\": { type: \"string\", description: \"Meta ad account ID (act_123)\", required: false },\n },\n});\n\nexport const audiencesDeleteCommand = defineCommand({\n meta: {\n name: \"delete\",\n description: `Stage deleting an audience — permanent: ads that target it stop for good. Only when the user asked to delete it. ${STAGED_NOTE}`,\n },\n args: {\n id: { type: \"positional\", description: \"Audience id\", required: true },\n \"account-id\": { type: \"string\", description: \"Meta ad account ID (act_123)\" },\n },\n run: async ({ args }) => {\n await stageOp({\n kind: \"customAudience.update\",\n accountId: await bareAccountId(args as Record<string, unknown>),\n target: requireTarget(args as Record<string, unknown>, \"audience\"),\n payload: { status: \"DELETED\" },\n });\n },\n});\n\n// --- Saved audiences ---\n\nregisterSchema({\n command: \"ads.meta.audiences.saved\",\n description:\n \"List the ad account's saved audiences (targeting saved in Ads Manager), or one with --saved-audience-id. Read-only — Meta's API cannot create or change one. Use one on a new ad set with `adsets create --saved-audience <id>`. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n args: {\n \"account-id\": { ...LISTING_ACCOUNT_ARG, required: false },\n \"saved-audience-id\": {\n type: \"string\",\n description: \"One saved audience, with its full targeting\",\n required: false,\n },\n full: { type: \"boolean\", description: \"Include each audience's whole targeting spec\", required: false },\n output: { type: \"string\", description: \"json|csv|jsonl|md\", required: false, default: \"json\" },\n },\n});\n\nexport const savedAudiencesCommand = defineCommand({\n meta: {\n name: \"saved\",\n description:\n \"Saved audiences on the account (read-only). Example: baker ads meta audiences saved --account-id act_123; use one with `adsets create --saved-audience <id>`\",\n },\n args: {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"saved-audience-id\": { type: \"string\", description: \"One saved audience, with its full targeting\" },\n full: { type: \"boolean\", description: \"Include each audience's whole targeting spec\" },\n output: { type: \"string\", description: \"json|csv|jsonl|md\", default: \"json\" },\n },\n run: async ({ args }) => {\n // One saved audience is read on the account it belongs to, which the caller names; the list reads them all.\n const accounts = args[\"saved-audience-id\"]\n ? [{ id: await resolveAccountIdArg(args) }]\n : await accountsInScope(args);\n try {\n const params: Record<string, string> = {};\n if (args[\"saved-audience-id\"]) params[\"saved-audience-id\"] = String(args[\"saved-audience-id\"]);\n const read = await readEachAccount(accounts, (accountId) =>\n apiGet<Array<Record<string, unknown>>>(\"/api/ads/meta/saved-audiences\", { ...params, \"account-id\": accountId }),\n );\n const rows = read.rows;\n const shown = withAccountColumn(\n args.full || args[\"saved-audience-id\"] ? rows : rows.map(({ targeting: _targeting, ...row }) => row),\n read.accountOf,\n );\n const hints = [\n ...read.hints,\n ...(rows.length === 0\n ? [\n \"This account has no saved audiences — Meta's API cannot create one; build the targeting on the ad set instead.\",\n ]\n : [\n \"Use one on a new ad set: `baker ads meta adsets create … --saved-audience <id>` (its targeting is copied).\",\n ]),\n ];\n const fmt = csvOrJson(args);\n if (fmt !== \"json\") {\n writeAdsOutput(shown, fmt, undefined, hints);\n return;\n }\n writeJsonEnvelope({ ok: true, data: shown, hints });\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\n/**\n * A saved audience's targeting with the command's own targeting laid over it:\n * the brand-safety flags (`--block-list`, …) join it, while a targeting file\n * would replace it whole, so the two are refused together.\n */\nexport function targetingFromSavedAudience(\n saved: Record<string, unknown>,\n flagged: Record<string, unknown> | undefined,\n): { targeting: Record<string, unknown> } | { refusal: string } {\n if (flagged === undefined) return { targeting: saved };\n if (!Object.keys(flagged).every((key) => key in brandSafetyTargetingFields)) {\n return { refusal: \"--saved-audience brings the targeting — pass it or --targeting-file, not both\" };\n }\n return { targeting: { ...saved, ...flagged } };\n}\n\n/** A saved audience's targeting, to start an ad set from. */\nexport async function savedAudienceTargeting(\n accountId: string,\n savedAudienceId: string,\n): Promise<Record<string, unknown>> {\n try {\n const rows = await apiGet<Array<{ targeting?: Record<string, unknown> }>>(\"/api/ads/meta/saved-audiences\", {\n \"account-id\": accountId,\n \"saved-audience-id\": savedAudienceId,\n });\n const targeting = rows[0]?.targeting;\n if (!targeting) {\n failWriteValidation(`saved audience ${savedAudienceId} has no targeting to copy`);\n }\n return targeting;\n } catch (err) {\n handleMetaError(err);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,YAAY,GAAG,IAAI,MAAM,GAAG;AAAA,QACnG,KAAK;AAAA,MACP;AACA,YAAM,QAAQ;AAAA,QACZ,GAAG,KAAK;AAAA,QACR,GAAI,KAAK,WAAW,IAChB;AAAA,UACE;AAAA,QACF,IACA;AAAA,UACE;AAAA,QACF;AAAA,MACN;AACA,YAAM,MAAM,UAAU,IAAI;AAC1B,UAAI,QAAQ,QAAQ;AAClB,uBAAe,OAAO,KAAK,QAAW,KAAK;AAC3C;AAAA,MACF;AACA,wBAAkB,EAAE,IAAI,MAAM,MAAM,OAAO,MAAM,CAAC;AAAA,IACpD,SAAS,KAAK;AACZ,sBAAgB,GAAG;AAAA,IACrB;AAAA,EACF;AACF,CAAC;AAOM,SAAS,2BACd,OACA,SAC8D;AAC9D,MAAI,YAAY,OAAW,QAAO,EAAE,WAAW,MAAM;AACrD,MAAI,CAAC,OAAO,KAAK,OAAO,EAAE,MAAM,CAAC,QAAQ,OAAO,0BAA0B,GAAG;AAC3E,WAAO,EAAE,SAAS,qFAAgF;AAAA,EACpG;AACA,SAAO,EAAE,WAAW,EAAE,GAAG,OAAO,GAAG,QAAQ,EAAE;AAC/C;AAGA,eAAsB,uBACpB,WACA,iBACkC;AAClC,MAAI;AACF,UAAM,OAAO,MAAM,OAAuD,iCAAiC;AAAA,MACzG,cAAc;AAAA,MACd,qBAAqB;AAAA,IACvB,CAAC;AACD,UAAM,YAAY,KAAK,CAAC,GAAG;AAC3B,QAAI,CAAC,WAAW;AACd,0BAAoB,kBAAkB,eAAe,2BAA2B;AAAA,IAClF;AACA,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,oBAAgB,GAAG;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -4,13 +4,16 @@ import {
|
|
|
4
4
|
registerMetaListSchema,
|
|
5
5
|
shapeMetaListRows,
|
|
6
6
|
writeMetaListRows
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AMCW2IG7.js";
|
|
8
8
|
import "./chunk-PRPSV4VB.js";
|
|
9
9
|
import {
|
|
10
|
+
LISTING_ACCOUNT_ARG,
|
|
11
|
+
accountsInScope,
|
|
10
12
|
csvOrJson,
|
|
11
13
|
handleMetaError,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
listingLimit,
|
|
15
|
+
readEachAccount
|
|
16
|
+
} from "./chunk-LDL5VBBD.js";
|
|
14
17
|
import "./chunk-QALAJNBG.js";
|
|
15
18
|
import {
|
|
16
19
|
NO_CACHE_ARG
|
|
@@ -28,7 +31,7 @@ import "./chunk-YQSBHWOI.js";
|
|
|
28
31
|
// src/commands/ads/meta/audiences.ts
|
|
29
32
|
import { defineCommand } from "citty";
|
|
30
33
|
var listArgs = {
|
|
31
|
-
"account-id":
|
|
34
|
+
"account-id": LISTING_ACCOUNT_ARG,
|
|
32
35
|
"name-contains": {
|
|
33
36
|
type: "string",
|
|
34
37
|
description: "Only audiences whose name contains this text, matched by Meta before anything is returned: --name-contains Cerradas. A lookalike can be named anything, so find one audience's lookalikes with --seed <its id>"
|
|
@@ -47,7 +50,7 @@ var listArgs = {
|
|
|
47
50
|
};
|
|
48
51
|
registerMetaListSchema(
|
|
49
52
|
"audiences",
|
|
50
|
-
"List custom and lookalike audiences, as a table by default: id, name, subtype, size_min, size_max, retention_days, updated_date \u2014 plus, when a row has one, size (not reported by Meta, where Meta answered its 1000\u20131000 placeholder, which is no count), status (still processing, e.g. Updating, or a problem Meta reports; absent once settled), delivery (why Meta says it cannot be used) and seed_id (the audience a lookalike was built from). The rule, data source and pixel are one --fields away (--fields id,name,rule) or --full. Start here to find one audience: baker ads meta audiences --name-contains <text>; then its lookalikes, whatever they are named: --seed <its id>. --output json returns the rows in the envelope.",
|
|
53
|
+
"List custom and lookalike audiences, as a table by default: id, name, subtype, size_min, size_max, retention_days, updated_date \u2014 plus, when a row has one, size (not reported by Meta, where Meta answered its 1000\u20131000 placeholder, which is no count), status (still processing, e.g. Updating, or a problem Meta reports; absent once settled), delivery (why Meta says it cannot be used) and seed_id (the audience a lookalike was built from). The rule, data source and pixel are one --fields away (--fields id,name,rule) or --full. Start here to find one audience: baker ads meta audiences --name-contains <text>; then its lookalikes, whatever they are named: --seed <its id>. --output json returns the rows in the envelope. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.",
|
|
51
54
|
listArgs
|
|
52
55
|
);
|
|
53
56
|
var listCommand = defineCommand({
|
|
@@ -57,9 +60,9 @@ var listCommand = defineCommand({
|
|
|
57
60
|
},
|
|
58
61
|
args: listArgs,
|
|
59
62
|
run: async ({ args }) => {
|
|
60
|
-
const
|
|
63
|
+
const accounts = await accountsInScope(args);
|
|
61
64
|
try {
|
|
62
|
-
const params = {
|
|
65
|
+
const params = {};
|
|
63
66
|
if (args["name-contains"]) params["name-contains"] = args["name-contains"];
|
|
64
67
|
if (args.seed) params.seed = args.seed;
|
|
65
68
|
if (args.ids) params.ids = args.ids;
|
|
@@ -67,8 +70,17 @@ var listCommand = defineCommand({
|
|
|
67
70
|
if (fields) params.fields = fields;
|
|
68
71
|
if (args.limit) params.limit = args.limit;
|
|
69
72
|
if (args["no-cache"]) params["skip-cache"] = "true";
|
|
70
|
-
const
|
|
71
|
-
|
|
73
|
+
const read = await readEachAccount(
|
|
74
|
+
accounts,
|
|
75
|
+
(accountId) => apiGet("/api/ads/meta/audiences", { ...params, "account-id": accountId }),
|
|
76
|
+
{ limit: listingLimit(args, 500) }
|
|
77
|
+
);
|
|
78
|
+
writeMetaListRows(
|
|
79
|
+
"audiences",
|
|
80
|
+
shapeMetaListRows("audiences", read.rows, args, read.accountOf),
|
|
81
|
+
csvOrJson(args),
|
|
82
|
+
read.hints
|
|
83
|
+
);
|
|
72
84
|
} catch (err) {
|
|
73
85
|
handleMetaError(err);
|
|
74
86
|
}
|
|
@@ -98,11 +110,11 @@ Examples:
|
|
|
98
110
|
},
|
|
99
111
|
subCommands: {
|
|
100
112
|
list: listCommand,
|
|
101
|
-
create: () => import("./write-commands-
|
|
102
|
-
update: () => import("./write-commands-
|
|
103
|
-
delete: () => import("./audience-writes-
|
|
104
|
-
members: () => import("./audience-writes-
|
|
105
|
-
saved: () => import("./audience-writes-
|
|
113
|
+
create: () => import("./write-commands-REUTFNJ3.js").then((m) => m.audiencesCreateCommand),
|
|
114
|
+
update: () => import("./write-commands-REUTFNJ3.js").then((m) => m.audiencesUpdateCommand),
|
|
115
|
+
delete: () => import("./audience-writes-36E6ECON.js").then((m) => m.audiencesDeleteCommand),
|
|
116
|
+
members: () => import("./audience-writes-36E6ECON.js").then((m) => m.audiencesMembersCommand),
|
|
117
|
+
saved: () => import("./audience-writes-36E6ECON.js").then((m) => m.savedAudiencesCommand)
|
|
106
118
|
},
|
|
107
119
|
// `args` stays even though the parent has no `run`: citty scans rawArgs for the
|
|
108
120
|
// subcommand name using THIS command's arg defs, so without them `--account-id act_1`
|
|
@@ -114,4 +126,4 @@ Examples:
|
|
|
114
126
|
export {
|
|
115
127
|
audiencesCommand
|
|
116
128
|
};
|
|
117
|
-
//# sourceMappingURL=audiences-
|
|
129
|
+
//# sourceMappingURL=audiences-65JSGH4L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/meta/audiences.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport {\n META_LIST_SHAPE_ARGS,\n metaListFields,\n registerMetaListSchema,\n shapeMetaListRows,\n writeMetaListRows,\n} from \"./list-rows.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n handleMetaError,\n LISTING_ACCOUNT_ARG,\n listingLimit,\n readEachAccount,\n} from \"./shared.ts\";\n\nconst listArgs = {\n \"account-id\": LISTING_ACCOUNT_ARG,\n \"name-contains\": {\n type: \"string\",\n description:\n \"Only audiences whose name contains this text, matched by Meta before anything is returned: --name-contains Cerradas. A lookalike can be named anything, so find one audience's lookalikes with --seed <its id>\",\n },\n seed: {\n type: \"string\",\n description:\n \"Only the lookalikes built from this source audience id, whatever they are named: --seed 120240480760260208\",\n },\n ids: {\n type: \"string\",\n description:\n \"Comma-separated audience ids: only these, read by id rather than by listing the account (Meta will not match audiences by id). Start here when you have the ids: --ids 120240480760260208\",\n },\n limit: { type: \"string\", description: \"Max rows (default 500)\" },\n \"no-cache\": NO_CACHE_ARG,\n ...META_LIST_SHAPE_ARGS,\n} as const;\n\nregisterMetaListSchema(\n \"audiences\",\n \"List custom and lookalike audiences, as a table by default: id, name, subtype, size_min, size_max, retention_days, updated_date — plus, when a row has one, size (not reported by Meta, where Meta answered its 1000–1000 placeholder, which is no count), status (still processing, e.g. Updating, or a problem Meta reports; absent once settled), delivery (why Meta says it cannot be used) and seed_id (the audience a lookalike was built from). The rule, data source and pixel are one --fields away (--fields id,name,rule) or --full. Start here to find one audience: baker ads meta audiences --name-contains <text>; then its lookalikes, whatever they are named: --seed <its id>. --output json returns the rows in the envelope. With no --account-id and several accounts connected, every account is read and each row leads with its account_id.\",\n listArgs,\n);\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"List custom audiences. Runs by default when no subcommand is given. Example: baker ads meta audiences --name-contains buyers\",\n },\n args: listArgs,\n run: async ({ args }) => {\n const accounts = await accountsInScope(args);\n try {\n const params: Record<string, string> = {};\n if (args[\"name-contains\"]) params[\"name-contains\"] = args[\"name-contains\"] as string;\n if (args.seed) params.seed = args.seed as string;\n if (args.ids) params.ids = args.ids as string;\n const fields = metaListFields(\"audiences\", args);\n if (fields) params.fields = fields;\n if (args.limit) params.limit = args.limit as string;\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const read = await readEachAccount(\n accounts,\n (accountId) =>\n apiGet<Array<Record<string, unknown>>>(\"/api/ads/meta/audiences\", { ...params, \"account-id\": accountId }),\n { limit: listingLimit(args, 500) },\n );\n writeMetaListRows(\n \"audiences\",\n shapeMetaListRows(\"audiences\", read.rows, args, read.accountOf),\n csvOrJson(args),\n read.hints,\n );\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nexport const audiencesCommand = defineCommand({\n meta: {\n name: \"audiences\",\n description: `List custom audiences, or stage writes (create/update/delete, members add|remove|replace). Write subcommands stage ops on this chat's draft.\nIncludes lookalikes, website-pixel audiences, customer-file audiences.\n\nListings print a table by default: id, name, subtype, size_min, size_max, retention_days, updated_date, plus\nsize (when Meta withheld it: its 1000–1000 is no count), status (still processing, e.g. Updating), delivery\nand seed_id when a row has one. The rule and data source are --fields (dotted paths) or --full away.\n\nExamples:\n baker ads meta audiences --account-id act_123\n baker ads meta audiences --name-contains Cerradas — find one audience by name\n baker ads meta audiences --seed 120240480760260208 — the lookalikes built from that audience\n baker ads meta audiences --ids 120240480760260208 — the audiences you have ids for\n baker ads meta audiences --name-contains Leads --fields id,name,rule,retention_days --output json\n baker ads meta audiences create --name \"Site 30d\" --subtype WEBSITE --file rule.json\n baker ads meta audiences create --name \"Past buyers\" --subtype CUSTOM --file buyers.json # {\"members\":[{\"email\":\"…\"}]}\n baker ads meta audiences create --name \"Customers\" --subtype CUSTOM --customer-file-source USER_PROVIDED_ONLY\n baker ads meta audiences members add meta_temp_ab12 --file customers.csv --country ES\n baker ads meta audiences saved --account-id act_123 — saved audiences (read-only)`,\n },\n subCommands: {\n list: listCommand,\n create: () => import(\"./write-commands.ts\").then((m) => m.audiencesCreateCommand),\n update: () => import(\"./write-commands.ts\").then((m) => m.audiencesUpdateCommand),\n delete: () => import(\"./audience-writes.ts\").then((m) => m.audiencesDeleteCommand),\n members: () => import(\"./audience-writes.ts\").then((m) => m.audiencesMembersCommand),\n saved: () => import(\"./audience-writes.ts\").then((m) => m.savedAudiencesCommand),\n },\n // `args` stays even though the parent has no `run`: citty scans rawArgs for the\n // subcommand name using THIS command's arg defs, so without them `--account-id act_1`\n // would read `act_1` as a subcommand. `default` (not `run`) dispatches the bare\n // invocation — citty falls through to `run` after a subcommand, double-executing it.\n args: listArgs,\n default: \"list\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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K;AACZ,sBAAgB,GAAG;AAAA,IACrB;AAAA,EACF;AACF,CAAC;AAEM,IAAM,mBAAmB,cAAc;AAAA,EAC5C,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBf;AAAA,EACA,aAAa;AAAA,IACX,MAAM;AAAA,IACN,QAAQ,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,sBAAsB;AAAA,IAChF,QAAQ,MAAM,OAAO,8BAAqB,EAAE,KAAK,CAAC,MAAM,EAAE,sBAAsB;AAAA,IAChF,QAAQ,MAAM,OAAO,+BAAsB,EAAE,KAAK,CAAC,MAAM,EAAE,sBAAsB;AAAA,IACjF,SAAS,MAAM,OAAO,+BAAsB,EAAE,KAAK,CAAC,MAAM,EAAE,uBAAuB;AAAA,IACnF,OAAO,MAAM,OAAO,+BAAsB,EAAE,KAAK,CAAC,MAAM,EAAE,qBAAqB;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM;AAAA,EACN,SAAS;AACX,CAAC;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
csvOrJson,
|
|
3
3
|
handleMetaError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LDL5VBBD.js";
|
|
5
5
|
import "./chunk-QALAJNBG.js";
|
|
6
6
|
import {
|
|
7
7
|
NO_CACHE_ARG
|
|
@@ -51,4 +51,4 @@ Examples:
|
|
|
51
51
|
export {
|
|
52
52
|
businessesCommand
|
|
53
53
|
};
|
|
54
|
-
//# sourceMappingURL=businesses-
|
|
54
|
+
//# sourceMappingURL=businesses-5AEHP23G.js.map
|
|
@@ -6,16 +6,18 @@ import {
|
|
|
6
6
|
registerMetaListSchema,
|
|
7
7
|
shapeMetaListRows,
|
|
8
8
|
writeMetaListRows
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AMCW2IG7.js";
|
|
10
10
|
import "./chunk-PRPSV4VB.js";
|
|
11
11
|
import {
|
|
12
12
|
NAME_CONTAINS_ARG,
|
|
13
|
+
accountsInScope,
|
|
13
14
|
csvOrJson,
|
|
14
15
|
handleMetaError,
|
|
15
|
-
|
|
16
|
+
listingLimit,
|
|
17
|
+
readEachAccount,
|
|
16
18
|
resolveEffectiveStatus,
|
|
17
19
|
statusFilterHints
|
|
18
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LDL5VBBD.js";
|
|
19
21
|
import "./chunk-QALAJNBG.js";
|
|
20
22
|
import {
|
|
21
23
|
NO_CACHE_ARG
|
|
@@ -43,7 +45,10 @@ function advantagePlusHints(rows) {
|
|
|
43
45
|
] : [];
|
|
44
46
|
}
|
|
45
47
|
var listArgs = {
|
|
46
|
-
"account-id": {
|
|
48
|
+
"account-id": {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "Meta ad account ID (act_123). Without it every connected account is read, each row tagged with its account_id."
|
|
51
|
+
},
|
|
47
52
|
"effective-status": { type: "string", description: "Comma-separated effective_status filter (overrides default)" },
|
|
48
53
|
"all-statuses": { type: "boolean", description: "Drop the default ACTIVE filter and return everything" },
|
|
49
54
|
"name-contains": NAME_CONTAINS_ARG,
|
|
@@ -54,7 +59,7 @@ var listArgs = {
|
|
|
54
59
|
};
|
|
55
60
|
registerMetaListSchema(
|
|
56
61
|
"campaigns",
|
|
57
|
-
"List campaigns in a Meta ad account, as a table by default: id, name, effective_status, daily_budget, lifetime_budget, created_date; a campaign budgeted on its ad sets adds budget_level: adset and adset_daily_budget/adset_lifetime_budget (the sum of its ACTIVE ad sets' budgets, 0 when all are paused). ACTIVE only unless --all-statuses. Start here: baker ads meta campaigns --account-id act_123 --all-statuses. --fields takes dotted paths for anything else (e.g. id,name,objective,bid_strategy,special_ad_categories,advantage_state_info); --full returns every field Meta sent; --output json returns the rows in the envelope. A hint names the campaigns Meta counts as Advantage+.",
|
|
62
|
+
"List campaigns in a Meta ad account, as a table by default: id, name, effective_status, daily_budget, lifetime_budget, created_date; a campaign budgeted on its ad sets adds budget_level: adset and adset_daily_budget/adset_lifetime_budget (the sum of its ACTIVE ad sets' budgets, 0 when all are paused). ACTIVE only unless --all-statuses. Start here: baker ads meta campaigns --account-id act_123 --all-statuses. --fields takes dotted paths for anything else (e.g. id,name,objective,bid_strategy,special_ad_categories,advantage_state_info); --full returns every field Meta sent; --output json returns the rows in the envelope. A hint names the campaigns Meta counts as Advantage+. With no --account-id and several accounts connected, every account is read and each row leads with its account_id: baker ads meta campaigns --all-statuses --name-contains octubre",
|
|
58
63
|
listArgs
|
|
59
64
|
);
|
|
60
65
|
var listCommand = defineCommand({
|
|
@@ -64,10 +69,10 @@ var listCommand = defineCommand({
|
|
|
64
69
|
},
|
|
65
70
|
args: listArgs,
|
|
66
71
|
run: async ({ args }) => {
|
|
67
|
-
const
|
|
72
|
+
const accounts = await accountsInScope(args);
|
|
68
73
|
const effectiveStatus = resolveEffectiveStatus(args);
|
|
69
74
|
try {
|
|
70
|
-
const params = {
|
|
75
|
+
const params = {};
|
|
71
76
|
if (effectiveStatus) params["effective-status"] = effectiveStatus;
|
|
72
77
|
if (args["name-contains"]) params["name-contains"] = args["name-contains"];
|
|
73
78
|
if (args.ids) params.ids = args.ids;
|
|
@@ -75,9 +80,15 @@ var listCommand = defineCommand({
|
|
|
75
80
|
if (fields) params.fields = fields;
|
|
76
81
|
if (args.limit) params.limit = args.limit;
|
|
77
82
|
if (args["no-cache"]) params["skip-cache"] = "true";
|
|
78
|
-
const
|
|
79
|
-
|
|
83
|
+
const read = await readEachAccount(
|
|
84
|
+
accounts,
|
|
85
|
+
(accountId) => apiGet("/api/ads/meta/campaigns", { ...params, "account-id": accountId }),
|
|
86
|
+
{ limit: listingLimit(args, 1e3) }
|
|
87
|
+
);
|
|
88
|
+
const data = read.rows;
|
|
89
|
+
const shaped = shapeMetaListRows("campaigns", data, args, read.accountOf);
|
|
80
90
|
writeMetaListRows("campaigns", shaped, csvOrJson(args), [
|
|
91
|
+
...read.hints,
|
|
81
92
|
...statusFilterHints(data, effectiveStatus, "campaigns"),
|
|
82
93
|
...advantagePlusHints(data),
|
|
83
94
|
...budgetUnitHints([...data, ...shaped.rows])
|
|
@@ -116,14 +127,14 @@ Examples:
|
|
|
116
127
|
},
|
|
117
128
|
subCommands: {
|
|
118
129
|
list: listCommand,
|
|
119
|
-
create: () => import("./write-commands-
|
|
120
|
-
update: () => import("./write-commands-
|
|
121
|
-
pause: () => import("./write-commands-
|
|
122
|
-
resume: () => import("./write-commands-
|
|
123
|
-
archive: () => import("./write-commands-
|
|
124
|
-
delete: () => import("./write-commands-
|
|
125
|
-
duplicate: () => import("./write-commands-
|
|
126
|
-
copy: () => import("./copy-writes-
|
|
130
|
+
create: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsCreateCommand),
|
|
131
|
+
update: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsUpdateCommand),
|
|
132
|
+
pause: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsPauseCommand),
|
|
133
|
+
resume: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsResumeCommand),
|
|
134
|
+
archive: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsArchiveCommand),
|
|
135
|
+
delete: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsDeleteCommand),
|
|
136
|
+
duplicate: () => import("./write-commands-REUTFNJ3.js").then((m) => m.campaignsDuplicateCommand),
|
|
137
|
+
copy: () => import("./copy-writes-TEJRR2W2.js").then((m) => m.campaignsCopyCommand)
|
|
127
138
|
},
|
|
128
139
|
// `args` stays even though the parent has no `run`: citty scans rawArgs for the
|
|
129
140
|
// subcommand name using THIS command's arg defs, so without them `--account-id act_1`
|
|
@@ -136,4 +147,4 @@ export {
|
|
|
136
147
|
advantagePlusHints,
|
|
137
148
|
campaignsCommand
|
|
138
149
|
};
|
|
139
|
-
//# sourceMappingURL=campaigns-
|
|
150
|
+
//# sourceMappingURL=campaigns-PP3MFPJR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/ads/meta/campaigns.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { NO_CACHE_ARG } from \"../../../cache-flag.ts\";\nimport { apiGet } from \"../../../client.ts\";\nimport {\n budgetUnitHints,\n IDS_ARG,\n META_LIST_SHAPE_ARGS,\n metaListFields,\n registerMetaListSchema,\n shapeMetaListRows,\n writeMetaListRows,\n} from \"./list-rows.ts\";\nimport {\n accountsInScope,\n csvOrJson,\n handleMetaError,\n listingLimit,\n NAME_CONTAINS_ARG,\n readEachAccount,\n resolveEffectiveStatus,\n statusFilterHints,\n} from \"./shared.ts\";\n\n/**\n * Which listed campaigns Meta counts as Advantage+, read off the derived\n * `advantage_state_info` — a hint rather than a column, so the compact row of a\n * 100-campaign account stays small. Advantage+ is not a switch: it follows from\n * a campaign budget, Advantage+ audience and automatic placements.\n */\nexport function advantagePlusHints(rows: ReadonlyArray<Record<string, unknown>>): string[] {\n const named = rows.flatMap((row) => {\n const info = row.advantage_state_info as { advantage_state?: unknown } | undefined;\n const state = info?.advantage_state;\n return typeof state === \"string\" && state.startsWith(\"ADVANTAGE_PLUS_\")\n ? [`${String(row.id)} (${state.slice(\"ADVANTAGE_PLUS_\".length).toLowerCase()})`]\n : [];\n });\n return named.length > 0\n ? [\n `Advantage+ campaigns: ${named.join(\", \")}. Per-lever states (budget, audience, placements): --fields id,name,advantage_state_info.`,\n ]\n : [];\n}\n\nconst listArgs = {\n \"account-id\": {\n type: \"string\",\n description:\n \"Meta ad account ID (act_123). Without it every connected account is read, each row tagged with its account_id.\",\n },\n \"effective-status\": { type: \"string\", description: \"Comma-separated effective_status filter (overrides default)\" },\n \"all-statuses\": { type: \"boolean\", description: \"Drop the default ACTIVE filter and return everything\" },\n \"name-contains\": NAME_CONTAINS_ARG,\n ids: IDS_ARG,\n limit: { type: \"string\", description: \"Max rows (default 1000)\" },\n \"no-cache\": NO_CACHE_ARG,\n ...META_LIST_SHAPE_ARGS,\n} as const;\n\nregisterMetaListSchema(\n \"campaigns\",\n \"List campaigns in a Meta ad account, as a table by default: id, name, effective_status, daily_budget, lifetime_budget, created_date; a campaign budgeted on its ad sets adds budget_level: adset and adset_daily_budget/adset_lifetime_budget (the sum of its ACTIVE ad sets' budgets, 0 when all are paused). ACTIVE only unless --all-statuses. Start here: baker ads meta campaigns --account-id act_123 --all-statuses. --fields takes dotted paths for anything else (e.g. id,name,objective,bid_strategy,special_ad_categories,advantage_state_info); --full returns every field Meta sent; --output json returns the rows in the envelope. A hint names the campaigns Meta counts as Advantage+. With no --account-id and several accounts connected, every account is read and each row leads with its account_id: baker ads meta campaigns --all-statuses --name-contains octubre\",\n listArgs,\n);\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"List campaigns for a Meta ad account. Runs by default when no subcommand is given. Example: baker ads meta campaigns --account-id act_123\",\n },\n args: listArgs,\n run: async ({ args }) => {\n const accounts = await accountsInScope(args);\n const effectiveStatus = resolveEffectiveStatus(args);\n try {\n const params: Record<string, string> = {};\n if (effectiveStatus) params[\"effective-status\"] = effectiveStatus;\n if (args[\"name-contains\"]) params[\"name-contains\"] = args[\"name-contains\"] as string;\n if (args.ids) params.ids = args.ids as string;\n const fields = metaListFields(\"campaigns\", args);\n if (fields) params.fields = fields;\n if (args.limit) params.limit = args.limit as string;\n if (args[\"no-cache\"]) params[\"skip-cache\"] = \"true\";\n const read = await readEachAccount(\n accounts,\n (accountId) =>\n apiGet<Array<Record<string, unknown>>>(\"/api/ads/meta/campaigns\", { ...params, \"account-id\": accountId }),\n { limit: listingLimit(args, 1000) },\n );\n const data = read.rows;\n const shaped = shapeMetaListRows(\"campaigns\", data, args, read.accountOf);\n writeMetaListRows(\"campaigns\", shaped, csvOrJson(args), [\n ...read.hints,\n ...statusFilterHints(data, effectiveStatus, \"campaigns\"),\n ...advantagePlusHints(data),\n ...budgetUnitHints([...data, ...shaped.rows]),\n ]);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nexport const campaignsCommand = defineCommand({\n meta: {\n name: \"campaigns\",\n description: `List campaigns for a Meta ad account, or stage writes (create/update/pause/resume/archive/delete/duplicate/copy).\nDefaults to ACTIVE only — pass --all-statuses to widen. Write subcommands stage ops on this chat's draft and\napply only when the chat is published.\n\nIn Meta's API \"campaign\" is the top-of-tree object (what marketers usually call a campaign group).\nThe dashboard shows effective_status: ACTIVE, PAUSED, DELETED, ARCHIVED, IN_PROCESS, WITH_ISSUES, etc.\n\nListings print a table by default: id, name, effective_status, daily/lifetime budget, created_date\n(a campaign budgeted on its ad sets adds budget_level: adset and adset_daily_budget: its ACTIVE ad sets' sum).\n--fields takes dotted paths for anything else (objective, bid_strategy, special_ad_categories, created_time,\nadvantage_state_info). A hint names the campaigns Meta counts as Advantage+ — a state Meta derives from a\ncampaign budget, Advantage+ audience and automatic placements on every ad set, not a setting;\n--full returns every field; --output json returns the same rows in the { ok, data } envelope.\n\nExamples:\n baker ads meta campaigns --account-id act_123 # ACTIVE only\n baker ads meta campaigns --account-id act_123 --all-statuses # everything\n baker ads meta campaigns --account-id act_123 --all-statuses --name-contains Q3 # find one by name\n baker ads meta campaigns --account-id act_123 --fields id,name,objective,bid_strategy,special_ad_categories\n baker ads meta campaigns --account-id act_123 --output json # rows as JSON\n baker ads meta campaigns --ids 6123,6124 # the ones you have ids for, any status\n baker ads meta campaigns create --account-id act_123 --name \"Q3\" --objective OUTCOME_LEADS --daily-budget 50\n baker ads meta campaigns pause 6123 --account-id act_123`,\n },\n subCommands: {\n list: listCommand,\n create: () => import(\"./write-commands.ts\").then((m) => m.campaignsCreateCommand),\n update: () => import(\"./write-commands.ts\").then((m) => m.campaignsUpdateCommand),\n pause: () => import(\"./write-commands.ts\").then((m) => m.campaignsPauseCommand),\n resume: () => import(\"./write-commands.ts\").then((m) => m.campaignsResumeCommand),\n archive: () => import(\"./write-commands.ts\").then((m) => m.campaignsArchiveCommand),\n delete: () => import(\"./write-commands.ts\").then((m) => m.campaignsDeleteCommand),\n duplicate: () => import(\"./write-commands.ts\").then((m) => m.campaignsDuplicateCommand),\n copy: () => import(\"./copy-writes.ts\").then((m) => m.campaignsCopyCommand),\n },\n // `args` stays even though the parent has no `run`: citty scans rawArgs for the\n // subcommand name using THIS command's arg defs, so without them `--account-id act_1`\n // would read `act_1` as a subcommand. `default` (not `run`) dispatches the bare\n // invocation — citty falls through to `run` after a subcommand, double-executing it.\n args: listArgs,\n default: \"list\",\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AA6BvB,SAAS,mBAAmB,MAAwD;AACzF,QAAM,QAAQ,KAAK,QAAQ,CAAC,QAAQ;AAClC,UAAM,OAAO,IAAI;AACjB,UAAM,QAAQ,MAAM;AACpB,WAAO,OAAO,UAAU,YAAY,MAAM,WAAW,iBAAiB,IAClE,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC,KAAK,MAAM,MAAM,kBAAkB,MAAM,EAAE,YAAY,CAAC,GAAG,IAC7E,CAAC;AAAA,EACP,CAAC;AACD,SAAO,MAAM,SAAS,IAClB;AAAA,IACE,yBAAyB,MAAM,KAAK,IAAI,CAAC;AAAA,EAC3C,IACA,CAAC;AACP;AAEA,IAAM,WAAW;AAAA,EACf,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,aACE;AAAA,EACJ;AAAA,EACA,oBAAoB,EAAE,MAAM,UAAU,aAAa,8DAA8D;AAAA,EACjH,gBAAgB,EAAE,MAAM,WAAW,aAAa,uDAAuD;AAAA,EACvG,iBAAiB;AAAA,EACjB,KAAK;AAAA,EACL,OAAO,EAAE,MAAM,UAAU,aAAa,0BAA0B;AAAA,EAChE,YAAY;AAAA,EACZ,GAAG;AACL;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,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