UNPKG

@tmlmobilidade/utils

Version:

This package provides a collection of common utility functions used across projects within the organization.

46 lines (45 loc) 1.83 kB
import { type Permission } from '@tmlmobilidade/types'; /** * Get a permission from a list of permissions * @param permissions - The list of permissions * @param scope - The scope of the permission * @param action - The action of the permission * @returns The permission */ export declare function getPermission(permissions: Permission<unknown>[], scope: string, action: string): Permission<unknown>; /** * Check if a permission exists in a list of permissions * @param permissions - The list of permissions * @param scope - The scope of the permission * @param action - The action of the permission * @returns The permission */ export declare function hasPermission(permissions: Permission<unknown>[], scope: string, action: string): boolean; export interface HasPermissionResourceArgs<T> { action: string; resource_key: keyof T; scope: string; value: unknown; } type HasPermissionResourceArgsWithPermissions<T> = HasPermissionResourceArgs<T> & { permissions: Permission<T>[]; }; /** * Check if a value exists in a resource of a permission * @param permissions - The list of permissions * @param value - The value to check * @param resource_key - The key of the resource * @param scope - The scope of the permission * @param action - The action of the permission * @returns The permission */ export declare function hasPermissionResource<T>({ action, permissions, resource_key, scope, value }: HasPermissionResourceArgsWithPermissions<T>): boolean; /** * Ensure a permission is granted in a fastify request * @param request - The FastifyRequest * @param reply - The FastifyReply * @param params - The parameters of the permission * @returns The allowed */ export declare function hasAPIResourcePermission<T>(request: any, params: HasPermissionResourceArgs<T>): boolean; export {};