1 | {"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 { parseAWSExports, } from '@aws-amplify/core/internals/utils';\nimport { cognitoUserPoolsTokenProvider, cognitoCredentialsProvider, } from './auth/cognito';\nexport const DefaultAmplify = {\n configure(resourceConfig, libraryOptions) {\n let resolvedResourceConfig;\n if (Object.keys(resourceConfig).some(key => key.startsWith('aws_'))) {\n resolvedResourceConfig = parseAWSExports(resourceConfig);\n }\n else {\n resolvedResourceConfig = resourceConfig;\n }\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 return Amplify.configure(resolvedResourceConfig, libraryOptions);\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 return Amplify.configure(resolvedResourceConfig, libraryOptions);\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 return Amplify.configure(resolvedResourceConfig, {\n ...libraryOptions,\n Auth: {\n tokenProvider: cognitoUserPoolsTokenProvider,\n credentialsProvider: cognitoCredentialsProvider,\n },\n });\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 return Amplify.configure(resolvedResourceConfig, {\n Auth: Amplify.libraryOptions.Auth,\n ...libraryOptions,\n });\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 getConfig() {\n return Amplify.getConfig();\n },\n};\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,cAAc,GAAG;AAC9B,IAAI,SAAS,CAAC,cAAc,EAAE,cAAc,EAAE;AAC9C,QAAQ,IAAI,sBAAsB,CAAC;AACnC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;AAC7E,YAAY,sBAAsB,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;AACrE,SAAS;AACT,aAAa;AACb,YAAY,sBAAsB,GAAG,cAAc,CAAC;AACpD,SAAS;AACT;AACA;AACA,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE;AAC1C,YAAY,OAAO,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;AAC7E,SAAS;AACT;AACA;AACA,QAAQ,IAAI,cAAc,EAAE,IAAI,EAAE;AAClC,YAAY,OAAO,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;AAC7E,SAAS;AACT;AACA,QAAQ,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE;AAC1C,YAAY,6BAA6B,CAAC,aAAa,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACrF,YAAY,6BAA6B,CAAC,kBAAkB;AAC5D;AACA,YAAY,cAAc,EAAE,GAAG;AAC/B,kBAAkB,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACxD,kBAAkB,cAAc,CAAC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