Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webhosting): add public search domains #1767

Merged
merged 1 commit into from
Feb 4, 2025
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
82 changes: 79 additions & 3 deletions packages/clients/src/api/webhosting/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
waitForResource,
} from '../../../bridge'
import type { Region as ScwRegion, WaitForOptions } from '../../../bridge'
import { HOSTING_TRANSIENT_STATUSES } from './content.gen'
import {
DOMAIN_TRANSIENT_STATUSES,
HOSTING_TRANSIENT_STATUSES,
} from './content.gen'
import {
marshalDatabaseApiAssignDatabaseUserRequest,
marshalDatabaseApiChangeDatabaseUserPasswordRequest,
Expand All @@ -28,6 +31,7 @@ import {
unmarshalDatabase,
unmarshalDatabaseUser,
unmarshalDnsRecords,
unmarshalDomain,
unmarshalFtpAccount,
unmarshalHosting,
unmarshalListControlPanelsResponse,
Expand All @@ -41,6 +45,7 @@ import {
unmarshalMailAccount,
unmarshalResetHostingPasswordResponse,
unmarshalResourceSummary,
unmarshalSearchDomainsResponse,
unmarshalSession,
} from './marshalling.gen'
import type {
Expand All @@ -61,8 +66,11 @@ import type {
DatabaseUser,
DnsApiCheckUserOwnsDomainRequest,
DnsApiGetDomainDnsRecordsRequest,
DnsApiGetDomainRequest,
DnsApiSearchDomainsRequest,
DnsApiSyncDomainDnsRecordsRequest,
DnsRecords,
Domain,
FtpAccount,
FtpAccountApiChangeFtpAccountPasswordRequest,
FtpAccountApiCreateFtpAccountRequest,
Expand Down Expand Up @@ -93,6 +101,7 @@ import type {
OfferApiListOffersRequest,
ResetHostingPasswordResponse,
ResourceSummary,
SearchDomainsResponse,
Session,
WebsiteApiListWebsitesRequest,
} from './types.gen'
Expand Down Expand Up @@ -427,7 +436,8 @@ export class DnsAPI extends ParentAPI {
)

/**
* "Check whether you own this domain or not.".
* Check whether you own this domain or not.. Check whether you own this
* domain or not.
*
* @param request - The request {@link DnsApiCheckUserOwnsDomainRequest}
* @returns A Promise of CheckUserOwnsDomainResponse
Expand All @@ -449,7 +459,8 @@ export class DnsAPI extends ParentAPI {
)

/**
* "Synchronize your DNS records on the Elements Console and on cPanel.".
* Synchronize your DNS records on the Elements Console and on cPanel..
* Synchronize your DNS records on the Elements Console and on cPanel.
*
* @param request - The request {@link DnsApiSyncDomainDnsRecordsRequest}
* @returns A Promise of DnsRecords
Expand All @@ -471,6 +482,71 @@ export class DnsAPI extends ParentAPI {
},
unmarshalDnsRecords,
)

/**
* Search for available domains based on domain name.. Search for available
* domains based on domain name.
*
* @param request - The request {@link DnsApiSearchDomainsRequest}
* @returns A Promise of SearchDomainsResponse
*/
searchDomains = (request: Readonly<DnsApiSearchDomainsRequest>) =>
this.client.fetch<SearchDomainsResponse>(
{
method: 'GET',
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/search-domains`,
urlParams: urlParams(
['domain_name', request.domainName],
[
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
],
),
},
unmarshalSearchDomainsResponse,
)

/**
* Retrieve detailed information about a specific domain, including its
* status, DNS configuration, and ownership.. Retrieve detailed information
* about a specific domain, including its status, DNS configuration, and
* ownership.
*
* @param request - The request {@link DnsApiGetDomainRequest}
* @returns A Promise of Domain
*/
getDomain = (request: Readonly<DnsApiGetDomainRequest>) =>
this.client.fetch<Domain>(
{
method: 'GET',
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/domains/${validatePathParam('domainName', request.domainName)}`,
urlParams: urlParams([
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
]),
},
unmarshalDomain,
)

/**
* Waits for {@link Domain} to be in a final state.
*
* @param request - The request {@link DnsApiGetDomainRequest}
* @param options - The waiting options
* @returns A Promise of Domain
*/
waitForDomain = (
request: Readonly<DnsApiGetDomainRequest>,
options?: Readonly<WaitForOptions<Domain>>,
) =>
waitForResource(
options?.stop ??
(res =>
Promise.resolve(!DOMAIN_TRANSIENT_STATUSES.includes(res.status))),
this.getDomain,
request,
options,
)
}

/**
Expand Down
14 changes: 13 additions & 1 deletion packages/clients/src/api/webhosting/v1/content.gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.
import type { HostingStatus, HostingSummaryStatus } from './types.gen'
import type {
DomainAvailabilityStatus,
DomainStatus,
HostingStatus,
HostingSummaryStatus,
} from './types.gen'

/** Lists transient statutes of the enum {@link DomainAvailabilityStatus}. */
export const DOMAIN_AVAILABILITY_TRANSIENT_STATUSES: DomainAvailabilityStatus[] =
['validating']

/** Lists transient statutes of the enum {@link DomainStatus}. */
export const DOMAIN_TRANSIENT_STATUSES: DomainStatus[] = ['validating']

/** Lists transient statutes of the enum {@link HostingStatus}. */
export const HOSTING_TRANSIENT_STATUSES: HostingStatus[] = [
Expand Down
11 changes: 11 additions & 0 deletions packages/clients/src/api/webhosting/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ export type {
DatabaseUser,
DnsApiCheckUserOwnsDomainRequest,
DnsApiGetDomainDnsRecordsRequest,
DnsApiGetDomainRequest,
DnsApiSearchDomainsRequest,
DnsApiSyncDomainDnsRecordsRequest,
DnsRecord,
DnsRecordStatus,
DnsRecordType,
DnsRecords,
DnsRecordsStatus,
Domain,
DomainAction,
DomainAvailability,
DomainAvailabilityAction,
DomainAvailabilityStatus,
DomainDnsAction,
DomainStatus,
DomainZoneOwner,
FtpAccount,
FtpAccountApiChangeFtpAccountPasswordRequest,
FtpAccountApiCreateFtpAccountRequest,
Expand Down Expand Up @@ -90,6 +100,7 @@ export type {
PlatformPlatformGroup,
ResetHostingPasswordResponse,
ResourceSummary,
SearchDomainsResponse,
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
Expand Down
54 changes: 54 additions & 0 deletions packages/clients/src/api/webhosting/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import type {
DnsApiSyncDomainDnsRecordsRequest,
DnsRecord,
DnsRecords,
Domain,
DomainAvailability,
FtpAccount,
FtpAccountApiChangeFtpAccountPasswordRequest,
FtpAccountApiCreateFtpAccountRequest,
Expand Down Expand Up @@ -53,6 +55,7 @@ import type {
PlatformControlPanelUrls,
ResetHostingPasswordResponse,
ResourceSummary,
SearchDomainsResponse,
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
Expand Down Expand Up @@ -170,6 +173,22 @@ export const unmarshalDnsRecords = (data: unknown): DnsRecords => {
} as DnsRecords
}

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

return {
availableActions: data.available_actions,
availableDnsActions: data.available_dns_actions,
name: data.name,
owner: data.owner,
status: data.status,
} as Domain
}

const unmarshalPlatformControlPanelUrls = (
data: unknown,
): PlatformControlPanelUrls => {
Expand Down Expand Up @@ -500,6 +519,40 @@ export const unmarshalResourceSummary = (data: unknown): ResourceSummary => {
} as ResourceSummary
}

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

return {
availableActions: data.available_actions,
canCreateHosting: data.can_create_hosting,
name: data.name,
price: data.price ? unmarshalMoney(data.price) : undefined,
status: data.status,
zoneName: data.zone_name,
} as DomainAvailability
}

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

return {
domainsAvailable: unmarshalArrayOfObject(
data.domains_available,
unmarshalDomainAvailability,
),
} as SearchDomainsResponse
}

export const unmarshalSession = (data: unknown): Session => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -593,6 +646,7 @@ export const marshalDnsApiSyncDomainDnsRecordsRequest = (
: undefined,
update_all_records: request.updateAllRecords,
update_mail_records: request.updateMailRecords,
update_nameservers: request.updateNameservers,
update_web_records: request.updateWebRecords,
})

Expand Down
Loading
Loading