docs: update imports and package names across docs (#9375)

* docs: update imports and package names across docs
+ reference configs

* generate files

* fix import

* change preview to rc
This commit is contained in:
Shahed Nasser
2024-10-01 11:03:42 +02:00
committed by GitHub
parent c726ed54f5
commit 2e16949979
196 changed files with 1379 additions and 1491 deletions
@@ -94,7 +94,7 @@ import { Container, Heading } from "@medusajs/ui"
import {
DetailWidgetProps,
AdminProduct,
} from "@medusajs/types"
} from "@medusajs/framework/types"
// The widget
const ProductWidget = ({
@@ -135,9 +135,9 @@ For example, consider you want to store the data passed in `additional_data` in
To do that, create the file `src/workflows/hooks/product-created.ts` with the following content:
```ts title="src/workflows/hooks/product-created.ts"
import { StepResponse } from "@medusajs/workflows-sdk"
import { createProductsWorkflow } from "@medusajs/core-flows"
import { Modules } from "@medusajs/utils"
import { StepResponse } from "@medusajs/framework/workflows-sdk"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
createProductsWorkflow.hooks.productsCreated(
async ({ products, additional_data }, { container }) => {
@@ -87,8 +87,8 @@ import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
import { ConfigModule } from "@medusajs/types"
import { parseCorsOrigins } from "@medusajs/utils"
import { ConfigModule } from "@medusajs/framework/types"
import { parseCorsOrigins } from "@medusajs/framework/utils"
import cors from "cors"
export default defineMiddlewares({
@@ -10,7 +10,7 @@ In this guide, you'll learn how to throw errors in your Medusa application, how
## Throw MedusaError
When throwing an error in your API routes, middlewares, workflows, or any customization, throw a `MedusaError`, which is imported from `@medusajs/utils`.
When throwing an error in your API routes, middlewares, workflows, or any customization, throw a `MedusaError`, which is imported from `@medusajs/framework/utils`.
The Medusa application's API route error handler then wraps your thrown error in a uniform object and returns it in the response.
@@ -18,7 +18,7 @@ For example:
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { MedusaError } from "@medusajs/utils"
import { MedusaError } from "@medusajs/framework/utils"
export const GET = async (
req: MedusaRequest,
@@ -258,7 +258,7 @@ import {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
import { MedusaError } from "@medusajs/utils"
import { MedusaError } from "@medusajs/framework/utils"
export default defineMiddlewares({
errorHandler: (
@@ -125,8 +125,8 @@ import type {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
import { Modules } from "@medusajs/utils"
import { ICustomerModuleService } from "@medusajs/types"
import { Modules } from "@medusajs/framework/utils"
import { ICustomerModuleService } from "@medusajs/framework/types"
export const GET = async (
req: AuthenticatedMedusaRequest,
@@ -160,8 +160,8 @@ import type {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
import { Modules } from "@medusajs/utils"
import { IUserModuleService } from "@medusajs/types"
import { Modules } from "@medusajs/framework/utils"
import { IUserModuleService } from "@medusajs/framework/types"
export const GET = async (
req: AuthenticatedMedusaRequest,
@@ -22,8 +22,8 @@ For example, create the file `src/scripts/my-script.ts` with the following conte
import {
ExecArgs,
IProductModuleService,
} from "@medusajs/types"
import { Modules } from "@medusajs/utils"
} from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
export default async function myScript({ container }: ExecArgs) {
const productModuleService: IProductModuleService = container.resolve(
@@ -58,7 +58,7 @@ Your script can accept arguments from the command line. Arguments are passed to
For example:
```ts
import { ExecArgs } from "@medusajs/types"
import { ExecArgs } from "@medusajs/framework/types"
export default async function myScript({ args }: ExecArgs) {
console.log(`The arguments you passed: ${args}`)
@@ -18,7 +18,7 @@ export const defaultHighlights = [
]
```ts highlights={defaultHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
color: model
@@ -48,7 +48,7 @@ export const nullableHighlights = [
]
```ts highlights={nullableHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
price: model.bigNumber().nullable(),
@@ -71,7 +71,7 @@ export const uniqueHighlights = [
]
```ts highlights={uniqueHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const User = model.define("user", {
email: model.text().unique(),
@@ -18,7 +18,7 @@ export const highlights = [
]
```ts highlights={highlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id().primaryKey(),
@@ -48,7 +48,7 @@ export const dataModelIndexHighlights = [
]
```ts highlights={dataModelIndexHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id().primaryKey(),
@@ -77,7 +77,7 @@ export const conditionHighlights = [
]
```ts highlights={conditionHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id().primaryKey(),
@@ -106,7 +106,7 @@ export const negationHighlights = [
]
```ts highlights={negationHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id().primaryKey(),
@@ -141,7 +141,7 @@ export const uniqueHighlights = [
]
```ts highlights={uniqueHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id().primaryKey(),
@@ -10,12 +10,12 @@ In this chapter, you'll learn how to infer the type of a data model.
Consider you have a `MyCustom` data model. You can't reference this data model in a type, such as a workflow input or service method output types, since it's a variable.
Instead, Medusa provides an `InferTypeOf` utility imported from `@medusajs/types` that transforms your data model to a type.
Instead, Medusa provides an `InferTypeOf` utility imported from `@medusajs/framework/types` that transforms your data model to a type.
For example:
```ts
import { InferTypeOf } from "@medusajs/types"
import { InferTypeOf } from "@medusajs/framework/types"
import { MyCustom } from "../models/my-custom" // relative path to the model
export type MyCustom = InferTypeOf<typeof MyCustom>
@@ -29,7 +29,7 @@ You can now use the `MyCustom` type to reference a data model in other types, su
```ts title="Example Service"
// other imports...
import { InferTypeOf } from "@medusajs/types"
import { InferTypeOf } from "@medusajs/framework/types"
import { MyCustom } from "../models/my-custom"
type MyCustom = InferTypeOf<typeof MyCustom>
@@ -17,7 +17,7 @@ export const highlights = [
]
```ts highlights={highlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id().primaryKey(),
@@ -6,7 +6,7 @@ export const metadata = {
In this chapter, youll learn about the types of properties in a data models schema.
These types are available as methods on the `model` utility imported from `@medusajs/utils`.
These types are available as methods on the `model` utility imported from `@medusajs/framework/utils`.
## id
@@ -17,7 +17,7 @@ For example:
export const idHighlights = [["4", ".id()", "Define an `id` property."]]
```ts highlights={idHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
id: model.id(),
@@ -38,7 +38,7 @@ For example:
export const textHighlights = [["4", "text", "Define a `text` property."]]
```ts highlights={textHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
name: model.text(),
@@ -59,7 +59,7 @@ For example:
export const numberHighlights = [["4", "number", "Define a `number` property."]]
```ts highlights={numberHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
age: model.number(),
@@ -80,7 +80,7 @@ For example:
export const bigNumberHighlights = [["4", "bigNumber", "Define a `bigNumber` property."]]
```ts highlights={bigNumberHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
price: model.bigNumber(),
@@ -101,7 +101,7 @@ For example:
export const booleanHighlights = [["4", "boolean", "Define a `boolean` property."]]
```ts highlights={booleanHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
hasAccount: model.boolean(),
@@ -122,7 +122,7 @@ For example:
export const enumHighlights = [["4", "enum", "Define a `enum` property."]]
```ts highlights={enumHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
color: model.enum(["black", "white"]),
@@ -145,7 +145,7 @@ For example:
export const dateTimeHighlights = [["4", "dateTime", "Define a `dateTime` property."]]
```ts highlights={dateTimeHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
date_of_birth: model.dateTime(),
@@ -166,7 +166,7 @@ For example:
export const jsonHighlights = [["4", "json", "Define a `json` property."]]
```ts highlights={jsonHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
metadata: model.json(),
@@ -187,7 +187,7 @@ For example:
export const arrHightlights = [["4", "array", "Define an `array` property."]]
```ts highlights={arrHightlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
names: model.array(),
@@ -46,7 +46,7 @@ export const oneToOneHighlights = [
]
```ts highlights={oneToOneHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const User = model.define("user", {
id: model.id().primaryKey(),
@@ -100,7 +100,7 @@ export const oneToManyHighlights = [
]
```ts highlights={oneToManyHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const Store = model.define("store", {
id: model.id().primaryKey(),
@@ -146,7 +146,7 @@ export const manyToManyHighlights = [
]
```ts highlights={manyToManyHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const Order = model.define("order", {
id: model.id().primaryKey(),
@@ -193,7 +193,7 @@ export const relationNameHighlights = [
]
```ts highlights={relationNameHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const User = model.define("user", {
id: model.id().primaryKey(),
@@ -229,7 +229,7 @@ export const highlights = [
]
```ts highlights={highlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const Store = model.define("store", {
id: model.id().primaryKey(),
@@ -25,7 +25,7 @@ export const searchableHighlights = [
]
```ts highlights={searchableHighlights}
import { model } from "@medusajs/utils"
import { model } from "@medusajs/framework/utils"
const MyCustom = model.define("my_custom", {
name: model.text().searchable(),
@@ -8,7 +8,7 @@ In this chapter, you'll learn how to emit an event in a workflow.
## Emit Event Step
Medusa provides an `emitEventStep` helper step in the `@medusajs/core-flows` package that emits an event.
Medusa provides an `emitEventStep` helper step in the `@medusajs/medusa/core-flows` package that emits an event.
When you emit an event, you specify the event's name and data payload to pass with the event.
@@ -23,10 +23,10 @@ export const highlights = [
```ts highlights={highlights}
import {
createWorkflow,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
import {
emitEventStep,
} from "@medusajs/core-flows"
} from "@medusajs/medusa/core-flows"
const helloWorldWorkflow = createWorkflow(
"hello-world",
@@ -53,7 +53,7 @@ For example:
```ts highlights={[["9"]]}
import {
LoaderOptions,
} from "@medusajs/modules-sdk"
} from "@medusajs/framework/modules-sdk"
import { Logger } from "@medusajs/medusa"
export default async function helloWorldLoader({
@@ -32,7 +32,7 @@ You want to create a relationship between data models in the same module. Use da
### 1. Create Link File
Links are defined in a TypeScript or JavaScript file under the `src/links` directory. The file defines the link using the `defineLink` function imported from `@medusajs/utils` and exports it.
Links are defined in a TypeScript or JavaScript file under the `src/links` directory. The file defines the link using the `defineLink` function imported from `@medusajs/framework/utils` and exports it.
For example:
@@ -43,8 +43,8 @@ export const highlights = [
```ts title="src/links/hello-product.ts" highlights={highlights}
import HelloModule from "../modules/hello"
import ProductModule from "@medusajs/product"
import { defineLink } from "@medusajs/utils"
import ProductModule from "@medusajs/medusa/product"
import { defineLink } from "@medusajs/framework/utils"
export default defineLink(
ProductModule.linkable.product,
@@ -84,8 +84,8 @@ For example:
```ts
import HelloModule from "../modules/hello"
import ProductModule from "@medusajs/product"
import { defineLink } from "@medusajs/utils"
import ProductModule from "@medusajs/medusa/product"
import { defineLink } from "@medusajs/framework/utils"
export default defineLink(
ProductModule.linkable.product,
@@ -130,8 +130,8 @@ For example:
```ts
import HelloModule from "../modules/hello"
import ProductModule from "@medusajs/product"
import { defineLink } from "@medusajs/utils"
import ProductModule from "@medusajs/medusa/product"
import { defineLink } from "@medusajs/framework/utils"
export default defineLink(
ProductModule.linkable.product,
@@ -47,7 +47,7 @@ The modules main service receives the module options as a second parameter.
For example:
```ts title="src/modules/hello/service.ts" highlights={[["12"], ["14", "options?: ModuleOptions"], ["17"], ["18"], ["19"]]}
import { MedusaService } from "@medusajs/utils"
import { MedusaService } from "@medusajs/framework/utils"
import MyCustom from "./models/my-custom"
// recommended to define type in another file
@@ -83,7 +83,7 @@ For example:
```ts title="src/modules/hello/loaders/hello-world.ts" highlights={[["11"], ["12", "ModuleOptions", "The type of expected module options."], ["16"]]}
import {
LoaderOptions,
} from "@medusajs/modules-sdk"
} from "@medusajs/framework/modules-sdk"
// recommended to define type in another file
type ModuleOptions = {
@@ -40,7 +40,7 @@ import {
} from "@medusajs/medusa"
import {
ContainerRegistrationKeys,
} from "@medusajs/utils"
} from "@medusajs/framework/utils"
export const GET = async (
req: MedusaRequest,
@@ -21,10 +21,10 @@ import {
} from "@medusajs/medusa"
import {
ContainerRegistrationKeys,
} from "@medusajs/utils"
} from "@medusajs/framework/utils"
import {
RemoteLink,
} from "@medusajs/modules-sdk"
} from "@medusajs/framework/modules-sdk"
export async function POST(
req: MedusaRequest,
@@ -49,7 +49,7 @@ To create a link between records of two data models, use the `create` method of
For example:
```ts
import { Modules } from "@medusajs/utils"
import { Modules } from "@medusajs/framework/utils"
// ...
@@ -84,7 +84,7 @@ To remove a link between records of two data models, use the `dismiss` method of
For example:
```ts
import { Modules } from "@medusajs/utils"
import { Modules } from "@medusajs/framework/utils"
// ...
@@ -115,7 +115,7 @@ If a record is deleted, use the `delete` method of the remote link to delete all
For example:
```ts
import { Modules } from "@medusajs/utils"
import { Modules } from "@medusajs/framework/utils"
// ...
@@ -139,7 +139,7 @@ If a record that was previously soft-deleted is now restored, use the `restore`
For example:
```ts
import { Modules } from "@medusajs/utils"
import { Modules } from "@medusajs/framework/utils"
// ...
@@ -13,7 +13,7 @@ Medusa wraps adds wrappers around your service's methods and executes them as as
So, make sure your service's methods are always async to avoid unexpected errors or behavior.
```ts highlights={[["8", "", "Method must be async."], ["13", "async", "Correct way of defining the method."]]}
import { MedusaService } from "@medusajs/utils"
import { MedusaService } from "@medusajs/framework/utils"
import MyCustom from "./models/my-custom"
class HelloModuleService extends MedusaService({
@@ -34,7 +34,7 @@ export const highlights = [
]
```ts title="src/modules/hello/service.ts" highlights={highlights}
import { MedusaService } from "@medusajs/utils"
import { MedusaService } from "@medusajs/framework/utils"
import MyCustom from "./models/my-custom"
class HelloModuleService extends MedusaService({
@@ -284,7 +284,7 @@ If you implement the `constructor` of your service, make sure to call `super` pa
For example:
```ts highlights={[["8"]]}
import { MedusaService } from "@medusajs/utils"
import { MedusaService } from "@medusajs/framework/utils"
import MyCustom from "./models/my-custom"
class HelloModuleService extends MedusaService({
@@ -24,7 +24,7 @@ Your workflow isn't reusable by other applications. Use a step that performs wha
## How to Expose a Hook in a Workflow?
To expose a hook in your workflow, use the `createHook` function imported from `@medusajs/workflows-sdk`.
To expose a hook in your workflow, use the `createHook` function imported from `@medusajs/framework/workflows-sdk`.
For example:
@@ -41,7 +41,7 @@ import {
createHook,
createWorkflow,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
import { createProductStep } from "./steps/create-product"
export const myWorkflow = createWorkflow(
@@ -26,7 +26,7 @@ For example, create the file `src/workflows/hello-world.ts` with the following c
import {
createStep,
StepResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
"step-1",
@@ -66,7 +66,7 @@ Then, create a workflow that uses the steps:
import {
createWorkflow,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
// other imports...
// steps...
@@ -135,7 +135,7 @@ export const inputHighlights = [
import {
createStep,
StepResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
"step-1",
@@ -172,8 +172,8 @@ export const containerHighlights = [
import {
createStep,
StepResponse,
} from "@medusajs/workflows-sdk"
import { ContainerRegistrationKeys } from "@medusajs/utils"
} from "@medusajs/framework/workflows-sdk"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
const step1 = createStep(
"step-1",
@@ -37,7 +37,7 @@ import {
createWorkflow,
WorkflowResponse,
when,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
// step imports...
const workflow = createWorkflow(
@@ -70,7 +70,7 @@ In this code snippet, you execute the `isActiveStep` only if the `input.is_activ
### When Parameters
`when` utility is a function imported from `@medusajs/workflows-sdk`. It accepts the following parameters:
`when` utility is a function imported from `@medusajs/framework/workflows-sdk`. It accepts the following parameters:
1. The first parameter is either an object or the workflow's input. This data is passed as a parameter to the function in `when`'s second parameter.
2. The second parameter is a function that returns a boolean indicating whether to execute the action in `then`.
@@ -38,7 +38,7 @@ Learn more about why you can't manipulate variables [in this chapter](../conditi
</Note>
Instead, use the `transform` utility function imported from `@medusajs/workflows-sdk`:
Instead, use the `transform` utility function imported from `@medusajs/framework/workflows-sdk`:
export const highlights = [
["9", "", "Don't manipulate variables directly."],
@@ -89,7 +89,7 @@ Learn more about why you can't use if-conditions [in this chapter](../conditions
</Note>
Instead, use the when-then utility function imported from `@medusajs/workflows-sdk`:
Instead, use the when-then utility function imported from `@medusajs/framework/workflows-sdk`:
```ts
// Don't
@@ -129,7 +129,7 @@ Values of other types, such as Maps, aren't allowed.
import {
createStep,
StepResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
"step-1",
@@ -148,7 +148,7 @@ const step1 = createStep(
import {
createStep,
StepResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
"step-1",
@@ -20,10 +20,10 @@ export const workflowsHighlights = [
```ts highlights={workflowsHighlights} collapsibleLines="1-7" expandMoreButton="Show Imports"
import {
createWorkflow,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
import {
createProductsWorkflow,
} from "@medusajs/core-flows"
} from "@medusajs/medusa/core-flows"
const workflow = createWorkflow(
"hello-world",
@@ -49,7 +49,7 @@ The object has an `input` property to pass input to the workflow.
## Preparing Input Data
If you need to perform some data manipulation to prepare the other workflow's input data, use the `transform` utility function imported from `@medusajs/workflows-sdk`.
If you need to perform some data manipulation to prepare the other workflow's input data, use the `transform` utility function imported from `@medusajs/framework/workflows-sdk`.
<Note>
@@ -68,10 +68,10 @@ export const transformHighlights = [
import {
createWorkflow,
transform,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
import {
createProductsWorkflow,
} from "@medusajs/core-flows"
} from "@medusajs/medusa/core-flows"
type WorkflowInput = {
title: string
@@ -105,7 +105,7 @@ In this example, you use the `transform` function to prepend `Hello` to the titl
## Run Workflow Conditionally
To run a workflow in another based on a condition, use the when-then utility functions imported from `@medusajs/workflows-sdk`.
To run a workflow in another based on a condition, use the when-then utility functions imported from `@medusajs/framework/workflows-sdk`.
<Note>
@@ -124,13 +124,13 @@ export const whenHighlights = [
import {
createWorkflow,
when,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
import {
createProductsWorkflow,
} from "@medusajs/core-flows"
} from "@medusajs/medusa/core-flows"
import {
CreateProductWorkflowInputDTO,
} from "@medusajs/types"
} from "@medusajs/framework/types"
type WorkflowInput = {
product?: CreateProductWorkflowInputDTO
@@ -35,7 +35,7 @@ import {
createWorkflow,
WorkflowResponse,
StepResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep("step-1", async () => {
return new StepResponse({})
@@ -114,11 +114,11 @@ export const successStatusHighlights = [
import {
Modules,
TransactionHandlerType,
} from "@medusajs/utils"
} from "@medusajs/framework/utils"
import {
StepResponse,
createStep,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
type SetStepSuccessStepInput = {
transactionId: string
@@ -232,11 +232,11 @@ export const failureStatusHighlights = [
import {
Modules,
TransactionHandlerType,
} from "@medusajs/utils"
} from "@medusajs/framework/utils"
import {
StepResponse,
createStep,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
type SetStepFailureStepInput = {
transactionId: string
@@ -288,8 +288,8 @@ import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import myWorkflow from "../../../workflows/hello-world"
import {
IWorkflowEngineService,
} from "@medusajs/types"
import { Modules } from "@medusajs/utils"
} from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
export async function GET(req: MedusaRequest, res: MedusaResponse) {
const { transaction, result } = await myWorkflow(req.scope).run()
@@ -8,7 +8,7 @@ In this chapter, youll learn how to run workflow steps in parallel.
## parallelize Utility Function
If your workflow has steps that dont rely on one anothers results, run them in parallel using the `parallelize` utility function imported from the `@medusajs/workflows-sdk`.
If your workflow has steps that dont rely on one anothers results, run them in parallel using the `parallelize` utility function imported from the `@medusajs/framework/workflows-sdk`.
The workflow waits until all steps passed to the `parallelize` function finish executing before continuing to the next step.
@@ -24,7 +24,7 @@ import {
createWorkflow,
WorkflowResponse,
parallelize,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
import {
createProductStep,
getProductStep,
@@ -19,7 +19,7 @@ import {
createStep,
createWorkflow,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
{
@@ -43,7 +43,7 @@ import {
createWorkflow,
WorkflowResponse,
transform,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
// step imports...
const myWorkflow = createWorkflow(
@@ -62,7 +62,7 @@ const myWorkflow = createWorkflow(
)
```
The `transform` utility function is imported from `@medusajs/workflows-sdk`. It accepts two parameters:
The `transform` utility function is imported from `@medusajs/framework/workflows-sdk`. It accepts two parameters:
1. The first parameter is an object of variables to manipulate. The object is passed as a parameter to `transform`'s second parameter function.
2. The second parameter is the function performing the variable manipulation.
@@ -84,7 +84,7 @@ import {
createWorkflow,
WorkflowResponse,
transform,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
// step imports...
type WorkflowInput = {
@@ -43,7 +43,7 @@ export const handlerHighlights = [
]
```ts title="src/workflows/hooks/product-created.ts" highlights={handlerHighlights}
import { createProductsWorkflow } from "@medusajs/core-flows"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
createProductsWorkflow.hooks.productsCreated(
async ({ products }, { container }) => {
@@ -83,7 +83,7 @@ Since the hook handler is a step function, you can set its compensation function
For example:
```ts title="src/workflows/hooks/product-created.ts"
import { createProductsWorkflow } from "@medusajs/core-flows"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
createProductsWorkflow.productCreated(
async ({ productId }, { container }) => {
@@ -108,7 +108,7 @@ It also accepts as a second parameter an object holding a `container` property t
Medusa's workflows pass in the hook's input an `additional_data` property:
```ts title="src/workflows/hooks/product-created.ts" highlights={[["4", "additional_data"]]}
import { createProductsWorkflow } from "@medusajs/core-flows"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
createProductsWorkflow.hooks.productsCreated(
async ({ products, additional_data }, { container }) => {
@@ -131,7 +131,7 @@ You can also pass that additional data when executing the workflow. Pass it as a
```ts title="src/workflows/hooks/product-created.ts" highlights={[["10", "additional_data"]]}
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { createProductsWorkflow } from "@medusajs/core-flows"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
export async function POST(req: MedusaRequest, res: MedusaResponse) {
await createProductsWorkflow(req.scope).run({
@@ -31,7 +31,7 @@ import {
createStep,
createWorkflow,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
} from "@medusajs/framework/workflows-sdk"
const step1 = createStep(
"step-1",