@davoodmehraban89 / medusa / commits / 58bfd2d9
Fork 0

Review Medusa upstream develop at 0b97a96ea0d32ff3f4b18dbeeeeba9e763600a15

github-actions[bot] committed Oct 14, 2026 at 20:02 UTC 58bfd2d99b2ef772491022aca8de41efdd4d5e2d
38 files changed +186 -27
.changeset/product-variant-update-id-and-empty-options.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +"@medusajs/product": patch
3 +---
4 +
5 +fix(product): keep the selected variant id when updating variants and ignore an empty options map instead of clearing the variant's options
.changeset/workflows-sdk-transform-key-property.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +"@medusajs/workflows-sdk": patch
3 +---
4 +
5 +fix(workflows-sdk): resolve transform results that have a `key` property
.github/medusa-upstream-reviewed-sha new
+1
@@ -0,0 +1 @@
1 +0b97a96ea0d32ff3f4b18dbeeeeba9e763600a15
.yarn/releases/yarn-3.2.1.cjs
integration-tests/scripts/cli/get-products.sh
integration-tests/scripts/cli/login.sh
integration-tests/scripts/cli/wait-for-server-live.sh
packages/cli/medusa-cli/cli.js
packages/cli/oas/oas-github-ci/scripts/build-openapi.js
packages/core/workflows-sdk/src/utils/composer/__tests__/compose.spec.ts
+59 -1
@@ -812,7 +812,7 @@ describe("Workflow composer", function () {
812 it("should compose a new workflow with conditional steps", async () => {
813 const stepResults: string[] = []
814
815 - let hookCalled = jest.fn()
815 + const hookCalled = jest.fn()
816 let timesExecuted = 0
817 const mockStep1Fn = jest.fn().mockImplementation(async () => {
818 timesExecuted += 1
@@ -1180,6 +1180,64 @@ describe("Workflow composer", function () {
1180 expect(mockStep3Fn.mock.calls[0][0]).toEqual({ variant: "variant_2" })
1181 })
1182
1183 + it("should resolve a transform result that has a key property when passed to a step", async () => {
1184 + const mockStep1Fn = jest.fn().mockImplementation((input) => input)
1185 + const mockStep2Fn = jest.fn().mockImplementation((input) => input)
1186 +
1187 + const step1 = createStep("step1", mockStep1Fn)
1188 + const step2 = createStep("step2", mockStep2Fn)
1189 +
1190 + const workflow = createWorkflow(
1191 + "workflow1",
1192 + function (input: { value: string }) {
1193 + const obj = transform({ input }, ({ input }) => ({
1194 + key: input.value,
1195 + other: "x",
1196 + }))
1197 + step1({ a: obj.key, b: obj.other })
1198 + step2({ nested: obj, list: [obj] })
1199 + }
1200 + )
1201 +
1202 + await workflow().run({
1203 + input: { value: "hello" },
1204 + })
1205 +
1206 + expect(mockStep1Fn.mock.calls[0][0]).toEqual({ a: "hello", b: "x" })
1207 + expect(mockStep2Fn.mock.calls[0][0]).toEqual({
1208 + nested: { key: "hello", other: "x" },
1209 + list: [{ key: "hello", other: "x" }],
1210 + })
1211 + })
1212 +
1213 + it("should resolve step results nested in a transform result when passed to a step", async () => {
1214 + const mockStep1Fn = jest.fn().mockImplementation(() => ({ id: "s1" }))
1215 + const mockStep2Fn = jest.fn().mockImplementation((input) => input)
1216 +
1217 + const step1 = createStep("step1", mockStep1Fn)
1218 + const step2 = createStep("step2", mockStep2Fn)
1219 +
1220 + const workflow = createWorkflow(
1221 + "workflow1",
1222 + function (input: { value: string }) {
1223 + const step1Result = step1(input)
1224 + const obj = transform({ input }, ({ input }) => ({
1225 + key: input.value,
1226 + step1: step1Result,
1227 + }))
1228 + step2({ data: obj })
1229 + }
1230 + )
1231 +
1232 + await workflow().run({
1233 + input: { value: "hello" },
1234 + })
1235 +
1236 + expect(mockStep2Fn.mock.calls[0][0]).toEqual({
1237 + data: { key: "hello", step1: { id: "s1" } },
1238 + })
1239 + })
1240 +
1241 it("should throw error when multiple handlers are defined for a single hook", async () => {
1242 const mockStep1Fn = jest.fn().mockImplementation(({ input }) => {
1243 return { id: input, product: "product_1", variant: "variant_2" }
packages/core/workflows-sdk/src/utils/composer/helpers/resolve-value.ts
+25 -20
@@ -111,7 +111,11 @@ function unwrapInput({
111 }
112
113 const keys = Object.keys(inputTOUnwrap)
114 - const promises: { promise: Promise<any>; keyIndex: number }[] = []
114 + const promises: {
115 + promise: Promise<any>
116 + keyIndex: number
117 + isUnwrapped?: boolean
118 + }[] = []
119
120 for (let i = 0; i < keys.length; i++) {
121 const key = keys[i]
@@ -136,8 +140,9 @@ function unwrapInput({
140 })
141 if (unwrapped instanceof Promise) {
142 promises.push({
139 - promise: unwrapped.then((r) => ({ key, value: r })),
143 + promise: unwrapped,
144 keyIndex: i,
145 + isUnwrapped: true,
146 })
147 } else {
148 parentRef[key] = unwrapped
@@ -151,26 +156,26 @@ function unwrapInput({
156 (resolvedPromises) => {
157 for (let i = 0; i < promises.length; i++) {
158 const resolved = resolvedPromises[i]
154 - if (resolved && typeof resolved === "object" && "key" in resolved) {
155 - parentRef[resolved.key] = resolved.value
156 - } else {
157 - const key = keys[promises[i].keyIndex]
158 - parentRef[key] = resolved
159 -
160 - if (resolved != null && typeof resolved === "object") {
161 - const unwrapped = unwrapInput({
162 - inputTOUnwrap: resolved,
163 - parentRef: {},
164 - transactionContext,
159 + const key = keys[promises[i].keyIndex]
160 + parentRef[key] = resolved
161 +
162 + if (
163 + !promises[i].isUnwrapped &&
164 + resolved != null &&
165 + typeof resolved === "object"
166 + ) {
167 + const unwrapped = unwrapInput({
168 + inputTOUnwrap: resolved,
169 + parentRef: {},
170 + transactionContext,
171 + })
172 + if (unwrapped instanceof Promise) {
173 + return unwrapped.then((r) => {
174 + parentRef[key] = r
175 + return parentRef
176 })
166 - if (unwrapped instanceof Promise) {
167 - return unwrapped.then((r) => {
168 - parentRef[key] = r
169 - return parentRef
170 - })
171 - }
172 - parentRef[key] = unwrapped
177 }
178 + parentRef[key] = unwrapped
179 }
180 }
181 return parentRef
packages/design-system/toolbox/bin/toolbox.js
packages/modules/product/integration-tests/__tests__/product-module-service/product-variants.spec.ts
+61
@@ -516,6 +516,67 @@ moduleIntegrationTestRunner<IProductModuleService>({
516 )
517 })
518
519 + it("should keep the options of a variant when updating with an empty options map", async () => {
520 + await service.updateProductVariants(
521 + { id: variantOne.id, product_id: productOne.id },
522 + { title: "updated variant", options: {} }
523 + )
524 +
525 + const productVariant = await service.retrieveProductVariant(
526 + variantOne.id,
527 + { relations: ["options"] }
528 + )
529 +
530 + expect(productVariant.title).toEqual("updated variant")
531 + expect(productVariant.options).toHaveLength(2)
532 + })
533 +
534 + it("should update the variant matched by the selector even when the data contains another id", async () => {
535 + const otherVariant = await service.createProductVariants({
536 + title: "other variant",
537 + product_id: productOne.id,
538 + options: { size: "small", color: "blue" },
539 + } as CreateProductVariantDTO)
540 +
541 + const updated = await service.updateProductVariants(
542 + { id: variantOne.id, product_id: productOne.id },
543 + { id: otherVariant.id, title: "updated" } as UpdateProductVariantDTO
544 + )
545 +
546 + expect(updated).toEqual([
547 + expect.objectContaining({ id: variantOne.id, title: "updated" }),
548 + ])
549 +
550 + const [selected, other] = await Promise.all([
551 + service.retrieveProductVariant(variantOne.id),
552 + service.retrieveProductVariant(otherVariant.id),
553 + ])
554 +
555 + expect(selected.title).toEqual("updated")
556 + expect(other.title).toEqual("other variant")
557 + })
558 +
559 + it("should update the variant matching the given id even when the data contains another id", async () => {
560 + const otherVariant = await service.createProductVariants({
561 + title: "other variant",
562 + product_id: productOne.id,
563 + options: { size: "small", color: "blue" },
564 + } as CreateProductVariantDTO)
565 +
566 + await service.updateProductVariants(variantOne.id, {
567 + id: otherVariant.id,
568 + title: "updated",
569 + } as UpdateProductVariantDTO)
570 +
571 + const [selected, other] = await Promise.all([
572 + service.retrieveProductVariant(variantOne.id),
573 + service.retrieveProductVariant(otherVariant.id),
574 + ])
575 +
576 + expect(selected.title).toEqual("updated")
577 + expect(other.title).toEqual("other variant")
578 + })
579 +
580 it("should throw an error when an id does not exist", async () => {
581 let error
582
packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts
+18
@@ -930,6 +930,24 @@ moduleIntegrationTestRunner<IProductModuleService>({
930 )
931 })
932
933 + it("should keep the options of variants updated with an empty options map", async () => {
934 + await service.updateProducts(productTwo.id, {
935 + variants: productTwo.variants.map((variant) => ({
936 + id: variant.id,
937 + options: {},
938 + })),
939 + })
940 +
941 + const fetchedProduct = await service.retrieveProduct(productTwo.id, {
942 + relations: ["variants", "variants.options"],
943 + })
944 +
945 + expect(fetchedProduct.variants).toHaveLength(2)
946 + fetchedProduct.variants.forEach((variant) => {
947 + expect(variant.options).toHaveLength(2)
948 + })
949 + })
950 +
951 it("should create a variant with id that was passed if it does not exist", async () => {
952 const updateData = {
953 id: productTwo.id,
packages/modules/product/src/repositories/product.ts
+5
@@ -105,6 +105,11 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory(
105 }
106
107 if (productToUpdate.variants) {
108 + productToUpdate.variants = productToUpdate.variants.map(
109 + ({ options, ...variant }: any) =>
110 + isPresent(options) ? { ...variant, options } : variant
111 + )
112 +
113 const expectedOptionIds = expectedOptionIdsMap.get(product.id)
114 const optionsForValidation = expectedOptionIds
115 ? product.options.filter((o) => expectedOptionIds.has(o.id))
packages/modules/product/src/services/product-module-service.ts
+7 -4
@@ -725,7 +725,7 @@ export default class ProductModuleService
725 > {
726 let normalizedInput: UpdateProductVariantInput[] = []
727 if (isString(idOrSelector)) {
728 - normalizedInput = [{ id: idOrSelector, ...data }]
728 + normalizedInput = [{ ...data, id: idOrSelector }]
729 } else {
730 const variants = await this.productVariantService_.list(
731 idOrSelector,
@@ -734,8 +734,8 @@ export default class ProductModuleService
734 )
735
736 normalizedInput = variants.map((variant) => ({
737 - id: variant.id,
737 ...data,
738 + id: variant.id,
739 }))
740 }
741
@@ -758,7 +758,7 @@ export default class ProductModuleService
758 // needed in that case. When no variant carries `options`, all of that work is
759 // dead weight — and on a product with a large number of variants it is very
760 // expensive (see below), so we skip it.
761 - const hasOptions = data.some((d) => !!d.options)
761 + const hasOptions = data.some((d) => isPresent(d.options))
762
763 // Validation step
764 const variantIdsToUpdate = data.map(({ id }) => id)
@@ -781,10 +781,13 @@ export default class ProductModuleService
781 // Data normalization
782 const variantsWithProductId: UpdateProductVariantInput[] = variants.map(
783 (variant) => {
784 - const update = data.find(({ id }) => id === variant.id)!
784 + const { options, ...update } = data.find(
785 + ({ id }) => id === variant.id
786 + )!
787
788 return {
789 ...update,
790 + ...(isPresent(options) ? { options } : {}),
791 id: variant.id,
792 product_id: variant.product_id,
793 ...(isPresent(update.metadata)
script.sh
scripts/assert-changed-files-actions.sh
scripts/assert-changed-files.sh
scripts/assert-codegen-build-committed-actions.sh
scripts/check_team_review.sh
scripts/close_issue.sh
scripts/deps-analyze/analyze-dependencies.js
scripts/deps-analyze/update-dependency-versions.sh
scripts/get_dependency_releases.sh
scripts/get_linked_prs.sh
scripts/get_pr_diff.sh
scripts/run-workspace-unit-tests-in-chunks.sh
scripts/search_prs.sh
www/apps/user-guide/app/tips/table-views/page.mdx
-2
@@ -55,8 +55,6 @@ To customize a table, use the following controls at the top of the table:
55 - <InlineIcon Icon={DescendingSorting} alt="Sorting" />: Change the column and direction the table is sorted by.
56 - **Search**: Type in the search field to find specific records.
57
58 -You can also resize a column by dragging the edge of its header.
59 -
58 After you customize a table, click the **Save** button to save your changes. The **Save** button shows a menu with the following options, depending on the active view:
59
60 - **Save as new view**: Create a new personal view. You're prompted to enter a name for the view. After you save it, the new view becomes active and appears as a badge.
www/utils/packages/typedoc-plugin-medusa-theme/src/resources/partials/comment.hbs
www/utils/packages/typedoc-plugin-medusa-theme/src/resources/partials/member.declaration.hbs
www/utils/packages/typedoc-plugin-medusa-theme/src/resources/partials/member.getterSetter.hbs
www/utils/packages/typedoc-plugin-medusa-theme/src/resources/partials/member.sources.hbs
www/utils/packages/typedoc-plugin-medusa-theme/src/resources/partials/members.group.hbs
www/utils/packages/typedoc-plugin-medusa-theme/src/resources/templates/reflection.hbs
www/vale/get-files.sh
www/vale/run-vale.sh