|
|
|
|
@ -1,5 +1,4 @@ |
|
|
|
|
import vm from 'vm'; |
|
|
|
|
|
|
|
|
|
import { VM, VMScript } from 'vm2'; |
|
|
|
|
import { Meteor } from 'meteor/meteor'; |
|
|
|
|
import { Random } from 'meteor/random'; |
|
|
|
|
import { HTTP } from 'meteor/http'; |
|
|
|
|
@ -19,7 +18,6 @@ import { fetch } from '../../../../server/lib/http/fetch'; |
|
|
|
|
|
|
|
|
|
export class RocketChatIntegrationHandler { |
|
|
|
|
constructor() { |
|
|
|
|
this.vm = vm; |
|
|
|
|
this.successResults = [200, 201, 202]; |
|
|
|
|
this.compiledScripts = {}; |
|
|
|
|
this.triggers = {}; |
|
|
|
|
@ -275,18 +273,20 @@ export class RocketChatIntegrationHandler { |
|
|
|
|
const script = integration.scriptCompiled; |
|
|
|
|
const { store, sandbox } = this.buildSandbox(); |
|
|
|
|
|
|
|
|
|
let vmScript; |
|
|
|
|
try { |
|
|
|
|
outgoingLogger.info({ msg: 'Will evaluate script of Trigger', name: integration.name }); |
|
|
|
|
outgoingLogger.debug(script); |
|
|
|
|
|
|
|
|
|
vmScript = this.vm.createScript(script, 'script.js'); |
|
|
|
|
const vmScript = new VMScript(`${script}; Script;`, 'script.js'); |
|
|
|
|
const vm = new VM({ |
|
|
|
|
sandbox, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
vmScript.runInNewContext(sandbox); |
|
|
|
|
const ScriptClass = vm.run(vmScript); |
|
|
|
|
|
|
|
|
|
if (sandbox.Script) { |
|
|
|
|
if (ScriptClass) { |
|
|
|
|
this.compiledScripts[integration._id] = { |
|
|
|
|
script: new sandbox.Script(), |
|
|
|
|
script: new ScriptClass(), |
|
|
|
|
store, |
|
|
|
|
_updatedAt: integration._updatedAt, |
|
|
|
|
}; |
|
|
|
|
@ -303,10 +303,8 @@ export class RocketChatIntegrationHandler { |
|
|
|
|
throw new Meteor.Error('error-evaluating-script'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!sandbox.Script) { |
|
|
|
|
outgoingLogger.error(`Class "Script" not in Trigger ${integration.name}:`); |
|
|
|
|
throw new Meteor.Error('class-script-not-found'); |
|
|
|
|
} |
|
|
|
|
outgoingLogger.error(`Class "Script" not in Trigger ${integration.name}:`); |
|
|
|
|
throw new Meteor.Error('class-script-not-found'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hasScriptAndMethod(integration, method) { |
|
|
|
|
@ -352,9 +350,12 @@ export class RocketChatIntegrationHandler { |
|
|
|
|
|
|
|
|
|
this.updateHistory({ historyId, step: `execute-script-before-running-${method}` }); |
|
|
|
|
|
|
|
|
|
const result = Future.fromPromise( |
|
|
|
|
this.vm.runInNewContext( |
|
|
|
|
` |
|
|
|
|
const vm = new VM({ |
|
|
|
|
timeout: 3000, |
|
|
|
|
sandbox, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const scriptResult = vm.run(` |
|
|
|
|
new Promise((resolve, reject) => { |
|
|
|
|
Fiber(() => { |
|
|
|
|
scriptTimeout(reject); |
|
|
|
|
@ -365,13 +366,9 @@ export class RocketChatIntegrationHandler { |
|
|
|
|
} |
|
|
|
|
}).run(); |
|
|
|
|
}).catch((error) => { throw new Error(error); }); |
|
|
|
|
`,
|
|
|
|
|
sandbox, |
|
|
|
|
{ |
|
|
|
|
timeout: 3000, |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
).wait(); |
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
const result = Future.fromPromise(scriptResult).wait(); |
|
|
|
|
|
|
|
|
|
outgoingLogger.debug({ |
|
|
|
|
msg: `Script method "${method}" result of the Integration "${integration.name}" is:`, |
|
|
|
|
|