Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion packages_generated/webhosting/src/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
marshalMailAccountApiChangeMailAccountPasswordRequest,
marshalMailAccountApiCreateMailAccountRequest,
marshalMailAccountApiRemoveMailAccountRequest,
marshalWebsiteApiCreateWebsiteRequest,
unmarshalBackup,
unmarshalCheckFreeDomainAvailabilityResponse,
unmarshalCheckUserOwnsDomainResponse,
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
unmarshalRestoreBackupResponse,
unmarshalSearchDomainsResponse,
unmarshalSession,
unmarshalWebsite,
} from './marshalling.gen.js'
import type {
Backup,
Expand Down Expand Up @@ -140,6 +142,9 @@ import type {
RestoreBackupResponse,
SearchDomainsResponse,
Session,
Website,
WebsiteApiCreateWebsiteRequest,
WebsiteApiDeleteWebsiteRequest,
WebsiteApiListWebsitesRequest,
} from './types.gen.js'

Expand Down Expand Up @@ -990,7 +995,7 @@ export class HostingAPI extends ParentAPI {
)

/**
* Attach a custom domain to a webhosting.
* Attach a custom domain to a webhosting as an alias to the main domain.
*
* @param request - The request {@link HostingApiAddCustomDomainRequest}
* @returns A Promise of HostingSummary
Expand Down Expand Up @@ -1365,4 +1370,34 @@ export class WebsiteAPI extends ParentAPI {
*/
listWebsites = (request: Readonly<WebsiteApiListWebsitesRequest>) =>
enrichForPagination('websites', this.pageOfListWebsites, request)

/**
* Create a new website and attach it to a webhosting.
*
* @param request - The request {@link WebsiteApiCreateWebsiteRequest}
* @returns A Promise of Website
*/
createWebsite = (request: Readonly<WebsiteApiCreateWebsiteRequest>) =>
this.client.fetch<Website>(
{
body: JSON.stringify(
marshalWebsiteApiCreateWebsiteRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/websites`,
},
unmarshalWebsite,
)

/**
* Delete a website from a webhosting.
*
* @param request - The request {@link WebsiteApiDeleteWebsiteRequest}
*/
deleteWebsite = (request: Readonly<WebsiteApiDeleteWebsiteRequest>) =>
this.client.fetch<void>({
method: 'DELETE',
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/websites/${validatePathParam('domainName', request.domainName)}`,
})
}
2 changes: 2 additions & 0 deletions packages_generated/webhosting/src/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export type {
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
WebsiteApiCreateWebsiteRequest,
WebsiteApiDeleteWebsiteRequest,
WebsiteApiListWebsitesRequest,
} from './types.gen.js'
export * as ValidationRules from './validation-rules.gen.js'
36 changes: 22 additions & 14 deletions packages_generated/webhosting/src/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import type {
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
WebsiteApiCreateWebsiteRequest,
} from './types.gen.js'

export const unmarshalBackup = (data: unknown): Backup => {
Expand Down Expand Up @@ -224,6 +225,20 @@ export const unmarshalMailAccount = (data: unknown): MailAccount => {
} as MailAccount
}

export const unmarshalWebsite = (data: unknown): Website => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'Website' failed as data isn't a dictionary.`,
)
}

return {
domain: data.domain,
path: data.path,
sslStatus: data.ssl_status,
} as Website
}

const unmarshalFreeDomain = (data: unknown): FreeDomain => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -705,20 +720,6 @@ export const unmarshalListRecentProgressesResponse = (
} as ListRecentProgressesResponse
}

const unmarshalWebsite = (data: unknown): Website => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'Website' failed as data isn't a dictionary.`,
)
}

return {
domain: data.domain,
path: data.path,
sslStatus: data.ssl_status,
} as Website
}

export const unmarshalListWebsitesResponse = (
data: unknown,
): ListWebsitesResponse => {
Expand Down Expand Up @@ -1091,3 +1092,10 @@ export const marshalMailAccountApiRemoveMailAccountRequest = (
domain: request.domain,
username: request.username,
})

export const marshalWebsiteApiCreateWebsiteRequest = (
request: WebsiteApiCreateWebsiteRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
domain_name: request.domainName,
})
30 changes: 30 additions & 0 deletions packages_generated/webhosting/src/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,36 @@ export interface Session {
url: string
}

export type WebsiteApiCreateWebsiteRequest = {
/**
* Region to target. If none is passed will use default region from the config.
*/
region?: ScwRegion
/**
* Hosting ID to which the website is attached to.
*/
hostingId: string
/**
* The new domain name or subdomain to use for the website.
*/
domainName: string
}

export type WebsiteApiDeleteWebsiteRequest = {
/**
* Region to target. If none is passed will use default region from the config.
*/
region?: ScwRegion
/**
* Hosting ID to which the website is detached from.
*/
hostingId: string
/**
* The new domain name or subdomain attached to the website.
*/
domainName: string
}

export type WebsiteApiListWebsitesRequest = {
/**
* Region to target. If none is passed will use default region from the config.
Expand Down
Loading