{"version":3,"file":"configure.mjs","sources":["../../src/configure.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createAmplifyContext as createCoreAmplifyContext, } from '@aws-amplify/core';\nimport { parseAmplifyConfig, selectSsrKeyValueStorage, } from '@aws-amplify/core/internals/utils';\nimport { createAWSCredentialsAndIdentityIdProvider, createUserPoolsTokenProvider, } from './adapter-core/authProvidersFactories/cognito';\n/**\n * Creates a local, branded {@link AmplifyContext} from the given resource\n * configuration.\n *\n * Unlike `Amplify.configure()`, the returned context is **not** set as the\n * global context and no Hub events are dispatched. Category APIs that receive\n * this context (as their first positional argument) will use it instead of the\n * global one, enabling per-request context injection in server-side /\n * multi-tenant scenarios.\n *\n * This is the `aws-amplify`-level wrapper around\n * {@link createCoreAmplifyContext | `@aws-amplify/core`'s `createAmplifyContext`}.\n * The core factory intentionally does **not** inject default Cognito providers\n * (it sits below `@aws-amplify/auth` in the dependency graph); this wrapper\n * closes that gap by resolving and injecting **factory-style, per-context**\n * Cognito token/credentials providers when the caller does not supply their own.\n * Because each call builds fresh provider instances, contexts created here do\n * **not** share the process-wide singleton providers used by\n * `Amplify.configure()` — two contexts remain isolated from one another.\n *\n * Storage behaviour mirrors `Amplify.configure()`: tokens are persisted to\n * `localStorage` by default, or to cookies when `{ ssr: true }` is set.\n *\n * @param resourceConfig - Back-end resource configuration (typed config,\n *   legacy `aws-exports`, or Gen2 `amplify_outputs`).\n * @param libraryOptions - Optional library options (e.g. Auth token/credentials\n *   providers, `ssr`).\n * @returns A branded, frozen {@link AmplifyContext}.\n *\n * @example\n * ```ts\n * import { createAmplifyContext } from 'aws-amplify';\n * import outputs from './amplify_outputs.json';\n *\n * const ctx = createAmplifyContext(outputs);\n * // Pass ctx explicitly to category APIs:\n * await signIn(ctx, { username, password });\n * ```\n */\nexport function createAmplifyContext(resourceConfig, libraryOptions) {\n    const resolvedResourceConfig = parseAmplifyConfig(resourceConfig);\n    const resolvedLibraryOptions = resolveLocalLibraryOptions(resolvedResourceConfig, libraryOptions);\n    // Delegate to core for branding + freezing + the per-context AuthClass.\n    // We already parsed `resourceConfig` above (the parsed shape is required by\n    // `resolveLocalLibraryOptions` to inject default Cognito providers), so tell\n    // core to skip re-parsing. This removes a redundant `parseAmplifyConfig` call\n    // on every context creation — and two per SSR request via adapter-nextjs —\n    // without changing behavior, because `parseAmplifyConfig` is a no-op on an\n    // already-normalized `ResourcesConfig`.\n    return createCoreAmplifyContext(resolvedResourceConfig, resolvedLibraryOptions, { skipConfigParse: true });\n}\n/**\n * Resolves the effective {@link LibraryOptions} for a locally-created context,\n * injecting default **factory-style** Cognito providers when the caller does\n * not supply their own.\n *\n * - No `Auth` in the resource config → pass options through unchanged.\n * - Caller-provided `libraryOptions.Auth` → take precedence (no defaults).\n * - Otherwise → build per-context token/credentials providers backed by\n *   cookie storage (`ssr: true`) or `localStorage` (default).\n */\nfunction resolveLocalLibraryOptions(resourceConfig, libraryOptions) {\n    if (!resourceConfig.Auth) {\n        return libraryOptions ?? {};\n    }\n    // User-provided providers take precedence.\n    if (libraryOptions?.Auth) {\n        return libraryOptions;\n    }\n    // Resolve storage via core's shared helper based on the SSR option:\n    // - ssr: true  → CookieStorage (shared between client and server)\n    // - ssr: false → defaultStorage (localStorage with server-safe fallback)\n    const keyValueStorage = selectSsrKeyValueStorage(libraryOptions?.ssr);\n    const tokenProvider = createUserPoolsTokenProvider(resourceConfig.Auth, keyValueStorage);\n    const credentialsProvider = createAWSCredentialsAndIdentityIdProvider(resourceConfig.Auth, keyValueStorage);\n    return {\n        ...libraryOptions,\n        Auth: { tokenProvider, credentialsProvider },\n    };\n}\n"],"names":["createCoreAmplifyContext"],"mappings":";;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,cAAc,EAAE,cAAc,EAAE;AACrE,IAAI,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,cAAc,CAAC;AACrE,IAAI,MAAM,sBAAsB,GAAG,0BAA0B,CAAC,sBAAsB,EAAE,cAAc,CAAC;AACrG;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAOA,sBAAwB,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;AAC9G;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,0BAA0B,CAAC,cAAc,EAAE,cAAc,EAAE;AACpE,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE;AAC9B,QAAQ,OAAO,cAAc,IAAI,EAAE;AACnC,IAAI;AACJ;AACA,IAAI,IAAI,cAAc,EAAE,IAAI,EAAE;AAC9B,QAAQ,OAAO,cAAc;AAC7B,IAAI;AACJ;AACA;AACA;AACA,IAAI,MAAM,eAAe,GAAG,wBAAwB,CAAC,cAAc,EAAE,GAAG,CAAC;AACzE,IAAI,MAAM,aAAa,GAAG,4BAA4B,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC;AAC5F,IAAI,MAAM,mBAAmB,GAAG,yCAAyC,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC;AAC/G,IAAI,OAAO;AACX,QAAQ,GAAG,cAAc;AACzB,QAAQ,IAAI,EAAE,EAAE,aAAa,EAAE,mBAAmB,EAAE;AACpD,KAAK;AACL;;;;"}