UNPKG

@nevis-security/nevis-mobile-authentication-sdk-react

Version:

React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.

90 lines (88 loc) 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PasswordChangeImpl = exports.PasswordChange = void 0; var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid")); var _UserInteractionPlatformOperation = require("../../cache/operation/UserInteractionPlatformOperation"); var _PlatformOperationCache = require("../../cache/PlatformOperationCache"); var _PasswordChangeErrorConverter = require("../../error/password/change/PasswordChangeErrorConverter"); var _NativeEventListener = require("../../event/NativeEventListener"); var _MobileAuthenticationSdk = _interopRequireDefault(require("../../MobileAuthenticationSdk")); var _PasswordChangeMessage = require("../../model/messages/out/PasswordChangeMessage"); var _Operation = require("../Operation"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Copyright © 2024 Nevis Security AG. All rights reserved. */ /** * The object that can be used to change the password. * * Usage example: * ```ts * class PasswordChangerImpl implements PasswordChanger { * async changePassword(context: PasswordChangeContext, handler: PasswordChangeHandler) { * handler.passwords(oldPassword, newPassword); * } * } * * [...] * async changePassword({ * client: MobileAuthenticationClient, * username: string, * }): Promise<void> { * await client.operations.passwordChange * .username(username) * .passwordChanger(PasswordChangerImpl(...)) * .onSuccess(() { * // handle success * }) * .onError((error) { * // handle error * }) * .execute(); * } * [...] * ``` */ class PasswordChange extends _Operation.Operation {} exports.PasswordChange = PasswordChange; class PasswordChangeImpl extends PasswordChange { username(username) { this._username = username; return this; } passwordChanger(passwordChanger) { this._passwordChanger = passwordChanger; return this; } onSuccess(onSuccess) { this._onSuccess = onSuccess; return this; } onError(onError) { this._onError = onError; return this; } async execute() { const operationId = _reactNativeUuid.default.v4(); const operation = new _UserInteractionPlatformOperation.UserInteractionPlatformOperationImpl(operationId, undefined, undefined, undefined, undefined, undefined, this._passwordChanger, undefined); _PlatformOperationCache.PlatformOperationCache.getInstance().put(operation); _NativeEventListener.NativeEventListener.getInstance().start(operationId); const message = new _PasswordChangeMessage.PasswordChangeMessage(operationId, this._passwordChanger !== undefined, this._onSuccess !== undefined, this._onError !== undefined, this._username); function finish() { _NativeEventListener.NativeEventListener.getInstance().stop(operationId); _PlatformOperationCache.PlatformOperationCache.getInstance().delete(operationId); } return _MobileAuthenticationSdk.default.passwordChange(message).then(() => { finish(); this._onSuccess?.(); }).catch(error => { finish(); const passwordChangeError = new _PasswordChangeErrorConverter.PasswordChangeErrorConverter(error).convert(); this._onError?.(passwordChangeError); }); } } exports.PasswordChangeImpl = PasswordChangeImpl; //# sourceMappingURL=PasswordChange.js.map