perimeterx-js-core 0.4.0 → 0.4.2

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.
package/README.md CHANGED
@@ -77,23 +77,20 @@ While you will need to create a custom implementation for the request context, y
77
77
  ### HTTP
78
78
 
79
79
  Every framework has a different API for creating and sending HTTP requests and responses. This library reduces this functionality
80
- into three interfaces:
80
+ into several interfaces:
81
81
 
82
- `IHttpRequest` - Represents an HTTP request.
82
+ `IIncomingRequest` - Represents an HTTP request from the user.
83
83
 
84
- `IHttpResponse` - Represents an HTTP response.
84
+ `IOutgoingResponse` - Represents an HTTP response which is returned to the user.
85
85
 
86
- `IHttpClient` - Represents a client that can send an `IHttpRequest` and return an `IHttpResponse`.
86
+ `IOutgoingRequest` - Represents an HTTP request that can be executed (sent to other origin)
87
87
 
88
- When developing your JavaScript/TypeScript enforcer with this library, you will need to wrap the native HTTP request/response
89
- objects such that they conform to these interfaces. Of course, you are free to extend these interfaces as needed.
88
+ `IIncomingResponse` - Represents an HTTP response that received from sending `IOutgoingRequest`
90
89
 
91
- The `HttpRequestBase` and `HttpResponseBase` classes are also provided for minimizing code repetition, simplifying
92
- encapsulating request and response body handling to a single `IBodyReader` interface.
90
+ `IHttpClient` - Represents a client that can send an `IIncomingRequest` and return an `IOutgoingResponse`.
93
91
 
94
- The library also provides the `DefaultHttpRequest` and `DefaultHttpResponse` classes, simple implementations of the
95
- `IHttpRequest` and `IHttpResponse` interfaces, which are used internally. These implementations use the `StringBodyReader`
96
- class to parse request and response bodies provided as strings.
92
+ When developing your JavaScript/TypeScript enforcer with this library, you will need to wrap the native HTTP request/response
93
+ objects such that they conform to these interfaces. Of course, you are free to extend these interfaces as needed.
97
94
 
98
95
  You will also need to implement an HTTP client. You can do this however you see fit: use the platform's built-in API
99
96
  or use an external library (e.g., `phin`, `axios`) if needed.
@@ -6,7 +6,7 @@ export declare type Activity = {
6
6
  socket_ip: string;
7
7
  url: string;
8
8
  px_app_id: string;
9
- headers?: Record<string, string | string[]>;
9
+ headers?: Record<string, string>;
10
10
  vid?: string;
11
11
  pxhd?: string;
12
12
  details: ActivityDetails;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createBlockActivityDetails = exports.createPageRequestedActivityDetails = exports.createGenericActivityDetails = exports.createActivityDetails = exports.createActivity = void 0;
4
4
  var utils_1 = require("../utils");
5
5
  var ActivityType_1 = require("./ActivityType");
6
+ var http_1 = require("../http");
6
7
  var createActivity = function (activityType, config, context) {
7
8
  return {
8
9
  type: activityType,
9
10
  px_app_id: config.appId,
10
11
  url: context.requestData.url.href,
11
- headers: (0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders),
12
+ headers: (0, http_1.joinHeaderValues)((0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders)),
12
13
  pxhd: context.pxhd,
13
14
  socket_ip: context.requestData.ip,
14
15
  timestamp: Date.now(),
@@ -1,3 +1,4 @@
1
1
  export declare type ReadOnlyHeaders = Readonly<Record<string, string[]>>;
2
2
  export declare const toReadOnlyHeaders: (headers: Headers) => ReadOnlyHeaders;
3
3
  export declare const fromReadOnlyHeaders: (headers?: ReadOnlyHeaders) => Headers;
4
+ export declare const joinHeaderValues: (headers: ReadOnlyHeaders) => Record<string, string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromReadOnlyHeaders = exports.toReadOnlyHeaders = void 0;
3
+ exports.joinHeaderValues = exports.fromReadOnlyHeaders = exports.toReadOnlyHeaders = void 0;
4
4
  var toReadOnlyHeaders = function (headers) {
5
5
  var readonlyHeaders = {};
6
6
  headers.forEach(function (headerValue, headerName) {
@@ -23,3 +23,10 @@ var fromReadOnlyHeaders = function (headers) {
23
23
  return new Headers(init);
24
24
  };
25
25
  exports.fromReadOnlyHeaders = fromReadOnlyHeaders;
26
+ var joinHeaderValues = function (headers) {
27
+ return Object.fromEntries(Object.entries(headers).map(function (_a) {
28
+ var name = _a[0], values = _a[1];
29
+ return [name, values.join(', ')];
30
+ }));
31
+ };
32
+ exports.joinHeaderValues = joinHeaderValues;
@@ -1,6 +1,7 @@
1
1
  export * from './ReadOnlyHeaders';
2
2
  export * from './IHttpClient';
3
3
  export * from './IIncomingResponse';
4
+ export * from './IIncomingRequest';
4
5
  export * from './IMinimalResponse';
5
6
  export * from './IOutgoingRequest';
6
7
  export * from './IOutgoingResponse';
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./ReadOnlyHeaders"), exports);
18
18
  __exportStar(require("./IHttpClient"), exports);
19
19
  __exportStar(require("./IIncomingResponse"), exports);
20
+ __exportStar(require("./IIncomingRequest"), exports);
20
21
  __exportStar(require("./IMinimalResponse"), exports);
21
22
  __exportStar(require("./IOutgoingRequest"), exports);
22
23
  __exportStar(require("./IOutgoingResponse"), exports);
@@ -7,4 +7,4 @@ export declare const BYPASS_MONITOR_HEADER_VALUE = "1";
7
7
  export declare const X_PX_AUTHORIZATION_HEADER_NAME = "x-px-authorization";
8
8
  export declare const X_PX_ORIGINAL_TOKEN_HEADER_NAME = "x-px-original-token";
9
9
  export declare const X_PX_BYPASS_REASON_HEADER_NAME = "x-px-bypass-reason";
10
- export declare const CORE_MODULE_VERSION = "JS Core 0.4.0";
10
+ export declare const CORE_MODULE_VERSION = "JS Core 0.4.2";
@@ -10,4 +10,4 @@ exports.BYPASS_MONITOR_HEADER_VALUE = '1';
10
10
  exports.X_PX_AUTHORIZATION_HEADER_NAME = 'x-px-authorization';
11
11
  exports.X_PX_ORIGINAL_TOKEN_HEADER_NAME = 'x-px-original-token';
12
12
  exports.X_PX_BYPASS_REASON_HEADER_NAME = 'x-px-bypass-reason';
13
- exports.CORE_MODULE_VERSION = 'JS Core 0.4.0';
13
+ exports.CORE_MODULE_VERSION = 'JS Core 0.4.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perimeterx-js-core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",