Commit 9110ab0b authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate get-api-url module to TS

parent acfa5a22
/** @typedef {import('../../types/config').SidebarSettings} SidebarSettings */ import type { SidebarSettings } from '../../types/config';
import { serviceConfig } from './service-config'; import { serviceConfig } from './service-config';
/** /**
* Function that returns apiUrl from the settings object. * Function that returns apiUrl from the settings object.
* *
* @param {SidebarSettings} settings - The settings object * @return The apiUrl from the service or the default apiUrl from the settings
* @return {string} The apiUrl from the service or the default apiUrl from the settings
* @throws {Error} If the settings has a service but the service doesn't have an apiUrl * @throws {Error} If the settings has a service but the service doesn't have an apiUrl
*
*/ */
export function getApiUrl(settings) { export function getApiUrl(settings: SidebarSettings): string {
const service = serviceConfig(settings); const service = serviceConfig(settings);
if (!service) {
return settings.apiUrl;
}
if (service) { // If the host page contains a service setting then the client should default
// If the host page contains a service setting then the client should default to // to using that apiUrl.
// using that apiUrl. if (service.apiUrl) {
if (service.apiUrl) { return service.apiUrl;
return service.apiUrl;
} else {
throw new Error('Service should contain an apiUrl value.');
}
} }
return settings.apiUrl;
throw new Error('Service should contain an apiUrl value.');
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment