senddart-cli 1.0.0 → 1.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/README.md +95 -7
- package/package.json +2 -2
- package/src/cli.js +4 -0
- package/src/commands/account.js +12 -0
- package/src/commands/apikeys.js +36 -5
- package/src/commands/automations.js +30 -7
- package/src/commands/campaigns.js +114 -1
- package/src/commands/contacts.js +19 -1
- package/src/commands/domains.js +5 -5
- package/src/commands/emails.js +63 -7
- package/src/commands/events.js +4 -0
- package/src/commands/inboxes.js +286 -0
- package/src/commands/segments.js +20 -1
- package/src/commands/suppressions.js +76 -0
- package/src/commands/templates.js +4 -2
- package/src/commands/usage.js +12 -0
- package/src/commands/webhooks.js +27 -0
package/README.md
CHANGED
|
@@ -57,6 +57,11 @@ senddart emails send --to 'ada@yourdomain.com,rae@yourdomain.com' \
|
|
|
57
57
|
senddart emails list --limit 20
|
|
58
58
|
senddart emails list --status delivered --search 'invoice'
|
|
59
59
|
senddart emails list --folder scheduled # mailbox folder: outbox | sent | scheduled | failed (anything else is a 422)
|
|
60
|
+
senddart emails list --engagement clicked --campaign-scope direct # one-off sends someone clicked
|
|
61
|
+
senddart emails list --created-after 2026-11-01T00:00:00Z --created-before 2026-12-01T00:00:00Z
|
|
62
|
+
senddart emails list --statuses bounced,failed --api-key-id 7 --query invoice # --statuses merges with --status
|
|
63
|
+
senddart emails metrics --start-date 2026-11-01 --end-date 2026-11-07 --dimensions period,domain # ≤92 UTC days
|
|
64
|
+
senddart emails share em_123 # public read-only link, 48 h; replaces the previous one
|
|
60
65
|
senddart emails sources # per-source metrics: one row per campaign/automation + api and individual one-off roll-ups
|
|
61
66
|
senddart emails get em_123
|
|
62
67
|
senddart emails update em_123 --scheduled-at 2026-08-02T09:00:00Z
|
|
@@ -80,7 +85,7 @@ senddart emails send --to delivered@test.senddart.com \
|
|
|
80
85
|
--template-alias welcome --variables '{"first_name":"Ada"}'
|
|
81
86
|
```
|
|
82
87
|
|
|
83
|
-
`--idempotency-key` accepts **1–255 characters**, measured after the server trims the value — 255, not 256 — and is honoured by `emails send`, `emails batch`, `emails receiving reply`,
|
|
88
|
+
`--idempotency-key` accepts **1–255 characters**, measured after the server trims the value — 255, not 256 — and is honoured by `emails send`, `emails batch`, `emails receiving reply`, `emails receiving forward`, `campaigns test`, `inboxes threads reply`, `inboxes threads forward` and `inboxes drafts send`. The CLI sends the key verbatim and lets the server be the authority: an out-of-range key comes back as `400 invalid_idempotency_key`. Reusing a key with a different body is rejected (`409 invalid_idempotent_request`); replaying it with the same body returns the original response instead of sending twice. Every other command ignores the header, so a retry there creates a second resource.
|
|
84
89
|
|
|
85
90
|
Batch-send up to 100 emails in one request from a JSON file (an array of send payloads) or inline JSON:
|
|
86
91
|
|
|
@@ -93,6 +98,7 @@ senddart emails batch --data '[{"from":"hi@yourdomain.com","to":["delivered@test
|
|
|
93
98
|
|
|
94
99
|
```bash
|
|
95
100
|
senddart emails receiving list --limit 20
|
|
101
|
+
senddart emails receiving list --search refund --created-after 2026-11-01T00:00:00Z # --query is an alias of --search
|
|
96
102
|
senddart emails receiving addresses # per-address inbound stats
|
|
97
103
|
senddart emails receiving get rem_123
|
|
98
104
|
senddart emails receiving attachments rem_123
|
|
@@ -100,6 +106,7 @@ senddart emails receiving attachment rem_123 att_456 --output invoice.pdf # de
|
|
|
100
106
|
senddart emails receiving raw rem_123 --output message.eml # default filename: <id>.eml
|
|
101
107
|
senddart emails receiving forward rem_123 --from you@yourdomain.com --to delivered@test.senddart.com
|
|
102
108
|
senddart emails receiving reply rem_123 --from you@yourdomain.com --html '<p>thanks!</p>'
|
|
109
|
+
senddart emails receiving mark-read rem_123 # --unread to mark it unread again
|
|
103
110
|
senddart emails receiving delete rem_123
|
|
104
111
|
```
|
|
105
112
|
|
|
@@ -121,7 +128,7 @@ senddart domains delete dom_123
|
|
|
121
128
|
|
|
122
129
|
`records-csv` answers `text/csv`, not JSON, so the CLI writes it to `--output` (or the default filename) and prints where it landed — the same shape as the `emails receiving` binary downloads.
|
|
123
130
|
|
|
124
|
-
|
|
131
|
+
**Deprecated:** automatic DNS setup was retired on 2026-10-15 and every `domains dns` subcommand now answers `410 dns_setup_disabled`. Add the records from `domains get` / `domains records-csv` at your DNS provider instead. The subcommands stay until 2.0:
|
|
125
132
|
|
|
126
133
|
```bash
|
|
127
134
|
senddart domains dns detect dom_123
|
|
@@ -162,7 +169,11 @@ Bulk-import a CSV. Files up to 5 MB / 10,000 rows go inline with `--csv`; anythi
|
|
|
162
169
|
senddart contacts import aud_123 --csv ./contacts.csv --segment-id seg_123
|
|
163
170
|
senddart contacts import-upload aud_123 --csv ./big-list.csv # → { storage_key, upload_url, max_bytes, ... }
|
|
164
171
|
curl -X PUT --upload-file ./big-list.csv "$UPLOAD_URL"
|
|
172
|
+
senddart contacts import-preview aud_123 --storage-key "$STORAGE_KEY" # optional: counts, columns, header_row, mapping — nothing is written
|
|
165
173
|
senddart contacts import aud_123 --storage-key "$STORAGE_KEY"
|
|
174
|
+
# Map columns yourself (one must map to email; others to first_name, last_name, unsubscribed, ignore or a property key):
|
|
175
|
+
senddart contacts import-preview aud_123 --storage-key "$STORAGE_KEY" --mapping '{"E-mail":"email","Company":"company"}'
|
|
176
|
+
senddart contacts import aud_123 --storage-key "$STORAGE_KEY" --mapping '{"E-mail":"email","Company":"company"}'
|
|
166
177
|
```
|
|
167
178
|
|
|
168
179
|
`import` takes exactly one of `--csv` / `--storage-key`. The `upload_url` is a short-lived bearer credential — don't log it or paste it into a shared shell history.
|
|
@@ -200,6 +211,8 @@ senddart segments create --domain yourdomain.com --name VIP
|
|
|
200
211
|
senddart segments create --domain yourdomain.com --name Actives --filter '{"status":"subscribed"}'
|
|
201
212
|
senddart segments list --domain yourdomain.com
|
|
202
213
|
senddart segments contacts seg_123
|
|
214
|
+
senddart segments move seg_123 --destination-id seg_456 --all --preview # check first…
|
|
215
|
+
senddart segments move seg_123 --destination-id seg_456 --all # …then move (or --contact-id con_1)
|
|
203
216
|
|
|
204
217
|
senddart topics create --domain yourdomain.com --name 'Product updates' --default-subscription opt_in
|
|
205
218
|
senddart topics list --domain yourdomain.com
|
|
@@ -218,8 +231,24 @@ senddart campaigns send camp_123 --scheduled-at 2026-08-01T09:00:00Z
|
|
|
218
231
|
senddart campaigns send camp_123 --scheduled-at 'in 1 min'
|
|
219
232
|
senddart campaigns stats camp_123
|
|
220
233
|
senddart campaigns engagement camp_123 # who opened, clicked and replied (each list capped at 500 rows)
|
|
234
|
+
senddart campaigns recipients camp_123 --type clicked --limit 50 # page with --after <last row id>
|
|
235
|
+
senddart campaigns clicked-links camp_123 --limit 10 # most-clicked first
|
|
221
236
|
senddart campaigns ab camp_123
|
|
222
237
|
senddart campaigns cancel camp_123
|
|
238
|
+
senddart campaigns update camp_123 --name 'Summer sale (EU)' # a name-only rename works in any status
|
|
239
|
+
senddart campaigns test camp_123 --to delivered@test.senddart.com # [Test] copy to up to 5 inboxes
|
|
240
|
+
senddart campaigns duplicate camp_123 # new draft copy
|
|
241
|
+
senddart campaigns save-template camp_123 # new draft template from its content
|
|
242
|
+
senddart campaigns batches camp_123 # daily-batch progress
|
|
243
|
+
senddart campaigns continue camp_123 # resume a paused send once the checks pass
|
|
244
|
+
senddart campaigns bounced-contacts camp_123 # count, sample and a version…
|
|
245
|
+
senddart campaigns remove-bounced-contacts camp_123 <version> # …that proves you reviewed the list
|
|
246
|
+
|
|
247
|
+
# Follow-ups on a sending or sent campaign (max 5 active)
|
|
248
|
+
senddart campaigns followup-create camp_123 --condition opened --delay-days 1 --delay-hours 0 --html '<p>Did you see this?</p>'
|
|
249
|
+
senddart campaigns followup-get camp_123 cfu_123
|
|
250
|
+
senddart campaigns followup-update camp_123 cfu_123 --condition opened --delay-days 2 --delay-hours 0 --html '<p>…</p>' --resend-previously-sent
|
|
251
|
+
senddart campaigns followup-cancel camp_123 cfu_123
|
|
223
252
|
```
|
|
224
253
|
|
|
225
254
|
### Templates
|
|
@@ -227,6 +256,7 @@ senddart campaigns cancel camp_123
|
|
|
227
256
|
```bash
|
|
228
257
|
senddart templates create --name Welcome --subject 'Hi {{first_name}}' --html '<p>Welcome!</p>'
|
|
229
258
|
senddart templates list
|
|
259
|
+
senddart templates list --folder-id root # a folder id, or root = templates in no folder
|
|
230
260
|
senddart templates duplicate tmpl_123 --name 'Welcome v2'
|
|
231
261
|
senddart templates publish tmpl_123
|
|
232
262
|
|
|
@@ -251,8 +281,13 @@ senddart automations update auto_123 --status enabled
|
|
|
251
281
|
# with `add-step --key` to re-key it.
|
|
252
282
|
senddart automations runs auto_123
|
|
253
283
|
senddart automations runs auto_123 --status failed,skipped # filtered before paging; repeatable
|
|
284
|
+
senddart automations runs auto_123 --status cancelled --created-after 2026-11-01
|
|
254
285
|
senddart automations run auto_123 run_456
|
|
286
|
+
senddart automations cancel-run auto_123 run_456 # cancelled: false if it had already finished
|
|
255
287
|
senddart automations stop auto_123
|
|
288
|
+
senddart automations duplicate auto_123 # disabled copy
|
|
289
|
+
# Re-enabling after contacts waited over an hour answers 409 waiting_enrollments (waiting, oldest):
|
|
290
|
+
senddart automations update auto_123 --status enabled --on-waiting skip_waiting # or resume
|
|
256
291
|
|
|
257
292
|
# Author (or extend) the step graph from a prompt — the automation must be stopped, and this spends AI credits
|
|
258
293
|
senddart automations ai auto_123 --prompt 'Welcome new signups, then nudge anyone who has not opened after 2 days'
|
|
@@ -261,6 +296,7 @@ senddart automations ai auto_123 --prompt 'Send the upgrade nudge' --attach-from
|
|
|
261
296
|
# Fire a custom event — only yourdomain.com's automations are triggered
|
|
262
297
|
senddart events send --domain yourdomain.com --name signup.completed --email ada@yourdomain.com --data '{"plan":"pro"}'
|
|
263
298
|
senddart events list
|
|
299
|
+
senddart events get signup.completed # by id or name
|
|
264
300
|
senddart events create --name signup.completed --schema '{"plan":"string"}'
|
|
265
301
|
senddart events update evt_123 --schema '{"plan":"string","seats":"number"}' # the name is immutable
|
|
266
302
|
```
|
|
@@ -271,10 +307,19 @@ senddart events update evt_123 --schema '{"plan":"string","seats":"number"}' #
|
|
|
271
307
|
senddart webhooks create --endpoint https://yourapp.com/hooks --events email.delivered,email.bounced
|
|
272
308
|
senddart webhooks rotate wh_123
|
|
273
309
|
senddart webhooks test wh_123
|
|
310
|
+
senddart webhooks events wh_123 --status failed --type email.bounced # what the endpoint was sent, newest first
|
|
311
|
+
senddart webhooks event wh_123 msg_123 # with the payload
|
|
312
|
+
senddart webhooks event-attempts wh_123 msg_123
|
|
313
|
+
senddart webhooks replay-event wh_123 msg_123 # one attempt now, same payload and id
|
|
274
314
|
senddart webhooks verify --secret whsec_xxx --payload-file ./delivery.json \
|
|
275
315
|
--svix-id msg_123 --svix-timestamp 1754000000 --svix-signature 'v1,base64sig'
|
|
276
316
|
|
|
277
|
-
senddart api-keys list
|
|
317
|
+
senddart api-keys list # rows include total_uses and created_by
|
|
318
|
+
senddart api-keys create --name CI --permission sending_access --domain-id dom_123 # prints the secret token once
|
|
319
|
+
senddart api-keys update key_123 --name 'CI (prod)' # or --permission, --domain-id, --all-domains
|
|
320
|
+
senddart api-keys delete key_123 # revoke
|
|
321
|
+
senddart account get # the account this key belongs to (plan, status, timezone)
|
|
322
|
+
senddart usage get # usage meters and limits (limit null = unlimited)
|
|
278
323
|
|
|
279
324
|
senddart logs list --limit 100 --method POST --status 429
|
|
280
325
|
senddart logs get log_123
|
|
@@ -285,13 +330,50 @@ senddart polls get em_123
|
|
|
285
330
|
|
|
286
331
|
`webhooks verify` is the only command that makes no HTTP request: it recomputes the delivery signature locally and prints `{ valid, reason }`. It is also the only command that needs **no API key** — it never contacts the API, so a webhook receiver can run it without holding a send-capable key. Pass the **exact raw body bytes** your endpoint received via `--payload` or `--payload-file` — re-serialized JSON will not match. `--tolerance <seconds>` caps timestamp skew (default `300`; `0` skips the freshness check). Note the exit code is `0` whenever the check ran, whatever the verdict — branch on `.valid`, not on `$?` (unlike `webhooks test`, which exits `1` on a failed delivery).
|
|
287
332
|
|
|
288
|
-
#### API keys
|
|
333
|
+
#### API keys need full access to change
|
|
289
334
|
|
|
290
|
-
`api-keys list`
|
|
335
|
+
`api-keys list` works with any key that can read. `api-keys create`, `update` and `delete` need a **full-access** key (or the dashboard): a sending-only key gets `401 restricted_api_key`, so a key that leaks from a CI log cannot mint itself a wider one. `create` prints the full secret `token` once — store it then.
|
|
291
336
|
|
|
292
|
-
|
|
337
|
+
### Suppressions
|
|
293
338
|
|
|
294
|
-
|
|
339
|
+
```bash
|
|
340
|
+
senddart suppressions add ada@example.com # already listed: the existing row comes back
|
|
341
|
+
senddart suppressions list --origin bounce --search example.com --limit 50
|
|
342
|
+
senddart suppressions get ada@example.com # by id or address
|
|
343
|
+
senddart suppressions delete ada@example.com # by address: every row for it
|
|
344
|
+
senddart suppressions batch-add --emails a@x.com,b@x.com # or --file list.txt (one per line); ≤1000, skipped ones listed
|
|
345
|
+
senddart suppressions batch-remove --ids 41,42 --emails c@x.com
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Inboxes
|
|
349
|
+
|
|
350
|
+
Reads need read access; changes need a full-access key; `threads reply`, `threads forward` and `drafts send` need write **and** send scope.
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
senddart inboxes create --email-address support@yourdomain.com --name Support # --receiving domain|forward if the domain does not receive yet
|
|
354
|
+
senddart inboxes list
|
|
355
|
+
senddart inboxes update inb_123 --from-name 'Ada from Support' --view-mode board
|
|
356
|
+
senddart inboxes labels create inb_123 --name Urgent --color red
|
|
357
|
+
senddart inboxes labels list inb_123
|
|
358
|
+
|
|
359
|
+
senddart inboxes threads list inb_123 --folder inbox --unread --limit 20 # page with --after <last thread id>
|
|
360
|
+
senddart inboxes threads search inb_123 --query invoice --from carol@example.org
|
|
361
|
+
senddart inboxes threads update inb_123 thr_123 --read --assignee ada@yourdomain.com
|
|
362
|
+
senddart inboxes threads add-labels inb_123 thr_123 --labels lbl_1,lbl_2
|
|
363
|
+
senddart inboxes threads set-labels inb_123 thr_123 --clear
|
|
364
|
+
senddart inboxes threads remove-label inb_123 thr_123 lbl_1
|
|
365
|
+
senddart inboxes threads delete inb_123 thr_123 # to Trash; again = for good
|
|
366
|
+
senddart inboxes threads emails inb_123 thr_123
|
|
367
|
+
senddart inboxes threads reply inb_123 thr_123 msg_123 --text 'Refund issued.' --idempotency-key refund-1041
|
|
368
|
+
senddart inboxes threads forward inb_123 thr_123 msg_123 --to colleague@example.org
|
|
369
|
+
|
|
370
|
+
senddart inboxes drafts create inb_123 --mode reply --email-id msg_123 --text 'Hi'
|
|
371
|
+
senddart inboxes drafts update inb_123 drf_123 --subject 'Your refund'
|
|
372
|
+
senddart inboxes drafts send inb_123 drf_123
|
|
373
|
+
|
|
374
|
+
senddart inboxes agent get inb_123
|
|
375
|
+
senddart inboxes agent update inb_123 --actions draft_reply,apply_label --tone '{"length":30,"register":20}'
|
|
376
|
+
```
|
|
295
377
|
|
|
296
378
|
## Command names vs. SDK method names
|
|
297
379
|
|
|
@@ -307,6 +389,12 @@ after its plural noun and every download after the thing downloaded:
|
|
|
307
389
|
| `emails receiving raw <id>` | `emails.receiving.getRaw` |
|
|
308
390
|
| `automations ai <id>` | `automations.createWithAi` |
|
|
309
391
|
| `contacts import-upload <audienceId>` | `contacts.createImportUpload` |
|
|
392
|
+
| `suppressions add <email>` | `suppressions.create` |
|
|
393
|
+
| `webhooks events <id>` | `webhooks.listEvents` |
|
|
394
|
+
| `webhooks event <id> <eventId>` | `webhooks.getEvent` |
|
|
395
|
+
| `webhooks event-attempts <id> <eventId>` | `webhooks.listEventAttempts` |
|
|
396
|
+
| `inboxes threads emails <inboxId> <threadId>` | `inboxes.threads.listEmails` |
|
|
397
|
+
| `inboxes threads email <inboxId> <threadId> <emailId>` | `inboxes.threads.getEmail` |
|
|
310
398
|
|
|
311
399
|
This is a shell-surface convention, not drift: the CLI applies the same
|
|
312
400
|
shortening rule to every endpoint rather than to some.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "senddart-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Official command-line interface for the SendDart email API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"senddart",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"commander": "^12.1.0",
|
|
41
|
-
"senddart": "^1.
|
|
41
|
+
"senddart": "^1.1.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/cli.js
CHANGED
|
@@ -21,6 +21,10 @@ const RESOURCES = [
|
|
|
21
21
|
require('./commands/events'),
|
|
22
22
|
require('./commands/logs'),
|
|
23
23
|
require('./commands/polls'),
|
|
24
|
+
require('./commands/account'),
|
|
25
|
+
require('./commands/inboxes'),
|
|
26
|
+
require('./commands/suppressions'),
|
|
27
|
+
require('./commands/usage'),
|
|
24
28
|
];
|
|
25
29
|
|
|
26
30
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// GET /user — the account the API key belongs to.
|
|
4
|
+
function register({ group, leaf, act }) {
|
|
5
|
+
const account = group('account', 'Show the account this API key belongs to');
|
|
6
|
+
|
|
7
|
+
act(leaf(account, 'get', "Plan, status and timezone of the key's account"), ({ client }) =>
|
|
8
|
+
client.account.get(),
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { register };
|
package/src/commands/apikeys.js
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { withPagination, pagination } = require('../helpers');
|
|
3
|
+
const { CliError, collect, clean, withPagination, pagination } = require('../helpers');
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// cannot mint itself a
|
|
5
|
+
// Listing needs read access. create / update / delete need a FULL-ACCESS key
|
|
6
|
+
// (or the dashboard): a sending-only key gets 401 restricted_api_key, so a
|
|
7
|
+
// leaked sending key cannot mint itself a wider one.
|
|
8
8
|
function register({ group, leaf, act }) {
|
|
9
|
-
const apiKeys = group('api-keys', '
|
|
9
|
+
const apiKeys = group('api-keys', 'Manage API keys (create/update/delete need a full-access key)');
|
|
10
|
+
|
|
11
|
+
act(
|
|
12
|
+
leaf(apiKeys, 'create', 'Create an API key (the full secret `token` is shown once)')
|
|
13
|
+
.requiredOption('--name <name>', 'key name (max 50 characters)')
|
|
14
|
+
.option('--permission <permission>', "'full_access' (default) | 'sending_access'")
|
|
15
|
+
.option('--domain-id <id>', 'restrict a sending_access key to this domain (repeatable or comma-separated)', collect),
|
|
16
|
+
({ client, opts }) =>
|
|
17
|
+
client.apiKeys.create(clean({ name: opts.name, permission: opts.permission, domain_ids: opts.domainId })),
|
|
18
|
+
);
|
|
10
19
|
|
|
11
20
|
act(withPagination(leaf(apiKeys, 'list', 'List API keys')), ({ client, opts }) =>
|
|
12
21
|
client.apiKeys.list(pagination(opts)),
|
|
13
22
|
);
|
|
23
|
+
|
|
24
|
+
act(
|
|
25
|
+
leaf(apiKeys, 'update <id>', "Rename a key or change its permission or domain restriction (the secret never changes)")
|
|
26
|
+
.option('--name <name>', 'new name')
|
|
27
|
+
.option('--permission <permission>', "'full_access' (clears a restriction) | 'sending_access'")
|
|
28
|
+
.option('--domain-id <id>', 'restrict to these domains (repeatable or comma-separated)', collect)
|
|
29
|
+
.option('--all-domains', 'remove the domain restriction'),
|
|
30
|
+
({ client, opts, args: [id] }) => {
|
|
31
|
+
if (opts.domainId && opts.allDomains) throw new CliError('Provide only one of --domain-id or --all-domains.');
|
|
32
|
+
const body = clean({
|
|
33
|
+
name: opts.name,
|
|
34
|
+
permission: opts.permission,
|
|
35
|
+
domain_ids: opts.allDomains ? null : opts.domainId,
|
|
36
|
+
});
|
|
37
|
+
if (!Object.keys(body).length) throw new CliError('Provide --name, --permission, --domain-id or --all-domains.');
|
|
38
|
+
return client.apiKeys.update(id, body);
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
act(leaf(apiKeys, 'delete <id>', 'Revoke an API key (it stops working at once)'), ({ client, args: [id] }) =>
|
|
43
|
+
client.apiKeys.remove(id),
|
|
44
|
+
);
|
|
14
45
|
}
|
|
15
46
|
|
|
16
47
|
module.exports = { register };
|
|
@@ -44,13 +44,18 @@ function register({ group, leaf, act }) {
|
|
|
44
44
|
.option('--name <name>', 'new name')
|
|
45
45
|
.option('--status <status>', "'enabled' | 'disabled'")
|
|
46
46
|
.option('--trigger-at <iso>', "update the 'senddart:schedule' trigger's ISO 8601 fire time (with --trigger-timezone)")
|
|
47
|
-
.option('--trigger-timezone <tz>', "IANA timezone the schedule was picked in, e.g. 'America/New_York'")
|
|
47
|
+
.option('--trigger-timezone <tz>', "IANA timezone the schedule was picked in, e.g. 'America/New_York'")
|
|
48
|
+
.option(
|
|
49
|
+
'--on-waiting <choice>',
|
|
50
|
+
"when enabling answers 409 waiting_enrollments: 'resume' runs waiting contacts' next step now, 'skip_waiting' enables for new contacts only",
|
|
51
|
+
),
|
|
48
52
|
({ client, opts, args: [id] }) =>
|
|
49
53
|
client.automations.update(
|
|
50
54
|
id,
|
|
51
55
|
clean({
|
|
52
56
|
name: opts.name,
|
|
53
57
|
status: opts.status,
|
|
58
|
+
on_waiting: opts.onWaiting,
|
|
54
59
|
trigger_config:
|
|
55
60
|
opts.triggerAt || opts.triggerTimezone
|
|
56
61
|
? clean({ at: opts.triggerAt, timezone: opts.triggerTimezone })
|
|
@@ -106,13 +111,21 @@ function register({ group, leaf, act }) {
|
|
|
106
111
|
);
|
|
107
112
|
|
|
108
113
|
act(
|
|
109
|
-
withPagination(leaf(automations, 'runs <id>', "List an automation's runs, newest first"))
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
withPagination(leaf(automations, 'runs <id>', "List an automation's runs, newest first"))
|
|
115
|
+
.option(
|
|
116
|
+
'--status <status>',
|
|
117
|
+
"keep only runs in these statuses: 'running' | 'completed' | 'failed' | 'skipped' | 'cancelled' | 'quota_exceeded' (repeatable or comma-separated); filtering happens before paging",
|
|
118
|
+
collect,
|
|
119
|
+
)
|
|
120
|
+
.option('--created-after <iso>', 'runs created at or after this ISO 8601 date or date-time')
|
|
121
|
+
.option('--created-before <iso>', 'runs created before this ISO 8601 date or date-time'),
|
|
114
122
|
({ client, opts, args: [id] }) =>
|
|
115
|
-
client.automations.runs(id, clean({
|
|
123
|
+
client.automations.runs(id, clean({
|
|
124
|
+
...pagination(opts),
|
|
125
|
+
status: opts.status,
|
|
126
|
+
created_after: opts.createdAfter,
|
|
127
|
+
created_before: opts.createdBefore,
|
|
128
|
+
})),
|
|
116
129
|
);
|
|
117
130
|
|
|
118
131
|
act(
|
|
@@ -120,6 +133,11 @@ function register({ group, leaf, act }) {
|
|
|
120
133
|
({ client, args: [id, runId] }) => client.automations.getRun(id, runId),
|
|
121
134
|
);
|
|
122
135
|
|
|
136
|
+
act(
|
|
137
|
+
leaf(automations, 'cancel-run <id> <runId>', "Stop one running run (a finished run comes back with cancelled: false)"),
|
|
138
|
+
({ client, args: [id, runId] }) => client.automations.cancelRun(id, runId),
|
|
139
|
+
);
|
|
140
|
+
|
|
123
141
|
act(
|
|
124
142
|
leaf(automations, 'stop <id>', 'Stop an automation (in-progress runs finish)'),
|
|
125
143
|
({ client, args: [id] }) => client.automations.stop(id),
|
|
@@ -149,6 +167,11 @@ function register({ group, leaf, act }) {
|
|
|
149
167
|
),
|
|
150
168
|
);
|
|
151
169
|
|
|
170
|
+
act(
|
|
171
|
+
leaf(automations, 'duplicate <id>', 'Copy an automation (trigger, steps, connections) into a new disabled one'),
|
|
172
|
+
({ client, args: [id] }) => client.automations.duplicate(id),
|
|
173
|
+
);
|
|
174
|
+
|
|
152
175
|
act(leaf(automations, 'delete <id>', 'Delete an automation'), ({ client, args: [id] }) =>
|
|
153
176
|
client.automations.remove(id),
|
|
154
177
|
);
|
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
const { collect, parseJson, clean, toInt, withPagination, pagination } = require('../helpers');
|
|
4
4
|
|
|
5
|
+
/** Same rule and help text as `emails send --idempotency-key` (1-255 characters, server-validated). */
|
|
6
|
+
const IDEMPOTENCY_KEY_HELP = 'idempotency key for safe retries (1-255 characters)';
|
|
7
|
+
|
|
8
|
+
/** Flags shared by `campaigns followup-create` and `campaigns followup-update`. */
|
|
9
|
+
function withFollowupFlags(cmd) {
|
|
10
|
+
return cmd
|
|
11
|
+
.requiredOption('--condition <condition>', "who gets it: 'delivered' | 'opened' | 'clicked' | 'replied'")
|
|
12
|
+
.requiredOption('--delay-days <n>', 'whole days to wait after the condition is met (0-7)')
|
|
13
|
+
.requiredOption('--delay-hours <n>', 'extra hours to wait (0-23)')
|
|
14
|
+
.requiredOption('--html <html>', 'follow-up HTML body')
|
|
15
|
+
.option('--subject <subject>', "subject line (default: the campaign's subject)")
|
|
16
|
+
.option('--auto-followup', 'keep sending to recipients who meet the condition later on');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Map the follow-up flags onto the API body. */
|
|
20
|
+
function followupBody(opts) {
|
|
21
|
+
return clean({
|
|
22
|
+
condition: opts.condition,
|
|
23
|
+
delay_days: toInt(opts.delayDays, '--delay-days'),
|
|
24
|
+
delay_hours: toInt(opts.delayHours, '--delay-hours'),
|
|
25
|
+
html: opts.html,
|
|
26
|
+
subject: opts.subject,
|
|
27
|
+
auto_followup: opts.autoFollowup,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
5
31
|
/** Flags shared by `campaigns create` and `campaigns update`. */
|
|
6
32
|
function withCampaignBodyFlags(cmd) {
|
|
7
33
|
return cmd
|
|
@@ -91,7 +117,7 @@ function register({ group, leaf, act }) {
|
|
|
91
117
|
|
|
92
118
|
act(
|
|
93
119
|
withCampaignBodyFlags(
|
|
94
|
-
leaf(campaigns, 'update <id>', 'Update a draft campaign')
|
|
120
|
+
leaf(campaigns, 'update <id>', 'Update a draft campaign (a --name-only rename works in any status)')
|
|
95
121
|
.option('--domain <domain>', 're-target another sending domain (clears segment and topic)')
|
|
96
122
|
.option('--from <from>', 'sender')
|
|
97
123
|
.option('--subject <subject>', 'subject line')
|
|
@@ -145,9 +171,96 @@ function register({ group, leaf, act }) {
|
|
|
145
171
|
({ client, args: [id] }) => client.campaigns.ab(id),
|
|
146
172
|
);
|
|
147
173
|
|
|
174
|
+
act(leaf(campaigns, 'duplicate <id>', 'Copy a campaign (any status) into a new draft'), ({ client, args: [id] }) =>
|
|
175
|
+
client.campaigns.duplicate(id),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
act(
|
|
179
|
+
leaf(campaigns, 'test <id>', "Send the campaign's saved content as one [Test] email to up to 5 addresses")
|
|
180
|
+
.requiredOption('--to <address>', 'recipient (repeatable or comma-separated; max 5)', collect)
|
|
181
|
+
.option('--idempotency-key <key>', IDEMPOTENCY_KEY_HELP),
|
|
182
|
+
({ client, opts, args: [id] }) =>
|
|
183
|
+
client.campaigns.test(
|
|
184
|
+
id,
|
|
185
|
+
{ to: opts.to },
|
|
186
|
+
opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : undefined,
|
|
187
|
+
),
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
act(
|
|
191
|
+
leaf(campaigns, 'save-template <id>', "Save a campaign's content as a new draft template"),
|
|
192
|
+
({ client, args: [id] }) => client.campaigns.saveAsTemplate(id),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
act(
|
|
196
|
+
leaf(campaigns, 'continue <id>', 'Resume a paused campaign once the server checks pass'),
|
|
197
|
+
({ client, args: [id] }) => client.campaigns.continueSending(id),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
act(
|
|
201
|
+
leaf(campaigns, 'bounced-contacts <id>', 'Audience contacts that bounced on this campaign (count, sample, version)'),
|
|
202
|
+
({ client, args: [id] }) => client.campaigns.bouncedContacts(id),
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
act(
|
|
206
|
+
// `version` is positional: `--version` is the program's own flag.
|
|
207
|
+
leaf(
|
|
208
|
+
campaigns,
|
|
209
|
+
'remove-bounced-contacts <id> <version>',
|
|
210
|
+
"Delete the bounced contacts from the campaign's audience (<version> = the one `campaigns bounced-contacts` printed)",
|
|
211
|
+
),
|
|
212
|
+
({ client, args: [id, version] }) => client.campaigns.removeBouncedContacts(id, { version }),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
act(leaf(campaigns, 'batches <id>', 'Daily-batch send progress'), ({ client, args: [id] }) =>
|
|
216
|
+
client.campaigns.batches(id),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
act(
|
|
220
|
+
withFollowupFlags(leaf(campaigns, 'followup-create <id>', 'Add a follow-up to a sending or sent campaign (max 5 active)')),
|
|
221
|
+
({ client, opts, args: [id] }) => client.campaigns.createFollowup(id, followupBody(opts)),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
act(
|
|
225
|
+
leaf(campaigns, 'followup-get <id> <followupId>', 'Retrieve a follow-up and its delivery counts'),
|
|
226
|
+
({ client, args: [id, followupId] }) => client.campaigns.getFollowup(id, followupId),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
act(
|
|
230
|
+
withFollowupFlags(leaf(campaigns, 'followup-update <id> <followupId>', "Replace a follow-up's settings (send every flag again)"))
|
|
231
|
+
.option('--resend-previously-sent', 'also send the new content to recipients who already got it'),
|
|
232
|
+
({ client, opts, args: [id, followupId] }) =>
|
|
233
|
+
client.campaigns.updateFollowup(id, followupId, clean({
|
|
234
|
+
...followupBody(opts),
|
|
235
|
+
resend_previously_sent: opts.resendPreviouslySent,
|
|
236
|
+
})),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
act(
|
|
240
|
+
leaf(campaigns, 'followup-cancel <id> <followupId>', 'Cancel a follow-up (pending deliveries stop)'),
|
|
241
|
+
({ client, args: [id, followupId] }) => client.campaigns.removeFollowup(id, followupId),
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
act(
|
|
245
|
+
leaf(campaigns, 'recipients <id>', 'One page of the people a campaign went to (page with --after = the last row id)')
|
|
246
|
+
.option('--type <type>', 'only one outcome: delivered | opened | clicked | bounced | complained | failed | suppressed')
|
|
247
|
+
.option('--limit <n>', 'rows per page (1-100, default 20)')
|
|
248
|
+
.option('--after <id>', 'the id of the last recipient on the previous page'),
|
|
249
|
+
({ client, opts, args: [id] }) =>
|
|
250
|
+
client.campaigns.recipients(id, clean({ type: opts.type, limit: toInt(opts.limit, '--limit'), after: opts.after })),
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
act(
|
|
254
|
+
leaf(campaigns, 'clicked-links <id>', 'Every tracked link with its click total, most-clicked first')
|
|
255
|
+
.option('--limit <n>', 'how many links (1-100, default 50)'),
|
|
256
|
+
({ client, opts, args: [id] }) =>
|
|
257
|
+
client.campaigns.clickedLinks(id, clean({ limit: toInt(opts.limit, '--limit') })),
|
|
258
|
+
);
|
|
259
|
+
|
|
148
260
|
act(leaf(campaigns, 'delete <id>', 'Delete a campaign'), ({ client, args: [id] }) =>
|
|
149
261
|
client.campaigns.remove(id),
|
|
150
262
|
);
|
|
151
263
|
}
|
|
152
264
|
|
|
265
|
+
|
|
153
266
|
module.exports = { register };
|
package/src/commands/contacts.js
CHANGED
|
@@ -4,6 +4,9 @@ const fs = require('node:fs');
|
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const { CliError, parseJson, clean, withPagination, pagination } = require('../helpers');
|
|
6
6
|
|
|
7
|
+
/** Help for `--mapping` on `contacts import` and `contacts import-preview`. */
|
|
8
|
+
const MAPPING_HELP = 'column mapping as JSON: {"<CSV header>": "email" | "first_name" | "last_name" | "unsubscribed" | "ignore" | "<property key>"}; one column must map to email';
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* A contact lives either in a sending domain's pool (`--domain`, the
|
|
9
12
|
* domain-first default) or in a plain audience (`--audience-id`, the nested
|
|
@@ -181,7 +184,8 @@ function register({ group, leaf, act }) {
|
|
|
181
184
|
.option('--file-name <name>', 'name recorded for the archived source file (inline --csv mode)')
|
|
182
185
|
.option('--segment-id <id>', 'also add every imported email to this segment (must belong to the audience)')
|
|
183
186
|
.option('--on-conflict <mode>', "how to resolve an existing email: 'upsert' (default) or 'skip'")
|
|
184
|
-
.option('--no-create-properties', 'strict mode: keep only columns matching a registered property')
|
|
187
|
+
.option('--no-create-properties', 'strict mode: keep only columns matching a registered property')
|
|
188
|
+
.option('--mapping <json>', MAPPING_HELP),
|
|
185
189
|
({ client, opts, args: [audienceId] }) => {
|
|
186
190
|
if (opts.csv && opts.storageKey) {
|
|
187
191
|
throw new CliError('Provide only one of --csv or --storage-key.');
|
|
@@ -199,6 +203,7 @@ function register({ group, leaf, act }) {
|
|
|
199
203
|
audienceId, csv, storage_key: opts.storageKey, file_name: opts.fileName,
|
|
200
204
|
segment_id: opts.segmentId, on_conflict: opts.onConflict,
|
|
201
205
|
create_properties: opts.createProperties === false ? false : undefined,
|
|
206
|
+
mapping: parseJson(opts.mapping, '--mapping'),
|
|
202
207
|
}));
|
|
203
208
|
},
|
|
204
209
|
);
|
|
@@ -222,6 +227,19 @@ function register({ group, leaf, act }) {
|
|
|
222
227
|
});
|
|
223
228
|
},
|
|
224
229
|
);
|
|
230
|
+
|
|
231
|
+
act(
|
|
232
|
+
leaf(
|
|
233
|
+
contacts,
|
|
234
|
+
'import-preview <audienceId>',
|
|
235
|
+
'Validate an uploaded CSV and preview the import (nothing is written)',
|
|
236
|
+
).requiredOption('--storage-key <key>', 'the storage_key from `contacts import-upload`, after the PUT')
|
|
237
|
+
.option('--mapping <json>', MAPPING_HELP),
|
|
238
|
+
({ client, opts, args: [audienceId] }) =>
|
|
239
|
+
client.contacts.previewImport(clean({
|
|
240
|
+
audienceId, storage_key: opts.storageKey, mapping: parseJson(opts.mapping, '--mapping'),
|
|
241
|
+
})),
|
|
242
|
+
);
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
module.exports = { register };
|
package/src/commands/domains.js
CHANGED
|
@@ -109,15 +109,15 @@ function register({ group, leaf, act }) {
|
|
|
109
109
|
|
|
110
110
|
const dns = domains
|
|
111
111
|
.command('dns')
|
|
112
|
-
.description("
|
|
112
|
+
.description("[deprecated] One-click DNS setup — retired; every subcommand now answers 410 dns_setup_disabled. Removed in 2.0");
|
|
113
113
|
|
|
114
114
|
act(
|
|
115
|
-
leaf(dns, 'detect <id>', 'Detect the DNS provider and available one-click apply methods'),
|
|
115
|
+
leaf(dns, 'detect <id>', 'Detect the DNS provider and available one-click apply methods [deprecated: automatic DNS setup was retired; the API answers 410 dns_setup_disabled — add the records from `domains get` at your DNS provider]'),
|
|
116
116
|
({ client, args: [id] }) => client.domains.detectDns(id),
|
|
117
117
|
);
|
|
118
118
|
|
|
119
119
|
act(
|
|
120
|
-
leaf(dns, 'cloudflare <id>', 'Apply DNS records via the Cloudflare API, then auto-verify').requiredOption(
|
|
120
|
+
leaf(dns, 'cloudflare <id>', 'Apply DNS records via the Cloudflare API, then auto-verify [deprecated: automatic DNS setup was retired; the API answers 410 dns_setup_disabled — add the records from `domains get` at your DNS provider]').requiredOption(
|
|
121
121
|
'--token <token>',
|
|
122
122
|
'Cloudflare API token with DNS edit access',
|
|
123
123
|
),
|
|
@@ -125,7 +125,7 @@ function register({ group, leaf, act }) {
|
|
|
125
125
|
);
|
|
126
126
|
|
|
127
127
|
act(
|
|
128
|
-
leaf(dns, 'godaddy <id>', 'Apply DNS records via the GoDaddy API, then auto-verify')
|
|
128
|
+
leaf(dns, 'godaddy <id>', 'Apply DNS records via the GoDaddy API, then auto-verify [deprecated: automatic DNS setup was retired; the API answers 410 dns_setup_disabled — add the records from `domains get` at your DNS provider]')
|
|
129
129
|
.requiredOption('--key <key>', 'GoDaddy API key')
|
|
130
130
|
.requiredOption('--secret <secret>', 'GoDaddy API secret'),
|
|
131
131
|
({ client, opts, args: [id] }) =>
|
|
@@ -133,7 +133,7 @@ function register({ group, leaf, act }) {
|
|
|
133
133
|
);
|
|
134
134
|
|
|
135
135
|
act(
|
|
136
|
-
leaf(dns, 'namecheap <id>', 'Apply DNS records via the Namecheap API, then auto-verify')
|
|
136
|
+
leaf(dns, 'namecheap <id>', 'Apply DNS records via the Namecheap API, then auto-verify [deprecated: automatic DNS setup was retired; the API answers 410 dns_setup_disabled — add the records from `domains get` at your DNS provider]')
|
|
137
137
|
.requiredOption('--api-user <user>', 'Namecheap API user')
|
|
138
138
|
.requiredOption('--key <key>', 'Namecheap API key')
|
|
139
139
|
.option('--user-name <name>', 'Namecheap account user name (default: the API user)'),
|
package/src/commands/emails.js
CHANGED
|
@@ -17,7 +17,8 @@ const MAX_ATTACHMENTS_TOTAL = 40 * 1024 * 1024;
|
|
|
17
17
|
*
|
|
18
18
|
* Unlike the attachment caps above this is NOT pre-checked: the key is sent as
|
|
19
19
|
* given and the server is the authority (400 invalid_idempotency_key). Only
|
|
20
|
-
* `emails send
|
|
20
|
+
* `emails send`, `emails batch`, inbound reply/forward and `campaigns test`
|
|
21
|
+
* honour the header at all.
|
|
21
22
|
*/
|
|
22
23
|
const IDEMPOTENCY_KEY_MAX_LENGTH = 255;
|
|
23
24
|
const IDEMPOTENCY_KEY_HELP = `idempotency key for safe retries (1-${IDEMPOTENCY_KEY_MAX_LENGTH} characters)`;
|
|
@@ -191,8 +192,19 @@ function register({ group, leaf, act }) {
|
|
|
191
192
|
)
|
|
192
193
|
.option('--domain-id <id>', 'only emails sent from this sending domain')
|
|
193
194
|
.option('--status <status>', "only emails whose last event matches, e.g. 'delivered'")
|
|
195
|
+
.option(
|
|
196
|
+
'--statuses <status>',
|
|
197
|
+
'one or more current statuses (repeatable or comma-separated; merged with --status): bounced, canceled, clicked, complained, delivered, delivery_delayed, failed, opened, queued, replied, scheduled, sent, suppressed',
|
|
198
|
+
collect,
|
|
199
|
+
)
|
|
200
|
+
.option('--api-key-id <id>', 'only emails sent with this API key (its id)')
|
|
194
201
|
.option('--search <text>', 'match recipients, subject or sender')
|
|
195
|
-
.option('--
|
|
202
|
+
.option('--query <text>', 'alias of --search')
|
|
203
|
+
.option('--folder <folder>', "mailbox folder: outbox | sent | scheduled | failed")
|
|
204
|
+
.option('--engagement <event>', 'delivered | opened | clicked | replied | bounced | complained')
|
|
205
|
+
.option('--campaign-scope <scope>', "'direct' = one-off sends only (no campaign mail)")
|
|
206
|
+
.option('--created-after <iso>', 'created at or after this ISO 8601 date-time, e.g. 2026-01-31T00:00:00Z')
|
|
207
|
+
.option('--created-before <iso>', 'created before this ISO 8601 date-time'),
|
|
196
208
|
({ client, opts }) =>
|
|
197
209
|
client.emails.list(
|
|
198
210
|
clean({
|
|
@@ -202,8 +214,15 @@ function register({ group, leaf, act }) {
|
|
|
202
214
|
source: opts.source,
|
|
203
215
|
domain_id: opts.domainId,
|
|
204
216
|
status: opts.status,
|
|
217
|
+
statuses: opts.statuses,
|
|
218
|
+
api_key_id: opts.apiKeyId,
|
|
205
219
|
search: opts.search,
|
|
220
|
+
query: opts.query,
|
|
206
221
|
folder: opts.folder,
|
|
222
|
+
engagement: opts.engagement,
|
|
223
|
+
campaign_scope: opts.campaignScope,
|
|
224
|
+
created_after: opts.createdAfter,
|
|
225
|
+
created_before: opts.createdBefore,
|
|
207
226
|
}),
|
|
208
227
|
),
|
|
209
228
|
);
|
|
@@ -225,6 +244,28 @@ function register({ group, leaf, act }) {
|
|
|
225
244
|
({ client }) => client.emails.sources(),
|
|
226
245
|
);
|
|
227
246
|
|
|
247
|
+
act(
|
|
248
|
+
leaf(emails, 'metrics', "Counts of what happened to the account's email in a window of UTC days (default: the last 7, max 92)")
|
|
249
|
+
.option('--start-date <day>', 'first UTC day, YYYY-MM-DD')
|
|
250
|
+
.option('--end-date <day>', 'last UTC day (inclusive), YYYY-MM-DD')
|
|
251
|
+
.option('--dimensions <dimension>', "split by 'period' (day), 'domain' and/or 'campaign' (repeatable or comma-separated)", collect)
|
|
252
|
+
.option('--domain-id <id>', 'only these sending domains (repeatable or comma-separated)', collect)
|
|
253
|
+
.option('--campaign-id <id>', 'only these campaigns (repeatable or comma-separated)', collect),
|
|
254
|
+
({ client, opts }) =>
|
|
255
|
+
client.emails.metrics(clean({
|
|
256
|
+
start_date: opts.startDate,
|
|
257
|
+
end_date: opts.endDate,
|
|
258
|
+
dimensions: opts.dimensions,
|
|
259
|
+
domain_id: opts.domainId,
|
|
260
|
+
campaign_id: opts.campaignId,
|
|
261
|
+
})),
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
act(
|
|
265
|
+
leaf(emails, 'share <id>', 'Create a public read-only link to a sent email (48 hours; replaces the previous link)'),
|
|
266
|
+
({ client, args: [id] }) => client.emails.share(id),
|
|
267
|
+
);
|
|
268
|
+
|
|
228
269
|
act(
|
|
229
270
|
leaf(emails, 'attachments <emailId>', "List a sent email's attachments"),
|
|
230
271
|
({ client, args: [emailId] }) => client.emails.listAttachments(emailId),
|
|
@@ -240,13 +281,22 @@ function register({ group, leaf, act }) {
|
|
|
240
281
|
const receiving = emails.command('receiving').description('Manage inbound (received) email');
|
|
241
282
|
|
|
242
283
|
act(
|
|
243
|
-
withPagination(leaf(receiving, 'list', 'List received emails'))
|
|
244
|
-
'--received-for <address>',
|
|
245
|
-
'
|
|
246
|
-
|
|
284
|
+
withPagination(leaf(receiving, 'list', 'List received emails'))
|
|
285
|
+
.option('--received-for <address>', 'only messages received for this address')
|
|
286
|
+
.option('--search <text>', 'text search over the messages')
|
|
287
|
+
.option('--query <text>', 'alias of --search')
|
|
288
|
+
.option('--created-after <iso>', 'received at or after this ISO 8601 date-time')
|
|
289
|
+
.option('--created-before <iso>', 'received before this ISO 8601 date-time'),
|
|
247
290
|
({ client, opts }) =>
|
|
248
291
|
client.emails.receiving.list(
|
|
249
|
-
clean({
|
|
292
|
+
clean({
|
|
293
|
+
...pagination(opts),
|
|
294
|
+
received_for: opts.receivedFor,
|
|
295
|
+
search: opts.search,
|
|
296
|
+
query: opts.query,
|
|
297
|
+
created_after: opts.createdAfter,
|
|
298
|
+
created_before: opts.createdBefore,
|
|
299
|
+
}),
|
|
250
300
|
),
|
|
251
301
|
);
|
|
252
302
|
|
|
@@ -322,6 +372,12 @@ function register({ group, leaf, act }) {
|
|
|
322
372
|
},
|
|
323
373
|
);
|
|
324
374
|
|
|
375
|
+
act(
|
|
376
|
+
leaf(receiving, 'mark-read <id>', 'Mark a received email read (or unread with --unread)')
|
|
377
|
+
.option('--unread', 'mark it unread instead'),
|
|
378
|
+
({ client, opts, args: [id] }) => client.emails.receiving.update(id, { read: !opts.unread }),
|
|
379
|
+
);
|
|
380
|
+
|
|
325
381
|
act(leaf(receiving, 'delete <id>', 'Delete a received email'), ({ client, args: [id] }) =>
|
|
326
382
|
client.emails.receiving.remove(id),
|
|
327
383
|
);
|
package/src/commands/events.js
CHANGED
|
@@ -32,6 +32,10 @@ function register({ group, leaf, act }) {
|
|
|
32
32
|
client.events.create(clean({ name: opts.name, schema: parseJson(opts.schema, '--schema') })),
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
+
act(leaf(events, 'get <idOrName>', 'Retrieve a custom-event definition by its id or name'), ({ client, args: [id] }) =>
|
|
36
|
+
client.events.get(id),
|
|
37
|
+
);
|
|
38
|
+
|
|
35
39
|
act(withPagination(leaf(events, 'list', 'List custom-event definitions')), ({ client, opts }) =>
|
|
36
40
|
client.events.list(pagination(opts)),
|
|
37
41
|
);
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { CliError, collect, append, parseJson, clean, toInt, withPagination, pagination } = require('../helpers');
|
|
6
|
+
|
|
7
|
+
/** Same rule and help text as `emails send --idempotency-key` (1-255 characters, server-validated). */
|
|
8
|
+
const IDEMPOTENCY_KEY_HELP = 'idempotency key for safe retries (1-255 characters)';
|
|
9
|
+
|
|
10
|
+
/** Recipient and body flags shared by reply, forward and the draft commands. */
|
|
11
|
+
function withMessageFlags(cmd) {
|
|
12
|
+
return cmd
|
|
13
|
+
.option('--cc <address>', 'cc recipient (repeatable or comma-separated)', collect)
|
|
14
|
+
.option('--bcc <address>', 'bcc recipient (repeatable or comma-separated)', collect)
|
|
15
|
+
.option('--subject <subject>', 'subject line')
|
|
16
|
+
.option('--html <html>', 'HTML body')
|
|
17
|
+
.option('--text <text>', 'plain-text body');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function messageBody(opts) {
|
|
21
|
+
return { to: opts.to, cc: opts.cc, bcc: opts.bcc, subject: opts.subject, html: opts.html, text: opts.text };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Files to attach: `{ filename, content (base64) }` read from each --attachment path. */
|
|
25
|
+
function readAttachments(paths) {
|
|
26
|
+
if (!paths) return undefined;
|
|
27
|
+
return paths.map((p) => {
|
|
28
|
+
let buf;
|
|
29
|
+
try { buf = fs.readFileSync(p); }
|
|
30
|
+
catch (err) { throw new CliError(`Cannot read --attachment ${p}: ${err.message}`); }
|
|
31
|
+
return { filename: path.basename(p), content: buf.toString('base64') };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Thread list / search query flags. */
|
|
36
|
+
function withThreadQuery(cmd) {
|
|
37
|
+
return cmd
|
|
38
|
+
.option('--folder <folder>', 'inbox (default) | sent | archive | spam | trash')
|
|
39
|
+
.option('--label <labelId>', 'only threads carrying this label id')
|
|
40
|
+
.option('--query <text>', 'search words and operators: from: to: label: has:attachment is:unread after:YYYY-MM-DD before:YYYY-MM-DD')
|
|
41
|
+
.option('--from <address>', 'from these addresses (repeatable or comma-separated)', collect)
|
|
42
|
+
.option('--to <address>', 'to these addresses (repeatable or comma-separated)', collect)
|
|
43
|
+
.option('--start-date <day>', 'last activity on or after this day, YYYY-MM-DD')
|
|
44
|
+
.option('--end-date <day>', 'last activity before this day, YYYY-MM-DD')
|
|
45
|
+
.option('--unread', 'only unread threads')
|
|
46
|
+
.option('--read', 'only read threads')
|
|
47
|
+
.option('--limit <n>', 'threads per page (1-100, default 20)')
|
|
48
|
+
.option('--after <threadId>', 'the last thread id of the previous page');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function threadQuery(opts) {
|
|
52
|
+
if (opts.unread && opts.read) throw new CliError('Provide only one of --unread or --read.');
|
|
53
|
+
return clean({
|
|
54
|
+
folder: opts.folder, label: opts.label, query: opts.query, from: opts.from, to: opts.to,
|
|
55
|
+
start_date: opts.startDate, end_date: opts.endDate,
|
|
56
|
+
unread: opts.unread ? true : opts.read ? false : undefined,
|
|
57
|
+
limit: toInt(opts.limit, '--limit'), after: opts.after,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function register({ group, leaf, act }) {
|
|
62
|
+
const inboxes = group('inboxes', 'Manage shared inboxes, their threads, labels, drafts and agent settings');
|
|
63
|
+
|
|
64
|
+
act(
|
|
65
|
+
leaf(inboxes, 'create', 'Create an inbox on a domain verified for sending')
|
|
66
|
+
.option('--email-address <address>', 'the full address, e.g. support@yourdomain.com')
|
|
67
|
+
.option('--local <part>', 'the part before @ (with --domain-id)')
|
|
68
|
+
.option('--domain-id <id>', 'the domain (with --local)')
|
|
69
|
+
.option('--name <name>', 'display name for the inbox')
|
|
70
|
+
.option('--from-name <name>', 'the name recipients see on mail sent from it')
|
|
71
|
+
.option('--receiving <how>', "when the domain does not receive yet: 'domain' | 'forward'"),
|
|
72
|
+
({ client, opts }) => {
|
|
73
|
+
if (!opts.emailAddress && !(opts.local && opts.domainId)) {
|
|
74
|
+
throw new CliError('Provide --email-address, or --local with --domain-id.');
|
|
75
|
+
}
|
|
76
|
+
return client.inboxes.create(clean({
|
|
77
|
+
email_address: opts.emailAddress, local: opts.local, domain_id: opts.domainId,
|
|
78
|
+
name: opts.name, from_name: opts.fromName, receiving: opts.receiving,
|
|
79
|
+
}));
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
act(withPagination(leaf(inboxes, 'list', 'List inboxes, newest first')), ({ client, opts }) =>
|
|
84
|
+
client.inboxes.list(pagination(opts)),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
act(leaf(inboxes, 'get <inboxId>', 'Retrieve an inbox'), ({ client, args: [id] }) => client.inboxes.get(id));
|
|
88
|
+
|
|
89
|
+
act(
|
|
90
|
+
leaf(inboxes, 'update <inboxId>', 'Change an inbox name, from name or view')
|
|
91
|
+
.option('--name <name>', 'display name')
|
|
92
|
+
.option('--from-name <name>', 'the name recipients see')
|
|
93
|
+
.option('--view-mode <mode>', 'list | grouped | board | swimlanes | cards'),
|
|
94
|
+
({ client, opts, args: [id] }) =>
|
|
95
|
+
client.inboxes.update(id, clean({ name: opts.name, from_name: opts.fromName, view_mode: opts.viewMode })),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
act(
|
|
99
|
+
leaf(inboxes, 'delete <inboxId>', 'Delete an inbox with its threads, labels and drafts (the mail stays under Emails)'),
|
|
100
|
+
({ client, args: [id] }) => client.inboxes.remove(id),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// ---- labels ----
|
|
104
|
+
const labels = inboxes.command('labels').description("Manage an inbox's labels");
|
|
105
|
+
|
|
106
|
+
act(
|
|
107
|
+
leaf(labels, 'create <inboxId>', 'Create a label')
|
|
108
|
+
.requiredOption('--name <name>', 'label name (unique per inbox)')
|
|
109
|
+
.option('--color <color>', 'gray | red | orange | amber | green | teal | blue | violet | pink'),
|
|
110
|
+
({ client, opts, args: [id] }) => client.inboxes.labels.create(id, clean({ name: opts.name, color: opts.color })),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
act(withPagination(leaf(labels, 'list <inboxId>', 'List labels with their thread counts')), ({ client, opts, args: [id] }) =>
|
|
114
|
+
client.inboxes.labels.list(id, pagination(opts)),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
act(
|
|
118
|
+
leaf(labels, 'update <inboxId> <labelId>', 'Rename or recolor a label')
|
|
119
|
+
.option('--name <name>', 'new name')
|
|
120
|
+
.option('--color <color>', 'new color'),
|
|
121
|
+
({ client, opts, args: [id, labelId] }) =>
|
|
122
|
+
client.inboxes.labels.update(id, labelId, clean({ name: opts.name, color: opts.color })),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
act(
|
|
126
|
+
leaf(labels, 'delete <inboxId> <labelId>', 'Delete a label (it comes off every thread)'),
|
|
127
|
+
({ client, args: [id, labelId] }) => client.inboxes.labels.remove(id, labelId),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// ---- threads ----
|
|
131
|
+
const threads = inboxes.command('threads').description("Manage an inbox's conversations and their emails");
|
|
132
|
+
|
|
133
|
+
act(withThreadQuery(leaf(threads, 'list <inboxId>', 'One page of threads, most recently active first')),
|
|
134
|
+
({ client, opts, args: [id] }) => client.inboxes.threads.list(id, threadQuery(opts)));
|
|
135
|
+
|
|
136
|
+
act(withThreadQuery(leaf(threads, 'search <inboxId>', 'Search threads (across Inbox, Sent and Archive unless --folder is spam or trash)')),
|
|
137
|
+
({ client, opts, args: [id] }) => client.inboxes.threads.search(id, threadQuery(opts)));
|
|
138
|
+
|
|
139
|
+
act(leaf(threads, 'get <inboxId> <threadId>', 'Retrieve a thread'), ({ client, args: [id, threadId] }) =>
|
|
140
|
+
client.inboxes.threads.get(id, threadId),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
act(
|
|
144
|
+
leaf(threads, 'update <inboxId> <threadId>', 'File, mark read/unread or assign a thread')
|
|
145
|
+
.option('--folder <folder>', 'inbox | archive | spam | trash')
|
|
146
|
+
.option('--read', 'mark it read')
|
|
147
|
+
.option('--unread', 'mark it unread')
|
|
148
|
+
.option('--assignee <email>', "a teammate's address")
|
|
149
|
+
.option('--unassign', 'remove the assignee'),
|
|
150
|
+
({ client, opts, args: [id, threadId] }) => {
|
|
151
|
+
if (opts.read && opts.unread) throw new CliError('Provide only one of --read or --unread.');
|
|
152
|
+
if (opts.assignee && opts.unassign) throw new CliError('Provide only one of --assignee or --unassign.');
|
|
153
|
+
return client.inboxes.threads.update(id, threadId, clean({
|
|
154
|
+
folder: opts.folder,
|
|
155
|
+
read: opts.read ? true : undefined,
|
|
156
|
+
unread: opts.unread ? true : undefined,
|
|
157
|
+
assignee: opts.unassign ? null : opts.assignee,
|
|
158
|
+
}));
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
act(
|
|
163
|
+
leaf(threads, 'delete <inboxId> <threadId>', 'Move a thread to Trash (one already in Trash is removed for good)'),
|
|
164
|
+
({ client, args: [id, threadId] }) => client.inboxes.threads.remove(id, threadId),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
act(
|
|
168
|
+
leaf(threads, 'add-labels <inboxId> <threadId>', 'Add labels to a thread')
|
|
169
|
+
.requiredOption('--labels <labelId>', 'label ids (repeatable or comma-separated)', collect),
|
|
170
|
+
({ client, opts, args: [id, threadId] }) => client.inboxes.threads.addLabels(id, threadId, { labels: opts.labels }),
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
act(
|
|
174
|
+
leaf(threads, 'set-labels <inboxId> <threadId>', "Make these the thread's only labels (--clear removes all)")
|
|
175
|
+
.option('--labels <labelId>', 'label ids (repeatable or comma-separated)', collect)
|
|
176
|
+
.option('--clear', 'remove every label'),
|
|
177
|
+
({ client, opts, args: [id, threadId] }) => {
|
|
178
|
+
if (opts.labels && opts.clear) throw new CliError('Provide only one of --labels or --clear.');
|
|
179
|
+
if (!opts.labels && !opts.clear) throw new CliError('Provide --labels or --clear.');
|
|
180
|
+
return client.inboxes.threads.setLabels(id, threadId, { labels: opts.clear ? [] : opts.labels });
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
act(
|
|
185
|
+
leaf(threads, 'remove-label <inboxId> <threadId> <labelId>', 'Take one label off a thread'),
|
|
186
|
+
({ client, args: [id, threadId, labelId] }) => client.inboxes.threads.removeLabel(id, threadId, labelId),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
act(
|
|
190
|
+
leaf(threads, 'emails <inboxId> <threadId>', 'Every message of a thread, oldest first'),
|
|
191
|
+
({ client, args: [id, threadId] }) => client.inboxes.threads.listEmails(id, threadId),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
act(
|
|
195
|
+
leaf(threads, 'email <inboxId> <threadId> <emailId>', 'Retrieve one message of a thread'),
|
|
196
|
+
({ client, args: [id, threadId, emailId] }) => client.inboxes.threads.getEmail(id, threadId, emailId),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
act(
|
|
200
|
+
withMessageFlags(leaf(threads, 'reply <inboxId> <threadId> <emailId>', 'Reply from the inbox address (to the sender unless --to is given)'))
|
|
201
|
+
.option('--to <address>', 'recipients (repeatable or comma-separated)', collect)
|
|
202
|
+
.option('--reply-all', 'reply to everyone on the message')
|
|
203
|
+
.option('--attachment <path>', 'file to attach (repeatable)', append)
|
|
204
|
+
.option('--idempotency-key <key>', IDEMPOTENCY_KEY_HELP),
|
|
205
|
+
({ client, opts, args: [id, threadId, emailId] }) => {
|
|
206
|
+
const body = clean({ ...messageBody(opts), reply_all: opts.replyAll, attachments: readAttachments(opts.attachment) });
|
|
207
|
+
return client.inboxes.threads.reply(id, threadId, emailId, body,
|
|
208
|
+
opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : undefined);
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
act(
|
|
213
|
+
withMessageFlags(leaf(threads, 'forward <inboxId> <threadId> <emailId>', 'Forward a message (its received files are attached)'))
|
|
214
|
+
.requiredOption('--to <address>', 'recipients (repeatable or comma-separated)', collect)
|
|
215
|
+
.option('--attachment <path>', 'extra file to attach (repeatable)', append)
|
|
216
|
+
.option('--idempotency-key <key>', IDEMPOTENCY_KEY_HELP),
|
|
217
|
+
({ client, opts, args: [id, threadId, emailId] }) =>
|
|
218
|
+
client.inboxes.threads.forward(id, threadId, emailId, clean({ ...messageBody(opts), attachments: readAttachments(opts.attachment) }),
|
|
219
|
+
opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : undefined),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
// ---- drafts ----
|
|
223
|
+
const drafts = inboxes.command('drafts').description("Manage an inbox's unsent messages");
|
|
224
|
+
|
|
225
|
+
act(
|
|
226
|
+
withMessageFlags(leaf(drafts, 'create <inboxId>', 'Start a draft (compose, or an answer to --email-id)'))
|
|
227
|
+
.option('--to <address>', 'recipients (repeatable or comma-separated)', collect)
|
|
228
|
+
.option('--mode <mode>', 'compose (default) | reply | reply_all | forward')
|
|
229
|
+
.option('--email-id <id>', 'the thread email being answered (not for compose)')
|
|
230
|
+
.option('--attachment <path>', 'file to attach (repeatable; up to 3 MB in total)', append),
|
|
231
|
+
({ client, opts, args: [id] }) =>
|
|
232
|
+
client.inboxes.drafts.create(id, clean({
|
|
233
|
+
mode: opts.mode, email_id: opts.emailId, ...messageBody(opts), attachments: readAttachments(opts.attachment),
|
|
234
|
+
})),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
act(withPagination(leaf(drafts, 'list <inboxId>', 'Unsent messages, most recently edited first')), ({ client, opts, args: [id] }) =>
|
|
238
|
+
client.inboxes.drafts.list(id, pagination(opts)),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
act(leaf(drafts, 'get <inboxId> <draftId>', 'Retrieve a draft'), ({ client, args: [id, draftId] }) =>
|
|
242
|
+
client.inboxes.drafts.get(id, draftId),
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
act(
|
|
246
|
+
withMessageFlags(leaf(drafts, 'update <inboxId> <draftId>', 'Change any of to, cc, bcc, subject, html, text'))
|
|
247
|
+
.option('--to <address>', 'recipients (repeatable or comma-separated)', collect),
|
|
248
|
+
({ client, opts, args: [id, draftId] }) => {
|
|
249
|
+
const body = clean(messageBody(opts));
|
|
250
|
+
if (!Object.keys(body).length) throw new CliError('Provide at least one of --to, --cc, --bcc, --subject, --html or --text.');
|
|
251
|
+
return client.inboxes.drafts.update(id, draftId, body);
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
act(leaf(drafts, 'delete <inboxId> <draftId>', 'Discard a draft'), ({ client, args: [id, draftId] }) =>
|
|
256
|
+
client.inboxes.drafts.remove(id, draftId),
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
act(
|
|
260
|
+
leaf(drafts, 'send <inboxId> <draftId>', 'Send a draft from the inbox address and remove it')
|
|
261
|
+
.option('--idempotency-key <key>', IDEMPOTENCY_KEY_HELP),
|
|
262
|
+
({ client, opts, args: [id, draftId] }) =>
|
|
263
|
+
client.inboxes.drafts.send(id, draftId, opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : undefined),
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// ---- agent ----
|
|
267
|
+
const agent = inboxes.command('agent').description("An inbox's AI agent settings (settings only; it never acts on its own)");
|
|
268
|
+
|
|
269
|
+
act(leaf(agent, 'get <inboxId>', 'Retrieve the agent settings'), ({ client, args: [id] }) =>
|
|
270
|
+
client.inboxes.agent.get(id),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
act(
|
|
274
|
+
leaf(agent, 'update <inboxId>', 'Change any part of the agent settings; the rest is kept')
|
|
275
|
+
.option('--instructions <text>', 'instructions (up to 4,000 characters)')
|
|
276
|
+
.option('--actions <action>', 'draft_reply, apply_label, assign, archive, mark_spam, forward (repeatable or comma-separated)', collect)
|
|
277
|
+
.option('--tone <json>', 'tone as JSON, e.g. \'{"length":30,"register":20}\' (0-100 each)'),
|
|
278
|
+
({ client, opts, args: [id] }) => {
|
|
279
|
+
const body = clean({ instructions: opts.instructions, actions: opts.actions, tone: parseJson(opts.tone, '--tone') });
|
|
280
|
+
if (!Object.keys(body).length) throw new CliError('Provide --instructions, --actions or --tone.');
|
|
281
|
+
return client.inboxes.agent.update(id, body);
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
module.exports = { register };
|
package/src/commands/segments.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { parseJson, clean, withPagination, pagination } = require('../helpers');
|
|
3
|
+
const { CliError, parseJson, clean, toInt, withPagination, pagination } = require('../helpers');
|
|
4
4
|
|
|
5
5
|
function register({ group, leaf, act }) {
|
|
6
6
|
const segments = group('segments', 'Manage contact segments (scoped to a sending domain)');
|
|
@@ -43,6 +43,25 @@ function register({ group, leaf, act }) {
|
|
|
43
43
|
client.segments.update(id, clean({ name: opts.name, filter: parseJson(opts.filter, '--filter') })),
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
+
act(
|
|
47
|
+
leaf(segments, 'move <id>', 'Move one contact (--contact-id) or all (--all) to another segment of the same audience')
|
|
48
|
+
.requiredOption('--destination-id <id>', 'the segment to move contacts into')
|
|
49
|
+
.option('--contact-id <id>', 'move this one contact')
|
|
50
|
+
.option('--all', 'move every contact in the segment')
|
|
51
|
+
.option('--preview', 'count and check only; nothing moves')
|
|
52
|
+
.option('--expected-count <n>', 'fail (409) unless the source still holds exactly this many contacts'),
|
|
53
|
+
({ client, opts, args: [id] }) => {
|
|
54
|
+
if (!!opts.contactId === !!opts.all) throw new CliError('Pass exactly one of --contact-id or --all.');
|
|
55
|
+
return client.segments.move(id, clean({
|
|
56
|
+
destination_id: opts.destinationId,
|
|
57
|
+
contact_id: opts.contactId,
|
|
58
|
+
all: opts.all,
|
|
59
|
+
preview: opts.preview,
|
|
60
|
+
expected_count: toInt(opts.expectedCount, '--expected-count'),
|
|
61
|
+
}));
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
|
|
46
65
|
act(leaf(segments, 'delete <id>', 'Delete a segment'), ({ client, args: [id] }) =>
|
|
47
66
|
client.segments.remove(id),
|
|
48
67
|
);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const { CliError, collect, clean, withPagination, pagination } = require('../helpers');
|
|
5
|
+
|
|
6
|
+
/** Addresses from --emails and/or one-per-line (or comma-separated) --file. */
|
|
7
|
+
function addresses(opts) {
|
|
8
|
+
let out = opts.emails || [];
|
|
9
|
+
if (opts.file) {
|
|
10
|
+
let text;
|
|
11
|
+
try { text = fs.readFileSync(opts.file, 'utf8'); }
|
|
12
|
+
catch (err) { throw new CliError(`Cannot read --file ${opts.file}: ${err.message}`); }
|
|
13
|
+
out = out.concat(text.split(/[\s,;]+/).map((s) => s.trim()).filter(Boolean));
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The suppression list: addresses SendDart will not send to.
|
|
19
|
+
function register({ group, leaf, act }) {
|
|
20
|
+
const suppressions = group('suppressions', 'Manage the suppression list (addresses SendDart will not send to)');
|
|
21
|
+
|
|
22
|
+
act(
|
|
23
|
+
leaf(suppressions, 'add <email>', 'Add one address (already listed: the existing row is returned)'),
|
|
24
|
+
({ client, args: [email] }) => client.suppressions.create({ email }),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
act(
|
|
28
|
+
withPagination(leaf(suppressions, 'list', 'List suppressions, newest first'))
|
|
29
|
+
.option('--origin <origin>', "'bounce' | 'complaint' | 'manual' | 'unsubscribe'")
|
|
30
|
+
.option('--search <text>', 'match part of the address')
|
|
31
|
+
.option('--created-after <iso>', 'added at or after this ISO 8601 date-time')
|
|
32
|
+
.option('--created-before <iso>', 'added before this ISO 8601 date-time'),
|
|
33
|
+
({ client, opts }) =>
|
|
34
|
+
client.suppressions.list(clean({
|
|
35
|
+
...pagination(opts),
|
|
36
|
+
origin: opts.origin,
|
|
37
|
+
search: opts.search,
|
|
38
|
+
created_after: opts.createdAfter,
|
|
39
|
+
created_before: opts.createdBefore,
|
|
40
|
+
})),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
act(leaf(suppressions, 'get <idOrEmail>', 'Retrieve a suppression by its id or address'), ({ client, args: [ref] }) =>
|
|
44
|
+
client.suppressions.get(ref),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
act(
|
|
48
|
+
leaf(suppressions, 'delete <idOrEmail>', 'Remove a suppression (by address: every row for it)'),
|
|
49
|
+
({ client, args: [ref] }) => client.suppressions.remove(ref),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
act(
|
|
53
|
+
leaf(suppressions, 'batch-add', 'Add up to 1,000 addresses (skipped ones are listed with a reason)')
|
|
54
|
+
.option('--emails <address>', 'addresses (repeatable or comma-separated)', collect)
|
|
55
|
+
.option('--file <path>', 'a file of addresses, one per line'),
|
|
56
|
+
({ client, opts }) => {
|
|
57
|
+
const emails = addresses(opts);
|
|
58
|
+
if (!emails.length) throw new CliError('Provide --emails or --file.');
|
|
59
|
+
return client.suppressions.batchAdd({ emails });
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
act(
|
|
64
|
+
leaf(suppressions, 'batch-remove', 'Remove up to 1,000 suppressions by id and/or address')
|
|
65
|
+
.option('--ids <id>', 'suppression ids (repeatable or comma-separated)', collect)
|
|
66
|
+
.option('--emails <address>', 'addresses (repeatable or comma-separated)', collect)
|
|
67
|
+
.option('--file <path>', 'a file of addresses, one per line'),
|
|
68
|
+
({ client, opts }) => {
|
|
69
|
+
const emails = addresses(opts);
|
|
70
|
+
if (!emails.length && !opts.ids) throw new CliError('Provide --ids, --emails or --file.');
|
|
71
|
+
return client.suppressions.batchRemove(clean({ ids: opts.ids, emails: emails.length ? emails : undefined }));
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { register };
|
|
@@ -45,8 +45,10 @@ function register({ group, leaf, act }) {
|
|
|
45
45
|
client.templates.get(id),
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
act(
|
|
49
|
-
|
|
48
|
+
act(
|
|
49
|
+
withPagination(leaf(templates, 'list', 'List templates'))
|
|
50
|
+
.option('--folder-id <id>', "only templates in this folder, or 'root' for templates in no folder"),
|
|
51
|
+
({ client, opts }) => client.templates.list(clean({ ...pagination(opts), folder_id: opts.folderId })),
|
|
50
52
|
);
|
|
51
53
|
|
|
52
54
|
act(
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// GET /usage — the account's meters and limits.
|
|
4
|
+
function register({ group, leaf, act }) {
|
|
5
|
+
const usage = group('usage', "Show the account's usage meters and limits");
|
|
6
|
+
|
|
7
|
+
act(leaf(usage, 'get', 'Usage meters and limits (limit null = unlimited)'), ({ client }) =>
|
|
8
|
+
client.usage.get(),
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { register };
|
package/src/commands/webhooks.js
CHANGED
|
@@ -56,6 +56,33 @@ function register({ group, leaf, act }) {
|
|
|
56
56
|
},
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
+
act(
|
|
60
|
+
leaf(webhooks, 'events <id>', 'What this endpoint was sent, newest first (page with --after = the last event id)')
|
|
61
|
+
.option('--limit <n>', 'events per page (1-100, default 20)')
|
|
62
|
+
.option('--after <eventId>', 'the last event id (msg_…) of the previous page')
|
|
63
|
+
.option('--status <status>', "'delivered' | 'failed' | 'retrying'")
|
|
64
|
+
.option('--type <event>', 'one event name, e.g. email.bounced'),
|
|
65
|
+
({ client, opts, args: [id] }) =>
|
|
66
|
+
client.webhooks.listEvents(id, clean({
|
|
67
|
+
limit: toInt(opts.limit, '--limit'), after: opts.after, status: opts.status, type: opts.type,
|
|
68
|
+
})),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
act(
|
|
72
|
+
leaf(webhooks, 'event <id> <eventId>', 'Retrieve one event with the payload that was sent'),
|
|
73
|
+
({ client, args: [id, eventId] }) => client.webhooks.getEvent(id, eventId),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
act(
|
|
77
|
+
leaf(webhooks, 'event-attempts <id> <eventId>', 'Every try at delivering one event, oldest first'),
|
|
78
|
+
({ client, args: [id, eventId] }) => client.webhooks.listEventAttempts(id, eventId),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
act(
|
|
82
|
+
leaf(webhooks, 'replay-event <id> <eventId>', 'Send one event again now (same payload and id, one attempt)'),
|
|
83
|
+
({ client, args: [id, eventId] }) => client.webhooks.replayEvent(id, eventId),
|
|
84
|
+
);
|
|
85
|
+
|
|
59
86
|
act(leaf(webhooks, 'delete <id>', 'Delete a webhook'), ({ client, args: [id] }) =>
|
|
60
87
|
client.webhooks.remove(id),
|
|
61
88
|
);
|