Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

chore: v2.0.0-canary.89

vholik27693649708b
diff --git a/bun.lock b/bun.lock
index 06ff834ce..3fad6285d 100644
--- a/bun.lock
+++ b/bun.lock
@@ -38,7 +38,7 @@
},
"packages/admin": {
"name": "@mercurjs/admin",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"dependencies": {
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
@@ -98,7 +98,7 @@
},
"packages/cli": {
"name": "@mercurjs/cli",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"bin": {
"mercurjs": "./dist/index.js",
},
@@ -109,7 +109,7 @@
"@medusajs/admin-vite-plugin": "2.13.3",
"@medusajs/dashboard": "2.13.3",
"@medusajs/framework": "2.13.3",
- "@mercurjs/dashboard-sdk": "2.0.0-canary.85",
+ "@mercurjs/dashboard-sdk": "2.0.0-canary.88",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"commander": "^14.0.2",
@@ -153,7 +153,7 @@
},
"packages/client": {
"name": "@mercurjs/client",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"dependencies": {
"@tanstack/react-query": "^5.64.2",
"qs": "^6.12.1",
@@ -170,7 +170,7 @@
},
"packages/core-plugin": {
"name": "@mercurjs/core-plugin",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"devDependencies": {
"@medusajs/cli": "^2.13.3",
"@medusajs/core-flows": "^2.13.3",
@@ -211,7 +211,7 @@
},
"packages/dashboard-sdk": {
"name": "@mercurjs/dashboard-sdk",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"dependencies": {
"@babel/parser": "7.25.6",
"@babel/traverse": "7.25.6",
@@ -228,7 +228,7 @@
},
"packages/dashboard-shared": {
"name": "@mercurjs/dashboard-shared",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"dependencies": {
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
@@ -241,7 +241,7 @@
"@medusajs/dashboard": "^2.13.3",
"@medusajs/icons": "2.13.3",
"@medusajs/ui": "4.1.1",
- "@mercurjs/client": "2.0.0-canary.85",
+ "@mercurjs/client": "2.0.0-canary.88",
"@radix-ui/react-dialog": "1.1.4",
"@radix-ui/react-dismissable-layer": "1.1.4",
"@tanstack/react-query": "5.64.2",
@@ -320,7 +320,7 @@
},
"packages/types": {
"name": "@mercurjs/types",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"dependencies": {
"@medusajs/types": "2.13.3",
},
@@ -330,7 +330,7 @@
},
"packages/vendor": {
"name": "@mercurjs/vendor",
- "version": "2.0.0-canary.85",
+ "version": "2.0.0-canary.88",
"dependencies": {
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
@@ -343,8 +343,8 @@
"@medusajs/dashboard": "^2.13.3",
"@medusajs/icons": "2.13.3",
"@medusajs/ui": "4.1.1",
- "@mercurjs/client": "2.0.0-canary.85",
- "@mercurjs/dashboard-shared": "2.0.0-canary.85",
+ "@mercurjs/client": "2.0.0-canary.88",
+ "@mercurjs/dashboard-shared": "2.0.0-canary.88",
"@radix-ui/react-dialog": "1.1.4",
"@radix-ui/react-dismissable-layer": "1.1.4",
"@tanstack/react-query": "5.64.2",
diff --git a/packages/admin/package.json b/packages/admin/package.json
index 620b8b4df..8e69301e8 100644
--- a/packages/admin/package.json
+++ b/packages/admin/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/admin",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
@@ -29,8 +29,8 @@
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
},
"dependencies": {
- "@mercurjs/dashboard-shared": "2.0.0-canary.88",
- "@mercurjs/client": "2.0.0-canary.88",
+ "@mercurjs/dashboard-shared": "2.0.0-canary.89",
+ "@mercurjs/client": "2.0.0-canary.89",
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
"@dnd-kit/core": "^6.1.0",
diff --git a/packages/cli/package.json b/packages/cli/package.json
index f713a3340..9afb682ec 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/cli",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
@@ -63,7 +63,7 @@
"vite": "^5.4.21",
"@medusajs/admin-bundler": "2.13.3",
"@medusajs/framework": "2.13.3",
- "@mercurjs/dashboard-sdk": "2.0.0-canary.88"
+ "@mercurjs/dashboard-sdk": "2.0.0-canary.89"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts
index 7a2172bf1..4967561fa 100644
--- a/packages/cli/src/commands/create.ts
+++ b/packages/cli/src/commands/create.ts
@@ -29,8 +29,9 @@ const MIN_SUPPORTED_NODE_VERSION = 20;
const CREATE_TEMPLATES = {
basic: "basic",
- // todo: add registry template back in after new release
+ // todo: uncomment registry template
// registry: "registry",
+ plugin: "plugin",
} as const;
export const create = new Command()
@@ -39,7 +40,7 @@ export const create = new Command()
.argument("[name]", "the name of your project")
.option(
"-t, --template <template>",
- "the template to use. e.g. basic or registry"
+ "the template to use. e.g. basic, registry, or plugin"
)
.option(
"-c, --cwd <cwd>",
@@ -80,28 +81,26 @@ export const create = new Command()
projectName = enteredName;
}
- // todo: uncomment when more templates are available
- // let template = opts.template;
- // if (!template) {
- // const { selectedTemplate } = await prompts({
- // type: "select",
- // name: "selectedTemplate",
- // message: `Which ${highlighter.info(
- // "template"
- // )} would you like to use?`,
- // choices: Object.entries(CREATE_TEMPLATES).map(([key, value]) => ({
- // title: value,
- // value: key,
- // })),
- // });
-
- // if (!selectedTemplate) {
- // process.exit(0);
- // }
-
- // template = selectedTemplate;
- // }
- const template = opts.template || "basic";
+ let template = opts.template;
+ if (!template) {
+ const { selectedTemplate } = await prompts({
+ type: "select",
+ name: "selectedTemplate",
+ message: `Which ${highlighter.info(
+ "template"
+ )} would you like to use?`,
+ choices: Object.entries(CREATE_TEMPLATES).map(([key, value]) => ({
+ title: value,
+ value: key,
+ })),
+ });
+
+ if (!selectedTemplate) {
+ process.exit(0);
+ }
+
+ template = selectedTemplate;
+ }
if (!opts.skipEmail) {
const { wantsEmail } = await prompts({
diff --git a/packages/client/package.json b/packages/client/package.json
index 4c19f694f..6c0cd6be3 100644
--- a/packages/client/package.json
+++ b/packages/client/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/client",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/core-plugin/package.json b/packages/core-plugin/package.json
index 83a908db0..48a7385fe 100644
--- a/packages/core-plugin/package.json
+++ b/packages/core-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/core-plugin",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/dashboard-sdk/package.json b/packages/dashboard-sdk/package.json
index 544cf1309..fd8cb7899 100644
--- a/packages/dashboard-sdk/package.json
+++ b/packages/dashboard-sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/dashboard-sdk",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/dashboard-shared/package.json b/packages/dashboard-shared/package.json
index f94eb80fa..54f36a798 100644
--- a/packages/dashboard-shared/package.json
+++ b/packages/dashboard-shared/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/dashboard-shared",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
@@ -23,7 +23,7 @@
"build": "tsup"
},
"dependencies": {
- "@mercurjs/client": "2.0.0-canary.88",
+ "@mercurjs/client": "2.0.0-canary.89",
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
"@dnd-kit/core": "^6.1.0",
diff --git a/packages/types/package.json b/packages/types/package.json
index 147ea008f..b50dd306b 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/types",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/vendor/package.json b/packages/vendor/package.json
index afbc456d8..f92df7f24 100644
--- a/packages/vendor/package.json
+++ b/packages/vendor/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/vendor",
- "version": "2.0.0-canary.88",
+ "version": "2.0.0-canary.89",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
@@ -29,8 +29,8 @@
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
},
"dependencies": {
- "@mercurjs/dashboard-shared": "2.0.0-canary.88",
- "@mercurjs/client": "2.0.0-canary.88",
+ "@mercurjs/dashboard-shared": "2.0.0-canary.89",
+ "@mercurjs/client": "2.0.0-canary.89",
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
"@dnd-kit/core": "^6.1.0",
diff --git a/templates/plugin/.gitignore b/templates/plugin/.gitignore
new file mode 100644
index 000000000..7aa216915
--- /dev/null
+++ b/templates/plugin/.gitignore
@@ -0,0 +1,26 @@
+/dist
+.env
+.DS_Store
+/uploads
+/node_modules
+yarn-error.log
+
+.idea
+
+coverage
+
+!src/**
+
+./tsconfig.tsbuildinfo
+medusa-db.sql
+build
+.cache
+
+.yarn/*
+!.yarn/patches
+!.yarn/plugins
+!.yarn/releases
+!.yarn/sdks
+!.yarn/versions
+
+.medusa
\ No newline at end of file
diff --git a/templates/plugin/.npmrc b/templates/plugin/.npmrc
new file mode 100644
index 000000000..cf6e3c410
--- /dev/null
+++ b/templates/plugin/.npmrc
@@ -0,0 +1,4 @@
+public-hoist-pattern[]=*@medusajs/*
+public-hoist-pattern[]=@tanstack/react-query
+public-hoist-pattern[]=react-i18next
+public-hoist-pattern[]=react-router-dom
\ No newline at end of file
diff --git a/templates/plugin/package.json b/templates/plugin/package.json
new file mode 100644
index 000000000..7c508d299
--- /dev/null
+++ b/templates/plugin/package.json
@@ -0,0 +1,75 @@
+{
+ "name": "@acme/plugin",
+ "version": "0.0.7",
+ "description": "A starter for Mercur plugins.",
+ "author": "Mercur (https://mercurjs.com)",
+ "license": "MIT",
+ "files": [
+ ".medusa/server"
+ ],
+ "exports": {
+ "./package.json": "./package.json",
+ "./workflows": "./.medusa/server/src/workflows/index.js",
+ "./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
+ "./modules/*": "./.medusa/server/src/modules/*/index.js",
+ "./providers/*": "./.medusa/server/src/providers/*/index.js",
+ "./*": "./.medusa/server/src/*.js",
+ "./admin": {
+ "import": "./.medusa/server/src/admin/index.mjs",
+ "require": "./.medusa/server/src/admin/index.js",
+ "default": "./.medusa/server/src/admin/index.js"
+ },
+ "./vendor": {
+ "import": "./.medusa/server/src/admin/index.mjs",
+ "require": "./.medusa/server/src/admin/index.js",
+ "default": "./.medusa/server/src/admin/index.js"
+ }
+ },
+ "keywords": [
+ "medusa",
+ "plugin",
+ "medusa-plugin-other",
+ "medusa-plugin",
+ "medusa-v2",
+ "mercur",
+ "mercur-plugin"
+ ],
+ "scripts": {
+ "build": "npx @mercurjs/cli@canary plugin:build",
+ "prepublishOnly": "npx @mercurjs/cli@canary plugin:build"
+ },
+ "devDependencies": {
+ "@medusajs/admin-sdk": "2.13.3",
+ "@medusajs/cli": "2.13.3",
+ "@medusajs/framework": "2.13.3",
+ "@medusajs/medusa": "2.13.3",
+ "@medusajs/test-utils": "2.13.3",
+ "@medusajs/ui": "4.0.25",
+ "@medusajs/icons": "2.13.3",
+ "@swc/core": "^1.7.28",
+ "@types/node": "^20.0.0",
+ "@types/react": "^18.3.2",
+ "@types/react-dom": "^18.2.25",
+ "prop-types": "^15.8.1",
+ "react": "^18.2.0",
+ "react-dom": "^18.2.0",
+ "ts-node": "^10.9.2",
+ "typescript": "^5.6.2",
+ "vite": "^5.2.11",
+ "yalc": "^1.0.0-pre.53"
+ },
+ "peerDependencies": {
+ "@medusajs/admin-sdk": "2.13.3",
+ "@medusajs/admin-shared": "2.13.3",
+ "@medusajs/cli": "2.13.3",
+ "@medusajs/framework": "2.13.3",
+ "@medusajs/test-utils": "2.13.3",
+ "@medusajs/medusa": "2.13.3",
+ "@medusajs/ui": "4.0.25",
+ "@medusajs/icons": "2.13.3"
+ },
+ "engines": {
+ "node": ">=20"
+ },
+ "packageManager": "[email protected]"
+}
\ No newline at end of file
diff --git a/templates/plugin/src/admin/tsconfig.json b/templates/plugin/src/admin/tsconfig.json
new file mode 100644
index 000000000..ea4bf122b
--- /dev/null
+++ b/templates/plugin/src/admin/tsconfig.json
@@ -0,0 +1,24 @@
+{
+ "compilerOptions": {
+ "target": "ES2020",
+ "useDefineForClassFields": true,
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
+ "module": "ESNext",
+ "skipLibCheck": true,
+
+ /* Bundler mode */
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "noEmit": true,
+ "jsx": "react-jsx",
+
+ /* Linting */
+ "strict": true,
+ "noUnusedLocals": true,
+ "noUnusedParameters": true,
+ "noFallthroughCasesInSwitch": true
+ },
+ "include": ["."]
+}
\ No newline at end of file
diff --git a/templates/plugin/src/admin/vite-env.d.ts b/templates/plugin/src/admin/vite-env.d.ts
new file mode 100644
index 000000000..151aa6856
--- /dev/null
+++ b/templates/plugin/src/admin/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
\ No newline at end of file
diff --git a/templates/plugin/src/api/README.md b/templates/plugin/src/api/README.md
new file mode 100644
index 000000000..9d57444ff
--- /dev/null
+++ b/templates/plugin/src/api/README.md
@@ -0,0 +1,133 @@
+# Custom API Routes
+
+An API Route is a REST API endpoint.
+
+An API Route is created in a TypeScript or JavaScript file under the `/src/api` directory of your Medusa application. The file’s name must be `route.ts` or `route.js`.
+
+For example, to create a `GET` API Route at `/store/hello-world`, create the file `src/api/store/hello-world/route.ts` with the following content:
+
+```ts
+import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
+
+export async function GET(req: MedusaRequest, res: MedusaResponse) {
+ res.json({
+ message: "Hello world!",
+ });
+}
+```
+
+## Supported HTTP methods
+
+The file based routing supports the following HTTP methods:
+
+- GET
+- POST
+- PUT
+- PATCH
+- DELETE
+- OPTIONS
+- HEAD
+
+You can define a handler for each of these methods by exporting a function with the name of the method in the paths `route.ts` file.
+
+For example:
+
+```ts
+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
+}
+```
+
+## Parameters
+
+To create an API route that accepts a path parameter, create a directory within the route's path whose name is of the format `[param]`.
+
+For example, if you want to define a route that takes a `productId` parameter, you can do so by creating a file called `/api/products/[productId]/route.ts`:
+
+```ts
+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}`
+ })
+}
+```
+
+To create an API route that accepts multiple path parameters, create within the file's path multiple directories whose names are of the format `[param]`.
+
+For example, if you want to define a route that takes both a `productId` and a `variantId` parameter, you can do so by creating a file called `/api/products/[productId]/variants/[variantId]/route.ts`.
+
+## Using the container
+
+The Medusa container is available on `req.scope`. Use it to access modules' main services and other registered resources:
+
+```ts
+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,
+ })
+}
+```
+
+## Middleware
+
+You can apply middleware to your routes by creating a file called `/api/middlewares.ts`. This file must export a configuration object with what middleware you want to apply to which routes.
+
+For example, if you want to apply a custom middleware function to the `/store/custom` route, you can do so by adding the following to your `/api/middlewares.ts` file:
+
+```ts
+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],
+ },
+ ],
+})
+```
+
+The `matcher` property can be either a string or a regular expression. The `middlewares` property accepts an array of middleware functions.
diff --git a/templates/plugin/src/api/admin/plugin/route.ts b/templates/plugin/src/api/admin/plugin/route.ts
new file mode 100644
index 000000000..9e2e618c3
--- /dev/null
+++ b/templates/plugin/src/api/admin/plugin/route.ts
@@ -0,0 +1,8 @@
+import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
+
+export async function GET(
+ req: MedusaRequest,
+ res: MedusaResponse
+) {
+ res.sendStatus(200);
+}
diff --git a/templates/plugin/src/api/store/plugin/route.ts b/templates/plugin/src/api/store/plugin/route.ts
new file mode 100644
index 000000000..9e2e618c3
--- /dev/null
+++ b/templates/plugin/src/api/store/plugin/route.ts
@@ -0,0 +1,8 @@
+import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
+
+export async function GET(
+ req: MedusaRequest,
+ res: MedusaResponse
+) {
+ res.sendStatus(200);
+}
diff --git a/templates/plugin/src/jobs/README.md b/templates/plugin/src/jobs/README.md
new file mode 100644
index 000000000..eaf89d795
--- /dev/null
+++ b/templates/plugin/src/jobs/README.md
@@ -0,0 +1,36 @@
+# Custom scheduled jobs
+
+A scheduled job is a function executed at a specified interval of time in the background of your Medusa application.
+
+A scheduled job is created in a TypeScript or JavaScript file under the `src/jobs` directory.
+
+For example, create the file `src/jobs/hello-world.ts` with the following content:
+
+```ts
+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
+};
+```
+
+A scheduled job file must export:
+
+- The function to be executed whenever it’s time to run the scheduled job.
+- A configuration object defining the job. It has three properties:
+ - `name`: a unique name for the job.
+ - `schedule`: a [cron expression](https://crontab.guru/).
+ - `numberOfExecutions`: an optional integer, specifying how many times the job will execute before being removed
+
+The `handler` is a function that accepts one parameter, `container`, which is a `MedusaContainer` instance used to resolve services.
diff --git a/templates/plugin/src/links/README.md b/templates/plugin/src/links/README.md
new file mode 100644
index 000000000..bd05ff7d4
--- /dev/null
+++ b/templates/plugin/src/links/README.md
@@ -0,0 +1,26 @@
+# Module Links
+
+A module link forms an association between two data models of different modules, while maintaining module isolation.
+
+Learn more about links in [this documentation](https://docs.medusajs.com/learn/fundamentals/module-links)
+
+For example:
+
+```ts
+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
+)
+```
+
+This defines a link between the Product Module's `product` data model and the Blog Module (custom module)'s `post` data model.
+
+Then, in the Medusa application using this plugin, run the following command to sync the links to the database:
+
+```bash
+npx medusa db:migrate
+```
\ No newline at end of file
diff --git a/templates/plugin/src/modules/README.md b/templates/plugin/src/modules/README.md
new file mode 100644
index 000000000..60e26e024
--- /dev/null
+++ b/templates/plugin/src/modules/README.md
@@ -0,0 +1,116 @@
+# Custom Module
+
+A module is a package of reusable functionalities. It can be integrated into your Medusa application without affecting the overall system. You can create a module as part of a plugin.
+
+Learn more about modules in [this documentation](https://docs.medusajs.com/learn/fundamentals/modules).
+
+To create a module:
+
+## 1. Create a Data Model
+
+A data model represents a table in the database. You create a data model in a TypeScript or JavaScript file under the `models` directory of a module.
+
+For example, create the file `src/modules/blog/models/post.ts` with the following content:
+
+```ts
+import { model } from "@medusajs/framework/utils"
+
+const Post = model.define("post", {
+ id: model.id().primaryKey(),
+ title: model.text(),
+})
+
+export default Post
+```
+
+## 2. Create a Service
+
+A module must define a service. A service is a TypeScript or JavaScript class holding methods related to a business logic or commerce functionality.
+
+For example, create the file `src/modules/blog/service.ts` with the following content:
+
+```ts
+import { MedusaService } from "@medusajs/framework/utils"
+import Post from "./models/post"
+
+class BlogModuleService extends MedusaService({
+ Post,
+}){
+}
+
+export default BlogModuleService
+```
+
+## 3. Export Module Definition
+
+A module must have an `index.ts` file in its root directory that exports its definition. The definition specifies the main service of the module.
+
+For example, create the file `src/modules/blog/index.ts` with the following content:
+
+```ts
+import BlogModuleService from "./service"
+import { Module } from "@medusajs/framework/utils"
+
+export const BLOG_MODULE = "blog"
+
+export default Module(BLOG_MODULE, {
+ service: BlogModuleService,
+})
+```
+
+## 4. Generate Migrations
+
+To generate migrations for your module, run the following command in the plugin's directory:
+
+```bash
+npx medusa plugin:db:genreate
+```
+
+## Use Module
+
+You can use the module in customizations within the plugin or within the Medusa application using this plugin. When the plugin is added to a Medusa application, all its modules are registered as well.
+
+For example, to use the module in an API route:
+
+```ts
+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<void> {
+ const blogModuleService: BlogModuleService = req.scope.resolve(
+ BLOG_MODULE
+ )
+
+ const posts = await blogModuleService.listPosts()
+
+ res.json({
+ posts
+ })
+}
+```
+
+## Module Options
+
+When you register the plugin in the Medusa application, it can accept options. These options are passed to the modules within the plugin:
+
+```ts
+import { defineConfig } from "@medusajs/framework/utils"
+
+module.exports = defineConfig({
+ // ...
+ plugins: [
+ {
+ resolve: "@myorg/plugin-name",
+ options: {
+ apiKey: process.env.API_KEY,
+ },
+ },
+ ],
+})
+```
+
+Learn more about module options in [this documentation](https://docs.medusajs.com/learn/fundamentals/modules/options).
diff --git a/templates/plugin/src/providers/README.md b/templates/plugin/src/providers/README.md
new file mode 100644
index 000000000..35ef56920
--- /dev/null
+++ b/templates/plugin/src/providers/README.md
@@ -0,0 +1,30 @@
+## Module Providers
+
+You can create module providers, such as Notification or File Module Providers under a sub-directory of this directory. For example, `src/providers/my-notification`.
+
+Then, you register them in the Medusa application as `plugin-name/providers/my-notification`:
+
+```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...
+ },
+ },
+ ],
+ },
+ },
+ ],
+})
+```
+
+Learn more in [this documentation](https://docs.medusajs.com/learn/fundamentals/plugins/create).
diff --git a/templates/plugin/src/subscribers/README.md b/templates/plugin/src/subscribers/README.md
new file mode 100644
index 000000000..0f5f58bf8
--- /dev/null
+++ b/templates/plugin/src/subscribers/README.md
@@ -0,0 +1,59 @@
+# Custom subscribers
+
+Subscribers handle events emitted in the Medusa application.
+
+The subscriber is created in a TypeScript or JavaScript file under the `src/subscribers` directory.
+
+For example, create the file `src/subscribers/product-created.ts` with the following content:
+
+```ts
+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",
+}
+```
+
+A subscriber file must export:
+
+- The subscriber function that is an asynchronous function executed whenever the associated event is triggered.
+- A configuration object defining the event this subscriber is listening to.
+
+## Subscriber Parameters
+
+A subscriber receives an object having the following properties:
+
+- `event`: An object holding the event's details. It has a `data` property, which is the event's data payload.
+- `container`: The Medusa container. Use it to resolve modules' main services and other registered resources.
+
+```ts
+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",
+}
+```
\ No newline at end of file
diff --git a/templates/plugin/src/vendor/tsconfig.json b/templates/plugin/src/vendor/tsconfig.json
new file mode 100644
index 000000000..ea4bf122b
--- /dev/null
+++ b/templates/plugin/src/vendor/tsconfig.json
@@ -0,0 +1,24 @@
+{
+ "compilerOptions": {
+ "target": "ES2020",
+ "useDefineForClassFields": true,
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
+ "module": "ESNext",
+ "skipLibCheck": true,
+
+ /* Bundler mode */
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "noEmit": true,
+ "jsx": "react-jsx",
+
+ /* Linting */
+ "strict": true,
+ "noUnusedLocals": true,
+ "noUnusedParameters": true,
+ "noFallthroughCasesInSwitch": true
+ },
+ "include": ["."]
+}
\ No newline at end of file
diff --git a/templates/plugin/src/vendor/vite-env.d.ts b/templates/plugin/src/vendor/vite-env.d.ts
new file mode 100644
index 000000000..151aa6856
--- /dev/null
+++ b/templates/plugin/src/vendor/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
\ No newline at end of file
diff --git a/templates/plugin/src/workflows/README.md b/templates/plugin/src/workflows/README.md
new file mode 100644
index 000000000..d1c4f1bbd
--- /dev/null
+++ b/templates/plugin/src/workflows/README.md
@@ -0,0 +1,79 @@
+# Custom Workflows
+
+A workflow is a series of queries and actions that complete a task.
+
+The workflow is created in a TypeScript or JavaScript file under the `src/workflows` directory.
+
+For example:
+
+```ts
+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
+```
+
+## Execute Workflow
+
+You can execute the workflow from other resources, such as API routes, scheduled jobs, or subscribers.
+
+For example, to execute the workflow in an API route:
+
+```ts
+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)
+}
+```
diff --git a/templates/plugin/tsconfig.json b/templates/plugin/tsconfig.json
new file mode 100644
index 000000000..c4bf72572
--- /dev/null
+++ b/templates/plugin/tsconfig.json
@@ -0,0 +1,36 @@
+{
+ "compilerOptions": {
+ "target": "ES2021",
+ "esModuleInterop": true,
+ "module": "Node16",
+ "moduleResolution": "Node16",
+ "emitDecoratorMetadata": true,
+ "experimentalDecorators": true,
+ "skipLibCheck": true,
+ "skipDefaultLibCheck": true,
+ "declaration": false,
+ "sourceMap": false,
+ "inlineSourceMap": true,
+ "outDir": "./.medusa/server",
+ "rootDir": "./",
+ "jsx": "react-jsx",
+ "forceConsistentCasingInFileNames": true,
+ "resolveJsonModule": true,
+ "checkJs": false,
+ "strictNullChecks": true
+ },
+ "ts-node": {
+ "swc": true
+ },
+ "include": [
+ "**/*",
+ ".medusa/types/*"
+ ],
+ "exclude": [
+ "node_modules",
+ ".medusa/server",
+ ".medusa/admin",
+ "src/admin",
+ ".cache"
+ ]
+}