Chore(medusa,utils,types,inventory,stock-location): remove core dependency modules (#3531)

This commit is contained in:
Carlos R. L. Rodrigues
2023-03-23 08:07:32 -03:00
committed by GitHub
parent bfef22b33e
commit 4e9d257d3b
159 changed files with 1769 additions and 693 deletions

View File

@@ -0,0 +1,14 @@
---
"@medusajs/cache-inmemory": patch
"@medusajs/stock-location": patch
"@medusajs/cache-redis": patch
"@medusajs/modules-sdk": patch
"@medusajs/inventory": patch
"@medusajs/medusa": patch
"@medusajs/types": patch
"@medusajs/utils": patch
"@medusajs/admin-ui": patch
"@medusajs/medusa-plugin-meilisearch": patch
---
Remove dependency on @medusajs/medusa from Inventory and Stock-Location Modules

View File

@@ -14,7 +14,10 @@ packages/*
!packages/event-bus-local
!packages/medusa-plugin-meilisearch
!packages/medusa-plugin-algolia
!packages/inventory
!packages/stock-location
!packages/cache-redis
!packages/cache-inmemory
**/models/*

View File

@@ -88,6 +88,10 @@ module.exports = {
"./packages/medusa-plugin-meilisearch/tsconfig.spec.json",
"./packages/medusa-plugin-algolia/tsconfig.spec.json",
"./packages/admin-ui/tsconfig.json",
"./packages/inventory/tsconfig.spec.json",
"./packages/stock-location/tsconfig.spec.json",
"./packages/cache-redis/tsconfig.spec.json",
"./packages/cache-inmemory/tsconfig.spec.json",
],
},
rules: {

View File

@@ -90,7 +90,7 @@ jobs:
########################## Test medusa develop ###############################
- name: Run development server
run: medusa develop > /dev/null 2>&1 &
run: medusa develop &
working-directory: ../cli-test
- name: Testing development server
@@ -99,7 +99,7 @@ jobs:
########################### Test medusa start ################################
- name: Starting medusa
run: medusa start > /dev/null 2>&1 &
run: medusa start &
working-directory: ../cli-test
- name: Testing server

View File

@@ -21,9 +21,9 @@ done
echo $status_code
if [[ "$status_code" = 000 ]] ; then
echo "Site status changed to $status_code"
if [[ "$status_code" = 000 ]] ; then
echo "Site status changed to $status_code"
exit 1
else
else
exit 0
fi

View File

@@ -79,6 +79,7 @@
},
"devDependencies": {
"@medusajs/medusa": "*",
"@medusajs/types": "^0.0.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",

View File

@@ -1,4 +1,5 @@
import { Country, StockLocationAddressDTO } from "@medusajs/medusa"
import { Country } from "@medusajs/medusa"
import { StockLocationAddressDTO } from "@medusajs/types"
import { useAdminRegions } from "medusa-react"
import { useEffect, useMemo, useState } from "react"
import { Controller, useWatch } from "react-hook-form"

View File

@@ -1,9 +1,9 @@
import { SalesChannel, StockLocationExpandedDTO } from "@medusajs/medusa"
import { SalesChannel } from "@medusajs/medusa"
import { StockLocationExpandedDTO } from "@medusajs/types"
import {
useAdminAddLocationToSalesChannel,
useAdminRemoveLocationFromSalesChannel
} from "medusa-react"
import SalesChannelsModal from "../../../../../components/forms/product/sales-channels-modal"
import Button from "../../../../../components/fundamentals/button"
import useToggleState from "../../../../../hooks/use-toggle-state"

View File

@@ -1,4 +1,4 @@
import { StockLocationDTO } from "@medusajs/medusa"
import { StockLocationDTO } from "@medusajs/types"
import { useAdminDeleteStockLocation } from "medusa-react"
import React from "react"
import IconBadge from "../../../../../components/fundamentals/icon-badge"
@@ -6,7 +6,7 @@ import BuildingsIcon from "../../../../../components/fundamentals/icons/building
import EditIcon from "../../../../../components/fundamentals/icons/edit-icon"
import TrashIcon from "../../../../../components/fundamentals/icons/trash-icon"
import Actionables, {
ActionType,
ActionType
} from "../../../../../components/molecules/actionables"
import useImperativeDialog from "../../../../../hooks/use-imperative-dialog"
import useNotification from "../../../../../hooks/use-notification"

View File

@@ -1,4 +1,4 @@
import { StockLocationExpandedDTO } from "@medusajs/medusa"
import { StockLocationExpandedDTO } from "@medusajs/types"
import SalesChannelsList from "../../../../../components/molecules/sales-channels-list"
import EditSalesChannels from "../edit-sales-channels"

View File

@@ -1,28 +1,27 @@
import {
AdminPostStockLocationsReq,
SalesChannel,
StockLocationAddressDTO,
StockLocationAddressInput,
} from "@medusajs/medusa"
import GeneralForm, { GeneralFormType } from "../components/general-form"
import { AdminPostStockLocationsReq, SalesChannel } from "@medusajs/medusa"
import {
useAdminAddLocationToSalesChannel,
useAdminCreateStockLocation,
useAdminCreateStockLocation
} from "medusa-react"
import GeneralForm, { GeneralFormType } from "../components/general-form"
import Accordion from "../../../../components/organisms/accordion"
import AddressForm from "../components/address-form"
import {
StockLocationAddressDTO,
StockLocationAddressInput
} from "@medusajs/types"
import { useForm } from "react-hook-form"
import Button from "../../../../components/fundamentals/button"
import CrossIcon from "../../../../components/fundamentals/icons/cross-icon"
import DeletePrompt from "../../../../components/organisms/delete-prompt"
import FocusModal from "../../../../components/molecules/modal/focus-modal"
import SalesChannelsForm from "../components/sales-channels-form"
import { getErrorMessage } from "../../../../utils/error-messages"
import { nestedForm } from "../../../../utils/nested-form"
import { useFeatureFlag } from "../../../../providers/feature-flag-provider"
import { useForm } from "react-hook-form"
import Accordion from "../../../../components/organisms/accordion"
import DeletePrompt from "../../../../components/organisms/delete-prompt"
import useNotification from "../../../../hooks/use-notification"
import useToggleState from "../../../../hooks/use-toggle-state"
import { useFeatureFlag } from "../../../../providers/feature-flag-provider"
import { getErrorMessage } from "../../../../utils/error-messages"
import { nestedForm } from "../../../../utils/nested-form"
import AddressForm from "../components/address-form"
import SalesChannelsForm from "../components/sales-channels-form"
type NewLocationForm = {
general: GeneralFormType

View File

@@ -1,7 +1,7 @@
module.exports = {
globals: {
"ts-jest": {
tsConfig: "tsconfig.json",
tsConfig: "tsconfig.spec.json",
isolatedModules: false,
},
},

View File

@@ -17,7 +17,7 @@
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"@medusajs/medusa": "*",
"@medusajs/types": "^0.0.1",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
@@ -30,7 +30,7 @@
"test": "jest --passWithNoTests",
"test:unit": "jest --passWithNoTests"
},
"peerDependencies": {
"@medusajs/medusa": "^1.7.11"
"dependencies": {
"@medusajs/modules-sdk": "^0.0.1"
}
}

View File

@@ -1,5 +1,4 @@
import { ICacheService } from "@medusajs/medusa"
import { ICacheService } from "@medusajs/types"
import { CacheRecord, InMemoryCacheModuleOptions } from "../types"
const DEFAULT_TTL = 30 // seconds

View File

@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@@ -1,7 +1,7 @@
module.exports = {
globals: {
"ts-jest": {
tsConfig: "tsconfig.json",
tsConfig: "tsconfig.spec.json",
isolatedModules: false,
},
},

View File

@@ -17,7 +17,7 @@
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"@medusajs/medusa": "*",
"@medusajs/types": "^0.0.1",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
@@ -30,7 +30,9 @@
"test": "jest --passWithNoTests",
"test:unit": "jest --passWithNoTests"
},
"peerDependencies": {
"@medusajs/medusa": "^1.7.11"
"dependencies": {
"@medusajs/modules-sdk": "^0.0.1",
"awilix": "^8.0.0",
"ioredis": "^5.3.1"
}
}

View File

@@ -1,7 +1,6 @@
import Redis from "ioredis"
import { asValue } from "awilix"
import { LoaderOptions } from "@medusajs/modules-sdk"
import { asValue } from "awilix"
import Redis from "ioredis"
import { RedisCacheModuleOptions } from "../types"
export default async ({

View File

@@ -1,6 +1,5 @@
import { ICacheService } from "@medusajs/types"
import { Redis } from "ioredis"
import { ICacheService } from "@medusajs/medusa"
import { RedisCacheModuleOptions } from "../types"
const DEFAULT_NAMESPACE = "medusa"

View File

@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@@ -1,6 +1,5 @@
import { LoaderOptions } from "@medusajs/modules-sdk"
export default async ({ logger }: LoaderOptions): Promise<void> => {
logger?.warn(
"Local Event Bus installed. This is not recommended for production."

View File

@@ -9,12 +9,14 @@ type InjectedDependencies = {
const eventEmitter = new EventEmitter()
// eslint-disable-next-line max-len
export default class LocalEventBusService extends AbstractEventBusModuleService {
protected readonly logger_: Logger
protected readonly eventEmitter_: EventEmitter
constructor({ logger }: MedusaContainer & InjectedDependencies) {
// @ts-ignore
// eslint-disable-next-line prefer-rest-params
super(...arguments)
this.logger_ = logger
@@ -52,12 +54,11 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
this.logger_.info(
`Processing ${event.eventName} which has ${eventListenersCount} subscribers`
)
if (eventListenersCount === 0) {
continue
}
try {
this.eventEmitter_.emit(event.eventName, event.data)
} catch (error) {

View File

@@ -34,6 +34,7 @@
"dependencies": {
"@medusajs/modules-sdk": "*",
"@medusajs/utils": "^0.0.1",
"awilix": "^8.0.0",
"bullmq": "^3.5.6",
"ioredis": "^5.2.5"
}

View File

@@ -15,10 +15,12 @@ type InjectedDependencies = {
* Can keep track of multiple subscribers to different events and run the
* subscribers when events happen. Events will run asynchronously.
*/
// eslint-disable-next-line max-len
export default class RedisEventBusService extends AbstractEventBusModuleService {
protected readonly config_: ConfigModule
protected readonly logger_: Logger
protected readonly moduleOptions_: EventBusRedisModuleOptions
// eslint-disable-next-line max-len
protected readonly moduleDeclaration_: InternalModuleDeclaration
protected queue_: Queue
@@ -29,6 +31,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
moduleDeclaration: InternalModuleDeclaration
) {
// @ts-ignore
// eslint-disable-next-line prefer-rest-params
super(...arguments)
this.moduleOptions_ = moduleOptions

View File

@@ -1,9 +1,7 @@
{
"compilerOptions": {
"lib": [
"es2019"
],
"target": "es5",
"lib": ["es2020"],
"target": "ES2020",
"outDir": "./dist",
"esModuleInterop": true,
"declaration": true,
@@ -21,13 +19,8 @@
"jsx": "react-jsx",
"emitDeclarationOnly": true
},
"include": [
"src"
],
"exclude": [
"node_modules",
"**/tests/*"
],
"include": ["src"],
"exclude": ["node_modules", "**/tests/*"],
"ts-node": {
"transpileOnly": true
}

View File

@@ -1,7 +1,7 @@
module.exports = {
globals: {
"ts-jest": {
tsConfig: "tsconfig.json",
tsConfig: "tsconfig.spec.json",
isolatedModules: false,
},
},

View File

@@ -17,14 +17,13 @@
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"@medusajs/types": "*",
"@medusajs/types": "^0.0.1",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
"typescript": "^4.4.4"
},
"dependencies": {
"@medusajs/medusa": "^1.7.7",
"@medusajs/modules-sdk": "*",
"@medusajs/utils": "^0.0.1",
"awilix": "^8.0.0",
@@ -36,8 +35,5 @@
"build": "tsc --build",
"test": "jest --passWithNoTests",
"test:unit": "jest --passWithNoTests"
},
"peerDependencies": {
"@medusajs/types": "^0.0.1"
}
}

View File

@@ -25,4 +25,3 @@ export default moduleDefinition
export * from "./initialize"
export * from "./types"

View File

@@ -1,16 +1,15 @@
import { IInventoryService } from "@medusajs/medusa"
import {
ExternalModuleDeclaration,
InternalModuleDeclaration,
MedusaModule
MedusaModule,
} from "@medusajs/modules-sdk"
import { EventBusTypes } from "@medusajs/types"
import { IEventBusService, IInventoryService } from "@medusajs/types"
import { InventoryServiceInitializeOptions } from "../types"
export const initialize = async (
options?: InventoryServiceInitializeOptions | ExternalModuleDeclaration,
injectedDependencies?: {
eventBusService: EventBusTypes.IEventBusService
eventBusService: IEventBusService
}
): Promise<IInventoryService> => {
const serviceKey = "inventoryService"

View File

@@ -6,8 +6,8 @@ import {
} from "@medusajs/modules-sdk"
import { DataSource, DataSourceOptions } from "typeorm"
import { MedusaError } from "@medusajs/utils"
import { asValue } from "awilix"
import { MedusaError } from "medusa-core-utils"
import * as InventoryModels from "../models"
import { InventoryServiceInitializeOptions } from "../types"

View File

@@ -3,7 +3,7 @@ import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk"
import {
InventoryItemService,
InventoryLevelService,
ReservationItemService
ReservationItemService,
} from "../services"
import { asClass } from "awilix"

View File

@@ -1,5 +1,5 @@
import { Index, BeforeInsert, Column, Entity } from "typeorm"
import { SoftDeletableEntity, generateEntityId } from "@medusajs/medusa"
import { generateEntityId, SoftDeletableEntity } from "@medusajs/utils"
import { BeforeInsert, Column, Entity, Index } from "typeorm"
@Entity()
export class InventoryItem extends SoftDeletableEntity {

View File

@@ -1,5 +1,5 @@
import { Index, Unique, BeforeInsert, Column, Entity } from "typeorm"
import { SoftDeletableEntity, generateEntityId } from "@medusajs/medusa"
import { generateEntityId, SoftDeletableEntity } from "@medusajs/utils"
import { BeforeInsert, Column, Entity, Index } from "typeorm"
@Entity()
@Index(["inventory_item_id", "location_id"], { unique: true })

View File

@@ -1,5 +1,5 @@
import { Index, BeforeInsert, Column, Entity } from "typeorm"
import { SoftDeletableEntity, generateEntityId } from "@medusajs/medusa"
import { generateEntityId, SoftDeletableEntity } from "@medusajs/utils"
import { BeforeInsert, Column, Entity, Index } from "typeorm"
@Entity()
export class ReservationItem extends SoftDeletableEntity {

View File

@@ -1,19 +1,24 @@
import {
buildQuery,
CreateInventoryItemInput,
FilterableInventoryItemProps,
FindConfig,
InventoryItemDTO
} from "@medusajs/medusa"
import { EventBusTypes, SharedContext } from "@medusajs/types"
import { InjectEntityManager, MedusaContext } from "@medusajs/utils"
import { isDefined, MedusaError } from "medusa-core-utils"
IEventBusService,
InventoryItemDTO,
SharedContext,
} from "@medusajs/types"
import {
buildQuery,
InjectEntityManager,
isDefined,
MedusaContext,
MedusaError,
} from "@medusajs/utils"
import { DeepPartial, EntityManager, FindManyOptions } from "typeorm"
import { InventoryItem } from "../models"
import { getListQuery } from "../utils/query"
type InjectedDependencies = {
eventBusService: EventBusTypes.IEventBusService
eventBusService: IEventBusService
manager: EntityManager
}
@@ -25,7 +30,7 @@ export default class InventoryItemService {
}
protected readonly manager_: EntityManager
protected readonly eventBusService_: EventBusTypes.IEventBusService | undefined
protected readonly eventBusService_: IEventBusService | undefined
constructor({ eventBusService, manager }: InjectedDependencies) {
this.manager_ = manager

View File

@@ -1,17 +1,22 @@
import {
buildQuery,
CreateInventoryLevelInput,
FilterableInventoryLevelProps,
FindConfig
} from "@medusajs/medusa"
import { EventBusTypes, SharedContext } from "@medusajs/types"
import { InjectEntityManager, MedusaContext } from "@medusajs/utils"
import { isDefined, MedusaError } from "medusa-core-utils"
FindConfig,
IEventBusService,
SharedContext,
} from "@medusajs/types"
import {
buildQuery,
InjectEntityManager,
isDefined,
MedusaContext,
MedusaError,
} from "@medusajs/utils"
import { DeepPartial, EntityManager, FindManyOptions, In } from "typeorm"
import { InventoryLevel } from "../models"
type InjectedDependencies = {
eventBusService: EventBusTypes.IEventBusService
eventBusService: IEventBusService
manager: EntityManager
}
@@ -23,7 +28,7 @@ export default class InventoryLevelService {
}
protected readonly manager_: EntityManager
protected readonly eventBusService_: EventBusTypes.IEventBusService | undefined
protected readonly eventBusService_: IEventBusService | undefined
constructor({ eventBusService, manager }: InjectedDependencies) {
this.manager_ = manager

View File

@@ -1,5 +1,4 @@
import { InternalModuleDeclaration } from "@medusajs/modules-sdk"
import {
CreateInventoryItemInput,
CreateInventoryLevelInput,
@@ -8,33 +7,35 @@ import {
FilterableInventoryLevelProps,
FilterableReservationItemProps,
FindConfig,
IEventBusService,
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
ReservationItemDTO,
SharedContext,
UpdateInventoryLevelInput,
UpdateReservationItemInput
} from "@medusajs/medusa"
import { EventBusTypes, SharedContext } from "@medusajs/types"
import { InjectEntityManager, MedusaContext } from "@medusajs/utils"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
UpdateReservationItemInput,
} from "@medusajs/types"
import {
InventoryItemService,
InventoryLevelService,
ReservationItemService
} from "./"
InjectEntityManager,
MedusaContext,
MedusaError,
} from "@medusajs/utils"
import { EntityManager } from "typeorm"
import InventoryItemService from "./inventory-item"
import InventoryLevelService from "./inventory-level"
import ReservationItemService from "./reservation-item"
type InjectedDependencies = {
manager: EntityManager
eventBusService: EventBusTypes.IEventBusService
eventBusService: IEventBusService
inventoryItemService: InventoryItemService
inventoryLevelService: InventoryLevelService
reservationItemService: ReservationItemService
}
export default class InventoryService implements IInventoryService {
protected readonly manager_: EntityManager
protected readonly eventBusService_: EventBusTypes.IEventBusService | undefined
protected readonly eventBusService_: IEventBusService | undefined
protected readonly inventoryItemService_: InventoryItemService
protected readonly reservationItemService_: ReservationItemService
protected readonly inventoryLevelService_: InventoryLevelService

View File

@@ -1,18 +1,24 @@
import {
buildQuery,
CreateReservationItemInput,
FilterableReservationItemProps,
FindConfig, UpdateReservationItemInput
} from "@medusajs/medusa"
import { EventBusTypes, SharedContext } from "@medusajs/types"
import { InjectEntityManager, MedusaContext } from "@medusajs/utils"
import { isDefined, MedusaError } from "medusa-core-utils"
FindConfig,
IEventBusService,
SharedContext,
UpdateReservationItemInput,
} from "@medusajs/types"
import {
buildQuery,
InjectEntityManager,
isDefined,
MedusaContext,
MedusaError,
} from "@medusajs/utils"
import { EntityManager, FindManyOptions } from "typeorm"
import { InventoryLevelService } from "."
import { ReservationItem } from "../models"
type InjectedDependencies = {
eventBusService: EventBusTypes.IEventBusService
eventBusService: IEventBusService
manager: EntityManager
inventoryLevelService: InventoryLevelService
}
@@ -25,7 +31,7 @@ export default class ReservationItemService {
}
protected readonly manager_: EntityManager
protected readonly eventBusService_: EventBusTypes.IEventBusService | undefined
protected readonly eventBusService_: IEventBusService | undefined
protected readonly inventoryLevelService_: InventoryLevelService
constructor({

View File

@@ -1,11 +1,10 @@
import { EntityManager, FindOptionsWhere, ILike } from "typeorm"
import {
buildLegacyFieldsListFrom,
buildQuery,
ExtendedFindConfig,
FilterableInventoryItemProps,
FindConfig,
} from "@medusajs/medusa"
} from "@medusajs/types"
import { buildLegacyFieldsListFrom, buildQuery } from "@medusajs/utils"
import { EntityManager, FindOptionsWhere, ILike } from "typeorm"
import { InventoryItem } from "../models"
export function getListQuery(

View File

@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules"]
}

View File

@@ -30,15 +30,12 @@
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-classes": "^7.9.5",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5",
"cross-env": "^5.2.1",
"jest": "^25.5.4"
},
"dependencies": {
"@babel/polyfill": "^7.8.7",
"@babel/runtime": "^7.9.6",
"axios": "^0.21.4",
"chalk": "^4.0.0",
"configstore": "5.0.1",
@@ -53,13 +50,13 @@
"meant": "^1.0.3",
"medusa-core-utils": "^1.1.39",
"medusa-telemetry": "0.0.16",
"netrc-parser": "^3.1.6",
"open": "^8.0.6",
"ora": "^5.4.1",
"pg-god": "^1.0.12",
"prompts": "^2.4.2",
"regenerator-runtime": "^0.13.11",
"resolve-cwd": "^3.0.0",
"sqlite3": "^5.0.2",
"stack-trace": "^0.0.10",
"ulid": "^2.3.0",
"url": "^0.11.0",

View File

@@ -13,12 +13,14 @@ const { whoami } = require("./commands/whoami")
const { login } = require("./commands/login")
const { link } = require("./commands/link")
const handlerP = fn => (...args) => {
Promise.resolve(fn(...args)).then(
() => process.exit(0),
err => console.log(err)
)
}
const handlerP =
(fn) =>
(...args) => {
Promise.resolve(fn(...args)).then(
() => process.exit(0),
(err) => console.log(err)
)
}
function buildLocalCommands(cli, isLocalProject) {
const defaultHost = `localhost`
@@ -54,12 +56,17 @@ function buildLocalCommands(cli, isLocalProject) {
)
return require(cmdPath).default
} catch (err) {
if (process.env.NODE_ENV !== "production") {
console.log("--------------- ERROR ---------------------")
console.log(err)
console.log("-------------------------------------------")
}
cli.showHelp()
}
}
function getCommandHandler(command, handler) {
return argv => {
return (argv) => {
const localCmd = resolveLocalCommand(command)
const args = { ...argv, ...projectInfo, useYarn }
@@ -70,7 +77,7 @@ function buildLocalCommands(cli, isLocalProject) {
cli
.command({
command: `new [root] [starter]`,
builder: _ =>
builder: (_) =>
_.option(`seed`, {
type: `boolean`,
describe: `If flag is set the command will attempt to seed the database after setup.`,
@@ -123,7 +130,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `telemetry`,
describe: `Enable or disable collection of anonymous usage data.`,
builder: yargs =>
builder: (yargs) =>
yargs
.option(`enable`, {
type: `boolean`,
@@ -145,7 +152,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `seed`,
desc: `Migrates and populates the database with the provided file.`,
builder: _ =>
builder: (_) =>
_.option(`f`, {
alias: `seed-file`,
type: `string`,
@@ -188,7 +195,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `link`,
desc: `Creates your Medusa Cloud user in your local database for local testing.`,
builder: _ =>
builder: (_) =>
_.option(`su`, {
alias: `skip-local-user`,
type: `boolean`,
@@ -199,7 +206,7 @@ function buildLocalCommands(cli, isLocalProject) {
default: false,
describe: `If set medusa develop will be run after successful linking.`,
}),
handler: handlerP(argv => {
handler: handlerP((argv) => {
if (!isLocalProject) {
console.log("must be a local project")
cli.showHelp()
@@ -218,7 +225,7 @@ function buildLocalCommands(cli, isLocalProject) {
.command({
command: `develop`,
desc: `Start development server. Watches file and rebuilds when something changes`,
builder: _ =>
builder: (_) =>
_.option(`H`, {
alias: `host`,
type: `string`,
@@ -239,14 +246,14 @@ function buildLocalCommands(cli, isLocalProject) {
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
// kills it so this is fine.
return new Promise(resolve => {})
return new Promise((resolve) => {})
})
),
})
.command({
command: `start`,
desc: `Start development server.`,
builder: _ =>
builder: (_) =>
_.option(`H`, {
alias: `host`,
type: `string`,
@@ -267,14 +274,14 @@ function buildLocalCommands(cli, isLocalProject) {
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
// kills it so this is fine.
return new Promise(resolve => {})
return new Promise((resolve) => {})
})
),
})
.command({
command: `user`,
desc: `Create a user`,
builder: _ =>
builder: (_) =>
_.option(`e`, {
alias: `email`,
type: `string`,
@@ -296,7 +303,7 @@ function buildLocalCommands(cli, isLocalProject) {
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
// kills it so this is fine.
return new Promise(resolve => {})
return new Promise((resolve) => {})
})
),
})
@@ -335,7 +342,7 @@ Medusa version: ${medusaVersion}
}
}
module.exports = argv => {
module.exports = (argv) => {
const cli = yargs()
const isLocalProject = isLocalMedusaProject()
@@ -381,13 +388,21 @@ module.exports = argv => {
.demandCommand(1, `Pass --help to see all available commands and options.`)
.strict()
.fail((msg, err, yargs) => {
const availableCommands = yargs.getCommands().map(commandDescription => {
const [command] = commandDescription
return command.split(` `)[0]
})
const availableCommands = yargs
.getCommands()
.map((commandDescription) => {
const [command] = commandDescription
return command.split(` `)[0]
})
const arg = argv.slice(2)[0]
const suggestion = arg ? didYouMean(arg, availableCommands) : ``
if (process.env.NODE_ENV !== "production") {
console.log("--------------- ERROR ---------------------")
console.log(err)
console.log("-------------------------------------------")
}
cli.showHelp()
reporter.info(suggestion)
reporter.info(msg)

View File

@@ -19,11 +19,12 @@
"watch": "tsc --watch"
},
"dependencies": {
"@medusajs/utils": "*",
"@medusajs/modules-sdk": "^0.0.1",
"@medusajs/utils": "^0.0.1",
"algoliasearch": "^4.15.0"
},
"devDependencies": {
"@medusajs/types": "*",
"@medusajs/types": "^0.0.1",
"client-sessions": "^0.8.0",
"cross-env": "^5.2.1",
"jest": "^25.5.4",

View File

@@ -19,11 +19,14 @@
"watch": "tsc --watch"
},
"dependencies": {
"@medusajs/utils": "*",
"@medusajs/utils": "^0.0.1",
"body-parser": "^1.19.0",
"lodash": "^4.17.21",
"meilisearch": "^0.31.1"
},
"devDependencies": {
"@medusajs/types": "*",
"@medusajs/medusa": "^1.7.12",
"@medusajs/types": "^0.0.1",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"typescript": "^4.9.5"

View File

@@ -19,20 +19,13 @@
"author": "Sebastian Rindom",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/preset-typescript": "^7.13.0",
"@medusajs/types": "*",
"@medusajs/types": "^0.0.1",
"@types/express": "^4.17.17",
"@types/jest": "^27.5.2",
"@types/jsonwebtoken": "^8.5.9",
"@types/multer": "^1.4.7",
"babel-preset-medusa-package": "^1.1.19",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"medusa-interfaces": "^1.3.6",
"nodemon": "^2.0.20",
"sqlite3": "^5.0.2",
"supertest": "^4.0.2",
"ts-jest": "^25.5.1",
"typescript": "^4.4.4"
@@ -46,17 +39,19 @@
"test:unit": "jest"
},
"peerDependencies": {
"@medusajs/types": "^0.0.1",
"medusa-interfaces": "1.3.6",
"typeorm": "^0.3.11"
},
"dependencies": {
"@medusajs/medusa-cli": "^1.3.8",
"@medusajs/modules-sdk": "*",
"@medusajs/utils": "*",
"@medusajs/modules-sdk": "^0.0.1",
"@medusajs/utils": "^0.0.1",
"@types/ioredis": "^4.28.10",
"@types/lodash": "^4.14.191",
"awilix": "^8.0.0",
"body-parser": "^1.19.0",
"boxen": "^5.0.1",
"bullmq": "^3.5.6",
"chokidar": "^3.4.2",
"class-transformer": "^0.5.1",
@@ -66,6 +61,7 @@
"core-js": "^3.6.5",
"cors": "^2.8.5",
"cross-spawn": "^7.0.3",
"dotenv": "^16.0.3",
"express": "^4.17.1",
"express-session": "^1.17.3",
"fs-exists-cached": "^1.0.0",
@@ -74,6 +70,7 @@
"ioredis-mock": "^5.6.0",
"iso8601-duration": "^1.3.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"medusa-core-utils": "^1.1.39",
"medusa-telemetry": "^0.0.16",
"medusa-test-utils": "^1.1.39",
@@ -85,14 +82,12 @@
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pg": "^8.5.1",
"randomatic": "^3.1.1",
"redis": "^3.0.2",
"reflect-metadata": "^0.1.13",
"regenerator-runtime": "^0.13.11",
"request-ip": "^2.1.3",
"resolve-cwd": "^3.0.0",
"scrypt-kdf": "^2.0.1",
"sqlite3": "^5.0.2",
"ulid": "^2.3.0",
"uuid": "^8.3.2",
"winston": "^3.8.2"

View File

@@ -1,16 +1,14 @@
import { IInventoryService } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
import { EntityManager } from "typeorm"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../services"
import { IInventoryService } from "../../../../interfaces"
import { validator } from "../../../../utils/validator"
import { EntityManager } from "typeorm"
import { createInventoryItemTransaction } from "./transaction/create-inventory-item"
import { MedusaError } from "medusa-core-utils"
import { FindParams } from "../../../../types/common"
import { validator } from "../../../../utils/validator"
import { createInventoryItemTransaction } from "./transaction/create-inventory-item"
/**
* @oas [post] /admin/inventory-items

View File

@@ -1,10 +1,6 @@
import { Request, Response } from "express"
import { IInventoryService, IStockLocationService } from "@medusajs/types"
import { IsNumber, IsOptional, IsString } from "class-validator"
import {
IInventoryService,
IStockLocationService,
} from "../../../../interfaces"
import { Request, Response } from "express"
import { FindParams } from "../../../../types/common"
/**

View File

@@ -1,6 +1,6 @@
import { IInventoryService } from "@medusajs/types"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
import { IInventoryService } from "../../../../interfaces"
import { ProductVariantInventoryService } from "../../../../services"
/**

View File

@@ -1,7 +1,7 @@
import { IInventoryService } from "@medusajs/types"
import { Request, Response } from "express"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { IInventoryService } from "../../../../interfaces"
/**
* @oas [delete] /admin/inventory-items/{id}/location-levels/{location_id}

View File

@@ -1,4 +1,4 @@
import { IInventoryService } from "../../../../interfaces"
import { IInventoryService } from "@medusajs/types"
import { Request, Response } from "express"
import { FindParams } from "../../../../types/common"
import { joinLevels } from "./utils/join-levels"

View File

@@ -1,35 +1,32 @@
import { InventoryItemDTO, InventoryLevelDTO } from "@medusajs/types"
import { Router } from "express"
import "reflect-metadata"
import { ProductVariant } from "../../../../models"
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
import {
InventoryItemDTO,
InventoryLevelDTO,
} from "../../../../types/inventory"
import middlewares, {
transformBody,
transformQuery,
} from "../../../middlewares"
import { AdminGetInventoryItemsParams } from "./list-inventory-items"
import { AdminGetInventoryItemsItemParams } from "./get-inventory-item"
import {
AdminPostInventoryItemsInventoryItemParams,
AdminPostInventoryItemsInventoryItemReq,
} from "./update-inventory-item"
import { AdminGetInventoryItemsItemLocationLevelsParams } from "./list-location-levels"
import {
AdminPostInventoryItemsItemLocationLevelsParams,
AdminPostInventoryItemsItemLocationLevelsReq,
} from "./create-location-level"
import {
AdminPostInventoryItemsItemLocationLevelsLevelParams,
AdminPostInventoryItemsItemLocationLevelsLevelReq,
} from "./update-location-level"
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
import { ProductVariant } from "../../../../models"
import {
AdminPostInventoryItemsParams,
AdminPostInventoryItemsReq,
} from "./create-inventory-item"
import {
AdminPostInventoryItemsItemLocationLevelsParams,
AdminPostInventoryItemsItemLocationLevelsReq,
} from "./create-location-level"
import { AdminGetInventoryItemsItemParams } from "./get-inventory-item"
import { AdminGetInventoryItemsParams } from "./list-inventory-items"
import { AdminGetInventoryItemsItemLocationLevelsParams } from "./list-location-levels"
import {
AdminPostInventoryItemsInventoryItemParams,
AdminPostInventoryItemsInventoryItemReq,
} from "./update-inventory-item"
import {
AdminPostInventoryItemsItemLocationLevelsLevelParams,
AdminPostInventoryItemsItemLocationLevelsLevelReq,
} from "./update-location-level"
const route = Router()
@@ -281,10 +278,10 @@ export type AdminInventoryItemsLocationLevelsRes = {
}
}
export * from "./list-inventory-items"
export * from "./create-inventory-item"
export * from "./get-inventory-item"
export * from "./update-inventory-item"
export * from "./list-location-levels"
export * from "./create-location-level"
export * from "./get-inventory-item"
export * from "./list-inventory-items"
export * from "./list-location-levels"
export * from "./update-inventory-item"
export * from "./update-location-level"

View File

@@ -1,20 +1,19 @@
import { Request, Response } from "express"
import { IsBoolean, IsOptional, IsString } from "class-validator"
import { IInventoryService } from "@medusajs/types"
import { Transform } from "class-transformer"
import { IsType } from "../../../../utils/validators/is-type"
import { getLevelsByInventoryItemId } from "./utils/join-levels"
import { getVariantsByInventoryItemId } from "./utils/join-variants"
import { IsBoolean, IsOptional, IsString } from "class-validator"
import { Request, Response } from "express"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../services"
import { IInventoryService } from "../../../../interfaces"
import {
extendedFindParamsMixin,
NumericalComparisonOperator,
StringComparisonOperator,
} from "../../../../types/common"
import { AdminInventoryItemsListWithVariantsAndLocationLevelsRes } from "."
import { IsType } from "../../../../utils/validators/is-type"
import { getLevelsByInventoryItemId } from "./utils/join-levels"
import { getVariantsByInventoryItemId } from "./utils/join-variants"
/**
* @oas [get] /admin/inventory-items

View File

@@ -1,6 +1,5 @@
import { IInventoryService } from "@medusajs/types"
import { Request, Response } from "express"
import { IInventoryService } from "../../../../interfaces"
import { FindParams } from "../../../../types/common"
/**

View File

@@ -1,3 +1,12 @@
import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { EntityManager } from "typeorm"
import { ulid } from "ulid"
import { ProductVariant } from "../../../../../models"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../../services"
import {
DistributedTransaction,
TransactionHandlerType,
@@ -6,16 +15,6 @@ import {
TransactionState,
TransactionStepsDefinition,
} from "../../../../../utils/transaction"
import { ulid } from "ulid"
import { EntityManager } from "typeorm"
import { IInventoryService } from "../../../../../interfaces"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../../services"
import { InventoryItemDTO } from "../../../../../types/inventory"
import { ProductVariant } from "../../../../../models"
import { MedusaError } from "medusa-core-utils"
enum actions {
createInventoryItem = "createInventoryItem",

View File

@@ -1,9 +1,8 @@
import { Request, Response } from "express"
import { IInventoryService } from "@medusajs/types"
import { IsBoolean, IsNumber, IsOptional, IsString } from "class-validator"
import { IInventoryService } from "../../../../interfaces"
import { FindParams } from "../../../../types/common"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
import { FindParams } from "../../../../types/common"
/**
* @oas [post] /admin/inventory-items/{id}

View File

@@ -1,9 +1,8 @@
import { Request, Response } from "express"
import { IInventoryService } from "@medusajs/types"
import { IsNumber, IsOptional, Min } from "class-validator"
import { IInventoryService } from "../../../../interfaces"
import { FindParams } from "../../../../types/common"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
import { FindParams } from "../../../../types/common"
/**
* @oas [post] /admin/inventory-items/{id}/location-levels/{location_id}

View File

@@ -1,8 +1,8 @@
import { IInventoryService } from "../../../../../interfaces"
import {
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
} from "../../../../../types/inventory"
} from "@medusajs/types"
import { LevelWithAvailability, ResponseInventoryItem } from "../../variants"
export const buildLevelsByInventoryItemId = (

View File

@@ -1,9 +1,9 @@
import { InventoryItemDTO } from "@medusajs/types"
import { ProductVariant } from "../../../../../models"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../../services"
import { InventoryItemDTO } from "../../../../../types/inventory"
import { ProductVariant } from "../../../../../models"
export type InventoryItemsWithVariants = Partial<InventoryItemDTO> & {
variants?: ProductVariant[]

View File

@@ -4,10 +4,10 @@ import {
ProductVariantInventoryService,
} from "../../../../services"
import { EntityManager } from "typeorm"
import { IInventoryService } from "@medusajs/types"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { Fulfillment } from "../../../../models"
import { IInventoryService } from "../../../../interfaces"
import { FindParams } from "../../../../types/common"
/**

View File

@@ -1,5 +1,5 @@
import { IInventoryService } from "@medusajs/types"
import { Request, Response } from "express"
import { IInventoryService } from "../../../../interfaces"
import { OrderService } from "../../../../services"
import { extendedFindParamsMixin } from "../../../../types/common"

View File

@@ -1,3 +1,5 @@
import { isDefined, MedusaError } from "@medusajs/utils"
import { Type } from "class-transformer"
import {
IsArray,
IsBoolean,
@@ -6,16 +8,13 @@ import {
IsString,
ValidateNested
} from "class-validator"
import { EntityManager } from "typeorm"
import { Order, Return } from "../../../../models"
import {
EventBusService,
OrderService,
ReturnService
} from "../../../../services"
import { Type } from "class-transformer"
import { isDefined, MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { Order, Return } from "../../../../models"
import { FindParams } from "../../../../types/common"
import { OrdersReturnItem } from "../../../../types/orders"

View File

@@ -28,21 +28,20 @@ import {
ProductVariantPricesCreateReq,
} from "../../../../types/product-variant"
import { IInventoryService } from "@medusajs/types"
import { Type } from "class-transformer"
import { EntityManager } from "typeorm"
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
import { ProductStatus } from "../../../../models"
import { Logger } from "../../../../types/global"
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
import { FlagRouter } from "../../../../utils/flag-router"
import { DistributedTransaction } from "../../../../utils/transaction"
import { validator } from "../../../../utils/validator"
import { IInventoryService } from "../../../../interfaces"
import {
createVariantTransaction,
revertVariantTransaction,
} from "./transaction/create-product-variant"
import { DistributedTransaction } from "../../../../utils/transaction"
import { Logger } from "../../../../types/global"
import { FlagRouter } from "../../../../utils/flag-router"
/**
* @oas [post] /admin/products

View File

@@ -1,3 +1,5 @@
import { IInventoryService } from "@medusajs/types"
import { Type } from "class-transformer"
import {
IsArray,
IsBoolean,
@@ -7,24 +9,19 @@ import {
IsString,
ValidateNested,
} from "class-validator"
import { Type } from "class-transformer"
import { EntityManager } from "typeorm"
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
import {
PricingService,
ProductService,
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../services"
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
import { IInventoryService } from "../../../../interfaces"
import {
CreateProductVariantInput,
ProductVariantPricesCreateReq,
} from "../../../../types/product-variant"
import { validator } from "../../../../utils/validator"
import { EntityManager } from "typeorm"
import { createVariantTransaction } from "./transaction/create-product-variant"
/**

View File

@@ -1,13 +1,12 @@
import { MedusaError } from "medusa-core-utils"
import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { EntityManager } from "typeorm"
import { ulid } from "ulid"
import { IInventoryService } from "../../../../../interfaces"
import { ProductVariant } from "../../../../../models"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../../services"
import { InventoryItemDTO } from "../../../../../types/inventory"
import { CreateProductVariantInput } from "../../../../../types/product-variant"
import {
DistributedTransaction,

View File

@@ -1,3 +1,6 @@
import { IInventoryService } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { Type } from "class-transformer"
import {
IsArray,
IsBoolean,
@@ -11,38 +14,34 @@ import {
ValidateIf,
ValidateNested,
} from "class-validator"
import { EntityManager } from "typeorm"
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
import { ProductStatus } from "../../../../models"
import {
PricingService,
ProductService,
ProductVariantInventoryService,
ProductVariantService,
} from "../../../../services"
import { Logger } from "../../../../types/global"
import {
ProductProductCategoryReq,
ProductSalesChannelReq,
ProductTagReq,
ProductTypeReq,
} from "../../../../types/product"
import { Type } from "class-transformer"
import { EntityManager } from "typeorm"
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
import { ProductStatus } from "../../../../models"
import {
CreateProductVariantInput,
ProductVariantPricesUpdateReq,
} from "../../../../types/product-variant"
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
import { validator } from "../../../../utils/validator"
import { MedusaError } from "medusa-core-utils"
import { DistributedTransaction } from "../../../../utils/transaction"
import { validator } from "../../../../utils/validator"
import {
createVariantTransaction,
revertVariantTransaction,
} from "./transaction/create-product-variant"
import { IInventoryService } from "../../../../interfaces"
import { Logger } from "../../../../types/global"
/**
* @oas [post] /admin/products/{id}

View File

@@ -1,6 +1,6 @@
import { IInventoryService } from "@medusajs/types"
import { isDefined } from "@medusajs/utils"
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
import { isDefined } from "medusa-core-utils"
import { IInventoryService } from "../../../../interfaces"
import { validateUpdateReservationQuantity } from "./utils/validate-reservation-quantity"
/**

View File

@@ -1,5 +1,5 @@
import { IInventoryService } from "@medusajs/types"
import { EntityManager } from "typeorm"
import { IInventoryService } from "../../../../interfaces"
/**
* @oas [delete] /admin/reservations/{id}

View File

@@ -1,5 +1,5 @@
import { MedusaError } from "medusa-core-utils"
import { IInventoryService } from "../../../../interfaces"
import { IInventoryService } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
/**
* @oas [get] /admin/reservations/{id}

View File

@@ -1,15 +1,14 @@
import { ReservationItemDTO } from "@medusajs/types"
import { Router } from "express"
import { ReservationItemDTO } from "../../../.."
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
import middlewares, {
transformBody,
transformQuery,
} from "../../../middlewares"
import "reflect-metadata"
import { AdminPostReservationsReq } from "./create-reservation"
import { AdminPostReservationsReservationReq } from "./update-reservation"
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
import { AdminPostReservationsReq } from "./create-reservation"
import { AdminGetReservationsParams } from "./list-reservations"
import { AdminPostReservationsReservationReq } from "./update-reservation"
const route = Router()
@@ -133,5 +132,5 @@ export type AdminReservationsDeleteRes = DeleteResponse
export * from "./create-reservation"
export * from "./delete-reservation"
export * from "./get-reservation"
export * from "./update-reservation"
export * from "./list-reservations"
export * from "./update-reservation"

View File

@@ -1,7 +1,7 @@
import { IInventoryService } from "@medusajs/types"
import { Type } from "class-transformer"
import { IsArray, IsOptional, IsString, ValidateNested } from "class-validator"
import { Request, Response } from "express"
import { IInventoryService } from "../../../../interfaces"
import {
extendedFindParamsMixin,
NumericalComparisonOperator,

View File

@@ -1,7 +1,7 @@
import { IInventoryService } from "@medusajs/types"
import { isDefined } from "@medusajs/utils"
import { IsNumber, IsObject, IsOptional, IsString } from "class-validator"
import { isDefined, MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { IInventoryService } from "../../../../interfaces"
import { LineItemService } from "../../../../services"
import { validateUpdateReservationQuantity } from "./utils/validate-reservation-quantity"

View File

@@ -1,5 +1,5 @@
import { MedusaError } from "medusa-core-utils"
import { IInventoryService } from "../../../../../interfaces"
import { IInventoryService } from "@medusajs/types"
import { MedusaError } from "@medusajs/utils"
import { LineItemService } from "../../../../../services"
export const validateUpdateReservationQuantity = async (

View File

@@ -1,8 +1,7 @@
import { Request, Response } from "express"
import { IStockLocationService } from "@medusajs/types"
import { Type } from "class-transformer"
import { IsObject, IsOptional, IsString, ValidateNested } from "class-validator"
import { IStockLocationService } from "../../../../interfaces"
import { Request, Response } from "express"
import { FindParams } from "../../../../types/common"
/**

View File

@@ -1,8 +1,5 @@
import { IInventoryService, IStockLocationService } from "@medusajs/types"
import { EntityManager } from "typeorm"
import {
IInventoryService,
IStockLocationService,
} from "../../../../interfaces"
import { SalesChannelLocationService } from "../../../../services"
/**

View File

@@ -1,11 +1,11 @@
import { IStockLocationService } from "../../../../interfaces"
import { IStockLocationService } from "@medusajs/types"
import { Request, Response } from "express"
import { FindParams } from "../../../../types/common"
import { joinSalesChannels } from "./utils/join-sales-channels"
import {
SalesChannelLocationService,
SalesChannelService,
} from "../../../../services"
import { FindParams } from "../../../../types/common"
import { joinSalesChannels } from "./utils/join-sales-channels"
/**
* @oas [get] /admin/stock-locations/{id}

View File

@@ -1,25 +1,24 @@
import { Router } from "express"
import "reflect-metadata"
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
import {
StockLocationDTO,
StockLocationExpandedDTO,
} from "../../../../types/stock-location"
DeleteResponse,
PaginatedResponse,
StockLocationTypes,
} from "@medusajs/types"
import { Router } from "express"
import middlewares, {
transformBody,
transformQuery,
} from "../../../middlewares"
import { AdminGetStockLocationsParams } from "./list-stock-locations"
import { AdminGetStockLocationsLocationParams } from "./get-stock-location"
import {
AdminPostStockLocationsLocationParams,
AdminPostStockLocationsLocationReq,
} from "./update-stock-location"
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
import {
AdminPostStockLocationsParams,
AdminPostStockLocationsReq,
} from "./create-stock-location"
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
import { AdminGetStockLocationsLocationParams } from "./get-stock-location"
import { AdminGetStockLocationsParams } from "./list-stock-locations"
import {
AdminPostStockLocationsLocationParams,
AdminPostStockLocationsLocationReq,
} from "./update-stock-location"
const route = Router()
@@ -82,14 +81,9 @@ export default (app) => {
return app
}
export const defaultAdminStockLocationFields: (keyof StockLocationDTO)[] = [
"id",
"name",
"address_id",
"metadata",
"created_at",
"updated_at",
]
// eslint-disable-next-line max-len
export const defaultAdminStockLocationFields: (keyof StockLocationTypes.StockLocationDTO)[] =
["id", "name", "address_id", "metadata", "created_at", "updated_at"]
export const defaultAdminStockLocationRelations = []
@@ -125,7 +119,7 @@ export type AdminStockLocationsDeleteRes = DeleteResponse
* $ref: "#/components/schemas/StockLocationExpandedDTO"
*/
export type AdminStockLocationsRes = {
stock_location: StockLocationExpandedDTO
stock_location: StockLocationTypes.StockLocationExpandedDTO
}
/**
@@ -152,10 +146,10 @@ export type AdminStockLocationsRes = {
* description: The number of items per page
*/
export type AdminStockLocationsListRes = PaginatedResponse & {
stock_locations: StockLocationExpandedDTO[]
stock_locations: StockLocationTypes.StockLocationExpandedDTO[]
}
export * from "./list-stock-locations"
export * from "./get-stock-location"
export * from "./create-stock-location"
export * from "./get-stock-location"
export * from "./list-stock-locations"
export * from "./update-stock-location"

View File

@@ -1,13 +1,12 @@
import { IStockLocationService } from "@medusajs/types"
import { IsOptional } from "class-validator"
import { IsType } from "../../../../utils/validators/is-type"
import { IStockLocationService } from "../../../../interfaces"
import { extendedFindParamsMixin } from "../../../../types/common"
import { Request, Response } from "express"
import {
SalesChannelLocationService,
SalesChannelService,
} from "../../../../services"
import { extendedFindParamsMixin } from "../../../../types/common"
import { IsType } from "../../../../utils/validators/is-type"
import { joinSalesChannels } from "./utils/join-sales-channels"
/**

View File

@@ -1,8 +1,7 @@
import { Request, Response } from "express"
import { IStockLocationService } from "@medusajs/types"
import { Type } from "class-transformer"
import { IsObject, IsOptional, IsString, ValidateNested } from "class-validator"
import { IStockLocationService } from "../../../../interfaces"
import { Request, Response } from "express"
import { FindParams } from "../../../../types/common"
/**

View File

@@ -1,11 +1,8 @@
import { StockLocationDTO, StockLocationExpandedDTO } from "@medusajs/types"
import {
SalesChannelLocationService,
SalesChannelService,
} from "../../../../../services"
import {
StockLocationDTO,
StockLocationExpandedDTO,
} from "../../../../../types/stock-location"
const joinSalesChannels = async (
locations: StockLocationDTO[],

View File

@@ -1,3 +1,5 @@
import { ModulesHelper } from "@medusajs/modules-sdk"
import { defaultRelationsExtended } from "."
import {
FulfillmentProviderService,
PaymentProviderService,
@@ -5,8 +7,6 @@ import {
} from "../../../../services"
import { ExtendedStoreDTO } from "../../../../types/store"
import { FlagRouter } from "../../../../utils/flag-router"
import { ModulesHelper } from "@medusajs/modules-sdk"
import { defaultRelationsExtended } from "."
/**
* @oas [get] /admin/store

View File

@@ -1,15 +1,15 @@
import {
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
} from "../../../../types/inventory"
import ProductVariantInventoryService from "../../../../services/product-variant-inventory"
} from "@medusajs/types"
import { SalesChannel } from "../../../../models"
import {
SalesChannelLocationService,
SalesChannelService,
} from "../../../../services"
import { SalesChannel } from "../../../../models"
import { IInventoryService } from "../../../../interfaces"
import ProductVariantService from "../../../../services/product-variant"
import ProductVariantInventoryService from "../../../../services/product-variant-inventory"
import { joinLevels } from "../inventory-items/utils/join-levels"
/**
@@ -126,6 +126,7 @@ export default async (req, res) => {
}
const quantity =
// eslint-disable-next-line max-len
await productVariantInventoryService.getVariantQuantityFromVariantInventoryItems(
variantInventoryItems,
channel.id

View File

@@ -1,10 +1,10 @@
import { EOL } from "os"
import boxen from "boxen"
import path from "path"
import { execSync } from "child_process"
import spawn from "cross-spawn"
import chokidar from "chokidar"
import spawn from "cross-spawn"
import Store from "medusa-telemetry/dist/store"
import { EOL } from "os"
import path from "path"
import Logger from "../loaders/logger"
@@ -50,7 +50,11 @@ export default async function ({ port, directory }) {
let child = spawn(cliPath, [`start`, ...args], {
cwd: directory,
env: process.env,
stdio: ["pipe", process.stdout, process.stderr],
stdio: ["inherit", "inherit", "inherit", "ipc"],
})
child.on("error", function (err) {
console.log("Error ", err)
process.exit(1)
})
chokidar.watch(`${directory}/src`).on("change", (file) => {
@@ -65,7 +69,7 @@ export default async function ({ port, directory }) {
execSync(`${babelPath} src -d dist --extensions ".ts,.js"`, {
cwd: directory,
stdio: ["pipe", process.stdout, process.stderr],
stdio: ["inherit", "inherit", "inherit", "ipc"],
})
Logger.info("Rebuilt")
@@ -73,7 +77,11 @@ export default async function ({ port, directory }) {
child = spawn(cliPath, [`start`, ...args], {
cwd: directory,
env: process.env,
stdio: ["pipe", process.stdout, process.stderr],
stdio: ["inherit", "inherit", "inherit", "ipc"],
})
child.on("error", function (err) {
console.log("Error ", err)
process.exit(1)
})
})
}

View File

@@ -18,40 +18,45 @@ export default async function ({ port, directory }) {
const app = express()
const { dbConnection } = await loaders({ directory, expressApp: app })
const serverActivity = Logger.activity(`Creating server`)
const server = GracefulShutdownServer.create(
app.listen(port, (err) => {
if (err) {
return
}
Logger.success(serverActivity, `Server is ready on port: ${port}`)
track("CLI_START_COMPLETED")
try {
const { dbConnection } = await loaders({ directory, expressApp: app })
const serverActivity = Logger.activity(`Creating server`)
const server = GracefulShutdownServer.create(
app.listen(port, (err) => {
if (err) {
return
}
Logger.success(serverActivity, `Server is ready on port: ${port}`)
track("CLI_START_COMPLETED")
})
)
// Handle graceful shutdown
const gracefulShutDown = () => {
server
.shutdown()
.then(() => {
Logger.info("Gracefully stopping the server.")
process.exit(0)
})
.catch((e) => {
Logger.error("Error received when shutting down the server.", e)
process.exit(1)
})
}
process.on("SIGTERM", gracefulShutDown)
process.on("SIGINT", gracefulShutDown)
scheduleJob(CRON_SCHEDULE, () => {
track("PING")
})
)
// Handle graceful shutdown
const gracefulShutDown = () => {
server
.shutdown()
.then(() => {
Logger.info("Gracefully stopping the server.")
process.exit(0)
})
.catch((e) => {
Logger.error("Error received when shutting down the server.", e)
process.exit(1)
})
return { dbConnection, server }
} catch (err) {
Logger.error("Error starting server", err)
process.exit(1)
}
process.on("SIGTERM", gracefulShutDown)
process.on("SIGINT", gracefulShutDown)
scheduleJob(CRON_SCHEDULE, () => {
track("PING")
})
return { dbConnection, server }
}
const { dbConnection, server } = await start()
await start()
}

View File

@@ -6,7 +6,5 @@ export * from "./services"
export * from "./types/batch-job"
export * from "./types/common"
export * from "./types/global"
export * from "./types/inventory"
export * from "./types/price-list"
export * from "./types/stock-location"
export * from "./utils"

View File

@@ -7,7 +7,6 @@ export * from "./notification-service"
export * from "./payment-processor"
export * from "./payment-service"
export * from "./price-selection-strategy"
export * from "./services"
export * from "./tax-calculation-strategy"
export * from "./tax-service"
export * from "./transaction-base-service"

View File

@@ -1,3 +0,0 @@
export * from "./cache"
export * from "./inventory"
export * from "./stock-location"

View File

@@ -589,9 +589,9 @@ async function runSetupFunctions(pluginDetails: PluginDetails): Promise<void> {
try {
await loaded()
} catch (err) {
throw new Error(`A setup function from ${pluginDetails.name} failed`, {
cause: err,
})
throw new Error(
`A setup function from ${pluginDetails.name} failed. ${err}`
)
}
})
)

View File

@@ -1,14 +1,14 @@
import dotenv from "dotenv"
import { AwilixContainer } from "awilix"
import dotenv from "dotenv"
import express from "express"
import {
ProductVariantService,
ProductVariantInventoryService,
} from "../services"
import { ProductVariant } from "../models"
import { IInventoryService, IStockLocationService } from "../interfaces"
import { IInventoryService, IStockLocationService } from "@medusajs/types"
import loaders from "../loaders"
import { ProductVariant } from "../models"
import {
ProductVariantInventoryService,
ProductVariantService,
} from "../services"
dotenv.config()

View File

@@ -1,4 +1,5 @@
import { isDefined, MedusaError } from "medusa-core-utils"
import { IInventoryService } from "@medusajs/types"
import { isDefined, MedusaError, TransactionBaseService } from "@medusajs/utils"
import {
EntityManager,
FindManyOptions,
@@ -8,43 +9,6 @@ import {
Not,
Raw,
} from "typeorm"
import { IInventoryService, TransactionBaseService } from "../interfaces"
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
import {
Address,
Cart,
ClaimOrder,
Fulfillment,
FulfillmentItem,
FulfillmentStatus,
GiftCard,
LineItem,
Order,
OrderStatus,
Payment,
PaymentStatus,
Return,
Swap,
TrackingLink
} from "../models"
import { AddressRepository } from "../repositories/address"
import { OrderRepository } from "../repositories/order"
import { FindConfig, QuerySelector, Selector } from "../types/common"
import {
CreateFulfillmentOrder,
FulFillmentItemType
} from "../types/fulfillment"
import { TotalsContext, UpdateOrderInput } from "../types/orders"
import { CreateShippingMethodDto } from "../types/shipping-options"
import {
buildQuery,
buildRelations,
buildSelects,
isString,
setMetadata,
} from "../utils"
import { FlagRouter } from "../utils/flag-router"
import {
CartService,
CustomerService,
@@ -61,8 +25,43 @@ import {
ShippingOptionService,
ShippingProfileService,
TaxProviderService,
TotalsService
TotalsService,
} from "."
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
import {
Address,
Cart,
ClaimOrder,
Fulfillment,
FulfillmentItem,
FulfillmentStatus,
GiftCard,
LineItem,
Order,
OrderStatus,
Payment,
PaymentStatus,
Return,
Swap,
TrackingLink,
} from "../models"
import { AddressRepository } from "../repositories/address"
import { OrderRepository } from "../repositories/order"
import { FindConfig, QuerySelector, Selector } from "../types/common"
import {
CreateFulfillmentOrder,
FulFillmentItemType,
} from "../types/fulfillment"
import { TotalsContext, UpdateOrderInput } from "../types/orders"
import { CreateShippingMethodDto } from "../types/shipping-options"
import {
buildQuery,
buildRelations,
buildSelects,
isString,
setMetadata,
} from "../utils"
import { FlagRouter } from "../utils/flag-router"
import EventBusService from "./event-bus"
export const ORDER_CART_ALREADY_EXISTS_ERROR = "Order from cart already exists"

View File

@@ -1,24 +1,19 @@
import { isDefined, MedusaError } from "medusa-core-utils"
import { EntityManager, In } from "typeorm"
import {
ICacheService,
IInventoryService,
IStockLocationService,
TransactionBaseService,
} from "../interfaces"
import { LineItem, Product, ProductVariant } from "../models"
import { ProductVariantInventoryItem } from "../models/product-variant-inventory-item"
import {
InventoryItemDTO,
IStockLocationService,
ReservationItemDTO,
ReserveQuantityContext,
} from "../types/inventory"
} from "@medusajs/types"
import { isDefined, MedusaError, TransactionBaseService } from "@medusajs/utils"
import { EntityManager, In } from "typeorm"
import { LineItem, Product, ProductVariant } from "../models"
import { ProductVariantInventoryItem } from "../models/product-variant-inventory-item"
import { PricedProduct, PricedVariant } from "../types/pricing"
import {
ProductVariantService,
SalesChannelInventoryService,
SalesChannelLocationService,
} from "./"
import ProductVariantService from "./product-variant"
import SalesChannelInventoryService from "./sales-channel-inventory"
import SalesChannelLocationService from "./sales-channel-location"
type InjectedDependencies = {
manager: EntityManager

View File

@@ -1,9 +1,7 @@
import { EventBusTypes, IInventoryService } from "@medusajs/types"
import { TransactionBaseService } from "@medusajs/utils"
import { EntityManager } from "typeorm"
import { IInventoryService, TransactionBaseService } from "../interfaces"
import { EventBusTypes } from "@medusajs/types"
import { SalesChannelLocationService } from "./"
import SalesChannelLocationService from "./sales-channel-location"
type InjectedDependencies = {
inventoryService: IInventoryService

View File

@@ -1,16 +1,15 @@
import { EntityManager, In } from "typeorm"
import { IStockLocationService, TransactionBaseService } from "../interfaces"
import { SalesChannelService } from "./"
import { EventBusTypes } from "@medusajs/types"
import { IEventBusService, IStockLocationService } from "@medusajs/types"
import { MedusaError } from "medusa-core-utils"
import { EntityManager, In } from "typeorm"
import { TransactionBaseService } from "../interfaces"
import { SalesChannelLocation } from "../models/sales-channel-location"
import SalesChannelService from "./sales-channel"
type InjectedDependencies = {
stockLocationService: IStockLocationService
salesChannelService: SalesChannelService
eventBusService: EventBusTypes.IEventBusService
eventBusService: IEventBusService
manager: EntityManager
}
@@ -20,7 +19,7 @@ type InjectedDependencies = {
class SalesChannelLocationService extends TransactionBaseService {
protected readonly salesChannelService_: SalesChannelService
protected readonly eventBusService_: EventBusTypes.IEventBusService
protected readonly eventBusService_: IEventBusService
protected readonly stockLocationService_: IStockLocationService
constructor({

View File

@@ -2,12 +2,12 @@ import { AwilixContainer } from "awilix"
import { MedusaError } from "medusa-core-utils"
import { In } from "typeorm"
import { ICacheService, IEventBusService } from "@medusajs/types"
import {
ICacheService,
ITaxService,
ItemTaxCalculationLine,
TaxCalculationContext,
TransactionBaseService,
TransactionBaseService
} from "../interfaces"
import {
Cart,
@@ -16,16 +16,13 @@ import {
Region,
ShippingMethod,
ShippingMethodTaxLine,
TaxProvider,
TaxProvider
} from "../models"
import { LineItemTaxLineRepository } from "../repositories/line-item-tax-line"
import { ShippingMethodTaxLineRepository } from "../repositories/shipping-method-tax-line"
import { TaxProviderRepository } from "../repositories/tax-provider"
import { isCart } from "../types/cart"
import { TaxLinesMaps, TaxServiceRate } from "../types/tax-service"
import EventBusService from "./event-bus"
import TaxRateService from "./tax-rate"
type RegionDetails = {
@@ -43,7 +40,7 @@ class TaxProviderService extends TransactionBaseService {
protected readonly taxLineRepo_: typeof LineItemTaxLineRepository
protected readonly smTaxLineRepo_: typeof ShippingMethodTaxLineRepository
protected readonly taxProviderRepo_: typeof TaxProviderRepository
protected readonly eventBus_: EventBusService
protected readonly eventBus_: IEventBusService
constructor(container: AwilixContainer) {
super(container)

View File

@@ -1,13 +1,13 @@
import { ICacheService } from "@medusajs/types"
import { isDefined } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import {
AbstractPriceSelectionStrategy,
ICacheService,
IPriceSelectionStrategy,
PriceSelectionContext,
PriceSelectionResult,
PriceType,
} from "../interfaces"
import { isDefined } from "medusa-core-utils"
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
import { MoneyAmountRepository } from "../repositories/money-amount"
import { TaxServiceRate } from "../types/tax-service"
@@ -79,9 +79,7 @@ class PriceSelectionStrategy extends AbstractPriceSelectionStrategy {
variant_id: string,
context: PriceSelectionContext
): Promise<PriceSelectionResult> {
const moneyRepo = this.manager_.withRepository(
this.moneyAmountRepository_
)
const moneyRepo = this.manager_.withRepository(this.moneyAmountRepository_)
const [prices, count] = await moneyRepo.findManyForVariantInRegion(
variant_id,
@@ -168,9 +166,7 @@ class PriceSelectionStrategy extends AbstractPriceSelectionStrategy {
variant_id: string,
context: PriceSelectionContext
): Promise<PriceSelectionResult> {
const moneyRepo = this.manager_.withRepository(
this.moneyAmountRepository_
)
const moneyRepo = this.manager_.withRepository(this.moneyAmountRepository_)
const [prices, count] = await moneyRepo.findManyForVariantInRegion(
variant_id,

View File

@@ -1,5 +1,5 @@
import { ICacheService } from "@medusajs/types"
import { EventBusService, ProductVariantService } from "../services"
import { ICacheService } from "../interfaces"
type ProductVariantUpdatedEventData = {
id: string

View File

@@ -15,11 +15,11 @@ import {
FindOptionsWhere,
OrderByCondition,
} from "typeorm"
import { transformDate } from "../utils/validators/date-transform"
import { BaseEntity } from "../interfaces"
import { ClassConstructor } from "./global"
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations"
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder"
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations"
import { BaseEntity } from "../interfaces"
import { transformDate } from "../utils/validators/date-transform"
import { ClassConstructor } from "./global"
/**
* Utility type used to remove some optional attributes (coming from K) from a type T

View File

@@ -1,6 +1,6 @@
import { Store, PaymentProvider, FulfillmentProvider } from "../models"
import { FeatureFlagsResponse } from "./feature-flags"
import { ModulesResponse as sdkModulesResponse } from "@medusajs/modules-sdk"
import { FulfillmentProvider, PaymentProvider, Store } from "../models"
import { FeatureFlagsResponse } from "./feature-flags"
export type UpdateStoreInput = {
name?: string

View File

@@ -1,4 +1,3 @@
import { ExtendedFindConfig, FindConfig } from "../types/common"
import {
FindManyOptions,
FindOperator,
@@ -13,6 +12,7 @@ import {
MoreThanOrEqual,
} from "typeorm"
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder"
import { ExtendedFindConfig, FindConfig } from "../types/common"
import { isObject } from "./is-object"
/**

View File

@@ -23,9 +23,10 @@
"typescript": "^4.4.4"
},
"dependencies": {
"@medusajs/types": "^0.0.1",
"@medusajs/utils": "^0.0.1",
"awilix": "^8.0.0",
"glob": "7.1.6",
"medusa-core-utils": "^1.1.39",
"medusa-telemetry": "^0.0.16",
"resolve-cwd": "^3.0.0"
},

View File

@@ -1,4 +1,8 @@
import { ModuleDefinition, MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
import {
ModuleDefinition,
MODULE_RESOURCE_TYPE,
MODULE_SCOPE,
} from "@medusajs/types"
export const MODULE_DEFINITIONS: ModuleDefinition[] = [
{

Some files were not shown because too many files have changed in this diff Show More