All files / src VonageApplication.ts

68% Statements 17/25
25% Branches 1/4
28.57% Functions 2/7
68% Lines 17/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 691x   1x 1x 1x 1x 1x 1x     1x   1x 1x 1x   1x     2x                                                                     1x 1x         1x       1x        
import CoreFormsEnum, { getFormName } from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
import Field from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field';
import FieldType from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType';
import Form from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form';
import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
import { ABasicApplication } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
import { CommonHeaders, JSON_TYPE } from '@orchesty/nodejs-sdk/dist/lib/Utils/Headers';
 
export const NAME = 'vonage';
export const API_SECRET = 'Api_secret';
export const API_KEY = 'Api_Key';
 
export default class VonageApplication extends ABasicApplication {
 
    public getName(): string {
        return NAME;
    }
 
    public getPublicName(): string {
        return 'Vonage';
    }
 
    public getDescription(): string {
        return 'Communication platform as a service (CPaaS) provider for consumers and businesses that makes it possible for customers to connect and communicate on any device through cloud-hosted voice or video';
    }
 
    public getLogo(): string {
        return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAxMDAgMTAwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAxMDAgMTAwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxnPgoJPHBhdGggZD0iTTM4LjcsNDguNEwyMCw2LjdIMC4zTDI4LjUsNzBjMC4xLDAuMiwwLjMsMC4zLDAuNSwwLjJjMC4xLDAsMC4xLTAuMSwwLjItMC4yTDM4LjcsNDguNHoiLz4KCTxwYXRoIGQ9Ik03OS43LDYuN2MwLDAtMjUuNCw1Ny40LTI4LjYsNjQuNGMtNy42LDE2LjgtMTMuMywyMS0xOSwyMS45QzMyLDkzLDMyLDkzLjEsMzIsOTMuMmMwLDAuMSwwLjEsMC4xLDAuMSwwLjFoMTgKCQljNy45LDAsMTMuMy01LjMsMjAuOS0yMi4xYzIuNy01LjksMjguNy02NC40LDI4LjctNjQuNEg3OS43eiIvPgo8L2c+Cjwvc3ZnPgo=';
    }
 
    public getFormStack(): FormStack {
        const form = new Form(CoreFormsEnum.AUTHORIZATION_FORM, getFormName(CoreFormsEnum.AUTHORIZATION_FORM))
            .addField(new Field(FieldType.TEXT, API_KEY, 'Api Key', undefined, true))
            .addField(new Field(FieldType.TEXT, API_SECRET, 'Api secret', undefined, true));
 
        return new FormStack().addForm(form);
    }
 
    public isAuthorized(applicationInstall: ApplicationInstall): boolean {
        const authorizationForm = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM];
        return authorizationForm?.[API_KEY] && authorizationForm?.[API_SECRET];
    }
 
    public getRequestDto(
        dto: AProcessDto,
        applicationInstall: ApplicationInstall,
        method: HttpMethods,
        url?: string,
        data?: unknown,
    ): RequestDto {
        const request = new RequestDto(`https://rest.nexmo.com/${url}`, method, dto);
        request.setHeaders({
            [CommonHeaders.CONTENT_TYPE]: JSON_TYPE,
            [CommonHeaders.ACCEPT]: JSON_TYPE,
        });
 
        Iif (data) {
            request.setJsonBody(data);
        }
 
        return request;
    }
 
}