import { includes, flatten, uniq } from 'lodash'; import { Signable } from '../web-api/api-query'; import { SigningObject } from './signing-object'; import { WebApiClient } from '../web-api/web-api-client'; import { TacSigningProcess, NoAuthSigningProcess, CaseMobileSigningProcess } from './signing-process'; /** * @export * @class FilledSigningObject * @extends {SigningObject} */ export class FilledSigningObject extends SigningObject { public authorizationType: string; public scenarios: [[string]]; /** * Creates an instance of FilledSigningObject. * @param {GetInfoResponse} response * @param {WebApiClient} client * @param {string} url * @param {any} order * * @memberOf FilledSigningObject */ constructor(response: GetInfoResponse, client: WebApiClient, url: string, order: any) { super(response, client, url); this.authorizationType = response.authorizationType; this.scenarios = response.scenarios; this.order = order; } /** * Returns itself in Promise. * @returns {Promise} * * @memberOf FilledSigningObject */ getInfo = (): Promise => { return Promise.resolve(this); } /** * Starts signing process with TAC (that usually means signing using OneTimePassword from SMS) * This method will inform the API that the client will sign using TAC. * Returned 'TACSigningProcess' is used to finish the signing or throws Error if the call fails * @returns {Promise} * * @memberOf FilledSigningObject */ startSigningWithTac = (): Promise => this.requestSigner.startSigningWithTac(this.signId).then(process => { process.signingObject.order = this.order; this.order.signing = process.signingObject; return process; }); /** * Starts signing process with CASE_MOBILE (that usually means signing using OneTimePassword from SMS) * This method will inform the API that the client will sign using CASE_MOBILE. * Returned 'CaseMobileSigningProcess' is used to finish the signing or throws Error if the call fails * @returns {Promise} * * @memberOf FilledSigningObject */ startSigningWithCaseMobile = (): Promise => this.requestSigner.startSigningWithCaseMobile(this.signId).then(process => { process.signingObject.order = this.order; this.order.signing = process.signingObject; return process; }); /** * Starts signing process with NO_AUTHORIZATION (that usually means signing the order just by clicking some button in UI) * This method signalizes the intent to the API that this order will be signed using NO_AUTHORIZATION method * Returned 'NoAuthSigningProcess' is used to finish the signing or throws Error if the call fails * @returns {Promise} * * @memberOf FilledSigningObject */ startSigningWithNoAuthorization = (): Promise => this.requestSigner.startSigningWithNoAuthorization(this.signId).then(process => { process.signingObject.order = this.order; this.order.signing = process.signingObject; return process; }); /** * Determines whether the signing can be currently done with the given AuthorizationType. * @param {string} authorizationType * @returns {boolean} * * @memberOf FilledSigningObject */ canBeSignedWith = (authorizationType: string): boolean => includes(flatten(this.scenarios), authorizationType); /** * List all current possible authorization types. The list will be empty if the entity is not in a signable state. * @returns {string[]} * * @memberOf FilledSigningObject */ getPossibleAuthorizationTypes = (): string[] => uniq(flatten(this.scenarios)); } /** * @export * @interface GetInfoResponse */ export interface GetInfoResponse { authorizationType: string; scenarios: [[string]]; signInfo: { state: string; signId: string; } }