@aws-amplify/storage
Version:
Storage category of aws-amplify
1 lines • 4.27 kB
Source Map (JSON)
{"version":3,"file":"resolveS3ConfigAndInput.mjs","sources":["../../../../../src/providers/s3/utils/resolveS3ConfigAndInput.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { StorageValidationErrorCode } from '../../../errors/types/validation';\nimport { DEFAULT_ACCESS_LEVEL, LOCAL_TESTING_S3_ENDPOINT } from './constants';\nimport { resolvePrefix as defaultPrefixResolver } from '../../../utils/resolvePrefix';\n/**\n * resolve the common input options for S3 API handlers from Amplify configuration and library options.\n *\n * @param {AmplifyClassV6} amplify The Amplify instance.\n * @param {S3ApiOptions} apiOptions The input options for S3 provider.\n * @returns {Promise<ResolvedS3ConfigAndInput>} The resolved common input options for S3 API handlers.\n * @throws A {@link StorageError} with `error.name` from {@link StorageValidationErrorCode} indicating invalid\n * configurations or Amplify library options.\n *\n * @internal\n */\nexport const resolveS3ConfigAndInput = async (amplify, apiOptions) => {\n // identityId is always cached in memory if forceRefresh is not set. So we can safely make calls here.\n const { credentials, identityId } = await amplify.Auth.fetchAuthSession({\n forceRefresh: false,\n });\n assertValidationError(!!credentials, StorageValidationErrorCode.NoCredentials);\n assertValidationError(!!identityId, StorageValidationErrorCode.NoIdentityId);\n const { bucket, region, dangerouslyConnectToHttpEndpointForTesting } = amplify.getConfig()?.Storage?.S3 ?? {};\n assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket);\n assertValidationError(!!region, StorageValidationErrorCode.NoRegion);\n const { defaultAccessLevel, prefixResolver = defaultPrefixResolver, isObjectLockEnabled, } = amplify.libraryOptions?.Storage?.S3 ?? {};\n const keyPrefix = await prefixResolver({\n accessLevel: apiOptions?.accessLevel ?? defaultAccessLevel ?? DEFAULT_ACCESS_LEVEL,\n // use conditional assign to make tsc happy because StorageOptions is a union type that may not have targetIdentityId\n targetIdentityId: apiOptions?.accessLevel === 'protected'\n ? apiOptions?.targetIdentityId ?? identityId\n : identityId,\n });\n return {\n s3Config: {\n credentials,\n region,\n useAccelerateEndpoint: apiOptions?.useAccelerateEndpoint,\n ...(dangerouslyConnectToHttpEndpointForTesting\n ? {\n customEndpoint: LOCAL_TESTING_S3_ENDPOINT,\n forcePathStyle: true,\n }\n : {}),\n },\n bucket,\n keyPrefix,\n isObjectLockEnabled,\n };\n};\n"],"names":["defaultPrefixResolver"],"mappings":";;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,uBAAuB,GAAG,OAAO,OAAO,EAAE,UAAU,KAAK;AACtE;AACA,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC;AAC5E,QAAQ,YAAY,EAAE,KAAK;AAC3B,KAAK,CAAC,CAAC;AACP,IAAI,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC;AACnF,IAAI,qBAAqB,CAAC,CAAC,CAAC,UAAU,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;AACjF,IAAI,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,0CAA0C,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC;AAClH,IAAI,qBAAqB,CAAC,CAAC,CAAC,MAAM,EAAE,0BAA0B,CAAC,QAAQ,CAAC,CAAC;AACzE,IAAI,qBAAqB,CAAC,CAAC,CAAC,MAAM,EAAE,0BAA0B,CAAC,QAAQ,CAAC,CAAC;AACzE,IAAI,MAAM,EAAE,kBAAkB,EAAE,cAAc,GAAGA,aAAqB,EAAE,mBAAmB,GAAG,GAAG,OAAO,CAAC,cAAc,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC;AAC3I,IAAI,MAAM,SA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