diff --git a/packages/clients/src/api/edge_services/v1alpha1/api.gen.ts b/packages/clients/src/api/edge_services/v1alpha1/api.gen.ts index 7c45077cd..d07adf9f4 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/api.gen.ts @@ -34,6 +34,7 @@ import { unmarshalCheckLbOriginResponse, unmarshalCheckPEMChainResponse, unmarshalDNSStage, + unmarshalGetBillingResponse, unmarshalListBackendStagesResponse, unmarshalListCacheStagesResponse, unmarshalListDNSStagesResponse, @@ -69,6 +70,8 @@ import type { DeletePipelineRequest, DeleteTLSStageRequest, GetBackendStageRequest, + GetBillingRequest, + GetBillingResponse, GetCacheStageRequest, GetCurrentPlanRequest, GetDNSStageRequest, @@ -826,4 +829,20 @@ export class API extends ParentAPI { method: 'DELETE', path: `/edge-services/v1alpha1/current-plan/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}`, }) + + /** + * Gives information on current edge-services subscription plan and used + * resources with associated price. + * + * @param request - The request {@link GetBillingRequest} + * @returns A Promise of GetBillingResponse + */ + getBilling = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/edge-services/v1alpha1/billing/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}`, + }, + unmarshalGetBillingResponse, + ) } diff --git a/packages/clients/src/api/edge_services/v1alpha1/index.gen.ts b/packages/clients/src/api/edge_services/v1alpha1/index.gen.ts index 1c594c759..3a5f14d98 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/index.gen.ts @@ -27,6 +27,8 @@ export type { DeletePipelineRequest, DeleteTLSStageRequest, GetBackendStageRequest, + GetBillingRequest, + GetBillingResponse, GetCacheStageRequest, GetCurrentPlanRequest, GetDNSStageRequest, diff --git a/packages/clients/src/api/edge_services/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/edge_services/v1alpha1/marshalling.gen.ts index 363cb6608..0474fd538 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/marshalling.gen.ts @@ -5,6 +5,7 @@ import { resolveOneOf, unmarshalArrayOfObject, unmarshalDate, + unmarshalMoney, } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { @@ -24,6 +25,7 @@ import type { CreatePurgeRequestRequest, CreateTLSStageRequest, DNSStage, + GetBillingResponse, ListBackendStagesResponse, ListCacheStagesResponse, ListDNSStagesResponse, @@ -288,6 +290,47 @@ export const unmarshalCheckPEMChainResponse = ( } as CheckPEMChainResponse } +const unmarshalPlanDetails = (data: unknown): PlanDetails => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'PlanDetails' failed as data isn't a dictionary.`, + ) + } + + return { + packageGb: data.package_gb, + pipelineLimit: data.pipeline_limit, + planName: data.plan_name, + } as PlanDetails +} + +export const unmarshalGetBillingResponse = ( + data: unknown, +): GetBillingResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'GetBillingResponse' failed as data isn't a dictionary.`, + ) + } + + return { + currentPlan: data.current_plan + ? unmarshalPlanDetails(data.current_plan) + : undefined, + currentPlanCacheUsage: data.current_plan_cache_usage, + extraCacheCost: data.extra_cache_cost + ? unmarshalMoney(data.extra_cache_cost) + : undefined, + extraCacheUsage: data.extra_cache_usage, + extraPipelinesCost: data.extra_pipelines_cost + ? unmarshalMoney(data.extra_pipelines_cost) + : undefined, + pipelineNumber: data.pipeline_number, + planCost: data.plan_cost ? unmarshalMoney(data.plan_cost) : undefined, + totalCost: data.total_cost ? unmarshalMoney(data.total_cost) : undefined, + } as GetBillingResponse +} + export const unmarshalListBackendStagesResponse = ( data: unknown, ): ListBackendStagesResponse => { @@ -348,20 +391,6 @@ export const unmarshalListPipelinesResponse = ( } as ListPipelinesResponse } -const unmarshalPlanDetails = (data: unknown): PlanDetails => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'PlanDetails' failed as data isn't a dictionary.`, - ) - } - - return { - packageGb: data.package_gb, - pipelineLimit: data.pipeline_limit, - planName: data.plan_name, - } as PlanDetails -} - export const unmarshalListPlansResponse = ( data: unknown, ): ListPlansResponse => { diff --git a/packages/clients/src/api/edge_services/v1alpha1/types.gen.ts b/packages/clients/src/api/edge_services/v1alpha1/types.gen.ts index 8be9232b0..455974838 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/types.gen.ts @@ -1,6 +1,6 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -import type { Region, Zone } from '../../../bridge' +import type { Money, Region, Zone } from '../../../bridge' export type DNSStageType = 'unknown_type' | 'auto' | 'managed' | 'custom' @@ -279,8 +279,11 @@ export interface CheckPEMChainRequestSecretChain { } export interface PlanDetails { + /** Subscription plan name. */ planName: PlanName + /** Amount of egress data from cache included in subscription plan. */ packageGb: number + /** Number of pipeline included in subscription plan. */ pipelineLimit: number } @@ -501,6 +504,32 @@ export type GetBackendStageRequest = { backendStageId: string } +export type GetBillingRequest = { + projectId?: string +} + +export interface GetBillingResponse { + /** Information on the current edge-service subscription plan. */ + currentPlan?: PlanDetails + /** Price of the current subscription plan. */ + planCost?: Money + /** Total number of pipeline currently configured. */ + pipelineNumber: number + /** Cost to date of the pipelines not included in the plans. */ + extraPipelinesCost?: Money + /** Total amount of data egressed from cache in current subscription plan. */ + currentPlanCacheUsage: number + /** Total amount of data egressed from cache not included in the plans. */ + extraCacheUsage: number + /** Cost to date of the data egressed from cache not included in the plans. */ + extraCacheCost?: Money + /** + * Total cost to date of edge-service product for the month including current + * plan, previous plans, extra pipelines and extra egress cache data. + */ + totalCost?: Money +} + export type GetCacheStageRequest = { /** ID of the requested cache stage. */ cacheStageId: string