groundmail-cli 0.53.4 → 0.55.4

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 (3) hide show
  1. package/README.md +3 -0
  2. package/dist/cli.js +634 -51
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -91,6 +91,9 @@ groundmail webhooks list
91
91
  groundmail webhooks deliveries list --webhook <webhook-id> --status failed
92
92
  groundmail webhooks deliveries resend --webhook <webhook-id> --id <delivery-id>
93
93
  groundmail emails list
94
+ groundmail contacts list
95
+ groundmail lists list
96
+ groundmail broadcasts list
94
97
  groundmail batches get batch_… # status counts for an emails batch
95
98
  groundmail batches cancel batch_… # cancel the batch's emails that are still scheduled
96
99
  groundmail brand set --logo-url https://cdn.acme.com/logo.png --color '#2f6feb' --company "Acme Inc" # logo, color and footer every template follows
package/dist/cli.js CHANGED
@@ -2109,7 +2109,7 @@ async function runListKeysCommandWithClient(args, env = process.env) {
2109
2109
  }
2110
2110
 
2111
2111
  // package.json
2112
- var version = "0.53.4";
2112
+ var version = "0.55.4";
2113
2113
 
2114
2114
  // src/help.ts
2115
2115
  var USAGE_LINES = [
@@ -2230,6 +2230,36 @@ var USAGE_LINES = [
2230
2230
  " groundmail tenants domains remove <tenant> example.com gives the domain back to the account",
2231
2231
  " groundmail brand get your logo, colors and footer, which templates follow",
2232
2232
  ' groundmail brand set [--logo-url <https url>|none] [--logo-align left|center] [--logo-width 120] [--logo-name on|off] [--color #2f6feb] [--company "Acme Inc"|none] [--address "\u2026"|none] [--website acme.com|none] [--settings-file brand.json] --color: buttons, links and the line across the top',
2233
+ " groundmail contacts list [--list <list>] [--email \u2026] [--external-id \u2026] [--limit 25] [--cursor \u2026] the people broadcasts go to, with their status",
2234
+ " groundmail contacts add <email> --consent signup_form [--first-name Ada] [--last-name \u2026] [--external-id \u2026] [--attr plan=pro] adds, or updates the contact with this address",
2235
+ " groundmail contacts get <id>",
2236
+ " groundmail contacts update <id> [--first-name \u2026|none] [--last-name \u2026|none] [--external-id \u2026|none] [--attr key=value] attributes are merged",
2237
+ " groundmail contacts delete <id> --yes takes it off every list; unsubscribes and bounces stay on record",
2238
+ " groundmail contacts import <file.csv> --consent signup_form [--list <list>] [--wait [--timeout 600]] UTF-8 CSV up to 20 MB with an email column; other columns become attributes",
2239
+ " groundmail contacts imports [--limit 25] [--cursor \u2026] recent CSV imports",
2240
+ " groundmail contacts import-status <import id>",
2241
+ " groundmail contacts import-cancel <import id> --yes contacts already added stay",
2242
+ " groundmail lists list [--limit 25] [--cursor \u2026]",
2243
+ ' groundmail lists create --name "Beta users" [--description \u2026] its key, for code, is made from the name',
2244
+ " groundmail lists get <list> <list>: its id or key",
2245
+ " groundmail lists update <list> [--name \u2026] [--description \u2026|none]",
2246
+ " groundmail lists delete <list> --yes its contacts stay",
2247
+ " groundmail lists contacts <list> [--limit 25] [--cursor \u2026]",
2248
+ " groundmail lists add <list> (--emails a@example.com,b@example.com | --ids <contact id>,\u2026) existing contacts; unknown ones come back in not_found",
2249
+ " groundmail lists remove <list> <contact id> the contact stays",
2250
+ " groundmail broadcasts list [--limit 25] [--cursor \u2026]",
2251
+ ' groundmail broadcasts create --name "December" --lists newsletter --from "Acme <news@mail.acme.dev>" (--template <template> | --subject \u2026 (--html \u2026 | --html-file email.html) [--text \u2026|--text-file \u2026]) [--reply-to \u2026] [--preheader \u2026] a draft; nothing is sent',
2252
+ " groundmail broadcasts get <id>",
2253
+ " groundmail broadcasts update <id> [the create flags; none clears one] drafts only",
2254
+ " groundmail broadcasts delete <id> --yes drafts only",
2255
+ " groundmail broadcasts audience <id> who it would reach now, and whether it would wait for review",
2256
+ " groundmail broadcasts preview <id> [--as ada@example.com] rendered as one contact; nothing is sent",
2257
+ " groundmail broadcasts test <id> --to you@example.com[,\u2026] up to 5 addresses, [Test] before the subject",
2258
+ " groundmail broadcasts send <id> [--at 2026-12-02T09:00:00Z] --yes to everyone on its lists, now or at --at (up to 30 days ahead)",
2259
+ " groundmail broadcasts pause <id>",
2260
+ " groundmail broadcasts resume <id>",
2261
+ " groundmail broadcasts cancel <id> --yes emails already sent stay sent",
2262
+ " groundmail broadcasts recipients <id> [--status sent|skipped|failed|pending|sending] [--limit 25] [--cursor \u2026]",
2233
2263
  " groundmail senders list the names and addresses your email goes out as",
2234
2264
  ' groundmail senders create --name "Acme Billing" --address billing@mail.acme.com [--reply-to billing@acme.com] [--handle billing] [--default] address on a verified domain',
2235
2265
  " groundmail senders get <id|handle>",
@@ -2263,7 +2293,8 @@ var FOOTER_LINES = [
2263
2293
  " AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY (+ AWS_SESSION_TOKEN, AWS_REGION) (migrate ses; used once, never stored)",
2264
2294
  "",
2265
2295
  "Scopes: full, emails:send, emails:read, domains:read, domains:write, webhooks:write, templates:write,",
2266
- " suppressions:write, account:read, mailboxes:read, mailboxes:write, mailboxes:send",
2296
+ " suppressions:write, account:read, mailboxes:read, mailboxes:write, mailboxes:send,",
2297
+ " contacts:read, contacts:write, broadcasts:write",
2267
2298
  "",
2268
2299
  "<tenant>: the tenant's external id (your id for that customer) or its Groundmail id.",
2269
2300
  "<mailbox>: the mailbox's mbx_ id, its address or your external id.",
@@ -2286,6 +2317,7 @@ var ALIASES = {
2286
2317
  tenants: { add: "create", remove: "delete" },
2287
2318
  mailboxes: { add: "create", remove: "delete" },
2288
2319
  senders: { add: "create", remove: "delete" },
2320
+ contacts: { create: "add", remove: "delete" },
2289
2321
  brand: { update: "set" }
2290
2322
  };
2291
2323
  function words(line) {
@@ -2460,15 +2492,15 @@ function parseArgs(argv, spec) {
2460
2492
  const booleanFlags = new Set(spec.booleans ?? []);
2461
2493
  const values = {};
2462
2494
  const booleans = {};
2463
- const positionals4 = [];
2495
+ const positionals5 = [];
2464
2496
  for (let i = 0; i < argv.length; i++) {
2465
2497
  const arg = argv[i];
2466
2498
  if (arg === "--") {
2467
- positionals4.push(...argv.slice(i + 1));
2499
+ positionals5.push(...argv.slice(i + 1));
2468
2500
  break;
2469
2501
  }
2470
2502
  if (!arg.startsWith("--") || arg === "-") {
2471
- positionals4.push(arg);
2503
+ positionals5.push(arg);
2472
2504
  continue;
2473
2505
  }
2474
2506
  const eq = arg.indexOf("=");
@@ -2494,7 +2526,7 @@ function parseArgs(argv, spec) {
2494
2526
  const known = [...valueFlags, ...booleanFlags].sort().join(", ");
2495
2527
  return { ok: false, error: `Unknown flag ${name}.${known ? ` This command takes: ${known}.` : ""}` };
2496
2528
  }
2497
- return { ok: true, args: { values, booleans, positionals: positionals4 } };
2529
+ return { ok: true, args: { values, booleans, positionals: positionals5 } };
2498
2530
  }
2499
2531
  function wantsJson(args, stdout = process.stdout) {
2500
2532
  if (args.booleans["--json"] !== void 0) return args.booleans["--json"];
@@ -2802,10 +2834,10 @@ async function resolveAuth(flags, env = process.env, config = loadConfig(env)) {
2802
2834
  return fromSaved(current.workspace);
2803
2835
  }
2804
2836
  async function applySavedSession(argv, env = process.env, config) {
2805
- const hasFlag3 = (flag) => argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
2837
+ const hasFlag4 = (flag) => argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
2806
2838
  let workspace = null;
2807
2839
  let notice;
2808
- if (!hasFlag3("--api-key") && !envApiKey(env)) {
2840
+ if (!hasFlag4("--api-key") && !envApiKey(env)) {
2809
2841
  const current = currentSavedWorkspace(config ?? loadConfig(env), env);
2810
2842
  if (current.ok) {
2811
2843
  workspace = current.workspace;
@@ -2816,7 +2848,7 @@ async function applySavedSession(argv, env = process.env, config) {
2816
2848
  notice = current.error;
2817
2849
  }
2818
2850
  }
2819
- if (hasFlag3("--base-url")) return { argv, notice };
2851
+ if (hasFlag4("--base-url")) return { argv, notice };
2820
2852
  const url = explicitApiUrl(env) || trimUrl(workspace?.apiUrl) || trimUrl(env.GROUNDMAIL_DEFAULT_API_URL);
2821
2853
  return { argv: url ? [...argv, "--base-url", url] : argv, notice };
2822
2854
  }
@@ -2849,7 +2881,10 @@ var CLI_SCOPES = [
2849
2881
  "account:read",
2850
2882
  "mailboxes:read",
2851
2883
  "mailboxes:write",
2852
- "mailboxes:send"
2884
+ "mailboxes:send",
2885
+ "contacts:read",
2886
+ "contacts:write",
2887
+ "broadcasts:write"
2853
2888
  ];
2854
2889
  function parseScopeFlag(value) {
2855
2890
  const tokens2 = String(value ?? "").split(/[\s,]+/).map((token) => token.trim()).filter(Boolean);
@@ -3713,8 +3748,8 @@ function extensionOf(filePath) {
3713
3748
  return match ? match[0].toLowerCase() : "";
3714
3749
  }
3715
3750
  async function defaultReadFile(filePath) {
3716
- const { readFile: readFile4 } = await import("fs/promises");
3717
- return readFile4(filePath, "utf8");
3751
+ const { readFile: readFile6 } = await import("fs/promises");
3752
+ return readFile6(filePath, "utf8");
3718
3753
  }
3719
3754
  async function defaultImportModule(filePath) {
3720
3755
  const { pathToFileURL } = await import("url");
@@ -3765,14 +3800,14 @@ async function toElement(mod, props) {
3765
3800
  return exported;
3766
3801
  }
3767
3802
  async function loadTemplateSource(filePath, options = {}, deps = {}) {
3768
- const readFile4 = deps.readFile ?? defaultReadFile;
3803
+ const readFile6 = deps.readFile ?? defaultReadFile;
3769
3804
  const importModule = deps.importModule ?? defaultImportModule;
3770
3805
  const extension = extensionOf(filePath);
3771
3806
  if (HTML_EXTENSIONS.includes(extension)) {
3772
- return { html: await readFile4(filePath) };
3807
+ return { html: await readFile6(filePath) };
3773
3808
  }
3774
3809
  if (TEXT_EXTENSIONS.includes(extension)) {
3775
- return { text: await readFile4(filePath) };
3810
+ return { text: await readFile6(filePath) };
3776
3811
  }
3777
3812
  if (!MODULE_EXTENSIONS.includes(extension)) {
3778
3813
  throw new Error(
@@ -3859,8 +3894,8 @@ async function runPushCommand(args, env = process.env, deps = {}) {
3859
3894
  if (!source.html && !source.text) {
3860
3895
  return { exitCode: 1, error: `${file} produced no content to push.` };
3861
3896
  }
3862
- const createClient2 = deps.createClient ?? createTemplatesClient;
3863
- const client3 = await createClient2(apiKey, options.baseUrl);
3897
+ const createClient3 = deps.createClient ?? createTemplatesClient;
3898
+ const client3 = await createClient3(apiKey, options.baseUrl);
3864
3899
  let existed = true;
3865
3900
  try {
3866
3901
  await client3.templates.get(alias);
@@ -5317,6 +5352,68 @@ async function runTestInboxCommand(subcommand, args, env = process.env) {
5317
5352
  }
5318
5353
  }
5319
5354
 
5355
+ // src/commands/mailboxes/delete-many.ts
5356
+ var MAX_PER_REQUEST = 100;
5357
+ var SHOWN_IN_CONFIRMATION = 20;
5358
+ async function mailboxesWithPrefix(client3, prefix, tenant) {
5359
+ const wanted = prefix.toLowerCase();
5360
+ const found = [];
5361
+ let cursor;
5362
+ do {
5363
+ const page = await client3.mailboxes.list({ limit: MAX_PER_REQUEST, ...cursor ? { cursor } : {}, ...tenant ? { tenant } : {} });
5364
+ for (const mailbox of page.data) {
5365
+ if (mailbox.address.toLowerCase().startsWith(wanted)) found.push({ ref: mailbox.id, label: `${mailbox.id} ${mailbox.address}` });
5366
+ }
5367
+ cursor = page.has_more && page.next_cursor ? page.next_cursor : void 0;
5368
+ } while (cursor);
5369
+ return found;
5370
+ }
5371
+ function confirmation(targets) {
5372
+ const shown = targets.slice(0, SHOWN_IN_CONFIRMATION).map((target) => ` ${target.label}`);
5373
+ const more = targets.length - shown.length;
5374
+ return [
5375
+ `This deletes ${targets.length} mailbox${targets.length === 1 ? "" : "es"} and all their mail:`,
5376
+ ...shown,
5377
+ ...more > 0 ? [` and ${more} more`] : [],
5378
+ "Add --yes to confirm."
5379
+ ].join("\n");
5380
+ }
5381
+ async function runBulkDelete(client3, options) {
5382
+ if (options.prefix !== void 0 && options.refs.length) {
5383
+ return { exitCode: 1, error: "Use either --prefix or a list of mailboxes, not both." };
5384
+ }
5385
+ const prefix = options.prefix?.trim();
5386
+ if (options.prefix !== void 0 && !prefix) return { exitCode: 1, error: "--prefix needs at least one character." };
5387
+ const targets = prefix ? await mailboxesWithPrefix(client3, prefix, options.tenant) : [...new Set(options.refs)].map((ref) => ({ ref, label: ref }));
5388
+ if (!targets.length) {
5389
+ console.log(options.json ? JSON.stringify({ deleted: [], not_found: [] }) : `No mailboxes start with ${prefix}.`);
5390
+ return { exitCode: 0 };
5391
+ }
5392
+ if (!options.yes) return { exitCode: 1, error: confirmation(targets) };
5393
+ const deleted = [];
5394
+ const notFound = [];
5395
+ for (let start = 0; start < targets.length; start += MAX_PER_REQUEST) {
5396
+ try {
5397
+ const result = await client3.mailboxes.deleteMany(targets.slice(start, start + MAX_PER_REQUEST).map((target) => target.ref));
5398
+ deleted.push(...result.deleted);
5399
+ notFound.push(...result.not_found);
5400
+ } catch (error) {
5401
+ const message = error instanceof Error ? error.message : String(error);
5402
+ return {
5403
+ exitCode: 1,
5404
+ error: `${message}
5405
+ Deleted ${deleted.length} of ${targets.length} before this failed. Run the same command again to delete the rest.`
5406
+ };
5407
+ }
5408
+ }
5409
+ if (options.json) console.log(JSON.stringify({ deleted, not_found: notFound }));
5410
+ else {
5411
+ console.log(`Deleted ${deleted.length} mailbox${deleted.length === 1 ? "" : "es"}.`);
5412
+ if (notFound.length) console.log(`Not found: ${notFound.join(", ")}`);
5413
+ }
5414
+ return { exitCode: 0 };
5415
+ }
5416
+
5320
5417
  // src/commands/mailboxes/mailboxes.ts
5321
5418
  var VALUE_FLAGS7 = [
5322
5419
  "--send-as",
@@ -5355,7 +5452,8 @@ var VALUE_FLAGS7 = [
5355
5452
  "--forward-from",
5356
5453
  "--owner-email",
5357
5454
  "--code",
5358
- "--source"
5455
+ "--source",
5456
+ "--prefix"
5359
5457
  ];
5360
5458
  var BOOLEAN_FLAGS = ["--instant", "--json", "--yes", "--unread", "--archived", "--include-held", "--reply-all"];
5361
5459
  var USAGE3 = [
@@ -5369,7 +5467,8 @@ var USAGE3 = [
5369
5467
  " groundmail mailboxes pause <mailbox> [--reason \u2026] [--json]",
5370
5468
  " groundmail mailboxes resume <mailbox> [--json]",
5371
5469
  " groundmail mailboxes usage <mailbox> [--days 30] [--json]",
5372
- " groundmail mailboxes delete <mailbox> --yes",
5470
+ " groundmail mailboxes delete <mailbox> [<mailbox>\u2026] --yes",
5471
+ " groundmail mailboxes delete --prefix white-g [--tenant <tenant>] --yes [--json]",
5373
5472
  " groundmail mailboxes forward <mailbox> --to <new mailbox> --yes",
5374
5473
  " groundmail mailboxes threads <mailbox> [--label \u2026] [--participant \u2026] [--unread] [--archived] [--since <iso>] [--include-held] [--limit 25] [--cursor \u2026] [--json]",
5375
5474
  " groundmail mailboxes read <mailbox> [mbm_\u2026|thd_\u2026] [--search \u2026] [--from \u2026] [--thread thd_\u2026] [--label \u2026] [--unread] [--since <iso>] [--include-held] [--limit 25] [--cursor \u2026] [--json]",
@@ -5552,6 +5651,20 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
5552
5651
  const [mailbox, target] = args.positionals;
5553
5652
  const v = args.values;
5554
5653
  const on = (flag) => args.booleans[flag] === true;
5654
+ if (subcommand === "delete" && (v["--prefix"] !== void 0 || args.positionals.length > 1)) {
5655
+ try {
5656
+ const client3 = await createMailboxesClient(apiKey, v["--base-url"]);
5657
+ return await runBulkDelete(client3, {
5658
+ refs: args.positionals,
5659
+ prefix: v["--prefix"],
5660
+ tenant: v["--tenant"],
5661
+ yes: on("--yes"),
5662
+ json
5663
+ });
5664
+ } catch (error) {
5665
+ return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
5666
+ }
5667
+ }
5555
5668
  if (subcommand !== "create" && subcommand !== "list" && !mailbox) {
5556
5669
  return { exitCode: 1, error: `Missing mailbox. Usage: groundmail mailboxes ${subcommand} <mailbox>` };
5557
5670
  }
@@ -5737,6 +5850,474 @@ Sending is on again.`);
5737
5850
  }
5738
5851
  }
5739
5852
 
5853
+ // src/commands/contacts/broadcasts.ts
5854
+ import { readFile as readFile4 } from "fs/promises";
5855
+
5856
+ // src/commands/contacts/shared.ts
5857
+ var VALUE_FLAGS8 = [
5858
+ "--api-key",
5859
+ "--base-url",
5860
+ "--limit",
5861
+ "--cursor",
5862
+ "--email",
5863
+ "--external-id",
5864
+ "--list",
5865
+ "--lists",
5866
+ "--consent",
5867
+ "--first-name",
5868
+ "--last-name",
5869
+ "--attr",
5870
+ "--name",
5871
+ "--description",
5872
+ "--emails",
5873
+ "--ids",
5874
+ "--from",
5875
+ "--reply-to",
5876
+ "--template",
5877
+ "--subject",
5878
+ "--html",
5879
+ "--html-file",
5880
+ "--text",
5881
+ "--text-file",
5882
+ "--preheader",
5883
+ "--to",
5884
+ "--as",
5885
+ "--at",
5886
+ "--status",
5887
+ "--timeout"
5888
+ ];
5889
+ function readFlag28(args, flag) {
5890
+ const index = args.indexOf(flag);
5891
+ return index === -1 ? void 0 : args[index + 1];
5892
+ }
5893
+ function readFlags4(args, flag) {
5894
+ const out = [];
5895
+ args.forEach((arg, index) => {
5896
+ if (arg === flag && args[index + 1] !== void 0) out.push(args[index + 1]);
5897
+ });
5898
+ return out;
5899
+ }
5900
+ function hasFlag3(args, flag) {
5901
+ return args.includes(flag);
5902
+ }
5903
+ function positionals4(args) {
5904
+ const out = [];
5905
+ for (let i = 0; i < args.length; i += 1) {
5906
+ const arg = args[i];
5907
+ if (arg.startsWith("--")) {
5908
+ if (VALUE_FLAGS8.includes(arg)) i += 1;
5909
+ continue;
5910
+ }
5911
+ out.push(arg);
5912
+ }
5913
+ return out;
5914
+ }
5915
+ function commaList(value) {
5916
+ return (value ?? "").split(",").map((part) => part.trim()).filter(Boolean);
5917
+ }
5918
+ function clearable2(value) {
5919
+ if (value === void 0) return void 0;
5920
+ return value === "none" || value === "" ? null : value;
5921
+ }
5922
+ function pageFlags(args) {
5923
+ const rawLimit = readFlag28(args, "--limit");
5924
+ const limit = rawLimit === void 0 ? void 0 : Number(rawLimit);
5925
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1 || limit > 100)) return { error: "--limit must be a whole number from 1 to 100" };
5926
+ const cursor = readFlag28(args, "--cursor");
5927
+ return { ...limit !== void 0 ? { limit } : {}, ...cursor ? { cursor } : {} };
5928
+ }
5929
+ var MISSING_KEY5 = "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key.";
5930
+ async function createClient2(apiKey, baseUrl) {
5931
+ const { Groundmail } = await import("groundmail");
5932
+ return new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
5933
+ }
5934
+ function failure3(error) {
5935
+ const message = error instanceof Error ? error.message : String(error);
5936
+ const hint = error?.hint;
5937
+ return { exitCode: 1, error: typeof hint === "string" && hint ? `${message}
5938
+ ${hint}` : message };
5939
+ }
5940
+ function usageError(message, usage) {
5941
+ return { exitCode: 1, error: `${message}. Usage: ${usage}` };
5942
+ }
5943
+ async function withClient5(args, env, run) {
5944
+ const apiKey = readFlag28(args, "--api-key") || env.GROUNDMAIL_API_KEY || null;
5945
+ if (!apiKey) return { exitCode: 1, error: MISSING_KEY5 };
5946
+ try {
5947
+ const client3 = await createClient2(apiKey, readFlag28(args, "--base-url"));
5948
+ console.log(JSON.stringify(await run(client3)));
5949
+ return { exitCode: 0 };
5950
+ } catch (error) {
5951
+ return failure3(error);
5952
+ }
5953
+ }
5954
+
5955
+ // src/commands/contacts/broadcasts.ts
5956
+ var readText = (path) => readFile4(path, "utf8");
5957
+ var RECIPIENT_STATUSES = ["pending", "sending", "sent", "skipped", "failed"];
5958
+ async function draftFields(args, read = readText) {
5959
+ const html = readFlag28(args, "--html");
5960
+ const htmlFile = readFlag28(args, "--html-file");
5961
+ const text = readFlag28(args, "--text");
5962
+ const textFile = readFlag28(args, "--text-file");
5963
+ if (html !== void 0 && htmlFile !== void 0) return { error: "Pass --html or --html-file, not both" };
5964
+ if (text !== void 0 && textFile !== void 0) return { error: "Pass --text or --text-file, not both" };
5965
+ const template = clearable2(readFlag28(args, "--template"));
5966
+ if (template && (html !== void 0 || htmlFile !== void 0 || text !== void 0 || textFile !== void 0)) {
5967
+ return { error: "Use --template or --html/--text, not both" };
5968
+ }
5969
+ const out = {};
5970
+ const name = readFlag28(args, "--name");
5971
+ if (name !== void 0) out.name = name;
5972
+ const lists = readFlag28(args, "--lists") ?? readFlag28(args, "--list");
5973
+ if (lists !== void 0) out.lists = commaList(lists);
5974
+ const from = readFlag28(args, "--from");
5975
+ if (from !== void 0) out.from = from;
5976
+ for (const [flag, key] of [["--reply-to", "reply_to"], ["--subject", "subject"], ["--preheader", "preheader"]]) {
5977
+ const value = clearable2(readFlag28(args, flag));
5978
+ if (value !== void 0) out[key] = value;
5979
+ }
5980
+ if (template !== void 0) out.template = template;
5981
+ try {
5982
+ if (htmlFile !== void 0) out.html = await read(htmlFile);
5983
+ else if (html !== void 0) out.html = clearable2(html);
5984
+ if (textFile !== void 0) out.text = await read(textFile);
5985
+ else if (text !== void 0) out.text = clearable2(text);
5986
+ } catch (error) {
5987
+ return { error: `Can't read ${htmlFile ?? textFile}: ${error instanceof Error ? error.message : String(error)}` };
5988
+ }
5989
+ return { value: out };
5990
+ }
5991
+ var CREATE_USAGE = 'groundmail broadcasts create --name "December" --lists newsletter --from "Acme <news@mail.acme.dev>" (--template <template> | --subject \u2026 (--html \u2026 | --html-file email.html) [--text \u2026])';
5992
+ async function runBroadcastsList(args, env = process.env) {
5993
+ const page = pageFlags(args);
5994
+ if ("error" in page) return { exitCode: 1, error: page.error };
5995
+ return withClient5(args, env, (client3) => client3.broadcasts.list(page));
5996
+ }
5997
+ async function runBroadcastsCreate(args, env = process.env, read = readText) {
5998
+ const fields = await draftFields(args, read);
5999
+ if ("error" in fields) return { exitCode: 1, error: fields.error };
6000
+ const name = fields.value.name;
6001
+ if (typeof name !== "string" || !name) return usageError("Missing --name", CREATE_USAGE);
6002
+ return withClient5(args, env, (client3) => client3.broadcasts.create({ ...fields.value, name }));
6003
+ }
6004
+ async function runBroadcastsGet(args, env = process.env) {
6005
+ const id = positionals4(args)[0];
6006
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts get <id>");
6007
+ return withClient5(args, env, (client3) => client3.broadcasts.get(id));
6008
+ }
6009
+ async function runBroadcastsUpdate(args, env = process.env, read = readText) {
6010
+ const usage = "groundmail broadcasts update <id> [--name \u2026] [--lists \u2026] [--from \u2026] [--subject \u2026] [--html \u2026|--html-file \u2026] [--template \u2026|none]";
6011
+ const id = positionals4(args)[0];
6012
+ if (!id) return usageError("Missing the broadcast id", usage);
6013
+ const fields = await draftFields(args, read);
6014
+ if ("error" in fields) return { exitCode: 1, error: fields.error };
6015
+ if (!Object.keys(fields.value).length) return usageError("Nothing to update", usage);
6016
+ return withClient5(args, env, (client3) => client3.broadcasts.update(id, fields.value));
6017
+ }
6018
+ async function runBroadcastsDelete(args, env = process.env) {
6019
+ const id = positionals4(args)[0];
6020
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts delete <id> --yes");
6021
+ if (!hasFlag3(args, "--yes")) return { exitCode: 1, error: `This deletes draft ${id}. Run again with --yes to confirm.` };
6022
+ return withClient5(args, env, (client3) => client3.broadcasts.remove(id));
6023
+ }
6024
+ async function runBroadcastsAudience(args, env = process.env) {
6025
+ const id = positionals4(args)[0];
6026
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts audience <id>");
6027
+ return withClient5(args, env, (client3) => client3.broadcasts.audience(id));
6028
+ }
6029
+ async function runBroadcastsPreview(args, env = process.env) {
6030
+ const id = positionals4(args)[0];
6031
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts preview <id> [--as ada@example.com]");
6032
+ const as = readFlag28(args, "--as");
6033
+ return withClient5(args, env, (client3) => client3.broadcasts.preview(id, as ? { email: as } : {}));
6034
+ }
6035
+ async function runBroadcastsTest(args, env = process.env) {
6036
+ const usage = "groundmail broadcasts test <id> --to you@example.com[,\u2026]";
6037
+ const id = positionals4(args)[0];
6038
+ const to = commaList(readFlag28(args, "--to"));
6039
+ if (!id) return usageError("Missing the broadcast id", usage);
6040
+ if (!to.length) return usageError("Missing --to", usage);
6041
+ return withClient5(args, env, (client3) => client3.broadcasts.test(id, to));
6042
+ }
6043
+ async function runBroadcastsSend(args, env = process.env) {
6044
+ const usage = "groundmail broadcasts send <id> [--at 2026-12-02T09:00:00Z] --yes";
6045
+ const id = positionals4(args)[0];
6046
+ if (!id) return usageError("Missing the broadcast id", usage);
6047
+ const at = readFlag28(args, "--at");
6048
+ if (hasFlag3(args, "--at") && (at === void 0 || at.startsWith("-") || Number.isNaN(new Date(at).getTime()))) {
6049
+ return { exitCode: 1, error: "--at must be an ISO 8601 date-time, such as 2026-12-02T09:00:00Z" };
6050
+ }
6051
+ if (!hasFlag3(args, "--yes")) {
6052
+ return {
6053
+ exitCode: 1,
6054
+ error: `This ${at ? `schedules broadcast ${id} for ${at}` : `sends broadcast ${id} now`} to everyone on its lists. Check who with: groundmail broadcasts audience ${id}. Run again with --yes to confirm.`
6055
+ };
6056
+ }
6057
+ return withClient5(args, env, (client3) => client3.broadcasts.send(id, at ? { scheduled_at: at } : {}));
6058
+ }
6059
+ async function runBroadcastsPause(args, env = process.env) {
6060
+ const id = positionals4(args)[0];
6061
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts pause <id>");
6062
+ return withClient5(args, env, (client3) => client3.broadcasts.pause(id));
6063
+ }
6064
+ async function runBroadcastsResume(args, env = process.env) {
6065
+ const id = positionals4(args)[0];
6066
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts resume <id>");
6067
+ return withClient5(args, env, (client3) => client3.broadcasts.resume(id));
6068
+ }
6069
+ async function runBroadcastsCancel(args, env = process.env) {
6070
+ const id = positionals4(args)[0];
6071
+ if (!id) return usageError("Missing the broadcast id", "groundmail broadcasts cancel <id> --yes");
6072
+ if (!hasFlag3(args, "--yes")) return { exitCode: 1, error: `This stops broadcast ${id} for good; emails already sent stay sent. Run again with --yes to confirm.` };
6073
+ return withClient5(args, env, (client3) => client3.broadcasts.cancel(id));
6074
+ }
6075
+ async function runBroadcastsRecipients(args, env = process.env) {
6076
+ const usage = "groundmail broadcasts recipients <id> [--status sent|skipped|failed|pending|sending] [--limit 25] [--cursor \u2026]";
6077
+ const id = positionals4(args)[0];
6078
+ if (!id) return usageError("Missing the broadcast id", usage);
6079
+ const status = readFlag28(args, "--status");
6080
+ if (status !== void 0 && !RECIPIENT_STATUSES.includes(status)) return usageError(`Unknown --status "${status}"`, usage);
6081
+ const page = pageFlags(args);
6082
+ if ("error" in page) return { exitCode: 1, error: page.error };
6083
+ return withClient5(
6084
+ args,
6085
+ env,
6086
+ (client3) => client3.broadcasts.recipients(id, { ...page, ...status ? { status } : {} })
6087
+ );
6088
+ }
6089
+
6090
+ // src/commands/contacts/contacts.ts
6091
+ import { readFile as readFile5 } from "fs/promises";
6092
+ var IMPORT_POLL_MS = 2e3;
6093
+ var IMPORT_WAIT_DEFAULT_SECONDS = 600;
6094
+ var FINISHED_IMPORT = ["succeeded", "failed", "cancelled"];
6095
+ function parseAttrs(args) {
6096
+ const pairs = readFlags4(args, "--attr");
6097
+ if (!pairs.length) return { value: void 0 };
6098
+ const out = {};
6099
+ for (const pair of pairs) {
6100
+ const at = pair.indexOf("=");
6101
+ if (at < 1) return { error: `--attr takes key=value, got "${pair}"` };
6102
+ out[pair.slice(0, at).trim()] = pair.slice(at + 1);
6103
+ }
6104
+ return { value: out };
6105
+ }
6106
+ function contactFields(args) {
6107
+ const attrs = parseAttrs(args);
6108
+ if ("error" in attrs) return attrs;
6109
+ const firstName = clearable2(readFlag28(args, "--first-name"));
6110
+ const lastName = clearable2(readFlag28(args, "--last-name"));
6111
+ const externalId = clearable2(readFlag28(args, "--external-id"));
6112
+ return {
6113
+ value: {
6114
+ ...firstName !== void 0 ? { first_name: firstName } : {},
6115
+ ...lastName !== void 0 ? { last_name: lastName } : {},
6116
+ ...externalId !== void 0 ? { external_id: externalId } : {},
6117
+ ...attrs.value ? { attributes: attrs.value } : {}
6118
+ }
6119
+ };
6120
+ }
6121
+ var ADD_USAGE = "groundmail contacts add <email> --consent signup_form [--first-name Ada] [--last-name \u2026] [--external-id \u2026] [--attr plan=pro]";
6122
+ async function runContactsList(args, env = process.env) {
6123
+ const page = pageFlags(args);
6124
+ if ("error" in page) return { exitCode: 1, error: page.error };
6125
+ return withClient5(
6126
+ args,
6127
+ env,
6128
+ (client3) => client3.contacts.list({
6129
+ ...page,
6130
+ list: readFlag28(args, "--list"),
6131
+ email: readFlag28(args, "--email"),
6132
+ external_id: readFlag28(args, "--external-id")
6133
+ })
6134
+ );
6135
+ }
6136
+ async function runContactsAdd(args, env = process.env) {
6137
+ const email = positionals4(args)[0];
6138
+ const consent = readFlag28(args, "--consent");
6139
+ if (!email) return usageError("Missing the address", ADD_USAGE);
6140
+ if (!consent) return usageError("Missing --consent: where this person agreed to get email from you", ADD_USAGE);
6141
+ const fields = contactFields(args);
6142
+ if ("error" in fields) return { exitCode: 1, error: fields.error };
6143
+ return withClient5(args, env, (client3) => client3.contacts.create({ email, consent_source: consent, ...fields.value }));
6144
+ }
6145
+ async function runContactsGet(args, env = process.env) {
6146
+ const id = positionals4(args)[0];
6147
+ if (!id) return usageError("Missing the contact id", "groundmail contacts get <id>");
6148
+ return withClient5(args, env, (client3) => client3.contacts.get(id));
6149
+ }
6150
+ async function runContactsUpdate(args, env = process.env) {
6151
+ const usage = "groundmail contacts update <id> [--first-name \u2026|none] [--last-name \u2026|none] [--external-id \u2026|none] [--attr key=value]";
6152
+ const id = positionals4(args)[0];
6153
+ if (!id) return usageError("Missing the contact id", usage);
6154
+ const fields = contactFields(args);
6155
+ if ("error" in fields) return { exitCode: 1, error: fields.error };
6156
+ if (!Object.keys(fields.value).length) return usageError("Nothing to update", usage);
6157
+ return withClient5(args, env, (client3) => client3.contacts.update(id, fields.value));
6158
+ }
6159
+ async function runContactsDelete(args, env = process.env) {
6160
+ const id = positionals4(args)[0];
6161
+ if (!id) return usageError("Missing the contact id", "groundmail contacts delete <id> --yes");
6162
+ if (!hasFlag3(args, "--yes")) {
6163
+ return { exitCode: 1, error: `This deletes contact ${id} and takes it off every list. Run again with --yes to confirm.` };
6164
+ }
6165
+ return withClient5(args, env, (client3) => client3.contacts.remove(id));
6166
+ }
6167
+ async function runContactsImport(args, env = process.env, deps = {}) {
6168
+ const usage = "groundmail contacts import <file.csv> --consent signup_form [--list <list>] [--wait [--timeout 600]]";
6169
+ const file = positionals4(args)[0];
6170
+ const consent = readFlag28(args, "--consent");
6171
+ if (!file) return usageError("Missing the CSV file", usage);
6172
+ if (!consent) return usageError("Missing --consent: where these people agreed to get email from you", usage);
6173
+ const timeoutSeconds = Number(readFlag28(args, "--timeout") ?? IMPORT_WAIT_DEFAULT_SECONDS);
6174
+ if (!Number.isFinite(timeoutSeconds) || timeoutSeconds <= 0) return { exitCode: 1, error: "--timeout must be a number of seconds" };
6175
+ let csv;
6176
+ try {
6177
+ csv = await (deps.readFile ?? readFile5)(file);
6178
+ } catch {
6179
+ return { exitCode: 1, error: `Can't read ${file}` };
6180
+ }
6181
+ const sleep = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
6182
+ const now = deps.now ?? Date.now;
6183
+ const filename = file.split(/[\\/]/).pop();
6184
+ return withClient5(args, env, async (client3) => {
6185
+ let row = await client3.contacts.imports.create(csv, { consent_source: consent, list: readFlag28(args, "--list"), filename });
6186
+ if (!hasFlag3(args, "--wait")) return row;
6187
+ const deadline = now() + timeoutSeconds * 1e3;
6188
+ while (!FINISHED_IMPORT.includes(row.status)) {
6189
+ if (now() >= deadline) throw new Error(`Import ${row.id} is still ${row.status}. Check it later: groundmail contacts import-status ${row.id}`);
6190
+ await sleep(IMPORT_POLL_MS);
6191
+ row = await client3.contacts.imports.get(row.id);
6192
+ }
6193
+ return row;
6194
+ });
6195
+ }
6196
+ async function runContactsImports(args, env = process.env) {
6197
+ const page = pageFlags(args);
6198
+ if ("error" in page) return { exitCode: 1, error: page.error };
6199
+ return withClient5(args, env, (client3) => client3.contacts.imports.list(page));
6200
+ }
6201
+ async function runContactsImportStatus(args, env = process.env) {
6202
+ const id = positionals4(args)[0];
6203
+ if (!id) return usageError("Missing the import id", "groundmail contacts import-status <import id>");
6204
+ return withClient5(args, env, (client3) => client3.contacts.imports.get(id));
6205
+ }
6206
+ async function runContactsImportCancel(args, env = process.env) {
6207
+ const id = positionals4(args)[0];
6208
+ if (!id) return usageError("Missing the import id", "groundmail contacts import-cancel <import id> --yes");
6209
+ if (!hasFlag3(args, "--yes")) return { exitCode: 1, error: `This stops import ${id}; contacts already added stay. Run again with --yes to confirm.` };
6210
+ return withClient5(args, env, (client3) => client3.contacts.imports.cancel(id));
6211
+ }
6212
+
6213
+ // src/commands/contacts/lists.ts
6214
+ async function runListsList(args, env = process.env) {
6215
+ const page = pageFlags(args);
6216
+ if ("error" in page) return { exitCode: 1, error: page.error };
6217
+ return withClient5(args, env, (client3) => client3.lists.list(page));
6218
+ }
6219
+ async function runListsCreate(args, env = process.env) {
6220
+ const name = readFlag28(args, "--name") ?? positionals4(args)[0];
6221
+ if (!name) return usageError("Missing --name", 'groundmail lists create --name "Beta users" [--description \u2026]');
6222
+ const description = readFlag28(args, "--description");
6223
+ return withClient5(args, env, (client3) => client3.lists.create({ name, ...description !== void 0 ? { description } : {} }));
6224
+ }
6225
+ async function runListsGet(args, env = process.env) {
6226
+ const list = positionals4(args)[0];
6227
+ if (!list) return usageError("Missing the list (id or key)", "groundmail lists get <list>");
6228
+ return withClient5(args, env, (client3) => client3.lists.get(list));
6229
+ }
6230
+ async function runListsUpdate(args, env = process.env) {
6231
+ const usage = "groundmail lists update <list> [--name \u2026] [--description \u2026|none]";
6232
+ const list = positionals4(args)[0];
6233
+ if (!list) return usageError("Missing the list (id or key)", usage);
6234
+ const name = readFlag28(args, "--name");
6235
+ const description = clearable2(readFlag28(args, "--description"));
6236
+ if (name === void 0 && description === void 0) return usageError("Nothing to update", usage);
6237
+ return withClient5(
6238
+ args,
6239
+ env,
6240
+ (client3) => client3.lists.update(list, { ...name !== void 0 ? { name } : {}, ...description !== void 0 ? { description } : {} })
6241
+ );
6242
+ }
6243
+ async function runListsDelete(args, env = process.env) {
6244
+ const list = positionals4(args)[0];
6245
+ if (!list) return usageError("Missing the list (id or key)", "groundmail lists delete <list> --yes");
6246
+ if (!hasFlag3(args, "--yes")) return { exitCode: 1, error: `This deletes list ${list}; its contacts stay. Run again with --yes to confirm.` };
6247
+ return withClient5(args, env, (client3) => client3.lists.remove(list));
6248
+ }
6249
+ async function runListsContacts(args, env = process.env) {
6250
+ const list = positionals4(args)[0];
6251
+ if (!list) return usageError("Missing the list (id or key)", "groundmail lists contacts <list> [--limit 25] [--cursor \u2026]");
6252
+ const page = pageFlags(args);
6253
+ if ("error" in page) return { exitCode: 1, error: page.error };
6254
+ return withClient5(args, env, (client3) => client3.lists.listContacts(list, page));
6255
+ }
6256
+ async function runListsAdd(args, env = process.env) {
6257
+ const usage = "groundmail lists add <list> (--emails a@example.com,b@example.com | --ids <contact id>,\u2026)";
6258
+ const list = positionals4(args)[0];
6259
+ if (!list) return usageError("Missing the list (id or key)", usage);
6260
+ const emails = commaList(readFlag28(args, "--emails"));
6261
+ const ids = commaList(readFlag28(args, "--ids"));
6262
+ if (!emails.length && !ids.length) return usageError("Pass --emails or --ids", usage);
6263
+ return withClient5(
6264
+ args,
6265
+ env,
6266
+ (client3) => client3.lists.addContacts(list, { ...emails.length ? { emails } : {}, ...ids.length ? { contact_ids: ids } : {} })
6267
+ );
6268
+ }
6269
+ async function runListsRemove(args, env = process.env) {
6270
+ const [list, contactId] = positionals4(args);
6271
+ if (!list || !contactId) return usageError("Missing the list or the contact id", "groundmail lists remove <list> <contact id>");
6272
+ return withClient5(args, env, (client3) => client3.lists.removeContact(list, contactId));
6273
+ }
6274
+
6275
+ // src/commands/contacts/dispatch.ts
6276
+ var COMMANDS = {
6277
+ contacts: {
6278
+ list: (args) => runContactsList(args),
6279
+ add: (args) => runContactsAdd(args),
6280
+ create: (args) => runContactsAdd(args),
6281
+ get: (args) => runContactsGet(args),
6282
+ update: (args) => runContactsUpdate(args),
6283
+ delete: (args) => runContactsDelete(args),
6284
+ remove: (args) => runContactsDelete(args),
6285
+ import: (args) => runContactsImport(args),
6286
+ imports: (args) => runContactsImports(args),
6287
+ "import-status": (args) => runContactsImportStatus(args),
6288
+ "import-cancel": (args) => runContactsImportCancel(args)
6289
+ },
6290
+ lists: {
6291
+ list: (args) => runListsList(args),
6292
+ create: (args) => runListsCreate(args),
6293
+ get: (args) => runListsGet(args),
6294
+ update: (args) => runListsUpdate(args),
6295
+ delete: (args) => runListsDelete(args),
6296
+ contacts: (args) => runListsContacts(args),
6297
+ add: (args) => runListsAdd(args),
6298
+ remove: (args) => runListsRemove(args)
6299
+ },
6300
+ broadcasts: {
6301
+ list: (args) => runBroadcastsList(args),
6302
+ create: (args) => runBroadcastsCreate(args),
6303
+ get: (args) => runBroadcastsGet(args),
6304
+ update: (args) => runBroadcastsUpdate(args),
6305
+ delete: (args) => runBroadcastsDelete(args),
6306
+ audience: (args) => runBroadcastsAudience(args),
6307
+ preview: (args) => runBroadcastsPreview(args),
6308
+ test: (args) => runBroadcastsTest(args),
6309
+ send: (args) => runBroadcastsSend(args),
6310
+ pause: (args) => runBroadcastsPause(args),
6311
+ resume: (args) => runBroadcastsResume(args),
6312
+ cancel: (args) => runBroadcastsCancel(args),
6313
+ recipients: (args) => runBroadcastsRecipients(args)
6314
+ }
6315
+ };
6316
+ function contactsCommand(command, subcommand) {
6317
+ if (!command || !subcommand) return null;
6318
+ return COMMANDS[command]?.[subcommand] ?? null;
6319
+ }
6320
+
5740
6321
  // src/session/failure.ts
5741
6322
  import { chmodSync as chmodSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
5742
6323
  import { join as join2 } from "path";
@@ -5783,11 +6364,11 @@ function commandName(argv) {
5783
6364
  function failurePath(env) {
5784
6365
  return join2(configDir(env), "last-error.json");
5785
6366
  }
5786
- function saveLastFailure(failure3, env = process.env) {
6367
+ function saveLastFailure(failure4, env = process.env) {
5787
6368
  try {
5788
6369
  mkdirSync2(configDir(env), { recursive: true });
5789
6370
  const path = failurePath(env);
5790
- writeFileSync2(path, `${JSON.stringify(failure3, null, 2)}
6371
+ writeFileSync2(path, `${JSON.stringify(failure4, null, 2)}
5791
6372
  `, { mode: 384 });
5792
6373
  chmodSync2(path, 384);
5793
6374
  } catch {
@@ -5812,16 +6393,16 @@ function buildFailure(input) {
5812
6393
  ...input.http ? { http: input.http } : {}
5813
6394
  };
5814
6395
  }
5815
- function jsonError(failure3) {
5816
- const usage = /^(Usage:|Unknown (flag|command)|Missing |Nothing to )/.test(failure3.error);
6396
+ function jsonError(failure4) {
6397
+ const usage = /^(Usage:|Unknown (flag|command)|Missing |Nothing to )/.test(failure4.error);
5817
6398
  return {
5818
6399
  error: {
5819
- message: failure3.http?.message && failure3.error.includes(failure3.http.message) ? failure3.http.message : failure3.error,
5820
- code: failure3.http?.code ?? (usage ? "usage_error" : "cli_error"),
5821
- ...failure3.http ? { status: failure3.http.status } : {},
5822
- ...failure3.http?.hint ? { hint: failure3.http.hint } : {},
5823
- ...failure3.http?.request_id ? { request_id: failure3.http.request_id } : {},
5824
- exit_code: failure3.exit_code
6400
+ message: failure4.http?.message && failure4.error.includes(failure4.http.message) ? failure4.http.message : failure4.error,
6401
+ code: failure4.http?.code ?? (usage ? "usage_error" : "cli_error"),
6402
+ ...failure4.http ? { status: failure4.http.status } : {},
6403
+ ...failure4.http?.hint ? { hint: failure4.http.hint } : {},
6404
+ ...failure4.http?.request_id ? { request_id: failure4.http.request_id } : {},
6405
+ exit_code: failure4.exit_code
5825
6406
  },
5826
6407
  feedback: FEEDBACK_LINE
5827
6408
  };
@@ -5867,23 +6448,23 @@ async function defaultClient(apiKey, baseUrl) {
5867
6448
  const { Groundmail } = await import("groundmail");
5868
6449
  return new Groundmail(apiKey, sdkOptions(baseUrl));
5869
6450
  }
5870
- function feedbackContext(failure3) {
6451
+ function feedbackContext(failure4) {
5871
6452
  const client3 = { client: CLI_PACKAGE.name, client_version: CLI_PACKAGE.version };
5872
- if (!failure3) return client3;
6453
+ if (!failure4) return client3;
5873
6454
  return {
5874
- command: failure3.command,
5875
- args: failure3.args,
5876
- error: failure3.error,
5877
- at: failure3.at,
5878
- ...failure3.http ? {
5879
- method: failure3.http.method,
5880
- path: failure3.http.path,
5881
- status: failure3.http.status,
5882
- ...failure3.http.code ? { code: failure3.http.code } : {},
5883
- ...failure3.http.request_id ? { request_id: failure3.http.request_id } : {}
6455
+ command: failure4.command,
6456
+ args: failure4.args,
6457
+ error: failure4.error,
6458
+ at: failure4.at,
6459
+ ...failure4.http ? {
6460
+ method: failure4.http.method,
6461
+ path: failure4.http.path,
6462
+ status: failure4.http.status,
6463
+ ...failure4.http.code ? { code: failure4.http.code } : {},
6464
+ ...failure4.http.request_id ? { request_id: failure4.http.request_id } : {}
5884
6465
  } : {},
5885
6466
  ...client3,
5886
- client_version: failure3.cli_version
6467
+ client_version: failure4.cli_version
5887
6468
  };
5888
6469
  }
5889
6470
  async function runFeedbackCommand(argv, deps = {}) {
@@ -5900,17 +6481,17 @@ ${USAGE4}` };
5900
6481
  if (!apiKey) return { exitCode: 1, error: "Missing API key. Run groundmail login, set GROUNDMAIL_API_KEY or pass --api-key. Or write to support@groundmail.dev." };
5901
6482
  const now = deps.now ?? /* @__PURE__ */ new Date();
5902
6483
  const saved = args.booleans["--last"] === false ? null : loadLastFailure(env);
5903
- const failure3 = saved && now.getTime() - new Date(saved.at).getTime() <= LAST_FAILURE_MAX_AGE_MS ? saved : null;
6484
+ const failure4 = saved && now.getTime() - new Date(saved.at).getTime() <= LAST_FAILURE_MAX_AGE_MS ? saved : null;
5904
6485
  try {
5905
6486
  const client3 = await (deps.client ?? defaultClient)(apiKey, args.values["--base-url"]);
5906
- const result = await client3.feedback({ message, context: feedbackContext(failure3) });
6487
+ const result = await client3.feedback({ message, context: feedbackContext(failure4) });
5907
6488
  if (args.booleans["--json"] === true) {
5908
- stdout(JSON.stringify({ ...result, included: failure3 ? { command: failure3.command, args: failure3.args, error: failure3.error, request_id: failure3.http?.request_id ?? null } : null }));
6489
+ stdout(JSON.stringify({ ...result, included: failure4 ? { command: failure4.command, args: failure4.args, error: failure4.error, request_id: failure4.http?.request_id ?? null } : null }));
5909
6490
  } else {
5910
6491
  const lines = [`Sent to Groundmail support. Reference: ${result.reference}`];
5911
- if (failure3) {
5912
- const detail = [failure3.http ? `HTTP ${failure3.http.status}` : null, failure3.http?.request_id ?? null].filter(Boolean).join(", ");
5913
- lines.push(`Included your last failed command: groundmail ${failure3.args.join(" ")}${detail ? ` (${detail})` : ""}`);
6492
+ if (failure4) {
6493
+ const detail = [failure4.http ? `HTTP ${failure4.http.status}` : null, failure4.http?.request_id ?? null].filter(Boolean).join(", ");
6494
+ lines.push(`Included your last failed command: groundmail ${failure4.args.join(" ")}${detail ? ` (${detail})` : ""}`);
5914
6495
  } else {
5915
6496
  lines.push("No failed command from the last 24 hours was attached.");
5916
6497
  }
@@ -6210,10 +6791,10 @@ console.error = (...parts2) => {
6210
6791
  };
6211
6792
  function fail(exitCode, message, options = {}) {
6212
6793
  const isFeedback = argvAll[0] === "feedback";
6213
- const failure3 = buildFailure({ argv: argvAll, error: message, exitCode, version: CLI_VERSION, http: lastHttpFailure() });
6214
- if (!isFeedback) saveLastFailure(failure3);
6794
+ const failure4 = buildFailure({ argv: argvAll, error: message, exitCode, version: CLI_VERSION, http: lastHttpFailure() });
6795
+ if (!isFeedback) saveLastFailure(failure4);
6215
6796
  if (jsonMode) {
6216
- const body = jsonError(failure3);
6797
+ const body = jsonError(failure4);
6217
6798
  writeError(JSON.stringify(isFeedback ? { error: body.error } : body));
6218
6799
  } else {
6219
6800
  if (!options.printed) writeError(message);
@@ -6463,6 +7044,8 @@ async function main() {
6463
7044
  if (subcommand === "update") await finish(await runUpdateCommand6(rest));
6464
7045
  if (subcommand === "delete" || subcommand === "remove") await finish(await runDeleteCommand6(rest));
6465
7046
  }
7047
+ const contactsRun = contactsCommand(command, subcommand);
7048
+ if (contactsRun) await finish(await contactsRun(rest));
6466
7049
  if (command === "keys") {
6467
7050
  if (subcommand === "list") {
6468
7051
  await finish(await runListKeysCommandWithClient(rest));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "groundmail-cli",
3
- "version": "0.53.4",
3
+ "version": "0.55.4",
4
4
  "description": "Groundmail CLI: send email and manage mailboxes from the terminal",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,12 +38,12 @@
38
38
  "prepublishOnly": "npm run build"
39
39
  },
40
40
  "dependencies": {
41
- "groundmail": "0.59.1"
41
+ "groundmail": "0.61.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsup": "^9.0.0",
45
45
  "typescript": "^6.0.3",
46
- "vitest": "^5.1.0"
46
+ "vitest": "^5.1.2"
47
47
  },
48
48
  "optionalDependencies": {
49
49
  "@napi-rs/keyring": "2.1.2"