File size: 5,384 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { UseQueryOptions, useQuery } from '@tanstack/react-query';
import wpcomRequest from 'wpcom-proxy-request';

interface DnssecRecords {
	dnskey?: string;
	dsData?: Array< string >;
}

export interface DomainData {
	primary_domain: boolean;
	blog_name: string;
	blog_id: number;
	subscription_id: string;
	can_manage_dns_records: boolean;
	can_manage_name_servers: boolean;
	can_update_contact_info: boolean;
	cannot_manage_dns_records_reason: unknown;
	cannot_manage_name_servers_reason: unknown;
	cannot_update_contact_info_reason: string | null;
	connection_mode: unknown;
	current_user_can_add_email: boolean;
	current_user_can_create_site_from_domain_only: boolean;
	current_user_cannot_add_email_reason: {
		errors: {
			[ key: string ]: string[];
		};
	};
	current_user_can_manage: boolean;
	current_user_is_owner: boolean;
	can_set_as_primary: boolean;
	can_transfer_to_any_user: boolean;
	can_transfer_to_other_site: boolean;
	dnssec_records?: DnssecRecords;
	domain: string;
	domain_notice_states: unknown;
	supports_domain_connect: unknown;
	email_forwards_count: number;
	expiry: string;
	expiry_soon: boolean;
	expired: boolean;
	auto_renewing: boolean;
	pending_registration: boolean;
	has_registration: boolean;
	has_email_forward_dns_records: unknown;
	points_to_wpcom: boolean;
	privacy_available: boolean;
	private_domain: boolean;
	partner_domain: boolean;
	wpcom_domain: boolean;
	has_pending_contact_update: boolean;
	has_zone: boolean;
	is_dnssec_enabled: boolean;
	is_dnssec_supported: boolean;
	is_gravatar_domain: boolean;
	is_gravatar_restricted_domain: boolean;
	is_hundred_year_domain: boolean;
	is_renewable: boolean;
	is_redeemable: boolean;
	is_subdomain: boolean;
	is_eligible_for_inbound_transfer: boolean;
	is_locked: boolean;
	is_wpcom_staging_domain: boolean;
	transfer_away_eligible_at: string;
	type: 'mapping' | 'wpcom' | 'registered' | 'redirect' | 'transfer';
	registration_date: string;
	auto_renewal_date: string;
	google_apps_subscription: {
		status: string;
		is_eligible_for_introductory_offer: boolean;
		total_user_count: number;
	};
	titan_mail_subscription: {
		status: string;
		is_eligible_for_introductory_offer: boolean;
		maximum_mailbox_count: number;
	};
	pending_whois_update: boolean;
	tld_maintenance_end_time: 0;
	ssl_status: 'active' | 'pending' | 'newly_registered' | 'disabled' | null;
	gdpr_consent_status: string;
	supports_gdpr_consent_management: boolean;
	supports_transfer_approval: boolean;
	domain_registration_agreement_url: string;
	contact_info_disclosure_available: boolean;
	contact_info_disclosed: boolean;
	renewable_until: string;
	redeemable_until: string;
	bundled_plan_subscription_id: string | number | null | undefined;
	product_slug: string;
	owner: string;
	pending_renewal: boolean;
	aftermarket_auction: boolean;
	aftermarket_auction_start: unknown;
	aftermarket_auction_end: string | null;
	nominet_pending_contact_verification_request: boolean;
	nominet_domain_suspended: boolean;
	transfer_status:
		| 'pending_owner'
		| 'pending_registry'
		| 'cancelled'
		| 'completed'
		| 'pending_start'
		| 'pending_async'
		| null;
	last_transfer_error: string;
	has_private_registration: boolean;
	is_pending_icann_verification: boolean;
	is_icann_verification_suspended: boolean;
	is_root_domain_registered_with_automattic: boolean;
	manual_transfer_required: boolean;
	registrar: string;
	domain_locking_available: boolean;
	is_premium: boolean;
	transfer_lock_on_whois_update_optional: boolean;
	transfer_start_date: string;
	whois_update_unmodifiable_fields: [];
	is_whois_editable: boolean;
	pending_transfer: boolean;
	has_wpcom_nameservers: boolean;
	admin_email: string;
	a_records_required_for_mapping: [];
	begin_transfer_until_date: string;
	must_remove_privacy_before_contact_update: boolean;
	registry_expiry_date: string;
	subdomain_part: string;
	auth_code_required: boolean;
	is_mapped_to_atomic_site: boolean;
	is_move_to_new_site_pending: boolean;
	pending_registration_at_registry: boolean;
	pending_registration_at_registry_url: string;
	registered_via_trustee: boolean;
	registered_via_trustee_url: string;
	domain_status?: {
		status: string;
		status_type: string;
		status_weight: number;
	};
}

export interface SiteDomainsQueryFnData {
	domains: DomainData[];
}

export const getSiteDomainsQueryKey = ( siteIdOrSlug: number | string | null | undefined ) => [
	'site-domains',
	siteIdOrSlug,
];

export function useSiteDomainsQuery< TError = unknown, TData = SiteDomainsQueryFnData >(
	siteIdOrSlug: number | string | null | undefined,
	options: Omit< UseQueryOptions< SiteDomainsQueryFnData, TError, TData >, 'queryKey' > = {}
) {
	return useQuery( getSiteDomainsQueryObject( siteIdOrSlug, options ) );
}

export function getSiteDomainsQueryObject< TError = unknown, TData = SiteDomainsQueryFnData >(
	siteIdOrSlug: number | string | null | undefined,
	options: Omit< UseQueryOptions< SiteDomainsQueryFnData, TError, TData >, 'queryKey' > = {}
): UseQueryOptions< SiteDomainsQueryFnData, TError, TData > {
	return {
		queryKey: getSiteDomainsQueryKey( siteIdOrSlug ),
		queryFn: () =>
			wpcomRequest< SiteDomainsQueryFnData >( {
				path: `/sites/${ siteIdOrSlug }/domains`,
				apiVersion: '1.2',
			} ),
		staleTime: 1000 * 60 * 5, // 5 minutes
		...options,
		meta: { persist: false, ...options.meta },
		enabled: Boolean( siteIdOrSlug ) && options.enabled,
	};
}