chore: Replace reservation customer group client with JS-SDK + clean up (#8857)
This commit is contained in:
1 parent
37ebc97d82
commit
e652d03b98
36 files changed
+404
-569
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
export class CustomerGroup {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminGetCustomerGroupParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCustomerGroupResponse>(
|
||||
`/admin/customer-groups/${id}`,
|
||||
{
|
||||
method: "GET",
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminGetCustomerGroupsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCustomerGroupListResponse>(
|
||||
`/admin/customer-groups`,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async create(
|
||||
body: HttpTypes.AdminCreateCustomerGroup,
|
||||
query?: HttpTypes.AdminGetCustomerGroupsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCustomerGroupResponse>(
|
||||
`/admin/customer-groups`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateCustomerGroup,
|
||||
query?: HttpTypes.AdminGetCustomerGroupsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCustomerGroupResponse>(
|
||||
`/admin/customer-groups/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"customer_group">>(
|
||||
`/admin/customer-groups/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async batchCustomers(
|
||||
id: string,
|
||||
body: HttpTypes.AdminBatchLink,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCustomerGroupResponse>(
|
||||
`/admin/customer-groups/${id}/customers`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { ApiKey } from "./api-key"
|
||||
import { Claim } from "./claim"
|
||||
import { Currency } from "./currency"
|
||||
import { Customer } from "./customer"
|
||||
import { CustomerGroup } from "./customer-group"
|
||||
import { Exchange } from "./exchange"
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
import { FulfillmentProvider } from "./fulfillment-provider"
|
||||
@@ -24,6 +25,7 @@ import { ProductType } from "./product-type"
|
||||
import { ProductVariant } from "./product-variant"
|
||||
import { RefundReason } from "./refund-reasons"
|
||||
import { Region } from "./region"
|
||||
import Reservation from "./reservation"
|
||||
import { Return } from "./return"
|
||||
import { ReturnReason } from "./return-reason"
|
||||
import { SalesChannel } from "./sales-channel"
|
||||
@@ -73,6 +75,8 @@ export class Admin {
|
||||
public refundReason: RefundReason
|
||||
public paymentCollection: PaymentCollection
|
||||
public apiKey: ApiKey
|
||||
public reservation: Reservation
|
||||
public customerGroup: CustomerGroup
|
||||
|
||||
constructor(client: Client) {
|
||||
this.invite = new Invite(client)
|
||||
@@ -111,5 +115,7 @@ export class Admin {
|
||||
this.exchange = new Exchange(client)
|
||||
this.paymentCollection = new PaymentCollection(client)
|
||||
this.apiKey = new ApiKey(client)
|
||||
this.reservation = new Reservation(client)
|
||||
this.customerGroup = new CustomerGroup(client)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
class Reservation {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminReservationParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminReservationResponse>(
|
||||
`/admin/reservations/${id}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminGetReservationsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminReservationListResponse>(
|
||||
"/admin/reservations",
|
||||
{
|
||||
method: "GET",
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async create(
|
||||
body: HttpTypes.AdminCreateReservation,
|
||||
query?: HttpTypes.AdminGetReservationsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminReservationResponse>(
|
||||
"/admin/reservations",
|
||||
{
|
||||
method: "POST",
|
||||
body,
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateReservation,
|
||||
query?: HttpTypes.AdminGetReservationsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminReservationResponse>(
|
||||
`/admin/reservations/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
body,
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"reservation">>(
|
||||
`/admin/reservations/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Reservation
|
||||
@@ -0,0 +1,3 @@
|
||||
import { BaseCustomerGroup } from "../common"
|
||||
|
||||
export interface AdminCustomerGroup extends BaseCustomerGroup {}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface AdminCreateCustomerGroup {
|
||||
name: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export interface AdminUpdateCustomerGroup {
|
||||
name?: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { OperatorMap } from "../../../dal"
|
||||
import { SelectParams } from "../../common"
|
||||
|
||||
export interface AdminCustomerInGroupFilters {
|
||||
id?: string | string[]
|
||||
email?: string | string[] | OperatorMap<string>
|
||||
default_billing_address_id?: string | string[]
|
||||
default_shipping_address_id?: string | string[]
|
||||
company_name?: string | string[]
|
||||
first_name?: string | string[]
|
||||
last_name?: string | string[]
|
||||
created_by?: string | string[]
|
||||
created_at?: OperatorMap<string>
|
||||
updated_at?: OperatorMap<string>
|
||||
deleted_at?: OperatorMap<string>
|
||||
}
|
||||
|
||||
export interface AdminGetCustomerGroupsParams {
|
||||
limit?: number
|
||||
offset?: number
|
||||
q?: string
|
||||
id?: string | string[]
|
||||
name?: string | string[]
|
||||
customers?: string | string[] | AdminCustomerInGroupFilters
|
||||
created_by?: string | string[]
|
||||
created_at?: OperatorMap<string>
|
||||
updated_at?: OperatorMap<string>
|
||||
deleted_at?: OperatorMap<string>
|
||||
$and?: AdminGetCustomerGroupsParams[]
|
||||
$or?: AdminGetCustomerGroupsParams[]
|
||||
}
|
||||
|
||||
export interface AdminGetCustomerGroupParams extends SelectParams {}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { AdminCustomerGroup } from "./entities"
|
||||
|
||||
export interface AdminCustomerGroupResponse {
|
||||
customer_group: AdminCustomerGroup
|
||||
}
|
||||
|
||||
export type AdminCustomerGroupListResponse = PaginatedResponse<{
|
||||
customer_groups: AdminCustomerGroup[]
|
||||
}>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { BaseCustomer } from "../customer/common"
|
||||
|
||||
export interface BaseCustomerGroup {
|
||||
id: string
|
||||
name: string | null
|
||||
customers: BaseCustomer[]
|
||||
metadata: Record<string, unknown> | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./admin";
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import {
|
||||
BaseCustomer,
|
||||
BaseCustomerAddress,
|
||||
BaseCustomerGroup,
|
||||
} from "../common"
|
||||
import { AdminCustomerGroup } from "../../customer-group"
|
||||
import { BaseCustomer, BaseCustomerAddress } from "../common"
|
||||
|
||||
export interface AdminCustomerGroup extends BaseCustomerGroup {}
|
||||
export interface AdminCustomer extends BaseCustomer {
|
||||
has_account: boolean
|
||||
groups?: AdminCustomerGroup[]
|
||||
}
|
||||
export interface AdminCustomerAddress extends BaseCustomerAddress {}
|
||||
export interface AdminCustomerAddress extends BaseCustomerAddress {}
|
||||
@@ -1,18 +1,12 @@
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { AdminCustomer, AdminCustomerAddress, AdminCustomerGroup } from "./entities";
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { AdminCustomer, AdminCustomerAddress } from "./entities"
|
||||
|
||||
export interface AdminCustomerResponse {
|
||||
customer: AdminCustomer
|
||||
}
|
||||
|
||||
export type AdminCustomerListResponse = PaginatedResponse<{ customers: AdminCustomer }>
|
||||
|
||||
export interface AdminCustomerGroupResponse {
|
||||
customer_group: AdminCustomerGroup
|
||||
}
|
||||
|
||||
export type AdminCustomerGroupListResponse = PaginatedResponse<{
|
||||
customer_groups: AdminCustomerGroup[]
|
||||
export type AdminCustomerListResponse = PaginatedResponse<{
|
||||
customers: AdminCustomer
|
||||
}>
|
||||
|
||||
export interface AdminCustomerAddressResponse {
|
||||
@@ -21,4 +15,4 @@ export interface AdminCustomerAddressResponse {
|
||||
|
||||
export type AdminCustomerAddressListResponse = PaginatedResponse<{
|
||||
addresses: AdminCustomerAddress[]
|
||||
}>
|
||||
}>
|
||||
@@ -6,6 +6,7 @@ export * from "./collection"
|
||||
export * from "./common"
|
||||
export * from "./currency"
|
||||
export * from "./customer"
|
||||
export * from "./customer-group"
|
||||
export * from "./exchange"
|
||||
export * from "./file"
|
||||
export * from "./fulfillment"
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface AdminCreateReservation {
|
||||
line_item_id?: string | null
|
||||
location_id: string
|
||||
inventory_item_id: string
|
||||
quantity: number
|
||||
description?: string | null
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export interface AdminUpdateReservation {
|
||||
location_id?: string
|
||||
quantity?: number
|
||||
description?: string | null
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { OperatorMap } from "../../../dal"
|
||||
import { SelectParams } from "../../common"
|
||||
|
||||
export interface AdminGetReservationsParams {
|
||||
limit?: number
|
||||
offset?: number
|
||||
location_id?: string | string[]
|
||||
inventory_item_id?: string | string[]
|
||||
line_item_id?: string | string[]
|
||||
created_by?: string | string[]
|
||||
description?: string | OperatorMap<string>
|
||||
created_at?: OperatorMap<string>
|
||||
updated_at?: OperatorMap<string>
|
||||
deleted_at?: OperatorMap<string>
|
||||
}
|
||||
|
||||
export interface AdminReservationParams extends SelectParams {}
|
||||
Reference in new issue
Block a user