@mailmodo/cli 0.0.35-beta.pr37.60 → 0.0.36-beta.pr38.61

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.
@@ -19,6 +19,7 @@ export default class Billing extends BaseCommand {
19
19
  private formatCurrency;
20
20
  private formatPaymentMethod;
21
21
  private formatUsageBlock;
22
+ private persistMonthlyCap;
22
23
  private pluralize;
23
24
  private purchaseBlocks;
24
25
  private setCap;
@@ -4,6 +4,7 @@ import open from 'open';
4
4
  import { BaseCommand } from '../../lib/base-command.js';
5
5
  import { API_ENDPOINTS } from '../../lib/constants.js';
6
6
  import { INFO } from '../../lib/messages.js';
7
+ import { loadYaml, saveYaml } from '../../lib/yaml-config.js';
7
8
  export default class Billing extends BaseCommand {
8
9
  static description = 'View billing status, purchase blocks, set cap, or add a payment method';
9
10
  static examples = [
@@ -89,18 +90,23 @@ export default class Billing extends BaseCommand {
89
90
  this.log(` Tier: ${data.tier}`);
90
91
  this.log(` Payment: ${this.formatPaymentMethod(data)}`);
91
92
  this.log(` Auto-charge: ${this.formatAutoCharge(data)}`);
92
- this.log(` Monthly cap: ${this.formatCap(data.cap)}`);
93
+ if (data.tier !== 'free') {
94
+ this.log(` Monthly cap: ${this.formatCap(data.cap)}`);
95
+ }
93
96
  this.log(` Total spent: ${this.formatCurrency(data.totalSpent, data.spentCurrency)}`);
94
97
  if (data.activeBlocks.length === 0) {
95
98
  this.log(' Active blocks: none');
96
- this.log('');
97
- return;
98
99
  }
99
- this.log(' Active blocks:');
100
- for (const block of data.activeBlocks) {
101
- this.log(` - ${this.formatUsageBlock(block)}`);
100
+ else {
101
+ this.log(' Active blocks:');
102
+ for (const block of data.activeBlocks) {
103
+ this.log(` - ${this.formatUsageBlock(block)}`);
104
+ }
102
105
  }
103
106
  this.log('');
107
+ if (!data.hasPaymentMethod) {
108
+ await this.startCheckout(jsonOutput);
109
+ }
104
110
  }
105
111
  formatAutoCharge(data) {
106
112
  if (!data.autoChargeEnabled) {
@@ -112,14 +118,18 @@ export default class Billing extends BaseCommand {
112
118
  return `enabled (${data.autoChargeBlockCount} ${this.pluralize('block', data.autoChargeBlockCount)})`;
113
119
  }
114
120
  formatCap(cap) {
115
- const parts = [];
116
- if (typeof cap.inBlocks === 'number') {
117
- parts.push(`${cap.inBlocks} ${this.pluralize('block', cap.inBlocks)}`);
121
+ const hasBlocks = typeof cap.inBlocks === 'number';
122
+ const hasEmails = typeof cap.inEmails === 'number';
123
+ if (hasBlocks && hasEmails) {
124
+ return `${cap.inBlocks} ${this.pluralize('block', cap.inBlocks)} (${cap.inEmails.toLocaleString()} ${this.pluralize('email', cap.inEmails)})`;
118
125
  }
119
- if (typeof cap.inEmails === 'number') {
120
- parts.push(`${cap.inEmails.toLocaleString()} emails`);
126
+ if (hasBlocks) {
127
+ return `${cap.inBlocks} ${this.pluralize('block', cap.inBlocks)}`;
121
128
  }
122
- return parts.length > 0 ? parts.join(' / ') : 'not set';
129
+ if (hasEmails) {
130
+ return `${cap.inEmails.toLocaleString()} ${this.pluralize('email', cap.inEmails)}`;
131
+ }
132
+ return 'not set';
123
133
  }
124
134
  formatCurrency(amount, currency) {
125
135
  const numericAmount = typeof amount === 'number' ? amount : Number.parseFloat(amount);
@@ -154,9 +164,18 @@ export default class Billing extends BaseCommand {
154
164
  const allowance = block.blockAllowance ?? Math.max(block.blocksCount * block.blockSize, 0);
155
165
  const used = Math.max(block.emailsSent ?? 0, 0);
156
166
  const activationSuffix = block.activatedAt
157
- ? `, activated ${new Date(block.activatedAt).toLocaleDateString('en-US')}`
167
+ ? `, activated at ${new Date(block.activatedAt).toLocaleDateString('en-US')}`
158
168
  : '';
159
- return `${block.type} block: ${used.toLocaleString()} / ${allowance.toLocaleString()} used (${block.status}${activationSuffix})`;
169
+ return `${block.type} block (${used + allowance}): ${used} ${this.pluralize('email', used)} sent, ${allowance} ${this.pluralize('email', allowance)} remaining${activationSuffix}`;
170
+ }
171
+ async persistMonthlyCap(capBlocks) {
172
+ const yamlConfig = await loadYaml();
173
+ if (!yamlConfig)
174
+ return;
175
+ if (yamlConfig.project.monthlyCap === capBlocks)
176
+ return;
177
+ yamlConfig.project.monthlyCap = capBlocks;
178
+ await saveYaml(yamlConfig);
160
179
  }
161
180
  pluralize(word, count) {
162
181
  return count === 1 ? word : `${word}s`;
@@ -181,29 +200,20 @@ export default class Billing extends BaseCommand {
181
200
  this.log('');
182
201
  }
183
202
  async setCap(cap, autoChargeBlockCount, jsonOutput) {
184
- if (cap < 1) {
185
- this.error('Cap must be at least 1 block.');
186
- }
187
- if (autoChargeBlockCount !== undefined && autoChargeBlockCount < 1) {
188
- this.error('Auto-charge block count must be at least 1 block.');
189
- }
190
- const response = await this.withApiSpinner({ json: jsonOutput, text: ' Updating spending cap...' }, () => {
191
- const payload = autoChargeBlockCount === undefined
192
- ? { cap }
193
- : { autoChargeBlockCount, cap };
194
- return this.apiClient.post(API_ENDPOINTS.BILLING_CAP, payload);
203
+ const data = await this.applyBillingCap({
204
+ autoChargeBlockCount,
205
+ cap,
206
+ json: jsonOutput,
195
207
  });
196
- if (!response.ok) {
197
- this.handleApiError(response);
198
- }
208
+ await this.persistMonthlyCap(data.capBlocks);
199
209
  if (jsonOutput) {
200
- this.log(JSON.stringify(response.data, null, 2));
210
+ this.log(JSON.stringify(data, null, 2));
201
211
  return;
202
212
  }
203
- this.log(`\n ${chalk.green('✓')} ${response.data.message}`);
204
- this.log(` Monthly cap: ${chalk.bold(String(response.data.capBlocks))} ${this.pluralize('block', response.data.capBlocks)} (${response.data.capEmails.toLocaleString()} emails)`);
205
- if (response.data.autoChargeBlockCount !== undefined) {
206
- this.log(` Auto-charge: ${response.data.autoChargeBlockCount} ${this.pluralize('block', response.data.autoChargeBlockCount)}`);
213
+ this.log(`\n ${chalk.green('✓')} ${data.message}`);
214
+ this.log(` Monthly cap: ${chalk.bold(String(data.capBlocks))} ${this.pluralize('block', data.capBlocks)} (${data.capEmails.toLocaleString()} emails)`);
215
+ if (data.autoChargeBlockCount !== undefined) {
216
+ this.log(` Auto-charge: ${data.autoChargeBlockCount} ${this.pluralize('block', data.autoChargeBlockCount)}`);
207
217
  }
208
218
  this.log('');
209
219
  }
@@ -9,6 +9,7 @@ export default class Settings extends BaseCommand {
9
9
  };
10
10
  run(): Promise<void>;
11
11
  private applySetFlag;
12
+ private applyMonthlyCapChange;
12
13
  private displaySettingsGroup;
13
14
  /**
14
15
  * Prompts the user to pick a setting key to edit and dispatches
@@ -73,8 +73,11 @@ export default class Settings extends BaseCommand {
73
73
  if (!(propKey in project) && key !== 'logo_file') {
74
74
  this.error(`Unknown setting: ${key}`);
75
75
  }
76
- project[propKey] =
77
- propKey === 'monthlyCap' ? Number(value) : value;
76
+ if (propKey === 'monthlyCap') {
77
+ await this.applyMonthlyCapChange(yamlConfig, value, isJson);
78
+ return;
79
+ }
80
+ project[propKey] = value;
78
81
  await saveYaml(yamlConfig);
79
82
  if (isJson) {
80
83
  this.log(JSON.stringify({ [propKey]: value, status: 'updated' }, null, 2));
@@ -83,6 +86,21 @@ export default class Settings extends BaseCommand {
83
86
  this.log(`\n ${chalk.green('✓')} ${key} updated to ${chalk.cyan(value)}`);
84
87
  this.log(` ${INFO.DEPLOY_TO_APPLY}\n`);
85
88
  }
89
+ async applyMonthlyCapChange(yamlConfig, rawValue, isJson) {
90
+ const parsed = Number(rawValue);
91
+ if (!Number.isInteger(parsed) || parsed < 1) {
92
+ this.error('monthly_cap must be a positive integer (blocks).');
93
+ }
94
+ await this.ensureAuth();
95
+ const data = await this.applyBillingCap({ cap: parsed, json: isJson });
96
+ yamlConfig.project.monthlyCap = data.capBlocks;
97
+ await saveYaml(yamlConfig);
98
+ if (isJson) {
99
+ this.log(JSON.stringify({ monthlyCap: data.capBlocks, status: 'updated' }, null, 2));
100
+ return;
101
+ }
102
+ this.log(`\n ${chalk.green('✓')} monthly_cap updated to ${chalk.cyan(String(data.capBlocks))} (${data.capEmails.toLocaleString()} emails)\n`);
103
+ }
86
104
  displaySettingsGroup(group, keys, project, domainVerified) {
87
105
  const availableKeys = keys.filter((key) => {
88
106
  if (group === 'brand' && key === 'logo_file')
@@ -159,6 +177,13 @@ export default class Settings extends BaseCommand {
159
177
  await this.handleDomainChange(yamlConfig);
160
178
  return;
161
179
  }
180
+ if (editKey === 'monthly_cap') {
181
+ const newValue = await input({
182
+ message: 'New monthly cap (blocks):',
183
+ });
184
+ await this.applyMonthlyCapChange(yamlConfig, newValue, false);
185
+ return;
186
+ }
162
187
  if (editKey === 'email_style') {
163
188
  const style = await select({
164
189
  choices: [
@@ -176,8 +201,7 @@ export default class Settings extends BaseCommand {
176
201
  const newValue = await input({
177
202
  message: `New value for ${editKey}:`,
178
203
  });
179
- project[editPropKey] =
180
- editPropKey === 'monthlyCap' ? Number(newValue) : newValue;
204
+ project[editPropKey] = newValue;
181
205
  await saveYaml(yamlConfig);
182
206
  this.log(`\n ${chalk.green('✓')} Updated. ${INFO.DEPLOY_TO_APPLY}\n`);
183
207
  }
@@ -2,6 +2,12 @@ import { Command } from '@oclif/core';
2
2
  import { ApiClient, type ApiRequestDebugInfo } from './api-client.js';
3
3
  import { type MailmodoConfig } from './config.js';
4
4
  import { type MailmodoYaml } from './yaml-config.js';
5
+ export interface BillingCapUpdateResult {
6
+ autoChargeBlockCount?: number;
7
+ capBlocks: number;
8
+ capEmails: number;
9
+ message: string;
10
+ }
5
11
  /**
6
12
  * Abstract base command providing shared functionality for all Mailmodo CLI commands.
7
13
  * Subclasses inherit --json and --yes base flags, authentication enforcement,
@@ -68,6 +74,17 @@ export declare abstract class BaseCommand extends Command {
68
74
  fromName: string;
69
75
  replyTo: string;
70
76
  }>;
77
+ /**
78
+ * Updates the account's monthly sending cap on the server.
79
+ * Validates inputs, wraps the POST /billing/cap call in a spinner, and
80
+ * surfaces errors via handleApiError. The caller is responsible for any
81
+ * local persistence (e.g. writing `monthlyCap` to mailmodo.yaml).
82
+ */
83
+ protected applyBillingCap(options: {
84
+ autoChargeBlockCount?: number;
85
+ cap: number;
86
+ json: boolean;
87
+ }): Promise<BillingCapUpdateResult>;
71
88
  protected registerDomain(yamlConfig: MailmodoYaml, inputs: {
72
89
  address: string;
73
90
  domain: string;
@@ -145,6 +145,32 @@ export class BaseCommand extends Command {
145
145
  });
146
146
  return { address, domain, fromEmail, fromName, replyTo };
147
147
  }
148
+ /**
149
+ * Updates the account's monthly sending cap on the server.
150
+ * Validates inputs, wraps the POST /billing/cap call in a spinner, and
151
+ * surfaces errors via handleApiError. The caller is responsible for any
152
+ * local persistence (e.g. writing `monthlyCap` to mailmodo.yaml).
153
+ */
154
+ async applyBillingCap(options) {
155
+ if (options.cap < 1) {
156
+ this.error('Cap must be at least 1 block.');
157
+ }
158
+ if (options.autoChargeBlockCount !== undefined &&
159
+ options.autoChargeBlockCount < 1) {
160
+ this.error('Auto-charge block count must be at least 1 block.');
161
+ }
162
+ const payload = options.autoChargeBlockCount === undefined
163
+ ? { cap: options.cap }
164
+ : {
165
+ autoChargeBlockCount: options.autoChargeBlockCount,
166
+ cap: options.cap,
167
+ };
168
+ const response = await this.withApiSpinner({ json: options.json, text: ' Updating spending cap...' }, () => this.apiClient.post(API_ENDPOINTS.BILLING_CAP, payload));
169
+ if (!response.ok) {
170
+ this.handleApiError(response);
171
+ }
172
+ return response.data;
173
+ }
148
174
  async registerDomain(yamlConfig, inputs, json) {
149
175
  const apiPayload = {
150
176
  address: inputs.address,
@@ -280,6 +280,45 @@
280
280
  "index.js"
281
281
  ]
282
282
  },
283
+ "emails": {
284
+ "aliases": [],
285
+ "args": {},
286
+ "description": "List and view configured email sequences",
287
+ "examples": [
288
+ "<%= config.bin %> emails",
289
+ "<%= config.bin %> emails --json"
290
+ ],
291
+ "flags": {
292
+ "json": {
293
+ "description": "Output as JSON",
294
+ "name": "json",
295
+ "allowNo": false,
296
+ "type": "boolean"
297
+ },
298
+ "yes": {
299
+ "char": "y",
300
+ "description": "Skip confirmation prompts",
301
+ "name": "yes",
302
+ "allowNo": false,
303
+ "type": "boolean"
304
+ }
305
+ },
306
+ "hasDynamicHelp": false,
307
+ "hiddenAliases": [],
308
+ "id": "emails",
309
+ "pluginAlias": "@mailmodo/cli",
310
+ "pluginName": "@mailmodo/cli",
311
+ "pluginType": "core",
312
+ "strict": true,
313
+ "enableJsonFlag": false,
314
+ "isESM": true,
315
+ "relativePath": [
316
+ "dist",
317
+ "commands",
318
+ "emails",
319
+ "index.js"
320
+ ]
321
+ },
283
322
  "init": {
284
323
  "aliases": [],
285
324
  "args": {},
@@ -365,13 +404,12 @@
365
404
  "index.js"
366
405
  ]
367
406
  },
368
- "emails": {
407
+ "logout": {
369
408
  "aliases": [],
370
409
  "args": {},
371
- "description": "List and view configured email sequences",
410
+ "description": "Sign out by removing saved credentials from this machine",
372
411
  "examples": [
373
- "<%= config.bin %> emails",
374
- "<%= config.bin %> emails --json"
412
+ "<%= config.bin %> logout"
375
413
  ],
376
414
  "flags": {
377
415
  "json": {
@@ -390,7 +428,7 @@
390
428
  },
391
429
  "hasDynamicHelp": false,
392
430
  "hiddenAliases": [],
393
- "id": "emails",
431
+ "id": "logout",
394
432
  "pluginAlias": "@mailmodo/cli",
395
433
  "pluginName": "@mailmodo/cli",
396
434
  "pluginType": "core",
@@ -400,7 +438,7 @@
400
438
  "relativePath": [
401
439
  "dist",
402
440
  "commands",
403
- "emails",
441
+ "logout",
404
442
  "index.js"
405
443
  ]
406
444
  },
@@ -474,14 +512,19 @@
474
512
  "index.js"
475
513
  ]
476
514
  },
477
- "settings": {
515
+ "preview": {
478
516
  "aliases": [],
479
- "args": {},
480
- "description": "View and update project settings",
517
+ "args": {
518
+ "id": {
519
+ "description": "Email template ID to preview",
520
+ "name": "id"
521
+ }
522
+ },
523
+ "description": "Preview an email in browser, as text, or send a test",
481
524
  "examples": [
482
- "<%= config.bin %> settings",
483
- "<%= config.bin %> settings --set brand_color=#0F3460",
484
- "<%= config.bin %> settings --json"
525
+ "<%= config.bin %> preview welcome",
526
+ "<%= config.bin %> preview welcome --text",
527
+ "<%= config.bin %> preview welcome --send me@example.com"
485
528
  ],
486
529
  "flags": {
487
530
  "json": {
@@ -497,56 +540,23 @@
497
540
  "allowNo": false,
498
541
  "type": "boolean"
499
542
  },
500
- "set": {
501
- "description": "Set a setting (format: key=value)",
502
- "name": "set",
543
+ "send": {
544
+ "description": "Send test email to this address",
545
+ "name": "send",
503
546
  "hasDynamicHelp": false,
504
547
  "multiple": false,
505
548
  "type": "option"
506
- }
507
- },
508
- "hasDynamicHelp": false,
509
- "hiddenAliases": [],
510
- "id": "settings",
511
- "pluginAlias": "@mailmodo/cli",
512
- "pluginName": "@mailmodo/cli",
513
- "pluginType": "core",
514
- "strict": true,
515
- "enableJsonFlag": false,
516
- "isESM": true,
517
- "relativePath": [
518
- "dist",
519
- "commands",
520
- "settings",
521
- "index.js"
522
- ]
523
- },
524
- "status": {
525
- "aliases": [],
526
- "args": {},
527
- "description": "View email performance metrics and quota usage",
528
- "examples": [
529
- "<%= config.bin %> status",
530
- "<%= config.bin %> status --json"
531
- ],
532
- "flags": {
533
- "json": {
534
- "description": "Output as JSON",
535
- "name": "json",
536
- "allowNo": false,
537
- "type": "boolean"
538
549
  },
539
- "yes": {
540
- "char": "y",
541
- "description": "Skip confirmation prompts",
542
- "name": "yes",
550
+ "text": {
551
+ "description": "Output plain text version (for AI agents)",
552
+ "name": "text",
543
553
  "allowNo": false,
544
554
  "type": "boolean"
545
555
  }
546
556
  },
547
557
  "hasDynamicHelp": false,
548
558
  "hiddenAliases": [],
549
- "id": "status",
559
+ "id": "preview",
550
560
  "pluginAlias": "@mailmodo/cli",
551
561
  "pluginName": "@mailmodo/cli",
552
562
  "pluginType": "core",
@@ -556,23 +566,18 @@
556
566
  "relativePath": [
557
567
  "dist",
558
568
  "commands",
559
- "status",
569
+ "preview",
560
570
  "index.js"
561
571
  ]
562
572
  },
563
- "preview": {
573
+ "settings": {
564
574
  "aliases": [],
565
- "args": {
566
- "id": {
567
- "description": "Email template ID to preview",
568
- "name": "id"
569
- }
570
- },
571
- "description": "Preview an email in browser, as text, or send a test",
575
+ "args": {},
576
+ "description": "View and update project settings",
572
577
  "examples": [
573
- "<%= config.bin %> preview welcome",
574
- "<%= config.bin %> preview welcome --text",
575
- "<%= config.bin %> preview welcome --send me@example.com"
578
+ "<%= config.bin %> settings",
579
+ "<%= config.bin %> settings --set brand_color=#0F3460",
580
+ "<%= config.bin %> settings --json"
576
581
  ],
577
582
  "flags": {
578
583
  "json": {
@@ -588,23 +593,17 @@
588
593
  "allowNo": false,
589
594
  "type": "boolean"
590
595
  },
591
- "send": {
592
- "description": "Send test email to this address",
593
- "name": "send",
596
+ "set": {
597
+ "description": "Set a setting (format: key=value)",
598
+ "name": "set",
594
599
  "hasDynamicHelp": false,
595
600
  "multiple": false,
596
601
  "type": "option"
597
- },
598
- "text": {
599
- "description": "Output plain text version (for AI agents)",
600
- "name": "text",
601
- "allowNo": false,
602
- "type": "boolean"
603
602
  }
604
603
  },
605
604
  "hasDynamicHelp": false,
606
605
  "hiddenAliases": [],
607
- "id": "preview",
606
+ "id": "settings",
608
607
  "pluginAlias": "@mailmodo/cli",
609
608
  "pluginName": "@mailmodo/cli",
610
609
  "pluginType": "core",
@@ -614,16 +613,17 @@
614
613
  "relativePath": [
615
614
  "dist",
616
615
  "commands",
617
- "preview",
616
+ "settings",
618
617
  "index.js"
619
618
  ]
620
619
  },
621
- "logout": {
620
+ "status": {
622
621
  "aliases": [],
623
622
  "args": {},
624
- "description": "Sign out by removing saved credentials from this machine",
623
+ "description": "View email performance metrics and quota usage",
625
624
  "examples": [
626
- "<%= config.bin %> logout"
625
+ "<%= config.bin %> status",
626
+ "<%= config.bin %> status --json"
627
627
  ],
628
628
  "flags": {
629
629
  "json": {
@@ -642,7 +642,7 @@
642
642
  },
643
643
  "hasDynamicHelp": false,
644
644
  "hiddenAliases": [],
645
- "id": "logout",
645
+ "id": "status",
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
- "logout",
655
+ "status",
656
656
  "index.js"
657
657
  ]
658
658
  }
659
659
  },
660
- "version": "0.0.35-beta.pr37.60"
660
+ "version": "0.0.36-beta.pr38.61"
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.35-beta.pr37.60",
4
+ "version": "0.0.36-beta.pr38.61",
5
5
  "author": "provishalk",
6
6
  "bin": {
7
7
  "mailmodo": "bin/run.js"