docs: general fixes across docs (#4737)
* docs: general fixes across docs * added deploy button to railway * fix eslint errors * fixes
This commit is contained in:
14
docs/content/development/cache/create.md
vendored
14
docs/content/development/cache/create.md
vendored
@@ -30,11 +30,11 @@ You can refer to the [Project Preparation step in the Create Module documentatio
|
||||
|
||||
## Step 1: Create the Service
|
||||
|
||||
Create the file `services/memcached-cache.ts` which will hold your cache service. Note that the name of the file is recommended to be in the format `<service_name>-cache`. So, if you’re not integrating `memcached`, you should replace the name with what’s relevant for your module.
|
||||
Create the file `src/services/memcached-cache.ts` which will hold your cache service. Note that the name of the file is recommended to be in the format `<service_name>-cache`. So, if you’re not integrating `memcached`, you should replace the name with what’s relevant for your module.
|
||||
|
||||
Add the following content to the file:
|
||||
|
||||
```ts title=services/memcached-cache.ts
|
||||
```ts title=src/services/memcached-cache.ts
|
||||
import { ICacheService } from "@medusajs/types"
|
||||
|
||||
class MemcachedCacheService implements ICacheService {
|
||||
@@ -201,12 +201,14 @@ class MemcachedCacheService implements ICacheService {
|
||||
|
||||
After implementing the cache service, you must export it so that the Medusa backend can use it.
|
||||
|
||||
Create the file `index.ts` with the following content:
|
||||
Create the file `src/index.ts` with the following content:
|
||||
|
||||
```ts title=index.ts
|
||||
```ts title=src/index.ts
|
||||
import { ModuleExports } from "@medusajs/modules-sdk"
|
||||
|
||||
import { MemcachedCacheService } from "./services"
|
||||
import {
|
||||
MemcachedCacheService,
|
||||
} from "./services/memcached-cache"
|
||||
|
||||
const service = MemcachedCacheService
|
||||
|
||||
@@ -235,7 +237,7 @@ module.exports = {
|
||||
modules: {
|
||||
// ...
|
||||
cacheService: {
|
||||
resolve: "path/to/custom-module",
|
||||
resolve: "path/to/custom-module/src/index.ts",
|
||||
options: {
|
||||
// any necessary options
|
||||
ttl: 30,
|
||||
|
||||
@@ -15,9 +15,9 @@ After creating the file under `src/subscribers`, in the constructor of your subs
|
||||
|
||||
The `eventBusService.subscribe` method receives the name of the event as a first parameter and as a second parameter a method in your subscriber that will handle this event.
|
||||
|
||||
For example, here is the `OrderNotifierSubscriber` class created in `src/subscribers/orderNotifier.ts`:
|
||||
For example, here is the `OrderNotifierSubscriber` class created in `src/subscribers/order-notifier.ts`:
|
||||
|
||||
```ts title=src/subscribers/orderNotifier.ts
|
||||
```ts title=src/subscribers/order-notifier.ts
|
||||
class OrderNotifierSubscriber {
|
||||
constructor({ eventBusService }) {
|
||||
eventBusService.subscribe("order.placed", this.handleOrder)
|
||||
@@ -93,7 +93,7 @@ You can access any service through the dependencies injected to your subscriber
|
||||
|
||||
For example:
|
||||
|
||||
```ts title=src/subscribers/orderNotifier.ts
|
||||
```ts title=src/subscribers/order-notifier.ts
|
||||
class OrderNotifierSubscriber {
|
||||
constructor({ productService, eventBusService }) {
|
||||
this.productService = productService
|
||||
@@ -109,7 +109,7 @@ class OrderNotifierSubscriber {
|
||||
|
||||
You can then use `this.productService` anywhere in your subscriber’s methods. For example:
|
||||
|
||||
```ts title=src/subscribers/orderNotifier.ts
|
||||
```ts title=src/subscribers/order-notifier.ts
|
||||
class OrderNotifierSubscriber {
|
||||
// ...
|
||||
handleOrder = async (data) => {
|
||||
@@ -129,4 +129,6 @@ When using attributes defined in the subscriber, such as the `productService` in
|
||||
|
||||
## See Also
|
||||
|
||||
- [Example: send order confirmation email](../../modules/orders/backend/send-order-confirmation.md)
|
||||
- [Example: send registration confirmation email](../../modules/customers/backend/send-confirmation.md)
|
||||
- [Create a Plugin](../plugins/create.mdx)
|
||||
@@ -13,6 +13,12 @@ In this document, you’ll learn what events are and why they’re useful in Med
|
||||
|
||||
Events are used in Medusa to inform different parts of the commerce ecosystem that this event occurred. For example, when an order is placed, the `order.placed` event is triggered, which informs notification services like SendGrid to send a confirmation email to the customer.
|
||||
|
||||
:::tip
|
||||
|
||||
If you want to implement order confirmation emails, you can check this [step-by-step guide](../../modules/orders/backend/send-order-confirmation.md).
|
||||
|
||||
:::
|
||||
|
||||
The events system in Medusa is built on a publish/subscribe architecture. The Medusa core publish an event when an action takes place, and modules, plugins, or other forms of customizations can subscribe to that event. [Subscribers](./subscribers.mdx) can then perform a task asynchronously when the event is triggered.
|
||||
|
||||
Although the core implements the main logic behind the events system, you’ll need to use an event module that takes care of the publish/subscribe functionality such as subscribing and emitting events. Medusa provides modules that you can use both for development and production, including Redis and Local modules.
|
||||
|
||||
@@ -20,9 +20,11 @@ Before you start implementing the custom functionality in your module, it's reco
|
||||
```
|
||||
custom-module
|
||||
|
|
||||
|___ index.ts
|
||||
|
|
||||
|___ services // directory
|
||||
|___ src
|
||||
|
|
||||
|___ index.ts
|
||||
|
|
||||
|___ services // directory
|
||||
```
|
||||
|
||||
The directory can be an NPM project, but that is optional. `index.ts` acts as an entry point to your Module. You'll learn about its content in a later step. The `service` directory will hold your custom services. If you're adding other resources you can add other directories for them. For example, if you're adding an entity you can add a `models` directory.
|
||||
@@ -219,12 +221,14 @@ For example, consider you have the following file structure:
|
||||
|
|
||||
|___ custom-module
|
||||
| |
|
||||
| |___ index.ts
|
||||
| |
|
||||
| |___ services
|
||||
| | |
|
||||
| | |___ custom-service.ts
|
||||
| |___ // more files
|
||||
| |___ src
|
||||
| |
|
||||
| |___ index.ts
|
||||
| |
|
||||
| |___ services
|
||||
| | |
|
||||
| | |___ custom-service.ts
|
||||
| |___ // more files
|
||||
|
|
||||
|
|
||||
|___ medusa-backend
|
||||
@@ -240,7 +244,7 @@ module.exports = {
|
||||
modules: {
|
||||
// ...
|
||||
moduleType: {
|
||||
resolve: "../custom-module",
|
||||
resolve: "../custom-module/src",
|
||||
// ...
|
||||
},
|
||||
},
|
||||
@@ -255,7 +259,7 @@ module.exports = {
|
||||
modules: {
|
||||
// ...
|
||||
moduleType: {
|
||||
resolve: "../custom-module/index.ts",
|
||||
resolve: "../custom-module/src/index.ts",
|
||||
// ...
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user