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,9 +1,19 @@
1
1
  import { Action } from './Action.js';
2
2
  import { PRODUCT_PRIORITY_ORDER } from '../products/index.js';
3
3
  import { ACTION_PRIORITY_ORDER } from './ActionPriorityOrder.js';
4
+ /**
5
+ * Determines the final decision from the context.
6
+ * @param context - The request context.
7
+ * @returns Decision - The final action that should be taken and the associated products and reasons responsible for the decision.
8
+ */
4
9
  export const getDecisionFromContext = (context) => {
5
10
  return getDecisionFromActions(getProductActions(context));
6
11
  };
12
+ /**
13
+ * Determines all product recommended actions from the context.
14
+ * @param context - The request context.
15
+ * @returns ProductAction[] - An array of objects, representing the recommended action and reason of all relevant products.
16
+ */
7
17
  export const getProductActions = (context) => {
8
18
  return Object.entries(context.productData)
9
19
  .filter(([_, data]) => data?.action != null && data?.reason != null)
@@ -13,6 +23,11 @@ export const getProductActions = (context) => {
13
23
  productName: productName,
14
24
  }));
15
25
  };
26
+ /**
27
+ * Reduces a list of ProductActions to a single Decision, taking into consideration the ACTION_PRIORITY_ORDER.
28
+ * @param productActions - All possible actions from all products.
29
+ * @returns Decision - The final action that should be taken and the associated products and reasons responsible for the decision.
30
+ */
16
31
  export const getDecisionFromActions = (productActions) => {
17
32
  return createDecision(reduce(productActions));
18
33
  };
@@ -33,6 +48,11 @@ const createDecision = (tally) => {
33
48
  }
34
49
  return { action: Action.PASS_REQUEST, reasons: {} };
35
50
  };
51
+ /**
52
+ * Provided a mapping of product names to reasons, returns the reason associated with the highest priority product in the mapping.
53
+ * @param reasons - An object mapping any product names to their associated reasons.
54
+ * @returns string - The reason for the highest priority product, or 'unknown_reason' if none is found.
55
+ */
36
56
  export const getReasonForHighestPriorityProduct = (reasons) => {
37
57
  for (let productName of PRODUCT_PRIORITY_ORDER) {
38
58
  const reason = reasons[productName];
@@ -4,16 +4,33 @@ import { getAuthorizationHeader } from '../utils/index.js';
4
4
  import { ActivityType } from './ActivityType.js';
5
5
  import { createAsyncActivity } from './utils.js';
6
6
  import { ACTIVITIES_ENDPOINT } from './constants.js';
7
+ /**
8
+ * The HttpActivityClient is responsible for sending async activities to the backend via HTTP.
9
+ */
7
10
  export class HttpActivityClient {
8
11
  config;
9
12
  httpClient;
13
+ /**
14
+ * Creates an instance of HttpActivityClient.
15
+ * @param config
16
+ * @param httpClient
17
+ */
10
18
  constructor(config, httpClient) {
11
19
  this.config = config;
12
20
  this.httpClient = httpClient;
13
21
  }
22
+ /**
23
+ * Creates and sends all necessary async activities to the backend.
24
+ * @param context - The context containing the request (and possibly response).
25
+ * @returns {Promise<boolean>} - A boolean indicating if the activities were sent successfully.
26
+ */
14
27
  async sendActivities(context) {
15
28
  try {
16
29
  const activities = this.createActivities(context);
30
+ if (!activities || activities.length === 0) {
31
+ context.logger.debug('no activities to send');
32
+ return true;
33
+ }
17
34
  return await this.postActivities(activities, context.logger);
18
35
  }
19
36
  catch (e) {
@@ -21,6 +38,12 @@ export class HttpActivityClient {
21
38
  return false;
22
39
  }
23
40
  }
41
+ /**
42
+ * Creates all async activities (block, page_requested, additional_s2s) that should be sent based on the context.
43
+ * @param context - The context containing the request (and possibly response).
44
+ * @returns {AsyncActivity[]} - An array of async activities to be sent.
45
+ * @protected
46
+ */
24
47
  createActivities(context) {
25
48
  const activities = [];
26
49
  if (this.shouldCreateBlockActivity(context)) {
@@ -34,28 +57,58 @@ export class HttpActivityClient {
34
57
  }
35
58
  return activities.map(this.finalizeActivity);
36
59
  }
60
+ /**
61
+ * Whether to create a block activity based on the context.
62
+ * @param context
63
+ * @protected
64
+ */
37
65
  shouldCreateBlockActivity(context) {
38
66
  return context.action === Action.BLOCK || context.action === Action.SIMULATED_BLOCK;
39
67
  }
68
+ /**
69
+ * Whether to create a page_requested activity based on the context.
70
+ * @param context
71
+ * @protected
72
+ */
40
73
  shouldCreatePageRequestedActivity(context) {
41
74
  return context.action === Action.PASS_REQUEST;
42
75
  }
76
+ /**
77
+ * Whether to create an additional_s2s activity based on the context.
78
+ * @param context
79
+ * @protected
80
+ */
43
81
  shouldCreateAdditionalS2SActivity(context) {
44
82
  return (this.shouldCreatePageRequestedActivity(context) &&
45
83
  !!context.productData.ci &&
46
84
  this.config.ciAutomaticAdditionalS2SEnabled);
47
85
  }
86
+ /**
87
+ * Creates a block activity based on the context.
88
+ * @param context
89
+ * @protected
90
+ */
48
91
  createBlockActivity(context) {
49
92
  return createAsyncActivity(ActivityType.BLOCK, this.config, context);
50
93
  }
94
+ /**
95
+ * Creates a page_requested activity based on the context.
96
+ * @param context
97
+ * @protected
98
+ */
51
99
  createPageRequestedActivity(context) {
52
100
  return createAsyncActivity(ActivityType.PAGE_REQUESTED, this.config, context);
53
101
  }
102
+ /**
103
+ * Creates an additional_s2s activity based on the context.
104
+ * @param context
105
+ * @protected
106
+ */
54
107
  createAdditionalS2SActivity(context) {
55
108
  return createAsyncActivity(ActivityType.ADDITIONAL_S2S, this.config, context);
56
109
  }
57
110
  /**
58
- * Allows for expansions or alterations to the async activity if needed.
111
+ * Allows for expansions or alterations to an async activity if needed. This applies to all created async activities.
59
112
  * @param activity
60
113
  * @returns AsyncActivity
61
114
  * @protected
@@ -63,6 +116,13 @@ export class HttpActivityClient {
63
116
  finalizeActivity(activity) {
64
117
  return activity;
65
118
  }
119
+ /**
120
+ * Sends the async activities to the backend.
121
+ * @param activities - The activities to be sent.
122
+ * @param logger - The logger instance for logging.
123
+ * @returns {Promise<boolean>} - A boolean indicating if the activities were sent successfully.
124
+ * @protected
125
+ */
66
126
  async postActivities(activities, logger) {
67
127
  const url = `${this.config.backendCollectorUrl}${ACTIVITIES_ENDPOINT}`;
68
128
  const method = HttpMethod.POST;
@@ -1,4 +1,11 @@
1
1
  import { HttpActivityClient } from './HttpActivityClient.js';
2
+ /**
3
+ * The HttpBatchedActivityClient is responsible for sending async activities to the backend via HTTP in batches.
4
+ * It extends the HttpActivityClient class and adds functionality for batching activities.
5
+ *
6
+ * This class uses setTimeout and clearTimeout for managing the timeout for sending activities. It also exposes the stop()
7
+ * method to stop the timer and prevent further activity sending, which should be called on shutdown.
8
+ */
2
9
  export class HttpBatchedActivityClient extends HttpActivityClient {
3
10
  batchSize;
4
11
  timeoutMs;
@@ -1,8 +1,15 @@
1
- import { EnforcerError, ModuleMode, removeSensitiveHeaders, transferExistingProperties } from '../utils/index.js';
1
+ import { EnforcerError, ModuleMode, removeSensitiveHeaders } from '../utils/index.js';
2
2
  import { ProductName } from '../products/index.js';
3
3
  import { Action, getReasonForHighestPriorityProduct } from '../action/index.js';
4
4
  import { ActivityType } from './ActivityType.js';
5
5
  import { TokenParseResult } from '../risk_token/index.js';
6
+ /**
7
+ * Creates an async activity object based on the provided parameters.
8
+ * @param activityType - The activity type to create.
9
+ * @param config - The enforcer configuration.
10
+ * @param context - The request context.
11
+ * @returns {AsyncActivity} - The complete async activity payload.
12
+ */
6
13
  export const createAsyncActivity = (activityType, config, context) => {
7
14
  return {
8
15
  type: activityType,
@@ -18,6 +25,13 @@ export const createAsyncActivity = (activityType, config, context) => {
18
25
  details: createActivityDetails(activityType, config, context),
19
26
  };
20
27
  };
28
+ /**
29
+ * Creates activity details based on the provided parameters.
30
+ * @param activityType - The activity type to create.
31
+ * @param config - The enforcer configuration.
32
+ * @param context - The request context.
33
+ * @returns {AsyncActivityDetails} - The activity details.
34
+ */
21
35
  export const createActivityDetails = (activityType, config, context) => {
22
36
  const commonActivityDetails = createCommonActivityDetails(config, context);
23
37
  const commonAsyncActivityDetails = createAsyncActivityCommonDetails(context);
@@ -60,13 +74,21 @@ export const createCommonActivityDetails = (config, context) => {
60
74
  return details;
61
75
  };
62
76
  export const addRootContextDataToDetails = (details, context) => {
63
- transferExistingProperties(context, details, {
64
- requestId: 'request_id',
65
- tokenOrigin: 'cookie_origin',
66
- vidSource: 'enforcer_vid_source',
67
- graphqlData: 'graphql_operations',
68
- enforcerStartTime: 'enforcer_start_time',
69
- });
77
+ if (context.requestId) {
78
+ details.request_id = context.requestId;
79
+ }
80
+ if (context.tokenOrigin) {
81
+ details.cookie_origin = context.tokenOrigin;
82
+ }
83
+ if (context.vidSource) {
84
+ details.enforcer_vid_source = context.vidSource;
85
+ }
86
+ if (context.graphqlData) {
87
+ details.graphql_operations = context.graphqlData;
88
+ }
89
+ if (context.enforcerStartTime) {
90
+ details.enforcer_start_time = context.enforcerStartTime;
91
+ }
70
92
  if (context.usedCookieSecret) {
71
93
  details.used_cookie_secret = redactCookieSecret(context.usedCookieSecret);
72
94
  }
@@ -75,10 +97,12 @@ export function redactCookieSecret(secret) {
75
97
  return '***'.concat(secret.substring(secret.length - 3, secret.length));
76
98
  }
77
99
  export const addConfigDataToDetails = (details, config) => {
78
- transferExistingProperties(config, details, {
79
- remoteConfigId: 'remote_config_id',
80
- remoteConfigVersion: 'remote_config_version',
81
- });
100
+ if (config.remoteConfigId) {
101
+ details.remote_config_id = config.remoteConfigId;
102
+ }
103
+ if (config.remoteConfigVersion) {
104
+ details.remote_config_version = config.remoteConfigVersion;
105
+ }
82
106
  };
83
107
  export const addCustomParametersToDetails = (details, customParameters) => {
84
108
  if (customParameters) {
@@ -86,44 +110,78 @@ export const addCustomParametersToDetails = (details, customParameters) => {
86
110
  }
87
111
  };
88
112
  export const addProductDataToDetails = (details, productData) => {
89
- transferExistingProperties(productData.ad, details, {
90
- appUserId: 'app_user_id',
91
- additionalFields: 'jwt_additional_fields',
92
- crossTabSession: 'cross_tab_session',
93
- });
94
- transferExistingProperties(productData.ci, details, {
95
- hashedUsername: 'user',
96
- hashedPassword: 'pass',
97
- ciVersion: 'ci_version',
98
- ssoStep: 'sso_step',
99
- });
100
- transferExistingProperties(productData.hsc, details, {
101
- isTokenHscApproved: 'cpa',
102
- });
113
+ if (productData.ad) {
114
+ if (productData.ad.appUserId) {
115
+ details.app_user_id = productData.ad.appUserId;
116
+ }
117
+ if (productData.ad.additionalFields) {
118
+ details.jwt_additional_fields = productData.ad.additionalFields;
119
+ }
120
+ if (productData.ad.crossTabSession) {
121
+ details.cross_tab_session = productData.ad.crossTabSession;
122
+ }
123
+ }
124
+ if (productData.ci) {
125
+ if (productData.ci.hashedUsername) {
126
+ details.user = productData.ci.hashedUsername;
127
+ }
128
+ if (productData.ci.hashedPassword) {
129
+ details.pass = productData.ci.hashedPassword;
130
+ }
131
+ if (productData.ci.ciVersion) {
132
+ details.ci_version = productData.ci.ciVersion;
133
+ }
134
+ if (productData.ci.ssoStep) {
135
+ details.sso_step = productData.ci.ssoStep;
136
+ }
137
+ }
138
+ if (productData.hsc) {
139
+ if (typeof productData.hsc.isTokenHscApproved === 'boolean') {
140
+ details.cpa = productData.hsc.isTokenHscApproved;
141
+ }
142
+ }
103
143
  };
104
144
  export const addTlsDataToDetails = (details, tlsData) => {
105
- transferExistingProperties(tlsData, details, {
106
- tlsProtocol: 'tls_protocol',
107
- tlsServer: 'tls_server',
108
- tlsCipher: 'tls_cipher',
109
- tlsCiphersSha: 'tls_ciphers_sha',
110
- tlsExtensionSha: 'tls_extension_sha',
111
- tlsPreferredCiphers: 'tls_preferred_ciphers',
112
- tlsJa3Fingerprint: 'tls_ja3_fingerprint',
113
- });
145
+ if (tlsData.tlsCipher) {
146
+ details.tls_cipher = tlsData.tlsCipher;
147
+ }
148
+ if (tlsData.tlsCiphersSha) {
149
+ details.tls_ciphers_sha = tlsData.tlsCiphersSha;
150
+ }
151
+ if (tlsData.tlsExtensionSha) {
152
+ details.tls_extension_sha = tlsData.tlsExtensionSha;
153
+ }
154
+ if (tlsData.tlsPreferredCiphers) {
155
+ details.tls_preferred_ciphers = tlsData.tlsPreferredCiphers;
156
+ }
157
+ if (tlsData.tlsJa3Fingerprint) {
158
+ details.tls_ja3_fingerprint = tlsData.tlsJa3Fingerprint;
159
+ }
160
+ if (tlsData.tlsProtocol) {
161
+ details.tls_protocol = tlsData.tlsProtocol;
162
+ }
163
+ if (tlsData.tlsServer) {
164
+ details.tls_server = tlsData.tlsServer;
165
+ }
114
166
  };
115
167
  export const addServerDataToDetails = (details, serverData) => {
116
- transferExistingProperties(serverData, details, {
117
- region: 'server_info_region',
118
- datacenter: 'server_info_datacenter',
119
- });
168
+ if (serverData.datacenter) {
169
+ details.server_info_datacenter = serverData.datacenter;
170
+ }
171
+ if (serverData.region) {
172
+ details.server_info_region = serverData.region;
173
+ }
120
174
  };
121
175
  export const addRequestDataToDetails = (details, requestData) => {
122
- transferExistingProperties(requestData, details, {
123
- httpVersion: 'http_version',
124
- method: 'http_method',
125
- requestCookieNames: 'request_cookie_names',
126
- });
176
+ if (requestData.httpVersion) {
177
+ details.http_version = requestData.httpVersion;
178
+ }
179
+ if (requestData.method) {
180
+ details.http_method = requestData.method;
181
+ }
182
+ if (requestData.requestCookieNames) {
183
+ details.request_cookie_names = requestData.requestCookieNames.concat();
184
+ }
127
185
  if (requestData.isUrlDifferentFromRawUrl) {
128
186
  details.raw_url = requestData.rawUrl;
129
187
  }
@@ -139,10 +197,12 @@ export const addTokenDataToDetails = (details, { token, mobileData }) => {
139
197
  }
140
198
  }
141
199
  if (mobileData) {
142
- transferExistingProperties(mobileData, details, {
143
- originalToken: 'original_token',
144
- decodedOriginalToken: 'px_decoded_original_token',
145
- });
200
+ if (mobileData.originalToken) {
201
+ details.original_token = mobileData.originalToken.tokenString;
202
+ }
203
+ if (mobileData.decodedOriginalToken) {
204
+ details.px_decoded_original_token = mobileData.decodedOriginalToken;
205
+ }
146
206
  if (mobileData.originalTokenParseResult === TokenParseResult.DECRYPTION_FAILED) {
147
207
  details.original_token_error = 'cookie_decryption_failed';
148
208
  }
@@ -152,11 +212,15 @@ export const addTokenDataToDetails = (details, { token, mobileData }) => {
152
212
  }
153
213
  };
154
214
  export const addRiskApiDataToAsyncActivityCommonDetails = (details, context) => {
155
- transferExistingProperties(context.riskApiData, details, {
156
- riskRtt: 'risk_rtt',
157
- s2sCallReason: 's2s_call_reason',
158
- riskStartTime: 'risk_start_time',
159
- });
215
+ if (context.riskApiData.riskRtt) {
216
+ details.risk_rtt = context.riskApiData.riskRtt;
217
+ }
218
+ if (context.riskApiData.s2sCallReason) {
219
+ details.s2s_call_reason = context.riskApiData.s2sCallReason;
220
+ }
221
+ if (context.riskApiData.riskStartTime) {
222
+ details.risk_start_time = context.riskApiData.riskStartTime;
223
+ }
160
224
  if (context.riskApiData.riskResponse?.additionalRiskInfo) {
161
225
  details.additional_risk_info = context.riskApiData.riskResponse.additionalRiskInfo;
162
226
  }
@@ -165,21 +229,23 @@ export const addRiskApiDataToAsyncActivityCommonDetails = (details, context) =>
165
229
  }
166
230
  };
167
231
  export const addResponseDataToAsyncActivityCommonDetails = (details, context) => {
168
- if (context.action !== Action.BLOCK) {
169
- transferExistingProperties(context.response, details, {
170
- status: 'http_status_code',
171
- });
232
+ if (context.action !== Action.BLOCK && context.response?.status) {
233
+ details.http_status_code = context.response.status;
172
234
  }
173
235
  };
174
236
  export const createPageRequestedActivityDetails = (context) => {
175
237
  const details = {
176
238
  pass_reason: getReasonForHighestPriorityProduct(context.reasons),
177
239
  };
178
- transferExistingProperties(context.riskApiData, details, {
179
- errorReason: 's2s_error_reason',
180
- errorHttpStatus: 's2s_error_http_status',
181
- errorMessage: 'error_message',
182
- });
240
+ if (context.riskApiData.errorReason) {
241
+ details.s2s_error_reason = context.riskApiData.errorReason;
242
+ }
243
+ if (context.riskApiData.errorHttpStatus) {
244
+ details.s2s_error_http_status = context.riskApiData.errorHttpStatus;
245
+ }
246
+ if (context.riskApiData.errorMessage) {
247
+ details.error_message = context.riskApiData.errorMessage;
248
+ }
183
249
  return details;
184
250
  };
185
251
  export const createBlockActivityDetails = (context) => {
@@ -187,7 +253,6 @@ export const createBlockActivityDetails = (context) => {
187
253
  block_reason: getReasonForHighestPriorityProduct(context.reasons),
188
254
  simulated_block: context.action === Action.SIMULATED_BLOCK,
189
255
  block_action: context.blockAction,
190
- // @ts-ignore
191
256
  block_score: context.score,
192
257
  };
193
258
  };
@@ -1,5 +1,11 @@
1
1
  export var AdditionalActivityHandlerUtils;
2
2
  (function (AdditionalActivityHandlerUtils) {
3
+ /**
4
+ * Invokes the additional activity handler if it is defined in the configuration.
5
+ * @param config - The enforcer configuration.
6
+ * @param context - The request context.
7
+ * @returns {Promise<void>} - A promise that resolves when the additional activity handler is complete.
8
+ */
3
9
  AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler = async (config, context) => {
4
10
  if (config.additionalActivityHandler && typeof config.additionalActivityHandler === 'function') {
5
11
  try {
@@ -1,11 +1,25 @@
1
1
  import { CONTENT_TYPE_HEADER_NAME, MinimalResponseImpl } from '../http/index.js';
2
+ /**
3
+ * Base class for creating a block response.
4
+ */
2
5
  export class BlockerBase {
3
6
  statusCode;
4
7
  contentType;
8
+ /**
9
+ * Creates a new instance of BlockerBase.
10
+ * @param contentType - The Content-Type header to be included in the HTTP block response.
11
+ * @param statusCode - The status code of the HTTP block response.
12
+ * @protected
13
+ */
5
14
  constructor(contentType, statusCode = 403) {
6
15
  this.contentType = contentType;
7
16
  this.statusCode = statusCode;
8
17
  }
18
+ /**
19
+ * Creates the complete HTTP block response based on the given context.
20
+ * @param context - The request context.
21
+ * @returns {IMinimalResponse} - The HTTP block response.
22
+ */
9
23
  createBlockResponse(context) {
10
24
  const status = this.statusCode;
11
25
  const headers = this.createHeaders();
@@ -1,5 +1,10 @@
1
1
  import { BlockerBase } from './BlockerBase.js';
2
2
  import { ACCEPT_HEADER_NAME, ContentType } from '../http/index.js';
3
+ /**
4
+ * Base class for creating a block response with JSON payload.
5
+ *
6
+ * The generic argument JsonPayloadT is the specific structure of the JSON payload to be returned.
7
+ */
3
8
  export class JsonBlockerBase extends BlockerBase {
4
9
  constructor() {
5
10
  super(ContentType.APPLICATION_JSON);
@@ -1,4 +1,10 @@
1
1
  import { FirstPartySuffix, getMostCustomizedFirstPartyPath } from '../products/index.js';
2
+ /**
3
+ * Renders the HTML template with the provided block data.
4
+ * @param htmlTemplate - The HTML template to be rendered. Placeholders are indicated with {{key_name}} where the key_name should be keyof BlockData.
5
+ * @param blockData - The block data to be used for rendering. The keys in the object should match the placeholders in the template.
6
+ * @returns {string} - The final HTML string. If no block data is provided, the original template is returned unchanged.
7
+ */
2
8
  export const renderHtml = (htmlTemplate, blockData) => {
3
9
  if (!blockData) {
4
10
  return htmlTemplate;
@@ -10,6 +16,13 @@ export const renderHtml = (htmlTemplate, blockData) => {
10
16
  });
11
17
  return htmlTemplate;
12
18
  };
19
+ /**
20
+ * Creates the block data object to be used when creating a block response.
21
+ * @param config - The enforcer configuration.
22
+ * @param context - The request context.
23
+ * @param base64Utils - The base64 utility functions.
24
+ * @returns {BlockData} - The block data object.
25
+ */
13
26
  export const createBlockData = (config, context, base64Utils) => {
14
27
  const captchaScriptSuffix = '/captcha.js';
15
28
  const b64EncodedUrl = config.enableBlockedUrlOnCaptchaBlockPage
@@ -3,6 +3,9 @@ import { DefaultLogger, LoggerSeverity } from '../logger/index.js';
3
3
  import { CORE_MODULE_VERSION, EnforcerConfigurationError, getCollectorDomain, getScoreApiDomain, isNullOrUndefined, isValidEnumValue, ModuleMode, } from '../utils/index.js';
4
4
  import { RemoteConfigUtils } from './remote_config/index.js';
5
5
  import { TokenVersion } from '../risk_token/index.js';
6
+ /**
7
+ * Base class for the enforcer configuration.
8
+ */
6
9
  export class ConfigurationBase {
7
10
  configParams;
8
11
  staticConfigParams;
@@ -11,6 +14,13 @@ export class ConfigurationBase {
11
14
  removedParams;
12
15
  // Logger is initialized at `createActiveConfiguration`
13
16
  internalLogger;
17
+ /**
18
+ * Creates an instance of the configuration base class.
19
+ * @param params - The configuration parameters as provided by the customer.
20
+ * @param defaultParams - Default parameters for added configurations or any default core configurations that should be overridden.
21
+ * @param removedParams - A map of all removed (unsupported) configuration parameters set to undefined. This parameter can be generated automatically by your IDE.
22
+ * @protected
23
+ */
14
24
  constructor(params, defaultParams, removedParams) {
15
25
  this.defaultConfigParams = { ...defaultConfigurationParams(), ...defaultParams };
16
26
  this.configParams = this.createActiveConfiguration(params, this.defaultConfigParams);
@@ -374,4 +384,7 @@ export class ConfigurationBase {
374
384
  get enableBlockedUrlOnCaptchaBlockPage() {
375
385
  return true;
376
386
  }
387
+ get isPostEnforceEnabled() {
388
+ return true;
389
+ }
377
390
  }
@@ -6,6 +6,10 @@ import { COOKIE_HEADER_NAME, toReadonlyHeaders, USER_AGENT_HEADER_NAME, } from '
6
6
  import { isValidUuid, PXHD_COOKIE_NAME, PXVID_COOKIE_NAME, StringSplitCookieParser, X_PX_AUTHORIZATION_HEADER_NAME, } from '../utils/index.js';
7
7
  import { Action } from '../action/index.js';
8
8
  import { DefaultLogger, X_PX_ENFORCER_LOG_HEADER } from '../logger/index.js';
9
+ /**
10
+ * The default implementation of the request context which uses the incoming HTTP request and enforcer configuration
11
+ * to populate the context with relevant data.
12
+ */
9
13
  export class DefaultContext {
10
14
  requestId;
11
15
  tokenOrigin;
@@ -1,6 +1,11 @@
1
1
  import { DefaultLogger } from '../logger/index.js';
2
2
  import { SerializedToken } from '../risk_token/index.js';
3
3
  import { SerializedRiskResponse } from '../risk_api/index.js';
4
+ /**
5
+ * Implements the `IContext` interface based an already serialized `ContextJson`. This class does not extract data from the
6
+ * incoming request, but rather uses already-extracted data from the `ContextJson` (likely returned from the `DefaultContext.toJSON()`
7
+ * function) and fills in the gaps using the other parameters.
8
+ */
4
9
  export class SerializedContext {
5
10
  isMobile;
6
11
  remoteConfigUpdateData;
@@ -1,5 +1,8 @@
1
- import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../phase/index.js';
1
+ import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../flow/index.js';
2
2
  import { createEnforcerInitializationBlock } from './utils.js';
3
+ /**
4
+ * The base class for fundamental enforcer logic.
5
+ */
3
6
  export class EnforcerBase {
4
7
  config;
5
8
  filterFlow;
@@ -27,15 +30,47 @@ export class EnforcerBase {
27
30
  this.config.logger.debug('HUMAN enforcer is disabled, will not enforce');
28
31
  }
29
32
  }
33
+ /**
34
+ * Creates the filter flow for the enforcer. The filter flow is responsible for filtering out requests that should not undergo the usual enforcement flow.
35
+ * For example, first party, filtered, CORS preflight, and telemetry requests are filtered out.
36
+ * @param config - The configuration object.
37
+ * @param initializationBlock - All entities necessary for the enforcer to function.
38
+ * @protected
39
+ * @returns - The filter flow for the enforcer.
40
+ */
30
41
  createFilterFlow(config, initializationBlock) {
31
42
  return new FilterFlow(config, initializationBlock);
32
43
  }
44
+ /**
45
+ * Creates the post enforce flow for the enforcer. The post enforce flow is responsible for any logic that requires the origin response in the case of passed requests.
46
+ * For example, enriching the context with response data (status, login successful information) and modifying the origin response (snippet injection, PXHD) are part of the post enforce flow.
47
+ * @param config - The configuration object.
48
+ * @param initializationBlock - All entities necessary for the enforcer to function.
49
+ * @protected
50
+ * @returns - The post enforce flow for the enforcer or null if post enforce is not enabled.
51
+ */
33
52
  createPostEnforceFlow(config, initializationBlock) {
34
- return new PostEnforceFlow(config, initializationBlock);
53
+ return this.config.isPostEnforceEnabled ? new PostEnforceFlow(config, initializationBlock) : null;
35
54
  }
55
+ /**
56
+ * Creates the enforce flow for the enforcer. The enforce flow is responsible for the core functionality of HUMAN enforcement.
57
+ * For example, parsing HUMAN cookies, performing Risk API, invoking the additional activity handler, and returning a block response are part of the enforce flow.
58
+ * @param config - The configuration object.
59
+ * @param initializationBlock - All entities necessary for the enforcer to function.
60
+ * @protected
61
+ * @returns - The enforce flow for the enforcer.
62
+ */
36
63
  createEnforceFlow(config, initializationBlock) {
37
64
  return new EnforceFlow(config, initializationBlock);
38
65
  }
66
+ /**
67
+ * Creates the end enforce flow for the enforcer. The end enforce flow is responsible for all actions that must be done after every incoming request.
68
+ * For example, sending the async activities, sending the telemetry activity, or updating the remote config, sending and clearing the enforcer logs, are parts of the end enforce flow.
69
+ * @param config - The configuration object.
70
+ * @param initializationBlock - All entities necessary for the enforcer to function.
71
+ * @protected
72
+ * @returns - The end enforce flow for the enforcer.
73
+ */
39
74
  createEndEnforcerFlow(config, initializationBlock) {
40
75
  return new EndEnforcerFlow(config, initializationBlock);
41
76
  }
@@ -72,12 +107,14 @@ export class EnforcerBase {
72
107
  await this.endEnforcerFlow.execute(context);
73
108
  return result.response ? this.convertToRes(result.response, ...args) : null;
74
109
  }
75
- await this.preserveContext(context, ...args);
76
110
  result = await this.enforceFlow.execute(context);
77
- if (result.done) {
111
+ if (result.done || !this.config.isPostEnforceEnabled) {
78
112
  await this.endEnforcerFlow.execute(context);
79
113
  return result.response ? this.convertToRes(result.response, ...args) : null;
80
114
  }
115
+ if (this.config.isPostEnforceEnabled) {
116
+ await this.preserveContext(context, ...args);
117
+ }
81
118
  return null;
82
119
  }
83
120
  /**
@@ -88,13 +125,13 @@ export class EnforcerBase {
88
125
  async postEnforce(...args) {
89
126
  let context;
90
127
  try {
91
- if (!this.config.moduleEnabled) {
128
+ if (!this.config.moduleEnabled || !this.config.isPostEnforceEnabled) {
92
129
  return;
93
130
  }
94
131
  context = this.retrieveContext(...args);
95
132
  if (context) {
96
133
  context.response = await this.convertToOutgoingResponse(...args);
97
- await this.postEnforceFlow.execute(context);
134
+ await this.postEnforceFlow?.execute(context);
98
135
  await this.endEnforcerFlow.execute(context);
99
136
  }
100
137
  }