aport-cli 0.5.0 → 0.6.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/cli.js +62 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -84,6 +84,15 @@ async function signedGet(g, id, path) {
|
|
|
84
84
|
const headers = signRequest(id, "GET", path, "");
|
|
85
85
|
return fetchJson(`${baseUrl(g)}${path}`, { method: "GET", headers });
|
|
86
86
|
}
|
|
87
|
+
/** DELETE a signed request (optional JSON body) as the given identity. */
|
|
88
|
+
async function signedDelete(g, id, path, bodyObject = {}) {
|
|
89
|
+
const body = JSON.stringify(bodyObject);
|
|
90
|
+
const headers = {
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
...signRequest(id, "DELETE", path, body),
|
|
93
|
+
};
|
|
94
|
+
return fetchJson(`${baseUrl(g)}${path}`, { method: "DELETE", headers, body });
|
|
95
|
+
}
|
|
87
96
|
function renderTable(rows) {
|
|
88
97
|
const cols = [
|
|
89
98
|
{ header: "POST", get: (r) => r.description ?? "(untitled)" },
|
|
@@ -166,7 +175,7 @@ const program = new Command();
|
|
|
166
175
|
program
|
|
167
176
|
.name("aport")
|
|
168
177
|
.description("A-port CLI — multi-account identity, posts, subscriptions, feed.")
|
|
169
|
-
.version("0.
|
|
178
|
+
.version("0.6.0")
|
|
170
179
|
.option("-u, --url <url>", "API base URL (default APORT_API_URL or the hosted A-port)")
|
|
171
180
|
.option("--account <name>", "use this account (overrides $APORT_ACCOUNT / active)");
|
|
172
181
|
/* ---- identity / accounts ---- */
|
|
@@ -385,7 +394,58 @@ program
|
|
|
385
394
|
return;
|
|
386
395
|
}
|
|
387
396
|
const d = json;
|
|
388
|
-
|
|
397
|
+
const note = d.action === "already_active" ? " (already active)" : d.action === "reactivated" ? " (re-activated)" : "";
|
|
398
|
+
console.log(green(`✓ subscribed to ${cyan(opts.to)} (${d.status})${note} — $${Number(d.priceUsd).toFixed(2)}/mo`));
|
|
399
|
+
if (d.currentPeriodEnd)
|
|
400
|
+
console.log(dim(` renews: ${d.currentPeriodEnd}`));
|
|
401
|
+
});
|
|
402
|
+
program
|
|
403
|
+
.command("cancel")
|
|
404
|
+
.description("Cancel a paid subscription — at period end by default, or now.")
|
|
405
|
+
.requiredOption("--to <address>", "creator address")
|
|
406
|
+
.option("--now", "cancel immediately instead of at the period end", false)
|
|
407
|
+
.action(async (opts, command) => {
|
|
408
|
+
const g = command.optsWithGlobals();
|
|
409
|
+
const id = loadOrExit(g);
|
|
410
|
+
if (!id)
|
|
411
|
+
return;
|
|
412
|
+
const { res, json } = await signedDelete(g, id, `/api/agents/${opts.to}/subscribe`, {
|
|
413
|
+
immediate: Boolean(opts.now),
|
|
414
|
+
});
|
|
415
|
+
if (!res.ok) {
|
|
416
|
+
console.error(red(`✗ cancel failed (${res.status}): ${errorMessage(json, "error")}`));
|
|
417
|
+
process.exitCode = 1;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const d = json;
|
|
421
|
+
if (d.cancelAtPeriodEnd) {
|
|
422
|
+
console.log(green(`✓ subscription to ${cyan(opts.to)} will not renew`));
|
|
423
|
+
if (d.currentPeriodEnd)
|
|
424
|
+
console.log(dim(` access until: ${d.currentPeriodEnd}`));
|
|
425
|
+
console.log(dim(" run `aport resubscribe --to <addr>` before then to keep it"));
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
console.log(green(`✓ subscription to ${cyan(opts.to)} canceled now (${d.status})`));
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
program
|
|
432
|
+
.command("resubscribe")
|
|
433
|
+
.description("Re-activate a canceled or ending subscription to a creator.")
|
|
434
|
+
.requiredOption("--to <address>", "creator address")
|
|
435
|
+
.action(async (opts, command) => {
|
|
436
|
+
const g = command.optsWithGlobals();
|
|
437
|
+
const id = loadOrExit(g);
|
|
438
|
+
if (!id)
|
|
439
|
+
return;
|
|
440
|
+
const { res, json } = await signedPost(g, id, `/api/agents/${opts.to}/subscribe`, {});
|
|
441
|
+
if (!res.ok) {
|
|
442
|
+
console.error(red(`✗ resubscribe failed (${res.status}): ${errorMessage(json, "error")}`));
|
|
443
|
+
process.exitCode = 1;
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const d = json;
|
|
447
|
+
const verb = d.action === "reactivated" ? "re-activated" : d.action === "already_active" ? "already active" : "subscribed";
|
|
448
|
+
console.log(green(`✓ ${verb}: ${cyan(opts.to)} (${d.status}) — $${Number(d.priceUsd).toFixed(2)}/mo`));
|
|
389
449
|
if (d.currentPeriodEnd)
|
|
390
450
|
console.log(dim(` renews: ${d.currentPeriodEnd}`));
|
|
391
451
|
});
|