supersendtx-cli 0.6.0 → 0.7.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.
Files changed (2) hide show
  1. package/dist/cli.js +95 -0
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -668,6 +668,87 @@ async function runRemoveCommand(args, env = process.env) {
668
668
  }
669
669
  }
670
670
 
671
+ // src/commands/templates/shared.ts
672
+ function readFlag11(args, flag) {
673
+ const index = args.indexOf(flag);
674
+ if (index === -1) return void 0;
675
+ return args[index + 1];
676
+ }
677
+ function parseTemplatesCommonArgs(args) {
678
+ return {
679
+ apiKey: readFlag11(args, "--api-key"),
680
+ baseUrl: readFlag11(args, "--base-url")
681
+ };
682
+ }
683
+ function resolveApiKey4(options, env) {
684
+ return options.apiKey || env.SUPERSENDTX_API_KEY || env.SUPERTX_API_KEY || null;
685
+ }
686
+ async function createTemplatesClient(apiKey, baseUrl) {
687
+ const { SuperSendTX } = await import("supersendtx");
688
+ return new SuperSendTX(apiKey, baseUrl ? { baseUrl } : void 0);
689
+ }
690
+
691
+ // src/commands/templates/list.ts
692
+ async function runListCommand5(args, env = process.env) {
693
+ const options = parseTemplatesCommonArgs(args);
694
+ const apiKey = resolveApiKey4(options, env);
695
+ if (!apiKey) {
696
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
697
+ }
698
+ try {
699
+ const client = await createTemplatesClient(apiKey, options.baseUrl);
700
+ const limitRaw = readFlag11(args, "--limit");
701
+ const cursor = readFlag11(args, "--cursor");
702
+ const status = readFlag11(args, "--status");
703
+ const result = await client.templates.list({
704
+ ...limitRaw ? { limit: Number(limitRaw) } : {},
705
+ ...cursor ? { cursor } : {},
706
+ ...status ? { status } : {}
707
+ });
708
+ console.log(JSON.stringify(result));
709
+ return { exitCode: 0 };
710
+ } catch (error) {
711
+ return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
712
+ }
713
+ }
714
+
715
+ // src/commands/templates/create.ts
716
+ async function runCreateCommand2(args, env = process.env) {
717
+ const options = parseTemplatesCommonArgs(args);
718
+ const apiKey = resolveApiKey4(options, env);
719
+ if (!apiKey) {
720
+ return { exitCode: 1, error: "Missing API key. Set SUPERSENDTX_API_KEY or pass --api-key." };
721
+ }
722
+ const name = readFlag11(args, "--name");
723
+ const subject = readFlag11(args, "--subject");
724
+ const html = readFlag11(args, "--html");
725
+ const text = readFlag11(args, "--text");
726
+ const alias = readFlag11(args, "--alias");
727
+ if (!name) {
728
+ return { exitCode: 1, error: 'Missing name. Pass --name "Welcome"' };
729
+ }
730
+ if (!subject) {
731
+ return { exitCode: 1, error: 'Missing subject. Pass --subject "Hello {{name}}"' };
732
+ }
733
+ if (!html && !text) {
734
+ return { exitCode: 1, error: 'Missing body. Pass --html "<p>Hi</p>" or --text "Hi"' };
735
+ }
736
+ try {
737
+ const client = await createTemplatesClient(apiKey, options.baseUrl);
738
+ const result = await client.templates.create({
739
+ name,
740
+ subject,
741
+ ...html ? { html } : {},
742
+ ...text ? { text } : {},
743
+ ...alias ? { alias } : {}
744
+ });
745
+ console.log(JSON.stringify(result));
746
+ return { exitCode: 0 };
747
+ } catch (error) {
748
+ return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
749
+ }
750
+ }
751
+
671
752
  // src/cli.ts
672
753
  function printUsage() {
673
754
  console.error("Usage:");
@@ -688,6 +769,8 @@ function printUsage() {
688
769
  console.error(" supersendtx suppressions list");
689
770
  console.error(" supersendtx suppressions add --email user@example.com [--reason \u2026]");
690
771
  console.error(" supersendtx suppressions remove --id <id> | --email user@example.com");
772
+ console.error(" supersendtx templates list [--status draft|published]");
773
+ console.error(' supersendtx templates create --name Welcome --subject "Hi" --html "<p>Hi</p>"');
691
774
  console.error(" supersendtx keys list");
692
775
  console.error(" supersendtx keys create [--name Default] [--scope full|sending]");
693
776
  console.error(" supersendtx keys delete --id <api-key-id>");
@@ -776,6 +859,18 @@ async function main() {
776
859
  process.exit(result.exitCode);
777
860
  }
778
861
  }
862
+ if (command === "templates") {
863
+ if (subcommand === "list") {
864
+ const result = await runListCommand5(rest);
865
+ if (result.error) console.error(result.error);
866
+ process.exit(result.exitCode);
867
+ }
868
+ if (subcommand === "create" || subcommand === "add") {
869
+ const result = await runCreateCommand2(rest);
870
+ if (result.error) console.error(result.error);
871
+ process.exit(result.exitCode);
872
+ }
873
+ }
779
874
  if (command === "keys") {
780
875
  if (subcommand === "list") {
781
876
  const result = await runListKeysCommandWithClient(rest);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supersendtx-cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.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.6.0"
42
+ "supersendtx": "0.7.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsup": "^8.5.0",