From 905f459ed03c91653cc29bd93074d7ca66a6806b Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 29 Jan 2023 11:12:34 +0530 Subject: [PATCH] feat: support for inbuilt libraries during scripting --- packages/bruno-electron/package.json | 5 +++++ packages/bruno-js/src/scripts/bru.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/bruno-electron/package.json b/packages/bruno-electron/package.json index 104d1058d..9c93ac0bb 100644 --- a/packages/bruno-electron/package.json +++ b/packages/bruno-electron/package.json @@ -16,7 +16,10 @@ "@usebruno/js": "0.1.0", "@usebruno/lang": "0.1.0", "@usebruno/schema": "0.1.0", + "ajv": "^8.12.0", + "atob": "^2.1.2", "axios": "^0.26.0", + "btoa": "^1.2.1", "chokidar": "^3.5.3", "electron-is-dev": "^2.0.0", "electron-store": "^8.1.0", @@ -25,8 +28,10 @@ "fs-extra": "^10.1.0", "is-valid-path": "^0.1.1", "lodash": "^4.17.21", + "moment": "^2.29.4", "mustache": "^4.2.0", "nanoid": "3.3.4", + "uuid": "^9.0.0", "vm2": "^3.9.13", "yup": "^0.32.11" }, diff --git a/packages/bruno-js/src/scripts/bru.js b/packages/bruno-js/src/scripts/bru.js index e7db958b5..76d4852e2 100644 --- a/packages/bruno-js/src/scripts/bru.js +++ b/packages/bruno-js/src/scripts/bru.js @@ -1,8 +1,36 @@ + +// Inbuilt Library Support +const atob = require('atob'); +const btoa = require('btoa'); +const _ = require('lodash'); +const moment = require('moment'); +const uuid = require('uuid'); +const nanoid = require('nanoid'); + class Bru { constructor(environment) { this._environment = environment; } + require(module) { + switch(module) { + case 'atob': + return atob; + case 'btoa': + return btoa; + case 'lodash': + return _; + case 'moment': + return moment; + case 'uuid': + return uuid; + case 'nanoid': + return nanoid; + default: + throw new Error(`Module ${module} is not supported`); + } + } + getEnvVar(key) { return this._environment[key]; }