62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import {
|
|
PROVIDER_DEFINITIONS,
|
|
getProviderDefinition,
|
|
} from '../../shared/providers/registry';
|
|
import type {
|
|
ProviderAccount,
|
|
ProviderConfig,
|
|
ProviderDefinition,
|
|
} from '../../shared/providers/types';
|
|
import { ensureProviderStoreMigrated } from './provider-migration';
|
|
import {
|
|
getDefaultProviderAccountId,
|
|
getProviderAccount,
|
|
listProviderAccounts,
|
|
providerConfigToAccount,
|
|
saveProviderAccount,
|
|
setDefaultProviderAccount,
|
|
} from './provider-store';
|
|
|
|
export class ProviderService {
|
|
async listVendors(): Promise<ProviderDefinition[]> {
|
|
return PROVIDER_DEFINITIONS;
|
|
}
|
|
|
|
async listAccounts(): Promise<ProviderAccount[]> {
|
|
await ensureProviderStoreMigrated();
|
|
return listProviderAccounts();
|
|
}
|
|
|
|
async getAccount(accountId: string): Promise<ProviderAccount | null> {
|
|
await ensureProviderStoreMigrated();
|
|
return getProviderAccount(accountId);
|
|
}
|
|
|
|
async getDefaultAccountId(): Promise<string | undefined> {
|
|
await ensureProviderStoreMigrated();
|
|
return getDefaultProviderAccountId();
|
|
}
|
|
|
|
async syncLegacyProvider(config: ProviderConfig, options?: { isDefault?: boolean }): Promise<ProviderAccount> {
|
|
await ensureProviderStoreMigrated();
|
|
const account = providerConfigToAccount(config, options);
|
|
await saveProviderAccount(account);
|
|
return account;
|
|
}
|
|
|
|
async setDefaultAccount(accountId: string): Promise<void> {
|
|
await ensureProviderStoreMigrated();
|
|
await setDefaultProviderAccount(accountId);
|
|
}
|
|
|
|
getVendorDefinition(vendorId: string): ProviderDefinition | undefined {
|
|
return getProviderDefinition(vendorId);
|
|
}
|
|
}
|
|
|
|
const providerService = new ProviderService();
|
|
|
|
export function getProviderService(): ProviderService {
|
|
return providerService;
|
|
}
|