Skip to content

Commit

Permalink
fix(core.gbapp): fixed the use of GBLogEx to create GuaribasLog.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanPerdomo committed Apr 21, 2023
1 parent 97df425 commit 2cb866b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"node_modules/**/*.js"
],
"outFiles": [
"${workspaceRoot}/dist/**/*.js"],
"${workspaceRoot}/dist/**/*.js",
"D:/VScode/Pragmatismo/GBO.gbai/saas.gbapp/dist/**/*.js"],
"stopOnEntry": false,
"console": "integratedTerminal"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"vm2-process": "2.1.1",
"walk-promise": "0.2.0",
"washyourmouthoutwithsoap": "1.0.2",
"whatsapp-web.js": "github:meetscrm/whatsapp-web.js#8a46b65e2284ae2b031b5a9217e33ec2bab2e579",
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
"winston": "3.8.2",
"winston-logs-display": "1.0.0",
"ws": "8.12.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
import crypto from 'crypto';
import urlJoin from 'url-join';
import { WaterfallDialog } from 'botbuilder-dialogs';
import { GBMinInstance, IGBDialog } from 'botlib';
import { GBLog, GBMinInstance, IGBDialog } from 'botlib';
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { GBImporter } from '../../core.gbapp/services/GBImporterService.js';
import { Messages } from '../strings.js';
import { GBAdminService } from '../services/GBAdminService.js';
import { CollectionUtil } from 'pragmatismo-io-framework';
import { SecService } from '../../security.gbapp/services/SecService.js';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';

/**
* Dialogs for administration tasks.
Expand Down
10 changes: 6 additions & 4 deletions packages/admin.gbapp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBPackage } from '
import { Sequelize } from 'sequelize-typescript';
import { AdminDialog } from './dialogs/AdminDialog.js';
import { GuaribasAdmin } from './models/AdminModel.js';
import { GBLogEx } from '../core.gbapp/services/GBLogEx.js';


/**
* The package for admin.gbapp.
Expand All @@ -48,19 +50,19 @@ export class GBAdminPackage implements IGBPackage {
public sysPackages: IGBPackage[];

public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);
GBLogEx.verbose(min,`getDialogs called.`);
}
public async unloadPackage (core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`);
}
public async unloadBot (min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`);
GBLogEx.verbose(min,`unloadBot called.`);
}
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`);
GBLogEx.verbose(min, `onNewSession called.`);
}
public async onExchangeData (min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`);
GBLogEx.verbose(min,`onExchangeData called.`);
}

public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
Expand Down
7 changes: 4 additions & 3 deletions packages/basic.gblib/services/ScheduleServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
import { GuaribasSchedule } from '../../core.gbapp/models/GBModel.js';

import cron from 'node-cron';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';

/**
* @fileoverview Schedule Services.
Expand All @@ -64,7 +65,7 @@ export class ScheduleServices extends GBService {
});

if (count > 0) {
GBLog.info(`BASIC: Removed ${name} SET SCHEDULE and ${count} rows from storage on: ${min.botId}...`);
GBLogEx.info(min,`BASIC: Removed ${name} SET SCHEDULE and ${count} rows from storage on: ${min.botId}...`);
}
}

Expand Down Expand Up @@ -118,7 +119,7 @@ export class ScheduleServices extends GBService {
}

private ScheduleItem (item: GuaribasSchedule, min: GBMinInstance) {
GBLog.info(`Scheduling ${item.name} on ${min.botId}...`);
GBLogEx.info(min,`Scheduling ${item.name} on ${min.botId}...`);
try {
const options = {
scheduled: true,
Expand Down Expand Up @@ -147,7 +148,7 @@ export class ScheduleServices extends GBService {
},
options
);
GBLog.info(`Running .gbdialog word ${item.name} on:${item.schedule}...`);
GBLogEx.info(min,`Running .gbdialog word ${item.name} on:${item.schedule}...`);
} catch (error) {}
}
}
13 changes: 7 additions & 6 deletions packages/basic.gblib/services/WebAutomationServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class WebAutomationServices {
*/

public async openPage({ pid, handle, sessionKind, sessionName, url, username, password }) {
GBLog.info(`BASIC: Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);
const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min,`BASIC: Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);

// Try to find an existing handle.

Expand Down Expand Up @@ -195,9 +195,10 @@ export class WebAutomationServices {
*
* @example GET "selector"
*/
public async getBySelector({ handle, selector }) {
public async getBySelector({ handle, selector, pid }) {
const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation GET element: ${selector}.`);
const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min,`BASIC: Web Automation GET element: ${selector}.`);
await page.waitForSelector(selector);
let elements = await page.$$(selector);
if (elements && elements.length > 1) {
Expand Down Expand Up @@ -241,7 +242,7 @@ export class WebAutomationServices {
public async hover({ pid, handle, selector }) {
const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation HOVER element: ${selector}.`);
await this.getBySelector({ handle, selector: selector });
await this.getBySelector({ handle, selector: selector, pid });
await page.hover(selector);
await this.debugStepWeb(pid, page);
}
Expand Down Expand Up @@ -346,7 +347,7 @@ export class WebAutomationServices {
text = `${text}`;
const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation TYPE on ${selector}: ${text}.`);
const e = await this.getBySelector({ handle, selector });
const e = await this.getBySelector({ handle, selector, pid });
await e.click({ clickCount: 3 });
await page.keyboard.press('Backspace');
await e.type(text, { delay: 200 });
Expand All @@ -362,7 +363,7 @@ export class WebAutomationServices {
const { min, user } = await DialogKeywords.getProcessInfo(pid);
const page = WebAutomationServices.getPageByHandle(handle);

const element = await this.getBySelector({ handle, selector });
const element = await this.getBySelector({ handle, selector, pid });
// https://github.com/GeneralBots/BotServer/issues/311
const container = element['_frame'] ? element['_frame'] : element['_page'];
await page.setRequestInterception(true);
Expand Down
6 changes: 3 additions & 3 deletions packages/basic.gblib/services/vm2-process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CollectionUtil } from 'pragmatismo-io-framework';
import { GBServer } from '../../../../src/app.js';
import { DebuggerService } from '../DebuggerService.js';
import finalStream from 'final-stream';
import { GBLogEx } from '../../../core.gbapp/services/GBLogEx.js';

const waitUntil = condition => {
if (condition()) {
Expand Down Expand Up @@ -119,8 +120,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
});
}
GBServer.globals.debuggers[limits.botId].scope = variablesText;
GBLog.info(`BASIC: Breakpoint variables: ${variablesText}`); // (zero-based)

GBLogEx.info(min,`BASIC: Breakpoint variables: ${variablesText}`); // (zero-based)
// Processes breakpoint hits.

if (hitBreakpoints.length >= 1) {
Expand All @@ -142,7 +142,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
});
GBLog.info(`BASIC break defined ${breakpointId} for ${limits.botId}`);
} catch (error) {
GBLog.info(`BASIC error defining defining ${brk} for ${limits.botId}. ${error}`);
GBLog.info(`BASIC error defining ${brk} for ${limits.botId}. ${error}`);
}
});
await client.Debugger.resume();
Expand Down
25 changes: 13 additions & 12 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export class GBDeployer implements IGBDeployer {
const siteId = process.env.STORAGE_SITE_ID;
const libraryId = process.env.STORAGE_LIBRARY;

GBLog.info(`Connecting to Config.xslx (siteId: ${siteId}, libraryId: ${libraryId})...`);
GBLogEx.info(min, `Connecting to Config.xslx (siteId: ${siteId}, libraryId: ${libraryId})...`);

// Connects to MSFT storage.

Expand All @@ -414,16 +414,17 @@ export class GBDeployer implements IGBDeployer {
const path = DialogKeywords.getGBAIPath(botId, 'gbot');
let url = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:/${path}:/children`;

GBLog.info(`Loading .gbot from Excel: ${url}`);
GBLogEx.info( min ,`Loading .gbot from Excel: ${url}`);
const res = await client.api(url).get();

// Finds Config.xlsx.


const document = res.value.filter(m => {
return m.name === 'Config.xlsx';
});
if (document === undefined || document.length === 0) {
GBLog.info(`Config.xlsx not found on .bot folder, check the package.`);
GBLogEx.info(min,`Config.xlsx not found on .bot folder, check the package.`);

return null;
}
Expand Down Expand Up @@ -458,7 +459,7 @@ export class GBDeployer implements IGBDeployer {
baseUrl: string = null,
client = null
): Promise<any> {
GBLog.info(`downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`);
GBLogEx.info(min ,`downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`);

if (!baseUrl) {
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
Expand Down Expand Up @@ -487,12 +488,12 @@ export class GBDeployer implements IGBDeployer {
path = urlJoin(path, remotePath);
let url = `${baseUrl}/drive/root:/${path}:/children`;

GBLog.info(`Download URL: ${url}`);
GBLogEx.info(min, `Download URL: ${url}`);

const res = await client.api(url).get();
const documents = res.value;
if (documents === undefined || documents.length === 0) {
GBLog.info(`${remotePath} is an empty folder.`);
GBLogEx.info(min, `${remotePath} is an empty folder.`);
return null;
}

Expand All @@ -518,14 +519,14 @@ export class GBDeployer implements IGBDeployer {
}

if (download) {
GBLog.verbose(`Downloading ${itemPath}...`);
GBLogEx.verbose(min, `Downloading ${itemPath}...`);
const url = item['@microsoft.graph.downloadUrl'];

const response = await fetch(url);
Fs.writeFileSync(itemPath, Buffer.from(await response.arrayBuffer()), { encoding: null });
Fs.utimesSync(itemPath, new Date(), new Date(item.lastModifiedDateTime));
} else {
GBLog.info(`Local is up to date: ${itemPath}...`);
GBLogEx.info(min, `Local is up to date: ${itemPath}...`);
}
}
});
Expand Down Expand Up @@ -609,7 +610,7 @@ export class GBDeployer implements IGBDeployer {

if (process.env.ENABLE_PARAMS_ONLINE === 'false') {
if (Fs.existsSync(localPath)) {
GBLog.info(`Loading .gbot from ${localPath}.`);
GBLogEx.info(min, `Loading .gbot from ${localPath}.`);
await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress);
}
} else {
Expand All @@ -635,15 +636,15 @@ export class GBDeployer implements IGBDeployer {

const vm = new GBVMService();
await vm.loadDialogPackage(localPath, min, this.core, this);
GBLog.verbose(`Dialogs (.gbdialog) for ${min.botId} loaded.`);
GBLogEx.verbose(min, `Dialogs (.gbdialog) for ${min.botId} loaded.`);
break;

case '.gbtheme':
// Updates server listeners to serve theme files in .gbtheme.

const packageName = Path.basename(localPath);
GBServer.globals.server.use(`/themes/${packageName}`, express.static(localPath));
GBLog.verbose(`Theme (.gbtheme) assets accessible at: /themes/${packageName}.`);
GBLogEx.verbose(min, `Theme (.gbtheme) assets accessible at: /themes/${packageName}.`);

break;

Expand Down Expand Up @@ -887,7 +888,7 @@ export class GBDeployer implements IGBDeployer {
// After compiled, adds the .gbapp to the current server VM context.

if (gbappPath.endsWith('.gbapp') || gbappPath.endsWith('.gblib')) {
const m = await import(gbappPath);
const m = await import(`file://${gbappPath}/dist/index.js`);
if (m.Package) {
const p = new m.Package();

Expand Down
11 changes: 5 additions & 6 deletions packages/core.gbapp/services/GBLogEx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ export class GBLogEx {
*/
public static async log(instance: IGBInstance, kind: string, message: string): Promise<GuaribasLog> {
message = message ? message.substring(0, 1023) : null;
// return await GuaribasLog.create(<GuaribasLog>{
// instanceId: instance ? instance.instanceId : 1,
// message: message,
// kind: kind
// });
return null;
return await GuaribasLog.create(<GuaribasLog>{
instanceId: instance ? instance.instanceId : 1,
message: message,
kind: kind
});
}
}
3 changes: 3 additions & 0 deletions packages/core.gbapp/services/GBSSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ export class GBSSR {
'build',
url === '/' || url === '' ? `index.html` : url
);
if (GBServer.globals.wwwroot && url === '/'){
path = GBServer.globals.wwwroot + "\\index.html";
}
if (Fs.existsSync(path)) {
if (min) {
let html = Fs.readFileSync(path, 'utf8');
Expand Down

0 comments on commit 2cb866b

Please sign in to comment.