feat(types,js-sdk,medusa,fulfillment): Types and SDK methods related to Stock Locations (#7625)

This commit is contained in:
Kasper Fabricius Kristensen
2024-06-06 11:04:42 +02:00
committed by GitHub
parent 9677daa568
commit 50ce223e4b
83 changed files with 1327 additions and 351 deletions
@@ -0,0 +1,24 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class FulfillmentProvider {
private client: Client
constructor(client: Client) {
this.client = client
}
async list(
query?: HttpTypes.AdminFulfillmentProviderListParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminFulfillmentProviderListResponse>(
`/admin/fulfillment-providers`,
{
method: "GET",
headers,
query,
}
)
}
}
@@ -0,0 +1,85 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class FulfillmentSet {
private client: Client
constructor(client: Client) {
this.client = client
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminFulfillmentSetDeleteResponse>(
`/admin/fulfillment-sets/${id}`,
{
method: "DELETE",
headers,
}
)
}
async createServiceZone(
id: string,
body: HttpTypes.AdminCreateFulfillmentSetServiceZone,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>(
`/admin/fulfillment-sets/${id}/service-zones`,
{
method: "POST",
headers,
body,
query,
}
)
}
async retrieveServiceZones(
fulfillmentSetId: string,
serviceZoneId: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminServiceZoneResponse>(
`/admin/fulfillment-sets/${fulfillmentSetId}/service-zones/${serviceZoneId}`,
{
method: "GET",
headers,
query,
}
)
}
async updateServiceZone(
fulfillmentSetId: string,
serviceZoneId: string,
body: HttpTypes.AdminUpdateFulfillmentSetServiceZone,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>(
`/admin/fulfillment-sets/${fulfillmentSetId}/service-zones/${serviceZoneId}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async deleteServiceZone(
fulfillmentSetId: string,
serviceZoneId: string,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminServiceZoneDeleteResponse>(
`/admin/fulfillment-sets/${fulfillmentSetId}/service-zones/${serviceZoneId}`,
{
method: "DELETE",
headers,
}
)
}
}
@@ -0,0 +1,58 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class Fulfillment {
private client: Client
constructor(client: Client) {
this.client = client
}
async create(
body: HttpTypes.AdminCreateFulfillment,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>(
`/admin/fulfillments`,
{
method: "POST",
headers,
body,
query,
}
)
}
async cancel(
id: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>(
`/admin/fulfillments/${id}`,
{
method: "POST",
body: {},
headers,
}
)
}
async createShipment(
id: string,
body: HttpTypes.AdminCreateFulfillmentShipment,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminFulfillmentResponse>(
`/admin/fulfillments/${id}/shipments`,
{
method: "POST",
headers,
body,
query,
}
)
}
}
+19 -1
View File
@@ -1,11 +1,17 @@
import { Client } from "../client"
import { Customer } from "./customer"
import { Fulfillment } from "./fulfillment"
import { FulfillmentSet } from "./fulfillment-set"
import { Invite } from "./invite"
import { Order } from "./order"
import { Product } from "./product"
import { ProductCollection } from "./product-collection"
import { Region } from "./region"
import { SalesChannel } from "./sales-channel"
import { ShippingOption } from "./shipping-option"
import { ShippingProfile } from "./shipping-profile"
import { StockLocation } from "./stock-location"
import { Upload } from "./upload"
import { Order } from "./order"
export class Admin {
public invite: Invite
@@ -14,6 +20,12 @@ export class Admin {
public product: Product
public upload: Upload
public region: Region
public stockLocation: StockLocation
public salesChannel: SalesChannel
public fulfillmentSet: FulfillmentSet
public fulfillment: Fulfillment
public shippingOption: ShippingOption
public shippingProfile: ShippingProfile
public order: Order
constructor(client: Client) {
@@ -23,6 +35,12 @@ export class Admin {
this.product = new Product(client)
this.upload = new Upload(client)
this.region = new Region(client)
this.stockLocation = new StockLocation(client)
this.salesChannel = new SalesChannel(client)
this.fulfillmentSet = new FulfillmentSet(client)
this.fulfillment = new Fulfillment(client)
this.shippingOption = new ShippingOption(client)
this.shippingProfile = new ShippingProfile(client)
this.order = new Order(client)
}
}
@@ -0,0 +1,97 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class SalesChannel {
private client: Client
constructor(client: Client) {
this.client = client
}
async create(
body: HttpTypes.AdminCreateSalesChannel,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminSalesChannelResponse>(
`/admin/sales-channels`,
{
method: "POST",
headers,
body,
query,
}
)
}
async update(
id: string,
body: HttpTypes.AdminUpdateSalesChannel,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminSalesChannelResponse>(
`/admin/sales-channels/${id}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminSalesChannelDeleteResponse>(
`/admin/sales-channels/${id}`,
{
method: "DELETE",
headers,
}
)
}
async retrieve(
id: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminSalesChannelResponse>(
`/admin/sales-channels/${id}`,
{
method: "GET",
headers,
query,
}
)
}
async list(
query?: HttpTypes.AdminSalesChannelListParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminSalesChannelListResponse>(
`/admin/sales-channels`,
{
method: "GET",
headers,
query,
}
)
}
async updateProducts(
id: string,
body: HttpTypes.AdminUpdateSalesChannelProducts,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminSalesChannelResponse>(
`/admin/sales-channels/${id}/products`,
{
method: "POST",
headers,
body,
}
)
}
}
@@ -0,0 +1,82 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class ShippingOption {
private client: Client
constructor(client: Client) {
this.client = client
}
async create(
body: HttpTypes.AdminCreateShippingOption,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingOptionResponse>(
`/admin/shipping-options`,
{
method: "POST",
headers,
body,
query,
}
)
}
async update(
id: string,
body: HttpTypes.AdminUpdateShippingOption,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingOptionResponse>(
`/admin/shipping-options/${id}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminShippingOptionDeleteResponse>(
`/admin/shipping-options/${id}`,
{
method: "DELETE",
headers,
}
)
}
async list(
query?: HttpTypes.AdminShippingOptionListParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingOptionListResponse>(
`/admin/shipping-options`,
{
method: "GET",
headers,
query,
}
)
}
async updateRules(
id: string,
body: HttpTypes.AdminUpdateShippingOptionRules,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminUpdateShippingOptionRulesResponse>(
`/admin/shipping-options/${id}/rules/batch`,
{
method: "POST",
headers,
body,
}
)
}
}
@@ -0,0 +1,82 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class ShippingProfile {
private client: Client
constructor(client: Client) {
this.client = client
}
async create(
body: HttpTypes.AdminCreateShippingProfile,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingProfileResponse>(
`/admin/shipping-profiles`,
{
method: "POST",
headers,
body,
query,
}
)
}
async update(
id: string,
body: HttpTypes.AdminUpdateShippingProfile,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingProfileResponse>(
`/admin/shipping-profiles/${id}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminShippingProfileDeleteResponse>(
`/admin/shipping-profiles/${id}`,
{
method: "DELETE",
headers,
}
)
}
async list(
query?: HttpTypes.AdminShippingProfileListParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingProfileListResponse>(
`/admin/shipping-profiles`,
{
method: "GET",
headers,
query,
}
)
}
async retrieve(
id: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminShippingProfileResponse>(
`/admin/shipping-profiles/${id}`,
{
method: "GET",
headers,
query,
}
)
}
}
@@ -0,0 +1,108 @@
import { HttpTypes, SelectParams } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class StockLocation {
private client: Client
constructor(client: Client) {
this.client = client
}
async create(
body: HttpTypes.AdminCreateStockLocation,
query?: SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminStockLocationResponse>(
`/admin/stock-locations`,
{
method: "POST",
headers,
body,
query,
}
)
}
async update(
id: string,
body: HttpTypes.AdminUpdateStockLocation,
query?: SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminStockLocationResponse>(
`/admin/stock-locations/${id}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminStockLocationDeleteResponse>(
`/admin/stock-locations/${id}`,
{
method: "DELETE",
headers,
}
)
}
async retrieve(id: string, query?: SelectParams, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminStockLocationResponse>(
`/admin/stock-locations/${id}`,
{
method: "GET",
headers,
query,
}
)
}
async list(
query?: HttpTypes.AdminStockLocationListParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminStockLocationListResponse>(
`/admin/stock-locations`,
{
method: "GET",
headers,
query,
}
)
}
async updateSalesChannels(
id: string,
body: HttpTypes.AdminUpdateStockLocationSalesChannels,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminStockLocationResponse>(
`/admin/stock-locations/${id}/sales-channels`,
{
method: "POST",
headers,
body,
}
)
}
async createFulfillmentSet(
id: string,
body: HttpTypes.AdminCreateStockLocationFulfillmentSet,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminStockLocationResponse>(
`/admin/stock-locations/${id}/fulfillment-sets`,
{
method: "POST",
headers,
body,
}
)
}
}