1.0.7 • Published 2 months ago

typed-shopify-storefront v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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

MethodDescriptionParametersReturns
all()Retrieves all products from the store.NoneCollection
get(handle)Retrieves a product by its handle.handle: stringProduct
findVariant(variants, selectedOptions)Finds a variant of a product based on selected options.variants: ProductVariant[], selectedOptions: SelectedProductOption[]ProductVariant \| undefined

Checkout

MethodDescriptionParametersReturns
create(lineItems)Creates a new checkout with specified line items.lineItems: LineItem[]Checkout
1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago