perimeterx-js-core 0.1.0

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.
Files changed (288) hide show
  1. package/README.md +158 -0
  2. package/lib/activities/ActivityType.d.ts +6 -0
  3. package/lib/activities/ActivityType.js +10 -0
  4. package/lib/activities/HttpActivityClient.d.ts +12 -0
  5. package/lib/activities/HttpActivityClient.js +107 -0
  6. package/lib/activities/IActivityClient.d.ts +8 -0
  7. package/lib/activities/IActivityClient.js +2 -0
  8. package/lib/activities/constants.d.ts +1 -0
  9. package/lib/activities/constants.js +4 -0
  10. package/lib/activities/index.d.ts +5 -0
  11. package/lib/activities/index.js +7 -0
  12. package/lib/activities/model/Activity.d.ts +13 -0
  13. package/lib/activities/model/Activity.js +2 -0
  14. package/lib/activities/model/ActivityDetails.d.ts +41 -0
  15. package/lib/activities/model/ActivityDetails.js +2 -0
  16. package/lib/activities/utils.d.ts +10 -0
  17. package/lib/activities/utils.js +88 -0
  18. package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +3 -0
  19. package/lib/additional_activity_handler/AdditionalActivityHandler.js +2 -0
  20. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +5 -0
  21. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +64 -0
  22. package/lib/additional_activity_handler/index.d.ts +2 -0
  23. package/lib/additional_activity_handler/index.js +5 -0
  24. package/lib/block_handler/BlockAction.d.ts +6 -0
  25. package/lib/block_handler/BlockAction.js +21 -0
  26. package/lib/block_handler/BlockReason.d.ts +4 -0
  27. package/lib/block_handler/BlockReason.js +8 -0
  28. package/lib/block_handler/DefaultBlockResponseGenerator.d.ts +14 -0
  29. package/lib/block_handler/DefaultBlockResponseGenerator.js +44 -0
  30. package/lib/block_handler/IBlockResponseGenerator.d.ts +14 -0
  31. package/lib/block_handler/IBlockResponseGenerator.js +2 -0
  32. package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.d.ts +14 -0
  33. package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.js +30 -0
  34. package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.d.ts +10 -0
  35. package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.js +25 -0
  36. package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.d.ts +10 -0
  37. package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.js +44 -0
  38. package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.d.ts +12 -0
  39. package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.js +36 -0
  40. package/lib/block_handler/index.d.ts +13 -0
  41. package/lib/block_handler/index.js +21 -0
  42. package/lib/block_handler/model/BlockData.d.ts +16 -0
  43. package/lib/block_handler/model/BlockData.js +2 -0
  44. package/lib/block_handler/model/JsonBlockPayload.d.ts +11 -0
  45. package/lib/block_handler/model/JsonBlockPayload.js +2 -0
  46. package/lib/block_handler/model/MobileBlockPayload.d.ts +8 -0
  47. package/lib/block_handler/model/MobileBlockPayload.js +2 -0
  48. package/lib/block_handler/templates/captcha_template.d.ts +1 -0
  49. package/lib/block_handler/templates/captcha_template.js +4 -0
  50. package/lib/block_handler/templates/rate_limit_template.d.ts +1 -0
  51. package/lib/block_handler/templates/rate_limit_template.js +4 -0
  52. package/lib/block_handler/utils.d.ts +5 -0
  53. package/lib/block_handler/utils.js +48 -0
  54. package/lib/config/ConfigurationParams.d.ts +65 -0
  55. package/lib/config/ConfigurationParams.js +2 -0
  56. package/lib/config/DefaultConfigurations.d.ts +2 -0
  57. package/lib/config/DefaultConfigurations.js +107 -0
  58. package/lib/config/IConfiguration.d.ts +172 -0
  59. package/lib/config/IConfiguration.js +2 -0
  60. package/lib/config/StaticConfigurationBase.d.ts +57 -0
  61. package/lib/config/StaticConfigurationBase.js +355 -0
  62. package/lib/config/index.d.ts +4 -0
  63. package/lib/config/index.js +7 -0
  64. package/lib/context/ContextBase.d.ts +55 -0
  65. package/lib/context/ContextBase.js +206 -0
  66. package/lib/context/DefaultTokenV2Context.d.ts +13 -0
  67. package/lib/context/DefaultTokenV2Context.js +35 -0
  68. package/lib/context/DefaultTokenV3Context.d.ts +13 -0
  69. package/lib/context/DefaultTokenV3Context.js +35 -0
  70. package/lib/context/IContext.d.ts +256 -0
  71. package/lib/context/IContext.js +2 -0
  72. package/lib/context/index.d.ts +4 -0
  73. package/lib/context/index.js +9 -0
  74. package/lib/custom_parameters/CustomParameters.d.ts +12 -0
  75. package/lib/custom_parameters/CustomParameters.js +2 -0
  76. package/lib/custom_parameters/CustomParametersFunction.d.ts +4 -0
  77. package/lib/custom_parameters/CustomParametersFunction.js +2 -0
  78. package/lib/custom_parameters/CustomParametersUtils.d.ts +4 -0
  79. package/lib/custom_parameters/CustomParametersUtils.js +19 -0
  80. package/lib/custom_parameters/index.d.ts +3 -0
  81. package/lib/custom_parameters/index.js +5 -0
  82. package/lib/enforcer/EnforcerBase.d.ts +139 -0
  83. package/lib/enforcer/EnforcerBase.js +376 -0
  84. package/lib/enforcer/IEnforcer.d.ts +4 -0
  85. package/lib/enforcer/IEnforcer.js +2 -0
  86. package/lib/enforcer/index.d.ts +2 -0
  87. package/lib/enforcer/index.js +5 -0
  88. package/lib/filter/DefaultFilter.d.ts +16 -0
  89. package/lib/filter/DefaultFilter.js +59 -0
  90. package/lib/filter/FilterReason.d.ts +8 -0
  91. package/lib/filter/FilterReason.js +12 -0
  92. package/lib/filter/IFilter.d.ts +8 -0
  93. package/lib/filter/IFilter.js +2 -0
  94. package/lib/filter/index.d.ts +3 -0
  95. package/lib/filter/index.js +7 -0
  96. package/lib/first_party/DefaultFirstParty.d.ts +22 -0
  97. package/lib/first_party/DefaultFirstParty.js +215 -0
  98. package/lib/first_party/IFirstParty.d.ts +9 -0
  99. package/lib/first_party/IFirstParty.js +2 -0
  100. package/lib/first_party/constants.d.ts +32 -0
  101. package/lib/first_party/constants.js +39 -0
  102. package/lib/first_party/index.d.ts +4 -0
  103. package/lib/first_party/index.js +21 -0
  104. package/lib/first_party/utils.d.ts +8 -0
  105. package/lib/first_party/utils.js +27 -0
  106. package/lib/http/IHttpClient.d.ts +10 -0
  107. package/lib/http/IHttpClient.js +2 -0
  108. package/lib/http/body_reader/IBodyReader.d.ts +5 -0
  109. package/lib/http/body_reader/IBodyReader.js +2 -0
  110. package/lib/http/body_reader/StringBodyReader.d.ts +8 -0
  111. package/lib/http/body_reader/StringBodyReader.js +70 -0
  112. package/lib/http/index.d.ts +10 -0
  113. package/lib/http/index.js +28 -0
  114. package/lib/http/request/DefaultHttpRequest.d.ts +5 -0
  115. package/lib/http/request/DefaultHttpRequest.js +42 -0
  116. package/lib/http/request/HttpRequestBase.d.ts +24 -0
  117. package/lib/http/request/HttpRequestBase.js +77 -0
  118. package/lib/http/request/IHttpRequest.d.ts +31 -0
  119. package/lib/http/request/IHttpRequest.js +2 -0
  120. package/lib/http/response/DefaultHttpResponse.d.ts +5 -0
  121. package/lib/http/response/DefaultHttpResponse.js +32 -0
  122. package/lib/http/response/HttpResponseBase.d.ts +17 -0
  123. package/lib/http/response/HttpResponseBase.js +75 -0
  124. package/lib/http/response/IHttpResponse.d.ts +26 -0
  125. package/lib/http/response/IHttpResponse.js +2 -0
  126. package/lib/http/utils/ContentType.d.ts +9 -0
  127. package/lib/http/utils/ContentType.js +13 -0
  128. package/lib/http/utils/HttpBody.d.ts +4 -0
  129. package/lib/http/utils/HttpBody.js +2 -0
  130. package/lib/http/utils/HttpHeaders.d.ts +51 -0
  131. package/lib/http/utils/HttpHeaders.js +106 -0
  132. package/lib/http/utils/HttpMethod.d.ts +11 -0
  133. package/lib/http/utils/HttpMethod.js +15 -0
  134. package/lib/http/utils/constants.d.ts +9 -0
  135. package/lib/http/utils/constants.js +12 -0
  136. package/lib/http/utils/index.d.ts +5 -0
  137. package/lib/http/utils/index.js +24 -0
  138. package/lib/index.d.ts +17 -0
  139. package/lib/index.js +33 -0
  140. package/lib/logger/DefaultLogger.d.ts +7 -0
  141. package/lib/logger/DefaultLogger.js +31 -0
  142. package/lib/logger/ILogger.d.ts +24 -0
  143. package/lib/logger/ILogger.js +2 -0
  144. package/lib/logger/LoggerBase.d.ts +11 -0
  145. package/lib/logger/LoggerBase.js +28 -0
  146. package/lib/logger/LoggerSeverity.d.ts +5 -0
  147. package/lib/logger/LoggerSeverity.js +9 -0
  148. package/lib/logger/index.d.ts +4 -0
  149. package/lib/logger/index.js +9 -0
  150. package/lib/pxde/DefaultDataEnrichment.d.ts +14 -0
  151. package/lib/pxde/DefaultDataEnrichment.js +133 -0
  152. package/lib/pxde/IDataEnrichment.d.ts +9 -0
  153. package/lib/pxde/IDataEnrichment.js +2 -0
  154. package/lib/pxde/constants.d.ts +4 -0
  155. package/lib/pxde/constants.js +7 -0
  156. package/lib/pxde/index.d.ts +4 -0
  157. package/lib/pxde/index.js +20 -0
  158. package/lib/pxde/model/PXDE.d.ts +9 -0
  159. package/lib/pxde/model/PXDE.js +2 -0
  160. package/lib/pxhd/PXHDUtils.d.ts +8 -0
  161. package/lib/pxhd/PXHDUtils.js +20 -0
  162. package/lib/pxhd/index.d.ts +1 -0
  163. package/lib/pxhd/index.js +5 -0
  164. package/lib/risk_api/PostRiskApiClient.d.ts +27 -0
  165. package/lib/risk_api/PostRiskApiClient.js +232 -0
  166. package/lib/risk_api/S2SCallReason.d.ts +12 -0
  167. package/lib/risk_api/S2SCallReason.js +16 -0
  168. package/lib/risk_api/S2SErrorHandler.d.ts +9 -0
  169. package/lib/risk_api/S2SErrorHandler.js +121 -0
  170. package/lib/risk_api/S2SErrorReason.d.ts +8 -0
  171. package/lib/risk_api/S2SErrorReason.js +12 -0
  172. package/lib/risk_api/constants.d.ts +1 -0
  173. package/lib/risk_api/constants.js +4 -0
  174. package/lib/risk_api/index.d.ts +13 -0
  175. package/lib/risk_api/index.js +34 -0
  176. package/lib/risk_api/model/RiskActivity.d.ts +50 -0
  177. package/lib/risk_api/model/RiskActivity.js +2 -0
  178. package/lib/risk_api/model/RiskResponseV2.d.ts +10 -0
  179. package/lib/risk_api/model/RiskResponseV2.js +2 -0
  180. package/lib/risk_api/model/RiskResponseV3.d.ts +12 -0
  181. package/lib/risk_api/model/RiskResponseV3.js +2 -0
  182. package/lib/risk_api/model/RiskStatus.d.ts +4 -0
  183. package/lib/risk_api/model/RiskStatus.js +8 -0
  184. package/lib/risk_api/risk_response_handler/IRiskResponseHandler.d.ts +5 -0
  185. package/lib/risk_api/risk_response_handler/IRiskResponseHandler.js +2 -0
  186. package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.d.ts +16 -0
  187. package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.js +73 -0
  188. package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.d.ts +10 -0
  189. package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +46 -0
  190. package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.d.ts +10 -0
  191. package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.js +47 -0
  192. package/lib/risk_token/MobileError.d.ts +6 -0
  193. package/lib/risk_token/MobileError.js +10 -0
  194. package/lib/risk_token/MobileErrorHandler.d.ts +9 -0
  195. package/lib/risk_token/MobileErrorHandler.js +100 -0
  196. package/lib/risk_token/RiskTokenScoreRetriever.d.ts +14 -0
  197. package/lib/risk_token/RiskTokenScoreRetriever.js +148 -0
  198. package/lib/risk_token/TokenOrigin.d.ts +4 -0
  199. package/lib/risk_token/TokenOrigin.js +8 -0
  200. package/lib/risk_token/TokenVerificationResult.d.ts +6 -0
  201. package/lib/risk_token/TokenVerificationResult.js +10 -0
  202. package/lib/risk_token/TokenVersion.d.ts +4 -0
  203. package/lib/risk_token/TokenVersion.js +8 -0
  204. package/lib/risk_token/constants.d.ts +9 -0
  205. package/lib/risk_token/constants.js +12 -0
  206. package/lib/risk_token/index.d.ts +9 -0
  207. package/lib/risk_token/index.js +32 -0
  208. package/lib/risk_token/token/BotDefenderTokenBase.d.ts +27 -0
  209. package/lib/risk_token/token/BotDefenderTokenBase.js +94 -0
  210. package/lib/risk_token/token/IBotDefenderToken.d.ts +54 -0
  211. package/lib/risk_token/token/IBotDefenderToken.js +2 -0
  212. package/lib/risk_token/token/index.d.ts +7 -0
  213. package/lib/risk_token/token/index.js +11 -0
  214. package/lib/risk_token/token/v2/BotDefenderTokenV2Payload.d.ts +6 -0
  215. package/lib/risk_token/token/v2/BotDefenderTokenV2Payload.js +2 -0
  216. package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.d.ts +28 -0
  217. package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.js +199 -0
  218. package/lib/risk_token/token/v3/BotDefenderTokenV3Payload.d.ts +9 -0
  219. package/lib/risk_token/token/v3/BotDefenderTokenV3Payload.js +2 -0
  220. package/lib/risk_token/token/v3/DefaultBotDefenderTokenV3.d.ts +31 -0
  221. package/lib/risk_token/token/v3/DefaultBotDefenderTokenV3.js +231 -0
  222. package/lib/risk_token/token/v3/TokenSignField.d.ts +4 -0
  223. package/lib/risk_token/token/v3/TokenSignField.js +8 -0
  224. package/lib/risk_token/utils.d.ts +2 -0
  225. package/lib/risk_token/utils.js +16 -0
  226. package/lib/telemetry/DefaultTelemetry.d.ts +19 -0
  227. package/lib/telemetry/DefaultTelemetry.js +176 -0
  228. package/lib/telemetry/ITelemetry.d.ts +13 -0
  229. package/lib/telemetry/ITelemetry.js +2 -0
  230. package/lib/telemetry/constants.d.ts +7 -0
  231. package/lib/telemetry/constants.js +10 -0
  232. package/lib/telemetry/index.d.ts +4 -0
  233. package/lib/telemetry/index.js +20 -0
  234. package/lib/telemetry/model/TelemetryActivity.d.ts +15 -0
  235. package/lib/telemetry/model/TelemetryActivity.js +2 -0
  236. package/lib/utils/Algorithm.d.ts +4 -0
  237. package/lib/utils/Algorithm.js +8 -0
  238. package/lib/utils/EnforcerException.d.ts +3 -0
  239. package/lib/utils/EnforcerException.js +26 -0
  240. package/lib/utils/IScoreRetriever.d.ts +14 -0
  241. package/lib/utils/IScoreRetriever.js +2 -0
  242. package/lib/utils/ModuleMode.d.ts +4 -0
  243. package/lib/utils/ModuleMode.js +8 -0
  244. package/lib/utils/PassReason.d.ts +6 -0
  245. package/lib/utils/PassReason.js +10 -0
  246. package/lib/utils/VidSource.d.ts +4 -0
  247. package/lib/utils/VidSource.js +8 -0
  248. package/lib/utils/base64/DefaultBase64Utils.d.ts +5 -0
  249. package/lib/utils/base64/DefaultBase64Utils.js +16 -0
  250. package/lib/utils/base64/IBase64Utils.d.ts +4 -0
  251. package/lib/utils/base64/IBase64Utils.js +2 -0
  252. package/lib/utils/base64/index.d.ts +2 -0
  253. package/lib/utils/base64/index.js +5 -0
  254. package/lib/utils/cipher/ICipherUtils.d.ts +7 -0
  255. package/lib/utils/cipher/ICipherUtils.js +2 -0
  256. package/lib/utils/cipher/index.d.ts +1 -0
  257. package/lib/utils/cipher/index.js +2 -0
  258. package/lib/utils/constants.d.ts +10 -0
  259. package/lib/utils/constants.js +13 -0
  260. package/lib/utils/cookie_parser/DefaultCookieParser.d.ts +4 -0
  261. package/lib/utils/cookie_parser/DefaultCookieParser.js +13 -0
  262. package/lib/utils/cookie_parser/ICookieParser.d.ts +3 -0
  263. package/lib/utils/cookie_parser/ICookieParser.js +2 -0
  264. package/lib/utils/cookie_parser/index.d.ts +2 -0
  265. package/lib/utils/cookie_parser/index.js +5 -0
  266. package/lib/utils/hash/DefaultHashUtils.d.ts +5 -0
  267. package/lib/utils/hash/DefaultHashUtils.js +19 -0
  268. package/lib/utils/hash/IHashUtils.d.ts +4 -0
  269. package/lib/utils/hash/IHashUtils.js +2 -0
  270. package/lib/utils/hash/index.d.ts +2 -0
  271. package/lib/utils/hash/index.js +5 -0
  272. package/lib/utils/index.d.ts +14 -0
  273. package/lib/utils/index.js +35 -0
  274. package/lib/utils/ip_range_checker/DefaultIpRangeChecker.d.ts +4 -0
  275. package/lib/utils/ip_range_checker/DefaultIpRangeChecker.js +13 -0
  276. package/lib/utils/ip_range_checker/IIpRangeChecker.d.ts +3 -0
  277. package/lib/utils/ip_range_checker/IIpRangeChecker.js +2 -0
  278. package/lib/utils/ip_range_checker/index.d.ts +2 -0
  279. package/lib/utils/ip_range_checker/index.js +5 -0
  280. package/lib/utils/utils.d.ts +13 -0
  281. package/lib/utils/utils.js +91 -0
  282. package/lib/utils/uuid_generator/DefaultUuidGenerator.d.ts +4 -0
  283. package/lib/utils/uuid_generator/DefaultUuidGenerator.js +13 -0
  284. package/lib/utils/uuid_generator/IUuidGenerator.d.ts +3 -0
  285. package/lib/utils/uuid_generator/IUuidGenerator.js +2 -0
  286. package/lib/utils/uuid_generator/index.d.ts +2 -0
  287. package/lib/utils/uuid_generator/index.js +5 -0
  288. package/package.json +52 -0
@@ -0,0 +1,22 @@
1
+ import { IConfiguration } from '../config';
2
+ import { IContext } from '../context/IContext';
3
+ import { IHttpClient, IHttpResponse } from '../http';
4
+ import { IFirstParty } from './IFirstParty';
5
+ export declare class DefaultFirstParty implements IFirstParty {
6
+ private readonly config;
7
+ private readonly httpClient;
8
+ constructor(config: IConfiguration, httpClient: IHttpClient);
9
+ handleFirstPartyRequest(context: IContext): Promise<IHttpResponse>;
10
+ private proxySensorScriptRequest;
11
+ private proxyXhrRequest;
12
+ private static getDefaultXhrResponse;
13
+ private proxyCaptchaScriptRequest;
14
+ private forwardRequest;
15
+ private prepareFirstPartyHeaders;
16
+ private setHostHeader;
17
+ private setXffHeader;
18
+ private addFirstPartyHeaders;
19
+ private getThirdPartySensorScriptUrl;
20
+ private getThirdPartyCaptchaScriptUrl;
21
+ private getThirdPartyXhrUrl;
22
+ }
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.DefaultFirstParty = void 0;
40
+ var utils_1 = require("../utils");
41
+ var http_1 = require("../http");
42
+ var utils_2 = require("./utils");
43
+ var constants_1 = require("./constants");
44
+ var DefaultFirstParty = /** @class */ (function () {
45
+ function DefaultFirstParty(config, httpClient) {
46
+ this.config = config;
47
+ this.httpClient = httpClient;
48
+ }
49
+ DefaultFirstParty.prototype.handleFirstPartyRequest = function (context) {
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var pathname, xhrPrefix, captchaPrefix;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ pathname = context.requestData.url.pathname;
56
+ if (!(0, utils_2.getFirstPartySensorScriptPaths)(this.config).includes(pathname)) return [3 /*break*/, 2];
57
+ return [4 /*yield*/, this.proxySensorScriptRequest(context)];
58
+ case 1: return [2 /*return*/, _a.sent()];
59
+ case 2:
60
+ xhrPrefix = (0, utils_2.getFirstPartyXhrPathPrefixes)(this.config).find(function (prefix) { return pathname.startsWith(prefix); });
61
+ if (!xhrPrefix) return [3 /*break*/, 4];
62
+ return [4 /*yield*/, this.proxyXhrRequest(context, xhrPrefix)];
63
+ case 3: return [2 /*return*/, _a.sent()];
64
+ case 4:
65
+ captchaPrefix = (0, utils_2.getFirstPartyCaptchaScriptPathPrefixes)(this.config).find(function (prefix) {
66
+ return pathname.startsWith(prefix);
67
+ });
68
+ if (!captchaPrefix) return [3 /*break*/, 6];
69
+ return [4 /*yield*/, this.proxyCaptchaScriptRequest(context, captchaPrefix)];
70
+ case 5: return [2 /*return*/, _a.sent()];
71
+ case 6: return [2 /*return*/, null];
72
+ }
73
+ });
74
+ });
75
+ };
76
+ DefaultFirstParty.prototype.proxySensorScriptRequest = function (context) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var url, response;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ if (!this.config.firstPartyEnabled) {
83
+ return [2 /*return*/, new http_1.DefaultHttpResponse(constants_1.DEFAULT_CLIENT_RESPONSE.content, constants_1.DEFAULT_CLIENT_RESPONSE.options)];
84
+ }
85
+ url = this.getThirdPartySensorScriptUrl();
86
+ return [4 /*yield*/, this.forwardRequest(url, context)];
87
+ case 1:
88
+ response = _a.sent();
89
+ return [2 /*return*/, response
90
+ ? response
91
+ : new http_1.DefaultHttpResponse(constants_1.DEFAULT_CLIENT_RESPONSE.content, constants_1.DEFAULT_CLIENT_RESPONSE.options)];
92
+ }
93
+ });
94
+ });
95
+ };
96
+ DefaultFirstParty.prototype.proxyXhrRequest = function (context, prefix) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var url, response;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0:
102
+ if (!this.config.firstPartyEnabled) {
103
+ return [2 /*return*/, DefaultFirstParty.getDefaultXhrResponse(context.requestData.url.pathname)];
104
+ }
105
+ url = this.getThirdPartyXhrUrl(context, prefix);
106
+ return [4 /*yield*/, this.forwardRequest(url, context)];
107
+ case 1:
108
+ response = _a.sent();
109
+ return [2 /*return*/, (response === null || response === void 0 ? void 0 : response.status) < 400
110
+ ? response
111
+ : DefaultFirstParty.getDefaultXhrResponse(context.requestData.url.pathname)];
112
+ }
113
+ });
114
+ });
115
+ };
116
+ DefaultFirstParty.getDefaultXhrResponse = function (path) {
117
+ var _a = path.endsWith('.gif') ? constants_1.DEFAULT_GIF_RESPONSE : constants_1.DEFAULT_XHR_RESPONSE, content = _a.content, options = _a.options;
118
+ return new http_1.DefaultHttpResponse(content, options);
119
+ };
120
+ DefaultFirstParty.prototype.proxyCaptchaScriptRequest = function (context, prefix) {
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ var url, response;
123
+ return __generator(this, function (_a) {
124
+ switch (_a.label) {
125
+ case 0:
126
+ if (!this.config.firstPartyEnabled) {
127
+ return [2 /*return*/, new http_1.DefaultHttpResponse(constants_1.DEFAULT_CLIENT_RESPONSE.content, constants_1.DEFAULT_CLIENT_RESPONSE.options)];
128
+ }
129
+ url = this.getThirdPartyCaptchaScriptUrl(context, prefix);
130
+ return [4 /*yield*/, this.forwardRequest(url, context)];
131
+ case 1:
132
+ response = _a.sent();
133
+ return [2 /*return*/, response
134
+ ? response
135
+ : new http_1.DefaultHttpResponse(constants_1.DEFAULT_CLIENT_RESPONSE.content, constants_1.DEFAULT_CLIENT_RESPONSE.options)];
136
+ }
137
+ });
138
+ });
139
+ };
140
+ DefaultFirstParty.prototype.forwardRequest = function (url, _a) {
141
+ var requestData = _a.requestData, vid = _a.vid;
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var firstPartyReq, e_1;
144
+ return __generator(this, function (_b) {
145
+ switch (_b.label) {
146
+ case 0:
147
+ _b.trys.push([0, 2, , 3]);
148
+ firstPartyReq = requestData.request;
149
+ firstPartyReq.url = url;
150
+ firstPartyReq.headers = this.prepareFirstPartyHeaders(url, requestData, vid);
151
+ this.config.logger.debug('forwarding to ' + url);
152
+ return [4 /*yield*/, this.httpClient.send(firstPartyReq)];
153
+ case 1: return [2 /*return*/, _b.sent()];
154
+ case 2:
155
+ e_1 = _b.sent();
156
+ this.config.logger.debug("failed sending first party request to ".concat(url));
157
+ return [2 /*return*/, null];
158
+ case 3: return [2 /*return*/];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ DefaultFirstParty.prototype.prepareFirstPartyHeaders = function (url, requestData, vid) {
164
+ var headers = requestData.headers.copy();
165
+ try {
166
+ headers = (0, utils_1.removeSensitiveHeaders)(headers, this.config.sensitiveHeaders);
167
+ this.setHostHeader(headers, url);
168
+ this.setXffHeader(headers, requestData.ip);
169
+ this.addFirstPartyHeaders(headers, requestData.ip);
170
+ if (vid) {
171
+ headers.append(http_1.COOKIE_HEADER_NAME, "pxvid=".concat(vid));
172
+ }
173
+ }
174
+ catch (e) {
175
+ this.config.logger.error("Caught error preparing first party headers: ".concat(e));
176
+ }
177
+ return headers;
178
+ };
179
+ DefaultFirstParty.prototype.setHostHeader = function (headers, url) {
180
+ var host = new URL(url).host;
181
+ headers.set(http_1.HOST_HEADER_NAME, host);
182
+ };
183
+ DefaultFirstParty.prototype.setXffHeader = function (headers, ip) {
184
+ var _a;
185
+ var xffValue = (_a = headers.get(http_1.X_FORWARDED_FOR_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0];
186
+ if (xffValue) {
187
+ xffValue += ", ".concat(ip);
188
+ }
189
+ else {
190
+ xffValue = ip;
191
+ }
192
+ headers.set(http_1.X_FORWARDED_FOR_HEADER_NAME, xffValue);
193
+ };
194
+ DefaultFirstParty.prototype.addFirstPartyHeaders = function (headers, ip) {
195
+ headers.set(constants_1.FIRST_PARTY_HEADER_NAME, constants_1.FIRST_PARTY_HEADER_VALUE);
196
+ headers.set(constants_1.X_PX_ENFORCER_TRUE_IP_HEADER_NAME, ip);
197
+ };
198
+ DefaultFirstParty.prototype.getThirdPartySensorScriptUrl = function () {
199
+ return "".concat(this.config.backendClientUrl, "/").concat(this.config.appId, "/main.min.js");
200
+ };
201
+ DefaultFirstParty.prototype.getThirdPartyCaptchaScriptUrl = function (context, prefix) {
202
+ var originalUrl = context.requestData.url;
203
+ var _a = this.config, appId = _a.appId, backendCaptchaUrl = _a.backendCaptchaUrl;
204
+ var regExString = "".concat(originalUrl.origin).concat(prefix);
205
+ var regEx = new RegExp(regExString, 'ig');
206
+ return "".concat(backendCaptchaUrl, "/").concat(appId).concat(originalUrl.href.replace(regEx, ''));
207
+ };
208
+ DefaultFirstParty.prototype.getThirdPartyXhrUrl = function (context, prefix) {
209
+ var originalUrl = context.requestData.url;
210
+ var backendCollectorUrl = this.config.backendCollectorUrl;
211
+ return "".concat(backendCollectorUrl).concat(originalUrl.pathname.replace(prefix, '')).concat(originalUrl.search);
212
+ };
213
+ return DefaultFirstParty;
214
+ }());
215
+ exports.DefaultFirstParty = DefaultFirstParty;
@@ -0,0 +1,9 @@
1
+ import { IContext } from '../context';
2
+ import { IHttpResponse } from '../http';
3
+ export interface IFirstParty {
4
+ /**
5
+ * @param context - The request context
6
+ * @returns Promise<IHttpResponse<UnreadBodyType>> - If the request is not a first party request, it will return null.
7
+ */
8
+ handleFirstPartyRequest(context: IContext): Promise<IHttpResponse>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,32 @@
1
+ import { ContentType } from '../http';
2
+ export declare const EMPTY_GIF: number[];
3
+ export declare const X_PX_ENFORCER_TRUE_IP_HEADER_NAME = "x-px-enforcer-true-ip";
4
+ export declare const FIRST_PARTY_HEADER_NAME = "x-px-first-party";
5
+ export declare const FIRST_PARTY_HEADER_VALUE = "1";
6
+ export declare const DEFAULT_CLIENT_RESPONSE: {
7
+ content: string;
8
+ options: {
9
+ status: number;
10
+ headers: {
11
+ "content-type": ContentType[];
12
+ };
13
+ };
14
+ };
15
+ export declare const DEFAULT_XHR_RESPONSE: {
16
+ content: string;
17
+ options: {
18
+ status: number;
19
+ headers: {
20
+ "content-type": ContentType[];
21
+ };
22
+ };
23
+ };
24
+ export declare const DEFAULT_GIF_RESPONSE: {
25
+ content: string;
26
+ options: {
27
+ status: number;
28
+ headers: {
29
+ "content-type": ContentType[];
30
+ };
31
+ };
32
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var _a, _b, _c;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DEFAULT_GIF_RESPONSE = exports.DEFAULT_XHR_RESPONSE = exports.DEFAULT_CLIENT_RESPONSE = exports.FIRST_PARTY_HEADER_VALUE = exports.FIRST_PARTY_HEADER_NAME = exports.X_PX_ENFORCER_TRUE_IP_HEADER_NAME = exports.EMPTY_GIF = void 0;
5
+ var http_1 = require("../http");
6
+ exports.EMPTY_GIF = [
7
+ 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
8
+ 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x3b,
9
+ ];
10
+ exports.X_PX_ENFORCER_TRUE_IP_HEADER_NAME = 'x-px-enforcer-true-ip';
11
+ exports.FIRST_PARTY_HEADER_NAME = 'x-px-first-party';
12
+ exports.FIRST_PARTY_HEADER_VALUE = '1';
13
+ exports.DEFAULT_CLIENT_RESPONSE = {
14
+ content: '',
15
+ options: {
16
+ status: 200,
17
+ headers: (_a = {},
18
+ _a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.APPLICATION_JAVASCRIPT],
19
+ _a),
20
+ },
21
+ };
22
+ exports.DEFAULT_XHR_RESPONSE = {
23
+ content: '{}',
24
+ options: {
25
+ status: 200,
26
+ headers: (_b = {},
27
+ _b[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.APPLICATION_JAVASCRIPT],
28
+ _b),
29
+ },
30
+ };
31
+ exports.DEFAULT_GIF_RESPONSE = {
32
+ content: 'GIF89a\x01\x00\x01\x00\x80\x00\x00ÿÿÿ\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;',
33
+ options: {
34
+ status: 200,
35
+ headers: (_c = {},
36
+ _c[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.IMAGE_GIF],
37
+ _c),
38
+ },
39
+ };
@@ -0,0 +1,4 @@
1
+ export { IFirstParty } from './IFirstParty';
2
+ export { DefaultFirstParty } from './DefaultFirstParty';
3
+ export * from './utils';
4
+ export * from './constants';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DefaultFirstParty = void 0;
18
+ var DefaultFirstParty_1 = require("./DefaultFirstParty");
19
+ Object.defineProperty(exports, "DefaultFirstParty", { enumerable: true, get: function () { return DefaultFirstParty_1.DefaultFirstParty; } });
20
+ __exportStar(require("./utils"), exports);
21
+ __exportStar(require("./constants"), exports);
@@ -0,0 +1,8 @@
1
+ import { IConfiguration } from '../config';
2
+ export declare const getDefaultFirstPartyPrefix: (appId: string) => string;
3
+ export declare const getFirstPartySensorScriptPaths: (config: IConfiguration) => string[];
4
+ export declare const getFirstPartyCaptchaScriptPathPrefixes: (config: IConfiguration) => string[];
5
+ export declare const getFirstPartyXhrPathPrefixes: (config: IConfiguration) => string[];
6
+ export declare const getFirstPartySensorScriptPath: (prefix: string) => string;
7
+ export declare const getFirstPartyCaptchaScriptPathPrefix: (prefix: string) => string;
8
+ export declare const getFirstPartyXhrPathPrefix: (prefix: string) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFirstPartyXhrPathPrefix = exports.getFirstPartyCaptchaScriptPathPrefix = exports.getFirstPartySensorScriptPath = exports.getFirstPartyXhrPathPrefixes = exports.getFirstPartyCaptchaScriptPathPrefixes = exports.getFirstPartySensorScriptPaths = exports.getDefaultFirstPartyPrefix = void 0;
4
+ var getDefaultFirstPartyPrefix = function (appId) { return appId.substring(2); };
5
+ exports.getDefaultFirstPartyPrefix = getDefaultFirstPartyPrefix;
6
+ var getFirstPartyPaths = function (config, callback) {
7
+ var allPrefixes = [config.firstPartyPrefix, (0, exports.getDefaultFirstPartyPrefix)(config.appId)];
8
+ return Array.from(new Set(allPrefixes)).map(callback);
9
+ };
10
+ var getFirstPartySensorScriptPaths = function (config) {
11
+ return getFirstPartyPaths(config, exports.getFirstPartySensorScriptPath);
12
+ };
13
+ exports.getFirstPartySensorScriptPaths = getFirstPartySensorScriptPaths;
14
+ var getFirstPartyCaptchaScriptPathPrefixes = function (config) {
15
+ return getFirstPartyPaths(config, exports.getFirstPartyCaptchaScriptPathPrefix);
16
+ };
17
+ exports.getFirstPartyCaptchaScriptPathPrefixes = getFirstPartyCaptchaScriptPathPrefixes;
18
+ var getFirstPartyXhrPathPrefixes = function (config) {
19
+ return getFirstPartyPaths(config, exports.getFirstPartyXhrPathPrefix);
20
+ };
21
+ exports.getFirstPartyXhrPathPrefixes = getFirstPartyXhrPathPrefixes;
22
+ var getFirstPartySensorScriptPath = function (prefix) { return "/".concat(prefix, "/init.js"); };
23
+ exports.getFirstPartySensorScriptPath = getFirstPartySensorScriptPath;
24
+ var getFirstPartyCaptchaScriptPathPrefix = function (prefix) { return "/".concat(prefix, "/captcha"); };
25
+ exports.getFirstPartyCaptchaScriptPathPrefix = getFirstPartyCaptchaScriptPathPrefix;
26
+ var getFirstPartyXhrPathPrefix = function (prefix) { return "/".concat(prefix, "/xhr"); };
27
+ exports.getFirstPartyXhrPathPrefix = getFirstPartyXhrPathPrefix;
@@ -0,0 +1,10 @@
1
+ import { IHttpRequest } from './request/IHttpRequest';
2
+ import { IHttpResponse } from './response/IHttpResponse';
3
+ export interface IHttpClient<UnreadBodyType = unknown> {
4
+ /**
5
+ * A function that sends the provided IHttpRequest and returns a Promise resolving to an IHttpResponse.
6
+ * @param request - The request to be sent by the client.
7
+ * @returns Promise<IHttpResponse> - A Promise resolving to the response the client received.
8
+ */
9
+ send(request: IHttpRequest<UnreadBodyType>): Promise<IHttpResponse<UnreadBodyType>>;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { ContentType, HttpBody } from '../utils';
2
+ export interface IBodyReader<UnreadBodyType> {
3
+ readonly body: UnreadBodyType | string;
4
+ readBody(contentType: ContentType): Promise<HttpBody>;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { ContentType, HttpBody } from '../utils';
2
+ import { IBodyReader } from './IBodyReader';
3
+ export declare class StringBodyReader implements IBodyReader<string> {
4
+ readonly body: string;
5
+ constructor(rawBody: string);
6
+ readBody(contentType: ContentType): Promise<HttpBody>;
7
+ private convertFormUrlEncodedStringToObject;
8
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.StringBodyReader = void 0;
40
+ var StringBodyReader = /** @class */ (function () {
41
+ function StringBodyReader(rawBody) {
42
+ this.body = rawBody;
43
+ }
44
+ StringBodyReader.prototype.readBody = function (contentType) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ return __generator(this, function (_a) {
47
+ if (!contentType) {
48
+ return [2 /*return*/, this.body];
49
+ }
50
+ if (contentType.includes('json')) {
51
+ return [2 /*return*/, JSON.parse(this.body)];
52
+ }
53
+ else if (contentType.includes('form-urlencoded')) {
54
+ return [2 /*return*/, this.convertFormUrlEncodedStringToObject(this.body)];
55
+ }
56
+ return [2 /*return*/, this.body];
57
+ });
58
+ });
59
+ };
60
+ StringBodyReader.prototype.convertFormUrlEncodedStringToObject = function (formUrlEncodedString) {
61
+ var object = {};
62
+ var params = new URLSearchParams(formUrlEncodedString);
63
+ params.forEach(function (value, key) {
64
+ object[key] = value;
65
+ });
66
+ return object;
67
+ };
68
+ return StringBodyReader;
69
+ }());
70
+ exports.StringBodyReader = StringBodyReader;
@@ -0,0 +1,10 @@
1
+ export { IHttpClient } from './IHttpClient';
2
+ export { IHttpRequest } from './request/IHttpRequest';
3
+ export { HttpRequestBase, HttpRequestOptions, HttpRequestBaseOptions } from './request/HttpRequestBase';
4
+ export { DefaultHttpRequest } from './request/DefaultHttpRequest';
5
+ export { IHttpResponse } from './response/IHttpResponse';
6
+ export { HttpResponseBase, HttpResponseOptions } from './response/HttpResponseBase';
7
+ export { DefaultHttpResponse } from './response/DefaultHttpResponse';
8
+ export { IBodyReader } from './body_reader/IBodyReader';
9
+ export { StringBodyReader } from './body_reader/StringBodyReader';
10
+ export * from './utils';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.StringBodyReader = exports.DefaultHttpResponse = exports.HttpResponseBase = exports.DefaultHttpRequest = exports.HttpRequestBase = void 0;
18
+ var HttpRequestBase_1 = require("./request/HttpRequestBase");
19
+ Object.defineProperty(exports, "HttpRequestBase", { enumerable: true, get: function () { return HttpRequestBase_1.HttpRequestBase; } });
20
+ var DefaultHttpRequest_1 = require("./request/DefaultHttpRequest");
21
+ Object.defineProperty(exports, "DefaultHttpRequest", { enumerable: true, get: function () { return DefaultHttpRequest_1.DefaultHttpRequest; } });
22
+ var HttpResponseBase_1 = require("./response/HttpResponseBase");
23
+ Object.defineProperty(exports, "HttpResponseBase", { enumerable: true, get: function () { return HttpResponseBase_1.HttpResponseBase; } });
24
+ var DefaultHttpResponse_1 = require("./response/DefaultHttpResponse");
25
+ Object.defineProperty(exports, "DefaultHttpResponse", { enumerable: true, get: function () { return DefaultHttpResponse_1.DefaultHttpResponse; } });
26
+ var StringBodyReader_1 = require("./body_reader/StringBodyReader");
27
+ Object.defineProperty(exports, "StringBodyReader", { enumerable: true, get: function () { return StringBodyReader_1.StringBodyReader; } });
28
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,5 @@
1
+ import { HttpRequestBase, HttpRequestOptions } from './HttpRequestBase';
2
+ export declare class DefaultHttpRequest extends HttpRequestBase<string, DefaultHttpRequest> {
3
+ constructor(url: string, options?: HttpRequestOptions<string>);
4
+ getUnderlyingRequest(): DefaultHttpRequest;
5
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DefaultHttpRequest = void 0;
30
+ var StringBodyReader_1 = require("../body_reader/StringBodyReader");
31
+ var HttpRequestBase_1 = require("./HttpRequestBase");
32
+ var DefaultHttpRequest = /** @class */ (function (_super) {
33
+ __extends(DefaultHttpRequest, _super);
34
+ function DefaultHttpRequest(url, options) {
35
+ return _super.call(this, url, __assign(__assign({}, options), { bodyReader: (options === null || options === void 0 ? void 0 : options.body) ? new StringBodyReader_1.StringBodyReader(options.body) : undefined })) || this;
36
+ }
37
+ DefaultHttpRequest.prototype.getUnderlyingRequest = function () {
38
+ return this;
39
+ };
40
+ return DefaultHttpRequest;
41
+ }(HttpRequestBase_1.HttpRequestBase));
42
+ exports.DefaultHttpRequest = DefaultHttpRequest;
@@ -0,0 +1,24 @@
1
+ import { HttpHeaders, HttpHeadersInit, HttpMethod, HttpBody } from '../utils';
2
+ import { IHttpRequest } from './IHttpRequest';
3
+ import { IBodyReader } from '../body_reader/IBodyReader';
4
+ export declare type HttpRequestOptions<UnreadBodyType> = {
5
+ method?: HttpMethod;
6
+ headers?: HttpHeaders | HttpHeadersInit;
7
+ body?: UnreadBodyType;
8
+ };
9
+ export declare type HttpRequestBaseOptions<UnreadBodyType> = {
10
+ method?: HttpMethod;
11
+ headers?: HttpHeaders | HttpHeadersInit;
12
+ bodyReader?: IBodyReader<UnreadBodyType>;
13
+ };
14
+ export declare abstract class HttpRequestBase<UnreadBodyType, Req> implements IHttpRequest<UnreadBodyType, Req> {
15
+ readonly url: string;
16
+ readonly method: HttpMethod;
17
+ readonly headers: HttpHeaders;
18
+ protected readonly bodyReader: IBodyReader<UnreadBodyType>;
19
+ protected httpBody: HttpBody;
20
+ abstract getUnderlyingRequest(): Req;
21
+ protected constructor(url: string, options?: HttpRequestBaseOptions<UnreadBodyType>);
22
+ get body(): UnreadBodyType | string;
23
+ readBody(): Promise<HttpBody>;
24
+ }