export type GetApiMetaHtmlArgs = {productId?: (number | null) | undefined, bagId?: (number | null) | undefined, contentPageUri?: (string | null) | undefined};
export type GetApiMetaHtmlOptions = {baseUrl: string, fetch?: typeof fetch | undefined};
/**
* Gets an HTML snippet including meta tags for SEO, customized for this product or bag.
*
* GET /meta.html
*/
export const getApiMetaHtml = async (args: GetApiMetaHtmlArgs, options: GetApiMetaHtmlOptions) => {
const {baseUrl, fetch: fetchFn = fetch} = options ?? {}
const query = new URLSearchParams()
const headers = new Headers()
headers.set('accept', "text/html")
if (args.productId != null) query.append("productId", String(args.productId))
if (args.bagId != null) query.append("bagId", String(args.bagId))
if (args.contentPageUri != null) query.append("contentPageUri", String(args.contentPageUri))
const url = `${baseUrl.replace(/\/+$/, '')}/meta.html${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.text()
};