-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathusage.ts
129 lines (105 loc) · 2.92 KB
/
usage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/
import { User, WorkspaceType } from "./protocol";
export interface BillableSession {
// The id of the one paying the bill
attributionId: string;
// Relevant for workspace type. When prebuild, shows "prebuild"
userId?: string;
teamId?: string;
instanceId: string;
workspaceId: string;
workspaceType: BillableWorkspaceType;
workspaceClass: string;
// When the workspace started
startTime: string;
// When the workspace ended. Not set when the workspace is still running.
endTime?: string;
// The credits used for this session
credits: number;
// TODO - maybe
projectId?: string;
}
export interface ExtendedBillableSession extends BillableSession {
contextURL?: string;
user?: Pick<User.Profile, "name" | "avatarURL">;
}
/**
* This is a paginated request
*/
export interface ListBilledUsageRequest {
attributionId: string;
fromDate?: number;
toDate?: number;
perPage: number;
page: number;
}
export interface ListBilledUsageResponse {
sessions: ExtendedBillableSession[];
totalCreditsUsed: number;
totalPages: number;
totalSessions: number;
perPage: number;
page: number;
}
export type BillableWorkspaceType = WorkspaceType;
// types below are copied over from components/usage-api/typescript/src/usage/v1/usage_pb.d.ts
export interface ListUsageRequest {
attributionId: string;
from?: number;
to?: number;
order: Ordering;
pagination?: PaginationRequest;
}
export enum Ordering {
ORDERING_DESCENDING = 0,
ORDERING_ASCENDING = 1,
}
export interface PaginationRequest {
perPage: number;
page: number;
}
export interface ListUsageResponse {
usageEntriesList: Usage[];
pagination?: PaginationResponse;
creditBalanceAtStart: number;
creditBalanceAtEnd: number;
}
export interface PaginationResponse {
perPage: number;
totalPages: number;
total: number;
page: number;
}
export type UsageKind = "workspaceinstance" | "invoice";
export interface Usage {
id: string;
attributionId: string;
description: string;
credits: number;
effectiveTime?: number;
kind: UsageKind;
workspaceInstanceId: string;
draft: boolean;
metadata: WorkspaceInstanceUsageData | InvoiceUsageData;
}
// the equivalent golang shape is maintained in `/workspace/gitpod/`components/usage/pkg/db/usage.go`
export interface WorkspaceInstanceUsageData {
workspaceId: string;
workspaceType: WorkspaceType;
workspaceClass: string;
contextURL: string;
startTime: string;
endTime?: string;
userId: string;
userName: string;
userAvatarURL: string;
}
export interface InvoiceUsageData {
invoiceId: string;
startDate: string;
endDate: string;
}