@@ -5,62 +5,77 @@ export type AggregateState =
55 | 'maintenance'
66 | 'unknown'
77
8- export interface IncidentIOWidgetEvent {
9- affected_components ?: Array < {
8+ export interface IncidentIOStatusPageSummaryResponse {
9+ status ?: {
10+ indicator ?: string
11+ }
12+ components ?: Array < {
13+ status ?: string
14+ } >
15+ scheduled_maintenances ?: Array < {
1016 status ?: string
1117 } >
12- }
13-
14- export interface IncidentIOWidgetResponse {
15- ongoing_incidents ?: IncidentIOWidgetEvent [ ]
16- in_progress_maintenances ?: IncidentIOWidgetEvent [ ]
17- scheduled_maintenances ?: IncidentIOWidgetEvent [ ]
1818}
1919
2020export function getStatusPageUrl ( ) {
21- return ( process . env . NEXT_PUBLIC_STATUS_PAGE_URL ?? 'https://status.e2b.dev' )
21+ return (
22+ process . env . NEXT_PUBLIC_STATUS_PAGE_URL ??
23+ 'https://statuspage.incident.io/e2b-service'
24+ )
2225 . trim ( )
2326 . replace ( / \/ + $ / , '' )
2427}
2528
26- export function getStatusPageWidgetUrl ( statusPageUrl : string ) {
27- const configuredWidgetUrl =
28- process . env . NEXT_PUBLIC_STATUS_PAGE_WIDGET_URL ?. trim ( )
29+ export function getStatusPageSummaryUrl ( statusPageUrl : string ) {
30+ const configuredSummaryUrl =
31+ process . env . NEXT_PUBLIC_STATUS_PAGE_SUMMARY_URL ?. trim ( )
2932
30- if ( configuredWidgetUrl ) return configuredWidgetUrl
33+ if ( configuredSummaryUrl ) return configuredSummaryUrl
3134
32- return `${ statusPageUrl } /api/widget `
35+ return `${ statusPageUrl } /api/v2/summary.json `
3336}
3437
35- function hasEvents ( events : IncidentIOWidgetEvent [ ] | undefined ) {
36- return Array . isArray ( events ) && events . length > 0
38+ function stateFromIndicator ( indicator : string | undefined ) {
39+ if ( indicator === 'none' ) return 'operational'
40+ if ( indicator === 'minor' ) return 'degraded'
41+ if ( indicator === 'major' ) return 'degraded'
42+ if ( indicator === 'critical' ) return 'downtime'
43+ if ( indicator === 'maintenance' ) return 'maintenance'
44+
45+ return undefined
3746}
3847
3948function getWorstComponentState (
40- events : IncidentIOWidgetEvent [ ] | undefined
49+ components : IncidentIOStatusPageSummaryResponse [ 'components' ]
4150) : AggregateState | undefined {
4251 const componentStatuses =
43- events ?. flatMap (
44- ( event ) =>
45- event . affected_components ?. map ( ( component ) => component . status ) ?? [ ]
46- ) ?? [ ]
52+ components ?. map ( ( component ) => component . status ) ?? [ ]
4753
48- if ( componentStatuses . includes ( 'full_outage ' ) ) return 'downtime'
54+ if ( componentStatuses . includes ( 'major_outage ' ) ) return 'downtime'
4955 if ( componentStatuses . includes ( 'partial_outage' ) ) return 'degraded'
5056 if ( componentStatuses . includes ( 'degraded_performance' ) ) return 'degraded'
5157 if ( componentStatuses . includes ( 'under_maintenance' ) ) return 'maintenance'
5258
5359 return undefined
5460}
5561
56- export function getStatusPageStateFromWidget (
57- data : IncidentIOWidgetResponse
58- ) : AggregateState {
59- if ( hasEvents ( data . ongoing_incidents ) ) {
60- return getWorstComponentState ( data . ongoing_incidents ) ?? 'degraded'
61- }
62+ function hasMaintenanceInProgress (
63+ maintenances : IncidentIOStatusPageSummaryResponse [ 'scheduled_maintenances' ]
64+ ) {
65+ return maintenances ?. some (
66+ ( maintenance ) => maintenance . status === 'maintenance_in_progress'
67+ )
68+ }
6269
63- if ( hasEvents ( data . in_progress_maintenances ) ) return 'maintenance'
70+ export function getStatusPageStateFromSummary (
71+ data : IncidentIOStatusPageSummaryResponse
72+ ) : AggregateState {
73+ if ( hasMaintenanceInProgress ( data . scheduled_maintenances ) )
74+ return 'maintenance'
6475
65- return 'operational'
76+ return (
77+ stateFromIndicator ( data . status ?. indicator ) ??
78+ getWorstComponentState ( data . components ) ??
79+ 'unknown'
80+ )
6681}
0 commit comments