(cliApiKey?: string)
| 5 | |
| 6 | // Get configuration with optional CLI API key |
| 7 | export function getConfig(cliApiKey?: string) { |
| 8 | const apiKey = cliApiKey || process.env.PAYSTACK_TEST_SECRET_KEY; |
| 9 | |
| 10 | if (!apiKey) { |
| 11 | console.error('Error: PAYSTACK_TEST_SECRET_KEY is required'); |
| 12 | process.exit(1); |
| 13 | } |
| 14 | |
| 15 | if (!apiKey.startsWith('sk_test_')) { |
| 16 | console.error( |
| 17 | 'Error: PAYSTACK_TEST_SECRET_KEY must begin with "sk_test_". No live keys allowed.', |
| 18 | ); |
| 19 | process.exit(1); |
| 20 | } |
| 21 | |
| 22 | if (apiKey.length < 30) { |
| 23 | console.error('Error: PAYSTACK_TEST_SECRET_KEY appears to be too short'); |
| 24 | process.exit(1); |
| 25 | } |
| 26 | |
| 27 | return { |
| 28 | PAYSTACK_TEST_SECRET_KEY: apiKey, |
| 29 | NODE_ENV: (process.env.NODE_ENV as 'development' | 'production' | 'test') || 'development', |
| 30 | LOG_LEVEL: (process.env.LOG_LEVEL as 'debug' | 'info' | 'warn' | 'error') || 'info', |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | // Paystack API configuration factory |
| 35 | export function createPaystackConfig(cliApiKey?: string) { |
no test coverage detected