const requiredErrorHandlers = [
'401 - Unauthorized',
'403 - Forbidden',
'404 - Not Found',
'422 - Validation Error',
'429 - Rate Limited',
'500+ - Server Errors',
'Network Timeout',
'Connection Refused',
];
const requiredMetrics = [
'maintainx_api_requests_total',
'maintainx_api_latency_seconds',
'maintainx_api_errors_total',
'maintainx_rate_limit_remaining',
'maintainx_work_orders_created',
];
import { MaintainXClient } from '../src/api/maintainx-client';
interface CheckResult {
name: string;
passed: boolean;
message: string;
}
async function runPreDeployChecks(): Promise<CheckResult[]> {
const results: CheckResult[] = [];
try {
const client = new MaintainXClient();
await client.getUsers({ limit: 1 });
results.push({
name: 'API Connectivity',
passed: true,
message: 'Successfully connected to MaintainX API',
});
} catch (error: any) {
results.push({
name: 'API Connectivity',
passed: false,
message: `Failed to connect: ${error.message}`,
});
}
const requiredEnvVars = [
'MAINTAINX_API_KEY',
'NODE_ENV',
];
for (const envVar of requiredEnvVars) {
results.push({
name: `Env: ${envVar}`,
passed: !!process.env[envVar],
message: process.env[envVar] ? 'Set' : 'Missing',
});
}
try {
const { execSync } = require('child_process');
execSync('npm audit --production --audit-level=high', { stdio: 'pipe' });
results.push({
name: 'Dependency Audit',
passed: true,
message: 'No high-severity vulnerabilities',
});
} catch (error) {
results.push({
name: 'Dependency Audit',
passed: false,
message: 'High-severity vulnerabilities found',
});
}
try {
const { execSync } = require('child_process');
execSync('npm run build', { stdio: 'pipe' });
results.push({
name: 'Build',
passed: true,
message: 'Build successful',
});
} catch (error) {
results.push({
name: 'Build',
passed: false,
message: 'Build failed',
});
}
try {
const { execSync } = require('child_process');
execSync('npm test', { stdio: 'pipe' });
results.push({
name: 'Tests',
passed: true,
message: 'All tests passed',
});
} catch (error) {
results.push({
name: 'Tests',
passed: false,
message: 'Tests failed',
});
}
return results;
}
async function main() {
console.log('=== MaintainX Pre-Deployment Checks ===\n');
const results = await runPreDeployChecks();
results.forEach(r => {
const status = r.passed ? '[PASS]' : '[FAIL]';
console.log(`${status} ${r.name}: ${r.message}`);
});
const failed = results.filter(r => !r.passed);
console.log(`\n${results.length - failed.length}/${results.length} checks passed`);
if (failed.length > 0) {
console.log('\nFix the following before deploying:');
failed.forEach(f => console.log(` - ${f.name}: ${f.message}`));
process.exit(1);
}
console.log('\nAll checks passed. Ready for deployment!');
}
main().catch(console.error);
#!/bin/bash
echo "=== Post-Deployment Verification ==="
echo -n "Health check... "
HEALTH=$(curl -s -o /dev/null -w "%{http_code}" https://your-app.com/health)
if [ "$HEALTH" == "200" ]; then
echo "PASS"
else
echo "FAIL (HTTP $HEALTH)"
fi
echo -n "MaintainX API... "
API_CHECK=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer $MAINTAINX_API_KEY" \
https://api.getmaintainx.com/v1/users?limit=1)
if [ "$API_CHECK" == "200" ]; then
echo "PASS"
else
echo "FAIL (HTTP $API_CHECK)"
fi
echo -n "Create work order... "
WO_RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer $MAINTAINX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"title":"Post-Deploy Test - DELETE ME","priority":"LOW"}' \
https://api.getmaintainx.com/v1/workorders)
if echo "$WO_RESPONSE" | grep -q '"id"'; then
echo "PASS"
WO_ID=$(echo "$WO_RESPONSE" | jq -r '.id')
echo " Created test work order: $WO_ID (delete manually)"
else
echo "FAIL"
fi
echo ""
echo "=== Verification Complete ==="