perimeterx-js-core 0.15.2 → 0.16.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 (113) hide show
  1. package/lib/cjs/activities/HttpActivityClient.js +4 -4
  2. package/lib/cjs/activities/HttpBatchedActivityClient.js +7 -7
  3. package/lib/cjs/additional_activity_handler/AdditionalActivityHandlerUtils.js +2 -2
  4. package/lib/cjs/config/ConfigurationBase.js +4 -1
  5. package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +25 -30
  6. package/lib/cjs/config/remote_config/RemoteConfigUtils.js +14 -0
  7. package/lib/cjs/config/remote_config/index.js +1 -0
  8. package/lib/cjs/context/DefaultContext.js +18 -7
  9. package/lib/cjs/custom_parameters/CustomParametersUtils.js +1 -1
  10. package/lib/cjs/enforcer/EnforcerBase.js +40 -31
  11. package/lib/cjs/graphql/DefaultGraphQLParser.js +20 -22
  12. package/lib/cjs/impl/url/DefaultUrlUtils.js +7 -1
  13. package/lib/cjs/logger/DefaultLogger.js +2 -2
  14. package/lib/cjs/logger/HttpLogServiceClient.js +32 -27
  15. package/lib/cjs/logger/LoggerBase.js +5 -1
  16. package/lib/cjs/monitored_request/MonitoredRequestUtils.js +8 -8
  17. package/lib/cjs/phase/impl/CreateBlockResponsePhase.js +2 -2
  18. package/lib/cjs/phase/impl/DecideActionPhase.js +3 -4
  19. package/lib/cjs/phase/impl/EnrichContextFromRequestPhase.js +3 -2
  20. package/lib/cjs/phase/impl/EnrichContextFromResponsePhase.js +1 -1
  21. package/lib/cjs/phase/impl/FirstPartyPhase.js +4 -4
  22. package/lib/cjs/phase/impl/RiskApiPhase.js +1 -1
  23. package/lib/cjs/phase/impl/SendLogsPhase.js +2 -2
  24. package/lib/cjs/phase/impl/UpdateRemoteConfigPhase.js +0 -1
  25. package/lib/cjs/products/account_defender/AccountDefender.js +9 -8
  26. package/lib/cjs/products/bot_defender/filter/DefaultBotDefenderFilter.js +10 -10
  27. package/lib/cjs/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +17 -17
  28. package/lib/cjs/products/credential_intelligence/endpoint/CredentialEndpoint.js +8 -9
  29. package/lib/cjs/products/credential_intelligence/endpoint/CredentialEndpointManager.js +13 -15
  30. package/lib/cjs/pxde/DefaultDataEnrichment.js +11 -11
  31. package/lib/cjs/risk_api/client/PostRiskApiClientBase.js +5 -5
  32. package/lib/cjs/risk_token/parser/TokenParserBase.js +12 -13
  33. package/lib/cjs/risk_token/token/v2/DefaultTokenV2.js +5 -5
  34. package/lib/cjs/risk_token/token/v3/DefaultTokenV3.js +11 -11
  35. package/lib/cjs/sensitive_request/SensitiveRequestUtils.js +4 -4
  36. package/lib/cjs/telemetry/DefaultTelemetry.js +7 -7
  37. package/lib/cjs/utils/constants.js +1 -1
  38. package/lib/cjs/utils/timestamp_hmac_header_validator/DefaultTimestampHmacHeaderValidator.js +7 -7
  39. package/lib/esm/activities/HttpActivityClient.js +4 -4
  40. package/lib/esm/activities/HttpBatchedActivityClient.js +7 -7
  41. package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +2 -2
  42. package/lib/esm/config/ConfigurationBase.js +4 -1
  43. package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +21 -23
  44. package/lib/esm/config/remote_config/RemoteConfigUtils.js +9 -0
  45. package/lib/esm/config/remote_config/index.js +1 -0
  46. package/lib/esm/context/DefaultContext.js +18 -8
  47. package/lib/esm/custom_parameters/CustomParametersUtils.js +1 -1
  48. package/lib/esm/enforcer/EnforcerBase.js +18 -7
  49. package/lib/esm/graphql/DefaultGraphQLParser.js +9 -10
  50. package/lib/esm/impl/url/DefaultUrlUtils.js +7 -1
  51. package/lib/esm/logger/DefaultLogger.js +2 -2
  52. package/lib/esm/logger/HttpLogServiceClient.js +25 -27
  53. package/lib/esm/logger/LoggerBase.js +6 -1
  54. package/lib/esm/monitored_request/MonitoredRequestUtils.js +8 -8
  55. package/lib/esm/phase/impl/CreateBlockResponsePhase.js +2 -2
  56. package/lib/esm/phase/impl/DecideActionPhase.js +2 -6
  57. package/lib/esm/phase/impl/EnrichContextFromRequestPhase.js +4 -2
  58. package/lib/esm/phase/impl/EnrichContextFromResponsePhase.js +1 -1
  59. package/lib/esm/phase/impl/FirstPartyPhase.js +4 -4
  60. package/lib/esm/phase/impl/RiskApiPhase.js +1 -1
  61. package/lib/esm/phase/impl/SendLogsPhase.js +2 -2
  62. package/lib/esm/phase/impl/UpdateRemoteConfigPhase.js +0 -1
  63. package/lib/esm/products/account_defender/AccountDefender.js +9 -8
  64. package/lib/esm/products/bot_defender/filter/DefaultBotDefenderFilter.js +8 -8
  65. package/lib/esm/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +16 -15
  66. package/lib/esm/products/credential_intelligence/endpoint/CredentialEndpoint.js +8 -10
  67. package/lib/esm/products/credential_intelligence/endpoint/CredentialEndpointManager.js +5 -5
  68. package/lib/esm/pxde/DefaultDataEnrichment.js +11 -11
  69. package/lib/esm/risk_api/client/PostRiskApiClientBase.js +5 -5
  70. package/lib/esm/risk_token/parser/TokenParserBase.js +12 -11
  71. package/lib/esm/risk_token/token/v2/DefaultTokenV2.js +5 -5
  72. package/lib/esm/risk_token/token/v3/DefaultTokenV3.js +11 -11
  73. package/lib/esm/sensitive_request/SensitiveRequestUtils.js +4 -4
  74. package/lib/esm/telemetry/DefaultTelemetry.js +7 -7
  75. package/lib/esm/utils/constants.js +1 -1
  76. package/lib/esm/utils/timestamp_hmac_header_validator/DefaultTimestampHmacHeaderValidator.js +7 -7
  77. package/lib/types/activities/HttpActivityClient.d.ts +4 -3
  78. package/lib/types/activities/HttpBatchedActivityClient.d.ts +8 -7
  79. package/lib/types/activities/utils.d.ts +270 -0
  80. package/lib/types/blocker/utils.d.ts +27 -0
  81. package/lib/types/config/ConfigurationBase.d.ts +6 -5
  82. package/lib/types/config/remote_config/DefaultRemoteConfigUpdater.d.ts +5 -5
  83. package/lib/types/config/remote_config/RemoteConfigUtils.d.ts +4 -0
  84. package/lib/types/config/remote_config/index.d.ts +1 -0
  85. package/lib/types/context/DefaultContext.d.ts +7 -2
  86. package/lib/types/context/interfaces/IContext.d.ts +11 -2
  87. package/lib/types/enforcer/EnforcerBase.d.ts +2 -1
  88. package/lib/types/graphql/DefaultGraphQLParser.d.ts +1 -2
  89. package/lib/types/logger/DefaultLogger.d.ts +1 -1
  90. package/lib/types/logger/HttpLogServiceClient.d.ts +5 -10
  91. package/lib/types/logger/ILogServiceClient.d.ts +1 -2
  92. package/lib/types/logger/LoggerBase.d.ts +2 -1
  93. package/lib/types/logger/model/LogMetadata.d.ts +1 -0
  94. package/lib/types/monitored_request/MonitoredRequestUtils.d.ts +1353 -2
  95. package/lib/types/phase/impl/DecideActionPhase.d.ts +0 -3
  96. package/lib/types/phase/impl/EnrichContextFromRequestPhase.d.ts +1 -0
  97. package/lib/types/phase/impl/FirstPartyPhase.d.ts +1 -1
  98. package/lib/types/products/account_defender/AccountDefender.d.ts +4 -5
  99. package/lib/types/products/bot_defender/filter/DefaultBotDefenderFilter.d.ts +2 -3
  100. package/lib/types/products/bot_defender/first_party/DefaultBotDefenderFirstParty.d.ts +3 -4
  101. package/lib/types/products/credential_intelligence/endpoint/CredentialEndpoint.d.ts +3 -5
  102. package/lib/types/products/credential_intelligence/endpoint/CredentialEndpointManager.d.ts +2 -2
  103. package/lib/types/products/credential_intelligence/endpoint/ICredentialEndpoint.d.ts +3 -4
  104. package/lib/types/pxhd/PXHDUtils.d.ts +54 -0
  105. package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +1 -1
  106. package/lib/types/risk_token/parser/TokenParserBase.d.ts +4 -5
  107. package/lib/types/risk_token/token/v3/DefaultTokenV3.d.ts +1 -1
  108. package/lib/types/sensitive_request/SensitiveRequestUtils.d.ts +705 -17
  109. package/lib/types/telemetry/DefaultTelemetry.d.ts +1 -1
  110. package/lib/types/utils/constants.d.ts +1 -1
  111. package/lib/types/utils/timestamp_hmac_header_validator/DefaultTimestampHmacHeaderValidator.d.ts +3 -2
  112. package/lib/types/utils/timestamp_hmac_header_validator/ITimestampHmacHeaderValidator.d.ts +2 -1
  113. package/package.json +1 -1
@@ -56,11 +56,11 @@ var HttpActivityClient = /** @class */ (function () {
56
56
  case 0:
57
57
  _a.trys.push([0, 2, , 3]);
58
58
  activities = this.createActivities(context);
59
- return [4 /*yield*/, this.postActivities(activities)];
59
+ return [4 /*yield*/, this.postActivities(activities, context.logger)];
60
60
  case 1: return [2 /*return*/, _a.sent()];
61
61
  case 2:
62
62
  e_1 = _a.sent();
63
- this.config.logger.error("unable to send activities - ".concat(e_1));
63
+ context.logger.error("unable to send activities - ".concat(e_1));
64
64
  return [2 /*return*/, false];
65
65
  case 3: return [2 /*return*/];
66
66
  }
@@ -89,7 +89,7 @@ var HttpActivityClient = /** @class */ (function () {
89
89
  HttpActivityClient.prototype.finalizeActivity = function (activity) {
90
90
  return activity;
91
91
  };
92
- HttpActivityClient.prototype.postActivities = function (activities) {
92
+ HttpActivityClient.prototype.postActivities = function (activities, logger) {
93
93
  return __awaiter(this, void 0, void 0, function () {
94
94
  var url, method, headers, body, req, res;
95
95
  var _a;
@@ -103,7 +103,7 @@ var HttpActivityClient = /** @class */ (function () {
103
103
  _a[http_1.AUTHORIZATION_HEADER_NAME] = [(0, utils_1.getAuthorizationHeader)(this.config.authToken)],
104
104
  _a);
105
105
  body = activities.length === 1 ? JSON.stringify(activities[0]) : JSON.stringify(activities);
106
- this.config.logger.debug("sending ".concat(activities.map(function (_a) {
106
+ logger.debug("sending ".concat(activities.map(function (_a) {
107
107
  var type = _a.type;
108
108
  return "".concat(type, " activity");
109
109
  }).join(', '), " to ").concat(url));
@@ -69,11 +69,11 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
69
69
  this.shouldKill = true;
70
70
  this.stopTimer();
71
71
  };
72
- HttpBatchedActivityClient.prototype.postActivities = function (activities) {
72
+ HttpBatchedActivityClient.prototype.postActivities = function (activities, logger) {
73
73
  return __awaiter(this, void 0, void 0, function () {
74
74
  return __generator(this, function (_a) {
75
75
  this.addToBuffer(activities);
76
- return [2 /*return*/, this.shouldFlush() ? this.triggerFlush() : true];
76
+ return [2 /*return*/, this.shouldFlush() ? this.triggerFlush(logger) : true];
77
77
  });
78
78
  });
79
79
  };
@@ -86,7 +86,7 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
86
86
  HttpBatchedActivityClient.prototype.shouldFlush = function () {
87
87
  return this.buffer.length >= this.batchSize;
88
88
  };
89
- HttpBatchedActivityClient.prototype.triggerFlush = function () {
89
+ HttpBatchedActivityClient.prototype.triggerFlush = function (logger) {
90
90
  return __awaiter(this, void 0, void 0, function () {
91
91
  var sentSuccessfully, _a;
92
92
  return __generator(this, function (_b) {
@@ -95,7 +95,7 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
95
95
  this.stopTimer();
96
96
  _a = this.buffer.length > 0;
97
97
  if (!_a) return [3 /*break*/, 2];
98
- return [4 /*yield*/, this.flush()];
98
+ return [4 /*yield*/, this.flush(logger)];
99
99
  case 1:
100
100
  _a = (_b.sent());
101
101
  _b.label = 2;
@@ -109,7 +109,7 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
109
109
  });
110
110
  });
111
111
  };
112
- HttpBatchedActivityClient.prototype.flush = function () {
112
+ HttpBatchedActivityClient.prototype.flush = function (logger) {
113
113
  return __awaiter(this, void 0, void 0, function () {
114
114
  var bufferCopy, sentSuccessfully;
115
115
  return __generator(this, function (_a) {
@@ -117,7 +117,7 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
117
117
  case 0:
118
118
  bufferCopy = this.buffer.concat();
119
119
  this.clear();
120
- return [4 /*yield*/, _super.prototype.postActivities.call(this, bufferCopy)];
120
+ return [4 /*yield*/, _super.prototype.postActivities.call(this, bufferCopy, logger)];
121
121
  case 1:
122
122
  sentSuccessfully = _a.sent();
123
123
  if (!sentSuccessfully) {
@@ -133,7 +133,7 @@ var HttpBatchedActivityClient = /** @class */ (function (_super) {
133
133
  };
134
134
  HttpBatchedActivityClient.prototype.startTimer = function () {
135
135
  var _this = this;
136
- this.timeoutId = setTimeout(function () { return _this.triggerFlush(); }, this.timeoutMs);
136
+ this.timeoutId = setTimeout(function () { return _this.triggerFlush(_this.config.logger); }, this.timeoutMs);
137
137
  };
138
138
  HttpBatchedActivityClient.prototype.stopTimer = function () {
139
139
  clearTimeout(this.timeoutId);
@@ -49,14 +49,14 @@ var AdditionalActivityHandlerUtils;
49
49
  _a.label = 1;
50
50
  case 1:
51
51
  _a.trys.push([1, 3, , 4]);
52
- config.logger.debug('calling additional activity handler');
52
+ context.logger.debug('calling additional activity handler');
53
53
  return [4 /*yield*/, config.additionalActivityHandler(config.toParams(), context, context.requestData.request.getUnderlyingRequest())];
54
54
  case 2:
55
55
  _a.sent();
56
56
  return [3 /*break*/, 4];
57
57
  case 3:
58
58
  e_1 = _a.sent();
59
- config.logger.error("caught additional activity handler error - ".concat(e_1));
59
+ context.logger.error("caught additional activity handler error - ".concat(e_1));
60
60
  return [3 /*break*/, 4];
61
61
  case 4: return [2 /*return*/];
62
62
  }
@@ -18,7 +18,7 @@ var utils_1 = require("../utils");
18
18
  var ConfigurationBase = /** @class */ (function () {
19
19
  function ConfigurationBase(params, defaultParams) {
20
20
  this.configParams = this.initialize(params, __assign(__assign({}, defaults_1.DEFAULT_CONFIGURATION_PARAMS), defaultParams));
21
- this.internalLogger = new logger_1.DefaultLogger(this.configParams.px_logger_severity);
21
+ this.internalLogger = this.createInternalLogger(this.configParams.px_logger_severity);
22
22
  }
23
23
  ConfigurationBase.prototype.initialize = function (params, defaultParams) {
24
24
  var _this = this;
@@ -71,6 +71,9 @@ var ConfigurationBase = /** @class */ (function () {
71
71
  return defaultParams[key];
72
72
  }
73
73
  };
74
+ ConfigurationBase.prototype.createInternalLogger = function (loggerSeverity) {
75
+ return new logger_1.DefaultLogger(loggerSeverity, false);
76
+ };
74
77
  ConfigurationBase.prototype.toParams = function () {
75
78
  return Object.assign({}, this.configParams);
76
79
  };
@@ -37,7 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.DefaultRemoteConfigUpdater = void 0;
40
- var http_1 = require("../../http");
41
40
  var utils_1 = require("../../utils");
42
41
  var constants_1 = require("./constants");
43
42
  var DefaultRemoteConfigUpdater = /** @class */ (function () {
@@ -49,59 +48,55 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
49
48
  options.timestampHmacHeaderValidator ||
50
49
  new utils_1.DefaultTimestampHmacHeaderValidator(config, config.remoteConfigSecret, options.base64Utils, options.hmacUtils);
51
50
  }
52
- DefaultRemoteConfigUpdater.prototype.isUpdateRemoteConfigRequest = function (_a) {
53
- var request = _a.requestData.request;
54
- var isCorrectMethod = request.method === http_1.HttpMethod.PATCH;
55
- var isCorrectFeature = request.headers.get(utils_1.PUSH_DATA_FEATURE_HEADER_NAME) === constants_1.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME;
56
- var isHmacHeaderPresent = !!request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
57
- return isCorrectMethod && isCorrectFeature && isHmacHeaderPresent;
51
+ DefaultRemoteConfigUpdater.prototype.isUpdateRemoteConfigRequest = function (context) {
52
+ return context.isRemoteConfigUpdateRequest;
58
53
  };
59
- DefaultRemoteConfigUpdater.prototype.updateRemoteConfig = function (_a) {
60
- var request = _a.requestData.request;
54
+ DefaultRemoteConfigUpdater.prototype.updateRemoteConfig = function (context) {
61
55
  return __awaiter(this, void 0, void 0, function () {
62
- var updateRequestData, remoteConfig;
63
- return __generator(this, function (_b) {
64
- switch (_b.label) {
56
+ var request, updateRequestData, remoteConfig;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
65
59
  case 0:
66
- this.config.logger.debug('identified an update remote config request');
67
- return [4 /*yield*/, this.isUpdateRequestValid(request)];
60
+ context.logger.debug('identified an update remote config request');
61
+ request = context.requestData.request;
62
+ return [4 /*yield*/, this.isUpdateRequestValid(request, context)];
68
63
  case 1:
69
- if (!(_b.sent())) {
64
+ if (!(_a.sent())) {
70
65
  return [2 /*return*/, false];
71
66
  }
72
- return [4 /*yield*/, this.getUpdateRequestData(request)];
67
+ return [4 /*yield*/, this.getUpdateRequestData(request, context)];
73
68
  case 2:
74
- updateRequestData = _b.sent();
69
+ updateRequestData = _a.sent();
75
70
  if (!updateRequestData) {
76
71
  return [2 /*return*/, false];
77
72
  }
78
- return [4 /*yield*/, this.fetchRemoteConfig(updateRequestData)];
73
+ return [4 /*yield*/, this.fetchRemoteConfig(updateRequestData, context)];
79
74
  case 3:
80
- remoteConfig = _b.sent();
75
+ remoteConfig = _a.sent();
81
76
  if (!remoteConfig) {
82
77
  return [2 /*return*/, false];
83
78
  }
84
79
  return [4 /*yield*/, this.storageClient.save(remoteConfig)];
85
80
  case 4:
86
- _b.sent();
87
- this.config.logger.debug("successfully updated with remote config version ".concat(remoteConfig.version));
81
+ _a.sent();
82
+ context.logger.debug("successfully updated with remote config version ".concat(remoteConfig.version));
88
83
  return [2 /*return*/, true];
89
84
  }
90
85
  });
91
86
  });
92
87
  };
93
- DefaultRemoteConfigUpdater.prototype.isUpdateRequestValid = function (request) {
88
+ DefaultRemoteConfigUpdater.prototype.isUpdateRequestValid = function (request, context) {
94
89
  return __awaiter(this, void 0, void 0, function () {
95
90
  var timestampHmacHeader, isValid;
96
91
  return __generator(this, function (_a) {
97
92
  switch (_a.label) {
98
93
  case 0:
99
94
  timestampHmacHeader = request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
100
- return [4 /*yield*/, this.timestampHmacHeaderValidator.isValid(timestampHmacHeader)];
95
+ return [4 /*yield*/, this.timestampHmacHeaderValidator.isValid(timestampHmacHeader, context.logger)];
101
96
  case 1:
102
97
  isValid = _a.sent();
103
98
  if (!isValid) {
104
- this.config.logger.error("invalid timestamp hmac header received: ".concat(timestampHmacHeader), {
99
+ context.logger.error("invalid timestamp hmac header received: ".concat(timestampHmacHeader), {
105
100
  errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
106
101
  });
107
102
  }
@@ -110,7 +105,7 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
110
105
  });
111
106
  });
112
107
  };
113
- DefaultRemoteConfigUpdater.prototype.getUpdateRequestData = function (request) {
108
+ DefaultRemoteConfigUpdater.prototype.getUpdateRequestData = function (request, context) {
114
109
  return __awaiter(this, void 0, void 0, function () {
115
110
  var updateRequestData, err_1;
116
111
  return __generator(this, function (_a) {
@@ -123,13 +118,13 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
123
118
  return [3 /*break*/, 3];
124
119
  case 2:
125
120
  err_1 = _a.sent();
126
- this.config.logger.error("could not parse update request body: ".concat(err_1), {
121
+ context.logger.error("could not parse update request body: ".concat(err_1), {
127
122
  errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
128
123
  });
129
124
  return [2 /*return*/, null];
130
125
  case 3:
131
126
  if (!(updateRequestData === null || updateRequestData === void 0 ? void 0 : updateRequestData.version)) {
132
- this.config.logger.error("no version on update request body: ".concat(updateRequestData), {
127
+ context.logger.error("no version on update request body: ".concat(updateRequestData), {
133
128
  errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME,
134
129
  });
135
130
  return [2 /*return*/, null];
@@ -139,9 +134,9 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
139
134
  });
140
135
  });
141
136
  };
142
- DefaultRemoteConfigUpdater.prototype.fetchRemoteConfig = function (updateRequestData) {
137
+ DefaultRemoteConfigUpdater.prototype.fetchRemoteConfig = function (updateRequestData, context) {
143
138
  return __awaiter(this, void 0, void 0, function () {
144
- var _a, remoteConfigMaxFetchAttempts, remoteConfigRetryIntervalMs, remoteConfigVersion, remoteConfigData, errorText, i, err_2;
139
+ var _a, remoteConfigMaxFetchAttempts, remoteConfigRetryIntervalMs, remoteConfigVersion, errorText, remoteConfigData, i, err_2;
145
140
  return __generator(this, function (_b) {
146
141
  switch (_b.label) {
147
142
  case 0:
@@ -173,7 +168,7 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
173
168
  case 9:
174
169
  errorText =
175
170
  errorText !== null && errorText !== void 0 ? errorText : "no config version ".concat(updateRequestData.version, " found after ").concat(remoteConfigMaxFetchAttempts, " attempts, current: ").concat(remoteConfigVersion, ", received: ").concat(remoteConfigData === null || remoteConfigData === void 0 ? void 0 : remoteConfigData.version);
176
- this.config.logger.error(errorText, { errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME });
171
+ context.logger.error(errorText, { errorType: constants_1.WRITE_REMOTE_CONFIG_ERROR_NAME });
177
172
  return [2 /*return*/];
178
173
  }
179
174
  });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteConfigUtils = void 0;
4
+ var http_1 = require("../../http");
5
+ var utils_1 = require("../../utils");
6
+ var constants_1 = require("./constants");
7
+ var RemoteConfigUtils;
8
+ (function (RemoteConfigUtils) {
9
+ RemoteConfigUtils.isRemoteConfigUpdateRequest = function (request) {
10
+ return request.method === http_1.HttpMethod.PATCH &&
11
+ request.headers.get(utils_1.PUSH_DATA_FEATURE_HEADER_NAME) === constants_1.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
12
+ !!request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
13
+ };
14
+ })(RemoteConfigUtils || (exports.RemoteConfigUtils = RemoteConfigUtils = {}));
@@ -20,3 +20,4 @@ __exportStar(require("./service_client"), exports);
20
20
  __exportStar(require("./storage_client"), exports);
21
21
  __exportStar(require("./DefaultRemoteConfigUpdater"), exports);
22
22
  __exportStar(require("./IRemoteConfigUpdater"), exports);
23
+ __exportStar(require("./RemoteConfigUtils"), exports);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultContext = void 0;
4
+ var config_1 = require("../config");
4
5
  var blocker_1 = require("../blocker");
5
6
  var pxhd_1 = require("../pxhd");
6
7
  var risk_token_1 = require("../risk_token");
@@ -25,13 +26,22 @@ var DefaultContext = /** @class */ (function () {
25
26
  this.requestId = options.requestIdGenerator.generateRequestId();
26
27
  this.blockAction = blocker_1.BlockAction.CAPTCHA;
27
28
  this.pxdeVerified = false;
29
+ this.isRemoteConfigUpdateRequest = config_1.RemoteConfigUtils.isRemoteConfigUpdateRequest(request);
30
+ this.shouldSendLogs = this.isRemoteConfigUpdateRequest || this.isHeaderBasedLoggerRequest(config, request);
31
+ this.contextLogger = this.createContextLogger(config, this.shouldSendLogs);
28
32
  this.requestData = this.createRequestData(config, request, options.cookieParser);
29
33
  this.tokenOrigin = this.getTokenOrigin(request);
30
34
  if (!this.isMobile) {
31
35
  this.setCookiesOnContext();
32
36
  }
33
- this.shouldSendLogs = this.isHeaderBasedLoggerEnabled();
34
37
  }
38
+ Object.defineProperty(DefaultContext.prototype, "logger", {
39
+ get: function () {
40
+ return this.contextLogger;
41
+ },
42
+ enumerable: false,
43
+ configurable: true
44
+ });
35
45
  Object.defineProperty(DefaultContext.prototype, "isMobile", {
36
46
  get: function () {
37
47
  return this.tokenOrigin === risk_token_1.TokenOrigin.HEADER;
@@ -39,16 +49,18 @@ var DefaultContext = /** @class */ (function () {
39
49
  enumerable: false,
40
50
  configurable: true
41
51
  });
52
+ DefaultContext.prototype.createContextLogger = function (config, shouldSaveLogs) {
53
+ return new logger_1.DefaultLogger(config.loggerSeverity, shouldSaveLogs);
54
+ };
42
55
  DefaultContext.prototype.createRequestData = function (config, request, cookieParser) {
43
56
  if (cookieParser === void 0) { cookieParser = new utils_1.StringSplitCookieParser(); }
44
57
  var rawUrl = request.url;
45
58
  var url = this.normalizeUrl(rawUrl);
46
59
  var isUrlDifferentFromRawUrl = rawUrl !== url.href;
47
60
  var method = request.method;
48
- var headers = request.headers;
49
61
  var cookies = DefaultContext.getCookies(cookieParser, request.headers.get(http_1.COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
50
62
  var requestCookieNames = Object.keys(cookies);
51
- var readOnlyHeaders = (0, http_1.toReadonlyHeaders)(headers);
63
+ var readOnlyHeaders = (0, http_1.toReadonlyHeaders)(request.headers);
52
64
  var userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
53
65
  var ip = this.extractIpFromHeader(config, readOnlyHeaders) || request.clientIP;
54
66
  var httpVersion = request.httpVersion;
@@ -84,7 +96,7 @@ var DefaultContext = /** @class */ (function () {
84
96
  url = this.urlUtils.createUrl("".concat(url.origin).concat(this.urlUtils.decodeUriComponent(url.pathname)).concat(url.search));
85
97
  }
86
98
  catch (e) {
87
- this.config.logger.debug("unable to URL decode reserved characters: ".concat(e));
99
+ this.logger.debug("unable to URL decode reserved characters: ".concat(e));
88
100
  }
89
101
  }
90
102
  url.pathname = url.pathname.replace(/\/+$/, '').replace(/\/+/g, '/');
@@ -123,9 +135,8 @@ var DefaultContext = /** @class */ (function () {
123
135
  };
124
136
  }
125
137
  };
126
- DefaultContext.prototype.isHeaderBasedLoggerEnabled = function () {
127
- var _a;
128
- return this.config.loggerAuthToken === ((_a = this.requestData.headers[logger_1.X_PX_ENFORCER_LOG_HEADER]) === null || _a === void 0 ? void 0 : _a[0]);
138
+ DefaultContext.prototype.isHeaderBasedLoggerRequest = function (config, request) {
139
+ return config.loggerAuthToken && config.loggerAuthToken === request.headers.get(logger_1.X_PX_ENFORCER_LOG_HEADER);
129
140
  };
130
141
  return DefaultContext;
131
142
  }());
@@ -56,7 +56,7 @@ var CustomParametersUtils;
56
56
  return [2 /*return*/, CustomParametersUtils.normalizeCustomParams(parameters)];
57
57
  case 3:
58
58
  e_1 = _a.sent();
59
- config.logger.error("unable to enrich custom params: ".concat(e_1));
59
+ context.logger.error("unable to enrich custom params: ".concat(e_1));
60
60
  return [3 /*break*/, 4];
61
61
  case 4: return [2 /*return*/, null];
62
62
  }
@@ -84,6 +84,9 @@ var EnforcerBase = /** @class */ (function () {
84
84
  this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
85
85
  this.postEnforceFlow = this.createPostEnforceFlow(config, initializationBlock);
86
86
  this.endEnforcerFlow = this.createEndEnforcerFlow(config, initializationBlock);
87
+ if (!this.config.moduleEnabled) {
88
+ this.config.logger.debug('HUMAN enforcer is disabled, will not enforce');
89
+ }
87
90
  }
88
91
  EnforcerBase.prototype.createFilterFlow = function (config, initializationBlock) {
89
92
  return new phase_1.FilterFlow(config, initializationBlock);
@@ -108,64 +111,64 @@ var EnforcerBase = /** @class */ (function () {
108
111
  args[_i] = arguments[_i];
109
112
  }
110
113
  return __awaiter(this, void 0, void 0, function () {
111
- var e_1;
114
+ var context, e_1;
112
115
  return __generator(this, function (_a) {
113
116
  switch (_a.label) {
114
117
  case 0:
115
- _a.trys.push([0, 2, , 3]);
118
+ _a.trys.push([0, 3, , 4]);
116
119
  if (!this.config.moduleEnabled) {
117
- this.config.logger.debug('module is disabled, will not enforce');
118
120
  return [2 /*return*/, null];
119
121
  }
120
- return [4 /*yield*/, this.doEnforce.apply(this, args)];
121
- case 1: return [2 /*return*/, _a.sent()];
122
- case 2:
122
+ return [4 /*yield*/, this.constructContext.apply(this, args)];
123
+ case 1:
124
+ context = _a.sent();
125
+ return [4 /*yield*/, this.doEnforce.apply(this, __spreadArray([context], args, false))];
126
+ case 2: return [2 /*return*/, _a.sent()];
127
+ case 3:
123
128
  e_1 = _a.sent();
124
- this.config.logger.error("caught error in enforce - ".concat(e_1));
129
+ (context || this.config).logger.error("caught error in enforce - ".concat(e_1));
125
130
  return [2 /*return*/, null];
126
- case 3: return [2 /*return*/];
131
+ case 4: return [2 /*return*/];
127
132
  }
128
133
  });
129
134
  });
130
135
  };
131
136
  /**
132
137
  * Performs all enforcer functionality on the incoming request context.
138
+ * @param context
133
139
  * @param args - The EnforceArgs required to enforce the incoming request.
134
140
  * @returns Promise<Res|null> - A Promise resolving to a Res or null depending on the action that should be taken.
135
141
  * @protected
136
142
  */
137
- EnforcerBase.prototype.doEnforce = function () {
143
+ EnforcerBase.prototype.doEnforce = function (context) {
138
144
  var args = [];
139
- for (var _i = 0; _i < arguments.length; _i++) {
140
- args[_i] = arguments[_i];
145
+ for (var _i = 1; _i < arguments.length; _i++) {
146
+ args[_i - 1] = arguments[_i];
141
147
  }
142
148
  return __awaiter(this, void 0, void 0, function () {
143
- var context, result;
149
+ var result;
144
150
  return __generator(this, function (_a) {
145
151
  switch (_a.label) {
146
- case 0: return [4 /*yield*/, this.constructContext.apply(this, args)];
152
+ case 0: return [4 /*yield*/, this.filterFlow.execute(context)];
147
153
  case 1:
148
- context = _a.sent();
149
- return [4 /*yield*/, this.filterFlow.execute(context)];
150
- case 2:
151
154
  result = _a.sent();
152
- if (!result.done) return [3 /*break*/, 4];
155
+ if (!result.done) return [3 /*break*/, 3];
153
156
  return [4 /*yield*/, this.endEnforcerFlow.execute(context)];
154
- case 3:
157
+ case 2:
155
158
  _a.sent();
156
159
  return [2 /*return*/, result.response ? this.convertToRes.apply(this, __spreadArray([result.response], args, false)) : null];
157
- case 4: return [4 /*yield*/, this.preserveContext.apply(this, __spreadArray([context], args, false))];
158
- case 5:
160
+ case 3: return [4 /*yield*/, this.preserveContext.apply(this, __spreadArray([context], args, false))];
161
+ case 4:
159
162
  _a.sent();
160
163
  return [4 /*yield*/, this.enforceFlow.execute(context)];
161
- case 6:
164
+ case 5:
162
165
  result = _a.sent();
163
- if (!result.done) return [3 /*break*/, 8];
166
+ if (!result.done) return [3 /*break*/, 7];
164
167
  return [4 /*yield*/, this.endEnforcerFlow.execute(context)];
165
- case 7:
168
+ case 6:
166
169
  _a.sent();
167
170
  return [2 /*return*/, result.response ? this.convertToRes.apply(this, __spreadArray([result.response], args, false)) : null];
168
- case 8: return [2 /*return*/, null];
171
+ case 7: return [2 /*return*/, null];
169
172
  }
170
173
  });
171
174
  });
@@ -182,28 +185,31 @@ var EnforcerBase = /** @class */ (function () {
182
185
  args[_i] = arguments[_i];
183
186
  }
184
187
  return __awaiter(this, void 0, void 0, function () {
185
- var context_1, _a, e_2;
188
+ var context, _a, e_2;
186
189
  return __generator(this, function (_b) {
187
190
  switch (_b.label) {
188
191
  case 0:
189
192
  _b.trys.push([0, 5, , 6]);
190
- context_1 = this.retrieveContext.apply(this, args);
191
- if (!context_1) return [3 /*break*/, 4];
192
- _a = context_1;
193
+ if (!this.config.moduleEnabled) {
194
+ return [2 /*return*/];
195
+ }
196
+ context = this.retrieveContext.apply(this, args);
197
+ if (!context) return [3 /*break*/, 4];
198
+ _a = context;
193
199
  return [4 /*yield*/, this.convertToOutgoingResponse.apply(this, args)];
194
200
  case 1:
195
201
  _a.response = _b.sent();
196
- return [4 /*yield*/, this.postEnforceFlow.execute(context_1)];
202
+ return [4 /*yield*/, this.postEnforceFlow.execute(context)];
197
203
  case 2:
198
204
  _b.sent();
199
- return [4 /*yield*/, this.endEnforcerFlow.execute(context_1)];
205
+ return [4 /*yield*/, this.endEnforcerFlow.execute(context)];
200
206
  case 3:
201
207
  _b.sent();
202
208
  _b.label = 4;
203
209
  case 4: return [3 /*break*/, 6];
204
210
  case 5:
205
211
  e_2 = _b.sent();
206
- this.config.logger.error("caught error in post enforce - ".concat(e_2));
212
+ (context || this.config).logger.error("caught error in post enforce - ".concat(e_2));
207
213
  return [3 /*break*/, 6];
208
214
  case 6: return [2 /*return*/];
209
215
  }
@@ -220,6 +226,9 @@ var EnforcerBase = /** @class */ (function () {
220
226
  return __generator(this, function (_a) {
221
227
  switch (_a.label) {
222
228
  case 0:
229
+ if (!this.config.moduleEnabled) {
230
+ return [2 /*return*/];
231
+ }
223
232
  context = this.retrieveContext.apply(this, args);
224
233
  if (!context) return [3 /*break*/, 2];
225
234
  return [4 /*yield*/, this.activityClient.sendActivities(context)];
@@ -42,7 +42,6 @@ var http_1 = require("../http");
42
42
  var model_1 = require("./model");
43
43
  var DefaultGraphQLParser = /** @class */ (function () {
44
44
  function DefaultGraphQLParser(config) {
45
- this.config = config;
46
45
  this.graphqlRoutes = config.graphqlRoutes;
47
46
  this.sensitiveOperationNames = config.sensitiveGraphqlOperationNames;
48
47
  this.sensitiveOperationTypes = config.sensitiveGraphqlOperationTypes;
@@ -51,55 +50,54 @@ var DefaultGraphQLParser = /** @class */ (function () {
51
50
  var requestData = _a.requestData;
52
51
  return (requestData.method === http_1.HttpMethod.POST && (0, utils_1.isRouteInPatterns)(requestData.url.pathname, this.graphqlRoutes));
53
52
  };
54
- DefaultGraphQLParser.prototype.parseGraphQLRequest = function (_a) {
55
- var requestData = _a.requestData;
53
+ DefaultGraphQLParser.prototype.parseGraphQLRequest = function (context) {
56
54
  return __awaiter(this, void 0, void 0, function () {
57
- var graphQLOperations, data, e_1;
58
- return __generator(this, function (_b) {
59
- switch (_b.label) {
55
+ var requestData, graphQLOperations, data, e_1;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
60
58
  case 0:
61
- _b.trys.push([0, 2, , 3]);
62
- return [4 /*yield*/, this.getGraphQLOperationsFromBody(requestData)];
59
+ _a.trys.push([0, 2, , 3]);
60
+ requestData = context.requestData;
61
+ return [4 /*yield*/, this.getGraphQLOperationsFromBody(requestData.request, context)];
63
62
  case 1:
64
- graphQLOperations = _b.sent();
63
+ graphQLOperations = _a.sent();
65
64
  if (!graphQLOperations) {
66
- this.config.logger.debug('unable to get graphql operations from request body');
65
+ context.logger.debug('unable to get graphql operations from request body');
67
66
  return [2 /*return*/, null];
68
67
  }
69
68
  data = this.parseGraphQLOperations(graphQLOperations);
70
69
  if (!data || data.length === 0) {
71
- this.config.logger.debug('unable to parse graphql operations');
70
+ context.logger.debug('unable to parse graphql operations');
72
71
  return [2 /*return*/, null];
73
72
  }
74
- this.config.logger.debug("".concat(data.length, " graphql operation").concat(data.length === 1 ? '' : 's', " parsed successfully"));
73
+ context.logger.debug("".concat(data.length, " graphql operation").concat(data.length === 1 ? '' : 's', " parsed successfully"));
75
74
  return [2 /*return*/, data];
76
75
  case 2:
77
- e_1 = _b.sent();
78
- this.config.logger.debug("unable to parse graphql request: ".concat(e_1));
76
+ e_1 = _a.sent();
77
+ context.logger.debug("unable to parse graphql request: ".concat(e_1));
79
78
  return [2 /*return*/, null];
80
79
  case 3: return [2 /*return*/];
81
80
  }
82
81
  });
83
82
  });
84
83
  };
85
- DefaultGraphQLParser.prototype.getGraphQLOperationsFromBody = function (_a) {
86
- var request = _a.request;
84
+ DefaultGraphQLParser.prototype.getGraphQLOperationsFromBody = function (request, context) {
87
85
  return __awaiter(this, void 0, void 0, function () {
88
86
  var body, e_2;
89
- return __generator(this, function (_b) {
90
- switch (_b.label) {
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
91
89
  case 0:
92
- _b.trys.push([0, 2, , 3]);
90
+ _a.trys.push([0, 2, , 3]);
93
91
  return [4 /*yield*/, request.json()];
94
92
  case 1:
95
- body = _b.sent();
93
+ body = _a.sent();
96
94
  if (!body) {
97
95
  return [2 /*return*/, null];
98
96
  }
99
97
  return [2 /*return*/, Array.isArray(body) ? body : [body]];
100
98
  case 2:
101
- e_2 = _b.sent();
102
- this.config.logger.debug("unable to parse body to json: ".concat(e_2));
99
+ e_2 = _a.sent();
100
+ context.logger.debug("unable to parse body to json: ".concat(e_2));
103
101
  return [2 /*return*/, null];
104
102
  case 3: return [2 /*return*/];
105
103
  }
@@ -1,11 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultUrlUtils = void 0;
4
+ var UrlImpl_1 = require("./UrlImpl");
4
5
  var DefaultUrlUtils = /** @class */ (function () {
5
6
  function DefaultUrlUtils() {
6
7
  }
7
8
  DefaultUrlUtils.prototype.createUrl = function (rawUrl) {
8
- return new URL(rawUrl);
9
+ try {
10
+ return new URL(rawUrl);
11
+ }
12
+ catch (e) {
13
+ return new UrlImpl_1.UrlImpl(rawUrl);
14
+ }
9
15
  };
10
16
  DefaultUrlUtils.prototype.createUrlSearchParams = function (params) {
11
17
  return new URLSearchParams(params);
@@ -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) {
23
- return _super.call(this, loggerSeverity) || this;
22
+ function DefaultLogger(loggerSeverity, shouldSaveLogs) {
23
+ return _super.call(this, loggerSeverity, shouldSaveLogs) || this;
24
24
  }
25
25
  DefaultLogger.prototype.log = function (message) {
26
26
  /* eslint-disable no-console */