import { HOST, Paginacion, paginacionToSearchParams, Paging, } from "./common.js"; export interface PublicationsQuery { paginacion?: Paginacion; productCode?: string; skuCode?: string; variantCode?: string; } export interface Publication { ProductCode: string; Description: string; VariantCode?: string; VariantDescription?: string; SkuCode: string; } export interface PublicationsResponse { Paging: Paging; Data: Publication[]; } // https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos export async function getPublications( token: string, options: PublicationsQuery ): Promise { let searchParams = new URLSearchParams(); paginacionToSearchParams(options.paginacion, searchParams); if (options.skuCode) { searchParams.set("skuCode", options.skuCode); } if (options.productCode) { searchParams.set("productCode", options.productCode); } if (options.variantCode) { searchParams.set("variantCode", options.variantCode); } const res = await fetch( `${HOST}/api/Aperture/Publications?${searchParams.toString()}`, { headers: { accesstoken: token, }, } ); const json = await res.json(); console.debug(json); if (json.Message) { throw new Error(`Tango: ${json.Message}`); } return json; }