Files
bknd/app/src/modules/SystemApi.ts
dswbx eb0822bbff Enhance authentication and authorization components
- Refactored `AppAuth` to introduce `getGuardContextSchema` for improved user context handling.
- Updated `Authenticator` to utilize `pickKeys` for user data extraction in JWT generation.
- Enhanced `Guard` class to improve permission checks and error handling.
- Modified `SystemController` to return context schema alongside permissions in API responses.
- Added new `permissions` method in `SystemApi` for fetching permissions.
- Improved UI components with additional props and tooltip support for better user experience.
2025-10-24 09:14:31 +02:00

63 lines
2.0 KiB
TypeScript

import type { ConfigUpdateResponse } from "modules/server/SystemController";
import { ModuleApi } from "./ModuleApi";
import type { ModuleConfigs, ModuleKey, ModuleSchemas } from "./ModuleManager";
import type { TPermission } from "auth/authorize/Permission";
export type ApiSchemaResponse = {
version: number;
schema: ModuleSchemas;
config: ModuleConfigs;
permissions: string[];
};
export class SystemApi extends ModuleApi<any> {
protected override getDefaultOptions(): Partial<any> {
return {
basepath: "/api/system",
};
}
readConfig() {
return this.get<{ version: number } & ModuleConfigs>("config");
}
readSchema(options?: { config?: boolean; secrets?: boolean; fresh?: boolean }) {
return this.get<ApiSchemaResponse>("schema", {
config: options?.config ? 1 : 0,
secrets: options?.secrets ? 1 : 0,
fresh: options?.fresh ? 1 : 0,
});
}
setConfig<Module extends ModuleKey>(
module: Module,
value: ModuleConfigs[Module],
force?: boolean,
) {
return this.post<ConfigUpdateResponse>(
["config", "set", module].join("/") + `?force=${force ? 1 : 0}`,
value,
);
}
addConfig<Module extends ModuleKey>(module: Module, path: string, value: any) {
return this.post<ConfigUpdateResponse>(["config", "add", module, path], value);
}
patchConfig<Module extends ModuleKey>(module: Module, path: string, value: any) {
return this.patch<ConfigUpdateResponse>(["config", "patch", module, path], value);
}
overwriteConfig<Module extends ModuleKey>(module: Module, path: string, value: any) {
return this.put<ConfigUpdateResponse>(["config", "overwrite", module, path], value);
}
removeConfig<Module extends ModuleKey>(module: Module, path: string) {
return this.delete<ConfigUpdateResponse>(["config", "remove", module, path]);
}
permissions() {
return this.get<{ permissions: TPermission[]; context: object }>("permissions");
}
}