npm.io
2.22.7 • Published 4d ago

@medusajs/modules-sdk

Licence
MIT
Version
2.22.7
Deps
3
Size
247 kB
Vulns
0
Weekly
0
Stars
36.8K

Medusa logo

@medusajs/modules-sdk

Documentation | Website

Building blocks for digital commerce

Medusa is released under the MIT license. PRs welcome! Discord Chat Follow @medusajs

Modules SDK for Medusa: loads, registers, and links Medusa modules, and builds the Medusa application's module layer, including Query and module links. Medusa uses it internally at startup; in your own code you mostly need its MedusaModule helpers, such as checking whether a module is installed. Import it through @medusajs/framework/modules-sdk, which re-exports this package; importing @medusajs/modules-sdk directly is discouraged.

At a glance

Package @medusajs/modules-sdk
Type Core library
Import from @medusajs/framework/modules-sdk

Features

  • MedusaModule to bootstrap modules and inspect loaded modules, for example with MedusaModule.isInstalled(moduleKey).
  • MedusaApp and the MedusaAppMigrateUp, MedusaAppMigrateDown, and MedusaAppMigrateGenerate functions to load all modules and run their migrations.
  • ModulesDefinition with the definitions of Medusa's built-in modules.
  • moduleProviderLoader to load a module's providers.
  • Link and createQuery to manage module links and query data across modules.

Installation

No separate installation is needed in a Medusa application. It's installed with @medusajs/framework.

Usage

Check that a module is installed before using it, for example in a data migration script:

import { MedusaModule } from "@medusajs/framework/modules-sdk"
import { ExecArgs } from "@medusajs/framework/types"
import { BLOG_MODULE } from "../modules/blog"

export default async function migrateBlogData({ container }: ExecArgs) {
  if (!MedusaModule.isInstalled(BLOG_MODULE)) {
    return
  }

  // ...
}

Resources