@gitpod/gitpod-protocol 0.1.5-pavel-fixlog.0 → 0.1.5-pavel-vswithtype.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.
Files changed (118) hide show
  1. package/data/gitpod-schema.json +71 -129
  2. package/lib/admin-protocol.d.ts +3 -0
  3. package/lib/admin-protocol.d.ts.map +1 -1
  4. package/lib/admin-protocol.js.map +1 -1
  5. package/lib/attribution.d.ts +4 -0
  6. package/lib/attribution.d.ts.map +1 -1
  7. package/lib/attribution.js +14 -0
  8. package/lib/attribution.js.map +1 -1
  9. package/lib/billing-mode.d.ts +11 -4
  10. package/lib/billing-mode.d.ts.map +1 -1
  11. package/lib/billing-mode.js +15 -16
  12. package/lib/billing-mode.js.map +1 -1
  13. package/lib/encryption/encryption-engine.d.ts.map +1 -1
  14. package/lib/encryption/encryption-engine.js +3 -3
  15. package/lib/encryption/encryption-engine.js.map +1 -1
  16. package/lib/encryption/encryption-engine.spec.js +1 -1
  17. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  18. package/lib/encryption/key-provider.js +1 -1
  19. package/lib/encryption/key-provider.js.map +1 -1
  20. package/lib/experiments/configcat.d.ts +1 -2
  21. package/lib/experiments/configcat.d.ts.map +1 -1
  22. package/lib/experiments/configcat.js +4 -6
  23. package/lib/experiments/configcat.js.map +1 -1
  24. package/lib/experiments/types.d.ts +2 -3
  25. package/lib/experiments/types.d.ts.map +1 -1
  26. package/lib/experiments/types.js.map +1 -1
  27. package/lib/gitpod-service.d.ts +14 -26
  28. package/lib/gitpod-service.d.ts.map +1 -1
  29. package/lib/gitpod-service.js +12 -0
  30. package/lib/gitpod-service.js.map +1 -1
  31. package/lib/ide-protocol.d.ts +8 -0
  32. package/lib/ide-protocol.d.ts.map +1 -1
  33. package/lib/index.d.ts +0 -1
  34. package/lib/index.d.ts.map +1 -1
  35. package/lib/index.js +0 -1
  36. package/lib/index.js.map +1 -1
  37. package/lib/messaging/error.d.ts +2 -0
  38. package/lib/messaging/error.d.ts.map +1 -1
  39. package/lib/messaging/error.js +4 -0
  40. package/lib/messaging/error.js.map +1 -1
  41. package/lib/plans.d.ts +1 -0
  42. package/lib/plans.d.ts.map +1 -1
  43. package/lib/plans.js +6 -2
  44. package/lib/plans.js.map +1 -1
  45. package/lib/protocol.d.ts +51 -20
  46. package/lib/protocol.d.ts.map +1 -1
  47. package/lib/protocol.js +36 -8
  48. package/lib/protocol.js.map +1 -1
  49. package/lib/teams-projects-protocol.d.ts +0 -1
  50. package/lib/teams-projects-protocol.d.ts.map +1 -1
  51. package/lib/teams-projects-protocol.js.map +1 -1
  52. package/lib/usage.d.ts +47 -17
  53. package/lib/usage.d.ts.map +1 -1
  54. package/lib/usage.js +6 -6
  55. package/lib/usage.js.map +1 -1
  56. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  57. package/lib/util/garbage-collected-cache.js +5 -0
  58. package/lib/util/garbage-collected-cache.js.map +1 -1
  59. package/lib/util/logging.spec.d.ts +7 -0
  60. package/lib/util/logging.spec.d.ts.map +1 -0
  61. package/lib/util/logging.spec.js +52 -0
  62. package/lib/util/logging.spec.js.map +1 -0
  63. package/lib/util/nice-grpc.d.ts +9 -0
  64. package/lib/util/nice-grpc.d.ts.map +1 -0
  65. package/lib/util/nice-grpc.js +119 -0
  66. package/lib/util/nice-grpc.js.map +1 -0
  67. package/lib/util/timeutil.d.ts +1 -0
  68. package/lib/util/timeutil.d.ts.map +1 -1
  69. package/lib/util/timeutil.js +7 -1
  70. package/lib/util/timeutil.js.map +1 -1
  71. package/lib/util/timeutil.spec.d.ts +2 -0
  72. package/lib/util/timeutil.spec.d.ts.map +1 -1
  73. package/lib/util/timeutil.spec.js +34 -0
  74. package/lib/util/timeutil.spec.js.map +1 -1
  75. package/lib/workspace-class.d.ts +1 -1
  76. package/lib/workspace-class.d.ts.map +1 -1
  77. package/lib/workspace-cluster.d.ts +6 -5
  78. package/lib/workspace-cluster.d.ts.map +1 -1
  79. package/lib/workspace-cluster.js.map +1 -1
  80. package/lib/workspace-instance.d.ts +1 -0
  81. package/lib/workspace-instance.d.ts.map +1 -1
  82. package/lib/wsready.d.ts +3 -3
  83. package/lib/wsready.d.ts.map +1 -1
  84. package/lib/wsready.js +2 -0
  85. package/lib/wsready.js.map +1 -1
  86. package/package.json +4 -2
  87. package/pkg-yarn.lock +4 -2
  88. package/provenance-bundle.jsonl +1 -1
  89. package/src/admin-protocol.ts +3 -0
  90. package/src/attribution.ts +15 -0
  91. package/src/billing-mode.ts +30 -15
  92. package/src/encryption/encryption-engine.spec.ts +1 -1
  93. package/src/encryption/encryption-engine.ts +7 -3
  94. package/src/encryption/key-provider.ts +1 -1
  95. package/src/experiments/configcat.ts +3 -5
  96. package/src/experiments/types.ts +4 -5
  97. package/src/gitpod-service.ts +26 -28
  98. package/src/ide-protocol.ts +10 -0
  99. package/src/index.ts +0 -1
  100. package/src/messaging/error.ts +6 -0
  101. package/src/plans.ts +6 -2
  102. package/src/protocol.ts +77 -25
  103. package/src/teams-projects-protocol.ts +0 -1
  104. package/src/usage.ts +51 -30
  105. package/src/util/garbage-collected-cache.ts +5 -0
  106. package/src/util/logging.spec.ts +23 -0
  107. package/src/util/nice-grpc.ts +93 -0
  108. package/src/util/timeutil.spec.ts +28 -1
  109. package/src/util/timeutil.ts +6 -0
  110. package/src/workspace-class.ts +1 -1
  111. package/src/workspace-cluster.ts +11 -6
  112. package/src/workspace-instance.ts +3 -0
  113. package/src/wsready.ts +4 -5
  114. package/lib/email-protocol.d.ts +0 -49
  115. package/lib/email-protocol.d.ts.map +0 -1
  116. package/lib/email-protocol.js +0 -28
  117. package/lib/email-protocol.js.map +0 -1
  118. package/src/email-protocol.ts +0 -65
@@ -60,8 +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 { Currency } from "./plans";
64
- import { BillableSession, BillableSessionRequest } from "./usage";
63
+ import { ListUsageRequest, ListUsageResponse } from "./usage";
65
64
  import { SupportedWorkspaceClass } from "./workspace-class";
66
65
  import { BillingMode } from "./billing-mode";
67
66
 
@@ -71,6 +70,8 @@ export interface GitpodClient {
71
70
 
72
71
  onPrebuildUpdate(update: PrebuildWithStatus): void;
73
72
 
73
+ onNotificationUpdated(): void;
74
+
74
75
  onCreditAlert(creditAlert: CreditAlert): void;
75
76
 
76
77
  //#region propagating reconnection to iframe
@@ -85,6 +86,8 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
85
86
  getLoggedInUser(): Promise<User>;
86
87
  getTerms(): Promise<Terms>;
87
88
  updateLoggedInUser(user: Partial<User>): Promise<User>;
89
+ sendPhoneNumberVerificationToken(phoneNumber: string): Promise<void>;
90
+ verifyPhoneNumberVerificationToken(phoneNumber: string, token: string): Promise<boolean>;
88
91
  getAuthProviders(): Promise<AuthProviderInfo[]>;
89
92
  getOwnAuthProviders(): Promise<AuthProviderEntry[]>;
90
93
  updateOwnAuthProvider(params: GitpodServer.UpdateOwnAuthProviderParams): Promise<AuthProviderEntry>;
@@ -190,11 +193,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
190
193
  getPrebuild(prebuildId: string): Promise<PrebuildWithStatus | undefined>;
191
194
  triggerPrebuild(projectId: string, branchName: string | null): Promise<StartPrebuildResult>;
192
195
  cancelPrebuild(projectId: string, prebuildId: string): Promise<void>;
193
- fetchProjectRepositoryConfiguration(projectId: string): Promise<string | undefined>;
194
- guessProjectConfiguration(projectId: string): Promise<string | undefined>;
195
- fetchRepositoryConfiguration(cloneUrl: string): Promise<string | undefined>;
196
- guessRepositoryConfiguration(cloneUrl: string): Promise<string | undefined>;
197
- setProjectConfiguration(projectId: string, configString: string): Promise<void>;
198
196
  updateProjectPartial(partialProject: PartialProject): Promise<void>;
199
197
  setProjectEnvironmentVariable(projectId: string, name: string, value: string, censored: boolean): Promise<void>;
200
198
  getProjectEnvironmentVariables(projectId: string): Promise<ProjectEnvVar[]>;
@@ -210,7 +208,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
210
208
  deleteGitpodToken(tokenHash: string): Promise<void>;
211
209
 
212
210
  // misc
213
- sendFeedback(feedback: string): Promise<string | undefined>;
214
211
  isGitHubAppEnabled(): Promise<boolean>;
215
212
  registerGithubApp(installationId: string): Promise<void>;
216
213
 
@@ -230,16 +227,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
230
227
  */
231
228
  getSnapshots(workspaceID: string): Promise<string[]>;
232
229
 
233
- /**
234
- * stores/updates layout information for the given workspace
235
- */
236
- storeLayout(workspaceId: string, layoutData: string): Promise<void>;
237
-
238
- /**
239
- * retrieves layout information for the given workspace
240
- */
241
- getLayout(workspaceId: string): Promise<string | undefined>;
242
-
243
230
  guessGitTokenScopes(params: GuessGitTokenScopesParams): Promise<GuessedGitTokenScopes>;
244
231
 
245
232
  /**
@@ -289,15 +276,17 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
289
276
 
290
277
  getStripePublishableKey(): Promise<string>;
291
278
  getStripeSetupIntentClientSecret(): Promise<string>;
292
- findStripeSubscriptionIdForTeam(teamId: string): Promise<string | undefined>;
293
- subscribeTeamToStripe(teamId: string, setupIntentId: string, currency: Currency): Promise<void>;
294
- getStripePortalUrlForTeam(teamId: string): Promise<string>;
295
- getSpendingLimitForTeam(teamId: string): Promise<number | undefined>;
296
- setSpendingLimitForTeam(teamId: string, spendingLimit: number): Promise<void>;
279
+ findStripeSubscriptionId(attributionId: string): Promise<string | undefined>;
280
+ createStripeCustomerIfNeeded(attributionId: string, currency: string): Promise<void>;
281
+ subscribeToStripe(attributionId: string, setupIntentId: string, usageLimit: number): Promise<number | undefined>;
282
+ getStripePortalUrl(attributionId: string): Promise<string>;
283
+ getUsageLimit(attributionId: string): Promise<number | undefined>;
284
+ setUsageLimit(attributionId: string, usageLimit: number): Promise<void>;
297
285
 
298
- listBilledUsage(req: BillableSessionRequest): Promise<BillableSession[]>;
286
+ listUsage(req: ListUsageRequest): Promise<ListUsageResponse>;
299
287
 
300
288
  setUsageAttribution(usageAttribution: string): Promise<void>;
289
+ listAvailableUsageAttributionIds(): Promise<string[]>;
301
290
 
302
291
  getBillingModeForUser(): Promise<BillingMode>;
303
292
  getBillingModeForTeam(teamId: string): Promise<BillingMode>;
@@ -329,9 +318,7 @@ export interface RateLimiterError {
329
318
 
330
319
  export interface CreateProjectParams {
331
320
  name: string;
332
- slug?: string;
333
- account: string;
334
- provider: string;
321
+ slug: string;
335
322
  cloneUrl: string;
336
323
  teamId?: string;
337
324
  userId?: string;
@@ -442,7 +429,6 @@ export namespace GitpodServer {
442
429
  }
443
430
  export interface TakeSnapshotOptions {
444
431
  workspaceId: string;
445
- layoutData?: string;
446
432
  /* this is here to enable backwards-compatibility and untangling rollout between workspace, IDE and meta */
447
433
  dontWait?: boolean;
448
434
  }
@@ -570,6 +556,18 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
570
556
  }
571
557
  }
572
558
  }
559
+
560
+ onNotificationUpdated(): void {
561
+ for (const client of this.clients) {
562
+ if (client.onNotificationUpdated) {
563
+ try {
564
+ client.onNotificationUpdated();
565
+ } catch (error) {
566
+ console.error(error);
567
+ }
568
+ }
569
+ }
570
+ }
573
571
  }
574
572
 
575
573
  export type GitpodService = GitpodServiceImpl<GitpodClient, GitpodServer>;
@@ -116,4 +116,14 @@ export interface IDEOption {
116
116
  * we resolve the tag regularly to the most recent image version.
117
117
  */
118
118
  resolveImageDigest?: boolean;
119
+
120
+ /**
121
+ * The plugin image ref for the IDE image, this image ref always resolve to digest.
122
+ */
123
+ pluginImage?: string;
124
+
125
+ /**
126
+ * The latest plugin image ref for the latest IDE image, this image ref always resolve to digest.
127
+ */
128
+ pluginLatestImage?: string;
119
129
  }
package/src/index.ts CHANGED
@@ -13,7 +13,6 @@ export * from "./license-protocol";
13
13
  export * from "./workspace-instance";
14
14
  export * from "./permission";
15
15
  export * from "./admin-protocol";
16
- export * from "./email-protocol";
17
16
  export * from "./headless-workspace-log";
18
17
  export * from "./context-url";
19
18
  export * from "./teams-projects-protocol";
@@ -26,6 +26,9 @@ export namespace ErrorCodes {
26
26
  // 410 No User
27
27
  export const SETUP_REQUIRED = 410;
28
28
 
29
+ // 411 No User
30
+ export const NEEDS_VERIFICATION = 411;
31
+
29
32
  // 429 Too Many Requests
30
33
  export const TOO_MANY_REQUESTS = 429;
31
34
 
@@ -91,4 +94,7 @@ export namespace ErrorCodes {
91
94
 
92
95
  // 640 Headless logs are not available (yet)
93
96
  export const HEADLESS_LOG_NOT_YET_AVAILABLE = 640;
97
+
98
+ // 650 Invalid Value
99
+ export const INVALID_VALUE = 650;
94
100
  }
package/src/plans.ts CHANGED
@@ -131,7 +131,7 @@ export namespace Plans {
131
131
  githubPlanNumber: 1,
132
132
 
133
133
  type: "free",
134
- name: "Open Source",
134
+ name: "Free",
135
135
  currency: "USD",
136
136
  pricePerMonth: 0,
137
137
  hoursPerMonth: 100,
@@ -146,7 +146,7 @@ export namespace Plans {
146
146
  githubPlanNumber: 5,
147
147
 
148
148
  type: "free-50",
149
- name: "Open Source",
149
+ name: "Free",
150
150
  currency: "USD",
151
151
  pricePerMonth: 0,
152
152
  hoursPerMonth: 50,
@@ -482,6 +482,10 @@ export namespace Plans {
482
482
  );
483
483
  }
484
484
 
485
+ export function isFreeTier(chargebeeId: string | undefined): boolean {
486
+ return chargebeeId === Plans.FREE.chargebeeId || chargebeeId === Plans.FREE_50.chargebeeId;
487
+ }
488
+
485
489
  export function isFreeNonTransientPlan(chargebeeId: string | undefined): boolean {
486
490
  return chargebeeId === Plans.FREE_OPEN_SOURCE.chargebeeId;
487
491
  }
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;
@@ -48,6 +49,12 @@ export interface User {
48
49
 
49
50
  // Identifies an explicit team or user ID to which all the user's workspace usage should be attributed to (e.g. for billing purposes)
50
51
  usageAttributionId?: string;
52
+
53
+ // The last time this user got verified somehow. The user is not verified if this is empty.
54
+ lastVerificationTime?: string;
55
+
56
+ // The phone number used for the last phone verification.
57
+ verificationPhoneNumber?: string;
51
58
  }
52
59
 
53
60
  export namespace User {
@@ -207,7 +214,21 @@ export interface AdditionalUserData {
207
214
  // additional user profile data
208
215
  profile?: ProfileDetails;
209
216
  }
210
-
217
+ export namespace AdditionalUserData {
218
+ export function set(user: User, partialData: Partial<AdditionalUserData>): User {
219
+ if (!user.additionalData) {
220
+ user.additionalData = {
221
+ ...partialData,
222
+ };
223
+ } else {
224
+ user.additionalData = {
225
+ ...user.additionalData,
226
+ ...partialData,
227
+ };
228
+ }
229
+ return user;
230
+ }
231
+ }
211
232
  // The format in which we store User Profiles in
212
233
  export interface ProfileDetails {
213
234
  // when was the last time the user updated their profile information or has been nudged to do so.
@@ -265,6 +286,8 @@ export interface UserFeatureSettings {
265
286
  permanentWSFeatureFlags?: NamedWorkspaceFeatureFlag[];
266
287
  }
267
288
 
289
+ export type BillingTier = "paid" | "free";
290
+
268
291
  /**
269
292
  * The values of this type MUST MATCH enum values in WorkspaceFeatureFlag from ws-manager/client/core_pb.d.ts
270
293
  * If they don't we'll break things during workspace startup.
@@ -274,8 +297,19 @@ export const WorkspaceFeatureFlags = {
274
297
  persistent_volume_claim: undefined,
275
298
  protected_secrets: undefined,
276
299
  workspace_class_limiting: undefined,
300
+ workspace_connection_limiting: undefined,
301
+ workspace_psi: undefined,
277
302
  };
278
303
  export type NamedWorkspaceFeatureFlag = keyof typeof WorkspaceFeatureFlags;
304
+ export namespace NamedWorkspaceFeatureFlag {
305
+ export const WORKSPACE_PERSISTED_FEATTURE_FLAGS: NamedWorkspaceFeatureFlag[] = [
306
+ "full_workspace_backup",
307
+ "persistent_volume_claim",
308
+ ];
309
+ export function isWorkspacePersisted(ff: NamedWorkspaceFeatureFlag): boolean {
310
+ return WORKSPACE_PERSISTED_FEATTURE_FLAGS.includes(ff);
311
+ }
312
+ }
279
313
 
280
314
  export interface EnvVarWithValue {
281
315
  name: string;
@@ -606,6 +640,7 @@ export interface PendingGithubEvent {
606
640
  creationDate: Date;
607
641
  type: string;
608
642
  event: string;
643
+ deleted: boolean;
609
644
  }
610
645
 
611
646
  export interface Snapshot {
@@ -614,7 +649,6 @@ export interface Snapshot {
614
649
  availableTime?: string;
615
650
  originalWorkspaceId: string;
616
651
  bucketId: string;
617
- layoutData?: string;
618
652
  state: SnapshotState;
619
653
  message?: string;
620
654
  }
@@ -626,14 +660,13 @@ export interface VolumeSnapshot {
626
660
  volumeHandle: string;
627
661
  }
628
662
 
629
- export type SnapshotState = "pending" | "available" | "error";
630
-
631
- export interface LayoutData {
632
- workspaceId: string;
633
- lastUpdatedTime: string;
634
- layoutData: string;
663
+ export interface VolumeSnapshotWithWSType {
664
+ vs: VolumeSnapshot;
665
+ wsType: WorkspaceType;
635
666
  }
636
667
 
668
+ export type SnapshotState = "pending" | "available" | "error";
669
+
637
670
  export interface Workspace {
638
671
  id: string;
639
672
  creationTime: string;
@@ -695,7 +728,7 @@ export interface Workspace {
695
728
 
696
729
  export type WorkspaceSoftDeletion = "user" | "gc";
697
730
 
698
- export type WorkspaceType = "regular" | "prebuild" | "probe"; // TODO(gpl) Removed prove here
731
+ export type WorkspaceType = "regular" | "prebuild";
699
732
 
700
733
  export namespace Workspace {
701
734
  export function getFullRepositoryName(ws: Workspace): string | undefined {
@@ -768,6 +801,8 @@ export interface JetBrainsConfig {
768
801
  goland?: JetBrainsProductConfig;
769
802
  pycharm?: JetBrainsProductConfig;
770
803
  phpstorm?: JetBrainsProductConfig;
804
+ rubymine?: JetBrainsProductConfig;
805
+ webstorm?: JetBrainsProductConfig;
771
806
  }
772
807
  export interface JetBrainsProductConfig {
773
808
  prebuilds?: JetBrainsPrebuilds;
@@ -782,6 +817,12 @@ export interface RepositoryCloneInformation {
782
817
  checkoutLocation?: string;
783
818
  }
784
819
 
820
+ export interface CoreDumpConfig {
821
+ enabled?: boolean;
822
+ softLimit?: number;
823
+ hardLimit?: number;
824
+ }
825
+
785
826
  export interface WorkspaceConfig {
786
827
  mainConfiguration?: string;
787
828
  additionalRepositories?: RepositoryCloneInformation[];
@@ -794,6 +835,7 @@ export interface WorkspaceConfig {
794
835
  github?: GithubAppConfig;
795
836
  vscode?: VSCodeConfig;
796
837
  jetbrains?: JetBrainsConfig;
838
+ coreDump?: CoreDumpConfig;
797
839
 
798
840
  /** deprecated. Enabled by default **/
799
841
  experimentalNetwork?: boolean;
@@ -802,13 +844,12 @@ export interface WorkspaceConfig {
802
844
  * Where the config object originates from.
803
845
  *
804
846
  * repo - from the repository
805
- * project-db - from the "Project" stored in the database
806
847
  * definitly-gp - from github.com/gitpod-io/definitely-gp
807
848
  * derived - computed based on analyzing the repository
808
849
  * additional-content - config comes from additional content, usually provided through the project's configuration
809
850
  * default - our static catch-all default config
810
851
  */
811
- _origin?: "repo" | "project-db" | "definitely-gp" | "derived" | "additional-content" | "default";
852
+ _origin?: "repo" | "definitely-gp" | "derived" | "additional-content" | "default";
812
853
 
813
854
  /**
814
855
  * Set of automatically infered feature flags. That's not something the user can set, but
@@ -1076,13 +1117,16 @@ export namespace SnapshotContext {
1076
1117
  }
1077
1118
  }
1078
1119
 
1079
- export interface StartPrebuildContext extends WorkspaceContext {
1080
- actual: WorkspaceContext;
1120
+ export interface WithCommitHistory {
1081
1121
  commitHistory?: string[];
1082
1122
  additionalRepositoryCommitHistories?: {
1083
1123
  cloneUrl: string;
1084
1124
  commitHistory: string[];
1085
1125
  }[];
1126
+ }
1127
+
1128
+ export interface StartPrebuildContext extends WorkspaceContext, WithCommitHistory {
1129
+ actual: WorkspaceContext;
1086
1130
  project?: Project;
1087
1131
  branch?: string;
1088
1132
  }
@@ -1126,17 +1170,6 @@ export namespace WithEnvvarsContext {
1126
1170
  }
1127
1171
  }
1128
1172
 
1129
- export interface WorkspaceProbeContext extends WorkspaceContext {
1130
- responseURL: string;
1131
- responseToken: string;
1132
- }
1133
-
1134
- export namespace WorkspaceProbeContext {
1135
- export function is(context: any): context is WorkspaceProbeContext {
1136
- return context && "responseURL" in context && "responseToken" in context;
1137
- }
1138
- }
1139
-
1140
1173
  export type RefType = "branch" | "tag" | "revision";
1141
1174
  export namespace RefType {
1142
1175
  export const getRefType = (commit: Commit): RefType => {
@@ -1176,6 +1209,16 @@ export namespace AdditionalContentContext {
1176
1209
  }
1177
1210
  }
1178
1211
 
1212
+ export interface OpenPrebuildContext extends WorkspaceContext {
1213
+ openPrebuildID: string;
1214
+ }
1215
+
1216
+ export namespace OpenPrebuildContext {
1217
+ export function is(ctx: any): ctx is OpenPrebuildContext {
1218
+ return "openPrebuildID" in ctx;
1219
+ }
1220
+ }
1221
+
1179
1222
  export interface CommitContext extends WorkspaceContext, GitCheckoutInfo {
1180
1223
  /** @deprecated Moved to .repository.cloneUrl, left here for backwards-compatibility for old workspace contextes in the DB */
1181
1224
  cloneUrl?: string;
@@ -1348,6 +1391,8 @@ export enum CreateWorkspaceMode {
1348
1391
  UsePrebuild = "use-prebuild",
1349
1392
  // SelectIfRunning returns a list of currently running workspaces for the context URL if there are any, otherwise falls back to Default mode
1350
1393
  SelectIfRunning = "select-if-running",
1394
+ // UseLastSuccessfulPrebuild returns ...
1395
+ UseLastSuccessfulPrebuild = "use-last-successful-prebuild",
1351
1396
  }
1352
1397
 
1353
1398
  export namespace WorkspaceCreationResult {
@@ -1483,10 +1528,17 @@ export interface Terms {
1483
1528
  readonly formElements?: object;
1484
1529
  }
1485
1530
 
1531
+ export interface StripeConfig {
1532
+ individualUsagePriceIds: { [currency: string]: string };
1533
+ teamUsagePriceIds: { [currency: string]: string };
1534
+ }
1535
+
1536
+ export type BillingStrategy = "other" | "stripe";
1486
1537
  export interface CostCenter {
1487
- readonly id: string;
1538
+ readonly id: AttributionId;
1488
1539
  /**
1489
1540
  * Unit: credits
1490
1541
  */
1491
1542
  spendingLimit: number;
1543
+ billingStrategy: BillingStrategy;
1492
1544
  }
@@ -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
@@ -6,45 +6,66 @@
6
6
 
7
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;
18
+ export enum Ordering {
19
+ ORDERING_DESCENDING = 0,
20
+ ORDERING_ASCENDING = 1,
21
+ }
27
22
 
28
- // When the workspace ended. Not set when the workspace is still running.
29
- endTime?: string;
23
+ export interface PaginationRequest {
24
+ perPage: number;
25
+ page: number;
26
+ }
30
27
 
31
- // The credits used for this session
32
- credits: number;
28
+ export interface ListUsageResponse {
29
+ usageEntriesList: Usage[];
30
+ pagination?: PaginationResponse;
31
+ creditsUsed: number;
32
+ }
33
33
 
34
- // TODO - maybe
35
- projectId?: string;
34
+ export interface PaginationResponse {
35
+ perPage: number;
36
+ totalPages: number;
37
+ total: number;
38
+ page: number;
36
39
  }
37
40
 
38
- export interface BillableSessionRequest {
41
+ export type UsageKind = "workspaceinstance" | "invoice";
42
+ export interface Usage {
43
+ id: string;
39
44
  attributionId: string;
40
- startedTimeOrder: SortOrder;
41
- from?: number;
42
- to?: number;
45
+ description: string;
46
+ credits: number;
47
+ effectiveTime?: number;
48
+ kind: UsageKind;
49
+ workspaceInstanceId: string;
50
+ draft: boolean;
51
+ metadata: WorkspaceInstanceUsageData | InvoiceUsageData;
43
52
  }
44
53
 
45
- 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
+ }
46
66
 
47
- export enum SortOrder {
48
- Descending = 0,
49
- Ascending = 1,
67
+ export interface InvoiceUsageData {
68
+ invoiceId: string;
69
+ startDate: string;
70
+ endDate: string;
50
71
  }
@@ -37,6 +37,11 @@ export class GarbageCollectedCache<T> {
37
37
  if (!entry) {
38
38
  return undefined;
39
39
  }
40
+ // Still valid?
41
+ if (entry.expiryDate < Date.now()) {
42
+ this.store.delete(entry.key);
43
+ return undefined;
44
+ }
40
45
  return entry.value;
41
46
  }
42
47
 
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the GNU Affero General Public License (AGPL).
4
+ * See License-AGPL.txt in the project root for license information.
5
+ */
6
+
7
+ import { suite, test } from "mocha-typescript";
8
+ import { log } from "./logging";
9
+
10
+ @suite
11
+ class TestLogging {
12
+ @test public async testLogInfo_output() {
13
+ const testObj = {
14
+ null: null,
15
+ undefined: undefined,
16
+ empty: "",
17
+ foo: "bar",
18
+ number: 0,
19
+ };
20
+ log.info("info logging test", testObj);
21
+ }
22
+ }
23
+ module.exports = new TestLogging();
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the GNU Affero General Public License (AGPL).
4
+ * See License-AGPL.txt in the project root for license information.
5
+ */
6
+
7
+ import { isAbortError } from "abort-controller-x";
8
+ import {
9
+ CallOptions,
10
+ ClientError,
11
+ ClientMiddleware,
12
+ ClientMiddlewareCall,
13
+ Status,
14
+ MethodDescriptor,
15
+ } from "nice-grpc-common";
16
+ import { GrpcMethodType, IClientCallMetrics } from "./grpc";
17
+
18
+ function getLabels(method: MethodDescriptor) {
19
+ const callType = method.requestStream
20
+ ? method.responseStream
21
+ ? "bidi_stream"
22
+ : "client_stream"
23
+ : method.responseStream
24
+ ? "server_stream"
25
+ : "unary";
26
+ const { path } = method;
27
+ const [serviceName, methodName] = path.split("/").slice(1);
28
+
29
+ return {
30
+ type: callType as GrpcMethodType,
31
+ service: serviceName,
32
+ method: methodName,
33
+ };
34
+ }
35
+
36
+ async function* incrementStreamMessagesCounter<T>(iterable: AsyncIterable<T>, callback: () => void): AsyncIterable<T> {
37
+ for await (const item of iterable) {
38
+ callback();
39
+ yield item;
40
+ }
41
+ }
42
+
43
+ export function prometheusClientMiddleware(metrics: IClientCallMetrics): ClientMiddleware {
44
+ return async function* prometheusClientMiddlewareGenerator<Request, Response>(
45
+ call: ClientMiddlewareCall<Request, Response>,
46
+ options: CallOptions,
47
+ ): AsyncGenerator<Response, Response | void, undefined> {
48
+ const labels = getLabels(call.method);
49
+
50
+ metrics.started(labels);
51
+
52
+ let settled = false;
53
+ let status: Status = Status.OK;
54
+
55
+ try {
56
+ let request;
57
+
58
+ if (!call.requestStream) {
59
+ request = call.request;
60
+ } else {
61
+ request = incrementStreamMessagesCounter(call.request, metrics.sent.bind(metrics, labels));
62
+ }
63
+
64
+ if (!call.responseStream) {
65
+ const response = yield* call.next(request, options);
66
+ settled = true;
67
+ return response;
68
+ } else {
69
+ yield* incrementStreamMessagesCounter(
70
+ call.next(request, options),
71
+ metrics.received.bind(metrics, labels),
72
+ );
73
+ settled = true;
74
+ return;
75
+ }
76
+ } catch (err) {
77
+ settled = true;
78
+ if (err instanceof ClientError) {
79
+ status = err.code;
80
+ } else if (isAbortError(err)) {
81
+ status = Status.CANCELLED;
82
+ } else {
83
+ status = Status.UNKNOWN;
84
+ }
85
+ throw err;
86
+ } finally {
87
+ if (!settled) {
88
+ status = Status.CANCELLED;
89
+ }
90
+ metrics.handled({ ...labels, code: Status[status] });
91
+ }
92
+ };
93
+ }