export type ProductObject = {id?: string | undefined, name: string, reference?: string | undefined, description?: string | undefined, normalPrice?: number | undefined, promoPrice?: number | undefined, wholesalePrice?: number | undefined, taxCode?: ('taxCode1' | 'taxCode2' | 'taxCode3' | 'taxCode4' | 'taxCode5') | undefined, category?: string | undefined, imageUrl?: string | undefined, updatedAt?: string | undefined, createdAt?: string | undefined}; export type CreateApiProductsArgs = {body: ProductObject}; export type CreateApiProductsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new product * * POST /products */ export const createApiProducts = async (args: CreateApiProductsArgs, options?: CreateApiProductsOptions) => { const {baseUrl = "https://api.test.bictorys.com/pay/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/products${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 };