Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / pass / lib / settings / service.ts
blob5c74f18cd6d72b448456ebf6fe700203de712122
1 import { type ProxiedSettings, getInitialSettings } from '@proton/pass/store/reducers/settings';
2 import type { MaybePromise } from '@proton/pass/types';
3 import { merge } from '@proton/pass/utils/object/merge';
5 export interface SettingsService {
6     clear: (localID?: number) => MaybePromise<void>;
7     resolve: (localID?: number) => Promise<ProxiedSettings>;
8     sync: (settings: ProxiedSettings, localID?: number) => MaybePromise<void>;
11 export const createSettingsService = (options: SettingsService): SettingsService => {
12     return {
13         clear: options.clear,
14         resolve: async (localID) => {
15             try {
16                 const settings = await options.resolve(localID);
17                 return merge(getInitialSettings(), settings ?? {});
18             } catch {
19                 return getInitialSettings();
20             }
21         },
22         sync: options.sync,
23     };