3.2.16 • Published 8 months ago

@megaads/wm v3.2.16

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@megaads/wm

Installation

To install the library, use npm:

npm install @megaads/wm

Usage

// 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

3.2.16

8 months ago

3.2.15

8 months ago

3.2.14

8 months ago

3.2.13

8 months ago

3.2.12

8 months ago

3.2.11

8 months ago

3.2.10

8 months ago

3.2.9

8 months ago

3.2.8

8 months ago

3.2.7

8 months ago

3.2.6

8 months ago

3.2.5

8 months ago

3.2.4

8 months ago

3.2.3

8 months ago

3.2.2

8 months ago

3.2.1

8 months ago

3.2.0

8 months ago

3.10.0

8 months ago

3.1.9

8 months ago

3.1.8

8 months ago

3.1.7

8 months ago

3.1.6

8 months ago

3.1.5

9 months ago

3.1.4

9 months ago

3.1.3

9 months ago

3.1.2

9 months ago

3.1.0

9 months ago

3.0.9

9 months ago

3.0.8

9 months ago

3.0.7

9 months ago

3.0.6

9 months ago

3.0.5

9 months ago

3.0.4

9 months ago

3.0.3

9 months ago

3.0.2

9 months ago

3.0.1

9 months ago

3.0.0

9 months ago

2.0.9

9 months ago

2.0.8

9 months ago

2.0.7

10 months ago

2.0.6

10 months ago

2.0.5

10 months ago

2.0.4

10 months ago

2.0.3

10 months ago

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago