@gitpod/gitpod-protocol 0.1.5-patch-2-fork.0 → 0.1.5-pavel-9469.26

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