@mailmodo/cli 0.0.8-beta.pr10.14 → 0.0.9-beta.pr11.15

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.
@@ -35,7 +35,7 @@ export default class Billing extends BaseCommand {
35
35
  * opens Stripe Checkout if no card is on file.
36
36
  */
37
37
  async showStatus(jsonOutput) {
38
- const response = await this.apiClient.get(API_ENDPOINTS.BILLING_STATUS);
38
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Loading billing status...' }, () => this.apiClient.get(API_ENDPOINTS.BILLING_STATUS));
39
39
  if (!response.ok) {
40
40
  this.handleApiError(response);
41
41
  }
@@ -84,9 +84,9 @@ export default class Billing extends BaseCommand {
84
84
  * @param {boolean} jsonOutput - Whether to output JSON instead of formatted text.
85
85
  */
86
86
  async setCap(cap, jsonOutput) {
87
- const response = await this.apiClient.patch(API_ENDPOINTS.BILLING_CAP, {
87
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Updating spending cap...' }, () => this.apiClient.patch(API_ENDPOINTS.BILLING_CAP, {
88
88
  cap,
89
- });
89
+ }));
90
90
  if (!response.ok) {
91
91
  this.handleApiError(response);
92
92
  }
@@ -43,7 +43,7 @@ export default class Contacts extends BaseCommand {
43
43
  * Displays aggregate contact counts: total, active, unsubscribed, bounced.
44
44
  */
45
45
  async showSummary(jsonOutput) {
46
- const response = await this.apiClient.get(API_ENDPOINTS.CONTACTS);
46
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Loading contacts...' }, () => this.apiClient.get(API_ENDPOINTS.CONTACTS));
47
47
  if (!response.ok) {
48
48
  this.handleApiError(response);
49
49
  }
@@ -62,7 +62,7 @@ export default class Contacts extends BaseCommand {
62
62
  * status, properties, and pending emails.
63
63
  */
64
64
  async searchContact(email, jsonOutput) {
65
- const response = await this.apiClient.get(`${API_ENDPOINTS.CONTACTS}/${encodeURIComponent(email)}`);
65
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Looking up contact...' }, () => this.apiClient.get(`${API_ENDPOINTS.CONTACTS}/${encodeURIComponent(email)}`));
66
66
  if (!response.ok) {
67
67
  if (response.status === 404) {
68
68
  if (jsonOutput) {
@@ -97,7 +97,7 @@ export default class Contacts extends BaseCommand {
97
97
  * for the generated file.
98
98
  */
99
99
  async exportContacts(jsonOutput) {
100
- const response = await this.apiClient.get(API_ENDPOINTS.CONTACTS_EXPORT);
100
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Preparing contact export...' }, () => this.apiClient.get(API_ENDPOINTS.CONTACTS_EXPORT));
101
101
  if (!response.ok) {
102
102
  this.handleApiError(response);
103
103
  }
@@ -126,7 +126,7 @@ export default class Contacts extends BaseCommand {
126
126
  return;
127
127
  }
128
128
  }
129
- const response = await this.apiClient.delete(`${API_ENDPOINTS.CONTACTS}/${encodeURIComponent(email)}`);
129
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Deleting contact...' }, () => this.apiClient.delete(`${API_ENDPOINTS.CONTACTS}/${encodeURIComponent(email)}`));
130
130
  if (!response.ok) {
131
131
  this.handleApiError(response);
132
132
  }
@@ -6,7 +6,24 @@ export default class Deploy extends BaseCommand {
6
6
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
7
  yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
8
  };
9
+ /**
10
+ * Fetches current DNS verification status for the deploy flow.
11
+ *
12
+ * @param jsonOutput - When true, spinner uses stderr for stdout-safe JSON runs.
13
+ */
14
+ private fetchDomainVerifyForDeploy;
9
15
  run(): Promise<void>;
16
+ /**
17
+ * Lists emails about to be deployed (skipped when `--json` is set).
18
+ *
19
+ * @param yamlConfig - Loaded project YAML.
20
+ * @param jsonOutput - When true, skip human-readable output.
21
+ */
22
+ private logPreDeploySummary;
23
+ /**
24
+ * Prints the post-deploy success message and SDK install snippet for interactive runs.
25
+ */
26
+ private logDeploySuccessInstructions;
10
27
  /**
11
28
  * Interactive domain setup flow. Collects domain, sender email, and business
12
29
  * address from the user, then calls the API to get DNS records to configure.
@@ -12,11 +12,19 @@ export default class Deploy extends BaseCommand {
12
12
  static flags = {
13
13
  ...BaseCommand.baseFlags,
14
14
  };
15
+ /**
16
+ * Fetches current DNS verification status for the deploy flow.
17
+ *
18
+ * @param jsonOutput - When true, spinner uses stderr for stdout-safe JSON runs.
19
+ */
20
+ fetchDomainVerifyForDeploy(jsonOutput) {
21
+ return this.withApiSpinner({ json: jsonOutput, text: ' Checking domain verification...' }, () => this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY));
22
+ }
15
23
  async run() {
16
24
  const { flags } = await this.parse(Deploy);
17
25
  await this.ensureAuth();
18
26
  const yamlConfig = await this.ensureYaml();
19
- const domainVerify = await this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY);
27
+ const domainVerify = await this.fetchDomainVerifyForDeploy(flags.json);
20
28
  const domainVerified = domainVerify.ok &&
21
29
  domainVerify.data?.spf === 'pass' &&
22
30
  domainVerify.data?.dkim === 'pass' &&
@@ -44,14 +52,7 @@ export default class Deploy extends BaseCommand {
44
52
  if (!completed)
45
53
  return;
46
54
  }
47
- if (!flags.json) {
48
- this.log(`\n ${chalk.green('✓')} Domain: ${yamlConfig.project?.domain || 'verified'}\n`);
49
- this.log(` Deploying:`);
50
- for (const email of yamlConfig.emails) {
51
- this.log(` ${chalk.green('+')} ${email.id.padEnd(24)} ${email.trigger}`);
52
- }
53
- this.log('');
54
- }
55
+ this.logPreDeploySummary(yamlConfig, flags.json);
55
56
  if (!flags.yes) {
56
57
  const proceed = await confirm({
57
58
  default: true,
@@ -62,10 +63,10 @@ export default class Deploy extends BaseCommand {
62
63
  return;
63
64
  }
64
65
  }
65
- const response = await this.apiClient.post(API_ENDPOINTS.SEQUENCES, {
66
+ const response = await this.withApiSpinner({ json: flags.json, text: ' Deploying email sequences...' }, () => this.apiClient.post(API_ENDPOINTS.SEQUENCES, {
66
67
  emails: yamlConfig.emails,
67
68
  project: yamlConfig.project,
68
- });
69
+ }));
69
70
  if (!response.ok) {
70
71
  this.handleApiError(response);
71
72
  }
@@ -77,6 +78,28 @@ export default class Deploy extends BaseCommand {
77
78
  }, null, 2));
78
79
  return;
79
80
  }
81
+ this.logDeploySuccessInstructions();
82
+ }
83
+ /**
84
+ * Lists emails about to be deployed (skipped when `--json` is set).
85
+ *
86
+ * @param yamlConfig - Loaded project YAML.
87
+ * @param jsonOutput - When true, skip human-readable output.
88
+ */
89
+ logPreDeploySummary(yamlConfig, jsonOutput) {
90
+ if (jsonOutput)
91
+ return;
92
+ this.log(`\n ${chalk.green('✓')} Domain: ${yamlConfig.project?.domain || 'verified'}\n`);
93
+ this.log(` Deploying:`);
94
+ for (const email of yamlConfig.emails) {
95
+ this.log(` ${chalk.green('+')} ${email.id.padEnd(24)} ${email.trigger}`);
96
+ }
97
+ this.log('');
98
+ }
99
+ /**
100
+ * Prints the post-deploy success message and SDK install snippet for interactive runs.
101
+ */
102
+ logDeploySuccessInstructions() {
80
103
  this.log(` ${chalk.green('Deployed.')} Emails are live.\n`);
81
104
  this.log(` ${'─'.repeat(53)}`);
82
105
  this.log(` ${chalk.bold('ADD THIS TO YOUR APP (one-time only):')}`);
@@ -125,11 +148,11 @@ export default class Deploy extends BaseCommand {
125
148
  validate: (v) => (v?.trim() ? true : 'Address is required'),
126
149
  });
127
150
  }
128
- const domainResponse = await this.apiClient.post(API_ENDPOINTS.DOMAIN, {
151
+ const domainResponse = await this.withApiSpinner({ json: flags.json, text: ' Configuring domain...' }, () => this.apiClient.post(API_ENDPOINTS.DOMAIN, {
129
152
  address,
130
153
  domain,
131
154
  fromEmail: senderEmail,
132
- });
155
+ }));
133
156
  if (!domainResponse.ok) {
134
157
  this.handleApiError(domainResponse);
135
158
  }
@@ -171,10 +194,7 @@ export default class Deploy extends BaseCommand {
171
194
  * @returns {Promise<boolean>} true if all records pass.
172
195
  */
173
196
  async verifyDomain(jsonOutput) {
174
- if (!jsonOutput) {
175
- this.log(`\n Checking DNS...`);
176
- }
177
- const verify = await this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY);
197
+ const verify = await this.withApiSpinner({ json: jsonOutput, text: ' Checking DNS...' }, () => this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY));
178
198
  if (!verify.ok) {
179
199
  this.handleApiError(verify);
180
200
  }
@@ -72,11 +72,11 @@ export default class Domain extends BaseCommand {
72
72
  validate: (v) => (v?.trim() ? true : 'Address is required'),
73
73
  });
74
74
  }
75
- const response = await this.apiClient.post(API_ENDPOINTS.DOMAIN, {
75
+ const response = await this.withApiSpinner({ json: flags.json, text: ' Configuring domain...' }, () => this.apiClient.post(API_ENDPOINTS.DOMAIN, {
76
76
  address,
77
77
  domain,
78
78
  fromEmail: senderEmail,
79
- });
79
+ }));
80
80
  if (!response.ok) {
81
81
  this.handleApiError(response);
82
82
  }
@@ -112,10 +112,7 @@ export default class Domain extends BaseCommand {
112
112
  * Calls the domain verification API and displays pass/fail for each DNS record.
113
113
  */
114
114
  async verifyDomain(jsonOutput) {
115
- if (!jsonOutput) {
116
- this.log(`\n Checking DNS...`);
117
- }
118
- const response = await this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY);
115
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Checking DNS...' }, () => this.apiClient.get(API_ENDPOINTS.DOMAIN_VERIFY));
119
116
  if (!response.ok) {
120
117
  this.handleApiError(response);
121
118
  }
@@ -148,7 +145,7 @@ export default class Domain extends BaseCommand {
148
145
  * bounce rate, and spam complaint rate.
149
146
  */
150
147
  async showDomainStatus(jsonOutput) {
151
- const response = await this.apiClient.get(API_ENDPOINTS.DOMAIN_STATUS);
148
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Loading domain status...' }, () => this.apiClient.get(API_ENDPOINTS.DOMAIN_STATUS));
152
149
  if (!response.ok) {
153
150
  this.handleApiError(response);
154
151
  }
@@ -39,7 +39,7 @@ export default class Edit extends BaseCommand {
39
39
  validate: (value) => value?.trim() ? true : 'Please describe the change',
40
40
  });
41
41
  }
42
- const response = await this.apiClient.post(API_ENDPOINTS.EDIT, {
42
+ const response = await this.withApiSpinner({ json: flags.json, text: ' Applying AI edits...' }, () => this.apiClient.post(API_ENDPOINTS.EDIT, {
43
43
  changeRequest: changeDescription,
44
44
  currentEmail: {
45
45
  condition: email.condition,
@@ -50,7 +50,7 @@ export default class Edit extends BaseCommand {
50
50
  subject: email.subject,
51
51
  trigger: email.trigger,
52
52
  },
53
- });
53
+ }));
54
54
  if (!response.ok) {
55
55
  this.handleApiError(response);
56
56
  }
@@ -12,6 +12,23 @@ function isValidUrl(value) {
12
12
  return false;
13
13
  }
14
14
  }
15
+ /**
16
+ * Prints the human-readable analysis summary using the provided line writer.
17
+ * Use stderr when `--json` is set so stdout stays free for machine-readable JSON.
18
+ *
19
+ * @param analysis - Parsed analyze API payload.
20
+ * @param logLine - Line writer (typically bound `this.log` or `this.logToStderr`).
21
+ */
22
+ function logAnalysisSummary(analysis, logLine) {
23
+ logLine(` Detected:`);
24
+ logLine(` - Type: ${analysis.businessType} — ${analysis.description}`);
25
+ logLine(` - Model: ${analysis.pricingModel}`);
26
+ logLine(` - Users: ${analysis.targetUser}`);
27
+ if (analysis.events?.length) {
28
+ logLine(` - Events: ${analysis.events.join(', ')}`);
29
+ }
30
+ logLine('');
31
+ }
15
32
  export default class Init extends BaseCommand {
16
33
  static description = 'Analyze your product and generate email sequences';
17
34
  static examples = [
@@ -38,22 +55,22 @@ export default class Init extends BaseCommand {
38
55
  },
39
56
  });
40
57
  }
41
- this.log(`\n Analyzing your product...`);
42
- this.log(` Scraping: homepage, pricing, features\n`);
43
- const analysisResponse = await this.apiClient.post(API_ENDPOINTS.ANALYZE, { url: productUrl });
58
+ const analysisResponse = await this.withApiSpinner({
59
+ json: flags.json,
60
+ text: ' Analyzing your product scraping homepage, pricing, features',
61
+ }, () => this.apiClient.post(API_ENDPOINTS.ANALYZE, {
62
+ url: productUrl,
63
+ }));
44
64
  if (!analysisResponse.ok) {
45
65
  this.handleApiError(analysisResponse);
46
66
  }
47
67
  const analysis = analysisResponse.data;
48
- if (!flags.json) {
49
- this.log(` Detected:`);
50
- this.log(` - Type: ${analysis.businessType} ${analysis.description}`);
51
- this.log(` - Model: ${analysis.pricingModel}`);
52
- this.log(` - Users: ${analysis.targetUser}`);
53
- if (analysis.events?.length) {
54
- this.log(` - Events: ${analysis.events.join(', ')}`);
55
- }
56
- this.log('');
68
+ const shouldShowAnalysisSummary = !flags.json || !flags.yes;
69
+ if (shouldShowAnalysisSummary) {
70
+ const logSummary = flags.json && !flags.yes
71
+ ? this.logToStderr.bind(this)
72
+ : this.log.bind(this);
73
+ logAnalysisSummary(analysis, logSummary);
57
74
  }
58
75
  let analysisPayload = analysis;
59
76
  if (!flags.yes) {
@@ -89,12 +106,13 @@ export default class Init extends BaseCommand {
89
106
  analysisPayload = JSON.parse(editedAnalysis);
90
107
  }
91
108
  }
92
- this.log('analysisPayload', analysisPayload);
93
- this.log('\n Generating emails...\n');
94
- const generateResponse = await this.apiClient.post(API_ENDPOINTS.GENERATE, {
109
+ const generateResponse = await this.withApiSpinner({
110
+ json: flags.json,
111
+ text: ' Generating email templates...',
112
+ }, () => this.apiClient.post(API_ENDPOINTS.GENERATE, {
95
113
  analysis: analysisPayload,
96
114
  productUrl,
97
- });
115
+ }));
98
116
  if (!generateResponse.ok) {
99
117
  this.handleApiError(generateResponse);
100
118
  }
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import open from 'open';
4
4
  import { BaseCommand } from '../../lib/base-command.js';
5
5
  import { ApiClient } from '../../lib/api-client.js';
6
- import { saveConfig } from '../../lib/config.js';
6
+ import { loadConfig, saveConfig } from '../../lib/config.js';
7
7
  import { API_ENDPOINTS, SIGNUP_URL } from '../../lib/constants.js';
8
8
  export default class Login extends BaseCommand {
9
9
  static description = 'Authenticate with Mailmodo using your API key';
@@ -16,7 +16,30 @@ export default class Login extends BaseCommand {
16
16
  };
17
17
  async run() {
18
18
  const { flags } = await this.parse(Login);
19
- let apiKey = process.env.MAILMODO_API_KEY;
19
+ const envKey = process.env.MAILMODO_API_KEY;
20
+ if (!envKey) {
21
+ const existing = await loadConfig();
22
+ if (existing?.apiKey) {
23
+ if (flags.json) {
24
+ this.log(JSON.stringify({
25
+ accountName: existing.accountName ?? null,
26
+ email: existing.email ?? null,
27
+ freeRemaining: existing.freeRemaining ?? null,
28
+ status: 'already_logged_in',
29
+ }, null, 2));
30
+ return;
31
+ }
32
+ this.log('\n You are already logged in.\n');
33
+ const emailDisplay = existing.email?.trim()
34
+ ? chalk.green(existing.email.trim())
35
+ : chalk.dim('(unknown)');
36
+ this.log(` Email: ${emailDisplay}\n`);
37
+ this.log(` ${chalk.dim('1.')} Run ${chalk.cyan('mailmodo init')} to generate an email sequence.`);
38
+ this.log(` ${chalk.dim('2.')} Run ${chalk.cyan('mailmodo logout')} to log in with another account.\n`);
39
+ return;
40
+ }
41
+ }
42
+ let apiKey = envKey;
20
43
  if (apiKey) {
21
44
  this.log('Detected MAILMODO_API_KEY from environment.');
22
45
  }
@@ -40,7 +63,7 @@ export default class Login extends BaseCommand {
40
63
  }
41
64
  const trimmedKey = apiKey.trim();
42
65
  const client = new ApiClient(trimmedKey);
43
- const response = await client.post(API_ENDPOINTS.AUTH_VALIDATE, {});
66
+ const response = await this.withApiSpinner({ json: flags.json, text: ' Validating API key...' }, () => client.post(API_ENDPOINTS.AUTH_VALIDATE, {}));
44
67
  if (!response.ok) {
45
68
  this.handleApiError(response);
46
69
  }
@@ -0,0 +1,10 @@
1
+ import { BaseCommand } from '../../lib/base-command.js';
2
+ export default class Logout extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ };
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,28 @@
1
+ import chalk from 'chalk';
2
+ import { BaseCommand } from '../../lib/base-command.js';
3
+ import { clearConfig, loadConfig } from '../../lib/config.js';
4
+ export default class Logout extends BaseCommand {
5
+ static description = 'Sign out by removing saved credentials from this machine';
6
+ static examples = ['<%= config.bin %> logout'];
7
+ static flags = {
8
+ ...BaseCommand.baseFlags,
9
+ };
10
+ async run() {
11
+ const { flags } = await this.parse(Logout);
12
+ const config = await loadConfig();
13
+ if (!config?.apiKey) {
14
+ if (flags.json) {
15
+ this.log(JSON.stringify({ status: 'not_logged_in' }, null, 2));
16
+ return;
17
+ }
18
+ this.log('You are not logged in.');
19
+ return;
20
+ }
21
+ await clearConfig();
22
+ if (flags.json) {
23
+ this.log(JSON.stringify({ status: 'logged_out' }, null, 2));
24
+ return;
25
+ }
26
+ this.log(`\n Signed out. Run ${chalk.cyan('mailmodo login')} to authenticate again.\n`);
27
+ }
28
+ }
@@ -26,7 +26,7 @@ export default class Logs extends BaseCommand {
26
26
  params.email = flags.email;
27
27
  if (flags.failed)
28
28
  params.failed = 'true';
29
- const response = await this.apiClient.get(API_ENDPOINTS.LOGS, params);
29
+ const response = await this.withApiSpinner({ json: flags.json, text: ' Loading email logs...' }, () => this.apiClient.get(API_ENDPOINTS.LOGS, params));
30
30
  if (!response.ok) {
31
31
  this.handleApiError(response);
32
32
  }
@@ -125,9 +125,9 @@ export default class Preview extends BaseCommand {
125
125
  */
126
126
  async sendTestEmail(emailId, toAddress, jsonOutput) {
127
127
  await this.ensureAuth();
128
- const response = await this.apiClient.post(`${API_ENDPOINTS.PREVIEW}/${emailId}/send`, {
128
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Sending test email...' }, () => this.apiClient.post(`${API_ENDPOINTS.PREVIEW}/${emailId}/send`, {
129
129
  to: toAddress,
130
- });
130
+ }));
131
131
  if (!response.ok) {
132
132
  this.handleApiError(response);
133
133
  }
@@ -14,6 +14,7 @@ export default class Settings extends BaseCommand {
14
14
  * and logoUrl in the project config.
15
15
  *
16
16
  * @param {import('../../lib/yaml-config.js').MailmodoYaml} yamlConfig - The full YAML config to update and save.
17
+ * @param {boolean} jsonOutput - When true, spinner uses stderr so stdout stays clean.
17
18
  */
18
19
  private handleLogoUpload;
19
20
  }
@@ -89,7 +89,7 @@ export default class Settings extends BaseCommand {
89
89
  return;
90
90
  }
91
91
  if (editKey === 'logo_file') {
92
- await this.handleLogoUpload(yamlConfig);
92
+ await this.handleLogoUpload(yamlConfig, flags.json);
93
93
  return;
94
94
  }
95
95
  if (editKey === 'email_style') {
@@ -122,8 +122,9 @@ export default class Settings extends BaseCommand {
122
122
  * and logoUrl in the project config.
123
123
  *
124
124
  * @param {import('../../lib/yaml-config.js').MailmodoYaml} yamlConfig - The full YAML config to update and save.
125
+ * @param {boolean} jsonOutput - When true, spinner uses stderr so stdout stays clean.
125
126
  */
126
- async handleLogoUpload(yamlConfig) {
127
+ async handleLogoUpload(yamlConfig, jsonOutput) {
127
128
  const logoPath = await input({ message: 'Path to logo file:' });
128
129
  const resolvedPath = resolve(logoPath);
129
130
  if (!existsSync(resolvedPath)) {
@@ -134,7 +135,7 @@ export default class Settings extends BaseCommand {
134
135
  const fileBuffer = await readFile(resolvedPath);
135
136
  const formData = new FormData();
136
137
  formData.append('logo', new Blob([new Uint8Array(fileBuffer)]), logoPath.split(/[/\\]/).pop() || 'logo.png');
137
- const response = await this.apiClient.postFormData(API_ENDPOINTS.ASSETS_LOGO, formData);
138
+ const response = await this.withApiSpinner({ json: jsonOutput, text: ' Uploading logo...' }, () => this.apiClient.postFormData(API_ENDPOINTS.ASSETS_LOGO, formData));
138
139
  if (!response.ok) {
139
140
  this.handleApiError(response);
140
141
  }
@@ -13,7 +13,7 @@ export default class Status extends BaseCommand {
13
13
  async run() {
14
14
  const { flags } = await this.parse(Status);
15
15
  await this.ensureAuth();
16
- const response = await this.apiClient.get(API_ENDPOINTS.ANALYTICS);
16
+ const response = await this.withApiSpinner({ json: flags.json, text: ' Loading analytics...' }, () => this.apiClient.get(API_ENDPOINTS.ANALYTICS));
17
17
  if (!response.ok) {
18
18
  this.handleApiError(response);
19
19
  }
@@ -22,6 +22,22 @@ export declare abstract class BaseCommand extends Command {
22
22
  * @returns {Promise<MailmodoConfig>} The resolved configuration containing the API key.
23
23
  */
24
24
  protected ensureAuth(): Promise<MailmodoConfig>;
25
+ /**
26
+ * Runs an async function (typically an API call) while showing a cyan ora spinner.
27
+ * When `options.json` is true, the leading blank line is written to stderr so stdout stays
28
+ * free for machine-readable JSON (e.g. piping to `jq`).
29
+ *
30
+ * @template T - Resolved type of the work promise (often the API client response).
31
+ * @param {{ json: boolean; text: string }} options - Spinner options.
32
+ * @param {boolean} options.json - If true, stderr for the blank line before the spinner.
33
+ * @param {string} options.text - Spinner label (often two leading spaces).
34
+ * @param {() => Promise<T>} work - Zero-argument async function that performs the request.
35
+ * @returns {Promise<T>} The fulfilled value from `work`.
36
+ */
37
+ protected withApiSpinner<T>(options: {
38
+ json: boolean;
39
+ text: string;
40
+ }, work: () => Promise<T>): Promise<T>;
25
41
  /**
26
42
  * Loads and returns the mailmodo.yaml configuration from the current directory.
27
43
  * Exits with an error if the file is not found, directing the user to run init.
@@ -1,5 +1,6 @@
1
1
  import { Command, Flags } from '@oclif/core';
2
2
  import chalk from 'chalk';
3
+ import ora from 'ora';
3
4
  import { ApiClient } from './api-client.js';
4
5
  import { loadConfig } from './config.js';
5
6
  import { loadYaml } from './yaml-config.js';
@@ -39,6 +40,36 @@ export class BaseCommand extends Command {
39
40
  this.apiClient = new ApiClient(config.apiKey);
40
41
  return config;
41
42
  }
43
+ /**
44
+ * Runs an async function (typically an API call) while showing a cyan ora spinner.
45
+ * When `options.json` is true, the leading blank line is written to stderr so stdout stays
46
+ * free for machine-readable JSON (e.g. piping to `jq`).
47
+ *
48
+ * @template T - Resolved type of the work promise (often the API client response).
49
+ * @param {{ json: boolean; text: string }} options - Spinner options.
50
+ * @param {boolean} options.json - If true, stderr for the blank line before the spinner.
51
+ * @param {string} options.text - Spinner label (often two leading spaces).
52
+ * @param {() => Promise<T>} work - Zero-argument async function that performs the request.
53
+ * @returns {Promise<T>} The fulfilled value from `work`.
54
+ */
55
+ async withApiSpinner(options, work) {
56
+ if (options.json) {
57
+ this.logToStderr('');
58
+ }
59
+ else {
60
+ this.log('');
61
+ }
62
+ const spinner = ora({
63
+ color: 'cyan',
64
+ text: options.text,
65
+ }).start();
66
+ try {
67
+ return await work();
68
+ }
69
+ finally {
70
+ spinner.stop();
71
+ }
72
+ }
42
73
  /**
43
74
  * Loads and returns the mailmodo.yaml configuration from the current directory.
44
75
  * Exits with an error if the file is not found, directing the user to run init.
@@ -22,6 +22,11 @@ export declare function loadConfig(): Promise<MailmodoConfig | null>;
22
22
  * at minimum an apiKey. Optional fields: email, accountName, freeRemaining.
23
23
  */
24
24
  export declare function saveConfig(config: MailmodoConfig): Promise<void>;
25
+ /**
26
+ * Deletes the saved CLI config file (~/.mailmodo/config), removing the stored API key.
27
+ * No-op if the file does not exist.
28
+ */
29
+ export declare function clearConfig(): Promise<void>;
25
30
  /**
26
31
  * Returns the absolute path to the Mailmodo config directory (~/.mailmodo).
27
32
  *
@@ -1,5 +1,5 @@
1
1
  import { existsSync } from 'node:fs';
2
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
3
3
  import { homedir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
  const CONFIG_DIR = join(homedir(), '.mailmodo');
@@ -13,7 +13,6 @@ const CONFIG_FILE = join(CONFIG_DIR, 'config');
13
13
  * or null if the config file does not exist or is corrupted.
14
14
  */
15
15
  export async function loadConfig() {
16
- console.log('Loading config from', CONFIG_FILE);
17
16
  if (!existsSync(CONFIG_FILE))
18
17
  return null;
19
18
  try {
@@ -38,6 +37,20 @@ export async function saveConfig(config) {
38
37
  }
39
38
  await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2));
40
39
  }
40
+ /**
41
+ * Deletes the saved CLI config file (~/.mailmodo/config), removing the stored API key.
42
+ * No-op if the file does not exist.
43
+ */
44
+ export async function clearConfig() {
45
+ if (!existsSync(CONFIG_FILE))
46
+ return;
47
+ try {
48
+ await unlink(CONFIG_FILE);
49
+ }
50
+ catch {
51
+ // Ignore missing file or permission errors; caller can treat as best-effort sign-out.
52
+ }
53
+ }
41
54
  /**
42
55
  * Returns the absolute path to the Mailmodo config directory (~/.mailmodo).
43
56
  *
@@ -153,14 +153,13 @@
153
153
  "index.js"
154
154
  ]
155
155
  },
156
- "domain": {
156
+ "emails": {
157
157
  "aliases": [],
158
158
  "args": {},
159
- "description": "Set up and verify your sending domain",
159
+ "description": "List and view configured email sequences",
160
160
  "examples": [
161
- "<%= config.bin %> domain",
162
- "<%= config.bin %> domain --verify",
163
- "<%= config.bin %> domain --status"
161
+ "<%= config.bin %> emails",
162
+ "<%= config.bin %> emails --json"
164
163
  ],
165
164
  "flags": {
166
165
  "json": {
@@ -175,23 +174,11 @@
175
174
  "name": "yes",
176
175
  "allowNo": false,
177
176
  "type": "boolean"
178
- },
179
- "status": {
180
- "description": "Show domain health status",
181
- "name": "status",
182
- "allowNo": false,
183
- "type": "boolean"
184
- },
185
- "verify": {
186
- "description": "Verify DNS records",
187
- "name": "verify",
188
- "allowNo": false,
189
- "type": "boolean"
190
177
  }
191
178
  },
192
179
  "hasDynamicHelp": false,
193
180
  "hiddenAliases": [],
194
- "id": "domain",
181
+ "id": "emails",
195
182
  "pluginAlias": "@mailmodo/cli",
196
183
  "pluginName": "@mailmodo/cli",
197
184
  "pluginType": "core",
@@ -201,17 +188,23 @@
201
188
  "relativePath": [
202
189
  "dist",
203
190
  "commands",
204
- "domain",
191
+ "emails",
205
192
  "index.js"
206
193
  ]
207
194
  },
208
- "emails": {
195
+ "edit": {
209
196
  "aliases": [],
210
- "args": {},
211
- "description": "List and view configured email sequences",
197
+ "args": {
198
+ "id": {
199
+ "description": "Email ID to edit",
200
+ "name": "id",
201
+ "required": true
202
+ }
203
+ },
204
+ "description": "Edit an email using AI-assisted natural language changes",
212
205
  "examples": [
213
- "<%= config.bin %> emails",
214
- "<%= config.bin %> emails --json"
206
+ "<%= config.bin %> edit welcome",
207
+ "<%= config.bin %> edit welcome --change \"make subject more urgent\" --yes"
215
208
  ],
216
209
  "flags": {
217
210
  "json": {
@@ -226,11 +219,18 @@
226
219
  "name": "yes",
227
220
  "allowNo": false,
228
221
  "type": "boolean"
222
+ },
223
+ "change": {
224
+ "description": "Natural language description of the change",
225
+ "name": "change",
226
+ "hasDynamicHelp": false,
227
+ "multiple": false,
228
+ "type": "option"
229
229
  }
230
230
  },
231
231
  "hasDynamicHelp": false,
232
232
  "hiddenAliases": [],
233
- "id": "emails",
233
+ "id": "edit",
234
234
  "pluginAlias": "@mailmodo/cli",
235
235
  "pluginName": "@mailmodo/cli",
236
236
  "pluginType": "core",
@@ -240,23 +240,18 @@
240
240
  "relativePath": [
241
241
  "dist",
242
242
  "commands",
243
- "emails",
243
+ "edit",
244
244
  "index.js"
245
245
  ]
246
246
  },
247
- "edit": {
247
+ "domain": {
248
248
  "aliases": [],
249
- "args": {
250
- "id": {
251
- "description": "Email ID to edit",
252
- "name": "id",
253
- "required": true
254
- }
255
- },
256
- "description": "Edit an email using AI-assisted natural language changes",
249
+ "args": {},
250
+ "description": "Set up and verify your sending domain",
257
251
  "examples": [
258
- "<%= config.bin %> edit welcome",
259
- "<%= config.bin %> edit welcome --change \"make subject more urgent\" --yes"
252
+ "<%= config.bin %> domain",
253
+ "<%= config.bin %> domain --verify",
254
+ "<%= config.bin %> domain --status"
260
255
  ],
261
256
  "flags": {
262
257
  "json": {
@@ -272,17 +267,22 @@
272
267
  "allowNo": false,
273
268
  "type": "boolean"
274
269
  },
275
- "change": {
276
- "description": "Natural language description of the change",
277
- "name": "change",
278
- "hasDynamicHelp": false,
279
- "multiple": false,
280
- "type": "option"
270
+ "status": {
271
+ "description": "Show domain health status",
272
+ "name": "status",
273
+ "allowNo": false,
274
+ "type": "boolean"
275
+ },
276
+ "verify": {
277
+ "description": "Verify DNS records",
278
+ "name": "verify",
279
+ "allowNo": false,
280
+ "type": "boolean"
281
281
  }
282
282
  },
283
283
  "hasDynamicHelp": false,
284
284
  "hiddenAliases": [],
285
- "id": "edit",
285
+ "id": "domain",
286
286
  "pluginAlias": "@mailmodo/cli",
287
287
  "pluginName": "@mailmodo/cli",
288
288
  "pluginType": "core",
@@ -292,7 +292,7 @@
292
292
  "relativePath": [
293
293
  "dist",
294
294
  "commands",
295
- "edit",
295
+ "domain",
296
296
  "index.js"
297
297
  ]
298
298
  },
@@ -342,6 +342,45 @@
342
342
  "index.js"
343
343
  ]
344
344
  },
345
+ "login": {
346
+ "aliases": [],
347
+ "args": {},
348
+ "description": "Authenticate with Mailmodo using your API key",
349
+ "examples": [
350
+ "<%= config.bin %> login",
351
+ "MAILMODO_API_KEY=mm_live_xxx <%= config.bin %> login"
352
+ ],
353
+ "flags": {
354
+ "json": {
355
+ "description": "Output as JSON",
356
+ "name": "json",
357
+ "allowNo": false,
358
+ "type": "boolean"
359
+ },
360
+ "yes": {
361
+ "char": "y",
362
+ "description": "Skip confirmation prompts",
363
+ "name": "yes",
364
+ "allowNo": false,
365
+ "type": "boolean"
366
+ }
367
+ },
368
+ "hasDynamicHelp": false,
369
+ "hiddenAliases": [],
370
+ "id": "login",
371
+ "pluginAlias": "@mailmodo/cli",
372
+ "pluginName": "@mailmodo/cli",
373
+ "pluginType": "core",
374
+ "strict": true,
375
+ "enableJsonFlag": false,
376
+ "isESM": true,
377
+ "relativePath": [
378
+ "dist",
379
+ "commands",
380
+ "login",
381
+ "index.js"
382
+ ]
383
+ },
345
384
  "logs": {
346
385
  "aliases": [],
347
386
  "args": {},
@@ -396,13 +435,12 @@
396
435
  "index.js"
397
436
  ]
398
437
  },
399
- "login": {
438
+ "logout": {
400
439
  "aliases": [],
401
440
  "args": {},
402
- "description": "Authenticate with Mailmodo using your API key",
441
+ "description": "Sign out by removing saved credentials from this machine",
403
442
  "examples": [
404
- "<%= config.bin %> login",
405
- "MAILMODO_API_KEY=mm_live_xxx <%= config.bin %> login"
443
+ "<%= config.bin %> logout"
406
444
  ],
407
445
  "flags": {
408
446
  "json": {
@@ -421,7 +459,7 @@
421
459
  },
422
460
  "hasDynamicHelp": false,
423
461
  "hiddenAliases": [],
424
- "id": "login",
462
+ "id": "logout",
425
463
  "pluginAlias": "@mailmodo/cli",
426
464
  "pluginName": "@mailmodo/cli",
427
465
  "pluginType": "core",
@@ -431,18 +469,23 @@
431
469
  "relativePath": [
432
470
  "dist",
433
471
  "commands",
434
- "login",
472
+ "logout",
435
473
  "index.js"
436
474
  ]
437
475
  },
438
- "settings": {
476
+ "preview": {
439
477
  "aliases": [],
440
- "args": {},
441
- "description": "View and update project settings",
478
+ "args": {
479
+ "id": {
480
+ "description": "Email ID to preview",
481
+ "name": "id"
482
+ }
483
+ },
484
+ "description": "Preview an email in browser, as text, or send a test",
442
485
  "examples": [
443
- "<%= config.bin %> settings",
444
- "<%= config.bin %> settings --set brand_color=#0F3460",
445
- "<%= config.bin %> settings --json"
486
+ "<%= config.bin %> preview welcome",
487
+ "<%= config.bin %> preview welcome --text",
488
+ "<%= config.bin %> preview welcome --send me@example.com"
446
489
  ],
447
490
  "flags": {
448
491
  "json": {
@@ -458,17 +501,23 @@
458
501
  "allowNo": false,
459
502
  "type": "boolean"
460
503
  },
461
- "set": {
462
- "description": "Set a setting (format: key=value)",
463
- "name": "set",
504
+ "send": {
505
+ "description": "Send test email to this address",
506
+ "name": "send",
464
507
  "hasDynamicHelp": false,
465
508
  "multiple": false,
466
509
  "type": "option"
510
+ },
511
+ "text": {
512
+ "description": "Output plain text version (for AI agents)",
513
+ "name": "text",
514
+ "allowNo": false,
515
+ "type": "boolean"
467
516
  }
468
517
  },
469
518
  "hasDynamicHelp": false,
470
519
  "hiddenAliases": [],
471
- "id": "settings",
520
+ "id": "preview",
472
521
  "pluginAlias": "@mailmodo/cli",
473
522
  "pluginName": "@mailmodo/cli",
474
523
  "pluginType": "core",
@@ -478,23 +527,18 @@
478
527
  "relativePath": [
479
528
  "dist",
480
529
  "commands",
481
- "settings",
530
+ "preview",
482
531
  "index.js"
483
532
  ]
484
533
  },
485
- "preview": {
534
+ "settings": {
486
535
  "aliases": [],
487
- "args": {
488
- "id": {
489
- "description": "Email ID to preview",
490
- "name": "id"
491
- }
492
- },
493
- "description": "Preview an email in browser, as text, or send a test",
536
+ "args": {},
537
+ "description": "View and update project settings",
494
538
  "examples": [
495
- "<%= config.bin %> preview welcome",
496
- "<%= config.bin %> preview welcome --text",
497
- "<%= config.bin %> preview welcome --send me@example.com"
539
+ "<%= config.bin %> settings",
540
+ "<%= config.bin %> settings --set brand_color=#0F3460",
541
+ "<%= config.bin %> settings --json"
498
542
  ],
499
543
  "flags": {
500
544
  "json": {
@@ -510,23 +554,17 @@
510
554
  "allowNo": false,
511
555
  "type": "boolean"
512
556
  },
513
- "send": {
514
- "description": "Send test email to this address",
515
- "name": "send",
557
+ "set": {
558
+ "description": "Set a setting (format: key=value)",
559
+ "name": "set",
516
560
  "hasDynamicHelp": false,
517
561
  "multiple": false,
518
562
  "type": "option"
519
- },
520
- "text": {
521
- "description": "Output plain text version (for AI agents)",
522
- "name": "text",
523
- "allowNo": false,
524
- "type": "boolean"
525
563
  }
526
564
  },
527
565
  "hasDynamicHelp": false,
528
566
  "hiddenAliases": [],
529
- "id": "preview",
567
+ "id": "settings",
530
568
  "pluginAlias": "@mailmodo/cli",
531
569
  "pluginName": "@mailmodo/cli",
532
570
  "pluginType": "core",
@@ -536,7 +574,7 @@
536
574
  "relativePath": [
537
575
  "dist",
538
576
  "commands",
539
- "preview",
577
+ "settings",
540
578
  "index.js"
541
579
  ]
542
580
  },
@@ -580,5 +618,5 @@
580
618
  ]
581
619
  }
582
620
  },
583
- "version": "0.0.8-beta.pr10.14"
621
+ "version": "0.0.9-beta.pr11.15"
584
622
  }
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.8-beta.pr10.14",
4
+ "version": "0.0.9-beta.pr11.15",
5
5
  "author": "provishalk",
6
6
  "bin": {
7
7
  "mailmodo": "bin/run.js"
@@ -14,7 +14,8 @@
14
14
  "@oclif/plugin-plugins": "^5",
15
15
  "chalk": "^5.6.2",
16
16
  "js-yaml": "^4.1.1",
17
- "open": "^11.0.0"
17
+ "open": "^11.0.0",
18
+ "ora": "^9.3.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@eslint/compat": "^1",