export type WebhookStockSchema = {sku: string, quantity: number | null, quantity_fbm: number | null}; export type StockWebhookMessageSchema = {id: number, event: 'stock.updated', timestamp?: string | undefined, message: Array, subscription_id?: (number | null) | undefined}; export type CreateApiApiV1WebhooksStockUpdatedArgs = {body: StockWebhookMessageSchema}; export type CreateApiApiV1WebhooksStockUpdatedOptions = {baseUrl: string, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stock Updated Webhook * * POST /api/v1/webhooks/stock-updated */ export const createApiApiV1WebhooksStockUpdated = async (args: CreateApiApiV1WebhooksStockUpdatedArgs, options: CreateApiApiV1WebhooksStockUpdatedOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v1/webhooks/stock-updated${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 };