export interface LandLordApi { dashboardState: string defaultState: string domainTemplateHref: string domainTemplateText: string heartbeat: number } export interface TenantAppApi { applyHref: string baseUrl: string defaultSubdomain: string excludedSubdomains: string[] tokenLoginHref: string } export interface DomainApi { default: string template: string } export interface PdfServerApi { href: string text: string } export type ApiUrl = string export type Debug = boolean export type Domain = string export type LandLordApp = LandLordApi export type PdfServer = PdfServerApi export type TenantApp = TenantAppApi export type Token = string | null export type UploadUrl = string export interface ApiConfig { apiUrl: ApiUrl debug: Debug domain: Domain landLordApp: LandLordApp | null pdfServer: PdfServer | null tenantApp: TenantApp | null token: Token uploadUrl: UploadUrl } export type ApiFactory = (api: Api) => T export type ApiUrlPath = string export interface ApiRequest { apiUrl: string } const defaultApiConfig: ApiConfig = { apiUrl: 'https://api.immomio.de', debug: false, domain: 'app', landLordApp: null, pdfServer: null, tenantApp: null, token: null, uploadUrl: 'https://upload.immomio.de', } export class Api { private config: ApiConfig constructor(options?: Partial) { this.config = { ...defaultApiConfig, ...options} } get apiUrl() { return this.config.apiUrl } set apiUrl(apiUrl: ApiUrl) { this.config.apiUrl = apiUrl } get debug() { return this.config.debug } set debug(debug: Debug) { this.config.debug = debug } get domain() { return this.config.domain } set domain(domain: Domain) { this.config.domain = domain } get landLordApp() { return this.config.landLordApp } set landLordApp(landLordApp: LandLordApp) { this.config.landLordApp = landLordApp } get pdfServer() { return this.config.pdfServer } set pdfServer(pdfServer: PdfServer) { this.config.pdfServer = pdfServer } get tenantApp() { return this.config.tenantApp } set tenantApp(tenantApp: TenantApp) { this.config.tenantApp = tenantApp } get token() { return this.config.token } set token(token: Token) { this.config.token = token } get uploadUrl() { return this.config.uploadUrl } set uploadUrl(uploadUrl: UploadUrl) { this.config.uploadUrl = uploadUrl } } export const api = new Api()