perimeterx-js-core 0.33.0 → 0.34.1

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.
@@ -54,7 +54,7 @@ var DefaultContext = /** @class */ (function () {
54
54
  if (!this.isMobile) {
55
55
  this.setCookiesOnContext();
56
56
  }
57
- this.shouldSendTelemetry = false;
57
+ this.telemetryUpdateReason = undefined;
58
58
  }
59
59
  Object.defineProperty(DefaultContext.prototype, "shouldSendLogs", {
60
60
  get: function () {
@@ -189,7 +189,7 @@ var DefaultContext = /** @class */ (function () {
189
189
  enforcerStartTime: this.enforcerStartTime,
190
190
  blockAction: this.blockAction,
191
191
  pxdeVerified: this.pxdeVerified,
192
- shouldSendTelemetry: this.shouldSendTelemetry,
192
+ telemetryUpdateReason: this.telemetryUpdateReason,
193
193
  logger: this.shouldSendLogs
194
194
  ? {
195
195
  logs: this.logger.getLogs(),
@@ -48,7 +48,7 @@ var SerializedContext = /** @class */ (function () {
48
48
  this.graphqlData = contextJson.graphqlData;
49
49
  this.enforcerStartTime = contextJson.enforcerStartTime;
50
50
  this.blockAction = contextJson.blockAction;
51
- this.shouldSendTelemetry = contextJson.shouldSendTelemetry;
51
+ this.telemetryUpdateReason = contextJson.telemetryUpdateReason;
52
52
  }
53
53
  SerializedContext.prototype.createRequestData = function (_a, request, urlUtils) {
54
54
  var requestData = _a.requestData;
@@ -53,7 +53,7 @@ var IdentifyTelemetryRequestPhase = /** @class */ (function () {
53
53
  case 0: return [4 /*yield*/, this.telemetry.isValidTelemetryRequest(context)];
54
54
  case 1:
55
55
  if (_a.sent()) {
56
- context.shouldSendTelemetry = true;
56
+ context.telemetryUpdateReason = 'command';
57
57
  return [2 /*return*/, { done: true }];
58
58
  }
59
59
  return [2 /*return*/, { done: false }];
@@ -139,7 +139,7 @@ var RiskApiPhase = /** @class */ (function (_super) {
139
139
  context.uuid = riskResponse.uuid;
140
140
  }
141
141
  if (riskResponse.telemetryRequested) {
142
- context.shouldSendTelemetry = true;
142
+ context.telemetryUpdateReason = 'risk';
143
143
  }
144
144
  if (riskResponse.dataEnrichment) {
145
145
  context.pxde = riskResponse.dataEnrichment;
@@ -51,7 +51,7 @@ var SendTelemetryActivityPhase = /** @class */ (function () {
51
51
  return __generator(this, function (_a) {
52
52
  switch (_a.label) {
53
53
  case 0:
54
- if (!context.shouldSendTelemetry) return [3 /*break*/, 2];
54
+ if (!context.telemetryUpdateReason) return [3 /*break*/, 2];
55
55
  promise = this.telemetry.sendTelemetry(context);
56
56
  if (!this.config.awaitAsyncHttpRequests) return [3 /*break*/, 2];
57
57
  return [4 /*yield*/, promise];
@@ -156,6 +156,9 @@ var DefaultTelemetry = /** @class */ (function () {
156
156
  enforcer_configs: telemetryConfig,
157
157
  },
158
158
  };
159
+ if (context.requestId) {
160
+ activity.details.request_id = context.requestId;
161
+ }
159
162
  if (context.serverData.osName) {
160
163
  activity.details.os_name = context.serverData.osName;
161
164
  }
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.DefaultTelemetry = void 0;
18
18
  var DefaultTelemetry_1 = require("./DefaultTelemetry.js");
19
19
  Object.defineProperty(exports, "DefaultTelemetry", { enumerable: true, get: function () { return DefaultTelemetry_1.DefaultTelemetry; } });
20
+ __exportStar(require("./model/TelemetryActivity.js"), exports);
20
21
  __exportStar(require("./constants.js"), exports);
@@ -15,4 +15,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
15
15
  exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
16
16
  exports.URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
17
17
  exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
18
- exports.CORE_MODULE_VERSION = 'JS Core 0.33.0';
18
+ exports.CORE_MODULE_VERSION = 'JS Core 0.34.1';
@@ -36,7 +36,7 @@ export class DefaultContext {
36
36
  enforcerStartTime;
37
37
  logger;
38
38
  usedCookieSecret;
39
- shouldSendTelemetry;
39
+ telemetryUpdateReason;
40
40
  _shouldSendLogs = false;
41
41
  config;
42
42
  urlUtils;
@@ -68,7 +68,7 @@ export class DefaultContext {
68
68
  if (!this.isMobile) {
69
69
  this.setCookiesOnContext();
70
70
  }
71
- this.shouldSendTelemetry = false;
71
+ this.telemetryUpdateReason = undefined;
72
72
  }
73
73
  get shouldSendLogs() {
74
74
  return this._shouldSendLogs;
@@ -195,7 +195,7 @@ export class DefaultContext {
195
195
  enforcerStartTime: this.enforcerStartTime,
196
196
  blockAction: this.blockAction,
197
197
  pxdeVerified: this.pxdeVerified,
198
- shouldSendTelemetry: this.shouldSendTelemetry,
198
+ telemetryUpdateReason: this.telemetryUpdateReason,
199
199
  logger: this.shouldSendLogs
200
200
  ? {
201
201
  logs: this.logger.getLogs(),
@@ -32,7 +32,7 @@ export class SerializedContext {
32
32
  vidSource;
33
33
  tokenOrigin;
34
34
  uuid;
35
- shouldSendTelemetry;
35
+ telemetryUpdateReason;
36
36
  constructor(config, contextJson, request, urlUtils) {
37
37
  this.action = contextJson.action;
38
38
  this.reasons = contextJson.reasons;
@@ -59,7 +59,7 @@ export class SerializedContext {
59
59
  this.graphqlData = contextJson.graphqlData;
60
60
  this.enforcerStartTime = contextJson.enforcerStartTime;
61
61
  this.blockAction = contextJson.blockAction;
62
- this.shouldSendTelemetry = contextJson.shouldSendTelemetry;
62
+ this.telemetryUpdateReason = contextJson.telemetryUpdateReason;
63
63
  }
64
64
  createRequestData({ requestData }, request, urlUtils) {
65
65
  return {
@@ -10,7 +10,7 @@ export class IdentifyTelemetryRequestPhase {
10
10
  }
11
11
  async execute(context) {
12
12
  if (await this.telemetry.isValidTelemetryRequest(context)) {
13
- context.shouldSendTelemetry = true;
13
+ context.telemetryUpdateReason = 'command';
14
14
  return { done: true };
15
15
  }
16
16
  return { done: false };
@@ -51,7 +51,7 @@ export class RiskApiPhase extends DecideActionPhase {
51
51
  context.uuid = riskResponse.uuid;
52
52
  }
53
53
  if (riskResponse.telemetryRequested) {
54
- context.shouldSendTelemetry = true;
54
+ context.telemetryUpdateReason = 'risk';
55
55
  }
56
56
  if (riskResponse.dataEnrichment) {
57
57
  context.pxde = riskResponse.dataEnrichment;
@@ -9,7 +9,7 @@ export class SendTelemetryActivityPhase {
9
9
  this.telemetry = telemetry;
10
10
  }
11
11
  async execute(context) {
12
- if (context.shouldSendTelemetry) {
12
+ if (context.telemetryUpdateReason) {
13
13
  // ensure error handling is done in the sendTelemetry method
14
14
  const promise = this.telemetry.sendTelemetry(context);
15
15
  if (this.config.awaitAsyncHttpRequests) {
@@ -78,6 +78,9 @@ export class DefaultTelemetry {
78
78
  enforcer_configs: telemetryConfig,
79
79
  },
80
80
  };
81
+ if (context.requestId) {
82
+ activity.details.request_id = context.requestId;
83
+ }
81
84
  if (context.serverData.osName) {
82
85
  activity.details.os_name = context.serverData.osName;
83
86
  }
@@ -1,2 +1,3 @@
1
1
  export { DefaultTelemetry } from './DefaultTelemetry.js';
2
+ export * from './model/TelemetryActivity.js';
2
3
  export * from './constants.js';
@@ -12,4 +12,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
12
12
  export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
13
13
  export const URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
14
14
  export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
15
- export const CORE_MODULE_VERSION = 'JS Core 0.33.0';
15
+ export const CORE_MODULE_VERSION = 'JS Core 0.34.1';
@@ -1,5 +1,5 @@
1
1
  import { IConfiguration } from './IConfiguration';
2
- import { RemoteConfigurationParams, StaticConfigurationParams, AllConfigurationParams, RequiredAllConfigurationParams, ActiveConfigurationParams, CoreConfigurationParams } from './params';
2
+ import { RemoteConfigurationParams, StaticConfigurationParams, AllConfigurationParams, RequiredAllConfigurationParams, ActiveConfigurationParams, CoreConfigurationParams, CoreConfigurationParamsKeys } from './params';
3
3
  import { CustomParametersFunction, ResponseCustomParametersFunction } from '../custom_parameters';
4
4
  import { AdditionalActivityHandler } from '../additional_activity_handler';
5
5
  import { ILogger, LoggerSeverity } from '../logger';
@@ -11,6 +11,11 @@ import { ExtractGraphQLKeywordsFunction } from '../graphql';
11
11
  import { RemoteConfigData } from './remote_config';
12
12
  import { TokenVersion } from '../risk_token';
13
13
  import { CustomSnippetFunction } from '../snippet_injection';
14
+ type EmptyObjectStrict = Record<PropertyKey, never>;
15
+ type Unsupported<Supported extends string> = Exclude<CoreConfigurationParamsKeys, Supported>;
16
+ type RemovedParams<Supported extends string> = Unsupported<Supported> extends never ? EmptyObjectStrict : {
17
+ [K in Unsupported<Supported>]: undefined;
18
+ };
14
19
  /**
15
20
  * Base class for the enforcer configuration.
16
21
  */
@@ -19,7 +24,7 @@ export declare abstract class ConfigurationBase<Req, Res, Supported extends stri
19
24
  protected readonly staticConfigParams: StaticConfigurationParams<Req, Res, Supported, Added>;
20
25
  protected remoteConfigData?: RemoteConfigData<Req, Res, Supported, Added>;
21
26
  protected readonly defaultConfigParams: RequiredAllConfigurationParams<Req, Res, Supported, Added>;
22
- protected readonly removedParams: Record<Exclude<keyof CoreConfigurationParams<Req, Res, Supported, Added>, Supported>, undefined>;
27
+ protected readonly removedParams: RemovedParams<Supported>;
23
28
  private internalLogger;
24
29
  /**
25
30
  * Returns the module version of the enforcer.
@@ -40,7 +45,7 @@ export declare abstract class ConfigurationBase<Req, Res, Supported extends stri
40
45
  * @param removedParams - A map of all removed (unsupported) configuration parameters set to undefined. This parameter can be generated automatically by your IDE.
41
46
  * @protected
42
47
  */
43
- protected constructor(params: StaticConfigurationParams<Req, Res, Supported, Added>, defaultParams: Required<Added> & Partial<CoreConfigurationParams<Req, Res, Supported, Added>>, removedParams: Record<Exclude<keyof CoreConfigurationParams<Req, Res, Supported, Added>, Supported>, undefined>);
48
+ protected constructor(params: StaticConfigurationParams<Req, Res, Supported, Added>, defaultParams: Required<Added> & Partial<CoreConfigurationParams<Req, Res, Supported, Added>>, removedParams: RemovedParams<Supported>);
44
49
  protected createActiveConfiguration(params: AllConfigurationParams<Req, Res, Supported, Added>, defaultParams: RequiredAllConfigurationParams<Req, Res, Supported, Added>): RequiredAllConfigurationParams<Req, Res, Supported, Added>;
45
50
  protected throwIfMissingRequiredField(params: AllConfigurationParams<Req, Res, Supported, Added>): void;
46
51
  protected getValidConfigValue<K extends keyof RequiredAllConfigurationParams<Req, Res, Supported, Added>, V extends RequiredAllConfigurationParams<Req, Res, Supported, Added>[K]>(params: AllConfigurationParams<Req, Res, Supported, Added>, defaultParams: RequiredAllConfigurationParams<Req, Res, Supported, Added>, key: K): V;
@@ -148,3 +153,4 @@ export declare abstract class ConfigurationBase<Req, Res, Supported extends stri
148
153
  get awaitAsyncHttpRequests(): boolean;
149
154
  get isPostEnforceEnabled(): boolean;
150
155
  }
156
+ export {};
@@ -9,6 +9,7 @@ import { CustomParameters } from '../custom_parameters';
9
9
  import { GraphQLData } from '../graphql';
10
10
  import { RemoteConfigUpdateData, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
11
11
  import { LogRecord } from '../logger';
12
+ import { TelemetryUpdateReason } from '../telemetry';
12
13
  type RequestDataJson<Req> = Omit<RequestData<Req>, 'url' | 'request'> & {
13
14
  url: string;
14
15
  request: undefined;
@@ -45,6 +46,6 @@ export type ContextJson<Req = unknown, Res = unknown> = {
45
46
  logger?: {
46
47
  logs: LogRecord[];
47
48
  };
48
- shouldSendTelemetry: boolean;
49
+ telemetryUpdateReason?: TelemetryUpdateReason;
49
50
  };
50
51
  export {};
@@ -12,6 +12,7 @@ import { ILogger } from '../logger';
12
12
  import { IContext, RemoteConfigUpdateData, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
13
13
  import { ContextJson } from './ContextJson';
14
14
  import { GraphQLData } from '../graphql';
15
+ import { TelemetryUpdateReason } from '../telemetry';
15
16
  export type DefaultContextOptions = {
16
17
  cookieParser?: ICookieParser;
17
18
  requestIdGenerator: IRequestIdGenerator;
@@ -47,7 +48,7 @@ export declare class DefaultContext<Req, Res, Supported extends string, Added> i
47
48
  enforcerStartTime?: number;
48
49
  logger: ILogger;
49
50
  usedCookieSecret?: string;
50
- shouldSendTelemetry: boolean;
51
+ telemetryUpdateReason?: TelemetryUpdateReason;
51
52
  protected _shouldSendLogs: boolean;
52
53
  protected readonly config: IConfiguration<Req, Res, Supported, Added>;
53
54
  protected readonly urlUtils: IUrlUtils;
@@ -12,6 +12,7 @@ import { CustomParameters } from '../custom_parameters';
12
12
  import { GraphQLData } from '../graphql';
13
13
  import { IContext, RemoteConfigUpdateData, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
14
14
  import { ContextJson } from './ContextJson';
15
+ import { TelemetryUpdateReason } from '../telemetry';
15
16
  /**
16
17
  * Implements the `IContext` interface based an already serialized `ContextJson`. This class does not extract data from the
17
18
  * incoming request, but rather uses already-extracted data from the `ContextJson` (likely returned from the `DefaultContext.toJSON()`
@@ -43,7 +44,7 @@ export declare class SerializedContext<Req, Res, Supported extends string, Added
43
44
  vidSource?: VidSource;
44
45
  tokenOrigin: TokenOrigin;
45
46
  uuid?: string;
46
- shouldSendTelemetry: boolean;
47
+ telemetryUpdateReason?: TelemetryUpdateReason;
47
48
  constructor(config: IConfiguration<Req, Res, Supported, Added>, contextJson: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils);
48
49
  protected createRequestData({ requestData }: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils): RequestData<Req>;
49
50
  protected createTokenData({ tokenData }: ContextJson<Req, Res>, config: IConfiguration<Req, Res, Supported, Added>): TokenData<Req, Res>;
@@ -15,6 +15,7 @@ import { GraphQLData } from '../../graphql';
15
15
  import { PXHD } from '../../pxhd';
16
16
  import { ILogger } from '../../logger';
17
17
  import { RemoteConfigUpdateData } from './RemoteConfigUpdateData';
18
+ import { TelemetryUpdateReason } from '../../telemetry';
18
19
  export interface IContext<Req, Res> {
19
20
  /**
20
21
  * Logger for recording messages related to the request flow.
@@ -138,7 +139,7 @@ export interface IContext<Req, Res> {
138
139
  */
139
140
  readonly enforcerStartTime?: number;
140
141
  /**
141
- * Whether to send telemetry activity for the current request.
142
+ * The reason why a telemetry activity should be sent (undefined if no telemetry activity is triggered)
142
143
  */
143
- shouldSendTelemetry: boolean;
144
+ telemetryUpdateReason?: TelemetryUpdateReason;
144
145
  }
@@ -1,4 +1,4 @@
1
1
  export { ITelemetry } from './ITelemetry';
2
2
  export { DefaultTelemetry } from './DefaultTelemetry';
3
- export { TelemetryActivity } from './model/TelemetryActivity';
3
+ export * from './model/TelemetryActivity';
4
4
  export * from './constants';
@@ -1,13 +1,15 @@
1
1
  import { ActivityType } from '../../activities';
2
2
  import { RemoteConfigurationParams, StaticConfigurationParams, ActiveConfigurationParams, CoreConfigurationParamsKeys } from '../../config';
3
+ export type TelemetryUpdateReason = 'command' | 'risk';
3
4
  export type TelemetryActivityDetails<Req, Res, Supported extends CoreConfigurationParamsKeys, Added> = {
4
5
  enforcer_configs: TelemetryEnforcerConfiguration<Req, Res, Supported, Added>;
5
6
  module_version: string;
6
- update_reason: 'command';
7
+ update_reason: TelemetryUpdateReason;
7
8
  node_name?: string;
8
9
  os_name?: string;
9
10
  remote_config_id?: string;
10
11
  remote_config_version?: number;
12
+ request_id?: string;
11
13
  };
12
14
  export type TelemetryActivity<Req, Res, Supported extends CoreConfigurationParamsKeys, Added> = {
13
15
  type: ActivityType.ENFORCER_TELEMETRY;
@@ -12,4 +12,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
12
12
  export declare const EMAIL_ADDRESS_REGEX: RegExp;
13
13
  export declare const URL_REGEX: RegExp;
14
14
  export declare const REGEX_STRUCTURE: RegExp;
15
- export declare const CORE_MODULE_VERSION = "JS Core 0.33.0";
15
+ export declare const CORE_MODULE_VERSION = "JS Core 0.34.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perimeterx-js-core",
3
- "version": "0.33.0",
3
+ "version": "0.34.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "typesVersions": {
@@ -61,7 +61,7 @@
61
61
  "@typescript-eslint/eslint-plugin": "^8.38.0",
62
62
  "@typescript-eslint/parser": "^8.26.0",
63
63
  "c8": "^10.1.3",
64
- "chai": "^5.2.0",
64
+ "chai": "^6.2.0",
65
65
  "chai-as-promised": "^8.0.0",
66
66
  "core-js": "^3.19.1",
67
67
  "eslint": "^9.21.0",