npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@madebywink/shwing

v0.0.53

Published

Shopify Storefront GraphQL Utility

Downloads

122

Readme

Shwing JS

What is it?

A Shopify Storefront API toolkit for Frontend Devs on a time budget.

Powerful!

dev: Code Style

The coding preferences of this repo can be described as:

  • descriptive, helpful, and minimal
  • functional, i.e. currying etc.
  • classless
  • immutable
  • data-safe
  • clean, concise scopes
  • lazy, asynchronous, and (where appropriate) reactive

But most importantly, do the thing.

Setup:

Be sure to check for the latest version here: https://www.npmjs.com/package/@madebywink/shwing

CDN: (i.e. Webflow embed)

<script src="https://cdn.jsdelivr.net/npm/@madebywink/[email protected]/dist/index.min.js"></script>
const Product = shwing.ShopifyProduct(productOptions)
const Cart = shwing.ShopifyProduct(cartOptions)

NPM: (i.e. Svelte component)

npm install --save shwing
import {
    ShopifyProduct,
    ShopifyCart
} from '@madebywink/shwing'

const Product = ShopifyProduct(productOptions)
const Cart = ShopifyProduct(cartOptions)

Cart:

Basic usage:

const options = {
    GQL_ENDPOINT_URL: "https://shopify-store-name.myshopify.com/api/2020-07/graphql",
    STOREFRONT_ACCESS_TOKEN: "aabc1234d5e6f7g0etc",
    onInit: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    },
    onUpdateState: (cartDetails, lineItems, cartNote, customAttributes) => {
        renderLineItems(lineItems)
        replaceCartDetails(cartDetails)
    }
}

const Cart = ShopifyCart(options)

window.onload = async function() {
    await Cart.init()
}

function renderLineItems(lineItems) {
    // do stuff
}

function replaceCartDetails(cartDetails) {
    // do stuff
}

Product:

Basic usage:

const options = {
    GQL_ENDPOINT_URL: "", /* https://shopify-store-name.myshopify.com/api/2020-07/graphql */
    STOREFRONT_ACCESS_TOKEN: "", /* long string of numbers and letters */
    onInit: (defaultProduct, variants) => {
        hydrateProductPage(defaultProduct, variants)
        addFormHandlers()
    },
    handle: "your-product-slug"
}

const Product = ShopifyProduct(options)

window.onload = async function() {
    await Product.init()
}

function hydrateProductPage (defaultProduct, variants) {
    //do stuff
}

function addFormHandlers () {
    // do stuff
}

ShopifyProduct:

const cartOptions = {...}
const Cart = ShopifyCart(cartOptions)

The Cart requires an options object of the following shape:

const options = {
    GQL_ENDPOINT_URL: "", /* https://shopify-store-name.myshopify.com/api/2020-07/graphql */
    STOREFRONT_ACCESS_TOKEN: "", /* long string of numbers and letters */
    onInit: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    },
    onUpdateState: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    }
}

Cart will be a returned Object containing various methods, including an initialization function, Cart mutation functions, getters, and setters.

These methods are only safe to use AFTER initialization.

{
    init() => undefined,
    query: {  
        cartState(onThisUpdate: function) => undefined,
    },
    mutate: {  
        lineItemQuantity(variantId: "...", quantity: 1) => undefined,
        removeLineItem(variantId: "...") => undefined,
        cartNote() => undefined,
        cartCustomAttributes() => undefined,
    },
    get: {
        lineItems() => [...],
        cartDetails() => ({...}),
        cartNote() => "...",
        customAttributes() => [...],
        _checkoutId() => ""
    },
    set: {
        cartNote("..."),
        customAttributes([{key: "", value: ""}])
    }
}

ShopifyCart

const productOptions = {...}
const Product = ShopifyCart(productOptions)

The Product requires an options object of the following shape:

const options = {
    GQL_ENDPOINT_URL: "", /* https://shopify-store-name.myshopify.com/api/2020-07/graphql */
    STOREFRONT_ACCESS_TOKEN: "", /* long string of numbers and letters */
    onInit: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    },
    onUpdateState: (cartDetails, lineItems, cartNote, customAttributes) => {
        // do stuff
    }
}

Product will be a returned Object containing various methods, including an initialization function, an addToCart funciton, getters, and setters.

These methods are only safe to use AFTER initialization.

{
    init() => undefined,
    api: {
        addToCart(customAttributes: [{key: "", value: ""}]) => undefined
    },
    get: {
        selectedVariant() => ({...}),
        deliveryDate() => "...",
        defaultProduct() => ({...}),
        variants() => [...],
        _checkoutId() => "..."
    },
    set: {
        selectedVariant({...}),
        deliveryDate("...")
    }
}

Shwing!

Powerful!