typed-shopify-storefront
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Typed Storefront

License: MIT GitHub issues

A simple, lightweight, explicit library for interacting with the Shopify Storefront API

Example

import shopify, { ProductVariant, SelectedProductOption, LineIem } from 'typed-shopify-storefront'

const client = shopify({
    accessToken: 'somestore_storefront_token',
    domain: 'somestore.myshopify.com'
})

(async () => {
    // Fetch all products within store
    const collection = await client.product.all()

    // Fetch data of a single product
    const product = await client.product.get(collection[0])

    // Find a product variant from selected options
    const options: SelectedProductOptions[] = [
        { name: "Color", value: "Black" },
        { name: "Size", value: "1" }
    ]
    const variant = client.product.findVariant(product.variants, options)

    // Create a checkout
    const cart: LineItem[] = [
        { variantId: variant.id, amount: 1 }
    ]
    const checkout = await client.checkout.create(cart)

    console.log(checkout.webUrl)
})

Documentation

Initialize the client

const  client = shopify({
    accessToken:  'somestore_storefront_token',
    domain:  'somestore.myshopify.com'
})

Once initialized, the client object is created with methods for interacting with the Shopify API.

Product

Method Description Parameters Returns
all() Retrieves all products from the store. None Collection
get(handle) Retrieves a product by its handle. handle: string Product
findVariant(variants, selectedOptions) Finds a variant of a product based on selected options. variants: ProductVariant[], selectedOptions: SelectedProductOption[] ProductVariant | undefined

Checkout

Method Description Parameters Returns
create(lineItems) Creates a new checkout with specified line items. lineItems: LineItem[] Checkout

Package Sidebar

Install

npm i typed-shopify-storefront

Weekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

36.5 kB

Total Files

63

Last publish

Collaborators

  • 0xalby