Skip to content

Commit 8d5ba7d

Browse files
committed
chore: removed GET_FUNCTION_FROM_STRING dependency on requestly-core
1 parent 3d664ad commit 8d5ba7d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/components/proxy-middleware/rule_action_processor/processors/modify_request_processor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { PROXY_HANDLER_TYPE } from "../../../../lib/proxy";
22

33
import {
4-
UTILS as GLOBAL_UTILS,
54
CONSTANTS as GLOBAL_CONSTANTS,
65
} from "@requestly/requestly-core";
76
import { get_request_url } from "../../helpers/proxy_ctx_helper";
87
import { build_action_processor_response } from "../utils";
9-
import fs from "fs";
108
import ConsoleCapture from "capture-console-logs";
9+
import { getFunctionFromString } from "../../../../utils";
10+
1111
const { types } = require("util");
1212

1313
const process_modify_request_action = (action, ctx) => {
@@ -36,7 +36,7 @@ const modify_request = (ctx, new_req) => {
3636
const modify_request_using_code = async (action, ctx) => {
3737
let userFunction = null;
3838
try {
39-
userFunction = GLOBAL_UTILS.GET_FUNCTION_FROM_STRING(action.request);
39+
userFunction = getFunctionFromString(action.request);
4040
} catch (error) {
4141
// User has provided an invalid function
4242
return modify_request(

src/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { PROXY_HANDLER_TYPE } from "../../../../lib/proxy";
22

33
import {
4-
UTILS as GLOBAL_UTILS,
54
CONSTANTS as GLOBAL_CONSTANTS,
65
} from "@requestly/requestly-core";
76
import { get_request_url } from "../../helpers/proxy_ctx_helper";
87
import { build_action_processor_response } from "../utils";
98
import fs from "fs";
109
import { parseJsonBody } from "../../helpers/http_helpers";
1110
import ConsoleCapture from "capture-console-logs";
11+
import { getFunctionFromString } from "../../../../utils";
12+
1213
const { types } = require("util");
1314

1415
const process_modify_response_action = async (action, ctx) => {
@@ -53,7 +54,7 @@ const modify_response_using_local = (action, ctx) => {
5354
const modify_response_using_code = async (action, ctx) => {
5455
let userFunction = null;
5556
try {
56-
userFunction = GLOBAL_UTILS.GET_FUNCTION_FROM_STRING(action.response);
57+
userFunction = getFunctionFromString(action.response);
5758
} catch (error) {
5859
// User has provided an invalid function
5960
return modify_response(

src/utils/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const getFunctionFromString = function (functionStringEscaped) {
2+
return new Function("return " + functionStringEscaped)();
3+
};

0 commit comments

Comments
 (0)