perimeterx-js-core 0.23.0 → 0.23.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.
@@ -165,6 +165,11 @@ var DefaultContext = /** @class */ (function () {
165
165
  enforcerStartTime: this.enforcerStartTime,
166
166
  blockAction: this.blockAction,
167
167
  pxdeVerified: this.pxdeVerified,
168
+ logger: this.shouldSendLogs
169
+ ? {
170
+ logs: this.logger.getLogs(),
171
+ }
172
+ : undefined,
168
173
  };
169
174
  };
170
175
  return DefaultContext;
@@ -17,12 +17,13 @@ var risk_token_1 = require("../risk_token");
17
17
  var risk_api_1 = require("../risk_api");
18
18
  var SerializedContext = /** @class */ (function () {
19
19
  function SerializedContext(config, contextJson, request, urlUtils) {
20
+ var _a;
20
21
  this.action = contextJson.action;
21
22
  this.reasons = contextJson.reasons;
22
23
  this.isMobile = contextJson.isMobile;
23
24
  this.requestId = contextJson.requestId;
24
25
  this.isRemoteConfigUpdateRequest = contextJson.isRemoteConfigUpdateRequest;
25
- this.logger = this.createLogger(config, contextJson.shouldSendLogs);
26
+ this.logger = this.createLogger(config, contextJson.shouldSendLogs, (_a = contextJson.logger) === null || _a === void 0 ? void 0 : _a.logs);
26
27
  this.productData = contextJson.productData;
27
28
  this.requestData = this.createRequestData(contextJson, request, urlUtils);
28
29
  this.riskApiData = this.createRiskApiData(contextJson);
@@ -58,8 +59,8 @@ var SerializedContext = /** @class */ (function () {
58
59
  var riskApiData = _a.riskApiData;
59
60
  return __assign(__assign({}, riskApiData), { riskResponse: riskApiData.riskResponse ? new risk_api_1.SerializedRiskResponse(riskApiData.riskResponse) : undefined });
60
61
  };
61
- SerializedContext.prototype.createLogger = function (config, shouldSendLogs) {
62
- return new logger_1.DefaultLogger(config.loggerSeverity, shouldSendLogs);
62
+ SerializedContext.prototype.createLogger = function (config, shouldSendLogs, logs) {
63
+ return new logger_1.DefaultLogger(config.loggerSeverity, shouldSendLogs, logs);
63
64
  };
64
65
  return SerializedContext;
65
66
  }());
@@ -19,8 +19,8 @@ exports.DefaultLogger = void 0;
19
19
  var LoggerBase_1 = require("./LoggerBase");
20
20
  var DefaultLogger = /** @class */ (function (_super) {
21
21
  __extends(DefaultLogger, _super);
22
- function DefaultLogger(loggerSeverity, shouldSaveLogs) {
23
- return _super.call(this, loggerSeverity, shouldSaveLogs) || this;
22
+ function DefaultLogger(loggerSeverity, shouldSaveLogs, logs) {
23
+ return _super.call(this, loggerSeverity, shouldSaveLogs, logs) || this;
24
24
  }
25
25
  DefaultLogger.prototype.log = function (message) {
26
26
  /* eslint-disable no-console */
@@ -14,4 +14,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
14
14
  exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
15
15
  exports.URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
16
16
  exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
17
- exports.CORE_MODULE_VERSION = 'JS Core 0.23.0';
17
+ exports.CORE_MODULE_VERSION = 'JS Core 0.23.2';
@@ -22,7 +22,14 @@ var EnforcerConfigurationError = /** @class */ (function (_super) {
22
22
  __extends(EnforcerConfigurationError, _super);
23
23
  function EnforcerConfigurationError(configName, invalidConfigValue, possibleValues) {
24
24
  var _this = this;
25
- var message = "configuration ".concat(configName, " cannot be type ").concat(typeof invalidConfigValue, " with value ").concat(invalidConfigValue);
25
+ var value = invalidConfigValue === null
26
+ ? 'null'
27
+ : invalidConfigValue === undefined
28
+ ? 'undefined'
29
+ : typeof invalidConfigValue === 'string'
30
+ ? "\"".concat(invalidConfigValue, "\"")
31
+ : invalidConfigValue;
32
+ var message = "configuration ".concat(configName, " cannot be type ").concat(typeof invalidConfigValue, " with value ").concat(value);
26
33
  if (possibleValues) {
27
34
  message += ", possible values: ".concat(possibleValues.join(', '));
28
35
  }
@@ -175,6 +175,11 @@ export class DefaultContext {
175
175
  enforcerStartTime: this.enforcerStartTime,
176
176
  blockAction: this.blockAction,
177
177
  pxdeVerified: this.pxdeVerified,
178
+ logger: this.shouldSendLogs
179
+ ? {
180
+ logs: this.logger.getLogs(),
181
+ }
182
+ : undefined,
178
183
  };
179
184
  }
180
185
  }
@@ -33,7 +33,7 @@ export class SerializedContext {
33
33
  this.isMobile = contextJson.isMobile;
34
34
  this.requestId = contextJson.requestId;
35
35
  this.isRemoteConfigUpdateRequest = contextJson.isRemoteConfigUpdateRequest;
36
- this.logger = this.createLogger(config, contextJson.shouldSendLogs);
36
+ this.logger = this.createLogger(config, contextJson.shouldSendLogs, contextJson.logger?.logs);
37
37
  this.productData = contextJson.productData;
38
38
  this.requestData = this.createRequestData(contextJson, request, urlUtils);
39
39
  this.riskApiData = this.createRiskApiData(contextJson);
@@ -81,7 +81,7 @@ export class SerializedContext {
81
81
  riskResponse: riskApiData.riskResponse ? new SerializedRiskResponse(riskApiData.riskResponse) : undefined,
82
82
  };
83
83
  }
84
- createLogger(config, shouldSendLogs) {
85
- return new DefaultLogger(config.loggerSeverity, shouldSendLogs);
84
+ createLogger(config, shouldSendLogs, logs) {
85
+ return new DefaultLogger(config.loggerSeverity, shouldSendLogs, logs);
86
86
  }
87
87
  }
@@ -1,7 +1,7 @@
1
1
  import { LoggerBase } from './LoggerBase';
2
2
  export class DefaultLogger extends LoggerBase {
3
- constructor(loggerSeverity, shouldSaveLogs) {
4
- super(loggerSeverity, shouldSaveLogs);
3
+ constructor(loggerSeverity, shouldSaveLogs, logs) {
4
+ super(loggerSeverity, shouldSaveLogs, logs);
5
5
  }
6
6
  log(message) {
7
7
  /* eslint-disable no-console */
@@ -11,4 +11,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
11
11
  export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
12
12
  export const URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
13
13
  export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
14
- export const CORE_MODULE_VERSION = 'JS Core 0.23.0';
14
+ export const CORE_MODULE_VERSION = 'JS Core 0.23.2';
@@ -2,7 +2,14 @@ import { EnforcerError } from './EnforcerError';
2
2
  import { EnforcerErrorName } from './EnforcerErrorName';
3
3
  export class EnforcerConfigurationError extends EnforcerError {
4
4
  constructor(configName, invalidConfigValue, possibleValues) {
5
- let message = `configuration ${configName} cannot be type ${typeof invalidConfigValue} with value ${invalidConfigValue}`;
5
+ const value = invalidConfigValue === null
6
+ ? 'null'
7
+ : invalidConfigValue === undefined
8
+ ? 'undefined'
9
+ : typeof invalidConfigValue === 'string'
10
+ ? `"${invalidConfigValue}"`
11
+ : invalidConfigValue;
12
+ let message = `configuration ${configName} cannot be type ${typeof invalidConfigValue} with value ${value}`;
6
13
  if (possibleValues) {
7
14
  message += `, possible values: ${possibleValues.join(', ')}`;
8
15
  }
@@ -1,5 +1,5 @@
1
1
  import { IConfiguration } from './IConfiguration';
2
- import { RemoteConfigurationParams, StaticConfigurationParams, AllConfigurationParams, RequiredAllConfigurationParams, ActiveConfigurationParams } from './params';
2
+ import { RemoteConfigurationParams, StaticConfigurationParams, AllConfigurationParams, RequiredAllConfigurationParams, ActiveConfigurationParams, CoreConfigurationParams } from './params';
3
3
  import { CustomParametersFunction } from '../custom_parameters';
4
4
  import { AdditionalActivityHandler } from '../additional_activity_handler';
5
5
  import { ILogger, LoggerSeverity } from '../logger';
@@ -17,7 +17,7 @@ export declare abstract class ConfigurationBase<Req, Res, Added, Removed extends
17
17
  protected readonly removedParams: Record<Removed, undefined>;
18
18
  private internalLogger;
19
19
  protected abstract getModuleVersion(): string;
20
- protected constructor(params: StaticConfigurationParams<Req, Res, Added, Removed>, defaultParams: Required<Added>, removedParams: Record<Removed, undefined>);
20
+ protected constructor(params: StaticConfigurationParams<Req, Res, Added, Removed>, defaultParams: Required<Added> & Partial<CoreConfigurationParams<Req, Res, Added, Removed>>, removedParams: Record<Removed, undefined>);
21
21
  protected createActiveConfiguration(params: AllConfigurationParams<Req, Res, Added, Removed>, defaultParams: RequiredAllConfigurationParams<Req, Res, Added, Removed>): RequiredAllConfigurationParams<Req, Res, Added, Removed>;
22
22
  protected throwIfMissingRequiredField(params: AllConfigurationParams<Req, Res, Added, Removed>): void;
23
23
  protected getValidConfigValue<K extends keyof RequiredAllConfigurationParams<Req, Res, Added, Removed>, V extends RequiredAllConfigurationParams<Req, Res, Added, Removed>[K]>(params: AllConfigurationParams<Req, Res, Added, Removed>, defaultParams: RequiredAllConfigurationParams<Req, Res, Added, Removed>, key: K): V;
@@ -8,6 +8,7 @@ import { PXDE } from '../pxde';
8
8
  import { CustomParameters } from '../custom_parameters';
9
9
  import { GraphQLData } from '../graphql';
10
10
  import { RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
11
+ import { LogRecord } from '../logger';
11
12
  type RequestDataJson<Req> = Omit<RequestData<Req>, 'url' | 'request'> & {
12
13
  url: string;
13
14
  request: undefined;
@@ -37,5 +38,8 @@ export type ContextJson<Req = unknown, Res = unknown> = {
37
38
  readonly shouldSendLogs: boolean;
38
39
  readonly isRemoteConfigUpdateRequest: boolean;
39
40
  readonly enforcerStartTime?: number;
41
+ logger?: {
42
+ logs: LogRecord[];
43
+ };
40
44
  };
41
45
  export {};
@@ -1,6 +1,6 @@
1
1
  import { IConfiguration } from '../config';
2
2
  import { Action } from '../action';
3
- import { ILogger } from '../logger';
3
+ import { ILogger, LogRecord } from '../logger';
4
4
  import { ProductData, ProductName } from '../products';
5
5
  import { TokenOrigin } from '../risk_token';
6
6
  import { IIncomingRequest } from '../http';
@@ -42,5 +42,5 @@ export declare class SerializedContext<Req, Res, Added, Removed> implements ICon
42
42
  protected createRequestData({ requestData }: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils): RequestData<Req>;
43
43
  protected createTokenData({ tokenData }: ContextJson<Req, Res>, config: IConfiguration<Req, Res, Added, Removed>): TokenData<Req, Res>;
44
44
  protected createRiskApiData({ riskApiData }: ContextJson<Req, Res>): RiskApiData;
45
- protected createLogger(config: IConfiguration<Req, Res, Added, Removed>, shouldSendLogs: boolean): ILogger;
45
+ protected createLogger(config: IConfiguration<Req, Res, Added, Removed>, shouldSendLogs: boolean, logs?: LogRecord[]): ILogger;
46
46
  }
@@ -1,7 +1,8 @@
1
1
  import { LoggerSeverity } from './LoggerSeverity';
2
2
  import { LoggerBase } from './LoggerBase';
3
3
  import { ILogger } from './ILogger';
4
+ import { LogRecord } from './model';
4
5
  export declare class DefaultLogger extends LoggerBase implements ILogger {
5
- constructor(loggerSeverity: `${LoggerSeverity}`, shouldSaveLogs: boolean);
6
+ constructor(loggerSeverity: `${LoggerSeverity}`, shouldSaveLogs: boolean, logs?: LogRecord[]);
6
7
  protected log(message: string): void;
7
8
  }
@@ -11,4 +11,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
11
11
  export declare const EMAIL_ADDRESS_REGEX: RegExp;
12
12
  export declare const URL_REGEX: RegExp;
13
13
  export declare const REGEX_STRUCTURE: RegExp;
14
- export declare const CORE_MODULE_VERSION = "JS Core 0.23.0";
14
+ export declare const CORE_MODULE_VERSION = "JS Core 0.23.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perimeterx-js-core",
3
- "version": "0.23.0",
3
+ "version": "0.23.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "typesVersions": {