@optima-chat/tiktok-cli 0.6.0 → 0.7.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.
- package/dist/index.js +52 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -85,6 +85,33 @@ async function createAuthLink() {
|
|
|
85
85
|
return { ok: false, error: { code: "BACKEND_UNREACHABLE", message: e.message, retryable: true } };
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
async function fetchEvents(shop, query) {
|
|
89
|
+
try {
|
|
90
|
+
const qs = new URLSearchParams(query).toString();
|
|
91
|
+
const r = await fetch(`${BACKEND}/events/${shop}${qs ? "?" + qs : ""}`, { headers: authHeaders() });
|
|
92
|
+
if (r.status === 401) return { ok: false, error: { code: "AUTH_EXPIRED", message: "\u672A\u767B\u5F55\u6216 token \u5931\u6548", retryable: false } };
|
|
93
|
+
if (r.status === 404) return { ok: false, error: { code: "SHOP_NOT_AUTHORIZED", message: "\u672A\u627E\u5230\u4F60\u540D\u4E0B\u7684\u5DF2\u6388\u6743\u5E97\u94FA", retryable: false }, meta: { shop } };
|
|
94
|
+
const body = await r.json();
|
|
95
|
+
return { ok: true, data: body, meta: { shop } };
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return { ok: false, error: { code: "BACKEND_UNREACHABLE", message: e.message, retryable: true } };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function ackEvents(shop, body) {
|
|
101
|
+
try {
|
|
102
|
+
const r = await fetch(`${BACKEND}/events/${shop}/ack`, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: { "Content-Type": "application/json", ...authHeaders() },
|
|
105
|
+
body: JSON.stringify(body)
|
|
106
|
+
});
|
|
107
|
+
if (r.status === 401) return { ok: false, error: { code: "AUTH_EXPIRED", message: "\u672A\u767B\u5F55\u6216 token \u5931\u6548", retryable: false } };
|
|
108
|
+
if (r.status === 404) return { ok: false, error: { code: "SHOP_NOT_AUTHORIZED", message: "\u672A\u627E\u5230\u4F60\u540D\u4E0B\u7684\u5DF2\u6388\u6743\u5E97\u94FA", retryable: false }, meta: { shop } };
|
|
109
|
+
const j = await r.json();
|
|
110
|
+
return { ok: true, data: j, meta: { shop } };
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return { ok: false, error: { code: "BACKEND_UNREACHABLE", message: e.message, retryable: true } };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
88
115
|
async function uploadImage(shop, filePath, useCase) {
|
|
89
116
|
try {
|
|
90
117
|
const buf = readFileSync(filePath);
|
|
@@ -300,6 +327,31 @@ var COMMANDS = [
|
|
|
300
327
|
{ body: readBodyFile(args2["body-file"]) }
|
|
301
328
|
)
|
|
302
329
|
},
|
|
330
|
+
// ── webhook 事件流(backend 自有事件库,不走 /proxy)──
|
|
331
|
+
{
|
|
332
|
+
name: "events",
|
|
333
|
+
summary: "\u67E5\u5E97\u94FA webhook \u4E8B\u4EF6\uFF08--type \u9017\u53F7\u5206\u9694 --since 1d/unix --unprocessed --limit\uFF09",
|
|
334
|
+
run: ({ shop, args: args2 }) => {
|
|
335
|
+
const q = {};
|
|
336
|
+
if (args2.type) q.type = args2.type;
|
|
337
|
+
if (args2.since) q.since = args2.since;
|
|
338
|
+
if (args2.unprocessed) q.unprocessed = "true";
|
|
339
|
+
if (args2.limit) q.limit = String(args2.limit);
|
|
340
|
+
return fetchEvents(shop, q);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: "events ack",
|
|
345
|
+
summary: "\u6807\u4E8B\u4EF6\u5DF2\u5904\u7406\uFF08--ids id1,id2 \u6216 --before <ts>\uFF09\u3002\u9ED8\u8BA4 dry-run\uFF0C--apply \u624D\u6807",
|
|
346
|
+
write: true,
|
|
347
|
+
preview: ({ args: args2 }) => [{
|
|
348
|
+
step: "\u6807\u4E8B\u4EF6\u5DF2\u5904\u7406",
|
|
349
|
+
method: "POST",
|
|
350
|
+
path: "/events/{shop}/ack",
|
|
351
|
+
body: args2.ids ? { event_ids: String(args2.ids).split(",") } : { before: args2.before }
|
|
352
|
+
}],
|
|
353
|
+
run: ({ shop, args: args2 }) => ackEvents(shop, args2.ids ? { event_ids: String(args2.ids).split(",") } : { before: args2.before })
|
|
354
|
+
},
|
|
303
355
|
{
|
|
304
356
|
name: "analytics shop",
|
|
305
357
|
summary: "\u5E97\u94FA\u7ECF\u8425\u6570\u636E\uFF08--from --to\uFF0C\u9ED8\u8BA4\u8FD130\u5929\uFF09",
|