{"version":3,"file":"initSingleton.mjs","sources":["../../src/initSingleton.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify, CookieStorage, defaultStorage, } from '@aws-amplify/core';\nimport { parseAmplifyConfig, } from '@aws-amplify/core/internals/utils';\nimport { cognitoCredentialsProvider, cognitoUserPoolsTokenProvider, } from './auth/cognito';\nexport const DefaultAmplify = {\n    /**\n     * Configures Amplify with the {@link resourceConfig} and {@link libraryOptions}.\n     *\n     * @param resourceConfig The {@link ResourcesConfig} object that is typically imported from the\n     * `amplifyconfiguration.json` file. It can also be an object literal created inline when calling `Amplify.configure`.\n     * @param libraryOptions The {@link LibraryOptions} additional options for the library.\n     *\n     * @example\n     * import config from './amplifyconfiguration.json';\n     *\n     * Amplify.configure(config);\n     */\n    configure(resourceConfig, libraryOptions) {\n        const resolvedResourceConfig = parseAmplifyConfig(resourceConfig);\n        // If no Auth config is provided, no special handling will be required, configure as is.\n        // Otherwise, we can assume an Auth config is provided from here on.\n        if (!resolvedResourceConfig.Auth) {\n            Amplify.configure(resolvedResourceConfig, libraryOptions);\n            return;\n        }\n        // If Auth options are provided, always just configure as is.\n        // Otherwise, we can assume no Auth libraryOptions were provided from here on.\n        if (libraryOptions?.Auth) {\n            Amplify.configure(resolvedResourceConfig, libraryOptions);\n            return;\n        }\n        // If no Auth libraryOptions were previously configured, then always add default providers.\n        if (!Amplify.libraryOptions.Auth) {\n            cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth);\n            cognitoUserPoolsTokenProvider.setKeyValueStorage(\n            // TODO: allow configure with a public interface\n            libraryOptions?.ssr\n                ? new CookieStorage({ sameSite: 'lax' })\n                : defaultStorage);\n            Amplify.configure(resolvedResourceConfig, {\n                ...libraryOptions,\n                Auth: {\n                    tokenProvider: cognitoUserPoolsTokenProvider,\n                    credentialsProvider: cognitoCredentialsProvider,\n                },\n            });\n            return;\n        }\n        // At this point, Auth libraryOptions would have been previously configured and no overriding\n        // Auth options were given, so we should preserve the currently configured Auth libraryOptions.\n        if (libraryOptions) {\n            // If ssr is provided through libraryOptions, we should respect the intentional reconfiguration.\n            if (libraryOptions.ssr !== undefined) {\n                cognitoUserPoolsTokenProvider.setKeyValueStorage(\n                // TODO: allow configure with a public interface\n                libraryOptions.ssr\n                    ? new CookieStorage({ sameSite: 'lax' })\n                    : defaultStorage);\n            }\n            Amplify.configure(resolvedResourceConfig, {\n                Auth: Amplify.libraryOptions.Auth,\n                ...libraryOptions,\n            });\n            return;\n        }\n        // Finally, if there were no libraryOptions given at all, we should simply not touch the currently\n        // configured libraryOptions.\n        Amplify.configure(resolvedResourceConfig);\n    },\n    /**\n     * Returns the {@link ResourcesConfig} object passed in as the `resourceConfig` parameter when calling\n     * `Amplify.configure`.\n     *\n     * @returns An {@link ResourcesConfig} object.\n     */\n    getConfig() {\n        return Amplify.getConfig();\n    },\n};\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,cAAc,GAAG;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,cAAc,EAAE,cAAc,EAAE;AAC9C,QAAQ,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC1E;AACA;AACA,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE;AAC1C,YAAY,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;AACtE,YAAY,OAAO;AACnB,SAAS;AACT;AACA;AACA,QAAQ,IAAI,cAAc,EAAE,IAAI,EAAE;AAClC,YAAY,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;AACtE,YAAY,OAAO;AACnB,SAAS;AACT;AACA,QAAQ,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE;AAC1C,YAAY,6BAA6B,CAAC,aAAa,CAAC,s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