@requestly/requestly-proxy 1.1.17 → 1.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,10 +22,29 @@ const capture_console_logs_1 = __importDefault(require("capture-console-logs"));
22
22
  const utils_2 = require("../../../../utils");
23
23
  const { types } = require("util");
24
24
  const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
25
- const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END, proxy_1.PROXY_HANDLER_TYPE.ON_ERROR];
25
+ 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];
26
26
  if (!allowed_handlers.includes(ctx.currentHandler)) {
27
27
  return (0, utils_1.build_action_processor_response)(action, false);
28
28
  }
29
+ if (ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST) {
30
+ if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC
31
+ && action.serveWithoutRequest) {
32
+ let contentType, finalBody;
33
+ try {
34
+ finalBody = JSON.parse(action.response);
35
+ contentType = "application/json";
36
+ }
37
+ catch (_a) {
38
+ contentType = "text/plain";
39
+ finalBody = action.response;
40
+ }
41
+ const status = action.statusCode || 200;
42
+ const finalHeaders = { "Content-Type": contentType };
43
+ modify_response(ctx, finalBody, status);
44
+ return (0, utils_1.build_action_processor_response)(action, true, (0, utils_1.build_post_process_data)(status, finalHeaders, finalBody));
45
+ }
46
+ return (0, utils_1.build_action_processor_response)(action, false);
47
+ }
29
48
  if (action.responseType &&
30
49
  action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
31
50
  yield modify_response_using_code(action, ctx);
@@ -55,7 +74,7 @@ const modify_response_using_local = (action, ctx) => {
55
74
  }
56
75
  };
57
76
  const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
58
- var _a, _b, _c, _d;
77
+ var _b, _c, _d, _e;
59
78
  let userFunction = null;
60
79
  try {
61
80
  userFunction = (0, utils_2.getFunctionFromString)(action.response);
@@ -80,14 +99,14 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
80
99
  : null,
81
100
  response: ctx === null || ctx === void 0 ? void 0 : ctx.rq_response_body,
82
101
  url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
83
- responseType: (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.serverToProxyResponse) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b["content-type"],
102
+ responseType: (_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.serverToProxyResponse) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c["content-type"],
84
103
  requestHeaders: ctx.clientToProxyRequest.headers,
85
- requestData: (0, http_helpers_1.parseJsonBody)((_d = (_c = ctx.rq) === null || _c === void 0 ? void 0 : _c.final_request) === null || _d === void 0 ? void 0 : _d.body) || null,
104
+ requestData: (0, http_helpers_1.parseJsonBody)((_e = (_d = ctx.rq) === null || _d === void 0 ? void 0 : _d.final_request) === null || _e === void 0 ? void 0 : _e.body) || null,
86
105
  };
87
106
  try {
88
107
  args.responseJSON = JSON.parse(args.response);
89
108
  }
90
- catch (_e) {
109
+ catch (_f) {
91
110
  /*Do nothing -- could not parse body as JSON */
92
111
  }
93
112
  const consoleCapture = new capture_console_logs_1.default();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "Proxy that gives superpowers to all the Requestly clients",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {