Socket
Socket
Sign inDemoInstall

recime-message-responder

Package Overview
Dependencies
154
Maintainers
1
Versions
193
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.6 to 1.0.7

dist/plugins/json-api.js

6

dist/code-block.d.ts
export declare class CodeBlock {
private code;
constructor(code: any);
private message;
constructor(message: any);
execute(data: any): Promise<{}>;
processMessage(message: any): any;
transformCode(code: any): any;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const HandleBars = require("handlebars");
const recime_bot_extension_1 = require("recime-bot-extension");

@@ -10,6 +12,4 @@ const __ = recime_bot_extension_1.default.default;

class CodeBlock {
constructor(code) {
this.code = babel.transform(code, {
"presets": [presetEnv]
}).code;
constructor(message) {
this.message = message;
}

@@ -48,3 +48,10 @@ execute(data) {

local.run(() => {
const handler = vm.runInNewContext(this.code, sandbox);
const config = this.message.content.config;
if (config) {
const str = JSON.stringify(config);
const template = HandleBars.compile(str);
data.config = JSON.parse(template(data.vars.vals));
}
const message = this.processMessage(this.message);
const handler = vm.runInNewContext(message, sandbox);
handler(data, (result) => {

@@ -69,3 +76,22 @@ if (Array.isArray(result)) {

}
processMessage(message) {
switch (message.type) {
case "json-api": {
console.log(message.content.config);
const filepath = path.join(__dirname, "plugins", `${message.type}.js`);
if (fs.existsSync(filepath))
return this.transformCode(fs.readFileSync(filepath, 'utf-8'));
throw new Error(`Unsupported message type "${message.type}"!`);
}
default: {
return this.transformCode(message.content.code);
}
}
}
transformCode(code) {
return babel.transform(code, {
"presets": [presetEnv]
}).code;
}
}
exports.CodeBlock = CodeBlock;

@@ -23,6 +23,7 @@ "use strict";

}
case 'code': {
case 'code':
case 'json-api': {
console.time("babel-compile");
try {
const block = new code_block_1.CodeBlock(message.content.code);
const block = new code_block_1.CodeBlock(message);
return block.execute(options).then((r) => {

@@ -29,0 +30,0 @@ console.timeEnd("babel-compile");

{
"name": "recime-message-responder",
"version": "1.0.6",
"version": "1.0.7",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -5,2 +5,4 @@ import fs = require("fs");

import HandleBars = require("handlebars");
import Ext from 'recime-bot-extension';

@@ -13,10 +15,8 @@ const __ = Ext.default;

export class CodeBlock {
private code: any;
private message: any;
constructor(code){
this.code = babel.transform(code, {
"presets" : [presetEnv]
}).code;
constructor(message){
this.message = message;
}
execute(data){

@@ -58,3 +58,14 @@ return new Promise((resolve, reject)=>{

local.run (()=>{
const handler = vm.runInNewContext(this.code, sandbox);
const config = this.message.content.config;
if (config){
const str = JSON.stringify(config);
const template = HandleBars.compile(str);
data.config = JSON.parse(template(data.vars.vals));
}
const message = this.processMessage(this.message);
const handler = vm.runInNewContext(message, sandbox);
handler(data, (result)=>{

@@ -66,3 +77,3 @@ if (Array.isArray(result)){

r.push(result);
}
}
resolve(r);

@@ -80,2 +91,23 @@ });

}
processMessage(message){
switch(message.type){
case "json-api":{
console.log(message.content.config);
const filepath = path.join(__dirname, "plugins", `${message.type}.js`);
if (fs.existsSync(filepath))
return this.transformCode(fs.readFileSync(filepath, 'utf-8'));
throw new Error(`Unsupported message type "${message.type}"!`)
}
default : {
return this.transformCode(message.content.code);
}
}
}
transformCode(code){
return babel.transform(code, {
"presets" : [presetEnv]
}).code;
}
}

@@ -33,7 +33,8 @@ import Ext from 'recime-bot-extension';

}
case 'code':{
case 'code':
case 'json-api': {
console.time("babel-compile");
try {
const block = new CodeBlock(message.content.code);
const block = new CodeBlock(message);

@@ -40,0 +41,0 @@ return block.execute(options).then((r) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc