Skip to content

Commit f73dfff

Browse files
committed
fix(installer): Correct API client instantiation for validation
This commit resolves a bug where the interactive installer was failing to validate the API key. The root cause was that the installer was passing the API key as a raw string, while the constructor expects a configuration object (e.g., ). This fix corrects the instantiation within to pass the proper configuration object, ensuring the API key is handled correctly and the validation call succeeds. The client and type definitions have been restored to their stable, correct state.
1 parent 771aa00 commit f73dfff

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎src/client.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ import type {
5252
JobCountry,
5353
JobType,
5454
} from './types.js';
55+
import { z, ZodSchema } from 'zod';
56+
import {
57+
CreditResponse,
58+
ValidateEmailResponse,
59+
FindEmailResponse,
60+
} from './types.js';
5561

5662
/**
5763
* Custom error class for LeadMagic API errors

‎src/install.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,19 @@ const ApiKeyInput: React.FC<{ onNext: (apiKey: string) => void, onBack: () => vo
421421
setError('');
422422
setCredits(null);
423423
try {
424-
const client = new LeadMagicClient(key);
424+
const client = new LeadMagicClient({ apiKey: key });
425425
const creditsData = await client.getCredits();
426426
setCredits(creditsData.credits);
427427
setTimeout(() => onNext(key), 1500); // Wait a moment so user can see credits
428428
} catch (err) {
429-
if (err instanceof LeadMagicError && (err.isClientError())) {
430-
setError('Invalid API Key. Please check the key and try again.');
429+
if (err instanceof Error) {
430+
let detailedMessage = `API Connection Error: ${err.message}.`;
431+
if ('code' in err) {
432+
detailedMessage += ` (Code: ${err.code})`;
433+
}
434+
setError(detailedMessage);
431435
} else {
432-
setError(`Could not connect to the LeadMagic API. Please check your network connection.`);
436+
setError(`An unknown error occurred while trying to connect to the LeadMagic API.`);
433437
}
434438
} finally {
435439
setIsValidating(false);

0 commit comments

Comments
 (0)