medusa icon indicating copy to clipboard operation
medusa copied to clipboard

feat(modules-sdk): External Modules

Open carlos-r-l-rodrigues opened this issue 1 year ago • 4 comments

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();

carlos-r-l-rodrigues avatar Jan 30 '24 19:01 carlos-r-l-rodrigues

🦋 Changeset detected

Latest commit: 1bb223348039e50d4676ccf7700b174fbe870a3f

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

This PR includes changesets to release 3 packages
Name Type
@medusajs/modules-sdk Patch
@medusajs/types Patch
integration-tests-http 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

changeset-bot[bot] avatar Jan 30 '24 19:01 changeset-bot[bot]

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 Jun 8, 2024 7:32pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Jun 8, 2024 7:32pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jun 8, 2024 7:32pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jun 8, 2024 7:32pm

vercel[bot] avatar Jan 30 '24 19:01 vercel[bot]

/snapshot-this

carlos-r-l-rodrigues avatar Jan 30 '24 20:01 carlos-r-l-rodrigues

:rocket: 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]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: ca0e0631afb0dd261d372358f6ffe67f92cf7eed

github-actions[bot] avatar Jan 30 '24 20:01 github-actions[bot]

/snapshot-this

carlos-r-l-rodrigues avatar Feb 07 '24 20:02 carlos-r-l-rodrigues

:rocket: 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]
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: 5c6ba674fbdc33e4d2bfe2f95452e1df1030da3f

github-actions[bot] avatar Feb 07 '24 20:02 github-actions[bot]

/snapshot-this

carlos-r-l-rodrigues avatar May 03 '24 18:05 carlos-r-l-rodrigues

:rocket: 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: 2f7b53488dbf1cf0a1bb8b2115679f61d543a745

github-actions[bot] avatar May 03 '24 18:05 github-actions[bot]