@gitpod/gitpod-protocol 0.1.5-mp-stripe-finalize-invoice.13 → 0.1.5-mp-revert-dialer-usage.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/usage.ts CHANGED
@@ -4,60 +4,68 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
- import { User, WorkspaceType } from "./protocol";
7
+ import { WorkspaceType } from "./protocol";
8
8
 
9
- export interface BillableSession {
10
- // The id of the one paying the bill
9
+ // types below are copied over from components/usage-api/typescript/src/usage/v1/usage_pb.d.ts
10
+ export interface ListUsageRequest {
11
11
  attributionId: string;
12
-
13
- // Relevant for workspace type. When prebuild, shows "prebuild"
14
- userId?: string;
15
- teamId?: string;
16
-
17
- instanceId: string;
18
-
19
- workspaceId: string;
20
-
21
- workspaceType: BillableWorkspaceType;
22
-
23
- workspaceClass: string;
24
-
25
- // When the workspace started
26
- startTime: string;
27
-
28
- // When the workspace ended. Not set when the workspace is still running.
29
- endTime?: string;
30
-
31
- // The credits used for this session
32
- credits: number;
33
-
34
- // TODO - maybe
35
- projectId?: string;
12
+ from?: number;
13
+ to?: number;
14
+ order: Ordering;
15
+ pagination?: PaginationRequest;
36
16
  }
37
17
 
38
- export interface ExtendedBillableSession extends BillableSession {
39
- contextURL?: string;
40
- user?: Pick<User.Profile, "name" | "avatarURL">;
18
+ export enum Ordering {
19
+ ORDERING_DESCENDING = 0,
20
+ ORDERING_ASCENDING = 1,
41
21
  }
42
22
 
43
- /**
44
- * This is a paginated request
45
- */
46
- export interface ListBilledUsageRequest {
47
- attributionId: string;
48
- fromDate?: number;
49
- toDate?: number;
23
+ export interface PaginationRequest {
50
24
  perPage: number;
51
25
  page: number;
52
26
  }
53
27
 
54
- export interface ListBilledUsageResponse {
55
- sessions: ExtendedBillableSession[];
56
- totalCreditsUsed: number;
57
- totalPages: number;
58
- totalSessions: number;
28
+ export interface ListUsageResponse {
29
+ usageEntriesList: Usage[];
30
+ pagination?: PaginationResponse;
31
+ creditsUsed: number;
32
+ }
33
+
34
+ export interface PaginationResponse {
59
35
  perPage: number;
36
+ totalPages: number;
37
+ total: number;
60
38
  page: number;
61
39
  }
62
40
 
63
- export type BillableWorkspaceType = WorkspaceType;
41
+ export type UsageKind = "workspaceinstance" | "invoice";
42
+ export interface Usage {
43
+ id: string;
44
+ attributionId: string;
45
+ description: string;
46
+ credits: number;
47
+ effectiveTime?: number;
48
+ kind: UsageKind;
49
+ workspaceInstanceId: string;
50
+ draft: boolean;
51
+ metadata: WorkspaceInstanceUsageData | InvoiceUsageData;
52
+ }
53
+
54
+ // the equivalent golang shape is maintained in `/workspace/gitpod/`components/usage/pkg/db/usage.go`
55
+ export interface WorkspaceInstanceUsageData {
56
+ workspaceId: string;
57
+ workspaceType: WorkspaceType;
58
+ workspaceClass: string;
59
+ contextURL: string;
60
+ startTime: string;
61
+ endTime?: string;
62
+ userId: string;
63
+ userName: string;
64
+ userAvatarURL: string;
65
+ }
66
+
67
+ export interface InvoiceUsageData {
68
+ invoiceId: string;
69
+ startDate: string;
70
+ endDate: string;
71
+ }
@@ -45,4 +45,25 @@ export class TimeutilSpec {
45
45
  const later = oneMonthLater(from.toISOString(), day);
46
46
  expect(later, `expected ${later} to be equal ${expectation}`).to.be.equal(expectation.toISOString());
47
47
  }
48
+
49
+ @test
50
+ testDaysBefore2() {
51
+ const tests: { date: Date; daysEarlier: number; expectation: string }[] = [
52
+ {
53
+ date: new Date("2021-07-13T00:00:00.000Z"),
54
+ daysEarlier: 365,
55
+ expectation: "2020-07-13T00:00:00.000Z",
56
+ },
57
+ {
58
+ date: new Date("2019-02-01T00:00:00.000Z"),
59
+ daysEarlier: 365,
60
+ expectation: "2018-02-01T00:00:00.000Z",
61
+ },
62
+ ];
63
+
64
+ for (const t of tests) {
65
+ const actual = daysBefore(t.date.toISOString(), t.daysEarlier);
66
+ expect(actual).to.equal(t.expectation, `expected ${actual} to be equal ${t.expectation}`);
67
+ }
68
+ }
48
69
  }