mirror of
https://github.com/MeshCore-Beacon/beacon-web.git
synced 2026-10-22 20:01:22 +00:00
added channel & observers
This commit is contained in:
1 parent
134289af92
commit
a0caf65a18
23 files changed
+1133
-81
No files matched your search
+40
-2
@@ -1,5 +1,7 @@
|
||||
import { API_BASE, DEFAULT_PAGE_SIZE } from "../lib/constants";
|
||||
import type { CursorPage, PacketSummary, PacketDetail, IataCode } from "../types/api";
|
||||
import type { CursorPage, PacketSummary, PacketDetail, IataCode, BrokerStatus } from "../types/api";
|
||||
import type { ChannelSummary, ChannelMessage } from "../features/channels/types";
|
||||
import type { ObserverSummary, Observer } from "../features/observers/types";
|
||||
|
||||
// typed fetch wrapper with query params
|
||||
|
||||
@@ -16,7 +18,7 @@ class ApiError extends Error {
|
||||
}
|
||||
|
||||
async function request<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T> {
|
||||
const url = new URL(`${API_BASE}${path}`);
|
||||
const url = new URL(`${API_BASE}${path}`, window.location.origin);
|
||||
if (params) {
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (value !== undefined) {
|
||||
@@ -57,4 +59,40 @@ export function getIatas(): Promise<IataCode[]> {
|
||||
return request("/iatas");
|
||||
}
|
||||
|
||||
export function getChannels(params?: { iata?: string; limit?: number }): Promise<ChannelSummary[]> {
|
||||
return request("/channels", {
|
||||
iata: params?.iata,
|
||||
limit: params?.limit,
|
||||
});
|
||||
}
|
||||
|
||||
export function getChannelMessages(
|
||||
channelId: number,
|
||||
params?: { iata?: string; limit?: number },
|
||||
): Promise<ChannelMessage[]> {
|
||||
return request(`/channels/${channelId}/messages`, {
|
||||
iata: params?.iata,
|
||||
limit: params?.limit ?? DEFAULT_PAGE_SIZE,
|
||||
});
|
||||
}
|
||||
|
||||
export function getBrokers(): Promise<BrokerStatus[]> {
|
||||
return request("/brokers");
|
||||
}
|
||||
|
||||
export function getObservers(
|
||||
params?: { iata?: string; type?: string; broker?: string; status?: string },
|
||||
): Promise<ObserverSummary[]> {
|
||||
return request("/observers", {
|
||||
iata: params?.iata,
|
||||
type: params?.type,
|
||||
broker: params?.broker,
|
||||
status: params?.status,
|
||||
});
|
||||
}
|
||||
|
||||
export function getObserver(observerId: string): Promise<Observer> {
|
||||
return request(`/observers/${observerId}`);
|
||||
}
|
||||
|
||||
export { ApiError };
|
||||
Reference in new issue
Block a user