@cakemail-org/cakemail-cli 1.5.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.
Files changed (234) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.env.example +40 -0
  3. package/.env.test.example +45 -0
  4. package/CHANGELOG.md +1031 -0
  5. package/README.md +319 -15
  6. package/audit-formats.js +128 -0
  7. package/cakemail.rb +20 -0
  8. package/dist/cli.js +27 -10
  9. package/dist/cli.js.map +1 -1
  10. package/dist/client.d.ts +2 -0
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +16 -6
  13. package/dist/client.js.map +1 -1
  14. package/dist/commands/account.js +1 -1
  15. package/dist/commands/account.js.map +1 -1
  16. package/dist/commands/attributes.js +1 -1
  17. package/dist/commands/attributes.js.map +1 -1
  18. package/dist/commands/campaigns.d.ts.map +1 -1
  19. package/dist/commands/campaigns.js +103 -8
  20. package/dist/commands/campaigns.js.map +1 -1
  21. package/dist/commands/config.d.ts.map +1 -1
  22. package/dist/commands/config.js +63 -4
  23. package/dist/commands/config.js.map +1 -1
  24. package/dist/commands/contacts.d.ts.map +1 -1
  25. package/dist/commands/contacts.js +91 -12
  26. package/dist/commands/contacts.js.map +1 -1
  27. package/dist/commands/emails.js +1 -1
  28. package/dist/commands/emails.js.map +1 -1
  29. package/dist/commands/interests.d.ts +5 -0
  30. package/dist/commands/interests.d.ts.map +1 -0
  31. package/dist/commands/interests.js +172 -0
  32. package/dist/commands/interests.js.map +1 -0
  33. package/dist/commands/lists.d.ts.map +1 -1
  34. package/dist/commands/lists.js +6 -8
  35. package/dist/commands/lists.js.map +1 -1
  36. package/dist/commands/logs.d.ts +5 -0
  37. package/dist/commands/logs.d.ts.map +1 -0
  38. package/dist/commands/logs.js +237 -0
  39. package/dist/commands/logs.js.map +1 -0
  40. package/dist/commands/reports.js +1 -1
  41. package/dist/commands/reports.js.map +1 -1
  42. package/dist/commands/segments.js +1 -1
  43. package/dist/commands/segments.js.map +1 -1
  44. package/dist/commands/senders.d.ts.map +1 -1
  45. package/dist/commands/senders.js +11 -8
  46. package/dist/commands/senders.js.map +1 -1
  47. package/dist/commands/suppressed.js +1 -1
  48. package/dist/commands/suppressed.js.map +1 -1
  49. package/dist/commands/tags.d.ts +5 -0
  50. package/dist/commands/tags.d.ts.map +1 -0
  51. package/dist/commands/tags.js +124 -0
  52. package/dist/commands/tags.js.map +1 -0
  53. package/dist/commands/templates.js +1 -1
  54. package/dist/commands/templates.js.map +1 -1
  55. package/dist/commands/transactional-templates.d.ts +5 -0
  56. package/dist/commands/transactional-templates.d.ts.map +1 -0
  57. package/dist/commands/transactional-templates.js +354 -0
  58. package/dist/commands/transactional-templates.js.map +1 -0
  59. package/dist/commands/webhooks.js +1 -1
  60. package/dist/commands/webhooks.js.map +1 -1
  61. package/dist/utils/auth.d.ts +8 -1
  62. package/dist/utils/auth.d.ts.map +1 -1
  63. package/dist/utils/auth.js +39 -11
  64. package/dist/utils/auth.js.map +1 -1
  65. package/dist/utils/config-file.d.ts +7 -0
  66. package/dist/utils/config-file.d.ts.map +1 -1
  67. package/dist/utils/config-file.js +15 -0
  68. package/dist/utils/config-file.js.map +1 -1
  69. package/dist/utils/config.d.ts +2 -0
  70. package/dist/utils/config.d.ts.map +1 -1
  71. package/dist/utils/config.js +12 -4
  72. package/dist/utils/config.js.map +1 -1
  73. package/dist/utils/errors.js +1 -1
  74. package/dist/utils/errors.js.map +1 -1
  75. package/dist/utils/list-defaults.d.ts +33 -0
  76. package/dist/utils/list-defaults.d.ts.map +1 -0
  77. package/dist/utils/list-defaults.js +52 -0
  78. package/dist/utils/list-defaults.js.map +1 -0
  79. package/dist/utils/output.d.ts.map +1 -1
  80. package/dist/utils/output.js +36 -13
  81. package/dist/utils/output.js.map +1 -1
  82. package/dist/utils/progress.d.ts.map +1 -1
  83. package/dist/utils/progress.js +32 -4
  84. package/dist/utils/progress.js.map +1 -1
  85. package/dist/utils/spinner.d.ts +17 -0
  86. package/dist/utils/spinner.d.ts.map +1 -0
  87. package/dist/utils/spinner.js +43 -0
  88. package/dist/utils/spinner.js.map +1 -0
  89. package/docs/DOCUMENTATION-STANDARD.md +1068 -0
  90. package/docs/README.md +161 -0
  91. package/docs/developer/ARCHITECTURE.md +516 -0
  92. package/docs/developer/AUTH.md +204 -0
  93. package/docs/developer/CONTRIBUTING.md +227 -0
  94. package/docs/developer/DOCUMENTATION_SUMMARY.md +346 -0
  95. package/docs/developer/PROJECT_INDEX.md +365 -0
  96. package/docs/planning/API_COVERAGE.md +1045 -0
  97. package/docs/planning/BACKLOG.md +1159 -0
  98. package/docs/planning/PROFILE_SYSTEM_TASKS.md +287 -0
  99. package/docs/planning/UX_IMPLEMENTATION_PLAN.md +691 -0
  100. package/docs/planning/archive/RELEASE_CHECKLIST_v1.3.0.md +332 -0
  101. package/docs/planning/archive/RELEASE_v1.3.0.md +428 -0
  102. package/docs/planning/archive/cakemail-cli-ux-improvements.md +438 -0
  103. package/docs/planning/cakemail-profile-system-plan.md +1121 -0
  104. package/docs/testing/AI_USER_SIMULATION_DESIGN.md +1342 -0
  105. package/docs/testing/KENOGAMI_BIDIRECTIONAL_FLOW.md +1517 -0
  106. package/docs/testing/KENOGAMI_TRUTH_RECONCILIATION_SYSTEM.md +1369 -0
  107. package/docs/user-manual/.obsidian/app.json +1 -0
  108. package/docs/user-manual/.obsidian/appearance.json +1 -0
  109. package/docs/user-manual/.obsidian/core-plugins.json +33 -0
  110. package/docs/user-manual/.obsidian/workspace.json +167 -0
  111. package/docs/user-manual/01-getting-started/01-installation.md +214 -0
  112. package/docs/user-manual/01-getting-started/02-quick-start.md +432 -0
  113. package/docs/user-manual/01-getting-started/03-authentication.md +448 -0
  114. package/docs/user-manual/01-getting-started/04-configuration.md +430 -0
  115. package/docs/user-manual/01-getting-started/05-output-formats.md +447 -0
  116. package/docs/user-manual/02-core-concepts/01-accounts.md +514 -0
  117. package/docs/user-manual/02-core-concepts/02-profile-system.md +771 -0
  118. package/docs/user-manual/02-core-concepts/03-smart-defaults.md +485 -0
  119. package/docs/user-manual/02-core-concepts/04-authentication-methods.md +435 -0
  120. package/docs/user-manual/02-core-concepts/05-pagination-filtering.md +600 -0
  121. package/docs/user-manual/02-core-concepts/06-error-handling.md +718 -0
  122. package/docs/user-manual/02-core-concepts/07-api-coverage.md +483 -0
  123. package/docs/user-manual/03-email-operations/01-senders.md +490 -0
  124. package/docs/user-manual/03-email-operations/02-templates.md +444 -0
  125. package/docs/user-manual/03-email-operations/03-transactional-emails.md +706 -0
  126. package/docs/user-manual/03-email-operations/04-email-tracking.md +407 -0
  127. package/docs/user-manual/04-campaign-management/01-campaigns-basics.md +394 -0
  128. package/docs/user-manual/04-campaign-management/02-campaign-scheduling.md +630 -0
  129. package/docs/user-manual/04-campaign-management/03-campaign-testing.md +997 -0
  130. package/docs/user-manual/04-campaign-management/04-campaign-lifecycle.md +709 -0
  131. package/docs/user-manual/04-campaign-management/05-campaign-links.md +934 -0
  132. package/docs/user-manual/05-contact-management/01-lists.md +836 -0
  133. package/docs/user-manual/05-contact-management/02-contacts.md +1035 -0
  134. package/docs/user-manual/05-contact-management/03-custom-attributes.md +788 -0
  135. package/docs/user-manual/05-contact-management/04-segments.md +1028 -0
  136. package/docs/user-manual/05-contact-management/05-contact-import-export.md +1031 -0
  137. package/docs/user-manual/06-analytics-reporting/01-campaign-analytics.md +867 -0
  138. package/docs/user-manual/06-analytics-reporting/02-account-reports.md +227 -0
  139. package/docs/user-manual/07-integrations/01-webhooks-integration.md +259 -0
  140. package/docs/user-manual/07-integrations/02-automation.md +326 -0
  141. package/docs/user-manual/08-advanced-usage/01-scripting-patterns.md +672 -0
  142. package/docs/user-manual/08-advanced-usage/02-bulk-operations.md +932 -0
  143. package/docs/user-manual/08-advanced-usage/03-ci-cd-integration.md +892 -0
  144. package/docs/user-manual/08-advanced-usage/04-performance-optimization.md +766 -0
  145. package/docs/user-manual/09-command-reference/01-config.md +776 -0
  146. package/docs/user-manual/09-command-reference/02-account.md +652 -0
  147. package/docs/user-manual/09-command-reference/03-lists.md +958 -0
  148. package/docs/user-manual/09-command-reference/04-contacts.md +1408 -0
  149. package/docs/user-manual/09-command-reference/05-attributes.md +617 -0
  150. package/docs/user-manual/09-command-reference/06-segments.md +894 -0
  151. package/docs/user-manual/09-command-reference/07-senders.md +803 -0
  152. package/docs/user-manual/09-command-reference/08-templates.md +818 -0
  153. package/docs/user-manual/09-command-reference/09-campaigns.md +1250 -0
  154. package/docs/user-manual/09-command-reference/10-emails.md +807 -0
  155. package/docs/user-manual/09-command-reference/11-reports.md +1135 -0
  156. package/docs/user-manual/09-command-reference/12-webhooks.md +773 -0
  157. package/docs/user-manual/09-command-reference/13-suppressed.md +797 -0
  158. package/docs/user-manual/09-command-reference/14-interests.md +630 -0
  159. package/docs/user-manual/09-command-reference/15-tags.md +584 -0
  160. package/docs/user-manual/09-command-reference/16-logs.md +656 -0
  161. package/docs/user-manual/09-command-reference/17-transactional-templates.md +850 -0
  162. package/docs/user-manual/10-troubleshooting/01-common-errors.md +457 -0
  163. package/docs/user-manual/10-troubleshooting/02-authentication-issues.md +558 -0
  164. package/docs/user-manual/10-troubleshooting/03-connection-problems.md +634 -0
  165. package/docs/user-manual/10-troubleshooting/04-debugging.md +725 -0
  166. package/docs/user-manual/11-appendix/04-faq.md +484 -0
  167. package/docs/user-manual/11-appendix/05-glossary.md +250 -0
  168. package/docs/user-manual/README.md +0 -0
  169. package/package.json +13 -47
  170. package/src/cli.ts +125 -0
  171. package/src/client.ts +16 -0
  172. package/src/commands/account.ts +267 -0
  173. package/src/commands/accounts.ts +78 -0
  174. package/src/commands/actions.ts +249 -0
  175. package/src/commands/attributes.ts +139 -0
  176. package/src/commands/campaign-blueprints.ts +106 -0
  177. package/src/commands/campaigns.ts +469 -0
  178. package/src/commands/config.ts +77 -0
  179. package/src/commands/contacts.ts +612 -0
  180. package/src/commands/custom-attributes.ts +127 -0
  181. package/src/commands/dkims.ts +117 -0
  182. package/src/commands/domains.ts +82 -0
  183. package/src/commands/email-apis.ts +569 -0
  184. package/src/commands/emails.ts +197 -0
  185. package/src/commands/forms.ts +283 -0
  186. package/src/commands/interests.ts +155 -0
  187. package/src/commands/links.ts +38 -0
  188. package/src/commands/lists.ts +406 -0
  189. package/src/commands/logos.ts +71 -0
  190. package/src/commands/logs.ts +386 -0
  191. package/src/commands/reports.ts +306 -0
  192. package/src/commands/segments.ts +158 -0
  193. package/src/commands/senders.ts +204 -0
  194. package/src/commands/sub-accounts.ts +271 -0
  195. package/src/commands/suppressed-emails.ts +234 -0
  196. package/src/commands/suppressed.ts +198 -0
  197. package/src/commands/system-emails.ts +85 -0
  198. package/src/commands/tags.ts +146 -0
  199. package/src/commands/tasks.ts +116 -0
  200. package/src/commands/templates.ts +189 -0
  201. package/src/commands/tokens.ts +83 -0
  202. package/src/commands/transactional-emails.ts +374 -0
  203. package/src/commands/transactional-templates.ts +385 -0
  204. package/src/commands/users.ts +506 -0
  205. package/src/commands/webhooks.ts +172 -0
  206. package/src/commands/workflow-blueprints.ts +123 -0
  207. package/src/commands/workflows.ts +265 -0
  208. package/src/types/profile.ts +93 -0
  209. package/src/utils/auth.ts +272 -0
  210. package/src/utils/config-file.ts +96 -0
  211. package/src/utils/config.ts +134 -0
  212. package/src/utils/confirm.ts +32 -0
  213. package/src/utils/defaults.ts +99 -0
  214. package/src/utils/errors.ts +116 -0
  215. package/src/utils/interactive.ts +91 -0
  216. package/src/utils/list-defaults.ts +74 -0
  217. package/src/utils/output.ts +190 -0
  218. package/src/utils/progress.ts +320 -0
  219. package/src/utils/spinner.ts +22 -0
  220. package/tests/IMPLEMENTATION_STATUS.md +258 -0
  221. package/tests/PTY_SETUP.md +118 -0
  222. package/tests/PTY_TESTING_GUIDE.md +507 -0
  223. package/tests/README.md +244 -0
  224. package/tests/fixtures/api-responses/campaigns.json +34 -0
  225. package/tests/fixtures/test-config.json +13 -0
  226. package/tests/helpers/cli-runner.ts +128 -0
  227. package/tests/helpers/mock-server.ts +301 -0
  228. package/tests/helpers/pty-runner.ts +181 -0
  229. package/tests/integration/campaigns-real-api.test.ts +196 -0
  230. package/tests/integration/setup-integration.ts +50 -0
  231. package/tests/pty/campaigns.test.ts +241 -0
  232. package/tests/setup.ts +34 -0
  233. package/tsconfig.json +15 -0
  234. package/vitest.config.ts +28 -0
@@ -0,0 +1,718 @@
1
+ # Error Handling
2
+
3
+ Understand error messages, HTTP status codes, and how to troubleshoot issues with the Cakemail CLI.
4
+
5
+ ## Overview
6
+
7
+ The Cakemail CLI provides user-friendly error messages with:
8
+ - **Clear error descriptions** - What went wrong
9
+ - **Helpful suggestions** - How to fix the issue
10
+ - **Actionable tips** - Next steps to take
11
+
12
+ Understanding errors helps you debug issues quickly and work more efficiently.
13
+
14
+ ---
15
+
16
+ ## Error Message Format
17
+
18
+ When an error occurs, you'll see a structured message:
19
+
20
+ ```
21
+ ✗ Error: Campaign not found
22
+
23
+ → Campaign 12345 doesn't exist or you don't have access
24
+
25
+ 💡 Tip:
26
+ To see all campaigns, use: cakemail campaigns list
27
+ ```
28
+
29
+ **Components:**
30
+ 1. **Error message** (red) - Brief description of the error
31
+ 2. **Suggestion** (yellow) - Specific context about what went wrong
32
+ 3. **Tip** (gray) - Helpful advice on how to resolve
33
+
34
+ ---
35
+
36
+ ## HTTP Status Codes
37
+
38
+ The CLI maps API HTTP status codes to user-friendly messages.
39
+
40
+ ### 400 - Bad Request
41
+
42
+ **What it means:** Invalid request parameters
43
+
44
+ **Example:**
45
+ ```bash
46
+ $ cakemail campaigns create -n "Test"
47
+
48
+ ✗ Error: Invalid request parameters
49
+
50
+ → Check the parameters for 'create' operation
51
+
52
+ 💡 Tip:
53
+ Use --help to see available options
54
+ ```
55
+
56
+ **Common causes:**
57
+ - Missing required parameters
58
+ - Invalid parameter values
59
+ - Malformed data (e.g., invalid JSON)
60
+
61
+ **How to fix:**
62
+ 1. Check the command syntax: `cakemail campaigns create --help`
63
+ 2. Verify all required options are provided
64
+ 3. Validate parameter values (e.g., email format, date format)
65
+
66
+ ---
67
+
68
+ ### 401 - Unauthorized
69
+
70
+ **What it means:** Authentication failed
71
+
72
+ **Example:**
73
+ ```bash
74
+ $ cakemail campaigns list
75
+
76
+ ✗ Error: Authentication failed
77
+
78
+ → Your credentials are invalid or expired
79
+
80
+ 💡 Tip:
81
+ To re-authenticate, run: cakemail account logout --force
82
+ Then run any command to authenticate again
83
+ Or check your .env file credentials
84
+ ```
85
+
86
+ **Common causes:**
87
+ - Invalid access token
88
+ - Incorrect email/password
89
+ - Expired session
90
+ - Missing credentials
91
+
92
+ **How to fix:**
93
+ 1. Verify credentials in `.env` file
94
+ 2. Test credentials: `cakemail account test`
95
+ 3. Re-authenticate:
96
+ ```bash
97
+ cakemail account logout --force
98
+ # Then run any command to authenticate again
99
+ ```
100
+ 4. Generate new access token if using token auth
101
+
102
+ ---
103
+
104
+ ### 403 - Forbidden
105
+
106
+ **What it means:** Permission denied
107
+
108
+ **Example:**
109
+ ```bash
110
+ $ cakemail campaigns delete 12345 --force
111
+
112
+ ✗ Error: Permission denied
113
+
114
+ → You don't have permission to access this campaign
115
+
116
+ 💡 Tip:
117
+ Check if campaign 12345 exists and you have access
118
+ ```
119
+
120
+ **Common causes:**
121
+ - Accessing a resource you don't own
122
+ - Insufficient account permissions
123
+ - Wrong account context
124
+
125
+ **How to fix:**
126
+ 1. Verify you're using the correct account:
127
+ ```bash
128
+ cakemail account show
129
+ ```
130
+ 2. Check if resource exists:
131
+ ```bash
132
+ cakemail campaigns get 12345
133
+ ```
134
+ 3. Switch to correct account if needed:
135
+ ```bash
136
+ cakemail account use <correct-account-id>
137
+ ```
138
+
139
+ ---
140
+
141
+ ### 404 - Not Found
142
+
143
+ **What it means:** Resource doesn't exist
144
+
145
+ **Example:**
146
+ ```bash
147
+ $ cakemail campaigns get 99999
148
+
149
+ ✗ Error: Campaign not found
150
+
151
+ → Campaign with ID '99999' doesn't exist
152
+
153
+ 💡 Tip:
154
+ To see all campaigns, use: cakemail campaigns list
155
+ ```
156
+
157
+ **Common causes:**
158
+ - Wrong resource ID
159
+ - Resource was deleted
160
+ - Typo in ID
161
+ - Wrong account context
162
+
163
+ **How to fix:**
164
+ 1. List available resources:
165
+ ```bash
166
+ cakemail campaigns list
167
+ cakemail lists list
168
+ cakemail contacts list <list-id>
169
+ ```
170
+ 2. Verify the ID is correct
171
+ 3. Check you're in the right account context
172
+
173
+ ---
174
+
175
+ ### 409 - Conflict
176
+
177
+ **What it means:** Resource already exists
178
+
179
+ **Example:**
180
+ ```bash
181
+ $ cakemail senders create -n "John" -e "john@example.com"
182
+
183
+ ✗ Error: Conflict - resource already exists
184
+
185
+ → This sender already exists or conflicts with existing data
186
+
187
+ 💡 Tip:
188
+ Try updating the existing resource instead of creating a new one
189
+ ```
190
+
191
+ **Common causes:**
192
+ - Duplicate email addresses
193
+ - Duplicate names (in some resources)
194
+ - Resource already exists
195
+
196
+ **How to fix:**
197
+ 1. Check if resource exists:
198
+ ```bash
199
+ cakemail senders list --filter "email==john@example.com"
200
+ ```
201
+ 2. Update existing resource instead:
202
+ ```bash
203
+ cakemail senders update <id> -n "John Updated"
204
+ ```
205
+
206
+ ---
207
+
208
+ ### 422 - Validation Error
209
+
210
+ **What it means:** Invalid field values
211
+
212
+ **Example:**
213
+ ```bash
214
+ $ cakemail contacts add 123 -e "invalid-email"
215
+
216
+ ✗ Error: Validation error
217
+
218
+ → email: Invalid email format
219
+ first_name: Field is required
220
+
221
+ 💡 Tip:
222
+ Check the error details above for specific field errors
223
+ ```
224
+
225
+ **Common causes:**
226
+ - Invalid email format
227
+ - Missing required fields
228
+ - Field value out of range
229
+ - Invalid date format
230
+
231
+ **How to fix:**
232
+ 1. Check error details for specific field issues
233
+ 2. Validate input formats:
234
+ - Email: `user@example.com`
235
+ - Date: `YYYY-MM-DD` (e.g., `2024-06-15`)
236
+ - JSON: Valid JSON syntax
237
+ 3. Provide all required fields
238
+
239
+ ---
240
+
241
+ ### 429 - Rate Limit Exceeded
242
+
243
+ **What it means:** Too many requests
244
+
245
+ **Example:**
246
+ ```bash
247
+ ✗ Error: Rate limit exceeded
248
+
249
+ → You're making too many requests
250
+
251
+ 💡 Tip:
252
+ Wait a moment before trying again, or reduce request frequency
253
+ ```
254
+
255
+ **Common causes:**
256
+ - Running scripts too quickly
257
+ - Multiple parallel requests
258
+ - Hitting API rate limits
259
+
260
+ **How to fix:**
261
+ 1. Add delays between requests in scripts:
262
+ ```bash
263
+ for id in $IDS; do
264
+ cakemail campaigns get $id
265
+ sleep 1 # Wait 1 second between requests
266
+ done
267
+ ```
268
+ 2. Reduce parallelism
269
+ 3. Batch operations where possible
270
+
271
+ ---
272
+
273
+ ### 500 - Server Error
274
+
275
+ **What it means:** Internal server error
276
+
277
+ **Example:**
278
+ ```bash
279
+ ✗ Error: Server error
280
+
281
+ → Something went wrong on the Cakemail server
282
+
283
+ 💡 Tip:
284
+ This is not your fault. Please try again in a few moments or contact support
285
+ ```
286
+
287
+ **Common causes:**
288
+ - Temporary server issue
289
+ - Unexpected API error
290
+ - Service degradation
291
+
292
+ **How to fix:**
293
+ 1. Wait a few minutes and retry
294
+ 2. Check Cakemail status page (if available)
295
+ 3. Contact support if persists
296
+
297
+ ---
298
+
299
+ ### 502/503 - Service Unavailable
300
+
301
+ **What it means:** API temporarily unavailable
302
+
303
+ **Example:**
304
+ ```bash
305
+ ✗ Error: Service unavailable
306
+
307
+ → The Cakemail API is temporarily down for maintenance
308
+
309
+ 💡 Tip:
310
+ Please try again later
311
+ ```
312
+
313
+ **Common causes:**
314
+ - Scheduled maintenance
315
+ - Service outage
316
+ - Network issues
317
+
318
+ **How to fix:**
319
+ 1. Wait and retry later
320
+ 2. Check Cakemail announcements
321
+ 3. Monitor status updates
322
+
323
+ ---
324
+
325
+ ## Common Error Patterns
326
+
327
+ ### Network Connection Errors
328
+
329
+ **Error:**
330
+ ```bash
331
+ ✗ Error: Network connection error
332
+
333
+ → Unable to connect to the Cakemail API
334
+
335
+ 💡 Tip:
336
+ Check your internet connection
337
+ Verify the API endpoint is correct
338
+ Check if there's a firewall blocking the connection
339
+ ```
340
+
341
+ **Causes:**
342
+ - No internet connection
343
+ - Firewall blocking requests
344
+ - VPN issues
345
+ - Incorrect API base URL
346
+
347
+ **Solutions:**
348
+ 1. Test internet: `ping api.cakemail.dev`
349
+ 2. Check firewall settings
350
+ 3. Verify `.env` file doesn't override API base URL
351
+ 4. Try different network
352
+
353
+ ---
354
+
355
+ ### Invalid Email Address
356
+
357
+ **Error:**
358
+ ```bash
359
+ ✗ Error: Invalid email address
360
+
361
+ → Please provide a valid email address
362
+
363
+ 💡 Tip:
364
+ Example: user@example.com
365
+ ```
366
+
367
+ **Causes:**
368
+ - Missing `@` symbol
369
+ - Invalid domain
370
+ - Special characters
371
+ - Spaces in email
372
+
373
+ **Solutions:**
374
+ 1. Check email format: `user@domain.com`
375
+ 2. Remove spaces and special characters
376
+ 3. Verify domain has proper TLD
377
+
378
+ ---
379
+
380
+ ### Missing Credentials
381
+
382
+ **Error:**
383
+ ```bash
384
+ ✗ Error: Missing credentials
385
+
386
+ → Authentication credentials are not configured
387
+
388
+ 💡 Tip:
389
+ Set credentials in .env file or environment variables:
390
+ CAKEMAIL_EMAIL=your@email.com
391
+ CAKEMAIL_PASSWORD=your_password
392
+
393
+ Or run any command to authenticate interactively
394
+ ```
395
+
396
+ **Causes:**
397
+ - No `.env` file
398
+ - Missing environment variables
399
+ - Typo in credential variable names
400
+
401
+ **Solutions:**
402
+ 1. Create `.env` file:
403
+ ```bash
404
+ CAKEMAIL_ACCESS_TOKEN=your_token
405
+ # OR
406
+ CAKEMAIL_EMAIL=your@email.com
407
+ CAKEMAIL_PASSWORD=your_password
408
+ ```
409
+ 2. Set environment variables:
410
+ ```bash
411
+ export CAKEMAIL_ACCESS_TOKEN=your_token
412
+ ```
413
+ 3. Run command to authenticate interactively
414
+
415
+ ---
416
+
417
+ ### Resource Not Found
418
+
419
+ **Error:**
420
+ ```bash
421
+ ✗ Error: List not found
422
+
423
+ → List 123 doesn't exist or you don't have access
424
+
425
+ 💡 Tip:
426
+ Use: cakemail lists list to see all available lists
427
+ ```
428
+
429
+ **Causes:**
430
+ - Wrong ID
431
+ - Resource deleted
432
+ - Wrong account
433
+ - Typo
434
+
435
+ **Solutions:**
436
+ 1. List resources:
437
+ ```bash
438
+ cakemail lists list
439
+ cakemail campaigns list
440
+ cakemail contacts list <list-id>
441
+ ```
442
+ 2. Verify account context:
443
+ ```bash
444
+ cakemail account show
445
+ ```
446
+ 3. Check ID for typos
447
+
448
+ ---
449
+
450
+ ## Debugging Strategies
451
+
452
+ ### 1. Check Command Syntax
453
+
454
+ Always verify command syntax first:
455
+
456
+ ```bash
457
+ # Get help for specific command
458
+ cakemail campaigns create --help
459
+ cakemail contacts add --help
460
+ ```
461
+
462
+ ### 2. Test Authentication
463
+
464
+ Verify credentials work:
465
+
466
+ ```bash
467
+ cakemail account test
468
+ cakemail account show
469
+ ```
470
+
471
+ ### 3. Verify Resource Exists
472
+
473
+ Before operating on a resource, check it exists:
474
+
475
+ ```bash
476
+ # Check campaign exists
477
+ cakemail campaigns get 12345
478
+
479
+ # Check list exists
480
+ cakemail lists get 789
481
+
482
+ # Check contact exists
483
+ cakemail contacts get <list-id> <contact-id>
484
+ ```
485
+
486
+ ### 4. Use JSON Format for Details
487
+
488
+ JSON output provides full error details:
489
+
490
+ ```bash
491
+ cakemail -f json campaigns create -n "Test"
492
+ ```
493
+
494
+ ### 5. Check Account Context
495
+
496
+ Verify you're using the correct account:
497
+
498
+ ```bash
499
+ cakemail account show
500
+ cakemail account list
501
+ ```
502
+
503
+ ### 6. Test with Simple Operations
504
+
505
+ Start with basic operations that should work:
506
+
507
+ ```bash
508
+ # List operations rarely fail
509
+ cakemail campaigns list --limit 1
510
+ cakemail lists list --limit 1
511
+ ```
512
+
513
+ ### 7. Validate Input Data
514
+
515
+ Test input values before using in commands:
516
+
517
+ ```bash
518
+ # Test email format
519
+ echo "user@example.com" | grep -E '^[^\s@]+@[^\s@]+\.[^\s@]+$'
520
+
521
+ # Test JSON syntax
522
+ echo '{"key":"value"}' | jq .
523
+
524
+ # Test date format
525
+ date -d "2024-06-15" || echo "Invalid date"
526
+ ```
527
+
528
+ ---
529
+
530
+ ## Validation Helpers
531
+
532
+ The CLI includes built-in validation for common data types:
533
+
534
+ ### Email Validation
535
+
536
+ **Valid:**
537
+ - `user@example.com`
538
+ - `john.doe@company.co.uk`
539
+ - `admin+tag@domain.com`
540
+
541
+ **Invalid:**
542
+ - `user@` (missing domain)
543
+ - `@example.com` (missing user)
544
+ - `user @example.com` (space)
545
+ - `user` (missing @)
546
+
547
+ ### ID Validation
548
+
549
+ **Valid:**
550
+ - `123`
551
+ - `456789`
552
+
553
+ **Invalid:**
554
+ - `-1` (negative)
555
+ - `0` (zero)
556
+ - `abc` (non-numeric)
557
+ - `12.5` (decimal)
558
+
559
+ ### Date Validation
560
+
561
+ **Valid:**
562
+ - `2024-06-15`
563
+ - `2024-01-01`
564
+
565
+ **Invalid:**
566
+ - `06/15/2024` (wrong format)
567
+ - `2024-6-15` (missing zero padding)
568
+ - `2024-13-01` (invalid month)
569
+ - `tomorrow` (text)
570
+
571
+ ### JSON Validation
572
+
573
+ **Valid:**
574
+ ```bash
575
+ '{"name":"John","age":30}'
576
+ '{"key":"value"}'
577
+ ```
578
+
579
+ **Invalid:**
580
+ ```bash
581
+ '{name:John}' (unquoted keys)
582
+ "{'name':'John'}" (single quotes)
583
+ '{name}' (incomplete)
584
+ ```
585
+
586
+ ---
587
+
588
+ ## Error Handling in Scripts
589
+
590
+ ### Exit Codes
591
+
592
+ The CLI returns exit codes for scripting:
593
+
594
+ - `0` - Success
595
+ - `1` - Error
596
+
597
+ **Example:**
598
+ ```bash
599
+ #!/bin/bash
600
+
601
+ if cakemail campaigns get 12345; then
602
+ echo "Campaign exists"
603
+ else
604
+ echo "Campaign not found"
605
+ exit 1
606
+ fi
607
+ ```
608
+
609
+ ### Capturing Errors
610
+
611
+ **Capture stderr:**
612
+ ```bash
613
+ ERROR=$(cakemail campaigns get 99999 2>&1)
614
+ if [ $? -ne 0 ]; then
615
+ echo "Error occurred: $ERROR"
616
+ fi
617
+ ```
618
+
619
+ **Check JSON response:**
620
+ ```bash
621
+ RESPONSE=$(cakemail -f json campaigns get 12345 2>&1)
622
+ if echo "$RESPONSE" | jq -e . > /dev/null 2>&1; then
623
+ # Valid JSON - success
624
+ echo "Success"
625
+ else
626
+ # Error occurred
627
+ echo "Error: $RESPONSE"
628
+ fi
629
+ ```
630
+
631
+ ### Retry Logic
632
+
633
+ **Simple retry:**
634
+ ```bash
635
+ MAX_RETRIES=3
636
+ RETRY=0
637
+
638
+ while [ $RETRY -lt $MAX_RETRIES ]; do
639
+ if cakemail campaigns get 12345; then
640
+ break
641
+ fi
642
+ RETRY=$((RETRY + 1))
643
+ echo "Retry $RETRY of $MAX_RETRIES..."
644
+ sleep 2
645
+ done
646
+ ```
647
+
648
+ ---
649
+
650
+ ## Getting Help
651
+
652
+ When errors persist:
653
+
654
+ 1. **Check documentation**
655
+ - This user manual
656
+ - Command help: `cakemail <command> --help`
657
+
658
+ 2. **Search existing issues**
659
+ - GitHub: https://github.com/cakemail-org/cakemail-cli/issues
660
+
661
+ 3. **Create new issue**
662
+ - Include CLI version: `cakemail --version`
663
+ - Include full error message
664
+ - Include command you ran (redact credentials)
665
+ - Include OS and Node.js version
666
+
667
+ 4. **Contact support**
668
+ - For API-related issues
669
+ - For account-specific problems
670
+
671
+ ---
672
+
673
+ ## Error Prevention Tips
674
+
675
+ ### 1. Validate Before Creating
676
+
677
+ ```bash
678
+ # Bad: Create without checking
679
+ cakemail lists create -n "Newsletter"
680
+
681
+ # Good: Check if exists first
682
+ cakemail lists list --filter "name==Newsletter" | grep Newsletter || \
683
+ cakemail lists create -n "Newsletter"
684
+ ```
685
+
686
+ ### 2. Use --help Frequently
687
+
688
+ ```bash
689
+ # Always check command syntax
690
+ cakemail campaigns create --help
691
+ ```
692
+
693
+ ### 3. Test with --limit 1
694
+
695
+ ```bash
696
+ # Test operations on small datasets
697
+ cakemail campaigns list --limit 1
698
+ ```
699
+
700
+ ### 4. Use Confirmation Flags
701
+
702
+ ```bash
703
+ # CLI prompts for confirmation on destructive operations
704
+ cakemail campaigns delete 12345
705
+
706
+ # Use --force carefully
707
+ cakemail campaigns delete 12345 --force
708
+ ```
709
+
710
+ ### 5. Keep Credentials Updated
711
+
712
+ ```bash
713
+ # Test regularly
714
+ cakemail account test
715
+ ```
716
+
717
+ ---
718
+