import { type TriggerType, type UpdateTriggerType } from "./_helpers.js"; import type { CustomObject } from "./custom-object.js"; import { type ExistingManifestContextOptions } from "./existing-manifest-context.js"; import type { Field } from "./field.js"; import type { ManifestComponentDeletion } from "./manifest-builder.js"; export interface RuleDeletionIdentifier { flowId: string; modelRqlName: string; } /** * A single action performed when a {@link Rule} fires. */ export interface RuleAction { /** * The field to set when this action runs. * * Required. */ targetField: Field; /** * Set the target field to a fixed value. Mutually exclusive with `rqlFormula`. * * Optional. For `SelectField` targets, pass one option value or an array of option * values; a scalar is serialized as a single-element array. For `RadioField` targets, * pass exactly one option value as a scalar; arrays are rejected. */ fixedValue?: any; /** * Set the target field to the result of an RQL formula. Mutually exclusive with `fixedValue`. * * Optional. */ rqlFormula?: string; } /** * Initialization properties for {@link Rule}. */ export interface RuleProps { /** * Display name of this automation rule shown in the UI. * * Required. */ flowName: string; /** * When this rule fires. One of `'CREATE'` | `'UPDATE'` | `'CREATE_OR_UPDATE'`. * * Required. The constructor throws if an invalid value is passed. */ triggerType: TriggerType; /** * Stable identifier for this rule. Pass a human-readable slug * (e.g. `'gym_default_enrollment_status'`) to keep it stable across regenerations. * * Optional. Auto-generated when omitted. @default generateId('flow') */ flowId?: string; /** * RQL formula guard — the rule fires only when this expression is truthy. * * Optional. @default null */ rqlCondition?: string; /** * Controls when an `UPDATE` trigger fires relative to the condition. * One of `'MEETS_CONDITION_AFTER_ONLY'` | `'MEETS_CONDITION_BEFORE_OR_AFTER'`. * * Conditional. Required when `triggerType` is `'UPDATE'` or `'CREATE_OR_UPDATE'`. * Must be omitted when `triggerType` is `'CREATE'`. */ updateTriggerType?: UpdateTriggerType; /** * Internal description of this rule (for developer reference only). * * Required. */ description: string; /** * Actions to run when the rule fires. Each action sets one field to a fixed value * or RQL formula result. * * Optional. @default `[]` */ actions?: RuleAction[]; } export interface RuleLoadFromExistingOptions extends ExistingManifestContextOptions { customObjectApiName?: string; } /** * Defines a record-triggered automation rule and registers it with the manifest. * * A rule fires automatically when a record on the parent custom object is created, * updated, or both — depending on `triggerType`. Each rule runs a list of actions * that set field values, optionally guarded by an RQL condition. * * @example * ```ts * new Rule(enrollmentObj, { * flowId: 'gym_default_enrollment_status', * flowName: 'Default attendance to Registered', * triggerType: 'CREATE', * description: 'New roster rows start as Registered unless changed', * actions: [{ targetField: enrollmentAttendanceField, fixedValue: ['Registered'] }], * }); * ``` */ export declare class Rule { static readonly componentType: "CUSTOM_OBJECT_RECORD_TRIGGERED_FLOW"; static toDeletionIdentifier(identifier: RuleDeletionIdentifier): ManifestComponentDeletion; private readonly _flowId; private readonly _customObjectApiName; private readonly _flowName; private readonly _triggerType; private readonly _rqlCondition; private readonly _updateTriggerType; private readonly _description; private readonly _actions; /** * @param customObject - The custom object this rule is attached to. * @param props - Initialization properties. * @throws {Error} If `props.triggerType` is not one of `'CREATE'`, `'UPDATE'`, `'CREATE_OR_UPDATE'`. * @throws {Error} If `props.updateTriggerType` is missing or invalid for update-style triggers. */ constructor(customObject: CustomObject, props: RuleProps); /** * Loads this record-triggered rule from the active existing-manifest JSON context. */ static loadFromExisting(flowId: string, options?: RuleLoadFromExistingOptions): Rule; /** @internal Hydrates a record-triggered rule from existing manifest wire JSON. */ static _fromExistingComponent(customObject: CustomObject, component: Record, resolveField: (apiName: string) => Field): Rule; /** * Returns the stable identifier for this rule (e.g. `'gym_default_enrollment_status'`). */ getFlowId(): string; /** * Returns the api_name of the custom object this rule is attached to. */ getCustomObjectApiName(): string; /** * Serializes this rule to the wire format consumed by the manifest install endpoint. * * @returns A plain object with `type: 'CUSTOM_OBJECT_RECORD_TRIGGERED_FLOW'`. * Optional fields are omitted when unset; `actions` is omitted when empty. */ toDict(): Record; } //# sourceMappingURL=rule.d.ts.map