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 74bee3060e..c18f3fdb8f 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,5 +1,5 @@ import { ModuleRegistrationName } from "@medusajs/modules-sdk" -import { CreateStoreDTO, IStoreModuleService } from "@medusajs/types" +import { CreateStoreDTO, IStoreModuleService, StoreDTO } from "@medusajs/types" import { StepResponse, createStep } from "@medusajs/workflows-sdk" import { createStoresWorkflow } from "../../store" @@ -16,8 +16,13 @@ export const createDefaultStoreStep = createStep( let shouldDelete = false let [store] = await storeService.list({}, { take: 1 }) + /** + * @todo + * Seems like we are missing an integration test when the + * following conditional as true. + */ if (!store) { - store = await createStoresWorkflow(container).run({ + const stores = await createStoresWorkflow(container).run({ input: { stores: [ { @@ -30,6 +35,12 @@ export const createDefaultStoreStep = createStep( }, }) + /** + * As per types, the result from "createStoresWorkflow.run" was + * an array of "StoreDTO". But at runtime it turns out to be + * a "StoreDTO" + */ + store = stores as unknown as StoreDTO shouldDelete = true } 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 ad4a19ffaa..a5d94854ab 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 @@ -83,6 +83,7 @@ export const updateCartPromotionsStep = createStep( : [] return new StepResponse(null, { + // @ts-expect-error createdLinkIds: createdLinks.map((link) => link.id), dismissedLinks: linksToDismiss, }) @@ -95,6 +96,7 @@ export const updateCartPromotionsStep = createStep( } if (revertData?.createdLinkIds?.length) { + // @ts-expect-error await remoteLink.delete(revertData.createdLinkIds) } } 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 497aee6ba6..c4f02f16f0 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 @@ -42,6 +42,20 @@ export const adjustInventoryLevelsStep = createStep( const inventoryService = container.resolve(ModuleRegistrationName.INVENTORY) - await inventoryService.adjustInventory(adjustedLevels) + /** + * @todo + * The method "adjustInventory" was broken, it was receiving the + * "inventoryItemId" and "locationId" as snake case, whereas + * the expected object needed these properties as camelCase + */ + await inventoryService.adjustInventory( + adjustedLevels.map((level) => { + return { + inventoryItemId: level.inventory_item_id, + locationId: level.location_id, + adjustment: level.adjustment, + } + }) + ) } ) diff --git a/packages/core/core-flows/src/inventory/steps/attach-inventory-items.ts b/packages/core/core-flows/src/inventory/steps/attach-inventory-items.ts index e3ffddc37b..f0b9dd2875 100644 --- a/packages/core/core-flows/src/inventory/steps/attach-inventory-items.ts +++ b/packages/core/core-flows/src/inventory/steps/attach-inventory-items.ts @@ -20,7 +20,7 @@ export const attachInventoryItemToVariants = createStep( .filter(({ tag }) => !!tag) .map(({ inventoryItemId, tag }) => ({ productService: { - variant_id: tag, + variant_id: tag!, }, inventoryService: { inventory_item_id: inventoryItemId, diff --git a/packages/core/core-flows/src/inventory/steps/validate-singular-inventory-items-for-tags.ts b/packages/core/core-flows/src/inventory/steps/validate-singular-inventory-items-for-tags.ts index bc1cbcf6c1..33224239a7 100644 --- a/packages/core/core-flows/src/inventory/steps/validate-singular-inventory-items-for-tags.ts +++ b/packages/core/core-flows/src/inventory/steps/validate-singular-inventory-items-for-tags.ts @@ -1,11 +1,5 @@ -import { - ContainerRegistrationKeys, - MedusaError, - remoteQueryObjectFromString, -} from "@medusajs/utils" +import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils" import { StepResponse, createStep } from "@medusajs/workflows-sdk" - -import { InventoryNext } from "@medusajs/types" import { Modules } from "@medusajs/modules-sdk" export const validateInventoryItemsForCreateStepId = @@ -25,7 +19,7 @@ export const validateInventoryItemsForCreate = createStep( "variant_id", Modules.INVENTORY, "inventory_item_id" - ) + )! const existingItems = await linkService.list( { variant_id: input.map((i) => i.tag) }, @@ -33,10 +27,12 @@ export const validateInventoryItemsForCreate = createStep( ) if (existingItems.length) { + // @ts-expect-error + const ids = existingItems.map((i) => i.variant_id).join(", ") + throw new MedusaError( MedusaError.Types.NOT_ALLOWED, - "Inventory items already exist for variants with ids: " + - existingItems.map((i) => i.variant_id).join(", ") + `Inventory items already exist for variants with ids: ${ids}` ) } diff --git a/packages/core/core-flows/src/product/steps/get-variant-pricing-link.ts b/packages/core/core-flows/src/product/steps/get-variant-pricing-link.ts index 0baa76b66b..6ed9073b2c 100644 --- a/packages/core/core-flows/src/product/steps/get-variant-pricing-link.ts +++ b/packages/core/core-flows/src/product/steps/get-variant-pricing-link.ts @@ -26,12 +26,15 @@ export const getVariantPricingLinkStep = createStep( "variant_id", Modules.PRICING, "price_set_id" - ) + )! - const existingItems = await linkService.list( + const existingItems = (await linkService.list( { variant_id: data.ids }, { select: ["variant_id", "price_set_id"] } - ) + )) as { + variant_id: string + price_set_id: string + }[] if (existingItems.length !== data.ids.length) { const missing = arrayDifference( diff --git a/packages/core/core-flows/src/product/workflows/update-product-variants.ts b/packages/core/core-flows/src/product/workflows/update-product-variants.ts index ae32de9389..173f142b3b 100644 --- a/packages/core/core-flows/src/product/workflows/update-product-variants.ts +++ b/packages/core/core-flows/src/product/workflows/update-product-variants.ts @@ -78,16 +78,22 @@ export const updateProductVariantsWorkflow = createWorkflow( } if ("product_variants" in data.input) { - return data.variantPriceSetLinks.map((link) => { - const variant = (data.input as any).product_variants.find( - (v) => v.id === link.variant_id - ) + return data.variantPriceSetLinks + .map((link) => { + if (!("product_variants" in data.input)) { + return + } - return { - id: link.price_set_id, - prices: variant.prices, - } as PricingTypes.UpsertPriceSetDTO - }) + const variant = data.input.product_variants.find( + (v) => v.id === link.variant_id + )! + + return { + id: link.price_set_id, + prices: variant.prices, + } as PricingTypes.UpsertPriceSetDTO + }) + .filter(Boolean) } return { diff --git a/packages/core/core-flows/src/sales-channel/steps/associate-products-with-channels.ts b/packages/core/core-flows/src/sales-channel/steps/associate-products-with-channels.ts index 25dafc1697..8e400a9a9e 100644 --- a/packages/core/core-flows/src/sales-channel/steps/associate-products-with-channels.ts +++ b/packages/core/core-flows/src/sales-channel/steps/associate-products-with-channels.ts @@ -1,4 +1,4 @@ -import { Modules } from "@medusajs/modules-sdk" +import { Modules, RemoteLink } from "@medusajs/modules-sdk" import { ContainerRegistrationKeys } from "@medusajs/utils" import { createStep, StepResponse } from "@medusajs/workflows-sdk" 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 b510bbe6a7..ca4f247e95 100644 --- a/packages/core/core-flows/src/user/steps/create-users.ts +++ b/packages/core/core-flows/src/user/steps/create-users.ts @@ -17,6 +17,6 @@ export const createUsersStep = createStep( return } const service = container.resolve(ModuleRegistrationName.USER) - await service.delete(createdUsers) + await service.delete(createdUsers.map((user) => user.id)) } ) diff --git a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts index 6459ee9858..2e4fc89c30 100644 --- a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts +++ b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts @@ -1,5 +1,6 @@ import { Constructor, + IModuleService, InternalModuleDeclaration, Logger, MedusaContainer, @@ -158,9 +159,9 @@ export async function loadInternalModule( if (loaderOnly) { // The expectation is only to run the loader as standalone, so we do not need to register the service and we need to cleanup all services - const service = container.resolve(registrationName) - await service.__hooks?.onApplicationPrepareShutdown() - await service.__hooks?.onApplicationShutdown() + const service = container.resolve(registrationName) + await service.__hooks?.onApplicationPrepareShutdown?.() + await service.__hooks?.onApplicationShutdown?.() } } diff --git a/packages/core/modules-sdk/src/medusa-app.ts b/packages/core/modules-sdk/src/medusa-app.ts index 5f13862083..4ea6285633 100644 --- a/packages/core/modules-sdk/src/medusa-app.ts +++ b/packages/core/modules-sdk/src/medusa-app.ts @@ -1,10 +1,13 @@ +import type { Knex } from "knex" import { mergeTypeDefs } from "@graphql-tools/merge" import { makeExecutableSchema } from "@graphql-tools/schema" import { RemoteFetchDataCallback } from "@medusajs/orchestration" -import { +import type { + ConfigModule, ExternalModuleDeclaration, InternalModuleDeclaration, LoadedModule, + Logger, MedusaContainer, ModuleDefinition, ModuleExports, @@ -36,6 +39,16 @@ import { cleanGraphQLSchema } from "./utils" const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK] +declare module "@medusajs/types" { + export interface ModuleImplementations { + [ContainerRegistrationKeys.REMOTE_LINK]: RemoteLink + [ContainerRegistrationKeys.CONFIG_MODULE]: ConfigModule + [ContainerRegistrationKeys.PG_CONNECTION]: Knex + [ContainerRegistrationKeys.REMOTE_QUERY]: RemoteQueryFunction + [ContainerRegistrationKeys.LOGGER]: Logger + } +} + export type RunMigrationFn = ( options?: ModuleServiceInitializeOptions, injectedDependencies?: Record diff --git a/packages/core/types/src/bundles.ts b/packages/core/types/src/bundles.ts index 7c51433a04..9dc4e933e4 100644 --- a/packages/core/types/src/bundles.ts +++ b/packages/core/types/src/bundles.ts @@ -29,3 +29,4 @@ export * as TaxTypes from "./tax" export * as TransactionBaseTypes from "./transaction-base" export * as UserTypes from "./user" export * as WorkflowTypes from "./workflow" +export * as WorkflowsSdkTypes from "./workflows-sdk" diff --git a/packages/core/types/src/common/medusa-container.ts b/packages/core/types/src/common/medusa-container.ts index 4acf0d1594..f2b9fc7c27 100644 --- a/packages/core/types/src/common/medusa-container.ts +++ b/packages/core/types/src/common/medusa-container.ts @@ -1,19 +1,32 @@ -import { AwilixContainer } from "awilix" +import { AwilixContainer, ResolveOptions } from "awilix" /** - * The Medusa Container extends [Awilix](https://github.com/jeffijoe/awilix) to + * The following interface acts as a bucket that other modules or the + * utils package can fill using declaration merging + */ +export interface ModuleImplementations {} + +/** + * The Medusa Container extends [Awilix](https://github.com/jeffijoe/awilix) to * provide dependency injection functionalities. */ -export type MedusaContainer = AwilixContainer & { - /** - * @ignore - */ - registerAdd: (name: string, registration: T) => MedusaContainer - /** - * @ignore - */ - createScope: () => MedusaContainer -} +export type MedusaContainer = + Omit & { + resolve( + key: K, + resolveOptions?: ResolveOptions + ): Cradle[K] + resolve(key: string, resolveOptions?: ResolveOptions): T + + /** + * @ignore + */ + registerAdd: (name: string, registration: T) => MedusaContainer + /** + * @ignore + */ + createScope: () => MedusaContainer + } export type ContainerLike = { resolve(key: string): T diff --git a/packages/core/types/src/index.ts b/packages/core/types/src/index.ts index 2362c6f10a..2295a4a1be 100644 --- a/packages/core/types/src/index.ts +++ b/packages/core/types/src/index.ts @@ -40,3 +40,4 @@ export * from "./transaction-base" export * from "./user" export * from "./workflow" export * from "./workflows" +export * from "./workflows-sdk" diff --git a/packages/core/types/src/stock-location/service-next.ts b/packages/core/types/src/stock-location/service-next.ts index f1dcf68309..b5c78093b5 100644 --- a/packages/core/types/src/stock-location/service-next.ts +++ b/packages/core/types/src/stock-location/service-next.ts @@ -282,7 +282,7 @@ export interface IStockLocationServiceNext extends IModuleService { * @example * await stockLocationModuleService.delete("sloc_123") */ - delete(id: string, context?: Context): Promise + delete(id: string | string[], context?: Context): Promise /** * This method soft deletes stock locations by their IDs. diff --git a/packages/core/types/src/user/service.ts b/packages/core/types/src/user/service.ts index 242068d24c..1a92c1aa16 100644 --- a/packages/core/types/src/user/service.ts +++ b/packages/core/types/src/user/service.ts @@ -16,7 +16,7 @@ import { IModuleService } from "../modules-sdk" export interface IUserModuleService extends IModuleService { /** * This method validates that a token belongs to an invite and returns that invite. - * + * * An error is thrown if the invite has expired or no invite matches the token. * * @param {string} token - The token to validate diff --git a/packages/core/workflows-sdk/src/types/common.ts b/packages/core/types/src/workflows-sdk/common.ts similarity index 89% rename from packages/core/workflows-sdk/src/types/common.ts rename to packages/core/types/src/workflows-sdk/common.ts index c8859970a3..025f7e25a7 100644 --- a/packages/core/workflows-sdk/src/types/common.ts +++ b/packages/core/types/src/workflows-sdk/common.ts @@ -1,4 +1,4 @@ -import { BaseFilterable, OperatorMap } from "@medusajs/types" +import { BaseFilterable, OperatorMap } from "../dal" export interface WorkflowExecutionDTO { id: string diff --git a/packages/core/workflows-sdk/src/types/index.ts b/packages/core/types/src/workflows-sdk/index.ts similarity index 100% rename from packages/core/workflows-sdk/src/types/index.ts rename to packages/core/types/src/workflows-sdk/index.ts diff --git a/packages/core/workflows-sdk/src/types/mutations.ts b/packages/core/types/src/workflows-sdk/mutations.ts similarity index 100% rename from packages/core/workflows-sdk/src/types/mutations.ts rename to packages/core/types/src/workflows-sdk/mutations.ts diff --git a/packages/core/workflows-sdk/src/types/service.ts b/packages/core/types/src/workflows-sdk/service.ts similarity index 87% rename from packages/core/workflows-sdk/src/types/service.ts rename to packages/core/types/src/workflows-sdk/service.ts index a2cfa9aa48..8c71d1afd7 100644 --- a/packages/core/workflows-sdk/src/types/service.ts +++ b/packages/core/types/src/workflows-sdk/service.ts @@ -1,10 +1,6 @@ -import { - ContainerLike, - Context, - FindConfig, - IModuleService, -} from "@medusajs/types" -import { ReturnWorkflow, UnwrapWorkflowInputDataType } from "../utils/composer" +import { ContainerLike, FindConfig } from "../common" +import { IModuleService } from "../modules-sdk" +import { Context } from "../shared-context" import { FilterableWorkflowExecutionProps, WorkflowExecutionDTO, @@ -55,14 +51,7 @@ export interface IWorkflowEngineService extends IModuleService { sharedContext?: Context ): Promise<[WorkflowExecutionDTO[], number]> - run< - TWorkflow extends ReturnWorkflow = ReturnWorkflow< - any, - any, - any - >, - TData = UnwrapWorkflowInputDataType - >( + run( workflowId: string, options?: WorkflowOrchestratorRunDTO, sharedContext?: Context diff --git a/packages/core/utils/src/common/container.ts b/packages/core/utils/src/common/container.ts index 63b32c6dc3..78406c1b80 100644 --- a/packages/core/utils/src/common/container.ts +++ b/packages/core/utils/src/common/container.ts @@ -6,4 +6,4 @@ export const ContainerRegistrationKeys = { REMOTE_QUERY: "remoteQuery", REMOTE_LINK: "remoteLink", FEATURE_FLAG_ROUTER: "featureFlagRouter", -} +} as const diff --git a/packages/core/utils/src/modules-sdk/definition.ts b/packages/core/utils/src/modules-sdk/definition.ts index c166cee5ca..a750b0f273 100644 --- a/packages/core/utils/src/modules-sdk/definition.ts +++ b/packages/core/utils/src/modules-sdk/definition.ts @@ -1,3 +1,29 @@ +import type { + IApiKeyModuleService, + IAuthModuleService, + ICacheService, + ICartModuleService, + ICurrencyModuleService, + ICustomerModuleService, + IEventBusModuleService, + IFileModuleService, + IFulfillmentModuleService, + IInventoryServiceNext, + INotificationModuleService, + IOrderModuleService, + IPaymentModuleService, + IPricingModuleService, + IProductModuleService, + IPromotionModuleService, + IRegionModuleService, + ISalesChannelModuleService, + IStockLocationServiceNext, + IStoreModuleService, + ITaxModuleService, + IUserModuleService, + IWorkflowEngineService, +} from "@medusajs/types" + export enum Modules { AUTH = "auth", CACHE = "cacheService", @@ -24,3 +50,57 @@ export enum Modules { FILE = "file", NOTIFICATION = "notification", } + +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", +} + +declare module "@medusajs/types" { + export interface ModuleImplementations { + [ModuleRegistrationName.AUTH]: IAuthModuleService + [ModuleRegistrationName.CACHE]: ICacheService + [ModuleRegistrationName.CART]: ICartModuleService + [ModuleRegistrationName.CUSTOMER]: ICustomerModuleService + [ModuleRegistrationName.EVENT_BUS]: IEventBusModuleService + [ModuleRegistrationName.INVENTORY]: IInventoryServiceNext + [ModuleRegistrationName.PAYMENT]: IPaymentModuleService + [ModuleRegistrationName.PRICING]: IPricingModuleService + [ModuleRegistrationName.PRODUCT]: IProductModuleService + [ModuleRegistrationName.PROMOTION]: IPromotionModuleService + [ModuleRegistrationName.SALES_CHANNEL]: ISalesChannelModuleService + [ModuleRegistrationName.TAX]: ITaxModuleService + [ModuleRegistrationName.FULFILLMENT]: IFulfillmentModuleService + [ModuleRegistrationName.STOCK_LOCATION]: IStockLocationServiceNext + [ModuleRegistrationName.USER]: IUserModuleService + [ModuleRegistrationName.WORKFLOW_ENGINE]: IWorkflowEngineService + [ModuleRegistrationName.REGION]: IRegionModuleService + [ModuleRegistrationName.ORDER]: IOrderModuleService + [ModuleRegistrationName.API_KEY]: IApiKeyModuleService + [ModuleRegistrationName.STORE]: IStoreModuleService + [ModuleRegistrationName.CURRENCY]: ICurrencyModuleService + [ModuleRegistrationName.FILE]: IFileModuleService + [ModuleRegistrationName.NOTIFICATION]: INotificationModuleService + } +} diff --git a/packages/core/workflows-sdk/src/index.ts b/packages/core/workflows-sdk/src/index.ts index f9fd0e20c7..9c27d4e26a 100644 --- a/packages/core/workflows-sdk/src/index.ts +++ b/packages/core/workflows-sdk/src/index.ts @@ -1,6 +1,4 @@ export * from "./helper" export * from "./medusa-workflow" -export * as WorkflowOrchestratorTypes from "./types" -export { IWorkflowEngineService } from "./types/service" export * from "./utils/composer" export * as Composer from "./utils/composer" diff --git a/packages/medusa/src/api/admin/products/helpers.ts b/packages/medusa/src/api/admin/products/helpers.ts index 2a46125dc0..634bba7450 100644 --- a/packages/medusa/src/api/admin/products/helpers.ts +++ b/packages/medusa/src/api/admin/products/helpers.ts @@ -107,6 +107,7 @@ export const refetchBatchProducts = async ( fields: remapKeysForProduct(fields ?? []), }) + // @ts-expect-error "Remote query can return null" created = remoteQuery(createdQuery) } @@ -119,6 +120,7 @@ export const refetchBatchProducts = async ( fields: remapKeysForProduct(fields ?? []), }) + // @ts-expect-error "Remote query can return null" updated = remoteQuery(updatedQuery) } @@ -148,6 +150,7 @@ export const refetchBatchVariants = async ( fields: remapKeysForVariant(fields ?? []), }) + // @ts-expect-error "Remote query can return null" created = remoteQuery(createdQuery) } @@ -160,6 +163,7 @@ export const refetchBatchVariants = async ( fields: remapKeysForVariant(fields ?? []), }) + // @ts-expect-error "Remote query can return null" updated = remoteQuery(updatedQuery) } diff --git a/packages/medusa/src/api/admin/promotions/helpers.ts b/packages/medusa/src/api/admin/promotions/helpers.ts index 630bcd85ec..b36b621197 100644 --- a/packages/medusa/src/api/admin/promotions/helpers.ts +++ b/packages/medusa/src/api/admin/promotions/helpers.ts @@ -42,6 +42,7 @@ export const refetchBatchRules = async ( fields: fields, }) + // @ts-expect-error "Remote query can return null" created = remoteQuery(createdQuery) } @@ -54,6 +55,7 @@ export const refetchBatchRules = async ( fields: fields, }) + // @ts-expect-error "Remote query can return null" updated = remoteQuery(updatedQuery) } diff --git a/packages/medusa/src/api/admin/shipping-options/helpers.ts b/packages/medusa/src/api/admin/shipping-options/helpers.ts index 0eabb3075d..af9286cbb5 100644 --- a/packages/medusa/src/api/admin/shipping-options/helpers.ts +++ b/packages/medusa/src/api/admin/shipping-options/helpers.ts @@ -45,6 +45,7 @@ export const refetchBatchRules = async ( fields: fields, }) + // @ts-expect-error "Remote query can return null" created = remoteQuery(createdQuery) } @@ -57,6 +58,7 @@ export const refetchBatchRules = async ( fields: fields, }) + // @ts-expect-error "Remote query can return null" updated = remoteQuery(updatedQuery) } 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 d960adfe55..5df786464d 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 @@ -1,9 +1,9 @@ +import { IWorkflowEngineService } from "@medusajs/types" import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../../../types/routing" -import { IWorkflowEngineService } from "@medusajs/workflows-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk" export const GET = async ( 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 9124b073f3..8c940f682a 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 @@ -4,9 +4,8 @@ import { } from "../../../../../types/routing" import { IWorkflowEngineService, - WorkflowOrchestratorTypes, -} from "@medusajs/workflows-sdk" - + WorkflowOrchestratorRunDTO, +} from "@medusajs/types" import { ModuleRegistrationName } from "@medusajs/modules-sdk" import { AdminCreateWorkflowsRunType } from "../../validators" @@ -28,7 +27,7 @@ export const POST = async ( context: { requestId: req.requestId, }, - } as WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO + } as WorkflowOrchestratorRunDTO const { acknowledgement } = await workflowEngineService.run( workflow_id, 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 e69274b1d8..78879ebf09 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 @@ -2,11 +2,12 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../../types/routing" -import { IWorkflowEngineService, StepResponse } from "@medusajs/workflows-sdk" +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" 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 2820f39c89..d6fc452a00 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 @@ -2,11 +2,12 @@ import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../../types/routing" -import { IWorkflowEngineService, StepResponse } from "@medusajs/workflows-sdk" +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" 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 588e5283e6..ff9af78ac1 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 @@ -1,9 +1,9 @@ +import { IWorkflowEngineService } from "@medusajs/types" import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../types/routing" -import { IWorkflowEngineService } from "@medusajs/workflows-sdk" import { ModuleRegistrationName } from "@medusajs/modules-sdk" export const GET = async ( 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 b1dce24baa..839a1aa3fc 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 @@ -62,7 +62,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => { }, }, { + // @ts-expect-error secret: jwtSecret, + // @ts-expect-error expiresIn: jwtExpiresIn, } ) 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 b651a522ba..d02986ab34 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 @@ -69,7 +69,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => { }, }, { + // @ts-expect-error secret: jwtSecret, + // @ts-expect-error expiresIn: jwtExpiresIn, } ) diff --git a/packages/medusa/src/api/hooks/payment/[provider]/route.ts b/packages/medusa/src/api/hooks/payment/[provider]/route.ts index a02d3f010e..a5a60d2914 100644 --- a/packages/medusa/src/api/hooks/payment/[provider]/route.ts +++ b/packages/medusa/src/api/hooks/payment/[provider]/route.ts @@ -9,6 +9,7 @@ export const POST = async (req: MedusaRequest, res: MedusaResponse) => { const { provider } = req.params const options: PaymentModuleOptions = + // @ts-expect-error "Not sure if .options exists on a module" req.scope.resolve(ModuleRegistrationName.PAYMENT).options || {} const event = { diff --git a/packages/medusa/src/loaders/index.ts b/packages/medusa/src/loaders/index.ts index d2ac3c4a1a..571662b746 100644 --- a/packages/medusa/src/loaders/index.ts +++ b/packages/medusa/src/loaders/index.ts @@ -160,6 +160,7 @@ export default async ({ await promiseAll([ container.dispose(), + // @ts-expect-error "Do we want to call `client.destroy` " pgConnection?.context?.destroy(), entrypointsShutdown(), ]) diff --git a/packages/modules/currency/src/loaders/initial-data.ts b/packages/modules/currency/src/loaders/initial-data.ts index 8fd751eee8..c4298af3f1 100644 --- a/packages/modules/currency/src/loaders/initial-data.ts +++ b/packages/modules/currency/src/loaders/initial-data.ts @@ -13,10 +13,9 @@ export default async ({ // TODO: Add default logger to the container when running tests const logger = container.resolve(ContainerRegistrationKeys.LOGGER) ?? console - const { - currencyService_, - }: { currencyService_: ModulesSdkTypes.InternalModuleService } = - container.resolve(ModuleRegistrationName.CURRENCY) + const { currencyService_ } = container.resolve<{ + currencyService_: ModulesSdkTypes.InternalModuleService + }>(ModuleRegistrationName.CURRENCY) try { const normalizedCurrencies = Object.values(defaultCurrencies).map((c) => ({ diff --git a/packages/modules/payment/src/loaders/defaults.ts b/packages/modules/payment/src/loaders/defaults.ts index b9855f5776..e5baf21e55 100644 --- a/packages/modules/payment/src/loaders/defaults.ts +++ b/packages/modules/payment/src/loaders/defaults.ts @@ -1,11 +1,11 @@ -import { - CreatePaymentProviderDTO, - LoaderOptions -} from "@medusajs/types" +import { CreatePaymentProviderDTO, LoaderOptions } from "@medusajs/types" +import { PaymentProviderService } from "@services" export default async ({ container }: LoaderOptions): Promise => { - const providersToLoad = container.resolve("payment_providers") - const paymentProviderService = container.resolve("paymentProviderService") + const providersToLoad = container.resolve("payment_providers") + const paymentProviderService = container.resolve( + "paymentProviderService" + ) const providers = await paymentProviderService.list({ id: providersToLoad, diff --git a/packages/modules/payment/src/services/payment-provider.ts b/packages/modules/payment/src/services/payment-provider.ts index 4b90cea65e..1abdfd8629 100644 --- a/packages/modules/payment/src/services/payment-provider.ts +++ b/packages/modules/payment/src/services/payment-provider.ts @@ -57,8 +57,8 @@ export default class PaymentProviderService { @InjectManager("paymentProviderRepository_") async list( - filters: FilterablePaymentProviderProps, - config: FindConfig, + filters?: FilterablePaymentProviderProps, + config?: FindConfig, @MedusaContext() sharedContext?: Context ): Promise { const queryOptions = ModulesSdkUtils.buildQuery( diff --git a/packages/modules/stock-location-next/src/services/stock-location-module.ts b/packages/modules/stock-location-next/src/services/stock-location-module.ts index 0dd07ee875..92de07a8a2 100644 --- a/packages/modules/stock-location-next/src/services/stock-location-module.ts +++ b/packages/modules/stock-location-next/src/services/stock-location-module.ts @@ -6,7 +6,6 @@ import { ModuleJoinerConfig, StockLocationAddressInput, StockLocationTypes, - UpdateStockLocationInput, ModulesSdkTypes, DAL, IStockLocationServiceNext, diff --git a/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts b/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts index 0a1bb3ee96..29cb6a15c6 100644 --- a/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts +++ b/packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts @@ -2,9 +2,11 @@ import { Context, DAL, FindConfig, + IWorkflowEngineService, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, + WorkflowsSdkTypes, } from "@medusajs/types" import { InjectManager, @@ -14,10 +16,8 @@ import { MedusaError, } from "@medusajs/utils" import type { - IWorkflowEngineService, ReturnWorkflow, UnwrapWorkflowInputDataType, - WorkflowOrchestratorTypes, } from "@medusajs/workflows-sdk" import { WorkflowOrchestratorService } from "@services" import { joinerConfig } from "../joiner-config" @@ -58,9 +58,9 @@ export class WorkflowsModuleService implements IWorkflowEngineService { workflow_id: string transaction_id: string }, - config: FindConfig = {}, + config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { const objValue = isString(idOrObject) ? { id: idOrObject } : { @@ -84,7 +84,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { } // eslint-disable-next-line max-len - return await this.baseRepository_.serialize( + return await this.baseRepository_.serialize( wfExecution[0], { populate: true, @@ -94,10 +94,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService { @InjectManager("baseRepository_") async listWorkflowExecution( - filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {}, - config: FindConfig = {}, + filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {}, + config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { if (filters.transaction_id) { if (Array.isArray(filters.transaction_id)) { filters.transaction_id = { @@ -121,7 +121,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { ) return await this.baseRepository_.serialize< - WorkflowOrchestratorTypes.WorkflowExecutionDTO[] + WorkflowsSdkTypes.WorkflowExecutionDTO[] >(wfExecutions, { populate: true, }) @@ -129,10 +129,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService { @InjectManager("baseRepository_") async listAndCountWorkflowExecution( - filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {}, - config: FindConfig = {}, + filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {}, + config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise<[WorkflowOrchestratorTypes.WorkflowExecutionDTO[], number]> { + ): Promise<[WorkflowsSdkTypes.WorkflowExecutionDTO[], number]> { if (filters.transaction_id) { if (Array.isArray(filters.transaction_id)) { filters.transaction_id = { @@ -158,7 +158,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { return [ await this.baseRepository_.serialize< - WorkflowOrchestratorTypes.WorkflowExecutionDTO[] + WorkflowsSdkTypes.WorkflowExecutionDTO[] >(wfExecutions, { populate: true, }), @@ -169,7 +169,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { @InjectSharedContext() async run>( workflowIdOrWorkflow: TWorkflow, - options: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO< + options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO< TWorkflow extends ReturnWorkflow ? UnwrapWorkflowInputDataType : unknown diff --git a/packages/modules/workflow-engine-redis/src/services/workflows-module.ts b/packages/modules/workflow-engine-redis/src/services/workflows-module.ts index 6dfe4f0614..092c8563ed 100644 --- a/packages/modules/workflow-engine-redis/src/services/workflows-module.ts +++ b/packages/modules/workflow-engine-redis/src/services/workflows-module.ts @@ -2,9 +2,11 @@ import { Context, DAL, FindConfig, + IWorkflowEngineService, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, + WorkflowsSdkTypes, } from "@medusajs/types" import { InjectManager, @@ -14,10 +16,8 @@ import { isString, } from "@medusajs/utils" import type { - IWorkflowEngineService, ReturnWorkflow, UnwrapWorkflowInputDataType, - WorkflowOrchestratorTypes, } from "@medusajs/workflows-sdk" import { WorkflowOrchestratorService } from "@services" import { joinerConfig } from "../joiner-config" @@ -72,9 +72,9 @@ export class WorkflowsModuleService implements IWorkflowEngineService { workflow_id: string transaction_id: string }, - config: FindConfig = {}, + config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { const objValue = isString(idOrObject) ? { id: idOrObject } : { @@ -98,7 +98,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { } // eslint-disable-next-line max-len - return await this.baseRepository_.serialize( + return await this.baseRepository_.serialize( wfExecution[0], { populate: true, @@ -108,10 +108,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService { @InjectManager("baseRepository_") async listWorkflowExecution( - filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {}, - config: FindConfig = {}, + filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {}, + config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise { + ): Promise { if (filters.transaction_id) { if (Array.isArray(filters.transaction_id)) { filters.transaction_id = { @@ -135,7 +135,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { ) return await this.baseRepository_.serialize< - WorkflowOrchestratorTypes.WorkflowExecutionDTO[] + WorkflowsSdkTypes.WorkflowExecutionDTO[] >(wfExecutions, { populate: true, }) @@ -143,10 +143,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService { @InjectManager("baseRepository_") async listAndCountWorkflowExecution( - filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {}, - config: FindConfig = {}, + filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {}, + config: FindConfig = {}, @MedusaContext() sharedContext: Context = {} - ): Promise<[WorkflowOrchestratorTypes.WorkflowExecutionDTO[], number]> { + ): Promise<[WorkflowsSdkTypes.WorkflowExecutionDTO[], number]> { if (filters.transaction_id) { if (Array.isArray(filters.transaction_id)) { filters.transaction_id = { @@ -172,7 +172,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { return [ await this.baseRepository_.serialize< - WorkflowOrchestratorTypes.WorkflowExecutionDTO[] + WorkflowsSdkTypes.WorkflowExecutionDTO[] >(wfExecutions, { populate: true, }), @@ -183,7 +183,7 @@ export class WorkflowsModuleService implements IWorkflowEngineService { @InjectSharedContext() async run>( workflowIdOrWorkflow: TWorkflow, - options: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO< + options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO< TWorkflow extends ReturnWorkflow ? UnwrapWorkflowInputDataType : unknown