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

@kampfire/bulkify

v1.8.2

Published

For handling bulk operations in Shopify

Downloads

27

Readme

Bulkify

Bulkify is a lightweight, efficient Node.js package specifically crafted to manage bulk operations within Shopify stores using Shopify's GraphQL API. It is designed with modern JavaScript and TypeScript in mind, providing strong typing and intelligent autocompletion that enhance developer productivity and code quality.

Key Features

  • Streaming First: Uses async generators to stream results, allowing you to process data as it arrives. This is especially useful for large datasets and memory efficiency.
  • Efficient Bulk Operations: Supports both bulk queries and mutations to handle large datasets efficiently.
  • TypeScript Support: Fully compatible with TypeScript for enhanced development experience.
  • Lightweight Design: Minimal dependencies ensure that the package is lightweight and fast.
  • Error Handling: Robust error handling capabilities to manage and retry failed operations seamlessly.

Installation

You can install Bulkify using your preferred package manager.

npm install @kampfire/bulkify

Usage

Here's a quick start guide to using Bulkify in your project:

import { ApiVersion, shopifyApi } from "@shopify/shopify-api";
import "dotenv/config";
import Bulkify from "@kampfire/bulkify";

async function run() {
  // Use the standard Shopify API client to create a session
  const shopify = shopifyApi({
    adminApiAccessToken: process.env.API_ACCESS_TOKEN,
    apiVersion: ApiVersion.January24,
    hostName: process.env.SHOP_NAME,
  });

  const session = shopify.session.customAppSession(process.env.SHOP_NAME);
  const client = new shopify.clients.Graphql({ session });
  const bulkify = new Bulkify({
    client,
  });

  // Example of a bulk query
  const query = `
  {
    productVariants(query:"tag:test") {
      edges {
        node {
          id
          sku
          price
        }
      }
    }
  }`;

  const { generator } = await bulkify.runBulkQuery(query);
  for await (const variant of generator) {
    console.log(variant);
  }
}

run();

API Reference

These are the main functions and classes provided by Bulkify, however there are additional functions and classes available for more advanced use cases.

Bulkify(options)

  • options.client: A configured Shopify GraphQL client instance.
  • options.resultsPath (optional): The path where results should be stored. Defaults to "./results".
  • options.deleteFiles (optional): Boolean flag to determine if result files should be deleted after processing. Defaults to true.

runBulkQuery(query)

  • query: The GraphQL query string.
  • Returns an async generator yielding query results.

runBulkMutation(mutation, filePath)

  • mutation: The GraphQL mutation string.
  • filePath: Path to the JSONL file containing data for mutations.
  • Returns an async generator yielding mutation results.

processURL(url)

  • Useful for processing a URL returned from a bulk operation (like from a webhook).
  • url: The URL of the resulting JSONL file.
  • Returns an async generator yielding the results of the bulk operation.

Examples

You can find more examples, such as how to do a bulk query and mutation in a couple lines of code to change prices, in the examples directory.

Gotchas

  • You can only have a single bulk operation of each type running per store / app.
  • Nested Queries: When using nested queries, the objects will appear after one another in the returned JSONL. To handle this, you should store the accumulated nested objects in an array and process them once you get to another parent object. See the examples for more details.

Documentation

Check out the official shopify docs on GraphQL and Bulk Operations.

Contributing

If you're interested in contributing to the development of Bulkify, please submit an issue or pull request. We welcome contributions from the community and appreciate your feedback.

License

Bulkify is available under the ISC license.

Author

Matt Oskamp