@mailmodo/cli 0.0.9 → 0.0.10-beta.pr12.16

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.get(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
  *
@@ -1,22 +1,22 @@
1
1
  export declare const API_BASE_URL: string;
2
2
  export declare const API_ENDPOINTS: Readonly<{
3
- ANALYTICS: "/api/analytics";
4
- ANALYZE: "/api/analyze";
5
- ASSETS_LOGO: "/api/assets/logo";
6
- AUTH_VALIDATE: "/api/auth/validate";
7
- BILLING_CAP: "/api/billing/cap";
8
- BILLING_STATUS: "/api/billing/status";
9
- CONTACTS: "/api/contacts";
10
- CONTACTS_EXPORT: "/api/contacts/export";
11
- DOMAIN: "/api/domain";
12
- DOMAIN_STATUS: "/api/domain/status";
13
- DOMAIN_VERIFY: "/api/domain/verify";
14
- EDIT: "/api/edit";
15
- EVENTS: "/api/events";
16
- GENERATE: "/api/generate";
17
- LOGS: "/api/logs";
18
- PREVIEW: "/api/preview";
19
- SEQUENCES: "/api/sequences";
3
+ ANALYTICS: "/analytics";
4
+ ANALYZE: "/analyze";
5
+ ASSETS_LOGO: "/assets/logo";
6
+ AUTH_VALIDATE: "/auth/validate";
7
+ BILLING_CAP: "/billing/cap";
8
+ BILLING_STATUS: "/billing/status";
9
+ CONTACTS: "/contacts";
10
+ CONTACTS_EXPORT: "/contacts/export";
11
+ DOMAIN: "/domain";
12
+ DOMAIN_STATUS: "/domain/status";
13
+ DOMAIN_VERIFY: "/domain/verify";
14
+ EDIT: "/edit";
15
+ EVENTS: "/events";
16
+ GENERATE: "/generate";
17
+ LOGS: "/logs";
18
+ PREVIEW: "/preview";
19
+ SEQUENCES: "/sequences";
20
20
  }>;
21
21
  export declare const SIGNUP_URL = "https://mailmodo.com/cli";
22
22
  export declare const DOCS_URL = "https://mailmodo.com/docs/cli";
@@ -5,23 +5,23 @@ export const API_BASE_URL = process.env.MAILMODO_DEV_TSX
5
5
  ? DEV_API_BASE_URL
6
6
  : PRODUCTION_API_BASE_URL;
7
7
  export const API_ENDPOINTS = Object.freeze({
8
- ANALYTICS: '/api/analytics',
9
- ANALYZE: '/api/analyze',
10
- ASSETS_LOGO: '/api/assets/logo',
11
- AUTH_VALIDATE: '/api/auth/validate',
12
- BILLING_CAP: '/api/billing/cap',
13
- BILLING_STATUS: '/api/billing/status',
14
- CONTACTS: '/api/contacts',
15
- CONTACTS_EXPORT: '/api/contacts/export',
16
- DOMAIN: '/api/domain',
17
- DOMAIN_STATUS: '/api/domain/status',
18
- DOMAIN_VERIFY: '/api/domain/verify',
19
- EDIT: '/api/edit',
20
- EVENTS: '/api/events',
21
- GENERATE: '/api/generate',
22
- LOGS: '/api/logs',
23
- PREVIEW: '/api/preview',
24
- SEQUENCES: '/api/sequences',
8
+ ANALYTICS: '/analytics',
9
+ ANALYZE: '/analyze',
10
+ ASSETS_LOGO: '/assets/logo',
11
+ AUTH_VALIDATE: '/auth/validate',
12
+ BILLING_CAP: '/billing/cap',
13
+ BILLING_STATUS: '/billing/status',
14
+ CONTACTS: '/contacts',
15
+ CONTACTS_EXPORT: '/contacts/export',
16
+ DOMAIN: '/domain',
17
+ DOMAIN_STATUS: '/domain/status',
18
+ DOMAIN_VERIFY: '/domain/verify',
19
+ EDIT: '/edit',
20
+ EVENTS: '/events',
21
+ GENERATE: '/generate',
22
+ LOGS: '/logs',
23
+ PREVIEW: '/preview',
24
+ SEQUENCES: '/sequences',
25
25
  });
26
26
  export const SIGNUP_URL = 'https://mailmodo.com/cli';
27
27
  export const DOCS_URL = 'https://mailmodo.com/docs/cli';
@@ -381,6 +381,44 @@
381
381
  "index.js"
382
382
  ]
383
383
  },
384
+ "logout": {
385
+ "aliases": [],
386
+ "args": {},
387
+ "description": "Sign out by removing saved credentials from this machine",
388
+ "examples": [
389
+ "<%= config.bin %> logout"
390
+ ],
391
+ "flags": {
392
+ "json": {
393
+ "description": "Output as JSON",
394
+ "name": "json",
395
+ "allowNo": false,
396
+ "type": "boolean"
397
+ },
398
+ "yes": {
399
+ "char": "y",
400
+ "description": "Skip confirmation prompts",
401
+ "name": "yes",
402
+ "allowNo": false,
403
+ "type": "boolean"
404
+ }
405
+ },
406
+ "hasDynamicHelp": false,
407
+ "hiddenAliases": [],
408
+ "id": "logout",
409
+ "pluginAlias": "@mailmodo/cli",
410
+ "pluginName": "@mailmodo/cli",
411
+ "pluginType": "core",
412
+ "strict": true,
413
+ "enableJsonFlag": false,
414
+ "isESM": true,
415
+ "relativePath": [
416
+ "dist",
417
+ "commands",
418
+ "logout",
419
+ "index.js"
420
+ ]
421
+ },
384
422
  "logs": {
385
423
  "aliases": [],
386
424
  "args": {},
@@ -482,13 +520,19 @@
482
520
  "index.js"
483
521
  ]
484
522
  },
485
- "status": {
523
+ "preview": {
486
524
  "aliases": [],
487
- "args": {},
488
- "description": "View email performance metrics and quota usage",
525
+ "args": {
526
+ "id": {
527
+ "description": "Email ID to preview",
528
+ "name": "id"
529
+ }
530
+ },
531
+ "description": "Preview an email in browser, as text, or send a test",
489
532
  "examples": [
490
- "<%= config.bin %> status",
491
- "<%= config.bin %> status --json"
533
+ "<%= config.bin %> preview welcome",
534
+ "<%= config.bin %> preview welcome --text",
535
+ "<%= config.bin %> preview welcome --send me@example.com"
492
536
  ],
493
537
  "flags": {
494
538
  "json": {
@@ -503,11 +547,24 @@
503
547
  "name": "yes",
504
548
  "allowNo": false,
505
549
  "type": "boolean"
550
+ },
551
+ "send": {
552
+ "description": "Send test email to this address",
553
+ "name": "send",
554
+ "hasDynamicHelp": false,
555
+ "multiple": false,
556
+ "type": "option"
557
+ },
558
+ "text": {
559
+ "description": "Output plain text version (for AI agents)",
560
+ "name": "text",
561
+ "allowNo": false,
562
+ "type": "boolean"
506
563
  }
507
564
  },
508
565
  "hasDynamicHelp": false,
509
566
  "hiddenAliases": [],
510
- "id": "status",
567
+ "id": "preview",
511
568
  "pluginAlias": "@mailmodo/cli",
512
569
  "pluginName": "@mailmodo/cli",
513
570
  "pluginType": "core",
@@ -517,23 +574,17 @@
517
574
  "relativePath": [
518
575
  "dist",
519
576
  "commands",
520
- "status",
577
+ "preview",
521
578
  "index.js"
522
579
  ]
523
580
  },
524
- "preview": {
581
+ "status": {
525
582
  "aliases": [],
526
- "args": {
527
- "id": {
528
- "description": "Email ID to preview",
529
- "name": "id"
530
- }
531
- },
532
- "description": "Preview an email in browser, as text, or send a test",
583
+ "args": {},
584
+ "description": "View email performance metrics and quota usage",
533
585
  "examples": [
534
- "<%= config.bin %> preview welcome",
535
- "<%= config.bin %> preview welcome --text",
536
- "<%= config.bin %> preview welcome --send me@example.com"
586
+ "<%= config.bin %> status",
587
+ "<%= config.bin %> status --json"
537
588
  ],
538
589
  "flags": {
539
590
  "json": {
@@ -548,24 +599,11 @@
548
599
  "name": "yes",
549
600
  "allowNo": false,
550
601
  "type": "boolean"
551
- },
552
- "send": {
553
- "description": "Send test email to this address",
554
- "name": "send",
555
- "hasDynamicHelp": false,
556
- "multiple": false,
557
- "type": "option"
558
- },
559
- "text": {
560
- "description": "Output plain text version (for AI agents)",
561
- "name": "text",
562
- "allowNo": false,
563
- "type": "boolean"
564
602
  }
565
603
  },
566
604
  "hasDynamicHelp": false,
567
605
  "hiddenAliases": [],
568
- "id": "preview",
606
+ "id": "status",
569
607
  "pluginAlias": "@mailmodo/cli",
570
608
  "pluginName": "@mailmodo/cli",
571
609
  "pluginType": "core",
@@ -575,10 +613,10 @@
575
613
  "relativePath": [
576
614
  "dist",
577
615
  "commands",
578
- "preview",
616
+ "status",
579
617
  "index.js"
580
618
  ]
581
619
  }
582
620
  },
583
- "version": "0.0.9"
621
+ "version": "0.0.10-beta.pr12.16"
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.9",
4
+ "version": "0.0.10-beta.pr12.16",
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",