From f73ca97ecc6123ae07776700c0cab298e46fc262 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 16 Jul 2024 19:12:05 +0300 Subject: [PATCH] docs: rename data to event in subscribers across docs (#8149) --- .../data-payload/page.mdx | 14 +++++------ .../basics/events-and-subscribers/page.mdx | 4 +-- www/apps/book/app/basics/workflows/page.mdx | 4 +-- .../notification/send-notification/page.mdx | 12 ++++----- .../notification/sendgrid/page.mdx | 12 ++++----- .../app/recipes/commerce-automation/page.mdx | 25 +++++++++---------- .../integrate-ecommerce-stack/page.mdx | 5 ++-- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/www/apps/book/app/advanced-development/events-and-subscribers/data-payload/page.mdx b/www/apps/book/app/advanced-development/events-and-subscribers/data-payload/page.mdx index 34caeb54e5..51ed7304a4 100644 --- a/www/apps/book/app/advanced-development/events-and-subscribers/data-payload/page.mdx +++ b/www/apps/book/app/advanced-development/events-and-subscribers/data-payload/page.mdx @@ -12,12 +12,12 @@ In this chapter, you'll learn how subscribers receive an event's data payload. When events are emitted, they’re emitted with a data payload. -The object that the subscriber function receives as a parameter has a `data` property, which is an object holding the event payload with additional context. +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", "", "The event's data payload."], + ["7", "event", "The event details."], ["8", "{ id: string }", "The type of expected data payloads."], ] @@ -28,9 +28,9 @@ import type { } from "@medusajs/medusa" export default async function productCreateHandler({ - data, + event, }: SubscriberArgs<{ id: string }>) { - const productId = data.data.id + const productId = event.data.id console.log(`The product ${productId} was created`) } @@ -39,16 +39,16 @@ export const config: SubscriberConfig = { } ``` -The `data` object has the following properties: +The `event` object has the following properties: ) { const productModuleService: IProductModuleService = container.resolve(ModuleRegistrationName.PRODUCT) - const productId = data.data.id + const productId = data.id const product = await productModuleService.retrieveProduct( productId diff --git a/www/apps/book/app/basics/workflows/page.mdx b/www/apps/book/app/basics/workflows/page.mdx index 3b1a1610b5..5315f2b0c6 100644 --- a/www/apps/book/app/basics/workflows/page.mdx +++ b/www/apps/book/app/basics/workflows/page.mdx @@ -130,10 +130,10 @@ To execute the workflow, invoke it passing the Medusa container as a parameter. import { IUserModuleService } from "@medusajs/types" export default async function handleCustomerCreate({ - data, + event: { data }, container, }: SubscriberArgs<{ id: string }>) { - const userId = data.data.id + const userId = data.id const userModuleService: IUserModuleService = container.resolve( ModuleRegistrationName.USER ) diff --git a/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx b/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx index 52b6c6cd74..e38d6a3298 100644 --- a/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx @@ -14,19 +14,19 @@ In your resource, such as a subscriber, resolve the Notification Module's main s export const highlights = [ ["12", "notificationModuleService", "Resolve the Notification Module."], - ["17", "create", "Create the notification to be sent."], + ["15", "create", "Create the notification to be sent."], [ - "19", + "17", '"email"', "Use the module provider defined for the `email` channel to send an email.", ], [ - "20", + "18", '"product-created"', "The ID of the template defined in the third-party service, such as SendGrid.", ], [ - "21", + "19", "data", "The data to pass to the template defined in the third-party service.", ], @@ -41,7 +41,7 @@ import { ModuleRegistrationName } from "@medusajs/utils" import { INotificationModuleService } from "@medusajs/types" export default async function productCreateHandler({ - data, + event: { data }, container, }: SubscriberArgs<{ id: string }>) { const notificationModuleService: INotificationModuleService = @@ -51,7 +51,7 @@ export default async function productCreateHandler({ to: "shahednasser@gmail.com", channel: "email", template: "product-created", - data: data.data, + data, }) } diff --git a/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx b/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx index c864b1d1bf..252e2890d3 100644 --- a/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx @@ -116,14 +116,14 @@ To test the module out, create a simple subscriber at `src/subscribers/product-c export const highlights = [ ["12", "notificationModuleService", "Resolve the Notification Module."], - ["17", "create", "Create the notification to be sent."], + ["15", "create", "Create the notification to be sent."], [ - "19", + "17", '"email"', "By specifying the `email` channel, SendGrid will be used to send the notification.", ], - ["20", '"product-created"', "The ID of the template defined in SendGrid."], - ["21", "data", "The data to pass to the template defined in SendGrid."], + ["18", '"product-created"', "The ID of the template defined in SendGrid."], + ["19", "data", "The data to pass to the template defined in SendGrid."], ] ```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports" @@ -135,7 +135,7 @@ import { ModuleRegistrationName } from "@medusajs/utils" import { INotificationModuleService } from "@medusajs/types" export default async function productCreateHandler({ - data, + event: { data }, container, }: SubscriberArgs<{ id: string }>) { const notificationModuleService: INotificationModuleService = @@ -145,7 +145,7 @@ export default async function productCreateHandler({ to: "test@gmail.com", channel: "email", template: "product-created", - data: data.data, + data, }) } diff --git a/www/apps/resources/app/recipes/commerce-automation/page.mdx b/www/apps/resources/app/recipes/commerce-automation/page.mdx index 551f48d098..6286191e5c 100644 --- a/www/apps/resources/app/recipes/commerce-automation/page.mdx +++ b/www/apps/resources/app/recipes/commerce-automation/page.mdx @@ -795,10 +795,10 @@ The `order.placed` event is currently not emitted. } from "@medusajs/types" export default async function orderCreatedHandler({ - data, + event: { data }, container, }: SubscriberArgs<{ id: string }>) { - const orderId = data.data.id + const orderId = data.id const orderModuleService: IOrderModuleService = container .resolve(ModuleRegistrationName.ORDER) @@ -886,15 +886,15 @@ You can also create a scheduled job that checks whether the number of new produc For example, create the file `src/subscribers/send-products-newsletter.ts` with the following content: export const newsletterHighlights = [ - ["33", "store", "Retrieve the first store in the application."], - ["35", "products", "Retrieve the products created since the last newsletter send date."], - ["41", "", "Check whether more than 10 products have been created before proceeding."], - ["45", "customers", "Retrieve all customers, assuming they're considered subscribed."], - ["47", "createNotifications", "Send a notification (newsletter) to each customer using the Notification Module."], - ["50", '"email"', "Send the notification through the email channel."], - ["51", '"newsletter_template"', "Specify the template name in the third-party service (for example, SendGrid)."], - ["53", "products", "Pass the created products to the template."], - ["58", "updateStores", "Update the store's `last_newsletter_send_date` property with the current date."] + ["32", "store", "Retrieve the first store in the application."], + ["34", "products", "Retrieve the products created since the last newsletter send date."], + ["40", "", "Check whether more than 10 products have been created before proceeding."], + ["44", "customers", "Retrieve all customers, assuming they're considered subscribed."], + ["46", "createNotifications", "Send a notification (newsletter) to each customer using the Notification Module."], + ["49", '"email"', "Send the notification through the email channel."], + ["50", '"newsletter_template"', "Specify the template name in the third-party service (for example, SendGrid)."], + ["52", "products", "Pass the created products to the template."], + ["57", "updateStores", "Update the store's `last_newsletter_send_date` property with the current date."] ] ```ts title="src/subscribers/send-products-newsletter.ts" highlights={newsletterHighlights} collapsibleLines="1-14" expandButtonLabel="Show Imports" @@ -913,7 +913,6 @@ export const newsletterHighlights = [ } from "@medusajs/types" export default async function productCreateHandler({ - data, container, }: SubscriberArgs<{ id: string }>) { const productModuleService: IProductModuleService = @@ -926,7 +925,7 @@ export const newsletterHighlights = [ container.resolve(ModuleRegistrationName.CUSTOMER) const notificationModuleService: - INotificationModuleService = container.resolve( + INotificationModuleService = container.resolve( ModuleRegistrationName.NOTIFICATION ) diff --git a/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx b/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx index ee66a31d74..b9b19a560f 100644 --- a/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx +++ b/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx @@ -264,12 +264,13 @@ export const workflowHighlights = [ import createProductWorkflow from "../workflows/create-product" export default async function handleProductUpdate({ - data, container + event: { data }, + container }: SubscriberArgs<{id: string}>) { createProductWorkflow(container) .run({ input: { - productId: data.data.id + productId: data.id } }) .then(() => {