### Install @lambdacurry/medusa-product-reviews Plugin Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Instructions for installing the product reviews plugin using yarn, including support for yarn workspaces. ```bash yarn add @lambdacurry/medusa-product-reviews # or, if you're using yarn workspaces yarn workspace my-app add @lambdacurry/medusa-product-reviews ``` -------------------------------- ### Install @lambdacurry/medusa-webhooks Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/webhooks/README.md Instructions for installing the @lambdacurry/medusa-webhooks plugin using npm or yarn. ```bash npm install @lambdacurry/medusa-webhooks # or yarn add @lambdacurry/medusa-webhooks ``` -------------------------------- ### Monorepo Package Installation Configuration Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Example of `package.json` configuration for monorepos using `installConfig.hoistingLimits` to manage package installation locations. ```json // monorepo/path-to/your-app/package.json { "installConfig": { "hoistingLimits": "workspaces" }, } ``` -------------------------------- ### Install @lambdacurry/medusa-plugins-sdk Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Installs the SDK package using yarn. Supports both standard installations and installations within yarn workspaces. ```bash yarn install @lambdacurry/medusa-plugins-sdk # or, if you're using yarn workspaces yarn workspace my-app add @lambdacurry/medusa-plugins-sdk ``` -------------------------------- ### Store SDK: Get Product Review Statistics Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to retrieve product review statistics for the store, with optional query parameters. ```typescript // Get review statistics const stats = await sdk.store.productReviews.listStats( query: StoreListProductReviewStatsQuery, headers?: ClientHeaders ); ``` -------------------------------- ### Run Medusa Database Migrations Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Command to execute database migrations after installing and configuring the product reviews plugin. ```bash yarn medusa db:migrate ``` -------------------------------- ### Run Medusa Migrations Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/webhooks/README.md Command to run database migrations after installing and configuring the @lambdacurry/medusa-webhooks plugin. ```bash yarn medusa db:migrate ``` -------------------------------- ### Clone and Install Medusa Plugins Source: https://github.com/lambda-curry/medusa-plugins/blob/main/README.md This snippet demonstrates how to clone the Medusa plugins repository, install its dependencies using yarn, and build the project for testing. ```bash git clone https://github.com/lambda-curry/medusa-plugins.git yarn install yarn build ``` -------------------------------- ### Store SDK: List Product Reviews Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to list product reviews for the store, including query parameters and client headers. ```typescript // List product reviews const { reviews, count } = await sdk.store.productReviews.list( query: StoreListProductReviewsQuery, headers?: ClientHeaders ); ``` -------------------------------- ### Webhook Subscriber Example with Medusa Workflows Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/webhooks/README.md An example TypeScript subscriber demonstrating how to use the @lambdacurry/medusa-webhooks plugin's workflows (`getWebhooksSubscriptionsWorkflow`, `sendWebhooksEventsWorkflow`, `fullWebhooksSubscriptionsWorkflow`) to handle product creation and update events. ```typescript import { SubscriberArgs, SubscriberConfig, } from "@medusajs/framework/subscribers"; import { getWebhooksSubscriptionsWorkflow, sendWebhooksEventsWorkflow, fullWebhooksSubscriptionsWorkflow, } from "@lambdacurry/medusa-webhooks/workflows"; export const config: SubscriberConfig = { event: ["product.created", "product.updated"], context: { subscriberId: "product-added", }, }; export default async function handleProductAdded({ event: { name }, container, }: SubscriberArgs<{ id: string }>): Promise { const query = container.resolve("query"); const logger = container.resolve("logger"); // Fetch product data const { data: productResult } = await query.graph({ entity: "product", fields: ["*"], }); const product = productResult[0]; if (!product) { logger.error("Product not found"); return; } // Option 1: Use the full workflow (recommended for most cases) const fullResult = await fullWebhooksSubscriptionsWorkflow(container).run({ input: { eventName: name, eventData: product, }, }); // Option 2: Use separate workflows for more control const { results: webhooks } = await getWebhooksSubscriptionsWorkflow( container ).run({ input: { eventName: name, eventData: product, }, }); const sendResult = await sendWebhooksEventsWorkflow(container).run({ input: { webhooks, eventData: product, }, }); console.log(fullResult); // or console.log(sendResult); } ``` -------------------------------- ### Install Medusa Braintree Plugin Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/providers/payment-braintree/README.md Installs the Braintree payment provider plugin for your Medusa project using npm. ```bash npm install medusa-plugin-braintree ``` -------------------------------- ### Install Braintree Payment Provider (Bash) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/README.md Installs the Braintree payment provider plugin for Medusa using npm. ```bash npm install @lambdacurry/medusa-payment-braintree ``` -------------------------------- ### Admin SDK: List Product Reviews Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to list product reviews within the admin panel, accepting query parameters. ```typescript // List reviews const { reviews, count } = await sdk.admin.productReviews.list( query: AdminListProductReviewsQuery ); ``` -------------------------------- ### Install @lambdacurry/medusa-plugin-event-bus-redis-dashboard Source: https://github.com/lambda-curry/medusa-plugins/blob/main/v1/packages/event-bus-dashboard/README.md Installs the event bus redis dashboard plugin using yarn. ```bash yarn add @lambdacurry/medusa-plugin-event-bus-redis-dashboard ``` -------------------------------- ### Add Plugin to Medusa Project Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Commands to add the locally published plugin to a Medusa project and install dependencies, especially for monorepos. ```bash cd path/to/your/medusa-application yarn medusa plugin:add @lambdacurry/medusa-product-reviews # If you are yarn with a monorepo, you may also need to run yarn install ``` -------------------------------- ### Configure Medusa with Product Reviews Plugin Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example of how to add the @lambdacurry/medusa-product-reviews plugin to your Medusa application's medusa-config.ts file, with an optional default review status. ```javascript module.exports = defineConfig({ plugins: [ { resolve: '@lambdacurry/medusa-product-reviews', options: { defaultReviewStatus: 'pending', // OPTIONAL, default is 'approved' }, }, ], }); ``` -------------------------------- ### Store SDK: Upsert Product Review Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to create or update a product review via the store interface, requiring DTO data. ```typescript // Create/Update a review const review = await sdk.store.productReviews.upsert( data: StoreUpsertProductReviewsDTO, headers?: ClientHeaders ); ``` -------------------------------- ### Configure Medusa with Webhooks Plugin Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/webhooks/README.md Example of how to add the @lambdacurry/medusa-webhooks plugin to your Medusa project's configuration file (`medusa-config.js`), including specifying event subscriptions. ```javascript const plugins = [ // ... other plugins { resolve: "@lambdacurry/medusa-webhooks", options: { // Add here the subcribers you will define subscriptions: ["product.created", "product.updated"], }, }, ]; ``` -------------------------------- ### Basic GET API Route Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/api/README.md Defines a simple GET request handler for a custom API route. It responds with a 'Hello world!' JSON message. This requires the `@medusajs/framework/http` types. ```TypeScript import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"; export async function GET(req: MedusaRequest, res: MedusaResponse) { res.json({ message: "Hello world!", }); } ``` -------------------------------- ### Install Medusa Redis Event Bus Module Source: https://github.com/lambda-curry/medusa-plugins/blob/main/v1/modules/event-bus-redis/README.md This command installs the @medusajs/event-bus-redis module using yarn. This module is a dependency for enabling the Redis-powered event bus in a MedusaJS project. ```bash yarn add @medusajs/event-bus-redis ``` -------------------------------- ### Admin SDK: Create Product Review Response Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to add a response to a product review in the admin panel, requiring the review ID and response data. ```typescript // Manage review responses const review = await sdk.admin.productReviews.createResponse( productReviewId: string, data: AdminCreateProductReviewResponseDTO ); ``` -------------------------------- ### Configure Plugin with Module Options (JavaScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/modules/README.md Example of configuring a Medusa plugin with options, which are then passed to the modules within the plugin. This shows setting an API key. ```javascript import { defineConfig } from "@medusajs/framework/utils" module.exports = defineConfig({ // ... plugins: [ { resolve: "@myorg/plugin-name", options: { apiKey: process.env.API_KEY, }, }, ], }) ``` -------------------------------- ### Create Product Subscriber Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/subscribers/README.md Example of a basic subscriber that logs a message when a product is created. It defines the event to listen for ('product.created') and the handler function. ```typescript import { type SubscriberConfig, } from "@medusajs/framework" // subscriber function export default async function productCreateHandler() { console.log("A product was created") } // subscriber config export const config: SubscriberConfig = { event: "product.created", } ``` -------------------------------- ### Extend Medusa SDK with Custom Resources Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Provides an example of extending the Medusa SDK by creating custom resource classes for both admin and store contexts, demonstrating how to add new functionalities like 'myCustom'. ```typescript import Medusa, { Admin, Store, type Client, type Config } from '@medusajs/js-sdk'; import { AdminProductReviewsResource } from '@lambdacurry/medusa-plugins-sdk'; type MyCustom = { id: string; name: string; }; type MyQuery = { name: string; }; type MyResponse = { myCustom: MyCustom[]; }; export class AdminMyCustomResource { constructor(private client: Client) {} // example admin method async list(query: MyQuery) { return this.client.fetch(`/admin/my-custom`, { method: 'GET', query, }); } // custom admin methods } class MyAdmin extends Admin { public productReviews: AdminProductReviewsResource; public myCustom: AdminMyCustomResource; constructor(client: Client) { super(client); this.productReviews = new AdminProductReviewsResource(client); this.myCustom = new AdminMyCustomResource(client); } } class StoreMyCustomResource { constructor(private client: Client) {} // custom store methods } class MyStore extends Store { public store: StoreMyCustomResource; constructor(client: Client) { super(client); this.store = new StoreMyCustomResource(client); } } export class MyExtendedSDK extends Medusa { public override admin: MyAdmin; public override store: MyStore; constructor(config: Config) { super(config); this.admin = new MyAdmin(this.client); this.store = new MyStore(this.client); } } ``` -------------------------------- ### Admin SDK: Update Product Review Status Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to update the status of a product review in the admin panel, requiring the review ID and new status. ```typescript // Update review status const review = await sdk.admin.productReviews.updateStatus( productReviewId: string, status: 'pending' | 'approved' | 'flagged' ); ``` -------------------------------- ### Admin SDK: Update Product Review Response Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to update an existing response to a product review in the admin panel, requiring the review ID and updated data. ```typescript await sdk.admin.productReviews.updateResponse( productReviewId: string, data: AdminUpdateProductReviewResponseDTO ); ``` -------------------------------- ### Create Module Service (TypeScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/modules/README.md Defines a service class for a module, encapsulating business logic. This example shows a BlogModuleService that interacts with the Post data model. ```typescript import { MedusaService } from "@medusajs/framework/utils" import Post from "./models/post" class BlogModuleService extends MedusaService({ Post, }){ } export default BlogModuleService ``` -------------------------------- ### Define Data Model for a Module (TypeScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/modules/README.md Creates a data model for a module, defining database table structure. This example defines a 'post' model with an ID and title. ```typescript import { model } from "@medusajs/framework/utils" const Post = model.define("post", { id: model.id().primaryKey(), title: model.text(), }) export default Post ``` -------------------------------- ### Product Subscriber with Event Data and Container Access Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/subscribers/README.md An advanced subscriber example that retrieves product details using the event data and the Medusa container. It demonstrates accessing services and using event payload data. ```typescript import type { SubscriberArgs, SubscriberConfig, } from "@medusajs/framework" export default async function productCreateHandler({ event: { data }, container, }: SubscriberArgs<{ id: string }>) { const productId = data.id const productModuleService = container.resolve("product") const product = await productModuleService.retrieveProduct(productId) console.log(`The product ${product.title} was created`) } export const config: SubscriberConfig = { event: "product.created", } ``` -------------------------------- ### Execute a Workflow from an API Route in TypeScript Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/providers/payment-braintree/src/workflows/README.md This example demonstrates how to execute a previously defined MedusaJS workflow from within an API route handler. It shows how to import the workflow, run it with specific input, and send the result back in the response. ```TypeScript import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework" import myWorkflow from "../../../workflows/hello-world" export async function GET( req: MedusaRequest, res: MedusaResponse ) { const { result } = await myWorkflow(req.scope) .run({ input: { name: req.query.name as string, }, }) res.send(result) } ``` -------------------------------- ### Admin SDK: Delete Product Review Response Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Example using the Medusa Plugins SDK to delete a response associated with a product review in the admin panel, requiring the review ID. ```typescript await sdk.admin.productReviews.deleteResponse( productReviewId: string ); ``` -------------------------------- ### Multiple HTTP Method Handlers Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/api/README.md Demonstrates how to export functions for different HTTP methods (GET, POST, PUT) within a single route file. Each function handles requests for its corresponding method. This utilizes types from `@medusajs/framework/http`. ```TypeScript import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"; export async function GET(req: MedusaRequest, res: MedusaResponse) { // Handle GET requests } export async function POST(req: MedusaRequest, res: MedusaResponse) { // Handle POST requests } export async function PUT(req: MedusaRequest, res: MedusaResponse) { // Handle PUT requests } ``` -------------------------------- ### Build the Plugin Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Command to build the @lambdacurry/medusa-product-reviews plugin. ```bash yarn build ``` -------------------------------- ### Initialize and Use MedusaPluginsSDK Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Demonstrates how to initialize the MedusaPluginsSDK with backend URL and publishable key, and then use it to list product reviews. ```typescript import { MedusaPluginsSDK, StoreListProductReviewsQuery, StoreListProductReviewStatsQuery, } from '@lambdacurry/medusa-plugins-sdk'; // Initialize the SDK const sdk = new MedusaPluginsSDK({ baseUrl: process.env.MEDUSA_BACKEND_URL || 'http://localhost:9000', publishableKey: process.env.MEDUSA_PUBLISHABLE_KEY, }); // List product reviews const productReviews = await sdk.store.productReviews.list({ product_id: product.id, offset: 0, limit: 10, }) ``` -------------------------------- ### Publish Plugin to Local Registry Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Command to publish the plugin to a local registry for testing purposes. ```bash yarn dev:publish ``` -------------------------------- ### Local Development Publish with Yalc Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Instructions for publishing the package locally using yalc for development purposes. Includes steps for both publishing and adding the package to another project. ```bash # from medusa-plugins/packages/plugins-sdk yarn dev:publish # from your project yarn yalc add @lambdacurry/medusa-plugins-sdk ``` -------------------------------- ### Generate Database Migrations Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Command to generate database migrations for the plugin. ```bash yarn db:generate ``` -------------------------------- ### Run Plugin in Development Mode Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/README.md Command to run the plugin in development mode with hot-reloading enabled. ```bash yarn dev ``` -------------------------------- ### Build All Packages with Yarn Source: https://github.com/lambda-curry/medusa-plugins/blob/main/v1/README.md This command builds all applications and packages within the Turborepo project. It's a common command for setting up and compiling the entire codebase. ```bash yarn build ``` -------------------------------- ### Configure Vite for Medusa Applications Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Configures the Vite build tool for Medusa applications to include the SDK in the `optimizeDeps.include` option, ensuring proper dependency handling. ```typescript // medusa-config.ts module.exports = defineConfig({ // other configs... admin: { // other admin configs... vite: () => { return { optimizeDeps: { include: ['@lambdacurry/medusa-plugins-sdk'], }, }; }, }, }); ``` -------------------------------- ### Configure Vite for Vite Applications Source: https://github.com/lambda-curry/medusa-plugins/blob/main/packages/plugins-sdk/README.md Configures Vite applications by specifying the SDK in the `ssr.noExternal` option to prevent it from being externalized during server-side rendering. ```typescript // vite.config.ts export default defineConfig({ // other configs... ssr: { noExternal: ['@medusajs/js-sdk', '@lambdacurry/medusa-plugins-sdk'], }, }); ``` -------------------------------- ### Registering Medusa Module Providers Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/src/providers/README.md Demonstrates how to register custom module providers within the Medusa application configuration. It specifies the resolution path for the core module and the custom provider, along with their respective options. ```ts module.exports = defineConfig({ // ... modules: [ { resolve: "@medusajs/medusa/notification", options: { providers: [ { resolve: "@myorg/plugin-name/providers/my-notification", id: "my-notification", options: { channels: ["email"], // provider options... }, }, ], }, }, ], }) ``` -------------------------------- ### Configure Braintree Environment Variables Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/providers/payment-braintree/README.md Sets up essential Braintree credentials and configuration options in the project's .env file. ```env BRAINTREE_PUBLIC_KEY= BRAINTREE_MERCHANT_ID= BRAINTREE_PRIVATE_KEY= BRAINTREE_WEBHOOK_SECRET= BRAINTREE_ENVIRONMENT=one of "sandbox" | "devevlopmnent" | "production" | "qa" BRAINTREE_ENABLE_3D_SECURE=true ``` -------------------------------- ### Generate Database Migrations (Bash) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/modules/README.md Command to generate database migrations for a module. This command should be run from the plugin's directory. ```bash npx medusa plugin:db:generate ``` -------------------------------- ### Define Product-Hello Module Link (TypeScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/product-reviews/src/links/README.md This snippet demonstrates how to define a module link between the Product module's 'product' data model and a custom module's 'myCustom' data model using Medusa.js utilities. It requires importing necessary modules and the `defineLink` function. ```TypeScript import HelloModule from "../modules/hello" import ProductModule from "@medusajs/product" import { defineLink } from "@medusajs/utils" export default defineLink( ProductModule.linkable.product, HelloModule.linkable.myCustom ) ``` -------------------------------- ### Define Product-Blog Module Link (TypeScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/links/README.md This snippet demonstrates how to define a link between the Product module's 'product' data model and a custom Blog module's 'post' data model using the `defineLink` function from the Medusa framework. It imports necessary modules and the `defineLink` utility. ```TypeScript import BlogModule from "../modules/blog" import ProductModule from "@medusajs/medusa/product" import { defineLink } from "@medusajs/framework/utils" export default defineLink( ProductModule.linkable.product, BlogModule.linkable.post ) ``` -------------------------------- ### Migrate Database Links (Bash) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/links/README.md This command is used within a Medusa application to synchronize the defined module links with the database schema. It triggers the necessary migrations to create or update the database structure based on the module link configurations. ```Bash npx medusa db:migrate ``` -------------------------------- ### Configure Braintree Environment Variables (Env) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/README.md Sets up essential environment variables for the Braintree payment provider, including API keys, webhook secrets, and environment settings. ```env BRAINTREE_PUBLIC_KEY= BRAINTREE_MERCHANT_ID= BRAINTREE_PRIVATE_KEY= BRAINTREE_WEBHOOK_SECRET= BRAINTREE_ENVIRONMENT=sandbox|development|production|qa BRAINTREE_ENABLE_3D_SECURE=true|false ``` -------------------------------- ### Create Product Widget Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/admin/README.md This code defines a React widget to be injected into the Medusa Admin. It uses `@medusajs/admin-sdk` to configure the widget's placement, specifically after the product details. ```tsx import { defineWidgetConfig } from "@medusajs/admin-sdk" // The widget const ProductWidget = () => { return (

Product Widget

) } // The widget's configurations export const config = defineWidgetConfig({ zone: "product.details.after", }) export default ProductWidget ``` -------------------------------- ### Configure Medusa Plugin Event Bus Redis Dashboard Source: https://github.com/lambda-curry/medusa-plugins/blob/main/v1/packages/event-bus-dashboard/README.md Configures the event bus redis dashboard plugin in medusa-config.js, specifying options for event bus redis and the dashboard's base path. ```javascript module.exports = { // ... plugins: [ { resolve: '@lambdacurry/medusa-plugin-event-bus-redis-dashboard', options: { eventBusRedisOptions: { // copy paste all options passed to event-bus-redis here. redisUrl: 'redis:..', }, // where you want the dashboard to live on the API. basePath: '/event-bus-ui', }, }, ], // ... }; ``` -------------------------------- ### Use Module in API Route (TypeScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/modules/README.md Demonstrates how to resolve and use a module's service within an API route handler. It retrieves posts using the BlogModuleService. ```typescript import { MedusaRequest, MedusaResponse } from "@medusajs/framework" import BlogModuleService from "../../../modules/blog/service" import { BLOG_MODULE } from "../../../modules/blog" export async function GET( req: MedusaRequest, res: MedusaResponse ): Promise { const blogModuleService: BlogModuleService = req.scope.resolve( BLOG_MODULE ) const posts = await blogModuleService.listPosts() res.json({ posts }) } ``` -------------------------------- ### API Route with Path Parameter Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/api/README.md Shows how to create an API route that accepts a dynamic path parameter, such as a product ID. The parameter is accessed via `req.params`. The route structure uses bracket notation for the parameter name (e.g., `[productId]`). ```TypeScript import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http"; export async function GET(req: MedusaRequest, res: MedusaResponse) { const { productId } = req.params; res.json({ message: `You're looking for product ${productId}`, }); } ``` -------------------------------- ### Applying Middleware to Routes Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/api/README.md Explains how to define and apply middleware functions to specific API routes using a `middlewares.ts` file. The `defineMiddlewares` function is used to configure middleware, matching routes by string or regular expression. ```TypeScript import { defineMiddlewares } from "@medusajs/framework/http"; import type { MedusaRequest, MedusaResponse, MedusaNextFunction, } from "@medusajs/framework/http"; async function logger( req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction ) { console.log("Request received"); next(); } export default defineMiddlewares({ routes: [ { matcher: "/store/custom", middlewares: [logger], }, ], }); ``` -------------------------------- ### Accessing Medusa Container Services Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/api/README.md Illustrates how to access Medusa services and other registered resources from the request scope. The `req.scope.resolve()` method is used to retrieve services, like the product module service, to perform operations such as listing products. ```TypeScript import type { MedusaRequest, MedusaResponse, } from "@medusajs/framework/http"; export const GET = async ( req: MedusaRequest, res: MedusaResponse ) => { const productModuleService = req.scope.resolve("product"); const [, count] = await productModuleService.listAndCount(); res.json({ count, }); } ``` -------------------------------- ### Export Module Definition (TypeScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/modules/README.md Exports the module definition, specifying the main service. This is crucial for Medusa to recognize and register the module. ```typescript import BlogModuleService from "./service" import { Module } from "@medusajs/framework/utils" export const BLOG_MODULE = "blog" export default Module(BLOG_MODULE, { service: BlogModuleService, }) ``` -------------------------------- ### Configure Medusa Braintree Payment Provider Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/providers/payment-braintree/README.md Integrates the Braintree payment provider into the Medusa configuration file (medusa-config.js or config.ts), specifying options like environment, keys, and feature flags. ```javascript { resolve: 'medusa-plugin-braintree/providers/payment-braintree/src', id: 'braintree', options: { environment: process.env.NODE_ENV !== 'production' ? 'sandbox' : 'production', merchantId: process.env.BRAINTREE_MERCHANT_ID, publicKey: process.env.BRAINTREE_PUBLIC_KEY, privateKey: process.env.BRAINTREE_PRIVATE_KEY, webhookSecret: process.env.BRAINTREE_WEBHOOK_SECRET, enable3DSecure: process.env.BRAINTREE_ENABLE_3D_SECURE === 'true', savePaymentMethod: true, autoCapture: true, } } ``` -------------------------------- ### Configure Braintree Payment Provider in Medusa (JavaScript) Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/README.md Integrates the Braintree payment provider into the Medusa configuration file (`medusa-config.js` or `config.ts`), specifying options like environment, API keys, and feature flags. ```javascript dependencies:[Modules.CACHE] { resolve: '@lambdacurry/medusa-payment-braintree/providers/payment-braintree', id: 'braintree', options: { environment: process.env.BRAINTREE_ENVIRONMENT || (process.env.NODE_ENV !== 'production' ? 'sandbox' : 'production'), merchantId: process.env.BRAINTREE_MERCHANT_ID, publicKey: process.env.BRAINTREE_PUBLIC_KEY, privateKey: process.env.BRAINTREE_PRIVATE_KEY, webhookSecret: process.env.BRAINTREE_WEBHOOK_SECRET, enable3DSecure: process.env.BRAINTREE_ENABLE_3D_SECURE === 'true', savePaymentMethod: true, autoCapture: true, } } ``` -------------------------------- ### Define a Custom Workflow in TypeScript Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/providers/payment-braintree/src/workflows/README.md This snippet shows how to define a custom workflow using the MedusaJS framework's workflow SDK. It includes creating individual steps and then composing them into a complete workflow with defined inputs and outputs. ```TypeScript import { createStep, createWorkflow, WorkflowResponse, StepResponse, } from "@medusajs/framework/workflows-sdk" const step1 = createStep("step-1", async () => { return new StepResponse(`Hello from step one!`) }) type WorkflowInput = { name: string } const step2 = createStep( "step-2", async ({ name }: WorkflowInput) => { return new StepResponse(`Hello ${name} from step two!`) } ) type WorkflowOutput = { message1: string message2: string } const helloWorldWorkflow = createWorkflow( "hello-world", (input: WorkflowInput) => { const greeting1 = step1() const greeting2 = step2(input) return new WorkflowResponse({ message1: greeting1, message2: greeting2 }) } ) export default helloWorldWorkflow ``` -------------------------------- ### Configure Medusa with Redis Event Bus Source: https://github.com/lambda-curry/medusa-plugins/blob/main/v1/modules/event-bus-redis/README.md This JavaScript code snippet shows how to configure a MedusaJS project to use the Redis Event Bus module. It involves adding the module to the `medusa-config.js` file and specifying the Redis connection URL. ```javascript module.exports = { // ... modules: [ { resolve: "@medusajs/event-bus-redis", options: { redisUrl: "redis:.." }, }, ], // ... } ``` -------------------------------- ### Define a Custom Scheduled Job in TypeScript Source: https://github.com/lambda-curry/medusa-plugins/blob/main/plugins/braintree-payment/src/jobs/README.md This snippet demonstrates how to create a custom scheduled job in TypeScript for a Medusa application. It includes importing necessary types, defining the job handler function that accepts a Medusa container, and exporting a configuration object with the job's name and schedule. ```TypeScript import { MedusaContainer } from "@medusajs/framework/types"; export default async function myCustomJob(container: MedusaContainer) { const productService = container.resolve("product") const products = await productService.listAndCountProducts(); // Do something with the products } export const config = { name: "daily-product-report", schedule: "0 0 * * *", // Every day at midnight }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.