siluzan-tso-cli 1.1.68 → 1.1.69-beta.2

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.
Files changed (41) hide show
  1. package/README.md +2 -1
  2. package/dist/index.js +1857 -568
  3. package/dist/skill/AGENTS.md +1 -1
  4. package/dist/skill/SKILL.md +19 -14
  5. package/dist/skill/_meta.json +2 -2
  6. package/dist/skill/references/README.md +4 -4
  7. package/dist/skill/references/accounts/accounts-list.md +1 -1
  8. package/dist/skill/references/accounts/accounts-permissions.md +2 -2
  9. package/dist/skill/references/accounts/finance.md +1 -1
  10. package/dist/skill/references/accounts/open-account-by-media.md +1 -1
  11. package/dist/skill/references/accounts/open-account-google-ui.md +1 -1
  12. package/dist/skill/references/analytics/account-analytics.md +7 -7
  13. package/dist/skill/references/analytics/google-analysis-batch.md +1 -0
  14. package/dist/skill/references/analytics/rag.md +1 -1
  15. package/dist/skill/references/analytics/reporting.md +5 -5
  16. package/dist/skill/references/analytics/website-diagnosis-guide.md +1 -1
  17. package/dist/skill/references/core/agent-conventions.md +8 -1
  18. package/dist/skill/references/core/intent-routing.md +7 -5
  19. package/dist/skill/references/core/playbooks.md +1 -1
  20. package/dist/skill/references/core/setup.md +5 -5
  21. package/dist/skill/references/core/workflows.md +3 -3
  22. package/dist/skill/references/google-ads/google-ads-read.md +34 -0
  23. package/dist/skill/references/google-ads/google-ads-write.md +65 -2
  24. package/dist/skill/references/google-ads/google-ads.md +1 -1
  25. package/dist/skill/references/meta-ads/meta-ads-write.md +2 -1
  26. package/dist/skill/references/meta-ads/meta-ads.md +2 -1
  27. package/dist/skill/references/misc/tso-home.md +2 -2
  28. package/dist/skill/references/operations/ad-gap.md +234 -0
  29. package/dist/skill/references/operations/hosted-automation-bing.md +3 -3
  30. package/dist/skill/references/operations/hosted-automation-scenarios.md +3 -3
  31. package/dist/skill/references/operations/hosted-automation-self-control.md +1 -1
  32. package/dist/skill/references/operations/hosted-automation-tiktok.md +3 -3
  33. package/dist/skill/references/operations/hosted-automation-user-catalog.md +7 -7
  34. package/dist/skill/references/operations/hosted-automation-yandex.md +3 -3
  35. package/dist/skill/references/report-templates/google-quarterly-report.md +1 -1
  36. package/dist/skill/references/report-templates/website-diagnosis-report.md +1 -1
  37. package/dist/skill/report-templates/google-quarterly-report.md +1 -1
  38. package/dist/skill/report-templates/website-diagnosis-report.md +1 -1
  39. package/dist/skill/scripts/install.ps1 +3 -3
  40. package/dist/skill/scripts/install.sh +3 -3
  41. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2397,7 +2397,7 @@ function rawRequest(url, options) {
2397
2397
  stream = res.pipe(zlib.createBrotliDecompress());
2398
2398
  }
2399
2399
  let failed = false;
2400
- const fail7 = (err) => {
2400
+ const fail8 = (err) => {
2401
2401
  if (failed) return;
2402
2402
  failed = true;
2403
2403
  res.destroy();
@@ -2416,7 +2416,7 @@ function rawRequest(url, options) {
2416
2416
  reject(err);
2417
2417
  };
2418
2418
  const onStreamError = (err) => {
2419
- fail7(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
2419
+ fail8(new Error(`\u54CD\u5E94\u89E3\u538B\u5931\u8D25\uFF08${encoding || "identity"}\uFF09\uFF1A${err.message}`));
2420
2420
  };
2421
2421
  if (stream !== res) stream.on("error", onStreamError);
2422
2422
  res.on("error", onStreamError);
@@ -2427,7 +2427,7 @@ function rawRequest(url, options) {
2427
2427
  const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
2428
2428
  byteLen += buf.length;
2429
2429
  if (maxBytes > 0 && byteLen > maxBytes) {
2430
- fail7(
2430
+ fail8(
2431
2431
  new Error(`\u54CD\u5E94\u4F53\u8D85\u8FC7\u4E0A\u9650\uFF08${(maxBytes / 1024 / 1024).toFixed(0)} MB\uFF09\uFF0C\u5DF2\u4E2D\u65AD\u8FDE\u63A5`)
2432
2432
  );
2433
2433
  return;
@@ -2540,15 +2540,15 @@ function messageFromJsonValue(value) {
2540
2540
  const rec = value;
2541
2541
  if (rec.errors && typeof rec.errors === "object" && !Array.isArray(rec.errors)) {
2542
2542
  const msgs = [];
2543
- for (const [field5, raw] of Object.entries(rec.errors)) {
2543
+ for (const [field6, raw] of Object.entries(rec.errors)) {
2544
2544
  if (Array.isArray(raw)) {
2545
2545
  for (const item of raw) {
2546
2546
  const msg = messageFromJsonValue(item);
2547
- if (msg) msgs.push(`${field5}: ${msg}`);
2547
+ if (msg) msgs.push(`${field6}: ${msg}`);
2548
2548
  }
2549
2549
  } else {
2550
2550
  const msg = messageFromJsonValue(raw);
2551
- if (msg) msgs.push(`${field5}: ${msg}`);
2551
+ if (msg) msgs.push(`${field6}: ${msg}`);
2552
2552
  }
2553
2553
  }
2554
2554
  if (msgs.length > 0) return msgs.join("; ");
@@ -4104,7 +4104,7 @@ var DEFAULT_API_BASE;
4104
4104
  var init_defaults = __esm({
4105
4105
  "src/config/defaults.ts"() {
4106
4106
  "use strict";
4107
- DEFAULT_API_BASE = "https://tso-api.siluzan.com";
4107
+ DEFAULT_API_BASE = "https://tso-api-ci.siluzan.com";
4108
4108
  }
4109
4109
  });
4110
4110
 
@@ -7616,7 +7616,8 @@ var init_google_analysis = __esm({
7616
7616
  "// \u4E2D\u6587\u8BD1\u540D\uFF1A`countryOrRegionZh`\uFF08\u7531 `countryOrRegion` \u7ECF geo-en2zh.json \u7FFB\u8BD1\uFF0C\u76EE\u524D\u8986\u76D6 105 \u4E2A\u56FD\u5BB6/\u5730\u533A\uFF1B\u672A\u547D\u4E2D\u65F6\u8BE5\u5B57\u6BB5\u7F3A\u7701\uFF09\u3002"
7617
7617
  ],
7618
7618
  "geo-targeted": [
7619
- "// \u5F53\u524D\u4ECD\u5728\u6295\u653E\u7684\u5B9A\u4F4D\uFF08\u5DF2\u79FB\u9664\u56FD\u5BB6\u4E0D\u4F1A\u51FA\u73B0\uFF09\u3002\u4E2D\u6587\u8BD1\u540D\uFF1A`countryOrRegionZh`\uFF08\u7531 `countryOrRegion` \u7ECF geo-en2zh.json \u7FFB\u8BD1\uFF1B\u672A\u547D\u4E2D\u65F6\u8BE5\u5B57\u6BB5\u7F3A\u7701\uFF09\u3002",
7619
+ "// \u5F53\u524D\u4ECD\u5728\u6295\u653E\u7684\u5B9A\u4F4D\uFF08\u5DF2\u79FB\u9664\u56FD\u5BB6\u4E0D\u4F1A\u51FA\u73B0\uFF09\u3002\u6BCF\u884C\u6709\u6240\u5C5E\u7CFB\u5217\u7684 `channelTypeV2`\uFF08SEARCH / DISPLAY / PERFORMANCE_MAX \u7B49\uFF09\u3002\u6309\u6E20\u9053\u7B5B\u5B9A\u4F4D\u76F4\u63A5\u8BFB\u8FD9\u4E2A\u5B57\u6BB5\u3002",
7620
+ "// \u4E2D\u6587\u8BD1\u540D\uFF1A`countryOrRegionZh`\uFF08\u7531 `countryOrRegion` \u7ECF geo-en2zh.json \u7FFB\u8BD1\uFF1B\u672A\u547D\u4E2D\u65F6\u8BE5\u5B57\u6BB5\u7F3A\u7701\uFF09\u3002",
7620
7621
  "// `ctr` \u5DF2\u6298\u6210 0~1 \u5C0F\u6570\uFF1B`conversionRate` \u7F51\u5173\u672C\u8EAB\u5C31\u662F 0~1\uFF0C\u4E0D\u8981\u518D \xF7100\u3002"
7621
7622
  ],
7622
7623
  "geo-matched": [
@@ -7686,8 +7687,8 @@ var init_bid_modifier_display = __esm({
7686
7687
  });
7687
7688
 
7688
7689
  // src/commands/facebook-analysis/xlsx-style-engine.ts
7689
- import fs13 from "fs";
7690
- import path18 from "path";
7690
+ import fs14 from "fs";
7691
+ import path19 from "path";
7691
7692
  function resolveAccent(accent) {
7692
7693
  if (!accent) return PLATFORM_ACCENTS.default;
7693
7694
  const hex = accent.replace(/^#/, "");
@@ -8176,9 +8177,9 @@ var init_xlsx_style_engine = __esm({
8176
8177
  return zipStore(files);
8177
8178
  }
8178
8179
  writeFile(filePath) {
8179
- const abs = path18.resolve(filePath);
8180
- fs13.mkdirSync(path18.dirname(abs), { recursive: true });
8181
- fs13.writeFileSync(abs, this.toBuffer());
8180
+ const abs = path19.resolve(filePath);
8181
+ fs14.mkdirSync(path19.dirname(abs), { recursive: true });
8182
+ fs14.writeFileSync(abs, this.toBuffer());
8182
8183
  return abs;
8183
8184
  }
8184
8185
  };
@@ -9358,8 +9359,8 @@ var init_http_retry = __esm({
9358
9359
  });
9359
9360
 
9360
9361
  // src/commands/google-analysis/normalize-impression-shares.ts
9361
- function normalizeShareValue(value, competitiveMetrics, field5) {
9362
- const cmVal = competitiveMetrics?.[field5];
9362
+ function normalizeShareValue(value, competitiveMetrics, field6) {
9363
+ const cmVal = competitiveMetrics?.[field6];
9363
9364
  if (typeof cmVal === "number" && Number.isFinite(cmVal)) {
9364
9365
  return cmVal;
9365
9366
  }
@@ -9371,10 +9372,10 @@ function normalizeShareValue(value, competitiveMetrics, field5) {
9371
9372
  function normalizeLegacyShareOnRow(row) {
9372
9373
  const rawCm = row.competitiveMetrics;
9373
9374
  const competitiveMetrics = rawCm !== null && typeof rawCm === "object" && !Array.isArray(rawCm) ? rawCm : null;
9374
- for (const field5 of LEGACY_ROW_IMPRESSION_SHARE_FIELDS) {
9375
- const v = row[field5];
9375
+ for (const field6 of LEGACY_ROW_IMPRESSION_SHARE_FIELDS) {
9376
+ const v = row[field6];
9376
9377
  if (typeof v !== "number" || !Number.isFinite(v)) continue;
9377
- row[field5] = normalizeShareValue(v, competitiveMetrics, field5);
9378
+ row[field6] = normalizeShareValue(v, competitiveMetrics, field6);
9378
9379
  }
9379
9380
  }
9380
9381
  function normalizeRowsInArray(rows) {
@@ -9553,6 +9554,7 @@ function targetedLocationsToGeographic(raw) {
9553
9554
  countryOrRegion: typeof row.locationName === "string" ? row.locationName : "",
9554
9555
  campaignId: row.campaignId == null ? void 0 : String(row.campaignId),
9555
9556
  campaignName: typeof row.campaignName === "string" ? row.campaignName : "",
9557
+ ...typeof row.channelTypeV2 === "string" && row.channelTypeV2 ? { channelTypeV2: row.channelTypeV2 } : {},
9556
9558
  impressions: finiteNumber2(row.impressions),
9557
9559
  clicks: finiteNumber2(row.clicks),
9558
9560
  ctr: finiteNumber2(row.ctr) / 100,
@@ -105137,22 +105139,22 @@ var init_demand_gen_report_content = __esm({
105137
105139
  });
105138
105140
 
105139
105141
  // src/commands/google-analysis/demand-gen-render.ts
105140
- import fs31 from "fs";
105142
+ import fs32 from "fs";
105141
105143
  import fsPromises2 from "fs/promises";
105142
- import path36 from "path";
105144
+ import path37 from "path";
105143
105145
  import { fileURLToPath as fileURLToPath9 } from "url";
105144
105146
  function resolveSkillTemplatePath3(basename13) {
105145
- const dir = path36.dirname(fileURLToPath9(import.meta.url));
105147
+ const dir = path37.dirname(fileURLToPath9(import.meta.url));
105146
105148
  const candidates = [
105147
- path36.join(dir, "skill", "report-templates", basename13),
105148
- path36.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
105149
- path36.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename13),
105150
- path36.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
105149
+ path37.join(dir, "skill", "report-templates", basename13),
105150
+ path37.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
105151
+ path37.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename13),
105152
+ path37.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
105151
105153
  ];
105152
105154
  for (const candidate of candidates) {
105153
- if (fs31.existsSync(candidate)) return candidate;
105155
+ if (fs32.existsSync(candidate)) return candidate;
105154
105156
  }
105155
- return path36.join(dir, "skill", "report-templates", basename13);
105157
+ return path37.join(dir, "skill", "report-templates", basename13);
105156
105158
  }
105157
105159
  function demandGenReportTemplatePath() {
105158
105160
  return resolveSkillTemplatePath3(TEMPLATE_BASENAME);
@@ -105173,7 +105175,7 @@ function injectDemandGenReport(html, payload) {
105173
105175
  return html.replace(DEMAND_GEN_INJECT_MARKER, `window.__DEMAND_GEN_REPORT__ = ${json};`);
105174
105176
  }
105175
105177
  async function runDemandGenRender(opts) {
105176
- const dataPath = path36.resolve(opts.dataFile);
105178
+ const dataPath = path37.resolve(opts.dataFile);
105177
105179
  const data = asDemandGenReport(await readJsonFile2(dataPath));
105178
105180
  if (opts.lang?.trim()) data.meta.lang = opts.lang.trim();
105179
105181
  const check = validateDemandGenReport(data);
@@ -105188,10 +105190,10 @@ ${formatDemandGenReportErrors(check)}`);
105188
105190
  } catch {
105189
105191
  throw new Error(`\u672A\u627E\u5230\u62A5\u544A\u6A21\u677F\uFF1A${templatePath}\u3002\u8BF7\u5148\u6267\u884C npm run build`);
105190
105192
  }
105191
- const outPath = path36.resolve(
105192
- opts.out ?? path36.join(path36.dirname(dataPath), "demand-gen-analysis-report.html")
105193
+ const outPath = path37.resolve(
105194
+ opts.out ?? path37.join(path37.dirname(dataPath), "demand-gen-analysis-report.html")
105193
105195
  );
105194
- await fsPromises2.mkdir(path36.dirname(outPath), { recursive: true });
105196
+ await fsPromises2.mkdir(path37.dirname(outPath), { recursive: true });
105195
105197
  await fsPromises2.writeFile(outPath, injectDemandGenReport(html, data), "utf8");
105196
105198
  console.log(`
105197
105199
  \u2705 Demand Gen \u6295\u653E\u6570\u636E\u5206\u6790 HTML \u5DF2\u751F\u6210\uFF1A${outPath}
@@ -105209,8 +105211,8 @@ var init_demand_gen_render = __esm({
105209
105211
  });
105210
105212
 
105211
105213
  // src/commands/google-analysis/okki-pmax-search-terms.ts
105212
- import * as fs32 from "fs/promises";
105213
- import * as path37 from "path";
105214
+ import * as fs33 from "fs/promises";
105215
+ import * as path38 from "path";
105214
105216
  function asRecord20(value) {
105215
105217
  if (value && typeof value === "object" && !Array.isArray(value)) return value;
105216
105218
  return null;
@@ -105325,8 +105327,8 @@ async function mapPool(items3, limit, fn) {
105325
105327
  }
105326
105328
  async function readManifest(snapshotDir, accountId) {
105327
105329
  try {
105328
- const raw = await fs32.readFile(
105329
- path37.join(snapshotDir, googleAnalysisManifestFile(accountId)),
105330
+ const raw = await fs33.readFile(
105331
+ path38.join(snapshotDir, googleAnalysisManifestFile(accountId)),
105330
105332
  "utf8"
105331
105333
  );
105332
105334
  const parsed = JSON.parse(raw);
@@ -105345,7 +105347,7 @@ function dateRangeOf(manifest) {
105345
105347
  return { start: range.start, end: range.end };
105346
105348
  }
105347
105349
  async function writePmaxSearchTermsSnapshot(opts) {
105348
- const absDir = path37.resolve(opts.snapshotDir);
105350
+ const absDir = path38.resolve(opts.snapshotDir);
105349
105351
  const manifest = await readManifest(absDir, opts.accountId);
105350
105352
  const range = manifest ? dateRangeOf(manifest) : null;
105351
105353
  if (!manifest || !range) return null;
@@ -105354,7 +105356,7 @@ async function writePmaxSearchTermsSnapshot(opts) {
105354
105356
  const campaignArt = campaignArts.find((art) => art.file.includes(dateTag)) ?? campaignArts.at(-1);
105355
105357
  if (!campaignArt) return null;
105356
105358
  const campaignRaw = JSON.parse(
105357
- await fs32.readFile(path37.join(absDir, campaignArt.file), "utf8")
105359
+ await fs33.readFile(path38.join(absDir, campaignArt.file), "utf8")
105358
105360
  );
105359
105361
  const campaigns = selectPmaxCampaignsWithTraffic(
105360
105362
  Array.isArray(campaignRaw.items) ? campaignRaw.items : []
@@ -105403,9 +105405,9 @@ async function writePmaxSearchTermsSnapshot(opts) {
105403
105405
  items: items3,
105404
105406
  record: null
105405
105407
  };
105406
- await fs32.writeFile(path37.join(absDir, fileName), `${JSON.stringify(envelope, null, 2)}
105408
+ await fs33.writeFile(path38.join(absDir, fileName), `${JSON.stringify(envelope, null, 2)}
105407
105409
  `, "utf8");
105408
- const manifestPath = path37.join(absDir, googleAnalysisManifestFile(opts.accountId));
105410
+ const manifestPath = path38.join(absDir, googleAnalysisManifestFile(opts.accountId));
105409
105411
  await withAsyncLock(manifestPath, async () => {
105410
105412
  const existing = await readManifest(absDir, opts.accountId);
105411
105413
  const merged = mergeGoogleAnalysisManifest(existing, {
@@ -105419,7 +105421,7 @@ async function writePmaxSearchTermsSnapshot(opts) {
105419
105421
  endpointHint: "campaign/pmax/{campaignId}/reports/search"
105420
105422
  }
105421
105423
  });
105422
- await fs32.writeFile(manifestPath, `${JSON.stringify(merged, null, 2)}
105424
+ await fs33.writeFile(manifestPath, `${JSON.stringify(merged, null, 2)}
105423
105425
  `, "utf8");
105424
105426
  });
105425
105427
  return {
@@ -105571,8 +105573,8 @@ var init_okki_display = __esm({
105571
105573
  });
105572
105574
 
105573
105575
  // src/commands/google-analysis/merge-snapshot.ts
105574
- import * as fs33 from "fs/promises";
105575
- import * as path38 from "path";
105576
+ import * as fs34 from "fs/promises";
105577
+ import * as path39 from "path";
105576
105578
  function asRecord22(value) {
105577
105579
  if (value && typeof value === "object" && !Array.isArray(value)) {
105578
105580
  return value;
@@ -105590,7 +105592,7 @@ async function readManifest2(snapshotDir, accountId) {
105590
105592
  const candidates = [];
105591
105593
  if (accountId) candidates.push(googleAnalysisManifestFile(accountId));
105592
105594
  try {
105593
- const entries = await fs33.readdir(snapshotDir);
105595
+ const entries = await fs34.readdir(snapshotDir);
105594
105596
  const manifestNames = entries.filter((n) => n.startsWith("manifest") && n.endsWith(".json"));
105595
105597
  for (const name2 of manifestNames) {
105596
105598
  if (!candidates.includes(name2)) candidates.push(name2);
@@ -105599,7 +105601,7 @@ async function readManifest2(snapshotDir, accountId) {
105599
105601
  }
105600
105602
  for (const name2 of candidates) {
105601
105603
  try {
105602
- const raw = await fs33.readFile(path38.join(snapshotDir, name2), "utf8");
105604
+ const raw = await fs34.readFile(path39.join(snapshotDir, name2), "utf8");
105603
105605
  const parsed = JSON.parse(raw);
105604
105606
  if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
105605
105607
  } catch {
@@ -105609,7 +105611,7 @@ async function readManifest2(snapshotDir, accountId) {
105609
105611
  }
105610
105612
  async function loadSectionFile(snapshotDir, file) {
105611
105613
  try {
105612
- const raw = await fs33.readFile(path38.join(snapshotDir, file), "utf8");
105614
+ const raw = await fs34.readFile(path39.join(snapshotDir, file), "utf8");
105613
105615
  const parsed = JSON.parse(raw);
105614
105616
  if (parsed && typeof parsed === "object") return parsed;
105615
105617
  return null;
@@ -105678,7 +105680,7 @@ async function recoverMissingReportSections(sectionMap, absDir, accountId, prefe
105678
105680
  if (!accountId) return;
105679
105681
  let entries;
105680
105682
  try {
105681
- entries = await fs33.readdir(absDir);
105683
+ entries = await fs34.readdir(absDir);
105682
105684
  } catch {
105683
105685
  return;
105684
105686
  }
@@ -105750,7 +105752,7 @@ function sumCampaignRowsToPeriodKpis(rows) {
105750
105752
  };
105751
105753
  }
105752
105754
  async function mergeGoogleAnalysisSnapshotIntoReport(payload, snapshotDir) {
105753
- const absDir = path38.resolve(snapshotDir);
105755
+ const absDir = path39.resolve(snapshotDir);
105754
105756
  const metaAccountId = typeof asRecord22(payload.meta)?.accountId === "string" ? asRecord22(payload.meta)?.accountId : void 0;
105755
105757
  const manifest = await readManifest2(snapshotDir, metaAccountId);
105756
105758
  if (!manifest) {
@@ -106116,8 +106118,8 @@ var init_okki_report_content = __esm({
106116
106118
  });
106117
106119
 
106118
106120
  // src/commands/google-analysis/okki-merge-snapshot.ts
106119
- import * as fs34 from "fs/promises";
106120
- import * as path39 from "path";
106121
+ import * as fs35 from "fs/promises";
106122
+ import * as path40 from "path";
106121
106123
  function num6(value) {
106122
106124
  const n = Number(value);
106123
106125
  return Number.isFinite(n) ? n : void 0;
@@ -106143,7 +106145,7 @@ async function readManifest3(snapshotDir, accountId) {
106143
106145
  const candidates = [];
106144
106146
  if (accountId) candidates.push(googleAnalysisManifestFile(accountId));
106145
106147
  try {
106146
- const entries = await fs34.readdir(snapshotDir);
106148
+ const entries = await fs35.readdir(snapshotDir);
106147
106149
  for (const name2 of entries.filter((n) => n.startsWith("manifest") && n.endsWith(".json"))) {
106148
106150
  if (!candidates.includes(name2)) candidates.push(name2);
106149
106151
  }
@@ -106151,7 +106153,7 @@ async function readManifest3(snapshotDir, accountId) {
106151
106153
  }
106152
106154
  for (const name2 of candidates) {
106153
106155
  try {
106154
- const raw = await fs34.readFile(path39.join(snapshotDir, name2), "utf8");
106156
+ const raw = await fs35.readFile(path40.join(snapshotDir, name2), "utf8");
106155
106157
  const parsed = JSON.parse(raw);
106156
106158
  if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
106157
106159
  } catch {
@@ -106161,7 +106163,7 @@ async function readManifest3(snapshotDir, accountId) {
106161
106163
  }
106162
106164
  async function loadSectionFile2(snapshotDir, file) {
106163
106165
  try {
106164
- const raw = await fs34.readFile(path39.join(snapshotDir, file), "utf8");
106166
+ const raw = await fs35.readFile(path40.join(snapshotDir, file), "utf8");
106165
106167
  const parsed = JSON.parse(raw);
106166
106168
  if (parsed && typeof parsed === "object") return parsed;
106167
106169
  return null;
@@ -106170,7 +106172,7 @@ async function loadSectionFile2(snapshotDir, file) {
106170
106172
  }
106171
106173
  }
106172
106174
  async function mergeOkkiSnapshotIntoReport(payload, snapshotDir) {
106173
- const absDir = path39.resolve(snapshotDir);
106175
+ const absDir = path40.resolve(snapshotDir);
106174
106176
  const metaAccountId = typeof asRecord23(payload.meta)?.accountId === "string" ? asRecord23(payload.meta)?.accountId : void 0;
106175
106177
  const manifest = await readManifest3(absDir, metaAccountId);
106176
106178
  if (!manifest) {
@@ -106187,7 +106189,7 @@ async function mergeOkkiSnapshotIntoReport(payload, snapshotDir) {
106187
106189
  if (accountId) {
106188
106190
  let entries = [];
106189
106191
  try {
106190
- entries = await fs34.readdir(absDir);
106192
+ entries = await fs35.readdir(absDir);
106191
106193
  } catch {
106192
106194
  entries = [];
106193
106195
  }
@@ -106713,10 +106715,10 @@ var init_okki_render_excel = __esm({
106713
106715
  });
106714
106716
 
106715
106717
  // src/commands/google-analysis/okki-render-report.ts
106716
- import fs35 from "fs/promises";
106717
- import path40 from "path";
106718
+ import fs36 from "fs/promises";
106719
+ import path41 from "path";
106718
106720
  async function readJsonFile3(filePath) {
106719
- const text5 = await fs35.readFile(filePath, "utf8");
106721
+ const text5 = await fs36.readFile(filePath, "utf8");
106720
106722
  try {
106721
106723
  return JSON.parse(text5);
106722
106724
  } catch {
@@ -106730,7 +106732,7 @@ function asPayload(value) {
106730
106732
  throw new Error("\u62A5\u544A\u6570\u636E\u987B\u4E3A JSON \u5BF9\u8C61");
106731
106733
  }
106732
106734
  async function runGoogleAnalysisOkkiRender(opts) {
106733
- const dataPath = path40.resolve(opts.dataFile);
106735
+ const dataPath = path41.resolve(opts.dataFile);
106734
106736
  const snapshotDir = opts.snapshotDir?.trim();
106735
106737
  if (!snapshotDir) {
106736
106738
  console.error("\n\u274C okki-render \u5FC5\u987B\u4F20 --snapshot-dir\uFF08google-analysis --json-out \u76EE\u5F55\uFF09\n");
@@ -106738,7 +106740,7 @@ async function runGoogleAnalysisOkkiRender(opts) {
106738
106740
  }
106739
106741
  let data = asPayload(await readJsonFile3(dataPath));
106740
106742
  try {
106741
- data = await mergeOkkiSnapshotIntoReport(data, path40.resolve(snapshotDir));
106743
+ data = await mergeOkkiSnapshotIntoReport(data, path41.resolve(snapshotDir));
106742
106744
  } catch (err) {
106743
106745
  console.error(`
106744
106746
  \u274C ${err instanceof Error ? err.message : String(err)}
@@ -106758,10 +106760,10 @@ async function runGoogleAnalysisOkkiRender(opts) {
106758
106760
  );
106759
106761
  process.exit(1);
106760
106762
  }
106761
- const outPath = path40.resolve(
106762
- opts.out ?? path40.join(path40.dirname(dataPath), "okki-weekly-report.xlsx")
106763
+ const outPath = path41.resolve(
106764
+ opts.out ?? path41.join(path41.dirname(dataPath), "okki-weekly-report.xlsx")
106763
106765
  );
106764
- await fs35.mkdir(path40.dirname(outPath), { recursive: true });
106766
+ await fs36.mkdir(path41.dirname(outPath), { recursive: true });
106765
106767
  writeOkkiWeeklyExcel(outPath, data, lang);
106766
106768
  console.log(`
106767
106769
  \u2705 OKKI \u5468\u62A5\u5DF2\u751F\u6210\uFF1A${outPath}
@@ -106934,19 +106936,19 @@ var init_report_content = __esm({
106934
106936
  });
106935
106937
 
106936
106938
  // src/commands/google-analysis/render-report.ts
106937
- import fs36 from "fs";
106939
+ import fs37 from "fs";
106938
106940
  import fsPromises3 from "fs/promises";
106939
- import path41 from "path";
106941
+ import path42 from "path";
106940
106942
  import { fileURLToPath as fileURLToPath10 } from "url";
106941
106943
  function resolveSkillTemplatePath4(basename13) {
106942
- const dir = path41.dirname(fileURLToPath10(import.meta.url));
106944
+ const dir = path42.dirname(fileURLToPath10(import.meta.url));
106943
106945
  const candidates = [
106944
- path41.join(dir, "skill", "report-templates", basename13),
106945
- path41.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
106946
- path41.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
106946
+ path42.join(dir, "skill", "report-templates", basename13),
106947
+ path42.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
106948
+ path42.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
106947
106949
  ];
106948
106950
  for (const p of candidates) {
106949
- if (fs36.existsSync(p)) return p;
106951
+ if (fs37.existsSync(p)) return p;
106950
106952
  }
106951
106953
  return candidates[0];
106952
106954
  }
@@ -106976,10 +106978,10 @@ function injectReportData2(html, payload, lang) {
106976
106978
  return localized.replace(INJECT_MARKER, `window.__GOOGLE_PERIOD_REPORT__ = ${json};`);
106977
106979
  }
106978
106980
  async function runGoogleAnalysisRender(opts) {
106979
- const dataPath = path41.resolve(opts.dataFile);
106981
+ const dataPath = path42.resolve(opts.dataFile);
106980
106982
  let data = asRecord25(await readJsonFile4(dataPath));
106981
106983
  if (opts.snapshotDir?.trim()) {
106982
- data = await mergeGoogleAnalysisSnapshotIntoReport(data, path41.resolve(opts.snapshotDir));
106984
+ data = await mergeGoogleAnalysisSnapshotIntoReport(data, path42.resolve(opts.snapshotDir));
106983
106985
  }
106984
106986
  const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
106985
106987
  const contentCheck = validateGooglePeriodReportContent(data);
@@ -107006,10 +107008,10 @@ async function runGoogleAnalysisRender(opts) {
107006
107008
  `);
107007
107009
  process.exit(1);
107008
107010
  }
107009
- const outPath = path41.resolve(
107010
- opts.out ?? path41.join(path41.dirname(dataPath), "google-period-report.html")
107011
+ const outPath = path42.resolve(
107012
+ opts.out ?? path42.join(path42.dirname(dataPath), "google-period-report.html")
107011
107013
  );
107012
- const outDir = path41.dirname(outPath);
107014
+ const outDir = path42.dirname(outPath);
107013
107015
  await fsPromises3.mkdir(outDir, { recursive: true });
107014
107016
  await fsPromises3.writeFile(outPath, injectReportData2(html, data, lang), "utf8");
107015
107017
  const { stats } = contentCheck;
@@ -107041,8 +107043,8 @@ var init_render_report = __esm({
107041
107043
 
107042
107044
  // src/utils/batch-runner.ts
107043
107045
  import { performance as performance2 } from "perf_hooks";
107044
- import * as path42 from "path";
107045
- import * as fs37 from "fs/promises";
107046
+ import * as path43 from "path";
107047
+ import * as fs38 from "fs/promises";
107046
107048
  async function runPool(items3, concurrencyRef, worker, signal) {
107047
107049
  let cursor = 0;
107048
107050
  const launch = () => {
@@ -107181,7 +107183,7 @@ async function runBatch(opts) {
107181
107183
  }
107182
107184
  const inner = {
107183
107185
  ...emptyProgress(
107184
- opts.paths.runDir.split(path42.sep).pop() ?? "run",
107186
+ opts.paths.runDir.split(path43.sep).pop() ?? "run",
107185
107187
  allTasks.length,
107186
107188
  opts.accountConcurrency,
107187
107189
  opts.sectionConcurrency
@@ -107306,7 +107308,7 @@ async function runBatch(opts) {
107306
107308
  signal: aborterToken.signal
107307
107309
  });
107308
107310
  await writer({
107309
- snapshotDir: path42.join(opts.paths.resultsDir, sanitizeAccountSegment(task.accountId)),
107311
+ snapshotDir: path43.join(opts.paths.resultsDir, sanitizeAccountSegment(task.accountId)),
107310
107312
  section: task.section,
107311
107313
  accountId: task.accountId,
107312
107314
  dateRange: result.dateRange,
@@ -107403,7 +107405,7 @@ async function runBatch(opts) {
107403
107405
  };
107404
107406
  }
107405
107407
  async function writeTaskError(paths, errorsDir, task, err, cls) {
107406
- const file = path42.join(errorsDir, `${sanitizeSection(task.section)}.error.json`);
107408
+ const file = path43.join(errorsDir, `${sanitizeSection(task.section)}.error.json`);
107407
107409
  const payload = {
107408
107410
  schemaVersion: 1,
107409
107411
  taskId: task.id,
@@ -107449,10 +107451,10 @@ async function persistRunMetadata(input) {
107449
107451
  accountsTotal: input.accounts.length,
107450
107452
  invocation: input.invocation
107451
107453
  };
107452
- await fs37.mkdir(paths.runDir, { recursive: true });
107453
- await fs37.mkdir(paths.stateDir, { recursive: true });
107454
- await fs37.mkdir(paths.resultsDir, { recursive: true });
107455
- await fs37.mkdir(paths.errorsDir, { recursive: true });
107454
+ await fs38.mkdir(paths.runDir, { recursive: true });
107455
+ await fs38.mkdir(paths.stateDir, { recursive: true });
107456
+ await fs38.mkdir(paths.resultsDir, { recursive: true });
107457
+ await fs38.mkdir(paths.errorsDir, { recursive: true });
107456
107458
  await writeRunManifest(paths, manifest);
107457
107459
  await writeAccounts(paths, input.accounts);
107458
107460
  return paths;
@@ -107495,8 +107497,8 @@ var init_batch_runner = __esm({
107495
107497
  shouldDowngrade(now = Date.now()) {
107496
107498
  if (this.window.length < this.opts.windowSize) return false;
107497
107499
  if (now - this.lastDowngradeAt < this.opts.cooldownMs) return false;
107498
- const fail7 = this.window.filter((s) => !s).length;
107499
- const rate2 = fail7 / this.window.length;
107500
+ const fail8 = this.window.filter((s) => !s).length;
107501
+ const rate2 = fail8 / this.window.length;
107500
107502
  if (rate2 >= this.opts.errorRateThreshold) {
107501
107503
  this.lastDowngradeAt = now;
107502
107504
  this.window.length = 0;
@@ -107517,7 +107519,7 @@ __export(google_analysis_batch_exports, {
107517
107519
  parseAccountIds: () => parseAccountIds,
107518
107520
  registerGoogleAnalysisBatchCommands: () => registerGoogleAnalysisBatchCommands
107519
107521
  });
107520
- import * as path43 from "path";
107522
+ import * as path44 from "path";
107521
107523
  import { performance as performance3 } from "perf_hooks";
107522
107524
  function parseSections(input) {
107523
107525
  if (!input || !input.trim()) return DEFAULT_SECTIONS;
@@ -108136,7 +108138,7 @@ var init_google_analysis_batch = __esm({
108136
108138
  });
108137
108139
 
108138
108140
  // src/commands/google-analysis/register-cli.ts
108139
- import * as path44 from "path";
108141
+ import * as path45 from "path";
108140
108142
  import { performance as performance4 } from "perf_hooks";
108141
108143
  import { Command } from "commander";
108142
108144
  function normalizeAnalysisDateOpts(opts) {
@@ -108312,7 +108314,7 @@ async function runAllSections(opts) {
108312
108314
  }
108313
108315
  const succeeded = results.filter((r) => r.ok).length;
108314
108316
  const failed = results.length - succeeded;
108315
- const absoluteSnapshotDir = path44.resolve(opts.jsonOut);
108317
+ const absoluteSnapshotDir = path45.resolve(opts.jsonOut);
108316
108318
  const summary = {
108317
108319
  kind: "siluzan-tso-google-analysis-snapshot-batch",
108318
108320
  absoluteSnapshotDir,
@@ -108596,8 +108598,8 @@ var init_google_analysis3 = __esm({
108596
108598
  // src/index.ts
108597
108599
  init_dist();
108598
108600
  init_dist();
108599
- import * as fs48 from "fs";
108600
- import * as path59 from "path";
108601
+ import * as fs49 from "fs";
108602
+ import * as path60 from "path";
108601
108603
  import { fileURLToPath as fileURLToPath16 } from "url";
108602
108604
  import { Command as Command6 } from "commander";
108603
108605
 
@@ -109087,8 +109089,8 @@ function deriveWebUrl(apiBaseUrl) {
109087
109089
  }
109088
109090
  var TSO_UMI_ROUTE_PREFIX = "/v3umijs/tso";
109089
109091
  function buildTsoPageWebUrl(webUrl, tsoSubRoute, extraQuery) {
109090
- const path60 = tsoSubRoute.replace(/^\/+/, "");
109091
- const umiPath = `${TSO_UMI_ROUTE_PREFIX}/${path60}`;
109092
+ const path61 = tsoSubRoute.replace(/^\/+/, "");
109093
+ const umiPath = `${TSO_UMI_ROUTE_PREFIX}/${path61}`;
109092
109094
  const q = new URLSearchParams({ tso: umiPath });
109093
109095
  if (extraQuery) {
109094
109096
  for (const [key, value] of Object.entries(extraQuery)) {
@@ -109096,7 +109098,7 @@ function buildTsoPageWebUrl(webUrl, tsoSubRoute, extraQuery) {
109096
109098
  if (v) q.set(key, v);
109097
109099
  }
109098
109100
  }
109099
- return `${webUrl.replace(/\/+$/, "")}/v3/foreign_trade/tso/${path60}?${q.toString()}`;
109101
+ return `${webUrl.replace(/\/+$/, "")}/v3/foreign_trade/tso/${path61}?${q.toString()}`;
109100
109102
  }
109101
109103
  function cmdConfigShow() {
109102
109104
  const shared = readSharedConfig();
@@ -111952,13 +111954,13 @@ init_lang();
111952
111954
  function moneyGte(leftYuan, rightYuan) {
111953
111955
  return Math.round(leftYuan * 100) >= Math.round(rightYuan * 100);
111954
111956
  }
111955
- function isBudgetCircuitHit(spend, budgetYuan, ratio) {
111956
- if (spend == null || budgetYuan == null) return false;
111957
- if (!Number.isFinite(spend) || !Number.isFinite(budgetYuan) || !Number.isFinite(ratio)) {
111957
+ function isBudgetCircuitHit(spend, budgetYuan2, ratio) {
111958
+ if (spend == null || budgetYuan2 == null) return false;
111959
+ if (!Number.isFinite(spend) || !Number.isFinite(budgetYuan2) || !Number.isFinite(ratio)) {
111958
111960
  return false;
111959
111961
  }
111960
- if (budgetYuan <= 0 || ratio <= 0) return false;
111961
- return moneyGte(spend, budgetYuan * ratio);
111962
+ if (budgetYuan2 <= 0 || ratio <= 0) return false;
111963
+ return moneyGte(spend, budgetYuan2 * ratio);
111962
111964
  }
111963
111965
  function isZeroConvHit(spend, conversions, targetCpaYuan, multiple) {
111964
111966
  if (spend == null || targetCpaYuan == null) return false;
@@ -115778,7 +115780,12 @@ init_shared();
115778
115780
 
115779
115781
  // src/commands/ad/campaign.ts
115780
115782
  init_auth();
115783
+ import fs12 from "fs/promises";
115784
+ import path17 from "path";
115781
115785
  init_cli_json_snapshot();
115786
+ init_media_customer_id();
115787
+ init_resumable_scan();
115788
+ init_time_budget();
115782
115789
 
115783
115790
  // src/commands/ad/digest-campaign-reuse.ts
115784
115791
  import fs11 from "fs";
@@ -116328,10 +116335,10 @@ function biddingStrategiesMatch(expected, actual) {
116328
116335
  const act = String(actual ?? "").trim().toUpperCase();
116329
116336
  return exp === "TARGET_CPA" && act === "MAXIMIZE_CONVERSIONS" || exp === "TARGET_ROAS" && act === "MAXIMIZE_CONVERSION_VALUE";
116330
116337
  }
116331
- function fieldCheck(field5, expected, actual, present) {
116332
- if (!present) return { field: field5, expected, actual: void 0, state: "unread" };
116338
+ function fieldCheck(field6, expected, actual, present) {
116339
+ if (!present) return { field: field6, expected, actual: void 0, state: "unread" };
116333
116340
  return {
116334
- field: field5,
116341
+ field: field6,
116335
116342
  expected,
116336
116343
  actual,
116337
116344
  state: sameWriteValue(expected, actual) ? "match" : "mismatch"
@@ -116374,10 +116381,10 @@ function readKey(obj, keys) {
116374
116381
  function evaluateCampaignReadback(after, expected, readFailed) {
116375
116382
  if (readFailed || !after) return { verification: "unknown", checks: [] };
116376
116383
  const checks = [];
116377
- const push = (field5, expectedValue, keys) => {
116384
+ const push = (field6, expectedValue, keys) => {
116378
116385
  if (expectedValue === void 0) return;
116379
116386
  const found = readKey(after, keys);
116380
- checks.push(fieldCheck(field5, expectedValue, found.value, found.present));
116387
+ checks.push(fieldCheck(field6, expectedValue, found.value, found.present));
116381
116388
  };
116382
116389
  push("name", expected.name, ["name", "Name"]);
116383
116390
  push("statusV2", expected.statusV2, ["statusV2", "StatusV2"]);
@@ -117339,7 +117346,7 @@ function cloneKeywordBlockShell(block) {
117339
117346
  delete shell["matchTypeV2"];
117340
117347
  return shell;
117341
117348
  }
117342
- function splitKeywordsForBatchJobBlockIfMixed(block, path60, warnings) {
117349
+ function splitKeywordsForBatchJobBlockIfMixed(block, path61, warnings) {
117343
117350
  const declaredUi = matchTypeV2ToUi(readBlockMatchTypeRaw(block));
117344
117351
  const entries = collectKeywordEntriesFromBlock(block);
117345
117352
  if (entries.length === 0) return [block];
@@ -117358,7 +117365,7 @@ function splitKeywordsForBatchJobBlockIfMixed(block, path60, warnings) {
117358
117365
  (ui) => matchTypeUiToV2(ui)
117359
117366
  );
117360
117367
  warnings.push(
117361
- `${path60} \u542B\u591A\u79CD\u5339\u914D\u7C7B\u578B\uFF0C\u5DF2\u81EA\u52A8\u62C6\u5206\u4E3A ${groups.size} \u4E2A KeywordsForBatchJob \u5757\uFF08${labels.join("\u3001")}\uFF09`
117368
+ `${path61} \u542B\u591A\u79CD\u5339\u914D\u7C7B\u578B\uFF0C\u5DF2\u81EA\u52A8\u62C6\u5206\u4E3A ${groups.size} \u4E2A KeywordsForBatchJob \u5757\uFF08${labels.join("\u3001")}\uFF09`
117362
117369
  );
117363
117370
  const shell = cloneKeywordBlockShell(block);
117364
117371
  const splitBlocks = [];
@@ -117378,16 +117385,16 @@ function splitKeywordsForBatchJobBlockIfMixed(block, path60, warnings) {
117378
117385
  }
117379
117386
  return splitBlocks;
117380
117387
  }
117381
- function validateKeywordCore(core, path60, errors, lengthViolations) {
117388
+ function validateKeywordCore(core, path61, errors, lengthViolations) {
117382
117389
  const trimmed = core.trim();
117383
117390
  if (!trimmed) {
117384
- errors.push(`${path60} \u5173\u952E\u8BCD\u8BCD\u5E72\u4E0D\u80FD\u4E3A\u7A7A`);
117391
+ errors.push(`${path61} \u5173\u952E\u8BCD\u8BCD\u5E72\u4E0D\u80FD\u4E3A\u7A7A`);
117385
117392
  return false;
117386
117393
  }
117387
117394
  if (trimmed.length > GOOGLE_KEYWORD_MAX_CORE_LENGTH) {
117388
117395
  if (lengthViolations) {
117389
117396
  pushLengthViolation(lengthViolations, {
117390
- path: path60,
117397
+ path: path61,
117391
117398
  field: "KeywordText",
117392
117399
  kind: "keyword_core",
117393
117400
  limit: GOOGLE_KEYWORD_MAX_CORE_LENGTH,
@@ -117397,13 +117404,13 @@ function validateKeywordCore(core, path60, errors, lengthViolations) {
117397
117404
  });
117398
117405
  }
117399
117406
  errors.push(
117400
- `${path60} \u5173\u952E\u8BCD\u8BCD\u5E72\u8D85\u8FC7 ${GOOGLE_KEYWORD_MAX_CORE_LENGTH} \u5B57\u7B26\uFF08\u5F53\u524D ${trimmed.length}\uFF09\uFF1A"${trimmed}"`
117407
+ `${path61} \u5173\u952E\u8BCD\u8BCD\u5E72\u8D85\u8FC7 ${GOOGLE_KEYWORD_MAX_CORE_LENGTH} \u5B57\u7B26\uFF08\u5F53\u524D ${trimmed.length}\uFF09\uFF1A"${trimmed}"`
117401
117408
  );
117402
117409
  return false;
117403
117410
  }
117404
117411
  if (!VALID_CORE_REGEX.test(trimmed)) {
117405
117412
  errors.push(
117406
- `${path60} \u542B Google \u4E0D\u5141\u8BB8\u7684\u5B57\u7B26\uFF08\u8BCD\u5E72\u4EC5\u5141\u8BB8\u5B57\u6BCD/\u6570\u5B57/\u7A7A\u683C/\u8FDE\u5B57\u7B26/\u53E5\u70B9\uFF09\uFF1A"${trimmed.slice(0, 40)}${trimmed.length > 40 ? "\u2026" : ""}"`
117413
+ `${path61} \u542B Google \u4E0D\u5141\u8BB8\u7684\u5B57\u7B26\uFF08\u8BCD\u5E72\u4EC5\u5141\u8BB8\u5B57\u6BCD/\u6570\u5B57/\u7A7A\u683C/\u8FDE\u5B57\u7B26/\u53E5\u70B9\uFF09\uFF1A"${trimmed.slice(0, 40)}${trimmed.length > 40 ? "\u2026" : ""}"`
117407
117414
  );
117408
117415
  return false;
117409
117416
  }
@@ -117460,10 +117467,10 @@ function canonicalizeKeywordBatchBlock(block, resolvedMatchV2, normalizedTexts,
117460
117467
  }
117461
117468
  }
117462
117469
  }
117463
- function pushKeywordAutoFixWarning(warnings, path60, fieldLabel, trimmedRaw, formatted, declaredUi, beforeUi, matchType, inferredMatchType) {
117470
+ function pushKeywordAutoFixWarning(warnings, path61, fieldLabel, trimmedRaw, formatted, declaredUi, beforeUi, matchType, inferredMatchType) {
117464
117471
  if (inferredMatchType) {
117465
117472
  warnings.push(
117466
- `${path60}.${fieldLabel} \u672A\u6307\u5B9A MatchTypeV2\uFF0C\u5DF2\u6309\u8BCD\u9762\u63A8\u65AD\u4E3A ${matchTypeUiToV2(matchType)}`
117473
+ `${path61}.${fieldLabel} \u672A\u6307\u5B9A MatchTypeV2\uFF0C\u5DF2\u6309\u8BCD\u9762\u63A8\u65AD\u4E3A ${matchTypeUiToV2(matchType)}`
117467
117474
  );
117468
117475
  return false;
117469
117476
  }
@@ -117472,16 +117479,16 @@ function pushKeywordAutoFixWarning(warnings, path60, fieldLabel, trimmedRaw, for
117472
117479
  }
117473
117480
  if (declaredUi && beforeUi !== declaredUi) {
117474
117481
  warnings.push(
117475
- `${path60}.${fieldLabel} MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u4E0E\u8BCD\u9762\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`
117482
+ `${path61}.${fieldLabel} MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u4E0E\u8BCD\u9762\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`
117476
117483
  );
117477
117484
  return false;
117478
117485
  }
117479
117486
  if (formatted !== trimmedRaw) {
117480
- warnings.push(`${path60}.${fieldLabel} \u5DF2\u81EA\u52A8\u4FEE\u590D\u8BCD\u9762\uFF1A${trimmedRaw} \u2192 ${formatted}`);
117487
+ warnings.push(`${path61}.${fieldLabel} \u5DF2\u81EA\u52A8\u4FEE\u590D\u8BCD\u9762\uFF1A${trimmedRaw} \u2192 ${formatted}`);
117481
117488
  }
117482
117489
  return false;
117483
117490
  }
117484
- function normalizeKeywordTextList(texts, matchTypeRaw, path60, fieldLabel, errors, warnings, lengthViolations) {
117491
+ function normalizeKeywordTextList(texts, matchTypeRaw, path61, fieldLabel, errors, warnings, lengthViolations) {
117485
117492
  const declaredUi = matchTypeV2ToUi(matchTypeRaw);
117486
117493
  const normalized = [];
117487
117494
  const seen = /* @__PURE__ */ new Set();
@@ -117490,7 +117497,7 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path60, fieldLabel, error
117490
117497
  for (let k = 0; k < texts.length; k++) {
117491
117498
  const raw = texts[k];
117492
117499
  if (typeof raw !== "string" || !raw.trim()) {
117493
- errors.push(`${path60}.${fieldLabel}[${k}] \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
117500
+ errors.push(`${path61}.${fieldLabel}[${k}] \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
117494
117501
  continue;
117495
117502
  }
117496
117503
  const trimmedRaw = collapseDuplicateSpacesInKeywordText(raw.trim());
@@ -117501,7 +117508,7 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path60, fieldLabel, error
117501
117508
  );
117502
117509
  if (pushKeywordAutoFixWarning(
117503
117510
  warnings,
117504
- path60,
117511
+ path61,
117505
117512
  fieldLabel,
117506
117513
  trimmedRaw,
117507
117514
  formatted,
@@ -117513,11 +117520,11 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path60, fieldLabel, error
117513
117520
  bareWrapped++;
117514
117521
  }
117515
117522
  const core = unwrapKeywordDisplayTextForEdit(formatted);
117516
- if (!validateKeywordCore(core, `${path60}.${fieldLabel}[${k}]`, errors, lengthViolations))
117523
+ if (!validateKeywordCore(core, `${path61}.${fieldLabel}[${k}]`, errors, lengthViolations))
117517
117524
  continue;
117518
117525
  const dedupeKey = `${matchTypeUiToV2(matchType)}:${core.toLowerCase()}`;
117519
117526
  if (seen.has(dedupeKey)) {
117520
- warnings.push(`${path60}.${fieldLabel}[${k}] \u4E0E\u540C\u7EC4\u91CD\u590D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${formatted}`);
117527
+ warnings.push(`${path61}.${fieldLabel}[${k}] \u4E0E\u540C\u7EC4\u91CD\u590D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${formatted}`);
117521
117528
  continue;
117522
117529
  }
117523
117530
  seen.add(dedupeKey);
@@ -117526,17 +117533,17 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path60, fieldLabel, error
117526
117533
  }
117527
117534
  if (bareWrapped > 0 && declaredUi) {
117528
117535
  warnings.push(
117529
- `${path60}.${fieldLabel}\uFF1A${bareWrapped} \u4E2A\u88F8\u8BCD\u5DF2\u6309 MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u81EA\u52A8\u4FEE\u590D\uFF08\u8865\u5168${declaredUi === "Exact" ? " [ ]" : "\u5F15\u53F7"}\uFF0C\u9884\u671F\u884C\u4E3A\uFF09`
117536
+ `${path61}.${fieldLabel}\uFF1A${bareWrapped} \u4E2A\u88F8\u8BCD\u5DF2\u6309 MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u81EA\u52A8\u4FEE\u590D\uFF08\u8865\u5168${declaredUi === "Exact" ? " [ ]" : "\u5F15\u53F7"}\uFF0C\u9884\u671F\u884C\u4E3A\uFF09`
117530
117537
  );
117531
117538
  }
117532
117539
  return { normalized, resolvedUi };
117533
117540
  }
117534
- function normalizeKeywordsForBatchJobBlock(block, path60, errors, warnings, lengthViolations) {
117541
+ function normalizeKeywordsForBatchJobBlock(block, path61, errors, warnings, lengthViolations) {
117535
117542
  const matchTypeRaw = readBlockMatchTypeRaw(block);
117536
117543
  const declaredUi = matchTypeV2ToUi(matchTypeRaw);
117537
117544
  if (matchTypeRaw !== void 0 && declaredUi === null) {
117538
117545
  errors.push(
117539
- `${path60}.MatchTypeV2 \u65E0\u6548\uFF08${String(matchTypeRaw)}\uFF09\uFF0C\u5408\u6CD5\u503C\uFF1ABROAD | PHRASE | EXACT`
117546
+ `${path61}.MatchTypeV2 \u65E0\u6548\uFF08${String(matchTypeRaw)}\uFF09\uFF0C\u5408\u6CD5\u503C\uFF1ABROAD | PHRASE | EXACT`
117540
117547
  );
117541
117548
  return;
117542
117549
  }
@@ -117551,7 +117558,7 @@ function normalizeKeywordsForBatchJobBlock(block, path60, errors, warnings, leng
117551
117558
  const result = normalizeKeywordTextList(
117552
117559
  texts,
117553
117560
  matchTypeRaw,
117554
- path60,
117561
+ path61,
117555
117562
  "KeywordText",
117556
117563
  errors,
117557
117564
  warnings,
@@ -117560,7 +117567,7 @@ function normalizeKeywordsForBatchJobBlock(block, path60, errors, warnings, leng
117560
117567
  normalizedTexts = result.normalized;
117561
117568
  if (result.resolvedUi) resolvedUi = result.resolvedUi;
117562
117569
  if (normalizedTexts.length === 0 && texts.length > 0) {
117563
- errors.push(`${path60}.KeywordText \u7ECF\u6821\u9A8C\u540E\u65E0\u6709\u6548\u5173\u952E\u8BCD\uFF0C\u8BF7\u4FEE\u6B63\u8BCD\u9762\u6216 MatchTypeV2`);
117570
+ errors.push(`${path61}.KeywordText \u7ECF\u6821\u9A8C\u540E\u65E0\u6709\u6548\u5173\u952E\u8BCD\uFF0C\u8BF7\u4FEE\u6B63\u8BCD\u9762\u6216 MatchTypeV2`);
117564
117571
  }
117565
117572
  }
117566
117573
  if (hasItems && items3) {
@@ -117568,12 +117575,12 @@ function normalizeKeywordsForBatchJobBlock(block, path60, errors, warnings, leng
117568
117575
  for (let k = 0; k < items3.length; k++) {
117569
117576
  const item = items3[k];
117570
117577
  if (!item || typeof item !== "object") {
117571
- errors.push(`${path60}.Items[${k}] \u5FC5\u987B\u662F\u5BF9\u8C61`);
117578
+ errors.push(`${path61}.Items[${k}] \u5FC5\u987B\u662F\u5BF9\u8C61`);
117572
117579
  continue;
117573
117580
  }
117574
117581
  const raw = readItemText(item);
117575
117582
  if (raw === null || !raw.trim()) {
117576
- errors.push(`${path60}.Items[${k}].Text \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
117583
+ errors.push(`${path61}.Items[${k}].Text \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
117577
117584
  continue;
117578
117585
  }
117579
117586
  const trimmedRaw = collapseDuplicateSpacesInKeywordText(raw.trim());
@@ -117584,7 +117591,7 @@ function normalizeKeywordsForBatchJobBlock(block, path60, errors, warnings, leng
117584
117591
  );
117585
117592
  if (pushKeywordAutoFixWarning(
117586
117593
  warnings,
117587
- path60,
117594
+ path61,
117588
117595
  `Items[${k}].Text`,
117589
117596
  trimmedRaw,
117590
117597
  formatted,
@@ -117593,14 +117600,14 @@ function normalizeKeywordsForBatchJobBlock(block, path60, errors, warnings, leng
117593
117600
  matchType,
117594
117601
  inferredMatchType
117595
117602
  )) {
117596
- warnings.push(`${path60}.Items[${k}].Text \u5DF2\u6309\u5757\u7EA7\u5339\u914D\u7C7B\u578B\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`);
117603
+ warnings.push(`${path61}.Items[${k}].Text \u5DF2\u6309\u5757\u7EA7\u5339\u914D\u7C7B\u578B\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`);
117597
117604
  }
117598
117605
  const core = unwrapKeywordDisplayTextForEdit(formatted);
117599
- if (!validateKeywordCore(core, `${path60}.Items[${k}].Text`, errors, lengthViolations))
117606
+ if (!validateKeywordCore(core, `${path61}.Items[${k}].Text`, errors, lengthViolations))
117600
117607
  continue;
117601
117608
  const dedupeKey = `${matchTypeUiToV2(matchType)}:${core.toLowerCase()}`;
117602
117609
  if (seen.has(dedupeKey)) {
117603
- warnings.push(`${path60}.Items[${k}].Text \u4E0E\u540C\u7EC4\u91CD\u590D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${formatted}`);
117610
+ warnings.push(`${path61}.Items[${k}].Text \u4E0E\u540C\u7EC4\u91CD\u590D\uFF0C\u5DF2\u8DF3\u8FC7\uFF1A${formatted}`);
117604
117611
  continue;
117605
117612
  }
117606
117613
  seen.add(dedupeKey);
@@ -117746,16 +117753,16 @@ function warnIfNegativeKeywordsInPositiveKeywords(campaign, warnings) {
117746
117753
  const raw = texts[ki];
117747
117754
  if (typeof raw !== "string" || !raw.trim()) continue;
117748
117755
  const core = normalizeKeywordCoreForNegativeCheck(raw);
117749
- const path60 = `campaign.AdGroupsForBatchJob[${gi}].KeywordsForBatchJob[${bi}].KeywordText[${ki}]`;
117756
+ const path61 = `campaign.AdGroupsForBatchJob[${gi}].KeywordsForBatchJob[${bi}].KeywordText[${ki}]`;
117750
117757
  if (plannedNegCores.has(core)) {
117751
117758
  warnings.push(
117752
- `${path60} \u8BCD\u9762\u300C${raw}\u300D\u5DF2\u51FA\u73B0\u5728 campaign.NegativeKeywordsForBatchJob\uFF0C\u4E0D\u5E94\u91CD\u590D\u5199\u5165\u6B63\u5411 KeywordsForBatchJob\uFF1B\u5426\u8BCD\u53EA\u653E NegativeKeywordsForBatchJob`
117759
+ `${path61} \u8BCD\u9762\u300C${raw}\u300D\u5DF2\u51FA\u73B0\u5728 campaign.NegativeKeywordsForBatchJob\uFF0C\u4E0D\u5E94\u91CD\u590D\u5199\u5165\u6B63\u5411 KeywordsForBatchJob\uFF1B\u5426\u8BCD\u53EA\u653E NegativeKeywordsForBatchJob`
117753
117760
  );
117754
117761
  continue;
117755
117762
  }
117756
117763
  if (looksLikeStandaloneNegativeKeyword(core)) {
117757
117764
  warnings.push(
117758
- `${path60} \u8BCD\u9762\u300C${raw}\u300D\u7591\u4F3C\u5426\u5B9A\u5173\u952E\u8BCD\uFF08\u5E38\u89C1\u5426\u8BCD\u8BCD\u6839\uFF09\uFF0C\u5E94\u5199\u5165 campaign.NegativeKeywordsForBatchJob\uFF08MatchTypeV2: BROAD\uFF09\uFF0C\u52FF\u653E\u5165 KeywordsForBatchJob`
117765
+ `${path61} \u8BCD\u9762\u300C${raw}\u300D\u7591\u4F3C\u5426\u5B9A\u5173\u952E\u8BCD\uFF08\u5E38\u89C1\u5426\u8BCD\u8BCD\u6839\uFF09\uFF0C\u5E94\u5199\u5165 campaign.NegativeKeywordsForBatchJob\uFF08MatchTypeV2: BROAD\uFF09\uFF0C\u52FF\u653E\u5165 KeywordsForBatchJob`
117759
117766
  );
117760
117767
  }
117761
117768
  }
@@ -118095,46 +118102,46 @@ function validateRsaDisplayPath(prefix, ad, errors, lengthViolations) {
118095
118102
  `${prefix} \u68C0\u6D4B\u5230\u5C0F\u5199 path2="${String(ad["path2"])}"\uFF0C\u540E\u7AEF\u5951\u7EA6\u5B57\u6BB5\u4E3A Path2\uFF08PascalCase\uFF09\uFF0C\u5F53\u524D\u63D0\u4EA4\u4E0D\u4F1A\u751F\u6548`
118096
118103
  );
118097
118104
  }
118098
- for (const [field5, label2, example] of [
118105
+ for (const [field6, label2, example] of [
118099
118106
  ["Path1", "\u663E\u793A\u8DEF\u5F84\u7B2C 1 \u6BB5", '"Path1": "products"'],
118100
118107
  ["Path2", "\u663E\u793A\u8DEF\u5F84\u7B2C 2 \u6BB5", '"Path2": "steel"']
118101
118108
  ]) {
118102
- const raw = ad[field5];
118109
+ const raw = ad[field6];
118103
118110
  if (raw === void 0) {
118104
118111
  pushErr2(
118105
118112
  errors,
118106
- `${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}`
118113
+ `${prefix}.${field6} \u5B57\u6BB5\u7F3A\u5931\uFF08RSA \u5FC5\u586B\uFF09\u3002${label2}\uFF0C\u5C55\u793A\u4E3A finalUrl \u57DF\u540D\u540E\u7684\u8DEF\u5F84\u6BB5\uFF08\u226415 \u5B57\u7B26\uFF0CCJK \u6309 2 \u8BA1\uFF09\u3002${RSA_PATH_BACKEND_HINT}\u3002${jsonHint}\u3002\u793A\u4F8B\uFF1A${example}`
118107
118114
  );
118108
118115
  continue;
118109
118116
  }
118110
118117
  if (raw === null) {
118111
118118
  pushErr2(
118112
118119
  errors,
118113
- `${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}`
118120
+ `${prefix}.${field6} \u4E3A null\uFF08RSA \u5FC5\u586B\uFF0C\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u53EF\u586B ""\uFF09\u3002${RSA_PATH_BACKEND_HINT}\u3002${jsonHint}\u3002\u793A\u4F8B\uFF1A${example}`
118114
118121
  );
118115
118122
  continue;
118116
118123
  }
118117
118124
  if (typeof raw !== "string") {
118118
- pushErr2(errors, `${prefix}.${field5} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u7C7B\u578B\u4E3A ${typeof raw}\u3002${jsonHint}`);
118125
+ pushErr2(errors, `${prefix}.${field6} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u7C7B\u578B\u4E3A ${typeof raw}\u3002${jsonHint}`);
118119
118126
  continue;
118120
118127
  }
118121
118128
  const len = calcGoogleCharLength(raw);
118122
118129
  if (len > 15) {
118123
118130
  pushLengthViolation(lengthViolations, {
118124
- path: `${prefix}.${field5}`,
118125
- field: field5,
118131
+ path: `${prefix}.${field6}`,
118132
+ field: field6,
118126
118133
  kind: "rsa_path",
118127
118134
  limit: 15,
118128
118135
  actual: len,
118129
118136
  countMode: "google",
118130
118137
  text: raw
118131
118138
  });
118132
- pushErr2(errors, `${prefix}.${field5} \u8D85\u8FC7 15 \u5B57\u7B26\uFF08\u5F53\u524D ${len}\uFF0CCJK \u6309 2 \u8BA1\uFF09\uFF1A"${raw}"`);
118139
+ pushErr2(errors, `${prefix}.${field6} \u8D85\u8FC7 15 \u5B57\u7B26\uFF08\u5F53\u524D ${len}\uFF0CCJK \u6309 2 \u8BA1\uFF09\uFF1A"${raw}"`);
118133
118140
  }
118134
118141
  if (raw.length > 0 && !PATH_SEGMENT_REGEX.test(raw)) {
118135
118142
  pushErr2(
118136
118143
  errors,
118137
- `${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}"`
118144
+ `${prefix}.${field6} \u542B\u975E\u6CD5\u5B57\u7B26\u6216\u683C\u5F0F\uFF08\u4EC5\u5141\u8BB8\u5C0F\u5199 a-z\u30010-9\u3001\u8FDE\u5B57\u7B26\uFF0C\u4E14\u4E0D\u80FD\u4EE5\u8FDE\u5B57\u7B26\u5F00\u5934/\u7ED3\u5C3E\uFF09\uFF1A"${raw}"`
118138
118145
  );
118139
118146
  }
118140
118147
  }
@@ -118173,10 +118180,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
118173
118180
  for (let i = 0; i < headlines.length; i++) {
118174
118181
  const len = calcGoogleCharLength(headlines[i]);
118175
118182
  if (len > 30) {
118176
- const field5 = headlineFields[i] ?? `headline[${i}]`;
118183
+ const field6 = headlineFields[i] ?? `headline[${i}]`;
118177
118184
  pushLengthViolation(lengthViolations, {
118178
- path: `${prefix}.${field5}`,
118179
- field: field5,
118185
+ path: `${prefix}.${field6}`,
118186
+ field: field6,
118180
118187
  kind: "rsa_headline",
118181
118188
  limit: 30,
118182
118189
  actual: len,
@@ -118208,10 +118215,10 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
118208
118215
  for (let i = 0; i < descriptions.length; i++) {
118209
118216
  const len = calcGoogleCharLength(descriptions[i]);
118210
118217
  if (len > 90) {
118211
- const field5 = descriptionFields[i] ?? `description[${i}]`;
118218
+ const field6 = descriptionFields[i] ?? `description[${i}]`;
118212
118219
  pushLengthViolation(lengthViolations, {
118213
- path: `${prefix}.${field5}`,
118214
- field: field5,
118220
+ path: `${prefix}.${field6}`,
118221
+ field: field6,
118215
118222
  kind: "rsa_description",
118216
118223
  limit: 90,
118217
118224
  actual: len,
@@ -118664,6 +118671,8 @@ async function resolveCampaignCustomerName(cfg, config, verbose) {
118664
118671
 
118665
118672
  // src/commands/ad/campaign.ts
118666
118673
  var CAMPAIGN_READBACK_WAIT_MS = 1e3;
118674
+ var CAMPAIGN_LIST_TIMEOUT_MS = 6e4;
118675
+ var CAMPAIGN_LIST_CONCURRENCY = 8;
118667
118676
  function formatGoogleCampaignListStatus(row) {
118668
118677
  const raw = row.statusV2;
118669
118678
  if (raw == null || String(raw).trim() === "") return "-";
@@ -118723,7 +118732,141 @@ async function emitReusedDigestCampaignTypes(opts, hit) {
118723
118732
  }
118724
118733
  console.log(JSON.stringify(payload));
118725
118734
  }
118735
+ function parseCampaignAccountIds(raw) {
118736
+ const parts = (raw ?? "").split(/[,,]+/).map((part) => part.trim()).filter((part) => part !== "");
118737
+ if (parts.length === 0) {
118738
+ console.error("\n\u274C -a/--account \u4E0D\u80FD\u4E3A\u7A7A\u3002\u591A\u4E2A\u8D26\u6237\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4E0D\u8981\u5199 shell \u5FAA\u73AF\u3002\n");
118739
+ process.exit(1);
118740
+ }
118741
+ const ids = [];
118742
+ const seen = /* @__PURE__ */ new Set();
118743
+ for (const part of parts) {
118744
+ const id = normalizeNumericMediaCustomerId(part);
118745
+ if (!id) {
118746
+ console.error(
118747
+ `
118748
+ \u274C account\uFF08customerId\uFF09\u65E0\u6548\uFF1A${part}
118749
+ \u591A\u4E2A\u8D26\u6237\u5199\u6210 -a id1,id2,id3\uFF0C\u6BCF\u4E2A ID \u662F\u7EAF\u6570\u5B57\u6216\u5E26\u8FDE\u5B57\u7B26\u7684 CID\u3002
118750
+ `
118751
+ );
118752
+ process.exit(1);
118753
+ }
118754
+ if (seen.has(id)) continue;
118755
+ seen.add(id);
118756
+ ids.push(id);
118757
+ }
118758
+ return ids;
118759
+ }
118760
+ function campaignListSnapshotFile(snapshotDir, accountId) {
118761
+ const section = normalizeCliSnapshotSection(`ad-campaigns-${accountId}`);
118762
+ const stem = applyIdSuffix(section, slugifyIdSuffix(accountId));
118763
+ return path17.join(path17.resolve(snapshotDir), `${stem}.json`);
118764
+ }
118765
+ async function fileExists(file) {
118766
+ try {
118767
+ await fs12.access(file);
118768
+ return true;
118769
+ } catch {
118770
+ return false;
118771
+ }
118772
+ }
118773
+ function campaignListPayload(data) {
118774
+ const rawItems = data.data ?? [];
118775
+ const items3 = rawItems.map((item) => ({
118776
+ ...item,
118777
+ budget: toDisplayMoney(item.budget),
118778
+ targetSpendBidCeilingYuan: toDisplayMoney(item["targetSpend_BidCeilingAmount"]),
118779
+ targetCpaAmountYuan: toDisplayMoney(item["targetCpa_BidingAmount"]),
118780
+ statusDisplay: formatGoogleCampaignListStatus(item)
118781
+ }));
118782
+ const n = items3.length;
118783
+ const payload = stripLegacyGoogleFieldsIfV2Present({
118784
+ ...wrapListJson({ page: 1, pageSize: Math.max(n, 1), total: n, items: items3 }),
118785
+ code: data.code ?? null,
118786
+ message: data.message ?? null
118787
+ });
118788
+ return { items: items3, payload };
118789
+ }
118790
+ async function fetchCampaignList(opts, account, config) {
118791
+ const googleApiUrl = requireGoogleApi(config);
118792
+ const url = campaignListUrl(googleApiUrl, account, opts.startDate, opts.endDate, opts.fresh);
118793
+ const data = await apiFetch2(
118794
+ url,
118795
+ config,
118796
+ {},
118797
+ opts.verbose,
118798
+ CAMPAIGN_LIST_TIMEOUT_MS
118799
+ );
118800
+ return campaignListPayload(data);
118801
+ }
118802
+ async function runAdCampaignListBatch(opts) {
118803
+ const jsonOut = opts.jsonOut?.trim() ?? "";
118804
+ if (!jsonOut || jsonOut.toLowerCase().endsWith(".json")) {
118805
+ console.error(
118806
+ "\n\u274C \u591A\u4E2A\u8D26\u6237\u5FC5\u987B --json-out <\u76EE\u5F55>\u3002\n \u4F8B\uFF1Asiluzan-tso ad campaigns -a id1,id2 --start <\u65E5\u671F> --end <\u65E5\u671F> --json-out ./camp\n \u4E0D\u8981\u5199\u6210\u5355\u4E2A .json\uFF0C\u4E5F\u4E0D\u8981 while/for \u9010\u6237\u8C03\u7528\u3002\n"
118807
+ );
118808
+ process.exit(1);
118809
+ }
118810
+ const config = loadConfig(opts.token);
118811
+ const budget = resolveTimeBudgetOrExit(void 0);
118812
+ const pending = [];
118813
+ for (const account of opts.accounts) {
118814
+ if (!opts.fresh && await fileExists(campaignListSnapshotFile(jsonOut, account))) continue;
118815
+ pending.push(account);
118816
+ }
118817
+ const failures = [];
118818
+ const scan = await runAccountsWithBudget({
118819
+ ids: pending,
118820
+ concurrency: CAMPAIGN_LIST_CONCURRENCY,
118821
+ budget,
118822
+ run: async (account) => {
118823
+ try {
118824
+ const { payload } = await fetchCampaignList(opts, account, config);
118825
+ await writeCliJsonSnapshot({
118826
+ snapshotDir: jsonOut,
118827
+ section: `ad-campaigns-${account}`,
118828
+ commandHint: account,
118829
+ payload,
118830
+ idSuffix: account
118831
+ });
118832
+ } catch (err) {
118833
+ const message = err instanceof Error ? err.message : String(err);
118834
+ failures.push({ account, error: message.replace(/\s+/g, " ").trim().slice(0, 300) });
118835
+ }
118836
+ }
118837
+ });
118838
+ const summary = {
118839
+ kind: "siluzan-tso-ad-campaigns-batch",
118840
+ ok: failures.length === 0 && scan.completed,
118841
+ state: scan.completed ? "succeeded" : "paused",
118842
+ accounts: opts.accounts.length,
118843
+ skippedExisting: opts.accounts.length - pending.length,
118844
+ fetched: scan.finished - failures.length,
118845
+ failed: failures.length,
118846
+ failures,
118847
+ snapshotDir: path17.resolve(jsonOut),
118848
+ filePattern: "ad-campaigns-<accountId>.json"
118849
+ };
118850
+ if (!scan.completed) {
118851
+ console.log(
118852
+ JSON.stringify({
118853
+ ...summary,
118854
+ resumeCommand: ["siluzan-tso", ...process.argv.slice(2)].join(" "),
118855
+ agentHint: "\u65F6\u95F4\u9884\u7B97\u5185\u6CA1\u62C9\u5B8C\u3002\u5DF2\u843D\u76D8\u7684\u8D26\u6237\u4F1A\u5728\u4E0B\u6B21\u8DF3\u8FC7\u3002\u539F\u6837\u518D\u6267\u884C resumeCommand\uFF0C\u4E0D\u8981\u6539\u6210 while/for \u9010\u6237\u8C03\u7528\u3002"
118856
+ })
118857
+ );
118858
+ process.exit(EXIT_SCAN_PAUSED);
118859
+ }
118860
+ console.log(JSON.stringify(summary));
118861
+ if (pending.length > 0 && failures.length === pending.length) process.exit(1);
118862
+ }
118726
118863
  async function runAdCampaigns(opts) {
118864
+ const accountIds = parseCampaignAccountIds(opts.account);
118865
+ if (accountIds.length > 1) {
118866
+ await runAdCampaignListBatch({ ...opts, account: accountIds.join(","), accounts: accountIds });
118867
+ return;
118868
+ }
118869
+ opts = { ...opts, account: accountIds[0] ?? "" };
118727
118870
  opts = withResolvedAdAccount(opts);
118728
118871
  if (!opts.live) {
118729
118872
  const hit = findDigestCampaignTypes(process.cwd(), opts.account);
@@ -118733,38 +118876,23 @@ async function runAdCampaigns(opts) {
118733
118876
  }
118734
118877
  }
118735
118878
  const config = loadConfig(opts.token);
118736
- const googleApiUrl = requireGoogleApi(config);
118737
- const url = campaignListUrl(googleApiUrl, opts.account, opts.startDate, opts.endDate, opts.fresh);
118738
- let data;
118879
+ let items3;
118880
+ let campaignListPayload2;
118739
118881
  try {
118740
- data = await apiFetch2(url, config, {}, opts.verbose);
118882
+ const loaded = await fetchCampaignList(opts, opts.account, config);
118883
+ items3 = loaded.items;
118884
+ campaignListPayload2 = loaded.payload;
118741
118885
  } catch (err) {
118742
118886
  console.error(`
118743
118887
  \u274C \u67E5\u8BE2\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
118744
118888
  `);
118745
118889
  process.exit(1);
118746
118890
  }
118747
- const rawItems = data.data ?? [];
118748
- const items3 = rawItems.map((item) => {
118749
- return {
118750
- ...item,
118751
- budget: toDisplayMoney(item.budget),
118752
- targetSpendBidCeilingYuan: toDisplayMoney(item["targetSpend_BidCeilingAmount"]),
118753
- targetCpaAmountYuan: toDisplayMoney(item["targetCpa_BidingAmount"]),
118754
- statusDisplay: formatGoogleCampaignListStatus(item)
118755
- };
118756
- });
118757
- const n = items3.length;
118758
- const campaignListPayload = stripLegacyGoogleFieldsIfV2Present({
118759
- ...wrapListJson({ page: 1, pageSize: Math.max(n, 1), total: n, items: items3 }),
118760
- code: data.code ?? null,
118761
- message: data.message ?? null
118762
- });
118763
118891
  if (await emitCliJsonOrSnapshot(opts, {
118764
118892
  section: `ad-campaigns-${opts.account}`,
118765
118893
  commandLabel: "ad campaigns",
118766
118894
  commandHint: opts.account,
118767
- payload: campaignListPayload,
118895
+ payload: campaignListPayload2,
118768
118896
  idSuffix: opts.account
118769
118897
  })) {
118770
118898
  return;
@@ -119974,8 +120102,8 @@ function normalizePlacementUrl(raw) {
119974
120102
  if (parts.length > 2) {
119975
120103
  throw new Error("\u7248\u4F4D\u7F51\u5740\u6700\u591A\u4E24\u7EA7\u8DEF\u5F84\uFF0C\u4F8B\u5982 http://www.domain.com/news/2024");
119976
120104
  }
119977
- const path60 = parts.length > 0 ? `/${parts.join("/")}` : "";
119978
- return `${url.protocol}//${host}${path60}`;
120105
+ const path61 = parts.length > 0 ? `/${parts.join("/")}` : "";
120106
+ return `${url.protocol}//${host}${path61}`;
119979
120107
  }
119980
120108
  var GROUP_LABEL = {
119981
120109
  sensitive: "\u654F\u611F\u5185\u5BB9",
@@ -120721,7 +120849,7 @@ async function runAdPmaxBrandsDetach(opts) {
120721
120849
  \u2705 \u5DF2\u4ECE\u7CFB\u5217 ${campaignId} \u5378\u4E0B\u54C1\u724C\u5217\u8868 ${criterionId}
120722
120850
  `);
120723
120851
  }
120724
- async function listCampaignRows(opts, path60, label2) {
120852
+ async function listCampaignRows(opts, path61, label2) {
120725
120853
  let campaignId;
120726
120854
  try {
120727
120855
  campaignId = requireCampaignId(opts.campaignId, label2);
@@ -120729,7 +120857,7 @@ async function listCampaignRows(opts, path60, label2) {
120729
120857
  fail(err, "\u53C2\u6570");
120730
120858
  }
120731
120859
  const { config, base: base2, account } = accountBase(opts);
120732
- const url = `${base2}/campaignmanagement/accounts/${account}/${path60}?campaignId=${campaignId}`;
120860
+ const url = `${base2}/campaignmanagement/accounts/${account}/${path61}?campaignId=${campaignId}`;
120733
120861
  let items3;
120734
120862
  try {
120735
120863
  items3 = unwrapItems(await apiFetch2(url, config, {}, opts.verbose));
@@ -120838,17 +120966,17 @@ async function runAdPmaxUrlsAdd(opts) {
120838
120966
  async function runAdPmaxUrlsRemove(opts) {
120839
120967
  await removeCampaignCriterion(opts, "pmax-urls", "\u7F51\u5740\u6392\u9664");
120840
120968
  }
120841
- async function removeCampaignCriterion(opts, path60, label2) {
120969
+ async function removeCampaignCriterion(opts, path61, label2) {
120842
120970
  let campaignId;
120843
120971
  let criterionId;
120844
120972
  try {
120845
- campaignId = requireCampaignId(opts.campaignId, path60);
120973
+ campaignId = requireCampaignId(opts.campaignId, path61);
120846
120974
  criterionId = requireDigits(opts.criterionId, "--criterion-id");
120847
120975
  } catch (err) {
120848
120976
  fail(err, "\u53C2\u6570");
120849
120977
  }
120850
120978
  const { config, base: base2, account } = accountBase(opts);
120851
- const url = `${base2}/campaignmanagement/accounts/${account}/${path60}/${criterionId}?campaignId=${campaignId}`;
120979
+ const url = `${base2}/campaignmanagement/accounts/${account}/${path61}/${criterionId}?campaignId=${campaignId}`;
120852
120980
  try {
120853
120981
  await apiDeleteRaw(url, config, { verbose: opts.verbose });
120854
120982
  } catch (err) {
@@ -122614,8 +122742,8 @@ init_cli_table();
122614
122742
  init_auth();
122615
122743
  init_cli_json_snapshot();
122616
122744
  init_shared();
122617
- import fs12 from "fs";
122618
- import path17 from "path";
122745
+ import fs13 from "fs";
122746
+ import path18 from "path";
122619
122747
 
122620
122748
  // src/commands/ad/campaign-extension-remediate.ts
122621
122749
  function shellArg(value) {
@@ -122759,7 +122887,7 @@ function buildBatchOperationSlots(cfg) {
122759
122887
  const campaign = asRecord3(cfg.campaign) ?? {};
122760
122888
  const names = Array.isArray(cfg.locations) ? cfg.locations : [];
122761
122889
  const slots = [];
122762
- const push = (kind, path60, label2) => slots.push({ index: slots.length, kind, path: path60, label: label2 });
122890
+ const push = (kind, path61, label2) => slots.push({ index: slots.length, kind, path: path61, label: label2 });
122763
122891
  push("campaign_budget", "campaign.Budget", "\u7CFB\u5217\u9884\u7B97");
122764
122892
  push("campaign", "campaign.Name", `\u7CFB\u5217\u300C${pickText(campaign, "Name", "name") || "\u2014"}\u300D`);
122765
122893
  pickArray(campaign, "targetedLocations", "TargetedLocations").forEach((loc, i) => {
@@ -123033,13 +123161,13 @@ function livePoolHasText(pool, text5) {
123033
123161
  function listPlannedRsaAssets(ad, groupPath, adIndex, adGroupName) {
123034
123162
  const base2 = `${groupPath}.AdsForBatchJob[${adIndex}]`;
123035
123163
  const out = [];
123036
- const push = (kind, field5, raw) => {
123164
+ const push = (kind, field6, raw) => {
123037
123165
  if (typeof raw !== "string" || !raw.trim()) return;
123038
123166
  out.push({
123039
- path: `${base2}.${field5}`,
123167
+ path: `${base2}.${field6}`,
123040
123168
  adGroupName,
123041
123169
  kind,
123042
- field: field5,
123170
+ field: field6,
123043
123171
  text: raw.trim()
123044
123172
  });
123045
123173
  };
@@ -123242,13 +123370,13 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123242
123370
  for (let ki = 0; ki < texts.length; ki++) {
123243
123371
  const t = texts[ki];
123244
123372
  if (typeof t !== "string" || !t.trim()) continue;
123245
- const path60 = `${groupPath}.KeywordsForBatchJob[${bi}].KeywordText[${ki}]`;
123373
+ const path61 = `${groupPath}.KeywordsForBatchJob[${bi}].KeywordText[${ki}]`;
123246
123374
  const key = keywordKey(t, matchTypeV2);
123247
123375
  const plannedContent = `\u8BCD\u9762: ${t} | \u5339\u914D: ${matchTypeV2}`;
123248
123376
  if (groupAbsent) {
123249
123377
  pushItem(items3, {
123250
123378
  layer: "keyword",
123251
- path: path60,
123379
+ path: path61,
123252
123380
  adGroupName: groupName,
123253
123381
  plannedContent,
123254
123382
  status: "skipped",
@@ -123260,7 +123388,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123260
123388
  if (!liveKwKeys.has(key)) {
123261
123389
  pushItem(items3, {
123262
123390
  layer: "keyword",
123263
- path: path60,
123391
+ path: path61,
123264
123392
  adGroupName: groupName,
123265
123393
  plannedContent,
123266
123394
  status: "missing",
@@ -123270,7 +123398,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123270
123398
  } else {
123271
123399
  pushItem(items3, {
123272
123400
  layer: "keyword",
123273
- path: path60,
123401
+ path: path61,
123274
123402
  adGroupName: groupName,
123275
123403
  plannedContent,
123276
123404
  status: "ok",
@@ -123290,7 +123418,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123290
123418
  for (let ai = 0; ai < ads.length; ai++) {
123291
123419
  const ad = asRecord4(ads[ai]);
123292
123420
  if (!ad) continue;
123293
- const path60 = `${groupPath}.AdsForBatchJob[${ai}]`;
123421
+ const path61 = `${groupPath}.AdsForBatchJob[${ai}]`;
123294
123422
  const primary = pickString2(ad["headlinePart1"], ad["AdTitle"]);
123295
123423
  const finalUrl = pickString2(ad["Finalurl"], ad["DestinationUrl"], ad["finalUrl"]);
123296
123424
  const rsaAssets = listPlannedRsaAssets(ad, groupPath, ai, groupName);
@@ -123299,7 +123427,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123299
123427
  if (groupAbsent) {
123300
123428
  pushItem(items3, {
123301
123429
  layer: "ad",
123302
- path: path60,
123430
+ path: path61,
123303
123431
  adGroupName: groupName,
123304
123432
  adLabel,
123305
123433
  plannedContent: primary ? `RSA \u9996\u6807\u9898: ${primary}${finalUrl ? ` | \u843D\u5730\u9875: ${finalUrl}` : ""}` : `AdsForBatchJob[${ai}]\uFF08\u7F3A\u5C11 headlinePart1\uFF09`,
@@ -123328,7 +123456,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123328
123456
  if (!primary) {
123329
123457
  pushItem(items3, {
123330
123458
  layer: "ad",
123331
- path: path60,
123459
+ path: path61,
123332
123460
  adGroupName: groupName,
123333
123461
  adLabel,
123334
123462
  plannedContent: `AdsForBatchJob[${ai}]\uFF08\u7F3A\u5C11 headlinePart1\uFF0C\u65E0\u6CD5\u6BD4\u5BF9\u6574\u6761 RSA\uFF09`,
@@ -123356,7 +123484,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123356
123484
  const rsaFound = matchedLive != null && liveAdHasHeadline(matchedLive, primary);
123357
123485
  pushItem(items3, {
123358
123486
  layer: "ad",
123359
- path: path60,
123487
+ path: path61,
123360
123488
  adGroupName: groupName,
123361
123489
  adLabel,
123362
123490
  plannedContent: `RSA \u9996\u6807\u9898: ${primary}${finalUrl ? ` | \u843D\u5730\u9875: ${finalUrl}` : ""}`,
@@ -123424,11 +123552,11 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123424
123552
  for (let ei = 0; ei < extBlocks.length; ei++) {
123425
123553
  const ext = asRecord4(extBlocks[ei]);
123426
123554
  const plannedContent = formatExtensionPlanned(ext);
123427
- const path60 = `campaign.ExtensionsForBatchJob[${ei}]`;
123555
+ const path61 = `campaign.ExtensionsForBatchJob[${ei}]`;
123428
123556
  if (campaignMissing) {
123429
123557
  pushItem(items3, {
123430
123558
  layer: "extension",
123431
- path: path60,
123559
+ path: path61,
123432
123560
  plannedContent,
123433
123561
  status: "skipped",
123434
123562
  liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u9644\u52A0\u4FE1\u606F\u6BD4\u5BF9",
@@ -123440,7 +123568,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123440
123568
  const remediateCommand = !found && ext && accountId && campaignId ? buildExtensionRemediateCommandLine({ accountId, campaignId, ext }) ?? void 0 : void 0;
123441
123569
  pushItem(items3, {
123442
123570
  layer: "extension",
123443
- path: path60,
123571
+ path: path61,
123444
123572
  plannedContent,
123445
123573
  status: found ? "ok" : "missing",
123446
123574
  liveNote: `\u7CFB\u5217\u7EA7\u9644\u52A0\u4FE1\u606F\u8D26\u6237\u5185 ${liveExt}/${plannedExt} \u6761`,
@@ -123467,11 +123595,11 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123467
123595
  if (!id) continue;
123468
123596
  const displayName = locationNames[li] || pickString2(loc["locationName"], loc["name"], loc["countryOrRegion"]) || "";
123469
123597
  const plannedContent = `locationId: ${id}${displayName ? ` | \u540D\u79F0: ${displayName}` : ""}`;
123470
- const path60 = `campaign.targetedLocations[${li}]`;
123598
+ const path61 = `campaign.targetedLocations[${li}]`;
123471
123599
  if (campaignMissing) {
123472
123600
  pushItem(items3, {
123473
123601
  layer: "location",
123474
- path: path60,
123602
+ path: path61,
123475
123603
  plannedContent,
123476
123604
  status: "skipped",
123477
123605
  liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u5730\u57DF\u6BD4\u5BF9",
@@ -123483,7 +123611,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123483
123611
  const remediateCommand = !found && accountId && campaignId ? buildGeoRemediateCommandLine({ accountId, campaignId, locationId: id }) : void 0;
123484
123612
  pushItem(items3, {
123485
123613
  layer: "location",
123486
- path: path60,
123614
+ path: path61,
123487
123615
  plannedContent,
123488
123616
  status: found ? "ok" : "missing",
123489
123617
  liveNote: `\u7CFB\u5217\u5DF2\u5B9A\u5411 ${liveLocIds.size}/${plannedLocCount} \u4E2A\u5730\u57DF`,
@@ -123503,12 +123631,12 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123503
123631
  const loc = asRecord4(plannedExcl[li]);
123504
123632
  const id = loc ? pickString2(loc["id"], loc["Id"]) : "";
123505
123633
  if (!id) continue;
123506
- const path60 = `campaign.excludedLocations[${li}]`;
123634
+ const path61 = `campaign.excludedLocations[${li}]`;
123507
123635
  const plannedContent = `\u6392\u9664 locationId: ${id}`;
123508
123636
  if (campaignMissing) {
123509
123637
  pushItem(items3, {
123510
123638
  layer: "excluded_location",
123511
- path: path60,
123639
+ path: path61,
123512
123640
  plannedContent,
123513
123641
  status: "skipped",
123514
123642
  liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u6392\u9664\u5730\u57DF\u6BD4\u5BF9",
@@ -123519,7 +123647,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
123519
123647
  const found = liveExclIds.has(id);
123520
123648
  pushItem(items3, {
123521
123649
  layer: "excluded_location",
123522
- path: path60,
123650
+ path: path61,
123523
123651
  plannedContent,
123524
123652
  status: found ? "ok" : "missing",
123525
123653
  liveNote: `\u7CFB\u5217\u5DF2\u6392\u9664 ${liveExclIds.size}/${plannedExclCount} \u4E2A\u5730\u57DF`,
@@ -124065,23 +124193,23 @@ function buildCampaignCreateStatusMarkdown(result, lang = "zh") {
124065
124193
  return lines.join("\n");
124066
124194
  }
124067
124195
  function resolveBatchDiffMdOutPath(opts) {
124068
- if (opts.mdOut?.trim()) return path17.resolve(opts.mdOut.trim());
124196
+ if (opts.mdOut?.trim()) return path18.resolve(opts.mdOut.trim());
124069
124197
  const fileName = `campaign-create-status-${opts.campaignId || "unknown"}.md`;
124070
124198
  if (opts.jsonOut?.trim()) {
124071
124199
  const jsonOut = opts.jsonOut.trim();
124072
- const abs = path17.resolve(jsonOut);
124200
+ const abs = path18.resolve(jsonOut);
124073
124201
  const looksLikeFile = /\.json$/i.test(jsonOut);
124074
124202
  if (looksLikeFile) {
124075
- return path17.join(path17.dirname(abs), fileName);
124203
+ return path18.join(path18.dirname(abs), fileName);
124076
124204
  }
124077
- return path17.join(abs, fileName);
124205
+ return path18.join(abs, fileName);
124078
124206
  }
124079
- return path17.resolve(fileName);
124207
+ return path18.resolve(fileName);
124080
124208
  }
124081
124209
  function writeCampaignCreateStatusMarkdown(result, mdPath, lang = "zh") {
124082
124210
  const reportMarkdown = buildCampaignCreateStatusMarkdown(result, lang);
124083
- fs12.mkdirSync(path17.dirname(mdPath), { recursive: true });
124084
- fs12.writeFileSync(mdPath, reportMarkdown, "utf8");
124211
+ fs13.mkdirSync(path18.dirname(mdPath), { recursive: true });
124212
+ fs13.writeFileSync(mdPath, reportMarkdown, "utf8");
124085
124213
  return { reportMarkdown, reportMarkdownFile: mdPath };
124086
124214
  }
124087
124215
  var USER_DELIVERY_MARKDOWN_BEGIN = "\u2500\u2500 BEGIN_USER_DELIVERY_MARKDOWN \uFF08\u5FC5\u987B\u539F\u6837\u7C98\u8D34\u5230\u5BF9\u7528\u6237\u7684\u4E0B\u4E00\u6761\u6D88\u606F\uFF1B\u7981\u6B62\u6458\u8981\u4EE3\u66FF\uFF1B\u4EA4\u4ED8\u4F18\u5148\u4E8E\u8865\u5EFA\uFF09\u2500\u2500";
@@ -124778,10 +124906,10 @@ function validateTextLengths(errors, lengthViolations, texts, arrayField, kind,
124778
124906
  texts.forEach((text5, i) => {
124779
124907
  const len = calcGoogleCharLength(text5);
124780
124908
  if (len > limit) {
124781
- const field5 = `${arrayField}[${i}]`;
124909
+ const field6 = `${arrayField}[${i}]`;
124782
124910
  pushLengthViolation(lengthViolations, {
124783
- path: field5,
124784
- field: field5,
124911
+ path: field6,
124912
+ field: field6,
124785
124913
  kind,
124786
124914
  limit,
124787
124915
  actual: len,
@@ -125199,8 +125327,8 @@ function pmaxChannelTypesUrl(googleApiUrl) {
125199
125327
  }
125200
125328
  function pmaxCampaignUrl(googleApiUrl, accountId, campaignId) {
125201
125329
  const base2 = googleApiUrl.replace(/\/$/, "");
125202
- const path60 = `${base2}/accounts/${accountId}/campaign/pmax`;
125203
- return campaignId ? `${path60}/${campaignId}` : path60;
125330
+ const path61 = `${base2}/accounts/${accountId}/campaign/pmax`;
125331
+ return campaignId ? `${path61}/${campaignId}` : path61;
125204
125332
  }
125205
125333
  function pmaxBrandAssetsUrl(googleApiUrl, accountId, campaignId) {
125206
125334
  return `${pmaxCampaignUrl(googleApiUrl, accountId, campaignId)}/brand-assets`;
@@ -125210,8 +125338,8 @@ function pmaxBrandGuidelinesEnableUrl(googleApiUrl, accountId, campaignId) {
125210
125338
  }
125211
125339
  function pmaxAssetGroupUrl(googleApiUrl, accountId, assetGroupId, suffix) {
125212
125340
  const base2 = googleApiUrl.replace(/\/$/, "");
125213
- const path60 = `${base2}/accounts/${accountId}/campaign/pmax/asset-group/${assetGroupId}`;
125214
- return suffix ? `${path60}/${suffix.replace(/^\//, "")}` : path60;
125341
+ const path61 = `${base2}/accounts/${accountId}/campaign/pmax/asset-group/${assetGroupId}`;
125342
+ return suffix ? `${path61}/${suffix.replace(/^\//, "")}` : path61;
125215
125343
  }
125216
125344
  function pmaxCampaignAssetGroupUrl(googleApiUrl, accountId, campaignId) {
125217
125345
  const base2 = googleApiUrl.replace(/\/$/, "");
@@ -128193,8 +128321,8 @@ async function runAdPmaxImageConvert(opts) {
128193
128321
  }
128194
128322
 
128195
128323
  // src/commands/ad/pmax-brand-mgmt.ts
128196
- function loadBrandConfig(path60, accountId, campaignId) {
128197
- const cfg = loadPmaxJsonFile(path60);
128324
+ function loadBrandConfig(path61, accountId, campaignId) {
128325
+ const cfg = loadPmaxJsonFile(path61);
128198
128326
  return {
128199
128327
  ...cfg,
128200
128328
  account: String(cfg["account"] ?? accountId).trim(),
@@ -128327,6 +128455,420 @@ async function runAdPmaxBrandGuidelinesEnable(opts) {
128327
128455
  });
128328
128456
  }
128329
128457
 
128458
+ // src/commands/ad/search-ops.ts
128459
+ init_auth();
128460
+ init_cli_json_snapshot();
128461
+ init_cli_table();
128462
+ init_shared();
128463
+ import { readFileSync as readFileSync15 } from "fs";
128464
+ var SCHEDULE_DAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
128465
+ var SCHEDULE_MINUTES = ["Zero", "Fifteen", "Thirty", "FortyFive"];
128466
+ var AUDIENCE_KINDS = {
128467
+ "user-list": { path: "userlist", listType: "USER_LIST", idField: "UserListId" },
128468
+ "user-interest": { path: "userinterest", listType: "USER_INTEREST", idField: "UserInterestId" },
128469
+ gender: {
128470
+ path: "gender",
128471
+ listType: "GENDER",
128472
+ enumField: "GenderTypeV2",
128473
+ values: ["Male", "Female", "Undetermined"]
128474
+ },
128475
+ age: {
128476
+ path: "agerange",
128477
+ listType: "AGE_RANGE",
128478
+ enumField: "AgeRangeTypeV2",
128479
+ values: ["AgeRange1824", "AgeRange2534", "AgeRange3544", "AgeRange4554", "AgeRange5564", "AgeRange65Up", "AgeRangeUndetermined"]
128480
+ },
128481
+ income: {
128482
+ path: "incomerange",
128483
+ listType: "INCOME_RANGE",
128484
+ enumField: "IncomeRangeTypeV2",
128485
+ values: ["IncomeRange050", "IncomeRange5060", "IncomeRange6070", "IncomeRange7080", "IncomeRange8090", "IncomeRange90Up", "IncomeRangeUndetermined"]
128486
+ },
128487
+ parent: {
128488
+ path: "parent",
128489
+ listType: "PARENTAL_STATUS",
128490
+ enumField: "ParentTypeV2",
128491
+ values: ["Parent", "NotAParent", "Undetermined"]
128492
+ }
128493
+ };
128494
+ function fail3(err, label2) {
128495
+ console.error(`
128496
+ \u274C ${label2}\uFF1A${err instanceof Error ? err.message : String(err)}
128497
+ `);
128498
+ process.exit(1);
128499
+ }
128500
+ function field5(item, ...keys) {
128501
+ for (const key of keys) {
128502
+ const value = item[key];
128503
+ if (value != null && String(value).trim() !== "") return String(value);
128504
+ }
128505
+ return "";
128506
+ }
128507
+ function accountBase3(opts) {
128508
+ const resolved = withResolvedAdAccount(opts);
128509
+ const config = loadConfig(resolved.token);
128510
+ return { config, base: requireGoogleApi(config), account: resolved.account };
128511
+ }
128512
+ function asRows(data) {
128513
+ if (Array.isArray(data)) return data.filter((row) => row && typeof row === "object");
128514
+ if (data && typeof data === "object") {
128515
+ const obj = data;
128516
+ for (const key of ["items", "Items", "data", "Data"]) {
128517
+ if (Array.isArray(obj[key])) return asRows(obj[key]);
128518
+ }
128519
+ }
128520
+ return [];
128521
+ }
128522
+ function parseAudienceKind(raw) {
128523
+ const kind = (raw ?? "").trim();
128524
+ if (!AUDIENCE_KINDS[kind]) {
128525
+ throw new Error(`--kind \u65E0\u6548\uFF08${raw ?? ""}\uFF09\u3002\u5408\u6CD5\u503C\uFF1A${Object.keys(AUDIENCE_KINDS).join(" | ")}`);
128526
+ }
128527
+ return kind;
128528
+ }
128529
+ function buildAudienceBody(input) {
128530
+ const spec = AUDIENCE_KINDS[input.kind];
128531
+ const target = (input.target ?? "").trim();
128532
+ if (!target) throw new Error("--target \u4E0D\u80FD\u4E3A\u7A7A");
128533
+ if (!/^\d+$/.test(input.adGroupId)) throw new Error("--ad-group-id \u987B\u4E3A\u6570\u5B57");
128534
+ const body = {
128535
+ AdGroupId: input.adGroupId,
128536
+ TypeV2: spec.listType
128537
+ };
128538
+ if ("idField" in spec) {
128539
+ if (!/^\d+$/.test(target)) throw new Error(`${input.kind} \u7684 --target \u987B\u4E3A\u6570\u5B57 ID`);
128540
+ body[spec.idField] = Number(target);
128541
+ } else if (!spec.values.includes(target)) {
128542
+ throw new Error(`--target \u65E0\u6548\uFF08${target}\uFF09\u3002\u5408\u6CD5\u503C\uFF1A${spec.values.join(" | ")}`);
128543
+ } else {
128544
+ body[spec.enumField] = target;
128545
+ }
128546
+ if (input.negative && input.bidModifier != null) {
128547
+ throw new Error("\u5426\u5B9A\u53D7\u4F17\u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E --bid-modifier");
128548
+ }
128549
+ if (input.bidModifier != null) {
128550
+ if (!Number.isFinite(input.bidModifier) || input.bidModifier < 0 || input.bidModifier > 10) {
128551
+ throw new Error("--bid-modifier \u662F\u500D\u7387\uFF0C\u8303\u56F4 0 \u5230 10\uFF081.2 = +20%\uFF0C0 = \u6392\u9664\uFF09");
128552
+ }
128553
+ const percent = multiplierToAdGroupBidPercent(input.bidModifier);
128554
+ if (percent !== 0) {
128555
+ body.BidModifier = percent;
128556
+ body.BidModifierSpecified = true;
128557
+ }
128558
+ }
128559
+ return body;
128560
+ }
128561
+ function parseAdSchedules(raw) {
128562
+ if (!Array.isArray(raw)) throw new Error("\u65F6\u6BB5\u6587\u4EF6\u5FC5\u987B\u662F JSON \u6570\u7EC4\uFF1B\u6E05\u7A7A\u4F20 []");
128563
+ return raw.map((item, index) => {
128564
+ if (!item || typeof item !== "object") throw new Error(`\u7B2C ${index + 1} \u6761\u65F6\u6BB5\u4E0D\u662F\u5BF9\u8C61`);
128565
+ const row = item;
128566
+ const day = String(row.DayOfWeekV2 ?? row.dayOfWeekV2 ?? "");
128567
+ const startMinute = String(row.StartMinuteV2 ?? row.startMinuteV2 ?? "Zero");
128568
+ const endMinute = String(row.EndMinuteV2 ?? row.endMinuteV2 ?? "Zero");
128569
+ const startHour = Number(row.StartHour ?? row.startHour);
128570
+ const endHour = Number(row.EndHour ?? row.endHour);
128571
+ const prefix = `\u7B2C ${index + 1} \u6761`;
128572
+ if (!SCHEDULE_DAYS.includes(day)) {
128573
+ throw new Error(`${prefix} DayOfWeekV2 \u65E0\u6548\uFF08${day}\uFF09\u3002\u5408\u6CD5\u503C\uFF1A${SCHEDULE_DAYS.join(" | ")}`);
128574
+ }
128575
+ if (!Number.isInteger(startHour) || startHour < 0 || startHour > 23) {
128576
+ throw new Error(`${prefix} StartHour \u5FC5\u987B\u662F 0\u201323 \u7684\u6574\u6570`);
128577
+ }
128578
+ if (!Number.isInteger(endHour) || endHour < 1 || endHour > 24) {
128579
+ throw new Error(`${prefix} EndHour \u5FC5\u987B\u662F 1\u201324 \u7684\u6574\u6570`);
128580
+ }
128581
+ if (!SCHEDULE_MINUTES.includes(startMinute) || !SCHEDULE_MINUTES.includes(endMinute)) {
128582
+ throw new Error(`${prefix} \u5206\u949F\u53EA\u63A5\u53D7 ${SCHEDULE_MINUTES.join(" | ")}`);
128583
+ }
128584
+ const schedule = {
128585
+ DayOfWeekV2: day,
128586
+ StartHour: startHour,
128587
+ EndHour: endHour,
128588
+ StartMinuteV2: startMinute,
128589
+ EndMinuteV2: endMinute
128590
+ };
128591
+ const bid = row.BidModifier ?? row.bidModifier;
128592
+ if (bid != null && bid !== "") {
128593
+ const percent = Number(bid);
128594
+ if (!Number.isFinite(percent) || percent < -100 || percent > 900) {
128595
+ throw new Error(`${prefix} BidModifier \u662F\u767E\u5206\u6BD4\uFF0C\u8303\u56F4 -100 \u5230 900\uFF0820 = +20%\uFF09`);
128596
+ }
128597
+ if (percent !== 0 && Math.abs(percent) < 2 && !Number.isInteger(percent)) {
128598
+ throw new Error(`${prefix} BidModifier=${percent} \u50CF\u500D\u7387\u3002\u65F6\u6BB5\u7528\u767E\u5206\u6BD4\uFF1A-20 \u8868\u793A\u964D 20%\uFF0C\u4E0D\u8981\u5199 0.8`);
128599
+ }
128600
+ schedule.BidModifier = percent;
128601
+ }
128602
+ return schedule;
128603
+ });
128604
+ }
128605
+ function readAdSchedulesFile(filePath) {
128606
+ let parsed;
128607
+ try {
128608
+ parsed = JSON.parse(readFileSync15(filePath, "utf8"));
128609
+ } catch (err) {
128610
+ throw new Error(`\u8BFB\u65F6\u6BB5\u6587\u4EF6\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128611
+ }
128612
+ return parseAdSchedules(parsed);
128613
+ }
128614
+ async function runAdAuctionInsights(opts) {
128615
+ let range;
128616
+ try {
128617
+ range = hyphenRange(opts.start, opts.end, "\u7ADE\u4EF7\u6D1E\u5BDF");
128618
+ } catch (err) {
128619
+ fail3(err, "\u53C2\u6570");
128620
+ }
128621
+ const { config, base: base2, account } = accountBase3(opts);
128622
+ const params = new URLSearchParams({ startDate: range.start, endDate: range.end });
128623
+ if (opts.campaignId?.trim()) params.set("campaignId", opts.campaignId.trim());
128624
+ const url = `${base2}/campaignmanagement/accounts/${account}/auction-insights?${params}`;
128625
+ let items3;
128626
+ try {
128627
+ items3 = asRows(await apiFetch2(url, config, {}, opts.verbose));
128628
+ } catch (err) {
128629
+ fail3(err, "\u67E5\u8BE2\u7ADE\u4EF7\u6D1E\u5BDF\u5931\u8D25");
128630
+ }
128631
+ const payload = { account, ...range, campaignId: opts.campaignId ?? "", count: items3.length, items: items3 };
128632
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-auction-insights", commandLabel: "ad auction-insights", payload })) return;
128633
+ console.log(`
128634
+ \u7ADE\u4EF7\u6D1E\u5BDF ${range.start} ~ ${range.end}\uFF08${items3.length} \u6761\uFF09
128635
+ `);
128636
+ printCliTable(
128637
+ items3.map((item) => ({
128638
+ campaignId: field5(item, "campaignId", "CampaignId"),
128639
+ campaignName: field5(item, "campaignName", "CampaignName"),
128640
+ domain: field5(item, "domain", "Domain"),
128641
+ impressionShare: field5(item, "impressionShare", "ImpressionShare")
128642
+ })),
128643
+ [
128644
+ { key: "campaignId", header: "\u7CFB\u5217" },
128645
+ { key: "campaignName", header: "\u540D\u79F0" },
128646
+ { key: "domain", header: "\u57DF\u540D" },
128647
+ { key: "impressionShare", header: "\u5C55\u793A\u4EFD\u989D" }
128648
+ ]
128649
+ );
128650
+ console.log();
128651
+ }
128652
+ async function listBudgets(opts) {
128653
+ const { config, base: base2, account } = accountBase3(opts);
128654
+ const url = `${base2}/budgetmanagement/budgets/${account}`;
128655
+ const items3 = asRows(await apiFetch2(url, config, {}, opts.verbose));
128656
+ return { config, base: base2, account, items: items3 };
128657
+ }
128658
+ function budgetYuan(item) {
128659
+ const raw = item.amount ?? item.Amount;
128660
+ const yuan = toDisplayMoney(typeof raw === "number" ? raw : Number(raw));
128661
+ return yuan == null ? "" : String(yuan);
128662
+ }
128663
+ async function runAdSharedBudgetList(opts) {
128664
+ let items3;
128665
+ let account = opts.account;
128666
+ try {
128667
+ const listed = await listBudgets(opts);
128668
+ items3 = listed.items;
128669
+ account = listed.account;
128670
+ } catch (err) {
128671
+ fail3(err, "\u67E5\u8BE2\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
128672
+ }
128673
+ const view = items3.map((item) => ({
128674
+ ...item,
128675
+ amountYuan: budgetYuan(item)
128676
+ }));
128677
+ const payload = { account, count: view.length, items: view };
128678
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-shared-budget", commandLabel: "ad shared-budget list", payload })) return;
128679
+ console.log(`
128680
+ \u5171\u4EAB\u9884\u7B97\uFF08${view.length} \u6761\uFF09\u3002amountYuan \u662F\u4E3B\u5E01\u79CD\u5143\u3002
128681
+ `);
128682
+ printCliTable(
128683
+ view.map((item) => ({
128684
+ id: field5(item, "id", "Id"),
128685
+ name: field5(item, "name", "Name"),
128686
+ amountYuan: field5(item, "amountYuan"),
128687
+ status: field5(item, "statusV2", "StatusV2")
128688
+ })),
128689
+ [
128690
+ { key: "id", header: "id" },
128691
+ { key: "name", header: "\u540D\u79F0" },
128692
+ { key: "amountYuan", header: "\u65E5\u9884\u7B97(\u5143)" },
128693
+ { key: "status", header: "\u72B6\u6001" }
128694
+ ]
128695
+ );
128696
+ console.log();
128697
+ }
128698
+ async function runAdSharedBudgetCreate(opts) {
128699
+ const name2 = (opts.name ?? "").trim();
128700
+ if (!name2) fail3(new Error("--name \u4E0D\u80FD\u4E3A\u7A7A"), "\u53C2\u6570");
128701
+ if (opts.amount == null || !Number.isFinite(opts.amount) || opts.amount <= 0) {
128702
+ fail3(new Error("--amount \u987B\u4E3A\u6B63\u6570\uFF0C\u5355\u4F4D\u662F\u4E3B\u5E01\u79CD\u5143"), "\u53C2\u6570");
128703
+ }
128704
+ const { config, base: base2, account } = accountBase3(opts);
128705
+ const body = {
128706
+ Name: name2,
128707
+ Amount: toCentAmount(opts.amount),
128708
+ IsExplicitlyShared: true,
128709
+ BudgetBudgetDeliveryMethodV2: "STANDARD",
128710
+ StatusV2: "ENABLED"
128711
+ };
128712
+ const url = `${base2}/budgetmanagement/budgets/${account}`;
128713
+ try {
128714
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
128715
+ } catch (err) {
128716
+ fail3(err, "\u521B\u5EFA\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
128717
+ }
128718
+ console.log(`
128719
+ \u2705 \u5DF2\u521B\u5EFA\u5171\u4EAB\u9884\u7B97\u300C${name2}\u300D\uFF0C\u65E5\u9884\u7B97 ${opts.amount}\u3002\u628A\u7CFB\u5217\u6302\u5230\u5B83\u4E0A\u9762\u9700\u8981\u7CFB\u5217\u7F16\u8F91\u91CC\u7684\u9884\u7B97 id\uFF0C\u672C\u547D\u4EE4\u4E0D\u6539\u5DF2\u6709\u7CFB\u5217\u3002
128720
+ `);
128721
+ }
128722
+ async function runAdSharedBudgetUpdate(opts) {
128723
+ const budgetId = (opts.budgetId ?? "").trim();
128724
+ if (!/^\d+$/.test(budgetId)) fail3(new Error("--budget-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
128725
+ if (opts.amount != null && (!Number.isFinite(opts.amount) || opts.amount <= 0)) {
128726
+ fail3(new Error("--amount \u987B\u4E3A\u6B63\u6570\uFF0C\u5355\u4F4D\u662F\u4E3B\u5E01\u79CD\u5143"), "\u53C2\u6570");
128727
+ }
128728
+ let current;
128729
+ let config;
128730
+ let url = "";
128731
+ try {
128732
+ const listed = await listBudgets(opts);
128733
+ config = listed.config;
128734
+ current = listed.items.find((item) => field5(item, "id", "Id") === budgetId);
128735
+ url = `${listed.base}/budgetmanagement/budgets/${listed.account}/${budgetId}`;
128736
+ } catch (err) {
128737
+ fail3(err, "\u67E5\u8BE2\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
128738
+ }
128739
+ if (!current) fail3(new Error(`\u8D26\u6237\u91CC\u6CA1\u6709\u5171\u4EAB\u9884\u7B97 ${budgetId}`), "\u53C2\u6570");
128740
+ const name2 = (opts.name ?? "").trim() || field5(current, "name", "Name");
128741
+ const amountCents = opts.amount != null ? toCentAmount(opts.amount) : Number(current.amount ?? current.Amount);
128742
+ if (!name2 || !Number.isFinite(amountCents) || amountCents <= 0) {
128743
+ fail3(new Error("\u7F3A\u5C11\u540D\u79F0\u6216\u91D1\u989D\u3002\u5148 list\uFF0C\u518D\u4F20 --name / --amount"), "\u53C2\u6570");
128744
+ }
128745
+ const body = {
128746
+ Id: budgetId,
128747
+ Name: name2,
128748
+ Amount: amountCents,
128749
+ IsExplicitlyShared: true,
128750
+ BudgetBudgetDeliveryMethodV2: field5(current, "budgetBudgetDeliveryMethodV2", "BudgetBudgetDeliveryMethodV2") || "STANDARD",
128751
+ StatusV2: field5(current, "statusV2", "StatusV2") || "ENABLED"
128752
+ };
128753
+ try {
128754
+ await apiFetch2(url, config, { method: "PUT", body: JSON.stringify(body) }, opts.verbose);
128755
+ } catch (err) {
128756
+ fail3(err, "\u4FEE\u6539\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
128757
+ }
128758
+ console.log(`
128759
+ \u2705 \u5DF2\u4FEE\u6539\u5171\u4EAB\u9884\u7B97 ${budgetId}\u300C${name2}\u300D\u3002\u540C\u4E00\u9884\u7B97\u4E0B\u7684\u7CFB\u5217\u4F1A\u4E00\u8D77\u53D8\u3002
128760
+ `);
128761
+ }
128762
+ async function runAdSharedBudgetDelete(opts) {
128763
+ const budgetId = (opts.budgetId ?? "").trim();
128764
+ if (!/^\d+$/.test(budgetId)) fail3(new Error("--budget-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
128765
+ if (!opts.iConfirm) fail3(new Error("\u5220\u9664\u5171\u4EAB\u9884\u7B97\u987B\u5148 list \u5E76\u5411\u7528\u6237\u786E\u8BA4\uFF0C\u518D\u52A0 --i-confirm"), "\u53C2\u6570");
128766
+ const { config, base: base2, account } = accountBase3(opts);
128767
+ const url = `${base2}/budgetmanagement/budgets/${account}/${budgetId}`;
128768
+ try {
128769
+ await apiDeleteRaw(url, config, { verbose: opts.verbose });
128770
+ } catch (err) {
128771
+ fail3(err, "\u5220\u9664\u5171\u4EAB\u9884\u7B97\u5931\u8D25");
128772
+ }
128773
+ console.log(`
128774
+ \u2705 \u5DF2\u5220\u9664\u5171\u4EAB\u9884\u7B97 ${budgetId}\u3002\u4ECD\u88AB\u7CFB\u5217\u4F7F\u7528\u65F6 Google \u4F1A\u62D2\u7EDD\uFF0C\u8FD9\u4E0D\u662F CLI \u91CD\u8BD5\u80FD\u89E3\u51B3\u7684\u3002
128775
+ `);
128776
+ }
128777
+ async function runAdAudienceList(opts) {
128778
+ let kind;
128779
+ try {
128780
+ kind = parseAudienceKind(opts.kind);
128781
+ } catch (err) {
128782
+ fail3(err, "\u53C2\u6570");
128783
+ }
128784
+ const campaignId = (opts.campaignId ?? "").trim();
128785
+ const adGroupId = (opts.adGroupId ?? "").trim();
128786
+ if (!/^\d+$/.test(campaignId) || !/^\d+$/.test(adGroupId)) {
128787
+ fail3(new Error("--campaign-id \u548C --ad-group-id \u90FD\u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
128788
+ }
128789
+ const spec = AUDIENCE_KINDS[kind];
128790
+ const { config, base: base2, account } = accountBase3(opts);
128791
+ const params = new URLSearchParams({ campaignId, adgroupId: adGroupId });
128792
+ const url = `${base2}/adgroupnmanagement/bidmodifiers/${account}/${spec.listType}?${params}`;
128793
+ let items3;
128794
+ try {
128795
+ items3 = asRows(await apiFetch2(url, config, {}, opts.verbose));
128796
+ } catch (err) {
128797
+ fail3(err, "\u67E5\u8BE2\u53D7\u4F17\u5931\u8D25");
128798
+ }
128799
+ const payload = { account, kind, campaignId, adGroupId, count: items3.length, items: items3 };
128800
+ if (await emitCliJsonOrSnapshot(opts, { section: "ad-audience", commandLabel: "ad audience list", payload })) return;
128801
+ console.log(`
128802
+ \u5E7F\u544A\u7EC4\u53D7\u4F17 ${kind}\uFF08${items3.length} \u6761\uFF09\u3002bidModifier \u82E5\u6709\uFF0C\u662F\u767E\u5206\u6BD4\u3002
128803
+ `);
128804
+ printCliTable(
128805
+ items3.map((item) => ({
128806
+ id: field5(item, "id", "Id"),
128807
+ name: field5(item, "userListName", "UserListName", "displayName", "DisplayName"),
128808
+ bid: field5(item, "bidModifier", "BidModifier")
128809
+ })),
128810
+ [
128811
+ { key: "id", header: "id" },
128812
+ { key: "name", header: "\u540D\u79F0" },
128813
+ { key: "bid", header: "\u51FA\u4EF7%" }
128814
+ ]
128815
+ );
128816
+ console.log();
128817
+ }
128818
+ async function runAdAudienceAdd(opts) {
128819
+ let body;
128820
+ let kind;
128821
+ try {
128822
+ kind = parseAudienceKind(opts.kind);
128823
+ body = buildAudienceBody({
128824
+ kind,
128825
+ adGroupId: (opts.adGroupId ?? "").trim(),
128826
+ target: opts.target,
128827
+ bidModifier: opts.bidModifier,
128828
+ negative: opts.negative
128829
+ });
128830
+ } catch (err) {
128831
+ fail3(err, "\u53C2\u6570");
128832
+ }
128833
+ const { config, base: base2, account } = accountBase3(opts);
128834
+ const spec = AUDIENCE_KINDS[kind];
128835
+ const negative = opts.negative ? "true" : "false";
128836
+ const url = `${base2}/adgroupnmanagement/${spec.path}/${account}?isNegative=${negative}`;
128837
+ try {
128838
+ await apiFetch2(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
128839
+ } catch (err) {
128840
+ fail3(err, "\u6DFB\u52A0\u53D7\u4F17\u5931\u8D25");
128841
+ }
128842
+ console.log(`
128843
+ \u2705 \u5DF2\u5728\u5E7F\u544A\u7EC4 ${opts.adGroupId} \u6DFB\u52A0 ${kind}\uFF1A${opts.target}${opts.negative ? "\uFF08\u5426\u5B9A\uFF09" : ""}
128844
+ `);
128845
+ }
128846
+ async function runAdScheduleReplace(opts) {
128847
+ const campaignId = (opts.campaignId ?? "").trim();
128848
+ if (!/^\d+$/.test(campaignId)) fail3(new Error("--campaign-id \u987B\u4E3A\u6570\u5B57"), "\u53C2\u6570");
128849
+ if (!opts.file?.trim()) fail3(new Error("\u987B --file \u6307\u5411\u65F6\u6BB5 JSON \u6570\u7EC4"), "\u53C2\u6570");
128850
+ let schedules;
128851
+ try {
128852
+ schedules = readAdSchedulesFile(opts.file.trim());
128853
+ } catch (err) {
128854
+ fail3(err, "\u53C2\u6570");
128855
+ }
128856
+ const { config, base: base2, account } = accountBase3(opts);
128857
+ const url = `${base2}/campaignmanagement/campaign/${account}/${campaignId}/ad-schedules`;
128858
+ try {
128859
+ await apiFetch2(url, config, { method: "PUT", body: JSON.stringify(schedules) }, opts.verbose);
128860
+ } catch (err) {
128861
+ fail3(err, "\u66FF\u6362\u6295\u653E\u65F6\u6BB5\u5931\u8D25");
128862
+ }
128863
+ console.log(
128864
+ schedules.length === 0 ? `
128865
+ \u2705 \u5DF2\u6E05\u7A7A\u7CFB\u5217 ${campaignId} \u7684\u6295\u653E\u65F6\u6BB5\u3002
128866
+ ` : `
128867
+ \u2705 \u5DF2\u7528 ${schedules.length} \u6761\u65F6\u6BB5\u66FF\u6362\u7CFB\u5217 ${campaignId}\u3002\u6CA1\u5199\u8FDB\u6587\u4EF6\u7684\u65E7\u65F6\u6BB5\u4F1A\u88AB\u5220\u6389\u3002
128868
+ `
128869
+ );
128870
+ }
128871
+
128330
128872
  // src/commands/ad/demand-gen-body.ts
128331
128873
  init_shared();
128332
128874
  var WRITE_CENT_KEYS = ["budget", "targetCpa_BidingAmount", "currencyMinimumBudget"];
@@ -128549,12 +129091,12 @@ function demandGenConversionsValidateUrl(googleApiUrl, accountId) {
128549
129091
  return `${demandGenCollectionUrl(googleApiUrl, accountId)}/conversions/validate`;
128550
129092
  }
128551
129093
  function demandGenAdGroupUrl(googleApiUrl, accountId, campaignId, adGroupId, suffix) {
128552
- const path60 = `${demandGenCampaignUrl(googleApiUrl, accountId, campaignId)}/ad-groups/${adGroupId}`;
128553
- return suffix ? `${path60}/${suffix.replace(/^\//, "")}` : path60;
129094
+ const path61 = `${demandGenCampaignUrl(googleApiUrl, accountId, campaignId)}/ad-groups/${adGroupId}`;
129095
+ return suffix ? `${path61}/${suffix.replace(/^\//, "")}` : path61;
128554
129096
  }
128555
129097
  function demandGenAdUrl(googleApiUrl, accountId, campaignId, adGroupId, adId, suffix) {
128556
- const path60 = `${demandGenAdGroupUrl(googleApiUrl, accountId, campaignId, adGroupId)}/ads/${adId}`;
128557
- return suffix ? `${path60}/${suffix.replace(/^\//, "")}` : path60;
129098
+ const path61 = `${demandGenAdGroupUrl(googleApiUrl, accountId, campaignId, adGroupId)}/ads/${adId}`;
129099
+ return suffix ? `${path61}/${suffix.replace(/^\//, "")}` : path61;
128558
129100
  }
128559
129101
  function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDate, endDate) {
128560
129102
  const params = new URLSearchParams({ startDate, endDate });
@@ -128564,7 +129106,7 @@ function demandGenChannelReportUrl(googleApiUrl, accountId, campaignId, startDat
128564
129106
  // src/commands/ad/demand-gen.ts
128565
129107
  init_shared();
128566
129108
  var MONEY_HINT = "budget / targetCpa_BidingAmount / minimumDailyBudget \u662F\u5206\uFF08500 = 5 \u5143\uFF09\u3002\u770B\u65C1\u8FB9\u7684 *Yuan\u3002\u5199\u5165 --budget / JSON \u586B\u5143\uFF1B\u82E5\u540C\u65F6\u6709 *Yuan\uFF0C\u4EE5 Yuan \u4E3A\u51C6\u3002targetRoas \u662F\u6BD4\u7387\u3002\u62A5\u8868 spend \u5DF2\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u4E0D\u8981\u62FF\u53BB\u5F53\u9884\u7B97\u3002";
128567
- function fail3(message) {
129109
+ function fail4(message) {
128568
129110
  console.error(`
128569
129111
  \u274C ${message}
128570
129112
  `);
@@ -128584,7 +129126,7 @@ async function emit(opts, section, commandLabel, payload, idSuffix) {
128584
129126
  }
128585
129127
  function printIssues(issues) {
128586
129128
  if (issues.length === 0) return;
128587
- fail3(issues.join("\n"));
129129
+ fail4(issues.join("\n"));
128588
129130
  }
128589
129131
  function loadBody(configFile) {
128590
129132
  return stripMetaKeys(loadPmaxJsonFile(configFile));
@@ -128658,7 +129200,7 @@ function explainCreateError(err) {
128658
129200
  if (failure) return demandGenResumeHint(failure);
128659
129201
  return err instanceof Error ? err.message : String(err);
128660
129202
  }
128661
- async function postCreate(opts, path60, commandLabel) {
129203
+ async function postCreate(opts, path61, commandLabel) {
128662
129204
  const accountId = requireAccountId(opts.account);
128663
129205
  const raw = loadBody(opts.configFile);
128664
129206
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -128667,10 +129209,10 @@ async function postCreate(opts, path60, commandLabel) {
128667
129209
  body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
128668
129210
  body = prepareCreateBody(body);
128669
129211
  } catch (err) {
128670
- fail3(err instanceof Error ? err.message : String(err));
129212
+ fail4(err instanceof Error ? err.message : String(err));
128671
129213
  }
128672
129214
  printIssues(demandGenCreateIssues(body));
128673
- const url = path60 ? `${demandGenCollectionUrl(googleApiUrl, accountId)}/${path60}` : demandGenCollectionUrl(googleApiUrl, accountId);
129215
+ const url = path61 ? `${demandGenCollectionUrl(googleApiUrl, accountId)}/${path61}` : demandGenCollectionUrl(googleApiUrl, accountId);
128674
129216
  let data;
128675
129217
  try {
128676
129218
  data = await pmaxApiFetch(
@@ -128680,10 +129222,10 @@ async function postCreate(opts, path60, commandLabel) {
128680
129222
  opts.verbose
128681
129223
  );
128682
129224
  } catch (err) {
128683
- fail3(explainCreateError(err));
129225
+ fail4(explainCreateError(err));
128684
129226
  }
128685
129227
  const payload = decorateDemandGenRead(data);
128686
- if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path60 || "create"}`, commandLabel, payload, accountId)) {
129228
+ if (await emit({ ...opts, account: accountId }, `ad-demand-gen-${path61 || "create"}`, commandLabel, payload, accountId)) {
128687
129229
  return;
128688
129230
  }
128689
129231
  console.log(`
@@ -128700,7 +129242,7 @@ async function runDemandGenList(opts) {
128700
129242
  try {
128701
129243
  data = await pmaxApiFetch(demandGenCollectionUrl(googleApiUrl, accountId), config, {}, opts.verbose);
128702
129244
  } catch (err) {
128703
- fail3(`\u5217\u51FA Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129245
+ fail4(`\u5217\u51FA Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128704
129246
  }
128705
129247
  const payload = {
128706
129248
  items: decorateDemandGenRead(data),
@@ -128737,7 +129279,7 @@ async function runDemandGenGet(opts) {
128737
129279
  opts.verbose
128738
129280
  );
128739
129281
  } catch (err) {
128740
- fail3(`\u8BFB\u53D6 Demand Gen \u8BE6\u60C5\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129282
+ fail4(`\u8BFB\u53D6 Demand Gen \u8BE6\u60C5\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128741
129283
  }
128742
129284
  const payload = asRecord5(decorateDemandGenRead(data));
128743
129285
  payload["agentHint"] = MONEY_HINT;
@@ -128766,7 +129308,7 @@ async function runDemandGenMinimumBudget(opts) {
128766
129308
  opts.verbose
128767
129309
  );
128768
129310
  } catch (err) {
128769
- fail3(`\u8BFB\u53D6\u6700\u4F4E\u65E5\u9884\u7B97\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129311
+ fail4(`\u8BFB\u53D6\u6700\u4F4E\u65E5\u9884\u7B97\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128770
129312
  }
128771
129313
  const payload = decorateDemandGenRead(data);
128772
129314
  if (await emit(
@@ -128798,7 +129340,7 @@ async function runDemandGenConversions(opts) {
128798
129340
  opts.verbose
128799
129341
  );
128800
129342
  } catch (err) {
128801
- fail3(`\u8BFB\u53D6\u53EF\u51FA\u4EF7\u8F6C\u5316\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129343
+ fail4(`\u8BFB\u53D6\u53EF\u51FA\u4EF7\u8F6C\u5316\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128802
129344
  }
128803
129345
  if (await emit(
128804
129346
  { ...opts, account: accountId },
@@ -128831,7 +129373,7 @@ async function runDemandGenDraft(opts) {
128831
129373
  opts.verbose
128832
129374
  );
128833
129375
  } catch (err) {
128834
- fail3(`\u751F\u6210\u8349\u7A3F\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129376
+ fail4(`\u751F\u6210\u8349\u7A3F\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128835
129377
  }
128836
129378
  const payload = decorateDemandGenRead(data);
128837
129379
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-draft", "ad demand-gen draft", payload, accountId)) {
@@ -128856,7 +129398,7 @@ async function runDemandGenConfirm(opts) {
128856
129398
  }
128857
129399
  function readFlagNumber(value, label2) {
128858
129400
  const amount = typeof value === "number" ? value : Number(String(value).trim());
128859
- if (!Number.isFinite(amount)) fail3(`${label2}\u987B\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${String(value)}`);
129401
+ if (!Number.isFinite(amount)) fail4(`${label2}\u987B\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u6536\u5230 ${String(value)}`);
128860
129402
  return amount;
128861
129403
  }
128862
129404
  async function runDemandGenEdit(opts) {
@@ -128873,7 +129415,7 @@ async function runDemandGenEdit(opts) {
128873
129415
  if (opts.name !== void 0) body["name"] = opts.name.trim();
128874
129416
  if (opts.status !== void 0) {
128875
129417
  const status2 = normalizeCampaignStatus(opts.status);
128876
- if (!status2) fail3("Campaign status must be Enabled, Paused, or Removed.");
129418
+ if (!status2) fail4("Campaign status must be Enabled, Paused, or Removed.");
128877
129419
  body["statusV2"] = status2;
128878
129420
  }
128879
129421
  if (opts.budget !== void 0) body["budget"] = readFlagNumber(opts.budget, "\u9884\u7B97");
@@ -128888,7 +129430,7 @@ async function runDemandGenEdit(opts) {
128888
129430
  body = normalizeDemandGenMoneyForWrite(body);
128889
129431
  }
128890
129432
  if (Object.keys(body).length === 0) {
128891
- fail3("\u8BF7\u6307\u5B9A --patch-file\uFF0C\u6216\u81F3\u5C11\u4E00\u9879\u4FEE\u6539\uFF08--name / --status / --budget / --bidding / \u2026\uFF09");
129433
+ fail4("\u8BF7\u6307\u5B9A --patch-file\uFF0C\u6216\u81F3\u5C11\u4E00\u9879\u4FEE\u6539\uFF08--name / --status / --budget / --bidding / \u2026\uFF09");
128892
129434
  }
128893
129435
  const status = normalizeCampaignStatus(body["statusV2"]);
128894
129436
  if (status) body["statusV2"] = status;
@@ -128906,7 +129448,7 @@ async function runDemandGenEdit(opts) {
128906
129448
  });
128907
129449
  }
128908
129450
  if (body["automatic"] === true) {
128909
- fail3("\u4EBA\u5DE5\u64CD\u4F5C\u4E0D\u8981\u5E26 automatic\u3002");
129451
+ fail4("\u4EBA\u5DE5\u64CD\u4F5C\u4E0D\u8981\u5E26 automatic\u3002");
128910
129452
  }
128911
129453
  await withGoogleApi(opts, async (config, googleApiUrl) => {
128912
129454
  try {
@@ -128917,7 +129459,7 @@ async function runDemandGenEdit(opts) {
128917
129459
  opts.verbose
128918
129460
  );
128919
129461
  } catch (err) {
128920
- fail3(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129462
+ fail4(`\u66F4\u65B0 Demand Gen \u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128921
129463
  }
128922
129464
  const payload = { ok: true, campaignId, patch: body };
128923
129465
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-edit", "ad demand-gen edit", payload, campaignId)) {
@@ -128936,20 +129478,20 @@ async function runDemandGenContent(opts) {
128936
129478
  delete body["targetedLocations"];
128937
129479
  delete body["targetedLanguages"];
128938
129480
  }
128939
- if (Object.keys(body).length === 0) fail3("content JSON \u6CA1\u6709\u8981\u6539\u7684\u5B57\u6BB5");
129481
+ if (Object.keys(body).length === 0) fail4("content JSON \u6CA1\u6709\u8981\u6539\u7684\u5B57\u6BB5");
128940
129482
  await withGoogleApi(opts, async (config, googleApiUrl) => {
128941
129483
  let next = body;
128942
129484
  try {
128943
129485
  next = await attachImages(opts.configFile, body, accountId, config, googleApiUrl, opts.verbose);
128944
129486
  } catch (err) {
128945
- fail3(err instanceof Error ? err.message : String(err));
129487
+ fail4(err instanceof Error ? err.message : String(err));
128946
129488
  }
128947
129489
  delete next["imagePaths"];
128948
129490
  const url = opts.adId?.trim() ? demandGenAdUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), opts.adId.trim(), "content") : demandGenAdGroupUrl(googleApiUrl, accountId, opts.campaignId.trim(), opts.adGroupId.trim(), "content");
128949
129491
  try {
128950
129492
  await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify(next) }, opts.verbose);
128951
129493
  } catch (err) {
128952
- fail3(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129494
+ fail4(`\u66F4\u65B0\u5E7F\u544A\u5185\u5BB9\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128953
129495
  }
128954
129496
  const payload = { ok: true, campaignId: opts.campaignId, adGroupId: opts.adGroupId, adId: opts.adId ?? null };
128955
129497
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-content", "ad demand-gen content", payload)) return;
@@ -128961,7 +129503,7 @@ async function runDemandGenChannels(opts) {
128961
129503
  const hasStrategy = Boolean(opts.strategy?.trim());
128962
129504
  const hasSelected = Boolean(opts.selected?.trim());
128963
129505
  if (hasStrategy === hasSelected) {
128964
- fail3("channelStrategy \u548C selectedChannels \u4E8C\u9009\u4E00\uFF1A\u53EA\u4F20 --strategy\uFF0C\u6216\u53EA\u4F20 --selected\u3002");
129506
+ fail4("channelStrategy \u548C selectedChannels \u4E8C\u9009\u4E00\uFF1A\u53EA\u4F20 --strategy\uFF0C\u6216\u53EA\u4F20 --selected\u3002");
128965
129507
  }
128966
129508
  const body = {};
128967
129509
  if (hasStrategy) body["channelStrategy"] = opts.strategy.trim();
@@ -128969,7 +129511,7 @@ async function runDemandGenChannels(opts) {
128969
129511
  try {
128970
129512
  body["selectedChannels"] = buildSelectedChannels(opts.selected.split(","));
128971
129513
  } catch (err) {
128972
- fail3(err instanceof Error ? err.message : String(err));
129514
+ fail4(err instanceof Error ? err.message : String(err));
128973
129515
  }
128974
129516
  }
128975
129517
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -128983,7 +129525,7 @@ async function runDemandGenChannels(opts) {
128983
129525
  try {
128984
129526
  await pmaxApiFetch(url, config, { method: "PATCH", body: JSON.stringify(body) }, opts.verbose);
128985
129527
  } catch (err) {
128986
- fail3(`\u66F4\u65B0\u7248\u4F4D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129528
+ fail4(`\u66F4\u65B0\u7248\u4F4D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
128987
129529
  }
128988
129530
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-channels", "ad demand-gen channels", { ok: true, patch: body })) {
128989
129531
  return;
@@ -128994,7 +129536,7 @@ async function runDemandGenChannels(opts) {
128994
129536
  async function putStatus(opts, kind) {
128995
129537
  const status = normalizeAdStatus(opts.status);
128996
129538
  if (!status) {
128997
- 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");
129539
+ fail4("\u5E7F\u544A\u548C\u5E7F\u544A\u7EC4\u53EA\u63A5\u53D7 Enabled \u6216 Paused\u3002\u4E0D\u8981\u7528\u5B83\u542F\u7528\u7CFB\u5217\uFF1B\u5220\u5149\u4F1A 400\uFF0C\u53EA\u60F3\u505C\u6295\u7528 Paused\u3002");
128998
129540
  }
128999
129541
  const accountId = requireAccountId(opts.account);
129000
129542
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -129020,7 +129562,7 @@ async function putStatus(opts, kind) {
129020
129562
  opts.verbose
129021
129563
  );
129022
129564
  } catch (err) {
129023
- fail3(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129565
+ fail4(`\u66F4\u65B0\u72B6\u6001\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129024
129566
  }
129025
129567
  console.log(`
129026
129568
  \u2705 \u5DF2\u8BBE\u4E3A ${status}\u3002\u7CFB\u5217\u72B6\u6001\u4E0D\u4F1A\u8DDF\u7740\u53D8\u3002
@@ -129035,7 +129577,7 @@ async function runDemandGenAdStatus(opts) {
129035
129577
  }
129036
129578
  async function runDemandGenAdGroupRename(opts) {
129037
129579
  const name2 = opts.name.trim();
129038
- if (!name2 || name2.length > 255) fail3("\u5E7F\u544A\u7EC4\u540D\u987B\u4E3A 1\uFF5E255 \u4E2A\u5B57\u7B26\u3002");
129580
+ if (!name2 || name2.length > 255) fail4("\u5E7F\u544A\u7EC4\u540D\u987B\u4E3A 1\uFF5E255 \u4E2A\u5B57\u7B26\u3002");
129039
129581
  const accountId = requireAccountId(opts.account);
129040
129582
  await withGoogleApi(opts, async (config, googleApiUrl) => {
129041
129583
  const url = demandGenAdGroupUrl(
@@ -129048,7 +129590,7 @@ async function runDemandGenAdGroupRename(opts) {
129048
129590
  try {
129049
129591
  await pmaxApiFetch(url, config, { method: "PUT", body: JSON.stringify({ name: name2 }) }, opts.verbose);
129050
129592
  } catch (err) {
129051
- fail3(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129593
+ fail4(`\u5E7F\u544A\u7EC4\u6539\u540D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129052
129594
  }
129053
129595
  console.log(`
129054
129596
  \u2705 \u5E7F\u544A\u7EC4\u5DF2\u6539\u540D\u4E3A ${name2}
@@ -129058,7 +129600,7 @@ async function runDemandGenAdGroupRename(opts) {
129058
129600
  async function runDemandGenAudience(opts) {
129059
129601
  const audienceResourceName = opts.resourceName.trim();
129060
129602
  if (!audienceResourceName.includes("/audiences/")) {
129061
- fail3("Audience resource name must be customers/{id}/audiences/{audienceId}.");
129603
+ fail4("Audience resource name must be customers/{id}/audiences/{audienceId}.");
129062
129604
  }
129063
129605
  const accountId = requireAccountId(opts.account);
129064
129606
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -129077,7 +129619,7 @@ async function runDemandGenAudience(opts) {
129077
129619
  opts.verbose
129078
129620
  );
129079
129621
  } catch (err) {
129080
- fail3(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129622
+ fail4(`\u66FF\u6362\u53D7\u4F17\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129081
129623
  }
129082
129624
  console.log("\n\u2705 \u5E7F\u544A\u7EC4\u53D7\u4F17\u5DF2\u66FF\u6362\u3002\u4E00\u4E2A\u5E7F\u544A\u7EC4\u53EA\u80FD\u7ED1\u4E00\u4E2A Audience\u3002\n");
129083
129625
  });
@@ -129085,7 +129627,7 @@ async function runDemandGenAudience(opts) {
129085
129627
  async function runDemandGenAudienceKeywords(opts) {
129086
129628
  const audienceKeywords = opts.keywords.split(",").map((item) => item.trim()).filter(Boolean);
129087
129629
  if (audienceKeywords.length < 1 || audienceKeywords.length > 10) {
129088
- fail3("Audience keyword count must be between 1 and 10.");
129630
+ fail4("Audience keyword count must be between 1 and 10.");
129089
129631
  }
129090
129632
  const accountId = requireAccountId(opts.account);
129091
129633
  await withGoogleApi(opts, async (config, googleApiUrl) => {
@@ -129104,7 +129646,7 @@ async function runDemandGenAudienceKeywords(opts) {
129104
129646
  opts.verbose
129105
129647
  );
129106
129648
  } catch (err) {
129107
- fail3(`\u66FF\u6362\u53D7\u4F17\u8BCD\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129649
+ fail4(`\u66FF\u6362\u53D7\u4F17\u8BCD\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129108
129650
  }
129109
129651
  console.log("\n\u2705 \u641C\u7D22\u81EA\u5B9A\u4E49\u53D7\u4F17\u7684\u8BCD\u5DF2\u6574\u4EFD\u66FF\u6362\n");
129110
129652
  });
@@ -129117,7 +129659,7 @@ async function postChild(opts, kind) {
129117
129659
  try {
129118
129660
  body = await attachImages(opts.configFile, raw, accountId, config, googleApiUrl, opts.verbose);
129119
129661
  } catch (err) {
129120
- fail3(err instanceof Error ? err.message : String(err));
129662
+ fail4(err instanceof Error ? err.message : String(err));
129121
129663
  }
129122
129664
  delete body["account"];
129123
129665
  delete body["imagePaths"];
@@ -129126,7 +129668,7 @@ async function postChild(opts, kind) {
129126
129668
  try {
129127
129669
  data = await pmaxApiFetch(url, config, { method: "POST", body: JSON.stringify(body) }, opts.verbose);
129128
129670
  } catch (err) {
129129
- fail3(err instanceof Error ? err.message : String(err));
129671
+ fail4(err instanceof Error ? err.message : String(err));
129130
129672
  }
129131
129673
  if (await emit({ ...opts, account: accountId }, `ad-demand-gen-add-${kind}`, `ad demand-gen add-${kind}`, data)) {
129132
129674
  return;
@@ -129161,7 +129703,7 @@ async function runDemandGenDeleteAd(opts) {
129161
129703
  try {
129162
129704
  await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
129163
129705
  } catch (err) {
129164
- fail3(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129706
+ fail4(`\u5220\u9664\u5E7F\u544A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129165
129707
  }
129166
129708
  console.log("\n\u2705 \u5E7F\u544A\u5DF2\u5220\u9664\n");
129167
129709
  });
@@ -129182,7 +129724,7 @@ async function runDemandGenDeleteAdGroup(opts) {
129182
129724
  try {
129183
129725
  await pmaxApiFetch(url, config, { method: "DELETE" }, opts.verbose);
129184
129726
  } catch (err) {
129185
- fail3(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129727
+ fail4(`\u5220\u9664\u5E7F\u544A\u7EC4\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129186
129728
  }
129187
129729
  console.log("\n\u2705 \u5E7F\u544A\u7EC4\u5DF2\u5220\u9664\n");
129188
129730
  });
@@ -129201,7 +129743,7 @@ async function runDemandGenReport(opts) {
129201
129743
  opts.verbose
129202
129744
  );
129203
129745
  } catch (err) {
129204
- fail3(`\u8BFB\u53D6\u7248\u4F4D\u62A5\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129746
+ fail4(`\u8BFB\u53D6\u7248\u4F4D\u62A5\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129205
129747
  }
129206
129748
  if (await emit({ ...opts, account: accountId }, "ad-demand-gen-report", "ad demand-gen report", data, opts.campaignId)) {
129207
129749
  return;
@@ -129225,7 +129767,7 @@ async function runDemandGenConversionsValidate(opts) {
129225
129767
  opts.verbose
129226
129768
  );
129227
129769
  } catch (err) {
129228
- fail3(`\u79BB\u7EBF\u8F6C\u5316\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129770
+ fail4(`\u79BB\u7EBF\u8F6C\u5316\u6821\u9A8C\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
129229
129771
  }
129230
129772
  if (await emit(
129231
129773
  { ...opts, account: accountId },
@@ -129425,7 +129967,12 @@ function register21(program2) {
129425
129967
  });
129426
129968
  }
129427
129969
  );
129428
- adCmd.command("campaigns").alias("campaign-list").description("\u67E5\u8BE2\u5E7F\u544A\u7CFB\u5217\u5217\u8868\uFF08\u65E5\u671F\u9ED8\u8BA4\u8FD1 30 \u5929\uFF1B\u522B\u540D campaign-list\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(
129970
+ adCmd.command("campaigns").alias("campaign-list").description(
129971
+ "\u67E5\u8BE2\u5E7F\u544A\u7CFB\u5217\u5217\u8868\uFF08\u65E5\u671F\u9ED8\u8BA4\u8FD1 30 \u5929\uFF1B\u522B\u540D campaign-list\uFF09\u3002\u591A\u4E2A\u8D26\u6237\u7528\u9017\u53F7\u4E00\u6B21\u4F20\u5165\uFF0C\u8FDB\u7A0B\u5185\u5E76\u53D1\uFF1B\u7981\u6B62 while/for/xargs \u9010\u6237\u8C03\u7528\u3002"
129972
+ ).requiredOption(
129973
+ "-a, --account <ids>",
129974
+ "\u4E00\u4E2A mediaCustomerId\uFF0C\u6216\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF08id1,id2\uFF09\u3002\u591A\u4E2A\u65F6\u5FC5\u987B\u5E26 --json-out <\u76EE\u5F55>"
129975
+ ).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(
129429
129976
  "--fresh",
129430
129977
  "\u8DF3\u8FC7\u7F51\u5173 60 \u79D2\u7F13\u5B58\uFF0C\u5F3A\u5236\u62C9\u53D6\u6700\u65B0\u6570\u636E\uFF08\u7F51\u5173 newest=true\uFF09\uFF1B\u521A\u521B\u5EFA/\u7F16\u8F91\u5B8C\u60F3\u7ACB\u523B\u770B\u5230\u7ED3\u679C\u65F6\u7528",
129431
129978
  false
@@ -130796,6 +131343,32 @@ function registerProtection(adCmd) {
130796
131343
  adCmd.command("rsa-assets").description("\u641C\u7D22\u5E7F\u544A RSA \u7D20\u6750\u8868\u73B0\u3002\u7528\u6765\u770B\u54EA\u6761\u6807\u9898\u3001\u63CF\u8FF0\u5728\u82B1\u94B1").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130797
131344
  await runAdRsaAssets(opts);
130798
131345
  });
131346
+ adCmd.command("auction-insights").description("\u7ADE\u4EF7\u6D1E\u5BDF\uFF1A\u4F60\u548C\u5BF9\u624B\u7684\u5C55\u793A\u4EFD\u989D\u3002\u53EA\u8BFB").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--start <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u8FD1 30 \u5929").option("--end <date>", "YYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929").option("--campaign-id <id>", "\u53EA\u770B\u4E00\u4E2A\u7CFB\u5217").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131347
+ await runAdAuctionInsights(opts);
131348
+ });
131349
+ const sharedBudget = adCmd.command("shared-budget").description("\u5171\u4EAB\u9884\u7B97\u3002campaign-edit \u5728 budgetShared \u65F6\u4F1A\u62D2\u7EDD\u6539\u9884\u7B97\uFF0C\u6539\u91D1\u989D\u7528\u8FD9\u91CC");
131350
+ sharedBudget.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131351
+ await runAdSharedBudgetList(opts);
131352
+ });
131353
+ sharedBudget.command("create").description("\u65B0\u5EFA\u4E00\u4EFD\u5171\u4EAB\u9884\u7B97\u3002\u4E0D\u6539\u5DF2\u6709\u7CFB\u5217\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--name <name>", "\u9884\u7B97\u540D\u79F0").requiredOption("--amount <yuan>", "\u65E5\u9884\u7B97\uFF0C\u4E3B\u5E01\u79CD\u5143", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131354
+ await runAdSharedBudgetCreate(opts);
131355
+ });
131356
+ sharedBudget.command("update").description("\u6539\u4E00\u4EFD\u5171\u4EAB\u9884\u7B97\u7684\u540D\u79F0\u6216\u91D1\u989D\u3002\u540C\u4E00\u9884\u7B97\u4E0B\u7684\u7CFB\u5217\u4F1A\u4E00\u8D77\u53D8\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--budget-id <id>", "list \u91CC\u7684 id").option("--name <name>", "\u65B0\u540D\u79F0\uFF0C\u4E0D\u4F20\u5219\u4FDD\u6301\u539F\u540D").option("--amount <yuan>", "\u65B0\u65E5\u9884\u7B97\uFF0C\u4E3B\u5E01\u79CD\u5143", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131357
+ await runAdSharedBudgetUpdate(opts);
131358
+ });
131359
+ sharedBudget.command("delete").description("\u5220\u9664\u5171\u4EAB\u9884\u7B97\u3002\u987B --i-confirm\u3002\u4ECD\u88AB\u7CFB\u5217\u4F7F\u7528\u65F6 Google \u4F1A\u62D2\u7EDD").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--budget-id <id>", "list \u91CC\u7684 id").option("--i-confirm", "\u7528\u6237\u5DF2\u786E\u8BA4\u5220\u9664", false).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131360
+ await runAdSharedBudgetDelete(opts);
131361
+ });
131362
+ const audience = adCmd.command("audience").description("\u641C\u7D22\u5E7F\u544A\u7EC4\u53D7\u4F17\uFF1A\u7528\u6237\u5217\u8868\u3001\u5174\u8DA3\u3001\u6027\u522B\u3001\u5E74\u9F84\u3001\u6536\u5165\u3001\u80B2\u513F\u3002\u4E0D\u662F PMax \u53D7\u4F17");
131363
+ audience.command("list").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--kind <kind>", "user-list | user-interest | gender | age | income | parent").requiredOption("--campaign-id <id>", "\u7CFB\u5217 id").requiredOption("--ad-group-id <id>", "\u5E7F\u544A\u7EC4 id").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131364
+ await runAdAudienceList(opts);
131365
+ });
131366
+ audience.command("add").description("\u7ED9\u5E7F\u544A\u7EC4\u52A0\u4E00\u6761\u53D7\u4F17\u3002--bid-modifier \u662F\u500D\u7387\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--kind <kind>", "user-list | user-interest | gender | age | income | parent").requiredOption("--ad-group-id <id>", "\u5E7F\u544A\u7EC4 id").requiredOption("--target <value>", "\u7528\u6237\u5217\u8868/\u5174\u8DA3\u7684\u6570\u5B57 ID\uFF0C\u6216\u679A\u4E3E\u540D\uFF0C\u5982 Male\u3001AgeRange1824").option("--negative", "\u4F5C\u4E3A\u5426\u5B9A\u53D7\u4F17\u3002\u4E0D\u80FD\u548C --bid-modifier \u4E00\u8D77\u7528", false).option("--bid-modifier <multiplier>", "\u500D\u7387\uFF1A1.2 = +20%\uFF0C0 = \u6392\u9664\u3002\u4E0D\u4F20\u8868\u793A\u4E0D\u6539\u51FA\u4EF7", (value) => Number(value)).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131367
+ await runAdAudienceAdd(opts);
131368
+ });
131369
+ adCmd.command("schedule-replace").description("\u6574\u8868\u66FF\u6362\u7CFB\u5217\u6295\u653E\u65F6\u6BB5\u3002\u6587\u4EF6\u6CA1\u5199\u7684\u65E7\u65F6\u6BB5\u4F1A\u88AB\u5220\u6389\u3002\u5199\u64CD\u4F5C\u987B --commit").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "\u7CFB\u5217 id").requiredOption("--file <path>", "JSON \u6570\u7EC4\u3002BidModifier \u662F\u767E\u5206\u6BD4\uFF0C20 = +20%\u3002\u6E05\u7A7A\u4F20 []").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
131370
+ await runAdScheduleReplace(opts);
131371
+ });
130799
131372
  adCmd.command("recommendation-subscriptions").description("\u81EA\u52A8\u5E94\u7528\u5EFA\u8BAE\u7684\u8BA2\u9605\u72B6\u6001\u3002\u53EA\u8BFB\uFF0C\u4E0D\u80FD\u4EE3\u5173\uFF0C\u4E5F\u4E0D\u80FD\u81EA\u52A8\u91C7\u7EB3").allowExcessArguments(false).requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").option("--json-out <path>", "\u843D\u76D8").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
130800
131373
  await runAdRecommendationSubscriptions(opts);
130801
131374
  });
@@ -131042,9 +131615,9 @@ function metaAdContext(token) {
131042
131615
  const config = loadConfig(token);
131043
131616
  return { config, facebookApiUrl: requireFacebookApi(config) };
131044
131617
  }
131045
- function adsUrl(facebookApiUrl, account, path60) {
131618
+ function adsUrl(facebookApiUrl, account, path61) {
131046
131619
  const base2 = metaAdsBaseUrl(facebookApiUrl, account);
131047
- const p = path60.startsWith("/") ? path60 : `/${path60}`;
131620
+ const p = path61.startsWith("/") ? path61 : `/${path61}`;
131048
131621
  return `${base2}${p}`;
131049
131622
  }
131050
131623
  async function metaAdGet(url, config, verbose, action) {
@@ -131371,11 +131944,11 @@ function snapshotSupported(targeting) {
131371
131944
  function diffSnapshots(before, after) {
131372
131945
  const fields = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
131373
131946
  const changes = [];
131374
- for (const field5 of fields) {
131375
- const from = before[field5];
131376
- const to = after[field5];
131947
+ for (const field6 of fields) {
131948
+ const from = before[field6];
131949
+ const to = after[field6];
131377
131950
  const changed = JSON.stringify(from) !== JSON.stringify(to);
131378
- changes.push({ field: field5, from: from ?? null, to: to ?? null, changed });
131951
+ changes.push({ field: field6, from: from ?? null, to: to ?? null, changed });
131379
131952
  }
131380
131953
  return changes;
131381
131954
  }
@@ -131513,7 +132086,7 @@ function formHasPredefinedQuestion(form) {
131513
132086
  }
131514
132087
 
131515
132088
  // src/commands/meta-ad/load.ts
131516
- import { readFileSync as readFileSync15 } from "fs";
132089
+ import { readFileSync as readFileSync16 } from "fs";
131517
132090
  function stripMetaKeys2(value) {
131518
132091
  if (Array.isArray(value)) {
131519
132092
  return value.map((item) => stripMetaKeys2(item));
@@ -131530,7 +132103,7 @@ function stripMetaKeys2(value) {
131530
132103
  }
131531
132104
  function tryLoadJsonFile(configFile) {
131532
132105
  try {
131533
- return JSON.parse(readFileSync15(configFile, "utf8"));
132106
+ return JSON.parse(readFileSync16(configFile, "utf8"));
131534
132107
  } catch {
131535
132108
  return null;
131536
132109
  }
@@ -131561,10 +132134,10 @@ function loadMetaLeadFormConfig(configFile) {
131561
132134
  }
131562
132135
 
131563
132136
  // src/commands/meta-ad/images.ts
131564
- import { readFileSync as readFileSync16 } from "fs";
132137
+ import { readFileSync as readFileSync17 } from "fs";
131565
132138
  import { basename as basename9 } from "path";
131566
132139
  function readImageBytesBase64(imagePath) {
131567
- const buf = readFileSync16(imagePath);
132140
+ const buf = readFileSync17(imagePath);
131568
132141
  if (buf.length < 1 || buf.length > 8 * 1024 * 1024) {
131569
132142
  throw new Error(`\u56FE\u7247\u5927\u5C0F\u987B\u4E3A 1 \u5B57\u8282\uFF5E8MB\uFF0C\u5F53\u524D ${buf.length} \u5B57\u8282`);
131570
132143
  }
@@ -132251,9 +132824,9 @@ async function runMetaAdForms(opts) {
132251
132824
  if (opts.after) params.set("after", opts.after);
132252
132825
  if (opts.before) params.set("before", opts.before);
132253
132826
  const qs = params.toString();
132254
- const path60 = `/pages/${encodeURIComponent(opts.pageId)}/forms${qs ? `?${qs}` : ""}`;
132827
+ const path61 = `/pages/${encodeURIComponent(opts.pageId)}/forms${qs ? `?${qs}` : ""}`;
132255
132828
  const raw = await metaAdGet(
132256
- adsUrl(facebookApiUrl, digits, path60),
132829
+ adsUrl(facebookApiUrl, digits, path61),
132257
132830
  config,
132258
132831
  opts.verbose,
132259
132832
  "\u5217\u8868\u5355\u5931\u8D25"
@@ -132348,8 +132921,8 @@ async function runMetaAdFormCreate(opts) {
132348
132921
 
132349
132922
  // src/commands/meta-ad/plan-render.ts
132350
132923
  init_xlsx_style_engine();
132351
- import fs14 from "fs";
132352
- import path19 from "path";
132924
+ import fs15 from "fs";
132925
+ import path20 from "path";
132353
132926
  init_html();
132354
132927
  init_lang();
132355
132928
  var PENDING = "[\u5F85\u8865]";
@@ -132737,18 +133310,18 @@ function writeMetaLeadPlanExcel(outPath, cfg, lang = "zh") {
132737
133310
  return writeOpsExcel(outPath, cfg, lang);
132738
133311
  }
132739
133312
  function writeMetaLeadPlanMarkdown(outPath, cfg, lang = "zh") {
132740
- const abs = path19.resolve(outPath);
132741
- fs14.mkdirSync(path19.dirname(abs), { recursive: true });
132742
- fs14.writeFileSync(abs, renderMarkdown(cfg, lang), "utf8");
133313
+ const abs = path20.resolve(outPath);
133314
+ fs15.mkdirSync(path20.dirname(abs), { recursive: true });
133315
+ fs15.writeFileSync(abs, renderMarkdown(cfg, lang), "utf8");
132743
133316
  return abs;
132744
133317
  }
132745
133318
  async function runMetaAdPlanRender(opts) {
132746
133319
  const cfg = loadMetaLeadCreateConfig(opts.configFile);
132747
133320
  const lang = readReportLangOrExit({ flag: opts.lang });
132748
- const configDir = path19.dirname(path19.resolve(opts.configFile));
132749
- const xlsxOut = path19.resolve(opts.out || path19.join(configDir, "meta-lead-plan.xlsx"));
132750
- const mdOut = path19.resolve(
132751
- opts.mdOut || path19.join(path19.dirname(xlsxOut), `${path19.parse(xlsxOut).name}.md`)
133321
+ const configDir = path20.dirname(path20.resolve(opts.configFile));
133322
+ const xlsxOut = path20.resolve(opts.out || path20.join(configDir, "meta-lead-plan.xlsx"));
133323
+ const mdOut = path20.resolve(
133324
+ opts.mdOut || path20.join(path20.dirname(xlsxOut), `${path20.parse(xlsxOut).name}.md`)
132752
133325
  );
132753
133326
  const xlsxPath = writeMetaLeadPlanExcel(xlsxOut, cfg, lang);
132754
133327
  const mdPath = writeMetaLeadPlanMarkdown(mdOut, cfg, lang);
@@ -136988,8 +137561,8 @@ async function runOpenAccountYandex(opts) {
136988
137561
 
136989
137562
  // src/commands/open-account/bing.ts
136990
137563
  init_auth();
136991
- import * as fs15 from "fs";
136992
- import * as path20 from "path";
137564
+ import * as fs16 from "fs";
137565
+ import * as path21 from "path";
136993
137566
  init_cli_json_snapshot();
136994
137567
 
136995
137568
  // src/commands/open-account/bing-industry-dict.ts
@@ -137117,8 +137690,8 @@ async function fetchBingIndustryOptions(config, verbose) {
137117
137690
 
137118
137691
  // src/commands/open-account/bing.ts
137119
137692
  async function uploadAttachment(filePath, apiBaseUrl, config, verbose) {
137120
- const fileName = path20.basename(filePath);
137121
- const fileBuffer = fs15.readFileSync(filePath);
137693
+ const fileName = path21.basename(filePath);
137694
+ const fileBuffer = fs16.readFileSync(filePath);
137122
137695
  const mimeType = guessContentType2(fileName);
137123
137696
  const form = new FormData();
137124
137697
  form.append("file", new Blob([fileBuffer], { type: mimeType }), fileName);
@@ -137146,7 +137719,7 @@ async function uploadAttachment(filePath, apiBaseUrl, config, verbose) {
137146
137719
  return { id: data.id, fileName, storageProvider: data.storageProvider ?? "StorageAccount" };
137147
137720
  }
137148
137721
  function guessContentType2(fileName) {
137149
- const ext = path20.extname(fileName).toLowerCase();
137722
+ const ext = path21.extname(fileName).toLowerCase();
137150
137723
  const map = {
137151
137724
  ".jpg": "image/jpeg",
137152
137725
  ".jpeg": "image/jpeg",
@@ -137159,7 +137732,7 @@ function guessContentType2(fileName) {
137159
137732
  }
137160
137733
  async function runOpenAccountBing(opts) {
137161
137734
  const config = loadConfig(opts.token);
137162
- if (!fs15.existsSync(opts.licenseFile)) {
137735
+ if (!fs16.existsSync(opts.licenseFile)) {
137163
137736
  console.error(`
137164
137737
  \u274C \u8425\u4E1A\u6267\u7167\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${opts.licenseFile}
137165
137738
  `);
@@ -137661,13 +138234,13 @@ Google \u5F00\u6237\u884C\u4E1A\uFF08\u7B2C 1 \u9875\uFF0C\u672C\u9875 ${rows.le
137661
138234
 
137662
138235
  // src/commands/open-account/tiktok.ts
137663
138236
  init_auth();
137664
- import * as fs16 from "fs";
137665
- import * as path21 from "path";
138237
+ import * as fs17 from "fs";
138238
+ import * as path22 from "path";
137666
138239
  init_cli_json_snapshot();
137667
138240
  init_cli_table();
137668
138241
  async function uploadLicenseToTikTok(filePath, businessCentreType, config, verbose) {
137669
- const fileName = path21.basename(filePath);
137670
- const fileBuffer = fs16.readFileSync(filePath);
138242
+ const fileName = path22.basename(filePath);
138243
+ const fileBuffer = fs17.readFileSync(filePath);
137671
138244
  const base64Image = fileBuffer.toString("base64");
137672
138245
  const res = await apiFetch2(
137673
138246
  `${config.apiBaseUrl}/command/media-account/tiktok/Upload`,
@@ -137692,7 +138265,7 @@ async function uploadLicenseToTikTok(filePath, businessCentreType, config, verbo
137692
138265
  async function runOpenAccountTikTok(opts) {
137693
138266
  const config = loadConfig(opts.token);
137694
138267
  const bcType = opts.businessCentreType ?? "Shop";
137695
- if (!fs16.existsSync(opts.licenseFile)) {
138268
+ if (!fs17.existsSync(opts.licenseFile)) {
137696
138269
  console.error(`
137697
138270
  \u274C \u8425\u4E1A\u6267\u7167\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${opts.licenseFile}
137698
138271
  `);
@@ -138683,8 +139256,8 @@ function attachLandingPageMeta(lighthouse, resolved) {
138683
139256
  // src/commands/website-diagnosis/shared.ts
138684
139257
  init_dist();
138685
139258
  init_auth();
138686
- import fs17 from "fs/promises";
138687
- import path22 from "path";
139259
+ import fs18 from "fs/promises";
139260
+ import path23 from "path";
138688
139261
  var HTML_FETCH_TIMEOUT_MS = 2e4;
138689
139262
  var HTML_FETCH_MAX_BYTES = 5 * 1024 * 1024;
138690
139263
  var HTML_FETCH_MAX_REDIRECTS = 5;
@@ -138748,17 +139321,17 @@ async function fetchWebsiteHtml(websiteUrl, verbose) {
138748
139321
  }
138749
139322
  }
138750
139323
  async function readWebsiteHtmlFile(filePath) {
138751
- const abs = path22.resolve(filePath);
139324
+ const abs = path23.resolve(filePath);
138752
139325
  let size = 0;
138753
139326
  try {
138754
- const stat2 = await fs17.stat(abs);
139327
+ const stat2 = await fs18.stat(abs);
138755
139328
  if (!stat2.isFile()) throw new Error(`\u9996\u9875 HTML \u4E0D\u662F\u6587\u4EF6\uFF1A${abs}`);
138756
139329
  size = stat2.size;
138757
139330
  } catch (err) {
138758
139331
  if (err instanceof Error && err.message.startsWith("\u9996\u9875 HTML")) throw err;
138759
139332
  throw new Error(`\u627E\u4E0D\u5230\u9996\u9875 HTML\uFF1A${abs}`);
138760
139333
  }
138761
- const fh = await fs17.open(abs, "r");
139334
+ const fh = await fs18.open(abs, "r");
138762
139335
  try {
138763
139336
  const len = Math.min(size, HTML_FETCH_MAX_BYTES);
138764
139337
  const buf = Buffer.alloc(len);
@@ -138936,10 +139509,10 @@ async function runWebsiteDiagnosisCollect(opts) {
138936
139509
 
138937
139510
  // src/commands/website-diagnosis/prepare.ts
138938
139511
  init_cli_json_snapshot();
138939
- import fs18 from "fs";
138940
- import path23 from "path";
139512
+ import fs19 from "fs";
139513
+ import path24 from "path";
138941
139514
  function readJson(filePath) {
138942
- const text5 = fs18.readFileSync(filePath, "utf8");
139515
+ const text5 = fs19.readFileSync(filePath, "utf8");
138943
139516
  try {
138944
139517
  const v = JSON.parse(text5);
138945
139518
  if (!v || typeof v !== "object" || Array.isArray(v)) {
@@ -138969,8 +139542,8 @@ function signalsFromCollectPayload(collect) {
138969
139542
  });
138970
139543
  }
138971
139544
  async function runWebsiteDiagnosisPrepare(opts) {
138972
- const collectPath = path23.resolve(opts.collectFile);
138973
- if (!fs18.existsSync(collectPath)) {
139545
+ const collectPath = path24.resolve(opts.collectFile);
139546
+ if (!fs19.existsSync(collectPath)) {
138974
139547
  console.error(`
138975
139548
  \u274C \u627E\u4E0D\u5230 collect \u6587\u4EF6\uFF1A${collectPath}
138976
139549
  `);
@@ -138979,11 +139552,11 @@ async function runWebsiteDiagnosisPrepare(opts) {
138979
139552
  const collect = readJson(collectPath);
138980
139553
  const signals = signalsFromCollectPayload(collect);
138981
139554
  const scaffold = buildDiagnosisScaffold(signals);
138982
- const outPath = path23.resolve(
138983
- opts.out ?? path23.join(path23.dirname(collectPath), "diagnosis.scaffold.json")
139555
+ const outPath = path24.resolve(
139556
+ opts.out ?? path24.join(path24.dirname(collectPath), "diagnosis.scaffold.json")
138984
139557
  );
138985
- fs18.mkdirSync(path23.dirname(outPath), { recursive: true });
138986
- fs18.writeFileSync(outPath, JSON.stringify(scaffold, null, 2), "utf8");
139558
+ fs19.mkdirSync(path24.dirname(outPath), { recursive: true });
139559
+ fs19.writeFileSync(outPath, JSON.stringify(scaffold, null, 2), "utf8");
138987
139560
  const summary = {
138988
139561
  url: signals.url,
138989
139562
  out: outPath,
@@ -139022,9 +139595,9 @@ async function runWebsiteDiagnosisPrepare(opts) {
139022
139595
  // src/commands/website-diagnosis/render-report.ts
139023
139596
  init_lang();
139024
139597
  init_html();
139025
- import fs19 from "fs";
139598
+ import fs20 from "fs";
139026
139599
  import fsPromises from "fs/promises";
139027
- import path24 from "path";
139600
+ import path25 from "path";
139028
139601
  import { fileURLToPath as fileURLToPath4 } from "url";
139029
139602
 
139030
139603
  // src/commands/website-diagnosis/tracking-probe.ts
@@ -139270,14 +139843,14 @@ var TEMPLATE_BASENAMES = {
139270
139843
  runtime: "website-diagnosis-report.runtime.js"
139271
139844
  };
139272
139845
  function resolveSkillTemplatePath(basename13) {
139273
- const dir = path24.dirname(fileURLToPath4(import.meta.url));
139846
+ const dir = path25.dirname(fileURLToPath4(import.meta.url));
139274
139847
  const candidates = [
139275
- path24.join(dir, "skill", "report-templates", basename13),
139276
- path24.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
139277
- path24.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
139848
+ path25.join(dir, "skill", "report-templates", basename13),
139849
+ path25.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
139850
+ path25.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
139278
139851
  ];
139279
139852
  for (const p of candidates) {
139280
- if (fs19.existsSync(p)) return p;
139853
+ if (fs20.existsSync(p)) return p;
139281
139854
  }
139282
139855
  return candidates[0];
139283
139856
  }
@@ -139369,14 +139942,14 @@ function injectReportData(html, payload, lang) {
139369
139942
  return localized.replace(marker, `window.__WEBSITE_DIAGNOSIS__ = ${json};`);
139370
139943
  }
139371
139944
  async function runWebsiteDiagnosisRender(opts) {
139372
- const dataPath = path24.resolve(opts.dataFile);
139945
+ const dataPath = path25.resolve(opts.dataFile);
139373
139946
  const dataRaw = await readJsonFile(dataPath);
139374
139947
  let data = asRecord6(dataRaw);
139375
139948
  if (opts.collectFile) {
139376
- const collectRaw = await readJsonFile(path24.resolve(opts.collectFile));
139949
+ const collectRaw = await readJsonFile(path25.resolve(opts.collectFile));
139377
139950
  data = mergeCollectLighthouse(data, asRecord6(collectRaw));
139378
139951
  }
139379
- const trackingSource = opts.trackingFile ? await readJsonFile(path24.resolve(opts.trackingFile)) : data.tracking;
139952
+ const trackingSource = opts.trackingFile ? await readJsonFile(path25.resolve(opts.trackingFile)) : data.tracking;
139380
139953
  let tracking;
139381
139954
  try {
139382
139955
  tracking = readTrackingForReport(trackingSource);
@@ -139407,14 +139980,14 @@ async function runWebsiteDiagnosisRender(opts) {
139407
139980
  `);
139408
139981
  process.exit(1);
139409
139982
  }
139410
- const outPath = path24.resolve(
139411
- opts.out ?? path24.join(path24.dirname(dataPath), "website-diagnosis-report.html")
139983
+ const outPath = path25.resolve(
139984
+ opts.out ?? path25.join(path25.dirname(dataPath), "website-diagnosis-report.html")
139412
139985
  );
139413
- const outDir = path24.dirname(outPath);
139986
+ const outDir = path25.dirname(outPath);
139414
139987
  await fsPromises.mkdir(outDir, { recursive: true });
139415
139988
  await fsPromises.writeFile(outPath, injectReportData(html, data, lang), "utf8");
139416
139989
  const runtimeSrc = websiteDiagnosisRuntimePath();
139417
- const runtimeOut = path24.join(outDir, TEMPLATE_BASENAMES.runtime);
139990
+ const runtimeOut = path25.join(outDir, TEMPLATE_BASENAMES.runtime);
139418
139991
  let runtimeCopied = false;
139419
139992
  try {
139420
139993
  await fsPromises.copyFile(runtimeSrc, runtimeOut);
@@ -139625,8 +140198,8 @@ async function runMarketAnalysisCollect(opts) {
139625
140198
  }
139626
140199
 
139627
140200
  // src/commands/market-analysis/render-report.ts
139628
- import fs20 from "fs/promises";
139629
- import path25 from "path";
140201
+ import fs21 from "fs/promises";
140202
+ import path26 from "path";
139630
140203
 
139631
140204
  // src/commands/market-analysis/report-content.ts
139632
140205
  var SILUZAN_ECHARTS_CDN_URL = "https://staticpn.siluzan.com/assets/slz/homeCDN/echarts.min.js";
@@ -140082,10 +140655,10 @@ function resolveMarketAnalysisHtml(data) {
140082
140655
  throw new Error("JSON \u4E2D\u7F3A\u5C11 htmlContent \u6216 rawResponse \u5B57\u6BB5");
140083
140656
  }
140084
140657
  async function runMarketAnalysisRender(opts) {
140085
- const dataPath = path25.resolve(opts.dataFile);
140658
+ const dataPath = path26.resolve(opts.dataFile);
140086
140659
  let dataRaw;
140087
140660
  try {
140088
- dataRaw = JSON.parse(await fs20.readFile(dataPath, "utf8"));
140661
+ dataRaw = JSON.parse(await fs21.readFile(dataPath, "utf8"));
140089
140662
  } catch {
140090
140663
  console.error(`
140091
140664
  \u274C \u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${dataPath}
@@ -140128,11 +140701,11 @@ async function runMarketAnalysisRender(opts) {
140128
140701
  );
140129
140702
  process.exit(1);
140130
140703
  }
140131
- const outPath = path25.resolve(
140132
- opts.out ?? path25.join(path25.dirname(dataPath), "market-analysis-report.html")
140704
+ const outPath = path26.resolve(
140705
+ opts.out ?? path26.join(path26.dirname(dataPath), "market-analysis-report.html")
140133
140706
  );
140134
- await fs20.mkdir(path25.dirname(outPath), { recursive: true });
140135
- await fs20.writeFile(outPath, html, "utf8");
140707
+ await fs21.mkdir(path26.dirname(outPath), { recursive: true });
140708
+ await fs21.writeFile(outPath, html, "utf8");
140136
140709
  const { stats } = contentCheck;
140137
140710
  console.log(`
140138
140711
  \u2705 \u5E02\u573A\u5206\u6790 HTML \u62A5\u544A\u5DF2\u751F\u6210\uFF1A${outPath}
@@ -140179,12 +140752,12 @@ function registerMarketAnalysisCommands(program2) {
140179
140752
 
140180
140753
  // src/commands/google-ads-diagnosis/run-collect.ts
140181
140754
  init_auth();
140182
- import fs25 from "fs/promises";
140183
- import path29 from "path";
140755
+ import fs26 from "fs/promises";
140756
+ import path30 from "path";
140184
140757
 
140185
140758
  // src/commands/google-ads-diagnosis/shared.ts
140186
- import fs21 from "fs";
140187
- import path26 from "path";
140759
+ import fs22 from "fs";
140760
+ import path27 from "path";
140188
140761
  import { fileURLToPath as fileURLToPath5 } from "url";
140189
140762
  var GOOGLE_ADS_DIAGNOSIS_TEMPLATE_BASENAME = "GoogleAdsDiagnosisReport.html";
140190
140763
  var GOOGLE_ADS_DIAGNOSIS_DATA_MARKER = "__REPORT_DATA__";
@@ -140241,15 +140814,15 @@ function buildGoogleAdsDiagnosisNarrativeChecks() {
140241
140814
  }
140242
140815
  var GOOGLE_ADS_DIAGNOSIS_NARRATIVE_CHECKS = buildGoogleAdsDiagnosisNarrativeChecks();
140243
140816
  function resolveSkillTemplatePath2(basename13) {
140244
- const dir = path26.dirname(fileURLToPath5(import.meta.url));
140817
+ const dir = path27.dirname(fileURLToPath5(import.meta.url));
140245
140818
  const candidates = [
140246
- path26.join(dir, "skill", "report-templates", basename13),
140247
- path26.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
140248
- path26.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13),
140249
- path26.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
140819
+ path27.join(dir, "skill", "report-templates", basename13),
140820
+ path27.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
140821
+ path27.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13),
140822
+ path27.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
140250
140823
  ];
140251
140824
  for (const p of candidates) {
140252
- if (fs21.existsSync(p)) return p;
140825
+ if (fs22.existsSync(p)) return p;
140253
140826
  }
140254
140827
  return candidates[0];
140255
140828
  }
@@ -140279,8 +140852,8 @@ function buildGoogleAdsDiagnosisCollectAgentHint(snapDir) {
140279
140852
  }
140280
140853
 
140281
140854
  // src/commands/google-ads-diagnosis/build-report-data.ts
140282
- import fs23 from "fs";
140283
- import path28 from "path";
140855
+ import fs24 from "fs";
140856
+ import path29 from "path";
140284
140857
 
140285
140858
  // src/commands/google-ads-diagnosis/agent-brief.ts
140286
140859
  function buildGoogleAdsDiagnosisAgentBrief(input) {
@@ -140349,8 +140922,8 @@ function buildGoogleAdsDiagnosisAgentBrief(input) {
140349
140922
 
140350
140923
  // src/commands/google-ads-diagnosis/snapshot-io.ts
140351
140924
  init_google_analysis_snapshot();
140352
- import fs22 from "fs";
140353
- import path27 from "path";
140925
+ import fs23 from "fs";
140926
+ import path28 from "path";
140354
140927
  function dateRangeManifest(start, end) {
140355
140928
  if (start && end) return { mode: "range", start, end };
140356
140929
  return null;
@@ -140361,17 +140934,17 @@ function findSectionSnapshotFile(snapDir, section, accountId, start, end) {
140361
140934
  accountId,
140362
140935
  dateRangeManifest(start, end)
140363
140936
  );
140364
- const exactPath = path27.join(snapDir, exactName);
140365
- if (fs22.existsSync(exactPath)) return exactPath;
140937
+ const exactPath = path28.join(snapDir, exactName);
140938
+ if (fs23.existsSync(exactPath)) return exactPath;
140366
140939
  if (start && end) return void 0;
140367
- const files = fs22.readdirSync(snapDir);
140368
- return files.filter((f) => f.startsWith(`${section}-${accountId}`) && f.endsWith(".json")).sort().map((f) => path27.join(snapDir, f)).at(-1);
140940
+ const files = fs23.readdirSync(snapDir);
140941
+ return files.filter((f) => f.startsWith(`${section}-${accountId}`) && f.endsWith(".json")).sort().map((f) => path28.join(snapDir, f)).at(-1);
140369
140942
  }
140370
140943
  function loadSectionSnapshot(snapDir, section, accountId, start, end) {
140371
140944
  const file = findSectionSnapshotFile(snapDir, section, accountId, start, end);
140372
- if (!file || !fs22.existsSync(file)) return null;
140945
+ if (!file || !fs23.existsSync(file)) return null;
140373
140946
  try {
140374
- return JSON.parse(fs22.readFileSync(file, "utf8"));
140947
+ return JSON.parse(fs23.readFileSync(file, "utf8"));
140375
140948
  } catch {
140376
140949
  return null;
140377
140950
  }
@@ -140817,10 +141390,10 @@ function toDailyConversionItem(row) {
140817
141390
  };
140818
141391
  }
140819
141392
  function loadCompanyNameFromSnap(snapDir) {
140820
- const file = path28.join(snapDir, "list-accounts-google.json");
140821
- if (!fs23.existsSync(file)) return void 0;
141393
+ const file = path29.join(snapDir, "list-accounts-google.json");
141394
+ if (!fs24.existsSync(file)) return void 0;
140822
141395
  try {
140823
- const parsed = JSON.parse(fs23.readFileSync(file, "utf8"));
141396
+ const parsed = JSON.parse(fs24.readFileSync(file, "utf8"));
140824
141397
  const item = parsed.items?.[0];
140825
141398
  return item?.ma?.mediaCustomerName?.trim() || item?.mag?.advertiserName?.trim() || void 0;
140826
141399
  } catch {
@@ -141477,7 +142050,7 @@ function invokeGoogleAnalysisCli(opts) {
141477
142050
  }
141478
142051
 
141479
142052
  // src/commands/google-ads-diagnosis/write-draft.ts
141480
- import fs24 from "fs/promises";
142053
+ import fs25 from "fs/promises";
141481
142054
  function asRecord11(value) {
141482
142055
  if (value && typeof value === "object" && !Array.isArray(value)) {
141483
142056
  return value;
@@ -141505,12 +142078,12 @@ function hasAgentNarrative(data) {
141505
142078
  }
141506
142079
  async function writeDiagnosisDraft(opts) {
141507
142080
  try {
141508
- const existing = JSON.parse(await fs24.readFile(opts.draftPath, "utf8"));
142081
+ const existing = JSON.parse(await fs25.readFile(opts.draftPath, "utf8"));
141509
142082
  const record2 = asRecord11(existing);
141510
142083
  if (record2 && hasAgentNarrative(record2)) return "skipped-existing-narrative";
141511
142084
  } catch {
141512
142085
  }
141513
- await fs24.writeFile(opts.draftPath, `${JSON.stringify(opts.reportData, null, 2)}
142086
+ await fs25.writeFile(opts.draftPath, `${JSON.stringify(opts.reportData, null, 2)}
141514
142087
  `, "utf8");
141515
142088
  return "written";
141516
142089
  }
@@ -141547,8 +142120,8 @@ async function runGoogleAdsDiagnosisCollect(opts) {
141547
142120
  console.error("\n\u274C collect \u987B\u540C\u65F6\u6307\u5B9A --start \u4E0E --end\u3002\n");
141548
142121
  process.exit(1);
141549
142122
  }
141550
- const snapDir = path29.resolve(opts.jsonOut);
141551
- await fs25.mkdir(snapDir, { recursive: true });
142123
+ const snapDir = path30.resolve(opts.jsonOut);
142124
+ await fs26.mkdir(snapDir, { recursive: true });
141552
142125
  let degraded = false;
141553
142126
  console.error(`
141554
142127
  \u{1F4E5} google-analysis \u62C9\u6570\uFF1A\u8D26\u6237 ${accountId}\uFF0C${opts.start} ~ ${opts.end}
@@ -141644,13 +142217,13 @@ async function runGoogleAdsDiagnosisCollect(opts) {
141644
142217
  agentBrief,
141645
142218
  agentHint: buildGoogleAdsDiagnosisCollectAgentHint(snapDir)
141646
142219
  };
141647
- const collectPath = path29.join(snapDir, GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME);
141648
- await fs25.writeFile(collectPath, `${JSON.stringify(collectPayload, null, 2)}
142220
+ const collectPath = path30.join(snapDir, GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME);
142221
+ await fs26.writeFile(collectPath, `${JSON.stringify(collectPayload, null, 2)}
141649
142222
  `, "utf8");
141650
- const draftPath = path29.join(snapDir, GOOGLE_ADS_DIAGNOSIS_REPORT_BASENAME);
142223
+ const draftPath = path30.join(snapDir, GOOGLE_ADS_DIAGNOSIS_REPORT_BASENAME);
141651
142224
  const draftOutcome = await writeDiagnosisDraft({ draftPath, reportData });
141652
- const digestPath = path29.join(snapDir, GOOGLE_ADS_DIAGNOSIS_DIGEST_BASENAME);
141653
- await fs25.writeFile(
142225
+ const digestPath = path30.join(snapDir, GOOGLE_ADS_DIAGNOSIS_DIGEST_BASENAME);
142226
+ await fs26.writeFile(
141654
142227
  digestPath,
141655
142228
  buildCollectDigest(reportData, {
141656
142229
  accountId,
@@ -141692,8 +142265,8 @@ async function runGoogleAdsDiagnosisCollect(opts) {
141692
142265
  }
141693
142266
 
141694
142267
  // src/commands/google-ads-diagnosis/render-report.ts
141695
- import fs26 from "fs/promises";
141696
- import path30 from "path";
142268
+ import fs27 from "fs/promises";
142269
+ import path31 from "path";
141697
142270
 
141698
142271
  // src/commands/google-ads-diagnosis/report-content.ts
141699
142272
  function asRecord12(value) {
@@ -141702,9 +142275,9 @@ function asRecord12(value) {
141702
142275
  }
141703
142276
  return null;
141704
142277
  }
141705
- function getNestedValue(root, path60) {
142278
+ function getNestedValue(root, path61) {
141706
142279
  let cur = root;
141707
- for (const key of path60) {
142280
+ for (const key of path61) {
141708
142281
  const rec = asRecord12(cur);
141709
142282
  if (!rec) return void 0;
141710
142283
  cur = rec[key];
@@ -142359,7 +142932,7 @@ function asRecord17(value) {
142359
142932
  }
142360
142933
  async function tryLoadCollectReportData(collectPath) {
142361
142934
  try {
142362
- const raw = JSON.parse(await fs26.readFile(collectPath, "utf8"));
142935
+ const raw = JSON.parse(await fs27.readFile(collectPath, "utf8"));
142363
142936
  const root = asRecord17(raw);
142364
142937
  const reportData = asRecord17(root?.reportData);
142365
142938
  return reportData ?? root;
@@ -142368,10 +142941,10 @@ async function tryLoadCollectReportData(collectPath) {
142368
142941
  }
142369
142942
  }
142370
142943
  async function runGoogleAdsDiagnosisRender(opts) {
142371
- const dataPath = path30.resolve(opts.dataFile);
142944
+ const dataPath = path31.resolve(opts.dataFile);
142372
142945
  let dataRaw;
142373
142946
  try {
142374
- dataRaw = JSON.parse(await fs26.readFile(dataPath, "utf8"));
142947
+ dataRaw = JSON.parse(await fs27.readFile(dataPath, "utf8"));
142375
142948
  } catch {
142376
142949
  console.error(`
142377
142950
  \u274C \u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${dataPath}
@@ -142380,8 +142953,8 @@ async function runGoogleAdsDiagnosisRender(opts) {
142380
142953
  }
142381
142954
  let data = asRecord17(dataRaw);
142382
142955
  if (!opts.noMergeCollect) {
142383
- const collectPath = path30.resolve(
142384
- opts.collectFile ?? path30.join(path30.dirname(dataPath), GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME)
142956
+ const collectPath = path31.resolve(
142957
+ opts.collectFile ?? path31.join(path31.dirname(dataPath), GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME)
142385
142958
  );
142386
142959
  const collectReportData = await tryLoadCollectReportData(collectPath);
142387
142960
  if (collectReportData) {
@@ -142410,7 +142983,7 @@ async function runGoogleAdsDiagnosisRender(opts) {
142410
142983
  }
142411
142984
  }
142412
142985
  }
142413
- data = reconcileGoldAccountInReport(data, path30.dirname(dataPath));
142986
+ data = reconcileGoldAccountInReport(data, path31.dirname(dataPath));
142414
142987
  data = applyDataRenderedCopy(data);
142415
142988
  const overview = normalizeDiagnosisOverview(data);
142416
142989
  data = overview.data;
@@ -142466,7 +143039,7 @@ async function runGoogleAdsDiagnosisRender(opts) {
142466
143039
  const templatePath = googleAdsDiagnosisReportTemplatePath();
142467
143040
  let html;
142468
143041
  try {
142469
- html = await fs26.readFile(templatePath, "utf8");
143042
+ html = await fs27.readFile(templatePath, "utf8");
142470
143043
  } catch {
142471
143044
  console.error(`
142472
143045
  \u274C \u672A\u627E\u5230\u62A5\u544A\u6A21\u677F\uFF1A${templatePath}
@@ -142485,11 +143058,11 @@ async function runGoogleAdsDiagnosisRender(opts) {
142485
143058
  `);
142486
143059
  process.exit(1);
142487
143060
  }
142488
- const outPath = path30.resolve(
142489
- opts.out ?? path30.join(path30.dirname(dataPath), "google-ads-diagnosis-report.html")
143061
+ const outPath = path31.resolve(
143062
+ opts.out ?? path31.join(path31.dirname(dataPath), "google-ads-diagnosis-report.html")
142490
143063
  );
142491
- await fs26.mkdir(path30.dirname(outPath), { recursive: true });
142492
- await fs26.writeFile(outPath, rendered, "utf8");
143064
+ await fs27.mkdir(path31.dirname(outPath), { recursive: true });
143065
+ await fs27.writeFile(outPath, rendered, "utf8");
142493
143066
  console.log(`
142494
143067
  \u2705 Google \u5E7F\u544A\u8BCA\u65AD HTML \u62A5\u544A\u5DF2\u751F\u6210\uFF1A${outPath}
142495
143068
  `);
@@ -142557,8 +143130,8 @@ function registerGoogleAdsDiagnosisCommands(program2) {
142557
143130
 
142558
143131
  // src/commands/google-quarterly/run-collect.ts
142559
143132
  init_auth();
142560
- import fs29 from "fs/promises";
142561
- import path33 from "path";
143133
+ import fs30 from "fs/promises";
143134
+ import path34 from "path";
142562
143135
 
142563
143136
  // src/commands/google-quarterly/drill-country.ts
142564
143137
  init_geo_en2zh();
@@ -143077,31 +143650,31 @@ function buildSpendPlanDefaults(currentSpend) {
143077
143650
  }
143078
143651
 
143079
143652
  // src/commands/google-quarterly/region.ts
143080
- import fs27 from "fs";
143081
- import path31 from "path";
143653
+ import fs28 from "fs";
143654
+ import path32 from "path";
143082
143655
  import { fileURLToPath as fileURLToPath6 } from "url";
143083
143656
  var EAST_ASIA = /* @__PURE__ */ new Set(["\u4E2D\u56FD", "\u65E5\u672C", "\u97E9\u56FD", "\u671D\u9C9C", "\u8499\u53E4", "\u9999\u6E2F", "\u6FB3\u95E8", "\u53F0\u6E7E"]);
143084
143657
  var continentMap = null;
143085
143658
  function continentsPath() {
143086
- const dir = path31.dirname(fileURLToPath6(import.meta.url));
143659
+ const dir = path32.dirname(fileURLToPath6(import.meta.url));
143087
143660
  const candidates = [
143088
143661
  // dist/index.js → dist/skill/references/...
143089
- path31.join(dir, "skill", "references", "analytics", "geo-continents.json"),
143090
- path31.join(dir, "skill", "siluzan-ads", "references", "analytics", "geo-continents.json"),
143662
+ path32.join(dir, "skill", "references", "analytics", "geo-continents.json"),
143663
+ path32.join(dir, "skill", "siluzan-ads", "references", "analytics", "geo-continents.json"),
143091
143664
  // dist/index.js → tso-cli/assets/...
143092
- path31.join(dir, "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json"),
143665
+ path32.join(dir, "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json"),
143093
143666
  // src/commands/google-quarterly/region.ts → tso-cli/assets/...
143094
- path31.join(dir, "..", "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json"),
143095
- path31.join(dir, "..", "..", "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json")
143667
+ path32.join(dir, "..", "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json"),
143668
+ path32.join(dir, "..", "..", "..", "assets", "siluzan-ads", "references", "analytics", "geo-continents.json")
143096
143669
  ];
143097
143670
  for (const p of candidates) {
143098
- if (fs27.existsSync(p)) return p;
143671
+ if (fs28.existsSync(p)) return p;
143099
143672
  }
143100
143673
  return candidates[0];
143101
143674
  }
143102
143675
  function loadContinentMap() {
143103
143676
  if (continentMap) return continentMap;
143104
- const raw = JSON.parse(fs27.readFileSync(continentsPath(), "utf8"));
143677
+ const raw = JSON.parse(fs28.readFileSync(continentsPath(), "utf8"));
143105
143678
  const map = {};
143106
143679
  for (const [k, v] of Object.entries(raw)) {
143107
143680
  if (k.startsWith("_")) continue;
@@ -143537,23 +144110,23 @@ function roundFacts(facts) {
143537
144110
  }
143538
144111
 
143539
144112
  // src/commands/google-quarterly/shared.ts
143540
- import fs28 from "fs";
143541
- import path32 from "path";
144113
+ import fs29 from "fs";
144114
+ import path33 from "path";
143542
144115
  import { fileURLToPath as fileURLToPath7 } from "url";
143543
144116
  var GOOGLE_QUARTERLY_COLLECT_BASENAME = "google-quarterly-collect.json";
143544
144117
  var GOOGLE_QUARTERLY_HTML_BASENAME = "google-quarterly-report.html";
143545
144118
  var GOOGLE_QUARTERLY_TEMPLATE_BASENAME = "google-quarterly-report.html";
143546
144119
  var GOOGLE_QUARTERLY_INJECT_MARKER = "window.__GOOGLE_QUARTERLY_REPORT__ = window.__GOOGLE_QUARTERLY_REPORT__ || null;";
143547
144120
  function googleQuarterlyTemplatePath() {
143548
- const dir = path32.dirname(fileURLToPath7(import.meta.url));
144121
+ const dir = path33.dirname(fileURLToPath7(import.meta.url));
143549
144122
  const candidates = [
143550
- path32.join(dir, "skill", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
143551
- path32.join(dir, "skill", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
143552
- path32.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
143553
- path32.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME)
144123
+ path33.join(dir, "skill", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
144124
+ path33.join(dir, "skill", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
144125
+ path33.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME),
144126
+ path33.join(dir, "..", "..", "..", "assets", "siluzan-ads", "report-templates", GOOGLE_QUARTERLY_TEMPLATE_BASENAME)
143554
144127
  ];
143555
144128
  for (const p of candidates) {
143556
- if (fs28.existsSync(p)) return p;
144129
+ if (fs29.existsSync(p)) return p;
143557
144130
  }
143558
144131
  return candidates[2];
143559
144132
  }
@@ -143579,7 +144152,7 @@ function periodSnap(dir, account, start, end, extra = []) {
143579
144152
  }
143580
144153
  async function readInquiries(file) {
143581
144154
  if (!file?.trim()) return void 0;
143582
- const raw = await fs29.readFile(path33.resolve(file), "utf8");
144155
+ const raw = await fs30.readFile(path34.resolve(file), "utf8");
143583
144156
  return JSON.parse(raw);
143584
144157
  }
143585
144158
  async function runGoogleQuarterlyCollect(opts) {
@@ -143592,8 +144165,8 @@ async function runGoogleQuarterlyCollect(opts) {
143592
144165
  const previous = previousRange(current.start, current.end);
143593
144166
  const yoy = yearOverYearRange(current.start, current.end);
143594
144167
  const months = listMonths(current.start, current.end);
143595
- const snapDir = path33.resolve(opts.jsonOut);
143596
- await fs29.mkdir(snapDir, { recursive: true });
144168
+ const snapDir = path34.resolve(opts.jsonOut);
144169
+ await fs30.mkdir(snapDir, { recursive: true });
143597
144170
  let degraded = false;
143598
144171
  const run = (label2, start, end, sections) => {
143599
144172
  console.error(`
@@ -143721,8 +144294,8 @@ async function runGoogleQuarterlyCollect(opts) {
143721
144294
  planDefaults: facts.planDefaults
143722
144295
  }
143723
144296
  };
143724
- const outFile = path33.join(snapDir, GOOGLE_QUARTERLY_COLLECT_BASENAME);
143725
- await fs29.writeFile(outFile, JSON.stringify(payload, null, 2), "utf8");
144297
+ const outFile = path34.join(snapDir, GOOGLE_QUARTERLY_COLLECT_BASENAME);
144298
+ await fs30.writeFile(outFile, JSON.stringify(payload, null, 2), "utf8");
143726
144299
  console.log(
143727
144300
  JSON.stringify({
143728
144301
  kind: "siluzan-tso-google-quarterly-collect-summary",
@@ -143741,8 +144314,8 @@ async function runGoogleQuarterlyCollect(opts) {
143741
144314
  }
143742
144315
 
143743
144316
  // src/commands/google-quarterly/render-report.ts
143744
- import fs30 from "fs/promises";
143745
- import path35 from "path";
144317
+ import fs31 from "fs/promises";
144318
+ import path36 from "path";
143746
144319
 
143747
144320
  // src/commands/google-quarterly/report-content.ts
143748
144321
  function asRecord18(value) {
@@ -143784,10 +144357,10 @@ function mergeCollectFacts(agentData, collect) {
143784
144357
  }
143785
144358
 
143786
144359
  // src/test-utils/report-echarts.ts
143787
- import { readFileSync as readFileSync19 } from "fs";
143788
- import path34 from "path";
144360
+ import { readFileSync as readFileSync20 } from "fs";
144361
+ import path35 from "path";
143789
144362
  import { fileURLToPath as fileURLToPath8 } from "url";
143790
- var TSO_CLI_ROOT = path34.join(path34.dirname(fileURLToPath8(import.meta.url)), "../..");
144363
+ var TSO_CLI_ROOT = path35.join(path35.dirname(fileURLToPath8(import.meta.url)), "../..");
143791
144364
 
143792
144365
  // src/commands/google-quarterly/render-report.ts
143793
144366
  init_lang();
@@ -143799,22 +144372,22 @@ function asRecord19(value) {
143799
144372
  throw new Error("\u62A5\u544A JSON \u987B\u4E3A\u5BF9\u8C61");
143800
144373
  }
143801
144374
  async function runGoogleQuarterlyRender(opts) {
143802
- const dataPath = path35.resolve(opts.dataFile);
144375
+ const dataPath = path36.resolve(opts.dataFile);
143803
144376
  let agentRaw;
143804
144377
  try {
143805
- agentRaw = JSON.parse(await fs30.readFile(dataPath, "utf8"));
144378
+ agentRaw = JSON.parse(await fs31.readFile(dataPath, "utf8"));
143806
144379
  } catch {
143807
144380
  console.error(`
143808
144381
  \u274C \u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${dataPath}
143809
144382
  `);
143810
144383
  process.exit(1);
143811
144384
  }
143812
- const collectPath = path35.resolve(
143813
- opts.collectFile ?? path35.join(path35.dirname(dataPath), GOOGLE_QUARTERLY_COLLECT_BASENAME)
144385
+ const collectPath = path36.resolve(
144386
+ opts.collectFile ?? path36.join(path36.dirname(dataPath), GOOGLE_QUARTERLY_COLLECT_BASENAME)
143814
144387
  );
143815
144388
  let collectRaw;
143816
144389
  try {
143817
- collectRaw = JSON.parse(await fs30.readFile(collectPath, "utf8"));
144390
+ collectRaw = JSON.parse(await fs31.readFile(collectPath, "utf8"));
143818
144391
  } catch {
143819
144392
  console.error(`
143820
144393
  \u274C \u65E0\u6CD5\u8BFB\u53D6 collect\uFF1A${collectPath}
@@ -143832,15 +144405,15 @@ async function runGoogleQuarterlyRender(opts) {
143832
144405
  const templatePath = googleQuarterlyTemplatePath();
143833
144406
  let html;
143834
144407
  try {
143835
- html = await fs30.readFile(templatePath, "utf8");
144408
+ html = await fs31.readFile(templatePath, "utf8");
143836
144409
  } catch {
143837
144410
  console.error(`
143838
144411
  \u274C \u627E\u4E0D\u5230\u6A21\u677F\uFF1A${templatePath}
143839
144412
  `);
143840
144413
  process.exit(1);
143841
144414
  }
143842
- const outPath = path35.resolve(opts.out ?? path35.join(path35.dirname(dataPath), GOOGLE_QUARTERLY_HTML_BASENAME));
143843
- await fs30.mkdir(path35.dirname(outPath), { recursive: true });
144415
+ const outPath = path36.resolve(opts.out ?? path36.join(path36.dirname(dataPath), GOOGLE_QUARTERLY_HTML_BASENAME));
144416
+ await fs31.mkdir(path36.dirname(outPath), { recursive: true });
143844
144417
  const lang = readReportLangOrExit({ flag: opts.lang, meta: merged.meta });
143845
144418
  const periodChrome = reportPeriodChrome(
143846
144419
  readMetaRange(merged, "current"),
@@ -143856,7 +144429,7 @@ async function runGoogleQuarterlyRender(opts) {
143856
144429
  console.error("\n\u274C \u6A21\u677F\u5FC5\u987B\u4F7F\u7528 ECharts\uFF0C\u7981\u6B62 Chart.js\u3002\n");
143857
144430
  process.exit(1);
143858
144431
  }
143859
- await fs30.writeFile(outPath, outHtml, "utf8");
144432
+ await fs31.writeFile(outPath, outHtml, "utf8");
143860
144433
  console.log(`
143861
144434
  \u2705 ${periodChrome.reportTitle}\u5DF2\u751F\u6210\uFF1A${outPath}
143862
144435
  `);
@@ -143996,14 +144569,14 @@ var FACEBOOK_SECTION_ALIASES = {
143996
144569
  import { Command as Command2 } from "commander";
143997
144570
 
143998
144571
  // src/commands/facebook-analysis/render-report.ts
143999
- import fs39 from "fs";
144572
+ import fs40 from "fs";
144000
144573
  import fsPromises4 from "fs/promises";
144001
- import path46 from "path";
144574
+ import path47 from "path";
144002
144575
  import { fileURLToPath as fileURLToPath11 } from "url";
144003
144576
 
144004
144577
  // src/commands/facebook-analysis/merge-snapshot.ts
144005
- import * as fs38 from "fs/promises";
144006
- import * as path45 from "path";
144578
+ import * as fs39 from "fs/promises";
144579
+ import * as path46 from "path";
144007
144580
 
144008
144581
  // src/commands/facebook-analysis/report-metrics.ts
144009
144582
  function asRecord26(value) {
@@ -144155,7 +144728,7 @@ function hasResults(row) {
144155
144728
 
144156
144729
  // src/commands/facebook-analysis/merge-snapshot.ts
144157
144730
  async function readManifest4(snapshotDir) {
144158
- const entries = await fs38.readdir(snapshotDir);
144731
+ const entries = await fs39.readdir(snapshotDir);
144159
144732
  const manifestNames = entries.filter(
144160
144733
  (n) => n.startsWith("report-manifest") && n.endsWith(".json")
144161
144734
  );
@@ -144165,7 +144738,7 @@ async function readManifest4(snapshotDir) {
144165
144738
  ];
144166
144739
  for (const name2 of ordered) {
144167
144740
  try {
144168
- const raw = await fs38.readFile(path45.join(snapshotDir, name2), "utf8");
144741
+ const raw = await fs39.readFile(path46.join(snapshotDir, name2), "utf8");
144169
144742
  const parsed = JSON.parse(raw);
144170
144743
  if (parsed?.artifacts?.length) return parsed;
144171
144744
  } catch {
@@ -144175,7 +144748,7 @@ async function readManifest4(snapshotDir) {
144175
144748
  }
144176
144749
  async function loadSectionFile3(snapshotDir, file) {
144177
144750
  try {
144178
- const raw = await fs38.readFile(path45.join(snapshotDir, file), "utf8");
144751
+ const raw = await fs39.readFile(path46.join(snapshotDir, file), "utf8");
144179
144752
  return asRecord26(JSON.parse(raw));
144180
144753
  } catch {
144181
144754
  return null;
@@ -144219,7 +144792,7 @@ function mapAdSetRows(groups) {
144219
144792
  })).sort((a, b) => (b.spend ?? 0) - (a.spend ?? 0));
144220
144793
  }
144221
144794
  async function mergeFacebookSnapshotIntoReport(payload, snapshotDir) {
144222
- const absDir = path45.resolve(snapshotDir);
144795
+ const absDir = path46.resolve(snapshotDir);
144223
144796
  const manifest = await readManifest4(snapshotDir);
144224
144797
  if (!manifest) {
144225
144798
  throw new Error(
@@ -144841,14 +145414,14 @@ var TEMPLATE_BASENAMES2 = {
144841
145414
  };
144842
145415
  var INJECT_MARKER2 = "window.__META_PERIOD_REPORT__ = window.__META_PERIOD_REPORT__ || null;";
144843
145416
  function resolveSkillTemplatePath5(basename13) {
144844
- const dir = path46.dirname(fileURLToPath11(import.meta.url));
145417
+ const dir = path47.dirname(fileURLToPath11(import.meta.url));
144845
145418
  const candidates = [
144846
- path46.join(dir, "skill", "report-templates", basename13),
144847
- path46.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
144848
- path46.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
145419
+ path47.join(dir, "skill", "report-templates", basename13),
145420
+ path47.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
145421
+ path47.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
144849
145422
  ];
144850
145423
  for (const p of candidates) {
144851
- if (fs39.existsSync(p)) return p;
145424
+ if (fs40.existsSync(p)) return p;
144852
145425
  }
144853
145426
  return candidates[0];
144854
145427
  }
@@ -144894,7 +145467,7 @@ function injectReportData3(html, payload, lang) {
144894
145467
  }
144895
145468
  function defaultOutPath(dataPath, format, out) {
144896
145469
  if (out?.trim()) {
144897
- const resolved = path46.resolve(out);
145470
+ const resolved = path47.resolve(out);
144898
145471
  if (format === "xlsx" && !/\.xlsx$/i.test(resolved)) {
144899
145472
  return resolved.replace(/\.(html?)$/i, ".xlsx");
144900
145473
  }
@@ -144903,14 +145476,14 @@ function defaultOutPath(dataPath, format, out) {
144903
145476
  }
144904
145477
  return resolved;
144905
145478
  }
144906
- const dir = path46.dirname(dataPath);
144907
- return path46.join(dir, format === "xlsx" ? "meta-period-report.xlsx" : "meta-period-report.html");
145479
+ const dir = path47.dirname(dataPath);
145480
+ return path47.join(dir, format === "xlsx" ? "meta-period-report.xlsx" : "meta-period-report.html");
144908
145481
  }
144909
145482
  async function runFacebookAnalysisRender(opts) {
144910
- const dataPath = path46.resolve(opts.dataFile);
145483
+ const dataPath = path47.resolve(opts.dataFile);
144911
145484
  let data = asRecord29(await readJsonFile5(dataPath));
144912
145485
  if (opts.snapshotDir?.trim()) {
144913
- data = await mergeFacebookSnapshotIntoReport(data, path46.resolve(opts.snapshotDir));
145486
+ data = await mergeFacebookSnapshotIntoReport(data, path47.resolve(opts.snapshotDir));
144914
145487
  }
144915
145488
  localizeFacebookReportLabels(data);
144916
145489
  const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
@@ -144930,7 +145503,7 @@ async function runFacebookAnalysisRender(opts) {
144930
145503
  const written = [];
144931
145504
  for (const format of formats) {
144932
145505
  const outPath = defaultOutPath(dataPath, format, opts.out);
144933
- await fsPromises4.mkdir(path46.dirname(outPath), { recursive: true });
145506
+ await fsPromises4.mkdir(path47.dirname(outPath), { recursive: true });
144934
145507
  if (format === "xlsx") {
144935
145508
  writeMetaPeriodExcel(outPath, data, lang);
144936
145509
  } else {
@@ -144966,14 +145539,14 @@ async function runFacebookAnalysisRender(opts) {
144966
145539
  }
144967
145540
 
144968
145541
  // src/commands/facebook-analysis/diagnosis-render-report.ts
144969
- import fs41 from "fs";
145542
+ import fs42 from "fs";
144970
145543
  import fsPromises5 from "fs/promises";
144971
- import path48 from "path";
145544
+ import path49 from "path";
144972
145545
  import { fileURLToPath as fileURLToPath12 } from "url";
144973
145546
 
144974
145547
  // src/commands/facebook-analysis/diagnosis-merge-snapshot.ts
144975
- import * as fs40 from "fs/promises";
144976
- import * as path47 from "path";
145548
+ import * as fs41 from "fs/promises";
145549
+ import * as path48 from "path";
144977
145550
  function asRecord30(value) {
144978
145551
  if (value && typeof value === "object" && !Array.isArray(value)) {
144979
145552
  return value;
@@ -144984,7 +145557,7 @@ function num9(value) {
144984
145557
  const n = Number(value);
144985
145558
  return Number.isFinite(n) ? n : void 0;
144986
145559
  }
144987
- function asRows(value) {
145560
+ function asRows2(value) {
144988
145561
  return Array.isArray(value) ? value.filter((r) => asRecord30(r) !== null) : [];
144989
145562
  }
144990
145563
  function pickMetricExtras(row, extras) {
@@ -145009,7 +145582,7 @@ async function readManifest5(snapshotDir, accountId) {
145009
145582
  const candidates = [];
145010
145583
  if (accountId) candidates.push(reportManifestFile(accountId));
145011
145584
  try {
145012
- const entries = await fs40.readdir(snapshotDir);
145585
+ const entries = await fs41.readdir(snapshotDir);
145013
145586
  const manifestNames = entries.filter(
145014
145587
  (n) => n.startsWith("report-manifest") && n.endsWith(".json")
145015
145588
  );
@@ -145023,7 +145596,7 @@ async function readManifest5(snapshotDir, accountId) {
145023
145596
  }
145024
145597
  for (const name2 of candidates) {
145025
145598
  try {
145026
- const raw = await fs40.readFile(path47.join(snapshotDir, name2), "utf8");
145599
+ const raw = await fs41.readFile(path48.join(snapshotDir, name2), "utf8");
145027
145600
  const parsed = JSON.parse(raw);
145028
145601
  if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
145029
145602
  } catch {
@@ -145033,14 +145606,14 @@ async function readManifest5(snapshotDir, accountId) {
145033
145606
  }
145034
145607
  async function loadSectionFile4(snapshotDir, file) {
145035
145608
  try {
145036
- const raw = await fs40.readFile(path47.join(snapshotDir, file), "utf8");
145609
+ const raw = await fs41.readFile(path48.join(snapshotDir, file), "utf8");
145037
145610
  return asRecord30(JSON.parse(raw));
145038
145611
  } catch {
145039
145612
  return null;
145040
145613
  }
145041
145614
  }
145042
145615
  async function mergeMetaDiagnosisSnapshotIntoReport(payload, snapshotDir) {
145043
- const absDir = path47.resolve(snapshotDir);
145616
+ const absDir = path48.resolve(snapshotDir);
145044
145617
  const metaAccountId = typeof asRecord30(payload.meta)?.accountId === "string" ? asRecord30(payload.meta)?.accountId : void 0;
145045
145618
  const manifest = await readManifest5(snapshotDir, metaAccountId);
145046
145619
  if (!manifest) {
@@ -145101,38 +145674,38 @@ async function mergeMetaDiagnosisSnapshotIntoReport(payload, snapshotDir) {
145101
145674
  }
145102
145675
  const tables = { ...payload.tables ?? {} };
145103
145676
  {
145104
- const rows = asRows(sectionMap.get("ad-sets")?.adGroups).map(
145677
+ const rows = asRows2(sectionMap.get("ad-sets")?.adGroups).map(
145105
145678
  (r) => pickMetricExtras(r, ["adGroupId", "adGroupName", "campaignName", "spendPercentage"])
145106
145679
  );
145107
145680
  if (rows.length > 0) tables.adSets = rows;
145108
145681
  }
145109
145682
  {
145110
- const rows = asRows(sectionMap.get("platform")?.networks).map(
145683
+ const rows = asRows2(sectionMap.get("platform")?.networks).map(
145111
145684
  (r) => pickMetricExtras(r, ["publisherPlatform", "platformPosition", "network"])
145112
145685
  );
145113
145686
  if (rows.length > 0) tables.platform = rows;
145114
145687
  }
145115
145688
  {
145116
- const rows = asRows(sectionMap.get("country")?.countries).map(
145689
+ const rows = asRows2(sectionMap.get("country")?.countries).map(
145117
145690
  (r) => pickMetricExtras(r, ["countryOrRegion"])
145118
145691
  );
145119
145692
  if (rows.length > 0) tables.country = rows;
145120
145693
  }
145121
145694
  {
145122
- const rows = asRows(sectionMap.get("audience")?.audiences).map(
145695
+ const rows = asRows2(sectionMap.get("audience")?.audiences).map(
145123
145696
  (r) => pickMetricExtras(r, ["age", "gender"])
145124
145697
  );
145125
145698
  if (rows.length > 0) tables.audience = rows;
145126
145699
  }
145127
145700
  {
145128
- const rows = asRows(sectionMap.get("creative")?.creatives).map(
145701
+ const rows = asRows2(sectionMap.get("creative")?.creatives).map(
145129
145702
  (r) => pickMetricExtras(r, ["adId", "adName", "creativeType", "title"])
145130
145703
  );
145131
145704
  if (rows.length > 0) tables.creative = rows;
145132
145705
  }
145133
145706
  {
145134
145707
  const mat = sectionMap.get("material");
145135
- const rows = asRows(mat?.materials).map(
145708
+ const rows = asRows2(mat?.materials).map(
145136
145709
  (r) => pickMetricExtras(r, ["materialId", "materialName", "materialType"])
145137
145710
  );
145138
145711
  if (rows.length > 0) {
@@ -145321,14 +145894,14 @@ init_html();
145321
145894
  var TEMPLATE_BASENAME3 = "meta-account-diagnosis-report.html";
145322
145895
  var INJECT_MARKER3 = "window.__META_DIAGNOSIS_REPORT__ = window.__META_DIAGNOSIS_REPORT__ || null;";
145323
145896
  function resolveSkillTemplatePath6(basename13) {
145324
- const dir = path48.dirname(fileURLToPath12(import.meta.url));
145897
+ const dir = path49.dirname(fileURLToPath12(import.meta.url));
145325
145898
  const candidates = [
145326
- path48.join(dir, "skill", "report-templates", basename13),
145327
- path48.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
145328
- path48.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
145899
+ path49.join(dir, "skill", "report-templates", basename13),
145900
+ path49.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
145901
+ path49.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
145329
145902
  ];
145330
145903
  for (const p of candidates) {
145331
- if (fs41.existsSync(p)) return p;
145904
+ if (fs42.existsSync(p)) return p;
145332
145905
  }
145333
145906
  return candidates[0];
145334
145907
  }
@@ -145358,10 +145931,10 @@ function injectReportData4(html, payload, lang) {
145358
145931
  return localized.replace(INJECT_MARKER3, `window.__META_DIAGNOSIS_REPORT__ = ${json};`);
145359
145932
  }
145360
145933
  async function runFacebookAnalysisDiagnosisRender(opts) {
145361
- const dataPath = path48.resolve(opts.dataFile);
145934
+ const dataPath = path49.resolve(opts.dataFile);
145362
145935
  let data = asRecord32(await readJsonFile6(dataPath));
145363
145936
  if (opts.snapshotDir?.trim()) {
145364
- data = await mergeMetaDiagnosisSnapshotIntoReport(data, path48.resolve(opts.snapshotDir));
145937
+ data = await mergeMetaDiagnosisSnapshotIntoReport(data, path49.resolve(opts.snapshotDir));
145365
145938
  }
145366
145939
  const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
145367
145940
  const contentCheck = validateMetaDiagnosisReportContent(data);
@@ -145388,10 +145961,10 @@ async function runFacebookAnalysisDiagnosisRender(opts) {
145388
145961
  `);
145389
145962
  process.exit(1);
145390
145963
  }
145391
- const outPath = path48.resolve(
145392
- opts.out ?? path48.join(path48.dirname(dataPath), "meta-account-diagnosis-report.html")
145964
+ const outPath = path49.resolve(
145965
+ opts.out ?? path49.join(path49.dirname(dataPath), "meta-account-diagnosis-report.html")
145393
145966
  );
145394
- const outDir = path48.dirname(outPath);
145967
+ const outDir = path49.dirname(outPath);
145395
145968
  await fsPromises5.mkdir(outDir, { recursive: true });
145396
145969
  await fsPromises5.writeFile(outPath, injectReportData4(html, data, lang), "utf8");
145397
145970
  const { stats } = contentCheck;
@@ -145409,7 +145982,7 @@ async function runFacebookAnalysisDiagnosisRender(opts) {
145409
145982
 
145410
145983
  // src/commands/facebook-analysis/run-batch.ts
145411
145984
  init_auth();
145412
- import * as path49 from "path";
145985
+ import * as path50 from "path";
145413
145986
  import { performance as performance5 } from "perf_hooks";
145414
145987
  init_version();
145415
145988
 
@@ -145511,7 +146084,7 @@ async function runAllFacebookSections(opts) {
145511
146084
  const results = await runWithConcurrency2(tasks, concurrency);
145512
146085
  const succeeded = results.filter((r) => r.ok).length;
145513
146086
  const failed = results.length - succeeded;
145514
- const absoluteSnapshotDir = path49.resolve(opts.jsonOut);
146087
+ const absoluteSnapshotDir = path50.resolve(opts.jsonOut);
145515
146088
  const summary = {
145516
146089
  kind: "siluzan-tso-facebook-analysis-snapshot-batch",
145517
146090
  absoluteSnapshotDir,
@@ -145635,9 +146208,9 @@ function parseEffectiveStatusFilter(raw) {
145635
146208
  }
145636
146209
  return canonical.length ? canonical.join(",") : void 0;
145637
146210
  }
145638
- function facebookAdsUrl(facebookApiUrl, digits, path60) {
146211
+ function facebookAdsUrl(facebookApiUrl, digits, path61) {
145639
146212
  const base2 = facebookApiUrl.replace(/\/$/, "");
145640
- const p = path60.startsWith("/") ? path60 : `/${path60}`;
146213
+ const p = path61.startsWith("/") ? path61 : `/${path61}`;
145641
146214
  return `${base2}/api/fb/ads/${digits}${p}`;
145642
146215
  }
145643
146216
  function facebookInsightsUrl(facebookApiUrl, digits, level) {
@@ -145674,7 +146247,7 @@ async function fetchFacebookAccount(config, digits, verbose) {
145674
146247
  verbose
145675
146248
  );
145676
146249
  }
145677
- async function fetchFacebookPagedList(config, digits, path60, opts) {
146250
+ async function fetchFacebookPagedList(config, digits, path61, opts) {
145678
146251
  const base2 = requireFacebookApi(config);
145679
146252
  const items3 = [];
145680
146253
  let after;
@@ -145689,7 +146262,7 @@ async function fetchFacebookPagedList(config, digits, path60, opts) {
145689
146262
  adsetId: opts.adsetId
145690
146263
  });
145691
146264
  const raw = await apiFetch2(
145692
- `${facebookAdsUrl(base2, digits, path60)}?${query}`,
146265
+ `${facebookAdsUrl(base2, digits, path61)}?${query}`,
145693
146266
  config,
145694
146267
  {},
145695
146268
  opts.verbose
@@ -145742,7 +146315,7 @@ function sumActionArray(raw) {
145742
146315
  }
145743
146316
 
145744
146317
  // src/commands/facebook-analysis/entities.ts
145745
- function fail4(label2, err) {
146318
+ function fail5(label2, err) {
145746
146319
  const msg = err instanceof Error ? err.message : String(err);
145747
146320
  console.error(`
145748
146321
  \u274C ${label2}\uFF1A${msg}
@@ -145770,7 +146343,7 @@ async function runFacebookAccountStatus(opts) {
145770
146343
  try {
145771
146344
  row = await fetchFacebookAccount(config, manifestId, !!opts.verbose);
145772
146345
  } catch (err) {
145773
- fail4("\u67E5\u8BE2 Facebook \u8D26\u6237\u5931\u8D25", err);
146346
+ fail5("\u67E5\u8BE2 Facebook \u8D26\u6237\u5931\u8D25", err);
145774
146347
  }
145775
146348
  const payload = { account: manifestId, ...row };
145776
146349
  if (await emitCliJsonOrSnapshot(opts, {
@@ -145820,11 +146393,11 @@ async function runFacebookEntityList(opts, kind) {
145820
146393
  try {
145821
146394
  effectiveStatus = parseEffectiveStatusFilter(opts.effectiveStatus);
145822
146395
  } catch (err) {
145823
- fail4("\u53C2\u6570\u9519\u8BEF", err);
146396
+ fail5("\u53C2\u6570\u9519\u8BEF", err);
145824
146397
  }
145825
146398
  const pageSize = resolveFacebookPageSize(opts.pageSize);
145826
146399
  const config = loadConfig(opts.token);
145827
- const path60 = `/${kind}`;
146400
+ const path61 = `/${kind}`;
145828
146401
  const labels = {
145829
146402
  campaigns: {
145830
146403
  section: "facebook-campaign-entities",
@@ -145837,7 +146410,7 @@ async function runFacebookEntityList(opts, kind) {
145837
146410
  const meta = labels[kind];
145838
146411
  let result;
145839
146412
  try {
145840
- result = await fetchFacebookPagedList(config, manifestId, path60, {
146413
+ result = await fetchFacebookPagedList(config, manifestId, path61, {
145841
146414
  pageSize,
145842
146415
  verbose: !!opts.verbose,
145843
146416
  effectiveStatus,
@@ -145845,7 +146418,7 @@ async function runFacebookEntityList(opts, kind) {
145845
146418
  adsetId: opts.adsetId?.trim() || void 0
145846
146419
  });
145847
146420
  } catch (err) {
145848
- fail4(`\u67E5\u8BE2 ${meta.title} \u5931\u8D25`, err);
146421
+ fail5(`\u67E5\u8BE2 ${meta.title} \u5931\u8D25`, err);
145849
146422
  }
145850
146423
  const payload = wrapListJson({
145851
146424
  page: 1,
@@ -145966,7 +146539,7 @@ async function runFacebookInsights(opts) {
145966
146539
  breakdown = resolveFacebookBreakdown(opts.breakdown);
145967
146540
  timeIncrement = parseOptionalNumber2(opts.timeIncrement);
145968
146541
  } catch (err) {
145969
- fail4("\u53C2\u6570\u9519\u8BEF", err);
146542
+ fail5("\u53C2\u6570\u9519\u8BEF", err);
145970
146543
  }
145971
146544
  const config = loadConfig(opts.token);
145972
146545
  let items3;
@@ -145982,7 +146555,7 @@ async function runFacebookInsights(opts) {
145982
146555
  adIds: opts.adIds?.trim() || void 0
145983
146556
  });
145984
146557
  } catch (err) {
145985
- fail4("\u67E5\u8BE2 Facebook Insights \u5931\u8D25", err);
146558
+ fail5("\u67E5\u8BE2 Facebook Insights \u5931\u8D25", err);
145986
146559
  }
145987
146560
  const payload = {
145988
146561
  account: manifestId,
@@ -146585,7 +147158,7 @@ function endpointHintForBingSection(def) {
146585
147158
 
146586
147159
  // src/commands/bing-analysis/run-batch.ts
146587
147160
  init_auth();
146588
- import * as path50 from "path";
147161
+ import * as path51 from "path";
146589
147162
  import { performance as performance6 } from "perf_hooks";
146590
147163
  init_version();
146591
147164
  async function runWithConcurrency3(tasks, concurrency) {
@@ -146660,7 +147233,7 @@ async function runAllBingSections(opts) {
146660
147233
  const results = await runWithConcurrency3(tasks, concurrency);
146661
147234
  const succeeded = results.filter((r) => r.ok).length;
146662
147235
  const failed = results.length - succeeded;
146663
- const absoluteSnapshotDir = path50.resolve(opts.jsonOut);
147236
+ const absoluteSnapshotDir = path51.resolve(opts.jsonOut);
146664
147237
  const summary = {
146665
147238
  kind: "siluzan-tso-bing-analysis-snapshot-batch",
146666
147239
  absoluteSnapshotDir,
@@ -147004,14 +147577,14 @@ Bing \u5B98\u65B9\u6708\u6D88\u8017\uFF08${id}\uFF09
147004
147577
  import { Command as Command3 } from "commander";
147005
147578
 
147006
147579
  // src/commands/bing-analysis/render-report.ts
147007
- import fs43 from "fs";
147580
+ import fs44 from "fs";
147008
147581
  import fsPromises6 from "fs/promises";
147009
- import path52 from "path";
147582
+ import path53 from "path";
147010
147583
  import { fileURLToPath as fileURLToPath13 } from "url";
147011
147584
 
147012
147585
  // src/commands/bing-analysis/merge-snapshot.ts
147013
- import * as fs42 from "fs/promises";
147014
- import * as path51 from "path";
147586
+ import * as fs43 from "fs/promises";
147587
+ import * as path52 from "path";
147015
147588
  function asRecord34(value) {
147016
147589
  if (value && typeof value === "object" && !Array.isArray(value)) {
147017
147590
  return value;
@@ -147025,7 +147598,7 @@ function num11(value) {
147025
147598
  function round28(value) {
147026
147599
  return value == null ? void 0 : Math.round(value * 100) / 100;
147027
147600
  }
147028
- function asRows2(value) {
147601
+ function asRows3(value) {
147029
147602
  if (Array.isArray(value)) {
147030
147603
  return value.filter((r) => asRecord34(r) !== null);
147031
147604
  }
@@ -147033,7 +147606,7 @@ function asRows2(value) {
147033
147606
  }
147034
147607
  async function loadSectionPayload(snapshotDir, file) {
147035
147608
  try {
147036
- const raw = await fs42.readFile(path51.join(snapshotDir, file), "utf8");
147609
+ const raw = await fs43.readFile(path52.join(snapshotDir, file), "utf8");
147037
147610
  return JSON.parse(raw);
147038
147611
  } catch {
147039
147612
  return null;
@@ -147043,7 +147616,7 @@ async function readManifest6(snapshotDir, accountId) {
147043
147616
  const candidates = [];
147044
147617
  if (accountId) candidates.push(reportManifestFile(accountId));
147045
147618
  try {
147046
- const entries = await fs42.readdir(snapshotDir);
147619
+ const entries = await fs43.readdir(snapshotDir);
147047
147620
  const manifestNames = entries.filter(
147048
147621
  (n) => n.startsWith("report-manifest") && n.endsWith(".json")
147049
147622
  );
@@ -147054,7 +147627,7 @@ async function readManifest6(snapshotDir, accountId) {
147054
147627
  }
147055
147628
  for (const name2 of candidates) {
147056
147629
  try {
147057
- const raw = await fs42.readFile(path51.join(snapshotDir, name2), "utf8");
147630
+ const raw = await fs43.readFile(path52.join(snapshotDir, name2), "utf8");
147058
147631
  const parsed = JSON.parse(raw);
147059
147632
  if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
147060
147633
  } catch {
@@ -147110,17 +147683,17 @@ function campaignStatusDisplay(status) {
147110
147683
  }
147111
147684
  function mapDeviceRows(payload) {
147112
147685
  const obj = asRecord34(payload);
147113
- return asRows2(obj?.devices).map((r) => pickMetrics(r, ["deviceType"]));
147686
+ return asRows3(obj?.devices).map((r) => pickMetrics(r, ["deviceType"]));
147114
147687
  }
147115
147688
  function mapGeographicRows(payload) {
147116
147689
  const obj = asRecord34(payload);
147117
- return asRows2(obj?.countries).map(
147690
+ return asRows3(obj?.countries).map(
147118
147691
  (r) => pickMetrics(r, ["countryOrRegion", "countryCriteriaId", "regionName", "cityName"])
147119
147692
  );
147120
147693
  }
147121
147694
  function mapAudienceLabelRows(payload, labelKey) {
147122
147695
  const obj = asRecord34(payload);
147123
- return asRows2(obj?.audience).map((r) => {
147696
+ return asRows3(obj?.audience).map((r) => {
147124
147697
  const m = pickMetrics(r, ["audience", "bidModifier"]);
147125
147698
  m[labelKey] = r.audience;
147126
147699
  return m;
@@ -147143,13 +147716,13 @@ function resolveAudienceTables(sectionMap) {
147143
147716
  };
147144
147717
  }
147145
147718
  function mapCampaignRows2(payload) {
147146
- return asRows2(payload).map((r) => ({
147719
+ return asRows3(payload).map((r) => ({
147147
147720
  ...pickMetrics(r, ["campaignId", "campaignName", "campaignStatus"]),
147148
147721
  campaignStatusDisplay: campaignStatusDisplay(r.campaignStatus)
147149
147722
  }));
147150
147723
  }
147151
147724
  function mapAdGroupRows(payload) {
147152
- return asRows2(payload).map(
147725
+ return asRows3(payload).map(
147153
147726
  (r) => pickMetrics(r, [
147154
147727
  "campaignId",
147155
147728
  "campaignName",
@@ -147172,7 +147745,7 @@ function displayAdTitle(row) {
147172
147745
  return { adTitle: fallback, adTitleFallback: fallback.length > 0 };
147173
147746
  }
147174
147747
  function mapAdRows(payload) {
147175
- return asRows2(payload).map((r) => {
147748
+ return asRows3(payload).map((r) => {
147176
147749
  const mapped = pickMetrics(r, [
147177
147750
  "campaignId",
147178
147751
  "campaignName",
@@ -147189,7 +147762,7 @@ function mapAdRows(payload) {
147189
147762
  });
147190
147763
  }
147191
147764
  function mapKeywordRows(payload) {
147192
- return asRows2(payload).map((r) => {
147765
+ return asRows3(payload).map((r) => {
147193
147766
  const m = pickMetrics(r, [
147194
147767
  "campaignId",
147195
147768
  "campaignName",
@@ -147207,7 +147780,7 @@ function mapKeywordRows(payload) {
147207
147780
  });
147208
147781
  }
147209
147782
  function mapSearchTermRows(payload) {
147210
- return asRows2(payload).map(
147783
+ return asRows3(payload).map(
147211
147784
  (r) => pickMetrics(r, [
147212
147785
  "campaignId",
147213
147786
  "campaignName",
@@ -147221,7 +147794,7 @@ function mapSearchTermRows(payload) {
147221
147794
  );
147222
147795
  }
147223
147796
  async function mergeBingAnalysisSnapshotIntoReport(payload, snapshotDir) {
147224
- const absDir = path51.resolve(snapshotDir);
147797
+ const absDir = path52.resolve(snapshotDir);
147225
147798
  const metaAccountId = typeof asRecord34(payload.meta)?.accountId === "string" ? asRecord34(payload.meta)?.accountId : void 0;
147226
147799
  const manifest = await readManifest6(snapshotDir, metaAccountId);
147227
147800
  if (!manifest) {
@@ -147459,14 +148032,14 @@ init_html();
147459
148032
  var TEMPLATE_BASENAME4 = "bing-period-report.html";
147460
148033
  var INJECT_MARKER4 = "window.__BING_PERIOD_REPORT__ = window.__BING_PERIOD_REPORT__ || null;";
147461
148034
  function resolveSkillTemplatePath7(basename13) {
147462
- const dir = path52.dirname(fileURLToPath13(import.meta.url));
148035
+ const dir = path53.dirname(fileURLToPath13(import.meta.url));
147463
148036
  const candidates = [
147464
- path52.join(dir, "skill", "report-templates", basename13),
147465
- path52.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
147466
- path52.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
148037
+ path53.join(dir, "skill", "report-templates", basename13),
148038
+ path53.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
148039
+ path53.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
147467
148040
  ];
147468
148041
  for (const p of candidates) {
147469
- if (fs43.existsSync(p)) return p;
148042
+ if (fs44.existsSync(p)) return p;
147470
148043
  }
147471
148044
  return candidates[0];
147472
148045
  }
@@ -147496,10 +148069,10 @@ function injectReportData5(html, payload, lang) {
147496
148069
  return localized.replace(INJECT_MARKER4, `window.__BING_PERIOD_REPORT__ = ${json};`);
147497
148070
  }
147498
148071
  async function runBingAnalysisRender(opts) {
147499
- const dataPath = path52.resolve(opts.dataFile);
148072
+ const dataPath = path53.resolve(opts.dataFile);
147500
148073
  let data = asRecord36(await readJsonFile7(dataPath));
147501
148074
  if (opts.snapshotDir?.trim()) {
147502
- data = await mergeBingAnalysisSnapshotIntoReport(data, path52.resolve(opts.snapshotDir));
148075
+ data = await mergeBingAnalysisSnapshotIntoReport(data, path53.resolve(opts.snapshotDir));
147503
148076
  }
147504
148077
  const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
147505
148078
  const contentCheck = validateBingPeriodReportContent(data);
@@ -147526,10 +148099,10 @@ async function runBingAnalysisRender(opts) {
147526
148099
  `);
147527
148100
  process.exit(1);
147528
148101
  }
147529
- const outPath = path52.resolve(
147530
- opts.out ?? path52.join(path52.dirname(dataPath), "bing-period-report.html")
148102
+ const outPath = path53.resolve(
148103
+ opts.out ?? path53.join(path53.dirname(dataPath), "bing-period-report.html")
147531
148104
  );
147532
- const outDir = path52.dirname(outPath);
148105
+ const outDir = path53.dirname(outPath);
147533
148106
  await fsPromises6.mkdir(outDir, { recursive: true });
147534
148107
  await fsPromises6.writeFile(outPath, injectReportData5(html, data, lang), "utf8");
147535
148108
  const { stats } = contentCheck;
@@ -147546,6 +148119,106 @@ async function runBingAnalysisRender(opts) {
147546
148119
  );
147547
148120
  }
147548
148121
 
148122
+ // src/commands/bing-analysis/write.ts
148123
+ init_auth();
148124
+ init_cli_json_snapshot();
148125
+ function parseBingToggleStatus(raw, label2) {
148126
+ if (raw == null || raw.trim() === "") return void 0;
148127
+ const value = raw.trim();
148128
+ if (value.toLowerCase() === "active") return "Active";
148129
+ if (value.toLowerCase() === "paused") return "Paused";
148130
+ throw new Error(`${label2} \u53EA\u63A5\u53D7 Active \u6216 Paused`);
148131
+ }
148132
+ function parsePositiveAmount(raw, label2) {
148133
+ if (raw == null || raw.trim() === "") return void 0;
148134
+ const n = Number(raw);
148135
+ if (!Number.isFinite(n) || n <= 0) {
148136
+ throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57\uFF08\u8D26\u6237\u5E01\u79CD\uFF09`);
148137
+ }
148138
+ return n;
148139
+ }
148140
+ function requirePositiveId(raw, label2) {
148141
+ const id = raw.trim();
148142
+ if (!/^\d+$/.test(id) || id === "0") {
148143
+ throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57 ID`);
148144
+ }
148145
+ return id;
148146
+ }
148147
+ async function postBing(url, body, opts, section, commandLabel) {
148148
+ const config = loadConfig(opts.token);
148149
+ const payload = await apiFetch2(
148150
+ url,
148151
+ config,
148152
+ { method: "POST", body: JSON.stringify(body) },
148153
+ opts.verbose
148154
+ );
148155
+ const emitted = await emitCliJsonOrSnapshot(
148156
+ { jsonOut: opts.jsonOut },
148157
+ {
148158
+ section,
148159
+ commandLabel,
148160
+ payload,
148161
+ idSuffix: assertBingAccountId(opts.account)
148162
+ }
148163
+ );
148164
+ if (emitted) return;
148165
+ const note = payload && typeof payload === "object" && "note" in payload ? String(payload.note ?? "") : "";
148166
+ console.log(`
148167
+ \u2705 ${commandLabel} \u5DF2\u63D0\u4EA4
148168
+ `);
148169
+ if (note) console.log(` ${note}
148170
+ `);
148171
+ console.log(JSON.stringify(payload, null, 2));
148172
+ console.log();
148173
+ }
148174
+ async function runBingCampaignUpdate(opts) {
148175
+ const account = assertBingAccountId(opts.account);
148176
+ const campaignId = requirePositiveId(opts.campaignId, "campaign-id");
148177
+ const status = parseBingToggleStatus(opts.status, "\u7CFB\u5217\u72B6\u6001");
148178
+ const dailyBudget = parsePositiveAmount(opts.dailyBudget, "\u65E5\u9884\u7B97");
148179
+ if (!status && dailyBudget == null) {
148180
+ throw new Error("\u81F3\u5C11\u4F20\u5165 --status Active|Paused \u6216 --daily-budget");
148181
+ }
148182
+ const config = loadConfig(opts.token);
148183
+ const url = reportingUrl(config, account, `campaigns/${campaignId}`, "");
148184
+ await postBing(
148185
+ url,
148186
+ { status, dailyBudget },
148187
+ opts,
148188
+ "bing-campaign-update",
148189
+ "bing-analysis campaign-update"
148190
+ );
148191
+ }
148192
+ async function runBingAdGroupUpdate(opts) {
148193
+ const account = assertBingAccountId(opts.account);
148194
+ const campaignId = requirePositiveId(opts.campaignId, "campaign-id");
148195
+ const adGroupId = requirePositiveId(opts.adGroupId, "adgroup-id");
148196
+ const status = parseBingToggleStatus(opts.status, "\u5E7F\u544A\u7EC4\u72B6\u6001");
148197
+ const cpcBid = parsePositiveAmount(opts.cpcBid, "CPC \u51FA\u4EF7");
148198
+ if (!status && cpcBid == null) {
148199
+ throw new Error("\u81F3\u5C11\u4F20\u5165 --status Active|Paused \u6216 --cpc-bid");
148200
+ }
148201
+ const config = loadConfig(opts.token);
148202
+ const url = reportingUrl(config, account, `campaigns/${campaignId}/ad-groups/${adGroupId}`, "");
148203
+ await postBing(
148204
+ url,
148205
+ { status, cpcBid },
148206
+ opts,
148207
+ "bing-adgroup-update",
148208
+ "bing-analysis adgroup-update"
148209
+ );
148210
+ }
148211
+ async function runBingAdStatus(opts) {
148212
+ const account = assertBingAccountId(opts.account);
148213
+ const adGroupId = requirePositiveId(opts.adGroupId, "adgroup-id");
148214
+ const adId = requirePositiveId(opts.adId, "ad-id");
148215
+ const status = parseBingToggleStatus(opts.status, "\u5E7F\u544A\u72B6\u6001");
148216
+ if (!status) throw new Error("\u5E7F\u544A\u72B6\u6001\u5FC5\u987B\u662F Active \u6216 Paused");
148217
+ const config = loadConfig(opts.token);
148218
+ const url = reportingUrl(config, account, `ad-groups/${adGroupId}/ads/${adId}/status`, "");
148219
+ await postBing(url, { status }, opts, "bing-ad-status", "bing-analysis ad-status");
148220
+ }
148221
+
147549
148222
  // src/commands/bing-analysis/register-cli.ts
147550
148223
  var ACCOUNT_OPTION2 = [
147551
148224
  "-a, --account <id>",
@@ -147650,6 +148323,17 @@ function registerBingAnalysisCommands(program2) {
147650
148323
  await runBingMonthlySpend(opts);
147651
148324
  }
147652
148325
  );
148326
+ root.command("campaign-update").description(
148327
+ "\u6539\u7CFB\u5217\u72B6\u6001\u6216\u65E5\u9884\u7B97\uFF08POST \u2026/campaigns/{id}\uFF1BActive/Paused\uFF1B\u5171\u4EAB\u9884\u7B97\u4F1A\u8FDE\u5750\u540C\u4E00 BudgetId\uFF09"
148328
+ ).requiredOption(...ACCOUNT_OPTION2).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").option("--status <status>", "Active \u6216 Paused").option("--daily-budget <amount>", "\u65E5\u9884\u7B97\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC2, void 0).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
148329
+ await runBingCampaignUpdate(opts);
148330
+ });
148331
+ root.command("adgroup-update").description("\u6539\u5E7F\u544A\u7EC4\u72B6\u6001\u6216 CPC\uFF08POST \u2026/ad-groups/{id}\uFF1B\u51FA\u4EF7\u662F\u5B98\u65B9 CpcBid\uFF0C\u8D26\u6237\u5E01\u79CD\uFF09").requiredOption(...ACCOUNT_OPTION2).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").option("--status <status>", "Active \u6216 Paused").option("--cpc-bid <amount>", "CPC \u51FA\u4EF7\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC2, void 0).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
148332
+ await runBingAdGroupUpdate({ ...opts, adGroupId: opts.adgroupId });
148333
+ });
148334
+ root.command("ad-status").description("\u6539\u5E7F\u544A\u72B6\u6001\uFF08POST \u2026/ads/{id}/status\uFF1B\u53EA\u6539 Status\uFF0C\u4E0D\u6539\u521B\u610F\uFF09").requiredOption(...ACCOUNT_OPTION2).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--status <status>", "Active \u6216 Paused").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC2, void 0).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
148335
+ await runBingAdStatus({ ...opts, adGroupId: opts.adgroupId });
148336
+ });
147653
148337
  }
147654
148338
 
147655
148339
  // src/commands/tiktok-analysis/sections.ts
@@ -147867,7 +148551,7 @@ async function fetchTikTokInterestList(config, account, verbose) {
147867
148551
 
147868
148552
  // src/commands/tiktok-analysis/run-batch.ts
147869
148553
  init_auth();
147870
- import * as path53 from "path";
148554
+ import * as path54 from "path";
147871
148555
  import { performance as performance7 } from "perf_hooks";
147872
148556
  init_version();
147873
148557
  async function runWithConcurrency4(tasks, concurrency) {
@@ -147942,7 +148626,7 @@ async function runAllTikTokSections(opts) {
147942
148626
  const results = await runWithConcurrency4(tasks, concurrency);
147943
148627
  const succeeded = results.filter((r) => r.ok).length;
147944
148628
  const failed = results.length - succeeded;
147945
- const absoluteSnapshotDir = path53.resolve(opts.jsonOut);
148629
+ const absoluteSnapshotDir = path54.resolve(opts.jsonOut);
147946
148630
  const summary = {
147947
148631
  kind: "siluzan-tso-tiktok-analysis-snapshot-batch",
147948
148632
  absoluteSnapshotDir,
@@ -147965,14 +148649,14 @@ init_auth();
147965
148649
  import { Command as Command4 } from "commander";
147966
148650
 
147967
148651
  // src/commands/tiktok-analysis/render-report.ts
147968
- import fs45 from "fs";
148652
+ import fs46 from "fs";
147969
148653
  import fsPromises7 from "fs/promises";
147970
- import path55 from "path";
148654
+ import path56 from "path";
147971
148655
  import { fileURLToPath as fileURLToPath14 } from "url";
147972
148656
 
147973
148657
  // src/commands/tiktok-analysis/merge-snapshot.ts
147974
- import * as fs44 from "fs/promises";
147975
- import * as path54 from "path";
148658
+ import * as fs45 from "fs/promises";
148659
+ import * as path55 from "path";
147976
148660
  function asRecord37(value) {
147977
148661
  if (value && typeof value === "object" && !Array.isArray(value)) {
147978
148662
  return value;
@@ -147988,7 +148672,7 @@ function round29(value) {
147988
148672
  }
147989
148673
  async function loadSectionPayload2(snapshotDir, file) {
147990
148674
  try {
147991
- const raw = await fs44.readFile(path54.join(snapshotDir, file), "utf8");
148675
+ const raw = await fs45.readFile(path55.join(snapshotDir, file), "utf8");
147992
148676
  return JSON.parse(raw);
147993
148677
  } catch {
147994
148678
  return null;
@@ -147998,7 +148682,7 @@ async function readManifest7(snapshotDir, accountId) {
147998
148682
  const candidates = [];
147999
148683
  if (accountId) candidates.push(reportManifestFile(accountId));
148000
148684
  try {
148001
- const entries = await fs44.readdir(snapshotDir);
148685
+ const entries = await fs45.readdir(snapshotDir);
148002
148686
  const manifestNames = entries.filter(
148003
148687
  (n) => n.startsWith("report-manifest") && n.endsWith(".json")
148004
148688
  );
@@ -148009,7 +148693,7 @@ async function readManifest7(snapshotDir, accountId) {
148009
148693
  }
148010
148694
  for (const name2 of candidates) {
148011
148695
  try {
148012
- const raw = await fs44.readFile(path54.join(snapshotDir, name2), "utf8");
148696
+ const raw = await fs45.readFile(path55.join(snapshotDir, name2), "utf8");
148013
148697
  const parsed = JSON.parse(raw);
148014
148698
  if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
148015
148699
  } catch {
@@ -148150,7 +148834,7 @@ function mapAudienceMerged(payload) {
148150
148834
  };
148151
148835
  }
148152
148836
  async function mergeTikTokAnalysisSnapshotIntoReport(payload, snapshotDir) {
148153
- const absDir = path54.resolve(snapshotDir);
148837
+ const absDir = path55.resolve(snapshotDir);
148154
148838
  const metaAccountId = typeof asRecord37(payload.meta)?.accountId === "string" ? asRecord37(payload.meta)?.accountId : void 0;
148155
148839
  const manifest = await readManifest7(snapshotDir, metaAccountId);
148156
148840
  if (!manifest) {
@@ -148363,14 +149047,14 @@ init_html();
148363
149047
  var TEMPLATE_BASENAME5 = "tiktok-period-report.html";
148364
149048
  var INJECT_MARKER5 = "window.__TIKTOK_PERIOD_REPORT__ = window.__TIKTOK_PERIOD_REPORT__ || null;";
148365
149049
  function resolveSkillTemplatePath8(basename13) {
148366
- const dir = path55.dirname(fileURLToPath14(import.meta.url));
149050
+ const dir = path56.dirname(fileURLToPath14(import.meta.url));
148367
149051
  const candidates = [
148368
- path55.join(dir, "skill", "report-templates", basename13),
148369
- path55.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
148370
- path55.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
149052
+ path56.join(dir, "skill", "report-templates", basename13),
149053
+ path56.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
149054
+ path56.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
148371
149055
  ];
148372
149056
  for (const p of candidates) {
148373
- if (fs45.existsSync(p)) return p;
149057
+ if (fs46.existsSync(p)) return p;
148374
149058
  }
148375
149059
  return candidates[0];
148376
149060
  }
@@ -148400,10 +149084,10 @@ function injectReportData6(html, payload, lang) {
148400
149084
  return localized.replace(INJECT_MARKER5, `window.__TIKTOK_PERIOD_REPORT__ = ${json};`);
148401
149085
  }
148402
149086
  async function runTikTokAnalysisRender(opts) {
148403
- const dataPath = path55.resolve(opts.dataFile);
149087
+ const dataPath = path56.resolve(opts.dataFile);
148404
149088
  let data = asRecord39(await readJsonFile8(dataPath));
148405
149089
  if (opts.snapshotDir?.trim()) {
148406
- data = await mergeTikTokAnalysisSnapshotIntoReport(data, path55.resolve(opts.snapshotDir));
149090
+ data = await mergeTikTokAnalysisSnapshotIntoReport(data, path56.resolve(opts.snapshotDir));
148407
149091
  }
148408
149092
  const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
148409
149093
  const contentCheck = validateTikTokPeriodReportContent(data);
@@ -148430,10 +149114,10 @@ async function runTikTokAnalysisRender(opts) {
148430
149114
  `);
148431
149115
  process.exit(1);
148432
149116
  }
148433
- const outPath = path55.resolve(
148434
- opts.out ?? path55.join(path55.dirname(dataPath), "tiktok-period-report.html")
149117
+ const outPath = path56.resolve(
149118
+ opts.out ?? path56.join(path56.dirname(dataPath), "tiktok-period-report.html")
148435
149119
  );
148436
- const outDir = path55.dirname(outPath);
149120
+ const outDir = path56.dirname(outPath);
148437
149121
  await fsPromises7.mkdir(outDir, { recursive: true });
148438
149122
  await fsPromises7.writeFile(outPath, injectReportData6(html, data, lang), "utf8");
148439
149123
  const { stats } = contentCheck;
@@ -148811,7 +149495,7 @@ async function fetchOfficialReport(config, opts) {
148811
149495
  }
148812
149496
 
148813
149497
  // src/commands/tiktok-analysis/entities.ts
148814
- function fail5(label2, err) {
149498
+ function fail6(label2, err) {
148815
149499
  const msg = err instanceof Error ? err.message : String(err);
148816
149500
  console.error(`
148817
149501
  \u274C ${label2}\uFF1A${msg}
@@ -148825,7 +149509,7 @@ async function runTikTokAccountStatus(opts) {
148825
149509
  try {
148826
149510
  rows = await fetchAdvertiserInfoList(config, id, !!opts.verbose);
148827
149511
  } catch (err) {
148828
- 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);
149512
+ fail6("\u67E5\u8BE2 TikTok \u8D26\u6237\u4FE1\u606F\u5931\u8D25\uFF08\u987B\u62E5\u6709\u8BE5\u5E7F\u544A\u4E3B\uFF0C\u5217\u8868\u53EF\u89C1\u4E0D\u591F\uFF09", err);
148829
149513
  }
148830
149514
  const payload = wrapListJson({
148831
149515
  page: 1,
@@ -148880,7 +149564,7 @@ async function runTikTokCampaignEntities(opts) {
148880
149564
  verbose: !!opts.verbose
148881
149565
  });
148882
149566
  } catch (err) {
148883
- fail5("\u67E5\u8BE2 TikTok \u7CFB\u5217\u5931\u8D25", err);
149567
+ fail6("\u67E5\u8BE2 TikTok \u7CFB\u5217\u5931\u8D25", err);
148884
149568
  }
148885
149569
  const payload = wrapListJson({
148886
149570
  page: 1,
@@ -148942,7 +149626,7 @@ async function runTikTokAdGroupEntities(opts) {
148942
149626
  verbose: !!opts.verbose
148943
149627
  });
148944
149628
  } catch (err) {
148945
- fail5("\u67E5\u8BE2 TikTok \u5E7F\u544A\u7EC4\u5931\u8D25", err);
149629
+ fail6("\u67E5\u8BE2 TikTok \u5E7F\u544A\u7EC4\u5931\u8D25", err);
148946
149630
  }
148947
149631
  const payload = wrapListJson({
148948
149632
  page: 1,
@@ -149009,7 +149693,7 @@ async function runTikTokAdEntities(opts) {
149009
149693
  verbose: !!opts.verbose
149010
149694
  });
149011
149695
  } catch (err) {
149012
- fail5("\u67E5\u8BE2 TikTok \u5E7F\u544A\u5931\u8D25", err);
149696
+ fail6("\u67E5\u8BE2 TikTok \u5E7F\u544A\u5931\u8D25", err);
149013
149697
  }
149014
149698
  const payload = wrapListJson({
149015
149699
  page: 1,
@@ -149083,7 +149767,7 @@ async function runTikTokOfficialReport(opts) {
149083
149767
  verbose: !!opts.verbose
149084
149768
  });
149085
149769
  } catch (err) {
149086
- fail5("\u67E5\u8BE2 TikTok \u5B98\u65B9\u62A5\u8868\u5931\u8D25", err);
149770
+ fail6("\u67E5\u8BE2 TikTok \u5B98\u65B9\u62A5\u8868\u5931\u8D25", err);
149087
149771
  }
149088
149772
  const totals = summarizeTikTokOfficialReport(result.items);
149089
149773
  const payload = {
@@ -149146,6 +149830,168 @@ TikTok \u5B98\u65B9\u62A5\u8868 ${dataLevel} ${startDate}~${endDate}\uFF08${id}\
149146
149830
  }
149147
149831
  }
149148
149832
 
149833
+ // src/commands/tiktok-analysis/write.ts
149834
+ init_auth();
149835
+ init_cli_json_snapshot();
149836
+ var CAMPAIGN_BUDGET_MODES = [
149837
+ "BUDGET_MODE_DAY",
149838
+ "BUDGET_MODE_TOTAL",
149839
+ "BUDGET_MODE_DYNAMIC_DAILY_BUDGET"
149840
+ ];
149841
+ function parseTikTokOptStatus(raw) {
149842
+ const value = (raw ?? "").trim().toUpperCase();
149843
+ if (value === "ENABLE" || value === "DISABLE") return value;
149844
+ throw new Error("status \u53EA\u63A5\u53D7 ENABLE \u6216 DISABLE\uFF08\u4E0D\u5F00\u653E DELETE\uFF09");
149845
+ }
149846
+ function parseTikTokBudgetMode(raw) {
149847
+ const value = (raw ?? "").trim().toUpperCase();
149848
+ if (CAMPAIGN_BUDGET_MODES.includes(value)) {
149849
+ return value;
149850
+ }
149851
+ throw new Error(`budget-mode \u53EA\u63A5\u53D7 ${CAMPAIGN_BUDGET_MODES.join(" / ")}`);
149852
+ }
149853
+ function parseTikTokAmount(raw, label2) {
149854
+ const n = Number((raw ?? "").trim());
149855
+ if (!Number.isFinite(n) || n <= 0) {
149856
+ throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57\uFF08\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF09`);
149857
+ }
149858
+ return n;
149859
+ }
149860
+ function campaignStatusBody(advertiserId, campaignId, status) {
149861
+ return {
149862
+ advertiser_id: advertiserId,
149863
+ campaign_ids: [campaignId],
149864
+ operation_status: status
149865
+ };
149866
+ }
149867
+ function campaignBudgetBody(advertiserId, campaignId, budget, budgetMode) {
149868
+ return {
149869
+ advertiser_id: advertiserId,
149870
+ campaign_id: campaignId,
149871
+ budget,
149872
+ budget_mode: budgetMode
149873
+ };
149874
+ }
149875
+ function adGroupStatusBody(advertiserId, adGroupId, status) {
149876
+ return {
149877
+ advertiser_id: advertiserId,
149878
+ adgroup_ids: [adGroupId],
149879
+ operation_status: status
149880
+ };
149881
+ }
149882
+ function adGroupBudgetBody(advertiserId, adGroupId, budget) {
149883
+ return {
149884
+ advertiser_id: advertiserId,
149885
+ budget: [{ adgroup_id: adGroupId, budget }]
149886
+ };
149887
+ }
149888
+ function adStatusBody(advertiserId, adId, status) {
149889
+ return {
149890
+ advertiser_id: advertiserId,
149891
+ ad_ids: [adId],
149892
+ operation_status: status
149893
+ };
149894
+ }
149895
+ function assertTikTokWriteOk(raw, label2) {
149896
+ if (!raw || typeof raw !== "object") return;
149897
+ const code = raw.code;
149898
+ if (code === void 0 || code === 0 || code === "0") return;
149899
+ const message = raw.message ?? "\u672A\u77E5\u9519\u8BEF";
149900
+ throw new Error(`${label2} \u4E1A\u52A1\u5931\u8D25 code=${String(code)}\uFF1A${message}`);
149901
+ }
149902
+ async function putTikTok(path61, body, opts, section, commandLabel) {
149903
+ const advertiserId = assertTikTokAccountId(opts.account);
149904
+ const config = loadConfig(opts.token);
149905
+ const url = `${requireTikTokApiUrl(config)}/${path61}`;
149906
+ const payload = await apiFetch2(
149907
+ url,
149908
+ config,
149909
+ { method: "PUT", body: JSON.stringify(body) },
149910
+ opts.verbose
149911
+ );
149912
+ assertTikTokWriteOk(payload, commandLabel);
149913
+ const emitted = await emitCliJsonOrSnapshot(
149914
+ { jsonOut: opts.jsonOut },
149915
+ { section, commandLabel, payload, idSuffix: advertiserId }
149916
+ );
149917
+ if (emitted) return;
149918
+ console.log(`
149919
+ \u2705 ${commandLabel} \u5DF2\u63D0\u4EA4
149920
+ `);
149921
+ console.log(JSON.stringify(payload, null, 2));
149922
+ console.log();
149923
+ }
149924
+ async function requireMediaAccountId(opts) {
149925
+ const advertiserId = assertTikTokAccountId(opts.account);
149926
+ const config = loadConfig(opts.token);
149927
+ const item = await fetchTikTokAccountByMediaCustomerId(config, advertiserId, opts.verbose);
149928
+ const entityId = String(item?.ma?.entityId ?? "").trim();
149929
+ if (!entityId) {
149930
+ throw new Error(
149931
+ `\u627E\u4E0D\u5230\u5E7F\u544A\u4E3B ${advertiserId} \u7684 entityId\u3002\u8BF7\u786E\u8BA4 list-accounts -m TikTok \u80FD\u67E5\u5230\u8BE5\u6237\u3002`
149932
+ );
149933
+ }
149934
+ return entityId;
149935
+ }
149936
+ async function runTikTokCampaignStatus(opts) {
149937
+ const advertiserId = assertTikTokAccountId(opts.account);
149938
+ const status = parseTikTokOptStatus(opts.status);
149939
+ await putTikTok(
149940
+ `tiktokcampaignmanagement/campaign/updatestatus/${TIKTOK_MEDIA_TYPE}`,
149941
+ campaignStatusBody(advertiserId, opts.campaignId.trim(), status),
149942
+ opts,
149943
+ "tiktok-campaign-status",
149944
+ "tiktok-analysis campaign-status"
149945
+ );
149946
+ }
149947
+ async function runTikTokCampaignBudget(opts) {
149948
+ const advertiserId = assertTikTokAccountId(opts.account);
149949
+ const budget = parseTikTokAmount(opts.budget, "\u7CFB\u5217\u9884\u7B97");
149950
+ const budgetMode = parseTikTokBudgetMode(opts.budgetMode);
149951
+ await putTikTok(
149952
+ `tiktokcampaignmanagement/campaign/update/${TIKTOK_MEDIA_TYPE}`,
149953
+ campaignBudgetBody(advertiserId, opts.campaignId.trim(), budget, budgetMode),
149954
+ opts,
149955
+ "tiktok-campaign-budget",
149956
+ "tiktok-analysis campaign-budget"
149957
+ );
149958
+ }
149959
+ async function runTikTokAdGroupStatus(opts) {
149960
+ const advertiserId = assertTikTokAccountId(opts.account);
149961
+ const entityId = await requireMediaAccountId(opts);
149962
+ const status = parseTikTokOptStatus(opts.status);
149963
+ await putTikTok(
149964
+ `tiktokadgroupmanagement/adgroup/UpdateStatus/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(entityId)}`,
149965
+ adGroupStatusBody(advertiserId, opts.adGroupId.trim(), status),
149966
+ opts,
149967
+ "tiktok-adgroup-status",
149968
+ "tiktok-analysis adgroup-status"
149969
+ );
149970
+ }
149971
+ async function runTikTokAdGroupBudget(opts) {
149972
+ const advertiserId = assertTikTokAccountId(opts.account);
149973
+ const entityId = await requireMediaAccountId(opts);
149974
+ const budget = parseTikTokAmount(opts.budget, "\u5E7F\u544A\u7EC4\u9884\u7B97");
149975
+ await putTikTok(
149976
+ `tiktokadgroupmanagement/adgroup/UpdateBudget/${TIKTOK_MEDIA_TYPE}/${encodeURIComponent(entityId)}`,
149977
+ adGroupBudgetBody(advertiserId, opts.adGroupId.trim(), budget),
149978
+ opts,
149979
+ "tiktok-adgroup-budget",
149980
+ "tiktok-analysis adgroup-budget"
149981
+ );
149982
+ }
149983
+ async function runTikTokAdStatus(opts) {
149984
+ const advertiserId = assertTikTokAccountId(opts.account);
149985
+ const status = parseTikTokOptStatus(opts.status);
149986
+ await putTikTok(
149987
+ `tiktokadmanagement/ad/updatestatus/${TIKTOK_MEDIA_TYPE}`,
149988
+ adStatusBody(advertiserId, opts.adId.trim(), status),
149989
+ opts,
149990
+ "tiktok-ad-status",
149991
+ "tiktok-analysis ad-status"
149992
+ );
149993
+ }
149994
+
149149
149995
  // src/commands/tiktok-analysis/register-cli.ts
149150
149996
  var ACCOUNT_OPTION3 = [
149151
149997
  "-a, --account <id>",
@@ -149299,6 +150145,26 @@ function registerTikTokAnalysisCommands(program2) {
149299
150145
  await runTikTokOfficialReport(opts);
149300
150146
  }
149301
150147
  );
150148
+ root.command("campaign-status").description("\u542F\u505C\u63A8\u5E7F\u7CFB\u5217\uFF08PUT \u2026/campaign/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--campaign-id <id>", "\u63A8\u5E7F\u7CFB\u5217 ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
150149
+ await runTikTokCampaignStatus(opts);
150150
+ });
150151
+ root.command("campaign-budget").description(
150152
+ "\u6539\u63A8\u5E7F\u7CFB\u5217\u9884\u7B97\uFF08PUT \u2026/campaign/update/Tiktok\uFF1B\u65E5\u9884\u7B97\u4E0E\u603B\u9884\u7B97\u4E0D\u80FD\u4E92\u5207\uFF0C\u4E0D\u652F\u6301\u4E0D\u9650\u9884\u7B97\uFF09"
150153
+ ).requiredOption(...ACCOUNT_OPTION3).requiredOption("--campaign-id <id>", "\u63A8\u5E7F\u7CFB\u5217 ID").requiredOption("--budget <amount>", "\u9884\u7B97\uFF0C\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").requiredOption(
150154
+ "--budget-mode <mode>",
150155
+ "BUDGET_MODE_DAY / BUDGET_MODE_TOTAL / BUDGET_MODE_DYNAMIC_DAILY_BUDGET"
150156
+ ).option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
150157
+ await runTikTokCampaignBudget(opts);
150158
+ });
150159
+ root.command("adgroup-status").description("\u542F\u505C\u5E7F\u544A\u7EC4\uFF08PUT \u2026/adgroup/UpdateStatus/Tiktok/{entityId}\uFF1BentityId \u6309\u5E7F\u544A\u4E3B\u81EA\u52A8\u67E5\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
150160
+ await runTikTokAdGroupStatus({ ...opts, adGroupId: opts.adgroupId });
150161
+ });
150162
+ root.command("adgroup-budget").description("\u6539\u5E7F\u544A\u7EC4\u9884\u7B97\uFF08PUT \u2026/adgroup/UpdateBudget\uFF1BCBO \u6216\u65E0\u9650\u9884\u7B97\u65F6\u7EC4\u9884\u7B97\u53EF\u80FD\u6539\u4E0D\u52A8\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--budget <amount>", "\u9884\u7B97\uFF0C\u5E7F\u544A\u4E3B\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
150163
+ await runTikTokAdGroupBudget({ ...opts, adGroupId: opts.adgroupId });
150164
+ });
150165
+ root.command("ad-status").description("\u542F\u505C\u5E7F\u544A\uFF08PUT \u2026/ad/updatestatus/Tiktok\uFF1BENABLE \u6216 DISABLE\uFF09").requiredOption(...ACCOUNT_OPTION3).requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--status <status>", "ENABLE \u6216 DISABLE").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC3).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
150166
+ await runTikTokAdStatus(opts);
150167
+ });
149302
150168
  }
149303
150169
 
149304
150170
  // src/commands/yandex-analysis/register-cli.ts
@@ -149361,7 +150227,7 @@ var YANDEX_SECTION_ALIASES = {
149361
150227
 
149362
150228
  // src/commands/yandex-analysis/run-batch.ts
149363
150229
  init_auth();
149364
- import * as path57 from "path";
150230
+ import * as path58 from "path";
149365
150231
  import { performance as performance8 } from "perf_hooks";
149366
150232
  init_version();
149367
150233
 
@@ -149501,8 +150367,8 @@ function endpointHintForYandexSection(def) {
149501
150367
  }
149502
150368
 
149503
150369
  // src/commands/yandex-analysis/merge-snapshot.ts
149504
- import * as fs46 from "fs/promises";
149505
- import * as path56 from "path";
150370
+ import * as fs47 from "fs/promises";
150371
+ import * as path57 from "path";
149506
150372
  function asRecord40(value) {
149507
150373
  if (value && typeof value === "object" && !Array.isArray(value)) {
149508
150374
  return value;
@@ -149552,7 +150418,7 @@ function pickMetrics2(row, extras = []) {
149552
150418
  }
149553
150419
  async function loadSectionPayload3(snapshotDir, file) {
149554
150420
  try {
149555
- const raw = await fs46.readFile(path56.join(snapshotDir, file), "utf8");
150421
+ const raw = await fs47.readFile(path57.join(snapshotDir, file), "utf8");
149556
150422
  return JSON.parse(raw);
149557
150423
  } catch {
149558
150424
  return null;
@@ -149562,7 +150428,7 @@ async function readManifest8(snapshotDir, accountId) {
149562
150428
  const candidates = [];
149563
150429
  if (accountId) candidates.push(reportManifestFile(accountId));
149564
150430
  try {
149565
- const entries = await fs46.readdir(snapshotDir);
150431
+ const entries = await fs47.readdir(snapshotDir);
149566
150432
  for (const name2 of entries.filter(
149567
150433
  (n) => n.startsWith("report-manifest") && n.endsWith(".json")
149568
150434
  )) {
@@ -149572,7 +150438,7 @@ async function readManifest8(snapshotDir, accountId) {
149572
150438
  }
149573
150439
  for (const name2 of candidates) {
149574
150440
  try {
149575
- const raw = await fs46.readFile(path56.join(snapshotDir, name2), "utf8");
150441
+ const raw = await fs47.readFile(path57.join(snapshotDir, name2), "utf8");
149576
150442
  const parsed = JSON.parse(raw);
149577
150443
  if (Array.isArray(parsed.artifacts) && parsed.artifacts.length > 0) return parsed;
149578
150444
  } catch {
@@ -149731,7 +150597,7 @@ function mapDeviceRows2(payload) {
149731
150597
  return asItems(payload).map((r) => pickMetrics2(r, ["device", "network"]));
149732
150598
  }
149733
150599
  async function mergeYandexAnalysisSnapshotIntoReport(payload, snapshotDir) {
149734
- const absDir = path56.resolve(snapshotDir);
150600
+ const absDir = path57.resolve(snapshotDir);
149735
150601
  const metaAccountId = typeof asRecord40(payload.meta)?.accountId === "string" ? asRecord40(payload.meta)?.accountId : void 0;
149736
150602
  const manifest = await readManifest8(snapshotDir, metaAccountId);
149737
150603
  if (!manifest) {
@@ -149917,7 +150783,7 @@ async function runAllYandexSections(opts) {
149917
150783
  const results = await runWithConcurrency5(tasks, concurrency);
149918
150784
  const succeeded = results.filter((r) => r.ok).length;
149919
150785
  const failed = results.length - succeeded;
149920
- const absoluteSnapshotDir = path57.resolve(opts.jsonOut);
150786
+ const absoluteSnapshotDir = path58.resolve(opts.jsonOut);
149921
150787
  const summary = {
149922
150788
  kind: "siluzan-tso-yandex-analysis-snapshot-batch",
149923
150789
  absoluteSnapshotDir,
@@ -149935,9 +150801,9 @@ async function runAllYandexSections(opts) {
149935
150801
  }
149936
150802
 
149937
150803
  // src/commands/yandex-analysis/render-report.ts
149938
- import fs47 from "fs";
150804
+ import fs48 from "fs";
149939
150805
  import fsPromises8 from "fs/promises";
149940
- import path58 from "path";
150806
+ import path59 from "path";
149941
150807
  import { fileURLToPath as fileURLToPath15 } from "url";
149942
150808
 
149943
150809
  // src/commands/yandex-analysis/report-content.ts
@@ -150144,14 +151010,14 @@ init_html();
150144
151010
  var TEMPLATE_BASENAME6 = "yandex-period-report.html";
150145
151011
  var INJECT_MARKER6 = "window.__YANDEX_PERIOD_REPORT__ = window.__YANDEX_PERIOD_REPORT__ || null;";
150146
151012
  function resolveSkillTemplatePath9(basename13) {
150147
- const dir = path58.dirname(fileURLToPath15(import.meta.url));
151013
+ const dir = path59.dirname(fileURLToPath15(import.meta.url));
150148
151014
  const candidates = [
150149
- path58.join(dir, "skill", "report-templates", basename13),
150150
- path58.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
150151
- path58.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
151015
+ path59.join(dir, "skill", "report-templates", basename13),
151016
+ path59.join(dir, "skill", "siluzan-ads", "report-templates", basename13),
151017
+ path59.join(dir, "..", "..", "assets", "siluzan-ads", "report-templates", basename13)
150152
151018
  ];
150153
151019
  for (const p of candidates) {
150154
- if (fs47.existsSync(p)) return p;
151020
+ if (fs48.existsSync(p)) return p;
150155
151021
  }
150156
151022
  return candidates[0];
150157
151023
  }
@@ -150194,10 +151060,10 @@ function injectReportData7(html, payload, lang) {
150194
151060
  return localized.replace(INJECT_MARKER6, `window.__YANDEX_PERIOD_REPORT__ = ${json};`);
150195
151061
  }
150196
151062
  async function runYandexAnalysisRender(opts) {
150197
- const dataPath = path58.resolve(opts.dataFile);
151063
+ const dataPath = path59.resolve(opts.dataFile);
150198
151064
  let data = asRecord42(await readJsonFile9(dataPath));
150199
151065
  if (opts.snapshotDir?.trim()) {
150200
- data = await mergeYandexAnalysisSnapshotIntoReport(data, path58.resolve(opts.snapshotDir));
151066
+ data = await mergeYandexAnalysisSnapshotIntoReport(data, path59.resolve(opts.snapshotDir));
150201
151067
  }
150202
151068
  data = refreshWeeklyFromDaily(data);
150203
151069
  const lang = readReportLangOrExit({ flag: opts.lang, meta: data.meta });
@@ -150223,10 +151089,10 @@ async function runYandexAnalysisRender(opts) {
150223
151089
  `);
150224
151090
  process.exit(1);
150225
151091
  }
150226
- const outPath = path58.resolve(
150227
- opts.out ?? path58.join(path58.dirname(dataPath), "yandex-period-report.html")
151092
+ const outPath = path59.resolve(
151093
+ opts.out ?? path59.join(path59.dirname(dataPath), "yandex-period-report.html")
150228
151094
  );
150229
- const outDir = path58.dirname(outPath);
151095
+ const outDir = path59.dirname(outPath);
150230
151096
  await fsPromises8.mkdir(outDir, { recursive: true });
150231
151097
  await fsPromises8.writeFile(outPath, injectReportData7(html, data, lang), "utf8");
150232
151098
  const { stats } = contentCheck;
@@ -150327,13 +151193,13 @@ function optionalId(raw) {
150327
151193
  function insightsLevelToPath(level) {
150328
151194
  return level;
150329
151195
  }
150330
- function assertYandexAnalysisQuery(path60, query) {
150331
- const caps = YANDEX_PATH_CAPS[path60];
151196
+ function assertYandexAnalysisQuery(path61, query) {
151197
+ const caps = YANDEX_PATH_CAPS[path61];
150332
151198
  if (query.timeIncrement != null && !caps.timeIncrement) {
150333
- throw new Error(`--time-increment \u4E0D\u80FD\u7528\u4E8E /${path60}\uFF08\u4EC5 campaigns / adgroups / ads\uFF09\u3002`);
151199
+ throw new Error(`--time-increment \u4E0D\u80FD\u7528\u4E8E /${path61}\uFF08\u4EC5 campaigns / adgroups / ads\uFF09\u3002`);
150334
151200
  }
150335
151201
  if (query.network != null && !caps.network) {
150336
- throw new Error(`--network \u4E0D\u80FD\u7528\u4E8E /${path60}\uFF08\u4EC5 campaigns / geo / devices\uFF09\u3002`);
151202
+ throw new Error(`--network \u4E0D\u80FD\u7528\u4E8E /${path61}\uFF08\u4EC5 campaigns / geo / devices\uFF09\u3002`);
150337
151203
  }
150338
151204
  if (query.status != null && !caps.status) {
150339
151205
  throw new Error(`--status \u4EC5\u7528\u4E8E /ads\uFF08\u62D2\u5BA1/\u5BA1\u6838\u6001\u8D70\u7ED3\u6784\u67E5\u8BE2\uFF0C\u884C\u5185 spend \u4E3A 0\uFF09\u3002`);
@@ -150350,12 +151216,12 @@ function assertYandexAnalysisQuery(path60, query) {
150350
151216
  );
150351
151217
  }
150352
151218
  if (query.limit != null && !caps.limit) {
150353
- throw new Error(`--limit \u4E0D\u80FD\u7528\u4E8E /${path60}\uFF08overview / daily / devices \u65E0\u6B64\u53C2\u6570\uFF09\u3002`);
151219
+ throw new Error(`--limit \u4E0D\u80FD\u7528\u4E8E /${path61}\uFF08overview / daily / devices \u65E0\u6B64\u53C2\u6570\uFF09\u3002`);
150354
151220
  }
150355
151221
  }
150356
- function buildYandexAnalysisSearchParams(path60, query) {
150357
- assertYandexAnalysisQuery(path60, query);
150358
- const caps = YANDEX_PATH_CAPS[path60];
151222
+ function buildYandexAnalysisSearchParams(path61, query) {
151223
+ assertYandexAnalysisQuery(path61, query);
151224
+ const caps = YANDEX_PATH_CAPS[path61];
150359
151225
  const params = new URLSearchParams({
150360
151226
  account: query.account,
150361
151227
  start: query.start,
@@ -150381,10 +151247,10 @@ function buildYandexAnalysisSearchParams(path60, query) {
150381
151247
  }
150382
151248
  return params;
150383
151249
  }
150384
- async function fetchYandexAnalysisPath(config, path60, query, verbose) {
151250
+ async function fetchYandexAnalysisPath(config, path61, query, verbose) {
150385
151251
  const yandexApiUrl = requireYandexApi(config);
150386
- const params = buildYandexAnalysisSearchParams(path60, query);
150387
- const url = analysisUrl(yandexApiUrl, path60, params.toString());
151252
+ const params = buildYandexAnalysisSearchParams(path61, query);
151253
+ const url = analysisUrl(yandexApiUrl, path61, params.toString());
150388
151254
  return apiFetch2(url, config, {}, verbose);
150389
151255
  }
150390
151256
  function unwrapYandexItems(raw) {
@@ -150398,7 +151264,7 @@ function asRecord43(raw) {
150398
151264
  }
150399
151265
 
150400
151266
  // src/commands/yandex-analysis/entities.ts
150401
- function fail6(label2, err) {
151267
+ function fail7(label2, err) {
150402
151268
  const msg = err instanceof Error ? err.message : String(err);
150403
151269
  console.error(`
150404
151270
  \u274C ${label2}\uFF1A${msg}
@@ -150448,13 +151314,13 @@ ${args.title}
150448
151314
  console.log(` ${args.footnote}
150449
151315
  `);
150450
151316
  }
150451
- async function fetchPath(opts, path60, extra) {
151317
+ async function fetchPath(opts, path61, extra) {
150452
151318
  const accountId = assertYandexAccountId(opts.account);
150453
151319
  const { startDate, endDate } = resolveRange(opts.start, opts.end);
150454
151320
  const config = loadConfig(opts.token);
150455
151321
  const raw = await fetchYandexAnalysisPath(
150456
151322
  config,
150457
- path60,
151323
+ path61,
150458
151324
  {
150459
151325
  account: accountId,
150460
151326
  start: startDate,
@@ -150470,7 +151336,7 @@ async function runYandexAccountStatus(opts) {
150470
151336
  try {
150471
151337
  result = await fetchPath(opts, "overview", {});
150472
151338
  } catch (err) {
150473
- fail6("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
151339
+ fail7("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
150474
151340
  }
150475
151341
  const row = asRecord43(result.raw);
150476
151342
  await emitOrTable(opts, {
@@ -150512,7 +151378,7 @@ async function runYandexCampaignEntities(opts) {
150512
151378
  network: flags.network
150513
151379
  });
150514
151380
  } catch (err) {
150515
- fail6("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
151381
+ fail7("\u67E5\u8BE2 Yandex \u7CFB\u5217\u5931\u8D25", err);
150516
151382
  }
150517
151383
  const items3 = unwrapYandexItems(result.raw);
150518
151384
  await emitOrTable(opts, {
@@ -150558,7 +151424,7 @@ async function runYandexAdGroupEntities(opts) {
150558
151424
  campaignId: flags.campaignId
150559
151425
  });
150560
151426
  } catch (err) {
150561
- fail6("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
151427
+ fail7("\u67E5\u8BE2 Yandex \u5E7F\u544A\u7EC4\u5931\u8D25", err);
150562
151428
  }
150563
151429
  const items3 = unwrapYandexItems(result.raw);
150564
151430
  await emitOrTable(opts, {
@@ -150608,7 +151474,7 @@ async function runYandexAdEntities(opts) {
150608
151474
  adGroupId: flags.adGroupId
150609
151475
  });
150610
151476
  } catch (err) {
150611
- fail6("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
151477
+ fail7("\u67E5\u8BE2 Yandex \u5E7F\u544A\u5931\u8D25", err);
150612
151478
  }
150613
151479
  const items3 = unwrapYandexItems(result.raw);
150614
151480
  const filtered = flags.status != null;
@@ -150660,7 +151526,7 @@ async function runYandexInsights(opts) {
150660
151526
  adGroupId: flags.adGroupId
150661
151527
  });
150662
151528
  } catch (err) {
150663
- fail6("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
151529
+ fail7("\u67E5\u8BE2 Yandex insights \u5931\u8D25", err);
150664
151530
  }
150665
151531
  const items3 = unwrapYandexItems(result.raw);
150666
151532
  await emitOrTable(opts, {
@@ -150696,6 +151562,106 @@ async function runYandexInsights(opts) {
150696
151562
  });
150697
151563
  }
150698
151564
 
151565
+ // src/commands/yandex-analysis/write.ts
151566
+ init_auth();
151567
+ init_cli_json_snapshot();
151568
+ function parseYandexAction(raw) {
151569
+ const value = (raw ?? "").trim().toLowerCase();
151570
+ if (value === "suspend" || value === "resume") return value;
151571
+ throw new Error("action \u53EA\u63A5\u53D7 suspend \u6216 resume");
151572
+ }
151573
+ function parseYandexBudgetMode(raw) {
151574
+ if (raw == null || raw.trim() === "") return "STANDARD";
151575
+ const value = raw.trim().toUpperCase();
151576
+ if (value === "STANDARD" || value === "DISTRIBUTED") return value;
151577
+ throw new Error("\u65E5\u9884\u7B97 mode \u53EA\u63A5\u53D7 STANDARD \u6216 DISTRIBUTED");
151578
+ }
151579
+ function parseYandexAmount(raw, label2) {
151580
+ const n = Number((raw ?? "").trim());
151581
+ if (!Number.isFinite(n) || n <= 0) {
151582
+ throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57\uFF08\u8D26\u6237\u5E01\u79CD\uFF0C\u4E0D\u8981\u81EA\u884C\u4E58 1000000\uFF09`);
151583
+ }
151584
+ return n;
151585
+ }
151586
+ function requireYandexEntityId(raw, label2) {
151587
+ const id = raw.trim();
151588
+ if (!/^\d+$/.test(id) || id === "0") {
151589
+ throw new Error(`${label2} \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6570\u5B57 ID`);
151590
+ }
151591
+ return id;
151592
+ }
151593
+ function yandexAdsUrl(base2, path61, account) {
151594
+ const q = new URLSearchParams({ account });
151595
+ return `${base2.replace(/\/$/, "")}/yandex-ads/${path61}?${q}`;
151596
+ }
151597
+ async function postYandex(path61, body, opts, section, commandLabel) {
151598
+ const account = assertYandexAccountId(opts.account);
151599
+ const config = loadConfig(opts.token);
151600
+ const url = yandexAdsUrl(requireYandexApi(config), path61, account);
151601
+ const payload = await apiFetch2(
151602
+ url,
151603
+ config,
151604
+ { method: "POST", body: JSON.stringify(body) },
151605
+ opts.verbose
151606
+ );
151607
+ const emitted = await emitCliJsonOrSnapshot(
151608
+ { jsonOut: opts.jsonOut },
151609
+ { section, commandLabel, payload, idSuffix: account }
151610
+ );
151611
+ if (emitted) return;
151612
+ console.log(`
151613
+ \u2705 ${commandLabel} \u5DF2\u63D0\u4EA4
151614
+ `);
151615
+ console.log(JSON.stringify(payload, null, 2));
151616
+ console.log();
151617
+ }
151618
+ async function runYandexCampaignState(opts) {
151619
+ const id = requireYandexEntityId(opts.campaignId, "campaign-id");
151620
+ const action = parseYandexAction(opts.action);
151621
+ await postYandex(
151622
+ `campaigns/${id}/state`,
151623
+ { action },
151624
+ opts,
151625
+ "yandex-campaign-state",
151626
+ "yandex-analysis campaign-state"
151627
+ );
151628
+ }
151629
+ async function runYandexCampaignBudget(opts) {
151630
+ const id = requireYandexEntityId(opts.campaignId, "campaign-id");
151631
+ const amount = parseYandexAmount(opts.dailyBudget, "\u65E5\u9884\u7B97");
151632
+ const mode = parseYandexBudgetMode(opts.mode);
151633
+ await postYandex(
151634
+ `campaigns/${id}/daily-budget`,
151635
+ { amount, mode },
151636
+ opts,
151637
+ "yandex-campaign-budget",
151638
+ "yandex-analysis campaign-budget"
151639
+ );
151640
+ }
151641
+ async function runYandexAdGroupState(opts) {
151642
+ requireYandexEntityId(opts.adGroupId, "adgroup-id");
151643
+ parseYandexAction(opts.action);
151644
+ throw new Error(
151645
+ "Yandex Direct \u7684\u5E7F\u544A\u7EC4\u4E0D\u80FD\u5355\u72EC\u6682\u505C\u6216\u6062\u590D\u3002\u8BF7\u7528 ad-state \u6539\u7EC4\u91CC\u7684\u5E7F\u544A\uFF0C\u6216\u7528 campaign-state \u6539\u6574\u4E2A\u7CFB\u5217\u3002"
151646
+ );
151647
+ }
151648
+ async function runYandexAdState(opts) {
151649
+ const id = requireYandexEntityId(opts.adId, "ad-id");
151650
+ const action = parseYandexAction(opts.action);
151651
+ await postYandex(`ads/${id}/state`, { action }, opts, "yandex-ad-state", "yandex-analysis ad-state");
151652
+ }
151653
+ async function runYandexKeywordBid(opts) {
151654
+ const id = requireYandexEntityId(opts.keywordId, "keyword-id");
151655
+ const amount = parseYandexAmount(opts.searchBid, "\u641C\u7D22\u51FA\u4EF7");
151656
+ await postYandex(
151657
+ `keywords/${id}/search-bid`,
151658
+ { amount },
151659
+ opts,
151660
+ "yandex-keyword-bid",
151661
+ "yandex-analysis keyword-bid"
151662
+ );
151663
+ }
151664
+
150699
151665
  // src/commands/yandex-analysis/register-cli.ts
150700
151666
  var ACCOUNT_OPTION4 = [
150701
151667
  "-a, --account <id>",
@@ -150786,6 +151752,328 @@ function registerYandexAnalysisCommands(program2) {
150786
151752
  await runYandexInsights(opts);
150787
151753
  }
150788
151754
  );
151755
+ root.command("campaign-state").description("\u6682\u505C\u6216\u6062\u590D\u7CFB\u5217\uFF08Direct campaigns.suspend / campaigns.resume\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
151756
+ await runYandexCampaignState(opts);
151757
+ });
151758
+ root.command("campaign-budget").description("\u6539\u7CFB\u5217\u65E5\u9884\u7B97\uFF08Direct campaigns.update DailyBudget\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF0C\u7F51\u5173\u6362\u7B97 micros\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--campaign-id <id>", "\u7CFB\u5217 ID").requiredOption("--daily-budget <amount>", "\u65E5\u9884\u7B97\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("--mode <mode>", "STANDARD\uFF08\u9ED8\u8BA4\uFF09\u6216 DISTRIBUTED").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
151759
+ await runYandexCampaignBudget(opts);
151760
+ });
151761
+ root.command("adgroup-state").description("\u5E7F\u544A\u7EC4\u4E0D\u80FD\u5355\u72EC\u542F\u505C\uFF08Direct \u7684 AdGroups \u6CA1\u6709 suspend/resume\uFF1B\u8BF7\u7528 ad-state \u6216 campaign-state\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--adgroup-id <id>", "\u5E7F\u544A\u7EC4 ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
151762
+ await runYandexAdGroupState({ ...opts, adGroupId: opts.adgroupId });
151763
+ });
151764
+ root.command("ad-state").description("\u6682\u505C\u6216\u6062\u590D\u5E7F\u544A\uFF08Direct ads.suspend / ads.resume\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--ad-id <id>", "\u5E7F\u544A ID").requiredOption("--action <action>", "suspend \u6216 resume").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
151765
+ await runYandexAdState(opts);
151766
+ });
151767
+ root.command("keyword-bid").description("\u6539\u5173\u952E\u8BCD\u641C\u7D22\u51FA\u4EF7\uFF08Direct keywordbids.set SearchBid\uFF1B\u91D1\u989D\u662F\u8D26\u6237\u5E01\u79CD\uFF09").requiredOption(...ACCOUNT_OPTION4).requiredOption("--keyword-id <id>", "\u5173\u952E\u8BCD ID").requiredOption("--search-bid <amount>", "\u641C\u7D22\u51FA\u4EF7\uFF0C\u8D26\u6237\u5E01\u79CD\uFF0C\u5FC5\u987B\u5927\u4E8E 0").option("-t, --token <token>", "Auth Token").option("--json-out <path>", JSON_OUT_OPTION_DESC4).option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
151768
+ await runYandexKeywordBid(opts);
151769
+ });
151770
+ }
151771
+
151772
+ // src/commands/ad-gap/catalog.ts
151773
+ var bing = (path61, needsBody = true) => ({
151774
+ service: "tso",
151775
+ method: "POST",
151776
+ path: `/reporting/media-account/BingV2/{account}/library/${path61}`,
151777
+ needsBody
151778
+ });
151779
+ var yandex = (path61, extra) => ({
151780
+ service: "yandex",
151781
+ method: "POST",
151782
+ path: `/yandex-ads/library/${path61}`,
151783
+ needsBody: true,
151784
+ ...extra
151785
+ });
151786
+ var facebook = (path61, extra) => ({
151787
+ service: "facebook",
151788
+ method: "POST",
151789
+ path: `/api/fb/ads/{account}/${path61}`,
151790
+ needsBody: true,
151791
+ ...extra
151792
+ });
151793
+ var tiktok = (path61) => ({
151794
+ service: "tiktok",
151795
+ method: "POST",
151796
+ path: `/tiktokgap/${path61}`,
151797
+ needsBody: true
151798
+ });
151799
+ var google = (method, path61, extra) => ({
151800
+ service: "google",
151801
+ method,
151802
+ path: path61,
151803
+ needsBody: method !== "GET" && method !== "DELETE",
151804
+ ...extra
151805
+ });
151806
+ var GAP_ACTIONS = {
151807
+ "bing.search-campaign": bing("campaigns"),
151808
+ "bing.delete-campaigns": bing("campaigns/delete"),
151809
+ "bing.ad-group": bing("ad-groups"),
151810
+ "bing.delete-ad-groups": bing("ad-groups/delete"),
151811
+ "bing.responsive-ad": bing("ads"),
151812
+ "bing.delete-ads": bing("ads/delete"),
151813
+ "bing.keywords": bing("keywords"),
151814
+ "bing.keyword-bids": bing("keywords/bids"),
151815
+ "bing.delete-keywords": bing("keywords/delete"),
151816
+ "bing.negative-keywords": bing("negative-keywords"),
151817
+ "bing.campaign-negative-sites": bing("negative-sites/campaigns"),
151818
+ "bing.ad-group-negative-sites": bing("negative-sites/ad-groups"),
151819
+ "bing.location": bing("locations"),
151820
+ "bing.delete-locations": bing("locations/delete"),
151821
+ "bing.budget": bing("budgets"),
151822
+ "bing.delete-budgets": bing("budgets/delete"),
151823
+ "bing.sitelink": bing("sitelinks"),
151824
+ "bing.link-sitelink": bing("sitelinks/link"),
151825
+ "bing.customer-list": bing("customer-lists"),
151826
+ "bing.customer-list-items": bing("customer-lists/items"),
151827
+ "bing.uet-tag": bing("uet-tags"),
151828
+ "bing.conversion-goal": bing("conversion-goals"),
151829
+ "bing.offline-conversions": bing("offline-conversions"),
151830
+ "bing.label": bing("labels"),
151831
+ "bing.link-labels": bing("labels/link"),
151832
+ "bing.experiment": bing("experiments"),
151833
+ "bing.asset-group": bing("asset-groups"),
151834
+ "bing.max-clicks": bing("bid-strategies"),
151835
+ "bing.appeal": bing("editorial-appeals"),
151836
+ "bing.image": bing("media"),
151837
+ "bing.video": bing("videos"),
151838
+ "yandex.text-campaign": yandex("campaigns"),
151839
+ "yandex.rename-campaign": yandex("campaigns/{id}/name", { needsId: true }),
151840
+ "yandex.archive-campaign": yandex("campaigns/{id}/archive", { needsId: true, needsBody: false }),
151841
+ "yandex.delete-campaign": yandex("campaigns/{id}/delete", { needsId: true, needsBody: false }),
151842
+ "yandex.ad-group": yandex("adgroups"),
151843
+ "yandex.rename-ad-group": yandex("adgroups/{id}/name", { needsId: true }),
151844
+ "yandex.delete-ad-group": yandex("adgroups/{id}/delete", { needsId: true, needsBody: false }),
151845
+ "yandex.text-ad": yandex("ads"),
151846
+ "yandex.moderate-ad": yandex("ads/{id}/moderate", { needsId: true, needsBody: false }),
151847
+ "yandex.delete-ad": yandex("ads/{id}/delete", { needsId: true, needsBody: false }),
151848
+ "yandex.keyword": yandex("keywords"),
151849
+ "yandex.update-keyword": yandex("keywords/{id}/text", { needsId: true }),
151850
+ "yandex.keyword-state": yandex("keywords/{id}/state", { needsId: true }),
151851
+ "yandex.delete-keyword": yandex("keywords/{id}/delete", { needsId: true, needsBody: false }),
151852
+ "yandex.keyword-bids": yandex("keyword-bids"),
151853
+ "yandex.mobile-modifier": yandex("bid-modifiers"),
151854
+ "yandex.delete-modifier": yandex("bid-modifiers/{id}/delete", { needsId: true, needsBody: false }),
151855
+ "yandex.retargeting-list": yandex("retargeting-lists"),
151856
+ "yandex.delete-retargeting-list": yandex("retargeting-lists/{id}/delete", { needsId: true, needsBody: false }),
151857
+ "yandex.audience-target": yandex("audience-targets"),
151858
+ "yandex.delete-audience-target": yandex("audience-targets/{id}/delete", { needsId: true, needsBody: false }),
151859
+ "yandex.sitelinks": yandex("sitelinks"),
151860
+ "yandex.delete-sitelinks": yandex("sitelinks/{id}/delete", { needsId: true, needsBody: false }),
151861
+ "yandex.callout": yandex("callouts"),
151862
+ "yandex.delete-callout": yandex("callouts/{id}/delete", { needsId: true, needsBody: false }),
151863
+ "yandex.ad-image": yandex("ad-images"),
151864
+ "yandex.delete-ad-image": yandex("ad-images/{id}/delete", { needsId: true, needsBody: false }),
151865
+ "yandex.creative": yandex("creatives"),
151866
+ "yandex.feed": yandex("feeds"),
151867
+ "yandex.delete-feed": yandex("feeds/{id}/delete", { needsId: true, needsBody: false }),
151868
+ "yandex.changes": yandex("changes"),
151869
+ "yandex.dictionaries": yandex("dictionaries"),
151870
+ "yandex.leads": yandex("leads"),
151871
+ "tiktok.audience-file": tiktok("audiences/file"),
151872
+ "tiktok.audience-rule": tiktok("audiences/rule"),
151873
+ "tiktok.campaign-copy": tiktok("campaign-copies"),
151874
+ "tiktok.gmv-max": tiktok("gmv-max"),
151875
+ "tiktok.smart-plus": tiktok("smart-plus"),
151876
+ "tiktok.negative-keywords": tiktok("negative-keywords"),
151877
+ "tiktok.split-test": tiktok("split-tests"),
151878
+ "meta.outcome-campaign": facebook("outcome-campaigns"),
151879
+ "meta.outcome-campaign-update": facebook("outcome-campaigns/{id}", { needsId: true }),
151880
+ "google.create-conversion-action": google("POST", "/conversion-actions/{account}"),
151881
+ "google.update-conversion-action": google("PUT", "/conversion-actions/{account}/{id}", { needsId: true }),
151882
+ "google.remove-conversion-action": google("DELETE", "/conversion-actions/{account}/{id}", { needsId: true, needsBody: false }),
151883
+ "google.upload-clicks": google("POST", "/conversion-uploads/{account}/clicks"),
151884
+ "google.upload-enhanced-clicks": google("POST", "/conversion-uploads/{account}/enhanced-clicks"),
151885
+ "google.customer-match-list": google("POST", "/customer-match/{account}/user-lists"),
151886
+ "google.customer-match-job": google("POST", "/customer-match/{account}/jobs?userListId={id}", { needsId: true, needsBody: false }),
151887
+ "google.customer-match-operations": google("POST", "/customer-match/{account}/jobs/{id}/operations", { needsId: true }),
151888
+ "google.customer-match-run": google("POST", "/customer-match/{account}/jobs/{id}/run", { needsId: true }),
151889
+ "google.value-rule": google("POST", "/conversion-value-rules/{account}"),
151890
+ "google.remove-value-rule": google("DELETE", "/conversion-value-rules/{account}/{id}", { needsId: true, needsBody: false }),
151891
+ "google.seasonality": google("POST", "/bidding-seasonality/{account}"),
151892
+ "google.remove-seasonality": google("DELETE", "/bidding-seasonality/{account}/{id}", { needsId: true, needsBody: false }),
151893
+ "google.data-exclusion": google("POST", "/bidding-data-exclusions/{account}"),
151894
+ "google.remove-data-exclusion": google("DELETE", "/bidding-data-exclusions/{account}/{id}", { needsId: true, needsBody: false }),
151895
+ "google.campaign-simulations": google("GET", "/bid-simulations/{account}/campaigns/{id}", { needsId: true, needsBody: false }),
151896
+ "google.experiment": google("POST", "/experiments/{account}"),
151897
+ "google.end-experiment": google("POST", "/experiments/{account}/{id}/end", { needsId: true, needsBody: false }),
151898
+ "google.label": google("POST", "/labels/{account}"),
151899
+ "google.link-campaign-label": google("POST", "/labels/{account}/campaigns/{parent}", { needsParent: true }),
151900
+ "google.unlink-campaign-label": google("DELETE", "/labels/{account}/campaigns/{parent}/{id}", { needsParent: true, needsId: true, needsBody: false }),
151901
+ "google.link-ad-group-label": google("POST", "/labels/{account}/ad-groups/{parent}", { needsParent: true }),
151902
+ "google.unlink-ad-group-label": google("DELETE", "/labels/{account}/ad-groups/{parent}/{id}", { needsParent: true, needsId: true, needsBody: false }),
151903
+ "google.link-ad-label": google("POST", "/labels/{account}/ad-groups/{parent}/ads/{id}", { needsParent: true, needsId: true }),
151904
+ "google.unlink-ad-label": google("DELETE", "/labels/{account}/ad-groups/{parent}/ads/{id}/{label}", { needsParent: true, needsId: true, needsLabel: true, needsBody: false }),
151905
+ "google.link-criterion-label": google("POST", "/labels/{account}/ad-groups/{parent}/criteria/{id}", { needsParent: true, needsId: true }),
151906
+ "google.unlink-criterion-label": google("DELETE", "/labels/{account}/ad-groups/{parent}/criteria/{id}/{label}", { needsParent: true, needsId: true, needsLabel: true, needsBody: false }),
151907
+ "google.customizer-attribute": google("POST", "/customizer-attributes/{account}"),
151908
+ "google.customer-customizer": google("POST", "/customizers/{account}"),
151909
+ "google.criterion-bid": google("PUT", "/ad-groups/{account}/{parent}/criteria/{id}/bid", { needsParent: true, needsId: true }),
151910
+ "google.shopping-campaign": google("POST", "/campaigns/{account}/shopping"),
151911
+ "google.dynamic-search-campaign": google("POST", "/campaigns/{account}/dynamic-search"),
151912
+ "google.app-campaign": google("POST", "/campaigns/{account}/app"),
151913
+ "google.display-campaign": google("POST", "/campaigns/{account}/display"),
151914
+ "google.apply-recommendation": google("POST", "/recommendations/{account}/apply"),
151915
+ "google.dismiss-recommendation": google("POST", "/recommendations/{account}/dismiss")
151916
+ };
151917
+ function gapActionNames() {
151918
+ return Object.keys(GAP_ACTIONS).sort();
151919
+ }
151920
+ function resolveGapPath(actionName, target) {
151921
+ const action = GAP_ACTIONS[actionName];
151922
+ if (!action) {
151923
+ throw new Error(`\u672A\u77E5 action\uFF1A${actionName}`);
151924
+ }
151925
+ if (action.path.includes("catalog")) {
151926
+ throw new Error("\u5546\u54C1\u76EE\u5F55\u8DEF\u5F84\u672A\u63A5\u5165");
151927
+ }
151928
+ const account = requireToken(target.account, "account");
151929
+ const parent = action.needsParent ? requireToken(target.parent, "parent") : target.parent?.trim() ?? "";
151930
+ const id = action.needsId ? requireToken(target.id, "id") : target.id?.trim() ?? "";
151931
+ const label2 = action.needsLabel ? requireToken(target.label, "label") : target.label?.trim() ?? "";
151932
+ let path61 = action.path.replaceAll("{account}", encodeURIComponent(account)).replaceAll("{parent}", encodeURIComponent(parent)).replaceAll("{id}", encodeURIComponent(id)).replaceAll("{label}", encodeURIComponent(label2));
151933
+ if (path61.includes("{")) {
151934
+ throw new Error(`action ${actionName} \u8FD8\u7F3A\u8DEF\u5F84\u53C2\u6570`);
151935
+ }
151936
+ if (action.service === "yandex") {
151937
+ path61 += `${path61.includes("?") ? "&" : "?"}account=${encodeURIComponent(account)}`;
151938
+ }
151939
+ return { action, path: path61 };
151940
+ }
151941
+ function requireToken(value, label2) {
151942
+ const text5 = (value ?? "").trim();
151943
+ if (!text5 || text5.includes("/") || text5.includes("\\")) {
151944
+ throw new Error(`${label2} \u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u4E5F\u4E0D\u80FD\u5305\u542B\u659C\u6760`);
151945
+ }
151946
+ return text5;
151947
+ }
151948
+
151949
+ // src/commands/ad-gap/run.ts
151950
+ init_auth();
151951
+ init_cli_json_snapshot();
151952
+ init_shared();
151953
+ import { readFileSync as readFileSync21 } from "fs";
151954
+ function readGapBody(opts, required) {
151955
+ const inline = opts.body?.trim();
151956
+ const file = opts.bodyFile?.trim();
151957
+ if (inline && file) {
151958
+ throw new Error("\u53EA\u4F20 --body \u6216 --body-file \u5176\u4E2D\u4E00\u4E2A");
151959
+ }
151960
+ if (!inline && !file) {
151961
+ if (!required) return void 0;
151962
+ throw new Error("\u8FD9\u4E2A action \u9700\u8981 --body \u6216 --body-file");
151963
+ }
151964
+ const raw = file ? readFileSync21(file, "utf8") : inline;
151965
+ let parsed;
151966
+ try {
151967
+ parsed = JSON.parse(raw);
151968
+ } catch {
151969
+ throw new Error("\u8BF7\u6C42\u4F53\u4E0D\u662F\u5408\u6CD5 JSON");
151970
+ }
151971
+ if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
151972
+ throw new Error("\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F JSON \u5BF9\u8C61");
151973
+ }
151974
+ return parsed;
151975
+ }
151976
+ function assertTikTokAccepted(payload) {
151977
+ if (payload == null || typeof payload !== "object" || Array.isArray(payload)) return;
151978
+ const code = payload.code;
151979
+ if (typeof code === "number" && code !== 0) {
151980
+ const message = payload.message;
151981
+ const text5 = typeof message === "string" && message.trim() ? message.trim() : String(code);
151982
+ throw new Error("TikTok \u62D2\u7EDD\u8BE5\u8BF7\u6C42: " + text5);
151983
+ }
151984
+ }
151985
+ function assertTikTokAdvertiser(account, body) {
151986
+ const advertiserId = body.advertiser_id;
151987
+ if (String(advertiserId ?? "").trim() !== account.trim()) {
151988
+ throw new Error("TikTok \u8BF7\u6C42\u4F53\u91CC\u7684 advertiser_id \u5FC5\u987B\u548C --account \u76F8\u540C");
151989
+ }
151990
+ }
151991
+ var META_OUTCOME_OBJECTIVES = /* @__PURE__ */ new Set([
151992
+ "OUTCOME_AWARENESS",
151993
+ "OUTCOME_TRAFFIC",
151994
+ "OUTCOME_ENGAGEMENT",
151995
+ "OUTCOME_APP_PROMOTION",
151996
+ "OUTCOME_SALES"
151997
+ ]);
151998
+ function assertMetaOutcome(action, body) {
151999
+ const record2 = body;
152000
+ const status = typeof record2.status === "string" ? record2.status.trim().toUpperCase() : "";
152001
+ if (status && status !== "PAUSED") {
152002
+ throw new Error("\u8FD9\u6761\u8DEF\u5F84\u53EA\u63A5\u53D7 PAUSED\uFF0C\u4E0D\u80FD\u5728\u8FD9\u91CC\u6253\u5F00\u6295\u653E");
152003
+ }
152004
+ if (action === "meta.outcome-campaign") {
152005
+ const objective = String(record2.objective ?? "").trim().toUpperCase();
152006
+ if (objective === "OUTCOME_LEADS") {
152007
+ throw new Error("\u7EBF\u7D22\u7CFB\u5217\u8BF7\u7528 meta-ad\uFF0C\u4E0D\u8981\u7528 meta.outcome-campaign");
152008
+ }
152009
+ if (!META_OUTCOME_OBJECTIVES.has(objective)) {
152010
+ throw new Error("objective \u53EA\u63A5\u53D7\u8BA4\u77E5\u3001\u6D41\u91CF\u3001\u4E92\u52A8\u3001\u5E94\u7528\u63A8\u5E7F\u3001\u9500\u552E\u8FD9\u4E94\u4E2A\u76EE\u6807");
152011
+ }
152012
+ if (!Array.isArray(record2.special_ad_categories)) {
152013
+ throw new Error("special_ad_categories \u5FC5\u586B\uFF0C\u6CA1\u6709\u7279\u6B8A\u5206\u7C7B\u65F6\u4F20\u7A7A\u6570\u7EC4");
152014
+ }
152015
+ }
152016
+ if (action === "meta.outcome-campaign-update" && ("objective" in record2 || "buying_type" in record2 || "special_ad_categories" in record2)) {
152017
+ throw new Error("\u8FD9\u91CC\u4E0D\u80FD\u6539 objective\u3001buying_type \u6216 special_ad_categories");
152018
+ }
152019
+ }
152020
+ async function runAdGap(opts) {
152021
+ const resolved = resolveGapPath(opts.action, opts);
152022
+ const body = readGapBody(opts, resolved.action.needsBody);
152023
+ if (resolved.action.service === "tiktok") {
152024
+ assertTikTokAdvertiser(opts.account, body);
152025
+ }
152026
+ if (resolved.action.service === "facebook") {
152027
+ assertMetaOutcome(opts.action, body);
152028
+ }
152029
+ const config = loadConfig(opts.token);
152030
+ const url = serviceBase(resolved.action.service, config) + resolved.path;
152031
+ const payload = await apiFetch2(
152032
+ url,
152033
+ config,
152034
+ {
152035
+ method: resolved.action.method,
152036
+ body: body == null ? void 0 : JSON.stringify(body)
152037
+ },
152038
+ opts.verbose
152039
+ );
152040
+ if (resolved.action.service === "tiktok") {
152041
+ assertTikTokAccepted(payload);
152042
+ }
152043
+ const emitted = await emitCliJsonOrSnapshot(
152044
+ { jsonOut: opts.jsonOut },
152045
+ {
152046
+ section: `ad-gap-${opts.action}`,
152047
+ commandLabel: `ad-gap ${opts.action}`,
152048
+ payload,
152049
+ idSuffix: opts.account.trim()
152050
+ }
152051
+ );
152052
+ if (emitted) return;
152053
+ console.log(`
152054
+ \u2705 ad-gap ${opts.action} \u5DF2\u63D0\u4EA4
152055
+ `);
152056
+ console.log(JSON.stringify(payload, null, 2));
152057
+ console.log();
152058
+ }
152059
+ function serviceBase(service, config) {
152060
+ if (service === "tso") return config.apiBaseUrl.replace(/\/$/, "");
152061
+ if (service === "google") return requireGoogleApi(config).replace(/\/$/, "");
152062
+ if (service === "yandex") return requireYandexApi(config).replace(/\/$/, "");
152063
+ if (service === "facebook") return requireFacebookApi(config).replace(/\/$/, "");
152064
+ return requireTikTokApiUrl(config).replace(/\/$/, "");
152065
+ }
152066
+
152067
+ // src/commands/ad-gap/register-cli.ts
152068
+ function registerAdGap(program2) {
152069
+ program2.command("ad-gap").description(
152070
+ "\u63D0\u4EA4\u5DF2\u7ECF\u63A5\u5165\u7684\u5E7F\u544A\u7F3A\u53E3\u63A5\u53E3\u3002--action \u51B3\u5B9A\u8DEF\u5F84\uFF0C--body \u662F\u8BE5\u63A5\u53E3\u7684 JSON\u3002\u5199\u64CD\u4F5C\u9700\u8981\u5168\u5C40 --commit\u3002\u65B0\u5EFA\u5BF9\u8C61\u7531\u7F51\u5173\u4FDD\u6301\u6682\u505C\u6216\u5173\u95ED\uFF0C\u4E0D\u8981\u5728\u6B63\u6587\u91CC\u8981\u6C42\u7ACB\u523B\u5F00\u542F\u6D88\u8017\u3002"
152071
+ ).requiredOption("--action <name>", `\u52A8\u4F5C\u540D\u3002\u53EF\u9009\uFF1A${gapActionNames().join(", ")}`).requiredOption(
152072
+ "--account <id>",
152073
+ "Google/Bing \u6570\u5B57\u8D26\u6237\u3001Yandex \u767B\u5F55\u540D\u3001TikTok advertiser_id\uFF0C\u6216 Meta \u5E7F\u544A\u8D26\u6237\uFF08\u6570\u5B57\u6216 act_\uFF09"
152074
+ ).option("--parent <id>", "\u8DEF\u5F84\u91CC\u7684\u4E0A\u4E00\u5C42 ID\uFF0C\u4F8B\u5982\u5E7F\u544A\u7EC4").option("--id <id>", "\u8DEF\u5F84\u91CC\u7684\u5BF9\u8C61 ID").option("--label <id>", "\u89E3\u9664\u5E7F\u544A\u6216\u51C6\u5219\u6807\u7B7E\u65F6\u7684\u6807\u7B7E ID").option("--body <json>", "\u8BF7\u6C42\u4F53 JSON \u5BF9\u8C61").option("--body-file <path>", "\u8BF7\u6C42\u4F53 JSON \u6587\u4EF6").option("-t, --token <token>", "Auth Token").option("--json-out <path>", "\u628A\u54CD\u5E94\u5199\u5230\u6587\u4EF6").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF", false).action(async (opts) => {
152075
+ await runAdGap(opts);
152076
+ });
150789
152077
  }
150790
152078
 
150791
152079
  // src/index.ts
@@ -150978,9 +152266,9 @@ function interceptAgentCompatArgv(argv) {
150978
152266
  installProcessHandlers();
150979
152267
  function getVersion() {
150980
152268
  try {
150981
- const __dirname3 = path59.dirname(fileURLToPath16(import.meta.url));
150982
- const pkgPath = path59.join(__dirname3, "..", "package.json");
150983
- const pkg = JSON.parse(fs48.readFileSync(pkgPath, "utf8"));
152269
+ const __dirname3 = path60.dirname(fileURLToPath16(import.meta.url));
152270
+ const pkgPath = path60.join(__dirname3, "..", "package.json");
152271
+ const pkg = JSON.parse(fs49.readFileSync(pkgPath, "utf8"));
150984
152272
  return pkg.version ?? "0.0.0";
150985
152273
  } catch {
150986
152274
  return "0.0.0";
@@ -151001,7 +152289,7 @@ configureCliJsonSnapshot({
151001
152289
  configureSiluzanClientIdentity({ client: "tso-cli", resolveVersion: getVersion });
151002
152290
  var program = new Command6();
151003
152291
  program.name("siluzan-tso").description(
151004
- "Siluzan \u5E7F\u544A\u8D26\u6237\u7BA1\u7406\uFF1A\u8D26\u6237\u67E5\u8BE2\u3001\u4F59\u989D\u3001\u6295\u653E\u6570\u636E\u3001\u5F00\u6237\u7533\u8BF7\uFF08Google/TikTok/Yandex/Bing/Meta\uFF09\u3001\n\u8D26\u53F7\u5206\u4EAB/\u89E3\u7ED1\u3001\u4F18\u5316\u62A5\u544A\u3001Google/Meta/TikTok/Bing/Yandex \u8D26\u6237\u5206\u6790\u3001Google \u5E7F\u544A\u8BCA\u65AD\u62A5\u544A\uFF08google-ads-diagnosis render\uFF09\u3001Google \u5B63\u5EA6\u7ECF\u8425\u62A5\u544A\uFF08google-quarterly\uFF09\u3001\u7F51\u7AD9\u8BCA\u65AD\uFF08website-diagnosis\uFF09\u3001\u6218\u7565\u5E02\u573A\u5206\u6790\uFF08market-analysis\uFF0CAgent \u751F\u6210\u62A5\u544A\uFF09\u3001\u5145\u503C\u8F6C\u8D26\u3001\u5F00\u7968\u3001\u667A\u80FD\u9884\u8B66\u3001Google \u5E7F\u544A\u7BA1\u7406\uFF08Search/PMax\uFF0C\u542B\u5F02\u6B65\u6279\u91CF\uFF09\u3001Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\uFF08meta-ad\uFF09\u3002"
152292
+ "Siluzan \u5E7F\u544A\u8D26\u6237\u7BA1\u7406\uFF1A\u8D26\u6237\u67E5\u8BE2\u3001\u4F59\u989D\u3001\u6295\u653E\u6570\u636E\u3001\u5F00\u6237\u7533\u8BF7\uFF08Google/TikTok/Yandex/Bing/Meta\uFF09\u3001\n\u8D26\u53F7\u5206\u4EAB/\u89E3\u7ED1\u3001\u4F18\u5316\u62A5\u544A\u3001Google/Meta/TikTok/Bing/Yandex \u8D26\u6237\u5206\u6790\u3001Google \u5E7F\u544A\u8BCA\u65AD\u62A5\u544A\uFF08google-ads-diagnosis render\uFF09\u3001Google \u5B63\u5EA6\u7ECF\u8425\u62A5\u544A\uFF08google-quarterly\uFF09\u3001\u7F51\u7AD9\u8BCA\u65AD\uFF08website-diagnosis\uFF09\u3001\u6218\u7565\u5E02\u573A\u5206\u6790\uFF08market-analysis\uFF0CAgent \u751F\u6210\u62A5\u544A\uFF09\u3001\u5145\u503C\u8F6C\u8D26\u3001\u5F00\u7968\u3001\u667A\u80FD\u9884\u8B66\u3001Google \u5E7F\u544A\u7BA1\u7406\uFF08Search/PMax\uFF0C\u542B\u5F02\u6B65\u6279\u91CF\uFF09\u3001Meta Instant Form \u7EBF\u7D22\u5E7F\u544A\uFF08meta-ad\uFF09\u3001Bing/Yandex/TikTok \u542F\u505C\u4E0E\u9884\u7B97\u3002"
151005
152293
  ).version(getVersion());
151006
152294
  program.option("--commit <text>", "\u5199\u64CD\u4F5C\u8BF4\u660E\uFF1B\u8BB0\u5165\u672C\u673A\u5199\u5BA1\u8BA1 JSONL");
151007
152295
  program.hook("preAction", async () => {
@@ -151037,6 +152325,7 @@ var REGISTRARS = [
151037
152325
  registerBingAnalysisCommands,
151038
152326
  registerTikTokAnalysisCommands,
151039
152327
  registerYandexAnalysisCommands,
152328
+ registerAdGap,
151040
152329
  register15,
151041
152330
  register16,
151042
152331
  register17,