Skip to content

Commit cef3269

Browse files
authored
feat(webhosting): add control panel support in webhosting (#995)
1 parent 183f950 commit cef3269

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

packages/clients/src/api/webhosting/v1alpha1/api.gen.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
marshalUpdateHostingRequest,
1515
unmarshalDnsRecords,
1616
unmarshalHosting,
17+
unmarshalListControlPanelsResponse,
1718
unmarshalListHostingsResponse,
1819
unmarshalListOffersResponse,
1920
} from './marshalling.gen'
@@ -24,6 +25,8 @@ import type {
2425
GetDomainDnsRecordsRequest,
2526
GetHostingRequest,
2627
Hosting,
28+
ListControlPanelsRequest,
29+
ListControlPanelsResponse,
2730
ListHostingsRequest,
2831
ListHostingsResponse,
2932
ListOffersRequest,
@@ -39,7 +42,7 @@ const jsonContentHeaders = {
3942
/** Web Hosting API. */
4043
export class API extends ParentAPI {
4144
/** Lists the available regions of the API. */
42-
public static readonly LOCALITIES: Region[] = ['fr-par']
45+
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams']
4346

4447
/**
4548
* Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer
@@ -75,6 +78,7 @@ export class API extends ParentAPI {
7578
request.region ?? this.client.settings.defaultRegion,
7679
)}/hostings`,
7780
urlParams: urlParams(
81+
['control_panels', request.controlPanels],
7882
['domain', request.domain],
7983
['order_by', request.orderBy],
8084
['organization_id', request.organizationId],
@@ -257,4 +261,35 @@ export class API extends ParentAPI {
257261
},
258262
unmarshalListOffersResponse,
259263
)
264+
265+
protected pageOfListControlPanels = (
266+
request: Readonly<ListControlPanelsRequest> = {},
267+
) =>
268+
this.client.fetch<ListControlPanelsResponse>(
269+
{
270+
method: 'GET',
271+
path: `/webhosting/v1alpha1/regions/${validatePathParam(
272+
'region',
273+
request.region ?? this.client.settings.defaultRegion,
274+
)}/control-panels`,
275+
urlParams: urlParams(
276+
['page', request.page],
277+
[
278+
'page_size',
279+
request.pageSize ?? this.client.settings.defaultPageSize,
280+
],
281+
),
282+
},
283+
unmarshalListControlPanelsResponse,
284+
)
285+
286+
/**
287+
* List all control panels type. List the control panels type: cpanel or
288+
* plesk.
289+
*
290+
* @param request - The request {@link ListControlPanelsRequest}
291+
* @returns A Promise of ListControlPanelsResponse
292+
*/
293+
listControlPanels = (request: Readonly<ListControlPanelsRequest> = {}) =>
294+
enrichForPagination('controlPanels', this.pageOfListControlPanels, request)
260295
}

packages/clients/src/api/webhosting/v1alpha1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export { API } from './api.gen'
44
export * from './content.gen'
55
export type {
6+
ControlPanel,
67
CreateHostingRequest,
78
DeleteHostingRequest,
89
DnsRecord,
@@ -17,6 +18,8 @@ export type {
1718
HostingDnsStatus,
1819
HostingOption,
1920
HostingStatus,
21+
ListControlPanelsRequest,
22+
ListControlPanelsResponse,
2023
ListHostingsRequest,
2124
ListHostingsRequestOrderBy,
2225
ListHostingsResponse,

packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import {
88
} from '../../../bridge'
99
import type { DefaultValues } from '../../../bridge'
1010
import type {
11+
ControlPanel,
1112
CreateHostingRequest,
1213
DnsRecord,
1314
DnsRecords,
1415
Hosting,
1516
HostingCpanelUrls,
1617
HostingOption,
18+
ListControlPanelsResponse,
1719
ListHostingsResponse,
1820
ListOffersResponse,
1921
Nameserver,
@@ -56,6 +58,7 @@ export const unmarshalHosting = (data: unknown): Hosting => {
5658
}
5759

5860
return {
61+
controlPanelName: data.control_panel_name,
5962
cpanelUrls: data.cpanel_urls
6063
? unmarshalHostingCpanelUrls(data.cpanel_urls)
6164
: undefined,
@@ -124,6 +127,38 @@ export const unmarshalDnsRecords = (data: unknown): DnsRecords => {
124127
} as DnsRecords
125128
}
126129

130+
const unmarshalControlPanel = (data: unknown): ControlPanel => {
131+
if (!isJSONObject(data)) {
132+
throw new TypeError(
133+
`Unmarshalling the type 'ControlPanel' failed as data isn't a dictionary.`,
134+
)
135+
}
136+
137+
return {
138+
available: data.available,
139+
logoUrl: data.logo_url,
140+
name: data.name,
141+
} as ControlPanel
142+
}
143+
144+
export const unmarshalListControlPanelsResponse = (
145+
data: unknown,
146+
): ListControlPanelsResponse => {
147+
if (!isJSONObject(data)) {
148+
throw new TypeError(
149+
`Unmarshalling the type 'ListControlPanelsResponse' failed as data isn't a dictionary.`,
150+
)
151+
}
152+
153+
return {
154+
controlPanels: unmarshalArrayOfObject(
155+
data.control_panels,
156+
unmarshalControlPanel,
157+
),
158+
totalCount: data.total_count,
159+
} as ListControlPanelsResponse
160+
}
161+
127162
export const unmarshalListHostingsResponse = (
128163
data: unknown,
129164
): ListHostingsResponse => {
@@ -170,6 +205,7 @@ const unmarshalOffer = (data: unknown): Offer => {
170205
return {
171206
available: data.available,
172207
billingOperationPath: data.billing_operation_path,
208+
controlPanelName: data.control_panel_name,
173209
endOfLife: data.end_of_life,
174210
id: data.id,
175211
price: data.price ? unmarshalMoney(data.price) : undefined,

packages/clients/src/api/webhosting/v1alpha1/types.gen.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ export interface Nameserver {
9797
isDefault: boolean
9898
}
9999

100+
export interface ControlPanel {
101+
/** Control panel name. */
102+
name: string
103+
/** Define if the control panel type is available to order. */
104+
available: boolean
105+
/** URL of this control panel's logo. */
106+
logoUrl: string
107+
}
108+
100109
export interface Hosting {
101110
/** ID of the Web Hosting plan. */
102111
id: string
@@ -132,6 +141,8 @@ export interface Hosting {
132141
username: string
133142
/** Indicates if the hosting offer has reached its end of life. */
134143
offerEndOfLife: boolean
144+
/** Name of the control panel. */
145+
controlPanelName: string
135146
/** Region where the Web Hosting plan is hosted. */
136147
region: Region
137148
}
@@ -154,6 +165,8 @@ export interface Offer {
154165
quotaWarnings: OfferQuotaWarning[]
155166
/** Indicates if the offer has reached its end of life. */
156167
endOfLife: boolean
168+
/** Name of the control panel. */
169+
controlPanelName: string
157170
}
158171

159172
export type CreateHostingRequest = {
@@ -218,6 +231,31 @@ export type GetHostingRequest = {
218231
hostingId: string
219232
}
220233

234+
export type ListControlPanelsRequest = {
235+
/**
236+
* Region to target. If none is passed will use default region from the
237+
* config.
238+
*/
239+
region?: Region
240+
/**
241+
* Page number to return, from the paginated results (must be a positive
242+
* integer).
243+
*/
244+
page?: number
245+
/**
246+
* Number of control panels to return (must be a positive integer lower or
247+
* equal to 100).
248+
*/
249+
pageSize?: number
250+
}
251+
252+
export interface ListControlPanelsResponse {
253+
/** Number of control panels returned. */
254+
totalCount: number
255+
/** List of control panels. */
256+
controlPanels: ControlPanel[]
257+
}
258+
221259
export type ListHostingsRequest = {
222260
/**
223261
* Region to target. If none is passed will use default region from the
@@ -261,6 +299,11 @@ export type ListHostingsRequest = {
261299
* Organization will be returned.
262300
*/
263301
organizationId?: string
302+
/**
303+
* Name of the control panel to filter for, only Web Hosting plans from this
304+
* control panel will be returned.
305+
*/
306+
controlPanels?: string[]
264307
}
265308

266309
export interface ListHostingsResponse {

packages/clients/src/api/webhosting/v1alpha1/validation-rules.gen.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33

4+
export const ListControlPanelsRequest = {
5+
page: {
6+
greaterThan: 0,
7+
},
8+
pageSize: {
9+
greaterThan: 0,
10+
lessThanOrEqual: 100,
11+
},
12+
}
13+
414
export const ListHostingsRequest = {
515
page: {
616
greaterThan: 0,

0 commit comments

Comments
 (0)