@mailmodo/cli 0.0.15-beta.pr18.27 → 0.0.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.
@@ -1,6 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  import { confirm } from '@inquirer/prompts';
3
3
  import chalk from 'chalk';
4
+ import { writeFile } from 'node:fs/promises';
4
5
  import { BaseCommand } from '../../lib/base-command.js';
5
6
  import { API_ENDPOINTS } from '../../lib/constants.js';
6
7
  export default class Contacts extends BaseCommand {
@@ -8,7 +9,7 @@ export default class Contacts extends BaseCommand {
8
9
  static examples = [
9
10
  '<%= config.bin %> contacts',
10
11
  '<%= config.bin %> contacts --search sarah@example.com',
11
- '<%= config.bin %> contacts --export',
12
+ "<%= config.bin %> contacts --export # GDPR CSV → contacts.csv",
12
13
  '<%= config.bin %> contacts --delete sarah@example.com',
13
14
  ];
14
15
  static flags = {
@@ -18,7 +19,7 @@ export default class Contacts extends BaseCommand {
18
19
  }),
19
20
  export: Flags.boolean({
20
21
  default: false,
21
- description: 'Export all contacts as CSV',
22
+ description: 'Export all contacts as GDPR-compliant CSV (writes contacts.csv in the current directory)',
22
23
  }),
23
24
  search: Flags.string({ description: 'Search for a contact by email' }),
24
25
  };
@@ -106,10 +107,19 @@ export default class Contacts extends BaseCommand {
106
107
  return;
107
108
  }
108
109
  this.log(`\n ${chalk.green('✓')} Contact export started.`);
109
- if (response.data?.downloadUrl) {
110
- this.log(` Download: ${chalk.cyan(response.data.downloadUrl)}`);
110
+ const { downloadUrl, status } = response.data;
111
+ if (!downloadUrl) {
112
+ this.log(`\n Export status: ${status ?? 'unknown'}. No download URL yet.\n`);
113
+ return;
111
114
  }
112
- this.log('');
115
+ const url = `https://${downloadUrl}`;
116
+ const fileResult = await this.apiClient.getFile(url);
117
+ if (!fileResult.ok) {
118
+ this.error(`Download failed: ${fileResult.status} ${fileResult.error ?? ''}\n` +
119
+ ` URL: ${fileResult.debug.fullUrl}`);
120
+ }
121
+ await writeFile('contacts.csv', Buffer.from(fileResult.body));
122
+ this.log(`\n ${chalk.green('✓')} Contact export saved to ${chalk.cyan('contacts.csv')}\n`);
113
123
  }
114
124
  /**
115
125
  * Performs a GDPR-compliant hard delete of a contact and all their
@@ -110,7 +110,8 @@ export default class Init extends BaseCommand {
110
110
  json: flags.json,
111
111
  text: ' Generating email templates...',
112
112
  }, () => this.apiClient.post(API_ENDPOINTS.GENERATE, {
113
- ...analysisPayload,
113
+ analysis: analysisPayload,
114
+ productUrl,
114
115
  }));
115
116
  if (!generateResponse.ok) {
116
117
  this.handleApiError(generateResponse);
@@ -1,3 +1,4 @@
1
+ import { type FileFetchResult } from './fetch-file.js';
1
2
  /**
2
3
  * Request context attached to API responses for troubleshooting failed calls.
3
4
  * Only the resolved URL is stored; it encodes origin, path, and query string.
@@ -38,6 +39,11 @@ export declare class ApiClient {
38
39
  private request;
39
40
  delete<T = Record<string, unknown>>(path: string): Promise<ApiResponse<T>>;
40
41
  get<T = Record<string, unknown>>(path: string, params?: Record<string, string>): Promise<ApiResponse<T>>;
42
+ /**
43
+ * GET an absolute URL and return the raw body (e.g. CSV export). Uses the same
44
+ * Bearer auth as other requests; does not parse JSON.
45
+ */
46
+ getFile(url: string): Promise<FileFetchResult>;
41
47
  patch<T = Record<string, unknown>>(path: string, body?: Record<string, unknown>): Promise<ApiResponse<T>>;
42
48
  post<T = Record<string, unknown>>(path: string, body?: Record<string, unknown> | unknown): Promise<ApiResponse<T>>;
43
49
  postFormData<T = Record<string, unknown>>(path: string, formData: FormData): Promise<ApiResponse<T>>;
@@ -1,4 +1,5 @@
1
1
  import { API_BASE_URL } from './constants.js';
2
+ import { fetchFileWithBearerAuth, } from './fetch-file.js';
2
3
  /**
3
4
  * HTTP client for the Mailmodo CLI API.
4
5
  * Wraps the native fetch API with Bearer token authentication,
@@ -115,6 +116,13 @@ export class ApiClient {
115
116
  async get(path, params) {
116
117
  return this.request('GET', path, undefined, params);
117
118
  }
119
+ /**
120
+ * GET an absolute URL and return the raw body (e.g. CSV export). Uses the same
121
+ * Bearer auth as other requests; does not parse JSON.
122
+ */
123
+ async getFile(url) {
124
+ return fetchFileWithBearerAuth(url, this.apiKey);
125
+ }
118
126
  async patch(path, body) {
119
127
  return this.request('PATCH', path, body);
120
128
  }
@@ -13,7 +13,7 @@ export declare const API_ENDPOINTS: Readonly<{
13
13
  DOMAIN_VERIFY: "/domain/verify";
14
14
  EDIT: "/edit";
15
15
  EVENTS: "/events";
16
- GENERATE: "/email/generate";
16
+ GENERATE: "/generate";
17
17
  LOGS: "/logs";
18
18
  PREVIEW: "/preview";
19
19
  SEQUENCES: "/sequences";
@@ -19,7 +19,7 @@ export const API_ENDPOINTS = Object.freeze({
19
19
  DOMAIN_VERIFY: '/domain/verify',
20
20
  EDIT: '/edit',
21
21
  EVENTS: '/events',
22
- GENERATE: '/email/generate',
22
+ GENERATE: '/generate',
23
23
  LOGS: '/logs',
24
24
  PREVIEW: '/preview',
25
25
  SEQUENCES: '/sequences',
@@ -0,0 +1,14 @@
1
+ export interface FileFetchResult {
2
+ body: ArrayBuffer;
3
+ debug: {
4
+ fullUrl: string;
5
+ };
6
+ error?: string;
7
+ ok: boolean;
8
+ status: number;
9
+ }
10
+ /**
11
+ * GET an absolute URL and return the raw body (e.g. CSV). Uses Bearer auth;
12
+ * does not parse JSON.
13
+ */
14
+ export declare function fetchFileWithBearerAuth(url: string, apiKey: string): Promise<FileFetchResult>;
@@ -0,0 +1,51 @@
1
+ const USER_AGENT = '@mailmodo/cli';
2
+ /**
3
+ * GET an absolute URL and return the raw body (e.g. CSV). Uses Bearer auth;
4
+ * does not parse JSON.
5
+ */
6
+ export async function fetchFileWithBearerAuth(url, apiKey) {
7
+ let href;
8
+ try {
9
+ href = new URL(url.trim()).toString();
10
+ }
11
+ catch {
12
+ return {
13
+ body: new ArrayBuffer(0),
14
+ debug: { fullUrl: url.trim() },
15
+ error: 'Invalid URL',
16
+ ok: false,
17
+ status: 0,
18
+ };
19
+ }
20
+ const debug = { fullUrl: href };
21
+ try {
22
+ const response = await fetch(href, {
23
+ headers: {
24
+ Authorization: `Bearer ${apiKey}`,
25
+ 'User-Agent': USER_AGENT,
26
+ },
27
+ method: 'GET',
28
+ });
29
+ const body = await response.arrayBuffer();
30
+ if (!response.ok) {
31
+ return {
32
+ body: new ArrayBuffer(0),
33
+ debug,
34
+ error: response.statusText,
35
+ ok: false,
36
+ status: response.status,
37
+ };
38
+ }
39
+ return { body, debug, ok: true, status: response.status };
40
+ }
41
+ catch (error) {
42
+ const err = error;
43
+ return {
44
+ body: new ArrayBuffer(0),
45
+ debug,
46
+ error: err?.message || 'Request failed.',
47
+ ok: false,
48
+ status: 0,
49
+ };
50
+ }
51
+ }
@@ -60,7 +60,7 @@
60
60
  "examples": [
61
61
  "<%= config.bin %> contacts",
62
62
  "<%= config.bin %> contacts --search sarah@example.com",
63
- "<%= config.bin %> contacts --export",
63
+ "<%= config.bin %> contacts --export # GDPR CSV → contacts.csv",
64
64
  "<%= config.bin %> contacts --delete sarah@example.com"
65
65
  ],
66
66
  "flags": {
@@ -85,7 +85,7 @@
85
85
  "type": "option"
86
86
  },
87
87
  "export": {
88
- "description": "Export all contacts as CSV",
88
+ "description": "Export all contacts as GDPR-compliant CSV (writes contacts.csv in the current directory)",
89
89
  "name": "export",
90
90
  "allowNo": false,
91
91
  "type": "boolean"
@@ -419,15 +419,19 @@
419
419
  "index.js"
420
420
  ]
421
421
  },
422
- "logs": {
422
+ "preview": {
423
423
  "aliases": [],
424
- "args": {},
425
- "description": "View email send logs and delivery events",
424
+ "args": {
425
+ "id": {
426
+ "description": "Email ID to preview",
427
+ "name": "id"
428
+ }
429
+ },
430
+ "description": "Preview an email in browser, as text, or send a test",
426
431
  "examples": [
427
- "<%= config.bin %> logs",
428
- "<%= config.bin %> logs --email sarah@example.com",
429
- "<%= config.bin %> logs --failed",
430
- "<%= config.bin %> logs --json"
432
+ "<%= config.bin %> preview welcome",
433
+ "<%= config.bin %> preview welcome --text",
434
+ "<%= config.bin %> preview welcome --send me@example.com"
431
435
  ],
432
436
  "flags": {
433
437
  "json": {
@@ -443,23 +447,23 @@
443
447
  "allowNo": false,
444
448
  "type": "boolean"
445
449
  },
446
- "email": {
447
- "description": "Filter logs by contact email",
448
- "name": "email",
450
+ "send": {
451
+ "description": "Send test email to this address",
452
+ "name": "send",
449
453
  "hasDynamicHelp": false,
450
454
  "multiple": false,
451
455
  "type": "option"
452
456
  },
453
- "failed": {
454
- "description": "Show only failed/bounced events",
455
- "name": "failed",
457
+ "text": {
458
+ "description": "Output plain text version (for AI agents)",
459
+ "name": "text",
456
460
  "allowNo": false,
457
461
  "type": "boolean"
458
462
  }
459
463
  },
460
464
  "hasDynamicHelp": false,
461
465
  "hiddenAliases": [],
462
- "id": "logs",
466
+ "id": "preview",
463
467
  "pluginAlias": "@mailmodo/cli",
464
468
  "pluginName": "@mailmodo/cli",
465
469
  "pluginType": "core",
@@ -469,23 +473,19 @@
469
473
  "relativePath": [
470
474
  "dist",
471
475
  "commands",
472
- "logs",
476
+ "preview",
473
477
  "index.js"
474
478
  ]
475
479
  },
476
- "preview": {
480
+ "logs": {
477
481
  "aliases": [],
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",
482
+ "args": {},
483
+ "description": "View email send logs and delivery events",
485
484
  "examples": [
486
- "<%= config.bin %> preview welcome",
487
- "<%= config.bin %> preview welcome --text",
488
- "<%= config.bin %> preview welcome --send me@example.com"
485
+ "<%= config.bin %> logs",
486
+ "<%= config.bin %> logs --email sarah@example.com",
487
+ "<%= config.bin %> logs --failed",
488
+ "<%= config.bin %> logs --json"
489
489
  ],
490
490
  "flags": {
491
491
  "json": {
@@ -501,23 +501,23 @@
501
501
  "allowNo": false,
502
502
  "type": "boolean"
503
503
  },
504
- "send": {
505
- "description": "Send test email to this address",
506
- "name": "send",
504
+ "email": {
505
+ "description": "Filter logs by contact email",
506
+ "name": "email",
507
507
  "hasDynamicHelp": false,
508
508
  "multiple": false,
509
509
  "type": "option"
510
510
  },
511
- "text": {
512
- "description": "Output plain text version (for AI agents)",
513
- "name": "text",
511
+ "failed": {
512
+ "description": "Show only failed/bounced events",
513
+ "name": "failed",
514
514
  "allowNo": false,
515
515
  "type": "boolean"
516
516
  }
517
517
  },
518
518
  "hasDynamicHelp": false,
519
519
  "hiddenAliases": [],
520
- "id": "preview",
520
+ "id": "logs",
521
521
  "pluginAlias": "@mailmodo/cli",
522
522
  "pluginName": "@mailmodo/cli",
523
523
  "pluginType": "core",
@@ -527,7 +527,7 @@
527
527
  "relativePath": [
528
528
  "dist",
529
529
  "commands",
530
- "preview",
530
+ "logs",
531
531
  "index.js"
532
532
  ]
533
533
  },
@@ -618,5 +618,5 @@
618
618
  ]
619
619
  }
620
620
  },
621
- "version": "0.0.15-beta.pr18.27"
621
+ "version": "0.0.16"
622
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.15-beta.pr18.27",
4
+ "version": "0.0.16",
5
5
  "author": "provishalk",
6
6
  "bin": {
7
7
  "mailmodo": "bin/run.js"