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 bd7d40337..abbe052e1 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/api.gen.ts @@ -22,6 +22,7 @@ import { marshalCreatePipelineRequest, marshalCreatePurgeRequestRequest, marshalCreateTLSStageRequest, + marshalSelectPlanRequest, marshalUpdateBackendStageRequest, marshalUpdateCacheStageRequest, marshalUpdateDNSStageRequest, @@ -37,9 +38,11 @@ import { unmarshalListCacheStagesResponse, unmarshalListDNSStagesResponse, unmarshalListPipelinesResponse, + unmarshalListPlansResponse, unmarshalListPurgeRequestsResponse, unmarshalListTLSStagesResponse, unmarshalPipeline, + unmarshalPlan, unmarshalPurgeRequest, unmarshalTLSStage, } from './marshalling.gen' @@ -61,11 +64,13 @@ import type { DNSStage, DeleteBackendStageRequest, DeleteCacheStageRequest, + DeleteCurrentPlanRequest, DeleteDNSStageRequest, DeletePipelineRequest, DeleteTLSStageRequest, GetBackendStageRequest, GetCacheStageRequest, + GetCurrentPlanRequest, GetDNSStageRequest, GetPipelineRequest, GetPurgeRequestRequest, @@ -78,12 +83,15 @@ import type { ListDNSStagesResponse, ListPipelinesRequest, ListPipelinesResponse, + ListPlansResponse, ListPurgeRequestsRequest, ListPurgeRequestsResponse, ListTLSStagesRequest, ListTLSStagesResponse, Pipeline, + Plan, PurgeRequest, + SelectPlanRequest, TLSStage, UpdateBackendStageRequest, UpdateCacheStageRequest, @@ -781,4 +789,49 @@ export class API extends ParentAPI { }, unmarshalCheckLbOriginResponse, ) + + listPlans = () => + this.client.fetch( + { + method: 'GET', + path: `/edge-services/v1alpha1/plans`, + }, + unmarshalListPlansResponse, + ) + + selectPlan = (request: Readonly = {}) => + this.client.fetch( + { + body: JSON.stringify( + marshalSelectPlanRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/edge-services/v1alpha1/current-plan`, + }, + unmarshalPlan, + ) + + getCurrentPlan = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/edge-services/v1alpha1/current-plan`, + urlParams: urlParams([ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ]), + }, + unmarshalPlan, + ) + + deleteCurrentPlan = (request: Readonly = {}) => + this.client.fetch({ + method: 'DELETE', + path: `/edge-services/v1alpha1/current-plan`, + urlParams: urlParams([ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ]), + }) } 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 f4404a2fb..1c594c759 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/index.gen.ts @@ -22,11 +22,13 @@ export type { DNSStageType, DeleteBackendStageRequest, DeleteCacheStageRequest, + DeleteCurrentPlanRequest, DeleteDNSStageRequest, DeletePipelineRequest, DeleteTLSStageRequest, GetBackendStageRequest, GetCacheStageRequest, + GetCurrentPlanRequest, GetDNSStageRequest, GetPipelineRequest, GetPurgeRequestRequest, @@ -44,6 +46,7 @@ export type { ListPipelinesRequest, ListPipelinesRequestOrderBy, ListPipelinesResponse, + ListPlansResponse, ListPurgeRequestsRequest, ListPurgeRequestsRequestOrderBy, ListPurgeRequestsResponse, @@ -57,11 +60,15 @@ export type { PipelineErrorStage, PipelineErrorType, PipelineStatus, + Plan, + PlanDetails, + PlanName, PurgeRequest, PurgeRequestStatus, ScalewayLb, ScalewayLbBackendConfig, ScalewayS3BackendConfig, + SelectPlanRequest, TLSSecret, TLSSecretsConfig, TLSStage, 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 83e817c11..5a731abc9 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/marshalling.gen.ts @@ -28,14 +28,18 @@ import type { ListCacheStagesResponse, ListDNSStagesResponse, ListPipelinesResponse, + ListPlansResponse, ListPurgeRequestsResponse, ListTLSStagesResponse, Pipeline, PipelineError, + Plan, + PlanDetails, PurgeRequest, ScalewayLb, ScalewayLbBackendConfig, ScalewayS3BackendConfig, + SelectPlanRequest, TLSSecret, TLSSecretsConfig, TLSStage, @@ -344,6 +348,35 @@ 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 => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListPlansResponse' failed as data isn't a dictionary.`, + ) + } + + return { + plans: unmarshalArrayOfObject(data.plans, unmarshalPlanDetails), + totalCount: data.total_count, + } as ListPlansResponse +} + export const unmarshalListPurgeRequestsResponse = ( data: unknown, ): ListPurgeRequestsResponse => { @@ -377,6 +410,18 @@ export const unmarshalListTLSStagesResponse = ( } as ListTLSStagesResponse } +export const unmarshalPlan = (data: unknown): Plan => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Plan' failed as data isn't a dictionary.`, + ) + } + + return { + planName: data.plan_name, + } as Plan +} + export const marshalCheckDomainRequest = ( request: CheckDomainRequest, defaults: DefaultValues, @@ -541,6 +586,14 @@ export const marshalCreateTLSStageRequest = ( ]), }) +export const marshalSelectPlanRequest = ( + request: SelectPlanRequest, + defaults: DefaultValues, +): Record => ({ + plan_name: request.planName, + project_id: request.projectId ?? defaults.defaultProjectId, +}) + export const marshalUpdateBackendStageRequest = ( request: UpdateBackendStageRequest, defaults: DefaultValues, 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 fd2bb2d2d..c1bfafaec 100644 --- a/packages/clients/src/api/edge_services/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/edge_services/v1alpha1/types.gen.ts @@ -77,6 +77,8 @@ export type PipelineStatus = | 'pending' | 'warning' +export type PlanName = 'unknown_name' | 'starter' | 'professional' | 'advanced' + export type PurgeRequestStatus = 'unknown_status' | 'done' | 'error' | 'pending' export interface ScalewayLb { @@ -240,6 +242,12 @@ export interface Pipeline { dnsStageId?: string } +export interface PlanDetails { + planName: PlanName + packageGb: number + pipelineLimit: number +} + export interface PurgeRequest { /** ID of the purge request. */ id: string @@ -469,6 +477,10 @@ export type DeleteCacheStageRequest = { cacheStageId: string } +export type DeleteCurrentPlanRequest = { + projectId?: string +} + export type DeleteDNSStageRequest = { /** ID of the DNS stage to delete. */ dnsStageId: string @@ -494,6 +506,10 @@ export type GetCacheStageRequest = { cacheStageId: string } +export type GetCurrentPlanRequest = { + projectId?: string +} + export type GetDNSStageRequest = { /** ID of the requested DNS stage. */ dnsStageId: string @@ -648,6 +664,11 @@ export interface ListPipelinesResponse { totalCount: number } +export interface ListPlansResponse { + totalCount: number + plans: PlanDetails[] +} + export type ListPurgeRequestsRequest = { /** Sort order of purge requests in the response. */ orderBy?: ListPurgeRequestsRequestOrderBy @@ -715,6 +736,15 @@ export interface ListTLSStagesResponse { totalCount: number } +export interface Plan { + planName: PlanName +} + +export type SelectPlanRequest = { + projectId?: string + planName?: PlanName +} + export type UpdateBackendStageRequest = { /** ID of the backend stage to update. */ backendStageId: string