supersendtx-cli 0.1.1 → 0.2.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 +201 -12
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -82,21 +82,178 @@ async function runSendCommandWithClient(args, env = process.env) {
|
|
|
82
82
|
return { exitCode };
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// src/commands/
|
|
85
|
+
// src/commands/domains/shared.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
|
-
function
|
|
91
|
+
function parseDomainsCommonArgs(args) {
|
|
92
92
|
return {
|
|
93
93
|
apiKey: readFlag2(args, "--api-key"),
|
|
94
|
-
baseUrl: readFlag2(args, "--base-url")
|
|
94
|
+
baseUrl: readFlag2(args, "--base-url"),
|
|
95
|
+
name: readFlag2(args, "--name") || readFlag2(args, "--domain"),
|
|
96
|
+
id: readFlag2(args, "--id")
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
function resolveApiKey(options, env) {
|
|
98
100
|
return options.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY || null;
|
|
99
101
|
}
|
|
102
|
+
async function createDomainsClient(apiKey, baseUrl) {
|
|
103
|
+
const { SuperSendTX } = await import("supersendtx");
|
|
104
|
+
return new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
105
|
+
}
|
|
106
|
+
function formatDnsRecords(records) {
|
|
107
|
+
const lines = ["DNS records to add:", ""];
|
|
108
|
+
for (const record of records) {
|
|
109
|
+
lines.push(` ${record.type.padEnd(6)} ${record.host}`);
|
|
110
|
+
lines.push(` ${record.value}`);
|
|
111
|
+
lines.push(` (${record.purpose})`);
|
|
112
|
+
lines.push("");
|
|
113
|
+
}
|
|
114
|
+
return lines.join("\n").trimEnd();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/commands/domains/add.ts
|
|
118
|
+
async function runAddCommand(args, env = process.env) {
|
|
119
|
+
const options = parseDomainsCommonArgs(args);
|
|
120
|
+
const apiKey = resolveApiKey(options, env);
|
|
121
|
+
if (!apiKey) {
|
|
122
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
123
|
+
}
|
|
124
|
+
const name = options.name || args.find((arg) => !arg.startsWith("--") && arg.includes("."));
|
|
125
|
+
if (!name) {
|
|
126
|
+
return {
|
|
127
|
+
exitCode: 1,
|
|
128
|
+
error: "Missing domain. Usage: supersendtx domains add example.com"
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const client = await createDomainsClient(apiKey, options.baseUrl);
|
|
133
|
+
const result = await client.domains.create({ name });
|
|
134
|
+
console.log(JSON.stringify(result));
|
|
135
|
+
console.error("");
|
|
136
|
+
console.error(`Domain ${result.domain.name} added (${result.domain.status}).`);
|
|
137
|
+
console.error(formatDnsRecords(result.records));
|
|
138
|
+
console.error("");
|
|
139
|
+
console.error(`Then: supersendtx domains verify ${result.domain.name}`);
|
|
140
|
+
return { exitCode: 0 };
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/commands/domains/apply.ts
|
|
147
|
+
async function runApplyCommand(args, env = process.env) {
|
|
148
|
+
const options = parseDomainsCommonArgs(args);
|
|
149
|
+
const apiKey = resolveApiKey(options, env);
|
|
150
|
+
if (!apiKey) {
|
|
151
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
152
|
+
}
|
|
153
|
+
const providerFlag = args.includes("--provider") ? args[args.indexOf("--provider") + 1] : void 0;
|
|
154
|
+
const provider = (providerFlag || "").toLowerCase();
|
|
155
|
+
if (provider !== "cloudflare" && provider !== "godaddy") {
|
|
156
|
+
return {
|
|
157
|
+
exitCode: 1,
|
|
158
|
+
error: "Missing or invalid --provider. Use --provider cloudflare or --provider godaddy."
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const idOrName = options.id || options.name || args.find((arg, i) => {
|
|
162
|
+
if (arg.startsWith("--")) return false;
|
|
163
|
+
const prev = args[i - 1];
|
|
164
|
+
if (prev === "--provider" || prev === "--api-key" || prev === "--base-url" || prev === "--name" || prev === "--domain" || prev === "--id") {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return arg.includes(".") || arg.length > 8;
|
|
168
|
+
});
|
|
169
|
+
if (!idOrName) {
|
|
170
|
+
return {
|
|
171
|
+
exitCode: 1,
|
|
172
|
+
error: "Missing domain. Usage: supersendtx domains apply example.com --provider cloudflare"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const client = await createDomainsClient(apiKey, options.baseUrl);
|
|
177
|
+
const result = await client.domains.applyDns({
|
|
178
|
+
idOrName,
|
|
179
|
+
provider,
|
|
180
|
+
cloudflareApiToken: env.CLOUDFLARE_API_TOKEN || env.CLOUDFLARE_API_KEY,
|
|
181
|
+
cloudflareZoneId: env.CLOUDFLARE_ZONE_ID,
|
|
182
|
+
godaddyApiKey: env.GODADDY_API_KEY,
|
|
183
|
+
godaddyApiSecret: env.GODADDY_API_SECRET
|
|
184
|
+
});
|
|
185
|
+
console.log(JSON.stringify(result));
|
|
186
|
+
console.error(`Applied ${result.results.length} DNS change(s) via ${result.provider} for ${result.domain}.`);
|
|
187
|
+
for (const row of result.results) {
|
|
188
|
+
console.error(` ${row.action.padEnd(10)} ${row.purpose} \u2192 ${row.host}`);
|
|
189
|
+
}
|
|
190
|
+
console.error("");
|
|
191
|
+
console.error(`Next: supersendtx domains verify ${result.domain}`);
|
|
192
|
+
return { exitCode: 0 };
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/commands/domains/list.ts
|
|
199
|
+
async function runListCommand(args, env = process.env) {
|
|
200
|
+
const options = parseDomainsCommonArgs(args);
|
|
201
|
+
const apiKey = resolveApiKey(options, env);
|
|
202
|
+
if (!apiKey) {
|
|
203
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const client = await createDomainsClient(apiKey, options.baseUrl);
|
|
207
|
+
const result = await client.domains.list();
|
|
208
|
+
console.log(JSON.stringify(result));
|
|
209
|
+
return { exitCode: 0 };
|
|
210
|
+
} catch (error) {
|
|
211
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/commands/domains/verify.ts
|
|
216
|
+
async function runVerifyCommand(args, env = process.env) {
|
|
217
|
+
const options = parseDomainsCommonArgs(args);
|
|
218
|
+
const apiKey = resolveApiKey(options, env);
|
|
219
|
+
if (!apiKey) {
|
|
220
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
221
|
+
}
|
|
222
|
+
const idOrName = options.id || options.name || args.find((arg) => !arg.startsWith("--") && (arg.includes(".") || arg.length > 8));
|
|
223
|
+
if (!idOrName) {
|
|
224
|
+
return {
|
|
225
|
+
exitCode: 1,
|
|
226
|
+
error: "Missing domain. Usage: supersendtx domains verify example.com"
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const client = await createDomainsClient(apiKey, options.baseUrl);
|
|
231
|
+
const result = await client.domains.verify(idOrName);
|
|
232
|
+
console.log(JSON.stringify(result));
|
|
233
|
+
if (result.verified) {
|
|
234
|
+
console.error(`Domain ${result.domain.name} verified.`);
|
|
235
|
+
}
|
|
236
|
+
return { exitCode: 0 };
|
|
237
|
+
} catch (error) {
|
|
238
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/commands/webhooks/shared.ts
|
|
243
|
+
function readFlag3(args, flag) {
|
|
244
|
+
const index = args.indexOf(flag);
|
|
245
|
+
if (index === -1) return void 0;
|
|
246
|
+
return args[index + 1];
|
|
247
|
+
}
|
|
248
|
+
function parseWebhooksCommonArgs(args) {
|
|
249
|
+
return {
|
|
250
|
+
apiKey: readFlag3(args, "--api-key"),
|
|
251
|
+
baseUrl: readFlag3(args, "--base-url")
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function resolveApiKey2(options, env) {
|
|
255
|
+
return options.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY || null;
|
|
256
|
+
}
|
|
100
257
|
async function createWebhooksClient(apiKey, baseUrl) {
|
|
101
258
|
const { SuperSendTX } = await import("supersendtx");
|
|
102
259
|
return new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
@@ -105,11 +262,11 @@ async function createWebhooksClient(apiKey, baseUrl) {
|
|
|
105
262
|
// src/commands/webhooks/create.ts
|
|
106
263
|
async function runCreateCommand(args, env = process.env) {
|
|
107
264
|
const options = parseWebhooksCommonArgs(args);
|
|
108
|
-
const apiKey =
|
|
265
|
+
const apiKey = resolveApiKey2(options, env);
|
|
109
266
|
if (!apiKey) {
|
|
110
267
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
111
268
|
}
|
|
112
|
-
const url =
|
|
269
|
+
const url = readFlag3(args, "--url");
|
|
113
270
|
if (!url) {
|
|
114
271
|
return { exitCode: 1, error: "Required flag: --url" };
|
|
115
272
|
}
|
|
@@ -126,11 +283,11 @@ async function runCreateCommand(args, env = process.env) {
|
|
|
126
283
|
// src/commands/webhooks/delete.ts
|
|
127
284
|
async function runDeleteCommand(args, env = process.env) {
|
|
128
285
|
const options = parseWebhooksCommonArgs(args);
|
|
129
|
-
const apiKey =
|
|
286
|
+
const apiKey = resolveApiKey2(options, env);
|
|
130
287
|
if (!apiKey) {
|
|
131
288
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
132
289
|
}
|
|
133
|
-
const id =
|
|
290
|
+
const id = readFlag3(args, "--id");
|
|
134
291
|
if (!id) {
|
|
135
292
|
return { exitCode: 1, error: "Required flag: --id" };
|
|
136
293
|
}
|
|
@@ -145,9 +302,9 @@ async function runDeleteCommand(args, env = process.env) {
|
|
|
145
302
|
}
|
|
146
303
|
|
|
147
304
|
// src/commands/webhooks/list.ts
|
|
148
|
-
async function
|
|
305
|
+
async function runListCommand2(args, env = process.env) {
|
|
149
306
|
const options = parseWebhooksCommonArgs(args);
|
|
150
|
-
const apiKey =
|
|
307
|
+
const apiKey = resolveApiKey2(options, env);
|
|
151
308
|
if (!apiKey) {
|
|
152
309
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
153
310
|
}
|
|
@@ -164,22 +321,54 @@ async function runListCommand(args, env = process.env) {
|
|
|
164
321
|
// src/cli.ts
|
|
165
322
|
function printUsage() {
|
|
166
323
|
console.error("Usage:");
|
|
167
|
-
console.error(
|
|
324
|
+
console.error(" supersendtx domains add example.com");
|
|
325
|
+
console.error(" supersendtx domains apply example.com --provider cloudflare");
|
|
326
|
+
console.error(" supersendtx domains apply example.com --provider godaddy");
|
|
327
|
+
console.error(" supersendtx domains list");
|
|
328
|
+
console.error(" supersendtx domains verify example.com");
|
|
329
|
+
console.error(
|
|
330
|
+
' supersendtx emails send --from you@domain.com --to user@example.com --subject "Hello" --html "<p>Hi</p>"'
|
|
331
|
+
);
|
|
168
332
|
console.error(" supersendtx webhooks list");
|
|
169
333
|
console.error(" supersendtx webhooks create --url https://yourapp.com/hooks");
|
|
170
334
|
console.error(" supersendtx webhooks delete --id <webhook-id>");
|
|
171
335
|
console.error("");
|
|
172
|
-
console.error("Environment:
|
|
336
|
+
console.error("Environment:");
|
|
337
|
+
console.error(" SUPERSENDTX_API_KEY=stx_\u2026");
|
|
338
|
+
console.error(" CLOUDFLARE_API_TOKEN=\u2026 (domains apply --provider cloudflare)");
|
|
339
|
+
console.error(" GODADDY_API_KEY=\u2026 GODADDY_API_SECRET=\u2026 (domains apply --provider godaddy)");
|
|
173
340
|
}
|
|
174
341
|
async function main() {
|
|
175
342
|
const [, , command, subcommand, ...rest] = process.argv;
|
|
343
|
+
if (command === "domains") {
|
|
344
|
+
if (subcommand === "add" || subcommand === "create") {
|
|
345
|
+
const result = await runAddCommand(rest);
|
|
346
|
+
if (result.error) console.error(result.error);
|
|
347
|
+
process.exit(result.exitCode);
|
|
348
|
+
}
|
|
349
|
+
if (subcommand === "apply") {
|
|
350
|
+
const result = await runApplyCommand(rest);
|
|
351
|
+
if (result.error) console.error(result.error);
|
|
352
|
+
process.exit(result.exitCode);
|
|
353
|
+
}
|
|
354
|
+
if (subcommand === "list") {
|
|
355
|
+
const result = await runListCommand(rest);
|
|
356
|
+
if (result.error) console.error(result.error);
|
|
357
|
+
process.exit(result.exitCode);
|
|
358
|
+
}
|
|
359
|
+
if (subcommand === "verify") {
|
|
360
|
+
const result = await runVerifyCommand(rest);
|
|
361
|
+
if (result.error) console.error(result.error);
|
|
362
|
+
process.exit(result.exitCode);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
176
365
|
if (command === "emails" && subcommand === "send") {
|
|
177
366
|
const result = await runSendCommandWithClient(rest);
|
|
178
367
|
process.exit(result.exitCode);
|
|
179
368
|
}
|
|
180
369
|
if (command === "webhooks") {
|
|
181
370
|
if (subcommand === "list") {
|
|
182
|
-
const result = await
|
|
371
|
+
const result = await runListCommand2(rest);
|
|
183
372
|
if (result.error) console.error(result.error);
|
|
184
373
|
process.exit(result.exitCode);
|
|
185
374
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supersendtx-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.5.0",
|