d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { type NextRequest, NextResponse } from 'next/server'
|
|
import { noInputSchema } from '@/lib/api/contracts/primitives'
|
|
import { validationErrorResponse } from '@/lib/api/server'
|
|
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
|
import type { IncidentIOWidgetResponse, StatusResponse, StatusType } from '@/app/api/status/types'
|
|
|
|
const logger = createLogger('StatusAPI')
|
|
|
|
let cachedResponse: { data: StatusResponse; timestamp: number } | null = null
|
|
const CACHE_TTL = 2 * 60 * 1000
|
|
|
|
function determineStatus(data: IncidentIOWidgetResponse): {
|
|
status: StatusType
|
|
message: string
|
|
} {
|
|
if (data.ongoing_incidents && data.ongoing_incidents.length > 0) {
|
|
const worstImpact = data.ongoing_incidents[0].current_worst_impact
|
|
|
|
if (worstImpact === 'full_outage') {
|
|
return { status: 'outage', message: 'Service Disruption' }
|
|
}
|
|
if (worstImpact === 'partial_outage') {
|
|
return { status: 'degraded', message: 'Experiencing Issues' }
|
|
}
|
|
return { status: 'degraded', message: 'Experiencing Issues' }
|
|
}
|
|
|
|
if (data.in_progress_maintenances && data.in_progress_maintenances.length > 0) {
|
|
return { status: 'maintenance', message: 'Under Maintenance' }
|
|
}
|
|
|
|
return { status: 'operational', message: 'All Systems Operational' }
|
|
}
|
|
|
|
export const GET = withRouteHandler(async (request: NextRequest) => {
|
|
try {
|
|
const queryValidation = noInputSchema.safeParse(
|
|
Object.fromEntries(request.nextUrl.searchParams.entries())
|
|
)
|
|
if (!queryValidation.success) return validationErrorResponse(queryValidation.error)
|
|
|
|
const now = Date.now()
|
|
|
|
if (cachedResponse && now - cachedResponse.timestamp < CACHE_TTL) {
|
|
return NextResponse.json(cachedResponse.data, {
|
|
headers: {
|
|
'Cache-Control': 'public, max-age=60, s-maxage=60',
|
|
'X-Cache': 'HIT',
|
|
},
|
|
})
|
|
}
|
|
|
|
const response = await fetch('https://status.sim.ai/api/v1/summary', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
signal: AbortSignal.timeout(5000),
|
|
})
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`incident.io API returned ${response.status}`)
|
|
}
|
|
|
|
const data: IncidentIOWidgetResponse = await response.json()
|
|
|
|
const { status, message } = determineStatus(data)
|
|
|
|
const statusResponse: StatusResponse = {
|
|
status,
|
|
message,
|
|
url: data.page_url || 'https://status.sim.ai',
|
|
lastUpdated: new Date().toISOString(),
|
|
}
|
|
|
|
cachedResponse = {
|
|
data: statusResponse,
|
|
timestamp: now,
|
|
}
|
|
|
|
return NextResponse.json(statusResponse, {
|
|
headers: {
|
|
'Cache-Control': 'public, max-age=60, s-maxage=60',
|
|
'X-Cache': 'MISS',
|
|
},
|
|
})
|
|
} catch (error) {
|
|
logger.error('Error fetching status from incident.io:', error)
|
|
|
|
const errorResponse: StatusResponse = {
|
|
status: 'error',
|
|
message: 'Status Unknown',
|
|
url: 'https://status.sim.ai',
|
|
lastUpdated: new Date().toISOString(),
|
|
}
|
|
|
|
return NextResponse.json(errorResponse, {
|
|
status: 200,
|
|
headers: {
|
|
'Cache-Control': 'public, max-age=30, s-maxage=30',
|
|
},
|
|
})
|
|
}
|
|
})
|