{"version":3,"file":"runWithAmplifyServerContext.mjs","sources":["../../../src/adapter-core/runWithAmplifyServerContext.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createAmplifyServerContext, destroyAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core';\nimport { AmplifyError } from '@aws-amplify/core/internals/utils';\n/**\n * The low level function that supports framework specific helpers.\n * It creates an Amplify server context based on the input and runs the\n * operation with injecting the context, and finally returns the result of the\n * operation.\n *\n * @deprecated This registry-backed API is retained solely so OLD published\n * `@aws-amplify/adapter-nextjs` versions (≤ 1.7.3, peer\n * `aws-amplify: ^6.16.4`) — which call it at runtime with cookie-backed\n * token/credentials providers in `libraryOptions` — keep working against this\n * version of `aws-amplify`. It will be removed in the next major version.\n *\n * The created context spec is a REAL branded `AmplifyContext` (structurally\n * compatible with the legacy `ContextSpec` shape), so operations may pass it\n * both to new context-first server APIs (e.g. `fetchAuthSession(contextSpec)`)\n * and to the deprecated `getAmplifyServerContext(contextSpec).amplify` lookup.\n * New code should build a context explicitly with `createAmplifyContext()`\n * (or use `@aws-amplify/adapter-nextjs`'s `createRunWithAmplifyServerContext`\n * for per-request isolation) instead.\n *\n * @param amplifyConfig The Amplify resource config.\n * @param libraryOptions The Amplify library options.\n * @param operation The operation to run with the server context created from\n *   `amplifyConfig` and `libraryOptions`.\n * @returns The result returned by the `operation`.\n */\nexport const runWithAmplifyServerContext = async (amplifyConfig, libraryOptions, operation) => {\n    // Fail loud for untyped-JS callers passing the adapter-level\n    // `{ nextServerContext, operation }` object shape (the signature of the\n    // `runWithAmplifyServerContext` returned by `createServerRunner` in\n    // `@aws-amplify/adapter-nextjs`, not of this function): silently treating\n    // that object as a resource config would produce an unconfigured context\n    // and fail far away from the call site.\n    if (typeof operation !== 'function') {\n        throw new AmplifyError({\n            name: 'InvalidServerContextError',\n            message: '`runWithAmplifyServerContext` from `aws-amplify/adapter-core` must be ' +\n                'called as `runWithAmplifyServerContext(amplifyConfig, libraryOptions, operation)`. ' +\n                'The `{ nextServerContext, operation }` object shape belongs to the ' +\n                'function returned by `createServerRunner` in `@aws-amplify/adapter-nextjs`.',\n            recoverySuggestion: 'Use `createServerRunner`/`createRunWithAmplifyServerContext` from ' +\n                '`@aws-amplify/adapter-nextjs` for request-scoped operations, or pass ' +\n                'the config, library options, and operation as three arguments.',\n        });\n    }\n    const contextSpec = createAmplifyServerContext(amplifyConfig, libraryOptions);\n    // run the operation with injecting the context\n    try {\n        const result = await operation(contextSpec);\n        return result;\n    }\n    finally {\n        // ensures destroy the context regardless whether the operation succeeded or failed\n        destroyAmplifyServerContext(contextSpec);\n    }\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;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;AACY,MAAC,2BAA2B,GAAG,OAAO,aAAa,EAAE,cAAc,EAAE,SAAS,KAAK;AAC/F;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;AACzC,QAAQ,MAAM,IAAI,YAAY,CAAC;AAC/B,YAAY,IAAI,EAAE,2BAA2B;AAC7C,YAAY,OAAO,EAAE,wEAAwE;AAC7F,gBAAgB,qFAAqF;AACrG,gBAAgB,qEAAqE;AACrF,gBAAgB,6EAA6E;AAC7F,YAAY,kBAAkB,EAAE,oEAAoE;AACpG,gBAAgB,uEAAuE;AACvF,gBAAgB,gEAAgE;AAChF,SAAS,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG,0BAA0B,CAAC,aAAa,EAAE,cAAc,CAAC;AACjF;AACA,IAAI,IAAI;AACR,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC;AACnD,QAAQ,OAAO,MAAM;AACrB,IAAI;AACJ,YAAY;AACZ;AACA,QAAQ,2BAA2B,CAAC,WAAW,CAAC;AAChD,IAAI;AACJ;;;;"}