mirror of
https://github.com/bitwarden/browser
synced 2026-02-28 10:33:31 +00:00
* Refactor provider service calls to include userId parameter - Updated multiple components and services to pass userId when fetching provider data. - Adjusted the ProviderService interface to require userId for get, get$, and getAll methods. - Ensured consistent handling of userId across various components, enhancing data retrieval based on active user context. * Remove deprecated type safety comments and use the getById utility for fetching providers. * Update ProviderService methods to return undefined for non-existent providers - Modified the return types of get$ and get methods in ProviderService to allow for undefined values, enhancing type safety. - Adjusted the providers$ method to return only defined Provider arrays, ensuring consistent handling of provider data. * Enhance provider permissions guard tests to include userId parameter - Updated test cases in provider-permissions.guard.spec.ts to pass userId when calling ProviderService methods. - Mocked AccountService to provide active account details for improved test coverage. - Ensured consistent handling of userId across all relevant test scenarios. * remove promise based api's from provider service, continue refactor * cleanup observable logic * cleanup --------- Co-authored-by: Brandon <btreston@bitwarden.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { map, Observable } from "rxjs";
|
|
|
|
import { getById } from "../../platform/misc";
|
|
import { PROVIDERS_DISK, StateProvider, UserKeyDefinition } from "../../platform/state";
|
|
import { UserId } from "../../types/guid";
|
|
import { ProviderService as ProviderServiceAbstraction } from "../abstractions/provider.service";
|
|
import { ProviderData } from "../models/data/provider.data";
|
|
import { Provider } from "../models/domain/provider";
|
|
|
|
export const PROVIDERS = UserKeyDefinition.record<ProviderData>(PROVIDERS_DISK, "providers", {
|
|
deserializer: (obj: ProviderData) => obj,
|
|
clearOn: ["logout"],
|
|
});
|
|
|
|
export class ProviderService implements ProviderServiceAbstraction {
|
|
constructor(private stateProvider: StateProvider) {}
|
|
|
|
providers$(userId: UserId): Observable<Provider[]> {
|
|
return this.stateProvider
|
|
.getUser(userId, PROVIDERS)
|
|
.state$.pipe(this.mapProviderRecordToArray());
|
|
}
|
|
|
|
private mapProviderRecordToArray() {
|
|
return map<Record<string, ProviderData> | null, Provider[]>((providers) =>
|
|
Object.values(providers ?? {}).map((o) => new Provider(o)),
|
|
);
|
|
}
|
|
|
|
get$(id: string, userId: UserId): Observable<Provider | undefined> {
|
|
return this.providers$(userId).pipe(getById(id));
|
|
}
|
|
|
|
async save(providers: { [id: string]: ProviderData }, userId: UserId) {
|
|
await this.stateProvider.setUserState(PROVIDERS, providers, userId);
|
|
}
|
|
}
|