Add deprioritized device group
Build and Deploy Gateway / build-and-push (push) Successful in 19s
Build and Deploy Gateway / deploy (push) Successful in 14s

This commit is contained in:
2026-08-10 09:25:29 +03:00
parent ec68ba6a7b
commit f233660dc3
13 changed files with 262 additions and 60 deletions
+15 -4
View File
@@ -67,6 +67,7 @@ interface InventoryDevice {
id: string;
alias: string;
pinned: boolean;
deprioritized: boolean;
hostname: string | null;
manufacturer: string | null;
mac: string;
@@ -265,6 +266,7 @@ function normalizeInventoryDevice(value: unknown): InventoryDevice | null {
: deviceId(mac),
alias: typeof device.alias === 'string' ? device.alias : '',
pinned: device.pinned === true,
deprioritized: device.deprioritized === true && device.pinned !== true,
hostname: typeof device.hostname === 'string' ? device.hostname : null,
manufacturer: typeof device.manufacturer === 'string' ? device.manufacturer : null,
mac,
@@ -792,6 +794,7 @@ export function createDeviceInventoryService({
};
}).sort((left, right) => (
Number(right.pinned) - Number(left.pinned)
|| Number(left.deprioritized) - Number(right.deprioritized)
|| rank[left.status] - rank[right.status]
|| String(right.lastSeenAt).localeCompare(String(left.lastSeenAt))
));
@@ -1016,6 +1019,7 @@ export function createDeviceInventoryService({
id: previous?.id || deviceId(mac),
alias: previous?.alias || '',
pinned: previous?.pinned === true,
deprioritized: previous?.deprioritized === true && previous?.pinned !== true,
hostname: previous?.hostname || null,
manufacturer: previous?.manufacturer || vendor(mac),
mac,
@@ -1031,7 +1035,7 @@ export function createDeviceInventoryService({
}
const cutoff = new Date(observedAt).getTime() - RETENTION_MS;
const devices = [...byMac.values()].filter((device) => (
device.pinned || device.alias || new Date(device.lastSeenAt).getTime() >= cutoff
device.pinned || device.deprioritized || device.alias || new Date(device.lastSeenAt).getTime() >= cutoff
));
let traffic = state.traffic;
if (trafficResult) {
@@ -1271,15 +1275,19 @@ export function createDeviceInventoryService({
const value = record(patch);
const aliasProvided = Object.hasOwn(value, 'alias');
const pinProvided = Object.hasOwn(value, 'pinned');
const deprioritizedProvided = Object.hasOwn(value, 'deprioritized');
if (typeof expectedRevision !== 'number' || !Number.isSafeInteger(expectedRevision) || expectedRevision < 0
|| (!aliasProvided && !pinProvided)
|| (!aliasProvided && !pinProvided && !deprioritizedProvided)
|| (aliasProvided && (typeof value.alias !== 'string' || value.alias.length > 64))
|| (pinProvided && typeof value.pinned !== 'boolean')) {
|| (pinProvided && typeof value.pinned !== 'boolean')
|| (deprioritizedProvided && typeof value.deprioritized !== 'boolean')
|| (value.pinned === true && value.deprioritized === true)) {
throw new HarborError('REQUEST_INVALID');
}
const revision = expectedRevision;
const alias = typeof value.alias === 'string' ? value.alias : '';
const pinned = value.pinned === true;
const deprioritized = value.deprioritized === true;
store.update((stored) => {
const state = migrateDeviceInventoryState(stored);
if (state.revision !== revision) throw new HarborError('STATE_CONFLICT');
@@ -1289,7 +1297,10 @@ export function createDeviceInventoryService({
devices[index] = {
...devices[index],
...(aliasProvided ? { alias: alias.trim() } : {}),
...(pinProvided ? { pinned } : {}),
...(pinProvided ? { pinned, ...(pinned ? { deprioritized: false } : {}) } : {}),
...(deprioritizedProvided
? { deprioritized, ...(deprioritized ? { pinned: false } : {}) }
: {}),
};
return { ...state, revision: state.revision + 1, devices };
});