From ea2cc974cc3d8c19fcdd9b812776107243229556 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 26 Sep 2024 16:00:37 +0300 Subject: [PATCH] docs: fixes to customization docs (#9236) Closes #9225, #9224, #9226, #9227 Closes DOCS-948, DOCS-947, DOCS-945, DOCS-946 --- .../api-routes/additional-data/page.mdx | 14 ++++---- .../data-models/manage-relationships/page.mdx | 4 +-- .../data-models/relationships/page.mdx | 4 +-- .../workflows/compensation-function/page.mdx | 4 +-- .../workflows/long-running-workflow/page.mdx | 24 +++++++------- .../extend-create-product/page.mdx | 32 ++++++++++++------- .../query-linked-records/page.mdx | 2 +- .../integrate-systems/handle-event/page.mdx | 2 +- .../integrate-systems/service/page.mdx | 4 +-- .../instrumentation/page.mdx | 8 ++--- 10 files changed, 53 insertions(+), 45 deletions(-) diff --git a/www/apps/book/app/advanced-development/api-routes/additional-data/page.mdx b/www/apps/book/app/advanced-development/api-routes/additional-data/page.mdx index 612597a01b..e90528ae2e 100644 --- a/www/apps/book/app/advanced-development/api-routes/additional-data/page.mdx +++ b/www/apps/book/app/advanced-development/api-routes/additional-data/page.mdx @@ -73,10 +73,10 @@ export default defineMiddlewares({ method: "POST", matcher: "/admin/products", additionalDataValidator: { - brand: z.string().optional() - } - } - ] + brand: z.string().optional(), + }, + }, + ], }) ``` @@ -154,14 +154,14 @@ createProductsWorkflow.hooks.productsCreated( ...product, metadata: { ...product.metadata, - brand: additional_data.brand - } + brand: additional_data.brand, + }, })) ) return new StepResponse(products, { products, - additional_data + additional_data, }) } ) diff --git a/www/apps/book/app/advanced-development/data-models/manage-relationships/page.mdx b/www/apps/book/app/advanced-development/data-models/manage-relationships/page.mdx index 1c07580b3c..f8693d327d 100644 --- a/www/apps/book/app/advanced-development/data-models/manage-relationships/page.mdx +++ b/www/apps/book/app/advanced-development/data-models/manage-relationships/page.mdx @@ -160,7 +160,7 @@ export const updateAssociationHighlights = [ const product = await helloModuleService.retrieveProduct( "123", { - relations: ["orders"] + relations: ["orders"], } ) @@ -169,7 +169,7 @@ const updatedProduct = await helloModuleService.updateProducts({ // other properties... orders: [ ...product.orders.map((order) => order.id), - "321" + "321", ], }) ``` diff --git a/www/apps/book/app/advanced-development/data-models/relationships/page.mdx b/www/apps/book/app/advanced-development/data-models/relationships/page.mdx index 448f3c1b8a..9946a51ac3 100644 --- a/www/apps/book/app/advanced-development/data-models/relationships/page.mdx +++ b/www/apps/book/app/advanced-development/data-models/relationships/page.mdx @@ -151,14 +151,14 @@ import { model } from "@medusajs/utils" const Order = model.define("order", { id: model.id().primaryKey(), products: model.manyToMany(() => Product, { - mappedBy: "orders" + mappedBy: "orders", }), }) const Product = model.define("product", { id: model.id().primaryKey(), orders: model.manyToMany(() => Order, { - mappedBy: "products" + mappedBy: "products", }), }) ``` diff --git a/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx b/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx index 27d900e2a7..fb0c3b2a33 100644 --- a/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx @@ -142,7 +142,7 @@ const step1 = createStep( async () => { return new StepResponse( `Hello from step one!`, - { message: "Oops! Rolling back my changes..."} + { message: "Oops! Rolling back my changes..." } ) }, async ({ message }) => { @@ -180,7 +180,7 @@ const step1 = createStep( async () => { return new StepResponse( `Hello from step one!`, - { message: "Oops! Rolling back my changes..."} + { message: "Oops! Rolling back my changes..." } ) }, async ({ message }, { container }) => { diff --git a/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx b/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx index 2e81b6c9ce..0f2610c911 100644 --- a/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx @@ -114,11 +114,11 @@ export const successStatusHighlights = [ import { Modules, TransactionHandlerType, -} from "@medusajs/utils"; +} from "@medusajs/utils" import { StepResponse, - createStep -} from "@medusajs/workflows-sdk"; + createStep, +} from "@medusajs/workflows-sdk" type SetStepSuccessStepInput = { transactionId: string @@ -132,7 +132,7 @@ export const setStepSuccessStep = createStep( ) { const workflowEngineService = container.resolve( Modules.WORKFLOW_ENGINE - ); + ) await workflowEngineService.setStepSuccess({ idempotencyKey: { @@ -145,9 +145,9 @@ export const setStepSuccessStep = createStep( options: { container, }, - }); + }) } -); +) ``` In this step (which you use in a workflow other than the long-running workflow), you resolve the Workflow Engine Module's main service and set `step-2` of the previous workflow as successful. @@ -232,11 +232,11 @@ export const failureStatusHighlights = [ import { Modules, TransactionHandlerType, -} from "@medusajs/utils"; +} from "@medusajs/utils" import { StepResponse, - createStep -} from "@medusajs/workflows-sdk"; + createStep, +} from "@medusajs/workflows-sdk" type SetStepFailureStepInput = { transactionId: string @@ -250,7 +250,7 @@ export const setStepFailureStep = createStep( ) { const workflowEngineService = container.resolve( Modules.WORKFLOW_ENGINE - ); + ) await workflowEngineService.setStepFailure({ idempotencyKey: { @@ -263,9 +263,9 @@ export const setStepFailureStep = createStep( options: { container, }, - }); + }) } -); +) ``` You use this step in another workflow that changes the status of an async step in a long-running workflow's execution to failed. diff --git a/www/apps/book/app/customization/extend-models/extend-create-product/page.mdx b/www/apps/book/app/customization/extend-models/extend-create-product/page.mdx index 7f7b30ae42..41b7df42f4 100644 --- a/www/apps/book/app/customization/extend-models/extend-create-product/page.mdx +++ b/www/apps/book/app/customization/extend-models/extend-create-product/page.mdx @@ -77,17 +77,18 @@ The [createProductsWorkflow](!resources!/references/medusa-workflows/createProdu So, to consume the `productsCreated` hook, create the file `src/workflows/hooks/created-product.ts` with the following content: export const hookHighlights = [ - ["6", "productsCreated", "Access the hook in the `hooks` property."], - ["8", "", "Only proceed if the brand ID is passed in the additional data."], - ["17", "retrieveBrand", "Try to retrieve the brand to ensure it exists."], - ["21", "links", "Define an array to store the links in."], - ["25", "push", "Add a link to be created."], - ["35", "create", "Create the links."] + ["7", "productsCreated", "Access the hook in the `hooks` property."], + ["9", "", "Only proceed if the brand ID is passed in the additional data."], + ["18", "retrieveBrand", "Try to retrieve the brand to ensure it exists."], + ["27", "links", "Define an array to store the links in."], + ["31", "push", "Add a link to be created."], + ["41", "create", "Create the links."] ] ```ts title="src/workflows/hooks/created-product.ts" highlights={hookHighlights} import { createProductsWorkflow } from "@medusajs/core-flows" -import { Modules } from "@medusajs/utils" +import { StepResponse } from "@medusajs/workflows-sdk" +import { Modules, ContainerRegistrationKeys } from "@medusajs/utils" import { BRAND_MODULE } from "../../modules/brand" import BrandModuleService from "../../modules/brand/service" @@ -104,7 +105,12 @@ createProductsWorkflow.hooks.productsCreated( // if the brand doesn't exist, an error is thrown. await brandModuleService.retrieveBrand(additional_data.brand_id as string) - const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK) + const remoteLink = container.resolve( + ContainerRegistrationKeys.REMOTE_LINK + ) + const logger = container.resolve( + ContainerRegistrationKeys.LOGGER + ) const links = [] @@ -122,8 +128,10 @@ createProductsWorkflow.hooks.productsCreated( await remoteLink.create(links) + logger.info("Linked brand to products") + return new StepResponse(links, links) - }) + }) ) ``` @@ -139,8 +147,8 @@ Add the following compensation function as a second parameter: ```ts title="src/workflows/hooks/created-product.ts" createProductsWorkflow.hooks.productsCreated( - // ... - (async ({ links }, { container }) => { + // ... + (async (links, { container }) => { if (!links.length) { return } @@ -149,7 +157,7 @@ createProductsWorkflow.hooks.productsCreated( ContainerRegistrationKeys.REMOTE_LINK ) - await remoteLink.dimiss(links) + await remoteLink.dismiss(links) }) ) ``` diff --git a/www/apps/book/app/customization/extend-models/query-linked-records/page.mdx b/www/apps/book/app/customization/extend-models/query-linked-records/page.mdx index 5b44dae631..b8bc1c8efb 100644 --- a/www/apps/book/app/customization/extend-models/query-linked-records/page.mdx +++ b/www/apps/book/app/customization/extend-models/query-linked-records/page.mdx @@ -112,7 +112,7 @@ Make sure to replace the email and password with your user's credentials. Then, send a `GET` request to `/admin/products/:id/brand`: ```bash -curl 'http://localhost:9000/admin/product/prod_123/brand' \ +curl 'http://localhost:9000/admin/products/prod_123/brand' \ -H 'Authorization: Bearer {token}' ``` diff --git a/www/apps/book/app/customization/integrate-systems/handle-event/page.mdx b/www/apps/book/app/customization/integrate-systems/handle-event/page.mdx index 5c0d11ede8..295e127c7d 100644 --- a/www/apps/book/app/customization/integrate-systems/handle-event/page.mdx +++ b/www/apps/book/app/customization/integrate-systems/handle-event/page.mdx @@ -176,7 +176,7 @@ import { syncBrandToSystemWorkflow } from "../workflows/sync-brand-to-system" export default async function brandCreatedHandler({ event: { data }, container, -}: SubscriberArgs>) { +}: SubscriberArgs<{ id: string }>) { await syncBrandToSystemWorkflow(container).run({ input: data, }) diff --git a/www/apps/book/app/customization/integrate-systems/service/page.mdx b/www/apps/book/app/customization/integrate-systems/service/page.mdx index 2ed1202bb8..4ed3276cb8 100644 --- a/www/apps/book/app/customization/integrate-systems/service/page.mdx +++ b/www/apps/book/app/customization/integrate-systems/service/page.mdx @@ -53,7 +53,7 @@ export class BrandClient { const moduleDef = configModule.modules[BRAND_MODULE] if (typeof moduleDef !== "boolean") { - this.options_ = moduleDef.options + this.options_ = moduleDef.options as BrandClientOptions } } } @@ -101,7 +101,7 @@ export class BrandClient { }`) } - async createBrand(brand: Record) { + async createBrand(brand: Record) { await this.sendRequest("/brands", "POST", brand) } diff --git a/www/apps/book/app/debugging-and-testing/instrumentation/page.mdx b/www/apps/book/app/debugging-and-testing/instrumentation/page.mdx index 23dfc257af..709237071e 100644 --- a/www/apps/book/app/debugging-and-testing/instrumentation/page.mdx +++ b/www/apps/book/app/debugging-and-testing/instrumentation/page.mdx @@ -51,22 +51,22 @@ Next, create the file `instrumentation.js` with the following content: ```js title="instrumentation.js" const { registerOtel } = require("@medusajs/medusa") // If using an exporter other than Zipkin, require it here. -const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin') +const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin") // If using an exporter other than Zipkin, initialize it here. const exporter = new ZipkinExporter({ - serviceName: 'my-medusa-project', + serviceName: "my-medusa-project", }) export function register() { registerOtel({ - serviceName: 'medusajs', + serviceName: "medusajs", // pass exporter exporter, instrument: { http: true, workflows: true, - remoteQuery: true + remoteQuery: true, }, }) }