All files / src/suppliers SupplierDailyBioUSA.ts

100% Statements 32/32
80% Branches 4/5
100% Functions 1/1
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 691x 1x   1x 1x 1x 1x   1x                     1x 1x 1x 1x   1x 1x   1x 1x   1x 1x 1x   1x 1x   1x   1x 1x 1x   1x                                 1x 1x 12x 12x   9x 9x 1x  
import { parseQuantity } from '@/helpers/quantity';
import { SupplierBaseWix } from './SupplierBaseWix';
 
// Daily Bio USA encodes the pack size in the SKU as a "SIZE" segment: "A932.SIZE.500G",
// "L011.SIZE.1L". The separator is usually a dot but the catalog has comma typos too
// ("A992.SIZE,500G"), so both are accepted.
const SKU_SIZE_REGEX = /\bSIZE\s*[.,]\s*([\d.,]+\s*[A-Za-z]+)/i;
 
/**
 * The SupplierDailyBioUSA module is meant to perform searches and retrieve product details from the
 * US based Biofuran Chem company website which utilizes a Wix ecommerce platform.
 *
 * The website is https://www.dailybiousa.com/
 * @remarks
 *
 * Wix has an exposed GraphQL API which can be used to retrieve product data. The queries are
 * mostly listed in the javascript file `CartIconController.bundle.min.js`.
 * @category Suppliers
 * @source
 */
export class SupplierDailyBioUSA extends SupplierBaseWix implements ISupplier {
  // Name of supplier (for display purposes)
  public static readonly supplierName: string = 'Daily Bio USA';
 
  // Base URL for HTTP(s) requests
  public static readonly baseURL: string = 'https://www.dailybiousa.com/';
 
  // Shipping scope for Biofuran Chem
  public static readonly shipping: ShippingRange = 'domestic';
 
  // The country code of the supplier.
  // This is used to determine the currency and other country-specific information.
  public static readonly country: CountryCode = 'US';
 
  // The payment methods accepted by the supplier.
  public static readonly paymentMethods: PaymentMethod[] = ['ebayonly'];
 
  public readonly ebayStoreURL: string = 'https://www.ebay.com/str/dailybiousa';
 
  // Pure-search supplier: the initial search returns every field and
  // getProductData is a passthrough, so there's no per-product detail to cache.
  protected readonly skipProductDetailCache: boolean = true;
 
  /**
   * Recovers the pack size from the product SKU for the single-size listings that Wix returns
   * with no options and no productItems. Daily Bio USA writes the size into the SKU itself
   * ("A932.SIZE.500G"), which is the only place it appears in machine-readable form on those
   * products, so without this they'd all be dropped for having no quantity. The product name
   * repeats the same catalog code and is checked second, since a handful of listings have
   * something else in the SKU field entirely (one holds a bare price).
   * @param product - The raw Wix product object from the search response
   * @returns The parsed quantity/uom, or nothing when no SIZE segment is found
   * @example
   * ```typescript
   * // product.sku === "A932.SIZE.500G"
   * this.getFallbackQuantity(product); // { quantity: 500, uom: "g" }
   * // product.sku === "LW001", name carries no size either
   * this.getFallbackQuantity(product); // undefined
   * ```
   * @source
   */
  protected override getFallbackQuantity(product: ProductObject): ReturnType<typeof parseQuantity> {
    const sizeMatch = SKU_SIZE_REGEX.exec(product.sku ?? '') ?? SKU_SIZE_REGEX.exec(product.name);
    if (!sizeMatch) return;
 
    return parseQuantity(sizeMatch[1]);
  }
}