@@ -4,41 +4,25 @@ import { cacheLife } from 'next/cache'
44import Link from 'next/link'
55import { l } from '@/core/shared/clients/logger/logger'
66import { LiveDot } from '@/ui/live'
7+ import {
8+ type AggregateState ,
9+ getStatusPageStateFromWidget ,
10+ getStatusPageUrl ,
11+ getStatusPageWidgetUrl ,
12+ type IncidentIOWidgetResponse ,
13+ } from './status-indicator'
714
8- const STATUS_PAGE_URL = 'https://status.e2b.dev'
9- const STATUS_PAGE_INDEX_URL = ` ${ STATUS_PAGE_URL } /index.json`
15+ export const STATUS_PAGE_URL = getStatusPageUrl ( )
16+ const STATUS_PAGE_WIDGET_URL = getStatusPageWidgetUrl ( STATUS_PAGE_URL )
1017const STATUS_PAGE_FETCH_TIMEOUT_MS = 5_000
1118const STATUS_PAGE_CACHE_SECONDS = 300
1219
13- type AggregateState =
14- | 'operational'
15- | 'degraded'
16- | 'downtime'
17- | 'maintenance'
18- | 'unknown'
19-
20- interface StatusPageIndexResponse {
21- data ?: {
22- attributes ?: {
23- aggregate_state ?: string
24- }
25- }
26- }
27-
2820interface StatusUI {
2921 label : string
3022 dotCircleClassName : string
3123 dotClassName : string
3224}
3325
34- function toAggregateState ( value : string | undefined ) : AggregateState {
35- if ( value === 'operational' ) return 'operational'
36- if ( value === 'degraded' ) return 'degraded'
37- if ( value === 'downtime' ) return 'downtime'
38- if ( value === 'maintenance' ) return 'maintenance'
39- return 'unknown'
40- }
41-
4226function getStatusUI ( state : AggregateState ) : StatusUI {
4327 switch ( state ) {
4428 case 'operational' :
@@ -83,7 +67,7 @@ async function getStatusPageState(): Promise<AggregateState> {
8367 } )
8468
8569 try {
86- const response = await fetch ( STATUS_PAGE_INDEX_URL , {
70+ const response = await fetch ( STATUS_PAGE_WIDGET_URL , {
8771 cache : 'force-cache' ,
8872 next : { revalidate : STATUS_PAGE_CACHE_SECONDS } ,
8973 signal : AbortSignal . timeout ( STATUS_PAGE_FETCH_TIMEOUT_MS ) ,
@@ -101,8 +85,8 @@ async function getStatusPageState(): Promise<AggregateState> {
10185 return 'unknown'
10286 }
10387
104- const data = ( await response . json ( ) ) as StatusPageIndexResponse
105- return toAggregateState ( data . data ?. attributes ?. aggregate_state )
88+ const data = ( await response . json ( ) ) as IncidentIOWidgetResponse
89+ return getStatusPageStateFromWidget ( data )
10690 } catch {
10791 return 'unknown'
10892 }
0 commit comments