supersendtx-cli 0.4.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 +229 -36
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -6,13 +6,39 @@ function readFlag(args, flag) {
|
|
|
6
6
|
if (index === -1) return void 0;
|
|
7
7
|
return args[index + 1];
|
|
8
8
|
}
|
|
9
|
+
function readFlags(args, flag) {
|
|
10
|
+
const values = [];
|
|
11
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
12
|
+
if (args[index] === flag && args[index + 1]) values.push(args[index + 1]);
|
|
13
|
+
}
|
|
14
|
+
return values;
|
|
15
|
+
}
|
|
16
|
+
function parseTags(values) {
|
|
17
|
+
const tags = values.map((value) => {
|
|
18
|
+
const separator = value.indexOf("=");
|
|
19
|
+
if (separator <= 0) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const name = value.slice(0, separator).trim();
|
|
23
|
+
const tagValue = value.slice(separator + 1).trim();
|
|
24
|
+
if (!name || !tagValue) return null;
|
|
25
|
+
return { name, value: tagValue };
|
|
26
|
+
});
|
|
27
|
+
if (tags.some((tag) => tag == null)) {
|
|
28
|
+
return { error: "--tag must be in name=value format" };
|
|
29
|
+
}
|
|
30
|
+
return tags;
|
|
31
|
+
}
|
|
9
32
|
function parseSendCommandArgs(args) {
|
|
33
|
+
const parsedTags = parseTags(readFlags(args, "--tag"));
|
|
10
34
|
return {
|
|
11
35
|
from: readFlag(args, "--from"),
|
|
12
36
|
to: readFlag(args, "--to"),
|
|
13
37
|
subject: readFlag(args, "--subject"),
|
|
14
38
|
html: readFlag(args, "--html"),
|
|
15
39
|
text: readFlag(args, "--text"),
|
|
40
|
+
tags: Array.isArray(parsedTags) ? parsedTags : void 0,
|
|
41
|
+
scheduledAt: readFlag(args, "--schedule"),
|
|
16
42
|
apiKey: readFlag(args, "--api-key"),
|
|
17
43
|
baseUrl: readFlag(args, "--base-url")
|
|
18
44
|
};
|
|
@@ -32,7 +58,9 @@ async function runSendCommand(args, deps) {
|
|
|
32
58
|
to: options.to,
|
|
33
59
|
subject: options.subject,
|
|
34
60
|
html: options.html,
|
|
35
|
-
text: options.text
|
|
61
|
+
text: options.text,
|
|
62
|
+
tags: options.tags,
|
|
63
|
+
scheduledAt: options.scheduledAt
|
|
36
64
|
});
|
|
37
65
|
stdout(JSON.stringify(result));
|
|
38
66
|
return 0;
|
|
@@ -44,9 +72,13 @@ async function runSendCommand(args, deps) {
|
|
|
44
72
|
function parseSendCommandOptions(args, env) {
|
|
45
73
|
const parsed = parseSendCommandArgs(args);
|
|
46
74
|
const apiKey = parsed.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
75
|
+
const parsedTags = parseTags(readFlags(args, "--tag"));
|
|
47
76
|
if (!apiKey) {
|
|
48
77
|
return { error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
49
78
|
}
|
|
79
|
+
if ("error" in parsedTags) {
|
|
80
|
+
return { error: parsedTags.error };
|
|
81
|
+
}
|
|
50
82
|
if (!parsed.from || !parsed.to || !parsed.subject) {
|
|
51
83
|
return { error: "Required flags: --from --to --subject (and --html or --text)" };
|
|
52
84
|
}
|
|
@@ -59,6 +91,8 @@ function parseSendCommandOptions(args, env) {
|
|
|
59
91
|
subject: parsed.subject,
|
|
60
92
|
html: parsed.html,
|
|
61
93
|
text: parsed.text,
|
|
94
|
+
tags: parsedTags.length ? parsedTags : void 0,
|
|
95
|
+
scheduledAt: parsed.scheduledAt,
|
|
62
96
|
apiKey,
|
|
63
97
|
baseUrl: parsed.baseUrl
|
|
64
98
|
};
|
|
@@ -82,18 +116,18 @@ async function runSendCommandWithClient(args, env = process.env) {
|
|
|
82
116
|
return { exitCode };
|
|
83
117
|
}
|
|
84
118
|
|
|
85
|
-
// src/commands/emails/
|
|
119
|
+
// src/commands/emails/cancel.ts
|
|
86
120
|
function readFlag2(args, flag) {
|
|
87
121
|
const index = args.indexOf(flag);
|
|
88
122
|
if (index === -1) return void 0;
|
|
89
123
|
return args[index + 1];
|
|
90
124
|
}
|
|
91
|
-
async function
|
|
125
|
+
async function runCancelCommand(args, deps) {
|
|
92
126
|
const env = deps.env ?? process.env;
|
|
93
127
|
const stdout = deps.stdout ?? ((line) => console.log(line));
|
|
94
128
|
const stderr = deps.stderr ?? ((line) => console.error(line));
|
|
95
|
-
const id = readFlag2(args, "--id") || args.find((a) => !a.startsWith("--"));
|
|
96
129
|
const apiKey = readFlag2(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
130
|
+
const id = readFlag2(args, "--id") || args.find((arg) => !arg.startsWith("--"));
|
|
97
131
|
if (!apiKey) {
|
|
98
132
|
stderr("Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key.");
|
|
99
133
|
return { exitCode: 1, error: "missing key" };
|
|
@@ -103,7 +137,7 @@ async function runGetCommand(args, deps) {
|
|
|
103
137
|
return { exitCode: 1, error: "missing id" };
|
|
104
138
|
}
|
|
105
139
|
try {
|
|
106
|
-
const result = await deps.
|
|
140
|
+
const result = await deps.cancelEmail(id);
|
|
107
141
|
stdout(JSON.stringify(result));
|
|
108
142
|
return { exitCode: 0 };
|
|
109
143
|
} catch (error) {
|
|
@@ -111,7 +145,7 @@ async function runGetCommand(args, deps) {
|
|
|
111
145
|
return { exitCode: 1, error: String(error) };
|
|
112
146
|
}
|
|
113
147
|
}
|
|
114
|
-
async function
|
|
148
|
+
async function runCancelCommandWithClient(args, env = process.env) {
|
|
115
149
|
const apiKey = readFlag2(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
116
150
|
const baseUrl = readFlag2(args, "--base-url");
|
|
117
151
|
if (!apiKey) {
|
|
@@ -119,6 +153,49 @@ async function runGetCommandWithClient(args, env = process.env) {
|
|
|
119
153
|
}
|
|
120
154
|
const { SuperSendTX } = await import("supersendtx");
|
|
121
155
|
const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
156
|
+
return runCancelCommand(args, {
|
|
157
|
+
env,
|
|
158
|
+
cancelEmail: (id) => client.emails.cancel(id)
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/commands/emails/get.ts
|
|
163
|
+
function readFlag3(args, flag) {
|
|
164
|
+
const index = args.indexOf(flag);
|
|
165
|
+
if (index === -1) return void 0;
|
|
166
|
+
return args[index + 1];
|
|
167
|
+
}
|
|
168
|
+
async function runGetCommand(args, deps) {
|
|
169
|
+
const env = deps.env ?? process.env;
|
|
170
|
+
const stdout = deps.stdout ?? ((line) => console.log(line));
|
|
171
|
+
const stderr = deps.stderr ?? ((line) => console.error(line));
|
|
172
|
+
const id = readFlag3(args, "--id") || args.find((a) => !a.startsWith("--"));
|
|
173
|
+
const apiKey = readFlag3(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
174
|
+
if (!apiKey) {
|
|
175
|
+
stderr("Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key.");
|
|
176
|
+
return { exitCode: 1, error: "missing key" };
|
|
177
|
+
}
|
|
178
|
+
if (!id) {
|
|
179
|
+
stderr("Required: --id <msg_\u2026>");
|
|
180
|
+
return { exitCode: 1, error: "missing id" };
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const result = await deps.getEmail(id);
|
|
184
|
+
stdout(JSON.stringify(result));
|
|
185
|
+
return { exitCode: 0 };
|
|
186
|
+
} catch (error) {
|
|
187
|
+
stderr(error instanceof Error ? error.message : String(error));
|
|
188
|
+
return { exitCode: 1, error: String(error) };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function runGetCommandWithClient(args, env = process.env) {
|
|
192
|
+
const apiKey = readFlag3(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
193
|
+
const baseUrl = readFlag3(args, "--base-url");
|
|
194
|
+
if (!apiKey) {
|
|
195
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
196
|
+
}
|
|
197
|
+
const { SuperSendTX } = await import("supersendtx");
|
|
198
|
+
const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
122
199
|
return runGetCommand(args, {
|
|
123
200
|
env,
|
|
124
201
|
getEmail: (id) => client.emails.get(id)
|
|
@@ -126,7 +203,7 @@ async function runGetCommandWithClient(args, env = process.env) {
|
|
|
126
203
|
}
|
|
127
204
|
|
|
128
205
|
// src/commands/emails/list.ts
|
|
129
|
-
function
|
|
206
|
+
function readFlag4(args, flag) {
|
|
130
207
|
const index = args.indexOf(flag);
|
|
131
208
|
if (index === -1) return void 0;
|
|
132
209
|
return args[index + 1];
|
|
@@ -135,13 +212,13 @@ async function runListCommand(args, deps) {
|
|
|
135
212
|
const env = deps.env ?? process.env;
|
|
136
213
|
const stdout = deps.stdout ?? ((line) => console.log(line));
|
|
137
214
|
const stderr = deps.stderr ?? ((line) => console.error(line));
|
|
138
|
-
const apiKey =
|
|
215
|
+
const apiKey = readFlag4(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
139
216
|
if (!apiKey) {
|
|
140
217
|
stderr("Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key.");
|
|
141
218
|
return { exitCode: 1, error: "missing key" };
|
|
142
219
|
}
|
|
143
|
-
const limitRaw =
|
|
144
|
-
const cursor =
|
|
220
|
+
const limitRaw = readFlag4(args, "--limit");
|
|
221
|
+
const cursor = readFlag4(args, "--cursor");
|
|
145
222
|
const limit = limitRaw ? Number(limitRaw) : void 0;
|
|
146
223
|
try {
|
|
147
224
|
const result = await deps.listEmails({
|
|
@@ -156,8 +233,8 @@ async function runListCommand(args, deps) {
|
|
|
156
233
|
}
|
|
157
234
|
}
|
|
158
235
|
async function runListCommandWithClient(args, env = process.env) {
|
|
159
|
-
const apiKey =
|
|
160
|
-
const baseUrl =
|
|
236
|
+
const apiKey = readFlag4(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
237
|
+
const baseUrl = readFlag4(args, "--base-url");
|
|
161
238
|
if (!apiKey) {
|
|
162
239
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
163
240
|
}
|
|
@@ -170,17 +247,17 @@ async function runListCommandWithClient(args, env = process.env) {
|
|
|
170
247
|
}
|
|
171
248
|
|
|
172
249
|
// src/commands/domains/shared.ts
|
|
173
|
-
function
|
|
250
|
+
function readFlag5(args, flag) {
|
|
174
251
|
const index = args.indexOf(flag);
|
|
175
252
|
if (index === -1) return void 0;
|
|
176
253
|
return args[index + 1];
|
|
177
254
|
}
|
|
178
255
|
function parseDomainsCommonArgs(args) {
|
|
179
256
|
return {
|
|
180
|
-
apiKey:
|
|
181
|
-
baseUrl:
|
|
182
|
-
name:
|
|
183
|
-
id:
|
|
257
|
+
apiKey: readFlag5(args, "--api-key"),
|
|
258
|
+
baseUrl: readFlag5(args, "--base-url"),
|
|
259
|
+
name: readFlag5(args, "--name") || readFlag5(args, "--domain"),
|
|
260
|
+
id: readFlag5(args, "--id")
|
|
184
261
|
};
|
|
185
262
|
}
|
|
186
263
|
function resolveApiKey(options, env) {
|
|
@@ -331,15 +408,15 @@ async function runVerifyCommand(args, env = process.env) {
|
|
|
331
408
|
}
|
|
332
409
|
|
|
333
410
|
// src/commands/webhooks/shared.ts
|
|
334
|
-
function
|
|
411
|
+
function readFlag6(args, flag) {
|
|
335
412
|
const index = args.indexOf(flag);
|
|
336
413
|
if (index === -1) return void 0;
|
|
337
414
|
return args[index + 1];
|
|
338
415
|
}
|
|
339
416
|
function parseWebhooksCommonArgs(args) {
|
|
340
417
|
return {
|
|
341
|
-
apiKey:
|
|
342
|
-
baseUrl:
|
|
418
|
+
apiKey: readFlag6(args, "--api-key"),
|
|
419
|
+
baseUrl: readFlag6(args, "--base-url")
|
|
343
420
|
};
|
|
344
421
|
}
|
|
345
422
|
function resolveApiKey2(options, env) {
|
|
@@ -357,7 +434,7 @@ async function runCreateCommand(args, env = process.env) {
|
|
|
357
434
|
if (!apiKey) {
|
|
358
435
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
359
436
|
}
|
|
360
|
-
const url =
|
|
437
|
+
const url = readFlag6(args, "--url");
|
|
361
438
|
if (!url) {
|
|
362
439
|
return { exitCode: 1, error: "Required flag: --url" };
|
|
363
440
|
}
|
|
@@ -378,7 +455,7 @@ async function runDeleteCommand(args, env = process.env) {
|
|
|
378
455
|
if (!apiKey) {
|
|
379
456
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
380
457
|
}
|
|
381
|
-
const id =
|
|
458
|
+
const id = readFlag6(args, "--id");
|
|
382
459
|
if (!id) {
|
|
383
460
|
return { exitCode: 1, error: "Required flag: --id" };
|
|
384
461
|
}
|
|
@@ -410,22 +487,22 @@ async function runListCommand3(args, env = process.env) {
|
|
|
410
487
|
}
|
|
411
488
|
|
|
412
489
|
// src/commands/keys/list.ts
|
|
413
|
-
function
|
|
490
|
+
function readFlag7(args, flag) {
|
|
414
491
|
const index = args.indexOf(flag);
|
|
415
492
|
if (index === -1) return void 0;
|
|
416
493
|
return args[index + 1];
|
|
417
494
|
}
|
|
418
495
|
async function runListKeysCommandWithClient(args, env = process.env) {
|
|
419
|
-
const apiKey =
|
|
420
|
-
const baseUrl =
|
|
496
|
+
const apiKey = readFlag7(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
497
|
+
const baseUrl = readFlag7(args, "--base-url");
|
|
421
498
|
if (!apiKey) {
|
|
422
499
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
423
500
|
}
|
|
424
501
|
const { SuperSendTX } = await import("supersendtx");
|
|
425
502
|
const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
426
503
|
try {
|
|
427
|
-
const limitRaw =
|
|
428
|
-
const cursor =
|
|
504
|
+
const limitRaw = readFlag7(args, "--limit");
|
|
505
|
+
const cursor = readFlag7(args, "--cursor");
|
|
429
506
|
const result = await client.apiKeys.list({
|
|
430
507
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
431
508
|
...cursor ? { cursor } : {}
|
|
@@ -440,19 +517,19 @@ async function runListKeysCommandWithClient(args, env = process.env) {
|
|
|
440
517
|
}
|
|
441
518
|
|
|
442
519
|
// src/commands/keys/create.ts
|
|
443
|
-
function
|
|
520
|
+
function readFlag8(args, flag) {
|
|
444
521
|
const index = args.indexOf(flag);
|
|
445
522
|
if (index === -1) return void 0;
|
|
446
523
|
return args[index + 1];
|
|
447
524
|
}
|
|
448
525
|
async function runCreateKeyCommandWithClient(args, env = process.env) {
|
|
449
|
-
const apiKey =
|
|
450
|
-
const baseUrl =
|
|
526
|
+
const apiKey = readFlag8(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
527
|
+
const baseUrl = readFlag8(args, "--base-url");
|
|
451
528
|
if (!apiKey) {
|
|
452
529
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
453
530
|
}
|
|
454
|
-
const name =
|
|
455
|
-
const scope =
|
|
531
|
+
const name = readFlag8(args, "--name");
|
|
532
|
+
const scope = readFlag8(args, "--scope");
|
|
456
533
|
if (scope && scope !== "full" && scope !== "sending") {
|
|
457
534
|
return { exitCode: 1, error: "--scope must be full or sending" };
|
|
458
535
|
}
|
|
@@ -473,15 +550,15 @@ async function runCreateKeyCommandWithClient(args, env = process.env) {
|
|
|
473
550
|
}
|
|
474
551
|
|
|
475
552
|
// src/commands/keys/delete.ts
|
|
476
|
-
function
|
|
553
|
+
function readFlag9(args, flag) {
|
|
477
554
|
const index = args.indexOf(flag);
|
|
478
555
|
if (index === -1) return void 0;
|
|
479
556
|
return args[index + 1];
|
|
480
557
|
}
|
|
481
558
|
async function runDeleteKeyCommandWithClient(args, env = process.env) {
|
|
482
|
-
const apiKey =
|
|
483
|
-
const baseUrl =
|
|
484
|
-
const id =
|
|
559
|
+
const apiKey = readFlag9(args, "--api-key") || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
560
|
+
const baseUrl = readFlag9(args, "--base-url");
|
|
561
|
+
const id = readFlag9(args, "--id");
|
|
485
562
|
if (!apiKey) {
|
|
486
563
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
487
564
|
}
|
|
@@ -501,6 +578,96 @@ async function runDeleteKeyCommandWithClient(args, env = process.env) {
|
|
|
501
578
|
}
|
|
502
579
|
}
|
|
503
580
|
|
|
581
|
+
// src/commands/suppressions/shared.ts
|
|
582
|
+
function readFlag10(args, flag) {
|
|
583
|
+
const index = args.indexOf(flag);
|
|
584
|
+
if (index === -1) return void 0;
|
|
585
|
+
return args[index + 1];
|
|
586
|
+
}
|
|
587
|
+
function parseSuppressionsCommonArgs(args) {
|
|
588
|
+
return {
|
|
589
|
+
apiKey: readFlag10(args, "--api-key"),
|
|
590
|
+
baseUrl: readFlag10(args, "--base-url")
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function resolveApiKey3(options, env) {
|
|
594
|
+
return options.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY || null;
|
|
595
|
+
}
|
|
596
|
+
async function createSuppressionsClient(apiKey, baseUrl) {
|
|
597
|
+
const { SuperSendTX } = await import("supersendtx");
|
|
598
|
+
return new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/commands/suppressions/list.ts
|
|
602
|
+
async function runListCommand4(args, env = process.env) {
|
|
603
|
+
const options = parseSuppressionsCommonArgs(args);
|
|
604
|
+
const apiKey = resolveApiKey3(options, env);
|
|
605
|
+
if (!apiKey) {
|
|
606
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
const client = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
610
|
+
const limitRaw = readFlag10(args, "--limit");
|
|
611
|
+
const cursor = readFlag10(args, "--cursor");
|
|
612
|
+
const email = readFlag10(args, "--email");
|
|
613
|
+
const result = await client.suppressions.list({
|
|
614
|
+
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
615
|
+
...cursor ? { cursor } : {},
|
|
616
|
+
...email ? { email } : {}
|
|
617
|
+
});
|
|
618
|
+
console.log(JSON.stringify(result));
|
|
619
|
+
return { exitCode: 0 };
|
|
620
|
+
} catch (error) {
|
|
621
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/commands/suppressions/add.ts
|
|
626
|
+
async function runAddCommand2(args, env = process.env) {
|
|
627
|
+
const options = parseSuppressionsCommonArgs(args);
|
|
628
|
+
const apiKey = resolveApiKey3(options, env);
|
|
629
|
+
if (!apiKey) {
|
|
630
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
631
|
+
}
|
|
632
|
+
const email = readFlag10(args, "--email") || args.find((a) => a.includes("@") && !a.startsWith("-"));
|
|
633
|
+
if (!email) {
|
|
634
|
+
return { exitCode: 1, error: "Missing email. Pass --email user@example.com" };
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
const client = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
638
|
+
const reason = readFlag10(args, "--reason");
|
|
639
|
+
const result = await client.suppressions.create({
|
|
640
|
+
email,
|
|
641
|
+
...reason ? { reason } : {}
|
|
642
|
+
});
|
|
643
|
+
console.log(JSON.stringify(result));
|
|
644
|
+
return { exitCode: 0 };
|
|
645
|
+
} catch (error) {
|
|
646
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/commands/suppressions/remove.ts
|
|
651
|
+
async function runRemoveCommand(args, env = process.env) {
|
|
652
|
+
const options = parseSuppressionsCommonArgs(args);
|
|
653
|
+
const apiKey = resolveApiKey3(options, env);
|
|
654
|
+
if (!apiKey) {
|
|
655
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
656
|
+
}
|
|
657
|
+
const idOrEmail = readFlag10(args, "--id") || readFlag10(args, "--email") || args.find((a) => !a.startsWith("-") && a !== "remove" && a !== "delete");
|
|
658
|
+
if (!idOrEmail) {
|
|
659
|
+
return { exitCode: 1, error: "Missing id or email. Pass --id <uuid> or --email user@example.com" };
|
|
660
|
+
}
|
|
661
|
+
try {
|
|
662
|
+
const client = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
663
|
+
const result = await client.suppressions.remove(idOrEmail);
|
|
664
|
+
console.log(JSON.stringify(result));
|
|
665
|
+
return { exitCode: 0 };
|
|
666
|
+
} catch (error) {
|
|
667
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
504
671
|
// src/cli.ts
|
|
505
672
|
function printUsage() {
|
|
506
673
|
console.error("Usage:");
|
|
@@ -514,9 +681,13 @@ function printUsage() {
|
|
|
514
681
|
);
|
|
515
682
|
console.error(" supersendtx emails list [--limit 25] [--cursor \u2026]");
|
|
516
683
|
console.error(" supersendtx emails get --id msg_\u2026");
|
|
684
|
+
console.error(" supersendtx emails cancel --id msg_\u2026");
|
|
517
685
|
console.error(" supersendtx webhooks list");
|
|
518
686
|
console.error(" supersendtx webhooks create --url https://yourapp.com/hooks");
|
|
519
687
|
console.error(" supersendtx webhooks delete --id <webhook-id>");
|
|
688
|
+
console.error(" supersendtx suppressions list");
|
|
689
|
+
console.error(" supersendtx suppressions add --email user@example.com [--reason \u2026]");
|
|
690
|
+
console.error(" supersendtx suppressions remove --id <id> | --email user@example.com");
|
|
520
691
|
console.error(" supersendtx keys list");
|
|
521
692
|
console.error(" supersendtx keys create [--name Default] [--scope full|sending]");
|
|
522
693
|
console.error(" supersendtx keys delete --id <api-key-id>");
|
|
@@ -555,6 +726,11 @@ async function main() {
|
|
|
555
726
|
const result = await runSendCommandWithClient(rest);
|
|
556
727
|
process.exit(result.exitCode);
|
|
557
728
|
}
|
|
729
|
+
if (subcommand === "cancel") {
|
|
730
|
+
const result = await runCancelCommandWithClient(rest);
|
|
731
|
+
if (result.error) console.error(result.error);
|
|
732
|
+
process.exit(result.exitCode);
|
|
733
|
+
}
|
|
558
734
|
if (subcommand === "list") {
|
|
559
735
|
const result = await runListCommandWithClient(rest);
|
|
560
736
|
if (result.error) console.error(result.error);
|
|
@@ -583,6 +759,23 @@ async function main() {
|
|
|
583
759
|
process.exit(result.exitCode);
|
|
584
760
|
}
|
|
585
761
|
}
|
|
762
|
+
if (command === "suppressions") {
|
|
763
|
+
if (subcommand === "list") {
|
|
764
|
+
const result = await runListCommand4(rest);
|
|
765
|
+
if (result.error) console.error(result.error);
|
|
766
|
+
process.exit(result.exitCode);
|
|
767
|
+
}
|
|
768
|
+
if (subcommand === "add" || subcommand === "create") {
|
|
769
|
+
const result = await runAddCommand2(rest);
|
|
770
|
+
if (result.error) console.error(result.error);
|
|
771
|
+
process.exit(result.exitCode);
|
|
772
|
+
}
|
|
773
|
+
if (subcommand === "remove" || subcommand === "delete") {
|
|
774
|
+
const result = await runRemoveCommand(rest);
|
|
775
|
+
if (result.error) console.error(result.error);
|
|
776
|
+
process.exit(result.exitCode);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
586
779
|
if (command === "keys") {
|
|
587
780
|
if (subcommand === "list") {
|
|
588
781
|
const result = await runListKeysCommandWithClient(rest);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supersendtx-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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.
|
|
42
|
+
"supersendtx": "0.6.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.5.0",
|