@gitpod/gitpod-protocol 0.1.5-wth-argo.0 → 0.1.5-yh-vmoptions-fork.1

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 (352) hide show
  1. package/data/gitpod-schema.json +206 -28
  2. package/lib/accounting-protocol.d.ts +162 -0
  3. package/lib/accounting-protocol.d.ts.map +1 -0
  4. package/lib/accounting-protocol.js +107 -0
  5. package/lib/accounting-protocol.js.map +1 -0
  6. package/lib/admin-protocol.d.ts +32 -4
  7. package/lib/admin-protocol.d.ts.map +1 -1
  8. package/lib/admin-protocol.js +15 -0
  9. package/lib/admin-protocol.js.map +1 -1
  10. package/lib/analytics.d.ts +44 -0
  11. package/lib/analytics.d.ts.map +1 -0
  12. package/lib/analytics.js +10 -0
  13. package/lib/analytics.js.map +1 -0
  14. package/lib/auth.d.ts.map +1 -1
  15. package/lib/context-url.d.ts +31 -0
  16. package/lib/context-url.d.ts.map +1 -0
  17. package/lib/context-url.js +102 -0
  18. package/lib/context-url.js.map +1 -0
  19. package/lib/context-url.spec.d.ts +14 -0
  20. package/lib/context-url.spec.d.ts.map +1 -0
  21. package/lib/context-url.spec.js +109 -0
  22. package/lib/context-url.spec.js.map +1 -0
  23. package/lib/email-protocol.d.ts +1 -2
  24. package/lib/email-protocol.d.ts.map +1 -1
  25. package/lib/email-protocol.js +4 -4
  26. package/lib/email-protocol.js.map +1 -1
  27. package/lib/encryption/container-module.d.ts.map +1 -1
  28. package/lib/encryption/container-module.js +5 -4
  29. package/lib/encryption/container-module.js.map +1 -1
  30. package/lib/encryption/encryption-engine.d.ts.map +1 -1
  31. package/lib/encryption/encryption-engine.js +25 -26
  32. package/lib/encryption/encryption-engine.js.map +1 -1
  33. package/lib/encryption/encryption-engine.spec.d.ts.map +1 -1
  34. package/lib/encryption/encryption-engine.spec.js +29 -37
  35. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  36. package/lib/encryption/encryption-service.d.ts.map +1 -1
  37. package/lib/encryption/encryption-service.js +30 -44
  38. package/lib/encryption/encryption-service.js.map +1 -1
  39. package/lib/encryption/key-provider.d.ts.map +1 -1
  40. package/lib/encryption/key-provider.js +31 -38
  41. package/lib/encryption/key-provider.js.map +1 -1
  42. package/lib/env.d.ts +0 -6
  43. package/lib/env.d.ts.map +1 -1
  44. package/lib/env.js +7 -27
  45. package/lib/env.js.map +1 -1
  46. package/lib/gitpod-file-parser.d.ts.map +1 -1
  47. package/lib/gitpod-file-parser.js +26 -42
  48. package/lib/gitpod-file-parser.js.map +1 -1
  49. package/lib/gitpod-file-parser.spec.js +145 -142
  50. package/lib/gitpod-file-parser.spec.js.map +1 -1
  51. package/lib/gitpod-service.d.ts +180 -33
  52. package/lib/gitpod-service.d.ts.map +1 -1
  53. package/lib/gitpod-service.js +194 -273
  54. package/lib/gitpod-service.js.map +1 -1
  55. package/lib/headless-workspace-log.d.ts +9 -11
  56. package/lib/headless-workspace-log.d.ts.map +1 -1
  57. package/lib/headless-workspace-log.js +6 -8
  58. package/lib/headless-workspace-log.js.map +1 -1
  59. package/lib/ide-frontend-service.d.ts +5 -1
  60. package/lib/ide-frontend-service.d.ts.map +1 -1
  61. package/lib/ide-protocol.d.ts +105 -0
  62. package/lib/ide-protocol.d.ts.map +1 -0
  63. package/lib/{util/without.js → ide-protocol.js} +2 -2
  64. package/lib/ide-protocol.js.map +1 -0
  65. package/lib/index.d.ts +16 -10
  66. package/lib/index.d.ts.map +1 -1
  67. package/lib/index.js +7 -1
  68. package/lib/index.js.map +1 -1
  69. package/lib/installation-admin-protocol.d.ts +27 -0
  70. package/lib/installation-admin-protocol.d.ts.map +1 -0
  71. package/lib/installation-admin-protocol.js +30 -0
  72. package/lib/installation-admin-protocol.js.map +1 -0
  73. package/lib/license-protocol.d.ts +7 -0
  74. package/lib/license-protocol.d.ts.map +1 -1
  75. package/lib/license-protocol.js.map +1 -1
  76. package/lib/messaging/browser/connection.d.ts +5 -3
  77. package/lib/messaging/browser/connection.d.ts.map +1 -1
  78. package/lib/messaging/browser/connection.js +184 -34
  79. package/lib/messaging/browser/connection.js.map +1 -1
  80. package/lib/messaging/browser/window-connection.d.ts +4 -4
  81. package/lib/messaging/browser/window-connection.d.ts.map +1 -1
  82. package/lib/messaging/browser/window-connection.js +42 -59
  83. package/lib/messaging/browser/window-connection.js.map +1 -1
  84. package/lib/messaging/client-call-metrics.d.ts +35 -0
  85. package/lib/messaging/client-call-metrics.d.ts.map +1 -0
  86. package/lib/messaging/client-call-metrics.js +83 -0
  87. package/lib/messaging/client-call-metrics.js.map +1 -0
  88. package/lib/messaging/error.d.ts +6 -1
  89. package/lib/messaging/error.d.ts.map +1 -1
  90. package/lib/messaging/error.js +12 -2
  91. package/lib/messaging/error.js.map +1 -1
  92. package/lib/messaging/handler.d.ts +10 -0
  93. package/lib/messaging/handler.d.ts.map +1 -1
  94. package/lib/messaging/handler.js +1 -1
  95. package/lib/messaging/node/connection.d.ts +1 -17
  96. package/lib/messaging/node/connection.d.ts.map +1 -1
  97. package/lib/messaging/node/connection.js +24 -60
  98. package/lib/messaging/node/connection.js.map +1 -1
  99. package/lib/messaging/proxy-factory.d.ts +3 -1
  100. package/lib/messaging/proxy-factory.d.ts.map +1 -1
  101. package/lib/messaging/proxy-factory.js +75 -162
  102. package/lib/messaging/proxy-factory.js.map +1 -1
  103. package/lib/oss-allowlist.d.ts +14 -0
  104. package/lib/oss-allowlist.d.ts.map +1 -0
  105. package/lib/oss-allowlist.js +8 -0
  106. package/lib/oss-allowlist.js.map +1 -0
  107. package/lib/payment-protocol.d.ts +18 -0
  108. package/lib/payment-protocol.d.ts.map +1 -0
  109. package/lib/payment-protocol.js +13 -0
  110. package/lib/payment-protocol.js.map +1 -0
  111. package/lib/permission.d.ts +10 -3
  112. package/lib/permission.d.ts.map +1 -1
  113. package/lib/permission.js +41 -31
  114. package/lib/permission.js.map +1 -1
  115. package/lib/plans.d.ts +210 -0
  116. package/lib/plans.d.ts.map +1 -0
  117. package/lib/plans.js +605 -0
  118. package/lib/plans.js.map +1 -0
  119. package/lib/protocol.d.ts +196 -83
  120. package/lib/protocol.d.ts.map +1 -1
  121. package/lib/protocol.js +264 -200
  122. package/lib/protocol.js.map +1 -1
  123. package/lib/snapshot-url.d.ts +14 -0
  124. package/lib/snapshot-url.d.ts.map +1 -0
  125. package/lib/snapshot-url.js +26 -0
  126. package/lib/snapshot-url.js.map +1 -0
  127. package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
  128. package/lib/snapshot-url.spec.d.ts.map +1 -0
  129. package/lib/snapshot-url.spec.js +41 -0
  130. package/lib/snapshot-url.spec.js.map +1 -0
  131. package/lib/team-subscription-protocol.d.ts +91 -0
  132. package/lib/team-subscription-protocol.d.ts.map +1 -0
  133. package/lib/team-subscription-protocol.js +74 -0
  134. package/lib/team-subscription-protocol.js.map +1 -0
  135. package/lib/teams-projects-protocol.d.ts +118 -0
  136. package/lib/teams-projects-protocol.d.ts.map +1 -0
  137. package/lib/teams-projects-protocol.js +30 -0
  138. package/lib/teams-projects-protocol.js.map +1 -0
  139. package/lib/typings/globals.d.ts +2 -2
  140. package/lib/typings/globals.d.ts.map +1 -1
  141. package/lib/util/analytics.d.ts +8 -0
  142. package/lib/util/analytics.d.ts.map +1 -0
  143. package/lib/util/analytics.js +88 -0
  144. package/lib/util/analytics.js.map +1 -0
  145. package/lib/util/async-iterator.d.ts.map +1 -1
  146. package/lib/util/async-iterator.js +57 -135
  147. package/lib/util/async-iterator.js.map +1 -1
  148. package/lib/util/cancelable.js +17 -59
  149. package/lib/util/cancelable.js.map +1 -1
  150. package/lib/util/date-time.js +11 -11
  151. package/lib/util/date-time.js.map +1 -1
  152. package/lib/util/deferred.js +10 -12
  153. package/lib/util/deferred.js.map +1 -1
  154. package/lib/util/disposable.d.ts.map +1 -1
  155. package/lib/util/disposable.js +27 -40
  156. package/lib/util/disposable.js.map +1 -1
  157. package/lib/util/event.d.ts.map +1 -1
  158. package/lib/util/event.js +63 -77
  159. package/lib/util/event.js.map +1 -1
  160. package/lib/util/garbage-collected-cache.d.ts +1 -0
  161. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  162. package/lib/util/garbage-collected-cache.js +27 -47
  163. package/lib/util/garbage-collected-cache.js.map +1 -1
  164. package/lib/util/generate-workspace-id.d.ts +6 -1
  165. package/lib/util/generate-workspace-id.d.ts.map +1 -1
  166. package/lib/util/generate-workspace-id.js +469 -502
  167. package/lib/util/generate-workspace-id.js.map +1 -1
  168. package/lib/util/generate-workspace-id.spec.js +68 -78
  169. package/lib/util/generate-workspace-id.spec.js.map +1 -1
  170. package/lib/util/gitpod-cookie.d.ts +20 -0
  171. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  172. package/lib/util/gitpod-cookie.js +41 -0
  173. package/lib/util/gitpod-cookie.js.map +1 -0
  174. package/lib/util/gitpod-host-url.d.ts +1 -2
  175. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  176. package/lib/util/gitpod-host-url.js +108 -109
  177. package/lib/util/gitpod-host-url.js.map +1 -1
  178. package/lib/util/gitpod-host-url.spec.d.ts +7 -1
  179. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  180. package/lib/util/gitpod-host-url.spec.js +113 -31
  181. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  182. package/lib/util/grpc.d.ts +15 -0
  183. package/lib/util/grpc.d.ts.map +1 -0
  184. package/lib/util/grpc.js +18 -0
  185. package/lib/util/grpc.js.map +1 -0
  186. package/lib/util/jaeger-client-types.d.ts +68 -0
  187. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  188. package/lib/{theia-plugins.js → util/jaeger-client-types.js} +1 -1
  189. package/lib/util/jaeger-client-types.js.map +1 -0
  190. package/lib/util/logging.d.ts +49 -33
  191. package/lib/util/logging.d.ts.map +1 -1
  192. package/lib/util/logging.js +125 -129
  193. package/lib/util/logging.js.map +1 -1
  194. package/lib/util/make-link.js +5 -5
  195. package/lib/util/make-link.js.map +1 -1
  196. package/lib/util/parse-workspace-id.d.ts +10 -0
  197. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  198. package/lib/util/parse-workspace-id.js +31 -7
  199. package/lib/util/parse-workspace-id.js.map +1 -1
  200. package/lib/util/parse-workspace-id.spec.d.ts +4 -0
  201. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  202. package/lib/util/parse-workspace-id.spec.js +123 -84
  203. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  204. package/lib/util/queue.js +16 -55
  205. package/lib/util/queue.js.map +1 -1
  206. package/lib/util/queue.spec.js +147 -288
  207. package/lib/util/queue.spec.js.map +1 -1
  208. package/lib/util/repeat.d.ts +15 -0
  209. package/lib/util/repeat.d.ts.map +1 -0
  210. package/lib/util/repeat.js +55 -0
  211. package/lib/util/repeat.js.map +1 -0
  212. package/lib/util/semaphore.d.ts.map +1 -1
  213. package/lib/util/semaphore.js +15 -46
  214. package/lib/util/semaphore.js.map +1 -1
  215. package/lib/util/skip-if.d.ts.map +1 -1
  216. package/lib/util/skip-if.js +6 -6
  217. package/lib/util/skip-if.js.map +1 -1
  218. package/lib/util/timeutil.d.ts +1 -0
  219. package/lib/util/timeutil.d.ts.map +1 -1
  220. package/lib/util/timeutil.js +35 -17
  221. package/lib/util/timeutil.js.map +1 -1
  222. package/lib/util/timeutil.spec.d.ts.map +1 -1
  223. package/lib/util/timeutil.spec.js +21 -24
  224. package/lib/util/timeutil.spec.js.map +1 -1
  225. package/lib/util/tracing.d.ts +52 -6
  226. package/lib/util/tracing.d.ts.map +1 -1
  227. package/lib/util/tracing.js +197 -64
  228. package/lib/util/tracing.js.map +1 -1
  229. package/lib/util/tracing.spec.d.ts +7 -0
  230. package/lib/util/tracing.spec.d.ts.map +1 -0
  231. package/lib/util/tracing.spec.js +121 -0
  232. package/lib/util/tracing.spec.js.map +1 -0
  233. package/lib/util/workspace-port-authentication.d.ts +7 -7
  234. package/lib/util/workspace-port-authentication.d.ts.map +1 -1
  235. package/lib/util/workspace-port-authentication.js +10 -12
  236. package/lib/util/workspace-port-authentication.js.map +1 -1
  237. package/lib/workspace-cluster.d.ts +76 -0
  238. package/lib/workspace-cluster.d.ts.map +1 -0
  239. package/lib/workspace-cluster.js +31 -0
  240. package/lib/workspace-cluster.js.map +1 -0
  241. package/lib/workspace-instance.d.ts +45 -5
  242. package/lib/workspace-instance.d.ts.map +1 -1
  243. package/lib/wsready.d.ts +1 -1
  244. package/lib/wsready.d.ts.map +1 -1
  245. package/lib/wsready.js +2 -2
  246. package/package.json +32 -18
  247. package/pkg-yarn.lock +18 -10
  248. package/provenance-bundle.jsonl +2 -0
  249. package/src/accounting-protocol.ts +241 -0
  250. package/src/admin-protocol.ts +70 -19
  251. package/src/analytics.ts +52 -0
  252. package/src/auth.ts +2 -2
  253. package/src/context-url.spec.ts +67 -0
  254. package/src/context-url.ts +109 -0
  255. package/src/email-protocol.ts +5 -7
  256. package/src/encryption/container-module.ts +2 -3
  257. package/src/encryption/encryption-engine.spec.ts +9 -8
  258. package/src/encryption/encryption-engine.ts +14 -14
  259. package/src/encryption/encryption-service.ts +4 -5
  260. package/src/encryption/key-provider.ts +16 -19
  261. package/src/env.ts +0 -22
  262. package/src/gitpod-file-parser.spec.ts +55 -61
  263. package/src/gitpod-file-parser.ts +16 -17
  264. package/src/gitpod-service.ts +348 -110
  265. package/src/headless-workspace-log.ts +12 -14
  266. package/src/ide-frontend-service.ts +6 -2
  267. package/src/ide-protocol.ts +119 -0
  268. package/src/index.ts +16 -10
  269. package/src/installation-admin-protocol.ts +42 -0
  270. package/src/license-protocol.ts +12 -6
  271. package/src/messaging/browser/connection.ts +197 -18
  272. package/src/messaging/browser/window-connection.ts +39 -29
  273. package/src/messaging/client-call-metrics.ts +96 -0
  274. package/src/messaging/error.ts +18 -5
  275. package/src/messaging/handler.ts +13 -1
  276. package/src/messaging/node/connection.ts +23 -70
  277. package/src/messaging/proxy-factory.ts +35 -34
  278. package/src/oss-allowlist.ts +15 -0
  279. package/src/payment-protocol.ts +20 -0
  280. package/src/permission.ts +42 -33
  281. package/src/plans.ts +679 -0
  282. package/src/protocol.ts +493 -275
  283. package/src/snapshot-url.spec.ts +27 -0
  284. package/src/snapshot-url.ts +27 -0
  285. package/src/team-subscription-protocol.ts +147 -0
  286. package/src/teams-projects-protocol.ts +153 -0
  287. package/src/typings/globals.ts +4 -4
  288. package/src/util/analytics.ts +109 -0
  289. package/src/util/async-iterator.ts +4 -5
  290. package/src/util/cancelable.ts +3 -3
  291. package/src/util/date-time.ts +8 -8
  292. package/src/util/deferred.ts +6 -6
  293. package/src/util/disposable.ts +3 -6
  294. package/src/util/event.ts +9 -11
  295. package/src/util/garbage-collected-cache.ts +11 -8
  296. package/src/util/generate-workspace-id.spec.ts +37 -10
  297. package/src/util/generate-workspace-id.ts +464 -438
  298. package/src/util/gitpod-cookie.ts +38 -0
  299. package/src/util/gitpod-host-url.spec.ts +59 -8
  300. package/src/util/gitpod-host-url.ts +52 -40
  301. package/src/util/grpc.ts +15 -0
  302. package/src/util/jaeger-client-types.ts +102 -0
  303. package/src/util/logging.ts +145 -72
  304. package/src/util/make-link.ts +6 -7
  305. package/src/util/parse-workspace-id.spec.ts +37 -8
  306. package/src/util/parse-workspace-id.ts +32 -7
  307. package/src/util/queue.spec.ts +28 -26
  308. package/src/util/repeat.ts +45 -0
  309. package/src/util/semaphore.ts +6 -8
  310. package/src/util/skip-if.ts +10 -7
  311. package/src/util/timeutil.spec.ts +14 -15
  312. package/src/util/timeutil.ts +25 -15
  313. package/src/util/tracing.spec.ts +88 -0
  314. package/src/util/tracing.ts +200 -31
  315. package/src/util/workspace-port-authentication.ts +10 -13
  316. package/src/workspace-cluster.ts +107 -0
  317. package/src/workspace-instance.ts +98 -31
  318. package/src/wsready.ts +3 -3
  319. package/data/builtin-theia-plugins.json +0 -372
  320. package/lib/messaging/connection-error-handler.d.ts +0 -27
  321. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  322. package/lib/messaging/connection-error-handler.js +0 -46
  323. package/lib/messaging/connection-error-handler.js.map +0 -1
  324. package/lib/theia-plugins.d.ts +0 -11
  325. package/lib/theia-plugins.d.ts.map +0 -1
  326. package/lib/theia-plugins.js.map +0 -1
  327. package/lib/util/context-url.d.ts +0 -13
  328. package/lib/util/context-url.d.ts.map +0 -1
  329. package/lib/util/context-url.js +0 -26
  330. package/lib/util/context-url.js.map +0 -1
  331. package/lib/util/context-url.spec.d.ts +0 -10
  332. package/lib/util/context-url.spec.d.ts.map +0 -1
  333. package/lib/util/context-url.spec.js +0 -52
  334. package/lib/util/context-url.spec.js.map +0 -1
  335. package/lib/util/repeater.d.ts +0 -22
  336. package/lib/util/repeater.d.ts.map +0 -1
  337. package/lib/util/repeater.js +0 -118
  338. package/lib/util/repeater.js.map +0 -1
  339. package/lib/util/safe-promise.d.ts +0 -11
  340. package/lib/util/safe-promise.d.ts.map +0 -1
  341. package/lib/util/safe-promise.js +0 -34
  342. package/lib/util/safe-promise.js.map +0 -1
  343. package/lib/util/without.d.ts +0 -7
  344. package/lib/util/without.d.ts.map +0 -1
  345. package/lib/util/without.js.map +0 -1
  346. package/src/messaging/connection-error-handler.ts +0 -62
  347. package/src/theia-plugins.ts +0 -11
  348. package/src/util/context-url.spec.ts +0 -25
  349. package/src/util/context-url.ts +0 -23
  350. package/src/util/jaeger-client.d.ts +0 -105
  351. package/src/util/repeater.ts +0 -49
  352. package/src/util/safe-promise.ts +0 -26
@@ -5,26 +5,66 @@
5
5
  */
6
6
 
7
7
  import {
8
- User, WorkspaceInfo, WorkspaceCreationResult, UserMessage, WorkspaceInstanceUser,
9
- WhitelistedRepository, WorkspaceImageBuild, AuthProviderInfo, Branding, CreateWorkspaceMode,
10
- Token, UserEnvVarValue, ResolvePluginsParams, PreparePluginUploadParams, Terms,
11
- ResolvedPlugins, Configuration, InstallPluginsParams, UninstallPluginParams, UserInfo, GitpodTokenType, GitpodToken, AuthProviderEntry
12
- } from './protocol';
13
- import { JsonRpcProxy, JsonRpcServer } from './messaging/proxy-factory';
14
- import { Disposable, CancellationTokenSource } from 'vscode-jsonrpc';
15
- import { HeadlessLogEvent } from './headless-workspace-log';
16
- import { WorkspaceInstance, WorkspaceInstancePort, WorkspaceInstancePhase } from './workspace-instance';
17
- import { AdminServer } from './admin-protocol';
18
- import { GitpodHostUrl } from './util/gitpod-host-url';
19
- import { WebSocketConnectionProvider } from './messaging/browser/connection';
20
- import { PermissionName } from './permission';
21
- import { LicenseService } from './license-protocol';
22
- import { Emitter } from './util/event';
8
+ User,
9
+ WorkspaceInfo,
10
+ WorkspaceCreationResult,
11
+ WorkspaceInstanceUser,
12
+ WhitelistedRepository,
13
+ WorkspaceImageBuild,
14
+ AuthProviderInfo,
15
+ CreateWorkspaceMode,
16
+ Token,
17
+ UserEnvVarValue,
18
+ Terms,
19
+ Configuration,
20
+ UserInfo,
21
+ GitpodTokenType,
22
+ GitpodToken,
23
+ AuthProviderEntry,
24
+ GuessGitTokenScopesParams,
25
+ GuessedGitTokenScopes,
26
+ ProjectEnvVar,
27
+ } from "./protocol";
28
+ import {
29
+ Team,
30
+ TeamMemberInfo,
31
+ TeamMembershipInvite,
32
+ Project,
33
+ TeamMemberRole,
34
+ PrebuildWithStatus,
35
+ StartPrebuildResult,
36
+ PartialProject,
37
+ } from "./teams-projects-protocol";
38
+ import { JsonRpcProxy, JsonRpcServer } from "./messaging/proxy-factory";
39
+ import { Disposable, CancellationTokenSource } from "vscode-jsonrpc";
40
+ import { HeadlessLogUrls } from "./headless-workspace-log";
41
+ import { WorkspaceInstance, WorkspaceInstancePort, WorkspaceInstancePhase } from "./workspace-instance";
42
+ import { AdminServer } from "./admin-protocol";
43
+ import { GitpodHostUrl } from "./util/gitpod-host-url";
44
+ import { WebSocketConnectionProvider } from "./messaging/browser/connection";
45
+ import { PermissionName } from "./permission";
46
+ import { LicenseService } from "./license-protocol";
47
+ import { Emitter } from "./util/event";
48
+ import { AccountStatement, CreditAlert } from "./accounting-protocol";
49
+ import { GithubUpgradeURL, PlanCoupon } from "./payment-protocol";
50
+ import {
51
+ TeamSubscription,
52
+ TeamSubscription2,
53
+ TeamSubscriptionSlot,
54
+ TeamSubscriptionSlotResolved,
55
+ } from "./team-subscription-protocol";
56
+ import { RemotePageMessage, RemoteTrackMessage, RemoteIdentifyMessage } from "./analytics";
57
+ import { IDEServer } from "./ide-protocol";
58
+ import { InstallationAdminSettings, TelemetryData } from "./installation-admin-protocol";
59
+ import { Currency } from "./plans";
23
60
 
24
61
  export interface GitpodClient {
25
62
  onInstanceUpdate(instance: WorkspaceInstance): void;
26
63
  onWorkspaceImageBuildLogs: WorkspaceImageBuild.LogCallback;
27
- onHeadlessWorkspaceLogs(evt: HeadlessLogEvent): void;
64
+
65
+ onPrebuildUpdate(update: PrebuildWithStatus): void;
66
+
67
+ onCreditAlert(creditAlert: CreditAlert): void;
28
68
 
29
69
  //#region propagating reconnection to iframe
30
70
  notifyDidOpenConnection(): void;
@@ -32,19 +72,19 @@ export interface GitpodClient {
32
72
  //#endregion
33
73
  }
34
74
 
35
- export const GitpodServer = Symbol('GitpodServer');
36
- export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer, LicenseService {
75
+ export const GitpodServer = Symbol("GitpodServer");
76
+ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer, LicenseService, IDEServer {
37
77
  // User related API
38
78
  getLoggedInUser(): Promise<User>;
39
79
  getTerms(): Promise<Terms>;
40
80
  updateLoggedInUser(user: Partial<User>): Promise<User>;
41
81
  getAuthProviders(): Promise<AuthProviderInfo[]>;
42
82
  getOwnAuthProviders(): Promise<AuthProviderEntry[]>;
43
- updateOwnAuthProvider(params: GitpodServer.UpdateOwnAuthProviderParams): Promise<void>;
83
+ updateOwnAuthProvider(params: GitpodServer.UpdateOwnAuthProviderParams): Promise<AuthProviderEntry>;
44
84
  deleteOwnAuthProvider(params: GitpodServer.DeleteOwnAuthProviderParams): Promise<void>;
45
- getBranding(): Promise<Branding>;
46
85
  getConfiguration(): Promise<Configuration>;
47
86
  getToken(query: GitpodServer.GetTokenSearchOptions): Promise<Token | undefined>;
87
+ getGitpodTokenScopes(tokenHash: string): Promise<string[]>;
48
88
  /**
49
89
  * @deprecated
50
90
  */
@@ -58,8 +98,15 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
58
98
  getWorkspaceOwner(workspaceId: string): Promise<UserInfo | undefined>;
59
99
  getWorkspaceUsers(workspaceId: string): Promise<WorkspaceInstanceUser[]>;
60
100
  getFeaturedRepositories(): Promise<WhitelistedRepository[]>;
101
+ getSuggestedContextURLs(): Promise<string[]>;
102
+ /**
103
+ * **Security:**
104
+ * Sensitive information like an owner token is erased, since it allows access for all team members.
105
+ * If you need to access an owner token use `getOwnerToken` instead.
106
+ */
61
107
  getWorkspace(id: string): Promise<WorkspaceInfo>;
62
108
  isWorkspaceOwner(workspaceId: string): Promise<boolean>;
109
+ getOwnerToken(workspaceId: string): Promise<string>;
63
110
 
64
111
  /**
65
112
  * Creates and starts a workspace for the given context URL.
@@ -76,8 +123,8 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
76
123
  updateWorkspaceUserPin(id: string, action: GitpodServer.PinAction): Promise<void>;
77
124
  sendHeartBeat(options: GitpodServer.SendHeartBeatOptions): Promise<void>;
78
125
  watchWorkspaceImageBuildLogs(workspaceId: string): Promise<void>;
79
- watchHeadlessWorkspaceLogs(workspaceId: string): Promise<void>;
80
126
  isPrebuildDone(pwsid: string): Promise<boolean>;
127
+ getHeadlessLog(instanceId: string): Promise<HeadlessLogUrls>;
81
128
 
82
129
  // Workspace timeout
83
130
  setWorkspaceTimeout(workspaceId: string, duration: WorkspaceTimeoutDuration): Promise<SetWorkspaceTimeoutResult>;
@@ -91,22 +138,55 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
91
138
  openPort(workspaceId: string, port: WorkspaceInstancePort): Promise<WorkspaceInstancePort | undefined>;
92
139
  closePort(workspaceId: string, port: number): Promise<void>;
93
140
 
94
- // User messages
95
- getUserMessages(options: GitpodServer.GetUserMessagesOptions): Promise<UserMessage[]>;
96
- updateUserMessages(options: GitpodServer.UpdateUserMessagesOptions): Promise<void>;
97
-
98
141
  // User storage
99
142
  getUserStorageResource(options: GitpodServer.GetUserStorageResourceOptions): Promise<string>;
100
143
  updateUserStorageResource(options: GitpodServer.UpdateUserStorageResourceOptions): Promise<void>;
101
144
 
102
- // user env vars
145
+ // User env vars
103
146
  getEnvVars(): Promise<UserEnvVarValue[]>;
147
+ getAllEnvVars(): Promise<UserEnvVarValue[]>;
104
148
  setEnvVar(variable: UserEnvVarValue): Promise<void>;
105
149
  deleteEnvVar(variable: UserEnvVarValue): Promise<void>;
106
150
 
151
+ // Teams
152
+ getTeams(): Promise<Team[]>;
153
+ getTeamMembers(teamId: string): Promise<TeamMemberInfo[]>;
154
+ createTeam(name: string): Promise<Team>;
155
+ joinTeam(inviteId: string): Promise<Team>;
156
+ setTeamMemberRole(teamId: string, userId: string, role: TeamMemberRole): Promise<void>;
157
+ removeTeamMember(teamId: string, userId: string): Promise<void>;
158
+ getGenericInvite(teamId: string): Promise<TeamMembershipInvite>;
159
+ resetGenericInvite(inviteId: string): Promise<TeamMembershipInvite>;
160
+ deleteTeam(teamId: string, userId: string): Promise<void>;
161
+
162
+ // Admin Settings
163
+ adminGetSettings(): Promise<InstallationAdminSettings>;
164
+ adminUpdateSettings(settings: InstallationAdminSettings): Promise<void>;
165
+ adminGetTelemetryData(): Promise<TelemetryData>;
166
+
167
+ // Projects
168
+ getProviderRepositoriesForUser(params: GetProviderRepositoriesParams): Promise<ProviderRepository[]>;
169
+ createProject(params: CreateProjectParams): Promise<Project>;
170
+ deleteProject(projectId: string): Promise<void>;
171
+ getTeamProjects(teamId: string): Promise<Project[]>;
172
+ getUserProjects(): Promise<Project[]>;
173
+ getProjectOverview(projectId: string): Promise<Project.Overview | undefined>;
174
+ findPrebuilds(params: FindPrebuildsParams): Promise<PrebuildWithStatus[]>;
175
+ triggerPrebuild(projectId: string, branchName: string | null): Promise<StartPrebuildResult>;
176
+ cancelPrebuild(projectId: string, prebuildId: string): Promise<void>;
177
+ fetchProjectRepositoryConfiguration(projectId: string): Promise<string | undefined>;
178
+ guessProjectConfiguration(projectId: string): Promise<string | undefined>;
179
+ fetchRepositoryConfiguration(cloneUrl: string): Promise<string | undefined>;
180
+ guessRepositoryConfiguration(cloneUrl: string): Promise<string | undefined>;
181
+ setProjectConfiguration(projectId: string, configString: string): Promise<void>;
182
+ updateProjectPartial(partialProject: PartialProject): Promise<void>;
183
+ setProjectEnvironmentVariable(projectId: string, name: string, value: string, censored: boolean): Promise<void>;
184
+ getProjectEnvironmentVariables(projectId: string): Promise<ProjectEnvVar[]>;
185
+ deleteProjectEnvironmentVariable(variableId: string): Promise<void>;
186
+
107
187
  // content service
108
- getContentBlobUploadUrl(name: string): Promise<string>
109
- getContentBlobDownloadUrl(name: string): Promise<string>
188
+ getContentBlobUploadUrl(name: string): Promise<string>;
189
+ getContentBlobDownloadUrl(name: string): Promise<string>;
110
190
 
111
191
  // Gitpod token
112
192
  getGitpodTokens(): Promise<GitpodToken[]>;
@@ -115,13 +195,19 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
115
195
 
116
196
  // misc
117
197
  sendFeedback(feedback: string): Promise<string | undefined>;
198
+ isGitHubAppEnabled(): Promise<boolean>;
118
199
  registerGithubApp(installationId: string): Promise<void>;
119
200
 
120
201
  /**
121
- * Stores a new snapshot for the given workspace and bucketId
202
+ * Stores a new snapshot for the given workspace and bucketId. Returns _before_ the actual snapshot is done. To wait for that, use `waitForSnapshot`.
122
203
  * @return the snapshot id
123
204
  */
124
205
  takeSnapshot(options: GitpodServer.TakeSnapshotOptions): Promise<string>;
206
+ /**
207
+ *
208
+ * @param snapshotId
209
+ */
210
+ waitForSnapshot(snapshotId: string): Promise<void>;
125
211
 
126
212
  /**
127
213
  * Returns the list of snapshots that exist for a workspace.
@@ -138,51 +224,168 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
138
224
  */
139
225
  getLayout(workspaceId: string): Promise<string | undefined>;
140
226
 
227
+ guessGitTokenScopes(params: GuessGitTokenScopesParams): Promise<GuessedGitTokenScopes>;
228
+
229
+ /**
230
+ * gitpod.io concerns
231
+ */
232
+ isStudent(): Promise<boolean>;
233
+ /**
234
+ *
235
+ */
236
+ getAccountStatement(options: GitpodServer.GetAccountStatementOptions): Promise<AccountStatement | undefined>;
237
+ getRemainingUsageHours(): Promise<number>;
238
+
141
239
  /**
142
- * @param params
143
- * @returns promise resolves to an URL to be used for the upload
240
+ *
144
241
  */
145
- preparePluginUpload(params: PreparePluginUploadParams): Promise<string>
146
- resolvePlugins(workspaceId: string, params: ResolvePluginsParams): Promise<ResolvedPlugins>;
147
- installUserPlugins(params: InstallPluginsParams): Promise<boolean>;
148
- uninstallUserPlugin(params: UninstallPluginParams): Promise<boolean>;
242
+ getChargebeeSiteId(): Promise<string>;
243
+ createPortalSession(): Promise<{}>;
244
+ createTeamPortalSession(teamId: string): Promise<{}>;
245
+ checkout(planId: string, planQuantity?: number): Promise<{}>;
246
+ teamCheckout(teamId: string, planId: string): Promise<{}>;
247
+ getAvailableCoupons(): Promise<PlanCoupon[]>;
248
+ getAppliedCoupons(): Promise<PlanCoupon[]>;
249
+
250
+ getShowPaymentUI(): Promise<boolean>;
251
+ isChargebeeCustomer(): Promise<boolean>;
252
+
253
+ subscriptionUpgradeTo(subscriptionId: string, chargebeePlanId: string): Promise<void>;
254
+ subscriptionDowngradeTo(subscriptionId: string, chargebeePlanId: string): Promise<void>;
255
+ subscriptionCancel(subscriptionId: string): Promise<void>;
256
+ subscriptionCancelDowngrade(subscriptionId: string): Promise<void>;
257
+
258
+ getTeamSubscription(teamId: string): Promise<TeamSubscription2 | undefined>;
259
+ tsGet(): Promise<TeamSubscription[]>;
260
+ tsGetSlots(): Promise<TeamSubscriptionSlotResolved[]>;
261
+ tsGetUnassignedSlot(teamSubscriptionId: string): Promise<TeamSubscriptionSlot | undefined>;
262
+ tsAddSlots(teamSubscriptionId: string, quantity: number): Promise<void>;
263
+ tsAssignSlot(
264
+ teamSubscriptionId: string,
265
+ teamSubscriptionSlotId: string,
266
+ identityStr: string | undefined,
267
+ ): Promise<void>;
268
+ tsReassignSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string, newIdentityStr: string): Promise<void>;
269
+ tsDeactivateSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string): Promise<void>;
270
+ tsReactivateSlot(teamSubscriptionId: string, teamSubscriptionSlotId: string): Promise<void>;
271
+
272
+ getGithubUpgradeUrls(): Promise<GithubUpgradeURL[]>;
273
+
274
+ getStripePublishableKey(): Promise<string>;
275
+ getStripeSetupIntentClientSecret(): Promise<string>;
276
+ findStripeCustomerIdForTeam(teamId: string): Promise<string | undefined>;
277
+ subscribeTeamToStripe(teamId: string, setupIntentId: string, currency: Currency): Promise<void>;
278
+ getStripePortalUrlForTeam(teamId: string): Promise<string>;
279
+
280
+ /**
281
+ * Analytics
282
+ */
283
+ trackEvent(event: RemoteTrackMessage): Promise<void>;
284
+ trackLocation(event: RemotePageMessage): Promise<void>;
285
+ identifyUser(event: RemoteIdentifyMessage): Promise<void>;
149
286
  }
150
287
 
151
- export const WorkspaceTimeoutValues = ["30m", "60m", "180m"] as const;
288
+ export interface RateLimiterError {
289
+ method?: string;
152
290
 
153
- export const createServiceMock = function <C extends GitpodClient, S extends GitpodServer>(methods: Partial<JsonRpcProxy<S>>): GitpodServiceImpl<C, S> {
154
- return new GitpodServiceImpl<C, S>(createServerMock(methods));
291
+ /**
292
+ * Retry after this many seconds, earliest.
293
+ * cmp.: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
294
+ */
295
+ retryAfter: number;
296
+ }
297
+
298
+ export interface CreateProjectParams {
299
+ name: string;
300
+ slug?: string;
301
+ account: string;
302
+ provider: string;
303
+ cloneUrl: string;
304
+ teamId?: string;
305
+ userId?: string;
306
+ appInstallationId: string;
155
307
  }
308
+ export interface FindPrebuildsParams {
309
+ projectId: string;
310
+ branch?: string;
311
+ latest?: boolean;
312
+ prebuildId?: string;
313
+ // default: 30
314
+ limit?: number;
315
+ }
316
+ export interface GetProviderRepositoriesParams {
317
+ provider: string;
318
+ hints?: { installationId: string } | object;
319
+ }
320
+ export interface ProviderRepository {
321
+ name: string;
322
+ path?: string;
323
+ account: string;
324
+ accountAvatarUrl: string;
325
+ cloneUrl: string;
326
+ updatedAt?: string;
327
+ installationId?: number;
328
+ installationUpdatedAt?: string;
329
+
330
+ inUse?: { userName: string };
331
+ }
332
+
333
+ export interface ClientHeaderFields {
334
+ ip?: string;
335
+ userAgent?: string;
336
+ dnt?: string;
337
+ clientRegion?: string;
338
+ }
339
+
340
+ export const WORKSPACE_TIMEOUT_DEFAULT_SHORT = "short";
341
+ export const WORKSPACE_TIMEOUT_DEFAULT_LONG = "long";
342
+ export const WORKSPACE_TIMEOUT_EXTENDED = "extended";
343
+ export const WORKSPACE_TIMEOUT_EXTENDED_ALT = "180m"; // for backwards compatibility since the IDE uses this
344
+ export const WorkspaceTimeoutValues = [
345
+ WORKSPACE_TIMEOUT_DEFAULT_SHORT,
346
+ WORKSPACE_TIMEOUT_DEFAULT_LONG,
347
+ WORKSPACE_TIMEOUT_EXTENDED,
348
+ WORKSPACE_TIMEOUT_EXTENDED_ALT,
349
+ ] as const;
350
+
351
+ export const createServiceMock = function <C extends GitpodClient, S extends GitpodServer>(
352
+ methods: Partial<JsonRpcProxy<S>>,
353
+ ): GitpodServiceImpl<C, S> {
354
+ return new GitpodServiceImpl<C, S>(createServerMock(methods));
355
+ };
156
356
 
157
- export const createServerMock = function <C extends GitpodClient, S extends GitpodServer>(methods: Partial<JsonRpcProxy<S>>): JsonRpcProxy<S> {
158
- methods.setClient = methods.setClient || (() => { });
159
- methods.dispose = methods.dispose || (() => { });
357
+ export const createServerMock = function <C extends GitpodClient, S extends GitpodServer>(
358
+ methods: Partial<JsonRpcProxy<S>>,
359
+ ): JsonRpcProxy<S> {
360
+ methods.setClient = methods.setClient || (() => {});
361
+ methods.dispose = methods.dispose || (() => {});
160
362
  return new Proxy<JsonRpcProxy<S>>(methods as any as JsonRpcProxy<S>, {
363
+ // @ts-ignore
161
364
  get: (target: S, property: keyof S) => {
162
365
  const result = target[property];
163
366
  if (!result) {
164
367
  throw new Error(`Method ${property} not implemented`);
165
368
  }
166
369
  return result;
167
- }
370
+ },
168
371
  });
169
- }
372
+ };
170
373
 
171
374
  type WorkspaceTimeoutDurationTuple = typeof WorkspaceTimeoutValues;
172
375
  export type WorkspaceTimeoutDuration = WorkspaceTimeoutDurationTuple[number];
173
376
 
174
377
  export interface SetWorkspaceTimeoutResult {
175
- resetTimeoutOnWorkspaces: string[]
378
+ resetTimeoutOnWorkspaces: string[];
176
379
  }
177
380
 
178
381
  export interface GetWorkspaceTimeoutResult {
179
- duration: WorkspaceTimeoutDuration
180
- canChange: boolean
382
+ duration: WorkspaceTimeoutDuration;
383
+ canChange: boolean;
181
384
  }
182
385
 
183
386
  export interface StartWorkspaceResult {
184
- instanceID: string
185
- workspaceURL?: string
387
+ instanceID: string;
388
+ workspaceURL?: string;
186
389
  }
187
390
 
188
391
  export namespace GitpodServer {
@@ -190,6 +393,8 @@ export namespace GitpodServer {
190
393
  limit?: number;
191
394
  searchString?: string;
192
395
  pinnedOnly?: boolean;
396
+ projectId?: string | string[];
397
+ includeWithoutProject?: boolean;
193
398
  }
194
399
  export interface GetAccountStatementOptions {
195
400
  date?: string;
@@ -197,6 +402,7 @@ export namespace GitpodServer {
197
402
  export interface CreateWorkspaceOptions {
198
403
  contextUrl: string;
199
404
  mode?: CreateWorkspaceMode;
405
+ forceDefaultConfig?: boolean;
200
406
  }
201
407
  export interface StartWorkspaceOptions {
202
408
  forceDefaultImage: boolean;
@@ -204,13 +410,8 @@ export namespace GitpodServer {
204
410
  export interface TakeSnapshotOptions {
205
411
  workspaceId: string;
206
412
  layoutData?: string;
207
- }
208
- export interface GetUserMessagesOptions {
209
- readonly releaseNotes?: boolean;
210
- readonly workspaceInstanceId: string;
211
- }
212
- export interface UpdateUserMessagesOptions {
213
- readonly messageIds: string[];
413
+ /* this is here to enable backwards-compatibility and untangling rollout between workspace, IDE and meta */
414
+ dontWait?: boolean;
214
415
  }
215
416
  export interface GetUserStorageResourceOptions {
216
417
  readonly uri: string;
@@ -228,23 +429,23 @@ export namespace GitpodServer {
228
429
  readonly roundTripTime?: number;
229
430
  }
230
431
  export interface UpdateOwnAuthProviderParams {
231
- readonly entry: AuthProviderEntry.UpdateEntry | AuthProviderEntry.NewEntry
432
+ readonly entry: AuthProviderEntry.UpdateEntry | AuthProviderEntry.NewEntry;
232
433
  }
233
434
  export interface DeleteOwnAuthProviderParams {
234
- readonly id: string
435
+ readonly id: string;
235
436
  }
236
437
  export type AdmissionLevel = "owner" | "everyone";
237
438
  export type PinAction = "pin" | "unpin" | "toggle";
238
439
  export interface GenerateNewGitpodTokenOptions {
239
- name?: string
240
- type: GitpodTokenType
241
- scopes?: string[]
440
+ name?: string;
441
+ type: GitpodTokenType;
442
+ scopes?: string[];
242
443
  }
243
444
  }
244
445
 
245
- export const GitpodServerPath = '/gitpod';
446
+ export const GitpodServerPath = "/gitpod";
246
447
 
247
- export const GitpodServerProxy = Symbol('GitpodServerProxy');
448
+ export const GitpodServerProxy = Symbol("GitpodServerProxy");
248
449
  export type GitpodServerProxy<S extends GitpodServer> = JsonRpcProxy<S>;
249
450
 
250
451
  export class GitpodCompositeClient<Client extends GitpodClient> implements GitpodClient {
@@ -252,12 +453,14 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
252
453
 
253
454
  public registerClient(client: Partial<Client>): Disposable {
254
455
  this.clients.push(client);
255
- const index = this.clients.length;
256
456
  return {
257
457
  dispose: () => {
258
- this.clients.slice(index, 1);
259
- }
260
- }
458
+ const index = this.clients.indexOf(client);
459
+ if (index > -1) {
460
+ this.clients.splice(index, 1);
461
+ }
462
+ },
463
+ };
261
464
  }
262
465
 
263
466
  onInstanceUpdate(instance: WorkspaceInstance): void {
@@ -266,31 +469,34 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
266
469
  try {
267
470
  client.onInstanceUpdate(instance);
268
471
  } catch (error) {
269
- console.error(error)
472
+ console.error(error);
270
473
  }
271
474
  }
272
475
  }
273
476
  }
274
477
 
275
- onWorkspaceImageBuildLogs(info: WorkspaceImageBuild.StateInfo, content: WorkspaceImageBuild.LogContent | undefined): void {
478
+ onPrebuildUpdate(update: PrebuildWithStatus): void {
276
479
  for (const client of this.clients) {
277
- if (client.onWorkspaceImageBuildLogs) {
480
+ if (client.onPrebuildUpdate) {
278
481
  try {
279
- client.onWorkspaceImageBuildLogs(info, content);
482
+ client.onPrebuildUpdate(update);
280
483
  } catch (error) {
281
- console.error(error)
484
+ console.error(error);
282
485
  }
283
486
  }
284
487
  }
285
488
  }
286
489
 
287
- onHeadlessWorkspaceLogs(evt: HeadlessLogEvent): void {
490
+ onWorkspaceImageBuildLogs(
491
+ info: WorkspaceImageBuild.StateInfo,
492
+ content: WorkspaceImageBuild.LogContent | undefined,
493
+ ): void {
288
494
  for (const client of this.clients) {
289
- if (client.onHeadlessWorkspaceLogs) {
495
+ if (client.onWorkspaceImageBuildLogs) {
290
496
  try {
291
- client.onHeadlessWorkspaceLogs(evt);
497
+ client.onWorkspaceImageBuildLogs(info, content);
292
498
  } catch (error) {
293
- console.error(error)
499
+ console.error(error);
294
500
  }
295
501
  }
296
502
  }
@@ -302,7 +508,7 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
302
508
  try {
303
509
  client.notifyDidOpenConnection();
304
510
  } catch (error) {
305
- console.error(error)
511
+ console.error(error);
306
512
  }
307
513
  }
308
514
  }
@@ -314,64 +520,73 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
314
520
  try {
315
521
  client.notifyDidCloseConnection();
316
522
  } catch (error) {
317
- console.error(error)
523
+ console.error(error);
318
524
  }
319
525
  }
320
526
  }
321
527
  }
322
528
 
529
+ onCreditAlert(creditAlert: CreditAlert): void {
530
+ for (const client of this.clients) {
531
+ if (client.onCreditAlert) {
532
+ try {
533
+ client.onCreditAlert(creditAlert);
534
+ } catch (error) {
535
+ console.error(error);
536
+ }
537
+ }
538
+ }
539
+ }
323
540
  }
324
541
 
325
542
  export type GitpodService = GitpodServiceImpl<GitpodClient, GitpodServer>;
326
543
 
327
- const hasWindow = (typeof window !== 'undefined');
544
+ const hasWindow = typeof window !== "undefined";
328
545
  const phasesOrder: Record<WorkspaceInstancePhase, number> = {
329
546
  unknown: 0,
330
547
  preparing: 1,
331
- pending: 2,
332
- creating: 3,
333
- initializing: 4,
334
- running: 5,
335
- interrupted: 6,
336
- stopping: 7,
337
- stopped: 8
548
+ building: 2,
549
+ pending: 3,
550
+ creating: 4,
551
+ initializing: 5,
552
+ running: 6,
553
+ interrupted: 7,
554
+ stopping: 8,
555
+ stopped: 9,
338
556
  };
339
557
  export class WorkspaceInstanceUpdateListener {
340
558
  private readonly onDidChangeEmitter = new Emitter<void>();
341
559
  readonly onDidChange = this.onDidChangeEmitter.event;
342
560
 
343
- private source: 'sync| 'update' = 'sync';
561
+ private source: "sync" | "update" = "sync";
344
562
 
345
563
  get info(): WorkspaceInfo {
346
564
  return this._info;
347
565
  }
348
566
 
349
- constructor(
350
- private readonly service: GitpodService,
351
- private _info: WorkspaceInfo
352
- ) {
567
+ constructor(private readonly service: GitpodService, private _info: WorkspaceInfo) {
353
568
  service.registerClient({
354
- onInstanceUpdate: instance => {
569
+ onInstanceUpdate: (instance) => {
355
570
  if (this.isOutOfOrder(instance)) {
356
571
  return;
357
572
  }
358
573
  this.cancelSync();
359
574
  this._info.latestInstance = instance;
360
- this.source = 'update';
575
+ this.source = "update";
361
576
  this.onDidChangeEmitter.fire(undefined);
362
577
  },
363
578
  notifyDidOpenConnection: () => {
364
579
  this.sync();
365
- }
580
+ },
366
581
  });
367
582
  if (hasWindow) {
368
583
  // learn about page lifecycle here: https://developers.google.com/web/updates/2018/07/page-lifecycle-api
369
- window.document.addEventListener('visibilitychange', async () => {
370
- if (window.document.visibilityState === 'visible') {
584
+ window.document.addEventListener("visibilitychange", async () => {
585
+ if (window.document.visibilityState === "visible") {
371
586
  this.sync();
372
587
  }
373
588
  });
374
- window.addEventListener('pageshow', e => {
589
+ window.addEventListener("pageshow", (e) => {
375
590
  if (e.persisted) {
376
591
  this.sync();
377
592
  }
@@ -399,12 +614,12 @@ export class WorkspaceInstanceUpdateListener {
399
614
  return;
400
615
  }
401
616
  this._info = info;
402
- this.source = 'sync';
617
+ this.source = "sync";
403
618
  this.onDidChangeEmitter.fire(undefined);
404
619
  } catch (e) {
405
- console.error('failed to sync workspace instance:', e)
620
+ console.error("failed to sync workspace instance:", e);
406
621
  }
407
- })
622
+ });
408
623
  }
409
624
  private cancelSync(): void {
410
625
  if (this.syncTokenSource) {
@@ -421,7 +636,7 @@ export class WorkspaceInstanceUpdateListener {
421
636
  if (instance.workspaceId !== this._info.workspace.id) {
422
637
  return true;
423
638
  }
424
- if (this.source === 'update') {
639
+ if (this.source === "update") {
425
640
  return false;
426
641
  }
427
642
  if (instance.id !== this.info.latestInstance?.id) {
@@ -429,14 +644,16 @@ export class WorkspaceInstanceUpdateListener {
429
644
  }
430
645
  return phasesOrder[instance.status.phase] < phasesOrder[this.info.latestInstance.status.phase];
431
646
  }
647
+ }
432
648
 
649
+ export interface GitpodServiceOptions {
650
+ onReconnect?: () => void | Promise<void>;
433
651
  }
434
652
 
435
653
  export class GitpodServiceImpl<Client extends GitpodClient, Server extends GitpodServer> {
436
-
437
654
  private readonly compositeClient = new GitpodCompositeClient<Client>();
438
655
 
439
- constructor(public readonly server: JsonRpcProxy<Server>) {
656
+ constructor(public readonly server: JsonRpcProxy<Server>, private options?: GitpodServiceOptions) {
440
657
  server.setClient(this.compositeClient);
441
658
  server.onDidOpenConnection(() => this.compositeClient.notifyDidOpenConnection());
442
659
  server.onDidCloseConnection(() => this.compositeClient.notifyDidCloseConnection());
@@ -448,7 +665,8 @@ export class GitpodServiceImpl<Client extends GitpodClient, Server extends Gitpo
448
665
 
449
666
  private readonly instanceListeners = new Map<string, Promise<WorkspaceInstanceUpdateListener>>();
450
667
  listenToInstance(workspaceId: string): Promise<WorkspaceInstanceUpdateListener> {
451
- const listener = this.instanceListeners.get(workspaceId) ||
668
+ const listener =
669
+ this.instanceListeners.get(workspaceId) ||
452
670
  (async () => {
453
671
  const info = await this.server.getWorkspace(workspaceId);
454
672
  return new WorkspaceInstanceUpdateListener(this, info);
@@ -456,13 +674,33 @@ export class GitpodServiceImpl<Client extends GitpodClient, Server extends Gitpo
456
674
  this.instanceListeners.set(workspaceId, listener);
457
675
  return listener;
458
676
  }
677
+
678
+ async reconnect(): Promise<void> {
679
+ if (this.options?.onReconnect) {
680
+ await this.options.onReconnect();
681
+ }
682
+ }
459
683
  }
460
684
 
461
- export function createGitpodService<C extends GitpodClient, S extends GitpodServer>(serverUrl: string) {
462
- const url = new GitpodHostUrl(serverUrl)
463
- .asWebsocket()
464
- .withApi({ pathname: GitpodServerPath });
685
+ export function createGitpodService<C extends GitpodClient, S extends GitpodServer>(
686
+ serverUrl: string | Promise<string>,
687
+ ) {
688
+ const toWsUrl = (serverUrl: string) => {
689
+ return new GitpodHostUrl(serverUrl).asWebsocket().withApi({ pathname: GitpodServerPath }).toString();
690
+ };
691
+ let url: string | Promise<string>;
692
+ if (typeof serverUrl === "string") {
693
+ url = toWsUrl(serverUrl);
694
+ } else {
695
+ url = serverUrl.then((url) => toWsUrl(url));
696
+ }
697
+
465
698
  const connectionProvider = new WebSocketConnectionProvider();
466
- const gitpodServer = connectionProvider.createProxy<S>(url.toString());
467
- return new GitpodServiceImpl<C, S>(gitpodServer);
468
- }
699
+ let onReconnect = () => {};
700
+ const gitpodServer = connectionProvider.createProxy<S>(url, undefined, {
701
+ onListening: (socket) => {
702
+ onReconnect = () => socket.reconnect();
703
+ },
704
+ });
705
+ return new GitpodServiceImpl<C, S>(gitpodServer, { onReconnect });
706
+ }