export type GetApiCustomsDeclarationsInformationSearchArgs = {partyRole: string, declarationCategory: string, eori?: string | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, goodsLocationCode?: string | undefined, declarationStatus?: string | undefined, pageNumber?: number | undefined, Accept: string, 'X-Badge-Identifier'?: string | undefined, 'X-Submitter-Identifier'?: string | undefined}; export type GetApiCustomsDeclarationsInformationSearchOptions = {baseUrl?: string | undefined, userRestricted?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search for declarations * * GET /customs/declarations-information/search */ export const getApiCustomsDeclarationsInformationSearch = async (args: GetApiCustomsDeclarationsInformationSearchArgs, options?: GetApiCustomsDeclarationsInformationSearchOptions) => { const {baseUrl = "https://test-api.service.hmrc.gov.uk", fetch: fetchFn = fetch, userRestricted} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/xml") if (args.partyRole != null) query.append("partyRole", String(args.partyRole)) if (args.declarationCategory != null) query.append("declarationCategory", String(args.declarationCategory)) if (args.eori != null) query.append("eori", String(args.eori)) if (args.dateFrom != null) query.append("dateFrom", String(args.dateFrom)) if (args.dateTo != null) query.append("dateTo", String(args.dateTo)) if (args.goodsLocationCode != null) query.append("goodsLocationCode", String(args.goodsLocationCode)) if (args.declarationStatus != null) query.append("declarationStatus", String(args.declarationStatus)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['X-Badge-Identifier'] != null) headers.set("X-Badge-Identifier", String(args['X-Badge-Identifier'])) if (args['X-Submitter-Identifier'] != null) headers.set("X-Submitter-Identifier", String(args['X-Submitter-Identifier'])) if (userRestricted !== undefined) headers.set('authorization', `Bearer ${userRestricted}`) const url = `${baseUrl.replace(/\/+$/, '')}/customs/declarations-information/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };