Skip to content

Commit c064d05

Browse files
authored
chore: version bump to v1.3.0 (#47)
1 parent d34de8b commit c064d05

File tree

16 files changed

+143
-45
lines changed

16 files changed

+143
-45
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default interface IInitialState extends Record<string, any> {
2+
sharedState?: Record<string, any>;
3+
variables?: Record<string, any>;
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

dist/components/proxy-middleware/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export namespace MIDDLEWARE_TYPE {
33
const RULES: string;
44
const LOGGER: string;
55
const SSL_CERT: string;
6+
const GLOBAL_STATE: string;
67
}
78
export default ProxyMiddlewareManager;
89
declare class ProxyMiddlewareManager {

dist/components/proxy-middleware/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ exports.MIDDLEWARE_TYPE = {
3333
RULES: "RULES",
3434
LOGGER: "LOGGER",
3535
SSL_CERT: "SSL_CERT",
36+
GLOBAL_STATE: "GLOBAL_STATE", // SEEMS UNUSUED, BUT ADDING FOR COMPLETENESS
3637
};
3738
class ProxyMiddlewareManager {
3839
constructor(proxy, proxyConfig, rulesHelper, loggerService, sslConfigFetcher) {
40+
/* NOT USEFUL */
3941
this.init_config = (config = {}) => {
4042
Object.keys(exports.MIDDLEWARE_TYPE).map((middleware_key) => {
4143
this.config[middleware_key] =
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export declare class State {
2+
private state;
3+
constructor(sharedState: Record<string, any>, envVars: Record<string, any>);
4+
setSharedState(newSharedState: Record<string, any>): void;
5+
getSharedStateRef(): Record<string, any>;
6+
getSharedStateCopy(): any;
7+
setVariables(newVariables: Record<string, any>): void;
8+
getVariablesRef(): Record<string, any>;
9+
getVariablesCopy(): any;
10+
}
11+
export default class GlobalStateProvider {
12+
private static instance;
13+
static initInstance(sharedState?: Record<string, any>, envVars?: Record<string, any>): State;
14+
static getInstance(): State;
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.State = void 0;
4+
const lodash_1 = require("lodash");
5+
class State {
6+
constructor(sharedState, envVars) {
7+
this.state = {
8+
variables: envVars,
9+
sharedState,
10+
};
11+
}
12+
setSharedState(newSharedState) {
13+
this.state.sharedState = newSharedState;
14+
}
15+
getSharedStateRef() {
16+
return this.state.sharedState;
17+
}
18+
getSharedStateCopy() {
19+
return (0, lodash_1.cloneDeep)(this.state.sharedState);
20+
}
21+
setVariables(newVariables) {
22+
this.state.variables = newVariables;
23+
}
24+
getVariablesRef() {
25+
return this.state.variables;
26+
}
27+
getVariablesCopy() {
28+
return (0, lodash_1.cloneDeep)(this.state.variables);
29+
}
30+
}
31+
exports.State = State;
32+
class GlobalStateProvider {
33+
static initInstance(sharedState = {}, envVars = {}) {
34+
if (!GlobalStateProvider.instance) {
35+
GlobalStateProvider.instance = new State(sharedState !== null && sharedState !== void 0 ? sharedState : {}, envVars !== null && envVars !== void 0 ? envVars : {});
36+
}
37+
return GlobalStateProvider.instance;
38+
}
39+
static getInstance() {
40+
if (!GlobalStateProvider.instance) {
41+
console.error("[GlobalStateProvider]", "Init first");
42+
}
43+
return GlobalStateProvider.instance;
44+
}
45+
}
46+
exports.default = GlobalStateProvider;

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
88
step((generator = generator.apply(thisArg, _arguments || [])).next());
99
});
1010
};
11-
var __importDefault = (this && this.__importDefault) || function (mod) {
12-
return (mod && mod.__esModule) ? mod : { "default": mod };
13-
};
1411
Object.defineProperty(exports, "__esModule", { value: true });
1512
const proxy_1 = require("../../../../lib/proxy");
1613
const requestly_core_1 = require("@requestly/requestly-core");
1714
const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
1815
const utils_1 = require("../utils");
19-
const capture_console_logs_1 = __importDefault(require("capture-console-logs"));
2016
const utils_2 = require("../../../../utils");
21-
const { types } = require("util");
2217
const process_modify_request_action = (action, ctx) => {
2318
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST_END];
2419
if (!allowed_handlers.includes(ctx.currentHandler)) {
@@ -72,19 +67,7 @@ const modify_request_using_code = (action, ctx) => __awaiter(void 0, void 0, voi
7267
catch (_a) {
7368
/*Do nothing -- could not parse body as JSON */
7469
}
75-
const consoleCapture = new capture_console_logs_1.default();
76-
consoleCapture.start(true);
77-
finalRequest = userFunction(args);
78-
if (types.isPromise(finalRequest)) {
79-
finalRequest = yield finalRequest;
80-
}
81-
consoleCapture.stop();
82-
const consoleLogs = consoleCapture.getCaptures();
83-
ctx.rq.consoleLogs.push(...consoleLogs);
84-
const isRequestJSON = !!args.bodyAsJson;
85-
if (typeof finalRequest === "object" && isRequestJSON) {
86-
finalRequest = JSON.stringify(finalRequest);
87-
}
70+
finalRequest = yield (0, utils_2.executeUserFunction)(ctx, userFunction, args);
8871
if (finalRequest && typeof finalRequest === "string") {
8972
return modify_request(ctx, finalRequest);
9073
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
1818
const utils_1 = require("../utils");
1919
const fs_1 = __importDefault(require("fs"));
2020
const http_helpers_1 = require("../../helpers/http_helpers");
21-
const capture_console_logs_1 = __importDefault(require("capture-console-logs"));
2221
const utils_2 = require("../../../../utils");
2322
const constants_1 = require("../../constants");
24-
const { types } = require("util");
2523
const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
2624
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST, proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END, proxy_1.PROXY_HANDLER_TYPE.ON_ERROR];
2725
if (!allowed_handlers.includes(ctx.currentHandler)) {
@@ -125,18 +123,7 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
125123
catch (_f) {
126124
/*Do nothing -- could not parse body as JSON */
127125
}
128-
const consoleCapture = new capture_console_logs_1.default();
129-
consoleCapture.start(true);
130-
finalResponse = userFunction(args);
131-
if (types.isPromise(finalResponse)) {
132-
finalResponse = yield finalResponse;
133-
}
134-
consoleCapture.stop();
135-
const consoleLogs = consoleCapture.getCaptures();
136-
ctx.rq.consoleLogs.push(...consoleLogs);
137-
if (typeof finalResponse === "object") {
138-
finalResponse = JSON.stringify(finalResponse);
139-
}
126+
finalResponse = yield (0, utils_2.executeUserFunction)(ctx, action.response, args);
140127
if (finalResponse && typeof finalResponse === "string") {
141128
return modify_response(ctx, finalResponse, action.statusCode);
142129
}

dist/rq-proxy-provider.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import RQProxy from "./rq-proxy";
22
import ILoggerService from "./components/interfaces/logger-service";
33
import IRulesDataSource from "./components/interfaces/rules-data-source";
4+
import IInitialState from "./components/interfaces/state";
45
import { ProxyConfig } from "./types";
56
declare class RQProxyProvider {
67
static rqProxyInstance: any;
7-
static createInstance: (proxyConfig: ProxyConfig, rulesDataSource: IRulesDataSource, loggerService: ILoggerService) => void;
8+
static createInstance: (proxyConfig: ProxyConfig, rulesDataSource: IRulesDataSource, loggerService: ILoggerService, initialGlobalState?: IInitialState) => void;
89
static getInstance: () => RQProxy;
910
}
1011
export default RQProxyProvider;

dist/rq-proxy-provider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class RQProxyProvider {
88
}
99
RQProxyProvider.rqProxyInstance = null;
1010
// TODO: rulesDataSource can be static here
11-
RQProxyProvider.createInstance = (proxyConfig, rulesDataSource, loggerService) => {
12-
RQProxyProvider.rqProxyInstance = new rq_proxy_1.default(proxyConfig, rulesDataSource, loggerService);
11+
RQProxyProvider.createInstance = (proxyConfig, rulesDataSource, loggerService, initialGlobalState) => {
12+
RQProxyProvider.rqProxyInstance = new rq_proxy_1.default(proxyConfig, rulesDataSource, loggerService, initialGlobalState);
1313
};
1414
RQProxyProvider.getInstance = () => {
1515
if (!RQProxyProvider.rqProxyInstance) {

0 commit comments

Comments
 (0)