{"version":3,"file":"utils.mjs","sources":["../../../src/storage/utils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '../Logger';\nimport { InMemoryStorage } from './InMemoryStorage';\n/**\n * @internal\n * @returns Either a reference to window.localStorage or an in-memory storage as fallback\n */\nconst logger = new ConsoleLogger('CoreStorageUtils');\nexport const getLocalStorageWithFallback = () => {\n    try {\n        // Attempt to use localStorage directly\n        if (typeof window !== 'undefined' && window.localStorage) {\n            return window.localStorage;\n        }\n    }\n    catch (e) {\n        // Handle any errors related to localStorage access\n        logger.info('localStorage not found. InMemoryStorage is used as a fallback.');\n    }\n    // Return in-memory storage as a fallback if localStorage is not accessible\n    return new InMemoryStorage();\n};\n/**\n * @internal\n * @returns Either a reference to window.sessionStorage or an in-memory storage as fallback\n */\nexport const getSessionStorageWithFallback = () => {\n    try {\n        // Attempt to use sessionStorage directly\n        if (typeof window !== 'undefined' && window.sessionStorage) {\n            // Verify we can actually use it by testing access\n            window.sessionStorage.getItem('test');\n            return window.sessionStorage;\n        }\n        throw new Error('sessionStorage is not defined');\n    }\n    catch (e) {\n        // Handle any errors related to sessionStorage access\n        logger.info('sessionStorage not found. InMemoryStorage is used as a fallback.');\n        return new InMemoryStorage();\n    }\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,kBAAkB,CAAC;AACxC,MAAC,2BAA2B,GAAG,MAAM;AACjD,IAAI,IAAI;AACR;AACA,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,YAAY,EAAE;AAClE,YAAY,OAAO,MAAM,CAAC,YAAY;AACtC,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,CAAC,EAAE;AACd;AACA,QAAQ,MAAM,CAAC,IAAI,CAAC,gEAAgE,CAAC;AACrF,IAAI;AACJ;AACA,IAAI,OAAO,IAAI,eAAe,EAAE;AAChC;AACA;AACA;AACA;AACA;AACY,MAAC,6BAA6B,GAAG,MAAM;AACnD,IAAI,IAAI;AACR;AACA,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,cAAc,EAAE;AACpE;AACA,YAAY,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;AACjD,YAAY,OAAO,MAAM,CAAC,cAAc;AACxC,QAAQ;AACR,QAAQ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC;AACxD,IAAI;AACJ,IAAI,OAAO,CAAC,EAAE;AACd;AACA,QAAQ,MAAM,CAAC,IAAI,CAAC,kEAAkE,CAAC;AACvF,QAAQ,OAAO,IAAI,eAAe,EAAE;AACpC,IAAI;AACJ;;;;"}