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