1 import { getAppHref } from '@proton/shared/lib/apps/helper';
2 import { APPS } from '@proton/shared/lib/constants';
3 import { appMode } from '@proton/shared/lib/webpack.constants';
5 import create from '../lib/guest';
7 GetLocalStorageKeysMessageResponse,
8 GetLocalStorageMessageResponse,
10 RemoveLocalStorageMessageResponse,
11 SetLocalStorageMessageResponse,
13 import { Action } from './interface';
15 const createProtonInstance = (url: string) => create<ProtonMessages>(url);
17 type CrossStorageInstance = ReturnType<typeof createProtonInstance>;
19 export let instance: ReturnType<typeof createHandlers>;
21 const createHandlers = ({ postAndGetMessage, supported }: CrossStorageInstance) => {
22 const getLocalStorage = (key: string) => {
23 return postAndGetMessage<GetLocalStorageMessageResponse>({
24 type: Action.getLocalStorage,
31 const getLocalStorageKeys = () => {
32 return postAndGetMessage<GetLocalStorageKeysMessageResponse>({
33 type: Action.getLocalStorageKeys,
37 const setLocalStorage = (key: string, value: string): Promise<void | undefined> => {
38 return postAndGetMessage<SetLocalStorageMessageResponse>({
39 type: Action.setLocalStorage,
47 const removeLocalStorage = (key: string): Promise<void | undefined> => {
48 return postAndGetMessage<RemoveLocalStorageMessageResponse>({
49 type: Action.removeLocalStorage,
65 export const setupGuestCrossStorage = () => {
66 if (appMode !== 'sso') {
69 instance = createHandlers(createProtonInstance(getAppHref('/storage.html', APPS.PROTONACCOUNT)));