import { BambooHRClient, BambooHRApiError } from '../bamboohr/client';
interface HealthStatus {
status: 'healthy' | 'degraded' | 'down';
bamboohr: {
connected: boolean;
latencyMs: number;
error?: string;
employeeCount?: number;
};
timestamp: string;
}
export async function healthCheck(client: BambooHRClient): Promise<HealthStatus> {
const start = Date.now();
try {
const dir = await client.getDirectory();
return {
status: 'healthy',
bamboohr: {
connected: true,
latencyMs: Date.now() - start,
employeeCount: dir.employees.length,
},
timestamp: new Date().toISOString(),
};
} catch (err) {
const latency = Date.now() - start;
const errMsg = err instanceof BambooHRApiError ? err.message : 'Unknown error';
return {
status: err instanceof BambooHRApiError && err.retryable ? 'degraded' : 'down',
bamboohr: { connected: false, latencyMs: latency, error: errMsg },
timestamp: new Date().toISOString(),
};
}
}
const ALERTS = {
p1_critical: [
{ name: 'Auth failure', condition: '401/403 errors > 0', action: 'Page on-call' },
{ name: 'API down', condition: 'Health check fails 3x consecutive', action: 'Page on-call' },
],
p2_high: [
{ name: 'Rate limited', condition: '503 errors > 3/min', action: 'Slack alert' },
{ name: 'High latency', condition: 'p99 > 5000ms', action: 'Slack alert' },
{ name: 'Sync failure', condition: 'Sync job fails', action: 'Slack + ticket' },
],
p3_medium: [
{ name: 'Elevated errors', condition: '4xx errors > 10/hour', action: 'Log + daily review' },
{ name: 'Data mismatch', condition: 'Schema validation failures', action: 'Log + ticket' },
],
};
#!/bin/bash
echo "=== Pre-flight checks ==="
curl -sf "https://status.bamboohr.com" > /dev/null || { echo "BambooHR may be down!"; exit 1; }
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-u "${BAMBOOHR_API_KEY}:x" \
-H "Accept: application/json" \
"https://api.bamboohr.com/api/gateway.php/${BAMBOOHR_COMPANY_DOMAIN}/v1/employees/directory")
[ "$STATUS" -eq 200 ] || { echo "Auth check failed: $STATUS"; exit 1; }
echo "API auth: OK"
echo "=== Deploying ==="
echo "=== Post-deploy verification ==="
sleep 10
curl -sf "https://your-app.com/api/health" | jq .bamboohr