From 8b5b96a83d20a48ff129d9647994a2446feffe3d Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 17 Apr 2025 18:47:09 +0300 Subject: [PATCH] docs-util: fix examples in workflow reference that have multiple code (#12223) --- .../page.mdx | 251 +----------------- .../page.mdx | 87 +----- .../resources/helpers/workflow-examples.ts | 16 +- 3 files changed, 14 insertions(+), 340 deletions(-) diff --git a/www/apps/resources/references/core_flows/Fulfillment/Workflows_Fulfillment/functions/core_flows.Fulfillment.Workflows_Fulfillment.createShippingOptionsWorkflow/page.mdx b/www/apps/resources/references/core_flows/Fulfillment/Workflows_Fulfillment/functions/core_flows.Fulfillment.Workflows_Fulfillment.createShippingOptionsWorkflow/page.mdx index 18b2abc949..eb68255ce0 100644 --- a/www/apps/resources/references/core_flows/Fulfillment/Workflows_Fulfillment/functions/core_flows.Fulfillment.Workflows_Fulfillment.createShippingOptionsWorkflow/page.mdx +++ b/www/apps/resources/references/core_flows/Fulfillment/Workflows_Fulfillment/functions/core_flows.Fulfillment.Workflows_Fulfillment.createShippingOptionsWorkflow/page.mdx @@ -182,256 +182,7 @@ const myWorkflow = createWorkflow( -To calculate shipping option with calculated prices, set - - - -```ts title="src/api/workflow/route.ts" -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/framework/http" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export async function POST( - req: MedusaRequest, - res: MedusaResponse -) { - `price_type` - - res.send(result) -} -``` - - - - -```ts title="src/subscribers/order-placed.ts" -import { - type SubscriberConfig, - type SubscriberArgs, -} from "@medusajs/framework" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function handleOrderPlaced({ - event: { data }, - container, -}: SubscriberArgs < { id: string } > ) { - `price_type` - - console.log(result) -} - -export const config: SubscriberConfig = { - event: "order.placed", -} -``` - - - - -```ts title="src/jobs/message-daily.ts" -import { MedusaContainer } from "@medusajs/framework/types" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function myCustomJob( - container: MedusaContainer -) { - `price_type` - - console.log(result) -} - -export const config = { - name: "run-once-a-day", - schedule: "0 0 * * *", -} -``` - - - - -```ts title="src/workflows/my-workflow.ts" -import { createWorkflow } from "@medusajs/framework/workflows-sdk" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -const myWorkflow = createWorkflow( - "my-workflow", - () => { - `price_type` - } -) -``` - - - - to - - - -```ts title="src/api/workflow/route.ts" -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/framework/http" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export async function POST( - req: MedusaRequest, - res: MedusaResponse -) { - `calculated` - - res.send(result) -} -``` - - - - -```ts title="src/subscribers/order-placed.ts" -import { - type SubscriberConfig, - type SubscriberArgs, -} from "@medusajs/framework" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function handleOrderPlaced({ - event: { data }, - container, -}: SubscriberArgs < { id: string } > ) { - `calculated` - - console.log(result) -} - -export const config: SubscriberConfig = { - event: "order.placed", -} -``` - - - - -```ts title="src/jobs/message-daily.ts" -import { MedusaContainer } from "@medusajs/framework/types" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function myCustomJob( - container: MedusaContainer -) { - `calculated` - - console.log(result) -} - -export const config = { - name: "run-once-a-day", - schedule: "0 0 * * *", -} -``` - - - - -```ts title="src/workflows/my-workflow.ts" -import { createWorkflow } from "@medusajs/framework/workflows-sdk" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -const myWorkflow = createWorkflow( - "my-workflow", - () => { - `calculated` - } -) -``` - - - - and don't pass a - - - -```ts title="src/api/workflow/route.ts" -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/framework/http" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export async function POST( - req: MedusaRequest, - res: MedusaResponse -) { - `prices` - - res.send(result) -} -``` - - - - -```ts title="src/subscribers/order-placed.ts" -import { - type SubscriberConfig, - type SubscriberArgs, -} from "@medusajs/framework" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function handleOrderPlaced({ - event: { data }, - container, -}: SubscriberArgs < { id: string } > ) { - `prices` - - console.log(result) -} - -export const config: SubscriberConfig = { - event: "order.placed", -} -``` - - - - -```ts title="src/jobs/message-daily.ts" -import { MedusaContainer } from "@medusajs/framework/types" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function myCustomJob( - container: MedusaContainer -) { - `prices` - - console.log(result) -} - -export const config = { - name: "run-once-a-day", - schedule: "0 0 * * *", -} -``` - - - - -```ts title="src/workflows/my-workflow.ts" -import { createWorkflow } from "@medusajs/framework/workflows-sdk" -import { createShippingOptionsWorkflow } from "@medusajs/medusa/core-flows" - -const myWorkflow = createWorkflow( - "my-workflow", - () => { - `prices` - } -) -``` - - - - array: +To calculate shipping option with calculated prices, set `price_type` to `calculated` and don't pass a `prices` array: :::note diff --git a/www/apps/resources/references/core_flows/Product/Workflows_Product/functions/core_flows.Product.Workflows_Product.importProductsWorkflow/page.mdx b/www/apps/resources/references/core_flows/Product/Workflows_Product/functions/core_flows.Product.Workflows_Product.importProductsWorkflow/page.mdx index 99f1d7ae64..39ba174d9c 100644 --- a/www/apps/resources/references/core_flows/Product/Workflows_Product/functions/core_flows.Product.Workflows_Product.importProductsWorkflow/page.mdx +++ b/www/apps/resources/references/core_flows/Product/Workflows_Product/functions/core_flows.Product.Workflows_Product.importProductsWorkflow/page.mdx @@ -146,92 +146,9 @@ const myWorkflow = createWorkflow( -Notice that the workflow returns a - - - -```ts title="src/api/workflow/route.ts" -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/framework/http" -import { importProductsWorkflow } from "@medusajs/medusa/core-flows" +Notice that the workflow returns a `transaction.transactionId`. You'll use this ID to confirm the import afterwards. -export async function POST( - req: MedusaRequest, - res: MedusaResponse -) { - `transaction.transactionId` - - res.send(result) -} -``` - - - - -```ts title="src/subscribers/order-placed.ts" -import { - type SubscriberConfig, - type SubscriberArgs, -} from "@medusajs/framework" -import { importProductsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function handleOrderPlaced({ - event: { data }, - container, -}: SubscriberArgs < { id: string } > ) { - `transaction.transactionId` - - console.log(result) -} - -export const config: SubscriberConfig = { - event: "order.placed", -} -``` - - - - -```ts title="src/jobs/message-daily.ts" -import { MedusaContainer } from "@medusajs/framework/types" -import { importProductsWorkflow } from "@medusajs/medusa/core-flows" - -export default async function myCustomJob( - container: MedusaContainer -) { - `transaction.transactionId` - - console.log(result) -} - -export const config = { - name: "run-once-a-day", - schedule: "0 0 * * *", -} -``` - - - - -```ts title="src/workflows/my-workflow.ts" -import { createWorkflow } from "@medusajs/framework/workflows-sdk" -import { importProductsWorkflow } from "@medusajs/medusa/core-flows" - -const myWorkflow = createWorkflow( - "my-workflow", - () => { - `transaction.transactionId` - } -) -``` - - - -. You'll use this ID to confirm the import afterwards. - -You confirm the import using the [Workflow Engine](https://docs.medusajs.com/resources/infrastructure-modules/workflow-engine). +You confirm the import using the [Workflow Engine](https://docs.medusajs.com/resources/architectural-modules/workflow-engine). For example, in an API route: ```ts workflow={false} diff --git a/www/utils/packages/typedoc-plugin-markdown-medusa/src/resources/helpers/workflow-examples.ts b/www/utils/packages/typedoc-plugin-markdown-medusa/src/resources/helpers/workflow-examples.ts index 40d80fd5f8..09bd6ff34d 100644 --- a/www/utils/packages/typedoc-plugin-markdown-medusa/src/resources/helpers/workflow-examples.ts +++ b/www/utils/packages/typedoc-plugin-markdown-medusa/src/resources/helpers/workflow-examples.ts @@ -24,11 +24,17 @@ export default function () { } else { exampleTags.forEach((exampleTag) => { exampleTag.content.forEach((part) => { - if ( - part.kind !== "code" || - part.text.startsWith("```ts workflow={false}") - ) { - exampleStr.push(part.text) + const isCode = part.kind === "code" + const isCodeBlock = part.text.startsWith("```") + const isWorkflowDisabled = part.text.startsWith( + "```ts workflow={false}" + ) + if (!isCode || !isCodeBlock || isWorkflowDisabled) { + if (!isCodeBlock && exampleStr.length > 0) { + exampleStr[exampleStr.length - 1] += part.text + } else { + exampleStr.push(part.text) + } return }