Initial commit

This commit is contained in:
root
2025-12-23 18:20:45 -05:00
committed by Sebastian Krupinski
commit ef82b32a6d
24 changed files with 4008 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
import { fetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper';
import type { ApiResponse, Role } from '@/types';
/**
* Role Manager Service
* API client for role management operations
*/
class RoleManagerService {
private baseUrl = '/user/roles';
private transactionCounter = 0;
private getTransaction(): string {
return `txn-${Date.now()}-${++this.transactionCounter}`;
}
/**
* List all roles
*/
async listRoles(): Promise<Role[]> {
const response = await fetchWrapper.post<ApiResponse<Role[]>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'role.list',
data: {}
},
{ skipLogoutOnError: true }
);
return response.data;
}
/**
* Fetch single role
*/
async fetchRole(rid: string): Promise<Role> {
const response = await fetchWrapper.post<ApiResponse<Role>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'role.fetch',
data: { rid }
}
);
return response.data;
}
/**
* Create new role
*/
async createRole(roleData: {
label: string;
description?: string;
permissions?: string[];
}): Promise<Role> {
const response = await fetchWrapper.post<ApiResponse<Role>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'role.create',
data: roleData
}
);
return response.data;
}
/**
* Update role
*/
async updateRole(rid: string, updates: {
label?: string;
description?: string;
permissions?: string[];
}): Promise<boolean> {
const response = await fetchWrapper.post<ApiResponse<boolean>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'role.update',
data: { rid, ...updates }
}
);
return response.data;
}
/**
* Delete role
*/
async deleteRole(rid: string): Promise<boolean> {
const response = await fetchWrapper.post<ApiResponse<boolean>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'role.delete',
data: { rid }
}
);
return response.data;
}
/**
* Get available permissions (grouped with metadata)
*/
async listPermissions(): Promise<import('@/types').PermissionGroup> {
const response = await fetchWrapper.post<ApiResponse<import('@/types').PermissionGroup>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'permissions.list',
data: {}
}
);
return response.data;
}
}
export const roleManagerService = new RoleManagerService();

View File

@@ -0,0 +1,125 @@
import { fetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper';
import type { ApiResponse, User } from '@/types';
/**
* User Manager Service
* API client for user management operations
*/
class UserManagerService {
private baseUrl = '/user/accounts';
private transactionCounter = 0;
private getTransaction(): string {
return `txn-${Date.now()}-${++this.transactionCounter}`;
}
/**
* List all users
*/
async listUsers(filters?: { enabled?: boolean; role?: string }): Promise<User[]> {
const response = await fetchWrapper.post<ApiResponse<User[]>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'user.list',
data: filters || {}
},
{ skipLogoutOnError: true }
);
return response.data;
}
/**
* Fetch single user
*/
async fetchUser(uid: string): Promise<User> {
const response = await fetchWrapper.post<ApiResponse<User>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'user.fetch',
data: { uid }
}
);
return response.data;
}
/**
* Create new user
*/
async createUser(userData: {
identity: string;
label: string;
enabled?: boolean;
roles?: string[];
profile?: Record<string, any>;
}): Promise<User> {
const response = await fetchWrapper.post<ApiResponse<User>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'user.create',
data: userData
}
);
return response.data;
}
/**
* Update user
*/
async updateUser(uid: string, updates: {
label?: string;
enabled?: boolean;
roles?: string[];
profile?: Record<string, any>;
}): Promise<boolean> {
const response = await fetchWrapper.post<ApiResponse<boolean>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'user.update',
data: { uid, ...updates }
}
);
return response.data;
}
/**
* Delete user
*/
async deleteUser(uid: string): Promise<boolean> {
const response = await fetchWrapper.post<ApiResponse<boolean>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'user.delete',
data: { uid }
}
);
return response.data;
}
/**
* Unlink external provider
*/
async unlinkProvider(uid: string): Promise<boolean> {
const response = await fetchWrapper.post<ApiResponse<boolean>>(
`${this.baseUrl}/v1`,
{
version: 1,
transaction: this.getTransaction(),
operation: 'user.provider.unlink',
data: { uid }
}
);
return response.data;
}
}
export const userManagerService = new UserManagerService();