@gitpod/gitpod-protocol 0.1.5-mp-papi-stripe-secret-subpath.1 → 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,52 +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
+ from?: number;
13
+ to?: number;
14
+ order: Ordering;
15
+ pagination?: PaginationRequest;
16
+ }
12
17
 
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;
18
+ export enum Ordering {
19
+ ORDERING_DESCENDING = 0,
20
+ ORDERING_ASCENDING = 1,
21
+ }
30
22
 
31
- // The credits used for this session
32
- credits: number;
23
+ export interface PaginationRequest {
24
+ perPage: number;
25
+ page: number;
26
+ }
33
27
 
34
- // TODO - maybe
35
- projectId?: string;
28
+ export interface ListUsageResponse {
29
+ usageEntriesList: Usage[];
30
+ pagination?: PaginationResponse;
31
+ creditsUsed: number;
36
32
  }
37
33
 
38
- export interface ExtendedBillableSession extends BillableSession {
39
- contextURL?: string;
40
- user?: Pick<User.Profile, "name" | "avatarURL">;
34
+ export interface PaginationResponse {
35
+ perPage: number;
36
+ totalPages: number;
37
+ total: number;
38
+ page: number;
41
39
  }
42
40
 
43
- export interface BillableSessionRequest {
41
+ export type UsageKind = "workspaceinstance" | "invoice";
42
+ export interface Usage {
43
+ id: string;
44
44
  attributionId: string;
45
- startedTimeOrder: SortOrder;
46
- from?: number;
47
- to?: number;
45
+ description: string;
46
+ credits: number;
47
+ effectiveTime?: number;
48
+ kind: UsageKind;
49
+ workspaceInstanceId: string;
50
+ draft: boolean;
51
+ metadata: WorkspaceInstanceUsageData | InvoiceUsageData;
48
52
  }
49
53
 
50
- export type BillableWorkspaceType = WorkspaceType;
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
+ }
51
66
 
52
- export enum SortOrder {
53
- Descending = 0,
54
- Ascending = 1,
67
+ export interface InvoiceUsageData {
68
+ invoiceId: string;
69
+ startDate: string;
70
+ endDate: string;
55
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
  }