npm package: @megaads/wm
Description: To install the library, use npm:
Author: duytungnguyen.bkhn.95@gmail.com
Latest version: 3.3.12

# @megaads/wm

## Installation

To install the library, use npm:

```sh
npm install @megaads/wm
```
## Usage

```typescript

// Variant Builder
import fetch from "node-fetch";
import WM from "@megaads/wm";

interface Variant {
    id: number;
    slug: string;
    values: Array<{ id: number }>;
}

interface ProductVariant {
    id: number;
    sku: string,
    variants: number[];
    price: number;
    high_price: number;
}

interface Galleries {
    [key: number]: string[];
}

interface FetchDataResult {
    variants: Variant[];
    productVariants: ProductVariant[];
    galleries: Galleries;
}

async function fetchData(productId: number): Promise<FetchDataResult> {
    const variantResponse = await fetch(`https://us-variant.printerval.com/v2/variant/${productId}?ignore_localization=1`);
    const variantDataJson = await variantResponse.json() as { result: { variants: Variant[], productVariants: ProductVariant[] } };

    const variants = variantDataJson.result.variants;
    const productVariants = variantDataJson.result.productVariants;

    const galleryResponse = await fetch(`https://us-variant.printerval.com/gallery/${productId}?ignore_localization=1`);
    const galleriesDataJson = await galleryResponse.json() as { result: Galleries };
    const galleries = galleriesDataJson.result;

    return { variants, productVariants, galleries };
}

async function getDetails(productId: number, productSkuId: number): Promise<void> {
    const { variants, productVariants, galleries } = await fetchData(productId);

    const variantsService = WM.initVarians({
        variants: variants,
        productVariants: productVariants,
        galleries: galleries
    });
    const retVal = variantsService.getProductSkuDetails(productSkuId);
    console.log(JSON.stringify(retVal));
}

getDetails(1000400032, 159658972).then(() => {});

// Get Image Cdn
function getCdnUrl(url: string): void {
    const imagesService = WM.initImages({
        baseCdnUrl: 'https://cdn.printerval.com'
    })

    console.log(imagesWM.getImageCdn(url, 960, 960, false, false, {}));

}

getCdnUrl('https://assets.printerval.com/seller/2024/02/15/womens-espresso-martini-drinking-coffee-lovers-cocktail-bartender-v-neck-t-shirt-15f0742d17528a2355b987d587766f8b.png');

// Format Price
function getPrice(): void {
    const priceService = WM.initPrice({
        currencyUnit: 'USD'
    });

    console.log(priceService.formatPrice(1000000));
}

getPrice();

// print location
const printLocationsService = WM.initPrintLocations([
    {
        "id": 1,
        "name": "Front",
        "value": "front"
    },
    {
        "id": 2,
        "name": "Chest",
        "value": "chest"
    },
    {
        "id": 3,
        "name": "Back",
        "value": "back"
    },
    {
        "id": 4,
        "name": "Chest & Back",
        "value": "chest_back"
    }
], 'us');

console.log(printLocationsService.getAdditionalPrice('chest_back', 7, 10));
```

## Contact
Email: duytungnguyen.bkhn.95@gmail.com