perimeterx-js-core 0.25.0 → 0.26.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 (255) hide show
  1. package/lib/cjs/action/Action.js +15 -0
  2. package/lib/cjs/action/ActionPriorityOrder.js +4 -0
  3. package/lib/cjs/action/utils.js +20 -0
  4. package/lib/cjs/activities/HttpActivityClient.js +61 -1
  5. package/lib/cjs/activities/HttpBatchedActivityClient.js +7 -0
  6. package/lib/cjs/activities/utils.js +128 -62
  7. package/lib/cjs/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
  8. package/lib/cjs/blocker/BlockerBase.js +14 -0
  9. package/lib/cjs/blocker/JsonBlockerBase.js +5 -0
  10. package/lib/cjs/blocker/utils.js +13 -0
  11. package/lib/cjs/config/ConfigurationBase.js +17 -0
  12. package/lib/cjs/context/DefaultContext.js +4 -0
  13. package/lib/cjs/context/SerializedContext.js +5 -0
  14. package/lib/cjs/enforcer/EnforcerBase.js +61 -22
  15. package/lib/cjs/enforcer/index.js +1 -0
  16. package/lib/cjs/{phase/flow → flow}/EndEnforcerFlow.js +11 -7
  17. package/lib/cjs/{phase/flow → flow}/EnforceFlow.js +10 -15
  18. package/lib/cjs/{phase/flow → flow}/FilterFlow.js +10 -9
  19. package/lib/cjs/flow/Flow.js +60 -0
  20. package/lib/cjs/flow/IFlow.js +2 -0
  21. package/lib/cjs/{phase/flow → flow}/PostEnforceFlow.js +6 -6
  22. package/lib/cjs/{phase/flow → flow}/index.js +2 -0
  23. package/lib/cjs/index.js +1 -0
  24. package/lib/cjs/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
  25. package/lib/cjs/phase/impl/ClearLogsPhase.js +3 -0
  26. package/lib/cjs/phase/impl/CompositePhase.js +9 -0
  27. package/lib/cjs/phase/impl/CreateBlockResponsePhase.js +16 -0
  28. package/lib/cjs/phase/impl/DecideActionPhase.js +11 -0
  29. package/lib/cjs/phase/impl/EnrichContextFromRequestPhase.js +13 -9
  30. package/lib/cjs/phase/impl/EnrichContextFromResponsePhase.js +4 -0
  31. package/lib/cjs/phase/impl/FilterPhase.js +4 -0
  32. package/lib/cjs/phase/impl/FirstPartyPhase.js +5 -0
  33. package/lib/cjs/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +5 -0
  34. package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
  35. package/lib/cjs/phase/impl/ModifyIncomingRequestPhase.js +5 -0
  36. package/lib/cjs/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
  37. package/lib/cjs/phase/impl/ParseTokenPhase.js +14 -7
  38. package/lib/cjs/phase/impl/PreflightPhase.js +4 -0
  39. package/lib/cjs/phase/impl/RiskApiPhase.js +18 -7
  40. package/lib/cjs/phase/impl/{SendAsyncActivitiesOnResponsePhase.js → SendAsyncActivitiesPhase.js} +15 -8
  41. package/lib/cjs/phase/impl/SendLogsPhase.js +3 -0
  42. package/lib/cjs/phase/impl/SendTelemetryActivityPhase.js +3 -0
  43. package/lib/cjs/phase/impl/UpdateRemoteConfigPhase.js +3 -0
  44. package/lib/cjs/phase/impl/index.js +1 -2
  45. package/lib/cjs/phase/index.js +0 -1
  46. package/lib/cjs/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
  47. package/lib/cjs/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
  48. package/lib/cjs/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +3 -1
  49. package/lib/cjs/risk_api/client/GetRiskApiClientV2.js +80 -0
  50. package/lib/cjs/risk_api/client/PostRiskApiClientV2.js +3 -3
  51. package/lib/cjs/risk_api/client/PostRiskApiClientV3.js +3 -3
  52. package/lib/cjs/risk_api/client/abstract/IRiskApiClient.js +2 -0
  53. package/lib/cjs/risk_api/client/abstract/PostRiskApiClientBase.js +43 -0
  54. package/lib/cjs/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +22 -69
  55. package/lib/cjs/risk_api/client/abstract/index.js +19 -0
  56. package/lib/cjs/risk_api/client/index.js +2 -2
  57. package/lib/cjs/risk_api/index.js +1 -0
  58. package/lib/cjs/risk_api/model/GetRiskRequestHeaders.js +185 -0
  59. package/lib/cjs/risk_api/model/GetRiskResponseHeaders.js +16 -0
  60. package/lib/cjs/risk_api/model/index.js +2 -0
  61. package/lib/cjs/{phase/impl/SendAsyncActivitiesOnRequestPhase.js → risk_api/risk_response/PostRiskResponseBase.js} +26 -30
  62. package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +11 -8
  63. package/lib/cjs/risk_api/risk_response/index.js +1 -0
  64. package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
  65. package/lib/cjs/risk_api/risk_response/v2/GetRiskResponseV2.js +80 -0
  66. package/lib/cjs/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +10 -10
  67. package/lib/cjs/risk_api/risk_response/v2/index.js +2 -1
  68. package/lib/cjs/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +10 -10
  69. package/lib/cjs/risk_api/risk_response/v3/index.js +1 -1
  70. package/lib/cjs/risk_api/utils.js +36 -0
  71. package/lib/cjs/telemetry/DefaultTelemetry.js +12 -9
  72. package/lib/cjs/utils/constants.js +1 -1
  73. package/lib/cjs/utils/utils.js +1 -19
  74. package/lib/esm/action/Action.js +15 -0
  75. package/lib/esm/action/ActionPriorityOrder.js +4 -0
  76. package/lib/esm/action/utils.js +20 -0
  77. package/lib/esm/activities/HttpActivityClient.js +61 -1
  78. package/lib/esm/activities/HttpBatchedActivityClient.js +7 -0
  79. package/lib/esm/activities/utils.js +128 -63
  80. package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
  81. package/lib/esm/blocker/BlockerBase.js +14 -0
  82. package/lib/esm/blocker/JsonBlockerBase.js +5 -0
  83. package/lib/esm/blocker/utils.js +13 -0
  84. package/lib/esm/config/ConfigurationBase.js +13 -0
  85. package/lib/esm/context/DefaultContext.js +4 -0
  86. package/lib/esm/context/SerializedContext.js +5 -0
  87. package/lib/esm/enforcer/EnforcerBase.js +43 -6
  88. package/lib/esm/enforcer/index.js +1 -0
  89. package/lib/esm/flow/EndEnforcerFlow.js +18 -0
  90. package/lib/esm/flow/EnforceFlow.js +14 -0
  91. package/lib/esm/{phase/flow → flow}/FilterFlow.js +5 -4
  92. package/lib/esm/flow/Flow.js +56 -0
  93. package/lib/esm/flow/IFlow.js +1 -0
  94. package/lib/esm/flow/PostEnforceFlow.js +10 -0
  95. package/lib/esm/{phase/flow → flow}/index.js +2 -0
  96. package/lib/esm/index.js +1 -0
  97. package/lib/esm/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
  98. package/lib/esm/phase/impl/ClearLogsPhase.js +3 -0
  99. package/lib/esm/phase/impl/CompositePhase.js +9 -0
  100. package/lib/esm/phase/impl/CreateBlockResponsePhase.js +16 -1
  101. package/lib/esm/phase/impl/DecideActionPhase.js +11 -0
  102. package/lib/esm/phase/impl/EnrichContextFromRequestPhase.js +9 -0
  103. package/lib/esm/phase/impl/EnrichContextFromResponsePhase.js +4 -0
  104. package/lib/esm/phase/impl/FilterPhase.js +4 -0
  105. package/lib/esm/phase/impl/FirstPartyPhase.js +5 -0
  106. package/lib/esm/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +5 -0
  107. package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
  108. package/lib/esm/phase/impl/ModifyIncomingRequestPhase.js +5 -0
  109. package/lib/esm/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
  110. package/lib/esm/phase/impl/ParseTokenPhase.js +15 -8
  111. package/lib/esm/phase/impl/PreflightPhase.js +4 -0
  112. package/lib/esm/phase/impl/RiskApiPhase.js +19 -8
  113. package/lib/esm/phase/impl/SendAsyncActivitiesPhase.js +16 -0
  114. package/lib/esm/phase/impl/SendLogsPhase.js +3 -0
  115. package/lib/esm/phase/impl/SendTelemetryActivityPhase.js +3 -0
  116. package/lib/esm/phase/impl/UpdateRemoteConfigPhase.js +3 -0
  117. package/lib/esm/phase/impl/index.js +1 -2
  118. package/lib/esm/phase/index.js +0 -1
  119. package/lib/esm/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
  120. package/lib/esm/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
  121. package/lib/esm/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +2 -1
  122. package/lib/esm/risk_api/client/GetRiskApiClientV2.js +57 -0
  123. package/lib/esm/risk_api/client/PostRiskApiClientV2.js +3 -3
  124. package/lib/esm/risk_api/client/PostRiskApiClientV3.js +3 -3
  125. package/lib/esm/risk_api/client/abstract/IRiskApiClient.js +1 -0
  126. package/lib/esm/risk_api/client/abstract/PostRiskApiClientBase.js +18 -0
  127. package/lib/esm/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +10 -49
  128. package/lib/esm/risk_api/client/abstract/index.js +3 -0
  129. package/lib/esm/risk_api/client/index.js +2 -2
  130. package/lib/esm/risk_api/index.js +1 -0
  131. package/lib/esm/risk_api/model/GetRiskRequestHeaders.js +182 -0
  132. package/lib/esm/risk_api/model/GetRiskResponseHeaders.js +13 -0
  133. package/lib/esm/risk_api/model/index.js +2 -0
  134. package/lib/esm/risk_api/risk_response/PostRiskResponseBase.js +6 -0
  135. package/lib/esm/risk_api/risk_response/RiskResponseBase.js +5 -1
  136. package/lib/esm/risk_api/risk_response/index.js +1 -0
  137. package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
  138. package/lib/esm/risk_api/risk_response/v2/GetRiskResponseV2.js +52 -0
  139. package/lib/esm/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +2 -2
  140. package/lib/esm/risk_api/risk_response/v2/index.js +2 -1
  141. package/lib/esm/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +2 -2
  142. package/lib/esm/risk_api/risk_response/v3/index.js +1 -1
  143. package/lib/esm/risk_api/utils.js +23 -0
  144. package/lib/esm/telemetry/DefaultTelemetry.js +13 -10
  145. package/lib/esm/utils/constants.js +1 -1
  146. package/lib/esm/utils/utils.js +0 -16
  147. package/lib/types/action/Action.d.ts +15 -0
  148. package/lib/types/action/ActionData.d.ts +3 -0
  149. package/lib/types/action/ActionPriorityOrder.d.ts +4 -0
  150. package/lib/types/action/Decision.d.ts +9 -0
  151. package/lib/types/action/ProductAction.d.ts +3 -0
  152. package/lib/types/action/utils.d.ts +20 -0
  153. package/lib/types/activities/HttpActivityClient.d.ts +57 -1
  154. package/lib/types/activities/HttpBatchedActivityClient.d.ts +7 -0
  155. package/lib/types/activities/IActivityClient.d.ts +4 -1
  156. package/lib/types/activities/model/AsyncActivity.d.ts +3 -0
  157. package/lib/types/activities/model/AsyncActivityDetails.d.ts +12 -0
  158. package/lib/types/activities/model/CommonActivityDetails.d.ts +3 -0
  159. package/lib/types/activities/utils.d.ts +14 -0
  160. package/lib/types/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +6 -0
  161. package/lib/types/blocker/BlockerBase.d.ts +21 -0
  162. package/lib/types/blocker/IBlocker.d.ts +8 -0
  163. package/lib/types/blocker/IConditionalBlocker.d.ts +4 -0
  164. package/lib/types/blocker/JsonBlockerBase.d.ts +12 -0
  165. package/lib/types/blocker/model/BlockData.d.ts +3 -0
  166. package/lib/types/blocker/utils.d.ts +13 -0
  167. package/lib/types/config/ConfigurationBase.d.ts +22 -0
  168. package/lib/types/config/IConfiguration.d.ts +4 -0
  169. package/lib/types/config/params/CoreConfigurationParams.d.ts +21 -0
  170. package/lib/types/config/params/RemoteConfigurationParams.d.ts +3 -0
  171. package/lib/types/config/params/StaticConfigurationParams.d.ts +3 -0
  172. package/lib/types/context/ContextJson.d.ts +4 -0
  173. package/lib/types/context/DefaultContext.d.ts +4 -0
  174. package/lib/types/context/SerializedContext.d.ts +5 -0
  175. package/lib/types/custom_parameters/CustomParameters.d.ts +3 -0
  176. package/lib/types/enforcer/EnforcerBase.d.ts +48 -12
  177. package/lib/types/enforcer/IEnforcer.d.ts +1 -2
  178. package/lib/types/enforcer/IPostEnforcer.d.ts +3 -0
  179. package/lib/types/enforcer/index.d.ts +1 -0
  180. package/lib/types/first_party/IFirstParty.d.ts +1 -1
  181. package/lib/types/flow/EndEnforcerFlow.d.ts +8 -0
  182. package/lib/types/flow/EnforceFlow.d.ts +8 -0
  183. package/lib/types/{phase/flow → flow}/FilterFlow.d.ts +7 -7
  184. package/lib/types/flow/Flow.d.ts +13 -0
  185. package/lib/types/flow/IFlow.d.ts +57 -0
  186. package/lib/types/flow/PostEnforceFlow.d.ts +6 -0
  187. package/lib/types/{phase/flow → flow}/index.d.ts +2 -0
  188. package/lib/types/index.d.ts +1 -0
  189. package/lib/types/phase/IPhase.d.ts +9 -0
  190. package/lib/types/phase/PhaseResult.d.ts +11 -0
  191. package/lib/types/phase/impl/AdditionalActivityHandlerPhase.d.ts +3 -0
  192. package/lib/types/phase/impl/ClearLogsPhase.d.ts +3 -0
  193. package/lib/types/phase/impl/CompositePhase.d.ts +9 -0
  194. package/lib/types/phase/impl/CreateBlockResponsePhase.d.ts +11 -1
  195. package/lib/types/phase/impl/DecideActionPhase.d.ts +11 -0
  196. package/lib/types/phase/impl/EnrichContextFromRequestPhase.d.ts +9 -0
  197. package/lib/types/phase/impl/EnrichContextFromResponsePhase.d.ts +4 -0
  198. package/lib/types/phase/impl/FilterPhase.d.ts +4 -0
  199. package/lib/types/phase/impl/FirstPartyPhase.d.ts +5 -0
  200. package/lib/types/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.d.ts +5 -0
  201. package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +5 -0
  202. package/lib/types/phase/impl/ModifyIncomingRequestPhase.d.ts +5 -0
  203. package/lib/types/phase/impl/ModifyOutgoingResponsePhase.d.ts +5 -0
  204. package/lib/types/phase/impl/ParseTokenPhase.d.ts +3 -0
  205. package/lib/types/phase/impl/PreflightPhase.d.ts +4 -0
  206. package/lib/types/phase/impl/RiskApiPhase.d.ts +5 -0
  207. package/lib/types/phase/impl/{SendAsyncActivitiesOnResponsePhase.d.ts → SendAsyncActivitiesPhase.d.ts} +5 -2
  208. package/lib/types/phase/impl/SendLogsPhase.d.ts +3 -0
  209. package/lib/types/phase/impl/SendTelemetryActivityPhase.d.ts +3 -0
  210. package/lib/types/phase/impl/UpdateRemoteConfigPhase.d.ts +3 -0
  211. package/lib/types/phase/impl/index.d.ts +1 -2
  212. package/lib/types/phase/index.d.ts +0 -1
  213. package/lib/types/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
  214. package/lib/types/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.d.ts +1 -1
  215. package/lib/types/products/interfaces/IProduct.d.ts +28 -0
  216. package/lib/types/products/interfaces/ProductDataType.d.ts +1 -1
  217. package/lib/types/risk_api/client/GetRiskApiClientV2.d.ts +15 -0
  218. package/lib/types/risk_api/client/PostRiskApiClientV2.d.ts +1 -1
  219. package/lib/types/risk_api/client/PostRiskApiClientV3.d.ts +2 -2
  220. package/lib/types/risk_api/client/{IRiskApiClient.d.ts → abstract/IRiskApiClient.d.ts} +1 -1
  221. package/lib/types/risk_api/client/abstract/PostRiskApiClientBase.d.ts +8 -0
  222. package/lib/types/risk_api/client/abstract/RiskApiClientBase.d.ts +26 -0
  223. package/lib/types/risk_api/client/abstract/index.d.ts +3 -0
  224. package/lib/types/risk_api/client/index.d.ts +2 -2
  225. package/lib/types/risk_api/index.d.ts +1 -0
  226. package/lib/types/risk_api/model/GetRiskRequestHeaders.d.ts +17 -0
  227. package/lib/types/risk_api/model/GetRiskResponseHeaders.d.ts +3 -0
  228. package/lib/types/risk_api/model/index.d.ts +2 -0
  229. package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +2 -0
  230. package/lib/types/risk_api/risk_response/PostRiskResponseBase.d.ts +7 -0
  231. package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +3 -1
  232. package/lib/types/risk_api/risk_response/index.d.ts +1 -0
  233. package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
  234. package/lib/types/risk_api/risk_response/v2/GetRiskResponseV2.d.ts +11 -0
  235. package/lib/types/risk_api/risk_response/{v3/DefaultRiskResponseV3.d.ts → v2/PostRiskResponseV2.d.ts} +2 -2
  236. package/lib/types/risk_api/risk_response/v2/index.d.ts +2 -1
  237. package/lib/types/risk_api/risk_response/{v2/DefaultRiskResponseV2.d.ts → v3/PostRiskResponseV3.d.ts} +2 -2
  238. package/lib/types/risk_api/risk_response/v3/index.d.ts +1 -1
  239. package/lib/types/risk_api/utils.d.ts +69 -0
  240. package/lib/types/telemetry/model/TelemetryActivity.d.ts +1 -1
  241. package/lib/types/utils/constants.d.ts +1 -1
  242. package/lib/types/utils/utils.d.ts +0 -5
  243. package/package.json +1 -1
  244. package/lib/esm/phase/flow/EndEnforcerFlow.js +0 -14
  245. package/lib/esm/phase/flow/EnforceFlow.js +0 -18
  246. package/lib/esm/phase/flow/PostEnforceFlow.js +0 -10
  247. package/lib/esm/phase/impl/SendAsyncActivitiesOnRequestPhase.js +0 -16
  248. package/lib/esm/phase/impl/SendAsyncActivitiesOnResponsePhase.js +0 -10
  249. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +0 -8
  250. package/lib/types/phase/flow/EnforceFlow.d.ts +0 -8
  251. package/lib/types/phase/flow/PostEnforceFlow.d.ts +0 -6
  252. package/lib/types/phase/impl/SendAsyncActivitiesOnRequestPhase.d.ts +0 -10
  253. package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +0 -40
  254. /package/lib/cjs/{risk_api/client/IRiskApiClient.js → enforcer/IPostEnforcer.js} +0 -0
  255. /package/lib/esm/{risk_api/client/IRiskApiClient.js → enforcer/IPostEnforcer.js} +0 -0
@@ -1,4 +1,5 @@
1
1
  export * from './IEnforcer.js';
2
+ export * from './IPostEnforcer.js';
2
3
  export * from './EnforcerBase.js';
3
4
  export * from './EnforcerOptions.js';
4
5
  export * from './utils.js';
@@ -0,0 +1,18 @@
1
+ import { ClearLogsPhase, SendLogsPhase, SendTelemetryActivityPhase, UpdateRemoteConfigPhase, SendAsyncActivitiesPhase, } from '../phase/index.js';
2
+ import { Flow } from './Flow.js';
3
+ export class EndEnforcerFlow extends Flow {
4
+ constructor(config, { logServiceClient, telemetry, remoteConfigManager, activityClient, }) {
5
+ const phases = [
6
+ new SendAsyncActivitiesPhase(activityClient),
7
+ new SendTelemetryActivityPhase(telemetry),
8
+ ];
9
+ if (remoteConfigManager) {
10
+ phases.push(new UpdateRemoteConfigPhase(config, remoteConfigManager));
11
+ }
12
+ if (logServiceClient) {
13
+ phases.push(new SendLogsPhase(config, logServiceClient));
14
+ }
15
+ phases.push(new ClearLogsPhase());
16
+ super(phases);
17
+ }
18
+ }
@@ -0,0 +1,14 @@
1
+ import { AdditionalActivityHandlerPhase, CreateBlockResponsePhase, EnrichContextFromRequestPhase, ModifyIncomingRequestPhase, ParseTokenPhase, RiskApiPhase, } from '../phase/index.js';
2
+ import { Flow } from './Flow.js';
3
+ export class EnforceFlow extends Flow {
4
+ constructor(config, { dataEnrichment, tokenParser, riskApiClient, cors, products, graphQLParser, }) {
5
+ super([
6
+ new ParseTokenPhase(tokenParser),
7
+ new EnrichContextFromRequestPhase(config, products, dataEnrichment, graphQLParser),
8
+ new RiskApiPhase(products, riskApiClient),
9
+ new AdditionalActivityHandlerPhase(config),
10
+ new CreateBlockResponsePhase(config, CreateBlockResponsePhase.getBlockers(products), cors),
11
+ new ModifyIncomingRequestPhase(Object.values(products)),
12
+ ]);
13
+ }
14
+ }
@@ -1,7 +1,8 @@
1
- import { ProductName } from '../../products/index.js';
2
- import { isNullOrUndefined } from '../../utils/index.js';
3
- import { CompositePhase, FilterPhase, FirstPartyPhase, PreflightPhase, IdentifyTelemetryRequestPhase, IdentifyRemoteConfigNotifyRequestPhase, } from '../impl/index.js';
4
- export class FilterFlow extends CompositePhase {
1
+ import { ProductName } from '../products/index.js';
2
+ import { isNullOrUndefined } from '../utils/index.js';
3
+ import { FilterPhase, FirstPartyPhase, PreflightPhase, IdentifyTelemetryRequestPhase, IdentifyRemoteConfigNotifyRequestPhase, } from '../phase/index.js';
4
+ import { Flow } from './Flow.js';
5
+ export class FilterFlow extends Flow {
5
6
  constructor(config, { httpClient, products, cors, telemetry, remoteConfigUpdateParser, }) {
6
7
  const phases = [];
7
8
  const firstPartyProducts = FilterFlow.getFirstPartyProducts(products);
@@ -0,0 +1,56 @@
1
+ import { CompositePhase } from '../phase/index.js';
2
+ export class Flow {
3
+ phases;
4
+ constructor(phases) {
5
+ this.phases = phases;
6
+ }
7
+ insert(phase, options) {
8
+ if (!options) {
9
+ this.phases.push(phase);
10
+ return;
11
+ }
12
+ if (options.before) {
13
+ const index = this.getIndexOfPhase(options.before);
14
+ if (index === -1) {
15
+ return;
16
+ }
17
+ this.phases.splice(index, 0, phase);
18
+ }
19
+ if (options.after) {
20
+ const index = this.getIndexOfPhase(options.after);
21
+ if (index === -1) {
22
+ return;
23
+ }
24
+ this.phases.splice(index + 1, 0, phase);
25
+ }
26
+ }
27
+ remove(name) {
28
+ const index = this.getIndexOfPhase(name);
29
+ if (index === -1) {
30
+ return;
31
+ }
32
+ this.phases.splice(index, 1);
33
+ }
34
+ replace(name, phase) {
35
+ const index = this.getIndexOfPhase(name);
36
+ if (index === -1) {
37
+ return;
38
+ }
39
+ this.phases.splice(index, 1, phase);
40
+ }
41
+ move(name, to) {
42
+ const index = this.getIndexOfPhase(name);
43
+ if (index === -1) {
44
+ return;
45
+ }
46
+ const phase = this.phases[index];
47
+ this.phases.splice(index, 1);
48
+ this.insert(phase, to);
49
+ }
50
+ getIndexOfPhase(name) {
51
+ return this.phases.findIndex((existingPhase) => existingPhase.constructor.name === name);
52
+ }
53
+ execute(context) {
54
+ return new CompositePhase(this.phases).execute(context);
55
+ }
56
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { EnrichContextFromResponsePhase, ModifyOutgoingResponsePhase } from '../phase/index.js';
2
+ import { Flow } from './Flow.js';
3
+ export class PostEnforceFlow extends Flow {
4
+ constructor(config, { products, snippetRetriever, snippetInjector, }) {
5
+ super([
6
+ new EnrichContextFromResponsePhase(config, products),
7
+ new ModifyOutgoingResponsePhase(config, Object.values(products), snippetRetriever, snippetInjector),
8
+ ]);
9
+ }
10
+ }
@@ -2,3 +2,5 @@ export * from './FilterFlow.js';
2
2
  export * from './EnforceFlow.js';
3
3
  export * from './PostEnforceFlow.js';
4
4
  export * from './EndEnforcerFlow.js';
5
+ export * from './IFlow.js';
6
+ export * from './Flow.js';
package/lib/esm/index.js CHANGED
@@ -9,6 +9,7 @@ export * from './sensitive_request/index.js';
9
9
  export * from './monitored_request/index.js';
10
10
  export * from './snippet_injection/index.js';
11
11
  export * from './cors/index.js';
12
+ export * from './flow/index.js';
12
13
  export * from './enforcer/index.js';
13
14
  export * from './filter/index.js';
14
15
  export * from './first_party/index.js';
@@ -1,4 +1,7 @@
1
1
  import { AdditionalActivityHandlerUtils } from '../../additional_activity_handler/index.js';
2
+ /**
3
+ * The `AdditionalActivityHandlerPhase` invokes the additional activity handler defined in the configuration.
4
+ */
2
5
  export class AdditionalActivityHandlerPhase {
3
6
  config;
4
7
  constructor(config) {
@@ -1,3 +1,6 @@
1
+ /**
2
+ * The `ClearLogsPhase` class deletes the context logs to free up memory.
3
+ */
1
4
  export class ClearLogsPhase {
2
5
  async execute(context) {
3
6
  context.logger.clearLogs();
@@ -1,5 +1,14 @@
1
+ /**
2
+ * The `CompositePhase` class executes a series of phases in sequence.
3
+ * It will stop executing phases as soon as one of them returns a result with `done: true`.
4
+ * It will return the result of the last phase executed or `{ done: false }`.
5
+ */
1
6
  export class CompositePhase {
2
7
  phases;
8
+ /**
9
+ * Creates a new CompositePhase instance.
10
+ * @param phases - An array of phases to be executed in sequence.
11
+ */
3
12
  constructor(phases) {
4
13
  this.phases = phases;
5
14
  }
@@ -1,7 +1,11 @@
1
1
  import { MinimalResponseUtils } from '../../http/index.js';
2
2
  import { PXHDSource, PXHDUtils } from '../../pxhd/index.js';
3
3
  import { Action } from '../../action/index.js';
4
- import { PRODUCT_PRIORITY_ORDER } from '../../products/index.js';
4
+ import { PRODUCT_PRIORITY_ORDER, ProductName } from '../../products/index.js';
5
+ /**
6
+ * `CreateBlockResponsePhase` is a phase that creates a block response for the product that recommended a block action.
7
+ * If multiple products recommended block, it will return the block response for the highest priority product.
8
+ */
5
9
  export class CreateBlockResponsePhase {
6
10
  config;
7
11
  blockers;
@@ -13,6 +17,17 @@ export class CreateBlockResponsePhase {
13
17
  this.cors = cors;
14
18
  }
15
19
  }
20
+ /**
21
+ * A static method that identifies those products that can block incoming requests and returns a map of the product name to the product instance.
22
+ * @param products - All supported products.
23
+ * @returns A mapping of those products that implement the `IConditionalBlocker` interface.
24
+ */
25
+ static getBlockers(products) {
26
+ return {
27
+ [ProductName.BOT_DEFENDER]: products[ProductName.BOT_DEFENDER],
28
+ [ProductName.HYPE_SALE_CHALLENGE]: products[ProductName.HYPE_SALE_CHALLENGE],
29
+ };
30
+ }
16
31
  async execute(context) {
17
32
  if (context.action !== Action.BLOCK) {
18
33
  return { done: false };
@@ -1,7 +1,18 @@
1
1
  import { LoggerSeverity } from '../../logger/index.js';
2
2
  import { Action, getDecisionFromContext } from '../../action/index.js';
3
3
  import { BlockAction } from '../../blocker/index.js';
4
+ /**
5
+ * `DecideActionPhase` is an abstract class that provides the protected function `updateContextDecision`.
6
+ * Phases that extend this class can use the `updateContextDecision` method to update the `context.action` and
7
+ * `context.reasons` properties based on the product data in the context. Calling this function essentially
8
+ * recalculates what action the enforcer should take and why.
9
+ */
4
10
  export class DecideActionPhase {
11
+ /**
12
+ * Updates the `action`, `reasons`, and `blockAction` properties based on the product data in the context.
13
+ * @param context - The request context.
14
+ * @protected
15
+ */
5
16
  async updateContextDecision(context) {
6
17
  const { action, reasons } = getDecisionFromContext(context);
7
18
  if (context.logger.getLoggerSeverity() === LoggerSeverity.DEBUG) {
@@ -1,5 +1,14 @@
1
1
  import { CustomParametersUtils } from '../../custom_parameters/index.js';
2
2
  import { DecideActionPhase } from './DecideActionPhase.js';
3
+ /**
4
+ * `EnrichContextFromRequestPhase` adds data to the context from the request. This includes parsing the data enrichment cookie,
5
+ * adding GraphQL data, custom parameters, and enriching the context with any product-specific data by calling each product's
6
+ * `enrichContextFromRequest` method. (As an example, this is where the Credential Intelligence product enriches the context by
7
+ * extracting login credentials and adding them to the product data of the request.) It then updates the context's final action
8
+ * and reasons based on the enriched data.
9
+ *
10
+ * Note: This phase should come after the `ParseTokenPhase`, since the Bot Defender product uses the parsed token to determine its recommended action.
11
+ */
3
12
  export class EnrichContextFromRequestPhase extends DecideActionPhase {
4
13
  config;
5
14
  products;
@@ -1,4 +1,8 @@
1
1
  import { isNullOrUndefined } from '../../utils/index.js';
2
+ /**
3
+ * `EnrichContextFromResponsePhase` enriches the context with response data. Each product's `enrichContextFromResponse`
4
+ * method is called since every product may use the response data differently.
5
+ */
2
6
  export class EnrichContextFromResponsePhase {
3
7
  config;
4
8
  products;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * The `FilterPhase` class checks if the provided filters indicate that the incoming HTTP request should be filtered from the flow.
3
+ * If any filter returns `true` for `shouldFilter`, the phase will stop further processing and return a `done` status.
4
+ */
1
5
  export class FilterPhase {
2
6
  filters;
3
7
  constructor(filters) {
@@ -1,4 +1,9 @@
1
1
  import { MinimalResponseUtils } from '../../http/index.js';
2
+ /**
3
+ * The `FirstPartyPhase` class is responsible for handling first-party requests. If a first-party request is detected,
4
+ * it will create the `FirstPartyData`, send the request to the configured endpoint using the provided HTTP client, and return
5
+ * a done status with the response. If an error occurs, it will return the default response.
6
+ */
2
7
  export class FirstPartyPhase {
3
8
  config;
4
9
  httpClient;
@@ -1,4 +1,9 @@
1
1
  import { MinimalResponseImpl } from '../../http/index.js';
2
+ /**
3
+ * The `IdentifyRemoteConfigNotifyRequestPhase` class is responsible for identifying incoming remote config update requests.
4
+ * It checks if the request is a remote config update request and, if so, parses the request and updates the context accordingly.
5
+ * Note that the remote config is not updated during this phase; that occurs in the `UpdateRemoteConfigPhase`.
6
+ */
2
7
  export class IdentifyRemoteConfigNotifyRequestPhase {
3
8
  remoteConfigUpdateParser;
4
9
  constructor(remoteConfigUpdateParser) {
@@ -1,3 +1,8 @@
1
+ /**
2
+ * The `IdentifyTelemetryRequestPhase` class is responsible for identifying incoming telemetry requests.
3
+ * It checks if the request is a telemetry request and, if so, parses the request and updates the context accordingly.
4
+ * Note that the telemetry activity is not sent during this phase; that occurs in the `SendTelemetryActivityPhase`.
5
+ */
1
6
  export class IdentifyTelemetryRequestPhase {
2
7
  telemetry;
3
8
  constructor(telemetry) {
@@ -1,3 +1,8 @@
1
+ /**
2
+ * The `ModifyIncomingRequestPhase` class is responsible for modifying the incoming HTTP request prior to forwarding the
3
+ * request to the origin server or cache. This phase invokes each product's `modifyIncomingRequest` method. (As an example,
4
+ * this is where the Credential Intelligence product adds the compromised credentials header to the request if needed.)
5
+ */
1
6
  export class ModifyIncomingRequestPhase {
2
7
  products;
3
8
  constructor(products) {
@@ -1,5 +1,10 @@
1
1
  import { PXHDSource, PXHDUtils } from '../../pxhd/index.js';
2
2
  import { CONTENT_TYPE_HEADER_NAME, ContentType } from '../../http/index.js';
3
+ /**
4
+ * The `ModifyOutgoingResponsePhase` class is responsible for modifying the outgoing HTTP response prior to returning it
5
+ * to the end user. This phase invokes each product's `modifyOutgoingResponse` method, as well as adding the PXHD cookie.
6
+ * If snippet injection is supported and enabled, it also occurs in this phase.
7
+ */
3
8
  export class ModifyOutgoingResponsePhase {
4
9
  config;
5
10
  products;
@@ -1,5 +1,8 @@
1
1
  import { TokenParseResult } from '../../risk_token/index.js';
2
- import { transferExistingProperties, VidSource } from '../../utils/index.js';
2
+ import { VidSource } from '../../utils/index.js';
3
+ /**
4
+ * The `ParseTokenPhase` class is responsible for parsing the risk token from the incoming request and updating the context.
5
+ */
3
6
  export class ParseTokenPhase {
4
7
  tokenParser;
5
8
  constructor(tokenParser) {
@@ -12,14 +15,18 @@ export class ParseTokenPhase {
12
15
  }
13
16
  addTokenDataToContext(context, tokenData) {
14
17
  Object.assign(context.tokenData, tokenData);
15
- if (tokenData.tokenParseResult === TokenParseResult.SUCCESSFUL) {
16
- transferExistingProperties(tokenData.token, context, {
17
- vid: 'vid',
18
- uuid: 'uuid',
19
- score: 'score',
20
- action: 'blockAction',
21
- });
18
+ if (tokenData.tokenParseResult === TokenParseResult.SUCCESSFUL && tokenData.token) {
19
+ if (tokenData.token.score != null) {
20
+ context.score = tokenData.token.score;
21
+ }
22
+ if (tokenData.token.action) {
23
+ context.blockAction = tokenData.token.action;
24
+ }
25
+ if (tokenData.token.uuid) {
26
+ context.uuid = tokenData.token.uuid;
27
+ }
22
28
  if (tokenData.token.vid) {
29
+ context.vid = tokenData.token.vid;
23
30
  context.vidSource = VidSource.RISK_COOKIE;
24
31
  }
25
32
  }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * The `PreflightPhase` class is responsible for handling preflight requests in CORS (Cross-Origin Resource Sharing).
3
+ * This includes filtering preflight requests or invoking the preflight custom handler if configured.
4
+ */
1
5
  export class PreflightPhase {
2
6
  corsSupportEnabled;
3
7
  filterPreflightRequestsEnabled;
@@ -1,7 +1,12 @@
1
1
  import { Action, getReasonForHighestPriorityProduct } from '../../action/index.js';
2
- import { isNullOrUndefined, transferExistingProperties } from '../../utils/index.js';
2
+ import { isNullOrUndefined } from '../../utils/index.js';
3
3
  import { PXHDSource } from '../../pxhd/index.js';
4
4
  import { DecideActionPhase } from './DecideActionPhase.js';
5
+ /**
6
+ * The `RiskApiPhase` class is responsible for making the synchronous Risk API request when necessary. If a Risk API call
7
+ * is made, it will also update the context with the Risk API response, product data (invoking each product's
8
+ * `enrichContextFromRiskApi` method), and update the context decision.
9
+ */
5
10
  export class RiskApiPhase extends DecideActionPhase {
6
11
  products;
7
12
  riskApiClient;
@@ -36,14 +41,20 @@ export class RiskApiPhase extends DecideActionPhase {
36
41
  if (!riskResponse) {
37
42
  return;
38
43
  }
39
- transferExistingProperties(riskResponse, context, {
40
- score: 'score',
41
- uuid: 'uuid',
42
- action: 'blockAction',
43
- dataEnrichment: 'pxde',
44
- telemetryRequested: 'shouldSendTelemetry',
45
- });
44
+ if (riskResponse.score != null) {
45
+ context.score = riskResponse.score;
46
+ }
47
+ if (riskResponse.action) {
48
+ context.blockAction = riskResponse.action;
49
+ }
50
+ if (riskResponse.uuid) {
51
+ context.uuid = riskResponse.uuid;
52
+ }
53
+ if (riskResponse.telemetryRequested) {
54
+ context.shouldSendTelemetry = true;
55
+ }
46
56
  if (riskResponse.dataEnrichment) {
57
+ context.pxde = riskResponse.dataEnrichment;
47
58
  context.pxdeVerified = true;
48
59
  }
49
60
  if (riskResponse.pxhd) {
@@ -0,0 +1,16 @@
1
+ import { Action } from '../../action/index.js';
2
+ /**
3
+ * The `SendAsyncActivitiesPhase` class is responsible for sending all necessary asynchronous activities based on the context.
4
+ */
5
+ export class SendAsyncActivitiesPhase {
6
+ activityClient;
7
+ constructor(activityClient) {
8
+ this.activityClient = activityClient;
9
+ }
10
+ async execute(context) {
11
+ if ([Action.PASS_REQUEST, Action.BLOCK, Action.SIMULATED_BLOCK].includes(context.action)) {
12
+ await this.activityClient.sendActivities(context);
13
+ }
14
+ return { done: false };
15
+ }
16
+ }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * The `SendLogsPhase` class is responsible for sending logs to the HUMAN logging service.
3
+ */
1
4
  export class SendLogsPhase {
2
5
  logServiceClient;
3
6
  constructor(_config, logServiceClient) {
@@ -1,3 +1,6 @@
1
+ /**
2
+ * The `SendTelemetryActivityPhase` class is responsible for sending the telemetry activity if necessary.
3
+ */
1
4
  export class SendTelemetryActivityPhase {
2
5
  telemetry;
3
6
  constructor(telemetry) {
@@ -1,3 +1,6 @@
1
+ /**
2
+ * The `UpdateRemoteConfigPhase` class is responsible for updating the remote configuration if necessary.
3
+ */
1
4
  export class UpdateRemoteConfigPhase {
2
5
  config;
3
6
  remoteConfigManager;
@@ -9,8 +9,7 @@ export * from './CreateBlockResponsePhase.js';
9
9
  export * from './ModifyIncomingRequestPhase.js';
10
10
  export * from './EnrichContextFromResponsePhase.js';
11
11
  export * from './ModifyOutgoingResponsePhase.js';
12
- export * from './SendAsyncActivitiesOnRequestPhase.js';
13
- export * from './SendAsyncActivitiesOnResponsePhase.js';
12
+ export * from './SendAsyncActivitiesPhase.js';
14
13
  export * from './AdditionalActivityHandlerPhase.js';
15
14
  export * from './CompositePhase.js';
16
15
  export * from './SendLogsPhase.js';
@@ -1,4 +1,3 @@
1
1
  export * from './IPhase.js';
2
2
  export * from './PhaseResult.js';
3
3
  export * from './impl/index.js';
4
- export * from './flow/index.js';
@@ -1,7 +1,7 @@
1
1
  export class BodyLoginSuccessfulParser {
2
2
  bodyRegex;
3
3
  constructor(regex) {
4
- this.bodyRegex = new RegExp(regex);
4
+ this.bodyRegex = regex;
5
5
  }
6
6
  async isLoginSuccessful(response) {
7
7
  return !!(await response.text()).match(this.bodyRegex);
@@ -3,7 +3,7 @@ import { BodyLoginSuccessfulParser } from './BodyLoginSuccessfulParser.js';
3
3
  import { CustomLoginSuccessfulParser } from './CustomLoginSuccessfulParser.js';
4
4
  import { HeaderLoginSuccessfulParser } from './HeaderLoginSuccessfulParser.js';
5
5
  import { StatusLoginSuccessfulParser } from './StatusLoginSuccessfulParser.js';
6
- import { EnforcerConfigurationError } from '../../../../utils/index.js';
6
+ import { convertRegexStringToRegex, EnforcerConfigurationError } from '../../../../utils/index.js';
7
7
  export class LoginSuccessfulParserFactory {
8
8
  static create(config, endpointConfig) {
9
9
  const { ciDefaultLoginSuccessfulReportingMethod, ciDefaultLoginSuccessfulBodyRegex, ciDefaultLoginSuccessfulStatus, ciDefaultLoginSuccessfulCustomCallback, ciDefaultLoginSuccessfulHeaderName, ciDefaultLoginSuccessfulHeaderValue, } = config;
@@ -13,7 +13,10 @@ export class LoginSuccessfulParserFactory {
13
13
  LoginSuccessfulReportingMethod.STATUS;
14
14
  switch (reportingMethod) {
15
15
  case LoginSuccessfulReportingMethod.BODY:
16
- return new BodyLoginSuccessfulParser(login_successful_body_regex ?? ciDefaultLoginSuccessfulBodyRegex);
16
+ const bodyRegex = login_successful_body_regex ?? ciDefaultLoginSuccessfulBodyRegex;
17
+ return new BodyLoginSuccessfulParser(typeof bodyRegex === 'string'
18
+ ? (convertRegexStringToRegex(bodyRegex) ?? new RegExp(bodyRegex))
19
+ : bodyRegex);
17
20
  case LoginSuccessfulReportingMethod.CUSTOM:
18
21
  const callback = login_successful_callback ?? ciDefaultLoginSuccessfulCustomCallback;
19
22
  if (!callback) {
@@ -1,3 +1,4 @@
1
+ import { convertRegexStringToRegex } from '../../../../utils/index.js';
1
2
  import { ExactPathEndpointMatcher } from './ExactPathEndpointMatcher.js';
2
3
  import { RegexPathEndpointMatcher } from './RegexPathEndpointMatcher.js';
3
4
  import { PathType } from './PathType.js';
@@ -5,7 +6,7 @@ export class CredentialIntelligenceEndpointMatcherFactory {
5
6
  static create({ path_type, path, method, }) {
6
7
  switch (path_type) {
7
8
  case PathType.REGEX:
8
- return new RegexPathEndpointMatcher(new RegExp(path), method.toUpperCase());
9
+ return new RegexPathEndpointMatcher(convertRegexStringToRegex(path) ?? new RegExp(path), method.toUpperCase());
9
10
  case PathType.EXACT:
10
11
  default:
11
12
  return new ExactPathEndpointMatcher(path, method.toUpperCase());
@@ -0,0 +1,57 @@
1
+ import { RiskApiClientBase } from './abstract/index.js';
2
+ import { AUTHORIZATION_HEADER_NAME, CONTENT_LENGTH_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, HttpMethod, OutgoingRequestImpl, } from '../../http/index.js';
3
+ import { GetRiskResponseV2 } from '../risk_response/index.js';
4
+ import { RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES, RISK_ACTIVITY_FIELDS_TO_HEADER_NAMES, RISK_ACTIVITY_REQUEST_FIELDS_TO_HEADER_NAMES, } from '../model/index.js';
5
+ import { createRiskApiActivity } from '../utils.js';
6
+ export class GetRiskApiClientV2 extends RiskApiClientBase {
7
+ constructor(config, httpClient) {
8
+ super(config, httpClient);
9
+ }
10
+ createRiskRequest(context) {
11
+ return new OutgoingRequestImpl({
12
+ method: HttpMethod.GET,
13
+ url: this.getRiskUrl(),
14
+ headers: this.getRiskActivityHeaders(context),
15
+ });
16
+ }
17
+ getRiskActivityHeaders(context) {
18
+ const riskHeaders = this.getRiskHeaders();
19
+ const requestHeaders = this.getRequestHeadersForRisk(context);
20
+ const riskActivityHeaders = this.riskActivityToHeaders(createRiskApiActivity(this.config, context));
21
+ return Object.assign(requestHeaders, riskActivityHeaders, riskHeaders);
22
+ }
23
+ getRequestHeadersForRisk(context) {
24
+ const HEADERS_TO_DELETE = [CONTENT_LENGTH_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, AUTHORIZATION_HEADER_NAME];
25
+ const headers = {};
26
+ Object.entries(context.requestData.headers).forEach(([key, value]) => {
27
+ if (!HEADERS_TO_DELETE.includes(key.toLowerCase())) {
28
+ headers[key] = value.concat();
29
+ }
30
+ });
31
+ return headers;
32
+ }
33
+ riskActivityToHeaders(riskActivity) {
34
+ const headers = {};
35
+ this.addHeadersFromObject(headers, riskActivity, RISK_ACTIVITY_FIELDS_TO_HEADER_NAMES);
36
+ this.addHeadersFromObject(headers, riskActivity.request, RISK_ACTIVITY_REQUEST_FIELDS_TO_HEADER_NAMES);
37
+ this.addHeadersFromObject(headers, riskActivity.additional, RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES);
38
+ return headers;
39
+ }
40
+ addHeadersFromObject(headers, object, headerNamesMap) {
41
+ Object.entries(object).forEach(([key, value]) => {
42
+ const headerConversionObject = headerNamesMap[key];
43
+ if (headerConversionObject && value != null) {
44
+ const { header, convertToString } = headerConversionObject;
45
+ const strValue = convertToString
46
+ ? convertToString(value)
47
+ : typeof value === 'string'
48
+ ? value
49
+ : `${value}`;
50
+ headers[header] = [strValue];
51
+ }
52
+ });
53
+ }
54
+ createRiskResponse(response) {
55
+ return new GetRiskResponseV2(response);
56
+ }
57
+ }
@@ -1,10 +1,10 @@
1
- import { DefaultRiskResponseV2 } from '../risk_response/index.js';
2
- import { PostRiskApiClientBase } from './PostRiskApiClientBase.js';
1
+ import { PostRiskResponseV2 } from '../risk_response/index.js';
2
+ import { PostRiskApiClientBase } from './abstract/index.js';
3
3
  export class PostRiskApiClientV2 extends PostRiskApiClientBase {
4
4
  constructor(config, httpClient) {
5
5
  super(config, httpClient);
6
6
  }
7
7
  createRiskResponse(response) {
8
- return new DefaultRiskResponseV2(response);
8
+ return new PostRiskResponseV2(response);
9
9
  }
10
10
  }
@@ -1,10 +1,10 @@
1
- import { PostRiskApiClientBase } from './PostRiskApiClientBase.js';
2
- import { DefaultRiskResponseV3 } from '../risk_response/index.js';
1
+ import { PostRiskResponseV3 } from '../risk_response/index.js';
2
+ import { PostRiskApiClientBase } from './abstract/index.js';
3
3
  export class PostRiskApiClientV3 extends PostRiskApiClientBase {
4
4
  constructor(config, httpClient) {
5
5
  super(config, httpClient);
6
6
  }
7
7
  createRiskResponse(response) {
8
- return new DefaultRiskResponseV3(response);
8
+ return new PostRiskResponseV3(response);
9
9
  }
10
10
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { RiskApiClientBase } from './RiskApiClientBase.js';
2
+ import { HttpMethod, OutgoingRequestImpl } from '../../../http/index.js';
3
+ import { createRiskApiActivity } from '../../utils.js';
4
+ import { CONTENT_TYPE_HEADER_NAME, ContentType } from '../../../http/index.js';
5
+ export class PostRiskApiClientBase extends RiskApiClientBase {
6
+ createRiskRequest(context) {
7
+ const url = this.getRiskUrl();
8
+ const headers = this.getRiskHeaders();
9
+ const body = JSON.stringify(createRiskApiActivity(this.config, context));
10
+ const method = HttpMethod.POST;
11
+ return new OutgoingRequestImpl({ url, method, headers, body });
12
+ }
13
+ getRiskHeaders() {
14
+ return Object.assign({
15
+ [CONTENT_TYPE_HEADER_NAME]: [ContentType.APPLICATION_JSON],
16
+ }, super.getRiskHeaders());
17
+ }
18
+ }