supersendtx-cli 0.1.0 → 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.d.ts +2 -1
- package/dist/cli.js +201 -13
- package/package.json +2 -2
package/dist/cli.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
export { }
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
#!/usr/bin/env node
|
|
3
2
|
|
|
4
3
|
// src/commands/emails/send.ts
|
|
5
4
|
function readFlag(args, flag) {
|
|
@@ -83,21 +82,178 @@ async function runSendCommandWithClient(args, env = process.env) {
|
|
|
83
82
|
return { exitCode };
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
// src/commands/
|
|
85
|
+
// src/commands/domains/shared.ts
|
|
87
86
|
function readFlag2(args, flag) {
|
|
88
87
|
const index = args.indexOf(flag);
|
|
89
88
|
if (index === -1) return void 0;
|
|
90
89
|
return args[index + 1];
|
|
91
90
|
}
|
|
92
|
-
function
|
|
91
|
+
function parseDomainsCommonArgs(args) {
|
|
93
92
|
return {
|
|
94
93
|
apiKey: readFlag2(args, "--api-key"),
|
|
95
|
-
baseUrl: readFlag2(args, "--base-url")
|
|
94
|
+
baseUrl: readFlag2(args, "--base-url"),
|
|
95
|
+
name: readFlag2(args, "--name") || readFlag2(args, "--domain"),
|
|
96
|
+
id: readFlag2(args, "--id")
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
function resolveApiKey(options, env) {
|
|
99
100
|
return options.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY || null;
|
|
100
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
|
+
}
|
|
101
257
|
async function createWebhooksClient(apiKey, baseUrl) {
|
|
102
258
|
const { SuperSendTX } = await import("supersendtx");
|
|
103
259
|
return new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
@@ -106,11 +262,11 @@ async function createWebhooksClient(apiKey, baseUrl) {
|
|
|
106
262
|
// src/commands/webhooks/create.ts
|
|
107
263
|
async function runCreateCommand(args, env = process.env) {
|
|
108
264
|
const options = parseWebhooksCommonArgs(args);
|
|
109
|
-
const apiKey =
|
|
265
|
+
const apiKey = resolveApiKey2(options, env);
|
|
110
266
|
if (!apiKey) {
|
|
111
267
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
112
268
|
}
|
|
113
|
-
const url =
|
|
269
|
+
const url = readFlag3(args, "--url");
|
|
114
270
|
if (!url) {
|
|
115
271
|
return { exitCode: 1, error: "Required flag: --url" };
|
|
116
272
|
}
|
|
@@ -127,11 +283,11 @@ async function runCreateCommand(args, env = process.env) {
|
|
|
127
283
|
// src/commands/webhooks/delete.ts
|
|
128
284
|
async function runDeleteCommand(args, env = process.env) {
|
|
129
285
|
const options = parseWebhooksCommonArgs(args);
|
|
130
|
-
const apiKey =
|
|
286
|
+
const apiKey = resolveApiKey2(options, env);
|
|
131
287
|
if (!apiKey) {
|
|
132
288
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
133
289
|
}
|
|
134
|
-
const id =
|
|
290
|
+
const id = readFlag3(args, "--id");
|
|
135
291
|
if (!id) {
|
|
136
292
|
return { exitCode: 1, error: "Required flag: --id" };
|
|
137
293
|
}
|
|
@@ -146,9 +302,9 @@ async function runDeleteCommand(args, env = process.env) {
|
|
|
146
302
|
}
|
|
147
303
|
|
|
148
304
|
// src/commands/webhooks/list.ts
|
|
149
|
-
async function
|
|
305
|
+
async function runListCommand2(args, env = process.env) {
|
|
150
306
|
const options = parseWebhooksCommonArgs(args);
|
|
151
|
-
const apiKey =
|
|
307
|
+
const apiKey = resolveApiKey2(options, env);
|
|
152
308
|
if (!apiKey) {
|
|
153
309
|
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
154
310
|
}
|
|
@@ -165,22 +321,54 @@ async function runListCommand(args, env = process.env) {
|
|
|
165
321
|
// src/cli.ts
|
|
166
322
|
function printUsage() {
|
|
167
323
|
console.error("Usage:");
|
|
168
|
-
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
|
+
);
|
|
169
332
|
console.error(" supersendtx webhooks list");
|
|
170
333
|
console.error(" supersendtx webhooks create --url https://yourapp.com/hooks");
|
|
171
334
|
console.error(" supersendtx webhooks delete --id <webhook-id>");
|
|
172
335
|
console.error("");
|
|
173
|
-
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)");
|
|
174
340
|
}
|
|
175
341
|
async function main() {
|
|
176
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
|
+
}
|
|
177
365
|
if (command === "emails" && subcommand === "send") {
|
|
178
366
|
const result = await runSendCommandWithClient(rest);
|
|
179
367
|
process.exit(result.exitCode);
|
|
180
368
|
}
|
|
181
369
|
if (command === "webhooks") {
|
|
182
370
|
if (subcommand === "list") {
|
|
183
|
-
const result = await
|
|
371
|
+
const result = await runListCommand2(rest);
|
|
184
372
|
if (result.error) console.error(result.error);
|
|
185
373
|
process.exit(result.exitCode);
|
|
186
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",
|