Skip to content

Commit

Permalink
Merge pull request #779 from codeforequity-at/develop
Browse files Browse the repository at this point in the history
Botium Core 1.14.0
  • Loading branch information
codeforequity-at authored Sep 25, 2023
2 parents 615ab67 + 6c8b2b6 commit bd15099
Show file tree
Hide file tree
Showing 29 changed files with 6,940 additions and 17,998 deletions.
6,450 changes: 0 additions & 6,450 deletions LICENSES-3RDPARTY.txt

This file was deleted.

17,543 changes: 6,626 additions & 10,917 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 20 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botium-core",
"version": "1.13.19",
"version": "1.14.0",
"description": "The Selenium for Chatbots",
"main": "index.js",
"module": "dist/botium-es.js",
Expand All @@ -18,7 +18,6 @@
"link": "npm link botium-connector-dialogflow botium-connector-webdriverio botium-connector-directline3 botium-connector-watson botium-connector-alexa-smapi botium-connector-echo",
"test": "cross-env NODE_PATH=\"./test/plugins/plugindir/fromfolder:./test/plugins/plugindir/fromfile:./test/security/resources\" mocha \"./test/**/*.spec.js\"",
"coverage:report": "nyc report --reporter=lcov npm test",
"license-checker": "license-checker > LICENSES-3RDPARTY.txt",
"update-dependencies": "npm-check-updates --reject globby,rollup -u --timeout 120000"
},
"repository": {
Expand All @@ -32,14 +31,13 @@
},
"homepage": "https://www.botium.ai",
"dependencies": {
"@babel/runtime": "^7.21.5",
"@babel/runtime": "^7.22.15",
"async": "^3.2.4",
"body-parser": "^1.20.2",
"boolean": "^3.2.0",
"bottleneck": "^2.19.5",
"csv-parse": "^5.3.10",
"csv-parse": "^5.5.0",
"debug": "^4.3.4",
"esprima": "^4.0.1",
"express": "^4.18.2",
"globby": "11.0.4",
"ioredis": "^5.3.2",
Expand All @@ -54,45 +52,42 @@
"moment-timezone": "^0.5.43",
"mustache": "^4.2.0",
"promise-retry": "^2.0.1",
"promise.allsettled": "^1.0.6",
"promise.allsettled": "^1.0.7",
"randomatic": "^3.1.1",
"request": "^2.88.2",
"rimraf": "^5.0.0",
"rimraf": "^5.0.1",
"sanitize-filename": "^1.6.3",
"slugify": "^1.6.6",
"socket.io": "^4.6.1",
"socket.io-client": "^4.6.1",
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"socketio-auth": "^0.1.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^4.6.3",
"swagger-ui-express": "^5.0.0",
"uuid": "^9.0.0",
"vm2": "^3.9.17",
"word-error-rate": "0.0.7",
"write-yaml": "^1.0.0",
"xlsx": "^0.18.5",
"xregexp": "^5.1.1",
"yaml": "^2.2.2"
"yaml": "^2.3.2"
},
"devDependencies": {
"@babel/core": "^7.21.8",
"@babel/node": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"chai": "^4.3.7",
"@babel/core": "^7.22.17",
"@babel/node": "^7.22.15",
"@babel/plugin-transform-runtime": "^7.22.15",
"@babel/preset-env": "^7.22.15",
"chai": "^4.3.8",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.40.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint": "^8.49.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^4.1.0",
"license-checker": "^25.0.1",
"license-compatibility-checker": "^0.3.5",
"mocha": "^10.2.0",
"nock": "^13.3.1",
"npm-check-updates": "^16.10.12",
"nock": "^13.3.3",
"npm-check-updates": "^16.13.3",
"nyc": "^15.1.0",
"rollup": "2.79.1",
"rollup-plugin-babel": "^4.4.0",
Expand Down
1 change: 1 addition & 0 deletions samples/extensions/asserterHooks/botium.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"WATSON_PASSWORD": "ZWDE5xo02sby",
"WATSON_WORKSPACE_ID": "97513bc0-c581-4bec-ac9f-ea6a8ec308a9",
"SCRIPTING_ENABLE_MEMORY": true,
"SAFEDIR": ".",
"ASSERTERS": [
{
"ref": "DUMMY",
Expand Down
1 change: 1 addition & 0 deletions samples/extensions/logichooks/botium.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Capabilities": {
"PROJECTNAME": "Botium Logichooks Sample",
"CONTAINERMODE": "echo",
"SAFEDIR": ".",
"ASSERTERS": [
{
"ref": "MYASSERTER",
Expand Down
6 changes: 3 additions & 3 deletions samples/extensions/logichooks/custom/MyAsserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module.exports = class MyAsserter {
this.caps = caps
}

assertConvoBegin ({convo, container, args}) {
assertConvoBegin ({ convo, container, args }) {
console.log(`MyAsserter assertConvoBegin: ${convo.header.name}`)
return Promise.resolve()
}

assertConvoStep ({convo, convoStep, args, botMsg}) {
assertConvoStep ({ convo, convoStep, args, botMsg }) {
console.log(`MyAsserter assertConvoStep, botMessage: ${utils.inspect(botMsg)} ...`)
return Promise.resolve()
}

assertConvoEnd ({convo, container, transcript, args}) {
assertConvoEnd ({ convo, container, transcript, args }) {
console.log(`MyAsserter assertConvoEnd ${convo.header.name}, transcript: ${utils.inspect(transcript)} ...`)
return Promise.resolve()
}
Expand Down
3 changes: 2 additions & 1 deletion src/Capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
TESTSESSIONNAME: 'TESTSESSIONNAME',
TESTCASENAME: 'TESTCASENAME',
TEMPDIR: 'TEMPDIR',
SAFEDIR: 'SAFEDIR',
CLEANUPTEMPDIR: 'CLEANUPTEMPDIR',
WAITFORBOTTIMEOUT: 'WAITFORBOTTIMEOUT',
CONTAINERMODE: 'CONTAINERMODE',
Expand All @@ -12,7 +13,7 @@ module.exports = {
BOTIUMGRIDURL: 'BOTIUMGRIDURL',
BOTIUMAPITOKEN: 'BOTIUMAPITOKEN',
BOTIUMGRIDSLOT: 'BOTIUMGRIDSLOT',
// Simple Reset Bot Settings
// Simple Rest Bot Settings
SIMPLEREST_PING_URL: 'SIMPLEREST_PING_URL',
SIMPLEREST_PING_VERB: 'SIMPLEREST_PING_VERB',
SIMPLEREST_PING_BODY: 'SIMPLEREST_PING_BODY',
Expand Down
8 changes: 8 additions & 0 deletions src/containers/PluginConnectorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@ module.exports = class PluginConnectorContainer extends BaseContainer {
return Promise.reject(new Error(`Clean - Botium plugin failed: ${util.inspect(err)}`))
}
}

GetMetaData () {
try {
return (this.pluginInstance.GetMetaData ? (this.pluginInstance.GetMetaData() || Promise.resolve()) : Promise.resolve())
} catch (err) {
return Promise.reject(new Error(`GetMetaData - Botium plugin failed: ${util.inspect(err)}`))
}
}
}
26 changes: 17 additions & 9 deletions src/containers/plugins/SimpleRestContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,33 @@ module.exports = class SimpleRestContainer {

const result = []
if (isFromUser) {
const _extractFrom = (root, jsonPaths) => {
const flattened = []
const _extractFrom = (root, jsonPaths, acceptFn = null) => {
const result = []
for (const jsonPath of jsonPaths) {
const jsonPathRes = []
const rb = jp.query(root, jsonPath)
if (_.isArray(rb)) {
_.flattenDeep(rb).forEach(r => flattened.push(r))
} else if (rb) {
flattened.push(rb)
_.flattenDeep(rb).forEach(r => jsonPathRes.push(r))
} else {
jsonPathRes.push(rb)
}
if (acceptFn) {
result.push(...jsonPathRes.filter(r => acceptFn(root, jsonPath, r)))
} else {
result.push(...jsonPathRes)
}
}
return flattened
return result
}

const jsonPathRoots = []

const jsonPathsBody = getAllCapValues(Capabilities.SIMPLEREST_BODY_JSONPATH, this.caps)
if (jsonPathsBody.length > 0) {
jsonPathRoots.push(..._extractFrom(body, jsonPathsBody))
jsonPathRoots.push(..._extractFrom(body, jsonPathsBody, (root, jsonPath, r) => {
if (r && _.isObject(r)) return true
debug(`Ignoring result body from ${jsonPath} - not a querieable object (${util.inspect(r)})`)
return false
}))
} else {
jsonPathRoots.push(body)
}
Expand Down Expand Up @@ -381,7 +390,6 @@ module.exports = class SimpleRestContainer {
const jsonPathsButtonsPayload = getAllCapValues(`${capPrefix}_PAYLOAD_SUBJSONPATH`, this.caps)

const retrievedButtons = []

const responseButtons = _extractFrom(jsonPathButtonRoot, jsonPathsButtons)
for (const responseButton of responseButtons) {
const retrievedButton = {}
Expand Down
70 changes: 29 additions & 41 deletions src/containers/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const debug = require('debug')('botium-connector-PluginConnectorContainer-helper

const SimpleRestContainer = require('./SimpleRestContainer')
const Capabilities = require('../../Capabilities')
const { BotiumError } = require('../../scripting/BotiumError')

const pluginResolver = (containermode) => {
if (containermode === 'simplerest') {
Expand Down Expand Up @@ -59,23 +58,6 @@ const loadConnectorModule = (PluginClass, args) => {

const tryLoadPlugin = (containermode, modulepath, args) => {
const pluginLoaderSpec = modulepath || containermode
const _checkUnsafe = (caps, mode, cause) => {
if (!caps[Capabilities.SECURITY_ALLOW_UNSAFE]) {
throw new BotiumError(
`Security Error. Using unsafe connector mode "${mode}" is not allowed`,
{
type: 'security',
subtype: 'allow unsafe',
source: 'src/containers/plugins/index.js',
cause: {
SECURITY_ALLOW_UNSAFE: caps[Capabilities.SECURITY_ALLOW_UNSAFE],
mode,
...cause
}
}
)
}
}

if (pluginResolver(pluginLoaderSpec)) {
const pluginInstance = new (pluginResolver(pluginLoaderSpec))(args)
Expand All @@ -88,44 +70,50 @@ const tryLoadPlugin = (containermode, modulepath, args) => {
return pluginInstance
}
const loadErr = []
const allowUnsafe = !!args.caps[Capabilities.SECURITY_ALLOW_UNSAFE]

if (_.isString(pluginLoaderSpec)) {
const tryLoadFile = path.resolve(process.cwd(), pluginLoaderSpec)
if (fs.existsSync(tryLoadFile)) {
_checkUnsafe(args.caps, 'Using work dir', { modulepath, containermode })
if (args.caps.SAFEDIR) {
const tryLoadFile = path.resolve(args.caps.SAFEDIR, pluginLoaderSpec)
if (tryLoadFile.startsWith(path.resolve(args.caps.SAFEDIR))) {
if (fs.existsSync(tryLoadFile)) {
try {
let plugin = require(tryLoadFile)
if (plugin.default) {
plugin = plugin.default
}
if (!plugin.PluginVersion || !plugin.PluginClass) {
loadErr.push(`Invalid Botium plugin loaded from ${tryLoadFile}, expected PluginVersion, PluginClass fields`)
} else {
const pluginInstance = loadConnectorModule(plugin.PluginClass, args)
debug(`Botium plugin loaded from ${tryLoadFile}`)
return pluginInstance
}
} catch (err) {
loadErr.push(`Loading Botium plugin from ${tryLoadFile} failed - ${err.message}`)
}
}
}
}

if (allowUnsafe) {
try {
let plugin = require(tryLoadFile)
let plugin = require(pluginLoaderSpec)
if (plugin.default) {
plugin = plugin.default
}
if (!plugin.PluginVersion || !plugin.PluginClass) {
loadErr.push(`Invalid Botium plugin loaded from ${tryLoadFile}, expected PluginVersion, PluginClass fields`)
loadErr.push(`Invalid Botium plugin loaded from ${pluginLoaderSpec}, expected PluginVersion, PluginClass fields`)
} else {
const pluginInstance = loadConnectorModule(plugin.PluginClass, args)
debug(`Botium plugin loaded from ${tryLoadFile}`)
debug(`Botium plugin loaded from ${pluginLoaderSpec}. Plugin version is ${getModuleVersionSafe(pluginLoaderSpec)}`)
return pluginInstance
}
} catch (err) {
loadErr.push(`Loading Botium plugin from ${tryLoadFile} failed - ${err.message}`)
loadErr.push(`Loading Botium plugin from ${pluginLoaderSpec} failed - ${err.message}`)
}
}

try {
let plugin = require(pluginLoaderSpec)
if (plugin.default) {
plugin = plugin.default
}
if (!plugin.PluginVersion || !plugin.PluginClass) {
loadErr.push(`Invalid Botium plugin loaded from ${pluginLoaderSpec}, expected PluginVersion, PluginClass fields`)
} else {
const pluginInstance = loadConnectorModule(plugin.PluginClass, args)
debug(`Botium plugin loaded from ${pluginLoaderSpec}. Plugin version is ${getModuleVersionSafe(pluginLoaderSpec)}`)
return pluginInstance
}
} catch (err) {
loadErr.push(`Loading Botium plugin from ${pluginLoaderSpec} failed - ${err.message}`)
}

const tryLoadPackage = `botium-connector-${pluginLoaderSpec}`
try {
let plugin = require(tryLoadPackage)
Expand Down
Loading

0 comments on commit bd15099

Please sign in to comment.