File size: 1,135 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import wp from 'calypso/lib/wp';
import { sslDetailsQueryKey } from './ssl-details-query-key';

export type DnsRawRecord = {
	host: string;
	class: string;
	type: string;
	ttl: number;
	target?: string;
	ip?: string;
};

export type SslFailureReason = {
	error_type: string;
	message: string;
	records: DnsRawRecord[];
};

export type SslDetails = {
	certificate_provisioned: boolean;
	certificate_expiry_date?: string;
	is_newly_registered: boolean;
	is_expired: boolean;
	last_attempt?: string;
	next_attempt?: string;
	failure_reasons?: SslFailureReason[];
};

export type SslDetailsResponse = {
	data: SslDetails;
	status: string;
};

export default function useSslDetailsQuery( domainName: string ): UseQueryResult< SslDetails > {
	return useQuery( {
		queryKey: sslDetailsQueryKey( domainName ),
		queryFn: () =>
			wp.req.get( {
				path: `/domains/ssl/${ domainName }`,
				apiNamespace: 'wpcom/v2',
			} ),
		refetchOnWindowFocus: false,
		staleTime: 5 * 60 * 1000,
		gcTime: 5 * 60 * 1000,
		select: ( response: SslDetailsResponse ) => response.data,
	} );
}