perimeterx-js-core 0.24.4 → 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 (314) 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 +26 -6
  12. package/lib/cjs/config/index.js +0 -1
  13. package/lib/cjs/config/remote_config/RemoteConfigUtils.js +12 -2
  14. package/lib/cjs/config/remote_config/index.js +2 -2
  15. package/lib/cjs/config/remote_config/manager/DefaultRemoteConfigManager.js +191 -0
  16. package/lib/cjs/config/remote_config/manager/index.js +18 -0
  17. package/lib/cjs/config/remote_config/model/index.js +1 -1
  18. package/lib/cjs/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.js +139 -0
  19. package/lib/cjs/config/remote_config/update_parser/index.js +18 -0
  20. package/lib/cjs/context/DefaultContext.js +26 -4
  21. package/lib/cjs/context/SerializedContext.js +6 -1
  22. package/lib/cjs/context/interfaces/RemoteConfigUpdateData.js +2 -0
  23. package/lib/cjs/context/interfaces/index.js +1 -0
  24. package/lib/cjs/enforcer/EnforcerBase.js +77 -32
  25. package/lib/cjs/enforcer/IPostEnforcer.js +2 -0
  26. package/lib/cjs/enforcer/index.js +1 -0
  27. package/lib/cjs/enforcer/utils.js +34 -38
  28. package/lib/cjs/{phase/flow → flow}/EndEnforcerFlow.js +13 -7
  29. package/lib/cjs/{phase/flow → flow}/EnforceFlow.js +10 -15
  30. package/lib/cjs/{phase/flow → flow}/FilterFlow.js +12 -12
  31. package/lib/cjs/flow/Flow.js +60 -0
  32. package/lib/cjs/flow/IFlow.js +2 -0
  33. package/lib/cjs/{phase/flow → flow}/PostEnforceFlow.js +6 -6
  34. package/lib/cjs/{phase/flow → flow}/index.js +2 -0
  35. package/lib/cjs/index.js +1 -0
  36. package/lib/cjs/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
  37. package/lib/cjs/phase/impl/ClearLogsPhase.js +3 -0
  38. package/lib/cjs/phase/impl/CompositePhase.js +9 -0
  39. package/lib/cjs/phase/impl/CreateBlockResponsePhase.js +16 -0
  40. package/lib/cjs/phase/impl/DecideActionPhase.js +11 -0
  41. package/lib/cjs/phase/impl/EnrichContextFromRequestPhase.js +13 -9
  42. package/lib/cjs/phase/impl/EnrichContextFromResponsePhase.js +4 -0
  43. package/lib/cjs/phase/impl/FilterPhase.js +4 -0
  44. package/lib/cjs/phase/impl/FirstPartyPhase.js +5 -0
  45. package/lib/cjs/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +80 -0
  46. package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
  47. package/lib/cjs/phase/impl/ModifyIncomingRequestPhase.js +5 -0
  48. package/lib/cjs/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
  49. package/lib/cjs/phase/impl/ParseTokenPhase.js +14 -7
  50. package/lib/cjs/phase/impl/PreflightPhase.js +4 -0
  51. package/lib/cjs/phase/impl/RiskApiPhase.js +18 -7
  52. package/lib/cjs/phase/impl/{SendAsyncActivitiesOnResponsePhase.js → SendAsyncActivitiesPhase.js} +15 -8
  53. package/lib/cjs/phase/impl/SendLogsPhase.js +3 -0
  54. package/lib/cjs/phase/impl/SendTelemetryActivityPhase.js +3 -0
  55. package/lib/cjs/phase/impl/UpdateRemoteConfigPhase.js +10 -14
  56. package/lib/cjs/phase/impl/index.js +3 -3
  57. package/lib/cjs/phase/index.js +0 -1
  58. package/lib/cjs/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
  59. package/lib/cjs/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
  60. package/lib/cjs/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +3 -1
  61. package/lib/cjs/risk_api/client/GetRiskApiClientV2.js +80 -0
  62. package/lib/cjs/risk_api/client/PostRiskApiClientV2.js +3 -3
  63. package/lib/cjs/risk_api/client/PostRiskApiClientV3.js +3 -3
  64. package/lib/cjs/risk_api/client/abstract/IRiskApiClient.js +2 -0
  65. package/lib/cjs/risk_api/client/abstract/PostRiskApiClientBase.js +43 -0
  66. package/lib/cjs/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +22 -69
  67. package/lib/cjs/risk_api/client/abstract/index.js +19 -0
  68. package/lib/cjs/risk_api/client/index.js +2 -2
  69. package/lib/cjs/risk_api/index.js +1 -0
  70. package/lib/cjs/risk_api/model/GetRiskRequestHeaders.js +185 -0
  71. package/lib/cjs/risk_api/model/GetRiskResponseHeaders.js +16 -0
  72. package/lib/cjs/risk_api/model/index.js +2 -0
  73. package/lib/cjs/{phase/impl/SendAsyncActivitiesOnRequestPhase.js → risk_api/risk_response/PostRiskResponseBase.js} +26 -30
  74. package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +11 -8
  75. package/lib/cjs/risk_api/risk_response/index.js +1 -0
  76. package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
  77. package/lib/cjs/risk_api/risk_response/v2/GetRiskResponseV2.js +80 -0
  78. package/lib/cjs/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +10 -10
  79. package/lib/cjs/risk_api/risk_response/v2/index.js +2 -1
  80. package/lib/cjs/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +10 -10
  81. package/lib/cjs/risk_api/risk_response/v3/index.js +1 -1
  82. package/lib/cjs/risk_api/utils.js +36 -0
  83. package/lib/cjs/telemetry/DefaultTelemetry.js +12 -9
  84. package/lib/cjs/utils/constants.js +1 -1
  85. package/lib/cjs/utils/utils.js +1 -19
  86. package/lib/esm/action/Action.js +15 -0
  87. package/lib/esm/action/ActionPriorityOrder.js +4 -0
  88. package/lib/esm/action/utils.js +20 -0
  89. package/lib/esm/activities/HttpActivityClient.js +61 -1
  90. package/lib/esm/activities/HttpBatchedActivityClient.js +7 -0
  91. package/lib/esm/activities/utils.js +128 -63
  92. package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
  93. package/lib/esm/blocker/BlockerBase.js +14 -0
  94. package/lib/esm/blocker/JsonBlockerBase.js +5 -0
  95. package/lib/esm/blocker/utils.js +13 -0
  96. package/lib/esm/config/ConfigurationBase.js +23 -8
  97. package/lib/esm/config/index.js +0 -1
  98. package/lib/esm/config/remote_config/RemoteConfigUtils.js +11 -2
  99. package/lib/esm/config/remote_config/index.js +2 -2
  100. package/lib/esm/config/remote_config/manager/DefaultRemoteConfigManager.js +87 -0
  101. package/lib/esm/config/remote_config/manager/index.js +2 -0
  102. package/lib/esm/config/remote_config/model/index.js +1 -1
  103. package/lib/esm/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.js +60 -0
  104. package/lib/esm/config/remote_config/update_parser/index.js +2 -0
  105. package/lib/esm/context/DefaultContext.js +23 -6
  106. package/lib/esm/context/SerializedContext.js +7 -2
  107. package/lib/esm/context/interfaces/RemoteConfigUpdateData.js +1 -0
  108. package/lib/esm/context/interfaces/index.js +1 -0
  109. package/lib/esm/enforcer/EnforcerBase.js +46 -6
  110. package/lib/esm/enforcer/IPostEnforcer.js +1 -0
  111. package/lib/esm/enforcer/index.js +1 -0
  112. package/lib/esm/enforcer/utils.js +32 -17
  113. package/lib/esm/flow/EndEnforcerFlow.js +18 -0
  114. package/lib/esm/flow/EnforceFlow.js +14 -0
  115. package/lib/esm/{phase/flow → flow}/FilterFlow.js +8 -8
  116. package/lib/esm/flow/Flow.js +56 -0
  117. package/lib/esm/flow/IFlow.js +1 -0
  118. package/lib/esm/flow/PostEnforceFlow.js +10 -0
  119. package/lib/esm/{phase/flow → flow}/index.js +2 -0
  120. package/lib/esm/index.js +1 -0
  121. package/lib/esm/logger/LoggerBase.js +1 -1
  122. package/lib/esm/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
  123. package/lib/esm/phase/impl/ClearLogsPhase.js +3 -0
  124. package/lib/esm/phase/impl/CompositePhase.js +9 -0
  125. package/lib/esm/phase/impl/CreateBlockResponsePhase.js +16 -1
  126. package/lib/esm/phase/impl/DecideActionPhase.js +11 -0
  127. package/lib/esm/phase/impl/EnrichContextFromRequestPhase.js +9 -0
  128. package/lib/esm/phase/impl/EnrichContextFromResponsePhase.js +4 -0
  129. package/lib/esm/phase/impl/FilterPhase.js +4 -0
  130. package/lib/esm/phase/impl/FirstPartyPhase.js +5 -0
  131. package/lib/esm/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +29 -0
  132. package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
  133. package/lib/esm/phase/impl/ModifyIncomingRequestPhase.js +5 -0
  134. package/lib/esm/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
  135. package/lib/esm/phase/impl/ParseTokenPhase.js +15 -8
  136. package/lib/esm/phase/impl/PreflightPhase.js +4 -0
  137. package/lib/esm/phase/impl/RiskApiPhase.js +19 -8
  138. package/lib/esm/phase/impl/SendAsyncActivitiesPhase.js +16 -0
  139. package/lib/esm/phase/impl/SendLogsPhase.js +3 -0
  140. package/lib/esm/phase/impl/SendTelemetryActivityPhase.js +3 -0
  141. package/lib/esm/phase/impl/UpdateRemoteConfigPhase.js +9 -13
  142. package/lib/esm/phase/impl/index.js +3 -3
  143. package/lib/esm/phase/index.js +0 -1
  144. package/lib/esm/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
  145. package/lib/esm/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
  146. package/lib/esm/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +2 -1
  147. package/lib/esm/risk_api/client/GetRiskApiClientV2.js +57 -0
  148. package/lib/esm/risk_api/client/PostRiskApiClientV2.js +3 -3
  149. package/lib/esm/risk_api/client/PostRiskApiClientV3.js +3 -3
  150. package/lib/esm/risk_api/client/abstract/IRiskApiClient.js +1 -0
  151. package/lib/esm/risk_api/client/abstract/PostRiskApiClientBase.js +18 -0
  152. package/lib/esm/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +10 -49
  153. package/lib/esm/risk_api/client/abstract/index.js +3 -0
  154. package/lib/esm/risk_api/client/index.js +2 -2
  155. package/lib/esm/risk_api/index.js +1 -0
  156. package/lib/esm/risk_api/model/GetRiskRequestHeaders.js +182 -0
  157. package/lib/esm/risk_api/model/GetRiskResponseHeaders.js +13 -0
  158. package/lib/esm/risk_api/model/index.js +2 -0
  159. package/lib/esm/risk_api/risk_response/PostRiskResponseBase.js +6 -0
  160. package/lib/esm/risk_api/risk_response/RiskResponseBase.js +5 -1
  161. package/lib/esm/risk_api/risk_response/index.js +1 -0
  162. package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
  163. package/lib/esm/risk_api/risk_response/v2/GetRiskResponseV2.js +52 -0
  164. package/lib/esm/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +2 -2
  165. package/lib/esm/risk_api/risk_response/v2/index.js +2 -1
  166. package/lib/esm/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +2 -2
  167. package/lib/esm/risk_api/risk_response/v3/index.js +1 -1
  168. package/lib/esm/risk_api/utils.js +23 -0
  169. package/lib/esm/telemetry/DefaultTelemetry.js +13 -10
  170. package/lib/esm/utils/constants.js +1 -1
  171. package/lib/esm/utils/utils.js +0 -16
  172. package/lib/types/action/Action.d.ts +15 -0
  173. package/lib/types/action/ActionData.d.ts +3 -0
  174. package/lib/types/action/ActionPriorityOrder.d.ts +4 -0
  175. package/lib/types/action/Decision.d.ts +9 -0
  176. package/lib/types/action/ProductAction.d.ts +3 -0
  177. package/lib/types/action/utils.d.ts +20 -0
  178. package/lib/types/activities/HttpActivityClient.d.ts +57 -1
  179. package/lib/types/activities/HttpBatchedActivityClient.d.ts +7 -0
  180. package/lib/types/activities/IActivityClient.d.ts +4 -1
  181. package/lib/types/activities/model/AsyncActivity.d.ts +3 -0
  182. package/lib/types/activities/model/AsyncActivityDetails.d.ts +12 -0
  183. package/lib/types/activities/model/CommonActivityDetails.d.ts +3 -0
  184. package/lib/types/activities/utils.d.ts +14 -0
  185. package/lib/types/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +6 -0
  186. package/lib/types/blocker/BlockerBase.d.ts +21 -0
  187. package/lib/types/blocker/IBlocker.d.ts +8 -0
  188. package/lib/types/blocker/IConditionalBlocker.d.ts +4 -0
  189. package/lib/types/blocker/JsonBlockerBase.d.ts +12 -0
  190. package/lib/types/blocker/model/BlockData.d.ts +3 -0
  191. package/lib/types/blocker/utils.d.ts +13 -0
  192. package/lib/types/config/ConfigurationBase.d.ts +25 -2
  193. package/lib/types/config/IConfiguration.d.ts +7 -2
  194. package/lib/types/config/index.d.ts +0 -1
  195. package/lib/types/config/params/CoreConfigurationParams.d.ts +22 -1
  196. package/lib/types/config/params/RemoteConfigurationParams.d.ts +3 -0
  197. package/lib/types/config/params/StaticConfigurationParams.d.ts +3 -0
  198. package/lib/types/config/remote_config/RemoteConfigUtils.d.ts +2 -1
  199. package/lib/types/config/remote_config/index.d.ts +2 -2
  200. package/lib/types/config/remote_config/manager/DefaultRemoteConfigManager.d.ts +23 -0
  201. package/lib/types/config/remote_config/manager/IRemoteConfigManager.d.ts +7 -0
  202. package/lib/types/config/remote_config/manager/index.d.ts +2 -0
  203. package/lib/types/config/remote_config/model/RemoteConfigNotifyRequestPayload.d.ts +3 -0
  204. package/lib/types/config/remote_config/model/index.d.ts +1 -1
  205. package/lib/types/config/remote_config/service_client/HttpRemoteConfigServiceClient.d.ts +2 -2
  206. package/lib/types/config/remote_config/service_client/IRemoteConfigServiceClient.d.ts +2 -2
  207. package/lib/types/config/remote_config/storage_client/IRemoteConfigStorageClient.d.ts +1 -1
  208. package/lib/types/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.d.ts +22 -0
  209. package/lib/types/config/remote_config/update_parser/IRemoteConfigUpdateParser.d.ts +5 -0
  210. package/lib/types/config/remote_config/update_parser/index.d.ts +2 -0
  211. package/lib/types/context/ContextJson.d.ts +6 -2
  212. package/lib/types/context/DefaultContext.d.ts +9 -3
  213. package/lib/types/context/SerializedContext.d.ts +7 -2
  214. package/lib/types/context/interfaces/IContext.d.ts +4 -3
  215. package/lib/types/context/interfaces/RemoteConfigUpdateData.d.ts +4 -0
  216. package/lib/types/context/interfaces/index.d.ts +1 -0
  217. package/lib/types/custom_parameters/CustomParameters.d.ts +3 -0
  218. package/lib/types/enforcer/EnforcerBase.d.ts +50 -13
  219. package/lib/types/enforcer/EnforcerOptions.d.ts +3 -2
  220. package/lib/types/enforcer/IEnforcer.d.ts +1 -2
  221. package/lib/types/enforcer/IPostEnforcer.d.ts +3 -0
  222. package/lib/types/enforcer/index.d.ts +1 -0
  223. package/lib/types/enforcer/utils.d.ts +7 -1
  224. package/lib/types/first_party/IFirstParty.d.ts +1 -1
  225. package/lib/types/flow/EndEnforcerFlow.d.ts +8 -0
  226. package/lib/types/flow/EnforceFlow.d.ts +8 -0
  227. package/lib/types/flow/FilterFlow.d.ts +11 -0
  228. package/lib/types/flow/Flow.d.ts +13 -0
  229. package/lib/types/flow/IFlow.d.ts +57 -0
  230. package/lib/types/flow/PostEnforceFlow.d.ts +6 -0
  231. package/lib/types/{phase/flow → flow}/index.d.ts +2 -0
  232. package/lib/types/index.d.ts +1 -0
  233. package/lib/types/logger/ILogger.d.ts +4 -0
  234. package/lib/types/logger/LoggerBase.d.ts +1 -1
  235. package/lib/types/phase/IPhase.d.ts +9 -0
  236. package/lib/types/phase/PhaseResult.d.ts +11 -0
  237. package/lib/types/phase/impl/AdditionalActivityHandlerPhase.d.ts +3 -0
  238. package/lib/types/phase/impl/ClearLogsPhase.d.ts +3 -0
  239. package/lib/types/phase/impl/CompositePhase.d.ts +9 -0
  240. package/lib/types/phase/impl/CreateBlockResponsePhase.d.ts +11 -1
  241. package/lib/types/phase/impl/DecideActionPhase.d.ts +11 -0
  242. package/lib/types/phase/impl/EnrichContextFromRequestPhase.d.ts +9 -0
  243. package/lib/types/phase/impl/EnrichContextFromResponsePhase.d.ts +4 -0
  244. package/lib/types/phase/impl/FilterPhase.d.ts +4 -0
  245. package/lib/types/phase/impl/FirstPartyPhase.d.ts +5 -0
  246. package/lib/types/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.d.ts +14 -0
  247. package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +5 -0
  248. package/lib/types/phase/impl/ModifyIncomingRequestPhase.d.ts +5 -0
  249. package/lib/types/phase/impl/ModifyOutgoingResponsePhase.d.ts +5 -0
  250. package/lib/types/phase/impl/ParseTokenPhase.d.ts +3 -0
  251. package/lib/types/phase/impl/PreflightPhase.d.ts +4 -0
  252. package/lib/types/phase/impl/RiskApiPhase.d.ts +5 -0
  253. package/lib/types/phase/impl/{SendAsyncActivitiesOnResponsePhase.d.ts → SendAsyncActivitiesPhase.d.ts} +5 -2
  254. package/lib/types/phase/impl/SendLogsPhase.d.ts +3 -0
  255. package/lib/types/phase/impl/SendTelemetryActivityPhase.d.ts +3 -0
  256. package/lib/types/phase/impl/UpdateRemoteConfigPhase.d.ts +6 -5
  257. package/lib/types/phase/impl/index.d.ts +3 -3
  258. package/lib/types/phase/index.d.ts +0 -1
  259. package/lib/types/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
  260. package/lib/types/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.d.ts +1 -1
  261. package/lib/types/products/interfaces/IProduct.d.ts +28 -0
  262. package/lib/types/products/interfaces/ProductDataType.d.ts +1 -1
  263. package/lib/types/risk_api/client/GetRiskApiClientV2.d.ts +15 -0
  264. package/lib/types/risk_api/client/PostRiskApiClientV2.d.ts +1 -1
  265. package/lib/types/risk_api/client/PostRiskApiClientV3.d.ts +2 -2
  266. package/lib/types/risk_api/client/{IRiskApiClient.d.ts → abstract/IRiskApiClient.d.ts} +1 -1
  267. package/lib/types/risk_api/client/abstract/PostRiskApiClientBase.d.ts +8 -0
  268. package/lib/types/risk_api/client/abstract/RiskApiClientBase.d.ts +26 -0
  269. package/lib/types/risk_api/client/abstract/index.d.ts +3 -0
  270. package/lib/types/risk_api/client/index.d.ts +2 -2
  271. package/lib/types/risk_api/index.d.ts +1 -0
  272. package/lib/types/risk_api/model/GetRiskRequestHeaders.d.ts +17 -0
  273. package/lib/types/risk_api/model/GetRiskResponseHeaders.d.ts +3 -0
  274. package/lib/types/risk_api/model/index.d.ts +2 -0
  275. package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +2 -0
  276. package/lib/types/risk_api/risk_response/PostRiskResponseBase.d.ts +7 -0
  277. package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +3 -1
  278. package/lib/types/risk_api/risk_response/index.d.ts +1 -0
  279. package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
  280. package/lib/types/risk_api/risk_response/v2/GetRiskResponseV2.d.ts +11 -0
  281. package/lib/types/risk_api/risk_response/v2/{DefaultRiskResponseV2.d.ts → PostRiskResponseV2.d.ts} +2 -2
  282. package/lib/types/risk_api/risk_response/v2/index.d.ts +2 -1
  283. package/lib/types/risk_api/risk_response/v3/{DefaultRiskResponseV3.d.ts → PostRiskResponseV3.d.ts} +2 -2
  284. package/lib/types/risk_api/risk_response/v3/index.d.ts +1 -1
  285. package/lib/types/risk_api/utils.d.ts +69 -0
  286. package/lib/types/telemetry/model/TelemetryActivity.d.ts +1 -1
  287. package/lib/types/utils/constants.d.ts +1 -1
  288. package/lib/types/utils/utils.d.ts +0 -5
  289. package/package.json +13 -13
  290. package/lib/cjs/config/ConfigurationBuilderBase.js +0 -135
  291. package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +0 -200
  292. package/lib/esm/config/ConfigurationBuilderBase.js +0 -66
  293. package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +0 -99
  294. package/lib/esm/phase/flow/EndEnforcerFlow.js +0 -12
  295. package/lib/esm/phase/flow/EnforceFlow.js +0 -18
  296. package/lib/esm/phase/flow/PostEnforceFlow.js +0 -10
  297. package/lib/esm/phase/impl/SendAsyncActivitiesOnRequestPhase.js +0 -16
  298. package/lib/esm/phase/impl/SendAsyncActivitiesOnResponsePhase.js +0 -10
  299. package/lib/types/config/ConfigurationBuilderBase.d.ts +0 -13
  300. package/lib/types/config/remote_config/DefaultRemoteConfigUpdater.d.ts +0 -34
  301. package/lib/types/config/remote_config/IRemoteConfigUpdater.d.ts +0 -6
  302. package/lib/types/config/remote_config/model/RemoteConfigUpdateRequestData.d.ts +0 -3
  303. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +0 -8
  304. package/lib/types/phase/flow/EnforceFlow.d.ts +0 -8
  305. package/lib/types/phase/flow/FilterFlow.d.ts +0 -11
  306. package/lib/types/phase/flow/PostEnforceFlow.d.ts +0 -6
  307. package/lib/types/phase/impl/SendAsyncActivitiesOnRequestPhase.d.ts +0 -10
  308. package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +0 -40
  309. /package/lib/cjs/config/remote_config/{IRemoteConfigUpdater.js → manager/IRemoteConfigManager.js} +0 -0
  310. /package/lib/cjs/config/remote_config/model/{RemoteConfigUpdateRequestData.js → RemoteConfigNotifyRequestPayload.js} +0 -0
  311. /package/lib/cjs/{risk_api/client/IRiskApiClient.js → config/remote_config/update_parser/IRemoteConfigUpdateParser.js} +0 -0
  312. /package/lib/esm/config/remote_config/{IRemoteConfigUpdater.js → manager/IRemoteConfigManager.js} +0 -0
  313. /package/lib/esm/config/remote_config/model/{RemoteConfigUpdateRequestData.js → RemoteConfigNotifyRequestPayload.js} +0 -0
  314. /package/lib/esm/{risk_api/client/IRiskApiClient.js → config/remote_config/update_parser/IRemoteConfigUpdateParser.js} +0 -0
@@ -46,8 +46,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.EnforcerBase = void 0;
49
- var phase_1 = require("../phase/index.js");
49
+ var flow_1 = require("../flow/index.js");
50
50
  var utils_1 = require("./utils.js");
51
+ /**
52
+ * The base class for fundamental enforcer logic.
53
+ */
51
54
  var EnforcerBase = /** @class */ (function () {
52
55
  /**
53
56
  * The EnforcerBase constructor.
@@ -59,6 +62,7 @@ var EnforcerBase = /** @class */ (function () {
59
62
  this.config = config;
60
63
  var initializationBlock = (0, utils_1.createEnforcerInitializationBlock)(config, options);
61
64
  this.activityClient = initializationBlock.activityClient;
65
+ this.remoteConfigManager = initializationBlock.remoteConfigManager;
62
66
  this.filterFlow = this.createFilterFlow(config, initializationBlock);
63
67
  this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
64
68
  this.postEnforceFlow = this.createPostEnforceFlow(config, initializationBlock);
@@ -67,17 +71,49 @@ var EnforcerBase = /** @class */ (function () {
67
71
  this.config.logger.debug('HUMAN enforcer is disabled, will not enforce');
68
72
  }
69
73
  }
74
+ /**
75
+ * Creates the filter flow for the enforcer. The filter flow is responsible for filtering out requests that should not undergo the usual enforcement flow.
76
+ * For example, first party, filtered, CORS preflight, and telemetry requests are filtered out.
77
+ * @param config - The configuration object.
78
+ * @param initializationBlock - All entities necessary for the enforcer to function.
79
+ * @protected
80
+ * @returns - The filter flow for the enforcer.
81
+ */
70
82
  EnforcerBase.prototype.createFilterFlow = function (config, initializationBlock) {
71
- return new phase_1.FilterFlow(config, initializationBlock);
83
+ return new flow_1.FilterFlow(config, initializationBlock);
72
84
  };
85
+ /**
86
+ * 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.
87
+ * 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.
88
+ * @param config - The configuration object.
89
+ * @param initializationBlock - All entities necessary for the enforcer to function.
90
+ * @protected
91
+ * @returns - The post enforce flow for the enforcer or null if post enforce is not enabled.
92
+ */
73
93
  EnforcerBase.prototype.createPostEnforceFlow = function (config, initializationBlock) {
74
- return new phase_1.PostEnforceFlow(config, initializationBlock);
94
+ return this.config.isPostEnforceEnabled ? new flow_1.PostEnforceFlow(config, initializationBlock) : null;
75
95
  };
96
+ /**
97
+ * Creates the enforce flow for the enforcer. The enforce flow is responsible for the core functionality of HUMAN enforcement.
98
+ * For example, parsing HUMAN cookies, performing Risk API, invoking the additional activity handler, and returning a block response are part of the enforce flow.
99
+ * @param config - The configuration object.
100
+ * @param initializationBlock - All entities necessary for the enforcer to function.
101
+ * @protected
102
+ * @returns - The enforce flow for the enforcer.
103
+ */
76
104
  EnforcerBase.prototype.createEnforceFlow = function (config, initializationBlock) {
77
- return new phase_1.EnforceFlow(config, initializationBlock);
105
+ return new flow_1.EnforceFlow(config, initializationBlock);
78
106
  };
107
+ /**
108
+ * 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.
109
+ * 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.
110
+ * @param config - The configuration object.
111
+ * @param initializationBlock - All entities necessary for the enforcer to function.
112
+ * @protected
113
+ * @returns - The end enforce flow for the enforcer.
114
+ */
79
115
  EnforcerBase.prototype.createEndEnforcerFlow = function (config, initializationBlock) {
80
- return new phase_1.EndEnforcerFlow(config, initializationBlock);
116
+ return new flow_1.EndEnforcerFlow(config, initializationBlock);
81
117
  };
82
118
  /**
83
119
  * The central function that triggers enforcement on the incoming request.
@@ -91,23 +127,28 @@ var EnforcerBase = /** @class */ (function () {
91
127
  }
92
128
  return __awaiter(this, void 0, void 0, function () {
93
129
  var context, e_1;
94
- return __generator(this, function (_a) {
95
- switch (_a.label) {
96
- case 0:
97
- _a.trys.push([0, 3, , 4]);
130
+ var _a;
131
+ return __generator(this, function (_b) {
132
+ switch (_b.label) {
133
+ case 0: return [4 /*yield*/, ((_a = this.remoteConfigManager) === null || _a === void 0 ? void 0 : _a.loadRemoteConfig())];
134
+ case 1:
135
+ _b.sent();
136
+ _b.label = 2;
137
+ case 2:
138
+ _b.trys.push([2, 5, , 6]);
98
139
  if (!this.config.moduleEnabled) {
99
140
  return [2 /*return*/, null];
100
141
  }
101
142
  return [4 /*yield*/, this.constructContext.apply(this, args)];
102
- case 1:
103
- context = _a.sent();
104
- return [4 /*yield*/, this.doEnforce.apply(this, __spreadArray([context], args, false))];
105
- case 2: return [2 /*return*/, _a.sent()];
106
143
  case 3:
107
- e_1 = _a.sent();
144
+ context = _b.sent();
145
+ return [4 /*yield*/, this.doEnforce.apply(this, __spreadArray([context], args, false))];
146
+ case 4: return [2 /*return*/, _b.sent()];
147
+ case 5:
148
+ e_1 = _b.sent();
108
149
  (context || this.config).logger.error("caught error in enforce - ".concat(e_1));
109
150
  return [2 /*return*/, null];
110
- case 4: return [2 /*return*/];
151
+ case 6: return [2 /*return*/];
111
152
  }
112
153
  });
113
154
  });
@@ -136,18 +177,21 @@ var EnforcerBase = /** @class */ (function () {
136
177
  case 2:
137
178
  _a.sent();
138
179
  return [2 /*return*/, result.response ? this.convertToRes.apply(this, __spreadArray([result.response], args, false)) : null];
139
- case 3: return [4 /*yield*/, this.preserveContext.apply(this, __spreadArray([context], args, false))];
180
+ case 3: return [4 /*yield*/, this.enforceFlow.execute(context)];
140
181
  case 4:
141
- _a.sent();
142
- return [4 /*yield*/, this.enforceFlow.execute(context)];
143
- case 5:
144
182
  result = _a.sent();
145
- if (!result.done) return [3 /*break*/, 7];
183
+ if (!(result.done || !this.config.isPostEnforceEnabled)) return [3 /*break*/, 6];
146
184
  return [4 /*yield*/, this.endEnforcerFlow.execute(context)];
147
- case 6:
185
+ case 5:
148
186
  _a.sent();
149
187
  return [2 /*return*/, result.response ? this.convertToRes.apply(this, __spreadArray([result.response], args, false)) : null];
150
- case 7: return [2 /*return*/, null];
188
+ case 6:
189
+ if (!this.config.isPostEnforceEnabled) return [3 /*break*/, 8];
190
+ return [4 /*yield*/, this.preserveContext.apply(this, __spreadArray([context], args, false))];
191
+ case 7:
192
+ _a.sent();
193
+ _a.label = 8;
194
+ case 8: return [2 /*return*/, null];
151
195
  }
152
196
  });
153
197
  });
@@ -164,11 +208,12 @@ var EnforcerBase = /** @class */ (function () {
164
208
  }
165
209
  return __awaiter(this, void 0, void 0, function () {
166
210
  var context, _a, e_2;
167
- return __generator(this, function (_b) {
168
- switch (_b.label) {
211
+ var _b;
212
+ return __generator(this, function (_c) {
213
+ switch (_c.label) {
169
214
  case 0:
170
- _b.trys.push([0, 5, , 6]);
171
- if (!this.config.moduleEnabled) {
215
+ _c.trys.push([0, 5, , 6]);
216
+ if (!this.config.moduleEnabled || !this.config.isPostEnforceEnabled) {
172
217
  return [2 /*return*/];
173
218
  }
174
219
  context = this.retrieveContext.apply(this, args);
@@ -176,17 +221,17 @@ var EnforcerBase = /** @class */ (function () {
176
221
  _a = context;
177
222
  return [4 /*yield*/, this.convertToOutgoingResponse.apply(this, args)];
178
223
  case 1:
179
- _a.response = _b.sent();
180
- return [4 /*yield*/, this.postEnforceFlow.execute(context)];
224
+ _a.response = _c.sent();
225
+ return [4 /*yield*/, ((_b = this.postEnforceFlow) === null || _b === void 0 ? void 0 : _b.execute(context))];
181
226
  case 2:
182
- _b.sent();
227
+ _c.sent();
183
228
  return [4 /*yield*/, this.endEnforcerFlow.execute(context)];
184
229
  case 3:
185
- _b.sent();
186
- _b.label = 4;
230
+ _c.sent();
231
+ _c.label = 4;
187
232
  case 4: return [3 /*break*/, 6];
188
233
  case 5:
189
- e_2 = _b.sent();
234
+ e_2 = _c.sent();
190
235
  (context || this.config).logger.error("caught error in post enforce - ".concat(e_2));
191
236
  return [3 /*break*/, 6];
192
237
  case 6: return [2 /*return*/];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./IEnforcer.js"), exports);
18
+ __exportStar(require("./IPostEnforcer.js"), exports);
18
19
  __exportStar(require("./EnforcerBase.js"), exports);
19
20
  __exportStar(require("./EnforcerOptions.js"), exports);
20
21
  __exportStar(require("./utils.js"), exports);
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.createEnforcerProducts = exports.createEnforcerInitializationBlock = void 0;
14
+ exports.createRemoteConfigClients = exports.createEnforcerProducts = exports.createEnforcerInitializationBlock = void 0;
15
15
  var risk_token_1 = require("../risk_token/index.js");
16
16
  var config_1 = require("../config/index.js");
17
17
  var cors_1 = require("../cors/index.js");
@@ -25,14 +25,14 @@ var products_1 = require("../products/index.js");
25
25
  var utils_1 = require("../utils/index.js");
26
26
  var snippet_injection_1 = require("../snippet_injection/index.js");
27
27
  var createEnforcerInitializationBlock = function (config, options) {
28
- var _a, _b, _c;
28
+ var _a, _b;
29
29
  var tokenVersion = config.tokenVersion;
30
30
  if (!(0, utils_1.isValidTokenVersion)(tokenVersion)) {
31
31
  throw new utils_1.EnforcerError("error initializing enforcer: token version ".concat(tokenVersion, " is invalid (must be one of ").concat(Object.values(risk_token_1.TokenVersion)
32
32
  .map(function (v) { return "\"".concat(v, "\""); })
33
33
  .join(', '), ")"));
34
34
  }
35
- var cipherUtils = tokenVersion === risk_token_1.TokenVersion.V2 ? null : (_a = options.cipherUtils) !== null && _a !== void 0 ? _a : null;
35
+ var cipherUtils = tokenVersion === risk_token_1.TokenVersion.V2 ? null : ((_a = options.cipherUtils) !== null && _a !== void 0 ? _a : null);
36
36
  if (tokenVersion === risk_token_1.TokenVersion.V3 && !cipherUtils) {
37
37
  throw new utils_1.EnforcerError('error initializing enforcer: token v3 requires cipherUtils');
38
38
  }
@@ -54,42 +54,10 @@ var createEnforcerInitializationBlock = function (config, options) {
54
54
  ? new activities_1.HttpBatchedActivityClient(config, httpClient)
55
55
  : new activities_1.HttpActivityClient(config, httpClient));
56
56
  var logServiceClient = options.logServiceClient || (config.loggerAuthToken ? new logger_1.HttpLogServiceClient(config, httpClient) : null);
57
- var remoteConfigStorageClient = (_b = options.remoteConfigStorageClient) !== null && _b !== void 0 ? _b : null;
58
- var remoteConfigServiceClient = options.remoteConfigServiceClient ||
59
- (config.remoteConfigAuthToken ? new config_1.HttpRemoteConfigServiceClient(config, httpClient) : null);
60
- var remoteConfigUpdater = options.remoteConfigUpdater ||
61
- (remoteConfigStorageClient && remoteConfigServiceClient
62
- ? new config_1.DefaultRemoteConfigUpdater(config, {
63
- serviceClient: remoteConfigServiceClient,
64
- storageClient: remoteConfigStorageClient,
65
- base64Utils: base64Utils,
66
- hmacUtils: hmacUtils,
67
- })
68
- : null);
69
- var snippetInjector = (_c = options.snippetInjector) !== null && _c !== void 0 ? _c : null;
57
+ var snippetInjector = (_b = options.snippetInjector) !== null && _b !== void 0 ? _b : null;
70
58
  var snippetRetriever = options.snippetRetriever || (snippetInjector ? new snippet_injection_1.DefaultSnippetRetriever(config) : null);
71
- var allOptions = {
72
- httpClient: httpClient,
73
- base64Utils: base64Utils,
74
- hmacUtils: hmacUtils,
75
- hashUtils: hashUtils,
76
- urlUtils: urlUtils,
77
- ipRangeChecker: ipRangeChecker,
78
- cipherUtils: cipherUtils,
79
- cors: cors,
80
- telemetry: telemetry,
81
- dataEnrichment: dataEnrichment,
82
- graphQLParser: graphQLParser,
83
- tokenParser: tokenParser,
84
- riskApiClient: riskApiClient,
85
- activityClient: activityClient,
86
- logServiceClient: logServiceClient,
87
- remoteConfigStorageClient: remoteConfigStorageClient,
88
- remoteConfigServiceClient: remoteConfigServiceClient,
89
- remoteConfigUpdater: remoteConfigUpdater,
90
- snippetInjector: snippetInjector,
91
- snippetRetriever: snippetRetriever,
92
- };
59
+ var remoteConfigClients = (0, exports.createRemoteConfigClients)(config, options);
60
+ var allOptions = __assign({ httpClient: httpClient, base64Utils: base64Utils, hmacUtils: hmacUtils, hashUtils: hashUtils, urlUtils: urlUtils, ipRangeChecker: ipRangeChecker, cipherUtils: cipherUtils, cors: cors, telemetry: telemetry, dataEnrichment: dataEnrichment, graphQLParser: graphQLParser, tokenParser: tokenParser, riskApiClient: riskApiClient, activityClient: activityClient, logServiceClient: logServiceClient, snippetInjector: snippetInjector, snippetRetriever: snippetRetriever }, remoteConfigClients);
93
61
  var products = (0, exports.createEnforcerProducts)(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
94
62
  return __assign({ products: products }, allOptions);
95
63
  };
@@ -111,3 +79,31 @@ var createEnforcerProducts = function (config, products, base64Utils, hashUtils,
111
79
  _a;
112
80
  };
113
81
  exports.createEnforcerProducts = createEnforcerProducts;
82
+ var createRemoteConfigClients = function (config, options) {
83
+ var _a, _b, _c, _d;
84
+ var remoteConfigStorageClient = (_a = options.remoteConfigStorageClient) !== null && _a !== void 0 ? _a : null;
85
+ var remoteConfigServiceClient = null;
86
+ var remoteConfigManager = null;
87
+ var remoteConfigUpdateParser = null;
88
+ if (remoteConfigStorageClient) {
89
+ remoteConfigServiceClient =
90
+ (_b = options.remoteConfigServiceClient) !== null && _b !== void 0 ? _b : new config_1.HttpRemoteConfigServiceClient(config, options.httpClient);
91
+ remoteConfigManager =
92
+ (_c = options.remoteConfigManager) !== null && _c !== void 0 ? _c : new config_1.DefaultRemoteConfigManager(config, {
93
+ serviceClient: remoteConfigServiceClient,
94
+ storageClient: remoteConfigStorageClient,
95
+ });
96
+ remoteConfigUpdateParser =
97
+ (_d = options.remoteConfigUpdateParser) !== null && _d !== void 0 ? _d : new config_1.DefaultNotifyRemoteConfigUpdateParser(config, {
98
+ base64Utils: options.base64Utils,
99
+ hmacUtils: options.hmacUtils,
100
+ });
101
+ }
102
+ return {
103
+ remoteConfigServiceClient: remoteConfigServiceClient,
104
+ remoteConfigManager: remoteConfigManager,
105
+ remoteConfigUpdateParser: remoteConfigUpdateParser,
106
+ remoteConfigStorageClient: remoteConfigStorageClient,
107
+ };
108
+ };
109
+ exports.createRemoteConfigClients = createRemoteConfigClients;
@@ -16,19 +16,25 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.EndEnforcerFlow = void 0;
19
- var impl_1 = require("../impl/index.js");
20
- var impl_2 = require("../impl/index.js");
19
+ var phase_1 = require("../phase/index.js");
20
+ var Flow_1 = require("./Flow.js");
21
21
  var EndEnforcerFlow = /** @class */ (function (_super) {
22
22
  __extends(EndEnforcerFlow, _super);
23
23
  function EndEnforcerFlow(config, _a) {
24
- var logServiceClient = _a.logServiceClient, telemetry = _a.telemetry;
25
- var phases = [new impl_2.SendTelemetryActivityPhase(telemetry)];
24
+ var logServiceClient = _a.logServiceClient, telemetry = _a.telemetry, remoteConfigManager = _a.remoteConfigManager, activityClient = _a.activityClient;
25
+ var phases = [
26
+ new phase_1.SendAsyncActivitiesPhase(activityClient),
27
+ new phase_1.SendTelemetryActivityPhase(telemetry),
28
+ ];
29
+ if (remoteConfigManager) {
30
+ phases.push(new phase_1.UpdateRemoteConfigPhase(config, remoteConfigManager));
31
+ }
26
32
  if (logServiceClient) {
27
- phases.push(new impl_1.SendLogsPhase(config, logServiceClient));
33
+ phases.push(new phase_1.SendLogsPhase(config, logServiceClient));
28
34
  }
29
- phases.push(new impl_2.ClearLogsPhase());
35
+ phases.push(new phase_1.ClearLogsPhase());
30
36
  return _super.call(this, phases) || this;
31
37
  }
32
38
  return EndEnforcerFlow;
33
- }(impl_1.CompositePhase));
39
+ }(Flow_1.Flow));
34
40
  exports.EndEnforcerFlow = EndEnforcerFlow;
@@ -16,26 +16,21 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.EnforceFlow = void 0;
19
- var products_1 = require("../../products/index.js");
20
- var impl_1 = require("../impl/index.js");
19
+ var phase_1 = require("../phase/index.js");
20
+ var Flow_1 = require("./Flow.js");
21
21
  var EnforceFlow = /** @class */ (function (_super) {
22
22
  __extends(EnforceFlow, _super);
23
23
  function EnforceFlow(config, _a) {
24
- var _b;
25
- var dataEnrichment = _a.dataEnrichment, tokenParser = _a.tokenParser, riskApiClient = _a.riskApiClient, activityClient = _a.activityClient, cors = _a.cors, products = _a.products, graphQLParser = _a.graphQLParser;
24
+ var dataEnrichment = _a.dataEnrichment, tokenParser = _a.tokenParser, riskApiClient = _a.riskApiClient, cors = _a.cors, products = _a.products, graphQLParser = _a.graphQLParser;
26
25
  return _super.call(this, [
27
- new impl_1.ParseTokenPhase(tokenParser),
28
- new impl_1.EnrichContextFromRequestPhase(config, products, dataEnrichment, graphQLParser),
29
- new impl_1.RiskApiPhase(products, riskApiClient),
30
- new impl_1.AdditionalActivityHandlerPhase(config),
31
- new impl_1.SendAsyncActivitiesOnRequestPhase(activityClient),
32
- new impl_1.CreateBlockResponsePhase(config, (_b = {},
33
- _b[products_1.ProductName.BOT_DEFENDER] = products[products_1.ProductName.BOT_DEFENDER],
34
- _b[products_1.ProductName.HYPE_SALE_CHALLENGE] = products[products_1.ProductName.HYPE_SALE_CHALLENGE],
35
- _b), cors),
36
- new impl_1.ModifyIncomingRequestPhase(Object.values(products)),
26
+ new phase_1.ParseTokenPhase(tokenParser),
27
+ new phase_1.EnrichContextFromRequestPhase(config, products, dataEnrichment, graphQLParser),
28
+ new phase_1.RiskApiPhase(products, riskApiClient),
29
+ new phase_1.AdditionalActivityHandlerPhase(config),
30
+ new phase_1.CreateBlockResponsePhase(config, phase_1.CreateBlockResponsePhase.getBlockers(products), cors),
31
+ new phase_1.ModifyIncomingRequestPhase(Object.values(products)),
37
32
  ]) || this;
38
33
  }
39
34
  return EnforceFlow;
40
- }(impl_1.CompositePhase));
35
+ }(Flow_1.Flow));
41
36
  exports.EnforceFlow = EnforceFlow;
@@ -16,27 +16,27 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.FilterFlow = void 0;
19
- var products_1 = require("../../products/index.js");
20
- var utils_1 = require("../../utils/index.js");
21
- var impl_1 = require("../impl/index.js");
19
+ var products_1 = require("../products/index.js");
20
+ var utils_1 = require("../utils/index.js");
21
+ var phase_1 = require("../phase/index.js");
22
+ var Flow_1 = require("./Flow.js");
22
23
  var FilterFlow = /** @class */ (function (_super) {
23
24
  __extends(FilterFlow, _super);
24
25
  function FilterFlow(config, _a) {
25
- var httpClient = _a.httpClient, products = _a.products, cors = _a.cors, telemetry = _a.telemetry, remoteConfigUpdater = _a.remoteConfigUpdater;
26
+ var httpClient = _a.httpClient, products = _a.products, cors = _a.cors, telemetry = _a.telemetry, remoteConfigUpdateParser = _a.remoteConfigUpdateParser;
26
27
  var phases = [];
27
28
  var firstPartyProducts = FilterFlow.getFirstPartyProducts(products);
28
29
  if ((firstPartyProducts === null || firstPartyProducts === void 0 ? void 0 : firstPartyProducts.length) > 0) {
29
- phases.push(new impl_1.FirstPartyPhase(config, httpClient, firstPartyProducts));
30
+ phases.push(new phase_1.FirstPartyPhase(config, httpClient, firstPartyProducts));
30
31
  }
31
32
  var filterProducts = FilterFlow.getFilterProducts(products);
32
33
  if ((filterProducts === null || filterProducts === void 0 ? void 0 : filterProducts.length) > 0) {
33
- phases.push(new impl_1.FilterPhase(filterProducts));
34
+ phases.push(new phase_1.FilterPhase(filterProducts));
34
35
  }
35
- phases.push(new impl_1.PreflightPhase(config, cors));
36
- phases.push(new impl_1.IdentifyTelemetryRequestPhase(telemetry));
37
- if (remoteConfigUpdater) {
38
- var updateRemoteConfigPhase = new impl_1.UpdateRemoteConfigPhase(config, remoteConfigUpdater);
39
- phases.push(updateRemoteConfigPhase);
36
+ phases.push(new phase_1.PreflightPhase(config, cors));
37
+ phases.push(new phase_1.IdentifyTelemetryRequestPhase(telemetry));
38
+ if (remoteConfigUpdateParser) {
39
+ phases.push(new phase_1.IdentifyRemoteConfigNotifyRequestPhase(remoteConfigUpdateParser));
40
40
  }
41
41
  return _super.call(this, phases) || this;
42
42
  }
@@ -47,5 +47,5 @@ var FilterFlow = /** @class */ (function (_super) {
47
47
  return [products[products_1.ProductName.BOT_DEFENDER]].filter(function (prod) { return !(0, utils_1.isNullOrUndefined)(prod); });
48
48
  };
49
49
  return FilterFlow;
50
- }(impl_1.CompositePhase));
50
+ }(Flow_1.Flow));
51
51
  exports.FilterFlow = FilterFlow;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Flow = void 0;
4
+ var phase_1 = require("../phase/index.js");
5
+ var Flow = /** @class */ (function () {
6
+ function Flow(phases) {
7
+ this.phases = phases;
8
+ }
9
+ Flow.prototype.insert = function (phase, options) {
10
+ if (!options) {
11
+ this.phases.push(phase);
12
+ return;
13
+ }
14
+ if (options.before) {
15
+ var index = this.getIndexOfPhase(options.before);
16
+ if (index === -1) {
17
+ return;
18
+ }
19
+ this.phases.splice(index, 0, phase);
20
+ }
21
+ if (options.after) {
22
+ var index = this.getIndexOfPhase(options.after);
23
+ if (index === -1) {
24
+ return;
25
+ }
26
+ this.phases.splice(index + 1, 0, phase);
27
+ }
28
+ };
29
+ Flow.prototype.remove = function (name) {
30
+ var index = this.getIndexOfPhase(name);
31
+ if (index === -1) {
32
+ return;
33
+ }
34
+ this.phases.splice(index, 1);
35
+ };
36
+ Flow.prototype.replace = function (name, phase) {
37
+ var index = this.getIndexOfPhase(name);
38
+ if (index === -1) {
39
+ return;
40
+ }
41
+ this.phases.splice(index, 1, phase);
42
+ };
43
+ Flow.prototype.move = function (name, to) {
44
+ var index = this.getIndexOfPhase(name);
45
+ if (index === -1) {
46
+ return;
47
+ }
48
+ var phase = this.phases[index];
49
+ this.phases.splice(index, 1);
50
+ this.insert(phase, to);
51
+ };
52
+ Flow.prototype.getIndexOfPhase = function (name) {
53
+ return this.phases.findIndex(function (existingPhase) { return existingPhase.constructor.name === name; });
54
+ };
55
+ Flow.prototype.execute = function (context) {
56
+ return new phase_1.CompositePhase(this.phases).execute(context);
57
+ };
58
+ return Flow;
59
+ }());
60
+ exports.Flow = Flow;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -16,17 +16,17 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PostEnforceFlow = void 0;
19
- var impl_1 = require("../impl/index.js");
19
+ var phase_1 = require("../phase/index.js");
20
+ var Flow_1 = require("./Flow.js");
20
21
  var PostEnforceFlow = /** @class */ (function (_super) {
21
22
  __extends(PostEnforceFlow, _super);
22
23
  function PostEnforceFlow(config, _a) {
23
- var products = _a.products, activityClient = _a.activityClient, snippetRetriever = _a.snippetRetriever, snippetInjector = _a.snippetInjector;
24
+ var products = _a.products, snippetRetriever = _a.snippetRetriever, snippetInjector = _a.snippetInjector;
24
25
  return _super.call(this, [
25
- new impl_1.EnrichContextFromResponsePhase(config, products),
26
- new impl_1.ModifyOutgoingResponsePhase(config, Object.values(products), snippetRetriever, snippetInjector),
27
- new impl_1.SendAsyncActivitiesOnResponsePhase(activityClient),
26
+ new phase_1.EnrichContextFromResponsePhase(config, products),
27
+ new phase_1.ModifyOutgoingResponsePhase(config, Object.values(products), snippetRetriever, snippetInjector),
28
28
  ]) || this;
29
29
  }
30
30
  return PostEnforceFlow;
31
- }(impl_1.CompositePhase));
31
+ }(Flow_1.Flow));
32
32
  exports.PostEnforceFlow = PostEnforceFlow;
@@ -18,3 +18,5 @@ __exportStar(require("./FilterFlow.js"), exports);
18
18
  __exportStar(require("./EnforceFlow.js"), exports);
19
19
  __exportStar(require("./PostEnforceFlow.js"), exports);
20
20
  __exportStar(require("./EndEnforcerFlow.js"), exports);
21
+ __exportStar(require("./IFlow.js"), exports);
22
+ __exportStar(require("./Flow.js"), exports);
package/lib/cjs/index.js CHANGED
@@ -25,6 +25,7 @@ __exportStar(require("./sensitive_request/index.js"), exports);
25
25
  __exportStar(require("./monitored_request/index.js"), exports);
26
26
  __exportStar(require("./snippet_injection/index.js"), exports);
27
27
  __exportStar(require("./cors/index.js"), exports);
28
+ __exportStar(require("./flow/index.js"), exports);
28
29
  __exportStar(require("./enforcer/index.js"), exports);
29
30
  __exportStar(require("./filter/index.js"), exports);
30
31
  __exportStar(require("./first_party/index.js"), exports);
@@ -38,6 +38,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.AdditionalActivityHandlerPhase = void 0;
40
40
  var additional_activity_handler_1 = require("../../additional_activity_handler/index.js");
41
+ /**
42
+ * The `AdditionalActivityHandlerPhase` invokes the additional activity handler defined in the configuration.
43
+ */
41
44
  var AdditionalActivityHandlerPhase = /** @class */ (function () {
42
45
  function AdditionalActivityHandlerPhase(config) {
43
46
  this.config = config;
@@ -37,6 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ClearLogsPhase = void 0;
40
+ /**
41
+ * The `ClearLogsPhase` class deletes the context logs to free up memory.
42
+ */
40
43
  var ClearLogsPhase = /** @class */ (function () {
41
44
  function ClearLogsPhase() {
42
45
  }
@@ -37,7 +37,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.CompositePhase = void 0;
40
+ /**
41
+ * The `CompositePhase` class executes a series of phases in sequence.
42
+ * It will stop executing phases as soon as one of them returns a result with `done: true`.
43
+ * It will return the result of the last phase executed or `{ done: false }`.
44
+ */
40
45
  var CompositePhase = /** @class */ (function () {
46
+ /**
47
+ * Creates a new CompositePhase instance.
48
+ * @param phases - An array of phases to be executed in sequence.
49
+ */
41
50
  function CompositePhase(phases) {
42
51
  this.phases = phases;
43
52
  }
@@ -41,6 +41,10 @@ var http_1 = require("../../http/index.js");
41
41
  var pxhd_1 = require("../../pxhd/index.js");
42
42
  var action_1 = require("../../action/index.js");
43
43
  var products_1 = require("../../products/index.js");
44
+ /**
45
+ * `CreateBlockResponsePhase` is a phase that creates a block response for the product that recommended a block action.
46
+ * If multiple products recommended block, it will return the block response for the highest priority product.
47
+ */
44
48
  var CreateBlockResponsePhase = /** @class */ (function () {
45
49
  function CreateBlockResponsePhase(config, blockers, cors) {
46
50
  this.config = config;
@@ -49,6 +53,18 @@ var CreateBlockResponsePhase = /** @class */ (function () {
49
53
  this.cors = cors;
50
54
  }
51
55
  }
56
+ /**
57
+ * A static method that identifies those products that can block incoming requests and returns a map of the product name to the product instance.
58
+ * @param products - All supported products.
59
+ * @returns A mapping of those products that implement the `IConditionalBlocker` interface.
60
+ */
61
+ CreateBlockResponsePhase.getBlockers = function (products) {
62
+ var _a;
63
+ return _a = {},
64
+ _a[products_1.ProductName.BOT_DEFENDER] = products[products_1.ProductName.BOT_DEFENDER],
65
+ _a[products_1.ProductName.HYPE_SALE_CHALLENGE] = products[products_1.ProductName.HYPE_SALE_CHALLENGE],
66
+ _a;
67
+ };
52
68
  CreateBlockResponsePhase.prototype.execute = function (context) {
53
69
  return __awaiter(this, void 0, void 0, function () {
54
70
  var response;
@@ -40,9 +40,20 @@ exports.DecideActionPhase = void 0;
40
40
  var logger_1 = require("../../logger/index.js");
41
41
  var action_1 = require("../../action/index.js");
42
42
  var blocker_1 = require("../../blocker/index.js");
43
+ /**
44
+ * `DecideActionPhase` is an abstract class that provides the protected function `updateContextDecision`.
45
+ * Phases that extend this class can use the `updateContextDecision` method to update the `context.action` and
46
+ * `context.reasons` properties based on the product data in the context. Calling this function essentially
47
+ * recalculates what action the enforcer should take and why.
48
+ */
43
49
  var DecideActionPhase = /** @class */ (function () {
44
50
  function DecideActionPhase() {
45
51
  }
52
+ /**
53
+ * Updates the `action`, `reasons`, and `blockAction` properties based on the product data in the context.
54
+ * @param context - The request context.
55
+ * @protected
56
+ */
46
57
  DecideActionPhase.prototype.updateContextDecision = function (context) {
47
58
  return __awaiter(this, void 0, void 0, function () {
48
59
  var _a, action, reasons, productReasons;