Files
chat/api/server/middleware/accessResources/canAccessSkillResource.js
zeekay 32969de598 fork: rename internal workspace packages to @hanzochat scope
librechat-data-provider  → @hanzochat/data-provider
@librechat/data-schemas  → @hanzochat/data-schemas
@librechat/client        → @hanzochat/client
(@hanzochat/api already forked; external @librechat/agents fork follows)

All imports, package.json names/deps, tsconfig path aliases, jest
moduleNameMapper, and rollup/vite build aliases updated. The data-provider
react-query subpath resolves via the exports map. Lockfiles regenerated in a
follow-on once the canonical package manager is confirmed.
2026-07-14 05:55:49 -07:00

33 lines
1.1 KiB
JavaScript

const { ResourceType } = require('@hanzochat/data-provider');
const { canAccessResource } = require('./canAccessResource');
const { getSkillById } = require('~/models');
/**
* Skill-specific middleware factory that checks skill access permissions.
* Wraps the generic `canAccessResource` with the SKILL resource type and
* `getSkillById` as the ID resolver.
*
* @param {Object} options
* @param {number} options.requiredPermission - Permission bit required (1=view, 2=edit, 4=delete, 8=share)
* @param {string} [options.resourceIdParam='id'] - Route parameter name holding the skill id
* @returns {Function} Express middleware
*/
const canAccessSkillResource = (options) => {
const { requiredPermission, resourceIdParam = 'id' } = options || {};
if (!requiredPermission || typeof requiredPermission !== 'number') {
throw new Error('canAccessSkillResource: requiredPermission is required and must be a number');
}
return canAccessResource({
resourceType: ResourceType.SKILL,
requiredPermission,
resourceIdParam,
idResolver: getSkillById,
});
};
module.exports = {
canAccessSkillResource,
};