@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
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
# Debugging Guide
|
|
2
|
+
|
|
3
|
+
Advanced debugging techniques for diagnosing and resolving CLI issues.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Learn to:
|
|
8
|
+
- Enable verbose logging
|
|
9
|
+
- Use debug mode
|
|
10
|
+
- Inspect API requests/responses
|
|
11
|
+
- Trace command execution
|
|
12
|
+
- Analyze error messages
|
|
13
|
+
- Report bugs effectively
|
|
14
|
+
|
|
15
|
+
## Debug Mode
|
|
16
|
+
|
|
17
|
+
### Enable CLI Debug Logging
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Enable all debug output
|
|
21
|
+
$ export DEBUG=cakemail:*
|
|
22
|
+
|
|
23
|
+
# Run command with debug output
|
|
24
|
+
$ cakemail campaigns list
|
|
25
|
+
cakemail:api GET /v1/campaigns +0ms
|
|
26
|
+
cakemail:auth Authenticating... +5ms
|
|
27
|
+
cakemail:api Response: 200 OK +245ms
|
|
28
|
+
|
|
29
|
+
# Disable debug mode
|
|
30
|
+
$ unset DEBUG
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Selective Debug Logging
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Authentication only
|
|
37
|
+
$ export DEBUG=cakemail:auth
|
|
38
|
+
$ cakemail account show
|
|
39
|
+
|
|
40
|
+
# API requests only
|
|
41
|
+
$ export DEBUG=cakemail:api
|
|
42
|
+
$ cakemail lists list
|
|
43
|
+
|
|
44
|
+
# Multiple modules
|
|
45
|
+
$ export DEBUG=cakemail:auth,cakemail:api
|
|
46
|
+
$ cakemail campaigns create -n "Test"
|
|
47
|
+
|
|
48
|
+
# Everything except cache
|
|
49
|
+
$ export DEBUG=cakemail:* -cakemail:cache
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Debug Log Levels
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Verbose output (all levels)
|
|
56
|
+
$ export DEBUG=cakemail:*
|
|
57
|
+
$ export DEBUG_LEVEL=trace
|
|
58
|
+
|
|
59
|
+
# Specific levels
|
|
60
|
+
$ export DEBUG_LEVEL=error # Errors only
|
|
61
|
+
$ export DEBUG_LEVEL=warn # Warnings and errors
|
|
62
|
+
$ export DEBUG_LEVEL=info # Info, warnings, errors
|
|
63
|
+
$ export DEBUG_LEVEL=debug # All messages (default)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Verbose Mode
|
|
67
|
+
|
|
68
|
+
### Command-Specific Verbosity
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Most commands support --verbose
|
|
72
|
+
$ cakemail campaigns list --verbose
|
|
73
|
+
|
|
74
|
+
# Shows:
|
|
75
|
+
# - API endpoint called
|
|
76
|
+
# - Request parameters
|
|
77
|
+
# - Response status
|
|
78
|
+
# - Timing information
|
|
79
|
+
|
|
80
|
+
# Example output:
|
|
81
|
+
# → GET /v1/campaigns
|
|
82
|
+
# ← 200 OK (245ms)
|
|
83
|
+
# Found 15 campaigns
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### JSON Output for Debugging
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Get raw API response
|
|
90
|
+
$ cakemail campaigns get 790 -f json
|
|
91
|
+
|
|
92
|
+
# Pretty print with jq
|
|
93
|
+
$ cakemail campaigns get 790 -f json | jq .
|
|
94
|
+
|
|
95
|
+
# Inspect specific fields
|
|
96
|
+
$ cakemail campaigns get 790 -f json | jq '.status, .name'
|
|
97
|
+
|
|
98
|
+
# Save for analysis
|
|
99
|
+
$ cakemail campaigns get 790 -f json > debug-campaign.json
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Logging
|
|
103
|
+
|
|
104
|
+
### Enable File Logging
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Log to file
|
|
108
|
+
$ cakemail campaigns list 2>&1 | tee debug.log
|
|
109
|
+
|
|
110
|
+
# Separate stdout and stderr
|
|
111
|
+
$ cakemail campaigns list > output.log 2> error.log
|
|
112
|
+
|
|
113
|
+
# Append mode
|
|
114
|
+
$ cakemail campaigns list 2>&1 | tee -a debug.log
|
|
115
|
+
|
|
116
|
+
# With timestamps
|
|
117
|
+
$ cakemail campaigns list 2>&1 | while read line; do
|
|
118
|
+
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $line"
|
|
119
|
+
done | tee debug.log
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Structured Logging
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
#!/bin/bash
|
|
126
|
+
|
|
127
|
+
# Logging function
|
|
128
|
+
log() {
|
|
129
|
+
local level="$1"
|
|
130
|
+
shift
|
|
131
|
+
local message="$*"
|
|
132
|
+
local timestamp=$(date +'%Y-%m-%d %H:%M:%S')
|
|
133
|
+
|
|
134
|
+
echo "[$timestamp] [$level] $message" | tee -a debug.log
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# Usage
|
|
138
|
+
log INFO "Starting campaign deployment"
|
|
139
|
+
log DEBUG "Campaign ID: 790"
|
|
140
|
+
|
|
141
|
+
if ! cakemail campaigns schedule 790 2>>debug.log; then
|
|
142
|
+
log ERROR "Failed to schedule campaign"
|
|
143
|
+
exit 1
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
log INFO "Deployment complete"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Network Debugging
|
|
150
|
+
|
|
151
|
+
### Inspect HTTP Requests
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Use curl with verbose output
|
|
155
|
+
$ curl -v https://api.cakemail.com/v1/campaigns 2>&1 | less
|
|
156
|
+
|
|
157
|
+
# Shows:
|
|
158
|
+
# - DNS resolution
|
|
159
|
+
# - TCP connection
|
|
160
|
+
# - SSL handshake
|
|
161
|
+
# - HTTP headers
|
|
162
|
+
# - Response data
|
|
163
|
+
|
|
164
|
+
# Save headers
|
|
165
|
+
$ curl -D headers.txt https://api.cakemail.com/v1/campaigns
|
|
166
|
+
|
|
167
|
+
# View response headers
|
|
168
|
+
$ cat headers.txt
|
|
169
|
+
HTTP/2 200
|
|
170
|
+
content-type: application/json
|
|
171
|
+
x-ratelimit-limit: 100
|
|
172
|
+
x-ratelimit-remaining: 95
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Capture Network Traffic
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Using tcpdump (requires root)
|
|
179
|
+
$ sudo tcpdump -i any -w capture.pcap host api.cakemail.com
|
|
180
|
+
|
|
181
|
+
# Run CLI command in another terminal
|
|
182
|
+
$ cakemail campaigns list
|
|
183
|
+
|
|
184
|
+
# Stop tcpdump (Ctrl+C)
|
|
185
|
+
|
|
186
|
+
# Analyze with Wireshark
|
|
187
|
+
$ wireshark capture.pcap
|
|
188
|
+
|
|
189
|
+
# Or use tshark (command-line)
|
|
190
|
+
$ tshark -r capture.pcap -Y "http or tls" -V
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### HTTP Proxy for Debugging
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Use mitmproxy to inspect requests
|
|
197
|
+
$ mitmproxy -p 8080
|
|
198
|
+
|
|
199
|
+
# In another terminal, configure proxy
|
|
200
|
+
$ export HTTP_PROXY=http://localhost:8080
|
|
201
|
+
$ export HTTPS_PROXY=http://localhost:8080
|
|
202
|
+
|
|
203
|
+
# Run CLI command
|
|
204
|
+
$ cakemail campaigns list
|
|
205
|
+
|
|
206
|
+
# View in mitmproxy:
|
|
207
|
+
# - Request headers
|
|
208
|
+
# - Request body
|
|
209
|
+
# - Response headers
|
|
210
|
+
# - Response body
|
|
211
|
+
# - Timing
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Error Analysis
|
|
215
|
+
|
|
216
|
+
### Parse Error Messages
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Capture full error
|
|
220
|
+
$ cakemail campaigns schedule 790 2>&1 | tee error.log
|
|
221
|
+
|
|
222
|
+
# Extract error type
|
|
223
|
+
$ grep -i "error" error.log
|
|
224
|
+
|
|
225
|
+
# Extract status code
|
|
226
|
+
$ grep -oP "HTTP \K\d+" error.log
|
|
227
|
+
|
|
228
|
+
# Get stack trace (if available)
|
|
229
|
+
$ grep -A 20 "Error:" error.log
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Common Error Patterns
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
#!/bin/bash
|
|
236
|
+
|
|
237
|
+
analyze_error() {
|
|
238
|
+
local error_output="$1"
|
|
239
|
+
|
|
240
|
+
if echo "$error_output" | grep -q "ECONNREFUSED"; then
|
|
241
|
+
echo "Connection refused - API unreachable"
|
|
242
|
+
echo "Check: Network, firewall, API status"
|
|
243
|
+
|
|
244
|
+
elif echo "$error_output" | grep -q "ETIMEDOUT"; then
|
|
245
|
+
echo "Connection timeout - network latency"
|
|
246
|
+
echo "Check: Internet speed, API latency"
|
|
247
|
+
|
|
248
|
+
elif echo "$error_output" | grep -q "ENOTFOUND"; then
|
|
249
|
+
echo "DNS resolution failed"
|
|
250
|
+
echo "Check: DNS servers, /etc/hosts"
|
|
251
|
+
|
|
252
|
+
elif echo "$error_output" | grep -q "401"; then
|
|
253
|
+
echo "Authentication failed"
|
|
254
|
+
echo "Check: Credentials, token expiration"
|
|
255
|
+
|
|
256
|
+
elif echo "$error_output" | grep -q "404"; then
|
|
257
|
+
echo "Resource not found"
|
|
258
|
+
echo "Check: Resource ID, account access"
|
|
259
|
+
|
|
260
|
+
elif echo "$error_output" | grep -q "429"; then
|
|
261
|
+
echo "Rate limit exceeded"
|
|
262
|
+
echo "Check: Request frequency, implement delays"
|
|
263
|
+
|
|
264
|
+
else
|
|
265
|
+
echo "Unknown error"
|
|
266
|
+
echo "Enable debug mode: DEBUG=cakemail:*"
|
|
267
|
+
fi
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
# Usage
|
|
271
|
+
ERROR_OUTPUT=$(cakemail campaigns get 999 2>&1)
|
|
272
|
+
analyze_error "$ERROR_OUTPUT"
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Command Tracing
|
|
276
|
+
|
|
277
|
+
### Bash Script Debugging
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
#!/bin/bash
|
|
281
|
+
|
|
282
|
+
# Enable tracing
|
|
283
|
+
set -x
|
|
284
|
+
|
|
285
|
+
# Your commands here
|
|
286
|
+
cakemail campaigns create -n "Test" -l 123 -s 101
|
|
287
|
+
|
|
288
|
+
# Disable tracing
|
|
289
|
+
set +x
|
|
290
|
+
|
|
291
|
+
# Output shows:
|
|
292
|
+
# + cakemail campaigns create -n Test -l 123 -s 101
|
|
293
|
+
# Campaign created: 790
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Advanced Tracing
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
#!/bin/bash
|
|
300
|
+
|
|
301
|
+
# Trace with timestamps
|
|
302
|
+
PS4='+ $(date +%Y-%m-%dT%H:%M:%S) ${BASH_SOURCE}:${LINENO}: '
|
|
303
|
+
set -x
|
|
304
|
+
|
|
305
|
+
cakemail campaigns list
|
|
306
|
+
cakemail campaigns get 790
|
|
307
|
+
|
|
308
|
+
set +x
|
|
309
|
+
|
|
310
|
+
# Output:
|
|
311
|
+
# + 2024-03-13T14:30:15 script.sh:5: cakemail campaigns list
|
|
312
|
+
# + 2024-03-13T14:30:16 script.sh:6: cakemail campaigns get 790
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Function Call Stack
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
#!/bin/bash
|
|
319
|
+
|
|
320
|
+
# Print call stack on error
|
|
321
|
+
trap 'echo "Error on line $LINENO"; exit 1' ERR
|
|
322
|
+
|
|
323
|
+
create_campaign() {
|
|
324
|
+
local name="$1"
|
|
325
|
+
echo "Creating campaign: $name"
|
|
326
|
+
|
|
327
|
+
cakemail campaigns create -n "$name" -l 123 -s 101
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
deploy_campaign() {
|
|
331
|
+
local id="$1"
|
|
332
|
+
echo "Deploying campaign: $id"
|
|
333
|
+
|
|
334
|
+
cakemail campaigns schedule "$id"
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
# Usage
|
|
338
|
+
CAMPAIGN_ID=$(create_campaign "Test" | grep -oP "Campaign created: \K\d+")
|
|
339
|
+
deploy_campaign "$CAMPAIGN_ID"
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Performance Profiling
|
|
343
|
+
|
|
344
|
+
### Measure Execution Time
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
# Simple timing
|
|
348
|
+
$ time cakemail campaigns list
|
|
349
|
+
|
|
350
|
+
real 0m1.234s
|
|
351
|
+
user 0m0.456s
|
|
352
|
+
sys 0m0.078s
|
|
353
|
+
|
|
354
|
+
# Detailed timing
|
|
355
|
+
$ time -v cakemail campaigns list 2>&1 | grep -E "Elapsed|Maximum"
|
|
356
|
+
Elapsed (wall clock) time: 0:01.23
|
|
357
|
+
Maximum resident set size: 45678
|
|
358
|
+
|
|
359
|
+
# Custom timing
|
|
360
|
+
start=$(date +%s%N)
|
|
361
|
+
cakemail campaigns list
|
|
362
|
+
end=$(date +%s%N)
|
|
363
|
+
duration=$(( (end - start) / 1000000 ))
|
|
364
|
+
echo "Duration: ${duration}ms"
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Profile Script Performance
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
#!/bin/bash
|
|
371
|
+
|
|
372
|
+
profile() {
|
|
373
|
+
local description="$1"
|
|
374
|
+
shift
|
|
375
|
+
local command="$*"
|
|
376
|
+
|
|
377
|
+
local start=$(date +%s%N)
|
|
378
|
+
eval "$command"
|
|
379
|
+
local end=$(date +%s%N)
|
|
380
|
+
|
|
381
|
+
local duration=$(( (end - start) / 1000000 ))
|
|
382
|
+
echo "[$description] ${duration}ms" >&2
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
# Usage
|
|
386
|
+
profile "List campaigns" cakemail campaigns list
|
|
387
|
+
profile "Get campaign" cakemail campaigns get 790
|
|
388
|
+
profile "List contacts" cakemail contacts list 123
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Memory Usage Monitoring
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
#!/bin/bash
|
|
395
|
+
|
|
396
|
+
monitor_memory() {
|
|
397
|
+
local pid=$1
|
|
398
|
+
local max_mem=0
|
|
399
|
+
|
|
400
|
+
while kill -0 $pid 2>/dev/null; do
|
|
401
|
+
local mem=$(ps -o rss= -p $pid 2>/dev/null || echo 0)
|
|
402
|
+
[ $mem -gt $max_mem ] && max_mem=$mem
|
|
403
|
+
sleep 0.1
|
|
404
|
+
done
|
|
405
|
+
|
|
406
|
+
local max_mem_mb=$((max_mem / 1024))
|
|
407
|
+
echo "Peak memory: ${max_mem_mb}MB" >&2
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
# Usage
|
|
411
|
+
cakemail contacts export 123 &
|
|
412
|
+
PID=$!
|
|
413
|
+
monitor_memory $PID
|
|
414
|
+
wait $PID
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
## API Debugging
|
|
418
|
+
|
|
419
|
+
### Inspect Request/Response
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
# Create debug wrapper
|
|
423
|
+
cakemail_debug() {
|
|
424
|
+
echo "=== Request ===" >&2
|
|
425
|
+
echo "Command: cakemail $*" >&2
|
|
426
|
+
|
|
427
|
+
local output=$(cakemail "$@" -f json 2>&1)
|
|
428
|
+
local exit_code=$?
|
|
429
|
+
|
|
430
|
+
echo "=== Response ===" >&2
|
|
431
|
+
echo "$output" | jq . >&2 2>/dev/null || echo "$output" >&2
|
|
432
|
+
|
|
433
|
+
echo "=== Exit Code: $exit_code ===" >&2
|
|
434
|
+
|
|
435
|
+
return $exit_code
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
# Usage
|
|
439
|
+
cakemail_debug campaigns get 790
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Mock API Responses
|
|
443
|
+
|
|
444
|
+
```bash
|
|
445
|
+
#!/bin/bash
|
|
446
|
+
|
|
447
|
+
# Mock mode for testing
|
|
448
|
+
MOCK_MODE=${MOCK_MODE:-false}
|
|
449
|
+
|
|
450
|
+
cakemail() {
|
|
451
|
+
if [ "$MOCK_MODE" = "true" ]; then
|
|
452
|
+
echo "MOCK: cakemail $*" >&2
|
|
453
|
+
|
|
454
|
+
case "$1" in
|
|
455
|
+
campaigns)
|
|
456
|
+
echo '{"id": 999, "name": "Mock Campaign", "status": "draft"}'
|
|
457
|
+
;;
|
|
458
|
+
lists)
|
|
459
|
+
echo '{"id": 123, "name": "Mock List", "contacts_count": 100}'
|
|
460
|
+
;;
|
|
461
|
+
*)
|
|
462
|
+
echo '{"success": true}'
|
|
463
|
+
;;
|
|
464
|
+
esac
|
|
465
|
+
else
|
|
466
|
+
command cakemail "$@"
|
|
467
|
+
fi
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
# Test without API calls
|
|
471
|
+
MOCK_MODE=true
|
|
472
|
+
cakemail campaigns get 790
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## Diagnostic Scripts
|
|
476
|
+
|
|
477
|
+
### Comprehensive Diagnostics
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
#!/bin/bash
|
|
481
|
+
# diagnostic.sh - Collect debugging information
|
|
482
|
+
|
|
483
|
+
OUTPUT_FILE="cakemail-diagnostic-$(date +%Y%m%d-%H%M%S).txt"
|
|
484
|
+
|
|
485
|
+
{
|
|
486
|
+
echo "=== Cakemail CLI Diagnostic Report ==="
|
|
487
|
+
echo "Generated: $(date)"
|
|
488
|
+
echo ""
|
|
489
|
+
|
|
490
|
+
echo "=== System Information ==="
|
|
491
|
+
echo "OS: $(uname -s)"
|
|
492
|
+
echo "Version: $(uname -r)"
|
|
493
|
+
echo "Architecture: $(uname -m)"
|
|
494
|
+
echo ""
|
|
495
|
+
|
|
496
|
+
echo "=== CLI Information ==="
|
|
497
|
+
echo "CLI Version: $(cakemail --version 2>&1)"
|
|
498
|
+
echo "CLI Location: $(which cakemail)"
|
|
499
|
+
echo "Node Version: $(node --version)"
|
|
500
|
+
echo "NPM Version: $(npm --version)"
|
|
501
|
+
echo ""
|
|
502
|
+
|
|
503
|
+
echo "=== Environment Variables ==="
|
|
504
|
+
env | grep -i cakemail | sed 's/PASSWORD=.*/PASSWORD=***redacted***/'
|
|
505
|
+
echo ""
|
|
506
|
+
|
|
507
|
+
echo "=== Configuration Files ==="
|
|
508
|
+
echo "Current directory .env:"
|
|
509
|
+
[ -f .env ] && echo " Exists" || echo " Not found"
|
|
510
|
+
|
|
511
|
+
echo "Home directory .env:"
|
|
512
|
+
[ -f ~/.cakemail/.env ] && echo " Exists" || echo " Not found"
|
|
513
|
+
echo ""
|
|
514
|
+
|
|
515
|
+
echo "=== Network Connectivity ==="
|
|
516
|
+
echo "Ping api.cakemail.com:"
|
|
517
|
+
ping -c 3 api.cakemail.com 2>&1 | tail -2
|
|
518
|
+
|
|
519
|
+
echo ""
|
|
520
|
+
echo "DNS Resolution:"
|
|
521
|
+
nslookup api.cakemail.com | grep -A1 "Name:"
|
|
522
|
+
|
|
523
|
+
echo ""
|
|
524
|
+
echo "Port 443 connectivity:"
|
|
525
|
+
nc -zv api.cakemail.com 443 2>&1
|
|
526
|
+
|
|
527
|
+
echo ""
|
|
528
|
+
echo "=== API Test ==="
|
|
529
|
+
echo "Testing API availability:"
|
|
530
|
+
curl -I -s https://api.cakemail.com | head -1
|
|
531
|
+
|
|
532
|
+
echo ""
|
|
533
|
+
echo "=== Authentication Test ==="
|
|
534
|
+
echo "Testing authentication:"
|
|
535
|
+
cakemail account test 2>&1
|
|
536
|
+
|
|
537
|
+
echo ""
|
|
538
|
+
echo "=== Recent Errors (if any) ==="
|
|
539
|
+
if [ -f debug.log ]; then
|
|
540
|
+
echo "From debug.log (last 20 lines):"
|
|
541
|
+
tail -20 debug.log
|
|
542
|
+
else
|
|
543
|
+
echo "No debug.log found"
|
|
544
|
+
fi
|
|
545
|
+
|
|
546
|
+
echo ""
|
|
547
|
+
echo "=== End of Diagnostic Report ==="
|
|
548
|
+
|
|
549
|
+
} | tee "$OUTPUT_FILE"
|
|
550
|
+
|
|
551
|
+
echo ""
|
|
552
|
+
echo "Diagnostic report saved to: $OUTPUT_FILE"
|
|
553
|
+
echo "Please include this file when reporting issues."
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Quick Health Check
|
|
557
|
+
|
|
558
|
+
```bash
|
|
559
|
+
#!/bin/bash
|
|
560
|
+
|
|
561
|
+
health_check() {
|
|
562
|
+
local tests_passed=0
|
|
563
|
+
local tests_failed=0
|
|
564
|
+
|
|
565
|
+
# Test 1: CLI installed
|
|
566
|
+
if command -v cakemail &>/dev/null; then
|
|
567
|
+
echo "✓ CLI installed"
|
|
568
|
+
((tests_passed++))
|
|
569
|
+
else
|
|
570
|
+
echo "✗ CLI not found"
|
|
571
|
+
((tests_failed++))
|
|
572
|
+
fi
|
|
573
|
+
|
|
574
|
+
# Test 2: Credentials configured
|
|
575
|
+
if [ -f .env ] || [ -f ~/.cakemail/.env ] || [ -n "$CAKEMAIL_EMAIL" ]; then
|
|
576
|
+
echo "✓ Credentials configured"
|
|
577
|
+
((tests_passed++))
|
|
578
|
+
else
|
|
579
|
+
echo "✗ Credentials missing"
|
|
580
|
+
((tests_failed++))
|
|
581
|
+
fi
|
|
582
|
+
|
|
583
|
+
# Test 3: API reachable
|
|
584
|
+
if curl -f -s -I https://api.cakemail.com &>/dev/null; then
|
|
585
|
+
echo "✓ API reachable"
|
|
586
|
+
((tests_passed++))
|
|
587
|
+
else
|
|
588
|
+
echo "✗ API unreachable"
|
|
589
|
+
((tests_failed++))
|
|
590
|
+
fi
|
|
591
|
+
|
|
592
|
+
# Test 4: Authentication works
|
|
593
|
+
if cakemail account test &>/dev/null; then
|
|
594
|
+
echo "✓ Authentication successful"
|
|
595
|
+
((tests_passed++))
|
|
596
|
+
else
|
|
597
|
+
echo "✗ Authentication failed"
|
|
598
|
+
((tests_failed++))
|
|
599
|
+
fi
|
|
600
|
+
|
|
601
|
+
echo ""
|
|
602
|
+
echo "Results: $tests_passed passed, $tests_failed failed"
|
|
603
|
+
|
|
604
|
+
[ $tests_failed -eq 0 ] && return 0 || return 1
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
health_check
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
## Bug Reporting
|
|
611
|
+
|
|
612
|
+
### Collect Debug Information
|
|
613
|
+
|
|
614
|
+
```bash
|
|
615
|
+
#!/bin/bash
|
|
616
|
+
|
|
617
|
+
# Collect info for bug report
|
|
618
|
+
echo "Please provide this information when reporting bugs:"
|
|
619
|
+
echo ""
|
|
620
|
+
|
|
621
|
+
echo "1. CLI Version:"
|
|
622
|
+
cakemail --version
|
|
623
|
+
|
|
624
|
+
echo ""
|
|
625
|
+
echo "2. Command that failed:"
|
|
626
|
+
echo " $ cakemail campaigns schedule 790"
|
|
627
|
+
|
|
628
|
+
echo ""
|
|
629
|
+
echo "3. Error output:"
|
|
630
|
+
DEBUG=cakemail:* cakemail campaigns schedule 790 2>&1 | \
|
|
631
|
+
sed 's/password=.*/password=***redacted***/'
|
|
632
|
+
|
|
633
|
+
echo ""
|
|
634
|
+
echo "4. System information:"
|
|
635
|
+
uname -a
|
|
636
|
+
|
|
637
|
+
echo ""
|
|
638
|
+
echo "5. Network test:"
|
|
639
|
+
curl -I https://api.cakemail.com 2>&1 | head -5
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Minimal Reproducible Example
|
|
643
|
+
|
|
644
|
+
```bash
|
|
645
|
+
#!/bin/bash
|
|
646
|
+
|
|
647
|
+
# Create minimal reproduction
|
|
648
|
+
echo "=== Minimal Reproducible Example ==="
|
|
649
|
+
|
|
650
|
+
# Clean state
|
|
651
|
+
rm -f .env debug.log
|
|
652
|
+
|
|
653
|
+
# Configure (with dummy creds for example)
|
|
654
|
+
cat > .env << 'EOF'
|
|
655
|
+
CAKEMAIL_EMAIL=test@example.com
|
|
656
|
+
CAKEMAIL_PASSWORD=test_password
|
|
657
|
+
EOF
|
|
658
|
+
|
|
659
|
+
# Enable debug
|
|
660
|
+
export DEBUG=cakemail:*
|
|
661
|
+
|
|
662
|
+
# Reproduce issue
|
|
663
|
+
echo "Running: cakemail campaigns list"
|
|
664
|
+
cakemail campaigns list 2>&1
|
|
665
|
+
|
|
666
|
+
# Output shows exactly what happens
|
|
667
|
+
# Include this in bug report
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
## Best Practices
|
|
671
|
+
|
|
672
|
+
1. **Always enable debug mode** when troubleshooting
|
|
673
|
+
```bash
|
|
674
|
+
export DEBUG=cakemail:*
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
2. **Save logs** for analysis
|
|
678
|
+
```bash
|
|
679
|
+
cakemail commands 2>&1 | tee debug.log
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
3. **Test in isolation** to identify root cause
|
|
683
|
+
```bash
|
|
684
|
+
# Remove variables that might interfere
|
|
685
|
+
env -i HOME=$HOME cakemail campaigns list
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
4. **Use verbose output** for detailed information
|
|
689
|
+
```bash
|
|
690
|
+
cakemail campaigns list --verbose
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
5. **Check exit codes** in scripts
|
|
694
|
+
```bash
|
|
695
|
+
if ! cakemail campaigns schedule 790; then
|
|
696
|
+
echo "Failed with exit code: $?"
|
|
697
|
+
fi
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
6. **Redact sensitive information** before sharing
|
|
701
|
+
```bash
|
|
702
|
+
sed 's/password=.*/password=***redacted***/' debug.log
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
## Debugging Checklist
|
|
706
|
+
|
|
707
|
+
When troubleshooting:
|
|
708
|
+
|
|
709
|
+
- [ ] Enabled debug mode (`DEBUG=cakemail:*`)
|
|
710
|
+
- [ ] Checked CLI version (`cakemail --version`)
|
|
711
|
+
- [ ] Verified credentials exist and are valid
|
|
712
|
+
- [ ] Tested network connectivity
|
|
713
|
+
- [ ] Checked API status (status.cakemail.com)
|
|
714
|
+
- [ ] Saved error logs
|
|
715
|
+
- [ ] Tried command with verbose flag
|
|
716
|
+
- [ ] Isolated issue to specific command/operation
|
|
717
|
+
- [ ] Checked for known issues on GitHub
|
|
718
|
+
- [ ] Collected diagnostic information
|
|
719
|
+
|
|
720
|
+
## Support Resources
|
|
721
|
+
|
|
722
|
+
- **GitHub Issues**: https://github.com/cakemail-org/cakemail-cli/issues
|
|
723
|
+
- **Documentation**: https://docs.cakemail.com
|
|
724
|
+
- **Support Email**: support@cakemail.com
|
|
725
|
+
- **Status Page**: https://status.cakemail.com
|