import { LogContext } from '@balena/jellyfish-logger'; import { AutumnDBSession, Contract, JsonSchema, Kernel } from 'autumndb'; import type { TriggeredActionContract } from './types'; interface GetRequestOptions { currentDate: Date; mode?: 'update' | 'insert'; logContext: LogContext; session: AutumnDBSession; } export declare const matchesContract: (logContext: LogContext, kernel: Kernel, session: AutumnDBSession, filter: JsonSchema, contract: Contract | null) => Promise; /** * @summary Create an action request from a trigger, if it matches, it didn't match before * or one of its fields listed in triggerPaths was changed * @function * @public * * @param kernel - kernel instance * @param trigger - triggered action contract * @param oldContract - contract before the change was applied (null if contract is new) * @param newContract - contract after the change was applied * @param options - options * @returns action request, or null if the trigger doesn't match */ export declare const getRequest: (kernel: Kernel, trigger: TriggeredActionContract, oldContract: Contract | null, newContract: Contract, options: GetRequestOptions) => Promise<{ action: string | undefined; arguments: any; originator: string; logContext: LogContext; currentDate: Date; card: any; } | null>; /** * @summary Get all triggered actions associated with a type * @function * @public * * @param logContext - execution context * @param kernel - kernel instance * @param session - session id * @param type - type slug * @returns triggered actions * * @example * const session = '4a962ad9-20b5-4dd8-a707-bf819593cc84'; * const contracts = await triggers.getTypeTriggers({ ... }, { ... }, session, 'user'); * * for (const contract of contracts) { * console.log(contract); * } */ export declare const getTypeTriggers: (logContext: LogContext, kernel: Kernel, session: AutumnDBSession, type: string) => Promise; /** * @summary Get the start date of a triggered action * @function * @public * * @description * The start date determines when the triggered action should * start taking effect. * This function defaults to epoch if there is no start date. * * @param trigger - triggered action contract * @returns start date * * @example * const date = triggers.getStartDate({ * type: 'triggered-action', * data: { ... }, * }); * * console.log(date.toISOString()); */ export declare const getStartDate: (trigger: TriggeredActionContract) => Date; /** * @summary Get the next execution date for a trigger * @function * @public * * @param trigger - triggered action contract * @param lastExecutionDate - last execution date * @returns next execution date, if any * * @example * const nextExecutionDate = triggers.getNextExecutionDate({ ... }, new Date()); * if (nextExecutionDate) { * console.log(nextExecutionDate.toISOString()); * } */ export declare const getNextExecutionDate: (trigger: TriggeredActionContract, lastExecutionDate?: Date) => Date | null; /** * Parses a JSON schema object for all properties which might be accessed as part of a match * * @param schema JSON schema object to parse * @returns the list of referenced property paths */ export declare function findUsedPropertyPaths(schema: any): string[]; export {};