@requestly/requestly-proxy 1.1.5 → 1.1.7

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.
@@ -1,2 +1,3 @@
1
1
  export function bodyParser(contentTypeHeader: any, buffer: any): any;
2
2
  export function getContentType(contentTypeHeader: any): any;
3
+ export function parseJsonBody(data: any): any;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getContentType = exports.bodyParser = void 0;
6
+ exports.parseJsonBody = exports.getContentType = exports.bodyParser = void 0;
7
7
  const charset_1 = __importDefault(require("charset"));
8
8
  const mime_types_1 = __importDefault(require("mime-types"));
9
9
  const bodyParser = (contentTypeHeader, buffer) => {
@@ -45,3 +45,13 @@ const getContentType = (contentTypeHeader) => {
45
45
  return contentType;
46
46
  };
47
47
  exports.getContentType = getContentType;
48
+ const parseJsonBody = (data) => {
49
+ try {
50
+ return JSON.parse(data);
51
+ }
52
+ catch (e) {
53
+ /* Body is still buffer array */
54
+ }
55
+ return data;
56
+ };
57
+ exports.parseJsonBody = parseJsonBody;
@@ -64,6 +64,7 @@ class RuleProcessorHelper {
64
64
  const rule_action = rule_processor.process({
65
65
  rule,
66
66
  requestURL: this.request_data.request_url,
67
+ details: this.request_data
67
68
  });
68
69
  return rule_action;
69
70
  };
@@ -78,7 +79,7 @@ class RuleProcessorHelper {
78
79
  const rule_action = rule_processor.process({
79
80
  rule,
80
81
  requestURL: this.request_data.request_url,
81
- details: { requestData },
82
+ details: Object.assign(Object.assign({}, this.request_data), { requestData }),
82
83
  });
83
84
  return rule_action;
84
85
  };
@@ -93,7 +94,7 @@ class RuleProcessorHelper {
93
94
  const rule_action = rule_processor.process({
94
95
  rule,
95
96
  requestURL: this.request_data.request_url,
96
- details: { requestData },
97
+ details: Object.assign(Object.assign({}, this.request_data), { requestData }),
97
98
  });
98
99
  return rule_action;
99
100
  };
@@ -127,6 +128,7 @@ class RuleProcessorHelper {
127
128
  payload: {
128
129
  requestOrigin: getRequestOrigin(),
129
130
  },
131
+ details: this.request_data
130
132
  });
131
133
  return rule_action;
132
134
  };
@@ -162,6 +164,7 @@ class RuleProcessorHelper {
162
164
  payload: {
163
165
  requestOrigin: getRequestOrigin(),
164
166
  },
167
+ details: this.request_data
165
168
  });
166
169
  return rule_action;
167
170
  };
@@ -182,6 +185,7 @@ class RuleProcessorHelper {
182
185
  requestURL: this.request_data.request_url,
183
186
  rule,
184
187
  originalRequestHeaders: originalRequestHeadersObjectKeysValuePairs,
188
+ details: this.request_data
185
189
  });
186
190
  return rule_action;
187
191
  };
@@ -17,6 +17,7 @@ const requestly_core_1 = require("@requestly/requestly-core");
17
17
  const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
18
18
  const utils_1 = require("../utils");
19
19
  const fs_1 = __importDefault(require("fs"));
20
+ const http_helpers_1 = require("../../helpers/http_helpers");
20
21
  const { types } = require("util");
21
22
  const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
22
23
  const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END];
@@ -52,6 +53,7 @@ const modify_response_using_local = (action, ctx) => {
52
53
  }
53
54
  };
54
55
  const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
56
+ var _a, _b;
55
57
  let userFunction = null;
56
58
  try {
57
59
  userFunction = requestly_core_1.UTILS.GET_FUNCTION_FROM_STRING(action.response);
@@ -78,12 +80,12 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
78
80
  url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
79
81
  responseType: ctx.serverToProxyResponse.headers["content-type"],
80
82
  requestHeaders: ctx.clientToProxyRequest.headers,
81
- requestData: null,
83
+ requestData: (0, http_helpers_1.parseJsonBody)((_b = (_a = ctx.rq) === null || _a === void 0 ? void 0 : _a.final_request) === null || _b === void 0 ? void 0 : _b.body) || null,
82
84
  };
83
85
  try {
84
86
  args.responseJSON = JSON.parse(args.response);
85
87
  }
86
- catch (_a) {
88
+ catch (_c) {
87
89
  /*Do nothing -- could not parse body as JSON */
88
90
  }
89
91
  finalResponse = userFunction(args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Proxy that gives superpowers to all the Requestly clients",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "author": "",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@requestly/requestly-core": "^1.0.0",
18
+ "@requestly/requestly-core": "^1.0.2",
19
19
  "@sentry/browser": "^6.19.2",
20
20
  "async": "^3.2.1",
21
21
  "axios": "^0.26.1",