@gitpod/gitpod-protocol 0.1.5-upgrade-code.5 → 0.1.5-vn-implement-jetbrains-terminals.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 (299) hide show
  1. package/data/builtin-theia-plugins.json +9 -9
  2. package/data/gitpod-schema.json +25 -24
  3. package/lib/accounting-protocol.d.ts +155 -0
  4. package/lib/accounting-protocol.d.ts.map +1 -0
  5. package/lib/accounting-protocol.js +109 -0
  6. package/lib/accounting-protocol.js.map +1 -0
  7. package/lib/admin-protocol.d.ts +31 -4
  8. package/lib/admin-protocol.d.ts.map +1 -1
  9. package/lib/admin-protocol.js +15 -0
  10. package/lib/admin-protocol.js.map +1 -1
  11. package/lib/analytics.d.ts +45 -0
  12. package/lib/analytics.d.ts.map +1 -0
  13. package/lib/analytics.js +10 -0
  14. package/lib/analytics.js.map +1 -0
  15. package/lib/auth.d.ts +25 -0
  16. package/lib/auth.d.ts.map +1 -0
  17. package/lib/auth.js +16 -0
  18. package/lib/auth.js.map +1 -0
  19. package/lib/context-url.d.ts +31 -0
  20. package/lib/context-url.d.ts.map +1 -0
  21. package/lib/context-url.js +102 -0
  22. package/lib/context-url.js.map +1 -0
  23. package/lib/context-url.spec.d.ts +14 -0
  24. package/lib/context-url.spec.d.ts.map +1 -0
  25. package/lib/context-url.spec.js +94 -0
  26. package/lib/context-url.spec.js.map +1 -0
  27. package/lib/email-protocol.d.ts +1 -2
  28. package/lib/email-protocol.d.ts.map +1 -1
  29. package/lib/email-protocol.js +4 -4
  30. package/lib/email-protocol.js.map +1 -1
  31. package/lib/encryption/container-module.js +5 -4
  32. package/lib/encryption/container-module.js.map +1 -1
  33. package/lib/encryption/encryption-engine.js +19 -20
  34. package/lib/encryption/encryption-engine.js.map +1 -1
  35. package/lib/encryption/encryption-engine.spec.js +29 -36
  36. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  37. package/lib/encryption/encryption-service.js +29 -43
  38. package/lib/encryption/encryption-service.js.map +1 -1
  39. package/lib/encryption/key-provider.js +25 -30
  40. package/lib/encryption/key-provider.js.map +1 -1
  41. package/lib/env.d.ts +1 -2
  42. package/lib/env.d.ts.map +1 -1
  43. package/lib/env.js +20 -21
  44. package/lib/env.js.map +1 -1
  45. package/lib/gitpod-file-parser.js +25 -41
  46. package/lib/gitpod-file-parser.js.map +1 -1
  47. package/lib/gitpod-file-parser.spec.js +116 -116
  48. package/lib/gitpod-file-parser.spec.js.map +1 -1
  49. package/lib/gitpod-service.d.ts +162 -20
  50. package/lib/gitpod-service.d.ts.map +1 -1
  51. package/lib/gitpod-service.js +170 -256
  52. package/lib/gitpod-service.js.map +1 -1
  53. package/lib/headless-workspace-log.d.ts +8 -11
  54. package/lib/headless-workspace-log.d.ts.map +1 -1
  55. package/lib/headless-workspace-log.js +4 -7
  56. package/lib/headless-workspace-log.js.map +1 -1
  57. package/lib/ide-frontend-service.d.ts +4 -0
  58. package/lib/ide-frontend-service.d.ts.map +1 -1
  59. package/lib/ide-protocol.d.ts +105 -0
  60. package/lib/ide-protocol.d.ts.map +1 -0
  61. package/lib/ide-protocol.js +8 -0
  62. package/lib/ide-protocol.js.map +1 -0
  63. package/lib/index.d.ts +6 -0
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js +7 -1
  66. package/lib/index.js.map +1 -1
  67. package/lib/installation-admin-protocol.d.ts +21 -0
  68. package/lib/installation-admin-protocol.d.ts.map +1 -0
  69. package/lib/installation-admin-protocol.js +30 -0
  70. package/lib/installation-admin-protocol.js.map +1 -0
  71. package/lib/messaging/browser/connection.d.ts +5 -3
  72. package/lib/messaging/browser/connection.d.ts.map +1 -1
  73. package/lib/messaging/browser/connection.js +183 -33
  74. package/lib/messaging/browser/connection.js.map +1 -1
  75. package/lib/messaging/browser/window-connection.js +35 -55
  76. package/lib/messaging/browser/window-connection.js.map +1 -1
  77. package/lib/messaging/client-call-metrics.d.ts +35 -0
  78. package/lib/messaging/client-call-metrics.d.ts.map +1 -0
  79. package/lib/messaging/client-call-metrics.js +83 -0
  80. package/lib/messaging/client-call-metrics.js.map +1 -0
  81. package/lib/messaging/error.d.ts +5 -1
  82. package/lib/messaging/error.d.ts.map +1 -1
  83. package/lib/messaging/error.js +10 -2
  84. package/lib/messaging/error.js.map +1 -1
  85. package/lib/messaging/handler.d.ts +10 -0
  86. package/lib/messaging/handler.d.ts.map +1 -1
  87. package/lib/messaging/node/connection.d.ts +1 -17
  88. package/lib/messaging/node/connection.d.ts.map +1 -1
  89. package/lib/messaging/node/connection.js +23 -59
  90. package/lib/messaging/node/connection.js.map +1 -1
  91. package/lib/messaging/proxy-factory.d.ts +2 -0
  92. package/lib/messaging/proxy-factory.d.ts.map +1 -1
  93. package/lib/messaging/proxy-factory.js +74 -159
  94. package/lib/messaging/proxy-factory.js.map +1 -1
  95. package/lib/oss-allowlist.d.ts +14 -0
  96. package/lib/oss-allowlist.d.ts.map +1 -0
  97. package/lib/oss-allowlist.js +8 -0
  98. package/lib/oss-allowlist.js.map +1 -0
  99. package/lib/payment-protocol.d.ts +18 -0
  100. package/lib/payment-protocol.d.ts.map +1 -0
  101. package/lib/payment-protocol.js +13 -0
  102. package/lib/payment-protocol.js.map +1 -0
  103. package/lib/permission.d.ts +5 -3
  104. package/lib/permission.d.ts.map +1 -1
  105. package/lib/permission.js +18 -17
  106. package/lib/permission.js.map +1 -1
  107. package/lib/plans.d.ts +210 -0
  108. package/lib/plans.d.ts.map +1 -0
  109. package/lib/plans.js +570 -0
  110. package/lib/plans.js.map +1 -0
  111. package/lib/protocol.d.ts +120 -58
  112. package/lib/protocol.d.ts.map +1 -1
  113. package/lib/protocol.js +116 -130
  114. package/lib/protocol.js.map +1 -1
  115. package/lib/snapshot-url.d.ts +14 -0
  116. package/lib/snapshot-url.d.ts.map +1 -0
  117. package/lib/snapshot-url.js +26 -0
  118. package/lib/snapshot-url.js.map +1 -0
  119. package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
  120. package/lib/snapshot-url.spec.d.ts.map +1 -0
  121. package/lib/snapshot-url.spec.js +41 -0
  122. package/lib/snapshot-url.spec.js.map +1 -0
  123. package/lib/team-subscription-protocol.d.ts +73 -0
  124. package/lib/team-subscription-protocol.d.ts.map +1 -0
  125. package/lib/team-subscription-protocol.js +63 -0
  126. package/lib/team-subscription-protocol.js.map +1 -0
  127. package/lib/teams-projects-protocol.d.ts +113 -0
  128. package/lib/teams-projects-protocol.d.ts.map +1 -0
  129. package/lib/teams-projects-protocol.js +30 -0
  130. package/lib/teams-projects-protocol.js.map +1 -0
  131. package/lib/util/analytics.d.ts +8 -0
  132. package/lib/util/analytics.d.ts.map +1 -0
  133. package/lib/util/analytics.js +79 -0
  134. package/lib/util/analytics.js.map +1 -0
  135. package/lib/util/async-iterator.js +55 -133
  136. package/lib/util/async-iterator.js.map +1 -1
  137. package/lib/util/cancelable.js +17 -59
  138. package/lib/util/cancelable.js.map +1 -1
  139. package/lib/util/date-time.js +8 -8
  140. package/lib/util/date-time.js.map +1 -1
  141. package/lib/util/deferred.js +10 -12
  142. package/lib/util/deferred.js.map +1 -1
  143. package/lib/util/disposable.js +26 -39
  144. package/lib/util/disposable.js.map +1 -1
  145. package/lib/util/event.js +58 -74
  146. package/lib/util/event.js.map +1 -1
  147. package/lib/util/garbage-collected-cache.d.ts +1 -0
  148. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  149. package/lib/util/garbage-collected-cache.js +26 -46
  150. package/lib/util/garbage-collected-cache.js.map +1 -1
  151. package/lib/util/generate-workspace-id.d.ts +4 -0
  152. package/lib/util/generate-workspace-id.d.ts.map +1 -0
  153. package/lib/util/generate-workspace-id.js +487 -0
  154. package/lib/util/generate-workspace-id.js.map +1 -0
  155. package/lib/util/{without.d.ts → generate-workspace-id.spec.d.ts} +2 -2
  156. package/lib/util/generate-workspace-id.spec.d.ts.map +1 -0
  157. package/lib/util/generate-workspace-id.spec.js +87 -0
  158. package/lib/util/generate-workspace-id.spec.js.map +1 -0
  159. package/lib/util/gitpod-cookie.d.ts +20 -0
  160. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  161. package/lib/util/gitpod-cookie.js +44 -0
  162. package/lib/util/gitpod-cookie.js.map +1 -0
  163. package/lib/util/gitpod-host-url.d.ts +1 -2
  164. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  165. package/lib/util/gitpod-host-url.js +96 -98
  166. package/lib/util/gitpod-host-url.js.map +1 -1
  167. package/lib/util/gitpod-host-url.spec.d.ts +8 -1
  168. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  169. package/lib/util/gitpod-host-url.spec.js +104 -22
  170. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  171. package/lib/util/grpc.d.ts +15 -0
  172. package/lib/util/grpc.d.ts.map +1 -0
  173. package/lib/util/grpc.js +18 -0
  174. package/lib/util/grpc.js.map +1 -0
  175. package/lib/util/jaeger-client-types.d.ts +68 -0
  176. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  177. package/lib/util/{without.js → jaeger-client-types.js} +1 -1
  178. package/lib/util/jaeger-client-types.js.map +1 -0
  179. package/lib/util/logging.d.ts +49 -33
  180. package/lib/util/logging.d.ts.map +1 -1
  181. package/lib/util/logging.js +107 -110
  182. package/lib/util/logging.js.map +1 -1
  183. package/lib/util/make-link.js +2 -2
  184. package/lib/util/make-link.js.map +1 -1
  185. package/lib/util/parse-workspace-id.d.ts +13 -3
  186. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  187. package/lib/util/parse-workspace-id.js +38 -8
  188. package/lib/util/parse-workspace-id.js.map +1 -1
  189. package/lib/util/parse-workspace-id.spec.d.ts +8 -0
  190. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  191. package/lib/util/parse-workspace-id.spec.js +127 -47
  192. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  193. package/lib/util/queue.js +16 -55
  194. package/lib/util/queue.js.map +1 -1
  195. package/lib/util/queue.spec.js +144 -288
  196. package/lib/util/queue.spec.js.map +1 -1
  197. package/lib/util/repeat.d.ts +15 -0
  198. package/lib/util/repeat.d.ts.map +1 -0
  199. package/lib/util/repeat.js +55 -0
  200. package/lib/util/repeat.js.map +1 -0
  201. package/lib/util/semaphore.js +15 -46
  202. package/lib/util/semaphore.js.map +1 -1
  203. package/lib/util/skip-if.js +6 -6
  204. package/lib/util/skip-if.js.map +1 -1
  205. package/lib/util/timeutil.js +28 -16
  206. package/lib/util/timeutil.js.map +1 -1
  207. package/lib/util/timeutil.spec.js +21 -24
  208. package/lib/util/timeutil.spec.js.map +1 -1
  209. package/lib/util/tracing.d.ts +51 -5
  210. package/lib/util/tracing.d.ts.map +1 -1
  211. package/lib/util/tracing.js +197 -62
  212. package/lib/util/tracing.js.map +1 -1
  213. package/lib/util/tracing.spec.d.ts +7 -0
  214. package/lib/util/tracing.spec.d.ts.map +1 -0
  215. package/lib/util/tracing.spec.js +121 -0
  216. package/lib/util/tracing.spec.js.map +1 -0
  217. package/lib/util/workspace-port-authentication.js +3 -2
  218. package/lib/util/workspace-port-authentication.js.map +1 -1
  219. package/lib/workspace-cluster.d.ts +71 -0
  220. package/lib/workspace-cluster.d.ts.map +1 -0
  221. package/lib/workspace-cluster.js +16 -0
  222. package/lib/workspace-cluster.js.map +1 -0
  223. package/lib/workspace-instance.d.ts +26 -2
  224. package/lib/workspace-instance.d.ts.map +1 -1
  225. package/lib/wsready.d.ts +1 -1
  226. package/lib/wsready.js +2 -2
  227. package/package.json +33 -17
  228. package/pkg-yarn.lock +18 -9
  229. package/provenance-bundle.jsonl +2 -0
  230. package/src/accounting-protocol.ts +229 -0
  231. package/src/admin-protocol.ts +53 -5
  232. package/src/analytics.ts +54 -0
  233. package/src/auth.ts +27 -0
  234. package/src/context-url.spec.ts +53 -0
  235. package/src/context-url.ts +107 -0
  236. package/src/email-protocol.ts +2 -3
  237. package/src/env.ts +10 -10
  238. package/src/gitpod-service.ts +237 -38
  239. package/src/headless-workspace-log.ts +7 -11
  240. package/src/ide-frontend-service.ts +5 -1
  241. package/src/ide-protocol.ts +119 -0
  242. package/src/index.ts +7 -1
  243. package/src/installation-admin-protocol.ts +35 -0
  244. package/src/messaging/browser/connection.ts +195 -14
  245. package/src/messaging/client-call-metrics.ts +97 -0
  246. package/src/messaging/error.ts +14 -2
  247. package/src/messaging/handler.ts +12 -0
  248. package/src/messaging/node/connection.ts +21 -68
  249. package/src/messaging/proxy-factory.ts +14 -6
  250. package/src/oss-allowlist.ts +15 -0
  251. package/src/payment-protocol.ts +20 -0
  252. package/src/permission.ts +7 -6
  253. package/src/plans.ts +632 -0
  254. package/src/protocol.ts +194 -87
  255. package/src/snapshot-url.spec.ts +25 -0
  256. package/src/snapshot-url.ts +27 -0
  257. package/src/team-subscription-protocol.ts +113 -0
  258. package/src/teams-projects-protocol.ts +147 -0
  259. package/src/util/analytics.ts +87 -0
  260. package/src/util/deferred.ts +1 -1
  261. package/src/util/garbage-collected-cache.ts +9 -3
  262. package/src/util/generate-workspace-id.spec.ts +48 -0
  263. package/src/util/generate-workspace-id.ts +475 -0
  264. package/src/util/gitpod-cookie.ts +39 -0
  265. package/src/util/gitpod-host-url.spec.ts +30 -1
  266. package/src/util/gitpod-host-url.ts +23 -13
  267. package/src/util/grpc.ts +15 -0
  268. package/src/util/jaeger-client-types.ts +102 -0
  269. package/src/util/logging.ts +102 -38
  270. package/src/util/parse-workspace-id.spec.ts +45 -4
  271. package/src/util/parse-workspace-id.ts +38 -7
  272. package/src/util/queue.spec.ts +1 -1
  273. package/src/util/repeat.ts +45 -0
  274. package/src/util/semaphore.ts +2 -2
  275. package/src/util/skip-if.ts +1 -1
  276. package/src/util/timeutil.ts +4 -4
  277. package/src/util/tracing.spec.ts +83 -0
  278. package/src/util/tracing.ts +183 -17
  279. package/src/workspace-cluster.ts +91 -0
  280. package/src/workspace-instance.ts +51 -13
  281. package/src/wsready.ts +2 -2
  282. package/lib/messaging/connection-error-handler.d.ts +0 -27
  283. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  284. package/lib/messaging/connection-error-handler.js +0 -46
  285. package/lib/messaging/connection-error-handler.js.map +0 -1
  286. package/lib/util/repeater.d.ts +0 -22
  287. package/lib/util/repeater.d.ts.map +0 -1
  288. package/lib/util/repeater.js +0 -118
  289. package/lib/util/repeater.js.map +0 -1
  290. package/lib/util/safe-promise.d.ts +0 -11
  291. package/lib/util/safe-promise.d.ts.map +0 -1
  292. package/lib/util/safe-promise.js +0 -34
  293. package/lib/util/safe-promise.js.map +0 -1
  294. package/lib/util/without.d.ts.map +0 -1
  295. package/lib/util/without.js.map +0 -1
  296. package/src/messaging/connection-error-handler.ts +0 -62
  297. package/src/util/jaeger-client.d.ts +0 -105
  298. package/src/util/repeater.ts +0 -49
  299. package/src/util/safe-promise.ts +0 -26
@@ -0,0 +1,229 @@
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 { v4 as uuidv4 } from 'uuid';
8
+ import { User } from './protocol';
9
+ import { oneMonthLater } from './util/timeutil';
10
+
11
+ /*
12
+ * Subscription and acocunting data
13
+ */
14
+ export interface AccountEntry {
15
+ uid: string;
16
+
17
+ userId: string;
18
+
19
+ /** [hours] */
20
+ amount: number;
21
+
22
+ /**
23
+ * credit: start of validity,
24
+ * session: end of (split-) session
25
+ */
26
+ date: string;
27
+
28
+ /**
29
+ * debits (session, expiry, loss): relation to credit
30
+ */
31
+ creditId?: string;
32
+
33
+ /**
34
+ * credit: end of validity
35
+ */
36
+ expiryDate?: string; // exclusive
37
+
38
+ kind: AccountEntryKind;
39
+
40
+ /**
41
+ * credit: amount - accounted debits
42
+ * [hours]
43
+ */
44
+ remainingAmount?: number;
45
+
46
+ description?: object;
47
+ }
48
+ export namespace AccountEntry {
49
+ export function create<T extends AccountEntry>(entry: Omit<T, 'uid'>): T {
50
+ const result = entry as T;
51
+ result.uid = uuidv4();
52
+ return result;
53
+ };
54
+ }
55
+
56
+ export type DebitAccountEntryKind = 'session' | 'expiry' | 'loss';
57
+ export type AccountEntryKind = 'credit' | DebitAccountEntryKind | 'carry' | 'open';
58
+
59
+ export interface Credit extends AccountEntry {
60
+ kind: 'credit';
61
+ expiryDate: string;
62
+ }
63
+ export type Debit = LossDebit | ExpiryDebit | SessionDebit;
64
+ export interface LossDebit extends AccountEntry {
65
+ kind: 'loss';
66
+ }
67
+ export interface ExpiryDebit extends AccountEntry {
68
+ kind: 'expiry';
69
+ creditId: undefined;
70
+ }
71
+ export interface SessionDebit extends AccountEntry {
72
+ kind: DebitAccountEntryKind;
73
+ creditId: string;
74
+ }
75
+
76
+ export type AccountEntryDescription = SessionDescription | CreditDescription;
77
+ export interface CreditDescription {
78
+ subscriptionId: string;
79
+ planId: string;
80
+ }
81
+ export namespace CreditDescription {
82
+ export function is(obj: any): obj is CreditDescription {
83
+ return !!obj
84
+ && obj.hasOwnProperty('subscriptionId')
85
+ && obj.hasOwnProperty('planId');
86
+ }
87
+ }
88
+ export interface SessionDescription {
89
+ contextTitle: string;
90
+ contextUrl: string;
91
+ workspaceId: string;
92
+ workspaceInstanceId: string;
93
+ }
94
+ export namespace SessionDescription {
95
+ export function is(obj: any): obj is SessionDescription {
96
+ return !!obj
97
+ && obj.hasOwnProperty('contextTitle')
98
+ && obj.hasOwnProperty('contextUrl')
99
+ && obj.hasOwnProperty('workspaceId')
100
+ && obj.hasOwnProperty('workspaceInstanceId')
101
+ }
102
+ }
103
+
104
+ /**
105
+ * - The earliest subscription may start with User.creationDate
106
+ * - There may be multiple Gitpod subscriptions for a user at any given time
107
+ * - The dates form an interval of the form: [startDate, endDate)
108
+ * - Subscriptions that directly map to a Chargebee plan have their paymentReference set and MAY carry additional paymentData (UserPaidSubscription)
109
+ * - Subscriptions that are assigned to a user through a Team Subscription carry a teamSubscriptionSlotId (AssignedTeamSubscription)
110
+ */
111
+ export interface Subscription {
112
+ uid: string;
113
+ userId: string;
114
+ startDate: string; // inclusive
115
+ /** When the subscription will end (must be >= cancellationDate!) */
116
+ endDate?: string; // exclusive
117
+ /** When the subscription was cancelled */
118
+ cancellationDate?: string; // exclusive
119
+ /** Number of granted hours */
120
+ amount: number;
121
+ /** Number of granted hours for the first month: If this is set, use this value for the first month */
122
+ firstMonthAmount?: number;
123
+ planId?: string;
124
+ paymentReference?: string;
125
+ paymentData?: PaymentData;
126
+ teamSubscriptionSlotId?: string;
127
+ /** marks the subscription as deleted */
128
+ deleted?: boolean;
129
+ }
130
+
131
+ export interface SubscriptionAndUser extends Subscription {
132
+ user: User;
133
+ }
134
+
135
+ export interface PaymentData {
136
+ /** Marks the date as of which the _switch_ is effective. */
137
+ downgradeDate?: string;
138
+ /** Determines the new plan the dowgrade is targeted against (optional for backwards compatibility) */
139
+ newPlan?: string;
140
+ }
141
+
142
+ export interface UserPaidSubscription extends Subscription {
143
+ paymentReference: string;
144
+ paymentData?: PaymentData;
145
+ }
146
+ export namespace UserPaidSubscription {
147
+ export function is(data: any): data is UserPaidSubscription {
148
+ return !!data
149
+ && data.hasOwnProperty('paymentReference');
150
+ }
151
+ }
152
+
153
+ export interface AssignedTeamSubscription extends Subscription {
154
+ teamSubscriptionSlotId: string;
155
+ }
156
+ export namespace AssignedTeamSubscription {
157
+ export function is(data: any): data is AssignedTeamSubscription {
158
+ return !!data
159
+ && data.hasOwnProperty('teamSubscriptionSlotId');
160
+ }
161
+ }
162
+
163
+ export namespace Subscription {
164
+ export function create(newSubscription: Omit<Subscription, 'uid'>) {
165
+ const subscription = newSubscription as Subscription;
166
+ subscription.uid = uuidv4();
167
+ return subscription;
168
+ };
169
+ export function cancelSubscription(s: Subscription, cancellationDate: string, endDate?: string) {
170
+ s.endDate = endDate || cancellationDate;
171
+ s.cancellationDate = cancellationDate;
172
+ };
173
+ export function isSame(s1: Subscription | undefined, s2: Subscription | undefined): boolean {
174
+ return !!s1 && !!s2
175
+ && s1.userId === s2.userId
176
+ && s1.planId === s2.planId
177
+ && s1.startDate === s2.startDate
178
+ && s1.endDate === s2.endDate
179
+ && s1.amount === s2.amount
180
+ && s1.cancellationDate === s2.cancellationDate
181
+ && s1.deleted === s2.deleted
182
+ && ((s1.paymentData === undefined && s2.paymentData === undefined)
183
+ || (!!s1.paymentData && !!s2.paymentData
184
+ && s1.paymentData.downgradeDate === s2.paymentData.downgradeDate
185
+ && s1.paymentData.newPlan === s2.paymentData.newPlan));
186
+ };
187
+ export function isActive(s: Subscription, date: string): boolean {
188
+ return s.startDate <= date && (s.endDate === undefined || date < s.endDate);
189
+ };
190
+ export function isDowngraded(s: Subscription) {
191
+ return s.paymentData && s.paymentData.downgradeDate;
192
+ };
193
+ export function calculateCurrentPeriod(startDate: string, now: Date) {
194
+ let nextStartDate = startDate;
195
+ do {
196
+ startDate = nextStartDate;
197
+ nextStartDate = oneMonthLater(startDate, new Date(startDate).getDate());
198
+ } while (nextStartDate < now.toISOString());
199
+ return { startDate, endDate: nextStartDate };
200
+ };
201
+ }
202
+
203
+ export type MaybeSubscription = Subscription | undefined;
204
+
205
+ export interface Period {
206
+ startDate: string; // inclusive
207
+ endDate: string; // exclusive
208
+ }
209
+
210
+ export type MaybePeriod = Period | undefined;
211
+
212
+ export type AccountEntryFixedPeriod = Omit<AccountEntry, 'uid'> & { expiryDate: string };
213
+ export interface AccountStatement extends Period {
214
+ userId: string;
215
+ /**
216
+ * The subscriptions that have not been cancelled yet at the end of the period
217
+ */
218
+ subscriptions: Subscription[];
219
+ credits: Credit[];
220
+ debits: Debit[];
221
+ /** Remaining valid hours (accumulated from credits) */
222
+ remainingHours: RemainingHours;
223
+ }
224
+ export type RemainingHours = number | 'unlimited';
225
+
226
+ export interface CreditAlert {
227
+ userId: string,
228
+ remainingUsageHours: number
229
+ }
@@ -5,22 +5,43 @@
5
5
  */
6
6
 
7
7
  import { User, Workspace, NamedWorkspaceFeatureFlag } from "./protocol";
8
- import { Without } from "./util/without";
8
+ import { FindPrebuildsParams } from "./gitpod-service";
9
+ import { PrebuildWithStatus } from "./teams-projects-protocol"
10
+ import { Project, Team } from "./teams-projects-protocol";
9
11
  import { WorkspaceInstance, WorkspaceInstancePhase } from "./workspace-instance";
10
12
  import { RoleOrPermission } from "./permission";
13
+ import { AccountStatement } from "./accounting-protocol";
14
+ import { InstallationAdminSettings } from "./installation-admin-protocol";
11
15
 
12
16
  export interface AdminServer {
13
17
  adminGetUsers(req: AdminGetListRequest<User>): Promise<AdminGetListResult<User>>;
14
18
  adminGetUser(id: string): Promise<User>;
15
19
  adminBlockUser(req: AdminBlockUserRequest): Promise<User>;
20
+ adminDeleteUser(id: string): Promise<void>;
16
21
  adminModifyRoleOrPermission(req: AdminModifyRoleOrPermissionRequest): Promise<User>;
17
22
  adminModifyPermanentWorkspaceFeatureFlag(req: AdminModifyPermanentWorkspaceFeatureFlagRequest): Promise<User>;
18
23
 
24
+ adminGetTeamById(id: string): Promise<Team | undefined>;
25
+
19
26
  adminGetWorkspaces(req: AdminGetWorkspacesRequest): Promise<AdminGetListResult<WorkspaceAndInstance>>;
20
27
  adminGetWorkspace(id: string): Promise<WorkspaceAndInstance>;
21
28
  adminForceStopWorkspace(id: string): Promise<void>;
29
+ adminRestoreSoftDeletedWorkspace(id: string): Promise<void>;
30
+
31
+ adminGetProjectsBySearchTerm(req: AdminGetListRequest<Project>): Promise<AdminGetListResult<Project>>;
32
+ adminGetProjectById(id: string): Promise<Project | undefined>;
22
33
 
34
+ adminFindPrebuilds(params: FindPrebuildsParams): Promise<PrebuildWithStatus[]>;
23
35
  adminSetLicense(key: string): Promise<void>;
36
+
37
+ adminGetAccountStatement(userId: string): Promise<AccountStatement>;
38
+ adminSetProfessionalOpenSource(userId: string, shouldGetProfOSS: boolean): Promise<void>;
39
+ adminIsStudent(userId: string): Promise<boolean>;
40
+ adminAddStudentEmailDomain(userId: string, domain: string): Promise<void>;
41
+ adminGrantExtraHours(userId: string, extraHours: number): Promise<void>;
42
+
43
+ adminGetSettings(): Promise<InstallationAdminSettings>
44
+ adminUpdateSettings(settings: InstallationAdminSettings): Promise<void>
24
45
  }
25
46
 
26
47
  export interface AdminGetListRequest<T> {
@@ -57,7 +78,7 @@ export interface AdminModifyPermanentWorkspaceFeatureFlagRequest {
57
78
  }[]
58
79
  }
59
80
 
60
- export interface WorkspaceAndInstance extends Without<Workspace, "id"|"creationTime">, Without<WorkspaceInstance, "id"|"creationTime"> {
81
+ export interface WorkspaceAndInstance extends Omit<Workspace, "id" | "creationTime">, Omit<WorkspaceInstance, "id" | "creationTime"> {
61
82
  workspaceId: string;
62
83
  workspaceCreationTime: string;
63
84
  instanceId: string;
@@ -65,6 +86,33 @@ export interface WorkspaceAndInstance extends Without<Workspace, "id"|"creationT
65
86
  phase: WorkspaceInstancePhase;
66
87
  }
67
88
 
68
- export interface AdminGetWorkspacesRequest extends AdminGetListRequest<WorkspaceAndInstance> {
69
- ownerId?: string
70
- }
89
+ export namespace WorkspaceAndInstance {
90
+ export function toWorkspace(wai: WorkspaceAndInstance): Workspace {
91
+ return {
92
+ id: wai.workspaceId,
93
+ creationTime: wai.workspaceCreationTime,
94
+ ...wai
95
+ };
96
+ }
97
+
98
+ export function toInstance(wai: WorkspaceAndInstance): WorkspaceInstance | undefined {
99
+ if (!wai.instanceId) {
100
+ return undefined;
101
+ }
102
+ return {
103
+ id: wai.instanceId,
104
+ creationTime: wai.instanceCreationTime,
105
+ ...wai
106
+ };
107
+ }
108
+ }
109
+
110
+ export type AdminGetWorkspacesRequest = AdminGetListRequest<WorkspaceAndInstance> & AdminGetWorkspacesQuery;
111
+ /** The fields are meant to be used either OR (not combined) */
112
+ export type AdminGetWorkspacesQuery = {
113
+ /** we use this field in case we have a UUIDv4 and don't know whether it's an (old) workspace or instance id */
114
+ instanceIdOrWorkspaceId?: string;
115
+ instanceId?: string;
116
+ workspaceId?: string;
117
+ ownerId?: string;
118
+ };
@@ -0,0 +1,54 @@
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
+
8
+ export const IAnalyticsWriter = Symbol("IAnalyticsWriter");
9
+
10
+ type Identity =
11
+ | { userId: string | number }
12
+ | { userId?: string | number; anonymousId: string | number };
13
+
14
+ interface Message {
15
+ messageId?: string;
16
+ }
17
+
18
+ export type IdentifyMessage = Message & Identity & {
19
+ traits?: any;
20
+ timestamp?: Date;
21
+ context?: any;
22
+ };
23
+
24
+ export type TrackMessage = Message & Identity & {
25
+ event: string;
26
+ properties?: any;
27
+ timestamp?: Date;
28
+ context?: any;
29
+ };
30
+
31
+ export type PageMessage = Message & Identity & {
32
+ properties?: any;
33
+ timestamp?: Date;
34
+ context?: any;
35
+ };
36
+
37
+ export type RemoteTrackMessage = Omit<TrackMessage, "timestamp" | "userId" | "anonymousId"> & {
38
+ anonymousId?: string | number;
39
+ };
40
+ export type RemotePageMessage = Omit<PageMessage, "timestamp" | "userId"> & {
41
+ anonymousId?: string | number;
42
+ };
43
+
44
+ export type RemoteIdentifyMessage = Omit<IdentifyMessage, "timestamp" | "userId" | "anonymousId">;
45
+
46
+ export interface IAnalyticsWriter {
47
+
48
+ identify(msg: IdentifyMessage): void;
49
+
50
+ track(msg: TrackMessage): void;
51
+
52
+ page(msg: PageMessage): void;
53
+
54
+ }
package/src/auth.ts ADDED
@@ -0,0 +1,27 @@
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
+ export interface SelectAccountPayload {
8
+ currentUser: {
9
+ name: string;
10
+ avatarUrl: string;
11
+ authHost: string;
12
+ authName: string;
13
+ authProviderType: string;
14
+ },
15
+ otherUser: {
16
+ name: string;
17
+ avatarUrl: string;
18
+ authHost: string;
19
+ authName: string;
20
+ authProviderType: string;
21
+ }
22
+ }
23
+ export namespace SelectAccountPayload {
24
+ export function is(data: any): data is SelectAccountPayload {
25
+ return typeof data === "object" && "currentUser" in data && "otherUser" in data;
26
+ }
27
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2020 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 * as chai from 'chai';
8
+ import { suite, test } from 'mocha-typescript';
9
+ import { Workspace } from '.';
10
+ import { ContextURL } from './context-url';
11
+ const expect = chai.expect;
12
+
13
+ type WsContextUrl = Pick<Workspace, "context" | "contextURL">;
14
+
15
+ @suite
16
+ export class ContextUrlTest {
17
+
18
+ @test public parseContextUrl_withEnvVar() {
19
+ const actual = ContextURL.getNormalizedURL({ contextURL: "passedin=test%20value/https://github.com/gitpod-io/gitpod-test-repo", context: {} } as WsContextUrl);
20
+ expect(actual?.host).to.equal("github.com");
21
+ expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
22
+ }
23
+
24
+ @test public parseContextUrl_withEnvVar_withoutSchema() {
25
+ const actual = ContextURL.getNormalizedURL({ contextURL: "passedin=test%20value/github.com/gitpod-io/gitpod-test-repo", context: {} } as WsContextUrl);
26
+ expect(actual?.host).to.equal("github.com");
27
+ expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
28
+ }
29
+
30
+ @test public parseContextUrl_withEnvVar_sshUrl() {
31
+ const actual = ContextURL.getNormalizedURL({ contextURL: "passedin=test%20value/git@github.com:gitpod-io/gitpod-test-repo.git", context: {} } as WsContextUrl);
32
+ expect(actual?.host).to.equal("github.com");
33
+ expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo.git");
34
+ }
35
+
36
+ @test public parseContextUrl_withPrebuild() {
37
+ const actual = ContextURL.getNormalizedURL({ contextURL: "prebuild/https://github.com/gitpod-io/gitpod-test-repo", context: {} } as WsContextUrl);
38
+ expect(actual?.host).to.equal("github.com");
39
+ expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
40
+ }
41
+
42
+ @test public parseContextUrl_withPrebuild_withoutSchema() {
43
+ const actual = ContextURL.getNormalizedURL({ contextURL: "prebuild/github.com/gitpod-io/gitpod-test-repo", context: {} } as WsContextUrl);
44
+ expect(actual?.host).to.equal("github.com");
45
+ expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo");
46
+ }
47
+
48
+ @test public parseContextUrl_badUrl() {
49
+ const actual = ContextURL.getNormalizedURL({ contextURL: "[Object object]", context: {} } as WsContextUrl);
50
+ expect(actual).to.be.undefined;
51
+ }
52
+ }
53
+ module.exports = new ContextUrlTest()
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Copyright (c) 2020 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 { Workspace } from ".";
8
+
9
+ /**
10
+ * The whole point of these methods is to overcome inconsistencies in our data model.
11
+ * Ideally we remove it at some point once we fixed our model, as it:
12
+ * - duplicates logic
13
+ * - but additional burden on clients (using this, copying this to other languages!)
14
+ *
15
+ * TODO(gpl) See if we can get this into `server` code to remove the burden from clients
16
+ */
17
+ export namespace ContextURL {
18
+ export const INCREMENTAL_PREBUILD_PREFIX = "incremental-prebuild";
19
+ export const PREBUILD_PREFIX = "prebuild";
20
+ export const IMAGEBUILD_PREFIX = "imagebuild";
21
+ export const SNAPSHOT_PREFIX = "snapshot";
22
+ export const REFERRER_PREFIX = 'referrer:';
23
+
24
+ /**
25
+ * This function will (try to) return the HTTP(S) URL of the context the user originally created this workspace on.
26
+ * Especially it will not contain any modifiers or be of different scheme than HTTP(S).
27
+ *
28
+ * Use this function if you need to provided a _working_ URL to the original context.
29
+ * @param ws
30
+ * @returns
31
+ */
32
+ export function getNormalizedURL(ws: Pick<Workspace, "context" | "contextURL"> | undefined): URL | undefined {
33
+ const normalized = normalize(ws);
34
+ if (!normalized) {
35
+ return undefined;
36
+ }
37
+
38
+ try {
39
+ return new URL(normalized);
40
+ } catch (err) {
41
+ console.error(`unable to parse URL from normalized contextURL: '${normalized}'`, err);
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ function normalize(ws: Pick<Workspace, "context" | "contextURL"> | undefined): string | undefined {
47
+ if (!ws) {
48
+ return undefined;
49
+ }
50
+ if (ws.context.normalizedContextURL) {
51
+ return ws.context.normalizedContextURL;
52
+ }
53
+
54
+ // fallback: we do not yet set normalizedContextURL on all workspaces, yet, let alone older existing workspaces
55
+ let fallback: string | undefined = undefined;
56
+ try {
57
+ fallback = removePrefixes(ws.contextURL);
58
+ } catch (err) {
59
+ console.error(`unable to remove prefixes from contextURL: '${ws.contextURL}'`, err);
60
+ }
61
+ return fallback;
62
+ }
63
+
64
+ /**
65
+ * The field "contextUrl" might contain prefixes like:
66
+ * - envvar1=value1/...
67
+ * - prebuild/...
68
+ * This is the analogon to the (Prefix)ContextParser structure in "server".
69
+ */
70
+ function removePrefixes(contextUrl: string | undefined): string | undefined {
71
+ if (contextUrl === undefined) {
72
+ return undefined;
73
+ }
74
+
75
+ const segments = contextUrl.split("/");
76
+ if (segments.length === 1) {
77
+ return segments[0]; // this might be something, we just try
78
+ }
79
+
80
+ const segmentsToURL = (offset: number): string => {
81
+ let rest = segments.slice(offset).join("/");
82
+ if (/^git@[^:\/]+:/.test(rest)) {
83
+ rest = rest.replace(/^git@([^:\/]+):/, 'https://$1/');
84
+ }
85
+ if (!rest.startsWith("http")) {
86
+ rest = 'https://' + rest;
87
+ }
88
+ return rest;
89
+ };
90
+
91
+ const firstSegment = segments[0];
92
+ if (firstSegment === PREBUILD_PREFIX ||
93
+ firstSegment === INCREMENTAL_PREBUILD_PREFIX ||
94
+ firstSegment === IMAGEBUILD_PREFIX ||
95
+ firstSegment === SNAPSHOT_PREFIX ||
96
+ firstSegment.startsWith(REFERRER_PREFIX)) {
97
+ return segmentsToURL(1);
98
+ }
99
+
100
+ // check for env vars
101
+ if (firstSegment.indexOf("=") !== -1) {
102
+ return segmentsToURL(1);
103
+ }
104
+
105
+ return segmentsToURL(0);
106
+ }
107
+ }
@@ -4,8 +4,7 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
- import { Without } from "./util/without";
8
- import uuidv4 = require("uuid/v4");
7
+ import { v4 as uuidv4 } from 'uuid';
9
8
 
10
9
  export type EMailState = "scheduledInternal"
11
10
  | "scheduledSendgrid";
@@ -59,7 +58,7 @@ export type EMail = {
59
58
  } & EMailStatus;
60
59
 
61
60
  export namespace EMail {
62
- export const create = (ts: Without<EMail, 'uid'>): EMail => {
61
+ export const create = (ts: Omit<EMail, 'uid'>): EMail => {
63
62
  const withId = ts as EMail;
64
63
  withId.uid = uuidv4();
65
64
  return withId;
package/src/env.ts CHANGED
@@ -13,18 +13,18 @@ const legacyStagenameTranslation: { [key: string]: KubeStage } = {
13
13
  "dev": "dev"
14
14
  }
15
15
 
16
+ export function translateLegacyStagename(kubeStage: string): KubeStage {
17
+ const stage = legacyStagenameTranslation[kubeStage];
18
+ if (!stage) {
19
+ throw new Error(`Invalid KUBE_STAGE: ${kubeStage}`);
20
+ }
21
+
22
+ return stage;
23
+ }
24
+
16
25
  @injectable()
17
26
  export abstract class AbstractComponentEnv {
18
- readonly kubeStage: KubeStage = getEnvVarParsed('KUBE_STAGE', (kubeStage) => {
19
- const stage = legacyStagenameTranslation[kubeStage];
20
- if (!stage) {
21
- throw new Error(`Environment variable invalid: KUBE_STAGE=${kubeStage}`);
22
- }
23
-
24
- return stage;
25
- });
26
- readonly kubeNamespace: string = getEnvVar('KUBE_NAMESPACE');
27
- readonly version: string = getEnvVar('VERSION');
27
+ readonly kubeStage: KubeStage = getEnvVarParsed('KUBE_STAGE', translateLegacyStagename);
28
28
 
29
29
  readonly installationLongname: string = getEnvVar("GITPOD_INSTALLATION_LONGNAME")
30
30
  readonly installationShortname: string = getEnvVar("GITPOD_INSTALLATION_SHORTNAME")