docs: revise main docs outline (#10502)

This commit is contained in:
Shahed Nasser
2024-12-09 13:54:42 +02:00
committed by GitHub
parent c8cb9b5c1a
commit 0ae98c51eb
141 changed files with 814 additions and 1181 deletions
@@ -0,0 +1,69 @@
import { TypeList } from "docs-ui"
export const metadata = {
title: `${pageNumber} Event Data Payload`,
}
# {metadata.title}
In this chapter, you'll learn how subscribers receive an event's data payload.
## Access Event's Data Payload
When events are emitted, theyre emitted with a data payload.
The object that the subscriber function receives as a parameter has an `event` property, which is an object holding the event payload in a `data` property with additional context.
For example:
export const highlights = [
["7", "event", "The event details."],
["8", "{ id: string }", "The type of expected data payloads."],
]
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-5" expandButtonLabel="Show Imports"
import type {
SubscriberArgs,
SubscriberConfig,
} from "@medusajs/framework"
export default async function productCreateHandler({
event,
}: SubscriberArgs<{ id: string }>) {
const productId = event.data.id
console.log(`The product ${productId} was created`)
}
export const config: SubscriberConfig = {
event: "product.created",
}
```
The `event` object has the following properties:
<TypeList types={[
{
name: "data",
type: "`object`",
description: "The data payload of the event. Its properties are different for each event."
},
{
name: "name",
type: "string",
description: "The name of the triggered event."
},
{
name: "metadata",
type: "`object`",
description: "Additional data and context of the emitted event.",
optional: true
},
]} sectionTitle="Access Event's Data Payload" />
This logs the product ID received in the `product.created` events data payload to the console.
{/* ---
## List of Events with Data Payload
Refer to [this reference](!resources!/events-reference) for a full list of events emitted by Medusa and their data payloads. */}