@nevis-security/nevis-mobile-authentication-sdk-react
Version:
React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.
81 lines (78 loc) • 3.1 kB
JavaScript
;
/**
* Copyright © 2024 Nevis Security AG. All rights reserved.
*/
import uuid from 'react-native-uuid';
import { DeviceInformationSyncPlatformOperation } from "../../cache/operation/DeviceInformationSyncPlatformOperation.js";
import { PlatformOperationCache } from "../../cache/PlatformOperationCache.js";
import NevisMobileAuthenticationSdkReact from "../../MobileAuthenticationSdk.js";
import { DeviceInformationSyncResultMessage } from "../../model/messages/in/DeviceInformationSyncResultMessage.js";
import { DeviceInformationSyncMessage } from "../../model/messages/out/DeviceInformationSyncMessage.js";
import { HttpOperation, HttpOperationImpl } from "../HttpOperation.js";
/**
* The operation that can be executed to correct the {@link DeviceInformationMismatch} problems
* that were found in a {@link DeviceInformationCheck}.
*
* The operation works in a best-effort mode: it will try to resolve as many mismatches as
* possible and will report the errors that occurred (if any) through the {@link DeviceInformationSyncResult.errors}
* method.
*
* > [!WARNING]
* > Some of the changes result in removal of credentials on both the server and client side. Use this
* > class with caution and understanding its implications. The changes that will be applied are
* > described on the documentation of each {@link DeviceInformationMismatch}.
*
* This is supported only when the backend uses nevisFIDO 7.2408.** or later.
*
* Usage example:
* ```ts
* [...]
* async fixDeviceInformationMismatches(
* operations: Operations,
* mismatches: DeviceInformationMismatch[]
* ): Promise<void> {
* operations.deviceInformationSync
* .mismatches(mismatches)
* .onResult((result) => {
* // handle the result
* })
* .execute();
* }
* [...]
* ```
*
* @group Performing Operations
* @see
* - {@link DeviceInformationCheck}
* - {@link DeviceInformationMismatch}
* - {@link Operations.deviceInformationSync}
*/
export class DeviceInformationSync extends HttpOperation {}
export class DeviceInformationSyncImpl extends HttpOperationImpl {
constructor() {
super();
}
mismatches(mismatches) {
this._mismatches = mismatches;
return this;
}
onResult(onResult) {
this._onResult = onResult;
return this;
}
async execute() {
const operationId = uuid.v4();
const operation = new DeviceInformationSyncPlatformOperation(operationId, this._onResult);
PlatformOperationCache.getInstance().put(operation);
const message = new DeviceInformationSyncMessage(operationId, this._onResult !== undefined, this._mismatches, this.httpRequestHeaders);
function finish() {
PlatformOperationCache.getInstance().delete(operationId);
}
return NevisMobileAuthenticationSdkReact.deviceInformationSync(message).then(result => {
const resultMessage = DeviceInformationSyncResultMessage.fromJson(result);
operation.handleResult(resultMessage.result);
finish();
});
}
}
//# sourceMappingURL=DeviceInformationSync.js.map