diff --git a/packages/clients/src/api/webhosting/v1/api.gen.ts b/packages/clients/src/api/webhosting/v1/api.gen.ts index a5e18de76..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. * @@ -428,7 +483,7 @@ export class OfferAPI extends ParentAPI { */ export class HostingAPI 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'] /** * Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer diff --git a/packages/clients/src/api/webhosting/v1/index.gen.ts b/packages/clients/src/api/webhosting/v1/index.gen.ts index 461774cf0..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,13 @@ export type { DatabaseApiListDatabasesRequest, DatabaseApiUnassignDatabaseUserRequest, DatabaseUser, + DnsApiCheckUserOwnsDomainRequest, + DnsApiGetDomainDnsRecordsRequest, + DnsRecord, + DnsRecordStatus, + DnsRecordType, + DnsRecords, + DnsRecordsStatus, FtpAccount, FtpAccountApiChangeFtpAccountPasswordRequest, FtpAccountApiCreateFtpAccountRequest, @@ -41,12 +50,10 @@ export type { HostingApiListHostingsRequest, HostingApiResetHostingPasswordRequest, HostingApiUpdateHostingRequest, - HostingCpanelUrls, - HostingDnsStatus, - HostingOption, HostingStatus, HostingSummary, HostingSummaryStatus, + HostingUser, ListControlPanelsResponse, ListDatabaseUsersRequestOrderBy, ListDatabaseUsersResponse, @@ -67,12 +74,18 @@ export type { MailAccountApiCreateMailAccountRequest, MailAccountApiListMailAccountsRequest, MailAccountApiRemoveMailAccountRequest, + Nameserver, + NameserverStatus, Offer, OfferApiListOffersRequest, OfferOption, OfferOptionName, OfferOptionRequest, OfferOptionWarning, + Platform, + PlatformControlPanel, + PlatformControlPanelUrls, + PlatformPlatformGroup, ResetHostingPasswordResponse, ResourceSummary, Session, diff --git a/packages/clients/src/api/webhosting/v1/marshalling.gen.ts b/packages/clients/src/api/webhosting/v1/marshalling.gen.ts index d50b5831c..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,15 +18,17 @@ import type { DatabaseApiCreateDatabaseUserRequest, DatabaseApiUnassignDatabaseUserRequest, DatabaseUser, + DnsApiCheckUserOwnsDomainRequest, + DnsRecord, + DnsRecords, FtpAccount, FtpAccountApiChangeFtpAccountPasswordRequest, FtpAccountApiCreateFtpAccountRequest, Hosting, HostingApiCreateHostingRequest, HostingApiUpdateHostingRequest, - HostingCpanelUrls, - HostingOption, HostingSummary, + HostingUser, ListControlPanelsResponse, ListDatabaseUsersResponse, ListDatabasesResponse, @@ -38,9 +41,13 @@ import type { MailAccountApiChangeMailAccountPasswordRequest, MailAccountApiCreateMailAccountRequest, MailAccountApiRemoveMailAccountRequest, + Nameserver, Offer, OfferOption, OfferOptionRequest, + Platform, + PlatformControlPanel, + PlatformControlPanelUrls, ResetHostingPasswordResponse, ResourceSummary, Session, @@ -99,67 +106,185 @@ export const unmarshalMailAccount = (data: unknown): MailAccount => { } as MailAccount } -const unmarshalHostingCpanelUrls = (data: unknown): HostingCpanelUrls => { +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 'HostingCpanelUrls' failed as data isn't a dictionary.`, + `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 => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'PlatformControlPanelUrls' failed as data isn't a dictionary.`, ) } return { dashboard: data.dashboard, webmail: data.webmail, - } as HostingCpanelUrls + } as PlatformControlPanelUrls } -const unmarshalHostingOption = (data: unknown): HostingOption => { +const unmarshalOfferOption = (data: unknown): OfferOption => { if (!isJSONObject(data)) { throw new TypeError( - `Unmarshalling the type 'HostingOption' failed as data isn't a dictionary.`, + `Unmarshalling the type 'OfferOption' failed as data isn't a dictionary.`, ) } return { + billingOperationPath: data.billing_operation_path, + currentValue: data.current_value, id: data.id, + maxValue: data.max_value, + minValue: data.min_value, name: data.name, - quantity: data.quantity, - } as HostingOption + price: data.price ? unmarshalMoney(data.price) : undefined, + quotaWarning: data.quota_warning, + } as OfferOption } -export const unmarshalHosting = (data: unknown): Hosting => { +const unmarshalPlatformControlPanel = (data: unknown): PlatformControlPanel => { if (!isJSONObject(data)) { throw new TypeError( - `Unmarshalling the type 'Hosting' failed as data isn't a dictionary.`, + `Unmarshalling the type 'PlatformControlPanel' failed as data isn't a dictionary.`, + ) + } + + return { + name: data.name, + urls: data.urls ? unmarshalPlatformControlPanelUrls(data.urls) : undefined, + } as PlatformControlPanel +} + +const unmarshalHostingUser = (data: unknown): HostingUser => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'HostingUser' failed as data isn't a dictionary.`, ) } return { contactEmail: data.contact_email, + oneTimePassword: data.one_time_password, + username: data.username, + } as HostingUser +} + +const unmarshalOffer = (data: unknown): Offer => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Offer' failed as data isn't a dictionary.`, + ) + } + + return { + available: data.available, + billingOperationPath: data.billing_operation_path, controlPanelName: data.control_panel_name, - cpanelUrls: data.cpanel_urls - ? unmarshalHostingCpanelUrls(data.cpanel_urls) + endOfLife: data.end_of_life, + id: data.id, + options: unmarshalArrayOfObject(data.options, unmarshalOfferOption), + price: data.price ? unmarshalMoney(data.price) : undefined, + } as Offer +} + +const unmarshalPlatform = (data: unknown): Platform => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Platform' failed as data isn't a dictionary.`, + ) + } + + return { + controlPanel: data.control_panel + ? unmarshalPlatformControlPanel(data.control_panel) : undefined, + groupName: data.group_name, + hostname: data.hostname, + ipv4: data.ipv4, + ipv6: data.ipv6, + number: data.number, + } as Platform +} + +export const unmarshalHosting = (data: unknown): Hosting => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Hosting' failed as data isn't a dictionary.`, + ) + } + + return { createdAt: unmarshalDate(data.created_at), dnsStatus: data.dns_status, domain: data.domain, id: data.id, ipv4: data.ipv4, - ipv6: data.ipv6, - offerEndOfLife: data.offer_end_of_life, - offerId: data.offer_id, - offerName: data.offer_name, - oneTimePassword: data.one_time_password, - options: unmarshalArrayOfObject(data.options, unmarshalHostingOption), - platformGroup: data.platform_group, - platformHostname: data.platform_hostname, - platformNumber: data.platform_number, + offer: data.offer ? unmarshalOffer(data.offer) : undefined, + platform: data.platform ? unmarshalPlatform(data.platform) : undefined, projectId: data.project_id, protected: data.protected, region: data.region, status: data.status, tags: data.tags, updatedAt: unmarshalDate(data.updated_at), - username: data.username, + user: data.user ? unmarshalHostingUser(data.user) : undefined, } as Hosting } @@ -293,42 +418,6 @@ export const unmarshalListMailAccountsResponse = ( } as ListMailAccountsResponse } -const unmarshalOfferOption = (data: unknown): OfferOption => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'OfferOption' failed as data isn't a dictionary.`, - ) - } - - return { - billingOperationPath: data.billing_operation_path, - currentValue: data.current_value, - id: data.id, - maxValue: data.max_value, - minValue: data.min_value, - name: data.name, - quotaWarning: data.quota_warning, - } as OfferOption -} - -const unmarshalOffer = (data: unknown): Offer => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'Offer' failed as data isn't a dictionary.`, - ) - } - - return { - available: data.available, - billingOperationPath: data.billing_operation_path, - controlPanelName: data.control_panel_name, - endOfLife: data.end_of_life, - id: data.id, - options: unmarshalArrayOfObject(data.options, unmarshalOfferOption), - price: data.price ? unmarshalMoney(data.price) : undefined, - } as Offer -} - export const unmarshalListOffersResponse = ( data: unknown, ): ListOffersResponse => { @@ -450,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 aa6a11667..a1e928ee5 100644 --- a/packages/clients/src/api/webhosting/v1/types.gen.ts +++ b/packages/clients/src/api/webhosting/v1/types.gen.ts @@ -3,7 +3,18 @@ import type { Money, Region } from '../../../bridge' import type { LanguageCode as StdLanguageCode } from '../../std/types.gen' -export type HostingDnsStatus = 'unknown_dns_status' | 'valid' | 'invalid' +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 = | 'unknown_status' @@ -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' @@ -55,6 +68,15 @@ export type OfferOptionName = export type OfferOptionWarning = 'unknown_warning' | 'quota_exceeded_warning' +export type PlatformPlatformGroup = 'unknown_group' | 'default' | 'premium' + +export interface PlatformControlPanelUrls { + /** URL to connect to the hosting control panel dashboard. */ + dashboard: string + /** URL to connect to the hosting Webmail interface. */ + webmail: string +} + export interface OfferOption { /** Option ID. */ id: string @@ -73,6 +95,15 @@ 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 { + /** Name of the control panel. */ + name: string + /** URL to connect to cPanel dashboard and to Webmail interface. */ + urls?: PlatformControlPanelUrls } export interface CreateHostingRequestDomainConfiguration { @@ -89,18 +120,75 @@ export interface OfferOptionRequest { quantity: number } -export interface HostingCpanelUrls { - dashboard: string - webmail: string +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 + /** + * One-time-password used for the first login or reset password, empty after + * first use. + */ + oneTimePassword?: string + /** Contact email used for the hosting. */ + contactEmail: string } -export interface HostingOption { - /** Option ID. */ +export interface Offer { + /** Offer ID. */ id: string - /** Option name. */ - name: OfferOptionName - /** Option quantity. */ - quantity: number + /** Unique identifier used for billing. */ + billingOperationPath: string + /** Options available for the offer. */ + options: OfferOption[] + /** Price of the offer. */ + price?: Money + /** + * If a hosting_id was specified in the call, defines whether the offer is + * available for a specified hosting plan to migrate (update) to. + */ + available: boolean + /** Name of the control panel. */ + controlPanelName: string + /** Indicates if the offer has reached its end of life. */ + endOfLife: boolean +} + +export interface Platform { + /** Hostname of the host platform. */ + hostname: string + /** Number of the host platform. */ + number: number + /** Group name of the hosting's host platform. */ + groupName: PlatformPlatformGroup + /** IPv4 address of the hosting's host platform. */ + ipv4: string + /** IPv6 address of the hosting's host platform. */ + ipv6: string + /** Details of the platform control panel. */ + controlPanel?: PlatformControlPanel } export interface ControlPanel { @@ -161,26 +249,6 @@ export interface MailAccount { username: string } -export interface Offer { - /** Offer ID. */ - id: string - /** Unique identifier used for billing. */ - billingOperationPath: string - /** Options available for the offer. */ - options: OfferOption[] - /** Price of the offer. */ - price?: Money - /** - * If a hosting_id was specified in the call, defines whether the offer is - * available for a specified hosting plan to migrate (update) to. - */ - available: boolean - /** Name of the control panel. */ - controlPanelName: string - /** Indicates if the offer has reached its end of life. */ - endOfLife: boolean -} - export interface Website { /** The domain of the website. */ domain: string @@ -190,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 @@ -359,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 @@ -433,45 +537,22 @@ export interface Hosting { createdAt?: Date /** Status of the Web Hosting plan. */ status: HostingStatus - /** Hostname of the host platform. */ - platformHostname: string - /** Number of the host platform. */ - platformNumber: number - /** ID of the active offer for the Web Hosting plan. */ - offerId: string - /** Name of the active offer for the Web Hosting plan. */ - offerName: string /** Main domain associated with the Web Hosting plan. */ domain: string + /** Details of the Web Hosting plan offer and options. */ + offer?: Offer + /** Details of the hosting platform. */ + platform?: Platform /** List of tags associated with the Web Hosting plan. */ tags: string[] - /** List of the Web Hosting plan options. */ - options: HostingOption[] /** DNS status of the Web Hosting plan. */ - dnsStatus: HostingDnsStatus - /** URL to connect to cPanel dashboard and to Webmail interface. */ - cpanelUrls?: HostingCpanelUrls - /** Main Web Hosting cPanel username. */ - username: string - /** Indicates if the hosting offer has reached its end of life. */ - offerEndOfLife: boolean - /** Name of the control panel. */ - controlPanelName: string - /** Group of the hosting's host server/platform. */ - platformGroup: string - /** IPv4 address of the hosting's host server. */ + dnsStatus: DnsRecordsStatus + /** Current IPv4 address of the hosting. */ ipv4: string - /** IPv6 address of the hosting's host server. */ - ipv6: string /** Whether the hosting is protected or not. */ protected: boolean - /** - * One-time-password used for the first login or reset password, empty after - * first use. - */ - oneTimePassword: string - /** Contact email used for the hosting. */ - contactEmail: string + /** Details of the hosting user. */ + user?: HostingUser /** Region where the Web Hosting plan is hosted. */ region: Region }