perimeterx-js-core 0.16.1 → 0.17.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 (101) hide show
  1. package/lib/cjs/activities/HttpActivityClient.js +27 -7
  2. package/lib/cjs/activities/utils.js +3 -3
  3. package/lib/cjs/config/defaults/constants.js +0 -0
  4. package/lib/cjs/context/ContextJson.js +2 -0
  5. package/lib/cjs/context/DefaultContext.js +41 -20
  6. package/lib/cjs/context/SerializedContext.js +66 -0
  7. package/lib/cjs/context/index.js +2 -0
  8. package/lib/cjs/enforcer/EnforcerBase.js +2 -101
  9. package/lib/cjs/enforcer/index.js +3 -3
  10. package/lib/cjs/enforcer/utils.js +96 -0
  11. package/lib/cjs/impl/url/UrlImpl.js +3 -0
  12. package/lib/cjs/products/bot_defender/first_party/IDefaultBotDefenderFirstPartyConfiguration.js +0 -0
  13. package/lib/cjs/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +4 -6
  14. package/lib/cjs/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +1 -11
  15. package/lib/cjs/products/hype_sale_challenge/HypeSaleChallenge.js +1 -1
  16. package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +14 -0
  17. package/lib/cjs/risk_api/risk_response/index.js +1 -0
  18. package/lib/cjs/risk_api/risk_response/serialize/RiskResponseJson.js +2 -0
  19. package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +22 -0
  20. package/lib/cjs/risk_api/risk_response/serialize/index.js +18 -0
  21. package/lib/cjs/risk_token/parser/TokenParserBase.js +1 -1
  22. package/lib/cjs/risk_token/token/TokenBase.js +31 -7
  23. package/lib/cjs/risk_token/token/index.js +19 -9
  24. package/lib/cjs/risk_token/token/serialize/SerializedToken.js +30 -0
  25. package/lib/cjs/risk_token/token/serialize/TokenJson.js +2 -0
  26. package/lib/cjs/risk_token/token/serialize/index.js +18 -0
  27. package/lib/cjs/risk_token/token/v2/index.js +18 -0
  28. package/lib/cjs/risk_token/token/v3/DefaultTokenV3.js +3 -2
  29. package/lib/cjs/risk_token/token/v3/index.js +19 -0
  30. package/lib/cjs/utils/constants.js +1 -1
  31. package/lib/cjs/utils/cookie_parser/StringSplitCookieParser.js +20 -4
  32. package/lib/esm/activities/HttpActivityClient.js +27 -7
  33. package/lib/esm/activities/utils.js +3 -3
  34. package/lib/esm/config/defaults/constants.js +0 -0
  35. package/lib/esm/context/ContextJson.js +1 -0
  36. package/lib/esm/context/DefaultContext.js +36 -13
  37. package/lib/esm/context/SerializedContext.js +87 -0
  38. package/lib/esm/context/index.js +2 -0
  39. package/lib/esm/enforcer/EnforcerBase.js +2 -89
  40. package/lib/esm/enforcer/index.js +3 -1
  41. package/lib/esm/enforcer/utils.js +79 -0
  42. package/lib/esm/impl/url/UrlImpl.js +3 -0
  43. package/lib/esm/products/bot_defender/first_party/IDefaultBotDefenderFirstPartyConfiguration.js +0 -0
  44. package/lib/esm/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +6 -8
  45. package/lib/esm/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +1 -6
  46. package/lib/esm/products/hype_sale_challenge/HypeSaleChallenge.js +1 -1
  47. package/lib/esm/risk_api/risk_response/RiskResponseBase.js +14 -0
  48. package/lib/esm/risk_api/risk_response/index.js +1 -0
  49. package/lib/esm/risk_api/risk_response/serialize/RiskResponseJson.js +1 -0
  50. package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +27 -0
  51. package/lib/esm/risk_api/risk_response/serialize/index.js +2 -0
  52. package/lib/esm/risk_token/parser/TokenParserBase.js +1 -1
  53. package/lib/esm/risk_token/token/TokenBase.js +19 -4
  54. package/lib/esm/risk_token/token/index.js +5 -4
  55. package/lib/esm/risk_token/token/serialize/SerializedToken.js +36 -0
  56. package/lib/esm/risk_token/token/serialize/TokenJson.js +1 -0
  57. package/lib/esm/risk_token/token/serialize/index.js +2 -0
  58. package/lib/esm/risk_token/token/v2/index.js +2 -0
  59. package/lib/esm/risk_token/token/v3/DefaultTokenV3.js +2 -2
  60. package/lib/esm/risk_token/token/v3/index.js +3 -0
  61. package/lib/esm/utils/constants.js +1 -1
  62. package/lib/esm/utils/cookie_parser/StringSplitCookieParser.js +16 -3
  63. package/lib/types/activities/HttpActivityClient.d.ts +6 -0
  64. package/lib/types/activities/utils.d.ts +91 -60
  65. package/lib/types/blocker/utils.d.ts +9 -6
  66. package/lib/types/config/defaults/constants.d.ts +0 -0
  67. package/lib/types/context/ContextJson.d.ts +41 -0
  68. package/lib/types/context/DefaultContext.d.ts +5 -3
  69. package/lib/types/context/SerializedContext.d.ts +46 -0
  70. package/lib/types/context/index.d.ts +2 -0
  71. package/lib/types/enforcer/EnforcerBase.d.ts +2 -13
  72. package/lib/types/enforcer/index.d.ts +3 -2
  73. package/lib/types/enforcer/utils.d.ts +7 -0
  74. package/lib/types/impl/url/UrlImpl.d.ts +1 -0
  75. package/lib/types/monitored_request/MonitoredRequestUtils.d.ts +27 -18
  76. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +1 -1
  77. package/lib/types/phase/flow/EnforceFlow.d.ts +3 -1
  78. package/lib/types/phase/flow/PostEnforceFlow.d.ts +1 -1
  79. package/lib/types/products/bot_defender/first_party/IDefaultBotDefenderFirstPartyConfiguration.d.ts +0 -0
  80. package/lib/types/products/bot_defender/first_party/utils.d.ts +7 -6
  81. package/lib/types/pxhd/PXHDUtils.d.ts +18 -12
  82. package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +2 -0
  83. package/lib/types/risk_api/risk_response/index.d.ts +1 -0
  84. package/lib/types/risk_api/risk_response/serialize/RiskResponseJson.d.ts +15 -0
  85. package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +19 -0
  86. package/lib/types/risk_api/risk_response/serialize/index.d.ts +2 -0
  87. package/lib/types/risk_token/token/IToken.d.ts +3 -3
  88. package/lib/types/risk_token/token/TokenBase.d.ts +6 -4
  89. package/lib/types/risk_token/token/index.d.ts +5 -7
  90. package/lib/types/risk_token/token/serialize/SerializedToken.d.ts +23 -0
  91. package/lib/types/risk_token/token/serialize/TokenJson.d.ts +13 -0
  92. package/lib/types/risk_token/token/serialize/index.d.ts +2 -0
  93. package/lib/types/risk_token/token/v2/index.d.ts +2 -0
  94. package/lib/types/risk_token/token/v3/DefaultTokenV3.d.ts +1 -1
  95. package/lib/types/risk_token/token/v3/index.d.ts +3 -0
  96. package/lib/types/sensitive_request/SensitiveRequestUtils.d.ts +18 -12
  97. package/lib/types/utils/constants.d.ts +1 -1
  98. package/lib/types/utils/cookie_parser/ICookieParser.d.ts +1 -1
  99. package/lib/types/utils/cookie_parser/StringSplitCookieParser.d.ts +5 -2
  100. package/lib/types/utils/url/IUrl.d.ts +1 -0
  101. package/package.json +1 -1
@@ -69,17 +69,37 @@ var HttpActivityClient = /** @class */ (function () {
69
69
  };
70
70
  HttpActivityClient.prototype.createActivities = function (context) {
71
71
  var activities = [];
72
- if (context.action === action_1.Action.BLOCK || context.action === action_1.Action.SIMULATED_BLOCK) {
73
- activities.push((0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.BLOCK, this.config, context));
72
+ if (this.shouldCreateBlockActivity(context)) {
73
+ activities.push(this.createBlockActivity(context));
74
74
  }
75
- else if (context.action === action_1.Action.PASS_REQUEST) {
76
- activities.push((0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.PAGE_REQUESTED, this.config, context));
77
- if (context.productData.ci && this.config.ciAutomaticAdditionalS2SEnabled) {
78
- activities.push((0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.ADDITIONAL_S2S, this.config, context));
79
- }
75
+ if (this.shouldCreatePageRequestedActivity(context)) {
76
+ activities.push(this.createPageRequestedActivity(context));
77
+ }
78
+ if (this.shouldCreateAdditionalS2SActivity(context)) {
79
+ activities.push(this.createAdditionalS2SActivity(context));
80
80
  }
81
81
  return activities.map(this.finalizeActivity);
82
82
  };
83
+ HttpActivityClient.prototype.shouldCreateBlockActivity = function (context) {
84
+ return context.action === action_1.Action.BLOCK || context.action === action_1.Action.SIMULATED_BLOCK;
85
+ };
86
+ HttpActivityClient.prototype.shouldCreatePageRequestedActivity = function (context) {
87
+ return context.action === action_1.Action.PASS_REQUEST;
88
+ };
89
+ HttpActivityClient.prototype.shouldCreateAdditionalS2SActivity = function (context) {
90
+ return (this.shouldCreatePageRequestedActivity(context) &&
91
+ context.productData.ci &&
92
+ this.config.ciAutomaticAdditionalS2SEnabled);
93
+ };
94
+ HttpActivityClient.prototype.createBlockActivity = function (context) {
95
+ return (0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.BLOCK, this.config, context);
96
+ };
97
+ HttpActivityClient.prototype.createPageRequestedActivity = function (context) {
98
+ return (0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.PAGE_REQUESTED, this.config, context);
99
+ };
100
+ HttpActivityClient.prototype.createAdditionalS2SActivity = function (context) {
101
+ return (0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.ADDITIONAL_S2S, this.config, context);
102
+ };
83
103
  /**
84
104
  * Allows for expansions or alterations to the async activity if needed.
85
105
  * @param activity
@@ -140,12 +140,12 @@ exports.addRequestDataToDetails = addRequestDataToDetails;
140
140
  var addTokenDataToDetails = function (details, _a) {
141
141
  var token = _a.token, mobileData = _a.mobileData;
142
142
  if (token) {
143
- if (token.isValid()) {
144
- details.px_cookie = token.getPayloadString();
143
+ if (token.isValidated) {
144
+ details.px_cookie = token.payloadString;
145
145
  details.px_cookie_hmac = token.hmac;
146
146
  }
147
147
  else {
148
- details.px_orig_cookie = token.getTokenString();
148
+ details.px_orig_cookie = token.tokenString;
149
149
  }
150
150
  }
151
151
  if (mobileData) {
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.DefaultContext = void 0;
4
15
  var config_1 = require("../config");
@@ -28,20 +39,13 @@ var DefaultContext = /** @class */ (function () {
28
39
  this.pxdeVerified = false;
29
40
  this.isRemoteConfigUpdateRequest = config_1.RemoteConfigUtils.isRemoteConfigUpdateRequest(request);
30
41
  this.shouldSendLogs = this.isRemoteConfigUpdateRequest || this.isHeaderBasedLoggerRequest(config, request);
31
- this.contextLogger = this.createContextLogger(config, this.shouldSendLogs);
42
+ this.logger = this.createContextLogger(config, this.shouldSendLogs);
32
43
  this.requestData = this.createRequestData(config, request, options.cookieParser);
33
44
  this.tokenOrigin = this.getTokenOrigin(request);
34
45
  if (!this.isMobile) {
35
46
  this.setCookiesOnContext();
36
47
  }
37
48
  }
38
- Object.defineProperty(DefaultContext.prototype, "logger", {
39
- get: function () {
40
- return this.contextLogger;
41
- },
42
- enumerable: false,
43
- configurable: true
44
- });
45
49
  Object.defineProperty(DefaultContext.prototype, "isMobile", {
46
50
  get: function () {
47
51
  return this.tokenOrigin === risk_token_1.TokenOrigin.HEADER;
@@ -58,7 +62,7 @@ var DefaultContext = /** @class */ (function () {
58
62
  var url = this.normalizeUrl(rawUrl);
59
63
  var isUrlDifferentFromRawUrl = rawUrl !== url.href;
60
64
  var method = request.method;
61
- var cookies = DefaultContext.getCookies(cookieParser, request.headers.get(http_1.COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
65
+ var cookies = cookieParser.parseCookies(request.headers.get(http_1.COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
62
66
  var requestCookieNames = Object.keys(cookies);
63
67
  var readOnlyHeaders = (0, http_1.toReadonlyHeaders)(request.headers);
64
68
  var userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
@@ -78,17 +82,6 @@ var DefaultContext = /** @class */ (function () {
78
82
  isUrlDifferentFromRawUrl: isUrlDifferentFromRawUrl,
79
83
  };
80
84
  };
81
- DefaultContext.getCookies = function (cookieParser) {
82
- var cookieHeaderValues = [];
83
- for (var _i = 1; _i < arguments.length; _i++) {
84
- cookieHeaderValues[_i - 1] = arguments[_i];
85
- }
86
- var cookies = {};
87
- cookieHeaderValues.forEach(function (value) {
88
- Object.assign(cookies, value ? cookieParser.parseCookies(value) : null);
89
- });
90
- return cookies;
91
- };
92
85
  DefaultContext.prototype.normalizeUrl = function (rawUrl) {
93
86
  var url = this.urlUtils.createUrl(rawUrl);
94
87
  if (this.config.urlDecodeReservedCharacters) {
@@ -138,6 +131,34 @@ var DefaultContext = /** @class */ (function () {
138
131
  DefaultContext.prototype.isHeaderBasedLoggerRequest = function (config, request) {
139
132
  return config.loggerAuthToken && config.loggerAuthToken === request.headers.get(logger_1.X_PX_ENFORCER_LOG_HEADER);
140
133
  };
134
+ DefaultContext.prototype.toJSON = function () {
135
+ return {
136
+ action: this.action,
137
+ reasons: this.reasons,
138
+ isMobile: this.isMobile,
139
+ isRemoteConfigUpdateRequest: this.isRemoteConfigUpdateRequest,
140
+ productData: this.productData,
141
+ requestData: __assign(__assign({}, this.requestData), { request: undefined, url: this.requestData.url.href }),
142
+ requestId: this.requestId,
143
+ riskApiData: this.riskApiData,
144
+ serverData: this.serverData,
145
+ shouldSendLogs: this.shouldSendLogs,
146
+ tlsData: this.tlsData,
147
+ tokenData: this.tokenData,
148
+ tokenOrigin: this.tokenOrigin,
149
+ pxhd: this.pxhd,
150
+ pxde: this.pxde,
151
+ score: this.score,
152
+ customParameters: this.customParameters,
153
+ graphqlData: this.graphqlData,
154
+ vid: this.vid,
155
+ vidSource: this.vidSource,
156
+ uuid: this.uuid,
157
+ enforcerStartTime: this.enforcerStartTime,
158
+ blockAction: this.blockAction,
159
+ pxdeVerified: this.pxdeVerified,
160
+ };
161
+ };
141
162
  return DefaultContext;
142
163
  }());
143
164
  exports.DefaultContext = DefaultContext;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.SerializedContext = void 0;
15
+ var logger_1 = require("../logger");
16
+ var risk_token_1 = require("../risk_token");
17
+ var risk_api_1 = require("../risk_api");
18
+ var SerializedContext = /** @class */ (function () {
19
+ function SerializedContext(config, contextJson, request, urlUtils) {
20
+ this.action = contextJson.action;
21
+ this.reasons = contextJson.reasons;
22
+ this.isMobile = contextJson.isMobile;
23
+ this.requestId = contextJson.requestId;
24
+ this.isRemoteConfigUpdateRequest = contextJson.isRemoteConfigUpdateRequest;
25
+ this.logger = this.createLogger(config, contextJson.shouldSendLogs);
26
+ this.productData = contextJson.productData;
27
+ this.requestData = this.createRequestData(contextJson, request, urlUtils);
28
+ this.riskApiData = this.createRiskApiData(contextJson);
29
+ this.serverData = contextJson.serverData;
30
+ this.shouldSendLogs = contextJson.shouldSendLogs;
31
+ this.tlsData = contextJson.tlsData;
32
+ this.tokenData = this.createTokenData(contextJson, config);
33
+ this.tokenOrigin = contextJson.tokenOrigin;
34
+ this.uuid = contextJson.uuid;
35
+ this.vid = contextJson.vid;
36
+ this.vidSource = contextJson.vidSource;
37
+ this.pxhd = contextJson.pxhd;
38
+ this.pxde = contextJson.pxde;
39
+ this.pxdeVerified = contextJson.pxdeVerified;
40
+ this.score = contextJson.score;
41
+ this.customParameters = contextJson.customParameters;
42
+ this.graphqlData = contextJson.graphqlData;
43
+ this.enforcerStartTime = contextJson.enforcerStartTime;
44
+ this.blockAction = contextJson.blockAction;
45
+ }
46
+ SerializedContext.prototype.createRequestData = function (_a, request, urlUtils) {
47
+ var requestData = _a.requestData;
48
+ return __assign(__assign({}, requestData), { url: urlUtils.createUrl(requestData.url), request: request });
49
+ };
50
+ SerializedContext.prototype.createTokenData = function (_a, config) {
51
+ var tokenData = _a.tokenData;
52
+ return __assign(__assign({}, tokenData), { token: tokenData.token ? new risk_token_1.SerializedToken(config, tokenData.token) : undefined, mobileData: tokenData.mobileData
53
+ ? __assign(__assign({}, tokenData.mobileData), { originalToken: tokenData.mobileData.originalToken
54
+ ? new risk_token_1.SerializedToken(config, tokenData.mobileData.originalToken)
55
+ : undefined }) : {} });
56
+ };
57
+ SerializedContext.prototype.createRiskApiData = function (_a) {
58
+ var riskApiData = _a.riskApiData;
59
+ return __assign(__assign({}, riskApiData), { riskResponse: riskApiData.riskResponse ? new risk_api_1.SerializedRiskResponse(riskApiData.riskResponse) : undefined });
60
+ };
61
+ SerializedContext.prototype.createLogger = function (config, shouldSendLogs) {
62
+ return new logger_1.DefaultLogger(config.loggerSeverity, shouldSendLogs);
63
+ };
64
+ return SerializedContext;
65
+ }());
66
+ exports.SerializedContext = SerializedContext;
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./interfaces"), exports);
18
18
  __exportStar(require("./DefaultContext"), exports);
19
+ __exportStar(require("./ContextJson"), exports);
20
+ __exportStar(require("./SerializedContext"), exports);
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -57,18 +46,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
46
  };
58
47
  Object.defineProperty(exports, "__esModule", { value: true });
59
48
  exports.EnforcerBase = void 0;
60
- var config_1 = require("../config");
61
- var pxde_1 = require("../pxde");
62
- var telemetry_1 = require("../telemetry");
63
- var risk_token_1 = require("../risk_token");
64
- var cors_1 = require("../cors");
65
- var risk_api_1 = require("../risk_api");
66
49
  var phase_1 = require("../phase");
67
- var products_1 = require("../products");
68
- var activities_1 = require("../activities");
69
- var graphql_1 = require("../graphql");
70
- var logger_1 = require("../logger");
71
- var products_2 = require("../products");
50
+ var utils_1 = require("./utils");
72
51
  var EnforcerBase = /** @class */ (function () {
73
52
  /**
74
53
  * The EnforcerBase constructor.
@@ -78,7 +57,7 @@ var EnforcerBase = /** @class */ (function () {
78
57
  */
79
58
  function EnforcerBase(config, options) {
80
59
  this.config = config;
81
- var initializationBlock = this.getInitializationBlock(config, options);
60
+ var initializationBlock = (0, utils_1.createEnforcerInitializationBlock)(config, options);
82
61
  this.activityClient = initializationBlock.activityClient;
83
62
  this.filterFlow = this.createFilterFlow(config, initializationBlock);
84
63
  this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
@@ -240,84 +219,6 @@ var EnforcerBase = /** @class */ (function () {
240
219
  });
241
220
  });
242
221
  };
243
- /**
244
- * Returns the components needed to initialize the enforcer according to the provided options. If no
245
- * component is provided in the options, a default one is generated and returned.
246
- * @param config
247
- * @param options
248
- * @returns Required<EnforcerBaseOptions>
249
- * @protected
250
- */
251
- EnforcerBase.prototype.getInitializationBlock = function (config, options) {
252
- var tokenVersion = options.tokenVersion, httpClient = options.httpClient, base64Utils = options.base64Utils, hmacUtils = options.hmacUtils, hashUtils = options.hashUtils, urlUtils = options.urlUtils, ipRangeChecker = options.ipRangeChecker;
253
- var cipherUtils = tokenVersion === risk_token_1.TokenVersion.V2 ? null : options.cipherUtils;
254
- var cors = options.cors || new cors_1.DefaultCors(config);
255
- var telemetry = options.telemetry || new telemetry_1.DefaultTelemetry(config, httpClient, base64Utils, hmacUtils);
256
- var dataEnrichment = options.dataEnrichment || new pxde_1.DefaultDataEnrichment(config, base64Utils, hmacUtils);
257
- var graphQLParser = options.graphQLParser || new graphql_1.DefaultGraphQLParser(config);
258
- var tokenParser = options.tokenParser ||
259
- (tokenVersion === risk_token_1.TokenVersion.V2
260
- ? new risk_token_1.DefaultTokenV2Parser(config, { base64Utils: base64Utils, hmacUtils: hmacUtils })
261
- : new risk_token_1.DefaultTokenV3Parser(config, { cipherUtils: cipherUtils, hmacUtils: hmacUtils }));
262
- var riskApiClient = options.riskApiClient ||
263
- (tokenVersion === risk_token_1.TokenVersion.V2
264
- ? new risk_api_1.PostRiskApiClientV2(config, httpClient)
265
- : new risk_api_1.PostRiskApiClientV3(config, httpClient));
266
- var activityClient = options.activityClient ||
267
- (config.maxActivityBatchSize > 1
268
- ? new activities_1.HttpBatchedActivityClient(config, httpClient)
269
- : new activities_1.HttpActivityClient(config, httpClient));
270
- var logServiceClient = options.logServiceClient || (config.loggerAuthToken ? new logger_1.HttpLogServiceClient(config, httpClient) : null);
271
- var remoteConfigStorageClient = options.remoteConfigStorageClient;
272
- var remoteConfigServiceClient = options.remoteConfigServiceClient ||
273
- (config.remoteConfigAuthToken ? new config_1.HttpRemoteConfigServiceClient(config, httpClient) : null);
274
- var remoteConfigUpdater = options.remoteConfigUpdater ||
275
- (remoteConfigStorageClient && remoteConfigServiceClient
276
- ? new config_1.DefaultRemoteConfigUpdater(config, {
277
- serviceClient: remoteConfigServiceClient,
278
- storageClient: remoteConfigStorageClient,
279
- base64Utils: base64Utils,
280
- hmacUtils: hmacUtils,
281
- })
282
- : null);
283
- var allOptions = {
284
- httpClient: httpClient,
285
- base64Utils: base64Utils,
286
- hmacUtils: hmacUtils,
287
- hashUtils: hashUtils,
288
- urlUtils: urlUtils,
289
- ipRangeChecker: ipRangeChecker,
290
- cors: cors,
291
- telemetry: telemetry,
292
- dataEnrichment: dataEnrichment,
293
- graphQLParser: graphQLParser,
294
- tokenParser: tokenParser,
295
- riskApiClient: riskApiClient,
296
- activityClient: activityClient,
297
- logServiceClient: logServiceClient,
298
- remoteConfigStorageClient: remoteConfigStorageClient,
299
- remoteConfigServiceClient: remoteConfigServiceClient,
300
- remoteConfigUpdater: remoteConfigUpdater,
301
- };
302
- var products = this.initializeProducts(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
303
- return __assign({ products: products }, allOptions);
304
- };
305
- EnforcerBase.prototype.initializeProducts = function (config, products, base64Utils, hashUtils, urlUtils, ipRangeChecker) {
306
- var _a;
307
- var botDefender = (products === null || products === void 0 ? void 0 : products.bd) || new products_1.BotDefender(config, { base64Utils: base64Utils, ipRangeChecker: ipRangeChecker, urlUtils: urlUtils });
308
- var accountDefender = (products === null || products === void 0 ? void 0 : products.ad) || new products_1.AccountDefender(config, { base64Utils: base64Utils });
309
- var credentialIntelligence = config.ciEnabled
310
- ? (products === null || products === void 0 ? void 0 : products.ci) || new products_1.CredentialIntelligence(config, { hashUtils: hashUtils, urlUtils: urlUtils })
311
- : null;
312
- var hypeSaleChallenge = (products === null || products === void 0 ? void 0 : products.hsc) || new products_2.HypeSaleChallenge(config, { base64Utils: base64Utils });
313
- return _a = {},
314
- _a[products_1.ProductName.BOT_DEFENDER] = botDefender,
315
- _a[products_1.ProductName.ACCOUNT_DEFENDER] = accountDefender,
316
- _a[products_1.ProductName.CODE_DEFENDER] = products === null || products === void 0 ? void 0 : products.cd,
317
- _a[products_1.ProductName.CREDENTIAL_INTELLIGENCE] = credentialIntelligence,
318
- _a[products_1.ProductName.HYPE_SALE_CHALLENGE] = hypeSaleChallenge,
319
- _a;
320
- };
321
222
  return EnforcerBase;
322
223
  }());
323
224
  exports.EnforcerBase = EnforcerBase;
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.EnforcerBase = void 0;
18
- var EnforcerBase_1 = require("./EnforcerBase");
19
- Object.defineProperty(exports, "EnforcerBase", { enumerable: true, get: function () { return EnforcerBase_1.EnforcerBase; } });
17
+ __exportStar(require("./IEnforcer"), exports);
18
+ __exportStar(require("./EnforcerBase"), exports);
20
19
  __exportStar(require("./options"), exports);
20
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createEnforcerProducts = exports.createEnforcerInitializationBlock = void 0;
15
+ var risk_token_1 = require("../risk_token");
16
+ var config_1 = require("../config");
17
+ var cors_1 = require("../cors");
18
+ var telemetry_1 = require("../telemetry");
19
+ var pxde_1 = require("../pxde");
20
+ var graphql_1 = require("../graphql");
21
+ var risk_api_1 = require("../risk_api");
22
+ var activities_1 = require("../activities");
23
+ var logger_1 = require("../logger");
24
+ var products_1 = require("../products");
25
+ var createEnforcerInitializationBlock = function (config, options) {
26
+ var tokenVersion = options.tokenVersion, httpClient = options.httpClient, base64Utils = options.base64Utils, hmacUtils = options.hmacUtils, hashUtils = options.hashUtils, urlUtils = options.urlUtils, ipRangeChecker = options.ipRangeChecker;
27
+ var cipherUtils = tokenVersion === risk_token_1.TokenVersion.V2 ? null : options.cipherUtils;
28
+ var cors = options.cors || new cors_1.DefaultCors(config);
29
+ var telemetry = options.telemetry || new telemetry_1.DefaultTelemetry(config, httpClient, base64Utils, hmacUtils);
30
+ var dataEnrichment = options.dataEnrichment || new pxde_1.DefaultDataEnrichment(config, base64Utils, hmacUtils);
31
+ var graphQLParser = options.graphQLParser || new graphql_1.DefaultGraphQLParser(config);
32
+ var tokenParser = options.tokenParser ||
33
+ (tokenVersion === risk_token_1.TokenVersion.V2
34
+ ? new risk_token_1.DefaultTokenV2Parser(config, { base64Utils: base64Utils, hmacUtils: hmacUtils })
35
+ : new risk_token_1.DefaultTokenV3Parser(config, { cipherUtils: cipherUtils, hmacUtils: hmacUtils }));
36
+ var riskApiClient = options.riskApiClient ||
37
+ (tokenVersion === risk_token_1.TokenVersion.V2
38
+ ? new risk_api_1.PostRiskApiClientV2(config, httpClient)
39
+ : new risk_api_1.PostRiskApiClientV3(config, httpClient));
40
+ var activityClient = options.activityClient ||
41
+ (config.maxActivityBatchSize > 1
42
+ ? new activities_1.HttpBatchedActivityClient(config, httpClient)
43
+ : new activities_1.HttpActivityClient(config, httpClient));
44
+ var logServiceClient = options.logServiceClient || (config.loggerAuthToken ? new logger_1.HttpLogServiceClient(config, httpClient) : null);
45
+ var remoteConfigStorageClient = options.remoteConfigStorageClient;
46
+ var remoteConfigServiceClient = options.remoteConfigServiceClient ||
47
+ (config.remoteConfigAuthToken ? new config_1.HttpRemoteConfigServiceClient(config, httpClient) : null);
48
+ var remoteConfigUpdater = options.remoteConfigUpdater ||
49
+ (remoteConfigStorageClient && remoteConfigServiceClient
50
+ ? new config_1.DefaultRemoteConfigUpdater(config, {
51
+ serviceClient: remoteConfigServiceClient,
52
+ storageClient: remoteConfigStorageClient,
53
+ base64Utils: base64Utils,
54
+ hmacUtils: hmacUtils,
55
+ })
56
+ : null);
57
+ var allOptions = {
58
+ httpClient: httpClient,
59
+ base64Utils: base64Utils,
60
+ hmacUtils: hmacUtils,
61
+ hashUtils: hashUtils,
62
+ urlUtils: urlUtils,
63
+ ipRangeChecker: ipRangeChecker,
64
+ cors: cors,
65
+ telemetry: telemetry,
66
+ dataEnrichment: dataEnrichment,
67
+ graphQLParser: graphQLParser,
68
+ tokenParser: tokenParser,
69
+ riskApiClient: riskApiClient,
70
+ activityClient: activityClient,
71
+ logServiceClient: logServiceClient,
72
+ remoteConfigStorageClient: remoteConfigStorageClient,
73
+ remoteConfigServiceClient: remoteConfigServiceClient,
74
+ remoteConfigUpdater: remoteConfigUpdater,
75
+ };
76
+ var products = (0, exports.createEnforcerProducts)(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
77
+ return __assign({ products: products }, allOptions);
78
+ };
79
+ exports.createEnforcerInitializationBlock = createEnforcerInitializationBlock;
80
+ var createEnforcerProducts = function (config, products, base64Utils, hashUtils, urlUtils, ipRangeChecker) {
81
+ var _a;
82
+ var botDefender = (products === null || products === void 0 ? void 0 : products.bd) || new products_1.BotDefender(config, { base64Utils: base64Utils, ipRangeChecker: ipRangeChecker, urlUtils: urlUtils });
83
+ var accountDefender = (products === null || products === void 0 ? void 0 : products.ad) || new products_1.AccountDefender(config, { base64Utils: base64Utils });
84
+ var credentialIntelligence = config.ciEnabled
85
+ ? (products === null || products === void 0 ? void 0 : products.ci) || new products_1.CredentialIntelligence(config, { hashUtils: hashUtils, urlUtils: urlUtils })
86
+ : null;
87
+ var hypeSaleChallenge = (products === null || products === void 0 ? void 0 : products.hsc) || new products_1.HypeSaleChallenge(config, { base64Utils: base64Utils });
88
+ return _a = {},
89
+ _a[products_1.ProductName.BOT_DEFENDER] = botDefender,
90
+ _a[products_1.ProductName.ACCOUNT_DEFENDER] = accountDefender,
91
+ _a[products_1.ProductName.CODE_DEFENDER] = products === null || products === void 0 ? void 0 : products.cd,
92
+ _a[products_1.ProductName.CREDENTIAL_INTELLIGENCE] = credentialIntelligence,
93
+ _a[products_1.ProductName.HYPE_SALE_CHALLENGE] = hypeSaleChallenge,
94
+ _a;
95
+ };
96
+ exports.createEnforcerProducts = createEnforcerProducts;
@@ -65,6 +65,9 @@ var UrlImpl = /** @class */ (function () {
65
65
  enumerable: false,
66
66
  configurable: true
67
67
  });
68
+ UrlImpl.prototype.toJSON = function () {
69
+ return this.href;
70
+ };
68
71
  UrlImpl.prototype.isDefaultPort = function (port) {
69
72
  var PROTOCOL_TO_DEFAULT_PORT = {
70
73
  'https:': '443',
@@ -55,20 +55,18 @@ var BodyCredentialExtractor = /** @class */ (function () {
55
55
  }
56
56
  BodyCredentialExtractor.prototype.extractCredentials = function (request) {
57
57
  return __awaiter(this, void 0, void 0, function () {
58
- var contentType, credentials, e_1;
58
+ var contentType, credentials;
59
59
  return __generator(this, function (_a) {
60
60
  switch (_a.label) {
61
61
  case 0:
62
- _a.trys.push([0, 2, , 3]);
63
62
  contentType = request.headers.get(http_1.CONTENT_TYPE_HEADER_NAME);
63
+ if (!contentType) {
64
+ throw new utils_1.EnforcerError('cannot extract credentials from body without content-type!');
65
+ }
64
66
  return [4 /*yield*/, this.extractFromBody(contentType, request)];
65
67
  case 1:
66
68
  credentials = _a.sent();
67
69
  return [2 /*return*/, typeof (credentials === null || credentials === void 0 ? void 0 : credentials.user) === 'string' || typeof (credentials === null || credentials === void 0 ? void 0 : credentials.pass) === 'string' ? credentials : null];
68
- case 2:
69
- e_1 = _a.sent();
70
- return [2 /*return*/, null];
71
- case 3: return [2 /*return*/];
72
70
  }
73
71
  });
74
72
  });
@@ -43,18 +43,8 @@ var CustomCredentialExtractor = /** @class */ (function () {
43
43
  }
44
44
  CustomCredentialExtractor.prototype.extractCredentials = function (request) {
45
45
  return __awaiter(this, void 0, void 0, function () {
46
- var e_1;
47
46
  return __generator(this, function (_a) {
48
- switch (_a.label) {
49
- case 0:
50
- _a.trys.push([0, 2, , 3]);
51
- return [4 /*yield*/, this.callback(request.getUnderlyingRequest())];
52
- case 1: return [2 /*return*/, _a.sent()];
53
- case 2:
54
- e_1 = _a.sent();
55
- return [2 /*return*/, null];
56
- case 3: return [2 /*return*/];
57
- }
47
+ return [2 /*return*/, this.callback(request.getUnderlyingRequest())];
58
48
  });
59
49
  });
60
50
  };
@@ -68,7 +68,7 @@ var HypeSaleChallenge = /** @class */ (function () {
68
68
  };
69
69
  HypeSaleChallenge.prototype.isTokenHscApproved = function (_a) {
70
70
  var tokenParseResult = _a.tokenParseResult, token = _a.token;
71
- return tokenParseResult === risk_token_1.TokenParseResult.SUCCESSFUL && (token === null || token === void 0 ? void 0 : token.isValid()) && token.cpa;
71
+ return tokenParseResult === risk_token_1.TokenParseResult.SUCCESSFUL && (token === null || token === void 0 ? void 0 : token.isValidated) && token.cpa;
72
72
  };
73
73
  HypeSaleChallenge.prototype.isRiskResponseHscApproved = function (_a) {
74
74
  var riskApiCallResult = _a.riskApiCallResult, riskResponse = _a.riskResponse;
@@ -134,6 +134,20 @@ var RiskResponseBase = /** @class */ (function () {
134
134
  enumerable: false,
135
135
  configurable: true
136
136
  });
137
+ RiskResponseBase.prototype.toJSON = function () {
138
+ return {
139
+ status: this.status,
140
+ action: this.action,
141
+ message: this.message,
142
+ dataEnrichment: this.dataEnrichment,
143
+ pxhd: this.pxhd,
144
+ pxhdDomain: this.pxhdDomain,
145
+ score: this.score,
146
+ drc: this.drc,
147
+ additionalRiskInfo: this.additionalRiskInfo,
148
+ uuid: this.uuid,
149
+ };
150
+ };
137
151
  return RiskResponseBase;
138
152
  }());
139
153
  exports.RiskResponseBase = RiskResponseBase;
@@ -19,3 +19,4 @@ __exportStar(require("./RiskResponseBase"), exports);
19
19
  __exportStar(require("./CommonRiskResponsePayload"), exports);
20
20
  __exportStar(require("./v2"), exports);
21
21
  __exportStar(require("./v3"), exports);
22
+ __exportStar(require("./serialize"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializedRiskResponse = void 0;
4
+ var SerializedRiskResponse = /** @class */ (function () {
5
+ function SerializedRiskResponse(riskResponseJson) {
6
+ this.action = riskResponseJson.action;
7
+ this.additionalRiskInfo = riskResponseJson.additionalRiskInfo;
8
+ this.dataEnrichment = riskResponseJson.dataEnrichment;
9
+ this.drc = riskResponseJson.drc;
10
+ this.message = riskResponseJson.message;
11
+ this.pxhd = riskResponseJson.pxhd;
12
+ this.pxhdDomain = riskResponseJson.pxhdDomain;
13
+ this.score = riskResponseJson.score;
14
+ this.status = riskResponseJson.status;
15
+ this.uuid = riskResponseJson.uuid;
16
+ }
17
+ SerializedRiskResponse.prototype.validate = function () {
18
+ return true;
19
+ };
20
+ return SerializedRiskResponse;
21
+ }());
22
+ exports.SerializedRiskResponse = SerializedRiskResponse;
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./SerializedRiskResponse"), exports);
18
+ __exportStar(require("./RiskResponseJson"), exports);
@@ -141,7 +141,7 @@ var TokenParserBase = /** @class */ (function () {
141
141
  case 1:
142
142
  _b.originalTokenParseResult = _c.sent();
143
143
  if (mobileData.originalTokenParseResult === TokenParseResult_1.TokenParseResult.SUCCESSFUL) {
144
- mobileData.decodedOriginalToken = mobileData.originalToken.getPayloadString();
144
+ mobileData.decodedOriginalToken = mobileData.originalToken.payloadString;
145
145
  }
146
146
  return [2 /*return*/];
147
147
  }