43 lines
982 B
TypeScript
Raw Normal View History

2022-07-21 10:39:53 +02:00
import { hooks, providerFactory } from '@strapi/utils';
interface Permission {
action: string;
2022-07-28 11:57:40 +02:00
subject?: string | object | null;
2022-07-21 10:39:53 +02:00
properties?: object;
conditions?: string[];
}
2022-07-28 11:57:40 +02:00
type Provider = ReturnType<typeof providerFactory>;
2022-07-21 10:39:53 +02:00
2022-07-28 11:57:40 +02:00
interface BaseAction {
actionId: string;
2022-07-21 10:39:53 +02:00
}
2022-07-28 11:57:40 +02:00
interface BaseCondition {
name: string;
handler(...params: unknown[]): boolean | object;
2022-07-21 10:39:53 +02:00
}
interface ActionProvider<T extends Action = Action> extends Provider {}
interface ConditionProvider<T extends Condition = Condition> extends Provider {}
interface PermissionEngine {
2022-07-28 11:57:40 +02:00
hooks: object;
2022-07-21 10:39:53 +02:00
generateAbility(permissions: Permission[], options?: object): Ability;
}
2022-07-28 11:57:40 +02:00
interface BaseAbility {
can: Function;
}
interface AbilityBuilder {
can(permission: Permission): void | Promise<void>;
build(): BaseAbility | Promise<BaseAbility>;
}
2022-07-21 10:39:53 +02:00
interface PermissionEngineParams {
providers: { action: ActionProvider; condition: ConditionProvider };
2022-07-28 11:57:40 +02:00
abilityBuilderFactory(): AbilityBuilder;
2022-07-21 10:39:53 +02:00
}