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,8 +1,15 @@
|
|
|
1
|
-
import { EnforcerError, ModuleMode, removeSensitiveHeaders
|
|
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
|
-
|
|
64
|
-
requestId
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
79
|
-
remoteConfigId
|
|
80
|
-
|
|
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
|
-
|
|
90
|
-
appUserId
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
tlsCiphersSha
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
httpVersion
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
143
|
-
originalToken
|
|
144
|
-
|
|
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
|
-
|
|
156
|
-
riskRtt
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
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
|
-
|
|
179
|
-
errorReason
|
|
180
|
-
|
|
181
|
-
|
|
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);
|
package/lib/esm/blocker/utils.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
81
|
-
this.
|
|
82
|
-
const
|
|
90
|
+
setRemoteConfigData(remoteConfigData) {
|
|
91
|
+
this.remoteConfigData = remoteConfigData;
|
|
92
|
+
const params = {
|
|
83
93
|
...this.staticConfigParams,
|
|
84
|
-
...RemoteConfigUtils.prepareRemoteConfigParams(
|
|
94
|
+
...RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigData, this.logger),
|
|
85
95
|
};
|
|
86
|
-
this.configParams = this.createActiveConfiguration(
|
|
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
|
|
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
|
}
|
package/lib/esm/config/index.js
CHANGED
|
@@ -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 = (
|
|
10
|
-
const remoteConfig =
|
|
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 './
|
|
6
|
-
export * from './
|
|
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
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './RemoteConfigData.js';
|
|
2
|
-
export * from './
|
|
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
|
+
}
|