feat: plugins v1
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import type {
|
||||
PluginEventDefinitionSummary,
|
||||
PluginRequirementStatus,
|
||||
PluginRequirementSummary,
|
||||
PluginRequirementsSnapshot
|
||||
} from '../../../../shared-kernel';
|
||||
|
||||
export interface UpsertPluginRequirementRequest {
|
||||
actorUserId: string;
|
||||
reason?: string;
|
||||
status: PluginRequirementStatus;
|
||||
versionRange?: string;
|
||||
}
|
||||
|
||||
export interface UpsertPluginEventDefinitionRequest {
|
||||
actorUserId: string;
|
||||
direction: 'clientToServer' | 'serverRelay' | 'p2pHint';
|
||||
maxPayloadBytes?: number;
|
||||
rateLimitJson?: string;
|
||||
schemaJson?: string;
|
||||
scope: 'server' | 'channel' | 'user' | 'plugin';
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PluginRequirementService {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getSnapshot(apiBaseUrl: string, serverId: string): Observable<PluginRequirementsSnapshot> {
|
||||
return this.http.get<PluginRequirementsSnapshot>(`${this.apiBase(apiBaseUrl)}/servers/${encodeURIComponent(serverId)}/plugins`);
|
||||
}
|
||||
|
||||
upsertRequirement(
|
||||
apiBaseUrl: string,
|
||||
serverId: string,
|
||||
pluginId: string,
|
||||
request: UpsertPluginRequirementRequest
|
||||
): Observable<{ requirement: PluginRequirementSummary }> {
|
||||
return this.http.put<{ requirement: PluginRequirementSummary }>(
|
||||
`${this.apiBase(apiBaseUrl)}/servers/${encodeURIComponent(serverId)}/plugins/${encodeURIComponent(pluginId)}/requirement`,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
upsertEventDefinition(
|
||||
apiBaseUrl: string,
|
||||
serverId: string,
|
||||
pluginId: string,
|
||||
eventName: string,
|
||||
request: UpsertPluginEventDefinitionRequest
|
||||
): Observable<{ eventDefinition: PluginEventDefinitionSummary }> {
|
||||
const eventUrl = `${this.apiBase(apiBaseUrl)}/servers/${encodeURIComponent(serverId)}`
|
||||
+ `/plugins/${encodeURIComponent(pluginId)}/events/${encodeURIComponent(eventName)}`;
|
||||
|
||||
return this.http.put<{ eventDefinition: PluginEventDefinitionSummary }>(
|
||||
eventUrl,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
private apiBase(apiBaseUrl: string): string {
|
||||
return apiBaseUrl.replace(/\/$/, '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user