Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modules-sdk): External Modules #6275

Open
wants to merge 67 commits into
base: develop
Choose a base branch
from

Conversation

carlos-r-l-rodrigues
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues commented Jan 30, 2024

What:

  • Enable External Modules config
  • Serve MedusaApp as http or grpc servers (Experimental Only. No TLS)
  • http and gRPC clients to communicate with MedusaApp server
// Server
import { MedusaApp, Modules } from "@medusajs/modules-sdk";

async function main() {
  const app = await MedusaApp({
    sharedResourcesConfig: {
      database: {
        clientUrl: "postgres://postgres:postgres@localhost:5432/medusa",
      },
    },
    modulesConfig: {
      [Modules.PRODUCT]: true,
    },
  });
  app.listen("http", 8000).then(() => {
    console.log("MedusaApp Server is running on port 8000");
  });
  app.listen("grpc", 8001).then(() => {
    console.log("Medusa gRPC Server is running on port 8001");
  });
}
main();
// Client
import { MODULE_SCOPE, MedusaApp, Modules } from "@medusajs/modules-sdk";
import { IProductModuleService } from "@medusajs/types";

async function main() {
  const { modules, query } = await MedusaApp({
    sharedResourcesConfig: {
      database: {
        clientUrl: "postgres://postgres:postgres@localhost:5432/medusa",
      },
    },
    modulesConfig: {
      [Modules.PRODUCT]: {
        scope: MODULE_SCOPE.EXTERNAL,
        server: {
          type: "grpc",
          url: "localhost:8001",
        },
      },
    },
  });

  const productService =
    modules.productService as unknown as IProductModuleService;

  await productService.create(
    [
      {
        title: "Product " + Math.random(),
        description: "Product 1",
      },
    ]
  );

  const products = await query({
    product: {
      fields: ["id", "title", "description"],
    },
  });

  console.log(products);
}
main();

Copy link

changeset-bot bot commented Jan 30, 2024

🦋 Changeset detected

Latest commit: 0ba8a61

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@medusajs/modules-sdk Patch
@medusajs/types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 24, 2024 7:01pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) May 24, 2024 7:01pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview May 24, 2024 7:01pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview May 24, 2024 7:01pm

Copy link
Contributor

github-actions bot commented May 3, 2024

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: 2f7b534

@carlos-r-l-rodrigues carlos-r-l-rodrigues changed the title Feat: Medusa app listen feat(modules-sdk): External Modules May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants