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
52 changes: 52 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ import {
marshalEnableManagedAlertsRequest,
marshalResetCockpitGrafanaRequest,
marshalResetGrafanaUserPasswordRequest,
marshalSelectPlanRequest,
marshalTriggerTestAlertRequest,
unmarshalCockpit,
unmarshalCockpitMetrics,
unmarshalContactPoint,
unmarshalGrafanaUser,
unmarshalListContactPointsResponse,
unmarshalListGrafanaUsersResponse,
unmarshalListPlansResponse,
unmarshalListTokensResponse,
unmarshalSelectPlanResponse,
unmarshalToken,
} from './marshalling.gen'
import type {
Expand All @@ -53,10 +56,14 @@ import type {
ListContactPointsResponse,
ListGrafanaUsersRequest,
ListGrafanaUsersResponse,
ListPlansRequest,
ListPlansResponse,
ListTokensRequest,
ListTokensResponse,
ResetCockpitGrafanaRequest,
ResetGrafanaUserPasswordRequest,
SelectPlanRequest,
SelectPlanResponse,
Token,
TriggerTestAlertRequest,
} from './types.gen'
Expand Down Expand Up @@ -484,4 +491,49 @@ export class API extends ParentAPI {
},
unmarshalGrafanaUser,
)

protected pageOfListPlans = (request: Readonly<ListPlansRequest> = {}) =>
this.client.fetch<ListPlansResponse>(
{
method: 'GET',
path: `/cockpit/v1beta1/plans`,
urlParams: urlParams(
['order_by', request.orderBy ?? 'name_asc'],
['page', request.page],
[
'page_size',
request.pageSize ?? this.client.settings.defaultPageSize,
],
),
},
unmarshalListPlansResponse,
)

/**
* List plans. List all pricing plans.
*
* @param request - The request {@link ListPlansRequest}
* @returns A Promise of ListPlansResponse
*/
listPlans = (request: Readonly<ListPlansRequest> = {}) =>
enrichForPagination('plans', this.pageOfListPlans, request)

/**
* Select pricing plan. Select the wanted pricing plan.
*
* @param request - The request {@link SelectPlanRequest}
* @returns A Promise of SelectPlanResponse
*/
selectPlan = (request: Readonly<SelectPlanRequest>) =>
this.client.fetch<SelectPlanResponse>(
{
body: JSON.stringify(
marshalSelectPlanRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/cockpit/v1beta1/select-plan`,
},
unmarshalSelectPlanResponse,
)
}
7 changes: 7 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ export type {
ListGrafanaUsersRequest,
ListGrafanaUsersRequestOrderBy,
ListGrafanaUsersResponse,
ListPlansRequest,
ListPlansRequestOrderBy,
ListPlansResponse,
ListTokensRequest,
ListTokensRequestOrderBy,
ListTokensResponse,
Plan,
PlanName,
ResetCockpitGrafanaRequest,
ResetGrafanaUserPasswordRequest,
SelectPlanRequest,
SelectPlanResponse,
Token,
TokenScopes,
TriggerTestAlertRequest,
Expand Down
54 changes: 54 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ import type {
GrafanaUser,
ListContactPointsResponse,
ListGrafanaUsersResponse,
ListPlansResponse,
ListTokensResponse,
Plan,
ResetCockpitGrafanaRequest,
ResetGrafanaUserPasswordRequest,
SelectPlanRequest,
SelectPlanResponse,
Token,
TokenScopes,
TriggerTestAlertRequest,
Expand Down Expand Up @@ -105,6 +109,24 @@ export const unmarshalGrafanaUser = (data: unknown) => {
} as GrafanaUser
}

const unmarshalPlan = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'Plan' failed as data isn't a dictionary.`,
)
}

return {
id: data.id,
logsIngestionPrice: data.logs_ingestion_price,
name: data.name,
retentionLogsInterval: data.retention_logs_interval,
retentionMetricsInterval: data.retention_metrics_interval,
retentionPrice: data.retention_price,
sampleIngestionPrice: data.sample_ingestion_price,
} as Plan
}

export const unmarshalToken = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -136,6 +158,7 @@ export const unmarshalCockpit = (data: unknown) => {
? unmarshalCockpitEndpoints(data.endpoints)
: undefined,
managedAlertsEnabled: data.managed_alerts_enabled,
plan: data.plan ? unmarshalPlan(data.plan) : undefined,
projectId: data.project_id,
status: data.status,
updatedAt: unmarshalDate(data.updated_at),
Expand Down Expand Up @@ -188,6 +211,19 @@ export const unmarshalListGrafanaUsersResponse = (data: unknown) => {
} as ListGrafanaUsersResponse
}

export const unmarshalListPlansResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ListPlansResponse' failed as data isn't a dictionary.`,
)
}

return {
plans: unmarshalArrayOfObject(data.plans, unmarshalPlan),
totalCount: data.total_count,
} as ListPlansResponse
}

export const unmarshalListTokensResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand All @@ -201,6 +237,16 @@ export const unmarshalListTokensResponse = (data: unknown) => {
} as ListTokensResponse
}

export const unmarshalSelectPlanResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'SelectPlanResponse' failed as data isn't a dictionary.`,
)
}

return {} as SelectPlanResponse
}

const marshalContactPointEmail = (
request: ContactPointEmail,
defaults: DefaultValues,
Expand Down Expand Up @@ -324,6 +370,14 @@ export const marshalResetGrafanaUserPasswordRequest = (
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalSelectPlanRequest = (
request: SelectPlanRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
plan_id: request.planId,
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalTriggerTestAlertRequest = (
request: TriggerTestAlertRequest,
defaults: DefaultValues,
Expand Down
44 changes: 44 additions & 0 deletions packages/clients/src/api/cockpit/v1beta1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ export type GrafanaUserRole = 'unknown_role' | 'editor' | 'viewer'

export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc'

export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc'

export type ListTokensRequestOrderBy =
| 'created_at_asc'
| 'created_at_desc'
| 'name_asc'
| 'name_desc'

export type PlanName = 'unknown_name' | 'free' | 'premium' | 'custom'

/** Cockpit. */
export interface Cockpit {
/** Project ID. */
Expand All @@ -34,6 +38,8 @@ export interface Cockpit {
status: CockpitStatus
/** Managed alerts enabled. */
managedAlertsEnabled: boolean
/** Pricing plan. */
plan?: Plan
}

/** Cockpit. endpoints. */
Expand Down Expand Up @@ -90,12 +96,39 @@ export interface ListGrafanaUsersResponse {
grafanaUsers: GrafanaUser[]
}

/** List all pricing plans response. List plans response. */
export interface ListPlansResponse {
totalCount: number
plans: Plan[]
}

/** List tokens response. */
export interface ListTokensResponse {
totalCount: number
tokens: Token[]
}

/** Plan. */
export interface Plan {
/** Plan id. */
id: string
/** Plan name. */
name: PlanName
/** Retention for metrics. */
retentionMetricsInterval?: string
/** Retention for logs. */
retentionLogsInterval?: string
/** Ingestion price for 1million samples in cents. */
sampleIngestionPrice: number
/** Ingestion price in cents for 1 Go of logs. */
logsIngestionPrice: number
/** Retention price in euros per month. */
retentionPrice: number
}

/** Select pricing plan response. Select plan response. */
export interface SelectPlanResponse {}

/** Token. */
export interface Token {
id: string
Expand Down Expand Up @@ -222,3 +255,14 @@ export type ResetGrafanaUserPasswordRequest = {
grafanaUserId: number
projectId?: string
}

export type ListPlansRequest = {
page?: number
pageSize?: number
orderBy?: ListPlansRequestOrderBy
}

export type SelectPlanRequest = {
projectId?: string
planId: string
}