@gitpod/gitpod-protocol 0.1.5-v0.6.0-beta4 → 0.1.5-vn-6525.75

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