Utilities
Public utility functions exported by @tetherto/mdk-ui-core.
Imported from @tetherto/mdk-ui-core.
Alerts
| Name | Signature / Type | Description |
|---|
breakTimeIntoIntervals | (start: number, end: number, intervalMs: number = ONE_DAY_MS) => TimeInterval[] | Split `[start, end]` into consecutive windows of `intervalMs`. The final window is clamped to `end`. Returns an empty array when the range is empty or inverted. Mirrors Moria's `breakTimeIntoIntervals`. |
buildCurrentAlertDevicesParams | (filterTags: string[] = []) => ListThingsParams | `list-things` params for the current-alerts table: every device that currently carries one or more alerts, with the fields the `<CurrentAlerts>` table reads. Consumed by `useCurrentAlertDevices`. |
buildHistoricalAlertsParams | (range: HistoricalAlertsRange) => HistoryLogParams | `history-log` params for a single alerts window. The chunked fetch (`useHistoricalAlerts`) calls this once per 24h sub-window. |
fetchHistoricalAlertsInChunks | (range: { start: number; end: number }, fetchWindow: (window: TimeInterval) => Promise<T[]>, options: FetchHistoricalAlertsOptions = {}) => Promise<T[]> | Fetch a historical-alerts range as successive 24h windows, merging the results by `uuid`. `fetchWindow` is called once per window (oldest → newest); individual window failures are swallowed (matches Moria) so one bad window doesn't drop th… |
getAlertsForDevices | (devices: ListThingsDevice[], formatDate: (d: Date) => string = (d) => d.toISOString()) => IncidentRow[] | Flatten an array of devices into a list of incident rows, one per alert. Devices without `last.alerts` are skipped. The output is **not yet sorted**; pair with {@link sortIncidentsBySeverity} for the final list-view order. |
getDefaultHistoricalAlertsRange | (now: number = Date.now()) => HistoricalAlertsRange | Default historical-alerts range: the last {@link DEFAULT_HISTORICAL_WINDOW_MS} ending now. Used by the devkit `<Alerts>` feature and the shell Alerts page to seed their range state. |
mapDevicesToIncidents | (devices: ListThingsDevice[], formatDate?: (d: Date) => string) => IncidentRow[] | One-shot helper: `devices → sorted rows`. Used by the `useActiveIncidents` hook's `select` projection. |
mapHistoryLogToAlerts | (rows: HistoricalAlert[] = []) => HistoricalAlert[] | Normalise raw `history-log` alert rows into the shape the devkit `<HistoricalAlerts>` table consumes. The table derives its device label, short code, and filter tokens from each row's `thing` (treated as a device), so this guarantees `thin… |
mergeAlertsByUuid | (prev: T[], next: T[]) => T[] | Concatenate `next` onto `prev`, replacing any row that shares a `uuid` (later windows win) and appending the rest. Rows without a `uuid` are always appended. Mirrors Moria's `updateHistoricalData`. |
sortIncidentsBySeverity | (rows: IncidentRow[]) => IncidentRow[] | Sort rows by severity (critical → high → medium), then by `id` for deterministic ordering when severities tie. Returns a new array. |
Auth
| Name | Signature / Type | Description |
|---|
extractAuthTokenFromUrl | (search: string) => string | null | Extract `?authToken=` from a URL search string. Accepts either a full URL, a query string with leading `?`, or a bare query string. |
stripAuthTokenFromUrl | (search: string) => string | Build a URL string with the `?authToken=` parameter stripped. Used after the OAuth callback to remove the token from the address bar without losing any other query state. |
Dashboard
| Name | Signature / Type | Description |
|---|
buildHashrateTailLogParams | (range: DashboardQueryRange) => TailLogParams | Hashrate tail-log params — per-miner 1-minute aggregate, summed across the `t-miner` tag. |
buildMinerpoolStatsHistoryExtDataParams | (range: MinerpoolStatsHistoryRange = {}) => ExtDataParams | Ext-data params for `type=minerpool, key=stats-history` — per-pool hashrate snapshots over time. Pair with `extDataQuery` to feed the multi-series Hash Rate chart (Mining OS + Aggr Pool + per-pool lines). |
buildSiteConsumptionTailLogParams | (range: DashboardQueryRange) => TailLogParams | Site-level consumption tail-log params — reads the dedicated powermeter's `site_power_w` aggregate (Moria's `type=powermeter, tag=t-powermeter, aggrFields={site_power_w:1}` query). Returns the same series the header's `useSitePowerMeter` s… |
getTimelineOptions | (opts: { includeOneMinute?: boolean } = {}) => TimelineOption[] | Default options for the dashboard timeline selector. Mirrors Moria's `timelineRadioButtons` (5m / 30m / 3h / 1D) — the production dashboard doesn't expose `stat-1m` because the backend typically only emits 5-minute and longer aggregates fo… |
normalizeAlertSeverity | (raw: string | null | undefined) => AlertSeverity | Narrow an arbitrary backend severity string to the `AlertSeverity` literal union expected by the `ActiveIncidentsCard` row component. Unknown values fall back to `'medium'` so the row still renders rather than crashing on an unexpected pay… |
readHashrateMhs | (entry: { hashrate_mhs_1m_sum_aggr?: unknown hashrate_mhs_5m_sum_aggr?: unknown }) => number | undefined | Reads the hashrate aggregate from a tail-log entry. Moria emits `hashrate_mhs_1m_sum_aggr` across every `stat-*` bucket, so a single field check covers all timelines; the `_5m_` legacy fallback is retained as a defensive secondary in case… |
General
| Name | Signature / Type | Description |
|---|
appendContainerToTag | (deviceId: string) => string | — |
appendIdToTag | (deviceId: string) => string | — |
appendIdToTags | (deviceIdList: string[]) => string[] | — |
checkPermission | (config: AuthConfig | null | undefined, { perm, write, cap }: PermissionCheck) => boolean | Check if user has the requested permission |
exportSettingsToFile | (data: SettingsExportData) => string | — |
filterUsers | ({ users, email, role }: FilterUsersParams) => SettingsUser[] | — |
formatLastActive | (timestamp: string | undefined) => string | — |
formatRoleLabel | (role: string) => string | — |
getByIdsQuery | (ids: string[], allowEmptyArray?: boolean) => string | — |
getByTagsQuery | (filterTags: string[], allowEmptyArray?: boolean) => string | — |
getByTagsWithAlertsQuery | (filterTags: string[], allowEmptyArray?: boolean) => string | — |
getByTagsWithCriticalAlertsQuery | (filterTags: string[], allowEmptyArray?: boolean) => string | — |
getByThingsAttributeQuery | (filterAttributes: FilterAttribute[], selectedTypes: string[], allowEmptyArray?: boolean) => UnknownRecord | — |
getByTypesQuery | (filterTypes: string[], allowEmptyArray?: boolean) => string | — |
getContainerByContainerTagsQuery | (filterTags: string[], allowEmptyArray?: boolean) => string | — |
getContainerMinersByContainerTagsQuery | (filterTags: string[], allowEmptyArray?: boolean) => string | — |
getDeviceByAlertId | (uuid: string) => string | — |
getFiltersQuery | (filterTags?: string[], filters?: Record<string, string[]>, selectedTypes: string[] = ['t-container']) => UnknownRecord | — |
getListQuery | (filterTags: string[], filters?: Record<string, string[]>, selectedTypes: string[] = ['t-container']) => string | — |
getLvCabinetDevicesByRoot | (root: string) => string | — |
getMinersByContainerTagsQuery | (filterTags: string[], allowEmptyArray?: boolean) => string | — |
getRolesFromAuthToken | (authToken?: string) => string[] | Extract roles from authentication token |
getSignInRedirectUrl | (authToken: string | null | undefined) => string | Get redirect URL based on user's primary role |
getSitePowerMeterQuery | () => string | — |
isAntminer | (type: string | undefined) => boolean | — |
isAvalon | (type: string | undefined) => boolean | — |
isContainer | (type: string | undefined) => boolean | — |
isMiner | (type: string | undefined) => boolean | — |
isWhatsminer | (type: string | undefined) => boolean | — |
parseSettingsFile | (file: File) => Promise<SettingsExportData> | — |
removeContainerPrefix | (text: string) => string | — |
validateSettingsJson | (data: unknown) => data is SettingsExportData | — |
Utils
| Name | Signature / Type | Description |
|---|
getLatestSample | (entries: readonly T[] | null | undefined) => T | undefined | Tiny projection helper used by the dashboard's header-stat hooks. |