50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
const SESSION_STORAGE_KEY = 'shahi-geoapify-disabled';
|
|
|
|
export type GeoapifyUnavailableReason =
|
|
| 'missing_key'
|
|
| 'quota_exceeded'
|
|
| 'unauthorized'
|
|
| 'forbidden'
|
|
| 'rate_limited'
|
|
| 'payment_required'
|
|
| 'network'
|
|
| 'server_error';
|
|
|
|
export function isGeoapifyApiKeyConfigured(): boolean {
|
|
const key = process.env.NEXT_PUBLIC_GEOAPIFY_API_KEY;
|
|
return typeof key === 'string' && key.trim().length > 0;
|
|
}
|
|
|
|
export function isGeoapifyAutocompleteDisabled(): boolean {
|
|
if (typeof window === 'undefined') return false;
|
|
try {
|
|
return sessionStorage.getItem(SESSION_STORAGE_KEY) === '1';
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function disableGeoapifyAutocomplete(): void {
|
|
if (typeof window === 'undefined') return;
|
|
try {
|
|
sessionStorage.setItem(SESSION_STORAGE_KEY, '1');
|
|
} catch {
|
|
// sessionStorage may be unavailable in private mode
|
|
}
|
|
}
|
|
|
|
export function mapGeoapifyHttpStatus(status: number): GeoapifyUnavailableReason {
|
|
switch (status) {
|
|
case 401:
|
|
return 'unauthorized';
|
|
case 402:
|
|
return 'payment_required';
|
|
case 403:
|
|
return 'forbidden';
|
|
case 429:
|
|
return 'rate_limited';
|
|
default:
|
|
if (status >= 500) return 'server_error';
|
|
return 'quota_exceeded';
|
|
}
|
|
} |