UNPKG

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

Version:

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

78 lines (75 loc) 3.07 kB
"use strict"; /** * Copyright © 2024 Nevis Security AG. All rights reserved. */ import uuid from 'react-native-uuid'; import { PendingOutOfBandPlatformOperation } from "../../cache/operation/PendingOutOfBandPlatformOperation.js"; import { PlatformOperationCache } from "../../cache/PlatformOperationCache.js"; import NevisMobileAuthenticationSdkReact from "../../MobileAuthenticationSdk.js"; import { PendingOutOfBandOperationsResultMessage } from "../../model/messages/in/PendingOutOfBandOperationsResultMessage.js"; import { PendingOutOfBandOperationsMessage } from "../../model/messages/out/PendingOutOfBandOperationsMessage.js"; import { HttpOperation, HttpOperationImpl } from "../HttpOperation.js"; /** * The operation retrieving the out-of-band operations that have been started in * the server, and must be handled by the application running the Mobile Authentication * SDK on the device. * * The retrieved operations have been neither timed-out, nor have been processed * by the SDK, that is, they have not been processed using an {@link OutOfBandOperation} * operation. * * > [!IMPORTANT] * > It is recommended to use this operation as sparsely as possible, because of * > the performance impact that it can have in the server. Do not use it for example * > with a polling mechanism. * * This is supported only when the backend uses nevisFIDO 7.2402.** or later. * * Usage example: * ```ts * [...] * async retrievePendingOutOfBandOperations( * operations: Operations * ): Promise<void> { * await operations.pendingOutOfBandOperations * .onResult((result) => { * // handle the retrieved out-of-band operations. For example * // they can be processed using an OutOfBandOperation. * }) * .execute(); * } * [...] * ``` * * @group Performing Operations * @see * - {@link PendingOutOfBandOperationsResult} * - {@link PendingOutOfBandOperation.payload} * - {@link OutOfBandOperation} * - {@link Operations#pendingOutOfBandOperations} */ export class PendingOutOfBandOperations extends HttpOperation {} export class PendingOutOfBandOperationsImpl extends HttpOperationImpl { constructor() { super(); } onResult(onResult) { this._onResult = onResult; return this; } async execute() { const operationId = uuid.v4(); const operation = new PendingOutOfBandPlatformOperation(operationId, this._onResult); PlatformOperationCache.getInstance().put(operation); const message = new PendingOutOfBandOperationsMessage(operationId, this._onResult !== undefined, this.httpRequestHeaders); function finish() { PlatformOperationCache.getInstance().delete(operationId); } return NevisMobileAuthenticationSdkReact.pendingOutOfBandOperations(message).then(result => { const resultMessage = PendingOutOfBandOperationsResultMessage.fromJson(result); operation.handleResult(resultMessage.result); finish(); }); } } //# sourceMappingURL=PendingOutOfBandOperations.js.map