initial commit
This commit is contained in:
3
shared/impact.d.mts
Normal file
3
shared/impact.d.mts
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Impact, Incident, Localized, Service } from '../src/types';
|
||||
export function serviceImpact(service: Service, services?: Service[]): Impact | null;
|
||||
export function incidentImpact(incident: Incident, services: Service[]): Localized | null;
|
||||
19
shared/impact.mjs
Normal file
19
shared/impact.mjs
Normal file
@@ -0,0 +1,19 @@
|
||||
export function serviceImpact(service, services = []) {
|
||||
if (!['down', 'degraded'].includes(service.status)) return null;
|
||||
const scope = service.availabilityStatus === 'operational' && ['down', 'degraded'].includes(service.scenario?.status) ? 'scenario' : 'availability';
|
||||
const message = service.impactPolicy?.[scope] || {
|
||||
ru: 'Возможны ограничения в работе сервиса. Подробности уточняются.',
|
||||
en: 'The service may have limitations. Details are being confirmed.',
|
||||
};
|
||||
const advice = service.impactPolicy?.advice || null;
|
||||
const alternatives = (service.impactPolicy?.fallbacks || []).flatMap(id => {
|
||||
const target = services.find(item => item.id === id);
|
||||
return target?.status === 'operational' ? [{ id: target.id, name: target.name, url: target.publicUrl }] : [];
|
||||
});
|
||||
return { scope, message, advice, alternatives };
|
||||
}
|
||||
|
||||
export function incidentImpact(incident, services) {
|
||||
const service = services.find(item => item.id === incident.serviceId);
|
||||
return service?.impactPolicy?.[incident.scope || 'availability'] || null;
|
||||
}
|
||||
Reference in New Issue
Block a user