UNPKG

@vansite/ts-sharetribe-flex-sdk

Version:

This is a TypeScript SDK for Sharetribe Flex API. It reduces the complexity of the API and provides a more user-friendly interface.

43 lines 1.61 kB
/** * @fileoverview Client for managing stock levels in the Sharetribe Integration API. * * The Stock API provides atomic `compareAndSet` operations to safely update listing stock * in concurrent environments (e.g. during checkout or inventory sync). * * @see https://www.sharetribe.com/api-reference/integration.html#stock */ import type { AxiosResponse } from "axios"; import IntegrationApi from "./index"; import { ExtraParameter, StockCompareAndSetParameter, StockResponse } from "../../types"; /** * Stock API client (privileged) */ declare class Stock { readonly authRequired = true; private readonly axios; private readonly endpoint; private readonly headers; constructor(api: IntegrationApi); /** * Atomically update stock using compare-and-set * * Fails if current stock doesn't match `oldTotal` — prevents race conditions. * * @template P * @template EP * @param {P & StockCompareAndSetParameter} params * @param {EP} [extraParams] - Optional extra parameters (e.g. `expand: true`) * @returns {Promise<AxiosResponse<StockResponse<"compareAndSet", EP>>>} * * @example * // Reserve 2 units if current stock is 10 * await sdk.stock.compareAndSet({ * listingId: "listing-abc123", * oldTotal: 10, * newTotal: 8 * }); */ compareAndSet<P extends StockCompareAndSetParameter, EP extends ExtraParameter | undefined = undefined>(params: P, extraParams?: EP): Promise<AxiosResponse<StockResponse<"compareAndSet", EP>>>; } export default Stock; //# sourceMappingURL=Stock.d.ts.map