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
@@ -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,14 +3,24 @@ 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;
9
- remoteConfigParams;
12
+ remoteConfigData;
10
13
  defaultConfigParams;
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);
@@ -75,15 +85,15 @@ export class ConfigurationBase {
75
85
  }
76
86
  }
77
87
  createInternalLogger(params) {
78
- return new DefaultLogger(params.px_logger_severity, false);
88
+ return new DefaultLogger(params.px_logger_severity, false, this.logger?.getLogs());
79
89
  }
80
- addRemoteConfig(remoteConfigParams) {
81
- this.remoteConfigParams = remoteConfigParams;
82
- const mergedParams = {
90
+ setRemoteConfigData(remoteConfigData) {
91
+ this.remoteConfigData = remoteConfigData;
92
+ const params = {
83
93
  ...this.staticConfigParams,
84
- ...RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigParams, this.logger),
94
+ ...RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigData, this.logger),
85
95
  };
86
- this.configParams = this.createActiveConfiguration(mergedParams, this.defaultConfigParams);
96
+ this.configParams = this.createActiveConfiguration(params, this.defaultConfigParams);
87
97
  }
88
98
  getActiveConfig() {
89
99
  const activeConfig = Object.assign({}, this.configParams);
@@ -97,7 +107,9 @@ export class ConfigurationBase {
97
107
  return Object.assign({}, this.staticConfigParams);
98
108
  }
99
109
  getRemoteConfig() {
100
- return Object.assign({}, this.remoteConfigParams);
110
+ return this.remoteConfigData
111
+ ? RemoteConfigUtils.prepareRemoteConfigParams(this.remoteConfigData, this.logger)
112
+ : {};
101
113
  }
102
114
  get moduleVersion() {
103
115
  return `${this.getModuleVersion()} (${CORE_MODULE_VERSION})`;
@@ -372,4 +384,7 @@ export class ConfigurationBase {
372
384
  get enableBlockedUrlOnCaptchaBlockPage() {
373
385
  return true;
374
386
  }
387
+ get isPostEnforceEnabled() {
388
+ return true;
389
+ }
375
390
  }
@@ -1,6 +1,5 @@
1
1
  export * from './IConfiguration.js';
2
2
  export * from './ConfigurationBase.js';
3
- export * from './ConfigurationBuilderBase.js';
4
3
  export * from './CustomRequestFunction.js';
5
4
  export * from './remote_config/index.js';
6
5
  export * from './params/index.js';
@@ -6,8 +6,17 @@ export var RemoteConfigUtils;
6
6
  RemoteConfigUtils.isRemoteConfigUpdateRequest = (request) => request.method === HttpMethod.POST &&
7
7
  request.headers.get(PUSH_DATA_FEATURE_HEADER_NAME) === REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
8
8
  !!request.headers.get(PUSH_DATA_HMAC_HEADER_NAME);
9
- RemoteConfigUtils.prepareRemoteConfigParams = (remoteConfigParams, logger) => {
10
- const remoteConfig = Object.assign({}, remoteConfigParams);
9
+ RemoteConfigUtils.prepareRemoteConfigParams = ({ version, configValue }, logger) => {
10
+ const remoteConfig = {
11
+ px_remote_config_version: version,
12
+ px_remote_config_enabled: configValue.px_remote_config_enabled,
13
+ };
14
+ if (!configValue.px_remote_config_enabled) {
15
+ // returning only the version and the fact that remote config is disabled
16
+ // so we can report the version on async activities without merging the rest of the remote configs
17
+ return remoteConfig;
18
+ }
19
+ Object.assign(remoteConfig, configValue);
11
20
  // Remote config receives strings and regexes in separate fields (px_sensitive_routes, px_sensitive_routes_regex)
12
21
  // Before initializing a new active configuration, we merge the two into the more generic field (px_sensitive_routes)
13
22
  CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG.forEach((k) => {
@@ -2,6 +2,6 @@ export * from './constants.js';
2
2
  export * from './model/index.js';
3
3
  export * from './service_client/index.js';
4
4
  export * from './storage_client/index.js';
5
- export * from './DefaultRemoteConfigUpdater.js';
6
- export * from './IRemoteConfigUpdater.js';
5
+ export * from './manager/index.js';
6
+ export * from './update_parser/index.js';
7
7
  export * from './RemoteConfigUtils.js';
@@ -0,0 +1,87 @@
1
+ import { sleep } from '../../../utils/index.js';
2
+ import { WRITE_REMOTE_CONFIG_ERROR_NAME } from '../constants.js';
3
+ export class DefaultRemoteConfigManager {
4
+ config;
5
+ serviceClient;
6
+ storageClient;
7
+ constructor(config, options) {
8
+ this.config = config;
9
+ this.serviceClient = options.serviceClient;
10
+ this.storageClient = options.storageClient;
11
+ }
12
+ async loadRemoteConfig() {
13
+ if (!this.config.remoteConfigId || !this.config.remoteConfigAuthToken) {
14
+ this.config.logger.debug('no remote config id or auth token provided, skipping remote config load');
15
+ return;
16
+ }
17
+ try {
18
+ const remoteConfigData = await this.loadRemoteConfigData();
19
+ if (!!remoteConfigData?.version && remoteConfigData.version > this.config.remoteConfigVersion) {
20
+ this.config.setRemoteConfigData(remoteConfigData);
21
+ }
22
+ }
23
+ catch (e) {
24
+ this.config.logger.debug(`caught error loading remote config: ${e}`);
25
+ }
26
+ }
27
+ async loadRemoteConfigData() {
28
+ const remoteConfigData = await this.storageClient.load();
29
+ if (!remoteConfigData) {
30
+ this.config.logger.debug('unable to load remote config from storage');
31
+ return null;
32
+ }
33
+ if (!this.isValidRemoteConfigId(remoteConfigData.id)) {
34
+ this.config.logger.debug(`remote config ID in static config does not match ID found in storage ${remoteConfigData.id}`);
35
+ return null;
36
+ }
37
+ return remoteConfigData;
38
+ }
39
+ isValidRemoteConfigId(remoteConfigId) {
40
+ return remoteConfigId === this.config.remoteConfigId;
41
+ }
42
+ shouldUpdateRemoteConfig(context) {
43
+ return context.remoteConfigUpdateData.shouldUpdate;
44
+ }
45
+ async updateRemoteConfig(context) {
46
+ const desiredVersion = context.remoteConfigUpdateData.desiredVersion ?? 0;
47
+ const remoteConfigData = await this.fetchRemoteConfigData(desiredVersion, context);
48
+ if (!remoteConfigData) {
49
+ return;
50
+ }
51
+ try {
52
+ await this.storageClient.save(remoteConfigData);
53
+ context.logger.debug(`successfully updated remote config to version ${remoteConfigData.version}`);
54
+ }
55
+ catch (e) {
56
+ context.logger.debug(`unable to save remote config version ${remoteConfigData.version} to storage: ${e}`, {
57
+ errorType: WRITE_REMOTE_CONFIG_ERROR_NAME,
58
+ });
59
+ }
60
+ }
61
+ async fetchRemoteConfigData(desiredVersion, context) {
62
+ try {
63
+ const { remoteConfigMaxFetchAttempts, remoteConfigRetryIntervalMs } = this.config;
64
+ for (let i = 0; i < remoteConfigMaxFetchAttempts; i++) {
65
+ const remoteConfigData = await this.serviceClient.fetch({ version: desiredVersion });
66
+ if (!!remoteConfigData && remoteConfigData.version >= desiredVersion) {
67
+ return remoteConfigData;
68
+ }
69
+ else {
70
+ await this.sleepBetweenFetchAttempts(remoteConfigRetryIntervalMs);
71
+ }
72
+ }
73
+ context.logger.debug(`unable to fetch remote config version ${desiredVersion} or higher: reached ${remoteConfigMaxFetchAttempts} fetch attempts`, {
74
+ errorType: WRITE_REMOTE_CONFIG_ERROR_NAME,
75
+ });
76
+ }
77
+ catch (e) {
78
+ context.logger.debug(`unable to fetch remote config version ${desiredVersion} or higher: ${e}`, {
79
+ errorType: WRITE_REMOTE_CONFIG_ERROR_NAME,
80
+ });
81
+ }
82
+ return null;
83
+ }
84
+ async sleepBetweenFetchAttempts(ms) {
85
+ await sleep(ms);
86
+ }
87
+ }
@@ -0,0 +1,2 @@
1
+ export * from './IRemoteConfigManager.js';
2
+ export * from './DefaultRemoteConfigManager.js';
@@ -1,2 +1,2 @@
1
1
  export * from './RemoteConfigData.js';
2
- export * from './RemoteConfigUpdateRequestData.js';
2
+ export * from './RemoteConfigNotifyRequestPayload.js';
@@ -0,0 +1,60 @@
1
+ import { DefaultTimestampHmacHeaderValidator, PUSH_DATA_FEATURE_HEADER_NAME, PUSH_DATA_HMAC_HEADER_NAME, } from '../../../utils/index.js';
2
+ import { REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME, WRITE_REMOTE_CONFIG_ERROR_NAME } from '../constants.js';
3
+ import { HttpMethod } from '../../../http/index.js';
4
+ export class DefaultNotifyRemoteConfigUpdateParser {
5
+ config;
6
+ timestampHmacHeaderValidator;
7
+ constructor(config, options) {
8
+ this.config = config;
9
+ this.timestampHmacHeaderValidator =
10
+ options.timestampHmacHeaderValidator ??
11
+ new DefaultTimestampHmacHeaderValidator(config, config.remoteConfigAuthToken, options.base64Utils, options.hmacUtils);
12
+ }
13
+ async isUpdateRequest({ requestData: { request } }) {
14
+ return (request.method === HttpMethod.POST &&
15
+ request.headers.get(PUSH_DATA_FEATURE_HEADER_NAME) === REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
16
+ !!request.headers.get(PUSH_DATA_HMAC_HEADER_NAME));
17
+ }
18
+ async parseUpdate(context) {
19
+ if (!(await this.isNotifyRequestValid(context))) {
20
+ return { shouldUpdate: false };
21
+ }
22
+ const updateData = { shouldUpdate: true };
23
+ const desiredVersion = await this.getDesiredRemoteConfigVersion(context);
24
+ context.logger.debug(`got notify request for remote config version ${desiredVersion}`);
25
+ if (desiredVersion) {
26
+ updateData.desiredVersion = desiredVersion;
27
+ }
28
+ return updateData;
29
+ }
30
+ async isNotifyRequestValid(context) {
31
+ const timestampHmacHeader = context.requestData.request.headers.get(PUSH_DATA_HMAC_HEADER_NAME);
32
+ const isValid = !!timestampHmacHeader &&
33
+ (await this.timestampHmacHeaderValidator.isValid(timestampHmacHeader, context.logger));
34
+ if (!isValid) {
35
+ context.logger.debug(`invalid remote config notify request hmac header received: ${timestampHmacHeader}`, {
36
+ errorType: WRITE_REMOTE_CONFIG_ERROR_NAME,
37
+ });
38
+ }
39
+ return isValid;
40
+ }
41
+ async getDesiredRemoteConfigVersion(context) {
42
+ let notifyRequestPayload;
43
+ try {
44
+ notifyRequestPayload = await context.requestData.request.json();
45
+ }
46
+ catch (e) {
47
+ context.logger.debug(`could not parse update request body: ${e}`, {
48
+ errorType: WRITE_REMOTE_CONFIG_ERROR_NAME,
49
+ });
50
+ return null;
51
+ }
52
+ if (!notifyRequestPayload?.version) {
53
+ context.logger.debug(`no version on update request body: ${notifyRequestPayload}`, {
54
+ errorType: WRITE_REMOTE_CONFIG_ERROR_NAME,
55
+ });
56
+ return null;
57
+ }
58
+ return notifyRequestPayload.version;
59
+ }
60
+ }
@@ -0,0 +1,2 @@
1
+ export * from './DefaultNotifyRemoteConfigUpdateParser.js';
2
+ export * from './IRemoteConfigUpdateParser.js';