import { Permission } from '@pickerjs/common/lib/generated-types'; /** * @description * 配置 {@link PermissionDefinition} * * @docsCategory auth * @docsPage PermissionDefinition */ export interface PermissionDefinitionConfig { /** * @description * 权限名,按照惯例,应该是这样的 * UpperCamelCased */ name: string; /** * @description * 权限描述 */ description?: string; /** * @description * 定义该权限是否可以分配给角色。一般来说这个除非在特殊情况下,应该保留为默认为 `true` * * @default true */ assignable?: boolean; /** * @description * 内部权限不会通过 API 暴露,而是保留给特殊的用例,如在 `Owner` 或 `Public` 权限。 * * @default false */ internal?: boolean; } /** * @description * 在生成 GraphQL `Permissions` enum。 * * @internal */ export declare type PermissionMetadata = Required; /** * @description * 定义一个新的权限来控制给 GraphQL resolvers 和 REST controllers 访问。 * 与 {@link Allow} decorator 一起使用(见下方示例). * * **Note:** 定义 CRUD permissions, 使用 {@link CrudPermissionDefinition}. * * @example * ```TypeScript * export const sync = new PermissionDefinition({ * name: 'SyncInventory', * description: 'Allows syncing stock levels via Admin API' * }); * ``` * * ```TypeScript * const config: PickerConfig = { * authOptions: { * customPermissions: [sync], * }, * } * ``` * * ```TypeScript * \@Resolver() * export class ExternalSyncResolver { * * \@Allow(sync.Permission) * \@Mutation() * syncStockLevels() { * // ... * } * } * ``` * @docsCategory auth * @docsPage PermissionDefinition * @docsWeight 0 */ export declare class PermissionDefinition { protected config: PermissionDefinitionConfig; constructor(config: PermissionDefinitionConfig); /** @internal */ getMetadata(): PermissionMetadata[]; /** * @description * 返回权限的定义用于 * {@link Allow} decorator. */ get Permission(): Permission; } /** * @description * 为给定的名称定义一组 CRUD 权限,例如创建一个 `name` 为 `Wishlist` * 将会定义出 4 种权限:'CreateWishlist', 'ReadWishlist', 'UpdateWishlist' & 'DeleteWishlist'. * * @example * ```TypeScript * export const wishlist = new CrudPermissionDefinition('Wishlist'); * ``` * * ```TypeScript * const config: PickerConfig = { * authOptions: { * customPermissions: [wishlist], * }, * } * ``` * * ```TypeScript * \@Resolver() * export class WishlistResolver { * * \@Allow(wishlist.Create) * \@Mutation() * createWishlist() { * // ... * } * } * ``` * * @docsCategory auth * @docsPage PermissionDefinition * @docsWeight 1 */ export declare class CrudPermissionDefinition extends PermissionDefinition { private descriptionFn?; constructor(name: string, descriptionFn?: (operation: 'create' | 'read' | 'update' | 'delete') => string); /** @internal */ getMetadata(): PermissionMetadata[]; /** * @description * 返回定义的 'Create' CRUD 权限用于 * {@link Allow} decorator. */ get Create(): Permission; /** * @description * 返回定义的 'Read' CRUD 权限用于 * {@link Allow} decorator. */ get Read(): Permission; /** * @description * 返回定义的 'Update' CRUD 权限用于 * {@link Allow} decorator. */ get Update(): Permission; /** * @description * 返回定义的 'Delete' CRUD 权限用于 * {@link Allow} decorator. */ get Delete(): Permission; }