@gitpod/gitpod-protocol 0.1.5-tar-sh-active-users.8 → 0.1.5-tar-sh-active-users.22

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.
@@ -60,7 +60,7 @@ import {
60
60
  import { RemotePageMessage, RemoteTrackMessage, RemoteIdentifyMessage } from "./analytics";
61
61
  import { IDEServer } from "./ide-protocol";
62
62
  import { InstallationAdminSettings, TelemetryData } from "./installation-admin-protocol";
63
- import { ListBilledUsageResponse, ListBilledUsageRequest } from "./usage";
63
+ import { ListUsageRequest, ListUsageResponse } from "./usage";
64
64
  import { SupportedWorkspaceClass } from "./workspace-class";
65
65
  import { BillingMode } from "./billing-mode";
66
66
 
@@ -70,6 +70,8 @@ export interface GitpodClient {
70
70
 
71
71
  onPrebuildUpdate(update: PrebuildWithStatus): void;
72
72
 
73
+ onNotificationUpdated(): void;
74
+
73
75
  onCreditAlert(creditAlert: CreditAlert): void;
74
76
 
75
77
  //#region propagating reconnection to iframe
@@ -191,11 +193,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
191
193
  getPrebuild(prebuildId: string): Promise<PrebuildWithStatus | undefined>;
192
194
  triggerPrebuild(projectId: string, branchName: string | null): Promise<StartPrebuildResult>;
193
195
  cancelPrebuild(projectId: string, prebuildId: string): Promise<void>;
194
- fetchProjectRepositoryConfiguration(projectId: string): Promise<string | undefined>;
195
- guessProjectConfiguration(projectId: string): Promise<string | undefined>;
196
- fetchRepositoryConfiguration(cloneUrl: string): Promise<string | undefined>;
197
- guessRepositoryConfiguration(cloneUrl: string): Promise<string | undefined>;
198
- setProjectConfiguration(projectId: string, configString: string): Promise<void>;
199
196
  updateProjectPartial(partialProject: PartialProject): Promise<void>;
200
197
  setProjectEnvironmentVariable(projectId: string, name: string, value: string, censored: boolean): Promise<void>;
201
198
  getProjectEnvironmentVariables(projectId: string): Promise<ProjectEnvVar[]>;
@@ -211,7 +208,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
211
208
  deleteGitpodToken(tokenHash: string): Promise<void>;
212
209
 
213
210
  // misc
214
- sendFeedback(feedback: string): Promise<string | undefined>;
215
211
  isGitHubAppEnabled(): Promise<boolean>;
216
212
  registerGithubApp(installationId: string): Promise<void>;
217
213
 
@@ -290,14 +286,20 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
290
286
 
291
287
  getStripePublishableKey(): Promise<string>;
292
288
  getStripeSetupIntentClientSecret(): Promise<string>;
289
+ findStripeSubscriptionId(attributionId: string): Promise<string | undefined>;
293
290
  findStripeSubscriptionIdForTeam(teamId: string): Promise<string | undefined>;
294
291
  createOrUpdateStripeCustomerForTeam(teamId: string, currency: string): Promise<void>;
292
+ createOrUpdateStripeCustomerForUser(currency: string): Promise<void>;
293
+ subscribeToStripe(attributionId: string, setupIntentId: string): Promise<void>;
295
294
  subscribeTeamToStripe(teamId: string, setupIntentId: string): Promise<void>;
295
+ getStripePortalUrl(attributionId: string): Promise<string>;
296
296
  getStripePortalUrlForTeam(teamId: string): Promise<string>;
297
- getSpendingLimitForTeam(teamId: string): Promise<number | undefined>;
298
- setSpendingLimitForTeam(teamId: string, spendingLimit: number): Promise<void>;
297
+ getUsageLimit(attributionId: string): Promise<number | undefined>;
298
+ setUsageLimit(attributionId: string, usageLimit: number): Promise<void>;
299
+ getUsageLimitForTeam(teamId: string): Promise<number | undefined>;
300
+ setUsageLimitForTeam(teamId: string, spendingLimit: number): Promise<void>;
299
301
 
300
- listBilledUsage(req: ListBilledUsageRequest): Promise<ListBilledUsageResponse>;
302
+ listUsage(req: ListUsageRequest): Promise<ListUsageResponse>;
301
303
 
302
304
  setUsageAttribution(usageAttribution: string): Promise<void>;
303
305
 
@@ -331,9 +333,7 @@ export interface RateLimiterError {
331
333
 
332
334
  export interface CreateProjectParams {
333
335
  name: string;
334
- slug?: string;
335
- account: string;
336
- provider: string;
336
+ slug: string;
337
337
  cloneUrl: string;
338
338
  teamId?: string;
339
339
  userId?: string;
@@ -572,6 +572,18 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
572
572
  }
573
573
  }
574
574
  }
575
+
576
+ onNotificationUpdated(): void {
577
+ for (const client of this.clients) {
578
+ if (client.onNotificationUpdated) {
579
+ try {
580
+ client.onNotificationUpdated();
581
+ } catch (error) {
582
+ console.error(error);
583
+ }
584
+ }
585
+ }
586
+ }
575
587
  }
576
588
 
577
589
  export type GitpodService = GitpodServiceImpl<GitpodClient, GitpodServer>;
package/src/protocol.ts CHANGED
@@ -8,6 +8,7 @@ import { WorkspaceInstance, PortVisibility } from "./workspace-instance";
8
8
  import { RoleOrPermission } from "./permission";
9
9
  import { Project } from "./teams-projects-protocol";
10
10
  import { createHash } from "crypto";
11
+ import { AttributionId } from "./attribution";
11
12
 
12
13
  export interface UserInfo {
13
14
  name?: string;
@@ -294,6 +295,7 @@ export const WorkspaceFeatureFlags = {
294
295
  persistent_volume_claim: undefined,
295
296
  protected_secrets: undefined,
296
297
  workspace_class_limiting: undefined,
298
+ workspace_connection_limiting: undefined,
297
299
  };
298
300
  export type NamedWorkspaceFeatureFlag = keyof typeof WorkspaceFeatureFlags;
299
301
 
@@ -822,13 +824,12 @@ export interface WorkspaceConfig {
822
824
  * Where the config object originates from.
823
825
  *
824
826
  * repo - from the repository
825
- * project-db - from the "Project" stored in the database
826
827
  * definitly-gp - from github.com/gitpod-io/definitely-gp
827
828
  * derived - computed based on analyzing the repository
828
829
  * additional-content - config comes from additional content, usually provided through the project's configuration
829
830
  * default - our static catch-all default config
830
831
  */
831
- _origin?: "repo" | "project-db" | "definitely-gp" | "derived" | "additional-content" | "default";
832
+ _origin?: "repo" | "definitely-gp" | "derived" | "additional-content" | "default";
832
833
 
833
834
  /**
834
835
  * Set of automatically infered feature flags. That's not something the user can set, but
@@ -1503,10 +1504,12 @@ export interface Terms {
1503
1504
  readonly formElements?: object;
1504
1505
  }
1505
1506
 
1507
+ export type BillingStrategy = "other" | "stripe";
1506
1508
  export interface CostCenter {
1507
- readonly id: string;
1509
+ readonly id: AttributionId;
1508
1510
  /**
1509
1511
  * Unit: credits
1510
1512
  */
1511
1513
  spendingLimit: number;
1514
+ billingStrategy: BillingStrategy;
1512
1515
  }
@@ -27,7 +27,6 @@ export interface Project {
27
27
  teamId?: string;
28
28
  userId?: string;
29
29
  appInstallationId: string;
30
- config?: ProjectConfig;
31
30
  settings?: ProjectSettings;
32
31
  creationTime: string;
33
32
  /** This is a flag that triggers the HARD DELETION of this entity */
package/src/usage.ts CHANGED
@@ -4,60 +4,69 @@
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
+ creditBalanceAtStart: number;
32
+ creditBalanceAtEnd: number;
33
+ }
34
+
35
+ export interface PaginationResponse {
59
36
  perPage: number;
37
+ totalPages: number;
38
+ total: number;
60
39
  page: number;
61
40
  }
62
41
 
63
- export type BillableWorkspaceType = WorkspaceType;
42
+ export type UsageKind = "workspaceinstance" | "invoice";
43
+ export interface Usage {
44
+ id: string;
45
+ attributionId: string;
46
+ description: string;
47
+ credits: number;
48
+ effectiveTime?: number;
49
+ kind: UsageKind;
50
+ workspaceInstanceId: string;
51
+ draft: boolean;
52
+ metadata: WorkspaceInstanceUsageData | InvoiceUsageData;
53
+ }
54
+
55
+ // the equivalent golang shape is maintained in `/workspace/gitpod/`components/usage/pkg/db/usage.go`
56
+ export interface WorkspaceInstanceUsageData {
57
+ workspaceId: string;
58
+ workspaceType: WorkspaceType;
59
+ workspaceClass: string;
60
+ contextURL: string;
61
+ startTime: string;
62
+ endTime?: string;
63
+ userId: string;
64
+ userName: string;
65
+ userAvatarURL: string;
66
+ }
67
+
68
+ export interface InvoiceUsageData {
69
+ invoiceId: string;
70
+ startDate: string;
71
+ endDate: string;
72
+ }
@@ -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
  }