sprint14-19: ABAC UI rule editor + permission templates + bulk share + analytics + delegation + resolution strategies + migrations 0056-0058
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* ABAC Policy API client.
|
||||
*
|
||||
* All requests use the shared `apiClient` (`baseURL: '/api/v1'`) and target
|
||||
* the Policies routes under `/policies/...`.
|
||||
*/
|
||||
|
||||
import { apiDelete, apiGet, apiPost, apiPut } from './client';
|
||||
|
||||
// ─── Types ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export type PrincipalType = 'user' | 'group' | 'role';
|
||||
|
||||
export type ConditionOperator =
|
||||
| 'eq'
|
||||
| 'neq'
|
||||
| 'in'
|
||||
| 'gt'
|
||||
| 'gte'
|
||||
| 'lt'
|
||||
| 'lte'
|
||||
| 'contains'
|
||||
| 'starts_with'
|
||||
| 'is_null';
|
||||
|
||||
export type ConditionGroupLogic = 'AND' | 'OR';
|
||||
|
||||
export interface Condition {
|
||||
id?: string;
|
||||
field: string;
|
||||
operator: ConditionOperator;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface ConditionGroup {
|
||||
id?: string;
|
||||
logic: ConditionGroupLogic;
|
||||
conditions: Condition[];
|
||||
groups?: ConditionGroup[];
|
||||
}
|
||||
|
||||
export interface ABACPolicy {
|
||||
id: string;
|
||||
name: string;
|
||||
entity_type: string;
|
||||
principal_type: PrincipalType;
|
||||
principal_id: string;
|
||||
principal_name?: string | null;
|
||||
effect: 'allow' | 'deny';
|
||||
conditions: ConditionGroup | null;
|
||||
priority: number;
|
||||
enabled: boolean;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface PolicyListResponse {
|
||||
items: ABACPolicy[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface CreatePolicyPayload {
|
||||
name: string;
|
||||
principal_type: PrincipalType;
|
||||
principal_id: string;
|
||||
effect: 'allow' | 'deny';
|
||||
conditions: ConditionGroup | null;
|
||||
priority: number;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface UpdatePolicyPayload {
|
||||
name?: string;
|
||||
principal_type?: PrincipalType;
|
||||
principal_id?: string;
|
||||
effect?: 'allow' | 'deny';
|
||||
conditions?: ConditionGroup | null;
|
||||
priority?: number;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
// ─── API Functions ─────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Fetch all policies for a given entity type.
|
||||
*/
|
||||
export function fetchPolicies(entityType: string): Promise<PolicyListResponse> {
|
||||
return apiGet<PolicyListResponse>(`/policies/${entityType}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a single policy by ID.
|
||||
*/
|
||||
export function fetchPolicy(entityType: string, policyId: string): Promise<ABACPolicy> {
|
||||
return apiGet<ABACPolicy>(`/policies/${entityType}/${policyId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new policy for the given entity type.
|
||||
*/
|
||||
export function createPolicy(
|
||||
entityType: string,
|
||||
payload: CreatePolicyPayload
|
||||
): Promise<ABACPolicy> {
|
||||
return apiPost<ABACPolicy>(`/policies/${entityType}`, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing policy.
|
||||
*/
|
||||
export function updatePolicy(
|
||||
entityType: string,
|
||||
policyId: string,
|
||||
payload: UpdatePolicyPayload
|
||||
): Promise<ABACPolicy> {
|
||||
return apiPut<ABACPolicy>(`/policies/${entityType}/${policyId}`, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a policy.
|
||||
*/
|
||||
export function deletePolicy(entityType: string, policyId: string): Promise<void> {
|
||||
return apiDelete<void>(`/policies/${entityType}/${policyId}`);
|
||||
}
|
||||
Reference in New Issue
Block a user