docs: added workflow hooks docs + changed workflow response (#8364)

* docs: added workflow hooks docs + changed workflow response

* Update page.mdx
This commit is contained in:
Shahed Nasser
2024-07-31 17:01:33 +03:00
committed by GitHub
parent 27837b8833
commit 6f973d9f2b
29 changed files with 321 additions and 167 deletions
@@ -33,7 +33,7 @@ export const highlights = [
```ts title="src/api/middlewares.ts" highlights={highlights}
import {
defineMiddlewares,
authenticate
authenticate,
} from "@medusajs/medusa"
export default defineMiddlewares({
@@ -37,10 +37,10 @@ Start by creating a workflow that does two things:
For example, create the file `src/workflows/create-manager.ts`. with the following content:
export const workflowHighlights = [
["20", "createManagerStep", "Thi step creates a manager."],
["37", "createManagerWorkflow", "The workflow used to create a manager and set its auth identity's actor type."],
["44", "setAuthAppMetadataStep", "Set the actor type of the manager's associated auth identity."],
["46", '"manager"', "The actor type of the manager."]
["21", "createManagerStep", "Thi step creates a manager."],
["38", "createManagerWorkflow", "The workflow used to create a manager and set its auth identity's actor type."],
["45", "setAuthAppMetadataStep", "Set the actor type of the manager's associated auth identity."],
["47", '"manager"', "The actor type of the manager."]
]
```ts title="src/workflows/create-manager.ts" highlights={workflowHighlights}
@@ -48,6 +48,7 @@ import {
createWorkflow,
createStep,
StepResponse,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
import {
setAuthAppMetadataStep,
@@ -93,7 +94,7 @@ const createManagerWorkflow = createWorkflow(
value: manager.id,
})
return manager
return new WorkflowResponse(manager)
}
)
@@ -184,7 +185,7 @@ export const middlewareHighlights = [
```ts title="src/api/middlewares.ts" highlights={middlewareHighlights}
import {
defineMiddlewares,
authenticate
authenticate,
} from "@medusajs/medusa"
export default defineMiddlewares({
@@ -30,15 +30,15 @@ const query = remoteQueryObjectFromString({
fields: [
"*",
"variants.*",
"variants.prices.*"
"variants.prices.*",
],
variables: {
filters: {
id: [
"prod_123"
]
"prod_123",
],
},
}
},
})
// `result` is array of products
@@ -72,19 +72,19 @@ const query = remoteQueryObjectFromString({
fields: [
"*",
"variants.*",
"variants.calculated_price.*"
"variants.calculated_price.*",
],
variables: {
filters: {
id
id,
},
"variants.calculated_price": {
context: {
region_id: "reg_01J3MRPDNXXXDSCC76Y6YCZARS",
currency_code: "eur"
}
}
}
currency_code: "eur",
},
},
},
})
// `result` is array of products