@anaella/cli 0.2.2 → 0.4.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 +44 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -104,7 +104,13 @@ var EXT_MIME = {
|
|
|
104
104
|
".gif": "image/gif",
|
|
105
105
|
".webp": "image/webp"
|
|
106
106
|
};
|
|
107
|
-
var cmdChannels = (client) => client.listChannels();
|
|
107
|
+
var cmdChannels = (client, o = {}) => client.listChannels(o.externalUser ? { externalUserId: o.externalUser } : {});
|
|
108
|
+
var cmdConnect = (client, platform, o) => client.createConnectSession({
|
|
109
|
+
platform,
|
|
110
|
+
externalUserId: o.externalUser,
|
|
111
|
+
returnUrl: o.returnUrl,
|
|
112
|
+
...o.resource?.length ? { resources: o.resource } : {}
|
|
113
|
+
});
|
|
108
114
|
function cmdPost(client, o) {
|
|
109
115
|
return client.createPost({
|
|
110
116
|
channels: o.channel,
|
|
@@ -143,6 +149,22 @@ function cmdUpload(client, o) {
|
|
|
143
149
|
}))
|
|
144
150
|
);
|
|
145
151
|
}
|
|
152
|
+
var cmdFind = (client, q, o) => client.find(q.join(" "), { category: o.category });
|
|
153
|
+
var cmdExplain = (client, id) => client.explain(id);
|
|
154
|
+
var cmdJob = (client, id) => client.job(id);
|
|
155
|
+
var cmdBalance = (client) => client.balance();
|
|
156
|
+
async function cmdDo(client, id, o) {
|
|
157
|
+
let input = {};
|
|
158
|
+
if (o.input) {
|
|
159
|
+
try {
|
|
160
|
+
input = JSON.parse(o.input);
|
|
161
|
+
} catch {
|
|
162
|
+
throw new Error(`--input must be JSON, e.g. --input '{"prompt":"a red fox"}'`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const job = await client.do(id, input);
|
|
166
|
+
return o.wait && (job.status === "queued" || job.status === "running") ? client.waitForJob(job.id) : job;
|
|
167
|
+
}
|
|
146
168
|
|
|
147
169
|
// src/config.ts
|
|
148
170
|
import { chmodSync, existsSync, mkdirSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "fs";
|
|
@@ -240,7 +262,9 @@ var collect = (val, acc) => {
|
|
|
240
262
|
return acc;
|
|
241
263
|
};
|
|
242
264
|
var program = new Command();
|
|
243
|
-
program.name("anaella").description(
|
|
265
|
+
program.name("anaella").description(
|
|
266
|
+
"CLI for anaella.com \u2014 find and run tools, schedule and publish posts via the /v1 API."
|
|
267
|
+
).version("0.1.1").option("--api-key <key>", "ana_ API key (overrides env + config)").option("--api-url <url>", "API base URL").option("--json", "output raw JSON");
|
|
244
268
|
async function withClient(command, fn, columns) {
|
|
245
269
|
const opts = command.optsWithGlobals();
|
|
246
270
|
const cfg = resolveConfig({ apiKey: opts.apiKey, apiUrl: opts.apiUrl }, process.env);
|
|
@@ -299,8 +323,17 @@ program.command("logout").description("Remove the saved API key").action(() => {
|
|
|
299
323
|
clearConfigFile(process.env);
|
|
300
324
|
process.stdout.write("Logged out.\n");
|
|
301
325
|
});
|
|
302
|
-
program.command("channels").description("List connected channels").action(
|
|
303
|
-
(
|
|
326
|
+
program.command("channels").description("List connected channels").option("--external-user <id>", "only this end user's connections").action(
|
|
327
|
+
(opts, command) => withClient(command, (c) => cmdChannels(c, opts), [
|
|
328
|
+
"id",
|
|
329
|
+
"platform",
|
|
330
|
+
"name",
|
|
331
|
+
"status",
|
|
332
|
+
"externalUserId"
|
|
333
|
+
])
|
|
334
|
+
);
|
|
335
|
+
program.command("connect <platform>").description("Create a connect link for an end user's account (e.g. google-search-console)").requiredOption("--external-user <id>", "your id for this person").requiredOption("--return-url <url>", "where to send them back (allowed origin)").option("--resource <id>", "connect this resource without the picker (repeatable)", collect, []).action(
|
|
336
|
+
(platform, opts, command) => withClient(command, (c) => cmdConnect(c, platform, opts))
|
|
304
337
|
);
|
|
305
338
|
program.command("post").description("Create/schedule/publish a post").requiredOption("-c, --channel <id>", "channel id (repeatable)", collect, []).option("-t, --text <text>", "post text").option("-w, --when <when>", '"now" | "draft" | ISO-8601', "draft").option("-m, --media <url>", "public media URL (repeatable)", collect, []).option("--type <type>", "post | reel | thread | story | article").option("--first-comment <text>", "first comment").option("--title <title>", "article title (--type article)").option("--markdown <md>", 'article body in Markdown, e.g. "$(cat post.md)" (--type article)').option("--excerpt <text>", "article excerpt (--type article)").option("--tag <tag>", "article tag (repeatable, --type article)", collect, []).option("--canonical-url <url>", "article canonical URL (--type article)").action((opts, command) => withClient(command, (c) => cmdPost(c, opts)));
|
|
306
339
|
program.command("posts").description("List recent posts").option("--limit <n>", "max results (1-100)").option("--cursor <n>", "offset").action(
|
|
@@ -312,4 +345,11 @@ program.command("analytics").description("Organization analytics, or one post wi
|
|
|
312
345
|
program.command("upload [files...]").description("Upload local media files, or register public URLs with --url").option("--url <url>", "public media URL to register (repeatable)", collect, []).action(
|
|
313
346
|
(files, opts, command) => withClient(command, (c) => cmdUpload(c, { files, url: opts.url }), ["id", "url", "type"])
|
|
314
347
|
);
|
|
348
|
+
program.command("find [query...]").description("Find capabilities by what you want to do").option("--category <c>", "filter by category").action(
|
|
349
|
+
(query, opts, command) => withClient(command, (c) => cmdFind(c, query, opts), ["id", "summary", "priceUsd", "mode"])
|
|
350
|
+
);
|
|
351
|
+
program.command("explain <id>").description("Show a capability's input/output schema and price").action((id, _opts, command) => withClient(command, (c) => cmdExplain(c, id)));
|
|
352
|
+
program.command("do <id>").description("Run a capability").option("-i, --input <json>", "input object as JSON (see explain)").option("--wait", "wait for async jobs to finish").action((id, opts, command) => withClient(command, (c) => cmdDo(c, id, opts)));
|
|
353
|
+
program.command("job <id>").description("Status, output and cost of a job").action((id, _opts, command) => withClient(command, (c) => cmdJob(c, id)));
|
|
354
|
+
program.command("balance").description("Wallet balance in dollars").action((_opts, command) => withClient(command, (c) => cmdBalance(c)));
|
|
315
355
|
program.parseAsync(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anaella/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Command-line tool for anaella.com — schedule and publish social posts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "bun test"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@anaella/client": "^0.
|
|
21
|
+
"@anaella/client": "^0.3.0",
|
|
22
22
|
"commander": "^12.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|