/// type PermissionAction = '$all' | 'read' | 'create' | 'update' | 'publish_unpublish' | 'delete' | string; type PermissionAssetModule = '$all' | 'folder' | 'asset' | string; type PermissionEntryModule = '$all' | 'content_type' | string; type PermissionTaxonomyModule = '$all' | 'taxonomy' | string; type PermissionModule = PermissionAssetModule | PermissionEntryModule | PermissionTaxonomyModule; export interface PermissionOptionItem { value: PermissionAction | PermissionModule; label: string | string[]; testId?: string; } export interface ModuleOptionItem extends PermissionOptionItem { /** * subLabel, used for placeholder text in Module's Value Select */ subLabel?: string; code?: string; uid?: string | string[]; fallback_locale?: string | string[]; _branches?: string | string[][] | string[]; _workspaces?: string | string[][] | string[]; name?: string | string[]; } export interface PermissionActionOptions { [key: string]: string; } export interface PermissionSubActionMapping { [key: string]: string[]; } export interface Rule { /** Used to determine if rule is CAN or CANNOT */ isCan: boolean; action: { create?: boolean; read?: boolean; update?: boolean; delete?: boolean; publish_unpublish?: boolean; [key: string]: boolean; }; /** On return, the consumer will only get string values */ module: '$all' | 'asset' | 'folder' | 'content_type' | 'taxonomy' | 'locale' | string | ModuleOptionItem; /** The list of asset uids affected by the rule */ assets?: string[] | Record[] | undefined; /** The list of folder uids affected by the rule */ folders?: string[] | Record[] | undefined; /** The list of locale uids affected by the rule */ locales?: string[] | Record[] | undefined; parents?: string[] | Record[] | undefined; hierarchy?: string[] | Record[] | undefined; /** To Disable the rule block */ shouldRestrict?: boolean; formError?: { /** Error/validation message for permission input */ permissionError?: string; /** Error/validation message for module value input */ moduleValueError?: string; [key: string]: any; }; } export interface InternalRule extends Omit { actions: PermissionOptionItem[]; ruleKey?: string; } export type Vendor = 'asset_management' | 'cms' | string; export interface RuleBuilderProps { /** * @vendor The vendor for which the rule builder is being configured. * Used to convert _branches to workspaces & used for other usage */ vendor?: Vendor; /** * @ruleBuildFor Determines the context in which the rule section is being built (e.g., asset, entry). */ ruleBuildFor: 'asset' | 'entry' | 'locale' | string; /** * @isCANRule Indicates if the rule section is a "CAN" rule (true) or "CANNOT" rule (false). */ isCANRule: boolean; /** * @title Title of the rule section. */ title?: string | React.ReactNode; /** * @subTitle Subtitle of the rule section. */ subTitle?: string | React.ReactNode; /** * @ruleDescription Description of the rule. */ ruleDescription?: string | React.ReactNode; /** * @ruleBlockHelpText Help text for the rule block. */ ruleBlockHelpText?: string | React.ReactNode; /** * @onlyBuilder Boolean to render only the builder, not the title, description, & help text. */ onlyBuilder?: boolean; /** * @className Custom class name for the rule builder container. */ className?: string; /** * @permissionSubActionMapping Map of permission actions to their corresponding sub-actions. * @example * * { * $all: ['$all', 'read', 'create', 'update', 'delete', 'publish_unpublish'], * create: ['read', 'create', 'update'], * read: ['read'], * update: ['read', 'update'], * delete: ['read', 'delete'], * publish_unpublish: ['read', 'publish_unpublish'] * } */ permissionSubActionMapping: PermissionSubActionMapping; /** * @permissionActionOptions Key-value mapping of permission actions to their display labels. * @example * { * $all: 'All Permission', * create: 'Create Permission', * read: 'Read Permission', * update: 'Update Permission', * delete: 'Delete Permission', * publish_unpublish: 'Publish/Unpublish Permission' * } */ permissionActionOptions: PermissionActionOptions; /** * @permissionToModuleOptions Map of permission modules to their corresponding module options. * @example * const permissionToModuleOptions = [ * { value: '$all', label: 'All Asset(s) and Folder(s)', testId: 'cs-role-action-all-assets' }, * { * value: 'folder', * label: 'Specific Folder(s)', * subLabel: 'Select Folders', // Placeholder text for folders selection * testId: 'cs-role-action-specific-folders' * }, * { * value: 'asset', * label: 'Specific Asset(s)', * subLabel: 'Select Assets', // Placeholder text for asset selection * testId: 'cs-role-action-specific-assets' * } * ] * * For locale Rule the option item structure should be * [ * { * uid: 'btl123enin', * value: 'btl123enin', * code: 'en-in', * label: ['English (India)', 'English (India) dev'], // Array format for branch feature * _branches: [['main'], ['dev']], // Either _branches or _workspaces supported * fallback_locale: ['en-us'] * }, * { * uid: 'btl123enin', * value: 'btl123enin', * code: 'en-in', * label: 'English (India)', // Without Array for non branch feature * fallback_locale: 'en-us' * } * ] */ permissionToModuleOptions: ModuleOptionItem[]; /** * @hasBranchFeature Indicates if the branch feature is enabled. */ hasBranchFeature: boolean; /** * @assetPickerModalMultiBranchInfo Information for the asset picker modal in a multi-branch context. */ assetPickerModalMultiBranchInfo?: { assets?: string; folders?: string; }; /** * @rules Array of rule objects with action, module, and optional assets/folders. * * @example * // Example of rules structure set in your state: * const rules = [ * { * isCan: true, // Based on isCANRule * action: { create: true, update: true }, * module: 'asset', * // On Page load provide as array of Asset Objects, the array of string is return from component to save in api * assets: ['bltasset1'] || [{ uid: 'bltasset1', name: 'asset1', filename: 'asset1.jpeg' }], * shouldRestrict: false, // To disable this rule block based on cannot rule * }, * { * isCan: true, // Based on isCANRule * action: { read: true }, * module: 'folder', * // On Page load provide as array of Folder Objects, the array of string is return from component to save in api * folders: ['bltfolder2'] || [{ uid: 'bltfolder2', name: 'folder2', filename: 'folder2.jpeg' }] * shouldRestrict: false, * } * ] * */ rules: Rule[]; /** * Handles changes to the rules. * @param rules The updated array of rules. * @returns void */ onRulesChange: (rules: Rule[]) => void; /** * Fetches the items (Module Values like assets, folders in picker modal) data. * @param args The arguments for fetching items data. * @returns void * * In args of fetchItemsData, you will receive default args from component for asset/folder. * @example * You can use these args to customize the data fetching logic. * { * "limit": 30, * "skip": 0, * "query": "", // Search Text entered by user in SearchBar * "folderUid": "cs_root", // UID of folder where user is navigated to * "excludeAssetUids": [], // can be asset uids or folder uids * "sort": { * "id": "name", * "order": "desc" * } * } * */ fetchItemsData?: (args: any) => void; /** * Opens the items chooser modal. * @returns void */ openItemsChooseModal?: () => void; /** * The test ID for the component. */ testId: string; } export interface RuleBlockProps { vendor?: Vendor; rule: Rule | InternalRule; index: number; uniqueKey: string; ruleBuildFor: string; selectActionOptions: any[]; selectModuleOptions: any[]; onPermissionActionChange: (index: number, newValue: any) => void; onModuleChange: (index: number, newValue: any) => void; onDeleteRuleBlock: (index: number) => void; hasBranchFeature: boolean; openItemsChooseModal: () => void; fetchItemsData: (args: any) => void; assetPickerModalMultiBranchInfo?: { assets?: string; folders?: string; }; selectedModuleValue: SelectedModuleValueObj | any; setSelectedModuleValues: (values: SelectedModuleValueObj | ((prevState: SelectedModuleValueObj) => SelectedModuleValueObj)) => void; actionErrorMessage?: string; moduleValueErrorMessage?: string; } export interface RulePermissionModuleSelectProps { vendor?: Vendor; index: number; value: any; isMultiSelect: boolean; selectOptions: any[]; placeholder?: string; type: string; handleChange: (event: any) => void; testId: string; errorMessage?: string; hasBranchFeature?: boolean; } export interface RuleModuleValueSelectProps { rule: Rule | InternalRule; vendor?: Vendor; uniqueKey: string; index: number; placeHolder?: string; setSelectedModuleValues: (values: SelectedModuleValueObj | ((prevState: SelectedModuleValueObj) => SelectedModuleValueObj)) => void; fetchModal: () => void; selectedValue: any; hasBranchFeature: boolean; errorMessage?: string; } export interface SelectedModuleValueObj { [key: number]: { folders?: string[]; assets?: string[]; locales?: string[]; }; } export {};