Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/usage.ts
2498 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { WorkspaceType } from "./protocol";
8
9
// types below are manually kept in sycn with components/usage-api/typescript/src/usage/v1/usage_pb.d.ts
10
export interface ListUsageRequest {
11
attributionId: string;
12
userId?: string;
13
from?: number;
14
to?: number;
15
order: Ordering;
16
pagination?: PaginationRequest;
17
}
18
19
export enum Ordering {
20
ORDERING_DESCENDING = 0,
21
ORDERING_ASCENDING = 1,
22
}
23
24
export interface PaginationRequest {
25
perPage: number;
26
page: number;
27
}
28
29
export interface ListUsageResponse {
30
usageEntriesList: Usage[];
31
pagination?: PaginationResponse;
32
creditsUsed: number;
33
ledgerIntervalMinutes?: number;
34
}
35
36
export interface PaginationResponse {
37
perPage: number;
38
totalPages: number;
39
total: number;
40
page: number;
41
}
42
43
export type UsageKind = "workspaceinstance" | "invoice";
44
export interface Usage {
45
id: string;
46
attributionId: string;
47
description: string;
48
credits: number;
49
effectiveTime?: number;
50
kind: UsageKind;
51
workspaceInstanceId: string;
52
draft: boolean;
53
metadata: WorkspaceInstanceUsageData | InvoiceUsageData;
54
}
55
56
// the equivalent golang shape is maintained in `/workspace/gitpod/`components/usage/pkg/db/usage.go`
57
export interface WorkspaceInstanceUsageData {
58
workspaceId: string;
59
workspaceType: WorkspaceType;
60
workspaceClass: string;
61
contextURL: string;
62
creationTime?: string;
63
startTime: string;
64
endTime?: string;
65
stoppedTime?: string;
66
userId: string;
67
userName: string;
68
userAvatarURL: string;
69
}
70
71
export interface InvoiceUsageData {
72
invoiceId: string;
73
startDate: string;
74
endDate: string;
75
}
76
77
export interface CostCenterJSON {
78
attributionId: string;
79
spendingLimit: number;
80
billingStrategy: CostCenter_BillingStrategy;
81
nextBillingTime?: string;
82
billingCycleStart?: string;
83
}
84
85
export enum CostCenter_BillingStrategy {
86
BILLING_STRATEGY_STRIPE = "BILLING_STRATEGY_STRIPE",
87
BILLING_STRATEGY_OTHER = "BILLING_STRATEGY_OTHER",
88
UNRECOGNIZED = "UNRECOGNIZED",
89
}
90
91