Skip to content

Commit 78a74da

Browse files
authored
feat(cockpit): add listPlans and selectPlan endpoints (#569)
1 parent ee5ac49 commit 78a74da

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

packages/clients/src/api/cockpit/v1beta1/api.gen.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ import {
2121
marshalEnableManagedAlertsRequest,
2222
marshalResetCockpitGrafanaRequest,
2323
marshalResetGrafanaUserPasswordRequest,
24+
marshalSelectPlanRequest,
2425
marshalTriggerTestAlertRequest,
2526
unmarshalCockpit,
2627
unmarshalCockpitMetrics,
2728
unmarshalContactPoint,
2829
unmarshalGrafanaUser,
2930
unmarshalListContactPointsResponse,
3031
unmarshalListGrafanaUsersResponse,
32+
unmarshalListPlansResponse,
3133
unmarshalListTokensResponse,
34+
unmarshalSelectPlanResponse,
3235
unmarshalToken,
3336
} from './marshalling.gen'
3437
import type {
@@ -53,10 +56,14 @@ import type {
5356
ListContactPointsResponse,
5457
ListGrafanaUsersRequest,
5558
ListGrafanaUsersResponse,
59+
ListPlansRequest,
60+
ListPlansResponse,
5661
ListTokensRequest,
5762
ListTokensResponse,
5863
ResetCockpitGrafanaRequest,
5964
ResetGrafanaUserPasswordRequest,
65+
SelectPlanRequest,
66+
SelectPlanResponse,
6067
Token,
6168
TriggerTestAlertRequest,
6269
} from './types.gen'
@@ -484,4 +491,49 @@ export class API extends ParentAPI {
484491
},
485492
unmarshalGrafanaUser,
486493
)
494+
495+
protected pageOfListPlans = (request: Readonly<ListPlansRequest> = {}) =>
496+
this.client.fetch<ListPlansResponse>(
497+
{
498+
method: 'GET',
499+
path: `/cockpit/v1beta1/plans`,
500+
urlParams: urlParams(
501+
['order_by', request.orderBy ?? 'name_asc'],
502+
['page', request.page],
503+
[
504+
'page_size',
505+
request.pageSize ?? this.client.settings.defaultPageSize,
506+
],
507+
),
508+
},
509+
unmarshalListPlansResponse,
510+
)
511+
512+
/**
513+
* List plans. List all pricing plans.
514+
*
515+
* @param request - The request {@link ListPlansRequest}
516+
* @returns A Promise of ListPlansResponse
517+
*/
518+
listPlans = (request: Readonly<ListPlansRequest> = {}) =>
519+
enrichForPagination('plans', this.pageOfListPlans, request)
520+
521+
/**
522+
* Select pricing plan. Select the wanted pricing plan.
523+
*
524+
* @param request - The request {@link SelectPlanRequest}
525+
* @returns A Promise of SelectPlanResponse
526+
*/
527+
selectPlan = (request: Readonly<SelectPlanRequest>) =>
528+
this.client.fetch<SelectPlanResponse>(
529+
{
530+
body: JSON.stringify(
531+
marshalSelectPlanRequest(request, this.client.settings),
532+
),
533+
headers: jsonContentHeaders,
534+
method: 'POST',
535+
path: `/cockpit/v1beta1/select-plan`,
536+
},
537+
unmarshalSelectPlanResponse,
538+
)
487539
}

packages/clients/src/api/cockpit/v1beta1/index.gen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ export type {
2929
ListGrafanaUsersRequest,
3030
ListGrafanaUsersRequestOrderBy,
3131
ListGrafanaUsersResponse,
32+
ListPlansRequest,
33+
ListPlansRequestOrderBy,
34+
ListPlansResponse,
3235
ListTokensRequest,
3336
ListTokensRequestOrderBy,
3437
ListTokensResponse,
38+
Plan,
39+
PlanName,
3540
ResetCockpitGrafanaRequest,
3641
ResetGrafanaUserPasswordRequest,
42+
SelectPlanRequest,
43+
SelectPlanResponse,
3744
Token,
3845
TokenScopes,
3946
TriggerTestAlertRequest,

packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ import type {
2727
GrafanaUser,
2828
ListContactPointsResponse,
2929
ListGrafanaUsersResponse,
30+
ListPlansResponse,
3031
ListTokensResponse,
32+
Plan,
3133
ResetCockpitGrafanaRequest,
3234
ResetGrafanaUserPasswordRequest,
35+
SelectPlanRequest,
36+
SelectPlanResponse,
3337
Token,
3438
TokenScopes,
3539
TriggerTestAlertRequest,
@@ -105,6 +109,24 @@ export const unmarshalGrafanaUser = (data: unknown) => {
105109
} as GrafanaUser
106110
}
107111

112+
const unmarshalPlan = (data: unknown) => {
113+
if (!isJSONObject(data)) {
114+
throw new TypeError(
115+
`Unmarshalling the type 'Plan' failed as data isn't a dictionary.`,
116+
)
117+
}
118+
119+
return {
120+
id: data.id,
121+
logsIngestionPrice: data.logs_ingestion_price,
122+
name: data.name,
123+
retentionLogsInterval: data.retention_logs_interval,
124+
retentionMetricsInterval: data.retention_metrics_interval,
125+
retentionPrice: data.retention_price,
126+
sampleIngestionPrice: data.sample_ingestion_price,
127+
} as Plan
128+
}
129+
108130
export const unmarshalToken = (data: unknown) => {
109131
if (!isJSONObject(data)) {
110132
throw new TypeError(
@@ -136,6 +158,7 @@ export const unmarshalCockpit = (data: unknown) => {
136158
? unmarshalCockpitEndpoints(data.endpoints)
137159
: undefined,
138160
managedAlertsEnabled: data.managed_alerts_enabled,
161+
plan: data.plan ? unmarshalPlan(data.plan) : undefined,
139162
projectId: data.project_id,
140163
status: data.status,
141164
updatedAt: unmarshalDate(data.updated_at),
@@ -188,6 +211,19 @@ export const unmarshalListGrafanaUsersResponse = (data: unknown) => {
188211
} as ListGrafanaUsersResponse
189212
}
190213

214+
export const unmarshalListPlansResponse = (data: unknown) => {
215+
if (!isJSONObject(data)) {
216+
throw new TypeError(
217+
`Unmarshalling the type 'ListPlansResponse' failed as data isn't a dictionary.`,
218+
)
219+
}
220+
221+
return {
222+
plans: unmarshalArrayOfObject(data.plans, unmarshalPlan),
223+
totalCount: data.total_count,
224+
} as ListPlansResponse
225+
}
226+
191227
export const unmarshalListTokensResponse = (data: unknown) => {
192228
if (!isJSONObject(data)) {
193229
throw new TypeError(
@@ -201,6 +237,16 @@ export const unmarshalListTokensResponse = (data: unknown) => {
201237
} as ListTokensResponse
202238
}
203239

240+
export const unmarshalSelectPlanResponse = (data: unknown) => {
241+
if (!isJSONObject(data)) {
242+
throw new TypeError(
243+
`Unmarshalling the type 'SelectPlanResponse' failed as data isn't a dictionary.`,
244+
)
245+
}
246+
247+
return {} as SelectPlanResponse
248+
}
249+
204250
const marshalContactPointEmail = (
205251
request: ContactPointEmail,
206252
defaults: DefaultValues,
@@ -324,6 +370,14 @@ export const marshalResetGrafanaUserPasswordRequest = (
324370
project_id: request.projectId ?? defaults.defaultProjectId,
325371
})
326372

373+
export const marshalSelectPlanRequest = (
374+
request: SelectPlanRequest,
375+
defaults: DefaultValues,
376+
): Record<string, unknown> => ({
377+
plan_id: request.planId,
378+
project_id: request.projectId ?? defaults.defaultProjectId,
379+
})
380+
327381
export const marshalTriggerTestAlertRequest = (
328382
request: TriggerTestAlertRequest,
329383
defaults: DefaultValues,

packages/clients/src/api/cockpit/v1beta1/types.gen.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ export type GrafanaUserRole = 'unknown_role' | 'editor' | 'viewer'
1414

1515
export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'
1616

17+
export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc'
18+
1719
export type ListTokensRequestOrderBy =
1820
| 'created_at_asc'
1921
| 'created_at_desc'
2022
| 'name_asc'
2123
| 'name_desc'
2224

25+
export type PlanName = 'unknown_name' | 'free' | 'premium' | 'custom'
26+
2327
/** Cockpit. */
2428
export interface Cockpit {
2529
/** Project ID. */
@@ -34,6 +38,8 @@ export interface Cockpit {
3438
status: CockpitStatus
3539
/** Managed alerts enabled. */
3640
managedAlertsEnabled: boolean
41+
/** Pricing plan. */
42+
plan?: Plan
3743
}
3844

3945
/** Cockpit. endpoints. */
@@ -90,12 +96,39 @@ export interface ListGrafanaUsersResponse {
9096
grafanaUsers: GrafanaUser[]
9197
}
9298

99+
/** List all pricing plans response. List plans response. */
100+
export interface ListPlansResponse {
101+
totalCount: number
102+
plans: Plan[]
103+
}
104+
93105
/** List tokens response. */
94106
export interface ListTokensResponse {
95107
totalCount: number
96108
tokens: Token[]
97109
}
98110

111+
/** Plan. */
112+
export interface Plan {
113+
/** Plan id. */
114+
id: string
115+
/** Plan name. */
116+
name: PlanName
117+
/** Retention for metrics. */
118+
retentionMetricsInterval?: string
119+
/** Retention for logs. */
120+
retentionLogsInterval?: string
121+
/** Ingestion price for 1million samples in cents. */
122+
sampleIngestionPrice: number
123+
/** Ingestion price in cents for 1 Go of logs. */
124+
logsIngestionPrice: number
125+
/** Retention price in euros per month. */
126+
retentionPrice: number
127+
}
128+
129+
/** Select pricing plan response. Select plan response. */
130+
export interface SelectPlanResponse {}
131+
99132
/** Token. */
100133
export interface Token {
101134
id: string
@@ -222,3 +255,14 @@ export type ResetGrafanaUserPasswordRequest = {
222255
grafanaUserId: number
223256
projectId?: string
224257
}
258+
259+
export type ListPlansRequest = {
260+
page?: number
261+
pageSize?: number
262+
orderBy?: ListPlansRequestOrderBy
263+
}
264+
265+
export type SelectPlanRequest = {
266+
projectId?: string
267+
planId: string
268+
}

0 commit comments

Comments
 (0)