-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathchart-summary.js
More file actions
61 lines (59 loc) · 2.42 KB
/
chart-summary.js
File metadata and controls
61 lines (59 loc) · 2.42 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
import { GraphQLObjectType } from 'graphql'
import { categorizedSummaryType } from './categorized-summary'
import { globalIdField } from 'graphql-relay'
import { GraphQLDate } from 'graphql-scalars'
const makeCategory = (key) => ({
type: categorizedSummaryType,
resolve: (parent) => {
const data = parent[key]
const total = data.total
const safe = total > 0
return {
total,
categories: [
{ name: 'pass', count: data.pass, percentage: safe ? Number(((data.pass / total) * 100).toFixed(1)) : 0 },
{ name: 'fail', count: data.fail, percentage: safe ? Number(((data.fail / total) * 100).toFixed(1)) : 0 },
],
}
},
})
export const chartSummaryType = new GraphQLObjectType({
name: 'ChartSummary',
description: `This object contains the information for each type of summary that has been pre-computed`,
fields: () => ({
id: globalIdField('chartSummary'),
date: {
type: GraphQLDate,
description: 'Date that the summary was computed.',
resolve: ({ date }) => date,
},
https: { ...makeCategory('https'), description: 'https summary data' },
dmarc: { ...makeCategory('dmarc'), description: 'dmarc summary data' },
mail: { ...makeCategory('mail'), description: 'Summary based on mail scan results for all domains.' },
web: { ...makeCategory('web'), description: 'Summary based on web scan results for all domains.' },
ssl: { ...makeCategory('ssl'), description: 'Summary based on SSL scan results for all domains.' },
webConnections: {
...makeCategory('web_connections'),
description: 'Summary based on HTTPS and HSTS scan results for all domains.',
},
spf: { ...makeCategory('spf'), description: 'Summary based on SPF scan results for all domains.' },
dkim: { ...makeCategory('dkim'), description: 'Summary based on DKIM scan results for all domains.' },
dmarcPhase: {
type: categorizedSummaryType,
description: 'Summary based on DMARC phases for all domains.',
resolve: ({ dmarc_phase: dmarcPhase }) => {
const total = dmarcPhase.total
const safe = total > 0
const phaseNames = ['assess', 'deploy', 'enforce', 'maintain']
return {
total,
categories: phaseNames.map((name) => ({
name,
count: dmarcPhase[name],
percentage: safe ? Number(((dmarcPhase[name] / total) * 100).toFixed(1)) : 0,
})),
}
},
},
}),
})