fix(gbminservice.ts): swagger-client migration from 2.0 to 3.0

This commit is contained in:
Alan Perdomo 2023-01-13 13:30:18 -03:00
parent ba96798c77
commit 552e8b14c4
6 changed files with 208 additions and 610 deletions

File diff suppressed because one or more lines are too long

View file

@ -124,7 +124,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return subscriptionClient.subscriptions.list();
}
public getKBSearchSchema (indexName) {
public getKBSearchSchema (indexName: any) {
return {
name: indexName,
fields: [
@ -235,7 +235,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
};
}
public async botExists (botId) {
public async botExists (botId: string) {
const baseUrl = `https://management.azure.com/`;
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
@ -257,7 +257,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return !res.parsedBody.valid;
}
public async updateBotProxy (botId, group, endpoint) {
public async updateBotProxy (botId: string, group: string, endpoint: string) {
const baseUrl = `https://management.azure.com/`;
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
@ -316,7 +316,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
GBLog.info(`Bot updated at: ${endpoint}.`);
}
public async deleteBot (botId: string, group) {
public async deleteBot (botId: string, group: string) {
const baseUrl = `https://management.azure.com/`;
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
@ -338,7 +338,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
GBLog.info(`Bot ${botId} was deleted from the provider.`);
}
public async openStorageFirewall (groupName, serverName) {
public async openStorageFirewall (groupName: string, serverName: string) {
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
@ -353,7 +353,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
public async deployFarm (
proxyAddress: string,
instance: IGBInstance,
credentials,
credentials: any,
subscriptionId: string
): Promise<IGBInstance> {
const culture = 'en-us';
@ -580,7 +580,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
});
}
public async syncBotServerRepository (group, name) {
public async syncBotServerRepository (group: string, name: string) {
await this.webSiteClient.webApps.syncRepository(group, name);
}
@ -605,7 +605,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}
}
const token = await new StaticAccessToken();
const token = new StaticAccessToken();
this.cloud = new ResourceManagementClient(token, subscriptionId);
this.webSiteClient = new WebSiteManagementClient(token, subscriptionId);
@ -614,7 +614,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
this.searchClient = new SearchManagementClient(token, subscriptionId);
}
private async createStorageServer (group, name, administratorLogin, administratorPassword, serverName, location) {
private async createStorageServer (group: string, name: string, administratorLogin: string, administratorPassword: string, serverName: string, location: string) {
const params = {
location: location,
administratorLogin: administratorLogin,
@ -680,7 +680,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
});
}
private async registerProviders (subscriptionId, baseUrl, accessToken) {
private async registerProviders (subscriptionId: string, baseUrl: string, accessToken: string) {
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
const requestUrl = urlJoin(baseUrl, query);
@ -793,7 +793,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await httpClient.sendRequest(req);
}
private async createSearch (group, name, location) {
private async createSearch (group: string, name: string, location: string) {
const params = {
sku: {
name: this.freeTier ? 'free' : 'standard'
@ -804,7 +804,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await this.searchClient.services.beginCreateOrUpdateAndWait(group, name, params as any);
}
private async createStorage (group, serverName, name, location) {
private async createStorage (group: string, serverName: string, name: string, location: string) {
const params = {
sku: { name: this.freeTier ? 'Free' : 'Basic' },
createMode: 'Default',
@ -814,7 +814,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await this.storageClient.databases.beginCreateOrUpdateAndWait(group, serverName, name, params);
}
private async createCognitiveServices (group, name, location, kind): Promise<Account> {
private async createCognitiveServices (group: string, name: string, location: string, kind: string): Promise<Account> {
const params = {
sku: {
name: name
@ -840,40 +840,40 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await this.cognitiveClient.accounts.beginCreateAndWait(group, name, params);
}
private async createSpeech (group, name, location): Promise<Account> {
private async createSpeech (group: string, name: string, location: string): Promise<Account> {
return await this.createCognitiveServices(group, name, location, 'SpeechServices');
}
private async createNLP (group, name, location): Promise<Account> {
private async createNLP (group: string, name: string, location: string): Promise<Account> {
return await this.createCognitiveServices(group, name, location, 'LUIS');
}
private async createNLPAuthoring (group, name, location): Promise<Account> {
private async createNLPAuthoring (group: string, name: string, location: string): Promise<Account> {
return await this.createCognitiveServices(group, name, location, 'LUIS.Authoring');
}
private async createSpellChecker (group, name): Promise<Account> {
private async createSpellChecker (group: string, name: string): Promise<Account> {
return await this.createCognitiveServices(group, name, 'westus', 'CognitiveServices');
}
private async createTextAnalytics (group, name, location): Promise<Account> {
private async createTextAnalytics (group: string, name: string, location: string): Promise<Account> {
return await this.createCognitiveServices(group, name, location, 'TextAnalytics');
}
private async createDeployGroup (name, location) {
private async createDeployGroup (name: string, location: string) {
const params = { location: location };
return await this.cloud.resourceGroups.createOrUpdate(name, params);
}
private async enableResourceProviders (name) {
private async enableResourceProviders (name: string) {
const ret = await this.cloud.providers.get(name);
if (ret.registrationState === 'NotRegistered') {
await this.cloud.providers.register(name);
}
}
private async createHostingPlan (group, name, location): Promise<AppServicePlan> {
private async createHostingPlan (group: string, name: string, location: string): Promise<AppServicePlan> {
const params = {
serverFarmWithRichSkuName: name,
location: location,
@ -887,7 +887,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await this.webSiteClient.appServicePlans.beginCreateOrUpdateAndWait(group, name, params);
}
private async createServer (farmId, group, name, location) {
private async createServer (farmId: string, group: string, name: string, location: string) {
let tryed = false;
const create = async () => {
const parameters: Site = {
@ -937,7 +937,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}
}
private async updateWebisteConfig (group, name, serverFarmId, instance: IGBInstance) {
private async updateWebisteConfig (group: string, name: string, serverFarmId: string, instance: IGBInstance) {
const parameters: Site = {
location: instance.cloudLocation,
serverFarmId: serverFarmId,

View file

@ -56,6 +56,7 @@ import Path from 'path';
import sgMail from '@sendgrid/mail';
import mammoth from 'mammoth';
import qrcode from 'qrcode';
import { json } from 'body-parser';
/**
* Base services of conversation to be called by BASIC.
@ -1028,10 +1029,7 @@ export class DialogKeywords {
}
public async getSingleton({}) {
const executionId = this.sys().getRandomId();
GBServer.globals.executions[executionId]={};
return {
executionId: executionId,
id: this.sys().getRandomId(),
username: this.userName(),
mobile: this.userMobile(),

View file

@ -34,6 +34,7 @@
import { GBLog, GBMinInstance, GBService, IGBCoreService, GBDialogStep } from 'botlib';
import * as Fs from 'fs';
import { GBServer } from '../../../src/app.js';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { TSCompiler } from './TSCompiler.js';
import { CollectionUtil } from 'pragmatismo-io-framework';
@ -48,6 +49,10 @@ import walkPromise from 'walk-promise';
import child_process from 'child_process';
import Path from 'path';
import indent from 'indent.js';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
import pkg from 'swagger-client';
const {Swagger} = pkg;
/**
* @fileoverview Decision was to priorize security(isolation) and debugging,
* over a beautiful BASIC transpiler (to be done).
@ -1022,6 +1027,10 @@ export class GBVMService extends GBService {
let code = min.sandBoxMap[text];
const executionId = GBAdminService.getNumberIdentifier();
GBServer.globals.executions[executionId]={
executionId: executionId,
};
if (GBConfigService.get('VM3') === 'true') {
try {
const vm1 = new NodeVM({

View file

@ -46,7 +46,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
let stderrCache = '';
const run = async (code, scope) => {
const run = async (code: any, scope: any) => {
const childProcess = spawn(
'cpulimit',
[

View file

@ -38,8 +38,7 @@
import cliProgress from 'cli-progress';
import { DialogSet, TextPrompt } from 'botbuilder-dialogs';
import express from 'express';
import Swagger from 'swagger-client';
import SwaggerClient from 'swagger-client';
import removeRoute from 'express-remove-route';
import AuthenticationContext from 'adal-node';
import wash from 'washyourmouthoutwithsoap';
@ -331,15 +330,14 @@ export class GBMinService {
if (process.env.TEST_MESSAGE) {
GBLog.info(`Starting auto test with '${process.env.TEST_MESSAGE}'.`);
const client = await new Swagger({
const client = await new SwaggerClient({
spec:JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
usePromise: true
});
client.clientAuthorizations.add(
'AuthorizationBotConnector',
new Swagger.ApiKeyAfuthorization('Authorization', `Bearer ${min.instance.webchatKey}`, 'header')
);
const response = await client.Conversations.Conversations_StartConversation();
requestInterceptor: req => {
req.headers["Authorization"] = `Bearer ${min.instance.webchatKey}`
}});
const response = await client.apis.Conversations.Conversations_StartConversation();
const conversationId = response.obj.conversationId;
GBServer.globals.debugConversationId = conversationId;
@ -351,7 +349,7 @@ export class GBMinService {
};
await CollectionUtil.asyncForEach(steps, async step => {
client.Conversations.Conversations_PostActivity({
client.apis.Conversations.Conversations_PostActivity({
conversationId: conversationId,
activity: {
textFormat: 'plain',
@ -411,7 +409,7 @@ export class GBMinService {
GBDeployer.mountGBKBAssets(`${instance.botId}.gbkb`, instance.botId, `${instance.botId}.gbkb`);
}
public static isChatAPI(req, res) {
public static isChatAPI(req:any, res: any) {
if (!res) {
return 'GeneralBots';
}