From 2cb866bc2f1f8a5157eddfdecf974e3a31f1280d Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 20 Apr 2023 22:41:58 -0300 Subject: [PATCH] fix(core.gbapp): fixed the use of GBLogEx to create GuaribasLog. --- .vscode/launch.json | 3 ++- package.json | 2 +- packages/admin.gbapp/dialogs/AdminDialog.ts | 3 ++- packages/admin.gbapp/index.ts | 10 +++++--- .../basic.gblib/services/ScheduleServices.ts | 7 +++--- .../services/WebAutomationServices.ts | 13 +++++----- .../basic.gblib/services/vm2-process/index.ts | 6 ++--- packages/core.gbapp/services/GBDeployer.ts | 25 ++++++++++--------- packages/core.gbapp/services/GBLogEx.ts | 11 ++++---- packages/core.gbapp/services/GBSSR.ts | 3 +++ 10 files changed, 46 insertions(+), 37 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9e3fe8b90..4394dd2cc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" } diff --git a/package.json b/package.json index 99f40e461..2a6324e9d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/admin.gbapp/dialogs/AdminDialog.ts b/packages/admin.gbapp/dialogs/AdminDialog.ts index f405d6110..2d095c882 100644 --- a/packages/admin.gbapp/dialogs/AdminDialog.ts +++ b/packages/admin.gbapp/dialogs/AdminDialog.ts @@ -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. diff --git a/packages/admin.gbapp/index.ts b/packages/admin.gbapp/index.ts index 3d6704017..e25d048b2 100644 --- a/packages/admin.gbapp/index.ts +++ b/packages/admin.gbapp/index.ts @@ -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. @@ -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 { GBLog.verbose(`unloadPackage called.`); } public async unloadBot (min: GBMinInstance): Promise { - GBLog.verbose(`unloadBot called.`); + GBLogEx.verbose(min,`unloadBot called.`); } public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise { - 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 { diff --git a/packages/basic.gblib/services/ScheduleServices.ts b/packages/basic.gblib/services/ScheduleServices.ts index e882cb518..0eca2e1e4 100644 --- a/packages/basic.gblib/services/ScheduleServices.ts +++ b/packages/basic.gblib/services/ScheduleServices.ts @@ -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. @@ -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}...`); } } @@ -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, @@ -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) {} } } diff --git a/packages/basic.gblib/services/WebAutomationServices.ts b/packages/basic.gblib/services/WebAutomationServices.ts index e2beef6b9..432b81b85 100644 --- a/packages/basic.gblib/services/WebAutomationServices.ts +++ b/packages/basic.gblib/services/WebAutomationServices.ts @@ -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. @@ -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) { @@ -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); } @@ -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 }); @@ -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); diff --git a/packages/basic.gblib/services/vm2-process/index.ts b/packages/basic.gblib/services/vm2-process/index.ts index 64605b185..9bbf3ddc9 100644 --- a/packages/basic.gblib/services/vm2-process/index.ts +++ b/packages/basic.gblib/services/vm2-process/index.ts @@ -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()) { @@ -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) { @@ -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(); diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 16db8d90f..3144656ee 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -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. @@ -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; } @@ -458,7 +459,7 @@ export class GBDeployer implements IGBDeployer { baseUrl: string = null, client = null ): Promise { - 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); @@ -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; } @@ -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}...`); } } }); @@ -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 { @@ -635,7 +636,7 @@ 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': @@ -643,7 +644,7 @@ export class GBDeployer implements IGBDeployer { 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; @@ -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(); diff --git a/packages/core.gbapp/services/GBLogEx.ts b/packages/core.gbapp/services/GBLogEx.ts index aade79265..a57db04f5 100644 --- a/packages/core.gbapp/services/GBLogEx.ts +++ b/packages/core.gbapp/services/GBLogEx.ts @@ -77,11 +77,10 @@ export class GBLogEx { */ public static async log(instance: IGBInstance, kind: string, message: string): Promise { message = message ? message.substring(0, 1023) : null; - // return await GuaribasLog.create({ - // instanceId: instance ? instance.instanceId : 1, - // message: message, - // kind: kind - // }); - return null; + return await GuaribasLog.create({ + instanceId: instance ? instance.instanceId : 1, + message: message, + kind: kind + }); } } diff --git a/packages/core.gbapp/services/GBSSR.ts b/packages/core.gbapp/services/GBSSR.ts index aa1b30f03..4de8051a2 100644 --- a/packages/core.gbapp/services/GBSSR.ts +++ b/packages/core.gbapp/services/GBSSR.ts @@ -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');