feat(medusa-js, medusa-react, medusa): Prepare API for admin implementations (#3110)

********What********
Add `joinSalesChannels util to stock locations

Add the following endpoints to medusa-react
- inventory items
    - mutations
        - update
        - delete
        - update location level
        - delete location level
        - create location level
    - queries
        - list inventory items
        - get inventory item
        - list location levels
- Stock locations
    - mutations
        - create stock location
        - update stock location
        - delete stock location
    - queries
        - list stock locations
        - get stock locatoin
- Variants
    - queries
        - get inventory
- Reservations
    - mutations
        - create reservation
        - update reservation
        - delete reservation
    - queries
        - list reservations
        - get reservation
- sales channels 
  - mutations
    - associate location with sc
    - remove location association

**Why**
- Update clients to reflect new api endpoints in the core with inventory modules

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
Rares StefanandPhilip Korsholm authored and GitHub committed 2023-02-16 08:49:48 +00:00
1 parent 121b42acfe
commit 12d304307a
48 files changed
+1756 -57

No files matched your search

@@ -33,6 +33,8 @@ import AdminUsersResource from "./users"
import AdminVariantsResource from "./variants"
import AdminPaymentCollectionsResource from "./payment-collections"
import AdminPaymentsResource from "./payments"
import AdminInventoryItemsResource from "./inventory-item"
import AdminReservationsResource from "./reservations"
import AdminProductCategoriesResource from "./product-categories"
class Admin extends BaseResource {
@@ -46,6 +48,7 @@ class Admin extends BaseResource {
public draftOrders = new AdminDraftOrdersResource(this.client)
public giftCards = new AdminGiftCardsResource(this.client)
public invites = new AdminInvitesResource(this.client)
public inventoryItems = new AdminInventoryItemsResource(this.client)
public notes = new AdminNotesResource(this.client)
public priceLists = new AdminPriceListResource(this.client)
public products = new AdminProductsResource(this.client)
@@ -65,6 +68,7 @@ class Admin extends BaseResource {
public store = new AdminStoresResource(this.client)
public shippingOptions = new AdminShippingOptionsResource(this.client)
public regions = new AdminRegionsResource(this.client)
public reservations = new AdminReservationsResource(this.client)
public notifications = new AdminNotificationsResource(this.client)
public taxRates = new AdminTaxRatesResource(this.client)
public uploads = new AdminUploadsResource(this.client)
@@ -8,6 +8,7 @@ import {
AdminGetInventoryItemsItemParams,
AdminInventoryItemsListWithVariantsAndLocationLevelsRes,
AdminInventoryItemsLocationLevelsRes,
AdminPostInventoryItemsItemLocationLevelsReq,
} from "@medusajs/medusa"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
@@ -119,6 +120,29 @@ class AdminInventoryItemsResource extends BaseResource {
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Create stock for an Inventory Item at a Stock Location
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description creates stock levle for an Inventory Item
* @returns the Inventory Item
*/
createLocationLevel(
inventoryItemId: string,
payload: AdminPostInventoryItemsItemLocationLevelsReq,
query?: AdminGetInventoryItemsParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsRes> {
let path = `/admin/inventory-items/${inventoryItemId}/location-levels`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Removes an Inventory Item from a Stock Location. This erases trace of any quantity currently at the location.
* @experimental This feature is under development and may change in the future.
@@ -0,0 +1,97 @@
import {
AdminPostReservationsReq,
AdminPostReservationsReservationReq,
AdminReservationsDeleteRes,
AdminReservationsRes,
AdminGetReservationsParams,
AdminReservationsListRes,
} from "@medusajs/medusa"
import qs from "qs"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
class AdminReservationsResource extends BaseResource {
/**
* Get a reservation
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description gets a reservation
* @returns The reservation with the provided id
*/
retrieve(
id: string,
customHeaders: Record<string, unknown> = {}
): ResponsePromise<AdminReservationsRes> {
const path = `/admin/reservations/${id}`
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
* List reservations
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description Lists reservations
* @returns A list of reservations matching the provided query
*/
list(
query?: AdminGetReservationsParams,
customHeaders: Record<string, unknown> = {}
): ResponsePromise<AdminReservationsListRes> {
let path = `/admin/reservations`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
* create a reservation
* @description create a reservation
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @returns the created reservation
*/
create(
payload: AdminPostReservationsReq,
customHeaders: Record<string, unknown> = {}
): ResponsePromise<AdminReservationsRes> {
const path = `/admin/reservations`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* update a reservation
* @description update a reservation
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @returns The updated reservation
*/
update(
id: string,
payload: AdminPostReservationsReservationReq,
customHeaders: Record<string, unknown> = {}
): ResponsePromise<AdminReservationsRes> {
const path = `/admin/reservations/${id}`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* remove a reservation
* @description remove a reservation
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @returns reservation removal confirmation
*/
delete(
id: string,
customHeaders: Record<string, unknown> = {}
): ResponsePromise<AdminReservationsDeleteRes> {
const path = `/admin/reservations/${id}`
return this.client.request("DELETE", path, undefined, {}, customHeaders)
}
}
export default AdminReservationsResource