@cakemail-org/cakemail-cli 1.2.0 → 1.5.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/README.md +140 -0
- package/dist/cli.js +48 -6
- package/dist/cli.js.map +1 -1
- package/dist/client.js +0 -2
- package/dist/client.js.map +1 -1
- package/dist/commands/account.d.ts +5 -0
- package/dist/commands/account.d.ts.map +1 -0
- package/dist/commands/account.js +231 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/attributes.d.ts +5 -0
- package/dist/commands/attributes.d.ts.map +1 -0
- package/dist/commands/attributes.js +126 -0
- package/dist/commands/attributes.js.map +1 -0
- package/dist/commands/campaigns.d.ts.map +1 -1
- package/dist/commands/campaigns.js +153 -19
- package/dist/commands/campaigns.js.map +1 -1
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +235 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/contacts.d.ts.map +1 -1
- package/dist/commands/contacts.js +436 -14
- package/dist/commands/contacts.js.map +1 -1
- package/dist/commands/emails.d.ts.map +1 -1
- package/dist/commands/emails.js +53 -0
- package/dist/commands/emails.js.map +1 -1
- package/dist/commands/lists.d.ts.map +1 -1
- package/dist/commands/lists.js +282 -11
- package/dist/commands/lists.js.map +1 -1
- package/dist/commands/reports.d.ts +5 -0
- package/dist/commands/reports.d.ts.map +1 -0
- package/dist/commands/reports.js +334 -0
- package/dist/commands/reports.js.map +1 -0
- package/dist/commands/segments.d.ts +5 -0
- package/dist/commands/segments.d.ts.map +1 -0
- package/dist/commands/segments.js +203 -0
- package/dist/commands/segments.js.map +1 -0
- package/dist/commands/senders.d.ts.map +1 -1
- package/dist/commands/senders.js +36 -5
- package/dist/commands/senders.js.map +1 -1
- package/dist/commands/suppressed.d.ts +5 -0
- package/dist/commands/suppressed.d.ts.map +1 -0
- package/dist/commands/suppressed.js +193 -0
- package/dist/commands/suppressed.js.map +1 -0
- package/dist/commands/templates.d.ts.map +1 -1
- package/dist/commands/templates.js +11 -3
- package/dist/commands/templates.js.map +1 -1
- package/dist/types/profile.d.ts +92 -0
- package/dist/types/profile.d.ts.map +1 -0
- package/dist/types/profile.js +119 -0
- package/dist/types/profile.js.map +1 -0
- package/dist/utils/auth.d.ts +26 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +198 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/config-file.d.ts +92 -0
- package/dist/utils/config-file.d.ts.map +1 -0
- package/dist/utils/config-file.js +244 -0
- package/dist/utils/config-file.js.map +1 -0
- package/dist/utils/config.d.ts +11 -2
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +74 -8
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/confirm.d.ts +38 -0
- package/dist/utils/confirm.d.ts.map +1 -0
- package/dist/utils/confirm.js +124 -0
- package/dist/utils/confirm.js.map +1 -0
- package/dist/utils/defaults.d.ts +39 -0
- package/dist/utils/defaults.d.ts.map +1 -0
- package/dist/utils/defaults.js +195 -0
- package/dist/utils/defaults.js.map +1 -0
- package/dist/utils/errors.d.ts +67 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +395 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/interactive.d.ts +97 -0
- package/dist/utils/interactive.d.ts.map +1 -0
- package/dist/utils/interactive.js +265 -0
- package/dist/utils/interactive.js.map +1 -0
- package/dist/utils/output.d.ts +72 -2
- package/dist/utils/output.d.ts.map +1 -1
- package/dist/utils/output.js +383 -37
- package/dist/utils/output.js.map +1 -1
- package/dist/utils/progress.d.ts +139 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +216 -0
- package/dist/utils/progress.js.map +1 -0
- package/package.json +3 -1
package/dist/utils/config.js
CHANGED
|
@@ -1,14 +1,77 @@
|
|
|
1
1
|
import { config } from 'dotenv';
|
|
2
|
-
|
|
2
|
+
import { authenticateInteractively } from './auth.js';
|
|
3
|
+
import { loadConfigFile, getProfileConfig, getCurrentProfile, migrateFromEnv } from './config-file.js';
|
|
4
|
+
// Load .env from current working directory (fallback for backward compatibility)
|
|
3
5
|
config({ path: process.cwd() + '/.env' });
|
|
4
|
-
export function getConfig(required = true) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export async function getConfig(required = true, interactive = true) {
|
|
7
|
+
// Try to load from config file first
|
|
8
|
+
let configFile = loadConfigFile();
|
|
9
|
+
// If no config file exists, try to migrate from .env
|
|
10
|
+
if (!configFile) {
|
|
11
|
+
configFile = migrateFromEnv();
|
|
12
|
+
}
|
|
13
|
+
// Load credentials from config file or .env
|
|
14
|
+
let accessToken = configFile?.auth?.token || process.env.CAKEMAIL_ACCESS_TOKEN;
|
|
15
|
+
let email = configFile?.auth?.email || process.env.CAKEMAIL_EMAIL || process.env.CAKEMAIL_USERNAME;
|
|
16
|
+
let password = process.env.CAKEMAIL_PASSWORD; // Password not stored in config (security)
|
|
17
|
+
const baseURL = configFile?.auth?.base_url || process.env.CAKEMAIL_API_BASE;
|
|
18
|
+
const currentAccountId = configFile?.defaults?.account_id || process.env.CAKEMAIL_CURRENT_ACCOUNT_ID || undefined;
|
|
19
|
+
// Load profile configuration
|
|
20
|
+
const profile = getCurrentProfile();
|
|
21
|
+
const profileConfig = getProfileConfig(profile);
|
|
22
|
+
// Output format priority: env var > profile config > default
|
|
23
|
+
const outputFormat = process.env.CAKEMAIL_OUTPUT_FORMAT || profileConfig.output.format;
|
|
24
|
+
// If credentials are missing and interactive mode is enabled, prompt the user
|
|
25
|
+
if (required && !accessToken && (!email || !password)) {
|
|
26
|
+
if (interactive) {
|
|
27
|
+
// Interactive authentication flow
|
|
28
|
+
const credentials = await authenticateInteractively();
|
|
29
|
+
email = credentials.email;
|
|
30
|
+
password = credentials.password;
|
|
31
|
+
// Reload config file (it was updated by auth flow)
|
|
32
|
+
configFile = loadConfigFile();
|
|
33
|
+
// Reload .env to get any updates from authentication (backward compatibility)
|
|
34
|
+
config({ path: process.cwd() + '/.env', override: true });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error('Missing credentials. Set CAKEMAIL_ACCESS_TOKEN or (CAKEMAIL_EMAIL and CAKEMAIL_PASSWORD) in environment variables, .env file, or run authentication');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
accessToken,
|
|
42
|
+
email,
|
|
43
|
+
password,
|
|
44
|
+
baseURL,
|
|
45
|
+
outputFormat,
|
|
46
|
+
currentAccountId,
|
|
47
|
+
profile,
|
|
48
|
+
profileConfig,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Synchronous version of getConfig for backwards compatibility
|
|
53
|
+
* Use this only when you're certain credentials are already set
|
|
54
|
+
*/
|
|
55
|
+
export function getConfigSync(required = true) {
|
|
56
|
+
// Try to load from config file first
|
|
57
|
+
let configFile = loadConfigFile();
|
|
58
|
+
// If no config file exists, try to migrate from .env
|
|
59
|
+
if (!configFile) {
|
|
60
|
+
configFile = migrateFromEnv();
|
|
61
|
+
}
|
|
62
|
+
// Load credentials from config file or .env
|
|
63
|
+
const accessToken = configFile?.auth?.token || process.env.CAKEMAIL_ACCESS_TOKEN;
|
|
64
|
+
const email = configFile?.auth?.email || process.env.CAKEMAIL_EMAIL || process.env.CAKEMAIL_USERNAME;
|
|
65
|
+
const password = process.env.CAKEMAIL_PASSWORD; // Password not stored in config (security)
|
|
66
|
+
const baseURL = configFile?.auth?.base_url || process.env.CAKEMAIL_API_BASE;
|
|
67
|
+
const currentAccountId = configFile?.defaults?.account_id || process.env.CAKEMAIL_CURRENT_ACCOUNT_ID || undefined;
|
|
68
|
+
// Load profile configuration
|
|
69
|
+
const profile = getCurrentProfile();
|
|
70
|
+
const profileConfig = getProfileConfig(profile);
|
|
71
|
+
// Output format priority: env var > profile config > default
|
|
72
|
+
const outputFormat = process.env.CAKEMAIL_OUTPUT_FORMAT || profileConfig.output.format;
|
|
10
73
|
if (required && !accessToken && (!email || !password)) {
|
|
11
|
-
throw new Error('Missing credentials. Set CAKEMAIL_ACCESS_TOKEN or (CAKEMAIL_EMAIL and CAKEMAIL_PASSWORD) in environment variables
|
|
74
|
+
throw new Error('Missing credentials. Set CAKEMAIL_ACCESS_TOKEN or (CAKEMAIL_EMAIL and CAKEMAIL_PASSWORD) in environment variables, .env file, or run authentication');
|
|
12
75
|
}
|
|
13
76
|
return {
|
|
14
77
|
accessToken,
|
|
@@ -16,6 +79,9 @@ export function getConfig(required = true) {
|
|
|
16
79
|
password,
|
|
17
80
|
baseURL,
|
|
18
81
|
outputFormat,
|
|
82
|
+
currentAccountId,
|
|
83
|
+
profile,
|
|
84
|
+
profileConfig,
|
|
19
85
|
};
|
|
20
86
|
}
|
|
21
87
|
//# sourceMappingURL=config.js.map
|
package/dist/utils/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAE1B,iFAAiF;AACjF,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAY1C,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,WAAoB,IAAI,EAAE,cAAuB,IAAI;IACnF,qCAAqC;IACrC,IAAI,UAAU,GAAG,cAAc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IAEhD,6DAA6D;IAC7D,MAAM,YAAY,GAAI,OAAO,CAAC,GAAG,CAAC,sBAAuC,IAAI,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC;IAEzG,IAAI,QAAQ,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CACb,qJAAqJ,CACtJ,CAAC;IACJ,CAAC;IAED,OAAO;QACL,WAAW;QACX,KAAK;QACL,QAAQ;QACR,OAAO;QACP,YAAY;QACZ,gBAAgB;QAChB,OAAO;QACP,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ProfileConfig } from '../types/profile.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interactive confirmation utilities for destructive operations
|
|
4
|
+
* Profile-aware: adapts behavior based on user profile settings
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfirmOptions {
|
|
7
|
+
message?: string;
|
|
8
|
+
resourceType?: string;
|
|
9
|
+
resourceId?: string | number;
|
|
10
|
+
details?: string[];
|
|
11
|
+
dangerLevel?: 'low' | 'medium' | 'high';
|
|
12
|
+
profileConfig?: ProfileConfig;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Display confirmation prompt for destructive operations
|
|
16
|
+
* Returns true if user confirms, false if they cancel
|
|
17
|
+
* Profile-aware: skips confirmation for developer profile
|
|
18
|
+
*/
|
|
19
|
+
export declare function confirm(options?: ConfirmOptions): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Confirm deletion of a resource
|
|
22
|
+
*/
|
|
23
|
+
export declare function confirmDelete(resourceType: string, resourceId: string | number, details?: string[], profileConfig?: ProfileConfig): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Confirm deletion with high danger level (permanent, no recovery)
|
|
26
|
+
*/
|
|
27
|
+
export declare function confirmDangerousDelete(resourceType: string, resourceId: string | number, details?: string[], profileConfig?: ProfileConfig): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Confirm a custom action
|
|
30
|
+
*/
|
|
31
|
+
export declare function confirmAction(message: string, details?: string[], dangerLevel?: 'low' | 'medium' | 'high', profileConfig?: ProfileConfig): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if force flag is present (for backwards compatibility)
|
|
34
|
+
* If force flag is present, skip confirmation
|
|
35
|
+
* If not present, show interactive confirmation
|
|
36
|
+
*/
|
|
37
|
+
export declare function shouldProceed(forceFlag: boolean, confirmOptions: ConfirmOptions): Promise<boolean>;
|
|
38
|
+
//# sourceMappingURL=confirm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm.d.ts","sourceRoot":"","sources":["../../src/utils/confirm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAoBD;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAmE5E;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,WAAW,GAAE,KAAK,GAAG,QAAQ,GAAG,MAAiB,EACjD,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,SAAS,EAAE,OAAO,EAClB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,OAAO,CAAC,CAQlB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { isScriptingMode } from './interactive.js';
|
|
4
|
+
/**
|
|
5
|
+
* Determine if confirmation should be shown based on profile
|
|
6
|
+
*/
|
|
7
|
+
function shouldConfirm(profileConfig) {
|
|
8
|
+
// Always skip in scripting mode
|
|
9
|
+
if (isScriptingMode()) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
// No profile config - default to confirming
|
|
13
|
+
if (!profileConfig) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
// Check profile setting for destructive operations
|
|
17
|
+
return profileConfig.behavior.confirm_destructive;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Display confirmation prompt for destructive operations
|
|
21
|
+
* Returns true if user confirms, false if they cancel
|
|
22
|
+
* Profile-aware: skips confirmation for developer profile
|
|
23
|
+
*/
|
|
24
|
+
export async function confirm(options = {}) {
|
|
25
|
+
const { message, resourceType, resourceId, details = [], dangerLevel = 'medium', profileConfig } = options;
|
|
26
|
+
// Check if confirmation is needed based on profile
|
|
27
|
+
if (!shouldConfirm(profileConfig)) {
|
|
28
|
+
return true; // Auto-confirm for developer profile or scripting mode
|
|
29
|
+
}
|
|
30
|
+
// Build the confirmation message
|
|
31
|
+
let confirmMessage = message;
|
|
32
|
+
if (!confirmMessage && resourceType) {
|
|
33
|
+
if (resourceId) {
|
|
34
|
+
confirmMessage = `Delete ${resourceType} ${chalk.bold(resourceId)}?`;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
confirmMessage = `Delete this ${resourceType}?`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!confirmMessage) {
|
|
41
|
+
confirmMessage = 'Are you sure?';
|
|
42
|
+
}
|
|
43
|
+
// Show danger level indicator
|
|
44
|
+
const dangerIndicators = {
|
|
45
|
+
low: chalk.yellow('⚠'),
|
|
46
|
+
medium: chalk.red('⚠'),
|
|
47
|
+
high: chalk.red.bold('⚠⚠⚠')
|
|
48
|
+
};
|
|
49
|
+
console.log('');
|
|
50
|
+
console.log(dangerIndicators[dangerLevel], chalk.bold('Confirmation Required'));
|
|
51
|
+
console.log('');
|
|
52
|
+
// Show details if provided
|
|
53
|
+
if (details.length > 0) {
|
|
54
|
+
console.log(chalk.gray('This will:'));
|
|
55
|
+
details.forEach(detail => {
|
|
56
|
+
console.log(chalk.gray(` • ${detail}`));
|
|
57
|
+
});
|
|
58
|
+
console.log('');
|
|
59
|
+
}
|
|
60
|
+
// Show warning for high danger operations
|
|
61
|
+
if (dangerLevel === 'high') {
|
|
62
|
+
console.log(chalk.red.bold('⚠ WARNING: This action cannot be undone!'));
|
|
63
|
+
console.log('');
|
|
64
|
+
}
|
|
65
|
+
// Prompt for confirmation
|
|
66
|
+
const answer = await inquirer.prompt([
|
|
67
|
+
{
|
|
68
|
+
type: 'confirm',
|
|
69
|
+
name: 'confirmed',
|
|
70
|
+
message: confirmMessage,
|
|
71
|
+
default: false
|
|
72
|
+
}
|
|
73
|
+
]);
|
|
74
|
+
return answer.confirmed;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Confirm deletion of a resource
|
|
78
|
+
*/
|
|
79
|
+
export async function confirmDelete(resourceType, resourceId, details, profileConfig) {
|
|
80
|
+
return confirm({
|
|
81
|
+
resourceType,
|
|
82
|
+
resourceId,
|
|
83
|
+
details,
|
|
84
|
+
dangerLevel: 'medium',
|
|
85
|
+
profileConfig
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Confirm deletion with high danger level (permanent, no recovery)
|
|
90
|
+
*/
|
|
91
|
+
export async function confirmDangerousDelete(resourceType, resourceId, details, profileConfig) {
|
|
92
|
+
return confirm({
|
|
93
|
+
resourceType,
|
|
94
|
+
resourceId,
|
|
95
|
+
details,
|
|
96
|
+
dangerLevel: 'high',
|
|
97
|
+
profileConfig
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Confirm a custom action
|
|
102
|
+
*/
|
|
103
|
+
export async function confirmAction(message, details, dangerLevel = 'medium', profileConfig) {
|
|
104
|
+
return confirm({
|
|
105
|
+
message,
|
|
106
|
+
details,
|
|
107
|
+
dangerLevel,
|
|
108
|
+
profileConfig
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if force flag is present (for backwards compatibility)
|
|
113
|
+
* If force flag is present, skip confirmation
|
|
114
|
+
* If not present, show interactive confirmation
|
|
115
|
+
*/
|
|
116
|
+
export async function shouldProceed(forceFlag, confirmOptions) {
|
|
117
|
+
// If force flag is present, skip confirmation
|
|
118
|
+
if (forceFlag) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
// Otherwise show interactive confirmation
|
|
122
|
+
return confirm(confirmOptions);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=confirm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm.js","sourceRoot":"","sources":["../../src/utils/confirm.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OA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AY;QACZ,UAAU;QACV,OAAO;QACP,WAAW,EAAE,QAAQ;QACrB,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,YAAoB,EACpB,UAA2B,EAC3B,OAAkB,EAClB,aAA6B;IAE7B,OAAO,OAAO,CAAC;QACb,YAAY;QACZ,UAAU;QACV,OAAO;QACP,WAAW,EAAE,MAAM;QACnB,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,OAAkB,EAClB,cAAyC,QAAQ,EACjD,aAA6B;IAE7B,OAAO,OAAO,CAAC;QACb,OAAO;QACP,OAAO;QACP,WAAW;QACX,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAkB,EAClB,cAA8B;IAE9B,8CAA8C;IAC9C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0CAA0C;IAC1C,OAAO,OAAO,CAAC,cAAc,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CakemailClient } from '../client.js';
|
|
2
|
+
import { OutputFormatter } from './output.js';
|
|
3
|
+
/**
|
|
4
|
+
* Auto-detect list ID when only one exists
|
|
5
|
+
* Returns the list ID if only one list exists, otherwise undefined
|
|
6
|
+
*/
|
|
7
|
+
export declare function autoDetectList(client: CakemailClient, formatter: OutputFormatter, providedListId?: string | number, options?: {
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
useCache?: boolean;
|
|
10
|
+
}): Promise<number | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Auto-detect sender ID when only one verified sender exists
|
|
13
|
+
*/
|
|
14
|
+
export declare function autoDetectSender(client: CakemailClient, formatter: OutputFormatter, providedSenderId?: string | number, options?: {
|
|
15
|
+
silent?: boolean;
|
|
16
|
+
useCache?: boolean;
|
|
17
|
+
requireConfirmed?: boolean;
|
|
18
|
+
}): Promise<string | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* Get last used list from cache
|
|
21
|
+
*/
|
|
22
|
+
export declare function getLastList(): number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get last used sender from cache
|
|
25
|
+
*/
|
|
26
|
+
export declare function getLastSender(): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Clear session cache (useful for testing)
|
|
29
|
+
*/
|
|
30
|
+
export declare function clearCache(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Suggest a default value for a missing required option
|
|
33
|
+
* Returns the detected value or undefined
|
|
34
|
+
*/
|
|
35
|
+
export declare function suggestDefault(client: CakemailClient, formatter: OutputFormatter, type: 'list' | 'sender', options?: {
|
|
36
|
+
silent?: boolean;
|
|
37
|
+
useCache?: boolean;
|
|
38
|
+
}): Promise<string | number | undefined>;
|
|
39
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/utils/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA+B9C;;;GAGG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,eAAe,EAC1B,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAChC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GACrD,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuE7B;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,eAAe,EAC1B,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,EAClC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAO,GACjF,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkF7B;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,GAAG,SAAS,CAKhD;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAKlD;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAIjC;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GACrD,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAStC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
// In-memory cache for session (cleared on CLI exit)
|
|
3
|
+
const sessionCache = {};
|
|
4
|
+
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
5
|
+
/**
|
|
6
|
+
* Check if cached resource is still valid
|
|
7
|
+
*/
|
|
8
|
+
function isCacheValid(cached) {
|
|
9
|
+
if (!cached)
|
|
10
|
+
return false;
|
|
11
|
+
return Date.now() - cached.timestamp < CACHE_TTL;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Auto-detect list ID when only one exists
|
|
15
|
+
* Returns the list ID if only one list exists, otherwise undefined
|
|
16
|
+
*/
|
|
17
|
+
export async function autoDetectList(client, formatter, providedListId, options = {}) {
|
|
18
|
+
// If user provided a list ID, use it
|
|
19
|
+
if (providedListId !== undefined) {
|
|
20
|
+
const listId = typeof providedListId === 'string' ? parseInt(providedListId) : providedListId;
|
|
21
|
+
// Cache it for future use
|
|
22
|
+
sessionCache.lastList = {
|
|
23
|
+
id: listId,
|
|
24
|
+
timestamp: Date.now()
|
|
25
|
+
};
|
|
26
|
+
return listId;
|
|
27
|
+
}
|
|
28
|
+
// Check cache if enabled
|
|
29
|
+
if (options.useCache && isCacheValid(sessionCache.lastList)) {
|
|
30
|
+
if (!options.silent) {
|
|
31
|
+
formatter.info(`Using cached list: ${sessionCache.lastList.id}${sessionCache.lastList.name ? ` (${sessionCache.lastList.name})` : ''}`);
|
|
32
|
+
}
|
|
33
|
+
return sessionCache.lastList.id;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
// Fetch all lists
|
|
37
|
+
const response = await client.sdk.lists.list({ per_page: 100 });
|
|
38
|
+
const lists = response.data || [];
|
|
39
|
+
if (lists.length === 0) {
|
|
40
|
+
if (!options.silent) {
|
|
41
|
+
formatter.error('No lists found. Create a list first with: cakemail lists create -n "My List"');
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
if (lists.length === 1) {
|
|
46
|
+
const list = lists[0];
|
|
47
|
+
const listId = list.id;
|
|
48
|
+
// Cache it
|
|
49
|
+
sessionCache.lastList = {
|
|
50
|
+
id: listId,
|
|
51
|
+
name: list.name,
|
|
52
|
+
timestamp: Date.now()
|
|
53
|
+
};
|
|
54
|
+
if (!options.silent) {
|
|
55
|
+
formatter.info(chalk.gray(`Auto-detected list: ${listId} (${list.name})`));
|
|
56
|
+
}
|
|
57
|
+
return listId;
|
|
58
|
+
}
|
|
59
|
+
// Multiple lists exist
|
|
60
|
+
if (!options.silent) {
|
|
61
|
+
formatter.info(chalk.yellow('Multiple lists found. Please specify --list-id <id>'));
|
|
62
|
+
formatter.info(chalk.gray('Available lists:'));
|
|
63
|
+
lists.slice(0, 5).forEach((list) => {
|
|
64
|
+
formatter.info(chalk.gray(` ${list.id}: ${list.name}`));
|
|
65
|
+
});
|
|
66
|
+
if (lists.length > 5) {
|
|
67
|
+
formatter.info(chalk.gray(` ... and ${lists.length - 5} more`));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (!options.silent) {
|
|
74
|
+
formatter.error(`Failed to auto-detect list: ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Auto-detect sender ID when only one verified sender exists
|
|
81
|
+
*/
|
|
82
|
+
export async function autoDetectSender(client, formatter, providedSenderId, options = {}) {
|
|
83
|
+
// If user provided a sender ID, use it
|
|
84
|
+
if (providedSenderId !== undefined) {
|
|
85
|
+
const senderId = String(providedSenderId);
|
|
86
|
+
// Cache it for future use
|
|
87
|
+
sessionCache.lastSender = {
|
|
88
|
+
id: senderId,
|
|
89
|
+
timestamp: Date.now()
|
|
90
|
+
};
|
|
91
|
+
return senderId;
|
|
92
|
+
}
|
|
93
|
+
// Check cache if enabled
|
|
94
|
+
if (options.useCache && isCacheValid(sessionCache.lastSender)) {
|
|
95
|
+
if (!options.silent) {
|
|
96
|
+
formatter.info(`Using cached sender: ${sessionCache.lastSender.id}${sessionCache.lastSender.name ? ` (${sessionCache.lastSender.name})` : ''}`);
|
|
97
|
+
}
|
|
98
|
+
return sessionCache.lastSender.id;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
// Fetch all senders
|
|
102
|
+
const response = await client.sdk.senderService.listSenders({ perPage: 100 });
|
|
103
|
+
const allSenders = response.data || [];
|
|
104
|
+
// Filter to confirmed senders if required
|
|
105
|
+
const senders = options.requireConfirmed
|
|
106
|
+
? allSenders.filter((s) => s.confirmed === true)
|
|
107
|
+
: allSenders;
|
|
108
|
+
if (senders.length === 0) {
|
|
109
|
+
if (!options.silent) {
|
|
110
|
+
if (options.requireConfirmed && allSenders.length > 0) {
|
|
111
|
+
formatter.error('No confirmed senders found. Please confirm a sender first.');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
formatter.error('No senders found. Create a sender first with: cakemail senders create -n "Name" -e "email@domain.com"');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
if (senders.length === 1) {
|
|
120
|
+
const sender = senders[0];
|
|
121
|
+
const senderId = sender.id;
|
|
122
|
+
// Cache it
|
|
123
|
+
sessionCache.lastSender = {
|
|
124
|
+
id: senderId,
|
|
125
|
+
name: sender.name,
|
|
126
|
+
timestamp: Date.now()
|
|
127
|
+
};
|
|
128
|
+
if (!options.silent) {
|
|
129
|
+
formatter.info(chalk.gray(`Auto-detected sender: ${senderId} (${sender.name} <${sender.email}>)`));
|
|
130
|
+
}
|
|
131
|
+
return senderId;
|
|
132
|
+
}
|
|
133
|
+
// Multiple senders exist
|
|
134
|
+
if (!options.silent) {
|
|
135
|
+
const senderType = options.requireConfirmed ? 'confirmed senders' : 'senders';
|
|
136
|
+
formatter.info(chalk.yellow(`Multiple ${senderType} found. Please specify --sender-id <id>`));
|
|
137
|
+
formatter.info(chalk.gray('Available senders:'));
|
|
138
|
+
senders.slice(0, 5).forEach((sender) => {
|
|
139
|
+
const confirmed = sender.confirmed ? chalk.green('✓') : chalk.gray('✗');
|
|
140
|
+
formatter.info(chalk.gray(` ${sender.id}: ${sender.name} <${sender.email}> ${confirmed}`));
|
|
141
|
+
});
|
|
142
|
+
if (senders.length > 5) {
|
|
143
|
+
formatter.info(chalk.gray(` ... and ${senders.length - 5} more`));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (!options.silent) {
|
|
150
|
+
formatter.error(`Failed to auto-detect sender: ${error.message}`);
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get last used list from cache
|
|
157
|
+
*/
|
|
158
|
+
export function getLastList() {
|
|
159
|
+
if (isCacheValid(sessionCache.lastList)) {
|
|
160
|
+
return sessionCache.lastList.id;
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get last used sender from cache
|
|
166
|
+
*/
|
|
167
|
+
export function getLastSender() {
|
|
168
|
+
if (isCacheValid(sessionCache.lastSender)) {
|
|
169
|
+
return sessionCache.lastSender.id;
|
|
170
|
+
}
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Clear session cache (useful for testing)
|
|
175
|
+
*/
|
|
176
|
+
export function clearCache() {
|
|
177
|
+
sessionCache.lastList = undefined;
|
|
178
|
+
sessionCache.lastCampaign = undefined;
|
|
179
|
+
sessionCache.lastSender = undefined;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Suggest a default value for a missing required option
|
|
183
|
+
* Returns the detected value or undefined
|
|
184
|
+
*/
|
|
185
|
+
export async function suggestDefault(client, formatter, type, options = {}) {
|
|
186
|
+
switch (type) {
|
|
187
|
+
case 'list':
|
|
188
|
+
return autoDetectList(client, formatter, undefined, options);
|
|
189
|
+
case 'sender':
|
|
190
|
+
return autoDetectSender(client, formatter, undefined, options);
|
|
191
|
+
default:
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/utils/defaults.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,oDAAoD;AACpD,MAAM,YAAY,GAId,EAAE,CAAC;AAEP,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAE7C;;GAEG;AACH,SAAS,YAAY,CAAC,MAAuB;IAC3C,IAAI,CAA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AO,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,YAAY,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxC,OAAO,YAAY,CAAC,QAAS,CAAC,EAAY,CAAC;IAC7C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,OAAO,YAAY,CAAC,UAAW,CAAC,EAAY,CAAC;IAC/C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,YAAY,CAAC,QAAQ,GAAG,SAAS,CAAC;IAClC,YAAY,CAAC,YAAY,GAAG,SAAS,CAAC;IACtC,YAAY,CAAC,UAAU,GAAG,SAAS,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAsB,EACtB,SAA0B,EAC1B,IAAuB,EACvB,UAAoD,EAAE;IAEtD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC/D,KAAK,QAAQ;YACX,OAAO,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACjE;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ProfileConfig } from '../types/profile.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced error handling with user-friendly messages and suggestions
|
|
4
|
+
*/
|
|
5
|
+
export interface ErrorContext {
|
|
6
|
+
command: string;
|
|
7
|
+
resource?: string;
|
|
8
|
+
resourceId?: string | number;
|
|
9
|
+
operation?: string;
|
|
10
|
+
profileConfig?: ProfileConfig;
|
|
11
|
+
}
|
|
12
|
+
export interface EnhancedError {
|
|
13
|
+
message: string;
|
|
14
|
+
suggestion?: string;
|
|
15
|
+
help?: string;
|
|
16
|
+
docsUrl?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Enhance error with user-friendly message and suggestions
|
|
20
|
+
*/
|
|
21
|
+
export declare function enhanceError(error: any, context: ErrorContext): EnhancedError;
|
|
22
|
+
/**
|
|
23
|
+
* Display enhanced error to user (profile-aware)
|
|
24
|
+
*/
|
|
25
|
+
export declare function displayError(error: any, context: ErrorContext): void;
|
|
26
|
+
/**
|
|
27
|
+
* Validation helpers
|
|
28
|
+
*/
|
|
29
|
+
export declare const validate: {
|
|
30
|
+
/**
|
|
31
|
+
* Validate email format
|
|
32
|
+
*/
|
|
33
|
+
email(email: string): {
|
|
34
|
+
valid: boolean;
|
|
35
|
+
error?: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Validate ID is a positive integer
|
|
39
|
+
*/
|
|
40
|
+
id(id: string | number, resourceName?: string): {
|
|
41
|
+
valid: boolean;
|
|
42
|
+
error?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Validate date format (YYYY-MM-DD)
|
|
46
|
+
*/
|
|
47
|
+
date(date: string): {
|
|
48
|
+
valid: boolean;
|
|
49
|
+
error?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Validate required field
|
|
53
|
+
*/
|
|
54
|
+
required(value: any, fieldName: string): {
|
|
55
|
+
valid: boolean;
|
|
56
|
+
error?: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Validate JSON string
|
|
60
|
+
*/
|
|
61
|
+
json(jsonString: string, fieldName?: string): {
|
|
62
|
+
valid: boolean;
|
|
63
|
+
error?: string;
|
|
64
|
+
parsed?: any;
|
|
65
|
+
};
|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