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