Chore(medusa,utils,types,inventory,stock-location): remove core dependency modules (#3531)
This commit is contained in:
@@ -16,13 +16,12 @@
|
||||
],
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@medusajs/modules-sdk": "^0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"awilix": "^8.0.0",
|
||||
"cross-env": "^5.2.1",
|
||||
"typeorm": "^0.3.11",
|
||||
"typescript": "^4.4.4"
|
||||
"typescript": "^4.4.4",
|
||||
"winston": "^3.8.2"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "cross-env NODE_ENV=production yarn run build",
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
export * as CacheTypes from "./cache"
|
||||
export * as CommonTypes from "./common"
|
||||
export * as EventBusTypes from "./event-bus"
|
||||
export * as InventoryTypes from "./inventory"
|
||||
export * as ModulesSdkTypes from "./modules-sdk"
|
||||
export * as SearchTypes from "./search"
|
||||
export * as StockLocationTypes from "./stock-location"
|
||||
export * as TransactionBaseTypes from "./transaction-base"
|
||||
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export * from "./service"
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export interface ICacheService {
|
||||
get<T>(key: string): Promise<T | null>
|
||||
set(key: string, data: unknown, ttl?: number): Promise<void>
|
||||
invalidate(key: string): Promise<void>
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import {
|
||||
FindManyOptions,
|
||||
FindOneOptions,
|
||||
FindOperator,
|
||||
FindOptionsSelect,
|
||||
FindOptionsWhere,
|
||||
OrderByCondition,
|
||||
} from "typeorm"
|
||||
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder"
|
||||
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations"
|
||||
|
||||
/**
|
||||
* Utility type used to remove some optional attributes (coming from K) from a type T
|
||||
*/
|
||||
export type WithRequiredProperty<T, K extends keyof T> = T & {
|
||||
// -? removes 'optional' from a property
|
||||
[Property in K]-?: T[Property]
|
||||
}
|
||||
|
||||
export type PartialPick<T, K extends keyof T> = {
|
||||
[P in K]?: T[P]
|
||||
}
|
||||
|
||||
export interface BaseEntity {
|
||||
id: string
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
}
|
||||
|
||||
export interface SoftDeletableEntity extends BaseEntity {
|
||||
deleted_at: Date | null
|
||||
}
|
||||
|
||||
export type Writable<T> = {
|
||||
-readonly [key in keyof T]:
|
||||
| T[key]
|
||||
| FindOperator<T[key]>
|
||||
| FindOperator<T[key][]>
|
||||
| FindOperator<string[]>
|
||||
}
|
||||
|
||||
export interface FindConfig<Entity> {
|
||||
select?: (keyof Entity)[]
|
||||
skip?: number
|
||||
take?: number
|
||||
relations?: string[]
|
||||
order?: { [K: string]: "ASC" | "DESC" }
|
||||
}
|
||||
|
||||
export type ExtendedFindConfig<TEntity> = (
|
||||
| Omit<FindOneOptions<TEntity>, "where" | "relations" | "select">
|
||||
| Omit<FindManyOptions<TEntity>, "where" | "relations" | "select">
|
||||
) & {
|
||||
select?: FindOptionsSelect<TEntity>
|
||||
relations?: FindOptionsRelations<TEntity>
|
||||
where: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[]
|
||||
order?: FindOptionsOrder<TEntity>
|
||||
skip?: number
|
||||
take?: number
|
||||
}
|
||||
|
||||
export type QuerySelector<TEntity> = Selector<TEntity> & { q?: string }
|
||||
export type TreeQuerySelector<TEntity> = QuerySelector<TEntity> & {
|
||||
include_descendants_tree?: boolean
|
||||
}
|
||||
|
||||
export type Selector<TEntity> = {
|
||||
[key in keyof TEntity]?:
|
||||
| TEntity[key]
|
||||
| TEntity[key][]
|
||||
| DateComparisonOperator
|
||||
| StringComparisonOperator
|
||||
| NumericalComparisonOperator
|
||||
| FindOperator<TEntity[key][] | string | string[]>
|
||||
}
|
||||
|
||||
export type TotalField =
|
||||
| "shipping_total"
|
||||
| "discount_total"
|
||||
| "tax_total"
|
||||
| "refunded_total"
|
||||
| "total"
|
||||
| "subtotal"
|
||||
| "refundable_amount"
|
||||
| "gift_card_total"
|
||||
| "gift_card_tax_total"
|
||||
|
||||
export interface CustomFindOptions<TModel, InKeys extends keyof TModel> {
|
||||
select?: FindManyOptions<TModel>["select"]
|
||||
where?: FindManyOptions<TModel>["where"] & {
|
||||
[P in InKeys]?: TModel[P][]
|
||||
}
|
||||
order?: OrderByCondition
|
||||
skip?: number
|
||||
take?: number
|
||||
}
|
||||
|
||||
export type QueryConfig<TEntity extends BaseEntity> = {
|
||||
defaultFields?: (keyof TEntity | string)[]
|
||||
defaultRelations?: string[]
|
||||
allowedFields?: string[]
|
||||
allowedRelations?: string[]
|
||||
defaultLimit?: number
|
||||
isList?: boolean
|
||||
}
|
||||
|
||||
export type RequestQueryFields = {
|
||||
expand?: string
|
||||
fields?: string
|
||||
offset?: number
|
||||
limit?: number
|
||||
order?: string
|
||||
}
|
||||
|
||||
export type PaginatedResponse = {
|
||||
limit: number
|
||||
offset: number
|
||||
count: number
|
||||
}
|
||||
|
||||
export type DeleteResponse = {
|
||||
id: string
|
||||
object: string
|
||||
deleted: boolean
|
||||
}
|
||||
|
||||
export interface EmptyQueryParams {}
|
||||
|
||||
export interface DateComparisonOperator {
|
||||
lt?: Date
|
||||
gt?: Date
|
||||
gte?: Date
|
||||
lte?: Date
|
||||
}
|
||||
|
||||
export interface StringComparisonOperator {
|
||||
lt?: string
|
||||
gt?: string
|
||||
gte?: string
|
||||
lte?: string
|
||||
}
|
||||
|
||||
export interface NumericalComparisonOperator {
|
||||
lt?: number
|
||||
gt?: number
|
||||
gte?: number
|
||||
lte?: number
|
||||
}
|
||||
|
||||
export interface AddressPayload {
|
||||
first_name?: string
|
||||
last_name?: string
|
||||
phone?: string
|
||||
metadata?: Record<string, unknown>
|
||||
company?: string
|
||||
address_1?: string
|
||||
address_2?: string
|
||||
city?: string
|
||||
country_code?: string
|
||||
province?: string
|
||||
postal_code?: string
|
||||
}
|
||||
|
||||
export interface AddressCreatePayload {
|
||||
first_name: string
|
||||
last_name: string
|
||||
phone: string
|
||||
metadata: object
|
||||
company: string
|
||||
address_1: string
|
||||
address_2: string
|
||||
city: string
|
||||
country_code: string
|
||||
province: string
|
||||
postal_code: string
|
||||
}
|
||||
|
||||
export interface FindParams {
|
||||
expand?: string
|
||||
fields?: string
|
||||
}
|
||||
|
||||
export interface FindPaginationParams {
|
||||
offset?: number
|
||||
limit?: number
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { LoggerOptions } from "typeorm"
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
} from "../modules-sdk"
|
||||
|
||||
type SessionOptions = {
|
||||
name?: string
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
export * from "./config-module";
|
||||
export * from "./common"
|
||||
export * from "./config-module"
|
||||
export * from "./medusa-container"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { AwilixContainer } from "awilix"
|
||||
|
||||
export type MedusaContainer = AwilixContainer & {
|
||||
registerAdd: <T>(name: string, registration: T) => MedusaContainer
|
||||
createScope: () => MedusaContainer
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Subscriber, SubscriberContext } from "."
|
||||
import { ITransactionBaseService } from "../transaction-base/transaction-base"
|
||||
|
||||
export interface IEventBusService extends ITransactionBaseService {
|
||||
export interface IEventBusService extends ITransactionBaseService {
|
||||
subscribe(
|
||||
eventName: string | symbol,
|
||||
subscriber: Subscriber,
|
||||
@@ -14,4 +14,4 @@ export interface IEventBusService extends ITransactionBaseService {
|
||||
context?: SubscriberContext
|
||||
): this
|
||||
emit<T>(event: string, data: T, options?: unknown): Promise<unknown | void>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from "./common"
|
||||
export * from "./event-bus"
|
||||
export * from "./event-bus-module"
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
export * from "./bundles"
|
||||
export * from "./cache"
|
||||
export * from "./common"
|
||||
export * from "./event-bus"
|
||||
export * from "./inventory"
|
||||
export * from "./modules-sdk"
|
||||
export * from "./search"
|
||||
export * from "./shared-context"
|
||||
export * from "./stock-location"
|
||||
export * from "./transaction-base"
|
||||
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import {
|
||||
NumericalComparisonOperator,
|
||||
StringComparisonOperator,
|
||||
} from "../common"
|
||||
|
||||
/**
|
||||
* @schema InventoryItemDTO
|
||||
* type: object
|
||||
* required:
|
||||
* - sku
|
||||
* properties:
|
||||
* sku:
|
||||
* description: The Stock Keeping Unit (SKU) code of the Inventory Item.
|
||||
* type: string
|
||||
* hs_code:
|
||||
* description: The Harmonized System code of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* origin_country:
|
||||
* description: The country in which the Inventory Item was produced. May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* mid_code:
|
||||
* description: The Manufacturers Identification code that identifies the manufacturer of the Inventory Item. May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* material:
|
||||
* description: The material and composition that the Inventory Item is made of, May be used by Fulfillment Providers to pass customs information to shipping carriers.
|
||||
* type: string
|
||||
* weight:
|
||||
* description: The weight of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* height:
|
||||
* description: The height of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* width:
|
||||
* description: The width of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* length:
|
||||
* description: The length of the Inventory Item. May be used in shipping rate calculations.
|
||||
* type: number
|
||||
* requires_shipping:
|
||||
* description: Whether the item requires shipping.
|
||||
* type: boolean
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
* created_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was created."
|
||||
* format: date-time
|
||||
* updated_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was updated."
|
||||
* format: date-time
|
||||
* deleted_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was deleted."
|
||||
* format: date-time
|
||||
*/
|
||||
export type InventoryItemDTO = {
|
||||
id: string
|
||||
sku?: string | null
|
||||
origin_country?: string | null
|
||||
hs_code?: string | null
|
||||
requires_shipping: boolean
|
||||
mid_code?: string | null
|
||||
material?: string | null
|
||||
weight?: number | null
|
||||
length?: number | null
|
||||
height?: number | null
|
||||
width?: number | null
|
||||
metadata?: Record<string, unknown> | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: string | Date | null
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema ReservationItemDTO
|
||||
* title: "Reservation item"
|
||||
* description: "Represents a reservation of an inventory item at a stock location"
|
||||
* type: object
|
||||
* required:
|
||||
* - id
|
||||
* - location_id
|
||||
* - inventory_item_id
|
||||
* - quantity
|
||||
* properties:
|
||||
* id:
|
||||
* description: "The id of the reservation item"
|
||||
* type: string
|
||||
* location_id:
|
||||
* description: "The id of the location of the reservation"
|
||||
* type: string
|
||||
* inventory_item_id:
|
||||
* description: "The id of the inventory item the reservation relates to"
|
||||
* type: string
|
||||
* quantity:
|
||||
* description: "The id of the reservation item"
|
||||
* type: number
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
* created_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was created."
|
||||
* format: date-time
|
||||
* updated_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was updated."
|
||||
* format: date-time
|
||||
* deleted_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was deleted."
|
||||
* format: date-time
|
||||
*/
|
||||
export type ReservationItemDTO = {
|
||||
id: string
|
||||
location_id: string
|
||||
inventory_item_id: string
|
||||
quantity: number
|
||||
line_item_id?: string | null
|
||||
metadata: Record<string, unknown> | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: string | Date | null
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema InventoryLevelDTO
|
||||
* type: object
|
||||
* required:
|
||||
* - inventory_item_id
|
||||
* - location_id
|
||||
* - stocked_quantity
|
||||
* - reserved_quantity
|
||||
* - incoming_quantity
|
||||
* properties:
|
||||
* location_id:
|
||||
* description: the item location ID
|
||||
* type: string
|
||||
* stocked_quantity:
|
||||
* description: the total stock quantity of an inventory item at the given location ID
|
||||
* type: number
|
||||
* reserved_quantity:
|
||||
* description: the reserved stock quantity of an inventory item at the given location ID
|
||||
* type: number
|
||||
* incoming_quantity:
|
||||
* description: the incoming stock quantity of an inventory item at the given location ID
|
||||
* type: number
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
* created_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was created."
|
||||
* format: date-time
|
||||
* updated_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was updated."
|
||||
* format: date-time
|
||||
* deleted_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was deleted."
|
||||
* format: date-time
|
||||
*/
|
||||
export type InventoryLevelDTO = {
|
||||
id: string
|
||||
inventory_item_id: string
|
||||
location_id: string
|
||||
stocked_quantity: number
|
||||
reserved_quantity: number
|
||||
incoming_quantity: number
|
||||
metadata: Record<string, unknown> | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: string | Date | null
|
||||
}
|
||||
|
||||
export type FilterableReservationItemProps = {
|
||||
id?: string | string[]
|
||||
type?: string | string[]
|
||||
line_item_id?: string | string[]
|
||||
inventory_item_id?: string | string[]
|
||||
location_id?: string | string[]
|
||||
quantity?: number | NumericalComparisonOperator
|
||||
}
|
||||
|
||||
export type FilterableInventoryItemProps = {
|
||||
id?: string | string[]
|
||||
location_id?: string | string[]
|
||||
q?: string
|
||||
sku?: string | string[] | StringComparisonOperator
|
||||
origin_country?: string | string[]
|
||||
hs_code?: string | string[] | StringComparisonOperator
|
||||
requires_shipping?: boolean
|
||||
}
|
||||
|
||||
export type CreateInventoryItemInput = {
|
||||
sku?: string
|
||||
origin_country?: string
|
||||
mid_code?: string
|
||||
material?: string
|
||||
weight?: number
|
||||
length?: number
|
||||
height?: number
|
||||
width?: number
|
||||
metadata?: Record<string, unknown> | null
|
||||
hs_code?: string
|
||||
requires_shipping?: boolean
|
||||
}
|
||||
|
||||
export type CreateReservationItemInput = {
|
||||
line_item_id?: string
|
||||
inventory_item_id: string
|
||||
location_id: string
|
||||
quantity: number
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export type FilterableInventoryLevelProps = {
|
||||
inventory_item_id?: string | string[]
|
||||
location_id?: string | string[]
|
||||
stocked_quantity?: number | NumericalComparisonOperator
|
||||
reserved_quantity?: number | NumericalComparisonOperator
|
||||
incoming_quantity?: number | NumericalComparisonOperator
|
||||
}
|
||||
|
||||
export type CreateInventoryLevelInput = {
|
||||
inventory_item_id: string
|
||||
location_id: string
|
||||
stocked_quantity: number
|
||||
reserved_quantity?: number
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export type UpdateInventoryLevelInput = {
|
||||
stocked_quantity?: number
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export type UpdateReservationItemInput = {
|
||||
quantity?: number
|
||||
location_id?: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export type ReserveQuantityContext = {
|
||||
locationId?: string
|
||||
lineItemId?: string
|
||||
salesChannelId?: string | null
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./common"
|
||||
export * from "./inventory"
|
||||
@@ -0,0 +1,114 @@
|
||||
import { FindConfig } from "../common"
|
||||
|
||||
import {
|
||||
CreateInventoryItemInput,
|
||||
CreateInventoryLevelInput,
|
||||
CreateReservationItemInput,
|
||||
FilterableInventoryItemProps,
|
||||
FilterableInventoryLevelProps,
|
||||
FilterableReservationItemProps,
|
||||
InventoryItemDTO,
|
||||
InventoryLevelDTO,
|
||||
ReservationItemDTO,
|
||||
UpdateInventoryLevelInput,
|
||||
UpdateReservationItemInput,
|
||||
} from "./common"
|
||||
|
||||
export interface IInventoryService {
|
||||
listInventoryItems(
|
||||
selector: FilterableInventoryItemProps,
|
||||
config?: FindConfig<InventoryItemDTO>
|
||||
): Promise<[InventoryItemDTO[], number]>
|
||||
|
||||
listReservationItems(
|
||||
selector: FilterableReservationItemProps,
|
||||
config?: FindConfig<ReservationItemDTO>
|
||||
): Promise<[ReservationItemDTO[], number]>
|
||||
|
||||
listInventoryLevels(
|
||||
selector: FilterableInventoryLevelProps,
|
||||
config?: FindConfig<InventoryLevelDTO>
|
||||
): Promise<[InventoryLevelDTO[], number]>
|
||||
|
||||
retrieveInventoryItem(
|
||||
inventoryItemId: string,
|
||||
config?: FindConfig<InventoryItemDTO>
|
||||
): Promise<InventoryItemDTO>
|
||||
|
||||
retrieveInventoryLevel(
|
||||
inventoryItemId: string,
|
||||
locationId: string
|
||||
): Promise<InventoryLevelDTO>
|
||||
|
||||
retrieveReservationItem(reservationId: string): Promise<ReservationItemDTO>
|
||||
|
||||
createReservationItem(
|
||||
input: CreateReservationItemInput
|
||||
): Promise<ReservationItemDTO>
|
||||
|
||||
createInventoryItem(
|
||||
input: CreateInventoryItemInput
|
||||
): Promise<InventoryItemDTO>
|
||||
|
||||
createInventoryLevel(
|
||||
data: CreateInventoryLevelInput
|
||||
): Promise<InventoryLevelDTO>
|
||||
|
||||
updateInventoryLevel(
|
||||
inventoryItemId: string,
|
||||
locationId: string,
|
||||
update: UpdateInventoryLevelInput
|
||||
): Promise<InventoryLevelDTO>
|
||||
|
||||
updateInventoryItem(
|
||||
inventoryItemId: string,
|
||||
input: CreateInventoryItemInput
|
||||
): Promise<InventoryItemDTO>
|
||||
|
||||
updateReservationItem(
|
||||
reservationItemId: string,
|
||||
input: UpdateReservationItemInput
|
||||
): Promise<ReservationItemDTO>
|
||||
|
||||
deleteReservationItemsByLineItem(lineItemId: string): Promise<void>
|
||||
|
||||
deleteReservationItem(reservationItemId: string | string[]): Promise<void>
|
||||
|
||||
deleteInventoryItem(inventoryItemId: string): Promise<void>
|
||||
|
||||
deleteInventoryItemLevelByLocationId(locationId: string): Promise<void>
|
||||
|
||||
deleteReservationItemByLocationId(locationId: string): Promise<void>
|
||||
|
||||
deleteInventoryLevel(
|
||||
inventoryLevelId: string,
|
||||
locationId: string
|
||||
): Promise<void>
|
||||
|
||||
adjustInventory(
|
||||
inventoryItemId: string,
|
||||
locationId: string,
|
||||
adjustment: number
|
||||
): Promise<InventoryLevelDTO>
|
||||
|
||||
confirmInventory(
|
||||
inventoryItemId: string,
|
||||
locationIds: string[],
|
||||
quantity: number
|
||||
): Promise<boolean>
|
||||
|
||||
retrieveAvailableQuantity(
|
||||
inventoryItemId: string,
|
||||
locationIds: string[]
|
||||
): Promise<number>
|
||||
|
||||
retrieveStockedQuantity(
|
||||
inventoryItemId: string,
|
||||
locationIds: string[]
|
||||
): Promise<number>
|
||||
|
||||
retrieveReservedQuantity(
|
||||
inventoryItemId: string,
|
||||
locationIds: string[]
|
||||
): Promise<number>
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Logger as _Logger } from "winston"
|
||||
import { MedusaContainer } from "../common/medusa-container"
|
||||
export type Constructor<T> = new (...args: any[]) => T
|
||||
export * from "../common/medusa-container"
|
||||
|
||||
export type LogLevel =
|
||||
| "query"
|
||||
| "schema"
|
||||
| "error"
|
||||
| "warn"
|
||||
| "info"
|
||||
| "log"
|
||||
| "migration"
|
||||
export type LoggerOptions = boolean | "all" | LogLevel[]
|
||||
|
||||
export type Logger = _Logger & {
|
||||
progress: (activityId: string, msg: string) => void
|
||||
info: (msg: string) => void
|
||||
warn: (msg: string) => void
|
||||
}
|
||||
|
||||
export enum MODULE_SCOPE {
|
||||
INTERNAL = "internal",
|
||||
EXTERNAL = "external",
|
||||
}
|
||||
|
||||
export enum MODULE_RESOURCE_TYPE {
|
||||
SHARED = "shared",
|
||||
ISOLATED = "isolated",
|
||||
}
|
||||
|
||||
export type InternalModuleDeclaration = {
|
||||
scope: MODULE_SCOPE.INTERNAL
|
||||
resources: MODULE_RESOURCE_TYPE
|
||||
dependencies?: string[]
|
||||
resolve?: string
|
||||
options?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export type ExternalModuleDeclaration = {
|
||||
scope: MODULE_SCOPE.EXTERNAL
|
||||
server: {
|
||||
type: "http"
|
||||
url: string
|
||||
keepAlive: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export type ModuleResolution = {
|
||||
resolutionPath: string | false
|
||||
definition: ModuleDefinition
|
||||
options?: Record<string, unknown>
|
||||
dependencies?: string[]
|
||||
moduleDeclaration?: InternalModuleDeclaration | ExternalModuleDeclaration
|
||||
}
|
||||
|
||||
export type ModuleDefinition = {
|
||||
key: string
|
||||
registrationName: string
|
||||
defaultPackage: string | false
|
||||
label: string
|
||||
canOverride?: boolean
|
||||
isRequired?: boolean
|
||||
dependencies?: string[]
|
||||
defaultModuleDeclaration:
|
||||
| InternalModuleDeclaration
|
||||
| ExternalModuleDeclaration
|
||||
}
|
||||
|
||||
export type LoaderOptions<TOptions = Record<string, unknown>> = {
|
||||
container: MedusaContainer
|
||||
options?: TOptions
|
||||
logger?: Logger
|
||||
}
|
||||
|
||||
export type ModuleLoaderFunction = (
|
||||
options: LoaderOptions,
|
||||
moduleDeclaration?: InternalModuleDeclaration
|
||||
) => Promise<void>
|
||||
|
||||
export type ModulesResponse = {
|
||||
module: string
|
||||
resolution: string | false
|
||||
}[]
|
||||
|
||||
export type ModuleExports = {
|
||||
service: Constructor<any>
|
||||
loaders?: ModuleLoaderFunction[]
|
||||
migrations?: any[]
|
||||
models?: Constructor<any>[]
|
||||
runMigrations?(
|
||||
options: LoaderOptions,
|
||||
moduleDeclaration: InternalModuleDeclaration
|
||||
): Promise<void>
|
||||
revertMigration?(
|
||||
options: LoaderOptions,
|
||||
moduleDeclaration: InternalModuleDeclaration
|
||||
): Promise<void>
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export const indexTypes = {
|
||||
PRODUCTS: "products"
|
||||
};
|
||||
PRODUCTS: "products",
|
||||
}
|
||||
|
||||
@@ -17,4 +17,3 @@ export type IndexSettings = {
|
||||
*/
|
||||
transformer?: (document: any) => any
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
import { StringComparisonOperator } from "../common/common"
|
||||
|
||||
/**
|
||||
* @schema StockLocationAddressDTO
|
||||
* title: "Stock Location Address"
|
||||
* description: "Represents a Stock Location Address"
|
||||
* type: object
|
||||
* required:
|
||||
* - address_1
|
||||
* - country_code
|
||||
* - created_at
|
||||
* - updated_at
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* description: The stock location address' ID
|
||||
* example: laddr_51G4ZW853Y6TFXWPG5ENJ81X42
|
||||
* address_1:
|
||||
* type: string
|
||||
* description: Stock location address
|
||||
* example: 35, Jhon Doe Ave
|
||||
* address_2:
|
||||
* type: string
|
||||
* description: Stock location address' complement
|
||||
* example: apartment 4432
|
||||
* company:
|
||||
* type: string
|
||||
* description: Stock location company' name
|
||||
* example: Medusa
|
||||
* city:
|
||||
* type: string
|
||||
* description: Stock location address' city
|
||||
* example: Mexico city
|
||||
* country_code:
|
||||
* type: string
|
||||
* description: Stock location address' country
|
||||
* example: MX
|
||||
* phone:
|
||||
* type: string
|
||||
* description: Stock location address' phone number
|
||||
* example: +1 555 61646
|
||||
* postal_code:
|
||||
* type: string
|
||||
* description: Stock location address' postal code
|
||||
* example: HD3-1G8
|
||||
* province:
|
||||
* type: string
|
||||
* description: Stock location address' province
|
||||
* example: Sinaloa
|
||||
* created_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was created."
|
||||
* format: date-time
|
||||
* updated_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was updated."
|
||||
* format: date-time
|
||||
* deleted_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was deleted."
|
||||
* format: date-time
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
*/
|
||||
export type StockLocationAddressDTO = {
|
||||
id?: string
|
||||
address_1: string
|
||||
address_2?: string | null
|
||||
company?: string | null
|
||||
country_code: string
|
||||
city?: string | null
|
||||
phone?: string | null
|
||||
postal_code?: string | null
|
||||
province?: string | null
|
||||
metadata?: Record<string, unknown> | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: string | Date | null
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema StockLocationDTO
|
||||
* title: "Stock Location"
|
||||
* description: "Represents a Stock Location"
|
||||
* type: object
|
||||
* required:
|
||||
* - id
|
||||
* - name
|
||||
* - address_id
|
||||
* - created_at
|
||||
* - updated_at
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* description: The stock location's ID
|
||||
* example: sloc_51G4ZW853Y6TFXWPG5ENJ81X42
|
||||
* address_id:
|
||||
* type: string
|
||||
* description: Stock location address' ID
|
||||
* example: laddr_05B2ZE853Y6FTXWPW85NJ81A44
|
||||
* name:
|
||||
* type: string
|
||||
* description: The name of the stock location
|
||||
* example: Main Warehouse
|
||||
* address:
|
||||
* description: "The Address of the Stock Location"
|
||||
* allOf:
|
||||
* - $ref: "#/components/schemas/StockLocationAddressDTO"
|
||||
* - type: object
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
* created_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was created."
|
||||
* format: date-time
|
||||
* updated_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was updated."
|
||||
* format: date-time
|
||||
* deleted_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was deleted."
|
||||
* format: date-time
|
||||
*/
|
||||
export type StockLocationDTO = {
|
||||
id: string
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
address_id: string
|
||||
address?: StockLocationAddressDTO
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
deleted_at: string | Date | null
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema StockLocationExpandedDTO
|
||||
* allOf:
|
||||
* - $ref: "#/components/schemas/StockLocationDTO"
|
||||
* - type: object
|
||||
* properties:
|
||||
* sales_channels:
|
||||
* $ref: "#/components/schemas/SalesChannel"
|
||||
*/
|
||||
export type StockLocationExpandedDTO = StockLocationDTO & {
|
||||
sales_channels?: any[] // TODO: SalesChannel type
|
||||
}
|
||||
|
||||
export type FilterableStockLocationProps = {
|
||||
id?: string | string[]
|
||||
name?: string | string[] | StringComparisonOperator
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema StockLocationAddressInput
|
||||
* title: "Stock Location Address Input"
|
||||
* description: "Represents a Stock Location Address Input"
|
||||
* type: object
|
||||
* required:
|
||||
* - address_1
|
||||
* - country_code
|
||||
* properties:
|
||||
* address_1:
|
||||
* type: string
|
||||
* description: Stock location address
|
||||
* example: 35, Jhon Doe Ave
|
||||
* address_2:
|
||||
* type: string
|
||||
* description: Stock location address' complement
|
||||
* example: apartment 4432
|
||||
* city:
|
||||
* type: string
|
||||
* description: Stock location address' city
|
||||
* example: Mexico city
|
||||
* country_code:
|
||||
* type: string
|
||||
* description: Stock location address' country
|
||||
* example: MX
|
||||
* phone:
|
||||
* type: string
|
||||
* description: Stock location address' phone number
|
||||
* example: +1 555 61646
|
||||
* postal_code:
|
||||
* type: string
|
||||
* description: Stock location address' postal code
|
||||
* example: HD3-1G8
|
||||
* province:
|
||||
* type: string
|
||||
* description: Stock location address' province
|
||||
* example: Sinaloa
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
*/
|
||||
export type StockLocationAddressInput = {
|
||||
address_1: string
|
||||
address_2?: string
|
||||
country_code: string
|
||||
city?: string
|
||||
phone?: string
|
||||
province?: string
|
||||
postal_code?: string
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema CreateStockLocationInput
|
||||
* title: "Create Stock Location Input"
|
||||
* description: "Represents the Input to create a Stock Location"
|
||||
* type: object
|
||||
* required:
|
||||
* - name
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* description: The stock location name
|
||||
* address_id:
|
||||
* type: string
|
||||
* description: The Stock location address ID
|
||||
* address:
|
||||
* description: Stock location address object
|
||||
* allOf:
|
||||
* - $ref: "#/components/schemas/StockLocationAddressInput"
|
||||
* - type: object
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
*/
|
||||
export type CreateStockLocationInput = {
|
||||
name: string
|
||||
address_id?: string
|
||||
address?: string | StockLocationAddressInput
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema UpdateStockLocationInput
|
||||
* title: "Update Stock Location Input"
|
||||
* description: "Represents the Input to update a Stock Location"
|
||||
* type: object
|
||||
* properties:
|
||||
* name:
|
||||
* type: string
|
||||
* description: The stock location name
|
||||
* address_id:
|
||||
* type: string
|
||||
* description: The Stock location address ID
|
||||
* address:
|
||||
* description: Stock location address object
|
||||
* allOf:
|
||||
* - $ref: "#/components/schemas/StockLocationAddressInput"
|
||||
* - type: object
|
||||
* metadata:
|
||||
* type: object
|
||||
* description: An optional key-value map with additional details
|
||||
* example: {car: "white"}
|
||||
*/
|
||||
export type UpdateStockLocationInput = {
|
||||
name?: string
|
||||
address_id?: string
|
||||
address?: StockLocationAddressInput
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./common"
|
||||
export * from "./stock-location"
|
||||
@@ -0,0 +1,30 @@
|
||||
import { FindConfig } from "../common/common"
|
||||
import {
|
||||
CreateStockLocationInput,
|
||||
FilterableStockLocationProps,
|
||||
StockLocationDTO,
|
||||
UpdateStockLocationInput,
|
||||
} from "./common"
|
||||
|
||||
export interface IStockLocationService {
|
||||
list(
|
||||
selector: FilterableStockLocationProps,
|
||||
config?: FindConfig<StockLocationDTO>
|
||||
): Promise<StockLocationDTO[]>
|
||||
|
||||
listAndCount(
|
||||
selector: FilterableStockLocationProps,
|
||||
config?: FindConfig<StockLocationDTO>
|
||||
): Promise<[StockLocationDTO[], number]>
|
||||
|
||||
retrieve(
|
||||
id: string,
|
||||
config?: FindConfig<StockLocationDTO>
|
||||
): Promise<StockLocationDTO>
|
||||
|
||||
create(input: CreateStockLocationInput): Promise<StockLocationDTO>
|
||||
|
||||
update(id: string, input: UpdateStockLocationInput): Promise<StockLocationDTO>
|
||||
|
||||
delete(id: string): Promise<void>
|
||||
}
|
||||
Reference in New Issue
Block a user