import { Observable, BehaviorSubject } from 'rxjs/Rx'; import { ApiRoot } from 'dotcms-js/dotcms-js'; import { ServerSideFieldModel, ServerSideTypeModel } from './ServerSideFieldModel'; import { CoreWebService } from 'dotcms-js/dotcms-js'; import { SiteService } from 'dotcms-js/dotcms-js'; import { Subject } from 'rxjs/Subject'; import { CwError } from 'dotcms-js/dotcms-js'; import { I18nService } from './system/locale/I18n'; export declare const RULE_CREATE = "RULE_CREATE"; export declare const RULE_DELETE = "RULE_DELETE"; export declare const RULE_UPDATE_NAME = "RULE_UPDATE_NAME"; export declare const RULE_UPDATE_ENABLED_STATE = "RULE_UPDATE_ENABLED_STATE"; export declare const V_RULE_UPDATE_EXPANDED_STATE = "V_RULE_UPDATE_EXPANDED_STATE"; export declare const RULE_UPDATE_FIRE_ON = "RULE_UPDATE_FIRE_ON"; export declare const RULE_RULE_ACTION_CREATE = "RULE_RULE_ACTION_CREATE"; export declare const RULE_RULE_ACTION_DELETE = "RULE_RULE_ACTION_DELETE"; export declare const RULE_RULE_ACTION_UPDATE_TYPE = "RULE_RULE_ACTION_UPDATE_TYPE"; export declare const RULE_RULE_ACTION_UPDATE_PARAMETER = "RULE_RULE_ACTION_UPDATE_PARAMETER"; export declare const RULE_CONDITION_GROUP_UPDATE_OPERATOR = "RULE_CONDITION_GROUP_UPDATE_OPERATOR"; export declare const RULE_CONDITION_GROUP_DELETE = "RULE_CONDITION_GROUP_DELETE"; export declare const RULE_CONDITION_GROUP_CREATE = "RULE_CONDITION_GROUP_CREATE"; export declare const RULE_CONDITION_CREATE = "RULE_CONDITION_CREATE"; export declare const RULE_CONDITION_DELETE = "RULE_CONDITION_DELETE"; export declare const RULE_CONDITION_UPDATE_TYPE = "RULE_CONDITION_UPDATE_TYPE"; export declare const RULE_CONDITION_UPDATE_PARAMETER = "RULE_CONDITION_UPDATE_PARAMETER"; export declare const RULE_CONDITION_UPDATE_OPERATOR = "RULE_CONDITION_UPDATE_OPERATOR"; export declare function getNextId(): string; export declare class RuleEngineState { showRules: boolean; globalError: string; loading: boolean; saving: boolean; hasError: boolean; filter: string; deleting: boolean; } export interface IRecord { _id?: string; _saving?: boolean; _saved?: boolean; deleting?: boolean; errors?: any; set?(string: any, any: any): any; } export interface IRuleAction extends IRecord { id?: string; priority: number; type?: string; parameters?: { [key: string]: any; }; owningRule?: string; _owningRule?: RuleModel; } export interface ICondition extends IRecord { id?: string; conditionlet?: string; type?: string; priority?: number; operator?: string; parameters?: { [key: string]: any; }; _type?: ServerSideTypeModel; } export interface IConditionGroup extends IRecord { id?: string; priority: number; operator: string; conditions?: any; } export interface IRule extends IRecord { _id?: string; _expanded?: boolean; _ruleActions?: ActionModel[]; _conditionGroups?: ConditionGroupModel[]; _ruleActionsLoaded?: boolean; _errors?: CwError[]; _saving?: boolean; _saved?: boolean; deleting?: boolean; id?: string; priority?: number; name?: string; fireOn?: string; enabled?: boolean; conditionGroups?: any; ruleActions?: any; set?(string: any, any: any): IRule; } export interface ParameterModel { key: string; value: string; priority: number; } export declare class ActionModel extends ServerSideFieldModel { owningRule: string; _owningRule: RuleModel; constructor(key: string, type: ServerSideTypeModel, priority?: number); isValid(): boolean; } export declare class ConditionModel extends ServerSideFieldModel { operator: string; conditionlet: string; constructor(iCondition: ICondition); isValid(): boolean; } export declare class ConditionGroupModel { key: string; priority: number; operator: string; conditions: { [key: string]: boolean; }; _id: string; _conditions: ConditionModel[]; constructor(iGroup: IConditionGroup); isPersisted(): boolean; isValid(): boolean; } export declare class RuleModel { key: string; name: string; enabled: boolean; priority: number; fireOn: string; conditionGroups: { [key: string]: ConditionGroupModel; }; ruleActions: { [key: string]: boolean; }; _id: string; _expanded: boolean; _conditionGroups: ConditionGroupModel[]; _ruleActions: ActionModel[]; _saved: boolean; _saving: boolean; _deleting: boolean; _errors: { [key: string]: any; }; constructor(iRule: IRule); isPersisted(): boolean; isValid(): boolean; } export declare const DEFAULT_RULE: IRule; export declare class RuleService { _apiRoot: ApiRoot; private _resources; private siteService; private coreWebService; ruleActionTypes$: BehaviorSubject; conditionTypes$: BehaviorSubject; _ruleActionTypes: { [key: string]: ServerSideTypeModel; }; _conditionTypes: { [key: string]: ServerSideTypeModel; }; private _rulesEndpointUrl; private _actionsEndpointUrl; private _conditionTypesEndpointUrl; private _ruleActionTypesEndpointUrl; private _rules$; private _ruleActions; private _conditions; private _ruleActionTypesAry; private _conditionTypesAry; private _rules; _errors$: Subject; static fromServerRulesTransformFn(ruleMap: any): RuleModel[]; static fromClientRuleTransformFn(rule: RuleModel): any; static removeMeta(entity: any): void; static alphaSort(key: any): (a, b) => number; static fromServerServersideTypesTransformFn(typesMap: any): ServerSideTypeModel[]; constructor(_apiRoot: ApiRoot, _resources: I18nService, siteService: SiteService, coreWebService: CoreWebService); createRule(body: RuleModel): Observable; deleteRule(ruleId: string): Observable<{ success: boolean; } | CwError>; loadRules(): Observable; requestRules(siteId: string): void; readonly rules: RuleModel[]; loadRule(id: string): Observable; updateRule(id: string, rule: RuleModel): Observable; getConditionTypes(): Observable; getRuleActionTypes(): Observable; _doLoadRuleActionTypes(): Observable; _doLoadConditionTypes(): Observable; private _preCacheCommonResources(resources); private sendLoadRulesRequest(siteId); private loadActionTypes(); private actionAndConditionTypeLoader(requestObserver, typeMap); private loadConditionTypes(); /** * Return the Site Id or Page Id for the rules operations. * First will check if the realmId parameter is included in the url. * If not then search for the current site Id. * @returns string */ private loadRulesSiteId(); }