perimeterx-js-core 0.7.0 → 0.8.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 (216) hide show
  1. package/lib/action/utils.js +1 -1
  2. package/lib/activities/HttpActivityClient.d.ts +5 -5
  3. package/lib/activities/HttpActivityClient.js +28 -39
  4. package/lib/activities/HttpBatchedActivityClient.d.ts +2 -2
  5. package/lib/activities/HttpBatchedActivityClient.js +19 -32
  6. package/lib/activities/model/AsyncActivity.d.ts +14 -0
  7. package/lib/activities/model/{ActivityDetails.d.ts → AsyncActivityDetails.d.ts} +6 -23
  8. package/lib/activities/model/CommonActivityDetails.d.ts +40 -0
  9. package/lib/activities/model/CommonActivityDetails.js +1 -0
  10. package/lib/activities/model/HeaderEntry.d.ts +4 -0
  11. package/lib/activities/model/HeaderEntry.js +1 -0
  12. package/lib/activities/model/index.d.ts +4 -2
  13. package/lib/activities/model/index.js +4 -2
  14. package/lib/activities/utils.d.ts +6071 -9
  15. package/lib/activities/utils.js +111 -35
  16. package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
  17. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +4 -12
  18. package/lib/config/ConfigurationParams.d.ts +2 -1
  19. package/lib/config/DefaultConfigurations.js +1 -0
  20. package/lib/config/IConfiguration.d.ts +5 -1
  21. package/lib/config/StaticConfigurationBase.d.ts +2 -1
  22. package/lib/config/StaticConfigurationBase.js +6 -1
  23. package/lib/context/DefaultContext.d.ts +1 -1
  24. package/lib/context/DefaultContext.js +40 -8
  25. package/lib/context/interfaces/RiskApiData.d.ts +4 -0
  26. package/lib/cors/DefaultCors.js +21 -31
  27. package/lib/custom_parameters/CustomParametersUtils.js +3 -12
  28. package/lib/enforcer/EnforcerBase.d.ts +2 -1
  29. package/lib/enforcer/EnforcerBase.js +56 -57
  30. package/lib/enforcer/options/EnforcerBaseOptions.d.ts +2 -0
  31. package/lib/graphql/DefaultGraphQLParser.js +30 -39
  32. package/lib/http/index.d.ts +0 -1
  33. package/lib/http/index.js +0 -1
  34. package/lib/http/interfaces/IBody.d.ts +3 -2
  35. package/lib/http/interfaces/IIncomingRequest.d.ts +4 -0
  36. package/lib/http/interfaces/IURL.d.ts +3 -0
  37. package/lib/http/interfaces/IURLSearchParams.d.ts +9 -0
  38. package/lib/http/interfaces/IURLSearchParams.js +1 -0
  39. package/lib/http/interfaces/index.d.ts +1 -0
  40. package/lib/http/interfaces/index.js +1 -0
  41. package/lib/http/{impl → utils}/FormDataImpl.js +4 -4
  42. package/lib/http/{impl → utils}/MinimalResponseImpl.js +3 -0
  43. package/lib/http/utils/MinimalResponseUtils.js +5 -7
  44. package/lib/http/utils/MultipartFormDataUtils.js +4 -5
  45. package/lib/http/{impl → utils}/OutgoingRequestImpl.d.ts +1 -1
  46. package/lib/http/{impl → utils}/OutgoingRequestImpl.js +5 -1
  47. package/lib/http/utils/URLUtils.d.ts +7 -0
  48. package/lib/http/utils/URLUtils.js +62 -0
  49. package/lib/http/utils/UrlImpl.d.ts +18 -0
  50. package/lib/http/utils/UrlImpl.js +54 -0
  51. package/lib/http/utils/UrlSearchParamsImpl.d.ts +19 -0
  52. package/lib/http/utils/UrlSearchParamsImpl.js +116 -0
  53. package/lib/http/utils/index.d.ts +6 -0
  54. package/lib/http/utils/index.js +6 -0
  55. package/lib/{utils → impl}/base64/AtobBase64Utils.d.ts +1 -1
  56. package/lib/{utils → impl}/base64/BufferBase64Utils.d.ts +1 -1
  57. package/lib/{utils → impl}/base64/BufferBase64Utils.js +1 -1
  58. package/lib/{utils → impl}/base64/JSBase64Base64Utils.d.ts +1 -1
  59. package/lib/{utils → impl}/cipher/CryptoCipherUtils.d.ts +1 -1
  60. package/lib/impl/cipher/CryptoCipherUtils.js +18 -0
  61. package/lib/{utils → impl}/cipher/SubtleCryptoCipherUtils.d.ts +1 -2
  62. package/lib/impl/cipher/SubtleCryptoCipherUtils.js +38 -0
  63. package/lib/{utils → impl}/hash/CryptoHashUtils.d.ts +1 -2
  64. package/lib/impl/hash/CryptoHashUtils.js +10 -0
  65. package/lib/{utils → impl}/hash/CryptoJSHashUtils.d.ts +1 -2
  66. package/lib/{utils → impl}/hash/CryptoJSHashUtils.js +1 -1
  67. package/lib/{utils → impl}/hash/SubtleCryptoHashUtils.d.ts +1 -2
  68. package/lib/impl/hash/SubtleCryptoHashUtils.js +21 -0
  69. package/lib/{utils → impl}/hmac/CryptoHmacUtils.d.ts +1 -2
  70. package/lib/{utils → impl}/hmac/CryptoHmacUtils.js +2 -1
  71. package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.d.ts +1 -2
  72. package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.js +1 -1
  73. package/lib/{http/impl → impl/http}/phin/PhinHttpClient.d.ts +1 -1
  74. package/lib/impl/http/phin/PhinHttpClient.js +31 -0
  75. package/lib/{http/impl → impl/http}/phin/PhinIncomingResponse.d.ts +2 -2
  76. package/lib/impl/http/phin/PhinIncomingResponse.js +23 -0
  77. package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.d.ts +1 -1
  78. package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.d.ts +1 -1
  79. package/lib/{utils → impl}/url_parser/DefaultUrlParser.d.ts +4 -4
  80. package/lib/{utils → impl}/url_parser/DefaultUrlParser.js +9 -2
  81. package/lib/logger/HttpLogServiceClient.d.ts +17 -0
  82. package/lib/logger/HttpLogServiceClient.js +52 -0
  83. package/lib/logger/ILogServiceClient.d.ts +6 -0
  84. package/lib/logger/ILogServiceClient.js +1 -0
  85. package/lib/logger/ILogger.d.ts +6 -0
  86. package/lib/logger/LoggerBase.d.ts +6 -2
  87. package/lib/logger/LoggerBase.js +14 -1
  88. package/lib/logger/constants.d.ts +2 -0
  89. package/lib/logger/constants.js +2 -0
  90. package/lib/logger/index.d.ts +4 -0
  91. package/lib/logger/index.js +3 -0
  92. package/lib/logger/model/EnrichedLogRecord.d.ts +3 -0
  93. package/lib/logger/model/EnrichedLogRecord.js +1 -0
  94. package/lib/logger/model/LogMetadata.d.ts +9 -0
  95. package/lib/logger/model/LogMetadata.js +1 -0
  96. package/lib/logger/model/LogRecord.d.ts +6 -0
  97. package/lib/logger/model/LogRecord.js +1 -0
  98. package/lib/logger/model/index.d.ts +3 -0
  99. package/lib/logger/model/index.js +3 -0
  100. package/lib/phase/flow/EndEnforcerFlow.d.ts +6 -0
  101. package/lib/phase/flow/EndEnforcerFlow.js +10 -0
  102. package/lib/phase/flow/index.d.ts +1 -0
  103. package/lib/phase/flow/index.js +1 -0
  104. package/lib/phase/impl/AdditionalActivityHandlerPhase.js +4 -15
  105. package/lib/phase/impl/CompositePhase.js +9 -19
  106. package/lib/phase/impl/CreateBlockResponsePhase.js +24 -35
  107. package/lib/phase/impl/DecideActionPhase.js +11 -21
  108. package/lib/phase/impl/EnrichContextFromRequestPhase.js +28 -45
  109. package/lib/phase/impl/EnrichContextFromResponsePhase.js +12 -23
  110. package/lib/phase/impl/FilterPhase.js +3 -13
  111. package/lib/phase/impl/FirstPartyPhase.js +21 -32
  112. package/lib/phase/impl/ModifyIncomingRequestPhase.js +4 -14
  113. package/lib/phase/impl/ModifyOutgoingResponsePhase.js +7 -18
  114. package/lib/phase/impl/ParseTokenPhase.js +5 -15
  115. package/lib/phase/impl/PreflightPhase.js +12 -20
  116. package/lib/phase/impl/RiskApiPhase.js +24 -36
  117. package/lib/phase/impl/SendAsyncActivitiesOnRequestPhase.js +8 -20
  118. package/lib/phase/impl/SendAsyncActivitiesOnResponsePhase.js +4 -14
  119. package/lib/phase/impl/SendLogsPhase.d.ts +11 -0
  120. package/lib/phase/impl/SendLogsPhase.js +16 -0
  121. package/lib/phase/impl/TelemetryPhase.js +9 -21
  122. package/lib/phase/impl/index.d.ts +1 -0
  123. package/lib/phase/impl/index.js +1 -0
  124. package/lib/products/account_defender/AccountDefender.js +16 -35
  125. package/lib/products/bot_defender/BotDefender.js +51 -72
  126. package/lib/products/bot_defender/BotDefenderActionData.js +2 -0
  127. package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.d.ts +4 -4
  128. package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.js +5 -3
  129. package/lib/products/bot_defender/block/captcha/CaptchaBlocker.d.ts +7 -4
  130. package/lib/products/bot_defender/block/captcha/CaptchaBlocker.js +12 -8
  131. package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +1 -1
  132. package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +1 -0
  133. package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +1 -1
  134. package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +5 -4
  135. package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.d.ts +2 -2
  136. package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.js +2 -0
  137. package/lib/products/bot_defender/block/utils.js +1 -2
  138. package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +7 -1
  139. package/lib/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +51 -68
  140. package/lib/products/bot_defender/first_party/constants.d.ts +0 -4
  141. package/lib/products/bot_defender/first_party/constants.js +0 -7
  142. package/lib/products/credential_intelligence/CredentialIntelligence.js +42 -63
  143. package/lib/products/credential_intelligence/endpoint/CredentialEndpoint.js +15 -23
  144. package/lib/products/credential_intelligence/endpoint/CredentialEndpointManager.js +9 -22
  145. package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +5 -5
  146. package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +22 -33
  147. package/lib/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +8 -18
  148. package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +2 -0
  149. package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +1 -1
  150. package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +11 -16
  151. package/lib/products/credential_intelligence/endpoint/hash_protocol/MultistepHashProtocol.js +11 -21
  152. package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepAndMultistepHashProtocol.js +9 -18
  153. package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepHashProtocol.js +13 -25
  154. package/lib/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -14
  155. package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulParser.js +10 -20
  156. package/lib/products/credential_intelligence/endpoint/login_successful/HeaderLoginSuccessfulParser.js +7 -16
  157. package/lib/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +7 -6
  158. package/lib/products/credential_intelligence/endpoint/login_successful/StatusLoginSuccessfulParser.js +3 -13
  159. package/lib/products/credential_intelligence/endpoint/matcher/ExactPathEndpointMatcher.js +2 -0
  160. package/lib/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +2 -0
  161. package/lib/pxde/DefaultDataEnrichment.js +47 -61
  162. package/lib/pxhd/PXHDUtils.js +2 -2
  163. package/lib/risk_api/client/PostRiskApiClientBase.d.ts +7 -12
  164. package/lib/risk_api/client/PostRiskApiClientBase.js +70 -171
  165. package/lib/risk_api/model/RiskActivity.d.ts +5 -45
  166. package/lib/risk_api/risk_response/IRiskResponse.d.ts +1 -0
  167. package/lib/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
  168. package/lib/risk_api/risk_response/RiskResponseBase.js +20 -33
  169. package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.d.ts +1 -1
  170. package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.js +3 -5
  171. package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -0
  172. package/lib/risk_api/risk_response/v3/DefaultRiskResponseV3.js +2 -4
  173. package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -0
  174. package/lib/risk_token/parser/TokenParserBase.js +25 -36
  175. package/lib/risk_token/token/TokenBase.js +24 -29
  176. package/lib/risk_token/token/v2/DefaultTokenV2.js +34 -49
  177. package/lib/risk_token/token/v3/DefaultTokenV3.js +63 -77
  178. package/lib/telemetry/DefaultTelemetry.js +46 -58
  179. package/lib/utils/base64/index.d.ts +0 -3
  180. package/lib/utils/base64/index.js +0 -3
  181. package/lib/utils/cipher/index.d.ts +1 -3
  182. package/lib/utils/cipher/index.js +1 -2
  183. package/lib/utils/constants.d.ts +2 -1
  184. package/lib/utils/constants.js +2 -1
  185. package/lib/utils/hash/index.d.ts +0 -3
  186. package/lib/utils/hash/index.js +0 -3
  187. package/lib/utils/hmac/index.d.ts +0 -2
  188. package/lib/utils/hmac/index.js +0 -2
  189. package/lib/utils/ip_range_checker/index.d.ts +1 -2
  190. package/lib/utils/ip_range_checker/index.js +1 -1
  191. package/lib/utils/request_id_generator/index.d.ts +1 -2
  192. package/lib/utils/request_id_generator/index.js +1 -1
  193. package/lib/utils/url_parser/index.d.ts +0 -1
  194. package/lib/utils/url_parser/index.js +0 -1
  195. package/lib/utils/utils.d.ts +1 -7
  196. package/lib/utils/utils.js +3 -25
  197. package/package.json +12 -6
  198. package/lib/activities/model/Activity.d.ts +0 -13
  199. package/lib/http/impl/index.d.ts +0 -4
  200. package/lib/http/impl/index.js +0 -4
  201. package/lib/http/impl/phin/PhinHttpClient.js +0 -41
  202. package/lib/http/impl/phin/PhinIncomingResponse.js +0 -38
  203. package/lib/utils/cipher/CryptoCipherUtils.js +0 -28
  204. package/lib/utils/cipher/SubtleCryptoCipherUtils.js +0 -47
  205. package/lib/utils/hash/CryptoHashUtils.js +0 -20
  206. package/lib/utils/hash/SubtleCryptoHashUtils.js +0 -31
  207. /package/lib/activities/model/{Activity.js → AsyncActivity.js} +0 -0
  208. /package/lib/activities/model/{ActivityDetails.js → AsyncActivityDetails.js} +0 -0
  209. /package/lib/http/{impl → utils}/FormDataImpl.d.ts +0 -0
  210. /package/lib/http/{impl → utils}/MinimalResponseImpl.d.ts +0 -0
  211. /package/lib/{utils → impl}/base64/AtobBase64Utils.js +0 -0
  212. /package/lib/{utils → impl}/base64/JSBase64Base64Utils.js +0 -0
  213. /package/lib/{http/impl → impl/http}/phin/index.d.ts +0 -0
  214. /package/lib/{http/impl → impl/http}/phin/index.js +0 -0
  215. /package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.js +0 -0
  216. /package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.js +0 -0
@@ -1,24 +1,14 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class CustomCredentialExtractor {
2
+ callback;
11
3
  constructor(callback) {
12
4
  this.callback = callback;
13
5
  }
14
- extractCredentials(request) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- try {
17
- return yield this.callback(request.getUnderlyingRequest());
18
- }
19
- catch (e) {
20
- return null;
21
- }
22
- });
6
+ async extractCredentials(request) {
7
+ try {
8
+ return await this.callback(request.getUnderlyingRequest());
9
+ }
10
+ catch (e) {
11
+ return null;
12
+ }
23
13
  }
24
14
  }
@@ -1,4 +1,6 @@
1
1
  export class HeaderCredentialExtractor {
2
+ userField;
3
+ passField;
2
4
  constructor(userField, passField) {
3
5
  this.userField = userField;
4
6
  this.passField = passField;
@@ -1,6 +1,6 @@
1
+ import { DeepReadonly } from 'ts-essentials';
1
2
  import { ICredentialExtractor } from './ICredentialExtractor';
2
3
  import { Credentials } from '../../model';
3
- import { DeepReadonly } from 'ts-essentials';
4
4
  import { IIncomingRequest } from '../../../../http';
5
5
  export declare class QueryParamCredentialExtractor<Req> implements ICredentialExtractor<Req> {
6
6
  protected readonly userField: string;
@@ -1,23 +1,18 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
1
+ import { URLUtils } from '../../../../http';
10
2
  export class QueryParamCredentialExtractor {
3
+ userField;
4
+ passField;
11
5
  constructor(userField, passField) {
12
6
  this.userField = userField;
13
7
  this.passField = passField;
14
8
  }
15
- extractCredentials(request) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { searchParams } = new URL(request.url);
18
- const user = searchParams.get(this.userField);
19
- const pass = searchParams.get(this.passField);
20
- return typeof user === 'string' || typeof pass === 'string' ? { user, pass } : null;
21
- });
9
+ async extractCredentials(request) {
10
+ const { searchParams } = URLUtils.parseURL(request.url);
11
+ if (!searchParams) {
12
+ return null;
13
+ }
14
+ const user = searchParams.get(this.userField);
15
+ const pass = searchParams.get(this.passField);
16
+ return typeof user === 'string' || typeof pass === 'string' ? { user, pass } : null;
22
17
  }
23
18
  }
@@ -1,30 +1,20 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { Algorithm } from '../../../../utils';
11
2
  import { SsoStep } from './SsoStep';
12
3
  import { CredentialIntelligenceVersion } from './CredentialIntelligenceVersion';
13
4
  export class MultistepHashProtocol {
5
+ hashUtils;
14
6
  constructor(hashUtils) {
15
7
  this.hashUtils = hashUtils;
16
8
  }
17
- hashCredentials({ user, pass }) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const rawUsername = user !== null && user !== void 0 ? user : null;
20
- const hashedPassword = typeof pass === 'string' ? yield this.hashUtils.hashString(pass, Algorithm.SHA256) : null;
21
- return {
22
- rawUsername,
23
- hashedUsername: rawUsername,
24
- hashedPassword,
25
- ciVersion: CredentialIntelligenceVersion.MULTI_STEP,
26
- ssoStep: user ? SsoStep.USER : SsoStep.PASS,
27
- };
28
- });
9
+ async hashCredentials({ user, pass }) {
10
+ const rawUsername = user ?? null;
11
+ const hashedPassword = typeof pass === 'string' ? await this.hashUtils.hashString(pass, Algorithm.SHA256) : null;
12
+ return {
13
+ rawUsername,
14
+ hashedUsername: rawUsername,
15
+ hashedPassword,
16
+ ciVersion: CredentialIntelligenceVersion.MULTI_STEP,
17
+ ssoStep: user ? SsoStep.USER : SsoStep.PASS,
18
+ };
29
19
  }
30
20
  }
@@ -1,25 +1,16 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class SingleStepAndMultistepHashProtocol {
2
+ singleStepHashProtocol;
3
+ multistepHashProtocol;
11
4
  constructor(singleStepHashProtocol, multistepHashProtocol) {
12
5
  this.singleStepHashProtocol = singleStepHashProtocol;
13
6
  this.multistepHashProtocol = multistepHashProtocol;
14
7
  }
15
- hashCredentials(credentials) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- if (credentials.user && credentials.pass) {
18
- return this.singleStepHashProtocol.hashCredentials(credentials);
19
- }
20
- else {
21
- return this.multistepHashProtocol.hashCredentials(credentials);
22
- }
23
- });
8
+ async hashCredentials(credentials) {
9
+ if (credentials.user && credentials.pass) {
10
+ return this.singleStepHashProtocol.hashCredentials(credentials);
11
+ }
12
+ else {
13
+ return this.multistepHashProtocol.hashCredentials(credentials);
14
+ }
24
15
  }
25
16
  }
@@ -1,30 +1,20 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { Algorithm, isEmailAddress } from '../../../../utils';
11
2
  import { CredentialIntelligenceVersion } from './CredentialIntelligenceVersion';
12
3
  export class SingleStepHashProtocol {
4
+ hashUtils;
13
5
  constructor(hashUtils) {
14
6
  this.hashUtils = hashUtils;
15
7
  }
16
- hashCredentials({ user, pass }) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const normalizedUsername = isEmailAddress(user) ? this.normalizeEmailAddress(user) : user;
19
- const hashedUsername = yield this.sha256(normalizedUsername);
20
- const hashedPassword = yield this.sha256(hashedUsername + (yield this.sha256(pass)));
21
- return {
22
- ciVersion: CredentialIntelligenceVersion.SINGLE_STEP,
23
- rawUsername: user,
24
- hashedUsername,
25
- hashedPassword,
26
- };
27
- });
8
+ async hashCredentials({ user, pass }) {
9
+ const normalizedUsername = isEmailAddress(user) ? this.normalizeEmailAddress(user) : user;
10
+ const hashedUsername = await this.sha256(normalizedUsername);
11
+ const hashedPassword = await this.sha256(hashedUsername + (await this.sha256(pass)));
12
+ return {
13
+ ciVersion: CredentialIntelligenceVersion.SINGLE_STEP,
14
+ rawUsername: user,
15
+ hashedUsername,
16
+ hashedPassword,
17
+ };
28
18
  }
29
19
  normalizeEmailAddress(emailAddress) {
30
20
  const lowercaseEmail = emailAddress.trim().toLowerCase();
@@ -41,9 +31,7 @@ export class SingleStepHashProtocol {
41
31
  }
42
32
  return `${normalizedUsername}${domain}`;
43
33
  }
44
- sha256(text) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- return yield this.hashUtils.hashString(text, Algorithm.SHA256);
47
- });
34
+ async sha256(text) {
35
+ return await this.hashUtils.hashString(text, Algorithm.SHA256);
48
36
  }
49
37
  }
@@ -1,20 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class BodyLoginSuccessfulParser {
2
+ bodyRegex;
11
3
  constructor(regex) {
12
4
  this.bodyRegex = new RegExp(regex);
13
5
  }
14
- isLoginSuccessful(response) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- // TODO: Possibly add IBody methods to IOutgoingResponse interface?
17
- return this.bodyRegex.test(response.body);
18
- });
6
+ async isLoginSuccessful(response) {
7
+ // TODO: Possibly add IBody methods to IOutgoingResponse interface?
8
+ return this.bodyRegex.test(response.body);
19
9
  }
20
10
  }
@@ -1,26 +1,16 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class CustomLoginSuccessfulParser {
2
+ callback;
11
3
  constructor(callback) {
12
4
  this.callback = callback;
13
5
  }
14
- isLoginSuccessful(response) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- try {
17
- const retVal = yield this.callback(response.getUnderlyingResponse());
18
- return typeof retVal === 'boolean' ? retVal : null;
19
- }
20
- catch (_a) {
21
- // We cannot say definitively if the login was successful or not here
22
- return null;
23
- }
24
- });
6
+ async isLoginSuccessful(response) {
7
+ try {
8
+ const retVal = await this.callback(response.getUnderlyingResponse());
9
+ return typeof retVal === 'boolean' ? retVal : null;
10
+ }
11
+ catch {
12
+ // We cannot say definitively if the login was successful or not here
13
+ return null;
14
+ }
25
15
  }
26
16
  }
@@ -1,23 +1,14 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class HeaderLoginSuccessfulParser {
2
+ headerName;
3
+ headerValue;
11
4
  constructor(headerName, headerValue) {
12
5
  this.headerName = headerName;
13
6
  this.headerValue = headerValue || null;
14
7
  }
15
- isLoginSuccessful(response) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- if (this.headerValue) {
18
- return response.headers.get(this.headerName) === this.headerValue;
19
- }
20
- return response.headers.has(this.headerName);
21
- });
8
+ async isLoginSuccessful(response) {
9
+ if (this.headerValue) {
10
+ return response.headers.get(this.headerName) === this.headerValue;
11
+ }
12
+ return response.headers.has(this.headerName);
22
13
  }
23
14
  }
@@ -6,19 +6,20 @@ import { StatusLoginSuccessfulParser } from './StatusLoginSuccessfulParser';
6
6
  import { EnforcerError } from '../../../../utils';
7
7
  export class LoginSuccessfulParserFactory {
8
8
  static create(config, endpointConfig) {
9
- var _a;
10
9
  const { ciDefaultLoginSuccessfulReportingMethod, ciDefaultLoginSuccessfulBodyRegex, ciDefaultLoginSuccessfulStatus, ciDefaultLoginSuccessfulCustomCallback, ciDefaultLoginSuccessfulHeaderName, ciDefaultLoginSuccessfulHeaderValue, } = config;
11
10
  const { login_successful_reporting_method, login_successful_callback, login_successful_statuses, login_successful_body_regex, login_successful_header_name, login_successful_header_value, } = endpointConfig;
12
- const reportingMethod = (_a = login_successful_reporting_method !== null && login_successful_reporting_method !== void 0 ? login_successful_reporting_method : ciDefaultLoginSuccessfulReportingMethod) !== null && _a !== void 0 ? _a : LoginSuccessfulReportingMethod.STATUS;
11
+ const reportingMethod = login_successful_reporting_method ??
12
+ ciDefaultLoginSuccessfulReportingMethod ??
13
+ LoginSuccessfulReportingMethod.STATUS;
13
14
  switch (reportingMethod) {
14
15
  case LoginSuccessfulReportingMethod.BODY:
15
- return new BodyLoginSuccessfulParser(login_successful_body_regex !== null && login_successful_body_regex !== void 0 ? login_successful_body_regex : ciDefaultLoginSuccessfulBodyRegex);
16
+ return new BodyLoginSuccessfulParser(login_successful_body_regex ?? ciDefaultLoginSuccessfulBodyRegex);
16
17
  case LoginSuccessfulReportingMethod.CUSTOM:
17
- return new CustomLoginSuccessfulParser(login_successful_callback !== null && login_successful_callback !== void 0 ? login_successful_callback : ciDefaultLoginSuccessfulCustomCallback);
18
+ return new CustomLoginSuccessfulParser(login_successful_callback ?? ciDefaultLoginSuccessfulCustomCallback);
18
19
  case LoginSuccessfulReportingMethod.HEADER:
19
- return new HeaderLoginSuccessfulParser(login_successful_header_name !== null && login_successful_header_name !== void 0 ? login_successful_header_name : ciDefaultLoginSuccessfulHeaderName, login_successful_header_value !== null && login_successful_header_value !== void 0 ? login_successful_header_value : ciDefaultLoginSuccessfulHeaderValue);
20
+ return new HeaderLoginSuccessfulParser(login_successful_header_name ?? ciDefaultLoginSuccessfulHeaderName, login_successful_header_value ?? ciDefaultLoginSuccessfulHeaderValue);
20
21
  case LoginSuccessfulReportingMethod.STATUS:
21
- return new StatusLoginSuccessfulParser(login_successful_statuses !== null && login_successful_statuses !== void 0 ? login_successful_statuses : ciDefaultLoginSuccessfulStatus);
22
+ return new StatusLoginSuccessfulParser(login_successful_statuses ?? ciDefaultLoginSuccessfulStatus);
22
23
  default:
23
24
  throw new EnforcerError('unknown login successful reporting method defined');
24
25
  }
@@ -1,19 +1,9 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class StatusLoginSuccessfulParser {
2
+ statuses;
11
3
  constructor(statuses) {
12
4
  this.statuses = statuses;
13
5
  }
14
- isLoginSuccessful(response) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- return this.statuses.includes(response.status);
17
- });
6
+ async isLoginSuccessful(response) {
7
+ return this.statuses.includes(response.status);
18
8
  }
19
9
  }
@@ -1,4 +1,6 @@
1
1
  export class ExactPathEndpointMatcher {
2
+ pathname;
3
+ method;
2
4
  constructor(pathname, method) {
3
5
  this.pathname = pathname;
4
6
  this.method = method;
@@ -1,4 +1,6 @@
1
1
  export class RegexPathEndpointMatcher {
2
+ pathnameRegex;
3
+ method;
2
4
  constructor(pathname, method) {
3
5
  this.pathnameRegex = pathname;
4
6
  this.method = method;
@@ -1,74 +1,60 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { Algorithm, PXDE_COOKIE_NAME } from '../utils';
11
2
  import { PXDE_COOKIE_DELIMITER, PXDE_COOKIE_PARTS_COUNT, PXDE_HMAC_INDEX, PXDE_PAYLOAD_INDEX } from './constants';
12
3
  export class DefaultDataEnrichment {
4
+ config;
5
+ base64Utils;
6
+ hmacUtils;
13
7
  constructor(config, base64Utils, hmacUtils) {
14
8
  this.config = config;
15
9
  this.base64Utils = base64Utils;
16
10
  this.hmacUtils = hmacUtils;
17
11
  }
18
- handlePxde(context) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- try {
21
- const pxdeCookie = context.requestData.cookies[PXDE_COOKIE_NAME];
22
- if (pxdeCookie) {
23
- return yield this.parsePxde(pxdeCookie);
24
- }
25
- }
26
- catch (e) {
27
- this.config.logger.debug(`unable to parse pxde cookie - ${e}`);
28
- }
29
- return null;
30
- });
12
+ async handlePxde(context) {
13
+ try {
14
+ const pxdeCookie = context.requestData.cookies[PXDE_COOKIE_NAME];
15
+ if (pxdeCookie) {
16
+ return await this.parsePxde(pxdeCookie);
17
+ }
18
+ }
19
+ catch (e) {
20
+ this.config.logger.debug(`unable to parse pxde cookie - ${e}`);
21
+ }
22
+ return null;
31
23
  }
32
- parsePxde(pxdeCookie) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const pxdeParts = pxdeCookie.split(PXDE_COOKIE_DELIMITER);
35
- if (pxdeParts.length !== PXDE_COOKIE_PARTS_COUNT) {
36
- this.config.logger.debug(`malformed pxde cookie: ${pxdeCookie}`);
37
- return null;
38
- }
39
- const hmac = pxdeParts[PXDE_HMAC_INDEX];
40
- const encodedPayload = pxdeParts[PXDE_PAYLOAD_INDEX];
41
- if (!hmac || !encodedPayload) {
42
- this.config.logger.debug(`malformed pxde cookie: hmac: ${hmac}, payload: ${encodedPayload}`);
43
- return null;
44
- }
45
- return {
46
- pxde: yield this.parsePxdePayload(encodedPayload),
47
- pxdeVerified: yield this.verifyPxdeHmac(hmac, encodedPayload),
48
- };
49
- });
24
+ async parsePxde(pxdeCookie) {
25
+ const pxdeParts = pxdeCookie.split(PXDE_COOKIE_DELIMITER);
26
+ if (pxdeParts.length !== PXDE_COOKIE_PARTS_COUNT) {
27
+ this.config.logger.debug(`malformed pxde cookie: ${pxdeCookie}`);
28
+ return null;
29
+ }
30
+ const hmac = pxdeParts[PXDE_HMAC_INDEX];
31
+ const encodedPayload = pxdeParts[PXDE_PAYLOAD_INDEX];
32
+ if (!hmac || !encodedPayload) {
33
+ this.config.logger.debug(`malformed pxde cookie: hmac: ${hmac}, payload: ${encodedPayload}`);
34
+ return null;
35
+ }
36
+ return {
37
+ pxde: await this.parsePxdePayload(encodedPayload),
38
+ pxdeVerified: await this.verifyPxdeHmac(hmac, encodedPayload),
39
+ };
50
40
  }
51
- verifyPxdeHmac(givenHmac, encodedPayload) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- try {
54
- return givenHmac === this.hmacUtils.createHmac(Algorithm.SHA256, encodedPayload, this.config.cookieSecret);
55
- }
56
- catch (e) {
57
- this.config.logger.debug(`failed verifying pxde hmac: ${e}`);
58
- return false;
59
- }
60
- });
41
+ async verifyPxdeHmac(givenHmac, encodedPayload) {
42
+ try {
43
+ return givenHmac === this.hmacUtils.createHmac(Algorithm.SHA256, encodedPayload, this.config.cookieSecret);
44
+ }
45
+ catch (e) {
46
+ this.config.logger.debug(`failed verifying pxde hmac: ${e}`);
47
+ return false;
48
+ }
61
49
  }
62
- parsePxdePayload(encodedPayload) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- try {
65
- const decodedPayload = this.base64Utils.base64Decode(encodedPayload);
66
- return JSON.parse(decodedPayload);
67
- }
68
- catch (e) {
69
- this.config.logger.debug(`failed parsing pxde payload: ${e}`);
70
- return null;
71
- }
72
- });
50
+ async parsePxdePayload(encodedPayload) {
51
+ try {
52
+ const decodedPayload = this.base64Utils.base64Decode(encodedPayload);
53
+ return JSON.parse(decodedPayload);
54
+ }
55
+ catch (e) {
56
+ this.config.logger.debug(`failed parsing pxde payload: ${e}`);
57
+ return null;
58
+ }
73
59
  }
74
60
  }
@@ -5,14 +5,14 @@ export var PXHDUtils;
5
5
  PXHDUtils.PXHD_SAMESITE_VALUE = 'Lax';
6
6
  PXHDUtils.PXHD_PATH_VALUE = '/';
7
7
  PXHDUtils.addPxhdToOutgoingResponse = (context, response) => {
8
- if (!(context === null || context === void 0 ? void 0 : context.pxhd)) {
8
+ if (!context?.pxhd) {
9
9
  return;
10
10
  }
11
11
  const setPxhdCookie = PXHDUtils.getPxhdCookieValue(context.pxhd);
12
12
  response.headers.append(SET_COOKIE_HEADER_NAME, setPxhdCookie);
13
13
  };
14
14
  PXHDUtils.addPxhdToMinimalResponse = (context, response) => {
15
- if (context === null || context === void 0 ? void 0 : context.pxhd) {
15
+ if (context?.pxhd) {
16
16
  const setPxhdCookie = PXHDUtils.getPxhdCookieValue(context.pxhd);
17
17
  return MinimalResponseUtils.appendHeader(response, SET_COOKIE_HEADER_NAME, setPxhdCookie);
18
18
  }
@@ -1,6 +1,7 @@
1
1
  import { ReadonlyContext, RiskApiData } from '../../context';
2
2
  import { IConfiguration } from '../../config';
3
- import { IHttpClient, IIncomingResponse } from '../../http';
3
+ import { IHttpClient, IIncomingResponse, ReadonlyHeaders } from '../../http';
4
+ import { HeaderEntry } from '../../activities';
4
5
  import { RiskActivity } from '../model';
5
6
  import { IRiskResponse } from '../risk_response';
6
7
  import { IRiskApiClient } from './IRiskApiClient';
@@ -29,16 +30,10 @@ export declare abstract class PostRiskApiClientBase<Req, Res> implements IRiskAp
29
30
  * @protected
30
31
  */
31
32
  protected finalizeRiskActivity(riskActivity: RiskActivity): RiskActivity;
32
- private addOptionalRiskFields;
33
- private addOptionalRiskFieldsToRoot;
34
- private addOptionalRiskFieldsToAdditional;
35
- private addProductDataToAdditional;
36
- private addCustomParamsToAdditional;
37
- private addTokenDataToAdditional;
38
- private formatRiskHeadersField;
33
+ protected formatRiskHeadersField(headers: ReadonlyHeaders): HeaderEntry[];
39
34
  protected sendRiskActivity(riskActivity: RiskActivity, riskApiData: RiskApiData): Promise<IIncomingResponse>;
40
- private getRiskUrl;
41
- private getRiskHeaders;
42
- private handleS2STimeout;
43
- private handleS2SError;
35
+ protected getRiskUrl(): string;
36
+ protected getRiskHeaders(): ReadonlyHeaders;
37
+ protected handleS2STimeout(riskApiData: RiskApiData): RiskApiData;
38
+ protected handleS2SError(riskApiData: RiskApiData, response: IIncomingResponse, error?: Error): Promise<RiskApiData>;
44
39
  }