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