diff --git a/packages/clients/src/api/webhosting/v1/api.gen.ts b/packages/clients/src/api/webhosting/v1/api.gen.ts index 0838ffdb8..c443046dc 100644 --- a/packages/clients/src/api/webhosting/v1/api.gen.ts +++ b/packages/clients/src/api/webhosting/v1/api.gen.ts @@ -15,6 +15,7 @@ import { marshalDatabaseApiCreateDatabaseRequest, marshalDatabaseApiCreateDatabaseUserRequest, marshalDatabaseApiUnassignDatabaseUserRequest, + marshalDnsApiCheckUserOwnsDomainRequest, marshalFtpAccountApiChangeFtpAccountPasswordRequest, marshalFtpAccountApiCreateFtpAccountRequest, marshalHostingApiCreateHostingRequest, @@ -22,8 +23,10 @@ import { marshalMailAccountApiChangeMailAccountPasswordRequest, marshalMailAccountApiCreateMailAccountRequest, marshalMailAccountApiRemoveMailAccountRequest, + unmarshalCheckUserOwnsDomainResponse, unmarshalDatabase, unmarshalDatabaseUser, + unmarshalDnsRecords, unmarshalFtpAccount, unmarshalHosting, unmarshalListControlPanelsResponse, @@ -40,6 +43,7 @@ import { unmarshalSession, } from './marshalling.gen' import type { + CheckUserOwnsDomainResponse, ControlPanelApiListControlPanelsRequest, Database, DatabaseApiAssignDatabaseUserRequest, @@ -54,6 +58,9 @@ import type { DatabaseApiListDatabasesRequest, DatabaseApiUnassignDatabaseUserRequest, DatabaseUser, + DnsApiCheckUserOwnsDomainRequest, + DnsApiGetDomainDnsRecordsRequest, + DnsRecords, FtpAccount, FtpAccountApiChangeFtpAccountPasswordRequest, FtpAccountApiCreateFtpAccountRequest, @@ -93,13 +100,13 @@ const jsonContentHeaders = { } /** - * Web Hosting API. + * Web Hosting Control Panel API. * * This API allows you to manage your Web Hosting services. */ export class ControlPanelAPI extends ParentAPI { /** Lists the available regions of the API. */ - public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams'] + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw'] protected pageOfListControlPanels = ( request: Readonly = {}, @@ -380,6 +387,54 @@ export class DatabaseAPI extends ParentAPI { ) } +/** + * Web Hosting Dns API. + * + * This API allows you to manage your Web Hosting services. + */ +export class DnsAPI extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw'] + + /** + * Get DNS records. Get the set of DNS records of a specified domain + * associated with a Web Hosting plan's domain. + * + * @param request - The request {@link DnsApiGetDomainDnsRecordsRequest} + * @returns A Promise of DnsRecords + */ + getDomainDnsRecords = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/domains/${validatePathParam('domain', request.domain)}/dns-records`, + }, + unmarshalDnsRecords, + ) + + /** + * "Check whether you own this domain or not.". + * + * @param request - The request {@link DnsApiCheckUserOwnsDomainRequest} + * @returns A Promise of CheckUserOwnsDomainResponse + */ + checkUserOwnsDomain = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalDnsApiCheckUserOwnsDomainRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/domains/${validatePathParam('domain', request.domain)}/check-ownership`, + }, + unmarshalCheckUserOwnsDomainResponse, + ) +} + /** * Web Hosting Offer API. * diff --git a/packages/clients/src/api/webhosting/v1/index.gen.ts b/packages/clients/src/api/webhosting/v1/index.gen.ts index aa0327384..47a6ef8f7 100644 --- a/packages/clients/src/api/webhosting/v1/index.gen.ts +++ b/packages/clients/src/api/webhosting/v1/index.gen.ts @@ -3,6 +3,7 @@ export { ControlPanelAPI, DatabaseAPI, + DnsAPI, FtpAccountAPI, HostingAPI, MailAccountAPI, @@ -11,6 +12,7 @@ export { } from './api.gen' export * from './content.gen' export type { + CheckUserOwnsDomainResponse, ControlPanel, ControlPanelApiListControlPanelsRequest, CreateHostingRequestDomainConfiguration, @@ -27,6 +29,12 @@ export type { DatabaseApiListDatabasesRequest, DatabaseApiUnassignDatabaseUserRequest, DatabaseUser, + DnsApiCheckUserOwnsDomainRequest, + DnsApiGetDomainDnsRecordsRequest, + DnsRecord, + DnsRecordStatus, + DnsRecordType, + DnsRecords, DnsRecordsStatus, FtpAccount, FtpAccountApiChangeFtpAccountPasswordRequest, @@ -66,6 +74,8 @@ export type { MailAccountApiCreateMailAccountRequest, MailAccountApiListMailAccountsRequest, MailAccountApiRemoveMailAccountRequest, + Nameserver, + NameserverStatus, Offer, OfferApiListOffersRequest, OfferOption, diff --git a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts index bc06cb160..cdc90bf25 100644 --- a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts +++ b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts @@ -8,6 +8,7 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + CheckUserOwnsDomainResponse, ControlPanel, CreateHostingRequestDomainConfiguration, Database, @@ -17,6 +18,9 @@ import type { DatabaseApiCreateDatabaseUserRequest, DatabaseApiUnassignDatabaseUserRequest, DatabaseUser, + DnsApiCheckUserOwnsDomainRequest, + DnsRecord, + DnsRecords, FtpAccount, FtpAccountApiChangeFtpAccountPasswordRequest, FtpAccountApiCreateFtpAccountRequest, @@ -37,6 +41,7 @@ import type { MailAccountApiChangeMailAccountPasswordRequest, MailAccountApiCreateMailAccountRequest, MailAccountApiRemoveMailAccountRequest, + Nameserver, Offer, OfferOption, OfferOptionRequest, @@ -101,6 +106,65 @@ export const unmarshalMailAccount = (data: unknown): MailAccount => { } as MailAccount } +export const unmarshalCheckUserOwnsDomainResponse = ( + data: unknown, +): CheckUserOwnsDomainResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CheckUserOwnsDomainResponse' failed as data isn't a dictionary.`, + ) + } + + return { + ownsDomain: data.owns_domain, + } as CheckUserOwnsDomainResponse +} + +const unmarshalDnsRecord = (data: unknown): DnsRecord => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DnsRecord' failed as data isn't a dictionary.`, + ) + } + + return { + name: data.name, + priority: data.priority, + status: data.status, + ttl: data.ttl, + type: data.type, + value: data.value, + } as DnsRecord +} + +const unmarshalNameserver = (data: unknown): Nameserver => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Nameserver' failed as data isn't a dictionary.`, + ) + } + + return { + hostname: data.hostname, + isDefault: data.is_default, + status: data.status, + } as Nameserver +} + +export const unmarshalDnsRecords = (data: unknown): DnsRecords => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DnsRecords' failed as data isn't a dictionary.`, + ) + } + + return { + nameServers: unmarshalArrayOfObject(data.name_servers, unmarshalNameserver), + records: unmarshalArrayOfObject(data.records, unmarshalDnsRecord), + status: data.status, + } as DnsRecords +} + const unmarshalPlatformControlPanelUrls = ( data: unknown, ): PlatformControlPanelUrls => { @@ -130,6 +194,7 @@ const unmarshalOfferOption = (data: unknown): OfferOption => { maxValue: data.max_value, minValue: data.min_value, name: data.name, + price: data.price ? unmarshalMoney(data.price) : undefined, quotaWarning: data.quota_warning, } as OfferOption } @@ -474,6 +539,13 @@ export const marshalDatabaseApiUnassignDatabaseUserRequest = ( username: request.username, }) +export const marshalDnsApiCheckUserOwnsDomainRequest = ( + request: DnsApiCheckUserOwnsDomainRequest, + defaults: DefaultValues, +): Record => ({ + project_id: request.projectId ?? defaults.defaultProjectId, +}) + export const marshalFtpAccountApiChangeFtpAccountPasswordRequest = ( request: FtpAccountApiChangeFtpAccountPasswordRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/webhosting/v1/types.gen.ts b/packages/clients/src/api/webhosting/v1/types.gen.ts index c1e43c719..a1e928ee5 100644 --- a/packages/clients/src/api/webhosting/v1/types.gen.ts +++ b/packages/clients/src/api/webhosting/v1/types.gen.ts @@ -3,6 +3,17 @@ import type { Money, Region } from '../../../bridge' import type { LanguageCode as StdLanguageCode } from '../../std/types.gen' +export type DnsRecordStatus = 'unknown_status' | 'valid' | 'invalid' + +export type DnsRecordType = + | 'unknown_type' + | 'a' + | 'cname' + | 'mx' + | 'txt' + | 'ns' + | 'aaaa' + export type DnsRecordsStatus = 'unknown_status' | 'valid' | 'invalid' export type HostingStatus = @@ -43,6 +54,8 @@ export type ListOffersRequestOrderBy = 'price_asc' export type ListWebsitesRequestOrderBy = 'domain_asc' | 'domain_desc' +export type NameserverStatus = 'unknown_status' | 'valid' | 'invalid' + export type OfferOptionName = | 'unknown_name' | 'domain_count' @@ -82,6 +95,8 @@ export interface OfferOption { maxValue: number /** Defines a warning if the maximum value for the option has been reached. */ quotaWarning: OfferOptionWarning + /** Price of the option for 1 value. */ + price?: Money } export interface PlatformControlPanel { @@ -105,6 +120,30 @@ export interface OfferOptionRequest { quantity: number } +export interface DnsRecord { + /** Record name. */ + name: string + /** Record type. */ + type: DnsRecordType + /** Record time-to-live. */ + ttl: number + /** Record value. */ + value: string + /** Record priority level. */ + priority?: number + /** Record status. */ + status: DnsRecordStatus +} + +export interface Nameserver { + /** Hostname of the nameserver. */ + hostname: string + /** Status of the nameserver. */ + status: NameserverStatus + /** Defines whether the nameserver is the default one. */ + isDefault: boolean +} + export interface HostingUser { /** Main Web Hosting cPanel username. */ username: string @@ -219,6 +258,11 @@ export interface Website { sslStatus: boolean } +export interface CheckUserOwnsDomainResponse { + /** Indicates whether the specified project owns the domain. */ + ownsDomain: boolean +} + export type ControlPanelApiListControlPanelsRequest = { /** * Region to target. If none is passed will use default region from the @@ -388,6 +432,37 @@ export type DatabaseApiUnassignDatabaseUserRequest = { username: string } +export type DnsApiCheckUserOwnsDomainRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Domain for which ownership is to be verified. */ + domain: string + /** ID of the project currently in use. */ + projectId?: string +} + +export type DnsApiGetDomainDnsRecordsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Domain associated with the DNS records. */ + domain: string +} + +export interface DnsRecords { + /** List of DNS records. */ + records: DnsRecord[] + /** List of nameservers. */ + nameServers: Nameserver[] + /** Status of the records. */ + status: DnsRecordsStatus +} + export type FtpAccountApiChangeFtpAccountPasswordRequest = { /** * Region to target. If none is passed will use default region from the