-
Notifications
You must be signed in to change notification settings - Fork 862
Expand file tree
/
Copy pathindex.ts
More file actions
86 lines (74 loc) · 2.32 KB
/
index.ts
File metadata and controls
86 lines (74 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { __ } from '@wordpress/i18n';
import { Threat } from '../types/threats.js';
import { getFixerDescription } from '../utils/index.js';
/**
* Threat Action IDs.
*/
export const THREAT_ACTION_VIEW = 'view';
export const THREAT_ACTION_FIX = 'fix';
export const THREAT_ACTION_IGNORE = 'ignore';
export const THREAT_ACTION_UNIGNORE = 'unignore';
export type ThreatAction = {
/** Unique ID of the action. */
id:
| typeof THREAT_ACTION_VIEW
| typeof THREAT_ACTION_FIX
| typeof THREAT_ACTION_IGNORE
| typeof THREAT_ACTION_UNIGNORE;
/** Label of the action. */
label: string | ( ( threats: Threat[] ) => string );
/** Description of the action. */
description?: string | ( ( threats: Threat[] ) => string );
/** Callback function which determines whether the action is eligible to run for a given threat. */
isEligible?: ( threat: Threat ) => boolean;
/** Callback function to run the action. */
callback: (
threats: Threat[],
{ onActionPerformed }?: { onActionPerformed?: ( items: Threat[] ) => void }
) => void;
/** Whether the action should use a confirmation flow. */
requiresConfirmation?: boolean;
/** Whether the action requires a Jetpack connection. */
requiresConnection?: boolean;
/** Wether the action requires site credentials. */
requiresCredentials?: boolean;
};
type ThreatActionBase = Omit< ThreatAction, 'callback' >;
type ThreatActionsObject = Partial< Record< ThreatAction[ 'id' ], ThreatActionBase > >;
/**
* Threat Actions.
*
* Threat action properties keyed by action ID.
*/
export const THREAT_ACTIONS: ThreatActionsObject = {
[ THREAT_ACTION_FIX ]: {
id: THREAT_ACTION_FIX,
label: __( 'Show Auto-Fix', 'jetpack-scan' ),
description: ( threats: Threat[] ) => {
return getFixerDescription( threats[ 0 ] );
},
isEligible( threat ) {
return !! threat.fixable;
},
requiresConfirmation: true,
requiresConnection: true,
requiresCredentials: true,
},
[ THREAT_ACTION_IGNORE ]: {
id: THREAT_ACTION_IGNORE,
label: __( 'Ignore', 'jetpack-scan' ),
isEligible( threat ) {
return threat.status === 'current';
},
requiresConfirmation: true,
requiresConnection: true,
},
[ THREAT_ACTION_UNIGNORE ]: {
id: THREAT_ACTION_UNIGNORE,
label: __( 'Un-ignore', 'jetpack-scan' ),
isEligible( threat ) {
return threat.status === 'ignored';
},
requiresConnection: true,
},
};