diff --git a/CHANGELOG.md b/CHANGELOG.md index 26a99a21..727e4f2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - BPay handling to NSW GovPay provider +- `formsAppService.getFormSubmissionMetaList()` ## [10.1.2] - 2026-05-07 diff --git a/src/apps/forms-app-service.ts b/src/apps/forms-app-service.ts index 5fa433d9..54cdd3c4 100644 --- a/src/apps/forms-app-service.ts +++ b/src/apps/forms-app-service.ts @@ -1,6 +1,10 @@ -import { FormsAppsTypes, EnvironmentTypes } from '@oneblink/types' +import { + FormsAppsTypes, + EnvironmentTypes, + SubmissionTypes, +} from '@oneblink/types' import tenants from './tenants' -import { HTTPError, getRequest } from './services/fetch' +import { HTTPError, getRequest, searchRequest } from './services/fetch' import { isOffline } from './offline-service' import OneBlinkAppsError from './services/errors/oneBlinkAppsError' import Sentry from './Sentry' @@ -70,3 +74,89 @@ export async function getFormsAppConfiguration( } } } + +/** Query parameters for `GET /forms-apps/:formsAppId/form-submission-meta` */ +export type GetFormSubmissionMetaQuery = { + formId?: number + submissionDateFrom?: string + submissionDateTo?: string + submissionId?: string + externalId?: string + submissionTitle?: string + limit?: number + offset?: number +} + +export type FormSubmissionMetaListResponse = { + meta: { + limit: number | undefined + offset: number | undefined + /** `undefined` means there are no results left to fetch */ + nextOffset: number | undefined + } + formSubmissionMeta: SubmissionTypes.FormSubmissionMeta[] +} + +/** + * List form submission metadata for a Forms App for the current user. + * + * @param formsAppId + * @param query + * @param abortSignal + */ +export async function getFormSubmissionMetaList( + formsAppId: number, + query: GetFormSubmissionMetaQuery = {}, + abortSignal?: AbortSignal, +): Promise { + const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/form-submission-meta` + const searchParameters: Record = { + ...query, + offset: query.offset ?? 0, + } + + try { + return await searchRequest( + url, + searchParameters, + abortSignal, + ) + } catch (err) { + Sentry.captureException(err) + + const error = err as HTTPError + + if (isOffline()) { + throw new OneBlinkAppsError( + 'You are currently offline, please connect to the internet and try again', + { + originalError: error, + isOffline: true, + }, + ) + } + + switch (error.status) { + case 400: + case 404: { + throw new OneBlinkAppsError( + 'We could not find the forms app you are looking for. Please contact support if the problem persists.', + { + originalError: error, + title: 'Invalid Request', + httpStatusCode: error.status, + }, + ) + } + default: { + throw new OneBlinkAppsError( + 'An unknown error has occurred. Please contact support if the problem persists.', + { + originalError: error, + httpStatusCode: error.status, + }, + ) + } + } + } +}