supersendtx-cli 0.1.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 +1 -0
- package/dist/cli.js +204 -0
- package/package.json +49 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
#!/usr/bin/env node
|
|
3
|
+
|
|
4
|
+
// src/commands/emails/send.ts
|
|
5
|
+
function readFlag(args, flag) {
|
|
6
|
+
const index = args.indexOf(flag);
|
|
7
|
+
if (index === -1) return void 0;
|
|
8
|
+
return args[index + 1];
|
|
9
|
+
}
|
|
10
|
+
function parseSendCommandArgs(args) {
|
|
11
|
+
return {
|
|
12
|
+
from: readFlag(args, "--from"),
|
|
13
|
+
to: readFlag(args, "--to"),
|
|
14
|
+
subject: readFlag(args, "--subject"),
|
|
15
|
+
html: readFlag(args, "--html"),
|
|
16
|
+
text: readFlag(args, "--text"),
|
|
17
|
+
apiKey: readFlag(args, "--api-key"),
|
|
18
|
+
baseUrl: readFlag(args, "--base-url")
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function runSendCommand(args, deps) {
|
|
22
|
+
const env = deps.env ?? process.env;
|
|
23
|
+
const stdout = deps.stdout ?? ((line) => console.log(line));
|
|
24
|
+
const stderr = deps.stderr ?? ((line) => console.error(line));
|
|
25
|
+
const options = parseSendCommandOptions(args, env);
|
|
26
|
+
if ("error" in options) {
|
|
27
|
+
stderr(options.error);
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const result = await deps.sendEmail({
|
|
32
|
+
from: options.from,
|
|
33
|
+
to: options.to,
|
|
34
|
+
subject: options.subject,
|
|
35
|
+
html: options.html,
|
|
36
|
+
text: options.text
|
|
37
|
+
});
|
|
38
|
+
stdout(JSON.stringify(result));
|
|
39
|
+
return 0;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
stderr(error instanceof Error ? error.message : String(error));
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function parseSendCommandOptions(args, env) {
|
|
46
|
+
const parsed = parseSendCommandArgs(args);
|
|
47
|
+
const apiKey = parsed.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY;
|
|
48
|
+
if (!apiKey) {
|
|
49
|
+
return { error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
50
|
+
}
|
|
51
|
+
if (!parsed.from || !parsed.to || !parsed.subject) {
|
|
52
|
+
return { error: "Required flags: --from --to --subject (and --html or --text)" };
|
|
53
|
+
}
|
|
54
|
+
if (!parsed.html && !parsed.text) {
|
|
55
|
+
return { error: "Provide --html or --text" };
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
from: parsed.from,
|
|
59
|
+
to: parsed.to,
|
|
60
|
+
subject: parsed.subject,
|
|
61
|
+
html: parsed.html,
|
|
62
|
+
text: parsed.text,
|
|
63
|
+
apiKey,
|
|
64
|
+
baseUrl: parsed.baseUrl
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function createDefaultSendDeps(apiKey, baseUrl) {
|
|
68
|
+
return {
|
|
69
|
+
sendEmail: async (params) => {
|
|
70
|
+
const { SuperSendTX } = await import("supersendtx");
|
|
71
|
+
const client = new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
72
|
+
return client.emails.send(params);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async function runSendCommandWithClient(args, env = process.env) {
|
|
77
|
+
const parsed = parseSendCommandOptions(args, env);
|
|
78
|
+
if ("error" in parsed) {
|
|
79
|
+
return { exitCode: 1, error: parsed.error };
|
|
80
|
+
}
|
|
81
|
+
const deps = createDefaultSendDeps(parsed.apiKey, parsed.baseUrl);
|
|
82
|
+
const exitCode = await runSendCommand(args, { ...deps, env });
|
|
83
|
+
return { exitCode };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/commands/webhooks/shared.ts
|
|
87
|
+
function readFlag2(args, flag) {
|
|
88
|
+
const index = args.indexOf(flag);
|
|
89
|
+
if (index === -1) return void 0;
|
|
90
|
+
return args[index + 1];
|
|
91
|
+
}
|
|
92
|
+
function parseWebhooksCommonArgs(args) {
|
|
93
|
+
return {
|
|
94
|
+
apiKey: readFlag2(args, "--api-key"),
|
|
95
|
+
baseUrl: readFlag2(args, "--base-url")
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function resolveApiKey(options, env) {
|
|
99
|
+
return options.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY || null;
|
|
100
|
+
}
|
|
101
|
+
async function createWebhooksClient(apiKey, baseUrl) {
|
|
102
|
+
const { SuperSendTX } = await import("supersendtx");
|
|
103
|
+
return new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/commands/webhooks/create.ts
|
|
107
|
+
async function runCreateCommand(args, env = process.env) {
|
|
108
|
+
const options = parseWebhooksCommonArgs(args);
|
|
109
|
+
const apiKey = resolveApiKey(options, env);
|
|
110
|
+
if (!apiKey) {
|
|
111
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
112
|
+
}
|
|
113
|
+
const url = readFlag2(args, "--url");
|
|
114
|
+
if (!url) {
|
|
115
|
+
return { exitCode: 1, error: "Required flag: --url" };
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const client = await createWebhooksClient(apiKey, options.baseUrl);
|
|
119
|
+
const result = await client.webhooks.create({ url });
|
|
120
|
+
console.log(JSON.stringify(result));
|
|
121
|
+
return { exitCode: 0 };
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/commands/webhooks/delete.ts
|
|
128
|
+
async function runDeleteCommand(args, env = process.env) {
|
|
129
|
+
const options = parseWebhooksCommonArgs(args);
|
|
130
|
+
const apiKey = resolveApiKey(options, env);
|
|
131
|
+
if (!apiKey) {
|
|
132
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
133
|
+
}
|
|
134
|
+
const id = readFlag2(args, "--id");
|
|
135
|
+
if (!id) {
|
|
136
|
+
return { exitCode: 1, error: "Required flag: --id" };
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const client = await createWebhooksClient(apiKey, options.baseUrl);
|
|
140
|
+
const result = await client.webhooks.delete(id);
|
|
141
|
+
console.log(JSON.stringify(result));
|
|
142
|
+
return { exitCode: 0 };
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/commands/webhooks/list.ts
|
|
149
|
+
async function runListCommand(args, env = process.env) {
|
|
150
|
+
const options = parseWebhooksCommonArgs(args);
|
|
151
|
+
const apiKey = resolveApiKey(options, env);
|
|
152
|
+
if (!apiKey) {
|
|
153
|
+
return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const client = await createWebhooksClient(apiKey, options.baseUrl);
|
|
157
|
+
const result = await client.webhooks.list();
|
|
158
|
+
console.log(JSON.stringify(result));
|
|
159
|
+
return { exitCode: 0 };
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/cli.ts
|
|
166
|
+
function printUsage() {
|
|
167
|
+
console.error("Usage:");
|
|
168
|
+
console.error(' supersendtx emails send --from you@domain.com --to user@example.com --subject "Hello" --html "<p>Hi</p>"');
|
|
169
|
+
console.error(" supersendtx webhooks list");
|
|
170
|
+
console.error(" supersendtx webhooks create --url https://yourapp.com/hooks");
|
|
171
|
+
console.error(" supersendtx webhooks delete --id <webhook-id>");
|
|
172
|
+
console.error("");
|
|
173
|
+
console.error("Environment: SUPERSENDTX_API_KEY=stx_\u2026");
|
|
174
|
+
}
|
|
175
|
+
async function main() {
|
|
176
|
+
const [, , command, subcommand, ...rest] = process.argv;
|
|
177
|
+
if (command === "emails" && subcommand === "send") {
|
|
178
|
+
const result = await runSendCommandWithClient(rest);
|
|
179
|
+
process.exit(result.exitCode);
|
|
180
|
+
}
|
|
181
|
+
if (command === "webhooks") {
|
|
182
|
+
if (subcommand === "list") {
|
|
183
|
+
const result = await runListCommand(rest);
|
|
184
|
+
if (result.error) console.error(result.error);
|
|
185
|
+
process.exit(result.exitCode);
|
|
186
|
+
}
|
|
187
|
+
if (subcommand === "create") {
|
|
188
|
+
const result = await runCreateCommand(rest);
|
|
189
|
+
if (result.error) console.error(result.error);
|
|
190
|
+
process.exit(result.exitCode);
|
|
191
|
+
}
|
|
192
|
+
if (subcommand === "delete") {
|
|
193
|
+
const result = await runDeleteCommand(rest);
|
|
194
|
+
if (result.error) console.error(result.error);
|
|
195
|
+
process.exit(result.exitCode);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
printUsage();
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
main().catch((error) => {
|
|
202
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
203
|
+
process.exit(1);
|
|
204
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "supersendtx-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SuperSend TX CLI — send transactional email from the terminal",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"supersendtx": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Super-Send/superTX-app.git",
|
|
16
|
+
"directory": "packages/supersendtx-cli"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://supersendtx.com",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/Super-Send/superTX-app/issues"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"email",
|
|
24
|
+
"cli",
|
|
25
|
+
"transactional",
|
|
26
|
+
"supersend",
|
|
27
|
+
"supersendtx"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"supersendtx": "^0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"tsup": "^8.5.0",
|
|
46
|
+
"typescript": "^5",
|
|
47
|
+
"vitest": "^3.2.4"
|
|
48
|
+
}
|
|
49
|
+
}
|