UNPKG

aws-amplify

Version:

AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.

1 lines 3.66 kB
{"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 { CognitoAWSCredentialsAndIdentityIdProvider, DefaultIdentityIdStore, 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 const cookieBasedKeyValueStorage = new CookieStorage({ sameSite: 'lax' });\n const resolvedKeyValueStorage = libraryOptions?.ssr\n ? cookieBasedKeyValueStorage\n : defaultStorage;\n const resolvedCredentialsProvider = libraryOptions?.ssr\n ? new CognitoAWSCredentialsAndIdentityIdProvider(new DefaultIdentityIdStore(cookieBasedKeyValueStorage))\n : cognitoCredentialsProvider;\n if (!resolvedResourceConfig.Auth || libraryOptions?.Auth) {\n Amplify.configure(resolvedResourceConfig, libraryOptions);\n return;\n }\n cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth);\n cognitoUserPoolsTokenProvider.setKeyValueStorage(\n // TODO: allow configure with a public interface\n resolvedKeyValueStorage);\n Amplify.configure(resolvedResourceConfig, {\n ...libraryOptions,\n Auth: {\n tokenProvider: cognitoUserPoolsTokenProvider,\n credentialsProvider: resolvedCredentialsProvider,\n },\n });\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;AACzE,QAAQ,MAAM,0BAA0B,GAAG,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACjF,QAAQ,MAAM,uBAAuB,GAAG,cAAc,EAAE;AACxD,cAAc;AACd,cAAc,cAAc;AAC5B,QAAQ,MAAM,2BAA2B,GAAG,cAAc,EAAE;AAC5D,cAAc,IAAI,0CAA0C,CAAC,IAAI,sBAAsB,CAAC,0BAA0B,CAAC;AACnH,cAAc,0BAA0B;AACxC,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,IAAI,cAAc,EAAE,IAAI,EAAE;AAClE,YAAY,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,cAAc,CAAC;AACrE,YAAY;AACZ,QAAQ;AACR,QAAQ,6BAA6B,CAAC,aAAa,CAAC,sBAAsB,CAAC,IAAI,CAAC;AAChF,QAAQ,6BAA6B,CAAC,kBAAkB;AACxD;AACA,QAAQ,uBAAuB,CAAC;AAChC,QAAQ,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE;AAClD,YAAY,GAAG,cAAc;AAC7B,YAAY,IAAI,EAAE;AAClB,gBAAgB,aAAa,EAAE,6BAA6B;AAC5D,gBAAgB,mBAAmB,EAAE,2BAA2B;AAChE,aAAa;AACb,SAAS,CAAC;AACV,IAAI,CAAC;AACL;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,GAAG;AAChB,QAAQ,OAAO,OAAO,CAAC,SAAS,EAAE;AAClC,IAAI,CAAC;AACL;;;;"}