export type Attribute = {id: string, name: string, type: 'STRING' | 'NUMERIC' | 'BOOLEAN', value: Record}; export type Attributes = Array | null; export type Brand = string | null; export type Locale = string; export type CategoryLabel = {locale: Locale, value: string}; export type Category = {id?: (string | null) | undefined, labels: Array}; export type Description = {locale: Locale, value: string}; export type Descriptions = Array | null; export type Money = {amount: number, currency: unknown}; export type PriceScope = string | null; export type DiscountPrice = {end_date?: (unknown | null) | undefined, price: Money, scope?: PriceScope | undefined, start_date?: (unknown | null) | undefined}; export type DiscountPrices = Array | null; export type Gtin = {value: string}; export type Gtins = Array; export type ProductId = string; export type Image = {url: string}; export type Images = Array | null; export type AvailableQuantity = number; export type Quantity = {available_quantity: AvailableQuantity, warehouse_code?: string | undefined}; export type Quantities = Array; export type StandardPrice = {price: Money, scope?: PriceScope | undefined}; export type StandardPrices = Array; export type Title = {locale: Locale, value: string}; export type Titles = Array | null; export type Product = {attributes?: Attributes | undefined, brand?: Brand | undefined, category?: (Category | null) | undefined, descriptions?: Descriptions | undefined, discount_prices?: DiscountPrices | undefined, gtins?: Gtins | undefined, id: ProductId, images?: Images | undefined, quantities?: Quantities | undefined, standard_prices?: StandardPrices | undefined, titles?: Titles | undefined}; export type UpsertProductsRequest = {products?: Array<Product> | undefined}; export type CreateApiProductsArgs = {body: UpsertProductsRequest}; export type CreateApiProductsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * upsertProducts - Create or Update your Mirakl Connect Catalog * * POST /products */ export const createApiProducts = async (args: CreateApiProductsArgs, options?: CreateApiProductsOptions) => { const {baseUrl = "https://miraklconnect.com/api", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) 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 };