@mailmodo/cli 0.0.30-beta.pr32.53 → 0.0.31-beta.pr33.54

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.
@@ -3,6 +3,7 @@ import chalk from 'chalk';
3
3
  import open from 'open';
4
4
  import { BaseCommand } from '../../lib/base-command.js';
5
5
  import { API_ENDPOINTS } from '../../lib/constants.js';
6
+ import { INFO } from '../../lib/messages.js';
6
7
  export default class Billing extends BaseCommand {
7
8
  static description = 'View billing status, purchase blocks, set cap, or add a payment method';
8
9
  static examples = [
@@ -68,10 +69,10 @@ export default class Billing extends BaseCommand {
68
69
  this.log(` ${chalk.dim(checkoutUrl)}\n`);
69
70
  try {
70
71
  await open(checkoutUrl);
71
- this.log(` Opening in browser...\n`);
72
+ this.log(` ${INFO.BROWSER_OPENING}\n`);
72
73
  }
73
74
  catch {
74
- this.log(` ${chalk.dim('Could not open browser. Visit the URL above manually.')}\n`);
75
+ this.log(` ${INFO.BROWSER_OPEN_FAILED}\n`);
75
76
  }
76
77
  }
77
78
  async showStatus(jsonOutput) {
@@ -2,6 +2,7 @@ import { confirm, input } from '@inquirer/prompts';
2
2
  import chalk from 'chalk';
3
3
  import { BaseCommand } from '../../lib/base-command.js';
4
4
  import { API_ENDPOINTS, DEFAULT_BRAND_COLOR, DEFAULT_MONTHLY_CAP, } from '../../lib/constants.js';
5
+ import { ERRORS, INFO, PROMPTS, SEPARATOR, VALIDATION, } from '../../lib/messages.js';
5
6
  import { loadTemplate, saveYaml, } from '../../lib/yaml-config.js';
6
7
  export default class Deploy extends BaseCommand {
7
8
  static description = 'Deploy email sequences and verify sending domain';
@@ -50,10 +51,10 @@ export default class Deploy extends BaseCommand {
50
51
  const response = await this.withApiSpinner({ json: flags.json, text: ' Validating sequence...' }, () => this.apiClient.post(API_ENDPOINTS.SEQUENCES_VALIDATE, payload));
51
52
  if (!response.ok) {
52
53
  if (response.data.error === 'senderDomainNotFound') {
53
- this.error(`Sending domain not registered. Run: ${chalk.cyan('mailmodo domain')}`);
54
+ this.error(ERRORS.DOMAIN_NOT_REGISTERED);
54
55
  }
55
56
  if (response.data.error === 'senderDomainNotVerified') {
56
- this.error(`Sending domain not verified. Run: ${chalk.cyan('mailmodo domain --verify')}`);
57
+ this.error(ERRORS.DOMAIN_NOT_VERIFIED);
57
58
  }
58
59
  this.handleApiError(response);
59
60
  }
@@ -148,10 +149,9 @@ export default class Deploy extends BaseCommand {
148
149
  message: 'Set up your sending domain now?',
149
150
  });
150
151
  if (!setupNow) {
151
- this.log(`\n Sequences saved but ${chalk.yellow('NOT deployed')}.`);
152
+ this.log(`\n ${INFO.SEQUENCES_NOT_DEPLOYED}`);
152
153
  this.log(` Emails will not send until your domain is verified.`);
153
- this.log(` When ready, run: ${chalk.cyan('mailmodo domain')}`);
154
- this.log(` Then: ${chalk.cyan('mailmodo deploy')}\n`);
154
+ this.log(` ${INFO.DOMAIN_NOT_DEPLOYED_HINT}\n`);
155
155
  return false;
156
156
  }
157
157
  }
@@ -194,9 +194,9 @@ export default class Deploy extends BaseCommand {
194
194
  }
195
195
  logDeploySuccessInstructions(sdkSnippet) {
196
196
  this.log(` ${chalk.green('Deployed.')} Emails are live.\n`);
197
- this.log(` ${'─'.repeat(53)}`);
197
+ this.log(` ${SEPARATOR}`);
198
198
  this.log(` ${chalk.bold('ADD THIS TO YOUR APP (one-time only):')}`);
199
- this.log(` ${'─'.repeat(53)}\n`);
199
+ this.log(` ${SEPARATOR}\n`);
200
200
  this.log(` ${chalk.cyan(sdkSnippet.install ?? 'npm install @mailmodo/sdk')}\n`);
201
201
  this.log(` ${chalk.dim("import { track, identify } from '@mailmodo/sdk'")}\n`);
202
202
  if (sdkSnippet.examples) {
@@ -217,7 +217,7 @@ export default class Deploy extends BaseCommand {
217
217
  if (identifyCalls.length > 0)
218
218
  this.log('');
219
219
  this.log(` Full SDK docs: ${chalk.cyan('mailmodo.com/docs/sdk')}\n`);
220
- this.log(` ${'─'.repeat(53)}\n`);
220
+ this.log(` ${SEPARATOR}\n`);
221
221
  }
222
222
  async runDomainSetup(yamlConfig, flags) {
223
223
  const { address, domain, senderEmail } = await this.collectDomainInputs(yamlConfig, flags);
@@ -242,9 +242,8 @@ export default class Deploy extends BaseCommand {
242
242
  message: "Press Enter once you've added the records, or 'skip' to do this later.",
243
243
  });
244
244
  if (action.toLowerCase() === 'skip') {
245
- this.log(`\n Sequences saved but ${chalk.yellow('NOT deployed')}.`);
246
- this.log(` When ready, run: ${chalk.cyan('mailmodo domain')}`);
247
- this.log(` Then: ${chalk.cyan('mailmodo deploy')}\n`);
245
+ this.log(`\n ${INFO.SEQUENCES_NOT_DEPLOYED}`);
246
+ this.log(` ${INFO.DOMAIN_NOT_DEPLOYED_HINT}\n`);
248
247
  return false;
249
248
  }
250
249
  return this.verifyDomain(flags.json, domain);
@@ -257,20 +256,20 @@ export default class Deploy extends BaseCommand {
257
256
  senderEmail: yamlConfig.project?.fromEmail || '',
258
257
  };
259
258
  }
260
- this.log(`\n ${'─'.repeat(53)}`);
259
+ this.log(`\n ${SEPARATOR}`);
261
260
  this.log(` ${chalk.bold('DOMAIN SETUP')}`);
262
- this.log(` ${'─'.repeat(53)}\n`);
261
+ this.log(` ${SEPARATOR}\n`);
263
262
  const domain = await input({
264
- message: 'What domain will you send from?',
265
- validate: (v) => (v?.trim() ? true : 'Domain is required'),
263
+ message: PROMPTS.DOMAIN,
264
+ validate: (v) => (v?.trim() ? true : VALIDATION.DOMAIN_REQUIRED),
266
265
  });
267
266
  const senderEmail = await input({
268
- message: 'Sender email address:',
269
- validate: (v) => (v?.includes('@') ? true : 'Please enter a valid email'),
267
+ message: PROMPTS.SENDER_EMAIL,
268
+ validate: (v) => (v?.includes('@') ? true : VALIDATION.EMAIL_INVALID),
270
269
  });
271
270
  const address = await input({
272
- message: 'Business address (required by law for email footers):',
273
- validate: (v) => (v?.trim() ? true : 'Address is required'),
271
+ message: PROMPTS.BUSINESS_ADDRESS,
272
+ validate: (v) => (v?.trim() ? true : VALIDATION.ADDRESS_REQUIRED),
274
273
  });
275
274
  return { address, domain, senderEmail };
276
275
  }
@@ -284,7 +283,7 @@ export default class Deploy extends BaseCommand {
284
283
  this.log(` Host: ${record.host}`);
285
284
  this.log(` Value: ${record.value}\n`);
286
285
  }
287
- this.log(` DNS changes take 5–30 minutes to propagate.`);
286
+ this.log(` ${INFO.DNS_PROPAGATION}`);
288
287
  if (dnsGuideUrl)
289
288
  this.log(` Full guide: ${chalk.cyan(dnsGuideUrl)}\n`);
290
289
  }
@@ -305,7 +304,8 @@ export default class Deploy extends BaseCommand {
305
304
  this.log(`\n ${chalk.green('Domain verified.')} Continuing deploy...\n`);
306
305
  }
307
306
  else {
308
- this.log(`\n ${chalk.yellow('Some records failed.')} Fix them and run ${chalk.cyan('mailmodo domain --verify')}.`);
307
+ this.log(`\n ${INFO.DNS_RECORDS_FAILED}`);
308
+ this.log(`\n ${INFO.DNS_FIX_AND_VERIFY}`);
309
309
  if (dnsGuideUrl)
310
310
  this.log(` Help: ${chalk.cyan(dnsGuideUrl)}\n`);
311
311
  }
@@ -23,6 +23,4 @@ export default class Domain extends BaseCommand {
23
23
  * bounce rate, and spam complaint rate.
24
24
  */
25
25
  private showDomainStatus;
26
- private collectDomainInputs;
27
- private recordLabel;
28
26
  }
@@ -3,8 +3,7 @@ import { input } from '@inquirer/prompts';
3
3
  import chalk from 'chalk';
4
4
  import { BaseCommand } from '../../lib/base-command.js';
5
5
  import { API_ENDPOINTS } from '../../lib/constants.js';
6
- import { saveConfig } from '../../lib/config.js';
7
- import { saveYaml } from '../../lib/yaml-config.js';
6
+ import { ERRORS, INFO, PROMPTS, SEPARATOR } from '../../lib/messages.js';
8
7
  export default class Domain extends BaseCommand {
9
8
  static description = 'Set up and verify your sending domain';
10
9
  static examples = [
@@ -25,83 +24,57 @@ export default class Domain extends BaseCommand {
25
24
  };
26
25
  async run() {
27
26
  const { flags } = await this.parse(Domain);
28
- const config = await this.ensureAuth();
27
+ await this.ensureAuth();
29
28
  if (flags.verify) {
30
- await this.verifyDomain(flags.json, config);
29
+ const yamlConfig = await this.ensureYaml();
30
+ const domain = yamlConfig.project?.domain;
31
+ if (!domain) {
32
+ this.error(ERRORS.DOMAIN_NOT_CONFIGURED);
33
+ }
34
+ await this.verifyDomain(flags.json, domain);
31
35
  return;
32
36
  }
33
37
  if (flags.status) {
34
- await this.showDomainStatus(flags.json, config);
38
+ const yamlConfig = await this.ensureYaml();
39
+ const domain = yamlConfig.project?.domain;
40
+ if (!domain) {
41
+ this.error(ERRORS.DOMAIN_NOT_CONFIGURED);
42
+ }
43
+ await this.showDomainStatus(flags.json, domain);
35
44
  return;
36
45
  }
37
- await this.setupDomain(flags, config);
46
+ await this.setupDomain(flags);
38
47
  }
39
48
  /**
40
49
  * Interactive domain setup: collects domain, sender email, and business address,
41
50
  * then calls the API to retrieve the required DNS records.
42
51
  */
43
- async setupDomain(flags, config) {
52
+ async setupDomain(flags) {
44
53
  const yamlConfig = await this.ensureYaml();
45
- this.log(`\n ${'─'.repeat(53)}`);
54
+ this.log(`\n ${SEPARATOR}`);
46
55
  this.log(` ${chalk.bold('DOMAIN SETUP')}`);
47
- this.log(` ${'─'.repeat(53)}\n`);
48
- const { domain, senderEmail, fromName, replyTo, address } = await this.collectDomainInputs(flags.yes, yamlConfig);
49
- const apiPayload = {
50
- address,
51
- domain,
52
- fromEmail: senderEmail,
53
- };
54
- if (fromName)
55
- apiPayload.fromName = fromName;
56
- if (replyTo)
57
- apiPayload.replyTo = replyTo;
58
- const response = await this.withApiSpinner({ json: flags.json, text: ' Configuring domain...' }, () => this.apiClient.post(API_ENDPOINTS.DOMAIN, apiPayload));
59
- if (!response.ok) {
60
- this.handleApiError(response);
61
- }
62
- yamlConfig.project.domain = domain;
63
- yamlConfig.project.fromEmail = senderEmail;
64
- yamlConfig.project.address = address;
65
- if (fromName)
66
- yamlConfig.project.fromName = fromName;
67
- if (replyTo)
68
- yamlConfig.project.replyTo = replyTo;
69
- await saveYaml(yamlConfig);
70
- await saveConfig({ ...config, domain });
71
- const records = response.data?.dnsRecords || [];
72
- const guideUrl = response.data?.dnsGuideUrl;
56
+ this.log(` ${SEPARATOR}\n`);
57
+ const inputs = await this.collectDomainSetupInputs(yamlConfig, flags.yes);
58
+ const { dnsRecords, dnsGuideUrl } = await this.registerDomain(yamlConfig, inputs, flags.json);
73
59
  if (flags.json) {
74
- this.log(JSON.stringify({ dnsRecords: records, domain }, null, 2));
60
+ this.log(JSON.stringify({ dnsRecords, domain: inputs.domain }, null, 2));
75
61
  return;
76
62
  }
77
- this.log(`\n Add these ${records.length} DNS records to your domain provider:\n`);
78
- for (const [i, record] of records.entries()) {
79
- this.log(` ${chalk.bold(`RECORD ${i + 1} — ${this.recordLabel(i)}`)}`);
80
- this.log(` Type: ${record.type}`);
81
- this.log(` Host: ${record.host}`);
82
- this.log(` Value: ${record.value}\n`);
83
- }
84
- this.log(` DNS changes take 5–30 minutes to propagate.`);
85
- if (guideUrl)
86
- this.log(` Full guide: ${chalk.cyan(guideUrl)}\n`);
63
+ this.logDnsRecords(dnsRecords, dnsGuideUrl, flags.json);
87
64
  if (!flags.yes) {
88
65
  const action = await input({
89
66
  default: '',
90
- message: "Press Enter once you've added the records, or 'skip'.",
67
+ message: PROMPTS.ENTER_AFTER_RECORDS,
91
68
  });
92
69
  if (action.toLowerCase() !== 'skip') {
93
- await this.verifyDomain(false, { ...config, domain });
70
+ await this.verifyDomain(false, inputs.domain);
94
71
  }
95
72
  }
96
73
  }
97
74
  /**
98
75
  * Calls the domain verification API and displays pass/fail for each DNS record.
99
76
  */
100
- async verifyDomain(jsonOutput, config) {
101
- if (!config.domain) {
102
- this.error(`No domain configured. Run ${chalk.cyan('mailmodo domain')} to set up your sending domain.`);
103
- }
104
- const domain = config.domain;
77
+ async verifyDomain(jsonOutput, domain) {
105
78
  const response = await this.withApiSpinner({ json: jsonOutput, text: ' Checking DNS...' }, () => this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY, {
106
79
  domain,
107
80
  }));
@@ -121,7 +94,7 @@ export default class Domain extends BaseCommand {
121
94
  this.log(`\n ${chalk.green('✓')} Domain verified.\n`);
122
95
  }
123
96
  else {
124
- this.log(`\n ${chalk.yellow('Some records failed.')}`);
97
+ this.log(`\n ${INFO.DNS_RECORDS_FAILED}`);
125
98
  if (!dkim) {
126
99
  this.log(`\n DKIM common mistakes:`);
127
100
  this.log(` - Using TXT instead of CNAME record type`);
@@ -133,7 +106,7 @@ export default class Domain extends BaseCommand {
133
106
  this.log(` - Missing or incorrect CNAME for mm-bounce subdomain`);
134
107
  this.log(` - Cloudflare: proxy must be OFF (grey cloud, not orange)`);
135
108
  }
136
- this.log(`\n Fix the records and run ${chalk.cyan('mailmodo domain --verify')} again.`);
109
+ this.log(`\n ${INFO.DNS_FIX_AND_VERIFY}`);
137
110
  if (dnsGuideUrl)
138
111
  this.log(` Help: ${chalk.cyan(dnsGuideUrl)}\n`);
139
112
  }
@@ -142,11 +115,7 @@ export default class Domain extends BaseCommand {
142
115
  * Displays domain health metrics including verification status,
143
116
  * bounce rate, and spam complaint rate.
144
117
  */
145
- async showDomainStatus(jsonOutput, config) {
146
- if (!config.domain) {
147
- this.error(`No domain configured. Run ${chalk.cyan('mailmodo domain')} to set up your sending domain.`);
148
- }
149
- const domain = config.domain;
118
+ async showDomainStatus(jsonOutput, domain) {
150
119
  const response = await this.withApiSpinner({ json: jsonOutput, text: ' Loading domain status...' }, () => this.apiClient.get(API_ENDPOINTS.DOMAIN_STATUS, {
151
120
  domain,
152
121
  }));
@@ -163,47 +132,4 @@ export default class Domain extends BaseCommand {
163
132
  this.log(` Bounce rate: ${data.bounceRate ?? 'N/A'}%`);
164
133
  this.log(` Spam rate: ${data.spamRate ?? 'N/A'}%\n`);
165
134
  }
166
- async collectDomainInputs(skipPrompts, yamlConfig) {
167
- if (skipPrompts) {
168
- const domain = yamlConfig.project?.domain || '';
169
- if (!domain) {
170
- this.error('Domain is required. Set it in mailmodo.yaml or use interactive mode.');
171
- }
172
- return {
173
- address: yamlConfig.project?.address || '',
174
- domain,
175
- fromName: yamlConfig.project?.fromName || '',
176
- replyTo: yamlConfig.project?.replyTo || '',
177
- senderEmail: yamlConfig.project?.fromEmail || '',
178
- };
179
- }
180
- const domain = await input({
181
- default: yamlConfig.project?.domain,
182
- message: 'What domain will you send from?',
183
- validate: (v) => (v?.trim() ? true : 'Domain is required'),
184
- });
185
- const senderEmail = await input({
186
- default: yamlConfig.project?.fromEmail,
187
- message: 'Sender email address:',
188
- validate: (v) => (v?.includes('@') ? true : 'Please enter a valid email'),
189
- });
190
- const fromName = await input({
191
- default: yamlConfig.project?.fromName || '',
192
- message: 'Display name (optional, shown as sender name):',
193
- });
194
- const replyTo = await input({
195
- default: yamlConfig.project?.replyTo || '',
196
- message: 'Reply-to address (optional, press Enter to use sender email):',
197
- });
198
- const address = await input({
199
- default: yamlConfig.project?.address,
200
- message: 'Business address (required by law):',
201
- validate: (v) => (v?.trim() ? true : 'Address is required'),
202
- });
203
- return { address, domain, fromName, replyTo, senderEmail };
204
- }
205
- recordLabel(index) {
206
- const labels = ['DKIM', 'DMARC', 'Return Path'];
207
- return labels[index] || `Record ${index + 1}`;
208
- }
209
135
  }
@@ -5,6 +5,7 @@ import { BaseCommand } from '../../lib/base-command.js';
5
5
  import { ApiClient } from '../../lib/api-client.js';
6
6
  import { loadConfig, saveConfig } from '../../lib/config.js';
7
7
  import { API_ENDPOINTS, LOGIN_URL } from '../../lib/constants.js';
8
+ import { INFO } from '../../lib/messages.js';
8
9
  export default class Login extends BaseCommand {
9
10
  static description = 'Authenticate with Mailmodo using your API key';
10
11
  static examples = [
@@ -47,10 +48,10 @@ export default class Login extends BaseCommand {
47
48
  this.log(`\n Get your free API key at: ${chalk.cyan(LOGIN_URL)}\n`);
48
49
  try {
49
50
  await open(LOGIN_URL);
50
- this.log(' Opening in browser...\n');
51
+ this.log(` ${INFO.BROWSER_OPENING}\n`);
51
52
  }
52
53
  catch {
53
- this.log(` ${chalk.dim('Could not open browser. Visit the URL above manually.')}\n`);
54
+ this.log(` ${INFO.BROWSER_OPEN_FAILED}\n`);
54
55
  }
55
56
  apiKey = await input({
56
57
  message: 'Paste your API key:',
@@ -4,6 +4,7 @@ import chalk from 'chalk';
4
4
  import open from 'open';
5
5
  import { BaseCommand } from '../../lib/base-command.js';
6
6
  import { API_ENDPOINTS, PREVIEW_PORT } from '../../lib/constants.js';
7
+ import { INFO } from '../../lib/messages.js';
7
8
  import { loadTemplate, getEmailStyle, getTemplateFilename, } from '../../lib/yaml-config.js';
8
9
  /* eslint-disable camelcase */
9
10
  const SAMPLE_DATA = Object.freeze({
@@ -238,7 +239,7 @@ export default class Preview extends BaseCommand {
238
239
  if (!jsonOutput) {
239
240
  this.log(`\n Style: ${chalk.cyan(effectiveStyle)}`);
240
241
  this.log(` Preview server at ${chalk.cyan(url)}`);
241
- this.log(` Opening in browser...\n`);
242
+ this.log(` ${INFO.BROWSER_OPENING}\n`);
242
243
  this.log(` ${chalk.dim('Press Ctrl+C to stop the preview server.')}\n`);
243
244
  }
244
245
  try {
@@ -246,7 +247,7 @@ export default class Preview extends BaseCommand {
246
247
  }
247
248
  catch {
248
249
  if (!jsonOutput) {
249
- this.log(` ${chalk.dim('Could not open browser. Visit the URL above manually.')}`);
250
+ this.log(` ${INFO.BROWSER_OPEN_FAILED}`);
250
251
  }
251
252
  }
252
253
  await new Promise((resolve) => {
@@ -20,14 +20,7 @@ export default class Settings extends BaseCommand {
20
20
  * Returns true/false for verified/unverified, or null if unavailable.
21
21
  */
22
22
  private fetchDomainVerified;
23
- /**
24
- * Handles domain change: collects the new domain, sender email, and
25
- * business address, calls the API to register them, displays the required
26
- * DNS records, and saves the updated config. Emails won't send until the
27
- * domain is re-verified.
28
- */
29
23
  private handleDomainChange;
30
- private recordLabel;
31
24
  /**
32
25
  * Handles the logo file upload flow: validates the local file exists,
33
26
  * reads it, uploads to Mailmodo CDN via API, and updates both logoFile
@@ -6,6 +6,7 @@ import { readFile } from 'node:fs/promises';
6
6
  import { resolve } from 'node:path';
7
7
  import { BaseCommand } from '../../lib/base-command.js';
8
8
  import { API_ENDPOINTS } from '../../lib/constants.js';
9
+ import { INFO } from '../../lib/messages.js';
9
10
  import { saveYaml } from '../../lib/yaml-config.js';
10
11
  const SETTINGS_GROUPS = Object.freeze({
11
12
  billing: ['monthly_cap'],
@@ -80,7 +81,7 @@ export default class Settings extends BaseCommand {
80
81
  return;
81
82
  }
82
83
  this.log(`\n ${chalk.green('✓')} ${key} updated to ${chalk.cyan(value)}`);
83
- this.log(` Run ${chalk.cyan("'mailmodo deploy'")} to apply.\n`);
84
+ this.log(` ${INFO.DEPLOY_TO_APPLY}\n`);
84
85
  }
85
86
  displaySettingsGroup(group, keys, project, domainVerified) {
86
87
  const availableKeys = keys.filter((key) => {
@@ -169,7 +170,7 @@ export default class Settings extends BaseCommand {
169
170
  project.emailStyle = style;
170
171
  await saveYaml(yamlConfig);
171
172
  this.log(`\n ${chalk.green('✓')} email_style updated to ${chalk.cyan(style)}`);
172
- this.log(` Run ${chalk.cyan("'mailmodo deploy'")} to apply.\n`);
173
+ this.log(` ${INFO.DEPLOY_TO_APPLY}\n`);
173
174
  return;
174
175
  }
175
176
  const newValue = await input({
@@ -178,7 +179,7 @@ export default class Settings extends BaseCommand {
178
179
  project[editPropKey] =
179
180
  editPropKey === 'monthlyCap' ? Number(newValue) : newValue;
180
181
  await saveYaml(yamlConfig);
181
- this.log(`\n ${chalk.green('✓')} Updated. Run ${chalk.cyan("'mailmodo deploy'")} to apply.\n`);
182
+ this.log(`\n ${chalk.green('✓')} Updated. ${INFO.DEPLOY_TO_APPLY}\n`);
182
183
  }
183
184
  /**
184
185
  * Fetches the domain verification status from the API.
@@ -201,58 +202,14 @@ export default class Settings extends BaseCommand {
201
202
  return null;
202
203
  }
203
204
  }
204
- /**
205
- * Handles domain change: collects the new domain, sender email, and
206
- * business address, calls the API to register them, displays the required
207
- * DNS records, and saves the updated config. Emails won't send until the
208
- * domain is re-verified.
209
- */
210
205
  async handleDomainChange(yamlConfig) {
211
- const newDomain = await input({
212
- message: 'New domain:',
213
- validate: (v) => (v?.trim() ? true : 'Domain is required'),
214
- });
215
- const newFromEmail = await input({
216
- default: yamlConfig.project.fromEmail || '',
217
- message: 'Sender email (from address):',
218
- validate: (v) => (v?.includes('@') ? true : 'Please enter a valid email'),
219
- });
220
- const newAddress = await input({
221
- default: yamlConfig.project.address || '',
222
- message: 'Business address (required by law):',
223
- validate: (v) => (v?.trim() ? true : 'Address is required'),
224
- });
225
206
  await this.ensureAuth();
226
- const response = await this.apiClient.post(API_ENDPOINTS.DOMAIN, {
227
- address: newAddress,
228
- domain: newDomain,
229
- fromEmail: newFromEmail,
230
- });
231
- if (!response.ok) {
232
- this.handleApiError(response);
233
- }
234
- const records = response.data?.dnsRecords || [];
235
- const dnsGuideUrl = response.data?.dnsGuideUrl;
236
- yamlConfig.project.domain = newDomain;
237
- yamlConfig.project.fromEmail = newFromEmail;
238
- yamlConfig.project.address = newAddress;
239
- await saveYaml(yamlConfig);
240
- this.log(`\n Domain, sender email, and business address updated. You will need to re-verify.`);
241
- this.log(` New DNS records:\n`);
242
- for (const [i, record] of records.entries()) {
243
- this.log(` ${chalk.bold(`RECORD ${i + 1} — ${this.recordLabel(i)}`)}`);
244
- this.log(` Type: ${record.type}`);
245
- this.log(` Host: ${record.host}`);
246
- this.log(` Value: ${record.value}\n`);
247
- }
207
+ const inputs = await this.collectDomainSetupInputs(yamlConfig, false);
208
+ const { dnsRecords, dnsGuideUrl } = await this.registerDomain(yamlConfig, inputs, false);
209
+ this.log(`\n Domain and sender details updated. You will need to re-verify.`);
210
+ this.logDnsRecords(dnsRecords, dnsGuideUrl, false);
248
211
  this.log(` Run ${chalk.cyan("'mailmodo domain --verify'")} once records are added.`);
249
212
  this.log(` Emails will not send until the new domain is verified.`);
250
- if (dnsGuideUrl)
251
- this.log(` Help: ${chalk.cyan(dnsGuideUrl)}\n`);
252
- }
253
- recordLabel(index) {
254
- const labels = ['DKIM', 'DMARC', 'Return Path'];
255
- return labels[index] || `Record ${index + 1}`;
256
213
  }
257
214
  /**
258
215
  * Handles the logo file upload flow: validates the local file exists,
@@ -69,5 +69,31 @@ export declare abstract class BaseCommand extends Command {
69
69
  * @param {{ status: number; debug?: ApiRequestDebugInfo }} response - Failed API response.
70
70
  * @returns {string} Message plus indented Request details for troubleshooting.
71
71
  */
72
+ protected collectDomainSetupInputs(yamlConfig: MailmodoYaml, skipPrompts: boolean): Promise<{
73
+ address: string;
74
+ domain: string;
75
+ fromEmail: string;
76
+ fromName: string;
77
+ replyTo: string;
78
+ }>;
79
+ protected registerDomain(yamlConfig: MailmodoYaml, inputs: {
80
+ address: string;
81
+ domain: string;
82
+ fromEmail: string;
83
+ fromName?: string;
84
+ replyTo?: string;
85
+ }, json: boolean): Promise<{
86
+ dnsGuideUrl?: string;
87
+ dnsRecords: Array<{
88
+ host: string;
89
+ type: string;
90
+ value: string;
91
+ }>;
92
+ }>;
93
+ protected logDnsRecords(records: Array<{
94
+ host: string;
95
+ type: string;
96
+ value: string;
97
+ }>, guideUrl: string | undefined, json: boolean): void;
72
98
  private formatApiFailure;
73
99
  }
@@ -1,9 +1,12 @@
1
+ import { input } from '@inquirer/prompts';
1
2
  import { Command, Flags } from '@oclif/core';
2
3
  import chalk from 'chalk';
3
4
  import ora from 'ora';
4
5
  import { ApiClient } from './api-client.js';
5
6
  import { loadConfig } from './config.js';
6
- import { loadYaml } from './yaml-config.js';
7
+ import { API_ENDPOINTS } from './constants.js';
8
+ import { ERRORS, INFO, PROMPTS, recordLabel, VALIDATION } from './messages.js';
9
+ import { loadYaml, saveYaml } from './yaml-config.js';
7
10
  /**
8
11
  * Abstract base command providing shared functionality for all Mailmodo CLI commands.
9
12
  * Subclasses inherit --json and --yes base flags, authentication enforcement,
@@ -35,7 +38,7 @@ export class BaseCommand extends Command {
35
38
  }
36
39
  const config = await loadConfig();
37
40
  if (!config?.apiKey) {
38
- this.error(`Not logged in. Run ${chalk.cyan('mailmodo login')} to authenticate.`);
41
+ this.error(ERRORS.NOT_LOGGED_IN);
39
42
  }
40
43
  this.apiClient = new ApiClient(config.apiKey);
41
44
  return config;
@@ -80,7 +83,7 @@ export class BaseCommand extends Command {
80
83
  async ensureYaml() {
81
84
  const config = await loadYaml();
82
85
  if (!config) {
83
- this.error(`No mailmodo.yaml found. Run ${chalk.cyan('mailmodo init')} first.`);
86
+ this.error(ERRORS.NO_YAML);
84
87
  }
85
88
  return config;
86
89
  }
@@ -96,12 +99,12 @@ export class BaseCommand extends Command {
96
99
  */
97
100
  handleApiError(response) {
98
101
  if (response.status === 401) {
99
- this.error(this.formatApiFailure(`Invalid API key. Run ${chalk.cyan('mailmodo login')} to re-authenticate.`, response));
102
+ this.error(this.formatApiFailure(ERRORS.INVALID_API_KEY, response));
100
103
  }
101
104
  if (response.status === 429) {
102
- this.error(this.formatApiFailure('Rate limit exceeded. Please try again later.', response));
105
+ this.error(this.formatApiFailure(ERRORS.RATE_LIMIT, response));
103
106
  }
104
- this.error(this.formatApiFailure(response.error || 'An unexpected API error occurred.', response));
107
+ this.error(this.formatApiFailure(response.error || ERRORS.UNEXPECTED_API, response));
105
108
  }
106
109
  /**
107
110
  * Builds the terminal error string for a failed API call, appending request
@@ -111,6 +114,86 @@ export class BaseCommand extends Command {
111
114
  * @param {{ status: number; debug?: ApiRequestDebugInfo }} response - Failed API response.
112
115
  * @returns {string} Message plus indented Request details for troubleshooting.
113
116
  */
117
+ async collectDomainSetupInputs(yamlConfig, skipPrompts) {
118
+ if (skipPrompts) {
119
+ const domain = yamlConfig.project?.domain || '';
120
+ if (!domain) {
121
+ this.error('Domain is required. Set it in mailmodo.yaml or use interactive mode.');
122
+ }
123
+ return {
124
+ address: yamlConfig.project?.address || '',
125
+ domain,
126
+ fromEmail: yamlConfig.project?.fromEmail || '',
127
+ fromName: yamlConfig.project?.fromName || '',
128
+ replyTo: yamlConfig.project?.replyTo || '',
129
+ };
130
+ }
131
+ const domain = await input({
132
+ default: yamlConfig.project?.domain,
133
+ message: PROMPTS.DOMAIN,
134
+ validate: (v) => (v?.trim() ? true : VALIDATION.DOMAIN_REQUIRED),
135
+ });
136
+ const fromEmail = await input({
137
+ default: yamlConfig.project?.fromEmail,
138
+ message: PROMPTS.SENDER_EMAIL,
139
+ validate: (v) => (v?.includes('@') ? true : VALIDATION.EMAIL_INVALID),
140
+ });
141
+ const fromName = await input({
142
+ default: yamlConfig.project?.fromName || '',
143
+ message: PROMPTS.FROM_NAME,
144
+ });
145
+ const replyTo = await input({
146
+ default: yamlConfig.project?.replyTo || '',
147
+ message: PROMPTS.REPLY_TO,
148
+ });
149
+ const address = await input({
150
+ default: yamlConfig.project?.address,
151
+ message: PROMPTS.BUSINESS_ADDRESS,
152
+ validate: (v) => (v?.trim() ? true : VALIDATION.ADDRESS_REQUIRED),
153
+ });
154
+ return { address, domain, fromEmail, fromName, replyTo };
155
+ }
156
+ async registerDomain(yamlConfig, inputs, json) {
157
+ const apiPayload = {
158
+ address: inputs.address,
159
+ domain: inputs.domain,
160
+ fromEmail: inputs.fromEmail,
161
+ };
162
+ if (inputs.fromName)
163
+ apiPayload.fromName = inputs.fromName;
164
+ if (inputs.replyTo)
165
+ apiPayload.replyTo = inputs.replyTo;
166
+ const response = await this.withApiSpinner({ json, text: ' Configuring domain...' }, () => this.apiClient.post(API_ENDPOINTS.DOMAIN, apiPayload));
167
+ if (!response.ok) {
168
+ this.handleApiError(response);
169
+ }
170
+ yamlConfig.project.domain = inputs.domain;
171
+ yamlConfig.project.fromEmail = inputs.fromEmail;
172
+ yamlConfig.project.address = inputs.address;
173
+ if (inputs.fromName)
174
+ yamlConfig.project.fromName = inputs.fromName;
175
+ if (inputs.replyTo)
176
+ yamlConfig.project.replyTo = inputs.replyTo;
177
+ await saveYaml(yamlConfig);
178
+ return {
179
+ dnsGuideUrl: response.data?.dnsGuideUrl,
180
+ dnsRecords: response.data?.dnsRecords || [],
181
+ };
182
+ }
183
+ logDnsRecords(records, guideUrl, json) {
184
+ if (json)
185
+ return;
186
+ this.log(`\n Add these ${records.length} DNS records to your domain provider:\n`);
187
+ for (const [i, record] of records.entries()) {
188
+ this.log(` ${chalk.bold(`RECORD ${i + 1} — ${recordLabel(i)}`)}`);
189
+ this.log(` Type: ${record.type}`);
190
+ this.log(` Host: ${record.host}`);
191
+ this.log(` Value: ${record.value}\n`);
192
+ }
193
+ this.log(` ${INFO.DNS_PROPAGATION}`);
194
+ if (guideUrl)
195
+ this.log(` Full guide: ${chalk.cyan(guideUrl)}\n`);
196
+ }
114
197
  formatApiFailure(message, response) {
115
198
  const { debug, status } = response;
116
199
  if (!debug) {
@@ -1,7 +1,6 @@
1
1
  export interface MailmodoConfig {
2
2
  accountName?: string;
3
3
  apiKey: string;
4
- domain?: string;
5
4
  email?: string;
6
5
  freeRemaining?: number;
7
6
  }
@@ -0,0 +1,36 @@
1
+ export declare const SEPARATOR: string;
2
+ export declare const VALIDATION: {
3
+ readonly ADDRESS_REQUIRED: "Address is required";
4
+ readonly DOMAIN_REQUIRED: "Domain is required";
5
+ readonly EMAIL_INVALID: "Please enter a valid email";
6
+ };
7
+ export declare const PROMPTS: {
8
+ readonly BUSINESS_ADDRESS: "Business address (required by law):";
9
+ readonly DOMAIN: "What domain will you send from?";
10
+ readonly ENTER_AFTER_RECORDS: "Press Enter once you've added the records, or 'skip'.";
11
+ readonly FROM_NAME: "Display name (optional, shown as sender name):";
12
+ readonly REPLY_TO: "Reply-to address (optional, press Enter to use sender email):";
13
+ readonly SENDER_EMAIL: "Sender email address:";
14
+ };
15
+ export declare const ERRORS: {
16
+ readonly DOMAIN_NOT_CONFIGURED: `No domain configured. Run ${string} to set up your sending domain.`;
17
+ readonly DOMAIN_NOT_REGISTERED: `Sending domain not registered. Run: ${string}`;
18
+ readonly DOMAIN_NOT_VERIFIED: `Sending domain not verified. Run: ${string}`;
19
+ readonly INVALID_API_KEY: `Invalid API key. Run ${string} to re-authenticate.`;
20
+ readonly NOT_LOGGED_IN: `Not logged in. Run ${string} to authenticate.`;
21
+ readonly NO_YAML: `No mailmodo.yaml found. Run ${string} first.`;
22
+ readonly RATE_LIMIT: "Rate limit exceeded. Please try again later.";
23
+ readonly UNEXPECTED_API: "An unexpected API error occurred.";
24
+ };
25
+ export declare const INFO: {
26
+ readonly BROWSER_OPEN_FAILED: string;
27
+ readonly BROWSER_OPENING: "Opening in browser...";
28
+ readonly DEPLOY_TO_APPLY: `Run ${string} to apply.`;
29
+ readonly DNS_FIX_AND_VERIFY: `Fix the records and run ${string} again.`;
30
+ readonly DNS_PROPAGATION: "DNS changes take 5–30 minutes to propagate.";
31
+ readonly DNS_RECORDS_FAILED: string;
32
+ readonly DOMAIN_NOT_DEPLOYED_HINT: `When ready, run: ${string}
33
+ Then: ${string}`;
34
+ readonly SEQUENCES_NOT_DEPLOYED: `Sequences saved but ${string}.`;
35
+ };
36
+ export declare function recordLabel(index: number): string;
@@ -0,0 +1,39 @@
1
+ import chalk from 'chalk';
2
+ export const SEPARATOR = '─'.repeat(53);
3
+ export const VALIDATION = {
4
+ ADDRESS_REQUIRED: 'Address is required',
5
+ DOMAIN_REQUIRED: 'Domain is required',
6
+ EMAIL_INVALID: 'Please enter a valid email',
7
+ };
8
+ export const PROMPTS = {
9
+ BUSINESS_ADDRESS: 'Business address (required by law):',
10
+ DOMAIN: 'What domain will you send from?',
11
+ ENTER_AFTER_RECORDS: "Press Enter once you've added the records, or 'skip'.",
12
+ FROM_NAME: 'Display name (optional, shown as sender name):',
13
+ REPLY_TO: 'Reply-to address (optional, press Enter to use sender email):',
14
+ SENDER_EMAIL: 'Sender email address:',
15
+ };
16
+ export const ERRORS = {
17
+ DOMAIN_NOT_CONFIGURED: `No domain configured. Run ${chalk.cyan('mailmodo domain')} to set up your sending domain.`,
18
+ DOMAIN_NOT_REGISTERED: `Sending domain not registered. Run: ${chalk.cyan('mailmodo domain')}`,
19
+ DOMAIN_NOT_VERIFIED: `Sending domain not verified. Run: ${chalk.cyan('mailmodo domain --verify')}`,
20
+ INVALID_API_KEY: `Invalid API key. Run ${chalk.cyan('mailmodo login')} to re-authenticate.`,
21
+ NOT_LOGGED_IN: `Not logged in. Run ${chalk.cyan('mailmodo login')} to authenticate.`,
22
+ NO_YAML: `No mailmodo.yaml found. Run ${chalk.cyan('mailmodo init')} first.`,
23
+ RATE_LIMIT: 'Rate limit exceeded. Please try again later.',
24
+ UNEXPECTED_API: 'An unexpected API error occurred.',
25
+ };
26
+ export const INFO = {
27
+ BROWSER_OPEN_FAILED: chalk.dim('Could not open browser. Visit the URL above manually.'),
28
+ BROWSER_OPENING: 'Opening in browser...',
29
+ DEPLOY_TO_APPLY: `Run ${chalk.cyan("'mailmodo deploy'")} to apply.`,
30
+ DNS_FIX_AND_VERIFY: `Fix the records and run ${chalk.cyan('mailmodo domain --verify')} again.`,
31
+ DNS_PROPAGATION: 'DNS changes take 5–30 minutes to propagate.',
32
+ DNS_RECORDS_FAILED: chalk.yellow('Some records failed.'),
33
+ DOMAIN_NOT_DEPLOYED_HINT: `When ready, run: ${chalk.cyan('mailmodo domain')}\n Then: ${chalk.cyan('mailmodo deploy')}`,
34
+ SEQUENCES_NOT_DEPLOYED: `Sequences saved but ${chalk.yellow('NOT deployed')}.`,
35
+ };
36
+ export function recordLabel(index) {
37
+ const labels = ['DKIM', 'DMARC', 'Return Path'];
38
+ return labels[index] || `Record ${index + 1}`;
39
+ }
@@ -442,15 +442,14 @@
442
442
  "index.js"
443
443
  ]
444
444
  },
445
- "logs": {
445
+ "settings": {
446
446
  "aliases": [],
447
447
  "args": {},
448
- "description": "View email send logs and delivery events",
448
+ "description": "View and update project settings",
449
449
  "examples": [
450
- "<%= config.bin %> logs",
451
- "<%= config.bin %> logs --email sarah@example.com",
452
- "<%= config.bin %> logs --failed",
453
- "<%= config.bin %> logs --json"
450
+ "<%= config.bin %> settings",
451
+ "<%= config.bin %> settings --set brand_color=#0F3460",
452
+ "<%= config.bin %> settings --json"
454
453
  ],
455
454
  "flags": {
456
455
  "json": {
@@ -466,31 +465,9 @@
466
465
  "allowNo": false,
467
466
  "type": "boolean"
468
467
  },
469
- "email": {
470
- "description": "Filter logs by contact email",
471
- "name": "email",
472
- "hasDynamicHelp": false,
473
- "multiple": false,
474
- "type": "option"
475
- },
476
- "failed": {
477
- "description": "Show only failed/bounced events",
478
- "name": "failed",
479
- "allowNo": false,
480
- "type": "boolean"
481
- },
482
- "limit": {
483
- "description": "Entries per page (max 200)",
484
- "name": "limit",
485
- "default": 50,
486
- "hasDynamicHelp": false,
487
- "multiple": false,
488
- "type": "option"
489
- },
490
- "page": {
491
- "description": "Page number",
492
- "name": "page",
493
- "default": 1,
468
+ "set": {
469
+ "description": "Set a setting (format: key=value)",
470
+ "name": "set",
494
471
  "hasDynamicHelp": false,
495
472
  "multiple": false,
496
473
  "type": "option"
@@ -498,7 +475,7 @@
498
475
  },
499
476
  "hasDynamicHelp": false,
500
477
  "hiddenAliases": [],
501
- "id": "logs",
478
+ "id": "settings",
502
479
  "pluginAlias": "@mailmodo/cli",
503
480
  "pluginName": "@mailmodo/cli",
504
481
  "pluginType": "core",
@@ -508,7 +485,7 @@
508
485
  "relativePath": [
509
486
  "dist",
510
487
  "commands",
511
- "logs",
488
+ "settings",
512
489
  "index.js"
513
490
  ]
514
491
  },
@@ -570,14 +547,13 @@
570
547
  "index.js"
571
548
  ]
572
549
  },
573
- "settings": {
550
+ "status": {
574
551
  "aliases": [],
575
552
  "args": {},
576
- "description": "View and update project settings",
553
+ "description": "View email performance metrics and quota usage",
577
554
  "examples": [
578
- "<%= config.bin %> settings",
579
- "<%= config.bin %> settings --set brand_color=#0F3460",
580
- "<%= config.bin %> settings --json"
555
+ "<%= config.bin %> status",
556
+ "<%= config.bin %> status --json"
581
557
  ],
582
558
  "flags": {
583
559
  "json": {
@@ -592,18 +568,11 @@
592
568
  "name": "yes",
593
569
  "allowNo": false,
594
570
  "type": "boolean"
595
- },
596
- "set": {
597
- "description": "Set a setting (format: key=value)",
598
- "name": "set",
599
- "hasDynamicHelp": false,
600
- "multiple": false,
601
- "type": "option"
602
571
  }
603
572
  },
604
573
  "hasDynamicHelp": false,
605
574
  "hiddenAliases": [],
606
- "id": "settings",
575
+ "id": "status",
607
576
  "pluginAlias": "@mailmodo/cli",
608
577
  "pluginName": "@mailmodo/cli",
609
578
  "pluginType": "core",
@@ -613,17 +582,19 @@
613
582
  "relativePath": [
614
583
  "dist",
615
584
  "commands",
616
- "settings",
585
+ "status",
617
586
  "index.js"
618
587
  ]
619
588
  },
620
- "status": {
589
+ "logs": {
621
590
  "aliases": [],
622
591
  "args": {},
623
- "description": "View email performance metrics and quota usage",
592
+ "description": "View email send logs and delivery events",
624
593
  "examples": [
625
- "<%= config.bin %> status",
626
- "<%= config.bin %> status --json"
594
+ "<%= config.bin %> logs",
595
+ "<%= config.bin %> logs --email sarah@example.com",
596
+ "<%= config.bin %> logs --failed",
597
+ "<%= config.bin %> logs --json"
627
598
  ],
628
599
  "flags": {
629
600
  "json": {
@@ -638,11 +609,40 @@
638
609
  "name": "yes",
639
610
  "allowNo": false,
640
611
  "type": "boolean"
612
+ },
613
+ "email": {
614
+ "description": "Filter logs by contact email",
615
+ "name": "email",
616
+ "hasDynamicHelp": false,
617
+ "multiple": false,
618
+ "type": "option"
619
+ },
620
+ "failed": {
621
+ "description": "Show only failed/bounced events",
622
+ "name": "failed",
623
+ "allowNo": false,
624
+ "type": "boolean"
625
+ },
626
+ "limit": {
627
+ "description": "Entries per page (max 200)",
628
+ "name": "limit",
629
+ "default": 50,
630
+ "hasDynamicHelp": false,
631
+ "multiple": false,
632
+ "type": "option"
633
+ },
634
+ "page": {
635
+ "description": "Page number",
636
+ "name": "page",
637
+ "default": 1,
638
+ "hasDynamicHelp": false,
639
+ "multiple": false,
640
+ "type": "option"
641
641
  }
642
642
  },
643
643
  "hasDynamicHelp": false,
644
644
  "hiddenAliases": [],
645
- "id": "status",
645
+ "id": "logs",
646
646
  "pluginAlias": "@mailmodo/cli",
647
647
  "pluginName": "@mailmodo/cli",
648
648
  "pluginType": "core",
@@ -652,10 +652,10 @@
652
652
  "relativePath": [
653
653
  "dist",
654
654
  "commands",
655
- "status",
655
+ "logs",
656
656
  "index.js"
657
657
  ]
658
658
  }
659
659
  },
660
- "version": "0.0.30-beta.pr32.53"
660
+ "version": "0.0.31-beta.pr33.54"
661
661
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mailmodo/cli",
3
3
  "description": "Email lifecycle automation for the AI-native builder generation.",
4
- "version": "0.0.30-beta.pr32.53",
4
+ "version": "0.0.31-beta.pr33.54",
5
5
  "author": "provishalk",
6
6
  "bin": {
7
7
  "mailmodo": "bin/run.js"