@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/data/gitpod-schema.json +19 -0
- package/lib/admin-protocol.d.ts +3 -0
- package/lib/admin-protocol.d.ts.map +1 -1
- package/lib/admin-protocol.js.map +1 -1
- package/lib/billing-mode.d.ts +2 -1
- package/lib/billing-mode.d.ts.map +1 -1
- package/lib/billing-mode.js +8 -0
- package/lib/billing-mode.js.map +1 -1
- package/lib/gitpod-service.d.ts +12 -17
- package/lib/gitpod-service.d.ts.map +1 -1
- package/lib/gitpod-service.js +12 -0
- package/lib/gitpod-service.js.map +1 -1
- package/lib/protocol.d.ts +16 -3
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +13 -1
- package/lib/protocol.js.map +1 -1
- package/lib/teams-projects-protocol.d.ts +0 -1
- package/lib/teams-projects-protocol.d.ts.map +1 -1
- package/lib/teams-projects-protocol.js.map +1 -1
- package/lib/usage.d.ts +46 -28
- package/lib/usage.d.ts.map +1 -1
- package/lib/usage.js +6 -0
- package/lib/usage.js.map +1 -1
- package/lib/util/timeutil.spec.d.ts +1 -0
- package/lib/util/timeutil.spec.d.ts.map +1 -1
- package/lib/util/timeutil.spec.js +24 -0
- package/lib/util/timeutil.spec.js.map +1 -1
- package/package.json +1 -1
- package/pkg-yarn.lock +1 -1
- package/provenance-bundle.jsonl +1 -1
- package/src/admin-protocol.ts +3 -0
- package/src/billing-mode.ts +11 -1
- package/src/gitpod-service.ts +24 -17
- package/src/protocol.ts +22 -3
- package/src/teams-projects-protocol.ts +0 -1
- package/src/usage.ts +51 -43
- package/src/util/timeutil.spec.ts +21 -0
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 {
|
|
7
|
+
import { WorkspaceType } from "./protocol";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
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
|
}
|