resend-cli 1.0.3 → 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/.claude/settings.local.json +14 -0
- package/.github/scripts/pr-title-check.js +34 -0
- package/.github/workflows/ci.yml +32 -0
- package/.github/workflows/pr-title-check.yml +13 -0
- package/.github/workflows/release.yml +93 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -21
- package/README.md +416 -19
- package/biome.json +36 -0
- package/bun.lock +76 -0
- package/bunfig.toml +2 -0
- package/install.ps1 +140 -0
- package/install.sh +294 -0
- package/package.json +43 -22
- package/src/cli.ts +65 -0
- package/src/commands/api-keys/create.ts +114 -0
- package/src/commands/api-keys/delete.ts +47 -0
- package/src/commands/api-keys/index.ts +26 -0
- package/src/commands/api-keys/list.ts +35 -0
- package/src/commands/api-keys/utils.ts +8 -0
- package/src/commands/auth/index.ts +20 -0
- package/src/commands/auth/login.ts +211 -0
- package/src/commands/auth/logout.ts +105 -0
- package/src/commands/broadcasts/create.ts +196 -0
- package/src/commands/broadcasts/delete.ts +46 -0
- package/src/commands/broadcasts/get.ts +59 -0
- package/src/commands/broadcasts/index.ts +43 -0
- package/src/commands/broadcasts/list.ts +60 -0
- package/src/commands/broadcasts/send.ts +56 -0
- package/src/commands/broadcasts/update.ts +95 -0
- package/src/commands/broadcasts/utils.ts +35 -0
- package/src/commands/contact-properties/create.ts +118 -0
- package/src/commands/contact-properties/delete.ts +48 -0
- package/src/commands/contact-properties/get.ts +46 -0
- package/src/commands/contact-properties/index.ts +48 -0
- package/src/commands/contact-properties/list.ts +68 -0
- package/src/commands/contact-properties/update.ts +88 -0
- package/src/commands/contact-properties/utils.ts +17 -0
- package/src/commands/contacts/add-segment.ts +78 -0
- package/src/commands/contacts/create.ts +122 -0
- package/src/commands/contacts/delete.ts +49 -0
- package/src/commands/contacts/get.ts +53 -0
- package/src/commands/contacts/index.ts +58 -0
- package/src/commands/contacts/list.ts +57 -0
- package/src/commands/contacts/remove-segment.ts +48 -0
- package/src/commands/contacts/segments.ts +39 -0
- package/src/commands/contacts/topics.ts +45 -0
- package/src/commands/contacts/update-topics.ts +90 -0
- package/src/commands/contacts/update.ts +77 -0
- package/src/commands/contacts/utils.ts +119 -0
- package/src/commands/doctor.ts +298 -0
- package/src/commands/domains/create.ts +83 -0
- package/src/commands/domains/delete.ts +42 -0
- package/src/commands/domains/get.ts +47 -0
- package/src/commands/domains/index.ts +35 -0
- package/src/commands/domains/list.ts +53 -0
- package/src/commands/domains/update.ts +75 -0
- package/src/commands/domains/utils.ts +44 -0
- package/src/commands/domains/verify.ts +38 -0
- package/src/commands/emails/batch.ts +140 -0
- package/src/commands/emails/index.ts +24 -0
- package/src/commands/emails/receiving/attachment.ts +55 -0
- package/src/commands/emails/receiving/attachments.ts +68 -0
- package/src/commands/emails/receiving/get.ts +58 -0
- package/src/commands/emails/receiving/index.ts +28 -0
- package/src/commands/emails/receiving/list.ts +59 -0
- package/src/commands/emails/receiving/utils.ts +38 -0
- package/src/commands/emails/send.ts +189 -0
- package/src/commands/segments/create.ts +50 -0
- package/src/commands/segments/delete.ts +47 -0
- package/src/commands/segments/get.ts +38 -0
- package/src/commands/segments/index.ts +36 -0
- package/src/commands/segments/list.ts +58 -0
- package/src/commands/segments/utils.ts +7 -0
- package/src/commands/teams/index.ts +10 -0
- package/src/commands/teams/list.ts +35 -0
- package/src/commands/teams/remove.ts +83 -0
- package/src/commands/teams/switch.ts +73 -0
- package/src/commands/topics/create.ts +73 -0
- package/src/commands/topics/delete.ts +47 -0
- package/src/commands/topics/get.ts +42 -0
- package/src/commands/topics/index.ts +42 -0
- package/src/commands/topics/list.ts +34 -0
- package/src/commands/topics/update.ts +59 -0
- package/src/commands/topics/utils.ts +16 -0
- package/src/commands/webhooks/create.ts +128 -0
- package/src/commands/webhooks/delete.ts +49 -0
- package/src/commands/webhooks/get.ts +42 -0
- package/src/commands/webhooks/index.ts +44 -0
- package/src/commands/webhooks/list.ts +55 -0
- package/src/commands/webhooks/update.ts +83 -0
- package/src/commands/webhooks/utils.ts +36 -0
- package/src/commands/whoami.ts +71 -0
- package/src/lib/actions.ts +157 -0
- package/src/lib/client.ts +29 -0
- package/src/lib/config.ts +211 -0
- package/src/lib/files.ts +15 -0
- package/src/lib/help-text.ts +36 -0
- package/src/lib/output.ts +54 -0
- package/src/lib/pagination.ts +36 -0
- package/src/lib/prompts.ts +149 -0
- package/src/lib/spinner.ts +89 -0
- package/src/lib/table.ts +57 -0
- package/src/lib/tty.ts +28 -0
- package/src/lib/version.ts +4 -0
- package/tests/commands/api-keys/create.test.ts +195 -0
- package/tests/commands/api-keys/delete.test.ts +156 -0
- package/tests/commands/api-keys/list.test.ts +133 -0
- package/tests/commands/auth/login.test.ts +119 -0
- package/tests/commands/auth/logout.test.ts +146 -0
- package/tests/commands/broadcasts/create.test.ts +447 -0
- package/tests/commands/broadcasts/delete.test.ts +182 -0
- package/tests/commands/broadcasts/get.test.ts +146 -0
- package/tests/commands/broadcasts/list.test.ts +196 -0
- package/tests/commands/broadcasts/send.test.ts +161 -0
- package/tests/commands/broadcasts/update.test.ts +283 -0
- package/tests/commands/contact-properties/create.test.ts +250 -0
- package/tests/commands/contact-properties/delete.test.ts +183 -0
- package/tests/commands/contact-properties/get.test.ts +144 -0
- package/tests/commands/contact-properties/list.test.ts +180 -0
- package/tests/commands/contact-properties/update.test.ts +216 -0
- package/tests/commands/contacts/add-segment.test.ts +188 -0
- package/tests/commands/contacts/create.test.ts +270 -0
- package/tests/commands/contacts/delete.test.ts +192 -0
- package/tests/commands/contacts/get.test.ts +148 -0
- package/tests/commands/contacts/list.test.ts +175 -0
- package/tests/commands/contacts/remove-segment.test.ts +166 -0
- package/tests/commands/contacts/segments.test.ts +167 -0
- package/tests/commands/contacts/topics.test.ts +163 -0
- package/tests/commands/contacts/update-topics.test.ts +247 -0
- package/tests/commands/contacts/update.test.ts +205 -0
- package/tests/commands/doctor.test.ts +165 -0
- package/tests/commands/domains/create.test.ts +192 -0
- package/tests/commands/domains/delete.test.ts +156 -0
- package/tests/commands/domains/get.test.ts +137 -0
- package/tests/commands/domains/list.test.ts +164 -0
- package/tests/commands/domains/update.test.ts +223 -0
- package/tests/commands/domains/verify.test.ts +117 -0
- package/tests/commands/emails/batch.test.ts +313 -0
- package/tests/commands/emails/receiving/attachment.test.ts +140 -0
- package/tests/commands/emails/receiving/attachments.test.ts +168 -0
- package/tests/commands/emails/receiving/get.test.ts +140 -0
- package/tests/commands/emails/receiving/list.test.ts +181 -0
- package/tests/commands/emails/send.test.ts +309 -0
- package/tests/commands/segments/create.test.ts +163 -0
- package/tests/commands/segments/delete.test.ts +182 -0
- package/tests/commands/segments/get.test.ts +137 -0
- package/tests/commands/segments/list.test.ts +173 -0
- package/tests/commands/teams/list.test.ts +63 -0
- package/tests/commands/teams/remove.test.ts +103 -0
- package/tests/commands/teams/switch.test.ts +96 -0
- package/tests/commands/topics/create.test.ts +191 -0
- package/tests/commands/topics/delete.test.ts +156 -0
- package/tests/commands/topics/get.test.ts +125 -0
- package/tests/commands/topics/list.test.ts +124 -0
- package/tests/commands/topics/update.test.ts +177 -0
- package/tests/commands/webhooks/create.test.ts +224 -0
- package/tests/commands/webhooks/delete.test.ts +156 -0
- package/tests/commands/webhooks/get.test.ts +125 -0
- package/tests/commands/webhooks/list.test.ts +177 -0
- package/tests/commands/webhooks/update.test.ts +206 -0
- package/tests/commands/whoami.test.ts +99 -0
- package/tests/helpers.ts +93 -0
- package/tests/lib/client.test.ts +71 -0
- package/tests/lib/config.test.ts +414 -0
- package/tests/lib/files.test.ts +65 -0
- package/tests/lib/help-text.test.ts +96 -0
- package/tests/lib/output.test.ts +127 -0
- package/tests/lib/prompts.test.ts +178 -0
- package/tests/lib/spinner.test.ts +146 -0
- package/tests/lib/table.test.ts +63 -0
- package/tests/lib/tty.test.ts +85 -0
- package/tsconfig.json +14 -0
- package/src/index.js +0 -72
- package/src/routes.js +0 -37
- package/src/sections/apikeys.js +0 -99
- package/src/sections/audiences.js +0 -84
- package/src/sections/contacts.js +0 -177
- package/src/sections/domain.js +0 -195
- package/src/sections/email.js +0 -132
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Command, Option } from '@commander-js/extra-typings';
|
|
2
|
+
import type { CreateContactPropertyOptions } from 'resend';
|
|
3
|
+
import { runCreate } from '../../lib/actions';
|
|
4
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
5
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
6
|
+
import { outputError } from '../../lib/output';
|
|
7
|
+
import { requireSelect, requireText } from '../../lib/prompts';
|
|
8
|
+
|
|
9
|
+
export const createContactPropertyCommand = new Command('create')
|
|
10
|
+
.description('Create a new contact property definition')
|
|
11
|
+
.addOption(
|
|
12
|
+
new Option(
|
|
13
|
+
'--key <key>',
|
|
14
|
+
'Property key name, used in broadcast template interpolation (e.g. company_name, department)',
|
|
15
|
+
),
|
|
16
|
+
)
|
|
17
|
+
.addOption(
|
|
18
|
+
new Option(
|
|
19
|
+
'--type <type>',
|
|
20
|
+
"Property data type: 'string' for text values, 'number' for numeric values",
|
|
21
|
+
).choices(['string', 'number'] as const),
|
|
22
|
+
)
|
|
23
|
+
.option(
|
|
24
|
+
'--fallback-value <value>',
|
|
25
|
+
'Default value used in broadcast templates when a contact has no value set for this property',
|
|
26
|
+
)
|
|
27
|
+
.addHelpText(
|
|
28
|
+
'after',
|
|
29
|
+
buildHelpText({
|
|
30
|
+
context: `Property keys are used as identifiers in broadcast HTML template interpolation:
|
|
31
|
+
{{{PROPERTY_NAME|fallback}}} — triple-brace syntax substitutes the contact's value
|
|
32
|
+
{{{company_name|Unknown}}} — falls back to "Unknown" if the property is not set
|
|
33
|
+
|
|
34
|
+
Reserved keys (cannot be used): FIRST_NAME, LAST_NAME, EMAIL, UNSUBSCRIBE_URL
|
|
35
|
+
|
|
36
|
+
Non-interactive: --key and --type are required. --fallback-value is optional.
|
|
37
|
+
Warning: do not create properties with reserved key names — they will conflict with
|
|
38
|
+
built-in contact fields and may cause unexpected behavior in broadcasts.`,
|
|
39
|
+
output: ` {"object":"contact_property","id":"<id>"}`,
|
|
40
|
+
errorCodes: [
|
|
41
|
+
'auth_error',
|
|
42
|
+
'missing_key',
|
|
43
|
+
'missing_type',
|
|
44
|
+
'invalid_fallback_value',
|
|
45
|
+
'create_error',
|
|
46
|
+
],
|
|
47
|
+
examples: [
|
|
48
|
+
'resend contact-properties create --key company_name --type string',
|
|
49
|
+
'resend contact-properties create --key company_name --type string --fallback-value "Unknown"',
|
|
50
|
+
'resend contact-properties create --key employee_count --type number --fallback-value 0',
|
|
51
|
+
'resend contact-properties create --key department --type string --json',
|
|
52
|
+
],
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
55
|
+
.action(async (opts, cmd) => {
|
|
56
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
57
|
+
|
|
58
|
+
const key = await requireText(
|
|
59
|
+
opts.key,
|
|
60
|
+
{ message: 'Property key', placeholder: 'company_name' },
|
|
61
|
+
{ message: 'Missing --key flag.', code: 'missing_key' },
|
|
62
|
+
globalOpts,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const type = await requireSelect(
|
|
66
|
+
opts.type,
|
|
67
|
+
{
|
|
68
|
+
message: 'Property data type',
|
|
69
|
+
options: [
|
|
70
|
+
{ value: 'string' as const, label: 'string — text values' },
|
|
71
|
+
{ value: 'number' as const, label: 'number — numeric values' },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{ message: 'Missing --type flag.', code: 'missing_type' },
|
|
75
|
+
globalOpts,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let fallbackValue: string | number | undefined;
|
|
79
|
+
if (opts.fallbackValue !== undefined) {
|
|
80
|
+
if (type === 'number') {
|
|
81
|
+
const parsed = parseFloat(opts.fallbackValue);
|
|
82
|
+
if (Number.isNaN(parsed)) {
|
|
83
|
+
outputError(
|
|
84
|
+
{
|
|
85
|
+
message:
|
|
86
|
+
'--fallback-value must be a valid number for number-type properties.',
|
|
87
|
+
code: 'invalid_fallback_value',
|
|
88
|
+
},
|
|
89
|
+
{ json: globalOpts.json },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
fallbackValue = parsed;
|
|
93
|
+
} else {
|
|
94
|
+
fallbackValue = opts.fallbackValue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const payload = {
|
|
99
|
+
key,
|
|
100
|
+
type,
|
|
101
|
+
...(fallbackValue !== undefined && { fallbackValue }),
|
|
102
|
+
} as CreateContactPropertyOptions;
|
|
103
|
+
|
|
104
|
+
await runCreate(
|
|
105
|
+
{
|
|
106
|
+
spinner: {
|
|
107
|
+
loading: 'Creating contact property...',
|
|
108
|
+
success: 'Contact property created',
|
|
109
|
+
fail: 'Failed to create contact property',
|
|
110
|
+
},
|
|
111
|
+
sdkCall: (resend) => resend.contactProperties.create(payload),
|
|
112
|
+
onInteractive: (data) => {
|
|
113
|
+
console.log(`\nContact property created: ${data.id}`);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
globalOpts,
|
|
117
|
+
);
|
|
118
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runDelete } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
|
|
6
|
+
export const deleteContactPropertyCommand = new Command('delete')
|
|
7
|
+
.alias('rm')
|
|
8
|
+
.description('Delete a contact property definition')
|
|
9
|
+
.argument('<id>', 'Contact property UUID')
|
|
10
|
+
.option(
|
|
11
|
+
'--yes',
|
|
12
|
+
'Skip the confirmation prompt (required in non-interactive mode)',
|
|
13
|
+
)
|
|
14
|
+
.addHelpText(
|
|
15
|
+
'after',
|
|
16
|
+
buildHelpText({
|
|
17
|
+
context: `WARNING: Deleting a property definition removes that property value from ALL contacts
|
|
18
|
+
permanently. This cannot be undone, and any broadcasts that reference this property key
|
|
19
|
+
via {{{PROPERTY_NAME}}} will render an empty string or their inline fallback instead.
|
|
20
|
+
|
|
21
|
+
Non-interactive: --yes is required to confirm deletion when stdin/stdout is not a TTY.`,
|
|
22
|
+
output: ` {"object":"contact_property","id":"<id>","deleted":true}`,
|
|
23
|
+
errorCodes: ['auth_error', 'confirmation_required', 'delete_error'],
|
|
24
|
+
examples: [
|
|
25
|
+
'resend contact-properties delete b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --yes',
|
|
26
|
+
'resend contact-properties delete b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --yes --json',
|
|
27
|
+
],
|
|
28
|
+
}),
|
|
29
|
+
)
|
|
30
|
+
.action(async (id, opts, cmd) => {
|
|
31
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
32
|
+
await runDelete(
|
|
33
|
+
id,
|
|
34
|
+
!!opts.yes,
|
|
35
|
+
{
|
|
36
|
+
confirmMessage: `Delete contact property "${id}"?\nThis will remove this property from ALL contacts permanently.`,
|
|
37
|
+
spinner: {
|
|
38
|
+
loading: 'Deleting contact property...',
|
|
39
|
+
success: 'Contact property deleted',
|
|
40
|
+
fail: 'Failed to delete contact property',
|
|
41
|
+
},
|
|
42
|
+
object: 'contact_property',
|
|
43
|
+
successMsg: 'Contact property deleted.',
|
|
44
|
+
sdkCall: (resend) => resend.contactProperties.remove(id),
|
|
45
|
+
},
|
|
46
|
+
globalOpts,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runGet } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
|
|
6
|
+
export const getContactPropertyCommand = new Command('get')
|
|
7
|
+
.description('Retrieve a contact property definition by ID')
|
|
8
|
+
.argument('<id>', 'Contact property UUID')
|
|
9
|
+
.addHelpText(
|
|
10
|
+
'after',
|
|
11
|
+
buildHelpText({
|
|
12
|
+
output: ` {
|
|
13
|
+
"object": "contact_property",
|
|
14
|
+
"id": "<uuid>",
|
|
15
|
+
"key": "company_name",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"fallbackValue": null,
|
|
18
|
+
"createdAt": "2026-01-01T00:00:00.000Z"
|
|
19
|
+
}`,
|
|
20
|
+
errorCodes: ['auth_error', 'fetch_error'],
|
|
21
|
+
examples: [
|
|
22
|
+
'resend contact-properties get b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d',
|
|
23
|
+
'resend contact-properties get b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --json',
|
|
24
|
+
],
|
|
25
|
+
}),
|
|
26
|
+
)
|
|
27
|
+
.action(async (id, _opts, cmd) => {
|
|
28
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
29
|
+
await runGet(
|
|
30
|
+
{
|
|
31
|
+
spinner: {
|
|
32
|
+
loading: 'Fetching contact property...',
|
|
33
|
+
success: 'Contact property fetched',
|
|
34
|
+
fail: 'Failed to fetch contact property',
|
|
35
|
+
},
|
|
36
|
+
sdkCall: (resend) => resend.contactProperties.get(id),
|
|
37
|
+
onInteractive: (data) => {
|
|
38
|
+
console.log(`\n${data.key} (${data.type})`);
|
|
39
|
+
console.log(`ID: ${data.id}`);
|
|
40
|
+
console.log(`Created: ${data.createdAt}`);
|
|
41
|
+
console.log(`Fallback value: ${data.fallbackValue ?? '(none)'}`);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
globalOpts,
|
|
45
|
+
);
|
|
46
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
3
|
+
import { createContactPropertyCommand } from './create';
|
|
4
|
+
import { deleteContactPropertyCommand } from './delete';
|
|
5
|
+
import { getContactPropertyCommand } from './get';
|
|
6
|
+
import { listContactPropertiesCommand } from './list';
|
|
7
|
+
import { updateContactPropertyCommand } from './update';
|
|
8
|
+
|
|
9
|
+
export const contactPropertiesCommand = new Command('contact-properties')
|
|
10
|
+
.description(
|
|
11
|
+
'Manage contact property definitions — schema for custom data on contacts',
|
|
12
|
+
)
|
|
13
|
+
.addHelpText(
|
|
14
|
+
'after',
|
|
15
|
+
buildHelpText({
|
|
16
|
+
context: `Contact properties define the schema for custom data stored on contacts.
|
|
17
|
+
Think of them as column definitions — you create a property definition (e.g. company_name)
|
|
18
|
+
and then set values for that property on individual contacts via "resend contacts update --properties".
|
|
19
|
+
|
|
20
|
+
Property values are interpolated into broadcast HTML using triple-brace syntax:
|
|
21
|
+
{{{PROPERTY_NAME|fallback}}} — inline fallback if property value is absent
|
|
22
|
+
{{{company_name|Unknown Company}}} — example: renders the company or "Unknown Company"
|
|
23
|
+
|
|
24
|
+
Reserved property keys (built-in, cannot be created): FIRST_NAME, LAST_NAME, EMAIL, UNSUBSCRIBE_URL
|
|
25
|
+
|
|
26
|
+
Supported types:
|
|
27
|
+
string — text values (default for most properties)
|
|
28
|
+
number — numeric values (useful for counts, scores, thresholds)
|
|
29
|
+
|
|
30
|
+
Note: property keys and types are immutable after creation. Only the fallback value can
|
|
31
|
+
be updated. Deleting a property removes it from all contacts.`,
|
|
32
|
+
examples: [
|
|
33
|
+
'resend contact-properties list',
|
|
34
|
+
'resend contact-properties create --key company_name --type string',
|
|
35
|
+
'resend contact-properties create --key plan --type string --fallback-value "free"',
|
|
36
|
+
'resend contact-properties create --key score --type number --fallback-value 0',
|
|
37
|
+
'resend contact-properties get b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d',
|
|
38
|
+
'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value "Unknown"',
|
|
39
|
+
'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --clear-fallback-value',
|
|
40
|
+
'resend contact-properties delete b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --yes',
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
.addCommand(createContactPropertyCommand)
|
|
45
|
+
.addCommand(getContactPropertyCommand)
|
|
46
|
+
.addCommand(listContactPropertiesCommand, { isDefault: true })
|
|
47
|
+
.addCommand(updateContactPropertyCommand)
|
|
48
|
+
.addCommand(deleteContactPropertyCommand);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runList } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
import {
|
|
6
|
+
buildPaginationOpts,
|
|
7
|
+
parseLimitOpt,
|
|
8
|
+
printPaginationHint,
|
|
9
|
+
} from '../../lib/pagination';
|
|
10
|
+
import { renderContactPropertiesTable } from './utils';
|
|
11
|
+
|
|
12
|
+
export const listContactPropertiesCommand = new Command('list')
|
|
13
|
+
.alias('ls')
|
|
14
|
+
.description('List all contact property definitions')
|
|
15
|
+
.option(
|
|
16
|
+
'--limit <n>',
|
|
17
|
+
'Maximum number of contact properties to return (1-100)',
|
|
18
|
+
'10',
|
|
19
|
+
)
|
|
20
|
+
.option(
|
|
21
|
+
'--after <cursor>',
|
|
22
|
+
'Return contact properties after this cursor (next page)',
|
|
23
|
+
)
|
|
24
|
+
.option(
|
|
25
|
+
'--before <cursor>',
|
|
26
|
+
'Return contact properties before this cursor (previous page)',
|
|
27
|
+
)
|
|
28
|
+
.addHelpText(
|
|
29
|
+
'after',
|
|
30
|
+
buildHelpText({
|
|
31
|
+
context: `Pagination: use --after or --before with a contact property ID as the cursor.
|
|
32
|
+
Only one of --after or --before may be used at a time.
|
|
33
|
+
The response includes has_more: true when additional pages exist.`,
|
|
34
|
+
output: ` {
|
|
35
|
+
"object": "list",
|
|
36
|
+
"has_more": false,
|
|
37
|
+
"data": [
|
|
38
|
+
{ "id": "<uuid>", "key": "company_name", "type": "string", "fallbackValue": null, "createdAt": "..." }
|
|
39
|
+
]
|
|
40
|
+
}`,
|
|
41
|
+
errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
|
|
42
|
+
examples: [
|
|
43
|
+
'resend contact-properties list',
|
|
44
|
+
'resend contact-properties list --limit 25 --json',
|
|
45
|
+
'resend contact-properties list --after b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --json',
|
|
46
|
+
],
|
|
47
|
+
}),
|
|
48
|
+
)
|
|
49
|
+
.action(async (opts, cmd) => {
|
|
50
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
51
|
+
const limit = parseLimitOpt(opts.limit, globalOpts);
|
|
52
|
+
const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
|
|
53
|
+
await runList(
|
|
54
|
+
{
|
|
55
|
+
spinner: {
|
|
56
|
+
loading: 'Fetching contact properties...',
|
|
57
|
+
success: 'Contact properties fetched',
|
|
58
|
+
fail: 'Failed to list contact properties',
|
|
59
|
+
},
|
|
60
|
+
sdkCall: (resend) => resend.contactProperties.list(paginationOpts),
|
|
61
|
+
onInteractive: (list) => {
|
|
62
|
+
console.log(renderContactPropertiesTable(list.data));
|
|
63
|
+
printPaginationHint(list);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
globalOpts,
|
|
67
|
+
);
|
|
68
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runWrite } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
import { outputError } from '../../lib/output';
|
|
6
|
+
|
|
7
|
+
export const updateContactPropertyCommand = new Command('update')
|
|
8
|
+
.description('Update a contact property definition')
|
|
9
|
+
.argument('<id>', 'Contact property UUID')
|
|
10
|
+
.option(
|
|
11
|
+
'--fallback-value <value>',
|
|
12
|
+
'New fallback value used in broadcast templates when a contact has no value set for this property',
|
|
13
|
+
)
|
|
14
|
+
.option(
|
|
15
|
+
'--clear-fallback-value',
|
|
16
|
+
'Remove the fallback value (sets it to null)',
|
|
17
|
+
)
|
|
18
|
+
.addHelpText(
|
|
19
|
+
'after',
|
|
20
|
+
buildHelpText({
|
|
21
|
+
context: `Note: the property key and type cannot be changed after creation. Only the fallback value
|
|
22
|
+
is updatable. Renaming a property would break existing broadcasts that reference the old key.
|
|
23
|
+
|
|
24
|
+
--fallback-value and --clear-fallback-value are mutually exclusive.
|
|
25
|
+
|
|
26
|
+
The fallback value is used in broadcast template interpolation when a contact has no value:
|
|
27
|
+
{{{company_name|Unknown}}} — inline fallback (takes precedence over the property's fallback)
|
|
28
|
+
{{{company_name}}} — uses the property's stored fallback value if set`,
|
|
29
|
+
output: ` {"object":"contact_property","id":"<id>"}`,
|
|
30
|
+
errorCodes: [
|
|
31
|
+
'auth_error',
|
|
32
|
+
'no_changes',
|
|
33
|
+
'conflicting_flags',
|
|
34
|
+
'update_error',
|
|
35
|
+
],
|
|
36
|
+
examples: [
|
|
37
|
+
'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value "Acme Corp"',
|
|
38
|
+
'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value 42',
|
|
39
|
+
'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --clear-fallback-value',
|
|
40
|
+
'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value "Unknown" --json',
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
.action(async (id, opts, cmd) => {
|
|
45
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
46
|
+
|
|
47
|
+
if (opts.fallbackValue === undefined && !opts.clearFallbackValue) {
|
|
48
|
+
outputError(
|
|
49
|
+
{
|
|
50
|
+
message:
|
|
51
|
+
'Provide at least one option to update: --fallback-value or --clear-fallback-value.',
|
|
52
|
+
code: 'no_changes',
|
|
53
|
+
},
|
|
54
|
+
{ json: globalOpts.json },
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (opts.fallbackValue !== undefined && opts.clearFallbackValue) {
|
|
59
|
+
outputError(
|
|
60
|
+
{
|
|
61
|
+
message:
|
|
62
|
+
'--fallback-value and --clear-fallback-value are mutually exclusive.',
|
|
63
|
+
code: 'conflicting_flags',
|
|
64
|
+
},
|
|
65
|
+
{ json: globalOpts.json },
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const fallbackValue = opts.clearFallbackValue ? null : opts.fallbackValue;
|
|
70
|
+
|
|
71
|
+
await runWrite(
|
|
72
|
+
{
|
|
73
|
+
spinner: {
|
|
74
|
+
loading: 'Updating contact property...',
|
|
75
|
+
success: 'Contact property updated',
|
|
76
|
+
fail: 'Failed to update contact property',
|
|
77
|
+
},
|
|
78
|
+
sdkCall: (resend) =>
|
|
79
|
+
resend.contactProperties.update({
|
|
80
|
+
id,
|
|
81
|
+
...(fallbackValue !== undefined && { fallbackValue }),
|
|
82
|
+
}),
|
|
83
|
+
errorCode: 'update_error',
|
|
84
|
+
successMsg: `Contact property updated: ${id}`,
|
|
85
|
+
},
|
|
86
|
+
globalOpts,
|
|
87
|
+
);
|
|
88
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ContactProperty } from 'resend';
|
|
2
|
+
import { renderTable } from '../../lib/table';
|
|
3
|
+
|
|
4
|
+
export function renderContactPropertiesTable(props: ContactProperty[]): string {
|
|
5
|
+
const rows = props.map((prop) => [
|
|
6
|
+
prop.key,
|
|
7
|
+
prop.type,
|
|
8
|
+
prop.fallbackValue != null ? String(prop.fallbackValue) : '',
|
|
9
|
+
prop.id,
|
|
10
|
+
prop.createdAt,
|
|
11
|
+
]);
|
|
12
|
+
return renderTable(
|
|
13
|
+
['Key', 'Type', 'Fallback Value', 'ID', 'Created'],
|
|
14
|
+
rows,
|
|
15
|
+
'(no contact properties)',
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as p from '@clack/prompts';
|
|
2
|
+
import { Command } from '@commander-js/extra-typings';
|
|
3
|
+
import type { AddContactSegmentOptions } from 'resend';
|
|
4
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
5
|
+
import { requireClient } from '../../lib/client';
|
|
6
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
7
|
+
import { outputError, outputResult } from '../../lib/output';
|
|
8
|
+
import { cancelAndExit } from '../../lib/prompts';
|
|
9
|
+
import { withSpinner } from '../../lib/spinner';
|
|
10
|
+
import { isInteractive } from '../../lib/tty';
|
|
11
|
+
import { segmentContactIdentifier } from './utils';
|
|
12
|
+
|
|
13
|
+
export const addContactSegmentCommand = new Command('add-segment')
|
|
14
|
+
.description('Add a contact to a segment')
|
|
15
|
+
.argument('<contactId>', 'Contact UUID or email address')
|
|
16
|
+
.option('--segment-id <id>', 'Segment ID to add the contact to (required)')
|
|
17
|
+
.addHelpText(
|
|
18
|
+
'after',
|
|
19
|
+
buildHelpText({
|
|
20
|
+
context: `The <contactId> argument accepts either a UUID or an email address.
|
|
21
|
+
|
|
22
|
+
Non-interactive: --segment-id is required.`,
|
|
23
|
+
output: ` {"id":"<segment-membership-id>"}`,
|
|
24
|
+
errorCodes: ['auth_error', 'missing_segment_id', 'add_segment_error'],
|
|
25
|
+
examples: [
|
|
26
|
+
'resend contacts add-segment 479e3145-dd38-4932-8c0c-e58b548c9e76 --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
|
|
27
|
+
'resend contacts add-segment user@example.com --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --json',
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
31
|
+
.action(async (contactId, opts, cmd) => {
|
|
32
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
33
|
+
const resend = requireClient(globalOpts);
|
|
34
|
+
|
|
35
|
+
let segmentId = opts.segmentId;
|
|
36
|
+
|
|
37
|
+
if (!segmentId) {
|
|
38
|
+
if (!isInteractive()) {
|
|
39
|
+
outputError(
|
|
40
|
+
{ message: 'Missing --segment-id flag.', code: 'missing_segment_id' },
|
|
41
|
+
{ json: globalOpts.json },
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const result = await p.text({
|
|
45
|
+
message: 'Segment ID',
|
|
46
|
+
placeholder: '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
|
|
47
|
+
validate: (v) => (!v ? 'Required' : undefined),
|
|
48
|
+
});
|
|
49
|
+
if (p.isCancel(result)) {
|
|
50
|
+
cancelAndExit('Cancelled.');
|
|
51
|
+
}
|
|
52
|
+
segmentId = result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// segmentContactIdentifier resolves UUID vs email for the ContactSegmentsBaseOptions
|
|
56
|
+
// discriminated union. The spread of that union requires an explicit cast.
|
|
57
|
+
const payload = {
|
|
58
|
+
...segmentContactIdentifier(contactId),
|
|
59
|
+
segmentId,
|
|
60
|
+
} as AddContactSegmentOptions;
|
|
61
|
+
|
|
62
|
+
const data = await withSpinner(
|
|
63
|
+
{
|
|
64
|
+
loading: 'Adding contact to segment...',
|
|
65
|
+
success: 'Contact added to segment',
|
|
66
|
+
fail: 'Failed to add contact to segment',
|
|
67
|
+
},
|
|
68
|
+
() => resend.contacts.segments.add(payload),
|
|
69
|
+
'add_segment_error',
|
|
70
|
+
globalOpts,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (!globalOpts.json && isInteractive()) {
|
|
74
|
+
console.log(`Contact added to segment: ${segmentId}`);
|
|
75
|
+
} else {
|
|
76
|
+
outputResult(data, { json: globalOpts.json });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as p from '@clack/prompts';
|
|
2
|
+
import { Command } from '@commander-js/extra-typings';
|
|
3
|
+
import { runCreate } from '../../lib/actions';
|
|
4
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
5
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
6
|
+
import { cancelAndExit, requireText } from '../../lib/prompts';
|
|
7
|
+
import { isInteractive } from '../../lib/tty';
|
|
8
|
+
import { parsePropertiesJson } from './utils';
|
|
9
|
+
|
|
10
|
+
export const createContactCommand = new Command('create')
|
|
11
|
+
.description('Create a new contact')
|
|
12
|
+
.option('--email <email>', 'Contact email address (required)')
|
|
13
|
+
.option('--first-name <name>', 'First name')
|
|
14
|
+
.option('--last-name <name>', 'Last name')
|
|
15
|
+
.option(
|
|
16
|
+
'--unsubscribed',
|
|
17
|
+
'Globally unsubscribe the contact from all broadcasts',
|
|
18
|
+
)
|
|
19
|
+
.option(
|
|
20
|
+
'--properties <json>',
|
|
21
|
+
'Custom properties as a JSON string (e.g. \'{"company":"Acme"}\')',
|
|
22
|
+
)
|
|
23
|
+
.option(
|
|
24
|
+
'--segment-id <id...>',
|
|
25
|
+
'Segment ID to add the contact to on creation (repeatable: --segment-id abc --segment-id def)',
|
|
26
|
+
)
|
|
27
|
+
.addHelpText(
|
|
28
|
+
'after',
|
|
29
|
+
buildHelpText({
|
|
30
|
+
context: `Non-interactive: --email is required. All other flags are optional.
|
|
31
|
+
|
|
32
|
+
Properties: pass a JSON object string to --properties (e.g. '{"plan":"pro","company":"Acme"}').
|
|
33
|
+
Properties are stored as custom contact attributes. To clear a property, set it to null.
|
|
34
|
+
firstName and lastName are convenience aliases — they map to FIRST_NAME/LAST_NAME properties internally.
|
|
35
|
+
|
|
36
|
+
Segments: use --segment-id once per segment to add the contact to one or more segments on creation.
|
|
37
|
+
|
|
38
|
+
Unsubscribed: setting --unsubscribed is a team-wide opt-out from all broadcasts, regardless of segments/topics.`,
|
|
39
|
+
output: ` {"object":"contact","id":"<id>"}`,
|
|
40
|
+
errorCodes: [
|
|
41
|
+
'auth_error',
|
|
42
|
+
'missing_email',
|
|
43
|
+
'invalid_properties',
|
|
44
|
+
'create_error',
|
|
45
|
+
],
|
|
46
|
+
examples: [
|
|
47
|
+
'resend contacts create --email jane@example.com',
|
|
48
|
+
'resend contacts create --email jane@example.com --first-name Jane --last-name Smith',
|
|
49
|
+
'resend contacts create --email jane@example.com --unsubscribed',
|
|
50
|
+
`resend contacts create --email jane@example.com --properties '{"company":"Acme","plan":"pro"}'`,
|
|
51
|
+
'resend contacts create --email jane@example.com --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --segment-id a2f4c6e8-1b3d-5f7a-9c2e-4d6f8a1b3c5e',
|
|
52
|
+
'resend contacts create --email jane@example.com --first-name Jane --json',
|
|
53
|
+
],
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
56
|
+
.action(async (opts, cmd) => {
|
|
57
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
58
|
+
|
|
59
|
+
const email = await requireText(
|
|
60
|
+
opts.email,
|
|
61
|
+
{ message: 'Email address', placeholder: 'user@example.com' },
|
|
62
|
+
{ message: 'Missing --email flag.', code: 'missing_email' },
|
|
63
|
+
globalOpts,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
let firstName = opts.firstName;
|
|
67
|
+
let lastName = opts.lastName;
|
|
68
|
+
|
|
69
|
+
if (isInteractive() && !opts.firstName) {
|
|
70
|
+
const result = await p.text({
|
|
71
|
+
message: 'First name (optional)',
|
|
72
|
+
placeholder: 'Jane',
|
|
73
|
+
});
|
|
74
|
+
if (p.isCancel(result)) {
|
|
75
|
+
cancelAndExit('Cancelled.');
|
|
76
|
+
}
|
|
77
|
+
if (result) {
|
|
78
|
+
firstName = result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (isInteractive() && !opts.lastName) {
|
|
83
|
+
const result = await p.text({
|
|
84
|
+
message: 'Last name (optional)',
|
|
85
|
+
placeholder: 'Smith',
|
|
86
|
+
});
|
|
87
|
+
if (p.isCancel(result)) {
|
|
88
|
+
cancelAndExit('Cancelled.');
|
|
89
|
+
}
|
|
90
|
+
if (result) {
|
|
91
|
+
lastName = result;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const properties = parsePropertiesJson(opts.properties, globalOpts);
|
|
96
|
+
const segments = opts.segmentId ?? [];
|
|
97
|
+
|
|
98
|
+
await runCreate(
|
|
99
|
+
{
|
|
100
|
+
spinner: {
|
|
101
|
+
loading: 'Creating contact...',
|
|
102
|
+
success: 'Contact created',
|
|
103
|
+
fail: 'Failed to create contact',
|
|
104
|
+
},
|
|
105
|
+
sdkCall: (resend) =>
|
|
106
|
+
resend.contacts.create({
|
|
107
|
+
email,
|
|
108
|
+
...(firstName && { firstName }),
|
|
109
|
+
...(lastName && { lastName }),
|
|
110
|
+
...(opts.unsubscribed && { unsubscribed: true }),
|
|
111
|
+
...(properties && { properties }),
|
|
112
|
+
...(segments.length > 0 && {
|
|
113
|
+
segments: segments.map((id) => ({ id })),
|
|
114
|
+
}),
|
|
115
|
+
}),
|
|
116
|
+
onInteractive: (data) => {
|
|
117
|
+
console.log(`\nContact created: ${data.id}`);
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
globalOpts,
|
|
121
|
+
);
|
|
122
|
+
});
|