new(basic.gblib): VBS to JS directly now and minor fixes.

This commit is contained in:
rodrigorodriguez 2023-01-29 12:02:14 -03:00
parent 786fc7ea1c
commit 3d6bc56eca
11 changed files with 190 additions and 429 deletions

View file

@ -1,7 +1,7 @@
dist: focal dist: focal
language: node_js language: node_js
node_js: node_js:
- 19.4.0 - 19.5.0
notifications: notifications:

View file

@ -14,7 +14,7 @@
"Dário Vieira <dario.junior3@gmail.com>" "Dário Vieira <dario.junior3@gmail.com>"
], ],
"engines": { "engines": {
"node": "=19.4.0" "node": "=19.5.0"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
"preferGlobal": true, "preferGlobal": true,

View file

@ -312,7 +312,6 @@ export class AdminDialog extends IGBDialog {
} }
await CollectionUtil.asyncForEach(packages, async packageName => { await CollectionUtil.asyncForEach(packages, async packageName => {
try {
let cmd1; let cmd1;
if (packageName.indexOf('.') !== -1) { if (packageName.indexOf('.') !== -1) {
cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`; cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;
@ -328,14 +327,6 @@ export class AdminDialog extends IGBDialog {
} }
await GBAdminService.deployPackageCommand(min, cmd1, deployer); await GBAdminService.deployPackageCommand(min, cmd1, deployer);
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`); await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
} catch (error) {
GBLog.error(error);
if (!skipError) {
await min.conversationalService.sendText(min, step, `ERROR: ${error}`);
return await step.replaceDialog('/ask', { isReturning: true });
}
}
}); });
await min.conversationalService.sendText(min, step, Messages[locale].publish_success); await min.conversationalService.sendText(min, step, Messages[locale].publish_success);
if (!step.activeDialog.state.options.confirm) { if (!step.activeDialog.state.options.confirm) {

View file

@ -37,7 +37,7 @@
'use strict'; 'use strict';
import { AuthenticationContext, TokenResponse } from 'adal-node'; import { AuthenticationContext, TokenResponse } from 'adal-node';
import { GBMinInstance, IGBAdminService, IGBCoreService, IGBDeployer, IGBInstance } from 'botlib'; import { GBError, GBLog, GBMinInstance, IGBAdminService, IGBCoreService, IGBDeployer, IGBInstance } from 'botlib';
import { FindOptions } from 'sequelize/types'; import { FindOptions } from 'sequelize/types';
import urlJoin from 'url-join'; import urlJoin from 'url-join';
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js'; import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js';
@ -205,18 +205,23 @@ export class GBAdminService implements IGBAdminService {
const options = <FindOptions>{ where: {} }; const options = <FindOptions>{ where: {} };
options.where = { key: key, instanceId: instanceId }; options.where = { key: key, instanceId: instanceId };
const obj = await GuaribasAdmin.findOne(options); const obj = await GuaribasAdmin.findOne(options);
return obj.value; return obj.value;
} }
public async acquireElevatedToken(instanceId: number): Promise<string> { public async acquireElevatedToken(instanceId: number): Promise<string> {
const minBoot = GBServer.globals.minBoot; const minBoot = GBServer.globals.minBoot;
instanceId = minBoot.instance.instanceId; instanceId = minBoot.instance.instanceId;
let expiresOnV;
try {
expiresOnV = await this.getValue(instanceId, 'expiresOn');
} catch (error) {
throw new Error(`/setupSecurity is required before running /publish.`);
}
return new Promise<string>(async (resolve, reject) => { return new Promise<string>(async (resolve, reject) => {
const instance = await this.core.loadInstanceById(instanceId); const instance = await this.core.loadInstanceById(instanceId);
const expiresOn = new Date(await this.getValue(instanceId, 'expiresOn')); const expiresOn = new Date(expiresOnV);
if (expiresOn.getTime() > new Date().getTime()) { if (expiresOn.getTime() > new Date().getTime()) {
const accessToken = await this.getValue(instanceId, 'accessToken'); const accessToken = await this.getValue(instanceId, 'accessToken');
resolve(accessToken); resolve(accessToken);

View file

@ -42,7 +42,7 @@ import { CognitiveServicesManagementClient } from '@azure/arm-cognitiveservices'
import { ResourceManagementClient } from '@azure/arm-resources'; import { ResourceManagementClient } from '@azure/arm-resources';
import { SubscriptionClient } from '@azure/arm-subscriptions'; import { SubscriptionClient } from '@azure/arm-subscriptions';
import { SearchManagementClient } from '@azure/arm-search'; import { SearchManagementClient } from '@azure/arm-search';
import { SqlManagementClient } from '@azure/arm-sql'; import { Server, SqlManagementClient } from '@azure/arm-sql';
import { WebSiteManagementClient } from '@azure/arm-appservice'; import { WebSiteManagementClient } from '@azure/arm-appservice';
import { AppServicePlan, Site, SiteLogsConfig, SiteSourceControl } from '@azure/arm-appservice'; import { AppServicePlan, Site, SiteLogsConfig, SiteSourceControl } from '@azure/arm-appservice';
import { GBLog, IGBInstallationDeployer, IGBInstance, IGBDeployer, IGBCoreService } from 'botlib'; import { GBLog, IGBInstallationDeployer, IGBInstance, IGBDeployer, IGBCoreService } from 'botlib';
@ -56,8 +56,6 @@ import {Spinner} from 'cli-spinner';
import * as publicIp from 'public-ip'; import * as publicIp from 'public-ip';
import { AccessToken, TokenCredential } from '@azure/core-auth'; import { AccessToken, TokenCredential } from '@azure/core-auth';
const WebSiteResponseTimeout = 900; const WebSiteResponseTimeout = 900;
const iconUrl = 'https://github.com/pragmatismo-io/BotServer/blob/master/docs/images/generalbots-logo-squared.png'; const iconUrl = 'https://github.com/pragmatismo-io/BotServer/blob/master/docs/images/generalbots-logo-squared.png';
/** /**
@ -82,13 +80,11 @@ export class AzureDeployerService implements IGBInstallationDeployer {
public core: IGBCoreService; public core: IGBCoreService;
private freeTier: boolean; private freeTier: boolean;
public async runSearch(instance: IGBInstance) { public async runSearch(instance: IGBInstance) {
await this.deployer.rebuildIndex(instance, this.getKBSearchSchema(instance.searchIndex)); await this.deployer.rebuildIndex(instance, this.getKBSearchSchema(instance.searchIndex));
} }
public static async createInstance(deployer: GBDeployer, freeTier: boolean = true): Promise<AzureDeployerService> { public static async createInstance(deployer: GBDeployer, freeTier: boolean = true): Promise<AzureDeployerService> {
const username = GBConfigService.get('CLOUD_USERNAME'); const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD'); const password = GBConfigService.get('CLOUD_PASSWORD');
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID'); const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
@ -272,9 +268,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
} }
}; };
const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${ const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider}/botServices/${botId}?api-version=${this.apiVersion}`;
this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query); const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters)); const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters));
const res = await httpClient.sendRequest(req); const res = await httpClient.sendRequest(req);
@ -303,9 +297,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
} }
}; };
const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${ const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider}/botServices/${botId}?api-version=${this.apiVersion}`;
this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query); const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters)); const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters));
const res = await httpClient.sendRequest(req); const res = await httpClient.sendRequest(req);
@ -325,9 +317,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password); const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const httpClient = new ServiceClient(); const httpClient = new ServiceClient();
const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${ const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider}/botServices/${botId}?api-version=${this.apiVersion}`;
this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query); const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'DELETE', undefined); const req = AzureDeployerService.createRequestObject(url, accessToken, 'DELETE', undefined);
const res = await httpClient.sendRequest(req); const res = await httpClient.sendRequest(req);
@ -341,7 +331,6 @@ export class AzureDeployerService implements IGBInstallationDeployer {
public async openStorageFirewall(groupName: string, serverName: string) { public async openStorageFirewall(groupName: string, serverName: string) {
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID'); const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
const ip = await publicIp.publicIpv4(); const ip = await publicIp.publicIpv4();
let params = { let params = {
startIpAddress: ip, startIpAddress: ip,
@ -550,9 +539,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}; };
const httpClient = new ServiceClient(); const httpClient = new ServiceClient();
let query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${ let query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider}/botServices/${botId}?api-version=${this.apiVersion}`;
this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
let url = urlJoin(baseUrl, query); let url = urlJoin(baseUrl, query);
let req = AzureDeployerService.createRequestObject(url, accessToken, 'PUT', JSON.stringify(parameters)); let req = AzureDeployerService.createRequestObject(url, accessToken, 'PUT', JSON.stringify(parameters));
const res = await httpClient.sendRequest(req); const res = await httpClient.sendRequest(req);
@ -564,9 +551,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
try { try {
//tslint:disable-next-line:max-line-length //tslint:disable-next-line:max-line-length
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${ query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${this.apiVersion}`;
this.apiVersion
}`;
url = urlJoin(baseUrl, query); url = urlJoin(baseUrl, query);
req = AzureDeployerService.createRequestObject(url, accessToken, 'POST', JSON.stringify(parameters)); req = AzureDeployerService.createRequestObject(url, accessToken, 'POST', JSON.stringify(parameters));
const resChannel = await httpClient.sendRequest(req); const resChannel = await httpClient.sendRequest(req);
@ -585,16 +570,13 @@ export class AzureDeployerService implements IGBInstallationDeployer {
} }
public async initServices(accessToken: string, expiresOnTimestamp, subscriptionId: string) { public async initServices(accessToken: string, expiresOnTimestamp, subscriptionId: string) {
this.accessToken = accessToken; this.accessToken = accessToken;
class AccessToken2 implements AccessToken class AccessToken2 implements AccessToken {
{
public expiresOnTimestamp: number; public expiresOnTimestamp: number;
public token: string; public token: string;
} }
class StaticAccessToken implements TokenCredential { class StaticAccessToken implements TokenCredential {
public getToken(): Promise<AccessToken> { public getToken(): Promise<AccessToken> {
return new Promise<AccessToken>(async (resolve, reject) => { return new Promise<AccessToken>(async (resolve, reject) => {
const t = new AccessToken2(); const t = new AccessToken2();
@ -614,15 +596,30 @@ export class AzureDeployerService implements IGBInstallationDeployer {
this.searchClient = new SearchManagementClient(token, subscriptionId); this.searchClient = new SearchManagementClient(token, subscriptionId);
} }
private async createStorageServer (group: string, name: string, administratorLogin: string, administratorPassword: string, serverName: string, location: string) { private async createStorageServer(
group: string,
name: string,
administratorLogin: string,
administratorPassword: string,
serverName: string,
location: string
) {
const params = { const params = {
location: location, location: location,
administratorLogin: administratorLogin, administratorLogin: administratorLogin,
administratorLoginPassword: administratorPassword, administratorLoginPassword: administratorPassword,
fullyQualifiedDomainName: serverName fullyQualifiedDomainName: serverName,
requestOptions: { timeout: 60 * 1000 * 5 }
}; };
const database = await this.storageClient.servers.beginCreateOrUpdateAndWait(group, name, params); let database: Server;
try {
database = await this.storageClient.servers.beginCreateOrUpdateAndWait(group, name, params);
} catch (error) {
// Try again (MSFT issues).
GBLog.info('Storage (server) creation failed. Retrying...');
database = await this.storageClient.servers.beginCreateOrUpdateAndWait(group, name, params);
}
// AllowAllWindowsAzureIps must be created that way, so the Azure Search can // AllowAllWindowsAzureIps must be created that way, so the Azure Search can
// access SQL Database to index its contents. // access SQL Database to index its contents.
@ -806,12 +803,21 @@ export class AzureDeployerService implements IGBInstallationDeployer {
private async createStorage(group: string, serverName: string, name: string, location: string) { private async createStorage(group: string, serverName: string, name: string, location: string) {
const params = { const params = {
sku: { name: this.freeTier ? 'Free' : 'Basic' }, sku: { name: 'Basic' },
createMode: 'Default', createMode: 'Default',
location: location location: location
}; };
return await this.storageClient.databases.beginCreateOrUpdateAndWait(group, serverName, name, params); let database;
try {
database = await this.storageClient.databases.beginCreateOrUpdateAndWait(group, serverName, name, params);
} catch (error) {
// Try again (MSFT issues).
GBLog.info('Storage (database) creation failed. Retrying...');
database = await this.storageClient.databases.beginCreateOrUpdateAndWait(group, serverName, name, params);
}
return database;
} }
private async createCognitiveServices(group: string, name: string, location: string, kind: string): Promise<Account> { private async createCognitiveServices(group: string, name: string, location: string, kind: string): Promise<Account> {

View file

@ -36,14 +36,12 @@ import { GBLog, GBMinInstance, GBService, IGBCoreService, GBDialogStep } from 'b
import * as Fs from 'fs'; import * as Fs from 'fs';
import { GBServer } from '../../../src/app.js'; import { GBServer } from '../../../src/app.js';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js'; import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { TSCompiler } from './TSCompiler.js';
import { CollectionUtil } from 'pragmatismo-io-framework'; import { CollectionUtil } from 'pragmatismo-io-framework';
import { ScheduleServices } from './ScheduleServices.js'; import { ScheduleServices } from './ScheduleServices.js';
import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js'; import { GBConfigService } from '../../core.gbapp/services/GBConfigService.js';
import urlJoin from 'url-join'; import urlJoin from 'url-join';
import { NodeVM, VMScript } from 'vm2'; import { NodeVM, VMScript } from 'vm2';
import { createVm2Pool } from './vm2-process/index.js'; import { createVm2Pool } from './vm2-process/index.js';
import * as vb2ts from './vbscript-to-typescript.js';
import textract from 'textract'; import textract from 'textract';
import walkPromise from 'walk-promise'; import walkPromise from 'walk-promise';
import child_process from 'child_process'; import child_process from 'child_process';
@ -208,21 +206,9 @@ export class GBVMService extends GBService {
Fs.writeFileSync(vbsFile, code); Fs.writeFileSync(vbsFile, code);
Fs.writeFileSync(mapFile, JSON.stringify(jsonMap)); Fs.writeFileSync(mapFile, JSON.stringify(jsonMap));
// Converts VBS into TS.
vb2ts.convertFile(vbsFile);
// Convert TS into JS.
const tsfile: string = `${filename}.ts`;
let tsCode: string = Fs.readFileSync(tsfile, 'utf8');
Fs.writeFileSync(tsfile, tsCode);
const tsc = new TSCompiler();
tsc.compile([tsfile]);
// Run JS into the GB context. // Run JS into the GB context.
const jsfile = `${tsfile}.js`.replace('.ts', ''); const jsfile: string = `${filename}.js`;
if (Fs.existsSync(jsfile)) { if (Fs.existsSync(jsfile)) {
let code: string = Fs.readFileSync(jsfile, 'utf8'); let code: string = Fs.readFileSync(jsfile, 'utf8');
@ -354,12 +340,9 @@ export class GBVMService extends GBService {
public async convertGBASICToVBS(min: GBMinInstance, code: string) { public async convertGBASICToVBS(min: GBMinInstance, code: string) {
// Start and End of VB2TS tags of processing. // Start and End of VB2TS tags of processing.
code = `<%\n code = `
${process.env.ENABLE_AUTH ? `hear gbLogin as login` : ``} ${process.env.ENABLE_AUTH ? `hear gbLogin as login` : ``}
${code} ${code}
`; `;
var allLines = code.split('\n'); var allLines = code.split('\n');
@ -388,6 +371,14 @@ export class GBVMService extends GBService {
let keywords = []; let keywords = [];
let i = 0; let i = 0;
const convertConditions = input => {
var result = input.replace(/ +and +/gi, ' && ');
result = result.replace(/ +or +/gi, ' || ');
result = result.replace(/ +<> +/gi, ' !== ');
result = result.replace(/ += +/gi, ' === ');
return result;
};
keywords[i++] = [ keywords[i++] = [
/^\s*(\w+)\s*\=\s*SELECT\s*(.*)/gim, /^\s*(\w+)\s*\=\s*SELECT\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {
@ -397,6 +388,40 @@ export class GBVMService extends GBService {
} }
]; ];
keywords[i++] = [
/if +(.*?) +then/gi,
(input, group1) => {
var condition = convertConditions(group1);
return '\nif (' + condition + ') {\n';
}
];
keywords[i++] = [/end if/gi, '\n}\n'];
keywords[i++] = [/else(?!{)/gi, '\n}\nelse {\n'];
keywords[i++] = [/select case +(.*)/gi, '\nswitch ($1) {\n'];
keywords[i++] = [/end select/gi, '\n}\n'];
keywords[i++] = [/function +(.*)\((.*)\)/gi, '\n$1 = ($2) => {\n'];
keywords[i++] = [/end function/gi, '\n}\n'];
keywords[i++] = [/for +(.*to.*)/gi, '\nfor ($1) {\n'];
keywords[i++] = [/^ *next *$/gim, '}\n'];
keywords[i++] = [
/do while +(.*)/gi,
function (input, group1) {
var condition = convertConditions(group1);
return '\nwhile (' + condition + ') {\n';
}
];
keywords[i++] = [/^ *loop *$/gim, '}\n'];
keywords[i++] = [ keywords[i++] = [
/^\s*open\s*(.*)/gim, /^\s*open\s*(.*)/gim,
($0, $1, $2) => { ($0, $1, $2) => {

View file

@ -1,102 +0,0 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' v `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| (˅) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
/**
* @fileoverview General Bots server core.
*/
'use strict';
import { GBLog } from 'botlib';
import ts from 'typescript';
/**
* Wrapper for a TypeScript compiler.
*/
export class TSCompiler {
private static shouldIgnoreError (diagnostic) {
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if (
message.indexOf('Cannot find name') >= 0 ||
message.indexOf('Cannot find module') >= 0 ||
message.indexOf('implicitly has an') >= 0 ||
message.indexOf('Cannot invoke an') >= 0 ||
message.indexOf('Cannot use imports, exports, or module') >= 0
) {
return true;
}
return false;
}
public compile (
fileNames: string[],
options: ts.CompilerOptions = {
noStrictGenericChecks: true,
noImplicitUseStrict: true,
noEmitOnError: false,
noImplicitAny: true,
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.None,
moduleResolution: ts.ModuleResolutionKind.Classic,
noEmitHelpers: true,
maxNodeModuleJsDepth: 0,
esModuleInterop: false
}
) {
const program = ts.createProgram(fileNames, options);
const emitResult = program.emit();
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
allDiagnostics.forEach(diagnostic => {
if (!TSCompiler.shouldIgnoreError(diagnostic)) {
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if (diagnostic.file !== undefined) {
if (
diagnostic.file.fileName.indexOf('readable-stream') == -1 &&
diagnostic.file.fileName.indexOf('request-promise') == -1
) {
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
GBLog.error(`BASIC error: ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
}
} else {
GBLog.error(`BASIC error: ${message}`);
}
}
});
return emitResult;
}
}

View file

@ -145,7 +145,7 @@ export class WebAutomationKeywords {
/** /**
* Find element on page DOM. * Find element on page DOM.
* *
* @example GET page,"selector" * @example GET "selector"
*/ */
public async getBySelector ({ handle, selector }) { public async getBySelector ({ handle, selector }) {
const page = this.getPageByHandle(handle); const page = this.getPageByHandle(handle);

View file

@ -1,156 +0,0 @@
// Source: https://github.com/uweg/vbscript-to-typescript
'use strict';
import fs_1 from 'fs';
import path from 'path';
export function convertFile (file) {
var extension = path.extname(file);
var withoutExtension = file.substr(0, file.length - extension.length);
var targetFile = withoutExtension + '.ts';
var baseName = path.basename(file, extension);
var content = fs_1.readFileSync(file, 'utf8');
var result = convert(content, baseName);
console.log('Writing to "' + targetFile + '"...');
fs_1.writeFileSync(targetFile, result);
}
export function convert (input, name) {
var result = convertImports(input, name);
return result;
}
function convertImports (input, name) {
var items = [];
var result = input.replace(/<!-- #include file="(.*?\/)?(.*?).asp" -->/gi, function (input, group1, group2) {
var path = group1 || './';
var file = '' + path + group2;
items.push({ name: group2, path: file });
return '<%\n' + group2 + '();\n%>';
});
result = convertCode(result);
result = convertExpressions(result);
result = convertStrings(result);
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
var item = items_1[_i];
result = 'import {' + item.name + '} from "' + item.path + '"\n' + result;
}
return result;
}
function convertCode (input) {
var result = input.replace(/<%([^=][\s\S]*?)%>/gi, function (input, group1) {
var code = group1;
code = convertComments(code);
code = convertIfStatements(code);
code = convertSwitchStatements(code);
code = convertFunctions(code);
code = convertForStatements(code);
code = convertLoops(code);
code = convertPRec(code);
code = convertPLan(code);
return '<%' + code + '%>';
});
return result;
}
function convertExpressions (input) {
var result = input.replace(/<%=([\s\S]*?)%>/gi, function (input, group1) {
var content = convertPRec(group1);
content = convertPLan(content);
return '${' + content + '}';
});
return result;
}
function convertStrings (input) {
var result = input.replace(/%>([\s\S]+?)<%/gi, '\nResponse.Write(`$1`);\n');
// Entire document is a string
if (result.indexOf('<%') === -1) {
result = 'Response.Write(`' + result + '`);';
}
// Start of the document is a string
var firstIndex = result.indexOf('<%');
if (firstIndex > 0) {
result = 'Response.Write(`' + result.substr(0, firstIndex) + '`);\n' + result.substring(firstIndex + 2);
}
result = result.replace(/%>$/, '');
// End of the document is a string
var lastIndex = result.lastIndexOf('%>');
if (lastIndex > -1 && lastIndex < result.length - 2) {
result = result.substr(0, lastIndex) + '\nResponse.Write(`' + result.substr(lastIndex + 3) + '`);';
}
result = result.replace(/^<%/, '');
return result;
}
function convertComments (input) {
var result = '';
var splitted = input.split(/(".*")/gim);
for (var _i = 0, splitted_1 = splitted; _i < splitted_1.length; _i++) {
var part = splitted_1[_i];
if (part.indexOf('"') === 0) {
result += part;
} else {
result += part.replace(/'/gi, '//');
}
}
return result;
}
function convertIfStatements (input) {
var result = input.replace(/if +(.*?) +then/gi, function (input, group1) {
var condition = convertConditions(group1);
return '\nif (' + condition + ') {\n';
});
result = result.replace(/end if/gi, '\n}\n');
result = result.replace(/else(?!{)/gi, '\n}\nelse {\n');
return result;
}
function convertSwitchStatements (input) {
var result = input.replace(/select case +(.*)/gi, '\nswitch ($1) {\n');
result = result.replace(/end select/gi, '\n}\n');
return result;
}
function convertFunctions (input) {
var result = input.replace(/function +(.*)\((.*)\)/gi, '\n$1 = ($2) => {\n');
result = result.replace(/end function/gi, '\n}\n');
return result;
}
function convertForStatements (input) {
var result = input.replace(/for +(.*to.*)/gi, '\nfor ($1) {\n');
result = result.replace(/^ *next *$/gim, '}\n');
return result;
}
function convertConditions (input) {
var result = input.replace(/ +and +/gi, ' && ');
result = result.replace(/ +or +/gi, ' || ');
result = result.replace(/ +<> +/gi, ' !== ');
result = result.replace(/ += +/gi, ' === ');
return result;
}
function convertLoops (input) {
var result = input.replace(/do while +(.*)/gi, function (input, group1) {
var condition = convertConditions(group1);
return '\nwhile (' + condition + ') {\n';
});
result = result.replace(/^ *loop *$/gim, '}\n');
return result;
}
function convertPRec (input) {
var result = input.replace(/(p_rec\("\S+?"\))/gi, '$1.Value');
return result;
}
function convertPLan (input) {
var result = input.replace(/(l_\S+?)\(p_lan\)/gi, '$1[p_lan]');
return result;
}

View file

@ -95,9 +95,7 @@ export class GBDeployer implements IGBDeployer {
* use to database like the Indexer (Azure Search). * use to database like the Indexer (Azure Search).
*/ */
public static getConnectionStringFromInstance(instance: IGBInstance) { public static getConnectionStringFromInstance(instance: IGBInstance) {
return `Server=tcp:${instance.storageServer},1433;Database=${instance.storageName};User ID=${ return `Server=tcp:${instance.storageServer},1433;Database=${instance.storageName};User ID=${instance.storageUsername};Password=${instance.storagePassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`;
instance.storageUsername
};Password=${instance.storagePassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;`;
} }
/** /**
@ -433,9 +431,7 @@ export class GBDeployer implements IGBDeployer {
const results = await client const results = await client
.api( .api(
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${ `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/items/${document[0].id}/workbook/worksheets('General')/range(address='A7:B100')`
document[0].id
}/workbook/worksheets('General')/range(address='A7:B100')`
) )
.get(); .get();
let index = 0, let index = 0,
@ -575,7 +571,6 @@ export class GBDeployer implements IGBDeployer {
const _this = this; const _this = this;
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => { await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
try {
// If it will be handled, create a temporary service layer to be // If it will be handled, create a temporary service layer to be
// called by .gbapp and manage the associated package row. // called by .gbapp and manage the associated package row.
@ -595,9 +590,6 @@ export class GBDeployer implements IGBDeployer {
) { ) {
handled = true; handled = true;
} }
} catch (error) {
GBLog.error(error);
}
}); });
if (handled) { if (handled) {
@ -663,9 +655,7 @@ export class GBDeployer implements IGBDeployer {
break; break;
default: default:
const err = GBError.create(`Unhandled package type: ${packageType}.`); throw GBError.create(`Unhandled package type: ${packageType}.`);
Promise.reject(err);
break;
} }
} }

View file

@ -96,9 +96,11 @@ export class GBServer {
server.use(bodyParser.urlencoded({ extended: true })); server.use(bodyParser.urlencoded({ extended: true }));
process.on('unhandledRejection', (err, p) => { process.on('unhandledRejection', (err, p) => {
console.log('An unhandledRejection occurred'); GBLog.error(`UNHANDLED_REJECTION(promises): ${p} ${err.toString()}`);
console.log(`Rejected Promise: ${p}`); });
console.log(`Rejection: ${err}`);
process.on('uncaughtException', (err, origin) => {
GBLog.error(`UNCAUGHT_EXCEPTION: ${err.toString()}`);
}); });
// Creates working directory. // Creates working directory.