feat: loosely typed container
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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}`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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<IModuleService>(registrationName)
|
||||
await service.__hooks?.onApplicationPrepareShutdown?.()
|
||||
await service.__hooks?.onApplicationShutdown?.()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<any>
|
||||
[ContainerRegistrationKeys.REMOTE_QUERY]: RemoteQueryFunction
|
||||
[ContainerRegistrationKeys.LOGGER]: Logger
|
||||
}
|
||||
}
|
||||
|
||||
export type RunMigrationFn = (
|
||||
options?: ModuleServiceInitializeOptions,
|
||||
injectedDependencies?: Record<any, any>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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: <T>(name: string, registration: T) => MedusaContainer
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
createScope: () => MedusaContainer
|
||||
}
|
||||
export type MedusaContainer<Cradle extends object = ModuleImplementations> =
|
||||
Omit<AwilixContainer, "resolve"> & {
|
||||
resolve<K extends keyof Cradle>(
|
||||
key: K,
|
||||
resolveOptions?: ResolveOptions
|
||||
): Cradle[K]
|
||||
resolve<T>(key: string, resolveOptions?: ResolveOptions): T
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
registerAdd: <T>(name: string, registration: T) => MedusaContainer
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
createScope: () => MedusaContainer
|
||||
}
|
||||
|
||||
export type ContainerLike = {
|
||||
resolve<T = unknown>(key: string): T
|
||||
|
||||
@@ -40,3 +40,4 @@ export * from "./transaction-base"
|
||||
export * from "./user"
|
||||
export * from "./workflow"
|
||||
export * from "./workflows"
|
||||
export * from "./workflows-sdk"
|
||||
|
||||
@@ -282,7 +282,7 @@ export interface IStockLocationServiceNext extends IModuleService {
|
||||
* @example
|
||||
* await stockLocationModuleService.delete("sloc_123")
|
||||
*/
|
||||
delete(id: string, context?: Context): Promise<void>
|
||||
delete(id: string | string[], context?: Context): Promise<void>
|
||||
|
||||
/**
|
||||
* This method soft deletes stock locations by their IDs.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseFilterable, OperatorMap } from "@medusajs/types"
|
||||
import { BaseFilterable, OperatorMap } from "../dal"
|
||||
|
||||
export interface WorkflowExecutionDTO {
|
||||
id: string
|
||||
@@ -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<any, any, any> = ReturnWorkflow<
|
||||
any,
|
||||
any,
|
||||
any
|
||||
>,
|
||||
TData = UnwrapWorkflowInputDataType<TWorkflow>
|
||||
>(
|
||||
run(
|
||||
workflowId: string,
|
||||
options?: WorkflowOrchestratorRunDTO,
|
||||
sharedContext?: Context
|
||||
@@ -6,4 +6,4 @@ export const ContainerRegistrationKeys = {
|
||||
REMOTE_QUERY: "remoteQuery",
|
||||
REMOTE_LINK: "remoteLink",
|
||||
FEATURE_FLAG_ROUTER: "featureFlagRouter",
|
||||
}
|
||||
} as const
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<AdminCreateWorkflowsAsyncResponseType>,
|
||||
|
||||
@@ -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<AdminCreateWorkflowsAsyncResponseType>,
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -62,7 +62,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
// @ts-expect-error
|
||||
secret: jwtSecret,
|
||||
// @ts-expect-error
|
||||
expiresIn: jwtExpiresIn,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -69,7 +69,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
},
|
||||
},
|
||||
{
|
||||
// @ts-expect-error
|
||||
secret: jwtSecret,
|
||||
// @ts-expect-error
|
||||
expiresIn: jwtExpiresIn,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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(),
|
||||
])
|
||||
|
||||
@@ -13,10 +13,9 @@ export default async ({
|
||||
// TODO: Add default logger to the container when running tests
|
||||
const logger =
|
||||
container.resolve<Logger>(ContainerRegistrationKeys.LOGGER) ?? console
|
||||
const {
|
||||
currencyService_,
|
||||
}: { currencyService_: ModulesSdkTypes.InternalModuleService<Currency> } =
|
||||
container.resolve(ModuleRegistrationName.CURRENCY)
|
||||
const { currencyService_ } = container.resolve<{
|
||||
currencyService_: ModulesSdkTypes.InternalModuleService<Currency>
|
||||
}>(ModuleRegistrationName.CURRENCY)
|
||||
|
||||
try {
|
||||
const normalizedCurrencies = Object.values(defaultCurrencies).map((c) => ({
|
||||
|
||||
@@ -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<void> => {
|
||||
const providersToLoad = container.resolve("payment_providers")
|
||||
const paymentProviderService = container.resolve("paymentProviderService")
|
||||
const providersToLoad = container.resolve<string[]>("payment_providers")
|
||||
const paymentProviderService = container.resolve<PaymentProviderService>(
|
||||
"paymentProviderService"
|
||||
)
|
||||
|
||||
const providers = await paymentProviderService.list({
|
||||
id: providersToLoad,
|
||||
|
||||
@@ -57,8 +57,8 @@ export default class PaymentProviderService {
|
||||
|
||||
@InjectManager("paymentProviderRepository_")
|
||||
async list(
|
||||
filters: FilterablePaymentProviderProps,
|
||||
config: FindConfig<PaymentProviderDTO>,
|
||||
filters?: FilterablePaymentProviderProps,
|
||||
config?: FindConfig<PaymentProviderDTO>,
|
||||
@MedusaContext() sharedContext?: Context
|
||||
): Promise<PaymentProvider[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PaymentProvider>(
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
ModuleJoinerConfig,
|
||||
StockLocationAddressInput,
|
||||
StockLocationTypes,
|
||||
UpdateStockLocationInput,
|
||||
ModulesSdkTypes,
|
||||
DAL,
|
||||
IStockLocationServiceNext,
|
||||
|
||||
@@ -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<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
|
||||
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO> {
|
||||
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO> {
|
||||
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<WorkflowOrchestratorTypes.WorkflowExecutionDTO>(
|
||||
return await this.baseRepository_.serialize<WorkflowsSdkTypes.WorkflowExecutionDTO>(
|
||||
wfExecution[0],
|
||||
{
|
||||
populate: true,
|
||||
@@ -94,10 +94,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listWorkflowExecution(
|
||||
filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {},
|
||||
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
|
||||
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
|
||||
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO[]> {
|
||||
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO[]> {
|
||||
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<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
|
||||
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
|
||||
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
|
||||
@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<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
|
||||
workflowIdOrWorkflow: TWorkflow,
|
||||
options: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO<
|
||||
options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO<
|
||||
TWorkflow extends ReturnWorkflow<any, any, any>
|
||||
? UnwrapWorkflowInputDataType<TWorkflow>
|
||||
: unknown
|
||||
|
||||
@@ -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<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
|
||||
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO> {
|
||||
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO> {
|
||||
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<WorkflowOrchestratorTypes.WorkflowExecutionDTO>(
|
||||
return await this.baseRepository_.serialize<WorkflowsSdkTypes.WorkflowExecutionDTO>(
|
||||
wfExecution[0],
|
||||
{
|
||||
populate: true,
|
||||
@@ -108,10 +108,10 @@ export class WorkflowsModuleService implements IWorkflowEngineService {
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listWorkflowExecution(
|
||||
filters: WorkflowOrchestratorTypes.FilterableWorkflowExecutionProps = {},
|
||||
config: FindConfig<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
|
||||
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
|
||||
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<WorkflowOrchestratorTypes.WorkflowExecutionDTO[]> {
|
||||
): Promise<WorkflowsSdkTypes.WorkflowExecutionDTO[]> {
|
||||
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<WorkflowOrchestratorTypes.WorkflowExecutionDTO> = {},
|
||||
filters: WorkflowsSdkTypes.FilterableWorkflowExecutionProps = {},
|
||||
config: FindConfig<WorkflowsSdkTypes.WorkflowExecutionDTO> = {},
|
||||
@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<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
|
||||
workflowIdOrWorkflow: TWorkflow,
|
||||
options: WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO<
|
||||
options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO<
|
||||
TWorkflow extends ReturnWorkflow<any, any, any>
|
||||
? UnwrapWorkflowInputDataType<TWorkflow>
|
||||
: unknown
|
||||
|
||||
Reference in New Issue
Block a user