supersendtx-cli 0.3.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.
- package/dist/cli.js +230 -17
- 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/
|
|
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:
|
|
94
|
-
baseUrl:
|
|
95
|
-
name:
|
|
96
|
-
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) {
|
|
@@ -200,7 +287,7 @@ async function runApplyCommand(args, env = process.env) {
|
|
|
200
287
|
}
|
|
201
288
|
|
|
202
289
|
// src/commands/domains/list.ts
|
|
203
|
-
async function
|
|
290
|
+
async function runListCommand2(args, env = process.env) {
|
|
204
291
|
const options = parseDomainsCommonArgs(args);
|
|
205
292
|
const apiKey = resolveApiKey(options, env);
|
|
206
293
|
if (!apiKey) {
|
|
@@ -244,15 +331,15 @@ async function runVerifyCommand(args, env = process.env) {
|
|
|
244
331
|
}
|
|
245
332
|
|
|
246
333
|
// src/commands/webhooks/shared.ts
|
|
247
|
-
function
|
|
334
|
+
function readFlag5(args, flag) {
|
|
248
335
|
const index = args.indexOf(flag);
|
|
249
336
|
if (index === -1) return void 0;
|
|
250
337
|
return args[index + 1];
|
|
251
338
|
}
|
|
252
339
|
function parseWebhooksCommonArgs(args) {
|
|
253
340
|
return {
|
|
254
|
-
apiKey:
|
|
255
|
-
baseUrl:
|
|
341
|
+
apiKey: readFlag5(args, "--api-key"),
|
|
342
|
+
baseUrl: readFlag5(args, "--base-url")
|
|
256
343
|
};
|
|
257
344
|
}
|
|
258
345
|
function resolveApiKey2(options, env) {
|
|
@@ -270,7 +357,7 @@ async function runCreateCommand(args, env = process.env) {
|
|
|
270
357
|
if (!apiKey) {
|
|
271
358
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
272
359
|
}
|
|
273
|
-
const url =
|
|
360
|
+
const url = readFlag5(args, "--url");
|
|
274
361
|
if (!url) {
|
|
275
362
|
return { exitCode: 1, error: "Required flag: --url" };
|
|
276
363
|
}
|
|
@@ -291,7 +378,7 @@ async function runDeleteCommand(args, env = process.env) {
|
|
|
291
378
|
if (!apiKey) {
|
|
292
379
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
293
380
|
}
|
|
294
|
-
const id =
|
|
381
|
+
const id = readFlag5(args, "--id");
|
|
295
382
|
if (!id) {
|
|
296
383
|
return { exitCode: 1, error: "Required flag: --id" };
|
|
297
384
|
}
|
|
@@ -306,7 +393,7 @@ async function runDeleteCommand(args, env = process.env) {
|
|
|
306
393
|
}
|
|
307
394
|
|
|
308
395
|
// src/commands/webhooks/list.ts
|
|
309
|
-
async function
|
|
396
|
+
async function runListCommand3(args, env = process.env) {
|
|
310
397
|
const options = parseWebhooksCommonArgs(args);
|
|
311
398
|
const apiKey = resolveApiKey2(options, env);
|
|
312
399
|
if (!apiKey) {
|
|
@@ -322,6 +409,98 @@ async function runListCommand2(args, env = process.env) {
|
|
|
322
409
|
}
|
|
323
410
|
}
|
|
324
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
|
+
|
|
325
504
|
// src/cli.ts
|
|
326
505
|
function printUsage() {
|
|
327
506
|
console.error("Usage:");
|
|
@@ -333,9 +512,14 @@ function printUsage() {
|
|
|
333
512
|
console.error(
|
|
334
513
|
' supersendtx emails send --from you@domain.com --to user@example.com --subject "Hello" --html "<p>Hi</p>"'
|
|
335
514
|
);
|
|
515
|
+
console.error(" supersendtx emails list [--limit 25] [--cursor \u2026]");
|
|
516
|
+
console.error(" supersendtx emails get --id msg_\u2026");
|
|
336
517
|
console.error(" supersendtx webhooks list");
|
|
337
518
|
console.error(" supersendtx webhooks create --url https://yourapp.com/hooks");
|
|
338
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>");
|
|
339
523
|
console.error("");
|
|
340
524
|
console.error("Environment:");
|
|
341
525
|
console.error(" SUPERSENDTX_API_KEY=stx_\u2026");
|
|
@@ -356,7 +540,7 @@ async function main() {
|
|
|
356
540
|
process.exit(result.exitCode);
|
|
357
541
|
}
|
|
358
542
|
if (subcommand === "list") {
|
|
359
|
-
const result = await
|
|
543
|
+
const result = await runListCommand2(rest);
|
|
360
544
|
if (result.error) console.error(result.error);
|
|
361
545
|
process.exit(result.exitCode);
|
|
362
546
|
}
|
|
@@ -366,13 +550,25 @@ async function main() {
|
|
|
366
550
|
process.exit(result.exitCode);
|
|
367
551
|
}
|
|
368
552
|
}
|
|
369
|
-
if (command === "emails"
|
|
370
|
-
|
|
371
|
-
|
|
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
|
+
}
|
|
372
568
|
}
|
|
373
569
|
if (command === "webhooks") {
|
|
374
570
|
if (subcommand === "list") {
|
|
375
|
-
const result = await
|
|
571
|
+
const result = await runListCommand3(rest);
|
|
376
572
|
if (result.error) console.error(result.error);
|
|
377
573
|
process.exit(result.exitCode);
|
|
378
574
|
}
|
|
@@ -387,6 +583,23 @@ async function main() {
|
|
|
387
583
|
process.exit(result.exitCode);
|
|
388
584
|
}
|
|
389
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
|
+
}
|
|
390
603
|
printUsage();
|
|
391
604
|
process.exit(1);
|
|
392
605
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supersendtx-cli",
|
|
3
|
-
"version": "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": "
|
|
42
|
+
"supersendtx": "0.4.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.5.0",
|