import { getLatestFormSubmissionDraftVersion } from './services/draft-data-store'; import { SubmissionTypes } from '@oneblink/types'; import { DraftSubmission, DraftSubmissionInput, LocalFormSubmissionDraft, ProgressListener } from './types/submissions'; export type PriorityFn = (a: SubmissionTypes.FormSubmissionDraft, b: SubmissionTypes.FormSubmissionDraft) => number; /** * Register a listener function that will be passed an array of Drafts when a * draft is added, updated or deleted. * * #### Example * * ```js * const listener = async (drafts) => { * // use drafts here... * } * const deregister = await draftService.registerDraftsListener(listener) * * // When no longer needed, remember to deregister the listener * deregister() * ``` * * @param listener * @returns */ declare function registerDraftsListener(listener: (drafts: LocalFormSubmissionDraft[]) => unknown): () => void; /** * Create or update a Draft in the local store and sync it with remote drafts. * Will also handle cleaning up auto save data (if the `autoSaveKey` property is * passed). * * #### Example * * ```js * const abortController = new AbortController() * const formSubmissionDraftId = 'd3aeb944-d0b3-11ea-87d0-0242ac130003' // pass `undefined` to create a new draft * const autoSaveKey = 'SET ME TO DELETE AUTOSAVE DATA AFTER SAVING DRAFT' * const draftSubmissionInput = { * title: 1, * formsAppId: 1, * submission: { * form: 'data', * goes: 'here', * }, * definition: { * form: 'definition', * goes: 'here', * }, * } * await draftService.upsertDraft({ * formSubmissionDraftId, * autoSaveKey, * draftSubmissionInput, * abortSignal: abortController.signal, * onProgress: (progress) => { * // ... * }, * }) * ``` * * @param options * @returns */ declare function upsertDraft({ formSubmissionDraftId, draftSubmissionInput, autoSaveKey, onProgress, abortSignal, pendingTimestamp, }: { formSubmissionDraftId: string | undefined; draftSubmissionInput: DraftSubmissionInput; autoSaveKey?: string; onProgress?: ProgressListener; abortSignal?: AbortSignal; pendingTimestamp?: string; }): Promise; /** * Get an array of Drafts for the currently logged in user. * * #### Example * * ```js * const drafts = await draftService.getDrafts() * ``` * * @param abortSignal - Signal to abort the requests * @returns */ declare function getDrafts(abortSignal?: AbortSignal): Promise; /** * Get an array of Drafts that have been submitted publicly on this device. * * #### Example * * ```js * const drafts = await draftService.getPublicDrafts() * ``` * * @returns */ declare function getPublicDrafts(): Promise; /** * Get a single Draft and the associated submission data. * * #### Example * * ```js * const draftId = 'd3aeb944-d0b3-11ea-87d0-0242ac130003' * const { draft, draftData, lastElementUpdated } = * await draftService.getDraftAndData(draftId) * // use "draftData" to prefill a from * ``` * * @param draftId * @returns */ declare function getDraftAndData(formsAppId: number, formSubmissionDraftId: string | undefined | null, abortSignal: AbortSignal | undefined): Promise; /** * Remove a draft from the local store and sync with remote drafts. * * #### Example * * ```js * const draftId = 'd3aeb944-d0b3-11ea-87d0-0242ac130003' * await draftService.deleteDraft(draftId) * ``` * * @param draftId * @param formsAppId * @returns */ declare function deleteDraft(formSubmissionDraftId: string, formsAppId: number, abortSignal?: AbortSignal): Promise; /** * Force a sync of remote drafts with locally stored drafts. This function will * swallow all errors thrown unless `true` is passed for the `throwError` * property. * * #### Example * * ```js * await draftService.syncDrafts({ * throwError: true, * formsAppId: 1, * }) * ``` * * @param param0 * @returns */ declare function syncDrafts({ priorityFn, formsAppId, throwError, abortSignal, }: { /** The id of the OneBlink Forms App to sync drafts with */ formsAppId: number; /** * Function used to determine the order of the draft downloads. It is expected * to return a negative value if the first argument is less than the second * argument, zero if they're equal, and a positive value otherwise. */ priorityFn?: PriorityFn; /** `true` to throw errors while syncing */ throwError?: boolean; /** Signal to abort the requests */ abortSignal?: AbortSignal; }): Promise; export { registerDraftsListener, upsertDraft, getDraftAndData, getDrafts, getPublicDrafts, deleteDraft, syncDrafts, getLatestFormSubmissionDraftVersion, LocalFormSubmissionDraft, };