UNPKG

@cabin-interactive/qrz-api-client

Version:
31 lines (30 loc) 925 B
export class BaseQrzService { constructor(config) { this.config = config; this.API_URL = 'https://logbook.qrz.com/api'; } get baseUrl() { if (!this.config.proxyUrl) { this.warnIfBrowser(); return this.API_URL; } return this.config.proxyUrl; } createFormData(params) { const upperCaseParams = Object.entries(params).reduce((acc, [key, value]) => { if (value !== undefined) { acc[key.toUpperCase()] = value; } return acc; }, {}); return new URLSearchParams({ ...upperCaseParams, KEY: this.config.apiKey, }); } warnIfBrowser() { if (typeof window !== 'undefined') { console.warn('Using QRZ API directly in a browser environment may fail due to CORS restrictions. Consider using a proxy.'); } } }