docs-util: fix examples in workflow reference that have multiple code (#12223)
This commit is contained in:
+1
-250
@@ -182,256 +182,7 @@ const myWorkflow = createWorkflow(
|
|||||||
</CodeTab>
|
</CodeTab>
|
||||||
</CodeTabs>
|
</CodeTabs>
|
||||||
|
|
||||||
To calculate shipping option with calculated prices, set
|
To calculate shipping option with calculated prices, set `price_type` to `calculated` and don't pass a `prices` array:
|
||||||
<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:
|
|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
|
|
||||||
|
|||||||
+2
-85
@@ -146,92 +146,9 @@ const myWorkflow = createWorkflow(
|
|||||||
</CodeTab>
|
</CodeTab>
|
||||||
</CodeTabs>
|
</CodeTabs>
|
||||||
|
|
||||||
Notice that the workflow returns a
|
Notice that the workflow returns a `transaction.transactionId`. You'll use this ID to confirm the import afterwards.
|
||||||
<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"
|
|
||||||
|
|
||||||
export async function POST(
|
You confirm the import using the [Workflow Engine](https://docs.medusajs.com/resources/architectural-modules/workflow-engine).
|
||||||
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).
|
|
||||||
For example, in an API route:
|
For example, in an API route:
|
||||||
|
|
||||||
```ts workflow={false}
|
```ts workflow={false}
|
||||||
|
|||||||
+11
-5
@@ -24,11 +24,17 @@ export default function () {
|
|||||||
} else {
|
} else {
|
||||||
exampleTags.forEach((exampleTag) => {
|
exampleTags.forEach((exampleTag) => {
|
||||||
exampleTag.content.forEach((part) => {
|
exampleTag.content.forEach((part) => {
|
||||||
if (
|
const isCode = part.kind === "code"
|
||||||
part.kind !== "code" ||
|
const isCodeBlock = part.text.startsWith("```")
|
||||||
part.text.startsWith("```ts workflow={false}")
|
const isWorkflowDisabled = part.text.startsWith(
|
||||||
) {
|
"```ts workflow={false}"
|
||||||
exampleStr.push(part.text)
|
)
|
||||||
|
if (!isCode || !isCodeBlock || isWorkflowDisabled) {
|
||||||
|
if (!isCodeBlock && exampleStr.length > 0) {
|
||||||
|
exampleStr[exampleStr.length - 1] += part.text
|
||||||
|
} else {
|
||||||
|
exampleStr.push(part.text)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user