UNPKG

@tmlmobilidade/utils

Version:

A collection of utility functions and helpers for the TML Mobilidade Go monorepo, providing common functionality for batching operations, caching, HTTP requests, object manipulation, permissions, and more.

47 lines (46 loc) 2.25 kB
import { type Permission } from '@tmlmobilidade/types'; /** * Get a scope and action filtered Permission object * from a list of User permissions. * @param permissions The full list of permissions of the user. * @param scope The resource scope of the permission to filter by. * @param action The action of the permission to filter by. * @returns The filtered Permission object. * @deprecated Use hasPermissionResource instead. */ export declare function getPermission(permissions: Permission[], scope: string, action: string): Permission; /** * Arguments for hasPermissionResource function. * @param T The type of the resource. */ export interface HasPermissionResourceArgs { action: string; permissions: Permission[]; resource_key: string; scope: string; value: unknown; } /** * Check if a permission exists in a list of permissions, with additional check for a given resource value. * If a `value` exists in a `resource` of a User `permissions` object that * matches the given `action` and `scope`. For example, if you want to check if * a user has access to a specific `agency_id`, you set `value=43` and `resource_key='agency_ids'`. * If the provided `permissions` object contains the value `43` inside the `scope='plans'`, * `action='create'` and `resource_key='agency_ids'` the function will return true. * @param permissions The list of permissions (from a user or request). * @param value The permission value to check against. * @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. * @deprecated Use hasPermissionResource instead. */ export declare function hasPermissionResource({ action, permissions, resource_key, scope, value }: HasPermissionResourceArgs): boolean; /** * Check if a value exists in a resource of a permission from Fastify request. * @param request The FastifyRequest. * @param params The parameters for checking permission. * @returns True if the user has the requested permission, false otherwise. * @deprecated Use hasPermissionResource instead. */ export declare function hasAPIResourcePermission(request: any, params: HasPermissionResourceArgs): boolean;