@qite/tide-booking-component
Version:
React Booking wizard & Booking product component for Tide
43 lines (36 loc) • 1.17 kB
text/typescript
import { TideClientConfig } from '@qite/tide-client';
import { isNil } from 'lodash';
import { ApiSettingsState } from '../types';
export const tideConnection = {
// host: 'https://localhost:44341',
host: 'https://preview-tide.tidesoftware.be',
apiKey: 'e9b95d79-de4c-41d6-ab7e-3dd429873058',
catalogueIds: [1],
officeId: 1
};
export function buildTideClientConfig(settings?: ApiSettingsState): TideClientConfig {
const HOST = settings?.apiUrl || tideConnection.host;
const API_KEY = settings?.apiKey || tideConnection.apiKey;
const token = selectAgentToken();
if (isNil(HOST)) {
throw Error(`Environment variable "HOST" was not set.`);
}
if (isNil(API_KEY)) {
throw Error(`Environment variable "API_KEY" was not set.`);
}
return {
host: HOST,
apiKey: API_KEY,
token: token
};
}
export const selectAgentToken = (): string | undefined => {
let token: string | null = null;
if (typeof sessionStorage !== 'undefined') {
token = sessionStorage.getItem('token');
}
if (token === null && typeof localStorage !== 'undefined') {
token = localStorage.getItem('token');
}
return token ?? undefined;
};