@optima-chat/tiktok-cli 0.8.0 → 0.9.0

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/index.js +34 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -75,6 +75,21 @@ async function listShops() {
75
75
  return { ok: false, error: { code: "BACKEND_UNREACHABLE", message: e.message, retryable: true } };
76
76
  }
77
77
  }
78
+ async function setShopApp(shopId, serviceId, note) {
79
+ const token = process.env.TIKTOK_ADMIN_TOKEN;
80
+ try {
81
+ const r = await fetch(`${BACKEND}/admin/apps/shop-map`, {
82
+ method: "PUT",
83
+ headers: { "Content-Type": "application/json", ...token ? { "x-admin-token": token } : {} },
84
+ body: JSON.stringify({ shopId, serviceId, note })
85
+ });
86
+ const body = await r.json().catch(() => ({}));
87
+ if (!r.ok || body?.error) return { ok: false, error: { code: r.status === 401 ? "AUTH_EXPIRED" : "VALIDATION", message: body?.error ?? `HTTP ${r.status}`, retryable: false } };
88
+ return { ok: true, data: body };
89
+ } catch (e) {
90
+ return { ok: false, error: { code: "BACKEND_UNREACHABLE", message: e.message, retryable: true } };
91
+ }
92
+ }
78
93
  async function availableApps() {
79
94
  try {
80
95
  const r = await fetch(`${BACKEND}/auth/apps`, { headers: authHeaders() });
@@ -88,12 +103,12 @@ async function availableApps() {
88
103
  return { ok: false, error: { code: "BACKEND_UNREACHABLE", message: e.message, retryable: true } };
89
104
  }
90
105
  }
91
- async function authLink(app) {
106
+ async function authLink(opts) {
92
107
  try {
93
108
  const r = await fetch(`${BACKEND}/auth/link`, {
94
109
  method: "POST",
95
110
  headers: { "Content-Type": "application/json", ...authHeaders() },
96
- body: JSON.stringify({ app })
111
+ body: JSON.stringify({ shop: opts.shop, app: opts.app })
97
112
  });
98
113
  if (r.status === 401) return { ok: false, error: { code: "AUTH_EXPIRED", message: "\u672A\u767B\u5F55\u6216 token \u5931\u6548", retryable: false } };
99
114
  const body = await r.json().catch(() => ({}));
@@ -894,10 +909,19 @@ var COMMANDS = [
894
909
  label: args2.label,
895
910
  ...args2.markets ? { markets: args2.markets.split(",") } : {},
896
911
  redirectUri: args2.redirect,
897
- ...args2["owner-entity"] ? { ownerEntity: args2["owner-entity"] } : {}
912
+ ...args2["owner-entity"] ? { ownerEntity: args2["owner-entity"] } : {},
913
+ ..."default" in args2 ? { isDefault: true } : {}
898
914
  }
899
915
  })
900
916
  },
917
+ {
918
+ name: "apps set-shop",
919
+ summary: "\u9884\u7F6E shop\u2192app \u6620\u5C04\uFF08--shop shopId --app serviceId [--note]\uFF09\u2014\u2014auth link \u65F6\u6309\u5E97\u89E3\u6790\u7528\u54EA\u4E2A app",
920
+ run: ({ args: args2 }) => {
921
+ if (!args2.shop || !args2.app) return Promise.resolve({ ok: false, error: { code: "VALIDATION", message: "--shop \u548C --app\uFF08serviceId\uFF09\u5FC5\u586B", retryable: false } });
922
+ return setShopApp(args2.shop, args2.app, args2.note);
923
+ }
924
+ },
901
925
  {
902
926
  name: "apps list",
903
927
  summary: "\u5217\u51FA\u5DF2\u767B\u8BB0\u7684 TikTok App\uFF08admin\uFF0C\u542B appKey/status\uFF09",
@@ -913,15 +937,16 @@ var COMMANDS = [
913
937
  summary: "\u505C\u7528\u4E00\u4E2A TikTok App\uFF08--id\uFF09",
914
938
  run: ({ args: args2 }) => adminApps("PATCH", { id: args2.id, body: { status: "disabled" } })
915
939
  },
916
- // ── auth link(多 app:--app 必填 serviceId,决定 backend 用哪个 app_key/secret 生成授权链接)──
940
+ // ── auth link:skill 只传 --shop,backend 按 shop 解析用哪个 app(custom 映射→默认 public)。
941
+ // --app 仅运维显式覆盖(可选)。二者至少给一个。──
917
942
  {
918
943
  name: "auth link",
919
- summary: "\u751F\u6210\u5E97\u94FA\u7ED1\u5B9A\u6388\u6743\u94FE\u63A5\uFF08--app serviceId \u5FC5\u586B\uFF0C\u53D1\u7ED9\u5546\u5BB6\u70B9\u51FB\uFF09",
944
+ summary: "\u751F\u6210\u5E97\u94FA\u7ED1\u5B9A\u6388\u6743\u94FE\u63A5\uFF08--shop shopId\uFF0Cbackend \u6309\u5E97\u5B9A app\uFF1B--app serviceId \u53EF\u9009\u8986\u76D6\uFF09",
920
945
  run: async ({ args: args2 }) => {
921
- if (!args2.app) {
922
- return { ok: false, error: { code: "VALIDATION", message: "--app \u5FC5\u586B\uFF08serviceId\uFF09", retryable: false } };
946
+ if (!args2.shop && !args2.app) {
947
+ return { ok: false, error: { code: "VALIDATION", message: "--shop\uFF08shopId\uFF09\u5FC5\u586B\uFF08\u6216 --app \u8986\u76D6\uFF09", retryable: false } };
923
948
  }
924
- return authLink(args2.app);
949
+ return authLink({ shop: args2.shop, app: args2.app });
925
950
  }
926
951
  }
927
952
  ];
@@ -988,7 +1013,7 @@ function findCommand(tokens) {
988
1013
  }
989
1014
 
990
1015
  // src/index.ts
991
- var NO_SHOP_COMMANDS = /* @__PURE__ */ new Set(["auth link", "apps add", "apps list", "apps disable", "apps available"]);
1016
+ var NO_SHOP_COMMANDS = /* @__PURE__ */ new Set(["auth link", "apps add", "apps list", "apps disable", "apps available", "apps set-shop"]);
992
1017
  function parseFlags(tokens) {
993
1018
  const args2 = {};
994
1019
  const positional2 = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/tiktok-cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "TikTok Shop CLI for Optima agents — 经 tiktok-backend 操作店铺",
5
5
  "type": "module",
6
6
  "bin": {