toolaby 1.3.0 → 1.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.
Files changed (2) hide show
  1. package/bin.mjs +35 -4
  2. package/package.json +1 -1
package/bin.mjs CHANGED
@@ -7,6 +7,9 @@
7
7
  // toolaby tools your tools, with the ids the commands want
8
8
  // toolaby webhooks events the six events, with an example of each
9
9
  // toolaby webhooks trigger <event> send an example delivery: to your registered endpoints, or with --to straight to a local server
10
+ // toolaby webhooks endpoints the workspace's endpoints
11
+ // toolaby webhooks add <url> register an endpoint; the secret is printed once
12
+ // toolaby webhooks remove <id> remove one
10
13
  // toolaby whoami · logout · help
11
14
  //
12
15
  // Test and live, as Stripe's command line has them: every command acts on
@@ -31,7 +34,7 @@ import { createHmac, randomBytes } from 'node:crypto';
31
34
  import { wireManifest, WORKER_LINES } from './lib/manifest.js';
32
35
  import { detectProject, CODE_FILES, filesToWrite, BUILD_COPY_NOTE } from './lib/project.js';
33
36
 
34
- const VERSION = '1.3.0';
37
+ const VERSION = '1.4.0';
35
38
  const CLIENT_ID = 'toolaby-cli';
36
39
  const argv = process.argv.slice(2);
37
40
  // `--version` and `--help` are commands of their own; every other command is the first bare word.
@@ -279,9 +282,9 @@ async function webhooks() {
279
282
  if (!type) fail('usage: toolaby webhooks trigger <event> [--to <url>] [--secret <whsec_…>] — `toolaby webhooks events` lists them');
280
283
  const to = opt('--to');
281
284
  if (!to) {
282
- const res = await api('/api/cli/webhooks/trigger', { method: 'POST', body: { type }, token: await tokenOrLogin() });
285
+ const res = await api('/api/cli/webhooks/trigger', { method: 'POST', body: { type, workspace: opt('--workspace') ?? undefined }, token: await tokenOrLogin() });
283
286
  if (!res.ok) fail(res.json.message ?? `The Wall answered HTTP ${res.status}.`);
284
- out(`\n Sent ${res.json.sent} to every endpoint of ${res.json.workspace} · ${side}. Its id is ${res.json.id}; the delivery log is under Configure → API.\n`);
287
+ out(`\n Sent ${res.json.sent} to every endpoint of ${res.json.workspace} · ${side}. Its id is ${res.json.id}; the delivery log is under Configure → Webhooks.\n`);
285
288
  return;
286
289
  }
287
290
  const events = await catalogue();
@@ -303,7 +306,34 @@ async function webhooks() {
303
306
  if (res.status >= 300) out(' A real delivery would be retried until your server answers 2xx.\n');
304
307
  return;
305
308
  }
306
- fail('usage: toolaby webhooks events | trigger <event> [--to <url>] [--secret <whsec_…>]');
309
+ if (sub === 'endpoints') {
310
+ const ws = opt('--workspace');
311
+ const res = await api(`/api/cli/webhooks/endpoints${ws ? `?workspace=${encodeURIComponent(ws)}` : ''}`, { token: await tokenOrLogin() });
312
+ if (!res.ok) fail(res.json.message ?? `The Wall answered HTTP ${res.status}.`);
313
+ out(`\n ${res.json.workspace} · ${side}\n`);
314
+ if (res.json.endpoints.length === 0) out(' None yet. `toolaby webhooks add <url>` registers one.');
315
+ for (const e of res.json.endpoints) out(` ${e.id} ${e.disabled ? 'paused ' : 'on '} ${e.url}${e.description ? ` — ${e.description}` : ''}${e.events.length ? ` (${e.events.join(', ')})` : ''}`);
316
+ out();
317
+ return;
318
+ }
319
+ if (sub === 'add') {
320
+ const url = positional[1];
321
+ if (!url) fail('usage: toolaby webhooks add <url> [--description <text>] [--events a.b,c.d] [--workspace <slug>]');
322
+ const events = (opt('--events') ?? '').split(',').map((e) => e.trim()).filter(Boolean);
323
+ const res = await api('/api/cli/webhooks/endpoints', { method: 'POST', body: { url, description: opt('--description') ?? '', events, workspace: opt('--workspace') ?? undefined }, token: await tokenOrLogin() });
324
+ if (!res.ok) fail(res.json.message ?? `The Wall answered HTTP ${res.status}.`);
325
+ out(`\n Added ${res.json.id} → ${res.json.url} · ${res.json.workspace} · ${side}\n\n Signing secret, shown once — keep it where your server keeps secrets:\n\n ${res.json.secret}\n`);
326
+ return;
327
+ }
328
+ if (sub === 'remove') {
329
+ const id = positional[1];
330
+ if (!id) fail('usage: toolaby webhooks remove <ep_…> [--workspace <slug>] — `toolaby webhooks endpoints` lists them');
331
+ const res = await api('/api/cli/webhooks/endpoints', { method: 'DELETE', body: { id, workspace: opt('--workspace') ?? undefined }, token: await tokenOrLogin() });
332
+ if (!res.ok) fail(res.json.message ?? `The Wall answered HTTP ${res.status}.`);
333
+ out(`\n Removed ${res.json.removed} · ${res.json.workspace} · ${side}. Deliveries to it stop at once.\n`);
334
+ return;
335
+ }
336
+ fail('usage: toolaby webhooks events | trigger <event> [--to <url>] | endpoints | add <url> | remove <id>');
307
337
  }
308
338
 
309
339
  function help() {
@@ -317,6 +347,7 @@ function help() {
317
347
  toolaby tools your tools, with their ids
318
348
  toolaby webhooks events the six events, with an example of each
319
349
  toolaby webhooks trigger <event> an example delivery to your endpoints; --to <url> sends it to a local server instead
350
+ toolaby webhooks endpoints your endpoints; add <url> registers one (secret shown once), remove <id> removes one
320
351
  toolaby login · whoami · logout the session, per side; a command that needs one signs you in itself
321
352
 
322
353
  Every command acts on Test (test.toolaby.app) unless told --live (toolaby.app).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolaby",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "The Toolaby command line: sign in once, then wire any Chrome extension to your tool on the Wall — sign-in, the Free plan, licences and subscriptions — or start a new one.",
5
5
  "type": "module",
6
6
  "bin": {