export type CreateApiISO19848Args = {'X-Package-External-Id'?: string | undefined, 'X-Package-Correlation-Id'?: string | undefined, 'User-Agent'?: string | undefined, body: Record | Record}; export type CreateApiISO19848Options = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * ISO19848 protocol * * POST /ISO19848 */ export const createApiISO19848 = async (args: CreateApiISO19848Args, options: CreateApiISO19848Options) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Package-External-Id'] != null) headers.set("X-Package-External-Id", String(args['X-Package-External-Id'])) if (args['X-Package-Correlation-Id'] != null) headers.set("X-Package-Correlation-Id", String(args['X-Package-Correlation-Id'])) if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/ISO19848${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };