siluzan-tso-cli 1.1.75-beta.2 → 1.1.75-beta.3
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 +1 -1
- package/dist/index.js +1699 -1818
- package/dist/skill/SKILL.md +8 -6
- package/dist/skill/_meta.json +2 -2
- package/dist/skill/assets/pmax-create-template.md +16 -2
- package/dist/skill/references/README.md +1 -0
- package/dist/skill/references/analytics/account-analytics.md +33 -0
- package/dist/skill/references/analytics/ga4-report.md +41 -0
- package/dist/skill/references/core/agent-conventions.md +3 -9
- package/dist/skill/references/core/workflows.md +3 -3
- package/dist/skill/references/google-ads/demand-gen-api.md +7 -6
- package/dist/skill/references/google-ads/google-ads-campaign-plan.md +1 -1
- package/dist/skill/references/google-ads/google-ads-read.md +1 -1
- package/dist/skill/references/google-ads/google-ads-write.md +19 -11
- package/dist/skill/references/google-ads/google-ads.md +1 -1
- package/dist/skill/references/google-ads/pmax-api.md +3 -1
- package/dist/skill/references/google-ads/rules/README.md +1 -1
- package/dist/skill/references/google-ads/rules/google-ads-audience-strategy.md +33 -33
- package/dist/skill/references/google-ads/rules/google-ads-launch-plan-template.md +1 -1
- package/dist/skill/references/google-ads/rules/google-ads-pmax-guide.md +24 -22
- package/dist/skill/references/google-ads/rules/google-ads-pmax-launch-plan-template.md +13 -2
- package/dist/skill/references/operations/ad-gap.md +121 -15
- package/dist/skill/references/operations/hosted-automation-optimize-scale.md +1 -1
- package/dist/skill/scripts/install.ps1 +1 -1
- package/dist/skill/scripts/install.sh +1 -1
- package/package.json +1 -2
- package/eval/cases/write-readback-budget-mismatch.scenario.json +0 -19
- package/eval/cases/write-readback-extra-country.scenario.json +0 -19
package/dist/index.js
CHANGED
|
@@ -1967,6 +1967,7 @@ import * as fs from "fs";
|
|
|
1967
1967
|
import * as path from "path";
|
|
1968
1968
|
import * as os from "os";
|
|
1969
1969
|
import lockfile from "proper-lockfile";
|
|
1970
|
+
import { randomBytes } from "crypto";
|
|
1970
1971
|
import * as https from "https";
|
|
1971
1972
|
import * as http from "http";
|
|
1972
1973
|
import * as zlib from "zlib";
|
|
@@ -2397,7 +2398,7 @@ function rawRequest(url, options) {
|
|
|
2397
2398
|
stream = res.pipe(zlib.createBrotliDecompress());
|
|
2398
2399
|
}
|
|
2399
2400
|
let failed = false;
|
|
2400
|
-
const
|
|
2401
|
+
const fail10 = (err) => {
|
|
2401
2402
|
if (failed) return;
|
|
2402
2403
|
failed = true;
|
|
2403
2404
|
res.destroy();
|
|
@@ -2416,7 +2417,7 @@ function rawRequest(url, options) {
|
|
|
2416
2417
|
reject(err);
|
|
2417
2418
|
};
|
|
2418
2419
|
const onStreamError = (err) => {
|
|
2419
|
-
|
|
2420
|
+
fail10(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
|
|
2420
2421
|
};
|
|
2421
2422
|
if (stream !== res) stream.on("error", onStreamError);
|
|
2422
2423
|
res.on("error", onStreamError);
|
|
@@ -2427,7 +2428,7 @@ function rawRequest(url, options) {
|
|
|
2427
2428
|
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
2428
2429
|
byteLen += buf.length;
|
|
2429
2430
|
if (maxBytes > 0 && byteLen > maxBytes) {
|
|
2430
|
-
|
|
2431
|
+
fail10(
|
|
2431
2432
|
new Error(`\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650\uFF08${(maxBytes / 1024 / 1024).toFixed(0)} MB\uFF09\uFF0C\u5DF2\u4E2D\u65AD\u8FDE\u63A5`)
|
|
2432
2433
|
);
|
|
2433
2434
|
return;
|
|
@@ -2607,6 +2608,40 @@ function formatHttpError(status, rawBody, opts) {
|
|
|
2607
2608
|
function buildAuthHeaders(config) {
|
|
2608
2609
|
return buildSiluzanAuthHeaders(config);
|
|
2609
2610
|
}
|
|
2611
|
+
function buildMultipartBody(fields, files) {
|
|
2612
|
+
const boundary = `----SiluzanForm${randomBytes(16).toString("hex")}`;
|
|
2613
|
+
const chunks = [];
|
|
2614
|
+
for (const [name2, value] of Object.entries(fields)) {
|
|
2615
|
+
chunks.push(
|
|
2616
|
+
Buffer.from(
|
|
2617
|
+
`--${boundary}\r
|
|
2618
|
+
Content-Disposition: form-data; name="${name2}"\r
|
|
2619
|
+
\r
|
|
2620
|
+
${value}\r
|
|
2621
|
+
`
|
|
2622
|
+
)
|
|
2623
|
+
);
|
|
2624
|
+
}
|
|
2625
|
+
for (const file of files) {
|
|
2626
|
+
chunks.push(
|
|
2627
|
+
Buffer.from(
|
|
2628
|
+
`--${boundary}\r
|
|
2629
|
+
Content-Disposition: form-data; name="${file.field}"; filename="${file.filename}"\r
|
|
2630
|
+
Content-Type: ${file.contentType}\r
|
|
2631
|
+
\r
|
|
2632
|
+
`
|
|
2633
|
+
)
|
|
2634
|
+
);
|
|
2635
|
+
chunks.push(file.data);
|
|
2636
|
+
chunks.push(Buffer.from("\r\n"));
|
|
2637
|
+
}
|
|
2638
|
+
chunks.push(Buffer.from(`--${boundary}--\r
|
|
2639
|
+
`));
|
|
2640
|
+
return {
|
|
2641
|
+
body: Buffer.concat(chunks),
|
|
2642
|
+
contentType: `multipart/form-data; boundary=${boundary}`
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2610
2645
|
async function parseApiResponse(status, text5, verbose) {
|
|
2611
2646
|
if (status < 200 || status >= 300) {
|
|
2612
2647
|
const err = new Error(formatHttpError(status, text5, { verbose }));
|
|
@@ -2667,6 +2702,22 @@ async function apiFetch(url, config, options = {}, verbose = false, timeoutMs) {
|
|
|
2667
2702
|
});
|
|
2668
2703
|
return parseApiResponse(res.status, res.text, verbose);
|
|
2669
2704
|
}
|
|
2705
|
+
async function apiFetchMultipart(url, config, payload, verbose = false) {
|
|
2706
|
+
const packed = buildMultipartBody(payload.fields ?? {}, payload.files);
|
|
2707
|
+
const reqHeaders = {
|
|
2708
|
+
"Content-Type": packed.contentType,
|
|
2709
|
+
"Accept-Language": "zh-CN",
|
|
2710
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
2711
|
+
...buildAuthHeaders(config),
|
|
2712
|
+
Datapermission: config.dataPermission ?? ""
|
|
2713
|
+
};
|
|
2714
|
+
const res = await rawRequest(url, {
|
|
2715
|
+
method: "POST",
|
|
2716
|
+
headers: reqHeaders,
|
|
2717
|
+
body: packed.body
|
|
2718
|
+
});
|
|
2719
|
+
return parseApiResponse(res.status, res.text, verbose);
|
|
2720
|
+
}
|
|
2670
2721
|
async function apiFetchWithHeaders(url, config, options = {}, verbose = false) {
|
|
2671
2722
|
const method = options.method ?? "GET";
|
|
2672
2723
|
const reqHeaders = {
|
|
@@ -4415,6 +4466,11 @@ async function apiFetch2(url, config, options = {}, verbose = false, timeoutMs)
|
|
|
4415
4466
|
value: await apiFetch(url, config, options, verbose, timeoutMs)
|
|
4416
4467
|
}));
|
|
4417
4468
|
}
|
|
4469
|
+
async function apiFetchMultipart2(url, config, payload, verbose = false) {
|
|
4470
|
+
return withWriteAudit({ config, url, method: "POST", verbose }, async () => ({
|
|
4471
|
+
value: await apiFetchMultipart(url, config, payload, verbose)
|
|
4472
|
+
}));
|
|
4473
|
+
}
|
|
4418
4474
|
async function apiFetchWithHeaders2(url, config, options = {}, verbose = false) {
|
|
4419
4475
|
const method = options.method ?? "GET";
|
|
4420
4476
|
if (!isMutatingHttpMethod(method)) {
|
|
@@ -6375,7 +6431,6 @@ function negativeKeywordSlimListUrl(googleApiUrl, accountId, query) {
|
|
|
6375
6431
|
if (query?.appliedLevel) params.set("appliedlevel", query.appliedLevel);
|
|
6376
6432
|
if (query?.readDeleted) params.set("readDeleted", "true");
|
|
6377
6433
|
if (query?.excludePaused) params.set("excludePaused", "true");
|
|
6378
|
-
if (query?.newest) params.set("newest", "true");
|
|
6379
6434
|
const text5 = query?.keywordText?.trim();
|
|
6380
6435
|
if (text5) params.set("keywordtext", text5);
|
|
6381
6436
|
if (query?.matchType) params.set("matchtype", query.matchType);
|
|
@@ -6402,11 +6457,11 @@ function toDisplayMoney(raw) {
|
|
|
6402
6457
|
if (!Number.isFinite(n)) return null;
|
|
6403
6458
|
return n / 100;
|
|
6404
6459
|
}
|
|
6405
|
-
function toCentAmount(
|
|
6406
|
-
if (!Number.isFinite(
|
|
6407
|
-
throw new Error(`toCentAmount: \u8F93\u5165\u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${
|
|
6460
|
+
function toCentAmount(displayValue) {
|
|
6461
|
+
if (!Number.isFinite(displayValue)) {
|
|
6462
|
+
throw new Error(`toCentAmount: \u8F93\u5165\u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${displayValue}`);
|
|
6408
6463
|
}
|
|
6409
|
-
return Math.round(
|
|
6464
|
+
return Math.round(displayValue * 100);
|
|
6410
6465
|
}
|
|
6411
6466
|
function convertBatchMoneyTreeFromYuan(value) {
|
|
6412
6467
|
return convertBatchMoneyTreeFromYuanInner(value);
|
|
@@ -105519,18 +105574,18 @@ import fs32 from "fs";
|
|
|
105519
105574
|
import fsPromises2 from "fs/promises";
|
|
105520
105575
|
import path37 from "path";
|
|
105521
105576
|
import { fileURLToPath as fileURLToPath9 } from "url";
|
|
105522
|
-
function resolveSkillTemplatePath3(
|
|
105577
|
+
function resolveSkillTemplatePath3(basename15) {
|
|
105523
105578
|
const dir = path37.dirname(fileURLToPath9(import.meta.url));
|
|
105524
105579
|
const candidates = [
|
|
105525
|
-
path37.join(dir, "skill", "report-templates",
|
|
105526
|
-
path37.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
105527
|
-
path37.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
105528
|
-
path37.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
105580
|
+
path37.join(dir, "skill", "report-templates", basename15),
|
|
105581
|
+
path37.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
105582
|
+
path37.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename15),
|
|
105583
|
+
path37.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
105529
105584
|
];
|
|
105530
105585
|
for (const candidate of candidates) {
|
|
105531
105586
|
if (fs32.existsSync(candidate)) return candidate;
|
|
105532
105587
|
}
|
|
105533
|
-
return path37.join(dir, "skill", "report-templates",
|
|
105588
|
+
return path37.join(dir, "skill", "report-templates", basename15);
|
|
105534
105589
|
}
|
|
105535
105590
|
function demandGenReportTemplatePath() {
|
|
105536
105591
|
return resolveSkillTemplatePath3(TEMPLATE_BASENAME);
|
|
@@ -107331,12 +107386,12 @@ import fs37 from "fs";
|
|
|
107331
107386
|
import fsPromises3 from "fs/promises";
|
|
107332
107387
|
import path42 from "path";
|
|
107333
107388
|
import { fileURLToPath as fileURLToPath10 } from "url";
|
|
107334
|
-
function resolveSkillTemplatePath4(
|
|
107389
|
+
function resolveSkillTemplatePath4(basename15) {
|
|
107335
107390
|
const dir = path42.dirname(fileURLToPath10(import.meta.url));
|
|
107336
107391
|
const candidates = [
|
|
107337
|
-
path42.join(dir, "skill", "report-templates",
|
|
107338
|
-
path42.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
107339
|
-
path42.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
107392
|
+
path42.join(dir, "skill", "report-templates", basename15),
|
|
107393
|
+
path42.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
107394
|
+
path42.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
107340
107395
|
];
|
|
107341
107396
|
for (const p of candidates) {
|
|
107342
107397
|
if (fs37.existsSync(p)) return p;
|
|
@@ -107897,8 +107952,8 @@ var init_batch_runner = __esm({
|
|
|
107897
107952
|
shouldDowngrade(now = Date.now()) {
|
|
107898
107953
|
if (this.window.length < this.opts.windowSize) return false;
|
|
107899
107954
|
if (now - this.lastDowngradeAt < this.opts.cooldownMs) return false;
|
|
107900
|
-
const
|
|
107901
|
-
const rate2 =
|
|
107955
|
+
const fail10 = this.window.filter((s) => !s).length;
|
|
107956
|
+
const rate2 = fail10 / this.window.length;
|
|
107902
107957
|
if (rate2 >= this.opts.errorRateThreshold) {
|
|
107903
107958
|
this.lastDowngradeAt = now;
|
|
107904
107959
|
this.window.length = 0;
|
|
@@ -113575,263 +113630,6 @@ async function runReportDelete(opts) {
|
|
|
113575
113630
|
init_auth();
|
|
113576
113631
|
init_cli_table();
|
|
113577
113632
|
init_cli_json_snapshot();
|
|
113578
|
-
|
|
113579
|
-
// src/commands/account-readback.ts
|
|
113580
|
-
init_auth();
|
|
113581
|
-
|
|
113582
|
-
// src/commands/write-receipt-record.ts
|
|
113583
|
-
init_auth();
|
|
113584
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
113585
|
-
var POST_SCRIPT = `
|
|
113586
|
-
fetch(process.env.RECEIPT_URL, {
|
|
113587
|
-
method: "POST",
|
|
113588
|
-
headers: {
|
|
113589
|
-
"content-type": "application/json",
|
|
113590
|
-
[process.env.RECEIPT_AUTH_NAME]: process.env.RECEIPT_AUTH_VALUE,
|
|
113591
|
-
},
|
|
113592
|
-
body: require("node:fs").readFileSync(0, "utf8"),
|
|
113593
|
-
signal: AbortSignal.timeout(2000),
|
|
113594
|
-
}).then(async (response) => {
|
|
113595
|
-
let state = "";
|
|
113596
|
-
try { state = JSON.parse(await response.text()).state; } catch { state = ""; }
|
|
113597
|
-
process.exit(response.ok && state === "ok" ? 0 : 2);
|
|
113598
|
-
}).catch(() => process.exit(1));
|
|
113599
|
-
`;
|
|
113600
|
-
function flagValue(argv, flags) {
|
|
113601
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
113602
|
-
const token = argv[i] ?? "";
|
|
113603
|
-
for (const flag of flags) {
|
|
113604
|
-
if (token === flag) {
|
|
113605
|
-
const next = argv[i + 1] ?? "";
|
|
113606
|
-
return next.startsWith("-") ? "" : next;
|
|
113607
|
-
}
|
|
113608
|
-
if (token.startsWith(`${flag}=`)) return token.slice(flag.length + 1);
|
|
113609
|
-
}
|
|
113610
|
-
}
|
|
113611
|
-
return "";
|
|
113612
|
-
}
|
|
113613
|
-
function commandContextFromArgv(argv) {
|
|
113614
|
-
const parts = [];
|
|
113615
|
-
for (const token of argv) {
|
|
113616
|
-
if (!token || token.includes("node") || token.endsWith("index.js") || token.endsWith("index.ts") || token.endsWith("cli.mjs")) {
|
|
113617
|
-
continue;
|
|
113618
|
-
}
|
|
113619
|
-
if (token.startsWith("-")) break;
|
|
113620
|
-
parts.push(token);
|
|
113621
|
-
if (parts.length >= 3) break;
|
|
113622
|
-
}
|
|
113623
|
-
return {
|
|
113624
|
-
command: parts.join(" "),
|
|
113625
|
-
accountId: flagValue(argv, ["-a", "--account"]),
|
|
113626
|
-
resourceId: flagValue(argv, ["--id"])
|
|
113627
|
-
};
|
|
113628
|
-
}
|
|
113629
|
-
function buildWriteReadSnapshot(verification, lines, argv) {
|
|
113630
|
-
const expected = {};
|
|
113631
|
-
const read = {};
|
|
113632
|
-
for (const line of lines) {
|
|
113633
|
-
expected[line.label] = line.expected;
|
|
113634
|
-
read[line.label] = line.actual;
|
|
113635
|
-
}
|
|
113636
|
-
const command = commandContextFromArgv(argv);
|
|
113637
|
-
return {
|
|
113638
|
-
verification,
|
|
113639
|
-
command: command.command,
|
|
113640
|
-
accountId: command.accountId,
|
|
113641
|
-
resourceId: command.resourceId,
|
|
113642
|
-
threadId: process.env.DEERFLOW_THREAD_ID?.trim() ?? "",
|
|
113643
|
-
runId: process.env.DEERFLOW_RUN_ID?.trim() ?? "",
|
|
113644
|
-
expected,
|
|
113645
|
-
read,
|
|
113646
|
-
lines
|
|
113647
|
-
};
|
|
113648
|
-
}
|
|
113649
|
-
function resolveReceiptPost(config) {
|
|
113650
|
-
const base2 = config.mainApiUrl?.trim().replace(/\/$/, "") ?? "";
|
|
113651
|
-
if (!base2) return null;
|
|
113652
|
-
const apiKey = config.apiKey?.trim();
|
|
113653
|
-
if (apiKey) {
|
|
113654
|
-
return { url: `${base2}/command/write-read-receipt`, authName: "x-api-key", authValue: apiKey };
|
|
113655
|
-
}
|
|
113656
|
-
const token = config.authToken?.trim();
|
|
113657
|
-
if (!token) return null;
|
|
113658
|
-
return { url: `${base2}/command/write-read-receipt`, authName: "Authorization", authValue: `Bearer ${token}` };
|
|
113659
|
-
}
|
|
113660
|
-
function postWriteReadSnapshot(url, authName, authValue, body, spawn3 = spawnSync2) {
|
|
113661
|
-
return spawn3(process.execPath, ["-e", POST_SCRIPT], {
|
|
113662
|
-
input: body,
|
|
113663
|
-
timeout: 2500,
|
|
113664
|
-
encoding: "utf8",
|
|
113665
|
-
env: { ...process.env, RECEIPT_URL: url, RECEIPT_AUTH_NAME: authName, RECEIPT_AUTH_VALUE: authValue }
|
|
113666
|
-
});
|
|
113667
|
-
}
|
|
113668
|
-
function recordWriteReadReceipt(verification, lines, load = loadConfig, spawn3 = spawnSync2) {
|
|
113669
|
-
let target;
|
|
113670
|
-
try {
|
|
113671
|
-
target = resolveReceiptPost(load());
|
|
113672
|
-
} catch {
|
|
113673
|
-
console.error("write-read receipt \u672A\u8BB0\u4E0B");
|
|
113674
|
-
return;
|
|
113675
|
-
}
|
|
113676
|
-
if (!target) return;
|
|
113677
|
-
const snapshot = buildWriteReadSnapshot(verification, lines, process.argv);
|
|
113678
|
-
const result = postWriteReadSnapshot(target.url, target.authName, target.authValue, JSON.stringify(snapshot), spawn3);
|
|
113679
|
-
if (result.status !== 0) {
|
|
113680
|
-
console.error("write-read receipt \u672A\u8BB0\u4E0B");
|
|
113681
|
-
}
|
|
113682
|
-
}
|
|
113683
|
-
|
|
113684
|
-
// src/commands/write-receipt.ts
|
|
113685
|
-
var UNREAD = "\uFF08\u672A\u8BFB\u5230\uFF09";
|
|
113686
|
-
var CENT_YUAN_FIELDS = {
|
|
113687
|
-
budget: "\u65E5\u9884\u7B97",
|
|
113688
|
-
targetCpa_BidingAmount: "\u76EE\u6807CPA",
|
|
113689
|
-
targetSpend_BidCeilingAmount: "CPC\u4E0A\u9650"
|
|
113690
|
-
};
|
|
113691
|
-
var FIELD_LABELS = {
|
|
113692
|
-
statusV2: "\u72B6\u6001",
|
|
113693
|
-
biddingStrategyTypeV2: "\u51FA\u4EF7\u7B56\u7565",
|
|
113694
|
-
targetRoas: "\u76EE\u6807ROAS",
|
|
113695
|
-
positiveGeoTargetTypeV2: "\u4F4D\u7F6E\u9009\u9879",
|
|
113696
|
-
negativeGeoTargetTypeV2: "\u6392\u9664\u4F4D\u7F6E\u9009\u9879",
|
|
113697
|
-
name: "\u540D\u79F0",
|
|
113698
|
-
daily_budget: "\u65E5\u9884\u7B97",
|
|
113699
|
-
status: "\u72B6\u6001",
|
|
113700
|
-
countries: "\u56FD\u5BB6",
|
|
113701
|
-
finalUrl: "\u843D\u5730\u9875",
|
|
113702
|
-
finalURL: "\u843D\u5730\u9875"
|
|
113703
|
-
};
|
|
113704
|
-
function yuanLabel(amount) {
|
|
113705
|
-
const rounded = Math.round(amount * 100) / 100;
|
|
113706
|
-
return `${rounded} \u5143`;
|
|
113707
|
-
}
|
|
113708
|
-
function displayValue(value) {
|
|
113709
|
-
if (value == null || value === "") return "\uFF08\u7A7A\uFF09";
|
|
113710
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
113711
|
-
const rounded = Math.round(value * 100) / 100;
|
|
113712
|
-
return String(rounded);
|
|
113713
|
-
}
|
|
113714
|
-
if (typeof value === "boolean") return value ? "\u662F" : "\u5426";
|
|
113715
|
-
if (Array.isArray(value)) return value.map((item) => displayValue(item)).join(",");
|
|
113716
|
-
return String(value);
|
|
113717
|
-
}
|
|
113718
|
-
function receiptLine(label2, expected, actual) {
|
|
113719
|
-
return {
|
|
113720
|
-
label: label2,
|
|
113721
|
-
expected: displayValue(expected),
|
|
113722
|
-
actual: actual === void 0 ? UNREAD : displayValue(actual)
|
|
113723
|
-
};
|
|
113724
|
-
}
|
|
113725
|
-
function receiptLinesFromFieldChecks(checks) {
|
|
113726
|
-
return checks.map((check) => {
|
|
113727
|
-
const yuanLabelName = CENT_YUAN_FIELDS[check.field];
|
|
113728
|
-
const label2 = yuanLabelName ?? FIELD_LABELS[check.field] ?? check.field;
|
|
113729
|
-
const unread = check.state === "unread";
|
|
113730
|
-
if (yuanLabelName) {
|
|
113731
|
-
const expectedYuan = centsToYuan(check.expected);
|
|
113732
|
-
const actualYuan = unread ? void 0 : centsToYuan(check.actual);
|
|
113733
|
-
return receiptLine(
|
|
113734
|
-
label2,
|
|
113735
|
-
expectedYuan == null ? check.expected : yuanLabel(expectedYuan),
|
|
113736
|
-
actualYuan == null ? unread ? void 0 : check.actual : yuanLabel(actualYuan)
|
|
113737
|
-
);
|
|
113738
|
-
}
|
|
113739
|
-
return receiptLine(label2, check.expected, unread ? void 0 : check.actual);
|
|
113740
|
-
});
|
|
113741
|
-
}
|
|
113742
|
-
function centsToYuan(value) {
|
|
113743
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
113744
|
-
return value / 100;
|
|
113745
|
-
}
|
|
113746
|
-
function judgeReceipt(lines, readFailed = false) {
|
|
113747
|
-
if (lines.length === 0) return "submitted";
|
|
113748
|
-
if (readFailed || lines.some((line) => line.actual === UNREAD)) return "unknown";
|
|
113749
|
-
if (lines.every((line) => line.expected === line.actual)) return "verified";
|
|
113750
|
-
return "partial";
|
|
113751
|
-
}
|
|
113752
|
-
function formatWriteReceipt(verification, lines) {
|
|
113753
|
-
const body = lines.length ? lines.map((line) => `${line.label}\uFF1A\u671F\u671B ${line.expected}\uFF0C\u8BFB\u56DE ${line.actual}`).join("\n") : verification === "verified" ? "\u5DF2\u6838\u5BF9" : "\u5DF2\u63D0\u4EA4\uFF0C\u5C1A\u672A\u6838\u9A8C";
|
|
113754
|
-
return `\u6838\u5BF9
|
|
113755
|
-
verification=${verification}
|
|
113756
|
-
${body}`;
|
|
113757
|
-
}
|
|
113758
|
-
function printWriteReceipt(verification, lines) {
|
|
113759
|
-
console.log(`
|
|
113760
|
-
${formatWriteReceipt(verification, lines)}
|
|
113761
|
-
`);
|
|
113762
|
-
try {
|
|
113763
|
-
recordWriteReadReceipt(verification, lines);
|
|
113764
|
-
} catch {
|
|
113765
|
-
}
|
|
113766
|
-
}
|
|
113767
|
-
function payloadHasExact(payload, value) {
|
|
113768
|
-
const text5 = JSON.stringify(payload ?? null);
|
|
113769
|
-
if (text5.includes(JSON.stringify(value))) return true;
|
|
113770
|
-
if (/^-?\d+(\.\d+)?$/.test(value)) {
|
|
113771
|
-
const token = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
113772
|
-
return new RegExp(`(?<=[:\\[,]\\s*)${token}(?=[,}\\]])`).test(text5);
|
|
113773
|
-
}
|
|
113774
|
-
return false;
|
|
113775
|
-
}
|
|
113776
|
-
function receiptFromNeedles(needles, payload) {
|
|
113777
|
-
if (payload === void 0) {
|
|
113778
|
-
const lines2 = needles.map((needle) => receiptLine(needle.label, needle.value, void 0));
|
|
113779
|
-
return { verification: "unknown", lines: lines2 };
|
|
113780
|
-
}
|
|
113781
|
-
const lines = needles.map(
|
|
113782
|
-
(needle) => receiptLine(needle.label, needle.value, payloadHasExact(payload, needle.value) ? needle.value : "\u672A\u627E\u5230")
|
|
113783
|
-
);
|
|
113784
|
-
return { verification: judgeReceipt(lines), lines };
|
|
113785
|
-
}
|
|
113786
|
-
function receiptForAbsence(label2, id, payload) {
|
|
113787
|
-
if (payload === void 0) {
|
|
113788
|
-
return {
|
|
113789
|
-
verification: "unknown",
|
|
113790
|
-
lines: [receiptLine(label2, "\u5DF2\u4E0D\u5728", void 0)]
|
|
113791
|
-
};
|
|
113792
|
-
}
|
|
113793
|
-
const stillThere = payloadHasExact(payload, id);
|
|
113794
|
-
const lines = [receiptLine(label2, "\u5DF2\u4E0D\u5728", stillThere ? "\u4ECD\u5728" : "\u5DF2\u4E0D\u5728")];
|
|
113795
|
-
return { verification: stillThere ? "partial" : "verified", lines };
|
|
113796
|
-
}
|
|
113797
|
-
|
|
113798
|
-
// src/commands/account-readback.ts
|
|
113799
|
-
async function fetchAccountsByKeyword(config, media, keyword, verbose) {
|
|
113800
|
-
try {
|
|
113801
|
-
const platform = media ? PLATFORM_CONFIG[media] : void 0;
|
|
113802
|
-
const params = new URLSearchParams();
|
|
113803
|
-
if (platform) {
|
|
113804
|
-
for (const [key, value] of Object.entries(platform.fixedParams)) {
|
|
113805
|
-
params.set(key, String(value));
|
|
113806
|
-
}
|
|
113807
|
-
params.set(platform.pageParam, "1");
|
|
113808
|
-
} else {
|
|
113809
|
-
params.set("pageNo", "1");
|
|
113810
|
-
}
|
|
113811
|
-
params.set("pageSize", "20");
|
|
113812
|
-
applyListAccountsSearchKeyword(params, keyword);
|
|
113813
|
-
const path61 = platform?.path ?? "/query/media-account/";
|
|
113814
|
-
const url = `${config.apiBaseUrl}${path61}?${params}`;
|
|
113815
|
-
if (!platform || platform.responseType === "array") {
|
|
113816
|
-
const res = await apiFetchWithHeaders2(url, config, {}, verbose);
|
|
113817
|
-
return res.data;
|
|
113818
|
-
}
|
|
113819
|
-
return await apiFetch2(url, config, {}, verbose);
|
|
113820
|
-
} catch {
|
|
113821
|
-
return void 0;
|
|
113822
|
-
}
|
|
113823
|
-
}
|
|
113824
|
-
async function printAccountAbsence(config, media, keyword, label2, verbose) {
|
|
113825
|
-
const listed = await fetchAccountsByKeyword(config, media, keyword, verbose);
|
|
113826
|
-
const judged = receiptForAbsence(label2, keyword, listed);
|
|
113827
|
-
printWriteReceipt(judged.verification, judged.lines);
|
|
113828
|
-
}
|
|
113829
|
-
function printApplicationNeedles(needles, payload) {
|
|
113830
|
-
const judged = receiptFromNeedles(needles, payload);
|
|
113831
|
-
printWriteReceipt(judged.verification, judged.lines);
|
|
113832
|
-
}
|
|
113833
|
-
|
|
113834
|
-
// src/commands/report/push.ts
|
|
113835
113633
|
async function runReportPushList(opts) {
|
|
113836
113634
|
assertReportPushMedia(opts.media);
|
|
113837
113635
|
const config = await ensureDataPermission(loadConfig(opts.token));
|
|
@@ -113934,56 +113732,8 @@ async function runReportPushDelete(opts) {
|
|
|
113934
113732
|
`);
|
|
113935
113733
|
process.exit(1);
|
|
113936
113734
|
}
|
|
113937
|
-
let listed;
|
|
113938
|
-
try {
|
|
113939
|
-
const params = new URLSearchParams();
|
|
113940
|
-
params.set("pageIndex", "1");
|
|
113941
|
-
params.set("pageSize", "20");
|
|
113942
|
-
params.set("Name", "");
|
|
113943
|
-
params.set("ReportType", "");
|
|
113944
|
-
params.set("startDate", "");
|
|
113945
|
-
params.set("endDate", "");
|
|
113946
|
-
listed = await apiFetch2(
|
|
113947
|
-
`${config.apiBaseUrl}/query/report-push/settings/${opts.media}?${params}`,
|
|
113948
|
-
config,
|
|
113949
|
-
{},
|
|
113950
|
-
opts.verbose
|
|
113951
|
-
);
|
|
113952
|
-
} catch {
|
|
113953
|
-
listed = void 0;
|
|
113954
|
-
}
|
|
113955
|
-
const gone = receiptForAbsence("\u63A8\u9001\u914D\u7F6E", opts.id, listed);
|
|
113956
|
-
printWriteReceipt(gone.verification, gone.lines);
|
|
113957
113735
|
console.log("\n\u2705 \u63A8\u9001\u5DF2\u5220\u9664\n");
|
|
113958
113736
|
}
|
|
113959
|
-
async function printReportPushReceipt(config, opts) {
|
|
113960
|
-
let listed;
|
|
113961
|
-
try {
|
|
113962
|
-
const params = new URLSearchParams();
|
|
113963
|
-
params.set("pageIndex", "1");
|
|
113964
|
-
params.set("pageSize", "20");
|
|
113965
|
-
params.set("Name", opts.name);
|
|
113966
|
-
params.set("ReportType", "");
|
|
113967
|
-
params.set("startDate", "");
|
|
113968
|
-
params.set("endDate", "");
|
|
113969
|
-
listed = await apiFetch2(
|
|
113970
|
-
`${config.apiBaseUrl}/query/report-push/settings/${opts.media}?${params}`,
|
|
113971
|
-
config,
|
|
113972
|
-
{},
|
|
113973
|
-
opts.verbose
|
|
113974
|
-
);
|
|
113975
|
-
} catch {
|
|
113976
|
-
listed = void 0;
|
|
113977
|
-
}
|
|
113978
|
-
printApplicationNeedles(
|
|
113979
|
-
[
|
|
113980
|
-
{ label: "\u540D\u79F0", value: opts.name },
|
|
113981
|
-
{ label: "\u6536\u4EF6\u4EBA", value: opts.receiveEmails[0] ?? "" },
|
|
113982
|
-
{ label: "\u8D26\u6237", value: opts.mediaAccounts[0] ?? "" }
|
|
113983
|
-
].filter((item) => item.value),
|
|
113984
|
-
listed
|
|
113985
|
-
);
|
|
113986
|
-
}
|
|
113987
113737
|
async function runReportPushCreate(opts) {
|
|
113988
113738
|
assertReportPushMedia(opts.media);
|
|
113989
113739
|
const config = await ensureDataPermission(loadConfig(opts.token));
|
|
@@ -114004,7 +113754,6 @@ async function runReportPushCreate(opts) {
|
|
|
114004
113754
|
`);
|
|
114005
113755
|
process.exit(1);
|
|
114006
113756
|
}
|
|
114007
|
-
await printReportPushReceipt(config, opts);
|
|
114008
113757
|
console.log("\n\u2705 \u63A8\u9001\u914D\u7F6E\u5DF2\u521B\u5EFA\n");
|
|
114009
113758
|
}
|
|
114010
113759
|
async function runReportPushUpdate(opts) {
|
|
@@ -114028,7 +113777,6 @@ async function runReportPushUpdate(opts) {
|
|
|
114028
113777
|
`);
|
|
114029
113778
|
process.exit(1);
|
|
114030
113779
|
}
|
|
114031
|
-
await printReportPushReceipt(config, opts);
|
|
114032
113780
|
console.log("\n\u2705 \u63A8\u9001\u914D\u7F6E\u5DF2\u66F4\u65B0\n");
|
|
114033
113781
|
}
|
|
114034
113782
|
async function runReportPushHistory(opts) {
|
|
@@ -114362,28 +114110,6 @@ async function runTransferCreate(opts) {
|
|
|
114362
114110
|
`);
|
|
114363
114111
|
process.exit(1);
|
|
114364
114112
|
}
|
|
114365
|
-
let listed;
|
|
114366
|
-
try {
|
|
114367
|
-
const params = new URLSearchParams();
|
|
114368
|
-
params.set("pageNumber", "1");
|
|
114369
|
-
params.set("pageSize", "20");
|
|
114370
|
-
listed = await apiFetch2(
|
|
114371
|
-
`${config.apiBaseUrl}/query/accounttransfer/${mediaToPath(opts.media)}/search?${params}`,
|
|
114372
|
-
config,
|
|
114373
|
-
{},
|
|
114374
|
-
opts.verbose
|
|
114375
|
-
);
|
|
114376
|
-
} catch {
|
|
114377
|
-
listed = void 0;
|
|
114378
|
-
}
|
|
114379
|
-
printApplicationNeedles(
|
|
114380
|
-
[
|
|
114381
|
-
{ label: "\u8F6C\u51FA\u8D26\u6237", value: opts.outAccount },
|
|
114382
|
-
{ label: "\u8F6C\u5165\u8D26\u6237", value: opts.inAccount },
|
|
114383
|
-
{ label: "\u7533\u8BF7\u91D1\u989D", value: String(opts.amount) }
|
|
114384
|
-
],
|
|
114385
|
-
listed
|
|
114386
|
-
);
|
|
114387
114113
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
114388
114114
|
section: `transfer-create-${mediaToPath(opts.media)}`,
|
|
114389
114115
|
commandLabel: "transfer create",
|
|
@@ -114862,7 +114588,7 @@ async function runInvoiceApply(opts) {
|
|
|
114862
114588
|
} else {
|
|
114863
114589
|
const cnName = opts.companyName?.trim() ?? "";
|
|
114864
114590
|
const tax = opts.taxId?.trim() ?? "";
|
|
114865
|
-
const
|
|
114591
|
+
const title = opts.title?.trim() ?? "";
|
|
114866
114592
|
const landline = opts.companyPhone?.trim() ?? "";
|
|
114867
114593
|
if (!cnName) {
|
|
114868
114594
|
console.error("\n\u274C VATI/VATSI \u9700\u8981 --company-name\uFF08\u4E2D\u6587\u516C\u53F8\u540D\uFF09\n");
|
|
@@ -114872,7 +114598,7 @@ async function runInvoiceApply(opts) {
|
|
|
114872
114598
|
console.error("\n\u274C VATI/VATSI \u9700\u8981 --tax-id\uFF08\u4F01\u4E1A\u7A0E\u53F7\uFF09\n");
|
|
114873
114599
|
process.exit(1);
|
|
114874
114600
|
}
|
|
114875
|
-
if (!
|
|
114601
|
+
if (!title) {
|
|
114876
114602
|
console.error("\n\u274C VATI/VATSI \u9700\u8981 --title\uFF08\u53D1\u7968\u62AC\u5934\uFF09\n");
|
|
114877
114603
|
process.exit(1);
|
|
114878
114604
|
}
|
|
@@ -114883,7 +114609,7 @@ async function runInvoiceApply(opts) {
|
|
|
114883
114609
|
invoiceInfomation = {
|
|
114884
114610
|
CompanyName: cnName,
|
|
114885
114611
|
TaxIdentificationNumber: tax,
|
|
114886
|
-
Title:
|
|
114612
|
+
Title: title,
|
|
114887
114613
|
Phone: landline
|
|
114888
114614
|
};
|
|
114889
114615
|
}
|
|
@@ -114915,31 +114641,6 @@ async function runInvoiceApply(opts) {
|
|
|
114915
114641
|
`);
|
|
114916
114642
|
process.exit(1);
|
|
114917
114643
|
}
|
|
114918
|
-
const end = /* @__PURE__ */ new Date();
|
|
114919
|
-
const start = /* @__PURE__ */ new Date();
|
|
114920
|
-
start.setMonth(start.getMonth() - 3);
|
|
114921
|
-
const params = new URLSearchParams();
|
|
114922
|
-
params.set("pageIndex", "1");
|
|
114923
|
-
params.set("pageSize", "20");
|
|
114924
|
-
params.set("searchValue", opts.billIds[0] ?? "");
|
|
114925
|
-
params.set("startDate", start.toISOString().slice(0, 10));
|
|
114926
|
-
params.set("endDate", end.toISOString().slice(0, 10));
|
|
114927
|
-
let listed;
|
|
114928
|
-
try {
|
|
114929
|
-
listed = await apiFetch2(`${config.apiBaseUrl}/invoice-request?${params}`, config, {}, opts.verbose);
|
|
114930
|
-
} catch {
|
|
114931
|
-
listed = void 0;
|
|
114932
|
-
}
|
|
114933
|
-
const info = invoiceInfomation;
|
|
114934
|
-
const title = String(info.Title || info.CompanyName || info.CompanyNameEn || "");
|
|
114935
|
-
printApplicationNeedles(
|
|
114936
|
-
[
|
|
114937
|
-
{ label: "\u8BA2\u5355", value: opts.billIds[0] ?? "" },
|
|
114938
|
-
{ label: "\u7968\u79CD", value: opts.invoiceType },
|
|
114939
|
-
...title ? [{ label: "\u62AC\u5934", value: title }] : []
|
|
114940
|
-
],
|
|
114941
|
-
listed
|
|
114942
|
-
);
|
|
114943
114644
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
114944
114645
|
section: "invoice-apply",
|
|
114945
114646
|
commandLabel: "invoice apply",
|
|
@@ -115854,19 +115555,6 @@ async function runForewarningDelete(opts) {
|
|
|
115854
115555
|
`);
|
|
115855
115556
|
process.exit(1);
|
|
115856
115557
|
}
|
|
115857
|
-
let listed;
|
|
115858
|
-
try {
|
|
115859
|
-
listed = await apiFetch2(
|
|
115860
|
-
`${config.apiBaseUrl}/query/smart-strategy/settings/${opts.media}?PageIndex=1&PageSize=20`,
|
|
115861
|
-
config,
|
|
115862
|
-
{},
|
|
115863
|
-
opts.verbose
|
|
115864
|
-
);
|
|
115865
|
-
} catch {
|
|
115866
|
-
listed = void 0;
|
|
115867
|
-
}
|
|
115868
|
-
const gone = receiptForAbsence("\u9884\u8B66\u89C4\u5219", opts.id, listed);
|
|
115869
|
-
printWriteReceipt(gone.verification, gone.lines);
|
|
115870
115558
|
console.log("\n\u2705 \u9884\u8B66\u89C4\u5219\u5DF2\u5220\u9664\n");
|
|
115871
115559
|
}
|
|
115872
115560
|
async function runForewarningGet(opts) {
|
|
@@ -116054,21 +115742,6 @@ async function runForewarningCreate(opts) {
|
|
|
116054
115742
|
`);
|
|
116055
115743
|
process.exit(1);
|
|
116056
115744
|
}
|
|
116057
|
-
let listed;
|
|
116058
|
-
try {
|
|
116059
|
-
const url2 = opts.id ? `${config.apiBaseUrl}/query/smart-strategy/settings/${opts.media}/${opts.id}` : `${config.apiBaseUrl}/query/smart-strategy/settings/${opts.media}?PageIndex=1&PageSize=20&Name=${encodeURIComponent(opts.name)}`;
|
|
116060
|
-
listed = await apiFetch2(url2, config, {}, opts.verbose);
|
|
116061
|
-
} catch {
|
|
116062
|
-
listed = void 0;
|
|
116063
|
-
}
|
|
116064
|
-
printApplicationNeedles(
|
|
116065
|
-
[
|
|
116066
|
-
{ label: "\u540D\u79F0", value: opts.name },
|
|
116067
|
-
{ label: "\u5B57\u6BB5", value: opts.field },
|
|
116068
|
-
{ label: "\u9608\u503C", value: String(opts.value) }
|
|
116069
|
-
],
|
|
116070
|
-
listed
|
|
116071
|
-
);
|
|
116072
115745
|
console.log(`
|
|
116073
115746
|
\u2705 \u9884\u8B66\u89C4\u5219\u5DF2${isUpdate ? "\u66F4\u65B0" : "\u521B\u5EFA"}\uFF1A${opts.name}
|
|
116074
115747
|
`);
|
|
@@ -117031,8 +116704,17 @@ function campaignEditPatchPairs(input) {
|
|
|
117031
116704
|
if (input.negativeGeoTargetType !== void 0) {
|
|
117032
116705
|
pairs.push(["negativeGeoTargetType", input.negativeGeoTargetType]);
|
|
117033
116706
|
}
|
|
116707
|
+
if (input.audienceTargeting !== void 0) {
|
|
116708
|
+
pairs.push(["audienceTargeting", input.audienceTargeting]);
|
|
116709
|
+
}
|
|
117034
116710
|
return pairs;
|
|
117035
116711
|
}
|
|
116712
|
+
function parseAudienceTargeting(raw) {
|
|
116713
|
+
const text5 = raw.trim().replace(/[_-]/g, "").toLowerCase();
|
|
116714
|
+
if (text5 === "observation") return "Observation";
|
|
116715
|
+
if (text5 === "targeting") return "Targeting";
|
|
116716
|
+
return void 0;
|
|
116717
|
+
}
|
|
117036
116718
|
function campaignStatusPatchPairs(status) {
|
|
117037
116719
|
return [["status", status]];
|
|
117038
116720
|
}
|
|
@@ -117275,18 +116957,6 @@ function summarizeNegativeKeywordCreate(requested, response, listItems) {
|
|
|
117275
116957
|
}
|
|
117276
116958
|
|
|
117277
116959
|
// src/commands/ad/keyword.ts
|
|
117278
|
-
async function printIdGone(label2, listUrl, config, id, verbose) {
|
|
117279
|
-
try {
|
|
117280
|
-
await findItemInList(listUrl, config, id, verbose);
|
|
117281
|
-
printWriteReceipt("partial", [receiptLine(label2, "\u5DF2\u5220\u9664", "\u4ECD\u5728")]);
|
|
117282
|
-
} catch (err) {
|
|
117283
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
117284
|
-
const gone = message.includes("\u672A\u5728\u5217\u8868\u4E2D\u627E\u5230");
|
|
117285
|
-
printWriteReceipt(gone ? "verified" : "unknown", [
|
|
117286
|
-
receiptLine(label2, "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : void 0)
|
|
117287
|
-
]);
|
|
117288
|
-
}
|
|
117289
|
-
}
|
|
117290
116960
|
function unwrapKeywordDisplayTextForEdit(raw) {
|
|
117291
116961
|
const t = raw.trim();
|
|
117292
116962
|
if (t.length >= 2 && t.startsWith('"') && t.endsWith('"')) {
|
|
@@ -117602,37 +117272,6 @@ async function runAdKeywordCreate(opts) {
|
|
|
117602
117272
|
`);
|
|
117603
117273
|
process.exit(1);
|
|
117604
117274
|
}
|
|
117605
|
-
const listParams = new URLSearchParams();
|
|
117606
|
-
listParams.set("startDate", toGoogleDate(void 0, -30));
|
|
117607
|
-
listParams.set("endDate", toGoogleDate(void 0, 0));
|
|
117608
|
-
listParams.set("newest", "true");
|
|
117609
|
-
let listItems = null;
|
|
117610
|
-
try {
|
|
117611
|
-
const listed = await apiFetch2(
|
|
117612
|
-
`${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${listParams}`,
|
|
117613
|
-
config,
|
|
117614
|
-
{},
|
|
117615
|
-
opts.verbose
|
|
117616
|
-
);
|
|
117617
|
-
listItems = listed.data ?? [];
|
|
117618
|
-
} catch {
|
|
117619
|
-
listItems = null;
|
|
117620
|
-
}
|
|
117621
|
-
const summary = summarizeNegativeKeywordCreate(keywords, response, listItems);
|
|
117622
|
-
const matched = new Set(summary.matched.map((item) => item.text));
|
|
117623
|
-
const lines = keywords.map(
|
|
117624
|
-
(text5) => receiptLine("\u5173\u952E\u8BCD", text5, listItems == null ? void 0 : matched.has(text5) ? text5 : "\u672A\u627E\u5230")
|
|
117625
|
-
);
|
|
117626
|
-
if (opts.finalUrl) {
|
|
117627
|
-
const hit = listItems?.find((item) => {
|
|
117628
|
-
const cores = [item["finalURL"], item["finalUrl"], item["FinalUrl"]].map(
|
|
117629
|
-
(value) => value == null ? "" : String(value)
|
|
117630
|
-
);
|
|
117631
|
-
return cores.includes(opts.finalUrl);
|
|
117632
|
-
});
|
|
117633
|
-
lines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, listItems == null ? void 0 : hit ? opts.finalUrl : "\u672A\u627E\u5230"));
|
|
117634
|
-
}
|
|
117635
|
-
printWriteReceipt(listItems == null ? "unknown" : judgeReceipt(lines), lines);
|
|
117636
117275
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
117637
117276
|
section: `ad-keyword-create-${opts.account}-${opts.adgroupId}`,
|
|
117638
117277
|
commandLabel: "ad keyword-create",
|
|
@@ -117723,7 +117362,7 @@ async function runAdNegativeKeywordCreate(opts) {
|
|
|
117723
117362
|
`);
|
|
117724
117363
|
process.exit(1);
|
|
117725
117364
|
}
|
|
117726
|
-
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account
|
|
117365
|
+
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account);
|
|
117727
117366
|
const readList = async () => {
|
|
117728
117367
|
try {
|
|
117729
117368
|
const listed = await apiFetch2(
|
|
@@ -117747,13 +117386,6 @@ async function runAdNegativeKeywordCreate(opts) {
|
|
|
117747
117386
|
const nextQuery = `siluzan-tso ad keywords -a ${opts.account} --negative --json-out ./snap`;
|
|
117748
117387
|
const detail = summary.verification === "verified" ? `\u5DF2\u6838\u9A8C\u6DFB\u52A0 ${summary.matchedCount} \u4E2A\u5426\u5B9A\u5173\u952E\u8BCD\uFF08${negativeKeywordLevelLabel[level]}\uFF09` : `\u8BF7\u6C42 ${keywords.length} \u4E2A\uFF0C\u5BF9\u4E0A ${summary.matchedCount} \u4E2A${summary.pending.length ? `\uFF0C\u5C1A\u672A\u6838\u9A8C\uFF1A${summary.pending.join("\u3001")}` : ""}`;
|
|
117749
117388
|
const headline = writeVerificationHeadline(summary.verification, detail);
|
|
117750
|
-
const matchedTexts = new Set(summary.matched.map((item) => item.text));
|
|
117751
|
-
printWriteReceipt(
|
|
117752
|
-
summary.verification,
|
|
117753
|
-
keywords.map(
|
|
117754
|
-
(text5) => receiptLine("\u5426\u5B9A\u5173\u952E\u8BCD", text5, listItems == null ? void 0 : matchedTexts.has(text5) ? text5 : "\u672A\u627E\u5230")
|
|
117755
|
-
)
|
|
117756
|
-
);
|
|
117757
117389
|
if (summary.verification !== "verified") {
|
|
117758
117390
|
console.error(`
|
|
117759
117391
|
${headline}
|
|
@@ -117801,17 +117433,6 @@ async function runAdKeywordDelete(opts) {
|
|
|
117801
117433
|
`);
|
|
117802
117434
|
process.exit(1);
|
|
117803
117435
|
}
|
|
117804
|
-
const goneParams = new URLSearchParams();
|
|
117805
|
-
goneParams.set("startDate", toGoogleDate(void 0, -30));
|
|
117806
|
-
goneParams.set("endDate", toGoogleDate(void 0, 0));
|
|
117807
|
-
goneParams.set("newest", "true");
|
|
117808
|
-
await printIdGone(
|
|
117809
|
-
"\u5173\u952E\u8BCD",
|
|
117810
|
-
`${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${goneParams}`,
|
|
117811
|
-
config,
|
|
117812
|
-
opts.id,
|
|
117813
|
-
opts.verbose
|
|
117814
|
-
);
|
|
117815
117436
|
console.log(`
|
|
117816
117437
|
\u2705 \u5173\u952E\u8BCD ${opts.id} \u5DF2\u5220\u9664
|
|
117817
117438
|
`);
|
|
@@ -117828,7 +117449,7 @@ function findKeywordEditMismatches(requested, returned, changed) {
|
|
|
117828
117449
|
const expectedCents = Number(requested["maxCPC"]);
|
|
117829
117450
|
const actualCents = returned["maxCPC"];
|
|
117830
117451
|
mismatches.push(
|
|
117831
|
-
`maxCPC\uFF1A\u671F\u671B ${expectedCents / 100} \u5143\uFF0C\u5217\u8868\u4ECD\u662F ${actualCents / 100} \u5143\u3002\
|
|
117452
|
+
`maxCPC\uFF1A\u671F\u671B ${expectedCents / 100} \u5143\uFF0C\u5217\u8868\u4ECD\u662F ${actualCents / 100} \u5143\u3002\u5173\u952E\u8BCD\u5217\u8868\u6309\u8D26\u6237\u548C\u65E5\u671F\u7F13\u5B58\u7EA6 60 \u79D2\uFF0C\u4E14\u6CA1\u6709 --fresh\uFF0C\u8FD9\u6B21\u56DE\u8BFB\u53EF\u80FD\u4ECD\u662F\u5199\u5165\u524D\u7684\u503C\u3002\u4E0D\u8981\u7ACB\u523B\u91CD\u8DD1 keyword-edit\uFF0C\u4E5F\u4E0D\u8981\u5220\u8BCD\u91CD\u5EFA\u3002\u7EA6 60 \u79D2\u540E\u7528 ad keywords --json-out \u770B\u8BE5 id \u7684 maxCPCYuan\uFF0C\u5DF2\u7ECF\u662F\u76EE\u6807\u503C\u5C31\u5F53\u6210\u529F\u3002`
|
|
117832
117453
|
);
|
|
117833
117454
|
}
|
|
117834
117455
|
if (changed.status !== void 0 && typeof returned["userStatusV2"] === "string" && str3(returned["userStatusV2"]).toLowerCase() !== changed.status.toLowerCase()) {
|
|
@@ -117856,7 +117477,6 @@ async function runAdKeywordEdit(opts) {
|
|
|
117856
117477
|
const params = new URLSearchParams();
|
|
117857
117478
|
params.set("startDate", toGoogleDate(opts.startDate, -30));
|
|
117858
117479
|
params.set("endDate", toGoogleDate(opts.endDate, 0));
|
|
117859
|
-
params.set("newest", "true");
|
|
117860
117480
|
const listUrl = `${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${params}`;
|
|
117861
117481
|
const notAppliedHint = ` \u8BF7\u52FF\u6539\u7528\u300C\u5220\u9664\u540E\u91CD\u5EFA\u300D\u7ED5\u8FC7\uFF08\u4F1A\u4E22\u5931\u5173\u952E\u8BCD id \u4E0E\u5386\u53F2\u6570\u636E\uFF09\uFF0C\u8BF7\u53CD\u9988\u5E73\u53F0\u6392\u67E5\u3002
|
|
117862
117482
|
`;
|
|
@@ -117952,19 +117572,6 @@ async function runAdKeywordEdit(opts) {
|
|
|
117952
117572
|
process.exit(1);
|
|
117953
117573
|
}
|
|
117954
117574
|
const mismatches = findKeywordEditMismatches(readbackExpected, fresh, opts);
|
|
117955
|
-
const editLines = [];
|
|
117956
|
-
if (opts.finalUrl !== void 0) {
|
|
117957
|
-
editLines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, fresh["finalURL"] ?? fresh["FinalUrl"]));
|
|
117958
|
-
}
|
|
117959
|
-
if (opts.maxCpc !== void 0) {
|
|
117960
|
-
const cents = fresh["maxCPC"] ?? fresh["maxCpc"];
|
|
117961
|
-
const yuan = typeof cents === "number" ? cents / 100 : void 0;
|
|
117962
|
-
editLines.push(receiptLine("CPC\u4E0A\u9650", yuanLabel(opts.maxCpc), yuan == null ? void 0 : yuanLabel(yuan)));
|
|
117963
|
-
}
|
|
117964
|
-
if (opts.status !== void 0) {
|
|
117965
|
-
editLines.push(receiptLine("\u72B6\u6001", opts.status, fresh["userStatusV2"] ?? fresh["status"]));
|
|
117966
|
-
}
|
|
117967
|
-
printWriteReceipt(mismatches.length > 0 ? "partial" : judgeReceipt(editLines), editLines);
|
|
117968
117575
|
if (mismatches.length > 0) {
|
|
117969
117576
|
console.error(
|
|
117970
117577
|
`
|
|
@@ -118082,7 +117689,7 @@ async function runAdNegativeKeywordDelete(opts) {
|
|
|
118082
117689
|
opts = withResolvedAdAccount(opts);
|
|
118083
117690
|
const config = loadConfig(opts.token);
|
|
118084
117691
|
const googleApiUrl = requireGoogleApi(config);
|
|
118085
|
-
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account
|
|
117692
|
+
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account);
|
|
118086
117693
|
let keyword;
|
|
118087
117694
|
try {
|
|
118088
117695
|
keyword = await findItemInList(listUrl, config, opts.id, opts.verbose);
|
|
@@ -118104,7 +117711,6 @@ async function runAdNegativeKeywordDelete(opts) {
|
|
|
118104
117711
|
`);
|
|
118105
117712
|
process.exit(1);
|
|
118106
117713
|
}
|
|
118107
|
-
await printIdGone("\u5426\u5B9A\u5173\u952E\u8BCD", listUrl, config, opts.id, opts.verbose);
|
|
118108
117714
|
console.log(`
|
|
118109
117715
|
\u2705 \u5426\u5B9A\u5173\u952E\u8BCD ${opts.id} \u5DF2\u5220\u9664
|
|
118110
117716
|
`);
|
|
@@ -119800,13 +119406,9 @@ function unwrapCampaign(res) {
|
|
|
119800
119406
|
}
|
|
119801
119407
|
return res;
|
|
119802
119408
|
}
|
|
119803
|
-
function campaignReadUrl(detailUrl) {
|
|
119804
|
-
if (/[?&]newest=/.test(detailUrl)) return detailUrl;
|
|
119805
|
-
return `${detailUrl}${detailUrl.includes("?") ? "&" : "?"}newest=true`;
|
|
119806
|
-
}
|
|
119807
119409
|
async function fetchCampaignRecord(detailUrl, config, verbose) {
|
|
119808
119410
|
const res = await apiFetch2(
|
|
119809
|
-
|
|
119411
|
+
detailUrl,
|
|
119810
119412
|
config,
|
|
119811
119413
|
{},
|
|
119812
119414
|
verbose
|
|
@@ -119863,7 +119465,6 @@ async function reportFailedCampaignPut(opts) {
|
|
|
119863
119465
|
});
|
|
119864
119466
|
}
|
|
119865
119467
|
async function reportCampaignWrite(opts) {
|
|
119866
|
-
printWriteReceipt(opts.verification, receiptLinesFromFieldChecks(opts.checks));
|
|
119867
119468
|
const nextQuery = `siluzan-tso ad campaigns -a ${opts.account} --json-out ./snap`;
|
|
119868
119469
|
const unmatched = describeUnmatchedChecks(opts.checks);
|
|
119869
119470
|
const text5 = opts.verification === "verified" ? opts.detail : unmatched || opts.detail;
|
|
@@ -119909,7 +119510,7 @@ async function runAdCampaignStatus(opts) {
|
|
|
119909
119510
|
let campaign;
|
|
119910
119511
|
try {
|
|
119911
119512
|
const res = await apiFetch2(
|
|
119912
|
-
|
|
119513
|
+
detailUrl,
|
|
119913
119514
|
config,
|
|
119914
119515
|
{},
|
|
119915
119516
|
opts.verbose
|
|
@@ -119976,7 +119577,7 @@ async function runAdCampaignDelete(opts) {
|
|
|
119976
119577
|
let campaign;
|
|
119977
119578
|
try {
|
|
119978
119579
|
const res = await apiFetch2(
|
|
119979
|
-
|
|
119580
|
+
detailUrl,
|
|
119980
119581
|
config,
|
|
119981
119582
|
{},
|
|
119982
119583
|
opts.verbose
|
|
@@ -120011,32 +119612,9 @@ async function runAdCampaignDelete(opts) {
|
|
|
120011
119612
|
`);
|
|
120012
119613
|
process.exit(1);
|
|
120013
119614
|
}
|
|
120014
|
-
|
|
120015
|
-
let stillStatus;
|
|
120016
|
-
try {
|
|
120017
|
-
const again = await apiFetch2(
|
|
120018
|
-
campaignReadUrl(detailUrl),
|
|
120019
|
-
config,
|
|
120020
|
-
{},
|
|
120021
|
-
opts.verbose
|
|
120022
|
-
);
|
|
120023
|
-
const row = again.data ?? again;
|
|
120024
|
-
const status = String(row["statusV2"] ?? row["status"] ?? "");
|
|
120025
|
-
removed = /removed/i.test(status);
|
|
120026
|
-
if (!removed) stillStatus = status || "\u4ECD\u5728";
|
|
120027
|
-
} catch (err) {
|
|
120028
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
120029
|
-
removed = /404|未找到|not found|不存在/i.test(message);
|
|
120030
|
-
}
|
|
120031
|
-
const verification = removed ? "verified" : stillStatus ? "partial" : "unknown";
|
|
120032
|
-
printWriteReceipt(verification, [
|
|
120033
|
-
receiptLine("\u7CFB\u5217", "\u5DF2\u5220\u9664", removed ? "\u5DF2\u5220\u9664" : stillStatus)
|
|
120034
|
-
]);
|
|
120035
|
-
if (verification === "verified") {
|
|
120036
|
-
console.log(`
|
|
119615
|
+
console.log(`
|
|
120037
119616
|
\u2705 \u5E7F\u544A\u7CFB\u5217 ${opts.id} \u5DF2\u5220\u9664
|
|
120038
119617
|
`);
|
|
120039
|
-
}
|
|
120040
119618
|
}
|
|
120041
119619
|
async function runAdCampaignCreate(opts) {
|
|
120042
119620
|
const cfg = loadCampaignCreateConfig(opts.configFile);
|
|
@@ -120232,8 +119810,22 @@ async function runAdCampaignBiddingStrategies(opts) {
|
|
|
120232
119810
|
`
|
|
120233
119811
|
);
|
|
120234
119812
|
}
|
|
119813
|
+
function parseCampaignAudienceTargeting(raw) {
|
|
119814
|
+
if (raw === void 0) return void 0;
|
|
119815
|
+
const parsed = parseAudienceTargeting(raw);
|
|
119816
|
+
if (!parsed) {
|
|
119817
|
+
console.error("\n\u274C --audience-targeting \u65E0\u6548\uFF0C\u5408\u6CD5\u503C\uFF1AObservation | Targeting\n");
|
|
119818
|
+
process.exit(1);
|
|
119819
|
+
}
|
|
119820
|
+
return parsed;
|
|
119821
|
+
}
|
|
119822
|
+
function isSearchChannel(channel) {
|
|
119823
|
+
const text5 = String(channel ?? "").trim();
|
|
119824
|
+
if (!text5) return true;
|
|
119825
|
+
return text5.replace(/[_-]/g, "").toUpperCase() === "SEARCH";
|
|
119826
|
+
}
|
|
120235
119827
|
function parseCampaignEditGeoTargetTypes(opts) {
|
|
120236
|
-
const
|
|
119828
|
+
const fail10 = (flag, value, allowed) => {
|
|
120237
119829
|
console.error(`
|
|
120238
119830
|
\u274C ${flag} \u65E0\u6548\uFF08${value}\uFF09\uFF0C\u5408\u6CD5\u503C\uFF1A${allowed}
|
|
120239
119831
|
`);
|
|
@@ -120244,13 +119836,13 @@ function parseCampaignEditGeoTargetTypes(opts) {
|
|
|
120244
119836
|
if (opts.geoTargetType !== void 0) {
|
|
120245
119837
|
positive = parsePositiveGeoTargetType(opts.geoTargetType) ?? void 0;
|
|
120246
119838
|
if (!positive) {
|
|
120247
|
-
|
|
119839
|
+
fail10("--geo-target-type", opts.geoTargetType, Object.keys(GEO_TARGET_TYPE_CLI_VALUES).join(" | "));
|
|
120248
119840
|
}
|
|
120249
119841
|
}
|
|
120250
119842
|
if (opts.negativeGeoTargetType !== void 0) {
|
|
120251
119843
|
negative = parseNegativeGeoTargetType(opts.negativeGeoTargetType) ?? void 0;
|
|
120252
119844
|
if (!negative) {
|
|
120253
|
-
|
|
119845
|
+
fail10("--negative-geo-target-type", opts.negativeGeoTargetType, "presence | presence-or-interest");
|
|
120254
119846
|
}
|
|
120255
119847
|
}
|
|
120256
119848
|
return { positive, negative };
|
|
@@ -120285,13 +119877,14 @@ async function runAdCampaignEdit(opts) {
|
|
|
120285
119877
|
opts = withResolvedAdAccount(opts);
|
|
120286
119878
|
validateCampaignEditBidding(opts);
|
|
120287
119879
|
const geoTargetTypes = parseCampaignEditGeoTargetTypes(opts);
|
|
119880
|
+
const audienceTargeting = parseCampaignAudienceTargeting(opts.audienceTargeting);
|
|
120288
119881
|
const config = loadConfig(opts.token);
|
|
120289
119882
|
const googleApiUrl = requireGoogleApi(config);
|
|
120290
119883
|
const detailUrl = `${googleApiUrl}/campaignmanagement/campaign/${opts.account}/${opts.id}`;
|
|
120291
119884
|
let campaign;
|
|
120292
119885
|
try {
|
|
120293
119886
|
const res = await apiFetch2(
|
|
120294
|
-
|
|
119887
|
+
detailUrl,
|
|
120295
119888
|
config,
|
|
120296
119889
|
{},
|
|
120297
119890
|
opts.verbose
|
|
@@ -120316,10 +119909,20 @@ async function runAdCampaignEdit(opts) {
|
|
|
120316
119909
|
targetSearchNetwork: opts.targetSearchNetwork,
|
|
120317
119910
|
targetContentNetwork: opts.targetContentNetwork,
|
|
120318
119911
|
positiveGeoTargetType: geoTargetTypes.positive,
|
|
120319
|
-
negativeGeoTargetType: geoTargetTypes.negative
|
|
119912
|
+
negativeGeoTargetType: geoTargetTypes.negative,
|
|
119913
|
+
audienceTargeting
|
|
120320
119914
|
});
|
|
120321
119915
|
if (patchPairs.length === 0) {
|
|
120322
|
-
console.error("\n\u274C \u8BF7\u81F3\u5C11\u6307\u5B9A\u4E00\u4E2A\u4FEE\u6539\u9879\uFF08--name / --budget / --bidding / --geo-target-type / \u2026\uFF09\n");
|
|
119916
|
+
console.error("\n\u274C \u8BF7\u81F3\u5C11\u6307\u5B9A\u4E00\u4E2A\u4FEE\u6539\u9879\uFF08--name / --budget / --bidding / --geo-target-type / --audience-targeting / \u2026\uFF09\n");
|
|
119917
|
+
process.exit(1);
|
|
119918
|
+
}
|
|
119919
|
+
if (audienceTargeting && !isSearchChannel(campaign.channelTypeV2 ?? campaign.ChannelTypeV2)) {
|
|
119920
|
+
const channel = String(campaign.channelTypeV2 ?? campaign.ChannelTypeV2 ?? "");
|
|
119921
|
+
console.error(
|
|
119922
|
+
`
|
|
119923
|
+
\u274C --audience-targeting \u53EA\u7528\u4E8E\u641C\u7D22\u7CFB\u5217\u3002\u5F53\u524D\u6E20\u9053\u662F ${channel || "\u672A\u77E5"}\u3002
|
|
119924
|
+
`
|
|
119925
|
+
);
|
|
120323
119926
|
process.exit(1);
|
|
120324
119927
|
}
|
|
120325
119928
|
if (opts.budget !== void 0 && readBudgetSharedFlag(campaign) === true) {
|
|
@@ -120368,6 +119971,9 @@ async function runAdCampaignEdit(opts) {
|
|
|
120368
119971
|
parts.push(`\u4F4D\u7F6E\u9009\u9879\u2192${GEO_TARGET_TYPE_LABEL[geoTargetTypes.positive]}`);
|
|
120369
119972
|
}
|
|
120370
119973
|
if (geoTargetTypes.negative) parts.push(`\u6392\u9664\u4F4D\u7F6E\u9009\u9879\u2192${geoTargetTypes.negative}`);
|
|
119974
|
+
if (audienceTargeting) {
|
|
119975
|
+
parts.push(`\u53D7\u4F17\u2192${audienceTargeting === "Observation" ? "\u89C2\u5BDF" : "\u5B9A\u5411"}`);
|
|
119976
|
+
}
|
|
120371
119977
|
const judged = await verifyCampaignAfterPut(
|
|
120372
119978
|
detailUrl,
|
|
120373
119979
|
config,
|
|
@@ -120914,7 +120520,6 @@ async function runAdDelete(opts) {
|
|
|
120914
120520
|
const params = new URLSearchParams();
|
|
120915
120521
|
params.set("startDate", toGoogleDate(opts.startDate, -30));
|
|
120916
120522
|
params.set("endDate", toGoogleDate(opts.endDate, 0));
|
|
120917
|
-
params.set("newest", "true");
|
|
120918
120523
|
const listUrl = `${googleApiUrl}/admanagement/v2/list/${opts.account}?${params}`;
|
|
120919
120524
|
let ad;
|
|
120920
120525
|
try {
|
|
@@ -120934,18 +120539,6 @@ async function runAdDelete(opts) {
|
|
|
120934
120539
|
`);
|
|
120935
120540
|
process.exit(1);
|
|
120936
120541
|
}
|
|
120937
|
-
let gone = false;
|
|
120938
|
-
let still = false;
|
|
120939
|
-
try {
|
|
120940
|
-
await findItemInList(listUrl, config, opts.id, opts.verbose);
|
|
120941
|
-
still = true;
|
|
120942
|
-
} catch (err) {
|
|
120943
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
120944
|
-
gone = message.includes("\u672A\u5728\u5217\u8868\u4E2D\u627E\u5230");
|
|
120945
|
-
}
|
|
120946
|
-
printWriteReceipt(gone ? "verified" : still ? "partial" : "unknown", [
|
|
120947
|
-
receiptLine("\u5E7F\u544A", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : still ? "\u4ECD\u5728" : void 0)
|
|
120948
|
-
]);
|
|
120949
120542
|
console.log(`
|
|
120950
120543
|
\u2705 \u5E7F\u544A ${opts.id} \u5DF2\u5220\u9664
|
|
120951
120544
|
`);
|
|
@@ -120995,31 +120588,6 @@ async function runAdEdit(opts) {
|
|
|
120995
120588
|
`);
|
|
120996
120589
|
process.exit(1);
|
|
120997
120590
|
}
|
|
120998
|
-
const readParams = new URLSearchParams();
|
|
120999
|
-
readParams.set("startDate", toGoogleDate(void 0, -30));
|
|
121000
|
-
readParams.set("endDate", toGoogleDate(void 0, 0));
|
|
121001
|
-
readParams.set("newest", "true");
|
|
121002
|
-
let fresh;
|
|
121003
|
-
try {
|
|
121004
|
-
fresh = await findItemInList(
|
|
121005
|
-
`${googleApiUrl}/admanagement/v2/list/${opts.account}?${readParams}`,
|
|
121006
|
-
config,
|
|
121007
|
-
opts.id,
|
|
121008
|
-
opts.verbose
|
|
121009
|
-
);
|
|
121010
|
-
} catch {
|
|
121011
|
-
fresh = void 0;
|
|
121012
|
-
}
|
|
121013
|
-
const lines = [];
|
|
121014
|
-
if (opts.finalUrl !== void 0) {
|
|
121015
|
-
lines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, fresh?.["finalUrl"] ?? fresh?.["Finalurl"] ?? fresh?.["FinalUrl"]));
|
|
121016
|
-
}
|
|
121017
|
-
if (opts.status !== void 0) {
|
|
121018
|
-
lines.push(receiptLine("\u72B6\u6001", opts.status, fresh?.["status"] ?? fresh?.["statusV2"]));
|
|
121019
|
-
}
|
|
121020
|
-
if (lines.length > 0) {
|
|
121021
|
-
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
121022
|
-
}
|
|
121023
120591
|
console.log(`
|
|
121024
120592
|
\u2705 \u5E7F\u544A ${opts.id} \u5DF2\u66F4\u65B0
|
|
121025
120593
|
`);
|
|
@@ -121036,7 +120604,8 @@ var EXCLUSION_TYPES = [
|
|
|
121036
120604
|
"youtube-channel",
|
|
121037
120605
|
"youtube-video",
|
|
121038
120606
|
"app",
|
|
121039
|
-
"app-category"
|
|
120607
|
+
"app-category",
|
|
120608
|
+
"user-list"
|
|
121040
120609
|
];
|
|
121041
120610
|
var RESERVED_PLACEMENT_SUFFIXES = [".invalid", ".example", ".test", ".localhost"];
|
|
121042
120611
|
function normalizePlacementUrl(raw) {
|
|
@@ -121074,7 +120643,7 @@ function buildExclusionCreateBody(input) {
|
|
|
121074
120643
|
const type = input.type.trim().toLowerCase();
|
|
121075
120644
|
if (!EXCLUSION_TYPES.includes(type)) {
|
|
121076
120645
|
throw new Error(
|
|
121077
|
-
"type \u987B\u4E3A content-label | placement | youtube-channel | youtube-video | app | app-category"
|
|
120646
|
+
"type \u987B\u4E3A content-label | placement | youtube-channel | youtube-video | app | app-category | user-list"
|
|
121078
120647
|
);
|
|
121079
120648
|
}
|
|
121080
120649
|
const filled = [
|
|
@@ -121083,10 +120652,11 @@ function buildExclusionCreateBody(input) {
|
|
|
121083
120652
|
input.channelId,
|
|
121084
120653
|
input.videoId,
|
|
121085
120654
|
input.appId,
|
|
121086
|
-
input.appCategoryId
|
|
120655
|
+
input.appCategoryId,
|
|
120656
|
+
input.userListId
|
|
121087
120657
|
].filter((value) => value != null && String(value).trim() !== "");
|
|
121088
120658
|
if (filled.length !== 1) {
|
|
121089
|
-
throw new Error("\u4E00\u6B21\u53EA\u586B\u4E00\u79CD\u503C\uFF1A\u5185\u5BB9\u6807\u7B7E\u3001\u7F51\u5740\u3001\u9891\u9053\u3001\u89C6\u9891\u3001\u5E94\u7528\
|
|
120659
|
+
throw new Error("\u4E00\u6B21\u53EA\u586B\u4E00\u79CD\u503C\uFF1A\u5185\u5BB9\u6807\u7B7E\u3001\u7F51\u5740\u3001\u9891\u9053\u3001\u89C6\u9891\u3001\u5E94\u7528\u3001\u5E94\u7528\u7C7B\u522B\u6216\u7528\u6237\u5217\u8868 id");
|
|
121090
120660
|
}
|
|
121091
120661
|
if (type === "content-label") {
|
|
121092
120662
|
const contentLabel = input.contentLabel?.trim() ?? "";
|
|
@@ -121113,11 +120683,18 @@ function buildExclusionCreateBody(input) {
|
|
|
121113
120683
|
}
|
|
121114
120684
|
return { type, appId };
|
|
121115
120685
|
}
|
|
121116
|
-
|
|
121117
|
-
|
|
121118
|
-
|
|
120686
|
+
if (type === "app-category") {
|
|
120687
|
+
const appCategoryId = input.appCategoryId?.trim() ?? "";
|
|
120688
|
+
if (!/^\d+$/.test(appCategoryId)) {
|
|
120689
|
+
throw new Error("app-category \u9700\u8981 app-categories \u8FD4\u56DE\u7684\u6570\u5B57 --app-category-id");
|
|
120690
|
+
}
|
|
120691
|
+
return { type, appCategoryId };
|
|
120692
|
+
}
|
|
120693
|
+
const userListId = input.userListId?.trim() ?? "";
|
|
120694
|
+
if (!/^\d+$/.test(userListId)) {
|
|
120695
|
+
throw new Error("user-list \u9700\u8981\u5DF2\u6709\u7528\u6237\u5217\u8868\u7684\u6570\u5B57 --user-list-id\u3002\u4E0A\u4F20\u540D\u5355\u8D70 Customer Match\uFF0C\u4E0D\u5728\u8FD9\u91CC\u505A\u3002");
|
|
121119
120696
|
}
|
|
121120
|
-
return { type,
|
|
120697
|
+
return { type, userListId };
|
|
121121
120698
|
}
|
|
121122
120699
|
function exclusionsUrl(googleApiUrl, accountId) {
|
|
121123
120700
|
return `${googleApiUrl}/campaignmanagement/accounts/${accountId}/exclusions`;
|
|
@@ -121209,15 +120786,6 @@ async function runAdExclusionsAdd(opts) {
|
|
|
121209
120786
|
process.exit(1);
|
|
121210
120787
|
}
|
|
121211
120788
|
const payload = { account: opts.account, request: body, response: created };
|
|
121212
|
-
let listed;
|
|
121213
|
-
try {
|
|
121214
|
-
listed = await apiFetch2(url, config, {}, opts.verbose);
|
|
121215
|
-
} catch {
|
|
121216
|
-
listed = void 0;
|
|
121217
|
-
}
|
|
121218
|
-
const needle = Object.values(body).map(String).find((value) => value && value !== body.type) ?? body.type;
|
|
121219
|
-
const added = receiptFromNeedles([{ label: "\u6392\u9664", value: needle }], listed);
|
|
121220
|
-
printWriteReceipt(added.verification, added.lines);
|
|
121221
120789
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
121222
120790
|
section: "ad-exclusions-add",
|
|
121223
120791
|
commandLabel: "ad exclusions add",
|
|
@@ -121248,14 +120816,6 @@ async function runAdExclusionsRemove(opts) {
|
|
|
121248
120816
|
`);
|
|
121249
120817
|
process.exit(1);
|
|
121250
120818
|
}
|
|
121251
|
-
let listed;
|
|
121252
|
-
try {
|
|
121253
|
-
listed = await apiFetch2(exclusionsUrl(requireGoogleApi(config), opts.account), config, {}, opts.verbose);
|
|
121254
|
-
} catch {
|
|
121255
|
-
listed = void 0;
|
|
121256
|
-
}
|
|
121257
|
-
const gone = receiptForAbsence("\u6392\u9664", opts.criterionId.trim(), listed);
|
|
121258
|
-
printWriteReceipt(gone.verification, gone.lines);
|
|
121259
120819
|
console.log(`
|
|
121260
120820
|
\u2705 \u5DF2\u5220\u9664\u5185\u5BB9\u6392\u9664 ${opts.criterionId}
|
|
121261
120821
|
`);
|
|
@@ -122381,11 +121941,10 @@ function extensionRowsFromResponse(res) {
|
|
|
122381
121941
|
(row) => !!row && typeof row === "object" && row["sectionHeadMode"] !== true
|
|
122382
121942
|
);
|
|
122383
121943
|
}
|
|
122384
|
-
function accountExtensionListUrl(googleApiUrl, account, startDate, endDate
|
|
121944
|
+
function accountExtensionListUrl(googleApiUrl, account, startDate, endDate) {
|
|
122385
121945
|
const params = new URLSearchParams();
|
|
122386
121946
|
params.set("startDate", toGoogleDate(startDate, -30));
|
|
122387
121947
|
params.set("endDate", toGoogleDate(endDate, 0));
|
|
122388
|
-
if (newest) params.set("newest", "true");
|
|
122389
121948
|
return `${googleApiUrl}/extensionmanagement/v2/list/${account}?${params}`;
|
|
122390
121949
|
}
|
|
122391
121950
|
function campaignExtensionListUrl(googleApiUrl, account, campaignId) {
|
|
@@ -122396,8 +121955,7 @@ async function fetchAccountExtensions(config, account, opts = {}) {
|
|
|
122396
121955
|
requireGoogleApi(config),
|
|
122397
121956
|
account,
|
|
122398
121957
|
opts.startDate,
|
|
122399
|
-
opts.endDate
|
|
122400
|
-
opts.newest
|
|
121958
|
+
opts.endDate
|
|
122401
121959
|
);
|
|
122402
121960
|
return extensionRowsFromResponse(await apiFetch2(url, config, {}, opts.verbose));
|
|
122403
121961
|
}
|
|
@@ -122417,7 +121975,7 @@ async function fetchCampaignExtensions(config, account, campaignId, opts = {}) {
|
|
|
122417
121975
|
} catch (err) {
|
|
122418
121976
|
if (!isNotFound(err)) throw err;
|
|
122419
121977
|
}
|
|
122420
|
-
const rows = (await fetchAccountExtensions(config, account,
|
|
121978
|
+
const rows = (await fetchAccountExtensions(config, account, opts)).filter(
|
|
122421
121979
|
(row) => String(row["campaignId"] ?? "") === cid
|
|
122422
121980
|
);
|
|
122423
121981
|
return { rows, source: "account-fallback" };
|
|
@@ -123351,8 +122909,8 @@ async function runAdGeoSearch(opts) {
|
|
|
123351
122909
|
name: geoItemDisplayName(item) || null,
|
|
123352
122910
|
targetType: geoItemType(item) || null
|
|
123353
122911
|
}));
|
|
123354
|
-
const
|
|
123355
|
-
const picked =
|
|
122912
|
+
const pick3 = pickGeoCandidate(opts.query, items3);
|
|
122913
|
+
const picked = pick3.picked;
|
|
123356
122914
|
const pickedId = picked ? String(picked["id"] ?? "") || null : null;
|
|
123357
122915
|
const payload = {
|
|
123358
122916
|
account: opts.account,
|
|
@@ -123360,8 +122918,8 @@ async function runAdGeoSearch(opts) {
|
|
|
123360
122918
|
itemCount: rows.length,
|
|
123361
122919
|
items: rows,
|
|
123362
122920
|
/** ok=同名候选(Country 优先);needs_review=无同名候选未自动选;unserved=Google 不投放地区 */
|
|
123363
|
-
pickStatus:
|
|
123364
|
-
pickNote:
|
|
122921
|
+
pickStatus: pick3.status,
|
|
122922
|
+
pickNote: pick3.note ?? null,
|
|
123365
122923
|
picked: picked ? {
|
|
123366
122924
|
id: pickedId,
|
|
123367
122925
|
name: geoItemDisplayName(picked) || null,
|
|
@@ -123404,7 +122962,7 @@ async function runAdGeoSearch(opts) {
|
|
|
123404
122962
|
);
|
|
123405
122963
|
} else {
|
|
123406
122964
|
console.log(`
|
|
123407
|
-
\u26A0\uFE0F \u672A\u81EA\u52A8\u9009\u62E9\uFF1A${
|
|
122965
|
+
\u26A0\uFE0F \u672A\u81EA\u52A8\u9009\u62E9\uFF1A${pick3.note ?? "\u65E0\u540C\u540D\u5019\u9009"}
|
|
123408
122966
|
`);
|
|
123409
122967
|
}
|
|
123410
122968
|
}
|
|
@@ -123449,17 +123007,17 @@ function parseGeoResolveQueries(opts) {
|
|
|
123449
123007
|
}
|
|
123450
123008
|
var GEO_RESOLVE_CONCURRENCY = 6;
|
|
123451
123009
|
function buildGeoResolveRow(query, items3) {
|
|
123452
|
-
const
|
|
123010
|
+
const pick3 = pickGeoCandidate(query, items3);
|
|
123453
123011
|
const row = {
|
|
123454
123012
|
query,
|
|
123455
|
-
id:
|
|
123456
|
-
name:
|
|
123457
|
-
targetType:
|
|
123458
|
-
status:
|
|
123013
|
+
id: pick3.picked ? String(pick3.picked["id"] ?? "") || null : null,
|
|
123014
|
+
name: pick3.picked ? geoItemDisplayName(pick3.picked) || null : null,
|
|
123015
|
+
targetType: pick3.picked ? geoItemType(pick3.picked) || null : null,
|
|
123016
|
+
status: pick3.status,
|
|
123459
123017
|
candidates: items3.length
|
|
123460
123018
|
};
|
|
123461
|
-
if (
|
|
123462
|
-
if (
|
|
123019
|
+
if (pick3.note) row.note = pick3.note;
|
|
123020
|
+
if (pick3.status === "needs_review") {
|
|
123463
123021
|
row.topCandidates = items3.slice(0, 5).map((it) => ({
|
|
123464
123022
|
id: String(it["id"] ?? ""),
|
|
123465
123023
|
name: geoItemDisplayName(it)
|
|
@@ -123656,7 +123214,6 @@ async function runAdGeoAdd(opts) {
|
|
|
123656
123214
|
`);
|
|
123657
123215
|
process.exit(1);
|
|
123658
123216
|
}
|
|
123659
|
-
await printGeoPresence(config, googleApiUrl, opts, true);
|
|
123660
123217
|
const label2 = opts.exclude ? "\u5DF2\u6392\u9664" : "\u5DF2\u6DFB\u52A0\u5B9A\u4F4D";
|
|
123661
123218
|
console.log(`
|
|
123662
123219
|
\u2705 \u5730\u7406\u4F4D\u7F6E ${opts.locationId} ${label2}\uFF08\u5E7F\u544A\u7CFB\u5217\uFF1A${opts.campaignId}\uFF09
|
|
@@ -123676,50 +123233,14 @@ async function runAdGeoRemove(opts) {
|
|
|
123676
123233
|
`);
|
|
123677
123234
|
process.exit(1);
|
|
123678
123235
|
}
|
|
123679
|
-
await printGeoPresence(config, googleApiUrl, opts, false);
|
|
123680
123236
|
console.log(`
|
|
123681
123237
|
\u2705 \u5730\u7406\u4F4D\u7F6E ${opts.locationId} \u5DF2\u4ECE\u5E7F\u544A\u7CFB\u5217 ${opts.campaignId} \u4E2D\u79FB\u9664
|
|
123682
123238
|
`);
|
|
123683
123239
|
}
|
|
123684
|
-
async function printGeoPresence(config, googleApiUrl, opts, shouldExist) {
|
|
123685
|
-
const params = new URLSearchParams({
|
|
123686
|
-
startDate: toGoogleDate(void 0, -30),
|
|
123687
|
-
endDate: toGoogleDate(void 0, 0),
|
|
123688
|
-
newest: "true"
|
|
123689
|
-
});
|
|
123690
|
-
const kinds = opts.exclude ? ["excludedlocations"] : shouldExist ? ["targetedlocations"] : ["targetedlocations", "excludedlocations"];
|
|
123691
|
-
let present;
|
|
123692
|
-
try {
|
|
123693
|
-
present = false;
|
|
123694
|
-
for (const kind of kinds) {
|
|
123695
|
-
const data = await apiFetch2(
|
|
123696
|
-
`${googleApiUrl}/campaignmanagement/v2/${kind}/${opts.account}?${params}`,
|
|
123697
|
-
config,
|
|
123698
|
-
{},
|
|
123699
|
-
opts.verbose
|
|
123700
|
-
);
|
|
123701
|
-
const rows = (data.data ?? []).filter(
|
|
123702
|
-
(row) => String(row["campaignId"] ?? row["CampaignId"] ?? "") === opts.campaignId
|
|
123703
|
-
);
|
|
123704
|
-
if (rows.some(
|
|
123705
|
-
(row) => [row["id"], row["Id"], row["locationId"], row["criterionId"]].map(String).includes(opts.locationId)
|
|
123706
|
-
)) {
|
|
123707
|
-
present = true;
|
|
123708
|
-
}
|
|
123709
|
-
}
|
|
123710
|
-
} catch {
|
|
123711
|
-
present = void 0;
|
|
123712
|
-
}
|
|
123713
|
-
const expected = shouldExist ? "\u5728\u5217\u8868\u4E2D" : "\u5DF2\u4E0D\u5728";
|
|
123714
|
-
const actual = present === void 0 ? void 0 : present ? "\u5728\u5217\u8868\u4E2D" : "\u5DF2\u4E0D\u5728";
|
|
123715
|
-
const lines = [receiptLine("\u5730\u533A", expected, actual)];
|
|
123716
|
-
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
123717
|
-
}
|
|
123718
123240
|
async function fetchTargetedGeoRows(config, googleApiUrl, account, campaignId, verbose) {
|
|
123719
123241
|
const params = new URLSearchParams({
|
|
123720
123242
|
startDate: toGoogleDate(void 0, -30),
|
|
123721
|
-
endDate: toGoogleDate(void 0, 0)
|
|
123722
|
-
newest: "true"
|
|
123243
|
+
endDate: toGoogleDate(void 0, 0)
|
|
123723
123244
|
});
|
|
123724
123245
|
const url = `${googleApiUrl}/campaignmanagement/v2/targetedlocations/${account}?${params}`;
|
|
123725
123246
|
const data = await apiFetch2(url, config, {}, verbose);
|
|
@@ -124257,73 +123778,6 @@ function listPlannedRsaAssets(ad, groupPath, adIndex, adGroupName) {
|
|
|
124257
123778
|
}
|
|
124258
123779
|
return out;
|
|
124259
123780
|
}
|
|
124260
|
-
function plannedLocationIds(value) {
|
|
124261
|
-
if (!Array.isArray(value)) return [];
|
|
124262
|
-
const ids = [];
|
|
124263
|
-
for (const item of value) {
|
|
124264
|
-
if (typeof item === "string" || typeof item === "number") {
|
|
124265
|
-
ids.push(String(item));
|
|
124266
|
-
continue;
|
|
124267
|
-
}
|
|
124268
|
-
if (item && typeof item === "object") {
|
|
124269
|
-
const id = pickString2(
|
|
124270
|
-
item["id"],
|
|
124271
|
-
item["Id"]
|
|
124272
|
-
);
|
|
124273
|
-
if (id) ids.push(id);
|
|
124274
|
-
}
|
|
124275
|
-
}
|
|
124276
|
-
return [...new Set(ids)].sort();
|
|
124277
|
-
}
|
|
124278
|
-
function firstPlannedFinalUrl(campaign) {
|
|
124279
|
-
const groups = campaign["AdGroupsForBatchJob"];
|
|
124280
|
-
if (!Array.isArray(groups)) return "";
|
|
124281
|
-
for (const group of groups) {
|
|
124282
|
-
if (!group || typeof group !== "object") continue;
|
|
124283
|
-
const ads = group["AdsForBatchJob"];
|
|
124284
|
-
if (!Array.isArray(ads)) continue;
|
|
124285
|
-
for (const ad of ads) {
|
|
124286
|
-
if (!ad || typeof ad !== "object") continue;
|
|
124287
|
-
const url = pickString2(
|
|
124288
|
-
ad["Finalurl"],
|
|
124289
|
-
ad["DestinationUrl"]
|
|
124290
|
-
);
|
|
124291
|
-
if (url) return url;
|
|
124292
|
-
}
|
|
124293
|
-
}
|
|
124294
|
-
return "";
|
|
124295
|
-
}
|
|
124296
|
-
function buildSearchCreateReceiptLines(campaign, live) {
|
|
124297
|
-
const lines = [];
|
|
124298
|
-
const plannedBudget = Number(campaign["Budget"] ?? campaign["budget"]);
|
|
124299
|
-
if (Number.isFinite(plannedBudget) && plannedBudget > 0) {
|
|
124300
|
-
lines.push(
|
|
124301
|
-
receiptLine(
|
|
124302
|
-
"\u65E5\u9884\u7B97",
|
|
124303
|
-
yuanLabel(plannedBudget),
|
|
124304
|
-
live.budgetYuan == null ? void 0 : yuanLabel(live.budgetYuan)
|
|
124305
|
-
)
|
|
124306
|
-
);
|
|
124307
|
-
}
|
|
124308
|
-
const plannedStatus = pickString2(campaign["StatusV2"], campaign["statusV2"]);
|
|
124309
|
-
if (plannedStatus) {
|
|
124310
|
-
lines.push(receiptLine("\u72B6\u6001", plannedStatus, live.statusV2));
|
|
124311
|
-
}
|
|
124312
|
-
const plannedIds = plannedLocationIds(campaign["targetedLocations"]);
|
|
124313
|
-
if (plannedIds.length > 0) {
|
|
124314
|
-
const liveIds = [...new Set((live.targetedLocations ?? []).map((row) => liveLocationId(row)).filter(Boolean))].sort();
|
|
124315
|
-
lines.push(receiptLine("\u6295\u653E\u56FD\u5BB6", plannedIds.join(","), live.campaignFound ? liveIds.join(",") : void 0));
|
|
124316
|
-
}
|
|
124317
|
-
const plannedGeo = resolveCampaignGeoTargetTypes(campaign);
|
|
124318
|
-
if (plannedGeo.positive) {
|
|
124319
|
-
lines.push(receiptLine("\u4F4D\u7F6E\u9009\u9879", plannedGeo.positive, live.positiveGeoTargetType));
|
|
124320
|
-
}
|
|
124321
|
-
const plannedUrl = firstPlannedFinalUrl(campaign);
|
|
124322
|
-
if (plannedUrl) {
|
|
124323
|
-
lines.push(receiptLine("\u843D\u5730\u9875", plannedUrl, live.landingUrl));
|
|
124324
|
-
}
|
|
124325
|
-
return lines;
|
|
124326
|
-
}
|
|
124327
123781
|
function liveLocationId(item) {
|
|
124328
123782
|
return pickString2(
|
|
124329
123783
|
item["id"],
|
|
@@ -125067,7 +124521,7 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
|
|
|
125067
124521
|
),
|
|
125068
124522
|
fetchList(
|
|
125069
124523
|
config,
|
|
125070
|
-
negativeKeywordSlimListUrl(googleApiUrl, accountId
|
|
124524
|
+
negativeKeywordSlimListUrl(googleApiUrl, accountId),
|
|
125071
124525
|
verbose
|
|
125072
124526
|
),
|
|
125073
124527
|
fetchList(
|
|
@@ -125101,19 +124555,9 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
|
|
|
125101
124555
|
const liveCampaign = campaigns.find((c) => pickString2(c["id"], c["Id"]) === campaignId) ?? campaigns.find((c) => pickString2(c["name"], c["Name"]) === campaignName);
|
|
125102
124556
|
const campaignFound = liveCampaign !== void 0;
|
|
125103
124557
|
const liveGeoTargetTypes = liveCampaign ? readLiveGeoTargetTypes(liveCampaign) : {};
|
|
125104
|
-
const budgetYuan2 = liveCampaign ? toDisplayMoney(liveCampaign["budget"] ?? liveCampaign["Budget"]) ?? void 0 : void 0;
|
|
125105
|
-
const campaignAds = ads.filter((row) => belongsToCampaign(row, campaignId, campaignName));
|
|
125106
|
-
const landingUrl = pickString2(
|
|
125107
|
-
campaignAds[0]?.["Finalurl"],
|
|
125108
|
-
campaignAds[0]?.["finalUrl"],
|
|
125109
|
-
campaignAds[0]?.["DestinationUrl"]
|
|
125110
|
-
);
|
|
125111
124558
|
return {
|
|
125112
124559
|
campaignFound,
|
|
125113
124560
|
campaignName,
|
|
125114
|
-
budgetYuan: budgetYuan2,
|
|
125115
|
-
statusV2: liveCampaign ? pickString2(liveCampaign["statusV2"], liveCampaign["StatusV2"]) : void 0,
|
|
125116
|
-
landingUrl: landingUrl || void 0,
|
|
125117
124561
|
positiveGeoTargetType: liveGeoTargetTypes.positive,
|
|
125118
124562
|
negativeGeoTargetType: liveGeoTargetTypes.negative,
|
|
125119
124563
|
adGroups: adGroups.filter((g) => belongsToCampaign(g, campaignId, campaignName)),
|
|
@@ -125710,7 +125154,6 @@ async function runCampaignBatchDiff(opts) {
|
|
|
125710
125154
|
const params = new URLSearchParams();
|
|
125711
125155
|
params.set("startDate", toGoogleDate(void 0, -30));
|
|
125712
125156
|
params.set("endDate", toGoogleDate(void 0, 0));
|
|
125713
|
-
params.set("newest", "true");
|
|
125714
125157
|
const campaigns = await fetchList(
|
|
125715
125158
|
config,
|
|
125716
125159
|
`${googleApiUrl}/campaignmanagement/v2/list/${accountId}?${params}`,
|
|
@@ -125755,8 +125198,6 @@ async function runCampaignBatchDiff(opts) {
|
|
|
125755
125198
|
...result,
|
|
125756
125199
|
...report
|
|
125757
125200
|
};
|
|
125758
|
-
const receiptLines = buildSearchCreateReceiptLines(campaign, live);
|
|
125759
|
-
printWriteReceipt(judgeReceipt(receiptLines, !live.campaignFound), receiptLines);
|
|
125760
125201
|
printBatchDiffUserDeliveryMarkdown(report);
|
|
125761
125202
|
if (await emitCliJsonOrSnapshot(
|
|
125762
125203
|
{ jsonOut: opts.jsonOut },
|
|
@@ -126141,23 +125582,6 @@ async function runAiCreationPublish(opts) {
|
|
|
126141
125582
|
`);
|
|
126142
125583
|
process.exit(1);
|
|
126143
125584
|
}
|
|
126144
|
-
let again;
|
|
126145
|
-
try {
|
|
126146
|
-
again = await apiFetch2(`${queryBase}/${opts.id}`, config, {}, opts.verbose);
|
|
126147
|
-
} catch {
|
|
126148
|
-
again = void 0;
|
|
126149
|
-
}
|
|
126150
|
-
const submittedCampaign = body["campaign"] ?? {};
|
|
126151
|
-
const readCampaign = again?.["campaign"] ?? {};
|
|
126152
|
-
const status = again ? String(again["status"] ?? again["draftStatus"] ?? "") : "";
|
|
126153
|
-
const leftDraft = status !== "" && status !== "Draft";
|
|
126154
|
-
const campaignId = again ? resolveCampaignIdFromBatch(again) : "";
|
|
126155
|
-
const lines = [
|
|
126156
|
-
receiptLine("\u53D1\u5E03\u72B6\u6001", "\u5DF2\u79BB\u5F00\u8349\u7A3F", again ? leftDraft ? "\u5DF2\u79BB\u5F00\u8349\u7A3F" : status || "Draft" : void 0),
|
|
126157
|
-
receiptLine("\u7CFB\u5217\u9884\u7B97", submittedCampaign["Budget"], again ? readCampaign["Budget"] : void 0),
|
|
126158
|
-
receiptLine("\u7CFB\u5217", "\u5DF2\u751F\u6210", again ? campaignId || "\u5C1A\u672A\u751F\u6210" : void 0)
|
|
126159
|
-
];
|
|
126160
|
-
printWriteReceipt(again ? judgeReceipt(lines) : "unknown", lines);
|
|
126161
125585
|
console.log(
|
|
126162
125586
|
`
|
|
126163
125587
|
\u2705 \u8349\u7A3F\u5DF2\u63D0\u4EA4\u53D1\u5E03\uFF0CGoogle \u5C06\u5728\u540E\u53F0\u5F02\u6B65\u6267\u884C\u521B\u5EFA\uFF0C\u53EF\u901A\u8FC7 ad batch list \u67E5\u770B\u6700\u65B0\u72B6\u6001
|
|
@@ -128124,6 +127548,345 @@ async function linkPmaxVideoAfterCreate(opts) {
|
|
|
128124
127548
|
}
|
|
128125
127549
|
}
|
|
128126
127550
|
|
|
127551
|
+
// src/commands/ad/pmax-create.ts
|
|
127552
|
+
function printVideoLinkRecoveryHint(accountId, assetGroupId, campaignId, youtubeTarget) {
|
|
127553
|
+
const cid = campaignId != null ? ` --campaign-id ${campaignId}` : "";
|
|
127554
|
+
const yt = youtubeTarget ? ` --youtube "${youtubeTarget}"` : ` --video-path "<path>"`;
|
|
127555
|
+
console.error(
|
|
127556
|
+
` \u53EF\u624B\u52A8\uFF1Asiluzan-tso ad pmax-youtube-link -a ${accountId} --asset-group-id ${assetGroupId}${cid}${yt}
|
|
127557
|
+
\u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002
|
|
127558
|
+
`
|
|
127559
|
+
);
|
|
127560
|
+
}
|
|
127561
|
+
async function runAdPmaxCreate(opts) {
|
|
127562
|
+
const cfg = loadPmaxCreateConfig(opts.configFile);
|
|
127563
|
+
const rawCfg = loadPmaxCreateConfigRaw(opts.configFile) ?? {};
|
|
127564
|
+
const deprecatedVideoKeys = detectDeprecatedPmaxVideoKeys(rawCfg);
|
|
127565
|
+
const {
|
|
127566
|
+
errors: cfgErrors,
|
|
127567
|
+
warnings: cfgWarnings,
|
|
127568
|
+
lengthViolations: cfgLengthViolations
|
|
127569
|
+
} = runPmaxCreateValidation(cfg);
|
|
127570
|
+
const { errors: imgErrors, warnings: imgWarnings } = await runPmaxImageValidation(
|
|
127571
|
+
opts.configFile,
|
|
127572
|
+
cfg
|
|
127573
|
+
);
|
|
127574
|
+
const { errors: videoErrors, warnings: videoWarnings } = runPmaxVideoValidation(
|
|
127575
|
+
opts.configFile,
|
|
127576
|
+
cfg
|
|
127577
|
+
);
|
|
127578
|
+
const { errors: extErrors, warnings: extWarnings } = validatePmaxCampaignExtensions(
|
|
127579
|
+
cfg.campaignExtensions,
|
|
127580
|
+
{
|
|
127581
|
+
skipCampaignExtensions: cfg.skipCampaignExtensions,
|
|
127582
|
+
rawConfig: rawCfg
|
|
127583
|
+
}
|
|
127584
|
+
);
|
|
127585
|
+
const errors = [...deprecatedVideoKeys, ...cfgErrors, ...imgErrors, ...videoErrors, ...extErrors];
|
|
127586
|
+
const warnings = [...cfgWarnings, ...imgWarnings, ...videoWarnings, ...extWarnings];
|
|
127587
|
+
if (warnings.length > 0) {
|
|
127588
|
+
console.warn("\n\u26A0\uFE0F PMax \u914D\u7F6E\u8B66\u544A\uFF08\u4E0D\u963B\u65AD\u63D0\u4EA4\uFF09\uFF1A");
|
|
127589
|
+
for (const w of warnings) console.warn(` \u2022 ${w}`);
|
|
127590
|
+
}
|
|
127591
|
+
if (errors.length > 0) {
|
|
127592
|
+
console.error("\n\u274C PMax \u914D\u7F6E\u6821\u9A8C\u5931\u8D25\uFF1A");
|
|
127593
|
+
for (const e of errors) console.error(` \u2022 ${e}`);
|
|
127594
|
+
const lengthReport = formatLengthViolationsReport(cfgLengthViolations, {
|
|
127595
|
+
revalidateCommand: "pmax-validate"
|
|
127596
|
+
});
|
|
127597
|
+
if (lengthReport) console.error(lengthReport);
|
|
127598
|
+
console.error();
|
|
127599
|
+
process.exit(1);
|
|
127600
|
+
}
|
|
127601
|
+
const config = await ensureDataPermission(loadConfig(opts.token));
|
|
127602
|
+
const googleApiUrl = requireGoogleApi(config);
|
|
127603
|
+
const accountId = resolveAdAccountId(cfg.account.toString(), "account");
|
|
127604
|
+
cfg.account = accountId;
|
|
127605
|
+
let imageSlots;
|
|
127606
|
+
try {
|
|
127607
|
+
imageSlots = await resolvePmaxImageSlots(
|
|
127608
|
+
opts.configFile,
|
|
127609
|
+
cfg,
|
|
127610
|
+
accountId,
|
|
127611
|
+
config,
|
|
127612
|
+
googleApiUrl,
|
|
127613
|
+
{ verbose: opts.verbose, logUploads: !opts.jsonOut }
|
|
127614
|
+
);
|
|
127615
|
+
} catch (err) {
|
|
127616
|
+
console.error(`
|
|
127617
|
+
\u274C \u56FE\u7247\u4E0A\u4F20/\u89E3\u6790\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
127618
|
+
`);
|
|
127619
|
+
process.exit(1);
|
|
127620
|
+
}
|
|
127621
|
+
let body;
|
|
127622
|
+
try {
|
|
127623
|
+
body = buildPmaxCreateApiBody(cfg, imageSlots);
|
|
127624
|
+
} catch (err) {
|
|
127625
|
+
console.error(`
|
|
127626
|
+
\u274C \u6784\u5EFA\u8BF7\u6C42\u4F53\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
127627
|
+
`);
|
|
127628
|
+
process.exit(1);
|
|
127629
|
+
}
|
|
127630
|
+
const url = buildPmaxCreateUrl(googleApiUrl, accountId);
|
|
127631
|
+
let data;
|
|
127632
|
+
try {
|
|
127633
|
+
data = await apiFetch2(
|
|
127634
|
+
url,
|
|
127635
|
+
config,
|
|
127636
|
+
{ method: "POST", body: JSON.stringify(body) },
|
|
127637
|
+
opts.verbose
|
|
127638
|
+
);
|
|
127639
|
+
} catch (err) {
|
|
127640
|
+
const failure = parsePmaxCreateFailureBody(readHttpRawBody(err));
|
|
127641
|
+
if (failure) {
|
|
127642
|
+
const advice = pmaxCreateRetryAdvice(cfg, failure);
|
|
127643
|
+
console.error(`
|
|
127644
|
+
\u274C \u521B\u5EFA PMax \u5E7F\u544A\u7CFB\u5217\u5931\u8D25\uFF1A${failure.message}`);
|
|
127645
|
+
console.error(` budgetId\uFF1A${failure.budgetId ?? "null"}`);
|
|
127646
|
+
console.error(` campaignId\uFF1A${failure.campaignId ?? "null"}`);
|
|
127647
|
+
console.error(` assetGroupId\uFF1A${failure.assetGroupId ?? "null"}`);
|
|
127648
|
+
if (advice === "resume") {
|
|
127649
|
+
console.error(
|
|
127650
|
+
" \u7EED\u8DD1\uFF1A\u628A\u975E\u7A7A\u7F16\u53F7\u6309\u540C\u540D\u5199\u56DE\u8FD9\u4EFD JSON\uFF0C\u5176\u4F59\u5185\u5BB9\u4E0D\u8981\u6539\uFF0C\u518D\u6267\u884C\u4E00\u6B21 pmax-create\u3002\u7F16\u53F7\u6309\u9884\u7B97\u3001\u7CFB\u5217\u3001\u7D20\u6750\u7EC4\u5E26\u3002\u540C\u4E00\u6B65\u518D\u5931\u8D25\u5C31\u505C\u3002\n"
|
|
127651
|
+
);
|
|
127652
|
+
} else if (advice === "stop-same-step") {
|
|
127653
|
+
console.error(" \u540C\u4E00\u6B65\u518D\u5931\u8D25\uFF0C\u505C\u6B62\u3002\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002\n");
|
|
127654
|
+
} else {
|
|
127655
|
+
console.error(" \u8FD9\u6B21\u8FD8\u6CA1\u6709\u5EFA\u6210\u9884\u7B97\u3001\u7CFB\u5217\u6216\u7D20\u6750\u7EC4\u3002\u4FEE\u6B63\u539F\u56E0\u540E\u7528\u539F JSON \u518D\u63D0\u4EA4\uFF0C\u4E0D\u8981\u586B\u8FD9\u4E09\u4E2A\u7F16\u53F7\u3002\n");
|
|
127656
|
+
}
|
|
127657
|
+
await emitCliJsonOrSnapshot(opts, {
|
|
127658
|
+
section: `ad-pmax-create-${accountId}`,
|
|
127659
|
+
commandLabel: "ad pmax-create",
|
|
127660
|
+
commandHint: accountId,
|
|
127661
|
+
payload: { ok: false, retryCreate: advice === "resume", ...failure },
|
|
127662
|
+
idSuffix: accountId,
|
|
127663
|
+
summaryExtras: {
|
|
127664
|
+
ok: false,
|
|
127665
|
+
retryCreate: advice === "resume",
|
|
127666
|
+
budgetId: failure.budgetId,
|
|
127667
|
+
campaignId: failure.campaignId,
|
|
127668
|
+
assetGroupId: failure.assetGroupId
|
|
127669
|
+
}
|
|
127670
|
+
});
|
|
127671
|
+
process.exit(1);
|
|
127672
|
+
}
|
|
127673
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
127674
|
+
console.error(`
|
|
127675
|
+
\u274C \u521B\u5EFA PMax \u5E7F\u544A\u7CFB\u5217\u5931\u8D25\uFF1A${classifyPmaxCreateHttpError(raw)}
|
|
127676
|
+
`);
|
|
127677
|
+
process.exit(1);
|
|
127678
|
+
}
|
|
127679
|
+
const campaignId = data["campaignId"] ?? data["campaign_id"];
|
|
127680
|
+
const assetGroupId = data["assetGroupId"] ?? data["asset_group_id"];
|
|
127681
|
+
const budgetId = data["budgetId"] ?? data["budget_id"];
|
|
127682
|
+
const videoResult = await linkPmaxVideoAfterCreate({
|
|
127683
|
+
config,
|
|
127684
|
+
googleApiUrl,
|
|
127685
|
+
accountId,
|
|
127686
|
+
configFile: opts.configFile,
|
|
127687
|
+
cfg,
|
|
127688
|
+
campaignId,
|
|
127689
|
+
assetGroupId,
|
|
127690
|
+
verbose: opts.verbose,
|
|
127691
|
+
logProgress: !opts.jsonOut
|
|
127692
|
+
});
|
|
127693
|
+
let extensionsResult;
|
|
127694
|
+
if (campaignId != null && cfg.campaignExtensions) {
|
|
127695
|
+
if (!opts.jsonOut) {
|
|
127696
|
+
console.log("\n \u6302\u8F7D Campaign \u9644\u52A0\u8D44\u4EA7\u2026");
|
|
127697
|
+
}
|
|
127698
|
+
extensionsResult = await attachPmaxCampaignExtensions({
|
|
127699
|
+
config,
|
|
127700
|
+
googleApiUrl,
|
|
127701
|
+
accountId,
|
|
127702
|
+
campaignId: String(campaignId),
|
|
127703
|
+
extensions: cfg.campaignExtensions,
|
|
127704
|
+
verbose: opts.verbose,
|
|
127705
|
+
logProgress: !opts.jsonOut
|
|
127706
|
+
});
|
|
127707
|
+
}
|
|
127708
|
+
const payload = {
|
|
127709
|
+
...data,
|
|
127710
|
+
_brandGuidelinesEnabled: cfg.brandGuidelinesEnabled !== false,
|
|
127711
|
+
_agentBrandHint: cfg.brandGuidelinesEnabled === false ? "\u54C1\u724C\u5728 AssetGroup \u7EA7\uFF1B\u6539\u54C1\u724C\u7528 pmax-assets-update" : "\u54C1\u724C\u5728 Campaign \u7EA7 brandAssets[]\uFF1B\u6539\u54C1\u724C\u7528 pmax-brand-assets-edit\uFF1B\u8FFD\u52A0 AG \u53EF\u7701\u7565 Logo/\u5546\u5BB6\u540D",
|
|
127712
|
+
videoLink: {
|
|
127713
|
+
ok: Boolean(videoResult.youtubeLink && !videoResult.uploadError && !videoResult.linkError),
|
|
127714
|
+
youtubeTarget: videoResult.youtubeTarget,
|
|
127715
|
+
assetResourceName: videoResult.youtubeLink?.["assetResourceName"],
|
|
127716
|
+
uploadError: videoResult.uploadError,
|
|
127717
|
+
linkError: videoResult.linkError,
|
|
127718
|
+
skippedReason: videoResult.skippedReason
|
|
127719
|
+
},
|
|
127720
|
+
campaignExtensions: extensionsResult ?? {
|
|
127721
|
+
allOk: true,
|
|
127722
|
+
skippedReason: "\u672A\u914D\u7F6E campaignExtensions"
|
|
127723
|
+
}
|
|
127724
|
+
};
|
|
127725
|
+
if (videoResult.uploadError) {
|
|
127726
|
+
console.error(`
|
|
127727
|
+
\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46\u672C\u5730\u89C6\u9891\u4E0A\u4F20\u5931\u8D25\uFF1A${videoResult.uploadError}`);
|
|
127728
|
+
if (assetGroupId != null) {
|
|
127729
|
+
printVideoLinkRecoveryHint(
|
|
127730
|
+
accountId,
|
|
127731
|
+
assetGroupId,
|
|
127732
|
+
campaignId,
|
|
127733
|
+
void 0
|
|
127734
|
+
);
|
|
127735
|
+
}
|
|
127736
|
+
console.error(" \u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002\n");
|
|
127737
|
+
} else if (videoResult.linkError) {
|
|
127738
|
+
console.error(`
|
|
127739
|
+
\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46 YouTube \u94FE\u63A5\u5931\u8D25\uFF1A${videoResult.linkError}`);
|
|
127740
|
+
if (assetGroupId != null) {
|
|
127741
|
+
printVideoLinkRecoveryHint(
|
|
127742
|
+
accountId,
|
|
127743
|
+
assetGroupId,
|
|
127744
|
+
campaignId,
|
|
127745
|
+
videoResult.youtubeTarget
|
|
127746
|
+
);
|
|
127747
|
+
}
|
|
127748
|
+
console.error(" \u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002\n");
|
|
127749
|
+
} else if (videoResult.skippedReason) {
|
|
127750
|
+
console.error(`
|
|
127751
|
+
\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46\u89C6\u9891\u672A\u94FE\u63A5\uFF1A${videoResult.skippedReason}
|
|
127752
|
+
`);
|
|
127753
|
+
}
|
|
127754
|
+
if (extensionsResult && !extensionsResult.allOk) {
|
|
127755
|
+
console.error("\n\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46\u90E8\u5206\u9644\u52A0\u8D44\u4EA7\u6302\u8F7D\u5931\u8D25\uFF1A");
|
|
127756
|
+
for (const msg of formatPmaxExtensionsAttachErrors(extensionsResult)) {
|
|
127757
|
+
console.error(` \u2022 ${msg}`);
|
|
127758
|
+
}
|
|
127759
|
+
console.error(
|
|
127760
|
+
` \u53EF\u624B\u52A8\u8865\u6302\uFF1Asiluzan-tso ad extension callout|snippet|lead-form -a ${accountId} --campaign-id ${campaignId} \u2026
|
|
127761
|
+
\u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002
|
|
127762
|
+
`
|
|
127763
|
+
);
|
|
127764
|
+
} else if (extensionsResult?.allOk && extensionsResult.callouts.length + extensionsResult.structuredSnippets.length + extensionsResult.sitelinks.length + (extensionsResult.leadForm ? 1 : 0) + (extensionsResult.whatsapp ? 1 : 0) > 0) {
|
|
127765
|
+
if (!opts.jsonOut) {
|
|
127766
|
+
console.log("\n\u2705 Campaign \u9644\u52A0\u8D44\u4EA7\u5DF2\u6302\u8F7D");
|
|
127767
|
+
}
|
|
127768
|
+
}
|
|
127769
|
+
const followUpFailed = pmaxCreateFollowUpFailed({
|
|
127770
|
+
uploadError: videoResult.uploadError,
|
|
127771
|
+
linkError: videoResult.linkError,
|
|
127772
|
+
extensionsAllOk: extensionsResult ? extensionsResult.allOk : void 0
|
|
127773
|
+
});
|
|
127774
|
+
if (followUpFailed) {
|
|
127775
|
+
payload["created"] = true;
|
|
127776
|
+
payload["retryCreate"] = false;
|
|
127777
|
+
}
|
|
127778
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
127779
|
+
section: `ad-pmax-create-${accountId}`,
|
|
127780
|
+
commandLabel: "ad pmax-create",
|
|
127781
|
+
commandHint: accountId,
|
|
127782
|
+
payload,
|
|
127783
|
+
idSuffix: accountId,
|
|
127784
|
+
summaryExtras: followUpFailed ? { created: true, retryCreate: false } : void 0
|
|
127785
|
+
})) {
|
|
127786
|
+
return;
|
|
127787
|
+
}
|
|
127788
|
+
if (videoResult.youtubeTarget && videoResult.youtubeLink) {
|
|
127789
|
+
console.log(`
|
|
127790
|
+
\u2705 \u5DF2\u94FE\u63A5 YouTube\uFF1A${videoResult.youtubeTarget}`);
|
|
127791
|
+
const arn = videoResult.youtubeLink["assetResourceName"];
|
|
127792
|
+
if (arn != null) console.log(` assetResourceName\uFF1A${arn}`);
|
|
127793
|
+
}
|
|
127794
|
+
console.log("\n\u2705 PMax \u5E7F\u544A\u7CFB\u5217\u5DF2\u521B\u5EFA\uFF08\u540C\u6B65\uFF09");
|
|
127795
|
+
console.log(` \u6D3B\u52A8\u540D\u79F0\uFF1A${cfg.name}`);
|
|
127796
|
+
if (campaignId != null) console.log(` campaignId\uFF1A${campaignId}`);
|
|
127797
|
+
if (assetGroupId != null) console.log(` assetGroupId\uFF1A${assetGroupId}`);
|
|
127798
|
+
if (budgetId != null) console.log(` budgetId\uFF1A${budgetId}`);
|
|
127799
|
+
console.log(
|
|
127800
|
+
`
|
|
127801
|
+
\u590D\u6838\uFF1Asiluzan-tso ad campaigns -a ${accountId} --json-out # channelTypeV2 \u5E94\u4E3A PERFORMANCE_MAX`
|
|
127802
|
+
);
|
|
127803
|
+
if (!cfg.videoPath?.trim() && !cfg.youtubeUrlOrId?.trim()) {
|
|
127804
|
+
console.log(
|
|
127805
|
+
" \u89C6\u9891\uFF1A\u914D\u7F6E videoPath\uFF08\u672C\u5730\uFF09\u6216 youtubeUrlOrId \u53EF\u5728\u521B\u5EFA\u65F6\u81EA\u52A8\u94FE\u63A5\uFF1B\u6216\u521B\u5EFA\u540E ad pmax-youtube-link"
|
|
127806
|
+
);
|
|
127807
|
+
}
|
|
127808
|
+
console.log();
|
|
127809
|
+
}
|
|
127810
|
+
|
|
127811
|
+
// src/commands/ad/pmax-validate.ts
|
|
127812
|
+
import { writeFileSync as writeFileSync3 } from "fs";
|
|
127813
|
+
init_cli_json_snapshot();
|
|
127814
|
+
async function runAdPmaxValidate(opts) {
|
|
127815
|
+
const cfg = loadPmaxCreateConfig(opts.configFile);
|
|
127816
|
+
const rawCfg = loadPmaxCreateConfigRaw(opts.configFile) ?? {};
|
|
127817
|
+
const deprecatedVideoKeys = detectDeprecatedPmaxVideoKeys(rawCfg);
|
|
127818
|
+
const {
|
|
127819
|
+
errors: cfgErrors,
|
|
127820
|
+
warnings: cfgWarnings,
|
|
127821
|
+
lengthViolations: cfgLengthViolations
|
|
127822
|
+
} = runPmaxCreateValidation(cfg);
|
|
127823
|
+
const { errors: imgErrors, warnings: imgWarnings } = await runPmaxImageValidation(
|
|
127824
|
+
opts.configFile,
|
|
127825
|
+
cfg
|
|
127826
|
+
);
|
|
127827
|
+
const { errors: videoErrors, warnings: videoWarnings } = runPmaxVideoValidation(
|
|
127828
|
+
opts.configFile,
|
|
127829
|
+
cfg
|
|
127830
|
+
);
|
|
127831
|
+
const { errors: extErrors, warnings: extWarnings } = validatePmaxCampaignExtensions(
|
|
127832
|
+
cfg.campaignExtensions,
|
|
127833
|
+
{
|
|
127834
|
+
skipCampaignExtensions: cfg.skipCampaignExtensions,
|
|
127835
|
+
rawConfig: rawCfg
|
|
127836
|
+
}
|
|
127837
|
+
);
|
|
127838
|
+
const errors = [...deprecatedVideoKeys, ...cfgErrors, ...imgErrors, ...videoErrors, ...extErrors];
|
|
127839
|
+
const warnings = [...cfgWarnings, ...imgWarnings, ...videoWarnings, ...extWarnings];
|
|
127840
|
+
const lengthViolations = cfgLengthViolations;
|
|
127841
|
+
if (opts.writeNormalized) {
|
|
127842
|
+
const toWrite = stripMetaKeysForExport(cfg);
|
|
127843
|
+
writeFileSync3(opts.writeNormalized, `${JSON.stringify(toWrite, null, 2)}
|
|
127844
|
+
`, "utf8");
|
|
127845
|
+
}
|
|
127846
|
+
const payload = {
|
|
127847
|
+
ok: errors.length === 0,
|
|
127848
|
+
configFile: opts.configFile,
|
|
127849
|
+
account: cfg.account?.toString().trim() || void 0,
|
|
127850
|
+
errors,
|
|
127851
|
+
warnings,
|
|
127852
|
+
lengthViolations,
|
|
127853
|
+
agentHint: lengthViolations.length > 0 ? lengthViolationAgentHint("pmax-validate") : void 0
|
|
127854
|
+
};
|
|
127855
|
+
const accountSuffix = payload.account;
|
|
127856
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
127857
|
+
section: "ad-pmax-validate",
|
|
127858
|
+
commandLabel: "ad pmax-validate",
|
|
127859
|
+
commandHint: opts.configFile,
|
|
127860
|
+
payload,
|
|
127861
|
+
idSuffix: accountSuffix
|
|
127862
|
+
})) {
|
|
127863
|
+
if (!payload.ok) process.exit(1);
|
|
127864
|
+
return;
|
|
127865
|
+
}
|
|
127866
|
+
if (warnings.length > 0) {
|
|
127867
|
+
console.warn("\n\u26A0\uFE0F PMax \u914D\u7F6E\u8B66\u544A\uFF1A");
|
|
127868
|
+
for (const w of warnings) console.warn(` \u2022 ${w}`);
|
|
127869
|
+
}
|
|
127870
|
+
if (errors.length > 0) {
|
|
127871
|
+
console.error("\n\u274C PMax \u914D\u7F6E\u6821\u9A8C\u5931\u8D25\uFF1A");
|
|
127872
|
+
for (const e of errors) console.error(` \u2022 ${e}`);
|
|
127873
|
+
const lengthReport = formatLengthViolationsReport(lengthViolations, {
|
|
127874
|
+
revalidateCommand: "pmax-validate"
|
|
127875
|
+
});
|
|
127876
|
+
if (lengthReport) console.error(lengthReport);
|
|
127877
|
+
console.error();
|
|
127878
|
+
process.exit(1);
|
|
127879
|
+
}
|
|
127880
|
+
console.log("\n\u2705 PMax \u914D\u7F6E\u6821\u9A8C\u901A\u8FC7");
|
|
127881
|
+
if (opts.writeNormalized) {
|
|
127882
|
+
console.log(` \u5DF2\u5199\u5165\uFF1A${opts.writeNormalized}`);
|
|
127883
|
+
}
|
|
127884
|
+
console.log();
|
|
127885
|
+
}
|
|
127886
|
+
|
|
127887
|
+
// src/commands/ad/pmax-mgmt.ts
|
|
127888
|
+
import { basename as basename7, isAbsolute as isAbsolute6 } from "path";
|
|
127889
|
+
|
|
128127
127890
|
// src/commands/ad/pmax-brand-guidelines.ts
|
|
128128
127891
|
var PMAX_CAMPAIGN_BRAND_FIELD_TYPES = /* @__PURE__ */ new Set(["BUSINESS_NAME", "LOGO", "LANDSCAPE_LOGO"]);
|
|
128129
127892
|
function isPmaxBrandGuidelinesActive(detail) {
|
|
@@ -128155,34 +127918,6 @@ async function fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaign
|
|
|
128155
127918
|
}
|
|
128156
127919
|
return { data: raw };
|
|
128157
127920
|
}
|
|
128158
|
-
function printPmaxWriteReceipt(expected, detail, liveCountryIds) {
|
|
128159
|
-
const lines = [];
|
|
128160
|
-
if (expected.budgetYuan != null) {
|
|
128161
|
-
const raw = detail?.["budget"] ?? detail?.["Budget"];
|
|
128162
|
-
const actual = typeof raw === "number" && Number.isFinite(raw) ? raw / 100 : void 0;
|
|
128163
|
-
lines.push(
|
|
128164
|
-
receiptLine(
|
|
128165
|
-
"\u65E5\u9884\u7B97",
|
|
128166
|
-
yuanLabel(expected.budgetYuan),
|
|
128167
|
-
actual == null ? void 0 : yuanLabel(actual)
|
|
128168
|
-
)
|
|
128169
|
-
);
|
|
128170
|
-
}
|
|
128171
|
-
if (expected.status) {
|
|
128172
|
-
lines.push(receiptLine("\u72B6\u6001", expected.status, detail?.["statusV2"] ?? detail?.["status"]));
|
|
128173
|
-
}
|
|
128174
|
-
if (expected.finalUrl) {
|
|
128175
|
-
const urls = detail?.["finalUrls"] ?? detail?.["finalurls"];
|
|
128176
|
-
const actual = Array.isArray(urls) ? urls[0] : detail?.["finalUrl"];
|
|
128177
|
-
lines.push(receiptLine("\u843D\u5730\u9875", expected.finalUrl, actual));
|
|
128178
|
-
}
|
|
128179
|
-
if (expected.countryIds && expected.countryIds.length > 0) {
|
|
128180
|
-
const expectedIds = [...expected.countryIds].map(String).sort().join(",");
|
|
128181
|
-
const actualIds = liveCountryIds ? [...liveCountryIds].map(String).sort().join(",") : void 0;
|
|
128182
|
-
lines.push(receiptLine("\u6295\u653E\u56FD\u5BB6", expectedIds, actualIds));
|
|
128183
|
-
}
|
|
128184
|
-
printWriteReceipt(detail ? judgeReceipt(lines) : "unknown", lines);
|
|
128185
|
-
}
|
|
128186
127921
|
function hasBrandImageSource(cfg, slot) {
|
|
128187
127922
|
if (slot === "logo") {
|
|
128188
127923
|
return Boolean(
|
|
@@ -128319,387 +128054,7 @@ async function buildEnableBrandGuidelinesApiBody(configFile, cfg, accountId, con
|
|
|
128319
128054
|
return body;
|
|
128320
128055
|
}
|
|
128321
128056
|
|
|
128322
|
-
// src/commands/ad/pmax-create.ts
|
|
128323
|
-
function printVideoLinkRecoveryHint(accountId, assetGroupId, campaignId, youtubeTarget) {
|
|
128324
|
-
const cid = campaignId != null ? ` --campaign-id ${campaignId}` : "";
|
|
128325
|
-
const yt = youtubeTarget ? ` --youtube "${youtubeTarget}"` : ` --video-path "<path>"`;
|
|
128326
|
-
console.error(
|
|
128327
|
-
` \u53EF\u624B\u52A8\uFF1Asiluzan-tso ad pmax-youtube-link -a ${accountId} --asset-group-id ${assetGroupId}${cid}${yt}
|
|
128328
|
-
\u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002
|
|
128329
|
-
`
|
|
128330
|
-
);
|
|
128331
|
-
}
|
|
128332
|
-
async function runAdPmaxCreate(opts) {
|
|
128333
|
-
const cfg = loadPmaxCreateConfig(opts.configFile);
|
|
128334
|
-
const rawCfg = loadPmaxCreateConfigRaw(opts.configFile) ?? {};
|
|
128335
|
-
const deprecatedVideoKeys = detectDeprecatedPmaxVideoKeys(rawCfg);
|
|
128336
|
-
const {
|
|
128337
|
-
errors: cfgErrors,
|
|
128338
|
-
warnings: cfgWarnings,
|
|
128339
|
-
lengthViolations: cfgLengthViolations
|
|
128340
|
-
} = runPmaxCreateValidation(cfg);
|
|
128341
|
-
const { errors: imgErrors, warnings: imgWarnings } = await runPmaxImageValidation(
|
|
128342
|
-
opts.configFile,
|
|
128343
|
-
cfg
|
|
128344
|
-
);
|
|
128345
|
-
const { errors: videoErrors, warnings: videoWarnings } = runPmaxVideoValidation(
|
|
128346
|
-
opts.configFile,
|
|
128347
|
-
cfg
|
|
128348
|
-
);
|
|
128349
|
-
const { errors: extErrors, warnings: extWarnings } = validatePmaxCampaignExtensions(
|
|
128350
|
-
cfg.campaignExtensions,
|
|
128351
|
-
{
|
|
128352
|
-
skipCampaignExtensions: cfg.skipCampaignExtensions,
|
|
128353
|
-
rawConfig: rawCfg
|
|
128354
|
-
}
|
|
128355
|
-
);
|
|
128356
|
-
const errors = [...deprecatedVideoKeys, ...cfgErrors, ...imgErrors, ...videoErrors, ...extErrors];
|
|
128357
|
-
const warnings = [...cfgWarnings, ...imgWarnings, ...videoWarnings, ...extWarnings];
|
|
128358
|
-
if (warnings.length > 0) {
|
|
128359
|
-
console.warn("\n\u26A0\uFE0F PMax \u914D\u7F6E\u8B66\u544A\uFF08\u4E0D\u963B\u65AD\u63D0\u4EA4\uFF09\uFF1A");
|
|
128360
|
-
for (const w of warnings) console.warn(` \u2022 ${w}`);
|
|
128361
|
-
}
|
|
128362
|
-
if (errors.length > 0) {
|
|
128363
|
-
console.error("\n\u274C PMax \u914D\u7F6E\u6821\u9A8C\u5931\u8D25\uFF1A");
|
|
128364
|
-
for (const e of errors) console.error(` \u2022 ${e}`);
|
|
128365
|
-
const lengthReport = formatLengthViolationsReport(cfgLengthViolations, {
|
|
128366
|
-
revalidateCommand: "pmax-validate"
|
|
128367
|
-
});
|
|
128368
|
-
if (lengthReport) console.error(lengthReport);
|
|
128369
|
-
console.error();
|
|
128370
|
-
process.exit(1);
|
|
128371
|
-
}
|
|
128372
|
-
const config = await ensureDataPermission(loadConfig(opts.token));
|
|
128373
|
-
const googleApiUrl = requireGoogleApi(config);
|
|
128374
|
-
const accountId = resolveAdAccountId(cfg.account.toString(), "account");
|
|
128375
|
-
cfg.account = accountId;
|
|
128376
|
-
let imageSlots;
|
|
128377
|
-
try {
|
|
128378
|
-
imageSlots = await resolvePmaxImageSlots(
|
|
128379
|
-
opts.configFile,
|
|
128380
|
-
cfg,
|
|
128381
|
-
accountId,
|
|
128382
|
-
config,
|
|
128383
|
-
googleApiUrl,
|
|
128384
|
-
{ verbose: opts.verbose, logUploads: !opts.jsonOut }
|
|
128385
|
-
);
|
|
128386
|
-
} catch (err) {
|
|
128387
|
-
console.error(`
|
|
128388
|
-
\u274C \u56FE\u7247\u4E0A\u4F20/\u89E3\u6790\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
128389
|
-
`);
|
|
128390
|
-
process.exit(1);
|
|
128391
|
-
}
|
|
128392
|
-
let body;
|
|
128393
|
-
try {
|
|
128394
|
-
body = buildPmaxCreateApiBody(cfg, imageSlots);
|
|
128395
|
-
} catch (err) {
|
|
128396
|
-
console.error(`
|
|
128397
|
-
\u274C \u6784\u5EFA\u8BF7\u6C42\u4F53\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
128398
|
-
`);
|
|
128399
|
-
process.exit(1);
|
|
128400
|
-
}
|
|
128401
|
-
const url = buildPmaxCreateUrl(googleApiUrl, accountId);
|
|
128402
|
-
let data;
|
|
128403
|
-
try {
|
|
128404
|
-
data = await apiFetch2(
|
|
128405
|
-
url,
|
|
128406
|
-
config,
|
|
128407
|
-
{ method: "POST", body: JSON.stringify(body) },
|
|
128408
|
-
opts.verbose
|
|
128409
|
-
);
|
|
128410
|
-
} catch (err) {
|
|
128411
|
-
const failure = parsePmaxCreateFailureBody(readHttpRawBody(err));
|
|
128412
|
-
if (failure) {
|
|
128413
|
-
const advice = pmaxCreateRetryAdvice(cfg, failure);
|
|
128414
|
-
console.error(`
|
|
128415
|
-
\u274C \u521B\u5EFA PMax \u5E7F\u544A\u7CFB\u5217\u5931\u8D25\uFF1A${failure.message}`);
|
|
128416
|
-
console.error(` budgetId\uFF1A${failure.budgetId ?? "null"}`);
|
|
128417
|
-
console.error(` campaignId\uFF1A${failure.campaignId ?? "null"}`);
|
|
128418
|
-
console.error(` assetGroupId\uFF1A${failure.assetGroupId ?? "null"}`);
|
|
128419
|
-
if (advice === "resume") {
|
|
128420
|
-
console.error(
|
|
128421
|
-
" \u7EED\u8DD1\uFF1A\u628A\u975E\u7A7A\u7F16\u53F7\u6309\u540C\u540D\u5199\u56DE\u8FD9\u4EFD JSON\uFF0C\u5176\u4F59\u5185\u5BB9\u4E0D\u8981\u6539\uFF0C\u518D\u6267\u884C\u4E00\u6B21 pmax-create\u3002\u7F16\u53F7\u6309\u9884\u7B97\u3001\u7CFB\u5217\u3001\u7D20\u6750\u7EC4\u5E26\u3002\u540C\u4E00\u6B65\u518D\u5931\u8D25\u5C31\u505C\u3002\n"
|
|
128422
|
-
);
|
|
128423
|
-
} else if (advice === "stop-same-step") {
|
|
128424
|
-
console.error(" \u540C\u4E00\u6B65\u518D\u5931\u8D25\uFF0C\u505C\u6B62\u3002\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002\n");
|
|
128425
|
-
} else {
|
|
128426
|
-
console.error(" \u8FD9\u6B21\u8FD8\u6CA1\u6709\u5EFA\u6210\u9884\u7B97\u3001\u7CFB\u5217\u6216\u7D20\u6750\u7EC4\u3002\u4FEE\u6B63\u539F\u56E0\u540E\u7528\u539F JSON \u518D\u63D0\u4EA4\uFF0C\u4E0D\u8981\u586B\u8FD9\u4E09\u4E2A\u7F16\u53F7\u3002\n");
|
|
128427
|
-
}
|
|
128428
|
-
await emitCliJsonOrSnapshot(opts, {
|
|
128429
|
-
section: `ad-pmax-create-${accountId}`,
|
|
128430
|
-
commandLabel: "ad pmax-create",
|
|
128431
|
-
commandHint: accountId,
|
|
128432
|
-
payload: { ok: false, retryCreate: advice === "resume", ...failure },
|
|
128433
|
-
idSuffix: accountId,
|
|
128434
|
-
summaryExtras: {
|
|
128435
|
-
ok: false,
|
|
128436
|
-
retryCreate: advice === "resume",
|
|
128437
|
-
budgetId: failure.budgetId,
|
|
128438
|
-
campaignId: failure.campaignId,
|
|
128439
|
-
assetGroupId: failure.assetGroupId
|
|
128440
|
-
}
|
|
128441
|
-
});
|
|
128442
|
-
process.exit(1);
|
|
128443
|
-
}
|
|
128444
|
-
const raw = err instanceof Error ? err.message : String(err);
|
|
128445
|
-
console.error(`
|
|
128446
|
-
\u274C \u521B\u5EFA PMax \u5E7F\u544A\u7CFB\u5217\u5931\u8D25\uFF1A${classifyPmaxCreateHttpError(raw)}
|
|
128447
|
-
`);
|
|
128448
|
-
process.exit(1);
|
|
128449
|
-
}
|
|
128450
|
-
const campaignId = data["campaignId"] ?? data["campaign_id"];
|
|
128451
|
-
const assetGroupId = data["assetGroupId"] ?? data["asset_group_id"];
|
|
128452
|
-
const budgetId = data["budgetId"] ?? data["budget_id"];
|
|
128453
|
-
const videoResult = await linkPmaxVideoAfterCreate({
|
|
128454
|
-
config,
|
|
128455
|
-
googleApiUrl,
|
|
128456
|
-
accountId,
|
|
128457
|
-
configFile: opts.configFile,
|
|
128458
|
-
cfg,
|
|
128459
|
-
campaignId,
|
|
128460
|
-
assetGroupId,
|
|
128461
|
-
verbose: opts.verbose,
|
|
128462
|
-
logProgress: !opts.jsonOut
|
|
128463
|
-
});
|
|
128464
|
-
let extensionsResult;
|
|
128465
|
-
if (campaignId != null && cfg.campaignExtensions) {
|
|
128466
|
-
if (!opts.jsonOut) {
|
|
128467
|
-
console.log("\n \u6302\u8F7D Campaign \u9644\u52A0\u8D44\u4EA7\u2026");
|
|
128468
|
-
}
|
|
128469
|
-
extensionsResult = await attachPmaxCampaignExtensions({
|
|
128470
|
-
config,
|
|
128471
|
-
googleApiUrl,
|
|
128472
|
-
accountId,
|
|
128473
|
-
campaignId: String(campaignId),
|
|
128474
|
-
extensions: cfg.campaignExtensions,
|
|
128475
|
-
verbose: opts.verbose,
|
|
128476
|
-
logProgress: !opts.jsonOut
|
|
128477
|
-
});
|
|
128478
|
-
}
|
|
128479
|
-
const payload = {
|
|
128480
|
-
...data,
|
|
128481
|
-
_brandGuidelinesEnabled: cfg.brandGuidelinesEnabled !== false,
|
|
128482
|
-
_agentBrandHint: cfg.brandGuidelinesEnabled === false ? "\u54C1\u724C\u5728 AssetGroup \u7EA7\uFF1B\u6539\u54C1\u724C\u7528 pmax-assets-update" : "\u54C1\u724C\u5728 Campaign \u7EA7 brandAssets[]\uFF1B\u6539\u54C1\u724C\u7528 pmax-brand-assets-edit\uFF1B\u8FFD\u52A0 AG \u53EF\u7701\u7565 Logo/\u5546\u5BB6\u540D",
|
|
128483
|
-
videoLink: {
|
|
128484
|
-
ok: Boolean(videoResult.youtubeLink && !videoResult.uploadError && !videoResult.linkError),
|
|
128485
|
-
youtubeTarget: videoResult.youtubeTarget,
|
|
128486
|
-
assetResourceName: videoResult.youtubeLink?.["assetResourceName"],
|
|
128487
|
-
uploadError: videoResult.uploadError,
|
|
128488
|
-
linkError: videoResult.linkError,
|
|
128489
|
-
skippedReason: videoResult.skippedReason
|
|
128490
|
-
},
|
|
128491
|
-
campaignExtensions: extensionsResult ?? {
|
|
128492
|
-
allOk: true,
|
|
128493
|
-
skippedReason: "\u672A\u914D\u7F6E campaignExtensions"
|
|
128494
|
-
}
|
|
128495
|
-
};
|
|
128496
|
-
if (videoResult.uploadError) {
|
|
128497
|
-
console.error(`
|
|
128498
|
-
\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46\u672C\u5730\u89C6\u9891\u4E0A\u4F20\u5931\u8D25\uFF1A${videoResult.uploadError}`);
|
|
128499
|
-
if (assetGroupId != null) {
|
|
128500
|
-
printVideoLinkRecoveryHint(
|
|
128501
|
-
accountId,
|
|
128502
|
-
assetGroupId,
|
|
128503
|
-
campaignId,
|
|
128504
|
-
void 0
|
|
128505
|
-
);
|
|
128506
|
-
}
|
|
128507
|
-
console.error(" \u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002\n");
|
|
128508
|
-
} else if (videoResult.linkError) {
|
|
128509
|
-
console.error(`
|
|
128510
|
-
\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46 YouTube \u94FE\u63A5\u5931\u8D25\uFF1A${videoResult.linkError}`);
|
|
128511
|
-
if (assetGroupId != null) {
|
|
128512
|
-
printVideoLinkRecoveryHint(
|
|
128513
|
-
accountId,
|
|
128514
|
-
assetGroupId,
|
|
128515
|
-
campaignId,
|
|
128516
|
-
videoResult.youtubeTarget
|
|
128517
|
-
);
|
|
128518
|
-
}
|
|
128519
|
-
console.error(" \u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002\n");
|
|
128520
|
-
} else if (videoResult.skippedReason) {
|
|
128521
|
-
console.error(`
|
|
128522
|
-
\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46\u89C6\u9891\u672A\u94FE\u63A5\uFF1A${videoResult.skippedReason}
|
|
128523
|
-
`);
|
|
128524
|
-
}
|
|
128525
|
-
if (extensionsResult && !extensionsResult.allOk) {
|
|
128526
|
-
console.error("\n\u26A0\uFE0F \u6D3B\u52A8\u5DF2\u521B\u5EFA\uFF0C\u4F46\u90E8\u5206\u9644\u52A0\u8D44\u4EA7\u6302\u8F7D\u5931\u8D25\uFF1A");
|
|
128527
|
-
for (const msg of formatPmaxExtensionsAttachErrors(extensionsResult)) {
|
|
128528
|
-
console.error(` \u2022 ${msg}`);
|
|
128529
|
-
}
|
|
128530
|
-
console.error(
|
|
128531
|
-
` \u53EF\u624B\u52A8\u8865\u6302\uFF1Asiluzan-tso ad extension callout|snippet|lead-form -a ${accountId} --campaign-id ${campaignId} \u2026
|
|
128532
|
-
\u6D3B\u52A8\u5DF2\u7ECF\u521B\u5EFA\u6210\u529F\uFF0C\u4E0D\u8981\u518D\u6267\u884C pmax-create\u3002
|
|
128533
|
-
`
|
|
128534
|
-
);
|
|
128535
|
-
} else if (extensionsResult?.allOk && extensionsResult.callouts.length + extensionsResult.structuredSnippets.length + extensionsResult.sitelinks.length + (extensionsResult.leadForm ? 1 : 0) + (extensionsResult.whatsapp ? 1 : 0) > 0) {
|
|
128536
|
-
if (!opts.jsonOut) {
|
|
128537
|
-
console.log("\n\u2705 Campaign \u9644\u52A0\u8D44\u4EA7\u5DF2\u6302\u8F7D");
|
|
128538
|
-
}
|
|
128539
|
-
}
|
|
128540
|
-
const followUpFailed = pmaxCreateFollowUpFailed({
|
|
128541
|
-
uploadError: videoResult.uploadError,
|
|
128542
|
-
linkError: videoResult.linkError,
|
|
128543
|
-
extensionsAllOk: extensionsResult ? extensionsResult.allOk : void 0
|
|
128544
|
-
});
|
|
128545
|
-
if (followUpFailed) {
|
|
128546
|
-
payload["created"] = true;
|
|
128547
|
-
payload["retryCreate"] = false;
|
|
128548
|
-
}
|
|
128549
|
-
if (campaignId != null) {
|
|
128550
|
-
let detail;
|
|
128551
|
-
try {
|
|
128552
|
-
detail = await fetchPmaxCampaignDetail(
|
|
128553
|
-
config,
|
|
128554
|
-
googleApiUrl,
|
|
128555
|
-
accountId,
|
|
128556
|
-
String(campaignId),
|
|
128557
|
-
opts.verbose
|
|
128558
|
-
);
|
|
128559
|
-
} catch {
|
|
128560
|
-
detail = void 0;
|
|
128561
|
-
}
|
|
128562
|
-
let liveCountryIds;
|
|
128563
|
-
const plannedCountries = (cfg.targetedLocations ?? []).map((loc) => String(loc.id));
|
|
128564
|
-
if (plannedCountries.length > 0) {
|
|
128565
|
-
try {
|
|
128566
|
-
const params = new URLSearchParams({
|
|
128567
|
-
startDate: toGoogleDate(void 0, -30),
|
|
128568
|
-
endDate: toGoogleDate(void 0, 0),
|
|
128569
|
-
newest: "true"
|
|
128570
|
-
});
|
|
128571
|
-
const listed = await apiFetch2(
|
|
128572
|
-
`${googleApiUrl}/campaignmanagement/v2/targetedlocations/${accountId}?${params}`,
|
|
128573
|
-
config,
|
|
128574
|
-
{},
|
|
128575
|
-
opts.verbose
|
|
128576
|
-
);
|
|
128577
|
-
liveCountryIds = (listed.data ?? []).filter((row) => String(row["campaignId"] ?? row["CampaignId"] ?? "") === String(campaignId)).map((row) => String(row["id"] ?? row["locationId"] ?? row["Id"] ?? "")).filter(Boolean);
|
|
128578
|
-
} catch {
|
|
128579
|
-
liveCountryIds = void 0;
|
|
128580
|
-
}
|
|
128581
|
-
}
|
|
128582
|
-
printPmaxWriteReceipt(
|
|
128583
|
-
{
|
|
128584
|
-
budgetYuan: cfg.budget,
|
|
128585
|
-
finalUrl: cfg.finalUrls?.[0],
|
|
128586
|
-
countryIds: plannedCountries
|
|
128587
|
-
},
|
|
128588
|
-
detail,
|
|
128589
|
-
liveCountryIds
|
|
128590
|
-
);
|
|
128591
|
-
}
|
|
128592
|
-
if (await emitCliJsonOrSnapshot(opts, {
|
|
128593
|
-
section: `ad-pmax-create-${accountId}`,
|
|
128594
|
-
commandLabel: "ad pmax-create",
|
|
128595
|
-
commandHint: accountId,
|
|
128596
|
-
payload,
|
|
128597
|
-
idSuffix: accountId,
|
|
128598
|
-
summaryExtras: followUpFailed ? { created: true, retryCreate: false } : void 0
|
|
128599
|
-
})) {
|
|
128600
|
-
return;
|
|
128601
|
-
}
|
|
128602
|
-
if (videoResult.youtubeTarget && videoResult.youtubeLink) {
|
|
128603
|
-
console.log(`
|
|
128604
|
-
\u2705 \u5DF2\u94FE\u63A5 YouTube\uFF1A${videoResult.youtubeTarget}`);
|
|
128605
|
-
const arn = videoResult.youtubeLink["assetResourceName"];
|
|
128606
|
-
if (arn != null) console.log(` assetResourceName\uFF1A${arn}`);
|
|
128607
|
-
}
|
|
128608
|
-
console.log("\n\u2705 PMax \u5E7F\u544A\u7CFB\u5217\u5DF2\u521B\u5EFA\uFF08\u540C\u6B65\uFF09");
|
|
128609
|
-
console.log(` \u6D3B\u52A8\u540D\u79F0\uFF1A${cfg.name}`);
|
|
128610
|
-
if (campaignId != null) console.log(` campaignId\uFF1A${campaignId}`);
|
|
128611
|
-
if (assetGroupId != null) console.log(` assetGroupId\uFF1A${assetGroupId}`);
|
|
128612
|
-
if (budgetId != null) console.log(` budgetId\uFF1A${budgetId}`);
|
|
128613
|
-
console.log(
|
|
128614
|
-
`
|
|
128615
|
-
\u590D\u6838\uFF1Asiluzan-tso ad campaigns -a ${accountId} --json-out # channelTypeV2 \u5E94\u4E3A PERFORMANCE_MAX`
|
|
128616
|
-
);
|
|
128617
|
-
if (!cfg.videoPath?.trim() && !cfg.youtubeUrlOrId?.trim()) {
|
|
128618
|
-
console.log(
|
|
128619
|
-
" \u89C6\u9891\uFF1A\u914D\u7F6E videoPath\uFF08\u672C\u5730\uFF09\u6216 youtubeUrlOrId \u53EF\u5728\u521B\u5EFA\u65F6\u81EA\u52A8\u94FE\u63A5\uFF1B\u6216\u521B\u5EFA\u540E ad pmax-youtube-link"
|
|
128620
|
-
);
|
|
128621
|
-
}
|
|
128622
|
-
console.log();
|
|
128623
|
-
}
|
|
128624
|
-
|
|
128625
|
-
// src/commands/ad/pmax-validate.ts
|
|
128626
|
-
import { writeFileSync as writeFileSync3 } from "fs";
|
|
128627
|
-
init_cli_json_snapshot();
|
|
128628
|
-
async function runAdPmaxValidate(opts) {
|
|
128629
|
-
const cfg = loadPmaxCreateConfig(opts.configFile);
|
|
128630
|
-
const rawCfg = loadPmaxCreateConfigRaw(opts.configFile) ?? {};
|
|
128631
|
-
const deprecatedVideoKeys = detectDeprecatedPmaxVideoKeys(rawCfg);
|
|
128632
|
-
const {
|
|
128633
|
-
errors: cfgErrors,
|
|
128634
|
-
warnings: cfgWarnings,
|
|
128635
|
-
lengthViolations: cfgLengthViolations
|
|
128636
|
-
} = runPmaxCreateValidation(cfg);
|
|
128637
|
-
const { errors: imgErrors, warnings: imgWarnings } = await runPmaxImageValidation(
|
|
128638
|
-
opts.configFile,
|
|
128639
|
-
cfg
|
|
128640
|
-
);
|
|
128641
|
-
const { errors: videoErrors, warnings: videoWarnings } = runPmaxVideoValidation(
|
|
128642
|
-
opts.configFile,
|
|
128643
|
-
cfg
|
|
128644
|
-
);
|
|
128645
|
-
const { errors: extErrors, warnings: extWarnings } = validatePmaxCampaignExtensions(
|
|
128646
|
-
cfg.campaignExtensions,
|
|
128647
|
-
{
|
|
128648
|
-
skipCampaignExtensions: cfg.skipCampaignExtensions,
|
|
128649
|
-
rawConfig: rawCfg
|
|
128650
|
-
}
|
|
128651
|
-
);
|
|
128652
|
-
const errors = [...deprecatedVideoKeys, ...cfgErrors, ...imgErrors, ...videoErrors, ...extErrors];
|
|
128653
|
-
const warnings = [...cfgWarnings, ...imgWarnings, ...videoWarnings, ...extWarnings];
|
|
128654
|
-
const lengthViolations = cfgLengthViolations;
|
|
128655
|
-
if (opts.writeNormalized) {
|
|
128656
|
-
const toWrite = stripMetaKeysForExport(cfg);
|
|
128657
|
-
writeFileSync3(opts.writeNormalized, `${JSON.stringify(toWrite, null, 2)}
|
|
128658
|
-
`, "utf8");
|
|
128659
|
-
}
|
|
128660
|
-
const payload = {
|
|
128661
|
-
ok: errors.length === 0,
|
|
128662
|
-
configFile: opts.configFile,
|
|
128663
|
-
account: cfg.account?.toString().trim() || void 0,
|
|
128664
|
-
errors,
|
|
128665
|
-
warnings,
|
|
128666
|
-
lengthViolations,
|
|
128667
|
-
agentHint: lengthViolations.length > 0 ? lengthViolationAgentHint("pmax-validate") : void 0
|
|
128668
|
-
};
|
|
128669
|
-
const accountSuffix = payload.account;
|
|
128670
|
-
if (await emitCliJsonOrSnapshot(opts, {
|
|
128671
|
-
section: "ad-pmax-validate",
|
|
128672
|
-
commandLabel: "ad pmax-validate",
|
|
128673
|
-
commandHint: opts.configFile,
|
|
128674
|
-
payload,
|
|
128675
|
-
idSuffix: accountSuffix
|
|
128676
|
-
})) {
|
|
128677
|
-
if (!payload.ok) process.exit(1);
|
|
128678
|
-
return;
|
|
128679
|
-
}
|
|
128680
|
-
if (warnings.length > 0) {
|
|
128681
|
-
console.warn("\n\u26A0\uFE0F PMax \u914D\u7F6E\u8B66\u544A\uFF1A");
|
|
128682
|
-
for (const w of warnings) console.warn(` \u2022 ${w}`);
|
|
128683
|
-
}
|
|
128684
|
-
if (errors.length > 0) {
|
|
128685
|
-
console.error("\n\u274C PMax \u914D\u7F6E\u6821\u9A8C\u5931\u8D25\uFF1A");
|
|
128686
|
-
for (const e of errors) console.error(` \u2022 ${e}`);
|
|
128687
|
-
const lengthReport = formatLengthViolationsReport(lengthViolations, {
|
|
128688
|
-
revalidateCommand: "pmax-validate"
|
|
128689
|
-
});
|
|
128690
|
-
if (lengthReport) console.error(lengthReport);
|
|
128691
|
-
console.error();
|
|
128692
|
-
process.exit(1);
|
|
128693
|
-
}
|
|
128694
|
-
console.log("\n\u2705 PMax \u914D\u7F6E\u6821\u9A8C\u901A\u8FC7");
|
|
128695
|
-
if (opts.writeNormalized) {
|
|
128696
|
-
console.log(` \u5DF2\u5199\u5165\uFF1A${opts.writeNormalized}`);
|
|
128697
|
-
}
|
|
128698
|
-
console.log();
|
|
128699
|
-
}
|
|
128700
|
-
|
|
128701
128057
|
// src/commands/ad/pmax-mgmt.ts
|
|
128702
|
-
import { basename as basename7, isAbsolute as isAbsolute6 } from "path";
|
|
128703
128058
|
init_shared();
|
|
128704
128059
|
function buildReportQuery(opts) {
|
|
128705
128060
|
const params = new URLSearchParams();
|
|
@@ -128874,22 +128229,6 @@ async function runAdPmaxEdit(opts) {
|
|
|
128874
128229
|
);
|
|
128875
128230
|
process.exit(1);
|
|
128876
128231
|
}
|
|
128877
|
-
let detail;
|
|
128878
|
-
try {
|
|
128879
|
-
detail = await fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaignId, opts.verbose);
|
|
128880
|
-
} catch {
|
|
128881
|
-
detail = void 0;
|
|
128882
|
-
}
|
|
128883
|
-
const budgetCents = body["budget"];
|
|
128884
|
-
const finalUrls = body["finalUrls"];
|
|
128885
|
-
printPmaxWriteReceipt(
|
|
128886
|
-
{
|
|
128887
|
-
budgetYuan: typeof budgetCents === "number" ? budgetCents / 100 : void 0,
|
|
128888
|
-
status: body["statusV2"] != null ? String(body["statusV2"]) : void 0,
|
|
128889
|
-
finalUrl: Array.isArray(finalUrls) ? String(finalUrls[0] ?? "") : void 0
|
|
128890
|
-
},
|
|
128891
|
-
detail
|
|
128892
|
-
);
|
|
128893
128232
|
if (await emitPmaxResult(
|
|
128894
128233
|
{ ...opts, account: accountId },
|
|
128895
128234
|
`ad-pmax-edit-${accountId}`,
|
|
@@ -129707,7 +129046,7 @@ async function loadSharp() {
|
|
|
129707
129046
|
}
|
|
129708
129047
|
}
|
|
129709
129048
|
async function convertOne(sharpFn, inputPath, outputPath, spec, quality) {
|
|
129710
|
-
let
|
|
129049
|
+
let pipeline2 = sharpFn(inputPath).resize(spec.width, spec.height, {
|
|
129711
129050
|
fit: spec.fit,
|
|
129712
129051
|
position: "centre",
|
|
129713
129052
|
background: { r: 255, g: 255, b: 255, alpha: 1 },
|
|
@@ -129715,11 +129054,11 @@ async function convertOne(sharpFn, inputPath, outputPath, spec, quality) {
|
|
|
129715
129054
|
});
|
|
129716
129055
|
const ext = extname(outputPath).toLowerCase();
|
|
129717
129056
|
if (ext === ".png") {
|
|
129718
|
-
|
|
129057
|
+
pipeline2 = pipeline2.png({ compressionLevel: 6 });
|
|
129719
129058
|
} else {
|
|
129720
|
-
|
|
129059
|
+
pipeline2 = pipeline2.jpeg({ quality, mozjpeg: true });
|
|
129721
129060
|
}
|
|
129722
|
-
await
|
|
129061
|
+
await pipeline2.toFile(outputPath);
|
|
129723
129062
|
}
|
|
129724
129063
|
async function runAdPmaxImageConvert(opts) {
|
|
129725
129064
|
const { input, inputMarketing, inputSquare, inputLogo } = opts;
|
|
@@ -130139,35 +129478,6 @@ function budgetYuan(item) {
|
|
|
130139
129478
|
const yuan = toDisplayMoney(typeof raw === "number" ? raw : Number(raw));
|
|
130140
129479
|
return yuan == null ? "" : String(yuan);
|
|
130141
129480
|
}
|
|
130142
|
-
async function printSharedBudgetReceipt(opts, expected) {
|
|
130143
|
-
try {
|
|
130144
|
-
const listed = await listBudgets(opts);
|
|
130145
|
-
const item = expected.id ? listed.items.find((row) => field5(row, "id", "Id") === expected.id) : listed.items.find((row) => field5(row, "name", "Name") === (expected.name ?? ""));
|
|
130146
|
-
if (expected.gone) {
|
|
130147
|
-
printWriteReceipt(item ? "partial" : "verified", [
|
|
130148
|
-
receiptLine("\u5171\u4EAB\u9884\u7B97", "\u5DF2\u5220\u9664", item ? "\u4ECD\u5728" : "\u5DF2\u5220\u9664")
|
|
130149
|
-
]);
|
|
130150
|
-
return;
|
|
130151
|
-
}
|
|
130152
|
-
const lines = [];
|
|
130153
|
-
if (expected.name) {
|
|
130154
|
-
lines.push(receiptLine("\u540D\u79F0", expected.name, item ? field5(item, "name", "Name") : void 0));
|
|
130155
|
-
}
|
|
130156
|
-
if (expected.amountYuan != null) {
|
|
130157
|
-
const read = item ? Number(budgetYuan(item)) : void 0;
|
|
130158
|
-
lines.push(
|
|
130159
|
-
receiptLine(
|
|
130160
|
-
"\u65E5\u9884\u7B97",
|
|
130161
|
-
yuanLabel(expected.amountYuan),
|
|
130162
|
-
read != null && Number.isFinite(read) ? yuanLabel(read) : void 0
|
|
130163
|
-
)
|
|
130164
|
-
);
|
|
130165
|
-
}
|
|
130166
|
-
printWriteReceipt(item ? judgeReceipt(lines) : "unknown", lines);
|
|
130167
|
-
} catch {
|
|
130168
|
-
printWriteReceipt("unknown", [receiptLine("\u5171\u4EAB\u9884\u7B97", expected.gone ? "\u5DF2\u5220\u9664" : "\u5DF2\u5199\u5165", void 0)]);
|
|
130169
|
-
}
|
|
130170
|
-
}
|
|
130171
129481
|
async function runAdSharedBudgetList(opts) {
|
|
130172
129482
|
let items3;
|
|
130173
129483
|
let account = opts.account;
|
|
@@ -130223,7 +129533,6 @@ async function runAdSharedBudgetCreate(opts) {
|
|
|
130223
129533
|
} catch (err) {
|
|
130224
129534
|
fail3(err, "\u521B\u5EFA\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
130225
129535
|
}
|
|
130226
|
-
await printSharedBudgetReceipt(opts, { name: name2, amountYuan: opts.amount });
|
|
130227
129536
|
console.log(`
|
|
130228
129537
|
\u2705 \u5DF2\u521B\u5EFA\u5171\u4EAB\u9884\u7B97\u300C${name2}\u300D\uFF0C\u65E5\u9884\u7B97 ${opts.amount}\u3002\u628A\u7CFB\u5217\u6302\u5230\u5B83\u4E0A\u9762\u9700\u8981\u7CFB\u5217\u7F16\u8F91\u91CC\u7684\u9884\u7B97 id\uFF0C\u672C\u547D\u4EE4\u4E0D\u6539\u5DF2\u6709\u7CFB\u5217\u3002
|
|
130229
129538
|
`);
|
|
@@ -130264,15 +129573,29 @@ async function runAdSharedBudgetUpdate(opts) {
|
|
|
130264
129573
|
} catch (err) {
|
|
130265
129574
|
fail3(err, "\u4FEE\u6539\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
130266
129575
|
}
|
|
130267
|
-
await printSharedBudgetReceipt(opts, {
|
|
130268
|
-
id: budgetId,
|
|
130269
|
-
name: name2,
|
|
130270
|
-
amountYuan: amountCents / 100
|
|
130271
|
-
});
|
|
130272
129576
|
console.log(`
|
|
130273
129577
|
\u2705 \u5DF2\u4FEE\u6539\u5171\u4EAB\u9884\u7B97 ${budgetId}\u300C${name2}\u300D\u3002\u540C\u4E00\u9884\u7B97\u4E0B\u7684\u7CFB\u5217\u4F1A\u4E00\u8D77\u53D8\u3002
|
|
130274
129578
|
`);
|
|
130275
129579
|
}
|
|
129580
|
+
function sharedBudgetAttachUrl(base2, account, campaignId, budgetId) {
|
|
129581
|
+
return `${base2}/campaignmanagement/campaign/${account}/${campaignId}/shared-budget/${budgetId}`;
|
|
129582
|
+
}
|
|
129583
|
+
async function runAdSharedBudgetAttach(opts) {
|
|
129584
|
+
const campaignId = (opts.campaignId ?? "").trim();
|
|
129585
|
+
const budgetId = (opts.budgetId ?? "").trim();
|
|
129586
|
+
if (!/^\d+$/.test(campaignId)) fail3(new Error("--campaign-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
129587
|
+
if (!/^\d+$/.test(budgetId)) fail3(new Error("--budget-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
129588
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
129589
|
+
const url = sharedBudgetAttachUrl(base2, account, campaignId, budgetId);
|
|
129590
|
+
try {
|
|
129591
|
+
await apiFetch2(url, config, { method: "POST" }, opts.verbose);
|
|
129592
|
+
} catch (err) {
|
|
129593
|
+
fail3(err, "\u628A\u7CFB\u5217\u6302\u5230\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
129594
|
+
}
|
|
129595
|
+
console.log(`
|
|
129596
|
+
\u2705 \u7CFB\u5217 ${campaignId} \u5DF2\u6539\u6302\u5230\u9884\u7B97 ${budgetId}\u3002\u91D1\u989D\u6CA1\u6709\u6539\u3002Demand Gen \u4F1A\u88AB\u62D2\u7EDD\u3002
|
|
129597
|
+
`);
|
|
129598
|
+
}
|
|
130276
129599
|
async function runAdSharedBudgetDelete(opts) {
|
|
130277
129600
|
const budgetId = (opts.budgetId ?? "").trim();
|
|
130278
129601
|
if (!/^\d+$/.test(budgetId)) fail3(new Error("--budget-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
@@ -130284,7 +129607,6 @@ async function runAdSharedBudgetDelete(opts) {
|
|
|
130284
129607
|
} catch (err) {
|
|
130285
129608
|
fail3(err, "\u5220\u9664\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
130286
129609
|
}
|
|
130287
|
-
await printSharedBudgetReceipt(opts, { id: budgetId, gone: true });
|
|
130288
129610
|
console.log(`
|
|
130289
129611
|
\u2705 \u5DF2\u5220\u9664\u5171\u4EAB\u9884\u7B97 ${budgetId}\u3002\u4ECD\u88AB\u7CFB\u5217\u4F7F\u7528\u65F6 Google \u4F1A\u62D2\u7EDD\uFF0C\u8FD9\u4E0D\u662F CLI \u91CD\u8BD5\u80FD\u89E3\u51B3\u7684\u3002
|
|
130290
129612
|
`);
|
|
@@ -130384,9 +129706,6 @@ async function runAdScheduleReplace(opts) {
|
|
|
130384
129706
|
);
|
|
130385
129707
|
}
|
|
130386
129708
|
|
|
130387
|
-
// src/commands/ad/demand-gen.ts
|
|
130388
|
-
init_shared();
|
|
130389
|
-
|
|
130390
129709
|
// src/commands/ad/demand-gen-body.ts
|
|
130391
129710
|
init_shared();
|
|
130392
129711
|
var WRITE_CENT_KEYS = ["budget", "targetCpa_BidingAmount", "currencyMinimumBudget"];
|
|
@@ -130622,6 +129941,7 @@ function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDat
|
|
|
130622
129941
|
}
|
|
130623
129942
|
|
|
130624
129943
|
// src/commands/ad/demand-gen.ts
|
|
129944
|
+
init_shared();
|
|
130625
129945
|
var MONEY_HINT = "budget / targetCpa_BidingAmount / minimumDailyBudget \u662F\u5206\uFF08500 = 5 \u5143\uFF09\u3002\u770B\u65C1\u8FB9\u7684 *Yuan\u3002\u5199\u5165 --budget / JSON \u586B\u5143\uFF1B\u82E5\u540C\u65F6\u6709 *Yuan\uFF0C\u4EE5 Yuan \u4E3A\u51C6\u3002targetRoas \u662F\u6BD4\u7387\u3002\u62A5\u8868 spend \u5DF2\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u4E0D\u8981\u62FF\u53BB\u5F53\u9884\u7B97\u3002";
|
|
130626
129946
|
function fail4(message) {
|
|
130627
129947
|
console.error(`
|
|
@@ -130629,73 +129949,6 @@ function fail4(message) {
|
|
|
130629
129949
|
`);
|
|
130630
129950
|
process.exit(1);
|
|
130631
129951
|
}
|
|
130632
|
-
async function readLocationIds(config, googleApiUrl, accountId, campaignId, verbose) {
|
|
130633
|
-
try {
|
|
130634
|
-
const params = new URLSearchParams({
|
|
130635
|
-
startDate: toGoogleDate(void 0, -30),
|
|
130636
|
-
endDate: toGoogleDate(void 0, 0),
|
|
130637
|
-
newest: "true"
|
|
130638
|
-
});
|
|
130639
|
-
const listed = await pmaxApiFetch(
|
|
130640
|
-
`${googleApiUrl}/campaignmanagement/v2/targetedlocations/${accountId}?${params}`,
|
|
130641
|
-
config,
|
|
130642
|
-
{},
|
|
130643
|
-
verbose
|
|
130644
|
-
);
|
|
130645
|
-
const rows = listed && typeof listed === "object" && Array.isArray(listed.data) ? listed.data : [];
|
|
130646
|
-
return rows.filter((row) => String(row["campaignId"] ?? "") === campaignId).map((row) => String(row["id"] ?? row["locationId"] ?? "")).filter(Boolean);
|
|
130647
|
-
} catch {
|
|
130648
|
-
return void 0;
|
|
130649
|
-
}
|
|
130650
|
-
}
|
|
130651
|
-
function plannedLocationIds2(value) {
|
|
130652
|
-
if (!Array.isArray(value)) return [];
|
|
130653
|
-
return value.map((item) => {
|
|
130654
|
-
if (typeof item === "string" || typeof item === "number") return String(item);
|
|
130655
|
-
if (item && typeof item === "object") {
|
|
130656
|
-
const id = item["id"] ?? item["Id"];
|
|
130657
|
-
return id == null ? "" : String(id);
|
|
130658
|
-
}
|
|
130659
|
-
return "";
|
|
130660
|
-
}).filter(Boolean);
|
|
130661
|
-
}
|
|
130662
|
-
async function printDemandGenCampaignReceipt(config, googleApiUrl, accountId, campaignId, expected, verbose) {
|
|
130663
|
-
let detail;
|
|
130664
|
-
try {
|
|
130665
|
-
detail = asRecord5(
|
|
130666
|
-
decorateDemandGenRead(
|
|
130667
|
-
await pmaxApiFetch(demandGenCampaignUrl(googleApiUrl, accountId, campaignId), config, {}, verbose)
|
|
130668
|
-
)
|
|
130669
|
-
);
|
|
130670
|
-
} catch {
|
|
130671
|
-
detail = void 0;
|
|
130672
|
-
}
|
|
130673
|
-
const lines = [];
|
|
130674
|
-
if (expected.budgetCents != null) {
|
|
130675
|
-
const actual = typeof detail?.["budgetYuan"] === "number" ? detail["budgetYuan"] : void 0;
|
|
130676
|
-
lines.push(
|
|
130677
|
-
receiptLine(
|
|
130678
|
-
"\u65E5\u9884\u7B97",
|
|
130679
|
-
yuanLabel(expected.budgetCents / 100),
|
|
130680
|
-
actual == null ? void 0 : yuanLabel(actual)
|
|
130681
|
-
)
|
|
130682
|
-
);
|
|
130683
|
-
}
|
|
130684
|
-
if (expected.status) {
|
|
130685
|
-
lines.push(receiptLine("\u72B6\u6001", expected.status, detail?.["statusV2"]));
|
|
130686
|
-
}
|
|
130687
|
-
if (expected.countryIds && expected.countryIds.length > 0) {
|
|
130688
|
-
const live = detail ? await readLocationIds(config, googleApiUrl, accountId, campaignId, verbose) : void 0;
|
|
130689
|
-
lines.push(
|
|
130690
|
-
receiptLine(
|
|
130691
|
-
"\u6295\u653E\u56FD\u5BB6",
|
|
130692
|
-
[...expected.countryIds].sort().join(","),
|
|
130693
|
-
live ? [...live].sort().join(",") : void 0
|
|
130694
|
-
)
|
|
130695
|
-
);
|
|
130696
|
-
}
|
|
130697
|
-
printWriteReceipt(detail ? judgeReceipt(lines) : "unknown", lines);
|
|
130698
|
-
}
|
|
130699
129952
|
function asRecord5(value) {
|
|
130700
129953
|
return value && typeof value === "object" && !Array.isArray(value) ? value : { data: value };
|
|
130701
129954
|
}
|
|
@@ -130809,27 +130062,6 @@ async function postCreate(opts, path61, commandLabel) {
|
|
|
130809
130062
|
fail4(explainCreateError(err));
|
|
130810
130063
|
}
|
|
130811
130064
|
const payload = decorateDemandGenRead(data);
|
|
130812
|
-
if (path61 !== "validate") {
|
|
130813
|
-
const created = asRecord5(payload);
|
|
130814
|
-
const createdId = String(created["id"] ?? created["campaignId"] ?? "");
|
|
130815
|
-
const countries = plannedLocationIds2(body["targetedLocations"]);
|
|
130816
|
-
if (createdId) {
|
|
130817
|
-
await printDemandGenCampaignReceipt(
|
|
130818
|
-
config,
|
|
130819
|
-
googleApiUrl,
|
|
130820
|
-
accountId,
|
|
130821
|
-
createdId,
|
|
130822
|
-
{
|
|
130823
|
-
budgetCents: typeof body["budget"] === "number" ? body["budget"] : void 0,
|
|
130824
|
-
status: "Paused",
|
|
130825
|
-
countryIds: countries
|
|
130826
|
-
},
|
|
130827
|
-
opts.verbose
|
|
130828
|
-
);
|
|
130829
|
-
} else {
|
|
130830
|
-
printWriteReceipt("unknown", [receiptLine("\u7CFB\u5217", "\u5DF2\u521B\u5EFA", void 0)]);
|
|
130831
|
-
}
|
|
130832
|
-
}
|
|
130833
130065
|
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path61 || "create"}`, commandLabel, payload, accountId)) {
|
|
130834
130066
|
return;
|
|
130835
130067
|
}
|
|
@@ -131066,18 +130298,6 @@ async function runDemandGenEdit(opts) {
|
|
|
131066
130298
|
} catch (err) {
|
|
131067
130299
|
fail4(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
131068
130300
|
}
|
|
131069
|
-
await printDemandGenCampaignReceipt(
|
|
131070
|
-
config,
|
|
131071
|
-
googleApiUrl,
|
|
131072
|
-
accountId,
|
|
131073
|
-
campaignId,
|
|
131074
|
-
{
|
|
131075
|
-
budgetCents: typeof body["budget"] === "number" ? body["budget"] : void 0,
|
|
131076
|
-
status: typeof body["statusV2"] === "string" ? body["statusV2"] : void 0,
|
|
131077
|
-
countryIds: plannedLocationIds2(body["targetedLocations"])
|
|
131078
|
-
},
|
|
131079
|
-
opts.verbose
|
|
131080
|
-
);
|
|
131081
130301
|
const payload = { ok: true, campaignId, patch: body };
|
|
131082
130302
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-edit", "ad demand-gen edit", payload, campaignId)) {
|
|
131083
130303
|
return;
|
|
@@ -131181,16 +130401,6 @@ async function putStatus(opts, kind) {
|
|
|
131181
130401
|
} catch (err) {
|
|
131182
130402
|
fail4(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
131183
130403
|
}
|
|
131184
|
-
let readStatus;
|
|
131185
|
-
try {
|
|
131186
|
-
const readUrl2 = url.replace(/\/status$/, "");
|
|
131187
|
-
const raw = asRecord5(await pmaxApiFetch(readUrl2, config, {}, opts.verbose));
|
|
131188
|
-
readStatus = raw["status"] ?? raw["statusV2"];
|
|
131189
|
-
} catch {
|
|
131190
|
-
readStatus = void 0;
|
|
131191
|
-
}
|
|
131192
|
-
const lines = [receiptLine("\u72B6\u6001", status, readStatus)];
|
|
131193
|
-
printWriteReceipt(readStatus === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
131194
130404
|
console.log(`
|
|
131195
130405
|
\u2705 \u5DF2\u8BBE\u4E3A ${status}\u3002\u7CFB\u5217\u72B6\u6001\u4E0D\u4F1A\u8DDF\u7740\u53D8\u3002
|
|
131196
130406
|
`);
|
|
@@ -132389,7 +131599,7 @@ function register21(program2) {
|
|
|
132389
131599
|
verbose: opts.verbose
|
|
132390
131600
|
});
|
|
132391
131601
|
});
|
|
132392
|
-
adCmd.command("campaign-edit").description("\u7F16\u8F91\u641C\u7D22\u5E7F\u544A\u7CFB\u5217\u3002\u540D\u79F0\u3001\u9884\u7B97\u3001\u51FA\u4EF7\u3001\u6295\u653E\u7F51\u7EDC\u3001\u4F4D\u7F6E\u9009\u9879\u90FD\u8D70\u5B57\u6BB5\u7EA7 PATCH\u3002\u81F3\u5C11\u4F20\u4E00\u4E2A\u4FEE\u6539\u9879").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--id <campaignId>", "\u5E7F\u544A\u7CFB\u5217 ID").option("--name <name>", "\u65B0\u540D\u79F0").option(
|
|
131602
|
+
adCmd.command("campaign-edit").description("\u7F16\u8F91\u641C\u7D22\u5E7F\u544A\u7CFB\u5217\u3002\u540D\u79F0\u3001\u9884\u7B97\u3001\u51FA\u4EF7\u3001\u6295\u653E\u7F51\u7EDC\u3001\u4F4D\u7F6E\u9009\u9879\u3001\u53D7\u4F17\u89C2\u5BDF/\u5B9A\u5411\u90FD\u8D70\u5B57\u6BB5\u7EA7 PATCH\u3002\u81F3\u5C11\u4F20\u4E00\u4E2A\u4FEE\u6539\u9879").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--id <campaignId>", "\u5E7F\u544A\u7CFB\u5217 ID").option("--name <name>", "\u65B0\u540D\u79F0").option(
|
|
132393
131603
|
"--budget <amount>",
|
|
132394
131604
|
"\u65B0\u9884\u7B97\uFF0C\u4E3B\u5E01\u79CD\u91D1\u989D\uFF08\u5982 100 \u8868\u793A \xA5100\uFF1B\u652F\u6301\u5C0F\u6570\uFF1BCLI \u5185\u90E8\u81EA\u52A8 \xD7100 \u5199\u5165\u300C\u5206\u300D\u5B57\u6BB5\uFF09",
|
|
132395
131605
|
parseFloat
|
|
@@ -132422,6 +131632,9 @@ function register21(program2) {
|
|
|
132422
131632
|
).option(
|
|
132423
131633
|
"--negative-geo-target-type <type>",
|
|
132424
131634
|
"\u4F4D\u7F6E\u9009\u9879\uFF08\u6392\u9664\uFF09\uFF1Apresence\uFF08\u6392\u9664\u8EAB\u5904\u8BE5\u5730\u7684\u4EBA\uFF09| presence-or-interest\uFF08\u8EAB\u5904\u6216\u5173\u6CE8\u8BE5\u5730\u7684\u4EBA\u90FD\u6392\u9664\uFF09"
|
|
131635
|
+
).option(
|
|
131636
|
+
"--audience-targeting <mode>",
|
|
131637
|
+
"\u641C\u7D22\u53D7\u4F17\uFF1AObservation\uFF08\u89C2\u5BDF\uFF0C\u4ECD\u53EF\u6295\u7ED9\u5176\u4ED6\u4EBA\uFF09| Targeting\uFF08\u5B9A\u5411\uFF0C\u53EA\u6295\u7ED9\u5DF2\u52A0\u7684\u53D7\u4F17\uFF09\u3002\u975E\u641C\u7D22\u7CFB\u5217\u62D2\u7EDD"
|
|
132425
131638
|
).option("--json-out <path>", "\u843D\u76D8\u6838\u9A8C\u7ED3\u679C\uFF08writeScope=search-field-patch\uFF09").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
132426
131639
|
async (opts) => {
|
|
132427
131640
|
await runAdCampaignEdit({
|
|
@@ -132439,6 +131652,7 @@ function register21(program2) {
|
|
|
132439
131652
|
targetContentNetwork: opts.contentNetwork,
|
|
132440
131653
|
geoTargetType: opts.geoTargetType,
|
|
132441
131654
|
negativeGeoTargetType: opts.negativeGeoTargetType,
|
|
131655
|
+
audienceTargeting: opts.audienceTargeting,
|
|
132442
131656
|
jsonOut: opts.jsonOut,
|
|
132443
131657
|
verbose: opts.verbose
|
|
132444
131658
|
});
|
|
@@ -133006,21 +132220,21 @@ function register21(program2) {
|
|
|
133006
132220
|
}
|
|
133007
132221
|
function registerAccountOps(adCmd) {
|
|
133008
132222
|
const exclusions = adCmd.command("exclusions").description(
|
|
133009
|
-
"\u8D26\u6237\u7EA7\u5185\u5BB9\u9002\u5B9C\u6027\u6392\u9664\uFF08\u654F\u611F\u5185\u5BB9\u3001\u7C7B\u578B\u548C\u6807\u7B7E\u3001\u5185\u5BB9\u4E3B\u9898\u3001\u7F51\u7AD9\u3001YouTube\u3001\u5E94\u7528\u3001\u5E94\u7528\u7C7B\u522B\uFF09\u3002\u5168\u8D26\u6237\u751F\u6548\u3002\u4E0D\u662F\u5C55\u793A\u5E7F\u544A\u521B\u5EFA\uFF0C\u4E5F\u4E0D\u662F\u641C\u7D22\u5426\u8BCD\u6216\u5185\u5BB9\u5173\u952E\u5B57"
|
|
132223
|
+
"\u8D26\u6237\u7EA7\u5185\u5BB9\u9002\u5B9C\u6027\u6392\u9664\uFF08\u654F\u611F\u5185\u5BB9\u3001\u7C7B\u578B\u548C\u6807\u7B7E\u3001\u5185\u5BB9\u4E3B\u9898\u3001\u7F51\u7AD9\u3001YouTube\u3001\u5E94\u7528\u3001\u5E94\u7528\u7C7B\u522B\uFF09\u3002user-list \u4F1A\u5728\u7F51\u5173\u62D2\u7EDD\uFF1A\u5BA2\u6237\u7EA7\u5426\u5B9A\u51C6\u5219\u6CA1\u6709\u7528\u6237\u5217\u8868\u5B57\u6BB5\u3002\u5168\u8D26\u6237\u751F\u6548\u3002\u4E0D\u662F\u5C55\u793A\u5E7F\u544A\u521B\u5EFA\uFF0C\u4E5F\u4E0D\u662F\u641C\u7D22\u5426\u8BCD\u6216\u5185\u5BB9\u5173\u952E\u5B57"
|
|
133010
132224
|
);
|
|
133011
132225
|
exclusions.command("list").description("\u5217\u51FA\u5DF2\u751F\u6548\u7684\u8D26\u6237\u7EA7\u5185\u5BB9\u6392\u9664").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option(
|
|
133012
132226
|
"--type <type>",
|
|
133013
|
-
"content-label | placement | youtube-channel | youtube-video | app | app-category"
|
|
132227
|
+
"content-label | placement | youtube-channel | youtube-video | app | app-category | user-list"
|
|
133014
132228
|
).option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
133015
132229
|
await runAdExclusionsList(opts);
|
|
133016
132230
|
});
|
|
133017
132231
|
exclusions.command("add").description("\u6DFB\u52A0\u4E00\u6761\u8D26\u6237\u7EA7\u6392\u9664\u3002\u4E00\u6B21\u4E00\u79CD\u7C7B\u578B\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list\uFF0C\u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption(
|
|
133018
132232
|
"--type <type>",
|
|
133019
|
-
"content-label | placement | youtube-channel | youtube-video | app | app-category"
|
|
132233
|
+
"content-label | placement | youtube-channel | youtube-video | app | app-category | user-list"
|
|
133020
132234
|
).option(
|
|
133021
132235
|
"--content-label <name>",
|
|
133022
132236
|
"\u5185\u5BB9\u6807\u7B7E proto \u540D\uFF0C\u6765\u81EA content-labels\uFF0C\u5982 BRAND_SUITABILITY_GAMES_FIGHTING"
|
|
133023
|
-
).option("--url <url>", "\u8981\u6392\u9664\u7684\u7F51\u7AD9").option("--channel-id <id>", "YouTube \u9891\u9053 ID").option("--video-id <id>", "YouTube \u89C6\u9891 ID").option("--app-id <id>", "\u5E94\u7528 ID\uFF1A1-\u6570\u5B57 \u6216 2-\u5305\u540D").option("--app-category-id <id>", "\u5E94\u7528\u7C7B\u522B\u6570\u5B57 id\uFF0C\u6765\u81EA app-categories").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
132237
|
+
).option("--url <url>", "\u8981\u6392\u9664\u7684\u7F51\u7AD9").option("--channel-id <id>", "YouTube \u9891\u9053 ID").option("--video-id <id>", "YouTube \u89C6\u9891 ID").option("--app-id <id>", "\u5E94\u7528 ID\uFF1A1-\u6570\u5B57 \u6216 2-\u5305\u540D").option("--app-category-id <id>", "\u5E94\u7528\u7C7B\u522B\u6570\u5B57 id\uFF0C\u6765\u81EA app-categories").option("--user-list-id <id>", "\u5DF2\u6709\u7528\u6237\u5217\u8868\u7684\u6570\u5B57 id\u3002\u4E0D\u4E0A\u4F20\u540D\u5355").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
133024
132238
|
await runAdExclusionsAdd({
|
|
133025
132239
|
token: opts.token,
|
|
133026
132240
|
account: opts.account,
|
|
@@ -133031,6 +132245,7 @@ function registerAccountOps(adCmd) {
|
|
|
133031
132245
|
videoId: opts.videoId,
|
|
133032
132246
|
appId: opts.appId,
|
|
133033
132247
|
appCategoryId: opts.appCategoryId,
|
|
132248
|
+
userListId: opts.userListId,
|
|
133034
132249
|
jsonOut: opts.jsonOut,
|
|
133035
132250
|
verbose: opts.verbose
|
|
133036
132251
|
});
|
|
@@ -133150,6 +132365,9 @@ function registerProtection(adCmd) {
|
|
|
133150
132365
|
sharedBudget.command("update").description("\u6539\u4E00\u4EFD\u5171\u4EAB\u9884\u7B97\u7684\u540D\u79F0\u6216\u91D1\u989D\u3002\u540C\u4E00\u9884\u7B97\u4E0B\u7684\u7CFB\u5217\u4F1A\u4E00\u8D77\u53D8\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--budget-id <id>", "list \u91CC\u7684 id").option("--name <name>", "\u65B0\u540D\u79F0\uFF0C\u4E0D\u4F20\u5219\u4FDD\u6301\u539F\u540D").option("--amount <yuan>", "\u65B0\u65E5\u9884\u7B97\uFF0C\u4E3B\u5E01\u79CD\u5143", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
133151
132366
|
await runAdSharedBudgetUpdate(opts);
|
|
133152
132367
|
});
|
|
132368
|
+
sharedBudget.command("attach").description("\u628A\u5DF2\u6709\u7CFB\u5217\u6539\u6302\u5230\u4E00\u4EFD\u5171\u4EAB\u9884\u7B97\u3002\u4E0D\u6539\u91D1\u989D\u3002Demand Gen \u4F1A\u62D2\u7EDD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "\u8981\u6539\u6302\u7684\u7CFB\u5217 id").requiredOption("--budget-id <id>", "list \u91CC\u7684\u5171\u4EAB\u9884\u7B97 id").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
132369
|
+
await runAdSharedBudgetAttach(opts);
|
|
132370
|
+
});
|
|
133153
132371
|
sharedBudget.command("delete").description("\u5220\u9664\u5171\u4EAB\u9884\u7B97\u3002\u987B --i-confirm\u3002\u4ECD\u88AB\u7CFB\u5217\u4F7F\u7528\u65F6 Google \u4F1A\u62D2\u7EDD").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--budget-id <id>", "list \u91CC\u7684 id").option("--i-confirm", "\u7528\u6237\u5DF2\u786E\u8BA4\u5220\u9664", false).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
133154
132372
|
await runAdSharedBudgetDelete(opts);
|
|
133155
132373
|
});
|
|
@@ -133889,52 +133107,6 @@ function formHasPredefinedQuestion(form) {
|
|
|
133889
133107
|
return (form.questions ?? []).some((q) => isPredefinedQuestionType(q.type));
|
|
133890
133108
|
}
|
|
133891
133109
|
|
|
133892
|
-
// src/commands/meta-ad/readback.ts
|
|
133893
|
-
init_auth();
|
|
133894
|
-
async function tryReadMeta(facebookApiUrl, account, path61, config, verbose) {
|
|
133895
|
-
try {
|
|
133896
|
-
const data = await apiFetch2(adsUrl(facebookApiUrl, account, path61), config, {}, verbose);
|
|
133897
|
-
if (data && typeof data === "object" && !Array.isArray(data)) return data;
|
|
133898
|
-
return void 0;
|
|
133899
|
-
} catch {
|
|
133900
|
-
return void 0;
|
|
133901
|
-
}
|
|
133902
|
-
}
|
|
133903
|
-
function countriesOf(row) {
|
|
133904
|
-
const targeting = row?.["targeting"];
|
|
133905
|
-
if (!targeting || typeof targeting !== "object") return void 0;
|
|
133906
|
-
const geo = targeting["geo_locations"];
|
|
133907
|
-
if (!geo || typeof geo !== "object") return void 0;
|
|
133908
|
-
const countries = geo["countries"];
|
|
133909
|
-
if (!Array.isArray(countries)) return void 0;
|
|
133910
|
-
return countries.map((item) => String(item).toUpperCase()).sort().join(",");
|
|
133911
|
-
}
|
|
133912
|
-
function printMetaObjectReceipt(expected, row) {
|
|
133913
|
-
const lines = [];
|
|
133914
|
-
if (expected.status) {
|
|
133915
|
-
lines.push(receiptLine("\u72B6\u6001", expected.status, row?.["status"]));
|
|
133916
|
-
}
|
|
133917
|
-
if (expected.dailyBudget) {
|
|
133918
|
-
lines.push(receiptLine("\u65E5\u9884\u7B97", expected.dailyBudget, row?.["daily_budget"]));
|
|
133919
|
-
}
|
|
133920
|
-
if (expected.countries && expected.countries.length > 0) {
|
|
133921
|
-
lines.push(
|
|
133922
|
-
receiptLine(
|
|
133923
|
-
"\u56FD\u5BB6",
|
|
133924
|
-
expected.countries.map((item) => item.toUpperCase()).sort().join(","),
|
|
133925
|
-
countriesOf(row)
|
|
133926
|
-
)
|
|
133927
|
-
);
|
|
133928
|
-
}
|
|
133929
|
-
if (expected.link) {
|
|
133930
|
-
const spec = row?.["object_story_spec"];
|
|
133931
|
-
const linkData = spec && typeof spec === "object" ? spec["link_data"] : void 0;
|
|
133932
|
-
const link = linkData && typeof linkData === "object" ? linkData["link"] : row?.["link"];
|
|
133933
|
-
lines.push(receiptLine("\u843D\u5730\u9875", expected.link, link));
|
|
133934
|
-
}
|
|
133935
|
-
printWriteReceipt(row ? judgeReceipt(lines) : "unknown", lines);
|
|
133936
|
-
}
|
|
133937
|
-
|
|
133938
133110
|
// src/commands/meta-ad/load.ts
|
|
133939
133111
|
import { readFileSync as readFileSync16 } from "fs";
|
|
133940
133112
|
function stripMetaKeys2(value) {
|
|
@@ -134586,18 +133758,6 @@ async function runMetaAdCreate(opts) {
|
|
|
134586
133758
|
process.exit(1);
|
|
134587
133759
|
}
|
|
134588
133760
|
progress.ok = true;
|
|
134589
|
-
const adsetRow = progress.adSetId ? await tryReadMeta(facebookApiUrl, digits, `/adsets/${progress.adSetId}`, config, opts.verbose) : void 0;
|
|
134590
|
-
const creativeRow = progress.creativeId ? await tryReadMeta(facebookApiUrl, digits, `/adcreatives/${progress.creativeId}`, config, opts.verbose) : void 0;
|
|
134591
|
-
const daily = cfg.adset.dailyBudget != null ? toMinorUnitString(cfg.adset.dailyBudget, currency) : void 0;
|
|
134592
|
-
printMetaObjectReceipt(
|
|
134593
|
-
{
|
|
134594
|
-
status: "PAUSED",
|
|
134595
|
-
dailyBudget: daily,
|
|
134596
|
-
countries: cfg.adset.countries,
|
|
134597
|
-
link: cfg.creative.link
|
|
134598
|
-
},
|
|
134599
|
-
adsetRow ? { ...adsetRow, ...creativeRow ?? {} } : void 0
|
|
134600
|
-
);
|
|
134601
133761
|
if (await emitProgress()) return;
|
|
134602
133762
|
console.log("\n\u2705 Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\u5DF2\u521B\u5EFA\uFF08\u9ED8\u8BA4 PAUSED\uFF09\n");
|
|
134603
133763
|
console.log(` formId ${progress.formId}`);
|
|
@@ -134912,6 +134072,8 @@ async function runMetaAdVideoUpload(opts) {
|
|
|
134912
134072
|
import { createWriteStream } from "fs";
|
|
134913
134073
|
import { mkdir as mkdir7, rename as rename2, rm as rm3, writeFile as writeFile7 } from "fs/promises";
|
|
134914
134074
|
import { dirname as dirname15, join as join14 } from "path";
|
|
134075
|
+
import { Readable } from "stream";
|
|
134076
|
+
import { pipeline } from "stream/promises";
|
|
134915
134077
|
var MAX_MEDIA_BATCH = 50;
|
|
134916
134078
|
var MAX_IMAGE_BYTES = 30 * 1024 * 1024;
|
|
134917
134079
|
var MAX_VIDEO_BYTES = 512 * 1024 * 1024;
|
|
@@ -135015,34 +134177,41 @@ async function downloadPublicFile(fileUrl, dest, maxBytes) {
|
|
|
135015
134177
|
const headParts = [];
|
|
135016
134178
|
let headLen = 0;
|
|
135017
134179
|
let total = 0;
|
|
135018
|
-
|
|
135019
|
-
|
|
135020
|
-
|
|
135021
|
-
|
|
135022
|
-
|
|
135023
|
-
|
|
135024
|
-
|
|
135025
|
-
|
|
135026
|
-
|
|
135027
|
-
|
|
135028
|
-
|
|
135029
|
-
|
|
135030
|
-
|
|
135031
|
-
|
|
135032
|
-
|
|
135033
|
-
|
|
134180
|
+
const source = new Readable({
|
|
134181
|
+
async read() {
|
|
134182
|
+
try {
|
|
134183
|
+
const { done, value } = await reader.read();
|
|
134184
|
+
if (done) {
|
|
134185
|
+
this.push(null);
|
|
134186
|
+
return;
|
|
134187
|
+
}
|
|
134188
|
+
const chunk = Buffer.from(value);
|
|
134189
|
+
total += chunk.length;
|
|
134190
|
+
if (total > maxBytes) {
|
|
134191
|
+
this.destroy(new Error(`\u6587\u4EF6\u8D85\u8FC7 ${maxBytes} \u5B57\u8282`));
|
|
134192
|
+
return;
|
|
134193
|
+
}
|
|
134194
|
+
if (headLen < 16) {
|
|
134195
|
+
headParts.push(chunk.subarray(0, 16 - headLen));
|
|
134196
|
+
headLen += chunk.length;
|
|
134197
|
+
}
|
|
134198
|
+
this.push(chunk);
|
|
134199
|
+
} catch (err) {
|
|
134200
|
+
this.destroy(err instanceof Error ? err : new Error(String(err)));
|
|
135034
134201
|
}
|
|
135035
134202
|
}
|
|
135036
|
-
|
|
135037
|
-
|
|
135038
|
-
|
|
135039
|
-
ws.end(() => resolve27());
|
|
135040
|
-
});
|
|
134203
|
+
});
|
|
134204
|
+
try {
|
|
134205
|
+
await pipeline(source, ws);
|
|
135041
134206
|
} catch (err) {
|
|
135042
|
-
|
|
135043
|
-
await rm3(dest, { force: true });
|
|
134207
|
+
await reader.cancel().catch(() => void 0);
|
|
134208
|
+
await rm3(dest, { force: true }).catch(() => void 0);
|
|
135044
134209
|
throw err;
|
|
135045
134210
|
}
|
|
134211
|
+
if (total < 1) {
|
|
134212
|
+
await rm3(dest, { force: true }).catch(() => void 0);
|
|
134213
|
+
throw new Error("\u6587\u4EF6\u4E3A\u7A7A");
|
|
134214
|
+
}
|
|
135046
134215
|
return {
|
|
135047
134216
|
bytes: total,
|
|
135048
134217
|
contentType: response.headers.get("content-type"),
|
|
@@ -135151,20 +134320,25 @@ async function runMetaAdMediaDownload(opts) {
|
|
|
135151
134320
|
await mkdir7(outDir, { recursive: true });
|
|
135152
134321
|
await writeFile7(join14(outDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
135153
134322
|
`, "utf8");
|
|
134323
|
+
const missingCount = missingImages.length + missingVideos.length;
|
|
134324
|
+
const incomplete = missingCount > 0 || failed.length > 0;
|
|
134325
|
+
if (incomplete) process.exitCode = 1;
|
|
135154
134326
|
if (await emitMetaJson(opts, "meta-ad-media-download", "meta-ad media-download", manifest, digits, {
|
|
135155
134327
|
images: images.length,
|
|
135156
134328
|
videos: videos.length,
|
|
135157
|
-
missing:
|
|
134329
|
+
missing: missingCount,
|
|
135158
134330
|
failed: failed.length
|
|
135159
134331
|
})) {
|
|
135160
134332
|
return;
|
|
135161
134333
|
}
|
|
135162
|
-
|
|
135163
|
-
|
|
135164
|
-
\
|
|
134334
|
+
const summary = `\u56FE\u7247 ${images.length}\uFF0C\u89C6\u9891 ${videos.length}\uFF0C\u7F3A\u5931 ${missingCount}\uFF0C\u5931\u8D25 ${failed.length}`;
|
|
134335
|
+
console.log(incomplete ? `
|
|
134336
|
+
\u672A\u5B8C\u6210\u3002${summary}
|
|
135165
134337
|
\u76EE\u5F55 ${outDir}
|
|
135166
|
-
`
|
|
135167
|
-
|
|
134338
|
+
` : `
|
|
134339
|
+
\u2705 ${summary}
|
|
134340
|
+
\u76EE\u5F55 ${outDir}
|
|
134341
|
+
`);
|
|
135168
134342
|
}
|
|
135169
134343
|
async function saveNamedFile(fileUrl, dir, id, kind, maxBytes) {
|
|
135170
134344
|
const temp = join14(dir, `${id}.part`);
|
|
@@ -135732,20 +134906,6 @@ async function runMetaAdCampaignEdit(opts) {
|
|
|
135732
134906
|
"\u6539\u7CFB\u5217\u5931\u8D25"
|
|
135733
134907
|
);
|
|
135734
134908
|
const payload = { id: extractCreatedId(data) ?? opts.id, ...data };
|
|
135735
|
-
const read = await tryReadMeta(
|
|
135736
|
-
facebookApiUrl,
|
|
135737
|
-
digits,
|
|
135738
|
-
`/campaigns/${encodeURIComponent(opts.id)}`,
|
|
135739
|
-
config,
|
|
135740
|
-
opts.verbose
|
|
135741
|
-
);
|
|
135742
|
-
printMetaObjectReceipt(
|
|
135743
|
-
{
|
|
135744
|
-
status: typeof body.status === "string" ? body.status : void 0,
|
|
135745
|
-
dailyBudget: typeof body.daily_budget === "string" ? body.daily_budget : void 0
|
|
135746
|
-
},
|
|
135747
|
-
read
|
|
135748
|
-
);
|
|
135749
134909
|
if (await emitMetaJson(opts, "meta-ad-campaign-edit", "meta-ad campaign-edit", payload, digits)) {
|
|
135750
134910
|
return;
|
|
135751
134911
|
}
|
|
@@ -135768,14 +134928,6 @@ async function runMetaAdCampaignStatus(opts) {
|
|
|
135768
134928
|
"\u6539\u7CFB\u5217\u72B6\u6001\u5931\u8D25"
|
|
135769
134929
|
);
|
|
135770
134930
|
const payload = { id: extractCreatedId(data) ?? opts.id, status: opts.status.trim(), ...data };
|
|
135771
|
-
const read = await tryReadMeta(
|
|
135772
|
-
facebookApiUrl,
|
|
135773
|
-
digits,
|
|
135774
|
-
`/campaigns/${encodeURIComponent(opts.id)}`,
|
|
135775
|
-
config,
|
|
135776
|
-
opts.verbose
|
|
135777
|
-
);
|
|
135778
|
-
printMetaObjectReceipt({ status: opts.status.trim().toUpperCase() }, read);
|
|
135779
134931
|
if (await emitMetaJson(opts, "meta-ad-campaign-status", "meta-ad campaign-status", payload, digits)) {
|
|
135780
134932
|
return;
|
|
135781
134933
|
}
|
|
@@ -136168,7 +135320,6 @@ async function runMetaAdAdsetEdit(opts) {
|
|
|
136168
135320
|
const unmatched = describeUnmatchedChecks(judged.checks);
|
|
136169
135321
|
const detail = verification === "verified" ? `\u5E7F\u544A\u7EC4 ${opts.id} \u5DF2\u6838\u9A8C` : unmatched || `\u5E7F\u544A\u7EC4 ${opts.id} \u7684\u5199\u5165\u7ED3\u679C\u5C1A\u672A\u6838\u9A8C`;
|
|
136170
135322
|
const headline = writeVerificationHeadline(verification, detail);
|
|
136171
|
-
printWriteReceipt(verification, receiptLinesFromFieldChecks(judged.checks));
|
|
136172
135323
|
if (verification !== "verified") {
|
|
136173
135324
|
console.error(`
|
|
136174
135325
|
${headline}
|
|
@@ -136209,14 +135360,6 @@ async function runMetaAdAdsetStatus(opts) {
|
|
|
136209
135360
|
"\u6539\u5E7F\u544A\u7EC4\u72B6\u6001\u5931\u8D25"
|
|
136210
135361
|
);
|
|
136211
135362
|
const payload = { id: extractCreatedId(data) ?? opts.id, status: opts.status.trim(), ...data };
|
|
136212
|
-
const read = await tryReadMeta(
|
|
136213
|
-
facebookApiUrl,
|
|
136214
|
-
digits,
|
|
136215
|
-
`/adsets/${encodeURIComponent(opts.id)}`,
|
|
136216
|
-
config,
|
|
136217
|
-
opts.verbose
|
|
136218
|
-
);
|
|
136219
|
-
printMetaObjectReceipt({ status: opts.status.trim().toUpperCase() }, read);
|
|
136220
135363
|
if (await emitMetaJson(opts, "meta-ad-adset-status", "meta-ad adset-status", payload, digits)) {
|
|
136221
135364
|
return;
|
|
136222
135365
|
}
|
|
@@ -136371,14 +135514,6 @@ async function runMetaAdStatus(opts) {
|
|
|
136371
135514
|
"\u6539\u5E7F\u544A\u72B6\u6001\u5931\u8D25"
|
|
136372
135515
|
);
|
|
136373
135516
|
const payload = { id: extractCreatedId(data) ?? opts.id, status: opts.status.trim(), ...data };
|
|
136374
|
-
const read = await tryReadMeta(
|
|
136375
|
-
facebookApiUrl,
|
|
136376
|
-
digits,
|
|
136377
|
-
`/ads/${encodeURIComponent(opts.id)}`,
|
|
136378
|
-
config,
|
|
136379
|
-
opts.verbose
|
|
136380
|
-
);
|
|
136381
|
-
printMetaObjectReceipt({ status: opts.status.trim().toUpperCase() }, read);
|
|
136382
135517
|
if (await emitMetaJson(opts, "meta-ad-ad-status", "meta-ad ad-status", payload, digits)) return;
|
|
136383
135518
|
console.log(`
|
|
136384
135519
|
\u2705 \u5E7F\u544A ${opts.id} \u72B6\u6001\u5DF2\u8BBE\u4E3A ${opts.status.trim()}
|
|
@@ -137869,16 +137004,6 @@ async function runAccountMccUnbind(opts) {
|
|
|
137869
137004
|
process.exit(1);
|
|
137870
137005
|
}
|
|
137871
137006
|
}
|
|
137872
|
-
for (const { customerId, response } of results) {
|
|
137873
|
-
const failed = managerIds.filter((mid) => !mccResponseHasSuccess(response, mid));
|
|
137874
|
-
const listed = await fetchAccountsByKeyword(config, "Google", customerId, opts.verbose);
|
|
137875
|
-
const stillListed = JSON.stringify(listed ?? "").includes(customerId);
|
|
137876
|
-
const lines = [
|
|
137877
|
-
receiptLine("MCC", managerIds.join(","), failed.length ? `\u672A\u6210\u529F ${failed.join(",")}` : managerIds.join(",")),
|
|
137878
|
-
receiptLine("\u8D26\u6237", "\u4ECD\u5728\u5217\u8868", listed === void 0 ? void 0 : stillListed ? "\u4ECD\u5728\u5217\u8868" : "\u5DF2\u4E0D\u5728")
|
|
137879
|
-
];
|
|
137880
|
-
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
137881
|
-
}
|
|
137882
137007
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
137883
137008
|
section: "account-mcc-unbind",
|
|
137884
137009
|
commandLabel: "account mcc-unbind",
|
|
@@ -138236,9 +137361,6 @@ async function runAccountDelink(opts) {
|
|
|
138236
137361
|
`);
|
|
138237
137362
|
process.exit(1);
|
|
138238
137363
|
}
|
|
138239
|
-
for (const id of opts.ids) {
|
|
138240
|
-
await printAccountAbsence(config, void 0, id, "\u8D26\u6237", opts.verbose);
|
|
138241
|
-
}
|
|
138242
137364
|
console.log(`
|
|
138243
137365
|
\u2705 \u5DF2\u6279\u91CF\u65AD\u5F00 ${opts.ids.length} \u4E2A\u8D26\u6237\u7684\u5173\u8054\u5173\u7CFB
|
|
138244
137366
|
`);
|
|
@@ -138258,7 +137380,6 @@ async function runAccountDelink(opts) {
|
|
|
138258
137380
|
`);
|
|
138259
137381
|
process.exit(1);
|
|
138260
137382
|
}
|
|
138261
|
-
await printAccountAbsence(config, void 0, entityId, "\u8D26\u6237", opts.verbose);
|
|
138262
137383
|
console.log(`
|
|
138263
137384
|
\u2705 \u8D26\u6237 ${entityId} \u5DF2\u65AD\u5F00\u5173\u8054
|
|
138264
137385
|
`);
|
|
@@ -138312,27 +137433,6 @@ async function runAccountShare(opts) {
|
|
|
138312
137433
|
`);
|
|
138313
137434
|
process.exit(1);
|
|
138314
137435
|
}
|
|
138315
|
-
let detail;
|
|
138316
|
-
try {
|
|
138317
|
-
const listed = await apiFetch2(
|
|
138318
|
-
`${config.apiBaseUrl}/query/media-account/?keyword=${encodeURIComponent(opts.id)}&pageNo=1&pageSize=5`,
|
|
138319
|
-
config,
|
|
138320
|
-
{},
|
|
138321
|
-
opts.verbose
|
|
138322
|
-
);
|
|
138323
|
-
const mediaId = JSON.stringify(listed ?? "").match(/"mediaCustomerId"\s*:\s*"([^"]+)"/)?.[1];
|
|
138324
|
-
if (mediaId && config.mainApiUrl) {
|
|
138325
|
-
detail = await apiFetch2(
|
|
138326
|
-
`${config.mainApiUrl}/query/account/GetAccountsByMediaAcountId?mediaAcountId=${encodeURIComponent(mediaId)}`,
|
|
138327
|
-
config,
|
|
138328
|
-
{},
|
|
138329
|
-
opts.verbose
|
|
138330
|
-
);
|
|
138331
|
-
}
|
|
138332
|
-
} catch {
|
|
138333
|
-
detail = void 0;
|
|
138334
|
-
}
|
|
138335
|
-
printApplicationNeedles([{ label: "\u88AB\u5206\u4EAB\u4EBA", value: userId }], detail);
|
|
138336
137436
|
console.log(`
|
|
138337
137437
|
\u2705 \u8D26\u6237\u5DF2\u6210\u529F\u5206\u4EAB\u7ED9\u624B\u673A\u53F7 ${phone} \u7684\u7528\u6237\uFF08AccountId: ${userId}\uFF09
|
|
138338
137438
|
`);
|
|
@@ -138354,29 +137454,6 @@ async function runAccountUnshare(opts) {
|
|
|
138354
137454
|
`);
|
|
138355
137455
|
process.exit(1);
|
|
138356
137456
|
}
|
|
138357
|
-
let detail;
|
|
138358
|
-
try {
|
|
138359
|
-
const listed = await apiFetch2(
|
|
138360
|
-
`${config.apiBaseUrl}/query/media-account/?keyword=${encodeURIComponent(opts.id)}&pageNo=1&pageSize=5`,
|
|
138361
|
-
config,
|
|
138362
|
-
{},
|
|
138363
|
-
opts.verbose
|
|
138364
|
-
);
|
|
138365
|
-
const text5 = JSON.stringify(listed ?? "");
|
|
138366
|
-
const mediaId = text5.match(/"mediaCustomerId"\s*:\s*"([^"]+)"/)?.[1];
|
|
138367
|
-
if (mediaId && config.mainApiUrl) {
|
|
138368
|
-
detail = await apiFetch2(
|
|
138369
|
-
`${config.mainApiUrl}/query/account/GetAccountsByMediaAcountId?mediaAcountId=${encodeURIComponent(mediaId)}`,
|
|
138370
|
-
config,
|
|
138371
|
-
{},
|
|
138372
|
-
opts.verbose
|
|
138373
|
-
);
|
|
138374
|
-
}
|
|
138375
|
-
} catch {
|
|
138376
|
-
detail = void 0;
|
|
138377
|
-
}
|
|
138378
|
-
const gone = receiptForAbsence("\u5206\u4EAB", opts.accountId, detail);
|
|
138379
|
-
printWriteReceipt(gone.verification, gone.lines);
|
|
138380
137457
|
console.log(`
|
|
138381
137458
|
\u2705 \u5DF2\u53D6\u6D88\u8D26\u6237 ${opts.id} \u5BF9\u7528\u6237 ${opts.accountId} \u7684\u5206\u4EAB
|
|
138382
137459
|
`);
|
|
@@ -138631,9 +137708,6 @@ async function runAccountClose(opts) {
|
|
|
138631
137708
|
console.error("");
|
|
138632
137709
|
process.exit(1);
|
|
138633
137710
|
}
|
|
138634
|
-
for (const id of mediaIds) {
|
|
138635
|
-
await printAccountAbsence(config, "TikTok", id, "\u8D26\u6237", opts.verbose);
|
|
138636
|
-
}
|
|
138637
137711
|
console.log(`
|
|
138638
137712
|
\u2705 TikTok \u5173\u6237\u5DF2\u6210\u529F\u63D0\u4EA4\uFF0CmediaCustomerId\uFF1A${mediaIds.join("\u3001")}
|
|
138639
137713
|
`);
|
|
@@ -138842,13 +137916,6 @@ async function runAccountWithdrawSubmit(opts) {
|
|
|
138842
137916
|
`);
|
|
138843
137917
|
process.exit(1);
|
|
138844
137918
|
}
|
|
138845
|
-
printApplicationNeedles(
|
|
138846
|
-
body.flatMap((item) => [
|
|
138847
|
-
{ label: "\u7533\u8BF7\u8D26\u6237", value: item.MediaCustomerId },
|
|
138848
|
-
{ label: "\u7533\u8BF7\u91D1\u989D", value: item.Amounts }
|
|
138849
|
-
]),
|
|
138850
|
-
result
|
|
138851
|
-
);
|
|
138852
137919
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
138853
137920
|
section: "account-withdraw-submit",
|
|
138854
137921
|
commandLabel: "account withdraw submit",
|
|
@@ -138952,17 +138019,6 @@ async function runAccountBcUnbind(opts) {
|
|
|
138952
138019
|
`);
|
|
138953
138020
|
process.exit(1);
|
|
138954
138021
|
}
|
|
138955
|
-
const failedIds = result && typeof result === "object" && !Array.isArray(result) ? Object.keys(result) : [];
|
|
138956
|
-
for (const customerId of opts.customers) {
|
|
138957
|
-
const listed = await fetchAccountsByKeyword(config, "TikTok", customerId, opts.verbose);
|
|
138958
|
-
const stillListed = JSON.stringify(listed ?? "").includes(customerId);
|
|
138959
|
-
const unbound = !failedIds.includes(customerId);
|
|
138960
|
-
const lines = [
|
|
138961
|
-
receiptLine("BC\u89E3\u7ED1", "\u5DF2\u89E3\u7ED1", unbound ? "\u5DF2\u89E3\u7ED1" : "\u5931\u8D25"),
|
|
138962
|
-
receiptLine("\u8D26\u6237", "\u4ECD\u5728\u5217\u8868", listed === void 0 ? void 0 : stillListed ? "\u4ECD\u5728\u5217\u8868" : "\u5DF2\u4E0D\u5728")
|
|
138963
|
-
];
|
|
138964
|
-
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
138965
|
-
}
|
|
138966
138022
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
138967
138023
|
section: `account-bc-unbind-${opts.bcId}`,
|
|
138968
138024
|
commandLabel: "account bc-unbind",
|
|
@@ -138973,11 +138029,11 @@ async function runAccountBcUnbind(opts) {
|
|
|
138973
138029
|
return;
|
|
138974
138030
|
}
|
|
138975
138031
|
const failedMap = result && typeof result === "object" && !Array.isArray(result) ? result : {};
|
|
138976
|
-
const
|
|
138977
|
-
if (
|
|
138032
|
+
const failedIds = Object.keys(failedMap);
|
|
138033
|
+
if (failedIds.length > 0) {
|
|
138978
138034
|
console.warn(`
|
|
138979
138035
|
\u26A0\uFE0F \u4EE5\u4E0B\u8D26\u6237\u89E3\u7ED1\u5931\u8D25\uFF1A`);
|
|
138980
|
-
for (const id of
|
|
138036
|
+
for (const id of failedIds) {
|
|
138981
138037
|
console.warn(` ${id}: ${failedMap[id]}`);
|
|
138982
138038
|
}
|
|
138983
138039
|
} else {
|
|
@@ -139214,14 +138270,6 @@ async function runAccountEmailDeauth(opts) {
|
|
|
139214
138270
|
`);
|
|
139215
138271
|
process.exit(1);
|
|
139216
138272
|
}
|
|
139217
|
-
let listed;
|
|
139218
|
-
try {
|
|
139219
|
-
listed = await fetchCustomerUserAccessInvitationList(config, opts.customerId, opts.verbose, opts.agentType);
|
|
139220
|
-
} catch {
|
|
139221
|
-
listed = void 0;
|
|
139222
|
-
}
|
|
139223
|
-
const gone = receiptForAbsence("\u90AE\u7BB1\u6388\u6743", opts.invitationId, listed);
|
|
139224
|
-
printWriteReceipt(gone.verification, gone.lines);
|
|
139225
138273
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
139226
138274
|
section: `account-email-deauth-${opts.customerId}-${opts.invitationId}`,
|
|
139227
138275
|
commandLabel: "account email-deauth",
|
|
@@ -139920,41 +138968,6 @@ async function resolveGoogleMediaAccountGroupId(config, opts) {
|
|
|
139920
138968
|
|
|
139921
138969
|
// src/commands/open-account/yandex.ts
|
|
139922
138970
|
init_auth();
|
|
139923
|
-
|
|
139924
|
-
// src/commands/open-account/readback.ts
|
|
139925
|
-
init_auth();
|
|
139926
|
-
async function printOpenAccountReceipt(config, media, company, verbose) {
|
|
139927
|
-
const params = new URLSearchParams();
|
|
139928
|
-
params.set("MediaType", media);
|
|
139929
|
-
params.set("keyword", company);
|
|
139930
|
-
params.set("pageIndex", "0");
|
|
139931
|
-
params.set("pageSize", "20");
|
|
139932
|
-
params.set(
|
|
139933
|
-
"mediaAccountState",
|
|
139934
|
-
media === "Google" ? "Created,Approved,Denied,Inactive" : "Created,Approved,Denied"
|
|
139935
|
-
);
|
|
139936
|
-
let listed;
|
|
139937
|
-
try {
|
|
139938
|
-
const res = await apiFetchWithHeaders2(
|
|
139939
|
-
`${config.apiBaseUrl}/query/media-account/?${params}`,
|
|
139940
|
-
config,
|
|
139941
|
-
{},
|
|
139942
|
-
verbose
|
|
139943
|
-
);
|
|
139944
|
-
listed = res.data;
|
|
139945
|
-
} catch {
|
|
139946
|
-
listed = void 0;
|
|
139947
|
-
}
|
|
139948
|
-
printApplicationNeedles(
|
|
139949
|
-
[
|
|
139950
|
-
{ label: "\u5A92\u4F53", value: media },
|
|
139951
|
-
{ label: "\u516C\u53F8", value: company }
|
|
139952
|
-
],
|
|
139953
|
-
listed
|
|
139954
|
-
);
|
|
139955
|
-
}
|
|
139956
|
-
|
|
139957
|
-
// src/commands/open-account/yandex.ts
|
|
139958
138971
|
async function runOpenAccountYandex(opts) {
|
|
139959
138972
|
const config = loadConfig(opts.token);
|
|
139960
138973
|
const magKey = await resolveGenericMagKey(
|
|
@@ -139989,7 +139002,6 @@ async function runOpenAccountYandex(opts) {
|
|
|
139989
139002
|
{ method: "POST", body: JSON.stringify(body) },
|
|
139990
139003
|
opts.verbose
|
|
139991
139004
|
);
|
|
139992
|
-
await printOpenAccountReceipt(config, "Yandex", opts.company, opts.verbose);
|
|
139993
139005
|
console.log("\n\u2705 Yandex \u5F00\u6237\u7533\u8BF7\u5DF2\u63D0\u4EA4\u6210\u529F\uFF0C\u8BF7\u5728\u300C\u5F00\u6237\u8BB0\u5F55\u300D\u9875\u9762\u67E5\u770B\u5BA1\u6838\u72B6\u6001\u3002\n");
|
|
139994
139006
|
logAccountOpeningHistoryWebUrl(config.apiBaseUrl, "Yandex");
|
|
139995
139007
|
if (opts.verbose && res != null) {
|
|
@@ -140259,7 +139271,6 @@ async function runOpenAccountBing(opts) {
|
|
|
140259
139271
|
{ method: "POST", body: JSON.stringify(body) },
|
|
140260
139272
|
opts.verbose
|
|
140261
139273
|
);
|
|
140262
|
-
await printOpenAccountReceipt(config, "BingV2", opts.advertiserName, opts.verbose);
|
|
140263
139274
|
console.log("\n\u2705 Bing \u5F00\u6237\u7533\u8BF7\u5DF2\u63D0\u4EA4\u6210\u529F\uFF0C\u8BF7\u5728\u300C\u5F00\u6237\u8BB0\u5F55\u300D\u9875\u9762\u67E5\u770B\u5BA1\u6838\u72B6\u6001\u3002\n");
|
|
140264
139275
|
logAccountOpeningHistoryWebUrl(config.apiBaseUrl, "BingV2");
|
|
140265
139276
|
} catch (err) {
|
|
@@ -140476,12 +139487,12 @@ async function runOpenAccountGoogleWizard(opts) {
|
|
|
140476
139487
|
` \u2026 \u5171 ${rows.length} \u6761\uFF0C\u4E5F\u53EF\u7528\uFF1Asiluzan-tso open-account google-timezones --keyword Tokyo
|
|
140477
139488
|
`
|
|
140478
139489
|
);
|
|
140479
|
-
const
|
|
140480
|
-
const n = parseInt(
|
|
139490
|
+
const pick3 = await q("\n\u8F93\u5165\u5E8F\u53F7\uFF081-60\uFF09\u6216\u76F4\u63A5\u7C98\u8D34 Code\uFF1A");
|
|
139491
|
+
const n = parseInt(pick3, 10);
|
|
140481
139492
|
if (!Number.isNaN(n) && n >= 1 && n <= Math.min(60, rows.length)) {
|
|
140482
139493
|
timezone = String(rows[n - 1]?.Code ?? timezone);
|
|
140483
|
-
} else if (
|
|
140484
|
-
timezone =
|
|
139494
|
+
} else if (pick3) {
|
|
139495
|
+
timezone = pick3;
|
|
140485
139496
|
}
|
|
140486
139497
|
} else if (tzAns) {
|
|
140487
139498
|
timezone = tzAns;
|
|
@@ -140601,7 +139612,6 @@ async function runOpenAccountGoogle(opts) {
|
|
|
140601
139612
|
},
|
|
140602
139613
|
opts.verbose
|
|
140603
139614
|
);
|
|
140604
|
-
await printOpenAccountReceipt(config, "Google", opts.company, opts.verbose);
|
|
140605
139615
|
console.log(
|
|
140606
139616
|
`
|
|
140607
139617
|
\u2705 Google \u5F00\u6237\u7533\u8BF7\u5DF2\u63D0\u4EA4\uFF08\u5171 ${counts} \u4E2A\uFF09\uFF0C\u9080\u8BF7\u90AE\u4EF6\u5C06\u53D1\u9001\u5230 ${inviteEmail}\u3002
|
|
@@ -140809,7 +139819,6 @@ async function runOpenAccountTikTok(opts) {
|
|
|
140809
139819
|
},
|
|
140810
139820
|
opts.verbose
|
|
140811
139821
|
);
|
|
140812
|
-
await printOpenAccountReceipt(config, "TikTok", opts.company, opts.verbose);
|
|
140813
139822
|
console.log(
|
|
140814
139823
|
`
|
|
140815
139824
|
\u2705 TikTok \u5F00\u6237\u7533\u8BF7\u5DF2\u63D0\u4EA4\uFF08\u5171 ${counts} \u4E2A\uFF09\u3002
|
|
@@ -142289,12 +141298,12 @@ var TEMPLATE_BASENAMES = {
|
|
|
142289
141298
|
html: "website-diagnosis-report.html",
|
|
142290
141299
|
runtime: "website-diagnosis-report.runtime.js"
|
|
142291
141300
|
};
|
|
142292
|
-
function resolveSkillTemplatePath(
|
|
141301
|
+
function resolveSkillTemplatePath(basename15) {
|
|
142293
141302
|
const dir = path25.dirname(fileURLToPath4(import.meta.url));
|
|
142294
141303
|
const candidates = [
|
|
142295
|
-
path25.join(dir, "skill", "report-templates",
|
|
142296
|
-
path25.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
142297
|
-
path25.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
141304
|
+
path25.join(dir, "skill", "report-templates", basename15),
|
|
141305
|
+
path25.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
141306
|
+
path25.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
142298
141307
|
];
|
|
142299
141308
|
for (const p of candidates) {
|
|
142300
141309
|
if (fs20.existsSync(p)) return p;
|
|
@@ -143260,13 +142269,13 @@ function buildGoogleAdsDiagnosisNarrativeChecks() {
|
|
|
143260
142269
|
return checks;
|
|
143261
142270
|
}
|
|
143262
142271
|
var GOOGLE_ADS_DIAGNOSIS_NARRATIVE_CHECKS = buildGoogleAdsDiagnosisNarrativeChecks();
|
|
143263
|
-
function resolveSkillTemplatePath2(
|
|
142272
|
+
function resolveSkillTemplatePath2(basename15) {
|
|
143264
142273
|
const dir = path27.dirname(fileURLToPath5(import.meta.url));
|
|
143265
142274
|
const candidates = [
|
|
143266
|
-
path27.join(dir, "skill", "report-templates",
|
|
143267
|
-
path27.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
143268
|
-
path27.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
143269
|
-
path27.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
142275
|
+
path27.join(dir, "skill", "report-templates", basename15),
|
|
142276
|
+
path27.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
142277
|
+
path27.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15),
|
|
142278
|
+
path27.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
143270
142279
|
];
|
|
143271
142280
|
for (const p of candidates) {
|
|
143272
142281
|
if (fs22.existsSync(p)) return p;
|
|
@@ -144468,7 +143477,7 @@ function getCollectIntegrityWarnings(reportData) {
|
|
|
144468
143477
|
}
|
|
144469
143478
|
|
|
144470
143479
|
// src/commands/google-ads-diagnosis/invoke-google-analysis.ts
|
|
144471
|
-
import { spawnSync as
|
|
143480
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
144472
143481
|
function invokeGoogleAnalysisCli(opts) {
|
|
144473
143482
|
const cliEntry = process.argv[1];
|
|
144474
143483
|
if (!cliEntry) {
|
|
@@ -144492,7 +143501,7 @@ function invokeGoogleAnalysisCli(opts) {
|
|
|
144492
143501
|
if (typeof opts.taskTimeoutMs === "number") {
|
|
144493
143502
|
args.push("--task-timeout-ms", String(opts.taskTimeoutMs));
|
|
144494
143503
|
}
|
|
144495
|
-
const result =
|
|
143504
|
+
const result = spawnSync2(process.execPath, args, {
|
|
144496
143505
|
encoding: "utf8",
|
|
144497
143506
|
stdio: ["ignore", "pipe", "inherit"],
|
|
144498
143507
|
timeout: opts.timeoutMs && opts.timeoutMs > 0 ? opts.timeoutMs : void 0
|
|
@@ -145637,7 +144646,7 @@ function channelBucket(channelTypeV2) {
|
|
|
145637
144646
|
if (raw === "DISPLAY") return "\u5C55\u793A";
|
|
145638
144647
|
return "\u5176\u4ED6";
|
|
145639
144648
|
}
|
|
145640
|
-
function
|
|
144649
|
+
function isSearchChannel2(channelTypeV2) {
|
|
145641
144650
|
return channelBucket(channelTypeV2) === "\u641C\u7D22";
|
|
145642
144651
|
}
|
|
145643
144652
|
function spendByChannel(rows) {
|
|
@@ -146303,7 +145312,7 @@ function pickSpecialAds(videos, campaigns) {
|
|
|
146303
145312
|
return { source: "pmax", label: "\u6548\u679C\u6700\u5927\u5316", items: pmax };
|
|
146304
145313
|
}
|
|
146305
145314
|
const other = sortBySpend(
|
|
146306
|
-
campaigns.filter((row) => !
|
|
145315
|
+
campaigns.filter((row) => !isSearchChannel2(row.channelTypeV2) && hasTraffic(row)).map(fromCampaign)
|
|
146307
145316
|
);
|
|
146308
145317
|
if (other.length > 0) {
|
|
146309
145318
|
return { source: "other", label: "\u975E\u641C\u7D22\u5E7F\u544A", items: other };
|
|
@@ -146948,6 +145957,237 @@ function registerGoogleQuarterlyCommands(program2) {
|
|
|
146948
145957
|
);
|
|
146949
145958
|
}
|
|
146950
145959
|
|
|
145960
|
+
// src/commands/ga4.ts
|
|
145961
|
+
init_auth();
|
|
145962
|
+
init_cli_json_snapshot();
|
|
145963
|
+
init_cli_table();
|
|
145964
|
+
init_shared();
|
|
145965
|
+
var GA4_REPORT_DIMENSIONS = [
|
|
145966
|
+
"date",
|
|
145967
|
+
"eventName",
|
|
145968
|
+
"sessionDefaultChannelGroup",
|
|
145969
|
+
"pagePath",
|
|
145970
|
+
"deviceCategory",
|
|
145971
|
+
"country",
|
|
145972
|
+
"sessionSourceMedium"
|
|
145973
|
+
];
|
|
145974
|
+
var GA4_REPORT_METRICS = [
|
|
145975
|
+
"sessions",
|
|
145976
|
+
"newUsers",
|
|
145977
|
+
"totalUsers",
|
|
145978
|
+
"activeUsers",
|
|
145979
|
+
"eventCount",
|
|
145980
|
+
"keyEvents",
|
|
145981
|
+
"bounceRate",
|
|
145982
|
+
"screenPageViews",
|
|
145983
|
+
"screenPageViewsPerUser",
|
|
145984
|
+
"averageSessionDuration"
|
|
145985
|
+
];
|
|
145986
|
+
var GA4_PATH = {
|
|
145987
|
+
overview: "AnalysisDataReportDataOverview",
|
|
145988
|
+
channels: "AnalysisDataReportSessionDefaultChannelGroup",
|
|
145989
|
+
pages: "AnalysisDataReportPagePath",
|
|
145990
|
+
report: "AnalysisDataReport"
|
|
145991
|
+
};
|
|
145992
|
+
var PRESET_DIMENSIONS = {
|
|
145993
|
+
overview: ["date"],
|
|
145994
|
+
channels: ["sessionDefaultChannelGroup"],
|
|
145995
|
+
pages: ["pagePath"]
|
|
145996
|
+
};
|
|
145997
|
+
function normalizeGa4PropertyId(raw) {
|
|
145998
|
+
const text5 = (raw ?? "").trim().replace(/^properties\//i, "");
|
|
145999
|
+
if (!/^\d+$/.test(text5)) {
|
|
146000
|
+
throw new Error(`--property \u987B\u4E3A GA4 \u6570\u5B57\u8D44\u6E90 ID\uFF0C\u6536\u5230\u300C${raw ?? ""}\u300D`);
|
|
146001
|
+
}
|
|
146002
|
+
return text5;
|
|
146003
|
+
}
|
|
146004
|
+
function parseIsoDate2(raw, label2) {
|
|
146005
|
+
const value = (raw ?? "").trim();
|
|
146006
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
146007
|
+
throw new Error(`${label2} \u987B\u4E3A YYYY-MM-DD\uFF0C\u6536\u5230\u300C${raw ?? ""}\u300D`);
|
|
146008
|
+
}
|
|
146009
|
+
const [year, month, day] = value.split("-").map((part) => Number(part));
|
|
146010
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
146011
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {
|
|
146012
|
+
throw new Error(`${label2} \u4E0D\u662F\u6709\u6548\u65E5\u671F\uFF1A${value}`);
|
|
146013
|
+
}
|
|
146014
|
+
return value;
|
|
146015
|
+
}
|
|
146016
|
+
function parseGa4FieldList(raw, allow, kind) {
|
|
146017
|
+
const names = (raw ?? "").split(",").map((part) => part.trim()).filter(Boolean);
|
|
146018
|
+
if (names.length === 0) {
|
|
146019
|
+
throw new Error(`--${kind === "\u7EF4\u5EA6" ? "dimensions" : "metrics"} \u4E0D\u80FD\u4E3A\u7A7A\u3002\u5141\u8BB8\uFF1A${allow.join(", ")}`);
|
|
146020
|
+
}
|
|
146021
|
+
const allowed = new Set(allow);
|
|
146022
|
+
const seen = /* @__PURE__ */ new Set();
|
|
146023
|
+
for (const name2 of names) {
|
|
146024
|
+
if (!allowed.has(name2)) {
|
|
146025
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684${kind}\u300C${name2}\u300D\u3002\u5141\u8BB8\uFF1A${allow.join(", ")}`);
|
|
146026
|
+
}
|
|
146027
|
+
if (seen.has(name2)) {
|
|
146028
|
+
throw new Error(`${kind}\u300C${name2}\u300D\u91CD\u590D`);
|
|
146029
|
+
}
|
|
146030
|
+
seen.add(name2);
|
|
146031
|
+
}
|
|
146032
|
+
return names;
|
|
146033
|
+
}
|
|
146034
|
+
function buildGa4ReportUrl(googleApiUrl, kind, input) {
|
|
146035
|
+
const account = input.account.trim();
|
|
146036
|
+
if (!account) {
|
|
146037
|
+
throw new Error("\u9700\u8981 --account\uFF1A\u5DF2\u7ED1\u5B9A\u7684 GoogleGA4 \u5A92\u4F53\u8D26\u53F7\uFF0C\u4E0D\u662F\u5E7F\u544A\u5BA2\u6237 ID");
|
|
146038
|
+
}
|
|
146039
|
+
const propertyId = normalizeGa4PropertyId(input.property);
|
|
146040
|
+
const startDate = parseIsoDate2(input.start, "--start");
|
|
146041
|
+
const endDate = parseIsoDate2(input.end, "--end");
|
|
146042
|
+
if (startDate > endDate) {
|
|
146043
|
+
throw new Error("--start \u4E0D\u80FD\u665A\u4E8E --end");
|
|
146044
|
+
}
|
|
146045
|
+
const dimensions = kind === "report" ? parseGa4FieldList(input.dimensions, GA4_REPORT_DIMENSIONS, "\u7EF4\u5EA6") : [...PRESET_DIMENSIONS[kind]];
|
|
146046
|
+
const metrics = kind === "report" ? parseGa4FieldList(input.metrics, GA4_REPORT_METRICS, "\u6307\u6807") : [];
|
|
146047
|
+
const params = new URLSearchParams();
|
|
146048
|
+
params.set("mediaAccountId", account);
|
|
146049
|
+
params.set("propertyId", propertyId);
|
|
146050
|
+
params.set("startDate", startDate);
|
|
146051
|
+
params.set("endDate", endDate);
|
|
146052
|
+
if (kind === "report") {
|
|
146053
|
+
params.set("dimensions", dimensions.join(","));
|
|
146054
|
+
params.set("metrics", metrics.join(","));
|
|
146055
|
+
}
|
|
146056
|
+
const base2 = googleApiUrl.replace(/\/+$/, "");
|
|
146057
|
+
return {
|
|
146058
|
+
url: `${base2}/analysisreporting/media-account/${GA4_PATH[kind]}?${params.toString()}`,
|
|
146059
|
+
query: { propertyId, startDate, endDate, dimensions, metrics }
|
|
146060
|
+
};
|
|
146061
|
+
}
|
|
146062
|
+
function cellValue(cell5) {
|
|
146063
|
+
return cell5?.value ?? cell5?.Value ?? "";
|
|
146064
|
+
}
|
|
146065
|
+
function periodRows(period) {
|
|
146066
|
+
if (!period) return [];
|
|
146067
|
+
return period.analyticsDataInfos ?? period.AnalyticsDataInfos ?? [];
|
|
146068
|
+
}
|
|
146069
|
+
function isPlaceholder(row, dimensionNames) {
|
|
146070
|
+
const dimensions = row.dimension ?? row.Dimension ?? [];
|
|
146071
|
+
const metrics = row.mtricInfos ?? row.MtricInfos ?? [];
|
|
146072
|
+
if (dimensions.length === 0 || dimensions.length !== dimensionNames.length) return false;
|
|
146073
|
+
const dimensionsMatch = dimensions.every((cell5, index) => cellValue(cell5) === dimensionNames[index]);
|
|
146074
|
+
const metricsMatch = metrics.every((cell5) => {
|
|
146075
|
+
const name2 = cell5.metric ?? cell5.Metric ?? "";
|
|
146076
|
+
return name2 !== "" && cellValue(cell5) === name2;
|
|
146077
|
+
});
|
|
146078
|
+
return dimensionsMatch && metricsMatch;
|
|
146079
|
+
}
|
|
146080
|
+
function flattenGa4Rows(period, dimensionNames) {
|
|
146081
|
+
const rows = [];
|
|
146082
|
+
for (const info of periodRows(period)) {
|
|
146083
|
+
if (isPlaceholder(info, dimensionNames)) continue;
|
|
146084
|
+
const record2 = {};
|
|
146085
|
+
const dimensions = info.dimension ?? info.Dimension ?? [];
|
|
146086
|
+
dimensionNames.forEach((name2, index) => {
|
|
146087
|
+
record2[name2] = cellValue(dimensions[index]);
|
|
146088
|
+
});
|
|
146089
|
+
for (const metric of info.mtricInfos ?? info.MtricInfos ?? []) {
|
|
146090
|
+
const name2 = metric.metric ?? metric.Metric;
|
|
146091
|
+
if (name2) record2[name2] = cellValue(metric);
|
|
146092
|
+
}
|
|
146093
|
+
rows.push(record2);
|
|
146094
|
+
}
|
|
146095
|
+
return rows;
|
|
146096
|
+
}
|
|
146097
|
+
function readEnvelope2(data) {
|
|
146098
|
+
return {
|
|
146099
|
+
current: data.analyticsDataReport ?? data.AnalyticsDataReport,
|
|
146100
|
+
previous: data.lastAnalyticsDataReport ?? data.LastAnalyticsDataReport
|
|
146101
|
+
};
|
|
146102
|
+
}
|
|
146103
|
+
function printPeriod(title, rows, dimensionNames) {
|
|
146104
|
+
console.log(`
|
|
146105
|
+
${title}\uFF08${rows.length} \u884C\uFF09`);
|
|
146106
|
+
if (rows.length === 0) {
|
|
146107
|
+
console.log(" \u6CA1\u6709\u6570\u636E\u884C\u3002\n");
|
|
146108
|
+
return;
|
|
146109
|
+
}
|
|
146110
|
+
const metricNames = [];
|
|
146111
|
+
for (const row of rows) {
|
|
146112
|
+
for (const key of Object.keys(row)) {
|
|
146113
|
+
if (!dimensionNames.includes(key) && !metricNames.includes(key)) metricNames.push(key);
|
|
146114
|
+
}
|
|
146115
|
+
}
|
|
146116
|
+
printCliTable(
|
|
146117
|
+
rows,
|
|
146118
|
+
[...dimensionNames, ...metricNames].map((key) => ({ key, header: key }))
|
|
146119
|
+
);
|
|
146120
|
+
}
|
|
146121
|
+
async function runGa4(opts) {
|
|
146122
|
+
let built;
|
|
146123
|
+
try {
|
|
146124
|
+
const config = loadConfig(opts.token);
|
|
146125
|
+
built = buildGa4ReportUrl(requireGoogleApi(config), opts.kind, opts);
|
|
146126
|
+
const data = await apiFetch2(built.url, config, { method: "GET" }, opts.verbose);
|
|
146127
|
+
const { current, previous } = readEnvelope2(data ?? {});
|
|
146128
|
+
const dimensions = built.query.dimensions;
|
|
146129
|
+
const rows = flattenGa4Rows(current, dimensions);
|
|
146130
|
+
const previousRows = flattenGa4Rows(previous, dimensions);
|
|
146131
|
+
const payload = {
|
|
146132
|
+
account: opts.account.trim(),
|
|
146133
|
+
propertyId: built.query.propertyId,
|
|
146134
|
+
startDate: built.query.startDate,
|
|
146135
|
+
endDate: built.query.endDate,
|
|
146136
|
+
dimensions,
|
|
146137
|
+
rows,
|
|
146138
|
+
previousRows
|
|
146139
|
+
};
|
|
146140
|
+
if (await emitCliJsonOrSnapshot(opts, {
|
|
146141
|
+
section: `ga4-${opts.kind}`,
|
|
146142
|
+
commandLabel: `ga4 ${opts.kind}`,
|
|
146143
|
+
payload,
|
|
146144
|
+
summaryExtras: { rows: rows.length, previousRows: previousRows.length }
|
|
146145
|
+
})) {
|
|
146146
|
+
return;
|
|
146147
|
+
}
|
|
146148
|
+
console.log(
|
|
146149
|
+
`GA4 ${opts.kind} property=${built.query.propertyId} ${built.query.startDate} ~ ${built.query.endDate}`
|
|
146150
|
+
);
|
|
146151
|
+
console.log("\u6307\u6807\u4FDD\u6301 GA4 \u539F\u503C\u3002\u4E0A\u4E00\u5468\u671F\u7531\u7F51\u5173\u6309\u7B49\u957F\u533A\u95F4\u81EA\u52A8\u67E5\u8BE2\u3002");
|
|
146152
|
+
printPeriod("\u672C\u671F", rows, dimensions);
|
|
146153
|
+
printPeriod("\u4E0A\u4E00\u5468\u671F", previousRows, dimensions);
|
|
146154
|
+
} catch (err) {
|
|
146155
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
146156
|
+
console.error(`
|
|
146157
|
+
\u274C GA4 \u62A5\u8868\u5931\u8D25\uFF1A${message}
|
|
146158
|
+
`);
|
|
146159
|
+
if (opts.verbose && err instanceof Error && err.stack) console.error(err.stack);
|
|
146160
|
+
process.exit(1);
|
|
146161
|
+
}
|
|
146162
|
+
}
|
|
146163
|
+
function addGa4QueryOptions(cmd) {
|
|
146164
|
+
attachJsonOutOption(cmd);
|
|
146165
|
+
return cmd.requiredOption("--account <id>", "\u5DF2\u7ED1\u5B9A\u7684 GoogleGA4 \u5A92\u4F53\u8D26\u53F7\u3002\u7528\u6765\u53D6\u6388\u6743\uFF0C\u4E0D\u662F\u5E7F\u544A\u5BA2\u6237 ID").requiredOption("--property <id>", "GA4 \u6570\u5B57\u8D44\u6E90 ID\uFF0C\u4F8B\u5982 123456789").requiredOption("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD").requiredOption("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD").option("--verbose", "\u8F93\u51FA\u8BE6\u7EC6\u9519\u8BEF\u5806\u6808").option("--token <jwt>", "\u4E34\u65F6\u4F7F\u7528\u7684 JWT Token\uFF08\u8986\u76D6 ~/.siluzan/config.json\uFF09");
|
|
146166
|
+
}
|
|
146167
|
+
function register28(program2) {
|
|
146168
|
+
const ga4 = program2.command("ga4").description("GA4 \u53EA\u8BFB\u6307\u6807\uFF08\u4F1A\u8BDD\u3001\u7528\u6237\u3001\u4E8B\u4EF6\u3001\u6E20\u9053\u3001\u9875\u9762\uFF09\u3002\u8D26\u53F7\u662F\u5DF2\u7ED1\u5B9A\u7684 GoogleGA4\uFF0C\u4E0D\u662F\u5E7F\u544A\u5BA2\u6237 ID");
|
|
146169
|
+
addGa4QueryOptions(
|
|
146170
|
+
ga4.command("overview").description("\u6309\u65E5\u7684\u4F1A\u8BDD\u3001\u7528\u6237\u3001\u4E8B\u4EF6\u3001\u5173\u952E\u4E8B\u4EF6\u3001\u8DF3\u51FA\u7387\u548C\u505C\u7559\u65F6\u957F\uFF0C\u542B\u4E0A\u4E00\u5468\u671F")
|
|
146171
|
+
).action(async (opts) => {
|
|
146172
|
+
await runGa4({ ...opts, kind: "overview" });
|
|
146173
|
+
});
|
|
146174
|
+
addGa4QueryOptions(
|
|
146175
|
+
ga4.command("channels").description("\u6309\u9ED8\u8BA4\u6E20\u9053\u5206\u7EC4\u7684\u4F1A\u8BDD\u548C\u4E8B\u4EF6\uFF0C\u542B\u4E0A\u4E00\u5468\u671F")
|
|
146176
|
+
).action(async (opts) => {
|
|
146177
|
+
await runGa4({ ...opts, kind: "channels" });
|
|
146178
|
+
});
|
|
146179
|
+
addGa4QueryOptions(
|
|
146180
|
+
ga4.command("pages").description("\u6309\u9875\u9762\u8DEF\u5F84\u7684\u4F1A\u8BDD\u548C\u4E8B\u4EF6\uFF0C\u542B\u4E0A\u4E00\u5468\u671F")
|
|
146181
|
+
).action(async (opts) => {
|
|
146182
|
+
await runGa4({ ...opts, kind: "pages" });
|
|
146183
|
+
});
|
|
146184
|
+
addGa4QueryOptions(
|
|
146185
|
+
ga4.command("report").description("\u6309\u767D\u540D\u5355\u91CC\u7684\u7EF4\u5EA6\u548C\u6307\u6807\u67E5 GA4\u3002\u4E8B\u4EF6\u793A\u4F8B\uFF1A--dimensions eventName --metrics eventCount,keyEvents")
|
|
146186
|
+
).requiredOption("--dimensions <names>", `\u7EF4\u5EA6\uFF0C\u9017\u53F7\u5206\u9694\u3002\u5141\u8BB8\uFF1A${GA4_REPORT_DIMENSIONS.join(", ")}`).requiredOption("--metrics <names>", `\u6307\u6807\uFF0C\u9017\u53F7\u5206\u9694\u3002\u5141\u8BB8\uFF1A${GA4_REPORT_METRICS.join(", ")}`).action(async (opts) => {
|
|
146187
|
+
await runGa4({ ...opts, kind: "report" });
|
|
146188
|
+
});
|
|
146189
|
+
}
|
|
146190
|
+
|
|
146951
146191
|
// src/index.ts
|
|
146952
146192
|
init_google_analysis3();
|
|
146953
146193
|
init_google_analysis_batch();
|
|
@@ -147871,12 +147111,12 @@ var TEMPLATE_BASENAMES2 = {
|
|
|
147871
147111
|
html: "meta-period-report.html"
|
|
147872
147112
|
};
|
|
147873
147113
|
var INJECT_MARKER2 = "window.__META_PERIOD_REPORT__ = window.__META_PERIOD_REPORT__ || null;";
|
|
147874
|
-
function resolveSkillTemplatePath5(
|
|
147114
|
+
function resolveSkillTemplatePath5(basename15) {
|
|
147875
147115
|
const dir = path47.dirname(fileURLToPath11(import.meta.url));
|
|
147876
147116
|
const candidates = [
|
|
147877
|
-
path47.join(dir, "skill", "report-templates",
|
|
147878
|
-
path47.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
147879
|
-
path47.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
147117
|
+
path47.join(dir, "skill", "report-templates", basename15),
|
|
147118
|
+
path47.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
147119
|
+
path47.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
147880
147120
|
];
|
|
147881
147121
|
for (const p of candidates) {
|
|
147882
147122
|
if (fs40.existsSync(p)) return p;
|
|
@@ -148351,12 +147591,12 @@ init_lang();
|
|
|
148351
147591
|
init_html();
|
|
148352
147592
|
var TEMPLATE_BASENAME3 = "meta-account-diagnosis-report.html";
|
|
148353
147593
|
var INJECT_MARKER3 = "window.__META_DIAGNOSIS_REPORT__ = window.__META_DIAGNOSIS_REPORT__ || null;";
|
|
148354
|
-
function resolveSkillTemplatePath6(
|
|
147594
|
+
function resolveSkillTemplatePath6(basename15) {
|
|
148355
147595
|
const dir = path49.dirname(fileURLToPath12(import.meta.url));
|
|
148356
147596
|
const candidates = [
|
|
148357
|
-
path49.join(dir, "skill", "report-templates",
|
|
148358
|
-
path49.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
148359
|
-
path49.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
147597
|
+
path49.join(dir, "skill", "report-templates", basename15),
|
|
147598
|
+
path49.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
147599
|
+
path49.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
148360
147600
|
];
|
|
148361
147601
|
for (const p of candidates) {
|
|
148362
147602
|
if (fs42.existsSync(p)) return p;
|
|
@@ -150489,12 +149729,12 @@ init_lang();
|
|
|
150489
149729
|
init_html();
|
|
150490
149730
|
var TEMPLATE_BASENAME4 = "bing-period-report.html";
|
|
150491
149731
|
var INJECT_MARKER4 = "window.__BING_PERIOD_REPORT__ = window.__BING_PERIOD_REPORT__ || null;";
|
|
150492
|
-
function resolveSkillTemplatePath7(
|
|
149732
|
+
function resolveSkillTemplatePath7(basename15) {
|
|
150493
149733
|
const dir = path53.dirname(fileURLToPath13(import.meta.url));
|
|
150494
149734
|
const candidates = [
|
|
150495
|
-
path53.join(dir, "skill", "report-templates",
|
|
150496
|
-
path53.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
150497
|
-
path53.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
149735
|
+
path53.join(dir, "skill", "report-templates", basename15),
|
|
149736
|
+
path53.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
149737
|
+
path53.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
150498
149738
|
];
|
|
150499
149739
|
for (const p of candidates) {
|
|
150500
149740
|
if (fs44.existsSync(p)) return p;
|
|
@@ -151504,12 +150744,12 @@ init_lang();
|
|
|
151504
150744
|
init_html();
|
|
151505
150745
|
var TEMPLATE_BASENAME5 = "tiktok-period-report.html";
|
|
151506
150746
|
var INJECT_MARKER5 = "window.__TIKTOK_PERIOD_REPORT__ = window.__TIKTOK_PERIOD_REPORT__ || null;";
|
|
151507
|
-
function resolveSkillTemplatePath8(
|
|
150747
|
+
function resolveSkillTemplatePath8(basename15) {
|
|
151508
150748
|
const dir = path56.dirname(fileURLToPath14(import.meta.url));
|
|
151509
150749
|
const candidates = [
|
|
151510
|
-
path56.join(dir, "skill", "report-templates",
|
|
151511
|
-
path56.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
151512
|
-
path56.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
150750
|
+
path56.join(dir, "skill", "report-templates", basename15),
|
|
150751
|
+
path56.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
150752
|
+
path56.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
151513
150753
|
];
|
|
151514
150754
|
for (const p of candidates) {
|
|
151515
150755
|
if (fs46.existsSync(p)) return p;
|
|
@@ -151757,6 +150997,29 @@ function daysInclusive(start, end) {
|
|
|
151757
150997
|
const b = new Date(end.getFullYear(), end.getMonth(), end.getDate());
|
|
151758
150998
|
return Math.floor((b.getTime() - a.getTime()) / 864e5) + 1;
|
|
151759
150999
|
}
|
|
151000
|
+
var REPORT_LEVEL_ID = {
|
|
151001
|
+
AUCTION_ADVERTISER: "",
|
|
151002
|
+
AUCTION_CAMPAIGN: "campaign_id",
|
|
151003
|
+
AUCTION_ADGROUP: "adgroup_id",
|
|
151004
|
+
AUCTION_AD: "ad_id"
|
|
151005
|
+
};
|
|
151006
|
+
var REPORT_ENTITY_IDS = ["campaign_id", "adgroup_id", "ad_id"];
|
|
151007
|
+
function tiktokReportDimensionError(dataLevel, dimensions) {
|
|
151008
|
+
const level = dataLevel.trim();
|
|
151009
|
+
if (!Object.prototype.hasOwnProperty.call(REPORT_LEVEL_ID, level)) {
|
|
151010
|
+
return "data-level \u53EA\u63A5\u53D7 AUCTION_ADVERTISER\u3001AUCTION_CAMPAIGN\u3001AUCTION_ADGROUP\u3001AUCTION_AD";
|
|
151011
|
+
}
|
|
151012
|
+
const dims = dimensions.split(",").map((item) => item.trim()).filter(Boolean);
|
|
151013
|
+
const own = REPORT_LEVEL_ID[level] ?? "";
|
|
151014
|
+
if (own && !dims.includes(own)) {
|
|
151015
|
+
return `${level} \u7684 dimensions \u5FC5\u987B\u5305\u542B ${own}`;
|
|
151016
|
+
}
|
|
151017
|
+
const extra = REPORT_ENTITY_IDS.filter((name2) => name2 !== own && dims.includes(name2));
|
|
151018
|
+
if (extra.length > 0) {
|
|
151019
|
+
return own ? `${level} \u4E0D\u80FD\u5E26 ${extra.join("\u3001")}` : "AUCTION_ADVERTISER \u4E0D\u80FD\u5E26 campaign_id\u3001adgroup_id \u6216 ad_id";
|
|
151020
|
+
}
|
|
151021
|
+
return void 0;
|
|
151022
|
+
}
|
|
151760
151023
|
function assertTikTokOfficialReportRange(startDate, endDate, dimensions) {
|
|
151761
151024
|
const start = startDate.trim();
|
|
151762
151025
|
const end = endDate.trim();
|
|
@@ -151802,7 +151065,8 @@ function unwrapTikTokEnvelope(raw, label2) {
|
|
|
151802
151065
|
if (code !== 0 && code !== void 0) {
|
|
151803
151066
|
throw new Error(`${label2} \u4E1A\u52A1\u5931\u8D25 code=${code}\uFF1A${env.message ?? "\u672A\u77E5\u9519\u8BEF"}`);
|
|
151804
151067
|
}
|
|
151805
|
-
const
|
|
151068
|
+
const data = env.data;
|
|
151069
|
+
const list = Array.isArray(data?.list) ? data.list : Array.isArray(data?.pixels) ? data.pixels : [];
|
|
151806
151070
|
const info = env.data?.page_info ?? {};
|
|
151807
151071
|
const page = parseTikTokNumber(info.page) ?? 1;
|
|
151808
151072
|
const pageSize = parseTikTokNumber(info.page_size) ?? list.length;
|
|
@@ -152207,6 +151471,13 @@ async function runTikTokOfficialReport(opts) {
|
|
|
152207
151471
|
console.error("\n\u274C --data-level / --dimensions / --metrics \u5747\u4E3A\u5FC5\u586B\u3002\n");
|
|
152208
151472
|
process.exit(1);
|
|
152209
151473
|
}
|
|
151474
|
+
const dimensionError = tiktokReportDimensionError(dataLevel, dimensions);
|
|
151475
|
+
if (dimensionError) {
|
|
151476
|
+
console.error(`
|
|
151477
|
+
\u274C ${dimensionError}
|
|
151478
|
+
`);
|
|
151479
|
+
process.exit(1);
|
|
151480
|
+
}
|
|
152210
151481
|
const { startDate, endDate } = assertTikTokOfficialReportRange(opts.start, opts.end, dimensions);
|
|
152211
151482
|
const serviceType = (opts.serviceType ?? "AUCTION").trim() || "AUCTION";
|
|
152212
151483
|
const pageSize = resolveTikTokPageSize(opts.pageSize, TIKTOK_REPORT_PAGE_SIZE_DEFAULT);
|
|
@@ -152450,12 +151721,700 @@ async function runTikTokAdStatus(opts) {
|
|
|
152450
151721
|
);
|
|
152451
151722
|
}
|
|
152452
151723
|
|
|
152453
|
-
// src/commands/tiktok-analysis/
|
|
151724
|
+
// src/commands/tiktok-analysis/media-run.ts
|
|
151725
|
+
init_dist();
|
|
151726
|
+
init_auth();
|
|
151727
|
+
init_cli_json_snapshot();
|
|
151728
|
+
import { readFileSync as readFileSync21 } from "fs";
|
|
151729
|
+
import { basename as basename14 } from "path";
|
|
151730
|
+
init_cli_table();
|
|
151731
|
+
|
|
151732
|
+
// src/commands/tiktok-analysis/media.ts
|
|
151733
|
+
var TIKTOK_IDENTITY_TYPES = [
|
|
151734
|
+
"CUSTOMIZED_USER",
|
|
151735
|
+
"AUTH_CODE",
|
|
151736
|
+
"TT_USER",
|
|
151737
|
+
"BC_AUTH_TT"
|
|
151738
|
+
];
|
|
151739
|
+
var PIXEL_PAGE_SIZE_MAX = 20;
|
|
151740
|
+
var LIST_PAGE_SIZE_DEFAULT = 100;
|
|
151741
|
+
function assertHttpsAssetUrl(raw, label2) {
|
|
151742
|
+
const text5 = (raw ?? "").trim();
|
|
151743
|
+
let parsed;
|
|
151744
|
+
try {
|
|
151745
|
+
parsed = new URL(text5);
|
|
151746
|
+
} catch {
|
|
151747
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F https \u5730\u5740\u3002\u7F51\u5173\u4E0D\u63A5\u6536\u672C\u5730\u6587\u4EF6`);
|
|
151748
|
+
}
|
|
151749
|
+
if (parsed.protocol !== "https:") {
|
|
151750
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F https \u5730\u5740\u3002\u7F51\u5173\u4E0D\u63A5\u6536\u672C\u5730\u6587\u4EF6`);
|
|
151751
|
+
}
|
|
151752
|
+
return text5;
|
|
151753
|
+
}
|
|
151754
|
+
function imageUploadBody(advertiserId, imageUrl) {
|
|
151755
|
+
return {
|
|
151756
|
+
advertiser_id: advertiserId,
|
|
151757
|
+
upload_type: "UPLOAD_BY_URL",
|
|
151758
|
+
image_url: assertHttpsAssetUrl(imageUrl, "\u56FE\u7247\u5730\u5740")
|
|
151759
|
+
};
|
|
151760
|
+
}
|
|
151761
|
+
function imageUploadPath(account) {
|
|
151762
|
+
return `tiktokadmanagement/ad/UploadImage/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(account)}`;
|
|
151763
|
+
}
|
|
151764
|
+
function videoUploadBody(advertiserId, videoUrl, fileName) {
|
|
151765
|
+
const name2 = fileName?.trim();
|
|
151766
|
+
return {
|
|
151767
|
+
advertiser_id: advertiserId,
|
|
151768
|
+
upload_type: "UPLOAD_BY_URL",
|
|
151769
|
+
video_url: assertHttpsAssetUrl(videoUrl, "\u89C6\u9891\u5730\u5740"),
|
|
151770
|
+
...name2 ? { file_name: name2 } : {},
|
|
151771
|
+
flaw_detect: false,
|
|
151772
|
+
auto_fix_enabled: false,
|
|
151773
|
+
auto_bind_enabled: false
|
|
151774
|
+
};
|
|
151775
|
+
}
|
|
151776
|
+
function videoUploadPath() {
|
|
151777
|
+
return `tiktokadmanagement/ad/UploadVideo/${TIKTOK_MEDIA_TYPE}`;
|
|
151778
|
+
}
|
|
151779
|
+
function videoUploadByUrlBody(advertiserId, videoUrl, videoName) {
|
|
151780
|
+
const name2 = videoName?.trim();
|
|
151781
|
+
return {
|
|
151782
|
+
MediaCustomerId: advertiserId,
|
|
151783
|
+
VideoUrl: assertHttpsAssetUrl(videoUrl, "\u89C6\u9891\u5730\u5740"),
|
|
151784
|
+
...name2 ? { VideoName: name2 } : {}
|
|
151785
|
+
};
|
|
151786
|
+
}
|
|
151787
|
+
function videoUploadByUrlPath() {
|
|
151788
|
+
return `tiktokadmanagement/ad/UploadVideoByUrl/${TIKTOK_MEDIA_TYPE}`;
|
|
151789
|
+
}
|
|
151790
|
+
function videoInfoQuery(account, videoIds, materialIds) {
|
|
151791
|
+
const videos = splitIds(videoIds, "video-ids");
|
|
151792
|
+
const materials = splitIds(materialIds, "material-ids");
|
|
151793
|
+
if (videos.length === 0 && materials.length === 0) {
|
|
151794
|
+
throw new Error("video-info \u8981 --video-ids \u6216 --material-ids");
|
|
151795
|
+
}
|
|
151796
|
+
const q = new URLSearchParams({ mediacustomerId: account });
|
|
151797
|
+
if (videos.length > 0) q.set("videoIds", videos.join(","));
|
|
151798
|
+
if (materials.length > 0) q.set("material_ids", materials.join(","));
|
|
151799
|
+
return `tiktokadmanagement/ad/getvideoinfo/${TIKTOK_MEDIA_TYPE}?${q}`;
|
|
151800
|
+
}
|
|
151801
|
+
function parseIdentityType(raw) {
|
|
151802
|
+
const text5 = (raw ?? "").trim();
|
|
151803
|
+
if (!text5) return void 0;
|
|
151804
|
+
const value = text5.toUpperCase();
|
|
151805
|
+
if (!TIKTOK_IDENTITY_TYPES.includes(value)) {
|
|
151806
|
+
throw new Error(`identity-type \u53EA\u63A5\u53D7 ${TIKTOK_IDENTITY_TYPES.join(" / ")}`);
|
|
151807
|
+
}
|
|
151808
|
+
return value;
|
|
151809
|
+
}
|
|
151810
|
+
function identityListPath(account, pageNum, pageSize, identityType) {
|
|
151811
|
+
const q = new URLSearchParams({
|
|
151812
|
+
mediacustomerId: account,
|
|
151813
|
+
pageNum: String(pageNum),
|
|
151814
|
+
pageSize: String(pageSize)
|
|
151815
|
+
});
|
|
151816
|
+
const type = parseIdentityType(identityType);
|
|
151817
|
+
if (type) q.set("IdentityType", type);
|
|
151818
|
+
return `tiktokadmanagement/ad/${TIKTOK_MEDIA_TYPE}/GetIdentityIdList?${q}`;
|
|
151819
|
+
}
|
|
151820
|
+
function identityCreateBody(advertiserId, displayName, imageUri) {
|
|
151821
|
+
const display_name = (displayName ?? "").trim();
|
|
151822
|
+
const image_uri = (imageUri ?? "").trim();
|
|
151823
|
+
if (!display_name) throw new Error("display-name \u4E0D\u80FD\u4E3A\u7A7A");
|
|
151824
|
+
if (!image_uri) {
|
|
151825
|
+
throw new Error("image-uri \u4E0D\u80FD\u4E3A\u7A7A\u3002\u5148 image-upload\uFF0C\u7528\u8FD4\u56DE\u7684 image_id");
|
|
151826
|
+
}
|
|
151827
|
+
return { advertiser_id: advertiserId, display_name, image_uri };
|
|
151828
|
+
}
|
|
151829
|
+
function identityCreatePath() {
|
|
151830
|
+
return `tiktokadmanagement/ad/CreateIdentity/${TIKTOK_MEDIA_TYPE}`;
|
|
151831
|
+
}
|
|
151832
|
+
function audienceListPath(account, pageNum, pageSize, audienceIds) {
|
|
151833
|
+
const q = new URLSearchParams({
|
|
151834
|
+
mediacustomerId: account,
|
|
151835
|
+
pageNum: String(pageNum),
|
|
151836
|
+
pageSize: String(pageSize)
|
|
151837
|
+
});
|
|
151838
|
+
const ids = splitIds(audienceIds, "audience-ids");
|
|
151839
|
+
if (ids.length > 0) q.set("customAudienceIds", ids.join(","));
|
|
151840
|
+
return `tiktokadgroupmanagement/adgroup/${TIKTOK_MEDIA_TYPE}/GetCustomAudienceList?${q}`;
|
|
151841
|
+
}
|
|
151842
|
+
function pixelListPath(account, pageNum, pageSize, filter) {
|
|
151843
|
+
const q = new URLSearchParams({
|
|
151844
|
+
mediacustomerId: account,
|
|
151845
|
+
pageNum: String(pageNum),
|
|
151846
|
+
pageSize: String(pageSize)
|
|
151847
|
+
});
|
|
151848
|
+
const code = filter?.code?.trim();
|
|
151849
|
+
const pixelId = filter?.pixelId?.trim();
|
|
151850
|
+
const name2 = filter?.name?.trim();
|
|
151851
|
+
if (code) q.set("code", code);
|
|
151852
|
+
if (pixelId) q.set("pixelId", pixelId);
|
|
151853
|
+
if (name2) q.set("name", name2);
|
|
151854
|
+
return `tiktokadgroupmanagement/adgroup/${TIKTOK_MEDIA_TYPE}/GetPixelList?${q}`;
|
|
151855
|
+
}
|
|
151856
|
+
function pixelCreateBody(advertiserId, name2, category) {
|
|
151857
|
+
const pixel_name = (name2 ?? "").trim();
|
|
151858
|
+
const pixel_category = (category ?? "").trim();
|
|
151859
|
+
if (!pixel_name || pixel_name.length > 40) {
|
|
151860
|
+
throw new Error("\u50CF\u7D20\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u4E14\u4E0D\u8D85\u8FC7 40 \u4E2A\u5B57\u7B26");
|
|
151861
|
+
}
|
|
151862
|
+
if (!pixel_category) throw new Error("pixel-category \u4E0D\u80FD\u4E3A\u7A7A");
|
|
151863
|
+
return { advertiser_id: advertiserId, pixel_name, pixel_category };
|
|
151864
|
+
}
|
|
151865
|
+
function pixelCreatePath(account) {
|
|
151866
|
+
return `tiktokadgroupmanagement/adgroup/CreatePixel/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(account)}`;
|
|
151867
|
+
}
|
|
151868
|
+
function parsePixelEvents(raw) {
|
|
151869
|
+
const text5 = (raw ?? "").trim();
|
|
151870
|
+
if (!text5) throw new Error("pixel \u4E8B\u4EF6\u9700\u8981 --events\uFF0C\u5185\u5BB9\u662F\u975E\u7A7A JSON \u6570\u7EC4");
|
|
151871
|
+
let parsed;
|
|
151872
|
+
try {
|
|
151873
|
+
parsed = JSON.parse(text5);
|
|
151874
|
+
} catch {
|
|
151875
|
+
throw new Error("pixel \u4E8B\u4EF6\u4E0D\u662F\u5408\u6CD5 JSON");
|
|
151876
|
+
}
|
|
151877
|
+
if (!Array.isArray(parsed) || parsed.length < 1) {
|
|
151878
|
+
throw new Error("pixel \u4E8B\u4EF6\u5FC5\u987B\u662F\u975E\u7A7A JSON \u6570\u7EC4");
|
|
151879
|
+
}
|
|
151880
|
+
return parsed;
|
|
151881
|
+
}
|
|
151882
|
+
function pixelEventBody(advertiserId, pixelId, events) {
|
|
151883
|
+
const pixel_id = (pixelId ?? "").trim();
|
|
151884
|
+
if (!pixel_id) throw new Error("pixel-id \u4E0D\u80FD\u4E3A\u7A7A");
|
|
151885
|
+
if (events.length < 1) throw new Error("pixel \u4E8B\u4EF6\u5FC5\u987B\u662F\u975E\u7A7A JSON \u6570\u7EC4");
|
|
151886
|
+
return { advertiser_id: advertiserId, pixel_id, pixel_events: events };
|
|
151887
|
+
}
|
|
151888
|
+
function pixelEventPath() {
|
|
151889
|
+
return `tiktokadgroupmanagement/adgroup/CreatePixelEvent/${TIKTOK_MEDIA_TYPE}`;
|
|
151890
|
+
}
|
|
151891
|
+
function assertPixelStatsRange(start, end) {
|
|
151892
|
+
const startDate = start.trim();
|
|
151893
|
+
const endDate = end.trim();
|
|
151894
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(startDate) || !/^\d{4}-\d{2}-\d{2}$/.test(endDate)) {
|
|
151895
|
+
throw new Error("pixel \u7EDF\u8BA1\u7684 start / end \u987B\u662F YYYY-MM-DD");
|
|
151896
|
+
}
|
|
151897
|
+
const startMs = Date.parse(`${startDate}T00:00:00Z`);
|
|
151898
|
+
const endMs = Date.parse(`${endDate}T00:00:00Z`);
|
|
151899
|
+
if (Number.isNaN(startMs) || Number.isNaN(endMs) || endMs < startMs) {
|
|
151900
|
+
throw new Error("pixel \u7EDF\u8BA1\u7684 end \u4E0D\u80FD\u65E9\u4E8E start");
|
|
151901
|
+
}
|
|
151902
|
+
const days = Math.round((endMs - startMs) / 864e5);
|
|
151903
|
+
if (days > 30) throw new Error("pixel \u7EDF\u8BA1\u533A\u95F4\u8DE8\u5EA6\u5FC5\u987B \u2264 30 \u5929");
|
|
151904
|
+
return { start: startDate, end: endDate };
|
|
151905
|
+
}
|
|
151906
|
+
function pixelStatsPath(account, pixelIdsRaw, start, end) {
|
|
151907
|
+
const ids = splitIds(pixelIdsRaw, "pixel-ids");
|
|
151908
|
+
if (ids.length < 1 || ids.length > 10) {
|
|
151909
|
+
throw new Error("pixel-ids \u9700\u8981 1 \u5230 10 \u4E2A\u50CF\u7D20 ID");
|
|
151910
|
+
}
|
|
151911
|
+
const range = assertPixelStatsRange(start, end);
|
|
151912
|
+
const q = new URLSearchParams({
|
|
151913
|
+
advertiser_id: account,
|
|
151914
|
+
PixelIds: ids.join(","),
|
|
151915
|
+
"date_range.start_date": range.start,
|
|
151916
|
+
"date_range.end_date": range.end
|
|
151917
|
+
});
|
|
151918
|
+
return `tiktokadgroupmanagement/adgroup/GetPixelStats/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(account)}?${q}`;
|
|
151919
|
+
}
|
|
151920
|
+
function ctaPortfolioPath(account, contentType, assetType) {
|
|
151921
|
+
const content = (contentType ?? "").trim();
|
|
151922
|
+
const asset = (assetType ?? "").trim();
|
|
151923
|
+
if (!content || !asset) throw new Error("content-type \u548C asset-type \u90FD\u4E0D\u80FD\u4E3A\u7A7A");
|
|
151924
|
+
const q = new URLSearchParams({
|
|
151925
|
+
mediacustomerId: account,
|
|
151926
|
+
contentType: content,
|
|
151927
|
+
assetType: asset
|
|
151928
|
+
});
|
|
151929
|
+
return `tiktokadmanagement/ad/${TIKTOK_MEDIA_TYPE}/GetPortfolio?${q}`;
|
|
151930
|
+
}
|
|
151931
|
+
function smartTextBody(advertiserId, input) {
|
|
151932
|
+
const keywords = splitIds(input.keywords, "keywords");
|
|
151933
|
+
const adgroup_id = input.adgroupId?.trim();
|
|
151934
|
+
const industry_id = input.industryId?.trim();
|
|
151935
|
+
if (!adgroup_id) {
|
|
151936
|
+
throw new Error("\u667A\u80FD\u6587\u6848\u5FC5\u987B\u5E26 adgroup-id\uFF0C\u5B98\u65B9\u63A5\u53E3\u4E0D\u63A5\u53D7\u53EA\u6709\u5173\u952E\u8BCD\u6216\u884C\u4E1A\u7684\u8BF7\u6C42");
|
|
151937
|
+
}
|
|
151938
|
+
const language = input.language?.trim();
|
|
151939
|
+
const param_type = input.paramType?.trim();
|
|
151940
|
+
let limit;
|
|
151941
|
+
if (input.limit != null && input.limit.trim() !== "") {
|
|
151942
|
+
limit = Number(input.limit.trim());
|
|
151943
|
+
if (!Number.isInteger(limit) || limit <= 0) throw new Error("limit \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6574\u6570");
|
|
151944
|
+
}
|
|
151945
|
+
return {
|
|
151946
|
+
advertiser_id: advertiserId,
|
|
151947
|
+
...adgroup_id ? { adgroup_id } : {},
|
|
151948
|
+
...param_type ? { param_type } : {},
|
|
151949
|
+
...language ? { language } : {},
|
|
151950
|
+
...industry_id ? { industry_id } : {},
|
|
151951
|
+
...keywords.length > 0 ? { keywords } : {},
|
|
151952
|
+
...limit != null ? { limit } : {}
|
|
151953
|
+
};
|
|
151954
|
+
}
|
|
151955
|
+
function smartTextPath() {
|
|
151956
|
+
return `tiktokadmanagement/ad/${TIKTOK_MEDIA_TYPE}/GetSmartText`;
|
|
151957
|
+
}
|
|
151958
|
+
function resolveMediaPageSize(raw, kind) {
|
|
151959
|
+
const fallback = kind === "pixel" ? PIXEL_PAGE_SIZE_MAX : LIST_PAGE_SIZE_DEFAULT;
|
|
151960
|
+
const size = resolveTikTokPageSize(raw, fallback);
|
|
151961
|
+
return kind === "pixel" ? Math.min(size, PIXEL_PAGE_SIZE_MAX) : size;
|
|
151962
|
+
}
|
|
151963
|
+
function splitIds(raw, label2) {
|
|
151964
|
+
if (raw == null || raw.trim() === "") return [];
|
|
151965
|
+
const ids = raw.split(",").map((part) => part.trim()).filter(Boolean);
|
|
151966
|
+
if (raw.trim() !== "" && ids.length === 0) {
|
|
151967
|
+
throw new Error(`${label2} \u4E0D\u80FD\u662F\u7A7A\u5217\u8868`);
|
|
151968
|
+
}
|
|
151969
|
+
return ids;
|
|
151970
|
+
}
|
|
151971
|
+
|
|
151972
|
+
// src/commands/tiktok-analysis/media-run.ts
|
|
151973
|
+
function fail8(label2, err) {
|
|
151974
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
151975
|
+
console.error(`
|
|
151976
|
+
\u274C ${label2}\uFF1A${msg}
|
|
151977
|
+
`);
|
|
151978
|
+
process.exit(1);
|
|
151979
|
+
}
|
|
151980
|
+
function assertBusinessOk(payload, label2) {
|
|
151981
|
+
if (!payload || typeof payload !== "object") return;
|
|
151982
|
+
const code = payload.code;
|
|
151983
|
+
if (code === void 0 || code === 0 || code === "0") return;
|
|
151984
|
+
const message = payload.message ?? "\u672A\u77E5\u9519\u8BEF";
|
|
151985
|
+
throw new Error(`${label2} \u4E1A\u52A1\u5931\u8D25 code=${String(code)}\uFF1A${message}`);
|
|
151986
|
+
}
|
|
151987
|
+
async function requestTikTok(method, path61, body, opts, section, commandLabel) {
|
|
151988
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151989
|
+
const config = loadConfig(opts.token);
|
|
151990
|
+
const url = `${requireTikTokApiUrl(config)}/${path61}`;
|
|
151991
|
+
const payload = await apiFetch2(
|
|
151992
|
+
url,
|
|
151993
|
+
config,
|
|
151994
|
+
method === "POST" ? { method: "POST", body: JSON.stringify(body) } : {},
|
|
151995
|
+
opts.verbose
|
|
151996
|
+
);
|
|
151997
|
+
assertBusinessOk(payload, commandLabel);
|
|
151998
|
+
const emitted = await emitCliJsonOrSnapshot(
|
|
151999
|
+
{ jsonOut: opts.jsonOut },
|
|
152000
|
+
{ section, commandLabel, payload, idSuffix: advertiserId }
|
|
152001
|
+
);
|
|
152002
|
+
if (emitted) return;
|
|
152003
|
+
console.log(`
|
|
152004
|
+
\u2705 ${commandLabel}
|
|
152005
|
+
`);
|
|
152006
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
152007
|
+
console.log();
|
|
152008
|
+
}
|
|
152009
|
+
async function requestTikTokList(buildPath, opts, kind, section, commandLabel, columns) {
|
|
152010
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
152011
|
+
const config = loadConfig(opts.token);
|
|
152012
|
+
const base2 = requireTikTokApiUrl(config);
|
|
152013
|
+
const pageSize = resolveMediaPageSize(opts.pageSize, kind);
|
|
152014
|
+
let result;
|
|
152015
|
+
try {
|
|
152016
|
+
result = await fetchTikTokPagedList(
|
|
152017
|
+
config,
|
|
152018
|
+
(pageNum, size) => `${base2}/${buildPath(pageNum, size)}`,
|
|
152019
|
+
{ pageSize, verbose: !!opts.verbose, label: commandLabel }
|
|
152020
|
+
);
|
|
152021
|
+
} catch (err) {
|
|
152022
|
+
fail8(commandLabel, err);
|
|
152023
|
+
}
|
|
152024
|
+
const payload = wrapListJson({
|
|
152025
|
+
page: 1,
|
|
152026
|
+
pageSize,
|
|
152027
|
+
total: result.totalNumber,
|
|
152028
|
+
items: result.items
|
|
152029
|
+
});
|
|
152030
|
+
if (await emitCliJsonOrSnapshot(
|
|
152031
|
+
{ jsonOut: opts.jsonOut },
|
|
152032
|
+
{ section, commandLabel, payload, idSuffix: advertiserId }
|
|
152033
|
+
)) {
|
|
152034
|
+
return;
|
|
152035
|
+
}
|
|
152036
|
+
console.log(`
|
|
152037
|
+
${commandLabel}\uFF08${advertiserId}\uFF0C\u5171 ${result.totalNumber} \u6761\uFF09
|
|
152038
|
+
`);
|
|
152039
|
+
if (result.items.length === 0) {
|
|
152040
|
+
console.log(" \u6682\u65E0\u6570\u636E\u3002\n");
|
|
152041
|
+
return;
|
|
152042
|
+
}
|
|
152043
|
+
printCliTable(
|
|
152044
|
+
result.items.map((row) => {
|
|
152045
|
+
const out = {};
|
|
152046
|
+
for (const column of columns) out[column.key] = pick2(row, column.fields);
|
|
152047
|
+
return out;
|
|
152048
|
+
}),
|
|
152049
|
+
columns.map((column) => ({ key: column.key, header: column.header }))
|
|
152050
|
+
);
|
|
152051
|
+
}
|
|
152052
|
+
function pick2(row, fields) {
|
|
152053
|
+
for (const field6 of fields) {
|
|
152054
|
+
const value = row[field6];
|
|
152055
|
+
if (value != null && value !== "") return String(value);
|
|
152056
|
+
}
|
|
152057
|
+
return "";
|
|
152058
|
+
}
|
|
152059
|
+
function assertCtaCommit() {
|
|
152060
|
+
if (isWriteAuditCommitRequiredSatisfied()) return;
|
|
152061
|
+
console.error(
|
|
152062
|
+
'\n\u274C \u8FD9\u6761\u547D\u4EE4\u4F1A\u521B\u5EFA CTA \u7EC4\u5408\uFF0C\u5FC5\u987B\u63D0\u4F9B\u8BF4\u660E\uFF1A\u8BF7\u5728\u547D\u4EE4\u672B\u5C3E\u52A0 --commit "\u7B80\u77ED\u8BF4\u660E"\n'
|
|
152063
|
+
);
|
|
152064
|
+
process.exit(1);
|
|
152065
|
+
}
|
|
152066
|
+
async function runTikTokImageUpload(opts) {
|
|
152067
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152068
|
+
let body;
|
|
152069
|
+
try {
|
|
152070
|
+
body = imageUploadBody(account, opts.imageUrl);
|
|
152071
|
+
} catch (err) {
|
|
152072
|
+
fail8("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25", err);
|
|
152073
|
+
}
|
|
152074
|
+
try {
|
|
152075
|
+
await requestTikTok("POST", imageUploadPath(account), body, opts, "tiktok-image-upload", "tiktok-analysis image-upload");
|
|
152076
|
+
} catch (err) {
|
|
152077
|
+
fail8("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25", err);
|
|
152078
|
+
}
|
|
152079
|
+
}
|
|
152080
|
+
async function runTikTokVideoUpload(opts) {
|
|
152081
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152082
|
+
let body;
|
|
152083
|
+
try {
|
|
152084
|
+
body = videoUploadBody(account, opts.videoUrl, opts.name);
|
|
152085
|
+
} catch (err) {
|
|
152086
|
+
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
152087
|
+
}
|
|
152088
|
+
try {
|
|
152089
|
+
await requestTikTok("POST", videoUploadPath(), body, opts, "tiktok-video-upload", "tiktok-analysis video-upload");
|
|
152090
|
+
} catch (err) {
|
|
152091
|
+
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
152092
|
+
}
|
|
152093
|
+
}
|
|
152094
|
+
async function runTikTokVideoUploadByUrl(opts) {
|
|
152095
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152096
|
+
let body;
|
|
152097
|
+
try {
|
|
152098
|
+
body = videoUploadByUrlBody(account, opts.videoUrl, opts.name);
|
|
152099
|
+
} catch (err) {
|
|
152100
|
+
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
152101
|
+
}
|
|
152102
|
+
try {
|
|
152103
|
+
await requestTikTok(
|
|
152104
|
+
"POST",
|
|
152105
|
+
videoUploadByUrlPath(),
|
|
152106
|
+
body,
|
|
152107
|
+
opts,
|
|
152108
|
+
"tiktok-video-upload-url",
|
|
152109
|
+
"tiktok-analysis video-upload-url"
|
|
152110
|
+
);
|
|
152111
|
+
} catch (err) {
|
|
152112
|
+
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
152113
|
+
}
|
|
152114
|
+
}
|
|
152115
|
+
async function runTikTokVideoInfo(opts) {
|
|
152116
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152117
|
+
let path61;
|
|
152118
|
+
try {
|
|
152119
|
+
path61 = videoInfoQuery(account, opts.videoIds, opts.materialIds);
|
|
152120
|
+
} catch (err) {
|
|
152121
|
+
fail8("\u67E5\u8BE2\u89C6\u9891\u5931\u8D25", err);
|
|
152122
|
+
}
|
|
152123
|
+
try {
|
|
152124
|
+
await requestTikTok("GET", path61, void 0, opts, "tiktok-video-info", "tiktok-analysis video-info");
|
|
152125
|
+
} catch (err) {
|
|
152126
|
+
fail8("\u67E5\u8BE2\u89C6\u9891\u5931\u8D25", err);
|
|
152127
|
+
}
|
|
152128
|
+
}
|
|
152129
|
+
async function runTikTokIdentityList(opts) {
|
|
152130
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152131
|
+
try {
|
|
152132
|
+
await requestTikTokList(
|
|
152133
|
+
(pageNum, pageSize) => identityListPath(account, pageNum, pageSize, opts.identityType),
|
|
152134
|
+
opts,
|
|
152135
|
+
"list",
|
|
152136
|
+
"tiktok-identity-list",
|
|
152137
|
+
"tiktok-analysis identity-list",
|
|
152138
|
+
[
|
|
152139
|
+
{ key: "identityId", header: "\u8EAB\u4EFDID", fields: ["identity_id", "identityId"] },
|
|
152140
|
+
{ key: "identityType", header: "\u7C7B\u578B", fields: ["identity_type", "identityType"] },
|
|
152141
|
+
{ key: "displayName", header: "\u540D\u79F0", fields: ["display_name", "displayName"] }
|
|
152142
|
+
]
|
|
152143
|
+
);
|
|
152144
|
+
} catch (err) {
|
|
152145
|
+
fail8("\u67E5\u8BE2\u8EAB\u4EFD\u5931\u8D25", err);
|
|
152146
|
+
}
|
|
152147
|
+
}
|
|
152148
|
+
async function runTikTokIdentityCreate(opts) {
|
|
152149
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152150
|
+
let body;
|
|
152151
|
+
try {
|
|
152152
|
+
body = identityCreateBody(account, opts.displayName, opts.imageUri);
|
|
152153
|
+
} catch (err) {
|
|
152154
|
+
fail8("\u521B\u5EFA\u8EAB\u4EFD\u5931\u8D25", err);
|
|
152155
|
+
}
|
|
152156
|
+
try {
|
|
152157
|
+
await requestTikTok(
|
|
152158
|
+
"POST",
|
|
152159
|
+
identityCreatePath(),
|
|
152160
|
+
body,
|
|
152161
|
+
opts,
|
|
152162
|
+
"tiktok-identity-create",
|
|
152163
|
+
"tiktok-analysis identity-create"
|
|
152164
|
+
);
|
|
152165
|
+
} catch (err) {
|
|
152166
|
+
fail8("\u521B\u5EFA\u8EAB\u4EFD\u5931\u8D25", err);
|
|
152167
|
+
}
|
|
152168
|
+
}
|
|
152169
|
+
async function runTikTokAudienceList(opts) {
|
|
152170
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152171
|
+
try {
|
|
152172
|
+
await requestTikTokList(
|
|
152173
|
+
(pageNum, pageSize) => audienceListPath(account, pageNum, pageSize, opts.audienceIds),
|
|
152174
|
+
opts,
|
|
152175
|
+
"list",
|
|
152176
|
+
"tiktok-audience-list",
|
|
152177
|
+
"tiktok-analysis audience-list",
|
|
152178
|
+
[
|
|
152179
|
+
{ key: "audienceId", header: "\u53D7\u4F17ID", fields: ["audience_id", "custom_audience_id"] },
|
|
152180
|
+
{ key: "name", header: "\u540D\u79F0", fields: ["name", "custom_audience_name"] },
|
|
152181
|
+
{ key: "audienceType", header: "\u7C7B\u578B", fields: ["audience_type"] }
|
|
152182
|
+
]
|
|
152183
|
+
);
|
|
152184
|
+
} catch (err) {
|
|
152185
|
+
fail8("\u67E5\u8BE2\u53D7\u4F17\u5931\u8D25", err);
|
|
152186
|
+
}
|
|
152187
|
+
}
|
|
152188
|
+
async function runTikTokPixelList(opts) {
|
|
152189
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152190
|
+
try {
|
|
152191
|
+
await requestTikTokList(
|
|
152192
|
+
(pageNum, pageSize) => pixelListPath(account, pageNum, pageSize, {
|
|
152193
|
+
code: opts.code,
|
|
152194
|
+
pixelId: opts.pixelId,
|
|
152195
|
+
name: opts.name
|
|
152196
|
+
}),
|
|
152197
|
+
opts,
|
|
152198
|
+
"pixel",
|
|
152199
|
+
"tiktok-pixel-list",
|
|
152200
|
+
"tiktok-analysis pixel-list",
|
|
152201
|
+
[
|
|
152202
|
+
{ key: "pixelId", header: "\u50CF\u7D20ID", fields: ["pixel_id"] },
|
|
152203
|
+
{ key: "name", header: "\u540D\u79F0", fields: ["pixel_name", "name"] },
|
|
152204
|
+
{ key: "code", header: "\u4EE3\u7801", fields: ["pixel_code", "code"] }
|
|
152205
|
+
]
|
|
152206
|
+
);
|
|
152207
|
+
} catch (err) {
|
|
152208
|
+
fail8("\u67E5\u8BE2\u50CF\u7D20\u5931\u8D25", err);
|
|
152209
|
+
}
|
|
152210
|
+
}
|
|
152211
|
+
async function runTikTokPixelCreate(opts) {
|
|
152212
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152213
|
+
let body;
|
|
152214
|
+
try {
|
|
152215
|
+
body = pixelCreateBody(account, opts.name, opts.pixelCategory);
|
|
152216
|
+
} catch (err) {
|
|
152217
|
+
fail8("\u521B\u5EFA\u50CF\u7D20\u5931\u8D25", err);
|
|
152218
|
+
}
|
|
152219
|
+
try {
|
|
152220
|
+
await requestTikTok(
|
|
152221
|
+
"POST",
|
|
152222
|
+
pixelCreatePath(account),
|
|
152223
|
+
body,
|
|
152224
|
+
opts,
|
|
152225
|
+
"tiktok-pixel-create",
|
|
152226
|
+
"tiktok-analysis pixel-create"
|
|
152227
|
+
);
|
|
152228
|
+
} catch (err) {
|
|
152229
|
+
fail8("\u521B\u5EFA\u50CF\u7D20\u5931\u8D25", err);
|
|
152230
|
+
}
|
|
152231
|
+
}
|
|
152232
|
+
async function runTikTokPixelEventCreate(opts) {
|
|
152233
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152234
|
+
let body;
|
|
152235
|
+
try {
|
|
152236
|
+
body = pixelEventBody(account, opts.pixelId, parsePixelEvents(opts.events));
|
|
152237
|
+
} catch (err) {
|
|
152238
|
+
fail8("\u521B\u5EFA\u50CF\u7D20\u4E8B\u4EF6\u5931\u8D25", err);
|
|
152239
|
+
}
|
|
152240
|
+
try {
|
|
152241
|
+
await requestTikTok(
|
|
152242
|
+
"POST",
|
|
152243
|
+
pixelEventPath(),
|
|
152244
|
+
body,
|
|
152245
|
+
opts,
|
|
152246
|
+
"tiktok-pixel-event-create",
|
|
152247
|
+
"tiktok-analysis pixel-event-create"
|
|
152248
|
+
);
|
|
152249
|
+
} catch (err) {
|
|
152250
|
+
fail8("\u521B\u5EFA\u50CF\u7D20\u4E8B\u4EF6\u5931\u8D25", err);
|
|
152251
|
+
}
|
|
152252
|
+
}
|
|
152253
|
+
async function runTikTokPixelStats(opts) {
|
|
152254
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152255
|
+
let path61;
|
|
152256
|
+
try {
|
|
152257
|
+
path61 = pixelStatsPath(account, opts.pixelIds, opts.start, opts.end);
|
|
152258
|
+
} catch (err) {
|
|
152259
|
+
fail8("\u67E5\u8BE2\u50CF\u7D20\u7EDF\u8BA1\u5931\u8D25", err);
|
|
152260
|
+
}
|
|
152261
|
+
try {
|
|
152262
|
+
await requestTikTok("GET", path61, void 0, opts, "tiktok-pixel-stats", "tiktok-analysis pixel-stats");
|
|
152263
|
+
} catch (err) {
|
|
152264
|
+
fail8("\u67E5\u8BE2\u50CF\u7D20\u7EDF\u8BA1\u5931\u8D25", err);
|
|
152265
|
+
}
|
|
152266
|
+
}
|
|
152267
|
+
async function runTikTokCtaRecommendCreate(opts) {
|
|
152268
|
+
assertCtaCommit();
|
|
152269
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152270
|
+
let path61;
|
|
152271
|
+
try {
|
|
152272
|
+
path61 = ctaPortfolioPath(account, opts.contentType, opts.assetType);
|
|
152273
|
+
} catch (err) {
|
|
152274
|
+
fail8("\u521B\u5EFA CTA \u7EC4\u5408\u5931\u8D25", err);
|
|
152275
|
+
}
|
|
152276
|
+
try {
|
|
152277
|
+
await requestTikTok(
|
|
152278
|
+
"GET",
|
|
152279
|
+
path61,
|
|
152280
|
+
void 0,
|
|
152281
|
+
opts,
|
|
152282
|
+
"tiktok-cta-recommend-create",
|
|
152283
|
+
"tiktok-analysis cta-recommend-create"
|
|
152284
|
+
);
|
|
152285
|
+
} catch (err) {
|
|
152286
|
+
fail8("\u521B\u5EFA CTA \u7EC4\u5408\u5931\u8D25", err);
|
|
152287
|
+
}
|
|
152288
|
+
}
|
|
152289
|
+
var AUDIENCE_FILE_MAX_BYTES = 50 * 1024 * 1024;
|
|
152290
|
+
function audienceFileContentType(filename) {
|
|
152291
|
+
const lower = filename.toLowerCase();
|
|
152292
|
+
if (lower.endsWith(".csv")) return "text/csv";
|
|
152293
|
+
if (lower.endsWith(".txt")) return "text/plain";
|
|
152294
|
+
return "application/octet-stream";
|
|
152295
|
+
}
|
|
152296
|
+
async function runTikTokAudienceFileUpload(opts) {
|
|
152297
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152298
|
+
const calculate = (opts.calculateType ?? "").trim();
|
|
152299
|
+
const filePath = (opts.file ?? "").trim();
|
|
152300
|
+
if (!calculate || calculate.length > 40) {
|
|
152301
|
+
fail8("\u4E0A\u4F20\u53D7\u4F17\u6587\u4EF6\u5931\u8D25", new Error("calculate-type \u957F\u5EA6\u5FC5\u987B\u662F 1 \u5230 40"));
|
|
152302
|
+
}
|
|
152303
|
+
if (!filePath) {
|
|
152304
|
+
fail8("\u4E0A\u4F20\u53D7\u4F17\u6587\u4EF6\u5931\u8D25", new Error("\u53D7\u4F17\u6587\u4EF6\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A"));
|
|
152305
|
+
}
|
|
152306
|
+
let data;
|
|
152307
|
+
try {
|
|
152308
|
+
data = readFileSync21(filePath);
|
|
152309
|
+
} catch (err) {
|
|
152310
|
+
fail8("\u4E0A\u4F20\u53D7\u4F17\u6587\u4EF6\u5931\u8D25", err);
|
|
152311
|
+
}
|
|
152312
|
+
if (data.length <= 0 || data.length > AUDIENCE_FILE_MAX_BYTES) {
|
|
152313
|
+
fail8("\u4E0A\u4F20\u53D7\u4F17\u6587\u4EF6\u5931\u8D25", new Error("\u53D7\u4F17\u6587\u4EF6\u5FC5\u987B\u5927\u4E8E 0\uFF0C\u4E14\u4E0D\u8D85\u8FC7 50MB"));
|
|
152314
|
+
}
|
|
152315
|
+
const filename = basename14(filePath);
|
|
152316
|
+
try {
|
|
152317
|
+
const config = loadConfig(opts.token);
|
|
152318
|
+
const url = `${requireTikTokApiUrl(config)}/tiktokgap/audiences/file-upload`;
|
|
152319
|
+
const payload = await apiFetchMultipart2(
|
|
152320
|
+
url,
|
|
152321
|
+
config,
|
|
152322
|
+
{
|
|
152323
|
+
fields: { advertiser_id: account, calculate_type: calculate },
|
|
152324
|
+
files: [{ field: "file", filename, contentType: audienceFileContentType(filename), data }]
|
|
152325
|
+
},
|
|
152326
|
+
!!opts.verbose
|
|
152327
|
+
);
|
|
152328
|
+
assertBusinessOk(payload, "tiktok-analysis audience-file-upload");
|
|
152329
|
+
const emitted = await emitCliJsonOrSnapshot(
|
|
152330
|
+
{ jsonOut: opts.jsonOut },
|
|
152331
|
+
{
|
|
152332
|
+
section: "tiktok-audience-file-upload",
|
|
152333
|
+
commandLabel: "tiktok-analysis audience-file-upload",
|
|
152334
|
+
payload,
|
|
152335
|
+
idSuffix: account
|
|
152336
|
+
}
|
|
152337
|
+
);
|
|
152338
|
+
if (emitted) return;
|
|
152339
|
+
console.log("\n\u2705 tiktok-analysis audience-file-upload\n");
|
|
152340
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
152341
|
+
console.log();
|
|
152342
|
+
} catch (err) {
|
|
152343
|
+
fail8("\u4E0A\u4F20\u53D7\u4F17\u6587\u4EF6\u5931\u8D25", err);
|
|
152344
|
+
}
|
|
152345
|
+
}
|
|
152346
|
+
async function runTikTokSmartText(opts) {
|
|
152347
|
+
const account = assertTikTokAccountId(opts.account);
|
|
152348
|
+
let body;
|
|
152349
|
+
try {
|
|
152350
|
+
body = smartTextBody(account, opts);
|
|
152351
|
+
} catch (err) {
|
|
152352
|
+
fail8("\u751F\u6210\u667A\u80FD\u6587\u6848\u5931\u8D25", err);
|
|
152353
|
+
}
|
|
152354
|
+
try {
|
|
152355
|
+
await requestTikTok("POST", smartTextPath(), body, opts, "tiktok-smart-text", "tiktok-analysis smart-text");
|
|
152356
|
+
} catch (err) {
|
|
152357
|
+
fail8("\u751F\u6210\u667A\u80FD\u6587\u6848\u5931\u8D25", err);
|
|
152358
|
+
}
|
|
152359
|
+
}
|
|
152360
|
+
|
|
152361
|
+
// src/commands/tiktok-analysis/register-media.ts
|
|
152454
152362
|
var ACCOUNT_OPTION3 = [
|
|
152455
152363
|
"-a, --account <id>",
|
|
152456
152364
|
"TikTok \u5E7F\u544A\u4E3B mediaCustomerId\uFF08\u6570\u5B57\uFF0C\u4E0E list-accounts -m TikTok \u4E00\u81F4\uFF09"
|
|
152457
152365
|
];
|
|
152458
152366
|
var JSON_OUT_OPTION_DESC3 = "\u843D\u76D8\uFF08\u76EE\u5F55\u6216 *.json \u6587\u4EF6\u8DEF\u5F84\uFF09\u5E76\u66F4\u65B0 cli-manifest[-<\u67E5\u8BE2id>].json\uFF1Bstdout \u4E00\u884C\u6458\u8981 JSON";
|
|
152367
|
+
function registerTikTokMediaCommands(root) {
|
|
152368
|
+
root.command("image-upload").description("\u7528\u516C\u7F51 https \u5730\u5740\u4E0A\u4F20\u5E7F\u544A\u56FE\u7247\uFF08UPLOAD_BY_URL\uFF09\u3002\u8FD4\u56DE\u7684 image_id \u624D\u80FD\u5F53\u8EAB\u4EFD\u5934\u50CF\u6216\u7D20\u6750\u3002\u4E0D\u6536\u672C\u5730\u6587\u4EF6\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--image-url <url>", "https \u56FE\u7247\u5730\u5740").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152369
|
+
await runTikTokImageUpload(opts);
|
|
152370
|
+
});
|
|
152371
|
+
root.command("video-upload").description("\u7528\u516C\u7F51 https \u5730\u5740\u76F4\u63A5\u4E0A\u4F20\u5E7F\u544A\u89C6\u9891\uFF08UPLOAD_BY_URL\uFF09\uFF0C\u5E76\u5173\u95ED\u81EA\u52A8\u4FEE\u590D\u3002\u4E0D\u6536\u672C\u5730\u6587\u4EF6\uFF0C\u4E0D\u8981\u81EA\u5DF1\u62C6\u7247\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--video-url <url>", "https \u89C6\u9891\u5730\u5740").option("--name <name>", "\u6587\u4EF6\u540D").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152372
|
+
await runTikTokVideoUpload(opts);
|
|
152373
|
+
});
|
|
152374
|
+
root.command("video-upload-url").description("\u7528\u516C\u7F51 https \u5730\u5740\u7ECF\u7F51\u5173\u4E34\u65F6\u6587\u4EF6\u4E2D\u8F6C\u540E\u7ED1\u5B9A\u89C6\u9891\uFF0C\u5355\u6587\u4EF6 100MB\u3002\u4E0D\u6536\u672C\u5730\u6587\u4EF6\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--video-url <url>", "https \u89C6\u9891\u5730\u5740").option("--name <name>", "\u89C6\u9891\u540D\u79F0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152375
|
+
await runTikTokVideoUploadByUrl(opts);
|
|
152376
|
+
});
|
|
152377
|
+
root.command("video-info").description("\u6309\u89C6\u9891 ID \u6216\u7D20\u6750 ID \u67E5\u89C6\u9891\u4FE1\u606F\u3002\u4E0D\u662F\u7D20\u6750\u5E93\u5217\u8868\uFF0C\u4E24\u4E2A ID \u81F3\u5C11\u7ED9\u4E00\u4E2A").requiredOption(...ACCOUNT_OPTION3).option("--video-ids <ids>", "\u9017\u53F7\u5206\u9694\u7684 video_id").option("--material-ids <ids>", "\u9017\u53F7\u5206\u9694\u7684 material_id").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152378
|
+
await runTikTokVideoInfo({ ...opts, materialIds: opts.materialIds });
|
|
152379
|
+
});
|
|
152380
|
+
root.command("identity-list").description("\u5E7F\u544A\u8EAB\u4EFD\u5217\u8868\uFF08/identity/get/\uFF09\u3002\u53EF\u9009\u6309 identity-type \u8FC7\u6EE4").requiredOption(...ACCOUNT_OPTION3).option("--identity-type <type>", "CUSTOMIZED_USER / AUTH_CODE / TT_USER / BC_AUTH_TT").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152381
|
+
await runTikTokIdentityList(opts);
|
|
152382
|
+
});
|
|
152383
|
+
root.command("identity-create").description("\u521B\u5EFA CUSTOMIZED_USER \u8EAB\u4EFD\u3002--image-uri \u5FC5\u987B\u662F\u672C\u8D26\u6237 image-upload \u8FD4\u56DE\u7684 image_id\uFF0C\u7F51\u5173\u4E0D\u518D\u4EE3\u586B\u5934\u50CF\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--display-name <name>", "\u8EAB\u4EFD\u663E\u793A\u540D").requiredOption("--image-uri <id>", "image-upload \u8FD4\u56DE\u7684 image_id").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152384
|
+
await runTikTokIdentityCreate(opts);
|
|
152385
|
+
});
|
|
152386
|
+
root.command("audience-list").description("\u81EA\u5B9A\u4E49\u53D7\u4F17\u5217\u8868\u3002\u4E0D\u662F Lookalike \u521B\u5EFA\u6216\u91CD\u53E0\u5206\u6790").requiredOption(...ACCOUNT_OPTION3).option("--audience-ids <ids>", "\u9017\u53F7\u5206\u9694\u7684\u53D7\u4F17 ID").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152387
|
+
await runTikTokAudienceList(opts);
|
|
152388
|
+
});
|
|
152389
|
+
root.command("pixel-list").description("\u50CF\u7D20\u5217\u8868\u3002\u6BCF\u9875\u6700\u591A 20 \u6761").requiredOption(...ACCOUNT_OPTION3).option("--code <code>", "\u6309 pixel code \u8FC7\u6EE4").option("--pixel-id <id>", "\u6309\u50CF\u7D20 ID \u8FC7\u6EE4").option("--name <name>", "\u6309\u540D\u79F0\u8FC7\u6EE4").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20\uFF0C\u4E0A\u9650 20", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152390
|
+
await runTikTokPixelList(opts);
|
|
152391
|
+
});
|
|
152392
|
+
root.command("pixel-create").description("\u521B\u5EFA\u50CF\u7D20\u3002\u540D\u79F0\u4E0D\u8D85\u8FC7 40 \u4E2A\u5B57\u7B26\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--name <name>", "\u50CF\u7D20\u540D\u79F0").requiredOption("--pixel-category <category>", "\u5B98\u65B9 pixel_category").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152393
|
+
await runTikTokPixelCreate(opts);
|
|
152394
|
+
});
|
|
152395
|
+
root.command("pixel-event-create").description("\u7ED9\u50CF\u7D20\u52A0\u4E8B\u4EF6\u3002--events \u662F\u5B98\u65B9 pixel_events \u7684 JSON \u6570\u7EC4\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--pixel-id <id>", "\u50CF\u7D20 ID").requiredOption("--events <json>", "\u975E\u7A7A JSON \u6570\u7EC4").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152396
|
+
await runTikTokPixelEventCreate(opts);
|
|
152397
|
+
});
|
|
152398
|
+
root.command("pixel-stats").description("\u50CF\u7D20\u4E8B\u4EF6\u7EDF\u8BA1\u3002\u533A\u95F4\u8DE8\u5EA6\u4E0D\u8D85\u8FC7 30 \u5929\uFF0C\u4E00\u6B21 1 \u5230 10 \u4E2A\u50CF\u7D20").requiredOption(...ACCOUNT_OPTION3).requiredOption("--pixel-ids <ids>", "\u9017\u53F7\u5206\u9694\uFF0C1 \u5230 10 \u4E2A").requiredOption("--start <date>", "YYYY-MM-DD").requiredOption("--end <date>", "YYYY-MM-DD").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152399
|
+
await runTikTokPixelStats(opts);
|
|
152400
|
+
});
|
|
152401
|
+
root.command("cta-recommend-create").description("\u6309\u63A8\u8350 CTA \u7ACB\u523B\u521B\u5EFA\u7EC4\u5408\uFF08\u4E0D\u662F\u5217\u8868\uFF09\u3002\u7F51\u5173\u5148\u62C9\u63A8\u8350\u518D\u521B\u5EFA\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--content-type <type>", "\u5B98\u65B9 content_type\uFF0C\u5982 LANDING_PAGE").requiredOption("--asset-type <type>", "\u5B98\u65B9 asset_type").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152402
|
+
await runTikTokCtaRecommendCreate(opts);
|
|
152403
|
+
});
|
|
152404
|
+
root.command("smart-text").description("\u751F\u6210\u667A\u80FD\u6587\u6848\u3002\u5B98\u65B9\u8981\u6C42\u5E7F\u544A\u7EC4 ID\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").option("--param-type <type>", "\u5B98\u65B9 param_type").option("--language <lang>", "\u6587\u6848\u8BED\u8A00").option("--industry-id <id>", "\u884C\u4E1A ID").option("--keywords <list>", "\u9017\u53F7\u5206\u9694\u5173\u952E\u8BCD").option("--limit <n>", "\u6761\u6570\uFF0C\u5927\u4E8E 0 \u7684\u6574\u6570").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152405
|
+
await runTikTokSmartText(opts);
|
|
152406
|
+
});
|
|
152407
|
+
root.command("audience-file-upload").description("\u628A\u672C\u5730\u53D7\u4F17\u6587\u4EF6\u4E0A\u4F20\u5230 TikTok\u3002\u8FD4\u56DE\u7684\u8DEF\u5F84\u624D\u80FD\u7ED9 tiktok.audience-file \u7684 file_paths\u3002\u5355\u6587\u4EF6 50MB\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption(...ACCOUNT_OPTION3).requiredOption("--file <path>", "\u672C\u5730 csv \u6216 txt").requiredOption("--calculate-type <type>", "\u5B98\u65B9 calculate_type\uFF0C\u5982 EMAIL_SHA256").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152408
|
+
await runTikTokAudienceFileUpload(opts);
|
|
152409
|
+
});
|
|
152410
|
+
}
|
|
152411
|
+
|
|
152412
|
+
// src/commands/tiktok-analysis/register-cli.ts
|
|
152413
|
+
var ACCOUNT_OPTION4 = [
|
|
152414
|
+
"-a, --account <id>",
|
|
152415
|
+
"TikTok \u5E7F\u544A\u4E3B mediaCustomerId\uFF08\u6570\u5B57\uFF0C\u4E0E list-accounts -m TikTok \u4E00\u81F4\uFF09"
|
|
152416
|
+
];
|
|
152417
|
+
var JSON_OUT_OPTION_DESC4 = "\u843D\u76D8\uFF08\u76EE\u5F55\u6216 *.json \u6587\u4EF6\u8DEF\u5F84\uFF09\u5E76\u66F4\u65B0 cli-manifest[-<\u67E5\u8BE2id>].json\uFF1Bstdout \u4E00\u884C\u6458\u8981 JSON";
|
|
152459
152418
|
function registerBatchCommand3(sectionHelp, aliasHelp) {
|
|
152460
152419
|
return new Command4("run").description(
|
|
152461
152420
|
"\u6279\u91CF\u62C9\u53D6 TSO reporting/media-account/TikTok Section \u6570\u636E\uFF08\u7701\u7565\u5B50\u547D\u4EE4\u540D\u65F6\u9ED8\u8BA4\u6267\u884C\u672C\u547D\u4EE4\uFF09"
|
|
@@ -152477,7 +152436,7 @@ function registerTikTokAnalysisCommands(program2) {
|
|
|
152477
152436
|
const sectionHelp = TIKTOK_SECTION_NAMES.join(", ");
|
|
152478
152437
|
const aliasHelp = Object.keys(TIKTOK_SECTION_ALIASES).join(", ");
|
|
152479
152438
|
const root = program2.command("tiktok-analysis").description(
|
|
152480
|
-
"TikTok \u8D26\u6237\u5206\u6790\uFF1A\u6279\u91CF\u62C9\u53D6 TSO \u770B\u677F Section\uFF08\u9ED8\u8BA4\uFF09\u3001render \u5468\u671F HTML\uFF0C\
|
|
152439
|
+
"TikTok \u8D26\u6237\u5206\u6790\uFF1A\u6279\u91CF\u62C9\u53D6 TSO \u770B\u677F Section\uFF08\u9ED8\u8BA4\uFF09\u3001render \u5468\u671F HTML\uFF0C\u67E5\u8BE2\u8D26\u6237\u72B6\u6001/\u7CFB\u5217/\u7EC4/\u5E7F\u544A/\u5B98\u65B9\u62A5\u8868\uFF0C\u4EE5\u53CA\u516C\u7F51\u7D20\u6750\u3001\u8EAB\u4EFD\u3001\u50CF\u7D20\u3001\u53D7\u4F17\u5217\u8868\u3001CTA \u7EC4\u5408\u3001\u667A\u80FD\u6587\u6848"
|
|
152481
152440
|
);
|
|
152482
152441
|
root.addCommand(registerBatchCommand3(sectionHelp, aliasHelp), { isDefault: true });
|
|
152483
152442
|
root.command("render").description(
|
|
@@ -152554,25 +152513,25 @@ function registerTikTokAnalysisCommands(program2) {
|
|
|
152554
152513
|
);
|
|
152555
152514
|
root.command("account-status").description(
|
|
152556
152515
|
"\u8D26\u6237\u72B6\u6001/\u4F59\u989D/\u65F6\u533A\uFF08GET \u2026/GetAdvertiserInfo/Tiktok\uFF1BSTATUS_ENABLE \u4E3A\u6B63\u5E38\uFF1B\u987B\u62E5\u6709\u8BE5\u5E7F\u544A\u4E3B\uFF09"
|
|
152557
|
-
).requiredOption(...
|
|
152516
|
+
).requiredOption(...ACCOUNT_OPTION4).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
152558
152517
|
async (opts) => {
|
|
152559
152518
|
await runTikTokAccountStatus(opts);
|
|
152560
152519
|
}
|
|
152561
152520
|
);
|
|
152562
152521
|
root.command("campaign-entities").description(
|
|
152563
152522
|
"\u7CFB\u5217\u539F\u59CB\u5B9E\u4F53\uFF08GET \u2026/campaign/Tiktok\uFF1Abudget/budget_mode/CBO/operation_status\uFF1B\u4E0E `run --sections campaigns` \u7684\u770B\u677F\u82B1\u8D39\u4E0D\u540C\uFF09"
|
|
152564
|
-
).requiredOption(...
|
|
152523
|
+
).requiredOption(...ACCOUNT_OPTION4).option("--campaign-ids <ids>", "\u9017\u53F7\u5206\u9694\u7CFB\u5217 ID\uFF0C\u5199\u5165 filtering.CampaignIds").option(
|
|
152565
152524
|
"--page-size <n>",
|
|
152566
152525
|
"\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 1000\uFF08\u5FC5\u987B\u663E\u5F0F\u4F20\u7ED9\u7F51\u5173\uFF09",
|
|
152567
152526
|
(v) => parseInt(v, 10)
|
|
152568
|
-
).option("-t, --token <token>", "Auth Token").option("--json-out <path>",
|
|
152527
|
+
).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
152569
152528
|
async (opts) => {
|
|
152570
152529
|
await runTikTokCampaignEntities(opts);
|
|
152571
152530
|
}
|
|
152572
152531
|
);
|
|
152573
152532
|
root.command("adgroup-entities").description(
|
|
152574
152533
|
"\u5E7F\u544A\u7EC4\u539F\u59CB\u5B9E\u4F53\uFF08GET \u2026/adgroup/Tiktok\uFF1Abid_type \u4E0E\u5BF9\u5E94\u51FA\u4EF7\u3001\u7EC4\u9884\u7B97\uFF1BCBO \u65F6\u7EC4\u9884\u7B97\u4E3A 0\uFF09"
|
|
152575
|
-
).requiredOption(...
|
|
152534
|
+
).requiredOption(...ACCOUNT_OPTION4).option("--campaign-ids <ids>", "\u9017\u53F7\u5206\u9694\u7CFB\u5217 ID").option("--adgroup-ids <ids>", "\u9017\u53F7\u5206\u9694\u5E7F\u544A\u7EC4 ID").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
152576
152535
|
async (opts) => {
|
|
152577
152536
|
await runTikTokAdGroupEntities({
|
|
152578
152537
|
...opts,
|
|
@@ -152582,10 +152541,10 @@ function registerTikTokAnalysisCommands(program2) {
|
|
|
152582
152541
|
);
|
|
152583
152542
|
root.command("ad-entities").description(
|
|
152584
152543
|
`\u5E7F\u544A\u539F\u59CB\u5B9E\u4F53\uFF08GET \u2026/ad/Tiktok\uFF1A\u843D\u5730\u9875/\u62D2\u5BA1\uFF1B\u62D2\u5BA1\u4F20 --secondary-status ${TIKTOK_AD_AUDIT_DENY}\uFF09`
|
|
152585
|
-
).requiredOption(...
|
|
152544
|
+
).requiredOption(...ACCOUNT_OPTION4).option("--campaign-ids <ids>", "\u9017\u53F7\u5206\u9694\u7CFB\u5217 ID").option("--adgroup-ids <ids>", "\u9017\u53F7\u5206\u9694\u5E7F\u544A\u7EC4 ID").option("--ad-ids <ids>", "\u9017\u53F7\u5206\u9694\u5E7F\u544A ID").option(
|
|
152586
152545
|
"--secondary-status <status>",
|
|
152587
152546
|
`\u5B98\u65B9 secondary_status \u5355\u503C\uFF0C\u5982 ${TIKTOK_AD_AUDIT_DENY}\uFF1B\u52FF\u4F20\u9EC4\u6761 REVIEW_PARTIALLY_APPROVED`
|
|
152588
|
-
).option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>",
|
|
152547
|
+
).option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
152589
152548
|
async (opts) => {
|
|
152590
152549
|
await runTikTokAdEntities({
|
|
152591
152550
|
...opts,
|
|
@@ -152595,34 +152554,35 @@ function registerTikTokAnalysisCommands(program2) {
|
|
|
152595
152554
|
);
|
|
152596
152555
|
root.command("official-report").description(
|
|
152597
152556
|
"TikTokAPI \u5B98\u65B9\u62A5\u8868\uFF08GET \u2026/query/report/Tiktok/search\uFF1B\u53EF\u542B\u4ECA\u5929/\u5C0F\u65F6\uFF1B\u4E0E `run` \u7684 TSO \u770B\u677F\u5468\u671F\u62A5\u8868\u4E0D\u540C\u3002ServiceType/DataLevel/Dimensions/Metrics/\u65E5\u671F/PageSize \u5FC5\u586B\uFF09"
|
|
152598
|
-
).requiredOption(...
|
|
152557
|
+
).requiredOption(...ACCOUNT_OPTION4).requiredOption("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08\u6309\u5E7F\u544A\u4E3B timezone \u81EA\u7136\u65E5\uFF09").requiredOption("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD").requiredOption("--data-level <level>", "AUCTION_CAMPAIGN / AUCTION_ADGROUP / AUCTION_AD").requiredOption("--dimensions <list>", "\u9017\u53F7\u5206\u9694\uFF0C\u5982 campaign_id \u6216 adgroup_id,stat_time_hour").requiredOption(
|
|
152599
152558
|
"--metrics <list>",
|
|
152600
152559
|
"\u9017\u53F7\u5206\u9694\uFF0C\u82B1\u8D39\u987B\u7528 spend\uFF08\u4E0D\u8981 stat_cost\uFF09\u3002complete_payment \u662F\u7F51\u9875\u5B8C\u4ED8\u6B21\u6570\u3002\u542B\u5B8C\u4ED8/ROAS \u65F6\u81EA\u52A8\u9644\u5E26 total_purchase_value,complete_payment_roas,total_active_pay_roas"
|
|
152601
|
-
).option("--service-type <type>", "AUCTION\uFF08\u9ED8\u8BA4\uFF09\u6216 RESERVATION", "AUCTION").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 200\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>",
|
|
152560
|
+
).option("--service-type <type>", "AUCTION\uFF08\u9ED8\u8BA4\uFF09\u6216 RESERVATION", "AUCTION").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 200\uFF0C\u4E0A\u9650 1000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
152602
152561
|
async (opts) => {
|
|
152603
152562
|
await runTikTokOfficialReport(opts);
|
|
152604
152563
|
}
|
|
152605
152564
|
);
|
|
152606
|
-
root.command("campaign-status").description("\u542F\u505C\u63A8\u5E7F\u7CFB\u5217\uFF08PUT \u2026/campaign/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...
|
|
152565
|
+
root.command("campaign-status").description("\u542F\u505C\u63A8\u5E7F\u7CFB\u5217\uFF08PUT \u2026/campaign/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--campaign-id <id>", "\u63A8\u5E7F\u7CFB\u5217 ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152607
152566
|
await runTikTokCampaignStatus(opts);
|
|
152608
152567
|
});
|
|
152609
152568
|
root.command("campaign-budget").description(
|
|
152610
152569
|
"\u6539\u63A8\u5E7F\u7CFB\u5217\u9884\u7B97\uFF08PUT \u2026/campaign/update/Tiktok\uFF1B\u65E5\u9884\u7B97\u4E0E\u603B\u9884\u7B97\u4E0D\u80FD\u4E92\u5207\uFF0C\u4E0D\u652F\u6301\u4E0D\u9650\u9884\u7B97\uFF09"
|
|
152611
|
-
).requiredOption(...
|
|
152570
|
+
).requiredOption(...ACCOUNT_OPTION4).requiredOption("--campaign-id <id>", "\u63A8\u5E7F\u7CFB\u5217 ID").requiredOption("--budget <amount>", "\u9884\u7B97\uFF0C\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").requiredOption(
|
|
152612
152571
|
"--budget-mode <mode>",
|
|
152613
152572
|
"BUDGET_MODE_DAY / BUDGET_MODE_TOTAL / BUDGET_MODE_DYNAMIC_DAILY_BUDGET"
|
|
152614
|
-
).option("-t, --token <token>", "Auth Token").option("--json-out <path>",
|
|
152573
|
+
).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152615
152574
|
await runTikTokCampaignBudget(opts);
|
|
152616
152575
|
});
|
|
152617
|
-
root.command("adgroup-status").description("\u542F\u505C\u5E7F\u544A\u7EC4\uFF08PUT \u2026/adgroup/UpdateStatus/Tiktok/{entityId}\uFF1BentityId \u6309\u5E7F\u544A\u4E3B\u81EA\u52A8\u67E5\uFF09").requiredOption(...
|
|
152576
|
+
root.command("adgroup-status").description("\u542F\u505C\u5E7F\u544A\u7EC4\uFF08PUT \u2026/adgroup/UpdateStatus/Tiktok/{entityId}\uFF1BentityId \u6309\u5E7F\u544A\u4E3B\u81EA\u52A8\u67E5\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152618
152577
|
await runTikTokAdGroupStatus({ ...opts, adGroupId: opts.adgroupId });
|
|
152619
152578
|
});
|
|
152620
|
-
root.command("adgroup-budget").description("\u6539\u5E7F\u544A\u7EC4\u9884\u7B97\uFF08PUT \u2026/adgroup/UpdateBudget\uFF1BCBO \u6216\u65E0\u9650\u9884\u7B97\u65F6\u7EC4\u9884\u7B97\u53EF\u80FD\u6539\u4E0D\u52A8\uFF09").requiredOption(...
|
|
152579
|
+
root.command("adgroup-budget").description("\u6539\u5E7F\u544A\u7EC4\u9884\u7B97\uFF08PUT \u2026/adgroup/UpdateBudget\uFF1BCBO \u6216\u65E0\u9650\u9884\u7B97\u65F6\u7EC4\u9884\u7B97\u53EF\u80FD\u6539\u4E0D\u52A8\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--budget <amount>", "\u9884\u7B97\uFF0C\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152621
152580
|
await runTikTokAdGroupBudget({ ...opts, adGroupId: opts.adgroupId });
|
|
152622
152581
|
});
|
|
152623
|
-
root.command("ad-status").description("\u542F\u505C\u5E7F\u544A\uFF08PUT \u2026/ad/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...
|
|
152582
|
+
root.command("ad-status").description("\u542F\u505C\u5E7F\u544A\uFF08PUT \u2026/ad/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
152624
152583
|
await runTikTokAdStatus(opts);
|
|
152625
152584
|
});
|
|
152585
|
+
registerTikTokMediaCommands(root);
|
|
152626
152586
|
}
|
|
152627
152587
|
|
|
152628
152588
|
// src/commands/yandex-analysis/register-cli.ts
|
|
@@ -153467,12 +153427,12 @@ init_lang();
|
|
|
153467
153427
|
init_html();
|
|
153468
153428
|
var TEMPLATE_BASENAME6 = "yandex-period-report.html";
|
|
153469
153429
|
var INJECT_MARKER6 = "window.__YANDEX_PERIOD_REPORT__ = window.__YANDEX_PERIOD_REPORT__ || null;";
|
|
153470
|
-
function resolveSkillTemplatePath9(
|
|
153430
|
+
function resolveSkillTemplatePath9(basename15) {
|
|
153471
153431
|
const dir = path59.dirname(fileURLToPath15(import.meta.url));
|
|
153472
153432
|
const candidates = [
|
|
153473
|
-
path59.join(dir, "skill", "report-templates",
|
|
153474
|
-
path59.join(dir, "skill", "siluzan-ads", "report-templates",
|
|
153475
|
-
path59.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates",
|
|
153433
|
+
path59.join(dir, "skill", "report-templates", basename15),
|
|
153434
|
+
path59.join(dir, "skill", "siluzan-ads", "report-templates", basename15),
|
|
153435
|
+
path59.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename15)
|
|
153476
153436
|
];
|
|
153477
153437
|
for (const p of candidates) {
|
|
153478
153438
|
if (fs48.existsSync(p)) return p;
|
|
@@ -153722,7 +153682,7 @@ function asRecord43(raw) {
|
|
|
153722
153682
|
}
|
|
153723
153683
|
|
|
153724
153684
|
// src/commands/yandex-analysis/entities.ts
|
|
153725
|
-
function
|
|
153685
|
+
function fail9(label2, err) {
|
|
153726
153686
|
const msg = err instanceof Error ? err.message : String(err);
|
|
153727
153687
|
console.error(`
|
|
153728
153688
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -153794,7 +153754,7 @@ async function runYandexAccountStatus(opts) {
|
|
|
153794
153754
|
try {
|
|
153795
153755
|
result = await fetchPath(opts, "overview", {});
|
|
153796
153756
|
} catch (err) {
|
|
153797
|
-
|
|
153757
|
+
fail9("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
|
|
153798
153758
|
}
|
|
153799
153759
|
const row = asRecord43(result.raw);
|
|
153800
153760
|
await emitOrTable(opts, {
|
|
@@ -153836,7 +153796,7 @@ async function runYandexCampaignEntities(opts) {
|
|
|
153836
153796
|
network: flags.network
|
|
153837
153797
|
});
|
|
153838
153798
|
} catch (err) {
|
|
153839
|
-
|
|
153799
|
+
fail9("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
|
|
153840
153800
|
}
|
|
153841
153801
|
const items3 = unwrapYandexItems(result.raw);
|
|
153842
153802
|
await emitOrTable(opts, {
|
|
@@ -153882,7 +153842,7 @@ async function runYandexAdGroupEntities(opts) {
|
|
|
153882
153842
|
campaignId: flags.campaignId
|
|
153883
153843
|
});
|
|
153884
153844
|
} catch (err) {
|
|
153885
|
-
|
|
153845
|
+
fail9("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
|
|
153886
153846
|
}
|
|
153887
153847
|
const items3 = unwrapYandexItems(result.raw);
|
|
153888
153848
|
await emitOrTable(opts, {
|
|
@@ -153932,7 +153892,7 @@ async function runYandexAdEntities(opts) {
|
|
|
153932
153892
|
adGroupId: flags.adGroupId
|
|
153933
153893
|
});
|
|
153934
153894
|
} catch (err) {
|
|
153935
|
-
|
|
153895
|
+
fail9("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
|
|
153936
153896
|
}
|
|
153937
153897
|
const items3 = unwrapYandexItems(result.raw);
|
|
153938
153898
|
const filtered = flags.status != null;
|
|
@@ -153984,7 +153944,7 @@ async function runYandexInsights(opts) {
|
|
|
153984
153944
|
adGroupId: flags.adGroupId
|
|
153985
153945
|
});
|
|
153986
153946
|
} catch (err) {
|
|
153987
|
-
|
|
153947
|
+
fail9("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
|
|
153988
153948
|
}
|
|
153989
153949
|
const items3 = unwrapYandexItems(result.raw);
|
|
153990
153950
|
await emitOrTable(opts, {
|
|
@@ -154121,11 +154081,11 @@ async function runYandexKeywordBid(opts) {
|
|
|
154121
154081
|
}
|
|
154122
154082
|
|
|
154123
154083
|
// src/commands/yandex-analysis/register-cli.ts
|
|
154124
|
-
var
|
|
154084
|
+
var ACCOUNT_OPTION5 = [
|
|
154125
154085
|
"-a, --account <id>",
|
|
154126
154086
|
"Yandex Client-Login / mediaCustomerId\uFF08\u5982 porg-xxx\uFF0C\u4E0E list-accounts -m Yandex \u4E00\u81F4\uFF09"
|
|
154127
154087
|
];
|
|
154128
|
-
var
|
|
154088
|
+
var JSON_OUT_OPTION_DESC5 = "\u843D\u76D8\uFF08\u76EE\u5F55\u6216 *.json \u6587\u4EF6\u8DEF\u5F84\uFF09\u5E76\u66F4\u65B0 cli-manifest[-<\u67E5\u8BE2id>].json\uFF1Bstdout \u4E00\u884C\u6458\u8981 JSON";
|
|
154129
154089
|
var START_OPTION = [
|
|
154130
154090
|
"--start <date>",
|
|
154131
154091
|
"\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08\u4E0E --end \u540C\u4F20\u6216\u540C\u7701\u7565\uFF1B\u7701\u7565=\u5F53\u5929\uFF09"
|
|
@@ -154174,55 +154134,55 @@ function registerYandexAnalysisCommands(program2) {
|
|
|
154174
154134
|
});
|
|
154175
154135
|
root.command("account-status").description(
|
|
154176
154136
|
"\u8D26\u6237\u5F52\u6863/\u4F59\u989D/\u533A\u95F4 KPI\uFF08GET /overview\uFF1Barchived=true \u4E3A\u5DF2\u5F52\u6863\uFF1B\u5B98\u65B9\u65E0\u5C01\u6237\u539F\u56E0\uFF1B\u7701\u7565\u65E5\u671F=\u5F53\u5929\uFF09"
|
|
154177
|
-
).requiredOption(...
|
|
154137
|
+
).requiredOption(...ACCOUNT_OPTION5).option(...START_OPTION).option(...END_OPTION).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
154178
154138
|
async (opts) => {
|
|
154179
154139
|
await runYandexAccountStatus(opts);
|
|
154180
154140
|
}
|
|
154181
154141
|
);
|
|
154182
154142
|
root.command("campaign-entities").description(
|
|
154183
154143
|
"\u7CFB\u5217\u7EE9\u6548+\u9884\u7B97/\u7B56\u7565\uFF08GET /campaigns\uFF1Aspend/weeklyBudget/budget/strategy/targetCpa\uFF1B\u5168\u6E20\u9053\u82B1\u8D39\u987B --network ALL\uFF1B\u53EF --time-increment 1 \u6309\u65E5\uFF09"
|
|
154184
|
-
).requiredOption(...
|
|
154144
|
+
).requiredOption(...ACCOUNT_OPTION5).option(...START_OPTION).option(...END_OPTION).option("--time-increment <n>", "\u4F20 1 \u6309\u65E5\u5207\u5206\uFF1B\u4E0D\u4F20=\u533A\u95F4\u6C47\u603B\u3002Direct \u65E0\u5C0F\u65F6\u7EF4\u5EA6").option("--network <value>", "SEARCH\uFF08\u9ED8\u8BA4\uFF09\u6216 ALL\uFF08\u5168\u7F51\u4E00\u884C\u5408\u8BA1\uFF0C\u884C\u5185 network \u4E3A null\uFF09").option("--limit <n>", "\u6761\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4\u7F51\u5173 100\uFF0C\u6700\u5927 10000\uFF09", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
154185
154145
|
async (opts) => {
|
|
154186
154146
|
await runYandexCampaignEntities(opts);
|
|
154187
154147
|
}
|
|
154188
154148
|
);
|
|
154189
154149
|
root.command("adgroup-entities").description(
|
|
154190
154150
|
"\u5E7F\u544A\u7EC4\u7EE9\u6548+\u7CFB\u5217\u76EE\u6807 CPA/\u5468\u9884\u7B97\uFF08GET /adgroups\uFF1B\u9ED8\u8BA4\u5168\u7F51\uFF1BCPA \u98D9\u5347\u770B\u8FD1 3 \u65E5\u533A\u95F4\u6C47\u603B\uFF0C\u4E0D\u8981\u4F20 timeIncrement\uFF09"
|
|
154191
|
-
).requiredOption(...
|
|
154151
|
+
).requiredOption(...ACCOUNT_OPTION5).option(...START_OPTION).option(...END_OPTION).option("--time-increment <n>", "\u4F20 1 \u6309\u65E5\u5207\u5206\uFF1B\u4E0D\u4F20=\u533A\u95F4\u6C47\u603B").option("--campaign-id <id>", "\u53EA\u62C9\u8BE5\u7CFB\u5217\u4E0B\u7684\u7EC4").option("--limit <n>", "\u6761\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4\u7F51\u5173 100\uFF0C\u6700\u5927 10000\uFF09", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
154192
154152
|
async (opts) => {
|
|
154193
154153
|
await runYandexAdGroupEntities(opts);
|
|
154194
154154
|
}
|
|
154195
154155
|
);
|
|
154196
154156
|
root.command("ad-entities").description(
|
|
154197
154157
|
`\u5E7F\u544A\u7EE9\u6548+\u843D\u5730\u9875/\u62D2\u5BA1\uFF08GET /ads\uFF1B\u62D2\u5BA1\u4F20 --status REJECTED\uFF1B\u5408\u6CD5\uFF1A${YANDEX_AD_STATUSES.join(",")}\uFF1B\u4E0E --time-increment \u4E92\u65A5\uFF09`
|
|
154198
|
-
).requiredOption(...
|
|
154158
|
+
).requiredOption(...ACCOUNT_OPTION5).option(...START_OPTION).option(...END_OPTION).option("--time-increment <n>", "\u4F20 1 \u6309\u65E5\u5207\u5206\uFF1B\u4E0D\u4F20=\u533A\u95F4\u6C47\u603B\u3002\u4E0D\u8981\u548C --status \u540C\u65F6\u4F20").option(
|
|
154199
154159
|
"--status <list>",
|
|
154200
154160
|
"\u5BA1\u6838\u6001\u9017\u53F7\u5206\u9694\uFF0C\u5982 REJECTED \u6216 MODERATION,REJECTED\uFF1B\u5E26 status \u65F6\u4E0D\u62C9\u7EE9\u6548\uFF08spend=0\uFF09"
|
|
154201
|
-
).option("--campaign-id <id>", "\u53EA\u62C9\u8BE5\u7CFB\u5217\u4E0B\u7684\u5E7F\u544A").option("--adgroup-id <id>", "\u53EA\u62C9\u8BE5\u7EC4\u4E0B\u7684\u5E7F\u544A").option("--limit <n>", "\u6761\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4\u7F51\u5173 100\uFF0C\u6700\u5927 10000\uFF09", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>",
|
|
154161
|
+
).option("--campaign-id <id>", "\u53EA\u62C9\u8BE5\u7CFB\u5217\u4E0B\u7684\u5E7F\u544A").option("--adgroup-id <id>", "\u53EA\u62C9\u8BE5\u7EC4\u4E0B\u7684\u5E7F\u544A").option("--limit <n>", "\u6761\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4\u7F51\u5173 100\uFF0C\u6700\u5927 10000\uFF09", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
154202
154162
|
async (opts) => {
|
|
154203
154163
|
await runYandexAdEntities(opts);
|
|
154204
154164
|
}
|
|
154205
154165
|
);
|
|
154206
154166
|
root.command("insights").description(
|
|
154207
154167
|
"YandexAPI \u62A5\u8868\u5207\u7247\uFF08GET /daily|/geo|/devices|/keywords \u6216 campaigns/adgroups/ads\uFF1B\u53EF\u542B\u4ECA\u5929\uFF1B\u65E0\u5C0F\u65F6\u7EF4\u5EA6\u3002geo/devices \u5168\u7F51\u987B --network ALL\uFF09"
|
|
154208
|
-
).requiredOption(...
|
|
154168
|
+
).requiredOption(...ACCOUNT_OPTION5).requiredOption("--level <level>", YANDEX_INSIGHTS_LEVELS.join(" / ")).option(...START_OPTION).option(...END_OPTION).option("--time-increment <n>", "\u4EC5 campaigns/adgroups/ads\uFF1A\u4F20 1 \u6309\u65E5\uFF1B\u4E0D\u8981\u548C --status \u540C\u65F6\u4F20").option("--network <value>", "\u4EC5 campaigns/geo/devices\uFF1ASEARCH \u6216 ALL").option("--status <list>", "\u4EC5 --level ads\uFF1A\u5BA1\u6838\u6001\u8FC7\u6EE4").option("--campaign-id <id>", "\u4EC5 adgroups/ads").option("--adgroup-id <id>", "\u4EC5 ads").option("--limit <n>", "\u6709 limit \u7684 path\uFF1A\u9ED8\u8BA4\u7F51\u5173 100\uFF0C\u6700\u5927 10000", (v) => parseInt(v, 10)).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
|
|
154209
154169
|
async (opts) => {
|
|
154210
154170
|
await runYandexInsights(opts);
|
|
154211
154171
|
}
|
|
154212
154172
|
);
|
|
154213
|
-
root.command("campaign-state").description("\u6682\u505C\u6216\u6062\u590D\u7CFB\u5217\uFF08Direct campaigns.suspend / campaigns.resume\uFF09").requiredOption(...
|
|
154173
|
+
root.command("campaign-state").description("\u6682\u505C\u6216\u6062\u590D\u7CFB\u5217\uFF08Direct campaigns.suspend / campaigns.resume\uFF09").requiredOption(...ACCOUNT_OPTION5).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
154214
154174
|
await runYandexCampaignState(opts);
|
|
154215
154175
|
});
|
|
154216
|
-
root.command("campaign-budget").description("\u6539\u7CFB\u5217\u65E5\u9884\u7B97\uFF08Direct campaigns.update DailyBudget\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u7F51\u5173\u6362\u7B97 micros\uFF09").requiredOption(...
|
|
154176
|
+
root.command("campaign-budget").description("\u6539\u7CFB\u5217\u65E5\u9884\u7B97\uFF08Direct campaigns.update DailyBudget\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u7F51\u5173\u6362\u7B97 micros\uFF09").requiredOption(...ACCOUNT_OPTION5).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--daily-budget <amount>", "\u65E5\u9884\u7B97\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("--mode <mode>", "STANDARD\uFF08\u9ED8\u8BA4\uFF09\u6216 DISTRIBUTED").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
154217
154177
|
await runYandexCampaignBudget(opts);
|
|
154218
154178
|
});
|
|
154219
|
-
root.command("adgroup-state").description("\u5E7F\u544A\u7EC4\u4E0D\u80FD\u5355\u72EC\u542F\u505C\uFF08Direct \u7684 AdGroups \u6CA1\u6709 suspend/resume\uFF1B\u8BF7\u7528 ad-state \u6216 campaign-state\uFF09").requiredOption(...
|
|
154179
|
+
root.command("adgroup-state").description("\u5E7F\u544A\u7EC4\u4E0D\u80FD\u5355\u72EC\u542F\u505C\uFF08Direct \u7684 AdGroups \u6CA1\u6709 suspend/resume\uFF1B\u8BF7\u7528 ad-state \u6216 campaign-state\uFF09").requiredOption(...ACCOUNT_OPTION5).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
154220
154180
|
await runYandexAdGroupState({ ...opts, adGroupId: opts.adgroupId });
|
|
154221
154181
|
});
|
|
154222
|
-
root.command("ad-state").description("\u6682\u505C\u6216\u6062\u590D\u5E7F\u544A\uFF08Direct ads.suspend / ads.resume\uFF09").requiredOption(...
|
|
154182
|
+
root.command("ad-state").description("\u6682\u505C\u6216\u6062\u590D\u5E7F\u544A\uFF08Direct ads.suspend / ads.resume\uFF09").requiredOption(...ACCOUNT_OPTION5).requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
154223
154183
|
await runYandexAdState(opts);
|
|
154224
154184
|
});
|
|
154225
|
-
root.command("keyword-bid").description("\u6539\u5173\u952E\u8BCD\u641C\u7D22\u51FA\u4EF7\uFF08Direct keywordbids.set SearchBid\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF09").requiredOption(...
|
|
154185
|
+
root.command("keyword-bid").description("\u6539\u5173\u952E\u8BCD\u641C\u7D22\u51FA\u4EF7\uFF08Direct keywordbids.set SearchBid\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF09").requiredOption(...ACCOUNT_OPTION5).requiredOption("--keyword-id <id>", "\u5173\u952E\u8BCD ID").requiredOption("--search-bid <amount>", "\u641C\u7D22\u51FA\u4EF7\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC5).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
154226
154186
|
await runYandexKeywordBid(opts);
|
|
154227
154187
|
});
|
|
154228
154188
|
}
|
|
@@ -154268,7 +154228,6 @@ var BING_COVERAGE_WRITES = [
|
|
|
154268
154228
|
"hotel-length-of-stay",
|
|
154269
154229
|
"hotel-date-selection",
|
|
154270
154230
|
"product-ad",
|
|
154271
|
-
"responsive-ad",
|
|
154272
154231
|
"hotel-ad",
|
|
154273
154232
|
"app-install-ad",
|
|
154274
154233
|
"update-responsive-ad",
|
|
@@ -154700,7 +154659,9 @@ var GAP_ACTIONS = {
|
|
|
154700
154659
|
"bing.delete-campaigns": bing("campaigns/delete"),
|
|
154701
154660
|
"bing.ad-group": bing("ad-groups"),
|
|
154702
154661
|
"bing.delete-ad-groups": bing("ad-groups/delete"),
|
|
154662
|
+
// 搜索响应式广告走 library/ads。受众广告是 bing.responsive-audience-ad。
|
|
154703
154663
|
"bing.responsive-ad": bing("ads"),
|
|
154664
|
+
"bing.responsive-audience-ad": bing("coverage/responsive-ad"),
|
|
154704
154665
|
"bing.delete-ads": bing("ads/delete"),
|
|
154705
154666
|
"bing.keywords": bing("keywords"),
|
|
154706
154667
|
"bing.keyword-bids": bing("keywords/bids"),
|
|
@@ -154848,6 +154809,88 @@ var GAP_ACTIONS = {
|
|
|
154848
154809
|
"tiktok.ad-group": tiktok("ad-groups"),
|
|
154849
154810
|
"tiktok.ad": tiktok("ads"),
|
|
154850
154811
|
"tiktok.smart-creative": tiktok("smart-creatives"),
|
|
154812
|
+
"tiktok.rename-campaign": tiktok("campaign-names"),
|
|
154813
|
+
"tiktok.rename-ad-group": tiktok("ad-group-names"),
|
|
154814
|
+
"tiktok.rename-ad": tiktok("ad-names"),
|
|
154815
|
+
"tiktok.rename-advertiser": tiktok("advertiser-names"),
|
|
154816
|
+
"tiktok.video-library": tiktok("video-library"),
|
|
154817
|
+
"tiktok.image-library": tiktok("image-library"),
|
|
154818
|
+
"tiktok.suggest-cover": tiktok("suggest-covers"),
|
|
154819
|
+
"tiktok.lookalike": tiktok("lookalikes"),
|
|
154820
|
+
"tiktok.refresh-lookalike": tiktok("lookalikes/refresh"),
|
|
154821
|
+
"tiktok.audience-detail": tiktok("audiences/detail"),
|
|
154822
|
+
"tiktok.audience-overlap": tiktok("audiences/overlap"),
|
|
154823
|
+
"tiktok.diagnosis": tiktok("diagnosis"),
|
|
154824
|
+
"tiktok.creative-fatigue": tiktok("creative-fatigue"),
|
|
154825
|
+
"tiktok.search-keywords": tiktok("search-keywords"),
|
|
154826
|
+
"tiktok.keyword-ideas": tiktok("keyword-ideas"),
|
|
154827
|
+
"tiktok.search-health": tiktok("search-health"),
|
|
154828
|
+
"tiktok.negative-keyword-list": tiktok("negative-keywords/list"),
|
|
154829
|
+
"tiktok.delete-negative-keywords": tiktok("negative-keywords/delete"),
|
|
154830
|
+
"tiktok.read-campaigns": tiktok("campaigns/raw"),
|
|
154831
|
+
"tiktok.read-ad-groups": tiktok("ad-groups/raw"),
|
|
154832
|
+
"tiktok.read-ads": tiktok("ads/raw"),
|
|
154833
|
+
"tiktok.smart-plus-ad-group": tiktok("smart-plus/ad-groups"),
|
|
154834
|
+
"tiktok.smart-plus-ad": tiktok("smart-plus/ads"),
|
|
154835
|
+
"tiktok.smart-plus-campaign-status": tiktok("smart-plus/campaign-status"),
|
|
154836
|
+
"tiktok.smart-plus-ad-group-status": tiktok("smart-plus/ad-group-status"),
|
|
154837
|
+
"tiktok.smart-plus-ad-status": tiktok("smart-plus/ad-status"),
|
|
154838
|
+
"tiktok.read-smart-creative": tiktok("smart-creatives/raw"),
|
|
154839
|
+
"tiktok.update-smart-creative": tiktok("smart-creatives/update"),
|
|
154840
|
+
"tiktok.catalog": tiktok("catalogs"),
|
|
154841
|
+
"tiktok.update-catalog": tiktok("catalogs/update"),
|
|
154842
|
+
"tiktok.delete-catalog": tiktok("catalogs/delete"),
|
|
154843
|
+
"tiktok.read-catalogs": tiktok("catalogs/list"),
|
|
154844
|
+
"tiktok.catalog-countries": tiktok("catalog-countries"),
|
|
154845
|
+
"tiktok.catalog-products": tiktok("catalog-products"),
|
|
154846
|
+
"tiktok.catalog-product-log": tiktok("catalog-product-logs"),
|
|
154847
|
+
"tiktok.catalog-set": tiktok("catalog-sets"),
|
|
154848
|
+
"tiktok.read-catalog-sets": tiktok("catalog-sets/list"),
|
|
154849
|
+
"tiktok.catalog-feed": tiktok("catalog-feeds"),
|
|
154850
|
+
"tiktok.read-catalog-feeds": tiktok("catalog-feeds/list"),
|
|
154851
|
+
"tiktok.catalog-diagnosis": tiktok("catalog-diagnosis"),
|
|
154852
|
+
"tiktok.catalog-overview": tiktok("catalog-overviews"),
|
|
154853
|
+
"tiktok.catalog-event-bind": tiktok("catalog-events"),
|
|
154854
|
+
"tiktok.store-products": tiktok("store-products"),
|
|
154855
|
+
"tiktok.read-gmv-max": tiktok("gmv-max/info"),
|
|
154856
|
+
"tiktok.update-gmv-max": tiktok("gmv-max/update"),
|
|
154857
|
+
"tiktok.gmv-max-stores": tiktok("gmv-max/stores"),
|
|
154858
|
+
"tiktok.gmv-max-report": tiktok("gmv-max/report"),
|
|
154859
|
+
"tiktok.rule": tiktok("rules"),
|
|
154860
|
+
"tiktok.update-rule": tiktok("rules/update"),
|
|
154861
|
+
"tiktok.rule-status": tiktok("rules/status"),
|
|
154862
|
+
"tiktok.read-rules": tiktok("rules/list"),
|
|
154863
|
+
"tiktok.rule-results": tiktok("rules/results"),
|
|
154864
|
+
"tiktok.comments": tiktok("comments"),
|
|
154865
|
+
"tiktok.comment-reply": tiktok("comments/reply"),
|
|
154866
|
+
"tiktok.blocked-words": tiktok("blocked-words"),
|
|
154867
|
+
"tiktok.create-blocked-words": tiktok("blocked-words/create"),
|
|
154868
|
+
"tiktok.delete-blocked-words": tiktok("blocked-words/delete"),
|
|
154869
|
+
"tiktok.spark-auth": tiktok("spark/authorize"),
|
|
154870
|
+
"tiktok.spark-posts": tiktok("spark/posts"),
|
|
154871
|
+
"tiktok.spark-unbind": tiktok("spark/unbind"),
|
|
154872
|
+
"tiktok.playables": tiktok("playables"),
|
|
154873
|
+
"tiktok.report-task": tiktok("report-tasks"),
|
|
154874
|
+
"tiktok.report-task-check": tiktok("report-tasks/check"),
|
|
154875
|
+
"tiktok.copy-task": tiktok("copy-tasks"),
|
|
154876
|
+
"tiktok.update-split-test": tiktok("split-tests/update"),
|
|
154877
|
+
"tiktok.end-split-test": tiktok("split-tests/end"),
|
|
154878
|
+
"tiktok.split-test-result": tiktok("split-tests/result"),
|
|
154879
|
+
"tiktok.promote-split-test": tiktok("split-tests/promote"),
|
|
154880
|
+
"tiktok.saved-audience": tiktok("saved-audiences"),
|
|
154881
|
+
"tiktok.read-saved-audiences": tiktok("saved-audiences/list"),
|
|
154882
|
+
"tiktok.delete-saved-audience": tiktok("saved-audiences/delete"),
|
|
154883
|
+
"tiktok.update-pixel": tiktok("pixels/update"),
|
|
154884
|
+
"tiktok.delete-pixel": tiktok("pixels/delete"),
|
|
154885
|
+
"tiktok.update-pixel-event": tiktok("pixel-events/update"),
|
|
154886
|
+
"tiktok.delete-pixel-event": tiktok("pixel-events/delete"),
|
|
154887
|
+
"tiktok.custom-conversion": tiktok("custom-conversions"),
|
|
154888
|
+
"tiktok.read-custom-conversions": tiktok("custom-conversions/list"),
|
|
154889
|
+
"tiktok.update-custom-conversion": tiktok("custom-conversions/update"),
|
|
154890
|
+
"tiktok.delete-custom-conversion": tiktok("custom-conversions/delete"),
|
|
154891
|
+
"tiktok.ad-review": tiktok("ad-reviews"),
|
|
154892
|
+
"tiktok.ad-group-review": tiktok("ad-group-reviews"),
|
|
154893
|
+
"tiktok.ad-appeal": tiktok("ad-appeals"),
|
|
154851
154894
|
"meta.outcome-campaign": facebook("outcome-campaigns"),
|
|
154852
154895
|
"meta.outcome-campaign-update": facebook("outcome-campaigns/{id}", { needsId: true }),
|
|
154853
154896
|
"meta.advantage-campaign": facebook("advantage-campaigns"),
|
|
@@ -154870,6 +154913,8 @@ var GAP_ACTIONS = {
|
|
|
154870
154913
|
needsBody: false
|
|
154871
154914
|
}),
|
|
154872
154915
|
"google.customer-match-list": google("POST", "/customer-match/{account}/user-lists"),
|
|
154916
|
+
"google.lookalike-list": google("POST", "/lookalike-user-lists/{account}?seedUserListId={id}", { needsId: true }),
|
|
154917
|
+
"google.ga4-link": google("POST", "/ga4-links/{account}"),
|
|
154873
154918
|
"google.remove-customer-match-list": google("DELETE", "/customer-match/{account}/user-lists/{id}", { needsId: true, needsBody: false }),
|
|
154874
154919
|
"google.customer-match-job": google("POST", "/customer-match/{account}/jobs?userListId={id}", { needsId: true, needsBody: false }),
|
|
154875
154920
|
"google.customer-match-operations": google("POST", "/customer-match/{account}/jobs/{id}/operations", { needsId: true }),
|
|
@@ -154931,7 +154976,7 @@ var GAP_ACTIONS = {
|
|
|
154931
154976
|
"google.remove-custom-audience": google("DELETE", "/custom-audiences/{account}/{id}", { needsId: true, needsBody: false }),
|
|
154932
154977
|
"google.goal": google("POST", "/goals/{account}"),
|
|
154933
154978
|
"google.campaign-goal-config": google("POST", "/campaign-goal-configs/{account}"),
|
|
154934
|
-
"google.remove-campaign-goal-config": google("DELETE", "/campaign-goal-configs/{account}/{id}", { needsId: true, needsBody: false }),
|
|
154979
|
+
"google.remove-campaign-goal-config": google("DELETE", "/campaign-goal-configs/{account}/{id}/{parent}", { needsId: true, needsParent: true, needsBody: false }),
|
|
154935
154980
|
"google.keyword-plan": google("POST", "/keyword-plans/{account}"),
|
|
154936
154981
|
"google.remove-keyword-plan": google("DELETE", "/keyword-plans/{account}/{id}", { needsId: true, needsBody: false }),
|
|
154937
154982
|
"google.keyword-plan-campaign": google("POST", "/keyword-plans/{account}/campaigns"),
|
|
@@ -154979,46 +155024,11 @@ var GAP_ACTIONS = {
|
|
|
154979
155024
|
function gapActionNames() {
|
|
154980
155025
|
return Object.keys(GAP_ACTIONS).sort();
|
|
154981
155026
|
}
|
|
154982
|
-
var READ_AFTER_WRITE = {
|
|
154983
|
-
"meta.outcome-campaign": "meta.read-campaign",
|
|
154984
|
-
"meta.outcome-campaign-update": "meta.read-campaign",
|
|
154985
|
-
"meta.advantage-campaign": "meta.read-campaign",
|
|
154986
|
-
"meta.outcome-adset": "meta.read-adset",
|
|
154987
|
-
"meta.advantage-adset": "meta.read-adset",
|
|
154988
|
-
"meta.outcome-ad": "meta.read-ad",
|
|
154989
|
-
"meta.copy-campaign": "meta.read-campaign",
|
|
154990
|
-
"meta.copy-adset": "meta.read-adset",
|
|
154991
|
-
"meta.copy-ad": "meta.read-ad",
|
|
154992
|
-
"bing.campaign-budget": "bing.read-budgets",
|
|
154993
|
-
"yandex.unified-campaign": "yandex.read-campaigns"
|
|
154994
|
-
};
|
|
154995
|
-
function findReadbackAction(writeName) {
|
|
154996
|
-
const named = READ_AFTER_WRITE[writeName];
|
|
154997
|
-
if (named && GAP_ACTIONS[named]) return named;
|
|
154998
|
-
const write = GAP_ACTIONS[writeName];
|
|
154999
|
-
if (!write || write.method === "GET") return null;
|
|
155000
|
-
const dot = writeName.indexOf(".");
|
|
155001
|
-
if (dot < 0) return null;
|
|
155002
|
-
const prefix = writeName.slice(0, dot + 1);
|
|
155003
|
-
const rest = writeName.slice(dot + 1).replace(/^(update-|delete-)/, "");
|
|
155004
|
-
for (const name2 of [`${prefix}read-${rest}`, `${prefix}read-${rest}s`]) {
|
|
155005
|
-
if (GAP_ACTIONS[name2]) return name2;
|
|
155006
|
-
}
|
|
155007
|
-
for (const [name2, action] of Object.entries(GAP_ACTIONS)) {
|
|
155008
|
-
if (name2 !== writeName && action.service === write.service && action.path === write.path && action.method === "GET") {
|
|
155009
|
-
return name2;
|
|
155010
|
-
}
|
|
155011
|
-
}
|
|
155012
|
-
return null;
|
|
155013
|
-
}
|
|
155014
155027
|
function resolveGapPath(actionName, target) {
|
|
155015
155028
|
const action = GAP_ACTIONS[actionName];
|
|
155016
155029
|
if (!action) {
|
|
155017
155030
|
throw new Error(`\u672A\u77E5 action\uFF1A${actionName}`);
|
|
155018
155031
|
}
|
|
155019
|
-
if (action.service === "tiktok" && action.path.toLowerCase().includes("catalog")) {
|
|
155020
|
-
throw new Error("\u5546\u54C1\u76EE\u5F55\u8DEF\u5F84\u672A\u63A5\u5165");
|
|
155021
|
-
}
|
|
155022
155032
|
const account = requireToken(target.account, "account");
|
|
155023
155033
|
const parent = action.needsParent ? requireToken(target.parent, "parent") : target.parent?.trim() ?? "";
|
|
155024
155034
|
const id = action.needsId ? requireToken(target.id, "id") : target.id?.trim() ?? "";
|
|
@@ -155050,123 +155060,7 @@ function requireToken(value, label2) {
|
|
|
155050
155060
|
init_auth();
|
|
155051
155061
|
init_cli_json_snapshot();
|
|
155052
155062
|
init_shared();
|
|
155053
|
-
import { readFileSync as
|
|
155054
|
-
|
|
155055
|
-
// src/commands/ad-gap/readback.ts
|
|
155056
|
-
init_auth();
|
|
155057
|
-
var COMPARE_KEYS = ["budget", "daily_budget", "amount", "status", "statusV2", "name", "countries"];
|
|
155058
|
-
function readCreatedId(payload) {
|
|
155059
|
-
if (!payload || typeof payload !== "object") return "";
|
|
155060
|
-
const row = payload;
|
|
155061
|
-
for (const key of ["id", "Id", "campaign_id", "campaignId", "adset_id", "ad_id"]) {
|
|
155062
|
-
const value = row[key];
|
|
155063
|
-
if (typeof value === "string" && value.trim()) return value.trim();
|
|
155064
|
-
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
155065
|
-
}
|
|
155066
|
-
if (row["data"] && typeof row["data"] === "object") return readCreatedId(row["data"]);
|
|
155067
|
-
return "";
|
|
155068
|
-
}
|
|
155069
|
-
function findDeep(value, key, depth = 0) {
|
|
155070
|
-
if (value == null || depth > 6) return void 0;
|
|
155071
|
-
if (Array.isArray(value)) {
|
|
155072
|
-
for (const item of value) {
|
|
155073
|
-
const hit = findDeep(item, key, depth + 1);
|
|
155074
|
-
if (hit !== void 0) return hit;
|
|
155075
|
-
}
|
|
155076
|
-
return void 0;
|
|
155077
|
-
}
|
|
155078
|
-
if (typeof value !== "object") return void 0;
|
|
155079
|
-
const row = value;
|
|
155080
|
-
if (Object.prototype.hasOwnProperty.call(row, key) && row[key] != null) {
|
|
155081
|
-
if (typeof row[key] !== "object" || Array.isArray(row[key])) return row[key];
|
|
155082
|
-
}
|
|
155083
|
-
for (const child of Object.values(row)) {
|
|
155084
|
-
const hit = findDeep(child, key, depth + 1);
|
|
155085
|
-
if (hit !== void 0) return hit;
|
|
155086
|
-
}
|
|
155087
|
-
return void 0;
|
|
155088
|
-
}
|
|
155089
|
-
function displayList(value) {
|
|
155090
|
-
if (Array.isArray(value)) return value.map((item) => String(item)).sort().join(",");
|
|
155091
|
-
return String(value);
|
|
155092
|
-
}
|
|
155093
|
-
function compareGapBody(body, payload, deleted) {
|
|
155094
|
-
if (deleted) {
|
|
155095
|
-
if (payload == null) {
|
|
155096
|
-
return [receiptLine("\u5BF9\u8C61", "\u5DF2\u5220\u9664", void 0)];
|
|
155097
|
-
}
|
|
155098
|
-
const status = findDeep(payload, "status") ?? findDeep(payload, "statusV2");
|
|
155099
|
-
const gone = status == null || /delete|removed|archive/i.test(String(status));
|
|
155100
|
-
return [receiptLine("\u5BF9\u8C61", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : status)];
|
|
155101
|
-
}
|
|
155102
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
155103
|
-
return [receiptLine("\u5199\u5165", "\u5DF2\u63D0\u4EA4", payload == null ? void 0 : "\u5DF2\u8BFB\u56DE")];
|
|
155104
|
-
}
|
|
155105
|
-
const lines = [];
|
|
155106
|
-
const record2 = body;
|
|
155107
|
-
for (const key of COMPARE_KEYS) {
|
|
155108
|
-
if (record2[key] == null || typeof record2[key] === "object" && !Array.isArray(record2[key])) continue;
|
|
155109
|
-
const expected = Array.isArray(record2[key]) ? displayList(record2[key]) : record2[key];
|
|
155110
|
-
const actualRaw = findDeep(payload, key);
|
|
155111
|
-
const actual = actualRaw == null ? void 0 : Array.isArray(actualRaw) ? displayList(actualRaw) : actualRaw;
|
|
155112
|
-
lines.push(receiptLine(key, expected, actual));
|
|
155113
|
-
}
|
|
155114
|
-
if (lines.length === 0) {
|
|
155115
|
-
lines.push(receiptLine("\u5199\u5165", "\u5DF2\u63D0\u4EA4", payload == null ? void 0 : "\u5DF2\u8BFB\u56DE"));
|
|
155116
|
-
}
|
|
155117
|
-
return lines;
|
|
155118
|
-
}
|
|
155119
|
-
async function printAdGapReadback(opts) {
|
|
155120
|
-
const readName = findReadbackAction(opts.action);
|
|
155121
|
-
if (!readName) {
|
|
155122
|
-
printWriteReceipt("unknown", [receiptLine("\u8BFB\u56DE", "\u6709\u914D\u5BF9\u67E5\u8BE2", void 0)]);
|
|
155123
|
-
return;
|
|
155124
|
-
}
|
|
155125
|
-
const createdId = readCreatedId(opts.payload) || opts.id || "";
|
|
155126
|
-
const deleted = opts.action.includes("delete");
|
|
155127
|
-
let path61;
|
|
155128
|
-
let method;
|
|
155129
|
-
let needsBody;
|
|
155130
|
-
try {
|
|
155131
|
-
const resolved = resolveGapPath(readName, {
|
|
155132
|
-
account: opts.account,
|
|
155133
|
-
parent: opts.parent,
|
|
155134
|
-
id: createdId,
|
|
155135
|
-
label: opts.label
|
|
155136
|
-
});
|
|
155137
|
-
path61 = resolved.path;
|
|
155138
|
-
method = resolved.action.method;
|
|
155139
|
-
needsBody = resolved.action.needsBody !== false;
|
|
155140
|
-
} catch {
|
|
155141
|
-
printWriteReceipt("unknown", [receiptLine("\u8BFB\u56DE", readName, void 0)]);
|
|
155142
|
-
return;
|
|
155143
|
-
}
|
|
155144
|
-
const config = loadConfig(opts.token);
|
|
155145
|
-
let readPayload;
|
|
155146
|
-
try {
|
|
155147
|
-
readPayload = await apiFetch2(
|
|
155148
|
-
opts.serviceBase(resolveGapPath(readName, { account: opts.account, id: createdId, parent: opts.parent, label: opts.label }).action.service, config) + path61,
|
|
155149
|
-
config,
|
|
155150
|
-
{
|
|
155151
|
-
method,
|
|
155152
|
-
body: needsBody ? JSON.stringify(opts.body ?? {}) : void 0
|
|
155153
|
-
},
|
|
155154
|
-
opts.verbose
|
|
155155
|
-
);
|
|
155156
|
-
} catch (err) {
|
|
155157
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
155158
|
-
if (deleted && /404|未找到|not found/i.test(message)) {
|
|
155159
|
-
printWriteReceipt("verified", [receiptLine("\u5BF9\u8C61", "\u5DF2\u5220\u9664", "\u5DF2\u5220\u9664")]);
|
|
155160
|
-
return;
|
|
155161
|
-
}
|
|
155162
|
-
printWriteReceipt("unknown", [receiptLine("\u8BFB\u56DE", readName, void 0)]);
|
|
155163
|
-
return;
|
|
155164
|
-
}
|
|
155165
|
-
const lines = compareGapBody(opts.body, readPayload, deleted);
|
|
155166
|
-
printWriteReceipt(judgeReceipt(lines), lines);
|
|
155167
|
-
}
|
|
155168
|
-
|
|
155169
|
-
// src/commands/ad-gap/run.ts
|
|
155063
|
+
import { readFileSync as readFileSync22 } from "fs";
|
|
155170
155064
|
function readGapBody(opts, required) {
|
|
155171
155065
|
const inline = opts.body?.trim();
|
|
155172
155066
|
const file = opts.bodyFile?.trim();
|
|
@@ -155177,7 +155071,7 @@ function readGapBody(opts, required) {
|
|
|
155177
155071
|
if (!required) return void 0;
|
|
155178
155072
|
throw new Error("\u8FD9\u4E2A action \u9700\u8981 --body \u6216 --body-file");
|
|
155179
155073
|
}
|
|
155180
|
-
const raw = file ?
|
|
155074
|
+
const raw = file ? readFileSync22(file, "utf8") : inline;
|
|
155181
155075
|
let parsed;
|
|
155182
155076
|
try {
|
|
155183
155077
|
parsed = JSON.parse(raw);
|
|
@@ -155324,20 +155218,6 @@ async function runAdGap(opts) {
|
|
|
155324
155218
|
if (resolved.action.service === "tiktok") {
|
|
155325
155219
|
assertTikTokAccepted(payload);
|
|
155326
155220
|
}
|
|
155327
|
-
if (resolved.action.method !== "GET") {
|
|
155328
|
-
await printAdGapReadback({
|
|
155329
|
-
action: opts.action,
|
|
155330
|
-
account: opts.account,
|
|
155331
|
-
parent: opts.parent,
|
|
155332
|
-
id: opts.id,
|
|
155333
|
-
label: opts.label,
|
|
155334
|
-
token: opts.token,
|
|
155335
|
-
verbose: opts.verbose,
|
|
155336
|
-
body,
|
|
155337
|
-
payload,
|
|
155338
|
-
serviceBase
|
|
155339
|
-
});
|
|
155340
|
-
}
|
|
155341
155221
|
const emitted = await emitCliJsonOrSnapshot(
|
|
155342
155222
|
{ jsonOut: opts.jsonOut },
|
|
155343
155223
|
{
|
|
@@ -155587,7 +155467,7 @@ configureCliJsonSnapshot({
|
|
|
155587
155467
|
configureSiluzanClientIdentity({ client: "tso-cli", resolveVersion: getVersion });
|
|
155588
155468
|
var program = new Command6();
|
|
155589
155469
|
program.name("siluzan-tso").description(
|
|
155590
|
-
"Siluzan \u5E7F\u544A\u8D26\u6237\u7BA1\u7406\uFF1A\u8D26\u6237\u67E5\u8BE2\u3001\u4F59\u989D\u3001\u6295\u653E\u6570\u636E\u3001\u5F00\u6237\u7533\u8BF7\uFF08Google/TikTok/Yandex/Bing/Meta\uFF09\u3001\n\u8D26\u53F7\u5206\u4EAB/\u89E3\u7ED1\u3001\u4F18\u5316\u62A5\u544A\u3001Google/Meta/TikTok/Bing/Yandex \u8D26\u6237\u5206\u6790\u3001Google \u5E7F\u544A\u8BCA\u65AD\u62A5\u544A\uFF08google-ads-diagnosis render\uFF09\u3001Google \u5B63\u5EA6\u7ECF\u8425\u62A5\u544A\uFF08google-quarterly\uFF09\u3001\u7F51\u7AD9\u8BCA\u65AD\uFF08website-diagnosis\uFF09\u3001\u6218\u7565\u5E02\u573A\u5206\u6790\uFF08market-analysis\uFF0CAgent \u751F\u6210\u62A5\u544A\uFF09\u3001\u5145\u503C\u8F6C\u8D26\u3001\u5F00\u7968\u3001\u667A\u80FD\u9884\u8B66\u3001Google \u5E7F\u544A\u7BA1\u7406\uFF08Search/PMax\uFF0C\u542B\u5F02\u6B65\u6279\u91CF\uFF09\u3001Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\uFF08meta-ad\uFF09\u3001Bing/Yandex/TikTok \u542F\u505C\u4E0E\u9884\u7B97\u3002"
|
|
155470
|
+
"Siluzan \u5E7F\u544A\u8D26\u6237\u7BA1\u7406\uFF1A\u8D26\u6237\u67E5\u8BE2\u3001\u4F59\u989D\u3001\u6295\u653E\u6570\u636E\u3001\u5F00\u6237\u7533\u8BF7\uFF08Google/TikTok/Yandex/Bing/Meta\uFF09\u3001\n\u8D26\u53F7\u5206\u4EAB/\u89E3\u7ED1\u3001\u4F18\u5316\u62A5\u544A\u3001Google/Meta/TikTok/Bing/Yandex \u8D26\u6237\u5206\u6790\u3001GA4 \u6307\u6807\uFF08ga4\uFF09\u3001Google \u5E7F\u544A\u8BCA\u65AD\u62A5\u544A\uFF08google-ads-diagnosis render\uFF09\u3001Google \u5B63\u5EA6\u7ECF\u8425\u62A5\u544A\uFF08google-quarterly\uFF09\u3001\u7F51\u7AD9\u8BCA\u65AD\uFF08website-diagnosis\uFF09\u3001\u6218\u7565\u5E02\u573A\u5206\u6790\uFF08market-analysis\uFF0CAgent \u751F\u6210\u62A5\u544A\uFF09\u3001\u5145\u503C\u8F6C\u8D26\u3001\u5F00\u7968\u3001\u667A\u80FD\u9884\u8B66\u3001Google \u5E7F\u544A\u7BA1\u7406\uFF08Search/PMax\uFF0C\u542B\u5F02\u6B65\u6279\u91CF\uFF09\u3001Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\uFF08meta-ad\uFF09\u3001Bing/Yandex/TikTok \u542F\u505C\u4E0E\u9884\u7B97\u3002"
|
|
155591
155471
|
).version(getVersion());
|
|
155592
155472
|
program.option("--commit <text>", "\u5199\u64CD\u4F5C\u8BF4\u660E\uFF1B\u8BB0\u5165\u672C\u673A\u5199\u5BA1\u8BA1 JSONL");
|
|
155593
155473
|
program.hook("preAction", async () => {
|
|
@@ -155618,6 +155498,7 @@ var REGISTRARS = [
|
|
|
155618
155498
|
register13,
|
|
155619
155499
|
register14,
|
|
155620
155500
|
registerGoogleAnalysisCommands,
|
|
155501
|
+
register28,
|
|
155621
155502
|
registerGoogleAnalysisBatchCommands,
|
|
155622
155503
|
registerFacebookAnalysisCommands,
|
|
155623
155504
|
registerBingAnalysisCommands,
|