import { registerPendingQueueListener, getPendingQueueSubmissions, cancelEditingPendingQueueSubmission, deletePendingQueueSubmission, editPendingQueueSubmission, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, PendingQueueListener, PendingQueueAction } from './services/pending-queue'; import { FormTypes, SubmissionTypes } from '@oneblink/types'; import { SubmissionParams, ProgressListener, ProgressListenerEvent } from './services/submit'; import { PendingFormSubmission, FormSubmission, FormSubmissionResult, BaseFormSubmission, NewDraftSubmission, NewFormSubmission, DraftSubmission, DraftSubmissionInput } from './types/submissions'; import getPostSubmissionAttachments from './services/api/post-submission-attachment-urls'; /** * Force processing the pending queue. This must be called to process the * pending queue and is best used when the application comes back online. * * ### Example * * ```js * await submissionService.processPendingQueue() * ``` * * @returns */ declare function processPendingQueue({ shouldRunExternalIdGeneration, shouldRunServerValidation, }: { shouldRunExternalIdGeneration: boolean; shouldRunServerValidation: boolean; }): Promise; /** * Submit a FormSubmission. Offline submissions will be added to a pending queue * and be processed using the `processPendingQueue()` function. FormSubmissions * with payment submission events will return the FormSubmissionResult with a * `payment` property set, this should be used to redirect the user to the * payment URL. Will also handle cleaning up auto save data (if the * `autoSaveKey` property is passed), locally stored drafts and prefill data. * * ### Example * * ```js * const formSubmission = { * formsAppId: 1, * submission: { * form: 'data', * goes: 'here', * }, * definition: OneBlinkForm, * captchaTokens: [], * formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233', * jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a', * preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990', * externalId: 'external-id-set-by-developer', * } * * // Pass paymentReceiptUrl if submission may require a payment * const paymentReceiptUrl = `${window.location.origin}/payment-receipt` * * // Pass schedulingBookingUrlConfiguration if submission utilise scheduling * const schedulingBookingUrlConfiguration = { * schedulingBookingUrl: 'https://my-website.com/booking', * schedulingRescheduleUrl: 'https://my-website.com/reschedule', * schedulingCancelUrl: 'https://my-website.com/cancel', * } * const submissionResult = await submissionService.submit({ * formSubmission, * paymentReceiptUrl, * schedulingBookingUrlConfiguration, * }) * * if (submissionResult.scheduling) { * // Redirect user to booking form * window.location.href = submissionResult.scheduling.bookingUrl * return * } * * if (submissionResult.payment) { * // Redirect user to payment form * window.location.href = submissionResult.payment.hostedFormUrl * return * } * * if (submissionResult.isOffline) { * if (submissionResult.isInPendingQueue) { * // Display message to user that the submission * // has been added to the pending queue * } else { * // Display message to user that this submission can * // not be processed while offline (most likely because it requires a payment) * } * return * } * * // submissionResult.submissionId and submissionResult.submissionTimestamp * // will be set if the submission was successful * ``` * * @param params * @returns */ declare function submit(params: SubmissionParams & { autoSaveKey?: string; }): Promise; /** * Go back in the browser history or attempts to close the browser tab if there * is no history. * * ### Example * * ```js * try { * await submissionService.goBackOrCloseWindow() * } catch (error) { * // Handle error while closing browser tab. * // Display message to user to close it manually * } * ``` * * @returns */ declare function goBackOrCloseWindow(): Promise; /** * Action to cancel completing a form, currently goes back in the browser * history or attempts to close the browser tab if there is no history. * * ### Example * * ```js * const options = { * definition: OneBlinkForm, * externalId: 'external-id-set-by-developer', * } * // Only used for relative URLs * const pushRelativePath = (path) => { * window.location.href = path * } * // Only used for aboslute URLS * const replaceAbsolutePath = window.location.replace * * try { * await submissionService.executeCancelAction(options, { * onRedirectToRelativeUrl: pushRelativePath, * onRedirectToAbsoluteUrl: replaceAbsolutePath, * }) * } catch (error) { * // Handle error while closing browser tab. * // Display message to user to close it manually * } * ``` * * @param options * @param redirectConfig */ declare function executeCancelAction(formSubmissionResultOptions: { definition: FormTypes.Form; externalId: string | null; taskCompletion?: FormSubmissionResult['taskCompletion']; }, { onRedirectToRelativeUrl, onRedirectToAbsoluteUrl, }: { onRedirectToRelativeUrl: (url: string) => void; onRedirectToAbsoluteUrl: (url: string) => void; }): Promise; /** * Execute the post submission action for a form after a successful form * submission. * * ### Example * * ```js * const formSubmissionResult = { * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34', * submissionTimestamp: '2020-07-29T01:03:26.573Z' * formsAppId: 1, * submission: { * form: 'data', * goes: 'here' * }, * definition: OneBlinkForm, * payment: { * hostedFormUrl: 'https://payment.com/transaction' * }, * formSubmissionDraftId: '2974602c-2c5b-4b46-b086-87ee9b2aa233', * jobId: 'bb37d1da-9cda-4950-a36a-22f58b25de3a', * preFillFormDataId: '7763f828-4aaf-49dc-9c1b-e2eeea8fa990', * externalId: 'external-id-set-by-developer', * } * // Only used for relative URLs * const pushRelativePath = (path) => { * window.location.href = path * } * // Only used for aboslute URLS * const replaceAbsolutePath = window.location.replace * * try { * await submissionService.executePostSubmissionAction(formSubmissionResult, { * onRedirectToRelativeUrl: pushRelativePath, * onRedirectToAbsoluteUrl: replaceAbsolutePath, * }) * } catch (error) { * // Handle error while closing browser tab. * // Display message to user to close it manually * } * ``` * * @param submissionResult * @param redirectConfig */ declare function executePostSubmissionAction(submissionResult: FormSubmissionResult, { onRedirectToRelativeUrl, onRedirectToAbsoluteUrl, }: { onRedirectToRelativeUrl: (url: string) => void; onRedirectToAbsoluteUrl: (url: string) => void; }): Promise; /** * Retrieve submission data for a known formId and submissionId * * #### Example * * ```js * const formId = 1 * const submissionId = 'fba95b9d-5a9c-463d-ab68-867f431e4120' * const credentials = await formSubmissionService.getSubmissionData({ * formId, * submissionId, * }) * ``` * * @param formId * @param submissionId * @param abortSignal * @returns */ declare function getSubmissionData({ formId, submissionId, abortSignal, }: { formId: number; submissionId: string; abortSignal?: AbortSignal; }): Promise; export { submit, executePostSubmissionAction, executeCancelAction, goBackOrCloseWindow, getPendingQueueSubmissions, deletePendingQueueSubmission, editPendingQueueSubmission, cancelEditingPendingQueueSubmission, registerPendingQueueListener, processPendingQueue, BaseFormSubmission, NewDraftSubmission, NewFormSubmission, DraftSubmissionInput, DraftSubmission, FormSubmission, FormSubmissionResult, PendingFormSubmission, SubmissionParams, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, ProgressListener, ProgressListenerEvent, PendingQueueListener, PendingQueueAction, getSubmissionData, getPostSubmissionAttachments, };