import { ServiceCollection, ServiceCollectionRequest } from '../models' import { APIService, ConsultService, DiagnosisService, GuardService, PracticeService, SearchService, TellerService, VaultService, WorkflowService, } from '../services' /** * This function is used to initialize services with a provided url * @param services an object containing the url of the services to init * @param authenticationCallback (optional) the authentification callback. Called when the token were not able to be refreshed. * @param useLocalStorage (default: true) if true store tokens into local storage (only for browsers) * @returns an instance of each services with a provided url */ export const init = ( services: ServiceCollectionRequest, authenticationCallback?: (err: Error, practiceUuid?: string) => void, useLocalStorage = true ): ServiceCollection => { const { tellerBaseURL, practiceBaseURL, consultBaseURL, vaultBaseURL, guardBaseURL, searchBaseURL, workflowBaseURL, diagnosisBaseURL, } = services const apiService = new APIService(useLocalStorage, undefined, authenticationCallback) return { apiService, tellerService: tellerBaseURL ? new TellerService(apiService, tellerBaseURL) : undefined, practiceService: practiceBaseURL ? new PracticeService(apiService, practiceBaseURL) : undefined, consultService: consultBaseURL ? new ConsultService(apiService, consultBaseURL) : undefined, vaultService: vaultBaseURL ? new VaultService(apiService, vaultBaseURL) : undefined, guardService: guardBaseURL ? new GuardService(apiService, guardBaseURL) : undefined, searchService: searchBaseURL ? new SearchService(apiService, searchBaseURL) : undefined, workflowService: workflowBaseURL ? new WorkflowService(apiService, workflowBaseURL) : undefined, diagnosisService: diagnosisBaseURL ? new DiagnosisService(apiService, diagnosisBaseURL) : undefined, } }