siluzan-tso-cli 1.1.75-beta.3 → 1.1.75-beta.4
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 +2978 -354
- package/dist/skill/_meta.json +2 -2
- package/dist/skill/references/core/agent-conventions.md +10 -1
- package/dist/skill/references/google-ads/google-ads-read.md +1 -1
- package/dist/skill/references/google-ads/google-ads-write.md +6 -1
- package/dist/skill/references/google-ads/google-ads.md +1 -1
- package/dist/skill/references/operations/ad-gap.md +1 -1
- 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/eval/cases/write-readback-budget-mismatch.scenario.json +19 -0
- package/eval/cases/write-readback-extra-country.scenario.json +19 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -6431,6 +6431,7 @@ function negativeKeywordSlimListUrl(googleApiUrl, accountId, query) {
|
|
|
6431
6431
|
if (query?.appliedLevel) params.set("appliedlevel", query.appliedLevel);
|
|
6432
6432
|
if (query?.readDeleted) params.set("readDeleted", "true");
|
|
6433
6433
|
if (query?.excludePaused) params.set("excludePaused", "true");
|
|
6434
|
+
if (query?.newest) params.set("newest", "true");
|
|
6434
6435
|
const text5 = query?.keywordText?.trim();
|
|
6435
6436
|
if (text5) params.set("keywordtext", text5);
|
|
6436
6437
|
if (query?.matchType) params.set("matchtype", query.matchType);
|
|
@@ -6457,11 +6458,11 @@ function toDisplayMoney(raw) {
|
|
|
6457
6458
|
if (!Number.isFinite(n)) return null;
|
|
6458
6459
|
return n / 100;
|
|
6459
6460
|
}
|
|
6460
|
-
function toCentAmount(
|
|
6461
|
-
if (!Number.isFinite(
|
|
6462
|
-
throw new Error(`toCentAmount: \u8F93\u5165\u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${
|
|
6461
|
+
function toCentAmount(displayValue2) {
|
|
6462
|
+
if (!Number.isFinite(displayValue2)) {
|
|
6463
|
+
throw new Error(`toCentAmount: \u8F93\u5165\u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${displayValue2}`);
|
|
6463
6464
|
}
|
|
6464
|
-
return Math.round(
|
|
6465
|
+
return Math.round(displayValue2 * 100);
|
|
6465
6466
|
}
|
|
6466
6467
|
function convertBatchMoneyTreeFromYuan(value) {
|
|
6467
6468
|
return convertBatchMoneyTreeFromYuanInner(value);
|
|
@@ -109855,6 +109856,230 @@ init_dist();
|
|
|
109855
109856
|
init_auth();
|
|
109856
109857
|
init_cli_json_snapshot();
|
|
109857
109858
|
import { createHash } from "crypto";
|
|
109859
|
+
|
|
109860
|
+
// src/commands/write-receipt-record.ts
|
|
109861
|
+
init_auth();
|
|
109862
|
+
import { spawnSync } from "child_process";
|
|
109863
|
+
var POST_SCRIPT = `
|
|
109864
|
+
fetch(process.env.RECEIPT_URL, {
|
|
109865
|
+
method: "POST",
|
|
109866
|
+
headers: {
|
|
109867
|
+
"content-type": "application/json",
|
|
109868
|
+
[process.env.RECEIPT_AUTH_NAME]: process.env.RECEIPT_AUTH_VALUE,
|
|
109869
|
+
},
|
|
109870
|
+
body: require("node:fs").readFileSync(0, "utf8"),
|
|
109871
|
+
signal: AbortSignal.timeout(2000),
|
|
109872
|
+
}).then(async (response) => {
|
|
109873
|
+
let state = "";
|
|
109874
|
+
try { state = JSON.parse(await response.text()).state; } catch { state = ""; }
|
|
109875
|
+
process.exit(response.ok && state === "ok" ? 0 : 2);
|
|
109876
|
+
}).catch(() => process.exit(1));
|
|
109877
|
+
`;
|
|
109878
|
+
function flagValue(argv, flags) {
|
|
109879
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
109880
|
+
const token = argv[i] ?? "";
|
|
109881
|
+
for (const flag of flags) {
|
|
109882
|
+
if (token === flag) {
|
|
109883
|
+
const next = argv[i + 1] ?? "";
|
|
109884
|
+
return next.startsWith("-") ? "" : next;
|
|
109885
|
+
}
|
|
109886
|
+
if (token.startsWith(`${flag}=`)) return token.slice(flag.length + 1);
|
|
109887
|
+
}
|
|
109888
|
+
}
|
|
109889
|
+
return "";
|
|
109890
|
+
}
|
|
109891
|
+
function commandContextFromArgv(argv) {
|
|
109892
|
+
const parts = [];
|
|
109893
|
+
for (const token of argv) {
|
|
109894
|
+
if (!token || token.includes("node") || token.endsWith("index.js") || token.endsWith("index.ts") || token.endsWith("cli.mjs")) {
|
|
109895
|
+
continue;
|
|
109896
|
+
}
|
|
109897
|
+
if (token.startsWith("-")) break;
|
|
109898
|
+
parts.push(token);
|
|
109899
|
+
if (parts.length >= 3) break;
|
|
109900
|
+
}
|
|
109901
|
+
return {
|
|
109902
|
+
command: parts.join(" "),
|
|
109903
|
+
accountId: flagValue(argv, ["-a", "--account"]),
|
|
109904
|
+
resourceId: flagValue(argv, ["--id"])
|
|
109905
|
+
};
|
|
109906
|
+
}
|
|
109907
|
+
function buildWriteReadSnapshot(verification, lines, argv) {
|
|
109908
|
+
const expected = {};
|
|
109909
|
+
const read = {};
|
|
109910
|
+
for (const line of lines) {
|
|
109911
|
+
expected[line.label] = line.expected;
|
|
109912
|
+
read[line.label] = line.actual;
|
|
109913
|
+
}
|
|
109914
|
+
const command = commandContextFromArgv(argv);
|
|
109915
|
+
return {
|
|
109916
|
+
verification,
|
|
109917
|
+
command: command.command,
|
|
109918
|
+
accountId: command.accountId,
|
|
109919
|
+
resourceId: command.resourceId,
|
|
109920
|
+
threadId: process.env.DEERFLOW_THREAD_ID?.trim() ?? "",
|
|
109921
|
+
runId: process.env.DEERFLOW_RUN_ID?.trim() ?? "",
|
|
109922
|
+
expected,
|
|
109923
|
+
read,
|
|
109924
|
+
lines
|
|
109925
|
+
};
|
|
109926
|
+
}
|
|
109927
|
+
function resolveReceiptPost(config) {
|
|
109928
|
+
const base2 = config.mainApiUrl?.trim().replace(/\/$/, "") ?? "";
|
|
109929
|
+
if (!base2) return null;
|
|
109930
|
+
const apiKey = config.apiKey?.trim();
|
|
109931
|
+
if (apiKey) {
|
|
109932
|
+
return { url: `${base2}/command/write-read-receipt`, authName: "x-api-key", authValue: apiKey };
|
|
109933
|
+
}
|
|
109934
|
+
const token = config.authToken?.trim();
|
|
109935
|
+
if (!token) return null;
|
|
109936
|
+
return { url: `${base2}/command/write-read-receipt`, authName: "Authorization", authValue: `Bearer ${token}` };
|
|
109937
|
+
}
|
|
109938
|
+
function postWriteReadSnapshot(url, authName, authValue, body, spawn3 = spawnSync) {
|
|
109939
|
+
return spawn3(process.execPath, ["-e", POST_SCRIPT], {
|
|
109940
|
+
input: body,
|
|
109941
|
+
timeout: 2500,
|
|
109942
|
+
encoding: "utf8",
|
|
109943
|
+
env: { ...process.env, RECEIPT_URL: url, RECEIPT_AUTH_NAME: authName, RECEIPT_AUTH_VALUE: authValue }
|
|
109944
|
+
});
|
|
109945
|
+
}
|
|
109946
|
+
function shouldPostWriteReadReceipt(env = process.env) {
|
|
109947
|
+
if (env.SILUZAN_SKIP_RECEIPT_POST === "1") return false;
|
|
109948
|
+
if (env.VITEST === "true" || env.VITEST === "1") return false;
|
|
109949
|
+
return true;
|
|
109950
|
+
}
|
|
109951
|
+
function recordWriteReadReceipt(verification, lines, load = loadConfig, spawn3 = spawnSync, env = process.env) {
|
|
109952
|
+
if (!shouldPostWriteReadReceipt(env)) return;
|
|
109953
|
+
let target;
|
|
109954
|
+
try {
|
|
109955
|
+
target = resolveReceiptPost(load());
|
|
109956
|
+
} catch {
|
|
109957
|
+
console.error("write-read receipt \u672A\u8BB0\u4E0B");
|
|
109958
|
+
return;
|
|
109959
|
+
}
|
|
109960
|
+
if (!target) return;
|
|
109961
|
+
const snapshot = buildWriteReadSnapshot(verification, lines, process.argv);
|
|
109962
|
+
const result = postWriteReadSnapshot(target.url, target.authName, target.authValue, JSON.stringify(snapshot), spawn3);
|
|
109963
|
+
if (result.status !== 0) {
|
|
109964
|
+
console.error("write-read receipt \u672A\u8BB0\u4E0B");
|
|
109965
|
+
}
|
|
109966
|
+
}
|
|
109967
|
+
|
|
109968
|
+
// src/commands/write-receipt.ts
|
|
109969
|
+
var UNREAD = "\uFF08\u672A\u8BFB\u5230\uFF09";
|
|
109970
|
+
var CENT_YUAN_FIELDS = {
|
|
109971
|
+
budget: "\u65E5\u9884\u7B97",
|
|
109972
|
+
targetCpa_BidingAmount: "\u76EE\u6807CPA",
|
|
109973
|
+
targetSpend_BidCeilingAmount: "CPC\u4E0A\u9650"
|
|
109974
|
+
};
|
|
109975
|
+
var FIELD_LABELS = {
|
|
109976
|
+
statusV2: "\u72B6\u6001",
|
|
109977
|
+
biddingStrategyTypeV2: "\u51FA\u4EF7\u7B56\u7565",
|
|
109978
|
+
targetRoas: "\u76EE\u6807ROAS",
|
|
109979
|
+
positiveGeoTargetTypeV2: "\u4F4D\u7F6E\u9009\u9879",
|
|
109980
|
+
negativeGeoTargetTypeV2: "\u6392\u9664\u4F4D\u7F6E\u9009\u9879",
|
|
109981
|
+
name: "\u540D\u79F0",
|
|
109982
|
+
daily_budget: "\u65E5\u9884\u7B97",
|
|
109983
|
+
status: "\u72B6\u6001",
|
|
109984
|
+
countries: "\u56FD\u5BB6",
|
|
109985
|
+
finalUrl: "\u843D\u5730\u9875",
|
|
109986
|
+
finalURL: "\u843D\u5730\u9875"
|
|
109987
|
+
};
|
|
109988
|
+
function yuanLabel(amount) {
|
|
109989
|
+
const rounded = Math.round(amount * 100) / 100;
|
|
109990
|
+
return `${rounded} \u5143`;
|
|
109991
|
+
}
|
|
109992
|
+
function displayValue(value) {
|
|
109993
|
+
if (value == null || value === "") return "\uFF08\u7A7A\uFF09";
|
|
109994
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
109995
|
+
const rounded = Math.round(value * 100) / 100;
|
|
109996
|
+
return String(rounded);
|
|
109997
|
+
}
|
|
109998
|
+
if (typeof value === "boolean") return value ? "\u662F" : "\u5426";
|
|
109999
|
+
if (Array.isArray(value)) return value.map((item) => displayValue(item)).join(",");
|
|
110000
|
+
return String(value);
|
|
110001
|
+
}
|
|
110002
|
+
function receiptLine(label2, expected, actual) {
|
|
110003
|
+
return {
|
|
110004
|
+
label: label2,
|
|
110005
|
+
expected: displayValue(expected),
|
|
110006
|
+
actual: actual === void 0 ? UNREAD : displayValue(actual)
|
|
110007
|
+
};
|
|
110008
|
+
}
|
|
110009
|
+
function receiptLinesFromFieldChecks(checks) {
|
|
110010
|
+
return checks.map((check) => {
|
|
110011
|
+
const yuanLabelName = CENT_YUAN_FIELDS[check.field];
|
|
110012
|
+
const label2 = yuanLabelName ?? FIELD_LABELS[check.field] ?? check.field;
|
|
110013
|
+
const unread = check.state === "unread";
|
|
110014
|
+
if (yuanLabelName) {
|
|
110015
|
+
const expectedYuan = centsToYuan(check.expected);
|
|
110016
|
+
const actualYuan = unread ? void 0 : centsToYuan(check.actual);
|
|
110017
|
+
return receiptLine(
|
|
110018
|
+
label2,
|
|
110019
|
+
expectedYuan == null ? check.expected : yuanLabel(expectedYuan),
|
|
110020
|
+
actualYuan == null ? unread ? void 0 : check.actual : yuanLabel(actualYuan)
|
|
110021
|
+
);
|
|
110022
|
+
}
|
|
110023
|
+
return receiptLine(label2, check.expected, unread ? void 0 : check.actual);
|
|
110024
|
+
});
|
|
110025
|
+
}
|
|
110026
|
+
function centsToYuan(value) {
|
|
110027
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
110028
|
+
return value / 100;
|
|
110029
|
+
}
|
|
110030
|
+
function judgeReceipt(lines, readFailed = false) {
|
|
110031
|
+
if (lines.length === 0) return "submitted";
|
|
110032
|
+
if (readFailed || lines.some((line) => line.actual === UNREAD)) return "unknown";
|
|
110033
|
+
if (lines.every((line) => line.expected === line.actual)) return "verified";
|
|
110034
|
+
return "partial";
|
|
110035
|
+
}
|
|
110036
|
+
function formatWriteReceipt(verification, lines) {
|
|
110037
|
+
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";
|
|
110038
|
+
return `\u6838\u5BF9
|
|
110039
|
+
verification=${verification}
|
|
110040
|
+
${body}`;
|
|
110041
|
+
}
|
|
110042
|
+
function printWriteReceipt(verification, lines) {
|
|
110043
|
+
console.log(`
|
|
110044
|
+
${formatWriteReceipt(verification, lines)}
|
|
110045
|
+
`);
|
|
110046
|
+
try {
|
|
110047
|
+
recordWriteReadReceipt(verification, lines);
|
|
110048
|
+
} catch {
|
|
110049
|
+
}
|
|
110050
|
+
}
|
|
110051
|
+
function payloadHasExact(payload, value) {
|
|
110052
|
+
const text5 = JSON.stringify(payload ?? null);
|
|
110053
|
+
if (text5.includes(JSON.stringify(value))) return true;
|
|
110054
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) {
|
|
110055
|
+
const token = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
110056
|
+
return new RegExp(`(?<=[:\\[,]\\s*)${token}(?=[,}\\]])`).test(text5);
|
|
110057
|
+
}
|
|
110058
|
+
return false;
|
|
110059
|
+
}
|
|
110060
|
+
function receiptFromNeedles(needles, payload) {
|
|
110061
|
+
if (payload === void 0) {
|
|
110062
|
+
const lines2 = needles.map((needle) => receiptLine(needle.label, needle.value, void 0));
|
|
110063
|
+
return { verification: "unknown", lines: lines2 };
|
|
110064
|
+
}
|
|
110065
|
+
const lines = needles.map(
|
|
110066
|
+
(needle) => receiptLine(needle.label, needle.value, payloadHasExact(payload, needle.value) ? needle.value : "\u672A\u627E\u5230")
|
|
110067
|
+
);
|
|
110068
|
+
return { verification: judgeReceipt(lines), lines };
|
|
110069
|
+
}
|
|
110070
|
+
function receiptForAbsence(label2, id, payload) {
|
|
110071
|
+
if (payload === void 0) {
|
|
110072
|
+
return {
|
|
110073
|
+
verification: "unknown",
|
|
110074
|
+
lines: [receiptLine(label2, "\u5DF2\u4E0D\u5728", void 0)]
|
|
110075
|
+
};
|
|
110076
|
+
}
|
|
110077
|
+
const stillThere = payloadHasExact(payload, id);
|
|
110078
|
+
const lines = [receiptLine(label2, "\u5DF2\u4E0D\u5728", stillThere ? "\u4ECD\u5728" : "\u5DF2\u4E0D\u5728")];
|
|
110079
|
+
return { verification: stillThere ? "partial" : "verified", lines };
|
|
110080
|
+
}
|
|
110081
|
+
|
|
110082
|
+
// src/commands/audit-restore.ts
|
|
109858
110083
|
var TSO_WRITE_AUDIT_NS3 = "tso";
|
|
109859
110084
|
var SUBSEQUENT_WRITES_LOOKBACK_DAYS_MAX = 400;
|
|
109860
110085
|
async function loadSnapshotForRecord(record2) {
|
|
@@ -110160,6 +110385,7 @@ async function runAuditRestoreApply(opts) {
|
|
|
110160
110385
|
{ method, body: JSON.stringify(snap.body) },
|
|
110161
110386
|
Boolean(opts.verbose)
|
|
110162
110387
|
);
|
|
110388
|
+
printWriteReceipt("submitted", [receiptLine("\u8865\u507F\u5199", auditId, "\u5DF2\u63D0\u4EA4")]);
|
|
110163
110389
|
const out = {
|
|
110164
110390
|
ok: true,
|
|
110165
110391
|
auditId,
|
|
@@ -110247,7 +110473,7 @@ init_dist();
|
|
|
110247
110473
|
init_version();
|
|
110248
110474
|
import * as path8 from "path";
|
|
110249
110475
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
110250
|
-
import { spawnSync } from "child_process";
|
|
110476
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
110251
110477
|
var __dirname = path8.dirname(fileURLToPath2(import.meta.url));
|
|
110252
110478
|
var PKG_NAME2 = "siluzan-tso-cli";
|
|
110253
110479
|
function getSkillSourceDir() {
|
|
@@ -110255,7 +110481,7 @@ function getSkillSourceDir() {
|
|
|
110255
110481
|
}
|
|
110256
110482
|
function isNpmGlobalInstall() {
|
|
110257
110483
|
try {
|
|
110258
|
-
const result =
|
|
110484
|
+
const result = spawnSync2("npm", ["list", "-g", "--depth=0", PKG_NAME2], {
|
|
110259
110485
|
encoding: "utf8",
|
|
110260
110486
|
stdio: "pipe"
|
|
110261
110487
|
});
|
|
@@ -110296,7 +110522,7 @@ async function runUpdate(options) {
|
|
|
110296
110522
|
}
|
|
110297
110523
|
if (isNpmGlobalInstall()) {
|
|
110298
110524
|
try {
|
|
110299
|
-
const result =
|
|
110525
|
+
const result = spawnSync2("npm", ["install", "-g", `${PKG_NAME2}@${targetVersion}`], {
|
|
110300
110526
|
stdio: "inherit",
|
|
110301
110527
|
shell: false
|
|
110302
110528
|
});
|
|
@@ -113264,6 +113490,43 @@ function endpointHintForFacebookSection(def, apiId) {
|
|
|
113264
113490
|
return `GET \u2026/FacebookAds/${apiId}/${def.segment}`;
|
|
113265
113491
|
}
|
|
113266
113492
|
|
|
113493
|
+
// src/commands/account-readback.ts
|
|
113494
|
+
init_auth();
|
|
113495
|
+
async function fetchAccountsByKeyword(config, media, keyword, verbose) {
|
|
113496
|
+
try {
|
|
113497
|
+
const platform = media ? PLATFORM_CONFIG[media] : void 0;
|
|
113498
|
+
const params = new URLSearchParams();
|
|
113499
|
+
if (platform) {
|
|
113500
|
+
for (const [key, value] of Object.entries(platform.fixedParams)) {
|
|
113501
|
+
params.set(key, String(value));
|
|
113502
|
+
}
|
|
113503
|
+
params.set(platform.pageParam, "1");
|
|
113504
|
+
} else {
|
|
113505
|
+
params.set("pageNo", "1");
|
|
113506
|
+
}
|
|
113507
|
+
params.set("pageSize", "20");
|
|
113508
|
+
applyListAccountsSearchKeyword(params, keyword);
|
|
113509
|
+
const path61 = platform?.path ?? "/query/media-account/";
|
|
113510
|
+
const url = `${config.apiBaseUrl}${path61}?${params}`;
|
|
113511
|
+
if (!platform || platform.responseType === "array") {
|
|
113512
|
+
const res = await apiFetchWithHeaders2(url, config, {}, verbose);
|
|
113513
|
+
return res.data;
|
|
113514
|
+
}
|
|
113515
|
+
return await apiFetch2(url, config, {}, verbose);
|
|
113516
|
+
} catch {
|
|
113517
|
+
return void 0;
|
|
113518
|
+
}
|
|
113519
|
+
}
|
|
113520
|
+
async function printAccountAbsence(config, media, keyword, label2, verbose) {
|
|
113521
|
+
const listed = await fetchAccountsByKeyword(config, media, keyword, verbose);
|
|
113522
|
+
const judged = receiptForAbsence(label2, keyword, listed);
|
|
113523
|
+
printWriteReceipt(judged.verification, judged.lines);
|
|
113524
|
+
}
|
|
113525
|
+
function printApplicationNeedles(needles, payload) {
|
|
113526
|
+
const judged = receiptFromNeedles(needles, payload);
|
|
113527
|
+
printWriteReceipt(judged.verification, judged.lines);
|
|
113528
|
+
}
|
|
113529
|
+
|
|
113267
113530
|
// src/commands/report/main.ts
|
|
113268
113531
|
async function runReportList(opts) {
|
|
113269
113532
|
if (!VALID_MEDIA_TYPES5.includes(opts.media)) {
|
|
@@ -113584,6 +113847,30 @@ async function runReportCreate(opts) {
|
|
|
113584
113847
|
`);
|
|
113585
113848
|
process.exit(1);
|
|
113586
113849
|
}
|
|
113850
|
+
const media = normalizeMedia(opts.media);
|
|
113851
|
+
let listed;
|
|
113852
|
+
try {
|
|
113853
|
+
const params = new URLSearchParams();
|
|
113854
|
+
params.set("PageIndex", "1");
|
|
113855
|
+
params.set("PageSize", "20");
|
|
113856
|
+
params.set("ReportType", opts.type);
|
|
113857
|
+
listed = await apiFetch2(
|
|
113858
|
+
`${config.apiBaseUrl}/query/media-account-report/stewardReportList/${media}?${params}`,
|
|
113859
|
+
config,
|
|
113860
|
+
{},
|
|
113861
|
+
opts.verbose
|
|
113862
|
+
);
|
|
113863
|
+
} catch {
|
|
113864
|
+
listed = void 0;
|
|
113865
|
+
}
|
|
113866
|
+
const firstCustomer = opts.accounts[0]?.trim() ?? "";
|
|
113867
|
+
printApplicationNeedles(
|
|
113868
|
+
[
|
|
113869
|
+
{ label: "\u8D26\u6237", value: firstCustomer },
|
|
113870
|
+
{ label: "\u7C7B\u578B", value: opts.type }
|
|
113871
|
+
].filter((item) => item.value),
|
|
113872
|
+
listed
|
|
113873
|
+
);
|
|
113587
113874
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
113588
113875
|
section: "report-create",
|
|
113589
113876
|
commandLabel: "report create",
|
|
@@ -113623,6 +113910,10 @@ async function runReportDelete(opts) {
|
|
|
113623
113910
|
`);
|
|
113624
113911
|
process.exit(1);
|
|
113625
113912
|
}
|
|
113913
|
+
const deletedIds = opts.ids && opts.ids.length > 1 ? opts.ids : [opts.id ?? opts.ids?.[0]].filter(Boolean);
|
|
113914
|
+
for (const id of deletedIds) {
|
|
113915
|
+
printWriteReceipt("submitted", [receiptLine("\u62A5\u544A", id, "\u5DF2\u63D0\u4EA4\u5220\u9664")]);
|
|
113916
|
+
}
|
|
113626
113917
|
console.log("\n\u2705 \u5220\u9664\u6210\u529F\n");
|
|
113627
113918
|
}
|
|
113628
113919
|
|
|
@@ -113692,6 +113983,38 @@ async function runReportPushList(opts) {
|
|
|
113692
113983
|
]);
|
|
113693
113984
|
console.log();
|
|
113694
113985
|
}
|
|
113986
|
+
async function printReportPushStoppedReceipt(config, opts, expectStopped) {
|
|
113987
|
+
let listed;
|
|
113988
|
+
try {
|
|
113989
|
+
const params = new URLSearchParams();
|
|
113990
|
+
params.set("pageIndex", "1");
|
|
113991
|
+
params.set("pageSize", "20");
|
|
113992
|
+
params.set("Name", "");
|
|
113993
|
+
params.set("ReportType", "");
|
|
113994
|
+
params.set("startDate", "");
|
|
113995
|
+
params.set("endDate", "");
|
|
113996
|
+
listed = await apiFetch2(
|
|
113997
|
+
`${config.apiBaseUrl}/query/report-push/settings/${opts.media}?${params}`,
|
|
113998
|
+
config,
|
|
113999
|
+
{},
|
|
114000
|
+
opts.verbose
|
|
114001
|
+
);
|
|
114002
|
+
} catch {
|
|
114003
|
+
listed = void 0;
|
|
114004
|
+
}
|
|
114005
|
+
const item = (listed?.results ?? []).find(
|
|
114006
|
+
(row) => String(row.entityId ?? row.id ?? "") === opts.id
|
|
114007
|
+
);
|
|
114008
|
+
const lines = [
|
|
114009
|
+
receiptLine("\u63A8\u9001\u914D\u7F6E", opts.id, item ? opts.id : listed === void 0 ? void 0 : "\u672A\u627E\u5230"),
|
|
114010
|
+
receiptLine(
|
|
114011
|
+
"\u5DF2\u505C\u7528",
|
|
114012
|
+
expectStopped ? "\u662F" : "\u5426",
|
|
114013
|
+
item === void 0 ? void 0 : item.stopped ? "\u662F" : "\u5426"
|
|
114014
|
+
)
|
|
114015
|
+
];
|
|
114016
|
+
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
114017
|
+
}
|
|
113695
114018
|
async function runReportPushStart(opts) {
|
|
113696
114019
|
assertReportPushMedia(opts.media);
|
|
113697
114020
|
const config = await ensureDataPermission(loadConfig(opts.token));
|
|
@@ -113704,6 +114027,7 @@ async function runReportPushStart(opts) {
|
|
|
113704
114027
|
`);
|
|
113705
114028
|
process.exit(1);
|
|
113706
114029
|
}
|
|
114030
|
+
await printReportPushStoppedReceipt(config, opts, false);
|
|
113707
114031
|
console.log("\n\u2705 \u63A8\u9001\u5DF2\u542F\u52A8\n");
|
|
113708
114032
|
}
|
|
113709
114033
|
async function runReportPushStop(opts) {
|
|
@@ -113718,6 +114042,7 @@ async function runReportPushStop(opts) {
|
|
|
113718
114042
|
`);
|
|
113719
114043
|
process.exit(1);
|
|
113720
114044
|
}
|
|
114045
|
+
await printReportPushStoppedReceipt(config, opts, true);
|
|
113721
114046
|
console.log("\n\u2705 \u63A8\u9001\u5DF2\u505C\u6B62\n");
|
|
113722
114047
|
}
|
|
113723
114048
|
async function runReportPushDelete(opts) {
|
|
@@ -113732,8 +114057,56 @@ async function runReportPushDelete(opts) {
|
|
|
113732
114057
|
`);
|
|
113733
114058
|
process.exit(1);
|
|
113734
114059
|
}
|
|
114060
|
+
let listed;
|
|
114061
|
+
try {
|
|
114062
|
+
const params = new URLSearchParams();
|
|
114063
|
+
params.set("pageIndex", "1");
|
|
114064
|
+
params.set("pageSize", "20");
|
|
114065
|
+
params.set("Name", "");
|
|
114066
|
+
params.set("ReportType", "");
|
|
114067
|
+
params.set("startDate", "");
|
|
114068
|
+
params.set("endDate", "");
|
|
114069
|
+
listed = await apiFetch2(
|
|
114070
|
+
`${config.apiBaseUrl}/query/report-push/settings/${opts.media}?${params}`,
|
|
114071
|
+
config,
|
|
114072
|
+
{},
|
|
114073
|
+
opts.verbose
|
|
114074
|
+
);
|
|
114075
|
+
} catch {
|
|
114076
|
+
listed = void 0;
|
|
114077
|
+
}
|
|
114078
|
+
const gone = receiptForAbsence("\u63A8\u9001\u914D\u7F6E", opts.id, listed);
|
|
114079
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
113735
114080
|
console.log("\n\u2705 \u63A8\u9001\u5DF2\u5220\u9664\n");
|
|
113736
114081
|
}
|
|
114082
|
+
async function printReportPushReceipt(config, opts) {
|
|
114083
|
+
let listed;
|
|
114084
|
+
try {
|
|
114085
|
+
const params = new URLSearchParams();
|
|
114086
|
+
params.set("pageIndex", "1");
|
|
114087
|
+
params.set("pageSize", "20");
|
|
114088
|
+
params.set("Name", opts.name);
|
|
114089
|
+
params.set("ReportType", "");
|
|
114090
|
+
params.set("startDate", "");
|
|
114091
|
+
params.set("endDate", "");
|
|
114092
|
+
listed = await apiFetch2(
|
|
114093
|
+
`${config.apiBaseUrl}/query/report-push/settings/${opts.media}?${params}`,
|
|
114094
|
+
config,
|
|
114095
|
+
{},
|
|
114096
|
+
opts.verbose
|
|
114097
|
+
);
|
|
114098
|
+
} catch {
|
|
114099
|
+
listed = void 0;
|
|
114100
|
+
}
|
|
114101
|
+
printApplicationNeedles(
|
|
114102
|
+
[
|
|
114103
|
+
{ label: "\u540D\u79F0", value: opts.name },
|
|
114104
|
+
{ label: "\u6536\u4EF6\u4EBA", value: opts.receiveEmails[0] ?? "" },
|
|
114105
|
+
{ label: "\u8D26\u6237", value: opts.mediaAccounts[0] ?? "" }
|
|
114106
|
+
].filter((item) => item.value),
|
|
114107
|
+
listed
|
|
114108
|
+
);
|
|
114109
|
+
}
|
|
113737
114110
|
async function runReportPushCreate(opts) {
|
|
113738
114111
|
assertReportPushMedia(opts.media);
|
|
113739
114112
|
const config = await ensureDataPermission(loadConfig(opts.token));
|
|
@@ -113754,6 +114127,7 @@ async function runReportPushCreate(opts) {
|
|
|
113754
114127
|
`);
|
|
113755
114128
|
process.exit(1);
|
|
113756
114129
|
}
|
|
114130
|
+
await printReportPushReceipt(config, opts);
|
|
113757
114131
|
console.log("\n\u2705 \u63A8\u9001\u914D\u7F6E\u5DF2\u521B\u5EFA\n");
|
|
113758
114132
|
}
|
|
113759
114133
|
async function runReportPushUpdate(opts) {
|
|
@@ -113777,6 +114151,7 @@ async function runReportPushUpdate(opts) {
|
|
|
113777
114151
|
`);
|
|
113778
114152
|
process.exit(1);
|
|
113779
114153
|
}
|
|
114154
|
+
await printReportPushReceipt(config, opts);
|
|
113780
114155
|
console.log("\n\u2705 \u63A8\u9001\u914D\u7F6E\u5DF2\u66F4\u65B0\n");
|
|
113781
114156
|
}
|
|
113782
114157
|
async function runReportPushHistory(opts) {
|
|
@@ -114110,6 +114485,28 @@ async function runTransferCreate(opts) {
|
|
|
114110
114485
|
`);
|
|
114111
114486
|
process.exit(1);
|
|
114112
114487
|
}
|
|
114488
|
+
let listed;
|
|
114489
|
+
try {
|
|
114490
|
+
const params = new URLSearchParams();
|
|
114491
|
+
params.set("pageNumber", "1");
|
|
114492
|
+
params.set("pageSize", "20");
|
|
114493
|
+
listed = await apiFetch2(
|
|
114494
|
+
`${config.apiBaseUrl}/query/accounttransfer/${mediaToPath(opts.media)}/search?${params}`,
|
|
114495
|
+
config,
|
|
114496
|
+
{},
|
|
114497
|
+
opts.verbose
|
|
114498
|
+
);
|
|
114499
|
+
} catch {
|
|
114500
|
+
listed = void 0;
|
|
114501
|
+
}
|
|
114502
|
+
printApplicationNeedles(
|
|
114503
|
+
[
|
|
114504
|
+
{ label: "\u8F6C\u51FA\u8D26\u6237", value: opts.outAccount },
|
|
114505
|
+
{ label: "\u8F6C\u5165\u8D26\u6237", value: opts.inAccount },
|
|
114506
|
+
{ label: "\u7533\u8BF7\u91D1\u989D", value: String(opts.amount) }
|
|
114507
|
+
],
|
|
114508
|
+
listed
|
|
114509
|
+
);
|
|
114113
114510
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
114114
114511
|
section: `transfer-create-${mediaToPath(opts.media)}`,
|
|
114115
114512
|
commandLabel: "transfer create",
|
|
@@ -114588,7 +114985,7 @@ async function runInvoiceApply(opts) {
|
|
|
114588
114985
|
} else {
|
|
114589
114986
|
const cnName = opts.companyName?.trim() ?? "";
|
|
114590
114987
|
const tax = opts.taxId?.trim() ?? "";
|
|
114591
|
-
const
|
|
114988
|
+
const title2 = opts.title?.trim() ?? "";
|
|
114592
114989
|
const landline = opts.companyPhone?.trim() ?? "";
|
|
114593
114990
|
if (!cnName) {
|
|
114594
114991
|
console.error("\n\u274C VATI/VATSI \u9700\u8981 --company-name\uFF08\u4E2D\u6587\u516C\u53F8\u540D\uFF09\n");
|
|
@@ -114598,7 +114995,7 @@ async function runInvoiceApply(opts) {
|
|
|
114598
114995
|
console.error("\n\u274C VATI/VATSI \u9700\u8981 --tax-id\uFF08\u4F01\u4E1A\u7A0E\u53F7\uFF09\n");
|
|
114599
114996
|
process.exit(1);
|
|
114600
114997
|
}
|
|
114601
|
-
if (!
|
|
114998
|
+
if (!title2) {
|
|
114602
114999
|
console.error("\n\u274C VATI/VATSI \u9700\u8981 --title\uFF08\u53D1\u7968\u62AC\u5934\uFF09\n");
|
|
114603
115000
|
process.exit(1);
|
|
114604
115001
|
}
|
|
@@ -114609,7 +115006,7 @@ async function runInvoiceApply(opts) {
|
|
|
114609
115006
|
invoiceInfomation = {
|
|
114610
115007
|
CompanyName: cnName,
|
|
114611
115008
|
TaxIdentificationNumber: tax,
|
|
114612
|
-
Title:
|
|
115009
|
+
Title: title2,
|
|
114613
115010
|
Phone: landline
|
|
114614
115011
|
};
|
|
114615
115012
|
}
|
|
@@ -114641,6 +115038,31 @@ async function runInvoiceApply(opts) {
|
|
|
114641
115038
|
`);
|
|
114642
115039
|
process.exit(1);
|
|
114643
115040
|
}
|
|
115041
|
+
const end = /* @__PURE__ */ new Date();
|
|
115042
|
+
const start = /* @__PURE__ */ new Date();
|
|
115043
|
+
start.setMonth(start.getMonth() - 3);
|
|
115044
|
+
const params = new URLSearchParams();
|
|
115045
|
+
params.set("pageIndex", "1");
|
|
115046
|
+
params.set("pageSize", "20");
|
|
115047
|
+
params.set("searchValue", opts.billIds[0] ?? "");
|
|
115048
|
+
params.set("startDate", start.toISOString().slice(0, 10));
|
|
115049
|
+
params.set("endDate", end.toISOString().slice(0, 10));
|
|
115050
|
+
let listed;
|
|
115051
|
+
try {
|
|
115052
|
+
listed = await apiFetch2(`${config.apiBaseUrl}/invoice-request?${params}`, config, {}, opts.verbose);
|
|
115053
|
+
} catch {
|
|
115054
|
+
listed = void 0;
|
|
115055
|
+
}
|
|
115056
|
+
const info = invoiceInfomation;
|
|
115057
|
+
const title = String(info.Title || info.CompanyName || info.CompanyNameEn || "");
|
|
115058
|
+
printApplicationNeedles(
|
|
115059
|
+
[
|
|
115060
|
+
{ label: "\u8BA2\u5355", value: opts.billIds[0] ?? "" },
|
|
115061
|
+
{ label: "\u7968\u79CD", value: opts.invoiceType },
|
|
115062
|
+
...title ? [{ label: "\u62AC\u5934", value: title }] : []
|
|
115063
|
+
],
|
|
115064
|
+
listed
|
|
115065
|
+
);
|
|
114644
115066
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
114645
115067
|
section: "invoice-apply",
|
|
114646
115068
|
commandLabel: "invoice apply",
|
|
@@ -114859,6 +115281,29 @@ async function runInvoiceInfoCreate(opts) {
|
|
|
114859
115281
|
`);
|
|
114860
115282
|
process.exit(1);
|
|
114861
115283
|
}
|
|
115284
|
+
if (!data?.id) {
|
|
115285
|
+
console.error(`
|
|
115286
|
+
\u274C \u521B\u5EFA\u5931\u8D25\uFF1A${JSON.stringify(data)}
|
|
115287
|
+
`);
|
|
115288
|
+
process.exit(1);
|
|
115289
|
+
}
|
|
115290
|
+
let listed;
|
|
115291
|
+
try {
|
|
115292
|
+
const params = new URLSearchParams();
|
|
115293
|
+
params.set("pageIndex", "1");
|
|
115294
|
+
params.set("pageSize", "20");
|
|
115295
|
+
params.set("search", opts.companyName);
|
|
115296
|
+
listed = await apiFetch2(`${config.apiBaseUrl}/InvoiceInfos?${params}`, config, {}, opts.verbose);
|
|
115297
|
+
} catch {
|
|
115298
|
+
listed = void 0;
|
|
115299
|
+
}
|
|
115300
|
+
printApplicationNeedles(
|
|
115301
|
+
[
|
|
115302
|
+
{ label: "\u62AC\u5934", value: data.id },
|
|
115303
|
+
{ label: "\u516C\u53F8", value: opts.companyName }
|
|
115304
|
+
],
|
|
115305
|
+
listed
|
|
115306
|
+
);
|
|
114862
115307
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
114863
115308
|
section: "invoice-info-create",
|
|
114864
115309
|
commandLabel: "invoice-info create",
|
|
@@ -114866,16 +115311,9 @@ async function runInvoiceInfoCreate(opts) {
|
|
|
114866
115311
|
})) {
|
|
114867
115312
|
return;
|
|
114868
115313
|
}
|
|
114869
|
-
|
|
114870
|
-
console.log(`
|
|
115314
|
+
console.log(`
|
|
114871
115315
|
\u2705 \u53D1\u7968\u62AC\u5934\u5DF2\u521B\u5EFA\uFF08ID: ${data.id}\uFF09
|
|
114872
115316
|
`);
|
|
114873
|
-
} else {
|
|
114874
|
-
console.error(`
|
|
114875
|
-
\u274C \u521B\u5EFA\u5931\u8D25\uFF1A${JSON.stringify(data)}
|
|
114876
|
-
`);
|
|
114877
|
-
process.exit(1);
|
|
114878
|
-
}
|
|
114879
115317
|
}
|
|
114880
115318
|
async function runInvoiceInfoUpdate(opts) {
|
|
114881
115319
|
const config = loadConfig(opts.token);
|
|
@@ -114890,6 +115328,29 @@ async function runInvoiceInfoUpdate(opts) {
|
|
|
114890
115328
|
`);
|
|
114891
115329
|
process.exit(1);
|
|
114892
115330
|
}
|
|
115331
|
+
if (!data?.id) {
|
|
115332
|
+
console.error(`
|
|
115333
|
+
\u274C \u66F4\u65B0\u5931\u8D25\uFF1A${JSON.stringify(data)}
|
|
115334
|
+
`);
|
|
115335
|
+
process.exit(1);
|
|
115336
|
+
}
|
|
115337
|
+
let listed;
|
|
115338
|
+
try {
|
|
115339
|
+
const params = new URLSearchParams();
|
|
115340
|
+
params.set("pageIndex", "1");
|
|
115341
|
+
params.set("pageSize", "20");
|
|
115342
|
+
params.set("search", opts.companyName);
|
|
115343
|
+
listed = await apiFetch2(`${config.apiBaseUrl}/InvoiceInfos?${params}`, config, {}, opts.verbose);
|
|
115344
|
+
} catch {
|
|
115345
|
+
listed = void 0;
|
|
115346
|
+
}
|
|
115347
|
+
printApplicationNeedles(
|
|
115348
|
+
[
|
|
115349
|
+
{ label: "\u62AC\u5934", value: opts.id },
|
|
115350
|
+
{ label: "\u516C\u53F8", value: opts.companyName }
|
|
115351
|
+
],
|
|
115352
|
+
listed
|
|
115353
|
+
);
|
|
114893
115354
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
114894
115355
|
section: `invoice-info-update-${opts.id}`,
|
|
114895
115356
|
commandLabel: "invoice-info update",
|
|
@@ -114899,16 +115360,9 @@ async function runInvoiceInfoUpdate(opts) {
|
|
|
114899
115360
|
})) {
|
|
114900
115361
|
return;
|
|
114901
115362
|
}
|
|
114902
|
-
|
|
114903
|
-
console.log(`
|
|
115363
|
+
console.log(`
|
|
114904
115364
|
\u2705 \u53D1\u7968\u62AC\u5934\u5DF2\u66F4\u65B0\uFF08ID: ${data.id}\uFF09
|
|
114905
115365
|
`);
|
|
114906
|
-
} else {
|
|
114907
|
-
console.error(`
|
|
114908
|
-
\u274C \u66F4\u65B0\u5931\u8D25\uFF1A${JSON.stringify(data)}
|
|
114909
|
-
`);
|
|
114910
|
-
process.exit(1);
|
|
114911
|
-
}
|
|
114912
115366
|
}
|
|
114913
115367
|
async function runInvoiceInfoDelete(opts) {
|
|
114914
115368
|
const config = loadConfig(opts.token);
|
|
@@ -114921,6 +115375,17 @@ async function runInvoiceInfoDelete(opts) {
|
|
|
114921
115375
|
`);
|
|
114922
115376
|
process.exit(1);
|
|
114923
115377
|
}
|
|
115378
|
+
let listed;
|
|
115379
|
+
try {
|
|
115380
|
+
const params = new URLSearchParams();
|
|
115381
|
+
params.set("pageIndex", "1");
|
|
115382
|
+
params.set("pageSize", "20");
|
|
115383
|
+
listed = await apiFetch2(`${config.apiBaseUrl}/InvoiceInfos?${params}`, config, {}, opts.verbose);
|
|
115384
|
+
} catch {
|
|
115385
|
+
listed = void 0;
|
|
115386
|
+
}
|
|
115387
|
+
const gone = receiptForAbsence("\u62AC\u5934", opts.id, listed);
|
|
115388
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
114924
115389
|
console.log(`
|
|
114925
115390
|
\u2705 \u53D1\u7968\u62AC\u5934\u5DF2\u5220\u9664\uFF08ID: ${opts.id}\uFF09
|
|
114926
115391
|
`);
|
|
@@ -115515,6 +115980,29 @@ async function runForewarningRecords(opts) {
|
|
|
115515
115980
|
|
|
115516
115981
|
// src/commands/forewarning/actions.ts
|
|
115517
115982
|
init_auth();
|
|
115983
|
+
async function printForewarningStoppedReceipt(config, opts, expectStopped) {
|
|
115984
|
+
let detail;
|
|
115985
|
+
try {
|
|
115986
|
+
detail = await apiFetch2(
|
|
115987
|
+
`${config.apiBaseUrl}/query/smart-strategy/settings/${opts.media}/${opts.id}`,
|
|
115988
|
+
config,
|
|
115989
|
+
{},
|
|
115990
|
+
opts.verbose
|
|
115991
|
+
);
|
|
115992
|
+
} catch {
|
|
115993
|
+
detail = void 0;
|
|
115994
|
+
}
|
|
115995
|
+
const stopped = detail && typeof detail === "object" && "stopped" in detail ? Boolean(detail.stopped) : void 0;
|
|
115996
|
+
const lines = [
|
|
115997
|
+
receiptLine("\u89C4\u5219", opts.id, detail === void 0 ? void 0 : opts.id),
|
|
115998
|
+
receiptLine(
|
|
115999
|
+
"\u5DF2\u505C\u7528",
|
|
116000
|
+
expectStopped ? "\u662F" : "\u5426",
|
|
116001
|
+
stopped === void 0 ? void 0 : stopped ? "\u662F" : "\u5426"
|
|
116002
|
+
)
|
|
116003
|
+
];
|
|
116004
|
+
printWriteReceipt(detail === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
116005
|
+
}
|
|
115518
116006
|
async function runForewarningStart(opts) {
|
|
115519
116007
|
if (skipForewarningInAgentEnv("siluzan-tso forewarning start")) return;
|
|
115520
116008
|
const config = loadConfig(opts.token);
|
|
@@ -115527,6 +116015,7 @@ async function runForewarningStart(opts) {
|
|
|
115527
116015
|
`);
|
|
115528
116016
|
process.exit(1);
|
|
115529
116017
|
}
|
|
116018
|
+
await printForewarningStoppedReceipt(config, opts, false);
|
|
115530
116019
|
console.log("\n\u2705 \u9884\u8B66\u89C4\u5219\u5DF2\u542F\u52A8\n");
|
|
115531
116020
|
}
|
|
115532
116021
|
async function runForewarningStop(opts) {
|
|
@@ -115541,6 +116030,7 @@ async function runForewarningStop(opts) {
|
|
|
115541
116030
|
`);
|
|
115542
116031
|
process.exit(1);
|
|
115543
116032
|
}
|
|
116033
|
+
await printForewarningStoppedReceipt(config, opts, true);
|
|
115544
116034
|
console.log("\n\u2705 \u9884\u8B66\u89C4\u5219\u5DF2\u505C\u6B62\n");
|
|
115545
116035
|
}
|
|
115546
116036
|
async function runForewarningDelete(opts) {
|
|
@@ -115555,6 +116045,19 @@ async function runForewarningDelete(opts) {
|
|
|
115555
116045
|
`);
|
|
115556
116046
|
process.exit(1);
|
|
115557
116047
|
}
|
|
116048
|
+
let listed;
|
|
116049
|
+
try {
|
|
116050
|
+
listed = await apiFetch2(
|
|
116051
|
+
`${config.apiBaseUrl}/query/smart-strategy/settings/${opts.media}?PageIndex=1&PageSize=20`,
|
|
116052
|
+
config,
|
|
116053
|
+
{},
|
|
116054
|
+
opts.verbose
|
|
116055
|
+
);
|
|
116056
|
+
} catch {
|
|
116057
|
+
listed = void 0;
|
|
116058
|
+
}
|
|
116059
|
+
const gone = receiptForAbsence("\u9884\u8B66\u89C4\u5219", opts.id, listed);
|
|
116060
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
115558
116061
|
console.log("\n\u2705 \u9884\u8B66\u89C4\u5219\u5DF2\u5220\u9664\n");
|
|
115559
116062
|
}
|
|
115560
116063
|
async function runForewarningGet(opts) {
|
|
@@ -115742,6 +116245,21 @@ async function runForewarningCreate(opts) {
|
|
|
115742
116245
|
`);
|
|
115743
116246
|
process.exit(1);
|
|
115744
116247
|
}
|
|
116248
|
+
let listed;
|
|
116249
|
+
try {
|
|
116250
|
+
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)}`;
|
|
116251
|
+
listed = await apiFetch2(url2, config, {}, opts.verbose);
|
|
116252
|
+
} catch {
|
|
116253
|
+
listed = void 0;
|
|
116254
|
+
}
|
|
116255
|
+
printApplicationNeedles(
|
|
116256
|
+
[
|
|
116257
|
+
{ label: "\u540D\u79F0", value: opts.name },
|
|
116258
|
+
{ label: "\u5B57\u6BB5", value: opts.field },
|
|
116259
|
+
{ label: "\u9608\u503C", value: String(opts.value) }
|
|
116260
|
+
],
|
|
116261
|
+
listed
|
|
116262
|
+
);
|
|
115745
116263
|
console.log(`
|
|
115746
116264
|
\u2705 \u9884\u8B66\u89C4\u5219\u5DF2${isUpdate ? "\u66F4\u65B0" : "\u521B\u5EFA"}\uFF1A${opts.name}
|
|
115747
116265
|
`);
|
|
@@ -116957,6 +117475,18 @@ function summarizeNegativeKeywordCreate(requested, response, listItems) {
|
|
|
116957
117475
|
}
|
|
116958
117476
|
|
|
116959
117477
|
// src/commands/ad/keyword.ts
|
|
117478
|
+
async function printIdGone(label2, listUrl, config, id, verbose) {
|
|
117479
|
+
try {
|
|
117480
|
+
await findItemInList(listUrl, config, id, verbose);
|
|
117481
|
+
printWriteReceipt("partial", [receiptLine(label2, "\u5DF2\u5220\u9664", "\u4ECD\u5728")]);
|
|
117482
|
+
} catch (err) {
|
|
117483
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
117484
|
+
const gone = message.includes("\u672A\u5728\u5217\u8868\u4E2D\u627E\u5230");
|
|
117485
|
+
printWriteReceipt(gone ? "verified" : "unknown", [
|
|
117486
|
+
receiptLine(label2, "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : void 0)
|
|
117487
|
+
]);
|
|
117488
|
+
}
|
|
117489
|
+
}
|
|
116960
117490
|
function unwrapKeywordDisplayTextForEdit(raw) {
|
|
116961
117491
|
const t = raw.trim();
|
|
116962
117492
|
if (t.length >= 2 && t.startsWith('"') && t.endsWith('"')) {
|
|
@@ -117272,6 +117802,37 @@ async function runAdKeywordCreate(opts) {
|
|
|
117272
117802
|
`);
|
|
117273
117803
|
process.exit(1);
|
|
117274
117804
|
}
|
|
117805
|
+
const listParams = new URLSearchParams();
|
|
117806
|
+
listParams.set("startDate", toGoogleDate(void 0, -30));
|
|
117807
|
+
listParams.set("endDate", toGoogleDate(void 0, 0));
|
|
117808
|
+
listParams.set("newest", "true");
|
|
117809
|
+
let listItems = null;
|
|
117810
|
+
try {
|
|
117811
|
+
const listed = await apiFetch2(
|
|
117812
|
+
`${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${listParams}`,
|
|
117813
|
+
config,
|
|
117814
|
+
{},
|
|
117815
|
+
opts.verbose
|
|
117816
|
+
);
|
|
117817
|
+
listItems = listed.data ?? [];
|
|
117818
|
+
} catch {
|
|
117819
|
+
listItems = null;
|
|
117820
|
+
}
|
|
117821
|
+
const summary = summarizeNegativeKeywordCreate(keywords, response, listItems);
|
|
117822
|
+
const matched = new Set(summary.matched.map((item) => item.text));
|
|
117823
|
+
const lines = keywords.map(
|
|
117824
|
+
(text5) => receiptLine("\u5173\u952E\u8BCD", text5, listItems == null ? void 0 : matched.has(text5) ? text5 : "\u672A\u627E\u5230")
|
|
117825
|
+
);
|
|
117826
|
+
if (opts.finalUrl) {
|
|
117827
|
+
const hit = listItems?.find((item) => {
|
|
117828
|
+
const cores = [item["finalURL"], item["finalUrl"], item["FinalUrl"]].map(
|
|
117829
|
+
(value) => value == null ? "" : String(value)
|
|
117830
|
+
);
|
|
117831
|
+
return cores.includes(opts.finalUrl);
|
|
117832
|
+
});
|
|
117833
|
+
lines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, listItems == null ? void 0 : hit ? opts.finalUrl : "\u672A\u627E\u5230"));
|
|
117834
|
+
}
|
|
117835
|
+
printWriteReceipt(listItems == null ? "unknown" : judgeReceipt(lines), lines);
|
|
117275
117836
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
117276
117837
|
section: `ad-keyword-create-${opts.account}-${opts.adgroupId}`,
|
|
117277
117838
|
commandLabel: "ad keyword-create",
|
|
@@ -117362,7 +117923,7 @@ async function runAdNegativeKeywordCreate(opts) {
|
|
|
117362
117923
|
`);
|
|
117363
117924
|
process.exit(1);
|
|
117364
117925
|
}
|
|
117365
|
-
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account);
|
|
117926
|
+
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account, { newest: true });
|
|
117366
117927
|
const readList = async () => {
|
|
117367
117928
|
try {
|
|
117368
117929
|
const listed = await apiFetch2(
|
|
@@ -117386,6 +117947,13 @@ async function runAdNegativeKeywordCreate(opts) {
|
|
|
117386
117947
|
const nextQuery = `siluzan-tso ad keywords -a ${opts.account} --negative --json-out ./snap`;
|
|
117387
117948
|
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")}` : ""}`;
|
|
117388
117949
|
const headline = writeVerificationHeadline(summary.verification, detail);
|
|
117950
|
+
const matchedTexts = new Set(summary.matched.map((item) => item.text));
|
|
117951
|
+
printWriteReceipt(
|
|
117952
|
+
summary.verification,
|
|
117953
|
+
keywords.map(
|
|
117954
|
+
(text5) => receiptLine("\u5426\u5B9A\u5173\u952E\u8BCD", text5, listItems == null ? void 0 : matchedTexts.has(text5) ? text5 : "\u672A\u627E\u5230")
|
|
117955
|
+
)
|
|
117956
|
+
);
|
|
117389
117957
|
if (summary.verification !== "verified") {
|
|
117390
117958
|
console.error(`
|
|
117391
117959
|
${headline}
|
|
@@ -117433,6 +118001,17 @@ async function runAdKeywordDelete(opts) {
|
|
|
117433
118001
|
`);
|
|
117434
118002
|
process.exit(1);
|
|
117435
118003
|
}
|
|
118004
|
+
const goneParams = new URLSearchParams();
|
|
118005
|
+
goneParams.set("startDate", toGoogleDate(void 0, -30));
|
|
118006
|
+
goneParams.set("endDate", toGoogleDate(void 0, 0));
|
|
118007
|
+
goneParams.set("newest", "true");
|
|
118008
|
+
await printIdGone(
|
|
118009
|
+
"\u5173\u952E\u8BCD",
|
|
118010
|
+
`${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${goneParams}`,
|
|
118011
|
+
config,
|
|
118012
|
+
opts.id,
|
|
118013
|
+
opts.verbose
|
|
118014
|
+
);
|
|
117436
118015
|
console.log(`
|
|
117437
118016
|
\u2705 \u5173\u952E\u8BCD ${opts.id} \u5DF2\u5220\u9664
|
|
117438
118017
|
`);
|
|
@@ -117449,7 +118028,7 @@ function findKeywordEditMismatches(requested, returned, changed) {
|
|
|
117449
118028
|
const expectedCents = Number(requested["maxCPC"]);
|
|
117450
118029
|
const actualCents = returned["maxCPC"];
|
|
117451
118030
|
mismatches.push(
|
|
117452
|
-
`maxCPC\uFF1A\u671F\u671B ${expectedCents / 100} \u5143\uFF0C\u5217\u8868\u4ECD\u662F ${actualCents / 100} \u5143\u3002\
|
|
118031
|
+
`maxCPC\uFF1A\u671F\u671B ${expectedCents / 100} \u5143\uFF0C\u5217\u8868\u4ECD\u662F ${actualCents / 100} \u5143\u3002\u8FD9\u6B21\u56DE\u8BFB\u5DF2\u8DF3\u8FC7\u7F51\u5173\u5217\u8868\u7F13\u5B58\uFF0C\u8FD9\u662F\u5F53\u524D\u8BFB\u5230\u7684\u51FA\u4EF7\u3002\u4E0D\u8981\u7ACB\u523B\u91CD\u8DD1 keyword-edit\uFF0C\u4E5F\u4E0D\u8981\u5220\u8BCD\u91CD\u5EFA\u3002`
|
|
117453
118032
|
);
|
|
117454
118033
|
}
|
|
117455
118034
|
if (changed.status !== void 0 && typeof returned["userStatusV2"] === "string" && str3(returned["userStatusV2"]).toLowerCase() !== changed.status.toLowerCase()) {
|
|
@@ -117477,10 +118056,12 @@ async function runAdKeywordEdit(opts) {
|
|
|
117477
118056
|
const params = new URLSearchParams();
|
|
117478
118057
|
params.set("startDate", toGoogleDate(opts.startDate, -30));
|
|
117479
118058
|
params.set("endDate", toGoogleDate(opts.endDate, 0));
|
|
118059
|
+
params.set("newest", "true");
|
|
117480
118060
|
const listUrl = `${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${params}`;
|
|
117481
118061
|
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
|
|
117482
118062
|
`;
|
|
117483
118063
|
let currentId = opts.id;
|
|
118064
|
+
let submittedText = opts.text !== void 0 && opts.matchType === void 0 ? opts.text : void 0;
|
|
117484
118065
|
if (replacesText) {
|
|
117485
118066
|
let keyword;
|
|
117486
118067
|
try {
|
|
@@ -117503,10 +118084,12 @@ async function runAdKeywordEdit(opts) {
|
|
|
117503
118084
|
console.error("\n\u274C \u65E0\u6CD5\u89E3\u6790\u5F53\u524D\u5173\u952E\u8BCD\u6587\u6848\uFF0C\u8BF7\u540C\u65F6\u4F20 --text <\u8BCD\u5E72>\n");
|
|
117504
118085
|
process.exit(1);
|
|
117505
118086
|
}
|
|
117506
|
-
|
|
118087
|
+
submittedText = formatKeywordTextForMatchType(base2, opts.matchType);
|
|
118088
|
+
body["keywordText"] = [submittedText];
|
|
117507
118089
|
body["matchTypeV2"] = opts.matchType;
|
|
117508
118090
|
} else if (opts.text !== void 0) {
|
|
117509
118091
|
body["keywordText"] = [opts.text];
|
|
118092
|
+
submittedText = opts.text;
|
|
117510
118093
|
}
|
|
117511
118094
|
const url = `${googleApiUrl}/keywordmanagement/Keyword/${opts.account}/batch`;
|
|
117512
118095
|
try {
|
|
@@ -117553,57 +118136,79 @@ async function runAdKeywordEdit(opts) {
|
|
|
117553
118136
|
finalURL: opts.finalUrl,
|
|
117554
118137
|
maxCPC: opts.maxCpc !== void 0 ? toCentAmount(opts.maxCpc) : void 0
|
|
117555
118138
|
};
|
|
117556
|
-
|
|
117557
|
-
|
|
117558
|
-
|
|
117559
|
-
|
|
117560
|
-
|
|
117561
|
-
|
|
117562
|
-
|
|
117563
|
-
|
|
117564
|
-
|
|
117565
|
-
|
|
117566
|
-
|
|
117567
|
-
|
|
118139
|
+
let fresh;
|
|
118140
|
+
try {
|
|
118141
|
+
fresh = await findItemInList(listUrl, config, currentId, opts.verbose);
|
|
118142
|
+
} catch (err) {
|
|
118143
|
+
const editLines2 = [];
|
|
118144
|
+
if (opts.text !== void 0 || opts.matchType !== void 0) {
|
|
118145
|
+
editLines2.push(receiptLine("\u8BCD\u9762", submittedText ?? opts.text ?? "\u5DF2\u63D0\u4EA4", void 0));
|
|
118146
|
+
}
|
|
118147
|
+
if (opts.matchType !== void 0) {
|
|
118148
|
+
editLines2.push(receiptLine("\u5339\u914D\u7C7B\u578B", opts.matchType, void 0));
|
|
118149
|
+
}
|
|
118150
|
+
if (opts.finalUrl !== void 0) editLines2.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, void 0));
|
|
118151
|
+
if (opts.maxCpc !== void 0) editLines2.push(receiptLine("CPC\u4E0A\u9650", yuanLabel(opts.maxCpc), void 0));
|
|
118152
|
+
if (opts.status !== void 0) editLines2.push(receiptLine("\u72B6\u6001", opts.status, void 0));
|
|
118153
|
+
printWriteReceipt("unknown", editLines2);
|
|
118154
|
+
console.error(
|
|
118155
|
+
`
|
|
117568
118156
|
\u274C \u5199\u5165\u8BF7\u6C42\u5DF2\u53D1\u9001\uFF0C\u4F46\u56DE\u8BFB\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
117569
118157
|
\u7A0D\u540E\u7528 ad keywords \u6838\u5BF9 id=${currentId} \u7684\u5B9E\u9645\u503C\uFF1B\u672A\u751F\u6548\u65F6\u91CD\u8DD1 keyword-edit \u5373\u53EF\uFF08\u5E42\u7B49\uFF09\u3002
|
|
117570
118158
|
` + notAppliedHint
|
|
117571
|
-
|
|
117572
|
-
|
|
118159
|
+
);
|
|
118160
|
+
process.exit(1);
|
|
118161
|
+
}
|
|
118162
|
+
const mismatches = findKeywordEditMismatches(readbackExpected, fresh, opts);
|
|
118163
|
+
const editLines = [];
|
|
118164
|
+
if (opts.text !== void 0 || opts.matchType !== void 0) {
|
|
118165
|
+
const actualText = firstKeywordTextFromRecord(fresh);
|
|
118166
|
+
const expect = submittedText ?? opts.text ?? "";
|
|
118167
|
+
editLines.push(receiptLine("\u8BCD\u9762", expect, actualText || void 0));
|
|
118168
|
+
if (expect && actualText.trim() !== expect.trim()) {
|
|
118169
|
+
mismatches.push(`\u8BCD\u9762\uFF1A\u671F\u671B ${expect}\uFF0C\u5B9E\u9645 ${actualText || "(\u7A7A)"}`);
|
|
117573
118170
|
}
|
|
117574
|
-
|
|
117575
|
-
|
|
117576
|
-
|
|
117577
|
-
|
|
118171
|
+
}
|
|
118172
|
+
if (opts.matchType !== void 0) {
|
|
118173
|
+
const actualMatch = String(fresh["matchTypeV2"] ?? fresh["matchType"] ?? "").trim();
|
|
118174
|
+
editLines.push(receiptLine("\u5339\u914D\u7C7B\u578B", opts.matchType, actualMatch || void 0));
|
|
118175
|
+
if (!actualMatch || actualMatch.toLowerCase() !== opts.matchType.toLowerCase()) {
|
|
118176
|
+
mismatches.push(`\u5339\u914D\u7C7B\u578B\uFF1A\u671F\u671B ${opts.matchType}\uFF0C\u5B9E\u9645 ${actualMatch || "(\u7A7A)"}`);
|
|
118177
|
+
}
|
|
118178
|
+
}
|
|
118179
|
+
if (opts.finalUrl !== void 0) {
|
|
118180
|
+
editLines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, fresh["finalURL"] ?? fresh["FinalUrl"]));
|
|
118181
|
+
}
|
|
118182
|
+
if (opts.maxCpc !== void 0) {
|
|
118183
|
+
const cents = fresh["maxCPC"] ?? fresh["maxCpc"];
|
|
118184
|
+
const yuan = typeof cents === "number" ? cents / 100 : void 0;
|
|
118185
|
+
editLines.push(receiptLine("CPC\u4E0A\u9650", yuanLabel(opts.maxCpc), yuan == null ? void 0 : yuanLabel(yuan)));
|
|
118186
|
+
}
|
|
118187
|
+
if (opts.status !== void 0) {
|
|
118188
|
+
editLines.push(receiptLine("\u72B6\u6001", opts.status, fresh["userStatusV2"] ?? fresh["status"]));
|
|
118189
|
+
}
|
|
118190
|
+
printWriteReceipt(mismatches.length > 0 ? "partial" : judgeReceipt(editLines), editLines);
|
|
118191
|
+
if (mismatches.length > 0) {
|
|
118192
|
+
console.error(
|
|
118193
|
+
`
|
|
117578
118194
|
\u274C \u7F51\u5173\u8FD4\u56DE\u6210\u529F\uFF0C\u4F46\u56DE\u8BFB\u540E\u4EE5\u4E0B\u5B57\u6BB5\u672A\u751F\u6548\uFF1A
|
|
117579
118195
|
${mismatches.map((m) => ` - ${m}`).join("\n")}
|
|
117580
118196
|
` + notAppliedHint
|
|
117581
|
-
|
|
117582
|
-
|
|
117583
|
-
}
|
|
118197
|
+
);
|
|
118198
|
+
process.exit(1);
|
|
117584
118199
|
}
|
|
117585
118200
|
const verifiedFields = [];
|
|
118201
|
+
if (opts.text !== void 0 || opts.matchType !== void 0) verifiedFields.push("\u8BCD\u9762");
|
|
118202
|
+
if (opts.matchType !== void 0) verifiedFields.push("\u5339\u914D\u7C7B\u578B");
|
|
117586
118203
|
if (opts.finalUrl !== void 0) verifiedFields.push("finalURL");
|
|
117587
118204
|
if (opts.maxCpc !== void 0) verifiedFields.push("maxCPC");
|
|
117588
118205
|
if (opts.status !== void 0) verifiedFields.push("userStatusV2");
|
|
117589
118206
|
const changeKind = currentId !== opts.id ? "replace" : "update";
|
|
117590
|
-
|
|
117591
|
-
|
|
117592
|
-
`
|
|
118207
|
+
console.log(
|
|
118208
|
+
`
|
|
117593
118209
|
\u2705 \u5173\u952E\u8BCD\u5DF2\u6838\u9A8C\uFF08${verifiedFields.join("\u3001")}\uFF1BchangeKind=${changeKind}${changeKind === "replace" ? `\uFF0C\u65B0 id ${currentId}` : ""}\uFF09
|
|
117594
118210
|
`
|
|
117595
|
-
|
|
117596
|
-
} else if (changeKind === "replace") {
|
|
117597
|
-
console.log(
|
|
117598
|
-
`
|
|
117599
|
-
\u2705 \u5173\u952E\u8BCD\u5DF2\u63D0\u4EA4\uFF08changeKind=replace\uFF0C\u65B0 id ${currentId}\uFF09\u3002\u8BCD\u9762\u6216\u5339\u914D\u7C7B\u578B\u4F1A\u65B0\u5EFA\u5E76\u79FB\u9664\u65E7\u8BCD\uFF0C\u8BF7\u7528 ad keywords \u6838\u5BF9\u65B0 id\u3002
|
|
117600
|
-
`
|
|
117601
|
-
);
|
|
117602
|
-
} else {
|
|
117603
|
-
console.log(`
|
|
117604
|
-
\u2705 \u5173\u952E\u8BCD\u5DF2\u63D0\u4EA4\uFF08changeKind=update\uFF09\u3002\u8BF7\u7528 ad keywords \u6838\u5BF9\u8BCD\u9762\u3002
|
|
117605
|
-
`);
|
|
117606
|
-
}
|
|
118211
|
+
);
|
|
117607
118212
|
}
|
|
117608
118213
|
async function runAdKeywordStatus(opts) {
|
|
117609
118214
|
opts = withResolvedAdAccount(opts);
|
|
@@ -117628,6 +118233,20 @@ async function runAdKeywordStatus(opts) {
|
|
|
117628
118233
|
`);
|
|
117629
118234
|
process.exit(1);
|
|
117630
118235
|
}
|
|
118236
|
+
const params = new URLSearchParams();
|
|
118237
|
+
params.set("startDate", toGoogleDate(opts.startDate, -30));
|
|
118238
|
+
params.set("endDate", toGoogleDate(opts.endDate, 0));
|
|
118239
|
+
params.set("newest", "true");
|
|
118240
|
+
const listUrl = `${googleApiUrl}/keywordmanagement/v2/list/${opts.account}?${params}`;
|
|
118241
|
+
let fresh;
|
|
118242
|
+
try {
|
|
118243
|
+
fresh = await findItemInList(listUrl, config, opts.id, opts.verbose);
|
|
118244
|
+
} catch {
|
|
118245
|
+
fresh = void 0;
|
|
118246
|
+
}
|
|
118247
|
+
const actual = fresh ? String(fresh["userStatusV2"] ?? fresh["status"] ?? fresh["statusV2"] ?? "").trim() : void 0;
|
|
118248
|
+
const lines = [receiptLine("\u72B6\u6001", opts.status, actual || void 0)];
|
|
118249
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
117631
118250
|
console.log(`
|
|
117632
118251
|
\u2705 \u5173\u952E\u8BCD ${opts.id} \u5DF2\u8BBE\u7F6E\u4E3A ${opts.status}
|
|
117633
118252
|
`);
|
|
@@ -117658,7 +118277,12 @@ async function runAdNegativeKeywordEdit(opts) {
|
|
|
117658
118277
|
} else if (opts.text !== void 0) {
|
|
117659
118278
|
body["keywordText"] = [opts.text];
|
|
117660
118279
|
}
|
|
118280
|
+
const submittedText = opts.matchType !== void 0 ? formatKeywordTextForMatchType(
|
|
118281
|
+
opts.text !== void 0 ? opts.text : firstKeywordTextFromRecord(keyword),
|
|
118282
|
+
opts.matchType
|
|
118283
|
+
) : opts.text !== void 0 ? opts.text : firstKeywordTextFromRecord(keyword);
|
|
117661
118284
|
const url = `${googleApiUrl}/negativekeywordmanagement/negativekeyword/${opts.account}/${opts.id}`;
|
|
118285
|
+
let currentId = opts.id;
|
|
117662
118286
|
try {
|
|
117663
118287
|
const raw = await apiFetch2(
|
|
117664
118288
|
url,
|
|
@@ -117669,6 +118293,7 @@ async function runAdNegativeKeywordEdit(opts) {
|
|
|
117669
118293
|
const returned = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : Array.isArray(raw) && raw[0] && typeof raw[0] === "object" ? raw[0] : null;
|
|
117670
118294
|
const returnedId = returned && typeof returned["id"] === "string" ? returned["id"] : void 0;
|
|
117671
118295
|
if (returnedId && returnedId !== opts.id) {
|
|
118296
|
+
currentId = returnedId;
|
|
117672
118297
|
console.log(
|
|
117673
118298
|
`
|
|
117674
118299
|
\u2139\uFE0F \u7F51\u5173\u8FD4\u56DE\u7684\u5426\u5B9A\u5173\u952E\u8BCD id \u5DF2\u53D8\u66F4\u4E3A ${returnedId}\uFF08\u8BF7\u6C42\u65F6 id \u4E3A ${opts.id}\uFF09\uFF0C\u540E\u7EED\u67E5\u8BE2/\u5220\u9664\u8BF7\u4F7F\u7528\u65B0 id\u3002
|
|
@@ -117681,15 +118306,40 @@ async function runAdNegativeKeywordEdit(opts) {
|
|
|
117681
118306
|
`);
|
|
117682
118307
|
process.exit(1);
|
|
117683
118308
|
}
|
|
118309
|
+
const readUrl2 = negativeKeywordSlimListUrl(googleApiUrl, opts.account, { newest: true });
|
|
118310
|
+
let fresh;
|
|
118311
|
+
try {
|
|
118312
|
+
fresh = await findItemInList(
|
|
118313
|
+
readUrl2,
|
|
118314
|
+
config,
|
|
118315
|
+
currentId,
|
|
118316
|
+
opts.verbose
|
|
118317
|
+
);
|
|
118318
|
+
} catch {
|
|
118319
|
+
fresh = void 0;
|
|
118320
|
+
}
|
|
118321
|
+
const lines = [];
|
|
118322
|
+
if (opts.text !== void 0 || opts.matchType !== void 0) {
|
|
118323
|
+
const actualText = fresh ? firstKeywordTextFromRecord(fresh) : "";
|
|
118324
|
+
lines.push(receiptLine("\u8BCD\u9762", submittedText, actualText || void 0));
|
|
118325
|
+
}
|
|
118326
|
+
if (opts.matchType !== void 0) {
|
|
118327
|
+
const actualMatch = fresh ? String(fresh["matchTypeV2"] ?? fresh["matchType"] ?? "").trim() : "";
|
|
118328
|
+
lines.push(receiptLine("\u5339\u914D\u7C7B\u578B", opts.matchType, actualMatch || void 0));
|
|
118329
|
+
}
|
|
118330
|
+
if (lines.length === 0) {
|
|
118331
|
+
lines.push(receiptLine("\u5426\u5B9A\u5173\u952E\u8BCD", currentId, fresh ? currentId : void 0));
|
|
118332
|
+
}
|
|
118333
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
117684
118334
|
console.log(`
|
|
117685
|
-
\u2705 \u5426\u5B9A\u5173\u952E\u8BCD ${
|
|
118335
|
+
\u2705 \u5426\u5B9A\u5173\u952E\u8BCD ${currentId} \u5DF2\u66F4\u65B0
|
|
117686
118336
|
`);
|
|
117687
118337
|
}
|
|
117688
118338
|
async function runAdNegativeKeywordDelete(opts) {
|
|
117689
118339
|
opts = withResolvedAdAccount(opts);
|
|
117690
118340
|
const config = loadConfig(opts.token);
|
|
117691
118341
|
const googleApiUrl = requireGoogleApi(config);
|
|
117692
|
-
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account);
|
|
118342
|
+
const listUrl = negativeKeywordSlimListUrl(googleApiUrl, opts.account, { newest: true });
|
|
117693
118343
|
let keyword;
|
|
117694
118344
|
try {
|
|
117695
118345
|
keyword = await findItemInList(listUrl, config, opts.id, opts.verbose);
|
|
@@ -117711,6 +118361,7 @@ async function runAdNegativeKeywordDelete(opts) {
|
|
|
117711
118361
|
`);
|
|
117712
118362
|
process.exit(1);
|
|
117713
118363
|
}
|
|
118364
|
+
await printIdGone("\u5426\u5B9A\u5173\u952E\u8BCD", listUrl, config, opts.id, opts.verbose);
|
|
117714
118365
|
console.log(`
|
|
117715
118366
|
\u2705 \u5426\u5B9A\u5173\u952E\u8BCD ${opts.id} \u5DF2\u5220\u9664
|
|
117716
118367
|
`);
|
|
@@ -119406,9 +120057,13 @@ function unwrapCampaign(res) {
|
|
|
119406
120057
|
}
|
|
119407
120058
|
return res;
|
|
119408
120059
|
}
|
|
120060
|
+
function campaignReadUrl(detailUrl) {
|
|
120061
|
+
if (/[?&]newest=/.test(detailUrl)) return detailUrl;
|
|
120062
|
+
return `${detailUrl}${detailUrl.includes("?") ? "&" : "?"}newest=true`;
|
|
120063
|
+
}
|
|
119409
120064
|
async function fetchCampaignRecord(detailUrl, config, verbose) {
|
|
119410
120065
|
const res = await apiFetch2(
|
|
119411
|
-
detailUrl,
|
|
120066
|
+
campaignReadUrl(detailUrl),
|
|
119412
120067
|
config,
|
|
119413
120068
|
{},
|
|
119414
120069
|
verbose
|
|
@@ -119465,6 +120120,7 @@ async function reportFailedCampaignPut(opts) {
|
|
|
119465
120120
|
});
|
|
119466
120121
|
}
|
|
119467
120122
|
async function reportCampaignWrite(opts) {
|
|
120123
|
+
printWriteReceipt(opts.verification, receiptLinesFromFieldChecks(opts.checks));
|
|
119468
120124
|
const nextQuery = `siluzan-tso ad campaigns -a ${opts.account} --json-out ./snap`;
|
|
119469
120125
|
const unmatched = describeUnmatchedChecks(opts.checks);
|
|
119470
120126
|
const text5 = opts.verification === "verified" ? opts.detail : unmatched || opts.detail;
|
|
@@ -119510,7 +120166,7 @@ async function runAdCampaignStatus(opts) {
|
|
|
119510
120166
|
let campaign;
|
|
119511
120167
|
try {
|
|
119512
120168
|
const res = await apiFetch2(
|
|
119513
|
-
detailUrl,
|
|
120169
|
+
campaignReadUrl(detailUrl),
|
|
119514
120170
|
config,
|
|
119515
120171
|
{},
|
|
119516
120172
|
opts.verbose
|
|
@@ -119577,7 +120233,7 @@ async function runAdCampaignDelete(opts) {
|
|
|
119577
120233
|
let campaign;
|
|
119578
120234
|
try {
|
|
119579
120235
|
const res = await apiFetch2(
|
|
119580
|
-
detailUrl,
|
|
120236
|
+
campaignReadUrl(detailUrl),
|
|
119581
120237
|
config,
|
|
119582
120238
|
{},
|
|
119583
120239
|
opts.verbose
|
|
@@ -119612,9 +120268,32 @@ async function runAdCampaignDelete(opts) {
|
|
|
119612
120268
|
`);
|
|
119613
120269
|
process.exit(1);
|
|
119614
120270
|
}
|
|
119615
|
-
|
|
120271
|
+
let removed = false;
|
|
120272
|
+
let stillStatus;
|
|
120273
|
+
try {
|
|
120274
|
+
const again = await apiFetch2(
|
|
120275
|
+
campaignReadUrl(detailUrl),
|
|
120276
|
+
config,
|
|
120277
|
+
{},
|
|
120278
|
+
opts.verbose
|
|
120279
|
+
);
|
|
120280
|
+
const row = again.data ?? again;
|
|
120281
|
+
const status = String(row["statusV2"] ?? row["status"] ?? "");
|
|
120282
|
+
removed = /removed/i.test(status);
|
|
120283
|
+
if (!removed) stillStatus = status || "\u4ECD\u5728";
|
|
120284
|
+
} catch (err) {
|
|
120285
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
120286
|
+
removed = /404|未找到|not found|不存在/i.test(message);
|
|
120287
|
+
}
|
|
120288
|
+
const verification = removed ? "verified" : stillStatus ? "partial" : "unknown";
|
|
120289
|
+
printWriteReceipt(verification, [
|
|
120290
|
+
receiptLine("\u7CFB\u5217", "\u5DF2\u5220\u9664", removed ? "\u5DF2\u5220\u9664" : stillStatus)
|
|
120291
|
+
]);
|
|
120292
|
+
if (verification === "verified") {
|
|
120293
|
+
console.log(`
|
|
119616
120294
|
\u2705 \u5E7F\u544A\u7CFB\u5217 ${opts.id} \u5DF2\u5220\u9664
|
|
119617
120295
|
`);
|
|
120296
|
+
}
|
|
119618
120297
|
}
|
|
119619
120298
|
async function runAdCampaignCreate(opts) {
|
|
119620
120299
|
const cfg = loadCampaignCreateConfig(opts.configFile);
|
|
@@ -119726,6 +120405,9 @@ async function runAdCampaignCreate(opts) {
|
|
|
119726
120405
|
nextCommand: taskId != null ? `siluzan-tso ad batch get --id ${String(taskId)} --config-file ${opts.configFile} --json-out ./snap-campaign` : null,
|
|
119727
120406
|
agentHint: "\u4EFB\u52A1\u5DF2\u63D0\u4EA4\uFF1A\u6BCF 5s \u8F6E\u8BE2 nextCommand\uFF08ad batch get\uFF0C\u987B\u5E26\u540C\u4E00 --config-file \u4E0E --json-out\uFF09\uFF1B\u8BFB\u843D\u76D8 agentWorkflow\uFF1ACreating \u7EE7\u7EED\u8F6E\u8BE2\uFF1BSuccessfully/HasFailed \u6267\u884C nextCommand \u7684 batch diff\uFF08\u542B\u6295\u653E\u56FD\u5BB6\uFF09\uFF1BFailed \u53EA\u770B reason/errors\u3002"
|
|
119728
120407
|
};
|
|
120408
|
+
printWriteReceipt("submitted", [
|
|
120409
|
+
receiptLine("\u6279\u91CF\u4EFB\u52A1", String(taskId), String(taskId))
|
|
120410
|
+
]);
|
|
119729
120411
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
119730
120412
|
section: `ad-campaign-create-async-${cfg.account}`,
|
|
119731
120413
|
commandLabel: "ad campaign-create",
|
|
@@ -119884,7 +120566,7 @@ async function runAdCampaignEdit(opts) {
|
|
|
119884
120566
|
let campaign;
|
|
119885
120567
|
try {
|
|
119886
120568
|
const res = await apiFetch2(
|
|
119887
|
-
detailUrl,
|
|
120569
|
+
campaignReadUrl(detailUrl),
|
|
119888
120570
|
config,
|
|
119889
120571
|
{},
|
|
119890
120572
|
opts.verbose
|
|
@@ -120012,6 +120694,21 @@ init_cli_json_snapshot();
|
|
|
120012
120694
|
init_strip_legacy_google_fields();
|
|
120013
120695
|
init_cli_table();
|
|
120014
120696
|
init_shared();
|
|
120697
|
+
function normalizeAdGroupStatus(raw) {
|
|
120698
|
+
const s = String(raw ?? "").trim();
|
|
120699
|
+
if (/^enabled$/i.test(s)) return "Enabled";
|
|
120700
|
+
if (/^paused$/i.test(s)) return "Paused";
|
|
120701
|
+
if (/^removed$/i.test(s)) return "Removed";
|
|
120702
|
+
return s;
|
|
120703
|
+
}
|
|
120704
|
+
async function readAdGroupFresh(googleApiUrl, config, account, id, verbose) {
|
|
120705
|
+
const listUrl = adgroupListUrl(googleApiUrl, account, void 0, void 0, true);
|
|
120706
|
+
try {
|
|
120707
|
+
return await findItemInList(listUrl, config, id, verbose);
|
|
120708
|
+
} catch {
|
|
120709
|
+
return void 0;
|
|
120710
|
+
}
|
|
120711
|
+
}
|
|
120015
120712
|
async function runAdGroups(opts) {
|
|
120016
120713
|
opts = withResolvedAdAccount(opts);
|
|
120017
120714
|
const config = loadConfig(opts.token);
|
|
@@ -120134,6 +120831,28 @@ async function runAdGroupCreate(opts) {
|
|
|
120134
120831
|
}
|
|
120135
120832
|
const normalized = adGroupRowToYuan(response);
|
|
120136
120833
|
const adgroupId = normalized["id"] ?? null;
|
|
120834
|
+
const expectStatus = normalizeAdGroupStatus(opts.status ?? "ENABLED");
|
|
120835
|
+
let fresh;
|
|
120836
|
+
if (adgroupId) {
|
|
120837
|
+
fresh = await readAdGroupFresh(googleApiUrl, config, opts.account, adgroupId, opts.verbose);
|
|
120838
|
+
}
|
|
120839
|
+
const lines = [
|
|
120840
|
+
receiptLine("\u540D\u79F0", opts.name, fresh?.["name"]),
|
|
120841
|
+
receiptLine(
|
|
120842
|
+
"\u72B6\u6001",
|
|
120843
|
+
expectStatus,
|
|
120844
|
+
fresh ? normalizeAdGroupStatus(fresh["statusV2"] ?? fresh["status"]) : void 0
|
|
120845
|
+
),
|
|
120846
|
+
receiptLine(
|
|
120847
|
+
"CPC\u4E0A\u9650",
|
|
120848
|
+
yuanLabel(opts.maxCpc),
|
|
120849
|
+
fresh ? (() => {
|
|
120850
|
+
const cents = fresh["maxCPCAmount"] ?? fresh["maxCpc"];
|
|
120851
|
+
return typeof cents === "number" ? yuanLabel(cents / 100) : void 0;
|
|
120852
|
+
})() : void 0
|
|
120853
|
+
)
|
|
120854
|
+
];
|
|
120855
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
120137
120856
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
120138
120857
|
section: `ad-adgroup-create-${opts.account}`,
|
|
120139
120858
|
commandLabel: "ad adgroup-create",
|
|
@@ -120166,6 +120885,15 @@ async function runAdGroupStatus(opts) {
|
|
|
120166
120885
|
opts.verbose,
|
|
120167
120886
|
"\u72B6\u6001\u66F4\u65B0\u5931\u8D25"
|
|
120168
120887
|
);
|
|
120888
|
+
const fresh = await readAdGroupFresh(googleApiUrl, config, opts.account, opts.id, opts.verbose);
|
|
120889
|
+
const lines = [
|
|
120890
|
+
receiptLine(
|
|
120891
|
+
"\u72B6\u6001",
|
|
120892
|
+
opts.status,
|
|
120893
|
+
fresh ? normalizeAdGroupStatus(fresh["statusV2"] ?? fresh["status"]) : void 0
|
|
120894
|
+
)
|
|
120895
|
+
];
|
|
120896
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
120169
120897
|
console.log(`
|
|
120170
120898
|
\u2705 \u5E7F\u544A\u7EC4 ${opts.id} \u5DF2\u8BBE\u7F6E\u4E3A ${opts.status}
|
|
120171
120899
|
`);
|
|
@@ -120193,6 +120921,19 @@ async function runAdGroupDelete(opts) {
|
|
|
120193
120921
|
`);
|
|
120194
120922
|
process.exit(1);
|
|
120195
120923
|
}
|
|
120924
|
+
const freshListUrl = adgroupListUrl(googleApiUrl, opts.account, opts.startDate, opts.endDate, true);
|
|
120925
|
+
let gone = false;
|
|
120926
|
+
let still = false;
|
|
120927
|
+
try {
|
|
120928
|
+
await findItemInList(freshListUrl, config, opts.id, opts.verbose);
|
|
120929
|
+
still = true;
|
|
120930
|
+
} catch (err) {
|
|
120931
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
120932
|
+
gone = message.includes("\u672A\u5728\u5217\u8868\u4E2D\u627E\u5230");
|
|
120933
|
+
}
|
|
120934
|
+
printWriteReceipt(gone ? "verified" : still ? "partial" : "unknown", [
|
|
120935
|
+
receiptLine("\u5E7F\u544A\u7EC4", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : still ? "\u4ECD\u5728" : void 0)
|
|
120936
|
+
]);
|
|
120196
120937
|
console.log(`
|
|
120197
120938
|
\u2705 \u5E7F\u544A\u7EC4 ${opts.id} \u5DF2\u5220\u9664
|
|
120198
120939
|
`);
|
|
@@ -120210,6 +120951,9 @@ async function runAdGroupRename(opts) {
|
|
|
120210
120951
|
opts.verbose,
|
|
120211
120952
|
"\u6539\u540D\u5931\u8D25"
|
|
120212
120953
|
);
|
|
120954
|
+
const fresh = await readAdGroupFresh(googleApiUrl, config, opts.account, opts.id, opts.verbose);
|
|
120955
|
+
const lines = [receiptLine("\u540D\u79F0", opts.name, fresh?.["name"])];
|
|
120956
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
120213
120957
|
console.log(`
|
|
120214
120958
|
\u2705 \u5E7F\u544A\u7EC4 ${opts.id} \u5DF2\u6539\u540D\u4E3A\u300C${opts.name}\u300D
|
|
120215
120959
|
`);
|
|
@@ -120246,6 +120990,20 @@ async function runAdGroupEdit(opts) {
|
|
|
120246
120990
|
opts.verbose,
|
|
120247
120991
|
"\u7F16\u8F91\u5E7F\u544A\u7EC4\u5931\u8D25"
|
|
120248
120992
|
);
|
|
120993
|
+
const fresh = await readAdGroupFresh(googleApiUrl, config, opts.account, opts.id, opts.verbose);
|
|
120994
|
+
const lines = [];
|
|
120995
|
+
if (hasName) lines.push(receiptLine("\u540D\u79F0", opts.name.trim(), fresh?.["name"]));
|
|
120996
|
+
if (hasMax) {
|
|
120997
|
+
const cents = fresh?.["maxCPCAmount"] ?? fresh?.["maxCpc"];
|
|
120998
|
+
const yuan = typeof cents === "number" ? cents / 100 : void 0;
|
|
120999
|
+
lines.push(receiptLine("CPC\u4E0A\u9650", yuanLabel(opts.maxCPCAmount), yuan == null ? void 0 : yuanLabel(yuan)));
|
|
121000
|
+
}
|
|
121001
|
+
if (hasTcpa) {
|
|
121002
|
+
const cents = fresh?.["targetCpaAmount"] ?? fresh?.["targetCpa"];
|
|
121003
|
+
const yuan = typeof cents === "number" ? cents / 100 : void 0;
|
|
121004
|
+
lines.push(receiptLine("\u76EE\u6807CPA", yuanLabel(opts.targetCpaAmount), yuan == null ? void 0 : yuanLabel(yuan)));
|
|
121005
|
+
}
|
|
121006
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
120249
121007
|
console.log(`
|
|
120250
121008
|
\u2705 \u5E7F\u544A\u7EC4 ${opts.id} \u5DF2\u66F4\u65B0
|
|
120251
121009
|
`);
|
|
@@ -120471,6 +121229,44 @@ async function runAdCreate(opts) {
|
|
|
120471
121229
|
process.exit(1);
|
|
120472
121230
|
}
|
|
120473
121231
|
const adId = response["id"] ?? null;
|
|
121232
|
+
const readParams = new URLSearchParams();
|
|
121233
|
+
readParams.set("startDate", toGoogleDate(void 0, -30));
|
|
121234
|
+
readParams.set("endDate", toGoogleDate(void 0, 0));
|
|
121235
|
+
readParams.set("newest", "true");
|
|
121236
|
+
const listUrl = `${googleApiUrl}/admanagement/v2/list/${opts.account}?${readParams}`;
|
|
121237
|
+
let fresh;
|
|
121238
|
+
try {
|
|
121239
|
+
if (adId) {
|
|
121240
|
+
fresh = await findItemInList(listUrl, config, String(adId), opts.verbose);
|
|
121241
|
+
} else {
|
|
121242
|
+
const listed = await apiFetch2(listUrl, config, {}, opts.verbose);
|
|
121243
|
+
const rows = listed.data ?? [];
|
|
121244
|
+
fresh = rows.find((row) => {
|
|
121245
|
+
const groupId = String(row["adGroupId"] ?? row["AdGroupId"] ?? "");
|
|
121246
|
+
const url2 = String(row["finalUrl"] ?? row["FinalUrl"] ?? row["finalURL"] ?? "");
|
|
121247
|
+
return groupId === opts.adgroupId && url2 === opts.finalUrl;
|
|
121248
|
+
});
|
|
121249
|
+
}
|
|
121250
|
+
} catch {
|
|
121251
|
+
fresh = void 0;
|
|
121252
|
+
}
|
|
121253
|
+
const lines = [];
|
|
121254
|
+
if (adId) {
|
|
121255
|
+
lines.push(
|
|
121256
|
+
receiptLine(
|
|
121257
|
+
"\u5E7F\u544A",
|
|
121258
|
+
String(adId),
|
|
121259
|
+
fresh ? String(fresh["id"] ?? fresh["Id"] ?? "") || void 0 : void 0
|
|
121260
|
+
)
|
|
121261
|
+
);
|
|
121262
|
+
} else {
|
|
121263
|
+
lines.push(receiptLine("\u5E7F\u544A", "\u5728\u5217\u8868\u4E2D", fresh ? "\u5728\u5217\u8868\u4E2D" : void 0));
|
|
121264
|
+
}
|
|
121265
|
+
const readFinal = fresh?.["finalUrl"] ?? fresh?.["FinalUrl"] ?? fresh?.["finalURL"];
|
|
121266
|
+
if (opts.finalUrl) {
|
|
121267
|
+
lines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, fresh ? readFinal : void 0));
|
|
121268
|
+
}
|
|
121269
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
120474
121270
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
120475
121271
|
section: `ad-create-${opts.account}`,
|
|
120476
121272
|
commandLabel: "ad ad-create",
|
|
@@ -120509,10 +121305,42 @@ async function runAdStatus(opts) {
|
|
|
120509
121305
|
`);
|
|
120510
121306
|
process.exit(1);
|
|
120511
121307
|
}
|
|
121308
|
+
const readParams = new URLSearchParams();
|
|
121309
|
+
readParams.set("startDate", toGoogleDate(void 0, -30));
|
|
121310
|
+
readParams.set("endDate", toGoogleDate(void 0, 0));
|
|
121311
|
+
readParams.set("newest", "true");
|
|
121312
|
+
let fresh;
|
|
121313
|
+
try {
|
|
121314
|
+
fresh = await findItemInList(
|
|
121315
|
+
`${googleApiUrl}/admanagement/v2/list/${opts.account}?${readParams}`,
|
|
121316
|
+
config,
|
|
121317
|
+
opts.id,
|
|
121318
|
+
opts.verbose
|
|
121319
|
+
);
|
|
121320
|
+
} catch {
|
|
121321
|
+
fresh = void 0;
|
|
121322
|
+
}
|
|
121323
|
+
const lines = [
|
|
121324
|
+
receiptLine("\u72B6\u6001", opts.status, readAdStatusLabel(fresh))
|
|
121325
|
+
];
|
|
121326
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
120512
121327
|
console.log(`
|
|
120513
121328
|
\u2705 \u5E7F\u544A ${opts.id} \u5DF2\u8BBE\u7F6E\u4E3A ${opts.status}
|
|
120514
121329
|
`);
|
|
120515
121330
|
}
|
|
121331
|
+
function readAdStatusLabel(fresh) {
|
|
121332
|
+
if (!fresh) return void 0;
|
|
121333
|
+
const v2 = fresh["statusV2"] ?? fresh["userStatusV2"];
|
|
121334
|
+
if (typeof v2 === "string" && v2.trim()) return v2.trim();
|
|
121335
|
+
const raw = fresh["status"];
|
|
121336
|
+
if (typeof raw === "string" && raw.trim()) return raw.trim();
|
|
121337
|
+
if (typeof raw === "number") {
|
|
121338
|
+
if (raw === 2) return "Enabled";
|
|
121339
|
+
if (raw === 3) return "Paused";
|
|
121340
|
+
if (raw === 4) return "Removed";
|
|
121341
|
+
}
|
|
121342
|
+
return raw == null ? void 0 : String(raw);
|
|
121343
|
+
}
|
|
120516
121344
|
async function runAdDelete(opts) {
|
|
120517
121345
|
opts = withResolvedAdAccount(opts);
|
|
120518
121346
|
const config = loadConfig(opts.token);
|
|
@@ -120520,6 +121348,7 @@ async function runAdDelete(opts) {
|
|
|
120520
121348
|
const params = new URLSearchParams();
|
|
120521
121349
|
params.set("startDate", toGoogleDate(opts.startDate, -30));
|
|
120522
121350
|
params.set("endDate", toGoogleDate(opts.endDate, 0));
|
|
121351
|
+
params.set("newest", "true");
|
|
120523
121352
|
const listUrl = `${googleApiUrl}/admanagement/v2/list/${opts.account}?${params}`;
|
|
120524
121353
|
let ad;
|
|
120525
121354
|
try {
|
|
@@ -120539,6 +121368,18 @@ async function runAdDelete(opts) {
|
|
|
120539
121368
|
`);
|
|
120540
121369
|
process.exit(1);
|
|
120541
121370
|
}
|
|
121371
|
+
let gone = false;
|
|
121372
|
+
let still = false;
|
|
121373
|
+
try {
|
|
121374
|
+
await findItemInList(listUrl, config, opts.id, opts.verbose);
|
|
121375
|
+
still = true;
|
|
121376
|
+
} catch (err) {
|
|
121377
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
121378
|
+
gone = message.includes("\u672A\u5728\u5217\u8868\u4E2D\u627E\u5230");
|
|
121379
|
+
}
|
|
121380
|
+
printWriteReceipt(gone ? "verified" : still ? "partial" : "unknown", [
|
|
121381
|
+
receiptLine("\u5E7F\u544A", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : still ? "\u4ECD\u5728" : void 0)
|
|
121382
|
+
]);
|
|
120542
121383
|
console.log(`
|
|
120543
121384
|
\u2705 \u5E7F\u544A ${opts.id} \u5DF2\u5220\u9664
|
|
120544
121385
|
`);
|
|
@@ -120588,6 +121429,31 @@ async function runAdEdit(opts) {
|
|
|
120588
121429
|
`);
|
|
120589
121430
|
process.exit(1);
|
|
120590
121431
|
}
|
|
121432
|
+
const readParams = new URLSearchParams();
|
|
121433
|
+
readParams.set("startDate", toGoogleDate(void 0, -30));
|
|
121434
|
+
readParams.set("endDate", toGoogleDate(void 0, 0));
|
|
121435
|
+
readParams.set("newest", "true");
|
|
121436
|
+
let fresh;
|
|
121437
|
+
try {
|
|
121438
|
+
fresh = await findItemInList(
|
|
121439
|
+
`${googleApiUrl}/admanagement/v2/list/${opts.account}?${readParams}`,
|
|
121440
|
+
config,
|
|
121441
|
+
opts.id,
|
|
121442
|
+
opts.verbose
|
|
121443
|
+
);
|
|
121444
|
+
} catch {
|
|
121445
|
+
fresh = void 0;
|
|
121446
|
+
}
|
|
121447
|
+
const lines = [];
|
|
121448
|
+
if (opts.finalUrl !== void 0) {
|
|
121449
|
+
lines.push(receiptLine("\u843D\u5730\u9875", opts.finalUrl, fresh?.["finalUrl"] ?? fresh?.["Finalurl"] ?? fresh?.["FinalUrl"]));
|
|
121450
|
+
}
|
|
121451
|
+
if (opts.status !== void 0) {
|
|
121452
|
+
lines.push(receiptLine("\u72B6\u6001", opts.status, readAdStatusLabel(fresh)));
|
|
121453
|
+
}
|
|
121454
|
+
if (lines.length > 0) {
|
|
121455
|
+
printWriteReceipt(fresh ? judgeReceipt(lines) : "unknown", lines);
|
|
121456
|
+
}
|
|
120591
121457
|
console.log(`
|
|
120592
121458
|
\u2705 \u5E7F\u544A ${opts.id} \u5DF2\u66F4\u65B0
|
|
120593
121459
|
`);
|
|
@@ -120786,6 +121652,15 @@ async function runAdExclusionsAdd(opts) {
|
|
|
120786
121652
|
process.exit(1);
|
|
120787
121653
|
}
|
|
120788
121654
|
const payload = { account: opts.account, request: body, response: created };
|
|
121655
|
+
let listed;
|
|
121656
|
+
try {
|
|
121657
|
+
listed = await apiFetch2(url, config, {}, opts.verbose);
|
|
121658
|
+
} catch {
|
|
121659
|
+
listed = void 0;
|
|
121660
|
+
}
|
|
121661
|
+
const needle = Object.values(body).map(String).find((value) => value && value !== body.type) ?? body.type;
|
|
121662
|
+
const added = receiptFromNeedles([{ label: "\u6392\u9664", value: needle }], listed);
|
|
121663
|
+
printWriteReceipt(added.verification, added.lines);
|
|
120789
121664
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
120790
121665
|
section: "ad-exclusions-add",
|
|
120791
121666
|
commandLabel: "ad exclusions add",
|
|
@@ -120816,6 +121691,14 @@ async function runAdExclusionsRemove(opts) {
|
|
|
120816
121691
|
`);
|
|
120817
121692
|
process.exit(1);
|
|
120818
121693
|
}
|
|
121694
|
+
let listed;
|
|
121695
|
+
try {
|
|
121696
|
+
listed = await apiFetch2(exclusionsUrl(requireGoogleApi(config), opts.account), config, {}, opts.verbose);
|
|
121697
|
+
} catch {
|
|
121698
|
+
listed = void 0;
|
|
121699
|
+
}
|
|
121700
|
+
const gone = receiptForAbsence("\u6392\u9664", opts.criterionId.trim(), listed);
|
|
121701
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
120819
121702
|
console.log(`
|
|
120820
121703
|
\u2705 \u5DF2\u5220\u9664\u5185\u5BB9\u6392\u9664 ${opts.criterionId}
|
|
120821
121704
|
`);
|
|
@@ -121151,10 +122034,20 @@ async function runAdNegativeListAttach(opts) {
|
|
|
121151
122034
|
}
|
|
121152
122035
|
const item = response && typeof response === "object" ? response : {};
|
|
121153
122036
|
const already = item["alreadyAttached"] ?? item["AlreadyAttached"];
|
|
121154
|
-
const sharedSetId = item["sharedSetId"] ?? item["SharedSetId"] ?? "";
|
|
122037
|
+
const sharedSetId = String(item["sharedSetId"] ?? item["SharedSetId"] ?? "").trim();
|
|
122038
|
+
if (sharedSetId) {
|
|
122039
|
+
printWriteReceipt("verified", [
|
|
122040
|
+
receiptLine("sharedSetId", sharedSetId, sharedSetId),
|
|
122041
|
+
receiptLine("\u6302\u63A5", already ? "\u5DF2\u6302\u63A5" : "\u65B0\u6302\u63A5", already ? "\u5DF2\u6302\u63A5" : "\u65B0\u6302\u63A5")
|
|
122042
|
+
]);
|
|
122043
|
+
} else {
|
|
122044
|
+
printWriteReceipt(already ? "unknown" : "partial", [
|
|
122045
|
+
receiptLine("sharedSetId", "\u975E\u7A7A", void 0)
|
|
122046
|
+
]);
|
|
122047
|
+
}
|
|
121155
122048
|
console.log(
|
|
121156
122049
|
`
|
|
121157
|
-
\u2705 \u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u5DF2\u6302\u63A5 sharedSetId=${
|
|
122050
|
+
\u2705 \u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u5DF2\u6302\u63A5 sharedSetId=${sharedSetId}${already ? "\uFF08\u672C\u6765\u5C31\u6302\u7740\uFF09" : ""}
|
|
121158
122051
|
`
|
|
121159
122052
|
);
|
|
121160
122053
|
}
|
|
@@ -121342,6 +122235,17 @@ async function runAdPmaxBrandsAdd(opts) {
|
|
|
121342
122235
|
} catch (err) {
|
|
121343
122236
|
fail(err, "\u6DFB\u52A0\u54C1\u724C\u5931\u8D25");
|
|
121344
122237
|
}
|
|
122238
|
+
let listed;
|
|
122239
|
+
try {
|
|
122240
|
+
listed = await apiFetch2(url, config, {}, opts.verbose);
|
|
122241
|
+
} catch {
|
|
122242
|
+
listed = void 0;
|
|
122243
|
+
}
|
|
122244
|
+
const present = listed === void 0 ? void 0 : payloadHasExact(listed, entityId);
|
|
122245
|
+
const lines = [
|
|
122246
|
+
receiptLine("\u54C1\u724C", entityId, present === void 0 ? void 0 : present ? entityId : "\u672A\u627E\u5230")
|
|
122247
|
+
];
|
|
122248
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
121345
122249
|
console.log(`
|
|
121346
122250
|
\u2705 \u5DF2\u628A\u54C1\u724C ${entityId} \u5199\u5165 PMax \u54C1\u724C\u5217\u8868
|
|
121347
122251
|
`);
|
|
@@ -121362,6 +122266,7 @@ async function runAdPmaxBrandsAttach(opts) {
|
|
|
121362
122266
|
} catch (err) {
|
|
121363
122267
|
fail(err, "\u6302\u63A5\u54C1\u724C\u5217\u8868\u5931\u8D25");
|
|
121364
122268
|
}
|
|
122269
|
+
printWriteReceipt("submitted", [receiptLine("\u54C1\u724C\u6302\u63A5", campaignId, campaignId)]);
|
|
121365
122270
|
console.log(`
|
|
121366
122271
|
\u2705 \u5DF2\u628A\u54C1\u724C\u5217\u8868\u6302\u5230\u7CFB\u5217 ${campaignId}\u3002\u5378\u4E0B\u7528 detach\uFF0C\u4E0D\u4F1A\u5220\u9664\u5217\u8868\u91CC\u7684\u54C1\u724C\u3002
|
|
121367
122272
|
`);
|
|
@@ -121382,6 +122287,7 @@ async function runAdPmaxBrandsDetach(opts) {
|
|
|
121382
122287
|
} catch (err) {
|
|
121383
122288
|
fail(err, "\u5378\u4E0B\u54C1\u724C\u5217\u8868\u5931\u8D25");
|
|
121384
122289
|
}
|
|
122290
|
+
printWriteReceipt("submitted", [receiptLine("\u54C1\u724C\u5378\u4E0B", criterionId, criterionId)]);
|
|
121385
122291
|
console.log(`
|
|
121386
122292
|
\u2705 \u5DF2\u4ECE\u7CFB\u5217 ${campaignId} \u5378\u4E0B\u54C1\u724C\u5217\u8868 ${criterionId}
|
|
121387
122293
|
`);
|
|
@@ -121444,6 +122350,22 @@ async function runAdPmaxNegativesAdd(opts) {
|
|
|
121444
122350
|
} catch (err) {
|
|
121445
122351
|
fail(err, "\u6DFB\u52A0 PMax \u5426\u8BCD\u5931\u8D25");
|
|
121446
122352
|
}
|
|
122353
|
+
let listed;
|
|
122354
|
+
try {
|
|
122355
|
+
listed = await apiFetch2(
|
|
122356
|
+
`${url}?campaignId=${campaignId}`,
|
|
122357
|
+
config,
|
|
122358
|
+
{},
|
|
122359
|
+
opts.verbose
|
|
122360
|
+
);
|
|
122361
|
+
} catch {
|
|
122362
|
+
listed = void 0;
|
|
122363
|
+
}
|
|
122364
|
+
const present = listed === void 0 ? void 0 : payloadHasExact(listed, text5);
|
|
122365
|
+
const lines = [
|
|
122366
|
+
receiptLine("\u5426\u8BCD", text5, present === void 0 ? void 0 : present ? text5 : "\u672A\u627E\u5230")
|
|
122367
|
+
];
|
|
122368
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
121447
122369
|
console.log(`
|
|
121448
122370
|
\u2705 \u5DF2\u4E3A\u7CFB\u5217 ${campaignId} \u6DFB\u52A0\u5426\u8BCD ${text5}
|
|
121449
122371
|
`);
|
|
@@ -121496,6 +122418,17 @@ async function runAdPmaxUrlsAdd(opts) {
|
|
|
121496
122418
|
} catch (err) {
|
|
121497
122419
|
fail(err, "\u6DFB\u52A0\u7F51\u5740\u6392\u9664\u5931\u8D25");
|
|
121498
122420
|
}
|
|
122421
|
+
let listed;
|
|
122422
|
+
try {
|
|
122423
|
+
listed = await apiFetch2(`${url}?campaignId=${campaignId}`, config, {}, opts.verbose);
|
|
122424
|
+
} catch {
|
|
122425
|
+
listed = void 0;
|
|
122426
|
+
}
|
|
122427
|
+
const present = listed === void 0 ? void 0 : payloadHasExact(listed, urlValue);
|
|
122428
|
+
const lines = [
|
|
122429
|
+
receiptLine("\u7F51\u5740\u6392\u9664", urlValue, present === void 0 ? void 0 : present ? urlValue : "\u672A\u627E\u5230")
|
|
122430
|
+
];
|
|
122431
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
121499
122432
|
console.log(`
|
|
121500
122433
|
\u2705 \u5DF2\u4E3A\u7CFB\u5217 ${campaignId} \u6392\u9664\u7F51\u5740 ${urlValue}
|
|
121501
122434
|
`);
|
|
@@ -121519,6 +122452,19 @@ async function removeCampaignCriterion(opts, path61, label2) {
|
|
|
121519
122452
|
} catch (err) {
|
|
121520
122453
|
fail(err, `\u5220\u9664${label2}\u5931\u8D25`);
|
|
121521
122454
|
}
|
|
122455
|
+
let listed;
|
|
122456
|
+
try {
|
|
122457
|
+
listed = await apiFetch2(
|
|
122458
|
+
`${base2}/campaignmanagement/accounts/${account}/${path61}?campaignId=${campaignId}`,
|
|
122459
|
+
config,
|
|
122460
|
+
{},
|
|
122461
|
+
opts.verbose
|
|
122462
|
+
);
|
|
122463
|
+
} catch {
|
|
122464
|
+
listed = void 0;
|
|
122465
|
+
}
|
|
122466
|
+
const gone = receiptForAbsence(label2, criterionId, listed);
|
|
122467
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
121522
122468
|
console.log(`
|
|
121523
122469
|
\u2705 \u5DF2\u5220\u9664${label2} ${criterionId}
|
|
121524
122470
|
`);
|
|
@@ -121675,6 +122621,17 @@ async function runAdIpExclusionsAdd(opts) {
|
|
|
121675
122621
|
} catch (err) {
|
|
121676
122622
|
fail2(err, "\u6DFB\u52A0 IP \u6392\u9664\u5931\u8D25");
|
|
121677
122623
|
}
|
|
122624
|
+
let listed;
|
|
122625
|
+
try {
|
|
122626
|
+
listed = await apiFetch2(url, config, {}, opts.verbose);
|
|
122627
|
+
} catch {
|
|
122628
|
+
listed = void 0;
|
|
122629
|
+
}
|
|
122630
|
+
const present = listed === void 0 ? void 0 : payloadHasExact(listed, ipAddress);
|
|
122631
|
+
const lines = [
|
|
122632
|
+
receiptLine("IP", ipAddress, present === void 0 ? void 0 : present ? ipAddress : "\u672A\u627E\u5230")
|
|
122633
|
+
];
|
|
122634
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
121678
122635
|
console.log(`
|
|
121679
122636
|
\u2705 \u5DF2\u6DFB\u52A0\u8D26\u6237\u7EA7 IP \u6392\u9664 ${ipAddress}
|
|
121680
122637
|
`);
|
|
@@ -121689,6 +122646,14 @@ async function runAdIpExclusionsRemove(opts) {
|
|
|
121689
122646
|
} catch (err) {
|
|
121690
122647
|
fail2(err, "\u5220\u9664 IP \u6392\u9664\u5931\u8D25");
|
|
121691
122648
|
}
|
|
122649
|
+
let listed;
|
|
122650
|
+
try {
|
|
122651
|
+
listed = await apiFetch2(`${base2}/campaignmanagement/accounts/${account}/ip-exclusions`, config, {}, opts.verbose);
|
|
122652
|
+
} catch {
|
|
122653
|
+
listed = void 0;
|
|
122654
|
+
}
|
|
122655
|
+
const gone = receiptForAbsence("IP", criterionId, listed);
|
|
122656
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
121692
122657
|
console.log(`
|
|
121693
122658
|
\u2705 \u5DF2\u5220\u9664\u8D26\u6237\u7EA7 IP \u6392\u9664 ${criterionId}
|
|
121694
122659
|
`);
|
|
@@ -121941,10 +122906,11 @@ function extensionRowsFromResponse(res) {
|
|
|
121941
122906
|
(row) => !!row && typeof row === "object" && row["sectionHeadMode"] !== true
|
|
121942
122907
|
);
|
|
121943
122908
|
}
|
|
121944
|
-
function accountExtensionListUrl(googleApiUrl, account, startDate, endDate) {
|
|
122909
|
+
function accountExtensionListUrl(googleApiUrl, account, startDate, endDate, newest = false) {
|
|
121945
122910
|
const params = new URLSearchParams();
|
|
121946
122911
|
params.set("startDate", toGoogleDate(startDate, -30));
|
|
121947
122912
|
params.set("endDate", toGoogleDate(endDate, 0));
|
|
122913
|
+
if (newest) params.set("newest", "true");
|
|
121948
122914
|
return `${googleApiUrl}/extensionmanagement/v2/list/${account}?${params}`;
|
|
121949
122915
|
}
|
|
121950
122916
|
function campaignExtensionListUrl(googleApiUrl, account, campaignId) {
|
|
@@ -121955,7 +122921,8 @@ async function fetchAccountExtensions(config, account, opts = {}) {
|
|
|
121955
122921
|
requireGoogleApi(config),
|
|
121956
122922
|
account,
|
|
121957
122923
|
opts.startDate,
|
|
121958
|
-
opts.endDate
|
|
122924
|
+
opts.endDate,
|
|
122925
|
+
opts.newest
|
|
121959
122926
|
);
|
|
121960
122927
|
return extensionRowsFromResponse(await apiFetch2(url, config, {}, opts.verbose));
|
|
121961
122928
|
}
|
|
@@ -121975,7 +122942,7 @@ async function fetchCampaignExtensions(config, account, campaignId, opts = {}) {
|
|
|
121975
122942
|
} catch (err) {
|
|
121976
122943
|
if (!isNotFound(err)) throw err;
|
|
121977
122944
|
}
|
|
121978
|
-
const rows = (await fetchAccountExtensions(config, account, opts)).filter(
|
|
122945
|
+
const rows = (await fetchAccountExtensions(config, account, { ...opts, newest: true })).filter(
|
|
121979
122946
|
(row) => String(row["campaignId"] ?? "") === cid
|
|
121980
122947
|
);
|
|
121981
122948
|
return { rows, source: "account-fallback" };
|
|
@@ -122121,6 +123088,23 @@ async function runAdExtensionCreate(opts) {
|
|
|
122121
123088
|
`);
|
|
122122
123089
|
process.exit(1);
|
|
122123
123090
|
}
|
|
123091
|
+
const resObj = response ?? {};
|
|
123092
|
+
const extId = resObj["id"];
|
|
123093
|
+
let present;
|
|
123094
|
+
if (extId) {
|
|
123095
|
+
try {
|
|
123096
|
+
const rows = await fetchAccountExtensions(config, opts.account, { verbose: opts.verbose });
|
|
123097
|
+
present = rows.some((row) => String(row["id"] ?? "") === extId);
|
|
123098
|
+
} catch {
|
|
123099
|
+
present = void 0;
|
|
123100
|
+
}
|
|
123101
|
+
const lines = [
|
|
123102
|
+
receiptLine("\u9644\u52A0\u4FE1\u606F", "\u5728\u5217\u8868\u4E2D", present === void 0 ? void 0 : present ? "\u5728\u5217\u8868\u4E2D" : "\u672A\u627E\u5230")
|
|
123103
|
+
];
|
|
123104
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
123105
|
+
} else {
|
|
123106
|
+
printWriteReceipt("submitted", [receiptLine("\u9644\u52A0\u4FE1\u606F", opts.type, "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
123107
|
+
}
|
|
122124
123108
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
122125
123109
|
section: `ad-extension-create-${opts.account}`,
|
|
122126
123110
|
commandLabel: "ad extension create",
|
|
@@ -122130,8 +123114,6 @@ async function runAdExtensionCreate(opts) {
|
|
|
122130
123114
|
})) {
|
|
122131
123115
|
return;
|
|
122132
123116
|
}
|
|
122133
|
-
const resObj = response ?? {};
|
|
122134
|
-
const extId = resObj["id"];
|
|
122135
123117
|
if (extId) {
|
|
122136
123118
|
console.log(`
|
|
122137
123119
|
\u2705 \u9644\u52A0\u4FE1\u606F\uFF08${opts.type}\uFF09\u5DF2\u521B\u5EFA\uFF08id: ${extId}\uFF09
|
|
@@ -122167,6 +123149,19 @@ async function runAdExtensionDelete(opts) {
|
|
|
122167
123149
|
`);
|
|
122168
123150
|
process.exit(1);
|
|
122169
123151
|
}
|
|
123152
|
+
let gone = false;
|
|
123153
|
+
let still = false;
|
|
123154
|
+
try {
|
|
123155
|
+
const rows = await fetchAccountExtensions(config, opts.account, { verbose: opts.verbose });
|
|
123156
|
+
still = rows.some((row) => String(row["id"] ?? "") === opts.id);
|
|
123157
|
+
gone = !still;
|
|
123158
|
+
} catch {
|
|
123159
|
+
gone = false;
|
|
123160
|
+
still = false;
|
|
123161
|
+
}
|
|
123162
|
+
printWriteReceipt(gone ? "verified" : still ? "partial" : "unknown", [
|
|
123163
|
+
receiptLine("\u9644\u52A0\u4FE1\u606F", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : still ? "\u4ECD\u5728" : void 0)
|
|
123164
|
+
]);
|
|
122170
123165
|
console.log(`
|
|
122171
123166
|
\u2705 \u9644\u52A0\u4FE1\u606F ${opts.id} \u5DF2\u5220\u9664
|
|
122172
123167
|
`);
|
|
@@ -122285,6 +123280,27 @@ async function runAdExtensionLeadFormCreate(opts) {
|
|
|
122285
123280
|
);
|
|
122286
123281
|
process.exit(1);
|
|
122287
123282
|
}
|
|
123283
|
+
const resObj = response ?? {};
|
|
123284
|
+
const extId = resObj["id"];
|
|
123285
|
+
if (extId) {
|
|
123286
|
+
let present;
|
|
123287
|
+
try {
|
|
123288
|
+
const rows = await fetchAccountExtensions(config, cfg.account, { verbose: opts.verbose });
|
|
123289
|
+
present = rows.some((row) => String(row["id"] ?? "") === extId);
|
|
123290
|
+
} catch {
|
|
123291
|
+
present = void 0;
|
|
123292
|
+
}
|
|
123293
|
+
const lines = [
|
|
123294
|
+
receiptLine(
|
|
123295
|
+
"Lead Form",
|
|
123296
|
+
"\u5728\u5217\u8868\u4E2D",
|
|
123297
|
+
present === void 0 ? void 0 : present ? "\u5728\u5217\u8868\u4E2D" : "\u672A\u627E\u5230"
|
|
123298
|
+
)
|
|
123299
|
+
];
|
|
123300
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
123301
|
+
} else {
|
|
123302
|
+
printWriteReceipt("submitted", [receiptLine("Lead Form", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
123303
|
+
}
|
|
122288
123304
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
122289
123305
|
section: `ad-extension-lead-form-${cfg.account}`,
|
|
122290
123306
|
commandLabel: "ad extension lead-form",
|
|
@@ -122294,8 +123310,6 @@ async function runAdExtensionLeadFormCreate(opts) {
|
|
|
122294
123310
|
})) {
|
|
122295
123311
|
return;
|
|
122296
123312
|
}
|
|
122297
|
-
const resObj = response ?? {};
|
|
122298
|
-
const extId = resObj["id"];
|
|
122299
123313
|
console.log(
|
|
122300
123314
|
`
|
|
122301
123315
|
\u2705 PMax Lead Form \u5DF2\u521B\u5EFA\uFF08campaignId: ${cfg.campaignId}${extId ? `\uFF0Cid: ${extId}` : ""}\uFF09
|
|
@@ -122342,6 +123356,27 @@ async function runAdExtensionWhatsappCreate(opts) {
|
|
|
122342
123356
|
);
|
|
122343
123357
|
process.exit(1);
|
|
122344
123358
|
}
|
|
123359
|
+
const resObj = response ?? {};
|
|
123360
|
+
const extId = resObj["id"];
|
|
123361
|
+
if (extId) {
|
|
123362
|
+
let present;
|
|
123363
|
+
try {
|
|
123364
|
+
const rows = await fetchAccountExtensions(config, cfg.account, { verbose: opts.verbose });
|
|
123365
|
+
present = rows.some((row) => String(row["id"] ?? "") === extId);
|
|
123366
|
+
} catch {
|
|
123367
|
+
present = void 0;
|
|
123368
|
+
}
|
|
123369
|
+
const lines = [
|
|
123370
|
+
receiptLine(
|
|
123371
|
+
"WhatsApp",
|
|
123372
|
+
"\u5728\u5217\u8868\u4E2D",
|
|
123373
|
+
present === void 0 ? void 0 : present ? "\u5728\u5217\u8868\u4E2D" : "\u672A\u627E\u5230"
|
|
123374
|
+
)
|
|
123375
|
+
];
|
|
123376
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
123377
|
+
} else {
|
|
123378
|
+
printWriteReceipt("submitted", [receiptLine("WhatsApp", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
123379
|
+
}
|
|
122345
123380
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
122346
123381
|
section: `ad-extension-whatsapp-${cfg.account}`,
|
|
122347
123382
|
commandLabel: "ad extension whatsapp",
|
|
@@ -122351,8 +123386,6 @@ async function runAdExtensionWhatsappCreate(opts) {
|
|
|
122351
123386
|
})) {
|
|
122352
123387
|
return;
|
|
122353
123388
|
}
|
|
122354
|
-
const resObj = response ?? {};
|
|
122355
|
-
const extId = resObj["id"];
|
|
122356
123389
|
console.log(
|
|
122357
123390
|
`
|
|
122358
123391
|
\u2705 PMax WhatsApp \u5DF2\u521B\u5EFA\uFF08campaignId: ${cfg.campaignId}${extId ? `\uFF0Cid: ${extId}` : ""}\uFF09
|
|
@@ -122416,6 +123449,21 @@ async function runAdExtensionUpdate(opts) {
|
|
|
122416
123449
|
`);
|
|
122417
123450
|
process.exit(1);
|
|
122418
123451
|
}
|
|
123452
|
+
let present;
|
|
123453
|
+
try {
|
|
123454
|
+
const rows = await fetchAccountExtensions(config, opts.account, { verbose: opts.verbose });
|
|
123455
|
+
present = rows.some((row) => String(row["id"] ?? "") === opts.id);
|
|
123456
|
+
} catch {
|
|
123457
|
+
present = void 0;
|
|
123458
|
+
}
|
|
123459
|
+
const updateLines = [
|
|
123460
|
+
receiptLine(
|
|
123461
|
+
"\u9644\u52A0\u4FE1\u606F",
|
|
123462
|
+
"\u5728\u5217\u8868\u4E2D",
|
|
123463
|
+
present === void 0 ? void 0 : present ? "\u5728\u5217\u8868\u4E2D" : "\u672A\u627E\u5230"
|
|
123464
|
+
)
|
|
123465
|
+
];
|
|
123466
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(updateLines), updateLines);
|
|
122419
123467
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
122420
123468
|
section: `ad-extension-update-${opts.account}`,
|
|
122421
123469
|
commandLabel,
|
|
@@ -122741,9 +123789,22 @@ async function runAdDeviceBidSet(opts) {
|
|
|
122741
123789
|
);
|
|
122742
123790
|
process.exit(1);
|
|
122743
123791
|
}
|
|
123792
|
+
const expectedLabel2 = formatBidModifierPercent(opts.bidModifier, true);
|
|
123793
|
+
let afterList2;
|
|
123794
|
+
try {
|
|
123795
|
+
afterList2 = await apiFetch2(listUrl2, config, {}, opts.verbose);
|
|
123796
|
+
} catch {
|
|
123797
|
+
afterList2 = void 0;
|
|
123798
|
+
}
|
|
123799
|
+
const after2 = (Array.isArray(afterList2) ? afterList2 : []).find(
|
|
123800
|
+
(r) => String(r.id) === criterionId2
|
|
123801
|
+
);
|
|
123802
|
+
const actualLabel2 = after2?.bidModifier == null ? void 0 : formatBidModifierPercent(1 + after2.bidModifier / 100, true);
|
|
123803
|
+
const lines2 = [receiptLine("\u51FA\u4EF7\u8C03\u6574", expectedLabel2, actualLabel2)];
|
|
123804
|
+
printWriteReceipt(afterList2 == null ? "unknown" : judgeReceipt(lines2), lines2);
|
|
122744
123805
|
console.log(
|
|
122745
123806
|
`
|
|
122746
|
-
\u2705 \u5DF2\u66F4\u65B0\u5E7F\u544A\u7EC4\u8BBE\u5907\u51FA\u4EF7\uFF08\u7CFB\u5217 ${opts.campaignId} / \u7EC4 ${opts.adGroupId} / id ${criterionId2} / ${deviceType ?? "?"} \u2192 ${
|
|
123807
|
+
\u2705 \u5DF2\u66F4\u65B0\u5E7F\u544A\u7EC4\u8BBE\u5907\u51FA\u4EF7\uFF08\u7CFB\u5217 ${opts.campaignId} / \u7EC4 ${opts.adGroupId} / id ${criterionId2} / ${deviceType ?? "?"} \u2192 ${expectedLabel2}\uFF09
|
|
122747
123808
|
`
|
|
122748
123809
|
);
|
|
122749
123810
|
return;
|
|
@@ -122776,10 +123837,22 @@ async function runAdDeviceBidSet(opts) {
|
|
|
122776
123837
|
);
|
|
122777
123838
|
process.exit(1);
|
|
122778
123839
|
}
|
|
123840
|
+
const expectedLabel = formatBidModifierPercent(opts.bidModifier, true);
|
|
123841
|
+
let afterList;
|
|
123842
|
+
try {
|
|
123843
|
+
afterList = await apiFetch2(listUrl, config, {}, opts.verbose);
|
|
123844
|
+
} catch {
|
|
123845
|
+
afterList = void 0;
|
|
123846
|
+
}
|
|
123847
|
+
const afterRows = Array.isArray(afterList) ? afterList : [];
|
|
123848
|
+
const after = afterRows.find((r) => String(r.id) === criterionId);
|
|
123849
|
+
const actualLabel = after?.bidModifier == null ? void 0 : formatBidModifierPercent(after.bidModifier, after.bidModifierSpecified);
|
|
123850
|
+
const lines = [receiptLine("\u51FA\u4EF7\u8C03\u6574", expectedLabel, actualLabel)];
|
|
123851
|
+
printWriteReceipt(afterList == null ? "unknown" : judgeReceipt(lines), lines);
|
|
122779
123852
|
const deviceLabel2 = opts.deviceType ? normalizeDeviceType(opts.deviceType) : "\u8BBE\u5907";
|
|
122780
123853
|
console.log(
|
|
122781
123854
|
`
|
|
122782
|
-
\u2705 \u5DF2\u66F4\u65B0\u7CFB\u5217\u8BBE\u5907\u51FA\u4EF7\uFF08\u7CFB\u5217 ${opts.campaignId} / ${deviceLabel2} / id ${criterionId} \u2192 \u500D\u7387 ${opts.bidModifier}\uFF0C${
|
|
123855
|
+
\u2705 \u5DF2\u66F4\u65B0\u7CFB\u5217\u8BBE\u5907\u51FA\u4EF7\uFF08\u7CFB\u5217 ${opts.campaignId} / ${deviceLabel2} / id ${criterionId} \u2192 \u500D\u7387 ${opts.bidModifier}\uFF0C${expectedLabel}\uFF09
|
|
122783
123856
|
`
|
|
122784
123857
|
);
|
|
122785
123858
|
}
|
|
@@ -123214,6 +124287,7 @@ async function runAdGeoAdd(opts) {
|
|
|
123214
124287
|
`);
|
|
123215
124288
|
process.exit(1);
|
|
123216
124289
|
}
|
|
124290
|
+
await printGeoPresence(config, googleApiUrl, opts, true);
|
|
123217
124291
|
const label2 = opts.exclude ? "\u5DF2\u6392\u9664" : "\u5DF2\u6DFB\u52A0\u5B9A\u4F4D";
|
|
123218
124292
|
console.log(`
|
|
123219
124293
|
\u2705 \u5730\u7406\u4F4D\u7F6E ${opts.locationId} ${label2}\uFF08\u5E7F\u544A\u7CFB\u5217\uFF1A${opts.campaignId}\uFF09
|
|
@@ -123233,14 +124307,50 @@ async function runAdGeoRemove(opts) {
|
|
|
123233
124307
|
`);
|
|
123234
124308
|
process.exit(1);
|
|
123235
124309
|
}
|
|
124310
|
+
await printGeoPresence(config, googleApiUrl, opts, false);
|
|
123236
124311
|
console.log(`
|
|
123237
124312
|
\u2705 \u5730\u7406\u4F4D\u7F6E ${opts.locationId} \u5DF2\u4ECE\u5E7F\u544A\u7CFB\u5217 ${opts.campaignId} \u4E2D\u79FB\u9664
|
|
123238
124313
|
`);
|
|
123239
124314
|
}
|
|
124315
|
+
async function printGeoPresence(config, googleApiUrl, opts, shouldExist) {
|
|
124316
|
+
const params = new URLSearchParams({
|
|
124317
|
+
startDate: toGoogleDate(void 0, -30),
|
|
124318
|
+
endDate: toGoogleDate(void 0, 0),
|
|
124319
|
+
newest: "true"
|
|
124320
|
+
});
|
|
124321
|
+
const kinds = opts.exclude ? ["excludedlocations"] : shouldExist ? ["targetedlocations"] : ["targetedlocations", "excludedlocations"];
|
|
124322
|
+
let present;
|
|
124323
|
+
try {
|
|
124324
|
+
present = false;
|
|
124325
|
+
for (const kind of kinds) {
|
|
124326
|
+
const data = await apiFetch2(
|
|
124327
|
+
`${googleApiUrl}/campaignmanagement/v2/${kind}/${opts.account}?${params}`,
|
|
124328
|
+
config,
|
|
124329
|
+
{},
|
|
124330
|
+
opts.verbose
|
|
124331
|
+
);
|
|
124332
|
+
const rows = (data.data ?? []).filter(
|
|
124333
|
+
(row) => String(row["campaignId"] ?? row["CampaignId"] ?? "") === opts.campaignId
|
|
124334
|
+
);
|
|
124335
|
+
if (rows.some(
|
|
124336
|
+
(row) => [row["id"], row["Id"], row["locationId"], row["criterionId"]].map(String).includes(opts.locationId)
|
|
124337
|
+
)) {
|
|
124338
|
+
present = true;
|
|
124339
|
+
}
|
|
124340
|
+
}
|
|
124341
|
+
} catch {
|
|
124342
|
+
present = void 0;
|
|
124343
|
+
}
|
|
124344
|
+
const expected = shouldExist ? "\u5728\u5217\u8868\u4E2D" : "\u5DF2\u4E0D\u5728";
|
|
124345
|
+
const actual = present === void 0 ? void 0 : present ? "\u5728\u5217\u8868\u4E2D" : "\u5DF2\u4E0D\u5728";
|
|
124346
|
+
const lines = [receiptLine("\u5730\u533A", expected, actual)];
|
|
124347
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
124348
|
+
}
|
|
123240
124349
|
async function fetchTargetedGeoRows(config, googleApiUrl, account, campaignId, verbose) {
|
|
123241
124350
|
const params = new URLSearchParams({
|
|
123242
124351
|
startDate: toGoogleDate(void 0, -30),
|
|
123243
|
-
endDate: toGoogleDate(void 0, 0)
|
|
124352
|
+
endDate: toGoogleDate(void 0, 0),
|
|
124353
|
+
newest: "true"
|
|
123244
124354
|
});
|
|
123245
124355
|
const url = `${googleApiUrl}/campaignmanagement/v2/targetedlocations/${account}?${params}`;
|
|
123246
124356
|
const data = await apiFetch2(url, config, {}, verbose);
|
|
@@ -123309,13 +124419,31 @@ async function runAdGeoSetBid(opts) {
|
|
|
123309
124419
|
);
|
|
123310
124420
|
process.exit(1);
|
|
123311
124421
|
}
|
|
124422
|
+
let afterRows;
|
|
124423
|
+
try {
|
|
124424
|
+
afterRows = await fetchTargetedGeoRows(
|
|
124425
|
+
config,
|
|
124426
|
+
googleApiUrl,
|
|
124427
|
+
opts.account,
|
|
124428
|
+
opts.campaignId,
|
|
124429
|
+
opts.verbose
|
|
124430
|
+
);
|
|
124431
|
+
} catch {
|
|
124432
|
+
afterRows = void 0;
|
|
124433
|
+
}
|
|
124434
|
+
const after = afterRows?.find((r) => String(r["id"] ?? "") === criterionId);
|
|
124435
|
+
const expectedLabel = formatBidModifierPercent(opts.bidModifier, true);
|
|
124436
|
+
const actualBid = after && typeof after["bidModifier"] === "number" ? after["bidModifier"] : void 0;
|
|
124437
|
+
const actualLabel = actualBid == null ? void 0 : formatBidModifierPercent(actualBid, after?.["bidModifierSpecified"]);
|
|
124438
|
+
const lines = [receiptLine("\u51FA\u4EF7\u8C03\u6574", expectedLabel, actualLabel)];
|
|
124439
|
+
printWriteReceipt(afterRows == null ? "unknown" : judgeReceipt(lines), lines);
|
|
123312
124440
|
const row = rows.find((r) => String(r["id"] ?? "") === criterionId);
|
|
123313
124441
|
const name2 = String(
|
|
123314
124442
|
row?.["locationName"] ?? row?.["name"] ?? row?.["countryOrRegion"] ?? criterionId
|
|
123315
124443
|
);
|
|
123316
124444
|
console.log(
|
|
123317
124445
|
`
|
|
123318
|
-
\u2705 \u5DF2\u66F4\u65B0\u5730\u7406\u4F4D\u7F6E\u51FA\u4EF7\uFF08\u7CFB\u5217 ${opts.campaignId} / ${name2} / id ${criterionId} \u2192 \u500D\u7387 ${opts.bidModifier}\uFF0C${
|
|
124446
|
+
\u2705 \u5DF2\u66F4\u65B0\u5730\u7406\u4F4D\u7F6E\u51FA\u4EF7\uFF08\u7CFB\u5217 ${opts.campaignId} / ${name2} / id ${criterionId} \u2192 \u500D\u7387 ${opts.bidModifier}\uFF0C${expectedLabel}\uFF09
|
|
123319
124447
|
`
|
|
123320
124448
|
);
|
|
123321
124449
|
}
|
|
@@ -123778,6 +124906,101 @@ function listPlannedRsaAssets(ad, groupPath, adIndex, adGroupName) {
|
|
|
123778
124906
|
}
|
|
123779
124907
|
return out;
|
|
123780
124908
|
}
|
|
124909
|
+
function plannedLocationIds(value) {
|
|
124910
|
+
if (!Array.isArray(value)) return [];
|
|
124911
|
+
const ids = [];
|
|
124912
|
+
for (const item of value) {
|
|
124913
|
+
if (typeof item === "string" || typeof item === "number") {
|
|
124914
|
+
ids.push(String(item));
|
|
124915
|
+
continue;
|
|
124916
|
+
}
|
|
124917
|
+
if (item && typeof item === "object") {
|
|
124918
|
+
const id = pickString2(
|
|
124919
|
+
item["id"],
|
|
124920
|
+
item["Id"]
|
|
124921
|
+
);
|
|
124922
|
+
if (id) ids.push(id);
|
|
124923
|
+
}
|
|
124924
|
+
}
|
|
124925
|
+
return [...new Set(ids)].sort();
|
|
124926
|
+
}
|
|
124927
|
+
function firstPlannedFinalUrl(campaign) {
|
|
124928
|
+
const groups = campaign["AdGroupsForBatchJob"];
|
|
124929
|
+
if (!Array.isArray(groups)) return "";
|
|
124930
|
+
for (const group of groups) {
|
|
124931
|
+
if (!group || typeof group !== "object") continue;
|
|
124932
|
+
const ads = group["AdsForBatchJob"];
|
|
124933
|
+
if (!Array.isArray(ads)) continue;
|
|
124934
|
+
for (const ad of ads) {
|
|
124935
|
+
if (!ad || typeof ad !== "object") continue;
|
|
124936
|
+
const url = pickString2(
|
|
124937
|
+
ad["Finalurl"],
|
|
124938
|
+
ad["DestinationUrl"]
|
|
124939
|
+
);
|
|
124940
|
+
if (url) return url;
|
|
124941
|
+
}
|
|
124942
|
+
}
|
|
124943
|
+
return "";
|
|
124944
|
+
}
|
|
124945
|
+
function pickLiveAdLandingUrl(ad) {
|
|
124946
|
+
if (!ad) return "";
|
|
124947
|
+
return pickString2(
|
|
124948
|
+
ad["Finalurl"],
|
|
124949
|
+
ad["finalurl"],
|
|
124950
|
+
ad["finalUrl"],
|
|
124951
|
+
ad["FinalUrl"],
|
|
124952
|
+
ad["DestinationUrl"],
|
|
124953
|
+
ad["destinationUrl"]
|
|
124954
|
+
);
|
|
124955
|
+
}
|
|
124956
|
+
var RECEIPT_MISSING_CAP = 8;
|
|
124957
|
+
function buildSearchCreateReceiptLines(campaign, live, opts) {
|
|
124958
|
+
const lines = [];
|
|
124959
|
+
const plannedBudget = Number(campaign["Budget"] ?? campaign["budget"]);
|
|
124960
|
+
if (Number.isFinite(plannedBudget) && plannedBudget > 0) {
|
|
124961
|
+
lines.push(
|
|
124962
|
+
receiptLine(
|
|
124963
|
+
"\u65E5\u9884\u7B97",
|
|
124964
|
+
yuanLabel(plannedBudget),
|
|
124965
|
+
live.budgetYuan == null ? void 0 : yuanLabel(live.budgetYuan)
|
|
124966
|
+
)
|
|
124967
|
+
);
|
|
124968
|
+
}
|
|
124969
|
+
if (live.campaignFound) {
|
|
124970
|
+
const liveStatus = pickString2(live.statusV2);
|
|
124971
|
+
lines.push(
|
|
124972
|
+
liveStatus ? receiptLine("\u72B6\u6001", liveStatus, liveStatus) : receiptLine("\u72B6\u6001", "\u53EF\u8BFB", void 0)
|
|
124973
|
+
);
|
|
124974
|
+
}
|
|
124975
|
+
const plannedIds = plannedLocationIds(campaign["targetedLocations"]);
|
|
124976
|
+
if (plannedIds.length > 0) {
|
|
124977
|
+
const liveIds = [...new Set((live.targetedLocations ?? []).map((row) => liveLocationId(row)).filter(Boolean))].sort();
|
|
124978
|
+
lines.push(receiptLine("\u6295\u653E\u56FD\u5BB6", plannedIds.join(","), live.campaignFound ? liveIds.join(",") : void 0));
|
|
124979
|
+
}
|
|
124980
|
+
const plannedGeo = resolveCampaignGeoTargetTypes(campaign);
|
|
124981
|
+
if (plannedGeo.positive) {
|
|
124982
|
+
lines.push(receiptLine("\u4F4D\u7F6E\u9009\u9879", plannedGeo.positive, live.positiveGeoTargetType));
|
|
124983
|
+
}
|
|
124984
|
+
const plannedUrl = firstPlannedFinalUrl(campaign);
|
|
124985
|
+
if (plannedUrl) {
|
|
124986
|
+
lines.push(receiptLine("\u843D\u5730\u9875", plannedUrl, live.landingUrl));
|
|
124987
|
+
}
|
|
124988
|
+
const counts = opts?.counts;
|
|
124989
|
+
if (counts) {
|
|
124990
|
+
const countActual = (n) => live.campaignFound ? String(n) : void 0;
|
|
124991
|
+
lines.push(receiptLine("\u5E7F\u544A\u7EC4", String(counts.plannedAdGroups), countActual(counts.liveAdGroups)));
|
|
124992
|
+
lines.push(receiptLine("\u5173\u952E\u8BCD", String(counts.plannedKeywords), countActual(counts.liveKeywords)));
|
|
124993
|
+
lines.push(receiptLine("RSA", String(counts.plannedAds), countActual(counts.liveAds)));
|
|
124994
|
+
lines.push(receiptLine("\u5426\u8BCD", String(counts.plannedNegativeKeywords), countActual(counts.liveNegativeKeywords)));
|
|
124995
|
+
}
|
|
124996
|
+
const missing = opts?.missing ?? [];
|
|
124997
|
+
for (const row of missing.slice(0, RECEIPT_MISSING_CAP)) {
|
|
124998
|
+
const layer = pickString2(row.layer) || "\u9879";
|
|
124999
|
+
const summary = pickString2(row.summary, row.plannedContent) || layer;
|
|
125000
|
+
lines.push(receiptLine(`\u7F3A\u5931\xB7${layer}`, summary, "\u672A\u5BF9\u9F50"));
|
|
125001
|
+
}
|
|
125002
|
+
return lines;
|
|
125003
|
+
}
|
|
123781
125004
|
function liveLocationId(item) {
|
|
123782
125005
|
return pickString2(
|
|
123783
125006
|
item["id"],
|
|
@@ -124521,7 +125744,7 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
|
|
|
124521
125744
|
),
|
|
124522
125745
|
fetchList(
|
|
124523
125746
|
config,
|
|
124524
|
-
negativeKeywordSlimListUrl(googleApiUrl, accountId),
|
|
125747
|
+
negativeKeywordSlimListUrl(googleApiUrl, accountId, { newest: true }),
|
|
124525
125748
|
verbose
|
|
124526
125749
|
),
|
|
124527
125750
|
fetchList(
|
|
@@ -124555,9 +125778,19 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
|
|
|
124555
125778
|
const liveCampaign = campaigns.find((c) => pickString2(c["id"], c["Id"]) === campaignId) ?? campaigns.find((c) => pickString2(c["name"], c["Name"]) === campaignName);
|
|
124556
125779
|
const campaignFound = liveCampaign !== void 0;
|
|
124557
125780
|
const liveGeoTargetTypes = liveCampaign ? readLiveGeoTargetTypes(liveCampaign) : {};
|
|
125781
|
+
const budgetYuan2 = liveCampaign ? toDisplayMoney(liveCampaign["budget"] ?? liveCampaign["Budget"]) ?? void 0 : void 0;
|
|
125782
|
+
const campaignAds = ads.filter((row) => belongsToCampaign(row, campaignId, campaignName));
|
|
125783
|
+
let landingUrl = "";
|
|
125784
|
+
for (const ad of campaignAds) {
|
|
125785
|
+
landingUrl = pickLiveAdLandingUrl(ad);
|
|
125786
|
+
if (landingUrl) break;
|
|
125787
|
+
}
|
|
124558
125788
|
return {
|
|
124559
125789
|
campaignFound,
|
|
124560
125790
|
campaignName,
|
|
125791
|
+
budgetYuan: budgetYuan2,
|
|
125792
|
+
statusV2: liveCampaign ? pickString2(liveCampaign["statusV2"], liveCampaign["StatusV2"]) : void 0,
|
|
125793
|
+
landingUrl: landingUrl || void 0,
|
|
124561
125794
|
positiveGeoTargetType: liveGeoTargetTypes.positive,
|
|
124562
125795
|
negativeGeoTargetType: liveGeoTargetTypes.negative,
|
|
124563
125796
|
adGroups: adGroups.filter((g) => belongsToCampaign(g, campaignId, campaignName)),
|
|
@@ -125154,6 +126387,7 @@ async function runCampaignBatchDiff(opts) {
|
|
|
125154
126387
|
const params = new URLSearchParams();
|
|
125155
126388
|
params.set("startDate", toGoogleDate(void 0, -30));
|
|
125156
126389
|
params.set("endDate", toGoogleDate(void 0, 0));
|
|
126390
|
+
params.set("newest", "true");
|
|
125157
126391
|
const campaigns = await fetchList(
|
|
125158
126392
|
config,
|
|
125159
126393
|
`${googleApiUrl}/campaignmanagement/v2/list/${accountId}?${params}`,
|
|
@@ -125198,6 +126432,11 @@ async function runCampaignBatchDiff(opts) {
|
|
|
125198
126432
|
...result,
|
|
125199
126433
|
...report
|
|
125200
126434
|
};
|
|
126435
|
+
const receiptLines = buildSearchCreateReceiptLines(campaign, live, {
|
|
126436
|
+
counts: result.counts,
|
|
126437
|
+
missing: result.missing
|
|
126438
|
+
});
|
|
126439
|
+
printWriteReceipt(judgeReceipt(receiptLines, !live.campaignFound), receiptLines);
|
|
125201
126440
|
printBatchDiffUserDeliveryMarkdown(report);
|
|
125202
126441
|
if (await emitCliJsonOrSnapshot(
|
|
125203
126442
|
{ jsonOut: opts.jsonOut },
|
|
@@ -125582,6 +126821,23 @@ async function runAiCreationPublish(opts) {
|
|
|
125582
126821
|
`);
|
|
125583
126822
|
process.exit(1);
|
|
125584
126823
|
}
|
|
126824
|
+
let again;
|
|
126825
|
+
try {
|
|
126826
|
+
again = await apiFetch2(`${queryBase}/${opts.id}`, config, {}, opts.verbose);
|
|
126827
|
+
} catch {
|
|
126828
|
+
again = void 0;
|
|
126829
|
+
}
|
|
126830
|
+
const submittedCampaign = body["campaign"] ?? {};
|
|
126831
|
+
const readCampaign = again?.["campaign"] ?? {};
|
|
126832
|
+
const status = again ? String(again["status"] ?? again["draftStatus"] ?? "") : "";
|
|
126833
|
+
const leftDraft = status !== "" && status !== "Draft";
|
|
126834
|
+
const campaignId = again ? resolveCampaignIdFromBatch(again) : "";
|
|
126835
|
+
const lines = [
|
|
126836
|
+
receiptLine("\u53D1\u5E03\u72B6\u6001", "\u5DF2\u79BB\u5F00\u8349\u7A3F", again ? leftDraft ? "\u5DF2\u79BB\u5F00\u8349\u7A3F" : status || "Draft" : void 0),
|
|
126837
|
+
receiptLine("\u7CFB\u5217\u9884\u7B97", submittedCampaign["Budget"], again ? readCampaign["Budget"] : void 0),
|
|
126838
|
+
receiptLine("\u7CFB\u5217", "\u5DF2\u751F\u6210", again ? campaignId || "\u5C1A\u672A\u751F\u6210" : void 0)
|
|
126839
|
+
];
|
|
126840
|
+
printWriteReceipt(again ? judgeReceipt(lines) : "unknown", lines);
|
|
125585
126841
|
console.log(
|
|
125586
126842
|
`
|
|
125587
126843
|
\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
|
|
@@ -125625,6 +126881,33 @@ async function runAiCreationUpdate(opts) {
|
|
|
125625
126881
|
`);
|
|
125626
126882
|
process.exit(1);
|
|
125627
126883
|
}
|
|
126884
|
+
let again;
|
|
126885
|
+
try {
|
|
126886
|
+
again = await apiFetch2(
|
|
126887
|
+
`${config.apiBaseUrl}/query/campaign-creation-record/campaign-batch-asyncs/${opts.id}`,
|
|
126888
|
+
config,
|
|
126889
|
+
{},
|
|
126890
|
+
opts.verbose
|
|
126891
|
+
);
|
|
126892
|
+
} catch {
|
|
126893
|
+
again = void 0;
|
|
126894
|
+
}
|
|
126895
|
+
const lines = [];
|
|
126896
|
+
if (opts.url) {
|
|
126897
|
+
lines.push(receiptLine("\u63A8\u5E7F\u94FE\u63A5", opts.url, again?.["url"]));
|
|
126898
|
+
}
|
|
126899
|
+
if (opts.campaignName) {
|
|
126900
|
+
lines.push(receiptLine("\u7CFB\u5217\u540D", opts.campaignName, again?.["campaignName"]));
|
|
126901
|
+
}
|
|
126902
|
+
if (opts.budget !== void 0) {
|
|
126903
|
+
const readCampaign = again?.["campaign"] ?? {};
|
|
126904
|
+
const expectCents = Math.round(opts.budget * 100);
|
|
126905
|
+
lines.push(receiptLine("\u7CFB\u5217\u9884\u7B97", expectCents, readCampaign["Budget"] ?? readCampaign["budget"]));
|
|
126906
|
+
}
|
|
126907
|
+
if (lines.length === 0) {
|
|
126908
|
+
lines.push(receiptLine("\u8349\u7A3F", opts.id, again ? opts.id : void 0));
|
|
126909
|
+
}
|
|
126910
|
+
printWriteReceipt(again ? judgeReceipt(lines) : "unknown", lines);
|
|
125628
126911
|
console.log(`
|
|
125629
126912
|
\u2705 \u8349\u7A3F\u5DF2\u66F4\u65B0
|
|
125630
126913
|
`);
|
|
@@ -127548,6 +128831,204 @@ async function linkPmaxVideoAfterCreate(opts) {
|
|
|
127548
128831
|
}
|
|
127549
128832
|
}
|
|
127550
128833
|
|
|
128834
|
+
// src/commands/ad/pmax-brand-guidelines.ts
|
|
128835
|
+
var PMAX_CAMPAIGN_BRAND_FIELD_TYPES = /* @__PURE__ */ new Set(["BUSINESS_NAME", "LOGO", "LANDSCAPE_LOGO"]);
|
|
128836
|
+
function isPmaxBrandGuidelinesActive(detail) {
|
|
128837
|
+
if (detail["brandGuidelinesEnabled"] === true) return true;
|
|
128838
|
+
const assets = detail["brandAssets"];
|
|
128839
|
+
if (!Array.isArray(assets)) return false;
|
|
128840
|
+
return assets.some((row) => {
|
|
128841
|
+
if (!row || typeof row !== "object") return false;
|
|
128842
|
+
const ft = String(row["fieldType"] ?? "").toUpperCase();
|
|
128843
|
+
return PMAX_CAMPAIGN_BRAND_FIELD_TYPES.has(ft);
|
|
128844
|
+
});
|
|
128845
|
+
}
|
|
128846
|
+
function brandEditAgentHint(bgActive) {
|
|
128847
|
+
return bgActive ? "\u6539\u5546\u5BB6\u540D/Logo/\u6837\u5F0F\uFF1Aad pmax-brand-assets-edit\uFF08\u52FF\u5BF9 AssetGroup \u7528 pmax-assets-update \u6539 BUSINESS_NAME/LOGO\uFF09" : "\u6539\u54C1\u724C\uFF1Aad pmax-assets-update\uFF08AssetGroup \u7EA7\uFF09\uFF1B\u6216 ad pmax-brand-guidelines-enable \u542F\u7528 BG \u540E\u8D70 ad pmax-brand-assets-edit";
|
|
128848
|
+
}
|
|
128849
|
+
function enrichPmaxDetailForAgent(detail) {
|
|
128850
|
+
const bgActive = isPmaxBrandGuidelinesActive(detail);
|
|
128851
|
+
return {
|
|
128852
|
+
...detail,
|
|
128853
|
+
_brandGuidelinesActive: bgActive,
|
|
128854
|
+
_agentBrandHint: brandEditAgentHint(bgActive)
|
|
128855
|
+
};
|
|
128856
|
+
}
|
|
128857
|
+
async function fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaignId, verbose) {
|
|
128858
|
+
const url = pmaxCampaignUrl(googleApiUrl, accountId, campaignId);
|
|
128859
|
+
const raw = await pmaxApiFetch(url, config, {}, verbose);
|
|
128860
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
128861
|
+
return raw;
|
|
128862
|
+
}
|
|
128863
|
+
return { data: raw };
|
|
128864
|
+
}
|
|
128865
|
+
function printPmaxWriteReceipt(expected, detail, liveCountryIds) {
|
|
128866
|
+
const lines = [];
|
|
128867
|
+
if (expected.name) {
|
|
128868
|
+
lines.push(receiptLine("\u540D\u79F0", expected.name, detail?.["name"] ?? detail?.["Name"]));
|
|
128869
|
+
}
|
|
128870
|
+
if (expected.budgetYuan != null) {
|
|
128871
|
+
const raw = detail?.["budget"] ?? detail?.["Budget"];
|
|
128872
|
+
const actual = typeof raw === "number" && Number.isFinite(raw) ? raw / 100 : void 0;
|
|
128873
|
+
lines.push(
|
|
128874
|
+
receiptLine(
|
|
128875
|
+
"\u65E5\u9884\u7B97",
|
|
128876
|
+
yuanLabel(expected.budgetYuan),
|
|
128877
|
+
actual == null ? void 0 : yuanLabel(actual)
|
|
128878
|
+
)
|
|
128879
|
+
);
|
|
128880
|
+
}
|
|
128881
|
+
if (expected.status) {
|
|
128882
|
+
lines.push(receiptLine("\u72B6\u6001", expected.status, detail?.["statusV2"] ?? detail?.["status"]));
|
|
128883
|
+
}
|
|
128884
|
+
if (expected.finalUrl) {
|
|
128885
|
+
const urls = detail?.["finalUrls"] ?? detail?.["finalurls"];
|
|
128886
|
+
const actual = Array.isArray(urls) ? urls[0] : detail?.["finalUrl"];
|
|
128887
|
+
lines.push(receiptLine("\u843D\u5730\u9875", expected.finalUrl, actual));
|
|
128888
|
+
}
|
|
128889
|
+
if (expected.countryIds && expected.countryIds.length > 0) {
|
|
128890
|
+
const expectedIds = [...expected.countryIds].map(String).sort().join(",");
|
|
128891
|
+
const actualIds = liveCountryIds ? [...liveCountryIds].map(String).sort().join(",") : void 0;
|
|
128892
|
+
lines.push(receiptLine("\u6295\u653E\u56FD\u5BB6", expectedIds, actualIds));
|
|
128893
|
+
}
|
|
128894
|
+
printWriteReceipt(detail ? judgeReceipt(lines) : "unknown", lines);
|
|
128895
|
+
}
|
|
128896
|
+
function hasBrandImageSource(cfg, slot) {
|
|
128897
|
+
if (slot === "logo") {
|
|
128898
|
+
return Boolean(
|
|
128899
|
+
cfg.logoImageAssetId?.trim() || cfg.logoImageBase64?.trim() || cfg.imagePaths?.logo?.trim()
|
|
128900
|
+
);
|
|
128901
|
+
}
|
|
128902
|
+
return Boolean(
|
|
128903
|
+
cfg.landscapeLogoImageAssetId?.trim() || cfg.landscapeLogoImageBase64?.trim() || cfg.imagePaths?.landscapeLogo?.trim()
|
|
128904
|
+
);
|
|
128905
|
+
}
|
|
128906
|
+
function validateBrandAssetsPatchBody(cfg, opts) {
|
|
128907
|
+
const errors = [];
|
|
128908
|
+
const style = cfg.brandGuidelines;
|
|
128909
|
+
const hasMain = Boolean(style?.mainColor?.trim());
|
|
128910
|
+
const hasAccent = Boolean(style?.accentColor?.trim());
|
|
128911
|
+
if (hasMain !== hasAccent) {
|
|
128912
|
+
errors.push("brandGuidelines.mainColor \u4E0E accentColor \u987B\u6210\u5BF9\u4F20\u5165");
|
|
128913
|
+
}
|
|
128914
|
+
const hasAny = Boolean(cfg.businessName?.trim()) || hasBrandImageSource(cfg, "logo") || hasBrandImageSource(cfg, "landscapeLogo") || Boolean(style?.predefinedFontFamily?.trim()) || hasMain;
|
|
128915
|
+
if (opts?.requireAtLeastOne !== false && !hasAny) {
|
|
128916
|
+
errors.push(
|
|
128917
|
+
"\u81F3\u5C11\u4F20\u4E00\u9879\uFF1AbusinessName\u3001logoImage*\u3001landscapeLogoImage* \u6216 brandGuidelines \u6837\u5F0F\u5B57\u6BB5"
|
|
128918
|
+
);
|
|
128919
|
+
}
|
|
128920
|
+
return errors;
|
|
128921
|
+
}
|
|
128922
|
+
function validateEnableBrandGuidelinesBody(cfg) {
|
|
128923
|
+
const errors = validateBrandAssetsPatchBody(cfg, {
|
|
128924
|
+
requireAtLeastOne: cfg.autoPopulateBrandAssets !== true
|
|
128925
|
+
});
|
|
128926
|
+
if (cfg.autoPopulateBrandAssets !== true) {
|
|
128927
|
+
if (!cfg.businessName?.trim()) {
|
|
128928
|
+
errors.push("autoPopulateBrandAssets=false \u65F6 businessName \u5FC5\u586B");
|
|
128929
|
+
}
|
|
128930
|
+
if (!hasBrandImageSource(cfg, "logo")) {
|
|
128931
|
+
errors.push("autoPopulateBrandAssets=false \u65F6 Logo\uFF08logoImage* / imagePaths.logo\uFF09\u5FC5\u586B");
|
|
128932
|
+
}
|
|
128933
|
+
}
|
|
128934
|
+
return errors;
|
|
128935
|
+
}
|
|
128936
|
+
function detectAssetGroupBrandLinkBlocked(body, bgActive) {
|
|
128937
|
+
if (!bgActive) return [];
|
|
128938
|
+
const errors = [];
|
|
128939
|
+
const links = body["assetsToLink"];
|
|
128940
|
+
if (Array.isArray(links)) {
|
|
128941
|
+
for (const item of links) {
|
|
128942
|
+
if (!item || typeof item !== "object") continue;
|
|
128943
|
+
const ft = String(item["fieldType"] ?? "").toUpperCase();
|
|
128944
|
+
if (PMAX_CAMPAIGN_BRAND_FIELD_TYPES.has(ft)) {
|
|
128945
|
+
errors.push(
|
|
128946
|
+
`Brand Guidelines \u5DF2\u751F\u6548\uFF0C\u7981\u6B62\u5728 AssetGroup PUT ${ft}\uFF1B\u8BF7\u7528 ad pmax-brand-assets-edit`
|
|
128947
|
+
);
|
|
128948
|
+
}
|
|
128949
|
+
}
|
|
128950
|
+
}
|
|
128951
|
+
const replace = body["replaceFieldTypes"];
|
|
128952
|
+
if (Array.isArray(replace)) {
|
|
128953
|
+
for (const ft of replace) {
|
|
128954
|
+
const upper = String(ft ?? "").toUpperCase();
|
|
128955
|
+
if (PMAX_CAMPAIGN_BRAND_FIELD_TYPES.has(upper)) {
|
|
128956
|
+
errors.push(
|
|
128957
|
+
`Brand Guidelines \u5DF2\u751F\u6548\uFF0CreplaceFieldTypes \u542B ${upper}\uFF1B\u8BF7\u7528 ad pmax-brand-assets-edit`
|
|
128958
|
+
);
|
|
128959
|
+
}
|
|
128960
|
+
}
|
|
128961
|
+
}
|
|
128962
|
+
return errors;
|
|
128963
|
+
}
|
|
128964
|
+
async function buildBrandAssetsApiBody(configFile, cfg, accountId, config, googleApiUrl, verbose) {
|
|
128965
|
+
const body = {};
|
|
128966
|
+
if (cfg.businessName?.trim()) body["businessName"] = cfg.businessName.trim();
|
|
128967
|
+
const logoCfg = {
|
|
128968
|
+
logoImageAssetId: cfg.logoImageAssetId,
|
|
128969
|
+
logoImageBase64: cfg.logoImageBase64,
|
|
128970
|
+
imagePaths: cfg.imagePaths?.logo ? { logo: cfg.imagePaths.logo } : void 0
|
|
128971
|
+
};
|
|
128972
|
+
const needsLogo = cfg.logoImageAssetId?.trim() || cfg.logoImageBase64?.trim() || cfg.imagePaths?.logo?.trim();
|
|
128973
|
+
if (needsLogo) {
|
|
128974
|
+
const slots = await resolvePmaxImageSlots(
|
|
128975
|
+
configFile,
|
|
128976
|
+
logoCfg,
|
|
128977
|
+
accountId,
|
|
128978
|
+
config,
|
|
128979
|
+
googleApiUrl,
|
|
128980
|
+
{ verbose, logUploads: false, requiredKinds: ["logo"] }
|
|
128981
|
+
);
|
|
128982
|
+
if (slots.logoImageAssetId) body["logoImageAssetId"] = slots.logoImageAssetId;
|
|
128983
|
+
else if (slots.logoImageBase64) body["logoImageBase64"] = slots.logoImageBase64;
|
|
128984
|
+
}
|
|
128985
|
+
const needsLandscape = cfg.landscapeLogoImageAssetId?.trim() || cfg.landscapeLogoImageBase64?.trim() || cfg.imagePaths?.landscapeLogo?.trim();
|
|
128986
|
+
if (needsLandscape) {
|
|
128987
|
+
const landscapeCfg = {
|
|
128988
|
+
logoImageAssetId: cfg.landscapeLogoImageAssetId,
|
|
128989
|
+
logoImageBase64: cfg.landscapeLogoImageBase64,
|
|
128990
|
+
imagePaths: cfg.imagePaths?.landscapeLogo ? { logo: cfg.imagePaths.landscapeLogo } : void 0
|
|
128991
|
+
};
|
|
128992
|
+
const slots = await resolvePmaxImageSlots(
|
|
128993
|
+
configFile,
|
|
128994
|
+
landscapeCfg,
|
|
128995
|
+
accountId,
|
|
128996
|
+
config,
|
|
128997
|
+
googleApiUrl,
|
|
128998
|
+
{ verbose, logUploads: false, requiredKinds: ["logo"] }
|
|
128999
|
+
);
|
|
129000
|
+
if (slots.logoImageAssetId) body["landscapeLogoImageAssetId"] = slots.logoImageAssetId;
|
|
129001
|
+
else if (slots.logoImageBase64) body["landscapeLogoImageBase64"] = slots.logoImageBase64;
|
|
129002
|
+
}
|
|
129003
|
+
if (cfg.brandGuidelines && typeof cfg.brandGuidelines === "object") {
|
|
129004
|
+
const style = {};
|
|
129005
|
+
const src = cfg.brandGuidelines;
|
|
129006
|
+
if (src.mainColor?.trim()) style["mainColor"] = src.mainColor.trim();
|
|
129007
|
+
if (src.accentColor?.trim()) style["accentColor"] = src.accentColor.trim();
|
|
129008
|
+
if (src.predefinedFontFamily?.trim()) {
|
|
129009
|
+
style["predefinedFontFamily"] = src.predefinedFontFamily.trim();
|
|
129010
|
+
}
|
|
129011
|
+
if (Object.keys(style).length > 0) body["brandGuidelines"] = style;
|
|
129012
|
+
}
|
|
129013
|
+
return body;
|
|
129014
|
+
}
|
|
129015
|
+
async function buildEnableBrandGuidelinesApiBody(configFile, cfg, accountId, config, googleApiUrl, verbose) {
|
|
129016
|
+
const body = await buildBrandAssetsApiBody(
|
|
129017
|
+
configFile,
|
|
129018
|
+
cfg,
|
|
129019
|
+
accountId,
|
|
129020
|
+
config,
|
|
129021
|
+
googleApiUrl,
|
|
129022
|
+
verbose
|
|
129023
|
+
);
|
|
129024
|
+
if (cfg.autoPopulateBrandAssets === true) {
|
|
129025
|
+
body["autoPopulateBrandAssets"] = true;
|
|
129026
|
+
} else {
|
|
129027
|
+
body["autoPopulateBrandAssets"] = false;
|
|
129028
|
+
}
|
|
129029
|
+
return body;
|
|
129030
|
+
}
|
|
129031
|
+
|
|
127551
129032
|
// src/commands/ad/pmax-create.ts
|
|
127552
129033
|
function printVideoLinkRecoveryHint(accountId, assetGroupId, campaignId, youtubeTarget) {
|
|
127553
129034
|
const cid = campaignId != null ? ` --campaign-id ${campaignId}` : "";
|
|
@@ -127775,6 +129256,49 @@ async function runAdPmaxCreate(opts) {
|
|
|
127775
129256
|
payload["created"] = true;
|
|
127776
129257
|
payload["retryCreate"] = false;
|
|
127777
129258
|
}
|
|
129259
|
+
if (campaignId != null) {
|
|
129260
|
+
let detail;
|
|
129261
|
+
try {
|
|
129262
|
+
detail = await fetchPmaxCampaignDetail(
|
|
129263
|
+
config,
|
|
129264
|
+
googleApiUrl,
|
|
129265
|
+
accountId,
|
|
129266
|
+
String(campaignId),
|
|
129267
|
+
opts.verbose
|
|
129268
|
+
);
|
|
129269
|
+
} catch {
|
|
129270
|
+
detail = void 0;
|
|
129271
|
+
}
|
|
129272
|
+
let liveCountryIds;
|
|
129273
|
+
const plannedCountries = (cfg.targetedLocations ?? []).map((loc) => String(loc.id));
|
|
129274
|
+
if (plannedCountries.length > 0) {
|
|
129275
|
+
try {
|
|
129276
|
+
const params = new URLSearchParams({
|
|
129277
|
+
startDate: toGoogleDate(void 0, -30),
|
|
129278
|
+
endDate: toGoogleDate(void 0, 0),
|
|
129279
|
+
newest: "true"
|
|
129280
|
+
});
|
|
129281
|
+
const listed = await apiFetch2(
|
|
129282
|
+
`${googleApiUrl}/campaignmanagement/v2/targetedlocations/${accountId}?${params}`,
|
|
129283
|
+
config,
|
|
129284
|
+
{},
|
|
129285
|
+
opts.verbose
|
|
129286
|
+
);
|
|
129287
|
+
liveCountryIds = (listed.data ?? []).filter((row) => String(row["campaignId"] ?? row["CampaignId"] ?? "") === String(campaignId)).map((row) => String(row["id"] ?? row["locationId"] ?? row["Id"] ?? "")).filter(Boolean);
|
|
129288
|
+
} catch {
|
|
129289
|
+
liveCountryIds = void 0;
|
|
129290
|
+
}
|
|
129291
|
+
}
|
|
129292
|
+
printPmaxWriteReceipt(
|
|
129293
|
+
{
|
|
129294
|
+
budgetYuan: cfg.budget,
|
|
129295
|
+
finalUrl: cfg.finalUrls?.[0],
|
|
129296
|
+
countryIds: plannedCountries
|
|
129297
|
+
},
|
|
129298
|
+
detail,
|
|
129299
|
+
liveCountryIds
|
|
129300
|
+
);
|
|
129301
|
+
}
|
|
127778
129302
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
127779
129303
|
section: `ad-pmax-create-${accountId}`,
|
|
127780
129304
|
commandLabel: "ad pmax-create",
|
|
@@ -127886,175 +129410,6 @@ async function runAdPmaxValidate(opts) {
|
|
|
127886
129410
|
|
|
127887
129411
|
// src/commands/ad/pmax-mgmt.ts
|
|
127888
129412
|
import { basename as basename7, isAbsolute as isAbsolute6 } from "path";
|
|
127889
|
-
|
|
127890
|
-
// src/commands/ad/pmax-brand-guidelines.ts
|
|
127891
|
-
var PMAX_CAMPAIGN_BRAND_FIELD_TYPES = /* @__PURE__ */ new Set(["BUSINESS_NAME", "LOGO", "LANDSCAPE_LOGO"]);
|
|
127892
|
-
function isPmaxBrandGuidelinesActive(detail) {
|
|
127893
|
-
if (detail["brandGuidelinesEnabled"] === true) return true;
|
|
127894
|
-
const assets = detail["brandAssets"];
|
|
127895
|
-
if (!Array.isArray(assets)) return false;
|
|
127896
|
-
return assets.some((row) => {
|
|
127897
|
-
if (!row || typeof row !== "object") return false;
|
|
127898
|
-
const ft = String(row["fieldType"] ?? "").toUpperCase();
|
|
127899
|
-
return PMAX_CAMPAIGN_BRAND_FIELD_TYPES.has(ft);
|
|
127900
|
-
});
|
|
127901
|
-
}
|
|
127902
|
-
function brandEditAgentHint(bgActive) {
|
|
127903
|
-
return bgActive ? "\u6539\u5546\u5BB6\u540D/Logo/\u6837\u5F0F\uFF1Aad pmax-brand-assets-edit\uFF08\u52FF\u5BF9 AssetGroup \u7528 pmax-assets-update \u6539 BUSINESS_NAME/LOGO\uFF09" : "\u6539\u54C1\u724C\uFF1Aad pmax-assets-update\uFF08AssetGroup \u7EA7\uFF09\uFF1B\u6216 ad pmax-brand-guidelines-enable \u542F\u7528 BG \u540E\u8D70 ad pmax-brand-assets-edit";
|
|
127904
|
-
}
|
|
127905
|
-
function enrichPmaxDetailForAgent(detail) {
|
|
127906
|
-
const bgActive = isPmaxBrandGuidelinesActive(detail);
|
|
127907
|
-
return {
|
|
127908
|
-
...detail,
|
|
127909
|
-
_brandGuidelinesActive: bgActive,
|
|
127910
|
-
_agentBrandHint: brandEditAgentHint(bgActive)
|
|
127911
|
-
};
|
|
127912
|
-
}
|
|
127913
|
-
async function fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaignId, verbose) {
|
|
127914
|
-
const url = pmaxCampaignUrl(googleApiUrl, accountId, campaignId);
|
|
127915
|
-
const raw = await pmaxApiFetch(url, config, {}, verbose);
|
|
127916
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
127917
|
-
return raw;
|
|
127918
|
-
}
|
|
127919
|
-
return { data: raw };
|
|
127920
|
-
}
|
|
127921
|
-
function hasBrandImageSource(cfg, slot) {
|
|
127922
|
-
if (slot === "logo") {
|
|
127923
|
-
return Boolean(
|
|
127924
|
-
cfg.logoImageAssetId?.trim() || cfg.logoImageBase64?.trim() || cfg.imagePaths?.logo?.trim()
|
|
127925
|
-
);
|
|
127926
|
-
}
|
|
127927
|
-
return Boolean(
|
|
127928
|
-
cfg.landscapeLogoImageAssetId?.trim() || cfg.landscapeLogoImageBase64?.trim() || cfg.imagePaths?.landscapeLogo?.trim()
|
|
127929
|
-
);
|
|
127930
|
-
}
|
|
127931
|
-
function validateBrandAssetsPatchBody(cfg, opts) {
|
|
127932
|
-
const errors = [];
|
|
127933
|
-
const style = cfg.brandGuidelines;
|
|
127934
|
-
const hasMain = Boolean(style?.mainColor?.trim());
|
|
127935
|
-
const hasAccent = Boolean(style?.accentColor?.trim());
|
|
127936
|
-
if (hasMain !== hasAccent) {
|
|
127937
|
-
errors.push("brandGuidelines.mainColor \u4E0E accentColor \u987B\u6210\u5BF9\u4F20\u5165");
|
|
127938
|
-
}
|
|
127939
|
-
const hasAny = Boolean(cfg.businessName?.trim()) || hasBrandImageSource(cfg, "logo") || hasBrandImageSource(cfg, "landscapeLogo") || Boolean(style?.predefinedFontFamily?.trim()) || hasMain;
|
|
127940
|
-
if (opts?.requireAtLeastOne !== false && !hasAny) {
|
|
127941
|
-
errors.push(
|
|
127942
|
-
"\u81F3\u5C11\u4F20\u4E00\u9879\uFF1AbusinessName\u3001logoImage*\u3001landscapeLogoImage* \u6216 brandGuidelines \u6837\u5F0F\u5B57\u6BB5"
|
|
127943
|
-
);
|
|
127944
|
-
}
|
|
127945
|
-
return errors;
|
|
127946
|
-
}
|
|
127947
|
-
function validateEnableBrandGuidelinesBody(cfg) {
|
|
127948
|
-
const errors = validateBrandAssetsPatchBody(cfg, {
|
|
127949
|
-
requireAtLeastOne: cfg.autoPopulateBrandAssets !== true
|
|
127950
|
-
});
|
|
127951
|
-
if (cfg.autoPopulateBrandAssets !== true) {
|
|
127952
|
-
if (!cfg.businessName?.trim()) {
|
|
127953
|
-
errors.push("autoPopulateBrandAssets=false \u65F6 businessName \u5FC5\u586B");
|
|
127954
|
-
}
|
|
127955
|
-
if (!hasBrandImageSource(cfg, "logo")) {
|
|
127956
|
-
errors.push("autoPopulateBrandAssets=false \u65F6 Logo\uFF08logoImage* / imagePaths.logo\uFF09\u5FC5\u586B");
|
|
127957
|
-
}
|
|
127958
|
-
}
|
|
127959
|
-
return errors;
|
|
127960
|
-
}
|
|
127961
|
-
function detectAssetGroupBrandLinkBlocked(body, bgActive) {
|
|
127962
|
-
if (!bgActive) return [];
|
|
127963
|
-
const errors = [];
|
|
127964
|
-
const links = body["assetsToLink"];
|
|
127965
|
-
if (Array.isArray(links)) {
|
|
127966
|
-
for (const item of links) {
|
|
127967
|
-
if (!item || typeof item !== "object") continue;
|
|
127968
|
-
const ft = String(item["fieldType"] ?? "").toUpperCase();
|
|
127969
|
-
if (PMAX_CAMPAIGN_BRAND_FIELD_TYPES.has(ft)) {
|
|
127970
|
-
errors.push(
|
|
127971
|
-
`Brand Guidelines \u5DF2\u751F\u6548\uFF0C\u7981\u6B62\u5728 AssetGroup PUT ${ft}\uFF1B\u8BF7\u7528 ad pmax-brand-assets-edit`
|
|
127972
|
-
);
|
|
127973
|
-
}
|
|
127974
|
-
}
|
|
127975
|
-
}
|
|
127976
|
-
const replace = body["replaceFieldTypes"];
|
|
127977
|
-
if (Array.isArray(replace)) {
|
|
127978
|
-
for (const ft of replace) {
|
|
127979
|
-
const upper = String(ft ?? "").toUpperCase();
|
|
127980
|
-
if (PMAX_CAMPAIGN_BRAND_FIELD_TYPES.has(upper)) {
|
|
127981
|
-
errors.push(
|
|
127982
|
-
`Brand Guidelines \u5DF2\u751F\u6548\uFF0CreplaceFieldTypes \u542B ${upper}\uFF1B\u8BF7\u7528 ad pmax-brand-assets-edit`
|
|
127983
|
-
);
|
|
127984
|
-
}
|
|
127985
|
-
}
|
|
127986
|
-
}
|
|
127987
|
-
return errors;
|
|
127988
|
-
}
|
|
127989
|
-
async function buildBrandAssetsApiBody(configFile, cfg, accountId, config, googleApiUrl, verbose) {
|
|
127990
|
-
const body = {};
|
|
127991
|
-
if (cfg.businessName?.trim()) body["businessName"] = cfg.businessName.trim();
|
|
127992
|
-
const logoCfg = {
|
|
127993
|
-
logoImageAssetId: cfg.logoImageAssetId,
|
|
127994
|
-
logoImageBase64: cfg.logoImageBase64,
|
|
127995
|
-
imagePaths: cfg.imagePaths?.logo ? { logo: cfg.imagePaths.logo } : void 0
|
|
127996
|
-
};
|
|
127997
|
-
const needsLogo = cfg.logoImageAssetId?.trim() || cfg.logoImageBase64?.trim() || cfg.imagePaths?.logo?.trim();
|
|
127998
|
-
if (needsLogo) {
|
|
127999
|
-
const slots = await resolvePmaxImageSlots(
|
|
128000
|
-
configFile,
|
|
128001
|
-
logoCfg,
|
|
128002
|
-
accountId,
|
|
128003
|
-
config,
|
|
128004
|
-
googleApiUrl,
|
|
128005
|
-
{ verbose, logUploads: false, requiredKinds: ["logo"] }
|
|
128006
|
-
);
|
|
128007
|
-
if (slots.logoImageAssetId) body["logoImageAssetId"] = slots.logoImageAssetId;
|
|
128008
|
-
else if (slots.logoImageBase64) body["logoImageBase64"] = slots.logoImageBase64;
|
|
128009
|
-
}
|
|
128010
|
-
const needsLandscape = cfg.landscapeLogoImageAssetId?.trim() || cfg.landscapeLogoImageBase64?.trim() || cfg.imagePaths?.landscapeLogo?.trim();
|
|
128011
|
-
if (needsLandscape) {
|
|
128012
|
-
const landscapeCfg = {
|
|
128013
|
-
logoImageAssetId: cfg.landscapeLogoImageAssetId,
|
|
128014
|
-
logoImageBase64: cfg.landscapeLogoImageBase64,
|
|
128015
|
-
imagePaths: cfg.imagePaths?.landscapeLogo ? { logo: cfg.imagePaths.landscapeLogo } : void 0
|
|
128016
|
-
};
|
|
128017
|
-
const slots = await resolvePmaxImageSlots(
|
|
128018
|
-
configFile,
|
|
128019
|
-
landscapeCfg,
|
|
128020
|
-
accountId,
|
|
128021
|
-
config,
|
|
128022
|
-
googleApiUrl,
|
|
128023
|
-
{ verbose, logUploads: false, requiredKinds: ["logo"] }
|
|
128024
|
-
);
|
|
128025
|
-
if (slots.logoImageAssetId) body["landscapeLogoImageAssetId"] = slots.logoImageAssetId;
|
|
128026
|
-
else if (slots.logoImageBase64) body["landscapeLogoImageBase64"] = slots.logoImageBase64;
|
|
128027
|
-
}
|
|
128028
|
-
if (cfg.brandGuidelines && typeof cfg.brandGuidelines === "object") {
|
|
128029
|
-
const style = {};
|
|
128030
|
-
const src = cfg.brandGuidelines;
|
|
128031
|
-
if (src.mainColor?.trim()) style["mainColor"] = src.mainColor.trim();
|
|
128032
|
-
if (src.accentColor?.trim()) style["accentColor"] = src.accentColor.trim();
|
|
128033
|
-
if (src.predefinedFontFamily?.trim()) {
|
|
128034
|
-
style["predefinedFontFamily"] = src.predefinedFontFamily.trim();
|
|
128035
|
-
}
|
|
128036
|
-
if (Object.keys(style).length > 0) body["brandGuidelines"] = style;
|
|
128037
|
-
}
|
|
128038
|
-
return body;
|
|
128039
|
-
}
|
|
128040
|
-
async function buildEnableBrandGuidelinesApiBody(configFile, cfg, accountId, config, googleApiUrl, verbose) {
|
|
128041
|
-
const body = await buildBrandAssetsApiBody(
|
|
128042
|
-
configFile,
|
|
128043
|
-
cfg,
|
|
128044
|
-
accountId,
|
|
128045
|
-
config,
|
|
128046
|
-
googleApiUrl,
|
|
128047
|
-
verbose
|
|
128048
|
-
);
|
|
128049
|
-
if (cfg.autoPopulateBrandAssets === true) {
|
|
128050
|
-
body["autoPopulateBrandAssets"] = true;
|
|
128051
|
-
} else {
|
|
128052
|
-
body["autoPopulateBrandAssets"] = false;
|
|
128053
|
-
}
|
|
128054
|
-
return body;
|
|
128055
|
-
}
|
|
128056
|
-
|
|
128057
|
-
// src/commands/ad/pmax-mgmt.ts
|
|
128058
129413
|
init_shared();
|
|
128059
129414
|
function buildReportQuery(opts) {
|
|
128060
129415
|
const params = new URLSearchParams();
|
|
@@ -128229,6 +129584,23 @@ async function runAdPmaxEdit(opts) {
|
|
|
128229
129584
|
);
|
|
128230
129585
|
process.exit(1);
|
|
128231
129586
|
}
|
|
129587
|
+
let detail;
|
|
129588
|
+
try {
|
|
129589
|
+
detail = await fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaignId, opts.verbose);
|
|
129590
|
+
} catch {
|
|
129591
|
+
detail = void 0;
|
|
129592
|
+
}
|
|
129593
|
+
const budgetCents = body["budget"];
|
|
129594
|
+
const finalUrls = body["finalUrls"];
|
|
129595
|
+
printPmaxWriteReceipt(
|
|
129596
|
+
{
|
|
129597
|
+
name: body["name"] != null ? String(body["name"]) : void 0,
|
|
129598
|
+
budgetYuan: typeof budgetCents === "number" ? budgetCents / 100 : void 0,
|
|
129599
|
+
status: body["statusV2"] != null ? String(body["statusV2"]) : void 0,
|
|
129600
|
+
finalUrl: Array.isArray(finalUrls) ? String(finalUrls[0] ?? "") : void 0
|
|
129601
|
+
},
|
|
129602
|
+
detail
|
|
129603
|
+
);
|
|
128232
129604
|
if (await emitPmaxResult(
|
|
128233
129605
|
{ ...opts, account: accountId },
|
|
128234
129606
|
`ad-pmax-edit-${accountId}`,
|
|
@@ -128356,6 +129728,29 @@ async function runAdPmaxAssetGroupCreate(opts) {
|
|
|
128356
129728
|
);
|
|
128357
129729
|
process.exit(1);
|
|
128358
129730
|
}
|
|
129731
|
+
const createdId = String(data["id"] ?? "");
|
|
129732
|
+
const expectName = String(body["name"] ?? "");
|
|
129733
|
+
let freshAg;
|
|
129734
|
+
if (createdId) {
|
|
129735
|
+
try {
|
|
129736
|
+
const raw = await pmaxApiFetch(
|
|
129737
|
+
pmaxAssetGroupUrl(googleApiUrl, accountId, createdId),
|
|
129738
|
+
config,
|
|
129739
|
+
{},
|
|
129740
|
+
opts.verbose
|
|
129741
|
+
);
|
|
129742
|
+
freshAg = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
|
|
129743
|
+
} catch {
|
|
129744
|
+
freshAg = void 0;
|
|
129745
|
+
}
|
|
129746
|
+
}
|
|
129747
|
+
const agLines = [
|
|
129748
|
+
receiptLine("\u8D44\u4EA7\u7EC4", createdId || "\u5DF2\u521B\u5EFA", freshAg ? String(freshAg["id"] ?? createdId) : void 0)
|
|
129749
|
+
];
|
|
129750
|
+
if (expectName) {
|
|
129751
|
+
agLines.push(receiptLine("\u540D\u79F0", expectName, freshAg?.["name"]));
|
|
129752
|
+
}
|
|
129753
|
+
printWriteReceipt(freshAg ? judgeReceipt(agLines) : "unknown", agLines);
|
|
128359
129754
|
if (await emitPmaxResult(
|
|
128360
129755
|
{ ...opts, account: accountId },
|
|
128361
129756
|
`ad-pmax-asset-group-create-${accountId}`,
|
|
@@ -128411,6 +129806,26 @@ async function runAdPmaxAssetGroupEdit(opts) {
|
|
|
128411
129806
|
);
|
|
128412
129807
|
process.exit(1);
|
|
128413
129808
|
}
|
|
129809
|
+
let freshAg;
|
|
129810
|
+
try {
|
|
129811
|
+
const raw = await pmaxApiFetch(
|
|
129812
|
+
pmaxAssetGroupUrl(googleApiUrl, accountId, assetGroupId),
|
|
129813
|
+
config,
|
|
129814
|
+
{},
|
|
129815
|
+
opts.verbose
|
|
129816
|
+
);
|
|
129817
|
+
freshAg = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
|
|
129818
|
+
} catch {
|
|
129819
|
+
freshAg = void 0;
|
|
129820
|
+
}
|
|
129821
|
+
const agLines = [receiptLine("\u8D44\u4EA7\u7EC4", assetGroupId, freshAg ? assetGroupId : void 0)];
|
|
129822
|
+
if (body["name"] != null) {
|
|
129823
|
+
agLines.push(receiptLine("\u540D\u79F0", String(body["name"]), freshAg?.["name"]));
|
|
129824
|
+
}
|
|
129825
|
+
if (body["status"] != null) {
|
|
129826
|
+
agLines.push(receiptLine("\u72B6\u6001", String(body["status"]), freshAg?.["status"] ?? freshAg?.["statusV2"]));
|
|
129827
|
+
}
|
|
129828
|
+
printWriteReceipt(freshAg ? judgeReceipt(agLines) : "unknown", agLines);
|
|
128414
129829
|
if (await emitPmaxResult(
|
|
128415
129830
|
{ ...opts, account: accountId },
|
|
128416
129831
|
`ad-pmax-asset-group-edit-${accountId}`,
|
|
@@ -128494,6 +129909,20 @@ async function runAdPmaxAssetsUpdate(opts) {
|
|
|
128494
129909
|
);
|
|
128495
129910
|
process.exit(1);
|
|
128496
129911
|
}
|
|
129912
|
+
let freshAg;
|
|
129913
|
+
try {
|
|
129914
|
+
const raw = await pmaxApiFetch(
|
|
129915
|
+
pmaxAssetGroupUrl(googleApiUrl, accountId, assetGroupId),
|
|
129916
|
+
config,
|
|
129917
|
+
{},
|
|
129918
|
+
opts.verbose
|
|
129919
|
+
);
|
|
129920
|
+
freshAg = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
|
|
129921
|
+
} catch {
|
|
129922
|
+
freshAg = void 0;
|
|
129923
|
+
}
|
|
129924
|
+
const lines = [receiptLine("\u8D44\u4EA7\u7EC4", assetGroupId, freshAg ? assetGroupId : void 0)];
|
|
129925
|
+
printWriteReceipt(freshAg ? judgeReceipt(lines) : "unknown", lines);
|
|
128497
129926
|
if (await emitPmaxResult(
|
|
128498
129927
|
{ ...opts, account: accountId },
|
|
128499
129928
|
`ad-pmax-assets-update-${accountId}`,
|
|
@@ -128583,6 +130012,19 @@ async function runAdPmaxYoutubeLink(opts) {
|
|
|
128583
130012
|
);
|
|
128584
130013
|
process.exit(1);
|
|
128585
130014
|
}
|
|
130015
|
+
const assetRes = data["assetResourceName"] ?? data["AssetResourceName"];
|
|
130016
|
+
const ytLines = [
|
|
130017
|
+
receiptLine("\u8D44\u4EA7\u7EC4", assetGroupId, assetGroupId),
|
|
130018
|
+
receiptLine(
|
|
130019
|
+
"YouTube\u8D44\u4EA7",
|
|
130020
|
+
linkedTarget ?? "\u5DF2\u63D0\u4EA4",
|
|
130021
|
+
assetRes != null && String(assetRes).trim() ? String(assetRes) : void 0
|
|
130022
|
+
)
|
|
130023
|
+
];
|
|
130024
|
+
printWriteReceipt(
|
|
130025
|
+
assetRes != null && String(assetRes).trim() ? judgeReceipt(ytLines) : "submitted",
|
|
130026
|
+
ytLines
|
|
130027
|
+
);
|
|
128586
130028
|
if (await emitPmaxResult(
|
|
128587
130029
|
{ ...opts, account: accountId },
|
|
128588
130030
|
`ad-pmax-youtube-link-${accountId}`,
|
|
@@ -128667,6 +130109,32 @@ async function runAdPmaxSignalsSet(opts) {
|
|
|
128667
130109
|
);
|
|
128668
130110
|
process.exit(1);
|
|
128669
130111
|
}
|
|
130112
|
+
let readSignals;
|
|
130113
|
+
try {
|
|
130114
|
+
const raw = await pmaxApiFetch(url, config, {}, opts.verbose);
|
|
130115
|
+
readSignals = raw && typeof raw === "object" && !Array.isArray(raw) ? raw["signals"] : raw;
|
|
130116
|
+
} catch {
|
|
130117
|
+
readSignals = void 0;
|
|
130118
|
+
}
|
|
130119
|
+
const expectThemes = body.searchThemes.join(",");
|
|
130120
|
+
const actualThemes = Array.isArray(readSignals) ? readSignals.map(
|
|
130121
|
+
(row) => row && typeof row === "object" ? String(row["searchThemeText"] ?? "") : ""
|
|
130122
|
+
).filter(Boolean).join(",") : void 0;
|
|
130123
|
+
const expectAudiences = body.audienceResourceNames.length;
|
|
130124
|
+
const actualAudiences = Array.isArray(readSignals) ? readSignals.filter(
|
|
130125
|
+
(row) => row && typeof row === "object" && Boolean(row["audienceResourceName"])
|
|
130126
|
+
).length : void 0;
|
|
130127
|
+
const signalLines = [
|
|
130128
|
+
receiptLine(
|
|
130129
|
+
"\u53D7\u4F17\u4FE1\u53F7\u6570",
|
|
130130
|
+
String(expectAudiences),
|
|
130131
|
+
actualAudiences === void 0 ? void 0 : String(actualAudiences)
|
|
130132
|
+
)
|
|
130133
|
+
];
|
|
130134
|
+
if (expectThemes) {
|
|
130135
|
+
signalLines.push(receiptLine("\u641C\u7D22\u4E3B\u9898", expectThemes, actualThemes));
|
|
130136
|
+
}
|
|
130137
|
+
printWriteReceipt(readSignals === void 0 ? "unknown" : judgeReceipt(signalLines), signalLines);
|
|
128670
130138
|
if (await emitPmaxResult(
|
|
128671
130139
|
{ ...opts, account: accountId },
|
|
128672
130140
|
`ad-pmax-signals-set-${accountId}`,
|
|
@@ -128814,6 +130282,13 @@ async function runAdPmaxImageUpload(opts) {
|
|
|
128814
130282
|
`);
|
|
128815
130283
|
process.exit(1);
|
|
128816
130284
|
}
|
|
130285
|
+
const imageId = data["id"] != null ? String(data["id"]) : "";
|
|
130286
|
+
const imageName = data["name"] != null ? String(data["name"]) : "";
|
|
130287
|
+
const imgLines = [
|
|
130288
|
+
receiptLine("\u56FE\u7247\u8D44\u4EA7", imageId || "\u5DF2\u63D0\u4EA4", imageId || void 0)
|
|
130289
|
+
];
|
|
130290
|
+
if (imageName) imgLines.push(receiptLine("\u540D\u79F0", imageName, imageName));
|
|
130291
|
+
printWriteReceipt(imageId ? judgeReceipt(imgLines) : "submitted", imgLines);
|
|
128817
130292
|
if (await emitPmaxResult(
|
|
128818
130293
|
{ ...opts, account: accountId },
|
|
128819
130294
|
`ad-pmax-image-upload-${accountId}`,
|
|
@@ -129046,7 +130521,7 @@ async function loadSharp() {
|
|
|
129046
130521
|
}
|
|
129047
130522
|
}
|
|
129048
130523
|
async function convertOne(sharpFn, inputPath, outputPath, spec, quality) {
|
|
129049
|
-
let
|
|
130524
|
+
let pipeline = sharpFn(inputPath).resize(spec.width, spec.height, {
|
|
129050
130525
|
fit: spec.fit,
|
|
129051
130526
|
position: "centre",
|
|
129052
130527
|
background: { r: 255, g: 255, b: 255, alpha: 1 },
|
|
@@ -129054,11 +130529,11 @@ async function convertOne(sharpFn, inputPath, outputPath, spec, quality) {
|
|
|
129054
130529
|
});
|
|
129055
130530
|
const ext = extname(outputPath).toLowerCase();
|
|
129056
130531
|
if (ext === ".png") {
|
|
129057
|
-
|
|
130532
|
+
pipeline = pipeline.png({ compressionLevel: 6 });
|
|
129058
130533
|
} else {
|
|
129059
|
-
|
|
130534
|
+
pipeline = pipeline.jpeg({ quality, mozjpeg: true });
|
|
129060
130535
|
}
|
|
129061
|
-
await
|
|
130536
|
+
await pipeline.toFile(outputPath);
|
|
129062
130537
|
}
|
|
129063
130538
|
async function runAdPmaxImageConvert(opts) {
|
|
129064
130539
|
const { input, inputMarketing, inputSquare, inputLogo } = opts;
|
|
@@ -129197,6 +130672,25 @@ async function runAdPmaxBrandAssetsEdit(opts) {
|
|
|
129197
130672
|
);
|
|
129198
130673
|
process.exit(1);
|
|
129199
130674
|
}
|
|
130675
|
+
let detail;
|
|
130676
|
+
try {
|
|
130677
|
+
detail = await fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaignId, opts.verbose);
|
|
130678
|
+
} catch {
|
|
130679
|
+
detail = void 0;
|
|
130680
|
+
}
|
|
130681
|
+
const expectName = cfg.businessName?.trim();
|
|
130682
|
+
const lines = [];
|
|
130683
|
+
if (expectName) {
|
|
130684
|
+
lines.push(receiptLine("\u5546\u5BB6\u540D", expectName, detail?.["businessName"] ?? detail?.["BusinessName"]));
|
|
130685
|
+
}
|
|
130686
|
+
lines.push(
|
|
130687
|
+
receiptLine(
|
|
130688
|
+
"Brand Guidelines",
|
|
130689
|
+
"\u5DF2\u751F\u6548",
|
|
130690
|
+
detail ? isPmaxBrandGuidelinesActive(detail) ? "\u5DF2\u751F\u6548" : "\u672A\u751F\u6548" : void 0
|
|
130691
|
+
)
|
|
130692
|
+
);
|
|
130693
|
+
printWriteReceipt(detail ? judgeReceipt(lines) : "unknown", lines);
|
|
129200
130694
|
if (await emitPmaxResult(
|
|
129201
130695
|
{ ...opts, account: accountId },
|
|
129202
130696
|
`ad-pmax-brand-assets-edit-${accountId}`,
|
|
@@ -129257,6 +130751,21 @@ async function runAdPmaxBrandGuidelinesEnable(opts) {
|
|
|
129257
130751
|
);
|
|
129258
130752
|
process.exit(1);
|
|
129259
130753
|
}
|
|
130754
|
+
let detail;
|
|
130755
|
+
try {
|
|
130756
|
+
detail = await fetchPmaxCampaignDetail(config, googleApiUrl, accountId, campaignId, opts.verbose);
|
|
130757
|
+
} catch {
|
|
130758
|
+
detail = void 0;
|
|
130759
|
+
}
|
|
130760
|
+
const active = detail ? isPmaxBrandGuidelinesActive(detail) : void 0;
|
|
130761
|
+
const lines = [
|
|
130762
|
+
receiptLine(
|
|
130763
|
+
"Brand Guidelines",
|
|
130764
|
+
"\u5DF2\u542F\u7528",
|
|
130765
|
+
active === void 0 ? void 0 : active ? "\u5DF2\u542F\u7528" : "\u672A\u542F\u7528"
|
|
130766
|
+
)
|
|
130767
|
+
];
|
|
130768
|
+
printWriteReceipt(detail ? judgeReceipt(lines) : "unknown", lines);
|
|
129260
130769
|
if (await emitPmaxResult(
|
|
129261
130770
|
{ ...opts, account: accountId },
|
|
129262
130771
|
`ad-pmax-brand-guidelines-enable-${accountId}`,
|
|
@@ -129478,6 +130987,35 @@ function budgetYuan(item) {
|
|
|
129478
130987
|
const yuan = toDisplayMoney(typeof raw === "number" ? raw : Number(raw));
|
|
129479
130988
|
return yuan == null ? "" : String(yuan);
|
|
129480
130989
|
}
|
|
130990
|
+
async function printSharedBudgetReceipt(opts, expected) {
|
|
130991
|
+
try {
|
|
130992
|
+
const listed = await listBudgets(opts);
|
|
130993
|
+
const item = expected.id ? listed.items.find((row) => field5(row, "id", "Id") === expected.id) : listed.items.find((row) => field5(row, "name", "Name") === (expected.name ?? ""));
|
|
130994
|
+
if (expected.gone) {
|
|
130995
|
+
printWriteReceipt(item ? "partial" : "verified", [
|
|
130996
|
+
receiptLine("\u5171\u4EAB\u9884\u7B97", "\u5DF2\u5220\u9664", item ? "\u4ECD\u5728" : "\u5DF2\u5220\u9664")
|
|
130997
|
+
]);
|
|
130998
|
+
return;
|
|
130999
|
+
}
|
|
131000
|
+
const lines = [];
|
|
131001
|
+
if (expected.name) {
|
|
131002
|
+
lines.push(receiptLine("\u540D\u79F0", expected.name, item ? field5(item, "name", "Name") : void 0));
|
|
131003
|
+
}
|
|
131004
|
+
if (expected.amountYuan != null) {
|
|
131005
|
+
const read = item ? Number(budgetYuan(item)) : void 0;
|
|
131006
|
+
lines.push(
|
|
131007
|
+
receiptLine(
|
|
131008
|
+
"\u65E5\u9884\u7B97",
|
|
131009
|
+
yuanLabel(expected.amountYuan),
|
|
131010
|
+
read != null && Number.isFinite(read) ? yuanLabel(read) : void 0
|
|
131011
|
+
)
|
|
131012
|
+
);
|
|
131013
|
+
}
|
|
131014
|
+
printWriteReceipt(item ? judgeReceipt(lines) : "unknown", lines);
|
|
131015
|
+
} catch {
|
|
131016
|
+
printWriteReceipt("unknown", [receiptLine("\u5171\u4EAB\u9884\u7B97", expected.gone ? "\u5DF2\u5220\u9664" : "\u5DF2\u5199\u5165", void 0)]);
|
|
131017
|
+
}
|
|
131018
|
+
}
|
|
129481
131019
|
async function runAdSharedBudgetList(opts) {
|
|
129482
131020
|
let items3;
|
|
129483
131021
|
let account = opts.account;
|
|
@@ -129533,6 +131071,7 @@ async function runAdSharedBudgetCreate(opts) {
|
|
|
129533
131071
|
} catch (err) {
|
|
129534
131072
|
fail3(err, "\u521B\u5EFA\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
129535
131073
|
}
|
|
131074
|
+
await printSharedBudgetReceipt(opts, { name: name2, amountYuan: opts.amount });
|
|
129536
131075
|
console.log(`
|
|
129537
131076
|
\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
|
|
129538
131077
|
`);
|
|
@@ -129573,6 +131112,11 @@ async function runAdSharedBudgetUpdate(opts) {
|
|
|
129573
131112
|
} catch (err) {
|
|
129574
131113
|
fail3(err, "\u4FEE\u6539\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
129575
131114
|
}
|
|
131115
|
+
await printSharedBudgetReceipt(opts, {
|
|
131116
|
+
id: budgetId,
|
|
131117
|
+
name: name2,
|
|
131118
|
+
amountYuan: amountCents / 100
|
|
131119
|
+
});
|
|
129576
131120
|
console.log(`
|
|
129577
131121
|
\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
|
|
129578
131122
|
`);
|
|
@@ -129592,6 +131136,21 @@ async function runAdSharedBudgetAttach(opts) {
|
|
|
129592
131136
|
} catch (err) {
|
|
129593
131137
|
fail3(err, "\u628A\u7CFB\u5217\u6302\u5230\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
129594
131138
|
}
|
|
131139
|
+
let actualBudget;
|
|
131140
|
+
try {
|
|
131141
|
+
const detail = await apiFetch2(
|
|
131142
|
+
`${base2}/campaignmanagement/campaign/${account}/${campaignId}`,
|
|
131143
|
+
config,
|
|
131144
|
+
{},
|
|
131145
|
+
opts.verbose
|
|
131146
|
+
);
|
|
131147
|
+
const row = detail["data"] ?? detail;
|
|
131148
|
+
actualBudget = field5(row, "budgetId", "BudgetId", "campaignBudgetId", "CampaignBudgetId") || void 0;
|
|
131149
|
+
} catch {
|
|
131150
|
+
actualBudget = void 0;
|
|
131151
|
+
}
|
|
131152
|
+
const lines = [receiptLine("\u5171\u4EAB\u9884\u7B97", budgetId, actualBudget)];
|
|
131153
|
+
printWriteReceipt(actualBudget === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
129595
131154
|
console.log(`
|
|
129596
131155
|
\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
131156
|
`);
|
|
@@ -129607,6 +131166,7 @@ async function runAdSharedBudgetDelete(opts) {
|
|
|
129607
131166
|
} catch (err) {
|
|
129608
131167
|
fail3(err, "\u5220\u9664\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
129609
131168
|
}
|
|
131169
|
+
await printSharedBudgetReceipt(opts, { id: budgetId, gone: true });
|
|
129610
131170
|
console.log(`
|
|
129611
131171
|
\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
|
|
129612
131172
|
`);
|
|
@@ -129676,6 +131236,35 @@ async function runAdAudienceAdd(opts) {
|
|
|
129676
131236
|
} catch (err) {
|
|
129677
131237
|
fail3(err, "\u6DFB\u52A0\u53D7\u4F17\u5931\u8D25");
|
|
129678
131238
|
}
|
|
131239
|
+
const target = (opts.target ?? "").trim();
|
|
131240
|
+
let present;
|
|
131241
|
+
try {
|
|
131242
|
+
const group = await findItemInList(
|
|
131243
|
+
adgroupListUrl(base2, account, void 0, void 0, true),
|
|
131244
|
+
config,
|
|
131245
|
+
(opts.adGroupId ?? "").trim(),
|
|
131246
|
+
opts.verbose
|
|
131247
|
+
);
|
|
131248
|
+
const campaignId = field5(group, "campaignId", "CampaignId");
|
|
131249
|
+
if (campaignId) {
|
|
131250
|
+
const params = new URLSearchParams({ campaignId, adgroupId: (opts.adGroupId ?? "").trim() });
|
|
131251
|
+
const listed = asRows(
|
|
131252
|
+
await apiFetch2(
|
|
131253
|
+
`${base2}/adgroupnmanagement/bidmodifiers/${account}/${spec.listType}?${params}`,
|
|
131254
|
+
config,
|
|
131255
|
+
{},
|
|
131256
|
+
opts.verbose
|
|
131257
|
+
)
|
|
131258
|
+
);
|
|
131259
|
+
present = payloadHasExact(listed, target);
|
|
131260
|
+
}
|
|
131261
|
+
} catch {
|
|
131262
|
+
present = void 0;
|
|
131263
|
+
}
|
|
131264
|
+
const lines = [
|
|
131265
|
+
receiptLine("\u53D7\u4F17", target, present === void 0 ? void 0 : present ? target : "\u672A\u627E\u5230")
|
|
131266
|
+
];
|
|
131267
|
+
printWriteReceipt(present === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
129679
131268
|
console.log(`
|
|
129680
131269
|
\u2705 \u5DF2\u5728\u5E7F\u544A\u7EC4 ${opts.adGroupId} \u6DFB\u52A0 ${kind}\uFF1A${opts.target}${opts.negative ? "\uFF08\u5426\u5B9A\uFF09" : ""}
|
|
129681
131270
|
`);
|
|
@@ -129697,6 +131286,16 @@ async function runAdScheduleReplace(opts) {
|
|
|
129697
131286
|
} catch (err) {
|
|
129698
131287
|
fail3(err, "\u66FF\u6362\u6295\u653E\u65F6\u6BB5\u5931\u8D25");
|
|
129699
131288
|
}
|
|
131289
|
+
const expectedCount = String(schedules.length);
|
|
131290
|
+
let actualCount;
|
|
131291
|
+
try {
|
|
131292
|
+
const readBack = asRows(await apiFetch2(url, config, {}, opts.verbose));
|
|
131293
|
+
actualCount = String(readBack.length);
|
|
131294
|
+
} catch {
|
|
131295
|
+
actualCount = void 0;
|
|
131296
|
+
}
|
|
131297
|
+
const lines = [receiptLine("\u6295\u653E\u65F6\u6BB5\u6761\u6570", expectedCount, actualCount)];
|
|
131298
|
+
printWriteReceipt(actualCount === void 0 ? "submitted" : judgeReceipt(lines), lines);
|
|
129700
131299
|
console.log(
|
|
129701
131300
|
schedules.length === 0 ? `
|
|
129702
131301
|
\u2705 \u5DF2\u6E05\u7A7A\u7CFB\u5217 ${campaignId} \u7684\u6295\u653E\u65F6\u6BB5\u3002
|
|
@@ -129706,6 +131305,9 @@ async function runAdScheduleReplace(opts) {
|
|
|
129706
131305
|
);
|
|
129707
131306
|
}
|
|
129708
131307
|
|
|
131308
|
+
// src/commands/ad/demand-gen.ts
|
|
131309
|
+
init_shared();
|
|
131310
|
+
|
|
129709
131311
|
// src/commands/ad/demand-gen-body.ts
|
|
129710
131312
|
init_shared();
|
|
129711
131313
|
var WRITE_CENT_KEYS = ["budget", "targetCpa_BidingAmount", "currencyMinimumBudget"];
|
|
@@ -129941,7 +131543,6 @@ function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDat
|
|
|
129941
131543
|
}
|
|
129942
131544
|
|
|
129943
131545
|
// src/commands/ad/demand-gen.ts
|
|
129944
|
-
init_shared();
|
|
129945
131546
|
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";
|
|
129946
131547
|
function fail4(message) {
|
|
129947
131548
|
console.error(`
|
|
@@ -129949,6 +131550,73 @@ function fail4(message) {
|
|
|
129949
131550
|
`);
|
|
129950
131551
|
process.exit(1);
|
|
129951
131552
|
}
|
|
131553
|
+
async function readLocationIds(config, googleApiUrl, accountId, campaignId, verbose) {
|
|
131554
|
+
try {
|
|
131555
|
+
const params = new URLSearchParams({
|
|
131556
|
+
startDate: toGoogleDate(void 0, -30),
|
|
131557
|
+
endDate: toGoogleDate(void 0, 0),
|
|
131558
|
+
newest: "true"
|
|
131559
|
+
});
|
|
131560
|
+
const listed = await pmaxApiFetch(
|
|
131561
|
+
`${googleApiUrl}/campaignmanagement/v2/targetedlocations/${accountId}?${params}`,
|
|
131562
|
+
config,
|
|
131563
|
+
{},
|
|
131564
|
+
verbose
|
|
131565
|
+
);
|
|
131566
|
+
const rows = listed && typeof listed === "object" && Array.isArray(listed.data) ? listed.data : [];
|
|
131567
|
+
return rows.filter((row) => String(row["campaignId"] ?? "") === campaignId).map((row) => String(row["id"] ?? row["locationId"] ?? "")).filter(Boolean);
|
|
131568
|
+
} catch {
|
|
131569
|
+
return void 0;
|
|
131570
|
+
}
|
|
131571
|
+
}
|
|
131572
|
+
function plannedLocationIds2(value) {
|
|
131573
|
+
if (!Array.isArray(value)) return [];
|
|
131574
|
+
return value.map((item) => {
|
|
131575
|
+
if (typeof item === "string" || typeof item === "number") return String(item);
|
|
131576
|
+
if (item && typeof item === "object") {
|
|
131577
|
+
const id = item["id"] ?? item["Id"];
|
|
131578
|
+
return id == null ? "" : String(id);
|
|
131579
|
+
}
|
|
131580
|
+
return "";
|
|
131581
|
+
}).filter(Boolean);
|
|
131582
|
+
}
|
|
131583
|
+
async function printDemandGenCampaignReceipt(config, googleApiUrl, accountId, campaignId, expected, verbose) {
|
|
131584
|
+
let detail;
|
|
131585
|
+
try {
|
|
131586
|
+
detail = asRecord5(
|
|
131587
|
+
decorateDemandGenRead(
|
|
131588
|
+
await pmaxApiFetch(demandGenCampaignUrl(googleApiUrl, accountId, campaignId), config, {}, verbose)
|
|
131589
|
+
)
|
|
131590
|
+
);
|
|
131591
|
+
} catch {
|
|
131592
|
+
detail = void 0;
|
|
131593
|
+
}
|
|
131594
|
+
const lines = [];
|
|
131595
|
+
if (expected.budgetCents != null) {
|
|
131596
|
+
const actual = typeof detail?.["budgetYuan"] === "number" ? detail["budgetYuan"] : void 0;
|
|
131597
|
+
lines.push(
|
|
131598
|
+
receiptLine(
|
|
131599
|
+
"\u65E5\u9884\u7B97",
|
|
131600
|
+
yuanLabel(expected.budgetCents / 100),
|
|
131601
|
+
actual == null ? void 0 : yuanLabel(actual)
|
|
131602
|
+
)
|
|
131603
|
+
);
|
|
131604
|
+
}
|
|
131605
|
+
if (expected.status) {
|
|
131606
|
+
lines.push(receiptLine("\u72B6\u6001", expected.status, detail?.["statusV2"]));
|
|
131607
|
+
}
|
|
131608
|
+
if (expected.countryIds && expected.countryIds.length > 0) {
|
|
131609
|
+
const live = detail ? await readLocationIds(config, googleApiUrl, accountId, campaignId, verbose) : void 0;
|
|
131610
|
+
lines.push(
|
|
131611
|
+
receiptLine(
|
|
131612
|
+
"\u6295\u653E\u56FD\u5BB6",
|
|
131613
|
+
[...expected.countryIds].sort().join(","),
|
|
131614
|
+
live ? [...live].sort().join(",") : void 0
|
|
131615
|
+
)
|
|
131616
|
+
);
|
|
131617
|
+
}
|
|
131618
|
+
printWriteReceipt(detail ? judgeReceipt(lines) : "unknown", lines);
|
|
131619
|
+
}
|
|
129952
131620
|
function asRecord5(value) {
|
|
129953
131621
|
return value && typeof value === "object" && !Array.isArray(value) ? value : { data: value };
|
|
129954
131622
|
}
|
|
@@ -130062,6 +131730,27 @@ async function postCreate(opts, path61, commandLabel) {
|
|
|
130062
131730
|
fail4(explainCreateError(err));
|
|
130063
131731
|
}
|
|
130064
131732
|
const payload = decorateDemandGenRead(data);
|
|
131733
|
+
if (path61 !== "validate") {
|
|
131734
|
+
const created = asRecord5(payload);
|
|
131735
|
+
const createdId = String(created["id"] ?? created["campaignId"] ?? "");
|
|
131736
|
+
const countries = plannedLocationIds2(body["targetedLocations"]);
|
|
131737
|
+
if (createdId) {
|
|
131738
|
+
await printDemandGenCampaignReceipt(
|
|
131739
|
+
config,
|
|
131740
|
+
googleApiUrl,
|
|
131741
|
+
accountId,
|
|
131742
|
+
createdId,
|
|
131743
|
+
{
|
|
131744
|
+
budgetCents: typeof body["budget"] === "number" ? body["budget"] : void 0,
|
|
131745
|
+
status: "Paused",
|
|
131746
|
+
countryIds: countries
|
|
131747
|
+
},
|
|
131748
|
+
opts.verbose
|
|
131749
|
+
);
|
|
131750
|
+
} else {
|
|
131751
|
+
printWriteReceipt("unknown", [receiptLine("\u7CFB\u5217", "\u5DF2\u521B\u5EFA", void 0)]);
|
|
131752
|
+
}
|
|
131753
|
+
}
|
|
130065
131754
|
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path61 || "create"}`, commandLabel, payload, accountId)) {
|
|
130066
131755
|
return;
|
|
130067
131756
|
}
|
|
@@ -130298,6 +131987,18 @@ async function runDemandGenEdit(opts) {
|
|
|
130298
131987
|
} catch (err) {
|
|
130299
131988
|
fail4(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130300
131989
|
}
|
|
131990
|
+
await printDemandGenCampaignReceipt(
|
|
131991
|
+
config,
|
|
131992
|
+
googleApiUrl,
|
|
131993
|
+
accountId,
|
|
131994
|
+
campaignId,
|
|
131995
|
+
{
|
|
131996
|
+
budgetCents: typeof body["budget"] === "number" ? body["budget"] : void 0,
|
|
131997
|
+
status: typeof body["statusV2"] === "string" ? body["statusV2"] : void 0,
|
|
131998
|
+
countryIds: plannedLocationIds2(body["targetedLocations"])
|
|
131999
|
+
},
|
|
132000
|
+
opts.verbose
|
|
132001
|
+
);
|
|
130301
132002
|
const payload = { ok: true, campaignId, patch: body };
|
|
130302
132003
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-edit", "ad demand-gen edit", payload, campaignId)) {
|
|
130303
132004
|
return;
|
|
@@ -130330,6 +132031,15 @@ async function runDemandGenContent(opts) {
|
|
|
130330
132031
|
} catch (err) {
|
|
130331
132032
|
fail4(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130332
132033
|
}
|
|
132034
|
+
const readUrl2 = opts.adId?.trim() ? demandGenAdUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), opts.adId.trim()) : demandGenAdGroupUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim());
|
|
132035
|
+
let fresh;
|
|
132036
|
+
try {
|
|
132037
|
+
fresh = asRecord5(await pmaxApiFetch(readUrl2, config, {}, opts.verbose));
|
|
132038
|
+
} catch {
|
|
132039
|
+
fresh = void 0;
|
|
132040
|
+
}
|
|
132041
|
+
const contentLines = [receiptLine("\u5185\u5BB9", "\u5DF2\u5199\u5165", fresh ? "\u53EF\u8BFB" : void 0)];
|
|
132042
|
+
printWriteReceipt(fresh ? judgeReceipt(contentLines) : "unknown", contentLines);
|
|
130333
132043
|
const payload = { ok: true, campaignId: opts.campaignId, adGroupId: opts.adGroupId, adId: opts.adId ?? null };
|
|
130334
132044
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-content", "ad demand-gen content", payload)) return;
|
|
130335
132045
|
console.log("\n\u2705 \u5E7F\u544A\u5185\u5BB9\u5DF2\u66F4\u65B0\u3002\u6539\u5B8C\u7528 demand-gen get \u8BFB\u56DE\u3002waitForReview \u65F6\u4E0D\u8981\u518D\u6539\u6587\u6848\u3002\n");
|
|
@@ -130401,6 +132111,16 @@ async function putStatus(opts, kind) {
|
|
|
130401
132111
|
} catch (err) {
|
|
130402
132112
|
fail4(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130403
132113
|
}
|
|
132114
|
+
let readStatus;
|
|
132115
|
+
try {
|
|
132116
|
+
const readUrl2 = url.replace(/\/status$/, "");
|
|
132117
|
+
const raw = asRecord5(await pmaxApiFetch(readUrl2, config, {}, opts.verbose));
|
|
132118
|
+
readStatus = raw["status"] ?? raw["statusV2"];
|
|
132119
|
+
} catch {
|
|
132120
|
+
readStatus = void 0;
|
|
132121
|
+
}
|
|
132122
|
+
const lines = [receiptLine("\u72B6\u6001", status, readStatus)];
|
|
132123
|
+
printWriteReceipt(readStatus === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
130404
132124
|
console.log(`
|
|
130405
132125
|
\u2705 \u5DF2\u8BBE\u4E3A ${status}\u3002\u7CFB\u5217\u72B6\u6001\u4E0D\u4F1A\u8DDF\u7740\u53D8\u3002
|
|
130406
132126
|
`);
|
|
@@ -130429,6 +132149,22 @@ async function runDemandGenAdGroupRename(opts) {
|
|
|
130429
132149
|
} catch (err) {
|
|
130430
132150
|
fail4(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130431
132151
|
}
|
|
132152
|
+
let freshName;
|
|
132153
|
+
try {
|
|
132154
|
+
const raw = asRecord5(
|
|
132155
|
+
await pmaxApiFetch(
|
|
132156
|
+
demandGenAdGroupUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim()),
|
|
132157
|
+
config,
|
|
132158
|
+
{},
|
|
132159
|
+
opts.verbose
|
|
132160
|
+
)
|
|
132161
|
+
);
|
|
132162
|
+
freshName = raw["name"] ?? raw["Name"];
|
|
132163
|
+
} catch {
|
|
132164
|
+
freshName = void 0;
|
|
132165
|
+
}
|
|
132166
|
+
const lines = [receiptLine("\u540D\u79F0", name2, freshName)];
|
|
132167
|
+
printWriteReceipt(freshName === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
130432
132168
|
console.log(`
|
|
130433
132169
|
\u2705 \u5E7F\u544A\u7EC4\u5DF2\u6539\u540D\u4E3A ${name2}
|
|
130434
132170
|
`);
|
|
@@ -130458,6 +132194,15 @@ async function runDemandGenAudience(opts) {
|
|
|
130458
132194
|
} catch (err) {
|
|
130459
132195
|
fail4(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130460
132196
|
}
|
|
132197
|
+
let actualAudience;
|
|
132198
|
+
try {
|
|
132199
|
+
const raw = asRecord5(await pmaxApiFetch(url, config, {}, opts.verbose));
|
|
132200
|
+
actualAudience = raw["audienceResourceName"] ?? raw["AudienceResourceName"];
|
|
132201
|
+
} catch {
|
|
132202
|
+
actualAudience = void 0;
|
|
132203
|
+
}
|
|
132204
|
+
const lines = [receiptLine("\u53D7\u4F17", audienceResourceName, actualAudience)];
|
|
132205
|
+
printWriteReceipt(actualAudience === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
130461
132206
|
console.log("\n\u2705 \u5E7F\u544A\u7EC4\u53D7\u4F17\u5DF2\u66FF\u6362\u3002\u4E00\u4E2A\u5E7F\u544A\u7EC4\u53EA\u80FD\u7ED1\u4E00\u4E2A Audience\u3002\n");
|
|
130462
132207
|
});
|
|
130463
132208
|
}
|
|
@@ -130542,6 +132287,17 @@ async function runDemandGenDeleteAd(opts) {
|
|
|
130542
132287
|
} catch (err) {
|
|
130543
132288
|
fail4(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130544
132289
|
}
|
|
132290
|
+
let gone = false;
|
|
132291
|
+
let still = false;
|
|
132292
|
+
try {
|
|
132293
|
+
await pmaxApiFetch(url, config, {}, opts.verbose);
|
|
132294
|
+
still = true;
|
|
132295
|
+
} catch {
|
|
132296
|
+
gone = true;
|
|
132297
|
+
}
|
|
132298
|
+
printWriteReceipt(gone ? "verified" : still ? "partial" : "unknown", [
|
|
132299
|
+
receiptLine("\u5E7F\u544A", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : still ? "\u4ECD\u5728" : void 0)
|
|
132300
|
+
]);
|
|
130545
132301
|
console.log("\n\u2705 \u5E7F\u544A\u5DF2\u5220\u9664\n");
|
|
130546
132302
|
});
|
|
130547
132303
|
}
|
|
@@ -130563,6 +132319,17 @@ async function runDemandGenDeleteAdGroup(opts) {
|
|
|
130563
132319
|
} catch (err) {
|
|
130564
132320
|
fail4(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
130565
132321
|
}
|
|
132322
|
+
let gone = false;
|
|
132323
|
+
let still = false;
|
|
132324
|
+
try {
|
|
132325
|
+
await pmaxApiFetch(url, config, {}, opts.verbose);
|
|
132326
|
+
still = true;
|
|
132327
|
+
} catch {
|
|
132328
|
+
gone = true;
|
|
132329
|
+
}
|
|
132330
|
+
printWriteReceipt(gone ? "verified" : still ? "partial" : "unknown", [
|
|
132331
|
+
receiptLine("\u5E7F\u544A\u7EC4", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : still ? "\u4ECD\u5728" : void 0)
|
|
132332
|
+
]);
|
|
130566
132333
|
console.log("\n\u2705 \u5E7F\u544A\u7EC4\u5DF2\u5220\u9664\n");
|
|
130567
132334
|
});
|
|
130568
132335
|
}
|
|
@@ -130754,6 +132521,10 @@ async function postCoverage(opts, path61, section, commandLabel) {
|
|
|
130754
132521
|
} catch (err) {
|
|
130755
132522
|
fail5(err instanceof Error ? err.message : String(err));
|
|
130756
132523
|
}
|
|
132524
|
+
const kindLabel = String(body["kind"] ?? (kind || path61 || "coverage"));
|
|
132525
|
+
printWriteReceipt("submitted", [
|
|
132526
|
+
receiptLine("\u8986\u76D6\u5199\u64CD\u4F5C", kindLabel, kindLabel)
|
|
132527
|
+
]);
|
|
130757
132528
|
await emitPmaxResult({ ...opts, account: accountId }, section, commandLabel, data, accountId);
|
|
130758
132529
|
});
|
|
130759
132530
|
}
|
|
@@ -133107,6 +134878,52 @@ function formHasPredefinedQuestion(form) {
|
|
|
133107
134878
|
return (form.questions ?? []).some((q) => isPredefinedQuestionType(q.type));
|
|
133108
134879
|
}
|
|
133109
134880
|
|
|
134881
|
+
// src/commands/meta-ad/readback.ts
|
|
134882
|
+
init_auth();
|
|
134883
|
+
async function tryReadMeta(facebookApiUrl, account, path61, config, verbose) {
|
|
134884
|
+
try {
|
|
134885
|
+
const data = await apiFetch2(adsUrl(facebookApiUrl, account, path61), config, {}, verbose);
|
|
134886
|
+
if (data && typeof data === "object" && !Array.isArray(data)) return data;
|
|
134887
|
+
return void 0;
|
|
134888
|
+
} catch {
|
|
134889
|
+
return void 0;
|
|
134890
|
+
}
|
|
134891
|
+
}
|
|
134892
|
+
function countriesOf(row) {
|
|
134893
|
+
const targeting = row?.["targeting"];
|
|
134894
|
+
if (!targeting || typeof targeting !== "object") return void 0;
|
|
134895
|
+
const geo = targeting["geo_locations"];
|
|
134896
|
+
if (!geo || typeof geo !== "object") return void 0;
|
|
134897
|
+
const countries = geo["countries"];
|
|
134898
|
+
if (!Array.isArray(countries)) return void 0;
|
|
134899
|
+
return countries.map((item) => String(item).toUpperCase()).sort().join(",");
|
|
134900
|
+
}
|
|
134901
|
+
function printMetaObjectReceipt(expected, row) {
|
|
134902
|
+
const lines = [];
|
|
134903
|
+
if (expected.status) {
|
|
134904
|
+
lines.push(receiptLine("\u72B6\u6001", expected.status, row?.["status"]));
|
|
134905
|
+
}
|
|
134906
|
+
if (expected.dailyBudget) {
|
|
134907
|
+
lines.push(receiptLine("\u65E5\u9884\u7B97", expected.dailyBudget, row?.["daily_budget"]));
|
|
134908
|
+
}
|
|
134909
|
+
if (expected.countries && expected.countries.length > 0) {
|
|
134910
|
+
lines.push(
|
|
134911
|
+
receiptLine(
|
|
134912
|
+
"\u56FD\u5BB6",
|
|
134913
|
+
expected.countries.map((item) => item.toUpperCase()).sort().join(","),
|
|
134914
|
+
countriesOf(row)
|
|
134915
|
+
)
|
|
134916
|
+
);
|
|
134917
|
+
}
|
|
134918
|
+
if (expected.link) {
|
|
134919
|
+
const spec = row?.["object_story_spec"];
|
|
134920
|
+
const linkData = spec && typeof spec === "object" ? spec["link_data"] : void 0;
|
|
134921
|
+
const link = linkData && typeof linkData === "object" ? linkData["link"] : row?.["link"];
|
|
134922
|
+
lines.push(receiptLine("\u843D\u5730\u9875", expected.link, link));
|
|
134923
|
+
}
|
|
134924
|
+
printWriteReceipt(row ? judgeReceipt(lines) : "unknown", lines);
|
|
134925
|
+
}
|
|
134926
|
+
|
|
133110
134927
|
// src/commands/meta-ad/load.ts
|
|
133111
134928
|
import { readFileSync as readFileSync16 } from "fs";
|
|
133112
134929
|
function stripMetaKeys2(value) {
|
|
@@ -133209,6 +135026,22 @@ async function runMetaAdImageUpload(opts) {
|
|
|
133209
135026
|
);
|
|
133210
135027
|
const hash = extractImageHash(data);
|
|
133211
135028
|
const payload = { ...data, hash, name: data.name ?? name2 };
|
|
135029
|
+
if (hash) {
|
|
135030
|
+
const read = await tryReadMeta(
|
|
135031
|
+
facebookApiUrl,
|
|
135032
|
+
digits,
|
|
135033
|
+
`/images?hashes=${encodeURIComponent(hash)}`,
|
|
135034
|
+
config,
|
|
135035
|
+
opts.verbose
|
|
135036
|
+
);
|
|
135037
|
+
const images = read?.["images"];
|
|
135038
|
+
const hit = images && typeof images === "object" && !Array.isArray(images) ? images[hash] : void 0;
|
|
135039
|
+
const actualHash = hit && typeof hit === "object" ? String(hit["hash"] ?? hash) : void 0;
|
|
135040
|
+
const lines = [receiptLine("hash", hash, hit ? actualHash : read ? "\u672A\u627E\u5230" : void 0)];
|
|
135041
|
+
printWriteReceipt(read ? judgeReceipt(lines) : "unknown", lines);
|
|
135042
|
+
} else {
|
|
135043
|
+
printWriteReceipt("submitted", [receiptLine("hash", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 hash\uFF09")]);
|
|
135044
|
+
}
|
|
133212
135045
|
if (await emitMetaJson(opts, "meta-ad-image-upload", "meta-ad image-upload", payload, digits)) {
|
|
133213
135046
|
return;
|
|
133214
135047
|
}
|
|
@@ -133758,6 +135591,29 @@ async function runMetaAdCreate(opts) {
|
|
|
133758
135591
|
process.exit(1);
|
|
133759
135592
|
}
|
|
133760
135593
|
progress.ok = true;
|
|
135594
|
+
const [campaignRow, adsetRow, creativeRow, adRow] = await Promise.all([
|
|
135595
|
+
progress.campaignId ? tryReadMeta(facebookApiUrl, digits, `/campaigns/${progress.campaignId}`, config, opts.verbose) : Promise.resolve(void 0),
|
|
135596
|
+
progress.adSetId ? tryReadMeta(facebookApiUrl, digits, `/adsets/${progress.adSetId}`, config, opts.verbose) : Promise.resolve(void 0),
|
|
135597
|
+
progress.creativeId ? tryReadMeta(facebookApiUrl, digits, `/adcreatives/${progress.creativeId}`, config, opts.verbose) : Promise.resolve(void 0),
|
|
135598
|
+
progress.adId ? tryReadMeta(facebookApiUrl, digits, `/ads/${progress.adId}`, config, opts.verbose) : Promise.resolve(void 0)
|
|
135599
|
+
]);
|
|
135600
|
+
const daily = cfg.adset.dailyBudget != null ? toMinorUnitString(cfg.adset.dailyBudget, currency) : void 0;
|
|
135601
|
+
printMetaObjectReceipt(
|
|
135602
|
+
{
|
|
135603
|
+
status: "PAUSED",
|
|
135604
|
+
dailyBudget: daily,
|
|
135605
|
+
countries: cfg.adset.countries,
|
|
135606
|
+
link: cfg.creative.link
|
|
135607
|
+
},
|
|
135608
|
+
adsetRow ? { ...adsetRow, ...creativeRow ?? {} } : void 0
|
|
135609
|
+
);
|
|
135610
|
+
const idLines = [
|
|
135611
|
+
receiptLine("\u7CFB\u5217ID", progress.campaignId, campaignRow?.["id"]),
|
|
135612
|
+
receiptLine("\u5E7F\u544A\u7EC4ID", progress.adSetId, adsetRow?.["id"]),
|
|
135613
|
+
receiptLine("\u521B\u610FID", progress.creativeId, creativeRow?.["id"]),
|
|
135614
|
+
receiptLine("\u5E7F\u544AID", progress.adId, adRow?.["id"])
|
|
135615
|
+
];
|
|
135616
|
+
printWriteReceipt(judgeReceipt(idLines), idLines);
|
|
133761
135617
|
if (await emitProgress()) return;
|
|
133762
135618
|
console.log("\n\u2705 Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\u5DF2\u521B\u5EFA\uFF08\u9ED8\u8BA4 PAUSED\uFF09\n");
|
|
133763
135619
|
console.log(` formId ${progress.formId}`);
|
|
@@ -133933,6 +135789,24 @@ async function runMetaAdFormCreate(opts) {
|
|
|
133933
135789
|
);
|
|
133934
135790
|
const id = extractCreatedId(data);
|
|
133935
135791
|
const payload = { ...data, id };
|
|
135792
|
+
if (id) {
|
|
135793
|
+
const list = await tryReadMeta(
|
|
135794
|
+
facebookApiUrl,
|
|
135795
|
+
digits,
|
|
135796
|
+
`/pages/${encodeURIComponent(opts.pageId)}/forms`,
|
|
135797
|
+
config,
|
|
135798
|
+
opts.verbose
|
|
135799
|
+
);
|
|
135800
|
+
const rows = Array.isArray(list?.["data"]) ? list["data"] : [];
|
|
135801
|
+
const found = rows.some((row) => {
|
|
135802
|
+
if (!row || typeof row !== "object") return false;
|
|
135803
|
+
return String(row["id"] ?? "") === id;
|
|
135804
|
+
});
|
|
135805
|
+
const lines = [receiptLine("ID", id, found ? id : list ? "\u672A\u627E\u5230" : void 0)];
|
|
135806
|
+
printWriteReceipt(list ? judgeReceipt(lines) : "unknown", lines);
|
|
135807
|
+
} else {
|
|
135808
|
+
printWriteReceipt("submitted", [receiptLine("ID", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
135809
|
+
}
|
|
133936
135810
|
if (await emitMetaJson(opts, "meta-ad-form-create", "meta-ad form-create", payload, digits)) {
|
|
133937
135811
|
return;
|
|
133938
135812
|
}
|
|
@@ -134060,6 +135934,21 @@ async function runMetaAdVideoUpload(opts) {
|
|
|
134060
135934
|
);
|
|
134061
135935
|
const id = extractCreatedId(data);
|
|
134062
135936
|
const payload = { ...data, id, title: data.title ?? name2 };
|
|
135937
|
+
if (id) {
|
|
135938
|
+
const read = await tryReadMeta(
|
|
135939
|
+
facebookApiUrl,
|
|
135940
|
+
digits,
|
|
135941
|
+
`/videos?ids=${encodeURIComponent(id)}`,
|
|
135942
|
+
config,
|
|
135943
|
+
opts.verbose
|
|
135944
|
+
);
|
|
135945
|
+
const hit = read?.[id];
|
|
135946
|
+
const actualId = hit && typeof hit === "object" ? String(hit["id"] ?? id) : void 0;
|
|
135947
|
+
const lines = [receiptLine("ID", id, hit ? actualId : read ? "\u672A\u627E\u5230" : void 0)];
|
|
135948
|
+
printWriteReceipt(read ? judgeReceipt(lines) : "unknown", lines);
|
|
135949
|
+
} else {
|
|
135950
|
+
printWriteReceipt("submitted", [receiptLine("ID", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
135951
|
+
}
|
|
134063
135952
|
if (await emitMetaJson(opts, "meta-ad-video-upload", "meta-ad video-upload", payload, digits)) {
|
|
134064
135953
|
return;
|
|
134065
135954
|
}
|
|
@@ -134072,8 +135961,6 @@ async function runMetaAdVideoUpload(opts) {
|
|
|
134072
135961
|
import { createWriteStream } from "fs";
|
|
134073
135962
|
import { mkdir as mkdir7, rename as rename2, rm as rm3, writeFile as writeFile7 } from "fs/promises";
|
|
134074
135963
|
import { dirname as dirname15, join as join14 } from "path";
|
|
134075
|
-
import { Readable } from "stream";
|
|
134076
|
-
import { pipeline } from "stream/promises";
|
|
134077
135964
|
var MAX_MEDIA_BATCH = 50;
|
|
134078
135965
|
var MAX_IMAGE_BYTES = 30 * 1024 * 1024;
|
|
134079
135966
|
var MAX_VIDEO_BYTES = 512 * 1024 * 1024;
|
|
@@ -134177,41 +136064,34 @@ async function downloadPublicFile(fileUrl, dest, maxBytes) {
|
|
|
134177
136064
|
const headParts = [];
|
|
134178
136065
|
let headLen = 0;
|
|
134179
136066
|
let total = 0;
|
|
134180
|
-
|
|
134181
|
-
|
|
134182
|
-
|
|
134183
|
-
|
|
134184
|
-
|
|
134185
|
-
|
|
134186
|
-
|
|
134187
|
-
|
|
134188
|
-
|
|
134189
|
-
|
|
134190
|
-
|
|
134191
|
-
|
|
134192
|
-
|
|
134193
|
-
|
|
134194
|
-
|
|
134195
|
-
|
|
134196
|
-
headLen += chunk.length;
|
|
134197
|
-
}
|
|
134198
|
-
this.push(chunk);
|
|
134199
|
-
} catch (err) {
|
|
134200
|
-
this.destroy(err instanceof Error ? err : new Error(String(err)));
|
|
136067
|
+
try {
|
|
136068
|
+
while (true) {
|
|
136069
|
+
const { done, value } = await reader.read();
|
|
136070
|
+
if (done) break;
|
|
136071
|
+
const chunk = Buffer.from(value);
|
|
136072
|
+
total += chunk.length;
|
|
136073
|
+
if (total > maxBytes) {
|
|
136074
|
+
await reader.cancel();
|
|
136075
|
+
throw new Error(`\u6587\u4EF6\u8D85\u8FC7 ${maxBytes} \u5B57\u8282`);
|
|
136076
|
+
}
|
|
136077
|
+
if (headLen < 16) {
|
|
136078
|
+
headParts.push(chunk.subarray(0, 16 - headLen));
|
|
136079
|
+
headLen += chunk.length;
|
|
136080
|
+
}
|
|
136081
|
+
if (!ws.write(chunk)) {
|
|
136082
|
+
await new Promise((resolve27) => ws.once("drain", resolve27));
|
|
134201
136083
|
}
|
|
134202
136084
|
}
|
|
134203
|
-
|
|
134204
|
-
|
|
134205
|
-
|
|
136085
|
+
if (total < 1) throw new Error("\u6587\u4EF6\u4E3A\u7A7A");
|
|
136086
|
+
await new Promise((resolve27, reject) => {
|
|
136087
|
+
ws.once("error", reject);
|
|
136088
|
+
ws.end(() => resolve27());
|
|
136089
|
+
});
|
|
134206
136090
|
} catch (err) {
|
|
134207
|
-
|
|
134208
|
-
await rm3(dest, { force: true })
|
|
136091
|
+
ws.destroy();
|
|
136092
|
+
await rm3(dest, { force: true });
|
|
134209
136093
|
throw err;
|
|
134210
136094
|
}
|
|
134211
|
-
if (total < 1) {
|
|
134212
|
-
await rm3(dest, { force: true }).catch(() => void 0);
|
|
134213
|
-
throw new Error("\u6587\u4EF6\u4E3A\u7A7A");
|
|
134214
|
-
}
|
|
134215
136095
|
return {
|
|
134216
136096
|
bytes: total,
|
|
134217
136097
|
contentType: response.headers.get("content-type"),
|
|
@@ -134320,25 +136200,20 @@ async function runMetaAdMediaDownload(opts) {
|
|
|
134320
136200
|
await mkdir7(outDir, { recursive: true });
|
|
134321
136201
|
await writeFile7(join14(outDir, "manifest.json"), `${JSON.stringify(manifest, null, 2)}
|
|
134322
136202
|
`, "utf8");
|
|
134323
|
-
const missingCount = missingImages.length + missingVideos.length;
|
|
134324
|
-
const incomplete = missingCount > 0 || failed.length > 0;
|
|
134325
|
-
if (incomplete) process.exitCode = 1;
|
|
134326
136203
|
if (await emitMetaJson(opts, "meta-ad-media-download", "meta-ad media-download", manifest, digits, {
|
|
134327
136204
|
images: images.length,
|
|
134328
136205
|
videos: videos.length,
|
|
134329
|
-
missing:
|
|
136206
|
+
missing: missingImages.length + missingVideos.length,
|
|
134330
136207
|
failed: failed.length
|
|
134331
136208
|
})) {
|
|
134332
136209
|
return;
|
|
134333
136210
|
}
|
|
134334
|
-
|
|
134335
|
-
|
|
134336
|
-
\
|
|
134337
|
-
\u76EE\u5F55 ${outDir}
|
|
134338
|
-
` : `
|
|
134339
|
-
\u2705 ${summary}
|
|
136211
|
+
console.log(
|
|
136212
|
+
`
|
|
136213
|
+
\u2705 \u56FE\u7247 ${images.length}\uFF0C\u89C6\u9891 ${videos.length}\uFF0C\u7F3A\u5931 ${missingImages.length + missingVideos.length}\uFF0C\u5931\u8D25 ${failed.length}
|
|
134340
136214
|
\u76EE\u5F55 ${outDir}
|
|
134341
|
-
`
|
|
136215
|
+
`
|
|
136216
|
+
);
|
|
134342
136217
|
}
|
|
134343
136218
|
async function saveNamedFile(fileUrl, dir, id, kind, maxBytes) {
|
|
134344
136219
|
const temp = join14(dir, `${id}.part`);
|
|
@@ -134856,6 +136731,20 @@ async function runMetaAdCampaignCreate(opts) {
|
|
|
134856
136731
|
);
|
|
134857
136732
|
const id = extractCreatedId(data);
|
|
134858
136733
|
const payload = { ...data, id, currency };
|
|
136734
|
+
const read = id ? await tryReadMeta(
|
|
136735
|
+
facebookApiUrl,
|
|
136736
|
+
digits,
|
|
136737
|
+
`/campaigns/${encodeURIComponent(id)}`,
|
|
136738
|
+
config,
|
|
136739
|
+
opts.verbose
|
|
136740
|
+
) : void 0;
|
|
136741
|
+
printMetaObjectReceipt(
|
|
136742
|
+
{
|
|
136743
|
+
status: (opts.status?.trim() || "PAUSED").toUpperCase(),
|
|
136744
|
+
dailyBudget: daily != null ? toMinorUnitString(daily, currency) : void 0
|
|
136745
|
+
},
|
|
136746
|
+
read
|
|
136747
|
+
);
|
|
134859
136748
|
if (await emitMetaJson(opts, "meta-ad-campaign-create", "meta-ad campaign-create", payload, digits)) {
|
|
134860
136749
|
return;
|
|
134861
136750
|
}
|
|
@@ -134906,6 +136795,20 @@ async function runMetaAdCampaignEdit(opts) {
|
|
|
134906
136795
|
"\u6539\u7CFB\u5217\u5931\u8D25"
|
|
134907
136796
|
);
|
|
134908
136797
|
const payload = { id: extractCreatedId(data) ?? opts.id, ...data };
|
|
136798
|
+
const read = await tryReadMeta(
|
|
136799
|
+
facebookApiUrl,
|
|
136800
|
+
digits,
|
|
136801
|
+
`/campaigns/${encodeURIComponent(opts.id)}`,
|
|
136802
|
+
config,
|
|
136803
|
+
opts.verbose
|
|
136804
|
+
);
|
|
136805
|
+
printMetaObjectReceipt(
|
|
136806
|
+
{
|
|
136807
|
+
status: typeof body.status === "string" ? body.status : void 0,
|
|
136808
|
+
dailyBudget: typeof body.daily_budget === "string" ? body.daily_budget : void 0
|
|
136809
|
+
},
|
|
136810
|
+
read
|
|
136811
|
+
);
|
|
134909
136812
|
if (await emitMetaJson(opts, "meta-ad-campaign-edit", "meta-ad campaign-edit", payload, digits)) {
|
|
134910
136813
|
return;
|
|
134911
136814
|
}
|
|
@@ -134928,6 +136831,14 @@ async function runMetaAdCampaignStatus(opts) {
|
|
|
134928
136831
|
"\u6539\u7CFB\u5217\u72B6\u6001\u5931\u8D25"
|
|
134929
136832
|
);
|
|
134930
136833
|
const payload = { id: extractCreatedId(data) ?? opts.id, status: opts.status.trim(), ...data };
|
|
136834
|
+
const read = await tryReadMeta(
|
|
136835
|
+
facebookApiUrl,
|
|
136836
|
+
digits,
|
|
136837
|
+
`/campaigns/${encodeURIComponent(opts.id)}`,
|
|
136838
|
+
config,
|
|
136839
|
+
opts.verbose
|
|
136840
|
+
);
|
|
136841
|
+
printMetaObjectReceipt({ status: opts.status.trim().toUpperCase() }, read);
|
|
134931
136842
|
if (await emitMetaJson(opts, "meta-ad-campaign-status", "meta-ad campaign-status", payload, digits)) {
|
|
134932
136843
|
return;
|
|
134933
136844
|
}
|
|
@@ -135162,6 +137073,15 @@ async function runMetaAdAdsetCreate(opts) {
|
|
|
135162
137073
|
}
|
|
135163
137074
|
const id2 = extractCreatedId(data);
|
|
135164
137075
|
const payload2 = { ...data, id: id2, currency, recovery: decision.recovery };
|
|
137076
|
+
const readRetry = id2 ? await tryReadMeta(facebookApiUrl, digits, `/adsets/${encodeURIComponent(id2)}`, config, opts.verbose) : void 0;
|
|
137077
|
+
printMetaObjectReceipt(
|
|
137078
|
+
{
|
|
137079
|
+
status: (opts.status?.trim() || "PAUSED").toUpperCase(),
|
|
137080
|
+
dailyBudget: daily != null ? toMinorUnitString(daily, currency) : void 0,
|
|
137081
|
+
countries
|
|
137082
|
+
},
|
|
137083
|
+
readRetry
|
|
137084
|
+
);
|
|
135165
137085
|
if (await emitMetaJson(opts, "meta-ad-adset-create", "meta-ad adset-create", payload2, digits)) {
|
|
135166
137086
|
return;
|
|
135167
137087
|
}
|
|
@@ -135172,6 +137092,15 @@ async function runMetaAdAdsetCreate(opts) {
|
|
|
135172
137092
|
}
|
|
135173
137093
|
const id = extractCreatedId(data);
|
|
135174
137094
|
const payload = { ...data, id, currency };
|
|
137095
|
+
const read = id ? await tryReadMeta(facebookApiUrl, digits, `/adsets/${encodeURIComponent(id)}`, config, opts.verbose) : void 0;
|
|
137096
|
+
printMetaObjectReceipt(
|
|
137097
|
+
{
|
|
137098
|
+
status: (opts.status?.trim() || "PAUSED").toUpperCase(),
|
|
137099
|
+
dailyBudget: daily != null ? toMinorUnitString(daily, currency) : void 0,
|
|
137100
|
+
countries
|
|
137101
|
+
},
|
|
137102
|
+
read
|
|
137103
|
+
);
|
|
135175
137104
|
if (await emitMetaJson(opts, "meta-ad-adset-create", "meta-ad adset-create", payload, digits)) {
|
|
135176
137105
|
return;
|
|
135177
137106
|
}
|
|
@@ -135320,6 +137249,7 @@ async function runMetaAdAdsetEdit(opts) {
|
|
|
135320
137249
|
const unmatched = describeUnmatchedChecks(judged.checks);
|
|
135321
137250
|
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`;
|
|
135322
137251
|
const headline = writeVerificationHeadline(verification, detail);
|
|
137252
|
+
printWriteReceipt(verification, receiptLinesFromFieldChecks(judged.checks));
|
|
135323
137253
|
if (verification !== "verified") {
|
|
135324
137254
|
console.error(`
|
|
135325
137255
|
${headline}
|
|
@@ -135360,6 +137290,14 @@ async function runMetaAdAdsetStatus(opts) {
|
|
|
135360
137290
|
"\u6539\u5E7F\u544A\u7EC4\u72B6\u6001\u5931\u8D25"
|
|
135361
137291
|
);
|
|
135362
137292
|
const payload = { id: extractCreatedId(data) ?? opts.id, status: opts.status.trim(), ...data };
|
|
137293
|
+
const read = await tryReadMeta(
|
|
137294
|
+
facebookApiUrl,
|
|
137295
|
+
digits,
|
|
137296
|
+
`/adsets/${encodeURIComponent(opts.id)}`,
|
|
137297
|
+
config,
|
|
137298
|
+
opts.verbose
|
|
137299
|
+
);
|
|
137300
|
+
printMetaObjectReceipt({ status: opts.status.trim().toUpperCase() }, read);
|
|
135363
137301
|
if (await emitMetaJson(opts, "meta-ad-adset-status", "meta-ad adset-status", payload, digits)) {
|
|
135364
137302
|
return;
|
|
135365
137303
|
}
|
|
@@ -135401,6 +137339,19 @@ async function runMetaAdCreativeCreate(opts) {
|
|
|
135401
137339
|
);
|
|
135402
137340
|
const id = extractCreatedId(data);
|
|
135403
137341
|
const payload = { ...data, id };
|
|
137342
|
+
if (id) {
|
|
137343
|
+
const read = await tryReadMeta(
|
|
137344
|
+
facebookApiUrl,
|
|
137345
|
+
digits,
|
|
137346
|
+
`/adcreatives/${encodeURIComponent(id)}`,
|
|
137347
|
+
config,
|
|
137348
|
+
opts.verbose
|
|
137349
|
+
);
|
|
137350
|
+
const lines = [receiptLine("ID", id, read?.["id"])];
|
|
137351
|
+
printWriteReceipt(read ? judgeReceipt(lines) : "unknown", lines);
|
|
137352
|
+
} else {
|
|
137353
|
+
printWriteReceipt("submitted", [receiptLine("ID", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
137354
|
+
}
|
|
135404
137355
|
if (await emitMetaJson(opts, "meta-ad-creative-create", "meta-ad creative-create", payload, digits)) {
|
|
135405
137356
|
return;
|
|
135406
137357
|
}
|
|
@@ -135469,6 +137420,11 @@ async function runMetaAdCreate2(opts) {
|
|
|
135469
137420
|
);
|
|
135470
137421
|
const id = extractCreatedId(data);
|
|
135471
137422
|
const payload = { ...data, id };
|
|
137423
|
+
const read = id ? await tryReadMeta(facebookApiUrl, digits, `/ads/${encodeURIComponent(id)}`, config, opts.verbose) : void 0;
|
|
137424
|
+
printMetaObjectReceipt(
|
|
137425
|
+
{ status: (opts.status?.trim() || "PAUSED").toUpperCase() },
|
|
137426
|
+
read
|
|
137427
|
+
);
|
|
135472
137428
|
if (await emitMetaJson(opts, "meta-ad-ad-create", "meta-ad ad-create", payload, digits)) return;
|
|
135473
137429
|
console.log(`
|
|
135474
137430
|
\u2705 \u5E7F\u544A\u5DF2\u521B\u5EFA\uFF1A${id ?? JSON.stringify(data)}
|
|
@@ -135494,6 +137450,17 @@ async function runMetaAdEdit(opts) {
|
|
|
135494
137450
|
"\u6539\u5E7F\u544A\u5931\u8D25"
|
|
135495
137451
|
);
|
|
135496
137452
|
const payload = { id: extractCreatedId(data) ?? opts.id, ...data };
|
|
137453
|
+
const read = await tryReadMeta(
|
|
137454
|
+
facebookApiUrl,
|
|
137455
|
+
digits,
|
|
137456
|
+
`/ads/${encodeURIComponent(opts.id)}`,
|
|
137457
|
+
config,
|
|
137458
|
+
opts.verbose
|
|
137459
|
+
);
|
|
137460
|
+
printMetaObjectReceipt(
|
|
137461
|
+
{ status: typeof body.status === "string" ? String(body.status).toUpperCase() : void 0 },
|
|
137462
|
+
read
|
|
137463
|
+
);
|
|
135497
137464
|
if (await emitMetaJson(opts, "meta-ad-ad-edit", "meta-ad ad-edit", payload, digits)) return;
|
|
135498
137465
|
console.log(`
|
|
135499
137466
|
\u2705 \u5E7F\u544A ${opts.id} \u5DF2\u66F4\u65B0
|
|
@@ -135514,6 +137481,14 @@ async function runMetaAdStatus(opts) {
|
|
|
135514
137481
|
"\u6539\u5E7F\u544A\u72B6\u6001\u5931\u8D25"
|
|
135515
137482
|
);
|
|
135516
137483
|
const payload = { id: extractCreatedId(data) ?? opts.id, status: opts.status.trim(), ...data };
|
|
137484
|
+
const read = await tryReadMeta(
|
|
137485
|
+
facebookApiUrl,
|
|
137486
|
+
digits,
|
|
137487
|
+
`/ads/${encodeURIComponent(opts.id)}`,
|
|
137488
|
+
config,
|
|
137489
|
+
opts.verbose
|
|
137490
|
+
);
|
|
137491
|
+
printMetaObjectReceipt({ status: opts.status.trim().toUpperCase() }, read);
|
|
135517
137492
|
if (await emitMetaJson(opts, "meta-ad-ad-status", "meta-ad ad-status", payload, digits)) return;
|
|
135518
137493
|
console.log(`
|
|
135519
137494
|
\u2705 \u5E7F\u544A ${opts.id} \u72B6\u6001\u5DF2\u8BBE\u4E3A ${opts.status.trim()}
|
|
@@ -136947,6 +138922,24 @@ async function runAccountMccBind(opts) {
|
|
|
136947
138922
|
process.exit(1);
|
|
136948
138923
|
}
|
|
136949
138924
|
}
|
|
138925
|
+
for (const { customerId, response } of results) {
|
|
138926
|
+
const failed = managerIds.filter((mid) => !mccResponseHasSuccess(response, mid));
|
|
138927
|
+
const listed = await fetchAccountsByKeyword(config, "Google", customerId, opts.verbose);
|
|
138928
|
+
const stillListed = JSON.stringify(listed ?? "").includes(customerId);
|
|
138929
|
+
const lines = [
|
|
138930
|
+
receiptLine(
|
|
138931
|
+
"MCC",
|
|
138932
|
+
managerIds.join(","),
|
|
138933
|
+
failed.length ? `\u672A\u6210\u529F ${failed.join(",")}` : managerIds.join(",")
|
|
138934
|
+
),
|
|
138935
|
+
receiptLine(
|
|
138936
|
+
"\u8D26\u6237",
|
|
138937
|
+
"\u4ECD\u5728\u5217\u8868",
|
|
138938
|
+
listed === void 0 ? void 0 : stillListed ? "\u4ECD\u5728\u5217\u8868" : "\u5DF2\u4E0D\u5728"
|
|
138939
|
+
)
|
|
138940
|
+
];
|
|
138941
|
+
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
138942
|
+
}
|
|
136950
138943
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
136951
138944
|
section: "account-mcc-bind",
|
|
136952
138945
|
commandLabel: "account mcc-bind",
|
|
@@ -137004,6 +138997,16 @@ async function runAccountMccUnbind(opts) {
|
|
|
137004
138997
|
process.exit(1);
|
|
137005
138998
|
}
|
|
137006
138999
|
}
|
|
139000
|
+
for (const { customerId, response } of results) {
|
|
139001
|
+
const failed = managerIds.filter((mid) => !mccResponseHasSuccess(response, mid));
|
|
139002
|
+
const listed = await fetchAccountsByKeyword(config, "Google", customerId, opts.verbose);
|
|
139003
|
+
const stillListed = JSON.stringify(listed ?? "").includes(customerId);
|
|
139004
|
+
const lines = [
|
|
139005
|
+
receiptLine("MCC", managerIds.join(","), failed.length ? `\u672A\u6210\u529F ${failed.join(",")}` : managerIds.join(",")),
|
|
139006
|
+
receiptLine("\u8D26\u6237", "\u4ECD\u5728\u5217\u8868", listed === void 0 ? void 0 : stillListed ? "\u4ECD\u5728\u5217\u8868" : "\u5DF2\u4E0D\u5728")
|
|
139007
|
+
];
|
|
139008
|
+
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
139009
|
+
}
|
|
137007
139010
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
137008
139011
|
section: "account-mcc-unbind",
|
|
137009
139012
|
commandLabel: "account mcc-unbind",
|
|
@@ -137361,6 +139364,9 @@ async function runAccountDelink(opts) {
|
|
|
137361
139364
|
`);
|
|
137362
139365
|
process.exit(1);
|
|
137363
139366
|
}
|
|
139367
|
+
for (const id of opts.ids) {
|
|
139368
|
+
await printAccountAbsence(config, void 0, id, "\u8D26\u6237", opts.verbose);
|
|
139369
|
+
}
|
|
137364
139370
|
console.log(`
|
|
137365
139371
|
\u2705 \u5DF2\u6279\u91CF\u65AD\u5F00 ${opts.ids.length} \u4E2A\u8D26\u6237\u7684\u5173\u8054\u5173\u7CFB
|
|
137366
139372
|
`);
|
|
@@ -137380,6 +139386,7 @@ async function runAccountDelink(opts) {
|
|
|
137380
139386
|
`);
|
|
137381
139387
|
process.exit(1);
|
|
137382
139388
|
}
|
|
139389
|
+
await printAccountAbsence(config, void 0, entityId, "\u8D26\u6237", opts.verbose);
|
|
137383
139390
|
console.log(`
|
|
137384
139391
|
\u2705 \u8D26\u6237 ${entityId} \u5DF2\u65AD\u5F00\u5173\u8054
|
|
137385
139392
|
`);
|
|
@@ -137433,6 +139440,27 @@ async function runAccountShare(opts) {
|
|
|
137433
139440
|
`);
|
|
137434
139441
|
process.exit(1);
|
|
137435
139442
|
}
|
|
139443
|
+
let detail;
|
|
139444
|
+
try {
|
|
139445
|
+
const listed = await apiFetch2(
|
|
139446
|
+
`${config.apiBaseUrl}/query/media-account/?keyword=${encodeURIComponent(opts.id)}&pageNo=1&pageSize=5`,
|
|
139447
|
+
config,
|
|
139448
|
+
{},
|
|
139449
|
+
opts.verbose
|
|
139450
|
+
);
|
|
139451
|
+
const mediaId = JSON.stringify(listed ?? "").match(/"mediaCustomerId"\s*:\s*"([^"]+)"/)?.[1];
|
|
139452
|
+
if (mediaId && config.mainApiUrl) {
|
|
139453
|
+
detail = await apiFetch2(
|
|
139454
|
+
`${config.mainApiUrl}/query/account/GetAccountsByMediaAcountId?mediaAcountId=${encodeURIComponent(mediaId)}`,
|
|
139455
|
+
config,
|
|
139456
|
+
{},
|
|
139457
|
+
opts.verbose
|
|
139458
|
+
);
|
|
139459
|
+
}
|
|
139460
|
+
} catch {
|
|
139461
|
+
detail = void 0;
|
|
139462
|
+
}
|
|
139463
|
+
printApplicationNeedles([{ label: "\u88AB\u5206\u4EAB\u4EBA", value: userId }], detail);
|
|
137436
139464
|
console.log(`
|
|
137437
139465
|
\u2705 \u8D26\u6237\u5DF2\u6210\u529F\u5206\u4EAB\u7ED9\u624B\u673A\u53F7 ${phone} \u7684\u7528\u6237\uFF08AccountId: ${userId}\uFF09
|
|
137438
139466
|
`);
|
|
@@ -137454,6 +139482,29 @@ async function runAccountUnshare(opts) {
|
|
|
137454
139482
|
`);
|
|
137455
139483
|
process.exit(1);
|
|
137456
139484
|
}
|
|
139485
|
+
let detail;
|
|
139486
|
+
try {
|
|
139487
|
+
const listed = await apiFetch2(
|
|
139488
|
+
`${config.apiBaseUrl}/query/media-account/?keyword=${encodeURIComponent(opts.id)}&pageNo=1&pageSize=5`,
|
|
139489
|
+
config,
|
|
139490
|
+
{},
|
|
139491
|
+
opts.verbose
|
|
139492
|
+
);
|
|
139493
|
+
const text5 = JSON.stringify(listed ?? "");
|
|
139494
|
+
const mediaId = text5.match(/"mediaCustomerId"\s*:\s*"([^"]+)"/)?.[1];
|
|
139495
|
+
if (mediaId && config.mainApiUrl) {
|
|
139496
|
+
detail = await apiFetch2(
|
|
139497
|
+
`${config.mainApiUrl}/query/account/GetAccountsByMediaAcountId?mediaAcountId=${encodeURIComponent(mediaId)}`,
|
|
139498
|
+
config,
|
|
139499
|
+
{},
|
|
139500
|
+
opts.verbose
|
|
139501
|
+
);
|
|
139502
|
+
}
|
|
139503
|
+
} catch {
|
|
139504
|
+
detail = void 0;
|
|
139505
|
+
}
|
|
139506
|
+
const gone = receiptForAbsence("\u5206\u4EAB", opts.accountId, detail);
|
|
139507
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
137457
139508
|
console.log(`
|
|
137458
139509
|
\u2705 \u5DF2\u53D6\u6D88\u8D26\u6237 ${opts.id} \u5BF9\u7528\u6237 ${opts.accountId} \u7684\u5206\u4EAB
|
|
137459
139510
|
`);
|
|
@@ -137547,6 +139598,7 @@ async function runAccountAuth(opts) {
|
|
|
137547
139598
|
redirectUrl,
|
|
137548
139599
|
tryOpenBrowser: tryOpenHttpsUrlInBrowser
|
|
137549
139600
|
});
|
|
139601
|
+
printWriteReceipt("submitted", [receiptLine("\u6388\u6743", opts.media, "\u5DF2\u6253\u5F00\u94FE\u63A5")]);
|
|
137550
139602
|
}
|
|
137551
139603
|
async function runAccountReauth(opts) {
|
|
137552
139604
|
tipPreferAgentNativeMediaOAuth("reauth");
|
|
@@ -137708,6 +139760,9 @@ async function runAccountClose(opts) {
|
|
|
137708
139760
|
console.error("");
|
|
137709
139761
|
process.exit(1);
|
|
137710
139762
|
}
|
|
139763
|
+
for (const id of mediaIds) {
|
|
139764
|
+
await printAccountAbsence(config, "TikTok", id, "\u8D26\u6237", opts.verbose);
|
|
139765
|
+
}
|
|
137711
139766
|
console.log(`
|
|
137712
139767
|
\u2705 TikTok \u5173\u6237\u5DF2\u6210\u529F\u63D0\u4EA4\uFF0CmediaCustomerId\uFF1A${mediaIds.join("\u3001")}
|
|
137713
139768
|
`);
|
|
@@ -137916,6 +139971,13 @@ async function runAccountWithdrawSubmit(opts) {
|
|
|
137916
139971
|
`);
|
|
137917
139972
|
process.exit(1);
|
|
137918
139973
|
}
|
|
139974
|
+
printApplicationNeedles(
|
|
139975
|
+
body.flatMap((item) => [
|
|
139976
|
+
{ label: "\u7533\u8BF7\u8D26\u6237", value: item.MediaCustomerId },
|
|
139977
|
+
{ label: "\u7533\u8BF7\u91D1\u989D", value: item.Amounts }
|
|
139978
|
+
]),
|
|
139979
|
+
result
|
|
139980
|
+
);
|
|
137919
139981
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
137920
139982
|
section: "account-withdraw-submit",
|
|
137921
139983
|
commandLabel: "account withdraw submit",
|
|
@@ -137973,6 +140035,21 @@ async function runAccountBcBind(opts) {
|
|
|
137973
140035
|
`);
|
|
137974
140036
|
process.exit(1);
|
|
137975
140037
|
}
|
|
140038
|
+
const resultArr = Array.isArray(result) ? result : [];
|
|
140039
|
+
const bindFailed = resultArr.some((r) => r.code !== 0);
|
|
140040
|
+
for (const customerId of opts.customers) {
|
|
140041
|
+
const listed = await fetchAccountsByKeyword(config, "TikTok", customerId, opts.verbose);
|
|
140042
|
+
const stillListed = JSON.stringify(listed ?? "").includes(customerId);
|
|
140043
|
+
const lines = [
|
|
140044
|
+
receiptLine("BC\u7ED1\u5B9A", "\u5DF2\u7ED1\u5B9A", bindFailed ? "\u90E8\u5206\u5931\u8D25" : "\u5DF2\u7ED1\u5B9A"),
|
|
140045
|
+
receiptLine(
|
|
140046
|
+
"\u8D26\u6237",
|
|
140047
|
+
"\u4ECD\u5728\u5217\u8868",
|
|
140048
|
+
listed === void 0 ? void 0 : stillListed ? "\u4ECD\u5728\u5217\u8868" : "\u5DF2\u4E0D\u5728"
|
|
140049
|
+
)
|
|
140050
|
+
];
|
|
140051
|
+
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
140052
|
+
}
|
|
137976
140053
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
137977
140054
|
section: "account-bc-bind",
|
|
137978
140055
|
commandLabel: "account bc-bind",
|
|
@@ -137981,7 +140058,6 @@ async function runAccountBcBind(opts) {
|
|
|
137981
140058
|
})) {
|
|
137982
140059
|
return;
|
|
137983
140060
|
}
|
|
137984
|
-
const resultArr = Array.isArray(result) ? result : [];
|
|
137985
140061
|
const failed = resultArr.filter((r) => r.code !== 0);
|
|
137986
140062
|
if (failed.length > 0) {
|
|
137987
140063
|
console.warn(`
|
|
@@ -138019,6 +140095,17 @@ async function runAccountBcUnbind(opts) {
|
|
|
138019
140095
|
`);
|
|
138020
140096
|
process.exit(1);
|
|
138021
140097
|
}
|
|
140098
|
+
const failedIds = result && typeof result === "object" && !Array.isArray(result) ? Object.keys(result) : [];
|
|
140099
|
+
for (const customerId of opts.customers) {
|
|
140100
|
+
const listed = await fetchAccountsByKeyword(config, "TikTok", customerId, opts.verbose);
|
|
140101
|
+
const stillListed = JSON.stringify(listed ?? "").includes(customerId);
|
|
140102
|
+
const unbound = !failedIds.includes(customerId);
|
|
140103
|
+
const lines = [
|
|
140104
|
+
receiptLine("BC\u89E3\u7ED1", "\u5DF2\u89E3\u7ED1", unbound ? "\u5DF2\u89E3\u7ED1" : "\u5931\u8D25"),
|
|
140105
|
+
receiptLine("\u8D26\u6237", "\u4ECD\u5728\u5217\u8868", listed === void 0 ? void 0 : stillListed ? "\u4ECD\u5728\u5217\u8868" : "\u5DF2\u4E0D\u5728")
|
|
140106
|
+
];
|
|
140107
|
+
printWriteReceipt(listed === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
140108
|
+
}
|
|
138022
140109
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
138023
140110
|
section: `account-bc-unbind-${opts.bcId}`,
|
|
138024
140111
|
commandLabel: "account bc-unbind",
|
|
@@ -138029,11 +140116,11 @@ async function runAccountBcUnbind(opts) {
|
|
|
138029
140116
|
return;
|
|
138030
140117
|
}
|
|
138031
140118
|
const failedMap = result && typeof result === "object" && !Array.isArray(result) ? result : {};
|
|
138032
|
-
const
|
|
138033
|
-
if (
|
|
140119
|
+
const failedMessages = Object.keys(failedMap);
|
|
140120
|
+
if (failedMessages.length > 0) {
|
|
138034
140121
|
console.warn(`
|
|
138035
140122
|
\u26A0\uFE0F \u4EE5\u4E0B\u8D26\u6237\u89E3\u7ED1\u5931\u8D25\uFF1A`);
|
|
138036
|
-
for (const id of
|
|
140123
|
+
for (const id of failedMessages) {
|
|
138037
140124
|
console.warn(` ${id}: ${failedMap[id]}`);
|
|
138038
140125
|
}
|
|
138039
140126
|
} else {
|
|
@@ -138231,6 +140318,19 @@ async function runAccountEmailAuth(opts) {
|
|
|
138231
140318
|
}
|
|
138232
140319
|
process.exit(1);
|
|
138233
140320
|
}
|
|
140321
|
+
let listed;
|
|
140322
|
+
try {
|
|
140323
|
+
listed = await fetchCustomerUserAccessInvitationList(
|
|
140324
|
+
config,
|
|
140325
|
+
opts.customerId,
|
|
140326
|
+
opts.verbose,
|
|
140327
|
+
opts.agentType
|
|
140328
|
+
);
|
|
140329
|
+
} catch {
|
|
140330
|
+
listed = void 0;
|
|
140331
|
+
}
|
|
140332
|
+
const added = receiptFromNeedles([{ label: "\u90AE\u7BB1\u6388\u6743", value: opts.email }], listed);
|
|
140333
|
+
printWriteReceipt(added.verification, added.lines);
|
|
138234
140334
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
138235
140335
|
section: `account-email-auth-${opts.customerId}`,
|
|
138236
140336
|
commandLabel: "account email-auth",
|
|
@@ -138270,6 +140370,14 @@ async function runAccountEmailDeauth(opts) {
|
|
|
138270
140370
|
`);
|
|
138271
140371
|
process.exit(1);
|
|
138272
140372
|
}
|
|
140373
|
+
let listed;
|
|
140374
|
+
try {
|
|
140375
|
+
listed = await fetchCustomerUserAccessInvitationList(config, opts.customerId, opts.verbose, opts.agentType);
|
|
140376
|
+
} catch {
|
|
140377
|
+
listed = void 0;
|
|
140378
|
+
}
|
|
140379
|
+
const gone = receiptForAbsence("\u90AE\u7BB1\u6388\u6743", opts.invitationId, listed);
|
|
140380
|
+
printWriteReceipt(gone.verification, gone.lines);
|
|
138273
140381
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
138274
140382
|
section: `account-email-deauth-${opts.customerId}-${opts.invitationId}`,
|
|
138275
140383
|
commandLabel: "account email-deauth",
|
|
@@ -138311,6 +140419,14 @@ async function runAccountBmBind(opts) {
|
|
|
138311
140419
|
`);
|
|
138312
140420
|
process.exit(1);
|
|
138313
140421
|
}
|
|
140422
|
+
const listed = await fetchAccountsByKeyword(config, "MetaAd", opts.accountId, opts.verbose);
|
|
140423
|
+
printApplicationNeedles(
|
|
140424
|
+
[
|
|
140425
|
+
{ label: "\u8D26\u6237", value: opts.accountId },
|
|
140426
|
+
{ label: "BM", value: opts.bmId }
|
|
140427
|
+
],
|
|
140428
|
+
listed
|
|
140429
|
+
);
|
|
138314
140430
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
138315
140431
|
section: `account-bm-bind-${opts.accountId}`,
|
|
138316
140432
|
commandLabel: "account bm-bind",
|
|
@@ -138968,6 +141084,41 @@ async function resolveGoogleMediaAccountGroupId(config, opts) {
|
|
|
138968
141084
|
|
|
138969
141085
|
// src/commands/open-account/yandex.ts
|
|
138970
141086
|
init_auth();
|
|
141087
|
+
|
|
141088
|
+
// src/commands/open-account/readback.ts
|
|
141089
|
+
init_auth();
|
|
141090
|
+
async function printOpenAccountReceipt(config, media, company, verbose) {
|
|
141091
|
+
const params = new URLSearchParams();
|
|
141092
|
+
params.set("MediaType", media);
|
|
141093
|
+
params.set("keyword", company);
|
|
141094
|
+
params.set("pageIndex", "0");
|
|
141095
|
+
params.set("pageSize", "20");
|
|
141096
|
+
params.set(
|
|
141097
|
+
"mediaAccountState",
|
|
141098
|
+
media === "Google" ? "Created,Approved,Denied,Inactive" : "Created,Approved,Denied"
|
|
141099
|
+
);
|
|
141100
|
+
let listed;
|
|
141101
|
+
try {
|
|
141102
|
+
const res = await apiFetchWithHeaders2(
|
|
141103
|
+
`${config.apiBaseUrl}/query/media-account/?${params}`,
|
|
141104
|
+
config,
|
|
141105
|
+
{},
|
|
141106
|
+
verbose
|
|
141107
|
+
);
|
|
141108
|
+
listed = res.data;
|
|
141109
|
+
} catch {
|
|
141110
|
+
listed = void 0;
|
|
141111
|
+
}
|
|
141112
|
+
printApplicationNeedles(
|
|
141113
|
+
[
|
|
141114
|
+
{ label: "\u5A92\u4F53", value: media },
|
|
141115
|
+
{ label: "\u516C\u53F8", value: company }
|
|
141116
|
+
],
|
|
141117
|
+
listed
|
|
141118
|
+
);
|
|
141119
|
+
}
|
|
141120
|
+
|
|
141121
|
+
// src/commands/open-account/yandex.ts
|
|
138971
141122
|
async function runOpenAccountYandex(opts) {
|
|
138972
141123
|
const config = loadConfig(opts.token);
|
|
138973
141124
|
const magKey = await resolveGenericMagKey(
|
|
@@ -139002,6 +141153,7 @@ async function runOpenAccountYandex(opts) {
|
|
|
139002
141153
|
{ method: "POST", body: JSON.stringify(body) },
|
|
139003
141154
|
opts.verbose
|
|
139004
141155
|
);
|
|
141156
|
+
await printOpenAccountReceipt(config, "Yandex", opts.company, opts.verbose);
|
|
139005
141157
|
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");
|
|
139006
141158
|
logAccountOpeningHistoryWebUrl(config.apiBaseUrl, "Yandex");
|
|
139007
141159
|
if (opts.verbose && res != null) {
|
|
@@ -139271,6 +141423,7 @@ async function runOpenAccountBing(opts) {
|
|
|
139271
141423
|
{ method: "POST", body: JSON.stringify(body) },
|
|
139272
141424
|
opts.verbose
|
|
139273
141425
|
);
|
|
141426
|
+
await printOpenAccountReceipt(config, "BingV2", opts.advertiserName, opts.verbose);
|
|
139274
141427
|
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");
|
|
139275
141428
|
logAccountOpeningHistoryWebUrl(config.apiBaseUrl, "BingV2");
|
|
139276
141429
|
} catch (err) {
|
|
@@ -139612,6 +141765,7 @@ async function runOpenAccountGoogle(opts) {
|
|
|
139612
141765
|
},
|
|
139613
141766
|
opts.verbose
|
|
139614
141767
|
);
|
|
141768
|
+
await printOpenAccountReceipt(config, "Google", opts.company, opts.verbose);
|
|
139615
141769
|
console.log(
|
|
139616
141770
|
`
|
|
139617
141771
|
\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
|
|
@@ -139819,6 +141973,7 @@ async function runOpenAccountTikTok(opts) {
|
|
|
139819
141973
|
},
|
|
139820
141974
|
opts.verbose
|
|
139821
141975
|
);
|
|
141976
|
+
await printOpenAccountReceipt(config, "TikTok", opts.company, opts.verbose);
|
|
139822
141977
|
console.log(
|
|
139823
141978
|
`
|
|
139824
141979
|
\u2705 TikTok \u5F00\u6237\u7533\u8BF7\u5DF2\u63D0\u4EA4\uFF08\u5171 ${counts} \u4E2A\uFF09\u3002
|
|
@@ -140072,6 +142227,7 @@ async function runOpenAccountMeta(opts) {
|
|
|
140072
142227
|
openAccountUrl,
|
|
140073
142228
|
note: "\u94FE\u63A5\u7531 Meta \u5B98\u65B9 OE \u751F\u6210\uFF0C\u6709\u65F6\u6548\uFF1B\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u5F00\u6237\uFF0C\u8FDB\u5EA6\u89C1 account-history -m MetaAd"
|
|
140074
142229
|
};
|
|
142230
|
+
printWriteReceipt("submitted", [receiptLine("\u5F00\u6237", "MetaAd", "\u5DF2\u6253\u5F00\u94FE\u63A5")]);
|
|
140075
142231
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
140076
142232
|
section: "open-account-meta",
|
|
140077
142233
|
commandLabel: "open-account meta",
|
|
@@ -143477,7 +145633,7 @@ function getCollectIntegrityWarnings(reportData) {
|
|
|
143477
145633
|
}
|
|
143478
145634
|
|
|
143479
145635
|
// src/commands/google-ads-diagnosis/invoke-google-analysis.ts
|
|
143480
|
-
import { spawnSync as
|
|
145636
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
143481
145637
|
function invokeGoogleAnalysisCli(opts) {
|
|
143482
145638
|
const cliEntry = process.argv[1];
|
|
143483
145639
|
if (!cliEntry) {
|
|
@@ -143501,7 +145657,7 @@ function invokeGoogleAnalysisCli(opts) {
|
|
|
143501
145657
|
if (typeof opts.taskTimeoutMs === "number") {
|
|
143502
145658
|
args.push("--task-timeout-ms", String(opts.taskTimeoutMs));
|
|
143503
145659
|
}
|
|
143504
|
-
const result =
|
|
145660
|
+
const result = spawnSync3(process.execPath, args, {
|
|
143505
145661
|
encoding: "utf8",
|
|
143506
145662
|
stdio: ["ignore", "pipe", "inherit"],
|
|
143507
145663
|
timeout: opts.timeoutMs && opts.timeoutMs > 0 ? opts.timeoutMs : void 0
|
|
@@ -149842,14 +151998,25 @@ function requirePositiveId(raw, label2) {
|
|
|
149842
151998
|
}
|
|
149843
151999
|
return id;
|
|
149844
152000
|
}
|
|
149845
|
-
|
|
152001
|
+
function asRows4(raw) {
|
|
152002
|
+
if (!Array.isArray(raw)) return [];
|
|
152003
|
+
return raw.filter((item) => !!item && typeof item === "object");
|
|
152004
|
+
}
|
|
152005
|
+
function statusEquals(expected, actual) {
|
|
152006
|
+
return String(actual ?? "").toLowerCase() === expected.toLowerCase();
|
|
152007
|
+
}
|
|
152008
|
+
async function tryFetchBing(config, url, verbose) {
|
|
152009
|
+
try {
|
|
152010
|
+
return await fetchBingJson(config, url, !!verbose);
|
|
152011
|
+
} catch {
|
|
152012
|
+
return void 0;
|
|
152013
|
+
}
|
|
152014
|
+
}
|
|
152015
|
+
async function postBingWrite(url, body, opts, verbose) {
|
|
149846
152016
|
const config = loadConfig(opts.token);
|
|
149847
|
-
|
|
149848
|
-
|
|
149849
|
-
|
|
149850
|
-
{ method: "POST", body: JSON.stringify(body) },
|
|
149851
|
-
opts.verbose
|
|
149852
|
-
);
|
|
152017
|
+
return apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, verbose);
|
|
152018
|
+
}
|
|
152019
|
+
async function emitOrPrint(opts, section, commandLabel, payload) {
|
|
149853
152020
|
const emitted = await emitCliJsonOrSnapshot(
|
|
149854
152021
|
{ jsonOut: opts.jsonOut },
|
|
149855
152022
|
{
|
|
@@ -149879,13 +152046,25 @@ async function runBingCampaignUpdate(opts) {
|
|
|
149879
152046
|
}
|
|
149880
152047
|
const config = loadConfig(opts.token);
|
|
149881
152048
|
const url = reportingUrl(config, account, `campaigns/${campaignId}`, "");
|
|
149882
|
-
await
|
|
152049
|
+
const payload = await postBingWrite(
|
|
149883
152050
|
url,
|
|
149884
152051
|
{ status, dailyBudget },
|
|
149885
152052
|
opts,
|
|
149886
|
-
|
|
149887
|
-
"bing-analysis campaign-update"
|
|
152053
|
+
opts.verbose
|
|
149888
152054
|
);
|
|
152055
|
+
const rows = asRows4(await tryFetchBing(config, reportingUrl(config, account, "campaigns", ""), opts.verbose));
|
|
152056
|
+
const row = rows.find((item) => String(item["campaignId"] ?? "") === campaignId);
|
|
152057
|
+
const lines = [];
|
|
152058
|
+
if (status) {
|
|
152059
|
+
lines.push(
|
|
152060
|
+
receiptLine("\u72B6\u6001", status, row ? statusEquals(status, row.status) ? status : row.status : void 0)
|
|
152061
|
+
);
|
|
152062
|
+
}
|
|
152063
|
+
if (dailyBudget != null) {
|
|
152064
|
+
lines.push(receiptLine("\u65E5\u9884\u7B97", dailyBudget, row?.dailyBudget));
|
|
152065
|
+
}
|
|
152066
|
+
printWriteReceipt(row ? judgeReceipt(lines) : "unknown", lines);
|
|
152067
|
+
await emitOrPrint(opts, "bing-campaign-update", "bing-analysis campaign-update", payload);
|
|
149889
152068
|
}
|
|
149890
152069
|
async function runBingAdGroupUpdate(opts) {
|
|
149891
152070
|
const account = assertBingAccountId(opts.account);
|
|
@@ -149898,13 +152077,50 @@ async function runBingAdGroupUpdate(opts) {
|
|
|
149898
152077
|
}
|
|
149899
152078
|
const config = loadConfig(opts.token);
|
|
149900
152079
|
const url = reportingUrl(config, account, `campaigns/${campaignId}/ad-groups/${adGroupId}`, "");
|
|
149901
|
-
await
|
|
152080
|
+
const payload = await postBingWrite(
|
|
149902
152081
|
url,
|
|
149903
152082
|
{ status, cpcBid },
|
|
149904
152083
|
opts,
|
|
149905
|
-
|
|
149906
|
-
|
|
152084
|
+
opts.verbose
|
|
152085
|
+
);
|
|
152086
|
+
const coverageUrl2 = reportingUrl(config, account, "library/coverage-read/ad-groups", "");
|
|
152087
|
+
let coverageRows = [];
|
|
152088
|
+
let coverageFailed = false;
|
|
152089
|
+
try {
|
|
152090
|
+
const raw = await apiFetch2(
|
|
152091
|
+
coverageUrl2,
|
|
152092
|
+
config,
|
|
152093
|
+
{ method: "POST", body: JSON.stringify({ campaignId: Number(campaignId) }) },
|
|
152094
|
+
opts.verbose
|
|
152095
|
+
);
|
|
152096
|
+
if (Array.isArray(raw)) coverageRows = asRows4(raw);
|
|
152097
|
+
else if (raw && typeof raw === "object" && Array.isArray(raw.items)) {
|
|
152098
|
+
coverageRows = asRows4(raw.items);
|
|
152099
|
+
} else if (raw && typeof raw === "object" && Array.isArray(raw.rows)) {
|
|
152100
|
+
coverageRows = asRows4(raw.rows);
|
|
152101
|
+
}
|
|
152102
|
+
} catch {
|
|
152103
|
+
coverageFailed = true;
|
|
152104
|
+
}
|
|
152105
|
+
const row = coverageRows.find(
|
|
152106
|
+
(item) => String(item["id"] ?? item["adGroupId"] ?? "") === adGroupId
|
|
149907
152107
|
);
|
|
152108
|
+
const lines = [];
|
|
152109
|
+
if (status) {
|
|
152110
|
+
const actual = row?.["status"] ?? row?.["Status"];
|
|
152111
|
+
lines.push(
|
|
152112
|
+
receiptLine("\u72B6\u6001", status, row ? statusEquals(status, actual) ? status : actual : void 0)
|
|
152113
|
+
);
|
|
152114
|
+
}
|
|
152115
|
+
if (cpcBid != null) {
|
|
152116
|
+
const applied = payload?.["cpcBid"] ?? payload?.["CpcBid"];
|
|
152117
|
+
if (applied != null) lines.push(receiptLine("CPC\u51FA\u4EF7", cpcBid, applied));
|
|
152118
|
+
}
|
|
152119
|
+
printWriteReceipt(
|
|
152120
|
+
coverageFailed && !row ? "unknown" : judgeReceipt(lines),
|
|
152121
|
+
lines
|
|
152122
|
+
);
|
|
152123
|
+
await emitOrPrint(opts, "bing-adgroup-update", "bing-analysis adgroup-update", payload);
|
|
149908
152124
|
}
|
|
149909
152125
|
async function runBingAdStatus(opts) {
|
|
149910
152126
|
const account = assertBingAccountId(opts.account);
|
|
@@ -149914,7 +152130,25 @@ async function runBingAdStatus(opts) {
|
|
|
149914
152130
|
if (!status) throw new Error("\u5E7F\u544A\u72B6\u6001\u5FC5\u987B\u662F Active \u6216 Paused");
|
|
149915
152131
|
const config = loadConfig(opts.token);
|
|
149916
152132
|
const url = reportingUrl(config, account, `ad-groups/${adGroupId}/ads/${adId}/status`, "");
|
|
149917
|
-
await
|
|
152133
|
+
const payload = await postBingWrite(url, { status }, opts, opts.verbose);
|
|
152134
|
+
const bulk = await tryFetchBing(
|
|
152135
|
+
config,
|
|
152136
|
+
reportingUrl(config, account, "bulk/ads", ""),
|
|
152137
|
+
opts.verbose
|
|
152138
|
+
);
|
|
152139
|
+
const items3 = bulk && typeof bulk === "object" && Array.isArray(bulk.items) ? asRows4(bulk.items) : asRows4(bulk);
|
|
152140
|
+
const row = items3.find(
|
|
152141
|
+
(item) => String(item["adId"] ?? "") === adId && (item["adGroupId"] == null || String(item["adGroupId"]) === adGroupId)
|
|
152142
|
+
);
|
|
152143
|
+
const lines = [
|
|
152144
|
+
receiptLine(
|
|
152145
|
+
"\u72B6\u6001",
|
|
152146
|
+
status,
|
|
152147
|
+
row ? statusEquals(status, row.status) ? status : row.status : void 0
|
|
152148
|
+
)
|
|
152149
|
+
];
|
|
152150
|
+
printWriteReceipt(row ? judgeReceipt(lines) : "unknown", lines);
|
|
152151
|
+
await emitOrPrint(opts, "bing-ad-status", "bing-analysis ad-status", payload);
|
|
149918
152152
|
}
|
|
149919
152153
|
|
|
149920
152154
|
// src/commands/bing-analysis/register-cli.ts
|
|
@@ -151639,6 +153873,9 @@ async function putTikTok(path61, body, opts, section, commandLabel) {
|
|
|
151639
153873
|
opts.verbose
|
|
151640
153874
|
);
|
|
151641
153875
|
assertTikTokWriteOk(payload, commandLabel);
|
|
153876
|
+
return { advertiserId, config, payload };
|
|
153877
|
+
}
|
|
153878
|
+
async function emitTikTokWrite(opts, advertiserId, section, commandLabel, payload) {
|
|
151642
153879
|
const emitted = await emitCliJsonOrSnapshot(
|
|
151643
153880
|
{ jsonOut: opts.jsonOut },
|
|
151644
153881
|
{ section, commandLabel, payload, idSuffix: advertiserId }
|
|
@@ -151650,6 +153887,40 @@ async function putTikTok(path61, body, opts, section, commandLabel) {
|
|
|
151650
153887
|
console.log(JSON.stringify(payload, null, 2));
|
|
151651
153888
|
console.log();
|
|
151652
153889
|
}
|
|
153890
|
+
async function printTikTokStatusReceipt(config, advertiserId, kind, id, expected, verbose) {
|
|
153891
|
+
try {
|
|
153892
|
+
let actual;
|
|
153893
|
+
if (kind === "campaign") {
|
|
153894
|
+
const result = await fetchCampaignEntities(config, {
|
|
153895
|
+
advertiserId,
|
|
153896
|
+
campaignIds: id,
|
|
153897
|
+
pageSize: 20,
|
|
153898
|
+
verbose: !!verbose
|
|
153899
|
+
});
|
|
153900
|
+
actual = result.items.find((row) => String(row.campaign_id ?? "") === id)?.operation_status;
|
|
153901
|
+
} else if (kind === "adgroup") {
|
|
153902
|
+
const result = await fetchAdGroupEntities(config, {
|
|
153903
|
+
advertiserId,
|
|
153904
|
+
adGroupIds: id,
|
|
153905
|
+
pageSize: 20,
|
|
153906
|
+
verbose: !!verbose
|
|
153907
|
+
});
|
|
153908
|
+
actual = result.items.find((row) => String(row.adgroup_id ?? "") === id)?.operation_status;
|
|
153909
|
+
} else {
|
|
153910
|
+
const result = await fetchAdEntities(config, {
|
|
153911
|
+
advertiserId,
|
|
153912
|
+
adIds: id,
|
|
153913
|
+
pageSize: 20,
|
|
153914
|
+
verbose: !!verbose
|
|
153915
|
+
});
|
|
153916
|
+
actual = result.items.find((row) => String(row.ad_id ?? "") === id)?.operation_status;
|
|
153917
|
+
}
|
|
153918
|
+
const lines = [receiptLine("\u72B6\u6001", expected, actual)];
|
|
153919
|
+
printWriteReceipt(actual === void 0 ? "unknown" : judgeReceipt(lines), lines);
|
|
153920
|
+
} catch {
|
|
153921
|
+
printWriteReceipt("unknown", [receiptLine("\u72B6\u6001", expected, void 0)]);
|
|
153922
|
+
}
|
|
153923
|
+
}
|
|
151653
153924
|
async function requireMediaAccountId(opts) {
|
|
151654
153925
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151655
153926
|
const config = loadConfig(opts.token);
|
|
@@ -151665,60 +153936,115 @@ async function requireMediaAccountId(opts) {
|
|
|
151665
153936
|
async function runTikTokCampaignStatus(opts) {
|
|
151666
153937
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151667
153938
|
const status = parseTikTokOptStatus(opts.status);
|
|
151668
|
-
|
|
153939
|
+
const campaignId = opts.campaignId.trim();
|
|
153940
|
+
const written = await putTikTok(
|
|
151669
153941
|
`tiktokcampaignmanagement/campaign/updatestatus/${TIKTOK_MEDIA_TYPE}`,
|
|
151670
|
-
campaignStatusBody(advertiserId,
|
|
153942
|
+
campaignStatusBody(advertiserId, campaignId, status),
|
|
151671
153943
|
opts,
|
|
151672
153944
|
"tiktok-campaign-status",
|
|
151673
153945
|
"tiktok-analysis campaign-status"
|
|
151674
153946
|
);
|
|
153947
|
+
await printTikTokStatusReceipt(
|
|
153948
|
+
written.config,
|
|
153949
|
+
written.advertiserId,
|
|
153950
|
+
"campaign",
|
|
153951
|
+
campaignId,
|
|
153952
|
+
status,
|
|
153953
|
+
opts.verbose
|
|
153954
|
+
);
|
|
153955
|
+
await emitTikTokWrite(
|
|
153956
|
+
opts,
|
|
153957
|
+
written.advertiserId,
|
|
153958
|
+
"tiktok-campaign-status",
|
|
153959
|
+
"tiktok-analysis campaign-status",
|
|
153960
|
+
written.payload
|
|
153961
|
+
);
|
|
151675
153962
|
}
|
|
151676
153963
|
async function runTikTokCampaignBudget(opts) {
|
|
151677
153964
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151678
153965
|
const budget = parseTikTokAmount(opts.budget, "\u7CFB\u5217\u9884\u7B97");
|
|
151679
153966
|
const budgetMode = parseTikTokBudgetMode(opts.budgetMode);
|
|
151680
|
-
await putTikTok(
|
|
153967
|
+
const written = await putTikTok(
|
|
151681
153968
|
`tiktokcampaignmanagement/campaign/update/${TIKTOK_MEDIA_TYPE}`,
|
|
151682
153969
|
campaignBudgetBody(advertiserId, opts.campaignId.trim(), budget, budgetMode),
|
|
151683
153970
|
opts,
|
|
151684
153971
|
"tiktok-campaign-budget",
|
|
151685
153972
|
"tiktok-analysis campaign-budget"
|
|
151686
153973
|
);
|
|
153974
|
+
await emitTikTokWrite(
|
|
153975
|
+
opts,
|
|
153976
|
+
written.advertiserId,
|
|
153977
|
+
"tiktok-campaign-budget",
|
|
153978
|
+
"tiktok-analysis campaign-budget",
|
|
153979
|
+
written.payload
|
|
153980
|
+
);
|
|
151687
153981
|
}
|
|
151688
153982
|
async function runTikTokAdGroupStatus(opts) {
|
|
151689
153983
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151690
153984
|
const entityId = await requireMediaAccountId(opts);
|
|
151691
153985
|
const status = parseTikTokOptStatus(opts.status);
|
|
151692
|
-
|
|
153986
|
+
const adGroupId = opts.adGroupId.trim();
|
|
153987
|
+
const written = await putTikTok(
|
|
151693
153988
|
`tiktokadgroupmanagement/adgroup/UpdateStatus/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(entityId)}`,
|
|
151694
|
-
adGroupStatusBody(advertiserId,
|
|
153989
|
+
adGroupStatusBody(advertiserId, adGroupId, status),
|
|
151695
153990
|
opts,
|
|
151696
153991
|
"tiktok-adgroup-status",
|
|
151697
153992
|
"tiktok-analysis adgroup-status"
|
|
151698
153993
|
);
|
|
153994
|
+
await printTikTokStatusReceipt(
|
|
153995
|
+
written.config,
|
|
153996
|
+
written.advertiserId,
|
|
153997
|
+
"adgroup",
|
|
153998
|
+
adGroupId,
|
|
153999
|
+
status,
|
|
154000
|
+
opts.verbose
|
|
154001
|
+
);
|
|
154002
|
+
await emitTikTokWrite(
|
|
154003
|
+
opts,
|
|
154004
|
+
written.advertiserId,
|
|
154005
|
+
"tiktok-adgroup-status",
|
|
154006
|
+
"tiktok-analysis adgroup-status",
|
|
154007
|
+
written.payload
|
|
154008
|
+
);
|
|
151699
154009
|
}
|
|
151700
154010
|
async function runTikTokAdGroupBudget(opts) {
|
|
151701
154011
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151702
154012
|
const entityId = await requireMediaAccountId(opts);
|
|
151703
154013
|
const budget = parseTikTokAmount(opts.budget, "\u5E7F\u544A\u7EC4\u9884\u7B97");
|
|
151704
|
-
await putTikTok(
|
|
154014
|
+
const written = await putTikTok(
|
|
151705
154015
|
`tiktokadgroupmanagement/adgroup/UpdateBudget/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(entityId)}`,
|
|
151706
154016
|
adGroupBudgetBody(advertiserId, opts.adGroupId.trim(), budget),
|
|
151707
154017
|
opts,
|
|
151708
154018
|
"tiktok-adgroup-budget",
|
|
151709
154019
|
"tiktok-analysis adgroup-budget"
|
|
151710
154020
|
);
|
|
154021
|
+
await emitTikTokWrite(
|
|
154022
|
+
opts,
|
|
154023
|
+
written.advertiserId,
|
|
154024
|
+
"tiktok-adgroup-budget",
|
|
154025
|
+
"tiktok-analysis adgroup-budget",
|
|
154026
|
+
written.payload
|
|
154027
|
+
);
|
|
151711
154028
|
}
|
|
151712
154029
|
async function runTikTokAdStatus(opts) {
|
|
151713
154030
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151714
154031
|
const status = parseTikTokOptStatus(opts.status);
|
|
151715
|
-
|
|
154032
|
+
const adId = opts.adId.trim();
|
|
154033
|
+
const written = await putTikTok(
|
|
151716
154034
|
`tiktokadmanagement/ad/updatestatus/${TIKTOK_MEDIA_TYPE}`,
|
|
151717
|
-
adStatusBody(advertiserId,
|
|
154035
|
+
adStatusBody(advertiserId, adId, status),
|
|
151718
154036
|
opts,
|
|
151719
154037
|
"tiktok-ad-status",
|
|
151720
154038
|
"tiktok-analysis ad-status"
|
|
151721
154039
|
);
|
|
154040
|
+
await printTikTokStatusReceipt(written.config, written.advertiserId, "ad", adId, status, opts.verbose);
|
|
154041
|
+
await emitTikTokWrite(
|
|
154042
|
+
opts,
|
|
154043
|
+
written.advertiserId,
|
|
154044
|
+
"tiktok-ad-status",
|
|
154045
|
+
"tiktok-analysis ad-status",
|
|
154046
|
+
written.payload
|
|
154047
|
+
);
|
|
151722
154048
|
}
|
|
151723
154049
|
|
|
151724
154050
|
// src/commands/tiktok-analysis/media-run.ts
|
|
@@ -151984,7 +154310,36 @@ function assertBusinessOk(payload, label2) {
|
|
|
151984
154310
|
const message = payload.message ?? "\u672A\u77E5\u9519\u8BEF";
|
|
151985
154311
|
throw new Error(`${label2} \u4E1A\u52A1\u5931\u8D25 code=${String(code)}\uFF1A${message}`);
|
|
151986
154312
|
}
|
|
151987
|
-
|
|
154313
|
+
function extractMediaId(payload) {
|
|
154314
|
+
if (!payload || typeof payload !== "object") return void 0;
|
|
154315
|
+
const row = payload;
|
|
154316
|
+
const data = row["data"];
|
|
154317
|
+
const bag = data && typeof data === "object" && !Array.isArray(data) ? data : row;
|
|
154318
|
+
for (const key of [
|
|
154319
|
+
"image_id",
|
|
154320
|
+
"video_id",
|
|
154321
|
+
"material_id",
|
|
154322
|
+
"identity_id",
|
|
154323
|
+
"pixel_id",
|
|
154324
|
+
"cta_id",
|
|
154325
|
+
"id"
|
|
154326
|
+
]) {
|
|
154327
|
+
const value = bag[key];
|
|
154328
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
154329
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
154330
|
+
}
|
|
154331
|
+
return void 0;
|
|
154332
|
+
}
|
|
154333
|
+
function printMediaCreateReceipt(payload) {
|
|
154334
|
+
const id = extractMediaId(payload);
|
|
154335
|
+
if (id) {
|
|
154336
|
+
const lines = [receiptLine("ID", id, id)];
|
|
154337
|
+
printWriteReceipt(judgeReceipt(lines), lines);
|
|
154338
|
+
} else {
|
|
154339
|
+
printWriteReceipt("submitted", [receiptLine("ID", "\u5DF2\u63D0\u4EA4", "\u5DF2\u63D0\u4EA4\uFF08\u65E0 id\uFF09")]);
|
|
154340
|
+
}
|
|
154341
|
+
}
|
|
154342
|
+
async function requestTikTok(method, path61, body, opts, section, commandLabel, receiptOnCreate = false) {
|
|
151988
154343
|
const advertiserId = assertTikTokAccountId(opts.account);
|
|
151989
154344
|
const config = loadConfig(opts.token);
|
|
151990
154345
|
const url = `${requireTikTokApiUrl(config)}/${path61}`;
|
|
@@ -151995,6 +154350,7 @@ async function requestTikTok(method, path61, body, opts, section, commandLabel)
|
|
|
151995
154350
|
opts.verbose
|
|
151996
154351
|
);
|
|
151997
154352
|
assertBusinessOk(payload, commandLabel);
|
|
154353
|
+
if (receiptOnCreate) printMediaCreateReceipt(payload);
|
|
151998
154354
|
const emitted = await emitCliJsonOrSnapshot(
|
|
151999
154355
|
{ jsonOut: opts.jsonOut },
|
|
152000
154356
|
{ section, commandLabel, payload, idSuffix: advertiserId }
|
|
@@ -152072,7 +154428,15 @@ async function runTikTokImageUpload(opts) {
|
|
|
152072
154428
|
fail8("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25", err);
|
|
152073
154429
|
}
|
|
152074
154430
|
try {
|
|
152075
|
-
await requestTikTok(
|
|
154431
|
+
await requestTikTok(
|
|
154432
|
+
"POST",
|
|
154433
|
+
imageUploadPath(account),
|
|
154434
|
+
body,
|
|
154435
|
+
opts,
|
|
154436
|
+
"tiktok-image-upload",
|
|
154437
|
+
"tiktok-analysis image-upload",
|
|
154438
|
+
true
|
|
154439
|
+
);
|
|
152076
154440
|
} catch (err) {
|
|
152077
154441
|
fail8("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25", err);
|
|
152078
154442
|
}
|
|
@@ -152086,7 +154450,15 @@ async function runTikTokVideoUpload(opts) {
|
|
|
152086
154450
|
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
152087
154451
|
}
|
|
152088
154452
|
try {
|
|
152089
|
-
await requestTikTok(
|
|
154453
|
+
await requestTikTok(
|
|
154454
|
+
"POST",
|
|
154455
|
+
videoUploadPath(),
|
|
154456
|
+
body,
|
|
154457
|
+
opts,
|
|
154458
|
+
"tiktok-video-upload",
|
|
154459
|
+
"tiktok-analysis video-upload",
|
|
154460
|
+
true
|
|
154461
|
+
);
|
|
152090
154462
|
} catch (err) {
|
|
152091
154463
|
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
152092
154464
|
}
|
|
@@ -152106,7 +154478,8 @@ async function runTikTokVideoUploadByUrl(opts) {
|
|
|
152106
154478
|
body,
|
|
152107
154479
|
opts,
|
|
152108
154480
|
"tiktok-video-upload-url",
|
|
152109
|
-
"tiktok-analysis video-upload-url"
|
|
154481
|
+
"tiktok-analysis video-upload-url",
|
|
154482
|
+
true
|
|
152110
154483
|
);
|
|
152111
154484
|
} catch (err) {
|
|
152112
154485
|
fail8("\u4E0A\u4F20\u89C6\u9891\u5931\u8D25", err);
|
|
@@ -152160,7 +154533,8 @@ async function runTikTokIdentityCreate(opts) {
|
|
|
152160
154533
|
body,
|
|
152161
154534
|
opts,
|
|
152162
154535
|
"tiktok-identity-create",
|
|
152163
|
-
"tiktok-analysis identity-create"
|
|
154536
|
+
"tiktok-analysis identity-create",
|
|
154537
|
+
true
|
|
152164
154538
|
);
|
|
152165
154539
|
} catch (err) {
|
|
152166
154540
|
fail8("\u521B\u5EFA\u8EAB\u4EFD\u5931\u8D25", err);
|
|
@@ -152223,7 +154597,8 @@ async function runTikTokPixelCreate(opts) {
|
|
|
152223
154597
|
body,
|
|
152224
154598
|
opts,
|
|
152225
154599
|
"tiktok-pixel-create",
|
|
152226
|
-
"tiktok-analysis pixel-create"
|
|
154600
|
+
"tiktok-analysis pixel-create",
|
|
154601
|
+
true
|
|
152227
154602
|
);
|
|
152228
154603
|
} catch (err) {
|
|
152229
154604
|
fail8("\u521B\u5EFA\u50CF\u7D20\u5931\u8D25", err);
|
|
@@ -152244,7 +154619,8 @@ async function runTikTokPixelEventCreate(opts) {
|
|
|
152244
154619
|
body,
|
|
152245
154620
|
opts,
|
|
152246
154621
|
"tiktok-pixel-event-create",
|
|
152247
|
-
"tiktok-analysis pixel-event-create"
|
|
154622
|
+
"tiktok-analysis pixel-event-create",
|
|
154623
|
+
true
|
|
152248
154624
|
);
|
|
152249
154625
|
} catch (err) {
|
|
152250
154626
|
fail8("\u521B\u5EFA\u50CF\u7D20\u4E8B\u4EF6\u5931\u8D25", err);
|
|
@@ -152280,7 +154656,8 @@ async function runTikTokCtaRecommendCreate(opts) {
|
|
|
152280
154656
|
void 0,
|
|
152281
154657
|
opts,
|
|
152282
154658
|
"tiktok-cta-recommend-create",
|
|
152283
|
-
"tiktok-analysis cta-recommend-create"
|
|
154659
|
+
"tiktok-analysis cta-recommend-create",
|
|
154660
|
+
true
|
|
152284
154661
|
);
|
|
152285
154662
|
} catch (err) {
|
|
152286
154663
|
fail8("\u521B\u5EFA CTA \u7EC4\u5408\u5931\u8D25", err);
|
|
@@ -152326,6 +154703,7 @@ async function runTikTokAudienceFileUpload(opts) {
|
|
|
152326
154703
|
!!opts.verbose
|
|
152327
154704
|
);
|
|
152328
154705
|
assertBusinessOk(payload, "tiktok-analysis audience-file-upload");
|
|
154706
|
+
printMediaCreateReceipt(payload);
|
|
152329
154707
|
const emitted = await emitCliJsonOrSnapshot(
|
|
152330
154708
|
{ jsonOut: opts.jsonOut },
|
|
152331
154709
|
{
|
|
@@ -154012,7 +156390,41 @@ function yandexAdsUrl(base2, path61, account) {
|
|
|
154012
156390
|
const q = new URLSearchParams({ account });
|
|
154013
156391
|
return `${base2.replace(/\/$/, "")}/yandex-ads/${path61}?${q}`;
|
|
154014
156392
|
}
|
|
154015
|
-
|
|
156393
|
+
function expectedState(action) {
|
|
156394
|
+
return action === "suspend" ? "SUSPENDED" : "ON";
|
|
156395
|
+
}
|
|
156396
|
+
function asRows5(raw) {
|
|
156397
|
+
if (Array.isArray(raw)) {
|
|
156398
|
+
return raw.filter((item) => !!item && typeof item === "object");
|
|
156399
|
+
}
|
|
156400
|
+
if (!raw || typeof raw !== "object") return [];
|
|
156401
|
+
const row = raw;
|
|
156402
|
+
for (const key of ["items", "Campaigns", "Ads", "Keywords", "AdGroups", "result", "Result"]) {
|
|
156403
|
+
if (Array.isArray(row[key])) return asRows5(row[key]);
|
|
156404
|
+
}
|
|
156405
|
+
if (row["data"] && typeof row["data"] === "object") return asRows5(row["data"]);
|
|
156406
|
+
return [];
|
|
156407
|
+
}
|
|
156408
|
+
function findById(rows, id) {
|
|
156409
|
+
return rows.find((row) => String(row["Id"] ?? row["id"] ?? "") === id);
|
|
156410
|
+
}
|
|
156411
|
+
async function tryCoverageRead(config, account, operation, body, verbose) {
|
|
156412
|
+
try {
|
|
156413
|
+
const url = yandexAdsUrl(requireYandexApi(config), `library/coverage-read/${operation}`, account);
|
|
156414
|
+
const raw = await apiFetch2(
|
|
156415
|
+
url,
|
|
156416
|
+
config,
|
|
156417
|
+
{ method: "POST", body: JSON.stringify(body) },
|
|
156418
|
+
verbose
|
|
156419
|
+
);
|
|
156420
|
+
const rows = asRows5(raw);
|
|
156421
|
+
const id = String(body["id"] ?? body["Id"] ?? (Array.isArray(body["ids"]) ? body["ids"][0] : "") ?? "");
|
|
156422
|
+
return id ? findById(rows, id) : rows[0];
|
|
156423
|
+
} catch {
|
|
156424
|
+
return void 0;
|
|
156425
|
+
}
|
|
156426
|
+
}
|
|
156427
|
+
async function postYandexWrite(path61, body, opts) {
|
|
154016
156428
|
const account = assertYandexAccountId(opts.account);
|
|
154017
156429
|
const config = loadConfig(opts.token);
|
|
154018
156430
|
const url = yandexAdsUrl(requireYandexApi(config), path61, account);
|
|
@@ -154022,6 +156434,9 @@ async function postYandex(path61, body, opts, section, commandLabel) {
|
|
|
154022
156434
|
{ method: "POST", body: JSON.stringify(body) },
|
|
154023
156435
|
opts.verbose
|
|
154024
156436
|
);
|
|
156437
|
+
return { account, config, payload };
|
|
156438
|
+
}
|
|
156439
|
+
async function emitYandexWrite(opts, account, section, commandLabel, payload) {
|
|
154025
156440
|
const emitted = await emitCliJsonOrSnapshot(
|
|
154026
156441
|
{ jsonOut: opts.jsonOut },
|
|
154027
156442
|
{ section, commandLabel, payload, idSuffix: account }
|
|
@@ -154033,27 +156448,58 @@ async function postYandex(path61, body, opts, section, commandLabel) {
|
|
|
154033
156448
|
console.log(JSON.stringify(payload, null, 2));
|
|
154034
156449
|
console.log();
|
|
154035
156450
|
}
|
|
156451
|
+
function printStateReceipt(expected, row) {
|
|
156452
|
+
const actual = row?.["State"] ?? row?.["state"];
|
|
156453
|
+
const lines = [receiptLine("\u72B6\u6001", expected, actual)];
|
|
156454
|
+
printWriteReceipt(row ? judgeReceipt(lines) : "unknown", lines);
|
|
156455
|
+
}
|
|
154036
156456
|
async function runYandexCampaignState(opts) {
|
|
154037
156457
|
const id = requireYandexEntityId(opts.campaignId, "campaign-id");
|
|
154038
156458
|
const action = parseYandexAction(opts.action);
|
|
154039
|
-
await
|
|
154040
|
-
|
|
154041
|
-
|
|
156459
|
+
const written = await postYandexWrite(`campaigns/${id}/state`, { action }, opts);
|
|
156460
|
+
const row = await tryCoverageRead(
|
|
156461
|
+
written.config,
|
|
156462
|
+
written.account,
|
|
156463
|
+
"campaigns",
|
|
156464
|
+
{ id: Number(id) },
|
|
156465
|
+
opts.verbose
|
|
156466
|
+
);
|
|
156467
|
+
printStateReceipt(expectedState(action), row);
|
|
156468
|
+
await emitYandexWrite(
|
|
154042
156469
|
opts,
|
|
156470
|
+
written.account,
|
|
154043
156471
|
"yandex-campaign-state",
|
|
154044
|
-
"yandex-analysis campaign-state"
|
|
156472
|
+
"yandex-analysis campaign-state",
|
|
156473
|
+
written.payload
|
|
154045
156474
|
);
|
|
154046
156475
|
}
|
|
154047
156476
|
async function runYandexCampaignBudget(opts) {
|
|
154048
156477
|
const id = requireYandexEntityId(opts.campaignId, "campaign-id");
|
|
154049
156478
|
const amount = parseYandexAmount(opts.dailyBudget, "\u65E5\u9884\u7B97");
|
|
154050
156479
|
const mode = parseYandexBudgetMode(opts.mode);
|
|
154051
|
-
await
|
|
156480
|
+
const written = await postYandexWrite(
|
|
154052
156481
|
`campaigns/${id}/daily-budget`,
|
|
154053
156482
|
{ amount, mode },
|
|
156483
|
+
opts
|
|
156484
|
+
);
|
|
156485
|
+
const row = await tryCoverageRead(
|
|
156486
|
+
written.config,
|
|
156487
|
+
written.account,
|
|
156488
|
+
"campaigns",
|
|
156489
|
+
{ id: Number(id) },
|
|
156490
|
+
opts.verbose
|
|
156491
|
+
);
|
|
156492
|
+
const lines = [
|
|
156493
|
+
receiptLine("\u7CFB\u5217ID", id, row ? String(row["Id"] ?? row["id"] ?? id) : void 0),
|
|
156494
|
+
receiptLine("\u65E5\u9884\u7B97", amount, row ? "\u5DF2\u63D0\u4EA4" : void 0)
|
|
156495
|
+
];
|
|
156496
|
+
printWriteReceipt(row ? "submitted" : "unknown", lines);
|
|
156497
|
+
await emitYandexWrite(
|
|
154054
156498
|
opts,
|
|
156499
|
+
written.account,
|
|
154055
156500
|
"yandex-campaign-budget",
|
|
154056
|
-
"yandex-analysis campaign-budget"
|
|
156501
|
+
"yandex-analysis campaign-budget",
|
|
156502
|
+
written.payload
|
|
154057
156503
|
);
|
|
154058
156504
|
}
|
|
154059
156505
|
async function runYandexAdGroupState(opts) {
|
|
@@ -154066,17 +156512,33 @@ async function runYandexAdGroupState(opts) {
|
|
|
154066
156512
|
async function runYandexAdState(opts) {
|
|
154067
156513
|
const id = requireYandexEntityId(opts.adId, "ad-id");
|
|
154068
156514
|
const action = parseYandexAction(opts.action);
|
|
154069
|
-
await
|
|
156515
|
+
const written = await postYandexWrite(`ads/${id}/state`, { action }, opts);
|
|
156516
|
+
const row = await tryCoverageRead(written.config, written.account, "ads", { id: Number(id) }, opts.verbose);
|
|
156517
|
+
printStateReceipt(expectedState(action), row);
|
|
156518
|
+
await emitYandexWrite(opts, written.account, "yandex-ad-state", "yandex-analysis ad-state", written.payload);
|
|
154070
156519
|
}
|
|
154071
156520
|
async function runYandexKeywordBid(opts) {
|
|
154072
156521
|
const id = requireYandexEntityId(opts.keywordId, "keyword-id");
|
|
154073
156522
|
const amount = parseYandexAmount(opts.searchBid, "\u641C\u7D22\u51FA\u4EF7");
|
|
154074
|
-
await
|
|
154075
|
-
|
|
154076
|
-
|
|
156523
|
+
const written = await postYandexWrite(`keywords/${id}/search-bid`, { amount }, opts);
|
|
156524
|
+
const row = await tryCoverageRead(
|
|
156525
|
+
written.config,
|
|
156526
|
+
written.account,
|
|
156527
|
+
"keywords",
|
|
156528
|
+
{ id: Number(id) },
|
|
156529
|
+
opts.verbose
|
|
156530
|
+
);
|
|
156531
|
+
const lines = [
|
|
156532
|
+
receiptLine("\u5173\u952E\u8BCDID", id, row ? String(row["Id"] ?? row["id"] ?? id) : void 0),
|
|
156533
|
+
receiptLine("\u641C\u7D22\u51FA\u4EF7", amount, row ? "\u5DF2\u63D0\u4EA4" : void 0)
|
|
156534
|
+
];
|
|
156535
|
+
printWriteReceipt(row ? "submitted" : "unknown", lines);
|
|
156536
|
+
await emitYandexWrite(
|
|
154077
156537
|
opts,
|
|
156538
|
+
written.account,
|
|
154078
156539
|
"yandex-keyword-bid",
|
|
154079
|
-
"yandex-analysis keyword-bid"
|
|
156540
|
+
"yandex-analysis keyword-bid",
|
|
156541
|
+
written.payload
|
|
154080
156542
|
);
|
|
154081
156543
|
}
|
|
154082
156544
|
|
|
@@ -154976,7 +157438,7 @@ var GAP_ACTIONS = {
|
|
|
154976
157438
|
"google.remove-custom-audience": google("DELETE", "/custom-audiences/{account}/{id}", { needsId: true, needsBody: false }),
|
|
154977
157439
|
"google.goal": google("POST", "/goals/{account}"),
|
|
154978
157440
|
"google.campaign-goal-config": google("POST", "/campaign-goal-configs/{account}"),
|
|
154979
|
-
"google.remove-campaign-goal-config": google("DELETE", "/campaign-goal-configs/{account}/{id}
|
|
157441
|
+
"google.remove-campaign-goal-config": google("DELETE", "/campaign-goal-configs/{account}/{id}", { needsId: true, needsBody: false }),
|
|
154980
157442
|
"google.keyword-plan": google("POST", "/keyword-plans/{account}"),
|
|
154981
157443
|
"google.remove-keyword-plan": google("DELETE", "/keyword-plans/{account}/{id}", { needsId: true, needsBody: false }),
|
|
154982
157444
|
"google.keyword-plan-campaign": google("POST", "/keyword-plans/{account}/campaigns"),
|
|
@@ -155024,6 +157486,38 @@ var GAP_ACTIONS = {
|
|
|
155024
157486
|
function gapActionNames() {
|
|
155025
157487
|
return Object.keys(GAP_ACTIONS).sort();
|
|
155026
157488
|
}
|
|
157489
|
+
var READ_AFTER_WRITE = {
|
|
157490
|
+
"meta.outcome-campaign": "meta.read-campaign",
|
|
157491
|
+
"meta.outcome-campaign-update": "meta.read-campaign",
|
|
157492
|
+
"meta.advantage-campaign": "meta.read-campaign",
|
|
157493
|
+
"meta.outcome-adset": "meta.read-adset",
|
|
157494
|
+
"meta.advantage-adset": "meta.read-adset",
|
|
157495
|
+
"meta.outcome-ad": "meta.read-ad",
|
|
157496
|
+
"meta.copy-campaign": "meta.read-campaign",
|
|
157497
|
+
"meta.copy-adset": "meta.read-adset",
|
|
157498
|
+
"meta.copy-ad": "meta.read-ad",
|
|
157499
|
+
"bing.campaign-budget": "bing.read-budgets",
|
|
157500
|
+
"yandex.unified-campaign": "yandex.read-campaigns"
|
|
157501
|
+
};
|
|
157502
|
+
function findReadbackAction(writeName) {
|
|
157503
|
+
const named = READ_AFTER_WRITE[writeName];
|
|
157504
|
+
if (named && GAP_ACTIONS[named]) return named;
|
|
157505
|
+
const write = GAP_ACTIONS[writeName];
|
|
157506
|
+
if (!write || write.method === "GET") return null;
|
|
157507
|
+
const dot = writeName.indexOf(".");
|
|
157508
|
+
if (dot < 0) return null;
|
|
157509
|
+
const prefix = writeName.slice(0, dot + 1);
|
|
157510
|
+
const rest = writeName.slice(dot + 1).replace(/^(update-|delete-)/, "");
|
|
157511
|
+
for (const name2 of [`${prefix}read-${rest}`, `${prefix}read-${rest}s`]) {
|
|
157512
|
+
if (GAP_ACTIONS[name2]) return name2;
|
|
157513
|
+
}
|
|
157514
|
+
for (const [name2, action] of Object.entries(GAP_ACTIONS)) {
|
|
157515
|
+
if (name2 !== writeName && action.service === write.service && action.path === write.path && action.method === "GET") {
|
|
157516
|
+
return name2;
|
|
157517
|
+
}
|
|
157518
|
+
}
|
|
157519
|
+
return null;
|
|
157520
|
+
}
|
|
155027
157521
|
function resolveGapPath(actionName, target) {
|
|
155028
157522
|
const action = GAP_ACTIONS[actionName];
|
|
155029
157523
|
if (!action) {
|
|
@@ -155061,6 +157555,122 @@ init_auth();
|
|
|
155061
157555
|
init_cli_json_snapshot();
|
|
155062
157556
|
init_shared();
|
|
155063
157557
|
import { readFileSync as readFileSync22 } from "fs";
|
|
157558
|
+
|
|
157559
|
+
// src/commands/ad-gap/readback.ts
|
|
157560
|
+
init_auth();
|
|
157561
|
+
var COMPARE_KEYS = ["budget", "daily_budget", "amount", "status", "statusV2", "name", "countries"];
|
|
157562
|
+
function readCreatedId(payload) {
|
|
157563
|
+
if (!payload || typeof payload !== "object") return "";
|
|
157564
|
+
const row = payload;
|
|
157565
|
+
for (const key of ["id", "Id", "campaign_id", "campaignId", "adset_id", "ad_id"]) {
|
|
157566
|
+
const value = row[key];
|
|
157567
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
157568
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
157569
|
+
}
|
|
157570
|
+
if (row["data"] && typeof row["data"] === "object") return readCreatedId(row["data"]);
|
|
157571
|
+
return "";
|
|
157572
|
+
}
|
|
157573
|
+
function findDeep(value, key, depth = 0) {
|
|
157574
|
+
if (value == null || depth > 6) return void 0;
|
|
157575
|
+
if (Array.isArray(value)) {
|
|
157576
|
+
for (const item of value) {
|
|
157577
|
+
const hit = findDeep(item, key, depth + 1);
|
|
157578
|
+
if (hit !== void 0) return hit;
|
|
157579
|
+
}
|
|
157580
|
+
return void 0;
|
|
157581
|
+
}
|
|
157582
|
+
if (typeof value !== "object") return void 0;
|
|
157583
|
+
const row = value;
|
|
157584
|
+
if (Object.prototype.hasOwnProperty.call(row, key) && row[key] != null) {
|
|
157585
|
+
if (typeof row[key] !== "object" || Array.isArray(row[key])) return row[key];
|
|
157586
|
+
}
|
|
157587
|
+
for (const child of Object.values(row)) {
|
|
157588
|
+
const hit = findDeep(child, key, depth + 1);
|
|
157589
|
+
if (hit !== void 0) return hit;
|
|
157590
|
+
}
|
|
157591
|
+
return void 0;
|
|
157592
|
+
}
|
|
157593
|
+
function displayList(value) {
|
|
157594
|
+
if (Array.isArray(value)) return value.map((item) => String(item)).sort().join(",");
|
|
157595
|
+
return String(value);
|
|
157596
|
+
}
|
|
157597
|
+
function compareGapBody(body, payload, deleted) {
|
|
157598
|
+
if (deleted) {
|
|
157599
|
+
if (payload == null) {
|
|
157600
|
+
return [receiptLine("\u5BF9\u8C61", "\u5DF2\u5220\u9664", void 0)];
|
|
157601
|
+
}
|
|
157602
|
+
const status = findDeep(payload, "status") ?? findDeep(payload, "statusV2");
|
|
157603
|
+
const gone = status == null || /delete|removed|archive/i.test(String(status));
|
|
157604
|
+
return [receiptLine("\u5BF9\u8C61", "\u5DF2\u5220\u9664", gone ? "\u5DF2\u5220\u9664" : status)];
|
|
157605
|
+
}
|
|
157606
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
157607
|
+
return [receiptLine("\u5199\u5165", "\u5DF2\u63D0\u4EA4", payload == null ? void 0 : "\u5DF2\u8BFB\u56DE")];
|
|
157608
|
+
}
|
|
157609
|
+
const lines = [];
|
|
157610
|
+
const record2 = body;
|
|
157611
|
+
for (const key of COMPARE_KEYS) {
|
|
157612
|
+
if (record2[key] == null || typeof record2[key] === "object" && !Array.isArray(record2[key])) continue;
|
|
157613
|
+
const expected = Array.isArray(record2[key]) ? displayList(record2[key]) : record2[key];
|
|
157614
|
+
const actualRaw = findDeep(payload, key);
|
|
157615
|
+
const actual = actualRaw == null ? void 0 : Array.isArray(actualRaw) ? displayList(actualRaw) : actualRaw;
|
|
157616
|
+
lines.push(receiptLine(key, expected, actual));
|
|
157617
|
+
}
|
|
157618
|
+
if (lines.length === 0) {
|
|
157619
|
+
lines.push(receiptLine("\u5199\u5165", "\u5DF2\u63D0\u4EA4", payload == null ? void 0 : "\u5DF2\u8BFB\u56DE"));
|
|
157620
|
+
}
|
|
157621
|
+
return lines;
|
|
157622
|
+
}
|
|
157623
|
+
async function printAdGapReadback(opts) {
|
|
157624
|
+
const readName = findReadbackAction(opts.action);
|
|
157625
|
+
if (!readName) {
|
|
157626
|
+
printWriteReceipt("unknown", [receiptLine("\u8BFB\u56DE", "\u6709\u914D\u5BF9\u67E5\u8BE2", void 0)]);
|
|
157627
|
+
return;
|
|
157628
|
+
}
|
|
157629
|
+
const createdId = readCreatedId(opts.payload) || opts.id || "";
|
|
157630
|
+
const deleted = opts.action.includes("delete");
|
|
157631
|
+
let path61;
|
|
157632
|
+
let method;
|
|
157633
|
+
let needsBody;
|
|
157634
|
+
try {
|
|
157635
|
+
const resolved = resolveGapPath(readName, {
|
|
157636
|
+
account: opts.account,
|
|
157637
|
+
parent: opts.parent,
|
|
157638
|
+
id: createdId,
|
|
157639
|
+
label: opts.label
|
|
157640
|
+
});
|
|
157641
|
+
path61 = resolved.path;
|
|
157642
|
+
method = resolved.action.method;
|
|
157643
|
+
needsBody = resolved.action.needsBody !== false;
|
|
157644
|
+
} catch {
|
|
157645
|
+
printWriteReceipt("unknown", [receiptLine("\u8BFB\u56DE", readName, void 0)]);
|
|
157646
|
+
return;
|
|
157647
|
+
}
|
|
157648
|
+
const config = loadConfig(opts.token);
|
|
157649
|
+
let readPayload;
|
|
157650
|
+
try {
|
|
157651
|
+
readPayload = await apiFetch2(
|
|
157652
|
+
opts.serviceBase(resolveGapPath(readName, { account: opts.account, id: createdId, parent: opts.parent, label: opts.label }).action.service, config) + path61,
|
|
157653
|
+
config,
|
|
157654
|
+
{
|
|
157655
|
+
method,
|
|
157656
|
+
body: needsBody ? JSON.stringify(opts.body ?? {}) : void 0
|
|
157657
|
+
},
|
|
157658
|
+
opts.verbose
|
|
157659
|
+
);
|
|
157660
|
+
} catch (err) {
|
|
157661
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
157662
|
+
if (deleted && /404|未找到|not found/i.test(message)) {
|
|
157663
|
+
printWriteReceipt("verified", [receiptLine("\u5BF9\u8C61", "\u5DF2\u5220\u9664", "\u5DF2\u5220\u9664")]);
|
|
157664
|
+
return;
|
|
157665
|
+
}
|
|
157666
|
+
printWriteReceipt("unknown", [receiptLine("\u8BFB\u56DE", readName, void 0)]);
|
|
157667
|
+
return;
|
|
157668
|
+
}
|
|
157669
|
+
const lines = compareGapBody(opts.body, readPayload, deleted);
|
|
157670
|
+
printWriteReceipt(judgeReceipt(lines), lines);
|
|
157671
|
+
}
|
|
157672
|
+
|
|
157673
|
+
// src/commands/ad-gap/run.ts
|
|
155064
157674
|
function readGapBody(opts, required) {
|
|
155065
157675
|
const inline = opts.body?.trim();
|
|
155066
157676
|
const file = opts.bodyFile?.trim();
|
|
@@ -155218,6 +157828,20 @@ async function runAdGap(opts) {
|
|
|
155218
157828
|
if (resolved.action.service === "tiktok") {
|
|
155219
157829
|
assertTikTokAccepted(payload);
|
|
155220
157830
|
}
|
|
157831
|
+
if (resolved.action.method !== "GET") {
|
|
157832
|
+
await printAdGapReadback({
|
|
157833
|
+
action: opts.action,
|
|
157834
|
+
account: opts.account,
|
|
157835
|
+
parent: opts.parent,
|
|
157836
|
+
id: opts.id,
|
|
157837
|
+
label: opts.label,
|
|
157838
|
+
token: opts.token,
|
|
157839
|
+
verbose: opts.verbose,
|
|
157840
|
+
body,
|
|
157841
|
+
payload,
|
|
157842
|
+
serviceBase
|
|
157843
|
+
});
|
|
157844
|
+
}
|
|
155221
157845
|
const emitted = await emitCliJsonOrSnapshot(
|
|
155222
157846
|
{ jsonOut: opts.jsonOut },
|
|
155223
157847
|
{
|