{ controls }
diff --git a/projects/plugins/protect/src/js/routes/scan/use-credentials.js b/projects/plugins/protect/src/js/routes/scan/use-credentials.js
deleted file mode 100644
index 77f787153f8e2..0000000000000
--- a/projects/plugins/protect/src/js/routes/scan/use-credentials.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import { useDispatch, useSelect } from '@wordpress/data';
-import { useEffect } from 'react';
-import { STORE_ID } from '../../state/store';
-
-const useCredentials = () => {
- const { checkCredentials } = useDispatch( STORE_ID );
- const credentials = useSelect( select => select( STORE_ID ).getCredentials() );
-
- useEffect( () => {
- if ( ! credentials ) {
- checkCredentials();
- }
- }, [ checkCredentials, credentials ] );
-};
-
-export default useCredentials;
diff --git a/projects/plugins/protect/src/js/routes/scan/use-status-polling.js b/projects/plugins/protect/src/js/routes/scan/use-status-polling.js
deleted file mode 100644
index ad662bc0ca4b4..0000000000000
--- a/projects/plugins/protect/src/js/routes/scan/use-status-polling.js
+++ /dev/null
@@ -1,105 +0,0 @@
-import apiFetch from '@wordpress/api-fetch';
-import { useDispatch, useSelect } from '@wordpress/data';
-import camelize from 'camelize';
-import { useEffect } from 'react';
-import {
- SCAN_IN_PROGRESS_STATUSES,
- SCAN_STATUS_IDLE,
- SCAN_STATUS_UNAVAILABLE,
-} from '../../constants';
-import useAnalyticsTracks from '../../hooks/use-analytics-tracks';
-import { STORE_ID } from '../../state/store';
-
-/**
- * Use Status Polling
- *
- * When the status is 'scheduled' or 'scanning', re-checks the status periodically until it isn't.
- */
-const useStatusPolling = () => {
- const { recordEvent } = useAnalyticsTracks();
- const status = useSelect( select => select( STORE_ID ).getStatus() );
- const { setStatus, setStatusProgress, setStatusIsFetching, setScanIsUnavailable } =
- useDispatch( STORE_ID );
- useEffect( () => {
- let pollTimeout;
- const pollDuration = 10000;
-
- const statusIsInProgress = currentStatus =>
- SCAN_IN_PROGRESS_STATUSES.indexOf( currentStatus ) >= 0;
-
- // if there has never been a scan, and the scan status is idle, then we must still be getting set up
- const scanIsInitializing = ( currentStatus, lastChecked ) =>
- ! lastChecked && SCAN_STATUS_IDLE === currentStatus;
-
- const pollStatus = () => {
- return new Promise( ( resolve, reject ) => {
- apiFetch( {
- path: 'jetpack-protect/v1/status?hard_refresh=true',
- method: 'GET',
- } )
- .then( newStatus => {
- if ( newStatus?.error ) {
- throw newStatus?.error_message;
- }
-
- if (
- statusIsInProgress( newStatus?.status ) ||
- scanIsInitializing( newStatus?.status, newStatus?.last_checked )
- ) {
- setStatusProgress( newStatus?.current_progress );
- pollTimeout = setTimeout( () => {
- pollStatus()
- .then( result => resolve( result ) )
- .catch( error => reject( error ) );
- }, pollDuration );
- return;
- }
-
- resolve( newStatus );
- } )
- .catch( () => {
- // Keep trying when unable to fetch the status.
- setTimeout( () => {
- pollStatus()
- .then( result => resolve( result ) )
- .catch( error => reject( error ) );
- }, 5000 );
- } );
- } );
- };
-
- if (
- ! statusIsInProgress( status?.status ) &&
- ! scanIsInitializing( status?.status, status?.lastChecked )
- ) {
- return;
- }
-
- pollTimeout = setTimeout( () => {
- setStatusIsFetching( true );
- pollStatus()
- .then( newStatus => {
- setScanIsUnavailable( SCAN_STATUS_UNAVAILABLE === newStatus.status );
- setStatus( camelize( newStatus ) );
- recordEvent( 'jetpack_protect_scan_completed', {
- scan_status: newStatus.status,
- } );
- } )
- .finally( () => {
- setStatusIsFetching( false );
- } );
- }, pollDuration );
-
- return () => clearTimeout( pollTimeout );
- }, [
- status?.status,
- status?.lastChecked,
- setScanIsUnavailable,
- setStatus,
- setStatusProgress,
- setStatusIsFetching,
- recordEvent,
- ] );
-};
-
-export default useStatusPolling;
diff --git a/projects/plugins/protect/src/js/state/actions.js b/projects/plugins/protect/src/js/state/actions.js
deleted file mode 100644
index 6a56452681951..0000000000000
--- a/projects/plugins/protect/src/js/state/actions.js
+++ /dev/null
@@ -1,544 +0,0 @@
-import apiFetch from '@wordpress/api-fetch';
-import { sprintf, _n, __ } from '@wordpress/i18n';
-import camelize from 'camelize';
-import API from '../api';
-import { SCAN_STATUS_UNAVAILABLE } from '../constants';
-
-const SET_CREDENTIALS_STATE_IS_FETCHING = 'SET_CREDENTIALS_STATE_IS_FETCHING';
-const SET_CREDENTIALS_STATE = 'SET_CREDENTIALS_STATE';
-const SET_SCAN_HISTORY = 'SET_SCAN_HISTORY';
-const SET_STATUS = 'SET_STATUS';
-const SET_STATUS_PROGRESS = 'SET_STATUS_PROGRESS';
-const START_SCAN_OPTIMISTICALLY = 'START_SCAN_OPTIMISTICALLY';
-const SET_STATUS_IS_FETCHING = 'SET_STATUS_IS_FETCHING';
-const SET_SCAN_IS_UNAVAILABLE = 'SET_SCAN_IS_UNAVAILABLE';
-const SET_SCAN_IS_ENQUEUING = 'SET_SCAN_IS_ENQUEUING';
-const SET_INSTALLED_PLUGINS = 'SET_INSTALLED_PLUGINS';
-const SET_INSTALLED_THEMES = 'SET_INSTALLED_THEMES';
-const SET_WP_VERSION = 'SET_WP_VERSION';
-const SET_JETPACK_SCAN = 'SET_JETPACK_SCAN';
-const SET_PRODUCT_DATA = 'SET_PRODUCT_DATA';
-const SET_THREAT_IS_UPDATING = 'SET_THREAT_IS_UPDATING';
-const SET_THREATS_ARE_FIXING = 'SET_THREATS_ARE_FIXING';
-const SET_MODAL = 'SET_MODAL';
-const SET_NOTICE = 'SET_NOTICE';
-const CLEAR_NOTICE = 'CLEAR_NOTICE';
-const SET_HAS_REQUIRED_PLAN = 'SET_HAS_REQUIRED_PLAN';
-const SET_ONBOARDING_PROGRESS = 'SET_ONBOARDING_PROGRESS';
-
-const SET_WAF_IS_SEEN = 'SET_WAF_IS_SEEN';
-const SET_WAF_UPGRADE_IS_SEEN = 'SET_WAF_UPGRADE_IS_SEEN';
-const SET_WAF_IS_ENABLED = 'SET_WAF_IS_ENABLED';
-const SET_WAF_IS_UPDATING = 'SET_WAF_IS_UPDATING';
-const SET_WAF_IS_TOGGLING = 'SET_WAF_IS_TOGGLING';
-const SET_WAF_CONFIG = 'SET_WAF_CONFIG';
-const SET_WAF_STATS = 'SET_WAF_STATS';
-
-const setScanHistory = scanHistory => {
- return { type: SET_SCAN_HISTORY, scanHistory };
-};
-
-const setStatus = status => {
- return { type: SET_STATUS, status };
-};
-
-const setStatusProgress = currentProgress => {
- return { type: SET_STATUS_PROGRESS, currentProgress };
-};
-
-const startScanOptimistically = () => {
- return { type: START_SCAN_OPTIMISTICALLY };
-};
-
-const refreshPlan =
- () =>
- ( { dispatch } ) => {
- apiFetch( {
- path: 'jetpack-protect/v1/check-plan',
- method: 'GET',
- } ).then( hasRequiredPlan => dispatch( setHasRequiredPlan( hasRequiredPlan ) ) );
- };
-
-/**
- * Fetch Status
- *
- * @param {boolean} hardRefresh - Clears the status cache before fetching, when enabled.
- * @return {Promise} - Promise which resolves with the status request results.
- */
-const fetchStatus = hardRefresh =>
- apiFetch( {
- path: `jetpack-protect/v1/status${ hardRefresh ? '?hard_refresh=true' : '' }`,
- method: 'GET',
- } );
-
-/**
- * Side effect action which will fetch the status from the server
- *
- * @param {boolean} hardRefresh - Clears the status cache before fetching, when enabled.
- * @return {Promise} - Promise which resolves when the status is refreshed from an API fetch.
- */
-const refreshStatus =
- ( hardRefresh = false ) =>
- async ( { dispatch } ) => {
- dispatch( setStatusIsFetching( true ) );
- return await new Promise( ( resolve, reject ) => {
- return fetchStatus( hardRefresh )
- .then( checkStatus )
- .then( status => {
- dispatch( setScanIsUnavailable( SCAN_STATUS_UNAVAILABLE === status.status ) );
- dispatch( setStatus( camelize( status ) ) );
- resolve( status );
- } )
- .catch( error => {
- reject( error );
- } )
- .finally( () => {
- dispatch( setStatusIsFetching( false ) );
- } );
- } );
- };
-
-/**
- * Refresh Scan History
- * @return {Promise} - Promise which resolves with the scan history once it has been fetched.
- */
-const refreshScanHistory = () => {
- return async ( { dispatch } ) => {
- return API.fetchScanHistory()
- .then( scanHistory => camelize( scanHistory ) )
- .then( scanHistory => {
- dispatch( setScanHistory( scanHistory ) );
- } );
- };
-};
-
-/**
- * Check Status
- *
- * @param {object} currentStatus - The status.
- * @param {number} attempts - The amount of recursive attempts that have already been made.
- * @return {Promise} - Promise which resolves with the status once it has been checked.
- */
-const checkStatus = ( currentStatus, attempts = 0 ) => {
- return new Promise( ( resolve, reject ) => {
- if ( SCAN_STATUS_UNAVAILABLE === currentStatus.status && attempts < 3 ) {
- fetchStatus( true )
- .then( newStatus => {
- setTimeout( () => {
- checkStatus( newStatus, attempts + 1 )
- .then( result => resolve( result ) )
- .catch( error => reject( error ) );
- }, 5000 );
- } )
- .catch( reject );
- } else {
- resolve( currentStatus );
- }
- } );
-};
-
-/**
- * Side effect action which will fetch the credential status from the server
- *
- * @return {Promise} - Promise which resolves when the status is refreshed from an API fetch.
- */
-const checkCredentials =
- () =>
- async ( { dispatch } ) => {
- return await new Promise( ( resolve, reject ) => {
- dispatch( setCredentialsIsFetching( true ) );
- return apiFetch( {
- path: 'jetpack-protect/v1/check-credentials',
- method: 'POST',
- } )
- .then( credentials => {
- dispatch( setCredentials( credentials ) );
- resolve( credentials );
- } )
- .catch( error => {
- reject( error );
- } )
- .finally( () => {
- dispatch( setCredentialsIsFetching( false ) );
- } );
- } );
- };
-
-const setCredentialsIsFetching = isFetching => {
- return { type: SET_CREDENTIALS_STATE_IS_FETCHING, isFetching };
-};
-
-const setCredentials = credentials => {
- return { type: SET_CREDENTIALS_STATE, credentials };
-};
-
-const setStatusIsFetching = status => {
- return { type: SET_STATUS_IS_FETCHING, status };
-};
-
-const setScanIsUnavailable = status => {
- return { type: SET_SCAN_IS_UNAVAILABLE, status };
-};
-
-const setScanIsEnqueuing = isEnqueuing => {
- return { type: SET_SCAN_IS_ENQUEUING, isEnqueuing };
-};
-
-const setInstalledPlugins = plugins => {
- return { type: SET_INSTALLED_PLUGINS, plugins };
-};
-
-const setInstalledThemes = themes => {
- return { type: SET_INSTALLED_THEMES, themes };
-};
-
-const setwpVersion = version => {
- return { type: SET_WP_VERSION, version };
-};
-
-const setJetpackScan = scan => {
- return { type: SET_JETPACK_SCAN, scan };
-};
-
-const setThreatIsUpdating = ( threatId, isUpdating ) => {
- return { type: SET_THREAT_IS_UPDATING, payload: { threatId, isUpdating } };
-};
-
-const setThreatsAreFixing = threatIds => {
- return { type: SET_THREATS_ARE_FIXING, threatIds };
-};
-
-const ignoreThreat =
- ( threatId, callback = () => {} ) =>
- async ( { dispatch } ) => {
- dispatch( setThreatIsUpdating( threatId, true ) );
- return await new Promise( () => {
- return apiFetch( {
- path: `jetpack-protect/v1/ignore-threat?threat_id=${ threatId }`,
- method: 'POST',
- } )
- .then( () => {
- return dispatch( refreshStatus() );
- } )
- .then( () => {
- return dispatch( refreshScanHistory() );
- } )
- .then( () => {
- return dispatch(
- setNotice( { type: 'success', message: __( 'Threat ignored', 'jetpack-protect' ) } )
- );
- } )
- .catch( () => {
- return dispatch(
- setNotice( {
- type: 'error',
- message: __( 'An error ocurred ignoring the threat.', 'jetpack-protect' ),
- } )
- );
- } )
- .finally( () => {
- dispatch( setThreatIsUpdating( threatId, false ) );
- callback();
- } );
- } );
- };
-
-const unignoreThreat =
- ( threatId, callback = () => {} ) =>
- async ( { dispatch } ) => {
- dispatch( setThreatIsUpdating( threatId, true ) );
- return await new Promise( () => {
- return apiFetch( {
- path: `jetpack-protect/v1/unignore-threat?threat_id=${ threatId }`,
- method: 'POST',
- } )
- .then( () => {
- return dispatch( refreshScanHistory() );
- } )
- .then( () => {
- return dispatch( refreshStatus() );
- } )
- .then( () => {
- return dispatch(
- setNotice( { type: 'success', message: __( 'Threat unignored', 'jetpack-protect' ) } )
- );
- } )
- .catch( () => {
- return dispatch(
- setNotice( {
- type: 'error',
- message: __( 'An error ocurred unignoring the threat.', 'jetpack-protect' ),
- } )
- );
- } )
- .finally( () => {
- dispatch( setThreatIsUpdating( threatId, false ) );
- callback();
- } );
- } );
- };
-
-const getFixThreatsStatus =
- threatIds =>
- async ( { dispatch } ) => {
- const path = threatIds.reduce( ( carryPath, threatId ) => {
- return `${ carryPath }threat_ids[]=${ threatId }&`;
- }, 'jetpack-protect/v1/fix-threats-status?' );
-
- dispatch( setThreatsAreFixing( threatIds ) );
-
- return await apiFetch( {
- path,
- method: 'GET',
- } )
- .then( async response => {
- const threatArray = Object.values( response.threats );
- const inProgressThreats = threatArray.filter( threat => 'in_progress' === threat.status );
-
- if ( inProgressThreats.length > 0 ) {
- // fix still in progress - try again in another second
- return await new Promise( () => {
- setTimeout( () => {
- dispatch( getFixThreatsStatus( threatIds ) );
- }, 1000 );
- } );
- }
-
- // throw an error if not all threats were fixed
- const fixedThreats = threatArray.filter( threat => threat.status === 'fixed' );
- if ( ! fixedThreats.length === threatIds.length ) {
- throw 'Not all threats could be fixed.';
- }
- } )
- .then( () => {
- // threats fixed - refresh the status
- dispatch( refreshStatus() );
- dispatch( refreshScanHistory() );
- dispatch(
- setNotice( {
- type: 'success',
- message: sprintf(
- // translators: placeholder is the number amount of fixed threats.
- _n(
- '%s threat was fixed successfully',
- '%s threats were fixed successfully',
- threatIds.length,
- 'jetpack-protect'
- ),
- threatIds.length
- ),
- } )
- );
- } )
- .catch( () => {
- dispatch(
- setNotice( {
- type: 'error',
- message: __(
- 'Not all threats could be fixed. Please contact our support.',
- 'jetpack-protect'
- ),
- } )
- );
- } )
- .finally( () => {
- dispatch( setThreatsAreFixing( [] ) );
- } );
- };
-
-const fixThreats =
- ( threatIds, callback = () => {} ) =>
- async ( { dispatch } ) => {
- threatIds.forEach( threatId => {
- dispatch( setThreatIsUpdating( threatId, true ) );
- } );
- return await new Promise( () => {
- return apiFetch( {
- path: `jetpack-protect/v1/fix-threats?threat_ids=${ threatIds }`,
- method: 'POST',
- data: { threatIds },
- } )
- .then( () => {
- return dispatch(
- setNotice( {
- type: 'success',
- message: __(
- "We're hard at work fixing this threat in the background. Please check back shortly.",
- 'jetpack-protect'
- ),
- } )
- );
- } )
- .then( () => {
- // wait one second, then start checking if the threats have been fixed
- setTimeout( () => dispatch( getFixThreatsStatus( threatIds ) ), 1000 );
- } )
- .catch( () => {
- return dispatch(
- setNotice( {
- type: 'error',
- message: __( 'Error fixing threats. Please contact support.', 'jetpack-protect' ),
- } )
- );
- } )
- .finally( () => {
- threatIds.forEach( threatId => {
- dispatch( setThreatIsUpdating( threatId, false ) );
- } );
- callback();
- } );
- } );
- };
-
-const scan =
- ( callback = () => {} ) =>
- async ( { dispatch } ) => {
- dispatch( setScanIsEnqueuing( true ) );
- return await new Promise( () => {
- return apiFetch( {
- path: `jetpack-protect/v1/scan`,
- method: 'POST',
- } )
- .then( () => {
- dispatch( startScanOptimistically() );
- setTimeout( () => dispatch( refreshStatus( true ) ), 5000 );
- } )
- .catch( () => {
- return dispatch(
- setNotice( {
- type: 'error',
- message: __( 'An error ocurred enqueuing the scan', 'jetpack-protect' ),
- } )
- );
- } )
- .finally( () => {
- dispatch( setScanIsEnqueuing( false ) );
- callback();
- } );
- } );
- };
-
-/**
- * Set Modal
- *
- * @param {object} modal - The modal payload to set in state.
- * @param {null|string} modal.type - The modal slug, or null to display no modal.
- * @param {object} modal.props - The props to pass to the modal component.
- * @return {object} The modal action object.
- */
-const setModal = modal => {
- return { type: SET_MODAL, payload: modal };
-};
-
-const setNotice = notice => {
- return { type: SET_NOTICE, payload: notice };
-};
-
-const clearNotice = () => {
- return { type: CLEAR_NOTICE };
-};
-
-const setHasRequiredPlan = hasRequiredPlan => {
- return { type: SET_HAS_REQUIRED_PLAN, hasRequiredPlan };
-};
-
-const setOnboardingProgress = progress => {
- return { type: SET_ONBOARDING_PROGRESS, progress };
-};
-
-const setWafIsEnabled = isEnabled => {
- return { type: SET_WAF_IS_ENABLED, isEnabled };
-};
-
-const setWafIsSeen = isSeen => {
- return { type: SET_WAF_IS_SEEN, isSeen };
-};
-
-const setWafUpgradeIsSeen = upgradeIsSeen => {
- return { type: SET_WAF_UPGRADE_IS_SEEN, upgradeIsSeen };
-};
-
-const setWafIsUpdating = isUpdating => {
- return { type: SET_WAF_IS_UPDATING, isUpdating };
-};
-
-const setWafIsToggling = isToggling => {
- return { type: SET_WAF_IS_TOGGLING, isToggling };
-};
-
-const setWafConfig = config => {
- return { type: SET_WAF_CONFIG, config };
-};
-
-const setWafStats = stats => {
- return { type: SET_WAF_STATS, stats };
-};
-
-const actions = {
- checkCredentials,
- setCredentials,
- setCredentialsIsFetching,
- setScanHistory,
- setStatus,
- setStatusProgress,
- startScanOptimistically,
- refreshStatus,
- refreshScanHistory,
- setStatusIsFetching,
- setScanIsEnqueuing,
- setInstalledPlugins,
- setInstalledThemes,
- setwpVersion,
- setJetpackScan,
- ignoreThreat,
- unignoreThreat,
- setModal,
- setNotice,
- clearNotice,
- fixThreats,
- scan,
- setThreatsAreFixing,
- refreshPlan,
- setHasRequiredPlan,
- setScanIsUnavailable,
- setOnboardingProgress,
- setWafIsEnabled,
- setWafIsSeen,
- setWafUpgradeIsSeen,
- setWafIsUpdating,
- setWafIsToggling,
- setWafConfig,
- setWafStats,
-};
-
-export {
- SET_CREDENTIALS_STATE,
- SET_CREDENTIALS_STATE_IS_FETCHING,
- SET_SCAN_HISTORY,
- SET_STATUS,
- SET_STATUS_PROGRESS,
- START_SCAN_OPTIMISTICALLY,
- SET_STATUS_IS_FETCHING,
- SET_SCAN_IS_UNAVAILABLE,
- SET_SCAN_IS_ENQUEUING,
- SET_INSTALLED_PLUGINS,
- SET_INSTALLED_THEMES,
- SET_WP_VERSION,
- SET_JETPACK_SCAN,
- SET_PRODUCT_DATA,
- SET_THREAT_IS_UPDATING,
- SET_MODAL,
- SET_NOTICE,
- CLEAR_NOTICE,
- SET_THREATS_ARE_FIXING,
- SET_HAS_REQUIRED_PLAN,
- SET_ONBOARDING_PROGRESS,
- SET_WAF_IS_SEEN,
- SET_WAF_UPGRADE_IS_SEEN,
- SET_WAF_IS_ENABLED,
- SET_WAF_IS_UPDATING,
- SET_WAF_IS_TOGGLING,
- SET_WAF_CONFIG,
- SET_WAF_STATS,
- actions as default,
-};
diff --git a/projects/plugins/protect/src/js/state/reducers.js b/projects/plugins/protect/src/js/state/reducers.js
deleted file mode 100644
index ebf4208200ea6..0000000000000
--- a/projects/plugins/protect/src/js/state/reducers.js
+++ /dev/null
@@ -1,228 +0,0 @@
-import { combineReducers } from '@wordpress/data';
-import camelize from 'camelize';
-import { SCAN_STATUS_OPTIMISTICALLY_SCANNING } from '../constants';
-import {
- SET_CREDENTIALS_STATE,
- SET_CREDENTIALS_STATE_IS_FETCHING,
- SET_SCAN_HISTORY,
- SET_STATUS,
- SET_STATUS_PROGRESS,
- START_SCAN_OPTIMISTICALLY,
- SET_STATUS_IS_FETCHING,
- SET_SCAN_IS_UNAVAILABLE,
- SET_SCAN_IS_ENQUEUING,
- SET_INSTALLED_PLUGINS,
- SET_INSTALLED_THEMES,
- SET_WP_VERSION,
- SET_JETPACK_SCAN,
- SET_THREAT_IS_UPDATING,
- SET_MODAL,
- SET_NOTICE,
- CLEAR_NOTICE,
- SET_THREATS_ARE_FIXING,
- SET_HAS_REQUIRED_PLAN,
- SET_ONBOARDING_PROGRESS,
- SET_WAF_IS_SEEN,
- SET_WAF_UPGRADE_IS_SEEN,
- SET_WAF_IS_ENABLED,
- SET_WAF_IS_UPDATING,
- SET_WAF_IS_TOGGLING,
- SET_WAF_CONFIG,
- SET_WAF_STATS,
-} from './actions';
-
-const credentials = ( state = null, action ) => {
- switch ( action.type ) {
- case SET_CREDENTIALS_STATE:
- return action.credentials;
- }
- return state;
-};
-
-const credentialsIsFetching = ( state = false, action ) => {
- switch ( action.type ) {
- case SET_CREDENTIALS_STATE_IS_FETCHING:
- return action.isFetching;
- }
- return state;
-};
-
-const scanHistory = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_SCAN_HISTORY:
- return camelize( action.scanHistory );
- }
- return state;
-};
-
-const status = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_STATUS:
- return action.status;
- case SET_STATUS_PROGRESS:
- return { ...state, currentProgress: action.currentProgress };
- case START_SCAN_OPTIMISTICALLY:
- return { ...state, currentProgress: 0, status: SCAN_STATUS_OPTIMISTICALLY_SCANNING };
- }
- return state;
-};
-
-const statusIsFetching = ( state = false, action ) => {
- switch ( action.type ) {
- case SET_STATUS_IS_FETCHING:
- return action.status;
- }
- return state;
-};
-
-const scanIsUnavailable = ( state = false, action ) => {
- switch ( action.type ) {
- case SET_SCAN_IS_UNAVAILABLE:
- return action.status;
- }
- return state;
-};
-
-const scanIsEnqueuing = ( state = false, action ) => {
- switch ( action.type ) {
- case SET_SCAN_IS_ENQUEUING:
- return action.isEnqueuing;
- }
- return state;
-};
-
-const installedPlugins = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_INSTALLED_PLUGINS:
- return action.plugins;
- }
- return state;
-};
-
-const installedThemes = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_INSTALLED_THEMES:
- return action.themes;
- }
- return state;
-};
-
-const wpVersion = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_WP_VERSION:
- return action.version;
- }
- return state;
-};
-
-const jetpackScan = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_JETPACK_SCAN:
- return action.scan;
- }
- return state;
-};
-
-const threatsUpdating = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_THREAT_IS_UPDATING:
- return { ...state, [ action.payload.threatId ]: action.payload.isUpdating };
- }
- return state;
-};
-
-const threatsAreFixing = ( state = [], action ) => {
- switch ( action.type ) {
- case SET_THREATS_ARE_FIXING:
- return action.threatIds;
- }
- return state;
-};
-
-const modal = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_MODAL:
- return { ...state, ...action.payload };
- }
- return state;
-};
-
-const notice = ( state = {}, action ) => {
- switch ( action.type ) {
- case SET_NOTICE:
- return { ...state, ...action.payload };
- case CLEAR_NOTICE:
- return {};
- }
- return state;
-};
-
-const hasRequiredPlan = ( state = false, action ) => {
- switch ( action.type ) {
- case SET_HAS_REQUIRED_PLAN:
- return action.hasRequiredPlan;
- }
- return state;
-};
-
-const onboardingProgress = ( state = null, action ) => {
- switch ( action.type ) {
- case SET_ONBOARDING_PROGRESS:
- return action.progress;
- }
- return state;
-};
-
-const defaultWaf = {
- wafSupported: null,
- bruteForceSupported: null,
- isSeen: false,
- upgradeIsSeen: false,
- isEnabled: false,
- isUpdating: false,
- isToggling: false,
- config: undefined,
- stats: undefined,
-};
-const waf = ( state = defaultWaf, action ) => {
- switch ( action.type ) {
- case SET_WAF_IS_SEEN:
- return { ...state, isSeen: action.isSeen };
- case SET_WAF_UPGRADE_IS_SEEN:
- return { ...state, upgradeIsSeen: action.upgradeIsSeen };
- case SET_WAF_IS_ENABLED:
- return { ...state, isEnabled: action.isEnabled };
- case SET_WAF_CONFIG:
- return { ...state, config: action.config };
- case SET_WAF_STATS:
- return { ...state, stats: action.stats };
- case SET_WAF_IS_UPDATING:
- return { ...state, isUpdating: action.isUpdating };
- case SET_WAF_IS_TOGGLING:
- return { ...state, isToggling: action.isToggling };
- }
- return state;
-};
-
-const reducers = combineReducers( {
- credentials,
- credentialsIsFetching,
- scanHistory,
- status,
- statusIsFetching,
- scanIsUnavailable,
- scanIsEnqueuing,
- installedPlugins,
- installedThemes,
- wpVersion,
- jetpackScan,
- threatsUpdating,
- modal,
- notice,
- threatsAreFixing,
- hasRequiredPlan,
- onboardingProgress,
- waf,
-} );
-
-export default reducers;
diff --git a/projects/plugins/protect/src/js/state/resolvers.js b/projects/plugins/protect/src/js/state/resolvers.js
deleted file mode 100644
index 40f916ce02375..0000000000000
--- a/projects/plugins/protect/src/js/state/resolvers.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import apiFetch from '@wordpress/api-fetch';
-import actions from './actions';
-
-const resolvers = {
- getJetpackScan: {
- isFulfilled: state => {
- return Object.keys( state?.jetpackScan ).length > 0;
- },
-
- fulfill:
- () =>
- async ( { dispatch } ) => {
- const response = await apiFetch( {
- path: '/my-jetpack/v1/site/products/scan',
- method: 'GET',
- } );
-
- dispatch( actions.setJetpackScan( response ) );
- },
- },
-};
-
-export default resolvers;
diff --git a/projects/plugins/protect/src/js/state/selectors.js b/projects/plugins/protect/src/js/state/selectors.js
deleted file mode 100644
index 5ef5d949f3dbe..0000000000000
--- a/projects/plugins/protect/src/js/state/selectors.js
+++ /dev/null
@@ -1,101 +0,0 @@
-import { __ } from '@wordpress/i18n';
-import { SCAN_IN_PROGRESS_STATUSES, SCAN_STATUS_OPTIMISTICALLY_SCANNING } from '../constants';
-
-/**
- * Scan in progress selector.
- *
- * @param {object} state - The current state.
- * @return {boolean} Whether a scan is in progress.
- */
-const scanInProgress = state => {
- const { status, lastChecked, error } = selectors.getStatus( state );
- const unavailable = selectors.getScanIsUnavailable( state );
-
- // When "optimistically" scanning, ignore any other status or error.
- if ( SCAN_STATUS_OPTIMISTICALLY_SCANNING === status ) {
- return true;
- }
-
- // If the scan is unavailable, scanning is not in progress.
- if ( unavailable ) {
- return false;
- }
-
- // If the status is one of the scanning statuses, we are scanning.
- if ( SCAN_IN_PROGRESS_STATUSES.includes( status ) ) {
- return true;
- }
-
- // If we have no record of a previous scan, we must be queueing up the initial scan.
- if ( ! lastChecked && ! error ) {
- return true;
- }
-
- return false;
-};
-
-/**
- * Scan error selector.
- *
- * @param {object} state - The current state.
- *
- * @typedef {object} ScanError
- * @property {string} code - The code identifying the type of error.
- * @property {string} message - A message describing the error.
- *
- * @return {ScanError|null} The error object or null.
- */
-const scanError = state => {
- const { status, error, errorCode, errorMessage } = selectors.getStatus( state );
- const unavailable = selectors.getScanIsUnavailable( state );
- const isFetching = selectors.getStatusIsFetching( state );
-
- // If the scan results include an error, return it.
- if ( error ) {
- return { code: errorCode, message: errorMessage };
- }
-
- // If the scan is unavailable, return an error.
- if ( unavailable ) {
- return {
- code: 'scan_unavailable',
- message: __( 'We are having problems scanning your site.', 'jetpack-protect' ),
- };
- }
-
- // If there is no status and we are not requesting it, return an error.
- if ( ! status && ! isFetching ) {
- return {
- code: 'scan_unavailable',
- message: __( 'We are having problems scanning your site.', 'jetpack-protect' ),
- };
- }
-
- return null;
-};
-
-const selectors = {
- getCredentials: state => state.credentials || null,
- getCredentialsIsFetching: state => state.credentialsIsFetching || false,
- getInstalledPlugins: state => state.installedPlugins || {},
- getInstalledThemes: state => state.installedThemes || {},
- getScanHistory: state => state.scanHistory || {},
- getStatus: state => state.status || {},
- getStatusIsFetching: state => state.statusIsFetching || false,
- getScanIsUnavailable: state => state.scanIsUnavailable || false,
- getScanIsEnqueuing: state => state.scanIsEnqueuing || false,
- scanInProgress,
- scanError,
- getWpVersion: state => state.wpVersion || '',
- getJetpackScan: state => state.jetpackScan || {},
- getThreatsUpdating: state => state.threatsUpdating || {},
- getModalType: state => state.modal?.type || null,
- getModalProps: state => state.modal?.props || {},
- getNotice: state => state.notice || null,
- getThreatsAreFixing: state => state.threatsAreFixing || [],
- hasRequiredPlan: state => state.hasRequiredPlan || false,
- getOnboardingProgress: state => state.onboardingProgress || null,
- getWaf: state => state.waf,
-};
-
-export default selectors;
diff --git a/projects/plugins/protect/src/js/state/store-holder.js b/projects/plugins/protect/src/js/state/store-holder.js
deleted file mode 100644
index 9956b859ebb31..0000000000000
--- a/projects/plugins/protect/src/js/state/store-holder.js
+++ /dev/null
@@ -1,14 +0,0 @@
-import { createReduxStore, register } from '@wordpress/data';
-
-class storeHolder {
- static store = null;
-
- static mayBeInit( storeId, storeConfig ) {
- if ( null === storeHolder.store ) {
- storeHolder.store = createReduxStore( storeId, storeConfig );
- register( storeHolder.store );
- }
- }
-}
-
-export default storeHolder;
diff --git a/projects/plugins/protect/src/js/state/store.js b/projects/plugins/protect/src/js/state/store.js
deleted file mode 100644
index c1112e549c975..0000000000000
--- a/projects/plugins/protect/src/js/state/store.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import camelize from 'camelize';
-import actions from './actions';
-import reducer from './reducers';
-import resolvers from './resolvers';
-import selectors from './selectors';
-import storeHolder from './store-holder';
-
-const STORE_ID = 'jetpack-protect';
-
-/**
- * Inits redux store for Jetpack Protect
- */
-function initStore() {
- storeHolder.mayBeInit( STORE_ID, {
- __experimentalUseThunks: true, // never stop experiment :sweat_smile:
- reducer,
- actions,
- selectors,
- resolvers,
- initialState: camelize( window.jetpackProtectInitialState ) || {},
- } );
-}
-
-export { STORE_ID, initStore };