diff --git a/docs/content/add-plugins/mailchimp.md b/docs/content/add-plugins/mailchimp.md index 6dd4f94ffd..abaae99f58 100644 --- a/docs/content/add-plugins/mailchimp.md +++ b/docs/content/add-plugins/mailchimp.md @@ -180,4 +180,4 @@ If you try entering an email and clicking Subscribe, the email will be subscribe ## What’s Next 🚀 - Check out SendGrid plugin for more Email functionalities. -- [Learn more about plugins.](https://docs.medusajs.com/guides/plugins) \ No newline at end of file +- [Learn more about plugins.](../advanced/backend/plugins/overview.md) \ No newline at end of file diff --git a/docs/content/advanced/backend/notification/how-to-create-notification-provider.md b/docs/content/advanced/backend/notification/how-to-create-notification-provider.md index 73ec0e949c..bc5dcd7786 100644 --- a/docs/content/advanced/backend/notification/how-to-create-notification-provider.md +++ b/docs/content/advanced/backend/notification/how-to-create-notification-provider.md @@ -78,7 +78,7 @@ Additionally, if you’re creating your Notification Provider as an external plu :::info -You can learn more about plugins and how to create them in the [Plugins](../../../guides/plugins.md) documentation. +You can learn more about plugins and how to create them in the [Plugins](../plugins/overview.md) documentation. ::: @@ -268,5 +268,5 @@ This request returns the same notification object as the List Notifications endp - Check out the [list of events](../subscribers/events-list.md) you can listen to. - Check out the [SendGrid](../../../add-plugins/sendgrid.mdx) plugin for easy integration of email notifications. -- Learn how to [create your own plugin](../../../guides/plugins.md). +- Learn how to [create your own plugin](../plugins/create.md). - Learn more about [Subscribers](../subscribers/create-subscriber.md) and [Services](../services/create-service.md). diff --git a/docs/content/advanced/backend/notification/overview.md b/docs/content/advanced/backend/notification/overview.md index b2ed328272..e22d5b9a94 100644 --- a/docs/content/advanced/backend/notification/overview.md +++ b/docs/content/advanced/backend/notification/overview.md @@ -16,7 +16,7 @@ An example of a notification provider is SendGrid. When an order is placed, the ### How Notification Provider is Created -A Notification Provider is essentially a Medusa [Service](../services/create-service.md) with a unique identifier, and it extends the [`NotificationService`](../../../references/services/classes/NotificationService.md) provided by the `medusa-interfaces` package. It can be created as part of a [Plugin](../../../guides/plugins.md), or it can be created just as a Service file in your Medusa server. +A Notification Provider is essentially a Medusa [Service](../services/create-service.md) with a unique identifier, and it extends the [`NotificationService`](../../../references/services/classes/NotificationService.md) provided by the `medusa-interfaces` package. It can be created as part of a [Plugin](../plugins/overview.md), or it can be created just as a Service file in your Medusa server. As a developer, you mainly work with the Notification Provider when integrating a third-party service that handles notifications in Medusa. diff --git a/docs/content/advanced/backend/payment/overview.md b/docs/content/advanced/backend/payment/overview.md index 1c3e68ff78..b5650ae9e0 100644 --- a/docs/content/advanced/backend/payment/overview.md +++ b/docs/content/advanced/backend/payment/overview.md @@ -24,7 +24,7 @@ Payment Providers can also be related to a custom way of handling payment operat ### How Payment Provider is Created -A Payment Provider is essentially a Medusa [service](../services/create-service.md) with a unique identifier, and it extends the `PaymentService` provided by the `medusa-interfaces` package. It can be created as part of a [plugin](../../../guides/plugins.md), or it can be created just as a service file in your Medusa server. +A Payment Provider is essentially a Medusa [service](../services/create-service.md) with a unique identifier, and it extends the `PaymentService` provided by the `medusa-interfaces` package. It can be created as part of a [plugin](../plugins/overview.md), or it can be created just as a service file in your Medusa server. As a developer, you will mainly work with the Payment Provider when integrating a payment method in Medusa. diff --git a/docs/content/advanced/backend/plugins/create.md b/docs/content/advanced/backend/plugins/create.md new file mode 100644 index 0000000000..5a956ecd9a --- /dev/null +++ b/docs/content/advanced/backend/plugins/create.md @@ -0,0 +1,371 @@ +# Create a Plugin + +In this document, you’ll learn how to create a plugin and publish it. If you’re interested to learn more about what plugins are and where to find available official and community plugins, check out the [overview document](overview.md). + +## Prerequisites + +This guide uses the Medusa CLI throughout different steps. If you don’t have the Medusa CLI installed you can install it with the following command: + +```bash npm2yarn +npm install @medusajs/medusa-cli -g +``` + +## Initialize Project + +The recommended way to create a plugin is using the Medusa CLI. Run the following command to create a new Medusa project: + +```bash +medusa new medusa-plugin-custom +``` + +Where `medusa-plugin-custom` is the name of the plugin you’re creating. In Medusa, plugins are named based on their functionalities. + +By convention, all plugin names start with `medusa` followed by a descriptive name of what the plugin does. For example, the Stripe plugin is named `medusa-payment-stripe`. + +### Project Structure + +The command above creates a new directory `medusa-plugin-custom` that holds essentially the same codebase you would have for a Medusa server. This is because a plugin has the same directory structure as a Medusa server. + +Under the `src` directory is where the code of your plugin resides. After running the previous command, you should have at least 3 directories inside the `src` directory: + +- `api` is where you can add custom endpoints. +- `services` is where you can add custom services. +- `subscribers` is where you can add custom subscribers. + +You can also add more directories and files to your plugin including: + +- `src/models` for adding custom entities or extending existing entities. +- `src/migrations` for migrations that make changes to the database schema. + +## Change Dependencies in package.json + +A basic Medusa server installed with the `medusa new` command has dependencies similar to this: + +```json +"dependencies": { + "@medusajs/medusa": "^1.3.1", + "@medusajs/medusa-cli": "^1.3.0", + "medusa-fulfillment-manual": "^1.1.31", + "medusa-interfaces": "^1.3.0", + "medusa-payment-manual": "^1.0.16", + "medusa-payment-stripe": "^1.1.38", + "mongoose": "^5.13.3", + "typeorm": "^0.2.36" +}, +"devDependencies": { + "@babel/cli": "^7.14.3", + "@babel/core": "^7.14.3", + "@babel/preset-typescript": "^7.14.5", + "babel-preset-medusa-package": "^1.1.19" +} +``` + +For a plugin, a lot of these dependencies are not necessary or should be labeled as [peer dependencies](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#peerdependencies). Therefore, it’s important to make changes to the dependencies of your plugin. + +The recommended change is the following: + +```json +"peerDependencies": { + "@medusajs/medusa": "^1.3.1", + "medusa-interfaces": "^1.3.0", + "typeorm": "^0.2.36" +}, +"devDependencies": { + "@babel/cli": "^7.14.3", + "@babel/core": "^7.14.3", + "@babel/preset-typescript": "^7.14.5", + "babel-preset-medusa-package": "^1.1.19", +} +``` + +The packages `@medusajs/medusa` and `medusa-interfaces` act as peer dependencies. They’ll be installed while you develop your package, and they are required when your plugin is installed in another NPM project. + +You remove the packages `medusa-fulfillment-manual`, `medusa-payment-manual`, and `medusa-payment-stripe` as they are fulfillment and payment plugins necessary for a Medusa server, but not for a plugin. + +Additionally, you remove `@medusajs/medusa-cli` as you don’t need to use the Medusa CLI while developing a plugin. + +Once you’re done making these changes, re-run the install command to update your `node_modules` directory: + +```bash npm2yarn +npm install +``` + +## Recommended Changes in package.json + +This section includes recommended changes to your `package.json`. You can skip any of these changes if you don’t find them necessary to your plugin. + +### Change Basic Info + +`package.json` holds information that further describes the package or the author that created the package. It is recommended to make the following changes: + +- `description`: Change this to a sentence that describes what your plugin does. +- `author`: Your name and email. +- `repository`: The repository that holds your plugin’s codebase. +- `keywords`: This should hold the keywords that are related to your plugin. It’s recommended that all plugins use the keywords `medusa-plugin` or `medusa`. + +### Change scripts + +A basic Medusa installation comes with the following scripts: + +```json +"scripts": { + "seed": "medusa seed -f ./data/seed.json", + "build": "babel src -d dist --extensions \".ts,.js\"", + "start": "medusa develop" +} +``` + +The `seed` and `start` scripts are not necessary for plugin development so you can remove them. + +It’s also recommended to add the `watch` script that automatically compiles your files if they are changed: + +```json +"watch": "babel -w src --out-dir . --ignore **/__tests__" +``` + +This is helpful when testing the plugin. + +:::note + +Testing the plugin is covered in a later section. + +::: + +Another recommended script is the `prepare` script that builds your files under a “production” environment: + +```json +"prepare": "cross-env NODE_ENV=production npm run build" +``` + +You would typically run this script before publishing your plugin. + +This script requires installing the package `cross-env` as a development dependency: + +```bash npm2yarn +npm install --save-dev cross-env +``` + +## Develop your Plugin + +Now, You can start developing your plugin. This can include adding services, endpoints, entities, or anything that is relevant to your plugin. + +This guide does not cover how to create each of those files or components. If you’re interested in learning how to do that, you can check out these guides: + +- How to create endpoints for [storefront](../endpoints/add-storefront.md) and [admin](../endpoints/add-admin.md) +- How to [create a service](../services/create-service.md) +- How to [create a subscriber](../subscribers/create-subscriber.md) +- How to create an entity +- How to [create a migration](../migrations.md) + +## Add Plugin Configuration + +Plugins often allow developers that will later use them to enter their own configuration. For example, you can allow developers to specify the API key of a service you’re integrating. + +To pass a plugin its configurations on a Medusa server, you have to add it to the `plugins` array in `medusa-config.js`: + +```jsx +const plugins = [ + //... + { + resolve: `medusa-plugin-custom`, + options: { + name: 'My Store' + } + } +]; +``` + +Then, you can have access to your plugin configuration in the constructor of services in your plugin: + +```jsx +//In a service in your plugin +constructor({}, options) { + //options contains plugin configurations + this.name = options.name +} +``` + +You can also have access to the configurations in endpoints in your plugin: + +```jsx +//in an endpoint in your plugin +export default (rootDirectory, options) => { + //options contain the plugin configurations + const router = Router() + + router.get("/hello-world", (req, res) => { + res.json({ + message: `Welcome to ${options.name ? options.name : 'Medusa'}!` + }) + }) + + return router; +} +``` + +:::tip + +Make sure to include in the README of your plugin the configurations that can be passed to a plugin. + +::: + +## Test Your Plugin + +While you develop your plugin, you’ll need to test it on an actual Medusa server. This can be done by using the [npm link](https://docs.npmjs.com/cli/v8/commands/npm-link) command. + +In the root of your plugin directory, run the following command: + +```bash npm2yarn +npm link +``` + +Then, change to the directory of the Medusa server you want to test the plugin on and run the following command: + +```bash npm2yarn +npm link medusa-plugin-custom +``` + +Where `medusa-plugin-custom` is the package name of your plugin. + +After linking to your plugin in a local Medusa server, either run the `build` or `watch` commands in your plugin directory: + +```bash npm2yarn +# in the directory of the plugin +npm run watch +``` + +:::tip + +If you’re running the `watch` command, you don’t need to run the `build` command every time you make a change to your plugin. + +::: + +Then, add your plugin into the array of plugins in `medusa-config.js`: + +```jsx +const plugins = [ + //... + { + resolve: `medusa-plugin-custom`, + //if your plugin has configurations + options: { + name: 'My Store' + } + } +]; +``` + +:::note + +If your plugin has migrations, you must run them before you start the server. Check out the [Migrations guide](../migrations.md#run-migration) for more details. + +::: + +Finally, start your server and test your plugin’s functionalities: + +```bash npm2yarn +npm run start +``` + +## NPM Ignore File + +Not all files that you use while developing your plugin are necessary to be published. + +For example, the files you add in the `src` directory are compiled to a `dist` directory before publishing. Then, when a developer installs your plugin, they’ll just be using the files under the `dist` directory. + +So, you can ignore files and directories like `src` from the final published NPM package. + +To do that, create the file `.npmignore` with the following content: + +```bash +/lib +node_modules +.DS_store +.env* +/*.js +!index.js +yarn.lock +src +.gitignore +.eslintrc +.babelrc +.prettierrc + +#These are files that are included in a +#Medusa project and can be removed from a +#plugin project +medusa-config.js +Dockerfile +medusa-db.sql +develop.sh +``` + +## Publish Plugin + +Once you’re done developing your plugin you can publish the package on NPM’s registry so that other developers can benefit from it and use it. + +Before you publish a plugin, you must [create an account on NPM](https://www.npmjs.com/signup). + +### Login + +In your terminal, log in with your NPM account: + +```bash +npm login +``` + +You’ll be asked to enter your NPM email and password. + +### Publish Plugin Package + +Once you’re logged in, you can publish your package with the following command: + +```bash +npm publish +``` + +Your package is then published on NPM and everyone can use it and install it. + +### Update Plugin + +To update your plugin at a later point, you can run the following command to change the NPM version: + +```bash +npm version +``` + +Where `` indicates the type of version update you’re publishing. For example, it can be `major` or `minor`. + +You can see the [full list of types in NPM’s documentation](https://docs.npmjs.com/cli/v8/commands/npm-version). + +Then, publish the new update: + +```bash +npm publish +``` + +## Add Plugin to Medusa’s Repository + +All officially-supported plugins are available in the [`packages` directory of the Medusa GitHub repository](https://github.com/medusajs/medusa/tree/master/packages). + +If you’re interested in adding your plugin, you need to create a new pull request (PR) where you add your plugin inside the `packages` directory. Our team will then review your plugin, and if it’s approved the PR will be merged and your plugin will be available on Medusa’s repository. + +:::note + +Before contributing to the Medusa repository, please check out the [contribution guidelines](https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md). + +::: + +## Install a Plugin + +To install any published plugin, you can run the following command on any Medusa server project: + +```bash npm2yarn +npm install medusa-plugin-custom +``` + +## What’s Next 🚀 + +- Check out [available Services in Medusa](references/services/../../../../../references/services/classes/AuthService.md) that you can use in your plugin. +- Check out [available events](../subscribers/events-list.md) that you can listen to in Subscribers. +- Check out [available official plugins](https://github.com/medusajs/medusa/tree/master/packages). diff --git a/docs/content/advanced/backend/plugins/overview.md b/docs/content/advanced/backend/plugins/overview.md new file mode 100644 index 0000000000..d8b51f7de6 --- /dev/null +++ b/docs/content/advanced/backend/plugins/overview.md @@ -0,0 +1,54 @@ +# Plugins + +In this document, you’ll get an overview of plugins in Medusa, where to find them, and how to install them. If you want to learn how to create a plugin, check out [this guide](create.md) instead. + +## Overview + +Medusa was built with flexibility and extendibility in mind. All different components and functionalities in Medusa are built with an abstraction layer that gives developers the freedom to choose what services they want to use or how to implement a certain component in their ecommerce store. + +Developers can use plugins to take advantage of this abstraction, flexibility, and extendibility. Plugins allow developers to implement custom features or integrate third-party services into Medusa. + +For example, if you want to use Stripe as a payment provider in your store, then you can install the Stripe plugin on your server and use it. + +An alternative approach is developing a custom way of handling payment on your ecommerce store. Both approaches are achievable by either creating a plugin or using an existing plugin. + +Plugins run within the same process as the core Medusa server eliminating the need for extra server capacity, infrastructure, and maintenance. As a result, plugins can use all other services as dependencies and access the database. + +## Using Existing Plugins + +### Official Plugins + +Medusa has official plugins that cover different aspects and functionalities such as payment, CMS, fulfillment, and notifications. You can check out the available plugins under the [packages directory in the Medusa repository on GitHub](https://github.com/medusajs/medusa/tree/master/packages). + +:::tip + +To feature your plugin in our repository, you can send a pull request that adds your plugin into the `packages` directory. Our team will review your plugin and, if approved, will merge the pull request and add your plugin in the repository. + +::: + +### Community Plugins + +You can find community plugins by [searching NPM for the `medusa` or `medusa-plugin` keywords](https://www.npmjs.com/search?q=keywords%3Amedusa%2Cmedusa-plugin). + +You can also check the [Awesome Medusa repository](https://github.com/adrien2p/awesome-medusajs#plugins) for a list of community plugins among other resources. + +## How to Install a Plugin + +To install an existing plugin, in your Medusa server run the following command: + +```bash npm2yarn +npm install +``` + +Where `` is the package name of the plugin. For example, if you’re installing the Stripe plugin `` is `medusa-payment-stripe`. + +### Plugin Configuration + +If you’re installing an official plugin from the Medusa repository, you can find in its `README.md` file a list of configurations that are either required or optional. You can also refer to the documentation related to that plugin for more details on how to install, configure, and use it. + +For community plugins, please refer to the installation instructions of that plugin to learn about any required configurations. + +## What’s Next 🚀 + +- Learn how to [create your own plugin](create.md). +- Learn how to [create a fulfillment provider](../shipping/add-fulfillment-provider.md) or a [payment provider](../payment/how-to-create-payment-provider.md). diff --git a/docs/content/advanced/backend/shipping/overview.md b/docs/content/advanced/backend/shipping/overview.md index 6c217e7414..60acadef38 100644 --- a/docs/content/advanced/backend/shipping/overview.md +++ b/docs/content/advanced/backend/shipping/overview.md @@ -31,7 +31,7 @@ Fulfillment Providers can also be related to a custom way of handling fulfillmen ### How Fulfillment Provider is Created -A Fulfillment Provider is essentially a Medusa [Service](../services/create-service.md) with a unique identifier, and it extends the `FulfillmentService` provided by the `medusa-interfaces` package. It can be created as part of a [plugin](../../../guides/plugins.md), or it can be created just as a Service file in your Medusa server. +A Fulfillment Provider is essentially a Medusa [Service](../services/create-service.md) with a unique identifier, and it extends the `FulfillmentService` provided by the `medusa-interfaces` package. It can be created as part of a [plugin](../plugins/overview.md), or it can be created just as a Service file in your Medusa server. As a developer, you will mainly work with the Fulfillment Provider when integrating a fulfillment method in Medusa. diff --git a/docs/content/guides/file-plugin.md b/docs/content/guides/file-plugin.md index 0112bdd8ed..c7b841240e 100644 --- a/docs/content/guides/file-plugin.md +++ b/docs/content/guides/file-plugin.md @@ -4,7 +4,7 @@ title: Create a file plugin # File Plugin -This guide will give an introduction about the File Service and steps required to create a custom file uploader plugin for Medusa. It build on article about [creating custom plugins](https://docs.medusajs.com/guides/plugins). +This guide will give an introduction about the File Service and steps required to create a custom file uploader plugin for Medusa. It build on article about [creating custom plugins](../advanced/backend/payment/overview.md). As an example, we will create a File plugin that uploads the product images to Cloudinary. diff --git a/docs/content/guides/fulfillment-api.md b/docs/content/guides/fulfillment-api.md index 47e3d3c385..d52fa8b8c0 100644 --- a/docs/content/guides/fulfillment-api.md +++ b/docs/content/guides/fulfillment-api.md @@ -6,7 +6,7 @@ title: Fulfillment API This guide will give an overview of Medusa's Fulfillment API and how it can be implemented to work with different fulfillment providers. Before digging deeper into the API it should be clarified what is meant by a fulfillment provider; in Medusa a fulfillment provider is typically a 3rd party service that can handle order data for the purpose of shipping the items in the order to a customer. Examples of fulfillment providers are: a carrier like UPS, a logistics platform like ShipBob or a 3PL solution. -Implementations of the Fulfillment API can be distributed as npm packages for easy installation through the plugin system, there are already a couple of examples of fulfillment plugins in the Medusa monorepo, you can identify these by looking for `medusa-fulfillment-*`. For further details on building and publishing plugins [please check this guide](https://docs.medusajs.com/guides/plugins). +Implementations of the Fulfillment API can be distributed as npm packages for easy installation through the plugin system, there are already a couple of examples of fulfillment plugins in the Medusa monorepo, you can identify these by looking for `medusa-fulfillment-*`. For further details on building and publishing plugins [please check this guide](../advanced/backend/payment/overview.md). ## Fulfillment Service Interface @@ -68,4 +68,4 @@ If the shipping option is configured to dynamically calculate the price of the t ## What's next? -Now that you have an overview of the Fulfillment API you can start developing your own fulfillment plugin. For a guide on how to create plugins [check this guide](https://docs.medusajs.com/how-to/plugins). If you have questions or issues please feel free to [join our Discord server](https://discord.gg/medusajs) for direct access to the engineering team. +Now that you have an overview of the Fulfillment API you can start developing your own fulfillment plugin. For a guide on how to create plugins [check this guide](../advanced/backend/payment/overview.md). If you have questions or issues please feel free to [join our Discord server](https://discord.gg/medusajs) for direct access to the engineering team. diff --git a/docs/content/guides/plugins.md b/docs/content/guides/plugins.md deleted file mode 100644 index 07fcf5e36d..0000000000 --- a/docs/content/guides/plugins.md +++ /dev/null @@ -1,150 +0,0 @@ ---- -title: Plugins ---- - -# Plugins - -The purpose of this guide is to give an introduction to the structure of a plugin and the steps required to create one. It builds upon our article describing the process of [adding custom functionality](https://docs.medusajs.com/tutorial/adding-custom-functionality). It can be seen as the proceeding steps for extracting your custom functionality to a reusable package for other developers to use. - -## What is a plugin? - -Plugins offer a way to extend and integrate the core functionality of Medusa. - -In most commerce solutions, you can extend the basic features but it often comes with the expense of having to build standalone web applications. Our architecture is built such that plugins run within the same process as the core eliminating the need for extra server capacity, infrastructure and maintenance. As a result, the plugins can use all other services as dependencies and access the database. - -:::note - -You will notice that plugins vary in naming. The name should signal what functionality they provide. - -::: - -In the following sections, we will go through the basics of implementing a generic plugin. And finally, how to use it as part of your commerce setup. - -## Building a plugin - -A plugin is essentially a Node.js project of their own. They contain a file in root, `package.json`, that holds all metadata and dependencies of the project. - -The first step in creating a plugin is to initialize the Node.js project: - -```bash npm2yarn -npm init -``` - -This command will ask you to fill out your project's metadata, which will eventually be used when publishing the package to NPM. After this command completes, you are ready to start implementing the functionality. - -### Implementation - -We've already gone through the process of building custom services, endpoints, and subscribers in another tutorial, so this will not be repeated. The process is the same for the logic within a plugin, meaning that the functionality is loaded as part of the core if the correct naming convention is followed. - -To quickly get started with the implementation, we advise you to copy `/services/welcome.js`, `/api/index.js`, `/subscribers/welcome.js` and the config files from the tutorial and add them in `/src`. As a result, you should have the following folder structure: - -:::note - -Since the container resolution paths are automatically generated from the used directories and filenames you should avoid pre- or suffixing your file (e.g. `services/welcomeService.js` would result in the service being registered as `WelcomeServiceService`). - -::: - -```js -. -├── src -│ ├── api -│ └── index.js -│ └── services -│ └── welcome.js -│ └── subscribers -│ └── welcome.js -├── .babelrc -├── .gitignore -├── medusa-config.js -├── README.md -└── package.json -``` -Please note that you will need some build step before being able to properly load your plugin, since Medusa expects to find the directories (`api`, `services`, `subscribers`, `loaders`…) within the npm package root. In the simplest case, this could be you manually copying the folders from `src`. - -It is worth mentioning the difference between building a generic and a non-generic plugin. A non-generic plugin has a specific purpose such as processing payments or creating fulfillments. Medusa core depends on a specific implementation from such plugins, which is why we've created interfaces that enforce this. These can be found in `medusa-interfaces`. - -:::note - -Non-generic plugins are required to extend the correct interface, otherwise they will not be loaded correctly as part of your Medusa setup. - -::: - -For a more comprehensive walkthrough of the implementation of such plugins, see our guides: - -- How to build a fulfillment provider (Coming soon!) -- How to build a payment provider (Coming soon!) - -### Publishing - -In order for your plugin to become a part of the Medusa plugin ecosystem, you need to publish it to NPM. Make sure that you've included the `package.json` file. NPM uses the details of this file to configure the publishing. Please include `medusa` and `medusa-plugin` and possibly more in the `keywords` field of the `package.json`. - -```bash -{ - "name": "medusa-payment-stripe", - ... - "keywords": [ - "medusa", - "medusa-payment", - "medusa-plugin" - ], - "description": "Stripe Payment provider for Medusa Commerce", - ... -} -``` - -Finally, you should add a README for the plugin, such that the community understands the purpose of the plugin and how to install it. - -## Installation and configuration - -Official Medusa plugins can be found within the [mono repo](https://github.com/medusajs/medusa/tree/master/packages) and community plugins can be found by searching NPM for keywords such as `medusa` or `medusa-plugin`. - -Note: For plugins to become a part of the mono repo, we require you to submit a PR request. If approved, we will publish it under the Medusa organisation on Github. - -Plugins are distributed as NPM packages making it possible for developers to simply install and use a plugin via: - -```bash npm2yarn -npm install -``` - -After installing a plugin using your preferred package manager, it should be added to `medusa-config.js`. We allow you to provide options for plugins. These options can be used for anything ranging from provider requirements such as API keys or custom configuration used in the plugin's logic. These options are injected into the services, subscribers, and APIs of the plugin. - -The following steps will install the official Contentful plugin for your Medusa engine: - -### Step 1: Installation - -First, we add the plugin as a dependency to your project: - -```bash npm2yarn -npm install medusa-plugin-contentful -``` - -### Step 2: Configuration - -In the README of the plugin, you will see the options for the plugin. Some are required and some are optional. - -In your `medusa-config.js`, add the plugin and the required options: - -```js -const plugins = [ - ... - { - resolve: `medusa-plugin-contentful`, - options: { - space_id: "some_space_id", - access_token: "some_access_token", - environment: "some_environment", - }, - }, - ... -] -``` - -### Step 3: Usage - -Depending on the purpose of the plugin, you will now be able to use the extended functionality as part of your commerce setup. - -In this case, you will need to add a content type in Contentful with the fields described in the README. Products created in Medusa Admin will now be synced to Contentful, such that you can enrich them with more details enabling you to enhance the customer experience of your webshop. - -## Summary - -As a result of following this guide, you should now be able to both implement and install plugins for you Medusa project. diff --git a/docs/content/how-to/create-medusa-app.md b/docs/content/how-to/create-medusa-app.md index 27c78a2267..bd4a208aca 100644 --- a/docs/content/how-to/create-medusa-app.md +++ b/docs/content/how-to/create-medusa-app.md @@ -116,6 +116,6 @@ To learn more about Medusa, go through our docs to get some inspiration and guid - [Find out how to set up a Medusa project with Gatsby and Contentful](https://docs.medusajs.com/how-to/headless-ecommerce-store-with-gatsby-contentful-medusa) - [Move your Medusa setup to the next level with some custom functionality](https://docs.medusajs.com/tutorial/adding-custom-functionality) -- [Create your own Medusa plugin](https://docs.medusajs.com/guides/plugins) +- [Create your own Medusa plugin](../advanced/backend/payment/overview.md) If you have any follow-up questions or want to chat directly with our engineering team, we are always happy to meet you at our [Discord](https://discord.gg/DSHySyMu). diff --git a/www/docs/docusaurus.config.js b/www/docs/docusaurus.config.js index bafacec1c6..e5b7caf835 100644 --- a/www/docs/docusaurus.config.js +++ b/www/docs/docusaurus.config.js @@ -26,7 +26,7 @@ module.exports = { [ "docusaurus-plugin-segment", { - apiKey: process.env.SEGMENT_API_KEY + apiKey: process.env.SEGMENT_API_KEY || "temp" } ] ], diff --git a/www/docs/sidebars.js b/www/docs/sidebars.js index 57d9b3289f..cda315899a 100644 --- a/www/docs/sidebars.js +++ b/www/docs/sidebars.js @@ -203,8 +203,20 @@ module.exports = { ] }, { - type: "doc", - id: "guides/plugins", + type: "category", + label: "Plugins", + collapsed: true, + items: [ + { + type: "doc", + id: "advanced/backend/plugins/overview", + label: "Overview" + }, + { + type: "doc", + id: "advanced/backend/plugins/create", + } + ] }, { type: "doc",