delivrie-cli 0.1.0 → 0.3.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/LICENSE +1 -1
- package/README.md +4 -1
- package/bin/delivrie.js +1 -1
- package/dist/api.js +58 -0
- package/dist/args.js +47 -0
- package/dist/cli.js +819 -0
- package/dist/config.js +38 -0
- package/dist/format.js +42 -0
- package/dist/version.js +1 -0
- package/package.json +12 -5
- package/src/api.js +0 -50
- package/src/args.js +0 -30
- package/src/cli.js +0 -485
- package/src/config.js +0 -28
- package/src/format.js +0 -36
- package/src/version.js +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -20,10 +20,13 @@ delivrie send -f "Acme <hi@acme.com>" -t ada@example.com -s "Hello" --text "It w
|
|
|
20
20
|
| `delivrie domains list\|add\|get\|verify\|delete` | Add a domain, see its DNS records, check DNS |
|
|
21
21
|
| `delivrie keys list\|create\|delete` | API keys (`--sending` for a sending-only key) |
|
|
22
22
|
| `delivrie webhooks list\|create\|test\|deliveries` | Endpoints, test events, delivery attempts |
|
|
23
|
-
| `delivrie templates
|
|
23
|
+
| `delivrie templates import <file.html>` | Upload an HTML template as written; `--publish` to make it live |
|
|
24
|
+
| `delivrie templates list\|get\|create\|update\|publish\|delete` | Templates by id or alias |
|
|
24
25
|
| `delivrie contacts list\|add\|get\|delete` | Contacts by id or email |
|
|
25
26
|
| `delivrie suppressions list\|add\|remove` | Addresses Delivrie won't send to |
|
|
26
27
|
| `delivrie logs list\|get` | API request logs |
|
|
28
|
+
| `delivrie init` | Install Delivrie's agent skills into `.claude/skills/` (`--dir` for another agent) |
|
|
29
|
+
| `delivrie skills list\|status\|update` | See which skills exist, which are out of date, and refresh them |
|
|
27
30
|
|
|
28
31
|
Run `delivrie <command> --help` for options. Add `--json` to any command for the raw API response, which makes the
|
|
29
32
|
CLI easy to script:
|
package/bin/delivrie.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { run } from "../
|
|
2
|
+
import { run } from "../dist/cli.js";
|
|
3
3
|
|
|
4
4
|
const major = Number(process.versions.node.split(".")[0]);
|
|
5
5
|
if (major < 18) { process.stderr.write("The Delivrie CLI needs Node.js 18 or later.\n"); process.exit(1); }
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// A small API client for the CLI: bearer key, JSON in and out, retries for rate limits and server errors.
|
|
2
|
+
// Sends (POST/PATCH) are only retried with an idempotency key, so a retry never sends an email twice.
|
|
3
|
+
import { VERSION } from "./version.js";
|
|
4
|
+
export class ApiError extends Error {
|
|
5
|
+
constructor(status, name, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.code = name;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
12
|
+
export function createClient({ key, baseUrl, timeout = 30000, maxRetries = 2, fetchImpl = globalThis.fetch }) {
|
|
13
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
14
|
+
async function request(method, path, body, { query, idempotencyKey } = {}) {
|
|
15
|
+
let url = base + path;
|
|
16
|
+
if (query) {
|
|
17
|
+
const q = Object.entries(query).filter(([, v]) => v !== undefined && v !== null && v !== "").map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join("&");
|
|
18
|
+
if (q)
|
|
19
|
+
url += (url.includes("?") ? "&" : "?") + q;
|
|
20
|
+
}
|
|
21
|
+
const headers = { authorization: `Bearer ${key}`, accept: "application/json", "user-agent": `delivrie-cli/${VERSION}` };
|
|
22
|
+
if (body !== undefined)
|
|
23
|
+
headers["content-type"] = "application/json";
|
|
24
|
+
if (idempotencyKey)
|
|
25
|
+
headers["idempotency-key"] = idempotencyKey;
|
|
26
|
+
const retryable = method === "GET" || method === "DELETE" || !!idempotencyKey;
|
|
27
|
+
for (let attempt = 0;; attempt++) {
|
|
28
|
+
let res;
|
|
29
|
+
try {
|
|
30
|
+
res = await fetchImpl(url, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(timeout) });
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
if (retryable && attempt < maxRetries) {
|
|
34
|
+
await sleep(500 * 2 ** attempt);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const timedOut = e?.name === "TimeoutError" || e?.name === "AbortError";
|
|
38
|
+
throw new ApiError(0, timedOut ? "timeout" : "network_error", timedOut ? `No response from ${base} within ${timeout / 1000}s` : `Couldn't reach ${base} (${e?.cause?.code || e?.message || "network error"})`);
|
|
39
|
+
}
|
|
40
|
+
const text = await res.text();
|
|
41
|
+
let json = null;
|
|
42
|
+
try {
|
|
43
|
+
json = text ? JSON.parse(text) : null;
|
|
44
|
+
}
|
|
45
|
+
catch { /* not JSON */ }
|
|
46
|
+
if (res.ok)
|
|
47
|
+
return json;
|
|
48
|
+
const name = (json && json.name) || (res.status === 401 ? "invalid_api_key" : res.status === 404 ? "not_found" : res.status === 429 ? "rate_limit_exceeded" : "application_error");
|
|
49
|
+
if ((res.status === 429 || res.status >= 500) && retryable && attempt < maxRetries) {
|
|
50
|
+
const after = Number(res.headers.get("retry-after"));
|
|
51
|
+
await sleep(Number.isFinite(after) && after > 0 ? Math.min(after, 30) * 1000 : 500 * 2 ** attempt);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw new ApiError(res.status, name, (json && json.message) || text.slice(0, 300) || `Request failed with status ${res.status}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { request, baseUrl: base };
|
|
58
|
+
}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function parseArgs(argv, { booleans = [], repeatable = [], aliases = {} } = {}) {
|
|
2
|
+
const flags = {}, positionals = [];
|
|
3
|
+
const set = (k, v) => {
|
|
4
|
+
k = aliases[k] || k;
|
|
5
|
+
if (repeatable.includes(k))
|
|
6
|
+
(flags[k] ||= []).push(v);
|
|
7
|
+
else
|
|
8
|
+
flags[k] = v;
|
|
9
|
+
};
|
|
10
|
+
for (let i = 0; i < argv.length; i++) {
|
|
11
|
+
const a = argv[i];
|
|
12
|
+
if (a === "--") {
|
|
13
|
+
positionals.push(...argv.slice(i + 1));
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
if (a.startsWith("--") || (a.startsWith("-") && a.length === 2 && !/^-\d/.test(a))) {
|
|
17
|
+
let k = a.replace(/^--?/, ""), v;
|
|
18
|
+
const eq = k.indexOf("=");
|
|
19
|
+
if (eq >= 0) {
|
|
20
|
+
v = k.slice(eq + 1);
|
|
21
|
+
k = k.slice(0, eq);
|
|
22
|
+
}
|
|
23
|
+
if (k.startsWith("no-") && booleans.includes(aliases[k.slice(3)] || k.slice(3))) {
|
|
24
|
+
set(k.slice(3), false);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const name = aliases[k] || k;
|
|
28
|
+
if (booleans.includes(name)) {
|
|
29
|
+
set(k, v === undefined ? true : !/^(false|0|no)$/i.test(v));
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (v === undefined) {
|
|
33
|
+
const next = argv[i + 1];
|
|
34
|
+
if (next === undefined || (next.startsWith("--") && next.length > 2))
|
|
35
|
+
throw new UsageError(`--${name} needs a value`);
|
|
36
|
+
v = next;
|
|
37
|
+
i++;
|
|
38
|
+
}
|
|
39
|
+
set(k, v);
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
positionals.push(a);
|
|
43
|
+
}
|
|
44
|
+
return { flags, positionals };
|
|
45
|
+
}
|
|
46
|
+
export class UsageError extends Error {
|
|
47
|
+
}
|