UNPKG

@tomei/live-price

Version:

Tomei live-price Package

33 lines (28 loc) 1.26 kB
import { IPriceData } from '../interfaces/price-data.interface'; export abstract class PriceSourceBase<TProductCategory extends object> { protected sourceName: string; // The name of the price source. protected apiUrl?: string; // Optional URL for the API from which prices can be fetched. protected productCategories: TProductCategory[]; // The category of the product associated with this price source. constructor( sourceName: string, productCategories: TProductCategory[], apiUrl?: string, ) { this.sourceName = sourceName; // Initialize source name. this.productCategories = productCategories; // Initialize product category. this.apiUrl = apiUrl; // Initialize optional API URL. } /** * Fetches the price for a specified product category. * @param productCategory - The category of the product for which the price is to be fetched. * @returns The price as a Promise. */ abstract fetchPrice( productCategories: Record<string, TProductCategory>, ): Promise<Record<string, IPriceData>>; /** * Checks if the price source is active. * @returns A boolean indicating the active status of the price source. */ abstract isActive(): Promise<boolean>; }