import { ConfigArg } from '@vendure/common/lib/generated-types'; import { RequestContext } from '../../api/common/request-context'; import { ConfigArgs, ConfigArgValues, ConfigurableOperationDef, ConfigurableOperationDefOptions } from '../../common/configurable-operation'; import { Order } from '../../entity/order/order.entity'; import { Promotion } from '../../entity/promotion/promotion.entity'; export type PromotionConditionState = Record; export type CheckPromotionConditionResult = boolean | PromotionConditionState; /** * @description * A function which checks whether or not a given {@link Order} satisfies the {@link PromotionCondition}. * * The function should return either a `boolean` or and plain object type: * * * `false`: The condition is not satisfied - do not apply PromotionActions * * `true`: The condition is satisfied, apply PromotionActions * * `{ [key: string]: any; }`: The condition is satisfied, apply PromotionActions * _and_ pass this object into the PromotionAction's `state` argument. * * @docsCategory promotions * @docsPage promotion-condition */ export type CheckPromotionConditionFn = (ctx: RequestContext, order: Order, args: ConfigArgValues, promotion: Promotion) => R | Promise; /** * @description * This object is used to configure a PromotionCondition. * * @docsCategory promotions * @docsPage promotion-condition * @docsWeight 1 */ export interface PromotionConditionConfig extends ConfigurableOperationDefOptions { code: C; check: CheckPromotionConditionFn; priorityValue?: number; } /** * @description * PromotionConditions are used to create {@link Promotion}s. The purpose of a PromotionCondition * is to check the order against a particular predicate function (the `check` function) and to return * `true` if the Order satisfies the condition, or `false` if it does not. * * @docsCategory promotions * @docsPage promotion-condition * @docsWeight 0 */ export declare class PromotionCondition extends ConfigurableOperationDef { /** * @description * Used to determine the order of application of multiple Promotions * on the same Order. See the {@link Promotion} `priorityScore` field for * more information. * * @default 0 */ readonly priorityValue: number; private readonly checkFn; get code(): C; constructor(config: PromotionConditionConfig); /** * @description * This is the function which contains the conditional logic to decide whether * a Promotion should apply to an Order. See {@link CheckPromotionConditionFn}. */ check(ctx: RequestContext, order: Order, args: ConfigArg[], promotion: Promotion): Promise; }