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

reshuffle-shopify-connector

v0.0.2

Published

Reshuffle Shopify connector

Downloads

3

Readme

reshuffle-shopify-connector

Code | npm | Code sample

npm install reshuffle-shopify-connector

This connector uses Official Node Shopify Client package.

Reshuffle Shopify Connector

This package contains a Reshuffle connector for connecting to Shopify.

The following example listens to Shopify order fulfillment events:

const { Reshuffle } = require('reshuffle')
const { ShopifyConnector } = require('reshuffle-shopify-connector')

const app = new Reshuffle()
const connector = new ShopifyConnector(app, {
  shopName: process.env.SHOPIFY_SHOP_NAME,
  apiKey: process.env.SHOPIFY_API_KEY,
  password: process.env.SHOPIFY_PASSWORD
})
  
connector.on({ topic: 'orders/fulfilled' }, (event, app) => {
  console.log('congratulations! Another order fulfilled')
})

app.start()

Table of Contents

Create Shopify API token

Configuration Options

Connector Events

Listening to Shopify events

Connector Actions

Examples using the SDK

SDK - Retrieve a full Shopify sdk object

Create Shopify API token

Create an API token on your Shopify Admin Page:

  1. Go to https://<your_shop_name>.myshopify.com/admin/apps/private
  2. Click Create new private app,
  3. Provide a name and scopes (keeping in mind that permissions are very limited per default)
  4. Click Save, and you'll get api key and password

Configuration Options

Provide options as below for connecting to Shopify:

const connector = new ShopifyConnector(app, {
  shopName: '<your_shop_name>',
  apiKey: '<your_api_key>',
  password: '<your password>',
})

To use Shopify connector events, you need to provide at least your runtime baseURL. You can also override the default webhookPath and webhookName.

interface ShopifyConnectorConfigOptions extends Shopify.IPrivateShopifyConfig {
  baseURL?: string
  webhookPath?: string // Default to '/reshuffle-shopify-connector/webhook'
}

// Full list of available options to connect to Shopify API
interface IPrivateShopifyConfig {
  shopName: string
  apiKey: string
  password: string
  apiVersion?: string
  autoLimit?: boolean | IAutoLimit
  presentmentPrices?: boolean
  timeout?: number
}

Connector events

Listening to Shopify events

To listen to events happening in Shopify, pass the topic as options to the connector.on function

interface ShopifyConnectorEventOptions {
  topic: WebhookTopic
}

// List extracted from https://github.com/MONEI/Shopify-api-node/blob/master/index.d.ts#L2869
type WebhookTopic =
    | 'app/uninstalled'
    | 'carts/create'
    | 'carts/update'
    | 'checkouts/create'
    | 'checkouts/delete'
    | 'checkouts/update'
    | 'collection_listings/add'
    | 'collection_listings/remove'
    | 'collection_listings/update'
    | 'collections/create'
    | 'collections/delete'
    | 'collections/update'
    | 'customer_groups/create'
    | 'customer_groups/delete'
    | 'customer_groups/update'
    | 'customers/create'
    | 'customers/delete'
    | 'customers/disable'
    | 'customers/enable'
    | 'customers/update'
    | 'draft_orders/create'
    | 'draft_orders/delete'
    | 'draft_orders/update'
    | 'fulfillment_events/create'
    | 'fulfillment_events/delete'
    | 'fulfillments/create'
    | 'fulfillments/update'
    | 'inventory_items/create'
    | 'inventory_items/update'
    | 'inventory_items/delete'
    | 'inventory_levels/connect'
    | 'inventory_levels/update'
    | 'inventory_levels/disconnect'
    | 'locations/create'
    | 'locations/update'
    | 'locations/delete'
    | 'order_transactions/create'
    | 'orders/cancelled'
    | 'orders/create'
    | 'orders/delete'
    | 'orders/fulfilled'
    | 'orders/paid'
    | 'orders/partially_fulfilled'
    | 'orders/updated'
    | 'product_listings/add'
    | 'product_listings/remove'
    | 'product_listings/update'
    | 'products/create'
    | 'products/delete'
    | 'products/update'
    | 'refunds/create'
    | 'shop/update'
    | 'themes/create'
    | 'themes/delete'
    | 'themes/publish'
    | 'themes/update'

Examples of event listeners:

const app = new Reshuffle()
const connector = new ShopifyConnector(app, {
  shopName: '<shop_name>',
  apiKey: '<api_key>',
  password: '<password>',
  baseURL: '<your_reshuffle_runtime_base_url>',
})

connector.on({ topic: 'shop/update' }, async (event, app) => {
  console.log(event.options.topic) // 'shop/update'
  console.log(event) // { id: '<your_shop_id>', name: 'shop name', ... }
})    

connector.on({ topic: 'orders/create' }, async (event, app) => {                             
  console.log(event) // event representing the order just created 
})  

Connector actions

All actions are provided via the sdk. // See full list of actions documentations in Shopify Client Available Resources and Methods

SDK

Full access to the Node Shopify Client SDK

const sdk = await connector.sdk()
Examples using the SDK
  • Get list of products (you can filter them by passing options to list(options))
const products = await connector.sdk().product.list()
console.log(products) // [{ id: 6095693840581, tite: 'Reshuffle cap', created_at: '2020-11-23T15:23:09+13:00', published_scope: 'web', admin_graphql_api_id: 'gid://shopify/Product/6095693840581', ... }]
  • Get list of orders
const orders = await connector.sdk().order.list({ limit: 5 })
console.log(orders)
  • Add a country:
const country = await connector.sdk().country.create({ code: 'FR', tax: 0.25 })
console.log(country) // { id: 381258858693, name: 'France', tax: 0.25, code: 'FR', tax_name: 'FR TVA', provinces: [] }