@cabin-interactive/qrz-api-client
Version:
A TypeScript wrapper for the QRZ.com API
30 lines (29 loc) • 918 B
JavaScript
import { QrzError } from "./errors";
export function validateConfig(config) {
var _a;
if (!config.apiKey) {
throw new QrzError('API key is required');
}
if (!((_a = config.userAgent) === null || _a === void 0 ? void 0 : _a.trim())) {
throw new QrzError('User agent is required. Please provide a unique identifier for your application.');
}
if (config.userAgent.length > 128) {
throw new QrzError('User agent must be 128 characters or less');
}
if (config.proxyUrl) {
validateProxyUrl(config.proxyUrl);
}
}
function validateProxyUrl(url) {
try {
const parsedUrl = new URL(url);
if (parsedUrl.protocol !== 'https:') {
throw new QrzError('Proxy URL must use HTTPS');
}
}
catch (e) {
if (e instanceof QrzError)
throw e;
throw new QrzError('Invalid proxy URL provided');
}
}