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

@husseyexplores/shopify-api

v2.3.0

Published

Shopify API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks

Downloads

10

Readme

@husseyexplores/shopify-api

Note This library is a patched version of @shopify/[email protected] with a fix for this issue

It exposes two new config options, namely:

  • stateCookieName: string - to override default state cookie name.
  • stateCookieSigned: boolean - To control cookie signing

Just replace all the imports of @shopify/shopify-api with @husseyexplores/shopify-api and you're good to go.

When deploying to firebase, set:

shopifyApi({
  stateCookieName: '__session',
  stateCookieSigned: false,
  ...,
})

License: MIT npm version

This library provides support for the backends of TypeScript/JavaScript Shopify apps to access the Shopify Admin API, by making it easier to perform the following actions:

Once your app has access to the Admin API, you can also access the Shopify Storefront API to run GraphQL queries using the unauthenticated_* access scopes.

This library can be used in any application that runs on one of the supported runtimes. It doesn't rely on any specific framework, so you can include it alongside your preferred stack and only use the features that you need to build your app.

Note: this package will enable your app's backend to work with Shopify APIs, but you'll need to use Shopify App Bridge in your frontend if you're planning on embedding your app into the Shopify Admin.

Requirements

To follow these usage guides, you will need to:

  • have a basic understanding of TypeScript
  • have a Shopify Partner account and development store
  • OR have a test store where you can create a private app
  • have a private or custom app already set up in your test store or partner account
  • use ngrok, in order to create a secure tunnel to your app running on your localhost
  • add the ngrok URL and the appropriate redirect for your OAuth callback route to your app settings
  • have a JavaScript package manager such as yarn installed

Getting started

To install this package, you can run this on your terminal:

# You can use your preferred Node package manager
pnpm add @husseyexplores/shopify-api

Note: throughout these docs, we'll provide some examples of how this library may be used in an app using the Express.js framework for simplicity, but you can use it with any framework you prefer, as mentioned before.

The first thing you need to import is the adapter for your app's runtime. This will internally set up the library to use the right defaults and behaviours for the runtime.

import '@husseyexplores/shopify-api/adapters/node';
import '@husseyexplores/shopify-api/adapters/cf-worker';

Next, configure the library - you'll need some values in advance:

Call shopifyApi (see reference) to create your library object before setting up your app itself:

import '@husseyexplores/shopify-api/adapters/node';
import {shopifyApi, LATEST_API_VERSION} from '@husseyexplores/shopify-api';
import express from 'express';

const shopify = shopifyApi({
  // The next 4 values are typically read from environment variables for added security
  apiKey: 'APIKeyFromPartnersDashboard',
  apiSecretKey: 'APISecretFromPartnersDashboard',
  scopes: ['read_products'],
  hostName: 'ngrok-tunnel-address',
  ...
});

const app = express();

Next steps

Once you configure your app, you can use this package to access the Shopify APIs. See the reference documentation for details on all the methods provided by this package.

See the specific documentation in the Guides section for high-level instructions on how to get API access tokens and use them to query the APIs.

As a general rule, apps will want to interact with the Admin API to fetch / submit data to Shopify. To do that, apps will need to:

  1. Create an Admin API access token by going through the OAuth flow.
  2. Set up its own endpoints to:
    1. Fetch the current session created in the OAuth process.
    2. Create a REST or GraphQL API client.
    3. Use the client to query the appropriate Admin API.

Guides

Migrating to v6

Before v6, this library only worked on Node.js runtimes. It now supports multiple runtimes through the use of adapters, more of which can be added over time. If an adapter for the runtime you wish to use doesn't exist, you can create your own adapter by implementing some key functions, or contribute a PR to this repository.

In addition to updating the library to work on different runtimes, we've also improved its public interface to make it easier for apps to load only the features they need from the library. If you're upgrading an existing app on v5 or earlier, please see the migration guide for v6.