0.0.1 • Published 5 months ago

@steelrazor47/medusa-plugin-sanity v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Adds Sanity CMS integration to a Medusa V2 backend, closely following the Medusa implementation guide. The following features are available:

  • Embedded Sanity Studio
  • Sync-all admin page
  • Support for redefining/adding schemas for any model
  • Built-in support for the following Medusa models, including admin widgets and subscribers for manual and automatic sync:
    • Product: Title, Description
    • Category: Name
    • Collection: Title
    • Shipping Option: Name

Required configs

Plugin options

import { SanityPluginOptions, sanityOptimizeDeps } from "medusa-plugin-sanity/modules/sanity"

module.exports = defineConfig({
  ...

  admin: {
    backendUrl: process.env.MEDUSA_BACKEND_URL,
    vite: () => ({
      optimizeDeps: {
        include: sanityOptimizeDeps
      }
    }),
  },
  plugins: [
    {
      resolve: "medusa-plugin-sanity",
      options: {
        api_token: process.env.SANITY_API_TOKEN,
        project_id: process.env.SANITY_PROJECT_ID,
        dataset: "development",
        backend_url: process.env.MEDUSA_BACKEND_URL,
        api_version: ...,
        extra_schemas: {
          "custom-model": {
            schema: ...,
            step: ...,
            transformForCreate: ...,
            transformForUpdate: ...,
          }
        }
      } satisfies SanityPluginOptions
    },
  ]

Extra schemas

To implement additional schemas, you MUST define a link from your model to the Sanity module(example). Optionally you can define subscribers(example) and admin widgets(example).

The following is an example of the properties that need to be added to the plugin options for a custom schema:

template

Known issues

  • Studio links and refreshes do not work, Medusa at the moment doesn't support catch-all routes in admin pages