@koda-sl/baker-cli 0.25.1 → 0.26.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 +73 -0
- package/dist/cli.js +1 -1
- package/dist/commands/ads/index.d.ts.map +1 -1
- package/dist/commands/ads/index.js +7 -2
- package/dist/commands/ads/index.js.map +1 -1
- package/dist/commands/ads/x/accounts.d.ts +14 -0
- package/dist/commands/ads/x/accounts.d.ts.map +1 -0
- package/dist/commands/ads/x/accounts.js +73 -0
- package/dist/commands/ads/x/accounts.js.map +1 -0
- package/dist/commands/ads/x/active-entities.d.ts +43 -0
- package/dist/commands/ads/x/active-entities.d.ts.map +1 -0
- package/dist/commands/ads/x/active-entities.js +88 -0
- package/dist/commands/ads/x/active-entities.js.map +1 -0
- package/dist/commands/ads/x/audiences.d.ts +19 -0
- package/dist/commands/ads/x/audiences.d.ts.map +1 -0
- package/dist/commands/ads/x/audiences.js +65 -0
- package/dist/commands/ads/x/audiences.js.map +1 -0
- package/dist/commands/ads/x/campaigns.d.ts +34 -0
- package/dist/commands/ads/x/campaigns.d.ts.map +1 -0
- package/dist/commands/ads/x/campaigns.js +56 -0
- package/dist/commands/ads/x/campaigns.js.map +1 -0
- package/dist/commands/ads/x/cards.d.ts +19 -0
- package/dist/commands/ads/x/cards.d.ts.map +1 -0
- package/dist/commands/ads/x/cards.js +65 -0
- package/dist/commands/ads/x/cards.js.map +1 -0
- package/dist/commands/ads/x/error-parser.d.ts +3 -0
- package/dist/commands/ads/x/error-parser.d.ts.map +1 -0
- package/dist/commands/ads/x/error-parser.js +80 -0
- package/dist/commands/ads/x/error-parser.js.map +1 -0
- package/dist/commands/ads/x/funding.d.ts +19 -0
- package/dist/commands/ads/x/funding.d.ts.map +1 -0
- package/dist/commands/ads/x/funding.js +65 -0
- package/dist/commands/ads/x/funding.js.map +1 -0
- package/dist/commands/ads/x/index.d.ts +2 -0
- package/dist/commands/ads/x/index.d.ts.map +1 -0
- package/dist/commands/ads/x/index.js +50 -0
- package/dist/commands/ads/x/index.js.map +1 -0
- package/dist/commands/ads/x/line-items.d.ts +34 -0
- package/dist/commands/ads/x/line-items.d.ts.map +1 -0
- package/dist/commands/ads/x/line-items.js +55 -0
- package/dist/commands/ads/x/line-items.js.map +1 -0
- package/dist/commands/ads/x/media.d.ts +24 -0
- package/dist/commands/ads/x/media.d.ts.map +1 -0
- package/dist/commands/ads/x/media.js +70 -0
- package/dist/commands/ads/x/media.js.map +1 -0
- package/dist/commands/ads/x/output.d.ts +13 -0
- package/dist/commands/ads/x/output.d.ts.map +1 -0
- package/dist/commands/ads/x/output.js +75 -0
- package/dist/commands/ads/x/output.js.map +1 -0
- package/dist/commands/ads/x/presets.d.ts +15 -0
- package/dist/commands/ads/x/presets.d.ts.map +1 -0
- package/dist/commands/ads/x/presets.js +60 -0
- package/dist/commands/ads/x/presets.js.map +1 -0
- package/dist/commands/ads/x/promoted-tweets.d.ts +29 -0
- package/dist/commands/ads/x/promoted-tweets.d.ts.map +1 -0
- package/dist/commands/ads/x/promoted-tweets.js +74 -0
- package/dist/commands/ads/x/promoted-tweets.js.map +1 -0
- package/dist/commands/ads/x/run-list.d.ts +17 -0
- package/dist/commands/ads/x/run-list.d.ts.map +1 -0
- package/dist/commands/ads/x/run-list.js +60 -0
- package/dist/commands/ads/x/run-list.js.map +1 -0
- package/dist/commands/ads/x/stats/index.d.ts +2 -0
- package/dist/commands/ads/x/stats/index.d.ts.map +1 -0
- package/dist/commands/ads/x/stats/index.js +32 -0
- package/dist/commands/ads/x/stats/index.js.map +1 -0
- package/dist/commands/ads/x/stats/job-create.d.ts +58 -0
- package/dist/commands/ads/x/stats/job-create.d.ts.map +1 -0
- package/dist/commands/ads/x/stats/job-create.js +95 -0
- package/dist/commands/ads/x/stats/job-create.js.map +1 -0
- package/dist/commands/ads/x/stats/job-status.d.ts +18 -0
- package/dist/commands/ads/x/stats/job-status.d.ts.map +1 -0
- package/dist/commands/ads/x/stats/job-status.js +58 -0
- package/dist/commands/ads/x/stats/job-status.js.map +1 -0
- package/dist/commands/ads/x/stats/job.d.ts +63 -0
- package/dist/commands/ads/x/stats/job.d.ts.map +1 -0
- package/dist/commands/ads/x/stats/job.js +183 -0
- package/dist/commands/ads/x/stats/job.js.map +1 -0
- package/dist/commands/ads/x/stats/sync.d.ts +73 -0
- package/dist/commands/ads/x/stats/sync.d.ts.map +1 -0
- package/dist/commands/ads/x/stats/sync.js +151 -0
- package/dist/commands/ads/x/stats/sync.js.map +1 -0
- package/dist/commands/ads/x/targeting-constants.d.ts +34 -0
- package/dist/commands/ads/x/targeting-constants.d.ts.map +1 -0
- package/dist/commands/ads/x/targeting-constants.js +80 -0
- package/dist/commands/ads/x/targeting-constants.js.map +1 -0
- package/dist/commands/ads/x/targeting-criteria.d.ts +24 -0
- package/dist/commands/ads/x/targeting-criteria.d.ts.map +1 -0
- package/dist/commands/ads/x/targeting-criteria.js +69 -0
- package/dist/commands/ads/x/targeting-criteria.js.map +1 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +4 -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
package/README.md
CHANGED
|
@@ -27,6 +27,9 @@ export BAKER_GA4_PROPERTY_ID="properties/123456789"
|
|
|
27
27
|
# Optional: default GSC site URL
|
|
28
28
|
export BAKER_GSC_SITE_URL="https://example.com/"
|
|
29
29
|
|
|
30
|
+
# Optional: default X Ads account ID (base36)
|
|
31
|
+
export BAKER_X_ADS_ACCOUNT_ID="18ce53xyz"
|
|
32
|
+
|
|
30
33
|
# Required for `baker actions ...` commands that stage against a chat
|
|
31
34
|
export BAKER_CHAT_ID="<chat-id>"
|
|
32
35
|
```
|
|
@@ -36,6 +39,7 @@ export BAKER_CHAT_ID="<chat-id>"
|
|
|
36
39
|
- `BAKER_GOOGLE_ADS_CUSTOMER_ID` — default Google Ads customer ID (10 digits). Used when `--customer-id` is not passed. If neither is set and the account has exactly one Google Ads customer, it is auto-selected.
|
|
37
40
|
- `BAKER_GA4_PROPERTY_ID` — default GA4 property ID. Used when `--property-id` is not passed. If neither is set and exactly one property is connected, it is auto-selected.
|
|
38
41
|
- `BAKER_GSC_SITE_URL` — default GSC site URL. Used when `--site-url` is not passed. If neither is set and exactly one site is verified, it is auto-selected.
|
|
42
|
+
- `BAKER_X_ADS_ACCOUNT_ID` — default X Ads account ID (base36). Used when `--account-id` is not passed. If neither is set and exactly one X Ads account is connected, it is auto-selected.
|
|
39
43
|
|
|
40
44
|
## Output Format
|
|
41
45
|
|
|
@@ -688,6 +692,75 @@ All errors include a `fix` object with `action`, `correctedCommand` (when applic
|
|
|
688
692
|
|
|
689
693
|
---
|
|
690
694
|
|
|
695
|
+
### X (Twitter) Ads (`baker ads x`)
|
|
696
|
+
|
|
697
|
+
Read X Ads campaigns, line items, promoted tweets, creatives, audiences, and analytics. Powered by the X Ads API v12.
|
|
698
|
+
|
|
699
|
+
**Environment:**
|
|
700
|
+
- `BAKER_X_ADS_ACCOUNT_ID` — default account ID (base36). Used when `--account-id` is not passed. If neither is set and exactly one X Ads account is connected, it's auto-selected.
|
|
701
|
+
|
|
702
|
+
**Subcommands:**
|
|
703
|
+
|
|
704
|
+
| Subcommand | What it returns |
|
|
705
|
+
|---|---|
|
|
706
|
+
| `accounts` | All accessible X Ads accounts |
|
|
707
|
+
| `funding` | Funding instruments for an account |
|
|
708
|
+
| `campaigns` | Campaigns (filter by `--funding-instrument-ids`, `--campaign-ids`) |
|
|
709
|
+
| `line-items` | Line items / ad groups (filter by `--campaign-ids`, `--line-item-ids`) |
|
|
710
|
+
| `promoted-tweets` | Promoted tweets (filter by `--line-item-ids`) |
|
|
711
|
+
| `cards` | Website cards, video cards, carousels |
|
|
712
|
+
| `media` | Media library (images / GIFs / videos) — `--media-type IMAGE\|GIF\|VIDEO` |
|
|
713
|
+
| `audiences` | Custom audiences (size, targetable status) |
|
|
714
|
+
| `targeting-criteria` | Targeting attached to line items |
|
|
715
|
+
| `targeting-constants` | Lookup locations / interests / events / devices etc. — `--constant <name> --q "Madrid"` |
|
|
716
|
+
| `active-entities` | Entities with metric activity in a time range |
|
|
717
|
+
| `stats sync` | Synchronous analytics (≤7 days, no segmentation) |
|
|
718
|
+
| `stats job` | Async stats end-to-end (creates + polls + downloads + decompresses). Must run in the background (the harness enforces this). Use for ranges >7 days, segmented stats, or when sync limits are hit. |
|
|
719
|
+
| `stats job-create` | Low-level: create async stats job, return ID immediately |
|
|
720
|
+
| `stats job-status` | Low-level: poll job status / get download URL |
|
|
721
|
+
|
|
722
|
+
**Examples:**
|
|
723
|
+
|
|
724
|
+
```bash
|
|
725
|
+
baker ads x accounts
|
|
726
|
+
baker ads x campaigns --account-id 18ce53xyz
|
|
727
|
+
baker ads x line-items --account-id 18ce53xyz --campaign-ids abc
|
|
728
|
+
baker ads x promoted-tweets --account-id 18ce53xyz
|
|
729
|
+
|
|
730
|
+
# Sync analytics with a preset (saves tokens)
|
|
731
|
+
baker ads x stats sync --preset campaign-engagement-7d --entity-ids abc,def
|
|
732
|
+
|
|
733
|
+
# Free-form sync stats
|
|
734
|
+
baker ads x stats sync --account-id 18ce53xyz --entity LINE_ITEM \
|
|
735
|
+
--entity-ids abc,def --start-time 2026-05-01T00:00:00Z --end-time 2026-05-07T00:00:00Z \
|
|
736
|
+
--metric-groups ENGAGEMENT,BILLING --granularity DAY
|
|
737
|
+
|
|
738
|
+
# Async job, sync from the CLI's perspective (creates → polls → downloads → returns).
|
|
739
|
+
# Must be invoked with run_in_background: true. The harness will block otherwise.
|
|
740
|
+
baker ads x stats job --account-id 18ce53xyz --entity CAMPAIGN \
|
|
741
|
+
--entity-ids abc --start-time 2026-04-01T00:00:00Z --end-time 2026-05-01T00:00:00Z \
|
|
742
|
+
--metric-groups ENGAGEMENT,BILLING --segmentation-type LOCATIONS
|
|
743
|
+
|
|
744
|
+
# Low-level (don't wait, manage polling yourself):
|
|
745
|
+
baker ads x stats job-create --account-id 18ce53xyz --entity CAMPAIGN \
|
|
746
|
+
--entity-ids abc --start-time 2026-04-01T00:00:00Z --end-time 2026-05-01T00:00:00Z \
|
|
747
|
+
--metric-groups ENGAGEMENT,BILLING --segmentation-type LOCATIONS
|
|
748
|
+
baker ads x stats job-status --account-id 18ce53xyz --job-id <jobId>
|
|
749
|
+
|
|
750
|
+
# List sync presets
|
|
751
|
+
baker ads x stats sync --list-presets
|
|
752
|
+
|
|
753
|
+
# Targeting lookups
|
|
754
|
+
baker ads x targeting-constants --constant locations --q "Madrid" --country-code ES
|
|
755
|
+
baker ads x targeting-constants --constant interests
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
**Caching:** account list 1h · campaigns/line items/promoted tweets 1h (date-keyed) · cards/media/audiences 6h · stats sync 1h · targeting constants 7 days. Pass `--no-cache` to bypass.
|
|
759
|
+
|
|
760
|
+
**Rate limits:** server-side buckets (`xAds:read`, `xAds:write`, `xAds:analyticsSync`, `xAds:analyticsAsync`, `xAds:audiences`) sit well under X's published quotas; 429s honor `x-account-rate-limit-reset` / `x-rate-limit-reset` headers.
|
|
761
|
+
|
|
762
|
+
---
|
|
763
|
+
|
|
691
764
|
### Meta Ads (`baker ads meta`)
|
|
692
765
|
|
|
693
766
|
Meta Marketing API (Facebook + Instagram). Connect via OAuth in the dashboard, pick which ad accounts to scope to, then call from the CLI. Account ID via `--account-id act_123` or `BAKER_META_AD_ACCOUNT_ID` env var.
|
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import { videosCommand } from "./commands/videos/index.js";
|
|
|
12
12
|
const main = defineCommand({
|
|
13
13
|
meta: {
|
|
14
14
|
name: "baker",
|
|
15
|
-
version: "0.
|
|
15
|
+
version: "0.26.0",
|
|
16
16
|
description: `AI-agent CLI for finding and managing images, videos, testimonials, action items, and ad platform data in Baker.
|
|
17
17
|
|
|
18
18
|
Auth: Set BAKER_API_KEY (starts with bk_) and BAKER_API_URL environment variables.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/ads/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/ads/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,qDAwBrB,CAAC"}
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import { googleCommand } from "./google/index.js";
|
|
3
3
|
import { metaCommand } from "./meta/index.js";
|
|
4
|
+
import { xCommand } from "./x/index.js";
|
|
4
5
|
export const adsCommand = defineCommand({
|
|
5
6
|
meta: {
|
|
6
7
|
name: "ads",
|
|
7
8
|
description: `Ad platform commands. Each platform exposes its own native command surface — no forced parity.
|
|
8
9
|
|
|
9
10
|
Platforms:
|
|
10
|
-
google — Google Ads (GAQL queries, keywords, accounts)
|
|
11
|
+
google — Google Ads (GAQL queries, keywords, accounts, ad library)
|
|
11
12
|
meta — Meta Ads (campaigns, adsets, ads, insights, previews)
|
|
13
|
+
x — X (Twitter) Ads (campaigns, line items, promoted tweets, analytics)
|
|
12
14
|
|
|
13
15
|
Examples:
|
|
14
16
|
baker ads google accounts
|
|
15
17
|
baker ads google query --preset campaign-performance --customer-id 1234567890
|
|
16
18
|
baker ads meta accounts
|
|
17
19
|
baker ads meta campaigns --account-id act_123 --effective-status ACTIVE
|
|
18
|
-
baker ads meta insights --object act_123 --level ad --date-preset last_7d --fields impressions,spend,ctr
|
|
20
|
+
baker ads meta insights --object act_123 --level ad --date-preset last_7d --fields impressions,spend,ctr
|
|
21
|
+
baker ads x accounts
|
|
22
|
+
baker ads x stats sync --preset campaign-engagement-7d --entity-ids abc,def`,
|
|
19
23
|
},
|
|
20
24
|
subCommands: {
|
|
21
25
|
google: googleCommand,
|
|
22
26
|
meta: metaCommand,
|
|
27
|
+
x: xCommand,
|
|
23
28
|
},
|
|
24
29
|
});
|
|
25
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/ads/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/ads/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;IACtC,IAAI,EAAE;QACJ,IAAI,EAAE,KAAK;QACX,WAAW,EAAE;;;;;;;;;;;;;;8EAc6D;KAC3E;IACD,WAAW,EAAE;QACX,MAAM,EAAE,aAAa;QACrB,IAAI,EAAE,WAAW;QACjB,CAAC,EAAE,QAAQ;KACZ;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const accountsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "no-cache": {
|
|
3
|
+
readonly type: "boolean";
|
|
4
|
+
readonly description: "Skip cache";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly output: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "Format: json|csv|md";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
readonly default: "json";
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/accounts.ts"],"names":[],"mappings":"AAuCA,eAAO,MAAM,eAAe;;;;;;;;;;;;EAqC1B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { ApiError, apiGet } from "../../../client.js";
|
|
3
|
+
import { handleConnectionError } from "../../../error-handler.js";
|
|
4
|
+
import { registerSchema } from "../../../schemas.js";
|
|
5
|
+
import { cacheGet, cacheSet } from "../cache.js";
|
|
6
|
+
import { writeAdsJson, writeAdsOutput } from "../output.js";
|
|
7
|
+
registerSchema({
|
|
8
|
+
command: "ads.x.accounts",
|
|
9
|
+
description: "List all accessible X Ads accounts. Returns accounts with id (base36), name, approval_status, timezone, currency. Run this first to find account IDs for other commands.",
|
|
10
|
+
args: {
|
|
11
|
+
"no-cache": { type: "boolean", description: "Skip cache, hit API directly", required: false },
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
function handleAccountsError(err) {
|
|
15
|
+
if (err instanceof ApiError) {
|
|
16
|
+
if (err.code === "UNAUTHORIZED" || err.code === "NOT_FOUND") {
|
|
17
|
+
handleConnectionError("x_ads", err.message);
|
|
18
|
+
}
|
|
19
|
+
const envelope = {
|
|
20
|
+
ok: false,
|
|
21
|
+
error: {
|
|
22
|
+
code: err.code,
|
|
23
|
+
message: err.message,
|
|
24
|
+
fix: { action: "reject", explanation: err.message },
|
|
25
|
+
retryable: false,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
writeAdsJson(envelope);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message: "Unexpected error" } });
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
export const accountsCommand = defineCommand({
|
|
35
|
+
meta: {
|
|
36
|
+
name: "accounts",
|
|
37
|
+
description: `List accessible X Ads accounts. Returns account IDs needed for all other commands.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
baker ads x accounts`,
|
|
41
|
+
},
|
|
42
|
+
args: {
|
|
43
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
44
|
+
output: { type: "string", description: "Format: json|csv|md", required: false, default: "json" },
|
|
45
|
+
},
|
|
46
|
+
run: async ({ args }) => {
|
|
47
|
+
const useCache = !args["no-cache"];
|
|
48
|
+
if (useCache) {
|
|
49
|
+
const cached = cacheGet("x-accounts", "list");
|
|
50
|
+
if (cached) {
|
|
51
|
+
writeAdsJson({ ok: true, data: cached.data, cached: true });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const params = !useCache ? { "skip-cache": "true" } : undefined;
|
|
57
|
+
const data = await apiGet("/api/ads/x/accounts", params);
|
|
58
|
+
if (useCache) {
|
|
59
|
+
cacheSet("x-accounts", "list", data, 60 * 60 * 1000);
|
|
60
|
+
}
|
|
61
|
+
const format = args.output || "json";
|
|
62
|
+
if (format !== "json") {
|
|
63
|
+
writeAdsOutput(data, format);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
writeAdsJson({ ok: true, data });
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
handleAccountsError(err);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,qBA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AAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const activeEntitiesCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "account-id": {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "X Ads account ID";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly entity: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "CAMPAIGN | LINE_ITEM | PROMOTED_TWEET";
|
|
10
|
+
readonly required: true;
|
|
11
|
+
};
|
|
12
|
+
readonly "start-time": {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "ISO 8601 hour-aligned start";
|
|
15
|
+
readonly required: true;
|
|
16
|
+
};
|
|
17
|
+
readonly "end-time": {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
readonly description: "ISO 8601 hour-aligned end";
|
|
20
|
+
readonly required: true;
|
|
21
|
+
};
|
|
22
|
+
readonly "campaign-ids": {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly description: "CSV of campaign IDs";
|
|
25
|
+
readonly required: false;
|
|
26
|
+
};
|
|
27
|
+
readonly "line-item-ids": {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly description: "CSV of line item IDs";
|
|
30
|
+
readonly required: false;
|
|
31
|
+
};
|
|
32
|
+
readonly "funding-instrument-ids": {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly description: "CSV of funding instrument IDs";
|
|
35
|
+
readonly required: false;
|
|
36
|
+
};
|
|
37
|
+
readonly "no-cache": {
|
|
38
|
+
readonly type: "boolean";
|
|
39
|
+
readonly description: "Skip cache";
|
|
40
|
+
readonly required: false;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
//# sourceMappingURL=active-entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-entities.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/active-entities.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDhC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { ApiError, apiPost } from "../../../client.js";
|
|
3
|
+
import { registerSchema } from "../../../schemas.js";
|
|
4
|
+
import { cacheGet, cacheSet } from "../cache.js";
|
|
5
|
+
import { writeAdsJson } from "../output.js";
|
|
6
|
+
import { parseXApiError } from "./error-parser.js";
|
|
7
|
+
import { resolveXAccountId } from "./output.js";
|
|
8
|
+
registerSchema({
|
|
9
|
+
command: "ads.x.activeEntities",
|
|
10
|
+
description: "List entities (campaigns/line items) that had metric activity within a time range. Use this to narrow which entities to query for stats. Time range max 90 days. Times must be ISO 8601 hour-aligned.",
|
|
11
|
+
args: {
|
|
12
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
13
|
+
entity: { type: "string", description: "CAMPAIGN | LINE_ITEM | PROMOTED_TWEET", required: true },
|
|
14
|
+
"start-time": { type: "string", description: "ISO 8601 hour-aligned start", required: true },
|
|
15
|
+
"end-time": { type: "string", description: "ISO 8601 hour-aligned end", required: true },
|
|
16
|
+
"campaign-ids": { type: "string", description: "CSV of campaign IDs", required: false },
|
|
17
|
+
"line-item-ids": { type: "string", description: "CSV of line item IDs", required: false },
|
|
18
|
+
"funding-instrument-ids": { type: "string", description: "CSV of funding instrument IDs", required: false },
|
|
19
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
function parseCsv(v) {
|
|
23
|
+
if (typeof v !== "string" || v.length === 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
const parts = v
|
|
26
|
+
.split(",")
|
|
27
|
+
.map((s) => s.trim())
|
|
28
|
+
.filter(Boolean);
|
|
29
|
+
return parts.length > 0 ? parts : undefined;
|
|
30
|
+
}
|
|
31
|
+
export const activeEntitiesCommand = defineCommand({
|
|
32
|
+
meta: {
|
|
33
|
+
name: "active-entities",
|
|
34
|
+
description: `List entities with metric activity in a time range.
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
baker ads x active-entities --account-id 18ce53xyz --entity LINE_ITEM \\
|
|
38
|
+
--start-time 2026-04-30T00:00:00Z --end-time 2026-05-07T00:00:00Z`,
|
|
39
|
+
},
|
|
40
|
+
args: {
|
|
41
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
42
|
+
entity: { type: "string", description: "CAMPAIGN | LINE_ITEM | PROMOTED_TWEET", required: true },
|
|
43
|
+
"start-time": { type: "string", description: "ISO 8601 hour-aligned start", required: true },
|
|
44
|
+
"end-time": { type: "string", description: "ISO 8601 hour-aligned end", required: true },
|
|
45
|
+
"campaign-ids": { type: "string", description: "CSV of campaign IDs", required: false },
|
|
46
|
+
"line-item-ids": { type: "string", description: "CSV of line item IDs", required: false },
|
|
47
|
+
"funding-instrument-ids": { type: "string", description: "CSV of funding instrument IDs", required: false },
|
|
48
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
49
|
+
},
|
|
50
|
+
run: async ({ args }) => {
|
|
51
|
+
const accountId = await resolveXAccountId(args);
|
|
52
|
+
const useCache = !args["no-cache"];
|
|
53
|
+
const body = {
|
|
54
|
+
accountId,
|
|
55
|
+
entity: args.entity,
|
|
56
|
+
startTime: args["start-time"],
|
|
57
|
+
endTime: args["end-time"],
|
|
58
|
+
fundingInstrumentIds: parseCsv(args["funding-instrument-ids"]),
|
|
59
|
+
campaignIds: parseCsv(args["campaign-ids"]),
|
|
60
|
+
lineItemIds: parseCsv(args["line-item-ids"]),
|
|
61
|
+
skipCache: !useCache || undefined,
|
|
62
|
+
};
|
|
63
|
+
const cacheKey = `active-entities:${JSON.stringify(body)}`;
|
|
64
|
+
if (useCache) {
|
|
65
|
+
const cached = cacheGet("x-account-data", cacheKey);
|
|
66
|
+
if (cached) {
|
|
67
|
+
writeAdsJson({ ok: true, data: cached.data, cached: true });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const data = await apiPost("/api/ads/x/active-entities", body);
|
|
73
|
+
if (useCache) {
|
|
74
|
+
cacheSet("x-account-data", cacheKey, data, 5 * 60 * 1000);
|
|
75
|
+
}
|
|
76
|
+
writeAdsJson({ ok: true, data });
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (err instanceof ApiError) {
|
|
80
|
+
writeAdsJson(parseXApiError(err.message, accountId));
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message: "Unexpected error" } });
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=active-entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-entities.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/active-entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,cAAc,CAAC;IACb,OAA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,CAAC;gBACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,YAAY,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAC;YAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const audiencesCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "account-id": {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "X Ads account ID";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly "no-cache": {
|
|
8
|
+
readonly type: "boolean";
|
|
9
|
+
readonly description: "Skip cache";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly output: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "Format: json|csv|md";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
readonly default: "json";
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=audiences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audiences.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/audiences.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;EA+C3B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { ApiError, apiGet } from "../../../client.js";
|
|
3
|
+
import { registerSchema } from "../../../schemas.js";
|
|
4
|
+
import { cacheGet, cacheSet } from "../cache.js";
|
|
5
|
+
import { writeAdsJson, writeAdsOutput } from "../output.js";
|
|
6
|
+
import { parseXApiError } from "./error-parser.js";
|
|
7
|
+
import { resolveXAccountId } from "./output.js";
|
|
8
|
+
registerSchema({
|
|
9
|
+
command: "ads.x.audiences",
|
|
10
|
+
description: "List custom audiences for an X Ads account. Returns id, name, audience_size, audience_type, targetable status. Audiences need 100+ active users in the past 90 days to be targetable.",
|
|
11
|
+
args: {
|
|
12
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
13
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export const audiencesCommand = defineCommand({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "audiences",
|
|
19
|
+
description: `List X Ads custom audiences.
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
baker ads x audiences --account-id 18ce53xyz`,
|
|
23
|
+
},
|
|
24
|
+
args: {
|
|
25
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
26
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
27
|
+
output: { type: "string", description: "Format: json|csv|md", required: false, default: "json" },
|
|
28
|
+
},
|
|
29
|
+
run: async ({ args }) => {
|
|
30
|
+
const accountId = await resolveXAccountId(args);
|
|
31
|
+
const useCache = !args["no-cache"];
|
|
32
|
+
const cacheKey = `audiences:${accountId}`;
|
|
33
|
+
if (useCache) {
|
|
34
|
+
const cached = cacheGet("x-account-data", cacheKey);
|
|
35
|
+
if (cached) {
|
|
36
|
+
writeAdsJson({ ok: true, data: cached.data, cached: true });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const params = { "account-id": accountId };
|
|
42
|
+
if (!useCache)
|
|
43
|
+
params["skip-cache"] = "true";
|
|
44
|
+
const data = await apiGet("/api/ads/x/custom-audiences", params);
|
|
45
|
+
if (useCache) {
|
|
46
|
+
cacheSet("x-account-data", cacheKey, data, 6 * 60 * 60 * 1000);
|
|
47
|
+
}
|
|
48
|
+
const format = args.output || "json";
|
|
49
|
+
if (format !== "json") {
|
|
50
|
+
writeAdsOutput(data, format);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
writeAdsJson({ ok: true, data });
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (err instanceof ApiError) {
|
|
57
|
+
writeAdsJson(parseXApiError(err.message, accountId));
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message: "Unexpected error" } });
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=audiences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audiences.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/audiences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,cAAc,CAAC;IACb,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EACT,uLAAuL;IACzL,IAAI,EAAE;QACJ,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE;QAClF,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC5E;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GA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AAQ,CAAC,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,MAAM,GAAI,IAAI,CAAC,MAAiB,IAAI,MAAM,CAAC;YACjD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;gBACtB,cAAc,CAAC,IAAsC,EAAE,MAAM,CAAC,CAAC;gBAC/D,OAAO;YACT,CAAC;YACD,YAAY,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBAC5B,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;gBACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,YAAY,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAC;YAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const campaignsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "account-id": {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "X Ads account ID";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly "funding-instrument-ids": {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "CSV of funding instrument IDs";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly "campaign-ids": {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "CSV of campaign IDs";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
};
|
|
17
|
+
readonly "with-deleted": {
|
|
18
|
+
readonly type: "boolean";
|
|
19
|
+
readonly description: "Include deleted";
|
|
20
|
+
readonly required: false;
|
|
21
|
+
};
|
|
22
|
+
readonly "no-cache": {
|
|
23
|
+
readonly type: "boolean";
|
|
24
|
+
readonly description: "Skip cache";
|
|
25
|
+
readonly required: false;
|
|
26
|
+
};
|
|
27
|
+
readonly output: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly description: "Format: json|csv|md";
|
|
30
|
+
readonly required: false;
|
|
31
|
+
readonly default: "json";
|
|
32
|
+
};
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=campaigns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"campaigns.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/campaigns.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuC3B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { registerSchema } from "../../../schemas.js";
|
|
3
|
+
import { resolveXAccountId } from "./output.js";
|
|
4
|
+
import { runListCommand } from "./run-list.js";
|
|
5
|
+
registerSchema({
|
|
6
|
+
command: "ads.x.campaigns",
|
|
7
|
+
description: "List campaigns for an X Ads account. Optionally filter by funding-instrument-ids or campaign-ids (comma-separated). Includes deleted with --with-deleted. Falls back to BAKER_X_ADS_ACCOUNT_ID.",
|
|
8
|
+
args: {
|
|
9
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
10
|
+
"funding-instrument-ids": { type: "string", description: "CSV of funding instrument IDs", required: false },
|
|
11
|
+
"campaign-ids": { type: "string", description: "CSV of campaign IDs", required: false },
|
|
12
|
+
"with-deleted": { type: "boolean", description: "Include deleted campaigns", required: false },
|
|
13
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export const campaignsCommand = defineCommand({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "campaigns",
|
|
19
|
+
description: `List X Ads campaigns. Returns budget, schedule, funding instrument, status.
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
baker ads x campaigns --account-id 18ce53xyz
|
|
23
|
+
baker ads x campaigns --account-id 18ce53xyz --campaign-ids abc,def
|
|
24
|
+
baker ads x campaigns --account-id 18ce53xyz --with-deleted`,
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
28
|
+
"funding-instrument-ids": { type: "string", description: "CSV of funding instrument IDs", required: false },
|
|
29
|
+
"campaign-ids": { type: "string", description: "CSV of campaign IDs", required: false },
|
|
30
|
+
"with-deleted": { type: "boolean", description: "Include deleted", required: false },
|
|
31
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
32
|
+
output: { type: "string", description: "Format: json|csv|md", required: false, default: "json" },
|
|
33
|
+
},
|
|
34
|
+
run: async ({ args }) => {
|
|
35
|
+
const accountId = await resolveXAccountId(args);
|
|
36
|
+
const useCache = !args["no-cache"];
|
|
37
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
38
|
+
const cacheKey = `campaigns:${accountId}:${today}:${args["funding-instrument-ids"] ?? ""}:${args["campaign-ids"] ?? ""}:${args["with-deleted"] ? "1" : "0"}`;
|
|
39
|
+
await runListCommand({
|
|
40
|
+
path: "/api/ads/x/campaigns",
|
|
41
|
+
cacheCategory: "x-account-data",
|
|
42
|
+
cacheKey,
|
|
43
|
+
cacheTtlMs: 60 * 60 * 1000,
|
|
44
|
+
params: {
|
|
45
|
+
"account-id": accountId,
|
|
46
|
+
"funding-instrument-ids": args["funding-instrument-ids"],
|
|
47
|
+
"campaign-ids": args["campaign-ids"],
|
|
48
|
+
"with-deleted": args["with-deleted"] ? "true" : undefined,
|
|
49
|
+
},
|
|
50
|
+
format: args.output || "json",
|
|
51
|
+
accountId,
|
|
52
|
+
useCache,
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=campaigns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"campaigns.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/campaigns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,cAAc,CAAC;IACb,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EACT,iMAAiM;IACnM,IAAI,EAAE;QACJ,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE;QAClF,wBAAwB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,+BAA+B,EAAE,QAAQ,EAAE,KAAK,EAAE;QAC3G,cAAc,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,EAAE;QACvF,cAAc,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,2BAA2B,EAAE,QAAQ,EAAE,KAAK,EAAE;QAC9F,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC5E;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;IAC5C,IAAI,EAAE;QACJ,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE;;;;;8DAK6C;KAC3D;IACD,IAAI,EAAE;QACJ,YAAY,EAAE,EAA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AAU,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;YAC1B,MAAM,EAAE;gBACN,YAAY,EAAE,SAAS;gBACvB,wBAAwB,EAAE,IAAI,CAAC,wBAAwB,CAAuB;gBAC9E,cAAc,EAAE,IAAI,CAAC,cAAc,CAAuB;gBAC1D,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;aAC1D;YACD,MAAM,EAAG,IAAI,CAAC,MAAiB,IAAI,MAAM;YACzC,SAAS;YACT,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const cardsCommand: import("citty").CommandDef<{
|
|
2
|
+
readonly "account-id": {
|
|
3
|
+
readonly type: "string";
|
|
4
|
+
readonly description: "X Ads account ID";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
};
|
|
7
|
+
readonly "no-cache": {
|
|
8
|
+
readonly type: "boolean";
|
|
9
|
+
readonly description: "Skip cache";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly output: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "Format: json|csv|md";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
readonly default: "json";
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=cards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cards.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/cards.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;EA+CvB,CAAC"}
|