-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
converted rocketchat-integrations coffee to js #6502
Conversation
@@ -0,0 +1,366 @@ | |||
/* globals Api Meteor Restivus logger processWebhookMessage*/ | |||
// TODO: remove globals | |||
const vm = Npm.require('vm'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use import instead of require
const buildSandbox = function(store) { | ||
if (store == null) { | ||
store = {}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use default values instead of this condition
return compiledScript.script; | ||
} | ||
const script = integration.scriptCompiled; | ||
let vmScript = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change from undefined
to null
?
try { | ||
script = getIntegrationScript(this.integration); | ||
} catch (error) { | ||
const e = error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why declare a new var?
const result = vm.runInNewContext('script.process_incoming_request({ request: request })', sandbox, { | ||
timeout: 3000 | ||
}); | ||
if (result && result.console.error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.console
?
if (result && result.console.error) { | ||
return RocketChat.API.v1.failure(result.error); | ||
} | ||
this.bodyParams = result != null ? result.content : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify with this.bodyParams = result && result.content;
logger.incoming.debug('[Process Incoming Request result of Trigger', this.integration.name, ':]'); | ||
logger.incoming.debug('result', this.bodyParams); | ||
} catch (error) { | ||
const e = error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this declaration?
} | ||
return RocketChat.API.v1.success(); | ||
} catch (error) { | ||
const e = error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this declaration?
} | ||
}; | ||
|
||
Object.keys(RocketChat.models).filter(function(k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we turn these into single line arrow functions? Would clean this up quite a bit.
return compiledScript.script; | ||
} | ||
const script = integration.scriptCompiled; | ||
const sandboxItems = buildSandbox(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break this out using the spread operator? const { store, sandbox } = buildSandbox();
And then use it below, as it'd clean this up and make it very similar to how the outgoing webhook script looks as well.
|
||
const compiledScripts = {}; | ||
|
||
const buildSandbox = function(store = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for variables instead of named functions in this entire file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the "way" that I chose wrong. I'll fix it. There are one difference if I tried to overwrite the function.
const buildSandbox = function(store = {}) {}
.
.
.
buildSandbox = anotherFunction(){}<- exception
logger.incoming.info('Add integration', options.name); | ||
logger.incoming.debug(options); | ||
Meteor.runAsUser(user._id, function() { | ||
switch (options['event']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert this to options.event
so the assessors are like the other ones for options.
avatar: this.integration.avatar, | ||
emoji: this.integration.emoji | ||
}; | ||
if (this.integration.scriptEnabled === true && (this.integration.scriptCompiled != null) && this.integration.scriptCompiled.trim() !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the extra ()
's around the middle condition?
} | ||
}; | ||
try { | ||
const sandboxItems = buildSandbox(compiledScripts[this.integration._id].store); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, use the object spread. 👍
}; | ||
}; | ||
|
||
Api.addRoute(':integrationId/:userId/:token', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the { authRequired: true }
be moved into the same line and not several lines, this way it looks like the api definitions for the api v1.
bca887a
to
2090709
Compare
…nto clarapy-v4 Changed over home.coffee & help.coffee to .js * 'develop' of https://github.com/RocketChat/Rocket.Chat: (162 commits) Remove coffeescript package from ui-flextab Remove coffeescript package from ui-sidenav Update PULL_REQUEST_TEMPLATE.md Fix Outgoing Webhooks Retrying Not Respecting Enabled Status (RocketChat#6478) Convert Theme Package to JS (RocketChat#6491) Fix typo of the safari pinned tab label (RocketChat#6487) fix channel merge option of user preferences (RocketChat#6493) converted Rocketchat logger coffee to js (RocketChat#6495) converted rocketchat-integrations coffee to js (RocketChat#6502) 'allow reacting' should be a toggle option (RocketChat#6522) Add to HISTORY.md Fix backup codes remaining not showing Fix ESLint Fix ESLint Fix review Fix review Fix review fix import issue fix fix ... # Conflicts: # packages/rocketchat-lib/server/lib/PushNotification.js # packages/rocketchat-ui/client/views/app/home.coffee # packages/rocketchat-ui/package.js
@RocketChat/core