@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.
Files changed (198) 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 +41 -37
  6. package/audit-formats.js +128 -0
  7. package/cakemail.rb +20 -0
  8. package/dist/client.js +1 -1
  9. package/dist/client.js.map +1 -1
  10. package/dist/commands/account.js +1 -1
  11. package/dist/commands/account.js.map +1 -1
  12. package/dist/commands/attributes.js +1 -1
  13. package/dist/commands/attributes.js.map +1 -1
  14. package/dist/commands/campaigns.js +1 -1
  15. package/dist/commands/campaigns.js.map +1 -1
  16. package/dist/commands/contacts.js +1 -1
  17. package/dist/commands/contacts.js.map +1 -1
  18. package/dist/commands/emails.js +1 -1
  19. package/dist/commands/emails.js.map +1 -1
  20. package/dist/commands/interests.js +1 -1
  21. package/dist/commands/interests.js.map +1 -1
  22. package/dist/commands/lists.js +1 -1
  23. package/dist/commands/lists.js.map +1 -1
  24. package/dist/commands/logs.js +1 -1
  25. package/dist/commands/logs.js.map +1 -1
  26. package/dist/commands/reports.js +1 -1
  27. package/dist/commands/reports.js.map +1 -1
  28. package/dist/commands/segments.js +1 -1
  29. package/dist/commands/segments.js.map +1 -1
  30. package/dist/commands/senders.js +1 -1
  31. package/dist/commands/senders.js.map +1 -1
  32. package/dist/commands/suppressed.js +1 -1
  33. package/dist/commands/suppressed.js.map +1 -1
  34. package/dist/commands/tags.js +1 -1
  35. package/dist/commands/tags.js.map +1 -1
  36. package/dist/commands/templates.js +1 -1
  37. package/dist/commands/templates.js.map +1 -1
  38. package/dist/commands/transactional-templates.js +1 -1
  39. package/dist/commands/transactional-templates.js.map +1 -1
  40. package/dist/commands/webhooks.js +1 -1
  41. package/dist/commands/webhooks.js.map +1 -1
  42. package/dist/utils/config.js +2 -2
  43. package/dist/utils/config.js.map +1 -1
  44. package/dist/utils/errors.js +1 -1
  45. package/dist/utils/errors.js.map +1 -1
  46. package/dist/utils/progress.d.ts.map +1 -1
  47. package/dist/utils/progress.js +32 -4
  48. package/dist/utils/progress.js.map +1 -1
  49. package/dist/utils/spinner.d.ts +17 -0
  50. package/dist/utils/spinner.d.ts.map +1 -0
  51. package/dist/utils/spinner.js +43 -0
  52. package/dist/utils/spinner.js.map +1 -0
  53. package/docs/DOCUMENTATION-STANDARD.md +1068 -0
  54. package/docs/README.md +161 -0
  55. package/docs/developer/ARCHITECTURE.md +516 -0
  56. package/docs/developer/AUTH.md +204 -0
  57. package/docs/developer/CONTRIBUTING.md +227 -0
  58. package/docs/developer/DOCUMENTATION_SUMMARY.md +346 -0
  59. package/docs/developer/PROJECT_INDEX.md +365 -0
  60. package/docs/planning/API_COVERAGE.md +1045 -0
  61. package/docs/planning/BACKLOG.md +1159 -0
  62. package/docs/planning/PROFILE_SYSTEM_TASKS.md +287 -0
  63. package/docs/planning/UX_IMPLEMENTATION_PLAN.md +691 -0
  64. package/docs/planning/archive/RELEASE_CHECKLIST_v1.3.0.md +332 -0
  65. package/docs/planning/archive/RELEASE_v1.3.0.md +428 -0
  66. package/docs/planning/archive/cakemail-cli-ux-improvements.md +438 -0
  67. package/docs/planning/cakemail-profile-system-plan.md +1121 -0
  68. package/docs/testing/AI_USER_SIMULATION_DESIGN.md +1342 -0
  69. package/docs/testing/KENOGAMI_BIDIRECTIONAL_FLOW.md +1517 -0
  70. package/docs/testing/KENOGAMI_TRUTH_RECONCILIATION_SYSTEM.md +1369 -0
  71. package/docs/user-manual/.obsidian/app.json +1 -0
  72. package/docs/user-manual/.obsidian/appearance.json +1 -0
  73. package/docs/user-manual/.obsidian/core-plugins.json +33 -0
  74. package/docs/user-manual/.obsidian/workspace.json +167 -0
  75. package/docs/user-manual/01-getting-started/01-installation.md +214 -0
  76. package/docs/user-manual/01-getting-started/02-quick-start.md +432 -0
  77. package/docs/user-manual/01-getting-started/03-authentication.md +448 -0
  78. package/docs/user-manual/01-getting-started/04-configuration.md +430 -0
  79. package/docs/user-manual/01-getting-started/05-output-formats.md +447 -0
  80. package/docs/user-manual/02-core-concepts/01-accounts.md +514 -0
  81. package/docs/user-manual/02-core-concepts/02-profile-system.md +771 -0
  82. package/docs/user-manual/02-core-concepts/03-smart-defaults.md +485 -0
  83. package/docs/user-manual/02-core-concepts/04-authentication-methods.md +435 -0
  84. package/docs/user-manual/02-core-concepts/05-pagination-filtering.md +600 -0
  85. package/docs/user-manual/02-core-concepts/06-error-handling.md +718 -0
  86. package/docs/user-manual/02-core-concepts/07-api-coverage.md +483 -0
  87. package/docs/user-manual/03-email-operations/01-senders.md +490 -0
  88. package/docs/user-manual/03-email-operations/02-templates.md +444 -0
  89. package/docs/user-manual/03-email-operations/03-transactional-emails.md +706 -0
  90. package/docs/user-manual/03-email-operations/04-email-tracking.md +407 -0
  91. package/docs/user-manual/04-campaign-management/01-campaigns-basics.md +394 -0
  92. package/docs/user-manual/04-campaign-management/02-campaign-scheduling.md +630 -0
  93. package/docs/user-manual/04-campaign-management/03-campaign-testing.md +997 -0
  94. package/docs/user-manual/04-campaign-management/04-campaign-lifecycle.md +709 -0
  95. package/docs/user-manual/04-campaign-management/05-campaign-links.md +934 -0
  96. package/docs/user-manual/05-contact-management/01-lists.md +836 -0
  97. package/docs/user-manual/05-contact-management/02-contacts.md +1035 -0
  98. package/docs/user-manual/05-contact-management/03-custom-attributes.md +788 -0
  99. package/docs/user-manual/05-contact-management/04-segments.md +1028 -0
  100. package/docs/user-manual/05-contact-management/05-contact-import-export.md +1031 -0
  101. package/docs/user-manual/06-analytics-reporting/01-campaign-analytics.md +867 -0
  102. package/docs/user-manual/06-analytics-reporting/02-account-reports.md +227 -0
  103. package/docs/user-manual/07-integrations/01-webhooks-integration.md +259 -0
  104. package/docs/user-manual/07-integrations/02-automation.md +326 -0
  105. package/docs/user-manual/08-advanced-usage/01-scripting-patterns.md +672 -0
  106. package/docs/user-manual/08-advanced-usage/02-bulk-operations.md +932 -0
  107. package/docs/user-manual/08-advanced-usage/03-ci-cd-integration.md +892 -0
  108. package/docs/user-manual/08-advanced-usage/04-performance-optimization.md +766 -0
  109. package/docs/user-manual/09-command-reference/01-config.md +776 -0
  110. package/docs/user-manual/09-command-reference/02-account.md +652 -0
  111. package/docs/user-manual/09-command-reference/03-lists.md +958 -0
  112. package/docs/user-manual/09-command-reference/04-contacts.md +1408 -0
  113. package/docs/user-manual/09-command-reference/05-attributes.md +617 -0
  114. package/docs/user-manual/09-command-reference/06-segments.md +894 -0
  115. package/docs/user-manual/09-command-reference/07-senders.md +803 -0
  116. package/docs/user-manual/09-command-reference/08-templates.md +818 -0
  117. package/docs/user-manual/09-command-reference/09-campaigns.md +1250 -0
  118. package/docs/user-manual/09-command-reference/10-emails.md +807 -0
  119. package/docs/user-manual/09-command-reference/11-reports.md +1135 -0
  120. package/docs/user-manual/09-command-reference/12-webhooks.md +773 -0
  121. package/docs/user-manual/09-command-reference/13-suppressed.md +797 -0
  122. package/docs/user-manual/09-command-reference/14-interests.md +630 -0
  123. package/docs/user-manual/09-command-reference/15-tags.md +584 -0
  124. package/docs/user-manual/09-command-reference/16-logs.md +656 -0
  125. package/docs/user-manual/09-command-reference/17-transactional-templates.md +850 -0
  126. package/docs/user-manual/10-troubleshooting/01-common-errors.md +457 -0
  127. package/docs/user-manual/10-troubleshooting/02-authentication-issues.md +558 -0
  128. package/docs/user-manual/10-troubleshooting/03-connection-problems.md +634 -0
  129. package/docs/user-manual/10-troubleshooting/04-debugging.md +725 -0
  130. package/docs/user-manual/11-appendix/04-faq.md +484 -0
  131. package/docs/user-manual/11-appendix/05-glossary.md +250 -0
  132. package/docs/user-manual/README.md +0 -0
  133. package/package.json +13 -61
  134. package/src/cli.ts +125 -0
  135. package/src/client.ts +16 -0
  136. package/src/commands/account.ts +267 -0
  137. package/src/commands/accounts.ts +78 -0
  138. package/src/commands/actions.ts +249 -0
  139. package/src/commands/attributes.ts +139 -0
  140. package/src/commands/campaign-blueprints.ts +106 -0
  141. package/src/commands/campaigns.ts +469 -0
  142. package/src/commands/config.ts +77 -0
  143. package/src/commands/contacts.ts +612 -0
  144. package/src/commands/custom-attributes.ts +127 -0
  145. package/src/commands/dkims.ts +117 -0
  146. package/src/commands/domains.ts +82 -0
  147. package/src/commands/email-apis.ts +569 -0
  148. package/src/commands/emails.ts +197 -0
  149. package/src/commands/forms.ts +283 -0
  150. package/src/commands/interests.ts +155 -0
  151. package/src/commands/links.ts +38 -0
  152. package/src/commands/lists.ts +406 -0
  153. package/src/commands/logos.ts +71 -0
  154. package/src/commands/logs.ts +386 -0
  155. package/src/commands/reports.ts +306 -0
  156. package/src/commands/segments.ts +158 -0
  157. package/src/commands/senders.ts +204 -0
  158. package/src/commands/sub-accounts.ts +271 -0
  159. package/src/commands/suppressed-emails.ts +234 -0
  160. package/src/commands/suppressed.ts +198 -0
  161. package/src/commands/system-emails.ts +85 -0
  162. package/src/commands/tags.ts +146 -0
  163. package/src/commands/tasks.ts +116 -0
  164. package/src/commands/templates.ts +189 -0
  165. package/src/commands/tokens.ts +83 -0
  166. package/src/commands/transactional-emails.ts +374 -0
  167. package/src/commands/transactional-templates.ts +385 -0
  168. package/src/commands/users.ts +506 -0
  169. package/src/commands/webhooks.ts +172 -0
  170. package/src/commands/workflow-blueprints.ts +123 -0
  171. package/src/commands/workflows.ts +265 -0
  172. package/src/types/profile.ts +93 -0
  173. package/src/utils/auth.ts +272 -0
  174. package/src/utils/config-file.ts +96 -0
  175. package/src/utils/config.ts +134 -0
  176. package/src/utils/confirm.ts +32 -0
  177. package/src/utils/defaults.ts +99 -0
  178. package/src/utils/errors.ts +116 -0
  179. package/src/utils/interactive.ts +91 -0
  180. package/src/utils/list-defaults.ts +74 -0
  181. package/src/utils/output.ts +190 -0
  182. package/src/utils/progress.ts +320 -0
  183. package/src/utils/spinner.ts +22 -0
  184. package/tests/IMPLEMENTATION_STATUS.md +258 -0
  185. package/tests/PTY_SETUP.md +118 -0
  186. package/tests/PTY_TESTING_GUIDE.md +507 -0
  187. package/tests/README.md +244 -0
  188. package/tests/fixtures/api-responses/campaigns.json +34 -0
  189. package/tests/fixtures/test-config.json +13 -0
  190. package/tests/helpers/cli-runner.ts +128 -0
  191. package/tests/helpers/mock-server.ts +301 -0
  192. package/tests/helpers/pty-runner.ts +181 -0
  193. package/tests/integration/campaigns-real-api.test.ts +196 -0
  194. package/tests/integration/setup-integration.ts +50 -0
  195. package/tests/pty/campaigns.test.ts +241 -0
  196. package/tests/setup.ts +34 -0
  197. package/tsconfig.json +15 -0
  198. package/vitest.config.ts +28 -0
@@ -0,0 +1,514 @@
1
+ # Accounts
2
+
3
+ Learn about Cakemail account management, multi-tenant access, and switching between accounts.
4
+
5
+ ## Overview
6
+
7
+ The Cakemail CLI supports managing multiple Cakemail accounts. This is useful when:
8
+
9
+ - You manage multiple businesses or brands
10
+ - You provide services to clients with separate Cakemail accounts
11
+ - You have a partner account with multiple sub-accounts
12
+ - You need to switch between development and production accounts
13
+
14
+ ## Account Types
15
+
16
+ ### Main Account
17
+
18
+ Your primary Cakemail account - the one you use to authenticate with email/password or access token.
19
+
20
+ ### Sub-Accounts
21
+
22
+ Accounts created under a partner account. Sub-accounts are separate Cakemail instances with their own:
23
+ - Contact lists
24
+ - Campaigns
25
+ - Templates
26
+ - Senders
27
+ - Analytics
28
+
29
+ **Key Features:**
30
+ - Managed from the parent account
31
+ - Can be accessed without separate credentials
32
+ - Inherit billing from parent account
33
+ - Isolated data and settings
34
+
35
+ ---
36
+
37
+ ## Account Commands
38
+
39
+ ### Show Current Account
40
+
41
+ Display details about the currently active account:
42
+
43
+ ```bash
44
+ cakemail account show
45
+ ```
46
+
47
+ **Example Output:**
48
+ ```json
49
+ {
50
+ "id": "12345",
51
+ "name": "My Marketing Account",
52
+ "email": "admin@example.com",
53
+ "created_on": "2024-01-15T10:00:00Z",
54
+ "timezone": "America/New_York",
55
+ "status": "active"
56
+ }
57
+ ```
58
+
59
+ **Current Context Indicator:**
60
+ If you've set a specific account context, it will be displayed:
61
+ ```
62
+ Current account context: 67890
63
+
64
+ {
65
+ "id": "67890",
66
+ "name": "Client Account"
67
+ }
68
+ ```
69
+
70
+ ---
71
+
72
+ ### List All Accessible Accounts
73
+
74
+ View all accounts you have access to (main account + sub-accounts):
75
+
76
+ ```bash
77
+ cakemail account list
78
+ ```
79
+
80
+ **Example Output:**
81
+ ```
82
+ Available accounts:
83
+
84
+ • My Marketing Account (ID: 12345) (current)
85
+ Client A (ID: 67890)
86
+ Client B (ID: 67891)
87
+ Development Account (ID: 67892)
88
+
89
+ Total accessible accounts: 4
90
+ ```
91
+
92
+ **Legend:**
93
+ - `•` (green bullet) - Currently active account
94
+ - `(current)` - Current account context
95
+
96
+ **Include Nested Sub-Accounts:**
97
+
98
+ ```bash
99
+ cakemail account list --recursive
100
+ ```
101
+
102
+ This includes sub-accounts of sub-accounts (nested hierarchy).
103
+
104
+ ---
105
+
106
+ ### Switch Account Context
107
+
108
+ Change which account you're working with:
109
+
110
+ ```bash
111
+ cakemail account use <account-id>
112
+ ```
113
+
114
+ **Example:**
115
+ ```bash
116
+ cakemail account use 67890
117
+ # Now using: Client A (ID: 67890)
118
+ ```
119
+
120
+ **What Happens:**
121
+ 1. Verifies the account exists and you have access
122
+ 2. Updates `.env` file with `CAKEMAIL_CURRENT_ACCOUNT_ID`
123
+ 3. All subsequent commands use the new account context
124
+
125
+ **Verify the Switch:**
126
+ ```bash
127
+ cakemail account show
128
+ ```
129
+
130
+ ---
131
+
132
+ ### Test Credentials
133
+
134
+ Validate that your current credentials are working:
135
+
136
+ ```bash
137
+ cakemail account test
138
+ ```
139
+
140
+ **Example Output (Success):**
141
+ ```
142
+ ✓ Credentials are valid
143
+
144
+ Authenticated as: admin@example.com
145
+ Account: My Marketing Account
146
+ ```
147
+
148
+ **Example Output (Failure):**
149
+ ```
150
+ ✗ Invalid credentials
151
+ ```
152
+
153
+ ---
154
+
155
+ ### Logout
156
+
157
+ Remove credentials from your `.env` file:
158
+
159
+ ```bash
160
+ cakemail account logout
161
+ ```
162
+
163
+ You'll be prompted for confirmation:
164
+ ```
165
+ Log out and remove credentials?
166
+ • Credentials will be removed from .env file
167
+ • You will need to re-authenticate
168
+
169
+ Proceed? (y/N)
170
+ ```
171
+
172
+ **Skip Confirmation:**
173
+ ```bash
174
+ cakemail account logout --force
175
+ ```
176
+
177
+ **What Gets Removed:**
178
+ - `CAKEMAIL_EMAIL`
179
+ - `CAKEMAIL_PASSWORD`
180
+ - `CAKEMAIL_ACCESS_TOKEN`
181
+ - `CAKEMAIL_CURRENT_ACCOUNT_ID`
182
+
183
+ **Note:** Other environment variables (like `CAKEMAIL_OUTPUT_FORMAT`) are preserved.
184
+
185
+ ---
186
+
187
+ ## Account Context
188
+
189
+ ### What is Account Context?
190
+
191
+ Account context determines which account's data you're working with. When you run commands, they operate on the currently active account.
192
+
193
+ ### Setting Context
194
+
195
+ **Method 1: Use Command**
196
+ ```bash
197
+ cakemail account use 67890
198
+ ```
199
+
200
+ This updates your `.env` file permanently.
201
+
202
+ **Method 2: Environment Variable**
203
+ ```bash
204
+ export CAKEMAIL_CURRENT_ACCOUNT_ID=67890
205
+ cakemail campaigns list
206
+ ```
207
+
208
+ This is temporary (current shell session only).
209
+
210
+ **Method 3: Command-Line Flag**
211
+ ```bash
212
+ cakemail --account 67890 campaigns list
213
+ ```
214
+
215
+ This overrides context for a single command.
216
+
217
+ ### Context Priority
218
+
219
+ When multiple context settings exist:
220
+
221
+ 1. **Command-line flag** (highest priority)
222
+ ```bash
223
+ cakemail --account 67890 campaigns list
224
+ ```
225
+
226
+ 2. **Environment variable**
227
+ ```bash
228
+ export CAKEMAIL_CURRENT_ACCOUNT_ID=67890
229
+ ```
230
+
231
+ 3. **`.env` file**
232
+ ```
233
+ CAKEMAIL_CURRENT_ACCOUNT_ID=67890
234
+ ```
235
+
236
+ 4. **Default** (main account)
237
+
238
+ ---
239
+
240
+ ## Multi-Account Workflows
241
+
242
+ ### Scenario 1: Managing Client Accounts
243
+
244
+ **Setup:**
245
+ ```bash
246
+ # List all accessible accounts
247
+ cakemail account list
248
+
249
+ # Available accounts:
250
+ # • My Agency (ID: 12345) (current)
251
+ # Client A (ID: 67890)
252
+ # Client B (ID: 67891)
253
+ ```
254
+
255
+ **Working with Client A:**
256
+ ```bash
257
+ # Switch to Client A
258
+ cakemail account use 67890
259
+
260
+ # All commands now operate on Client A's account
261
+ cakemail campaigns list
262
+ cakemail contacts list 123
263
+ cakemail reports account
264
+ ```
265
+
266
+ **Quick Check of Client B (without switching):**
267
+ ```bash
268
+ # Use --account flag for one-off command
269
+ cakemail --account 67891 reports account
270
+ ```
271
+
272
+ **Switch Back to Agency Account:**
273
+ ```bash
274
+ cakemail account use 12345
275
+ ```
276
+
277
+ ---
278
+
279
+ ### Scenario 2: Development vs Production
280
+
281
+ **Setup:**
282
+ ```bash
283
+ # Create separate .env files
284
+ # .env.development
285
+ CAKEMAIL_CURRENT_ACCOUNT_ID=11111
286
+
287
+ # .env.production
288
+ CAKEMAIL_CURRENT_ACCOUNT_ID=22222
289
+ ```
290
+
291
+ **Use Development:**
292
+ ```bash
293
+ cp .env.development .env
294
+ cakemail campaigns list # Development data
295
+ ```
296
+
297
+ **Use Production:**
298
+ ```bash
299
+ cp .env.production .env
300
+ cakemail campaigns list # Production data
301
+ ```
302
+
303
+ ---
304
+
305
+ ### Scenario 3: Scripted Multi-Account Operations
306
+
307
+ **Bash Script Example:**
308
+ ```bash
309
+ #!/bin/bash
310
+ # Report on all accessible accounts
311
+
312
+ # Get list of account IDs
313
+ ACCOUNTS=(12345 67890 67891)
314
+
315
+ for ACCOUNT_ID in "${ACCOUNTS[@]}"; do
316
+ echo "=== Account $ACCOUNT_ID ==="
317
+ cakemail --account "$ACCOUNT_ID" reports account
318
+ echo ""
319
+ done
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Account Hierarchy
325
+
326
+ ### Parent-Child Relationship
327
+
328
+ ```
329
+ Main Account (12345)
330
+ ├── Sub-Account A (67890)
331
+ ├── Sub-Account B (67891)
332
+ └── Sub-Account C (67892)
333
+ ├── Nested Sub-Account C1 (78901)
334
+ └── Nested Sub-Account C2 (78902)
335
+ ```
336
+
337
+ **Access Levels:**
338
+ - **Main Account**: Can access all sub-accounts
339
+ - **Sub-Account**: Can only access itself (unless it's a partner)
340
+
341
+ **List with Recursion:**
342
+ ```bash
343
+ # Shows all accounts including nested
344
+ cakemail account list --recursive
345
+
346
+ # Shows only direct children
347
+ cakemail account list
348
+ ```
349
+
350
+ ---
351
+
352
+ ## Best Practices
353
+
354
+ ### 1. Use Descriptive Account Names
355
+
356
+ When creating sub-accounts, use clear names:
357
+ - ✅ "Client A - Marketing"
358
+ - ✅ "Production Environment"
359
+ - ❌ "Account 1"
360
+ - ❌ "Test"
361
+
362
+ ### 2. Document Account IDs
363
+
364
+ Keep a reference document with account IDs and purposes:
365
+ ```
366
+ # accounts.txt
367
+ 12345 - Main Agency Account
368
+ 67890 - Client A (Acme Corp)
369
+ 67891 - Client B (Widget Inc)
370
+ 67892 - Development/Testing
371
+ ```
372
+
373
+ ### 3. Use Project-Specific Context
374
+
375
+ For project-specific work, set context in project `.env`:
376
+ ```bash
377
+ # project-client-a/.env
378
+ CAKEMAIL_CURRENT_ACCOUNT_ID=67890
379
+ ```
380
+
381
+ ### 4. Verify Context Before Destructive Operations
382
+
383
+ Always check which account you're using before:
384
+ - Deleting campaigns
385
+ - Removing contacts
386
+ - Changing configurations
387
+
388
+ ```bash
389
+ # Check current account
390
+ cakemail account show
391
+
392
+ # Then perform operation
393
+ cakemail campaigns delete 123 --force
394
+ ```
395
+
396
+ ### 5. Use Account Flag for One-Off Commands
397
+
398
+ Instead of switching context, use `--account` flag:
399
+ ```bash
400
+ # Quick check without switching
401
+ cakemail --account 67890 campaigns list
402
+
403
+ # Current context remains unchanged
404
+ ```
405
+
406
+ ---
407
+
408
+ ## Common Patterns
409
+
410
+ ### Pattern 1: Daily Multi-Account Check
411
+
412
+ ```bash
413
+ #!/bin/bash
414
+ # daily-check.sh
415
+
416
+ for ACCOUNT in 12345 67890 67891; do
417
+ echo "=== Account $ACCOUNT ==="
418
+
419
+ # Get account name
420
+ NAME=$(cakemail --account "$ACCOUNT" account show | jq -r '.name')
421
+ echo "Account: $NAME"
422
+
423
+ # Check campaigns scheduled today
424
+ TODAY=$(date -u +"%Y-%m-%d")
425
+ cakemail --account "$ACCOUNT" campaigns list --filter "scheduled_for>=$TODAY"
426
+
427
+ echo ""
428
+ done
429
+ ```
430
+
431
+ ### Pattern 2: Report Generation Across Accounts
432
+
433
+ ```bash
434
+ #!/bin/bash
435
+ # generate-reports.sh
436
+
437
+ ACCOUNTS=(12345 67890 67891)
438
+ OUTPUT_DIR="reports/$(date +%Y-%m-%d)"
439
+ mkdir -p "$OUTPUT_DIR"
440
+
441
+ for ACCOUNT in "${ACCOUNTS[@]}"; do
442
+ echo "Generating report for account $ACCOUNT..."
443
+
444
+ cakemail --account "$ACCOUNT" -f json reports account \
445
+ > "$OUTPUT_DIR/account-$ACCOUNT.json"
446
+ done
447
+
448
+ echo "Reports saved to $OUTPUT_DIR"
449
+ ```
450
+
451
+ ### Pattern 3: Bulk Contact Import
452
+
453
+ ```bash
454
+ #!/bin/bash
455
+ # bulk-import.sh
456
+
457
+ # Import contacts to multiple accounts
458
+ ACCOUNTS=(67890 67891)
459
+ CSV_FILE="contacts.csv"
460
+
461
+ for ACCOUNT in "${ACCOUNTS[@]}"; do
462
+ echo "Importing to account $ACCOUNT..."
463
+ cakemail --account "$ACCOUNT" contacts import "$CSV_FILE"
464
+ done
465
+ ```
466
+
467
+ ---
468
+
469
+ ## Troubleshooting
470
+
471
+ ### "Account not found or not accessible"
472
+
473
+ **Cause:** You're trying to switch to an account that doesn't exist or you don't have access to.
474
+
475
+ **Solutions:**
476
+ 1. List accessible accounts:
477
+ ```bash
478
+ cakemail account list --recursive
479
+ ```
480
+ 2. Verify the account ID is correct
481
+ 3. Check that you're authenticated with the right credentials
482
+
483
+ ---
484
+
485
+ ### Commands Use Wrong Account
486
+
487
+ **Cause:** Account context is set to a different account than you expect.
488
+
489
+ **Solutions:**
490
+ 1. Check current context:
491
+ ```bash
492
+ cakemail account show
493
+ ```
494
+ 2. Check `.env` file for `CAKEMAIL_CURRENT_ACCOUNT_ID`
495
+ 3. Clear context to use main account:
496
+ ```bash
497
+ # Remove from .env
498
+ grep -v "CAKEMAIL_CURRENT_ACCOUNT_ID" .env > .env.tmp
499
+ mv .env.tmp .env
500
+ ```
501
+
502
+ ---
503
+
504
+ ### Can't See Sub-Accounts
505
+
506
+ **Cause:** Your account might not be a partner account or doesn't have sub-accounts.
507
+
508
+ **Solutions:**
509
+ 1. Verify account type in Cakemail dashboard
510
+ 2. Check if you need partner account privileges
511
+ 3. Contact Cakemail support to enable sub-account features
512
+
513
+ ---
514
+