diff --git a/packages_generated/webhosting/src/v1/api.gen.ts b/packages_generated/webhosting/src/v1/api.gen.ts index db373b68f..96fc4ff3a 100644 --- a/packages_generated/webhosting/src/v1/api.gen.ts +++ b/packages_generated/webhosting/src/v1/api.gen.ts @@ -26,6 +26,7 @@ import { marshalDnsApiSyncDomainDnsRecordsRequest, marshalFtpAccountApiChangeFtpAccountPasswordRequest, marshalFtpAccountApiCreateFtpAccountRequest, + marshalHostingApiAddCustomDomainRequest, marshalHostingApiCreateHostingRequest, marshalHostingApiUpdateHostingRequest, marshalMailAccountApiChangeMailAccountPasswordRequest, @@ -39,6 +40,7 @@ import { unmarshalDomain, unmarshalFtpAccount, unmarshalHosting, + unmarshalHostingSummary, unmarshalListBackupItemsResponse, unmarshalListBackupsResponse, unmarshalListControlPanelsResponse, @@ -92,14 +94,17 @@ import type { FtpAccountApiListFtpAccountsRequest, FtpAccountApiRemoveFtpAccountRequest, Hosting, + HostingApiAddCustomDomainRequest, HostingApiCreateHostingRequest, HostingApiCreateSessionRequest, HostingApiDeleteHostingRequest, HostingApiGetHostingRequest, HostingApiGetResourceSummaryRequest, HostingApiListHostingsRequest, + HostingApiRemoveCustomDomainRequest, HostingApiResetHostingPasswordRequest, HostingApiUpdateHostingRequest, + HostingSummary, ListBackupItemsResponse, ListBackupsResponse, ListControlPanelsResponse, @@ -937,6 +942,47 @@ export class HostingAPI extends ParentAPI { }, unmarshalResourceSummary, ) + + /** + * Attach a custom domain to a webhosting. + * + * @param request - The request {@link HostingApiAddCustomDomainRequest} + * @returns A Promise of HostingSummary + */ + addCustomDomain = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalHostingApiAddCustomDomainRequest( + 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)}/add-custom-domain`, + }, + unmarshalHostingSummary, + ) + + /** + * Detach a custom domain from a webhosting. + * + * @param request - The request {@link HostingApiRemoveCustomDomainRequest} + * @returns A Promise of HostingSummary + */ + removeCustomDomain = ( + request: Readonly, + ) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/remove-custom-domain`, + }, + unmarshalHostingSummary, + ) } /** diff --git a/packages_generated/webhosting/src/v1/index.gen.ts b/packages_generated/webhosting/src/v1/index.gen.ts index 936ad321a..fc01d5d4b 100644 --- a/packages_generated/webhosting/src/v1/index.gen.ts +++ b/packages_generated/webhosting/src/v1/index.gen.ts @@ -67,12 +67,14 @@ export type { FtpAccountApiListFtpAccountsRequest, FtpAccountApiRemoveFtpAccountRequest, Hosting, + HostingApiAddCustomDomainRequest, HostingApiCreateHostingRequest, HostingApiCreateSessionRequest, HostingApiDeleteHostingRequest, HostingApiGetHostingRequest, HostingApiGetResourceSummaryRequest, HostingApiListHostingsRequest, + HostingApiRemoveCustomDomainRequest, HostingApiResetHostingPasswordRequest, HostingApiUpdateHostingRequest, HostingDomain, diff --git a/packages_generated/webhosting/src/v1/marshalling.gen.ts b/packages_generated/webhosting/src/v1/marshalling.gen.ts index cd4822eef..d34081085 100644 --- a/packages_generated/webhosting/src/v1/marshalling.gen.ts +++ b/packages_generated/webhosting/src/v1/marshalling.gen.ts @@ -36,6 +36,7 @@ import type { FtpAccountApiChangeFtpAccountPasswordRequest, FtpAccountApiCreateFtpAccountRequest, Hosting, + HostingApiAddCustomDomainRequest, HostingApiCreateHostingRequest, HostingApiUpdateHostingRequest, HostingDomain, @@ -128,6 +129,81 @@ export const unmarshalFtpAccount = (data: unknown): FtpAccount => { } as FtpAccount } +const unmarshalAutoConfigDomainDns = (data: unknown): AutoConfigDomainDns => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AutoConfigDomainDns' failed as data isn't a dictionary.`, + ) + } + + return { + allRecords: data.all_records, + mailRecords: data.mail_records, + nameservers: data.nameservers, + none: data.none, + webRecords: data.web_records, + } as AutoConfigDomainDns +} + +const unmarshalHostingDomainCustomDomain = ( + data: unknown, +): HostingDomainCustomDomain => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'HostingDomainCustomDomain' failed as data isn't a dictionary.`, + ) + } + + return { + autoConfigDomainDns: data.auto_config_domain_dns + ? unmarshalAutoConfigDomainDns(data.auto_config_domain_dns) + : undefined, + dnsStatus: data.dns_status, + domain: data.domain, + domainStatus: data.domain_status, + } as HostingDomainCustomDomain +} + +const unmarshalHostingDomain = (data: unknown): HostingDomain => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'HostingDomain' failed as data isn't a dictionary.`, + ) + } + + return { + customDomain: data.custom_domain + ? unmarshalHostingDomainCustomDomain(data.custom_domain) + : undefined, + subdomain: data.subdomain, + } as HostingDomain +} + +export const unmarshalHostingSummary = (data: unknown): HostingSummary => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'HostingSummary' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + dnsStatus: data.dns_status ? data.dns_status : undefined, + domain: data.domain, + domainInfo: data.domain_info + ? unmarshalHostingDomain(data.domain_info) + : undefined, + domainStatus: data.domain_status ? data.domain_status : undefined, + id: data.id, + offerName: data.offer_name, + projectId: data.project_id, + protected: data.protected, + region: data.region, + status: data.status, + updatedAt: unmarshalDate(data.updated_at), + } as HostingSummary +} + export const unmarshalMailAccount = (data: unknown): MailAccount => { if (!isJSONObject(data)) { throw new TypeError( @@ -155,22 +231,6 @@ export const unmarshalCheckUserOwnsDomainResponse = ( } as CheckUserOwnsDomainResponse } -const unmarshalAutoConfigDomainDns = (data: unknown): AutoConfigDomainDns => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'AutoConfigDomainDns' failed as data isn't a dictionary.`, - ) - } - - return { - allRecords: data.all_records, - mailRecords: data.mail_records, - nameservers: data.nameservers, - none: data.none, - webRecords: data.web_records, - } as AutoConfigDomainDns -} - const unmarshalDnsRecord = (data: unknown): DnsRecord => { if (!isJSONObject(data)) { throw new TypeError( @@ -258,25 +318,6 @@ const unmarshalPlatformControlPanelUrls = ( } as PlatformControlPanelUrls } -const unmarshalHostingDomainCustomDomain = ( - data: unknown, -): HostingDomainCustomDomain => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'HostingDomainCustomDomain' failed as data isn't a dictionary.`, - ) - } - - return { - autoConfigDomainDns: data.auto_config_domain_dns - ? unmarshalAutoConfigDomainDns(data.auto_config_domain_dns) - : undefined, - dnsStatus: data.dns_status, - domain: data.domain, - domainStatus: data.domain_status, - } as HostingDomainCustomDomain -} - const unmarshalOfferOption = (data: unknown): OfferOption => { if (!isJSONObject(data)) { throw new TypeError( @@ -309,21 +350,6 @@ const unmarshalPlatformControlPanel = (data: unknown): PlatformControlPanel => { } as PlatformControlPanel } -const unmarshalHostingDomain = (data: unknown): HostingDomain => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'HostingDomain' failed as data isn't a dictionary.`, - ) - } - - return { - customDomain: data.custom_domain - ? unmarshalHostingDomainCustomDomain(data.custom_domain) - : undefined, - subdomain: data.subdomain, - } as HostingDomain -} - const unmarshalHostingUser = (data: unknown): HostingUser => { if (!isJSONObject(data)) { throw new TypeError( @@ -545,31 +571,6 @@ export const unmarshalListFtpAccountsResponse = ( } as ListFtpAccountsResponse } -const unmarshalHostingSummary = (data: unknown): HostingSummary => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'HostingSummary' failed as data isn't a dictionary.`, - ) - } - - return { - createdAt: unmarshalDate(data.created_at), - dnsStatus: data.dns_status ? data.dns_status : undefined, - domain: data.domain, - domainInfo: data.domain_info - ? unmarshalHostingDomain(data.domain_info) - : undefined, - domainStatus: data.domain_status ? data.domain_status : undefined, - id: data.id, - offerName: data.offer_name, - projectId: data.project_id, - protected: data.protected, - region: data.region, - status: data.status, - updatedAt: unmarshalDate(data.updated_at), - } as HostingSummary -} - export const unmarshalListHostingsResponse = ( data: unknown, ): ListHostingsResponse => { @@ -870,6 +871,13 @@ export const marshalFtpAccountApiCreateFtpAccountRequest = ( username: request.username, }) +export const marshalHostingApiAddCustomDomainRequest = ( + request: HostingApiAddCustomDomainRequest, + defaults: DefaultValues, +): Record => ({ + domain_name: request.domainName, +}) + const marshalCreateHostingRequestDomainConfiguration = ( request: CreateHostingRequestDomainConfiguration, defaults: DefaultValues, diff --git a/packages_generated/webhosting/src/v1/types.gen.ts b/packages_generated/webhosting/src/v1/types.gen.ts index f4d8ed618..7b379d1a1 100644 --- a/packages_generated/webhosting/src/v1/types.gen.ts +++ b/packages_generated/webhosting/src/v1/types.gen.ts @@ -1228,6 +1228,21 @@ export interface Hosting { domainInfo?: HostingDomain } +export type HostingApiAddCustomDomainRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * Hosting ID to which the custom domain is attached to. + */ + hostingId: string + /** + * The custom domain name to attach to the hosting. + */ + domainName: string +} + export type HostingApiCreateHostingRequest = { /** * Region to target. If none is passed will use default region from the config. @@ -1370,6 +1385,17 @@ export type HostingApiListHostingsRequest = { subdomain?: string } +export type HostingApiRemoveCustomDomainRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * Hosting ID to which the custom domain is detached from. + */ + hostingId: string +} + export type HostingApiResetHostingPasswordRequest = { /** * Region to target. If none is passed will use default region from the config.