export type CreateApiCatalogAttributesArgs = {body: {code: string, admin_name: string, type: 'text' | 'textarea' | 'price' | 'boolean' | 'select' | 'multiselect' | 'checkbox' | 'date' | 'datetime' | 'image' | 'file', swatch_type?: (string | null) | undefined, is_required?: boolean | undefined, is_unique?: boolean | undefined, is_filterable?: boolean | undefined, is_configurable?: boolean | undefined, is_visible_on_front?: boolean | undefined, is_comparable?: boolean | undefined, value_per_locale?: boolean | undefined, value_per_channel?: boolean | undefined, enable_wysiwyg?: boolean | undefined, validation?: (string | null) | undefined, default_value?: (string | null) | undefined, position?: number | undefined, translations?: Record | undefined, options?: Array> | undefined}}; export type CreateApiCatalogAttributesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new attribute * * POST /catalog/attributes */ export const createApiCatalogAttributes = async (args: CreateApiCatalogAttributesArgs, options?: CreateApiCatalogAttributesOptions) => { const {baseUrl = "http://localhost:8000/api/admin", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/catalog/attributes${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 (await res.json()) as unknown };