feat(dashboard, types, js-sdk): Claims client, hooks and types (#8370)

This commit is contained in:
Frane Polić
2024-07-31 13:37:43 +00:00
committed by GitHub
parent 31449972ed
commit 7b86fc2176
13 changed files with 1054 additions and 6 deletions
+368
View File
@@ -0,0 +1,368 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class Claim {
private client: Client
constructor(client: Client) {
this.client = client
}
async list(query?: HttpTypes.AdminClaimListParams, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminClaimListResponse>(
`/admin/claims`,
{
query,
headers,
}
)
}
async retrieve(
id: string,
query?: HttpTypes.AdminClaimParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}`,
{
query,
headers,
}
)
}
async create(
body: HttpTypes.AdminCreateClaim,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims`,
{
method: "POST",
headers,
body,
query,
}
)
}
async cancel(
id: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/cancel`,
{
method: "POST",
headers,
query,
}
)
}
async delete(
id: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimDeleteResponse>(
`/admin/claims/${id}`,
{
method: "DELETE",
headers,
query,
}
)
}
async addItems(
id: string,
body: HttpTypes.AdminAddClaimItems,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/claim-items`,
{
method: "POST",
headers,
body,
query,
}
)
}
async updateItem(
id: string,
actionId: string,
body: HttpTypes.AdminUpdateClaimItem,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/claim-items/${actionId}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async removeItem(
id: string,
actionId: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminReturnResponse>(
`/admin/claims/${id}/claim-items/${actionId}`,
{
method: "DELETE",
headers,
query,
}
)
}
async addInboundItems(
id: string,
body: HttpTypes.AdminAddClaimInboundItems,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/inbound/items`,
{
method: "POST",
headers,
body,
query,
}
)
}
async updateInboundItem(
id: string,
actionId: string,
body: HttpTypes.AdminUpdateClaimInboundItem,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/inbound/items/${actionId}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async removeInboundItem(
id: string,
actionId: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/inbound/items/${actionId}`,
{
method: "DELETE",
headers,
query,
}
)
}
async addInboundShipping(
id: string,
body: HttpTypes.AdminClaimAddInboundShipping,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/inbound/shipping-method`,
{
method: "POST",
headers,
body,
query,
}
)
}
async updateInboundShipping(
id: string,
actionId: string,
body: HttpTypes.AdminClaimUpdateInboundShipping,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/inbound/shipping-method/${actionId}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async deleteInboundShipping(
id: string,
actionId: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/inbound/shipping-method/${actionId}`,
{
method: "DELETE",
headers,
query,
}
)
}
async addOutboundItems(
id: string,
body: HttpTypes.AdminAddClaimOutboundItems,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/outbound/items`,
{
method: "POST",
headers,
body,
query,
}
)
}
async updateOutboundItem(
id: string,
actionId: string,
body: HttpTypes.AdminUpdateClaimOutboundItem,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/outbound/items/${actionId}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async removeOutboundItem(
id: string,
actionId: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/outbound/items/${actionId}`,
{
method: "DELETE",
headers,
query,
}
)
}
async addOutboundShipping(
id: string,
body: HttpTypes.AdminClaimAddOutboundShipping,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/outbound/shipping-method`,
{
method: "POST",
headers,
body,
query,
}
)
}
async updateOutboundShipping(
id: string,
actionId: string,
body: HttpTypes.AdminClaimUpdateOutboundShipping,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/outbound/shipping-method/${actionId}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async deleteOutboundShipping(
id: string,
actionId: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/outbound/shipping-method/${actionId}`,
{
method: "DELETE",
headers,
query,
}
)
}
async request(
id: string,
body: HttpTypes.AdminRequestClaim,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/request`,
{
method: "POST",
headers,
body,
query,
}
)
}
async cancelRequest(
id: string,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminClaimResponse>(
`/admin/claims/${id}/request`,
{
method: "DELETE",
headers,
query,
}
)
}
}
+3
View File
@@ -27,6 +27,7 @@ import { TaxRate } from "./tax-rate"
import { TaxRegion } from "./tax-region"
import { Upload } from "./upload"
import { User } from "./user"
import { Claim } from "./claim"
export class Admin {
public invite: Invite
@@ -51,6 +52,7 @@ export class Admin {
public notification: Notification
public order: Order
public return: Return
public claim: Claim
public taxRate: TaxRate
public taxRegion: TaxRegion
public store: Store
@@ -81,6 +83,7 @@ export class Admin {
this.notification = new Notification(client)
this.order = new Order(client)
this.return = new Return(client)
this.claim = new Claim(client)
this.taxRate = new TaxRate(client)
this.taxRegion = new TaxRegion(client)
this.store = new Store(client)
@@ -0,0 +1,3 @@
import { BaseClaim } from "../common"
export interface AdminClaim extends BaseClaim {}
@@ -0,0 +1,4 @@
export * from "./entities"
export * from "./payloads"
export * from "./queries"
export * from "./responses"
@@ -0,0 +1,72 @@
enum ClaimReason {
MISSING_ITEM = "missing_item",
WRONG_ITEM = "wrong_item",
PRODUCTION_FAILURE = "production_failure",
OTHER = "other",
}
interface AdminClaimAddItems {
items: {
id: string
quantity: number
reason?: ClaimReason
description?: string
internal_note?: string
}[]
}
interface AdminClaimUpdateItem {
quantity?: number
reason_id?: ClaimReason
description?: string
internal_note?: string
}
interface AdminClaimAddShippingMethod {
shipping_option_id: string
custom_price?: number
description?: string
internal_note?: string
metadata?: Record<string, unknown> | null
}
interface AdminClaimUpdateShippingMethod {
custom_price?: number
internal_note?: string
metadata?: Record<string, unknown> | null
}
export interface AdminCreateClaim {
type: "refund" | "replace"
order_id: string
description?: string
internal_note?: string
metadata?: Record<string, unknown> | null
}
export interface AdminAddClaimItems extends AdminClaimAddItems {}
export interface AdminUpdateClaimItem extends AdminClaimUpdateItem {}
export interface AdminAddClaimInboundItems extends AdminClaimAddItems {}
export interface AdminUpdateClaimInboundItem extends AdminClaimUpdateItem {}
export interface AdminAddClaimOutboundItems extends AdminClaimAddItems {}
export interface AdminUpdateClaimOutboundItem extends AdminClaimUpdateItem {}
export interface AdminClaimAddInboundShipping
extends AdminClaimAddShippingMethod {}
export interface AdminClaimUpdateInboundShipping
extends AdminClaimUpdateShippingMethod {}
export interface AdminClaimAddOutboundShipping
extends AdminClaimAddShippingMethod {}
export interface AdminClaimUpdateOutboundShipping
extends AdminClaimUpdateShippingMethod {}
export interface AdminRequestClaim {
// no_notification?: boolean // TODO: add in the API
}
export interface AdminCancelClaim {
no_notification?: boolean
}
@@ -0,0 +1,17 @@
import { BaseFilterable, OperatorMap } from "../../../dal"
import { SelectParams } from "../../common"
import { BaseClaimListParams } from "../common"
export interface AdminClaimListParams
extends BaseClaimListParams,
BaseFilterable<AdminClaimListParams> {
deleted_at?: OperatorMap<string>
}
export interface AdminClaimParams extends SelectParams {
id?: string | string[]
status?: string | string[]
created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
deleted_at?: OperatorMap<string>
}
@@ -0,0 +1,13 @@
import { DeleteResponse, PaginatedResponse } from "../../common"
import { AdminClaim } from "./entities"
export interface AdminClaimResponse {
claim: AdminClaim
}
export interface AdminClaimListResponse
extends PaginatedResponse<{
claims: AdminClaim[]
}> {}
export interface AdminClaimDeleteResponse extends DeleteResponse<"claim"> {}
@@ -0,0 +1,39 @@
import { OperatorMap } from "../../dal"
import { FindParams } from "../common"
import { ClaimReason, ReturnDTO } from "../../order"
import { BaseOrder } from "../order/common"
import { BigNumberRawValue } from "../../totals"
export interface BaseClaimItem {
id: string
claim_id: string
order_id: string
item_id: string
quantity: number
reason: ClaimReason
raw_quantity: BigNumberRawValue
metadata?: Record<string, unknown> | null
created_at?: Date | string
updated_at?: Date | string
}
export interface BaseClaim
extends Omit<BaseOrder, "status" | "version" | "items"> {
order_id: string
claim_items: BaseClaimItem
additional_items: any[]
return?: ReturnDTO
return_id?: string
no_notification?: boolean
refund_amount?: number
}
export interface BaseClaimListParams extends FindParams {
q?: string
id?: string | string[]
order_id?: string | string[]
status?: string | string[]
created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
deleted_at?: OperatorMap<string>
}
@@ -0,0 +1 @@
export * from "./admin"
+1
View File
@@ -1,6 +1,7 @@
export * from "./api-key"
export * from "./campaign"
export * from "./cart"
export * from "./claim"
export * from "./collection"
export * from "./common"
export * from "./currency"