beervid-app-cli 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.mjs +35 -88
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -169,11 +169,11 @@ function register(cli2) {
169
169
  if (type === "tt") {
170
170
  const data = await openApiGet("/api/v1/open/thirdparty-auth/tt-url");
171
171
  console.log("TT OAuth \u6388\u6743\u94FE\u63A5:");
172
- printResult({ type: "tt", url: data });
172
+ printResult(data);
173
173
  } else {
174
174
  const data = await openApiGet("/api/v1/open/thirdparty-auth/tts-url");
175
175
  console.log("TTS OAuth \u6388\u6743\u94FE\u63A5:");
176
- printResult({ type: "tts", url: data.crossBorderUrl });
176
+ printResult(data);
177
177
  }
178
178
  } catch (err) {
179
179
  rethrowIfProcessExit(err);
@@ -451,7 +451,7 @@ function register5(cli2) {
451
451
 
452
452
  // src/commands/query-video.ts
453
453
  function register6(cli2) {
454
- cli2.command("query-video", "\u67E5\u8BE2\u89C6\u9891\u7EDF\u8BA1\u6570\u636E").option("--business-id <id>", "TT \u8D26\u53F7 businessId\uFF08\u5FC5\u586B\uFF09").option("--item-ids <ids>", "\u89C6\u9891 ID\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF08\u5FC5\u586B\uFF09").action(
454
+ cli2.command("query-video", "\u67E5\u8BE2\u89C6\u9891\u7EDF\u8BA1\u6570\u636E").option("--business-id <id>", "TT \u8D26\u53F7 businessId\uFF08\u5FC5\u586B\uFF09").option("--item-ids <ids>", "\u89C6\u9891 ID\uFF0C\u652F\u6301\u91CD\u590D\u4F20\u53C2\u6216\u9017\u53F7\u5206\u9694\uFF08\u5FC5\u586B\uFF09").action(
455
455
  async (options) => {
456
456
  if (!options.businessId || !options.itemIds) {
457
457
  const missing = [
@@ -465,7 +465,7 @@ function register6(cli2) {
465
465
  );
466
466
  process.exit(1);
467
467
  }
468
- const itemIds = options.itemIds.split(",").map((id) => id.trim()).filter(Boolean);
468
+ const itemIds = (Array.isArray(options.itemIds) ? options.itemIds : [options.itemIds]).flatMap((value) => value.split(",")).map((id) => id.trim()).filter(Boolean);
469
469
  if (itemIds.length === 0) {
470
470
  console.error("\u9519\u8BEF: --item-ids \u4E0D\u80FD\u4E3A\u7A7A");
471
471
  process.exit(1);
@@ -501,7 +501,7 @@ function register6(cli2) {
501
501
  if (v.shareUrl) console.log(` \u94FE\u63A5: ${v.shareUrl}`);
502
502
  console.log("");
503
503
  }
504
- printResult({ videos: normalized, _raw: data });
504
+ printResult(data);
505
505
  } catch (err) {
506
506
  rethrowIfProcessExit(err);
507
507
  console.error("\u67E5\u8BE2\u89C6\u9891\u6570\u636E\u5931\u8D25:", err.message);
@@ -581,23 +581,6 @@ async function pollNormalVideoStatus(businessId, shareId, intervalSec, maxPolls)
581
581
  raw: lastData
582
582
  };
583
583
  }
584
- function normalizeVideoQuery(data) {
585
- const list = data.videoList ?? data.videos ?? [];
586
- const videos = list.map((video) => ({
587
- itemId: video.itemId ?? video.item_id,
588
- videoViews: video.videoViews ?? video.video_views ?? 0,
589
- likes: video.likes ?? 0,
590
- comments: video.comments ?? 0,
591
- shares: video.shares ?? 0,
592
- thumbnailUrl: video.thumbnailUrl ?? video.thumbnail_url ?? "",
593
- shareUrl: video.shareUrl ?? video.share_url ?? ""
594
- }));
595
- return {
596
- attempts: 1,
597
- videos,
598
- raw: data
599
- };
600
- }
601
584
  async function queryVideoWithRetry(businessId, itemId, intervalSec, maxAttempts) {
602
585
  const warnings = [];
603
586
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
@@ -605,10 +588,9 @@ async function queryVideoWithRetry(businessId, itemId, intervalSec, maxAttempts)
605
588
  businessId,
606
589
  itemIds: [itemId]
607
590
  });
608
- const normalized = normalizeVideoQuery(data);
609
- normalized.attempts = attempt;
610
- if (normalized.videos.length > 0) {
611
- return { query: normalized, warnings };
591
+ const list = data.videoList ?? data.videos ?? [];
592
+ if (list.length > 0) {
593
+ return { query: data, warnings };
612
594
  }
613
595
  if (attempt < maxAttempts) {
614
596
  await sleep2(intervalSec * 1e3);
@@ -642,6 +624,7 @@ async function queryProductsPage(creatorId, productType, pageSize, cursor) {
642
624
  return token !== null;
643
625
  });
644
626
  const allProducts = /* @__PURE__ */ new Map();
627
+ const rawGroups = [];
645
628
  let nextShopToken = cursor.shopToken;
646
629
  let nextShowcaseToken = cursor.showcaseToken;
647
630
  let successCount = 0;
@@ -669,6 +652,7 @@ async function queryProductsPage(creatorId, productType, pageSize, cursor) {
669
652
  successCount += 1;
670
653
  const { data } = result.value;
671
654
  const groups = Array.isArray(data) ? data : [data];
655
+ rawGroups.push(...groups);
672
656
  for (const group of groups) {
673
657
  const token = group.nextPageToken === void 0 ? null : group.nextPageToken;
674
658
  if (type === "shop") nextShopToken = token;
@@ -694,6 +678,7 @@ async function queryProductsPage(creatorId, productType, pageSize, cursor) {
694
678
  const nextCursor = encodeCursor({ shopToken: nextShopToken, showcaseToken: nextShowcaseToken });
695
679
  return {
696
680
  products: Array.from(allProducts.values()),
681
+ rawGroups,
697
682
  nextCursor,
698
683
  successCount,
699
684
  failedSources
@@ -701,6 +686,7 @@ async function queryProductsPage(creatorId, productType, pageSize, cursor) {
701
686
  }
702
687
  async function fetchProductPool(creatorId, productType, pageSize, maxPages) {
703
688
  const allProducts = /* @__PURE__ */ new Map();
689
+ const rawGroups = [];
704
690
  let cursor = { shopToken: "", showcaseToken: "" };
705
691
  let nextCursor = null;
706
692
  let pagesScanned = 0;
@@ -714,6 +700,7 @@ async function fetchProductPool(creatorId, productType, pageSize, maxPages) {
714
700
  failedSourcesSet.add(src);
715
701
  }
716
702
  pagesScanned = page;
703
+ rawGroups.push(...pageResult.rawGroups);
717
704
  for (const product of pageResult.products) {
718
705
  if (!allProducts.has(product.id)) {
719
706
  allProducts.set(product.id, product);
@@ -727,6 +714,7 @@ async function fetchProductPool(creatorId, productType, pageSize, maxPages) {
727
714
  }
728
715
  return {
729
716
  products: Array.from(allProducts.values()),
717
+ rawGroups,
730
718
  summary: {
731
719
  productType,
732
720
  pageSize,
@@ -738,17 +726,6 @@ async function fetchProductPool(creatorId, productType, pageSize, maxPages) {
738
726
  }
739
727
  };
740
728
  }
741
- function buildSkippedProductQuerySummary(productType, pageSize) {
742
- return {
743
- productType,
744
- pageSize,
745
- pagesScanned: 0,
746
- productCount: 0,
747
- nextCursor: null,
748
- reachedPageLimit: false,
749
- failedSources: []
750
- };
751
- }
752
729
  function isProductPublishable(product) {
753
730
  if (product.reviewStatus && product.reviewStatus.toUpperCase() !== "APPROVED") return false;
754
731
  if (product.inventoryStatus && product.inventoryStatus.toUpperCase() !== "IN_STOCK") return false;
@@ -757,18 +734,6 @@ function isProductPublishable(product) {
757
734
  function sortProductsForSelection(products) {
758
735
  return products.filter(isProductPublishable).sort((a, b) => b.salesCount - a.salesCount);
759
736
  }
760
- function buildSelectedProductSummary(product, selectionMode) {
761
- return {
762
- selectionMode,
763
- id: product.id,
764
- title: product.title,
765
- salesCount: product.salesCount,
766
- source: product.source,
767
- price: product.price,
768
- brandName: product.brandName,
769
- shopName: product.shopName
770
- };
771
- }
772
737
  async function promptForProductSelection(products) {
773
738
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
774
739
  throw new Error("\u4EA4\u4E92\u6A21\u5F0F\u9700\u8981\u5728 TTY \u7EC8\u7AEF\u4E2D\u8FD0\u884C");
@@ -858,7 +823,7 @@ function register7(cli2) {
858
823
  } else {
859
824
  console.log("\u5DF2\u5230\u6700\u540E\u4E00\u9875");
860
825
  }
861
- printResult({ products: productList, nextCursor: pageResult.nextCursor });
826
+ printResult(pageResult.rawGroups);
862
827
  } catch (err) {
863
828
  rethrowIfProcessExit(err);
864
829
  console.error("\u67E5\u8BE2\u5546\u54C1\u5931\u8D25:", err.message);
@@ -917,7 +882,6 @@ function register8(cli2) {
917
882
  intervalSec,
918
883
  maxPolls
919
884
  );
920
- const warnings = [];
921
885
  const videoId = status.postIds[0] ?? null;
922
886
  let query = null;
923
887
  if (status.finalStatus === "PUBLISH_COMPLETE" && videoId) {
@@ -929,18 +893,16 @@ function register8(cli2) {
929
893
  queryMaxAttempts
930
894
  );
931
895
  query = queryResult.query;
932
- warnings.push(...queryResult.warnings);
896
+ for (const warning of queryResult.warnings) {
897
+ console.warn(warning.message);
898
+ }
933
899
  }
934
- const result = {
935
- flowType: "tt",
900
+ printResult({
936
901
  upload,
937
902
  publish,
938
- status,
939
- videoId,
940
- query,
941
- warnings
942
- };
943
- printResult(result);
903
+ status: status.raw,
904
+ query
905
+ });
944
906
  if (status.finalStatus === "FAILED") {
945
907
  process.exit(1);
946
908
  }
@@ -1023,12 +985,9 @@ function register9(cli2) {
1023
985
  );
1024
986
  try {
1025
987
  console.log("\u5F00\u59CB\u6267\u884C TTS \u5B8C\u6574\u53D1\u5E03\u6D41\u7A0B...");
1026
- const warnings = [];
1027
- let selectionMode = "automatic";
1028
988
  let selectedProduct;
1029
- let productPoolSummary;
989
+ let queriedProducts = null;
1030
990
  if (options.productId && options.productTitle) {
1031
- selectionMode = "manual";
1032
991
  console.log("1/4 \u5DF2\u624B\u52A8\u6307\u5B9A\u5546\u54C1\uFF0C\u8DF3\u8FC7\u5546\u54C1\u67E5\u8BE2...");
1033
992
  selectedProduct = buildManualProduct(options.productId, options.productTitle);
1034
993
  } else {
@@ -1039,21 +998,16 @@ function register9(cli2) {
1039
998
  pageSize,
1040
999
  maxProductPages
1041
1000
  );
1042
- productPoolSummary = productPool.summary;
1001
+ queriedProducts = productPool.rawGroups;
1043
1002
  if (productPool.summary.reachedPageLimit && productPool.summary.nextCursor) {
1044
- warnings.push({
1045
- code: "PRODUCT_SCAN_LIMIT_REACHED",
1046
- message: `\u5546\u54C1\u626B\u63CF\u5DF2\u8FBE\u5230\u9875\u6570\u4E0A\u9650 ${maxProductPages}\uFF0C\u4ECD\u5B58\u5728\u672A\u62C9\u53D6\u5206\u9875`
1047
- });
1003
+ console.warn(`\u5546\u54C1\u626B\u63CF\u5DF2\u8FBE\u5230\u9875\u6570\u4E0A\u9650 ${maxProductPages}\uFF0C\u4ECD\u5B58\u5728\u672A\u62C9\u53D6\u5206\u9875`);
1048
1004
  }
1049
1005
  if (productPool.summary.failedSources.length > 0) {
1050
- warnings.push({
1051
- code: "PRODUCT_SOURCE_PARTIAL_FAILURE",
1052
- message: `\u4EE5\u4E0B\u5546\u54C1\u6E90\u8BF7\u6C42\u5931\u8D25: ${productPool.summary.failedSources.join(", ")}\uFF0C\u5546\u54C1\u6C60\u53EF\u80FD\u4E0D\u5B8C\u6574`
1053
- });
1006
+ console.warn(
1007
+ `\u4EE5\u4E0B\u5546\u54C1\u6E90\u8BF7\u6C42\u5931\u8D25: ${productPool.summary.failedSources.join(", ")}\uFF0C\u5546\u54C1\u6C60\u53EF\u80FD\u4E0D\u5B8C\u6574`
1008
+ );
1054
1009
  }
1055
1010
  if (options.productId) {
1056
- selectionMode = "manual";
1057
1011
  const matchedProduct = productPool.products.find(
1058
1012
  (product) => product.id === options.productId
1059
1013
  );
@@ -1070,7 +1024,6 @@ function register9(cli2) {
1070
1024
  console.error("TTS \u5B8C\u6574\u53D1\u5E03\u6D41\u7A0B\u5931\u8D25: \u5F53\u524D\u5546\u54C1\u6C60\u4E3A\u7A7A\uFF0C\u65E0\u6CD5\u9009\u62E9\u5546\u54C1");
1071
1025
  process.exit(1);
1072
1026
  }
1073
- selectionMode = "interactive";
1074
1027
  console.log("2/4 \u8BF7\u9009\u62E9\u8981\u6302\u8F66\u7684\u5546\u54C1...");
1075
1028
  selectedProduct = await promptForProductSelection(productPool.products);
1076
1029
  } else {
@@ -1100,20 +1053,14 @@ function register9(cli2) {
1100
1053
  options.caption
1101
1054
  );
1102
1055
  if (publishResult.productTitle !== selectedProduct.title) {
1103
- warnings.push({
1104
- code: "PRODUCT_TITLE_TRUNCATED",
1105
- message: "\u5546\u54C1\u6807\u9898\u8D85\u8FC7 29 \u5B57\u7B26\uFF0C\u53D1\u5E03\u65F6\u5DF2\u81EA\u52A8\u622A\u65AD"
1106
- });
1056
+ console.warn("\u5546\u54C1\u6807\u9898\u8D85\u8FC7 29 \u5B57\u7B26\uFF0C\u53D1\u5E03\u65F6\u5DF2\u81EA\u52A8\u622A\u65AD");
1107
1057
  }
1108
- const result = {
1109
- flowType: "tts",
1110
- productQuery: productPoolSummary ?? buildSkippedProductQuerySummary(productType, pageSize),
1111
- selectedProduct: buildSelectedProductSummary(selectedProduct, selectionMode),
1058
+ printResult({
1059
+ products: queriedProducts,
1060
+ selectedProduct,
1112
1061
  upload,
1113
- publish: publishResult.publish,
1114
- warnings
1115
- };
1116
- printResult(result);
1062
+ publish: publishResult.publish
1063
+ });
1117
1064
  } catch (err) {
1118
1065
  rethrowIfProcessExit(err);
1119
1066
  console.error("TTS \u5B8C\u6574\u53D1\u5E03\u6D41\u7A0B\u5931\u8D25:", err.message);
@@ -1164,7 +1111,7 @@ function register10(cli2) {
1164
1111
 
1165
1112
  // src/cli.ts
1166
1113
  var cli = cac("beervid");
1167
- var cliVersion = true ? "0.2.2" : pkg.version;
1114
+ var cliVersion = true ? "0.2.3" : pkg.version;
1168
1115
  register10(cli);
1169
1116
  register(cli);
1170
1117
  register2(cli);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beervid-app-cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "BEERVID App CLI — TikTok video publish, account auth, and data query",
5
5
  "type": "module",
6
6
  "engines": {