@cakemail-org/cakemail-cli 1.7.0 → 2.0.0
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.
- package/.claude/settings.local.json +12 -0
- package/.env.example +40 -0
- package/.env.test.example +45 -0
- package/CHANGELOG.md +1031 -0
- package/README.md +41 -37
- package/audit-formats.js +128 -0
- package/cakemail.rb +20 -0
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/commands/account.js +1 -1
- package/dist/commands/account.js.map +1 -1
- package/dist/commands/attributes.js +1 -1
- package/dist/commands/attributes.js.map +1 -1
- package/dist/commands/campaigns.js +1 -1
- package/dist/commands/campaigns.js.map +1 -1
- package/dist/commands/contacts.js +1 -1
- package/dist/commands/contacts.js.map +1 -1
- package/dist/commands/emails.js +1 -1
- package/dist/commands/emails.js.map +1 -1
- package/dist/commands/interests.js +1 -1
- package/dist/commands/interests.js.map +1 -1
- package/dist/commands/lists.js +1 -1
- package/dist/commands/lists.js.map +1 -1
- package/dist/commands/logs.js +1 -1
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/reports.js +1 -1
- package/dist/commands/reports.js.map +1 -1
- package/dist/commands/segments.js +1 -1
- package/dist/commands/segments.js.map +1 -1
- package/dist/commands/senders.js +1 -1
- package/dist/commands/senders.js.map +1 -1
- package/dist/commands/suppressed.js +1 -1
- package/dist/commands/suppressed.js.map +1 -1
- package/dist/commands/tags.js +1 -1
- package/dist/commands/tags.js.map +1 -1
- package/dist/commands/templates.js +1 -1
- package/dist/commands/templates.js.map +1 -1
- package/dist/commands/transactional-templates.js +1 -1
- package/dist/commands/transactional-templates.js.map +1 -1
- package/dist/commands/webhooks.js +1 -1
- package/dist/commands/webhooks.js.map +1 -1
- package/dist/utils/config.js +2 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/errors.js +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/progress.d.ts.map +1 -1
- package/dist/utils/progress.js +32 -4
- package/dist/utils/progress.js.map +1 -1
- package/dist/utils/spinner.d.ts +17 -0
- package/dist/utils/spinner.d.ts.map +1 -0
- package/dist/utils/spinner.js +43 -0
- package/dist/utils/spinner.js.map +1 -0
- package/docs/DOCUMENTATION-STANDARD.md +1068 -0
- package/docs/README.md +161 -0
- package/docs/developer/ARCHITECTURE.md +516 -0
- package/docs/developer/AUTH.md +204 -0
- package/docs/developer/CONTRIBUTING.md +227 -0
- package/docs/developer/DOCUMENTATION_SUMMARY.md +346 -0
- package/docs/developer/PROJECT_INDEX.md +365 -0
- package/docs/planning/API_COVERAGE.md +1045 -0
- package/docs/planning/BACKLOG.md +1159 -0
- package/docs/planning/PROFILE_SYSTEM_TASKS.md +287 -0
- package/docs/planning/UX_IMPLEMENTATION_PLAN.md +691 -0
- package/docs/planning/archive/RELEASE_CHECKLIST_v1.3.0.md +332 -0
- package/docs/planning/archive/RELEASE_v1.3.0.md +428 -0
- package/docs/planning/archive/cakemail-cli-ux-improvements.md +438 -0
- package/docs/planning/cakemail-profile-system-plan.md +1121 -0
- package/docs/testing/AI_USER_SIMULATION_DESIGN.md +1342 -0
- package/docs/testing/KENOGAMI_BIDIRECTIONAL_FLOW.md +1517 -0
- package/docs/testing/KENOGAMI_TRUTH_RECONCILIATION_SYSTEM.md +1369 -0
- package/docs/user-manual/.obsidian/app.json +1 -0
- package/docs/user-manual/.obsidian/appearance.json +1 -0
- package/docs/user-manual/.obsidian/core-plugins.json +33 -0
- package/docs/user-manual/.obsidian/workspace.json +167 -0
- package/docs/user-manual/01-getting-started/01-installation.md +214 -0
- package/docs/user-manual/01-getting-started/02-quick-start.md +432 -0
- package/docs/user-manual/01-getting-started/03-authentication.md +448 -0
- package/docs/user-manual/01-getting-started/04-configuration.md +430 -0
- package/docs/user-manual/01-getting-started/05-output-formats.md +447 -0
- package/docs/user-manual/02-core-concepts/01-accounts.md +514 -0
- package/docs/user-manual/02-core-concepts/02-profile-system.md +771 -0
- package/docs/user-manual/02-core-concepts/03-smart-defaults.md +485 -0
- package/docs/user-manual/02-core-concepts/04-authentication-methods.md +435 -0
- package/docs/user-manual/02-core-concepts/05-pagination-filtering.md +600 -0
- package/docs/user-manual/02-core-concepts/06-error-handling.md +718 -0
- package/docs/user-manual/02-core-concepts/07-api-coverage.md +483 -0
- package/docs/user-manual/03-email-operations/01-senders.md +490 -0
- package/docs/user-manual/03-email-operations/02-templates.md +444 -0
- package/docs/user-manual/03-email-operations/03-transactional-emails.md +706 -0
- package/docs/user-manual/03-email-operations/04-email-tracking.md +407 -0
- package/docs/user-manual/04-campaign-management/01-campaigns-basics.md +394 -0
- package/docs/user-manual/04-campaign-management/02-campaign-scheduling.md +630 -0
- package/docs/user-manual/04-campaign-management/03-campaign-testing.md +997 -0
- package/docs/user-manual/04-campaign-management/04-campaign-lifecycle.md +709 -0
- package/docs/user-manual/04-campaign-management/05-campaign-links.md +934 -0
- package/docs/user-manual/05-contact-management/01-lists.md +836 -0
- package/docs/user-manual/05-contact-management/02-contacts.md +1035 -0
- package/docs/user-manual/05-contact-management/03-custom-attributes.md +788 -0
- package/docs/user-manual/05-contact-management/04-segments.md +1028 -0
- package/docs/user-manual/05-contact-management/05-contact-import-export.md +1031 -0
- package/docs/user-manual/06-analytics-reporting/01-campaign-analytics.md +867 -0
- package/docs/user-manual/06-analytics-reporting/02-account-reports.md +227 -0
- package/docs/user-manual/07-integrations/01-webhooks-integration.md +259 -0
- package/docs/user-manual/07-integrations/02-automation.md +326 -0
- package/docs/user-manual/08-advanced-usage/01-scripting-patterns.md +672 -0
- package/docs/user-manual/08-advanced-usage/02-bulk-operations.md +932 -0
- package/docs/user-manual/08-advanced-usage/03-ci-cd-integration.md +892 -0
- package/docs/user-manual/08-advanced-usage/04-performance-optimization.md +766 -0
- package/docs/user-manual/09-command-reference/01-config.md +776 -0
- package/docs/user-manual/09-command-reference/02-account.md +652 -0
- package/docs/user-manual/09-command-reference/03-lists.md +958 -0
- package/docs/user-manual/09-command-reference/04-contacts.md +1408 -0
- package/docs/user-manual/09-command-reference/05-attributes.md +617 -0
- package/docs/user-manual/09-command-reference/06-segments.md +894 -0
- package/docs/user-manual/09-command-reference/07-senders.md +803 -0
- package/docs/user-manual/09-command-reference/08-templates.md +818 -0
- package/docs/user-manual/09-command-reference/09-campaigns.md +1250 -0
- package/docs/user-manual/09-command-reference/10-emails.md +807 -0
- package/docs/user-manual/09-command-reference/11-reports.md +1135 -0
- package/docs/user-manual/09-command-reference/12-webhooks.md +773 -0
- package/docs/user-manual/09-command-reference/13-suppressed.md +797 -0
- package/docs/user-manual/09-command-reference/14-interests.md +630 -0
- package/docs/user-manual/09-command-reference/15-tags.md +584 -0
- package/docs/user-manual/09-command-reference/16-logs.md +656 -0
- package/docs/user-manual/09-command-reference/17-transactional-templates.md +850 -0
- package/docs/user-manual/10-troubleshooting/01-common-errors.md +457 -0
- package/docs/user-manual/10-troubleshooting/02-authentication-issues.md +558 -0
- package/docs/user-manual/10-troubleshooting/03-connection-problems.md +634 -0
- package/docs/user-manual/10-troubleshooting/04-debugging.md +725 -0
- package/docs/user-manual/11-appendix/04-faq.md +484 -0
- package/docs/user-manual/11-appendix/05-glossary.md +250 -0
- package/docs/user-manual/README.md +0 -0
- package/package.json +13 -61
- package/src/cli.ts +125 -0
- package/src/client.ts +16 -0
- package/src/commands/account.ts +267 -0
- package/src/commands/accounts.ts +78 -0
- package/src/commands/actions.ts +249 -0
- package/src/commands/attributes.ts +139 -0
- package/src/commands/campaign-blueprints.ts +106 -0
- package/src/commands/campaigns.ts +469 -0
- package/src/commands/config.ts +77 -0
- package/src/commands/contacts.ts +612 -0
- package/src/commands/custom-attributes.ts +127 -0
- package/src/commands/dkims.ts +117 -0
- package/src/commands/domains.ts +82 -0
- package/src/commands/email-apis.ts +569 -0
- package/src/commands/emails.ts +197 -0
- package/src/commands/forms.ts +283 -0
- package/src/commands/interests.ts +155 -0
- package/src/commands/links.ts +38 -0
- package/src/commands/lists.ts +406 -0
- package/src/commands/logos.ts +71 -0
- package/src/commands/logs.ts +386 -0
- package/src/commands/reports.ts +306 -0
- package/src/commands/segments.ts +158 -0
- package/src/commands/senders.ts +204 -0
- package/src/commands/sub-accounts.ts +271 -0
- package/src/commands/suppressed-emails.ts +234 -0
- package/src/commands/suppressed.ts +198 -0
- package/src/commands/system-emails.ts +85 -0
- package/src/commands/tags.ts +146 -0
- package/src/commands/tasks.ts +116 -0
- package/src/commands/templates.ts +189 -0
- package/src/commands/tokens.ts +83 -0
- package/src/commands/transactional-emails.ts +374 -0
- package/src/commands/transactional-templates.ts +385 -0
- package/src/commands/users.ts +506 -0
- package/src/commands/webhooks.ts +172 -0
- package/src/commands/workflow-blueprints.ts +123 -0
- package/src/commands/workflows.ts +265 -0
- package/src/types/profile.ts +93 -0
- package/src/utils/auth.ts +272 -0
- package/src/utils/config-file.ts +96 -0
- package/src/utils/config.ts +134 -0
- package/src/utils/confirm.ts +32 -0
- package/src/utils/defaults.ts +99 -0
- package/src/utils/errors.ts +116 -0
- package/src/utils/interactive.ts +91 -0
- package/src/utils/list-defaults.ts +74 -0
- package/src/utils/output.ts +190 -0
- package/src/utils/progress.ts +320 -0
- package/src/utils/spinner.ts +22 -0
- package/tests/IMPLEMENTATION_STATUS.md +258 -0
- package/tests/PTY_SETUP.md +118 -0
- package/tests/PTY_TESTING_GUIDE.md +507 -0
- package/tests/README.md +244 -0
- package/tests/fixtures/api-responses/campaigns.json +34 -0
- package/tests/fixtures/test-config.json +13 -0
- package/tests/helpers/cli-runner.ts +128 -0
- package/tests/helpers/mock-server.ts +301 -0
- package/tests/helpers/pty-runner.ts +181 -0
- package/tests/integration/campaigns-real-api.test.ts +196 -0
- package/tests/integration/setup-integration.ts +50 -0
- package/tests/pty/campaigns.test.ts +241 -0
- package/tests/setup.ts +34 -0
- package/tsconfig.json +15 -0
- package/vitest.config.ts +28 -0
package/docs/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Cakemail CLI - Documentation Hub
|
|
2
|
+
|
|
3
|
+
**Welcome to the Cakemail CLI documentation!**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📚 Documentation Types
|
|
8
|
+
|
|
9
|
+
### For Users
|
|
10
|
+
- **[User Manual](./user-manual/)** - Complete guide for using the CLI
|
|
11
|
+
- **[Quick Start](./user-manual/01-getting-started/quick-start.md)** - Get started in 5 minutes
|
|
12
|
+
|
|
13
|
+
### For Contributors
|
|
14
|
+
- **[Developer Docs](./developer/)** - Internal documentation for contributors
|
|
15
|
+
- **[Project Index](./developer/PROJECT_INDEX.md)** - Start here for contributing
|
|
16
|
+
|
|
17
|
+
### For Project Management
|
|
18
|
+
- **[Planning Docs](./planning/)** - Roadmaps and feature plans
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 🚀 Quick Links
|
|
23
|
+
|
|
24
|
+
### I want to...
|
|
25
|
+
- **Use the CLI** → [User Manual](./user-manual/)
|
|
26
|
+
- **Contribute code** → [Developer Docs](./developer/)
|
|
27
|
+
- **See what's planned** → [Backlog](./planning/BACKLOG.md)
|
|
28
|
+
- **See what's shipped** → [Changelog](../CHANGELOG.md)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📖 Documentation Structure
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
docs/
|
|
36
|
+
├── README.md (this file) # Documentation hub
|
|
37
|
+
│
|
|
38
|
+
├── user-manual/ # End-user documentation
|
|
39
|
+
│ ├── 01-getting-started/
|
|
40
|
+
│ ├── 02-core-concepts/
|
|
41
|
+
│ ├── 03-campaigns/
|
|
42
|
+
│ ├── ...
|
|
43
|
+
│ └── README.md
|
|
44
|
+
│
|
|
45
|
+
├── developer/ # Contributor documentation
|
|
46
|
+
│ ├── PROJECT_INDEX.md # Start here!
|
|
47
|
+
│ ├── ARCHITECTURE.md # Code structure
|
|
48
|
+
│ ├── CONTRIBUTING.md # How to contribute
|
|
49
|
+
│ ├── AUTH.md # Auth reference
|
|
50
|
+
│ └── DOCUMENTATION_SUMMARY.md # How docs work
|
|
51
|
+
│
|
|
52
|
+
└── planning/ # Project planning
|
|
53
|
+
├── BACKLOG.md # What's next (FUTURE)
|
|
54
|
+
├── API_COVERAGE.md # API coverage tracking
|
|
55
|
+
├── UX_IMPLEMENTATION_PLAN.md # UX roadmap
|
|
56
|
+
├── PROFILE_SYSTEM_PLAN.md # Profile system design
|
|
57
|
+
└── PROFILE_SYSTEM_TASKS.md # Profile tasks
|
|
58
|
+
|
|
59
|
+
Root level:
|
|
60
|
+
├── README.md # Project README
|
|
61
|
+
├── CHANGELOG.md # Version history (PAST)
|
|
62
|
+
└── package.json # Package info
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🗺️ Documentation Map
|
|
68
|
+
|
|
69
|
+
### User Journey
|
|
70
|
+
```
|
|
71
|
+
New User → README.md → User Manual → Quick Start → Commands
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Contributor Journey
|
|
75
|
+
```
|
|
76
|
+
New Contributor → PROJECT_INDEX.md → ARCHITECTURE.md → BACKLOG.md → Code
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Project Manager Journey
|
|
80
|
+
```
|
|
81
|
+
PM → BACKLOG.md → Planning Docs → CHANGELOG.md
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 📝 Documentation Standards
|
|
87
|
+
|
|
88
|
+
### User Manual
|
|
89
|
+
- **Audience:** CLI users (technical and non-technical)
|
|
90
|
+
- **Tone:** Helpful, example-driven, clear
|
|
91
|
+
- **Format:** Step-by-step guides with examples
|
|
92
|
+
|
|
93
|
+
### Developer Docs
|
|
94
|
+
- **Audience:** Contributors and maintainers
|
|
95
|
+
- **Tone:** Technical, precise, comprehensive
|
|
96
|
+
- **Format:** Reference docs with code examples
|
|
97
|
+
|
|
98
|
+
### Planning Docs
|
|
99
|
+
- **Audience:** Project team and stakeholders
|
|
100
|
+
- **Tone:** Strategic, decision-oriented
|
|
101
|
+
- **Format:** Roadmaps, priorities, timelines
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🔄 Documentation Lifecycle
|
|
106
|
+
|
|
107
|
+
### When to Update
|
|
108
|
+
|
|
109
|
+
**After implementing a feature:**
|
|
110
|
+
1. Update [BACKLOG.md](./planning/BACKLOG.md) → Mark completed
|
|
111
|
+
2. Add to [CHANGELOG.md](../CHANGELOG.md) → [Unreleased] section
|
|
112
|
+
3. Update [User Manual](./user-manual/) → Add command guide
|
|
113
|
+
4. Update [README.md](../README.md) → If major feature
|
|
114
|
+
|
|
115
|
+
**Before a release:**
|
|
116
|
+
1. Move CHANGELOG [Unreleased] → [v1.X.0]
|
|
117
|
+
2. Archive BACKLOG completed items
|
|
118
|
+
3. Update version numbers everywhere
|
|
119
|
+
4. Review all docs for accuracy
|
|
120
|
+
|
|
121
|
+
**Quarterly:**
|
|
122
|
+
1. Review all documentation
|
|
123
|
+
2. Archive outdated plans
|
|
124
|
+
3. Update roadmaps
|
|
125
|
+
4. Clean up duplicates
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 🤝 Contributing to Docs
|
|
130
|
+
|
|
131
|
+
### User Manual
|
|
132
|
+
- Keep examples realistic
|
|
133
|
+
- Test all commands before documenting
|
|
134
|
+
- Include troubleshooting for common issues
|
|
135
|
+
- Cross-reference related commands
|
|
136
|
+
|
|
137
|
+
### Developer Docs
|
|
138
|
+
- Keep ARCHITECTURE.md updated with code changes
|
|
139
|
+
- Document all design decisions
|
|
140
|
+
- Update PROJECT_INDEX.md when adding docs
|
|
141
|
+
- Maintain cross-references
|
|
142
|
+
|
|
143
|
+
### Planning Docs
|
|
144
|
+
- Update BACKLOG.md weekly
|
|
145
|
+
- Sync CHANGELOG.md with releases
|
|
146
|
+
- Keep effort estimates realistic
|
|
147
|
+
- Document decisions and trade-offs
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 📞 Need Help?
|
|
152
|
+
|
|
153
|
+
- **For CLI usage:** Check [User Manual](./user-manual/)
|
|
154
|
+
- **For contributing:** Check [Developer Docs](./developer/)
|
|
155
|
+
- **For roadmap:** Check [Planning Docs](./planning/)
|
|
156
|
+
- **For bugs:** Open an issue on GitHub
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
**Last Updated:** 2025-10-11
|
|
161
|
+
**Maintained By:** François Lane
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
# Cakemail CLI Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Cakemail CLI is built on the official [@cakemail-org/cakemail-sdk](https://www.npmjs.com/package/@cakemail-org/cakemail-sdk) v2.0, providing a type-safe, developer-friendly command-line interface for the Cakemail email marketing platform. The CLI wraps the SDK to deliver intuitive commands while maintaining 100% API coverage through direct SDK access.
|
|
6
|
+
|
|
7
|
+
**Current Version:** 1.2.0
|
|
8
|
+
**SDK Version:** @cakemail-org/cakemail-sdk v2.0.0
|
|
9
|
+
**Package Name:** @cakemail-org/cakemail-cli
|
|
10
|
+
**Binary Name:** `cakemail`
|
|
11
|
+
|
|
12
|
+
## Project Structure
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
├── src/
|
|
16
|
+
│ ├── cli.ts # Main CLI entry point
|
|
17
|
+
│ ├── client.ts # SDK wrapper with configuration
|
|
18
|
+
│ ├── commands/ # Command modules
|
|
19
|
+
│ │ ├── campaigns.ts # Campaign management (15 commands)
|
|
20
|
+
│ │ ├── lists.ts # List management (4 commands)
|
|
21
|
+
│ │ ├── contacts.ts # Contact management (6 commands)
|
|
22
|
+
│ │ ├── senders.ts # Sender management (7 commands)
|
|
23
|
+
│ │ ├── templates.ts # Template management (6 commands)
|
|
24
|
+
│ │ ├── webhooks.ts # Webhook management (6 commands)
|
|
25
|
+
│ │ └── emails.ts # Email API v2 (3 commands)
|
|
26
|
+
│ └── utils/
|
|
27
|
+
│ ├── config.ts # Configuration and credentials
|
|
28
|
+
│ └── output.ts # Output formatting (JSON/table/compact)
|
|
29
|
+
├── dist/ # Compiled JavaScript
|
|
30
|
+
├── cakemail.rb # Homebrew formula
|
|
31
|
+
├── package.json
|
|
32
|
+
├── tsconfig.json
|
|
33
|
+
├── README.md
|
|
34
|
+
├── CHANGELOG.md
|
|
35
|
+
├── CONTRIBUTING.md
|
|
36
|
+
└── HOMEBREW.md
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Key Components
|
|
40
|
+
|
|
41
|
+
### 1. SDK Wrapper (`client.ts`)
|
|
42
|
+
|
|
43
|
+
The `CakemailClient` class wraps the official Cakemail SDK, providing:
|
|
44
|
+
- Authentication configuration (email/password or access token)
|
|
45
|
+
- SDK instance exposure via `client.sdk`
|
|
46
|
+
- Consistent error handling
|
|
47
|
+
- Base URL configuration
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { CakemailClient as SDK } from '@cakemail-org/cakemail-sdk';
|
|
51
|
+
|
|
52
|
+
export class CakemailClient {
|
|
53
|
+
public sdk: SDK;
|
|
54
|
+
|
|
55
|
+
constructor(config: CakemailConfig) {
|
|
56
|
+
this.sdk = new SDK({
|
|
57
|
+
email: config.email,
|
|
58
|
+
password: config.password,
|
|
59
|
+
baseURL: config.baseURL || 'https://api.cakemail.dev'
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Key Design Decision:** The CLI doesn't implement HTTP calls directly—it delegates to the SDK. This ensures:
|
|
66
|
+
- Type safety from SDK's TypeScript definitions
|
|
67
|
+
- Automatic updates when SDK adds features
|
|
68
|
+
- Consistency with other SDK consumers
|
|
69
|
+
- Reliability (SDK is thoroughly tested)
|
|
70
|
+
|
|
71
|
+
### 2. Command Modules (`commands/`)
|
|
72
|
+
|
|
73
|
+
Each command module:
|
|
74
|
+
- Uses Commander.js to define CLI commands
|
|
75
|
+
- Receives a `CakemailClient` instance (which exposes the SDK)
|
|
76
|
+
- Receives an `OutputFormatter` instance
|
|
77
|
+
- Calls SDK methods via `client.sdk.serviceName.method()`
|
|
78
|
+
- Provides user-friendly options and flags
|
|
79
|
+
|
|
80
|
+
**SDK 2.0 Object-Based API Pattern:**
|
|
81
|
+
```typescript
|
|
82
|
+
// All SDK methods use object parameters
|
|
83
|
+
const data = await client.sdk.senderService.createSender({
|
|
84
|
+
requestBody: {
|
|
85
|
+
name: 'John Doe',
|
|
86
|
+
email: 'john@example.com'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Pagination uses camelCase
|
|
91
|
+
const campaigns = await client.sdk.campaigns.list({
|
|
92
|
+
perPage: 50,
|
|
93
|
+
page: 2,
|
|
94
|
+
sort: '-created_on'
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Output Formatting (`utils/output.ts`)
|
|
99
|
+
|
|
100
|
+
Supports three output formats:
|
|
101
|
+
- **JSON**: Full API response (default) - pipeable to jq, scripts
|
|
102
|
+
- **Table**: Tabular view with column headers - human-readable
|
|
103
|
+
- **Compact**: Minimal ID and name view - quick scanning
|
|
104
|
+
|
|
105
|
+
Format selection priority:
|
|
106
|
+
1. CLI flag: `cakemail -f table campaigns list`
|
|
107
|
+
2. Environment variable: `CAKEMAIL_OUTPUT_FORMAT=compact`
|
|
108
|
+
3. Default: `json`
|
|
109
|
+
|
|
110
|
+
### 4. Configuration (`utils/config.ts`)
|
|
111
|
+
|
|
112
|
+
Loads credentials from (priority order):
|
|
113
|
+
1. CLI flags: `--email`, `--password`, `--access-token`
|
|
114
|
+
2. Environment variables: `CAKEMAIL_EMAIL`, `CAKEMAIL_PASSWORD`, `CAKEMAIL_ACCESS_TOKEN`
|
|
115
|
+
3. `.env` file (loaded from current working directory)
|
|
116
|
+
|
|
117
|
+
**Security Note:** Credentials are never stored persistently. The CLI reads them on each invocation.
|
|
118
|
+
|
|
119
|
+
## Authentication
|
|
120
|
+
|
|
121
|
+
The CLI supports two authentication methods via the SDK:
|
|
122
|
+
|
|
123
|
+
1. **Email/Password** (OAuth2 Password Grant):
|
|
124
|
+
```bash
|
|
125
|
+
CAKEMAIL_EMAIL=your@email.com
|
|
126
|
+
CAKEMAIL_PASSWORD=your_password
|
|
127
|
+
```
|
|
128
|
+
The SDK automatically obtains and refreshes OAuth2 tokens.
|
|
129
|
+
|
|
130
|
+
2. **Access Token** (for CI/CD):
|
|
131
|
+
```bash
|
|
132
|
+
CAKEMAIL_ACCESS_TOKEN=your_token
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The SDK handles token management, expiration, and refresh automatically.
|
|
136
|
+
|
|
137
|
+
## SDK Integration Architecture
|
|
138
|
+
|
|
139
|
+
### Why SDK-Based vs Direct HTTP?
|
|
140
|
+
|
|
141
|
+
**SDK Approach (Current):**
|
|
142
|
+
- ✅ Type safety from SDK TypeScript definitions
|
|
143
|
+
- ✅ Automatic API updates (SDK updates = CLI updates)
|
|
144
|
+
- ✅ Tested, reliable HTTP layer
|
|
145
|
+
- ✅ Consistent error handling
|
|
146
|
+
- ✅ OAuth2 complexity abstracted
|
|
147
|
+
- ✅ 100% API coverage available
|
|
148
|
+
|
|
149
|
+
**Direct HTTP Approach (Previous):**
|
|
150
|
+
- ❌ Manual type definitions
|
|
151
|
+
- ❌ Manual OAuth2 implementation
|
|
152
|
+
- ❌ Breaking when API changes
|
|
153
|
+
- ❌ Duplicate maintenance burden
|
|
154
|
+
|
|
155
|
+
### SDK Services Used
|
|
156
|
+
|
|
157
|
+
The SDK provides two API styles:
|
|
158
|
+
|
|
159
|
+
**1. Legacy Resources (v1 compatibility):**
|
|
160
|
+
```typescript
|
|
161
|
+
client.sdk.campaigns.list(params)
|
|
162
|
+
client.sdk.lists.create(payload)
|
|
163
|
+
client.sdk.contacts.get(id)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**2. Generated Services (v2, object-based):**
|
|
167
|
+
```typescript
|
|
168
|
+
client.sdk.campaignService.listCampaigns({ perPage: 50 })
|
|
169
|
+
client.sdk.senderService.createSender({ requestBody: {...} })
|
|
170
|
+
client.sdk.templateService.getTemplate({ templateId: 123 })
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The CLI uses the most appropriate style for each resource.
|
|
174
|
+
|
|
175
|
+
## Adding New Commands
|
|
176
|
+
|
|
177
|
+
To add a new command leveraging the SDK:
|
|
178
|
+
|
|
179
|
+
### 1. Create Command Module
|
|
180
|
+
|
|
181
|
+
`src/commands/reports.ts`:
|
|
182
|
+
```typescript
|
|
183
|
+
import { Command } from 'commander';
|
|
184
|
+
import { CakemailClient } from '../client.js';
|
|
185
|
+
import { OutputFormatter } from '../utils/output.js';
|
|
186
|
+
import ora from 'ora';
|
|
187
|
+
|
|
188
|
+
export function createReportsCommand(
|
|
189
|
+
client: CakemailClient,
|
|
190
|
+
formatter: OutputFormatter
|
|
191
|
+
): Command {
|
|
192
|
+
const reports = new Command('reports')
|
|
193
|
+
.description('Campaign analytics and reporting');
|
|
194
|
+
|
|
195
|
+
reports
|
|
196
|
+
.command('campaign <campaign-id>')
|
|
197
|
+
.description('Get campaign analytics report')
|
|
198
|
+
.action(async (campaignId) => {
|
|
199
|
+
const spinner = ora('Fetching campaign report...').start();
|
|
200
|
+
try {
|
|
201
|
+
// Use SDK service directly
|
|
202
|
+
const data = await client.sdk.reportService.getCampaignReport({
|
|
203
|
+
campaignId: parseInt(campaignId)
|
|
204
|
+
});
|
|
205
|
+
spinner.stop();
|
|
206
|
+
formatter.output(data);
|
|
207
|
+
} catch (error: any) {
|
|
208
|
+
spinner.stop();
|
|
209
|
+
formatter.error(error.message);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return reports;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 2. Register in CLI
|
|
219
|
+
|
|
220
|
+
`src/cli.ts`:
|
|
221
|
+
```typescript
|
|
222
|
+
import { createReportsCommand } from './commands/reports.js';
|
|
223
|
+
|
|
224
|
+
// In main():
|
|
225
|
+
program.addCommand(createReportsCommand(client, formatter));
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 3. Rebuild and Test
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
npm run build
|
|
232
|
+
cakemail reports campaign 123
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Development Workflow
|
|
236
|
+
|
|
237
|
+
### Local Development
|
|
238
|
+
|
|
239
|
+
1. **Install dependencies**: `npm install`
|
|
240
|
+
2. **Make changes** to TypeScript files in `src/`
|
|
241
|
+
3. **Build**: `npm run build`
|
|
242
|
+
4. **Test**: `node dist/cli.js <command>` or `cakemail <command>` if installed globally
|
|
243
|
+
5. **Watch mode**: `npm run dev` (auto-rebuilds on changes)
|
|
244
|
+
|
|
245
|
+
### Testing Workflow
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Set up test credentials
|
|
249
|
+
cp .env.example .env
|
|
250
|
+
# Edit .env with dev/test credentials
|
|
251
|
+
|
|
252
|
+
# Test commands
|
|
253
|
+
cakemail campaigns list
|
|
254
|
+
cakemail -f table senders list
|
|
255
|
+
cakemail contacts add 123 -e test@example.com
|
|
256
|
+
|
|
257
|
+
# Test output formats
|
|
258
|
+
cakemail campaigns list | jq '.data[0].name'
|
|
259
|
+
cakemail -f compact lists list
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Building for Distribution
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Clean build
|
|
266
|
+
npm run clean && npm run build
|
|
267
|
+
|
|
268
|
+
# Test binary
|
|
269
|
+
./dist/cli.js --version
|
|
270
|
+
|
|
271
|
+
# Test installation
|
|
272
|
+
npm pack
|
|
273
|
+
npm install -g ./cakemail-org-cakemail-cli-1.2.0.tgz
|
|
274
|
+
cakemail --version
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Distribution
|
|
278
|
+
|
|
279
|
+
The CLI is distributed via three channels:
|
|
280
|
+
|
|
281
|
+
### 1. npm
|
|
282
|
+
```bash
|
|
283
|
+
npm install -g @cakemail-org/cakemail-cli
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Publishing:**
|
|
287
|
+
```bash
|
|
288
|
+
npm version patch # or minor, major
|
|
289
|
+
npm run build
|
|
290
|
+
npm publish --access public
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### 2. Homebrew
|
|
294
|
+
```bash
|
|
295
|
+
brew tap cakemail/cakemail
|
|
296
|
+
brew install cakemail-cli
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Updating Formula:**
|
|
300
|
+
```bash
|
|
301
|
+
# Get new tarball SHA256
|
|
302
|
+
curl -sL https://registry.npmjs.org/@cakemail-org/cakemail-cli/-/cakemail-cli-VERSION.tgz | shasum -a 256
|
|
303
|
+
|
|
304
|
+
# Update ~/homebrew-cakemail/Formula/cakemail-cli.rb
|
|
305
|
+
# Update URL and SHA256
|
|
306
|
+
# Commit and push
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### 3. npx (no installation)
|
|
310
|
+
```bash
|
|
311
|
+
npx @cakemail-org/cakemail-cli campaigns list
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Dependencies
|
|
315
|
+
|
|
316
|
+
### Production Dependencies
|
|
317
|
+
- **@cakemail-org/cakemail-sdk**: Official SDK with 100% API coverage
|
|
318
|
+
- **commander**: CLI framework with subcommands and help
|
|
319
|
+
- **chalk**: Terminal colors for better UX
|
|
320
|
+
- **ora**: Loading spinners for async operations
|
|
321
|
+
- **cli-table3**: Table formatting
|
|
322
|
+
- **dotenv**: Environment variable loading from .env files
|
|
323
|
+
|
|
324
|
+
### Development Dependencies
|
|
325
|
+
- **typescript**: TypeScript compiler
|
|
326
|
+
- **@types/node**: Node.js type definitions
|
|
327
|
+
|
|
328
|
+
### Dependency Strategy
|
|
329
|
+
- Minimal, well-maintained dependencies
|
|
330
|
+
- No build-time transpilation beyond TypeScript
|
|
331
|
+
- All dependencies are mature open-source projects
|
|
332
|
+
|
|
333
|
+
## Error Handling
|
|
334
|
+
|
|
335
|
+
The CLI provides helpful error messages at multiple levels:
|
|
336
|
+
|
|
337
|
+
### 1. Configuration Errors
|
|
338
|
+
```
|
|
339
|
+
Error: Email and password are required for SDK authentication
|
|
340
|
+
|
|
341
|
+
Tip: Set credentials in environment variables or .env file:
|
|
342
|
+
CAKEMAIL_EMAIL=your@email.com
|
|
343
|
+
CAKEMAIL_PASSWORD=your_password
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### 2. API Errors
|
|
347
|
+
```
|
|
348
|
+
Error: Campaign not found (404)
|
|
349
|
+
Failed to retrieve campaign with ID: 12345
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### 3. Validation Errors
|
|
353
|
+
```
|
|
354
|
+
Error: Missing required option: --email
|
|
355
|
+
Try: cakemail contacts add 123 --email test@example.com
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Exit Codes
|
|
359
|
+
- **0**: Success
|
|
360
|
+
- **1**: Error (configuration, API, validation, etc.)
|
|
361
|
+
|
|
362
|
+
## Version Strategy
|
|
363
|
+
|
|
364
|
+
The CLI follows [Semantic Versioning](https://semver.org/):
|
|
365
|
+
|
|
366
|
+
- **Patch** (1.2.x): Bug fixes, no breaking changes
|
|
367
|
+
- **Minor** (1.x.0): New commands, backward compatible
|
|
368
|
+
- **Major** (x.0.0): Breaking changes (command signature changes, SDK major updates)
|
|
369
|
+
|
|
370
|
+
### Breaking Changes
|
|
371
|
+
Breaking changes are announced 2 minor versions ahead with deprecation warnings:
|
|
372
|
+
```
|
|
373
|
+
Warning: The --key option is deprecated and will be removed in v2.0.0
|
|
374
|
+
Please use --api-key instead
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
## Current Implementation Status
|
|
378
|
+
|
|
379
|
+
### ✅ Implemented (56 commands)
|
|
380
|
+
- **Campaigns**: 15 commands (full lifecycle)
|
|
381
|
+
- **Lists**: 4 commands (core CRUD)
|
|
382
|
+
- **Contacts**: 6 commands (core CRUD)
|
|
383
|
+
- **Senders**: 7 commands (complete management)
|
|
384
|
+
- **Templates**: 6 commands (complete management)
|
|
385
|
+
- **Webhooks**: 6 commands (complete management)
|
|
386
|
+
- **Email API v2**: 3 commands (transactional emails)
|
|
387
|
+
|
|
388
|
+
### 📦 Available via SDK (not yet CLI commands)
|
|
389
|
+
- Reports and analytics (ReportService)
|
|
390
|
+
- Segments (SegmentService)
|
|
391
|
+
- Custom attributes (CustomAttributeService)
|
|
392
|
+
- Contact tagging (TagsService)
|
|
393
|
+
- Workflows and automation (WorkflowService)
|
|
394
|
+
- Forms (FormService)
|
|
395
|
+
- Sub-accounts (SubAccountService)
|
|
396
|
+
- And 20+ more services (see API_COVERAGE.md)
|
|
397
|
+
|
|
398
|
+
### 🎯 Roadmap
|
|
399
|
+
|
|
400
|
+
**v1.3.0 - High-Value Commands:**
|
|
401
|
+
- Reports (campaign analytics, list stats)
|
|
402
|
+
- Segments (contact segmentation)
|
|
403
|
+
- Custom attributes management
|
|
404
|
+
|
|
405
|
+
**v1.4.0 - Bulk Operations:**
|
|
406
|
+
- Contact import/export
|
|
407
|
+
- Bulk tagging
|
|
408
|
+
- Batch operations
|
|
409
|
+
|
|
410
|
+
**v1.5.0 - Advanced Features:**
|
|
411
|
+
- Workflows and automation
|
|
412
|
+
- Forms management
|
|
413
|
+
- Sub-account operations
|
|
414
|
+
|
|
415
|
+
## Testing
|
|
416
|
+
|
|
417
|
+
### Manual Testing
|
|
418
|
+
```bash
|
|
419
|
+
# Test authentication
|
|
420
|
+
cakemail campaigns list
|
|
421
|
+
|
|
422
|
+
# Test output formats
|
|
423
|
+
cakemail -f json campaigns list
|
|
424
|
+
cakemail -f table senders list
|
|
425
|
+
cakemail -f compact lists list
|
|
426
|
+
|
|
427
|
+
# Test piping
|
|
428
|
+
cakemail campaigns list | jq '.data[0]'
|
|
429
|
+
|
|
430
|
+
# Test error handling
|
|
431
|
+
cakemail campaigns get 999999 # Non-existent ID
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### CI/CD Testing
|
|
435
|
+
The CLI is suitable for automated testing in pipelines:
|
|
436
|
+
```yaml
|
|
437
|
+
# GitHub Actions example
|
|
438
|
+
- name: Test CLI
|
|
439
|
+
env:
|
|
440
|
+
CAKEMAIL_EMAIL: ${{ secrets.CAKEMAIL_EMAIL }}
|
|
441
|
+
CAKEMAIL_PASSWORD: ${{ secrets.CAKEMAIL_PASSWORD }}
|
|
442
|
+
run: |
|
|
443
|
+
npm install -g @cakemail-org/cakemail-cli
|
|
444
|
+
cakemail campaigns list --status active
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### SDK Compatibility
|
|
448
|
+
The CLI version pins to a specific SDK version to ensure stability. SDK updates are tested before releasing a new CLI version.
|
|
449
|
+
|
|
450
|
+
## Performance Considerations
|
|
451
|
+
|
|
452
|
+
- **Startup time**: ~500ms (Node.js + SDK initialization)
|
|
453
|
+
- **API calls**: Direct SDK calls (no additional overhead)
|
|
454
|
+
- **Memory**: Minimal (~50MB resident)
|
|
455
|
+
- **Concurrency**: Single-threaded (Node.js event loop)
|
|
456
|
+
|
|
457
|
+
For high-volume operations, consider:
|
|
458
|
+
- Batch API endpoints (when available)
|
|
459
|
+
- Direct SDK usage in custom scripts
|
|
460
|
+
- Parallel execution of multiple CLI invocations
|
|
461
|
+
|
|
462
|
+
## Security
|
|
463
|
+
|
|
464
|
+
### Credential Management
|
|
465
|
+
- Never commit credentials to git (`.env` is gitignored)
|
|
466
|
+
- Use environment variables in CI/CD (not stored in repos)
|
|
467
|
+
- Rotate credentials regularly
|
|
468
|
+
- Use access tokens for automated systems
|
|
469
|
+
|
|
470
|
+
### Supply Chain
|
|
471
|
+
- All dependencies are verified via npm
|
|
472
|
+
- `package-lock.json` ensures reproducible builds
|
|
473
|
+
- No post-install scripts
|
|
474
|
+
- Regular dependency audits: `npm audit`
|
|
475
|
+
|
|
476
|
+
## Troubleshooting
|
|
477
|
+
|
|
478
|
+
### Common Issues
|
|
479
|
+
|
|
480
|
+
**"Email and password are required"**
|
|
481
|
+
- Set credentials in `.env` or environment variables
|
|
482
|
+
- Verify `.env` is in current working directory
|
|
483
|
+
|
|
484
|
+
**"Command not found: cakemail"**
|
|
485
|
+
- Install globally: `npm install -g @cakemail-org/cakemail-cli`
|
|
486
|
+
- Or use npx: `npx @cakemail-org/cakemail-cli`
|
|
487
|
+
|
|
488
|
+
**"Invalid credentials"**
|
|
489
|
+
- Verify email and password are correct
|
|
490
|
+
- Check for special characters in password (quote in .env if needed)
|
|
491
|
+
|
|
492
|
+
**"Network error" or timeouts**
|
|
493
|
+
- Check internet connection
|
|
494
|
+
- Verify API base URL (default: https://api.cakemail.dev)
|
|
495
|
+
- Check firewall/proxy settings
|
|
496
|
+
|
|
497
|
+
### Debug Mode
|
|
498
|
+
Set `NODE_ENV=development` for verbose SDK logging (if implemented by SDK).
|
|
499
|
+
|
|
500
|
+
## Contributing
|
|
501
|
+
|
|
502
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for:
|
|
503
|
+
- Development setup
|
|
504
|
+
- Code style guidelines
|
|
505
|
+
- Pull request process
|
|
506
|
+
- Command prioritization criteria
|
|
507
|
+
|
|
508
|
+
## License
|
|
509
|
+
|
|
510
|
+
MIT License - See [LICENSE](LICENSE) file
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
*Last Updated: 2025-10-10*
|
|
515
|
+
*CLI Version: 1.2.0*
|
|
516
|
+
*SDK Version: @cakemail-org/cakemail-sdk v2.0.0*
|