shipmail-cli 0.1.3 → 0.1.4
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 +166 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "shipmail";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = "0.1.
|
|
15
|
+
var VERSION = "0.1.4";
|
|
16
16
|
|
|
17
17
|
// src/cli.ts
|
|
18
18
|
var DEFAULT_BASE_URL = "https://shipmail.to/api/v1";
|
|
@@ -242,6 +242,18 @@ Usage:
|
|
|
242
242
|
shipmail webhooks create --url https://example.com/hook --events message.received,message.bounced
|
|
243
243
|
shipmail suppressions list
|
|
244
244
|
shipmail suppressions remove <email>
|
|
245
|
+
shipmail audiences list [--limit 25] [--cursor cur]
|
|
246
|
+
shipmail audiences create <name> --consent-source "Signup form" [--description "..."]
|
|
247
|
+
shipmail audiences get <id>
|
|
248
|
+
shipmail audiences update <id> [--name "..."] [--description "..."]
|
|
249
|
+
shipmail audiences delete <id>
|
|
250
|
+
shipmail audiences subscribers add <audience-id> <email> [--name "Jane"] [--consent-source "..."]
|
|
251
|
+
shipmail audiences subscribers list <audience-id> [--status subscribed] [--email jane@x.com] [--limit 25]
|
|
252
|
+
shipmail audiences subscribers get <audience-id> <subscriber-id>
|
|
253
|
+
shipmail audiences subscribers by-email <audience-id> <email>
|
|
254
|
+
shipmail audiences subscribers update <audience-id> <subscriber-id> [--name "..."]
|
|
255
|
+
shipmail audiences subscribers unsubscribe <audience-id> <subscriber-id>
|
|
256
|
+
shipmail audiences subscribers remove <audience-id> <subscriber-id>
|
|
245
257
|
|
|
246
258
|
Global options:
|
|
247
259
|
--api-key <key> API key. Defaults to SHIPMAIL_API_KEY.
|
|
@@ -575,6 +587,158 @@ async function runSuppressions(client, parsed, out) {
|
|
|
575
587
|
}
|
|
576
588
|
throw new CliUsageError("Unknown suppressions command.");
|
|
577
589
|
}
|
|
590
|
+
var SUBSCRIBER_STATUS_VALUES = [
|
|
591
|
+
"subscribed",
|
|
592
|
+
"unsubscribed",
|
|
593
|
+
"bounced",
|
|
594
|
+
"complained",
|
|
595
|
+
"suppressed",
|
|
596
|
+
"transactional_only"
|
|
597
|
+
];
|
|
598
|
+
function subscriberListParams(options) {
|
|
599
|
+
const email = getString(options, "email");
|
|
600
|
+
const statusRaw = getString(options, "status");
|
|
601
|
+
const status = statusRaw ? SUBSCRIBER_STATUS_VALUES.find((s) => s === statusRaw) : void 0;
|
|
602
|
+
if (statusRaw && !status) {
|
|
603
|
+
throw new CliUsageError(`Invalid --status: ${statusRaw}.`);
|
|
604
|
+
}
|
|
605
|
+
return {
|
|
606
|
+
cursor: getString(options, "cursor"),
|
|
607
|
+
limit: getNumber(options, "limit"),
|
|
608
|
+
...status ? { status } : {},
|
|
609
|
+
...email ? { email } : {}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
async function runSubscribers(client, parsed, out) {
|
|
613
|
+
const action = parsed.positional[2];
|
|
614
|
+
const audienceId = requirePositional(parsed.positional, 3, "audience id");
|
|
615
|
+
if (action === "list") {
|
|
616
|
+
writeJson(
|
|
617
|
+
out,
|
|
618
|
+
await client.audiences.subscribers.list(audienceId, subscriberListParams(parsed.options))
|
|
619
|
+
);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (action === "add") {
|
|
623
|
+
const name = getString(parsed.options, "name");
|
|
624
|
+
const consentSource = getString(parsed.options, "consent-source");
|
|
625
|
+
const consentIp = getString(parsed.options, "consent-ip");
|
|
626
|
+
writeJson(
|
|
627
|
+
out,
|
|
628
|
+
await client.audiences.subscribers.add(audienceId, {
|
|
629
|
+
email_address: requirePositional(parsed.positional, 4, "email"),
|
|
630
|
+
...name ? { display_name: name } : {},
|
|
631
|
+
...consentSource ? { consent_source: consentSource } : {},
|
|
632
|
+
...consentIp ? { consent_ip: consentIp } : {}
|
|
633
|
+
})
|
|
634
|
+
);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
if (action === "get") {
|
|
638
|
+
writeJson(
|
|
639
|
+
out,
|
|
640
|
+
await client.audiences.subscribers.get(
|
|
641
|
+
audienceId,
|
|
642
|
+
requirePositional(parsed.positional, 4, "subscriber id")
|
|
643
|
+
)
|
|
644
|
+
);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (action === "by-email") {
|
|
648
|
+
writeJson(
|
|
649
|
+
out,
|
|
650
|
+
await client.audiences.subscribers.getByEmail(
|
|
651
|
+
audienceId,
|
|
652
|
+
requirePositional(parsed.positional, 4, "email")
|
|
653
|
+
)
|
|
654
|
+
);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (action === "update") {
|
|
658
|
+
const subscriberId = requirePositional(parsed.positional, 4, "subscriber id");
|
|
659
|
+
const name = getString(parsed.options, "name");
|
|
660
|
+
writeJson(
|
|
661
|
+
out,
|
|
662
|
+
await client.audiences.subscribers.update(audienceId, subscriberId, {
|
|
663
|
+
...name ? { display_name: name } : {}
|
|
664
|
+
})
|
|
665
|
+
);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
if (action === "unsubscribe") {
|
|
669
|
+
writeJson(
|
|
670
|
+
out,
|
|
671
|
+
await client.audiences.subscribers.unsubscribe(
|
|
672
|
+
audienceId,
|
|
673
|
+
requirePositional(parsed.positional, 4, "subscriber id")
|
|
674
|
+
)
|
|
675
|
+
);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (action === "remove") {
|
|
679
|
+
const subscriberId = requirePositional(parsed.positional, 4, "subscriber id");
|
|
680
|
+
await client.audiences.subscribers.remove(audienceId, subscriberId);
|
|
681
|
+
writeJson(out, { ok: true, id: subscriberId });
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
throw new CliUsageError("Unknown audiences subscribers command.");
|
|
685
|
+
}
|
|
686
|
+
async function runAudiences(client, parsed, out) {
|
|
687
|
+
const subcommand = parsed.positional[1];
|
|
688
|
+
if (subcommand === "subscribers") {
|
|
689
|
+
await runSubscribers(client, parsed, out);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (subcommand === "list") {
|
|
693
|
+
writeJson(
|
|
694
|
+
out,
|
|
695
|
+
await client.audiences.list({
|
|
696
|
+
cursor: getString(parsed.options, "cursor"),
|
|
697
|
+
limit: getNumber(parsed.options, "limit")
|
|
698
|
+
})
|
|
699
|
+
);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (subcommand === "create") {
|
|
703
|
+
const description = getString(parsed.options, "description");
|
|
704
|
+
writeJson(
|
|
705
|
+
out,
|
|
706
|
+
await client.audiences.create({
|
|
707
|
+
name: requirePositional(parsed.positional, 2, "audience name"),
|
|
708
|
+
consent_source: getRequiredString(parsed.options, "consent-source"),
|
|
709
|
+
...description ? { description } : {}
|
|
710
|
+
})
|
|
711
|
+
);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (subcommand === "get") {
|
|
715
|
+
writeJson(
|
|
716
|
+
out,
|
|
717
|
+
await client.audiences.get(requirePositional(parsed.positional, 2, "audience id"))
|
|
718
|
+
);
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (subcommand === "update") {
|
|
722
|
+
const id = requirePositional(parsed.positional, 2, "audience id");
|
|
723
|
+
const name = getString(parsed.options, "name");
|
|
724
|
+
const description = getString(parsed.options, "description");
|
|
725
|
+
writeJson(
|
|
726
|
+
out,
|
|
727
|
+
await client.audiences.update(id, {
|
|
728
|
+
...name ? { name } : {},
|
|
729
|
+
...description ? { description } : {}
|
|
730
|
+
})
|
|
731
|
+
);
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (subcommand === "delete") {
|
|
735
|
+
const id = requirePositional(parsed.positional, 2, "audience id");
|
|
736
|
+
await client.audiences.delete(id);
|
|
737
|
+
writeJson(out, { ok: true, id });
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
throw new CliUsageError("Unknown audiences command.");
|
|
741
|
+
}
|
|
578
742
|
function writeError(err, errOut) {
|
|
579
743
|
if (err instanceof CliUsageError) {
|
|
580
744
|
errOut.write(`Error: ${err.message}
|
|
@@ -633,6 +797,7 @@ async function runCli(argv, options = {}) {
|
|
|
633
797
|
else if (command === "messages") await runMessages(client, parsed, out);
|
|
634
798
|
else if (command === "webhooks") await runWebhooks(client, parsed, out);
|
|
635
799
|
else if (command === "suppressions") await runSuppressions(client, parsed, out);
|
|
800
|
+
else if (command === "audiences") await runAudiences(client, parsed, out);
|
|
636
801
|
else throw new CliUsageError(`Unknown command: ${command}.`);
|
|
637
802
|
return 0;
|
|
638
803
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shipmail-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Official CLI for the ShipMail API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"shipmail": "0.1.
|
|
44
|
+
"shipmail": "0.1.24"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.4.0",
|