Skip to content

Commit 54c1f2e

Browse files
authored
feat(webhosting): add hosting resource summary (#1573)
1 parent 1966eef commit 54c1f2e

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
unmarshalListWebsitesResponse,
3737
unmarshalMailAccount,
3838
unmarshalResetHostingPasswordResponse,
39+
unmarshalResourceSummary,
3940
unmarshalSession,
4041
} from './marshalling.gen'
4142
import type {
@@ -63,6 +64,7 @@ import type {
6364
HostingApiCreateSessionRequest,
6465
HostingApiDeleteHostingRequest,
6566
HostingApiGetHostingRequest,
67+
HostingApiGetResourceSummaryRequest,
6668
HostingApiListHostingsRequest,
6769
HostingApiResetHostingPasswordRequest,
6870
HostingApiUpdateHostingRequest,
@@ -81,6 +83,7 @@ import type {
8183
MailAccountApiRemoveMailAccountRequest,
8284
OfferApiListOffersRequest,
8385
ResetHostingPasswordResponse,
86+
ResourceSummary,
8487
Session,
8588
WebsiteApiListWebsitesRequest,
8689
} from './types.gen'
@@ -593,6 +596,24 @@ export class HostingAPI extends ParentAPI {
593596
},
594597
unmarshalResetHostingPasswordResponse,
595598
)
599+
600+
/**
601+
* Get the total counts of websites, databases, email accounts, and FTP
602+
* accounts of a Web Hosting plan.
603+
*
604+
* @param request - The request {@link HostingApiGetResourceSummaryRequest}
605+
* @returns A Promise of ResourceSummary
606+
*/
607+
getResourceSummary = (
608+
request: Readonly<HostingApiGetResourceSummaryRequest>,
609+
) =>
610+
this.client.fetch<ResourceSummary>(
611+
{
612+
method: 'GET',
613+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/resource-summary`,
614+
},
615+
unmarshalResourceSummary,
616+
)
596617
}
597618

598619
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type {
3737
HostingApiCreateSessionRequest,
3838
HostingApiDeleteHostingRequest,
3939
HostingApiGetHostingRequest,
40+
HostingApiGetResourceSummaryRequest,
4041
HostingApiListHostingsRequest,
4142
HostingApiResetHostingPasswordRequest,
4243
HostingApiUpdateHostingRequest,
@@ -73,6 +74,7 @@ export type {
7374
OfferOptionRequest,
7475
OfferOptionWarning,
7576
ResetHostingPasswordResponse,
77+
ResourceSummary,
7678
Session,
7779
Website,
7880
WebsiteApiListWebsitesRequest,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import type {
4242
OfferOption,
4343
OfferOptionRequest,
4444
ResetHostingPasswordResponse,
45+
ResourceSummary,
4546
Session,
4647
Website,
4748
} from './types.gen'
@@ -385,6 +386,21 @@ export const unmarshalResetHostingPasswordResponse = (
385386
} as ResetHostingPasswordResponse
386387
}
387388

389+
export const unmarshalResourceSummary = (data: unknown): ResourceSummary => {
390+
if (!isJSONObject(data)) {
391+
throw new TypeError(
392+
`Unmarshalling the type 'ResourceSummary' failed as data isn't a dictionary.`,
393+
)
394+
}
395+
396+
return {
397+
databasesCount: data.databases_count,
398+
ftpAccountsCount: data.ftp_accounts_count,
399+
mailAccountsCount: data.mail_accounts_count,
400+
websitesCount: data.websites_count,
401+
} as ResourceSummary
402+
}
403+
388404
export const unmarshalSession = (data: unknown): Session => {
389405
if (!isJSONObject(data)) {
390406
throw new TypeError(

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,16 @@ export type HostingApiGetHostingRequest = {
539539
hostingId: string
540540
}
541541

542+
export type HostingApiGetResourceSummaryRequest = {
543+
/**
544+
* Region to target. If none is passed will use default region from the
545+
* config.
546+
*/
547+
region?: Region
548+
/** Hosting ID. */
549+
hostingId: string
550+
}
551+
542552
export type HostingApiListHostingsRequest = {
543553
/**
544554
* Region to target. If none is passed will use default region from the
@@ -768,6 +778,17 @@ export interface ResetHostingPasswordResponse {
768778
oneTimePassword: string
769779
}
770780

781+
export interface ResourceSummary {
782+
/** Total number of active databases in the Web Hosting plan. */
783+
databasesCount: number
784+
/** Total number of active email accounts in the Web Hosting plan. */
785+
mailAccountsCount: number
786+
/** Total number of active FTP accounts in the Web Hosting plan. */
787+
ftpAccountsCount: number
788+
/** Total number of active domains in the the Web Hosting plan. */
789+
websitesCount: number
790+
}
791+
771792
export interface Session {
772793
/** Logged user's session URL. */
773794
url: string

0 commit comments

Comments
 (0)