11import { Api } from "coder/site/src/api/api"
2+ import { ProxyAgent } from "proxy-agent"
23import * as vscode from "vscode"
34import { WebSocket } from "ws"
45import { errToStr } from "./api-helper"
5- import { Storage } from "./storage"
6- import { ProxyAgent } from "proxy-agent"
6+ import { type Storage } from "./storage"
77
88type InboxMessage = {
99 unread_count : number
@@ -14,26 +14,26 @@ type InboxMessage = {
1414 targets : string [ ]
1515 title : string
1616 content : string
17- actions : {
18- [ key : string ] : string
19- }
17+ actions : Record < string , string >
2018 read_at : string
2119 created_at : string
2220 }
2321}
2422
25- const TemplateWorkspaceOutOfMemory = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
26- const TemplateWorkspaceOutOfDisk = "f047f6a3-5713-40f7-85aa-0394cce9fa3a"
23+ // These are the template IDs of our notifications.
24+ // Maybe in the future we should avoid hardcoding
25+ // these in both coderd and here.
26+ const TEMPLATE_WORKSPACE_OUT_OF_MEMORY = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
27+ const TEMPLATE_WORKSPACE_OUT_OF_DISK = "f047f6a3-5713-40f7-85aa-0394cce9fa3a"
2728
2829export class Inbox implements vscode . Disposable {
30+ private readonly storage : Storage
2931 private disposed = false
3032 private socket : WebSocket
3133
32- constructor (
33- httpAgent : ProxyAgent ,
34- restClient : Api ,
35- private readonly storage : Storage ,
36- ) {
34+ constructor ( httpAgent : ProxyAgent , restClient : Api , storage : Storage ) {
35+ this . storage = storage
36+
3737 const baseUrlRaw = restClient . getAxiosInstance ( ) . defaults . baseURL
3838 if ( ! baseUrlRaw ) {
3939 throw new Error ( "No base URL set on REST client" )
@@ -43,11 +43,12 @@ export class Inbox implements vscode.Disposable {
4343 const socketProto = baseUrl . protocol === "https:" ? "wss:" : "ws:"
4444 const socketUrlRaw = `${ socketProto } //${ baseUrl . host } /api/v2/notifications/watch`
4545
46+ const coderSessionTokenHeader = "Coder-Session-Token"
4647 this . socket = new WebSocket ( new URL ( socketUrlRaw ) , {
4748 followRedirects : true ,
4849 agent : httpAgent ,
4950 headers : {
50- "Coder-Session-Token" : restClient . getAxiosInstance ( ) . defaults . headers . common [ "Coder-Session-Token" ] as
51+ [ coderSessionTokenHeader ] : restClient . getAxiosInstance ( ) . defaults . headers . common [ coderSessionTokenHeader ] as
5152 | string
5253 | undefined ,
5354 } ,
@@ -66,8 +67,8 @@ export class Inbox implements vscode.Disposable {
6667 const inboxMessage = JSON . parse ( data . toString ( ) ) as InboxMessage
6768
6869 if (
69- inboxMessage . notification . template_id === TemplateWorkspaceOutOfDisk ||
70- inboxMessage . notification . template_id === TemplateWorkspaceOutOfMemory
70+ inboxMessage . notification . template_id === TEMPLATE_WORKSPACE_OUT_OF_DISK ||
71+ inboxMessage . notification . template_id === TEMPLATE_WORKSPACE_OUT_OF_MEMORY
7172 ) {
7273 vscode . window . showWarningMessage ( inboxMessage . notification . title )
7374 }
0 commit comments