siluzan-tso-cli 1.1.67-beta.1 → 1.1.67-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 fail5 = (err) => {
2400
+ const fail7 = (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
- fail5(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
2419
+ fail7(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
- fail5(
2430
+ fail7(
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 [field, raw] of Object.entries(rec.errors)) {
2543
+ for (const [field5, 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(`${field}: ${msg}`);
2547
+ if (msg) msgs.push(`${field5}: ${msg}`);
2548
2548
  }
2549
2549
  } else {
2550
2550
  const msg = messageFromJsonValue(raw);
2551
- if (msg) msgs.push(`${field}: ${msg}`);
2551
+ if (msg) msgs.push(`${field5}: ${msg}`);
2552
2552
  }
2553
2553
  }
2554
2554
  if (msgs.length > 0) return msgs.join("; ");
@@ -5980,7 +5980,7 @@ function htmlLangAttr(lang) {
5980
5980
  return lang === "en" ? "en" : "zh-CN";
5981
5981
  }
5982
5982
  function stampMetaLang(payload, lang) {
5983
- const prev = payload.meta;
5983
+ const prev = "meta" in payload ? payload.meta : void 0;
5984
5984
  const meta = prev && typeof prev === "object" && !Array.isArray(prev) ? { ...prev, lang } : { lang };
5985
5985
  return { ...payload, meta };
5986
5986
  }
@@ -9326,8 +9326,8 @@ var init_http_retry = __esm({
9326
9326
  });
9327
9327
 
9328
9328
  // src/commands/google-analysis/normalize-impression-shares.ts
9329
- function normalizeShareValue(value, competitiveMetrics, field) {
9330
- const cmVal = competitiveMetrics?.[field];
9329
+ function normalizeShareValue(value, competitiveMetrics, field5) {
9330
+ const cmVal = competitiveMetrics?.[field5];
9331
9331
  if (typeof cmVal === "number" && Number.isFinite(cmVal)) {
9332
9332
  return cmVal;
9333
9333
  }
@@ -9339,10 +9339,10 @@ function normalizeShareValue(value, competitiveMetrics, field) {
9339
9339
  function normalizeLegacyShareOnRow(row) {
9340
9340
  const rawCm = row.competitiveMetrics;
9341
9341
  const competitiveMetrics = rawCm !== null && typeof rawCm === "object" && !Array.isArray(rawCm) ? rawCm : null;
9342
- for (const field of LEGACY_ROW_IMPRESSION_SHARE_FIELDS) {
9343
- const v = row[field];
9342
+ for (const field5 of LEGACY_ROW_IMPRESSION_SHARE_FIELDS) {
9343
+ const v = row[field5];
9344
9344
  if (typeof v !== "number" || !Number.isFinite(v)) continue;
9345
- row[field] = normalizeShareValue(v, competitiveMetrics, field);
9345
+ row[field5] = normalizeShareValue(v, competitiveMetrics, field5);
9346
9346
  }
9347
9347
  }
9348
9348
  function normalizeRowsInArray(rows) {
@@ -106008,7 +106008,7 @@ function num6(value) {
106008
106008
  function round26(value) {
106009
106009
  return Math.round(value * 100) / 100;
106010
106010
  }
106011
- function money(value) {
106011
+ function money2(value) {
106012
106012
  return round26(num6(value) ?? 0);
106013
106013
  }
106014
106014
  function count(value) {
@@ -106126,15 +106126,15 @@ function campaignRows(data) {
106126
106126
  conv += pair.conv;
106127
106127
  return [
106128
106128
  str(row.campaignName),
106129
- money(row.budgetAmountYuan),
106130
- money(row.spend),
106129
+ money2(row.budgetAmountYuan),
106130
+ money2(row.spend),
106131
106131
  count(row.impressions),
106132
106132
  count(row.clicks),
106133
106133
  rate(row.ctr),
106134
- money(row.averageCpc),
106134
+ money2(row.averageCpc),
106135
106135
  count(pair.all),
106136
106136
  count(pair.conv),
106137
- num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money(row.costPerConversion),
106137
+ num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money2(row.costPerConversion),
106138
106138
  rate(row.conversionRate)
106139
106139
  ];
106140
106140
  });
@@ -106162,13 +106162,13 @@ function keywordRows(data, lang = "zh") {
106162
106162
  str(matchOf(row)),
106163
106163
  str(row.campaignName),
106164
106164
  str(row.adGroupName),
106165
- money(row.spend),
106165
+ money2(row.spend),
106166
106166
  count(row.impressions),
106167
106167
  count(row.clicks),
106168
106168
  rate(row.ctr),
106169
- money(row.averageCpc),
106169
+ money2(row.averageCpc),
106170
106170
  count(row.conversions),
106171
- num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" : money(row.costPerConversion),
106171
+ num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" : money2(row.costPerConversion),
106172
106172
  rate(row.conversionRate)
106173
106173
  ]);
106174
106174
  }
@@ -106186,10 +106186,10 @@ function searchTermRows(data, lang = "zh") {
106186
106186
  count(row.impressions),
106187
106187
  count(row.clicks),
106188
106188
  rate(row.ctr),
106189
- money(row.averageCpc),
106190
- money(row.spend),
106189
+ money2(row.averageCpc),
106190
+ money2(row.spend),
106191
106191
  count(row.conversions),
106192
- num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" : money(row.costPerConversion),
106192
+ num6(row.costPerConversion) == null && (num6(row.conversions) ?? 0) <= 0 ? "\u2014" : money2(row.costPerConversion),
106193
106193
  rate(row.conversionRate)
106194
106194
  ]);
106195
106195
  }
@@ -106204,11 +106204,11 @@ function deviceRows(data, lang = "zh") {
106204
106204
  count(row.impressions),
106205
106205
  count(row.clicks),
106206
106206
  rate(row.ctr),
106207
- money(row.averageCpc),
106208
- money(row.spend),
106207
+ money2(row.averageCpc),
106208
+ money2(row.spend),
106209
106209
  count(pair.all),
106210
106210
  count(pair.conv),
106211
- num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money(row.costPerConversion),
106211
+ num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money2(row.costPerConversion),
106212
106212
  rate(row.conversionRate)
106213
106213
  ];
106214
106214
  });
@@ -106226,13 +106226,13 @@ function geoRows(data, lang = "zh") {
106226
106226
  count(row.impressions),
106227
106227
  interactions > 0 ? count(interactions) : 0,
106228
106228
  interactionRateOf(row, impressions, interactions),
106229
- money(row.spend),
106229
+ money2(row.spend),
106230
106230
  dashOrMoney(num6(row.spend) ?? 0, interactions),
106231
106231
  count(row.clicks),
106232
106232
  rate(row.ctr),
106233
106233
  count(pair.all),
106234
106234
  count(pair.conv),
106235
- num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money(row.costPerConversion),
106235
+ num6(row.costPerConversion) == null && pair.conv <= 0 ? "\u2014" : money2(row.costPerConversion),
106236
106236
  rate(row.conversionRate)
106237
106237
  ];
106238
106238
  });
@@ -107223,8 +107223,8 @@ var init_batch_runner = __esm({
107223
107223
  shouldDowngrade(now = Date.now()) {
107224
107224
  if (this.window.length < this.opts.windowSize) return false;
107225
107225
  if (now - this.lastDowngradeAt < this.opts.cooldownMs) return false;
107226
- const fail5 = this.window.filter((s) => !s).length;
107227
- const rate2 = fail5 / this.window.length;
107226
+ const fail7 = this.window.filter((s) => !s).length;
107227
+ const rate2 = fail7 / this.window.length;
107228
107228
  if (rate2 >= this.opts.errorRateThreshold) {
107229
107229
  this.lastDowngradeAt = now;
107230
107230
  this.window.length = 0;
@@ -112481,8 +112481,8 @@ function assertReportPushMedia(media) {
112481
112481
  process.exit(1);
112482
112482
  }
112483
112483
  }
112484
- function formatReportPushHistoryDate(isoDate2) {
112485
- const t = isoDate2.trim();
112484
+ function formatReportPushHistoryDate(isoDate3) {
112485
+ const t = isoDate3.trim();
112486
112486
  if (!t) return "";
112487
112487
  if (t.includes("T") && t.includes("+")) return t;
112488
112488
  if (t.includes("T")) return `${t}+08:00`;
@@ -116017,10 +116017,10 @@ function biddingStrategiesMatch(expected, actual) {
116017
116017
  const act = String(actual ?? "").trim().toUpperCase();
116018
116018
  return exp === "TARGET_CPA" && act === "MAXIMIZE_CONVERSIONS" || exp === "TARGET_ROAS" && act === "MAXIMIZE_CONVERSION_VALUE";
116019
116019
  }
116020
- function fieldCheck(field, expected, actual, present) {
116021
- if (!present) return { field, expected, actual: void 0, state: "unread" };
116020
+ function fieldCheck(field5, expected, actual, present) {
116021
+ if (!present) return { field: field5, expected, actual: void 0, state: "unread" };
116022
116022
  return {
116023
- field,
116023
+ field: field5,
116024
116024
  expected,
116025
116025
  actual,
116026
116026
  state: sameWriteValue(expected, actual) ? "match" : "mismatch"
@@ -116063,10 +116063,10 @@ function readKey(obj, keys) {
116063
116063
  function evaluateCampaignReadback(after, expected, readFailed) {
116064
116064
  if (readFailed || !after) return { verification: "unknown", checks: [] };
116065
116065
  const checks = [];
116066
- const push = (field, expectedValue, keys) => {
116066
+ const push = (field5, expectedValue, keys) => {
116067
116067
  if (expectedValue === void 0) return;
116068
116068
  const found = readKey(after, keys);
116069
- checks.push(fieldCheck(field, expectedValue, found.value, found.present));
116069
+ checks.push(fieldCheck(field5, expectedValue, found.value, found.present));
116070
116070
  };
116071
116071
  push("name", expected.name, ["name", "Name"]);
116072
116072
  push("statusV2", expected.statusV2, ["statusV2", "StatusV2"]);
@@ -116326,6 +116326,20 @@ function keywordRowToYuan(item) {
116326
116326
  if (rawMaxCpc == null) return item;
116327
116327
  return { ...rest, maxCPCYuan: toDisplayMoney(rawMaxCpc) };
116328
116328
  }
116329
+ function keywordApprovalCell(item) {
116330
+ const status = String(item["approvalStatusV2"] ?? item["ApprovalStatusV2"] ?? "").trim();
116331
+ return status || "\u2014";
116332
+ }
116333
+ function keywordDisapprovalReasons(item) {
116334
+ const raw = item["disapprovalReasons"] ?? item["DisapprovalReasons"];
116335
+ if (Array.isArray(raw)) {
116336
+ return raw.map((part) => String(part).trim()).filter(Boolean);
116337
+ }
116338
+ if (typeof raw === "string" && raw.trim()) {
116339
+ return raw.split(/[;;]/).map((part) => part.trim()).filter(Boolean);
116340
+ }
116341
+ return [];
116342
+ }
116329
116343
  async function runAdKeywords(opts) {
116330
116344
  opts = withResolvedAdAccount(opts);
116331
116345
  const config = loadConfig(opts.token);
@@ -116417,6 +116431,7 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
116417
116431
  { key: "campaign", header: "\u5E7F\u544A\u7CFB\u5217" },
116418
116432
  { key: "adGroup", header: "\u5E7F\u544A\u7EC4" },
116419
116433
  { key: "status", header: "\u72B6\u6001" },
116434
+ { key: "approval", header: "\u5BA1\u6838" },
116420
116435
  { key: "matchType", header: "\u5339\u914D\u7C7B\u578B" },
116421
116436
  { key: "impressions", header: "\u5C55\u793A" },
116422
116437
  { key: "clicks", header: "\u70B9\u51FB" },
@@ -116430,6 +116445,7 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
116430
116445
  const adGroup = String(item["adGroupName"] ?? item["adGroup"] ?? "");
116431
116446
  const status = String(item["userStatus"] ?? "");
116432
116447
  const matchType = String(item["matchTypeV2"] ?? "");
116448
+ const approval = keywordApprovalCell(item);
116433
116449
  const ctr = item["ctr"] != null ? (Number(item["ctr"]) * 100).toFixed(2) + "%" : "\u2014";
116434
116450
  const spend = item["spend"] != null ? Number(item["spend"]).toFixed(2) : "\u2014";
116435
116451
  const valueRaw = item["conversionsValue"];
@@ -116439,6 +116455,7 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
116439
116455
  campaign: campaign.slice(0, campW),
116440
116456
  adGroup: adGroup.slice(0, grpW),
116441
116457
  status,
116458
+ approval,
116442
116459
  matchType,
116443
116460
  impressions: String(item["impressions"] ?? 0),
116444
116461
  clicks: String(item["clicks"] ?? 0),
@@ -116448,6 +116465,12 @@ ${label2}\uFF08\u8D26\u6237\uFF1A${opts.account}\uFF0C\u7B2C 1 \u9875\uFF0C\u672
116448
116465
  };
116449
116466
  });
116450
116467
  printCliTable(rows, cols);
116468
+ items3.forEach((item) => {
116469
+ const reasons = keywordDisapprovalReasons(item);
116470
+ if (reasons.length === 0) return;
116471
+ const text4 = String(item["text"] ?? item["keywordText"] ?? item["id"] ?? "");
116472
+ console.log(` \u62D2\u5BA1 ${text4}\uFF1A${reasons.join("\uFF1B")}`);
116473
+ });
116451
116474
  }
116452
116475
  console.log();
116453
116476
  }
@@ -117761,46 +117784,46 @@ function validateRsaDisplayPath(prefix, ad, errors, lengthViolations) {
117761
117784
  `${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`
117762
117785
  );
117763
117786
  }
117764
- for (const [field, label2, example] of [
117787
+ for (const [field5, label2, example] of [
117765
117788
  ["Path1", "\u663E\u793A\u8DEF\u5F84\u7B2C 1 \u6BB5", '"Path1": "products"'],
117766
117789
  ["Path2", "\u663E\u793A\u8DEF\u5F84\u7B2C 2 \u6BB5", '"Path2": "steel"']
117767
117790
  ]) {
117768
- const raw = ad[field];
117791
+ const raw = ad[field5];
117769
117792
  if (raw === void 0) {
117770
117793
  pushErr2(
117771
117794
  errors,
117772
- `${prefix}.${field} \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}`
117795
+ `${prefix}.${field5} \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}`
117773
117796
  );
117774
117797
  continue;
117775
117798
  }
117776
117799
  if (raw === null) {
117777
117800
  pushErr2(
117778
117801
  errors,
117779
- `${prefix}.${field} \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}`
117802
+ `${prefix}.${field5} \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}`
117780
117803
  );
117781
117804
  continue;
117782
117805
  }
117783
117806
  if (typeof raw !== "string") {
117784
- pushErr2(errors, `${prefix}.${field} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u7C7B\u578B\u4E3A ${typeof raw}\u3002${jsonHint}`);
117807
+ pushErr2(errors, `${prefix}.${field5} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u7C7B\u578B\u4E3A ${typeof raw}\u3002${jsonHint}`);
117785
117808
  continue;
117786
117809
  }
117787
117810
  const len = calcGoogleCharLength(raw);
117788
117811
  if (len > 15) {
117789
117812
  pushLengthViolation(lengthViolations, {
117790
- path: `${prefix}.${field}`,
117791
- field,
117813
+ path: `${prefix}.${field5}`,
117814
+ field: field5,
117792
117815
  kind: "rsa_path",
117793
117816
  limit: 15,
117794
117817
  actual: len,
117795
117818
  countMode: "google",
117796
117819
  text: raw
117797
117820
  });
117798
- pushErr2(errors, `${prefix}.${field} \u8D85\u8FC7 15 \u5B57\u7B26\uFF08\u5F53\u524D ${len}\uFF0CCJK \u6309 2 \u8BA1\uFF09\uFF1A"${raw}"`);
117821
+ pushErr2(errors, `${prefix}.${field5} \u8D85\u8FC7 15 \u5B57\u7B26\uFF08\u5F53\u524D ${len}\uFF0CCJK \u6309 2 \u8BA1\uFF09\uFF1A"${raw}"`);
117799
117822
  }
117800
117823
  if (raw.length > 0 && !PATH_SEGMENT_REGEX.test(raw)) {
117801
117824
  pushErr2(
117802
117825
  errors,
117803
- `${prefix}.${field} \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}"`
117826
+ `${prefix}.${field5} \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}"`
117804
117827
  );
117805
117828
  }
117806
117829
  }
@@ -117839,10 +117862,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
117839
117862
  for (let i = 0; i < headlines.length; i++) {
117840
117863
  const len = calcGoogleCharLength(headlines[i]);
117841
117864
  if (len > 30) {
117842
- const field = headlineFields[i] ?? `headline[${i}]`;
117865
+ const field5 = headlineFields[i] ?? `headline[${i}]`;
117843
117866
  pushLengthViolation(lengthViolations, {
117844
- path: `${prefix}.${field}`,
117845
- field,
117867
+ path: `${prefix}.${field5}`,
117868
+ field: field5,
117846
117869
  kind: "rsa_headline",
117847
117870
  limit: 30,
117848
117871
  actual: len,
@@ -117874,10 +117897,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
117874
117897
  for (let i = 0; i < descriptions.length; i++) {
117875
117898
  const len = calcGoogleCharLength(descriptions[i]);
117876
117899
  if (len > 90) {
117877
- const field = descriptionFields[i] ?? `description[${i}]`;
117900
+ const field5 = descriptionFields[i] ?? `description[${i}]`;
117878
117901
  pushLengthViolation(lengthViolations, {
117879
- path: `${prefix}.${field}`,
117880
- field,
117902
+ path: `${prefix}.${field5}`,
117903
+ field: field5,
117881
117904
  kind: "rsa_description",
117882
117905
  limit: 90,
117883
117906
  actual: len,
@@ -119599,6 +119622,1098 @@ async function runAdEdit(opts) {
119599
119622
  `);
119600
119623
  }
119601
119624
 
119625
+ // src/commands/ad/exclusions.ts
119626
+ init_auth();
119627
+ init_cli_json_snapshot();
119628
+ init_cli_table();
119629
+ init_shared();
119630
+ var EXCLUSION_TYPES = [
119631
+ "content-label",
119632
+ "placement",
119633
+ "youtube-channel",
119634
+ "youtube-video",
119635
+ "app",
119636
+ "app-category"
119637
+ ];
119638
+ var RESERVED_PLACEMENT_SUFFIXES = [".invalid", ".example", ".test", ".localhost"];
119639
+ function normalizePlacementUrl(raw) {
119640
+ const trimmed = raw.trim();
119641
+ if (!trimmed || /\s/.test(trimmed) || trimmed.includes(",")) {
119642
+ throw new Error("\u7248\u4F4D\u9700\u8981\u4E00\u4E2A\u7F51\u5740\uFF0C\u4E0D\u80FD\u542B\u7A7A\u683C\u3002\u4F8B\u5982 http://www.domain.com");
119643
+ }
119644
+ const withScheme = /^https?:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;
119645
+ let url;
119646
+ try {
119647
+ url = new URL(withScheme);
119648
+ } catch {
119649
+ throw new Error("\u7248\u4F4D\u7F51\u5740\u683C\u5F0F\u4E0D\u5BF9\u3002\u4F8B\u5982 http://www.domain.com\uFF0C\u8DEF\u5F84\u6700\u591A\u4E24\u7EA7\u3002");
119650
+ }
119651
+ if (url.username || url.password || url.search || url.hash || !url.hostname.includes(".")) {
119652
+ throw new Error("\u7248\u4F4D\u7F51\u5740\u4E0D\u8981\u5E26\u8D26\u53F7\u3001\u53C2\u6570\u6216\u951A\u70B9\u3002\u4F8B\u5982 http://www.domain.com");
119653
+ }
119654
+ const host = url.hostname.toLowerCase();
119655
+ if (RESERVED_PLACEMENT_SUFFIXES.some((suffix) => host.endsWith(suffix))) {
119656
+ throw new Error("Google \u4E0D\u63A5\u53D7 .invalid\u3001.example\u3001.test \u8FD9\u7C7B\u4FDD\u7559\u57DF\u540D\u3002\u8BF7\u7528\u771F\u5B9E\u7F51\u7AD9\uFF0C\u4F8B\u5982 http://www.domain.com\u3002");
119657
+ }
119658
+ const parts = url.pathname.split("/").filter(Boolean);
119659
+ if (parts.length > 2) {
119660
+ throw new Error("\u7248\u4F4D\u7F51\u5740\u6700\u591A\u4E24\u7EA7\u8DEF\u5F84\uFF0C\u4F8B\u5982 http://www.domain.com/news/2024");
119661
+ }
119662
+ const path58 = parts.length > 0 ? `/${parts.join("/")}` : "";
119663
+ return `${url.protocol}//${host}${path58}`;
119664
+ }
119665
+ var GROUP_LABEL = {
119666
+ sensitive: "\u654F\u611F\u5185\u5BB9",
119667
+ types: "\u7C7B\u578B\u548C\u6807\u7B7E",
119668
+ themes: "\u5185\u5BB9\u4E3B\u9898"
119669
+ };
119670
+ function buildExclusionCreateBody(input) {
119671
+ const type = input.type.trim().toLowerCase();
119672
+ if (!EXCLUSION_TYPES.includes(type)) {
119673
+ throw new Error(
119674
+ "type \u987B\u4E3A content-label | placement | youtube-channel | youtube-video | app | app-category"
119675
+ );
119676
+ }
119677
+ const filled = [
119678
+ input.contentLabel,
119679
+ input.url,
119680
+ input.channelId,
119681
+ input.videoId,
119682
+ input.appId,
119683
+ input.appCategoryId
119684
+ ].filter((value) => value != null && String(value).trim() !== "");
119685
+ if (filled.length !== 1) {
119686
+ throw new Error("\u4E00\u6B21\u53EA\u586B\u4E00\u79CD\u503C\uFF1A\u5185\u5BB9\u6807\u7B7E\u3001\u7F51\u5740\u3001\u9891\u9053\u3001\u89C6\u9891\u3001\u5E94\u7528\u6216\u5E94\u7528\u7C7B\u522B id");
119687
+ }
119688
+ if (type === "content-label") {
119689
+ const contentLabel = input.contentLabel?.trim() ?? "";
119690
+ if (!contentLabel) throw new Error("content-label \u9700\u8981 --content-label");
119691
+ return { type, contentLabel };
119692
+ }
119693
+ if (type === "placement") {
119694
+ return { type, url: normalizePlacementUrl(input.url ?? "") };
119695
+ }
119696
+ if (type === "youtube-channel") {
119697
+ const channelId = input.channelId?.trim() ?? "";
119698
+ if (!channelId) throw new Error("youtube-channel \u9700\u8981 --channel-id");
119699
+ return { type, channelId };
119700
+ }
119701
+ if (type === "youtube-video") {
119702
+ const videoId = input.videoId?.trim() ?? "";
119703
+ if (!videoId) throw new Error("youtube-video \u9700\u8981 --video-id");
119704
+ return { type, videoId };
119705
+ }
119706
+ if (type === "app") {
119707
+ const appId = input.appId?.trim() ?? "";
119708
+ if (!/^[12]-.+/.test(appId)) {
119709
+ throw new Error("app \u7684 --app-id \u5F62\u5982 1-123456789\uFF08Apple\uFF09\u6216 2-com.example.app\uFF08Google Play\uFF09");
119710
+ }
119711
+ return { type, appId };
119712
+ }
119713
+ const appCategoryId = input.appCategoryId?.trim() ?? "";
119714
+ if (!/^\d+$/.test(appCategoryId)) {
119715
+ throw new Error("app-category \u9700\u8981 app-categories \u8FD4\u56DE\u7684\u6570\u5B57 --app-category-id");
119716
+ }
119717
+ return { type, appCategoryId };
119718
+ }
119719
+ function exclusionsUrl(googleApiUrl, accountId) {
119720
+ return `${googleApiUrl}/campaignmanagement/accounts/${accountId}/exclusions`;
119721
+ }
119722
+ function unwrapItems(body) {
119723
+ if (Array.isArray(body)) return body;
119724
+ if (body && typeof body === "object") {
119725
+ const record2 = body;
119726
+ const data = record2["data"] ?? record2["Data"] ?? record2["items"] ?? record2["Items"];
119727
+ if (Array.isArray(data)) return data;
119728
+ }
119729
+ return [];
119730
+ }
119731
+ function field(item, ...keys) {
119732
+ for (const key of keys) {
119733
+ const value = item[key];
119734
+ if (value != null && String(value).trim() !== "") return String(value);
119735
+ }
119736
+ return "";
119737
+ }
119738
+ async function runAdExclusionsList(opts) {
119739
+ opts = withResolvedAdAccount(opts);
119740
+ const config = loadConfig(opts.token);
119741
+ const url = exclusionsUrl(requireGoogleApi(config), opts.account);
119742
+ let items3;
119743
+ try {
119744
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
119745
+ } catch (err) {
119746
+ console.error(`
119747
+ \u274C \u67E5\u8BE2\u5185\u5BB9\u6392\u9664\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
119748
+ `);
119749
+ process.exit(1);
119750
+ }
119751
+ if (opts.type) {
119752
+ const type = opts.type.trim().toLowerCase();
119753
+ items3 = items3.filter((item) => field(item, "type", "Type") === type);
119754
+ }
119755
+ const payload = { account: opts.account, count: items3.length, items: items3 };
119756
+ if (await emitCliJsonOrSnapshot(opts, {
119757
+ section: "ad-exclusions",
119758
+ commandLabel: "ad exclusions list",
119759
+ payload
119760
+ })) {
119761
+ return;
119762
+ }
119763
+ console.log(`
119764
+ \u8D26\u6237\u7EA7\u5185\u5BB9\u6392\u9664\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF09`);
119765
+ console.log("\u8FD9\u662F\u5185\u5BB9\u9002\u5B9C\u6027\uFF0C\u4E0D\u662F\u641C\u7D22\u5426\u8BCD\uFF0C\u4E5F\u4E0D\u662F\u5185\u5BB9\u5173\u952E\u5B57\u3002\n");
119766
+ if (items3.length === 0) {
119767
+ console.log(" \u6682\u65E0\u6392\u9664\u3002\n");
119768
+ return;
119769
+ }
119770
+ printCliTable(
119771
+ items3.map((item) => ({
119772
+ id: field(item, "criterionId", "CriterionId"),
119773
+ type: field(item, "type", "Type"),
119774
+ group: GROUP_LABEL[field(item, "group", "Group")] ?? field(item, "group", "Group"),
119775
+ value: field(item, "value", "Value", "labelZh", "LabelZh")
119776
+ })),
119777
+ [
119778
+ { key: "id", header: "criterionId" },
119779
+ { key: "type", header: "\u7C7B\u578B" },
119780
+ { key: "group", header: "\u5206\u7EC4" },
119781
+ { key: "value", header: "\u5185\u5BB9" }
119782
+ ]
119783
+ );
119784
+ console.log();
119785
+ }
119786
+ async function runAdExclusionsAdd(opts) {
119787
+ opts = withResolvedAdAccount(opts);
119788
+ let body;
119789
+ try {
119790
+ body = buildExclusionCreateBody(opts);
119791
+ } catch (err) {
119792
+ console.error(`
119793
+ \u274C ${err instanceof Error ? err.message : String(err)}
119794
+ `);
119795
+ process.exit(1);
119796
+ }
119797
+ const config = loadConfig(opts.token);
119798
+ const url = exclusionsUrl(requireGoogleApi(config), opts.account);
119799
+ let created;
119800
+ try {
119801
+ created = await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
119802
+ } catch (err) {
119803
+ console.error(`
119804
+ \u274C \u6DFB\u52A0\u5185\u5BB9\u6392\u9664\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
119805
+ `);
119806
+ process.exit(1);
119807
+ }
119808
+ const payload = { account: opts.account, request: body, response: created };
119809
+ if (await emitCliJsonOrSnapshot(opts, {
119810
+ section: "ad-exclusions-add",
119811
+ commandLabel: "ad exclusions add",
119812
+ payload
119813
+ })) {
119814
+ return;
119815
+ }
119816
+ const item = created && typeof created === "object" ? created : {};
119817
+ console.log(
119818
+ `
119819
+ \u2705 \u5DF2\u6DFB\u52A0\u8D26\u6237\u7EA7\u6392\u9664 ${field(item, "type", "Type") || body.type} ${field(item, "value", "Value") || field(item, "criterionId", "CriterionId")}
119820
+ `
119821
+ );
119822
+ }
119823
+ async function runAdExclusionsRemove(opts) {
119824
+ opts = withResolvedAdAccount(opts);
119825
+ if (!/^\d+$/.test(opts.criterionId.trim())) {
119826
+ console.error("\n\u274C --criterion-id \u987B\u4E3A list \u8FD4\u56DE\u7684\u6570\u5B57\n");
119827
+ process.exit(1);
119828
+ }
119829
+ const config = loadConfig(opts.token);
119830
+ const url = `${exclusionsUrl(requireGoogleApi(config), opts.account)}/${opts.criterionId.trim()}`;
119831
+ try {
119832
+ await apiDeleteRaw(url, config, { verbose: opts.verbose });
119833
+ } catch (err) {
119834
+ console.error(`
119835
+ \u274C \u5220\u9664\u5185\u5BB9\u6392\u9664\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
119836
+ `);
119837
+ process.exit(1);
119838
+ }
119839
+ console.log(`
119840
+ \u2705 \u5DF2\u5220\u9664\u5185\u5BB9\u6392\u9664 ${opts.criterionId}
119841
+ `);
119842
+ }
119843
+ async function runAdExclusionContentLabels(opts) {
119844
+ const config = loadConfig(opts.token);
119845
+ const url = `${requireGoogleApi(config)}/campaignmanagement/exclusions/content-labels`;
119846
+ let items3;
119847
+ try {
119848
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
119849
+ } catch (err) {
119850
+ console.error(`
119851
+ \u274C \u67E5\u8BE2\u5185\u5BB9\u6807\u7B7E\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
119852
+ `);
119853
+ process.exit(1);
119854
+ }
119855
+ const payload = { count: items3.length, items: items3 };
119856
+ if (await emitCliJsonOrSnapshot(opts, {
119857
+ section: "ad-exclusion-content-labels",
119858
+ commandLabel: "ad exclusions content-labels",
119859
+ payload
119860
+ })) {
119861
+ return;
119862
+ }
119863
+ console.log("\n\u5185\u5BB9\u6807\u7B7E\u3002\u5185\u5BB9\u4E3B\u9898\u4E5F\u662F content_label\uFF0C\u4E0D\u662F Topic\u3002\u5185\u5BB9\u5173\u952E\u5B57\u6CA1\u6709\u516C\u5F00\u5B57\u6BB5\u3002\n");
119864
+ printCliTable(
119865
+ items3.map((item) => ({
119866
+ group: GROUP_LABEL[field(item, "group", "Group")] ?? field(item, "group", "Group"),
119867
+ label: field(item, "labelZh", "LabelZh"),
119868
+ name: field(item, "contentLabel", "ContentLabel")
119869
+ })),
119870
+ [
119871
+ { key: "group", header: "\u5206\u7EC4" },
119872
+ { key: "label", header: "\u540D\u79F0" },
119873
+ { key: "name", header: "contentLabel" }
119874
+ ]
119875
+ );
119876
+ console.log();
119877
+ }
119878
+ async function runAdExclusionAppCategories(opts) {
119879
+ opts = withResolvedAdAccount(opts);
119880
+ const config = loadConfig(opts.token);
119881
+ const url = `${exclusionsUrl(requireGoogleApi(config), opts.account)}/app-categories`;
119882
+ let items3;
119883
+ try {
119884
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
119885
+ } catch (err) {
119886
+ console.error(`
119887
+ \u274C \u67E5\u8BE2\u5E94\u7528\u7C7B\u522B\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
119888
+ `);
119889
+ process.exit(1);
119890
+ }
119891
+ const payload = { account: opts.account, count: items3.length, items: items3 };
119892
+ if (await emitCliJsonOrSnapshot(opts, {
119893
+ section: "ad-exclusion-app-categories",
119894
+ commandLabel: "ad exclusions app-categories",
119895
+ payload
119896
+ })) {
119897
+ return;
119898
+ }
119899
+ console.log(`
119900
+ \u5E94\u7528\u7C7B\u522B\uFF08${items3.length} \u4E2A\uFF0C\u4EE5\u672C\u6B21\u67E5\u8BE2\u4E3A\u51C6\uFF09
119901
+ `);
119902
+ printCliTable(
119903
+ items3.map((item) => ({
119904
+ id: field(item, "id", "Id"),
119905
+ name: field(item, "name", "Name")
119906
+ })),
119907
+ [
119908
+ { key: "id", header: "id" },
119909
+ { key: "name", header: "\u540D\u79F0" }
119910
+ ]
119911
+ );
119912
+ console.log();
119913
+ }
119914
+
119915
+ // src/commands/ad/account-insights.ts
119916
+ init_auth();
119917
+ init_cli_json_snapshot();
119918
+ init_cli_table();
119919
+ init_shared();
119920
+ function inclusiveDayCount(start, end) {
119921
+ const a = Date.parse(`${start}T00:00:00Z`);
119922
+ const b = Date.parse(`${end}T00:00:00Z`);
119923
+ if (!Number.isFinite(a) || !Number.isFinite(b)) {
119924
+ throw new Error("\u65E5\u671F\u987B\u4E3A YYYY-MM-DD");
119925
+ }
119926
+ return Math.round((b - a) / 864e5) + 1;
119927
+ }
119928
+ function isoDate(dateStr, offsetDays) {
119929
+ if (dateStr) {
119930
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) throw new Error("\u65E5\u671F\u987B\u4E3A YYYY-MM-DD");
119931
+ return dateStr;
119932
+ }
119933
+ const d = /* @__PURE__ */ new Date();
119934
+ d.setDate(d.getDate() + offsetDays);
119935
+ return d.toISOString().slice(0, 10);
119936
+ }
119937
+ function assertChangeRange(start, end) {
119938
+ const days = inclusiveDayCount(start, end);
119939
+ if (days < 1) throw new Error("\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65E5\u671F");
119940
+ if (days > 30) throw new Error("\u64CD\u4F5C\u8BB0\u5F55\u53EA\u4FDD\u7559\u7EA6 30 \u5929\uFF0C\u8BF7\u628A\u533A\u95F4\u7F29\u5230 30 \u5929\u5185");
119941
+ }
119942
+ function field2(item, ...keys) {
119943
+ for (const key of keys) {
119944
+ const value = item[key];
119945
+ if (value != null && String(value).trim() !== "") return String(value);
119946
+ }
119947
+ return "";
119948
+ }
119949
+ function money(item) {
119950
+ const raw = item["spend"] ?? item["Spend"];
119951
+ const n = typeof raw === "number" ? raw : Number(raw);
119952
+ return Number.isFinite(n) ? n.toFixed(2) : "\u2014";
119953
+ }
119954
+ async function runAdPlacements(opts) {
119955
+ opts = withResolvedAdAccount(opts);
119956
+ let start;
119957
+ let end;
119958
+ try {
119959
+ start = isoDate(opts.start, -30);
119960
+ end = isoDate(opts.end, 0);
119961
+ } catch (err) {
119962
+ console.error(`
119963
+ \u274C ${err instanceof Error ? err.message : String(err)}
119964
+ `);
119965
+ process.exit(1);
119966
+ }
119967
+ const config = loadConfig(opts.token);
119968
+ const url = `${requireGoogleApi(config)}/campaignmanagement/accounts/${opts.account}/placements?startDate=${start}&endDate=${end}`;
119969
+ let items3;
119970
+ try {
119971
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
119972
+ } catch (err) {
119973
+ console.error(`
119974
+ \u274C \u67E5\u8BE2\u7248\u4F4D\u82B1\u8D39\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
119975
+ `);
119976
+ process.exit(1);
119977
+ }
119978
+ const payload = { account: opts.account, start, end, count: items3.length, items: items3 };
119979
+ if (await emitCliJsonOrSnapshot(opts, {
119980
+ section: "ad-placements",
119981
+ commandLabel: "ad placements",
119982
+ payload
119983
+ })) {
119984
+ return;
119985
+ }
119986
+ console.log(`
119987
+ \u7248\u4F4D\u82B1\u8D39 ${start} ~ ${end}\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF0C\u6309\u82B1\u8D39\u964D\u5E8F\uFF0C\u6700\u591A 500\uFF09`);
119988
+ console.log("\u8FD9\u662F\u5177\u4F53\u7F51\u7AD9 / \u5E94\u7528 / \u9891\u9053\u3002Demand Gen \u6E20\u9053\u7ED3\u6784\u4ECD\u7528 ad demand-gen report\u3002\n");
119989
+ if (items3.length === 0) {
119990
+ console.log(" \u8FD9\u4E2A\u533A\u95F4\u6CA1\u6709\u5C55\u793A\u3002\n");
119991
+ return;
119992
+ }
119993
+ printCliTable(
119994
+ items3.map((item) => ({
119995
+ campaign: field2(item, "campaignName", "CampaignName"),
119996
+ type: field2(item, "placementType", "PlacementType"),
119997
+ name: field2(item, "displayName", "DisplayName") || field2(item, "placement", "Placement"),
119998
+ spend: money(item),
119999
+ clicks: field2(item, "clicks", "Clicks") || "0",
120000
+ conversions: field2(item, "conversions", "Conversions") || "0"
120001
+ })),
120002
+ [
120003
+ { key: "campaign", header: "\u7CFB\u5217" },
120004
+ { key: "type", header: "\u7C7B\u578B" },
120005
+ { key: "name", header: "\u7248\u4F4D" },
120006
+ { key: "spend", header: "\u82B1\u8D39" },
120007
+ { key: "clicks", header: "\u70B9\u51FB" },
120008
+ { key: "conversions", header: "\u8F6C\u5316" }
120009
+ ]
120010
+ );
120011
+ console.log();
120012
+ }
120013
+ async function runAdConversionGoals(opts) {
120014
+ opts = withResolvedAdAccount(opts);
120015
+ if (opts.campaignId && !/^\d+$/.test(opts.campaignId.trim())) {
120016
+ console.error("\n\u274C --campaign-id \u987B\u4E3A\u6570\u5B57\n");
120017
+ process.exit(1);
120018
+ }
120019
+ const config = loadConfig(opts.token);
120020
+ const query = opts.campaignId ? `?campaignId=${opts.campaignId.trim()}` : "";
120021
+ const url = `${requireGoogleApi(config)}/campaignmanagement/accounts/${opts.account}/conversion-goals${query}`;
120022
+ let items3;
120023
+ try {
120024
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
120025
+ } catch (err) {
120026
+ console.error(`
120027
+ \u274C \u67E5\u8BE2\u8F6C\u5316\u76EE\u6807\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
120028
+ `);
120029
+ process.exit(1);
120030
+ }
120031
+ const payload = { account: opts.account, count: items3.length, items: items3 };
120032
+ if (await emitCliJsonOrSnapshot(opts, {
120033
+ section: "ad-conversion-goals",
120034
+ commandLabel: "ad conversion-goals",
120035
+ payload
120036
+ })) {
120037
+ return;
120038
+ }
120039
+ console.log(`
120040
+ \u7CFB\u5217\u8BA1\u5165\u51FA\u4EF7\u7684\u8F6C\u5316\u76EE\u6807\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF09`);
120041
+ console.log("\u8FD9\u4E0D\u662F\u8D26\u6237\u91CC\u914D\u8FC7\u7684\u5168\u90E8\u8F6C\u5316\u52A8\u4F5C\u3002CPA \u5F02\u5E38\u65F6\u5148\u770B biddable\uFF0C\u4E0D\u8981\u5148\u6539\u51FA\u4EF7\u3002\n");
120042
+ printCliTable(
120043
+ items3.map((item) => ({
120044
+ campaign: field2(item, "campaignName", "CampaignName"),
120045
+ category: field2(item, "category", "Category"),
120046
+ origin: field2(item, "origin", "Origin"),
120047
+ biddable: String(item["biddable"] ?? item["Biddable"] ?? "")
120048
+ })),
120049
+ [
120050
+ { key: "campaign", header: "\u7CFB\u5217" },
120051
+ { key: "category", header: "\u7C7B\u522B" },
120052
+ { key: "origin", header: "\u6765\u6E90" },
120053
+ { key: "biddable", header: "\u8BA1\u5165\u51FA\u4EF7" }
120054
+ ]
120055
+ );
120056
+ console.log();
120057
+ }
120058
+ async function runAdChanges(opts) {
120059
+ opts = withResolvedAdAccount(opts);
120060
+ try {
120061
+ assertChangeRange(opts.start, opts.end);
120062
+ } catch (err) {
120063
+ console.error(`
120064
+ \u274C ${err instanceof Error ? err.message : String(err)}
120065
+ `);
120066
+ process.exit(1);
120067
+ }
120068
+ const config = loadConfig(opts.token);
120069
+ const url = `${requireGoogleApi(config)}/campaignmanagement/accounts/${opts.account}/changes?startDate=${opts.start}&endDate=${opts.end}`;
120070
+ let items3;
120071
+ try {
120072
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
120073
+ } catch (err) {
120074
+ console.error(`
120075
+ \u274C \u67E5\u8BE2\u64CD\u4F5C\u8BB0\u5F55\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
120076
+ `);
120077
+ process.exit(1);
120078
+ }
120079
+ const payload = {
120080
+ account: opts.account,
120081
+ start: opts.start,
120082
+ end: opts.end,
120083
+ count: items3.length,
120084
+ note: "\u5B98\u65B9 change_event \u5927\u7EA6\u53EA\u4FDD\u7559 30 \u5929\u3002\u7A7A\u5217\u8868\u8868\u793A\u8FD9\u6BB5\u6CA1\u6709\u8BB0\u5F55\uFF0C\u4E0D\u662F\u67E5\u8BE2\u5931\u8D25\u3002",
120085
+ items: items3
120086
+ };
120087
+ if (await emitCliJsonOrSnapshot(opts, {
120088
+ section: "ad-changes",
120089
+ commandLabel: "ad changes",
120090
+ payload
120091
+ })) {
120092
+ return;
120093
+ }
120094
+ console.log(`
120095
+ \u64CD\u4F5C\u8BB0\u5F55 ${opts.start} ~ ${opts.end}\uFF08${opts.account}\uFF0C${items3.length} \u6761\uFF0C\u6700\u591A 500\uFF09`);
120096
+ console.log("\u8D85\u8FC7\u5B98\u65B9\u4FDD\u7559\u671F\u65F6\u8FD9\u91CC\u662F\u7A7A\u7684\uFF0C\u4E0D\u8981\u8865\u5199\u3002\n");
120097
+ if (items3.length === 0) {
120098
+ console.log(" \u8FD9\u6BB5\u6CA1\u6709\u64CD\u4F5C\u8BB0\u5F55\u3002\n");
120099
+ return;
120100
+ }
120101
+ printCliTable(
120102
+ items3.map((item) => ({
120103
+ time: field2(item, "changeDateTime", "ChangeDateTime"),
120104
+ type: field2(item, "resourceType", "ResourceType"),
120105
+ op: field2(item, "operation", "Operation"),
120106
+ who: field2(item, "userEmail", "UserEmail") || field2(item, "clientType", "ClientType"),
120107
+ fields: field2(item, "changedFields", "ChangedFields")
120108
+ })),
120109
+ [
120110
+ { key: "time", header: "\u65F6\u95F4" },
120111
+ { key: "type", header: "\u8D44\u6E90" },
120112
+ { key: "op", header: "\u64CD\u4F5C" },
120113
+ { key: "who", header: "\u6765\u6E90" },
120114
+ { key: "fields", header: "\u5B57\u6BB5" }
120115
+ ]
120116
+ );
120117
+ console.log();
120118
+ }
120119
+
120120
+ // src/commands/ad/negative-list.ts
120121
+ init_auth();
120122
+ init_shared();
120123
+ function negativeListAttachUrl(googleApiUrl, accountId) {
120124
+ return `${googleApiUrl}/negativekeywordmanagement/account-list/${accountId}/attach`;
120125
+ }
120126
+ async function runAdNegativeList(opts) {
120127
+ if (!opts.jsonOut) {
120128
+ console.log("\u8D26\u6237\u7EA7\u641C\u7D22\u5426\u8BCD\u5217\u8868\u3002\u6BCF\u6237\u4E00\u4E2A\uFF0C\u4E0D\u7BA1 YouTube / \u5C55\u793A\u5185\u5BB9\u3002");
120129
+ }
120130
+ await runAdKeywords({
120131
+ token: opts.token,
120132
+ account: opts.account,
120133
+ negative: true,
120134
+ level: "Account",
120135
+ jsonOut: opts.jsonOut,
120136
+ verbose: opts.verbose
120137
+ });
120138
+ }
120139
+ async function runAdNegativeListAdd(opts) {
120140
+ await runAdNegativeKeywordCreate({
120141
+ token: opts.token,
120142
+ account: opts.account,
120143
+ level: "Account",
120144
+ keywords: opts.keywords,
120145
+ keywordsFile: opts.keywordsFile,
120146
+ matchType: opts.matchType,
120147
+ jsonOut: opts.jsonOut,
120148
+ verbose: opts.verbose
120149
+ });
120150
+ }
120151
+ async function runAdNegativeListRemove(opts) {
120152
+ await runAdNegativeKeywordDelete({
120153
+ token: opts.token,
120154
+ account: opts.account,
120155
+ id: opts.id,
120156
+ verbose: opts.verbose
120157
+ });
120158
+ }
120159
+ async function runAdNegativeListAttach(opts) {
120160
+ opts = withResolvedAdAccount(opts);
120161
+ const config = loadConfig(opts.token);
120162
+ const url = negativeListAttachUrl(requireGoogleApi(config), opts.account);
120163
+ let response;
120164
+ try {
120165
+ response = await apiFetch2(url, config, { method: "POST", body: "{}" }, opts.verbose);
120166
+ } catch (err) {
120167
+ console.error(`
120168
+ \u274C \u6302\u63A5\u5426\u8BCD\u5217\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
120169
+ `);
120170
+ process.exit(1);
120171
+ }
120172
+ const item = response && typeof response === "object" ? response : {};
120173
+ const already = item["alreadyAttached"] ?? item["AlreadyAttached"];
120174
+ const sharedSetId = item["sharedSetId"] ?? item["SharedSetId"] ?? "";
120175
+ console.log(
120176
+ `
120177
+ \u2705 \u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u5DF2\u6302\u63A5 sharedSetId=${String(sharedSetId)}${already ? "\uFF08\u672C\u6765\u5C31\u6302\u7740\uFF09" : ""}
120178
+ `
120179
+ );
120180
+ }
120181
+
120182
+ // src/commands/ad/pmax-protection.ts
120183
+ init_auth();
120184
+ init_cli_json_snapshot();
120185
+ init_cli_table();
120186
+ init_shared();
120187
+ function requireDigits(raw, label2) {
120188
+ const value = (raw ?? "").trim();
120189
+ if (!/^\d+$/.test(value)) throw new Error(`${label2} \u987B\u4E3A\u6570\u5B57`);
120190
+ return value;
120191
+ }
120192
+ function requireCampaignId(campaignId, hint) {
120193
+ const value = (campaignId ?? "").trim();
120194
+ if (!/^\d+$/.test(value)) {
120195
+ throw new Error(`${hint} \u5FC5\u987B\u5E26\u6570\u5B57 --campaign-id\u3002\u8FD9\u4E0D\u662F ad search-terms`);
120196
+ }
120197
+ return value;
120198
+ }
120199
+ function assertBrandEntityId(raw) {
120200
+ const value = (raw ?? "").trim();
120201
+ const mid = /^\/[a-z]\/[A-Za-z0-9_]+$/.test(value);
120202
+ if (!/^\d+$/.test(value) && !mid) {
120203
+ throw new Error("\u54C1\u724C id \u5FC5\u987B\u6765\u81EA pmax-brands search\uFF0C\u4E0D\u80FD\u624B\u5199\u54C1\u724C\u540D");
120204
+ }
120205
+ return value;
120206
+ }
120207
+ function assertWebpageOperator(raw) {
120208
+ const value = (raw ?? "").trim().toUpperCase();
120209
+ if (value === "EQUALS" || value === "CONTAINS") return value;
120210
+ throw new Error("\u7F51\u5740\u6761\u4EF6\u53EA\u63A5\u53D7 EQUALS \u6216 CONTAINS");
120211
+ }
120212
+ function assertKeywordText(raw) {
120213
+ const value = (raw ?? "").trim();
120214
+ if (!value || value.includes(",") || value.length > 80) {
120215
+ throw new Error("\u4E00\u6B21\u52A0\u4E00\u4E2A\u8BCD\uFF0C\u4E0D\u80FD\u4E3A\u7A7A\u3001\u4E0D\u80FD\u542B\u9017\u53F7\u3001\u4E0D\u80FD\u8D85\u8FC7 80 \u4E2A\u5B57\u7B26");
120216
+ }
120217
+ return value;
120218
+ }
120219
+ function hyphenRange(start, end, label2) {
120220
+ const from = isoDate(start, -30);
120221
+ const to = isoDate(end, 0);
120222
+ const days = inclusiveDayCount(from, to);
120223
+ if (days < 1) throw new Error("\u7ED3\u675F\u65E5\u671F\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65E5\u671F");
120224
+ if (days > 366) throw new Error(`${label2}\u533A\u95F4\u4E0D\u80FD\u8D85\u8FC7 366 \u5929`);
120225
+ return { start: from, end: to };
120226
+ }
120227
+ function pmaxSearchTermsUrl(base2, account, campaignId, start, end) {
120228
+ const id = requireCampaignId(campaignId, "pmax-search-terms");
120229
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(start) || !/^\d{4}-\d{2}-\d{2}$/.test(end)) {
120230
+ throw new Error("\u65E5\u671F\u987B\u4E3A YYYY-MM-DD");
120231
+ }
120232
+ return `${base2}/campaignmanagement/accounts/${account}/pmax-search-terms?campaignId=${id}&startDate=${start}&endDate=${end}`;
120233
+ }
120234
+ function field3(item, ...keys) {
120235
+ for (const key of keys) {
120236
+ const value = item[key];
120237
+ if (value != null && String(value).trim() !== "") return String(value);
120238
+ }
120239
+ return "";
120240
+ }
120241
+ function fail(err, label2) {
120242
+ console.error(`
120243
+ \u274C ${label2}\uFF1A${err instanceof Error ? err.message : String(err)}
120244
+ `);
120245
+ process.exit(1);
120246
+ }
120247
+ function accountBase(opts) {
120248
+ const resolved = withResolvedAdAccount(opts);
120249
+ const config = loadConfig(resolved.token);
120250
+ return { config, base: requireGoogleApi(config), account: resolved.account };
120251
+ }
120252
+ async function runAdPmaxSearchTerms(opts) {
120253
+ let url;
120254
+ let range;
120255
+ try {
120256
+ range = hyphenRange(opts.start, opts.end, "PMax \u641C\u7D22\u8BCD");
120257
+ const { base: base2, account: account2 } = accountBase(opts);
120258
+ url = pmaxSearchTermsUrl(base2, account2, opts.campaignId ?? "", range.start, range.end);
120259
+ } catch (err) {
120260
+ fail(err, "\u53C2\u6570");
120261
+ }
120262
+ const { config, account } = accountBase(opts);
120263
+ let items3;
120264
+ try {
120265
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
120266
+ } catch (err) {
120267
+ fail(err, "\u67E5\u8BE2 PMax \u641C\u7D22\u8BCD\u5931\u8D25");
120268
+ }
120269
+ const payload = { account, campaignId: opts.campaignId, ...range, count: items3.length, items: items3 };
120270
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-search-terms", commandLabel: "ad pmax-search-terms", payload })) return;
120271
+ console.log(`
120272
+ PMax \u641C\u7D22\u8BCD ${range.start} ~ ${range.end}\uFF08\u7CFB\u5217 ${opts.campaignId}\uFF0C${items3.length} \u6761\uFF09`);
120273
+ console.log("\u8FD9\u662F PMax \u7684\u641C\u7D22\u67E5\u8BE2\u3002\u8FD9\u5F20\u8868\u6CA1\u6709\u82B1\u8D39\uFF0C\u6309\u5C55\u793A\u770B\u70ED\u5EA6\u3002\u641C\u7D22\u5E7F\u544A\u4ECD\u7528 ad search-terms\u3002\n");
120274
+ printCliTable(
120275
+ items3.map((item) => ({
120276
+ term: field3(item, "searchTerm", "SearchTerm"),
120277
+ category: field3(item, "categoryLabel", "CategoryLabel"),
120278
+ impressions: field3(item, "impressions", "Impressions") || "0",
120279
+ clicks: field3(item, "clicks", "Clicks") || "0"
120280
+ })),
120281
+ [
120282
+ { key: "term", header: "\u641C\u7D22\u8BCD" },
120283
+ { key: "category", header: "\u7C7B\u522B" },
120284
+ { key: "impressions", header: "\u5C55\u793A" },
120285
+ { key: "clicks", header: "\u70B9\u51FB" }
120286
+ ]
120287
+ );
120288
+ console.log();
120289
+ }
120290
+ async function runAdPmaxBrandsSearch(opts) {
120291
+ const prefix = (opts.prefix ?? "").trim();
120292
+ if (!prefix) fail(new Error("prefix \u4E0D\u80FD\u4E3A\u7A7A"), "\u53C2\u6570");
120293
+ const { config, base: base2, account } = accountBase(opts);
120294
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands/suggestions?prefix=${encodeURIComponent(prefix)}`;
120295
+ let items3;
120296
+ try {
120297
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
120298
+ } catch (err) {
120299
+ fail(err, "\u67E5\u8BE2\u54C1\u724C\u5EFA\u8BAE\u5931\u8D25");
120300
+ }
120301
+ const payload = { account, prefix, count: items3.length, items: items3 };
120302
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-brands-search", commandLabel: "ad pmax-brands search", payload })) return;
120303
+ console.log(`
120304
+ \u54C1\u724C\u5EFA\u8BAE\u300C${prefix}\u300D\uFF08${items3.length} \u6761\uFF09\u3002add \u65F6\u7528 id\uFF0C\u4E0D\u8981\u7528 name\u3002
120305
+ `);
120306
+ printCliTable(
120307
+ items3.map((item) => ({
120308
+ id: field3(item, "id", "Id"),
120309
+ name: field3(item, "name", "Name")
120310
+ })),
120311
+ [
120312
+ { key: "id", header: "id" },
120313
+ { key: "name", header: "\u540D\u79F0" }
120314
+ ]
120315
+ );
120316
+ console.log();
120317
+ }
120318
+ async function runAdPmaxBrandsList(opts) {
120319
+ const { config, base: base2, account } = accountBase(opts);
120320
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands`;
120321
+ let body;
120322
+ try {
120323
+ const raw = await apiFetch2(url, config, {}, opts.verbose);
120324
+ body = raw && typeof raw === "object" ? raw : {};
120325
+ } catch (err) {
120326
+ fail(err, "\u67E5\u8BE2\u54C1\u724C\u5217\u8868\u5931\u8D25");
120327
+ }
120328
+ const lists = unwrapItems(body["lists"] ?? body["Lists"] ?? []);
120329
+ const attachments = unwrapItems(body["attachments"] ?? body["Attachments"] ?? []);
120330
+ const payload = { account, lists, attachments };
120331
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-brands", commandLabel: "ad pmax-brands list", payload })) return;
120332
+ console.log(`
120333
+ \u54C1\u724C\u5217\u8868\u6210\u5458 ${lists.length} \u6761\uFF0C\u5DF2\u6302\u7CFB\u5217 ${attachments.length} \u6761
120334
+ `);
120335
+ if (lists.length > 0) {
120336
+ printCliTable(
120337
+ lists.map((item) => ({
120338
+ set: field3(item, "sharedSetName", "SharedSetName"),
120339
+ id: field3(item, "entityId", "EntityId"),
120340
+ name: field3(item, "displayName", "DisplayName")
120341
+ })),
120342
+ [
120343
+ { key: "set", header: "\u5217\u8868" },
120344
+ { key: "id", header: "\u54C1\u724C id" },
120345
+ { key: "name", header: "\u540D\u79F0" }
120346
+ ]
120347
+ );
120348
+ }
120349
+ console.log();
120350
+ }
120351
+ async function runAdPmaxBrandsAdd(opts) {
120352
+ let entityId;
120353
+ try {
120354
+ entityId = assertBrandEntityId(opts.entityId);
120355
+ } catch (err) {
120356
+ fail(err, "\u53C2\u6570");
120357
+ }
120358
+ const { config, base: base2, account } = accountBase(opts);
120359
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands`;
120360
+ try {
120361
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ entityId }) }, opts.verbose);
120362
+ } catch (err) {
120363
+ fail(err, "\u6DFB\u52A0\u54C1\u724C\u5931\u8D25");
120364
+ }
120365
+ console.log(`
120366
+ \u2705 \u5DF2\u628A\u54C1\u724C ${entityId} \u5199\u5165 PMax \u54C1\u724C\u5217\u8868
120367
+ `);
120368
+ }
120369
+ async function runAdPmaxBrandsAttach(opts) {
120370
+ let campaignId;
120371
+ try {
120372
+ campaignId = requireCampaignId(opts.campaignId, "pmax-brands attach");
120373
+ } catch (err) {
120374
+ fail(err, "\u53C2\u6570");
120375
+ }
120376
+ const { config, base: base2, account } = accountBase(opts);
120377
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands/attach`;
120378
+ const body = { campaignId };
120379
+ if (opts.sharedSetId?.trim()) body.sharedSetId = opts.sharedSetId.trim();
120380
+ try {
120381
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
120382
+ } catch (err) {
120383
+ fail(err, "\u6302\u63A5\u54C1\u724C\u5217\u8868\u5931\u8D25");
120384
+ }
120385
+ console.log(`
120386
+ \u2705 \u5DF2\u628A\u54C1\u724C\u5217\u8868\u6302\u5230\u7CFB\u5217 ${campaignId}\u3002\u5378\u4E0B\u7528 detach\uFF0C\u4E0D\u4F1A\u5220\u9664\u5217\u8868\u91CC\u7684\u54C1\u724C\u3002
120387
+ `);
120388
+ }
120389
+ async function runAdPmaxBrandsDetach(opts) {
120390
+ let campaignId;
120391
+ let criterionId;
120392
+ try {
120393
+ campaignId = requireCampaignId(opts.campaignId, "pmax-brands detach");
120394
+ criterionId = requireDigits(opts.criterionId, "--criterion-id");
120395
+ } catch (err) {
120396
+ fail(err, "\u53C2\u6570");
120397
+ }
120398
+ const { config, base: base2, account } = accountBase(opts);
120399
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-brands/detach`;
120400
+ try {
120401
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ campaignId, criterionId }) }, opts.verbose);
120402
+ } catch (err) {
120403
+ fail(err, "\u5378\u4E0B\u54C1\u724C\u5217\u8868\u5931\u8D25");
120404
+ }
120405
+ console.log(`
120406
+ \u2705 \u5DF2\u4ECE\u7CFB\u5217 ${campaignId} \u5378\u4E0B\u54C1\u724C\u5217\u8868 ${criterionId}
120407
+ `);
120408
+ }
120409
+ async function listCampaignRows(opts, path58, label2) {
120410
+ let campaignId;
120411
+ try {
120412
+ campaignId = requireCampaignId(opts.campaignId, label2);
120413
+ } catch (err) {
120414
+ fail(err, "\u53C2\u6570");
120415
+ }
120416
+ const { config, base: base2, account } = accountBase(opts);
120417
+ const url = `${base2}/campaignmanagement/accounts/${account}/${path58}?campaignId=${campaignId}`;
120418
+ let items3;
120419
+ try {
120420
+ items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
120421
+ } catch (err) {
120422
+ fail(err, `\u67E5\u8BE2${label2}\u5931\u8D25`);
120423
+ }
120424
+ return { account, campaignId, items: items3 };
120425
+ }
120426
+ async function runAdPmaxNegativesList(opts) {
120427
+ const listed = await listCampaignRows(opts, "pmax-negatives", "pmax-negatives");
120428
+ if (!listed) return;
120429
+ const payload = { ...listed, count: listed.items.length };
120430
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-negatives", commandLabel: "ad pmax-negatives list", payload })) return;
120431
+ console.log(`
120432
+ PMax \u7CFB\u5217\u5426\u8BCD\uFF08\u7CFB\u5217 ${listed.campaignId}\uFF0C${listed.items.length} \u6761\uFF09`);
120433
+ console.log("\u8FD9\u4E0D\u662F ad negative-list\u3002\u4E0A\u9650\u4EE5 Google \u8FD4\u56DE\u7684\u9519\u8BEF\u4E3A\u51C6\u3002\n");
120434
+ printCliTable(
120435
+ listed.items.map((item) => ({
120436
+ id: field3(item, "criterionId", "CriterionId"),
120437
+ text: field3(item, "text", "Text"),
120438
+ match: field3(item, "matchType", "MatchType")
120439
+ })),
120440
+ [
120441
+ { key: "id", header: "id" },
120442
+ { key: "text", header: "\u8BCD" },
120443
+ { key: "match", header: "\u5339\u914D" }
120444
+ ]
120445
+ );
120446
+ console.log();
120447
+ }
120448
+ async function runAdPmaxNegativesAdd(opts) {
120449
+ let campaignId;
120450
+ let text4;
120451
+ let matchType;
120452
+ try {
120453
+ campaignId = requireCampaignId(opts.campaignId, "pmax-negatives add");
120454
+ text4 = assertKeywordText(opts.text);
120455
+ matchType = opts.matchType?.trim() || "Broad";
120456
+ if (!/^(broad|phrase|exact)$/i.test(matchType)) throw new Error("matchType \u987B\u4E3A Broad\u3001Phrase \u6216 Exact");
120457
+ } catch (err) {
120458
+ fail(err, "\u53C2\u6570");
120459
+ }
120460
+ const { config, base: base2, account } = accountBase(opts);
120461
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-negatives`;
120462
+ try {
120463
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ campaignId, text: text4, matchType }) }, opts.verbose);
120464
+ } catch (err) {
120465
+ fail(err, "\u6DFB\u52A0 PMax \u5426\u8BCD\u5931\u8D25");
120466
+ }
120467
+ console.log(`
120468
+ \u2705 \u5DF2\u4E3A\u7CFB\u5217 ${campaignId} \u6DFB\u52A0\u5426\u8BCD ${text4}
120469
+ `);
120470
+ }
120471
+ async function runAdPmaxNegativesRemove(opts) {
120472
+ await removeCampaignCriterion(opts, "pmax-negatives", "PMax \u5426\u8BCD");
120473
+ }
120474
+ async function runAdPmaxUrlsList(opts) {
120475
+ const listed = await listCampaignRows(opts, "pmax-urls", "pmax-urls");
120476
+ if (!listed) return;
120477
+ const payload = { ...listed, count: listed.items.length };
120478
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-pmax-urls", commandLabel: "ad pmax-urls list", payload })) return;
120479
+ console.log(`
120480
+ PMax \u7F51\u5740\u6392\u9664\uFF08\u7CFB\u5217 ${listed.campaignId}\uFF0C${listed.items.length} \u6761\uFF09`);
120481
+ console.log("\u8FD9\u4E0D\u662F pmax-edit \u7684\u7F51\u5740\u6269\u5C55\u5F00\u5173\u3002\u6B63\u5411\u7F51\u5740\u89C4\u5219\u4ECD\u8981\u5728\u540E\u53F0\u8BBE\u7F6E\u3002\n");
120482
+ printCliTable(
120483
+ listed.items.map((item) => ({
120484
+ id: field3(item, "criterionId", "CriterionId"),
120485
+ op: field3(item, "operator", "Operator"),
120486
+ url: field3(item, "url", "Url")
120487
+ })),
120488
+ [
120489
+ { key: "id", header: "id" },
120490
+ { key: "op", header: "\u6761\u4EF6" },
120491
+ { key: "url", header: "\u7F51\u5740" }
120492
+ ]
120493
+ );
120494
+ console.log();
120495
+ }
120496
+ async function runAdPmaxUrlsAdd(opts) {
120497
+ let campaignId;
120498
+ let operator;
120499
+ const urlValue = (opts.url ?? "").trim();
120500
+ try {
120501
+ campaignId = requireCampaignId(opts.campaignId, "pmax-urls add");
120502
+ operator = assertWebpageOperator(opts.operator);
120503
+ if (!urlValue || urlValue.includes(" ")) throw new Error("\u7F51\u5740\u6392\u9664\u9700\u8981\u4E00\u4E2A URL\uFF0C\u4E0D\u80FD\u542B\u7A7A\u683C");
120504
+ } catch (err) {
120505
+ fail(err, "\u53C2\u6570");
120506
+ }
120507
+ const { config, base: base2, account } = accountBase(opts);
120508
+ const url = `${base2}/campaignmanagement/accounts/${account}/pmax-urls`;
120509
+ try {
120510
+ await apiFetch2(
120511
+ url,
120512
+ config,
120513
+ { method: "POST", body: JSON.stringify({ campaignId, url: urlValue, operator }) },
120514
+ opts.verbose
120515
+ );
120516
+ } catch (err) {
120517
+ fail(err, "\u6DFB\u52A0\u7F51\u5740\u6392\u9664\u5931\u8D25");
120518
+ }
120519
+ console.log(`
120520
+ \u2705 \u5DF2\u4E3A\u7CFB\u5217 ${campaignId} \u6392\u9664\u7F51\u5740 ${urlValue}
120521
+ `);
120522
+ }
120523
+ async function runAdPmaxUrlsRemove(opts) {
120524
+ await removeCampaignCriterion(opts, "pmax-urls", "\u7F51\u5740\u6392\u9664");
120525
+ }
120526
+ async function removeCampaignCriterion(opts, path58, label2) {
120527
+ let campaignId;
120528
+ let criterionId;
120529
+ try {
120530
+ campaignId = requireCampaignId(opts.campaignId, path58);
120531
+ criterionId = requireDigits(opts.criterionId, "--criterion-id");
120532
+ } catch (err) {
120533
+ fail(err, "\u53C2\u6570");
120534
+ }
120535
+ const { config, base: base2, account } = accountBase(opts);
120536
+ const url = `${base2}/campaignmanagement/accounts/${account}/${path58}/${criterionId}?campaignId=${campaignId}`;
120537
+ try {
120538
+ await apiDeleteRaw(url, config, { verbose: opts.verbose });
120539
+ } catch (err) {
120540
+ fail(err, `\u5220\u9664${label2}\u5931\u8D25`);
120541
+ }
120542
+ console.log(`
120543
+ \u2705 \u5DF2\u5220\u9664${label2} ${criterionId}
120544
+ `);
120545
+ }
120546
+
120547
+ // src/commands/ad/account-diagnostics.ts
120548
+ init_auth();
120549
+ init_cli_json_snapshot();
120550
+ init_cli_table();
120551
+ init_shared();
120552
+ function assertIpv4OrCidr(raw) {
120553
+ const value = (raw ?? "").trim();
120554
+ const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?:\/(\d{1,2}))?$/.exec(value);
120555
+ if (!match) throw new Error("IP \u53EA\u63A5\u53D7\u5355\u4E2A IPv4\uFF0C\u6216 IPv4/\u524D\u7F00\u957F\u5EA6");
120556
+ const octets = [match[1], match[2], match[3], match[4]].map((part) => Number(part));
120557
+ if (octets.some((part) => part > 255)) throw new Error("IP \u53EA\u63A5\u53D7\u5355\u4E2A IPv4\uFF0C\u6216 IPv4/\u524D\u7F00\u957F\u5EA6");
120558
+ if (match[5] != null) {
120559
+ const prefix = Number(match[5]);
120560
+ if (prefix > 32) throw new Error("IPv4 \u524D\u7F00\u957F\u5EA6\u987B\u4E3A 0 \u5230 32");
120561
+ }
120562
+ return value;
120563
+ }
120564
+ function field4(item, ...keys) {
120565
+ for (const key of keys) {
120566
+ const value = item[key];
120567
+ if (value != null && String(value).trim() !== "") return String(value);
120568
+ }
120569
+ return "";
120570
+ }
120571
+ function fail2(err, label2) {
120572
+ console.error(`
120573
+ \u274C ${label2}\uFF1A${err instanceof Error ? err.message : String(err)}
120574
+ `);
120575
+ process.exit(1);
120576
+ }
120577
+ function accountBase2(opts) {
120578
+ const resolved = withResolvedAdAccount(opts);
120579
+ const config = loadConfig(resolved.token);
120580
+ return { config, base: requireGoogleApi(config), account: resolved.account };
120581
+ }
120582
+ async function getItems(url, config, verbose) {
120583
+ return unwrapItems(await apiFetch2(url, config, {}, verbose));
120584
+ }
120585
+ async function runAdRsaAssets(opts) {
120586
+ let range;
120587
+ try {
120588
+ range = hyphenRange(opts.start, opts.end, "\u7D20\u6750\u62A5\u8868");
120589
+ } catch (err) {
120590
+ fail2(err, "\u53C2\u6570");
120591
+ }
120592
+ const { config, base: base2, account } = accountBase2(opts);
120593
+ const url = `${base2}/campaignmanagement/accounts/${account}/rsa-assets?startDate=${range.start}&endDate=${range.end}`;
120594
+ let items3;
120595
+ try {
120596
+ items3 = await getItems(url, config, opts.verbose);
120597
+ } catch (err) {
120598
+ fail2(err, "\u67E5\u8BE2\u7D20\u6750\u8868\u73B0\u5931\u8D25");
120599
+ }
120600
+ const payload = { account, ...range, count: items3.length, items: items3 };
120601
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-rsa-assets", commandLabel: "ad rsa-assets", payload })) return;
120602
+ console.log(`
120603
+ \u641C\u7D22\u5E7F\u544A\u7D20\u6750 ${range.start} ~ ${range.end}\uFF08${items3.length} \u6761\uFF09
120604
+ `);
120605
+ printCliTable(
120606
+ items3.map((item) => ({
120607
+ fieldType: field4(item, "fieldType", "FieldType"),
120608
+ label: field4(item, "performanceLabel", "PerformanceLabel"),
120609
+ text: field4(item, "text", "Text"),
120610
+ spend: field4(item, "spend", "Spend")
120611
+ })),
120612
+ [
120613
+ { key: "fieldType", header: "\u5B57\u6BB5" },
120614
+ { key: "label", header: "\u8868\u73B0" },
120615
+ { key: "text", header: "\u6587\u6848" },
120616
+ { key: "spend", header: "\u82B1\u8D39" }
120617
+ ]
120618
+ );
120619
+ console.log();
120620
+ }
120621
+ async function runAdRecommendationSubscriptions(opts) {
120622
+ const { config, base: base2, account } = accountBase2(opts);
120623
+ const url = `${base2}/campaignmanagement/accounts/${account}/recommendation-subscriptions`;
120624
+ let items3;
120625
+ try {
120626
+ items3 = await getItems(url, config, opts.verbose);
120627
+ } catch (err) {
120628
+ fail2(err, "\u67E5\u8BE2\u5EFA\u8BAE\u8BA2\u9605\u5931\u8D25");
120629
+ }
120630
+ const payload = {
120631
+ account,
120632
+ count: items3.length,
120633
+ note: "\u53EA\u8BFB\u3002Enabled \u7684\u9AD8\u98CE\u9669\u9879\u8981\u5230 Google Ads \u540E\u53F0\u5173\u95ED\u3002\u672C\u547D\u4EE4\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3\u3002",
120634
+ items: items3
120635
+ };
120636
+ if (await emitCliJsonOrSnapshot(opts, {
120637
+ section: "ad-recommendation-subscriptions",
120638
+ commandLabel: "ad recommendation-subscriptions",
120639
+ payload
120640
+ })) {
120641
+ return;
120642
+ }
120643
+ console.log(`
120644
+ \u81EA\u52A8\u5E94\u7528\u5EFA\u8BAE\u8BA2\u9605\uFF08${items3.length} \u6761\uFF09`);
120645
+ console.log("\u770B\u5230 Enabled \u65F6\u5230\u540E\u53F0\u5173\u95ED\u3002\u8FD9\u91CC\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3\u3002\n");
120646
+ printCliTable(
120647
+ items3.map((item) => ({
120648
+ type: field4(item, "type", "Type"),
120649
+ status: field4(item, "status", "Status")
120650
+ })),
120651
+ [
120652
+ { key: "type", header: "\u7C7B\u578B" },
120653
+ { key: "status", header: "\u72B6\u6001" }
120654
+ ]
120655
+ );
120656
+ console.log();
120657
+ }
120658
+ async function runAdIpExclusionsList(opts) {
120659
+ const { config, base: base2, account } = accountBase2(opts);
120660
+ const url = `${base2}/campaignmanagement/accounts/${account}/ip-exclusions`;
120661
+ let items3;
120662
+ try {
120663
+ items3 = await getItems(url, config, opts.verbose);
120664
+ } catch (err) {
120665
+ fail2(err, "\u67E5\u8BE2 IP \u6392\u9664\u5931\u8D25");
120666
+ }
120667
+ const payload = { account, count: items3.length, items: items3 };
120668
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-ip-exclusions", commandLabel: "ad ip-exclusions list", payload })) return;
120669
+ console.log(`
120670
+ \u8D26\u6237\u7EA7 IP \u6392\u9664\uFF08${items3.length} \u6761\uFF09\u3002\u8FD9\u4E0D\u662F ad exclusions\uFF0C\u4E5F\u4E0D\u662F\u7CFB\u5217\u7EA7 IP\u3002
120671
+ `);
120672
+ printCliTable(
120673
+ items3.map((item) => ({
120674
+ id: field4(item, "criterionId", "CriterionId"),
120675
+ ip: field4(item, "ipAddress", "IpAddress")
120676
+ })),
120677
+ [
120678
+ { key: "id", header: "id" },
120679
+ { key: "ip", header: "IP" }
120680
+ ]
120681
+ );
120682
+ console.log();
120683
+ }
120684
+ async function runAdIpExclusionsAdd(opts) {
120685
+ let ipAddress;
120686
+ try {
120687
+ ipAddress = assertIpv4OrCidr(opts.ip);
120688
+ } catch (err) {
120689
+ fail2(err, "\u53C2\u6570");
120690
+ }
120691
+ const { config, base: base2, account } = accountBase2(opts);
120692
+ const url = `${base2}/campaignmanagement/accounts/${account}/ip-exclusions`;
120693
+ try {
120694
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify({ ipAddress }) }, opts.verbose);
120695
+ } catch (err) {
120696
+ fail2(err, "\u6DFB\u52A0 IP \u6392\u9664\u5931\u8D25");
120697
+ }
120698
+ console.log(`
120699
+ \u2705 \u5DF2\u6DFB\u52A0\u8D26\u6237\u7EA7 IP \u6392\u9664 ${ipAddress}
120700
+ `);
120701
+ }
120702
+ async function runAdIpExclusionsRemove(opts) {
120703
+ const criterionId = (opts.criterionId ?? "").trim();
120704
+ if (!/^\d+$/.test(criterionId)) fail2(new Error("--criterion-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
120705
+ const { config, base: base2, account } = accountBase2(opts);
120706
+ const url = `${base2}/campaignmanagement/accounts/${account}/ip-exclusions/${criterionId}`;
120707
+ try {
120708
+ await apiDeleteRaw(url, config, { verbose: opts.verbose });
120709
+ } catch (err) {
120710
+ fail2(err, "\u5220\u9664 IP \u6392\u9664\u5931\u8D25");
120711
+ }
120712
+ console.log(`
120713
+ \u2705 \u5DF2\u5220\u9664\u8D26\u6237\u7EA7 IP \u6392\u9664 ${criterionId}
120714
+ `);
120715
+ }
120716
+
119602
120717
  // src/commands/ad/extension.ts
119603
120718
  init_auth();
119604
120719
  import { readFileSync as readFileSync8 } from "fs";
@@ -121603,13 +122718,13 @@ function livePoolHasText(pool, text4) {
121603
122718
  function listPlannedRsaAssets(ad, groupPath, adIndex, adGroupName) {
121604
122719
  const base2 = `${groupPath}.AdsForBatchJob[${adIndex}]`;
121605
122720
  const out = [];
121606
- const push = (kind, field, raw) => {
122721
+ const push = (kind, field5, raw) => {
121607
122722
  if (typeof raw !== "string" || !raw.trim()) return;
121608
122723
  out.push({
121609
- path: `${base2}.${field}`,
122724
+ path: `${base2}.${field5}`,
121610
122725
  adGroupName,
121611
122726
  kind,
121612
- field,
122727
+ field: field5,
121613
122728
  text: raw.trim()
121614
122729
  });
121615
122730
  };
@@ -123348,10 +124463,10 @@ function validateTextLengths(errors, lengthViolations, texts, arrayField, kind,
123348
124463
  texts.forEach((text4, i) => {
123349
124464
  const len = calcGoogleCharLength(text4);
123350
124465
  if (len > limit) {
123351
- const field = `${arrayField}[${i}]`;
124466
+ const field5 = `${arrayField}[${i}]`;
123352
124467
  pushLengthViolation(lengthViolations, {
123353
- path: field,
123354
- field,
124468
+ path: field5,
124469
+ field: field5,
123355
124470
  kind,
123356
124471
  limit,
123357
124472
  actual: len,
@@ -127134,7 +128249,7 @@ function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDat
127134
128249
  // src/commands/ad/demand-gen.ts
127135
128250
  init_shared();
127136
128251
  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";
127137
- function fail(message) {
128252
+ function fail3(message) {
127138
128253
  console.error(`
127139
128254
  \u274C ${message}
127140
128255
  `);
@@ -127154,7 +128269,7 @@ async function emit(opts, section, commandLabel, payload, idSuffix) {
127154
128269
  }
127155
128270
  function printIssues(issues) {
127156
128271
  if (issues.length === 0) return;
127157
- fail(issues.join("\n"));
128272
+ fail3(issues.join("\n"));
127158
128273
  }
127159
128274
  function loadBody(configFile) {
127160
128275
  return stripMetaKeys(loadPmaxJsonFile(configFile));
@@ -127237,7 +128352,7 @@ async function postCreate(opts, path58, commandLabel) {
127237
128352
  body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
127238
128353
  body = prepareCreateBody(body);
127239
128354
  } catch (err) {
127240
- fail(err instanceof Error ? err.message : String(err));
128355
+ fail3(err instanceof Error ? err.message : String(err));
127241
128356
  }
127242
128357
  printIssues(demandGenCreateIssues(body));
127243
128358
  const url = path58 ? `${demandGenCollectionUrl(googleApiUrl, accountId)}/${path58}` : demandGenCollectionUrl(googleApiUrl, accountId);
@@ -127250,7 +128365,7 @@ async function postCreate(opts, path58, commandLabel) {
127250
128365
  opts.verbose
127251
128366
  );
127252
128367
  } catch (err) {
127253
- fail(explainCreateError(err));
128368
+ fail3(explainCreateError(err));
127254
128369
  }
127255
128370
  const payload = decorateDemandGenRead(data);
127256
128371
  if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path58 || "create"}`, commandLabel, payload, accountId)) {
@@ -127270,7 +128385,7 @@ async function runDemandGenList(opts) {
127270
128385
  try {
127271
128386
  data = await pmaxApiFetch(demandGenCollectionUrl(googleApiUrl, accountId), config, {}, opts.verbose);
127272
128387
  } catch (err) {
127273
- fail(`\u5217\u51FA Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128388
+ fail3(`\u5217\u51FA Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127274
128389
  }
127275
128390
  const payload = {
127276
128391
  items: decorateDemandGenRead(data),
@@ -127307,7 +128422,7 @@ async function runDemandGenGet(opts) {
127307
128422
  opts.verbose
127308
128423
  );
127309
128424
  } catch (err) {
127310
- fail(`\u8BFB\u53D6 Demand Gen \u8BE6\u60C5\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128425
+ fail3(`\u8BFB\u53D6 Demand Gen \u8BE6\u60C5\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127311
128426
  }
127312
128427
  const payload = asRecord5(decorateDemandGenRead(data));
127313
128428
  payload["agentHint"] = MONEY_HINT;
@@ -127336,7 +128451,7 @@ async function runDemandGenMinimumBudget(opts) {
127336
128451
  opts.verbose
127337
128452
  );
127338
128453
  } catch (err) {
127339
- fail(`\u8BFB\u53D6\u6700\u4F4E\u65E5\u9884\u7B97\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128454
+ fail3(`\u8BFB\u53D6\u6700\u4F4E\u65E5\u9884\u7B97\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127340
128455
  }
127341
128456
  const payload = decorateDemandGenRead(data);
127342
128457
  if (await emit(
@@ -127368,7 +128483,7 @@ async function runDemandGenConversions(opts) {
127368
128483
  opts.verbose
127369
128484
  );
127370
128485
  } catch (err) {
127371
- fail(`\u8BFB\u53D6\u53EF\u51FA\u4EF7\u8F6C\u5316\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128486
+ fail3(`\u8BFB\u53D6\u53EF\u51FA\u4EF7\u8F6C\u5316\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127372
128487
  }
127373
128488
  if (await emit(
127374
128489
  { ...opts, account: accountId },
@@ -127401,7 +128516,7 @@ async function runDemandGenDraft(opts) {
127401
128516
  opts.verbose
127402
128517
  );
127403
128518
  } catch (err) {
127404
- fail(`\u751F\u6210\u8349\u7A3F\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128519
+ fail3(`\u751F\u6210\u8349\u7A3F\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127405
128520
  }
127406
128521
  const payload = decorateDemandGenRead(data);
127407
128522
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-draft", "ad demand-gen draft", payload, accountId)) {
@@ -127426,7 +128541,7 @@ async function runDemandGenConfirm(opts) {
127426
128541
  }
127427
128542
  function readFlagNumber(value, label2) {
127428
128543
  const amount = typeof value === "number" ? value : Number(String(value).trim());
127429
- if (!Number.isFinite(amount)) fail(`${label2}\u987B\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${String(value)}`);
128544
+ if (!Number.isFinite(amount)) fail3(`${label2}\u987B\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${String(value)}`);
127430
128545
  return amount;
127431
128546
  }
127432
128547
  async function runDemandGenEdit(opts) {
@@ -127443,7 +128558,7 @@ async function runDemandGenEdit(opts) {
127443
128558
  if (opts.name !== void 0) body["name"] = opts.name.trim();
127444
128559
  if (opts.status !== void 0) {
127445
128560
  const status2 = normalizeCampaignStatus(opts.status);
127446
- if (!status2) fail("Campaign status must be Enabled, Paused, or Removed.");
128561
+ if (!status2) fail3("Campaign status must be Enabled, Paused, or Removed.");
127447
128562
  body["statusV2"] = status2;
127448
128563
  }
127449
128564
  if (opts.budget !== void 0) body["budget"] = readFlagNumber(opts.budget, "\u9884\u7B97");
@@ -127458,7 +128573,7 @@ async function runDemandGenEdit(opts) {
127458
128573
  body = normalizeDemandGenMoneyForWrite(body);
127459
128574
  }
127460
128575
  if (Object.keys(body).length === 0) {
127461
- fail("\u8BF7\u6307\u5B9A --patch-file\uFF0C\u6216\u81F3\u5C11\u4E00\u9879\u4FEE\u6539\uFF08--name / --status / --budget / --bidding / \u2026\uFF09");
128576
+ fail3("\u8BF7\u6307\u5B9A --patch-file\uFF0C\u6216\u81F3\u5C11\u4E00\u9879\u4FEE\u6539\uFF08--name / --status / --budget / --bidding / \u2026\uFF09");
127462
128577
  }
127463
128578
  const status = normalizeCampaignStatus(body["statusV2"]);
127464
128579
  if (status) body["statusV2"] = status;
@@ -127476,7 +128591,7 @@ async function runDemandGenEdit(opts) {
127476
128591
  });
127477
128592
  }
127478
128593
  if (body["automatic"] === true) {
127479
- fail("\u4EBA\u5DE5\u64CD\u4F5C\u4E0D\u8981\u5E26 automatic\u3002");
128594
+ fail3("\u4EBA\u5DE5\u64CD\u4F5C\u4E0D\u8981\u5E26 automatic\u3002");
127480
128595
  }
127481
128596
  await withGoogleApi(opts, async (config, googleApiUrl) => {
127482
128597
  try {
@@ -127487,7 +128602,7 @@ async function runDemandGenEdit(opts) {
127487
128602
  opts.verbose
127488
128603
  );
127489
128604
  } catch (err) {
127490
- fail(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128605
+ fail3(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127491
128606
  }
127492
128607
  const payload = { ok: true, campaignId, patch: body };
127493
128608
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-edit", "ad demand-gen edit", payload, campaignId)) {
@@ -127506,20 +128621,20 @@ async function runDemandGenContent(opts) {
127506
128621
  delete body["targetedLocations"];
127507
128622
  delete body["targetedLanguages"];
127508
128623
  }
127509
- if (Object.keys(body).length === 0) fail("content JSON \u6CA1\u6709\u8981\u6539\u7684\u5B57\u6BB5");
128624
+ if (Object.keys(body).length === 0) fail3("content JSON \u6CA1\u6709\u8981\u6539\u7684\u5B57\u6BB5");
127510
128625
  await withGoogleApi(opts, async (config, googleApiUrl) => {
127511
128626
  let next = body;
127512
128627
  try {
127513
128628
  next = await attachImages(opts.configFile, body, accountId, config, googleApiUrl, opts.verbose);
127514
128629
  } catch (err) {
127515
- fail(err instanceof Error ? err.message : String(err));
128630
+ fail3(err instanceof Error ? err.message : String(err));
127516
128631
  }
127517
128632
  delete next["imagePaths"];
127518
128633
  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");
127519
128634
  try {
127520
128635
  await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify(next) }, opts.verbose);
127521
128636
  } catch (err) {
127522
- fail(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128637
+ fail3(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127523
128638
  }
127524
128639
  const payload = { ok: true, campaignId: opts.campaignId, adGroupId: opts.adGroupId, adId: opts.adId ?? null };
127525
128640
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-content", "ad demand-gen content", payload)) return;
@@ -127531,7 +128646,7 @@ async function runDemandGenChannels(opts) {
127531
128646
  const hasStrategy = Boolean(opts.strategy?.trim());
127532
128647
  const hasSelected = Boolean(opts.selected?.trim());
127533
128648
  if (hasStrategy === hasSelected) {
127534
- fail("channelStrategy \u548C selectedChannels \u4E8C\u9009\u4E00\uFF1A\u53EA\u4F20 --strategy\uFF0C\u6216\u53EA\u4F20 --selected\u3002");
128649
+ fail3("channelStrategy \u548C selectedChannels \u4E8C\u9009\u4E00\uFF1A\u53EA\u4F20 --strategy\uFF0C\u6216\u53EA\u4F20 --selected\u3002");
127535
128650
  }
127536
128651
  const body = {};
127537
128652
  if (hasStrategy) body["channelStrategy"] = opts.strategy.trim();
@@ -127539,7 +128654,7 @@ async function runDemandGenChannels(opts) {
127539
128654
  try {
127540
128655
  body["selectedChannels"] = buildSelectedChannels(opts.selected.split(","));
127541
128656
  } catch (err) {
127542
- fail(err instanceof Error ? err.message : String(err));
128657
+ fail3(err instanceof Error ? err.message : String(err));
127543
128658
  }
127544
128659
  }
127545
128660
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -127553,7 +128668,7 @@ async function runDemandGenChannels(opts) {
127553
128668
  try {
127554
128669
  await pmaxApiFetch(url, config, { method: "PATCH", body: JSON.stringify(body) }, opts.verbose);
127555
128670
  } catch (err) {
127556
- fail(`\u66F4\u65B0\u7248\u4F4D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128671
+ fail3(`\u66F4\u65B0\u7248\u4F4D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127557
128672
  }
127558
128673
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-channels", "ad demand-gen channels", { ok: true, patch: body })) {
127559
128674
  return;
@@ -127564,7 +128679,7 @@ async function runDemandGenChannels(opts) {
127564
128679
  async function putStatus(opts, kind) {
127565
128680
  const status = normalizeAdStatus(opts.status);
127566
128681
  if (!status) {
127567
- fail("\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");
128682
+ fail3("\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");
127568
128683
  }
127569
128684
  const accountId = requireAccountId(opts.account);
127570
128685
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -127590,7 +128705,7 @@ async function putStatus(opts, kind) {
127590
128705
  opts.verbose
127591
128706
  );
127592
128707
  } catch (err) {
127593
- fail(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128708
+ fail3(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127594
128709
  }
127595
128710
  console.log(`
127596
128711
  \u2705 \u5DF2\u8BBE\u4E3A ${status}\u3002\u7CFB\u5217\u72B6\u6001\u4E0D\u4F1A\u8DDF\u7740\u53D8\u3002
@@ -127605,7 +128720,7 @@ async function runDemandGenAdStatus(opts) {
127605
128720
  }
127606
128721
  async function runDemandGenAdGroupRename(opts) {
127607
128722
  const name2 = opts.name.trim();
127608
- if (!name2 || name2.length > 255) fail("\u5E7F\u544A\u7EC4\u540D\u987B\u4E3A 1\uFF5E255 \u4E2A\u5B57\u7B26\u3002");
128723
+ if (!name2 || name2.length > 255) fail3("\u5E7F\u544A\u7EC4\u540D\u987B\u4E3A 1\uFF5E255 \u4E2A\u5B57\u7B26\u3002");
127609
128724
  const accountId = requireAccountId(opts.account);
127610
128725
  await withGoogleApi(opts, async (config, googleApiUrl) => {
127611
128726
  const url = demandGenAdGroupUrl(
@@ -127618,7 +128733,7 @@ async function runDemandGenAdGroupRename(opts) {
127618
128733
  try {
127619
128734
  await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify({ name: name2 }) }, opts.verbose);
127620
128735
  } catch (err) {
127621
- fail(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128736
+ fail3(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127622
128737
  }
127623
128738
  console.log(`
127624
128739
  \u2705 \u5E7F\u544A\u7EC4\u5DF2\u6539\u540D\u4E3A ${name2}
@@ -127628,7 +128743,7 @@ async function runDemandGenAdGroupRename(opts) {
127628
128743
  async function runDemandGenAudience(opts) {
127629
128744
  const audienceResourceName = opts.resourceName.trim();
127630
128745
  if (!audienceResourceName.includes("/audiences/")) {
127631
- fail("Audience resource name must be customers/{id}/audiences/{audienceId}.");
128746
+ fail3("Audience resource name must be customers/{id}/audiences/{audienceId}.");
127632
128747
  }
127633
128748
  const accountId = requireAccountId(opts.account);
127634
128749
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -127647,7 +128762,7 @@ async function runDemandGenAudience(opts) {
127647
128762
  opts.verbose
127648
128763
  );
127649
128764
  } catch (err) {
127650
- fail(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128765
+ fail3(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127651
128766
  }
127652
128767
  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");
127653
128768
  });
@@ -127655,7 +128770,7 @@ async function runDemandGenAudience(opts) {
127655
128770
  async function runDemandGenAudienceKeywords(opts) {
127656
128771
  const audienceKeywords = opts.keywords.split(",").map((item) => item.trim()).filter(Boolean);
127657
128772
  if (audienceKeywords.length < 1 || audienceKeywords.length > 10) {
127658
- fail("Audience keyword count must be between 1 and 10.");
128773
+ fail3("Audience keyword count must be between 1 and 10.");
127659
128774
  }
127660
128775
  const accountId = requireAccountId(opts.account);
127661
128776
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -127674,7 +128789,7 @@ async function runDemandGenAudienceKeywords(opts) {
127674
128789
  opts.verbose
127675
128790
  );
127676
128791
  } catch (err) {
127677
- fail(`\u66FF\u6362\u53D7\u4F17\u8BCD\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128792
+ fail3(`\u66FF\u6362\u53D7\u4F17\u8BCD\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127678
128793
  }
127679
128794
  console.log("\n\u2705 \u641C\u7D22\u81EA\u5B9A\u4E49\u53D7\u4F17\u7684\u8BCD\u5DF2\u6574\u4EFD\u66FF\u6362\n");
127680
128795
  });
@@ -127687,7 +128802,7 @@ async function postChild(opts, kind) {
127687
128802
  try {
127688
128803
  body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
127689
128804
  } catch (err) {
127690
- fail(err instanceof Error ? err.message : String(err));
128805
+ fail3(err instanceof Error ? err.message : String(err));
127691
128806
  }
127692
128807
  delete body["account"];
127693
128808
  delete body["imagePaths"];
@@ -127696,7 +128811,7 @@ async function postChild(opts, kind) {
127696
128811
  try {
127697
128812
  data = await pmaxApiFetch(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
127698
128813
  } catch (err) {
127699
- fail(err instanceof Error ? err.message : String(err));
128814
+ fail3(err instanceof Error ? err.message : String(err));
127700
128815
  }
127701
128816
  if (await emit({ ...opts, account: accountId }, `ad-demand-gen-add-${kind}`, `ad demand-gen add-${kind}`, data)) {
127702
128817
  return;
@@ -127731,7 +128846,7 @@ async function runDemandGenDeleteAd(opts) {
127731
128846
  try {
127732
128847
  await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
127733
128848
  } catch (err) {
127734
- fail(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128849
+ fail3(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127735
128850
  }
127736
128851
  console.log("\n\u2705 \u5E7F\u544A\u5DF2\u5220\u9664\n");
127737
128852
  });
@@ -127752,7 +128867,7 @@ async function runDemandGenDeleteAdGroup(opts) {
127752
128867
  try {
127753
128868
  await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
127754
128869
  } catch (err) {
127755
- fail(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128870
+ fail3(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127756
128871
  }
127757
128872
  console.log("\n\u2705 \u5E7F\u544A\u7EC4\u5DF2\u5220\u9664\n");
127758
128873
  });
@@ -127771,7 +128886,7 @@ async function runDemandGenReport(opts) {
127771
128886
  opts.verbose
127772
128887
  );
127773
128888
  } catch (err) {
127774
- fail(`\u8BFB\u53D6\u7248\u4F4D\u62A5\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128889
+ fail3(`\u8BFB\u53D6\u7248\u4F4D\u62A5\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127775
128890
  }
127776
128891
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-report", "ad demand-gen report", data, opts.campaignId)) {
127777
128892
  return;
@@ -127795,7 +128910,7 @@ async function runDemandGenConversionsValidate(opts) {
127795
128910
  opts.verbose
127796
128911
  );
127797
128912
  } catch (err) {
127798
- fail(`\u79BB\u7EBF\u8F6C\u5316\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128913
+ fail3(`\u79BB\u7EBF\u8F6C\u5316\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
127799
128914
  }
127800
128915
  if (await emit(
127801
128916
  { ...opts, account: accountId },
@@ -129047,7 +130162,7 @@ function register21(program2) {
129047
130162
  verbose: opts.verbose
129048
130163
  });
129049
130164
  });
129050
- adCmd.command("search-terms").description("\u67E5\u8BE2\u641C\u7D22\u5B57\u8BCD\u62A5\u544A\uFF08\u65E5\u671F\u9ED8\u8BA4\u8FD1 30 \u5929\uFF09").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4 30 \u5929\u524D\uFF09").option("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4\u4ECA\u5929\uFF09").option("-t, --token <token>", "Auth Token").option(
130165
+ adCmd.command("search-terms").description("\u67E5\u8BE2\u641C\u7D22\u5B57\u8BCD\u62A5\u544A\uFF08\u65E5\u671F\u9ED8\u8BA4\u8FD1 30 \u5929\uFF09\u3002PMax \u641C\u7D22\u8BCD\u7528 ad pmax-search-terms").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "\u5F00\u59CB\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4 30 \u5929\u524D\uFF09").option("--end <date>", "\u7ED3\u675F\u65E5\u671F YYYY-MM-DD\uFF08\u9ED8\u8BA4\u4ECA\u5929\uFF09").option("-t, --token <token>", "Auth Token").option(
129051
130166
  "--json-out <path>",
129052
130167
  "\u843D\u76D8\uFF08\u76EE\u5F55\u6216 *.json \u6587\u4EF6\u8DEF\u5F84\uFF09\u5E76\u66F4\u65B0 cli-manifest[-<\u67E5\u8BE2id>].json\uFF1B\u76EE\u5F55\u6A21\u5F0F\u6587\u4EF6\u540D\u4E3A `<section>[-<\u67E5\u8BE2id>].json`\uFF1Bstdout \u4E00\u884C\u6458\u8981 JSON\uFF0C\u542B outlineFile\uFF08TS \u5F0F\u7C7B\u578B\u5728 `*.outline.txt`\uFF09",
129053
130168
  void 0
@@ -129239,6 +130354,146 @@ function register21(program2) {
129239
130354
  }
129240
130355
  );
129241
130356
  registerDemandGen(adCmd);
130357
+ registerAccountOps(adCmd);
130358
+ registerProtection(adCmd);
130359
+ }
130360
+ function registerAccountOps(adCmd) {
130361
+ const exclusions = adCmd.command("exclusions").description(
130362
+ "\u8D26\u6237\u7EA7\u5185\u5BB9\u9002\u5B9C\u6027\u6392\u9664\uFF08\u654F\u611F\u5185\u5BB9\u3001\u7C7B\u578B\u548C\u6807\u7B7E\u3001\u5185\u5BB9\u4E3B\u9898\u3001\u7F51\u7AD9\u3001YouTube\u3001\u5E94\u7528\u3001\u5E94\u7528\u7C7B\u522B\uFF09\u3002\u5168\u8D26\u6237\u751F\u6548\u3002\u4E0D\u662F\u5C55\u793A\u5E7F\u544A\u521B\u5EFA\uFF0C\u4E5F\u4E0D\u662F\u641C\u7D22\u5426\u8BCD\u6216\u5185\u5BB9\u5173\u952E\u5B57"
130363
+ );
130364
+ exclusions.command("list").description("\u5217\u51FA\u5DF2\u751F\u6548\u7684\u8D26\u6237\u7EA7\u5185\u5BB9\u6392\u9664").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--type <type>", "content-label | placement | youtube-channel | youtube-video | app | app-category").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130365
+ await runAdExclusionsList(opts);
130366
+ });
130367
+ exclusions.command("add").description("\u6DFB\u52A0\u4E00\u6761\u8D26\u6237\u7EA7\u6392\u9664\u3002\u4E00\u6B21\u4E00\u79CD\u7C7B\u578B\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list\uFF0C\u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--type <type>", "content-label | placement | youtube-channel | youtube-video | app | app-category").option("--content-label <name>", "\u5185\u5BB9\u6807\u7B7E proto \u540D\uFF0C\u6765\u81EA content-labels\uFF0C\u5982 BRAND_SUITABILITY_GAMES_FIGHTING").option("--url <url>", "\u8981\u6392\u9664\u7684\u7F51\u7AD9").option("--channel-id <id>", "YouTube \u9891\u9053 ID").option("--video-id <id>", "YouTube \u89C6\u9891 ID").option("--app-id <id>", "\u5E94\u7528 ID\uFF1A1-\u6570\u5B57 \u6216 2-\u5305\u540D").option("--app-category-id <id>", "\u5E94\u7528\u7C7B\u522B\u6570\u5B57 id\uFF0C\u6765\u81EA app-categories").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130368
+ await runAdExclusionsAdd({
130369
+ token: opts.token,
130370
+ account: opts.account,
130371
+ type: opts.type ?? "",
130372
+ contentLabel: opts.contentLabel,
130373
+ url: opts.url,
130374
+ channelId: opts.channelId,
130375
+ videoId: opts.videoId,
130376
+ appId: opts.appId,
130377
+ appCategoryId: opts.appCategoryId,
130378
+ jsonOut: opts.jsonOut,
130379
+ verbose: opts.verbose
130380
+ });
130381
+ });
130382
+ exclusions.command("remove").description("\u6309 list \u8FD4\u56DE\u7684 criterionId \u5220\u9664\u4E00\u6761\u8D26\u6237\u7EA7\u6392\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--criterion-id <id>", "exclusions list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130383
+ await runAdExclusionsRemove({
130384
+ token: opts.token,
130385
+ account: opts.account,
130386
+ criterionId: opts.criterionId ?? "",
130387
+ verbose: opts.verbose
130388
+ });
130389
+ });
130390
+ exclusions.command("content-labels").description("\u5185\u5BB9\u6807\u7B7E\u76EE\u5F55\u3002\u6E38\u620F\uFF08\u683C\u6597\uFF09\u662F BRAND_SUITABILITY_GAMES_FIGHTING\uFF0C\u4E0D\u662F Topic").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130391
+ await runAdExclusionContentLabels(opts);
130392
+ });
130393
+ exclusions.command("app-categories").description("\u5E94\u7528\u7C7B\u522B\u5E38\u91CF\u3002\u6761\u6570\u4EE5\u67E5\u8BE2\u4E3A\u51C6\u3002\u6392\u9664\u524D\u5148\u62FF id").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) => {
130394
+ await runAdExclusionAppCategories(opts);
130395
+ });
130396
+ adCmd.command("placements").description("\u7248\u4F4D\u82B1\u8D39\uFF08\u7F51\u7AD9 / \u5E94\u7528 / \u9891\u9053\uFF09\u3002\u6392\u9664\u7248\u4F4D\u524D\u5148\u770B\u8FD9\u5F20\u8868\u3002\u4E0D\u662F ad demand-gen report").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) => {
130397
+ await runAdPlacements(opts);
130398
+ });
130399
+ adCmd.command("conversion-goals").description("\u7CFB\u5217\u5B9E\u9645\u8BA1\u5165\u51FA\u4EF7\u7684\u8F6C\u5316\u76EE\u6807\u3002\u53EA\u8BFB\u3002CPA \u5F02\u5E38\u65F6\u5148\u770B\u8FD9\u91CC").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").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) => {
130400
+ await runAdConversionGoals(opts);
130401
+ });
130402
+ adCmd.command("changes").description("\u64CD\u4F5C\u8BB0\u5F55\u3002\u53EA\u8BFB\uFF0C\u533A\u95F4\u6700\u591A 30 \u5929\u3002\u7A7A\u5217\u8868\u8868\u793A\u6CA1\u6709\u8BB0\u5F55").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--start <date>", "YYYY-MM-DD").requiredOption("--end <date>", "YYYY-MM-DD").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130403
+ await runAdChanges({
130404
+ token: opts.token,
130405
+ account: opts.account,
130406
+ start: opts.start ?? "",
130407
+ end: opts.end ?? "",
130408
+ jsonOut: opts.jsonOut,
130409
+ verbose: opts.verbose
130410
+ });
130411
+ });
130412
+ const negativeList = adCmd.command("negative-list").description(
130413
+ "\u8D26\u6237\u7EA7\u641C\u7D22\u5426\u8BCD\u5171\u4EAB\u5217\u8868\uFF08\u6BCF\u6237\u4E00\u4E2A\uFF09\u3002\u6321\u641C\u7D22\u67E5\u8BE2\uFF0C\u4E0D\u7BA1 YouTube / \u5C55\u793A\u5185\u5BB9\u3002\u5185\u5BB9\u5173\u952E\u5B57\u6CA1\u6709\u516C\u5F00\u63A5\u53E3"
130414
+ );
130415
+ negativeList.command("list").description("\u5217\u51FA\u5DF2\u6302\u63A5\u7684\u8D26\u6237\u7EA7\u641C\u7D22\u5426\u8BCD").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) => {
130416
+ await runAdNegativeList(opts);
130417
+ });
130418
+ negativeList.command("add").description("\u5F80\u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u52A0\u8BCD\u3002\u672A\u6302\u63A5\u65F6\u540E\u7AEF\u4F1A\u5148\u6302\u63A5\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--keywords <kw1,kw2>", "\u9017\u53F7\u5206\u9694", (v) => parseKeywordsCsv(v)).option("--keywords-file <path>", "\u8BCD\u6587\u4EF6").option("--match-type <type>", "Broad | Phrase | Exact").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130419
+ await runAdNegativeListAdd({
130420
+ token: opts.token,
130421
+ account: opts.account,
130422
+ keywords: opts.keywords,
130423
+ keywordsFile: opts.keywordsFile,
130424
+ matchType: parseOptionalMatchType(opts.matchType),
130425
+ jsonOut: opts.jsonOut,
130426
+ verbose: opts.verbose
130427
+ });
130428
+ });
130429
+ negativeList.command("remove").description("\u6309 list \u7684 id \u5220\u9664\u4E00\u6761\u8D26\u6237\u7EA7\u5426\u8BCD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--id <id>", "\u5426\u8BCD id").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130430
+ await runAdNegativeListRemove({
130431
+ token: opts.token,
130432
+ account: opts.account,
130433
+ id: opts.id ?? "",
130434
+ verbose: opts.verbose
130435
+ });
130436
+ });
130437
+ negativeList.command("attach").description("\u786E\u4FDD\u8D26\u6237\u7EA7\u5426\u8BCD\u5217\u8868\u5DF2\u6302\u63A5\u3002\u4E0D\u52A0\u8BCD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130438
+ await runAdNegativeListAttach(opts);
130439
+ });
130440
+ }
130441
+ function registerProtection(adCmd) {
130442
+ adCmd.command("pmax-search-terms").description("PMax \u641C\u7D22\u8BCD\u3002\u5FC5\u987B\u6307\u5B9A\u4E00\u4E2A\u7CFB\u5217\u3002\u4E0D\u662F ad search-terms").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").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) => {
130443
+ await runAdPmaxSearchTerms(opts);
130444
+ });
130445
+ const brands = adCmd.command("pmax-brands").description("PMax \u54C1\u724C\u6392\u9664\u3002id \u53EA\u80FD\u6765\u81EA search\u3002\u6302\u63A5\u53EA\u4F5C\u7528\u4E8E PMax \u7CFB\u5217");
130446
+ brands.command("search").description("\u6309\u524D\u7F00\u67E5\u54C1\u724C\u5EFA\u8BAE").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--prefix <text>", "\u54C1\u724C\u540D\u524D\u7F00").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130447
+ await runAdPmaxBrandsSearch(opts);
130448
+ });
130449
+ brands.command("list").description("\u5DF2\u6709\u54C1\u724C\u548C\u5DF2\u6302\u4E0A\u7684\u7CFB\u5217").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) => {
130450
+ await runAdPmaxBrandsList(opts);
130451
+ });
130452
+ brands.command("add").description("\u628A search \u8FD4\u56DE\u7684\u54C1\u724C id \u5199\u5165\u5217\u8868\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--entity-id <id>", "pmax-brands search \u7684 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) => {
130453
+ await runAdPmaxBrandsAdd(opts);
130454
+ });
130455
+ brands.command("attach").description("\u628A\u54C1\u724C\u5217\u8868\u6302\u5230\u4E00\u4E2A PMax \u7CFB\u5217\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list \u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").option("--shared-set-id <id>", "\u54C1\u724C\u5217\u8868 id\uFF0C\u4E0D\u4F20\u5219\u7528\u8D26\u6237\u91CC\u5DF2\u6709\u7684\u90A3\u4EFD").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130456
+ await runAdPmaxBrandsAttach(opts);
130457
+ });
130458
+ brands.command("detach").description("\u4ECE\u7CFB\u5217\u5378\u4E0B\u54C1\u724C\u5217\u8868\u3002\u4E0D\u5220\u9664\u5217\u8868\u91CC\u7684\u54C1\u724C\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--criterion-id <id>", "list \u91CC\u5DF2\u6302\u7CFB\u5217\u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130459
+ await runAdPmaxBrandsDetach(opts);
130460
+ });
130461
+ const negatives = adCmd.command("pmax-negatives").description("PMax \u7CFB\u5217\u5426\u8BCD\u3002\u4E0D\u662F ad negative-list\u3002\u53EA\u63A5\u53D7 PMax \u7CFB\u5217");
130462
+ negatives.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 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) => {
130463
+ await runAdPmaxNegativesList(opts);
130464
+ });
130465
+ negatives.command("add").description("\u52A0\u4E00\u6761\u7CFB\u5217\u5426\u8BCD\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--text <keyword>", "\u4E00\u4E2A\u8BCD").option("--match-type <type>", "Broad | Phrase | Exact\uFF0C\u9ED8\u8BA4 Broad").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130466
+ await runAdPmaxNegativesAdd(opts);
130467
+ });
130468
+ negatives.command("remove").description("\u6309 list \u7684 criterionId \u5220\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--criterion-id <id>", "list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130469
+ await runAdPmaxNegativesRemove(opts);
130470
+ });
130471
+ const urls = adCmd.command("pmax-urls").description("PMax \u7F51\u5740\u6392\u9664\u3002\u4E0D\u662F pmax-edit \u7684\u7F51\u5740\u6269\u5C55\u5F00\u5173");
130472
+ urls.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 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) => {
130473
+ await runAdPmaxUrlsList(opts);
130474
+ });
130475
+ urls.command("add").description("\u6392\u9664\u4E00\u4E2A URL\u3002EQUALS \u6216 CONTAINS\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--url <url>", "\u8981\u6392\u9664\u7684\u7F51\u5740").requiredOption("--operator <op>", "EQUALS | CONTAINS").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130476
+ await runAdPmaxUrlsAdd(opts);
130477
+ });
130478
+ urls.command("remove").description("\u6309 criterionId \u5220\u9664\u4E00\u6761\u7F51\u5740\u6392\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "PMax \u7CFB\u5217 id").requiredOption("--criterion-id <id>", "list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130479
+ await runAdPmaxUrlsRemove(opts);
130480
+ });
130481
+ 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) => {
130482
+ await runAdRsaAssets(opts);
130483
+ });
130484
+ 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) => {
130485
+ await runAdRecommendationSubscriptions(opts);
130486
+ });
130487
+ const ips = adCmd.command("ip-exclusions").description("\u8D26\u6237\u7EA7 IP \u6392\u9664\u3002\u4E0D\u662F\u5185\u5BB9\u6392\u9664\uFF0C\u4E5F\u4E0D\u662F\u7CFB\u5217\u7EA7 IP\u3002\u5168\u8D26\u6237\u751F\u6548");
130488
+ ips.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) => {
130489
+ await runAdIpExclusionsList(opts);
130490
+ });
130491
+ ips.command("add").description("\u6DFB\u52A0\u4E00\u4E2A IPv4 \u6216 IPv4 CIDR\u3002\u5199\u64CD\u4F5C\u987B --commit\u3002\u5148 list \u5E76\u5411\u7528\u6237\u786E\u8BA4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--ip <address>", "\u4F8B\u5982 203.0.113.10 \u6216 203.0.113.0/24").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130492
+ await runAdIpExclusionsAdd(opts);
130493
+ });
130494
+ ips.command("remove").description("\u6309 list \u7684 criterionId \u5220\u9664\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--criterion-id <id>", "list \u7684 criterionId").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130495
+ await runAdIpExclusionsRemove(opts);
130496
+ });
129242
130497
  }
129243
130498
 
129244
130499
  // src/commands/meta-ad/account.ts
@@ -129801,11 +131056,11 @@ function snapshotSupported(targeting) {
129801
131056
  function diffSnapshots(before, after) {
129802
131057
  const fields = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
129803
131058
  const changes = [];
129804
- for (const field of fields) {
129805
- const from = before[field];
129806
- const to = after[field];
131059
+ for (const field5 of fields) {
131060
+ const from = before[field5];
131061
+ const to = after[field5];
129807
131062
  const changed = JSON.stringify(from) !== JSON.stringify(to);
129808
- changes.push({ field, from: from ?? null, to: to ?? null, changed });
131063
+ changes.push({ field: field5, from: from ?? null, to: to ?? null, changed });
129809
131064
  }
129810
131065
  return changes;
129811
131066
  }
@@ -129912,9 +131167,9 @@ function evaluateAdSetEditReadback(sentBody, actual, readFailed) {
129912
131167
  for (const key of ADSET_SCALAR_READBACK_KEYS) {
129913
131168
  if (sentBody[key] === void 0) continue;
129914
131169
  const present = Object.prototype.hasOwnProperty.call(actual, key);
129915
- const money2 = key === "daily_budget" || key === "lifetime_budget" || key === "bid_amount";
129916
- const expected = money2 ? String(sentBody[key]) : sentBody[key];
129917
- const actualValue = money2 && actual[key] != null && actual[key] !== "" ? String(actual[key]) : actual[key];
131170
+ const money3 = key === "daily_budget" || key === "lifetime_budget" || key === "bid_amount";
131171
+ const expected = money3 ? String(sentBody[key]) : sentBody[key];
131172
+ const actualValue = money3 && actual[key] != null && actual[key] !== "" ? String(actual[key]) : actual[key];
129918
131173
  checks.push(fieldCheck(key, expected, actualValue, present));
129919
131174
  }
129920
131175
  if (isPlainObject(sentBody["targeting"])) {
@@ -130461,7 +131716,7 @@ async function runMetaAdCreate(opts) {
130461
131716
  optimizationGoal: cfg.adset.optimizationGoal?.toUpperCase(),
130462
131717
  status: omitActive(cfg.adset.status)
130463
131718
  };
130464
- const money2 = {
131719
+ const money3 = {
130465
131720
  dailyBudgetMinor: cfg.adset.dailyBudget != null ? toMinorUnitString(cfg.adset.dailyBudget, currency) : void 0,
130466
131721
  lifetimeBudgetMinor: cfg.adset.lifetimeBudget != null ? toMinorUnitString(cfg.adset.lifetimeBudget, currency) : void 0
130467
131722
  };
@@ -130474,7 +131729,7 @@ async function runMetaAdCreate(opts) {
130474
131729
  adset: baseAdset,
130475
131730
  campaignId: progress.campaignId,
130476
131731
  pageId,
130477
- ...money2,
131732
+ ...money3,
130478
131733
  bidAmountMinor: cfg.adset.bidAmount != null ? toMinorUnitString(cfg.adset.bidAmount, currency) : void 0
130479
131734
  }),
130480
131735
  opts.verbose
@@ -130520,7 +131775,7 @@ async function runMetaAdCreate(opts) {
130520
131775
  adset: { ...baseAdset, bidStrategy: decision.bidStrategy },
130521
131776
  campaignId: progress.campaignId,
130522
131777
  pageId,
130523
- ...money2,
131778
+ ...money3,
130524
131779
  bidAmountMinor: toMinorUnitString(decision.bidAmount, currency)
130525
131780
  }),
130526
131781
  opts.verbose
@@ -133590,6 +134845,143 @@ Google \u8D26\u6237\u8BBF\u95EE\u6743\u9650\u6821\u9A8C ${mediaCustomerId}`);
133590
134845
  }
133591
134846
  }
133592
134847
 
134848
+ // src/commands/account-manage/google-promotions.ts
134849
+ init_auth();
134850
+ init_cli_json_snapshot();
134851
+ init_media_customer_id();
134852
+ var INCENTIVE_STATE_LABEL = {
134853
+ Redeemed: "\u5DF2\u5151\u6362\uFF0C\u5F85\u5B8C\u6210\u6D88\u8017",
134854
+ Fulfilled: "\u5DF2\u8FBE\u6210\u6761\u4EF6\uFF0C\u8D60\u9001\u91D1\u5C1A\u672A\u5230\u8D26",
134855
+ RewardGranted: "\u8D60\u9001\u91D1\u5DF2\u5230\u8D26",
134856
+ Expired: "\u672A\u5728\u671F\u9650\u5185\u8FBE\u6210\u6761\u4EF6",
134857
+ RewardExpired: "\u8D60\u9001\u91D1\u5DF2\u8FC7\u671F",
134858
+ RewardExhausted: "\u8D60\u9001\u91D1\u5DF2\u7528\u5B8C",
134859
+ Invalidated: "\u5DF2\u4F5C\u5E9F",
134860
+ Unknown: "\u672A\u77E5",
134861
+ Unspecified: "\u672A\u77E5"
134862
+ };
134863
+ function incentiveStateLabel(state) {
134864
+ return INCENTIVE_STATE_LABEL[state] ?? (state || "\u672A\u77E5");
134865
+ }
134866
+ function formatPromotionAmount(value) {
134867
+ if (value == null || !Number.isFinite(value)) return "\u2014";
134868
+ return value.toFixed(6).replace(/\.?0+$/, "");
134869
+ }
134870
+ function buildAppliedIncentivesUrl(googleApiUrl, mediaCustomerId) {
134871
+ const base2 = googleApiUrl.replace(/\/$/, "");
134872
+ return `${base2}/query/media-account/${mediaCustomerId}/applied-incentives`;
134873
+ }
134874
+ function readString(row, ...keys) {
134875
+ for (const key of keys) {
134876
+ const value = row[key];
134877
+ if (typeof value === "string" && value.trim()) return value.trim();
134878
+ }
134879
+ return null;
134880
+ }
134881
+ function readMoney(row, ...keys) {
134882
+ for (const key of keys) {
134883
+ if (!(key in row) || row[key] == null) continue;
134884
+ const value = row[key];
134885
+ if (typeof value === "number" && Number.isFinite(value)) return value;
134886
+ if (typeof value === "string" && value.trim() && Number.isFinite(Number(value))) return Number(value);
134887
+ }
134888
+ return null;
134889
+ }
134890
+ function parseAppliedIncentive(raw) {
134891
+ const row = raw && typeof raw === "object" ? raw : {};
134892
+ return {
134893
+ resourceName: readString(row, "resourceName", "ResourceName") ?? "",
134894
+ couponCode: readString(row, "couponCode", "CouponCode") ?? "",
134895
+ incentiveState: readString(row, "incentiveState", "IncentiveState") ?? "",
134896
+ currencyCode: readString(row, "currencyCode", "CurrencyCode"),
134897
+ redemptionDateTime: readString(row, "redemptionDateTime", "RedemptionDateTime"),
134898
+ fulfillmentExpirationDateTime: readString(
134899
+ row,
134900
+ "fulfillmentExpirationDateTime",
134901
+ "FulfillmentExpirationDateTime"
134902
+ ),
134903
+ rewardGrantDateTime: readString(row, "rewardGrantDateTime", "RewardGrantDateTime"),
134904
+ rewardExpirationDateTime: readString(row, "rewardExpirationDateTime", "RewardExpirationDateTime"),
134905
+ rewardAmount: readMoney(row, "rewardAmount", "RewardAmount"),
134906
+ grantedAmount: readMoney(row, "grantedAmount", "GrantedAmount"),
134907
+ requiredMinSpend: readMoney(row, "requiredMinSpend", "RequiredMinSpend"),
134908
+ currentSpendTowardsFulfillment: readMoney(
134909
+ row,
134910
+ "currentSpendTowardsFulfillment",
134911
+ "CurrentSpendTowardsFulfillment"
134912
+ ),
134913
+ rewardBalanceRemaining: readMoney(row, "rewardBalanceRemaining", "RewardBalanceRemaining")
134914
+ };
134915
+ }
134916
+ function parseAppliedIncentiveList(body) {
134917
+ const list = Array.isArray(body) ? body : body && typeof body === "object" && Array.isArray(body.items) ? body.items : null;
134918
+ if (!list) {
134919
+ throw new Error("\u8D60\u9001\u91D1\u63A5\u53E3\u8FD4\u56DE\u7684\u4E0D\u662F\u5217\u8868");
134920
+ }
134921
+ return list.map(parseAppliedIncentive);
134922
+ }
134923
+ function assertGoogleMediaCustomerId2(raw) {
134924
+ try {
134925
+ return requireNumericMediaCustomerId(raw, "--account");
134926
+ } catch (error) {
134927
+ console.error(`
134928
+ \u274C ${error instanceof Error ? error.message : String(error)}
134929
+ `);
134930
+ process.exit(1);
134931
+ }
134932
+ }
134933
+ function formatAppliedIncentivesText(payload) {
134934
+ if (payload.items.length === 0) {
134935
+ return [
134936
+ `\u8D26\u6237 ${payload.mediaCustomerId} \u6CA1\u6709\u5DF2\u5151\u6362\u7684 Google Ads \u8D60\u9001\u91D1\u3002`,
134937
+ "\u672A\u5151\u6362\u7684\u65B0\u5BA2\u4F18\u60E0\u4E0D\u5728\u8FD9\u4E2A\u63A5\u53E3\u91CC\u3002\u8D26\u6237\u9884\u7B97\u8C03\u6574\u5408\u8BA1\u8FD8\u6DF7\u6709\u65E0\u6548\u70B9\u51FB\u8D54\u4ED8\uFF0C\u4E0D\u80FD\u5F53\u6210\u8D60\u9001\u91D1\u3002"
134938
+ ].join("\n");
134939
+ }
134940
+ const blocks = payload.items.map((item, index) => {
134941
+ const currency = item.currencyCode ? ` ${item.currencyCode}` : "";
134942
+ return [
134943
+ `${index + 1}. \u5238\u7801 ${item.couponCode || "\u2014"} ${incentiveStateLabel(item.incentiveState)}\uFF08${item.incentiveState || "\u2014"}\uFF09`,
134944
+ ` \u6700\u9AD8\u53EF\u5F97${currency} ${formatPromotionAmount(item.rewardAmount)} \u5DF2\u53D1\u653E ${formatPromotionAmount(item.grantedAmount)} \u5269\u4F59 ${formatPromotionAmount(item.rewardBalanceRemaining)}`,
134945
+ ` \u6700\u4F4E\u6D88\u8017 ${formatPromotionAmount(item.requiredMinSpend)} \u5DF2\u8BA1\u5165 ${formatPromotionAmount(item.currentSpendTowardsFulfillment)}`,
134946
+ ` \u5151\u6362 ${item.redemptionDateTime ?? "\u2014"} UTC \u8FBE\u6210\u622A\u6B62 ${item.fulfillmentExpirationDateTime ?? "\u2014"} UTC`,
134947
+ ` \u5230\u8D26 ${item.rewardGrantDateTime ?? "\u2014"} UTC \u8D60\u9001\u8FC7\u671F ${item.rewardExpirationDateTime ?? "\u2014"} UTC`
134948
+ ].join("\n");
134949
+ });
134950
+ return [`Google \u8D60\u9001\u91D1\uFF08\u5DF2\u5151\u6362\uFF09 \u8D26\u6237 ${payload.mediaCustomerId} \u5171 ${payload.count} \u6761`, "", ...blocks].join(
134951
+ "\n"
134952
+ );
134953
+ }
134954
+ async function fetchAppliedIncentives(config, mediaCustomerId, verbose) {
134955
+ await ensureDataPermission(config);
134956
+ const url = buildAppliedIncentivesUrl(googleGatewayBase(config), mediaCustomerId);
134957
+ const body = await apiFetch2(url, config, {}, verbose);
134958
+ const items3 = parseAppliedIncentiveList(body);
134959
+ return { mediaCustomerId, count: items3.length, items: items3 };
134960
+ }
134961
+ async function runAccountPromotions(opts) {
134962
+ const mediaCustomerId = assertGoogleMediaCustomerId2(opts.account);
134963
+ const config = loadConfig(opts.token);
134964
+ let payload;
134965
+ try {
134966
+ payload = await fetchAppliedIncentives(config, mediaCustomerId, opts.verbose);
134967
+ } catch (error) {
134968
+ console.error(`
134969
+ \u274C ${error instanceof Error ? error.message : String(error)}
134970
+ `);
134971
+ process.exit(1);
134972
+ }
134973
+ if (await emitCliJsonOrSnapshot(opts, {
134974
+ section: "account-promotions",
134975
+ commandLabel: "account promotions",
134976
+ payload
134977
+ })) {
134978
+ return;
134979
+ }
134980
+ console.log(`
134981
+ ${formatAppliedIncentivesText(payload)}
134982
+ `);
134983
+ }
134984
+
133593
134985
  // src/commands/account-manage/share.ts
133594
134986
  init_dist();
133595
134987
  init_auth();
@@ -134651,6 +136043,21 @@ function register25(program2) {
134651
136043
  });
134652
136044
  }
134653
136045
  );
136046
+ accountCmd.command("promotions").description(
136047
+ "\u67E5\u8BE2 Google \u5DF2\u5151\u6362\u8D60\u9001\u91D1\uFF08\u91D1\u989D\u3001\u5269\u4F59\u3001\u8FBE\u6210\u622A\u6B62\u3001\u8D60\u9001\u5230\u671F\uFF09\u3002\u4EC5 Google\uFF0C\u672A\u53D1\u653E\u5B57\u6BB5\u4E3A null"
136048
+ ).requiredOption(
136049
+ "-a, --account <mediaCustomerId>",
136050
+ "Google mediaCustomerId\uFF08\u7EAF\u6570\u5B57\uFF0C\u6216\u5E26\u8FDE\u5B57\u7B26\u7684 CID\uFF09"
136051
+ ).option("-t, --token <token>", "Auth Token").option("--json-out <path>", "\u843D\u76D8 JSON\uFF1Bstdout \u4E00\u884C\u6458\u8981").option("--verbose", "\u6253\u5370\u8BE6\u7EC6\u9519\u8BEF", false).action(
136052
+ async (opts) => {
136053
+ await runAccountPromotions({
136054
+ account: opts.account,
136055
+ token: opts.token,
136056
+ jsonOut: opts.jsonOut,
136057
+ verbose: opts.verbose
136058
+ });
136059
+ }
136060
+ );
134654
136061
  accountCmd.command("delink").description(
134655
136062
  "\u89E3\u9664\u6388\u6743\uFF1A\u65AD\u5F00\u5E7F\u544A\u8D26\u6237\u4E0E\u5F53\u524D\u4E1D\u8DEF\u8D5E\u8D26\u53F7\u7684\u5173\u8054\uFF08\u7834\u574F\u6027\uFF1B\u987B\u7528\u6237\u786E\u8BA4\u540E\u52A0 --i-confirm + --commit\uFF09"
134656
136063
  ).option("--id <entityId>", "\u5355\u4E2A\u8D26\u6237 entityId\uFF08\u6765\u81EA list-accounts \u7684 ma.entityId \u5B57\u6BB5\uFF09").option("--ids <entityIds>", "\u6279\u91CF entityId\uFF0C\u9017\u53F7\u5206\u9694\uFF08\u4E0E --id \u4E8C\u9009\u4E00\uFF0C\u53EF\u540C\u65F6\u4F20\uFF09").option("--i-confirm", "\u786E\u8BA4\u5DF2\u5411\u7528\u6237\u8BF4\u660E\u89E3\u7ED1\u98CE\u9669\u5E76\u83B7\u5F97\u660E\u786E\u540C\u610F", false).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
@@ -140726,7 +142133,7 @@ async function fetchSubdivisions(opts) {
140726
142133
  }
140727
142134
  const url = `${base2}/reporting/media-account/${opts.accountId}/reports/geo/subdivisions?${qs}`;
140728
142135
  try {
140729
- const payload = await apiFetch2(url, opts.config, { verbose: opts.verbose });
142136
+ const payload = await apiFetch2(url, opts.config, {}, opts.verbose);
140730
142137
  const rows = Array.isArray(payload) ? payload : payload && typeof payload === "object" && Array.isArray(payload.countries) ? payload.countries : payload && typeof payload === "object" && Array.isArray(payload.items) ? payload.items : [];
140731
142138
  const out = [];
140732
142139
  for (const item of rows) {
@@ -140781,7 +142188,7 @@ async function fetchYoutubeChannel(opts) {
140781
142188
  if (opts.channelId?.trim()) qs.set("ids", `channel==${opts.channelId.trim()}`);
140782
142189
  const url = `${base2}/query/report/YouTube/channel-kpi?${qs}`;
140783
142190
  try {
140784
- const payload = await apiFetch2(url, opts.config, { verbose: opts.verbose });
142191
+ const payload = await apiFetch2(url, opts.config, {}, opts.verbose);
140785
142192
  const headers = Array.isArray(payload.columnHeaders) ? payload.columnHeaders : [];
140786
142193
  const first = Array.isArray(payload.rows) && Array.isArray(payload.rows[0]) ? payload.rows[0] : [];
140787
142194
  return {
@@ -140817,7 +142224,7 @@ function parseIsoDate(iso) {
140817
142224
  function pad(n) {
140818
142225
  return String(n).padStart(2, "0");
140819
142226
  }
140820
- function isoDate(y, m, d) {
142227
+ function isoDate2(y, m, d) {
140821
142228
  return `${y}-${pad(m)}-${pad(d)}`;
140822
142229
  }
140823
142230
  function lastDayOfMonth2(y, m) {
@@ -140830,8 +142237,8 @@ function listMonths(start, end) {
140830
142237
  let y = s.y;
140831
142238
  let m = s.m;
140832
142239
  while (y < e.y || y === e.y && m <= e.m) {
140833
- const monthStart = y === s.y && m === s.m ? start : isoDate(y, m, 1);
140834
- const monthEnd = y === e.y && m === e.m ? end : isoDate(y, m, lastDayOfMonth2(y, m));
142240
+ const monthStart = y === s.y && m === s.m ? start : isoDate2(y, m, 1);
142241
+ const monthEnd = y === e.y && m === e.m ? end : isoDate2(y, m, lastDayOfMonth2(y, m));
140835
142242
  months.push({
140836
142243
  start: monthStart,
140837
142244
  end: monthEnd,
@@ -140872,8 +142279,8 @@ function previousCalendarQuarter(start, end) {
140872
142279
  const endM = prevEndMonth < 1 ? 12 : prevEndMonth;
140873
142280
  const startM = endM - 2;
140874
142281
  return {
140875
- start: isoDate(year, startM, 1),
140876
- end: isoDate(year, endM, lastDayOfMonth2(year, endM))
142282
+ start: isoDate2(year, startM, 1),
142283
+ end: isoDate2(year, endM, lastDayOfMonth2(year, endM))
140877
142284
  };
140878
142285
  }
140879
142286
  function yearOverYearRange(start, end) {
@@ -140887,11 +142294,11 @@ function yearOverYearRange(start, end) {
140887
142294
  function shiftYear(p, delta) {
140888
142295
  const y = p.y + delta;
140889
142296
  const last = lastDayOfMonth2(y, p.m);
140890
- return isoDate(y, p.m, Math.min(p.d, last));
142297
+ return isoDate2(y, p.m, Math.min(p.d, last));
140891
142298
  }
140892
142299
  function utcToIso(ms) {
140893
142300
  const d = new Date(ms);
140894
- return isoDate(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate());
142301
+ return isoDate2(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate());
140895
142302
  }
140896
142303
  function reportPeriodChrome(current, previous, lang = "zh") {
140897
142304
  const kind = classifyReportPeriod(current, previous, lang);
@@ -140928,8 +142335,8 @@ function lastCompleteQuarter(now = /* @__PURE__ */ new Date()) {
140928
142335
  const qStartMonth = qEndMonth - 2;
140929
142336
  const year = m <= 3 ? y - 1 : y;
140930
142337
  return {
140931
- start: isoDate(year, qStartMonth, 1),
140932
- end: isoDate(year, qEndMonth, lastDayOfMonth2(year, qEndMonth))
142338
+ start: isoDate2(year, qStartMonth, 1),
142339
+ end: isoDate2(year, qEndMonth, lastDayOfMonth2(year, qEndMonth))
140933
142340
  };
140934
142341
  }
140935
142342
 
@@ -141810,9 +143217,10 @@ async function runGoogleQuarterlyRender(opts) {
141810
143217
  readMetaRange(merged, "previous"),
141811
143218
  lang
141812
143219
  );
143220
+ const reportPayload = { ...merged, periodChrome };
141813
143221
  const outHtml = injectQuarterlyReport(
141814
143222
  localizeReportHtml(html, lang),
141815
- stampMetaLang({ ...merged, periodChrome }, lang)
143223
+ stampMetaLang(reportPayload, lang)
141816
143224
  );
141817
143225
  if (!outHtml.includes("homeCDN/echarts.min.js") || /new Chart\s*\(/.test(outHtml)) {
141818
143226
  console.error("\n\u274C \u6A21\u677F\u5FC5\u987B\u4F7F\u7528 ECharts\uFF0C\u7981\u6B62 Chart.js\u3002\n");
@@ -143704,7 +145112,7 @@ function sumActionArray(raw) {
143704
145112
  }
143705
145113
 
143706
145114
  // src/commands/facebook-analysis/entities.ts
143707
- function fail2(label2, err) {
145115
+ function fail4(label2, err) {
143708
145116
  const msg = err instanceof Error ? err.message : String(err);
143709
145117
  console.error(`
143710
145118
  \u274C ${label2}\uFF1A${msg}
@@ -143732,7 +145140,7 @@ async function runFacebookAccountStatus(opts) {
143732
145140
  try {
143733
145141
  row = await fetchFacebookAccount(config, manifestId, !!opts.verbose);
143734
145142
  } catch (err) {
143735
- fail2("\u67E5\u8BE2 Facebook \u8D26\u6237\u5931\u8D25", err);
145143
+ fail4("\u67E5\u8BE2 Facebook \u8D26\u6237\u5931\u8D25", err);
143736
145144
  }
143737
145145
  const payload = { account: manifestId, ...row };
143738
145146
  if (await emitCliJsonOrSnapshot(opts, {
@@ -143782,7 +145190,7 @@ async function runFacebookEntityList(opts, kind) {
143782
145190
  try {
143783
145191
  effectiveStatus = parseEffectiveStatusFilter(opts.effectiveStatus);
143784
145192
  } catch (err) {
143785
- fail2("\u53C2\u6570\u9519\u8BEF", err);
145193
+ fail4("\u53C2\u6570\u9519\u8BEF", err);
143786
145194
  }
143787
145195
  const pageSize = resolveFacebookPageSize(opts.pageSize);
143788
145196
  const config = loadConfig(opts.token);
@@ -143807,7 +145215,7 @@ async function runFacebookEntityList(opts, kind) {
143807
145215
  adsetId: opts.adsetId?.trim() || void 0
143808
145216
  });
143809
145217
  } catch (err) {
143810
- fail2(`\u67E5\u8BE2 ${meta.title} \u5931\u8D25`, err);
145218
+ fail4(`\u67E5\u8BE2 ${meta.title} \u5931\u8D25`, err);
143811
145219
  }
143812
145220
  const payload = wrapListJson({
143813
145221
  page: 1,
@@ -143928,7 +145336,7 @@ async function runFacebookInsights(opts) {
143928
145336
  breakdown = resolveFacebookBreakdown(opts.breakdown);
143929
145337
  timeIncrement = parseOptionalNumber2(opts.timeIncrement);
143930
145338
  } catch (err) {
143931
- fail2("\u53C2\u6570\u9519\u8BEF", err);
145339
+ fail4("\u53C2\u6570\u9519\u8BEF", err);
143932
145340
  }
143933
145341
  const config = loadConfig(opts.token);
143934
145342
  let items3;
@@ -143944,7 +145352,7 @@ async function runFacebookInsights(opts) {
143944
145352
  adIds: opts.adIds?.trim() || void 0
143945
145353
  });
143946
145354
  } catch (err) {
143947
- fail2("\u67E5\u8BE2 Facebook Insights \u5931\u8D25", err);
145355
+ fail4("\u67E5\u8BE2 Facebook Insights \u5931\u8D25", err);
143948
145356
  }
143949
145357
  const payload = {
143950
145358
  account: manifestId,
@@ -146773,7 +148181,7 @@ async function fetchOfficialReport(config, opts) {
146773
148181
  }
146774
148182
 
146775
148183
  // src/commands/tiktok-analysis/entities.ts
146776
- function fail3(label2, err) {
148184
+ function fail5(label2, err) {
146777
148185
  const msg = err instanceof Error ? err.message : String(err);
146778
148186
  console.error(`
146779
148187
  \u274C ${label2}\uFF1A${msg}
@@ -146787,7 +148195,7 @@ async function runTikTokAccountStatus(opts) {
146787
148195
  try {
146788
148196
  rows = await fetchAdvertiserInfoList(config, id, !!opts.verbose);
146789
148197
  } catch (err) {
146790
- fail3("\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);
148198
+ fail5("\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);
146791
148199
  }
146792
148200
  const payload = wrapListJson({
146793
148201
  page: 1,
@@ -146842,7 +148250,7 @@ async function runTikTokCampaignEntities(opts) {
146842
148250
  verbose: !!opts.verbose
146843
148251
  });
146844
148252
  } catch (err) {
146845
- fail3("\u67E5\u8BE2 TikTok \u7CFB\u5217\u5931\u8D25", err);
148253
+ fail5("\u67E5\u8BE2 TikTok \u7CFB\u5217\u5931\u8D25", err);
146846
148254
  }
146847
148255
  const payload = wrapListJson({
146848
148256
  page: 1,
@@ -146904,7 +148312,7 @@ async function runTikTokAdGroupEntities(opts) {
146904
148312
  verbose: !!opts.verbose
146905
148313
  });
146906
148314
  } catch (err) {
146907
- fail3("\u67E5\u8BE2 TikTok \u5E7F\u544A\u7EC4\u5931\u8D25", err);
148315
+ fail5("\u67E5\u8BE2 TikTok \u5E7F\u544A\u7EC4\u5931\u8D25", err);
146908
148316
  }
146909
148317
  const payload = wrapListJson({
146910
148318
  page: 1,
@@ -146971,7 +148379,7 @@ async function runTikTokAdEntities(opts) {
146971
148379
  verbose: !!opts.verbose
146972
148380
  });
146973
148381
  } catch (err) {
146974
- fail3("\u67E5\u8BE2 TikTok \u5E7F\u544A\u5931\u8D25", err);
148382
+ fail5("\u67E5\u8BE2 TikTok \u5E7F\u544A\u5931\u8D25", err);
146975
148383
  }
146976
148384
  const payload = wrapListJson({
146977
148385
  page: 1,
@@ -147045,7 +148453,7 @@ async function runTikTokOfficialReport(opts) {
147045
148453
  verbose: !!opts.verbose
147046
148454
  });
147047
148455
  } catch (err) {
147048
- fail3("\u67E5\u8BE2 TikTok \u5B98\u65B9\u62A5\u8868\u5931\u8D25", err);
148456
+ fail5("\u67E5\u8BE2 TikTok \u5B98\u65B9\u62A5\u8868\u5931\u8D25", err);
147049
148457
  }
147050
148458
  const totals = summarizeTikTokOfficialReport(result.items);
147051
148459
  const payload = {
@@ -148360,7 +149768,7 @@ function asRecord42(raw) {
148360
149768
  }
148361
149769
 
148362
149770
  // src/commands/yandex-analysis/entities.ts
148363
- function fail4(label2, err) {
149771
+ function fail6(label2, err) {
148364
149772
  const msg = err instanceof Error ? err.message : String(err);
148365
149773
  console.error(`
148366
149774
  \u274C ${label2}\uFF1A${msg}
@@ -148432,7 +149840,7 @@ async function runYandexAccountStatus(opts) {
148432
149840
  try {
148433
149841
  result = await fetchPath(opts, "overview", {});
148434
149842
  } catch (err) {
148435
- fail4("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
149843
+ fail6("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
148436
149844
  }
148437
149845
  const row = asRecord42(result.raw);
148438
149846
  await emitOrTable(opts, {
@@ -148474,7 +149882,7 @@ async function runYandexCampaignEntities(opts) {
148474
149882
  network: flags.network
148475
149883
  });
148476
149884
  } catch (err) {
148477
- fail4("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
149885
+ fail6("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
148478
149886
  }
148479
149887
  const items3 = unwrapYandexItems(result.raw);
148480
149888
  await emitOrTable(opts, {
@@ -148520,7 +149928,7 @@ async function runYandexAdGroupEntities(opts) {
148520
149928
  campaignId: flags.campaignId
148521
149929
  });
148522
149930
  } catch (err) {
148523
- fail4("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
149931
+ fail6("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
148524
149932
  }
148525
149933
  const items3 = unwrapYandexItems(result.raw);
148526
149934
  await emitOrTable(opts, {
@@ -148570,7 +149978,7 @@ async function runYandexAdEntities(opts) {
148570
149978
  adGroupId: flags.adGroupId
148571
149979
  });
148572
149980
  } catch (err) {
148573
- fail4("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
149981
+ fail6("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
148574
149982
  }
148575
149983
  const items3 = unwrapYandexItems(result.raw);
148576
149984
  const filtered = flags.status != null;
@@ -148622,7 +150030,7 @@ async function runYandexInsights(opts) {
148622
150030
  adGroupId: flags.adGroupId
148623
150031
  });
148624
150032
  } catch (err) {
148625
- fail4("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
150033
+ fail6("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
148626
150034
  }
148627
150035
  const items3 = unwrapYandexItems(result.raw);
148628
150036
  await emitOrTable(opts, {