@gitpod/gitpod-protocol 0.1.5-patch-1.2 → 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 (349) hide show
  1. package/data/gitpod-schema.json +53 -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 +32 -4
  7. package/lib/admin-protocol.d.ts.map +1 -1
  8. package/lib/admin-protocol.js +15 -0
  9. package/lib/admin-protocol.js.map +1 -1
  10. package/lib/analytics.d.ts +44 -0
  11. package/lib/analytics.d.ts.map +1 -0
  12. package/lib/analytics.js +10 -0
  13. package/lib/analytics.js.map +1 -0
  14. package/lib/auth.d.ts.map +1 -1
  15. package/lib/context-url.d.ts +31 -0
  16. package/lib/context-url.d.ts.map +1 -0
  17. package/lib/context-url.js +102 -0
  18. package/lib/context-url.js.map +1 -0
  19. package/lib/context-url.spec.d.ts +14 -0
  20. package/lib/context-url.spec.d.ts.map +1 -0
  21. package/lib/context-url.spec.js +109 -0
  22. package/lib/context-url.spec.js.map +1 -0
  23. package/lib/email-protocol.d.ts +1 -2
  24. package/lib/email-protocol.d.ts.map +1 -1
  25. package/lib/email-protocol.js +4 -4
  26. package/lib/email-protocol.js.map +1 -1
  27. package/lib/encryption/container-module.d.ts.map +1 -1
  28. package/lib/encryption/container-module.js +5 -4
  29. package/lib/encryption/container-module.js.map +1 -1
  30. package/lib/encryption/encryption-engine.d.ts.map +1 -1
  31. package/lib/encryption/encryption-engine.js +25 -26
  32. package/lib/encryption/encryption-engine.js.map +1 -1
  33. package/lib/encryption/encryption-engine.spec.d.ts.map +1 -1
  34. package/lib/encryption/encryption-engine.spec.js +29 -37
  35. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  36. package/lib/encryption/encryption-service.d.ts.map +1 -1
  37. package/lib/encryption/encryption-service.js +30 -44
  38. package/lib/encryption/encryption-service.js.map +1 -1
  39. package/lib/encryption/key-provider.d.ts.map +1 -1
  40. package/lib/encryption/key-provider.js +31 -38
  41. package/lib/encryption/key-provider.js.map +1 -1
  42. package/lib/env.d.ts +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 +165 -32
  52. package/lib/gitpod-service.d.ts.map +1 -1
  53. package/lib/gitpod-service.js +176 -265
  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 +4 -1
  87. package/lib/messaging/error.d.ts.map +1 -1
  88. package/lib/messaging/error.js +8 -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 +18 -0
  106. package/lib/payment-protocol.d.ts.map +1 -0
  107. package/lib/payment-protocol.js +13 -0
  108. package/lib/payment-protocol.js.map +1 -0
  109. package/lib/permission.d.ts +10 -3
  110. package/lib/permission.d.ts.map +1 -1
  111. package/lib/permission.js +41 -31
  112. package/lib/permission.js.map +1 -1
  113. package/lib/plans.d.ts +210 -0
  114. package/lib/plans.d.ts.map +1 -0
  115. package/lib/plans.js +605 -0
  116. package/lib/plans.js.map +1 -0
  117. package/lib/protocol.d.ts +163 -82
  118. package/lib/protocol.d.ts.map +1 -1
  119. package/lib/protocol.js +180 -199
  120. package/lib/protocol.js.map +1 -1
  121. package/lib/snapshot-url.d.ts +14 -0
  122. package/lib/snapshot-url.d.ts.map +1 -0
  123. package/lib/snapshot-url.js +26 -0
  124. package/lib/snapshot-url.js.map +1 -0
  125. package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
  126. package/lib/snapshot-url.spec.d.ts.map +1 -0
  127. package/lib/snapshot-url.spec.js +41 -0
  128. package/lib/snapshot-url.spec.js.map +1 -0
  129. package/lib/team-subscription-protocol.d.ts +75 -0
  130. package/lib/team-subscription-protocol.d.ts.map +1 -0
  131. package/lib/team-subscription-protocol.js +63 -0
  132. package/lib/team-subscription-protocol.js.map +1 -0
  133. package/lib/teams-projects-protocol.d.ts +113 -0
  134. package/lib/teams-projects-protocol.d.ts.map +1 -0
  135. package/lib/teams-projects-protocol.js +30 -0
  136. package/lib/teams-projects-protocol.js.map +1 -0
  137. package/lib/typings/globals.d.ts +2 -2
  138. package/lib/typings/globals.d.ts.map +1 -1
  139. package/lib/util/analytics.d.ts +8 -0
  140. package/lib/util/analytics.d.ts.map +1 -0
  141. package/lib/util/analytics.js +88 -0
  142. package/lib/util/analytics.js.map +1 -0
  143. package/lib/util/async-iterator.d.ts.map +1 -1
  144. package/lib/util/async-iterator.js +57 -135
  145. package/lib/util/async-iterator.js.map +1 -1
  146. package/lib/util/cancelable.js +17 -59
  147. package/lib/util/cancelable.js.map +1 -1
  148. package/lib/util/date-time.js +11 -11
  149. package/lib/util/date-time.js.map +1 -1
  150. package/lib/util/deferred.js +10 -12
  151. package/lib/util/deferred.js.map +1 -1
  152. package/lib/util/disposable.d.ts.map +1 -1
  153. package/lib/util/disposable.js +27 -40
  154. package/lib/util/disposable.js.map +1 -1
  155. package/lib/util/event.d.ts.map +1 -1
  156. package/lib/util/event.js +63 -77
  157. package/lib/util/event.js.map +1 -1
  158. package/lib/util/garbage-collected-cache.d.ts +1 -0
  159. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  160. package/lib/util/garbage-collected-cache.js +27 -47
  161. package/lib/util/garbage-collected-cache.js.map +1 -1
  162. package/lib/util/generate-workspace-id.d.ts +1 -1
  163. package/lib/util/generate-workspace-id.d.ts.map +1 -1
  164. package/lib/util/generate-workspace-id.js +460 -497
  165. package/lib/util/generate-workspace-id.js.map +1 -1
  166. package/lib/util/generate-workspace-id.spec.js +61 -78
  167. package/lib/util/generate-workspace-id.spec.js.map +1 -1
  168. package/lib/util/gitpod-cookie.d.ts +20 -0
  169. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  170. package/lib/util/gitpod-cookie.js +41 -0
  171. package/lib/util/gitpod-cookie.js.map +1 -0
  172. package/lib/util/gitpod-host-url.d.ts +1 -2
  173. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  174. package/lib/util/gitpod-host-url.js +108 -109
  175. package/lib/util/gitpod-host-url.js.map +1 -1
  176. package/lib/util/gitpod-host-url.spec.d.ts +7 -1
  177. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  178. package/lib/util/gitpod-host-url.spec.js +113 -31
  179. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  180. package/lib/util/grpc.d.ts +15 -0
  181. package/lib/util/grpc.d.ts.map +1 -0
  182. package/lib/util/grpc.js +18 -0
  183. package/lib/util/grpc.js.map +1 -0
  184. package/lib/util/jaeger-client-types.d.ts +68 -0
  185. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  186. package/lib/{theia-plugins.js → util/jaeger-client-types.js} +1 -1
  187. package/lib/util/jaeger-client-types.js.map +1 -0
  188. package/lib/util/logging.d.ts +49 -33
  189. package/lib/util/logging.d.ts.map +1 -1
  190. package/lib/util/logging.js +125 -129
  191. package/lib/util/logging.js.map +1 -1
  192. package/lib/util/make-link.js +5 -5
  193. package/lib/util/make-link.js.map +1 -1
  194. package/lib/util/parse-workspace-id.d.ts +10 -0
  195. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  196. package/lib/util/parse-workspace-id.js +31 -7
  197. package/lib/util/parse-workspace-id.js.map +1 -1
  198. package/lib/util/parse-workspace-id.spec.d.ts +4 -0
  199. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  200. package/lib/util/parse-workspace-id.spec.js +123 -84
  201. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  202. package/lib/util/queue.js +16 -55
  203. package/lib/util/queue.js.map +1 -1
  204. package/lib/util/queue.spec.js +147 -288
  205. package/lib/util/queue.spec.js.map +1 -1
  206. package/lib/util/repeat.d.ts +15 -0
  207. package/lib/util/repeat.d.ts.map +1 -0
  208. package/lib/util/repeat.js +55 -0
  209. package/lib/util/repeat.js.map +1 -0
  210. package/lib/util/semaphore.d.ts.map +1 -1
  211. package/lib/util/semaphore.js +15 -46
  212. package/lib/util/semaphore.js.map +1 -1
  213. package/lib/util/skip-if.d.ts.map +1 -1
  214. package/lib/util/skip-if.js +6 -6
  215. package/lib/util/skip-if.js.map +1 -1
  216. package/lib/util/timeutil.d.ts.map +1 -1
  217. package/lib/util/timeutil.js +28 -16
  218. package/lib/util/timeutil.js.map +1 -1
  219. package/lib/util/timeutil.spec.d.ts.map +1 -1
  220. package/lib/util/timeutil.spec.js +21 -24
  221. package/lib/util/timeutil.spec.js.map +1 -1
  222. package/lib/util/tracing.d.ts +52 -6
  223. package/lib/util/tracing.d.ts.map +1 -1
  224. package/lib/util/tracing.js +199 -64
  225. package/lib/util/tracing.js.map +1 -1
  226. package/lib/util/tracing.spec.d.ts +7 -0
  227. package/lib/util/tracing.spec.d.ts.map +1 -0
  228. package/lib/util/tracing.spec.js +121 -0
  229. package/lib/util/tracing.spec.js.map +1 -0
  230. package/lib/util/workspace-port-authentication.d.ts +7 -7
  231. package/lib/util/workspace-port-authentication.d.ts.map +1 -1
  232. package/lib/util/workspace-port-authentication.js +10 -12
  233. package/lib/util/workspace-port-authentication.js.map +1 -1
  234. package/lib/workspace-cluster.d.ts +76 -0
  235. package/lib/workspace-cluster.d.ts.map +1 -0
  236. package/lib/workspace-cluster.js +31 -0
  237. package/lib/workspace-cluster.js.map +1 -0
  238. package/lib/workspace-instance.d.ts +26 -4
  239. package/lib/workspace-instance.d.ts.map +1 -1
  240. package/lib/wsready.d.ts +1 -1
  241. package/lib/wsready.d.ts.map +1 -1
  242. package/lib/wsready.js +2 -2
  243. package/package.json +31 -17
  244. package/pkg-yarn.lock +17 -9
  245. package/provenance-bundle.jsonl +2 -0
  246. package/src/accounting-protocol.ts +231 -0
  247. package/src/admin-protocol.ts +70 -19
  248. package/src/analytics.ts +52 -0
  249. package/src/auth.ts +2 -2
  250. package/src/context-url.spec.ts +67 -0
  251. package/src/context-url.ts +109 -0
  252. package/src/email-protocol.ts +5 -7
  253. package/src/encryption/container-module.ts +2 -3
  254. package/src/encryption/encryption-engine.spec.ts +9 -8
  255. package/src/encryption/encryption-engine.ts +14 -14
  256. package/src/encryption/encryption-service.ts +4 -5
  257. package/src/encryption/key-provider.ts +16 -19
  258. package/src/env.ts +18 -18
  259. package/src/gitpod-file-parser.spec.ts +55 -61
  260. package/src/gitpod-file-parser.ts +16 -17
  261. package/src/gitpod-service.ts +315 -103
  262. package/src/headless-workspace-log.ts +12 -14
  263. package/src/ide-frontend-service.ts +2 -2
  264. package/src/ide-protocol.ts +119 -0
  265. package/src/index.ts +16 -10
  266. package/src/installation-admin-protocol.ts +42 -0
  267. package/src/license-protocol.ts +5 -6
  268. package/src/messaging/browser/connection.ts +197 -18
  269. package/src/messaging/browser/window-connection.ts +39 -29
  270. package/src/messaging/client-call-metrics.ts +96 -0
  271. package/src/messaging/error.ts +12 -5
  272. package/src/messaging/handler.ts +13 -1
  273. package/src/messaging/node/connection.ts +23 -70
  274. package/src/messaging/proxy-factory.ts +35 -34
  275. package/src/oss-allowlist.ts +15 -0
  276. package/src/payment-protocol.ts +20 -0
  277. package/src/permission.ts +42 -33
  278. package/src/plans.ts +679 -0
  279. package/src/protocol.ts +378 -273
  280. package/src/snapshot-url.spec.ts +27 -0
  281. package/src/snapshot-url.ts +27 -0
  282. package/src/team-subscription-protocol.ts +123 -0
  283. package/src/teams-projects-protocol.ts +147 -0
  284. package/src/typings/globals.ts +4 -4
  285. package/src/util/analytics.ts +109 -0
  286. package/src/util/async-iterator.ts +4 -5
  287. package/src/util/cancelable.ts +3 -3
  288. package/src/util/date-time.ts +8 -8
  289. package/src/util/deferred.ts +6 -6
  290. package/src/util/disposable.ts +3 -6
  291. package/src/util/event.ts +9 -11
  292. package/src/util/garbage-collected-cache.ts +11 -8
  293. package/src/util/generate-workspace-id.spec.ts +29 -9
  294. package/src/util/generate-workspace-id.ts +458 -438
  295. package/src/util/gitpod-cookie.ts +38 -0
  296. package/src/util/gitpod-host-url.spec.ts +59 -8
  297. package/src/util/gitpod-host-url.ts +52 -40
  298. package/src/util/grpc.ts +15 -0
  299. package/src/util/jaeger-client-types.ts +102 -0
  300. package/src/util/logging.ts +145 -71
  301. package/src/util/make-link.ts +6 -7
  302. package/src/util/parse-workspace-id.spec.ts +37 -8
  303. package/src/util/parse-workspace-id.ts +32 -7
  304. package/src/util/queue.spec.ts +28 -26
  305. package/src/util/repeat.ts +45 -0
  306. package/src/util/semaphore.ts +6 -8
  307. package/src/util/skip-if.ts +10 -7
  308. package/src/util/timeutil.spec.ts +14 -15
  309. package/src/util/timeutil.ts +19 -15
  310. package/src/util/tracing.spec.ts +88 -0
  311. package/src/util/tracing.ts +202 -31
  312. package/src/util/workspace-port-authentication.ts +10 -13
  313. package/src/workspace-cluster.ts +107 -0
  314. package/src/workspace-instance.ts +66 -30
  315. package/src/wsready.ts +3 -3
  316. package/data/builtin-theia-plugins.json +0 -372
  317. package/lib/messaging/connection-error-handler.d.ts +0 -27
  318. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  319. package/lib/messaging/connection-error-handler.js +0 -46
  320. package/lib/messaging/connection-error-handler.js.map +0 -1
  321. package/lib/theia-plugins.d.ts +0 -11
  322. package/lib/theia-plugins.d.ts.map +0 -1
  323. package/lib/theia-plugins.js.map +0 -1
  324. package/lib/util/context-url.d.ts +0 -13
  325. package/lib/util/context-url.d.ts.map +0 -1
  326. package/lib/util/context-url.js +0 -26
  327. package/lib/util/context-url.js.map +0 -1
  328. package/lib/util/context-url.spec.d.ts +0 -10
  329. package/lib/util/context-url.spec.d.ts.map +0 -1
  330. package/lib/util/context-url.spec.js +0 -52
  331. package/lib/util/context-url.spec.js.map +0 -1
  332. package/lib/util/repeater.d.ts +0 -22
  333. package/lib/util/repeater.d.ts.map +0 -1
  334. package/lib/util/repeater.js +0 -118
  335. package/lib/util/repeater.js.map +0 -1
  336. package/lib/util/safe-promise.d.ts +0 -11
  337. package/lib/util/safe-promise.d.ts.map +0 -1
  338. package/lib/util/safe-promise.js +0 -34
  339. package/lib/util/safe-promise.js.map +0 -1
  340. package/lib/util/without.d.ts +0 -7
  341. package/lib/util/without.d.ts.map +0 -1
  342. package/lib/util/without.js.map +0 -1
  343. package/src/messaging/connection-error-handler.ts +0 -62
  344. package/src/theia-plugins.ts +0 -11
  345. package/src/util/context-url.spec.ts +0 -25
  346. package/src/util/context-url.ts +0 -23
  347. package/src/util/jaeger-client.d.ts +0 -105
  348. package/src/util/repeater.ts +0 -49
  349. 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,22 +132,55 @@ 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
+
107
181
  // content service
108
- getContentBlobUploadUrl(name: string): Promise<string>
109
- getContentBlobDownloadUrl(name: string): Promise<string>
182
+ getContentBlobUploadUrl(name: string): Promise<string>;
183
+ getContentBlobDownloadUrl(name: string): Promise<string>;
110
184
 
111
185
  // Gitpod token
112
186
  getGitpodTokens(): Promise<GitpodToken[]>;
@@ -118,10 +192,15 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
118
192
  registerGithubApp(installationId: string): Promise<void>;
119
193
 
120
194
  /**
121
- * 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`.
122
196
  * @return the snapshot id
123
197
  */
124
198
  takeSnapshot(options: GitpodServer.TakeSnapshotOptions): Promise<string>;
199
+ /**
200
+ *
201
+ * @param snapshotId
202
+ */
203
+ waitForSnapshot(snapshotId: string): Promise<void>;
125
204
 
126
205
  /**
127
206
  * Returns the list of snapshots that exist for a workspace.
@@ -138,51 +217,150 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
138
217
  */
139
218
  getLayout(workspaceId: string): Promise<string | undefined>;
140
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
+
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
+
141
275
  /**
142
- * @param params
143
- * @returns promise resolves to an URL to be used for the upload
276
+ * Retry after this many seconds, earliest.
277
+ * cmp.: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
144
278
  */
145
- preparePluginUpload(params: PreparePluginUploadParams): Promise<string>
146
- resolvePlugins(workspaceId: string, params: ResolvePluginsParams): Promise<ResolvedPlugins>;
147
- installUserPlugins(params: InstallPluginsParams): Promise<boolean>;
148
- uninstallUserPlugin(params: UninstallPluginParams): Promise<boolean>;
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;
149
322
  }
150
323
 
151
324
  export const WorkspaceTimeoutValues = ["30m", "60m", "180m"] as const;
152
325
 
153
- 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> {
154
329
  return new GitpodServiceImpl<C, S>(createServerMock(methods));
155
- }
330
+ };
156
331
 
157
- export const createServerMock = function <C extends GitpodClient, S extends GitpodServer>(methods: Partial<JsonRpcProxy<S>>): JsonRpcProxy<S> {
158
- methods.setClient = methods.setClient || (() => { });
159
- methods.dispose = methods.dispose || (() => { });
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 || (() => {});
160
337
  return new Proxy<JsonRpcProxy<S>>(methods as any as JsonRpcProxy<S>, {
338
+ // @ts-ignore
161
339
  get: (target: S, property: keyof S) => {
162
340
  const result = target[property];
163
341
  if (!result) {
164
342
  throw new Error(`Method ${property} not implemented`);
165
343
  }
166
344
  return result;
167
- }
345
+ },
168
346
  });
169
- }
347
+ };
170
348
 
171
349
  type WorkspaceTimeoutDurationTuple = typeof WorkspaceTimeoutValues;
172
350
  export type WorkspaceTimeoutDuration = WorkspaceTimeoutDurationTuple[number];
173
351
 
174
352
  export interface SetWorkspaceTimeoutResult {
175
- resetTimeoutOnWorkspaces: string[]
353
+ resetTimeoutOnWorkspaces: string[];
176
354
  }
177
355
 
178
356
  export interface GetWorkspaceTimeoutResult {
179
- duration: WorkspaceTimeoutDuration
180
- canChange: boolean
357
+ duration: WorkspaceTimeoutDuration;
358
+ canChange: boolean;
181
359
  }
182
360
 
183
361
  export interface StartWorkspaceResult {
184
- instanceID: string
185
- workspaceURL?: string
362
+ instanceID: string;
363
+ workspaceURL?: string;
186
364
  }
187
365
 
188
366
  export namespace GitpodServer {
@@ -190,6 +368,8 @@ export namespace GitpodServer {
190
368
  limit?: number;
191
369
  searchString?: string;
192
370
  pinnedOnly?: boolean;
371
+ projectId?: string | string[];
372
+ includeWithoutProject?: boolean;
193
373
  }
194
374
  export interface GetAccountStatementOptions {
195
375
  date?: string;
@@ -197,6 +377,7 @@ export namespace GitpodServer {
197
377
  export interface CreateWorkspaceOptions {
198
378
  contextUrl: string;
199
379
  mode?: CreateWorkspaceMode;
380
+ forceDefaultConfig?: boolean;
200
381
  }
201
382
  export interface StartWorkspaceOptions {
202
383
  forceDefaultImage: boolean;
@@ -204,13 +385,8 @@ export namespace GitpodServer {
204
385
  export interface TakeSnapshotOptions {
205
386
  workspaceId: string;
206
387
  layoutData?: string;
207
- }
208
- export interface GetUserMessagesOptions {
209
- readonly releaseNotes?: boolean;
210
- readonly workspaceInstanceId: string;
211
- }
212
- export interface UpdateUserMessagesOptions {
213
- readonly messageIds: string[];
388
+ /* this is here to enable backwards-compatibility and untangling rollout between workspace, IDE and meta */
389
+ dontWait?: boolean;
214
390
  }
215
391
  export interface GetUserStorageResourceOptions {
216
392
  readonly uri: string;
@@ -228,23 +404,23 @@ export namespace GitpodServer {
228
404
  readonly roundTripTime?: number;
229
405
  }
230
406
  export interface UpdateOwnAuthProviderParams {
231
- readonly entry: AuthProviderEntry.UpdateEntry | AuthProviderEntry.NewEntry
407
+ readonly entry: AuthProviderEntry.UpdateEntry | AuthProviderEntry.NewEntry;
232
408
  }
233
409
  export interface DeleteOwnAuthProviderParams {
234
- readonly id: string
410
+ readonly id: string;
235
411
  }
236
412
  export type AdmissionLevel = "owner" | "everyone";
237
413
  export type PinAction = "pin" | "unpin" | "toggle";
238
414
  export interface GenerateNewGitpodTokenOptions {
239
- name?: string
240
- type: GitpodTokenType
241
- scopes?: string[]
415
+ name?: string;
416
+ type: GitpodTokenType;
417
+ scopes?: string[];
242
418
  }
243
419
  }
244
420
 
245
- export const GitpodServerPath = '/gitpod';
421
+ export const GitpodServerPath = "/gitpod";
246
422
 
247
- export const GitpodServerProxy = Symbol('GitpodServerProxy');
423
+ export const GitpodServerProxy = Symbol("GitpodServerProxy");
248
424
  export type GitpodServerProxy<S extends GitpodServer> = JsonRpcProxy<S>;
249
425
 
250
426
  export class GitpodCompositeClient<Client extends GitpodClient> implements GitpodClient {
@@ -252,12 +428,14 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
252
428
 
253
429
  public registerClient(client: Partial<Client>): Disposable {
254
430
  this.clients.push(client);
255
- const index = this.clients.length;
256
431
  return {
257
432
  dispose: () => {
258
- this.clients.slice(index, 1);
259
- }
260
- }
433
+ const index = this.clients.indexOf(client);
434
+ if (index > -1) {
435
+ this.clients.splice(index, 1);
436
+ }
437
+ },
438
+ };
261
439
  }
262
440
 
263
441
  onInstanceUpdate(instance: WorkspaceInstance): void {
@@ -266,31 +444,34 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
266
444
  try {
267
445
  client.onInstanceUpdate(instance);
268
446
  } catch (error) {
269
- console.error(error)
447
+ console.error(error);
270
448
  }
271
449
  }
272
450
  }
273
451
  }
274
452
 
275
- onWorkspaceImageBuildLogs(info: WorkspaceImageBuild.StateInfo, content: WorkspaceImageBuild.LogContent | undefined): void {
453
+ onPrebuildUpdate(update: PrebuildWithStatus): void {
276
454
  for (const client of this.clients) {
277
- if (client.onWorkspaceImageBuildLogs) {
455
+ if (client.onPrebuildUpdate) {
278
456
  try {
279
- client.onWorkspaceImageBuildLogs(info, content);
457
+ client.onPrebuildUpdate(update);
280
458
  } catch (error) {
281
- console.error(error)
459
+ console.error(error);
282
460
  }
283
461
  }
284
462
  }
285
463
  }
286
464
 
287
- onHeadlessWorkspaceLogs(evt: HeadlessLogEvent): void {
465
+ onWorkspaceImageBuildLogs(
466
+ info: WorkspaceImageBuild.StateInfo,
467
+ content: WorkspaceImageBuild.LogContent | undefined,
468
+ ): void {
288
469
  for (const client of this.clients) {
289
- if (client.onHeadlessWorkspaceLogs) {
470
+ if (client.onWorkspaceImageBuildLogs) {
290
471
  try {
291
- client.onHeadlessWorkspaceLogs(evt);
472
+ client.onWorkspaceImageBuildLogs(info, content);
292
473
  } catch (error) {
293
- console.error(error)
474
+ console.error(error);
294
475
  }
295
476
  }
296
477
  }
@@ -302,7 +483,7 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
302
483
  try {
303
484
  client.notifyDidOpenConnection();
304
485
  } catch (error) {
305
- console.error(error)
486
+ console.error(error);
306
487
  }
307
488
  }
308
489
  }
@@ -314,17 +495,28 @@ export class GitpodCompositeClient<Client extends GitpodClient> implements Gitpo
314
495
  try {
315
496
  client.notifyDidCloseConnection();
316
497
  } catch (error) {
317
- console.error(error)
498
+ console.error(error);
318
499
  }
319
500
  }
320
501
  }
321
502
  }
322
503
 
504
+ onCreditAlert(creditAlert: CreditAlert): void {
505
+ for (const client of this.clients) {
506
+ if (client.onCreditAlert) {
507
+ try {
508
+ client.onCreditAlert(creditAlert);
509
+ } catch (error) {
510
+ console.error(error);
511
+ }
512
+ }
513
+ }
514
+ }
323
515
  }
324
516
 
325
517
  export type GitpodService = GitpodServiceImpl<GitpodClient, GitpodServer>;
326
518
 
327
- const hasWindow = (typeof window !== 'undefined');
519
+ const hasWindow = typeof window !== "undefined";
328
520
  const phasesOrder: Record<WorkspaceInstancePhase, number> = {
329
521
  unknown: 0,
330
522
  preparing: 1,
@@ -334,44 +526,41 @@ const phasesOrder: Record<WorkspaceInstancePhase, number> = {
334
526
  running: 5,
335
527
  interrupted: 6,
336
528
  stopping: 7,
337
- stopped: 8
529
+ stopped: 8,
338
530
  };
339
531
  export class WorkspaceInstanceUpdateListener {
340
532
  private readonly onDidChangeEmitter = new Emitter<void>();
341
533
  readonly onDidChange = this.onDidChangeEmitter.event;
342
534
 
343
- private source: 'sync' | 'update' = 'sync';
535
+ private source: "sync" | "update" = "sync";
344
536
 
345
537
  get info(): WorkspaceInfo {
346
538
  return this._info;
347
539
  }
348
540
 
349
- constructor(
350
- private readonly service: GitpodService,
351
- private _info: WorkspaceInfo
352
- ) {
541
+ constructor(private readonly service: GitpodService, private _info: WorkspaceInfo) {
353
542
  service.registerClient({
354
- onInstanceUpdate: instance => {
543
+ onInstanceUpdate: (instance) => {
355
544
  if (this.isOutOfOrder(instance)) {
356
545
  return;
357
546
  }
358
547
  this.cancelSync();
359
548
  this._info.latestInstance = instance;
360
- this.source = 'update';
549
+ this.source = "update";
361
550
  this.onDidChangeEmitter.fire(undefined);
362
551
  },
363
552
  notifyDidOpenConnection: () => {
364
553
  this.sync();
365
- }
554
+ },
366
555
  });
367
556
  if (hasWindow) {
368
557
  // learn about page lifecycle here: https://developers.google.com/web/updates/2018/07/page-lifecycle-api
369
- window.document.addEventListener('visibilitychange', async () => {
370
- if (window.document.visibilityState === 'visible') {
558
+ window.document.addEventListener("visibilitychange", async () => {
559
+ if (window.document.visibilityState === "visible") {
371
560
  this.sync();
372
561
  }
373
562
  });
374
- window.addEventListener('pageshow', e => {
563
+ window.addEventListener("pageshow", (e) => {
375
564
  if (e.persisted) {
376
565
  this.sync();
377
566
  }
@@ -399,12 +588,12 @@ export class WorkspaceInstanceUpdateListener {
399
588
  return;
400
589
  }
401
590
  this._info = info;
402
- this.source = 'sync';
591
+ this.source = "sync";
403
592
  this.onDidChangeEmitter.fire(undefined);
404
593
  } catch (e) {
405
- console.error('failed to sync workspace instance:', e)
594
+ console.error("failed to sync workspace instance:", e);
406
595
  }
407
- })
596
+ });
408
597
  }
409
598
  private cancelSync(): void {
410
599
  if (this.syncTokenSource) {
@@ -421,7 +610,7 @@ export class WorkspaceInstanceUpdateListener {
421
610
  if (instance.workspaceId !== this._info.workspace.id) {
422
611
  return true;
423
612
  }
424
- if (this.source === 'update') {
613
+ if (this.source === "update") {
425
614
  return false;
426
615
  }
427
616
  if (instance.id !== this.info.latestInstance?.id) {
@@ -429,14 +618,16 @@ export class WorkspaceInstanceUpdateListener {
429
618
  }
430
619
  return phasesOrder[instance.status.phase] < phasesOrder[this.info.latestInstance.status.phase];
431
620
  }
621
+ }
432
622
 
623
+ export interface GitpodServiceOptions {
624
+ onReconnect?: () => void | Promise<void>;
433
625
  }
434
626
 
435
627
  export class GitpodServiceImpl<Client extends GitpodClient, Server extends GitpodServer> {
436
-
437
628
  private readonly compositeClient = new GitpodCompositeClient<Client>();
438
629
 
439
- constructor(public readonly server: JsonRpcProxy<Server>) {
630
+ constructor(public readonly server: JsonRpcProxy<Server>, private options?: GitpodServiceOptions) {
440
631
  server.setClient(this.compositeClient);
441
632
  server.onDidOpenConnection(() => this.compositeClient.notifyDidOpenConnection());
442
633
  server.onDidCloseConnection(() => this.compositeClient.notifyDidCloseConnection());
@@ -448,7 +639,8 @@ export class GitpodServiceImpl<Client extends GitpodClient, Server extends Gitpo
448
639
 
449
640
  private readonly instanceListeners = new Map<string, Promise<WorkspaceInstanceUpdateListener>>();
450
641
  listenToInstance(workspaceId: string): Promise<WorkspaceInstanceUpdateListener> {
451
- const listener = this.instanceListeners.get(workspaceId) ||
642
+ const listener =
643
+ this.instanceListeners.get(workspaceId) ||
452
644
  (async () => {
453
645
  const info = await this.server.getWorkspace(workspaceId);
454
646
  return new WorkspaceInstanceUpdateListener(this, info);
@@ -456,13 +648,33 @@ export class GitpodServiceImpl<Client extends GitpodClient, Server extends Gitpo
456
648
  this.instanceListeners.set(workspaceId, listener);
457
649
  return listener;
458
650
  }
651
+
652
+ async reconnect(): Promise<void> {
653
+ if (this.options?.onReconnect) {
654
+ await this.options.onReconnect();
655
+ }
656
+ }
459
657
  }
460
658
 
461
- export function createGitpodService<C extends GitpodClient, S extends GitpodServer>(serverUrl: string) {
462
- const url = new GitpodHostUrl(serverUrl)
463
- .asWebsocket()
464
- .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
+
465
672
  const connectionProvider = new WebSocketConnectionProvider();
466
- const gitpodServer = connectionProvider.createProxy<S>(url.toString());
467
- return new GitpodServiceImpl<C, S>(gitpodServer);
468
- }
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
+ }