Skip to content

Commit 9205729

Browse files
authored
feat(webhosting): add custom domain to hosting (#2312)
1 parent 8f23fcf commit 9205729

File tree

4 files changed

+157
-75
lines changed

4 files changed

+157
-75
lines changed

packages_generated/webhosting/src/v1/api.gen.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
marshalDnsApiSyncDomainDnsRecordsRequest,
2727
marshalFtpAccountApiChangeFtpAccountPasswordRequest,
2828
marshalFtpAccountApiCreateFtpAccountRequest,
29+
marshalHostingApiAddCustomDomainRequest,
2930
marshalHostingApiCreateHostingRequest,
3031
marshalHostingApiUpdateHostingRequest,
3132
marshalMailAccountApiChangeMailAccountPasswordRequest,
@@ -39,6 +40,7 @@ import {
3940
unmarshalDomain,
4041
unmarshalFtpAccount,
4142
unmarshalHosting,
43+
unmarshalHostingSummary,
4244
unmarshalListBackupItemsResponse,
4345
unmarshalListBackupsResponse,
4446
unmarshalListControlPanelsResponse,
@@ -92,14 +94,17 @@ import type {
9294
FtpAccountApiListFtpAccountsRequest,
9395
FtpAccountApiRemoveFtpAccountRequest,
9496
Hosting,
97+
HostingApiAddCustomDomainRequest,
9598
HostingApiCreateHostingRequest,
9699
HostingApiCreateSessionRequest,
97100
HostingApiDeleteHostingRequest,
98101
HostingApiGetHostingRequest,
99102
HostingApiGetResourceSummaryRequest,
100103
HostingApiListHostingsRequest,
104+
HostingApiRemoveCustomDomainRequest,
101105
HostingApiResetHostingPasswordRequest,
102106
HostingApiUpdateHostingRequest,
107+
HostingSummary,
103108
ListBackupItemsResponse,
104109
ListBackupsResponse,
105110
ListControlPanelsResponse,
@@ -937,6 +942,47 @@ export class HostingAPI extends ParentAPI {
937942
},
938943
unmarshalResourceSummary,
939944
)
945+
946+
/**
947+
* Attach a custom domain to a webhosting.
948+
*
949+
* @param request - The request {@link HostingApiAddCustomDomainRequest}
950+
* @returns A Promise of HostingSummary
951+
*/
952+
addCustomDomain = (request: Readonly<HostingApiAddCustomDomainRequest>) =>
953+
this.client.fetch<HostingSummary>(
954+
{
955+
body: JSON.stringify(
956+
marshalHostingApiAddCustomDomainRequest(
957+
request,
958+
this.client.settings,
959+
),
960+
),
961+
headers: jsonContentHeaders,
962+
method: 'POST',
963+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/add-custom-domain`,
964+
},
965+
unmarshalHostingSummary,
966+
)
967+
968+
/**
969+
* Detach a custom domain from a webhosting.
970+
*
971+
* @param request - The request {@link HostingApiRemoveCustomDomainRequest}
972+
* @returns A Promise of HostingSummary
973+
*/
974+
removeCustomDomain = (
975+
request: Readonly<HostingApiRemoveCustomDomainRequest>,
976+
) =>
977+
this.client.fetch<HostingSummary>(
978+
{
979+
body: '{}',
980+
headers: jsonContentHeaders,
981+
method: 'POST',
982+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/remove-custom-domain`,
983+
},
984+
unmarshalHostingSummary,
985+
)
940986
}
941987

942988
/**

packages_generated/webhosting/src/v1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ export type {
6767
FtpAccountApiListFtpAccountsRequest,
6868
FtpAccountApiRemoveFtpAccountRequest,
6969
Hosting,
70+
HostingApiAddCustomDomainRequest,
7071
HostingApiCreateHostingRequest,
7172
HostingApiCreateSessionRequest,
7273
HostingApiDeleteHostingRequest,
7374
HostingApiGetHostingRequest,
7475
HostingApiGetResourceSummaryRequest,
7576
HostingApiListHostingsRequest,
77+
HostingApiRemoveCustomDomainRequest,
7678
HostingApiResetHostingPasswordRequest,
7779
HostingApiUpdateHostingRequest,
7880
HostingDomain,

packages_generated/webhosting/src/v1/marshalling.gen.ts

Lines changed: 83 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import type {
3636
FtpAccountApiChangeFtpAccountPasswordRequest,
3737
FtpAccountApiCreateFtpAccountRequest,
3838
Hosting,
39+
HostingApiAddCustomDomainRequest,
3940
HostingApiCreateHostingRequest,
4041
HostingApiUpdateHostingRequest,
4142
HostingDomain,
@@ -128,6 +129,81 @@ export const unmarshalFtpAccount = (data: unknown): FtpAccount => {
128129
} as FtpAccount
129130
}
130131

132+
const unmarshalAutoConfigDomainDns = (data: unknown): AutoConfigDomainDns => {
133+
if (!isJSONObject(data)) {
134+
throw new TypeError(
135+
`Unmarshalling the type 'AutoConfigDomainDns' failed as data isn't a dictionary.`,
136+
)
137+
}
138+
139+
return {
140+
allRecords: data.all_records,
141+
mailRecords: data.mail_records,
142+
nameservers: data.nameservers,
143+
none: data.none,
144+
webRecords: data.web_records,
145+
} as AutoConfigDomainDns
146+
}
147+
148+
const unmarshalHostingDomainCustomDomain = (
149+
data: unknown,
150+
): HostingDomainCustomDomain => {
151+
if (!isJSONObject(data)) {
152+
throw new TypeError(
153+
`Unmarshalling the type 'HostingDomainCustomDomain' failed as data isn't a dictionary.`,
154+
)
155+
}
156+
157+
return {
158+
autoConfigDomainDns: data.auto_config_domain_dns
159+
? unmarshalAutoConfigDomainDns(data.auto_config_domain_dns)
160+
: undefined,
161+
dnsStatus: data.dns_status,
162+
domain: data.domain,
163+
domainStatus: data.domain_status,
164+
} as HostingDomainCustomDomain
165+
}
166+
167+
const unmarshalHostingDomain = (data: unknown): HostingDomain => {
168+
if (!isJSONObject(data)) {
169+
throw new TypeError(
170+
`Unmarshalling the type 'HostingDomain' failed as data isn't a dictionary.`,
171+
)
172+
}
173+
174+
return {
175+
customDomain: data.custom_domain
176+
? unmarshalHostingDomainCustomDomain(data.custom_domain)
177+
: undefined,
178+
subdomain: data.subdomain,
179+
} as HostingDomain
180+
}
181+
182+
export const unmarshalHostingSummary = (data: unknown): HostingSummary => {
183+
if (!isJSONObject(data)) {
184+
throw new TypeError(
185+
`Unmarshalling the type 'HostingSummary' failed as data isn't a dictionary.`,
186+
)
187+
}
188+
189+
return {
190+
createdAt: unmarshalDate(data.created_at),
191+
dnsStatus: data.dns_status ? data.dns_status : undefined,
192+
domain: data.domain,
193+
domainInfo: data.domain_info
194+
? unmarshalHostingDomain(data.domain_info)
195+
: undefined,
196+
domainStatus: data.domain_status ? data.domain_status : undefined,
197+
id: data.id,
198+
offerName: data.offer_name,
199+
projectId: data.project_id,
200+
protected: data.protected,
201+
region: data.region,
202+
status: data.status,
203+
updatedAt: unmarshalDate(data.updated_at),
204+
} as HostingSummary
205+
}
206+
131207
export const unmarshalMailAccount = (data: unknown): MailAccount => {
132208
if (!isJSONObject(data)) {
133209
throw new TypeError(
@@ -155,22 +231,6 @@ export const unmarshalCheckUserOwnsDomainResponse = (
155231
} as CheckUserOwnsDomainResponse
156232
}
157233

158-
const unmarshalAutoConfigDomainDns = (data: unknown): AutoConfigDomainDns => {
159-
if (!isJSONObject(data)) {
160-
throw new TypeError(
161-
`Unmarshalling the type 'AutoConfigDomainDns' failed as data isn't a dictionary.`,
162-
)
163-
}
164-
165-
return {
166-
allRecords: data.all_records,
167-
mailRecords: data.mail_records,
168-
nameservers: data.nameservers,
169-
none: data.none,
170-
webRecords: data.web_records,
171-
} as AutoConfigDomainDns
172-
}
173-
174234
const unmarshalDnsRecord = (data: unknown): DnsRecord => {
175235
if (!isJSONObject(data)) {
176236
throw new TypeError(
@@ -258,25 +318,6 @@ const unmarshalPlatformControlPanelUrls = (
258318
} as PlatformControlPanelUrls
259319
}
260320

261-
const unmarshalHostingDomainCustomDomain = (
262-
data: unknown,
263-
): HostingDomainCustomDomain => {
264-
if (!isJSONObject(data)) {
265-
throw new TypeError(
266-
`Unmarshalling the type 'HostingDomainCustomDomain' failed as data isn't a dictionary.`,
267-
)
268-
}
269-
270-
return {
271-
autoConfigDomainDns: data.auto_config_domain_dns
272-
? unmarshalAutoConfigDomainDns(data.auto_config_domain_dns)
273-
: undefined,
274-
dnsStatus: data.dns_status,
275-
domain: data.domain,
276-
domainStatus: data.domain_status,
277-
} as HostingDomainCustomDomain
278-
}
279-
280321
const unmarshalOfferOption = (data: unknown): OfferOption => {
281322
if (!isJSONObject(data)) {
282323
throw new TypeError(
@@ -309,21 +350,6 @@ const unmarshalPlatformControlPanel = (data: unknown): PlatformControlPanel => {
309350
} as PlatformControlPanel
310351
}
311352

312-
const unmarshalHostingDomain = (data: unknown): HostingDomain => {
313-
if (!isJSONObject(data)) {
314-
throw new TypeError(
315-
`Unmarshalling the type 'HostingDomain' failed as data isn't a dictionary.`,
316-
)
317-
}
318-
319-
return {
320-
customDomain: data.custom_domain
321-
? unmarshalHostingDomainCustomDomain(data.custom_domain)
322-
: undefined,
323-
subdomain: data.subdomain,
324-
} as HostingDomain
325-
}
326-
327353
const unmarshalHostingUser = (data: unknown): HostingUser => {
328354
if (!isJSONObject(data)) {
329355
throw new TypeError(
@@ -545,31 +571,6 @@ export const unmarshalListFtpAccountsResponse = (
545571
} as ListFtpAccountsResponse
546572
}
547573

548-
const unmarshalHostingSummary = (data: unknown): HostingSummary => {
549-
if (!isJSONObject(data)) {
550-
throw new TypeError(
551-
`Unmarshalling the type 'HostingSummary' failed as data isn't a dictionary.`,
552-
)
553-
}
554-
555-
return {
556-
createdAt: unmarshalDate(data.created_at),
557-
dnsStatus: data.dns_status ? data.dns_status : undefined,
558-
domain: data.domain,
559-
domainInfo: data.domain_info
560-
? unmarshalHostingDomain(data.domain_info)
561-
: undefined,
562-
domainStatus: data.domain_status ? data.domain_status : undefined,
563-
id: data.id,
564-
offerName: data.offer_name,
565-
projectId: data.project_id,
566-
protected: data.protected,
567-
region: data.region,
568-
status: data.status,
569-
updatedAt: unmarshalDate(data.updated_at),
570-
} as HostingSummary
571-
}
572-
573574
export const unmarshalListHostingsResponse = (
574575
data: unknown,
575576
): ListHostingsResponse => {
@@ -870,6 +871,13 @@ export const marshalFtpAccountApiCreateFtpAccountRequest = (
870871
username: request.username,
871872
})
872873

874+
export const marshalHostingApiAddCustomDomainRequest = (
875+
request: HostingApiAddCustomDomainRequest,
876+
defaults: DefaultValues,
877+
): Record<string, unknown> => ({
878+
domain_name: request.domainName,
879+
})
880+
873881
const marshalCreateHostingRequestDomainConfiguration = (
874882
request: CreateHostingRequestDomainConfiguration,
875883
defaults: DefaultValues,

packages_generated/webhosting/src/v1/types.gen.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,21 @@ export interface Hosting {
12281228
domainInfo?: HostingDomain
12291229
}
12301230

1231+
export type HostingApiAddCustomDomainRequest = {
1232+
/**
1233+
* Region to target. If none is passed will use default region from the config.
1234+
*/
1235+
region?: ScwRegion
1236+
/**
1237+
* Hosting ID to which the custom domain is attached to.
1238+
*/
1239+
hostingId: string
1240+
/**
1241+
* The custom domain name to attach to the hosting.
1242+
*/
1243+
domainName: string
1244+
}
1245+
12311246
export type HostingApiCreateHostingRequest = {
12321247
/**
12331248
* Region to target. If none is passed will use default region from the config.
@@ -1370,6 +1385,17 @@ export type HostingApiListHostingsRequest = {
13701385
subdomain?: string
13711386
}
13721387

1388+
export type HostingApiRemoveCustomDomainRequest = {
1389+
/**
1390+
* Region to target. If none is passed will use default region from the config.
1391+
*/
1392+
region?: ScwRegion
1393+
/**
1394+
* Hosting ID to which the custom domain is detached from.
1395+
*/
1396+
hostingId: string
1397+
}
1398+
13731399
export type HostingApiResetHostingPasswordRequest = {
13741400
/**
13751401
* Region to target. If none is passed will use default region from the config.

0 commit comments

Comments
 (0)