Bring Device Core settings to Mission UI and expose scoped B2 controls
Device Core qualification / qualify (push) Successful in 6m40s

This commit is contained in:
DCCONSTRUCTIONS
2026-09-30 22:43:54 +03:00
parent 8031ed76a2
commit 8941769b4c
12 changed files with 295 additions and 4 deletions
+8 -1
View File
@@ -6,6 +6,10 @@ export type B2Status = { connected: boolean; endpoint?: string; authority?: 'hos
links?: Array<{ contourId: string; projectRef: string }> };
export type B2Device = { id: string; identifier: { masked: string }; name: string; active: boolean; number: number; contourId: string };
const messages: Record<string, string> = {
b2_settings_revision_changed: 'Настройки изменились. Обновите сведения о трекере перед отправкой.',
b2_settings_initial_read_required: 'Сначала прочитайте настройки трекера через VPS.',
b2_settings_sim_observation_required: 'Нет свежих данных выбранной SIM. Дождитесь регистрации карты и обновите сведения.',
b2_request_invalid: 'Проверьте параметры: VPS отклонил запрос.',
b2_infrastructure_unavailable: 'Подключение ARNavi пока не настроено на сервере Device Core.',
b2_host_unavailable: 'VPS не отвечает. Проверьте доступность сервера.',
b2_host_not_connected: 'Сначала подключите VPS.',
@@ -20,6 +24,9 @@ const messages: Record<string, string> = {
b2_company_mismatch: 'Выберите проект той же компании.',
device_owner_scope_access_denied: 'Настройки общего VPS доступны администратору компании.',
};
export class B2RequestError extends Error {
constructor(message: string, public readonly rejected: boolean) { super(message); }
}
export async function b2Request<T>(projectRef: string, hostRef: string, action: string, fields: Record<string, unknown> = {}, requestId = crypto.randomUUID().replaceAll('-', '')): Promise<T> {
const response = await fetch('/api/device-manager/b2/infrastructure', {
method: 'POST', credentials: 'same-origin',
@@ -27,6 +34,6 @@ export async function b2Request<T>(projectRef: string, hostRef: string, action:
body: JSON.stringify({ projectRef, hostRef, action, ...fields }),
});
const body = await response.json().catch(() => null);
if (!response.ok || body?.ok !== true) throw new Error(messages[body?.error] || 'Не удалось выполнить действие на VPS. Обновите сведения о подключении.');
if (!response.ok || body?.ok !== true) throw new B2RequestError(messages[body?.error] || 'Не удалось выполнить действие на VPS. Обновите сведения о подключении.', response.status >= 400 && response.status < 500);
return body.result as T;
}