import { ActionType, DeclarationActionType, DisplayableAction } from './ActionType'; import { EventConfig } from './EventConfig'; import { FieldConfig, FieldReference } from './FieldConfig'; import { Action, ActionDocument, ActionUpdate, EventState } from './ActionDocument'; import { PageConfig, VerificationPageConfig } from './PageConfig'; import { ValidatorContext } from '../conditionals/validate'; import { Draft } from './Draft'; import { EventDocument } from './EventDocument'; import { UUID } from '../uuid'; import { ActionConfig, ActionConfigTypes } from './ActionConfig'; import { FormConfig } from './FormConfig'; import { PlainDate, SelectDateRangeValue } from './FieldValue'; export declare function ageToDate(age: number, asOfDate: PlainDate): string & import("zod").$brand<"PlainDate">; export declare function getDeclarationFields(configuration: EventConfig): FieldConfig[]; export declare function getDeclarationPages(configuration: EventConfig): { id: string; title: { id: string; defaultMessage: string; description: string; }; requireCompletionToContinue: boolean; fields: FieldConfig[]; type: "FORM"; conditional?: any; }[]; export declare function getDeclaration(configuration: EventConfig): { label: { id: string; defaultMessage: string; description: string; }; pages: { id: string; title: { id: string; defaultMessage: string; description: string; }; requireCompletionToContinue: boolean; fields: FieldConfig[]; type: "FORM"; conditional?: any; }[]; }; export declare function isActionConfigType(type: ActionType): type is ActionConfigTypes; export declare function getActionConfig({ eventConfiguration, actionType, customActionType }: { eventConfiguration: EventConfig; actionType: DisplayableAction; customActionType?: string; }): ActionConfig | undefined; export declare function getCustomActionFields(eventConfiguration: EventConfig, customActionType: string): FieldConfig[]; export declare function getPrintCertificatePages(configuration: EventConfig): ({ id: string; title: { id: string; defaultMessage: string; description: string; }; requireCompletionToContinue: boolean; fields: FieldConfig[]; type: "FORM"; conditional?: any; } | { id: string; title: { id: string; defaultMessage: string; description: string; }; requireCompletionToContinue: boolean; fields: FieldConfig[]; type: "VERIFICATION"; actions: { verify: { label: { id: string; defaultMessage: string; description: string; }; }; cancel: { label: { id: string; defaultMessage: string; description: string; }; confirmation: { title: { id: string; defaultMessage: string; description: string; }; body: { id: string; defaultMessage: string; description: string; }; }; }; }; conditional?: any; })[]; export declare const getActionAnnotationFields: (actionConfig: ActionConfig) => FieldConfig[]; export declare function getAllUniqueFields(eventConfig: EventConfig): FieldConfig[]; export declare function getDeclarationFieldById(config: EventConfig, fieldId: string): FieldConfig; /** * @TODO: Request correction should have same format as print certificate */ export declare const findRecordActionPages: (config: EventConfig, actionType: ActionType) => PageConfig[]; export declare function getActionReview(configuration: EventConfig, actionType: ActionType): { title: { id: string; defaultMessage: string; description: string; }; fields: FieldConfig[]; } | undefined; export declare function getActionReviewFields(configuration: EventConfig, actionType: DeclarationActionType): FieldConfig[]; export declare function isPageVisible(page: PageConfig, formValues: ActionUpdate, context: ValidatorContext): boolean; /** * Removes values from the form that correspond to hidden fields. * This function recursively omits any fields from the form values that are not visible * according to their FieldConfig and the current form state. It ensures that only values * for visible fields are retained, which is useful for conditional forms where hidden field * values should not affect validation or submission. * * @template T - The type of the form values * @param {T} formValues - The current form values * @param {FieldConfig[]} fields - The list of field configurations to check visibility against * * @param validatorContext - custom validation context * @returns {Partial} A new object containing only the values for visible fields */ export declare function omitHiddenFields(fields: FieldConfig[], formValues: T, validatorContext: ValidatorContext, includeHiddenFieldsWithNullValues?: boolean): Partial; export declare function omitHiddenPaginatedFields(formConfig: FormConfig, values: T, validatorContext: ValidatorContext, includeHiddenFieldsWithNullValues?: boolean): Partial>; /** * * @returns a draft for the event that has been created since the last non-read action. */ export declare function findActiveDraftForEvent(event: EventDocument, draft: Draft): Draft | undefined; export declare function createEmptyDraft(eventId: UUID, draftId: UUID, actionType: Exclude): Draft; export declare function isVerificationPage(page: PageConfig): page is VerificationPageConfig; export declare function getVisibleVerificationPageIds(pages: PageConfig[], annotation: ActionUpdate, context: ValidatorContext): string[]; export declare function omitHiddenAnnotationFields(actionConfig: ActionConfig, declaration: EventState, annotation: ActionUpdate, context: ValidatorContext): Partial>; /** * Merges two documents together. * * @example deepMerge({'review.signature': { path: '/path.png', type: 'image/png' }}, { foo: 'bar'}) } => { 'review.signature': { path: '/path.png', type: 'image/png' }, foo: 'bar' } * * NOTE: When merging deep objects, the values from the second object will override the first one. * @example { annotation: {'review.signature': { path: '/path.png', type: 'image/png' }}, { annotation: { foo: 'bar'}) } } => { annotation: { foo: 'bar' } } */ export declare function deepMerge, K extends Record>(currentDocument: T, actionDocument: K): T & K; export declare function findLastAssignmentAction(actions: Action[]): { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "REGISTER"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; registrationNumber?: string | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "DUPLICATE_DETECTED"; content: { duplicates: { id: string & import("zod").$brand<"UUID">; trackingId: string; }[]; }; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "EDIT"; content: { comment?: string | undefined; }; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "PRINT_CERTIFICATE"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; content?: { templateId?: string | undefined; } | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "REQUEST_CORRECTION"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "CUSTOM"; customActionType: string; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "CREATE"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "REJECT"; content: { reason: string; }; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "MARK_AS_NOT_DUPLICATE"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "MARK_AS_DUPLICATE"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; content?: { duplicateOf: string & import("zod").$brand<"UUID">; } | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "ARCHIVE"; content: { reason: string; }; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "NOTIFY"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "DECLARE"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "ASSIGN"; assignedTo: string; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "APPROVE_CORRECTION"; requestId: string; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; content?: { immediateCorrection?: boolean | undefined; } | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "REJECT_CORRECTION"; requestId: string; content: { reason: string; }; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "UNASSIGN"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; declaration: Record; status: "Requested" | "Accepted" | "Rejected"; type: "READ"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; annotation?: Record | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | { id: string & import("zod").$brand<"UUID">; transactionId: string; createdByUserType: "user" | "system"; createdAt: string; createdBy: string; type: "CUSTOM" | "NOTIFY" | "DECLARE" | "REGISTER" | "EDIT" | "REJECT" | "ARCHIVE" | "PRINT_CERTIFICATE" | "REQUEST_CORRECTION" | "REJECT_CORRECTION" | "APPROVE_CORRECTION"; status: "Rejected"; createdByRole?: string | undefined; createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined; createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined; originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined; } | undefined; /** * Tell compiler that accessing record with arbitrary key might result to undefined * Use when you **cannot guarantee** that key exists in the record */ export type IndexMap = { [id: string]: T | undefined; }; /** * Recursive union type that mirrors the shape of a form configuration. * * A `FormState` is either: * - A leaf value of type `T` (e.g. a field's current value, error message, or * touched flag), or * - A nested object whose values are themselves `FormState`, representing a * `FIELD_GROUP` whose children each carry their own state. * * This makes it possible to represent form field values as well as metadata * (errors, touched state, etc.) in a single recursive structure that naturally * matches the nesting of the form configuration. */ export type FormState = T | { [id: string]: FormState | undefined; }; /** * Construct a `FormState` map from a list of `FieldConfig` items by applying a * mapper function to every leaf field. * * `FIELD_GROUP` fields are handled recursively: instead of calling `mapper` on * the group itself, `buildFormState` descends into the group's `fields` and * stores the resulting nested state under the group's id. * * Leaf fields for which `mapper` returns `undefined` are omitted from the * result entirely. * * @param fields - Flat or nested list (using FIELD_GROUP) of field configurations * to process. * @param mapper - Called for every non-group field. Return a value to include * that field in the state, or `undefined` to omit it. * @returns A nested state map whose structure mirrors the field hierarchy. * * @example * const fields = [ * { id: 'firstName', type: 'TEXT' }, * { * id: 'address', * type: 'FIELD_GROUP', * fields: [ * { id: 'street', type: 'TEXT'}, * { id: 'city', type: 'TEXT'} * ] * } * ] * // Mark every field as untouched (false) * const touched = buildFormState(fields, () => false) * // { firstName: false, address: { street: false, city: false } } */ export declare function buildFormState(fields: FieldConfig[], mapper: (field: FieldConfig) => T | undefined): IndexMap>; /** * Transform every leaf value in a `FormState` via a mapping function, * preserving the nested structure. * * `undefined` entries are dropped from the result. Objects * are treated as nested groups and traversed recursively * Leaf values are passed to `fn`. * * @param state - The source state to transform. * @param fn - Transformer applied to each leaf value. * @returns A new state with the same shape but with leaf values replaced by the * return value of `fn`. * * @example * // Convert an error state from string[] to boolean (has-error flag) * const hasErrors = mapFormState(formErrors, (msgs) => msgs.length > 0) */ export declare function mapFormState(state: IndexMap>, fn: (leafState: T) => R): IndexMap>; /** * Flatten a nested `FormState` into an array of `[path, value]` pairs, where * `path` is the sequence of keys that leads to the leaf value. * * Empty arrays are treated as "no value" and are omitted from the output. * * @param state - The state to flatten. * @param path - Internal accumulator for the current key path. Callers should * omit this parameter (defaults to `[]`). * @returns An array of `[string[], T]` tuples — one entry per leaf value. * * @example * const errors = { firstName: ['Required'], address: { city: ['Required'] } } * flattenFormState(errors) * // => [ [['firstName'], ['Required']], [['address', 'city'], ['Required']] ] */ export declare function flattenFormState(state: FormState, path?: string[]): Array<[string[], T]>; export declare function flattenFieldReference(ref: FieldReference): string[]; export declare function isWriteAction(actionType: ActionType): boolean; /** * @returns All the fields in the event configuration. */ export declare const findAllFields: (config: EventConfig) => FieldConfig[]; /** * Returns the value of the object at the given path with the ability of resolving mixed paths. See examples. * * @param obj Entity we want to get the value from * @param path property path e.g. `a.b.c` * @param defaultValue * @returns the value of the object at the given path. */ export declare function getMixedPath(obj: Record, path: string, defaultValue?: T | undefined): T | undefined; export declare function getEventConfigById(eventConfigs: EventConfig[], id: string): EventConfig; export declare function timePeriodToDateRange(value: SelectDateRangeValue): { startDate: string; endDate: string; }; export declare function mergeDrafts(currentDraft: Draft, incomingDraft: Draft): Draft; export declare function getPendingAction(actions: Action[]): ActionDocument; export declare function getCompleteActionAnnotation(event: EventDocument, action: ActionDocument): ActionUpdate; /** * Resolves the complete content for an action, inheriting from its original * Requested action when the Accepted action carries no content of its own. * * Mirrors the same "originalActionId → merge from Requested" pattern used by * getCompleteActionAnnotation and getCompleteActionDeclaration. */ export declare function getCompleteActionContent(event: EventDocument, action: ActionDocument): Record | null | undefined; export declare function getCompleteActionDeclaration(declaration: T, event: EventDocument, action: ActionDocument): T; export declare function getAcceptedActions(event: EventDocument): ActionDocument[]; export declare function aggregateActionDeclarations(event: EventDocument): EventState; export declare function aggregateActionAnnotations(event: EventDocument): EventState; //# sourceMappingURL=utils.d.ts.map