docs-util: fix examples in workflow reference that have multiple code (#12223)

This commit is contained in:
Shahed Nasser
2025-04-17 18:47:09 +03:00
committed by GitHub
parent f492a1a475
commit 8b5b96a83d
3 changed files with 14 additions and 340 deletions

View File

@@ -182,256 +182,7 @@ const myWorkflow = createWorkflow(
</CodeTab>
</CodeTabs>
To calculate shipping option with calculated prices, set
<CodeTabs group="workflow-exection">
<CodeTab label="API Route" value="api-route">
```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)
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscriber">
```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",
}
```
</CodeTab>
<CodeTab label="Scheduled Job" value="scheduled-job">
```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 * * *",
}
```
</CodeTab>
<CodeTab label="Another Workflow" value="another-workflow">
```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`
}
)
```
</CodeTab>
</CodeTabs>
to
<CodeTabs group="workflow-exection">
<CodeTab label="API Route" value="api-route">
```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)
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscriber">
```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",
}
```
</CodeTab>
<CodeTab label="Scheduled Job" value="scheduled-job">
```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 * * *",
}
```
</CodeTab>
<CodeTab label="Another Workflow" value="another-workflow">
```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`
}
)
```
</CodeTab>
</CodeTabs>
and don't pass a
<CodeTabs group="workflow-exection">
<CodeTab label="API Route" value="api-route">
```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)
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscriber">
```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",
}
```
</CodeTab>
<CodeTab label="Scheduled Job" value="scheduled-job">
```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 * * *",
}
```
</CodeTab>
<CodeTab label="Another Workflow" value="another-workflow">
```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`
}
)
```
</CodeTab>
</CodeTabs>
array:
To calculate shipping option with calculated prices, set `price_type` to `calculated` and don't pass a `prices` array:
:::note

View File

@@ -146,92 +146,9 @@ const myWorkflow = createWorkflow(
</CodeTab>
</CodeTabs>
Notice that the workflow returns a
<CodeTabs group="workflow-exection">
<CodeTab label="API Route" value="api-route">
```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)
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscriber">
```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",
}
```
</CodeTab>
<CodeTab label="Scheduled Job" value="scheduled-job">
```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 * * *",
}
```
</CodeTab>
<CodeTab label="Another Workflow" value="another-workflow">
```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`
}
)
```
</CodeTab>
</CodeTabs>
. 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}

View File

@@ -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
}