1 import type { AuthService } from '@proton/pass/lib/auth/service';
2 import type { AuthStore } from '@proton/pass/lib/auth/store';
12 } from '@proton/pass/types';
13 import type { TelemetryEvent } from '@proton/pass/types/data/telemetry';
14 import type { EncryptedPassCache } from '@proton/pass/types/worker/cache';
16 import type { Notification } from './actions/enhancers/notification';
17 import type { FeatureFlagState, rootReducer } from './reducers';
18 import type { ProxiedSettings } from './reducers/settings';
20 export type State = ReturnType<typeof rootReducer>;
21 export type Telemetry = { start: () => void; stop: () => void; push: (event: TelemetryEvent) => Promise<boolean> };
22 export type PassSaga = (options: RootSagaOptions) => Generator;
23 export type PassBootResult =
24 | { ok: true; fromCache: boolean; offline?: boolean; version?: string }
25 | { ok: false; clearCache: boolean };
27 export interface RootSagaOptions {
28 /** defines the current client type */
29 endpoint: ClientEndpoint;
31 getAppState: () => AppState;
32 getAuthService: () => AuthService;
33 getAuthStore: () => AuthStore;
34 getSettings: () => MaybePromise<ProxiedSettings>;
35 getTelemetry: () => MaybeNull<Telemetry>;
37 setAppStatus: (status: AppStatus) => void;
39 /** Fine-tune the event channel polling interval - this will
40 * be called after each polling run to set the next value */
41 getPollingInterval: () => number;
42 /** Define the initial polling delay : this is especially useful
43 * to avoid immediately spawning the event channels after the
44 * service worker was killed by the browser */
45 getPollingDelay?: (pollingInterval: number, lastCalledAt?: number) => number;
47 /** Retrieves the encrypted cache from whatever storage
48 * the current client is using for persisting data */
49 getCache: () => Promise<Partial<EncryptedPassCache>>;
50 /** Persists the stringified encrypted cache to whatever storage the
51 * current client is using for persisting data */
52 setCache: (encrypted: EncryptedPassCache) => Promise<void>;
54 /** Retrieves storage for the given client */
55 getStorage?: () => AnyStorage<LocalStoreData>;
57 /** Retrieves the IPC bridge when running in Electron */
58 getDesktopBridge?: () => ContextBridgeApi;
60 /** Callback with the result of the boot sequence. The `clearCache`
61 * flag indicates if the boot failure should result in a cache wipe */
62 onBoot?: (result: PassBootResult) => void;
64 /** Callback used when account locale is updated */
65 onLocaleUpdated?: (locale: string) => void;
67 /** Callback used when the local beta flag is updated */
68 onBetaUpdated?: (enabled: boolean) => MaybePromise<void>;
70 /** Callback for handling notification effects */
71 onNotification?: (notification: Notification) => void;
73 /** Callback for propagating feature flags updates */
74 onFeatureFlags?: (features: FeatureFlagState) => void;
76 /** Called whenever some changes were committed to the items state */
77 onItemsUpdated?: () => void;
79 /** Callback triggered when settings have been updated: leverage
80 * this to persist the settings to storage if needed. */
81 onSettingsUpdated?: (settings: ProxiedSettings) => MaybePromise<void>;