Skip to content
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
19 changes: 19 additions & 0 deletions packages/clients/src/api/edge_services/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
unmarshalCheckLbOriginResponse,
unmarshalCheckPEMChainResponse,
unmarshalDNSStage,
unmarshalGetBillingResponse,
unmarshalListBackendStagesResponse,
unmarshalListCacheStagesResponse,
unmarshalListDNSStagesResponse,
Expand Down Expand Up @@ -69,6 +70,8 @@ import type {
DeletePipelineRequest,
DeleteTLSStageRequest,
GetBackendStageRequest,
GetBillingRequest,
GetBillingResponse,
GetCacheStageRequest,
GetCurrentPlanRequest,
GetDNSStageRequest,
Expand Down Expand Up @@ -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<GetBillingRequest> = {}) =>
this.client.fetch<GetBillingResponse>(
{
method: 'GET',
path: `/edge-services/v1alpha1/billing/${validatePathParam('projectId', request.projectId ?? this.client.settings.defaultProjectId)}`,
},
unmarshalGetBillingResponse,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type {
DeletePipelineRequest,
DeleteTLSStageRequest,
GetBackendStageRequest,
GetBillingRequest,
GetBillingResponse,
GetCacheStageRequest,
GetCurrentPlanRequest,
GetDNSStageRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
resolveOneOf,
unmarshalArrayOfObject,
unmarshalDate,
unmarshalMoney,
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
Expand All @@ -24,6 +25,7 @@ import type {
CreatePurgeRequestRequest,
CreateTLSStageRequest,
DNSStage,
GetBillingResponse,
ListBackendStagesResponse,
ListCacheStagesResponse,
ListDNSStagesResponse,
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down
31 changes: 30 additions & 1 deletion packages/clients/src/api/edge_services/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down