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

shopify-orm

v0.0.1

Published

This is a simple ORM for Shopify's MetaObject API. Which simplifies the process of creating, updating, and deleting metaobjects and its definitions. **_Note: This is still in development/alpha and not ready recommended for production use._**

Downloads

132

Readme

[WIP] 🚧 🚀 Shopify MetaObject ORM

This is a simple ORM for Shopify's MetaObject API. Which simplifies the process of creating, updating, and deleting metaobjects and its definitions. Note: This is still in development/alpha and not ready recommended for production use.

🌟 Features

  • Migration Support: Migrate metaobject definitions to Shopify with ease.
  • Simplified MetaObject Management: Easily create, update, and delete Shopify metaobjects.
  • Efficient Schema Definitions: Define metaobject schemas with ease.
  • GraphQL Client Integration: Seamlessly works with Shopify's GraphQL client.
  • CRUD Operations Made Easy: Intuitive methods for all your CRUD needs.
  • Pagination Support: Supports pagination for listing metaobjects.

Screenshots

image

📖 Our Story

Initially developed for internal use in our apps, Shopify MetaObject ORM proved to be a game-changer in how we interacted with Shopify's MetaObject API. It not only enhanced our productivity but also brought an unmatched level of simplicity to complex tasks.

The turning point came when @blanklob tweeted about the need for a simplified approach to managing Shopify's metaobjects. This tweet resonated with our experience, and we were inspired to contribute our solution to the community.

A big shoutout to @blanklob for the inspiration and to the vibrant Shopify developer community for their continuous support and feedback!

🚀 Quick Start Guide

Tune to examples for more examples. I used bun to run the examples. No typescript compilation is required.

Create a graphql client using @shopify/graphql-client

import { createGraphQLClient } from "@shopify/graphql-client";
const client = createGraphQLClient({
  url: "https://myshop.myshopify.com/admin/api/2023-10/graphql.json",
  headers: {
    "Content-Type": "application/json",
    "X-Shopify-Access-Token": "<token>",
  },
  retries: 1,
});

Define your metaobject schema, In below example we are defining a size_chart metaobject with name, config, products, and collections fields.

const sizeChart: OrmSchema = metaobject(
  "size_chart",
  {
    name: {
      name: "name",
      type: "single_line_text_field",
    },
    config: {
      name: "config",
      type: "json",
    },
    products: {
      name: "products",
      type: "list.product_reference",
    },
    collections: {
      name: "collections",
      type: "list.collection_reference",
    },
  },
  {
    displayNameKey: "name",
    capabilities: {
      publishable: {
        enabled: true,
      },
    },
    admin_access: "PUBLIC_READ_WRITE",
    access: {
      admin: "PUBLIC_READ_WRITE",
      storefront: "PUBLIC_READ",
    },
  }
);

Create a db instance using the client

const db = shopifyORM(client);

Create CRUD instances for your metaobjects

const sizeChartSchema = db.metaobject(sizeChart);

Operations

Migrate

When you call migrate function, It will check the metaobject definition in shopify and update it if it is not matching with the local definition. If the metaobject is not present in shopify, It will create it.

const resp = await sizeChartSchema.migrate();

Create

Create a new metaobject by passing data

const createdItems = await sizeChartSchema.create({
  data: {
    name: "Jeans Size Chart",
    config: {
      size: ["S", "M", "L", "XL"],
      waist: ["28", "30", "32", "34"],
    },
    products: ["gid://shopify/Product/8537198461244"],
  },
});

List

List items in items and pageInfo for additional information like hasNextPage, hasPreviousPage, startCursor, endCursor, pageSize.

const items = await sizeChartSchema.list({
  first: 10,
});

Update

Update metaobject by id and data

const item = await sizeChartSchema.update({
  id: "gid://shopify/Metaobject/24441422140",
  data: {
    name: "Jeans Size Chart",
    config: {
      size: ["S", "M", "L", "XL"],
      waist: ["28", "30", "32", "34"],
    },
    products: ["gid://shopify/Product/8537198461244"],
  },
});

Get

Get single item by id

const item = await sizeChartSchema.get({
  id: "gid://shopify/Metaobject/24354980156",
});

Delete

Delete single item by id


const deletedItem = await sizeChartSchema.delete({
  id: "gid://shopify/Metaobject/24354980156",
});

👥 Contributing

We welcome contributions! Please see our contributing guidelines for more details.

📬 Feedback

Your feedback is valuable to us. Please reach out with suggestions or issues.