Skip to content

Commit 50278b2

Browse files
feat(webhosting): implement FreeDomainAPI (#2373)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 64fe049 commit 50278b2

File tree

5 files changed

+227
-0
lines changed

5 files changed

+227
-0
lines changed

packages_generated/webhosting/src/v1/api.gen.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
marshalDatabaseApiUnassignDatabaseUserRequest,
2525
marshalDnsApiCheckUserOwnsDomainRequest,
2626
marshalDnsApiSyncDomainDnsRecordsRequest,
27+
marshalFreeDomainApiCheckFreeDomainAvailabilityRequest,
2728
marshalFtpAccountApiChangeFtpAccountPasswordRequest,
2829
marshalFtpAccountApiCreateFtpAccountRequest,
2930
marshalHostingApiAddCustomDomainRequest,
@@ -33,6 +34,7 @@ import {
3334
marshalMailAccountApiCreateMailAccountRequest,
3435
marshalMailAccountApiRemoveMailAccountRequest,
3536
unmarshalBackup,
37+
unmarshalCheckFreeDomainAvailabilityResponse,
3638
unmarshalCheckUserOwnsDomainResponse,
3739
unmarshalDatabase,
3840
unmarshalDatabaseUser,
@@ -46,6 +48,7 @@ import {
4648
unmarshalListControlPanelsResponse,
4749
unmarshalListDatabasesResponse,
4850
unmarshalListDatabaseUsersResponse,
51+
unmarshalListFreeRootDomainsResponse,
4952
unmarshalListFtpAccountsResponse,
5053
unmarshalListHostingsResponse,
5154
unmarshalListMailAccountsResponse,
@@ -66,6 +69,7 @@ import type {
6669
BackupApiListBackupsRequest,
6770
BackupApiRestoreBackupItemsRequest,
6871
BackupApiRestoreBackupRequest,
72+
CheckFreeDomainAvailabilityResponse,
6973
CheckUserOwnsDomainResponse,
7074
ControlPanelApiListControlPanelsRequest,
7175
Database,
@@ -88,6 +92,8 @@ import type {
8892
DnsApiSyncDomainDnsRecordsRequest,
8993
DnsRecords,
9094
Domain,
95+
FreeDomainApiCheckFreeDomainAvailabilityRequest,
96+
FreeDomainApiListFreeRootDomainsRequest,
9197
FtpAccount,
9298
FtpAccountApiChangeFtpAccountPasswordRequest,
9399
FtpAccountApiCreateFtpAccountRequest,
@@ -110,6 +116,7 @@ import type {
110116
ListControlPanelsResponse,
111117
ListDatabasesResponse,
112118
ListDatabaseUsersResponse,
119+
ListFreeRootDomainsResponse,
113120
ListFtpAccountsResponse,
114121
ListHostingsResponse,
115122
ListMailAccountsResponse,
@@ -986,6 +993,74 @@ export class HostingAPI extends ParentAPI {
986993
)
987994
}
988995

996+
/**
997+
* Web Hosting free domain API.
998+
999+
This API allows you to list and check a free domain's validity.
1000+
*/
1001+
export class FreeDomainAPI extends ParentAPI {
1002+
/**
1003+
* Locality of this API.
1004+
* type ∈ {'zone','region','global','unspecified'}
1005+
*/
1006+
public static readonly LOCALITY: ApiLocality = toApiLocality({
1007+
regions: ['fr-par', 'nl-ams', 'pl-waw'],
1008+
})
1009+
1010+
/**
1011+
* Check whether a given slug and free domain combination is available.. Check whether a given slug and free domain combination is available.
1012+
*
1013+
* @param request - The request {@link FreeDomainApiCheckFreeDomainAvailabilityRequest}
1014+
* @returns A Promise of CheckFreeDomainAvailabilityResponse
1015+
*/
1016+
checkFreeDomainAvailability = (
1017+
request: Readonly<FreeDomainApiCheckFreeDomainAvailabilityRequest>,
1018+
) =>
1019+
this.client.fetch<CheckFreeDomainAvailabilityResponse>(
1020+
{
1021+
body: JSON.stringify(
1022+
marshalFreeDomainApiCheckFreeDomainAvailabilityRequest(
1023+
request,
1024+
this.client.settings,
1025+
),
1026+
),
1027+
headers: jsonContentHeaders,
1028+
method: 'POST',
1029+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/free-domains/check-availability`,
1030+
},
1031+
unmarshalCheckFreeDomainAvailabilityResponse,
1032+
)
1033+
1034+
protected pageOfListFreeRootDomains = (
1035+
request: Readonly<FreeDomainApiListFreeRootDomainsRequest> = {},
1036+
) =>
1037+
this.client.fetch<ListFreeRootDomainsResponse>(
1038+
{
1039+
method: 'GET',
1040+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/free-domains/root-domains`,
1041+
urlParams: urlParams(
1042+
['page', request.page],
1043+
[
1044+
'page_size',
1045+
request.pageSize ?? this.client.settings.defaultPageSize,
1046+
],
1047+
),
1048+
},
1049+
unmarshalListFreeRootDomainsResponse,
1050+
)
1051+
1052+
/**
1053+
* Retrieve the list of free root domains available for a Web Hosting.. Retrieve the list of free root domains available for a Web Hosting.
1054+
*
1055+
* @param request - The request {@link FreeDomainApiListFreeRootDomainsRequest}
1056+
* @returns A Promise of ListFreeRootDomainsResponse
1057+
*/
1058+
listFreeRootDomains = (
1059+
request: Readonly<FreeDomainApiListFreeRootDomainsRequest> = {},
1060+
) =>
1061+
enrichForPagination('rootDomains', this.pageOfListFreeRootDomains, request)
1062+
}
1063+
9891064
/**
9901065
* Web Hosting FTP Account API.
9911066

packages_generated/webhosting/src/v1/index.gen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export {
55
ControlPanelAPI,
66
DatabaseAPI,
77
DnsAPI,
8+
FreeDomainAPI,
89
FtpAccountAPI,
910
HostingAPI,
1011
MailAccountAPI,
@@ -25,6 +26,8 @@ export type {
2526
BackupItemGroup,
2627
BackupItemType,
2728
BackupStatus,
29+
CheckFreeDomainAvailabilityResponse,
30+
CheckFreeDomainAvailabilityResponseUnavailableReason,
2831
CheckUserOwnsDomainResponse,
2932
ControlPanel,
3033
ControlPanelApiListControlPanelsRequest,
@@ -61,6 +64,9 @@ export type {
6164
DomainDnsAction,
6265
DomainStatus,
6366
DomainZoneOwner,
67+
FreeDomain,
68+
FreeDomainApiCheckFreeDomainAvailabilityRequest,
69+
FreeDomainApiListFreeRootDomainsRequest,
6470
FtpAccount,
6571
FtpAccountApiChangeFtpAccountPasswordRequest,
6672
FtpAccountApiCreateFtpAccountRequest,
@@ -90,6 +96,7 @@ export type {
9096
ListDatabasesResponse,
9197
ListDatabaseUsersRequestOrderBy,
9298
ListDatabaseUsersResponse,
99+
ListFreeRootDomainsResponse,
93100
ListFtpAccountsRequestOrderBy,
94101
ListFtpAccountsResponse,
95102
ListHostingsRequestOrderBy,

packages_generated/webhosting/src/v1/marshalling.gen.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
BackupApiRestoreBackupItemsRequest,
1616
BackupItem,
1717
BackupItemGroup,
18+
CheckFreeDomainAvailabilityResponse,
1819
CheckUserOwnsDomainResponse,
1920
ControlPanel,
2021
CreateDatabaseRequestUser,
@@ -32,6 +33,8 @@ import type {
3233
DnsRecords,
3334
Domain,
3435
DomainAvailability,
36+
FreeDomain,
37+
FreeDomainApiCheckFreeDomainAvailabilityRequest,
3538
FtpAccount,
3639
FtpAccountApiChangeFtpAccountPasswordRequest,
3740
FtpAccountApiCreateFtpAccountRequest,
@@ -48,6 +51,7 @@ import type {
4851
ListControlPanelsResponse,
4952
ListDatabasesResponse,
5053
ListDatabaseUsersResponse,
54+
ListFreeRootDomainsResponse,
5155
ListFtpAccountsResponse,
5256
ListHostingsResponse,
5357
ListMailAccountsResponse,
@@ -217,6 +221,37 @@ export const unmarshalMailAccount = (data: unknown): MailAccount => {
217221
} as MailAccount
218222
}
219223

224+
const unmarshalFreeDomain = (data: unknown): FreeDomain => {
225+
if (!isJSONObject(data)) {
226+
throw new TypeError(
227+
`Unmarshalling the type 'FreeDomain' failed as data isn't a dictionary.`,
228+
)
229+
}
230+
231+
return {
232+
rootDomain: data.root_domain,
233+
slug: data.slug,
234+
} as FreeDomain
235+
}
236+
237+
export const unmarshalCheckFreeDomainAvailabilityResponse = (
238+
data: unknown,
239+
): CheckFreeDomainAvailabilityResponse => {
240+
if (!isJSONObject(data)) {
241+
throw new TypeError(
242+
`Unmarshalling the type 'CheckFreeDomainAvailabilityResponse' failed as data isn't a dictionary.`,
243+
)
244+
}
245+
246+
return {
247+
freeDomain: data.free_domain
248+
? unmarshalFreeDomain(data.free_domain)
249+
: undefined,
250+
isAvailable: data.is_available,
251+
reason: data.reason ? data.reason : undefined,
252+
} as CheckFreeDomainAvailabilityResponse
253+
}
254+
220255
export const unmarshalCheckUserOwnsDomainResponse = (
221256
data: unknown,
222257
): CheckUserOwnsDomainResponse => {
@@ -556,6 +591,21 @@ export const unmarshalListDatabasesResponse = (
556591
} as ListDatabasesResponse
557592
}
558593

594+
export const unmarshalListFreeRootDomainsResponse = (
595+
data: unknown,
596+
): ListFreeRootDomainsResponse => {
597+
if (!isJSONObject(data)) {
598+
throw new TypeError(
599+
`Unmarshalling the type 'ListFreeRootDomainsResponse' failed as data isn't a dictionary.`,
600+
)
601+
}
602+
603+
return {
604+
rootDomains: data.root_domains,
605+
totalCount: data.total_count,
606+
} as ListFreeRootDomainsResponse
607+
}
608+
559609
export const unmarshalListFtpAccountsResponse = (
560610
data: unknown,
561611
): ListFtpAccountsResponse => {
@@ -855,6 +905,14 @@ export const marshalDnsApiSyncDomainDnsRecordsRequest = (
855905
update_web_records: request.updateWebRecords,
856906
})
857907

908+
export const marshalFreeDomainApiCheckFreeDomainAvailabilityRequest = (
909+
request: FreeDomainApiCheckFreeDomainAvailabilityRequest,
910+
defaults: DefaultValues,
911+
): Record<string, unknown> => ({
912+
root_domain: request.rootDomain,
913+
slug: request.slug,
914+
})
915+
858916
export const marshalFtpAccountApiChangeFtpAccountPasswordRequest = (
859917
request: FtpAccountApiChangeFtpAccountPasswordRequest,
860918
defaults: DefaultValues,

packages_generated/webhosting/src/v1/types.gen.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ export type BackupStatus =
2323
| 'damaged'
2424
| 'restoring'
2525

26+
export type CheckFreeDomainAvailabilityResponseUnavailableReason =
27+
| 'unavailable_reason_unknown'
28+
| 'unavailable_reason_already_used'
29+
| 'unavailable_reason_too_short'
30+
| 'unavailable_reason_too_long'
31+
| 'unavailable_reason_invalid_characters'
32+
| 'unavailable_reason_starts_or_ends_with_hyphen'
33+
| 'unavailable_reason_contains_dots'
34+
| 'unavailable_reason_contains_reserved_keyword'
35+
2636
export type DnsRecordStatus = 'unknown_status' | 'valid' | 'invalid'
2737

2838
export type DnsRecordType =
@@ -269,6 +279,17 @@ export interface HostingDomain {
269279
customDomain?: HostingDomainCustomDomain
270280
}
271281

282+
export interface FreeDomain {
283+
/**
284+
* Custom prefix used for the free domain.
285+
*/
286+
slug: string
287+
/**
288+
* Free root domain provided by Web Hosting, selected from the list returned by `ListFreeRootDomains`.
289+
*/
290+
rootDomain: string
291+
}
292+
272293
export interface CreateDatabaseRequestUser {
273294
username: string
274295
password: string
@@ -701,6 +722,21 @@ export type BackupApiRestoreBackupRequest = {
701722
backupId: string
702723
}
703724

725+
export interface CheckFreeDomainAvailabilityResponse {
726+
/**
727+
* The free domain that was checked.
728+
*/
729+
freeDomain?: FreeDomain
730+
/**
731+
* Whether the free domain is available.
732+
*/
733+
isAvailable: boolean
734+
/**
735+
* Reason the domain is unavailable, if applicable.
736+
*/
737+
reason?: CheckFreeDomainAvailabilityResponseUnavailableReason
738+
}
739+
704740
export interface CheckUserOwnsDomainResponse {
705741
/**
706742
* Indicates whether the specified project owns the domain.
@@ -1077,6 +1113,36 @@ export interface Domain {
10771113
autoConfigDomainDns?: AutoConfigDomainDns
10781114
}
10791115

1116+
export type FreeDomainApiCheckFreeDomainAvailabilityRequest = {
1117+
/**
1118+
* Region to target. If none is passed will use default region from the config.
1119+
*/
1120+
region?: ScwRegion
1121+
/**
1122+
* Custom prefix used for the free domain.
1123+
*/
1124+
slug: string
1125+
/**
1126+
* Free root domain provided by Web Hosting, selected from the list returned by `ListFreeRootDomains`.
1127+
*/
1128+
rootDomain: string
1129+
}
1130+
1131+
export type FreeDomainApiListFreeRootDomainsRequest = {
1132+
/**
1133+
* Region to target. If none is passed will use default region from the config.
1134+
*/
1135+
region?: ScwRegion
1136+
/**
1137+
* Page number to return, from the paginated results (must be a positive integer).
1138+
*/
1139+
page?: number
1140+
/**
1141+
* Number of free root domains to return (must be a positive integer lower or equal to 100).
1142+
*/
1143+
pageSize?: number
1144+
}
1145+
10801146
export type FtpAccountApiChangeFtpAccountPasswordRequest = {
10811147
/**
10821148
* Region to target. If none is passed will use default region from the config.
@@ -1493,6 +1559,17 @@ export interface ListDatabasesResponse {
14931559
databases: Database[]
14941560
}
14951561

1562+
export interface ListFreeRootDomainsResponse {
1563+
/**
1564+
* List of free root domains available for the Web Hosting.
1565+
*/
1566+
rootDomains: string[]
1567+
/**
1568+
* Total number of free root domains available.
1569+
*/
1570+
totalCount: number
1571+
}
1572+
14961573
export interface ListFtpAccountsResponse {
14971574
/**
14981575
* Total number of FTP accounts.

packages_generated/webhosting/src/v1/validation-rules.gen.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ export const DatabaseApiListDatabasesRequest = {
4141
},
4242
}
4343

44+
export const FreeDomainApiListFreeRootDomainsRequest = {
45+
page: {
46+
greaterThan: 0,
47+
},
48+
pageSize: {
49+
greaterThan: 0,
50+
lessThanOrEqual: 100,
51+
},
52+
}
53+
4454
export const FtpAccountApiListFtpAccountsRequest = {
4555
page: {
4656
greaterThan: 0,

0 commit comments

Comments
 (0)