fix(core.gbapp): fixed the use of GBLogEx to create GuaribasLog.

This commit is contained in:
Alan 2023-04-20 22:41:58 -03:00
parent 97df425566
commit 2cb866bc2f
10 changed files with 46 additions and 37 deletions

3
.vscode/launch.json vendored
View file

@ -21,7 +21,8 @@
"node_modules/**/*.js" "node_modules/**/*.js"
], ],
"outFiles": [ "outFiles": [
"${workspaceRoot}/dist/**/*.js"], "${workspaceRoot}/dist/**/*.js",
"D:/VScode/Pragmatismo/GBO.gbai/saas.gbapp/dist/**/*.js"],
"stopOnEntry": false, "stopOnEntry": false,
"console": "integratedTerminal" "console": "integratedTerminal"
} }

View file

@ -177,7 +177,7 @@
"vm2-process": "2.1.1", "vm2-process": "2.1.1",
"walk-promise": "0.2.0", "walk-promise": "0.2.0",
"washyourmouthoutwithsoap": "1.0.2", "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": "3.8.2",
"winston-logs-display": "1.0.0", "winston-logs-display": "1.0.0",
"ws": "8.12.1", "ws": "8.12.1",

View file

@ -39,13 +39,14 @@
import crypto from 'crypto'; import crypto from 'crypto';
import urlJoin from 'url-join'; import urlJoin from 'url-join';
import { WaterfallDialog } from 'botbuilder-dialogs'; 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 { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
import { GBImporter } from '../../core.gbapp/services/GBImporterService.js'; import { GBImporter } from '../../core.gbapp/services/GBImporterService.js';
import { Messages } from '../strings.js'; import { Messages } from '../strings.js';
import { GBAdminService } from '../services/GBAdminService.js'; import { GBAdminService } from '../services/GBAdminService.js';
import { CollectionUtil } from 'pragmatismo-io-framework'; import { CollectionUtil } from 'pragmatismo-io-framework';
import { SecService } from '../../security.gbapp/services/SecService.js'; import { SecService } from '../../security.gbapp/services/SecService.js';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
/** /**
* Dialogs for administration tasks. * Dialogs for administration tasks.

View file

@ -40,6 +40,8 @@ import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBPackage } from '
import { Sequelize } from 'sequelize-typescript'; import { Sequelize } from 'sequelize-typescript';
import { AdminDialog } from './dialogs/AdminDialog.js'; import { AdminDialog } from './dialogs/AdminDialog.js';
import { GuaribasAdmin } from './models/AdminModel.js'; import { GuaribasAdmin } from './models/AdminModel.js';
import { GBLogEx } from '../core.gbapp/services/GBLogEx.js';
/** /**
* The package for admin.gbapp. * The package for admin.gbapp.
@ -48,19 +50,19 @@ export class GBAdminPackage implements IGBPackage {
public sysPackages: IGBPackage[]; public sysPackages: IGBPackage[];
public async getDialogs (min: GBMinInstance) { public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`); GBLogEx.verbose(min,`getDialogs called.`);
} }
public async unloadPackage (core: IGBCoreService): Promise<void> { public async unloadPackage (core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`); GBLog.verbose(`unloadPackage called.`);
} }
public async unloadBot (min: GBMinInstance): Promise<void> { 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> { 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) { 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> { public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {

View file

@ -39,6 +39,7 @@ import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
import { GuaribasSchedule } from '../../core.gbapp/models/GBModel.js'; import { GuaribasSchedule } from '../../core.gbapp/models/GBModel.js';
import cron from 'node-cron'; import cron from 'node-cron';
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
/** /**
* @fileoverview Schedule Services. * @fileoverview Schedule Services.
@ -64,7 +65,7 @@ export class ScheduleServices extends GBService {
}); });
if (count > 0) { 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) { private ScheduleItem (item: GuaribasSchedule, min: GBMinInstance) {
GBLog.info(`Scheduling ${item.name} on ${min.botId}...`); GBLogEx.info(min,`Scheduling ${item.name} on ${min.botId}...`);
try { try {
const options = { const options = {
scheduled: true, scheduled: true,
@ -147,7 +148,7 @@ export class ScheduleServices extends GBService {
}, },
options options
); );
GBLog.info(`Running .gbdialog word ${item.name} on:${item.schedule}...`); GBLogEx.info(min,`Running .gbdialog word ${item.name} on:${item.schedule}...`);
} catch (error) {} } catch (error) {}
} }
} }

View file

@ -97,8 +97,8 @@ export class WebAutomationServices {
*/ */
public async openPage({ pid, handle, sessionKind, sessionName, url, username, password }) { 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); const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min,`BASIC: Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);
// Try to find an existing handle. // Try to find an existing handle.
@ -195,9 +195,10 @@ export class WebAutomationServices {
* *
* @example GET "selector" * @example GET "selector"
*/ */
public async getBySelector({ handle, selector }) { public async getBySelector({ handle, selector, pid }) {
const page = WebAutomationServices.getPageByHandle(handle); 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); await page.waitForSelector(selector);
let elements = await page.$$(selector); let elements = await page.$$(selector);
if (elements && elements.length > 1) { if (elements && elements.length > 1) {
@ -241,7 +242,7 @@ export class WebAutomationServices {
public async hover({ pid, handle, selector }) { public async hover({ pid, handle, selector }) {
const page = WebAutomationServices.getPageByHandle(handle); const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation HOVER element: ${selector}.`); 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 page.hover(selector);
await this.debugStepWeb(pid, page); await this.debugStepWeb(pid, page);
} }
@ -346,7 +347,7 @@ export class WebAutomationServices {
text = `${text}`; text = `${text}`;
const page = WebAutomationServices.getPageByHandle(handle); const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation TYPE on ${selector}: ${text}.`); 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 e.click({ clickCount: 3 });
await page.keyboard.press('Backspace'); await page.keyboard.press('Backspace');
await e.type(text, { delay: 200 }); await e.type(text, { delay: 200 });
@ -362,7 +363,7 @@ export class WebAutomationServices {
const { min, user } = await DialogKeywords.getProcessInfo(pid); const { min, user } = await DialogKeywords.getProcessInfo(pid);
const page = WebAutomationServices.getPageByHandle(handle); 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 // https://github.com/GeneralBots/BotServer/issues/311
const container = element['_frame'] ? element['_frame'] : element['_page']; const container = element['_frame'] ? element['_frame'] : element['_page'];
await page.setRequestInterception(true); await page.setRequestInterception(true);

View file

@ -8,6 +8,7 @@ import { CollectionUtil } from 'pragmatismo-io-framework';
import { GBServer } from '../../../../src/app.js'; import { GBServer } from '../../../../src/app.js';
import { DebuggerService } from '../DebuggerService.js'; import { DebuggerService } from '../DebuggerService.js';
import finalStream from 'final-stream'; import finalStream from 'final-stream';
import { GBLogEx } from '../../../core.gbapp/services/GBLogEx.js';
const waitUntil = condition => { const waitUntil = condition => {
if (condition()) { if (condition()) {
@ -119,8 +120,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
}); });
} }
GBServer.globals.debuggers[limits.botId].scope = variablesText; 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. // Processes breakpoint hits.
if (hitBreakpoints.length >= 1) { if (hitBreakpoints.length >= 1) {
@ -142,7 +142,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
}); });
GBLog.info(`BASIC break defined ${breakpointId} for ${limits.botId}`); GBLog.info(`BASIC break defined ${breakpointId} for ${limits.botId}`);
} catch (error) { } 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(); await client.Debugger.resume();

View file

@ -397,7 +397,7 @@ export class GBDeployer implements IGBDeployer {
const siteId = process.env.STORAGE_SITE_ID; const siteId = process.env.STORAGE_SITE_ID;
const libraryId = process.env.STORAGE_LIBRARY; 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. // Connects to MSFT storage.
@ -414,16 +414,17 @@ export class GBDeployer implements IGBDeployer {
const path = DialogKeywords.getGBAIPath(botId, 'gbot'); const path = DialogKeywords.getGBAIPath(botId, 'gbot');
let url = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:/${path}:/children`; 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(); const res = await client.api(url).get();
// Finds Config.xlsx. // Finds Config.xlsx.
const document = res.value.filter(m => { const document = res.value.filter(m => {
return m.name === 'Config.xlsx'; return m.name === 'Config.xlsx';
}); });
if (document === undefined || document.length === 0) { 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; return null;
} }
@ -458,7 +459,7 @@ export class GBDeployer implements IGBDeployer {
baseUrl: string = null, baseUrl: string = null,
client = null client = null
): Promise<any> { ): Promise<any> {
GBLog.info(`downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`); GBLogEx.info(min ,`downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`);
if (!baseUrl) { if (!baseUrl) {
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min); let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
@ -487,12 +488,12 @@ export class GBDeployer implements IGBDeployer {
path = urlJoin(path, remotePath); path = urlJoin(path, remotePath);
let url = `${baseUrl}/drive/root:/${path}:/children`; 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 res = await client.api(url).get();
const documents = res.value; const documents = res.value;
if (documents === undefined || documents.length === 0) { if (documents === undefined || documents.length === 0) {
GBLog.info(`${remotePath} is an empty folder.`); GBLogEx.info(min, `${remotePath} is an empty folder.`);
return null; return null;
} }
@ -518,14 +519,14 @@ export class GBDeployer implements IGBDeployer {
} }
if (download) { if (download) {
GBLog.verbose(`Downloading ${itemPath}...`); GBLogEx.verbose(min, `Downloading ${itemPath}...`);
const url = item['@microsoft.graph.downloadUrl']; const url = item['@microsoft.graph.downloadUrl'];
const response = await fetch(url); const response = await fetch(url);
Fs.writeFileSync(itemPath, Buffer.from(await response.arrayBuffer()), { encoding: null }); Fs.writeFileSync(itemPath, Buffer.from(await response.arrayBuffer()), { encoding: null });
Fs.utimesSync(itemPath, new Date(), new Date(item.lastModifiedDateTime)); Fs.utimesSync(itemPath, new Date(), new Date(item.lastModifiedDateTime));
} else { } 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 (process.env.ENABLE_PARAMS_ONLINE === 'false') {
if (Fs.existsSync(localPath)) { if (Fs.existsSync(localPath)) {
GBLog.info(`Loading .gbot from ${localPath}.`); GBLogEx.info(min, `Loading .gbot from ${localPath}.`);
await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress); await this.deployBotFromLocalPath(localPath, GBServer.globals.publicAddress);
} }
} else { } else {
@ -635,7 +636,7 @@ export class GBDeployer implements IGBDeployer {
const vm = new GBVMService(); const vm = new GBVMService();
await vm.loadDialogPackage(localPath, min, this.core, this); 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; break;
case '.gbtheme': case '.gbtheme':
@ -643,7 +644,7 @@ export class GBDeployer implements IGBDeployer {
const packageName = Path.basename(localPath); const packageName = Path.basename(localPath);
GBServer.globals.server.use(`/themes/${packageName}`, express.static(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; break;
@ -887,7 +888,7 @@ export class GBDeployer implements IGBDeployer {
// After compiled, adds the .gbapp to the current server VM context. // After compiled, adds the .gbapp to the current server VM context.
if (gbappPath.endsWith('.gbapp') || gbappPath.endsWith('.gblib')) { if (gbappPath.endsWith('.gbapp') || gbappPath.endsWith('.gblib')) {
const m = await import(gbappPath); const m = await import(`file://${gbappPath}/dist/index.js`);
if (m.Package) { if (m.Package) {
const p = new m.Package(); const p = new m.Package();

View file

@ -77,11 +77,10 @@ export class GBLogEx {
*/ */
public static async log(instance: IGBInstance, kind: string, message: string): Promise<GuaribasLog> { public static async log(instance: IGBInstance, kind: string, message: string): Promise<GuaribasLog> {
message = message ? message.substring(0, 1023) : null; message = message ? message.substring(0, 1023) : null;
// return await GuaribasLog.create(<GuaribasLog>{ return await GuaribasLog.create(<GuaribasLog>{
// instanceId: instance ? instance.instanceId : 1, instanceId: instance ? instance.instanceId : 1,
// message: message, message: message,
// kind: kind kind: kind
// }); });
return null;
} }
} }

View file

@ -332,6 +332,9 @@ export class GBSSR {
'build', 'build',
url === '/' || url === '' ? `index.html` : url url === '/' || url === '' ? `index.html` : url
); );
if (GBServer.globals.wwwroot && url === '/'){
path = GBServer.globals.wwwroot + "\\index.html";
}
if (Fs.existsSync(path)) { if (Fs.existsSync(path)) {
if (min) { if (min) {
let html = Fs.readFileSync(path, 'utf8'); let html = Fs.readFileSync(path, 'utf8');