Spaces:
Sleeping
Sleeping
File size: 2,012 Bytes
c40c75a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
export interface PermissionInfo {
method: string;
endpoint: string;
description: string;
route: string;
}
/**
* Map of permission endpoint patterns to their descriptions
*/
export const PERMISSION_DESCRIPTIONS: Record<string, string> = {
'/key/generate': 'Member can generate a virtual key for this team',
'/key/update': 'Member can update a virtual key belonging to this team',
'/key/delete': 'Member can delete a virtual key belonging to this team',
'/key/info': 'Member can get info about a virtual key belonging to this team',
'/key/regenerate': 'Member can regenerate a virtual key belonging to this team',
'/key/{key_id}/regenerate': 'Member can regenerate a virtual key belonging to this team',
'/key/list': 'Member can list virtual keys belonging to this team',
'/key/block': 'Member can block a virtual key belonging to this team',
'/key/unblock': 'Member can unblock a virtual key belonging to this team'
};
/**
* Determines the HTTP method for a given permission endpoint
*/
export const getMethodForEndpoint = (endpoint: string): string => {
if (endpoint.includes('/info') || endpoint.includes('/list')) {
return 'GET';
}
return 'POST';
};
/**
* Parses a permission string into a structured PermissionInfo object
*/
export const getPermissionInfo = (permission: string): PermissionInfo => {
const method = getMethodForEndpoint(permission);
const endpoint = permission;
// Find exact match or fallback to default description
let description = PERMISSION_DESCRIPTIONS[permission];
// If no exact match, try to find a partial match based on patterns
if (!description) {
for (const [pattern, desc] of Object.entries(PERMISSION_DESCRIPTIONS)) {
if (permission.includes(pattern)) {
description = desc;
break;
}
}
}
// Fallback if no match found
if (!description) {
description = `Access ${permission}`;
}
return {
method,
endpoint,
description,
route: permission
};
}; |