@gitpod/gitpod-protocol 0.1.5-sh-jupyter.0 → 0.1.5-siddhant-k-code-allow-github-prebuilds-10358.2

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