siluzan-tso-cli 1.1.68 → 1.1.69-beta.1
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 +2 -1
- package/dist/index.js +1279 -123
- package/dist/skill/AGENTS.md +1 -1
- package/dist/skill/SKILL.md +17 -13
- package/dist/skill/_meta.json +2 -2
- package/dist/skill/references/README.md +4 -4
- package/dist/skill/references/accounts/accounts-list.md +1 -1
- package/dist/skill/references/accounts/accounts-permissions.md +2 -2
- package/dist/skill/references/accounts/finance.md +1 -1
- package/dist/skill/references/accounts/open-account-by-media.md +1 -1
- package/dist/skill/references/accounts/open-account-google-ui.md +1 -1
- package/dist/skill/references/analytics/account-analytics.md +6 -6
- package/dist/skill/references/analytics/rag.md +1 -1
- package/dist/skill/references/analytics/reporting.md +5 -5
- package/dist/skill/references/core/intent-routing.md +7 -5
- package/dist/skill/references/core/setup.md +5 -5
- package/dist/skill/references/core/workflows.md +2 -2
- package/dist/skill/references/google-ads/google-ads-read.md +30 -0
- package/dist/skill/references/google-ads/google-ads-write.md +65 -2
- package/dist/skill/references/google-ads/google-ads.md +1 -1
- package/dist/skill/references/meta-ads/meta-ads-write.md +2 -1
- package/dist/skill/references/meta-ads/meta-ads.md +2 -1
- package/dist/skill/references/misc/tso-home.md +2 -2
- package/dist/skill/references/operations/ad-gap.md +234 -0
- package/dist/skill/references/operations/hosted-automation-bing.md +3 -3
- package/dist/skill/references/operations/hosted-automation-scenarios.md +3 -3
- package/dist/skill/references/operations/hosted-automation-self-control.md +1 -1
- package/dist/skill/references/operations/hosted-automation-tiktok.md +3 -3
- package/dist/skill/references/operations/hosted-automation-user-catalog.md +7 -7
- package/dist/skill/references/operations/hosted-automation-yandex.md +3 -3
- package/dist/skill/scripts/install.ps1 +3 -3
- package/dist/skill/scripts/install.sh +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2397,7 +2397,7 @@ function rawRequest(url, options) {
|
|
|
2397
2397
|
stream = res.pipe(zlib.createBrotliDecompress());
|
|
2398
2398
|
}
|
|
2399
2399
|
let failed = false;
|
|
2400
|
-
const
|
|
2400
|
+
const fail8 = (err) => {
|
|
2401
2401
|
if (failed) return;
|
|
2402
2402
|
failed = true;
|
|
2403
2403
|
res.destroy();
|
|
@@ -2416,7 +2416,7 @@ function rawRequest(url, options) {
|
|
|
2416
2416
|
reject(err);
|
|
2417
2417
|
};
|
|
2418
2418
|
const onStreamError = (err) => {
|
|
2419
|
-
|
|
2419
|
+
fail8(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
|
|
2420
2420
|
};
|
|
2421
2421
|
if (stream !== res) stream.on("error", onStreamError);
|
|
2422
2422
|
res.on("error", onStreamError);
|
|
@@ -2427,7 +2427,7 @@ function rawRequest(url, options) {
|
|
|
2427
2427
|
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
2428
2428
|
byteLen += buf.length;
|
|
2429
2429
|
if (maxBytes > 0 && byteLen > maxBytes) {
|
|
2430
|
-
|
|
2430
|
+
fail8(
|
|
2431
2431
|
new Error(`\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650\uFF08${(maxBytes / 1024 / 1024).toFixed(0)} MB\uFF09\uFF0C\u5DF2\u4E2D\u65AD\u8FDE\u63A5`)
|
|
2432
2432
|
);
|
|
2433
2433
|
return;
|
|
@@ -2540,15 +2540,15 @@ function messageFromJsonValue(value) {
|
|
|
2540
2540
|
const rec = value;
|
|
2541
2541
|
if (rec.errors && typeof rec.errors === "object" && !Array.isArray(rec.errors)) {
|
|
2542
2542
|
const msgs = [];
|
|
2543
|
-
for (const [
|
|
2543
|
+
for (const [field6, raw] of Object.entries(rec.errors)) {
|
|
2544
2544
|
if (Array.isArray(raw)) {
|
|
2545
2545
|
for (const item of raw) {
|
|
2546
2546
|
const msg = messageFromJsonValue(item);
|
|
2547
|
-
if (msg) msgs.push(`${
|
|
2547
|
+
if (msg) msgs.push(`${field6}: ${msg}`);
|
|
2548
2548
|
}
|
|
2549
2549
|
} else {
|
|
2550
2550
|
const msg = messageFromJsonValue(raw);
|
|
2551
|
-
if (msg) msgs.push(`${
|
|
2551
|
+
if (msg) msgs.push(`${field6}: ${msg}`);
|
|
2552
2552
|
}
|
|
2553
2553
|
}
|
|
2554
2554
|
if (msgs.length > 0) return msgs.join("; ");
|
|
@@ -4104,7 +4104,7 @@ var DEFAULT_API_BASE;
|
|
|
4104
4104
|
var init_defaults = __esm({
|
|
4105
4105
|
"src/config/defaults.ts"() {
|
|
4106
4106
|
"use strict";
|
|
4107
|
-
DEFAULT_API_BASE = "https://tso-api.siluzan.com";
|
|
4107
|
+
DEFAULT_API_BASE = "https://tso-api-ci.siluzan.com";
|
|
4108
4108
|
}
|
|
4109
4109
|
});
|
|
4110
4110
|
|
|
@@ -9358,8 +9358,8 @@ var init_http_retry = __esm({
|
|
|
9358
9358
|
});
|
|
9359
9359
|
|
|
9360
9360
|
// src/commands/google-analysis/normalize-impression-shares.ts
|
|
9361
|
-
function normalizeShareValue(value, competitiveMetrics,
|
|
9362
|
-
const cmVal = competitiveMetrics?.[
|
|
9361
|
+
function normalizeShareValue(value, competitiveMetrics, field6) {
|
|
9362
|
+
const cmVal = competitiveMetrics?.[field6];
|
|
9363
9363
|
if (typeof cmVal === "number" && Number.isFinite(cmVal)) {
|
|
9364
9364
|
return cmVal;
|
|
9365
9365
|
}
|
|
@@ -9371,10 +9371,10 @@ function normalizeShareValue(value, competitiveMetrics, field5) {
|
|
|
9371
9371
|
function normalizeLegacyShareOnRow(row) {
|
|
9372
9372
|
const rawCm = row.competitiveMetrics;
|
|
9373
9373
|
const competitiveMetrics = rawCm !== null && typeof rawCm === "object" && !Array.isArray(rawCm) ? rawCm : null;
|
|
9374
|
-
for (const
|
|
9375
|
-
const v = row[
|
|
9374
|
+
for (const field6 of LEGACY_ROW_IMPRESSION_SHARE_FIELDS) {
|
|
9375
|
+
const v = row[field6];
|
|
9376
9376
|
if (typeof v !== "number" || !Number.isFinite(v)) continue;
|
|
9377
|
-
row[
|
|
9377
|
+
row[field6] = normalizeShareValue(v, competitiveMetrics, field6);
|
|
9378
9378
|
}
|
|
9379
9379
|
}
|
|
9380
9380
|
function normalizeRowsInArray(rows) {
|
|
@@ -107495,8 +107495,8 @@ var init_batch_runner = __esm({
|
|
|
107495
107495
|
shouldDowngrade(now = Date.now()) {
|
|
107496
107496
|
if (this.window.length < this.opts.windowSize) return false;
|
|
107497
107497
|
if (now - this.lastDowngradeAt < this.opts.cooldownMs) return false;
|
|
107498
|
-
const
|
|
107499
|
-
const rate2 =
|
|
107498
|
+
const fail8 = this.window.filter((s) => !s).length;
|
|
107499
|
+
const rate2 = fail8 / this.window.length;
|
|
107500
107500
|
if (rate2 >= this.opts.errorRateThreshold) {
|
|
107501
107501
|
this.lastDowngradeAt = now;
|
|
107502
107502
|
this.window.length = 0;
|
|
@@ -111952,13 +111952,13 @@ init_lang();
|
|
|
111952
111952
|
function moneyGte(leftYuan, rightYuan) {
|
|
111953
111953
|
return Math.round(leftYuan * 100) >= Math.round(rightYuan * 100);
|
|
111954
111954
|
}
|
|
111955
|
-
function isBudgetCircuitHit(spend,
|
|
111956
|
-
if (spend == null ||
|
|
111957
|
-
if (!Number.isFinite(spend) || !Number.isFinite(
|
|
111955
|
+
function isBudgetCircuitHit(spend, budgetYuan2, ratio) {
|
|
111956
|
+
if (spend == null || budgetYuan2 == null) return false;
|
|
111957
|
+
if (!Number.isFinite(spend) || !Number.isFinite(budgetYuan2) || !Number.isFinite(ratio)) {
|
|
111958
111958
|
return false;
|
|
111959
111959
|
}
|
|
111960
|
-
if (
|
|
111961
|
-
return moneyGte(spend,
|
|
111960
|
+
if (budgetYuan2 <= 0 || ratio <= 0) return false;
|
|
111961
|
+
return moneyGte(spend, budgetYuan2 * ratio);
|
|
111962
111962
|
}
|
|
111963
111963
|
function isZeroConvHit(spend, conversions, targetCpaYuan, multiple) {
|
|
111964
111964
|
if (spend == null || targetCpaYuan == null) return false;
|
|
@@ -116328,10 +116328,10 @@ function biddingStrategiesMatch(expected, actual) {
|
|
|
116328
116328
|
const act = String(actual ?? "").trim().toUpperCase();
|
|
116329
116329
|
return exp === "TARGET_CPA" && act === "MAXIMIZE_CONVERSIONS" || exp === "TARGET_ROAS" && act === "MAXIMIZE_CONVERSION_VALUE";
|
|
116330
116330
|
}
|
|
116331
|
-
function fieldCheck(
|
|
116332
|
-
if (!present) return { field:
|
|
116331
|
+
function fieldCheck(field6, expected, actual, present) {
|
|
116332
|
+
if (!present) return { field: field6, expected, actual: void 0, state: "unread" };
|
|
116333
116333
|
return {
|
|
116334
|
-
field:
|
|
116334
|
+
field: field6,
|
|
116335
116335
|
expected,
|
|
116336
116336
|
actual,
|
|
116337
116337
|
state: sameWriteValue(expected, actual) ? "match" : "mismatch"
|
|
@@ -116374,10 +116374,10 @@ function readKey(obj, keys) {
|
|
|
116374
116374
|
function evaluateCampaignReadback(after, expected, readFailed) {
|
|
116375
116375
|
if (readFailed || !after) return { verification: "unknown", checks: [] };
|
|
116376
116376
|
const checks = [];
|
|
116377
|
-
const push = (
|
|
116377
|
+
const push = (field6, expectedValue, keys) => {
|
|
116378
116378
|
if (expectedValue === void 0) return;
|
|
116379
116379
|
const found = readKey(after, keys);
|
|
116380
|
-
checks.push(fieldCheck(
|
|
116380
|
+
checks.push(fieldCheck(field6, expectedValue, found.value, found.present));
|
|
116381
116381
|
};
|
|
116382
116382
|
push("name", expected.name, ["name", "Name"]);
|
|
116383
116383
|
push("statusV2", expected.statusV2, ["statusV2", "StatusV2"]);
|
|
@@ -118095,46 +118095,46 @@ function validateRsaDisplayPath(prefix, ad, errors, lengthViolations) {
|
|
|
118095
118095
|
`${prefix} \u68C0\u6D4B\u5230\u5C0F\u5199 path2="${String(ad["path2"])}"\uFF0C\u540E\u7AEF\u5951\u7EA6\u5B57\u6BB5\u4E3A Path2\uFF08PascalCase\uFF09\uFF0C\u5F53\u524D\u63D0\u4EA4\u4E0D\u4F1A\u751F\u6548`
|
|
118096
118096
|
);
|
|
118097
118097
|
}
|
|
118098
|
-
for (const [
|
|
118098
|
+
for (const [field6, label2, example] of [
|
|
118099
118099
|
["Path1", "\u663E\u793A\u8DEF\u5F84\u7B2C 1 \u6BB5", '"Path1": "products"'],
|
|
118100
118100
|
["Path2", "\u663E\u793A\u8DEF\u5F84\u7B2C 2 \u6BB5", '"Path2": "steel"']
|
|
118101
118101
|
]) {
|
|
118102
|
-
const raw = ad[
|
|
118102
|
+
const raw = ad[field6];
|
|
118103
118103
|
if (raw === void 0) {
|
|
118104
118104
|
pushErr2(
|
|
118105
118105
|
errors,
|
|
118106
|
-
`${prefix}.${
|
|
118106
|
+
`${prefix}.${field6} \u5B57\u6BB5\u7F3A\u5931\uFF08RSA \u5FC5\u586B\uFF09\u3002${label2}\uFF0C\u5C55\u793A\u4E3A finalUrl \u57DF\u540D\u540E\u7684\u8DEF\u5F84\u6BB5\uFF08\u226415 \u5B57\u7B26\uFF0CCJK \u6309 2 \u8BA1\uFF09\u3002${RSA_PATH_BACKEND_HINT}\u3002${jsonHint}\u3002\u793A\u4F8B\uFF1A${example}`
|
|
118107
118107
|
);
|
|
118108
118108
|
continue;
|
|
118109
118109
|
}
|
|
118110
118110
|
if (raw === null) {
|
|
118111
118111
|
pushErr2(
|
|
118112
118112
|
errors,
|
|
118113
|
-
`${prefix}.${
|
|
118113
|
+
`${prefix}.${field6} \u4E3A null\uFF08RSA \u5FC5\u586B\uFF0C\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u53EF\u586B ""\uFF09\u3002${RSA_PATH_BACKEND_HINT}\u3002${jsonHint}\u3002\u793A\u4F8B\uFF1A${example}`
|
|
118114
118114
|
);
|
|
118115
118115
|
continue;
|
|
118116
118116
|
}
|
|
118117
118117
|
if (typeof raw !== "string") {
|
|
118118
|
-
pushErr2(errors, `${prefix}.${
|
|
118118
|
+
pushErr2(errors, `${prefix}.${field6} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u7C7B\u578B\u4E3A ${typeof raw}\u3002${jsonHint}`);
|
|
118119
118119
|
continue;
|
|
118120
118120
|
}
|
|
118121
118121
|
const len = calcGoogleCharLength(raw);
|
|
118122
118122
|
if (len > 15) {
|
|
118123
118123
|
pushLengthViolation(lengthViolations, {
|
|
118124
|
-
path: `${prefix}.${
|
|
118125
|
-
field:
|
|
118124
|
+
path: `${prefix}.${field6}`,
|
|
118125
|
+
field: field6,
|
|
118126
118126
|
kind: "rsa_path",
|
|
118127
118127
|
limit: 15,
|
|
118128
118128
|
actual: len,
|
|
118129
118129
|
countMode: "google",
|
|
118130
118130
|
text: raw
|
|
118131
118131
|
});
|
|
118132
|
-
pushErr2(errors, `${prefix}.${
|
|
118132
|
+
pushErr2(errors, `${prefix}.${field6} \u8D85\u8FC7 15 \u5B57\u7B26\uFF08\u5F53\u524D ${len}\uFF0CCJK \u6309 2 \u8BA1\uFF09\uFF1A"${raw}"`);
|
|
118133
118133
|
}
|
|
118134
118134
|
if (raw.length > 0 && !PATH_SEGMENT_REGEX.test(raw)) {
|
|
118135
118135
|
pushErr2(
|
|
118136
118136
|
errors,
|
|
118137
|
-
`${prefix}.${
|
|
118137
|
+
`${prefix}.${field6} \u542B\u975E\u6CD5\u5B57\u7B26\u6216\u683C\u5F0F\uFF08\u4EC5\u5141\u8BB8\u5C0F\u5199 a-z\u30010-9\u3001\u8FDE\u5B57\u7B26\uFF0C\u4E14\u4E0D\u80FD\u4EE5\u8FDE\u5B57\u7B26\u5F00\u5934/\u7ED3\u5C3E\uFF09\uFF1A"${raw}"`
|
|
118138
118138
|
);
|
|
118139
118139
|
}
|
|
118140
118140
|
}
|
|
@@ -118173,10 +118173,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
|
|
|
118173
118173
|
for (let i = 0; i < headlines.length; i++) {
|
|
118174
118174
|
const len = calcGoogleCharLength(headlines[i]);
|
|
118175
118175
|
if (len > 30) {
|
|
118176
|
-
const
|
|
118176
|
+
const field6 = headlineFields[i] ?? `headline[${i}]`;
|
|
118177
118177
|
pushLengthViolation(lengthViolations, {
|
|
118178
|
-
path: `${prefix}.${
|
|
118179
|
-
field:
|
|
118178
|
+
path: `${prefix}.${field6}`,
|
|
118179
|
+
field: field6,
|
|
118180
118180
|
kind: "rsa_headline",
|
|
118181
118181
|
limit: 30,
|
|
118182
118182
|
actual: len,
|
|
@@ -118208,10 +118208,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
|
|
|
118208
118208
|
for (let i = 0; i < descriptions.length; i++) {
|
|
118209
118209
|
const len = calcGoogleCharLength(descriptions[i]);
|
|
118210
118210
|
if (len > 90) {
|
|
118211
|
-
const
|
|
118211
|
+
const field6 = descriptionFields[i] ?? `description[${i}]`;
|
|
118212
118212
|
pushLengthViolation(lengthViolations, {
|
|
118213
|
-
path: `${prefix}.${
|
|
118214
|
-
field:
|
|
118213
|
+
path: `${prefix}.${field6}`,
|
|
118214
|
+
field: field6,
|
|
118215
118215
|
kind: "rsa_description",
|
|
118216
118216
|
limit: 90,
|
|
118217
118217
|
actual: len,
|
|
@@ -123033,13 +123033,13 @@ function livePoolHasText(pool, text5) {
|
|
|
123033
123033
|
function listPlannedRsaAssets(ad, groupPath, adIndex, adGroupName) {
|
|
123034
123034
|
const base2 = `${groupPath}.AdsForBatchJob[${adIndex}]`;
|
|
123035
123035
|
const out = [];
|
|
123036
|
-
const push = (kind,
|
|
123036
|
+
const push = (kind, field6, raw) => {
|
|
123037
123037
|
if (typeof raw !== "string" || !raw.trim()) return;
|
|
123038
123038
|
out.push({
|
|
123039
|
-
path: `${base2}.${
|
|
123039
|
+
path: `${base2}.${field6}`,
|
|
123040
123040
|
adGroupName,
|
|
123041
123041
|
kind,
|
|
123042
|
-
field:
|
|
123042
|
+
field: field6,
|
|
123043
123043
|
text: raw.trim()
|
|
123044
123044
|
});
|
|
123045
123045
|
};
|
|
@@ -124778,10 +124778,10 @@ function validateTextLengths(errors, lengthViolations, texts, arrayField, kind,
|
|
|
124778
124778
|
texts.forEach((text5, i) => {
|
|
124779
124779
|
const len = calcGoogleCharLength(text5);
|
|
124780
124780
|
if (len > limit) {
|
|
124781
|
-
const
|
|
124781
|
+
const field6 = `${arrayField}[${i}]`;
|
|
124782
124782
|
pushLengthViolation(lengthViolations, {
|
|
124783
|
-
path:
|
|
124784
|
-
field:
|
|
124783
|
+
path: field6,
|
|
124784
|
+
field: field6,
|
|
124785
124785
|
kind,
|
|
124786
124786
|
limit,
|
|
124787
124787
|
actual: len,
|
|
@@ -128327,6 +128327,420 @@ async function runAdPmaxBrandGuidelinesEnable(opts) {
|
|
|
128327
128327
|
});
|
|
128328
128328
|
}
|
|
128329
128329
|
|
|
128330
|
+
// src/commands/ad/search-ops.ts
|
|
128331
|
+
init_auth();
|
|
128332
|
+
init_cli_json_snapshot();
|
|
128333
|
+
init_cli_table();
|
|
128334
|
+
init_shared();
|
|
128335
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
128336
|
+
var SCHEDULE_DAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
128337
|
+
var SCHEDULE_MINUTES = ["Zero", "Fifteen", "Thirty", "FortyFive"];
|
|
128338
|
+
var AUDIENCE_KINDS = {
|
|
128339
|
+
"user-list": { path: "userlist", listType: "USER_LIST", idField: "UserListId" },
|
|
128340
|
+
"user-interest": { path: "userinterest", listType: "USER_INTEREST", idField: "UserInterestId" },
|
|
128341
|
+
gender: {
|
|
128342
|
+
path: "gender",
|
|
128343
|
+
listType: "GENDER",
|
|
128344
|
+
enumField: "GenderTypeV2",
|
|
128345
|
+
values: ["Male", "Female", "Undetermined"]
|
|
128346
|
+
},
|
|
128347
|
+
age: {
|
|
128348
|
+
path: "agerange",
|
|
128349
|
+
listType: "AGE_RANGE",
|
|
128350
|
+
enumField: "AgeRangeTypeV2",
|
|
128351
|
+
values: ["AgeRange1824", "AgeRange2534", "AgeRange3544", "AgeRange4554", "AgeRange5564", "AgeRange65Up", "AgeRangeUndetermined"]
|
|
128352
|
+
},
|
|
128353
|
+
income: {
|
|
128354
|
+
path: "incomerange",
|
|
128355
|
+
listType: "INCOME_RANGE",
|
|
128356
|
+
enumField: "IncomeRangeTypeV2",
|
|
128357
|
+
values: ["IncomeRange050", "IncomeRange5060", "IncomeRange6070", "IncomeRange7080", "IncomeRange8090", "IncomeRange90Up", "IncomeRangeUndetermined"]
|
|
128358
|
+
},
|
|
128359
|
+
parent: {
|
|
128360
|
+
path: "parent",
|
|
128361
|
+
listType: "PARENTAL_STATUS",
|
|
128362
|
+
enumField: "ParentTypeV2",
|
|
128363
|
+
values: ["Parent", "NotAParent", "Undetermined"]
|
|
128364
|
+
}
|
|
128365
|
+
};
|
|
128366
|
+
function fail3(err, label2) {
|
|
128367
|
+
console.error(`
|
|
128368
|
+
\u274C ${label2}\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
128369
|
+
`);
|
|
128370
|
+
process.exit(1);
|
|
128371
|
+
}
|
|
128372
|
+
function field5(item, ...keys) {
|
|
128373
|
+
for (const key of keys) {
|
|
128374
|
+
const value = item[key];
|
|
128375
|
+
if (value != null && String(value).trim() !== "") return String(value);
|
|
128376
|
+
}
|
|
128377
|
+
return "";
|
|
128378
|
+
}
|
|
128379
|
+
function accountBase3(opts) {
|
|
128380
|
+
const resolved = withResolvedAdAccount(opts);
|
|
128381
|
+
const config = loadConfig(resolved.token);
|
|
128382
|
+
return { config, base: requireGoogleApi(config), account: resolved.account };
|
|
128383
|
+
}
|
|
128384
|
+
function asRows(data) {
|
|
128385
|
+
if (Array.isArray(data)) return data.filter((row) => row && typeof row === "object");
|
|
128386
|
+
if (data && typeof data === "object") {
|
|
128387
|
+
const obj = data;
|
|
128388
|
+
for (const key of ["items", "Items", "data", "Data"]) {
|
|
128389
|
+
if (Array.isArray(obj[key])) return asRows(obj[key]);
|
|
128390
|
+
}
|
|
128391
|
+
}
|
|
128392
|
+
return [];
|
|
128393
|
+
}
|
|
128394
|
+
function parseAudienceKind(raw) {
|
|
128395
|
+
const kind = (raw ?? "").trim();
|
|
128396
|
+
if (!AUDIENCE_KINDS[kind]) {
|
|
128397
|
+
throw new Error(`--kind \u65E0\u6548\uFF08${raw ?? ""}\uFF09\u3002\u5408\u6CD5\u503C\uFF1A${Object.keys(AUDIENCE_KINDS).join(" | ")}`);
|
|
128398
|
+
}
|
|
128399
|
+
return kind;
|
|
128400
|
+
}
|
|
128401
|
+
function buildAudienceBody(input) {
|
|
128402
|
+
const spec = AUDIENCE_KINDS[input.kind];
|
|
128403
|
+
const target = (input.target ?? "").trim();
|
|
128404
|
+
if (!target) throw new Error("--target \u4E0D\u80FD\u4E3A\u7A7A");
|
|
128405
|
+
if (!/^\d+$/.test(input.adGroupId)) throw new Error("--ad-group-id \u987B\u4E3A\u6570\u5B57");
|
|
128406
|
+
const body = {
|
|
128407
|
+
AdGroupId: input.adGroupId,
|
|
128408
|
+
TypeV2: spec.listType
|
|
128409
|
+
};
|
|
128410
|
+
if ("idField" in spec) {
|
|
128411
|
+
if (!/^\d+$/.test(target)) throw new Error(`${input.kind} \u7684 --target \u987B\u4E3A\u6570\u5B57 ID`);
|
|
128412
|
+
body[spec.idField] = Number(target);
|
|
128413
|
+
} else if (!spec.values.includes(target)) {
|
|
128414
|
+
throw new Error(`--target \u65E0\u6548\uFF08${target}\uFF09\u3002\u5408\u6CD5\u503C\uFF1A${spec.values.join(" | ")}`);
|
|
128415
|
+
} else {
|
|
128416
|
+
body[spec.enumField] = target;
|
|
128417
|
+
}
|
|
128418
|
+
if (input.negative && input.bidModifier != null) {
|
|
128419
|
+
throw new Error("\u5426\u5B9A\u53D7\u4F17\u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E --bid-modifier");
|
|
128420
|
+
}
|
|
128421
|
+
if (input.bidModifier != null) {
|
|
128422
|
+
if (!Number.isFinite(input.bidModifier) || input.bidModifier < 0 || input.bidModifier > 10) {
|
|
128423
|
+
throw new Error("--bid-modifier \u662F\u500D\u7387\uFF0C\u8303\u56F4 0 \u5230 10\uFF081.2 = +20%\uFF0C0 = \u6392\u9664\uFF09");
|
|
128424
|
+
}
|
|
128425
|
+
const percent = multiplierToAdGroupBidPercent(input.bidModifier);
|
|
128426
|
+
if (percent !== 0) {
|
|
128427
|
+
body.BidModifier = percent;
|
|
128428
|
+
body.BidModifierSpecified = true;
|
|
128429
|
+
}
|
|
128430
|
+
}
|
|
128431
|
+
return body;
|
|
128432
|
+
}
|
|
128433
|
+
function parseAdSchedules(raw) {
|
|
128434
|
+
if (!Array.isArray(raw)) throw new Error("\u65F6\u6BB5\u6587\u4EF6\u5FC5\u987B\u662F JSON \u6570\u7EC4\uFF1B\u6E05\u7A7A\u4F20 []");
|
|
128435
|
+
return raw.map((item, index) => {
|
|
128436
|
+
if (!item || typeof item !== "object") throw new Error(`\u7B2C ${index + 1} \u6761\u65F6\u6BB5\u4E0D\u662F\u5BF9\u8C61`);
|
|
128437
|
+
const row = item;
|
|
128438
|
+
const day = String(row.DayOfWeekV2 ?? row.dayOfWeekV2 ?? "");
|
|
128439
|
+
const startMinute = String(row.StartMinuteV2 ?? row.startMinuteV2 ?? "Zero");
|
|
128440
|
+
const endMinute = String(row.EndMinuteV2 ?? row.endMinuteV2 ?? "Zero");
|
|
128441
|
+
const startHour = Number(row.StartHour ?? row.startHour);
|
|
128442
|
+
const endHour = Number(row.EndHour ?? row.endHour);
|
|
128443
|
+
const prefix = `\u7B2C ${index + 1} \u6761`;
|
|
128444
|
+
if (!SCHEDULE_DAYS.includes(day)) {
|
|
128445
|
+
throw new Error(`${prefix} DayOfWeekV2 \u65E0\u6548\uFF08${day}\uFF09\u3002\u5408\u6CD5\u503C\uFF1A${SCHEDULE_DAYS.join(" | ")}`);
|
|
128446
|
+
}
|
|
128447
|
+
if (!Number.isInteger(startHour) || startHour < 0 || startHour > 23) {
|
|
128448
|
+
throw new Error(`${prefix} StartHour \u5FC5\u987B\u662F 0\u201323 \u7684\u6574\u6570`);
|
|
128449
|
+
}
|
|
128450
|
+
if (!Number.isInteger(endHour) || endHour < 1 || endHour > 24) {
|
|
128451
|
+
throw new Error(`${prefix} EndHour \u5FC5\u987B\u662F 1\u201324 \u7684\u6574\u6570`);
|
|
128452
|
+
}
|
|
128453
|
+
if (!SCHEDULE_MINUTES.includes(startMinute) || !SCHEDULE_MINUTES.includes(endMinute)) {
|
|
128454
|
+
throw new Error(`${prefix} \u5206\u949F\u53EA\u63A5\u53D7 ${SCHEDULE_MINUTES.join(" | ")}`);
|
|
128455
|
+
}
|
|
128456
|
+
const schedule = {
|
|
128457
|
+
DayOfWeekV2: day,
|
|
128458
|
+
StartHour: startHour,
|
|
128459
|
+
EndHour: endHour,
|
|
128460
|
+
StartMinuteV2: startMinute,
|
|
128461
|
+
EndMinuteV2: endMinute
|
|
128462
|
+
};
|
|
128463
|
+
const bid = row.BidModifier ?? row.bidModifier;
|
|
128464
|
+
if (bid != null && bid !== "") {
|
|
128465
|
+
const percent = Number(bid);
|
|
128466
|
+
if (!Number.isFinite(percent) || percent < -100 || percent > 900) {
|
|
128467
|
+
throw new Error(`${prefix} BidModifier \u662F\u767E\u5206\u6BD4\uFF0C\u8303\u56F4 -100 \u5230 900\uFF0820 = +20%\uFF09`);
|
|
128468
|
+
}
|
|
128469
|
+
if (percent !== 0 && Math.abs(percent) < 2 && !Number.isInteger(percent)) {
|
|
128470
|
+
throw new Error(`${prefix} BidModifier=${percent} \u50CF\u500D\u7387\u3002\u65F6\u6BB5\u7528\u767E\u5206\u6BD4\uFF1A-20 \u8868\u793A\u964D 20%\uFF0C\u4E0D\u8981\u5199 0.8`);
|
|
128471
|
+
}
|
|
128472
|
+
schedule.BidModifier = percent;
|
|
128473
|
+
}
|
|
128474
|
+
return schedule;
|
|
128475
|
+
});
|
|
128476
|
+
}
|
|
128477
|
+
function readAdSchedulesFile(filePath) {
|
|
128478
|
+
let parsed;
|
|
128479
|
+
try {
|
|
128480
|
+
parsed = JSON.parse(readFileSync15(filePath, "utf8"));
|
|
128481
|
+
} catch (err) {
|
|
128482
|
+
throw new Error(`\u8BFB\u65F6\u6BB5\u6587\u4EF6\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128483
|
+
}
|
|
128484
|
+
return parseAdSchedules(parsed);
|
|
128485
|
+
}
|
|
128486
|
+
async function runAdAuctionInsights(opts) {
|
|
128487
|
+
let range;
|
|
128488
|
+
try {
|
|
128489
|
+
range = hyphenRange(opts.start, opts.end, "\u7ADE\u4EF7\u6D1E\u5BDF");
|
|
128490
|
+
} catch (err) {
|
|
128491
|
+
fail3(err, "\u53C2\u6570");
|
|
128492
|
+
}
|
|
128493
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128494
|
+
const params = new URLSearchParams({ startDate: range.start, endDate: range.end });
|
|
128495
|
+
if (opts.campaignId?.trim()) params.set("campaignId", opts.campaignId.trim());
|
|
128496
|
+
const url = `${base2}/campaignmanagement/accounts/${account}/auction-insights?${params}`;
|
|
128497
|
+
let items3;
|
|
128498
|
+
try {
|
|
128499
|
+
items3 = asRows(await apiFetch2(url, config, {}, opts.verbose));
|
|
128500
|
+
} catch (err) {
|
|
128501
|
+
fail3(err, "\u67E5\u8BE2\u7ADE\u4EF7\u6D1E\u5BDF\u5931\u8D25");
|
|
128502
|
+
}
|
|
128503
|
+
const payload = { account, ...range, campaignId: opts.campaignId ?? "", count: items3.length, items: items3 };
|
|
128504
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-auction-insights", commandLabel: "ad auction-insights", payload })) return;
|
|
128505
|
+
console.log(`
|
|
128506
|
+
\u7ADE\u4EF7\u6D1E\u5BDF ${range.start} ~ ${range.end}\uFF08${items3.length} \u6761\uFF09
|
|
128507
|
+
`);
|
|
128508
|
+
printCliTable(
|
|
128509
|
+
items3.map((item) => ({
|
|
128510
|
+
campaignId: field5(item, "campaignId", "CampaignId"),
|
|
128511
|
+
campaignName: field5(item, "campaignName", "CampaignName"),
|
|
128512
|
+
domain: field5(item, "domain", "Domain"),
|
|
128513
|
+
impressionShare: field5(item, "impressionShare", "ImpressionShare")
|
|
128514
|
+
})),
|
|
128515
|
+
[
|
|
128516
|
+
{ key: "campaignId", header: "\u7CFB\u5217" },
|
|
128517
|
+
{ key: "campaignName", header: "\u540D\u79F0" },
|
|
128518
|
+
{ key: "domain", header: "\u57DF\u540D" },
|
|
128519
|
+
{ key: "impressionShare", header: "\u5C55\u793A\u4EFD\u989D" }
|
|
128520
|
+
]
|
|
128521
|
+
);
|
|
128522
|
+
console.log();
|
|
128523
|
+
}
|
|
128524
|
+
async function listBudgets(opts) {
|
|
128525
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128526
|
+
const url = `${base2}/budgetmanagement/budgets/${account}`;
|
|
128527
|
+
const items3 = asRows(await apiFetch2(url, config, {}, opts.verbose));
|
|
128528
|
+
return { config, base: base2, account, items: items3 };
|
|
128529
|
+
}
|
|
128530
|
+
function budgetYuan(item) {
|
|
128531
|
+
const raw = item.amount ?? item.Amount;
|
|
128532
|
+
const yuan = toDisplayMoney(typeof raw === "number" ? raw : Number(raw));
|
|
128533
|
+
return yuan == null ? "" : String(yuan);
|
|
128534
|
+
}
|
|
128535
|
+
async function runAdSharedBudgetList(opts) {
|
|
128536
|
+
let items3;
|
|
128537
|
+
let account = opts.account;
|
|
128538
|
+
try {
|
|
128539
|
+
const listed = await listBudgets(opts);
|
|
128540
|
+
items3 = listed.items;
|
|
128541
|
+
account = listed.account;
|
|
128542
|
+
} catch (err) {
|
|
128543
|
+
fail3(err, "\u67E5\u8BE2\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
128544
|
+
}
|
|
128545
|
+
const view = items3.map((item) => ({
|
|
128546
|
+
...item,
|
|
128547
|
+
amountYuan: budgetYuan(item)
|
|
128548
|
+
}));
|
|
128549
|
+
const payload = { account, count: view.length, items: view };
|
|
128550
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-shared-budget", commandLabel: "ad shared-budget list", payload })) return;
|
|
128551
|
+
console.log(`
|
|
128552
|
+
\u5171\u4EAB\u9884\u7B97\uFF08${view.length} \u6761\uFF09\u3002amountYuan \u662F\u4E3B\u5E01\u79CD\u5143\u3002
|
|
128553
|
+
`);
|
|
128554
|
+
printCliTable(
|
|
128555
|
+
view.map((item) => ({
|
|
128556
|
+
id: field5(item, "id", "Id"),
|
|
128557
|
+
name: field5(item, "name", "Name"),
|
|
128558
|
+
amountYuan: field5(item, "amountYuan"),
|
|
128559
|
+
status: field5(item, "statusV2", "StatusV2")
|
|
128560
|
+
})),
|
|
128561
|
+
[
|
|
128562
|
+
{ key: "id", header: "id" },
|
|
128563
|
+
{ key: "name", header: "\u540D\u79F0" },
|
|
128564
|
+
{ key: "amountYuan", header: "\u65E5\u9884\u7B97(\u5143)" },
|
|
128565
|
+
{ key: "status", header: "\u72B6\u6001" }
|
|
128566
|
+
]
|
|
128567
|
+
);
|
|
128568
|
+
console.log();
|
|
128569
|
+
}
|
|
128570
|
+
async function runAdSharedBudgetCreate(opts) {
|
|
128571
|
+
const name2 = (opts.name ?? "").trim();
|
|
128572
|
+
if (!name2) fail3(new Error("--name \u4E0D\u80FD\u4E3A\u7A7A"), "\u53C2\u6570");
|
|
128573
|
+
if (opts.amount == null || !Number.isFinite(opts.amount) || opts.amount <= 0) {
|
|
128574
|
+
fail3(new Error("--amount \u987B\u4E3A\u6B63\u6570\uFF0C\u5355\u4F4D\u662F\u4E3B\u5E01\u79CD\u5143"), "\u53C2\u6570");
|
|
128575
|
+
}
|
|
128576
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128577
|
+
const body = {
|
|
128578
|
+
Name: name2,
|
|
128579
|
+
Amount: toCentAmount(opts.amount),
|
|
128580
|
+
IsExplicitlyShared: true,
|
|
128581
|
+
BudgetBudgetDeliveryMethodV2: "STANDARD",
|
|
128582
|
+
StatusV2: "ENABLED"
|
|
128583
|
+
};
|
|
128584
|
+
const url = `${base2}/budgetmanagement/budgets/${account}`;
|
|
128585
|
+
try {
|
|
128586
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
|
|
128587
|
+
} catch (err) {
|
|
128588
|
+
fail3(err, "\u521B\u5EFA\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
128589
|
+
}
|
|
128590
|
+
console.log(`
|
|
128591
|
+
\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
|
|
128592
|
+
`);
|
|
128593
|
+
}
|
|
128594
|
+
async function runAdSharedBudgetUpdate(opts) {
|
|
128595
|
+
const budgetId = (opts.budgetId ?? "").trim();
|
|
128596
|
+
if (!/^\d+$/.test(budgetId)) fail3(new Error("--budget-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
128597
|
+
if (opts.amount != null && (!Number.isFinite(opts.amount) || opts.amount <= 0)) {
|
|
128598
|
+
fail3(new Error("--amount \u987B\u4E3A\u6B63\u6570\uFF0C\u5355\u4F4D\u662F\u4E3B\u5E01\u79CD\u5143"), "\u53C2\u6570");
|
|
128599
|
+
}
|
|
128600
|
+
let current;
|
|
128601
|
+
let config;
|
|
128602
|
+
let url = "";
|
|
128603
|
+
try {
|
|
128604
|
+
const listed = await listBudgets(opts);
|
|
128605
|
+
config = listed.config;
|
|
128606
|
+
current = listed.items.find((item) => field5(item, "id", "Id") === budgetId);
|
|
128607
|
+
url = `${listed.base}/budgetmanagement/budgets/${listed.account}/${budgetId}`;
|
|
128608
|
+
} catch (err) {
|
|
128609
|
+
fail3(err, "\u67E5\u8BE2\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
128610
|
+
}
|
|
128611
|
+
if (!current) fail3(new Error(`\u8D26\u6237\u91CC\u6CA1\u6709\u5171\u4EAB\u9884\u7B97 ${budgetId}`), "\u53C2\u6570");
|
|
128612
|
+
const name2 = (opts.name ?? "").trim() || field5(current, "name", "Name");
|
|
128613
|
+
const amountCents = opts.amount != null ? toCentAmount(opts.amount) : Number(current.amount ?? current.Amount);
|
|
128614
|
+
if (!name2 || !Number.isFinite(amountCents) || amountCents <= 0) {
|
|
128615
|
+
fail3(new Error("\u7F3A\u5C11\u540D\u79F0\u6216\u91D1\u989D\u3002\u5148 list\uFF0C\u518D\u4F20 --name / --amount"), "\u53C2\u6570");
|
|
128616
|
+
}
|
|
128617
|
+
const body = {
|
|
128618
|
+
Id: budgetId,
|
|
128619
|
+
Name: name2,
|
|
128620
|
+
Amount: amountCents,
|
|
128621
|
+
IsExplicitlyShared: true,
|
|
128622
|
+
BudgetBudgetDeliveryMethodV2: field5(current, "budgetBudgetDeliveryMethodV2", "BudgetBudgetDeliveryMethodV2") || "STANDARD",
|
|
128623
|
+
StatusV2: field5(current, "statusV2", "StatusV2") || "ENABLED"
|
|
128624
|
+
};
|
|
128625
|
+
try {
|
|
128626
|
+
await apiFetch2(url, config, { method: "PUT", body: JSON.stringify(body) }, opts.verbose);
|
|
128627
|
+
} catch (err) {
|
|
128628
|
+
fail3(err, "\u4FEE\u6539\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
128629
|
+
}
|
|
128630
|
+
console.log(`
|
|
128631
|
+
\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
|
|
128632
|
+
`);
|
|
128633
|
+
}
|
|
128634
|
+
async function runAdSharedBudgetDelete(opts) {
|
|
128635
|
+
const budgetId = (opts.budgetId ?? "").trim();
|
|
128636
|
+
if (!/^\d+$/.test(budgetId)) fail3(new Error("--budget-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
128637
|
+
if (!opts.iConfirm) fail3(new Error("\u5220\u9664\u5171\u4EAB\u9884\u7B97\u987B\u5148 list \u5E76\u5411\u7528\u6237\u786E\u8BA4\uFF0C\u518D\u52A0 --i-confirm"), "\u53C2\u6570");
|
|
128638
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128639
|
+
const url = `${base2}/budgetmanagement/budgets/${account}/${budgetId}`;
|
|
128640
|
+
try {
|
|
128641
|
+
await apiDeleteRaw(url, config, { verbose: opts.verbose });
|
|
128642
|
+
} catch (err) {
|
|
128643
|
+
fail3(err, "\u5220\u9664\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
|
|
128644
|
+
}
|
|
128645
|
+
console.log(`
|
|
128646
|
+
\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
|
|
128647
|
+
`);
|
|
128648
|
+
}
|
|
128649
|
+
async function runAdAudienceList(opts) {
|
|
128650
|
+
let kind;
|
|
128651
|
+
try {
|
|
128652
|
+
kind = parseAudienceKind(opts.kind);
|
|
128653
|
+
} catch (err) {
|
|
128654
|
+
fail3(err, "\u53C2\u6570");
|
|
128655
|
+
}
|
|
128656
|
+
const campaignId = (opts.campaignId ?? "").trim();
|
|
128657
|
+
const adGroupId = (opts.adGroupId ?? "").trim();
|
|
128658
|
+
if (!/^\d+$/.test(campaignId) || !/^\d+$/.test(adGroupId)) {
|
|
128659
|
+
fail3(new Error("--campaign-id \u548C --ad-group-id \u90FD\u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
128660
|
+
}
|
|
128661
|
+
const spec = AUDIENCE_KINDS[kind];
|
|
128662
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128663
|
+
const params = new URLSearchParams({ campaignId, adgroupId: adGroupId });
|
|
128664
|
+
const url = `${base2}/adgroupnmanagement/bidmodifiers/${account}/${spec.listType}?${params}`;
|
|
128665
|
+
let items3;
|
|
128666
|
+
try {
|
|
128667
|
+
items3 = asRows(await apiFetch2(url, config, {}, opts.verbose));
|
|
128668
|
+
} catch (err) {
|
|
128669
|
+
fail3(err, "\u67E5\u8BE2\u53D7\u4F17\u5931\u8D25");
|
|
128670
|
+
}
|
|
128671
|
+
const payload = { account, kind, campaignId, adGroupId, count: items3.length, items: items3 };
|
|
128672
|
+
if (await emitCliJsonOrSnapshot(opts, { section: "ad-audience", commandLabel: "ad audience list", payload })) return;
|
|
128673
|
+
console.log(`
|
|
128674
|
+
\u5E7F\u544A\u7EC4\u53D7\u4F17 ${kind}\uFF08${items3.length} \u6761\uFF09\u3002bidModifier \u82E5\u6709\uFF0C\u662F\u767E\u5206\u6BD4\u3002
|
|
128675
|
+
`);
|
|
128676
|
+
printCliTable(
|
|
128677
|
+
items3.map((item) => ({
|
|
128678
|
+
id: field5(item, "id", "Id"),
|
|
128679
|
+
name: field5(item, "userListName", "UserListName", "displayName", "DisplayName"),
|
|
128680
|
+
bid: field5(item, "bidModifier", "BidModifier")
|
|
128681
|
+
})),
|
|
128682
|
+
[
|
|
128683
|
+
{ key: "id", header: "id" },
|
|
128684
|
+
{ key: "name", header: "\u540D\u79F0" },
|
|
128685
|
+
{ key: "bid", header: "\u51FA\u4EF7%" }
|
|
128686
|
+
]
|
|
128687
|
+
);
|
|
128688
|
+
console.log();
|
|
128689
|
+
}
|
|
128690
|
+
async function runAdAudienceAdd(opts) {
|
|
128691
|
+
let body;
|
|
128692
|
+
let kind;
|
|
128693
|
+
try {
|
|
128694
|
+
kind = parseAudienceKind(opts.kind);
|
|
128695
|
+
body = buildAudienceBody({
|
|
128696
|
+
kind,
|
|
128697
|
+
adGroupId: (opts.adGroupId ?? "").trim(),
|
|
128698
|
+
target: opts.target,
|
|
128699
|
+
bidModifier: opts.bidModifier,
|
|
128700
|
+
negative: opts.negative
|
|
128701
|
+
});
|
|
128702
|
+
} catch (err) {
|
|
128703
|
+
fail3(err, "\u53C2\u6570");
|
|
128704
|
+
}
|
|
128705
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128706
|
+
const spec = AUDIENCE_KINDS[kind];
|
|
128707
|
+
const negative = opts.negative ? "true" : "false";
|
|
128708
|
+
const url = `${base2}/adgroupnmanagement/${spec.path}/${account}?isNegative=${negative}`;
|
|
128709
|
+
try {
|
|
128710
|
+
await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
|
|
128711
|
+
} catch (err) {
|
|
128712
|
+
fail3(err, "\u6DFB\u52A0\u53D7\u4F17\u5931\u8D25");
|
|
128713
|
+
}
|
|
128714
|
+
console.log(`
|
|
128715
|
+
\u2705 \u5DF2\u5728\u5E7F\u544A\u7EC4 ${opts.adGroupId} \u6DFB\u52A0 ${kind}\uFF1A${opts.target}${opts.negative ? "\uFF08\u5426\u5B9A\uFF09" : ""}
|
|
128716
|
+
`);
|
|
128717
|
+
}
|
|
128718
|
+
async function runAdScheduleReplace(opts) {
|
|
128719
|
+
const campaignId = (opts.campaignId ?? "").trim();
|
|
128720
|
+
if (!/^\d+$/.test(campaignId)) fail3(new Error("--campaign-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
|
|
128721
|
+
if (!opts.file?.trim()) fail3(new Error("\u987B --file \u6307\u5411\u65F6\u6BB5 JSON \u6570\u7EC4"), "\u53C2\u6570");
|
|
128722
|
+
let schedules;
|
|
128723
|
+
try {
|
|
128724
|
+
schedules = readAdSchedulesFile(opts.file.trim());
|
|
128725
|
+
} catch (err) {
|
|
128726
|
+
fail3(err, "\u53C2\u6570");
|
|
128727
|
+
}
|
|
128728
|
+
const { config, base: base2, account } = accountBase3(opts);
|
|
128729
|
+
const url = `${base2}/campaignmanagement/campaign/${account}/${campaignId}/ad-schedules`;
|
|
128730
|
+
try {
|
|
128731
|
+
await apiFetch2(url, config, { method: "PUT", body: JSON.stringify(schedules) }, opts.verbose);
|
|
128732
|
+
} catch (err) {
|
|
128733
|
+
fail3(err, "\u66FF\u6362\u6295\u653E\u65F6\u6BB5\u5931\u8D25");
|
|
128734
|
+
}
|
|
128735
|
+
console.log(
|
|
128736
|
+
schedules.length === 0 ? `
|
|
128737
|
+
\u2705 \u5DF2\u6E05\u7A7A\u7CFB\u5217 ${campaignId} \u7684\u6295\u653E\u65F6\u6BB5\u3002
|
|
128738
|
+
` : `
|
|
128739
|
+
\u2705 \u5DF2\u7528 ${schedules.length} \u6761\u65F6\u6BB5\u66FF\u6362\u7CFB\u5217 ${campaignId}\u3002\u6CA1\u5199\u8FDB\u6587\u4EF6\u7684\u65E7\u65F6\u6BB5\u4F1A\u88AB\u5220\u6389\u3002
|
|
128740
|
+
`
|
|
128741
|
+
);
|
|
128742
|
+
}
|
|
128743
|
+
|
|
128330
128744
|
// src/commands/ad/demand-gen-body.ts
|
|
128331
128745
|
init_shared();
|
|
128332
128746
|
var WRITE_CENT_KEYS = ["budget", "targetCpa_BidingAmount", "currencyMinimumBudget"];
|
|
@@ -128564,7 +128978,7 @@ function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDat
|
|
|
128564
128978
|
// src/commands/ad/demand-gen.ts
|
|
128565
128979
|
init_shared();
|
|
128566
128980
|
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";
|
|
128567
|
-
function
|
|
128981
|
+
function fail4(message) {
|
|
128568
128982
|
console.error(`
|
|
128569
128983
|
\u274C ${message}
|
|
128570
128984
|
`);
|
|
@@ -128584,7 +128998,7 @@ async function emit(opts, section, commandLabel, payload, idSuffix) {
|
|
|
128584
128998
|
}
|
|
128585
128999
|
function printIssues(issues) {
|
|
128586
129000
|
if (issues.length === 0) return;
|
|
128587
|
-
|
|
129001
|
+
fail4(issues.join("\n"));
|
|
128588
129002
|
}
|
|
128589
129003
|
function loadBody(configFile) {
|
|
128590
129004
|
return stripMetaKeys(loadPmaxJsonFile(configFile));
|
|
@@ -128667,7 +129081,7 @@ async function postCreate(opts, path60, commandLabel) {
|
|
|
128667
129081
|
body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
|
|
128668
129082
|
body = prepareCreateBody(body);
|
|
128669
129083
|
} catch (err) {
|
|
128670
|
-
|
|
129084
|
+
fail4(err instanceof Error ? err.message : String(err));
|
|
128671
129085
|
}
|
|
128672
129086
|
printIssues(demandGenCreateIssues(body));
|
|
128673
129087
|
const url = path60 ? `${demandGenCollectionUrl(googleApiUrl, accountId)}/${path60}` : demandGenCollectionUrl(googleApiUrl, accountId);
|
|
@@ -128680,7 +129094,7 @@ async function postCreate(opts, path60, commandLabel) {
|
|
|
128680
129094
|
opts.verbose
|
|
128681
129095
|
);
|
|
128682
129096
|
} catch (err) {
|
|
128683
|
-
|
|
129097
|
+
fail4(explainCreateError(err));
|
|
128684
129098
|
}
|
|
128685
129099
|
const payload = decorateDemandGenRead(data);
|
|
128686
129100
|
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path60 || "create"}`, commandLabel, payload, accountId)) {
|
|
@@ -128700,7 +129114,7 @@ async function runDemandGenList(opts) {
|
|
|
128700
129114
|
try {
|
|
128701
129115
|
data = await pmaxApiFetch(demandGenCollectionUrl(googleApiUrl, accountId), config, {}, opts.verbose);
|
|
128702
129116
|
} catch (err) {
|
|
128703
|
-
|
|
129117
|
+
fail4(`\u5217\u51FA Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128704
129118
|
}
|
|
128705
129119
|
const payload = {
|
|
128706
129120
|
items: decorateDemandGenRead(data),
|
|
@@ -128737,7 +129151,7 @@ async function runDemandGenGet(opts) {
|
|
|
128737
129151
|
opts.verbose
|
|
128738
129152
|
);
|
|
128739
129153
|
} catch (err) {
|
|
128740
|
-
|
|
129154
|
+
fail4(`\u8BFB\u53D6 Demand Gen \u8BE6\u60C5\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128741
129155
|
}
|
|
128742
129156
|
const payload = asRecord5(decorateDemandGenRead(data));
|
|
128743
129157
|
payload["agentHint"] = MONEY_HINT;
|
|
@@ -128766,7 +129180,7 @@ async function runDemandGenMinimumBudget(opts) {
|
|
|
128766
129180
|
opts.verbose
|
|
128767
129181
|
);
|
|
128768
129182
|
} catch (err) {
|
|
128769
|
-
|
|
129183
|
+
fail4(`\u8BFB\u53D6\u6700\u4F4E\u65E5\u9884\u7B97\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128770
129184
|
}
|
|
128771
129185
|
const payload = decorateDemandGenRead(data);
|
|
128772
129186
|
if (await emit(
|
|
@@ -128798,7 +129212,7 @@ async function runDemandGenConversions(opts) {
|
|
|
128798
129212
|
opts.verbose
|
|
128799
129213
|
);
|
|
128800
129214
|
} catch (err) {
|
|
128801
|
-
|
|
129215
|
+
fail4(`\u8BFB\u53D6\u53EF\u51FA\u4EF7\u8F6C\u5316\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128802
129216
|
}
|
|
128803
129217
|
if (await emit(
|
|
128804
129218
|
{ ...opts, account: accountId },
|
|
@@ -128831,7 +129245,7 @@ async function runDemandGenDraft(opts) {
|
|
|
128831
129245
|
opts.verbose
|
|
128832
129246
|
);
|
|
128833
129247
|
} catch (err) {
|
|
128834
|
-
|
|
129248
|
+
fail4(`\u751F\u6210\u8349\u7A3F\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128835
129249
|
}
|
|
128836
129250
|
const payload = decorateDemandGenRead(data);
|
|
128837
129251
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-draft", "ad demand-gen draft", payload, accountId)) {
|
|
@@ -128856,7 +129270,7 @@ async function runDemandGenConfirm(opts) {
|
|
|
128856
129270
|
}
|
|
128857
129271
|
function readFlagNumber(value, label2) {
|
|
128858
129272
|
const amount = typeof value === "number" ? value : Number(String(value).trim());
|
|
128859
|
-
if (!Number.isFinite(amount))
|
|
129273
|
+
if (!Number.isFinite(amount)) fail4(`${label2}\u987B\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${String(value)}`);
|
|
128860
129274
|
return amount;
|
|
128861
129275
|
}
|
|
128862
129276
|
async function runDemandGenEdit(opts) {
|
|
@@ -128873,7 +129287,7 @@ async function runDemandGenEdit(opts) {
|
|
|
128873
129287
|
if (opts.name !== void 0) body["name"] = opts.name.trim();
|
|
128874
129288
|
if (opts.status !== void 0) {
|
|
128875
129289
|
const status2 = normalizeCampaignStatus(opts.status);
|
|
128876
|
-
if (!status2)
|
|
129290
|
+
if (!status2) fail4("Campaign status must be Enabled, Paused, or Removed.");
|
|
128877
129291
|
body["statusV2"] = status2;
|
|
128878
129292
|
}
|
|
128879
129293
|
if (opts.budget !== void 0) body["budget"] = readFlagNumber(opts.budget, "\u9884\u7B97");
|
|
@@ -128888,7 +129302,7 @@ async function runDemandGenEdit(opts) {
|
|
|
128888
129302
|
body = normalizeDemandGenMoneyForWrite(body);
|
|
128889
129303
|
}
|
|
128890
129304
|
if (Object.keys(body).length === 0) {
|
|
128891
|
-
|
|
129305
|
+
fail4("\u8BF7\u6307\u5B9A --patch-file\uFF0C\u6216\u81F3\u5C11\u4E00\u9879\u4FEE\u6539\uFF08--name / --status / --budget / --bidding / \u2026\uFF09");
|
|
128892
129306
|
}
|
|
128893
129307
|
const status = normalizeCampaignStatus(body["statusV2"]);
|
|
128894
129308
|
if (status) body["statusV2"] = status;
|
|
@@ -128906,7 +129320,7 @@ async function runDemandGenEdit(opts) {
|
|
|
128906
129320
|
});
|
|
128907
129321
|
}
|
|
128908
129322
|
if (body["automatic"] === true) {
|
|
128909
|
-
|
|
129323
|
+
fail4("\u4EBA\u5DE5\u64CD\u4F5C\u4E0D\u8981\u5E26 automatic\u3002");
|
|
128910
129324
|
}
|
|
128911
129325
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
128912
129326
|
try {
|
|
@@ -128917,7 +129331,7 @@ async function runDemandGenEdit(opts) {
|
|
|
128917
129331
|
opts.verbose
|
|
128918
129332
|
);
|
|
128919
129333
|
} catch (err) {
|
|
128920
|
-
|
|
129334
|
+
fail4(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128921
129335
|
}
|
|
128922
129336
|
const payload = { ok: true, campaignId, patch: body };
|
|
128923
129337
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-edit", "ad demand-gen edit", payload, campaignId)) {
|
|
@@ -128936,20 +129350,20 @@ async function runDemandGenContent(opts) {
|
|
|
128936
129350
|
delete body["targetedLocations"];
|
|
128937
129351
|
delete body["targetedLanguages"];
|
|
128938
129352
|
}
|
|
128939
|
-
if (Object.keys(body).length === 0)
|
|
129353
|
+
if (Object.keys(body).length === 0) fail4("content JSON \u6CA1\u6709\u8981\u6539\u7684\u5B57\u6BB5");
|
|
128940
129354
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
128941
129355
|
let next = body;
|
|
128942
129356
|
try {
|
|
128943
129357
|
next = await attachImages(opts.configFile, body, accountId, config, googleApiUrl, opts.verbose);
|
|
128944
129358
|
} catch (err) {
|
|
128945
|
-
|
|
129359
|
+
fail4(err instanceof Error ? err.message : String(err));
|
|
128946
129360
|
}
|
|
128947
129361
|
delete next["imagePaths"];
|
|
128948
129362
|
const url = opts.adId?.trim() ? demandGenAdUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), opts.adId.trim(), "content") : demandGenAdGroupUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), "content");
|
|
128949
129363
|
try {
|
|
128950
129364
|
await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify(next) }, opts.verbose);
|
|
128951
129365
|
} catch (err) {
|
|
128952
|
-
|
|
129366
|
+
fail4(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128953
129367
|
}
|
|
128954
129368
|
const payload = { ok: true, campaignId: opts.campaignId, adGroupId: opts.adGroupId, adId: opts.adId ?? null };
|
|
128955
129369
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-content", "ad demand-gen content", payload)) return;
|
|
@@ -128961,7 +129375,7 @@ async function runDemandGenChannels(opts) {
|
|
|
128961
129375
|
const hasStrategy = Boolean(opts.strategy?.trim());
|
|
128962
129376
|
const hasSelected = Boolean(opts.selected?.trim());
|
|
128963
129377
|
if (hasStrategy === hasSelected) {
|
|
128964
|
-
|
|
129378
|
+
fail4("channelStrategy \u548C selectedChannels \u4E8C\u9009\u4E00\uFF1A\u53EA\u4F20 --strategy\uFF0C\u6216\u53EA\u4F20 --selected\u3002");
|
|
128965
129379
|
}
|
|
128966
129380
|
const body = {};
|
|
128967
129381
|
if (hasStrategy) body["channelStrategy"] = opts.strategy.trim();
|
|
@@ -128969,7 +129383,7 @@ async function runDemandGenChannels(opts) {
|
|
|
128969
129383
|
try {
|
|
128970
129384
|
body["selectedChannels"] = buildSelectedChannels(opts.selected.split(","));
|
|
128971
129385
|
} catch (err) {
|
|
128972
|
-
|
|
129386
|
+
fail4(err instanceof Error ? err.message : String(err));
|
|
128973
129387
|
}
|
|
128974
129388
|
}
|
|
128975
129389
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -128983,7 +129397,7 @@ async function runDemandGenChannels(opts) {
|
|
|
128983
129397
|
try {
|
|
128984
129398
|
await pmaxApiFetch(url, config, { method: "PATCH", body: JSON.stringify(body) }, opts.verbose);
|
|
128985
129399
|
} catch (err) {
|
|
128986
|
-
|
|
129400
|
+
fail4(`\u66F4\u65B0\u7248\u4F4D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
128987
129401
|
}
|
|
128988
129402
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-channels", "ad demand-gen channels", { ok: true, patch: body })) {
|
|
128989
129403
|
return;
|
|
@@ -128994,7 +129408,7 @@ async function runDemandGenChannels(opts) {
|
|
|
128994
129408
|
async function putStatus(opts, kind) {
|
|
128995
129409
|
const status = normalizeAdStatus(opts.status);
|
|
128996
129410
|
if (!status) {
|
|
128997
|
-
|
|
129411
|
+
fail4("\u5E7F\u544A\u548C\u5E7F\u544A\u7EC4\u53EA\u63A5\u53D7 Enabled \u6216 Paused\u3002\u4E0D\u8981\u7528\u5B83\u542F\u7528\u7CFB\u5217\uFF1B\u5220\u5149\u4F1A 400\uFF0C\u53EA\u60F3\u505C\u6295\u7528 Paused\u3002");
|
|
128998
129412
|
}
|
|
128999
129413
|
const accountId = requireAccountId(opts.account);
|
|
129000
129414
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -129020,7 +129434,7 @@ async function putStatus(opts, kind) {
|
|
|
129020
129434
|
opts.verbose
|
|
129021
129435
|
);
|
|
129022
129436
|
} catch (err) {
|
|
129023
|
-
|
|
129437
|
+
fail4(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129024
129438
|
}
|
|
129025
129439
|
console.log(`
|
|
129026
129440
|
\u2705 \u5DF2\u8BBE\u4E3A ${status}\u3002\u7CFB\u5217\u72B6\u6001\u4E0D\u4F1A\u8DDF\u7740\u53D8\u3002
|
|
@@ -129035,7 +129449,7 @@ async function runDemandGenAdStatus(opts) {
|
|
|
129035
129449
|
}
|
|
129036
129450
|
async function runDemandGenAdGroupRename(opts) {
|
|
129037
129451
|
const name2 = opts.name.trim();
|
|
129038
|
-
if (!name2 || name2.length > 255)
|
|
129452
|
+
if (!name2 || name2.length > 255) fail4("\u5E7F\u544A\u7EC4\u540D\u987B\u4E3A 1\uFF5E255 \u4E2A\u5B57\u7B26\u3002");
|
|
129039
129453
|
const accountId = requireAccountId(opts.account);
|
|
129040
129454
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
129041
129455
|
const url = demandGenAdGroupUrl(
|
|
@@ -129048,7 +129462,7 @@ async function runDemandGenAdGroupRename(opts) {
|
|
|
129048
129462
|
try {
|
|
129049
129463
|
await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify({ name: name2 }) }, opts.verbose);
|
|
129050
129464
|
} catch (err) {
|
|
129051
|
-
|
|
129465
|
+
fail4(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129052
129466
|
}
|
|
129053
129467
|
console.log(`
|
|
129054
129468
|
\u2705 \u5E7F\u544A\u7EC4\u5DF2\u6539\u540D\u4E3A ${name2}
|
|
@@ -129058,7 +129472,7 @@ async function runDemandGenAdGroupRename(opts) {
|
|
|
129058
129472
|
async function runDemandGenAudience(opts) {
|
|
129059
129473
|
const audienceResourceName = opts.resourceName.trim();
|
|
129060
129474
|
if (!audienceResourceName.includes("/audiences/")) {
|
|
129061
|
-
|
|
129475
|
+
fail4("Audience resource name must be customers/{id}/audiences/{audienceId}.");
|
|
129062
129476
|
}
|
|
129063
129477
|
const accountId = requireAccountId(opts.account);
|
|
129064
129478
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -129077,7 +129491,7 @@ async function runDemandGenAudience(opts) {
|
|
|
129077
129491
|
opts.verbose
|
|
129078
129492
|
);
|
|
129079
129493
|
} catch (err) {
|
|
129080
|
-
|
|
129494
|
+
fail4(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129081
129495
|
}
|
|
129082
129496
|
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");
|
|
129083
129497
|
});
|
|
@@ -129085,7 +129499,7 @@ async function runDemandGenAudience(opts) {
|
|
|
129085
129499
|
async function runDemandGenAudienceKeywords(opts) {
|
|
129086
129500
|
const audienceKeywords = opts.keywords.split(",").map((item) => item.trim()).filter(Boolean);
|
|
129087
129501
|
if (audienceKeywords.length < 1 || audienceKeywords.length > 10) {
|
|
129088
|
-
|
|
129502
|
+
fail4("Audience keyword count must be between 1 and 10.");
|
|
129089
129503
|
}
|
|
129090
129504
|
const accountId = requireAccountId(opts.account);
|
|
129091
129505
|
await withGoogleApi(opts, async (config, googleApiUrl) => {
|
|
@@ -129104,7 +129518,7 @@ async function runDemandGenAudienceKeywords(opts) {
|
|
|
129104
129518
|
opts.verbose
|
|
129105
129519
|
);
|
|
129106
129520
|
} catch (err) {
|
|
129107
|
-
|
|
129521
|
+
fail4(`\u66FF\u6362\u53D7\u4F17\u8BCD\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129108
129522
|
}
|
|
129109
129523
|
console.log("\n\u2705 \u641C\u7D22\u81EA\u5B9A\u4E49\u53D7\u4F17\u7684\u8BCD\u5DF2\u6574\u4EFD\u66FF\u6362\n");
|
|
129110
129524
|
});
|
|
@@ -129117,7 +129531,7 @@ async function postChild(opts, kind) {
|
|
|
129117
129531
|
try {
|
|
129118
129532
|
body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
|
|
129119
129533
|
} catch (err) {
|
|
129120
|
-
|
|
129534
|
+
fail4(err instanceof Error ? err.message : String(err));
|
|
129121
129535
|
}
|
|
129122
129536
|
delete body["account"];
|
|
129123
129537
|
delete body["imagePaths"];
|
|
@@ -129126,7 +129540,7 @@ async function postChild(opts, kind) {
|
|
|
129126
129540
|
try {
|
|
129127
129541
|
data = await pmaxApiFetch(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
|
|
129128
129542
|
} catch (err) {
|
|
129129
|
-
|
|
129543
|
+
fail4(err instanceof Error ? err.message : String(err));
|
|
129130
129544
|
}
|
|
129131
129545
|
if (await emit({ ...opts, account: accountId }, `ad-demand-gen-add-${kind}`, `ad demand-gen add-${kind}`, data)) {
|
|
129132
129546
|
return;
|
|
@@ -129161,7 +129575,7 @@ async function runDemandGenDeleteAd(opts) {
|
|
|
129161
129575
|
try {
|
|
129162
129576
|
await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
|
|
129163
129577
|
} catch (err) {
|
|
129164
|
-
|
|
129578
|
+
fail4(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129165
129579
|
}
|
|
129166
129580
|
console.log("\n\u2705 \u5E7F\u544A\u5DF2\u5220\u9664\n");
|
|
129167
129581
|
});
|
|
@@ -129182,7 +129596,7 @@ async function runDemandGenDeleteAdGroup(opts) {
|
|
|
129182
129596
|
try {
|
|
129183
129597
|
await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
|
|
129184
129598
|
} catch (err) {
|
|
129185
|
-
|
|
129599
|
+
fail4(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129186
129600
|
}
|
|
129187
129601
|
console.log("\n\u2705 \u5E7F\u544A\u7EC4\u5DF2\u5220\u9664\n");
|
|
129188
129602
|
});
|
|
@@ -129201,7 +129615,7 @@ async function runDemandGenReport(opts) {
|
|
|
129201
129615
|
opts.verbose
|
|
129202
129616
|
);
|
|
129203
129617
|
} catch (err) {
|
|
129204
|
-
|
|
129618
|
+
fail4(`\u8BFB\u53D6\u7248\u4F4D\u62A5\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129205
129619
|
}
|
|
129206
129620
|
if (await emit({ ...opts, account: accountId }, "ad-demand-gen-report", "ad demand-gen report", data, opts.campaignId)) {
|
|
129207
129621
|
return;
|
|
@@ -129225,7 +129639,7 @@ async function runDemandGenConversionsValidate(opts) {
|
|
|
129225
129639
|
opts.verbose
|
|
129226
129640
|
);
|
|
129227
129641
|
} catch (err) {
|
|
129228
|
-
|
|
129642
|
+
fail4(`\u79BB\u7EBF\u8F6C\u5316\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
129229
129643
|
}
|
|
129230
129644
|
if (await emit(
|
|
129231
129645
|
{ ...opts, account: accountId },
|
|
@@ -130796,6 +131210,32 @@ function registerProtection(adCmd) {
|
|
|
130796
131210
|
adCmd.command("rsa-assets").description("\u641C\u7D22\u5E7F\u544A RSA \u7D20\u6750\u8868\u73B0\u3002\u7528\u6765\u770B\u54EA\u6761\u6807\u9898\u3001\u63CF\u8FF0\u5728\u82B1\u94B1").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130797
131211
|
await runAdRsaAssets(opts);
|
|
130798
131212
|
});
|
|
131213
|
+
adCmd.command("auction-insights").description("\u7ADE\u4EF7\u6D1E\u5BDF\uFF1A\u4F60\u548C\u5BF9\u624B\u7684\u5C55\u793A\u4EFD\u989D\u3002\u53EA\u8BFB").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--campaign-id <id>", "\u53EA\u770B\u4E00\u4E2A\u7CFB\u5217").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131214
|
+
await runAdAuctionInsights(opts);
|
|
131215
|
+
});
|
|
131216
|
+
const sharedBudget = adCmd.command("shared-budget").description("\u5171\u4EAB\u9884\u7B97\u3002campaign-edit \u5728 budgetShared \u65F6\u4F1A\u62D2\u7EDD\u6539\u9884\u7B97\uFF0C\u6539\u91D1\u989D\u7528\u8FD9\u91CC");
|
|
131217
|
+
sharedBudget.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131218
|
+
await runAdSharedBudgetList(opts);
|
|
131219
|
+
});
|
|
131220
|
+
sharedBudget.command("create").description("\u65B0\u5EFA\u4E00\u4EFD\u5171\u4EAB\u9884\u7B97\u3002\u4E0D\u6539\u5DF2\u6709\u7CFB\u5217\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--name <name>", "\u9884\u7B97\u540D\u79F0").requiredOption("--amount <yuan>", "\u65E5\u9884\u7B97\uFF0C\u4E3B\u5E01\u79CD\u5143", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131221
|
+
await runAdSharedBudgetCreate(opts);
|
|
131222
|
+
});
|
|
131223
|
+
sharedBudget.command("update").description("\u6539\u4E00\u4EFD\u5171\u4EAB\u9884\u7B97\u7684\u540D\u79F0\u6216\u91D1\u989D\u3002\u540C\u4E00\u9884\u7B97\u4E0B\u7684\u7CFB\u5217\u4F1A\u4E00\u8D77\u53D8\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--budget-id <id>", "list \u91CC\u7684 id").option("--name <name>", "\u65B0\u540D\u79F0\uFF0C\u4E0D\u4F20\u5219\u4FDD\u6301\u539F\u540D").option("--amount <yuan>", "\u65B0\u65E5\u9884\u7B97\uFF0C\u4E3B\u5E01\u79CD\u5143", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131224
|
+
await runAdSharedBudgetUpdate(opts);
|
|
131225
|
+
});
|
|
131226
|
+
sharedBudget.command("delete").description("\u5220\u9664\u5171\u4EAB\u9884\u7B97\u3002\u987B --i-confirm\u3002\u4ECD\u88AB\u7CFB\u5217\u4F7F\u7528\u65F6 Google \u4F1A\u62D2\u7EDD").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--budget-id <id>", "list \u91CC\u7684 id").option("--i-confirm", "\u7528\u6237\u5DF2\u786E\u8BA4\u5220\u9664", false).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131227
|
+
await runAdSharedBudgetDelete(opts);
|
|
131228
|
+
});
|
|
131229
|
+
const audience = adCmd.command("audience").description("\u641C\u7D22\u5E7F\u544A\u7EC4\u53D7\u4F17\uFF1A\u7528\u6237\u5217\u8868\u3001\u5174\u8DA3\u3001\u6027\u522B\u3001\u5E74\u9F84\u3001\u6536\u5165\u3001\u80B2\u513F\u3002\u4E0D\u662F PMax \u53D7\u4F17");
|
|
131230
|
+
audience.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--kind <kind>", "user-list | user-interest | gender | age | income | parent").requiredOption("--campaign-id <id>", "\u7CFB\u5217 id").requiredOption("--ad-group-id <id>", "\u5E7F\u544A\u7EC4 id").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131231
|
+
await runAdAudienceList(opts);
|
|
131232
|
+
});
|
|
131233
|
+
audience.command("add").description("\u7ED9\u5E7F\u544A\u7EC4\u52A0\u4E00\u6761\u53D7\u4F17\u3002--bid-modifier \u662F\u500D\u7387\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--kind <kind>", "user-list | user-interest | gender | age | income | parent").requiredOption("--ad-group-id <id>", "\u5E7F\u544A\u7EC4 id").requiredOption("--target <value>", "\u7528\u6237\u5217\u8868/\u5174\u8DA3\u7684\u6570\u5B57 ID\uFF0C\u6216\u679A\u4E3E\u540D\uFF0C\u5982 Male\u3001AgeRange1824").option("--negative", "\u4F5C\u4E3A\u5426\u5B9A\u53D7\u4F17\u3002\u4E0D\u80FD\u548C --bid-modifier \u4E00\u8D77\u7528", false).option("--bid-modifier <multiplier>", "\u500D\u7387\uFF1A1.2 = +20%\uFF0C0 = \u6392\u9664\u3002\u4E0D\u4F20\u8868\u793A\u4E0D\u6539\u51FA\u4EF7", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131234
|
+
await runAdAudienceAdd(opts);
|
|
131235
|
+
});
|
|
131236
|
+
adCmd.command("schedule-replace").description("\u6574\u8868\u66FF\u6362\u7CFB\u5217\u6295\u653E\u65F6\u6BB5\u3002\u6587\u4EF6\u6CA1\u5199\u7684\u65E7\u65F6\u6BB5\u4F1A\u88AB\u5220\u6389\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "\u7CFB\u5217 id").requiredOption("--file <path>", "JSON \u6570\u7EC4\u3002BidModifier \u662F\u767E\u5206\u6BD4\uFF0C20 = +20%\u3002\u6E05\u7A7A\u4F20 []").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
131237
|
+
await runAdScheduleReplace(opts);
|
|
131238
|
+
});
|
|
130799
131239
|
adCmd.command("recommendation-subscriptions").description("\u81EA\u52A8\u5E94\u7528\u5EFA\u8BAE\u7684\u8BA2\u9605\u72B6\u6001\u3002\u53EA\u8BFB\uFF0C\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3").allowExcessArguments(false).requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
130800
131240
|
await runAdRecommendationSubscriptions(opts);
|
|
130801
131241
|
});
|
|
@@ -131371,11 +131811,11 @@ function snapshotSupported(targeting) {
|
|
|
131371
131811
|
function diffSnapshots(before, after) {
|
|
131372
131812
|
const fields = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
131373
131813
|
const changes = [];
|
|
131374
|
-
for (const
|
|
131375
|
-
const from = before[
|
|
131376
|
-
const to = after[
|
|
131814
|
+
for (const field6 of fields) {
|
|
131815
|
+
const from = before[field6];
|
|
131816
|
+
const to = after[field6];
|
|
131377
131817
|
const changed = JSON.stringify(from) !== JSON.stringify(to);
|
|
131378
|
-
changes.push({ field:
|
|
131818
|
+
changes.push({ field: field6, from: from ?? null, to: to ?? null, changed });
|
|
131379
131819
|
}
|
|
131380
131820
|
return changes;
|
|
131381
131821
|
}
|
|
@@ -131513,7 +131953,7 @@ function formHasPredefinedQuestion(form) {
|
|
|
131513
131953
|
}
|
|
131514
131954
|
|
|
131515
131955
|
// src/commands/meta-ad/load.ts
|
|
131516
|
-
import { readFileSync as
|
|
131956
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
131517
131957
|
function stripMetaKeys2(value) {
|
|
131518
131958
|
if (Array.isArray(value)) {
|
|
131519
131959
|
return value.map((item) => stripMetaKeys2(item));
|
|
@@ -131530,7 +131970,7 @@ function stripMetaKeys2(value) {
|
|
|
131530
131970
|
}
|
|
131531
131971
|
function tryLoadJsonFile(configFile) {
|
|
131532
131972
|
try {
|
|
131533
|
-
return JSON.parse(
|
|
131973
|
+
return JSON.parse(readFileSync16(configFile, "utf8"));
|
|
131534
131974
|
} catch {
|
|
131535
131975
|
return null;
|
|
131536
131976
|
}
|
|
@@ -131561,10 +132001,10 @@ function loadMetaLeadFormConfig(configFile) {
|
|
|
131561
132001
|
}
|
|
131562
132002
|
|
|
131563
132003
|
// src/commands/meta-ad/images.ts
|
|
131564
|
-
import { readFileSync as
|
|
132004
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
131565
132005
|
import { basename as basename9 } from "path";
|
|
131566
132006
|
function readImageBytesBase64(imagePath) {
|
|
131567
|
-
const buf =
|
|
132007
|
+
const buf = readFileSync17(imagePath);
|
|
131568
132008
|
if (buf.length < 1 || buf.length > 8 * 1024 * 1024) {
|
|
131569
132009
|
throw new Error(`\u56FE\u7247\u5927\u5C0F\u987B\u4E3A 1 \u5B57\u8282\uFF5E8MB\uFF0C\u5F53\u524D ${buf.length} \u5B57\u8282`);
|
|
131570
132010
|
}
|
|
@@ -143784,7 +144224,7 @@ function mergeCollectFacts(agentData, collect) {
|
|
|
143784
144224
|
}
|
|
143785
144225
|
|
|
143786
144226
|
// src/test-utils/report-echarts.ts
|
|
143787
|
-
import { readFileSync as
|
|
144227
|
+
import { readFileSync as readFileSync20 } from "fs";
|
|
143788
144228
|
import path34 from "path";
|
|
143789
144229
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
143790
144230
|
var TSO_CLI_ROOT = path34.join(path34.dirname(fileURLToPath8(import.meta.url)), "../..");
|
|
@@ -144984,7 +145424,7 @@ function num9(value) {
|
|
|
144984
145424
|
const n = Number(value);
|
|
144985
145425
|
return Number.isFinite(n) ? n : void 0;
|
|
144986
145426
|
}
|
|
144987
|
-
function
|
|
145427
|
+
function asRows2(value) {
|
|
144988
145428
|
return Array.isArray(value) ? value.filter((r) => asRecord30(r) !== null) : [];
|
|
144989
145429
|
}
|
|
144990
145430
|
function pickMetricExtras(row, extras) {
|
|
@@ -145101,38 +145541,38 @@ async function mergeMetaDiagnosisSnapshotIntoReport(payload, snapshotDir) {
|
|
|
145101
145541
|
}
|
|
145102
145542
|
const tables = { ...payload.tables ?? {} };
|
|
145103
145543
|
{
|
|
145104
|
-
const rows =
|
|
145544
|
+
const rows = asRows2(sectionMap.get("ad-sets")?.adGroups).map(
|
|
145105
145545
|
(r) => pickMetricExtras(r, ["adGroupId", "adGroupName", "campaignName", "spendPercentage"])
|
|
145106
145546
|
);
|
|
145107
145547
|
if (rows.length > 0) tables.adSets = rows;
|
|
145108
145548
|
}
|
|
145109
145549
|
{
|
|
145110
|
-
const rows =
|
|
145550
|
+
const rows = asRows2(sectionMap.get("platform")?.networks).map(
|
|
145111
145551
|
(r) => pickMetricExtras(r, ["publisherPlatform", "platformPosition", "network"])
|
|
145112
145552
|
);
|
|
145113
145553
|
if (rows.length > 0) tables.platform = rows;
|
|
145114
145554
|
}
|
|
145115
145555
|
{
|
|
145116
|
-
const rows =
|
|
145556
|
+
const rows = asRows2(sectionMap.get("country")?.countries).map(
|
|
145117
145557
|
(r) => pickMetricExtras(r, ["countryOrRegion"])
|
|
145118
145558
|
);
|
|
145119
145559
|
if (rows.length > 0) tables.country = rows;
|
|
145120
145560
|
}
|
|
145121
145561
|
{
|
|
145122
|
-
const rows =
|
|
145562
|
+
const rows = asRows2(sectionMap.get("audience")?.audiences).map(
|
|
145123
145563
|
(r) => pickMetricExtras(r, ["age", "gender"])
|
|
145124
145564
|
);
|
|
145125
145565
|
if (rows.length > 0) tables.audience = rows;
|
|
145126
145566
|
}
|
|
145127
145567
|
{
|
|
145128
|
-
const rows =
|
|
145568
|
+
const rows = asRows2(sectionMap.get("creative")?.creatives).map(
|
|
145129
145569
|
(r) => pickMetricExtras(r, ["adId", "adName", "creativeType", "title"])
|
|
145130
145570
|
);
|
|
145131
145571
|
if (rows.length > 0) tables.creative = rows;
|
|
145132
145572
|
}
|
|
145133
145573
|
{
|
|
145134
145574
|
const mat = sectionMap.get("material");
|
|
145135
|
-
const rows =
|
|
145575
|
+
const rows = asRows2(mat?.materials).map(
|
|
145136
145576
|
(r) => pickMetricExtras(r, ["materialId", "materialName", "materialType"])
|
|
145137
145577
|
);
|
|
145138
145578
|
if (rows.length > 0) {
|
|
@@ -145742,7 +146182,7 @@ function sumActionArray(raw) {
|
|
|
145742
146182
|
}
|
|
145743
146183
|
|
|
145744
146184
|
// src/commands/facebook-analysis/entities.ts
|
|
145745
|
-
function
|
|
146185
|
+
function fail5(label2, err) {
|
|
145746
146186
|
const msg = err instanceof Error ? err.message : String(err);
|
|
145747
146187
|
console.error(`
|
|
145748
146188
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -145770,7 +146210,7 @@ async function runFacebookAccountStatus(opts) {
|
|
|
145770
146210
|
try {
|
|
145771
146211
|
row = await fetchFacebookAccount(config, manifestId, !!opts.verbose);
|
|
145772
146212
|
} catch (err) {
|
|
145773
|
-
|
|
146213
|
+
fail5("\u67E5\u8BE2 Facebook \u8D26\u6237\u5931\u8D25", err);
|
|
145774
146214
|
}
|
|
145775
146215
|
const payload = { account: manifestId, ...row };
|
|
145776
146216
|
if (await emitCliJsonOrSnapshot(opts, {
|
|
@@ -145820,7 +146260,7 @@ async function runFacebookEntityList(opts, kind) {
|
|
|
145820
146260
|
try {
|
|
145821
146261
|
effectiveStatus = parseEffectiveStatusFilter(opts.effectiveStatus);
|
|
145822
146262
|
} catch (err) {
|
|
145823
|
-
|
|
146263
|
+
fail5("\u53C2\u6570\u9519\u8BEF", err);
|
|
145824
146264
|
}
|
|
145825
146265
|
const pageSize = resolveFacebookPageSize(opts.pageSize);
|
|
145826
146266
|
const config = loadConfig(opts.token);
|
|
@@ -145845,7 +146285,7 @@ async function runFacebookEntityList(opts, kind) {
|
|
|
145845
146285
|
adsetId: opts.adsetId?.trim() || void 0
|
|
145846
146286
|
});
|
|
145847
146287
|
} catch (err) {
|
|
145848
|
-
|
|
146288
|
+
fail5(`\u67E5\u8BE2 ${meta.title} \u5931\u8D25`, err);
|
|
145849
146289
|
}
|
|
145850
146290
|
const payload = wrapListJson({
|
|
145851
146291
|
page: 1,
|
|
@@ -145966,7 +146406,7 @@ async function runFacebookInsights(opts) {
|
|
|
145966
146406
|
breakdown = resolveFacebookBreakdown(opts.breakdown);
|
|
145967
146407
|
timeIncrement = parseOptionalNumber2(opts.timeIncrement);
|
|
145968
146408
|
} catch (err) {
|
|
145969
|
-
|
|
146409
|
+
fail5("\u53C2\u6570\u9519\u8BEF", err);
|
|
145970
146410
|
}
|
|
145971
146411
|
const config = loadConfig(opts.token);
|
|
145972
146412
|
let items3;
|
|
@@ -145982,7 +146422,7 @@ async function runFacebookInsights(opts) {
|
|
|
145982
146422
|
adIds: opts.adIds?.trim() || void 0
|
|
145983
146423
|
});
|
|
145984
146424
|
} catch (err) {
|
|
145985
|
-
|
|
146425
|
+
fail5("\u67E5\u8BE2 Facebook Insights \u5931\u8D25", err);
|
|
145986
146426
|
}
|
|
145987
146427
|
const payload = {
|
|
145988
146428
|
account: manifestId,
|
|
@@ -147025,7 +147465,7 @@ function num11(value) {
|
|
|
147025
147465
|
function round28(value) {
|
|
147026
147466
|
return value == null ? void 0 : Math.round(value * 100) / 100;
|
|
147027
147467
|
}
|
|
147028
|
-
function
|
|
147468
|
+
function asRows3(value) {
|
|
147029
147469
|
if (Array.isArray(value)) {
|
|
147030
147470
|
return value.filter((r) => asRecord34(r) !== null);
|
|
147031
147471
|
}
|
|
@@ -147110,17 +147550,17 @@ function campaignStatusDisplay(status) {
|
|
|
147110
147550
|
}
|
|
147111
147551
|
function mapDeviceRows(payload) {
|
|
147112
147552
|
const obj = asRecord34(payload);
|
|
147113
|
-
return
|
|
147553
|
+
return asRows3(obj?.devices).map((r) => pickMetrics(r, ["deviceType"]));
|
|
147114
147554
|
}
|
|
147115
147555
|
function mapGeographicRows(payload) {
|
|
147116
147556
|
const obj = asRecord34(payload);
|
|
147117
|
-
return
|
|
147557
|
+
return asRows3(obj?.countries).map(
|
|
147118
147558
|
(r) => pickMetrics(r, ["countryOrRegion", "countryCriteriaId", "regionName", "cityName"])
|
|
147119
147559
|
);
|
|
147120
147560
|
}
|
|
147121
147561
|
function mapAudienceLabelRows(payload, labelKey) {
|
|
147122
147562
|
const obj = asRecord34(payload);
|
|
147123
|
-
return
|
|
147563
|
+
return asRows3(obj?.audience).map((r) => {
|
|
147124
147564
|
const m = pickMetrics(r, ["audience", "bidModifier"]);
|
|
147125
147565
|
m[labelKey] = r.audience;
|
|
147126
147566
|
return m;
|
|
@@ -147143,13 +147583,13 @@ function resolveAudienceTables(sectionMap) {
|
|
|
147143
147583
|
};
|
|
147144
147584
|
}
|
|
147145
147585
|
function mapCampaignRows2(payload) {
|
|
147146
|
-
return
|
|
147586
|
+
return asRows3(payload).map((r) => ({
|
|
147147
147587
|
...pickMetrics(r, ["campaignId", "campaignName", "campaignStatus"]),
|
|
147148
147588
|
campaignStatusDisplay: campaignStatusDisplay(r.campaignStatus)
|
|
147149
147589
|
}));
|
|
147150
147590
|
}
|
|
147151
147591
|
function mapAdGroupRows(payload) {
|
|
147152
|
-
return
|
|
147592
|
+
return asRows3(payload).map(
|
|
147153
147593
|
(r) => pickMetrics(r, [
|
|
147154
147594
|
"campaignId",
|
|
147155
147595
|
"campaignName",
|
|
@@ -147172,7 +147612,7 @@ function displayAdTitle(row) {
|
|
|
147172
147612
|
return { adTitle: fallback, adTitleFallback: fallback.length > 0 };
|
|
147173
147613
|
}
|
|
147174
147614
|
function mapAdRows(payload) {
|
|
147175
|
-
return
|
|
147615
|
+
return asRows3(payload).map((r) => {
|
|
147176
147616
|
const mapped = pickMetrics(r, [
|
|
147177
147617
|
"campaignId",
|
|
147178
147618
|
"campaignName",
|
|
@@ -147189,7 +147629,7 @@ function mapAdRows(payload) {
|
|
|
147189
147629
|
});
|
|
147190
147630
|
}
|
|
147191
147631
|
function mapKeywordRows(payload) {
|
|
147192
|
-
return
|
|
147632
|
+
return asRows3(payload).map((r) => {
|
|
147193
147633
|
const m = pickMetrics(r, [
|
|
147194
147634
|
"campaignId",
|
|
147195
147635
|
"campaignName",
|
|
@@ -147207,7 +147647,7 @@ function mapKeywordRows(payload) {
|
|
|
147207
147647
|
});
|
|
147208
147648
|
}
|
|
147209
147649
|
function mapSearchTermRows(payload) {
|
|
147210
|
-
return
|
|
147650
|
+
return asRows3(payload).map(
|
|
147211
147651
|
(r) => pickMetrics(r, [
|
|
147212
147652
|
"campaignId",
|
|
147213
147653
|
"campaignName",
|
|
@@ -147546,6 +147986,106 @@ async function runBingAnalysisRender(opts) {
|
|
|
147546
147986
|
);
|
|
147547
147987
|
}
|
|
147548
147988
|
|
|
147989
|
+
// src/commands/bing-analysis/write.ts
|
|
147990
|
+
init_auth();
|
|
147991
|
+
init_cli_json_snapshot();
|
|
147992
|
+
function parseBingToggleStatus(raw, label2) {
|
|
147993
|
+
if (raw == null || raw.trim() === "") return void 0;
|
|
147994
|
+
const value = raw.trim();
|
|
147995
|
+
if (value.toLowerCase() === "active") return "Active";
|
|
147996
|
+
if (value.toLowerCase() === "paused") return "Paused";
|
|
147997
|
+
throw new Error(`${label2} \u53EA\u63A5\u53D7 Active \u6216 Paused`);
|
|
147998
|
+
}
|
|
147999
|
+
function parsePositiveAmount(raw, label2) {
|
|
148000
|
+
if (raw == null || raw.trim() === "") return void 0;
|
|
148001
|
+
const n = Number(raw);
|
|
148002
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
148003
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57\uFF08\u8D26\u6237\u5E01\u79CD\uFF09`);
|
|
148004
|
+
}
|
|
148005
|
+
return n;
|
|
148006
|
+
}
|
|
148007
|
+
function requirePositiveId(raw, label2) {
|
|
148008
|
+
const id = raw.trim();
|
|
148009
|
+
if (!/^\d+$/.test(id) || id === "0") {
|
|
148010
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57 ID`);
|
|
148011
|
+
}
|
|
148012
|
+
return id;
|
|
148013
|
+
}
|
|
148014
|
+
async function postBing(url, body, opts, section, commandLabel) {
|
|
148015
|
+
const config = loadConfig(opts.token);
|
|
148016
|
+
const payload = await apiFetch2(
|
|
148017
|
+
url,
|
|
148018
|
+
config,
|
|
148019
|
+
{ method: "POST", body: JSON.stringify(body) },
|
|
148020
|
+
opts.verbose
|
|
148021
|
+
);
|
|
148022
|
+
const emitted = await emitCliJsonOrSnapshot(
|
|
148023
|
+
{ jsonOut: opts.jsonOut },
|
|
148024
|
+
{
|
|
148025
|
+
section,
|
|
148026
|
+
commandLabel,
|
|
148027
|
+
payload,
|
|
148028
|
+
idSuffix: assertBingAccountId(opts.account)
|
|
148029
|
+
}
|
|
148030
|
+
);
|
|
148031
|
+
if (emitted) return;
|
|
148032
|
+
const note = payload && typeof payload === "object" && "note" in payload ? String(payload.note ?? "") : "";
|
|
148033
|
+
console.log(`
|
|
148034
|
+
\u2705 ${commandLabel} \u5DF2\u63D0\u4EA4
|
|
148035
|
+
`);
|
|
148036
|
+
if (note) console.log(` ${note}
|
|
148037
|
+
`);
|
|
148038
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
148039
|
+
console.log();
|
|
148040
|
+
}
|
|
148041
|
+
async function runBingCampaignUpdate(opts) {
|
|
148042
|
+
const account = assertBingAccountId(opts.account);
|
|
148043
|
+
const campaignId = requirePositiveId(opts.campaignId, "campaign-id");
|
|
148044
|
+
const status = parseBingToggleStatus(opts.status, "\u7CFB\u5217\u72B6\u6001");
|
|
148045
|
+
const dailyBudget = parsePositiveAmount(opts.dailyBudget, "\u65E5\u9884\u7B97");
|
|
148046
|
+
if (!status && dailyBudget == null) {
|
|
148047
|
+
throw new Error("\u81F3\u5C11\u4F20\u5165 --status Active|Paused \u6216 --daily-budget");
|
|
148048
|
+
}
|
|
148049
|
+
const config = loadConfig(opts.token);
|
|
148050
|
+
const url = reportingUrl(config, account, `campaigns/${campaignId}`, "");
|
|
148051
|
+
await postBing(
|
|
148052
|
+
url,
|
|
148053
|
+
{ status, dailyBudget },
|
|
148054
|
+
opts,
|
|
148055
|
+
"bing-campaign-update",
|
|
148056
|
+
"bing-analysis campaign-update"
|
|
148057
|
+
);
|
|
148058
|
+
}
|
|
148059
|
+
async function runBingAdGroupUpdate(opts) {
|
|
148060
|
+
const account = assertBingAccountId(opts.account);
|
|
148061
|
+
const campaignId = requirePositiveId(opts.campaignId, "campaign-id");
|
|
148062
|
+
const adGroupId = requirePositiveId(opts.adGroupId, "adgroup-id");
|
|
148063
|
+
const status = parseBingToggleStatus(opts.status, "\u5E7F\u544A\u7EC4\u72B6\u6001");
|
|
148064
|
+
const cpcBid = parsePositiveAmount(opts.cpcBid, "CPC \u51FA\u4EF7");
|
|
148065
|
+
if (!status && cpcBid == null) {
|
|
148066
|
+
throw new Error("\u81F3\u5C11\u4F20\u5165 --status Active|Paused \u6216 --cpc-bid");
|
|
148067
|
+
}
|
|
148068
|
+
const config = loadConfig(opts.token);
|
|
148069
|
+
const url = reportingUrl(config, account, `campaigns/${campaignId}/ad-groups/${adGroupId}`, "");
|
|
148070
|
+
await postBing(
|
|
148071
|
+
url,
|
|
148072
|
+
{ status, cpcBid },
|
|
148073
|
+
opts,
|
|
148074
|
+
"bing-adgroup-update",
|
|
148075
|
+
"bing-analysis adgroup-update"
|
|
148076
|
+
);
|
|
148077
|
+
}
|
|
148078
|
+
async function runBingAdStatus(opts) {
|
|
148079
|
+
const account = assertBingAccountId(opts.account);
|
|
148080
|
+
const adGroupId = requirePositiveId(opts.adGroupId, "adgroup-id");
|
|
148081
|
+
const adId = requirePositiveId(opts.adId, "ad-id");
|
|
148082
|
+
const status = parseBingToggleStatus(opts.status, "\u5E7F\u544A\u72B6\u6001");
|
|
148083
|
+
if (!status) throw new Error("\u5E7F\u544A\u72B6\u6001\u5FC5\u987B\u662F Active \u6216 Paused");
|
|
148084
|
+
const config = loadConfig(opts.token);
|
|
148085
|
+
const url = reportingUrl(config, account, `ad-groups/${adGroupId}/ads/${adId}/status`, "");
|
|
148086
|
+
await postBing(url, { status }, opts, "bing-ad-status", "bing-analysis ad-status");
|
|
148087
|
+
}
|
|
148088
|
+
|
|
147549
148089
|
// src/commands/bing-analysis/register-cli.ts
|
|
147550
148090
|
var ACCOUNT_OPTION2 = [
|
|
147551
148091
|
"-a, --account <id>",
|
|
@@ -147650,6 +148190,17 @@ function registerBingAnalysisCommands(program2) {
|
|
|
147650
148190
|
await runBingMonthlySpend(opts);
|
|
147651
148191
|
}
|
|
147652
148192
|
);
|
|
148193
|
+
root.command("campaign-update").description(
|
|
148194
|
+
"\u6539\u7CFB\u5217\u72B6\u6001\u6216\u65E5\u9884\u7B97\uFF08POST \u2026/campaigns/{id}\uFF1BActive/Paused\uFF1B\u5171\u4EAB\u9884\u7B97\u4F1A\u8FDE\u5750\u540C\u4E00 BudgetId\uFF09"
|
|
148195
|
+
).requiredOption(...ACCOUNT_OPTION2).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").option("--status <status>", "Active \u6216 Paused").option("--daily-budget <amount>", "\u65E5\u9884\u7B97\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC2, void 0).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
148196
|
+
await runBingCampaignUpdate(opts);
|
|
148197
|
+
});
|
|
148198
|
+
root.command("adgroup-update").description("\u6539\u5E7F\u544A\u7EC4\u72B6\u6001\u6216 CPC\uFF08POST \u2026/ad-groups/{id}\uFF1B\u51FA\u4EF7\u662F\u5B98\u65B9 CpcBid\uFF0C\u8D26\u6237\u5E01\u79CD\uFF09").requiredOption(...ACCOUNT_OPTION2).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").option("--status <status>", "Active \u6216 Paused").option("--cpc-bid <amount>", "CPC \u51FA\u4EF7\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC2, void 0).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
148199
|
+
await runBingAdGroupUpdate({ ...opts, adGroupId: opts.adgroupId });
|
|
148200
|
+
});
|
|
148201
|
+
root.command("ad-status").description("\u6539\u5E7F\u544A\u72B6\u6001\uFF08POST \u2026/ads/{id}/status\uFF1B\u53EA\u6539 Status\uFF0C\u4E0D\u6539\u521B\u610F\uFF09").requiredOption(...ACCOUNT_OPTION2).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--status <status>", "Active \u6216 Paused").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC2, void 0).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
148202
|
+
await runBingAdStatus({ ...opts, adGroupId: opts.adgroupId });
|
|
148203
|
+
});
|
|
147653
148204
|
}
|
|
147654
148205
|
|
|
147655
148206
|
// src/commands/tiktok-analysis/sections.ts
|
|
@@ -148811,7 +149362,7 @@ async function fetchOfficialReport(config, opts) {
|
|
|
148811
149362
|
}
|
|
148812
149363
|
|
|
148813
149364
|
// src/commands/tiktok-analysis/entities.ts
|
|
148814
|
-
function
|
|
149365
|
+
function fail6(label2, err) {
|
|
148815
149366
|
const msg = err instanceof Error ? err.message : String(err);
|
|
148816
149367
|
console.error(`
|
|
148817
149368
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -148825,7 +149376,7 @@ async function runTikTokAccountStatus(opts) {
|
|
|
148825
149376
|
try {
|
|
148826
149377
|
rows = await fetchAdvertiserInfoList(config, id, !!opts.verbose);
|
|
148827
149378
|
} catch (err) {
|
|
148828
|
-
|
|
149379
|
+
fail6("\u67E5\u8BE2 TikTok \u8D26\u6237\u4FE1\u606F\u5931\u8D25\uFF08\u987B\u62E5\u6709\u8BE5\u5E7F\u544A\u4E3B\uFF0C\u5217\u8868\u53EF\u89C1\u4E0D\u591F\uFF09", err);
|
|
148829
149380
|
}
|
|
148830
149381
|
const payload = wrapListJson({
|
|
148831
149382
|
page: 1,
|
|
@@ -148880,7 +149431,7 @@ async function runTikTokCampaignEntities(opts) {
|
|
|
148880
149431
|
verbose: !!opts.verbose
|
|
148881
149432
|
});
|
|
148882
149433
|
} catch (err) {
|
|
148883
|
-
|
|
149434
|
+
fail6("\u67E5\u8BE2 TikTok \u7CFB\u5217\u5931\u8D25", err);
|
|
148884
149435
|
}
|
|
148885
149436
|
const payload = wrapListJson({
|
|
148886
149437
|
page: 1,
|
|
@@ -148942,7 +149493,7 @@ async function runTikTokAdGroupEntities(opts) {
|
|
|
148942
149493
|
verbose: !!opts.verbose
|
|
148943
149494
|
});
|
|
148944
149495
|
} catch (err) {
|
|
148945
|
-
|
|
149496
|
+
fail6("\u67E5\u8BE2 TikTok \u5E7F\u544A\u7EC4\u5931\u8D25", err);
|
|
148946
149497
|
}
|
|
148947
149498
|
const payload = wrapListJson({
|
|
148948
149499
|
page: 1,
|
|
@@ -149009,7 +149560,7 @@ async function runTikTokAdEntities(opts) {
|
|
|
149009
149560
|
verbose: !!opts.verbose
|
|
149010
149561
|
});
|
|
149011
149562
|
} catch (err) {
|
|
149012
|
-
|
|
149563
|
+
fail6("\u67E5\u8BE2 TikTok \u5E7F\u544A\u5931\u8D25", err);
|
|
149013
149564
|
}
|
|
149014
149565
|
const payload = wrapListJson({
|
|
149015
149566
|
page: 1,
|
|
@@ -149083,7 +149634,7 @@ async function runTikTokOfficialReport(opts) {
|
|
|
149083
149634
|
verbose: !!opts.verbose
|
|
149084
149635
|
});
|
|
149085
149636
|
} catch (err) {
|
|
149086
|
-
|
|
149637
|
+
fail6("\u67E5\u8BE2 TikTok \u5B98\u65B9\u62A5\u8868\u5931\u8D25", err);
|
|
149087
149638
|
}
|
|
149088
149639
|
const totals = summarizeTikTokOfficialReport(result.items);
|
|
149089
149640
|
const payload = {
|
|
@@ -149146,6 +149697,168 @@ TikTok \u5B98\u65B9\u62A5\u8868 ${dataLevel} ${startDate}~${endDate}\uFF08${id}\
|
|
|
149146
149697
|
}
|
|
149147
149698
|
}
|
|
149148
149699
|
|
|
149700
|
+
// src/commands/tiktok-analysis/write.ts
|
|
149701
|
+
init_auth();
|
|
149702
|
+
init_cli_json_snapshot();
|
|
149703
|
+
var CAMPAIGN_BUDGET_MODES = [
|
|
149704
|
+
"BUDGET_MODE_DAY",
|
|
149705
|
+
"BUDGET_MODE_TOTAL",
|
|
149706
|
+
"BUDGET_MODE_DYNAMIC_DAILY_BUDGET"
|
|
149707
|
+
];
|
|
149708
|
+
function parseTikTokOptStatus(raw) {
|
|
149709
|
+
const value = (raw ?? "").trim().toUpperCase();
|
|
149710
|
+
if (value === "ENABLE" || value === "DISABLE") return value;
|
|
149711
|
+
throw new Error("status \u53EA\u63A5\u53D7 ENABLE \u6216 DISABLE\uFF08\u4E0D\u5F00\u653E DELETE\uFF09");
|
|
149712
|
+
}
|
|
149713
|
+
function parseTikTokBudgetMode(raw) {
|
|
149714
|
+
const value = (raw ?? "").trim().toUpperCase();
|
|
149715
|
+
if (CAMPAIGN_BUDGET_MODES.includes(value)) {
|
|
149716
|
+
return value;
|
|
149717
|
+
}
|
|
149718
|
+
throw new Error(`budget-mode \u53EA\u63A5\u53D7 ${CAMPAIGN_BUDGET_MODES.join(" / ")}`);
|
|
149719
|
+
}
|
|
149720
|
+
function parseTikTokAmount(raw, label2) {
|
|
149721
|
+
const n = Number((raw ?? "").trim());
|
|
149722
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
149723
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57\uFF08\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF09`);
|
|
149724
|
+
}
|
|
149725
|
+
return n;
|
|
149726
|
+
}
|
|
149727
|
+
function campaignStatusBody(advertiserId, campaignId, status) {
|
|
149728
|
+
return {
|
|
149729
|
+
advertiser_id: advertiserId,
|
|
149730
|
+
campaign_ids: [campaignId],
|
|
149731
|
+
operation_status: status
|
|
149732
|
+
};
|
|
149733
|
+
}
|
|
149734
|
+
function campaignBudgetBody(advertiserId, campaignId, budget, budgetMode) {
|
|
149735
|
+
return {
|
|
149736
|
+
advertiser_id: advertiserId,
|
|
149737
|
+
campaign_id: campaignId,
|
|
149738
|
+
budget,
|
|
149739
|
+
budget_mode: budgetMode
|
|
149740
|
+
};
|
|
149741
|
+
}
|
|
149742
|
+
function adGroupStatusBody(advertiserId, adGroupId, status) {
|
|
149743
|
+
return {
|
|
149744
|
+
advertiser_id: advertiserId,
|
|
149745
|
+
adgroup_ids: [adGroupId],
|
|
149746
|
+
operation_status: status
|
|
149747
|
+
};
|
|
149748
|
+
}
|
|
149749
|
+
function adGroupBudgetBody(advertiserId, adGroupId, budget) {
|
|
149750
|
+
return {
|
|
149751
|
+
advertiser_id: advertiserId,
|
|
149752
|
+
budget: [{ adgroup_id: adGroupId, budget }]
|
|
149753
|
+
};
|
|
149754
|
+
}
|
|
149755
|
+
function adStatusBody(advertiserId, adId, status) {
|
|
149756
|
+
return {
|
|
149757
|
+
advertiser_id: advertiserId,
|
|
149758
|
+
ad_ids: [adId],
|
|
149759
|
+
operation_status: status
|
|
149760
|
+
};
|
|
149761
|
+
}
|
|
149762
|
+
function assertTikTokWriteOk(raw, label2) {
|
|
149763
|
+
if (!raw || typeof raw !== "object") return;
|
|
149764
|
+
const code = raw.code;
|
|
149765
|
+
if (code === void 0 || code === 0 || code === "0") return;
|
|
149766
|
+
const message = raw.message ?? "\u672A\u77E5\u9519\u8BEF";
|
|
149767
|
+
throw new Error(`${label2} \u4E1A\u52A1\u5931\u8D25 code=${String(code)}\uFF1A${message}`);
|
|
149768
|
+
}
|
|
149769
|
+
async function putTikTok(path60, body, opts, section, commandLabel) {
|
|
149770
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149771
|
+
const config = loadConfig(opts.token);
|
|
149772
|
+
const url = `${requireTikTokApiUrl(config)}/${path60}`;
|
|
149773
|
+
const payload = await apiFetch2(
|
|
149774
|
+
url,
|
|
149775
|
+
config,
|
|
149776
|
+
{ method: "PUT", body: JSON.stringify(body) },
|
|
149777
|
+
opts.verbose
|
|
149778
|
+
);
|
|
149779
|
+
assertTikTokWriteOk(payload, commandLabel);
|
|
149780
|
+
const emitted = await emitCliJsonOrSnapshot(
|
|
149781
|
+
{ jsonOut: opts.jsonOut },
|
|
149782
|
+
{ section, commandLabel, payload, idSuffix: advertiserId }
|
|
149783
|
+
);
|
|
149784
|
+
if (emitted) return;
|
|
149785
|
+
console.log(`
|
|
149786
|
+
\u2705 ${commandLabel} \u5DF2\u63D0\u4EA4
|
|
149787
|
+
`);
|
|
149788
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
149789
|
+
console.log();
|
|
149790
|
+
}
|
|
149791
|
+
async function requireMediaAccountId(opts) {
|
|
149792
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149793
|
+
const config = loadConfig(opts.token);
|
|
149794
|
+
const item = await fetchTikTokAccountByMediaCustomerId(config, advertiserId, opts.verbose);
|
|
149795
|
+
const entityId = String(item?.ma?.entityId ?? "").trim();
|
|
149796
|
+
if (!entityId) {
|
|
149797
|
+
throw new Error(
|
|
149798
|
+
`\u627E\u4E0D\u5230\u5E7F\u544A\u4E3B ${advertiserId} \u7684 entityId\u3002\u8BF7\u786E\u8BA4 list-accounts -m TikTok \u80FD\u67E5\u5230\u8BE5\u6237\u3002`
|
|
149799
|
+
);
|
|
149800
|
+
}
|
|
149801
|
+
return entityId;
|
|
149802
|
+
}
|
|
149803
|
+
async function runTikTokCampaignStatus(opts) {
|
|
149804
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149805
|
+
const status = parseTikTokOptStatus(opts.status);
|
|
149806
|
+
await putTikTok(
|
|
149807
|
+
`tiktokcampaignmanagement/campaign/updatestatus/${TIKTOK_MEDIA_TYPE}`,
|
|
149808
|
+
campaignStatusBody(advertiserId, opts.campaignId.trim(), status),
|
|
149809
|
+
opts,
|
|
149810
|
+
"tiktok-campaign-status",
|
|
149811
|
+
"tiktok-analysis campaign-status"
|
|
149812
|
+
);
|
|
149813
|
+
}
|
|
149814
|
+
async function runTikTokCampaignBudget(opts) {
|
|
149815
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149816
|
+
const budget = parseTikTokAmount(opts.budget, "\u7CFB\u5217\u9884\u7B97");
|
|
149817
|
+
const budgetMode = parseTikTokBudgetMode(opts.budgetMode);
|
|
149818
|
+
await putTikTok(
|
|
149819
|
+
`tiktokcampaignmanagement/campaign/update/${TIKTOK_MEDIA_TYPE}`,
|
|
149820
|
+
campaignBudgetBody(advertiserId, opts.campaignId.trim(), budget, budgetMode),
|
|
149821
|
+
opts,
|
|
149822
|
+
"tiktok-campaign-budget",
|
|
149823
|
+
"tiktok-analysis campaign-budget"
|
|
149824
|
+
);
|
|
149825
|
+
}
|
|
149826
|
+
async function runTikTokAdGroupStatus(opts) {
|
|
149827
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149828
|
+
const entityId = await requireMediaAccountId(opts);
|
|
149829
|
+
const status = parseTikTokOptStatus(opts.status);
|
|
149830
|
+
await putTikTok(
|
|
149831
|
+
`tiktokadgroupmanagement/adgroup/UpdateStatus/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(entityId)}`,
|
|
149832
|
+
adGroupStatusBody(advertiserId, opts.adGroupId.trim(), status),
|
|
149833
|
+
opts,
|
|
149834
|
+
"tiktok-adgroup-status",
|
|
149835
|
+
"tiktok-analysis adgroup-status"
|
|
149836
|
+
);
|
|
149837
|
+
}
|
|
149838
|
+
async function runTikTokAdGroupBudget(opts) {
|
|
149839
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149840
|
+
const entityId = await requireMediaAccountId(opts);
|
|
149841
|
+
const budget = parseTikTokAmount(opts.budget, "\u5E7F\u544A\u7EC4\u9884\u7B97");
|
|
149842
|
+
await putTikTok(
|
|
149843
|
+
`tiktokadgroupmanagement/adgroup/UpdateBudget/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(entityId)}`,
|
|
149844
|
+
adGroupBudgetBody(advertiserId, opts.adGroupId.trim(), budget),
|
|
149845
|
+
opts,
|
|
149846
|
+
"tiktok-adgroup-budget",
|
|
149847
|
+
"tiktok-analysis adgroup-budget"
|
|
149848
|
+
);
|
|
149849
|
+
}
|
|
149850
|
+
async function runTikTokAdStatus(opts) {
|
|
149851
|
+
const advertiserId = assertTikTokAccountId(opts.account);
|
|
149852
|
+
const status = parseTikTokOptStatus(opts.status);
|
|
149853
|
+
await putTikTok(
|
|
149854
|
+
`tiktokadmanagement/ad/updatestatus/${TIKTOK_MEDIA_TYPE}`,
|
|
149855
|
+
adStatusBody(advertiserId, opts.adId.trim(), status),
|
|
149856
|
+
opts,
|
|
149857
|
+
"tiktok-ad-status",
|
|
149858
|
+
"tiktok-analysis ad-status"
|
|
149859
|
+
);
|
|
149860
|
+
}
|
|
149861
|
+
|
|
149149
149862
|
// src/commands/tiktok-analysis/register-cli.ts
|
|
149150
149863
|
var ACCOUNT_OPTION3 = [
|
|
149151
149864
|
"-a, --account <id>",
|
|
@@ -149299,6 +150012,26 @@ function registerTikTokAnalysisCommands(program2) {
|
|
|
149299
150012
|
await runTikTokOfficialReport(opts);
|
|
149300
150013
|
}
|
|
149301
150014
|
);
|
|
150015
|
+
root.command("campaign-status").description("\u542F\u505C\u63A8\u5E7F\u7CFB\u5217\uFF08PUT \u2026/campaign/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--campaign-id <id>", "\u63A8\u5E7F\u7CFB\u5217 ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
150016
|
+
await runTikTokCampaignStatus(opts);
|
|
150017
|
+
});
|
|
150018
|
+
root.command("campaign-budget").description(
|
|
150019
|
+
"\u6539\u63A8\u5E7F\u7CFB\u5217\u9884\u7B97\uFF08PUT \u2026/campaign/update/Tiktok\uFF1B\u65E5\u9884\u7B97\u4E0E\u603B\u9884\u7B97\u4E0D\u80FD\u4E92\u5207\uFF0C\u4E0D\u652F\u6301\u4E0D\u9650\u9884\u7B97\uFF09"
|
|
150020
|
+
).requiredOption(...ACCOUNT_OPTION3).requiredOption("--campaign-id <id>", "\u63A8\u5E7F\u7CFB\u5217 ID").requiredOption("--budget <amount>", "\u9884\u7B97\uFF0C\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").requiredOption(
|
|
150021
|
+
"--budget-mode <mode>",
|
|
150022
|
+
"BUDGET_MODE_DAY / BUDGET_MODE_TOTAL / BUDGET_MODE_DYNAMIC_DAILY_BUDGET"
|
|
150023
|
+
).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
150024
|
+
await runTikTokCampaignBudget(opts);
|
|
150025
|
+
});
|
|
150026
|
+
root.command("adgroup-status").description("\u542F\u505C\u5E7F\u544A\u7EC4\uFF08PUT \u2026/adgroup/UpdateStatus/Tiktok/{entityId}\uFF1BentityId \u6309\u5E7F\u544A\u4E3B\u81EA\u52A8\u67E5\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
150027
|
+
await runTikTokAdGroupStatus({ ...opts, adGroupId: opts.adgroupId });
|
|
150028
|
+
});
|
|
150029
|
+
root.command("adgroup-budget").description("\u6539\u5E7F\u544A\u7EC4\u9884\u7B97\uFF08PUT \u2026/adgroup/UpdateBudget\uFF1BCBO \u6216\u65E0\u9650\u9884\u7B97\u65F6\u7EC4\u9884\u7B97\u53EF\u80FD\u6539\u4E0D\u52A8\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--budget <amount>", "\u9884\u7B97\uFF0C\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
150030
|
+
await runTikTokAdGroupBudget({ ...opts, adGroupId: opts.adgroupId });
|
|
150031
|
+
});
|
|
150032
|
+
root.command("ad-status").description("\u542F\u505C\u5E7F\u544A\uFF08PUT \u2026/ad/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
150033
|
+
await runTikTokAdStatus(opts);
|
|
150034
|
+
});
|
|
149302
150035
|
}
|
|
149303
150036
|
|
|
149304
150037
|
// src/commands/yandex-analysis/register-cli.ts
|
|
@@ -150398,7 +151131,7 @@ function asRecord43(raw) {
|
|
|
150398
151131
|
}
|
|
150399
151132
|
|
|
150400
151133
|
// src/commands/yandex-analysis/entities.ts
|
|
150401
|
-
function
|
|
151134
|
+
function fail7(label2, err) {
|
|
150402
151135
|
const msg = err instanceof Error ? err.message : String(err);
|
|
150403
151136
|
console.error(`
|
|
150404
151137
|
\u274C ${label2}\uFF1A${msg}
|
|
@@ -150470,7 +151203,7 @@ async function runYandexAccountStatus(opts) {
|
|
|
150470
151203
|
try {
|
|
150471
151204
|
result = await fetchPath(opts, "overview", {});
|
|
150472
151205
|
} catch (err) {
|
|
150473
|
-
|
|
151206
|
+
fail7("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
|
|
150474
151207
|
}
|
|
150475
151208
|
const row = asRecord43(result.raw);
|
|
150476
151209
|
await emitOrTable(opts, {
|
|
@@ -150512,7 +151245,7 @@ async function runYandexCampaignEntities(opts) {
|
|
|
150512
151245
|
network: flags.network
|
|
150513
151246
|
});
|
|
150514
151247
|
} catch (err) {
|
|
150515
|
-
|
|
151248
|
+
fail7("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
|
|
150516
151249
|
}
|
|
150517
151250
|
const items3 = unwrapYandexItems(result.raw);
|
|
150518
151251
|
await emitOrTable(opts, {
|
|
@@ -150558,7 +151291,7 @@ async function runYandexAdGroupEntities(opts) {
|
|
|
150558
151291
|
campaignId: flags.campaignId
|
|
150559
151292
|
});
|
|
150560
151293
|
} catch (err) {
|
|
150561
|
-
|
|
151294
|
+
fail7("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
|
|
150562
151295
|
}
|
|
150563
151296
|
const items3 = unwrapYandexItems(result.raw);
|
|
150564
151297
|
await emitOrTable(opts, {
|
|
@@ -150608,7 +151341,7 @@ async function runYandexAdEntities(opts) {
|
|
|
150608
151341
|
adGroupId: flags.adGroupId
|
|
150609
151342
|
});
|
|
150610
151343
|
} catch (err) {
|
|
150611
|
-
|
|
151344
|
+
fail7("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
|
|
150612
151345
|
}
|
|
150613
151346
|
const items3 = unwrapYandexItems(result.raw);
|
|
150614
151347
|
const filtered = flags.status != null;
|
|
@@ -150660,7 +151393,7 @@ async function runYandexInsights(opts) {
|
|
|
150660
151393
|
adGroupId: flags.adGroupId
|
|
150661
151394
|
});
|
|
150662
151395
|
} catch (err) {
|
|
150663
|
-
|
|
151396
|
+
fail7("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
|
|
150664
151397
|
}
|
|
150665
151398
|
const items3 = unwrapYandexItems(result.raw);
|
|
150666
151399
|
await emitOrTable(opts, {
|
|
@@ -150696,6 +151429,106 @@ async function runYandexInsights(opts) {
|
|
|
150696
151429
|
});
|
|
150697
151430
|
}
|
|
150698
151431
|
|
|
151432
|
+
// src/commands/yandex-analysis/write.ts
|
|
151433
|
+
init_auth();
|
|
151434
|
+
init_cli_json_snapshot();
|
|
151435
|
+
function parseYandexAction(raw) {
|
|
151436
|
+
const value = (raw ?? "").trim().toLowerCase();
|
|
151437
|
+
if (value === "suspend" || value === "resume") return value;
|
|
151438
|
+
throw new Error("action \u53EA\u63A5\u53D7 suspend \u6216 resume");
|
|
151439
|
+
}
|
|
151440
|
+
function parseYandexBudgetMode(raw) {
|
|
151441
|
+
if (raw == null || raw.trim() === "") return "STANDARD";
|
|
151442
|
+
const value = raw.trim().toUpperCase();
|
|
151443
|
+
if (value === "STANDARD" || value === "DISTRIBUTED") return value;
|
|
151444
|
+
throw new Error("\u65E5\u9884\u7B97 mode \u53EA\u63A5\u53D7 STANDARD \u6216 DISTRIBUTED");
|
|
151445
|
+
}
|
|
151446
|
+
function parseYandexAmount(raw, label2) {
|
|
151447
|
+
const n = Number((raw ?? "").trim());
|
|
151448
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
151449
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57\uFF08\u8D26\u6237\u5E01\u79CD\uFF0C\u4E0D\u8981\u81EA\u884C\u4E58 1000000\uFF09`);
|
|
151450
|
+
}
|
|
151451
|
+
return n;
|
|
151452
|
+
}
|
|
151453
|
+
function requireYandexEntityId(raw, label2) {
|
|
151454
|
+
const id = raw.trim();
|
|
151455
|
+
if (!/^\d+$/.test(id) || id === "0") {
|
|
151456
|
+
throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57 ID`);
|
|
151457
|
+
}
|
|
151458
|
+
return id;
|
|
151459
|
+
}
|
|
151460
|
+
function yandexAdsUrl(base2, path60, account) {
|
|
151461
|
+
const q = new URLSearchParams({ account });
|
|
151462
|
+
return `${base2.replace(/\/$/, "")}/yandex-ads/${path60}?${q}`;
|
|
151463
|
+
}
|
|
151464
|
+
async function postYandex(path60, body, opts, section, commandLabel) {
|
|
151465
|
+
const account = assertYandexAccountId(opts.account);
|
|
151466
|
+
const config = loadConfig(opts.token);
|
|
151467
|
+
const url = yandexAdsUrl(requireYandexApi(config), path60, account);
|
|
151468
|
+
const payload = await apiFetch2(
|
|
151469
|
+
url,
|
|
151470
|
+
config,
|
|
151471
|
+
{ method: "POST", body: JSON.stringify(body) },
|
|
151472
|
+
opts.verbose
|
|
151473
|
+
);
|
|
151474
|
+
const emitted = await emitCliJsonOrSnapshot(
|
|
151475
|
+
{ jsonOut: opts.jsonOut },
|
|
151476
|
+
{ section, commandLabel, payload, idSuffix: account }
|
|
151477
|
+
);
|
|
151478
|
+
if (emitted) return;
|
|
151479
|
+
console.log(`
|
|
151480
|
+
\u2705 ${commandLabel} \u5DF2\u63D0\u4EA4
|
|
151481
|
+
`);
|
|
151482
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
151483
|
+
console.log();
|
|
151484
|
+
}
|
|
151485
|
+
async function runYandexCampaignState(opts) {
|
|
151486
|
+
const id = requireYandexEntityId(opts.campaignId, "campaign-id");
|
|
151487
|
+
const action = parseYandexAction(opts.action);
|
|
151488
|
+
await postYandex(
|
|
151489
|
+
`campaigns/${id}/state`,
|
|
151490
|
+
{ action },
|
|
151491
|
+
opts,
|
|
151492
|
+
"yandex-campaign-state",
|
|
151493
|
+
"yandex-analysis campaign-state"
|
|
151494
|
+
);
|
|
151495
|
+
}
|
|
151496
|
+
async function runYandexCampaignBudget(opts) {
|
|
151497
|
+
const id = requireYandexEntityId(opts.campaignId, "campaign-id");
|
|
151498
|
+
const amount = parseYandexAmount(opts.dailyBudget, "\u65E5\u9884\u7B97");
|
|
151499
|
+
const mode = parseYandexBudgetMode(opts.mode);
|
|
151500
|
+
await postYandex(
|
|
151501
|
+
`campaigns/${id}/daily-budget`,
|
|
151502
|
+
{ amount, mode },
|
|
151503
|
+
opts,
|
|
151504
|
+
"yandex-campaign-budget",
|
|
151505
|
+
"yandex-analysis campaign-budget"
|
|
151506
|
+
);
|
|
151507
|
+
}
|
|
151508
|
+
async function runYandexAdGroupState(opts) {
|
|
151509
|
+
requireYandexEntityId(opts.adGroupId, "adgroup-id");
|
|
151510
|
+
parseYandexAction(opts.action);
|
|
151511
|
+
throw new Error(
|
|
151512
|
+
"Yandex Direct \u7684\u5E7F\u544A\u7EC4\u4E0D\u80FD\u5355\u72EC\u6682\u505C\u6216\u6062\u590D\u3002\u8BF7\u7528 ad-state \u6539\u7EC4\u91CC\u7684\u5E7F\u544A\uFF0C\u6216\u7528 campaign-state \u6539\u6574\u4E2A\u7CFB\u5217\u3002"
|
|
151513
|
+
);
|
|
151514
|
+
}
|
|
151515
|
+
async function runYandexAdState(opts) {
|
|
151516
|
+
const id = requireYandexEntityId(opts.adId, "ad-id");
|
|
151517
|
+
const action = parseYandexAction(opts.action);
|
|
151518
|
+
await postYandex(`ads/${id}/state`, { action }, opts, "yandex-ad-state", "yandex-analysis ad-state");
|
|
151519
|
+
}
|
|
151520
|
+
async function runYandexKeywordBid(opts) {
|
|
151521
|
+
const id = requireYandexEntityId(opts.keywordId, "keyword-id");
|
|
151522
|
+
const amount = parseYandexAmount(opts.searchBid, "\u641C\u7D22\u51FA\u4EF7");
|
|
151523
|
+
await postYandex(
|
|
151524
|
+
`keywords/${id}/search-bid`,
|
|
151525
|
+
{ amount },
|
|
151526
|
+
opts,
|
|
151527
|
+
"yandex-keyword-bid",
|
|
151528
|
+
"yandex-analysis keyword-bid"
|
|
151529
|
+
);
|
|
151530
|
+
}
|
|
151531
|
+
|
|
150699
151532
|
// src/commands/yandex-analysis/register-cli.ts
|
|
150700
151533
|
var ACCOUNT_OPTION4 = [
|
|
150701
151534
|
"-a, --account <id>",
|
|
@@ -150786,6 +151619,328 @@ function registerYandexAnalysisCommands(program2) {
|
|
|
150786
151619
|
await runYandexInsights(opts);
|
|
150787
151620
|
}
|
|
150788
151621
|
);
|
|
151622
|
+
root.command("campaign-state").description("\u6682\u505C\u6216\u6062\u590D\u7CFB\u5217\uFF08Direct campaigns.suspend / campaigns.resume\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
151623
|
+
await runYandexCampaignState(opts);
|
|
151624
|
+
});
|
|
151625
|
+
root.command("campaign-budget").description("\u6539\u7CFB\u5217\u65E5\u9884\u7B97\uFF08Direct campaigns.update DailyBudget\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u7F51\u5173\u6362\u7B97 micros\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--daily-budget <amount>", "\u65E5\u9884\u7B97\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("--mode <mode>", "STANDARD\uFF08\u9ED8\u8BA4\uFF09\u6216 DISTRIBUTED").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
151626
|
+
await runYandexCampaignBudget(opts);
|
|
151627
|
+
});
|
|
151628
|
+
root.command("adgroup-state").description("\u5E7F\u544A\u7EC4\u4E0D\u80FD\u5355\u72EC\u542F\u505C\uFF08Direct \u7684 AdGroups \u6CA1\u6709 suspend/resume\uFF1B\u8BF7\u7528 ad-state \u6216 campaign-state\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
151629
|
+
await runYandexAdGroupState({ ...opts, adGroupId: opts.adgroupId });
|
|
151630
|
+
});
|
|
151631
|
+
root.command("ad-state").description("\u6682\u505C\u6216\u6062\u590D\u5E7F\u544A\uFF08Direct ads.suspend / ads.resume\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
151632
|
+
await runYandexAdState(opts);
|
|
151633
|
+
});
|
|
151634
|
+
root.command("keyword-bid").description("\u6539\u5173\u952E\u8BCD\u641C\u7D22\u51FA\u4EF7\uFF08Direct keywordbids.set SearchBid\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--keyword-id <id>", "\u5173\u952E\u8BCD ID").requiredOption("--search-bid <amount>", "\u641C\u7D22\u51FA\u4EF7\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
|
|
151635
|
+
await runYandexKeywordBid(opts);
|
|
151636
|
+
});
|
|
151637
|
+
}
|
|
151638
|
+
|
|
151639
|
+
// src/commands/ad-gap/catalog.ts
|
|
151640
|
+
var bing = (path60, needsBody = true) => ({
|
|
151641
|
+
service: "tso",
|
|
151642
|
+
method: "POST",
|
|
151643
|
+
path: `/reporting/media-account/BingV2/{account}/library/${path60}`,
|
|
151644
|
+
needsBody
|
|
151645
|
+
});
|
|
151646
|
+
var yandex = (path60, extra) => ({
|
|
151647
|
+
service: "yandex",
|
|
151648
|
+
method: "POST",
|
|
151649
|
+
path: `/yandex-ads/library/${path60}`,
|
|
151650
|
+
needsBody: true,
|
|
151651
|
+
...extra
|
|
151652
|
+
});
|
|
151653
|
+
var facebook = (path60, extra) => ({
|
|
151654
|
+
service: "facebook",
|
|
151655
|
+
method: "POST",
|
|
151656
|
+
path: `/api/fb/ads/{account}/${path60}`,
|
|
151657
|
+
needsBody: true,
|
|
151658
|
+
...extra
|
|
151659
|
+
});
|
|
151660
|
+
var tiktok = (path60) => ({
|
|
151661
|
+
service: "tiktok",
|
|
151662
|
+
method: "POST",
|
|
151663
|
+
path: `/tiktokgap/${path60}`,
|
|
151664
|
+
needsBody: true
|
|
151665
|
+
});
|
|
151666
|
+
var google = (method, path60, extra) => ({
|
|
151667
|
+
service: "google",
|
|
151668
|
+
method,
|
|
151669
|
+
path: path60,
|
|
151670
|
+
needsBody: method !== "GET" && method !== "DELETE",
|
|
151671
|
+
...extra
|
|
151672
|
+
});
|
|
151673
|
+
var GAP_ACTIONS = {
|
|
151674
|
+
"bing.search-campaign": bing("campaigns"),
|
|
151675
|
+
"bing.delete-campaigns": bing("campaigns/delete"),
|
|
151676
|
+
"bing.ad-group": bing("ad-groups"),
|
|
151677
|
+
"bing.delete-ad-groups": bing("ad-groups/delete"),
|
|
151678
|
+
"bing.responsive-ad": bing("ads"),
|
|
151679
|
+
"bing.delete-ads": bing("ads/delete"),
|
|
151680
|
+
"bing.keywords": bing("keywords"),
|
|
151681
|
+
"bing.keyword-bids": bing("keywords/bids"),
|
|
151682
|
+
"bing.delete-keywords": bing("keywords/delete"),
|
|
151683
|
+
"bing.negative-keywords": bing("negative-keywords"),
|
|
151684
|
+
"bing.campaign-negative-sites": bing("negative-sites/campaigns"),
|
|
151685
|
+
"bing.ad-group-negative-sites": bing("negative-sites/ad-groups"),
|
|
151686
|
+
"bing.location": bing("locations"),
|
|
151687
|
+
"bing.delete-locations": bing("locations/delete"),
|
|
151688
|
+
"bing.budget": bing("budgets"),
|
|
151689
|
+
"bing.delete-budgets": bing("budgets/delete"),
|
|
151690
|
+
"bing.sitelink": bing("sitelinks"),
|
|
151691
|
+
"bing.link-sitelink": bing("sitelinks/link"),
|
|
151692
|
+
"bing.customer-list": bing("customer-lists"),
|
|
151693
|
+
"bing.customer-list-items": bing("customer-lists/items"),
|
|
151694
|
+
"bing.uet-tag": bing("uet-tags"),
|
|
151695
|
+
"bing.conversion-goal": bing("conversion-goals"),
|
|
151696
|
+
"bing.offline-conversions": bing("offline-conversions"),
|
|
151697
|
+
"bing.label": bing("labels"),
|
|
151698
|
+
"bing.link-labels": bing("labels/link"),
|
|
151699
|
+
"bing.experiment": bing("experiments"),
|
|
151700
|
+
"bing.asset-group": bing("asset-groups"),
|
|
151701
|
+
"bing.max-clicks": bing("bid-strategies"),
|
|
151702
|
+
"bing.appeal": bing("editorial-appeals"),
|
|
151703
|
+
"bing.image": bing("media"),
|
|
151704
|
+
"bing.video": bing("videos"),
|
|
151705
|
+
"yandex.text-campaign": yandex("campaigns"),
|
|
151706
|
+
"yandex.rename-campaign": yandex("campaigns/{id}/name", { needsId: true }),
|
|
151707
|
+
"yandex.archive-campaign": yandex("campaigns/{id}/archive", { needsId: true, needsBody: false }),
|
|
151708
|
+
"yandex.delete-campaign": yandex("campaigns/{id}/delete", { needsId: true, needsBody: false }),
|
|
151709
|
+
"yandex.ad-group": yandex("adgroups"),
|
|
151710
|
+
"yandex.rename-ad-group": yandex("adgroups/{id}/name", { needsId: true }),
|
|
151711
|
+
"yandex.delete-ad-group": yandex("adgroups/{id}/delete", { needsId: true, needsBody: false }),
|
|
151712
|
+
"yandex.text-ad": yandex("ads"),
|
|
151713
|
+
"yandex.moderate-ad": yandex("ads/{id}/moderate", { needsId: true, needsBody: false }),
|
|
151714
|
+
"yandex.delete-ad": yandex("ads/{id}/delete", { needsId: true, needsBody: false }),
|
|
151715
|
+
"yandex.keyword": yandex("keywords"),
|
|
151716
|
+
"yandex.update-keyword": yandex("keywords/{id}/text", { needsId: true }),
|
|
151717
|
+
"yandex.keyword-state": yandex("keywords/{id}/state", { needsId: true }),
|
|
151718
|
+
"yandex.delete-keyword": yandex("keywords/{id}/delete", { needsId: true, needsBody: false }),
|
|
151719
|
+
"yandex.keyword-bids": yandex("keyword-bids"),
|
|
151720
|
+
"yandex.mobile-modifier": yandex("bid-modifiers"),
|
|
151721
|
+
"yandex.delete-modifier": yandex("bid-modifiers/{id}/delete", { needsId: true, needsBody: false }),
|
|
151722
|
+
"yandex.retargeting-list": yandex("retargeting-lists"),
|
|
151723
|
+
"yandex.delete-retargeting-list": yandex("retargeting-lists/{id}/delete", { needsId: true, needsBody: false }),
|
|
151724
|
+
"yandex.audience-target": yandex("audience-targets"),
|
|
151725
|
+
"yandex.delete-audience-target": yandex("audience-targets/{id}/delete", { needsId: true, needsBody: false }),
|
|
151726
|
+
"yandex.sitelinks": yandex("sitelinks"),
|
|
151727
|
+
"yandex.delete-sitelinks": yandex("sitelinks/{id}/delete", { needsId: true, needsBody: false }),
|
|
151728
|
+
"yandex.callout": yandex("callouts"),
|
|
151729
|
+
"yandex.delete-callout": yandex("callouts/{id}/delete", { needsId: true, needsBody: false }),
|
|
151730
|
+
"yandex.ad-image": yandex("ad-images"),
|
|
151731
|
+
"yandex.delete-ad-image": yandex("ad-images/{id}/delete", { needsId: true, needsBody: false }),
|
|
151732
|
+
"yandex.creative": yandex("creatives"),
|
|
151733
|
+
"yandex.feed": yandex("feeds"),
|
|
151734
|
+
"yandex.delete-feed": yandex("feeds/{id}/delete", { needsId: true, needsBody: false }),
|
|
151735
|
+
"yandex.changes": yandex("changes"),
|
|
151736
|
+
"yandex.dictionaries": yandex("dictionaries"),
|
|
151737
|
+
"yandex.leads": yandex("leads"),
|
|
151738
|
+
"tiktok.audience-file": tiktok("audiences/file"),
|
|
151739
|
+
"tiktok.audience-rule": tiktok("audiences/rule"),
|
|
151740
|
+
"tiktok.campaign-copy": tiktok("campaign-copies"),
|
|
151741
|
+
"tiktok.gmv-max": tiktok("gmv-max"),
|
|
151742
|
+
"tiktok.smart-plus": tiktok("smart-plus"),
|
|
151743
|
+
"tiktok.negative-keywords": tiktok("negative-keywords"),
|
|
151744
|
+
"tiktok.split-test": tiktok("split-tests"),
|
|
151745
|
+
"meta.outcome-campaign": facebook("outcome-campaigns"),
|
|
151746
|
+
"meta.outcome-campaign-update": facebook("outcome-campaigns/{id}", { needsId: true }),
|
|
151747
|
+
"google.create-conversion-action": google("POST", "/conversion-actions/{account}"),
|
|
151748
|
+
"google.update-conversion-action": google("PUT", "/conversion-actions/{account}/{id}", { needsId: true }),
|
|
151749
|
+
"google.remove-conversion-action": google("DELETE", "/conversion-actions/{account}/{id}", { needsId: true, needsBody: false }),
|
|
151750
|
+
"google.upload-clicks": google("POST", "/conversion-uploads/{account}/clicks"),
|
|
151751
|
+
"google.upload-enhanced-clicks": google("POST", "/conversion-uploads/{account}/enhanced-clicks"),
|
|
151752
|
+
"google.customer-match-list": google("POST", "/customer-match/{account}/user-lists"),
|
|
151753
|
+
"google.customer-match-job": google("POST", "/customer-match/{account}/jobs?userListId={id}", { needsId: true, needsBody: false }),
|
|
151754
|
+
"google.customer-match-operations": google("POST", "/customer-match/{account}/jobs/{id}/operations", { needsId: true }),
|
|
151755
|
+
"google.customer-match-run": google("POST", "/customer-match/{account}/jobs/{id}/run", { needsId: true }),
|
|
151756
|
+
"google.value-rule": google("POST", "/conversion-value-rules/{account}"),
|
|
151757
|
+
"google.remove-value-rule": google("DELETE", "/conversion-value-rules/{account}/{id}", { needsId: true, needsBody: false }),
|
|
151758
|
+
"google.seasonality": google("POST", "/bidding-seasonality/{account}"),
|
|
151759
|
+
"google.remove-seasonality": google("DELETE", "/bidding-seasonality/{account}/{id}", { needsId: true, needsBody: false }),
|
|
151760
|
+
"google.data-exclusion": google("POST", "/bidding-data-exclusions/{account}"),
|
|
151761
|
+
"google.remove-data-exclusion": google("DELETE", "/bidding-data-exclusions/{account}/{id}", { needsId: true, needsBody: false }),
|
|
151762
|
+
"google.campaign-simulations": google("GET", "/bid-simulations/{account}/campaigns/{id}", { needsId: true, needsBody: false }),
|
|
151763
|
+
"google.experiment": google("POST", "/experiments/{account}"),
|
|
151764
|
+
"google.end-experiment": google("POST", "/experiments/{account}/{id}/end", { needsId: true, needsBody: false }),
|
|
151765
|
+
"google.label": google("POST", "/labels/{account}"),
|
|
151766
|
+
"google.link-campaign-label": google("POST", "/labels/{account}/campaigns/{parent}", { needsParent: true }),
|
|
151767
|
+
"google.unlink-campaign-label": google("DELETE", "/labels/{account}/campaigns/{parent}/{id}", { needsParent: true, needsId: true, needsBody: false }),
|
|
151768
|
+
"google.link-ad-group-label": google("POST", "/labels/{account}/ad-groups/{parent}", { needsParent: true }),
|
|
151769
|
+
"google.unlink-ad-group-label": google("DELETE", "/labels/{account}/ad-groups/{parent}/{id}", { needsParent: true, needsId: true, needsBody: false }),
|
|
151770
|
+
"google.link-ad-label": google("POST", "/labels/{account}/ad-groups/{parent}/ads/{id}", { needsParent: true, needsId: true }),
|
|
151771
|
+
"google.unlink-ad-label": google("DELETE", "/labels/{account}/ad-groups/{parent}/ads/{id}/{label}", { needsParent: true, needsId: true, needsLabel: true, needsBody: false }),
|
|
151772
|
+
"google.link-criterion-label": google("POST", "/labels/{account}/ad-groups/{parent}/criteria/{id}", { needsParent: true, needsId: true }),
|
|
151773
|
+
"google.unlink-criterion-label": google("DELETE", "/labels/{account}/ad-groups/{parent}/criteria/{id}/{label}", { needsParent: true, needsId: true, needsLabel: true, needsBody: false }),
|
|
151774
|
+
"google.customizer-attribute": google("POST", "/customizer-attributes/{account}"),
|
|
151775
|
+
"google.customer-customizer": google("POST", "/customizers/{account}"),
|
|
151776
|
+
"google.criterion-bid": google("PUT", "/ad-groups/{account}/{parent}/criteria/{id}/bid", { needsParent: true, needsId: true }),
|
|
151777
|
+
"google.shopping-campaign": google("POST", "/campaigns/{account}/shopping"),
|
|
151778
|
+
"google.dynamic-search-campaign": google("POST", "/campaigns/{account}/dynamic-search"),
|
|
151779
|
+
"google.app-campaign": google("POST", "/campaigns/{account}/app"),
|
|
151780
|
+
"google.display-campaign": google("POST", "/campaigns/{account}/display"),
|
|
151781
|
+
"google.apply-recommendation": google("POST", "/recommendations/{account}/apply"),
|
|
151782
|
+
"google.dismiss-recommendation": google("POST", "/recommendations/{account}/dismiss")
|
|
151783
|
+
};
|
|
151784
|
+
function gapActionNames() {
|
|
151785
|
+
return Object.keys(GAP_ACTIONS).sort();
|
|
151786
|
+
}
|
|
151787
|
+
function resolveGapPath(actionName, target) {
|
|
151788
|
+
const action = GAP_ACTIONS[actionName];
|
|
151789
|
+
if (!action) {
|
|
151790
|
+
throw new Error(`\u672A\u77E5 action\uFF1A${actionName}`);
|
|
151791
|
+
}
|
|
151792
|
+
if (action.path.includes("catalog")) {
|
|
151793
|
+
throw new Error("\u5546\u54C1\u76EE\u5F55\u8DEF\u5F84\u672A\u63A5\u5165");
|
|
151794
|
+
}
|
|
151795
|
+
const account = requireToken(target.account, "account");
|
|
151796
|
+
const parent = action.needsParent ? requireToken(target.parent, "parent") : target.parent?.trim() ?? "";
|
|
151797
|
+
const id = action.needsId ? requireToken(target.id, "id") : target.id?.trim() ?? "";
|
|
151798
|
+
const label2 = action.needsLabel ? requireToken(target.label, "label") : target.label?.trim() ?? "";
|
|
151799
|
+
let path60 = action.path.replaceAll("{account}", encodeURIComponent(account)).replaceAll("{parent}", encodeURIComponent(parent)).replaceAll("{id}", encodeURIComponent(id)).replaceAll("{label}", encodeURIComponent(label2));
|
|
151800
|
+
if (path60.includes("{")) {
|
|
151801
|
+
throw new Error(`action ${actionName} \u8FD8\u7F3A\u8DEF\u5F84\u53C2\u6570`);
|
|
151802
|
+
}
|
|
151803
|
+
if (action.service === "yandex") {
|
|
151804
|
+
path60 += `${path60.includes("?") ? "&" : "?"}account=${encodeURIComponent(account)}`;
|
|
151805
|
+
}
|
|
151806
|
+
return { action, path: path60 };
|
|
151807
|
+
}
|
|
151808
|
+
function requireToken(value, label2) {
|
|
151809
|
+
const text5 = (value ?? "").trim();
|
|
151810
|
+
if (!text5 || text5.includes("/") || text5.includes("\\")) {
|
|
151811
|
+
throw new Error(`${label2} \u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u4E5F\u4E0D\u80FD\u5305\u542B\u659C\u6760`);
|
|
151812
|
+
}
|
|
151813
|
+
return text5;
|
|
151814
|
+
}
|
|
151815
|
+
|
|
151816
|
+
// src/commands/ad-gap/run.ts
|
|
151817
|
+
init_auth();
|
|
151818
|
+
init_cli_json_snapshot();
|
|
151819
|
+
init_shared();
|
|
151820
|
+
import { readFileSync as readFileSync21 } from "fs";
|
|
151821
|
+
function readGapBody(opts, required) {
|
|
151822
|
+
const inline = opts.body?.trim();
|
|
151823
|
+
const file = opts.bodyFile?.trim();
|
|
151824
|
+
if (inline && file) {
|
|
151825
|
+
throw new Error("\u53EA\u4F20 --body \u6216 --body-file \u5176\u4E2D\u4E00\u4E2A");
|
|
151826
|
+
}
|
|
151827
|
+
if (!inline && !file) {
|
|
151828
|
+
if (!required) return void 0;
|
|
151829
|
+
throw new Error("\u8FD9\u4E2A action \u9700\u8981 --body \u6216 --body-file");
|
|
151830
|
+
}
|
|
151831
|
+
const raw = file ? readFileSync21(file, "utf8") : inline;
|
|
151832
|
+
let parsed;
|
|
151833
|
+
try {
|
|
151834
|
+
parsed = JSON.parse(raw);
|
|
151835
|
+
} catch {
|
|
151836
|
+
throw new Error("\u8BF7\u6C42\u4F53\u4E0D\u662F\u5408\u6CD5 JSON");
|
|
151837
|
+
}
|
|
151838
|
+
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
151839
|
+
throw new Error("\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F JSON \u5BF9\u8C61");
|
|
151840
|
+
}
|
|
151841
|
+
return parsed;
|
|
151842
|
+
}
|
|
151843
|
+
function assertTikTokAccepted(payload) {
|
|
151844
|
+
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) return;
|
|
151845
|
+
const code = payload.code;
|
|
151846
|
+
if (typeof code === "number" && code !== 0) {
|
|
151847
|
+
const message = payload.message;
|
|
151848
|
+
const text5 = typeof message === "string" && message.trim() ? message.trim() : String(code);
|
|
151849
|
+
throw new Error("TikTok \u62D2\u7EDD\u8BE5\u8BF7\u6C42: " + text5);
|
|
151850
|
+
}
|
|
151851
|
+
}
|
|
151852
|
+
function assertTikTokAdvertiser(account, body) {
|
|
151853
|
+
const advertiserId = body.advertiser_id;
|
|
151854
|
+
if (String(advertiserId ?? "").trim() !== account.trim()) {
|
|
151855
|
+
throw new Error("TikTok \u8BF7\u6C42\u4F53\u91CC\u7684 advertiser_id \u5FC5\u987B\u548C --account \u76F8\u540C");
|
|
151856
|
+
}
|
|
151857
|
+
}
|
|
151858
|
+
var META_OUTCOME_OBJECTIVES = /* @__PURE__ */ new Set([
|
|
151859
|
+
"OUTCOME_AWARENESS",
|
|
151860
|
+
"OUTCOME_TRAFFIC",
|
|
151861
|
+
"OUTCOME_ENGAGEMENT",
|
|
151862
|
+
"OUTCOME_APP_PROMOTION",
|
|
151863
|
+
"OUTCOME_SALES"
|
|
151864
|
+
]);
|
|
151865
|
+
function assertMetaOutcome(action, body) {
|
|
151866
|
+
const record2 = body;
|
|
151867
|
+
const status = typeof record2.status === "string" ? record2.status.trim().toUpperCase() : "";
|
|
151868
|
+
if (status && status !== "PAUSED") {
|
|
151869
|
+
throw new Error("\u8FD9\u6761\u8DEF\u5F84\u53EA\u63A5\u53D7 PAUSED\uFF0C\u4E0D\u80FD\u5728\u8FD9\u91CC\u6253\u5F00\u6295\u653E");
|
|
151870
|
+
}
|
|
151871
|
+
if (action === "meta.outcome-campaign") {
|
|
151872
|
+
const objective = String(record2.objective ?? "").trim().toUpperCase();
|
|
151873
|
+
if (objective === "OUTCOME_LEADS") {
|
|
151874
|
+
throw new Error("\u7EBF\u7D22\u7CFB\u5217\u8BF7\u7528 meta-ad\uFF0C\u4E0D\u8981\u7528 meta.outcome-campaign");
|
|
151875
|
+
}
|
|
151876
|
+
if (!META_OUTCOME_OBJECTIVES.has(objective)) {
|
|
151877
|
+
throw new Error("objective \u53EA\u63A5\u53D7\u8BA4\u77E5\u3001\u6D41\u91CF\u3001\u4E92\u52A8\u3001\u5E94\u7528\u63A8\u5E7F\u3001\u9500\u552E\u8FD9\u4E94\u4E2A\u76EE\u6807");
|
|
151878
|
+
}
|
|
151879
|
+
if (!Array.isArray(record2.special_ad_categories)) {
|
|
151880
|
+
throw new Error("special_ad_categories \u5FC5\u586B\uFF0C\u6CA1\u6709\u7279\u6B8A\u5206\u7C7B\u65F6\u4F20\u7A7A\u6570\u7EC4");
|
|
151881
|
+
}
|
|
151882
|
+
}
|
|
151883
|
+
if (action === "meta.outcome-campaign-update" && ("objective" in record2 || "buying_type" in record2 || "special_ad_categories" in record2)) {
|
|
151884
|
+
throw new Error("\u8FD9\u91CC\u4E0D\u80FD\u6539 objective\u3001buying_type \u6216 special_ad_categories");
|
|
151885
|
+
}
|
|
151886
|
+
}
|
|
151887
|
+
async function runAdGap(opts) {
|
|
151888
|
+
const resolved = resolveGapPath(opts.action, opts);
|
|
151889
|
+
const body = readGapBody(opts, resolved.action.needsBody);
|
|
151890
|
+
if (resolved.action.service === "tiktok") {
|
|
151891
|
+
assertTikTokAdvertiser(opts.account, body);
|
|
151892
|
+
}
|
|
151893
|
+
if (resolved.action.service === "facebook") {
|
|
151894
|
+
assertMetaOutcome(opts.action, body);
|
|
151895
|
+
}
|
|
151896
|
+
const config = loadConfig(opts.token);
|
|
151897
|
+
const url = serviceBase(resolved.action.service, config) + resolved.path;
|
|
151898
|
+
const payload = await apiFetch2(
|
|
151899
|
+
url,
|
|
151900
|
+
config,
|
|
151901
|
+
{
|
|
151902
|
+
method: resolved.action.method,
|
|
151903
|
+
body: body == null ? void 0 : JSON.stringify(body)
|
|
151904
|
+
},
|
|
151905
|
+
opts.verbose
|
|
151906
|
+
);
|
|
151907
|
+
if (resolved.action.service === "tiktok") {
|
|
151908
|
+
assertTikTokAccepted(payload);
|
|
151909
|
+
}
|
|
151910
|
+
const emitted = await emitCliJsonOrSnapshot(
|
|
151911
|
+
{ jsonOut: opts.jsonOut },
|
|
151912
|
+
{
|
|
151913
|
+
section: `ad-gap-${opts.action}`,
|
|
151914
|
+
commandLabel: `ad-gap ${opts.action}`,
|
|
151915
|
+
payload,
|
|
151916
|
+
idSuffix: opts.account.trim()
|
|
151917
|
+
}
|
|
151918
|
+
);
|
|
151919
|
+
if (emitted) return;
|
|
151920
|
+
console.log(`
|
|
151921
|
+
\u2705 ad-gap ${opts.action} \u5DF2\u63D0\u4EA4
|
|
151922
|
+
`);
|
|
151923
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
151924
|
+
console.log();
|
|
151925
|
+
}
|
|
151926
|
+
function serviceBase(service, config) {
|
|
151927
|
+
if (service === "tso") return config.apiBaseUrl.replace(/\/$/, "");
|
|
151928
|
+
if (service === "google") return requireGoogleApi(config).replace(/\/$/, "");
|
|
151929
|
+
if (service === "yandex") return requireYandexApi(config).replace(/\/$/, "");
|
|
151930
|
+
if (service === "facebook") return requireFacebookApi(config).replace(/\/$/, "");
|
|
151931
|
+
return requireTikTokApiUrl(config).replace(/\/$/, "");
|
|
151932
|
+
}
|
|
151933
|
+
|
|
151934
|
+
// src/commands/ad-gap/register-cli.ts
|
|
151935
|
+
function registerAdGap(program2) {
|
|
151936
|
+
program2.command("ad-gap").description(
|
|
151937
|
+
"\u63D0\u4EA4\u5DF2\u7ECF\u63A5\u5165\u7684\u5E7F\u544A\u7F3A\u53E3\u63A5\u53E3\u3002--action \u51B3\u5B9A\u8DEF\u5F84\uFF0C--body \u662F\u8BE5\u63A5\u53E3\u7684 JSON\u3002\u5199\u64CD\u4F5C\u9700\u8981\u5168\u5C40 --commit\u3002\u65B0\u5EFA\u5BF9\u8C61\u7531\u7F51\u5173\u4FDD\u6301\u6682\u505C\u6216\u5173\u95ED\uFF0C\u4E0D\u8981\u5728\u6B63\u6587\u91CC\u8981\u6C42\u7ACB\u523B\u5F00\u542F\u6D88\u8017\u3002"
|
|
151938
|
+
).requiredOption("--action <name>", `\u52A8\u4F5C\u540D\u3002\u53EF\u9009\uFF1A${gapActionNames().join(", ")}`).requiredOption(
|
|
151939
|
+
"--account <id>",
|
|
151940
|
+
"Google/Bing \u6570\u5B57\u8D26\u6237\u3001Yandex \u767B\u5F55\u540D\u3001TikTok advertiser_id\uFF0C\u6216 Meta \u5E7F\u544A\u8D26\u6237\uFF08\u6570\u5B57\u6216 act_\uFF09"
|
|
151941
|
+
).option("--parent <id>", "\u8DEF\u5F84\u91CC\u7684\u4E0A\u4E00\u5C42 ID\uFF0C\u4F8B\u5982\u5E7F\u544A\u7EC4").option("--id <id>", "\u8DEF\u5F84\u91CC\u7684\u5BF9\u8C61 ID").option("--label <id>", "\u89E3\u9664\u5E7F\u544A\u6216\u51C6\u5219\u6807\u7B7E\u65F6\u7684\u6807\u7B7E ID").option("--body <json>", "\u8BF7\u6C42\u4F53 JSON \u5BF9\u8C61").option("--body-file <path>", "\u8BF7\u6C42\u4F53 JSON \u6587\u4EF6").option("-t, --token <token>", "Auth Token").option("--json-out <path>", "\u628A\u54CD\u5E94\u5199\u5230\u6587\u4EF6").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF", false).action(async (opts) => {
|
|
151942
|
+
await runAdGap(opts);
|
|
151943
|
+
});
|
|
150789
151944
|
}
|
|
150790
151945
|
|
|
150791
151946
|
// src/index.ts
|
|
@@ -151001,7 +152156,7 @@ configureCliJsonSnapshot({
|
|
|
151001
152156
|
configureSiluzanClientIdentity({ client: "tso-cli", resolveVersion: getVersion });
|
|
151002
152157
|
var program = new Command6();
|
|
151003
152158
|
program.name("siluzan-tso").description(
|
|
151004
|
-
"Siluzan \u5E7F\u544A\u8D26\u6237\u7BA1\u7406\uFF1A\u8D26\u6237\u67E5\u8BE2\u3001\u4F59\u989D\u3001\u6295\u653E\u6570\u636E\u3001\u5F00\u6237\u7533\u8BF7\uFF08Google/TikTok/Yandex/Bing/Meta\uFF09\u3001\n\u8D26\u53F7\u5206\u4EAB/\u89E3\u7ED1\u3001\u4F18\u5316\u62A5\u544A\u3001Google/Meta/TikTok/Bing/Yandex \u8D26\u6237\u5206\u6790\u3001Google \u5E7F\u544A\u8BCA\u65AD\u62A5\u544A\uFF08google-ads-diagnosis render\uFF09\u3001Google \u5B63\u5EA6\u7ECF\u8425\u62A5\u544A\uFF08google-quarterly\uFF09\u3001\u7F51\u7AD9\u8BCA\u65AD\uFF08website-diagnosis\uFF09\u3001\u6218\u7565\u5E02\u573A\u5206\u6790\uFF08market-analysis\uFF0CAgent \u751F\u6210\u62A5\u544A\uFF09\u3001\u5145\u503C\u8F6C\u8D26\u3001\u5F00\u7968\u3001\u667A\u80FD\u9884\u8B66\u3001Google \u5E7F\u544A\u7BA1\u7406\uFF08Search/PMax\uFF0C\u542B\u5F02\u6B65\u6279\u91CF\uFF09\u3001Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\uFF08meta-ad\uFF09\u3002"
|
|
152159
|
+
"Siluzan \u5E7F\u544A\u8D26\u6237\u7BA1\u7406\uFF1A\u8D26\u6237\u67E5\u8BE2\u3001\u4F59\u989D\u3001\u6295\u653E\u6570\u636E\u3001\u5F00\u6237\u7533\u8BF7\uFF08Google/TikTok/Yandex/Bing/Meta\uFF09\u3001\n\u8D26\u53F7\u5206\u4EAB/\u89E3\u7ED1\u3001\u4F18\u5316\u62A5\u544A\u3001Google/Meta/TikTok/Bing/Yandex \u8D26\u6237\u5206\u6790\u3001Google \u5E7F\u544A\u8BCA\u65AD\u62A5\u544A\uFF08google-ads-diagnosis render\uFF09\u3001Google \u5B63\u5EA6\u7ECF\u8425\u62A5\u544A\uFF08google-quarterly\uFF09\u3001\u7F51\u7AD9\u8BCA\u65AD\uFF08website-diagnosis\uFF09\u3001\u6218\u7565\u5E02\u573A\u5206\u6790\uFF08market-analysis\uFF0CAgent \u751F\u6210\u62A5\u544A\uFF09\u3001\u5145\u503C\u8F6C\u8D26\u3001\u5F00\u7968\u3001\u667A\u80FD\u9884\u8B66\u3001Google \u5E7F\u544A\u7BA1\u7406\uFF08Search/PMax\uFF0C\u542B\u5F02\u6B65\u6279\u91CF\uFF09\u3001Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\uFF08meta-ad\uFF09\u3001Bing/Yandex/TikTok \u542F\u505C\u4E0E\u9884\u7B97\u3002"
|
|
151005
152160
|
).version(getVersion());
|
|
151006
152161
|
program.option("--commit <text>", "\u5199\u64CD\u4F5C\u8BF4\u660E\uFF1B\u8BB0\u5165\u672C\u673A\u5199\u5BA1\u8BA1 JSONL");
|
|
151007
152162
|
program.hook("preAction", async () => {
|
|
@@ -151037,6 +152192,7 @@ var REGISTRARS = [
|
|
|
151037
152192
|
registerBingAnalysisCommands,
|
|
151038
152193
|
registerTikTokAnalysisCommands,
|
|
151039
152194
|
registerYandexAnalysisCommands,
|
|
152195
|
+
registerAdGap,
|
|
151040
152196
|
register15,
|
|
151041
152197
|
register16,
|
|
151042
152198
|
register17,
|