@koda-sl/baker-cli 0.22.0-dev.ecc541fb → 0.25.0-dev.f89d9a60
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 +75 -9
- package/dist/cli.js +1 -1
- package/dist/commands/actions/create.d.ts +0 -5
- package/dist/commands/actions/create.d.ts.map +1 -1
- package/dist/commands/actions/create.js +0 -15
- package/dist/commands/actions/create.js.map +1 -1
- package/dist/commands/actions/update.d.ts +0 -5
- package/dist/commands/actions/update.d.ts.map +1 -1
- package/dist/commands/actions/update.js +3 -14
- package/dist/commands/actions/update.js.map +1 -1
- package/dist/commands/ads/index.d.ts.map +1 -1
- package/dist/commands/ads/index.js +8 -3
- 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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const mediaCommand: 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 "media-type": {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "IMAGE | GIF | VIDEO";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly "no-cache": {
|
|
13
|
+
readonly type: "boolean";
|
|
14
|
+
readonly description: "Skip cache";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
};
|
|
17
|
+
readonly output: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
readonly description: "Format: json|csv|md";
|
|
20
|
+
readonly required: false;
|
|
21
|
+
readonly default: "json";
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/media.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;EAkDvB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
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.media",
|
|
10
|
+
description: "List media assets in the X Ads media library (images, GIFs, videos). Filter by media-type (IMAGE, GIF, VIDEO).",
|
|
11
|
+
args: {
|
|
12
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
13
|
+
"media-type": { type: "string", description: "IMAGE | GIF | VIDEO", required: false },
|
|
14
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
export const mediaCommand = defineCommand({
|
|
18
|
+
meta: {
|
|
19
|
+
name: "media",
|
|
20
|
+
description: `List media assets in the X Ads media library.
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
baker ads x media --account-id 18ce53xyz
|
|
24
|
+
baker ads x media --account-id 18ce53xyz --media-type VIDEO`,
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
28
|
+
"media-type": { type: "string", description: "IMAGE | GIF | VIDEO", required: false },
|
|
29
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
30
|
+
output: { type: "string", description: "Format: json|csv|md", required: false, default: "json" },
|
|
31
|
+
},
|
|
32
|
+
run: async ({ args }) => {
|
|
33
|
+
const accountId = await resolveXAccountId(args);
|
|
34
|
+
const useCache = !args["no-cache"];
|
|
35
|
+
const cacheKey = `media:${accountId}:${args["media-type"] ?? "ALL"}`;
|
|
36
|
+
if (useCache) {
|
|
37
|
+
const cached = cacheGet("x-account-data", cacheKey);
|
|
38
|
+
if (cached) {
|
|
39
|
+
writeAdsJson({ ok: true, data: cached.data, cached: true });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const params = { "account-id": accountId };
|
|
45
|
+
if (args["media-type"])
|
|
46
|
+
params["media-type"] = args["media-type"];
|
|
47
|
+
if (!useCache)
|
|
48
|
+
params["skip-cache"] = "true";
|
|
49
|
+
const data = await apiGet("/api/ads/x/media-library", params);
|
|
50
|
+
if (useCache) {
|
|
51
|
+
cacheSet("x-account-data", cacheKey, data, 6 * 60 * 60 * 1000);
|
|
52
|
+
}
|
|
53
|
+
const format = args.output || "json";
|
|
54
|
+
if (format !== "json") {
|
|
55
|
+
writeAdsOutput(data, format);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
writeAdsJson({ ok: true, data });
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err instanceof ApiError) {
|
|
62
|
+
writeAdsJson(parseXApiError(err.message, accountId));
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message: "Unexpected error" } });
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/media.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,aAAa;IACtB,WAAW,EACT,gHAAgH;IAClH,IAAI,EAAE;QACJ,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE;QAClF,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qBAAqB,EAAE,QAAQ,EAAE,KAAK,EAAE;QACrF,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC5E;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;IACxC,IAAI,EAAE;QACJ,IAAI,EAAE,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C;YAC5E,IAAI,CAAC,QAAQ;gBAAE,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC;YAC7C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAY,0BAA0B,EAAE,MAAM,CAAC,CAAC;YACzE,IAAI,QAAQ,EAAE,CAAC;gBACb,QAAQ,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,13 @@
|
|
|
1
|
+
export interface XAccountInfo {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
approval_status?: string;
|
|
5
|
+
timezone?: string;
|
|
6
|
+
currency?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolve an X Ads account_id from either --account-id, BAKER_X_ADS_ACCOUNT_ID, or
|
|
10
|
+
* (if exactly one account is connected) auto-detect.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveXAccountId(args: Record<string, unknown>): Promise<string>;
|
|
13
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/output.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAiBD;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAmDtF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ApiError, apiGet } from "../../../client.js";
|
|
2
|
+
import { getEnv } from "../../../env.js";
|
|
3
|
+
import { handleConnectionError } from "../../../error-handler.js";
|
|
4
|
+
import { cacheGet, cacheSet } from "../cache.js";
|
|
5
|
+
import { writeAdsJson } from "../output.js";
|
|
6
|
+
const ACCOUNTS_CACHE_TTL_MS = 60 * 60 * 1000;
|
|
7
|
+
async function fetchXAccounts(useCache) {
|
|
8
|
+
if (useCache) {
|
|
9
|
+
const cached = cacheGet("x-accounts", "list");
|
|
10
|
+
if (cached)
|
|
11
|
+
return cached.data;
|
|
12
|
+
}
|
|
13
|
+
const params = !useCache ? { "skip-cache": "true" } : undefined;
|
|
14
|
+
const data = await apiGet("/api/ads/x/accounts", params);
|
|
15
|
+
if (useCache) {
|
|
16
|
+
cacheSet("x-accounts", "list", data, ACCOUNTS_CACHE_TTL_MS);
|
|
17
|
+
}
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve an X Ads account_id from either --account-id, BAKER_X_ADS_ACCOUNT_ID, or
|
|
22
|
+
* (if exactly one account is connected) auto-detect.
|
|
23
|
+
*/
|
|
24
|
+
export async function resolveXAccountId(args) {
|
|
25
|
+
const fromArgs = args["account-id"];
|
|
26
|
+
const accountId = fromArgs || getEnv().BAKER_X_ADS_ACCOUNT_ID;
|
|
27
|
+
if (accountId) {
|
|
28
|
+
if (!/^[a-z0-9]+$/.test(accountId)) {
|
|
29
|
+
writeAdsJson({
|
|
30
|
+
ok: false,
|
|
31
|
+
error: {
|
|
32
|
+
code: "INVALID_ACCOUNT_ID",
|
|
33
|
+
message: "X Ads account ID must be a base36 string (lowercase letters and digits). Pass --account-id or set BAKER_X_ADS_ACCOUNT_ID.",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
return accountId;
|
|
39
|
+
}
|
|
40
|
+
const useCache = !args["no-cache"];
|
|
41
|
+
try {
|
|
42
|
+
const accounts = await fetchXAccounts(useCache);
|
|
43
|
+
const [single] = accounts;
|
|
44
|
+
if (accounts.length === 1 && single) {
|
|
45
|
+
process.stderr.write(`Using account "${single.name}" (${single.id})\n`);
|
|
46
|
+
return single.id;
|
|
47
|
+
}
|
|
48
|
+
if (accounts.length === 0) {
|
|
49
|
+
handleConnectionError("x_ads");
|
|
50
|
+
}
|
|
51
|
+
const list = accounts.map((a) => ` ${a.id} ${a.name}`).join("\n");
|
|
52
|
+
writeAdsJson({
|
|
53
|
+
ok: false,
|
|
54
|
+
error: {
|
|
55
|
+
code: "MULTIPLE_ACCOUNTS",
|
|
56
|
+
message: `Multiple X Ads accounts found. Pass --account-id or set BAKER_X_ADS_ACCOUNT_ID:\n${list}`,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
if (err instanceof ApiError && (err.code === "UNAUTHORIZED" || err.code === "NOT_FOUND")) {
|
|
63
|
+
handleConnectionError("x_ads", err.message);
|
|
64
|
+
}
|
|
65
|
+
writeAdsJson({
|
|
66
|
+
ok: false,
|
|
67
|
+
error: {
|
|
68
|
+
code: "INVALID_ACCOUNT_ID",
|
|
69
|
+
message: "Could not auto-detect account. Pass --account-id or set BAKER_X_ADS_ACCOUNT_ID.",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAU5C,MAAM,qBAAqB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7C,KAAK,UAAU,cAAc,CAAC,QAAiB;IAC7C,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,QAAQ,CAAiB,YAAY,EAAE,MAAM,CAAC,CAAC;QAC9D,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACjC,CAAC;IACD,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAiB,qBAAqB,EAAE,MAAM,CAAC,CAAC;IACzE,IAAI,QAAQ,EAAE,CAAC;QACb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,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpE,YAAY,CAAC;YACX,EAAE,EAAE,KAAK;YACT,KAAK,EAAE;gBACL,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,oFAAoF,IAAI,EAAE;aACpG;SACF,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,CAAC;YACzF,qBAAqB,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,YAAY,CAAC;YACX,EAAE,EAAE,KAAK;YACT,KAAK,EAAE;gBACL,IAAI,EAAE,oBAAoB;gBAC1B,OAAO,EAAE,iFAAiF;aAC3F;SACF,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface XStatsPreset {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
entity: string;
|
|
5
|
+
metricGroups: string[];
|
|
6
|
+
granularity: "TOTAL" | "DAY" | "HOUR";
|
|
7
|
+
defaultDays: number;
|
|
8
|
+
placement: "ALL_ON_TWITTER" | "PUBLISHER_NETWORK";
|
|
9
|
+
}
|
|
10
|
+
export declare const X_STATS_PRESETS: XStatsPreset[];
|
|
11
|
+
export declare function getPreset(name: string): XStatsPreset | undefined;
|
|
12
|
+
/** Hour-aligned ISO 8601 string `daysAgo` days before now (UTC). */
|
|
13
|
+
export declare function isoHourFloor(daysAgo: number): string;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/presets.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,gBAAgB,GAAG,mBAAmB,CAAC;CACnD;AAED,eAAO,MAAM,eAAe,EAAE,YAAY,EA8CzC,CAAC;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEhE;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const X_STATS_PRESETS = [
|
|
2
|
+
{
|
|
3
|
+
name: "campaign-engagement-7d",
|
|
4
|
+
description: "Campaign-level engagements + impressions over the last 7 days, daily granularity",
|
|
5
|
+
entity: "CAMPAIGN",
|
|
6
|
+
metricGroups: ["ENGAGEMENT"],
|
|
7
|
+
granularity: "DAY",
|
|
8
|
+
defaultDays: 7,
|
|
9
|
+
placement: "ALL_ON_TWITTER",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "campaign-spend-30d",
|
|
13
|
+
description: "Campaign-level billed engagements + spend over the last 30 days, daily",
|
|
14
|
+
entity: "CAMPAIGN",
|
|
15
|
+
metricGroups: ["BILLING"],
|
|
16
|
+
granularity: "DAY",
|
|
17
|
+
defaultDays: 30,
|
|
18
|
+
placement: "ALL_ON_TWITTER",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "tweet-performance-7d",
|
|
22
|
+
description: "Promoted tweet engagement + media metrics over the last 7 days, daily",
|
|
23
|
+
entity: "PROMOTED_TWEET",
|
|
24
|
+
metricGroups: ["ENGAGEMENT", "MEDIA"],
|
|
25
|
+
granularity: "DAY",
|
|
26
|
+
defaultDays: 7,
|
|
27
|
+
placement: "ALL_ON_TWITTER",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "video-performance-30d",
|
|
31
|
+
description: "Promoted tweet video views/CTAs + engagement over the last 30 days, daily",
|
|
32
|
+
entity: "PROMOTED_TWEET",
|
|
33
|
+
metricGroups: ["VIDEO", "ENGAGEMENT"],
|
|
34
|
+
granularity: "DAY",
|
|
35
|
+
defaultDays: 30,
|
|
36
|
+
placement: "ALL_ON_TWITTER",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "line-item-conversions-30d",
|
|
40
|
+
description: "Line item web conversions + billing over the last 30 days, daily",
|
|
41
|
+
entity: "LINE_ITEM",
|
|
42
|
+
metricGroups: ["WEB_CONVERSION", "BILLING"],
|
|
43
|
+
granularity: "DAY",
|
|
44
|
+
defaultDays: 30,
|
|
45
|
+
placement: "ALL_ON_TWITTER",
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
export function getPreset(name) {
|
|
49
|
+
return X_STATS_PRESETS.find((p) => p.name === name);
|
|
50
|
+
}
|
|
51
|
+
/** Hour-aligned ISO 8601 string `daysAgo` days before now (UTC). */
|
|
52
|
+
export function isoHourFloor(daysAgo) {
|
|
53
|
+
const d = new Date();
|
|
54
|
+
d.setUTCMilliseconds(0);
|
|
55
|
+
d.setUTCSeconds(0);
|
|
56
|
+
d.setUTCMinutes(0);
|
|
57
|
+
d.setUTCDate(d.getUTCDate() - daysAgo);
|
|
58
|
+
return d.toISOString();
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/presets.ts"],"names":[],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AC,CAAC;AACtD,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;IACrB,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const promotedTweetsCommand: 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 "line-item-ids": {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly description: "CSV of line item IDs";
|
|
10
|
+
readonly required: false;
|
|
11
|
+
};
|
|
12
|
+
readonly "with-deleted": {
|
|
13
|
+
readonly type: "boolean";
|
|
14
|
+
readonly description: "Include deleted";
|
|
15
|
+
readonly required: false;
|
|
16
|
+
};
|
|
17
|
+
readonly "no-cache": {
|
|
18
|
+
readonly type: "boolean";
|
|
19
|
+
readonly description: "Skip cache";
|
|
20
|
+
readonly required: false;
|
|
21
|
+
};
|
|
22
|
+
readonly output: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly description: "Format: json|csv|md";
|
|
25
|
+
readonly required: false;
|
|
26
|
+
readonly default: "json";
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=promoted-tweets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promoted-tweets.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/promoted-tweets.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDhC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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.promotedTweets",
|
|
10
|
+
description: "List promoted tweets for an X Ads account. Returns id, line_item_id, tweet_id, approval_status. Filter by line-item-ids (CSV).",
|
|
11
|
+
args: {
|
|
12
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
13
|
+
"line-item-ids": { type: "string", description: "CSV of line item IDs", required: false },
|
|
14
|
+
"with-deleted": { type: "boolean", description: "Include deleted", required: false },
|
|
15
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export const promotedTweetsCommand = defineCommand({
|
|
19
|
+
meta: {
|
|
20
|
+
name: "promoted-tweets",
|
|
21
|
+
description: `List X Ads promoted tweets.
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
baker ads x promoted-tweets --account-id 18ce53xyz --line-item-ids abc,def`,
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
"account-id": { type: "string", description: "X Ads account ID", required: false },
|
|
28
|
+
"line-item-ids": { type: "string", description: "CSV of line item IDs", required: false },
|
|
29
|
+
"with-deleted": { type: "boolean", description: "Include deleted", required: false },
|
|
30
|
+
"no-cache": { type: "boolean", description: "Skip cache", required: false },
|
|
31
|
+
output: { type: "string", description: "Format: json|csv|md", required: false, default: "json" },
|
|
32
|
+
},
|
|
33
|
+
run: async ({ args }) => {
|
|
34
|
+
const accountId = await resolveXAccountId(args);
|
|
35
|
+
const useCache = !args["no-cache"];
|
|
36
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
37
|
+
const cacheKey = `promoted-tweets:${accountId}:${today}:${args["line-item-ids"] ?? ""}:${args["with-deleted"] ? "1" : "0"}`;
|
|
38
|
+
if (useCache) {
|
|
39
|
+
const cached = cacheGet("x-account-data", cacheKey);
|
|
40
|
+
if (cached) {
|
|
41
|
+
writeAdsJson({ ok: true, data: cached.data, cached: true });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const params = { "account-id": accountId };
|
|
47
|
+
if (args["line-item-ids"])
|
|
48
|
+
params["line-item-ids"] = args["line-item-ids"];
|
|
49
|
+
if (args["with-deleted"])
|
|
50
|
+
params["with-deleted"] = "true";
|
|
51
|
+
if (!useCache)
|
|
52
|
+
params["skip-cache"] = "true";
|
|
53
|
+
const data = await apiGet("/api/ads/x/promoted-tweets", params);
|
|
54
|
+
if (useCache) {
|
|
55
|
+
cacheSet("x-account-data", cacheKey, data, 60 * 60 * 1000);
|
|
56
|
+
}
|
|
57
|
+
const format = args.output || "json";
|
|
58
|
+
if (format !== "json") {
|
|
59
|
+
writeAdsOutput(data, format);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
writeAdsJson({ ok: true, data });
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err instanceof ApiError) {
|
|
66
|
+
writeAdsJson(parseXApiError(err.message, accountId));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message: "Unexpected error" } });
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=promoted-tweets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface ListParams {
|
|
2
|
+
path: string;
|
|
3
|
+
cacheCategory: string;
|
|
4
|
+
cacheKey: string;
|
|
5
|
+
cacheTtlMs?: number;
|
|
6
|
+
params: Record<string, string | undefined>;
|
|
7
|
+
format: string;
|
|
8
|
+
accountId?: string;
|
|
9
|
+
useCache: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Shared GET-list flow: cache check → request → cache set → format-aware output.
|
|
13
|
+
* Centralizing this keeps each CLI command file under Biome's complexity budget.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runListCommand(opts: ListParams): Promise<void>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=run-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-list.d.ts","sourceRoot":"","sources":["../../../../src/commands/ads/x/run-list.ts"],"names":[],"mappings":"AAKA,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAwCD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAYpE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ApiError, apiGet } from "../../../client.js";
|
|
2
|
+
import { cacheGet, cacheSet } from "../cache.js";
|
|
3
|
+
import { writeAdsJson, writeAdsOutput } from "../output.js";
|
|
4
|
+
import { parseXApiError } from "./error-parser.js";
|
|
5
|
+
function buildCleanParams(opts) {
|
|
6
|
+
const out = {};
|
|
7
|
+
for (const [k, v] of Object.entries(opts.params)) {
|
|
8
|
+
if (v !== undefined && v !== "") {
|
|
9
|
+
out[k] = v;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!opts.useCache) {
|
|
13
|
+
out["skip-cache"] = "true";
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
function emitFromCache(opts) {
|
|
18
|
+
if (!opts.useCache || opts.cacheTtlMs === undefined)
|
|
19
|
+
return false;
|
|
20
|
+
const cached = cacheGet(opts.cacheCategory, opts.cacheKey);
|
|
21
|
+
if (!cached)
|
|
22
|
+
return false;
|
|
23
|
+
writeAdsJson({ ok: true, data: cached.data, cached: true });
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function emitData(opts, data) {
|
|
27
|
+
if (opts.format !== "json") {
|
|
28
|
+
writeAdsOutput(data, opts.format);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
writeAdsJson({ ok: true, data });
|
|
32
|
+
}
|
|
33
|
+
function emitError(opts, err) {
|
|
34
|
+
if (err instanceof ApiError) {
|
|
35
|
+
writeAdsJson(parseXApiError(err.message, opts.accountId ?? "—"));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
writeAdsJson({ ok: false, error: { code: "NETWORK_ERROR", message: "Unexpected error" } });
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Shared GET-list flow: cache check → request → cache set → format-aware output.
|
|
43
|
+
* Centralizing this keeps each CLI command file under Biome's complexity budget.
|
|
44
|
+
*/
|
|
45
|
+
export async function runListCommand(opts) {
|
|
46
|
+
if (emitFromCache(opts))
|
|
47
|
+
return;
|
|
48
|
+
const params = buildCleanParams(opts);
|
|
49
|
+
try {
|
|
50
|
+
const data = await apiGet(opts.path, params);
|
|
51
|
+
if (opts.useCache && opts.cacheTtlMs !== undefined) {
|
|
52
|
+
cacheSet(opts.cacheCategory, opts.cacheKey, data, opts.cacheTtlMs);
|
|
53
|
+
}
|
|
54
|
+
emitData(opts, data);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
emitError(opts, err);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=run-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-list.js","sourceRoot":"","sources":["../../../../src/commands/ads/x/run-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACtD,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;AAanD,SAAS,gBAAgB,CAAC,IAAgB;IACxC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YAChC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;IACH,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,GAAG,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,aAAa,CAAC,IAAgB;IACrC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClE,MAAM,MAAM,GAAG,QAAQ,CAAY,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtE,IAAI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K,SAAS,EAAE,CAAC;YACnD,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACrE,CAAC;QACD,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/commands/ads/x/stats/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,qDAyBvB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { statsJobCommand } from "./job.js";
|
|
3
|
+
import { statsJobCreateCommand } from "./job-create.js";
|
|
4
|
+
import { statsJobStatusCommand } from "./job-status.js";
|
|
5
|
+
import { statsSyncCommand } from "./sync.js";
|
|
6
|
+
export const statsCommand = defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "stats",
|
|
9
|
+
description: `X Ads analytics. Sync (≤7 days, no segmentation) or async jobs (≤90 days, segmentable).
|
|
10
|
+
|
|
11
|
+
Subcommands:
|
|
12
|
+
sync — synchronous stats (max 7 days). Cheapest, fastest.
|
|
13
|
+
job — async stats job, end-to-end (creates + polls + downloads). Must run in the background.
|
|
14
|
+
Use for ranges >7 days, segmented stats, or when sync limits are hit.
|
|
15
|
+
job-create — low-level: create an async stats job and return the ID immediately
|
|
16
|
+
job-status — low-level: poll job status / get the download URL
|
|
17
|
+
|
|
18
|
+
Examples:
|
|
19
|
+
baker ads x stats sync --preset campaign-engagement-7d --entity-ids abc,def
|
|
20
|
+
baker ads x stats job --account-id 18ce53xyz --entity CAMPAIGN \\
|
|
21
|
+
--entity-ids abc,def --start-time 2026-04-01T00:00:00Z \\
|
|
22
|
+
--end-time 2026-05-01T00:00:00Z --metric-groups ENGAGEMENT,BILLING
|
|
23
|
+
baker ads x stats job-status --account-id 18ce53xyz --job-id abc`,
|
|
24
|
+
},
|
|
25
|
+
subCommands: {
|
|
26
|
+
sync: statsSyncCommand,
|
|
27
|
+
job: statsJobCommand,
|
|
28
|
+
"job-create": statsJobCreateCommand,
|
|
29
|
+
"job-status": statsJobStatusCommand,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/commands/ads/x/stats/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;IACxC,IAAI,EAAE;QACJ,IAAI,EAAE,OAAO;QACb,WAAW,EAAE;;;;;;;;;;;;;;mEAckD;KAChE;IACD,WAAW,EAAE;QACX,IAAI,EAAE,gBAAgB;QACtB,GAAG,EAAE,eAAe;QACpB,YAAY,EAAE,qBAAqB;QACnC,YAAY,EAAE,qBAAqB;KACpC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const statsJobCreateCommand: 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: "Entity type";
|
|
10
|
+
readonly required: true;
|
|
11
|
+
};
|
|
12
|
+
readonly "entity-ids": {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "CSV of entity IDs";
|
|
15
|
+
readonly required: true;
|
|
16
|
+
};
|
|
17
|
+
readonly "start-time": {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
readonly description: "ISO start";
|
|
20
|
+
readonly required: true;
|
|
21
|
+
};
|
|
22
|
+
readonly "end-time": {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly description: "ISO end";
|
|
25
|
+
readonly required: true;
|
|
26
|
+
};
|
|
27
|
+
readonly granularity: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly description: "Granularity";
|
|
30
|
+
readonly required: false;
|
|
31
|
+
};
|
|
32
|
+
readonly "metric-groups": {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly description: "Metric groups CSV";
|
|
35
|
+
readonly required: true;
|
|
36
|
+
};
|
|
37
|
+
readonly placement: {
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
readonly description: "Placement";
|
|
40
|
+
readonly required: false;
|
|
41
|
+
};
|
|
42
|
+
readonly "segmentation-type": {
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
readonly description: "Segmentation type";
|
|
45
|
+
readonly required: false;
|
|
46
|
+
};
|
|
47
|
+
readonly country: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
readonly description: "Country filter";
|
|
50
|
+
readonly required: false;
|
|
51
|
+
};
|
|
52
|
+
readonly platform: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
readonly description: "Platform filter";
|
|
55
|
+
readonly required: false;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
//# sourceMappingURL=job-create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-create.d.ts","sourceRoot":"","sources":["../../../../../src/commands/ads/x/stats/job-create.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4DhC,CAAC"}
|