34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { createAud0Client } from "../clients/aud0-client";
|
|
import { resolveDependencyBaseUrl } from "../platform/dependency-mode";
|
|
import { SiaxError } from "../platform/errors";
|
|
import { createSearchDefinitionRepository } from "../repositories/search-definition-repository";
|
|
import { HttpOpenSearchAdapter } from "../search/opensearch-adapter";
|
|
import { SearchService } from "../search/search-service";
|
|
|
|
let singleton: SearchService | undefined;
|
|
|
|
export function getSearchService(): SearchService {
|
|
if (singleton) return singleton;
|
|
const baseUrl = resolveDependencyBaseUrl("opensearch", process.env.OPENSEARCH_URL);
|
|
if (!baseUrl) {
|
|
throw new SiaxError("DEPENDENCY_UNAVAILABLE", "opensearch", "OPENSEARCH_URL is required for the search HTTP surface");
|
|
}
|
|
singleton = new SearchService(
|
|
new HttpOpenSearchAdapter({
|
|
baseUrl,
|
|
...(process.env.OPENSEARCH_BASIC_AUTH
|
|
? { basicAuth: process.env.OPENSEARCH_BASIC_AUTH }
|
|
: {}),
|
|
}),
|
|
{
|
|
aud0Client: createAud0Client(),
|
|
definitionRepository: createSearchDefinitionRepository(),
|
|
},
|
|
);
|
|
return singleton;
|
|
}
|
|
|
|
export function resetSearchServiceForTests(): void {
|
|
singleton = undefined;
|
|
}
|