export type CreateApiCustomsDeclarationsFileUploadArgs = {Accept: string, 'Content-Type': string, 'X-Badge-Identifier'?: string | undefined, 'X-Eori-Identifier'?: string | undefined, body: BodyInit}; export type CreateApiCustomsDeclarationsFileUploadOptions = {baseUrl?: string | undefined, userRestricted?: string | undefined, fetch?: typeof fetch | undefined}; /** * Submit an upload initiate request * * POST /customs/declarations/file-upload */ export const createApiCustomsDeclarationsFileUpload = async (args: CreateApiCustomsDeclarationsFileUploadArgs, options?: CreateApiCustomsDeclarationsFileUploadOptions) => { const {baseUrl = "https://test-api.service.hmrc.gov.uk", fetch: fetchFn = fetch, userRestricted} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/xml") headers.set('accept', "application/xml") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args['X-Badge-Identifier'] != null) headers.set("X-Badge-Identifier", String(args['X-Badge-Identifier'])) if (args['X-Eori-Identifier'] != null) headers.set("X-Eori-Identifier", String(args['X-Eori-Identifier'])) if (userRestricted !== undefined) headers.set('authorization', `Bearer ${userRestricted}`) const url = `${baseUrl.replace(/\/+$/, '')}/customs/declarations/file-upload${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };