mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-12 21:44:22 +08:00
3c7b347d7b
* perf(nodes): paginate node lists and fetch details directly * fix(nodes): preserve Unicode search and page transition state * fix(nodes): validate search using the UTF-8 byte limit
94 lines
2.5 KiB
TypeScript
94 lines
2.5 KiB
TypeScript
import { OpenFlareBaseService } from './base.service';
|
|
import type {
|
|
NodeAgentReleaseInfo,
|
|
NodeAgentUpdatePayload,
|
|
NodeBootstrapToken,
|
|
NodeItem,
|
|
NodeListQuery,
|
|
NodeListResult,
|
|
NodeMutationPayload,
|
|
NodeObservability,
|
|
ReleaseChannel,
|
|
} from './types';
|
|
|
|
export class NodeService extends OpenFlareBaseService {
|
|
protected static override readonly basePath: string = '/api/v1/d/nodes';
|
|
|
|
static async listNodes(): Promise<NodeItem[]> {
|
|
return this.get<NodeItem[]>('/');
|
|
}
|
|
|
|
static async listNodePage(
|
|
query: NodeListQuery = {},
|
|
): Promise<NodeListResult> {
|
|
return this.get<NodeListResult>('/page', { ...query });
|
|
}
|
|
|
|
static async getNode(id: number): Promise<NodeItem> {
|
|
return this.get<NodeItem>(`/${id}`);
|
|
}
|
|
|
|
static async createNode(payload: NodeMutationPayload): Promise<NodeItem> {
|
|
return this.post<NodeItem>('/', payload);
|
|
}
|
|
|
|
static async updateNode(
|
|
id: number,
|
|
payload: NodeMutationPayload,
|
|
): Promise<NodeItem> {
|
|
return this.post<NodeItem>(`/${id}/update`, payload);
|
|
}
|
|
|
|
static async deleteNode(id: number): Promise<void> {
|
|
return this.post<void>(`/${id}/delete`);
|
|
}
|
|
|
|
static async getBootstrapToken(): Promise<NodeBootstrapToken> {
|
|
return this.get<NodeBootstrapToken>('/bootstrap-token');
|
|
}
|
|
|
|
static async rotateBootstrapToken(): Promise<NodeBootstrapToken> {
|
|
return this.post<NodeBootstrapToken>('/bootstrap-token/rotate');
|
|
}
|
|
|
|
static async requestAgentUpdate(
|
|
id: number,
|
|
payload?: NodeAgentUpdatePayload,
|
|
): Promise<NodeItem> {
|
|
return this.post<NodeItem>(`/${id}/agent-update`, payload ?? {});
|
|
}
|
|
|
|
static async requestForceSync(id: number): Promise<NodeItem> {
|
|
return this.post<NodeItem>(`/${id}/force-sync`);
|
|
}
|
|
|
|
static async requestOpenrestyRestart(id: number): Promise<NodeItem> {
|
|
return this.post<NodeItem>(`/${id}/openresty-restart`);
|
|
}
|
|
|
|
static async getAgentRelease(
|
|
id: number,
|
|
channel: ReleaseChannel = 'stable',
|
|
): Promise<NodeAgentReleaseInfo> {
|
|
return this.get<NodeAgentReleaseInfo>(`/${id}/agent-release`, { channel });
|
|
}
|
|
|
|
static async getObservability(
|
|
id: number,
|
|
options?: { hours?: number; limit?: number },
|
|
): Promise<NodeObservability> {
|
|
return this.get<NodeObservability>(`/${id}/observability`, {
|
|
hours: options?.hours,
|
|
limit: options?.limit,
|
|
});
|
|
}
|
|
|
|
static async cleanupHealthEvents(
|
|
id: number,
|
|
): Promise<{ node_id: string; deleted_count: number }> {
|
|
return this.post<{ node_id: string; deleted_count: number }>(
|
|
`/${id}/observability/cleanup`,
|
|
);
|
|
}
|
|
}
|