-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
customHostnames.ts
356 lines (342 loc) · 9.54 KB
/
customHostnames.ts
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/* SPDX-FileCopyrightText: 2022-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { type Zone } from "./dnsRecords.js";
import { baseUrl, createFetch, HttpMethod, type Credentials } from "./fetch.js";
// #region TypeScript
type FindOptions = {
/**
* Fully qualified domain name to match against. This parameter cannot be used
* with the `id` parameter.
* @example "app.example.com"
*/
hostname?: string;
/**
* Hostname ID to match against. This ID was generated and returned during the
* initial custom_hostname creation. This parameter cannot be used with the
* `hostname` parameter.
* @example "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
*/
id?: string;
/**
* Whether to filter hostnames based on if they have SSL enabled
* @example "example.com"
*/
ssl?: 0 | 1;
/**
* Page number of paginated results (`min: 1`)
* @default 1
*/
page?: number;
/**
* Number of hostnames per page (`min: 5`, `max: 50`)
* @default 20
*/
perPage?: number;
/**
* Field to order hostnames by
* @default "ssl"
*/
order?: "ssl" | "ssl_status";
/**
* Direction to order hostnames
* @example "desc"
*/
direction?: "asc" | "desc";
};
export type CustomHostname = {
/**
* Custom hostname identifier tag (`min length: 36`, `max length: 36`)
* @example "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
*/
id: string;
/**
* Custom hostname that points to zone's hostname via CNAME (`max length: 255`)
* @example "@app.example.com"
*/
hostname: string;
/**
* SSL properties for the custom hostname
*/
ssl: {
/**
* Custom hostname SSL identifier tag (`min length: 36`, `max length: 36`)
* @example "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
*/
id: string;
/**
* Status of the hostname's SSL certificates
*/
status:
| "initializing"
| "pending_validation"
| "pending_issuance"
| "pending_deployment"
| "active"
| "pending_deletion"
| "deleted";
/**
* Domain control validation (DCV) method used for this hostname.
*/
method: "http" | "txt" | "email";
/**
* Level of validation to be used for this hostname. Domain validation (dv) must be used.
*/
type: "dv";
validation_records: Array<{
txt_name: string;
txt_value: string;
http_url: string;
http_body: string;
emails: string[];
}>;
validation_errors: Array<{ message: string }>;
hosts: string[];
issuer: string;
serial_number: string;
signature: string;
uploaded_on: string;
expires_on: string;
custom_csr_id: string;
settings: Record<string, unknown>;
bundle_method: "ubiquitous" | "optimal" | "force";
wildcard: boolean;
certificate_authority: "digicert" | "lets_encrypt";
custom_certificate: string;
custom_key: string;
} | null;
/**
* These are per-hostname (customer) settings.
*/
custom_metadata?: Record<string, unknown>;
/**
* A valid hostname that’s been added to your DNS zone as an A, AAAA,
* or CNAME record.
* @example "origin2.example.com"
*/
custom_origin_server?: string;
/**
* A hostname that will be sent to your custom origin server as SNI for TLS
* handshake. This can be a valid subdomain of the zone or custom origin
* server name or the string ':request_host_header:' which will cause the host
* header in the request to be used as SNI. Not configurable with
* default/fallback origin server.
* @example "sni.example.com"
*/
custom_origin_sni?: string;
/**
* Status of the hostname's activation.
*/
status: "pending" | "active" | "moved" | "deleted";
/**
* These are errors that were encountered while trying to activate a hostname.
*/
verification_errors: string[];
/**
* This is a record which can be placed to activate a hostname.
*/
ownership_verification: {
/**
* DNS Record type
*/
type: "txt";
/**
* DNS Name for record.
* @example "_cf-custom-hostname.app.example.com"
*/
name: string;
/**
* Content for the record.
* @example "5cc07c04-ea62-4a5a-95f0-419334a875a4"
*/
value: string;
};
/**
* This presents the token to be served by the given http url to activate a hostname.
*/
ownership_verification_http: {
/**
* The HTTP URL that will be checked during custom hostname verification and where the customer should host the token.
* @example "http://custom.test.com/.well-known/cf-custom-hostname-challenge/0d89c70d-ad9f-4843-b99f-6cc0252067e9"
*/
http_url: string;
/**
* Token to be served.
* @example "5cc07c04-ea62-4a5a-95f0-419334a875a4"
*/
http_body: string;
};
/**
* This is the time the hostname was created.
* @example "2020-02-06T18:11:23.531995+00:00"
*/
created_at: string;
};
/**
* SSL properties for the custom hostname
*/
type SSL = {
/**
* Domain control validation (DCV) method used for this hostname.
*/
method?: "http" | "txt" | "email";
/**
* Level of validation to be used for this hostname. Domain validation (dv) must be used.
*/
type?: "dv";
/**
* SSL specific settings
*/
settings?: {
/**
* Whether or not HTTP2 is enabled.
*/
http2?: boolean;
/**
* The minimum TLS version supported.
*/
min_tls_version?: "1.0" | "1.1" | "1.2" | "1.3";
/**
* Whether or not TLS 1.3 is enabled.
*/
tls_1_3?: boolean;
/**
* An allowlist of ciphers for TLS termination. These ciphers must be in
* the BoringSSL format.
* @example
* [
* "ECDHE-RSA-AES128-GCM-SHA256",
* "AES128-SHA"
* ]
*/
ciphers?: string[];
/**
* Whether or not Early Hints is enabled.
*/
early_hints?: boolean;
};
/**
* A ubiquitous bundle has the highest probability of being verified
* everywhere, even by clients using outdated or unusual trust stores.
* An optimal bundle uses the shortest chain and newest intermediates.
* And the force bundle verifies the chain, but does not otherwise modify it.
*/
bundle_method?: "ubiquitous" | "optimal" | "force";
/**
* Indicates whether the certificate covers a wildcard.
*/
wildcard?: boolean;
/**
* If a custom uploaded certificate is used
*/
custom_certificate?: string;
/**
* The key for a custom uploaded certificate
*/
custom_key?: string;
};
type CreateParams = {
/**
* The custom hostname that will point to your hostname via CNAME (`max length: 255`).
* @example "app.example.com"
*/
hostname: string;
/**
* SSL properties for the custom hostname
*/
ssl?: SSL;
};
type UpdateParams = {
/**
* SSL properties for the custom hostname
*/
ssl?: SSL;
/**
* These are per-hostname (customer) settings.
* @example
* {
* "key": "value"
* }
*/
custom_metadata?: Record<string, unknown>;
/**
* A valid hostname that’s been added to your DNS zone as an A, AAAA,
* or CNAME record.
* @example "origin2.example.com"
*/
custom_origin_server?: string;
/**
* A hostname that will be sent to your custom origin server as SNI for TLS
* handshake. This can be a valid subdomain of the zone or custom origin
* server name or the string `:request_host_header:` which will cause the host
* header in the request to be used as SNI. Not configurable with
* default/fallback origin server.
*/
custom_origin_sni?: string;
};
// #endregion
/**
* Custom Hostname for a Zone
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-properties
*/
export function customHostnames(options: Zone & Credentials) {
const { zoneId, ...credentials } = options;
const url = `${baseUrl}/zones/${zoneId}/custom_hostnames`;
return {
/**
* Custom Hostname Details
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-custom-hostname-details
*/
get: createFetch((id: string) => ({
method: HttpMethod.GET,
url: `${url}/${id}`,
credentials,
})).response<CustomHostname>(),
/**
* List Custom Hostnames
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-list-custom-hostnames
*/
find: createFetch((params?: FindOptions) => ({
method: HttpMethod.GET,
url,
searchParams: {
hostname: params?.hostname,
id: params?.id,
ssl: params?.ssl,
page: params?.page,
per_page: params?.perPage,
order: params?.order,
direction: params?.direction,
},
credentials,
})).query<CustomHostname>(),
/**
* Create Custom Hostname
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-create-custom-hostname
*/
create: createFetch((params: CreateParams) => ({
method: HttpMethod.POST,
url,
body: JSON.stringify(params),
credentials,
})).response<CustomHostname>(),
/**
* Edit Custom Hostname
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-edit-custom-hostname
*/
update: createFetch((id: string, params: UpdateParams) => ({
method: HttpMethod.PATCH,
url: `${url}/${id}`,
body: JSON.stringify(params),
credentials,
})).response<CustomHostname>(),
/**
* Delete Custom Hostname (and any issued SSL certificates)
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-delete-custom-hostname-and-any-issued-ssl-certificates-
*/
delete: createFetch((id: string) => ({
method: HttpMethod.DELETE,
url: `${url}/${id}`,
credentials,
})).response<{ id: string; ssl: SSL | null; created_at: string }>(),
};
}