UNPKG

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

Version:

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

97 lines (94 loc) 3.48 kB
"use strict"; /** * Copyright © 2023-2024 Nevis Security AG. All rights reserved. */ import uuid from 'react-native-uuid'; import { HttpOperation, HttpOperationImpl } from "./HttpOperation.js"; import { UserInteractionPlatformOperationImpl } from "../cache/operation/UserInteractionPlatformOperation.js"; import { PlatformOperationCache } from "../cache/PlatformOperationCache.js"; import { DeviceInformationChangeErrorConverter } from "../error/deviceInformation/change/DeviceInformationChangeErrorConverter.js"; import { NativeEventListener } from "../event/NativeEventListener.js"; import NevisMobileAuthenticationSdkReact from "../MobileAuthenticationSdk.js"; import { DeviceInformationChangeMessage } from "../model/messages/out/DeviceInformationChangeMessage.js"; /** * The object that changes the device information. * * The device information change can be used to * - modify the name of the device and/or * - modify its Firebase registration token or * - disable push notifications. * * If neither {@link name} or {@link fcmRegistrationToken} are provided, the provided {@link onSuccess} * callback will be executed when {@link execute} is invoked. * * Usage example for changing device information: * ```ts * [...] * async updateDeviceInformation( * client: MobileAuthenticationClient, * newName: string, * fcmToken: string * ): Promise<void> { * await client.operations.deviceInformationChange * .name(newName) * .fcmRegistrationToken(fcmToken) * .onSuccess(() => { * // handle success * }) * .onError((_error) => { * // handle error * }) * .execute(); * } * [...] * ``` * * @group Performing Operations */ export class DeviceInformationChange extends HttpOperation {} export class DeviceInformationChangeImpl extends HttpOperationImpl { name(name) { this._name = name; return this; } fcmRegistrationToken(fcmRegistrationToken) { this._fcmRegistrationToken = fcmRegistrationToken; return this; } disablePushNotifications() { this._disablePushNotifications = true; return this; } retryPolicy(retryPolicy) { this._retryPolicy = retryPolicy; return this; } onSuccess(onSuccess) { this._onSuccess = onSuccess; return this; } onError(onError) { this._onError = onError; return this; } async execute() { const operationId = uuid.v4(); const operation = new UserInteractionPlatformOperationImpl(operationId); PlatformOperationCache.getInstance().put(operation); NativeEventListener.getInstance().start(operationId); const message = new DeviceInformationChangeMessage(operationId, this._onSuccess !== undefined, this._onError !== undefined, this.httpRequestHeaders, this._name, this._fcmRegistrationToken, this._disablePushNotifications, this._retryPolicy); function finish() { NativeEventListener.getInstance().stop(operationId); PlatformOperationCache.getInstance().delete(operationId); } return NevisMobileAuthenticationSdkReact.deviceInformationChange(message).then(() => { finish(); this._onSuccess?.(); }).catch(error => { finish(); const deviceInformationChangeError = new DeviceInformationChangeErrorConverter(error).convert(); this._onError?.(deviceInformationChangeError); }); } } //# sourceMappingURL=DeviceInformationChange.js.map