{"version":3,"file":"updatePassword.mjs","sources":["../../../../../src/providers/cognito/apis/updatePassword.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify, fetchAuthSession } from '@aws-amplify/core';\nimport { AuthAction, assertTokenProviderConfig, } from '@aws-amplify/core/internals/utils';\nimport { AuthValidationErrorCode } from '../../../errors/types/validation';\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { assertAuthTokens } from '../utils/types';\nimport { getAuthUserAgentValue } from '../../../utils';\nimport { createChangePasswordClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\n/**\n * Updates user's password while authenticated.\n *\n * @param input - The UpdatePasswordInput object.\n * @throws - {@link ChangePasswordException} - Cognito service errors thrown when updating a password.\n * @throws - {@link AuthValidationErrorCode} - Validation errors thrown when oldPassword or newPassword are empty.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nexport async function updatePassword(input) {\n    const authConfig = Amplify.getConfig().Auth?.Cognito;\n    assertTokenProviderConfig(authConfig);\n    const { userPoolEndpoint, userPoolId } = authConfig;\n    const { oldPassword, newPassword } = input;\n    assertValidationError(!!oldPassword, AuthValidationErrorCode.EmptyUpdatePassword);\n    assertValidationError(!!newPassword, AuthValidationErrorCode.EmptyUpdatePassword);\n    const { tokens } = await fetchAuthSession({ forceRefresh: false });\n    assertAuthTokens(tokens);\n    const changePassword = createChangePasswordClient({\n        endpointResolver: createCognitoUserPoolEndpointResolver({\n            endpointOverride: userPoolEndpoint,\n        }),\n    });\n    await changePassword({\n        region: getRegionFromUserPoolId(userPoolId),\n        userAgentValue: getAuthUserAgentValue(AuthAction.UpdatePassword),\n    }, {\n        AccessToken: tokens.accessToken.toString(),\n        PreviousPassword: oldPassword,\n        ProposedPassword: newPassword,\n    });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,cAAc,CAAC,KAAK,EAAE;AAC5C,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO;AACxD,IAAI,yBAAyB,CAAC,UAAU,CAAC;AACzC,IAAI,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,UAAU;AACvD,IAAI,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,KAAK;AAC9C,IAAI,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,uBAAuB,CAAC,mBAAmB,CAAC;AACrF,IAAI,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,uBAAuB,CAAC,mBAAmB,CAAC;AACrF,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACtE,IAAI,gBAAgB,CAAC,MAAM,CAAC;AAC5B,IAAI,MAAM,cAAc,GAAG,0BAA0B,CAAC;AACtD,QAAQ,gBAAgB,EAAE,qCAAqC,CAAC;AAChE,YAAY,gBAAgB,EAAE,gBAAgB;AAC9C,SAAS,CAAC;AACV,KAAK,CAAC;AACN,IAAI,MAAM,cAAc,CAAC;AACzB,QAAQ,MAAM,EAAE,uBAAuB,CAAC,UAAU,CAAC;AACnD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,cAAc,CAAC;AACxE,KAAK,EAAE;AACP,QAAQ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;AAClD,QAAQ,gBAAgB,EAAE,WAAW;AACrC,QAAQ,gBAAgB,EAAE,WAAW;AACrC,KAAK,CAAC;AACN;;;;"}