diff --git a/integration-tests/helpers/create-admin-user.ts b/integration-tests/helpers/create-admin-user.ts index eb551c278d..90fb5854e1 100644 --- a/integration-tests/helpers/create-admin-user.ts +++ b/integration-tests/helpers/create-admin-user.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IAuthModuleService, IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import jwt from "jsonwebtoken" import { getContainer } from "../environment-helpers/use-container" diff --git a/integration-tests/helpers/seed-storefront-defaults.ts b/integration-tests/helpers/seed-storefront-defaults.ts index 99161e84c9..822f6b747b 100644 --- a/integration-tests/helpers/seed-storefront-defaults.ts +++ b/integration-tests/helpers/seed-storefront-defaults.ts @@ -1,10 +1,10 @@ import { createDefaultsWorkflow } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IRegionModuleService, IStoreModuleService, MedusaContainer, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" export const seedStorefrontDefaults = async ( container: MedusaContainer, diff --git a/integration-tests/http/__tests__/fulfillment/admin/fulfillment-sets.spec.ts b/integration-tests/http/__tests__/fulfillment/admin/fulfillment-sets.spec.ts index 70cee78d5d..46589dc60f 100644 --- a/integration-tests/http/__tests__/fulfillment/admin/fulfillment-sets.spec.ts +++ b/integration-tests/http/__tests__/fulfillment/admin/fulfillment-sets.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { adminHeaders, createAdminUser, diff --git a/integration-tests/http/__tests__/stock-location/admin/stock-location.spec.ts b/integration-tests/http/__tests__/stock-location/admin/stock-location.spec.ts index cc18583a92..be337e1dd5 100644 --- a/integration-tests/http/__tests__/stock-location/admin/stock-location.spec.ts +++ b/integration-tests/http/__tests__/stock-location/admin/stock-location.spec.ts @@ -1,4 +1,4 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import { adminHeaders, createAdminUser, diff --git a/integration-tests/modules/__tests__/auth/admin/email-password-provider.spec.ts b/integration-tests/modules/__tests__/auth/admin/email-password-provider.spec.ts index babe32fa89..e39b59d80c 100644 --- a/integration-tests/modules/__tests__/auth/admin/email-password-provider.spec.ts +++ b/integration-tests/modules/__tests__/auth/admin/email-password-provider.spec.ts @@ -1,7 +1,7 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IAuthModuleService } from "@medusajs/types" -import Scrypt from "scrypt-kdf" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import Scrypt from "scrypt-kdf" import { adminHeaders, createAdminUser, diff --git a/integration-tests/modules/__tests__/cart/store/add-promotions-to-cart.spec.ts b/integration-tests/modules/__tests__/cart/store/add-promotions-to-cart.spec.ts index 687c051baf..da3d227272 100644 --- a/integration-tests/modules/__tests__/cart/store/add-promotions-to-cart.spec.ts +++ b/integration-tests/modules/__tests__/cart/store/add-promotions-to-cart.spec.ts @@ -1,10 +1,11 @@ -import { - LinkModuleUtils, - ModuleRegistrationName, - RemoteLink, -} from "@medusajs/modules-sdk" +import { RemoteLink } from "@medusajs/modules-sdk" import { ICartModuleService, IPromotionModuleService } from "@medusajs/types" -import { Modules, PromotionType } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, + PromotionType, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { adminHeaders, @@ -30,7 +31,9 @@ medusaIntegrationTestRunner({ promotionModuleService = appContainer.resolve( ModuleRegistrationName.PROMOTION ) - remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK) + remoteLinkService = appContainer.resolve( + ContainerRegistrationKeys.REMOTE_LINK + ) }) beforeEach(async () => { diff --git a/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts b/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts index 1c1bcbd8d2..e696215fe7 100644 --- a/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts +++ b/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts @@ -13,7 +13,6 @@ import { updateLineItemsStepId, updatePaymentCollectionStepId, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, ICustomerModuleService, @@ -28,6 +27,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, RuleOperator, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/cart/store/carts.spec.ts b/integration-tests/modules/__tests__/cart/store/carts.spec.ts index 133a72a8c8..6e7a5e5505 100644 --- a/integration-tests/modules/__tests__/cart/store/carts.spec.ts +++ b/integration-tests/modules/__tests__/cart/store/carts.spec.ts @@ -1,8 +1,4 @@ -import { - LinkModuleUtils, - ModuleRegistrationName, - RemoteLink, -} from "@medusajs/modules-sdk" +import { RemoteLink } from "@medusajs/modules-sdk" import PaymentModuleService from "@medusajs/payment/dist/services/payment-module" import { IApiKeyModuleService, @@ -21,6 +17,7 @@ import { import { ContainerRegistrationKeys, MedusaError, + ModuleRegistrationName, Modules, ProductStatus, PromotionRuleOperator, @@ -71,7 +68,7 @@ medusaIntegrationTestRunner({ productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT) pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING) apiKeyModule = appContainer.resolve(ModuleRegistrationName.API_KEY) - remoteLink = appContainer.resolve(LinkModuleUtils.REMOTE_LINK) + remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK) promotionModule = appContainer.resolve(ModuleRegistrationName.PROMOTION) taxModule = appContainer.resolve(ModuleRegistrationName.TAX) regionService = appContainer.resolve(ModuleRegistrationName.REGION) diff --git a/integration-tests/modules/__tests__/cart/store/remove-promotions-from-cart.spec.ts b/integration-tests/modules/__tests__/cart/store/remove-promotions-from-cart.spec.ts index fdd25397f2..3c80da9b50 100644 --- a/integration-tests/modules/__tests__/cart/store/remove-promotions-from-cart.spec.ts +++ b/integration-tests/modules/__tests__/cart/store/remove-promotions-from-cart.spec.ts @@ -1,10 +1,11 @@ -import { - LinkModuleUtils, - ModuleRegistrationName, - RemoteLink, -} from "@medusajs/modules-sdk" +import { RemoteLink } from "@medusajs/modules-sdk" import { ICartModuleService, IPromotionModuleService } from "@medusajs/types" -import { Modules, PromotionType } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, + PromotionType, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { adminHeaders, @@ -27,7 +28,9 @@ medusaIntegrationTestRunner({ beforeAll(async () => { appContainer = getContainer() cartModuleService = appContainer.resolve(ModuleRegistrationName.CART) - remoteLinkService = appContainer.resolve(LinkModuleUtils.REMOTE_LINK) + remoteLinkService = appContainer.resolve( + ContainerRegistrationKeys.REMOTE_LINK + ) promotionModuleService = appContainer.resolve( ModuleRegistrationName.PROMOTION ) diff --git a/integration-tests/modules/__tests__/customer-group/admin/batch-add-customers.ts b/integration-tests/modules/__tests__/customer-group/admin/batch-add-customers.ts index ea14b4f9e7..fd5276c9eb 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/batch-add-customers.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/batch-add-customers.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/customer-group/admin/batch-remove-customers.ts b/integration-tests/modules/__tests__/customer-group/admin/batch-remove-customers.ts index c452013fd3..f55a765ce5 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/batch-remove-customers.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/batch-remove-customers.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/customer-group/admin/delete-customer-group.ts b/integration-tests/modules/__tests__/customer-group/admin/delete-customer-group.ts index 16a8c2942f..e8f72cc92c 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/delete-customer-group.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/delete-customer-group.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer-group/admin/list-customer-group-customers.ts b/integration-tests/modules/__tests__/customer-group/admin/list-customer-group-customers.ts index 269fb9024a..b78fa8a821 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/list-customer-group-customers.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/list-customer-group-customers.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer-group/admin/list-customer-groups.spec.ts b/integration-tests/modules/__tests__/customer-group/admin/list-customer-groups.spec.ts index bdbdd61298..a6ca46f501 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/list-customer-groups.spec.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/list-customer-groups.spec.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer-group/admin/retrieve-customer-group.ts b/integration-tests/modules/__tests__/customer-group/admin/retrieve-customer-group.ts index 22ebfc42f0..c431963ff5 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/retrieve-customer-group.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/retrieve-customer-group.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer-group/admin/update-customer-group.ts b/integration-tests/modules/__tests__/customer-group/admin/update-customer-group.ts index c35773bd01..d5a933413f 100644 --- a/integration-tests/modules/__tests__/customer-group/admin/update-customer-group.ts +++ b/integration-tests/modules/__tests__/customer-group/admin/update-customer-group.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts b/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts index 0644d5eff4..2238e3491e 100644 --- a/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts +++ b/integration-tests/modules/__tests__/customer/admin/create-customer-addresses.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts index c40716fb52..3c8d27b10a 100644 --- a/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/admin/delete-customer-address.spec.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/admin/delete-customer.ts b/integration-tests/modules/__tests__/customer/admin/delete-customer.ts index 643b50edf1..0046cd69bf 100644 --- a/integration-tests/modules/__tests__/customer/admin/delete-customer.ts +++ b/integration-tests/modules/__tests__/customer/admin/delete-customer.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/admin/list-customer-addresses.ts b/integration-tests/modules/__tests__/customer/admin/list-customer-addresses.ts index 7e3156fad0..676dca6079 100644 --- a/integration-tests/modules/__tests__/customer/admin/list-customer-addresses.ts +++ b/integration-tests/modules/__tests__/customer/admin/list-customer-addresses.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/admin/list-customers.spec.ts b/integration-tests/modules/__tests__/customer/admin/list-customers.spec.ts index 43759e658a..ade854131b 100644 --- a/integration-tests/modules/__tests__/customer/admin/list-customers.spec.ts +++ b/integration-tests/modules/__tests__/customer/admin/list-customers.spec.ts @@ -4,7 +4,7 @@ import { } from "../../../../helpers/create-admin-user" import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" const { medusaIntegrationTestRunner } = require("medusa-test-utils") diff --git a/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts index b6baa7f0ec..32bfbaf8fb 100644 --- a/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/admin/update-customer-address.spec.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/admin/update-customer.ts b/integration-tests/modules/__tests__/customer/admin/update-customer.ts index 663afccbe6..9d76618267 100644 --- a/integration-tests/modules/__tests__/customer/admin/update-customer.ts +++ b/integration-tests/modules/__tests__/customer/admin/update-customer.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/store/create-customer-addresses.ts b/integration-tests/modules/__tests__/customer/store/create-customer-addresses.ts index bd93d0abfc..5e2ee72365 100644 --- a/integration-tests/modules/__tests__/customer/store/create-customer-addresses.ts +++ b/integration-tests/modules/__tests__/customer/store/create-customer-addresses.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/store/create-customer.spec.ts b/integration-tests/modules/__tests__/customer/store/create-customer.spec.ts index 035dcd51da..28bc574e26 100644 --- a/integration-tests/modules/__tests__/customer/store/create-customer.spec.ts +++ b/integration-tests/modules/__tests__/customer/store/create-customer.spec.ts @@ -1,13 +1,15 @@ -import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types" +import { IAuthModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, +} from "@medusajs/utils" import jwt from "jsonwebtoken" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { adminHeaders, createAdminUser, } from "../../../../helpers/create-admin-user" -import { ContainerRegistrationKeys } from "@medusajs/utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts index 22236d5eb1..d80d9c2c08 100644 --- a/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/store/delete-customer-address.spec.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" const env = { MEDUSA_FF_MEDUSA_V2: true } diff --git a/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts b/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts index c9e58cc929..741d2e12af 100644 --- a/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts +++ b/integration-tests/modules/__tests__/customer/store/list-customer-addresses.ts @@ -1,7 +1,7 @@ import { ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" const env = { MEDUSA_FF_MEDUSA_V2: true } diff --git a/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts b/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts index cff7b87c62..62e3ade379 100644 --- a/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts +++ b/integration-tests/modules/__tests__/customer/store/update-customer-address.spec.ts @@ -1,7 +1,7 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService } from "@medusajs/types" -import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/fulfillment-providers/index.spec.ts b/integration-tests/modules/__tests__/fulfillment-providers/index.spec.ts index 5e209a3247..7cc6216da6 100644 --- a/integration-tests/modules/__tests__/fulfillment-providers/index.spec.ts +++ b/integration-tests/modules/__tests__/fulfillment-providers/index.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/fulfillment/fulfillment.workflows.spec.ts b/integration-tests/modules/__tests__/fulfillment/fulfillment.workflows.spec.ts index 0a4774598e..6e80ba3e3e 100644 --- a/integration-tests/modules/__tests__/fulfillment/fulfillment.workflows.spec.ts +++ b/integration-tests/modules/__tests__/fulfillment/fulfillment.workflows.spec.ts @@ -6,8 +6,8 @@ import { updateFulfillmentWorkflow, updateFulfillmentWorkflowId, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { generateCreateFulfillmentData, diff --git a/integration-tests/modules/__tests__/fulfillment/index.spec.ts b/integration-tests/modules/__tests__/fulfillment/index.spec.ts index 10e6ad020a..03e2428e90 100644 --- a/integration-tests/modules/__tests__/fulfillment/index.spec.ts +++ b/integration-tests/modules/__tests__/fulfillment/index.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../helpers/create-admin-user" import { diff --git a/integration-tests/modules/__tests__/invites/accept-invite.spec.ts b/integration-tests/modules/__tests__/invites/accept-invite.spec.ts index b51155ce56..971f51fda1 100644 --- a/integration-tests/modules/__tests__/invites/accept-invite.spec.ts +++ b/integration-tests/modules/__tests__/invites/accept-invite.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/invites/delete-invite.spec.ts b/integration-tests/modules/__tests__/invites/delete-invite.spec.ts index be4a8ce27a..2c98b81b0e 100644 --- a/integration-tests/modules/__tests__/invites/delete-invite.spec.ts +++ b/integration-tests/modules/__tests__/invites/delete-invite.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/invites/list-invites.spec.ts b/integration-tests/modules/__tests__/invites/list-invites.spec.ts index 238ed3f8da..347b482080 100644 --- a/integration-tests/modules/__tests__/invites/list-invites.spec.ts +++ b/integration-tests/modules/__tests__/invites/list-invites.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/invites/resend-invite.spec.ts b/integration-tests/modules/__tests__/invites/resend-invite.spec.ts index bbaddd7f9b..97bb6b8af5 100644 --- a/integration-tests/modules/__tests__/invites/resend-invite.spec.ts +++ b/integration-tests/modules/__tests__/invites/resend-invite.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/invites/retrieve-invite.spec.ts b/integration-tests/modules/__tests__/invites/retrieve-invite.spec.ts index 4966a0d056..b6317cdc25 100644 --- a/integration-tests/modules/__tests__/invites/retrieve-invite.spec.ts +++ b/integration-tests/modules/__tests__/invites/retrieve-invite.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/cart-links.spec.ts b/integration-tests/modules/__tests__/link-modules/cart-links.spec.ts index 79399e9e95..d098a363cd 100644 --- a/integration-tests/modules/__tests__/link-modules/cart-links.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/cart-links.spec.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, ICustomerModuleService, @@ -6,8 +5,8 @@ import { IRegionModuleService, ISalesChannelModuleService, } from "@medusajs/types" +import { ModuleRegistrationName, Modules } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" -import { Modules } from "@medusajs/utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/cart-region.spec.ts b/integration-tests/modules/__tests__/link-modules/cart-region.spec.ts index c3e0d82460..c7d42cd58c 100644 --- a/integration-tests/modules/__tests__/link-modules/cart-region.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/cart-region.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/fulfillment-set-location.spec.ts b/integration-tests/modules/__tests__/link-modules/fulfillment-set-location.spec.ts index ddf3b21d5d..2b2a5c582e 100644 --- a/integration-tests/modules/__tests__/link-modules/fulfillment-set-location.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/fulfillment-set-location.spec.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService, IStockLocationService, } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/link-modules/product-variant-price-set.spec.ts b/integration-tests/modules/__tests__/link-modules/product-variant-price-set.spec.ts index d3ab8f70b5..ef3e1e57cb 100644 --- a/integration-tests/modules/__tests__/link-modules/product-variant-price-set.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/product-variant-price-set.spec.ts @@ -1,7 +1,7 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService, IProductModuleService } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/link-modules/publishable-key-sales-channel.spec.ts b/integration-tests/modules/__tests__/link-modules/publishable-key-sales-channel.spec.ts index c776c818d7..9bddc85753 100644 --- a/integration-tests/modules/__tests__/link-modules/publishable-key-sales-channel.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/publishable-key-sales-channel.spec.ts @@ -1,9 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IApiKeyModuleService, ISalesChannelModuleService, } from "@medusajs/types" -import { Modules, remoteQueryObjectFromString } from "@medusajs/utils" +import { + ModuleRegistrationName, + Modules, + remoteQueryObjectFromString, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/region-payment-provider.spec.ts b/integration-tests/modules/__tests__/link-modules/region-payment-provider.spec.ts index 070fa8583f..9b80431b3a 100644 --- a/integration-tests/modules/__tests__/link-modules/region-payment-provider.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/region-payment-provider.spec.ts @@ -1,7 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IRegionModuleService } from "@medusajs/types" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" -import { ContainerRegistrationKeys, Modules } from "@medusajs/utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/sales-channel-location.spec.ts b/integration-tests/modules/__tests__/link-modules/sales-channel-location.spec.ts index 5055390fef..09143e85a7 100644 --- a/integration-tests/modules/__tests__/link-modules/sales-channel-location.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/sales-channel-location.spec.ts @@ -1,9 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ISalesChannelModuleService, IStockLocationService, } from "@medusajs/types" -import { Modules, remoteQueryObjectFromString } from "@medusajs/utils" +import { + ModuleRegistrationName, + Modules, + remoteQueryObjectFromString, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/shipping-option-price-set.spec.ts b/integration-tests/modules/__tests__/link-modules/shipping-option-price-set.spec.ts index 29b93afed9..84d4555eb7 100644 --- a/integration-tests/modules/__tests__/link-modules/shipping-option-price-set.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/shipping-option-price-set.spec.ts @@ -1,9 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService, IPricingModuleService, } from "@medusajs/types" -import { ContainerRegistrationKeys, Modules } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/link-modules/store-currency.spec.ts b/integration-tests/modules/__tests__/link-modules/store-currency.spec.ts index ec9e92a426..fe45d8d23e 100644 --- a/integration-tests/modules/__tests__/link-modules/store-currency.spec.ts +++ b/integration-tests/modules/__tests__/link-modules/store-currency.spec.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICurrencyModuleService, IStoreModuleService } from "@medusajs/types" -import { remoteQueryObjectFromString } from "@medusajs/utils" +import { + ModuleRegistrationName, + remoteQueryObjectFromString, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/modules/remote-query.spec.ts b/integration-tests/modules/__tests__/modules/remote-query.spec.ts index ac8a102c9f..bc9fae48c5 100644 --- a/integration-tests/modules/__tests__/modules/remote-query.spec.ts +++ b/integration-tests/modules/__tests__/modules/remote-query.spec.ts @@ -1,6 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IRegionModuleService } from "@medusajs/types" -import { ContainerRegistrationKeys, Modules } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../..//helpers/create-admin-user" import { adminHeaders } from "../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/notification/admin/notification.spec.ts b/integration-tests/modules/__tests__/notification/admin/notification.spec.ts index 73f68ebc48..c4b135a63a 100644 --- a/integration-tests/modules/__tests__/notification/admin/notification.spec.ts +++ b/integration-tests/modules/__tests__/notification/admin/notification.spec.ts @@ -1,12 +1,14 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateNotificationDTO, IEventBusModuleService, INotificationModuleService, Logger, } from "@medusajs/types" -import { ContainerRegistrationKeys } from "@medusajs/utils" -import { medusaIntegrationTestRunner, TestEventUtils } from "medusa-test-utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, +} from "@medusajs/utils" +import { TestEventUtils, medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/order/draft-order.spec.ts b/integration-tests/modules/__tests__/order/draft-order.spec.ts index d100da8f4a..74a395fa4a 100644 --- a/integration-tests/modules/__tests__/order/draft-order.spec.ts +++ b/integration-tests/modules/__tests__/order/draft-order.spec.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, IFulfillmentModuleService, @@ -10,7 +9,11 @@ import { IStockLocationServiceNext, ITaxModuleService, } from "@medusajs/types" -import { ContainerRegistrationKeys, Modules } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { adminHeaders, diff --git a/integration-tests/modules/__tests__/order/order.spec.ts b/integration-tests/modules/__tests__/order/order.spec.ts index 20cc93b824..cbfb0e3396 100644 --- a/integration-tests/modules/__tests__/order/order.spec.ts +++ b/integration-tests/modules/__tests__/order/order.spec.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, IFulfillmentModuleService, @@ -10,7 +9,10 @@ import { IRegionModuleService, IStockLocationServiceNext, } from "@medusajs/types" -import { ContainerRegistrationKeys } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { adminHeaders, diff --git a/integration-tests/modules/__tests__/order/workflows/cancel-order.spec.ts b/integration-tests/modules/__tests__/order/workflows/cancel-order.spec.ts index 63391df8b3..6bab3d77d5 100644 --- a/integration-tests/modules/__tests__/order/workflows/cancel-order.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/cancel-order.spec.ts @@ -4,7 +4,6 @@ import { createOrderFulfillmentWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentWorkflow, IOrderModuleService, @@ -18,6 +17,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts index 37c707c786..8de1b3a82e 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-fulfillment.spec.ts @@ -3,7 +3,6 @@ import { createOrderFulfillmentWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentWorkflow, IOrderModuleService, @@ -17,6 +16,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/order/workflows/create-return.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-return.spec.ts index 2ab35cf96b..bdb55806d9 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-return.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-return.spec.ts @@ -2,7 +2,7 @@ import { createReturnOrderWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName, RemoteLink } from "@medusajs/modules-sdk" +import { RemoteLink } from "@medusajs/modules-sdk" import { FulfillmentSetDTO, FulfillmentWorkflow, @@ -17,6 +17,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, RuleOperator, remoteQueryObjectFromString, diff --git a/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts b/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts index cd076841dc..89c836df22 100644 --- a/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts +++ b/integration-tests/modules/__tests__/order/workflows/create-shipment.spec.ts @@ -3,7 +3,6 @@ import { createOrderShipmentWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentWorkflow, IOrderModuleService, @@ -17,6 +16,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, Modules, RuleOperator, remoteQueryObjectFromString, diff --git a/integration-tests/modules/__tests__/payment/payment-session.workflows.spec.ts b/integration-tests/modules/__tests__/payment/payment-session.workflows.spec.ts index 46b32b2ba0..33a26a3efd 100644 --- a/integration-tests/modules/__tests__/payment/payment-session.workflows.spec.ts +++ b/integration-tests/modules/__tests__/payment/payment-session.workflows.spec.ts @@ -2,8 +2,8 @@ import { createPaymentSessionsWorkflow, createPaymentSessionsWorkflowId, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/payment/payments.spec.ts b/integration-tests/modules/__tests__/payment/payments.spec.ts index 4c72dcd938..0c10fd318b 100644 --- a/integration-tests/modules/__tests__/payment/payments.spec.ts +++ b/integration-tests/modules/__tests__/payment/payments.spec.ts @@ -2,9 +2,12 @@ import { capturePaymentWorkflow, refundPaymentWorkflow, } from "@medusajs/core-flows" -import { LinkModuleUtils, ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPaymentModuleService, IRegionModuleService } from "@medusajs/types" -import { Modules } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) @@ -24,7 +27,7 @@ medusaIntegrationTestRunner({ appContainer = getContainer() regionService = appContainer.resolve(ModuleRegistrationName.REGION) paymentService = appContainer.resolve(ModuleRegistrationName.PAYMENT) - remoteLink = appContainer.resolve(LinkModuleUtils.REMOTE_LINK) + remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK) }) // TODO: Test should move to `integration-tests/api` diff --git a/integration-tests/modules/__tests__/price-lists/admin/price-lists.spec.ts b/integration-tests/modules/__tests__/price-lists/admin/price-lists.spec.ts index 6ed7cc18e5..1a8b4b72a0 100644 --- a/integration-tests/modules/__tests__/price-lists/admin/price-lists.spec.ts +++ b/integration-tests/modules/__tests__/price-lists/admin/price-lists.spec.ts @@ -1,11 +1,14 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService, IPricingModuleService, IProductModuleService, IRegionModuleService, } from "@medusajs/types" -import { PriceListStatus, PriceListType } from "@medusajs/utils" +import { + ModuleRegistrationName, + PriceListStatus, + PriceListType, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" diff --git a/integration-tests/modules/__tests__/pricing/get-product.ts b/integration-tests/modules/__tests__/pricing/get-product.ts index 0582af47b7..7d6e0bece4 100644 --- a/integration-tests/modules/__tests__/pricing/get-product.ts +++ b/integration-tests/modules/__tests__/pricing/get-product.ts @@ -1,6 +1,6 @@ import { simpleCartFactory, simpleRegionFactory } from "../../../factories" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/product/admin/products.spec.ts b/integration-tests/modules/__tests__/product/admin/products.spec.ts index a1980ba96a..5b1e10c8ff 100644 --- a/integration-tests/modules/__tests__/product/admin/products.spec.ts +++ b/integration-tests/modules/__tests__/product/admin/products.spec.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateProductDTO, IPricingModuleService, @@ -6,7 +5,11 @@ import { ProductDTO, ProductVariantDTO, } from "@medusajs/types" -import { PriceListStatus, PriceListType } from "@medusajs/utils" +import { + ModuleRegistrationName, + PriceListStatus, + PriceListType, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" import { createVariantPriceSet } from "../../../helpers/create-variant-price-set" diff --git a/integration-tests/modules/__tests__/product/workflows/batch-products.spec.ts b/integration-tests/modules/__tests__/product/workflows/batch-products.spec.ts index 77705d293f..742113c069 100644 --- a/integration-tests/modules/__tests__/product/workflows/batch-products.spec.ts +++ b/integration-tests/modules/__tests__/product/workflows/batch-products.spec.ts @@ -4,8 +4,8 @@ import { batchProductVariantsWorkflow, batchProductVariantsWorkflowId, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/promotion/admin/campaigns.spec.ts b/integration-tests/modules/__tests__/promotion/admin/campaigns.spec.ts index 20de876a97..3d2873ad26 100644 --- a/integration-tests/modules/__tests__/promotion/admin/campaigns.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/campaigns.spec.ts @@ -1,6 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" -import { CampaignBudgetType, PromotionType } from "@medusajs/utils" +import { + CampaignBudgetType, + ModuleRegistrationName, + PromotionType, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/promotion/admin/create-promotion.spec.ts b/integration-tests/modules/__tests__/promotion/admin/create-promotion.spec.ts index 162e98e35c..cabe38fe77 100644 --- a/integration-tests/modules/__tests__/promotion/admin/create-promotion.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/create-promotion.spec.ts @@ -1,5 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { IPromotionModuleService } from "@medusajs/types" import { PromotionType } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/promotion/admin/delete-promotion.spec.ts b/integration-tests/modules/__tests__/promotion/admin/delete-promotion.spec.ts index c67691983a..4ff9dfee80 100644 --- a/integration-tests/modules/__tests__/promotion/admin/delete-promotion.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/delete-promotion.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/promotion/admin/list-promotions.spec.ts b/integration-tests/modules/__tests__/promotion/admin/list-promotions.spec.ts index eb0e75fd8f..b898dd3f1a 100644 --- a/integration-tests/modules/__tests__/promotion/admin/list-promotions.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/list-promotions.spec.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" -import { PromotionType } from "@medusajs/utils" +import { ModuleRegistrationName, PromotionType } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/promotion/admin/promotion-rules.spec.ts b/integration-tests/modules/__tests__/promotion/admin/promotion-rules.spec.ts index 6d382059ad..b79c85047a 100644 --- a/integration-tests/modules/__tests__/promotion/admin/promotion-rules.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/promotion-rules.spec.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService, IProductModuleService, @@ -6,7 +5,7 @@ import { IRegionModuleService, ISalesChannelModuleService, } from "@medusajs/types" -import { PromotionType } from "@medusajs/utils" +import { ModuleRegistrationName, PromotionType } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/promotion/admin/retrieve-promotion.spec.ts b/integration-tests/modules/__tests__/promotion/admin/retrieve-promotion.spec.ts index a21728b187..6c42097d59 100644 --- a/integration-tests/modules/__tests__/promotion/admin/retrieve-promotion.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/retrieve-promotion.spec.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" -import { PromotionType } from "@medusajs/utils" +import { ModuleRegistrationName, PromotionType } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/promotion/admin/update-promotion.spec.ts b/integration-tests/modules/__tests__/promotion/admin/update-promotion.spec.ts index 862df69fe7..205e2f9f47 100644 --- a/integration-tests/modules/__tests__/promotion/admin/update-promotion.spec.ts +++ b/integration-tests/modules/__tests__/promotion/admin/update-promotion.spec.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" -import { PromotionType } from "@medusajs/utils" +import { ModuleRegistrationName, PromotionType } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/regions/admin/regions.spec.ts b/integration-tests/modules/__tests__/regions/admin/regions.spec.ts index c60515317f..30a5d54a45 100644 --- a/integration-tests/modules/__tests__/regions/admin/regions.spec.ts +++ b/integration-tests/modules/__tests__/regions/admin/regions.spec.ts @@ -1,7 +1,7 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IRegionModuleService } from "@medusajs/types" -import { createAdminUser } from "../../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/shipping-options/store/shipping-options.spec.ts b/integration-tests/modules/__tests__/shipping-options/store/shipping-options.spec.ts index 7244f3b165..daed25f245 100644 --- a/integration-tests/modules/__tests__/shipping-options/store/shipping-options.spec.ts +++ b/integration-tests/modules/__tests__/shipping-options/store/shipping-options.spec.ts @@ -1,9 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService, IRegionModuleService, } from "@medusajs/types" -import { ContainerRegistrationKeys, Modules } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, +} from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts b/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts index ffe1a233fc..f0a42478ed 100644 --- a/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts +++ b/integration-tests/modules/__tests__/shipping-options/workflows/batch-shipping-options-rules.ts @@ -2,7 +2,6 @@ import { batchShippingOptionRulesWorkflow, createShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { BatchWorkflowInput, CreateShippingOptionRuleDTO, @@ -16,6 +15,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/shipping-options/workflows/create-shipping-options.ts b/integration-tests/modules/__tests__/shipping-options/workflows/create-shipping-options.ts index 9509759a9d..421477c082 100644 --- a/integration-tests/modules/__tests__/shipping-options/workflows/create-shipping-options.ts +++ b/integration-tests/modules/__tests__/shipping-options/workflows/create-shipping-options.ts @@ -1,5 +1,4 @@ import { createShippingOptionsWorkflow } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentSetDTO, FulfillmentWorkflow, @@ -10,6 +9,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/shipping-options/workflows/delete-shipping-options.ts b/integration-tests/modules/__tests__/shipping-options/workflows/delete-shipping-options.ts index da74c4cb94..91b30d2afa 100644 --- a/integration-tests/modules/__tests__/shipping-options/workflows/delete-shipping-options.ts +++ b/integration-tests/modules/__tests__/shipping-options/workflows/delete-shipping-options.ts @@ -2,7 +2,6 @@ import { createShippingOptionsWorkflow, deleteShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentSetDTO, FulfillmentWorkflow, @@ -13,6 +12,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/shipping-options/workflows/update-shipping-options.ts b/integration-tests/modules/__tests__/shipping-options/workflows/update-shipping-options.ts index 319d074203..d4cc85cf9f 100644 --- a/integration-tests/modules/__tests__/shipping-options/workflows/update-shipping-options.ts +++ b/integration-tests/modules/__tests__/shipping-options/workflows/update-shipping-options.ts @@ -2,7 +2,6 @@ import { createShippingOptionsWorkflow, updateShippingOptionsWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentSetDTO, FulfillmentWorkflow, @@ -14,6 +13,7 @@ import { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, RuleOperator, remoteQueryObjectFromString, } from "@medusajs/utils" diff --git a/integration-tests/modules/__tests__/store/admin/store.spec.ts b/integration-tests/modules/__tests__/store/admin/store.spec.ts index ccaafb8fe9..85dee2c9e3 100644 --- a/integration-tests/modules/__tests__/store/admin/store.spec.ts +++ b/integration-tests/modules/__tests__/store/admin/store.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/tax/admin/tax.spec.ts b/integration-tests/modules/__tests__/tax/admin/tax.spec.ts index 868656e93a..dcd5768fdf 100644 --- a/integration-tests/modules/__tests__/tax/admin/tax.spec.ts +++ b/integration-tests/modules/__tests__/tax/admin/tax.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" import { createAdminUser } from "../../../../helpers/create-admin-user" diff --git a/integration-tests/modules/__tests__/tax/workflow/tax.spec.ts b/integration-tests/modules/__tests__/tax/workflow/tax.spec.ts index 765ee4410d..dee8b8466e 100644 --- a/integration-tests/modules/__tests__/tax/workflow/tax.spec.ts +++ b/integration-tests/modules/__tests__/tax/workflow/tax.spec.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createTaxRateRulesStepId, diff --git a/integration-tests/modules/__tests__/users/delete-user.spec.ts b/integration-tests/modules/__tests__/users/delete-user.spec.ts index 7de05c9563..83c74d01ce 100644 --- a/integration-tests/modules/__tests__/users/delete-user.spec.ts +++ b/integration-tests/modules/__tests__/users/delete-user.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/users/list-users.spec.ts b/integration-tests/modules/__tests__/users/list-users.spec.ts index 8a2e5ee779..aaafa7706f 100644 --- a/integration-tests/modules/__tests__/users/list-users.spec.ts +++ b/integration-tests/modules/__tests__/users/list-users.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/users/retrieve-user.spec.ts b/integration-tests/modules/__tests__/users/retrieve-user.spec.ts index bbd1f2f3a3..6d911ea5df 100644 --- a/integration-tests/modules/__tests__/users/retrieve-user.spec.ts +++ b/integration-tests/modules/__tests__/users/retrieve-user.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/__tests__/users/update-user.spec.ts b/integration-tests/modules/__tests__/users/update-user.spec.ts index 275d98ef66..9f614c3560 100644 --- a/integration-tests/modules/__tests__/users/update-user.spec.ts +++ b/integration-tests/modules/__tests__/users/update-user.spec.ts @@ -1,7 +1,7 @@ import { IUserModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { createAdminUser } from "../../../helpers/create-admin-user" +import { ModuleRegistrationName } from "@medusajs/utils" import { medusaIntegrationTestRunner } from "medusa-test-utils" +import { createAdminUser } from "../../../helpers/create-admin-user" jest.setTimeout(50000) diff --git a/integration-tests/modules/helpers/create-authenticated-customer.ts b/integration-tests/modules/helpers/create-authenticated-customer.ts index 5a6552013d..0c964b73b9 100644 --- a/integration-tests/modules/helpers/create-authenticated-customer.ts +++ b/integration-tests/modules/helpers/create-authenticated-customer.ts @@ -1,6 +1,6 @@ import { CreateCustomerDTO, MedusaContainer } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import jwt from "jsonwebtoken" export const createAuthenticatedCustomer = async ( diff --git a/packages/core/core-flows/src/api-key/steps/create-api-keys.ts b/packages/core/core-flows/src/api-key/steps/create-api-keys.ts index 93b2dd5b24..47b70fe02f 100644 --- a/packages/core/core-flows/src/api-key/steps/create-api-keys.ts +++ b/packages/core/core-flows/src/api-key/steps/create-api-keys.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateApiKeyDTO, IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CreateApiKeysStepInput = { diff --git a/packages/core/core-flows/src/api-key/steps/delete-api-keys.ts b/packages/core/core-flows/src/api-key/steps/delete-api-keys.ts index 7d438b800a..be63550149 100644 --- a/packages/core/core-flows/src/api-key/steps/delete-api-keys.ts +++ b/packages/core/core-flows/src/api-key/steps/delete-api-keys.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteApiKeysStepId = "delete-api-keys" diff --git a/packages/core/core-flows/src/api-key/steps/revoke-api-keys.ts b/packages/core/core-flows/src/api-key/steps/revoke-api-keys.ts index 6917eed6c5..3d0dd61174 100644 --- a/packages/core/core-flows/src/api-key/steps/revoke-api-keys.ts +++ b/packages/core/core-flows/src/api-key/steps/revoke-api-keys.ts @@ -1,9 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableApiKeyProps, IApiKeyModuleService, RevokeApiKeyDTO, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type RevokeApiKeysStepInput = { diff --git a/packages/core/core-flows/src/api-key/steps/update-api-keys.ts b/packages/core/core-flows/src/api-key/steps/update-api-keys.ts index 9e505a0a0e..07ae1d8e7d 100644 --- a/packages/core/core-flows/src/api-key/steps/update-api-keys.ts +++ b/packages/core/core-flows/src/api-key/steps/update-api-keys.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableApiKeyProps, IApiKeyModuleService, UpdateApiKeyDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateApiKeysStepInput = { diff --git a/packages/core/core-flows/src/api-key/steps/validate-sales-channel-exists.ts b/packages/core/core-flows/src/api-key/steps/validate-sales-channel-exists.ts index 4a0dbf78f2..4d06ad83c4 100644 --- a/packages/core/core-flows/src/api-key/steps/validate-sales-channel-exists.ts +++ b/packages/core/core-flows/src/api-key/steps/validate-sales-channel-exists.ts @@ -1,6 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ISalesChannelModuleService } from "@medusajs/types" -import { MedusaError, arrayDifference } from "@medusajs/utils" +import { + MedusaError, + ModuleRegistrationName, + arrayDifference, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/auth/steps/set-auth-app-metadata.ts b/packages/core/core-flows/src/auth/steps/set-auth-app-metadata.ts index 97f68cea3d..445d4f04dd 100644 --- a/packages/core/core-flows/src/auth/steps/set-auth-app-metadata.ts +++ b/packages/core/core-flows/src/auth/steps/set-auth-app-metadata.ts @@ -1,8 +1,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IAuthModuleService } from "@medusajs/types" -import { isDefined } from "@medusajs/utils" +import { ModuleRegistrationName, isDefined } from "@medusajs/utils" type StepInput = { authIdentityId: string diff --git a/packages/core/core-flows/src/customer-group/steps/create-customer-groups.ts b/packages/core/core-flows/src/customer-group/steps/create-customer-groups.ts index 6af7db371b..323872ae4d 100644 --- a/packages/core/core-flows/src/customer-group/steps/create-customer-groups.ts +++ b/packages/core/core-flows/src/customer-group/steps/create-customer-groups.ts @@ -1,6 +1,6 @@ import { CreateCustomerGroupDTO, ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" export const createCustomerGroupsStepId = "create-customer-groups" export const createCustomerGroupsStep = createStep( diff --git a/packages/core/core-flows/src/customer-group/steps/delete-customer-group-customers.ts b/packages/core/core-flows/src/customer-group/steps/delete-customer-group-customers.ts index b47aae66aa..3fa83e28f6 100644 --- a/packages/core/core-flows/src/customer-group/steps/delete-customer-group-customers.ts +++ b/packages/core/core-flows/src/customer-group/steps/delete-customer-group-customers.ts @@ -1,6 +1,6 @@ import { GroupCustomerPair, ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" export const deleteCustomerGroupCustomersStepId = "delete-customer-group-customers" diff --git a/packages/core/core-flows/src/customer-group/steps/delete-customer-groups.ts b/packages/core/core-flows/src/customer-group/steps/delete-customer-groups.ts index d9ad730678..00505027fc 100644 --- a/packages/core/core-flows/src/customer-group/steps/delete-customer-groups.ts +++ b/packages/core/core-flows/src/customer-group/steps/delete-customer-groups.ts @@ -1,6 +1,6 @@ import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" type DeleteCustomerGroupStepInput = string[] diff --git a/packages/core/core-flows/src/customer-group/steps/link-customers-customer-group.ts b/packages/core/core-flows/src/customer-group/steps/link-customers-customer-group.ts index 7a83eb21d3..9ae2afbc8f 100644 --- a/packages/core/core-flows/src/customer-group/steps/link-customers-customer-group.ts +++ b/packages/core/core-flows/src/customer-group/steps/link-customers-customer-group.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService, LinkWorkflowInput } from "@medusajs/types" -import { promiseAll } from "@medusajs/utils" +import { ModuleRegistrationName, promiseAll } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const linkCustomersToCustomerGroupStepId = diff --git a/packages/core/core-flows/src/customer-group/steps/update-customer-groups.ts b/packages/core/core-flows/src/customer-group/steps/update-customer-groups.ts index 3147d2dd7b..ce6cb68102 100644 --- a/packages/core/core-flows/src/customer-group/steps/update-customer-groups.ts +++ b/packages/core/core-flows/src/customer-group/steps/update-customer-groups.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CustomerGroupUpdatableFields, FilterableCustomerGroupProps, ICustomerModuleService, } from "@medusajs/types" import { + ModuleRegistrationName, getSelectsAndRelationsFromObjectArray, promiseAll, } from "@medusajs/utils" diff --git a/packages/core/core-flows/src/customer/steps/create-addresses.ts b/packages/core/core-flows/src/customer/steps/create-addresses.ts index 4210f81106..afac1b0793 100644 --- a/packages/core/core-flows/src/customer/steps/create-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/create-addresses.ts @@ -2,8 +2,8 @@ import { CreateCustomerAddressDTO, ICustomerModuleService, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createCustomerAddressesStepId = "create-customer-addresses" export const createCustomerAddressesStep = createStep( diff --git a/packages/core/core-flows/src/customer/steps/create-customers.ts b/packages/core/core-flows/src/customer/steps/create-customers.ts index 67de8a458d..615650ad2b 100644 --- a/packages/core/core-flows/src/customer/steps/create-customers.ts +++ b/packages/core/core-flows/src/customer/steps/create-customers.ts @@ -1,6 +1,6 @@ -import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { CreateCustomerDTO, ICustomerModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createCustomersStepId = "create-customers" export const createCustomersStep = createStep( diff --git a/packages/core/core-flows/src/customer/steps/delete-addresses.ts b/packages/core/core-flows/src/customer/steps/delete-addresses.ts index 9d8d05ccb9..e2bd8a4a62 100644 --- a/packages/core/core-flows/src/customer/steps/delete-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/delete-addresses.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type DeleteCustomerAddressStepInput = string[] diff --git a/packages/core/core-flows/src/customer/steps/delete-customers.ts b/packages/core/core-flows/src/customer/steps/delete-customers.ts index 98071f4757..c777162d23 100644 --- a/packages/core/core-flows/src/customer/steps/delete-customers.ts +++ b/packages/core/core-flows/src/customer/steps/delete-customers.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type DeleteCustomerStepInput = string[] diff --git a/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts b/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts index e036bd9b73..d96a160bd6 100644 --- a/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/maybe-unset-default-billing-addresses.ts @@ -1,13 +1,12 @@ import { CreateCustomerAddressDTO, - UpdateCustomerAddressDTO, FilterableCustomerAddressProps, ICustomerModuleService, + UpdateCustomerAddressDTO, } from "@medusajs/types" +import { ModuleRegistrationName, isDefined } from "@medusajs/utils" import { createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { unsetForCreate, unsetForUpdate } from "./utils" -import { isDefined } from "@medusajs/utils" type StepInput = { create?: CreateCustomerAddressDTO[] diff --git a/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts b/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts index 37dd60fe92..50a8fc5326 100644 --- a/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/maybe-unset-default-shipping-addresses.ts @@ -1,13 +1,12 @@ import { CreateCustomerAddressDTO, - UpdateCustomerAddressDTO, FilterableCustomerAddressProps, ICustomerModuleService, + UpdateCustomerAddressDTO, } from "@medusajs/types" +import { ModuleRegistrationName, isDefined } from "@medusajs/utils" import { createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { unsetForCreate, unsetForUpdate } from "./utils" -import { isDefined } from "@medusajs/utils" type StepInput = { create?: CreateCustomerAddressDTO[] diff --git a/packages/core/core-flows/src/customer/steps/update-addresses.ts b/packages/core/core-flows/src/customer/steps/update-addresses.ts index 80c27f581a..031808256b 100644 --- a/packages/core/core-flows/src/customer/steps/update-addresses.ts +++ b/packages/core/core-flows/src/customer/steps/update-addresses.ts @@ -1,14 +1,14 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { - UpdateCustomerAddressDTO, FilterableCustomerAddressProps, ICustomerModuleService, + UpdateCustomerAddressDTO, } from "@medusajs/types" import { + ModuleRegistrationName, getSelectsAndRelationsFromObjectArray, promiseAll, } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateCustomerAddresseStepInput = { selector: FilterableCustomerAddressProps diff --git a/packages/core/core-flows/src/customer/steps/update-customers.ts b/packages/core/core-flows/src/customer/steps/update-customers.ts index d884c7b06a..61871ddd45 100644 --- a/packages/core/core-flows/src/customer/steps/update-customers.ts +++ b/packages/core/core-flows/src/customer/steps/update-customers.ts @@ -1,14 +1,14 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { + CustomerUpdatableFields, FilterableCustomerProps, ICustomerModuleService, - CustomerUpdatableFields, } from "@medusajs/types" import { + ModuleRegistrationName, getSelectsAndRelationsFromObjectArray, promiseAll, } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateCustomersStepInput = { selector: FilterableCustomerProps diff --git a/packages/core/core-flows/src/defaults/steps/create-default-store.ts b/packages/core/core-flows/src/defaults/steps/create-default-store.ts index 9dbc97039e..301933c928 100644 --- a/packages/core/core-flows/src/defaults/steps/create-default-store.ts +++ b/packages/core/core-flows/src/defaults/steps/create-default-store.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateStoreDTO, IStoreModuleService, StoreDTO } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { createStoresWorkflow } from "../../store" type CreateDefaultStoreStepInput = { diff --git a/packages/core/core-flows/src/definition/cart/steps/add-shipping-method-to-cart.ts b/packages/core/core-flows/src/definition/cart/steps/add-shipping-method-to-cart.ts index eb3045947d..61cb6860fa 100644 --- a/packages/core/core-flows/src/definition/cart/steps/add-shipping-method-to-cart.ts +++ b/packages/core/core-flows/src/definition/cart/steps/add-shipping-method-to-cart.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateShippingMethodDTO, ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/confirm-inventory.ts b/packages/core/core-flows/src/definition/cart/steps/confirm-inventory.ts index 03a58713e5..fc71ec78f3 100644 --- a/packages/core/core-flows/src/definition/cart/steps/confirm-inventory.ts +++ b/packages/core/core-flows/src/definition/cart/steps/confirm-inventory.ts @@ -1,7 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IInventoryService } from "@medusajs/types" -import { MedusaError, promiseAll } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + MedusaError, + ModuleRegistrationName, + promiseAll, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { items: { diff --git a/packages/core/core-flows/src/definition/cart/steps/create-carts.ts b/packages/core/core-flows/src/definition/cart/steps/create-carts.ts index 4d3200ee97..18a6f1f548 100644 --- a/packages/core/core-flows/src/definition/cart/steps/create-carts.ts +++ b/packages/core/core-flows/src/definition/cart/steps/create-carts.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateCartDTO, ICartModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createCartsStepId = "create-carts" export const createCartsStep = createStep( diff --git a/packages/core/core-flows/src/definition/cart/steps/create-line-item-adjustments.ts b/packages/core/core-flows/src/definition/cart/steps/create-line-item-adjustments.ts index 56ca03ffbb..da7165aa12 100644 --- a/packages/core/core-flows/src/definition/cart/steps/create-line-item-adjustments.ts +++ b/packages/core/core-flows/src/definition/cart/steps/create-line-item-adjustments.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateLineItemAdjustmentDTO, ICartModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/create-line-items.ts b/packages/core/core-flows/src/definition/cart/steps/create-line-items.ts index 7cf8d9e07d..7cf8aa8c8f 100644 --- a/packages/core/core-flows/src/definition/cart/steps/create-line-items.ts +++ b/packages/core/core-flows/src/definition/cart/steps/create-line-items.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateLineItemForCartDTO, ICartModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { id: string diff --git a/packages/core/core-flows/src/definition/cart/steps/create-payment-collection.ts b/packages/core/core-flows/src/definition/cart/steps/create-payment-collection.ts index 4495859fb8..75c015549b 100644 --- a/packages/core/core-flows/src/definition/cart/steps/create-payment-collection.ts +++ b/packages/core/core-flows/src/definition/cart/steps/create-payment-collection.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { BigNumberInput, IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = { diff --git a/packages/core/core-flows/src/definition/cart/steps/create-shipping-method-adjustments.ts b/packages/core/core-flows/src/definition/cart/steps/create-shipping-method-adjustments.ts index 44ebdd4695..cbe6f97b2f 100644 --- a/packages/core/core-flows/src/definition/cart/steps/create-shipping-method-adjustments.ts +++ b/packages/core/core-flows/src/definition/cart/steps/create-shipping-method-adjustments.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateShippingMethodAdjustmentDTO, ICartModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/find-one-or-any-region.ts b/packages/core/core-flows/src/definition/cart/steps/find-one-or-any-region.ts index 7775aed35f..f6fc61b768 100644 --- a/packages/core/core-flows/src/definition/cart/steps/find-one-or-any-region.ts +++ b/packages/core/core-flows/src/definition/cart/steps/find-one-or-any-region.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IRegionModuleService, IStoreModuleService } from "@medusajs/types" -import { MedusaError } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const findOneOrAnyRegionStepId = "find-one-or-any-region" diff --git a/packages/core/core-flows/src/definition/cart/steps/find-or-create-customer.ts b/packages/core/core-flows/src/definition/cart/steps/find-or-create-customer.ts index 882655b53a..29eb816824 100644 --- a/packages/core/core-flows/src/definition/cart/steps/find-or-create-customer.ts +++ b/packages/core/core-flows/src/definition/cart/steps/find-or-create-customer.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CustomerDTO, ICustomerModuleService } from "@medusajs/types" -import { validateEmail } from "@medusajs/utils" +import { ModuleRegistrationName, validateEmail } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/find-sales-channel.ts b/packages/core/core-flows/src/definition/cart/steps/find-sales-channel.ts index b3a4a830a7..4260551b46 100644 --- a/packages/core/core-flows/src/definition/cart/steps/find-sales-channel.ts +++ b/packages/core/core-flows/src/definition/cart/steps/find-sales-channel.ts @@ -1,10 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ISalesChannelModuleService, IStoreModuleService, SalesChannelDTO, } from "@medusajs/types" -import { MedusaError, isDefined } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName, isDefined } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/get-actions-to-compute-from-promotions.ts b/packages/core/core-flows/src/definition/cart/steps/get-actions-to-compute-from-promotions.ts index 3a8de587f0..6fc53550f7 100644 --- a/packages/core/core-flows/src/definition/cart/steps/get-actions-to-compute-from-promotions.ts +++ b/packages/core/core-flows/src/definition/cart/steps/get-actions-to-compute-from-promotions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartDTO, IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/get-item-tax-lines.ts b/packages/core/core-flows/src/definition/cart/steps/get-item-tax-lines.ts index c98d13e431..19b92e9810 100644 --- a/packages/core/core-flows/src/definition/cart/steps/get-item-tax-lines.ts +++ b/packages/core/core-flows/src/definition/cart/steps/get-item-tax-lines.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartLineItemDTO, CartShippingMethodDTO, @@ -10,7 +9,7 @@ import { TaxableItemDTO, TaxableShippingDTO, } from "@medusajs/types" -import { MedusaError } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/get-line-item-actions.ts b/packages/core/core-flows/src/definition/cart/steps/get-line-item-actions.ts index 06a4010604..91977b4e60 100644 --- a/packages/core/core-flows/src/definition/cart/steps/get-line-item-actions.ts +++ b/packages/core/core-flows/src/definition/cart/steps/get-line-item-actions.ts @@ -1,12 +1,16 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartLineItemDTO, CreateLineItemForCartDTO, ICartModuleService, UpdateLineItemWithSelectorDTO, } from "@medusajs/types" -import { deepEqualObj, isPresent, MathBN } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + MathBN, + ModuleRegistrationName, + deepEqualObj, + isPresent, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { id: string diff --git a/packages/core/core-flows/src/definition/cart/steps/get-promotion-codes-to-apply.ts b/packages/core/core-flows/src/definition/cart/steps/get-promotion-codes-to-apply.ts index 350808e4c2..599617db20 100644 --- a/packages/core/core-flows/src/definition/cart/steps/get-promotion-codes-to-apply.ts +++ b/packages/core/core-flows/src/definition/cart/steps/get-promotion-codes-to-apply.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" -import { PromotionActions } from "@medusajs/utils" +import { ModuleRegistrationName, PromotionActions } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/get-variant-price-sets.ts b/packages/core/core-flows/src/definition/cart/steps/get-variant-price-sets.ts index 413f09e79f..fcdf291968 100644 --- a/packages/core/core-flows/src/definition/cart/steps/get-variant-price-sets.ts +++ b/packages/core/core-flows/src/definition/cart/steps/get-variant-price-sets.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService } from "@medusajs/types" -import { MedusaError } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/get-variants.ts b/packages/core/core-flows/src/definition/cart/steps/get-variants.ts index 63571b5761..bf2d780f35 100644 --- a/packages/core/core-flows/src/definition/cart/steps/get-variants.ts +++ b/packages/core/core-flows/src/definition/cart/steps/get-variants.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableProductVariantProps, FindConfig, IProductModuleService, ProductVariantDTO, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/prepare-adjustments-from-promotion-actions.ts b/packages/core/core-flows/src/definition/cart/steps/prepare-adjustments-from-promotion-actions.ts index 5536d68ddb..f4353425d4 100644 --- a/packages/core/core-flows/src/definition/cart/steps/prepare-adjustments-from-promotion-actions.ts +++ b/packages/core/core-flows/src/definition/cart/steps/prepare-adjustments-from-promotion-actions.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AddItemAdjustmentAction, AddShippingMethodAdjustment, @@ -8,7 +7,7 @@ import { RemoveItemAdjustmentAction, RemoveShippingMethodAdjustment, } from "@medusajs/types" -import { ComputedActions } from "@medusajs/utils" +import { ComputedActions, ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/refresh-cart-shipping-methods.ts b/packages/core/core-flows/src/definition/cart/steps/refresh-cart-shipping-methods.ts index f1a6a71d0d..b06b4e6493 100644 --- a/packages/core/core-flows/src/definition/cart/steps/refresh-cart-shipping-methods.ts +++ b/packages/core/core-flows/src/definition/cart/steps/refresh-cart-shipping-methods.ts @@ -1,11 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartDTO, ICartModuleService, IFulfillmentModuleService, } from "@medusajs/types" -import { arrayDifference } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName, arrayDifference } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { cart: CartDTO diff --git a/packages/core/core-flows/src/definition/cart/steps/remove-line-item-adjustments.ts b/packages/core/core-flows/src/definition/cart/steps/remove-line-item-adjustments.ts index 8524adf11a..3cfcbfcc98 100644 --- a/packages/core/core-flows/src/definition/cart/steps/remove-line-item-adjustments.ts +++ b/packages/core/core-flows/src/definition/cart/steps/remove-line-item-adjustments.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/remove-shipping-method-adjustments.ts b/packages/core/core-flows/src/definition/cart/steps/remove-shipping-method-adjustments.ts index 8403ffc7e2..0dd09638ae 100644 --- a/packages/core/core-flows/src/definition/cart/steps/remove-shipping-method-adjustments.ts +++ b/packages/core/core-flows/src/definition/cart/steps/remove-shipping-method-adjustments.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/reserve-inventory.ts b/packages/core/core-flows/src/definition/cart/steps/reserve-inventory.ts index 91f797d463..d96428fbfc 100644 --- a/packages/core/core-flows/src/definition/cart/steps/reserve-inventory.ts +++ b/packages/core/core-flows/src/definition/cart/steps/reserve-inventory.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/retrieve-cart-with-links.ts b/packages/core/core-flows/src/definition/cart/steps/retrieve-cart-with-links.ts index 3cf4748e75..78fd5e29d7 100644 --- a/packages/core/core-flows/src/definition/cart/steps/retrieve-cart-with-links.ts +++ b/packages/core/core-flows/src/definition/cart/steps/retrieve-cart-with-links.ts @@ -1,7 +1,11 @@ -import { LinkModuleUtils } from "@medusajs/modules-sdk" import { CartWorkflowDTO } from "@medusajs/types" -import { isObject, Modules, remoteQueryObjectFromString } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + ContainerRegistrationKeys, + Modules, + isObject, + remoteQueryObjectFromString, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { cart_or_cart_id: string | CartWorkflowDTO @@ -19,7 +23,9 @@ export const retrieveCartWithLinksStep = createStep( } const id = cartOrCartId - const remoteQuery = container.resolve(LinkModuleUtils.REMOTE_QUERY) + const remoteQuery = container.resolve( + ContainerRegistrationKeys.REMOTE_QUERY + ) const query = remoteQueryObjectFromString({ entryPoint: Modules.CART, fields, diff --git a/packages/core/core-flows/src/definition/cart/steps/retrieve-cart.ts b/packages/core/core-flows/src/definition/cart/steps/retrieve-cart.ts index e7de7477ba..8b47164002 100644 --- a/packages/core/core-flows/src/definition/cart/steps/retrieve-cart.ts +++ b/packages/core/core-flows/src/definition/cart/steps/retrieve-cart.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartDTO, FindConfig, ICartModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { id: string diff --git a/packages/core/core-flows/src/definition/cart/steps/set-tax-lines-for-items.ts b/packages/core/core-flows/src/definition/cart/steps/set-tax-lines-for-items.ts index f2797612ae..756abe4772 100644 --- a/packages/core/core-flows/src/definition/cart/steps/set-tax-lines-for-items.ts +++ b/packages/core/core-flows/src/definition/cart/steps/set-tax-lines-for-items.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartWorkflowDTO, CreateLineItemTaxLineDTO, @@ -7,6 +6,7 @@ import { ItemTaxLineDTO, ShippingTaxLineDTO, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/cart/steps/update-cart-promotions.ts b/packages/core/core-flows/src/definition/cart/steps/update-cart-promotions.ts index d8a2de3327..16cba461e1 100644 --- a/packages/core/core-flows/src/definition/cart/steps/update-cart-promotions.ts +++ b/packages/core/core-flows/src/definition/cart/steps/update-cart-promotions.ts @@ -1,7 +1,11 @@ -import { LinkModuleUtils, ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" -import { Modules, PromotionActions } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, + PromotionActions, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { id: string @@ -17,8 +21,10 @@ export const updateCartPromotionsStep = createStep( updateCartPromotionsStepId, async (data: StepInput, { container }) => { const { promo_codes = [], id, action = PromotionActions.ADD } = data - const remoteLink = container.resolve(LinkModuleUtils.REMOTE_LINK) - const remoteQuery = container.resolve(LinkModuleUtils.REMOTE_QUERY) + const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK) + const remoteQuery = container.resolve( + ContainerRegistrationKeys.REMOTE_QUERY + ) const promotionService = container.resolve( ModuleRegistrationName.PROMOTION ) @@ -85,7 +91,7 @@ export const updateCartPromotionsStep = createStep( }) }, async (revertData, { container }) => { - const remoteLink = container.resolve(LinkModuleUtils.REMOTE_LINK) + const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK) if (revertData?.dismissedLinks?.length) { await remoteLink.create(revertData.dismissedLinks) diff --git a/packages/core/core-flows/src/definition/cart/steps/update-carts.ts b/packages/core/core-flows/src/definition/cart/steps/update-carts.ts index 37c55dfdd7..ec4388e809 100644 --- a/packages/core/core-flows/src/definition/cart/steps/update-carts.ts +++ b/packages/core/core-flows/src/definition/cart/steps/update-carts.ts @@ -1,11 +1,13 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, UpdateCartDTO, UpdateCartWorkflowInputDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const updateCartsStepId = "update-carts" export const updateCartsStep = createStep( diff --git a/packages/core/core-flows/src/definition/cart/steps/update-line-items.ts b/packages/core/core-flows/src/definition/cart/steps/update-line-items.ts index 4c47027efa..d91d07a7ae 100644 --- a/packages/core/core-flows/src/definition/cart/steps/update-line-items.ts +++ b/packages/core/core-flows/src/definition/cart/steps/update-line-items.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, UpdateLineItemWithSelectorDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { id: string diff --git a/packages/core/core-flows/src/definition/cart/steps/validate-cart-shipping-options.ts b/packages/core/core-flows/src/definition/cart/steps/validate-cart-shipping-options.ts index ff430926bc..a54b410082 100644 --- a/packages/core/core-flows/src/definition/cart/steps/validate-cart-shipping-options.ts +++ b/packages/core/core-flows/src/definition/cart/steps/validate-cart-shipping-options.ts @@ -1,7 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartDTO, IFulfillmentModuleService } from "@medusajs/types" -import { arrayDifference, MedusaError } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + MedusaError, + ModuleRegistrationName, + arrayDifference, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { cart: CartDTO diff --git a/packages/core/core-flows/src/definition/line-item/steps/delete-line-items.ts b/packages/core/core-flows/src/definition/line-item/steps/delete-line-items.ts index 567351d2e8..eef855ca8b 100644 --- a/packages/core/core-flows/src/definition/line-item/steps/delete-line-items.ts +++ b/packages/core/core-flows/src/definition/line-item/steps/delete-line-items.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteLineItemsStepId = "delete-line-items" diff --git a/packages/core/core-flows/src/definition/line-item/steps/list-line-items.ts b/packages/core/core-flows/src/definition/line-item/steps/list-line-items.ts index e2675e505d..b2c1b921f9 100644 --- a/packages/core/core-flows/src/definition/line-item/steps/list-line-items.ts +++ b/packages/core/core-flows/src/definition/line-item/steps/list-line-items.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CartLineItemDTO, FilterableLineItemProps, FindConfig, ICartModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/definition/line-item/steps/update-line-items.ts b/packages/core/core-flows/src/definition/line-item/steps/update-line-items.ts index 28458b239b..800fda26f3 100644 --- a/packages/core/core-flows/src/definition/line-item/steps/update-line-items.ts +++ b/packages/core/core-flows/src/definition/line-item/steps/update-line-items.ts @@ -1,9 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService, UpdateLineItemWithSelectorDTO, } from "@medusajs/types" import { + ModuleRegistrationName, getSelectsAndRelationsFromObjectArray, promiseAll, removeUndefined, diff --git a/packages/core/core-flows/src/file/steps/delete-files.ts b/packages/core/core-flows/src/file/steps/delete-files.ts index f4af33e893..aa339e747f 100644 --- a/packages/core/core-flows/src/file/steps/delete-files.ts +++ b/packages/core/core-flows/src/file/steps/delete-files.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFileModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteFilesStepId = "delete-files" diff --git a/packages/core/core-flows/src/file/steps/upload-files.ts b/packages/core/core-flows/src/file/steps/upload-files.ts index d722154828..d14a740b58 100644 --- a/packages/core/core-flows/src/file/steps/upload-files.ts +++ b/packages/core/core-flows/src/file/steps/upload-files.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFileModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UploadFilesStepInput = { diff --git a/packages/core/core-flows/src/fulfillment/steps/add-shipping-options-prices.ts b/packages/core/core-flows/src/fulfillment/steps/add-shipping-options-prices.ts index 9914692412..26116a2ea8 100644 --- a/packages/core/core-flows/src/fulfillment/steps/add-shipping-options-prices.ts +++ b/packages/core/core-flows/src/fulfillment/steps/add-shipping-options-prices.ts @@ -1,10 +1,10 @@ -import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { CreatePriceSetDTO, IPricingModuleService, IRegionModuleService, } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" interface PriceCurrencyCode { currency_code: string diff --git a/packages/core/core-flows/src/fulfillment/steps/cancel-fulfillment.ts b/packages/core/core-flows/src/fulfillment/steps/cancel-fulfillment.ts index a3980467ce..a8be96e8c8 100644 --- a/packages/core/core-flows/src/fulfillment/steps/cancel-fulfillment.ts +++ b/packages/core/core-flows/src/fulfillment/steps/cancel-fulfillment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const cancelFulfillmentStepId = "cancel-fulfillment" diff --git a/packages/core/core-flows/src/fulfillment/steps/create-fulfillment-set.ts b/packages/core/core-flows/src/fulfillment/steps/create-fulfillment-set.ts index a25bb72a96..f949590589 100644 --- a/packages/core/core-flows/src/fulfillment/steps/create-fulfillment-set.ts +++ b/packages/core/core-flows/src/fulfillment/steps/create-fulfillment-set.ts @@ -1,9 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateFulfillmentSetDTO, IFulfillmentModuleService, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createFulfillmentSetsId = "create-fulfillment-sets" export const createFulfillmentSets = createStep( diff --git a/packages/core/core-flows/src/fulfillment/steps/create-fulfillment.ts b/packages/core/core-flows/src/fulfillment/steps/create-fulfillment.ts index 331cdd5628..c43e0e224c 100644 --- a/packages/core/core-flows/src/fulfillment/steps/create-fulfillment.ts +++ b/packages/core/core-flows/src/fulfillment/steps/create-fulfillment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentTypes, IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createFulfillmentStepId = "create-fulfillment" diff --git a/packages/core/core-flows/src/fulfillment/steps/create-return-fulfillment.ts b/packages/core/core-flows/src/fulfillment/steps/create-return-fulfillment.ts index c478bdb59d..e087cb352c 100644 --- a/packages/core/core-flows/src/fulfillment/steps/create-return-fulfillment.ts +++ b/packages/core/core-flows/src/fulfillment/steps/create-return-fulfillment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentTypes, IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createReturnFulfillmentStepId = "create-return-fulfillment" diff --git a/packages/core/core-flows/src/fulfillment/steps/create-service-zones.ts b/packages/core/core-flows/src/fulfillment/steps/create-service-zones.ts index 14a98f7330..57ee0bb4db 100644 --- a/packages/core/core-flows/src/fulfillment/steps/create-service-zones.ts +++ b/packages/core/core-flows/src/fulfillment/steps/create-service-zones.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateServiceZoneDTO, IFulfillmentModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = CreateServiceZoneDTO[] diff --git a/packages/core/core-flows/src/fulfillment/steps/create-shipping-option-rules.ts b/packages/core/core-flows/src/fulfillment/steps/create-shipping-option-rules.ts index 3dacd02d5b..d658e037e6 100644 --- a/packages/core/core-flows/src/fulfillment/steps/create-shipping-option-rules.ts +++ b/packages/core/core-flows/src/fulfillment/steps/create-shipping-option-rules.ts @@ -1,9 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AddFulfillmentShippingOptionRulesWorkflowDTO, IFulfillmentModuleService, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createShippingOptionRulesStepId = "create-shipping-option-rules" export const createShippingOptionRulesStep = createStep( diff --git a/packages/core/core-flows/src/fulfillment/steps/create-shipping-profiles.ts b/packages/core/core-flows/src/fulfillment/steps/create-shipping-profiles.ts index aa3c8de3cc..46b83049e8 100644 --- a/packages/core/core-flows/src/fulfillment/steps/create-shipping-profiles.ts +++ b/packages/core/core-flows/src/fulfillment/steps/create-shipping-profiles.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateShippingProfileDTO, IFulfillmentModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = CreateShippingProfileDTO[] diff --git a/packages/core/core-flows/src/fulfillment/steps/delete-fulfillment-sets.ts b/packages/core/core-flows/src/fulfillment/steps/delete-fulfillment-sets.ts index 656f82547e..19260d7a47 100644 --- a/packages/core/core-flows/src/fulfillment/steps/delete-fulfillment-sets.ts +++ b/packages/core/core-flows/src/fulfillment/steps/delete-fulfillment-sets.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" export const deleteFulfillmentSetsStepId = "delete-fulfillment-sets" diff --git a/packages/core/core-flows/src/fulfillment/steps/delete-service-zones.ts b/packages/core/core-flows/src/fulfillment/steps/delete-service-zones.ts index 75cd8f87c4..47694b76af 100644 --- a/packages/core/core-flows/src/fulfillment/steps/delete-service-zones.ts +++ b/packages/core/core-flows/src/fulfillment/steps/delete-service-zones.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteServiceZonesStepId = "delete-service-zones" diff --git a/packages/core/core-flows/src/fulfillment/steps/delete-shipping-option-rules.ts b/packages/core/core-flows/src/fulfillment/steps/delete-shipping-option-rules.ts index 1a1ce36ddd..b42cd599b8 100644 --- a/packages/core/core-flows/src/fulfillment/steps/delete-shipping-option-rules.ts +++ b/packages/core/core-flows/src/fulfillment/steps/delete-shipping-option-rules.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService, RemoveFulfillmentShippingOptionRulesWorkflowDTO, RuleOperatorType, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteShippingOptionRulesStepId = "delete-shipping-option-rules" export const deleteShippingOptionRulesStep = createStep( diff --git a/packages/core/core-flows/src/fulfillment/steps/delete-shipping-options.ts b/packages/core/core-flows/src/fulfillment/steps/delete-shipping-options.ts index ff6f2133a9..2468bda939 100644 --- a/packages/core/core-flows/src/fulfillment/steps/delete-shipping-options.ts +++ b/packages/core/core-flows/src/fulfillment/steps/delete-shipping-options.ts @@ -1,10 +1,7 @@ -import { - DeleteEntityInput, - ModuleRegistrationName, -} from "@medusajs/modules-sdk" +import { DeleteEntityInput } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName, Modules } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" -import { Modules } from "@medusajs/utils" export const deleteShippingOptionsStepId = "delete-shipping-options-step" export const deleteShippingOptionsStep = createStep( diff --git a/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts b/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts index 2d310ccd94..97618a643f 100644 --- a/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts +++ b/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts @@ -8,14 +8,14 @@ import { PriceSetDTO, RemoteQueryFunction, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { ContainerRegistrationKeys, - isDefined, LINKS, + ModuleRegistrationName, + isDefined, remoteQueryObjectFromString, } from "@medusajs/utils" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface PriceRegionId { region_id: string diff --git a/packages/core/core-flows/src/fulfillment/steps/update-fulfillment.ts b/packages/core/core-flows/src/fulfillment/steps/update-fulfillment.ts index f3f1d6864f..86fbd816d5 100644 --- a/packages/core/core-flows/src/fulfillment/steps/update-fulfillment.ts +++ b/packages/core/core-flows/src/fulfillment/steps/update-fulfillment.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentWorkflow, IFulfillmentModuleService } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const updateFulfillmentStepId = "update-fulfillment" diff --git a/packages/core/core-flows/src/fulfillment/steps/update-service-zones.ts b/packages/core/core-flows/src/fulfillment/steps/update-service-zones.ts index 204ac20310..828958775b 100644 --- a/packages/core/core-flows/src/fulfillment/steps/update-service-zones.ts +++ b/packages/core/core-flows/src/fulfillment/steps/update-service-zones.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentWorkflow, IFulfillmentModuleService } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = FulfillmentWorkflow.UpdateServiceZonesWorkflowInput diff --git a/packages/core/core-flows/src/fulfillment/steps/update-shipping-option-rules.ts b/packages/core/core-flows/src/fulfillment/steps/update-shipping-option-rules.ts index c15e69da64..edb4b735f1 100644 --- a/packages/core/core-flows/src/fulfillment/steps/update-shipping-option-rules.ts +++ b/packages/core/core-flows/src/fulfillment/steps/update-shipping-option-rules.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService, UpdateFulfillmentShippingOptionRulesWorkflowDTO, UpdateShippingOptionRuleDTO, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const updateShippingOptionRulesStepId = "update-shipping-option-rules" export const updateShippingOptionRulesStep = createStep( diff --git a/packages/core/core-flows/src/fulfillment/steps/update-shipping-profiles.ts b/packages/core/core-flows/src/fulfillment/steps/update-shipping-profiles.ts index 16631007c9..6f3b376430 100644 --- a/packages/core/core-flows/src/fulfillment/steps/update-shipping-profiles.ts +++ b/packages/core/core-flows/src/fulfillment/steps/update-shipping-profiles.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableShippingProfileProps, IFulfillmentModuleService, UpdateShippingProfileDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = { diff --git a/packages/core/core-flows/src/fulfillment/steps/upsert-shipping-options.ts b/packages/core/core-flows/src/fulfillment/steps/upsert-shipping-options.ts index a4d34688ce..889534fc4c 100644 --- a/packages/core/core-flows/src/fulfillment/steps/upsert-shipping-options.ts +++ b/packages/core/core-flows/src/fulfillment/steps/upsert-shipping-options.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FulfillmentWorkflow, IFulfillmentModuleService, @@ -6,10 +5,11 @@ import { UpsertShippingOptionDTO, } from "@medusajs/types" import { + ModuleRegistrationName, arrayDifference, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = Omit< | FulfillmentWorkflow.CreateShippingOptionsWorkflowInput diff --git a/packages/core/core-flows/src/fulfillment/steps/validate-shipment.ts b/packages/core/core-flows/src/fulfillment/steps/validate-shipment.ts index bda7d5f802..8e74521cab 100644 --- a/packages/core/core-flows/src/fulfillment/steps/validate-shipment.ts +++ b/packages/core/core-flows/src/fulfillment/steps/validate-shipment.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" -import { MedusaError } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" export const validateShipmentStepId = "validate-shipment" diff --git a/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts b/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts index 56db099975..e3db5ea3c8 100644 --- a/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts +++ b/packages/core/core-flows/src/inventory/steps/adjust-inventory-levels.ts @@ -1,7 +1,7 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const adjustInventoryLevelsStepId = "adjust-inventory-levels-step" export const adjustInventoryLevelsStep = createStep( diff --git a/packages/core/core-flows/src/inventory/steps/create-inventory-items.ts b/packages/core/core-flows/src/inventory/steps/create-inventory-items.ts index fa733314be..3e27176507 100644 --- a/packages/core/core-flows/src/inventory/steps/create-inventory-items.ts +++ b/packages/core/core-flows/src/inventory/steps/create-inventory-items.ts @@ -1,7 +1,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IInventoryService, InventoryTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" export const createInventoryItemsStepId = "create-inventory-items" export const createInventoryItemsStep = createStep( diff --git a/packages/core/core-flows/src/inventory/steps/create-inventory-levels.ts b/packages/core/core-flows/src/inventory/steps/create-inventory-levels.ts index 79f5625822..1137dbef33 100644 --- a/packages/core/core-flows/src/inventory/steps/create-inventory-levels.ts +++ b/packages/core/core-flows/src/inventory/steps/create-inventory-levels.ts @@ -1,7 +1,7 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const createInventoryLevelsStepId = "create-inventory-levels" export const createInventoryLevelsStep = createStep( diff --git a/packages/core/core-flows/src/inventory/steps/delete-inventory-items.ts b/packages/core/core-flows/src/inventory/steps/delete-inventory-items.ts index 8ab0d52121..ce8621345d 100644 --- a/packages/core/core-flows/src/inventory/steps/delete-inventory-items.ts +++ b/packages/core/core-flows/src/inventory/steps/delete-inventory-items.ts @@ -1,6 +1,6 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const deleteInventoryItemStepId = "delete-inventory-item-step" export const deleteInventoryItemStep = createStep( diff --git a/packages/core/core-flows/src/inventory/steps/delete-inventory-levels.ts b/packages/core/core-flows/src/inventory/steps/delete-inventory-levels.ts index ce79f514fd..bcf8ff0792 100644 --- a/packages/core/core-flows/src/inventory/steps/delete-inventory-levels.ts +++ b/packages/core/core-flows/src/inventory/steps/delete-inventory-levels.ts @@ -1,7 +1,7 @@ -import { ICustomerModuleService, IInventoryService } from "@medusajs/types" -import { StepResponse, WorkflowData, createStep } from "@medusajs/workflows-sdk" +import { IInventoryService } from "@medusajs/types" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const deleteInventoryLevelsStepId = "delete-inventory-levels-step" export const deleteInventoryLevelsStep = createStep( diff --git a/packages/core/core-flows/src/inventory/steps/delete-levels-by-item-and-location.ts b/packages/core/core-flows/src/inventory/steps/delete-levels-by-item-and-location.ts index ab22251994..1a36c0e133 100644 --- a/packages/core/core-flows/src/inventory/steps/delete-levels-by-item-and-location.ts +++ b/packages/core/core-flows/src/inventory/steps/delete-levels-by-item-and-location.ts @@ -1,4 +1,4 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { IInventoryService } from "@medusajs/types" diff --git a/packages/core/core-flows/src/inventory/steps/update-inventory-items.ts b/packages/core/core-flows/src/inventory/steps/update-inventory-items.ts index 580407393f..59d05728d1 100644 --- a/packages/core/core-flows/src/inventory/steps/update-inventory-items.ts +++ b/packages/core/core-flows/src/inventory/steps/update-inventory-items.ts @@ -1,11 +1,11 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { convertItemResponseToUpdateRequest, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const updateInventoryItemsStepId = "update-inventory-items-step" export const updateInventoryItemsStep = createStep( diff --git a/packages/core/core-flows/src/inventory/steps/update-inventory-levels.ts b/packages/core/core-flows/src/inventory/steps/update-inventory-levels.ts index 8fc65ce411..a90cb8dc2d 100644 --- a/packages/core/core-flows/src/inventory/steps/update-inventory-levels.ts +++ b/packages/core/core-flows/src/inventory/steps/update-inventory-levels.ts @@ -1,11 +1,11 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { convertItemResponseToUpdateRequest, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const updateInventoryLevelsStepId = "update-inventory-levels-step" export const updateInventoryLevelsStep = createStep( diff --git a/packages/core/core-flows/src/invite/steps/create-invites.ts b/packages/core/core-flows/src/invite/steps/create-invites.ts index f6a4ac3a68..b19ffd6a67 100644 --- a/packages/core/core-flows/src/invite/steps/create-invites.ts +++ b/packages/core/core-flows/src/invite/steps/create-invites.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { CreateInviteDTO, IUserModuleService, InviteDTO } from "@medusajs/types" +import { CreateInviteDTO, IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createInviteStepId = "create-invite-step" diff --git a/packages/core/core-flows/src/invite/steps/delete-invites.ts b/packages/core/core-flows/src/invite/steps/delete-invites.ts index 036d71c2be..dbbeb50435 100644 --- a/packages/core/core-flows/src/invite/steps/delete-invites.ts +++ b/packages/core/core-flows/src/invite/steps/delete-invites.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteInvitesStepId = "delete-invites-step" diff --git a/packages/core/core-flows/src/invite/steps/refresh-invite-tokens.ts b/packages/core/core-flows/src/invite/steps/refresh-invite-tokens.ts index bbc9329ca4..26278d8f81 100644 --- a/packages/core/core-flows/src/invite/steps/refresh-invite-tokens.ts +++ b/packages/core/core-flows/src/invite/steps/refresh-invite-tokens.ts @@ -1,7 +1,7 @@ -import { IUserModuleService, InviteDTO } from "@medusajs/types" +import { IUserModuleService } from "@medusajs/types" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const refreshInviteTokensStepId = "refresh-invite-tokens-step" export const refreshInviteTokensStep = createStep( diff --git a/packages/core/core-flows/src/invite/steps/validate-token.ts b/packages/core/core-flows/src/invite/steps/validate-token.ts index 849d32fad5..11aedea937 100644 --- a/packages/core/core-flows/src/invite/steps/validate-token.ts +++ b/packages/core/core-flows/src/invite/steps/validate-token.ts @@ -1,8 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { InviteDTO } from "@medusajs/types" import { IUserModuleService } from "@medusajs/types" -import { StepResponse } from "@medusajs/workflows-sdk" -import { createStep } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const validateTokenStepId = "validate-invite-token-step" export const validateTokenStep = createStep( diff --git a/packages/core/core-flows/src/order/steps/archive-orders.ts b/packages/core/core-flows/src/order/steps/archive-orders.ts index 10355e0fd6..c2aef08585 100644 --- a/packages/core/core-flows/src/order/steps/archive-orders.ts +++ b/packages/core/core-flows/src/order/steps/archive-orders.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type ArchiveOrdersStepInput = { diff --git a/packages/core/core-flows/src/order/steps/cancel-claim.ts b/packages/core/core-flows/src/order/steps/cancel-claim.ts index 2f6b354983..8e9ae8f72f 100644 --- a/packages/core/core-flows/src/order/steps/cancel-claim.ts +++ b/packages/core/core-flows/src/order/steps/cancel-claim.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CancelOrderClaimDTO, IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CancelOrderClaimStepInput = CancelOrderClaimDTO diff --git a/packages/core/core-flows/src/order/steps/cancel-exchange.ts b/packages/core/core-flows/src/order/steps/cancel-exchange.ts index b1cddcdd9a..414882b075 100644 --- a/packages/core/core-flows/src/order/steps/cancel-exchange.ts +++ b/packages/core/core-flows/src/order/steps/cancel-exchange.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CancelOrderExchangeDTO, IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CancelOrderExchangeStepInput = CancelOrderExchangeDTO diff --git a/packages/core/core-flows/src/order/steps/cancel-fulfillment.ts b/packages/core/core-flows/src/order/steps/cancel-fulfillment.ts index a9f707021e..1e0f202ae6 100644 --- a/packages/core/core-flows/src/order/steps/cancel-fulfillment.ts +++ b/packages/core/core-flows/src/order/steps/cancel-fulfillment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CancelOrderFulfillmentDTO, IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CancelOrderFulfillmentStepInput = CancelOrderFulfillmentDTO diff --git a/packages/core/core-flows/src/order/steps/cancel-orders.ts b/packages/core/core-flows/src/order/steps/cancel-orders.ts index 0bbc6c3c07..b9d728d778 100644 --- a/packages/core/core-flows/src/order/steps/cancel-orders.ts +++ b/packages/core/core-flows/src/order/steps/cancel-orders.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type CompleteOrdersStepInput = { diff --git a/packages/core/core-flows/src/order/steps/cancel-return.ts b/packages/core/core-flows/src/order/steps/cancel-return.ts index 099c9bede2..a316b21e73 100644 --- a/packages/core/core-flows/src/order/steps/cancel-return.ts +++ b/packages/core/core-flows/src/order/steps/cancel-return.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CancelOrderReturnDTO, IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CancelOrderReturnStepInput = CancelOrderReturnDTO diff --git a/packages/core/core-flows/src/order/steps/complete-orders.ts b/packages/core/core-flows/src/order/steps/complete-orders.ts index b1ce009ca8..9dd159c2e5 100644 --- a/packages/core/core-flows/src/order/steps/complete-orders.ts +++ b/packages/core/core-flows/src/order/steps/complete-orders.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type CompleteOrdersStepInput = { diff --git a/packages/core/core-flows/src/order/steps/create-orders.ts b/packages/core/core-flows/src/order/steps/create-orders.ts index b8eede7b8f..6365aff354 100644 --- a/packages/core/core-flows/src/order/steps/create-orders.ts +++ b/packages/core/core-flows/src/order/steps/create-orders.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateOrderDTO, IOrderModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CreateOrdersStepInput = CreateOrderDTO[] diff --git a/packages/core/core-flows/src/order/steps/create-return.ts b/packages/core/core-flows/src/order/steps/create-return.ts index 21e3ed1491..eef5c2b3ec 100644 --- a/packages/core/core-flows/src/order/steps/create-return.ts +++ b/packages/core/core-flows/src/order/steps/create-return.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateOrderReturnDTO, IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CreateReturnStepInput = CreateOrderReturnDTO diff --git a/packages/core/core-flows/src/order/steps/get-item-tax-lines.ts b/packages/core/core-flows/src/order/steps/get-item-tax-lines.ts index 3ecb11bd1e..5a61e22881 100644 --- a/packages/core/core-flows/src/order/steps/get-item-tax-lines.ts +++ b/packages/core/core-flows/src/order/steps/get-item-tax-lines.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ITaxModuleService, ItemTaxLineDTO, @@ -10,7 +9,7 @@ import { TaxableShippingDTO, TaxCalculationContext, } from "@medusajs/types" -import { MedusaError } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/order/steps/receive-return.ts b/packages/core/core-flows/src/order/steps/receive-return.ts index 9bc9f29aed..89f1351389 100644 --- a/packages/core/core-flows/src/order/steps/receive-return.ts +++ b/packages/core/core-flows/src/order/steps/receive-return.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService, ReceiveOrderReturnDTO } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type ReceiveReturnStepInput = ReceiveOrderReturnDTO diff --git a/packages/core/core-flows/src/order/steps/register-fulfillment.ts b/packages/core/core-flows/src/order/steps/register-fulfillment.ts index f1da06618d..cecbf5a689 100644 --- a/packages/core/core-flows/src/order/steps/register-fulfillment.ts +++ b/packages/core/core-flows/src/order/steps/register-fulfillment.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService, RegisterOrderFulfillmentDTO, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type RegisterOrderFulfillmentStepInput = RegisterOrderFulfillmentDTO diff --git a/packages/core/core-flows/src/order/steps/register-shipment.ts b/packages/core/core-flows/src/order/steps/register-shipment.ts index 9d266d4728..648aec5004 100644 --- a/packages/core/core-flows/src/order/steps/register-shipment.ts +++ b/packages/core/core-flows/src/order/steps/register-shipment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService, RegisterOrderShipmentDTO } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type RegisterOrderShipmentStepInput = RegisterOrderShipmentDTO diff --git a/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts b/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts index 40dbbb6844..4d82537df8 100644 --- a/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts +++ b/packages/core/core-flows/src/order/steps/set-tax-lines-for-items.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateLineItemTaxLineDTO, CreateShippingMethodTaxLineDTO, @@ -7,7 +6,7 @@ import { OrderDTO, ShippingTaxLineDTO, } from "@medusajs/types" -import { promiseAll } from "@medusajs/utils" +import { ModuleRegistrationName, promiseAll } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/payment-collection/steps/create-payment-session.ts b/packages/core/core-flows/src/payment-collection/steps/create-payment-session.ts index f2bcf6efda..00f2764584 100644 --- a/packages/core/core-flows/src/payment-collection/steps/create-payment-session.ts +++ b/packages/core/core-flows/src/payment-collection/steps/create-payment-session.ts @@ -1,9 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { BigNumberInput, IPaymentModuleService, PaymentProviderContext, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/payment-collection/steps/delete-payment-sessions.ts b/packages/core/core-flows/src/payment-collection/steps/delete-payment-sessions.ts index e5bfbef331..03413ccbaf 100644 --- a/packages/core/core-flows/src/payment-collection/steps/delete-payment-sessions.ts +++ b/packages/core/core-flows/src/payment-collection/steps/delete-payment-sessions.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPaymentModuleService, Logger, PaymentSessionDTO, } from "@medusajs/types" -import { ContainerRegistrationKeys } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/payment-collection/steps/update-payment-collection.ts b/packages/core/core-flows/src/payment-collection/steps/update-payment-collection.ts index 46cd2bdfc8..d50193aa3d 100644 --- a/packages/core/core-flows/src/payment-collection/steps/update-payment-collection.ts +++ b/packages/core/core-flows/src/payment-collection/steps/update-payment-collection.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterablePaymentCollectionProps, IPaymentModuleService, PaymentCollectionUpdatableFields, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts b/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts index 7c9cd16e3d..f940426fca 100644 --- a/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts +++ b/packages/core/core-flows/src/payment/steps/authorize-payment-session.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPaymentModuleService, Logger, PaymentDTO } from "@medusajs/types" import { ContainerRegistrationKeys, MedusaError, + ModuleRegistrationName, PaymentSessionStatus, } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" diff --git a/packages/core/core-flows/src/payment/steps/cancel-payment.ts b/packages/core/core-flows/src/payment/steps/cancel-payment.ts index a1b34760d8..ca369f44e7 100644 --- a/packages/core/core-flows/src/payment/steps/cancel-payment.ts +++ b/packages/core/core-flows/src/payment/steps/cancel-payment.ts @@ -1,6 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPaymentModuleService, Logger } from "@medusajs/types" -import { ContainerRegistrationKeys, promiseAll } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + promiseAll, +} from "@medusajs/utils" import { createStep } from "@medusajs/workflows-sdk" type StepInput = { diff --git a/packages/core/core-flows/src/payment/steps/capture-payment.ts b/packages/core/core-flows/src/payment/steps/capture-payment.ts index fc1ebbb6d6..c339c615fb 100644 --- a/packages/core/core-flows/src/payment/steps/capture-payment.ts +++ b/packages/core/core-flows/src/payment/steps/capture-payment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { BigNumberInput, IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = { diff --git a/packages/core/core-flows/src/payment/steps/refund-payment.ts b/packages/core/core-flows/src/payment/steps/refund-payment.ts index 7b01f75eac..6d18a4d698 100644 --- a/packages/core/core-flows/src/payment/steps/refund-payment.ts +++ b/packages/core/core-flows/src/payment/steps/refund-payment.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { BigNumberInput, IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type StepInput = { diff --git a/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts b/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts index 273e697b65..c3f3bf5fd4 100644 --- a/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts +++ b/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AddPriceListPricesDTO, CreatePriceListPriceDTO, @@ -6,6 +5,7 @@ import { CreatePriceListPricesWorkflowStepDTO, IPricingModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createPriceListPricesStepId = "create-price-list-prices" diff --git a/packages/core/core-flows/src/price-list/steps/create-price-lists.ts b/packages/core/core-flows/src/price-list/steps/create-price-lists.ts index 6c4d0f7c01..fd6f03f5d1 100644 --- a/packages/core/core-flows/src/price-list/steps/create-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/create-price-lists.ts @@ -1,9 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreatePriceListDTO, CreatePriceListsWorkflowStepDTO, IPricingModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createPriceListsStepId = "create-price-lists" diff --git a/packages/core/core-flows/src/price-list/steps/delete-price-lists.ts b/packages/core/core-flows/src/price-list/steps/delete-price-lists.ts index 923f1d570e..d7ba2138f7 100644 --- a/packages/core/core-flows/src/price-list/steps/delete-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/delete-price-lists.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deletePriceListsStepId = "delete-campaigns" diff --git a/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts b/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts index f8e8999beb..98913cbee7 100644 --- a/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts +++ b/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const getExistingPriceListsPriceIdsStepId = diff --git a/packages/core/core-flows/src/price-list/steps/remove-price-list-prices.ts b/packages/core/core-flows/src/price-list/steps/remove-price-list-prices.ts index 461fe336da..5f80cdf7a2 100644 --- a/packages/core/core-flows/src/price-list/steps/remove-price-list-prices.ts +++ b/packages/core/core-flows/src/price-list/steps/remove-price-list-prices.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const removePriceListPricesStepId = "remove-price-list-prices" diff --git a/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts b/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts index 7b0f83bd80..92999ab80f 100644 --- a/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts +++ b/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts @@ -1,4 +1,3 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService, PriceDTO, @@ -7,7 +6,10 @@ import { UpdatePriceListPriceWorkflowDTO, UpdatePriceListPriceWorkflowStepDTO, } from "@medusajs/types" -import { buildPriceSetPricesForModule } from "@medusajs/utils" +import { + buildPriceSetPricesForModule, + ModuleRegistrationName, +} from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" export const updatePriceListPricesStepId = "update-price-list-prices" diff --git a/packages/core/core-flows/src/price-list/steps/update-price-lists.ts b/packages/core/core-flows/src/price-list/steps/update-price-lists.ts index 257f678950..192f23cbe6 100644 --- a/packages/core/core-flows/src/price-list/steps/update-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/update-price-lists.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService, UpdatePriceListDTO, UpdatePriceListWorkflowInputDTO, } from "@medusajs/types" import { + ModuleRegistrationName, buildPriceListRules, convertItemResponseToUpdateRequest, getSelectsAndRelationsFromObjectArray, diff --git a/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts b/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts index c3474d4299..b38c02b2aa 100644 --- a/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts @@ -1,10 +1,13 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService, PriceListDTO, UpdatePriceListDTO, } from "@medusajs/types" -import { MedusaError, arrayDifference } from "@medusajs/utils" +import { + MedusaError, + ModuleRegistrationName, + arrayDifference, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const validatePriceListsStepId = "validate-price-lists" diff --git a/packages/core/core-flows/src/pricing/steps/create-price-sets.ts b/packages/core/core-flows/src/pricing/steps/create-price-sets.ts index fdbe85880d..ac46ff99de 100644 --- a/packages/core/core-flows/src/pricing/steps/create-price-sets.ts +++ b/packages/core/core-flows/src/pricing/steps/create-price-sets.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreatePriceSetDTO, IPricingModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createPriceSetsStepId = "create-price-sets" export const createPriceSetsStep = createStep( diff --git a/packages/core/core-flows/src/pricing/steps/update-price-sets.ts b/packages/core/core-flows/src/pricing/steps/update-price-sets.ts index ba7ab14814..47f272919e 100644 --- a/packages/core/core-flows/src/pricing/steps/update-price-sets.ts +++ b/packages/core/core-flows/src/pricing/steps/update-price-sets.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPricingModuleService, PricingTypes } from "@medusajs/types" import { - getSelectsAndRelationsFromObjectArray, MedusaError, + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdatePriceSetsStepInput = | { diff --git a/packages/core/core-flows/src/product-category/steps/create-product-categories.ts b/packages/core/core-flows/src/product-category/steps/create-product-categories.ts index c9f76cfa2b..d8b178b22b 100644 --- a/packages/core/core-flows/src/product-category/steps/create-product-categories.ts +++ b/packages/core/core-flows/src/product-category/steps/create-product-categories.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateProductCategoryDTO, IProductModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CreateProductCategoriesStepInput = { diff --git a/packages/core/core-flows/src/product-category/steps/delete-product-categories.ts b/packages/core/core-flows/src/product-category/steps/delete-product-categories.ts index cdd44f5874..172c69ef5a 100644 --- a/packages/core/core-flows/src/product-category/steps/delete-product-categories.ts +++ b/packages/core/core-flows/src/product-category/steps/delete-product-categories.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteProductCategoriesStepId = "delete-product-categories" diff --git a/packages/core/core-flows/src/product-category/steps/update-product-categories.ts b/packages/core/core-flows/src/product-category/steps/update-product-categories.ts index 5da7006b5a..afdbca102f 100644 --- a/packages/core/core-flows/src/product-category/steps/update-product-categories.ts +++ b/packages/core/core-flows/src/product-category/steps/update-product-categories.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableProductCategoryProps, IProductModuleService, UpdateProductCategoryDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateProductCategoriesStepInput = { diff --git a/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts b/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts index 6846280470..f4b396b8d6 100644 --- a/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts +++ b/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, LinkWorkflowInput } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const batchLinkProductsToCollectionStepId = diff --git a/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts b/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts index b7e813a28f..f4a385d525 100644 --- a/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts +++ b/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductCategoryWorkflow } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const batchLinkProductsToCategoryStepId = diff --git a/packages/core/core-flows/src/product/steps/create-collections.ts b/packages/core/core-flows/src/product/steps/create-collections.ts index ae6af82a59..6ea67c2de9 100644 --- a/packages/core/core-flows/src/product/steps/create-collections.ts +++ b/packages/core/core-flows/src/product/steps/create-collections.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createCollectionsStepId = "create-collections" diff --git a/packages/core/core-flows/src/product/steps/create-product-options.ts b/packages/core/core-flows/src/product/steps/create-product-options.ts index a5f90af194..3832959e05 100644 --- a/packages/core/core-flows/src/product/steps/create-product-options.ts +++ b/packages/core/core-flows/src/product/steps/create-product-options.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createProductOptionsStepId = "create-product-options" diff --git a/packages/core/core-flows/src/product/steps/create-product-tags.ts b/packages/core/core-flows/src/product/steps/create-product-tags.ts index c436ef9020..9bbe3d097b 100644 --- a/packages/core/core-flows/src/product/steps/create-product-tags.ts +++ b/packages/core/core-flows/src/product/steps/create-product-tags.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createProductTagsStepId = "create-product-tags" diff --git a/packages/core/core-flows/src/product/steps/create-product-types.ts b/packages/core/core-flows/src/product/steps/create-product-types.ts index a0196266d0..d18e5337b0 100644 --- a/packages/core/core-flows/src/product/steps/create-product-types.ts +++ b/packages/core/core-flows/src/product/steps/create-product-types.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createProductTypesStepId = "create-product-types" diff --git a/packages/core/core-flows/src/product/steps/create-product-variants.ts b/packages/core/core-flows/src/product/steps/create-product-variants.ts index 90bb358965..edeb5a1157 100644 --- a/packages/core/core-flows/src/product/steps/create-product-variants.ts +++ b/packages/core/core-flows/src/product/steps/create-product-variants.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createProductVariantsStepId = "create-product-variants" diff --git a/packages/core/core-flows/src/product/steps/create-products.ts b/packages/core/core-flows/src/product/steps/create-products.ts index 9226d6a73f..13a8ed5839 100644 --- a/packages/core/core-flows/src/product/steps/create-products.ts +++ b/packages/core/core-flows/src/product/steps/create-products.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createProductsStepId = "create-products" diff --git a/packages/core/core-flows/src/product/steps/delete-collections.ts b/packages/core/core-flows/src/product/steps/delete-collections.ts index 2dbb723519..773dde2b3f 100644 --- a/packages/core/core-flows/src/product/steps/delete-collections.ts +++ b/packages/core/core-flows/src/product/steps/delete-collections.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteCollectionsStepId = "delete-collections" diff --git a/packages/core/core-flows/src/product/steps/delete-product-options.ts b/packages/core/core-flows/src/product/steps/delete-product-options.ts index afe33f506b..0817dd48f8 100644 --- a/packages/core/core-flows/src/product/steps/delete-product-options.ts +++ b/packages/core/core-flows/src/product/steps/delete-product-options.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteProductOptionsStepId = "delete-product-options" diff --git a/packages/core/core-flows/src/product/steps/delete-product-tags.ts b/packages/core/core-flows/src/product/steps/delete-product-tags.ts index 08385b6df0..651914fa7a 100644 --- a/packages/core/core-flows/src/product/steps/delete-product-tags.ts +++ b/packages/core/core-flows/src/product/steps/delete-product-tags.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteProductTagsStepId = "delete-product-tags" diff --git a/packages/core/core-flows/src/product/steps/delete-product-types.ts b/packages/core/core-flows/src/product/steps/delete-product-types.ts index c1645f963a..42e73030d9 100644 --- a/packages/core/core-flows/src/product/steps/delete-product-types.ts +++ b/packages/core/core-flows/src/product/steps/delete-product-types.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteProductTypesStepId = "delete-product-types" diff --git a/packages/core/core-flows/src/product/steps/delete-product-variants.ts b/packages/core/core-flows/src/product/steps/delete-product-variants.ts index 29aa181da6..ebcae16812 100644 --- a/packages/core/core-flows/src/product/steps/delete-product-variants.ts +++ b/packages/core/core-flows/src/product/steps/delete-product-variants.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteProductVariantsStepId = "delete-product-variants" diff --git a/packages/core/core-flows/src/product/steps/delete-products.ts b/packages/core/core-flows/src/product/steps/delete-products.ts index 1fc3cc3020..adf7b9da5f 100644 --- a/packages/core/core-flows/src/product/steps/delete-products.ts +++ b/packages/core/core-flows/src/product/steps/delete-products.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteProductsStepId = "delete-products" diff --git a/packages/core/core-flows/src/product/steps/get-products.ts b/packages/core/core-flows/src/product/steps/get-products.ts index b5c494799e..71386c5171 100644 --- a/packages/core/core-flows/src/product/steps/get-products.ts +++ b/packages/core/core-flows/src/product/steps/get-products.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type StepInput = { diff --git a/packages/core/core-flows/src/product/steps/update-collections.ts b/packages/core/core-flows/src/product/steps/update-collections.ts index 13c447d822..183a819dff 100644 --- a/packages/core/core-flows/src/product/steps/update-collections.ts +++ b/packages/core/core-flows/src/product/steps/update-collections.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateCollectionsStepInput = { diff --git a/packages/core/core-flows/src/product/steps/update-product-options.ts b/packages/core/core-flows/src/product/steps/update-product-options.ts index b7ea512351..0227a492a3 100644 --- a/packages/core/core-flows/src/product/steps/update-product-options.ts +++ b/packages/core/core-flows/src/product/steps/update-product-options.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateProductOptionsStepInput = { diff --git a/packages/core/core-flows/src/product/steps/update-product-tags.ts b/packages/core/core-flows/src/product/steps/update-product-tags.ts index c5286d876e..4ec3365602 100644 --- a/packages/core/core-flows/src/product/steps/update-product-tags.ts +++ b/packages/core/core-flows/src/product/steps/update-product-tags.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateProductTagsStepInput = { diff --git a/packages/core/core-flows/src/product/steps/update-product-types.ts b/packages/core/core-flows/src/product/steps/update-product-types.ts index e01f5be8d0..31ef644849 100644 --- a/packages/core/core-flows/src/product/steps/update-product-types.ts +++ b/packages/core/core-flows/src/product/steps/update-product-types.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateProductTypesStepInput = { diff --git a/packages/core/core-flows/src/product/steps/update-product-variants.ts b/packages/core/core-flows/src/product/steps/update-product-variants.ts index 2f21d3677c..10b11d54dd 100644 --- a/packages/core/core-flows/src/product/steps/update-product-variants.ts +++ b/packages/core/core-flows/src/product/steps/update-product-variants.ts @@ -1,7 +1,7 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" import { MedusaError, + ModuleRegistrationName, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" diff --git a/packages/core/core-flows/src/product/steps/update-products.ts b/packages/core/core-flows/src/product/steps/update-products.ts index 41d1368c21..f45bbc3c00 100644 --- a/packages/core/core-flows/src/product/steps/update-products.ts +++ b/packages/core/core-flows/src/product/steps/update-products.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IProductModuleService, ProductTypes } from "@medusajs/types" import { - getSelectsAndRelationsFromObjectArray, MedusaError, + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export type UpdateProductsStepInput = | { diff --git a/packages/core/core-flows/src/promotion/steps/add-campaign-promotions.ts b/packages/core/core-flows/src/promotion/steps/add-campaign-promotions.ts index a175b5b15d..3ce7e6ebee 100644 --- a/packages/core/core-flows/src/promotion/steps/add-campaign-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/add-campaign-promotions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService, LinkWorkflowInput } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, WorkflowData, createStep } from "@medusajs/workflows-sdk" export const addCampaignPromotionsStepId = "add-campaign-promotions" diff --git a/packages/core/core-flows/src/promotion/steps/add-or-remove-campaign-promotions.ts b/packages/core/core-flows/src/promotion/steps/add-or-remove-campaign-promotions.ts index f94495ce5d..bbed397dc6 100644 --- a/packages/core/core-flows/src/promotion/steps/add-or-remove-campaign-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/add-or-remove-campaign-promotions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService, LinkWorkflowInput } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, WorkflowData, createStep } from "@medusajs/workflows-sdk" export const addOrRemoveCampaignPromotionsStepId = diff --git a/packages/core/core-flows/src/promotion/steps/add-rules-to-promotions.ts b/packages/core/core-flows/src/promotion/steps/add-rules-to-promotions.ts index 54cf22f4b6..b202110857 100644 --- a/packages/core/core-flows/src/promotion/steps/add-rules-to-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/add-rules-to-promotions.ts @@ -1,9 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AddPromotionRulesWorkflowDTO, IPromotionModuleService, } from "@medusajs/types" -import { RuleType } from "@medusajs/utils" +import { ModuleRegistrationName, RuleType } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const addRulesToPromotionsStepId = "add-rules-to-promotions" diff --git a/packages/core/core-flows/src/promotion/steps/create-campaigns.ts b/packages/core/core-flows/src/promotion/steps/create-campaigns.ts index b85238d795..3b8a0a32cf 100644 --- a/packages/core/core-flows/src/promotion/steps/create-campaigns.ts +++ b/packages/core/core-flows/src/promotion/steps/create-campaigns.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateCampaignDTO, IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createCampaignsStepId = "create-campaigns" diff --git a/packages/core/core-flows/src/promotion/steps/create-promotions.ts b/packages/core/core-flows/src/promotion/steps/create-promotions.ts index 1f85d93fc0..aad05a3e01 100644 --- a/packages/core/core-flows/src/promotion/steps/create-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/create-promotions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreatePromotionDTO, IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createPromotionsStepId = "create-promotions" diff --git a/packages/core/core-flows/src/promotion/steps/delete-campaigns.ts b/packages/core/core-flows/src/promotion/steps/delete-campaigns.ts index c0b7f20f59..65b6849e0a 100644 --- a/packages/core/core-flows/src/promotion/steps/delete-campaigns.ts +++ b/packages/core/core-flows/src/promotion/steps/delete-campaigns.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteCampaignsStepId = "delete-campaigns" diff --git a/packages/core/core-flows/src/promotion/steps/delete-promotions.ts b/packages/core/core-flows/src/promotion/steps/delete-promotions.ts index af6dd4f0d5..f907049440 100644 --- a/packages/core/core-flows/src/promotion/steps/delete-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/delete-promotions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deletePromotionsStepId = "delete-promotions" diff --git a/packages/core/core-flows/src/promotion/steps/remove-campaign-promotions.ts b/packages/core/core-flows/src/promotion/steps/remove-campaign-promotions.ts index fdcf242b1a..56c365e742 100644 --- a/packages/core/core-flows/src/promotion/steps/remove-campaign-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/remove-campaign-promotions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService, LinkWorkflowInput } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, WorkflowData, createStep } from "@medusajs/workflows-sdk" export const removeCampaignPromotionsStepId = "remove-campaign-promotions" diff --git a/packages/core/core-flows/src/promotion/steps/remove-rules-from-promotions.ts b/packages/core/core-flows/src/promotion/steps/remove-rules-from-promotions.ts index 00369d3fb4..01e9c03cc5 100644 --- a/packages/core/core-flows/src/promotion/steps/remove-rules-from-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/remove-rules-from-promotions.ts @@ -1,11 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreatePromotionRuleDTO, IPromotionModuleService, PromotionRuleDTO, RemovePromotionRulesWorkflowDTO, } from "@medusajs/types" -import { RuleType } from "@medusajs/utils" +import { ModuleRegistrationName, RuleType } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const removeRulesFromPromotionsStepId = "remove-rules-from-promotions" diff --git a/packages/core/core-flows/src/promotion/steps/update-campaigns.ts b/packages/core/core-flows/src/promotion/steps/update-campaigns.ts index 57d2999ca7..f93082934c 100644 --- a/packages/core/core-flows/src/promotion/steps/update-campaigns.ts +++ b/packages/core/core-flows/src/promotion/steps/update-campaigns.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService, UpdateCampaignDTO } from "@medusajs/types" import { + ModuleRegistrationName, convertItemResponseToUpdateRequest, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" diff --git a/packages/core/core-flows/src/promotion/steps/update-promotion-rules.ts b/packages/core/core-flows/src/promotion/steps/update-promotion-rules.ts index 29e4e65b8f..9a851fddf9 100644 --- a/packages/core/core-flows/src/promotion/steps/update-promotion-rules.ts +++ b/packages/core/core-flows/src/promotion/steps/update-promotion-rules.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService, UpdatePromotionRulesWorkflowDTO, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const updatePromotionRulesStepId = "update-promotion-rules" diff --git a/packages/core/core-flows/src/promotion/steps/update-promotions.ts b/packages/core/core-flows/src/promotion/steps/update-promotions.ts index 4f679f910c..c90d646580 100644 --- a/packages/core/core-flows/src/promotion/steps/update-promotions.ts +++ b/packages/core/core-flows/src/promotion/steps/update-promotions.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPromotionModuleService, UpdatePromotionDTO } from "@medusajs/types" import { + ModuleRegistrationName, convertItemResponseToUpdateRequest, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" diff --git a/packages/core/core-flows/src/region/steps/create-regions.ts b/packages/core/core-flows/src/region/steps/create-regions.ts index a755ea386c..07e100e84b 100644 --- a/packages/core/core-flows/src/region/steps/create-regions.ts +++ b/packages/core/core-flows/src/region/steps/create-regions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateRegionDTO, IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createRegionsStepId = "create-regions" diff --git a/packages/core/core-flows/src/region/steps/delete-regions.ts b/packages/core/core-flows/src/region/steps/delete-regions.ts index ae14864600..ea5ac41d70 100644 --- a/packages/core/core-flows/src/region/steps/delete-regions.ts +++ b/packages/core/core-flows/src/region/steps/delete-regions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteRegionsStepId = "delete-regions" diff --git a/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts b/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts index ff28df7505..0fa24d5d56 100644 --- a/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts +++ b/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts @@ -1,15 +1,16 @@ -import { ModuleRegistrationName, RemoteLink } from "@medusajs/modules-sdk" +import { RemoteLink } from "@medusajs/modules-sdk" import { IPaymentModuleService, RemoteQueryFunction } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { - arrayDifference, ContainerRegistrationKeys, LINKS, MedusaError, + ModuleRegistrationName, Modules, + arrayDifference, promiseAll, remoteQueryObjectFromString, } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export interface SetRegionsPaymentProvidersStepInput { input: { diff --git a/packages/core/core-flows/src/region/steps/update-regions.ts b/packages/core/core-flows/src/region/steps/update-regions.ts index 3613cd73ac..3236dc9be9 100644 --- a/packages/core/core-flows/src/region/steps/update-regions.ts +++ b/packages/core/core-flows/src/region/steps/update-regions.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableRegionProps, IRegionModuleService, UpdateRegionDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateRegionsStepInput = { diff --git a/packages/core/core-flows/src/reservation/steps/create-reservations.ts b/packages/core/core-flows/src/reservation/steps/create-reservations.ts index 2770f1a144..2981369699 100644 --- a/packages/core/core-flows/src/reservation/steps/create-reservations.ts +++ b/packages/core/core-flows/src/reservation/steps/create-reservations.ts @@ -1,7 +1,7 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const createReservationsStepId = "create-reservations-step" export const createReservationsStep = createStep( diff --git a/packages/core/core-flows/src/reservation/steps/delete-reservations-by-line-items.ts b/packages/core/core-flows/src/reservation/steps/delete-reservations-by-line-items.ts index 2737a731ce..dd9b46bcbe 100644 --- a/packages/core/core-flows/src/reservation/steps/delete-reservations-by-line-items.ts +++ b/packages/core/core-flows/src/reservation/steps/delete-reservations-by-line-items.ts @@ -1,7 +1,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" export const deleteReservationsByLineItemsStepId = "delete-reservations-by-line-items" diff --git a/packages/core/core-flows/src/reservation/steps/delete-reservations.ts b/packages/core/core-flows/src/reservation/steps/delete-reservations.ts index 374b877ae5..24564232c0 100644 --- a/packages/core/core-flows/src/reservation/steps/delete-reservations.ts +++ b/packages/core/core-flows/src/reservation/steps/delete-reservations.ts @@ -1,7 +1,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" export const deleteReservationsStepId = "delete-reservations" export const deleteReservationsStep = createStep( diff --git a/packages/core/core-flows/src/reservation/steps/update-reservations.ts b/packages/core/core-flows/src/reservation/steps/update-reservations.ts index 80cc1584e7..09b4f31218 100644 --- a/packages/core/core-flows/src/reservation/steps/update-reservations.ts +++ b/packages/core/core-flows/src/reservation/steps/update-reservations.ts @@ -1,11 +1,11 @@ import { IInventoryService, InventoryTypes } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { convertItemResponseToUpdateRequest, getSelectsAndRelationsFromObjectArray, } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const updateReservationsStepId = "update-reservations-step" export const updateReservationsStep = createStep( diff --git a/packages/core/core-flows/src/return-reason/steps/create-return-reasons.ts b/packages/core/core-flows/src/return-reason/steps/create-return-reasons.ts index f73594be1d..d2cf924740 100644 --- a/packages/core/core-flows/src/return-reason/steps/create-return-reasons.ts +++ b/packages/core/core-flows/src/return-reason/steps/create-return-reasons.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateOrderReturnReasonDTO, IOrderModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createReturnReasonsStepId = "create-return-reasons" diff --git a/packages/core/core-flows/src/return-reason/steps/delete-return-reasons.ts b/packages/core/core-flows/src/return-reason/steps/delete-return-reasons.ts index f41ad3a2cb..786ac95524 100644 --- a/packages/core/core-flows/src/return-reason/steps/delete-return-reasons.ts +++ b/packages/core/core-flows/src/return-reason/steps/delete-return-reasons.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" type DeleteReturnReasonStepInput = string[] diff --git a/packages/core/core-flows/src/return-reason/steps/update-return-resons.ts b/packages/core/core-flows/src/return-reason/steps/update-return-resons.ts index 498c203fdc..bbcfe8fb33 100644 --- a/packages/core/core-flows/src/return-reason/steps/update-return-resons.ts +++ b/packages/core/core-flows/src/return-reason/steps/update-return-resons.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableOrderReturnReasonProps, IOrderModuleService, ReturnReasonUpdatableFields, } from "@medusajs/types" import { + ModuleRegistrationName, getSelectsAndRelationsFromObjectArray, promiseAll, } from "@medusajs/utils" diff --git a/packages/core/core-flows/src/sales-channel/steps/create-default-sales-channel.ts b/packages/core/core-flows/src/sales-channel/steps/create-default-sales-channel.ts index b3b911e0ac..8a40f2cd5b 100644 --- a/packages/core/core-flows/src/sales-channel/steps/create-default-sales-channel.ts +++ b/packages/core/core-flows/src/sales-channel/steps/create-default-sales-channel.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateSalesChannelDTO, ISalesChannelModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/sales-channel/steps/create-sales-channels.ts b/packages/core/core-flows/src/sales-channel/steps/create-sales-channels.ts index 0f856d33fc..bbd9143bbc 100644 --- a/packages/core/core-flows/src/sales-channel/steps/create-sales-channels.ts +++ b/packages/core/core-flows/src/sales-channel/steps/create-sales-channels.ts @@ -1,8 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateSalesChannelDTO, ISalesChannelModuleService, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { diff --git a/packages/core/core-flows/src/sales-channel/steps/delete-sales-channels.ts b/packages/core/core-flows/src/sales-channel/steps/delete-sales-channels.ts index 08915cc187..32c57eeb3c 100644 --- a/packages/core/core-flows/src/sales-channel/steps/delete-sales-channels.ts +++ b/packages/core/core-flows/src/sales-channel/steps/delete-sales-channels.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type DeleteSalesChannelsInput = string[] diff --git a/packages/core/core-flows/src/sales-channel/steps/update-sales-channels.ts b/packages/core/core-flows/src/sales-channel/steps/update-sales-channels.ts index 455f03b1eb..e3f42aca3f 100644 --- a/packages/core/core-flows/src/sales-channel/steps/update-sales-channels.ts +++ b/packages/core/core-flows/src/sales-channel/steps/update-sales-channels.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableSalesChannelProps, ISalesChannelModuleService, UpdateSalesChannelDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateSalesChannelsStepInput = { diff --git a/packages/core/core-flows/src/shipping-options/steps/list-shipping-options-for-context.ts b/packages/core/core-flows/src/shipping-options/steps/list-shipping-options-for-context.ts index 878bcea7f2..b348dfe001 100644 --- a/packages/core/core-flows/src/shipping-options/steps/list-shipping-options-for-context.ts +++ b/packages/core/core-flows/src/shipping-options/steps/list-shipping-options-for-context.ts @@ -1,10 +1,10 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FindConfig, IFulfillmentModuleService, ShippingOptionDTO, } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" interface StepInput { context: Record diff --git a/packages/core/core-flows/src/shipping-profile/steps/delete-shipping-profile.ts b/packages/core/core-flows/src/shipping-profile/steps/delete-shipping-profile.ts index 677c9a6b41..29f9fff1ad 100644 --- a/packages/core/core-flows/src/shipping-profile/steps/delete-shipping-profile.ts +++ b/packages/core/core-flows/src/shipping-profile/steps/delete-shipping-profile.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteShippingProfilesStepId = "delete-shipping-profile" diff --git a/packages/core/core-flows/src/stock-location/steps/create-stock-locations.ts b/packages/core/core-flows/src/stock-location/steps/create-stock-locations.ts index 8ae2a2ac9c..305c178ecb 100644 --- a/packages/core/core-flows/src/stock-location/steps/create-stock-locations.ts +++ b/packages/core/core-flows/src/stock-location/steps/create-stock-locations.ts @@ -4,7 +4,7 @@ import { } from "@medusajs/types" import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const createStockLocationsStepId = "create-stock-locations" export const createStockLocations = createStep( diff --git a/packages/core/core-flows/src/stock-location/steps/delete-stock-locations.ts b/packages/core/core-flows/src/stock-location/steps/delete-stock-locations.ts index 89f5b38d41..b81013104f 100644 --- a/packages/core/core-flows/src/stock-location/steps/delete-stock-locations.ts +++ b/packages/core/core-flows/src/stock-location/steps/delete-stock-locations.ts @@ -1,9 +1,6 @@ -import { - DeleteEntityInput, - ModuleRegistrationName, -} from "@medusajs/modules-sdk" +import { DeleteEntityInput } from "@medusajs/modules-sdk" +import { ModuleRegistrationName, Modules } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" -import { Modules } from "@medusajs/utils" export const deleteStockLocationsStepId = "delete-stock-locations-step" export const deleteStockLocationsStep = createStep( diff --git a/packages/core/core-flows/src/stock-location/steps/update-stock-locations.ts b/packages/core/core-flows/src/stock-location/steps/update-stock-locations.ts index 3566a4f538..ebacd66c01 100644 --- a/packages/core/core-flows/src/stock-location/steps/update-stock-locations.ts +++ b/packages/core/core-flows/src/stock-location/steps/update-stock-locations.ts @@ -3,10 +3,10 @@ import { IStockLocationService, UpdateStockLocationInput, } from "@medusajs/types" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" interface StepInput { selector: FilterableStockLocationProps diff --git a/packages/core/core-flows/src/store/steps/create-stores.ts b/packages/core/core-flows/src/store/steps/create-stores.ts index 2d778111ee..82a1aa79bb 100644 --- a/packages/core/core-flows/src/store/steps/create-stores.ts +++ b/packages/core/core-flows/src/store/steps/create-stores.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateStoreDTO, IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type CreateStoresStepInput = { diff --git a/packages/core/core-flows/src/store/steps/delete-stores.ts b/packages/core/core-flows/src/store/steps/delete-stores.ts index ad5053c946..78d8363885 100644 --- a/packages/core/core-flows/src/store/steps/delete-stores.ts +++ b/packages/core/core-flows/src/store/steps/delete-stores.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteStoresStepId = "delete-stores" diff --git a/packages/core/core-flows/src/store/steps/update-stores.ts b/packages/core/core-flows/src/store/steps/update-stores.ts index 76b9dcde90..52dd6fd9d8 100644 --- a/packages/core/core-flows/src/store/steps/update-stores.ts +++ b/packages/core/core-flows/src/store/steps/update-stores.ts @@ -1,10 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableStoreProps, IStoreModuleService, UpdateStoreDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateStoresStepInput = { diff --git a/packages/core/core-flows/src/tax/steps/create-tax-rate-rules.ts b/packages/core/core-flows/src/tax/steps/create-tax-rate-rules.ts index f73e347770..cba622eb23 100644 --- a/packages/core/core-flows/src/tax/steps/create-tax-rate-rules.ts +++ b/packages/core/core-flows/src/tax/steps/create-tax-rate-rules.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateTaxRateRuleDTO, ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createTaxRateRulesStepId = "create-tax-rate-rules" diff --git a/packages/core/core-flows/src/tax/steps/create-tax-rates.ts b/packages/core/core-flows/src/tax/steps/create-tax-rates.ts index 37672f5323..f09287bd1a 100644 --- a/packages/core/core-flows/src/tax/steps/create-tax-rates.ts +++ b/packages/core/core-flows/src/tax/steps/create-tax-rates.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateTaxRateDTO, ITaxModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createTaxRatesStepId = "create-tax-rates" export const createTaxRatesStep = createStep( diff --git a/packages/core/core-flows/src/tax/steps/create-tax-regions.ts b/packages/core/core-flows/src/tax/steps/create-tax-regions.ts index b2e05e81ca..46e1dea111 100644 --- a/packages/core/core-flows/src/tax/steps/create-tax-regions.ts +++ b/packages/core/core-flows/src/tax/steps/create-tax-regions.ts @@ -1,6 +1,6 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateTaxRegionDTO, ITaxModuleService } from "@medusajs/types" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createTaxRegionsStepId = "create-tax-regions" export const createTaxRegionsStep = createStep( diff --git a/packages/core/core-flows/src/tax/steps/delete-tax-rate-rules.ts b/packages/core/core-flows/src/tax/steps/delete-tax-rate-rules.ts index 9003b4bdf7..1dfdb2c21f 100644 --- a/packages/core/core-flows/src/tax/steps/delete-tax-rate-rules.ts +++ b/packages/core/core-flows/src/tax/steps/delete-tax-rate-rules.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteTaxRateRulesStepId = "delete-tax-rate-rules" diff --git a/packages/core/core-flows/src/tax/steps/delete-tax-rates.ts b/packages/core/core-flows/src/tax/steps/delete-tax-rates.ts index e2ec9842c6..9b1a2f0e84 100644 --- a/packages/core/core-flows/src/tax/steps/delete-tax-rates.ts +++ b/packages/core/core-flows/src/tax/steps/delete-tax-rates.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" export const deleteTaxRatesStepId = "delete-tax-rates" diff --git a/packages/core/core-flows/src/tax/steps/delete-tax-regions.ts b/packages/core/core-flows/src/tax/steps/delete-tax-regions.ts index 8e5ea406bb..489237967e 100644 --- a/packages/core/core-flows/src/tax/steps/delete-tax-regions.ts +++ b/packages/core/core-flows/src/tax/steps/delete-tax-regions.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteTaxRegionsStepId = "delete-tax-regions" diff --git a/packages/core/core-flows/src/tax/steps/list-tax-rate-ids.ts b/packages/core/core-flows/src/tax/steps/list-tax-rate-ids.ts index b5b2f9d847..2bf8e612b6 100644 --- a/packages/core/core-flows/src/tax/steps/list-tax-rate-ids.ts +++ b/packages/core/core-flows/src/tax/steps/list-tax-rate-ids.ts @@ -1,6 +1,6 @@ -import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { FilterableTaxRateProps, ITaxModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" type StepInput = { selector: FilterableTaxRateProps diff --git a/packages/core/core-flows/src/tax/steps/list-tax-rate-rule-ids.ts b/packages/core/core-flows/src/tax/steps/list-tax-rate-rule-ids.ts index 8f1fa65c2b..af67e1ab08 100644 --- a/packages/core/core-flows/src/tax/steps/list-tax-rate-rule-ids.ts +++ b/packages/core/core-flows/src/tax/steps/list-tax-rate-rule-ids.ts @@ -1,6 +1,6 @@ -import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { FilterableTaxRateRuleProps, ITaxModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" type StepInput = { selector: FilterableTaxRateRuleProps diff --git a/packages/core/core-flows/src/tax/steps/update-tax-rates.ts b/packages/core/core-flows/src/tax/steps/update-tax-rates.ts index 7fee421263..25b998aa77 100644 --- a/packages/core/core-flows/src/tax/steps/update-tax-rates.ts +++ b/packages/core/core-flows/src/tax/steps/update-tax-rates.ts @@ -1,11 +1,13 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { FilterableTaxRateProps, ITaxModuleService, UpdateTaxRateDTO, } from "@medusajs/types" -import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" +import { + ModuleRegistrationName, + getSelectsAndRelationsFromObjectArray, +} from "@medusajs/utils" +import { StepResponse, createStep } from "@medusajs/workflows-sdk" type UpdateTaxRatesStepInput = { selector: FilterableTaxRateProps diff --git a/packages/core/core-flows/src/tax/workflows/update-tax-rates.ts b/packages/core/core-flows/src/tax/workflows/update-tax-rates.ts index fe5c8ae670..12471f0480 100644 --- a/packages/core/core-flows/src/tax/workflows/update-tax-rates.ts +++ b/packages/core/core-flows/src/tax/workflows/update-tax-rates.ts @@ -4,6 +4,7 @@ import { TaxRateDTO, UpdateTaxRateDTO, } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, WorkflowData, @@ -16,7 +17,6 @@ import { deleteTaxRateRulesStep, updateTaxRatesStep, } from "../steps" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" // import { setTaxRateRulesWorkflow } from "./set-tax-rate-rules" type UpdateTaxRatesStepInput = { diff --git a/packages/core/core-flows/src/user/steps/create-users.ts b/packages/core/core-flows/src/user/steps/create-users.ts index f632ff3ef6..a0c0a8399d 100644 --- a/packages/core/core-flows/src/user/steps/create-users.ts +++ b/packages/core/core-flows/src/user/steps/create-users.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { CreateUserDTO, IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const createUsersStepId = "create-users-step" diff --git a/packages/core/core-flows/src/user/steps/delete-users.ts b/packages/core/core-flows/src/user/steps/delete-users.ts index 50676329ab..1b58233c13 100644 --- a/packages/core/core-flows/src/user/steps/delete-users.ts +++ b/packages/core/core-flows/src/user/steps/delete-users.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const deleteUsersStepId = "delete-users-step" diff --git a/packages/core/core-flows/src/user/steps/update-users.ts b/packages/core/core-flows/src/user/steps/update-users.ts index 978c7819e2..d1c883b881 100644 --- a/packages/core/core-flows/src/user/steps/update-users.ts +++ b/packages/core/core-flows/src/user/steps/update-users.ts @@ -1,5 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IUserModuleService, UpdateUserDTO } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" export const updateUsersStepId = "update-users-step" diff --git a/packages/core/modules-sdk/src/definitions.ts b/packages/core/modules-sdk/src/definitions.ts index 65c55edbd6..1c8aae03f5 100644 --- a/packages/core/modules-sdk/src/definitions.ts +++ b/packages/core/modules-sdk/src/definitions.ts @@ -1,38 +1,11 @@ import { ModuleDefinition } from "@medusajs/types" -import { Modules, upperCaseFirst } from "@medusajs/utils" +import { + ModuleRegistrationName, + Modules, + upperCaseFirst, +} from "@medusajs/utils" import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types" -export enum LinkModuleUtils { - REMOTE_QUERY = "remoteQuery", - REMOTE_LINK = "remoteLink", -} - -export enum ModuleRegistrationName { - AUTH = "authModuleService", - CACHE = "cacheService", - CART = "cartModuleService", - CUSTOMER = "customerModuleService", - EVENT_BUS = "eventBusModuleService", - INVENTORY = "inventoryService", - PAYMENT = "paymentModuleService", - PRICING = "pricingModuleService", - PRODUCT = "productModuleService", - PROMOTION = "promotionModuleService", - SALES_CHANNEL = "salesChannelModuleService", - FULFILLMENT = "fulfillmentModuleService", - STOCK_LOCATION = "stockLocationService", - TAX = "taxModuleService", - USER = "userModuleService", - WORKFLOW_ENGINE = "workflowsModuleService", - REGION = "regionModuleService", - ORDER = "orderModuleService", - API_KEY = "apiKeyModuleService", - STORE = "storeModuleService", - CURRENCY = "currencyModuleService", - FILE = "fileModuleService", - NOTIFICATION = "notificationModuleService", -} - export const MODULE_PACKAGE_NAMES = { [Modules.AUTH]: "@medusajs/auth", [Modules.CACHE]: "@medusajs/cache-inmemory", diff --git a/packages/core/modules-sdk/src/medusa-app.ts b/packages/core/modules-sdk/src/medusa-app.ts index c10487eb3a..c0d5dc4214 100644 --- a/packages/core/modules-sdk/src/medusa-app.ts +++ b/packages/core/modules-sdk/src/medusa-app.ts @@ -18,16 +18,17 @@ import type { } from "@medusajs/types" import { ContainerRegistrationKeys, + ModuleRegistrationName, + Modules, + ModulesSdkUtils, createMedusaContainer, isObject, isString, - Modules, - ModulesSdkUtils, promiseAll, } from "@medusajs/utils" import { asValue } from "awilix" import type { Knex } from "knex" -import { MODULE_PACKAGE_NAMES, ModuleRegistrationName } from "./definitions" +import { MODULE_PACKAGE_NAMES } from "./definitions" import { MedusaModule, RegisterModuleJoinerConfig } from "./medusa-module" import { RemoteLink } from "./remote-link" import { RemoteQuery } from "./remote-query" diff --git a/packages/medusa/src/api/admin/fulfillment-sets/[id]/service-zones/[zone_id]/route.ts b/packages/medusa/src/api/admin/fulfillment-sets/[id]/service-zones/[zone_id]/route.ts index 15b3ed50ad..d5ed9b4fdc 100644 --- a/packages/medusa/src/api/admin/fulfillment-sets/[id]/service-zones/[zone_id]/route.ts +++ b/packages/medusa/src/api/admin/fulfillment-sets/[id]/service-zones/[zone_id]/route.ts @@ -2,7 +2,6 @@ import { deleteServiceZonesWorkflow, updateServiceZonesWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AdminFulfillmentSetResponse, AdminServiceZoneResponse, @@ -11,6 +10,7 @@ import { import { ContainerRegistrationKeys, MedusaError, + ModuleRegistrationName, remoteQueryObjectFromString, } from "@medusajs/utils" import { diff --git a/packages/medusa/src/api/admin/shipping-profiles/[id]/route.ts b/packages/medusa/src/api/admin/shipping-profiles/[id]/route.ts index e77856c5ec..18dea7d895 100644 --- a/packages/medusa/src/api/admin/shipping-profiles/[id]/route.ts +++ b/packages/medusa/src/api/admin/shipping-profiles/[id]/route.ts @@ -2,8 +2,8 @@ import { deleteShippingProfileWorkflow, updateShippingProfilesWorkflow, } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { HttpTypes, IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" import { AuthenticatedMedusaRequest, MedusaResponse, diff --git a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/[transaction_id]/[step_id]/subscribe/route.ts b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/[transaction_id]/[step_id]/subscribe/route.ts index 5df786464d..790fdc1023 100644 --- a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/[transaction_id]/[step_id]/subscribe/route.ts +++ b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/[transaction_id]/[step_id]/subscribe/route.ts @@ -4,7 +4,7 @@ import { MedusaResponse, } from "../../../../../../../types/routing" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const GET = async ( req: AuthenticatedMedusaRequest, diff --git a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/run/route.ts b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/run/route.ts index 8c940f682a..3c84e9dac8 100644 --- a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/run/route.ts +++ b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/run/route.ts @@ -1,12 +1,12 @@ -import { - AuthenticatedMedusaRequest, - MedusaResponse, -} from "../../../../../types/routing" import { IWorkflowEngineService, WorkflowOrchestratorRunDTO, } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" +import { + AuthenticatedMedusaRequest, + MedusaResponse, +} from "../../../../../types/routing" import { AdminCreateWorkflowsRunType } from "../../validators" export const POST = async ( diff --git a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts index 78879ebf09..8cfbcee066 100644 --- a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts +++ b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/failure/route.ts @@ -1,13 +1,13 @@ +import { TransactionHandlerType, isDefined } from "@medusajs/utils" +import { StepResponse } from "@medusajs/workflows-sdk" import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../../types/routing" -import { StepResponse } from "@medusajs/workflows-sdk" -import { TransactionHandlerType, isDefined } from "@medusajs/utils" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { AdminCreateWorkflowsAsyncResponseType } from "../../../validators" import { IWorkflowEngineService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" +import { AdminCreateWorkflowsAsyncResponseType } from "../../../validators" export const POST = async ( req: AuthenticatedMedusaRequest, diff --git a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/success/route.ts b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/success/route.ts index d6fc452a00..141a9a6920 100644 --- a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/success/route.ts +++ b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/steps/success/route.ts @@ -1,13 +1,13 @@ +import { TransactionHandlerType, isDefined } from "@medusajs/utils" +import { StepResponse } from "@medusajs/workflows-sdk" import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../../types/routing" -import { StepResponse } from "@medusajs/workflows-sdk" -import { TransactionHandlerType, isDefined } from "@medusajs/utils" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { AdminCreateWorkflowsAsyncResponseType } from "../../../validators" import { IWorkflowEngineService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" +import { AdminCreateWorkflowsAsyncResponseType } from "../../../validators" export const POST = async ( req: AuthenticatedMedusaRequest, diff --git a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/subscribe/route.ts b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/subscribe/route.ts index ff9af78ac1..6c4f7d2d7d 100644 --- a/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/subscribe/route.ts +++ b/packages/medusa/src/api/admin/workflows-executions/[workflow_id]/subscribe/route.ts @@ -4,7 +4,7 @@ import { MedusaResponse, } from "../../../../../types/routing" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const GET = async ( req: AuthenticatedMedusaRequest, diff --git a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts index 31b5b02cf6..82e44d01c1 100644 --- a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts +++ b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/callback/route.ts @@ -1,12 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AuthenticationInput, - IAuthModuleService, ConfigModule, + IAuthModuleService, } from "@medusajs/types" import { ContainerRegistrationKeys, MedusaError, + ModuleRegistrationName, generateJwtToken, } from "@medusajs/utils" import { MedusaRequest, MedusaResponse } from "../../../../../types/routing" diff --git a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts index 07c9a61dcb..4594936679 100644 --- a/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts +++ b/packages/medusa/src/api/auth/[actor_type]/[auth_provider]/route.ts @@ -1,12 +1,12 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AuthenticationInput, - IAuthModuleService, ConfigModule, + IAuthModuleService, } from "@medusajs/types" import { ContainerRegistrationKeys, MedusaError, + ModuleRegistrationName, generateJwtToken, } from "@medusajs/utils" import { MedusaRequest, MedusaResponse } from "../../../../types/routing" diff --git a/packages/medusa/src/api/hooks/payment/[provider]/route.ts b/packages/medusa/src/api/hooks/payment/[provider]/route.ts index ea3dbc034a..e03cae5c83 100644 --- a/packages/medusa/src/api/hooks/payment/[provider]/route.ts +++ b/packages/medusa/src/api/hooks/payment/[provider]/route.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { PaymentModuleOptions } from "@medusajs/types" -import { PaymentWebhookEvents } from "@medusajs/utils" +import { ModuleRegistrationName, PaymentWebhookEvents } from "@medusajs/utils" import { MedusaRequest, MedusaResponse } from "../../../../types/routing" diff --git a/packages/medusa/src/api/store/shipping-options/route.ts b/packages/medusa/src/api/store/shipping-options/route.ts index e4733f1428..797b855567 100644 --- a/packages/medusa/src/api/store/shipping-options/route.ts +++ b/packages/medusa/src/api/store/shipping-options/route.ts @@ -1,7 +1,6 @@ import { listShippingOptionsForCartWorkflow } from "@medusajs/core-flows" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ICartModuleService } from "@medusajs/types" -import { MedusaError } from "@medusajs/utils" +import { MedusaError, ModuleRegistrationName } from "@medusajs/utils" import { MedusaRequest, MedusaResponse } from "../../../types/routing" export const GET = async (req: MedusaRequest, res: MedusaResponse) => { diff --git a/packages/medusa/src/commands/user.ts b/packages/medusa/src/commands/user.ts index f35920b4ef..859b8ae66b 100644 --- a/packages/medusa/src/commands/user.ts +++ b/packages/medusa/src/commands/user.ts @@ -4,9 +4,9 @@ import "regenerator-runtime/runtime" import express from "express" import { track } from "medusa-telemetry" +import { ModuleRegistrationName } from "@medusajs/utils" import loaders from "../loaders" import Logger from "../loaders/logger" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" export default async function ({ directory, diff --git a/packages/medusa/src/loaders/helpers/subscribers/__mocks__/index.ts b/packages/medusa/src/loaders/helpers/subscribers/__mocks__/index.ts index c526507eeb..2696eb94d6 100644 --- a/packages/medusa/src/loaders/helpers/subscribers/__mocks__/index.ts +++ b/packages/medusa/src/loaders/helpers/subscribers/__mocks__/index.ts @@ -1,4 +1,4 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export const eventBusServiceMock = { subscribe: jest.fn().mockImplementation((...args) => { diff --git a/packages/medusa/src/loaders/helpers/subscribers/index.ts b/packages/medusa/src/loaders/helpers/subscribers/index.ts index 7035917aba..59130263d1 100644 --- a/packages/medusa/src/loaders/helpers/subscribers/index.ts +++ b/packages/medusa/src/loaders/helpers/subscribers/index.ts @@ -1,10 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IEventBusModuleService, MedusaContainer, Subscriber, } from "@medusajs/types" -import { kebabCase } from "@medusajs/utils" +import { ModuleRegistrationName, kebabCase } from "@medusajs/utils" import { readdir } from "fs/promises" import { extname, join, sep } from "path" diff --git a/packages/medusa/src/subscribers/configurable-notifications.ts b/packages/medusa/src/subscribers/configurable-notifications.ts index e1c3541239..c09e4209f0 100644 --- a/packages/medusa/src/subscribers/configurable-notifications.ts +++ b/packages/medusa/src/subscribers/configurable-notifications.ts @@ -1,8 +1,11 @@ import { INotificationModuleService } from "@medusajs/types" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + promiseAll, +} from "@medusajs/utils" import { get } from "lodash" import { SubscriberArgs, SubscriberConfig } from "../types/subscribers" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { ContainerRegistrationKeys, promiseAll } from "@medusajs/utils" type HandlerConfig = { event: string diff --git a/packages/medusa/src/subscribers/payment-webhook.ts b/packages/medusa/src/subscribers/payment-webhook.ts index f96ed8c9f3..5746beaa6d 100644 --- a/packages/medusa/src/subscribers/payment-webhook.ts +++ b/packages/medusa/src/subscribers/payment-webhook.ts @@ -1,6 +1,5 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { IPaymentModuleService, ProviderWebhookPayload } from "@medusajs/types" -import { PaymentWebhookEvents } from "@medusajs/utils" +import { ModuleRegistrationName, PaymentWebhookEvents } from "@medusajs/utils" import { SubscriberArgs, SubscriberConfig } from "../types/subscribers" type SerializedBuffer = { diff --git a/packages/medusa/src/utils/middlewares/authenticate-middleware.ts b/packages/medusa/src/utils/middlewares/authenticate-middleware.ts index 16c9685d7d..cd0d51fbe3 100644 --- a/packages/medusa/src/utils/middlewares/authenticate-middleware.ts +++ b/packages/medusa/src/utils/middlewares/authenticate-middleware.ts @@ -1,6 +1,8 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { ApiKeyDTO, ConfigModule, IApiKeyModuleService } from "@medusajs/types" -import { ContainerRegistrationKeys } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, +} from "@medusajs/utils" import { NextFunction, RequestHandler } from "express" import jwt, { JwtPayload } from "jsonwebtoken" import { diff --git a/packages/modules/currency/src/loaders/initial-data.ts b/packages/modules/currency/src/loaders/initial-data.ts index 8da5115117..3f3a624c65 100644 --- a/packages/modules/currency/src/loaders/initial-data.ts +++ b/packages/modules/currency/src/loaders/initial-data.ts @@ -1,6 +1,9 @@ -import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types" -import { ContainerRegistrationKeys, defaultCurrencies } from "@medusajs/utils" +import { + ContainerRegistrationKeys, + ModuleRegistrationName, + defaultCurrencies, +} from "@medusajs/utils" import { Currency } from "@models" export default async ({ diff --git a/packages/modules/link-modules/src/initialize/index.ts b/packages/modules/link-modules/src/initialize/index.ts index 63c500bb30..a3ae4ff458 100644 --- a/packages/modules/link-modules/src/initialize/index.ts +++ b/packages/modules/link-modules/src/initialize/index.ts @@ -3,7 +3,6 @@ import { MedusaModule, MODULE_RESOURCE_TYPE, MODULE_SCOPE, - ModuleRegistrationName, } from "@medusajs/modules-sdk" import { ExternalModuleDeclaration, @@ -19,6 +18,7 @@ import { arrayDifference, ContainerRegistrationKeys, lowerCaseFirst, + ModuleRegistrationName, simpleHash, toPascalCase, } from "@medusajs/utils" diff --git a/www/apps/book/app/advanced-development/api-routes/protected-routes/page.mdx b/www/apps/book/app/advanced-development/api-routes/protected-routes/page.mdx index 8e962b7d60..09a87bdd04 100644 --- a/www/apps/book/app/advanced-development/api-routes/protected-routes/page.mdx +++ b/www/apps/book/app/advanced-development/api-routes/protected-routes/page.mdx @@ -30,15 +30,9 @@ To disable the authentication guard on custom routes under the `/admin` or `/sto For example: ```ts title="src/api/store/customers/me/custom/route.ts" highlights={[["15"]]} apiTesting testApiUrl="http://localhost:9000/store/customers/me/custom" testApiMethod="GET" -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/medusa" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" -export const GET = async ( - req: MedusaRequest, - res: MedusaResponse -) => { +export const GET = async (req: MedusaRequest, res: MedusaResponse) => { res.json({ message: "Hello", }) @@ -62,15 +56,16 @@ import type { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/medusa" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import { ICustomerModuleService } from "@medusajs/types" export const GET = async ( req: AuthenticatedMedusaRequest, res: MedusaResponse ) => { - const customerModuleService: ICustomerModuleService = - req.scope.resolve(ModuleRegistrationName.CUSTOMER) + const customerModuleService: ICustomerModuleService = req.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) const customer = await customerModuleService.retrieve( req.auth_context.actor_id @@ -95,7 +90,7 @@ import type { AuthenticatedMedusaRequest, MedusaResponse, } from "@medusajs/medusa" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import { IUserModuleService } from "@medusajs/types" export const GET = async ( @@ -106,9 +101,7 @@ export const GET = async ( ModuleRegistrationName.USER ) - const user = await userService.retrieve( - req.auth_context.actor_id - ) + const user = await userService.retrieve(req.auth_context.actor_id) // ... } @@ -125,29 +118,30 @@ To protect custom API Routes that don’t start with `/store/customers/me` or `/ For example: export const highlights = [ - ["11", "authenticate", "Only authenticated admin users can access routes starting with `/custom/admin`"], - ["17", "authenticate", "Only authenticated customers can access routes starting with `/custom/customers`"] + [ + "11", + "authenticate", + "Only authenticated admin users can access routes starting with `/custom/admin`", + ], + [ + "17", + "authenticate", + "Only authenticated customers can access routes starting with `/custom/customers`", + ], ] ```ts title="src/api/middlewares.ts" highlights={highlights} -import { - MiddlewaresConfig, - authenticate, -} from "@medusajs/medusa" +import { MiddlewaresConfig, authenticate } from "@medusajs/medusa" export const config: MiddlewaresConfig = { routes: [ { matcher: "/custom/admin*", - middlewares: [ - authenticate("user", ["session", "bearer", "api-key"]), - ], + middlewares: [authenticate("user", ["session", "bearer", "api-key"])], }, { matcher: "/custom/customer*", - middlewares: [ - authenticate("customer", ["session", "bearer"]), - ], + middlewares: [authenticate("customer", ["session", "bearer"])], }, ], } @@ -158,5 +152,5 @@ The `authenticate` middleware function accepts three parameters: 1. The type of user authenticating. Use `user` for authenticating admin users, and `customer` for authenticating customers. 2. An array of the types of authentication methods allowed. Both `user` and `customer` scopes support `session` and `bearer`. The `admin` scope also supports the `api-key` authentication method. 3. An optional object of options having the following properties: - 1. `allowUnauthenticated`: (default: `false`) A boolean indicating whether authentication is required. For example, you may have an API route where you want to access the logged-in customer if available, but guest customers can still access it too. In that case, enable the `allowUnauthenticated` option. - 2. `allowUnregistered`: (default: `false`) A boolean indicating whether new users can be authenticated. + 1. `allowUnauthenticated`: (default: `false`) A boolean indicating whether authentication is required. For example, you may have an API route where you want to access the logged-in customer if available, but guest customers can still access it too. In that case, enable the `allowUnauthenticated` option. + 2. `allowUnregistered`: (default: `false`) A boolean indicating whether new users can be authenticated. diff --git a/www/apps/book/app/advanced-development/custom-cli-scripts/page.mdx b/www/apps/book/app/advanced-development/custom-cli-scripts/page.mdx index 3e134c4595..825336d9b4 100644 --- a/www/apps/book/app/advanced-development/custom-cli-scripts/page.mdx +++ b/www/apps/book/app/advanced-development/custom-cli-scripts/page.mdx @@ -19,17 +19,13 @@ To create a custom CLI script, create a TypeScript or JavaScript file under the For example, create the file `src/scripts/my-script.ts` with the following content: ```ts title="src/scripts/my-script.ts" -import { - ExecArgs, - IProductModuleService, -} from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ExecArgs, IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" -export default async function myScript({ - container, -}: ExecArgs) { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) +export default async function myScript({ container }: ExecArgs) { + const productModuleService: IProductModuleService = container.resolve( + ModuleRegistrationName.PRODUCT + ) const [, count] = await productModuleService.listAndCount() @@ -60,9 +56,7 @@ For example: ```ts import { ExecArgs } from "@medusajs/types" -export default async function myScript({ - args, -}: ExecArgs) { +export default async function myScript({ args }: ExecArgs) { console.log(`The arguments you passed: ${args}`) } ``` diff --git a/www/apps/book/app/advanced-development/loaders/outside-modules/page.mdx b/www/apps/book/app/advanced-development/loaders/outside-modules/page.mdx index 35fc6a5390..18e8162228 100644 --- a/www/apps/book/app/advanced-development/loaders/outside-modules/page.mdx +++ b/www/apps/book/app/advanced-development/loaders/outside-modules/page.mdx @@ -22,9 +22,7 @@ For example, create the file `src/loaders/hello-world.ts` with the following con ```ts title="src/loaders/hello-world.ts" export default function () { - console.log( - "[HELLO LOADER] Just started the Medusa application!" - ) + console.log("[HELLO LOADER] Just started the Medusa application!") } ``` @@ -51,11 +49,12 @@ For example: ```ts title="src/loaders/hello-world.ts" collapsibleLines="1-5" expandButtonLabel="Show Imports" import { MedusaContainer } from "@medusajs/medusa" import { IProductModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export default async function (container: MedusaContainer) { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) + const productModuleService: IProductModuleService = container.resolve( + ModuleRegistrationName.PRODUCT + ) const [, count] = await productModuleService.listAndCount() @@ -78,13 +77,11 @@ import { MedusaContainer } from "@medusajs/medusa" import { ConfigModule } from "@medusajs/types" export default async function ( - container: MedusaContainer, + container: MedusaContainer, config: ConfigModule ) { - console.log(`You have ${ - Object.values(config.modules || {}).length - } modules!`) + console.log(`You have ${Object.values(config.modules || {}).length} modules!`) } ``` -This loader logs on application start-up the number of modules defined in your Medusa configurations. \ No newline at end of file +This loader logs on application start-up the number of modules defined in your Medusa configurations. diff --git a/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx b/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx index 590194e30b..a209c03662 100644 --- a/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx @@ -26,7 +26,6 @@ In the file, add the type of the expected workflow input: import { UpdateProductDTO } from "@medusajs/types" export type UpdateProductAndErpWorkflowInput = UpdateProductDTO - ``` The expected input is the data to update in the product along with the product’s ID. @@ -41,18 +40,23 @@ Create the file `src/workflows/update-product-erp/steps/update-product.ts` with export const updateProductHighlights = [ ["13", "resolve", "Resolve the `ProductService` from the Medusa container."], - ["16", "previousProductData", "Retrieve the `previousProductData` to pass it to the compensation function."], + [ + "16", + "previousProductData", + "Retrieve the `previousProductData` to pass it to the compensation function.", + ], ["19", "", "Update the product."], - ["39", "", "Revert the product’s data using the `previousProductData` passed from the step to the compensation function."] + [ + "39", + "", + "Revert the product’s data using the `previousProductData` passed from the step to the compensation function.", + ], ] ```ts title="src/workflows/update-product-erp/steps/update-product.ts" highlights={updateProductHighlights} collapsibleLines="1-9" expandButtonLabel="Show Imports" -import { - createStep, - StepResponse, -} from "@medusajs/workflows-sdk" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { IProductModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" import { UpdateProductAndErpWorkflowInput } from ".." const updateProduct = createStep( @@ -62,8 +66,7 @@ const updateProduct = createStep( context.container.resolve(ModuleRegistrationName.PRODUCT) const { id } = input - const previousProductData = - await productModuleService.retrieve(id) + const previousProductData = await productModuleService.retrieve(id) const product = await productModuleService.update(id, input) @@ -77,37 +80,28 @@ const updateProduct = createStep( const productModuleService: IProductModuleService = context.container.resolve(ModuleRegistrationName.PRODUCT) - const { - id, - type, - options, - variants, - ...previousData - } = previousProductData + const { id, type, options, variants, ...previousData } = previousProductData - await productModuleService.update( - id, - { - ...previousData, - variants: variants.map((variant) => { - const variantOptions = {} + await productModuleService.update(id, { + ...previousData, + variants: variants.map((variant) => { + const variantOptions = {} - variant.options.forEach((option) => { - variantOptions[option.option.title] = option.value - }) + variant.options.forEach((option) => { + variantOptions[option.option.title] = option.value + }) - return { - ...variant, - options: variantOptions, - } - }), - options: options.map((option) => ({ - ...option, - values: option.values.map((value) => value.value), - })), - type_id: type.id, - } - ) + return { + ...variant, + options: variantOptions, + } + }), + options: options.map((option) => ({ + ...option, + values: option.values.map((value) => value.value), + })), + type_id: type.id, + }) } ) @@ -139,17 +133,30 @@ The `ErpModuleService` used is assumed to be created in a module. Create the file `src/workflows/update-product-erp/steps/update-erp.ts` with the following content: export const updateErpHighlights = [ - ["12", "resolve", "Resolve the `erpModuleService` from the Medusa container."], - ["17", "previousErpData", "Retrieve the `previousErpData` to pass it to the compensation function."], - ["21", "updateProductErpData", "Update the product’s ERP data and return the data from the ERP system."], - ["37", "updateProductErpData", "Revert the product's data in the ERP system to its previous state using the `previousErpData`."] + [ + "12", + "resolve", + "Resolve the `erpModuleService` from the Medusa container.", + ], + [ + "17", + "previousErpData", + "Retrieve the `previousErpData` to pass it to the compensation function.", + ], + [ + "21", + "updateProductErpData", + "Update the product’s ERP data and return the data from the ERP system.", + ], + [ + "37", + "updateProductErpData", + "Revert the product's data in the ERP system to its previous state using the `previousErpData`.", + ], ] ```ts title="src/workflows/update-product-erp/steps/update-erp.ts" highlights={updateErpHighlights} collapsibleLines="1-8" expandButtonLabel="Show Imports" -import { - createStep, - StepResponse, -} from "@medusajs/workflows-sdk" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" import { UpdateProductAndErpWorkflowInput } from ".." import ErpModuleService from "../../../modules/erp/service" @@ -162,14 +169,12 @@ const updateErp = createStep( const { id, ...updatedData } = input // get previous ERP data - const previousErpData = - await erpModuleService.retrieveProductErpDetails(id) + const previousErpData = await erpModuleService.retrieveProductErpDetails(id) - const updatedErpData = - await erpModuleService.updateProductErpData( - id, - updatedData - ) + const updatedErpData = await erpModuleService.updateProductErpData( + id, + updatedData + ) return new StepResponse(updatedErpData, { // pass to compensation function @@ -179,13 +184,9 @@ const updateErp = createStep( }, // compensation function async ({ previousErpData, productId }, context) => { - const erpService: ErpModuleService = - context.container.resolve("erpService") + const erpService: ErpModuleService = context.container.resolve("erpService") - await erpService.updateProductErpData( - productId, - previousErpData - ) + await erpService.updateProductErpData(productId, previousErpData) } ) @@ -253,10 +254,7 @@ import updateProductAndErpWorkflow, { UpdateProductAndErpWorkflowInput, } from "../../../../../workflows/update-product-erp" -type ProductErpReq = Omit< - UpdateProductAndErpWorkflowInput, - "id" -> +type ProductErpReq = Omit export const POST = async ( req: MedusaRequest, @@ -268,9 +266,7 @@ export const POST = async ( ...req.body, } - const { result } = await updateProductAndErpWorkflow( - req.scope - ).run({ + const { result } = await updateProductAndErpWorkflow(req.scope).run({ input: productData, }) @@ -280,4 +276,4 @@ export const POST = async ( In this `POST` API route, you retrieve the product’s ID from the path parameter and the data to update from the request body. You then execute the workflow by passing it the retrieved data as an input. -The route returns the result of the workflow, which is an object holding both the update product’s details and the ERP details. \ No newline at end of file +The route returns the result of the workflow, which is an object holding both the update product’s details and the ERP details. 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 1cbda61c16..613f25e61a 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 @@ -23,10 +23,7 @@ A workflow is considered long-running if at least one step has its `async` confi For example, consider the following workflow and steps: ```ts title="src/workflows/hello-world.ts" highlights={[["13"]]} collapsibleLines="1-10" expandButtonLabel="Show More" -import { - createStep, - createWorkflow, -} from "@medusajs/workflows-sdk" +import { createStep, createWorkflow } from "@medusajs/workflows-sdk" const step1 = createStep("step-1", async () => { // ... @@ -50,19 +47,18 @@ type WorkflowOutput = { message: string } -const myWorkflow = createWorkflow< - {}, - WorkflowOutput ->({ - name: "hello-world", -}, function () { - step1() - step2() - step3() -}) +const myWorkflow = createWorkflow<{}, WorkflowOutput>( + { + name: "hello-world", + }, + function () { + step1() + step2() + step3() + } +) export default myWorkflow - ``` The second step has in its configuration object `async` set to true. This indicates that this step is an asynchronous step. @@ -89,26 +85,15 @@ export const highlights = [ ] ```ts title="src/api/store/workflows/route.ts" highlights={highlights} collapsibleLines="1-11" expandButtonLabel="Show Imports" -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/medusa" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" import myWorkflow from "../../../workflows/hello-world" -import { - IWorkflowEngineService, -} from "@medusajs/workflows-sdk" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { IWorkflowEngineService } from "@medusajs/workflows-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" -export async function GET( - req: MedusaRequest, - res: MedusaResponse -) { - const { transaction, result } = await myWorkflow(req.scope) - .run() +export async function GET(req: MedusaRequest, res: MedusaResponse) { + const { transaction, result } = await myWorkflow(req.scope).run() - const workflowEngine = req.scope.resolve< - IWorkflowEngineService - >( + const workflowEngine = req.scope.resolve( ModuleRegistrationName.WORKFLOW_ENGINE ) @@ -137,18 +122,20 @@ The `subscribe` method accepts an object having three properties: { name: "workflowId", type: "`string`", - description: "The name of the workflow." + description: "The name of the workflow.", }, { name: "transactionId", type: "`string`", - description: "The ID of the workflow exection's transaction. The transaction's details are returned in the response of the workflow execution." + description: + "The ID of the workflow exection's transaction. The transaction's details are returned in the response of the workflow execution.", }, { name: "subscriber", type: "`string`", - description: "The function executed when the workflow execution's status changes. The function receives a data object. It has an `eventType` property, which you use to check the status of the workflow execution." - } + description: + "The function executed when the workflow execution's status changes. The function receives a data object. It has an `eventType` property, which you use to check the status of the workflow execution.", + }, ]} sectionTitle="Access Long-Running Workflow Status and Result" /> diff --git a/www/apps/book/app/basics/commerce-modules/page.mdx b/www/apps/book/app/basics/commerce-modules/page.mdx index cec0860651..53e47bb7ac 100644 --- a/www/apps/book/app/basics/commerce-modules/page.mdx +++ b/www/apps/book/app/basics/commerce-modules/page.mdx @@ -23,19 +23,14 @@ Similarly to your custom module, a commerce module's main service is registered For example, you saw this code snippet in the [Medusa container chapter](../medusa-container/page.mdx): ```ts highlights={[["13"]]} -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/medusa" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" import { IProductModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" -export const GET = async ( - req: MedusaRequest, - res: MedusaResponse -) => { - const productModuleService: IProductModuleService = - req.scope.resolve(ModuleRegistrationName.PRODUCT) +export const GET = async (req: MedusaRequest, res: MedusaResponse) => { + const productModuleService: IProductModuleService = req.scope.resolve( + ModuleRegistrationName.PRODUCT + ) const [, count] = await productModuleService.listAndCount() @@ -51,4 +46,4 @@ When you resolve the `ModuleRegistrationName.PRODUCT` (or `productModuleService` To resolve the main service of any commerce module, use the registration name defined in the `ModuleRegistrationName` enum imported from `@medusajs/modules-sdk`. - \ No newline at end of file + diff --git a/www/apps/book/app/basics/events-and-subscribers/page.mdx b/www/apps/book/app/basics/events-and-subscribers/page.mdx index 44c70d4753..dd22178390 100644 --- a/www/apps/book/app/basics/events-and-subscribers/page.mdx +++ b/www/apps/book/app/basics/events-and-subscribers/page.mdx @@ -43,7 +43,7 @@ The above subscriber listens to the `product.created` event. Whenever the event {/* TODO add when we have the admin dashboard to use with V2 for easy testing. */} -{/* ### Test Subscriber +{/\* ### Test Subscriber To test the subscriber, start the Medusa application: @@ -58,7 +58,7 @@ info: Processing product.created which has 1 subscribers A product is created ``` -The first message indicates that the `product.created` event was emitted, and the second one is the message logged from the subscriber. */} +The first message indicates that the `product.created` event was emitted, and the second one is the message logged from the subscriber. \*/} --- @@ -83,23 +83,25 @@ For example: export const highlights = [ ["10", "container", "Recieve the Medusa Container in the object parameter."], ["13", "resolve", "Resolve the Product Module's main service."], - ["13", "ModuleRegistrationName.PRODUCT", "The resource registration name imported from `@medusajs/modules-sdk`."] + [ + "13", + "ModuleRegistrationName.PRODUCT", + "The resource registration name imported from `@medusajs/modules-sdk`.", + ], ] ```ts title="src/subscribers/product-created.ts" highlights={highlights} -import { - SubscriberArgs, - type SubscriberConfig, -} from "@medusajs/medusa" +import { SubscriberArgs, type SubscriberConfig } from "@medusajs/medusa" import { IProductModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" export default async function productCreateHandler({ data, container, }: SubscriberArgs>) { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) + const productModuleService: IProductModuleService = container.resolve( + ModuleRegistrationName.PRODUCT + ) const product = await productModuleService.retrieve(data.id) diff --git a/www/apps/book/app/basics/medusa-container/page.mdx b/www/apps/book/app/basics/medusa-container/page.mdx index ae33f42f62..00fe1ac80b 100644 --- a/www/apps/book/app/basics/medusa-container/page.mdx +++ b/www/apps/book/app/basics/medusa-container/page.mdx @@ -16,23 +16,22 @@ For example, in a custom API route you can resolve any service registered in the export const highlights = [ ["13", "resolve", "Resolve the Product Module's main service."], - ["13", "ModuleRegistrationName.PRODUCT", "The resource registration name imported from `@medusajs/modules-sdk`."] + [ + "13", + "ModuleRegistrationName.PRODUCT", + "The resource registration name imported from `@medusajs/modules-sdk`.", + ], ] ```ts highlights={highlights} -import type { - MedusaRequest, - MedusaResponse, -} from "@medusajs/medusa" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" import { IProductModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" -export const GET = async ( - req: MedusaRequest, - res: MedusaResponse -) => { - const productModuleService: IProductModuleService = - req.scope.resolve(ModuleRegistrationName.PRODUCT) +export const GET = async (req: MedusaRequest, res: MedusaResponse) => { + const productModuleService: IProductModuleService = req.scope.resolve( + ModuleRegistrationName.PRODUCT + ) const [, count] = await productModuleService.listAndCount() diff --git a/www/apps/book/app/basics/workflows/page.mdx b/www/apps/book/app/basics/workflows/page.mdx index 28080c26bb..be86a24d90 100644 --- a/www/apps/book/app/basics/workflows/page.mdx +++ b/www/apps/book/app/basics/workflows/page.mdx @@ -25,10 +25,7 @@ A workflow is made of a series of steps. A step is created using the `createStep Create the file `src/workflows/hello-world.ts` with the following content: ```ts title="src/workflows/hello-world.ts" -import { - createStep, - StepResponse, -} from "@medusajs/workflows-sdk" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" const step1 = createStep("step-1", async () => { return new StepResponse(`Hello from step one!`) @@ -44,12 +41,9 @@ type WorkflowInput = { name: string } -const step2 = createStep( - "step-2", - async ({ name }: WorkflowInput) => { - return new StepResponse(`Hello ${name} from step two!`) - } -) +const step2 = createStep("step-2", async ({ name }: WorkflowInput) => { + return new StepResponse(`Hello ${name} from step two!`) +}) ``` ### 2. Create a Workflow @@ -68,21 +62,20 @@ type WorkflowOutput = { message: string } -const myWorkflow = createWorkflow< - WorkflowInput, - WorkflowOutput ->("hello-world", function (input) { - const str1 = step1() - // to pass input - const str2 = step2(input) +const myWorkflow = createWorkflow( + "hello-world", + function (input) { + const str1 = step1() + // to pass input + const str2 = step2(input) - return { - message: str1, + return { + message: str1, + } } -}) +) export default myWorkflow - ``` This creates a `hello-world` workflow. When you create a workflow, it’s constructed but not executed yet. @@ -226,7 +219,11 @@ For example: export const highlights = [ ["15", "resolve", "Resolve the Product Module's main service."], - ["15", "ModuleRegistrationName.PRODUCT", "The resource registration name imported from `@medusajs/modules-sdk`."] + [ + "15", + "ModuleRegistrationName.PRODUCT", + "The resource registration name imported from `@medusajs/modules-sdk`.", + ], ] ```ts title="src/workflows/product-count.ts" highlights={highlights} collapsibleLines="1-12" expandButtonLabel="Show Imports" @@ -236,18 +233,17 @@ import { createWorkflow, } from "@medusajs/workflows-sdk" import { IProductModuleService } from "@medusajs/types" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { ModuleRegistrationName } from "@medusajs/utils" type WorkflowOutput = { count: number } const step1 = createStep("step-1", async (_, context) => { - const productModuleService: IProductModuleService = - context.container.resolve(ModuleRegistrationName.PRODUCT) - return new StepResponse( - (await productModuleService.listAndCount())[1] + const productModuleService: IProductModuleService = context.container.resolve( + ModuleRegistrationName.PRODUCT ) + return new StepResponse((await productModuleService.listAndCount())[1]) }) const myWorkflow = createWorkflow( @@ -264,4 +260,4 @@ const myWorkflow = createWorkflow( export default myWorkflow ``` -In the step, you resolve the Product Module's main service and use it to retrieve the product count. \ No newline at end of file +In the step, you resolve the Product Module's main service and use it to retrieve the product count. diff --git a/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx b/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx index 3c6fa423b4..49a1f13a2f 100644 --- a/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx @@ -15,17 +15,26 @@ In your resource, such as a subscriber, resolve the Notification Module's main s export const highlights = [ ["12", "notificationModuleService", "Resolve the Notification Module."], ["17", "create", "Create the notification to be sent."], - ["19", '"email"', "Use the module provider defined for the `email` channel to send an email."], - ["20", '"product-created"', "The ID of the template defined in the third-party service, such as SendGrid."], - ["21", "data", "The data to pass to the template defined in the third-party service."] + [ + "19", + '"email"', + "Use the module provider defined for the `email` channel to send an email.", + ], + [ + "20", + '"product-created"', + "The ID of the template defined in the third-party service, such as SendGrid.", + ], + [ + "21", + "data", + "The data to pass to the template defined in the third-party service.", + ], ] ```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports" -import type { - SubscriberArgs, - SubscriberConfig, -} from "@medusajs/medusa" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa" +import { ModuleRegistrationName } from "@medusajs/utils" import { INotificationModuleService } from "@medusajs/types" export default async function productCreateHandler({ @@ -33,9 +42,7 @@ export default async function productCreateHandler({ container, }: SubscriberArgs<{ id: string }>) { const notificationModuleService: INotificationModuleService = - container.resolve( - ModuleRegistrationName.NOTIFICATION - ) + container.resolve(ModuleRegistrationName.NOTIFICATION) await notificationModuleService.create({ to: "shahednasser@gmail.com", @@ -57,26 +64,29 @@ The `create` method accepts an object or an array of objects having the followin { name: "to", type: "`string`", - description: "The destination to send the notification to. When sending an email, it'll be the email address. When sending an SMS, it'll be the phone number.", + description: + "The destination to send the notification to. When sending an email, it'll be the email address. When sending an SMS, it'll be the phone number.", optional: false, }, { name: "channel", type: "`string`", - description: "The channel to send the notification through. For example, `email` or `sms`. The module provider defined for that channel will be used to send the notification.", - optional: false + description: + "The channel to send the notification through. For example, `email` or `sms`. The module provider defined for that channel will be used to send the notification.", + optional: false, }, { name: "template", type: "`string`", - description: "The ID of the template used for the notification. This is useful for providers like SendGrid, where you define templates within SendGrid and use their IDs here.", - optional: false + description: + "The ID of the template used for the notification. This is useful for providers like SendGrid, where you define templates within SendGrid and use their IDs here.", + optional: false, }, { name: "data", type: "`Record`", - description: "The data to pass along to the template, if necessary." - } + description: "The data to pass along to the template, if necessary.", + }, ]} sectionTitle="Use the Create Method" /> diff --git a/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx b/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx index ae8a4c52b5..28df88b26e 100644 --- a/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx +++ b/www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx @@ -86,40 +86,19 @@ SENDGRID_FROM= + `channels` - - `channels` - - - - - The channels this notification module is used to send notifications for. Only one provider can be defined for a channel. - + The channels this notification module is used to send notifications for. + Only one provider can be defined for a channel. - - - `api_key` - - - - - The SendGrid API key. - - + `api_key` + The SendGrid API key. - - - `from` - - - - - The SendGrid from email. - - + `from` + The SendGrid from email. @@ -141,17 +120,18 @@ To test the module out, create a simple subscriber at `src/subscribers/product-c export const highlights = [ ["12", "notificationModuleService", "Resolve the Notification Module."], ["17", "create", "Create the notification to be sent."], - ["19", '"email"', "By specifying the `email` channel, SendGrid will be used to send the notification."], + [ + "19", + '"email"', + "By specifying the `email` channel, SendGrid will be used to send the notification.", + ], ["20", '"product-created"', "The ID of the template defined in SendGrid."], - ["21", "data", "The data to pass to the template defined in SendGrid."] + ["21", "data", "The data to pass to the template defined in SendGrid."], ] ```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports" -import type { - SubscriberArgs, - SubscriberConfig, -} from "@medusajs/medusa" -import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa" +import { ModuleRegistrationName } from "@medusajs/utils" import { INotificationModuleService } from "@medusajs/types" export default async function productCreateHandler({ @@ -159,9 +139,7 @@ export default async function productCreateHandler({ container, }: SubscriberArgs<{ id: string }>) { const notificationModuleService: INotificationModuleService = - container.resolve( - ModuleRegistrationName.NOTIFICATION - ) + container.resolve(ModuleRegistrationName.NOTIFICATION) await notificationModuleService.create({ to: "test@gmail.com", @@ -178,7 +156,7 @@ export const config: SubscriberConfig = { In this subscriber: -- Resolve the Notification Module's main service. +- Resolve the Notification Module's main service. - Use the `create` method of the main service to create a notification to be sent to the specified email. - By specifying the `email` channel, the SendGrid Notification Module Provider is used to send the notification. - The `template` property of the `create` method's parameter specifies the ID of the template defined in SendGrid. diff --git a/www/apps/resources/app/commerce-modules/api-key/examples/page.mdx b/www/apps/resources/app/commerce-modules/api-key/examples/page.mdx index 1fee0c10fc..2c21870a0d 100644 --- a/www/apps/resources/app/commerce-modules/api-key/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/api-key/examples/page.mdx @@ -13,54 +13,50 @@ In this guide, you’ll find common examples of how you can use the API Key Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const apiKeyModuleService: IApiKeyModuleService = - request.scope.resolve(ModuleRegistrationName.API_KEY) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve( + ModuleRegistrationName.API_KEY + ) - const apiKey = await apiKeyModuleService.createApiKeys({ - title: "Publishable API key", - type: "publishable", - created_by: "user_123", - }) + const apiKey = await apiKeyModuleService.createApiKeys({ + title: "Publishable API key", + type: "publishable", + created_by: "user_123", + }) - res.json({ - api_key: apiKey, - }) - } - ``` + res.json({ + api_key: apiKey, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeApiKeyModule, - } from "@medusajs/api-key" +import { initialize as initializeApiKeyModule } from "@medusajs/api-key" - export async function POST(request: Request) { - const apiKeyModuleService = await initializeApiKeyModule() +export async function POST(request: Request) { + const apiKeyModuleService = await initializeApiKeyModule() - const apiKey = await apiKeyModuleService.createApiKeys({ - title: "Publishable API key", - type: "publishable", - created_by: "user_123", - }) + const apiKey = await apiKeyModuleService.createApiKeys({ + title: "Publishable API key", + type: "publishable", + created_by: "user_123", + }) - return NextResponse.json({ - api_key: apiKey, - }) - } - ``` + return NextResponse.json({ + api_key: apiKey, + }) +} +``` @@ -72,42 +68,38 @@ In this guide, you’ll find common examples of how you can use the API Key Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ) { - const apiKeyModuleService: IApiKeyModuleService = - request.scope.resolve(ModuleRegistrationName.API_KEY) +export async function GET(request: MedusaRequest, res: MedusaResponse) { + const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve( + ModuleRegistrationName.API_KEY + ) - res.json({ - api_keys: await apiKeyModuleService.listApiKeys(), - }) - } - ``` + res.json({ + api_keys: await apiKeyModuleService.listApiKeys(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeApiKeyModule, - } from "@medusajs/api-key" +import { initialize as initializeApiKeyModule } from "@medusajs/api-key" - export async function GET(request: Request) { - const apiKeyModuleService = await initializeApiKeyModule() +export async function GET(request: Request) { + const apiKeyModuleService = await initializeApiKeyModule() - return NextResponse.json({ - api_keys: await apiKeyModuleService.listApiKeys(), - }) - } - ``` + return NextResponse.json({ + api_keys: await apiKeyModuleService.listApiKeys(), + }) +} +``` @@ -119,71 +111,56 @@ In this guide, you’ll find common examples of how you can use the API Key Modu - ```ts collapsibleLines="1-9" expandButtonLabel="Show Imports" - import { - AuthenticatedMedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" +```ts collapsibleLines="1-9" expandButtonLabel="Show Imports" +import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: AuthenticatedMedusaRequest, - res: MedusaResponse - ) { - const apiKeyModuleService: IApiKeyModuleService = - request.scope.resolve(ModuleRegistrationName.API_KEY) +export async function POST( + request: AuthenticatedMedusaRequest, + res: MedusaResponse +) { + const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve( + ModuleRegistrationName.API_KEY + ) - const revokedKey = await apiKeyModuleService.revoke( - request.params.id, - { - revoked_by: request.auth_context.actor_id, - } - ) + const revokedKey = await apiKeyModuleService.revoke(request.params.id, { + revoked_by: request.auth_context.actor_id, + }) - res.json({ - api_key: revokedKey, - }) - } - ``` + res.json({ + api_key: revokedKey, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeApiKeyModule, - } from "@medusajs/api-key" +import { initialize as initializeApiKeyModule } from "@medusajs/api-key" - type ContextType = { - params: { - id: string - user_id: string - } +type ContextType = { + params: { + id: string + user_id: string } +} - export async function POST( - request: Request, - { params }: ContextType - ) { - const apiKeyModuleService = await initializeApiKeyModule() +export async function POST(request: Request, { params }: ContextType) { + const apiKeyModuleService = await initializeApiKeyModule() - const revokedKey = await apiKeyModuleService.revoke( - params.id, - { - revoked_by: params.user_id, - } - ) + const revokedKey = await apiKeyModuleService.revoke(params.id, { + revoked_by: params.user_id, + }) - return NextResponse.json({ - api_key: revokedKey, - }) - } - ``` + return NextResponse.json({ + api_key: revokedKey, + }) +} +``` @@ -195,57 +172,52 @@ In this guide, you’ll find common examples of how you can use the API Key Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const apiKeyModuleService: IApiKeyModuleService = - request.scope.resolve(ModuleRegistrationName.API_KEY) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve( + ModuleRegistrationName.API_KEY + ) - const authenticatedToken = - await apiKeyModuleService.authenticate(request.params.token) + const authenticatedToken = await apiKeyModuleService.authenticate( + request.params.token + ) - res.json({ - is_authenticated: !!authenticatedToken, - }) - } - ``` + res.json({ + is_authenticated: !!authenticatedToken, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeApiKeyModule, - } from "@medusajs/api-key" +import { initialize as initializeApiKeyModule } from "@medusajs/api-key" - type ContextType = { - params: { - token: string - } +type ContextType = { + params: { + token: string } +} - export async function POST( - request: Request, - { params }: ContextType - ) { - const apiKeyModuleService = await initializeApiKeyModule() +export async function POST(request: Request, { params }: ContextType) { + const apiKeyModuleService = await initializeApiKeyModule() - const authenticatedToken = - await apiKeyModuleService.authenticate(request.params.token) + const authenticatedToken = await apiKeyModuleService.authenticate( + request.params.token + ) - return NextResponse.json({ - is_authenticated: !!authenticatedToken, - }) - } - ``` + return NextResponse.json({ + is_authenticated: !!authenticatedToken, + }) +} +``` @@ -257,78 +229,68 @@ In this guide, you’ll find common examples of how you can use the API Key Modu - ```ts collapsibleLines="1-8" expandButtonLabel="Show Imports" - import { - AuthenticatedMedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts collapsibleLines="1-8" expandButtonLabel="Show Imports" +import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: AuthenticatedMedusaRequest, - res: MedusaResponse - ) { - const apiKeyModuleService: IApiKeyModuleService = - request.scope.resolve(ModuleRegistrationName.API_KEY) +export async function POST( + request: AuthenticatedMedusaRequest, + res: MedusaResponse +) { + const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve( + ModuleRegistrationName.API_KEY + ) - const revokedKey = await apiKeyModuleService.revoke( - request.params.id, - { - revoked_by: request.auth_context.actor_id, - } - ) + const revokedKey = await apiKeyModuleService.revoke(request.params.id, { + revoked_by: request.auth_context.actor_id, + }) - const newKey = await apiKeyModuleService.createApiKeys({ - title: revokedKey.title, - type: revokedKey.type, - created_by: revokedKey.created_by, - }) + const newKey = await apiKeyModuleService.createApiKeys({ + title: revokedKey.title, + type: revokedKey.type, + created_by: revokedKey.created_by, + }) - res.json({ - api_key: newKey, - }) - } - ``` + res.json({ + api_key: newKey, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeApiKeyModule, - } from "@medusajs/api-key" +import { initialize as initializeApiKeyModule } from "@medusajs/api-key" - type ContextType = { - params: { - id: string - user_id: string - } +type ContextType = { + params: { + id: string + user_id: string } +} - export async function POST( - request: Request, - { params }: ContextType - ) { - const apiKeyModuleService = await initializeApiKeyModule() +export async function POST(request: Request, { params }: ContextType) { + const apiKeyModuleService = await initializeApiKeyModule() - const revokedKey = await apiKeyModuleService.revoke(params.id, { - revoked_by: params.user_id, - }) + const revokedKey = await apiKeyModuleService.revoke(params.id, { + revoked_by: params.user_id, + }) - const newKey = await apiKeyModuleService.createApiKeys({ - title: revokedKey.title, - type: revokedKey.type, - created_by: revokedKey.created_by, - }) + const newKey = await apiKeyModuleService.createApiKeys({ + title: revokedKey.title, + type: revokedKey.type, + created_by: revokedKey.created_by, + }) - return NextResponse.json({ - api_key: newKey, - }) - } - ``` + return NextResponse.json({ + api_key: newKey, + }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/api-key/page.mdx b/www/apps/resources/app/commerce-modules/api-key/page.mdx index b42f1e97c6..9461794207 100644 --- a/www/apps/resources/app/commerce-modules/api-key/page.mdx +++ b/www/apps/resources/app/commerce-modules/api-key/page.mdx @@ -37,8 +37,7 @@ const secretApiKey = await apiKeyModuleService.createApiKeys({ Verify tokens of secret API keys to authenticate users or actions, such as verifying a password reset token. ```ts -const authenticatedToken = - await apiKeyModuleService.authenticate("sk_123") +const authenticatedToken = await apiKeyModuleService.authenticate("sk_123") if (!authenticatedToken) { console.error("Couldn't verify token") @@ -84,61 +83,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const apiKeyModuleService: IApiKeyModuleService = - request.scope.resolve(ModuleRegistrationName.API_KEY) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const apiKeyModuleService: IApiKeyModuleService = request.scope.resolve( + ModuleRegistrationName.API_KEY + ) - res.json({ - api_keys: await apiKeyModuleService.listApiKeys(), - }) - } - ``` + res.json({ + api_keys: await apiKeyModuleService.listApiKeys(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const apiKeyModuleService: IApiKeyModuleService = - container.resolve(ModuleRegistrationName.API_KEY) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const apiKeyModuleService: IApiKeyModuleService = container.resolve( + ModuleRegistrationName.API_KEY + ) - const apiKeys = await apiKeyModuleService.listApiKeys() - } - ``` + const apiKeys = await apiKeyModuleService.listApiKeys() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IApiKeyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IApiKeyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const apiKeyModuleService: IApiKeyModuleService = - container.resolve( - ModuleRegistrationName.API_KEY - ) +const step1 = createStep("step-1", async (_, { container }) => { + const apiKeyModuleService: IApiKeyModuleService = container.resolve( + ModuleRegistrationName.API_KEY + ) - const apiKeys = await apiKeyModuleService.listApiKeys() - }) - ``` + const apiKeys = await apiKeyModuleService.listApiKeys() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/auth/examples/page.mdx b/www/apps/resources/app/commerce-modules/auth/examples/page.mdx index 228743b5e2..842bef2690 100644 --- a/www/apps/resources/app/commerce-modules/auth/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/examples/page.mdx @@ -19,92 +19,90 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j - ```ts collapsibleLines="1-10" expandButtonLabel="Show Imports" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { - IAuthModuleService, - AuthenticationInput, - } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" - import { MedusaError } from "@medusajs/utils" - import jwt from "jsonwebtoken" +```ts collapsibleLines="1-10" expandButtonLabel="Show Imports" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService, AuthenticationInput } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" +import { MedusaError } from "@medusajs/utils" +import jwt from "jsonwebtoken" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - const { success, authIdentity, location, error } = - await authModuleService.authenticate("emailpass", { - url: req.url, - headers: req.headers, - query: req.query, - body: req.body, - authScope: "admin", - protocol: req.protocol, - } as AuthenticationInput) + const { success, authIdentity, location, error } = + await authModuleService.authenticate("emailpass", { + url: req.url, + headers: req.headers, + query: req.query, + body: req.body, + authScope: "admin", + protocol: req.protocol, + } as AuthenticationInput) - if (!success) { - throw new MedusaError(MedusaError.Types.UNAUTHORIZED, error) - } - - if (location) { - res.redirect(location) - return - } - - const { jwtSecret } = - req.scope.resolve("configModule").projectConfig.http - const token = jwt.sign(authIdentity, jwtSecret) - - res.status(200).json({ token }) + if (!success) { + throw new MedusaError(MedusaError.Types.UNAUTHORIZED, error) } - ``` + + if (location) { + res.redirect(location) + return + } + + const { jwtSecret } = req.scope.resolve("configModule").projectConfig.http + const token = jwt.sign(authIdentity, jwtSecret) + + res.status(200).json({ token }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeAuthModule, - } from "@medusajs/auth" +import { initialize as initializeAuthModule } from "@medusajs/auth" - export async function POST(request: Request) { - const authModuleService = await initializeAuthModule() - const url = new URL(request.url) +export async function POST(request: Request) { + const authModuleService = await initializeAuthModule() + const url = new URL(request.url) - const { success, authIdentity, location, error } = - await authModuleService.authenticate("emailpass", { - url: request.url, - headers: Object.fromEntries(request.headers), - query: Object.fromEntries(url.searchParams), - body: await request.json(), - authScope: "admin", - protocol: url.protocol, - } as AuthenticationInput) + const { success, authIdentity, location, error } = + await authModuleService.authenticate("emailpass", { + url: request.url, + headers: Object.fromEntries(request.headers), + query: Object.fromEntries(url.searchParams), + body: await request.json(), + authScope: "admin", + protocol: url.protocol, + } as AuthenticationInput) - if (!success) { - throw new Error(error) - } - - if (location) { - return NextResponse.redirect(location) - return - } - - const token = jwt.sign(authIdentity, "supersecret") - - return NextResponse.json({ - token, - }, { - status: 200, - }) + if (!success) { + throw new Error(error) } - ``` + + if (location) { + return NextResponse.redirect(location) + return + } + + const token = jwt.sign(authIdentity, "supersecret") + + return NextResponse.json( + { + token, + }, + { + status: 200, + } + ) +} +``` @@ -122,96 +120,94 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j - ```ts collapsibleLines="1-10" expandButtonLabel="Show Imports" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { - IAuthModuleService, - AuthenticationInput, - } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" - import { MedusaError } from "@medusajs/utils" - import jwt from "jsonwebtoken" +```ts collapsibleLines="1-10" expandButtonLabel="Show Imports" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService, AuthenticationInput } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" +import { MedusaError } from "@medusajs/utils" +import jwt from "jsonwebtoken" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - const { success, authIdentity, error, successRedirectUrl } = - await authModuleService.validateCallback("google", { - url: req.url, - headers: req.headers, - query: req.query, - body: req.body, - authScope: "admin", - protocol: req.protocol, - } as AuthenticationInput) + const { success, authIdentity, error, successRedirectUrl } = + await authModuleService.validateCallback("google", { + url: req.url, + headers: req.headers, + query: req.query, + body: req.body, + authScope: "admin", + protocol: req.protocol, + } as AuthenticationInput) - if (!success) { - throw new MedusaError(MedusaError.Types.UNAUTHORIZED, error) - } - - const { jwtSecret } = - req.scope.resolve("configModule").projectConfig.http - const token = jwt.sign(authIdentity, jwtSecret) - - if (successRedirectUrl) { - const url = new URL(successRedirectUrl!) - url.searchParams.append("auth_token", token) - - return res.redirect(url.toString()) - } - - res.status(200).json({ token }) + if (!success) { + throw new MedusaError(MedusaError.Types.UNAUTHORIZED, error) } - ``` + + const { jwtSecret } = req.scope.resolve("configModule").projectConfig.http + const token = jwt.sign(authIdentity, jwtSecret) + + if (successRedirectUrl) { + const url = new URL(successRedirectUrl!) + url.searchParams.append("auth_token", token) + + return res.redirect(url.toString()) + } + + res.status(200).json({ token }) +} +``` - ```ts collapsibleLines="1-7" expandButtonLabel="Show Imports" - import { NextResponse } from "next/server" +```ts collapsibleLines="1-7" expandButtonLabel="Show Imports" +import { NextResponse } from "next/server" - import { - initialize as initializeAuthModule, - } from "@medusajs/auth" +import { initialize as initializeAuthModule } from "@medusajs/auth" - export async function POST(request: Request) { - const authModuleService = await initializeAuthModule() - const url = new URL(request.url) +export async function POST(request: Request) { + const authModuleService = await initializeAuthModule() + const url = new URL(request.url) - const { success, authIdentity, location, error } = - await authModuleService.authenticate("google", { - url: request.url, - headers: Object.fromEntries(request.headers), - query: Object.fromEntries(url.searchParams), - body: await request.json(), - authScope: "admin", - protocol: url.protocol, - } as AuthenticationInput) + const { success, authIdentity, location, error } = + await authModuleService.authenticate("google", { + url: request.url, + headers: Object.fromEntries(request.headers), + query: Object.fromEntries(url.searchParams), + body: await request.json(), + authScope: "admin", + protocol: url.protocol, + } as AuthenticationInput) - if (!success) { - throw new Error(error) - } - - const token = jwt.sign(authIdentity, "supersecret") - - if (successRedirectUrl) { - const url = new URL(successRedirectUrl!) - url.searchParams.append("auth_token", token) - - return NextResponse.redirect(url.toString()) - } - - return NextResponse.json({ - token, - }, { - status: 200, - }) + if (!success) { + throw new Error(error) } - ``` + + const token = jwt.sign(authIdentity, "supersecret") + + if (successRedirectUrl) { + const url = new URL(successRedirectUrl!) + url.searchParams.append("auth_token", token) + + return NextResponse.redirect(url.toString()) + } + + return NextResponse.json( + { + token, + }, + { + status: 200, + } + ) +} +``` @@ -223,54 +219,51 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IAuthModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - const authIdentity = await authModuleService - .createAuthIdentities({ - provider: "emailpass", - entity_id: "user@example.com", - scope: "admin", - }) + const authIdentity = await authModuleService.createAuthIdentities({ + provider: "emailpass", + entity_id: "user@example.com", + scope: "admin", + }) - res.json({ auth_identity: authIdentity }) - } - ``` + res.json({ auth_identity: authIdentity }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeAuthModule, - } from "@medusajs/auth" +import { initialize as initializeAuthModule } from "@medusajs/auth" - export async function POST(request: Request) { - const authModuleService = await initializeAuthModule() +export async function POST(request: Request) { + const authModuleService = await initializeAuthModule() - const authIdentity = await authModuleService - .createAuthIdentities({ - provider: "emailpass", - entity_id: "user@example.com", - scope: "admin", - }) + const authIdentity = await authModuleService.createAuthIdentities({ + provider: "emailpass", + entity_id: "user@example.com", + scope: "admin", + }) - return NextResponse.json({ - auth_identity: authIdentity, - }) - } - ``` + return NextResponse.json({ + auth_identity: authIdentity, + }) +} +``` @@ -282,44 +275,41 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IAuthModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - res.json({ - auth_identitys: - await authModuleService.listAuthIdentities(), - }) - } - ``` + res.json({ + auth_identitys: await authModuleService.listAuthIdentities(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeAuthModule, - } from "@medusajs/auth" +import { initialize as initializeAuthModule } from "@medusajs/auth" - export async function GET(request: Request) { - const authModuleService = await initializeAuthModule() +export async function GET(request: Request) { + const authModuleService = await initializeAuthModule() - return NextResponse.json({ - auth_identities: - await authModuleService.listAuthIdentities(), - }) - } - ``` + return NextResponse.json({ + auth_identities: await authModuleService.listAuthIdentities(), + }) +} +``` @@ -331,67 +321,61 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IAuthModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - const authIdentity = await authModuleService - .updateAuthIdentites({ - id: "authusr_123", - provider_metadata: { - test: true, - }, - }) + const authIdentity = await authModuleService.updateAuthIdentites({ + id: "authusr_123", + provider_metadata: { + test: true, + }, + }) - res.json({ - auth_identity: authIdentity, - }) - } - ``` + res.json({ + auth_identity: authIdentity, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeAuthModule, - } from "@medusajs/auth" +import { initialize as initializeAuthModule } from "@medusajs/auth" - type ContextType = { - params: { - id: string - } +type ContextType = { + params: { + id: string } +} - export async function POST( - request: Request, - { params }: ContextType - ) { - const authModuleService = await initializeAuthModule() +export async function POST(request: Request, { params }: ContextType) { + const authModuleService = await initializeAuthModule() - const authIdentity = await authModuleService - .updateAuthIdentites({ - id: "authusr_123", - provider_metadata: { - test: true, - }, - }) + const authIdentity = await authModuleService.updateAuthIdentites({ + id: "authusr_123", + provider_metadata: { + test: true, + }, + }) - return NextResponse.json({ - auth_identity: authIdentity, - }) - } - ``` + return NextResponse.json({ + auth_identity: authIdentity, + }) +} +``` @@ -403,53 +387,45 @@ This example uses the [jsonwebtoken NPM package](https://www.npmjs.com/package/j - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IAuthModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function DELETE( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - await authModuleService.deleteAuthIdentities([ - "authusr_123", - ]) + await authModuleService.deleteAuthIdentities(["authusr_123"]) - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeAuthModule, - } from "@medusajs/auth" +import { initialize as initializeAuthModule } from "@medusajs/auth" - type ContextType = { - params: { - id: string - } +type ContextType = { + params: { + id: string } +} - export async function DELETE( - request: Request, - { params }: ContextType - ) { - const authModuleService = await initializeAuthModule() +export async function DELETE(request: Request, { params }: ContextType) { + const authModuleService = await initializeAuthModule() - await authModuleService.deleteAuthIdentities([ - "authusr_123", - ]) - } - ``` + await authModuleService.deleteAuthIdentities(["authusr_123"]) +} +``` diff --git a/www/apps/resources/app/commerce-modules/auth/page.mdx b/www/apps/resources/app/commerce-modules/auth/page.mdx index d4163da844..d8ec058504 100644 --- a/www/apps/resources/app/commerce-modules/auth/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/page.mdx @@ -15,15 +15,17 @@ The Auth Module is the `@medusajs/auth` NPM package that provides authentication With the Auth Module, authenticate users using their email and password credentials. ```ts -const { success, authIdentity, error } = - await authModuleService.authenticate("emailpass", { +const { success, authIdentity, error } = await authModuleService.authenticate( + "emailpass", + { url: req.url, headers: req.headers, query: req.query, body: req.body, authScope: "admin", protocol: req.protocol, - } as AuthenticationInput) + } as AuthenticationInput +) if (!success) { // incorrect authentication details @@ -53,15 +55,17 @@ if (!authIdentity && location) { } // in callback API route -const { success, authIdentity } = - await authModuleService.validateCallback("google", { +const { success, authIdentity } = await authModuleService.validateCallback( + "google", + { url: req.url, headers: req.headers, query: req.query, body: req.body, authScope: "admin", protocol: req.protocol, - } as AuthenticationInput) + } as AuthenticationInput +) ``` --- @@ -81,72 +85,57 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { - MedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { IAuthModuleService } from "@medusajs/types" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const authModuleService: IAuthModuleService = - req.scope.resolve(ModuleRegistrationName.AUTH) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const authModuleService: IAuthModuleService = req.scope.resolve( + ModuleRegistrationName.AUTH + ) - res.json({ - authIdentitys: - await authModuleService.listAuthIdentities(), - }) - } - ``` + res.json({ + authIdentitys: await authModuleService.listAuthIdentities(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IAuthModuleService } from "@medusajs/types" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/modules-sdk" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const authModuleService: IAuthModuleService = - container.resolve(ModuleRegistrationName.AUTH) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const authModuleService: IAuthModuleService = container.resolve( + ModuleRegistrationName.AUTH + ) - const authIdentitys = await authModuleService - .listAuthIdentities() - } - ``` + const authIdentitys = await authModuleService.listAuthIdentities() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IAuthModuleService } from "@medusajs/types" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IAuthModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/modules-sdk" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const authModuleService: IAuthModuleService = - container.resolve( - ModuleRegistrationName.AUTH - ) - const authIdentitys = await authModuleService - .listAuthIdentities() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const authModuleService: IAuthModuleService = container.resolve( + ModuleRegistrationName.AUTH + ) + const authIdentitys = await authModuleService.listAuthIdentities() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/cart/examples/page.mdx b/www/apps/resources/app/commerce-modules/cart/examples/page.mdx index 84caf5dd66..f0135d5b77 100644 --- a/www/apps/resources/app/commerce-modules/cart/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/cart/examples/page.mdx @@ -13,70 +13,69 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - const cart = await cartModuleService.createCarts({ - currency_code: "usd", - shipping_address: { - address_1: "1512 Barataria Blvd", - country_code: "us", + const cart = await cartModuleService.createCarts({ + currency_code: "usd", + shipping_address: { + address_1: "1512 Barataria Blvd", + country_code: "us", + }, + items: [ + { + title: "Shirt", + unit_price: 1000, + quantity: 1, }, - items: [ - { - title: "Shirt", - unit_price: 1000, - quantity: 1, - }, - ], - }) + ], + }) - res.json({ cart }) - } - ``` + res.json({ cart }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function POST(request: Request) { - const cartModuleService = await initializeCartModule() +export async function POST(request: Request) { + const cartModuleService = await initializeCartModule() - const cart = await cartModuleService.createCarts({ - currency_code: "usd", - shipping_address: { - address_1: "1512 Barataria Blvd", - country_code: "us", + const cart = await cartModuleService.createCarts({ + currency_code: "usd", + shipping_address: { + address_1: "1512 Barataria Blvd", + country_code: "us", + }, + items: [ + { + title: "Shirt", + unit_price: 1000, + quantity: 1, }, - items: [ - { - title: "Shirt", - unit_price: 1000, - quantity: 1, - }, - ], - }) + ], + }) - return NextResponse.json({ - cart, - }) - } - ``` + return NextResponse.json({ + cart, + }) +} +``` @@ -88,48 +87,43 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - const cart = await cartModuleService.retrieveCart( - "cart_123" - ) + const cart = await cartModuleService.retrieveCart("cart_123") - res.json({ cart }) - } - ``` + res.json({ cart }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function GET(request: Request) { - const cartModuleService = await initializeCartModule() +export async function GET(request: Request) { + const cartModuleService = await initializeCartModule() - const cart = await cartModuleService.retrieveCart( - "cart_123" - ) + const cart = await cartModuleService.retrieveCart("cart_123") - return NextResponse.json({ - cart, - }) - } - ``` + return NextResponse.json({ + cart, + }) +} +``` @@ -141,58 +135,55 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - const lineItem = await cartModuleService.addLineItems({ - cart_id: "cart_123", - title: "Shirt", - quantity: 2, - unit_price: 5000, - }) + const lineItem = await cartModuleService.addLineItems({ + cart_id: "cart_123", + title: "Shirt", + quantity: 2, + unit_price: 5000, + }) - res.json({ - line_item: lineItem, - }) - } - ``` + res.json({ + line_item: lineItem, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function POST( - request: Request - ) { - const cartModuleService = await initializeCartModule() +export async function POST(request: Request) { + const cartModuleService = await initializeCartModule() - const lineItem = await cartModuleService.addLineItems({ - cart_id: "cart_123", - title: "Shirt", - quantity: 2, - unit_price: 5000, - }) + const lineItem = await cartModuleService.addLineItems({ + cart_id: "cart_123", + title: "Shirt", + quantity: 2, + unit_price: 5000, + }) - return NextResponse.json({ - line_item: lineItem, - }) - } - ``` + return NextResponse.json({ + line_item: lineItem, + }) +} +``` @@ -204,58 +195,53 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - const shippingMethod = - await cartModuleService.addShippingMethods({ - cart_id: "cart_123", - name: "Custom shipping", - amount: 1000, - }) + const shippingMethod = await cartModuleService.addShippingMethods({ + cart_id: "cart_123", + name: "Custom shipping", + amount: 1000, + }) - res.json({ - shipping_method: shippingMethod, - }) - } - ``` + res.json({ + shipping_method: shippingMethod, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function POST( - request: Request - ) { - const cartModuleService = await initializeCartModule() +export async function POST(request: Request) { + const cartModuleService = await initializeCartModule() - const shippingMethod = - await cartModuleService.addShippingMethods({ - cart_id: "cart_123", - name: "Custom shipping", - amount: 1000, - }) + const shippingMethod = await cartModuleService.addShippingMethods({ + cart_id: "cart_123", + name: "Custom shipping", + amount: 1000, + }) - return NextResponse.json({ - shipping_method: shippingMethod, - }) - } - ``` + return NextResponse.json({ + shipping_method: shippingMethod, + }) +} +``` @@ -267,58 +253,53 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - const itemAdjustment = - await cartModuleService.addLineItemAdjustments({ - item_id: "cali_123", - amount: 500, - code: "50%OFF", - }) + const itemAdjustment = await cartModuleService.addLineItemAdjustments({ + item_id: "cali_123", + amount: 500, + code: "50%OFF", + }) - res.json({ - adjustment: itemAdjustment, - }) - } - ``` + res.json({ + adjustment: itemAdjustment, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function POST( - request: Request - ) { - const cartModuleService = await initializeCartModule() +export async function POST(request: Request) { + const cartModuleService = await initializeCartModule() - const itemAdjustment = - await cartModuleService.addLineItemAdjustments({ - item_id: "cali_123", - amount: 500, - code: "50%OFF", - }) + const itemAdjustment = await cartModuleService.addLineItemAdjustments({ + item_id: "cali_123", + amount: 500, + code: "50%OFF", + }) - return NextResponse.json({ - adjustment: itemAdjustment, - }) - } - ``` + return NextResponse.json({ + adjustment: itemAdjustment, + }) +} +``` @@ -330,58 +311,55 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - const shippingMethodAdjustment = - await cartModuleService.addShippingMethodAdjustments({ - shipping_method_id: "casm_123", - amount: 500, - code: "FREESHIPPING", - }) - - res.json({ - adjustment: shippingMethodAdjustment, + const shippingMethodAdjustment = + await cartModuleService.addShippingMethodAdjustments({ + shipping_method_id: "casm_123", + amount: 500, + code: "FREESHIPPING", }) - } - ``` + + res.json({ + adjustment: shippingMethodAdjustment, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function POST( - request: Request - ) { - const cartModuleService = await initializeCartModule() +export async function POST(request: Request) { + const cartModuleService = await initializeCartModule() - const shippingMethodAdjustment = - await cartModuleService.addShippingMethodAdjustments({ - shipping_method_id: "casm_123", - amount: 500, - code: "FREESHIPPING", - }) - - return NextResponse.json({ - adjustment: shippingMethodAdjustment, + const shippingMethodAdjustment = + await cartModuleService.addShippingMethodAdjustments({ + shipping_method_id: "casm_123", + amount: 500, + code: "FREESHIPPING", }) - } - ``` + + return NextResponse.json({ + adjustment: shippingMethodAdjustment, + }) +} +``` @@ -393,42 +371,39 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function DELETE( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - await cartModuleService.deleteLineItems(["cali_123"]) + await cartModuleService.deleteLineItems(["cali_123"]) - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCartModule, - } from "@medusajs/cart" +import { initialize as initializeCartModule } from "@medusajs/cart" - export async function DELETE( - request: Request - ) { - const cartModuleService = await initializeCartModule() +export async function DELETE(request: Request) { + const cartModuleService = await initializeCartModule() - await cartModuleService.deleteLineItems(["cali_123"]) - } - ``` + await cartModuleService.deleteLineItems(["cali_123"]) +} +``` @@ -440,44 +415,46 @@ In this guide, you’ll find common examples of how you can use the Cart Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function DELETE( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - await cartModuleService.deleteShippingMethods(["casm_123"]) + await cartModuleService.deleteShippingMethods(["casm_123"]) - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function DELETE( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - await cartModuleService.deleteShippingMethods(["casm_123"]) + await cartModuleService.deleteShippingMethods(["casm_123"]) - res.status(200) - } - ``` + res.status(200) +} +``` diff --git a/www/apps/resources/app/commerce-modules/cart/page.mdx b/www/apps/resources/app/commerce-modules/cart/page.mdx index 5e1d321af9..3eecd9a2b9 100644 --- a/www/apps/resources/app/commerce-modules/cart/page.mdx +++ b/www/apps/resources/app/commerce-modules/cart/page.mdx @@ -36,12 +36,11 @@ const cart = await cartModuleService.createCarts({ Apply promotions or discounts to line items and shipping methods by adding adjustment lines that are factored into their subtotals. ```ts -const lineAdjustments = - await cartModuleService.addLineItemAdjustments({ - item_id: "cali_123", - code: "50OFF", - amount: 500, - }) +const lineAdjustments = await cartModuleService.addLineItemAdjustments({ + item_id: "cali_123", + code: "50OFF", + amount: 500, +}) const shippingAdjustments = await cartModuleService.addShippingMethodAdjustments({ @@ -72,61 +71,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const cartModuleService: ICartModuleService = - req.scope.resolve(ModuleRegistrationName.CART) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const cartModuleService: ICartModuleService = req.scope.resolve( + ModuleRegistrationName.CART + ) - res.json({ - carts: await cartModuleService.listCarts(), - }) - } - ``` + res.json({ + carts: await cartModuleService.listCarts(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const cartModuleService: ICartModuleService = - container.resolve(ModuleRegistrationName.CART) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const cartModuleService: ICartModuleService = container.resolve( + ModuleRegistrationName.CART + ) - const carts = await cartModuleService.listCarts() - } - ``` + const carts = await cartModuleService.listCarts() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { ICartModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { ICartModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const cartModuleService: ICartModuleService = - container.resolve( - ModuleRegistrationName.CART - ) - - const carts = await cartModuleService.listCarts() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const cartModuleService: ICartModuleService = container.resolve( + ModuleRegistrationName.CART + ) + + const carts = await cartModuleService.listCarts() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/currency/examples/page.mdx b/www/apps/resources/app/commerce-modules/currency/examples/page.mdx index 16c9ffe303..3fd7f4ac10 100644 --- a/www/apps/resources/app/commerce-modules/currency/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/currency/examples/page.mdx @@ -13,43 +13,41 @@ In this guide, you’ll find common examples of how you can use the Currency Mod - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICurrencyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICurrencyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const currencyModuleService: ICurrencyModuleService = - req.scope.resolve(ModuleRegistrationName.CURRENCY) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const currencyModuleService: ICurrencyModuleService = req.scope.resolve( + ModuleRegistrationName.CURRENCY + ) - res.json({ - currencies: await currencyModuleService.listCurrencies(), - }) - } - ``` + res.json({ + currencies: await currencyModuleService.listCurrencies(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCurrencyModule, - } from "@medusajs/currency" +import { initialize as initializeCurrencyModule } from "@medusajs/currency" - export async function GET(request: Request) { - const currencyModuleService = - await initializeCurrencyModule() +export async function GET(request: Request) { + const currencyModuleService = await initializeCurrencyModule() - return NextResponse.json({ - currencies: await currencyModuleService.listCurrencies(), - }) - } - ``` + return NextResponse.json({ + currencies: await currencyModuleService.listCurrencies(), + }) +} +``` @@ -61,48 +59,43 @@ In this guide, you’ll find common examples of how you can use the Currency Mod - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICurrencyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICurrencyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const currencyModuleService: ICurrencyModuleService = - req.scope.resolve(ModuleRegistrationName.CURRENCY) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const currencyModuleService: ICurrencyModuleService = req.scope.resolve( + ModuleRegistrationName.CURRENCY + ) - const currency = await currencyModuleService - .retrieveCurrency("usd") + const currency = await currencyModuleService.retrieveCurrency("usd") - res.json({ - currency, - }) - } - ``` + res.json({ + currency, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCurrencyModule, - } from "@medusajs/currency" +import { initialize as initializeCurrencyModule } from "@medusajs/currency" - export async function GET( - request: Request - ) { - const currencyModuleService = await initializeCurrencyModule() +export async function GET(request: Request) { + const currencyModuleService = await initializeCurrencyModule() - const currency = await currencyModuleService - .retrieveCurrency("usd") + const currency = await currencyModuleService.retrieveCurrency("usd") - return NextResponse.json({ currency }) - } - ``` + return NextResponse.json({ currency }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/currency/page.mdx b/www/apps/resources/app/commerce-modules/currency/page.mdx index 02660d9d30..7462a6c04b 100644 --- a/www/apps/resources/app/commerce-modules/currency/page.mdx +++ b/www/apps/resources/app/commerce-modules/currency/page.mdx @@ -15,9 +15,7 @@ The Currency Module is the `@medusajs/currency` NPM package that provides curren List and retrieve currencies stored in your application. ```ts -const currency = await currencyModuleService.retrieveCurrency( - "usd" -) +const currency = await currencyModuleService.retrieveCurrency("usd") ``` ### Support Currencies in Modules @@ -27,9 +25,7 @@ Other commerce modules use currency codes in their data models or operations. Yo An example with the Region Module: ```ts -const region = await regionModuleService.retrieveCurrency( - "reg_123" -) +const region = await regionModuleService.retrieveCurrency("reg_123") const currency = await currencyModuleService.retrieveCurrency( region.currency_code ) @@ -46,63 +42,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICurrencyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICurrencyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const currencyModuleService: ICurrencyModuleService = - req.scope.resolve(ModuleRegistrationName.CURRENCY) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const currencyModuleService: ICurrencyModuleService = req.scope.resolve( + ModuleRegistrationName.CURRENCY + ) - res.json({ - currencies: await currencyModuleService.listCurrencies(), - }) - } - ``` + res.json({ + currencies: await currencyModuleService.listCurrencies(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { ICurrencyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { ICurrencyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const currencyModuleService: ICurrencyModuleService = - container.resolve(ModuleRegistrationName.CURRENCY) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const currencyModuleService: ICurrencyModuleService = container.resolve( + ModuleRegistrationName.CURRENCY + ) - const currencies = await currencyModuleService - .listCurrencies() - } - ``` + const currencies = await currencyModuleService.listCurrencies() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { ICurrencyModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { ICurrencyModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const currencyModuleService: ICurrencyModuleService = - container.resolve( - ModuleRegistrationName.CURRENCY - ) - - const currencies = await currencyModuleService - .listCurrencies() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const currencyModuleService: ICurrencyModuleService = container.resolve( + ModuleRegistrationName.CURRENCY + ) + + const currencies = await currencyModuleService.listCurrencies() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/customer/examples/page.mdx b/www/apps/resources/app/commerce-modules/customer/examples/page.mdx index 7a127e398a..8d093514a5 100644 --- a/www/apps/resources/app/commerce-modules/customer/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/customer/examples/page.mdx @@ -13,54 +13,50 @@ In this guide, you’ll find common examples of how you can use the Customer Mod - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const customerModuleService: ICustomerModuleService = - request.scope.resolve(ModuleRegistrationName.CUSTOMER) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const customerModuleService: ICustomerModuleService = request.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) - const customer = await customerModuleService.createCustomers({ - first_name: "Peter", - last_name: "Hayes", - email: "peter.hayes@example.com", - }) + const customer = await customerModuleService.createCustomers({ + first_name: "Peter", + last_name: "Hayes", + email: "peter.hayes@example.com", + }) - res.json({ - customer, - }) - } - ``` + res.json({ + customer, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCustomerModule, - } from "@medusajs/customer" +import { initialize as initializeCustomerModule } from "@medusajs/customer" - export async function POST(request: Request) { - const customerModuleService = await initializeCustomerModule() +export async function POST(request: Request) { + const customerModuleService = await initializeCustomerModule() - const customer = await customerModuleService.createCustomers({ - first_name: "Peter", - last_name: "Hayes", - email: "peter.hayes@example.com", - }) + const customer = await customerModuleService.createCustomers({ + first_name: "Peter", + last_name: "Hayes", + email: "peter.hayes@example.com", + }) - return NextResponse.json({ - customer, - }) - } - ``` + return NextResponse.json({ + customer, + }) +} +``` @@ -72,52 +68,46 @@ In this guide, you’ll find common examples of how you can use the Customer Mod - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const customerModuleService: ICustomerModuleService = - request.scope.resolve(ModuleRegistrationName.CUSTOMER) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const customerModuleService: ICustomerModuleService = request.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) - const customerGroup = - await customerModuleService.createCustomerGroups({ - name: "VIP", - }) + const customerGroup = await customerModuleService.createCustomerGroups({ + name: "VIP", + }) - res.json({ - customer_group: customerGroup, - }) - } - ``` + res.json({ + customer_group: customerGroup, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCustomerModule, - } from "@medusajs/customer" +import { initialize as initializeCustomerModule } from "@medusajs/customer" - export async function POST(request: Request) { - const customerModuleService = await initializeCustomerModule() +export async function POST(request: Request) { + const customerModuleService = await initializeCustomerModule() - const customerGroup = - await customerModuleService.createCustomerGroups({ - name: "VIP", - }) + const customerGroup = await customerModuleService.createCustomerGroups({ + name: "VIP", + }) - return NextResponse.json({ - customer_group: customerGroup, - }) - } - ``` + return NextResponse.json({ + customer_group: customerGroup, + }) +} +``` @@ -129,48 +119,44 @@ In this guide, you’ll find common examples of how you can use the Customer Mod - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const customerModuleService: ICustomerModuleService = - request.scope.resolve(ModuleRegistrationName.CUSTOMER) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const customerModuleService: ICustomerModuleService = request.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) - await customerModuleService.addCustomerToGroup({ - customer_id: "cus_123", - customer_group_id: "cusgroup_123", - }) + await customerModuleService.addCustomerToGroup({ + customer_id: "cus_123", + customer_group_id: "cusgroup_123", + }) - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeCustomerModule, - } from "@medusajs/customer" +import { initialize as initializeCustomerModule } from "@medusajs/customer" - export async function POST(request: Request) { - const customerModuleService = await initializeCustomerModule() +export async function POST(request: Request) { + const customerModuleService = await initializeCustomerModule() - await customerModuleService.addCustomerToGroup({ - customer_id: "cus_123", - customer_group_id: "cusgroup_123", - }) + await customerModuleService.addCustomerToGroup({ + customer_id: "cus_123", + customer_group_id: "cusgroup_123", + }) - return NextResponse.json({}, { status: 200 }) - } - ``` + return NextResponse.json({}, { status: 200 }) +} +``` @@ -182,49 +168,45 @@ In this guide, you’ll find common examples of how you can use the Customer Mod - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const customerModuleService: ICustomerModuleService = - request.scope.resolve(ModuleRegistrationName.CUSTOMER) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const customerModuleService: ICustomerModuleService = request.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) - await customerModuleService.removeCustomerFromGroup({ - customer_id: "cus_123", - customer_group_id: "cusgroup_123", - }) + await customerModuleService.removeCustomerFromGroup({ + customer_id: "cus_123", + customer_group_id: "cusgroup_123", + }) - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - // eslint-disable-next-line prettier/prettier - import { - initialize as initializeCustomerModule, - } from "@medusajs/customer" +// eslint-disable-next-line prettier/prettier +import { initialize as initializeCustomerModule } from "@medusajs/customer" - export async function POST(request: Request) { - const customerModuleService = await initializeCustomerModule() +export async function POST(request: Request) { + const customerModuleService = await initializeCustomerModule() - await customerModuleService.removeCustomerFromGroup({ - customer_id: "cus_123", - customer_group_id: "cusgroup_123", - }) + await customerModuleService.removeCustomerFromGroup({ + customer_id: "cus_123", + customer_group_id: "cusgroup_123", + }) - return NextResponse.json({}, { status: 200 }) - } - ``` + return NextResponse.json({}, { status: 200 }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/customer/page.mdx b/www/apps/resources/app/commerce-modules/customer/page.mdx index 73979c8cb7..5c43305213 100644 --- a/www/apps/resources/app/commerce-modules/customer/page.mdx +++ b/www/apps/resources/app/commerce-modules/customer/page.mdx @@ -27,10 +27,9 @@ const customer = await customerModuleService.createCustomers({ You can organize customers into groups. This has a lot of benefits and supports more use cases, such as provide discounts for specific customer groups using the Promotion Module. ```ts -const customerGroup = - await customerModuleService.createCustomerGroups({ - name: "VIP", - }) +const customerGroup = await customerModuleService.createCustomerGroups({ + name: "VIP", +}) await customerModuleService.addCustomerToGroup({ customer_id: "cus_123", @@ -49,59 +48,55 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ) { - const customerModuleService: ICustomerModuleService = - request.scope.resolve(ModuleRegistrationName.CUSTOMER) +export async function GET(request: MedusaRequest, res: MedusaResponse) { + const customerModuleService: ICustomerModuleService = request.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) - res.json({ - customers: await customerModuleService.listCustomers(), - }) - } - ``` + res.json({ + customers: await customerModuleService.listCustomers(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const customerModuleService: ICustomerModuleService = - container.resolve(ModuleRegistrationName.CUSTOMER) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const customerModuleService: ICustomerModuleService = container.resolve( + ModuleRegistrationName.CUSTOMER + ) - const customers = await customerModuleService.listCustomers() - } - ``` + const customers = await customerModuleService.listCustomers() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { ICustomerModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { ICustomerModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const customerModuleService: ICustomerModuleService = - container.resolve(ModuleRegistrationName.CUSTOMER) +const step1 = createStep("step-1", async (_, { container }) => { + const customerModuleService: ICustomerModuleService = container.resolve( + ModuleRegistrationName.CUSTOMER + ) - const customers = await customerModuleService.listCustomers() - }) - ``` + const customers = await customerModuleService.listCustomers() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/fulfillment/page.mdx b/www/apps/resources/app/commerce-modules/fulfillment/page.mdx index d5e9a60ae2..368cfa1662 100644 --- a/www/apps/resources/app/commerce-modules/fulfillment/page.mdx +++ b/www/apps/resources/app/commerce-modules/fulfillment/page.mdx @@ -15,26 +15,25 @@ The Fulfillment Module is the `@medusajs/fulfillment` NPM package that provides Create fulfillments and keep track of their status, items, and more. ```ts -const fulfillment = - await fulfillmentModuleService.createFulfillment({ - location_id: "loc_123", - provider_id: "webshipper", - delivery_address: { - country_code: "us", - city: "Strongsville", - address_1: "18290 Royalton Rd", +const fulfillment = await fulfillmentModuleService.createFulfillment({ + location_id: "loc_123", + provider_id: "webshipper", + delivery_address: { + country_code: "us", + city: "Strongsville", + address_1: "18290 Royalton Rd", + }, + items: [ + { + title: "Shirt", + sku: "SHIRT", + quantity: 1, + barcode: "123456", }, - items: [ - { - title: "Shirt", - sku: "SHIRT", - quantity: 1, - barcode: "123456", - }, - ], - labels: [], - order: {}, - }) + ], + labels: [], + order: {}, +}) ``` ### Integrate Third-Party Fulfillment Providers @@ -42,11 +41,10 @@ const fulfillment = Use third-party fulfillment providers to provide customers with shipping options and fulfill their orders. ```ts -const shippingOption = - await fulfillmentModuleService.createShippingOptions({ - // ... - provider_id: "webshipper", - }) +const shippingOption = await fulfillmentModuleService.createShippingOptions({ + // ... + provider_id: "webshipper", +}) ``` ### Restrict By Location and Rules @@ -54,33 +52,31 @@ const shippingOption = Shipping options can be restricted to specific geographical locations. You can also specify custom rules to restrict shipping options. ```ts -const serviceZone = - await fulfillmentModuleService.createServiceZones({ - name: "US", - fulfillment_set_id: "fset_123", - geo_zones: [ - { - type: "country", - country_code: "us", - }, - ], - }) +const serviceZone = await fulfillmentModuleService.createServiceZones({ + name: "US", + fulfillment_set_id: "fset_123", + geo_zones: [ + { + type: "country", + country_code: "us", + }, + ], +}) -const shippingOption = - await fulfillmentModuleService.createShippingOptions({ - name: "Express Shipping", - // restrict location - service_zone_id: serviceZone.id, - // restrict by custom rules - rules: [ - { - field: "customer_group", - operator: "eq", - value: "vip", - }, - ], - // ... - }) +const shippingOption = await fulfillmentModuleService.createShippingOptions({ + name: "Express Shipping", + // restrict location + service_zone_id: serviceZone.id, + // restrict by custom rules + rules: [ + { + field: "customer_group", + operator: "eq", + value: "vip", + }, + ], + // ... +}) ``` ### Support Different Fulfillment Forms @@ -88,18 +84,16 @@ const shippingOption = Support various fulfillment forms, such as shipping or pick up. ```ts -const fulfillmentSets = await fulfillmentModuleService.createFulfillmentSets( - [ - { - name: "Shipping", - type: "shipping", - }, - { - name: "Pick-up", - type: "pick-up", - }, - ] -) +const fulfillmentSets = await fulfillmentModuleService.createFulfillmentSets([ + { + name: "Shipping", + type: "shipping", + }, + { + name: "Pick-up", + type: "pick-up", + }, +]) ``` --- @@ -119,64 +113,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IFulfillmentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const fulfillmentModuleService: IFulfillmentModuleService = - req.scope.resolve(ModuleRegistrationName.FULFILLMENT) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const fulfillmentModuleService: IFulfillmentModuleService = req.scope.resolve( + ModuleRegistrationName.FULFILLMENT + ) - res.json({ - fulfillments: - await fulfillmentModuleService.listFulfillments(), - }) - } - ``` + res.json({ + fulfillments: await fulfillmentModuleService.listFulfillments(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IFulfillmentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const fulfillmentModuleService: IFulfillmentModuleService = - container.resolve(ModuleRegistrationName.FULFILLMENT) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const fulfillmentModuleService: IFulfillmentModuleService = container.resolve( + ModuleRegistrationName.FULFILLMENT + ) - const fulfillments = - await fulfillmentModuleService.listFulfillments() - } - ``` + const fulfillments = await fulfillmentModuleService.listFulfillments() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IFulfillmentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IFulfillmentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const fulfillmentModuleService: IFulfillmentModuleService = - container.resolve( - ModuleRegistrationName.FULFILLMENT - ) - - const fulfillments = - await fulfillmentModuleService.listFulfillments() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const fulfillmentModuleService: IFulfillmentModuleService = container.resolve( + ModuleRegistrationName.FULFILLMENT + ) + + const fulfillments = await fulfillmentModuleService.listFulfillments() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/inventory/examples/page.mdx b/www/apps/resources/app/commerce-modules/inventory/examples/page.mdx index f6347befd0..1234e5f787 100644 --- a/www/apps/resources/app/commerce-modules/inventory/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/inventory/examples/page.mdx @@ -13,54 +13,50 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryItem = - await inventoryModuleService.createInventoryItems({ - sku: request.body.sku, - title: request.body.title, - requires_shipping: request.body.requires_shipping, - }) + const inventoryItem = await inventoryModuleService.createInventoryItems({ + sku: request.body.sku, + title: request.body.title, + requires_shipping: request.body.requires_shipping, + }) - res.json({ inventory_item: inventoryItem }) - } - ``` + res.json({ inventory_item: inventoryItem }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - export async function POST(request: Request) { - const inventoryModuleService = - await initializeInventoryModule({}) - const body = await request.json() +export async function POST(request: Request) { + const inventoryModuleService = await initializeInventoryModule({}) + const body = await request.json() - const inventoryItem = - await inventoryModuleService.createInventoryItems({ - sku: body.sku, - title: body.title, - requires_shipping: body.requires_shipping, - }) + const inventoryItem = await inventoryModuleService.createInventoryItems({ + sku: body.sku, + title: body.title, + requires_shipping: body.requires_shipping, + }) - return NextResponse.json({ inventory_item: inventoryItem }) - } - ``` + return NextResponse.json({ inventory_item: inventoryItem }) +} +``` @@ -72,45 +68,41 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryItems = - await inventoryModuleService.listInventoryItems({}) + const inventoryItems = await inventoryModuleService.listInventoryItems({}) - res.json({ inventory_items: inventoryItems }) - } - ``` + res.json({ inventory_items: inventoryItems }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - export async function GET(request: Request) { - const inventoryModuleService = - await initializeInventoryModule({}) +export async function GET(request: Request) { + const inventoryModuleService = await initializeInventoryModule({}) - const inventoryItems = - await inventoryModuleService.listInventoryItems({}) + const inventoryItems = await inventoryModuleService.listInventoryItems({}) - return NextResponse.json({ inventory_items: inventoryItems }) - } - ``` + return NextResponse.json({ inventory_items: inventoryItems }) +} +``` @@ -122,58 +114,51 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryItem = - await inventoryModuleService.retrieveInventoryItem( - request.params.id - ) + const inventoryItem = await inventoryModuleService.retrieveInventoryItem( + request.params.id + ) - res.json({ inventory_item: inventoryItem }) - } - ``` + res.json({ inventory_item: inventoryItem }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - type ContextType = { - params: { - id: string - } +type ContextType = { + params: { + id: string } +} - export async function GET( - request: Request, - { params }: ContextType - ) { - const inventoryModuleService = - await initializeInventoryModule({}) +export async function GET(request: Request, { params }: ContextType) { + const inventoryModuleService = await initializeInventoryModule({}) - const inventoryItem = - await inventoryModuleService.retrieveInventoryItem( - params.id - ) + const inventoryItem = await inventoryModuleService.retrieveInventoryItem( + params.id + ) - return NextResponse.json({ inventory_item: inventoryItem }) - } - ``` + return NextResponse.json({ inventory_item: inventoryItem }) +} +``` @@ -185,54 +170,50 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryLevel = - await inventoryModuleService.createInventoryLevels({ - inventory_item_id: request.body.inventory_item_id, - location_id: request.body.location_id, - stocked_quantity: request.body.quantity, - }) + const inventoryLevel = await inventoryModuleService.createInventoryLevels({ + inventory_item_id: request.body.inventory_item_id, + location_id: request.body.location_id, + stocked_quantity: request.body.quantity, + }) - res.json({ inventory_level: inventoryLevel }) - } - ``` + res.json({ inventory_level: inventoryLevel }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - export async function POST(request: Request) { - const inventoryModuleService = - await initializeInventoryModule({}) - const body = await request.json() +export async function POST(request: Request) { + const inventoryModuleService = await initializeInventoryModule({}) + const body = await request.json() - const inventoryLevel = - await inventoryModuleService.createInventoryLevels({ - inventory_item_id: body.inventory_item_id, - location_id: body.location_id, - stocked_quantity: body.quantity, - }) + const inventoryLevel = await inventoryModuleService.createInventoryLevels({ + inventory_item_id: body.inventory_item_id, + location_id: body.location_id, + stocked_quantity: body.quantity, + }) - return NextResponse.json({ inventory_level: inventoryLevel }) - } - ``` + return NextResponse.json({ inventory_level: inventoryLevel }) +} +``` @@ -244,54 +225,50 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryLevel = - await inventoryModuleService.adjustInventory( - request.body.inventory_item_id, - request.body.location_id, - request.body.new_quantity - ) + const inventoryLevel = await inventoryModuleService.adjustInventory( + request.body.inventory_item_id, + request.body.location_id, + request.body.new_quantity + ) - res.json({ inventory_level: inventoryLevel }) - } - ``` + res.json({ inventory_level: inventoryLevel }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - export async function POST(request: Request) { - const inventoryModuleService = - await initializeInventoryModule({}) - const body = await request.json() +export async function POST(request: Request) { + const inventoryModuleService = await initializeInventoryModule({}) + const body = await request.json() - const inventoryLevel = - await inventoryModuleService.adjustInventory( - body.inventory_item_id, - body.location_id, - body.new_quantity - ) + const inventoryLevel = await inventoryModuleService.adjustInventory( + body.inventory_item_id, + body.location_id, + body.new_quantity + ) - return NextResponse.json({ inventory_level: inventoryLevel }) - } - ``` + return NextResponse.json({ inventory_level: inventoryLevel }) +} +``` @@ -303,52 +280,50 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - res.json({ - is_available: await inventoryModuleService.confirmInventory( - request.body.inventory_item_id, - [request.body.location_id], - request.body.required_quantity - ), - }) - } - ``` + res.json({ + is_available: await inventoryModuleService.confirmInventory( + request.body.inventory_item_id, + [request.body.location_id], + request.body.required_quantity + ), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - export async function POST(request: Request) { - const inventoryModuleService = - await initializeInventoryModule({}) - const body = await request.json() +export async function POST(request: Request) { + const inventoryModuleService = await initializeInventoryModule({}) + const body = await request.json() - return NextResponse.json({ - is_available: await inventoryModuleService.confirmInventory( - body.inventory_item_id, - [body.location_id], - body.required_quantity - ), - }) - } - ``` + return NextResponse.json({ + is_available: await inventoryModuleService.confirmInventory( + body.inventory_item_id, + [body.location_id], + body.required_quantity + ), + }) +} +``` @@ -360,56 +335,52 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const reservationItem = - await inventoryModuleService.createReservationItems({ - inventory_item_id: request.body.inventory_item_id, - location_id: request.body.location_id, - quantity: request.body.reserved_quantity, - }) + const reservationItem = await inventoryModuleService.createReservationItems({ + inventory_item_id: request.body.inventory_item_id, + location_id: request.body.location_id, + quantity: request.body.reserved_quantity, + }) - res.json({ reservation_item: reservationItem }) - } - ``` + res.json({ reservation_item: reservationItem }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - export async function POST(request: Request) { - const inventoryModuleService = - await initializeInventoryModule({}) - const body = await request.json() +export async function POST(request: Request) { + const inventoryModuleService = await initializeInventoryModule({}) + const body = await request.json() - const reservationItem = - await inventoryModuleService.createReservationItems({ - inventory_item_id: body.inventory_item_id, - location_id: body.location_id, - quantity: body.reserved_quantity, - }) + const reservationItem = await inventoryModuleService.createReservationItems({ + inventory_item_id: body.inventory_item_id, + location_id: body.location_id, + quantity: body.reserved_quantity, + }) - return NextResponse.json({ - reservation_item: reservationItem, - }) - } - ``` + return NextResponse.json({ + reservation_item: reservationItem, + }) +} +``` @@ -421,89 +392,82 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - const reservedQuantity = - await inventoryModuleService.retrieveReservedQuantity( - request.params.inventory_item_id, - [request.params.location_id] - ) - const stockedQuantity = - await inventoryModuleService.retrieveStockedQuantity( - request.params.inventory_item_id, - [request.params.location_id] - ) - const availableQuantity = - await inventoryModuleService.retrieveAvailableQuantity( - request.params.inventory_item_id, - [request.params.location_id] - ) + const reservedQuantity = + await inventoryModuleService.retrieveReservedQuantity( + request.params.inventory_item_id, + [request.params.location_id] + ) + const stockedQuantity = await inventoryModuleService.retrieveStockedQuantity( + request.params.inventory_item_id, + [request.params.location_id] + ) + const availableQuantity = + await inventoryModuleService.retrieveAvailableQuantity( + request.params.inventory_item_id, + [request.params.location_id] + ) - res.json({ - reserved_quantity: reservedQuantity, - stocked_quantity: stockedQuantity, - available_quantity: availableQuantity, - }) - } - ``` + res.json({ + reserved_quantity: reservedQuantity, + stocked_quantity: stockedQuantity, + available_quantity: availableQuantity, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - type ContextType = { - params: { - inventory_item_id: string - location_id: string - } +type ContextType = { + params: { + inventory_item_id: string + location_id: string } +} - export async function POST( - request: Request, - { params }: ContextType - ) { - const inventoryModuleService = - await initializeInventoryModule({}) +export async function POST(request: Request, { params }: ContextType) { + const inventoryModuleService = await initializeInventoryModule({}) - const reservedQuantity = - await inventoryModuleService.retrieveReservedQuantity( - params.inventory_item_id, - [params.location_id] - ) - const stockedQuantity = - await inventoryModuleService.retrieveStockedQuantity( - params.inventory_item_id, - [params.location_id] - ) - const availableQuantity = - await inventoryModuleService.retrieveAvailableQuantity( - params.inventory_item_id, - [params.location_id] - ) + const reservedQuantity = + await inventoryModuleService.retrieveReservedQuantity( + params.inventory_item_id, + [params.location_id] + ) + const stockedQuantity = await inventoryModuleService.retrieveStockedQuantity( + params.inventory_item_id, + [params.location_id] + ) + const availableQuantity = + await inventoryModuleService.retrieveAvailableQuantity( + params.inventory_item_id, + [params.location_id] + ) - return NextResponse.json({ - reserved_quantity: reservedQuantity, - stocked_quantity: stockedQuantity, - available_quantity: availableQuantity, - }) - } - ``` + return NextResponse.json({ + reserved_quantity: reservedQuantity, + stocked_quantity: stockedQuantity, + available_quantity: availableQuantity, + }) +} +``` @@ -515,52 +479,45 @@ In this document, you’ll find common examples of how you can use the Inventory - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function DELETE( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - await inventoryModuleService.deleteReservationItems([ - request.params.reservation_id, - ]) + await inventoryModuleService.deleteReservationItems([ + request.params.reservation_id, + ]) - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { - initialize as initializeInventoryModule, - } from "@medusajs/inventory-next" +```ts +import { initialize as initializeInventoryModule } from "@medusajs/inventory-next" - type ContextType = { - params: { - reservation_id: string - } +type ContextType = { + params: { + reservation_id: string } +} - export async function DELETE( - request: Request, - { params }: ContextType - ) { - const inventoryModuleService = - await initializeInventoryModule({}) +export async function DELETE(request: Request, { params }: ContextType) { + const inventoryModuleService = await initializeInventoryModule({}) - await inventoryModuleService.deleteReservationItems([ - params.reservation_id, - ]) - } - ``` + await inventoryModuleService.deleteReservationItems([params.reservation_id]) +} +``` diff --git a/www/apps/resources/app/commerce-modules/inventory/page.mdx b/www/apps/resources/app/commerce-modules/inventory/page.mdx index c7df55f915..4d7255ed83 100644 --- a/www/apps/resources/app/commerce-modules/inventory/page.mdx +++ b/www/apps/resources/app/commerce-modules/inventory/page.mdx @@ -17,12 +17,11 @@ Store and manage inventory of any stock-kept item, such as product variants. Inventory items hold details of the underlying stock-kept item, as well as inventory details such as whether the item requires shipping. ```ts -const inventoryItem = - await inventoryModuleService.createInventoryItems({ - sku: "SHIRT", - title: "Green Medusa Shirt", - requires_shipping: true, - }) +const inventoryItem = await inventoryModuleService.createInventoryItems({ + sku: "SHIRT", + title: "Green Medusa Shirt", + requires_shipping: true, +}) ``` ### Inventory Across Locations @@ -30,12 +29,13 @@ const inventoryItem = Inventory items' quantities are set per locations through inventory levels. This gives you more flexibility in managing the quantity of a stock-kept item across different locations, such as different warehouses. ```ts -const inventoryLevel = - await inventoryModuleService.createInventoryLevels([{ +const inventoryLevel = await inventoryModuleService.createInventoryLevels([ + { inventory_item_id: "iitem_123", location_id: "sloc_123", stocked_quantity: 20, - }]) + }, +]) ``` ### Reservation Management @@ -43,12 +43,13 @@ const inventoryLevel = Reserve quantities of inventory items at specific locations for orders or other purposes. The reserved quantity isn't considered for purchase, but can be deleted to revert the reservation. ```ts -const reservationItem = - await inventoryModuleService.createReservationItems([{ +const reservationItem = await inventoryModuleService.createReservationItems([ + { inventory_item_id: "iitem_123", location_id: "sloc_123", quantity: 10, - }]) + }, +]) ``` ### Check Inventory Availability @@ -56,12 +57,11 @@ const reservationItem = Check whether an inventory item has the necessary quantity for purchase. Any reserved quantity is considered unavailable. ```ts -const isAvailable = - await inventoryModuleService.confirmInventory( - inventoryItemId, - [locationId], - neededQuantity - ) +const isAvailable = await inventoryModuleService.confirmInventory( + inventoryItemId, + [locationId], + neededQuantity +) ``` --- @@ -75,62 +75,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const inventoryModuleService: IInventoryService = - request.scope.resolve(ModuleRegistrationName.INVENTORY) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const inventoryModuleService: IInventoryService = request.scope.resolve( + ModuleRegistrationName.INVENTORY + ) - res.json({ - inventory_items: - await inventoryModuleService.listInventoryItems({}), - }) - } - ``` + res.json({ + inventory_items: await inventoryModuleService.listInventoryItems({}), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const inventoryModuleService: IInventoryService = - container.resolve(ModuleRegistrationName.INVENTORY) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const inventoryModuleService: IInventoryService = container.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryItems = - await inventoryModuleService.listInventoryItems({}) - } - ``` + const inventoryItems = await inventoryModuleService.listInventoryItems({}) +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IInventoryService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IInventoryService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const inventoryModuleService: IInventoryService = - container.resolve(ModuleRegistrationName.INVENTORY) +const step1 = createStep("step-1", async (_, { container }) => { + const inventoryModuleService: IInventoryService = container.resolve( + ModuleRegistrationName.INVENTORY + ) - const inventoryItems = - await inventoryModuleService.listInventoryItems({}) - }) - ``` + const inventoryItems = await inventoryModuleService.listInventoryItems({}) +}) +``` diff --git a/www/apps/resources/app/commerce-modules/order/page.mdx b/www/apps/resources/app/commerce-modules/order/page.mdx index 827bb88a1c..519fe18df8 100644 --- a/www/apps/resources/app/commerce-modules/order/page.mdx +++ b/www/apps/resources/app/commerce-modules/order/page.mdx @@ -50,12 +50,11 @@ const draftOrder = await orderModuleService.createOrders({ Apply promotions or discounts to the order's items and shipping methods by adding adjustment lines that are factored into their subtotals. ```ts -const lineAdjustments = - await orderModuleService.addLineItemAdjustments({ - item_id: "cali_123", - code: "50OFF", - amount: 500, - }) +const lineAdjustments = await orderModuleService.addLineItemAdjustments({ + item_id: "cali_123", + code: "50OFF", + amount: 500, +}) const shippingAdjustments = await orderModuleService.addShippingMethodAdjustments({ @@ -78,10 +77,9 @@ Orders can be changed to return items from the customer, exchange an item with a Changes are only applied after confirmation, and order history is preserved through versioning. ```ts -const orderChange = - await orderModuleService.createOrderChange({ - order_id: "ord_123", - }) +const orderChange = await orderModuleService.createOrderChange({ + order_id: "ord_123", +}) // add item to the order await orderModuleService.addOrderAction({ @@ -109,60 +107,57 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IOrderModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const orderModuleService: IOrderModuleService = - req.scope.resolve(ModuleRegistrationName.ORDER) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const orderModuleService: IOrderModuleService = req.scope.resolve( + ModuleRegistrationName.ORDER + ) - res.json({ - orders: await orderModuleService.listOrders(), - }) - } - ``` + res.json({ + orders: await orderModuleService.listOrders(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IOrderModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const orderModuleService: IOrderModuleService = - container.resolve(ModuleRegistrationName.ORDER) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const orderModuleService: IOrderModuleService = container.resolve( + ModuleRegistrationName.ORDER + ) - const orders = await orderModuleService.listOrders() - } - ``` + const orders = await orderModuleService.listOrders() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IOrderModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IOrderModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const orderModuleService: IOrderModuleService = - container.resolve( - ModuleRegistrationName.ORDER - ) - const orders = await orderModuleService.listOrders() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const orderModuleService: IOrderModuleService = container.resolve( + ModuleRegistrationName.ORDER + ) + const orders = await orderModuleService.listOrders() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/payment/examples/page.mdx b/www/apps/resources/app/commerce-modules/payment/examples/page.mdx index 290079f4b4..fdb946bbd6 100644 --- a/www/apps/resources/app/commerce-modules/payment/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/payment/examples/page.mdx @@ -13,56 +13,57 @@ In this guide, you’ll find common examples of how you can use the Payment Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - const paymentCollection = - await paymentModuleService.createPaymentCollections({ - region_id: "reg_123", - currency_code: "usd", - amount: 4000, - }) + const paymentCollection = await paymentModuleService.createPaymentCollections( + { + region_id: "reg_123", + currency_code: "usd", + amount: 4000, + } + ) - res.json({ - payment_collection: paymentCollection, - }) - } - ``` + res.json({ + payment_collection: paymentCollection, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePaymentModule, - } from "@medusajs/payment" +import { initialize as initializePaymentModule } from "@medusajs/payment" - export async function POST(request: Request) { - const paymentModuleService = await initializePaymentModule() +export async function POST(request: Request) { + const paymentModuleService = await initializePaymentModule() - const paymentCollection = - await paymentModuleService.createPaymentCollections({ - region_id: "reg_123", - currency_code: "usd", - amount: 4000, - }) + const paymentCollection = await paymentModuleService.createPaymentCollections( + { + region_id: "reg_123", + currency_code: "usd", + amount: 4000, + } + ) - return NextResponse.json({ - payment_collection: paymentCollection, - }) - } - ``` + return NextResponse.json({ + payment_collection: paymentCollection, + }) +} +``` @@ -74,64 +75,61 @@ In this guide, you’ll find common examples of how you can use the Payment Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - const paymentSession = - await paymentModuleService.createPaymentSession( - "pay_col_123", - { - currency_code: "usd", - provider_id: "system", - amount: 4000, - data: {}, - } - ) + const paymentSession = await paymentModuleService.createPaymentSession( + "pay_col_123", + { + currency_code: "usd", + provider_id: "system", + amount: 4000, + data: {}, + } + ) - res.json({ - payment_session: paymentSession, - }) - } - ``` + res.json({ + payment_session: paymentSession, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePaymentModule, - } from "@medusajs/payment" +import { initialize as initializePaymentModule } from "@medusajs/payment" - export async function POST(request: Request) { - const paymentModuleService = await initializePaymentModule() +export async function POST(request: Request) { + const paymentModuleService = await initializePaymentModule() - const paymentSession = - await paymentModuleService.createPaymentSession( - "pay_col_123", - { - currency_code: "usd", - provider_id: "system", - amount: 4000, - data: {}, - } - ) + const paymentSession = await paymentModuleService.createPaymentSession( + "pay_col_123", + { + currency_code: "usd", + provider_id: "system", + amount: 4000, + data: {}, + } + ) - return NextResponse.json({ - payment_session: paymentSession, - }) - } - ``` + return NextResponse.json({ + payment_session: paymentSession, + }) +} +``` @@ -143,54 +141,49 @@ In this guide, you’ll find common examples of how you can use the Payment Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - const paymentSessions = - await paymentModuleService.listPaymentSessions({ - payment_collection_id: ["pay_col_123"], - }) + const paymentSessions = await paymentModuleService.listPaymentSessions({ + payment_collection_id: ["pay_col_123"], + }) - res.json({ - payment_sessions: paymentSessions, - }) - } - ``` + res.json({ + payment_sessions: paymentSessions, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePaymentModule, - } from "@medusajs/payment" +import { initialize as initializePaymentModule } from "@medusajs/payment" - export async function POST( - request: Request - ) { - const paymentModuleService = await initializePaymentModule() +export async function POST(request: Request) { + const paymentModuleService = await initializePaymentModule() - const paymentSessions = - await paymentModuleService.listPaymentSessions({ - payment_collection_id: ["pay_col_123"], - }) + const paymentSessions = await paymentModuleService.listPaymentSessions({ + payment_collection_id: ["pay_col_123"], + }) - return NextResponse.json({ - payment_sessions: paymentSessions, - }) - } - ``` + return NextResponse.json({ + payment_sessions: paymentSessions, + }) +} +``` @@ -202,56 +195,51 @@ In this guide, you’ll find common examples of how you can use the Payment Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - const payment = - await paymentModuleService.authorizePaymentSession( - "payses_123", - {} - ) + const payment = await paymentModuleService.authorizePaymentSession( + "payses_123", + {} + ) - res.json({ - payment, - }) - } - ``` + res.json({ + payment, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePaymentModule, - } from "@medusajs/payment" +import { initialize as initializePaymentModule } from "@medusajs/payment" - export async function POST( - request: Request - ) { - const paymentModuleService = await initializePaymentModule() +export async function POST(request: Request) { + const paymentModuleService = await initializePaymentModule() - const payment = - await paymentModuleService.authorizePaymentSession( - "payses_123", - {} - ) + const payment = await paymentModuleService.authorizePaymentSession( + "payses_123", + {} + ) - return NextResponse.json({ - payment, - }) - } - ``` + return NextResponse.json({ + payment, + }) +} +``` @@ -263,52 +251,49 @@ In this guide, you’ll find common examples of how you can use the Payment Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - const payments = await paymentModuleService.listPayments({ - session_id: "payses_123", - }) + const payments = await paymentModuleService.listPayments({ + session_id: "payses_123", + }) - res.json({ - payments, - }) - } - ``` + res.json({ + payments, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePaymentModule, - } from "@medusajs/payment" +import { initialize as initializePaymentModule } from "@medusajs/payment" - export async function GET( - request: Request - ) { - const paymentModuleService = await initializePaymentModule() +export async function GET(request: Request) { + const paymentModuleService = await initializePaymentModule() - const payments = await paymentModuleService.listPayments({ - session_id: "payses_123", - }) + const payments = await paymentModuleService.listPayments({ + session_id: "payses_123", + }) - return NextResponse.json({ - payments, - }) - } - ``` + return NextResponse.json({ + payments, + }) +} +``` @@ -320,52 +305,49 @@ In this guide, you’ll find common examples of how you can use the Payment Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - const payment = await paymentModuleService.capturePayment({ - payment_id: "pay_123", - }) + const payment = await paymentModuleService.capturePayment({ + payment_id: "pay_123", + }) - res.json({ - payment, - }) - } - ``` + res.json({ + payment, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePaymentModule, - } from "@medusajs/payment" +import { initialize as initializePaymentModule } from "@medusajs/payment" - export async function POST( - request: Request - ) { - const paymentModuleService = await initializePaymentModule() +export async function POST(request: Request) { + const paymentModuleService = await initializePaymentModule() - const payment = await paymentModuleService.capturePayment({ - payment_id: "pay_123", - }) + const payment = await paymentModuleService.capturePayment({ + payment_id: "pay_123", + }) - return NextResponse.json({ - payment, - }) - } - ``` + return NextResponse.json({ + payment, + }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/payment/page.mdx b/www/apps/resources/app/commerce-modules/payment/page.mdx index 375969b385..de105d094e 100644 --- a/www/apps/resources/app/commerce-modules/payment/page.mdx +++ b/www/apps/resources/app/commerce-modules/payment/page.mdx @@ -18,12 +18,11 @@ The Payment Module provides payment functionalities that allow you to process pa All payment processing starts with creating a payment collection. ```ts -const paymentCollection = - await paymentModuleService.createPaymentCollections({ - region_id: "reg_123", - currency_code: "usd", - amount: 5000, - }) +const paymentCollection = await paymentModuleService.createPaymentCollections({ + region_id: "reg_123", + currency_code: "usd", + amount: 5000, +}) ``` ### Authorize, Capture, and Refund Payment @@ -41,18 +40,14 @@ await paymentModuleService.capturePayment({ Use payment providers like Stripe to handle and process payments. ```ts -const payment = - await paymentModuleService.createPaymentSession( - "pay_col_1", - { - provider_id: "stripe", - amount: 1000, - currency_code: "usd", - data: { - // necessary data for the payment provider - }, - } - ) +const payment = await paymentModuleService.createPaymentSession("pay_col_1", { + provider_id: "stripe", + amount: 1000, + currency_code: "usd", + data: { + // necessary data for the payment provider + }, +}) ``` ### Handle Webhook Events @@ -85,64 +80,60 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const paymentModuleService: IPaymentModuleService = - req.scope.resolve(ModuleRegistrationName.PAYMENT) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const paymentModuleService: IPaymentModuleService = req.scope.resolve( + ModuleRegistrationName.PAYMENT + ) - res.json({ - payment_collections: - await paymentModuleService.listPaymentCollections(), - }) - } - ``` + res.json({ + payment_collections: await paymentModuleService.listPaymentCollections(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const paymentModuleService: IPaymentModuleService = - container.resolve(ModuleRegistrationName.PAYMENT) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const paymentModuleService: IPaymentModuleService = container.resolve( + ModuleRegistrationName.PAYMENT + ) - const payment_collections = - await paymentModuleService.listPaymentCollections() - } - ``` + const payment_collections = + await paymentModuleService.listPaymentCollections() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IPaymentModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IPaymentModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const paymentModuleService: IPaymentModuleService = - container.resolve( - ModuleRegistrationName.PAYMENT - ) +const step1 = createStep("step-1", async (_, { container }) => { + const paymentModuleService: IPaymentModuleService = container.resolve( + ModuleRegistrationName.PAYMENT + ) - const payment_collections = - await paymentModuleService.listPaymentCollections() - }) - ``` + const payment_collections = + await paymentModuleService.listPaymentCollections() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/pricing/examples/page.mdx b/www/apps/resources/app/commerce-modules/pricing/examples/page.mdx index f6d6787460..67b19292b7 100644 --- a/www/apps/resources/app/commerce-modules/pricing/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/pricing/examples/page.mdx @@ -13,67 +13,66 @@ In this document, you’ll find common examples of how you can use the Pricing M - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - const priceSet = await pricingModuleService.createPriceSets([ - { - prices: [ - { - currency_code: "eur", - amount: 10, - rules: { - region_id: "reg_123", - }, + const priceSet = await pricingModuleService.createPriceSets([ + { + prices: [ + { + currency_code: "eur", + amount: 10, + rules: { + region_id: "reg_123", }, - ], - }, - ]) + }, + ], + }, + ]) - res.json({ price_set: priceSet }) - } - ``` + res.json({ price_set: priceSet }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePricingModule, - } from "@medusajs/pricing" +import { initialize as initializePricingModule } from "@medusajs/pricing" - export async function POST(request: Request) { - const pricingModuleService = await initializePricingModule() - const body = await request.json() +export async function POST(request: Request) { + const pricingModuleService = await initializePricingModule() + const body = await request.json() - const priceSet = await pricingModuleService.createPriceSets([ - { - prices: [ - { - currency_code: "eur", - amount: 10, - rules: { - region_id: "reg_123", - }, + const priceSet = await pricingModuleService.createPriceSets([ + { + prices: [ + { + currency_code: "eur", + amount: 10, + rules: { + region_id: "reg_123", }, - ], - }, - ]) + }, + ], + }, + ]) - return NextResponse.json({ price_set: priceSet }) - } - ``` + return NextResponse.json({ price_set: priceSet }) +} +``` @@ -85,42 +84,41 @@ In this document, you’ll find common examples of how you can use the Pricing M - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - const priceSets = await pricingModuleService.listPriceSets() + const priceSets = await pricingModuleService.listPriceSets() - res.json({ price_sets: priceSets }) - } - ``` + res.json({ price_sets: priceSets }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePricingModule, - } from "@medusajs/pricing" +import { initialize as initializePricingModule } from "@medusajs/pricing" - export async function GET(request: Request) { - const pricingModuleService = await initializePricingModule() +export async function GET(request: Request) { + const pricingModuleService = await initializePricingModule() - const priceSets = await pricingModuleService.listPriceSets() + const priceSets = await pricingModuleService.listPriceSets() - return NextResponse.json({ price_sets: priceSets }) - } - ``` + return NextResponse.json({ price_sets: priceSets }) +} +``` @@ -132,48 +130,41 @@ In this document, you’ll find common examples of how you can use the Pricing M - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - const priceSet = await pricingModuleService.retrievePriceSet( - "pset_123" - ) + const priceSet = await pricingModuleService.retrievePriceSet("pset_123") - res.json({ price_set: priceSet }) - } - ``` + res.json({ price_set: priceSet }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePricingModule, - } from "@medusajs/pricing" +import { initialize as initializePricingModule } from "@medusajs/pricing" - export async function GET( - request: Request - ) { - const pricingModuleService = await initializePricingModule() +export async function GET(request: Request) { + const pricingModuleService = await initializePricingModule() - const priceSet = await pricingModuleService.retrievePriceSet( - "pset_123" - ) + const priceSet = await pricingModuleService.retrievePriceSet("pset_123") - return NextResponse.json({ price_set: priceSet }) - } - ``` + return NextResponse.json({ price_set: priceSet }) +} +``` @@ -185,65 +176,64 @@ In this document, you’ll find common examples of how you can use the Pricing M - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - const priceSet = await pricingModuleService.addPrices({ - priceSetId: "pset_123", - prices: [ - { - amount: 500, - currency_code: "USD", - rules: { - region_id: "reg_123", - }, + const priceSet = await pricingModuleService.addPrices({ + priceSetId: "pset_123", + prices: [ + { + amount: 500, + currency_code: "USD", + rules: { + region_id: "reg_123", }, - ], - }) + }, + ], + }) - res.json({ price_set: priceSet }) - } - ``` + res.json({ price_set: priceSet }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePricingModule, - } from "@medusajs/pricing" +import { initialize as initializePricingModule } from "@medusajs/pricing" - export async function POST(request: Request) { - const pricingModuleService = await initializePricingModule() - const body = await request.json() +export async function POST(request: Request) { + const pricingModuleService = await initializePricingModule() + const body = await request.json() - const priceSet = await pricingModuleService.addPrices({ - priceSetId: "pset_123", - prices: [ - { - amount: 500, - currency_code: "USD", - rules: { - region_id: "reg_123", - }, + const priceSet = await pricingModuleService.addPrices({ + priceSetId: "pset_123", + prices: [ + { + amount: 500, + currency_code: "USD", + rules: { + region_id: "reg_123", }, - ], - }) + }, + ], + }) - return NextResponse.json({ price_set: priceSet }) - } - ``` + return NextResponse.json({ price_set: priceSet }) +} +``` @@ -255,83 +245,80 @@ In this document, you’ll find common examples of how you can use the Pricing M - ```ts collapsibleLines="1-8" expandButtonLabel="Show Imports" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { PriceListType } from "@medusajs/utils" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts collapsibleLines="1-8" expandButtonLabel="Show Imports" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { PriceListType } from "@medusajs/utils" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - const priceLists = - await pricingModuleService.createPriceLists([ + const priceLists = await pricingModuleService.createPriceLists([ + { + title: "My Sale", + description: "This is my sale", + type: PriceListType.SALE, + starts_at: Date.parse("01/10/2023").toString(), + ends_at: Date.parse("31/10/2023").toString(), + rules: { + region_id: ["reg_123", "reg_321"], + }, + prices: [ { - title: "My Sale", - description: "This is my sale", - type: PriceListType.SALE, - starts_at: Date.parse("01/10/2023").toString(), - ends_at: Date.parse("31/10/2023").toString(), - rules: { - region_id: ["reg_123", "reg_321"], - }, - prices: [ - { - amount: 400, - currency_code: "EUR", - price_set_id: "pset_124", - }, - ], + amount: 400, + currency_code: "EUR", + price_set_id: "pset_124", }, - ]) + ], + }, + ]) - res.json({ price_lists: priceLists }) - } - ``` + res.json({ price_lists: priceLists }) +} +``` - ```ts - import { NextResponse } from "next/server" - import { PriceListType } from "@medusajs/medusa" - - import { - initialize as initializePricingModule, - } from "@medusajs/pricing" - import { PriceListType } from "@medusajs/utils" +```ts +import { NextResponse } from "next/server" +import { PriceListType } from "@medusajs/medusa" - export async function POST(request: Request) { - const pricingModuleService = await initializePricingModule() +import { initialize as initializePricingModule } from "@medusajs/pricing" +import { PriceListType } from "@medusajs/utils" - const priceLists = - await pricingModuleService.createPriceLists([ +export async function POST(request: Request) { + const pricingModuleService = await initializePricingModule() + + const priceLists = await pricingModuleService.createPriceLists([ + { + title: "My Sale", + description: "This is my sale", + type: PriceListType.SALE, + starts_at: Date.parse("01/10/2023").toString(), + ends_at: Date.parse("31/10/2023").toString(), + rules: { + region_id: ["reg_123", "reg_321"], + }, + prices: [ { - title: "My Sale", - description: "This is my sale", - type: PriceListType.SALE, - starts_at: Date.parse("01/10/2023").toString(), - ends_at: Date.parse("31/10/2023").toString(), - rules: { - region_id: ["reg_123", "reg_321"], - }, - prices: [ - { - amount: 400, - currency_code: "EUR", - price_set_id: "pset_124", - }, - ], + amount: 400, + currency_code: "EUR", + price_set_id: "pset_124", }, - ]) + ], + }, + ]) - return NextResponse.json({ price_lists: priceLists }) - } - ``` + return NextResponse.json({ price_lists: priceLists }) +} +``` @@ -343,62 +330,59 @@ In this document, you’ll find common examples of how you can use the Pricing M - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - const price = await pricingModuleService.calculatePrices( - { - id: ["pset_123"], + const price = await pricingModuleService.calculatePrices( + { + id: ["pset_123"], + }, + { + context: { + currency_code: "eur", }, - { - context: { - currency_code: "eur", - }, - } - ) + } + ) - res.json({ price }) - } - ``` + res.json({ price }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePricingModule, - } from "@medusajs/pricing" +import { initialize as initializePricingModule } from "@medusajs/pricing" - export async function GET( - request: Request - ) { - const pricingModuleService = await initializePricingModule() +export async function GET(request: Request) { + const pricingModuleService = await initializePricingModule() - const price = await pricingModuleService.calculatePrices( - { - id: ["pset_123"], + const price = await pricingModuleService.calculatePrices( + { + id: ["pset_123"], + }, + { + context: { + currency_code: "eur", }, - { - context: { - currency_code: "eur", - }, - } - ) + } + ) - return NextResponse.json({ price }) - } - ``` + return NextResponse.json({ price }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/pricing/page.mdx b/www/apps/resources/app/commerce-modules/pricing/page.mdx index 1f37865466..9cffcba0a0 100644 --- a/www/apps/resources/app/commerce-modules/pricing/page.mdx +++ b/www/apps/resources/app/commerce-modules/pricing/page.mdx @@ -24,12 +24,12 @@ const priceSet = await pricingModuleService.createPriceSets({ currency_code: "USD", }, { - amount: 400, - currency_code: "EUR", - min_quantity: 0, - max_quantity: 4, - rules: {}, - }, + amount: 400, + currency_code: "EUR", + min_quantity: 0, + max_quantity: 4, + rules: {}, + }, ], }) ``` @@ -58,23 +58,25 @@ const priceSet = await pricingModuleService.addPrices({ Price lists allow you to group prices and apply them only in specific conditions. You can also use them to override existing prices for the specified conditions. ```ts -const priceList = await pricingModuleService.createPriceLists([{ - title: "My Sale", - description: "Sale on selected items.", - type: "sale", - starts_at: Date.parse("01/10/2023").toString(), - ends_at: Date.parse("31/10/2023").toString(), - rules: { - region_id: ["reg_123", "reg_321"], - }, - prices: [ - { - amount: 400, - currency_code: "EUR", - price_set_id: "pset_123", +const priceList = await pricingModuleService.createPriceLists([ + { + title: "My Sale", + description: "Sale on selected items.", + type: "sale", + starts_at: Date.parse("01/10/2023").toString(), + ends_at: Date.parse("31/10/2023").toString(), + rules: { + region_id: ["reg_123", "reg_321"], }, - ], -}]) + prices: [ + { + amount: 400, + currency_code: "EUR", + price_set_id: "pset_123", + }, + ], + }, +]) ``` ### Price Calculation Strategy @@ -104,59 +106,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const pricingModuleService: IPricingModuleService = - request.scope.resolve(ModuleRegistrationName.PRICING) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const pricingModuleService: IPricingModuleService = request.scope.resolve( + ModuleRegistrationName.PRICING + ) - res.json({ - price_sets: await pricingModuleService.listPriceSets(), - }) - } - ``` + res.json({ + price_sets: await pricingModuleService.listPriceSets(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const pricingModuleService: IPricingModuleService = - container.resolve(ModuleRegistrationName.PRICING) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const pricingModuleService: IPricingModuleService = container.resolve( + ModuleRegistrationName.PRICING + ) - const priceSets = await pricingModuleService.listPriceSets() - } - ``` + const priceSets = await pricingModuleService.listPriceSets() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IPricingModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IPricingModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const pricingModuleService: IPricingModuleService = - container.resolve(ModuleRegistrationName.PRICING) +const step1 = createStep("step-1", async (_, { container }) => { + const pricingModuleService: IPricingModuleService = container.resolve( + ModuleRegistrationName.PRICING + ) - const priceSets = await pricingModuleService.listPriceSets() - }) - ``` + const priceSets = await pricingModuleService.listPriceSets() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/product/examples/page.mdx b/www/apps/resources/app/commerce-modules/product/examples/page.mdx index 5da0d88d30..4d13294ead 100644 --- a/www/apps/resources/app/commerce-modules/product/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/product/examples/page.mdx @@ -13,80 +13,76 @@ In this guide, you’ll find common examples of how you can use the Product Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - const products = await productModuleService.createProducts([ - { - title: "Medusa Shirt", - options: [ - { - title: "Color", - }, - ], - variants: [ - { - title: "Black Shirt", - options: [ - { - value: "Black", - }, - ], - }, - ], - }, - ]) + const products = await productModuleService.createProducts([ + { + title: "Medusa Shirt", + options: [ + { + title: "Color", + }, + ], + variants: [ + { + title: "Black Shirt", + options: [ + { + value: "Black", + }, + ], + }, + ], + }, + ]) - res.json({ products }) - } - ``` + res.json({ products }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeProductModule, - } from "@medusajs/product" +import { initialize as initializeProductModule } from "@medusajs/product" - export async function POST(request: Request) { - const productModuleService = await initializeProductModule() +export async function POST(request: Request) { + const productModuleService = await initializeProductModule() - const products = await productModuleService.createProducts([ - { - title: "Medusa Shirt", - options: [ - { - title: "Color", - }, - ], - variants: [ - { - title: "Black Shirt", - options: [ - { - value: "Black", - }, - ], - }, - ], - }, - ]) + const products = await productModuleService.createProducts([ + { + title: "Medusa Shirt", + options: [ + { + title: "Color", + }, + ], + variants: [ + { + title: "Black Shirt", + options: [ + { + value: "Black", + }, + ], + }, + ], + }, + ]) - return NextResponse.json({ products }) - } - ``` + return NextResponse.json({ products }) +} +``` @@ -98,42 +94,38 @@ In this guide, you’ll find common examples of how you can use the Product Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function GET(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - const products = await productModuleService.listProducts() + const products = await productModuleService.listProducts() - res.json({ products }) - } - ``` + res.json({ products }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeProductModule, - } from "@medusajs/product" +import { initialize as initializeProductModule } from "@medusajs/product" - export async function GET(request: Request) { - const productModuleService = await initializeProductModule() +export async function GET(request: Request) { + const productModuleService = await initializeProductModule() - const products = await productModuleService.listProducts() + const products = await productModuleService.listProducts() - return NextResponse.json({ products }) - } - ``` + return NextResponse.json({ products }) +} +``` @@ -145,50 +137,42 @@ In this guide, you’ll find common examples of how you can use the Product Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function GET(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - const product = await productModuleService.retrieveProduct( - request.params.id - ) + const product = await productModuleService.retrieveProduct(request.params.id) - res.json({ product }) - } - ``` + res.json({ product }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeProductModule, - } from "@medusajs/product" +import { initialize as initializeProductModule } from "@medusajs/product" - export async function GET( - request: Request, - { params }: { params: Record }) { - - const { id } = params - const productModuleService = await initializeProductModule() +export async function GET( + request: Request, + { params }: { params: Record } +) { + const { id } = params + const productModuleService = await initializeProductModule() - const product = await productModuleService.retrieveProduct( - id - ) + const product = await productModuleService.retrieveProduct(id) - return NextResponse.json({ product }) - } - ``` + return NextResponse.json({ product }) +} +``` @@ -200,46 +184,42 @@ In this guide, you’ll find common examples of how you can use the Product Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function GET(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - const data = await productModuleService.listProducts({ - handle: "shirt", - }) + const data = await productModuleService.listProducts({ + handle: "shirt", + }) - res.json({ product: data[0] }) - } - ``` + res.json({ product: data[0] }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeProductModule, - } from "@medusajs/product" +import { initialize as initializeProductModule } from "@medusajs/product" - export async function GET(request: Request) { - const productModuleService = await initializeProductModule() +export async function GET(request: Request) { + const productModuleService = await initializeProductModule() - const data = await productModuleService.listProducts({ - handle: "shirt", - }) + const data = await productModuleService.listProducts({ + handle: "shirt", + }) - return NextResponse.json({ product: data[0] }) - } - ``` + return NextResponse.json({ product: data[0] }) +} +``` @@ -251,44 +231,38 @@ In this guide, you’ll find common examples of how you can use the Product Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - const categories = await productModuleService - .listProductCategories() + const categories = await productModuleService.listProductCategories() - res.json({ categories }) - } - ``` + res.json({ categories }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeProductModule, - } from "@medusajs/product" +import { initialize as initializeProductModule } from "@medusajs/product" - export async function GET(request: Request) { - const productModuleService = await initializeProductModule() +export async function GET(request: Request) { + const productModuleService = await initializeProductModule() - const categories = await productModuleService - .listProductCategories() + const categories = await productModuleService.listProductCategories() - return NextResponse.json({ categories }) - } - ``` + return NextResponse.json({ categories }) +} +``` @@ -300,52 +274,46 @@ In this guide, you’ll find common examples of how you can use the Product Modu - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function POST(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - const data = await productModuleService - .listProductCategories({ - handle: request.params.handle, - }) + const data = await productModuleService.listProductCategories({ + handle: request.params.handle, + }) - res.json({ category: data[0] }) - } - ``` + res.json({ category: data[0] }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeProductModule, - } from "@medusajs/product" +import { initialize as initializeProductModule } from "@medusajs/product" - export async function GET( - request: Request, - { params }: { params: Record }) { - - const { handle } = params - const productModuleService = await initializeProductModule() +export async function GET( + request: Request, + { params }: { params: Record } +) { + const { handle } = params + const productModuleService = await initializeProductModule() - const data = await productModuleService - .listProductCategories({ - handle, - }) + const data = await productModuleService.listProductCategories({ + handle, + }) - return NextResponse.json({ category: data[0] }) - } - ``` + return NextResponse.json({ category: data[0] }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/product/page.mdx b/www/apps/resources/app/commerce-modules/product/page.mdx index 12ab3831de..eb33795edd 100644 --- a/www/apps/resources/app/commerce-modules/product/page.mdx +++ b/www/apps/resources/app/commerce-modules/product/page.mdx @@ -69,59 +69,55 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ) { - const productModuleService: IProductModuleService = - request.scope.resolve(ModuleRegistrationName.PRODUCT) +export async function GET(request: MedusaRequest, res: MedusaResponse) { + const productModuleService: IProductModuleService = request.scope.resolve( + ModuleRegistrationName.PRODUCT + ) - res.json({ - products: await productModuleService.listProducts(), - }) - } - ``` + res.json({ + products: await productModuleService.listProducts(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const productModuleService: IProductModuleService = container.resolve( + ModuleRegistrationName.PRODUCT + ) - const products = await productModuleService.listProducts() - } - ``` + const products = await productModuleService.listProducts() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IProductModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) +const step1 = createStep("step-1", async (_, { container }) => { + const productModuleService: IProductModuleService = container.resolve( + ModuleRegistrationName.PRODUCT + ) - const products = await productModuleService.listProducts() - }) - ``` + const products = await productModuleService.listProducts() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/promotion/examples/page.mdx b/www/apps/resources/app/commerce-modules/promotion/examples/page.mdx index f8c369e9bd..e8b83a3aa4 100644 --- a/www/apps/resources/app/commerce-modules/promotion/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/promotion/examples/page.mdx @@ -13,62 +13,60 @@ In this document, you’ll find common examples of how you can use the Promotion - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const promotionModuleService: IPromotionModuleService = - request.scope.resolve(ModuleRegistrationName.PROMOTION) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const promotionModuleService: IPromotionModuleService = request.scope.resolve( + ModuleRegistrationName.PROMOTION + ) - const promotion = await promotionModuleService.createPromotions({ - code: "10%OFF", - type: "standard", - application_method: { - type: "percentage", - target_type: "order", - value: "10", - currency_code: "usd", - }, - }) + const promotion = await promotionModuleService.createPromotions({ + code: "10%OFF", + type: "standard", + application_method: { + type: "percentage", + target_type: "order", + value: "10", + currency_code: "usd", + }, + }) - res.json({ promotion }) - } - ``` + res.json({ promotion }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePromotionModule, - } from "@medusajs/promotion" +import { initialize as initializePromotionModule } from "@medusajs/promotion" - export async function POST(request: Request) { - const promotionModuleService = - await initializePromotionModule() - const body = await request.json() +export async function POST(request: Request) { + const promotionModuleService = await initializePromotionModule() + const body = await request.json() - const promotion = await promotionModuleService.createPromotions({ - code: "10%OFF", - type: "standard", - application_method: { - type: "percentage", - target_type: "order", - value: "10", - currency_code: "usd", - }, - }) + const promotion = await promotionModuleService.createPromotions({ + code: "10%OFF", + type: "standard", + application_method: { + type: "percentage", + target_type: "order", + value: "10", + currency_code: "usd", + }, + }) - return NextResponse.json({ promotion }) - } - ``` + return NextResponse.json({ promotion }) +} +``` @@ -80,58 +78,52 @@ In this document, you’ll find common examples of how you can use the Promotion - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const promotionModuleService: IPromotionModuleService = - request.scope.resolve(ModuleRegistrationName.PROMOTION) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const promotionModuleService: IPromotionModuleService = request.scope.resolve( + ModuleRegistrationName.PROMOTION + ) - const campaign = await promotionModuleService.createCampaigns( - { - name: "Summer Discounts", - campaign_identifier: "G-123445", - starts_at: new Date("2024-05-02"), - ends_at: new Date("2024-07-20"), - } - ) + const campaign = await promotionModuleService.createCampaigns({ + name: "Summer Discounts", + campaign_identifier: "G-123445", + starts_at: new Date("2024-05-02"), + ends_at: new Date("2024-07-20"), + }) - res.json({ campaign }) - } - ``` + res.json({ campaign }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePromotionModule, - } from "@medusajs/promotion" +import { initialize as initializePromotionModule } from "@medusajs/promotion" - export async function POST(request: Request) { - const promotionModuleService = - await initializePromotionModule() - const body = await request.json() +export async function POST(request: Request) { + const promotionModuleService = await initializePromotionModule() + const body = await request.json() - const campaign = await promotionModuleService.createCampaigns( - { - name: "Summer Discounts", - campaign_identifier: "G-123445", - starts_at: new Date("2024-05-02"), - ends_at: new Date("2024-07-20"), - } - ) + const campaign = await promotionModuleService.createCampaigns({ + name: "Summer Discounts", + campaign_identifier: "G-123445", + starts_at: new Date("2024-05-02"), + ends_at: new Date("2024-07-20"), + }) - return NextResponse.json({ campaign }) - } - ``` + return NextResponse.json({ campaign }) +} +``` @@ -143,75 +135,73 @@ In this document, you’ll find common examples of how you can use the Promotion - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const promotionModuleService: IPromotionModuleService = - request.scope.resolve(ModuleRegistrationName.PROMOTION) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const promotionModuleService: IPromotionModuleService = request.scope.resolve( + ModuleRegistrationName.PROMOTION + ) - const promotion = await promotionModuleService.createPromotions({ - code: "10%OFF", - type: "standard", - application_method: { - type: "percentage", - target_type: "order", - value: "10", - currency_code: "usd", + const promotion = await promotionModuleService.createPromotions({ + code: "10%OFF", + type: "standard", + application_method: { + type: "percentage", + target_type: "order", + value: "10", + currency_code: "usd", + }, + rules: [ + { + attribute: "customer_group_id", + operator: "eq", + values: ["VIP"], }, - rules: [ - { - attribute: "customer_group_id", - operator: "eq", - values: ["VIP"], - }, - ], - }) + ], + }) - res.json({ promotion }) - } - ``` + res.json({ promotion }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePromotionModule, - } from "@medusajs/promotion" +import { initialize as initializePromotionModule } from "@medusajs/promotion" - export async function POST(request: Request) { - const promotionModuleService = - await initializePromotionModule() +export async function POST(request: Request) { + const promotionModuleService = await initializePromotionModule() - const promotion = await promotionModuleService.createPromotions({ - code: "10%OFF", - type: "standard", - application_method: { - type: "percentage", - target_type: "order", - value: "10", - currency_code: "usd", + const promotion = await promotionModuleService.createPromotions({ + code: "10%OFF", + type: "standard", + application_method: { + type: "percentage", + target_type: "order", + value: "10", + currency_code: "usd", + }, + rules: [ + { + attribute: "customer_group_id", + operator: "eq", + values: ["VIP"], }, - rules: [ - { - attribute: "customer_group_id", - operator: "eq", - values: ["VIP"], - }, - ], - }) + ], + }) - return NextResponse.json({ promotion }) - } - ``` + return NextResponse.json({ promotion }) +} +``` @@ -223,43 +213,41 @@ In this document, you’ll find common examples of how you can use the Promotion - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const promotionModuleService: IPromotionModuleService = - request.scope.resolve(ModuleRegistrationName.PROMOTION) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const promotionModuleService: IPromotionModuleService = request.scope.resolve( + ModuleRegistrationName.PROMOTION + ) - res.json({ - promotions: await promotionModuleService.listPromotions(), - }) - } - ``` + res.json({ + promotions: await promotionModuleService.listPromotions(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializePromotionModule, - } from "@medusajs/promotion" +import { initialize as initializePromotionModule } from "@medusajs/promotion" - export async function GET(request: Request) { - const promotionModuleService = - await initializePromotionModule() +export async function GET(request: Request) { + const promotionModuleService = await initializePromotionModule() - return NextResponse.json({ - promotions: await promotionModuleService.listPromotions(), - }) - } - ``` + return NextResponse.json({ + promotions: await promotionModuleService.listPromotions(), + }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/promotion/page.mdx b/www/apps/resources/app/commerce-modules/promotion/page.mdx index 9063556876..fe2fe1db82 100644 --- a/www/apps/resources/app/commerce-modules/promotion/page.mdx +++ b/www/apps/resources/app/commerce-modules/promotion/page.mdx @@ -60,14 +60,12 @@ A campaign combines promotions under the same conditions, such as start and end A campaign can also have an identifier for tracking purposes, such as tracking through tools like Google Analytics. ```ts -const campaign = await promotionModuleService.createCampaigns( - { - name: "Summer Discounts", - campaign_identifier: "G-123445", - starts_at: new Date("2024-05-02"), - ends_at: new Date("2024-07-20"), - } -) +const campaign = await promotionModuleService.createCampaigns({ + name: "Summer Discounts", + campaign_identifier: "G-123445", + starts_at: new Date("2024-05-02"), + ends_at: new Date("2024-07-20"), +}) ``` --- @@ -81,59 +79,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const promotionModuleService: IPromotionModuleService = - request.scope.resolve(ModuleRegistrationName.PROMOTION) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const promotionModuleService: IPromotionModuleService = request.scope.resolve( + ModuleRegistrationName.PROMOTION + ) - res.json({ - promotions: await promotionModuleService.listPromotions(), - }) - } - ``` + res.json({ + promotions: await promotionModuleService.listPromotions(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const promotionModuleService: IPromotionModuleService = - container.resolve(ModuleRegistrationName.PROMOTION) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const promotionModuleService: IPromotionModuleService = container.resolve( + ModuleRegistrationName.PROMOTION + ) - const promotions = await promotionModuleService.listPromotions() - } - ``` + const promotions = await promotionModuleService.listPromotions() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IPromotionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IPromotionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const promotionModuleService: IPromotionModuleService = - container.resolve(ModuleRegistrationName.PROMOTION) +const step1 = createStep("step-1", async (_, { container }) => { + const promotionModuleService: IPromotionModuleService = container.resolve( + ModuleRegistrationName.PROMOTION + ) - const promotions = await promotionModuleService.listPromotions() - }) - ``` + const promotions = await promotionModuleService.listPromotions() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/region/examples/page.mdx b/www/apps/resources/app/commerce-modules/region/examples/page.mdx index 77c270c80d..c48d10a4ef 100644 --- a/www/apps/resources/app/commerce-modules/region/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/region/examples/page.mdx @@ -13,52 +13,51 @@ In this guide, you’ll find common examples of how you can use the Region Modul - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const regionModuleService: IRegionModuleService = - req.scope.resolve(ModuleRegistrationName.REGION) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const regionModuleService: IRegionModuleService = req.scope.resolve( + ModuleRegistrationName.REGION + ) - const region = await regionModuleService.createRegions({ - name: "Europe", - currency_code: "eur", - }) + const region = await regionModuleService.createRegions({ + name: "Europe", + currency_code: "eur", + }) - res.json({ - region, - }) - } - ``` + res.json({ + region, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeRegionModule, - } from "@medusajs/region" +import { initialize as initializeRegionModule } from "@medusajs/region" - export async function POST(request: Request) { - const regionModuleService = await initializeRegionModule() +export async function POST(request: Request) { + const regionModuleService = await initializeRegionModule() - const region = await regionModuleService.createRegions({ - name: "Europe", - currency_code: "eur", - }) + const region = await regionModuleService.createRegions({ + name: "Europe", + currency_code: "eur", + }) - res.json({ - region, - }) - } - ``` + res.json({ + region, + }) +} +``` @@ -70,42 +69,41 @@ In this guide, you’ll find common examples of how you can use the Region Modul - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const regionModuleService: IRegionModuleService = - req.scope.resolve(ModuleRegistrationName.REGION) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const regionModuleService: IRegionModuleService = req.scope.resolve( + ModuleRegistrationName.REGION + ) - res.json({ - regions: await regionModuleService.listRegions(), - }) - } - ``` + res.json({ + regions: await regionModuleService.listRegions(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeRegionModule, - } from "@medusajs/region" +import { initialize as initializeRegionModule } from "@medusajs/region" - export async function GET(request: Request) { - const regionModuleService = await initializeRegionModule() +export async function GET(request: Request) { + const regionModuleService = await initializeRegionModule() - return NextResponse.json({ - regions: await regionModuleService.listRegions(), - }) - } - ``` + return NextResponse.json({ + regions: await regionModuleService.listRegions(), + }) +} +``` @@ -117,46 +115,41 @@ In this guide, you’ll find common examples of how you can use the Region Modul - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const regionModuleService: IRegionModuleService = - req.scope.resolve(ModuleRegistrationName.REGION) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const regionModuleService: IRegionModuleService = req.scope.resolve( + ModuleRegistrationName.REGION + ) - const region = await regionModuleService - .retrieveRegion("reg_123") + const region = await regionModuleService.retrieveRegion("reg_123") - res.json({ region }) - } - ``` + res.json({ region }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeRegionModule, - } from "@medusajs/region" +import { initialize as initializeRegionModule } from "@medusajs/region" - export async function GET( - request: Request - ) { - const regionModuleService = await initializeRegionModule() +export async function GET(request: Request) { + const regionModuleService = await initializeRegionModule() - const region = await regionModuleService - .retrieveRegion("reg_123") + const region = await regionModuleService.retrieveRegion("reg_123") - return NextResponse.json({ region }) - } - ``` + return NextResponse.json({ region }) +} +``` @@ -168,50 +161,45 @@ In this guide, you’ll find common examples of how you can use the Region Modul - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const regionModuleService: IRegionModuleService = - req.scope.resolve(ModuleRegistrationName.REGION) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const regionModuleService: IRegionModuleService = req.scope.resolve( + ModuleRegistrationName.REGION + ) - const region = await regionModuleService - .updateRegions("reg_123", { - automatic_taxes: false, - }) + const region = await regionModuleService.updateRegions("reg_123", { + automatic_taxes: false, + }) - res.json({ region }) - } - ``` + res.json({ region }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeRegionModule, - } from "@medusajs/region" +import { initialize as initializeRegionModule } from "@medusajs/region" - export async function POST( - request: Request - ) { - const regionModuleService = await initializeRegionModule() +export async function POST(request: Request) { + const regionModuleService = await initializeRegionModule() - const region = await regionModuleService - .updateRegions("reg_123", { - automatic_taxes: false, - }) + const region = await regionModuleService.updateRegions("reg_123", { + automatic_taxes: false, + }) - return NextResponse.json({ region }) - } - ``` + return NextResponse.json({ region }) +} +``` @@ -223,42 +211,39 @@ In this guide, you’ll find common examples of how you can use the Region Modul - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const regionModuleService: IRegionModuleService = - req.scope.resolve(ModuleRegistrationName.REGION) +export async function DELETE( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const regionModuleService: IRegionModuleService = req.scope.resolve( + ModuleRegistrationName.REGION + ) - await regionModuleService.deleteRegions("reg_123") + await regionModuleService.deleteRegions("reg_123") - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeRegionModule, - } from "@medusajs/region" +import { initialize as initializeRegionModule } from "@medusajs/region" - export async function DELETE( - request: Request - ) { - const regionModuleService = await initializeRegionModule() +export async function DELETE(request: Request) { + const regionModuleService = await initializeRegionModule() - await regionModuleService.deleteRegions("reg_123") - } - ``` + await regionModuleService.deleteRegions("reg_123") +} +``` diff --git a/www/apps/resources/app/commerce-modules/region/page.mdx b/www/apps/resources/app/commerce-modules/region/page.mdx index 90fcc9b857..e016c53e2b 100644 --- a/www/apps/resources/app/commerce-modules/region/page.mdx +++ b/www/apps/resources/app/commerce-modules/region/page.mdx @@ -76,61 +76,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const regionModuleService: IRegionModuleService = - req.scope.resolve(ModuleRegistrationName.REGION) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const regionModuleService: IRegionModuleService = req.scope.resolve( + ModuleRegistrationName.REGION + ) - res.json({ - regions: await regionModuleService.listRegions(), - }) - } - ``` + res.json({ + regions: await regionModuleService.listRegions(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const regionModuleService: IRegionModuleService = - container.resolve(ModuleRegistrationName.REGION) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const regionModuleService: IRegionModuleService = container.resolve( + ModuleRegistrationName.REGION + ) - const regions = await regionModuleService.listRegions() - } - ``` + const regions = await regionModuleService.listRegions() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IRegionModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IRegionModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const regionModuleService: IRegionModuleService = - container.resolve( - ModuleRegistrationName.REGION - ) - - const regions = await regionModuleService.listRegions() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const regionModuleService: IRegionModuleService = container.resolve( + ModuleRegistrationName.REGION + ) + + const regions = await regionModuleService.listRegions() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/sales-channel/examples/page.mdx b/www/apps/resources/app/commerce-modules/sales-channel/examples/page.mdx index 1440e2910e..fe9fffb3b0 100644 --- a/www/apps/resources/app/commerce-modules/sales-channel/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/sales-channel/examples/page.mdx @@ -13,51 +13,46 @@ In this guide, you’ll find common examples of how you can use the Sales Channe - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const salesChannelModuleService: ISalesChannelModuleService = - request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const salesChannelModuleService: ISalesChannelModuleService = + request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) - const salesChannel = await salesChannelModuleService - .createSalesChannels({ - name: "B2B", - }) + const salesChannel = await salesChannelModuleService.createSalesChannels({ + name: "B2B", + }) - res.json({ - sales_channel: salesChannel, - }) - } - ``` + res.json({ + sales_channel: salesChannel, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeSalesChannelModule, - } from "@medusajs/sales-channel" +import { initialize as initializeSalesChannelModule } from "@medusajs/sales-channel" - export async function POST(request: Request) { - const salesChannelModuleService = - await initializeSalesChannelModule() +export async function POST(request: Request) { + const salesChannelModuleService = await initializeSalesChannelModule() - const salesChannel = await salesChannelModuleService - .createSalesChannels({ - name: "B2B", - }) + const salesChannel = await salesChannelModuleService.createSalesChannels({ + name: "B2B", + }) - return NextResponse.json({ sales_channel: salesChannel }) - } - ``` + return NextResponse.json({ sales_channel: salesChannel }) +} +``` @@ -69,45 +64,40 @@ In this guide, you’ll find common examples of how you can use the Sales Channe - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const salesChannelModuleService: ISalesChannelModuleService = - request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const salesChannelModuleService: ISalesChannelModuleService = + request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) - res.json({ - sales_channels: salesChannelModuleService - .listSalesChannels(), - }) - } - ``` + res.json({ + sales_channels: salesChannelModuleService.listSalesChannels(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeSalesChannelModule, - } from "@medusajs/sales-channel" +import { initialize as initializeSalesChannelModule } from "@medusajs/sales-channel" - export async function GET(request: Request) { - const salesChannelModuleService = - await initializeSalesChannelModule() +export async function GET(request: Request) { + const salesChannelModuleService = await initializeSalesChannelModule() - const salesChannels = await salesChannelModuleService - .listSalesChannels() + const salesChannels = await salesChannelModuleService.listSalesChannels() - return NextResponse.json({ sales_channels: salesChannels }) - } - ``` + return NextResponse.json({ sales_channels: salesChannels }) +} +``` @@ -119,53 +109,46 @@ In this guide, you’ll find common examples of how you can use the Sales Channe - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const salesChannelModuleService: ISalesChannelModuleService = - request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const salesChannelModuleService: ISalesChannelModuleService = + request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) - const salesChannel = await salesChannelModuleService - .retrieveSalesChannel( - "sc_123" - ) + const salesChannel = await salesChannelModuleService.retrieveSalesChannel( + "sc_123" + ) - res.json({ - sales_channel: salesChannel, - }) - } - ``` + res.json({ + sales_channel: salesChannel, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeSalesChannelModule, - } from "@medusajs/sales-channel" +import { initialize as initializeSalesChannelModule } from "@medusajs/sales-channel" - export async function GET( - request: Request - ) { - const salesChannelModuleService = - await initializeSalesChannelModule() +export async function GET(request: Request) { + const salesChannelModuleService = await initializeSalesChannelModule() - const salesChannel = await salesChannelModuleService - .retrieveSalesChannel( - "sc_123" - ) + const salesChannel = await salesChannelModuleService.retrieveSalesChannel( + "sc_123" + ) - return NextResponse.json({ sales_channel: salesChannel }) - } - ``` + return NextResponse.json({ sales_channel: salesChannel }) +} +``` @@ -177,55 +160,48 @@ In this guide, you’ll find common examples of how you can use the Sales Channe - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const salesChannelModuleService: ISalesChannelModuleService = - request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const salesChannelModuleService: ISalesChannelModuleService = + request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) - const salesChannel = await salesChannelModuleService - .updateSalesChannels({ - id: "sc_123", - description: "Sales channel for B2B customers", - }) + const salesChannel = await salesChannelModuleService.updateSalesChannels({ + id: "sc_123", + description: "Sales channel for B2B customers", + }) - res.json({ - sales_channel: salesChannel, - }) - } - ``` + res.json({ + sales_channel: salesChannel, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeSalesChannelModule, - } from "@medusajs/sales-channel" +import { initialize as initializeSalesChannelModule } from "@medusajs/sales-channel" - export async function POST( - request: Request - ) { - const salesChannelModuleService = - await initializeSalesChannelModule() +export async function POST(request: Request) { + const salesChannelModuleService = await initializeSalesChannelModule() - const salesChannel = await salesChannelModuleService - .updateSalesChannels({ - id: "sc_123", - description: "Sales channel for B2B customers", - }) + const salesChannel = await salesChannelModuleService.updateSalesChannels({ + id: "sc_123", + description: "Sales channel for B2B customers", + }) - return NextResponse.json({ sales_channel: salesChannel }) - } - ``` + return NextResponse.json({ sales_channel: salesChannel }) +} +``` @@ -237,43 +213,38 @@ In this guide, you’ll find common examples of how you can use the Sales Channe - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const salesChannelModuleService: ISalesChannelModuleService = - request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) +export async function DELETE( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const salesChannelModuleService: ISalesChannelModuleService = + request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) - await salesChannelModuleService.deleteSalesChannels("sc_123") + await salesChannelModuleService.deleteSalesChannels("sc_123") - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeSalesChannelModule, - } from "@medusajs/sales-channel" +import { initialize as initializeSalesChannelModule } from "@medusajs/sales-channel" - export async function DELETE( - request: Request - ) { - const salesChannelModuleService = - await initializeSalesChannelModule() +export async function DELETE(request: Request) { + const salesChannelModuleService = await initializeSalesChannelModule() - await salesChannelModuleService.deleteSalesChannels("sc_123") - } - ``` + await salesChannelModuleService.deleteSalesChannels("sc_123") +} +``` diff --git a/www/apps/resources/app/commerce-modules/sales-channel/page.mdx b/www/apps/resources/app/commerce-modules/sales-channel/page.mdx index a6e9abc789..b49323e6b3 100644 --- a/www/apps/resources/app/commerce-modules/sales-channel/page.mdx +++ b/www/apps/resources/app/commerce-modules/sales-channel/page.mdx @@ -27,15 +27,14 @@ Some use case examples for using a sales channel: Manage sales channels in your store. Each sales channel has different meta information such as name or description, allowing you to easily differentiate between sales channels. ```ts -const salesChannels = await salesChannelModuleService - .createSalesChannels([ - { - name: "B2B", - }, - { - name: "Mobile App", - }, - ]) +const salesChannels = await salesChannelModuleService.createSalesChannels([ + { + name: "B2B", + }, + { + name: "Mobile App", + }, +]) ``` ### Product Availability @@ -61,64 +60,55 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const salesChannelModuleService: ISalesChannelModuleService = - request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const salesChannelModuleService: ISalesChannelModuleService = + request.scope.resolve(ModuleRegistrationName.SALES_CHANNEL) - res.json({ - sales_channels: await salesChannelModuleService - .listSalesChannels(), - }) - } - ``` + res.json({ + sales_channels: await salesChannelModuleService.listSalesChannels(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const salesChannelModuleService: ISalesChannelModuleService = - container.resolve(ModuleRegistrationName.SALES_CHANNEL) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const salesChannelModuleService: ISalesChannelModuleService = + container.resolve(ModuleRegistrationName.SALES_CHANNEL) - const salesChannels = await salesChannelModuleService - .listSalesChannels() - } - ``` + const salesChannels = await salesChannelModuleService.listSalesChannels() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { ISalesChannelModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { ISalesChannelModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const salesChannelModuleService: ISalesChannelModuleService = - container.resolve( - ModuleRegistrationName.SALES_CHANNEL - ) - - const salesChannels = await salesChannelModuleService - .listSalesChannels() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const salesChannelModuleService: ISalesChannelModuleService = + container.resolve(ModuleRegistrationName.SALES_CHANNEL) + + const salesChannels = await salesChannelModuleService.listSalesChannels() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/stock-location/examples/page.mdx b/www/apps/resources/app/commerce-modules/stock-location/examples/page.mdx index 9c184efa22..6fa155d727 100644 --- a/www/apps/resources/app/commerce-modules/stock-location/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/stock-location/examples/page.mdx @@ -13,55 +13,46 @@ In this document, you’ll find common examples of how you can use the Stock Loc - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const stockLocationModuleService: IStockLocationService = - request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const stockLocationModuleService: IStockLocationService = + request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) - const stockLocation = await stockLocationModuleService - .createStockLocations( - { - name: "Warehouse 1", - } - ) + const stockLocation = await stockLocationModuleService.createStockLocations({ + name: "Warehouse 1", + }) - res.json({ - stock_location: stockLocation, - }) - } - ``` + res.json({ + stock_location: stockLocation, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStockLocationModule, - } from "@medusajs/stock-location-next" +import { initialize as initializeStockLocationModule } from "@medusajs/stock-location-next" - export async function POST(request: Request) { - const stockLocationModuleService = - await initializeStockLocationModule({}) +export async function POST(request: Request) { + const stockLocationModuleService = await initializeStockLocationModule({}) - const stockLocation = await stockLocationModuleService - .createStockLocations( - { - name: "Warehouse 1", - } - ) + const stockLocation = await stockLocationModuleService.createStockLocations({ + name: "Warehouse 1", + }) - return NextResponse.json({ stock_location: stockLocation }) - } - ``` + return NextResponse.json({ stock_location: stockLocation }) +} +``` @@ -73,45 +64,40 @@ In this document, you’ll find common examples of how you can use the Stock Loc - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const stockLocationModuleService: IStockLocationService = - request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const stockLocationModuleService: IStockLocationService = + request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) - res.json({ - stock_locations: await stockLocationModuleService - .listStockLocations({}), - }) - } - ``` + res.json({ + stock_locations: await stockLocationModuleService.listStockLocations({}), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStockLocationModule, - } from "@medusajs/stock-location-next" +import { initialize as initializeStockLocationModule } from "@medusajs/stock-location-next" - export async function GET(request: Request) { - const stockLocationModuleService = - await initializeStockLocationModule({}) +export async function GET(request: Request) { + const stockLocationModuleService = await initializeStockLocationModule({}) - return NextResponse.json({ - stock_locations: await stockLocationModuleService - .listStockLocations({}), - }) - } - ``` + return NextResponse.json({ + stock_locations: await stockLocationModuleService.listStockLocations({}), + }) +} +``` @@ -123,67 +109,60 @@ In this document, you’ll find common examples of how you can use the Stock Loc - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const stockLocationModuleService: IStockLocationService = - request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const stockLocationModuleService: IStockLocationService = + request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) - const stockLocation = await stockLocationModuleService - .updateStockLocations({ - id: "sloc_123", - address: { - country_code: "US", - city: "New York City", - address_1: "52 Stone St", - postal_code: "10004", - }, - }) + const stockLocation = await stockLocationModuleService.updateStockLocations({ + id: "sloc_123", + address: { + country_code: "US", + city: "New York City", + address_1: "52 Stone St", + postal_code: "10004", + }, + }) - res.json({ - stock_location: stockLocation, - }) - } - ``` + res.json({ + stock_location: stockLocation, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStockLocationModule, - } from "@medusajs/stock-location-next" +import { initialize as initializeStockLocationModule } from "@medusajs/stock-location-next" - export async function POST( - request: Request - ) { - const stockLocationModuleService = - await initializeStockLocationModule({}) +export async function POST(request: Request) { + const stockLocationModuleService = await initializeStockLocationModule({}) - const stockLocation = await stockLocationModuleService - .updateStockLocations({ - id: "sloc_123", - address: { - country_code: "us", - city: "New York City", - address_1: "52 Stone St", - postal_code: "10004", - }, - }) + const stockLocation = await stockLocationModuleService.updateStockLocations({ + id: "sloc_123", + address: { + country_code: "us", + city: "New York City", + address_1: "52 Stone St", + postal_code: "10004", + }, + }) - return NextResponse.json({ - stock_location: stockLocation, - }) - } - ``` + return NextResponse.json({ + stock_location: stockLocation, + }) +} +``` @@ -195,47 +174,38 @@ In this document, you’ll find common examples of how you can use the Stock Loc - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const stockLocationModuleService: IStockLocationService = - request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) +export async function DELETE( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const stockLocationModuleService: IStockLocationService = + request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) - await stockLocationModuleService.deleteStockLocations( - "sloc_123" - ) + await stockLocationModuleService.deleteStockLocations("sloc_123") - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStockLocationModule, - } from "@medusajs/stock-location-next" +import { initialize as initializeStockLocationModule } from "@medusajs/stock-location-next" - export async function DELETE( - request: Request - ) { - const stockLocationModuleService = - await initializeStockLocationModule({}) +export async function DELETE(request: Request) { + const stockLocationModuleService = await initializeStockLocationModule({}) - await stockLocationModuleService.deleteStockLocations( - "sloc_123" - ) - } - ``` + await stockLocationModuleService.deleteStockLocations("sloc_123") +} +``` diff --git a/www/apps/resources/app/commerce-modules/stock-location/page.mdx b/www/apps/resources/app/commerce-modules/stock-location/page.mdx index 9d057ebe71..d300de5cc6 100644 --- a/www/apps/resources/app/commerce-modules/stock-location/page.mdx +++ b/www/apps/resources/app/commerce-modules/stock-location/page.mdx @@ -15,12 +15,9 @@ The Stock Location Module is the `@medusajs/stock-location-next` NPM package tha Store and manage stock locations. Stock locations are associated with data models of other modules that require a location, such as the [Inventory Module's InventoryLevel](../inventory/concepts/page.mdx#inventory-level). ```ts -const stockLocation = await stockLocationModuleService - .createStockLocations( - { - name: "Warehouse 1", - } - ) +const stockLocation = await stockLocationModuleService.createStockLocations({ + name: "Warehouse 1", +}) ``` ### Address Management @@ -28,18 +25,15 @@ const stockLocation = await stockLocationModuleService Manage the address of each stock location. ```ts -const stockLocation = await stockLocationModuleService - .updateStockLocations( - { - id: "sloc_123", - address: { - country_code: "us", - city: "New York City", - address_1: "52 Stone St", - postal_code: "10004", - }, - } - ) +const stockLocation = await stockLocationModuleService.updateStockLocations({ + id: "sloc_123", + address: { + country_code: "us", + city: "New York City", + address_1: "52 Stone St", + postal_code: "10004", + }, +}) ``` --- @@ -53,64 +47,57 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const stockLocationModuleService: IStockLocationService = - request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const stockLocationModuleService: IStockLocationService = + request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION) - res.json({ - stock_locations: await stockLocationModuleService - .listStockLocations({}), - }) - } - ``` + res.json({ + stock_locations: await stockLocationModuleService.listStockLocations({}), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const stockLocationModuleService: IStockLocationService = - container.resolve(ModuleRegistrationName.STOCK_LOCATION) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const stockLocationModuleService: IStockLocationService = container.resolve( + ModuleRegistrationName.STOCK_LOCATION + ) - const stockLocations = await stockLocationModuleService - .listStockLocations({}) - } - ``` + const stockLocations = await stockLocationModuleService.listStockLocations({}) +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IStockLocationService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IStockLocationService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const stockLocationModuleService: IStockLocationService = - container.resolve( - ModuleRegistrationName.STOCK_LOCATION - ) +const step1 = createStep("step-1", async (_, { container }) => { + const stockLocationModuleService: IStockLocationService = container.resolve( + ModuleRegistrationName.STOCK_LOCATION + ) - const stockLocations = await stockLocationModuleService - .listStockLocations({}) - }) - ``` + const stockLocations = await stockLocationModuleService.listStockLocations({}) +}) +``` diff --git a/www/apps/resources/app/commerce-modules/store/examples/page.mdx b/www/apps/resources/app/commerce-modules/store/examples/page.mdx index abdfb6e840..332cfbe086 100644 --- a/www/apps/resources/app/commerce-modules/store/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/store/examples/page.mdx @@ -13,62 +13,61 @@ In this guide, you’ll find common examples of how you can use the Store Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const storeModuleService: IStoreModuleService = - request.scope.resolve(ModuleRegistrationName.STORE) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const storeModuleService: IStoreModuleService = request.scope.resolve( + ModuleRegistrationName.STORE + ) - const store = await storeModuleService.createStores({ - name: "My Store", - supported_currencies: [ - { - currency_code: "usd", - is_default: true, - }, - ], - }) + const store = await storeModuleService.createStores({ + name: "My Store", + supported_currencies: [ + { + currency_code: "usd", + is_default: true, + }, + ], + }) - res.json({ - store, - }) - } - ``` + res.json({ + store, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStoreModule, - } from "@medusajs/store" +import { initialize as initializeStoreModule } from "@medusajs/store" - export async function POST(request: Request) { - const storeModuleService = await initializeStoreModule() +export async function POST(request: Request) { + const storeModuleService = await initializeStoreModule() - const store = await storeModuleService.createStores({ - name: "My Store", - supported_currencies: [ - { - currency_code: "usd", - is_default: true, - }, - ], - }) + const store = await storeModuleService.createStores({ + name: "My Store", + supported_currencies: [ + { + currency_code: "usd", + is_default: true, + }, + ], + }) - res.json({ - store, - }) - } - ``` + res.json({ + store, + }) +} +``` @@ -80,44 +79,43 @@ In this guide, you’ll find common examples of how you can use the Store Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const storeModuleService: IStoreModuleService = - request.scope.resolve(ModuleRegistrationName.STORE) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const storeModuleService: IStoreModuleService = request.scope.resolve( + ModuleRegistrationName.STORE + ) - res.json({ - stores: await storeModuleService.listStores(), - }) - } - ``` + res.json({ + stores: await storeModuleService.listStores(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStoreModule, - } from "@medusajs/store" +import { initialize as initializeStoreModule } from "@medusajs/store" - export async function GET(request: Request) { - const storeModuleService = await initializeStoreModule() +export async function GET(request: Request) { + const storeModuleService = await initializeStoreModule() - const salesChannels = await storeModuleService.listStores() + const salesChannels = await storeModuleService.listStores() - return NextResponse.json({ - stores: await storeModuleService.list(), - }) - } - ``` + return NextResponse.json({ + stores: await storeModuleService.list(), + }) +} +``` @@ -129,51 +127,43 @@ In this guide, you’ll find common examples of how you can use the Store Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const storeModuleService: IStoreModuleService = - request.scope.resolve(ModuleRegistrationName.STORE) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const storeModuleService: IStoreModuleService = request.scope.resolve( + ModuleRegistrationName.STORE + ) - const store = await storeModuleService.retrieveStore( - "store_123" - ) + const store = await storeModuleService.retrieveStore("store_123") - res.json({ - store, - }) - } - ``` + res.json({ + store, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStoreModule, - } from "@medusajs/store" +import { initialize as initializeStoreModule } from "@medusajs/store" - export async function GET( - request: Request, - { params }: ContextType - ) { - const storeModuleService = await initializeStoreModule() +export async function GET(request: Request, { params }: ContextType) { + const storeModuleService = await initializeStoreModule() - const store = await storeModuleService.retrieveStore( - "store_123" - ) + const store = await storeModuleService.retrieveStore("store_123") - return NextResponse.json({ store }) - } - ``` + return NextResponse.json({ store }) +} +``` @@ -185,53 +175,47 @@ In this guide, you’ll find common examples of how you can use the Store Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const storeModuleService: IStoreModuleService = - request.scope.resolve(ModuleRegistrationName.STORE) +export async function POST( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const storeModuleService: IStoreModuleService = request.scope.resolve( + ModuleRegistrationName.STORE + ) - const store = await storeModuleService - .updateStores("store_123", { - name: "Change Store", - }) + const store = await storeModuleService.updateStores("store_123", { + name: "Change Store", + }) - res.json({ - store, - }) - } - ``` + res.json({ + store, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStoreModule, - } from "@medusajs/store" +import { initialize as initializeStoreModule } from "@medusajs/store" - export async function POST( - request: Request, - { params }: ContextType - ) { - const storeModuleService = await initializeStoreModule() +export async function POST(request: Request, { params }: ContextType) { + const storeModuleService = await initializeStoreModule() - const store = await storeModuleService - .updateStores("store_123", { - name: "Change Store", - }) + const store = await storeModuleService.updateStores("store_123", { + name: "Change Store", + }) - return NextResponse.json({ store }) - } - ``` + return NextResponse.json({ store }) +} +``` @@ -243,43 +227,39 @@ In this guide, you’ll find common examples of how you can use the Store Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const storeModuleService: IStoreModuleService = - request.scope.resolve(ModuleRegistrationName.STORE) +export async function DELETE( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const storeModuleService: IStoreModuleService = request.scope.resolve( + ModuleRegistrationName.STORE + ) - await storeModuleService.deleteStores("store_123") + await storeModuleService.deleteStores("store_123") - res.status(200) - } - ``` + res.status(200) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeStoreModule, - } from "@medusajs/store" +import { initialize as initializeStoreModule } from "@medusajs/store" - export async function DELETE( - request: Request, - { params }: ContextType - ) { - const storeModuleService = await initializeStoreModule() +export async function DELETE(request: Request, { params }: ContextType) { + const storeModuleService = await initializeStoreModule() - await storeModuleService.deleteStores("store_123") - } - ``` + await storeModuleService.deleteStores("store_123") +} +``` @@ -289,4 +269,3 @@ In this guide, you’ll find common examples of how you can use the Store Module ## More Examples The [Store Module's main service reference](/references/store) provides a reference to all the methods available for use with examples for each. - diff --git a/www/apps/resources/app/commerce-modules/store/page.mdx b/www/apps/resources/app/commerce-modules/store/page.mdx index 141e3ef1ba..b63a708186 100644 --- a/www/apps/resources/app/commerce-modules/store/page.mdx +++ b/www/apps/resources/app/commerce-modules/store/page.mdx @@ -49,61 +49,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - request: MedusaRequest, - res: MedusaResponse - ): Promise { - const storeModuleService: IStoreModuleService = - request.scope.resolve(ModuleRegistrationName.STORE) +export async function GET( + request: MedusaRequest, + res: MedusaResponse +): Promise { + const storeModuleService: IStoreModuleService = request.scope.resolve( + ModuleRegistrationName.STORE + ) - res.json({ - stores: await storeModuleService.listStores(), - }) - } - ``` + res.json({ + stores: await storeModuleService.listStores(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const storeModuleService: IStoreModuleService = - container.resolve(ModuleRegistrationName.STORE) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const storeModuleService: IStoreModuleService = container.resolve( + ModuleRegistrationName.STORE + ) - const stores = await storeModuleService.listStores() - } - ``` + const stores = await storeModuleService.listStores() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IStoreModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IStoreModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const storeModuleService: IStoreModuleService = - container.resolve( - ModuleRegistrationName.STORE - ) - - const stores = await storeModuleService.listStores() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const storeModuleService: IStoreModuleService = container.resolve( + ModuleRegistrationName.STORE + ) + + const stores = await storeModuleService.listStores() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/tax/examples/page.mdx b/www/apps/resources/app/commerce-modules/tax/examples/page.mdx index 5a54c063b7..29b2fa6f7c 100644 --- a/www/apps/resources/app/commerce-modules/tax/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/tax/examples/page.mdx @@ -13,59 +13,57 @@ In this guide, you’ll find common examples of how you can use the Tax Module i - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) - const taxRegion = await taxModuleService.createTaxRegions({ - country_code: "us", - default_tax_rate: { - rate: 10, - name: "Default rate", - }, - }) + const taxRegion = await taxModuleService.createTaxRegions({ + country_code: "us", + default_tax_rate: { + rate: 10, + name: "Default rate", + }, + }) - res.json({ - tax_region: taxRegion, - }) - } - ``` + res.json({ + tax_region: taxRegion, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeTaxModule, - } from "@medusajs/tax" +import { initialize as initializeTaxModule } from "@medusajs/tax" - export async function POST(request: Request) { - const taxModuleService = await initializeTaxModule() +export async function POST(request: Request) { + const taxModuleService = await initializeTaxModule() - const taxRegion = await taxModuleService.createTaxRegions({ - country_code: "us", - default_tax_rate: { - rate: 10, - name: "Default rate", - }, - }) + const taxRegion = await taxModuleService.createTaxRegions({ + country_code: "us", + default_tax_rate: { + rate: 10, + name: "Default rate", + }, + }) - return NextResponse.json({ - tax_region: taxRegion, - }) - } - ``` + return NextResponse.json({ + tax_region: taxRegion, + }) +} +``` @@ -77,43 +75,41 @@ In this guide, you’ll find common examples of how you can use the Tax Module i - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) - res.json({ - tax_regions: await taxModuleService.listTaxRegions(), - }) - } - ``` + res.json({ + tax_regions: await taxModuleService.listTaxRegions(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeTaxModule, - } from "@medusajs/tax" +import { initialize as initializeTaxModule } from "@medusajs/tax" - export async function GET(request: Request) { - const taxModuleService = await initializeTaxModule() +export async function GET(request: Request) { + const taxModuleService = await initializeTaxModule() - return NextResponse.json({ - tax_regions: await taxModuleService.listTaxRegions(), - }) - } - ``` + return NextResponse.json({ + tax_regions: await taxModuleService.listTaxRegions(), + }) +} +``` @@ -125,77 +121,73 @@ In this guide, you’ll find common examples of how you can use the Tax Module i - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) - const taxRate = await taxModuleService.createTaxRates({ - tax_region_id: "txreg_123", - name: "Custom rate", - rate: 15, - rules: [ - { - reference: "product_type", - reference_id: "ptyp_1", - }, - { - reference: "product", - reference_id: "prod_123", - }, - ], - }) + const taxRate = await taxModuleService.createTaxRates({ + tax_region_id: "txreg_123", + name: "Custom rate", + rate: 15, + rules: [ + { + reference: "product_type", + reference_id: "ptyp_1", + }, + { + reference: "product", + reference_id: "prod_123", + }, + ], + }) - res.json({ - tax_rate: taxRate, - }) - } - ``` + res.json({ + tax_rate: taxRate, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeTaxModule, - } from "@medusajs/tax" +import { initialize as initializeTaxModule } from "@medusajs/tax" - export async function POST( - request: Request - ) { - const taxModuleService = await initializeTaxModule() +export async function POST(request: Request) { + const taxModuleService = await initializeTaxModule() - const taxRate = await taxModuleService.createTaxRates({ - tax_region_id: "txreg_123", - name: "Custom rate", - rate: 15, - rules: [ - { - reference: "product_type", - reference_id: "ptyp_1", - }, - { - reference: "product", - reference_id: "prod_123", - }, - ], - }) + const taxRate = await taxModuleService.createTaxRates({ + tax_region_id: "txreg_123", + name: "Custom rate", + rate: 15, + rules: [ + { + reference: "product_type", + reference_id: "ptyp_1", + }, + { + reference: "product", + reference_id: "prod_123", + }, + ], + }) - return NextResponse.json({ - tax_rate: taxRate, - }) - } - ``` + return NextResponse.json({ + tax_rate: taxRate, + }) +} +``` @@ -207,45 +199,41 @@ In this guide, you’ll find common examples of how you can use the Tax Module i - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) - res.json({ - tax_rates: await taxModuleService.listTaxRates(), - }) - } - ``` + res.json({ + tax_rates: await taxModuleService.listTaxRates(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeTaxModule, - } from "@medusajs/tax" +import { initialize as initializeTaxModule } from "@medusajs/tax" - export async function GET( - request: Request - ) { - const taxModuleService = await initializeTaxModule() +export async function GET(request: Request) { + const taxModuleService = await initializeTaxModule() - return NextResponse.json({ - tax_rates: await taxModuleService.listTaxRates(), - }) - } - ``` + return NextResponse.json({ + tax_rates: await taxModuleService.listTaxRates(), + }) +} +``` @@ -257,97 +245,93 @@ In this guide, you’ll find common examples of how you can use the Tax Module i - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) - const taxLines = await taxModuleService.getTaxLines( - [ - { - id: "cali_123", - product_id: "prod_123", - unit_price: 1000, - }, - { - id: "casm_123", - shipping_option_id: "so_123", - unit_price: 2000, - }, - ], + const taxLines = await taxModuleService.getTaxLines( + [ { - address: { - country_code: "us", - postal_code: "123456", - }, - customer: { - id: "cus_123", - email: "user@example.com", - customer_groups: ["VIP"], - }, - } - ) + id: "cali_123", + product_id: "prod_123", + unit_price: 1000, + }, + { + id: "casm_123", + shipping_option_id: "so_123", + unit_price: 2000, + }, + ], + { + address: { + country_code: "us", + postal_code: "123456", + }, + customer: { + id: "cus_123", + email: "user@example.com", + customer_groups: ["VIP"], + }, + } + ) - res.json({ - tax_lines: taxLines, - }) - } - ``` + res.json({ + tax_lines: taxLines, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeTaxModule, - } from "@medusajs/tax" +import { initialize as initializeTaxModule } from "@medusajs/tax" - export async function GET( - request: Request - ) { - const taxModuleService = await initializeTaxModule() +export async function GET(request: Request) { + const taxModuleService = await initializeTaxModule() - const taxLines = await taxModuleService.getTaxLines( - [ - { - id: "cali_123", - product_id: "prod_123", - unit_price: 1000, - }, - { - id: "casm_123", - shipping_option_id: "so_123", - unit_price: 2000, - }, - ], + const taxLines = await taxModuleService.getTaxLines( + [ { - address: { - country_code: "us", - postal_code: "123456", - }, - customer: { - id: "cus_123", - email: "user@example.com", - customer_groups: ["VIP"], - }, - } - ) + id: "cali_123", + product_id: "prod_123", + unit_price: 1000, + }, + { + id: "casm_123", + shipping_option_id: "so_123", + unit_price: 2000, + }, + ], + { + address: { + country_code: "us", + postal_code: "123456", + }, + customer: { + id: "cus_123", + email: "user@example.com", + customer_groups: ["VIP"], + }, + } + ) - return NextResponse.json({ - tax_lines: taxLines, - }) - } - ``` + return NextResponse.json({ + tax_lines: taxLines, + }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/tax/page.mdx b/www/apps/resources/app/commerce-modules/tax/page.mdx index f0b43f9cab..67fe4f4f16 100644 --- a/www/apps/resources/app/commerce-modules/tax/page.mdx +++ b/www/apps/resources/app/commerce-modules/tax/page.mdx @@ -91,62 +91,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const taxModuleService: ITaxModuleService = req.scope.resolve( - ModuleRegistrationName.TAX - ) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const taxModuleService: ITaxModuleService = req.scope.resolve( + ModuleRegistrationName.TAX + ) - res.json({ - tax_regions: await taxModuleService.listTaxRegions(), - }) - } - ``` + res.json({ + tax_regions: await taxModuleService.listTaxRegions(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const taxModuleService: ITaxModuleService = - container.resolve(ModuleRegistrationName.TAX) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const taxModuleService: ITaxModuleService = container.resolve( + ModuleRegistrationName.TAX + ) - const taxRegions = await taxModuleService.listTaxRegions() - } - ``` + const taxRegions = await taxModuleService.listTaxRegions() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { ITaxModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { ITaxModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const taxModuleService: ITaxModuleService = - container.resolve( - ModuleRegistrationName.TAX - ) +const step1 = createStep("step-1", async (_, { container }) => { + const taxModuleService: ITaxModuleService = container.resolve( + ModuleRegistrationName.TAX + ) - const taxRegions = await taxModuleService.listTaxRegions() - }) - ``` + const taxRegions = await taxModuleService.listTaxRegions() +}) +``` diff --git a/www/apps/resources/app/commerce-modules/user/examples/page.mdx b/www/apps/resources/app/commerce-modules/user/examples/page.mdx index 119fcaade5..4748db8a94 100644 --- a/www/apps/resources/app/commerce-modules/user/examples/page.mdx +++ b/www/apps/resources/app/commerce-modules/user/examples/page.mdx @@ -13,52 +13,51 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - const user = await userModuleService.createUsers({ - email: "user@example.com", - first_name: "John", - last_name: "Smith", - }) + const user = await userModuleService.createUsers({ + email: "user@example.com", + first_name: "John", + last_name: "Smith", + }) - res.json({ user }) - } - ``` + res.json({ user }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function POST(request: Request) { - const userModuleService = await initializeUserModule() +export async function POST(request: Request) { + const userModuleService = await initializeUserModule() - const user = await userModuleService.createUsers({ - email: "user@example.com", - first_name: "John", - last_name: "Smith", - }) + const user = await userModuleService.createUsers({ + email: "user@example.com", + first_name: "John", + last_name: "Smith", + }) - return NextResponse.json({ - user, - }) - } - ``` + return NextResponse.json({ + user, + }) +} +``` @@ -70,42 +69,41 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - res.json({ - users: await userModuleService.listUsers(), - }) - } - ``` + res.json({ + users: await userModuleService.listUsers(), + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function GET(request: Request) { - const userModuleService = await initializeUserModule() +export async function GET(request: Request) { + const userModuleService = await initializeUserModule() - return NextResponse.json({ - users: await userModuleService.listUsers(), - }) - } - ``` + return NextResponse.json({ + users: await userModuleService.listUsers(), + }) +} +``` @@ -117,52 +115,49 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - const user = await userModuleService.updateUsers({ - id: "user_123", - last_name: "Smith", - }) + const user = await userModuleService.updateUsers({ + id: "user_123", + last_name: "Smith", + }) - res.json({ user }) - } - ``` + res.json({ user }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function POST( - request: Request - ) { - const userModuleService = await initializeUserModule() +export async function POST(request: Request) { + const userModuleService = await initializeUserModule() - const user = await userModuleService.updateUsers({ - id: "user_123", - last_name: "Smith", - }) + const user = await userModuleService.updateUsers({ + id: "user_123", + last_name: "Smith", + }) - return NextResponse.json({ - user, - }) - } - ``` + return NextResponse.json({ + user, + }) +} +``` @@ -174,40 +169,37 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function DELETE( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function DELETE( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - await userModuleService.deleteUsers(["user_123"]) - } - ``` + await userModuleService.deleteUsers(["user_123"]) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function DELETE( - request: Request - ) { - const userModuleService = await initializeUserModule() +export async function DELETE(request: Request) { + const userModuleService = await initializeUserModule() - await userModuleService.deleteUsers(["user_123"]) - } - ``` + await userModuleService.deleteUsers(["user_123"]) +} +``` @@ -219,53 +211,49 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - const invite = await userModuleService.createInvites({ - email: "user2@example.com", - }) + const invite = await userModuleService.createInvites({ + email: "user2@example.com", + }) - res.json({ - invite, - }) - } - ``` + res.json({ + invite, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function POST( - request: Request, - { params }: ContextType - ) { - const userModuleService = await initializeUserModule() +export async function POST(request: Request, { params }: ContextType) { + const userModuleService = await initializeUserModule() - const invite = await userModuleService.createInvites({ - email: "user2@example.com", - }) + const invite = await userModuleService.createInvites({ + email: "user2@example.com", + }) - return NextResponse.json({ - invite, - }) - } - ``` + return NextResponse.json({ + invite, + }) +} +``` @@ -277,71 +265,65 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - const invite = - await userModuleService.validateInviteToken("secret_123") + const invite = await userModuleService.validateInviteToken("secret_123") - const user = await userModuleService.createUsers({ - email: invite.email, - metadata: invite.metadata, - }) + const user = await userModuleService.createUsers({ + email: invite.email, + metadata: invite.metadata, + }) - await userModuleService.updateInvites({ - id: invite.id, - accepted: true, - }) + await userModuleService.updateInvites({ + id: invite.id, + accepted: true, + }) - res.json({ - user, - }) - } - ``` + res.json({ + user, + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function POST( - request: Request, - { params }: ContextType - ) { - const userModuleService = await initializeUserModule() +export async function POST(request: Request, { params }: ContextType) { + const userModuleService = await initializeUserModule() - const invite = - await userModuleService.validateInviteToken("secret_123") + const invite = await userModuleService.validateInviteToken("secret_123") - const user = await userModuleService.createUsers({ - email: invite.email, - metadata: invite.metadata, - }) + const user = await userModuleService.createUsers({ + email: invite.email, + metadata: invite.metadata, + }) - await userModuleService.updateInvites({ - id: invite.id, - accepted: true, - }) + await userModuleService.updateInvites({ + id: invite.id, + accepted: true, + }) - return NextResponse.json({ - user, - }) - } - ``` + return NextResponse.json({ + user, + }) +} +``` @@ -353,53 +335,45 @@ In this guide, you’ll find common examples of how you can use the User Module - ```ts - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function POST( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - const invites = await userModuleService.refreshInviteTokens([ - "invite_123", - ]) + const invites = await userModuleService.refreshInviteTokens(["invite_123"]) - res.json({ - invite: invites[0], - }) - } - ``` + res.json({ + invite: invites[0], + }) +} +``` - ```ts - import { NextResponse } from "next/server" +```ts +import { NextResponse } from "next/server" - import { - initialize as initializeUserModule, - } from "@medusajs/user" +import { initialize as initializeUserModule } from "@medusajs/user" - export async function POST( - request: Request, - { params }: ContextType - ) { - const userModuleService = await initializeUserModule() +export async function POST(request: Request, { params }: ContextType) { + const userModuleService = await initializeUserModule() - const invites = await userModuleService.refreshInviteTokens([ - "invite_123", - ]) + const invites = await userModuleService.refreshInviteTokens(["invite_123"]) - return NextResponse.json({ - invite: invites[0], - }) - } - ``` + return NextResponse.json({ + invite: invites[0], + }) +} +``` diff --git a/www/apps/resources/app/commerce-modules/user/page.mdx b/www/apps/resources/app/commerce-modules/user/page.mdx index fd3618f596..2fa2bb8daa 100644 --- a/www/apps/resources/app/commerce-modules/user/page.mdx +++ b/www/apps/resources/app/commerce-modules/user/page.mdx @@ -52,61 +52,58 @@ For example: - ```ts title="src/api/store/custom/route.ts" - import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/api/store/custom/route.ts" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ): Promise { - const userModuleService: IUserModuleService = - req.scope.resolve(ModuleRegistrationName.USER) +export async function GET( + req: MedusaRequest, + res: MedusaResponse +): Promise { + const userModuleService: IUserModuleService = req.scope.resolve( + ModuleRegistrationName.USER + ) - res.json({ - users: await userModuleService.listUsers(), - }) - } - ``` + res.json({ + users: await userModuleService.listUsers(), + }) +} +``` - ```ts title="src/subscribers/custom-handler.ts" - import { SubscriberArgs } from "@medusajs/medusa" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/subscribers/custom-handler.ts" +import { SubscriberArgs } from "@medusajs/medusa" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - export default async function subscriberHandler({ - container, - }: SubscriberArgs) { - const userModuleService: IUserModuleService = - container.resolve(ModuleRegistrationName.USER) +export default async function subscriberHandler({ container }: SubscriberArgs) { + const userModuleService: IUserModuleService = container.resolve( + ModuleRegistrationName.USER + ) - const users = await userModuleService.listUsers() - } - ``` + const users = await userModuleService.listUsers() +} +``` - ```ts title="src/workflows/hello-world/step1.ts" - import { createStep } from "@medusajs/workflows-sdk" - import { IUserModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" +```ts title="src/workflows/hello-world/step1.ts" +import { createStep } from "@medusajs/workflows-sdk" +import { IUserModuleService } from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" - const step1 = createStep( - "step-1", - async (_, { container }) => { - const userModuleService: IUserModuleService = - container.resolve( - ModuleRegistrationName.USER - ) - - const users = await userModuleService.listUsers() - }) - ``` +const step1 = createStep("step-1", async (_, { container }) => { + const userModuleService: IUserModuleService = container.resolve( + ModuleRegistrationName.USER + ) + + const users = await userModuleService.listUsers() +}) +``` diff --git a/www/apps/resources/app/recipes/b2b/page.mdx b/www/apps/resources/app/recipes/b2b/page.mdx index d479b2d4e9..ca0037ab7d 100644 --- a/www/apps/resources/app/recipes/b2b/page.mdx +++ b/www/apps/resources/app/recipes/b2b/page.mdx @@ -36,26 +36,28 @@ You can create a sales channel through the Medusa Admin or Admin REST APIs. {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#sales-channels_postsaleschannels", - title: "Option 2: Using the REST APIs", - text: "Create the sales channel using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#sales-channels_postsaleschannels", + title: "Option 2: Using the REST APIs", + text: "Create the sales channel using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -74,51 +76,55 @@ You can create a publishable API key through the Medusa Admin or the Admin REST ### Create Key -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#api-keys_postapikeys", - title: "Option 2: Using the REST APIs", - text: "Create the publishable API key using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#api-keys_postapikeys", + title: "Option 2: Using the REST APIs", + text: "Create the publishable API key using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> ### Associate Key with Sales Channel {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "#", - title: "Option 2: Using the REST APIs", - text: "Associate the publishable API key with the B2B sales channel using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "#", + title: "Option 2: Using the REST APIs", + text: "Associate the publishable API key with the B2B sales channel using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -130,51 +136,55 @@ You can create new products or add existing ones to the B2B sales channel using {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#products_postproducts", - title: "Using REST APIs", - text: "Create products using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#products_postproducts", + title: "Using REST APIs", + text: "Create products using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> ### Add Products to Sales Channel {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#sales-channels_postsaleschannelsidproductsbatchadd", - title: "Using REST APIs", - text: "Add the products to the B2B sales channel using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#sales-channels_postsaleschannelsidproductsbatchadd", + title: "Using REST APIs", + text: "Add the products to the B2B sales channel using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -192,315 +202,308 @@ Module Relationships is coming soon. -, - showLinkIcon: false - }, - { - href: "!docs!/basics/data-models", - title: "Create Data Models", - text: "Learn how to create data models.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/basics/data-models", + title: "Create Data Models", + text: "Learn how to create data models.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> -{/* } - showLinkIcon={false} - className="mt-1" -/> */} +{/_ } +showLinkIcon={false} +className="mt-1" +/> _/} -{/*
- In this section, you'll create a B2B module that has a `Company` data model. The `Company` data model has a relationship to the `CustomerGroup` data model of the Customer Module. +{/\*
+In this section, you'll create a B2B module that has a `Company` data model. The `Company` data model has a relationship to the `CustomerGroup` data model of the Customer Module. - Start by creating the `src/modules/b2b` directory. +Start by creating the `src/modules/b2b` directory. - Then, create the file `src/modules/b2b/models/company.ts` with the following content: +Then, create the file `src/modules/b2b/models/company.ts` with the following content: - ```ts title="src/modules/b2b/models/company.ts" highlights={[["8", "", "The property will be used to create a relationship to customer groups."]]} - import { model } from "@medusajs/utils" +```ts title="src/modules/b2b/models/company.ts" highlights={[["8", "", "The property will be used to create a relationship to customer groups."]]} +import { model } from "@medusajs/utils" - const Company = model.define("company", { - id: model.id().primaryKey(), - name: model.text(), - city: model.text(), - country_code: model.text(), - customer_group_id: model.text().nullable(), - }) +const Company = model.define("company", { + id: model.id().primaryKey(), + name: model.text(), + city: model.text(), + country_code: model.text(), + customer_group_id: model.text().nullable(), +}) - export default Company - ``` +export default Company +``` - This creates a `Company` data model with some relevant properties. Most importantly, it has a `customer_group_id` property. It'll later be used when creating the relationship to the `CustomerGroup` data model in the Customer Module. +This creates a `Company` data model with some relevant properties. Most importantly, it has a `customer_group_id` property. It'll later be used when creating the relationship to the `CustomerGroup` data model in the Customer Module. - Next, create the migration in the file `src/modules/b2b/migrations/Migration20240516081502.ts` with the following content: +Next, create the migration in the file `src/modules/b2b/migrations/Migration20240516081502.ts` with the following content: - ```ts title="src/modules/b2b/migrations/Migration20240516081502.ts" - import { Migration } from "@mikro-orm/migrations" - - export class Migration20240516081502 extends Migration { +```ts title="src/modules/b2b/migrations/Migration20240516081502.ts" +import { Migration } from "@mikro-orm/migrations" - async up(): Promise { - this.addSql("create table if not exists \"company\" (\"id\" text not null, \"name\" text not null, \"city\" text not null, \"country_code\" text not null, \"customer_group_id\" text not null, constraint \"company_pkey\" primary key (\"id\"));") - } - - async down(): Promise { - this.addSql("drop table if exists \"company\" cascade;") - } - } - ``` - - You'll run the migration to reflect the data model in the database after finishing the module definition. - - Then, create the module's main service at `src/modules/b2b/service.ts` with the following content: - - ```ts title="src/modules/b2b/service.ts" - import { MedusaService } from "@medusajs/utils" - import Company from "./models/company" - - class B2bModuleService extends MedusaService({ - Company, - }){ - // TODO add custom methods +export class Migration20240516081502 extends Migration { + async up(): Promise { + this.addSql( + 'create table if not exists "company" ("id" text not null, "name" text not null, "city" text not null, "country_code" text not null, "customer_group_id" text not null, constraint "company_pkey" primary key ("id"));' + ) } - export default B2bModuleService - ``` - - This creates a `B2bModuleService` that extends the service factory, which generates data-management functionalities for the `Company` data model. - - Next, create the module definition at `src/modules/b2b/index.ts` with the following content: - - ```ts title="src/modules/b2b/index.ts" - import B2bModuleService from "./service" - - export default { - service: B2bModuleService, + async down(): Promise { + this.addSql('drop table if exists "company" cascade;') } - ``` +} +``` - Finally, add the module to the `modules` object in `medusa-config.js`: +You'll run the migration to reflect the data model in the database after finishing the module definition. - ```js title="medusa-config.js" - module.exports = defineConfig({ - // ... - modules: { - b2bModuleService: { - resolve: "./modules/b2b", - definition: { - isQueryable: true, - }, +Then, create the module's main service at `src/modules/b2b/service.ts` with the following content: + +```ts title="src/modules/b2b/service.ts" +import { MedusaService } from "@medusajs/utils" +import Company from "./models/company" + +class B2bModuleService extends MedusaService({ + Company, +}) { + // TODO add custom methods +} + +export default B2bModuleService +``` + +This creates a `B2bModuleService` that extends the service factory, which generates data-management functionalities for the `Company` data model. + +Next, create the module definition at `src/modules/b2b/index.ts` with the following content: + +```ts title="src/modules/b2b/index.ts" +import B2bModuleService from "./service" + +export default { + service: B2bModuleService, +} +``` + +Finally, add the module to the `modules` object in `medusa-config.js`: + +```js title="medusa-config.js" +module.exports = defineConfig({ + // ... + modules: { + b2bModuleService: { + resolve: "./modules/b2b", + definition: { + isQueryable: true, }, }, - }) - ``` + }, +}) +``` - You can now run migrations with the following commands: +You can now run migrations with the following commands: - ```bash npm2yarn - npx medusa migrations run - ``` +```bash npm2yarn +npx medusa migrations run +``` - ### Add Create Company API Route +### Add Create Company API Route - To test out using the B2B Module, you'll add an API route to create a company. +To test out using the B2B Module, you'll add an API route to create a company. - Start by creating the file `src/types/b2b/index.ts` with some helper types: +Start by creating the file `src/types/b2b/index.ts` with some helper types: - ```ts title="src/types/b2b/index.ts" - import { CustomerGroupDTO } from "@medusajs/types" +```ts title="src/types/b2b/index.ts" +import { CustomerGroupDTO } from "@medusajs/types" - export type CompanyDTO = { - id: string - name: string - city: string - country_code: string - customer_group_id?: string - customer_group?: CustomerGroupDTO - } +export type CompanyDTO = { + id: string + name: string + city: string + country_code: string + customer_group_id?: string + customer_group?: CustomerGroupDTO +} - export type CreateCompanyDTO = { - name: string - city: string - country_code: string - customer_group_id?: string - } +export type CreateCompanyDTO = { + name: string + city: string + country_code: string + customer_group_id?: string +} +``` - ``` - - Then, create the file `src/workflows/create-company.ts` with the following content: +Then, create the file `src/workflows/create-company.ts` with the following content: export const workflowHighlights = [ - ["23", "tryToCreateCustomerGroupStep", "This step creates the customer group if its data is passed in the `customer_group` property."], - ["36", "createCustomerGroupsWorkflow", "Use the `createCustomerGroupsWorkflow` defined by Medusa to create the customer group."], - ["44", "", "Set the ID of the new customer group in the `customer_group_id` property so that it's added to the created company."], + [ + "23", + "tryToCreateCustomerGroupStep", + "This step creates the customer group if its data is passed in the `customer_group` property.", + ], + [ + "36", + "createCustomerGroupsWorkflow", + "Use the `createCustomerGroupsWorkflow` defined by Medusa to create the customer group.", + ], + [ + "44", + "", + "Set the ID of the new customer group in the `customer_group_id` property so that it's added to the created company.", + ], ["54", "createCompanyStep", "This step creates the company."], ] - ```ts title="src/workflows/create-company.ts" highlights={workflowHighlights} collapsibleLines="1-12" expandButtonLabel="Show Imports" - import { - StepResponse, - createStep, - createWorkflow, - } from "@medusajs/workflows-sdk" - import { - createCustomerGroupsWorkflow, - } from "@medusajs/core-flows" - import { CreateCustomerGroupDTO } from "@medusajs/types" - import { CompanyDTO, CreateCompanyDTO } from "../types/b2b" - import B2bModuleService from "../modules/b2b/service" +```ts title="src/workflows/create-company.ts" highlights={workflowHighlights} collapsibleLines="1-12" expandButtonLabel="Show Imports" +import { + StepResponse, + createStep, + createWorkflow, +} from "@medusajs/workflows-sdk" +import { createCustomerGroupsWorkflow } from "@medusajs/core-flows" +import { CreateCustomerGroupDTO } from "@medusajs/types" +import { CompanyDTO, CreateCompanyDTO } from "../types/b2b" +import B2bModuleService from "../modules/b2b/service" - export type CreateCompanyWorkflowInput = CreateCompanyDTO & { - customer_group?: CreateCustomerGroupDTO - } +export type CreateCompanyWorkflowInput = CreateCompanyDTO & { + customer_group?: CreateCustomerGroupDTO +} - type CreateCompanyWorkflowOutput = { - company: CompanyDTO - } +type CreateCompanyWorkflowOutput = { + company: CompanyDTO +} - type CreateCustomerGroupStepInput = CreateCompanyWorkflowInput - - const tryToCreateCustomerGroupStep = createStep( - "try-to-create-customer-group-step", - async ( - { - customer_group, - ...company - }: CreateCustomerGroupStepInput, - { container }) => { - if (!customer_group) { - return new StepResponse({ company }) - } - - // create customer group - const { result } = await createCustomerGroupsWorkflow( - container - ).run({ - input: { - customersData: [customer_group], - }, - }) - - company.customer_group_id = result[0].id - - return new StepResponse({ company }) - } - ) - - export type CreateCompanyStep = { - companyData: CreateCompanyDTO - } - - const createCompanyStep = createStep( - "create-company-step", - async ( - { companyData }: CreateCompanyStep, - { container }) => { - const b2bModuleService: B2bModuleService = container - .resolve( - "b2bModuleService" - ) - - const company = await b2bModuleService.createCompany( - companyData - ) +type CreateCustomerGroupStepInput = CreateCompanyWorkflowInput +const tryToCreateCustomerGroupStep = createStep( + "try-to-create-customer-group-step", + async ( + { customer_group, ...company }: CreateCustomerGroupStepInput, + { container } + ) => { + if (!customer_group) { return new StepResponse({ company }) } - ) - export const createCompanyWorkflow = createWorkflow< - CreateCompanyWorkflowInput, - CreateCompanyWorkflowOutput - >( - "create-company", - function (input) { - const { - company: companyData, - } = tryToCreateCustomerGroupStep(input) - - const company = createCompanyStep({ companyData }) - - return company - } - ) - ``` - - You create a workflow with two steps: - - 1. The first one tries to create a customer group if its data is provided in the `customer_group` property and sets its value in the `customer_group_id` property. - 2. The second one creates the company. - - Finally, create the file `src/api/admin/b2b/company/route.ts` with the following content: - - ```ts title="src/api/admin/b2b/company/route.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports" - import type { - MedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { - CreateCompanyWorkflowInput, - createCompanyWorkflow, - } from "../../../../workflows/create-company" - - type CreateCompanyReq = CreateCompanyWorkflowInput - - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ) { - const { result } = await createCompanyWorkflow(req.scope) - .run({ - input: req.body, - }) - - res.json({ - company: result.company, + // create customer group + const { result } = await createCustomerGroupsWorkflow(container).run({ + input: { + customersData: [customer_group], + }, }) + + company.customer_group_id = result[0].id + + return new StepResponse({ company }) } - ``` +) - The API route uses the workflow to create the company. It passes the request body as the workflow's input. +export type CreateCompanyStep = { + companyData: CreateCompanyDTO +} - ### Test API Route +const createCompanyStep = createStep( + "create-company-step", + async ({ companyData }: CreateCompanyStep, { container }) => { + const b2bModuleService: B2bModuleService = + container.resolve("b2bModuleService") - To test the API route, start the Medusa application: + const company = await b2bModuleService.createCompany(companyData) - ```bash npm2yarn - npm run dev - ``` - - Next, make sure you authenticate as an admin user as explained in [this Authentication guide](!api!/api/admin#authentication). + return new StepResponse({ company }) + } +) - Then, send a `POST` request to the `/admin/b2b/company` API route: +export const createCompanyWorkflow = createWorkflow< + CreateCompanyWorkflowInput, + CreateCompanyWorkflowOutput +>("create-company", function (input) { + const { company: companyData } = tryToCreateCustomerGroupStep(input) - ```bash - curl -X POST 'localhost:9000/admin/b2b/company' \ - --header 'Content-Type: application/json' \ - --header 'Authorization: Bearer {jwt_token}' \ - --data '{ - "name": "Acme", - "city": "London", - "country_code": "gb", - "customer_group": { - "name": "B2B" - } - }' - ``` + const company = createCompanyStep({ companyData }) - This creates a company and its associated customer group. + return company +}) +``` + +You create a workflow with two steps: + +1. The first one tries to create a customer group if its data is provided in the `customer_group` property and sets its value in the `customer_group_id` property. +2. The second one creates the company. + +Finally, create the file `src/api/admin/b2b/company/route.ts` with the following content: + +```ts title="src/api/admin/b2b/company/route.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { + CreateCompanyWorkflowInput, + createCompanyWorkflow, +} from "../../../../workflows/create-company" + +type CreateCompanyReq = CreateCompanyWorkflowInput + +export async function POST( + req: MedusaRequest, + res: MedusaResponse +) { + const { result } = await createCompanyWorkflow(req.scope).run({ + input: req.body, + }) + + res.json({ + company: result.company, + }) +} +``` + +The API route uses the workflow to create the company. It passes the request body as the workflow's input. + +### Test API Route + +To test the API route, start the Medusa application: + +```bash npm2yarn +npm run dev +``` + +Next, make sure you authenticate as an admin user as explained in [this Authentication guide](!api!/api/admin#authentication). + +Then, send a `POST` request to the `/admin/b2b/company` API route: + +```bash +curl -X POST 'localhost:9000/admin/b2b/company' \ +--header 'Content-Type: application/json' \ +--header 'Authorization: Bearer {jwt_token}' \ +--data '{ + "name": "Acme", + "city": "London", + "country_code": "gb", + "customer_group": { + "name": "B2B" + } +}' +``` + +This creates a company and its associated customer group. - You can alternatively pass a `customer_group_id` to use an existing customer group. +You can alternatively pass a `customer_group_id` to use an existing customer group. @@ -516,51 +519,55 @@ You can do that through the Medusa Admin or Admin REST APIs. {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#customers_postcustomers", - title: "Option 2: Using the REST APIs", - text: "Create the customers using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#customers_postcustomers", + title: "Option 2: Using the REST APIs", + text: "Create the customers using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> ### Assign Customers to Groups {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#customer-groups_postcustomergroupsidcustomersbatch", - title: "Option 2: Using the REST APIs", - text: "Assign the customers to the B2B customer group using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#customer-groups_postcustomergroupsidcustomersbatch", + title: "Option 2: Using the REST APIs", + text: "Assign the customers to the B2B customer group using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -572,26 +579,28 @@ You can create a price list using the Medusa Admin or the Admin REST APIs. Make {/* TODO add links */} -, - showLinkIcon: false, - badge: { - variant: "blue", - children: "Guide Soon" - } - }, - { - href: "!api!/api/admin#price-lists_postpricelists", - title: "Using REST APIs", - text: "Create the price list using the REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + badge: { + variant: "blue", + children: "Guide Soon", + }, + }, + { + href: "!api!/api/admin#price-lists_postpricelists", + title: "Using REST APIs", + text: "Create the price list using the REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -599,7 +608,7 @@ You can create a price list using the Medusa Admin or the Admin REST APIs. Make To implement a more advanced B2B sales flow, add custom data models such as `Company`, `Employee`, `Admin`, and `Buyer` to your B2B module. -This provides more granular control of your B2B sales and allows you to build features like privileges, limits, and more. +This provides more granular control of your B2B sales and allows you to build features like privileges, limits, and more. -{/*
+{/\*
- For example, create the API route `src/api/store/b2b/check-customer/route.ts` with the following content: +For example, create the API route `src/api/store/b2b/check-customer/route.ts` with the following content: export const checkCustomerHighlights = [ ["19", "retrieveCustomer", "Retrieve the customer along with its groups."], - ["26", "listCompanies", "List the companies that have a customer group ID matching any of the customer's group IDs."], - ["31", "", "Return whether there are any companies associated with the customer's groups."] + [ + "26", + "listCompanies", + "List the companies that have a customer group ID matching any of the customer's group IDs.", + ], + [ + "31", + "", + "Return whether there are any companies associated with the customer's groups.", + ], ] - ```ts title="src/api/store/b2b/check-customer/route.ts" highlights={checkCustomerHighlights} collapsibleLines="1-5" expandButtonLabel="Show Imports" - import type { - AuthenticatedMedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" - import { ICustomerModuleService } from "@medusajs/types" - import B2bModuleService from "../../../../modules/b2b/service" - - export async function GET( - req: AuthenticatedMedusaRequest, - res: MedusaResponse - ) { - const customerModuleService: ICustomerModuleService = req - .scope.resolve(ModuleRegistrationName.CUSTOMER) - const b2bModuleService: B2bModuleService = req.scope.resolve( - "b2bModuleService" - ) +```ts title="src/api/store/b2b/check-customer/route.ts" highlights={checkCustomerHighlights} collapsibleLines="1-5" expandButtonLabel="Show Imports" +import type { + AuthenticatedMedusaRequest, + MedusaResponse, +} from "@medusajs/medusa" +import { ModuleRegistrationName } from "@medusajs/utils" +import { ICustomerModuleService } from "@medusajs/types" +import B2bModuleService from "../../../../modules/b2b/service" - const customer = await customerModuleService.retrieveCustomer( - req.auth_context.actor_id, - { - relations: ["groups"], - } - ) +export async function GET( + req: AuthenticatedMedusaRequest, + res: MedusaResponse +) { + const customerModuleService: ICustomerModuleService = req.scope.resolve( + ModuleRegistrationName.CUSTOMER + ) + const b2bModuleService: B2bModuleService = + req.scope.resolve("b2bModuleService") - const companies = await b2bModuleService.listCompanies({ - customer_group_id: customer.groups.map((group) => group.id), - }) + const customer = await customerModuleService.retrieveCustomer( + req.auth_context.actor_id, + { + relations: ["groups"], + } + ) - res.json({ - is_b2b: companies.length > 0, - }) - } - ``` + const companies = await b2bModuleService.listCompanies({ + customer_group_id: customer.groups.map((group) => group.id), + }) - This creates a `GET` API Route at `/store/b2b/check-customer` that: + res.json({ + is_b2b: companies.length > 0, + }) +} +``` - 1. Retrieves the customer along with its groups using the Customer Module's main service. - 2. Lists the companies that have a customer group ID matching any of the customer's group IDs. - 3. Return an `is_b2b` field whose value is `true` if there are any companies associated with the customer's groups. +This creates a `GET` API Route at `/store/b2b/check-customer` that: - Before using the API route, create the file `src/api/middlewares.ts` with the following content: +1. Retrieves the customer along with its groups using the Customer Module's main service. +2. Lists the companies that have a customer group ID matching any of the customer's group IDs. +3. Return an `is_b2b` field whose value is `true` if there are any companies associated with the customer's groups. - ```ts title="src/api/middlewares.ts" - import { - MiddlewaresConfig, - authenticate, - } from "@medusajs/medusa" +Before using the API route, create the file `src/api/middlewares.ts` with the following content: - export const config: MiddlewaresConfig = { - routes: [ - { - matcher: "/store/b2b*", - middlewares: [ - authenticate("store", ["bearer", "session"]), - ], - }, - ], - } - ``` +```ts title="src/api/middlewares.ts" +import { MiddlewaresConfig, authenticate } from "@medusajs/medusa" - This ensures that only logged-in customers can use the API route. +export const config: MiddlewaresConfig = { + routes: [ + { + matcher: "/store/b2b*", + middlewares: [authenticate("store", ["bearer", "session"])], + }, + ], +} +``` - ### Test API Route +This ensures that only logged-in customers can use the API route. - To test out the API route: +### Test API Route - 1. Start the Medusa application. - 2. Obtain an authentication JWT token for a new customer. Do that by sending a `POST` request to the `/auth/store/emailpass` API Route: +To test out the API route: - ```bash - curl -X POST 'http://localhost:9000/auth/store/emailpass' \ - -H 'Content-Type: application/json' \ - --data-raw '{ - "email": "test@medusajs.com", - "password": "supersecret" - }' - ``` - - 3. Send a `POST` request to the `/store/customers` API route that registers the customer. Make sure to pass the authentication JWT token from the previous token in the header: +1. Start the Medusa application. +2. Obtain an authentication JWT token for a new customer. Do that by sending a `POST` request to the `/auth/store/emailpass` API Route: - ```bash - curl -X POST 'http://localhost:9000/store/customers' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer {jwt_token}' \ - --data-raw '{ - "email": "test@medusajs.com", - "password": "supersecret" - }' - ``` +```bash +curl -X POST 'http://localhost:9000/auth/store/emailpass' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "email": "test@medusajs.com", + "password": "supersecret" +}' +``` - 4. Add the customer to the B2B group as explained in a [previous section](#add-b2b-customers). - 5. Send a `GET` request to the `/store/b2b/check-customer` API route you created in this section: +3. Send a `POST` request to the `/store/customers` API route that registers the customer. Make sure to pass the authentication JWT token from the previous token in the header: - ```bash - curl 'http://localhost:9000/store/b2b/check-customer' \ - --header 'Authorization: Bearer {jwt_token}' - ``` +```bash +curl -X POST 'http://localhost:9000/store/customers' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer {jwt_token}' \ +--data-raw '{ + "email": "test@medusajs.com", + "password": "supersecret" +}' +``` - You'll receive a JSON response as the following: +4. Add the customer to the B2B group as explained in a [previous section](#add-b2b-customers). +5. Send a `GET` request to the `/store/b2b/check-customer` API route you created in this section: - ```json - { - "is_b2b": true - } - ``` +```bash +curl 'http://localhost:9000/store/b2b/check-customer' \ +--header 'Authorization: Bearer {jwt_token}' +``` + +You'll receive a JSON response as the following: + +```json +{ + "is_b2b": true +} +```
*/} @@ -753,29 +765,31 @@ Based on your use case, you may need to customize the Medusa Admin to add new wi The Medusa Admin plugin can be extended to add widgets, new pages, and setting pages. -, - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/admin/ui-routes", - title: "Create Admin UI Routes", - text: "Learn how to add new pages to your Medusa Admin.", - startIcon: , - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/admin/setting-pages", - title: "Create Admin Setting Page", - text: "Learn how to add new page to the Medusa Admin settings.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/advanced-development/admin/ui-routes", + title: "Create Admin UI Routes", + text: "Learn how to add new pages to your Medusa Admin.", + startIcon: , + showLinkIcon: false, + }, + { + href: "!docs!/advanced-development/admin/setting-pages", + title: "Create Admin Setting Page", + text: "Learn how to add new page to the Medusa Admin settings.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -785,22 +799,24 @@ Medusa provides a Next.js storefront to use with your application. You can eithe Use the publishable API key you associated with your B2B sales channel in the storefront to ensure only B2B products are retrieved. -, - showLinkIcon: false - }, - { - href: "/storefront-development", - title: "Storefront Development", - text: "Find guides for your storefront development.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "/storefront-development", + title: "Storefront Development", + text: "Find guides for your storefront development.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> -The `inventory-item.updated` event is currently not emitted. +The `inventory-item.updated` event is currently not emitted. -, - showLinkIcon: false - }, - { - href: "!docs!/basics/data-models", - title: "Create a Data Model", - text: "Learn how to create a data model.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/basics/data-models", + title: "Create a Data Model", + text: "Learn how to create a data model.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> -, - showLinkIcon: false - }, - { - href: "!docs!/basics/events-and-subscribers", - title: "Create a Subscriber", - text: "Learn how to create a subscriber in Medusa.", - startIcon: , - showLinkIcon: false - }, -]} className="mt-1" /> +, + showLinkIcon: false, + }, + { + href: "!docs!/basics/events-and-subscribers", + title: "Create a Subscriber", + text: "Learn how to create a subscriber in Medusa.", + startIcon: , + showLinkIcon: false, + }, + ]} + className="mt-1" +/>
- In this example, you'll create a Restock Notification Module with the features explained above. +In this example, you'll create a Restock Notification Module with the features explained above. - ### Create Restock Notification Module +### Create Restock Notification Module - Start by creating the `src/modules/restock-notification` directory. +Start by creating the `src/modules/restock-notification` directory. - Then, create the file `src/modules/restock-notification/models/restock-notification.ts` with the following content: +Then, create the file `src/modules/restock-notification/models/restock-notification.ts` with the following content: export const restockModelHighlights = [ - ["5", "email", "The email of the customer to send the notification to when the item is restocked."], + [ + "5", + "email", + "The email of the customer to send the notification to when the item is restocked.", + ], ["6", "variant_id", "The ID of the variant the customer is subscribed to."], - ["7", "sales_channel_id", "The ID of the sales channel the customer is viewing the product variant from."] + [ + "7", + "sales_channel_id", + "The ID of the sales channel the customer is viewing the product variant from.", + ], ] - ```ts title="src/modules/restock-notification/models/restock-notification.ts" highlights={restockModelHighlights} - import { model } from "@medusajs/utils" +```ts title="src/modules/restock-notification/models/restock-notification.ts" highlights={restockModelHighlights} +import { model } from "@medusajs/utils" - const RestockNotification = model.define("restock_notification", { - id: model.id().primaryKey(), - email: model.text(), - variant_id: model.text(), - sales_channel_id: model.text(), - }) +const RestockNotification = model.define("restock_notification", { + id: model.id().primaryKey(), + email: model.text(), + variant_id: model.text(), + sales_channel_id: model.text(), +}) - export default RestockNotification - ``` +export default RestockNotification +``` - This creates a `RestockNotification` data model with the following properties: +This creates a `RestockNotification` data model with the following properties: - - `id`: An automatically generated ID. - - `email`: The email of the customer to send the notification to when the item is restocked. - - `variant_id`: The ID of the variant the customer is subscribed to. This will later be used to form a relationship with the `ProductVariant` data model of the Product Module. - - `sales_channel_id`: The ID of the sales channel the customer is viewing the product variant from. This will later be used to form a relationship with the `SalesChannel` data model of the Sales Channel Module. +- `id`: An automatically generated ID. +- `email`: The email of the customer to send the notification to when the item is restocked. +- `variant_id`: The ID of the variant the customer is subscribed to. This will later be used to form a relationship with the `ProductVariant` data model of the Product Module. +- `sales_channel_id`: The ID of the sales channel the customer is viewing the product variant from. This will later be used to form a relationship with the `SalesChannel` data model of the Sales Channel Module. - Since a variant's inventory is managed based on the locations of each sales channel, you have to specify which sales channel to check stock quantity in. +Since a variant's inventory is managed based on the locations of each sales channel, you have to specify which sales channel to check stock quantity in. - Next, create the file `src/modules/restock-notification/migrations/Migration20240516140616.ts` with the following content: +Next, create the file `src/modules/restock-notification/migrations/Migration20240516140616.ts` with the following content: - ```ts title="src/modules/restock-notification/migrations/Migration20240516140616.ts" - import { Migration } from "@mikro-orm/migrations" - - export class Migration20240516140616 extends Migration { +```ts title="src/modules/restock-notification/migrations/Migration20240516140616.ts" +import { Migration } from "@mikro-orm/migrations" - async up(): Promise { - this.addSql("create table if not exists \"restock_notification\" (\"id\" text not null, \"email\" text not null, \"variant_id\" text not null, \"sales_channel_id\" text not null, constraint \"restock_notification_pkey\" primary key (\"id\"));") - } - - async down(): Promise { - this.addSql("drop table if exists \"restock_notification\" cascade;") - } - - } - ``` - - You'll run the migration to reflect the changes on the database after finishing the module's definition. - - Then, create the module's main service at `src/modules/restock-notification/service.ts` with the following content: - - ```ts title="src/modules/restock-notification/service.ts" - import { MedusaService } from "@medusajs/utils" - import RestockNotification from "./models/restock-notification" - - class RestockNotificationModuleService extends MedusaService({ - RestockNotification, - }){ - // TODO add custom methods +export class Migration20240516140616 extends Migration { + async up(): Promise { + this.addSql( + 'create table if not exists "restock_notification" ("id" text not null, "email" text not null, "variant_id" text not null, "sales_channel_id" text not null, constraint "restock_notification_pkey" primary key ("id"));' + ) } - export default RestockNotificationModuleService - ``` - - The module's main service extends the service factory which generates basic management features for the `RestockNotification` data model. - - Next, create the module's definition file `src/modules/restock-notification/index.ts` with the following content: - - ```ts title="src/modules/restock-notification/index.ts" - import RestockNotificationModuleService from "./service" - - export default { - service: RestockNotificationModuleService, + async down(): Promise { + this.addSql('drop table if exists "restock_notification" cascade;') } - ``` +} +``` - Finally, add the module to the `modules` object in `medusa-config.js`: +You'll run the migration to reflect the changes on the database after finishing the module's definition. - ```js title="medusa-config.js" - module.exports = defineConfig({ - // ... - modules: { - "restockNotificationModuleService": { - resolve: "./modules/restock-notification", - definition: { - isQueryable: true, - }, +Then, create the module's main service at `src/modules/restock-notification/service.ts` with the following content: + +```ts title="src/modules/restock-notification/service.ts" +import { MedusaService } from "@medusajs/utils" +import RestockNotification from "./models/restock-notification" + +class RestockNotificationModuleService extends MedusaService({ + RestockNotification, +}) { + // TODO add custom methods +} + +export default RestockNotificationModuleService +``` + +The module's main service extends the service factory which generates basic management features for the `RestockNotification` data model. + +Next, create the module's definition file `src/modules/restock-notification/index.ts` with the following content: + +```ts title="src/modules/restock-notification/index.ts" +import RestockNotificationModuleService from "./service" + +export default { + service: RestockNotificationModuleService, +} +``` + +Finally, add the module to the `modules` object in `medusa-config.js`: + +```js title="medusa-config.js" +module.exports = defineConfig({ + // ... + modules: { + restockNotificationModuleService: { + resolve: "./modules/restock-notification", + definition: { + isQueryable: true, }, }, + }, +}) +``` + +You can now run the module's migrations with the following command: + +```bash npm2yarn +npx medusa migrations run +``` + +### Create Restock Notification API Route + +Create the file `src/api/store/restock-notification/route.ts` with the following content: + +```ts title="src/api/store/restock-notification/route.ts" collapsibleLines="1-13" expandButtonLabel="Show Imports" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import RestockNotificationModuleService from "../../../modules/restock-notification/service" + +type RestockNotificationReq = { + email: string + variant_id: string + sales_channel_id: string +} + +export async function POST( + req: MedusaRequest, + res: MedusaResponse +) { + const restockNotificationModuleService: RestockNotificationModuleService = + req.scope.resolve("restockNotificationModuleService") + + await restockNotificationModuleService.createRestockNotifications(req.body) + + res.json({ + success: true, }) - ``` +} +``` - You can now run the module's migrations with the following command: +This creates a `POST` API route at `/store/restock-notification`. It accepts the `email`, `variant_id`, and `sales_channel_id` request body parameters and creates a restock notification. - ```bash npm2yarn - npx medusa migrations run - ``` +### Create Inventory Item Updated Subscriber - ### Create Restock Notification API Route - - Create the file `src/api/store/restock-notification/route.ts` with the following content: - - ```ts title="src/api/store/restock-notification/route.ts" collapsibleLines="1-13" expandButtonLabel="Show Imports" - import type { - MedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import RestockNotificationModuleService - from "../../../modules/restock-notification/service" - - type RestockNotificationReq = { - email: string - variant_id: string - sales_channel_id: string - } - - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ) { - const restockNotificationModuleService: - RestockNotificationModuleService = req.scope.resolve( - "restockNotificationModuleService" - ) - - await restockNotificationModuleService.createRestockNotifications( - req.body - ) - - res.json({ - success: true, - }) - } - ``` - - This creates a `POST` API route at `/store/restock-notification`. It accepts the `email`, `variant_id`, and `sales_channel_id` request body parameters and creates a restock notification. - - ### Create Inventory Item Updated Subscriber - - To handle the sending of the restock notifications, create a subscriber that listens to the `inventory-item.updated` event, then sends a notification using the Notification Module to subscribed emails. +To handle the sending of the restock notifications, create a subscriber that listens to the `inventory-item.updated` event, then sends a notification using the Notification Module to subscribed emails. - The `inventory-item.updated` event is currently not emitted. +The `inventory-item.updated` event is currently not emitted. - {/* To handle the sending of the restock notifications, create the file `src/subscribers/inventory-item-update.ts` with the following content: */} +{/* To handle the sending of the restock notifications, create the file `src/subscribers/inventory-item-update.ts` with the following content: */} export const subscriberHighlights = [ - ["48", "inventoryVariantLinkService", "Retrieve an instance of the link service for the product-variant-inventory-item link module."], - ["55", "inventoryVariantItems", "Retrieve the variants linked to the updated inventory item."], - ["68", "restockQuery", "Assemble the query to retrieve the restock notifications with their associated variants."], - ["81", "restockNotifications", "Retrieve the restock notifications using the query."], - ["84", "salesChannelLocationService", "Retrieve an instance of the link service for the sales-channel-stock-location link module."], - ["93", "salesChannelLocations", "Retrieve the stock locations linked to the restock notification's sales channel."], - ["107", "availableQuantity", "Retrieve the available quantity of the variant in the retrieved stock locations."], - ["116", "continue", "Only send the notification if the available quantity is greater than `0`"], - ["119", "createNotifications", "Send the notification to the customer using the Notification Module."], - ["122", '"test_template"', "Replace with the actual template used for sending the email."], - ["123", "data", "The data to send along to the third-party service sending the notification."], - ["131", "deleteRestockNotifications", "Delete the restock notification to not send the notification again."] + [ + "48", + "inventoryVariantLinkService", + "Retrieve an instance of the link service for the product-variant-inventory-item link module.", + ], + [ + "55", + "inventoryVariantItems", + "Retrieve the variants linked to the updated inventory item.", + ], + [ + "68", + "restockQuery", + "Assemble the query to retrieve the restock notifications with their associated variants.", + ], + [ + "81", + "restockNotifications", + "Retrieve the restock notifications using the query.", + ], + [ + "84", + "salesChannelLocationService", + "Retrieve an instance of the link service for the sales-channel-stock-location link module.", + ], + [ + "93", + "salesChannelLocations", + "Retrieve the stock locations linked to the restock notification's sales channel.", + ], + [ + "107", + "availableQuantity", + "Retrieve the available quantity of the variant in the retrieved stock locations.", + ], + [ + "116", + "continue", + "Only send the notification if the available quantity is greater than `0`", + ], + [ + "119", + "createNotifications", + "Send the notification to the customer using the Notification Module.", + ], + [ + "122", + '"test_template"', + "Replace with the actual template used for sending the email.", + ], + [ + "123", + "data", + "The data to send along to the third-party service sending the notification.", + ], + [ + "131", + "deleteRestockNotifications", + "Delete the restock notification to not send the notification again.", + ], ] - {/* ```ts title="src/subscribers/inventory-item-update.ts" highlights={subscriberHighlights} collapsibleLines="1-20" expandButtonLabel="Show Imports" - import type { - SubscriberArgs, - SubscriberConfig, - } from "@medusajs/medusa" - import { - IInventoryService, - INotificationModuleService, - RemoteQueryFunction, - } from "@medusajs/types" - import { - ContainerRegistrationKeys, - Modules, - remoteQueryObjectFromString, - } from "@medusajs/utils" - import { - RemoteLink, - } from "@medusajs/modules-sdk" - import RestockNotificationModuleService - from "../modules/restock-notification/service" +{/\* ```ts title="src/subscribers/inventory-item-update.ts" highlights={subscriberHighlights} collapsibleLines="1-20" expandButtonLabel="Show Imports" +import type { +SubscriberArgs, +SubscriberConfig, +} from "@medusajs/medusa" +import { +IInventoryService, +INotificationModuleService, +RemoteQueryFunction, +} from "@medusajs/types" +import { +ContainerRegistrationKeys, +Modules, +remoteQueryObjectFromString, +} from "@medusajs/utils" +import { +RemoteLink, +} from "@medusajs/modules-sdk" +import RestockNotificationModuleService +from "../modules/restock-notification/service" - // subscriber function - export default async function inventoryItemUpdateHandler({ - data, - container, - }: SubscriberArgs<{ id: string }>) { - const remoteQuery: RemoteQueryFunction = container.resolve( - ContainerRegistrationKeys.REMOTE_QUERY - ) - const remoteLink: RemoteLink = container.resolve( - ContainerRegistrationKeys.REMOTE_LINK - ) - const restockNotificationModuleService: - RestockNotificationModuleService = container.resolve( - "restockNotificationModuleService" - ) - const inventoryModuleService: IInventoryService = - container.resolve(Modules.INVENTORY) - const notificationModuleService: INotificationModuleService = - container.resolve( - Modules.NOTIFICATION - ) +// subscriber function +export default async function inventoryItemUpdateHandler({ +data, +container, +}: SubscriberArgs<{ id: string }>) { +const remoteQuery: RemoteQueryFunction = container.resolve( +ContainerRegistrationKeys.REMOTE_QUERY +) +const remoteLink: RemoteLink = container.resolve( +ContainerRegistrationKeys.REMOTE_LINK +) +const restockNotificationModuleService: +RestockNotificationModuleService = container.resolve( +"restockNotificationModuleService" +) +const inventoryModuleService: IInventoryService = +container.resolve(Modules.INVENTORY) +const notificationModuleService: INotificationModuleService = +container.resolve( +Modules.NOTIFICATION +) const inventoryItemId = "data" in data ? data.data.id : data.id const inventoryVariantLinkService = remoteLink.getLinkModule( - Modules.PRODUCT, - "variant_id", - Modules.INVENTORY, + Modules.PRODUCT, + "variant_id", + Modules.INVENTORY, "inventory_item_id" ) - const inventoryVariantItems = + const inventoryVariantItems = await inventoryVariantLinkService.list({ inventory_item_id: [inventoryItemId], }) as { @@ -325,7 +378,7 @@ export const subscriberHighlights = [ }, }) - const restockNotifications = + const restockNotifications = await remoteQuery(restockQuery) const salesChannelLocationService = remoteLink.getLinkModule( @@ -336,7 +389,7 @@ export const subscriberHighlights = [ ) for (const restockNotification of restockNotifications) { - const salesChannelLocations = + const salesChannelLocations = await salesChannelLocationService.list({ sales_channel_id: [ restockNotification.sales_channel_id, @@ -354,7 +407,7 @@ export const subscriberHighlights = [ .retrieveAvailableQuantity( inventoryItemId, salesChannelLocations.map( - (salesChannelLocation) => + (salesChannelLocation) => salesChannelLocation.stock_location_id ) ) @@ -362,7 +415,7 @@ export const subscriberHighlights = [ if (availableQuantity === 0) { continue } - + notificationModuleService.createNotifications({ to: restockNotification.email, channel: "email", @@ -378,22 +431,24 @@ export const subscriberHighlights = [ await restockNotificationModuleService .deleteRestockNotifications(restockNotification.id) } - } - // subscriber config - export const config: SubscriberConfig = { - event: "inventory-item.updated", - } - ``` +} - This adds a subscriber to the `inventory-item.updated` event. In the subscriber handler function, you: +// subscriber config +export const config: SubscriberConfig = { +event: "inventory-item.updated", +} - - Retrieve an instance of the link service for the product-variant-inventory-item link module. - - Retrieve the variants linked to the updated inventory item. - - Retrieve the restock notifications of those variants. - - For each restock notification, you: - - Retrieve its quantity based on the stock location associated with the restock notification's sales channel. - - If the quantity is greater than `0`, you send a notification using the Notification Module and delete the restock notification. */} +```` + +This adds a subscriber to the `inventory-item.updated` event. In the subscriber handler function, you: + +- Retrieve an instance of the link service for the product-variant-inventory-item link module. +- Retrieve the variants linked to the updated inventory item. +- Retrieve the restock notifications of those variants. +- For each restock notification, you: + - Retrieve its quantity based on the stock location associated with the restock notification's sales channel. + - If the quantity is greater than `0`, you send a notification using the Notification Module and delete the restock notification. */}
@@ -414,20 +469,20 @@ The [Events reference](../../events-reference/page.mdx) shows an extensive list Medusa also provides Notification Module Providers that integrate with third-party services, such as SendGrid. , - showLinkIcon: false - }, - { - href: "!docs!/basics/events-and-subscribers", - title: "Create Subscriber", - text: "Learn how to create a subscriber to handle events.", - startIcon: , - showLinkIcon: false - }, +{ + href: "/architectural-modules/notification", + title: "Notification Module", + text: "Learn about the Notification Module.", + startIcon: , + showLinkIcon: false +}, +{ + href: "!docs!/basics/events-and-subscribers", + title: "Create Subscriber", + text: "Learn how to create a subscriber to handle events.", + startIcon: , + showLinkIcon: false +}, ]} /> --- @@ -442,217 +497,212 @@ To implement that: - Create a scheduled job that executes the workflow automatically at the specified time pattern. } - showLinkIcon={false} +href="!docs!/basics/scheduled-jobs" +title="Create a Scheduled Job" +text="Learn how to create a scheduled job in Medusa." +startIcon={} +showLinkIcon={false} />
- For example, create the file `src/workflows/sync-products.ts` with the following content: +For example, create the file `src/workflows/sync-products.ts` with the following content: export const syncProductsWorkflowHighlight = [ - ["20", "retrieveStoreStep", "A step that retrieves the store by its ID."], - ["36", "retrieveProductsToUpdateStep", "A step that retrieves the products to update based on a last update date."], - ["56", "syncProductsStep", "A step to sync the product with a third-party service."], - ["59", "productSyncModuleService", "Assuming this is a custom module's main service that provides connection to the third-party service."], - ["63", "productsBeforeSync", "Retrieve old product data from third-party service for compensation function."], - ["68", "sync", "Sync the product data in the third-party service."], - ["72", "", "Pass products data before sync to compensation function."], - ["75", "", "A compensation function to revert the sync when an error occurs."], - ["81", "sync", "Revert the product's data in the third-party service to its old data before the synchronization."], - ["90", "updateStoreLastSyncStep", "A step to update the `last_sync_data` of the store."], - ["96", "prevLastSyncDate", "Retrieve the previous value of `last_sync_date` to pass it to compensation function."], - ["98", "update", "Update the `last_sync_date` of the store."], - ["106", "", "Pass previous last sync date to compensation function."], - ["109", "", "A compensation function to revert the update of `last_sync_data` if an error occurs."], - ["125", "syncProductsWorkflow", "Define the workflow that uses the above steps."] +["20", "retrieveStoreStep", "A step that retrieves the store by its ID."], +["36", "retrieveProductsToUpdateStep", "A step that retrieves the products to update based on a last update date."], +["56", "syncProductsStep", "A step to sync the product with a third-party service."], +["59", "productSyncModuleService", "Assuming this is a custom module's main service that provides connection to the third-party service."], +["63", "productsBeforeSync", "Retrieve old product data from third-party service for compensation function."], +["68", "sync", "Sync the product data in the third-party service."], +["72", "", "Pass products data before sync to compensation function."], +["75", "", "A compensation function to revert the sync when an error occurs."], +["81", "sync", "Revert the product's data in the third-party service to its old data before the synchronization."], +["90", "updateStoreLastSyncStep", "A step to update the `last_sync_data` of the store."], +["96", "prevLastSyncDate", "Retrieve the previous value of `last_sync_date` to pass it to compensation function."], +["98", "update", "Update the `last_sync_date` of the store."], +["106", "", "Pass previous last sync date to compensation function."], +["109", "", "A compensation function to revert the update of `last_sync_data` if an error occurs."], +["125", "syncProductsWorkflow", "Define the workflow that uses the above steps."] ] - ```ts title="src/workflows/sync-products.ts" highlights={syncProductsWorkflowHighlight} collapsibleLines="1-16" expandButtonLabel="Show Imports" - import { - ModuleRegistrationName - } from "@medusajs/modules-sdk" - import { - IProductModuleService, - IStoreModuleService, - ProductDTO, - StoreDTO - } from "@medusajs/types" - import { - StepResponse, - createStep, - createWorkflow - } from "@medusajs/workflows-sdk" +```ts title="src/workflows/sync-products.ts" highlights={syncProductsWorkflowHighlight} collapsibleLines="1-16" expandButtonLabel="Show Imports" +import { + ModuleRegistrationName +} from "@medusajs/modules-sdk" +import { + IProductModuleService, + IStoreModuleService, + ProductDTO, + StoreDTO +} from "@medusajs/types" +import { + StepResponse, + createStep, + createWorkflow +} from "@medusajs/workflows-sdk" - type RetrieveStoreStepInput = { - id: string +type RetrieveStoreStepInput = { + id: string +} + +const retrieveStoreStep = createStep( + "retrieve-store-step", + async ({ id }: RetrieveStoreStepInput, { container }) => { + const storeModuleService: IStoreModuleService = + container.resolve(ModuleRegistrationName.STORE) + + const store = await storeModuleService.retrieveStore(id) + + return new StepResponse({ store }) } +) - const retrieveStoreStep = createStep( - "retrieve-store-step", - async ({ id }: RetrieveStoreStepInput, { container }) => { - const storeModuleService: IStoreModuleService = - container.resolve(ModuleRegistrationName.STORE) +type RetrieveProductsToUpdateStepInput = { + last_sync_date?: string +} - const store = await storeModuleService.retrieveStore(id) +const retrieveProductsToUpdateStep = createStep( + "retrieve-products-to-update-step", + async ({ last_sync_date }: RetrieveProductsToUpdateStepInput, { container }) => { + const productModuleService: IProductModuleService = + container.resolve(ModuleRegistrationName.PRODUCT) - return new StepResponse({ store }) - } - ) + const products = await productModuleService.listProducts({ + updated_at: { + $gt: last_sync_date, + }, + }) - type RetrieveProductsToUpdateStepInput = { - last_sync_date?: string + return new StepResponse({ products }) } +) - const retrieveProductsToUpdateStep = createStep( - "retrieve-products-to-update-step", - async ({ last_sync_date }: RetrieveProductsToUpdateStepInput, { container }) => { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) +type SyncProductsStepInput = { + products: ProductDTO[] +} - const products = await productModuleService.listProducts({ - updated_at: { - $gt: last_sync_date, - }, - }) - - return new StepResponse({ products }) - } - ) - - type SyncProductsStepInput = { - products: ProductDTO[] - } - - const syncProductsStep = createStep( - "sync-products-step", - async ({ products }: SyncProductsStepInput, { container }) => { - const productSyncModuleService = container.resolve( - "productSyncModuleService" - ) - - const productsBeforeSync = await productSyncModuleService.listProductSyncs({ - id: products.map((product) => product.id), - }) - - for (const product of products) { - await productSyncModuleService.sync(product) - } - - return new StepResponse({}, { - products: productsBeforeSync, - }) - }, - async ({ products }, { container }) => { - const productSyncModuleService = container.resolve( - "productSyncModuleService" - ) - - for (const product of products) { - await productSyncModuleService.sync(product) - } - } - ) - - type UpdateStoreLastSyncStepInput = { - store: StoreDTO - } - - const updateStoreLastSyncStep = createStep( - "update-store-last-sync-step", - async ({ store }: UpdateStoreLastSyncStepInput, { container }) => { - const storeModuleService: IStoreModuleService = - container.resolve(ModuleRegistrationName.STORE) - - const prevLastSyncDate = store.metadata.last_sync_date - - await storeModuleService.updateStores(store.id, { - metadata: { - last_sync_date: (new Date()).toString(), - }, - }) - - return new StepResponse({}, { - id: store.id, - last_sync_date: prevLastSyncDate, - }) - }, - async ({ id, last_sync_date }, { container }) => { - const storeModuleService: IStoreModuleService = - container.resolve(ModuleRegistrationName.STORE) - - await storeModuleService.updateStores(id, { - metadata: { - last_sync_date, - }, - }) - } - ) - - type SyncProductsWorkflowInput = { - store_id: string - } - - export const syncProductsWorkflow = createWorkflow< - SyncProductsWorkflowInput, {} - >( - "sync-products-workflow", - function ({ store_id }: SyncProductsWorkflowInput) { - const { store } = retrieveStoreStep({ - id: store_id, - }) - - const { products } = retrieveProductsToUpdateStep({ - last_sync_date: store.metadata.last_sync_date, - }) - - syncProductsStep({ - products, - }) - - updateStoreLastSyncStep({ - store, - }) - } +const syncProductsStep = createStep( + "sync-products-step", + async ({ products }: SyncProductsStepInput, { container }) => { + const productSyncModuleService = container.resolve( + "productSyncModuleService" ) - ``` - This creates a workflow with the following steps: + const productsBeforeSync = await productSyncModuleService.listProductSyncs({ + id: products.map((product) => product.id), + }) - 1. Retrieve the store by its ID. - 2. Retrieve products to update based on the last date and time the products were synced. The last sync date is retrieved from the store's `metadata` property. - 3. Sync the retrieved products with a third-party service. It's assumed that the connection to the third-party service is implemented within a custom module's main service. - 4. Update the last sync date of the store to the current date. + for (const product of products) { + await productSyncModuleService.sync(product) + } - Then, create a scheduled job at `src/jobs/sync-products.ts` that executes the workflow at the specified interval: + return new StepResponse({}, { + products: productsBeforeSync, + }) + }, + async ({ products }, { container }) => { + const productSyncModuleService = container.resolve( + "productSyncModuleService" + ) - ```ts - import { MedusaContainer } from "@medusajs/types" - import { - syncProductsWorkflow, - } from "../workflows/sync-products" + for (const product of products) { + await productSyncModuleService.sync(product) + } + } +) - export default async function syncProductsJob( - container: MedusaContainer - ) { - await syncProductsWorkflow(container) - .run({ - input: { - name: "John", +type UpdateStoreLastSyncStepInput = { + store: StoreDTO +} + +const updateStoreLastSyncStep = createStep( + "update-store-last-sync-step", + async ({ store }: UpdateStoreLastSyncStepInput, { container }) => { + const storeModuleService: IStoreModuleService = + container.resolve(ModuleRegistrationName.STORE) + + const prevLastSyncDate = store.metadata.last_sync_date + + await storeModuleService.updateStores(store.id, { + metadata: { + last_sync_date: (new Date()).toString(), + }, + }) + + return new StepResponse({}, { + id: store.id, + last_sync_date: prevLastSyncDate, + }) + }, + async ({ id, last_sync_date }, { container }) => { + const storeModuleService: IStoreModuleService = + container.resolve(ModuleRegistrationName.STORE) + + await storeModuleService.updateStores(id, { + metadata: { + last_sync_date, }, }) } +) - export const config = { - name: "sync-products", - // execute every minute - schedule: "0 0 * * *", - numberOfExecutions: 3, - } - ``` +type SyncProductsWorkflowInput = { + store_id: string +} + +export const syncProductsWorkflow = createWorkflow< + SyncProductsWorkflowInput, {} + >( + "sync-products-workflow", + function ({ store_id }: SyncProductsWorkflowInput) { + const { store } = retrieveStoreStep({ + id: store_id, + }) + + const { products } = retrieveProductsToUpdateStep({ + last_sync_date: store.metadata.last_sync_date, + }) + + syncProductsStep({ + products, + }) + + updateStoreLastSyncStep({ + store, + }) + } + ) +```` + +This creates a workflow with the following steps: + +1. Retrieve the store by its ID. +2. Retrieve products to update based on the last date and time the products were synced. The last sync date is retrieved from the store's `metadata` property. +3. Sync the retrieved products with a third-party service. It's assumed that the connection to the third-party service is implemented within a custom module's main service. +4. Update the last sync date of the store to the current date. + +Then, create a scheduled job at `src/jobs/sync-products.ts` that executes the workflow at the specified interval: + +```ts +import { MedusaContainer } from "@medusajs/types" +import { syncProductsWorkflow } from "../workflows/sync-products" + +export default async function syncProductsJob(container: MedusaContainer) { + await syncProductsWorkflow(container).run({ + input: { + name: "John", + }, + }) +} + +export const config = { + name: "sync-products", + // execute every minute + schedule: "0 0 * * *", + numberOfExecutions: 3, +} +```
@@ -678,22 +728,22 @@ The `order.placed` event is currently not emitted. showLinkIcon={false} /> -{/* , - showLinkIcon: false - }, - { - href: "/events-reference", - title: "Events Reference", - text: "Check out triggered events by each commerce module.", - startIcon: , - showLinkIcon: false - }, -]} /> */} +{/_ , +showLinkIcon: false +}, +{ +href: "/events-reference", +title: "Events Reference", +text: "Check out triggered events by each commerce module.", +startIcon: , +showLinkIcon: false +}, +]} /> _/} --- @@ -707,22 +757,24 @@ Medusa's commerce features are geared towards automating RMA flows and ensuring - Merchants can make order changes and request the customer's approval for them. The customer can also send any additional payment if necessary. - Every order-related action triggers an event, which you can listen to with a subscriber. This allows you to handle order events to automate actions. -, - showLinkIcon: false - }, - { - href: "!docs!/basics/events-and-subscribers", - title: "Create a Subscriber", - text: "Learn how to create a subscriber in Medusa.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/basics/events-and-subscribers", + title: "Create a Subscriber", + text: "Learn how to create a subscriber in Medusa.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -746,112 +798,110 @@ The `order.placed` event is currently not emitted. -, - showLinkIcon: false - }, - { - href: "/commerce-modules/pricing", - title: "Pricing Module", - text: "Learn about the Pricing Module and its features.", - startIcon: , - showLinkIcon: false - }, - { - href: "!docs!/basics/events-and-subscribers", - title: "Create a Subscriber", - text: "Learn how to create a subscriber in Medusa.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "/commerce-modules/pricing", + title: "Pricing Module", + text: "Learn about the Pricing Module and its features.", + startIcon: , + showLinkIcon: false, + }, + { + href: "!docs!/basics/events-and-subscribers", + title: "Create a Subscriber", + text: "Learn how to create a subscriber in Medusa.", + startIcon: , + showLinkIcon: false, + }, + ]} +/>
- Here’s an example of a subscriber that listens to the `order.placed` event and checks whether the customer should be added to the VIP customer group based on their number of orders: +Here’s an example of a subscriber that listens to the `order.placed` event and checks whether the customer should be added to the VIP customer group based on their number of orders: - The `order.placed` event is currently not emitted. +The `order.placed` event is currently not emitted. - ```ts title="src/subscribers/add-custom-to-vip.ts" collapsibleLines="1-12" expandButtonLabel="Show Imports" - import type { - SubscriberArgs, - SubscriberConfig, - } from "@medusajs/medusa" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" - import { - ICustomerModuleService, - IOrderModuleService, - } from "@medusajs/types" +```ts title="src/subscribers/add-custom-to-vip.ts" collapsibleLines="1-12" expandButtonLabel="Show Imports" +import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa" +import { ModuleRegistrationName } from "@medusajs/utils" +import { ICustomerModuleService, IOrderModuleService } from "@medusajs/types" - export default async function orderCreatedHandler({ - data, - container, - }: SubscriberArgs<{ id: string }>) { - const orderId = "data" in data ? data.data.id : data.id +export default async function orderCreatedHandler({ + data, + container, +}: SubscriberArgs<{ id: string }>) { + const orderId = "data" in data ? data.data.id : data.id - const orderModuleService: IOrderModuleService = container - .resolve(ModuleRegistrationName.ORDER) + const orderModuleService: IOrderModuleService = container.resolve( + ModuleRegistrationName.ORDER + ) - const customerModuleService: - ICustomerModuleService = container.resolve( - ModuleRegistrationName.CUSTOMER - ) + const customerModuleService: ICustomerModuleService = container.resolve( + ModuleRegistrationName.CUSTOMER + ) - // check if VIP group exists - const vipGroup = await customerModuleService - .listCustomerGroups({ - name: "VIP", - }, { - relations: ["customers"], - }) - - if (!vipGroup.length) { - return + // check if VIP group exists + const vipGroup = await customerModuleService.listCustomerGroups( + { + name: "VIP", + }, + { + relations: ["customers"], } + ) - // retrieve the order - const order = await orderModuleService.retrieveOrder(orderId) - - if (!order || - !order.customer_id || - vipGroup[0].customers.find( - (customer) => customer.id === order.customer_id - ) !== undefined) { - return - } - - const [, count] = await orderModuleService.listAndCountOrders({ - customer_id: order.customer_id, - }) - - if (count < 20) { - return - } - - // add customer to VIP group - await customerModuleService.addCustomerToGroup({ - customer_group_id: vipGroup[0].id, - customer_id: order.customer_id, - }) + if (!vipGroup.length) { + return } - export const config: SubscriberConfig = { - event: "order.placed", + // retrieve the order + const order = await orderModuleService.retrieveOrder(orderId) + + if ( + !order || + !order.customer_id || + vipGroup[0].customers.find( + (customer) => customer.id === order.customer_id + ) !== undefined + ) { + return } - ``` + + const [, count] = await orderModuleService.listAndCountOrders({ + customer_id: order.customer_id, + }) + + if (count < 20) { + return + } + + // add customer to VIP group + await customerModuleService.addCustomerToGroup({ + customer_group_id: vipGroup[0].id, + customer_id: order.customer_id, + }) +} + +export const config: SubscriberConfig = { + event: "order.placed", +} +```
- + --- @@ -863,116 +913,138 @@ To do that, create a subscriber that listens to the `product.created`, and send You can also create a scheduled job that checks whether the number of new products has exceeded a set threshold, then sends out the newsletter. -, - showLinkIcon: false - }, - { - href: "!docs!/basics/scheduled-jobs", - title: "Scheduled Jobs", - text: "Learn how to create a scheduled job in Medusa.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/basics/scheduled-jobs", + title: "Scheduled Jobs", + text: "Learn how to create a scheduled job in Medusa.", + startIcon: , + showLinkIcon: false, + }, + ]} +/>
- For example, create the file `src/subscribers/send-products-newsletter.ts` with the following content: +For example, create the file `src/subscribers/send-products-newsletter.ts` with the following content: export const newsletterHighlights = [ ["33", "store", "Retrieve the first store in the application."], - ["35", "products", "Retrieve the products created since the last newsletter send date."], - ["41", "", "Check whether more than 10 products have been created before proceeding."], - ["45", "customers", "Retrieve all customers, assuming they're considered subscribed."], - ["47", "createNotifications", "Send a notification (newsletter) to each customer using the Notification Module."], + [ + "35", + "products", + "Retrieve the products created since the last newsletter send date.", + ], + [ + "41", + "", + "Check whether more than 10 products have been created before proceeding.", + ], + [ + "45", + "customers", + "Retrieve all customers, assuming they're considered subscribed.", + ], + [ + "47", + "createNotifications", + "Send a notification (newsletter) to each customer using the Notification Module.", + ], ["50", '"email"', "Send the notification through the email channel."], - ["51", '"newsletter_template"', "Specify the template name in the third-party service (for example, SendGrid)."], + [ + "51", + '"newsletter_template"', + "Specify the template name in the third-party service (for example, SendGrid).", + ], ["53", "products", "Pass the created products to the template."], - ["58", "updateStores", "Update the store's `last_newsletter_send_date` property with the current date."] + [ + "58", + "updateStores", + "Update the store's `last_newsletter_send_date` property with the current date.", + ], ] - ```ts title="src/subscribers/send-products-newsletter.ts" highlights={newsletterHighlights} collapsibleLines="1-14" expandButtonLabel="Show Imports" - import type { - SubscriberArgs, - SubscriberConfig, - } from "@medusajs/medusa" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" - import { - ICustomerModuleService, - IProductModuleService, - IStoreModuleService, - INotificationModuleService, - } from "@medusajs/types" +```ts title="src/subscribers/send-products-newsletter.ts" highlights={newsletterHighlights} collapsibleLines="1-14" expandButtonLabel="Show Imports" +import type { SubscriberArgs, SubscriberConfig } from "@medusajs/medusa" +import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { + ICustomerModuleService, + IProductModuleService, + IStoreModuleService, + INotificationModuleService, +} from "@medusajs/types" - export default async function productCreateHandler({ - data, - container, - }: SubscriberArgs<{ id: string }>) { - const productModuleService: IProductModuleService = - container.resolve(ModuleRegistrationName.PRODUCT) +export default async function productCreateHandler({ + data, + container, +}: SubscriberArgs<{ id: string }>) { + const productModuleService: IProductModuleService = container.resolve( + ModuleRegistrationName.PRODUCT + ) - const storeModuleService: IStoreModuleService = - container.resolve(ModuleRegistrationName.STORE) + const storeModuleService: IStoreModuleService = container.resolve( + ModuleRegistrationName.STORE + ) - const customerModuleService: ICustomerModuleService = - container.resolve(ModuleRegistrationName.CUSTOMER) + const customerModuleService: ICustomerModuleService = container.resolve( + ModuleRegistrationName.CUSTOMER + ) - const notificationModuleService: - INotificationModuleService = container.resolve( - ModuleRegistrationName.NOTIFICATION - ) + const notificationModuleService: INotificationModuleService = + container.resolve(ModuleRegistrationName.NOTIFICATION) - const store = (await storeModuleService.listStores())[0] + const store = (await storeModuleService.listStores())[0] - const products = await productModuleService.listProducts({ - created_at: { - $gt: store.metadata.last_newsletter_send_date, - }, - }) + const products = await productModuleService.listProducts({ + created_at: { + $gt: store.metadata.last_newsletter_send_date, + }, + }) - if (products.length < 10) { - return - } - - const customers = await customerModuleService.listCustomers() - - await notificationModuleService.createNotifications( - customers.map((customer) => ({ - to: customer.email, - channel: "email", - template: "newsletter_template", - data: { - products, - }, - })) - ) - - await storeModuleService.updateStores(store.id, { - metadata: { - last_newsletter_send_date: (new Date()).toString(), - }, - }) + if (products.length < 10) { + return } - export const config: SubscriberConfig = { - event: "product.created", - } - ``` + const customers = await customerModuleService.listCustomers() - In the subscriber function, you: + await notificationModuleService.createNotifications( + customers.map((customer) => ({ + to: customer.email, + channel: "email", + template: "newsletter_template", + data: { + products, + }, + })) + ) - 1. Retrieve the first store in our application. - 2. Retrieve products created since the last time a newsletter is sent. The last send date is stored in the store's `metadata` property. - 3. If the count of last created products is less than 10, stop execution. - 4. Retrieve all customers. Here, it's assumed that all customers are considered subscribed for simplicity. - 5. Use the Notification Module to send a notification to the customer. This uses the Notification Module Provider configured for the `email` channel. - 6. Update the store's `last_newsletter_send_date` with the current date. + await storeModuleService.updateStores(store.id, { + metadata: { + last_newsletter_send_date: new Date().toString(), + }, + }) +} + +export const config: SubscriberConfig = { + event: "product.created", +} +``` + +In the subscriber function, you: + +1. Retrieve the first store in our application. +2. Retrieve products created since the last time a newsletter is sent. The last send date is stored in the store's `metadata` property. +3. If the count of last created products is less than 10, stop execution. +4. Retrieve all customers. Here, it's assumed that all customers are considered subscribed for simplicity. +5. Use the Notification Module to send a notification to the customer. This uses the Notification Module Provider configured for the `email` channel. +6. Update the store's `last_newsletter_send_date` with the current date.
diff --git a/www/apps/resources/app/recipes/digital-products/page.mdx b/www/apps/resources/app/recipes/digital-products/page.mdx index a0fe152ed2..9d6268db5d 100644 --- a/www/apps/resources/app/recipes/digital-products/page.mdx +++ b/www/apps/resources/app/recipes/digital-products/page.mdx @@ -33,22 +33,24 @@ Use a file module provider to manage your stored digital products. During development, you can use the Local File Module Provider, which is installed by default in your store. For production, check out available file module providers or create your own. -, - showLinkIcon: false - }, - { - href: "/references/file-provider-module", - title: "Create a File Module Provider", - text: "Learn how to create a file module provider.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "/references/file-provider-module", + title: "Create a File Module Provider", + text: "Learn how to create a file module provider.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -62,22 +64,24 @@ You can use one of Medusa’s notification module providers or create your own. {/* TODO add links */} -, - showLinkIcon: false - }, - { - href: "/references/notification-provider-module", - title: "Create a Notification Module Provider", - text: "Learn how to create a custom notification service.", - startIcon: , - showLinkIcon: false, - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "/references/notification-provider-module", + title: "Create a Notification Module Provider", + text: "Learn how to create a custom notification service.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -97,46 +101,46 @@ The module will hold your custom data models and the service implementing digita
- In this section, you’ll create the skeleton of the Digital Product Module. In later sections, you’ll add more resources to it. - - Start by creating the directory `src/modules/digital-product`. - - Then, create the file `src/modules/digital-product/service.ts` with the following content: - - ```ts title="src/modules/digital-product/service.ts" - class DigitalProductModuleService { - // TODO - } - - export default DigitalProductModuleService - ``` - - A module must export a service. So, you implement a dummy service for now. - - Next, create the file `src/modules/digital-product/index.ts` with the following content: - - ```ts title="src/modules/digital-product/index.ts" - import DigitalProductModuleService from "./service" - - export default { - service: DigitalProductModuleService, - } - ``` - - This file holds the definition of the module. - - Finally, add the module to `medusa-config.js` into the `modules` object: - - ```js title="medusa-config.js" - module.exports = defineConfig({ - // ... - modules: { - digitalProductModuleService: { - resolve: "./modules/digital-product", - }, +In this section, you’ll create the skeleton of the Digital Product Module. In later sections, you’ll add more resources to it. + +Start by creating the directory `src/modules/digital-product`. + +Then, create the file `src/modules/digital-product/service.ts` with the following content: + +```ts title="src/modules/digital-product/service.ts" +class DigitalProductModuleService { + // TODO +} + +export default DigitalProductModuleService +``` + +A module must export a service. So, you implement a dummy service for now. + +Next, create the file `src/modules/digital-product/index.ts` with the following content: + +```ts title="src/modules/digital-product/index.ts" +import DigitalProductModuleService from "./service" + +export default { + service: DigitalProductModuleService, +} +``` + +This file holds the definition of the module. + +Finally, add the module to `medusa-config.js` into the `modules` object: + +```js title="medusa-config.js" +module.exports = defineConfig({ + // ... + modules: { + digitalProductModuleService: { + resolve: "./modules/digital-product", }, - }) - ``` + }, +}) +```
@@ -162,41 +166,41 @@ Module Relationships is coming soon. showLinkIcon={false} /> -{/*
+{/\*
- In this section, you’ll create a `ProductMedia` data model that represents your digital products. - - Before creating the data model, create the file `src/types/digital-product/product-media.ts` that holds common types: - - ```ts title="src/types/digital-product/product-media.ts" - export enum MediaType { - MAIN = "main", - PREVIEW = "preview" - } - ``` - - Then, create the file `src/modules/digital-product/models/product-media.ts` with the following content: - - ```ts title="src/modules/digital-product/models/product-media.ts" - import { model } from "@medusajs/utils" - import { MediaType } from "../../../types/digital-product/product-media" +In this section, you’ll create a `ProductMedia` data model that represents your digital products. - const ProductMedia = model.define("product_media", { - id: model.id().primaryKey(), - name: model.text(), - type: model.enum(Object.values(MediaType)), - fileKey: model.text(), - mimeType: model.text(), - variant_id: model.text().index("IDX_product_media_variant_id"), - }) +Before creating the data model, create the file `src/types/digital-product/product-media.ts` that holds common types: + +```ts title="src/types/digital-product/product-media.ts" +export enum MediaType { + MAIN = "main", + PREVIEW = "preview", +} +``` + +Then, create the file `src/modules/digital-product/models/product-media.ts` with the following content: + +```ts title="src/modules/digital-product/models/product-media.ts" +import { model } from "@medusajs/utils" +import { MediaType } from "../../../types/digital-product/product-media" + +const ProductMedia = model.define("product_media", { + id: model.id().primaryKey(), + name: model.text(), + type: model.enum(Object.values(MediaType)), + fileKey: model.text(), + mimeType: model.text(), + variant_id: model.text().index("IDX_product_media_variant_id"), +}) + +export default ProductMedia +``` + +The `ProductMedia` data model has properties relevant to digital products. Most importantly, it has a `variant_id` property that will later be used for its relationship with the Product Module. + +To reflect the data model in the database, you must create a migration. - export default ProductMedia - ``` - - The `ProductMedia` data model has properties relevant to digital products. Most importantly, it has a `variant_id` property that will later be used for its relationship with the Product Module. - - To reflect the data model in the database, you must create a migration. - Learn how to generate a migration in [this guide](!docs!/basics/data-models#create-a-migration). @@ -246,32 +250,32 @@ Medusa facilitates implementing data-management features by providing a service showLinkIcon={false} /> -{/*
- - In this section, you’ll modify the `DigitalProductModuleService` you created earlier to provide data-management functionalities of the `ProductMedia` data model. - - Change the content of `src/modules/digital-product/service.ts` to the following: - - ```ts title="src/modules/digital-product/service.ts" - import { MedusaService } from "@medusajs/utils" - import ProductMedia from "./models/product-media" +{/\*
- class DigitalProductModuleService extends MedusaService({ - ProductMedia, - }){ - // TODO add custom methods - } +In this section, you’ll modify the `DigitalProductModuleService` you created earlier to provide data-management functionalities of the `ProductMedia` data model. + +Change the content of `src/modules/digital-product/service.ts` to the following: + +```ts title="src/modules/digital-product/service.ts" +import { MedusaService } from "@medusajs/utils" +import ProductMedia from "./models/product-media" + +class DigitalProductModuleService extends MedusaService({ + ProductMedia, +}) { + // TODO add custom methods +} + +export default DigitalProductModuleService +``` + +The `DigitalProductModuleService` now extends the service factory which generates data-management methods for the `ProductMedia` data model. - export default DigitalProductModuleService - ``` - - The `DigitalProductModuleService` now extends the service factory which generates data-management methods for the `ProductMedia` data model. -
*/} {/* --- */} -{/* ## Add Relationship to Product Variants +{/\* ## Add Relationship to Product Variants As mentioned in a previous section, the product media has a `variant_id` that points to the saleable product variant. @@ -340,8 +344,8 @@ The Medusa application resolves module relationships without creating an actual - Learn more about the data returned in the `__joinerConfig` method here. - +Learn more about the data returned in the `__joinerConfig` method here. + Next, change the module’s entry in the `modules` object in `medusa-config.js` to the following: @@ -378,530 +382,479 @@ Fetching data across modules using the remote query is coming soon. -, - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/modules/remote-query", - title: "Remote Query", - text: "Learn about what the remote query is and how to use it.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/advanced-development/modules/remote-query", + title: "Remote Query", + text: "Learn about what the remote query is and how to use it.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> -{/*
+{/\*
- In this section, you’ll create a List and Create API routes to retrieve and create digital products. - - ### Create API Route - - In the Create API route, you want to create not only the product media but also the associated product variant if no ID is specified. - - You’ll implement this logic in a workflow, then use the workflow in the API route. - - Start by changing the content of `src/types/digital-product/product-media.ts` to include more types: - - ```ts title="src/types/digital-product/product-media.ts" - import { - ProductVariantDTO, - CreateProductWorkflowInputDTO, - } from "@medusajs/types" - - export enum MediaType { - MAIN = "main", - PREVIEW = "preview" - } - - export type ProductMediaDTO = { - id: string - name: string - type: MediaType - file_key: string - mime_type: string - variant_id: string - variant?: ProductVariantDTO - } - - export type CreateProductMediaDTO = { - name: string - file_key: string - type: MediaType - mime_type: string - variant_id?: string - } - - export type CreateProductMediaWorkflowInput = - CreateProductMediaDTO & { - product?: CreateProductWorkflowInputDTO - } +In this section, you’ll create a List and Create API routes to retrieve and create digital products. - ``` - - Then, create the file `src/workflows/digital-product/create.ts` with the following content: - - ```ts title="src/workflows/digital-product/create.ts" collapsibleLines="1-19" expandButtonLabel="Show Imports" - import { - createWorkflow, - WorkflowData, - createStep, - StepResponse, - } from "@medusajs/workflows-sdk" - import { createProductsWorkflow } from "@medusajs/core-flows" - import { - CreateProductMediaDTO, - CreateProductMediaWorkflowInput, - ProductMediaDTO, - } from "../../types/digital-product/product-media" - import DigitalProductModuleService from - "../../modules/digital-product/service" - import { RemoteQueryFunction } from "@medusajs/modules-sdk" - import { - ContainerRegistrationKeys, - remoteQueryObjectFromString, - } from "@medusajs/utils" +### Create API Route - const tryToCreateProductVariantStep = createStep( - "try-to-create-product-variant-step", - async (input: CreateProductMediaWorkflowInput, { container }) => { - if (input.product && !input.variant_id) { - const { result, errors } = await createProductsWorkflow(container) - .run({ - input: { - products: [input.product], - }, - throwOnError: false, - }) +In the Create API route, you want to create not only the product media but also the associated product variant if no ID is specified. - if (errors.length) { - throw errors[0].error - } +You’ll implement this logic in a workflow, then use the workflow in the API route. - input.variant_id = result[0].variants[0].id +Start by changing the content of `src/types/digital-product/product-media.ts` to include more types: - delete input.product - } +```ts title="src/types/digital-product/product-media.ts" +import { + ProductVariantDTO, + CreateProductWorkflowInputDTO, +} from "@medusajs/types" - return new StepResponse(input) - } - ) +export enum MediaType { + MAIN = "main", + PREVIEW = "preview", +} - const createProductMediaStep = createStep( - "create-product-media-step", - async (input: CreateProductMediaDTO, { container }) => { - const digitalProductModuleService: - DigitalProductModuleService = container.resolve( - "digitalProductModuleService" - ) +export type ProductMediaDTO = { + id: string + name: string + type: MediaType + file_key: string + mime_type: string + variant_id: string + variant?: ProductVariantDTO +} - const productMedia = await digitalProductModuleService - .createProductMedias( - input - ) +export type CreateProductMediaDTO = { + name: string + file_key: string + type: MediaType + mime_type: string + variant_id?: string +} - return new StepResponse(productMedia) - } - ) +export type CreateProductMediaWorkflowInput = CreateProductMediaDTO & { + product?: CreateProductWorkflowInputDTO +} +``` - const retrieveProductMediaWithVariant = createStep( - "retrieve-product-media-with-variant-step", - async (input: ProductMediaDTO, { container }) => { - const remoteQuery: RemoteQueryFunction = container.resolve( - ContainerRegistrationKeys.REMOTE_QUERY - ) +Then, create the file `src/workflows/digital-product/create.ts` with the following content: - const query = remoteQueryObjectFromString({ - entryPoint: "product_media", - fields: [ - "id", - "name", - "type", - "file_key", - "mime_type", - "variant.*", - ], - variables: { - filters: { - id: input.id, - }, - }, - }) +```ts title="src/workflows/digital-product/create.ts" collapsibleLines="1-19" expandButtonLabel="Show Imports" +import { + createWorkflow, + WorkflowData, + createStep, + StepResponse, +} from "@medusajs/workflows-sdk" +import { createProductsWorkflow } from "@medusajs/core-flows" +import { + CreateProductMediaDTO, + CreateProductMediaWorkflowInput, + ProductMediaDTO, +} from "../../types/digital-product/product-media" +import DigitalProductModuleService from "../../modules/digital-product/service" +import { RemoteQueryFunction } from "@medusajs/modules-sdk" +import { + ContainerRegistrationKeys, + remoteQueryObjectFromString, +} from "@medusajs/utils" - const result = await remoteQuery(query) - - return new StepResponse(result[0]) - } - ) - - type WorkflowInput = { - data: CreateProductMediaWorkflowInput - } - - export const createProductMediaWorkflow = createWorkflow( - "create-product-media-workflow", - function (input: WorkflowData) { - // create the product variant before creating the media - // if variant_id isn't passed - const normalizedInput = tryToCreateProductVariantStep(input.data) - - const productMedia = createProductMediaStep(normalizedInput) - - return retrieveProductMediaWithVariant(productMedia) - } - ) - ``` - - This workflow has three steps: - - 1. If a `variant_id` field isn’t passed and a `product` field is passed, create the product using Medusa’s `createProductsWorkflow` and set the ID of the variant in the `variant_id` property. - 2. Use the `DigitalProductModuleService` to create the product media. - 3. Use the remote query to retrieve the product media along with the variant it references. - - Finally, create the `src/api/admin/digital-products/route.ts` file with the following content: - - ```ts title="src/api/admin/digital-products/route.ts" collapsibleLines="1-12" expandButtonLabel="Show Imports" - import { - MedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { MedusaError } from "@medusajs/utils" - import { - CreateProductMediaWorkflowInput, - } from "../../../types/digital-product/product-media" - import { - createProductMediaWorkflow, - } from "../../../workflows/digital-product/create" - - type CreateProductMediaReq = CreateProductMediaWorkflowInput - - export async function POST( - req: MedusaRequest, - res: MedusaResponse - ) { - // validation omitted for simplicity - const { - result, - errors, - } = await createProductMediaWorkflow(req.scope) - .run({ +const tryToCreateProductVariantStep = createStep( + "try-to-create-product-variant-step", + async (input: CreateProductMediaWorkflowInput, { container }) => { + if (input.product && !input.variant_id) { + const { result, errors } = await createProductsWorkflow(container).run({ input: { - data: { - ...req.body, - }, + products: [input.product], }, throwOnError: false, }) - - if (errors.length) { - throw new MedusaError( - MedusaError.Types.DB_ERROR, - errors[0].error - ) + + if (errors.length) { + throw errors[0].error + } + + input.variant_id = result[0].variants[0].id + + delete input.product } - - res.json({ - product_media: result, - }) + + return new StepResponse(input) } - ``` - - This adds a `POST` API route at `/admin/digital-products` that executes the `createProductMediaWorkflow` workflow. - - To test it out, start the Medusa application: - - ```bash npm2yarn - npm run dev - ``` - - Next, authenticate as an admin user as explained in the [API Reference] - - Then, upload a file using the Upload API route: - - ```bash - curl -X POST 'http://localhost:9000/admin/uploads' \ - -H 'Authorization: Bearer {bearer_token}' \ - --form 'files=@"/path/to/file"' - ``` - - Make sure to replace `/path/to/file` with the path to the file to upload. Copy the `id` field’s value as you’ll use it as the `file_key`'s value when creating the digital product. - - Finally, send a request to the API route you created: - - ```bash - curl -X POST 'localhost:9000/admin/digital-products' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer {bearer_token}' \ - --data '{ - "name": "Harry Potter", - "file_key": "file.png", - "type": "main", - "mime_type": "image/png", - "product": { - "title": "Harry Potter Books", - "variants": [ - { - "title": "Harry Potter 1" - } - ] - } - }' - ``` - - This creates a product and a variant, and a product media that references the created variant. - - You’ll receive a response similar to the following: - - ```json - { - "product_media": { - "id": "promed_01HXEFRMS79293ASYVN8YY9Y0J", - "name": "Harry Potter", - "type": "main", - "file_key": "file.png", - "mime_type": "image/png", - "variant_id": "variant_01HXEFRMR3B09EZJX23P1DMYFQ", - "variant": { - "id": "variant_01HXEFRMR3B09EZJX23P1DMYFQ", - "title": "Harry Potter 1", - // ... - } - } +) + +const createProductMediaStep = createStep( + "create-product-media-step", + async (input: CreateProductMediaDTO, { container }) => { + const digitalProductModuleService: DigitalProductModuleService = + container.resolve("digitalProductModuleService") + + const productMedia = await digitalProductModuleService.createProductMedias( + input + ) + + return new StepResponse(productMedia) } - ``` - - ### List API Route - - Next, you’ll create the List API route that returns a list of digital products. - - To do that, add the following to `src/api/admin/digital-products/route.ts`: - - ```ts title="src/api/admin/digital-products/route.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports" - // other imports... - import { RemoteQueryFunction } from "@medusajs/modules-sdk" - import { - ContainerRegistrationKeys, - remoteQueryObjectFromString, - } from "@medusajs/utils" - - // ... - - export async function GET( - req: MedusaRequest, - res: MedusaResponse - ) { - const remoteQuery: RemoteQueryFunction = req.scope.resolve( +) + +const retrieveProductMediaWithVariant = createStep( + "retrieve-product-media-with-variant-step", + async (input: ProductMediaDTO, { container }) => { + const remoteQuery: RemoteQueryFunction = container.resolve( ContainerRegistrationKeys.REMOTE_QUERY ) - + const query = remoteQueryObjectFromString({ entryPoint: "product_media", - fields: [ - "id", - "name", - "type", - "file_key", - "mime_type", - "variant.*", - "variant.product.*", - ], + fields: ["id", "name", "type", "file_key", "mime_type", "variant.*"], + variables: { + filters: { + id: input.id, + }, + }, }) - + const result = await remoteQuery(query) - - res.json({ - product_medias: result, - }) + + return new StepResponse(result[0]) } - ``` - - This creates a new `GET` API route at `/admin/digital-products` that retrieves the list of digital products and their associated variants. - - To test it out, send a request to the API route while your Medusa application is running: - - ```bash apiTesting testApiUrl="http://localhost:9000/admin/digital-products" testApiMethod="GET" - curl 'localhost:9000/admin/digital-products' \ - -H 'Authorization: Bearer {bearer_token}' \ - ``` - - You’ll receive a list of digital products. +) + +type WorkflowInput = { + data: CreateProductMediaWorkflowInput +} + +export const createProductMediaWorkflow = createWorkflow( + "create-product-media-workflow", + function (input: WorkflowData) { + // create the product variant before creating the media + // if variant_id isn't passed + const normalizedInput = tryToCreateProductVariantStep(input.data) + + const productMedia = createProductMediaStep(normalizedInput) + + return retrieveProductMediaWithVariant(productMedia) + } +) +``` + +This workflow has three steps: + +1. If a `variant_id` field isn’t passed and a `product` field is passed, create the product using Medusa’s `createProductsWorkflow` and set the ID of the variant in the `variant_id` property. +2. Use the `DigitalProductModuleService` to create the product media. +3. Use the remote query to retrieve the product media along with the variant it references. + +Finally, create the `src/api/admin/digital-products/route.ts` file with the following content: + +```ts title="src/api/admin/digital-products/route.ts" collapsibleLines="1-12" expandButtonLabel="Show Imports" +import { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { MedusaError } from "@medusajs/utils" +import { CreateProductMediaWorkflowInput } from "../../../types/digital-product/product-media" +import { createProductMediaWorkflow } from "../../../workflows/digital-product/create" + +type CreateProductMediaReq = CreateProductMediaWorkflowInput + +export async function POST( + req: MedusaRequest, + res: MedusaResponse +) { + // validation omitted for simplicity + const { result, errors } = await createProductMediaWorkflow(req.scope).run({ + input: { + data: { + ...req.body, + }, + }, + throwOnError: false, + }) + + if (errors.length) { + throw new MedusaError(MedusaError.Types.DB_ERROR, errors[0].error) + } + + res.json({ + product_media: result, + }) +} +``` + +This adds a `POST` API route at `/admin/digital-products` that executes the `createProductMediaWorkflow` workflow. + +To test it out, start the Medusa application: + +```bash npm2yarn +npm run dev +``` + +Next, authenticate as an admin user as explained in the [API Reference] + +Then, upload a file using the Upload API route: + +```bash +curl -X POST 'http://localhost:9000/admin/uploads' \ +-H 'Authorization: Bearer {bearer_token}' \ +--form 'files=@"/path/to/file"' +``` + +Make sure to replace `/path/to/file` with the path to the file to upload. Copy the `id` field’s value as you’ll use it as the `file_key`'s value when creating the digital product. + +Finally, send a request to the API route you created: + +```bash +curl -X POST 'localhost:9000/admin/digital-products' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer {bearer_token}' \ +--data '{ + "name": "Harry Potter", + "file_key": "file.png", + "type": "main", + "mime_type": "image/png", + "product": { + "title": "Harry Potter Books", + "variants": [ + { + "title": "Harry Potter 1" + } + ] + } +}' +``` + +This creates a product and a variant, and a product media that references the created variant. + +You’ll receive a response similar to the following: + +```json +{ + "product_media": { + "id": "promed_01HXEFRMS79293ASYVN8YY9Y0J", + "name": "Harry Potter", + "type": "main", + "file_key": "file.png", + "mime_type": "image/png", + "variant_id": "variant_01HXEFRMR3B09EZJX23P1DMYFQ", + "variant": { + "id": "variant_01HXEFRMR3B09EZJX23P1DMYFQ", + "title": "Harry Potter 1" + // ... + } + } +} +``` + +### List API Route + +Next, you’ll create the List API route that returns a list of digital products. + +To do that, add the following to `src/api/admin/digital-products/route.ts`: + +```ts title="src/api/admin/digital-products/route.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports" +// other imports... +import { RemoteQueryFunction } from "@medusajs/modules-sdk" +import { + ContainerRegistrationKeys, + remoteQueryObjectFromString, +} from "@medusajs/utils" + +// ... + +export async function GET(req: MedusaRequest, res: MedusaResponse) { + const remoteQuery: RemoteQueryFunction = req.scope.resolve( + ContainerRegistrationKeys.REMOTE_QUERY + ) + + const query = remoteQueryObjectFromString({ + entryPoint: "product_media", + fields: [ + "id", + "name", + "type", + "file_key", + "mime_type", + "variant.*", + "variant.product.*", + ], + }) + + const result = await remoteQuery(query) + + res.json({ + product_medias: result, + }) +} +``` + +This creates a new `GET` API route at `/admin/digital-products` that retrieves the list of digital products and their associated variants. + +To test it out, send a request to the API route while your Medusa application is running: + +```bash apiTesting testApiUrl="http://localhost:9000/admin/digital-products" testApiMethod="GET" +curl 'localhost:9000/admin/digital-products' \ +-H 'Authorization: Bearer {bearer_token}' \ +``` + +You’ll receive a list of digital products.
*/} - + --- ## Customize Admin Dashboard -You can extend the Medusa Admin to provide merchants with an interface to manage digital products. You can inject widgets into existing pages or create new pages. +You can extend the Medusa Admin to provide merchants with an interface to manage digital products. You can inject widgets into existing pages or create new pages. In your customizations, you send requests to the API routes you created to create and list digital products. -, - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/admin/ui-routes", - title: "Create UI Route", - text: "Learn how to create a UI route in the Medusa Admin.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/advanced-development/admin/ui-routes", + title: "Create UI Route", + text: "Learn how to create a UI route in the Medusa Admin.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> -{/*
+{/\*
- In this example, you’ll add a single page that lists the digital products and allows you to create a new one. The implementation will be minimal for the purpose of simplicity, so you can elaborate on it based on your use case. +In this example, you’ll add a single page that lists the digital products and allows you to create a new one. The implementation will be minimal for the purpose of simplicity, so you can elaborate on it based on your use case. - To create the UI route, create the file `src/admin/routes/product-media/page.tsx` with the following content: +To create the UI route, create the file `src/admin/routes/product-media/page.tsx` with the following content: - ```tsx title="src/admin/routes/product-media/page.tsx" badgeLabel="Medusa Application" collapsibleLines="1-13" expandButtonLabel="Show Imports" - import { defineRouteConfig } from "@medusajs/admin-shared" - import { useEffect, useState } from "react" - import { - Container, - Heading, - Table, - } from "@medusajs/ui" - import { PhotoSolid } from "@medusajs/icons" - import { ProductMediaDTO } from "../../../types/digital-product/product-media" - import { Link } from "react-router-dom" - import ProductMediaCreateForm - from "../../components/product-media/CreateForm" +```tsx title="src/admin/routes/product-media/page.tsx" badgeLabel="Medusa Application" collapsibleLines="1-13" expandButtonLabel="Show Imports" +import { defineRouteConfig } from "@medusajs/admin-shared" +import { useEffect, useState } from "react" +import { Container, Heading, Table } from "@medusajs/ui" +import { PhotoSolid } from "@medusajs/icons" +import { ProductMediaDTO } from "../../../types/digital-product/product-media" +import { Link } from "react-router-dom" +import ProductMediaCreateForm from "../../components/product-media/CreateForm" - const ProductMediaListPage = () => { - const [loading, setLoading] = useState(true) - const [productMedias, setProductMedias] = useState([]) +const ProductMediaListPage = () => { + const [loading, setLoading] = useState(true) + const [productMedias, setProductMedias] = useState([]) - useEffect(() => { - if (!loading) { - return - } + useEffect(() => { + if (!loading) { + return + } - fetch(`/admin/digital-products`, { - credentials: "include", - }) + fetch(`/admin/digital-products`, { + credentials: "include", + }) .then((response) => response.json()) .then(({ product_medias }) => { setProductMedias(product_medias) setLoading(false) }) - }, [loading]) + }, [loading]) - return ( - -
- Digital Products - setLoading(true)} /> -
- {loading &&
Loading...
} - {!loading && !productMedias.length && ( -
No Digital Products
- )} - {!loading && productMedias.length > 0 && ( - - - - Product - - Product Variant - - File Key - Action - - - - {productMedias.map((product_media) => ( - - - {product_media.variant?.product.title} - - - {product_media.variant?.title} - - - {product_media.file_key} - - - {product_media.variant && + return ( + +
+ Digital Products + setLoading(true)} /> +
+ {loading &&
Loading...
} + {!loading && !productMedias.length &&
No Digital Products
} + {!loading && productMedias.length > 0 && ( +
+ + + Product + Product Variant + File Key + Action + + + + {productMedias.map((product_media) => ( + + {product_media.variant?.product.title} + {product_media.variant?.title} + {product_media.file_key} + + {product_media.variant && ( + View Product - } - - - ))} - -
- )} -
- ) - } + + )} + + + ))} + + + )} + + ) +} - export const config = defineRouteConfig({ - label: "Digital Products", - icon: PhotoSolid, +export const config = defineRouteConfig({ + label: "Digital Products", + icon: PhotoSolid, +}) + +export default ProductMediaListPage +``` + +This UI route will show under the sidebar with the label “Digital Products”. In the page, you use the `/admin/digital-products` API route to retrieve and display the product medias. + +You also render a `ProductMediaCreateForm` component that implements the Create Digital Product form. + +To create this form, create the file `src/admin/components/product-media/CreateForm/index.tsx` with the following content: + +```tsx title="src/admin/components/product-media/CreateForm/index.tsx" badgeLabel="Medusa Application" collapsibleLines="1-11" expandButtonLabel="Show Imports" +import { useState } from "react" +import { redirect } from "react-router-dom" +import { Button, Container, Input, Label, Select, Drawer } from "@medusajs/ui" + +type Props = { + onCreate: () => void +} + +const ProductMediaCreateForm = ({ onCreate }: Props) => { + const [open, setOpen] = useState(false) + const [productName, setProductName] = useState("") + const [productVariantName, setProductVariantName] = useState("") + const [name, setName] = useState("") + const [type, setType] = useState("main") + const [file, setFile] = useState() + const [loading, setLoading] = useState(false) + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault() + setLoading(true) + + const formData = new FormData() + formData.append("files", file) + + // upload file + fetch(`/admin/uploads`, { + method: "POST", + credentials: "include", + body: formData, }) - - export default ProductMediaListPage - ``` - - This UI route will show under the sidebar with the label “Digital Products”. In the page, you use the `/admin/digital-products` API route to retrieve and display the product medias. - - You also render a `ProductMediaCreateForm` component that implements the Create Digital Product form. - - To create this form, create the file `src/admin/components/product-media/CreateForm/index.tsx` with the following content: - - ```tsx title="src/admin/components/product-media/CreateForm/index.tsx" badgeLabel="Medusa Application" collapsibleLines="1-11" expandButtonLabel="Show Imports" - import { useState } from "react" - import { redirect } from "react-router-dom" - import { - Button, - Container, - Input, - Label, - Select, - Drawer, - } from "@medusajs/ui" - - type Props = { - onCreate: () => void - } - - const ProductMediaCreateForm = ({ onCreate }: Props) => { - const [open, setOpen] = useState(false) - const [productName, setProductName] = useState("") - const [ - productVariantName, - setProductVariantName, - ] = useState("") - const [name, setName] = useState("") - const [type, setType] = useState("main") - const [file, setFile] = useState() - const [loading, setLoading] = useState(false) - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault() - setLoading(true) - - const formData = new FormData() - formData.append("files", file) - - // upload file - fetch(`/admin/uploads`, { - method: "POST", - credentials: "include", - body: formData, - }) .then((res) => res.json()) .then(({ files }) => { // create digital product @@ -926,96 +879,82 @@ In your customizations, you send requests to the API routes you created to creat }, }), }) - .then((res) => res.json()) - .then(() => { - setOpen(false) - setLoading(false) - onCreate() - }) - .catch((e) => { - console.error(e) - setLoading(false) - }) + .then((res) => res.json()) + .then(() => { + setOpen(false) + setLoading(false) + onCreate() + }) + .catch((e) => { + console.error(e) + setLoading(false) + }) }) .catch((e) => { console.error(e) setLoading(false) }) - } + } - return ( - - - - - - - - Create Digital Product - - - + return ( + + + + + + + Create Digital Product + + -
-
+ +
- setProductName(e.target.value)} />
-
+
- - setProductVariantName(e.target.value) - } + setProductVariantName(e.target.value)} />
-
+
- setName(e.target.value)} />
-
+
-
+
- setFile(e.target.files[0])} />
- @@ -1023,31 +962,31 @@ In your customizations, you send requests to the API routes you created to creat - ) - } + ) +} - export default ProductMediaCreateForm - ``` +export default ProductMediaCreateForm +``` - In this component, you create a form that accepts basic information needed to create the digital product. This form only accepts one file for one variant for simplicity purposes. You can expand on this based on your use case. +In this component, you create a form that accepts basic information needed to create the digital product. This form only accepts one file for one variant for simplicity purposes. You can expand on this based on your use case. - An alternative approach would be to inject a widget to the Product Details page and allow users to upload the files from there. It depends on whether you’re only supporting Digital Products or you want the distinction between them, as done here. +An alternative approach would be to inject a widget to the Product Details page and allow users to upload the files from there. It depends on whether you’re only supporting Digital Products or you want the distinction between them, as done here. - When the user submits the form, you first upload the file using the [Upload Protected File API Route](!api!/admin#uploads_postuploads). Then, you create the digital product using the custom API Route you created. +When the user submits the form, you first upload the file using the [Upload Protected File API Route](!api!/admin#uploads_postuploads). Then, you create the digital product using the custom API Route you created. - The product’s details can still be edited from the product's page, similar to regular products. You can edit its price, add more variants, and more. +The product’s details can still be edited from the product's page, similar to regular products. You can edit its price, add more variants, and more. - To test it out, run the `dev` command: +To test it out, run the `dev` command: - ```bash npm2yarn - npm run dev - ``` +```bash npm2yarn +npm run dev +``` - If you open the admin now, you’ll find a new Digital Products item in the sidebar. You can try adding Digital Products and viewing them. +If you open the admin now, you’ll find a new Digital Products item in the sidebar. You can try adding Digital Products and viewing them.
*/} @@ -1081,94 +1020,81 @@ In the subscriber, you can send a notification, such as an email, to the custome showLinkIcon={false} /> -{/*
+{/\*
- An alternative solution is to create a store download API Route that allows authenticated customers to download products they've purchased, then add the link to the API Route or a storefront page that calls the API Route in the email. Learn how to implement the download API Route [here](#download-product-after-purchase). +An alternative solution is to create a store download API Route that allows authenticated customers to download products they've purchased, then add the link to the API Route or a storefront page that calls the API Route in the email. Learn how to implement the download API Route [here](#download-product-after-purchase). - Here’s an example of a subscriber that retrieves the download links and sends them to the customer using the installed notification module provider: - - ```ts title="src/subscribers/handle-order.ts" badgeLabel="Medusa Application" collapsibleLines="1-15" expandButtonLabel="Show Imports" - import { - type SubscriberConfig, - type SubscriberArgs, - } from "@medusajs/medusa" - import { - IOrderModuleService, - IFileModuleService, - INotificationModuleService, - } from "@medusajs/types" - import { - ModuleRegistrationName, - } from "@medusajs/modules-sdk" - import DigitalProductModuleService - from "../modules/digital-product/service" +Here’s an example of a subscriber that retrieves the download links and sends them to the customer using the installed notification module provider: - export default async function handleOrderPlaced({ - data, container, - }: SubscriberArgs<{ id: string }>) { - const orderModuleService: IOrderModuleService = - container.resolve( - ModuleRegistrationName.ORDER - ) - const fileModuleService: IFileModuleService = - container.resolve( - ModuleRegistrationName.FILE - ) - const notificationModuleService: INotificationModuleService = - container.resolve(ModuleRegistrationName.NOTIFICATION) - const digitalProductModuleService: - DigitalProductModuleService = container.resolve( - "digitalProductModuleService" - ) +```ts title="src/subscribers/handle-order.ts" badgeLabel="Medusa Application" collapsibleLines="1-15" expandButtonLabel="Show Imports" +import { type SubscriberConfig, type SubscriberArgs } from "@medusajs/medusa" +import { + IOrderModuleService, + IFileModuleService, + INotificationModuleService, +} from "@medusajs/types" +import { ModuleRegistrationName } from "@medusajs/utils" +import DigitalProductModuleService from "../modules/digital-product/service" - const orderId = "data" in data ? data.data.id : data.id +export default async function handleOrderPlaced({ + data, + container, +}: SubscriberArgs<{ id: string }>) { + const orderModuleService: IOrderModuleService = container.resolve( + ModuleRegistrationName.ORDER + ) + const fileModuleService: IFileModuleService = container.resolve( + ModuleRegistrationName.FILE + ) + const notificationModuleService: INotificationModuleService = + container.resolve(ModuleRegistrationName.NOTIFICATION) + const digitalProductModuleService: DigitalProductModuleService = + container.resolve("digitalProductModuleService") - const order = await orderModuleService.retrieveOrder(orderId, { - relations: ["items"], + const orderId = "data" in data ? data.data.id : data.id + + const order = await orderModuleService.retrieveOrder(orderId, { + relations: ["items"], + }) + + // find product medias in the order + const urls = [] + for (const item of order.items) { + const productMedias = await digitalProductModuleService.listProductMedias({ + variant_id: [item.variant_id], }) - // find product medias in the order - const urls = [] - for (const item of order.items) { - const productMedias = await digitalProductModuleService - .listProductMedias({ - variant_id: [item.variant_id], - }) - - const downloadUrls = await Promise.all( - productMedias.map(async (productMedia) => { - - // get the download URL from the file service - return (await fileModuleService.retrieveFile( - productMedia.file_key - )).url - }) - ) + const downloadUrls = await Promise.all( + productMedias.map(async (productMedia) => { + // get the download URL from the file service + return (await fileModuleService.retrieveFile(productMedia.file_key)).url + }) + ) - urls.push(...downloadUrls) - } - - notificationModuleService.createNotifications({ - to: order.email, - template: "digital-download", - channel: "email", - data: { - // any data necessary for your template... - digital_download_urls: urls, - }, - }) + urls.push(...downloadUrls) } - export const config: SubscriberConfig = { - event: "order.placed", - } - ``` - - The `handleOrderPlaced` subscriber function retrieves the order, loops over its items to find digital products and retrieve their download links, then uses the installed notification module provider to send the email, passing the URLs as a data payload. You can customize the sent data based on your template and your use case. + notificationModuleService.createNotifications({ + to: order.email, + template: "digital-download", + channel: "email", + data: { + // any data necessary for your template... + digital_download_urls: urls, + }, + }) +} + +export const config: SubscriberConfig = { + event: "order.placed", +} +``` + +The `handleOrderPlaced` subscriber function retrieves the order, loops over its items to find digital products and retrieve their download links, then uses the installed notification module provider to send the email, passing the URLs as a data payload. You can customize the sent data based on your template and your use case.
*/} diff --git a/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx b/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx index f1e89eda42..8ed61e9f3e 100644 --- a/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx +++ b/www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx @@ -37,11 +37,11 @@ Then, resolve the module's main service in other resources, such as API routes o
- This example showcases how to create a module that integrates to a dummy ERP system. +This example showcases how to create a module that integrates to a dummy ERP system. - Start by creating the directory `src/modules/erp` for your module. +Start by creating the directory `src/modules/erp` for your module. - Then, create the file `src/modules/erp/service.ts` with the following content: +Then, create the file `src/modules/erp/service.ts` with the following content: export const serviceHighlights = [ ["4", "ErpModuleOptions", "The module's expected options."], @@ -56,12 +56,12 @@ export const serviceHighlights = [ import axios, { AxiosInstance } from "axios" import { ProductDTO } from "@medusajs/types" - type ErpModuleOptions = { - apiKey: string - } +type ErpModuleOptions = { +apiKey: string +} - class ErpModuleService { - private client_: AxiosInstance +class ErpModuleService { +private client\_: AxiosInstance constructor({}, { apiKey }: ErpModuleOptions) { this.client_ = axios.create({ @@ -74,66 +74,68 @@ export const serviceHighlights = [ async getProductData(id: string) { const { data: erpProduct } = await this.client_.get(`/product/${id}`) - + return erpProduct } async createProduct(data: ProductDTO) { const { data: erpProduct } = await this.client_.post(`/product`, data) - + return erpProduct } async deleteProduct(id: string) { await this.client_.delete(`/product/${id}`) } - } - export default ErpModuleService - ``` +} - This creates the module's main service. Few things to note: +export default ErpModuleService - - The module accepts an `apiKey` option, used to authenticate to the dummy ERP system. The module's main service accesses this option in the second parameter of the constructor. - - The module uses axios to create a client in the constructor. The client is used in the service's methods when connecting to the ERP system. If the system you're integrating has an SDK, you can initialize it in the constructor, instead. - - The `getProductData` method retrieves a product's details from the ERP system by sending a `GET` request using the client. - - The `createProduct` method creates a product in the ERP system by sending a `POST` request using the client. - - The `deleteProduct` method deletes a product in the ERP system by sending a `DELETE` request using the client. +```` - +This creates the module's main service. Few things to note: - You can store the product's ID in the external system using the `metadata` property of the `Product` data model in the Product Module. Alternatively, you can create a [data model](!docs!/basics/data-models) in your module to store data related to the external system. +- The module accepts an `apiKey` option, used to authenticate to the dummy ERP system. The module's main service accesses this option in the second parameter of the constructor. +- The module uses axios to create a client in the constructor. The client is used in the service's methods when connecting to the ERP system. If the system you're integrating has an SDK, you can initialize it in the constructor, instead. +- The `getProductData` method retrieves a product's details from the ERP system by sending a `GET` request using the client. +- The `createProduct` method creates a product in the ERP system by sending a `POST` request using the client. +- The `deleteProduct` method deletes a product in the ERP system by sending a `DELETE` request using the client. - + - Then, create the module's definition file at `src/modules/erp/index.ts` with the following content: +You can store the product's ID in the external system using the `metadata` property of the `Product` data model in the Product Module. Alternatively, you can create a [data model](!docs!/basics/data-models) in your module to store data related to the external system. - ```ts title="src/modules/erp/index.ts" - import ErpModuleService from "./service" - - export default { - service: ErpModuleService, - } - ``` + - Finally, add the module to the `modules` object in `medusa-config.js`: +Then, create the module's definition file at `src/modules/erp/index.ts` with the following content: - ```js title="medusa-config.js" highlights={[["7", "ERP_API_KEY", "The environment variable holding the API key of the ERP system."]]} - module.exports = defineConfig({ - // ... - modules: { - erpModuleService: { - resolve: "./modules/erp", - options: { - apiKey: process.env.ERP_API_KEY, - }, +```ts title="src/modules/erp/index.ts" +import ErpModuleService from "./service" + +export default { + service: ErpModuleService, +} +```` + +Finally, add the module to the `modules` object in `medusa-config.js`: + +```js title="medusa-config.js" highlights={[["7", "ERP_API_KEY", "The environment variable holding the API key of the ERP system."]]} +module.exports = defineConfig({ + // ... + modules: { + erpModuleService: { + resolve: "./modules/erp", + options: { + apiKey: process.env.ERP_API_KEY, }, }, - }) - ``` + }, +}) +```
- + --- @@ -167,12 +169,28 @@ export const workflowHighlights = [ ["24", "productModuleService", "Resolve the Product Module's main service."], ["28", "retrieve", "Retrieve the created product's data."], ["30", "createProduct", "Create the product in the ERP system."], - ["34", "update", "Update the product in Medusa with the ID of the ERP product."], + [ + "34", + "update", + "Update the product in Medusa with the ID of the ERP product.", + ], ["43", "erpId", "Pass the ERP product's ID to the compensation function."], ["44", "productId", "Pass the product's ID to the compensation function."], - ["46", "", "Define a compensation function that rolls back changes when an error occurs."], - ["53", "deleteProduct", "Undo creating the product in the ERP system by deleting it."], - ["54", "update", "Update the product in Medusa to remove the ERP product's ID."] + [ + "46", + "", + "Define a compensation function that rolls back changes when an error occurs.", + ], + [ + "53", + "deleteProduct", + "Undo creating the product in the ERP system by deleting it.", + ], + [ + "54", + "update", + "Update the product in Medusa to remove the ERP product's ID.", + ], ] ```ts title="src/workflows/create-product.ts" highlights={workflowHighlights} collapsibleLines="1-9" expandButtonLabel="Show Imports" @@ -182,7 +200,7 @@ export const workflowHighlights = [ createWorkflow } from "@medusajs/workflows-sdk" import { IProductModuleService } from "@medusajs/types" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" + import { ModuleRegistrationName } from "@medusajs/utils" import ErpModuleService from "../modules/erp/service" type WorkflowInput = { @@ -194,14 +212,14 @@ export const workflowHighlights = [ } const createInErpStep = createStep( - "create-in-erp", + "create-in-erp", async ({ productId }: WorkflowInput, { container }) => { const erpModuleService: ErpModuleService = container.resolve( "erpModuleService" ) const productModuleService: IProductModuleService = container .resolve(ModuleRegistrationName.PRODUCT) - + const createdProductData = await productModuleService .retrieveProduct(productId) @@ -214,7 +232,7 @@ export const workflowHighlights = [ erp_id: erpProduct.id } }) - + return new StepResponse({ erpProduct }, { @@ -250,20 +268,20 @@ export const workflowHighlights = [ - Retrieves the product's data using the Product Module's main service. - Create the product in the ERP system using the ERP Module's main service. - Updates the product in Medusa by setting the ID of the ERP product in the product's `metadata` property. - + The step also has a compensation function that rolls back changes when an error occurs. It deletes the product in the ERP system and removes the ID of the ERP product in the Medusa product. - + Then, create the subscriber at `src/subscribers/create-product.ts`: ```ts title="src/subscribers/create-product.ts" - import type { - SubscriberConfig, + import type { + SubscriberConfig, SubscriberArgs, } from "@medusajs/medusa" import createProductWorkflow from "../workflows/create-product" - export default async function handleProductUpdate({ - data, container + export default async function handleProductUpdate({ + data, container }: SubscriberArgs<{id: string}>) { createProductWorkflow(container) .run({ @@ -306,12 +324,12 @@ For example, suppose an administrator changes the product data in the ERP system For example, create the file `src/api/webhooks/erp/update/route.ts` with the following content: ```ts title="src/api/webhooks/erp/update/route.ts" collapsibleLines="1-12" expandButtonLabel="Show Imports" - import { - MedusaRequest, - MedusaResponse, + import { + MedusaRequest, + MedusaResponse, } from "@medusajs/medusa" - import { - IProductModuleService, + import { + IProductModuleService, UpdateProductDTO } from "@medusajs/types" import { @@ -324,7 +342,7 @@ For example, suppose an administrator changes the product data in the ERP system } export async function POST( - req: MedusaRequest, + req: MedusaRequest, res: MedusaResponse ) { const { id, updatedData} = req.body @@ -339,15 +357,15 @@ For example, suppose an administrator changes the product data in the ERP system res.status(200) } ``` - + This creates a webhook listener for an ERP system. It receives the ID of a product and its updated data, assuming that’s how your ERP system sends the data. - + Then, create the file `src/api/middlewares.ts` with the following content: ```ts title="src/api/middlewares.ts" import { MiddlewaresConfig } from "@medusajs/medusa" import { raw } from "body-parser" - + export const config: MiddlewaresConfig = { routes: [ { diff --git a/www/apps/resources/app/recipes/marketplace/page.mdx b/www/apps/resources/app/recipes/marketplace/page.mdx index 5bb178a99f..56f46f9bb9 100644 --- a/www/apps/resources/app/recipes/marketplace/page.mdx +++ b/www/apps/resources/app/recipes/marketplace/page.mdx @@ -40,113 +40,119 @@ Module Relationships is coming soon. -, - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/modules/module-relationships", - title: "Module Relationships", - text: "Create relationships between modules.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/advanced-development/modules/module-relationships", + title: "Module Relationships", + text: "Create relationships between modules.", + startIcon: , + showLinkIcon: false, + }, + ]} +/>
- In this section, you’ll create a Marketplace Module with the necessary relationships and functionalities in the main service. - - Start by creating the directory `src/modules/marketplace`. - - Then, create the file `src/modules/marketplace/models/store-user.ts` with the following content: - - ```ts title="src/modules/marketplace/models/store-user.ts" - import { model } from "@medusajs/utils" +In this section, you’ll create a Marketplace Module with the necessary relationships and functionalities in the main service. - const StoreUser = model.define("store_user", { - id: model.id().primaryKey(), - store_id: model.text(), - user_id: model.text(), - }) +Start by creating the directory `src/modules/marketplace`. - export default StoreUser - ``` - - This creates a `StoreUser` data model with the `store_id` and `user_id` properties. - - {/* These properties will be used later to establish relationships to the Store and User modules. */} - - Next, create the file `src/modules/marketplace/models/store-product.ts` with the following content: - - ```ts title="src/modules/marketplace/models/store-product.ts" - import { model } from "@medusajs/utils" +Then, create the file `src/modules/marketplace/models/store-user.ts` with the following content: - const StoreProduct = model.define("store_user", { - id: model.id().primaryKey(), - store_id: model.text(), - product_id: model.text(), - }) +```ts title="src/modules/marketplace/models/store-user.ts" +import { model } from "@medusajs/utils" - export default StoreProduct - ``` - - This creates a `StoreProduct` data model with the `store_id` and `product_id` properties. - - {/* These properties will be used later to establish relationships to the Store and Product modules. */} - - Finally, create the file `src/modules/marketplace/models/store-order.ts` with the following content: - - ```ts title="src/modules/marketplace/models/store-order.ts" - import { model } from "@medusajs/utils" +const StoreUser = model.define("store_user", { + id: model.id().primaryKey(), + store_id: model.text(), + user_id: model.text(), +}) - const StoreOrder = model.define("store_user", { - id: model.id().primaryKey(), - store_id: model.text(), - order_id: model.text(), - parent_order_id: model.text(), - }) +export default StoreUser +``` - export default StoreOrder - ``` - - This creates a `StoreOrder` data model with the `store_id`, `order_id`, and `parent_order_id` properties. - - {/* The `store_id` and `order_id` properties will be used to establish relationships to the Store and Order modules. You’ll learn about the use of `parent_order_id` in a later section. */} - - To reflect these changes on the database, create the migration `src/modules/marketplace/migrations/Migration20240514143248.ts` with the following content: - - ```ts title="src/modules/marketplace/migrations/Migration20240514143248.ts" - import { Migration } from "@mikro-orm/migrations" - - export class Migration20240514143248 extends Migration { - - async up(): Promise { - this.addSql("create table if not exists \"store_order\" (\"id\" varchar(255) not null, \"store_id\" text not null, \"order_id\" text not null, \"parent_order_id\" text not null, constraint \"store_order_pkey\" primary key (\"id\"));") - - this.addSql("create table if not exists \"store_product\" (\"id\" varchar(255) not null, \"store_id\" text not null, \"product_id\" text not null, constraint \"store_product_pkey\" primary key (\"id\"));") - - this.addSql("create table if not exists \"store_user\" (\"id\" varchar(255) not null, \"store_id\" text not null, \"user_id\" text not null, constraint \"store_user_pkey\" primary key (\"id\"));") - } - - async down(): Promise { - this.addSql("drop table if exists \"store_order\" cascade;") - - this.addSql("drop table if exists \"store_product\" cascade;") - - this.addSql("drop table if exists \"store_user\" cascade;") - } - +This creates a `StoreUser` data model with the `store_id` and `user_id` properties. + +{/* These properties will be used later to establish relationships to the Store and User modules. */} + +Next, create the file `src/modules/marketplace/models/store-product.ts` with the following content: + +```ts title="src/modules/marketplace/models/store-product.ts" +import { model } from "@medusajs/utils" + +const StoreProduct = model.define("store_user", { + id: model.id().primaryKey(), + store_id: model.text(), + product_id: model.text(), +}) + +export default StoreProduct +``` + +This creates a `StoreProduct` data model with the `store_id` and `product_id` properties. + +{/* These properties will be used later to establish relationships to the Store and Product modules. */} + +Finally, create the file `src/modules/marketplace/models/store-order.ts` with the following content: + +```ts title="src/modules/marketplace/models/store-order.ts" +import { model } from "@medusajs/utils" + +const StoreOrder = model.define("store_user", { + id: model.id().primaryKey(), + store_id: model.text(), + order_id: model.text(), + parent_order_id: model.text(), +}) + +export default StoreOrder +``` + +This creates a `StoreOrder` data model with the `store_id`, `order_id`, and `parent_order_id` properties. + +{/* The `store_id` and `order_id` properties will be used to establish relationships to the Store and Order modules. You’ll learn about the use of `parent_order_id` in a later section. */} + +To reflect these changes on the database, create the migration `src/modules/marketplace/migrations/Migration20240514143248.ts` with the following content: + +```ts title="src/modules/marketplace/migrations/Migration20240514143248.ts" +import { Migration } from "@mikro-orm/migrations" + +export class Migration20240514143248 extends Migration { + async up(): Promise { + this.addSql( + 'create table if not exists "store_order" ("id" varchar(255) not null, "store_id" text not null, "order_id" text not null, "parent_order_id" text not null, constraint "store_order_pkey" primary key ("id"));' + ) + + this.addSql( + 'create table if not exists "store_product" ("id" varchar(255) not null, "store_id" text not null, "product_id" text not null, constraint "store_product_pkey" primary key ("id"));' + ) + + this.addSql( + 'create table if not exists "store_user" ("id" varchar(255) not null, "store_id" text not null, "user_id" text not null, constraint "store_user_pkey" primary key ("id"));' + ) } - ``` - - You’ll run the migration after registering the module in the Medusa configurations. - - Then, create the module’s main service at `src/modules/marketplace/service.ts` with the following content: + + async down(): Promise { + this.addSql('drop table if exists "store_order" cascade;') + + this.addSql('drop table if exists "store_product" cascade;') + + this.addSql('drop table if exists "store_user" cascade;') + } +} +``` + +You’ll run the migration after registering the module in the Medusa configurations. + +Then, create the module’s main service at `src/modules/marketplace/service.ts` with the following content: export const mainServiceHighlights = [ ["6", "MedusaService", "Extends the service factory to generate data management features."] @@ -158,53 +164,54 @@ export const mainServiceHighlights = [ import StoreProduct from "./models/store-product" import StoreOrder from "./models/store-order" - class MarketplaceModuleService extends MedusaService({ - StoreUser, - StoreProduct, - StoreOrder, - }){ - // TODO add custom methods - } +class MarketplaceModuleService extends MedusaService({ +StoreUser, +StoreProduct, +StoreOrder, +}){ +// TODO add custom methods +} - export default MarketplaceModuleService - ``` - - The module’s main service extends the service factory to generate data management features for the `StoreUser`, `StoreProduct`, and `StoreOrder` data models. - - Finally, create the module definition at `src/modules/marketplace/index.ts` with the following content: - - ```ts title="src/modules/marketplace/index.ts" - import MarketplaceModuleService from "./service" - - export default { - service: MarketplaceModuleService, - } - ``` - - To use the module, add it to the `modules` object in `medusa-config.js`: - - ```js title="medusa-config.js" - module.exports = defineConfig({ - // ... - modules: { - marketplaceModuleService: { - resolve: "./modules/marketplace", - definition: { - isQueryable: true, - }, +export default MarketplaceModuleService + +```` + +The module’s main service extends the service factory to generate data management features for the `StoreUser`, `StoreProduct`, and `StoreOrder` data models. + +Finally, create the module definition at `src/modules/marketplace/index.ts` with the following content: + +```ts title="src/modules/marketplace/index.ts" +import MarketplaceModuleService from "./service" + +export default { + service: MarketplaceModuleService, +} +```` + +To use the module, add it to the `modules` object in `medusa-config.js`: + +```js title="medusa-config.js" +module.exports = defineConfig({ + // ... + modules: { + marketplaceModuleService: { + resolve: "./modules/marketplace", + definition: { + isQueryable: true, }, }, - }) - ``` - - Then, run the migrations of the module: - - ```bash npm2yarn - npx medusa migrations run - ``` + }, +}) +``` + +Then, run the migrations of the module: + +```bash npm2yarn +npx medusa migrations run +```
- + --- @@ -227,10 +234,10 @@ To attach admin users to their own stores, create a subscriber that listens to t showLinkIcon={false} /> -{/*
+{/\*
+ +Create the file `src/subscribers/user-created.ts` with the following content: - Create the file `src/subscribers/user-created.ts` with the following content: - export const userSubscriberHighlights = [ ["13", "data", "The event data payload with the created user's ID."], ["27", "retrieveUser", "Retrieve the created user."], @@ -243,60 +250,62 @@ export const userSubscriberHighlights = [ SubscriberArgs, SubscriberConfig, } from "@medusajs/medusa" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" + import { ModuleRegistrationName } from "@medusajs/utils" import { IUserModuleService, IStoreModuleService, } from "@medusajs/types" import MarketplaceModuleService from "../modules/marketplace/service" - export default async function userCreatedHandler({ - data, - container, - }: SubscriberArgs<{ id: string }>) { - const { id } = "data" in data ? data.data : data - const userModuleService: IUserModuleService = container.resolve( - ModuleRegistrationName.USER - ) - const storeModuleService: IStoreModuleService = container.resolve( - ModuleRegistrationName.STORE - ) - const marketplaceModuleService: MarketplaceModuleService = container.resolve( - "marketplaceModuleService" - ) +export default async function userCreatedHandler({ +data, +container, +}: SubscriberArgs<{ id: string }>) { +const { id } = "data" in data ? data.data : data +const userModuleService: IUserModuleService = container.resolve( +ModuleRegistrationName.USER +) +const storeModuleService: IStoreModuleService = container.resolve( +ModuleRegistrationName.STORE +) +const marketplaceModuleService: MarketplaceModuleService = container.resolve( +"marketplaceModuleService" +) const user = await userModuleService.retrieveUser(id) const store = await storeModuleService.createStores({ name: `${user.first_name}'s Store`, }) - + const storeUser = await marketplaceModuleService.createStoreUsers({ store_id: store.id, user_id: user.id, }) console.log(`Created StoreUser ${storeUser.id}`) - } - export const config: SubscriberConfig = { - event: "user.created", - } - ``` - - This adds a subscriber to the `user.created` event. In the subscriber, you: - - - Retrieve the created user. The created user’s ID is passed in the event’s data payload. - - Create a store for that user using the Store Module. - - Create a relationship between the user and the store by creating a `StoreUser` record. - - To test it out, use the `medusa user` command to create a user: - - ```bash npm2yarn - npx medusa user -e my-admin@medusa-test.com -p supersecret - ``` - - At the end of the output, you should see the message `Created StoreUser {store_user_id}` where the `{store_user_id}` is the ID of the created `StoreUser`. +} + +export const config: SubscriberConfig = { +event: "user.created", +} + +```` + +This adds a subscriber to the `user.created` event. In the subscriber, you: + +- Retrieve the created user. The created user’s ID is passed in the event’s data payload. +- Create a store for that user using the Store Module. +- Create a relationship between the user and the store by creating a `StoreUser` record. + +To test it out, use the `medusa user` command to create a user: + +```bash npm2yarn +npx medusa user -e my-admin@medusa-test.com -p supersecret +```` + +At the end of the output, you should see the message `Created StoreUser {store_user_id}` where the `{store_user_id}` is the ID of the created `StoreUser`.
*/} @@ -321,9 +330,9 @@ Similar to the previous section, to attach products to stores, create a subscrib showLinkIcon={false} /> -{/*
+{/\*
- Create the file `src/subscribers/product-created.ts` with the following content: +Create the file `src/subscribers/product-created.ts` with the following content: export const productSubscriberHighlights = [ ["24", "retrieveProduct", "Retrieve the created product."], @@ -336,21 +345,21 @@ export const productSubscriberHighlights = [ SubscriberArgs, SubscriberConfig, } from "@medusajs/medusa" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" + import { ModuleRegistrationName } from "@medusajs/utils" import { IProductModuleService, } from "@medusajs/types" import MarketplaceModuleService from "../modules/marketplace/service" - export default async function productCreateHandler({ - data, - container, - }: SubscriberArgs<{ id: string }>) { - const { id } = "data" in data ? data.data : data - const productModuleService: IProductModuleService = container.resolve( - ModuleRegistrationName.PRODUCT - ) - +export default async function productCreateHandler({ +data, +container, +}: SubscriberArgs<{ id: string }>) { +const { id } = "data" in data ? data.data : data +const productModuleService: IProductModuleService = container.resolve( +ModuleRegistrationName.PRODUCT +) + const marketplaceModuleService: MarketplaceModuleService = container.resolve( "marketplaceModuleService" ) @@ -365,43 +374,45 @@ export const productSubscriberHighlights = [ store_id: product.metadata.store_id as string, product_id: id, }) - } - export const config: SubscriberConfig = { - event: "product.created", - } - ``` - - This adds a subscriber to the `product.created` event. In the subscriber, you: - - - Retrieve the created product. - - This subscriber requires the store ID to be set in `product.metadata.store_id`. If not, the subscriber ends execution. - - If the store ID is found, create a relationship between the product and the store by creating a `StoreProduct` record. - - To test it out, start the Medusa application: - - ```bash npm2yarn - npm run dev - ``` - - Then, send an authenticated `POST` request to `/admin/products`: - - ```bash - curl -X POST 'http://localhost:9000/admin/products' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer {jwt_token}' \ - --data '{ - "title": "My Shirt 13", - "metadata": { - "store_id": "store_01HXV74JCCAHA3F2X3EWZTZG5R" - } - }' - ``` - - This returns the created product. In the next section, you’ll implement the API route to fetch the products of a store. +} + +export const config: SubscriberConfig = { +event: "product.created", +} + +```` + +This adds a subscriber to the `product.created` event. In the subscriber, you: + +- Retrieve the created product. +- This subscriber requires the store ID to be set in `product.metadata.store_id`. If not, the subscriber ends execution. +- If the store ID is found, create a relationship between the product and the store by creating a `StoreProduct` record. + +To test it out, start the Medusa application: + +```bash npm2yarn +npm run dev +```` + +Then, send an authenticated `POST` request to `/admin/products`: + +```bash +curl -X POST 'http://localhost:9000/admin/products' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer {jwt_token}' \ +--data '{ + "title": "My Shirt 13", + "metadata": { + "store_id": "store_01HXV74JCCAHA3F2X3EWZTZG5R" + } +}' +``` + +This returns the created product. In the next section, you’ll implement the API route to fetch the products of a store.
*/} - + --- @@ -415,26 +426,28 @@ Retrieving module relationship data using the remote query is coming soon. -, - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/modules/remote-query", - title: "Remote Query", - text: "Use the remote query to fetch data across modules.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/advanced-development/modules/remote-query", + title: "Remote Query", + text: "Use the remote query to fetch data across modules.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> -{/*
+{/\*
- Create the file `src/api/admin/marketplace/products/route.ts` with the following content: +Create the file `src/api/admin/marketplace/products/route.ts` with the following content: export const productRoutesHighlights = [ ["26", "storeUsers", "Retrieve the store of the logged-in user."], @@ -456,17 +469,17 @@ export const productRoutesHighlights = [ import MarketplaceModuleService from "../../../../modules/marketplace/service" - export async function GET( - req: AuthenticatedMedusaRequest, - res: MedusaResponse - ): Promise { - const marketplaceModuleService: MarketplaceModuleService = - req.scope.resolve( - "marketplaceModuleService" - ) - const remoteQuery: RemoteQueryFunction = req.scope.resolve( - ContainerRegistrationKeys.REMOTE_QUERY - ) +export async function GET( +req: AuthenticatedMedusaRequest, +res: MedusaResponse +): Promise { +const marketplaceModuleService: MarketplaceModuleService = +req.scope.resolve( +"marketplaceModuleService" +) +const remoteQuery: RemoteQueryFunction = req.scope.resolve( +ContainerRegistrationKeys.REMOTE_QUERY +) const storeUsers = await marketplaceModuleService .listStoreUsers({ @@ -498,51 +511,53 @@ export const productRoutesHighlights = [ store_id: storeUsers[0].store_id, products: result.map((data) => data.product), }) - } - ``` - - This creates a `GET` API route at `/admin/marketplace/products`. In the API route, you: - - - Retrieve the store of the logged-in user. - - Build a query that retrieves the products of that store. - - Retrieve the products using remote query and return them. - - Next, create the file `src/api/middlewares.ts` with the following content: - - ```ts title="src/api/middlewares.ts" - import { - MiddlewaresConfig, - authenticate, - } from "@medusajs/medusa" - - export const config: MiddlewaresConfig = { - routes: [ - { - matcher: "/admin/marketplace*", - middlewares: [ - authenticate( - "admin", - ["session", "bearer", "api-key"] - ), - ], - }, - ], - } - ``` - - This ensures that only authenticated admin users can access your API route. - - To test it out, start the Medusa application. Then, send a `GET` request to `/admin/marketplace/products`: - - ```bash - curl 'localhost:9000/admin/marketplace/products' \ - -H 'Authorization: Bearer {jwt_token}' - ``` - - This will return the product you created in the previous section, if the `{jwt_token}` belongs to the user of the same store ID. + +} + +```` + +This creates a `GET` API route at `/admin/marketplace/products`. In the API route, you: + +- Retrieve the store of the logged-in user. +- Build a query that retrieves the products of that store. +- Retrieve the products using remote query and return them. + +Next, create the file `src/api/middlewares.ts` with the following content: + +```ts title="src/api/middlewares.ts" +import { + MiddlewaresConfig, + authenticate, +} from "@medusajs/medusa" + +export const config: MiddlewaresConfig = { + routes: [ + { + matcher: "/admin/marketplace*", + middlewares: [ + authenticate( + "admin", + ["session", "bearer", "api-key"] + ), + ], + }, + ], +} +```` + +This ensures that only authenticated admin users can access your API route. + +To test it out, start the Medusa application. Then, send a `GET` request to `/admin/marketplace/products`: + +```bash +curl 'localhost:9000/admin/marketplace/products' \ +-H 'Authorization: Bearer {jwt_token}' +``` + +This will return the product you created in the previous section, if the `{jwt_token}` belongs to the user of the same store ID.
*/} - + --- @@ -564,9 +579,9 @@ The `order.placed` event is still not emitted in Medusa V2. showLinkIcon={false} /> -{/*
+{/\*
- Create the file `src/subscribers/order-created.ts` with the following content: +Create the file `src/subscribers/order-created.ts` with the following content: export const orderSubscriberHighlights = [ ["35", "", "Loop over the created order’s items."], @@ -581,7 +596,7 @@ export const orderSubscriberHighlights = [ SubscriberArgs, SubscriberConfig, } from "@medusajs/medusa" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" + import { ModuleRegistrationName } from "@medusajs/utils" import { IOrderModuleService, CreateOrderDTO, @@ -590,17 +605,17 @@ export const orderSubscriberHighlights = [ from "../modules/marketplace/service" import { createOrdersWorkflow } from "@medusajs/core-flows" - export default async function orderCreatedHandler({ - data, - container, - }: SubscriberArgs<{ id: string }>) { - const { id } = "data" in data ? data.data : data - const orderModuleService: IOrderModuleService = - container.resolve( - ModuleRegistrationName.ORDER - ) - - const marketplaceModuleService: MarketplaceModuleService = +export default async function orderCreatedHandler({ +data, +container, +}: SubscriberArgs<{ id: string }>) { +const { id } = "data" in data ? data.data : data +const orderModuleService: IOrderModuleService = +container.resolve( +ModuleRegistrationName.ORDER +) + + const marketplaceModuleService: MarketplaceModuleService = container.resolve( "marketplaceModuleService" ) @@ -622,7 +637,7 @@ export const orderSubscriberHighlights = [ } const storeId = storeProduct[0].store_id - + if (!storeToOrders[storeId]) { const { id, ...orderDetails } = order storeToOrders[storeId] = { @@ -643,10 +658,10 @@ export const orderSubscriberHighlights = [ } if ( - storeToOrdersKeys.length === 1 && + storeToOrdersKeys.length === 1 && storeToOrders[0].items.length === order.items.length ) { - // The order is composed of items from one store, so + // The order is composed of items from one store, so // associate the order as-is with the store. await marketplaceModuleService.createStoreOrders({ store_id: storeToOrdersKeys[0], @@ -671,26 +686,28 @@ export const orderSubscriberHighlights = [ }) }) ) - } - export const config: SubscriberConfig = { - event: "order.placed", - } - ``` - - This adds a subscriber to the `order.placed` event. In the subscriber, you: - - - Loop over the created order’s items. - - Group the items by their store ID. - - If the items have the same store ID, then associate the created order with the store. - - If there are items from more than one store in the order, create child orders and associate each of them with the store. Here, you use the `parent_order_id` property in the `StoreOrder` data model to point to the original order. - - To test this out, create an order in your store. That will run the subscriber and create the child orders. - - The next section covers how to retrieve the store’s orders. +} + +export const config: SubscriberConfig = { +event: "order.placed", +} + +```` + +This adds a subscriber to the `order.placed` event. In the subscriber, you: + +- Loop over the created order’s items. +- Group the items by their store ID. +- If the items have the same store ID, then associate the created order with the store. +- If there are items from more than one store in the order, create child orders and associate each of them with the store. Here, you use the `parent_order_id` property in the `StoreOrder` data model to point to the original order. + +To test this out, create an order in your store. That will run the subscriber and create the child orders. + +The next section covers how to retrieve the store’s orders.
*/} - + --- @@ -705,95 +722,95 @@ Retrieving module relationship data using the remote query is coming soon. , - showLinkIcon: false - }, - { - href: "!docs!/advanced-development/modules/remote-query", - title: "Remote Query", - text: "Use the remote query to fetch data across modules.", - startIcon: , - showLinkIcon: false - }, +{ + href: "!docs!/basics/api-routes", + title: "API Routes", + text: "Learn how to create an API Route in Medusa.", + startIcon: , + showLinkIcon: false +}, +{ + href: "!docs!/advanced-development/modules/remote-query", + title: "Remote Query", + text: "Use the remote query to fetch data across modules.", + startIcon: , + showLinkIcon: false +}, ]} /> {/*
- Create the file `src/api/admin/marketplace/orders/route.ts` with the following content: +Create the file `src/api/admin/marketplace/orders/route.ts` with the following content: export const orderRoutesHighlights = [ - ["25", "", "Retrieve the store of the logged-in user."], - ["29", "", "Build a query that retrieves the orders of that store."], - ["41", "", "Retrieve the orders using remote query."] +["25", "", "Retrieve the store of the logged-in user."], +["29", "", "Build a query that retrieves the orders of that store."], +["41", "", "Retrieve the orders using remote query."] ] - - ```ts title="src/api/admin/marketplace/orders/route.ts" highlights={orderRoutesHighlights} collapsibleLines="1-12" expandButtonLabel="Show Imports" - import { - AuthenticatedMedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { RemoteQueryFunction } from "@medusajs/modules-sdk" - import { - remoteQueryObjectFromString, - ContainerRegistrationKeys, - } from "@medusajs/utils" - import MarketplaceModuleService - from "../../../../modules/marketplace/service" - export async function GET( - req: AuthenticatedMedusaRequest, - res: MedusaResponse - ): Promise { - const marketplaceModuleService: MarketplaceModuleService = - req.scope.resolve( - "marketplaceModuleService" - ) - const remoteQuery: RemoteQueryFunction = req.scope.resolve( - ContainerRegistrationKeys.REMOTE_QUERY +```ts title="src/api/admin/marketplace/orders/route.ts" highlights={orderRoutesHighlights} collapsibleLines="1-12" expandButtonLabel="Show Imports" +import { + AuthenticatedMedusaRequest, + MedusaResponse, +} from "@medusajs/medusa" +import { RemoteQueryFunction } from "@medusajs/modules-sdk" +import { + remoteQueryObjectFromString, + ContainerRegistrationKeys, +} from "@medusajs/utils" +import MarketplaceModuleService + from "../../../../modules/marketplace/service" + +export async function GET( + req: AuthenticatedMedusaRequest, + res: MedusaResponse +): Promise { + const marketplaceModuleService: MarketplaceModuleService = + req.scope.resolve( + "marketplaceModuleService" ) + const remoteQuery: RemoteQueryFunction = req.scope.resolve( + ContainerRegistrationKeys.REMOTE_QUERY + ) - const storeUsers = await marketplaceModuleService.listStoreUsers({ - user_id: req.auth_context.actor_id, - }) + const storeUsers = await marketplaceModuleService.listStoreUsers({ + user_id: req.auth_context.actor_id, + }) - const query = remoteQueryObjectFromString({ - entryPoint: "store_order", - fields: [ - "order.*", - ], - variables: { - filters: { - store_id: storeUsers[0].store_id, - }, + const query = remoteQueryObjectFromString({ + entryPoint: "store_order", + fields: [ + "order.*", + ], + variables: { + filters: { + store_id: storeUsers[0].store_id, }, - }) + }, + }) - const result = await remoteQuery(query) + const result = await remoteQuery(query) - res.json({ - orders: result.map((data) => data.order), - }) - } - ``` - - This creates a `GET` API route at `/admin/marketplace/orders`. In the API route, you: - - - Retrieve the store of the logged-in user. - - Build a query that retrieves the orders of that store. - - Retrieve the orders using remote query and return them. - - To test it out, start the Medusa application. Then, send a `GET` request to `/admin/marketplace/orders`: - - ```bash - curl 'localhost:9000/admin/marketplace/orders' \ - -H 'Authorization: Bearer {jwt_token}' - ``` - - This will return the orders you created in the previous section if the `{jwt_token}` belongs to the user of the same store ID. + res.json({ + orders: result.map((data) => data.order), + }) +} +```` + +This creates a `GET` API route at `/admin/marketplace/orders`. In the API route, you: + +- Retrieve the store of the logged-in user. +- Build a query that retrieves the orders of that store. +- Retrieve the orders using remote query and return them. + +To test it out, start the Medusa application. Then, send a `GET` request to `/admin/marketplace/orders`: + +```bash +curl 'localhost:9000/admin/marketplace/orders' \ +-H 'Authorization: Bearer {jwt_token}' +``` + +This will return the orders you created in the previous section if the `{jwt_token}` belongs to the user of the same store ID.
*/} @@ -805,19 +822,21 @@ Medusa provides a Next.js storefront to use with your application. You can eithe For example, you can create an API route that retrieves available stores and another API route that retrieves the products of each store using the remote query as done in previous sections. -, - showLinkIcon: false - }, - { - href: "!docs!/storefront-development/tips", - title: "Storefront Tips", - text: "Find tips on developing a custom storefront.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/storefront-development/tips", + title: "Storefront Tips", + text: "Find tips on developing a custom storefront.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> diff --git a/www/apps/resources/app/recipes/pos/page.mdx b/www/apps/resources/app/recipes/pos/page.mdx index 7c85f382bc..01df442e64 100644 --- a/www/apps/resources/app/recipes/pos/page.mdx +++ b/www/apps/resources/app/recipes/pos/page.mdx @@ -51,65 +51,57 @@ To search through product variants by their barcode, create a custom API Route a ![Example flow of integrating a barcode scanner](https://res.cloudinary.com/dza7lstvk/image/upload/v1709034282/Medusa%20Book/pos-scan-barcode_a8j8ew.jpg) -, - showLinkIcon: false - }, - { - href: "!docs!/basics/api-routes", - title: "Create API Route", - text: "Learn how to create an API Route.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!docs!/basics/api-routes", + title: "Create API Route", + text: "Learn how to create an API Route.", + startIcon: , + showLinkIcon: false, + }, + ]} +/>
- Here’s an example of creating a custom API Route at `/store/pos/search-barcode` that searches product variants by a barcode: +Here’s an example of creating a custom API Route at `/store/pos/search-barcode` that searches product variants by a barcode: - ```ts title="src/api/store/pos/search-barcode/route.ts" collapsibleLines="1-8" expandButtonLabel="Show Imports" - import type { - MedusaRequest, - MedusaResponse, - } from "@medusajs/medusa" - import { MedusaError } from "@medusajs/utils" - import { ModuleRegistrationName } from "@medusajs/modules-sdk" - import { IProductModuleService } from "@medusajs/types" +```ts title="src/api/store/pos/search-barcode/route.ts" collapsibleLines="1-8" expandButtonLabel="Show Imports" +import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa" +import { MedusaError } from "@medusajs/utils" +import { ModuleRegistrationName } from "@medusajs/utils" +import { IProductModuleService } from "@medusajs/types" - export const GET = async ( - req: MedusaRequest, - res: MedusaResponse - ) => { - const barcode = (req.query.barcode as string) || "" - if (!barcode) { - throw new MedusaError( - MedusaError.Types.INVALID_DATA, - "Barcode is required" - ) - } - // get product service - const productModuleService: IProductModuleService = - req.scope.resolve( - ModuleRegistrationName.PRODUCT - ) - - // retrieve product variants by barcode - const productVariants = await productModuleService - .listProductVariants({ - // @ts-ignore - barcode, - }) - - res.json({ - product_variants: productVariants, - }) +export const GET = async (req: MedusaRequest, res: MedusaResponse) => { + const barcode = (req.query.barcode as string) || "" + if (!barcode) { + throw new MedusaError(MedusaError.Types.INVALID_DATA, "Barcode is required") } - ``` + // get product service + const productModuleService: IProductModuleService = req.scope.resolve( + ModuleRegistrationName.PRODUCT + ) + + // retrieve product variants by barcode + const productVariants = await productModuleService.listProductVariants({ + // @ts-ignore + barcode, + }) + + res.json({ + product_variants: productVariants, + }) +} +```
@@ -127,29 +119,31 @@ Merchants can create a sales channel for their online store and a sales channel This also opens the door for other business opportunities, such as an endless aisle experience. Suppose a product isn't available in-store but is available in different warehouses. You can allow customers to purchase that item in-store and deliver it to their address. -, - showLinkIcon: false - }, - { - href: "/commerce-modules/stock-location", - title: "Stock Location Module", - text: "Learn about the Stock Location Module.", - startIcon: , - showLinkIcon: false - }, - { - href: "/commerce-modules/sales-channel", - title: "Sales Channel Module", - text: "Learn about the Sales Channel Module.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "/commerce-modules/stock-location", + title: "Stock Location Module", + text: "Learn about the Stock Location Module.", + startIcon: , + showLinkIcon: false, + }, + { + href: "/commerce-modules/sales-channel", + title: "Sales Channel Module", + text: "Learn about the Sales Channel Module.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -161,29 +155,31 @@ In addition, using Medusa's Promotion Module, store operators can create promoti You can also create custom modules to provide features for a better customer experience, such as a rewards system or loyalty points. -, - showLinkIcon: false - }, - { - href: "/commerce-modules/promotion", - title: "Promotion Module", - text: "Learn about the Promotion Module.", - startIcon: , - showLinkIcon: false - }, - { - href: "!docs!/basics/modules-and-services", - title: "Create a Module", - text: "Learn how to create a module.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "/commerce-modules/promotion", + title: "Promotion Module", + text: "Learn about the Promotion Module.", + startIcon: , + showLinkIcon: false, + }, + { + href: "!docs!/basics/modules-and-services", + title: "Create a Module", + text: "Learn how to create a module.", + startIcon: , + showLinkIcon: false, + }, + ]} +/> --- @@ -195,19 +191,21 @@ Once you accept the payment, place an order in the POS system using the [Draft O Then, merchants can view all orders coming from different sales channels using the Medusa Admin. This keeps logistics and order handling consistent between online and in-store customers. -, - showLinkIcon: false - }, - { - href: "!api!/admin", - title: "Admin REST APIs", - text: "Check out available Admin REST APIs.", - startIcon: , - showLinkIcon: false - }, -]} /> +, + showLinkIcon: false, + }, + { + href: "!api!/admin", + title: "Admin REST APIs", + text: "Check out available Admin REST APIs.", + startIcon: , + showLinkIcon: false, + }, + ]} +/>