supersendtx-cli 0.2.0 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +238 -21
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -82,18 +82,105 @@ async function runSendCommandWithClient(args, env = process.env) {
82
82
  return { exitCode };
83
83
  }
84
84
 
85
- // src/commands/domains/shared.ts
85
+ // src/commands/emails/get.ts
86
86
  function readFlag2(args, flag) {
87
87
  const index = args.indexOf(flag);
88
88
  if (index === -1) return void 0;
89
89
  return args[index + 1];
90
90
  }
91
+ async function runGetCommand(args, deps) {
92
+ const env = deps.env ?? process.env;
93
+ const stdout = deps.stdout ?? ((line) => console.log(line));
94
+ const stderr = deps.stderr ?? ((line) => console.error(line));
95
+ const id = readFlag2(args, "--id") || args.find((a) => !a.startsWith("--"));
96
+ const apiKey = readFlag2(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
97
+ if (!apiKey) {
98
+ stderr("Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key.");
99
+ return { exitCode: 1, error: "missing key" };
100
+ }
101
+ if (!id) {
102
+ stderr("Required: --id <msg_\u2026>");
103
+ return { exitCode: 1, error: "missing id" };
104
+ }
105
+ try {
106
+ const result = await deps.getEmail(id);
107
+ stdout(JSON.stringify(result));
108
+ return { exitCode: 0 };
109
+ } catch (error) {
110
+ stderr(error instanceof Error ? error.message : String(error));
111
+ return { exitCode: 1, error: String(error) };
112
+ }
113
+ }
114
+ async function runGetCommandWithClient(args, env = process.env) {
115
+ const apiKey = readFlag2(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
116
+ const baseUrl = readFlag2(args, "--base-url");
117
+ if (!apiKey) {
118
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
119
+ }
120
+ const { SuperSendTX } = await import("supersendtx");
121
+ const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
122
+ return runGetCommand(args, {
123
+ env,
124
+ getEmail: (id) => client.emails.get(id)
125
+ });
126
+ }
127
+
128
+ // src/commands/emails/list.ts
129
+ function readFlag3(args, flag) {
130
+ const index = args.indexOf(flag);
131
+ if (index === -1) return void 0;
132
+ return args[index + 1];
133
+ }
134
+ async function runListCommand(args, deps) {
135
+ const env = deps.env ?? process.env;
136
+ const stdout = deps.stdout ?? ((line) => console.log(line));
137
+ const stderr = deps.stderr ?? ((line) => console.error(line));
138
+ const apiKey = readFlag3(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
139
+ if (!apiKey) {
140
+ stderr("Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key.");
141
+ return { exitCode: 1, error: "missing key" };
142
+ }
143
+ const limitRaw = readFlag3(args, "--limit");
144
+ const cursor = readFlag3(args, "--cursor");
145
+ const limit = limitRaw ? Number(limitRaw) : void 0;
146
+ try {
147
+ const result = await deps.listEmails({
148
+ ...limit != null && Number.isFinite(limit) ? { limit } : {},
149
+ ...cursor ? { cursor } : {}
150
+ });
151
+ stdout(JSON.stringify(result));
152
+ return { exitCode: 0 };
153
+ } catch (error) {
154
+ stderr(error instanceof Error ? error.message : String(error));
155
+ return { exitCode: 1, error: String(error) };
156
+ }
157
+ }
158
+ async function runListCommandWithClient(args, env = process.env) {
159
+ const apiKey = readFlag3(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
160
+ const baseUrl = readFlag3(args, "--base-url");
161
+ if (!apiKey) {
162
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
163
+ }
164
+ const { SuperSendTX } = await import("supersendtx");
165
+ const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
166
+ return runListCommand(args, {
167
+ env,
168
+ listEmails: (params) => client.emails.list(params)
169
+ });
170
+ }
171
+
172
+ // src/commands/domains/shared.ts
173
+ function readFlag4(args, flag) {
174
+ const index = args.indexOf(flag);
175
+ if (index === -1) return void 0;
176
+ return args[index + 1];
177
+ }
91
178
  function parseDomainsCommonArgs(args) {
92
179
  return {
93
- apiKey: readFlag2(args, "--api-key"),
94
- baseUrl: readFlag2(args, "--base-url"),
95
- name: readFlag2(args, "--name") || readFlag2(args, "--domain"),
96
- id: readFlag2(args, "--id")
180
+ apiKey: readFlag4(args, "--api-key"),
181
+ baseUrl: readFlag4(args, "--base-url"),
182
+ name: readFlag4(args, "--name") || readFlag4(args, "--domain"),
183
+ id: readFlag4(args, "--id")
97
184
  };
98
185
  }
99
186
  function resolveApiKey(options, env) {
@@ -174,16 +261,20 @@ async function runApplyCommand(args, env = process.env) {
174
261
  }
175
262
  try {
176
263
  const client = await createDomainsClient(apiKey, options.baseUrl);
177
- const result = await client.domains.applyDns({
264
+ const localCloudflare = env.CLOUDFLARE_API_TOKEN || env.CLOUDFLARE_API_KEY;
265
+ const useStoredCloudflare = provider === "cloudflare" && !localCloudflare;
266
+ const result = useStoredCloudflare ? await client.domains.apply(idOrName, { provider: "cloudflare" }) : await client.domains.applyDns({
178
267
  idOrName,
179
268
  provider,
180
- cloudflareApiToken: env.CLOUDFLARE_API_TOKEN || env.CLOUDFLARE_API_KEY,
269
+ cloudflareApiToken: localCloudflare,
181
270
  cloudflareZoneId: env.CLOUDFLARE_ZONE_ID,
182
271
  godaddyApiKey: env.GODADDY_API_KEY,
183
272
  godaddyApiSecret: env.GODADDY_API_SECRET
184
273
  });
185
274
  console.log(JSON.stringify(result));
186
- console.error(`Applied ${result.results.length} DNS change(s) via ${result.provider} for ${result.domain}.`);
275
+ console.error(
276
+ useStoredCloudflare ? `Applied ${result.results.length} DNS change(s) via stored Cloudflare credentials for ${result.domain}.` : `Applied ${result.results.length} DNS change(s) via ${result.provider} for ${result.domain}.`
277
+ );
187
278
  for (const row of result.results) {
188
279
  console.error(` ${row.action.padEnd(10)} ${row.purpose} \u2192 ${row.host}`);
189
280
  }
@@ -196,7 +287,7 @@ async function runApplyCommand(args, env = process.env) {
196
287
  }
197
288
 
198
289
  // src/commands/domains/list.ts
199
- async function runListCommand(args, env = process.env) {
290
+ async function runListCommand2(args, env = process.env) {
200
291
  const options = parseDomainsCommonArgs(args);
201
292
  const apiKey = resolveApiKey(options, env);
202
293
  if (!apiKey) {
@@ -240,15 +331,15 @@ async function runVerifyCommand(args, env = process.env) {
240
331
  }
241
332
 
242
333
  // src/commands/webhooks/shared.ts
243
- function readFlag3(args, flag) {
334
+ function readFlag5(args, flag) {
244
335
  const index = args.indexOf(flag);
245
336
  if (index === -1) return void 0;
246
337
  return args[index + 1];
247
338
  }
248
339
  function parseWebhooksCommonArgs(args) {
249
340
  return {
250
- apiKey: readFlag3(args, "--api-key"),
251
- baseUrl: readFlag3(args, "--base-url")
341
+ apiKey: readFlag5(args, "--api-key"),
342
+ baseUrl: readFlag5(args, "--base-url")
252
343
  };
253
344
  }
254
345
  function resolveApiKey2(options, env) {
@@ -266,7 +357,7 @@ async function runCreateCommand(args, env = process.env) {
266
357
  if (!apiKey) {
267
358
  return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
268
359
  }
269
- const url = readFlag3(args, "--url");
360
+ const url = readFlag5(args, "--url");
270
361
  if (!url) {
271
362
  return { exitCode: 1, error: "Required flag: --url" };
272
363
  }
@@ -287,7 +378,7 @@ async function runDeleteCommand(args, env = process.env) {
287
378
  if (!apiKey) {
288
379
  return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
289
380
  }
290
- const id = readFlag3(args, "--id");
381
+ const id = readFlag5(args, "--id");
291
382
  if (!id) {
292
383
  return { exitCode: 1, error: "Required flag: --id" };
293
384
  }
@@ -302,7 +393,7 @@ async function runDeleteCommand(args, env = process.env) {
302
393
  }
303
394
 
304
395
  // src/commands/webhooks/list.ts
305
- async function runListCommand2(args, env = process.env) {
396
+ async function runListCommand3(args, env = process.env) {
306
397
  const options = parseWebhooksCommonArgs(args);
307
398
  const apiKey = resolveApiKey2(options, env);
308
399
  if (!apiKey) {
@@ -318,6 +409,98 @@ async function runListCommand2(args, env = process.env) {
318
409
  }
319
410
  }
320
411
 
412
+ // src/commands/keys/list.ts
413
+ function readFlag6(args, flag) {
414
+ const index = args.indexOf(flag);
415
+ if (index === -1) return void 0;
416
+ return args[index + 1];
417
+ }
418
+ async function runListKeysCommandWithClient(args, env = process.env) {
419
+ const apiKey = readFlag6(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
420
+ const baseUrl = readFlag6(args, "--base-url");
421
+ if (!apiKey) {
422
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
423
+ }
424
+ const { SuperSendTX } = await import("supersendtx");
425
+ const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
426
+ try {
427
+ const limitRaw = readFlag6(args, "--limit");
428
+ const cursor = readFlag6(args, "--cursor");
429
+ const result = await client.apiKeys.list({
430
+ ...limitRaw ? { limit: Number(limitRaw) } : {},
431
+ ...cursor ? { cursor } : {}
432
+ });
433
+ console.log(JSON.stringify(result));
434
+ return { exitCode: 0 };
435
+ } catch (error) {
436
+ const message = error instanceof Error ? error.message : String(error);
437
+ console.error(message);
438
+ return { exitCode: 1, error: message };
439
+ }
440
+ }
441
+
442
+ // src/commands/keys/create.ts
443
+ function readFlag7(args, flag) {
444
+ const index = args.indexOf(flag);
445
+ if (index === -1) return void 0;
446
+ return args[index + 1];
447
+ }
448
+ async function runCreateKeyCommandWithClient(args, env = process.env) {
449
+ const apiKey = readFlag7(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
450
+ const baseUrl = readFlag7(args, "--base-url");
451
+ if (!apiKey) {
452
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
453
+ }
454
+ const name = readFlag7(args, "--name");
455
+ const scope = readFlag7(args, "--scope");
456
+ if (scope && scope !== "full" && scope !== "sending") {
457
+ return { exitCode: 1, error: "--scope must be full or sending" };
458
+ }
459
+ const { SuperSendTX } = await import("supersendtx");
460
+ const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
461
+ try {
462
+ const result = await client.apiKeys.create({
463
+ ...name ? { name } : {},
464
+ ...scope ? { scope } : {}
465
+ });
466
+ console.log(JSON.stringify(result));
467
+ return { exitCode: 0 };
468
+ } catch (error) {
469
+ const message = error instanceof Error ? error.message : String(error);
470
+ console.error(message);
471
+ return { exitCode: 1, error: message };
472
+ }
473
+ }
474
+
475
+ // src/commands/keys/delete.ts
476
+ function readFlag8(args, flag) {
477
+ const index = args.indexOf(flag);
478
+ if (index === -1) return void 0;
479
+ return args[index + 1];
480
+ }
481
+ async function runDeleteKeyCommandWithClient(args, env = process.env) {
482
+ const apiKey = readFlag8(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
483
+ const baseUrl = readFlag8(args, "--base-url");
484
+ const id = readFlag8(args, "--id");
485
+ if (!apiKey) {
486
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
487
+ }
488
+ if (!id) {
489
+ return { exitCode: 1, error: "Required: --id <api-key-id>" };
490
+ }
491
+ const { SuperSendTX } = await import("supersendtx");
492
+ const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
493
+ try {
494
+ const result = await client.apiKeys.remove(id);
495
+ console.log(JSON.stringify(result));
496
+ return { exitCode: 0 };
497
+ } catch (error) {
498
+ const message = error instanceof Error ? error.message : String(error);
499
+ console.error(message);
500
+ return { exitCode: 1, error: message };
501
+ }
502
+ }
503
+
321
504
  // src/cli.ts
322
505
  function printUsage() {
323
506
  console.error("Usage:");
@@ -329,13 +512,18 @@ function printUsage() {
329
512
  console.error(
330
513
  ' supersendtx emails send --from you@domain.com --to user@example.com --subject "Hello" --html "<p>Hi</p>"'
331
514
  );
515
+ console.error(" supersendtx emails list [--limit 25] [--cursor \u2026]");
516
+ console.error(" supersendtx emails get --id msg_\u2026");
332
517
  console.error(" supersendtx webhooks list");
333
518
  console.error(" supersendtx webhooks create --url https://yourapp.com/hooks");
334
519
  console.error(" supersendtx webhooks delete --id <webhook-id>");
520
+ console.error(" supersendtx keys list");
521
+ console.error(" supersendtx keys create [--name Default] [--scope full|sending]");
522
+ console.error(" supersendtx keys delete --id <api-key-id>");
335
523
  console.error("");
336
524
  console.error("Environment:");
337
525
  console.error(" SUPERSENDTX_API_KEY=stx_\u2026");
338
- console.error(" CLOUDFLARE_API_TOKEN=\u2026 (domains apply --provider cloudflare)");
526
+ console.error(" CLOUDFLARE_API_TOKEN=\u2026 (optional local apply; else uses dashboard Integrations)");
339
527
  console.error(" GODADDY_API_KEY=\u2026 GODADDY_API_SECRET=\u2026 (domains apply --provider godaddy)");
340
528
  }
341
529
  async function main() {
@@ -352,7 +540,7 @@ async function main() {
352
540
  process.exit(result.exitCode);
353
541
  }
354
542
  if (subcommand === "list") {
355
- const result = await runListCommand(rest);
543
+ const result = await runListCommand2(rest);
356
544
  if (result.error) console.error(result.error);
357
545
  process.exit(result.exitCode);
358
546
  }
@@ -362,13 +550,25 @@ async function main() {
362
550
  process.exit(result.exitCode);
363
551
  }
364
552
  }
365
- if (command === "emails" && subcommand === "send") {
366
- const result = await runSendCommandWithClient(rest);
367
- process.exit(result.exitCode);
553
+ if (command === "emails") {
554
+ if (subcommand === "send") {
555
+ const result = await runSendCommandWithClient(rest);
556
+ process.exit(result.exitCode);
557
+ }
558
+ if (subcommand === "list") {
559
+ const result = await runListCommandWithClient(rest);
560
+ if (result.error) console.error(result.error);
561
+ process.exit(result.exitCode);
562
+ }
563
+ if (subcommand === "get") {
564
+ const result = await runGetCommandWithClient(rest);
565
+ if (result.error) console.error(result.error);
566
+ process.exit(result.exitCode);
567
+ }
368
568
  }
369
569
  if (command === "webhooks") {
370
570
  if (subcommand === "list") {
371
- const result = await runListCommand2(rest);
571
+ const result = await runListCommand3(rest);
372
572
  if (result.error) console.error(result.error);
373
573
  process.exit(result.exitCode);
374
574
  }
@@ -383,6 +583,23 @@ async function main() {
383
583
  process.exit(result.exitCode);
384
584
  }
385
585
  }
586
+ if (command === "keys") {
587
+ if (subcommand === "list") {
588
+ const result = await runListKeysCommandWithClient(rest);
589
+ if (result.error) console.error(result.error);
590
+ process.exit(result.exitCode);
591
+ }
592
+ if (subcommand === "create") {
593
+ const result = await runCreateKeyCommandWithClient(rest);
594
+ if (result.error) console.error(result.error);
595
+ process.exit(result.exitCode);
596
+ }
597
+ if (subcommand === "delete") {
598
+ const result = await runDeleteKeyCommandWithClient(rest);
599
+ if (result.error) console.error(result.error);
600
+ process.exit(result.exitCode);
601
+ }
602
+ }
386
603
  printUsage();
387
604
  process.exit(1);
388
605
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supersendtx-cli",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "SuperSend TX CLI — send transactional email from the terminal",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,7 +39,7 @@
39
39
  "prepublishOnly": "npm run build"
40
40
  },
41
41
  "dependencies": {
42
- "supersendtx": "^0.2.0"
42
+ "supersendtx": "0.4.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsup": "^8.5.0",