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.
- package/lib/cjs/action/Action.js +15 -0
- package/lib/cjs/action/ActionPriorityOrder.js +4 -0
- package/lib/cjs/action/utils.js +20 -0
- package/lib/cjs/activities/HttpActivityClient.js +61 -1
- package/lib/cjs/activities/HttpBatchedActivityClient.js +7 -0
- package/lib/cjs/activities/utils.js +128 -62
- package/lib/cjs/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
- package/lib/cjs/blocker/BlockerBase.js +14 -0
- package/lib/cjs/blocker/JsonBlockerBase.js +5 -0
- package/lib/cjs/blocker/utils.js +13 -0
- package/lib/cjs/config/ConfigurationBase.js +26 -6
- package/lib/cjs/config/index.js +0 -1
- package/lib/cjs/config/remote_config/RemoteConfigUtils.js +12 -2
- package/lib/cjs/config/remote_config/index.js +2 -2
- package/lib/cjs/config/remote_config/manager/DefaultRemoteConfigManager.js +191 -0
- package/lib/cjs/config/remote_config/manager/index.js +18 -0
- package/lib/cjs/config/remote_config/model/index.js +1 -1
- package/lib/cjs/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.js +139 -0
- package/lib/cjs/config/remote_config/update_parser/index.js +18 -0
- package/lib/cjs/context/DefaultContext.js +26 -4
- package/lib/cjs/context/SerializedContext.js +6 -1
- package/lib/cjs/context/interfaces/RemoteConfigUpdateData.js +2 -0
- package/lib/cjs/context/interfaces/index.js +1 -0
- package/lib/cjs/enforcer/EnforcerBase.js +77 -32
- package/lib/cjs/enforcer/IPostEnforcer.js +2 -0
- package/lib/cjs/enforcer/index.js +1 -0
- package/lib/cjs/enforcer/utils.js +34 -38
- package/lib/cjs/{phase/flow → flow}/EndEnforcerFlow.js +13 -7
- package/lib/cjs/{phase/flow → flow}/EnforceFlow.js +10 -15
- package/lib/cjs/{phase/flow → flow}/FilterFlow.js +12 -12
- package/lib/cjs/flow/Flow.js +60 -0
- package/lib/cjs/flow/IFlow.js +2 -0
- package/lib/cjs/{phase/flow → flow}/PostEnforceFlow.js +6 -6
- package/lib/cjs/{phase/flow → flow}/index.js +2 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
- package/lib/cjs/phase/impl/ClearLogsPhase.js +3 -0
- package/lib/cjs/phase/impl/CompositePhase.js +9 -0
- package/lib/cjs/phase/impl/CreateBlockResponsePhase.js +16 -0
- package/lib/cjs/phase/impl/DecideActionPhase.js +11 -0
- package/lib/cjs/phase/impl/EnrichContextFromRequestPhase.js +13 -9
- package/lib/cjs/phase/impl/EnrichContextFromResponsePhase.js +4 -0
- package/lib/cjs/phase/impl/FilterPhase.js +4 -0
- package/lib/cjs/phase/impl/FirstPartyPhase.js +5 -0
- package/lib/cjs/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +80 -0
- package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
- package/lib/cjs/phase/impl/ModifyIncomingRequestPhase.js +5 -0
- package/lib/cjs/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
- package/lib/cjs/phase/impl/ParseTokenPhase.js +14 -7
- package/lib/cjs/phase/impl/PreflightPhase.js +4 -0
- package/lib/cjs/phase/impl/RiskApiPhase.js +18 -7
- package/lib/cjs/phase/impl/{SendAsyncActivitiesOnResponsePhase.js → SendAsyncActivitiesPhase.js} +15 -8
- package/lib/cjs/phase/impl/SendLogsPhase.js +3 -0
- package/lib/cjs/phase/impl/SendTelemetryActivityPhase.js +3 -0
- package/lib/cjs/phase/impl/UpdateRemoteConfigPhase.js +10 -14
- package/lib/cjs/phase/impl/index.js +3 -3
- package/lib/cjs/phase/index.js +0 -1
- package/lib/cjs/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
- package/lib/cjs/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
- package/lib/cjs/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +3 -1
- package/lib/cjs/risk_api/client/GetRiskApiClientV2.js +80 -0
- package/lib/cjs/risk_api/client/PostRiskApiClientV2.js +3 -3
- package/lib/cjs/risk_api/client/PostRiskApiClientV3.js +3 -3
- package/lib/cjs/risk_api/client/abstract/IRiskApiClient.js +2 -0
- package/lib/cjs/risk_api/client/abstract/PostRiskApiClientBase.js +43 -0
- package/lib/cjs/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +22 -69
- package/lib/cjs/risk_api/client/abstract/index.js +19 -0
- package/lib/cjs/risk_api/client/index.js +2 -2
- package/lib/cjs/risk_api/index.js +1 -0
- package/lib/cjs/risk_api/model/GetRiskRequestHeaders.js +185 -0
- package/lib/cjs/risk_api/model/GetRiskResponseHeaders.js +16 -0
- package/lib/cjs/risk_api/model/index.js +2 -0
- package/lib/cjs/{phase/impl/SendAsyncActivitiesOnRequestPhase.js → risk_api/risk_response/PostRiskResponseBase.js} +26 -30
- package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +11 -8
- package/lib/cjs/risk_api/risk_response/index.js +1 -0
- package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
- package/lib/cjs/risk_api/risk_response/v2/GetRiskResponseV2.js +80 -0
- package/lib/cjs/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +10 -10
- package/lib/cjs/risk_api/risk_response/v2/index.js +2 -1
- package/lib/cjs/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +10 -10
- package/lib/cjs/risk_api/risk_response/v3/index.js +1 -1
- package/lib/cjs/risk_api/utils.js +36 -0
- package/lib/cjs/telemetry/DefaultTelemetry.js +12 -9
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/utils.js +1 -19
- package/lib/esm/action/Action.js +15 -0
- package/lib/esm/action/ActionPriorityOrder.js +4 -0
- package/lib/esm/action/utils.js +20 -0
- package/lib/esm/activities/HttpActivityClient.js +61 -1
- package/lib/esm/activities/HttpBatchedActivityClient.js +7 -0
- package/lib/esm/activities/utils.js +128 -63
- package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
- package/lib/esm/blocker/BlockerBase.js +14 -0
- package/lib/esm/blocker/JsonBlockerBase.js +5 -0
- package/lib/esm/blocker/utils.js +13 -0
- package/lib/esm/config/ConfigurationBase.js +23 -8
- package/lib/esm/config/index.js +0 -1
- package/lib/esm/config/remote_config/RemoteConfigUtils.js +11 -2
- package/lib/esm/config/remote_config/index.js +2 -2
- package/lib/esm/config/remote_config/manager/DefaultRemoteConfigManager.js +87 -0
- package/lib/esm/config/remote_config/manager/index.js +2 -0
- package/lib/esm/config/remote_config/model/index.js +1 -1
- package/lib/esm/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.js +60 -0
- package/lib/esm/config/remote_config/update_parser/index.js +2 -0
- package/lib/esm/context/DefaultContext.js +23 -6
- package/lib/esm/context/SerializedContext.js +7 -2
- package/lib/esm/context/interfaces/RemoteConfigUpdateData.js +1 -0
- package/lib/esm/context/interfaces/index.js +1 -0
- package/lib/esm/enforcer/EnforcerBase.js +46 -6
- package/lib/esm/enforcer/IPostEnforcer.js +1 -0
- package/lib/esm/enforcer/index.js +1 -0
- package/lib/esm/enforcer/utils.js +32 -17
- package/lib/esm/flow/EndEnforcerFlow.js +18 -0
- package/lib/esm/flow/EnforceFlow.js +14 -0
- package/lib/esm/{phase/flow → flow}/FilterFlow.js +8 -8
- package/lib/esm/flow/Flow.js +56 -0
- package/lib/esm/flow/IFlow.js +1 -0
- package/lib/esm/flow/PostEnforceFlow.js +10 -0
- package/lib/esm/{phase/flow → flow}/index.js +2 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/logger/LoggerBase.js +1 -1
- package/lib/esm/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
- package/lib/esm/phase/impl/ClearLogsPhase.js +3 -0
- package/lib/esm/phase/impl/CompositePhase.js +9 -0
- package/lib/esm/phase/impl/CreateBlockResponsePhase.js +16 -1
- package/lib/esm/phase/impl/DecideActionPhase.js +11 -0
- package/lib/esm/phase/impl/EnrichContextFromRequestPhase.js +9 -0
- package/lib/esm/phase/impl/EnrichContextFromResponsePhase.js +4 -0
- package/lib/esm/phase/impl/FilterPhase.js +4 -0
- package/lib/esm/phase/impl/FirstPartyPhase.js +5 -0
- package/lib/esm/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +29 -0
- package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
- package/lib/esm/phase/impl/ModifyIncomingRequestPhase.js +5 -0
- package/lib/esm/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
- package/lib/esm/phase/impl/ParseTokenPhase.js +15 -8
- package/lib/esm/phase/impl/PreflightPhase.js +4 -0
- package/lib/esm/phase/impl/RiskApiPhase.js +19 -8
- package/lib/esm/phase/impl/SendAsyncActivitiesPhase.js +16 -0
- package/lib/esm/phase/impl/SendLogsPhase.js +3 -0
- package/lib/esm/phase/impl/SendTelemetryActivityPhase.js +3 -0
- package/lib/esm/phase/impl/UpdateRemoteConfigPhase.js +9 -13
- package/lib/esm/phase/impl/index.js +3 -3
- package/lib/esm/phase/index.js +0 -1
- package/lib/esm/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
- package/lib/esm/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
- package/lib/esm/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +2 -1
- package/lib/esm/risk_api/client/GetRiskApiClientV2.js +57 -0
- package/lib/esm/risk_api/client/PostRiskApiClientV2.js +3 -3
- package/lib/esm/risk_api/client/PostRiskApiClientV3.js +3 -3
- package/lib/esm/risk_api/client/abstract/IRiskApiClient.js +1 -0
- package/lib/esm/risk_api/client/abstract/PostRiskApiClientBase.js +18 -0
- package/lib/esm/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +10 -49
- package/lib/esm/risk_api/client/abstract/index.js +3 -0
- package/lib/esm/risk_api/client/index.js +2 -2
- package/lib/esm/risk_api/index.js +1 -0
- package/lib/esm/risk_api/model/GetRiskRequestHeaders.js +182 -0
- package/lib/esm/risk_api/model/GetRiskResponseHeaders.js +13 -0
- package/lib/esm/risk_api/model/index.js +2 -0
- package/lib/esm/risk_api/risk_response/PostRiskResponseBase.js +6 -0
- package/lib/esm/risk_api/risk_response/RiskResponseBase.js +5 -1
- package/lib/esm/risk_api/risk_response/index.js +1 -0
- package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
- package/lib/esm/risk_api/risk_response/v2/GetRiskResponseV2.js +52 -0
- package/lib/esm/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +2 -2
- package/lib/esm/risk_api/risk_response/v2/index.js +2 -1
- package/lib/esm/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +2 -2
- package/lib/esm/risk_api/risk_response/v3/index.js +1 -1
- package/lib/esm/risk_api/utils.js +23 -0
- package/lib/esm/telemetry/DefaultTelemetry.js +13 -10
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/utils.js +0 -16
- package/lib/types/action/Action.d.ts +15 -0
- package/lib/types/action/ActionData.d.ts +3 -0
- package/lib/types/action/ActionPriorityOrder.d.ts +4 -0
- package/lib/types/action/Decision.d.ts +9 -0
- package/lib/types/action/ProductAction.d.ts +3 -0
- package/lib/types/action/utils.d.ts +20 -0
- package/lib/types/activities/HttpActivityClient.d.ts +57 -1
- package/lib/types/activities/HttpBatchedActivityClient.d.ts +7 -0
- package/lib/types/activities/IActivityClient.d.ts +4 -1
- package/lib/types/activities/model/AsyncActivity.d.ts +3 -0
- package/lib/types/activities/model/AsyncActivityDetails.d.ts +12 -0
- package/lib/types/activities/model/CommonActivityDetails.d.ts +3 -0
- package/lib/types/activities/utils.d.ts +14 -0
- package/lib/types/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +6 -0
- package/lib/types/blocker/BlockerBase.d.ts +21 -0
- package/lib/types/blocker/IBlocker.d.ts +8 -0
- package/lib/types/blocker/IConditionalBlocker.d.ts +4 -0
- package/lib/types/blocker/JsonBlockerBase.d.ts +12 -0
- package/lib/types/blocker/model/BlockData.d.ts +3 -0
- package/lib/types/blocker/utils.d.ts +13 -0
- package/lib/types/config/ConfigurationBase.d.ts +25 -2
- package/lib/types/config/IConfiguration.d.ts +7 -2
- package/lib/types/config/index.d.ts +0 -1
- package/lib/types/config/params/CoreConfigurationParams.d.ts +22 -1
- package/lib/types/config/params/RemoteConfigurationParams.d.ts +3 -0
- package/lib/types/config/params/StaticConfigurationParams.d.ts +3 -0
- package/lib/types/config/remote_config/RemoteConfigUtils.d.ts +2 -1
- package/lib/types/config/remote_config/index.d.ts +2 -2
- package/lib/types/config/remote_config/manager/DefaultRemoteConfigManager.d.ts +23 -0
- package/lib/types/config/remote_config/manager/IRemoteConfigManager.d.ts +7 -0
- package/lib/types/config/remote_config/manager/index.d.ts +2 -0
- package/lib/types/config/remote_config/model/RemoteConfigNotifyRequestPayload.d.ts +3 -0
- package/lib/types/config/remote_config/model/index.d.ts +1 -1
- package/lib/types/config/remote_config/service_client/HttpRemoteConfigServiceClient.d.ts +2 -2
- package/lib/types/config/remote_config/service_client/IRemoteConfigServiceClient.d.ts +2 -2
- package/lib/types/config/remote_config/storage_client/IRemoteConfigStorageClient.d.ts +1 -1
- package/lib/types/config/remote_config/update_parser/DefaultNotifyRemoteConfigUpdateParser.d.ts +22 -0
- package/lib/types/config/remote_config/update_parser/IRemoteConfigUpdateParser.d.ts +5 -0
- package/lib/types/config/remote_config/update_parser/index.d.ts +2 -0
- package/lib/types/context/ContextJson.d.ts +6 -2
- package/lib/types/context/DefaultContext.d.ts +9 -3
- package/lib/types/context/SerializedContext.d.ts +7 -2
- package/lib/types/context/interfaces/IContext.d.ts +4 -3
- package/lib/types/context/interfaces/RemoteConfigUpdateData.d.ts +4 -0
- package/lib/types/context/interfaces/index.d.ts +1 -0
- package/lib/types/custom_parameters/CustomParameters.d.ts +3 -0
- package/lib/types/enforcer/EnforcerBase.d.ts +50 -13
- package/lib/types/enforcer/EnforcerOptions.d.ts +3 -2
- package/lib/types/enforcer/IEnforcer.d.ts +1 -2
- package/lib/types/enforcer/IPostEnforcer.d.ts +3 -0
- package/lib/types/enforcer/index.d.ts +1 -0
- package/lib/types/enforcer/utils.d.ts +7 -1
- package/lib/types/first_party/IFirstParty.d.ts +1 -1
- package/lib/types/flow/EndEnforcerFlow.d.ts +8 -0
- package/lib/types/flow/EnforceFlow.d.ts +8 -0
- package/lib/types/flow/FilterFlow.d.ts +11 -0
- package/lib/types/flow/Flow.d.ts +13 -0
- package/lib/types/flow/IFlow.d.ts +57 -0
- package/lib/types/flow/PostEnforceFlow.d.ts +6 -0
- package/lib/types/{phase/flow → flow}/index.d.ts +2 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/logger/ILogger.d.ts +4 -0
- package/lib/types/logger/LoggerBase.d.ts +1 -1
- package/lib/types/phase/IPhase.d.ts +9 -0
- package/lib/types/phase/PhaseResult.d.ts +11 -0
- package/lib/types/phase/impl/AdditionalActivityHandlerPhase.d.ts +3 -0
- package/lib/types/phase/impl/ClearLogsPhase.d.ts +3 -0
- package/lib/types/phase/impl/CompositePhase.d.ts +9 -0
- package/lib/types/phase/impl/CreateBlockResponsePhase.d.ts +11 -1
- package/lib/types/phase/impl/DecideActionPhase.d.ts +11 -0
- package/lib/types/phase/impl/EnrichContextFromRequestPhase.d.ts +9 -0
- package/lib/types/phase/impl/EnrichContextFromResponsePhase.d.ts +4 -0
- package/lib/types/phase/impl/FilterPhase.d.ts +4 -0
- package/lib/types/phase/impl/FirstPartyPhase.d.ts +5 -0
- package/lib/types/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.d.ts +14 -0
- package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +5 -0
- package/lib/types/phase/impl/ModifyIncomingRequestPhase.d.ts +5 -0
- package/lib/types/phase/impl/ModifyOutgoingResponsePhase.d.ts +5 -0
- package/lib/types/phase/impl/ParseTokenPhase.d.ts +3 -0
- package/lib/types/phase/impl/PreflightPhase.d.ts +4 -0
- package/lib/types/phase/impl/RiskApiPhase.d.ts +5 -0
- package/lib/types/phase/impl/{SendAsyncActivitiesOnResponsePhase.d.ts → SendAsyncActivitiesPhase.d.ts} +5 -2
- package/lib/types/phase/impl/SendLogsPhase.d.ts +3 -0
- package/lib/types/phase/impl/SendTelemetryActivityPhase.d.ts +3 -0
- package/lib/types/phase/impl/UpdateRemoteConfigPhase.d.ts +6 -5
- package/lib/types/phase/impl/index.d.ts +3 -3
- package/lib/types/phase/index.d.ts +0 -1
- package/lib/types/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
- package/lib/types/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.d.ts +1 -1
- package/lib/types/products/interfaces/IProduct.d.ts +28 -0
- package/lib/types/products/interfaces/ProductDataType.d.ts +1 -1
- package/lib/types/risk_api/client/GetRiskApiClientV2.d.ts +15 -0
- package/lib/types/risk_api/client/PostRiskApiClientV2.d.ts +1 -1
- package/lib/types/risk_api/client/PostRiskApiClientV3.d.ts +2 -2
- package/lib/types/risk_api/client/{IRiskApiClient.d.ts → abstract/IRiskApiClient.d.ts} +1 -1
- package/lib/types/risk_api/client/abstract/PostRiskApiClientBase.d.ts +8 -0
- package/lib/types/risk_api/client/abstract/RiskApiClientBase.d.ts +26 -0
- package/lib/types/risk_api/client/abstract/index.d.ts +3 -0
- package/lib/types/risk_api/client/index.d.ts +2 -2
- package/lib/types/risk_api/index.d.ts +1 -0
- package/lib/types/risk_api/model/GetRiskRequestHeaders.d.ts +17 -0
- package/lib/types/risk_api/model/GetRiskResponseHeaders.d.ts +3 -0
- package/lib/types/risk_api/model/index.d.ts +2 -0
- package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +2 -0
- package/lib/types/risk_api/risk_response/PostRiskResponseBase.d.ts +7 -0
- package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +3 -1
- package/lib/types/risk_api/risk_response/index.d.ts +1 -0
- package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
- package/lib/types/risk_api/risk_response/v2/GetRiskResponseV2.d.ts +11 -0
- package/lib/types/risk_api/risk_response/v2/{DefaultRiskResponseV2.d.ts → PostRiskResponseV2.d.ts} +2 -2
- package/lib/types/risk_api/risk_response/v2/index.d.ts +2 -1
- package/lib/types/risk_api/risk_response/v3/{DefaultRiskResponseV3.d.ts → PostRiskResponseV3.d.ts} +2 -2
- package/lib/types/risk_api/risk_response/v3/index.d.ts +1 -1
- package/lib/types/risk_api/utils.d.ts +69 -0
- package/lib/types/telemetry/model/TelemetryActivity.d.ts +1 -1
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/utils.d.ts +0 -5
- package/package.json +13 -13
- package/lib/cjs/config/ConfigurationBuilderBase.js +0 -135
- package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +0 -200
- package/lib/esm/config/ConfigurationBuilderBase.js +0 -66
- package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +0 -99
- package/lib/esm/phase/flow/EndEnforcerFlow.js +0 -12
- package/lib/esm/phase/flow/EnforceFlow.js +0 -18
- package/lib/esm/phase/flow/PostEnforceFlow.js +0 -10
- package/lib/esm/phase/impl/SendAsyncActivitiesOnRequestPhase.js +0 -16
- package/lib/esm/phase/impl/SendAsyncActivitiesOnResponsePhase.js +0 -10
- package/lib/types/config/ConfigurationBuilderBase.d.ts +0 -13
- package/lib/types/config/remote_config/DefaultRemoteConfigUpdater.d.ts +0 -34
- package/lib/types/config/remote_config/IRemoteConfigUpdater.d.ts +0 -6
- package/lib/types/config/remote_config/model/RemoteConfigUpdateRequestData.d.ts +0 -3
- package/lib/types/phase/flow/EndEnforcerFlow.d.ts +0 -8
- package/lib/types/phase/flow/EnforceFlow.d.ts +0 -8
- package/lib/types/phase/flow/FilterFlow.d.ts +0 -11
- package/lib/types/phase/flow/PostEnforceFlow.d.ts +0 -6
- package/lib/types/phase/impl/SendAsyncActivitiesOnRequestPhase.d.ts +0 -10
- package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +0 -40
- /package/lib/cjs/config/remote_config/{IRemoteConfigUpdater.js → manager/IRemoteConfigManager.js} +0 -0
- /package/lib/cjs/config/remote_config/model/{RemoteConfigUpdateRequestData.js → RemoteConfigNotifyRequestPayload.js} +0 -0
- /package/lib/cjs/{risk_api/client/IRiskApiClient.js → config/remote_config/update_parser/IRemoteConfigUpdateParser.js} +0 -0
- /package/lib/esm/config/remote_config/{IRemoteConfigUpdater.js → manager/IRemoteConfigManager.js} +0 -0
- /package/lib/esm/config/remote_config/model/{RemoteConfigUpdateRequestData.js → RemoteConfigNotifyRequestPayload.js} +0 -0
- /package/lib/esm/{risk_api/client/IRiskApiClient.js → config/remote_config/update_parser/IRemoteConfigUpdateParser.js} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RemoteConfigUtils } from '../config/index.js';
|
|
2
1
|
import { BlockAction } from '../blocker/index.js';
|
|
3
2
|
import { PXHDSource } from '../pxhd/index.js';
|
|
4
3
|
import { TokenOrigin, TokenParseResult } from '../risk_token/index.js';
|
|
@@ -7,11 +6,14 @@ import { COOKIE_HEADER_NAME, toReadonlyHeaders, USER_AGENT_HEADER_NAME, } from '
|
|
|
7
6
|
import { isValidUuid, PXHD_COOKIE_NAME, PXVID_COOKIE_NAME, StringSplitCookieParser, X_PX_AUTHORIZATION_HEADER_NAME, } from '../utils/index.js';
|
|
8
7
|
import { Action } from '../action/index.js';
|
|
9
8
|
import { DefaultLogger, X_PX_ENFORCER_LOG_HEADER } from '../logger/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* The default implementation of the request context which uses the incoming HTTP request and enforcer configuration
|
|
11
|
+
* to populate the context with relevant data.
|
|
12
|
+
*/
|
|
10
13
|
export class DefaultContext {
|
|
11
14
|
requestId;
|
|
12
15
|
tokenOrigin;
|
|
13
|
-
|
|
14
|
-
shouldSendLogs;
|
|
16
|
+
remoteConfigUpdateData;
|
|
15
17
|
requestData;
|
|
16
18
|
tokenData;
|
|
17
19
|
riskApiData;
|
|
@@ -35,6 +37,7 @@ export class DefaultContext {
|
|
|
35
37
|
logger;
|
|
36
38
|
usedCookieSecret;
|
|
37
39
|
shouldSendTelemetry;
|
|
40
|
+
_shouldSendLogs = false;
|
|
38
41
|
config;
|
|
39
42
|
urlUtils;
|
|
40
43
|
constructor(config, request, options) {
|
|
@@ -55,8 +58,10 @@ export class DefaultContext {
|
|
|
55
58
|
this.pxdeVerified = false;
|
|
56
59
|
this.action = Action.TRIGGER_RISK_API;
|
|
57
60
|
this.reasons = {};
|
|
58
|
-
this.
|
|
59
|
-
|
|
61
|
+
this.remoteConfigUpdateData = {
|
|
62
|
+
shouldUpdate: false,
|
|
63
|
+
};
|
|
64
|
+
this.shouldSendLogs = this.isHeaderBasedLoggerRequest(config, request);
|
|
60
65
|
this.logger = this.createContextLogger(config, this.shouldSendLogs);
|
|
61
66
|
this.requestData = this.createRequestData(config, request, options.cookieParser);
|
|
62
67
|
this.tokenOrigin = this.getTokenOrigin(request);
|
|
@@ -65,6 +70,18 @@ export class DefaultContext {
|
|
|
65
70
|
}
|
|
66
71
|
this.shouldSendTelemetry = false;
|
|
67
72
|
}
|
|
73
|
+
get shouldSendLogs() {
|
|
74
|
+
return this._shouldSendLogs;
|
|
75
|
+
}
|
|
76
|
+
set shouldSendLogs(shouldSendLogs) {
|
|
77
|
+
if (this._shouldSendLogs === shouldSendLogs) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._shouldSendLogs = shouldSendLogs;
|
|
81
|
+
if (this.logger) {
|
|
82
|
+
this.logger.shouldSaveLogs = shouldSendLogs;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
68
85
|
get isMobile() {
|
|
69
86
|
return this.tokenOrigin === TokenOrigin.HEADER;
|
|
70
87
|
}
|
|
@@ -152,7 +169,7 @@ export class DefaultContext {
|
|
|
152
169
|
action: this.action,
|
|
153
170
|
reasons: this.reasons,
|
|
154
171
|
isMobile: this.isMobile,
|
|
155
|
-
|
|
172
|
+
remoteConfigUpdateData: this.remoteConfigUpdateData,
|
|
156
173
|
productData: this.productData,
|
|
157
174
|
requestData: {
|
|
158
175
|
...this.requestData,
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { DefaultLogger } from '../logger/index.js';
|
|
2
2
|
import { SerializedToken } from '../risk_token/index.js';
|
|
3
3
|
import { SerializedRiskResponse } from '../risk_api/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Implements the `IContext` interface based an already serialized `ContextJson`. This class does not extract data from the
|
|
6
|
+
* incoming request, but rather uses already-extracted data from the `ContextJson` (likely returned from the `DefaultContext.toJSON()`
|
|
7
|
+
* function) and fills in the gaps using the other parameters.
|
|
8
|
+
*/
|
|
4
9
|
export class SerializedContext {
|
|
5
10
|
isMobile;
|
|
6
|
-
|
|
11
|
+
remoteConfigUpdateData;
|
|
7
12
|
logger;
|
|
8
13
|
productData;
|
|
9
14
|
requestData;
|
|
@@ -33,7 +38,7 @@ export class SerializedContext {
|
|
|
33
38
|
this.reasons = contextJson.reasons;
|
|
34
39
|
this.isMobile = contextJson.isMobile;
|
|
35
40
|
this.requestId = contextJson.requestId;
|
|
36
|
-
this.
|
|
41
|
+
this.remoteConfigUpdateData = contextJson.remoteConfigUpdateData;
|
|
37
42
|
this.logger = this.createLogger(config, contextJson.shouldSendLogs, contextJson.logger?.logs);
|
|
38
43
|
this.productData = contextJson.productData;
|
|
39
44
|
this.requestData = this.createRequestData(contextJson, request, urlUtils);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../
|
|
1
|
+
import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../flow/index.js';
|
|
2
2
|
import { createEnforcerInitializationBlock } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* The base class for fundamental enforcer logic.
|
|
5
|
+
*/
|
|
3
6
|
export class EnforcerBase {
|
|
4
7
|
config;
|
|
5
8
|
filterFlow;
|
|
@@ -7,6 +10,7 @@ export class EnforcerBase {
|
|
|
7
10
|
postEnforceFlow;
|
|
8
11
|
endEnforcerFlow;
|
|
9
12
|
activityClient;
|
|
13
|
+
remoteConfigManager;
|
|
10
14
|
/**
|
|
11
15
|
* The EnforcerBase constructor.
|
|
12
16
|
* @param config - The enforcer configuration.
|
|
@@ -17,6 +21,7 @@ export class EnforcerBase {
|
|
|
17
21
|
this.config = config;
|
|
18
22
|
const initializationBlock = createEnforcerInitializationBlock(config, options);
|
|
19
23
|
this.activityClient = initializationBlock.activityClient;
|
|
24
|
+
this.remoteConfigManager = initializationBlock.remoteConfigManager;
|
|
20
25
|
this.filterFlow = this.createFilterFlow(config, initializationBlock);
|
|
21
26
|
this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
|
|
22
27
|
this.postEnforceFlow = this.createPostEnforceFlow(config, initializationBlock);
|
|
@@ -25,15 +30,47 @@ export class EnforcerBase {
|
|
|
25
30
|
this.config.logger.debug('HUMAN enforcer is disabled, will not enforce');
|
|
26
31
|
}
|
|
27
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates the filter flow for the enforcer. The filter flow is responsible for filtering out requests that should not undergo the usual enforcement flow.
|
|
35
|
+
* For example, first party, filtered, CORS preflight, and telemetry requests are filtered out.
|
|
36
|
+
* @param config - The configuration object.
|
|
37
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
38
|
+
* @protected
|
|
39
|
+
* @returns - The filter flow for the enforcer.
|
|
40
|
+
*/
|
|
28
41
|
createFilterFlow(config, initializationBlock) {
|
|
29
42
|
return new FilterFlow(config, initializationBlock);
|
|
30
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates the post enforce flow for the enforcer. The post enforce flow is responsible for any logic that requires the origin response in the case of passed requests.
|
|
46
|
+
* For example, enriching the context with response data (status, login successful information) and modifying the origin response (snippet injection, PXHD) are part of the post enforce flow.
|
|
47
|
+
* @param config - The configuration object.
|
|
48
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
49
|
+
* @protected
|
|
50
|
+
* @returns - The post enforce flow for the enforcer or null if post enforce is not enabled.
|
|
51
|
+
*/
|
|
31
52
|
createPostEnforceFlow(config, initializationBlock) {
|
|
32
|
-
return new PostEnforceFlow(config, initializationBlock);
|
|
53
|
+
return this.config.isPostEnforceEnabled ? new PostEnforceFlow(config, initializationBlock) : null;
|
|
33
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates the enforce flow for the enforcer. The enforce flow is responsible for the core functionality of HUMAN enforcement.
|
|
57
|
+
* For example, parsing HUMAN cookies, performing Risk API, invoking the additional activity handler, and returning a block response are part of the enforce flow.
|
|
58
|
+
* @param config - The configuration object.
|
|
59
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
60
|
+
* @protected
|
|
61
|
+
* @returns - The enforce flow for the enforcer.
|
|
62
|
+
*/
|
|
34
63
|
createEnforceFlow(config, initializationBlock) {
|
|
35
64
|
return new EnforceFlow(config, initializationBlock);
|
|
36
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates the end enforce flow for the enforcer. The end enforce flow is responsible for all actions that must be done after every incoming request.
|
|
68
|
+
* For example, sending the async activities, sending the telemetry activity, or updating the remote config, sending and clearing the enforcer logs, are parts of the end enforce flow.
|
|
69
|
+
* @param config - The configuration object.
|
|
70
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
71
|
+
* @protected
|
|
72
|
+
* @returns - The end enforce flow for the enforcer.
|
|
73
|
+
*/
|
|
37
74
|
createEndEnforcerFlow(config, initializationBlock) {
|
|
38
75
|
return new EndEnforcerFlow(config, initializationBlock);
|
|
39
76
|
}
|
|
@@ -43,6 +80,7 @@ export class EnforcerBase {
|
|
|
43
80
|
* @returns Promise<Res|null> - A Promise resolving to a Res or null depending on the action that should be taken.
|
|
44
81
|
*/
|
|
45
82
|
async enforce(...args) {
|
|
83
|
+
await this.remoteConfigManager?.loadRemoteConfig();
|
|
46
84
|
let context;
|
|
47
85
|
try {
|
|
48
86
|
if (!this.config.moduleEnabled) {
|
|
@@ -69,12 +107,14 @@ export class EnforcerBase {
|
|
|
69
107
|
await this.endEnforcerFlow.execute(context);
|
|
70
108
|
return result.response ? this.convertToRes(result.response, ...args) : null;
|
|
71
109
|
}
|
|
72
|
-
await this.preserveContext(context, ...args);
|
|
73
110
|
result = await this.enforceFlow.execute(context);
|
|
74
|
-
if (result.done) {
|
|
111
|
+
if (result.done || !this.config.isPostEnforceEnabled) {
|
|
75
112
|
await this.endEnforcerFlow.execute(context);
|
|
76
113
|
return result.response ? this.convertToRes(result.response, ...args) : null;
|
|
77
114
|
}
|
|
115
|
+
if (this.config.isPostEnforceEnabled) {
|
|
116
|
+
await this.preserveContext(context, ...args);
|
|
117
|
+
}
|
|
78
118
|
return null;
|
|
79
119
|
}
|
|
80
120
|
/**
|
|
@@ -85,13 +125,13 @@ export class EnforcerBase {
|
|
|
85
125
|
async postEnforce(...args) {
|
|
86
126
|
let context;
|
|
87
127
|
try {
|
|
88
|
-
if (!this.config.moduleEnabled) {
|
|
128
|
+
if (!this.config.moduleEnabled || !this.config.isPostEnforceEnabled) {
|
|
89
129
|
return;
|
|
90
130
|
}
|
|
91
131
|
context = this.retrieveContext(...args);
|
|
92
132
|
if (context) {
|
|
93
133
|
context.response = await this.convertToOutgoingResponse(...args);
|
|
94
|
-
await this.postEnforceFlow
|
|
134
|
+
await this.postEnforceFlow?.execute(context);
|
|
95
135
|
await this.endEnforcerFlow.execute(context);
|
|
96
136
|
}
|
|
97
137
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DefaultTokenV2Parser, DefaultTokenV3Parser, TokenVersion } from '../risk_token/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { DefaultNotifyRemoteConfigUpdateParser, DefaultRemoteConfigManager, HttpRemoteConfigServiceClient, } from '../config/index.js';
|
|
3
3
|
import { DefaultCors } from '../cors/index.js';
|
|
4
4
|
import { DefaultTelemetry } from '../telemetry/index.js';
|
|
5
5
|
import { DefaultDataEnrichment } from '../pxde/index.js';
|
|
@@ -17,7 +17,7 @@ export const createEnforcerInitializationBlock = (config, options) => {
|
|
|
17
17
|
.map((v) => `"${v}"`)
|
|
18
18
|
.join(', ')})`);
|
|
19
19
|
}
|
|
20
|
-
const cipherUtils = tokenVersion === TokenVersion.V2 ? null : options.cipherUtils ?? null;
|
|
20
|
+
const cipherUtils = tokenVersion === TokenVersion.V2 ? null : (options.cipherUtils ?? null);
|
|
21
21
|
if (tokenVersion === TokenVersion.V3 && !cipherUtils) {
|
|
22
22
|
throw new EnforcerError('error initializing enforcer: token v3 requires cipherUtils');
|
|
23
23
|
}
|
|
@@ -39,20 +39,9 @@ export const createEnforcerInitializationBlock = (config, options) => {
|
|
|
39
39
|
? new HttpBatchedActivityClient(config, httpClient)
|
|
40
40
|
: new HttpActivityClient(config, httpClient));
|
|
41
41
|
const logServiceClient = options.logServiceClient || (config.loggerAuthToken ? new HttpLogServiceClient(config, httpClient) : null);
|
|
42
|
-
const remoteConfigStorageClient = options.remoteConfigStorageClient ?? null;
|
|
43
|
-
const remoteConfigServiceClient = options.remoteConfigServiceClient ||
|
|
44
|
-
(config.remoteConfigAuthToken ? new HttpRemoteConfigServiceClient(config, httpClient) : null);
|
|
45
|
-
const remoteConfigUpdater = options.remoteConfigUpdater ||
|
|
46
|
-
(remoteConfigStorageClient && remoteConfigServiceClient
|
|
47
|
-
? new DefaultRemoteConfigUpdater(config, {
|
|
48
|
-
serviceClient: remoteConfigServiceClient,
|
|
49
|
-
storageClient: remoteConfigStorageClient,
|
|
50
|
-
base64Utils,
|
|
51
|
-
hmacUtils,
|
|
52
|
-
})
|
|
53
|
-
: null);
|
|
54
42
|
const snippetInjector = options.snippetInjector ?? null;
|
|
55
43
|
const snippetRetriever = options.snippetRetriever || (snippetInjector ? new DefaultSnippetRetriever(config) : null);
|
|
44
|
+
const remoteConfigClients = createRemoteConfigClients(config, options);
|
|
56
45
|
const allOptions = {
|
|
57
46
|
httpClient,
|
|
58
47
|
base64Utils,
|
|
@@ -69,11 +58,9 @@ export const createEnforcerInitializationBlock = (config, options) => {
|
|
|
69
58
|
riskApiClient,
|
|
70
59
|
activityClient,
|
|
71
60
|
logServiceClient,
|
|
72
|
-
remoteConfigStorageClient,
|
|
73
|
-
remoteConfigServiceClient,
|
|
74
|
-
remoteConfigUpdater,
|
|
75
61
|
snippetInjector,
|
|
76
62
|
snippetRetriever,
|
|
63
|
+
...remoteConfigClients,
|
|
77
64
|
};
|
|
78
65
|
const products = createEnforcerProducts(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
|
|
79
66
|
return { products, ...allOptions };
|
|
@@ -93,3 +80,31 @@ export const createEnforcerProducts = (config, products, base64Utils, hashUtils,
|
|
|
93
80
|
[ProductName.HYPE_SALE_CHALLENGE]: hypeSaleChallenge,
|
|
94
81
|
};
|
|
95
82
|
};
|
|
83
|
+
export const createRemoteConfigClients = (config, options) => {
|
|
84
|
+
const remoteConfigStorageClient = options.remoteConfigStorageClient ?? null;
|
|
85
|
+
let remoteConfigServiceClient = null;
|
|
86
|
+
let remoteConfigManager = null;
|
|
87
|
+
let remoteConfigUpdateParser = null;
|
|
88
|
+
if (remoteConfigStorageClient) {
|
|
89
|
+
remoteConfigServiceClient =
|
|
90
|
+
options.remoteConfigServiceClient ?? new HttpRemoteConfigServiceClient(config, options.httpClient);
|
|
91
|
+
remoteConfigManager =
|
|
92
|
+
options.remoteConfigManager ??
|
|
93
|
+
new DefaultRemoteConfigManager(config, {
|
|
94
|
+
serviceClient: remoteConfigServiceClient,
|
|
95
|
+
storageClient: remoteConfigStorageClient,
|
|
96
|
+
});
|
|
97
|
+
remoteConfigUpdateParser =
|
|
98
|
+
options.remoteConfigUpdateParser ??
|
|
99
|
+
new DefaultNotifyRemoteConfigUpdateParser(config, {
|
|
100
|
+
base64Utils: options.base64Utils,
|
|
101
|
+
hmacUtils: options.hmacUtils,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
remoteConfigServiceClient,
|
|
106
|
+
remoteConfigManager,
|
|
107
|
+
remoteConfigUpdateParser,
|
|
108
|
+
remoteConfigStorageClient,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ClearLogsPhase, SendLogsPhase, SendTelemetryActivityPhase, UpdateRemoteConfigPhase, SendAsyncActivitiesPhase, } from '../phase/index.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
export class EndEnforcerFlow extends Flow {
|
|
4
|
+
constructor(config, { logServiceClient, telemetry, remoteConfigManager, activityClient, }) {
|
|
5
|
+
const phases = [
|
|
6
|
+
new SendAsyncActivitiesPhase(activityClient),
|
|
7
|
+
new SendTelemetryActivityPhase(telemetry),
|
|
8
|
+
];
|
|
9
|
+
if (remoteConfigManager) {
|
|
10
|
+
phases.push(new UpdateRemoteConfigPhase(config, remoteConfigManager));
|
|
11
|
+
}
|
|
12
|
+
if (logServiceClient) {
|
|
13
|
+
phases.push(new SendLogsPhase(config, logServiceClient));
|
|
14
|
+
}
|
|
15
|
+
phases.push(new ClearLogsPhase());
|
|
16
|
+
super(phases);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AdditionalActivityHandlerPhase, CreateBlockResponsePhase, EnrichContextFromRequestPhase, ModifyIncomingRequestPhase, ParseTokenPhase, RiskApiPhase, } from '../phase/index.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
export class EnforceFlow extends Flow {
|
|
4
|
+
constructor(config, { dataEnrichment, tokenParser, riskApiClient, cors, products, graphQLParser, }) {
|
|
5
|
+
super([
|
|
6
|
+
new ParseTokenPhase(tokenParser),
|
|
7
|
+
new EnrichContextFromRequestPhase(config, products, dataEnrichment, graphQLParser),
|
|
8
|
+
new RiskApiPhase(products, riskApiClient),
|
|
9
|
+
new AdditionalActivityHandlerPhase(config),
|
|
10
|
+
new CreateBlockResponsePhase(config, CreateBlockResponsePhase.getBlockers(products), cors),
|
|
11
|
+
new ModifyIncomingRequestPhase(Object.values(products)),
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ProductName } from '
|
|
2
|
-
import { isNullOrUndefined } from '
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ProductName } from '../products/index.js';
|
|
2
|
+
import { isNullOrUndefined } from '../utils/index.js';
|
|
3
|
+
import { FilterPhase, FirstPartyPhase, PreflightPhase, IdentifyTelemetryRequestPhase, IdentifyRemoteConfigNotifyRequestPhase, } from '../phase/index.js';
|
|
4
|
+
import { Flow } from './Flow.js';
|
|
5
|
+
export class FilterFlow extends Flow {
|
|
6
|
+
constructor(config, { httpClient, products, cors, telemetry, remoteConfigUpdateParser, }) {
|
|
6
7
|
const phases = [];
|
|
7
8
|
const firstPartyProducts = FilterFlow.getFirstPartyProducts(products);
|
|
8
9
|
if (firstPartyProducts?.length > 0) {
|
|
@@ -14,9 +15,8 @@ export class FilterFlow extends CompositePhase {
|
|
|
14
15
|
}
|
|
15
16
|
phases.push(new PreflightPhase(config, cors));
|
|
16
17
|
phases.push(new IdentifyTelemetryRequestPhase(telemetry));
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
phases.push(updateRemoteConfigPhase);
|
|
18
|
+
if (remoteConfigUpdateParser) {
|
|
19
|
+
phases.push(new IdentifyRemoteConfigNotifyRequestPhase(remoteConfigUpdateParser));
|
|
20
20
|
}
|
|
21
21
|
super(phases);
|
|
22
22
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CompositePhase } from '../phase/index.js';
|
|
2
|
+
export class Flow {
|
|
3
|
+
phases;
|
|
4
|
+
constructor(phases) {
|
|
5
|
+
this.phases = phases;
|
|
6
|
+
}
|
|
7
|
+
insert(phase, options) {
|
|
8
|
+
if (!options) {
|
|
9
|
+
this.phases.push(phase);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (options.before) {
|
|
13
|
+
const index = this.getIndexOfPhase(options.before);
|
|
14
|
+
if (index === -1) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.phases.splice(index, 0, phase);
|
|
18
|
+
}
|
|
19
|
+
if (options.after) {
|
|
20
|
+
const index = this.getIndexOfPhase(options.after);
|
|
21
|
+
if (index === -1) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.phases.splice(index + 1, 0, phase);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
remove(name) {
|
|
28
|
+
const index = this.getIndexOfPhase(name);
|
|
29
|
+
if (index === -1) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.phases.splice(index, 1);
|
|
33
|
+
}
|
|
34
|
+
replace(name, phase) {
|
|
35
|
+
const index = this.getIndexOfPhase(name);
|
|
36
|
+
if (index === -1) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.phases.splice(index, 1, phase);
|
|
40
|
+
}
|
|
41
|
+
move(name, to) {
|
|
42
|
+
const index = this.getIndexOfPhase(name);
|
|
43
|
+
if (index === -1) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const phase = this.phases[index];
|
|
47
|
+
this.phases.splice(index, 1);
|
|
48
|
+
this.insert(phase, to);
|
|
49
|
+
}
|
|
50
|
+
getIndexOfPhase(name) {
|
|
51
|
+
return this.phases.findIndex((existingPhase) => existingPhase.constructor.name === name);
|
|
52
|
+
}
|
|
53
|
+
execute(context) {
|
|
54
|
+
return new CompositePhase(this.phases).execute(context);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EnrichContextFromResponsePhase, ModifyOutgoingResponsePhase } from '../phase/index.js';
|
|
2
|
+
import { Flow } from './Flow.js';
|
|
3
|
+
export class PostEnforceFlow extends Flow {
|
|
4
|
+
constructor(config, { products, snippetRetriever, snippetInjector, }) {
|
|
5
|
+
super([
|
|
6
|
+
new EnrichContextFromResponsePhase(config, products),
|
|
7
|
+
new ModifyOutgoingResponsePhase(config, Object.values(products), snippetRetriever, snippetInjector),
|
|
8
|
+
]);
|
|
9
|
+
}
|
|
10
|
+
}
|
package/lib/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './sensitive_request/index.js';
|
|
|
9
9
|
export * from './monitored_request/index.js';
|
|
10
10
|
export * from './snippet_injection/index.js';
|
|
11
11
|
export * from './cors/index.js';
|
|
12
|
+
export * from './flow/index.js';
|
|
12
13
|
export * from './enforcer/index.js';
|
|
13
14
|
export * from './filter/index.js';
|
|
14
15
|
export * from './first_party/index.js';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { AdditionalActivityHandlerUtils } from '../../additional_activity_handler/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `AdditionalActivityHandlerPhase` invokes the additional activity handler defined in the configuration.
|
|
4
|
+
*/
|
|
2
5
|
export class AdditionalActivityHandlerPhase {
|
|
3
6
|
config;
|
|
4
7
|
constructor(config) {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `CompositePhase` class executes a series of phases in sequence.
|
|
3
|
+
* It will stop executing phases as soon as one of them returns a result with `done: true`.
|
|
4
|
+
* It will return the result of the last phase executed or `{ done: false }`.
|
|
5
|
+
*/
|
|
1
6
|
export class CompositePhase {
|
|
2
7
|
phases;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new CompositePhase instance.
|
|
10
|
+
* @param phases - An array of phases to be executed in sequence.
|
|
11
|
+
*/
|
|
3
12
|
constructor(phases) {
|
|
4
13
|
this.phases = phases;
|
|
5
14
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { MinimalResponseUtils } from '../../http/index.js';
|
|
2
2
|
import { PXHDSource, PXHDUtils } from '../../pxhd/index.js';
|
|
3
3
|
import { Action } from '../../action/index.js';
|
|
4
|
-
import { PRODUCT_PRIORITY_ORDER } from '../../products/index.js';
|
|
4
|
+
import { PRODUCT_PRIORITY_ORDER, ProductName } from '../../products/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* `CreateBlockResponsePhase` is a phase that creates a block response for the product that recommended a block action.
|
|
7
|
+
* If multiple products recommended block, it will return the block response for the highest priority product.
|
|
8
|
+
*/
|
|
5
9
|
export class CreateBlockResponsePhase {
|
|
6
10
|
config;
|
|
7
11
|
blockers;
|
|
@@ -13,6 +17,17 @@ export class CreateBlockResponsePhase {
|
|
|
13
17
|
this.cors = cors;
|
|
14
18
|
}
|
|
15
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A static method that identifies those products that can block incoming requests and returns a map of the product name to the product instance.
|
|
22
|
+
* @param products - All supported products.
|
|
23
|
+
* @returns A mapping of those products that implement the `IConditionalBlocker` interface.
|
|
24
|
+
*/
|
|
25
|
+
static getBlockers(products) {
|
|
26
|
+
return {
|
|
27
|
+
[ProductName.BOT_DEFENDER]: products[ProductName.BOT_DEFENDER],
|
|
28
|
+
[ProductName.HYPE_SALE_CHALLENGE]: products[ProductName.HYPE_SALE_CHALLENGE],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
16
31
|
async execute(context) {
|
|
17
32
|
if (context.action !== Action.BLOCK) {
|
|
18
33
|
return { done: false };
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { LoggerSeverity } from '../../logger/index.js';
|
|
2
2
|
import { Action, getDecisionFromContext } from '../../action/index.js';
|
|
3
3
|
import { BlockAction } from '../../blocker/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* `DecideActionPhase` is an abstract class that provides the protected function `updateContextDecision`.
|
|
6
|
+
* Phases that extend this class can use the `updateContextDecision` method to update the `context.action` and
|
|
7
|
+
* `context.reasons` properties based on the product data in the context. Calling this function essentially
|
|
8
|
+
* recalculates what action the enforcer should take and why.
|
|
9
|
+
*/
|
|
4
10
|
export class DecideActionPhase {
|
|
11
|
+
/**
|
|
12
|
+
* Updates the `action`, `reasons`, and `blockAction` properties based on the product data in the context.
|
|
13
|
+
* @param context - The request context.
|
|
14
|
+
* @protected
|
|
15
|
+
*/
|
|
5
16
|
async updateContextDecision(context) {
|
|
6
17
|
const { action, reasons } = getDecisionFromContext(context);
|
|
7
18
|
if (context.logger.getLoggerSeverity() === LoggerSeverity.DEBUG) {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { CustomParametersUtils } from '../../custom_parameters/index.js';
|
|
2
2
|
import { DecideActionPhase } from './DecideActionPhase.js';
|
|
3
|
+
/**
|
|
4
|
+
* `EnrichContextFromRequestPhase` adds data to the context from the request. This includes parsing the data enrichment cookie,
|
|
5
|
+
* adding GraphQL data, custom parameters, and enriching the context with any product-specific data by calling each product's
|
|
6
|
+
* `enrichContextFromRequest` method. (As an example, this is where the Credential Intelligence product enriches the context by
|
|
7
|
+
* extracting login credentials and adding them to the product data of the request.) It then updates the context's final action
|
|
8
|
+
* and reasons based on the enriched data.
|
|
9
|
+
*
|
|
10
|
+
* Note: This phase should come after the `ParseTokenPhase`, since the Bot Defender product uses the parsed token to determine its recommended action.
|
|
11
|
+
*/
|
|
3
12
|
export class EnrichContextFromRequestPhase extends DecideActionPhase {
|
|
4
13
|
config;
|
|
5
14
|
products;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { isNullOrUndefined } from '../../utils/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* `EnrichContextFromResponsePhase` enriches the context with response data. Each product's `enrichContextFromResponse`
|
|
4
|
+
* method is called since every product may use the response data differently.
|
|
5
|
+
*/
|
|
2
6
|
export class EnrichContextFromResponsePhase {
|
|
3
7
|
config;
|
|
4
8
|
products;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `FilterPhase` class checks if the provided filters indicate that the incoming HTTP request should be filtered from the flow.
|
|
3
|
+
* If any filter returns `true` for `shouldFilter`, the phase will stop further processing and return a `done` status.
|
|
4
|
+
*/
|
|
1
5
|
export class FilterPhase {
|
|
2
6
|
filters;
|
|
3
7
|
constructor(filters) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { MinimalResponseUtils } from '../../http/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `FirstPartyPhase` class is responsible for handling first-party requests. If a first-party request is detected,
|
|
4
|
+
* it will create the `FirstPartyData`, send the request to the configured endpoint using the provided HTTP client, and return
|
|
5
|
+
* a done status with the response. If an error occurs, it will return the default response.
|
|
6
|
+
*/
|
|
2
7
|
export class FirstPartyPhase {
|
|
3
8
|
config;
|
|
4
9
|
httpClient;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MinimalResponseImpl } from '../../http/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `IdentifyRemoteConfigNotifyRequestPhase` class is responsible for identifying incoming remote config update requests.
|
|
4
|
+
* It checks if the request is a remote config update request and, if so, parses the request and updates the context accordingly.
|
|
5
|
+
* Note that the remote config is not updated during this phase; that occurs in the `UpdateRemoteConfigPhase`.
|
|
6
|
+
*/
|
|
7
|
+
export class IdentifyRemoteConfigNotifyRequestPhase {
|
|
8
|
+
remoteConfigUpdateParser;
|
|
9
|
+
constructor(remoteConfigUpdateParser) {
|
|
10
|
+
this.remoteConfigUpdateParser = remoteConfigUpdateParser;
|
|
11
|
+
}
|
|
12
|
+
async execute(context) {
|
|
13
|
+
if (!(await this.remoteConfigUpdateParser.isUpdateRequest(context))) {
|
|
14
|
+
return { done: false };
|
|
15
|
+
}
|
|
16
|
+
context.shouldSendLogs = true;
|
|
17
|
+
const { shouldUpdate, desiredVersion } = await this.remoteConfigUpdateParser.parseUpdate(context);
|
|
18
|
+
context.remoteConfigUpdateData.shouldUpdate = shouldUpdate;
|
|
19
|
+
context.remoteConfigUpdateData.desiredVersion = desiredVersion;
|
|
20
|
+
return {
|
|
21
|
+
done: true,
|
|
22
|
+
response: new MinimalResponseImpl({
|
|
23
|
+
status: shouldUpdate ? 200 : 400,
|
|
24
|
+
body: shouldUpdate ? 'OK' : 'Bad Request',
|
|
25
|
+
headers: {},
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `IdentifyTelemetryRequestPhase` class is responsible for identifying incoming telemetry requests.
|
|
3
|
+
* It checks if the request is a telemetry request and, if so, parses the request and updates the context accordingly.
|
|
4
|
+
* Note that the telemetry activity is not sent during this phase; that occurs in the `SendTelemetryActivityPhase`.
|
|
5
|
+
*/
|
|
1
6
|
export class IdentifyTelemetryRequestPhase {
|
|
2
7
|
telemetry;
|
|
3
8
|
constructor(telemetry) {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ModifyIncomingRequestPhase` class is responsible for modifying the incoming HTTP request prior to forwarding the
|
|
3
|
+
* request to the origin server or cache. This phase invokes each product's `modifyIncomingRequest` method. (As an example,
|
|
4
|
+
* this is where the Credential Intelligence product adds the compromised credentials header to the request if needed.)
|
|
5
|
+
*/
|
|
1
6
|
export class ModifyIncomingRequestPhase {
|
|
2
7
|
products;
|
|
3
8
|
constructor(products) {
|