Skip to content

Commit c5da2b7

Browse files
authored
feat(webhosting): add the CreateWebsite and DeleteWebsite endpoints (#2538)
1 parent 4601ce2 commit c5da2b7

File tree

4 files changed

+90
-15
lines changed

4 files changed

+90
-15
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
marshalMailAccountApiChangeMailAccountPasswordRequest,
3434
marshalMailAccountApiCreateMailAccountRequest,
3535
marshalMailAccountApiRemoveMailAccountRequest,
36+
marshalWebsiteApiCreateWebsiteRequest,
3637
unmarshalBackup,
3738
unmarshalCheckFreeDomainAvailabilityResponse,
3839
unmarshalCheckUserOwnsDomainResponse,
@@ -63,6 +64,7 @@ import {
6364
unmarshalRestoreBackupResponse,
6465
unmarshalSearchDomainsResponse,
6566
unmarshalSession,
67+
unmarshalWebsite,
6668
} from './marshalling.gen.js'
6769
import type {
6870
Backup,
@@ -140,6 +142,9 @@ import type {
140142
RestoreBackupResponse,
141143
SearchDomainsResponse,
142144
Session,
145+
Website,
146+
WebsiteApiCreateWebsiteRequest,
147+
WebsiteApiDeleteWebsiteRequest,
143148
WebsiteApiListWebsitesRequest,
144149
} from './types.gen.js'
145150

@@ -990,7 +995,7 @@ export class HostingAPI extends ParentAPI {
990995
)
991996

992997
/**
993-
* Attach a custom domain to a webhosting.
998+
* Attach a custom domain to a webhosting as an alias to the main domain.
994999
*
9951000
* @param request - The request {@link HostingApiAddCustomDomainRequest}
9961001
* @returns A Promise of HostingSummary
@@ -1365,4 +1370,34 @@ export class WebsiteAPI extends ParentAPI {
13651370
*/
13661371
listWebsites = (request: Readonly<WebsiteApiListWebsitesRequest>) =>
13671372
enrichForPagination('websites', this.pageOfListWebsites, request)
1373+
1374+
/**
1375+
* Create a new website and attach it to a webhosting.
1376+
*
1377+
* @param request - The request {@link WebsiteApiCreateWebsiteRequest}
1378+
* @returns A Promise of Website
1379+
*/
1380+
createWebsite = (request: Readonly<WebsiteApiCreateWebsiteRequest>) =>
1381+
this.client.fetch<Website>(
1382+
{
1383+
body: JSON.stringify(
1384+
marshalWebsiteApiCreateWebsiteRequest(request, this.client.settings),
1385+
),
1386+
headers: jsonContentHeaders,
1387+
method: 'POST',
1388+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/websites`,
1389+
},
1390+
unmarshalWebsite,
1391+
)
1392+
1393+
/**
1394+
* Delete a website from a webhosting.
1395+
*
1396+
* @param request - The request {@link WebsiteApiDeleteWebsiteRequest}
1397+
*/
1398+
deleteWebsite = (request: Readonly<WebsiteApiDeleteWebsiteRequest>) =>
1399+
this.client.fetch<void>({
1400+
method: 'DELETE',
1401+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/websites/${validatePathParam('domainName', request.domainName)}`,
1402+
})
13681403
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export type {
138138
Session,
139139
SyncDomainDnsRecordsRequestRecord,
140140
Website,
141+
WebsiteApiCreateWebsiteRequest,
142+
WebsiteApiDeleteWebsiteRequest,
141143
WebsiteApiListWebsitesRequest,
142144
} from './types.gen.js'
143145
export * as ValidationRules from './validation-rules.gen.js'

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import type {
7979
Session,
8080
SyncDomainDnsRecordsRequestRecord,
8181
Website,
82+
WebsiteApiCreateWebsiteRequest,
8283
} from './types.gen.js'
8384

8485
export const unmarshalBackup = (data: unknown): Backup => {
@@ -224,6 +225,20 @@ export const unmarshalMailAccount = (data: unknown): MailAccount => {
224225
} as MailAccount
225226
}
226227

228+
export const unmarshalWebsite = (data: unknown): Website => {
229+
if (!isJSONObject(data)) {
230+
throw new TypeError(
231+
`Unmarshalling the type 'Website' failed as data isn't a dictionary.`,
232+
)
233+
}
234+
235+
return {
236+
domain: data.domain,
237+
path: data.path,
238+
sslStatus: data.ssl_status,
239+
} as Website
240+
}
241+
227242
const unmarshalFreeDomain = (data: unknown): FreeDomain => {
228243
if (!isJSONObject(data)) {
229244
throw new TypeError(
@@ -705,20 +720,6 @@ export const unmarshalListRecentProgressesResponse = (
705720
} as ListRecentProgressesResponse
706721
}
707722

708-
const unmarshalWebsite = (data: unknown): Website => {
709-
if (!isJSONObject(data)) {
710-
throw new TypeError(
711-
`Unmarshalling the type 'Website' failed as data isn't a dictionary.`,
712-
)
713-
}
714-
715-
return {
716-
domain: data.domain,
717-
path: data.path,
718-
sslStatus: data.ssl_status,
719-
} as Website
720-
}
721-
722723
export const unmarshalListWebsitesResponse = (
723724
data: unknown,
724725
): ListWebsitesResponse => {
@@ -1091,3 +1092,10 @@ export const marshalMailAccountApiRemoveMailAccountRequest = (
10911092
domain: request.domain,
10921093
username: request.username,
10931094
})
1095+
1096+
export const marshalWebsiteApiCreateWebsiteRequest = (
1097+
request: WebsiteApiCreateWebsiteRequest,
1098+
defaults: DefaultValues,
1099+
): Record<string, unknown> => ({
1100+
domain_name: request.domainName,
1101+
})

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,36 @@ export interface Session {
18911891
url: string
18921892
}
18931893

1894+
export type WebsiteApiCreateWebsiteRequest = {
1895+
/**
1896+
* Region to target. If none is passed will use default region from the config.
1897+
*/
1898+
region?: ScwRegion
1899+
/**
1900+
* Hosting ID to which the website is attached to.
1901+
*/
1902+
hostingId: string
1903+
/**
1904+
* The new domain name or subdomain to use for the website.
1905+
*/
1906+
domainName: string
1907+
}
1908+
1909+
export type WebsiteApiDeleteWebsiteRequest = {
1910+
/**
1911+
* Region to target. If none is passed will use default region from the config.
1912+
*/
1913+
region?: ScwRegion
1914+
/**
1915+
* Hosting ID to which the website is detached from.
1916+
*/
1917+
hostingId: string
1918+
/**
1919+
* The new domain name or subdomain attached to the website.
1920+
*/
1921+
domainName: string
1922+
}
1923+
18941924
export type WebsiteApiListWebsitesRequest = {
18951925
/**
18961926
* Region to target. If none is passed will use default region from the config.

0 commit comments

Comments
 (0)