Skip to content

feat(webhosting): add control panel support in webhosting #995

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

Merged
merged 1 commit into from
Nov 10, 2023
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
37 changes: 36 additions & 1 deletion packages/clients/src/api/webhosting/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
marshalUpdateHostingRequest,
unmarshalDnsRecords,
unmarshalHosting,
unmarshalListControlPanelsResponse,
unmarshalListHostingsResponse,
unmarshalListOffersResponse,
} from './marshalling.gen'
Expand All @@ -24,6 +25,8 @@ import type {
GetDomainDnsRecordsRequest,
GetHostingRequest,
Hosting,
ListControlPanelsRequest,
ListControlPanelsResponse,
ListHostingsRequest,
ListHostingsResponse,
ListOffersRequest,
Expand All @@ -39,7 +42,7 @@ const jsonContentHeaders = {
/** Web Hosting API. */
export class API extends ParentAPI {
/** Lists the available regions of the API. */
public static readonly LOCALITIES: Region[] = ['fr-par']
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams']

/**
* Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer
Expand Down Expand Up @@ -75,6 +78,7 @@ export class API extends ParentAPI {
request.region ?? this.client.settings.defaultRegion,
)}/hostings`,
urlParams: urlParams(
['control_panels', request.controlPanels],
['domain', request.domain],
['order_by', request.orderBy],
['organization_id', request.organizationId],
Expand Down Expand Up @@ -257,4 +261,35 @@ export class API extends ParentAPI {
},
unmarshalListOffersResponse,
)

protected pageOfListControlPanels = (
request: Readonly<ListControlPanelsRequest> = {},
) =>
this.client.fetch<ListControlPanelsResponse>(
{
method: 'GET',
path: `/webhosting/v1alpha1/regions/${validatePathParam(
'region',
request.region ?? this.client.settings.defaultRegion,
)}/control-panels`,
urlParams: urlParams(
['page', request.page],
[
'page_size',
request.pageSize ?? this.client.settings.defaultPageSize,
],
),
},
unmarshalListControlPanelsResponse,
)

/**
* List all control panels type. List the control panels type: cpanel or
* plesk.
*
* @param request - The request {@link ListControlPanelsRequest}
* @returns A Promise of ListControlPanelsResponse
*/
listControlPanels = (request: Readonly<ListControlPanelsRequest> = {}) =>
enrichForPagination('controlPanels', this.pageOfListControlPanels, request)
}
3 changes: 3 additions & 0 deletions packages/clients/src/api/webhosting/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export { API } from './api.gen'
export * from './content.gen'
export type {
ControlPanel,
CreateHostingRequest,
DeleteHostingRequest,
DnsRecord,
Expand All @@ -17,6 +18,8 @@ export type {
HostingDnsStatus,
HostingOption,
HostingStatus,
ListControlPanelsRequest,
ListControlPanelsResponse,
ListHostingsRequest,
ListHostingsRequestOrderBy,
ListHostingsResponse,
Expand Down
36 changes: 36 additions & 0 deletions packages/clients/src/api/webhosting/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
ControlPanel,
CreateHostingRequest,
DnsRecord,
DnsRecords,
Hosting,
HostingCpanelUrls,
HostingOption,
ListControlPanelsResponse,
ListHostingsResponse,
ListOffersResponse,
Nameserver,
Expand Down Expand Up @@ -56,6 +58,7 @@ export const unmarshalHosting = (data: unknown): Hosting => {
}

return {
controlPanelName: data.control_panel_name,
cpanelUrls: data.cpanel_urls
? unmarshalHostingCpanelUrls(data.cpanel_urls)
: undefined,
Expand Down Expand Up @@ -124,6 +127,38 @@ export const unmarshalDnsRecords = (data: unknown): DnsRecords => {
} as DnsRecords
}

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

return {
available: data.available,
logoUrl: data.logo_url,
name: data.name,
} as ControlPanel
}

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

return {
controlPanels: unmarshalArrayOfObject(
data.control_panels,
unmarshalControlPanel,
),
totalCount: data.total_count,
} as ListControlPanelsResponse
}

export const unmarshalListHostingsResponse = (
data: unknown,
): ListHostingsResponse => {
Expand Down Expand Up @@ -170,6 +205,7 @@ const unmarshalOffer = (data: unknown): Offer => {
return {
available: data.available,
billingOperationPath: data.billing_operation_path,
controlPanelName: data.control_panel_name,
endOfLife: data.end_of_life,
id: data.id,
price: data.price ? unmarshalMoney(data.price) : undefined,
Expand Down
43 changes: 43 additions & 0 deletions packages/clients/src/api/webhosting/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ export interface Nameserver {
isDefault: boolean
}

export interface ControlPanel {
/** Control panel name. */
name: string
/** Define if the control panel type is available to order. */
available: boolean
/** URL of this control panel's logo. */
logoUrl: string
}

export interface Hosting {
/** ID of the Web Hosting plan. */
id: string
Expand Down Expand Up @@ -132,6 +141,8 @@ export interface Hosting {
username: string
/** Indicates if the hosting offer has reached its end of life. */
offerEndOfLife: boolean
/** Name of the control panel. */
controlPanelName: string
/** Region where the Web Hosting plan is hosted. */
region: Region
}
Expand All @@ -154,6 +165,8 @@ export interface Offer {
quotaWarnings: OfferQuotaWarning[]
/** Indicates if the offer has reached its end of life. */
endOfLife: boolean
/** Name of the control panel. */
controlPanelName: string
}

export type CreateHostingRequest = {
Expand Down Expand Up @@ -218,6 +231,31 @@ export type GetHostingRequest = {
hostingId: string
}

export type ListControlPanelsRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/**
* Page number to return, from the paginated results (must be a positive
* integer).
*/
page?: number
/**
* Number of control panels to return (must be a positive integer lower or
* equal to 100).
*/
pageSize?: number
}

export interface ListControlPanelsResponse {
/** Number of control panels returned. */
totalCount: number
/** List of control panels. */
controlPanels: ControlPanel[]
}

export type ListHostingsRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down Expand Up @@ -261,6 +299,11 @@ export type ListHostingsRequest = {
* Organization will be returned.
*/
organizationId?: string
/**
* Name of the control panel to filter for, only Web Hosting plans from this
* control panel will be returned.
*/
controlPanels?: string[]
}

export interface ListHostingsResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.

export const ListControlPanelsRequest = {
page: {
greaterThan: 0,
},
pageSize: {
greaterThan: 0,
lessThanOrEqual: 100,
},
}

export const ListHostingsRequest = {
page: {
greaterThan: 0,
Expand Down