chore: Remove last trace of client in dashboard (#8873)
This commit is contained in:
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
|
||||
import { useCustomer } from "../../../hooks/api/customers"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { getStylizedAmount } from "../../../lib/money-amount-helpers"
|
||||
import {
|
||||
getOrderFulfillmentStatus,
|
||||
@@ -74,7 +74,7 @@ export const TransferOwnerShipForm = ({
|
||||
const { data, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({
|
||||
queryKey: ["customers", debouncedQuery],
|
||||
queryFn: async ({ pageParam = 0 }) => {
|
||||
const res = await client.customers.list({
|
||||
const res = await sdk.admin.customer.list({
|
||||
q: debouncedQuery,
|
||||
limit: 10,
|
||||
offset: pageParam,
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
AdminCampaignListResponse,
|
||||
AdminCampaignResponse,
|
||||
AdminCreateCampaign,
|
||||
AdminUpdateCampaign,
|
||||
LinkMethodRequest,
|
||||
} from "@medusajs/types"
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
@@ -12,23 +6,23 @@ import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
import { client } from "../../lib/client"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { CampaignDeleteRes } from "../../types/api-responses"
|
||||
import { promotionsQueryKeys } from "./promotions"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
|
||||
const REGIONS_QUERY_KEY = "campaigns" as const
|
||||
export const campaignsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
|
||||
|
||||
export const useCampaign = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminGetCampaignParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
AdminCampaignResponse,
|
||||
Error,
|
||||
AdminCampaignResponse,
|
||||
HttpTypes.AdminCampaignResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCampaignResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
@@ -36,7 +30,7 @@ export const useCampaign = (
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: campaignsQueryKeys.detail(id),
|
||||
queryFn: async () => client.campaigns.retrieve(id, query),
|
||||
queryFn: async () => sdk.admin.campaign.retrieve(id, query),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -44,19 +38,19 @@ export const useCampaign = (
|
||||
}
|
||||
|
||||
export const useCampaigns = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminGetCampaignsParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
AdminCampaignListResponse,
|
||||
Error,
|
||||
AdminCampaignListResponse,
|
||||
HttpTypes.AdminCampaignListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCampaignListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.campaigns.list(query),
|
||||
queryFn: () => sdk.admin.campaign.list(query),
|
||||
queryKey: campaignsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
@@ -66,13 +60,13 @@ export const useCampaigns = (
|
||||
|
||||
export const useCreateCampaign = (
|
||||
options?: UseMutationOptions<
|
||||
AdminCampaignResponse,
|
||||
Error,
|
||||
AdminCreateCampaign
|
||||
HttpTypes.AdminCampaignResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateCampaign
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.campaigns.create(payload),
|
||||
mutationFn: (payload) => sdk.admin.campaign.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
@@ -84,13 +78,13 @@ export const useCreateCampaign = (
|
||||
export const useUpdateCampaign = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
AdminCampaignResponse,
|
||||
Error,
|
||||
AdminUpdateCampaign
|
||||
HttpTypes.AdminCampaignResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateCampaign
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.campaigns.update(id, payload),
|
||||
mutationFn: (payload) => sdk.admin.campaign.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||
@@ -103,10 +97,14 @@ export const useUpdateCampaign = (
|
||||
|
||||
export const useDeleteCampaign = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<CampaignDeleteRes, Error, void>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.DeleteResponse<"campaign">,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.campaigns.delete(id),
|
||||
mutationFn: () => sdk.admin.campaign.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||
@@ -119,11 +117,14 @@ export const useDeleteCampaign = (
|
||||
|
||||
export const useAddOrRemoveCampaignPromotions = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<AdminCampaignResponse, Error, LinkMethodRequest>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminCampaignResponse,
|
||||
FetchError,
|
||||
LinkMethodRequest
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.campaigns.addOrRemovePromotions(id, payload),
|
||||
mutationFn: (payload) => sdk.admin.campaign.batchPromotions(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { AdminGetPromotionsParams } from "@medusajs/medusa"
|
||||
import {
|
||||
AdminPromotionRuleListResponse,
|
||||
AdminRuleAttributeOptionsListResponse,
|
||||
AdminRuleValueOptionsListResponse,
|
||||
} from "@medusajs/types"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import {
|
||||
QueryKey,
|
||||
useMutation,
|
||||
@@ -11,21 +7,9 @@ import {
|
||||
useQuery,
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
import { client } from "../../lib/client"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import {
|
||||
BatchAddPromotionRulesReq,
|
||||
BatchRemovePromotionRulesReq,
|
||||
BatchUpdatePromotionRulesReq,
|
||||
CreatePromotionReq,
|
||||
UpdatePromotionReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
PromotionDeleteRes,
|
||||
PromotionListRes,
|
||||
PromotionRes,
|
||||
} from "../../types/api-responses"
|
||||
import { campaignsQueryKeys } from "./campaigns"
|
||||
|
||||
const PROMOTIONS_QUERY_KEY = "promotions" as const
|
||||
@@ -35,31 +19,35 @@ export const promotionsQueryKeys = {
|
||||
listRules: (
|
||||
id: string | null,
|
||||
ruleType: string,
|
||||
query?: Record<string, string>
|
||||
query?: HttpTypes.AdminGetPromotionRuleParams
|
||||
) => [PROMOTIONS_QUERY_KEY, id, ruleType, query],
|
||||
listRuleAttributes: (ruleType: string, promotionType?: string) => [
|
||||
PROMOTIONS_QUERY_KEY,
|
||||
ruleType,
|
||||
promotionType,
|
||||
],
|
||||
listRuleValues: (ruleType: string, ruleValue: string, query: object) => [
|
||||
PROMOTIONS_QUERY_KEY,
|
||||
ruleType,
|
||||
ruleValue,
|
||||
query,
|
||||
],
|
||||
listRuleValues: (
|
||||
ruleType: string,
|
||||
ruleValue: string,
|
||||
query: HttpTypes.AdminGetPromotionsRuleValueParams
|
||||
) => [PROMOTIONS_QUERY_KEY, ruleType, ruleValue, query],
|
||||
}
|
||||
|
||||
export const usePromotion = (
|
||||
id: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<PromotionRes, Error, PromotionRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: promotionsQueryKeys.detail(id),
|
||||
queryFn: async () => client.promotions.retrieve(id),
|
||||
queryFn: async () => sdk.admin.promotion.retrieve(id),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -69,12 +57,12 @@ export const usePromotion = (
|
||||
export const usePromotionRules = (
|
||||
id: string | null,
|
||||
ruleType: string,
|
||||
query?: Record<string, string>,
|
||||
query?: HttpTypes.AdminGetPromotionRuleParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
AdminPromotionRuleListResponse,
|
||||
Error,
|
||||
AdminPromotionRuleListResponse,
|
||||
HttpTypes.AdminGetPromotionRuleParams,
|
||||
FetchError,
|
||||
HttpTypes.AdminPromotionRuleListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
@@ -82,7 +70,7 @@ export const usePromotionRules = (
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: promotionsQueryKeys.listRules(id, ruleType, query),
|
||||
queryFn: async () => client.promotions.listRules(id, ruleType, query),
|
||||
queryFn: async () => sdk.admin.promotion.listRules(id, ruleType, query),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -90,15 +78,20 @@ export const usePromotionRules = (
|
||||
}
|
||||
|
||||
export const usePromotions = (
|
||||
query?: AdminGetPromotionsParams,
|
||||
query?: HttpTypes.AdminGetPromotionsParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<PromotionListRes, Error, PromotionListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminPromotionListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminPromotionListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: promotionsQueryKeys.list(query),
|
||||
queryFn: async () => client.promotions.list(query),
|
||||
queryFn: async () => sdk.admin.promotion.list(query),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -110,9 +103,9 @@ export const usePromotionRuleAttributes = (
|
||||
promotionType?: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
AdminRuleAttributeOptionsListResponse,
|
||||
Error,
|
||||
AdminRuleAttributeOptionsListResponse,
|
||||
HttpTypes.AdminRuleAttributeOptionsListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminRuleAttributeOptionsListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
@@ -121,7 +114,7 @@ export const usePromotionRuleAttributes = (
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: promotionsQueryKeys.listRuleAttributes(ruleType, promotionType),
|
||||
queryFn: async () =>
|
||||
client.promotions.listRuleAttributes(ruleType, promotionType),
|
||||
sdk.admin.promotion.listRuleAttributes(ruleType, promotionType),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -131,12 +124,12 @@ export const usePromotionRuleAttributes = (
|
||||
export const usePromotionRuleValues = (
|
||||
ruleType: string,
|
||||
ruleValue: string,
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminGetPromotionsRuleValueParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
AdminRuleValueOptionsListResponse,
|
||||
Error,
|
||||
AdminRuleValueOptionsListResponse,
|
||||
HttpTypes.AdminRuleValueOptionsListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminRuleValueOptionsListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
@@ -149,7 +142,7 @@ export const usePromotionRuleValues = (
|
||||
query || {}
|
||||
),
|
||||
queryFn: async () =>
|
||||
client.promotions.listRuleValues(ruleType, ruleValue, query),
|
||||
sdk.admin.promotion.listRuleValues(ruleType, ruleValue, query),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -158,10 +151,14 @@ export const usePromotionRuleValues = (
|
||||
|
||||
export const useDeletePromotion = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<PromotionDeleteRes, Error, void>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.DeleteResponse<"promotion">,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.promotions.delete(id),
|
||||
mutationFn: () => sdk.admin.promotion.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
@@ -175,10 +172,14 @@ export const useDeletePromotion = (
|
||||
}
|
||||
|
||||
export const useCreatePromotion = (
|
||||
options?: UseMutationOptions<PromotionRes, Error, CreatePromotionReq>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreatePromotion
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.promotions.create(payload),
|
||||
mutationFn: (payload) => sdk.admin.promotion.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
|
||||
@@ -190,10 +191,14 @@ export const useCreatePromotion = (
|
||||
|
||||
export const useUpdatePromotion = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<PromotionRes, Error, UpdatePromotionReq>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdatePromotion
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.promotions.update(id, payload),
|
||||
mutationFn: (payload) => sdk.admin.promotion.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||
|
||||
@@ -206,10 +211,15 @@ export const useUpdatePromotion = (
|
||||
export const usePromotionAddRules = (
|
||||
id: string,
|
||||
ruleType: string,
|
||||
options?: UseMutationOptions<PromotionRes, Error, BatchAddPromotionRulesReq>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
FetchError,
|
||||
HttpTypes.BatchAddPromotionRulesReq
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.promotions.addRules(id, ruleType, payload),
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.promotion.addRules(id, ruleType, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||
|
||||
@@ -223,14 +233,14 @@ export const usePromotionRemoveRules = (
|
||||
id: string,
|
||||
ruleType: string,
|
||||
options?: UseMutationOptions<
|
||||
PromotionRes,
|
||||
Error,
|
||||
BatchRemovePromotionRulesReq
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
FetchError,
|
||||
HttpTypes.BatchRemovePromotionRulesReq
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.promotions.removeRules(id, ruleType, payload),
|
||||
sdk.admin.promotion.removeRules(id, ruleType, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||
|
||||
@@ -244,14 +254,14 @@ export const usePromotionUpdateRules = (
|
||||
id: string,
|
||||
ruleType: string,
|
||||
options?: UseMutationOptions<
|
||||
PromotionRes,
|
||||
Error,
|
||||
BatchUpdatePromotionRulesReq
|
||||
HttpTypes.AdminPromotionResponse,
|
||||
FetchError,
|
||||
HttpTypes.BatchUpdatePromotionRulesReq
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.promotions.updateRules(id, ruleType, payload),
|
||||
sdk.admin.promotion.updateRules(id, ruleType, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.all })
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import {
|
||||
AdminCampaignListResponse,
|
||||
AdminCampaignResponse,
|
||||
AdminCreateCampaign,
|
||||
AdminUpdateCampaign,
|
||||
LinkMethodRequest,
|
||||
} from "@medusajs/types"
|
||||
import { CampaignDeleteRes } from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
async function retrieveCampaign(id: string, query?: Record<string, any>) {
|
||||
return getRequest<AdminCampaignResponse>(`/admin/campaigns/${id}`, query)
|
||||
}
|
||||
|
||||
async function listCampaigns(query?: Record<string, any>) {
|
||||
return getRequest<AdminCampaignListResponse>(`/admin/campaigns`, query)
|
||||
}
|
||||
|
||||
async function createCampaign(payload: AdminCreateCampaign) {
|
||||
return postRequest<AdminCampaignResponse>(`/admin/campaigns`, payload)
|
||||
}
|
||||
|
||||
async function updateCampaign(id: string, payload: AdminUpdateCampaign) {
|
||||
return postRequest<AdminCampaignResponse>(`/admin/campaigns/${id}`, payload)
|
||||
}
|
||||
|
||||
async function deleteCampaign(id: string) {
|
||||
return deleteRequest<CampaignDeleteRes>(`/admin/campaigns/${id}`)
|
||||
}
|
||||
|
||||
async function addOrRemoveCampaignPromotions(
|
||||
id: string,
|
||||
payload: LinkMethodRequest
|
||||
) {
|
||||
return postRequest<AdminCampaignResponse>(
|
||||
`/admin/campaigns/${id}/promotions`,
|
||||
payload
|
||||
)
|
||||
}
|
||||
|
||||
export const campaigns = {
|
||||
retrieve: retrieveCampaign,
|
||||
list: listCampaigns,
|
||||
create: createCampaign,
|
||||
update: updateCampaign,
|
||||
delete: deleteCampaign,
|
||||
addOrRemovePromotions: addOrRemoveCampaignPromotions,
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import {
|
||||
AdminProductCategoryListResponse,
|
||||
AdminProductCategoryResponse,
|
||||
} from "@medusajs/types"
|
||||
import { getRequest } from "./common"
|
||||
|
||||
async function listProductCategories(query?: Record<string, any>) {
|
||||
return getRequest<AdminProductCategoryListResponse>(
|
||||
`/admin/product-categories`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function retrieveProductCategory(
|
||||
id: string,
|
||||
query?: Record<string, any>
|
||||
) {
|
||||
return getRequest<AdminProductCategoryResponse>(
|
||||
`/admin/product-categories/${id}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
export const categories = {
|
||||
list: listProductCategories,
|
||||
retrieve: retrieveProductCategory,
|
||||
}
|
||||
@@ -1,16 +1,7 @@
|
||||
import Medusa from "@medusajs/js-sdk"
|
||||
import { campaigns } from "./campaigns"
|
||||
import { categories } from "./categories"
|
||||
import { promotions } from "./promotions"
|
||||
|
||||
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
||||
|
||||
export const client = {
|
||||
campaigns: campaigns,
|
||||
categories: categories,
|
||||
promotions: promotions,
|
||||
}
|
||||
|
||||
export const sdk = new Medusa({
|
||||
baseUrl: backendUrl,
|
||||
auth: {
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
import { stringify } from "qs"
|
||||
|
||||
const baseUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
||||
|
||||
const commonHeaders: HeadersInit = {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
function getUrl(path: string, query?: Record<string, any>) {
|
||||
const params = query ? stringify(query) : null
|
||||
|
||||
return `${baseUrl}${path}${params ? `?${params}` : ""}`
|
||||
}
|
||||
|
||||
function getBody(payload?: Record<string, any>) {
|
||||
return payload ? JSON.stringify(payload) : undefined
|
||||
}
|
||||
|
||||
function getOptions(
|
||||
options?: Omit<RequestInit, "body">,
|
||||
payload?: Record<string, any>
|
||||
): RequestInit {
|
||||
const body = getBody(payload)
|
||||
|
||||
return {
|
||||
...options,
|
||||
headers: {
|
||||
...commonHeaders,
|
||||
...options?.headers,
|
||||
},
|
||||
body,
|
||||
credentials: "include",
|
||||
}
|
||||
}
|
||||
|
||||
async function makeRequest<
|
||||
TRes,
|
||||
TPayload extends Record<string, any> | undefined,
|
||||
TQuery extends Record<string, any> | undefined = undefined,
|
||||
>(
|
||||
path: string,
|
||||
payload?: TPayload,
|
||||
query?: TQuery,
|
||||
options?: Omit<RequestInit, "body">
|
||||
): Promise<TRes> {
|
||||
const url = getUrl(path, query)
|
||||
const requestOptions = getOptions(options, payload)
|
||||
|
||||
const response = await fetch(url, requestOptions)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json()
|
||||
|
||||
// Temp: Add a better error type
|
||||
throw new Error(`API error ${response.status}: ${errorData.message}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function getRequest<
|
||||
TRes,
|
||||
TQuery extends Record<string, any> | undefined = {},
|
||||
>(
|
||||
path: string,
|
||||
query?: TQuery,
|
||||
options?: Omit<RequestInit, "body" | "method">
|
||||
): Promise<TRes> {
|
||||
return makeRequest<TRes, undefined, Record<string, any>>(
|
||||
path,
|
||||
undefined,
|
||||
query,
|
||||
{
|
||||
...options,
|
||||
method: "GET",
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export async function postRequest<
|
||||
TRes,
|
||||
TPayload extends Record<string, any> | undefined = {},
|
||||
>(
|
||||
path: string,
|
||||
payload?: TPayload,
|
||||
options?: Omit<RequestInit, "body" | "method">
|
||||
): Promise<TRes> {
|
||||
return makeRequest<TRes, Record<string, any>, undefined>(
|
||||
path,
|
||||
payload,
|
||||
undefined,
|
||||
{
|
||||
...options,
|
||||
method: "POST",
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export async function deleteRequest<TRes>(
|
||||
path: string,
|
||||
options?: Omit<RequestInit, "body" | "method">
|
||||
): Promise<TRes> {
|
||||
return makeRequest<TRes, undefined, undefined>(path, undefined, undefined, {
|
||||
...options,
|
||||
method: "DELETE",
|
||||
})
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
import {
|
||||
AdminGetPromotionsParams,
|
||||
AdminGetPromotionsRuleValueParams,
|
||||
} from "@medusajs/medusa"
|
||||
import { AdminRuleValueOptionsListResponse } from "@medusajs/types"
|
||||
import {
|
||||
BatchAddPromotionRulesReq,
|
||||
BatchRemovePromotionRulesReq,
|
||||
BatchUpdatePromotionRulesReq,
|
||||
CreatePromotionReq,
|
||||
UpdatePromotionReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
PromotionDeleteRes,
|
||||
PromotionListRes,
|
||||
PromotionRes,
|
||||
PromotionRuleAttributesListRes,
|
||||
} from "../../types/api-responses"
|
||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||
|
||||
async function retrievePromotion(id: string, query?: AdminGetPromotionsParams) {
|
||||
return getRequest<PromotionRes, AdminGetPromotionsParams>(
|
||||
`/admin/promotions/${id}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotions(query?: AdminGetPromotionsParams) {
|
||||
return getRequest<PromotionListRes>(`/admin/promotions`, query)
|
||||
}
|
||||
|
||||
async function deletePromotion(id: string) {
|
||||
return deleteRequest<PromotionDeleteRes>(`/admin/promotions/${id}`)
|
||||
}
|
||||
|
||||
async function updatePromotion(id: string, payload: UpdatePromotionReq) {
|
||||
return postRequest<PromotionRes>(`/admin/promotions/${id}`, payload)
|
||||
}
|
||||
|
||||
async function createPromotion(payload: CreatePromotionReq) {
|
||||
return postRequest<PromotionRes>(`/admin/promotions`, payload)
|
||||
}
|
||||
|
||||
async function addPromotionRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: BatchAddPromotionRulesReq
|
||||
) {
|
||||
return postRequest<PromotionRes>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||
{
|
||||
create: payload.rules,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async function updatePromotionRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: BatchUpdatePromotionRulesReq
|
||||
) {
|
||||
return postRequest<PromotionRes>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||
{
|
||||
update: payload.rules,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async function removePromotionRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: BatchRemovePromotionRulesReq
|
||||
) {
|
||||
return postRequest<PromotionRes>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||
{
|
||||
delete: payload.rule_ids,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRules(
|
||||
id: string | null,
|
||||
ruleType: string,
|
||||
query?: Record<string, string>
|
||||
) {
|
||||
return getRequest<PromotionRuleAttributesListRes>(
|
||||
`/admin/promotions/${id}/${ruleType}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRuleAttributes(
|
||||
ruleType: string,
|
||||
promotionType?: string
|
||||
) {
|
||||
return getRequest<PromotionRuleAttributesListRes>(
|
||||
`/admin/promotions/rule-attribute-options/${ruleType}?promotion_type=${promotionType}`
|
||||
)
|
||||
}
|
||||
|
||||
async function listPromotionRuleValues(
|
||||
ruleType: string,
|
||||
ruleValue: string,
|
||||
query?: AdminGetPromotionsRuleValueParams
|
||||
) {
|
||||
return getRequest<AdminRuleValueOptionsListResponse>(
|
||||
`/admin/promotions/rule-value-options/${ruleType}/${ruleValue}`,
|
||||
query
|
||||
)
|
||||
}
|
||||
|
||||
export const promotions = {
|
||||
retrieve: retrievePromotion,
|
||||
list: listPromotions,
|
||||
delete: deletePromotion,
|
||||
update: updatePromotion,
|
||||
create: createPromotion,
|
||||
addRules: addPromotionRules,
|
||||
removeRules: removePromotionRules,
|
||||
updateRules: updatePromotionRules,
|
||||
listRules: listPromotionRules,
|
||||
listRuleAttributes: listPromotionRuleAttributes,
|
||||
listRuleValues: listPromotionRuleValues,
|
||||
}
|
||||
@@ -2,13 +2,13 @@ import { AdminCampaignResponse } from "@medusajs/types"
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
|
||||
import { campaignsQueryKeys } from "../../../hooks/api/campaigns"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
|
||||
const campaignDetailQuery = (id: string) => ({
|
||||
queryKey: campaignsQueryKeys.detail(id),
|
||||
queryFn: async () =>
|
||||
client.campaigns.retrieve(id, {
|
||||
sdk.admin.campaign.retrieve(id, {
|
||||
fields: "+promotions.id",
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,12 +2,12 @@ import { AdminProductCategoryResponse } from "@medusajs/types"
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
|
||||
import { categoriesQueryKeys } from "../../../hooks/api/categories"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
|
||||
const categoryDetailQuery = (id: string) => ({
|
||||
queryKey: categoriesQueryKeys.detail(id),
|
||||
queryFn: async () => client.categories.retrieve(id),
|
||||
queryFn: async () => sdk.admin.productCategory.retrieve(id),
|
||||
})
|
||||
|
||||
export const categoryLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||
|
||||
@@ -26,7 +26,7 @@ import { useCustomerGroupTableColumns } from "../../../../../hooks/table/columns
|
||||
import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters.tsx"
|
||||
import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query.tsx"
|
||||
import { useDataTable } from "../../../../../hooks/use-data-table.tsx"
|
||||
import { client, sdk } from "../../../../../lib/client/index.ts"
|
||||
import { sdk } from "../../../../../lib/client/index.ts"
|
||||
import { queryClient } from "../../../../../lib/query-client.ts"
|
||||
|
||||
type CustomerGroupSectionProps = {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { LoaderFunctionArgs } from "react-router-dom"
|
||||
import { promotionsQueryKeys } from "../../../hooks/api/promotions"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
import { PromotionRes } from "../../../types/api-responses"
|
||||
|
||||
const promotionDetailQuery = (id: string) => ({
|
||||
queryKey: promotionsQueryKeys.detail(id),
|
||||
queryFn: async () => client.promotions.retrieve(id),
|
||||
queryFn: async () => sdk.admin.promotion.retrieve(id),
|
||||
})
|
||||
|
||||
export const promotionLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { QueryClient } from "@tanstack/react-query"
|
||||
import { promotionsQueryKeys } from "../../../hooks/api/promotions"
|
||||
import { client } from "../../../lib/client"
|
||||
import { sdk } from "../../../lib/client"
|
||||
import { queryClient } from "../../../lib/query-client"
|
||||
import { PromotionListRes } from "../../../types/api-responses"
|
||||
|
||||
@@ -11,7 +11,7 @@ const params = {
|
||||
|
||||
const promotionsListQuery = () => ({
|
||||
queryKey: promotionsQueryKeys.list(params),
|
||||
queryFn: async () => client.promotions.list(params),
|
||||
queryFn: async () => sdk.admin.promotion.list(params),
|
||||
})
|
||||
|
||||
export const promotionsLoader = (client: QueryClient) => {
|
||||
|
||||
91
packages/core/js-sdk/src/admin/campaign.ts
Normal file
91
packages/core/js-sdk/src/admin/campaign.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
export class Campaign {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminGetCampaignParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||
`/admin/campaigns/${id}`,
|
||||
{
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminGetCampaignsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCampaignListResponse>(
|
||||
`/admin/campaigns`,
|
||||
{
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async create(
|
||||
payload: HttpTypes.AdminCreateCampaign,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||
`/admin/campaigns`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: payload,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
payload: HttpTypes.AdminUpdateCampaign,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||
`/admin/campaigns/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: payload,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"campaign">>(
|
||||
`/admin/campaigns/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async batchPromotions(
|
||||
id: string,
|
||||
payload: HttpTypes.AdminBatchLink,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminCampaignResponse>(
|
||||
`/admin/campaigns/${id}/promotions`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: payload,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Client } from "../client"
|
||||
import { ApiKey } from "./api-key"
|
||||
import { Campaign } from "./campaign"
|
||||
import { Claim } from "./claim"
|
||||
import { Currency } from "./currency"
|
||||
import { Customer } from "./customer"
|
||||
@@ -23,6 +24,7 @@ import { ProductCollection } from "./product-collection"
|
||||
import { ProductTag } from "./product-tag"
|
||||
import { ProductType } from "./product-type"
|
||||
import { ProductVariant } from "./product-variant"
|
||||
import { Promotion } from "./promotion"
|
||||
import { RefundReason } from "./refund-reasons"
|
||||
import { Region } from "./region"
|
||||
import Reservation from "./reservation"
|
||||
@@ -79,6 +81,8 @@ export class Admin {
|
||||
public workflowExecution: WorkflowExecution
|
||||
public reservation: Reservation
|
||||
public customerGroup: CustomerGroup
|
||||
public promotion: Promotion
|
||||
public campaign: Campaign
|
||||
|
||||
constructor(client: Client) {
|
||||
this.invite = new Invite(client)
|
||||
@@ -120,5 +124,7 @@ export class Admin {
|
||||
this.workflowExecution = new WorkflowExecution(client)
|
||||
this.reservation = new Reservation(client)
|
||||
this.customerGroup = new CustomerGroup(client)
|
||||
this.promotion = new Promotion(client)
|
||||
this.campaign = new Campaign(client)
|
||||
}
|
||||
}
|
||||
|
||||
170
packages/core/js-sdk/src/admin/promotion.ts
Normal file
170
packages/core/js-sdk/src/admin/promotion.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
export class Promotion {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminGetPromotionParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||
`/admin/promotions/${id}`,
|
||||
{
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminGetPromotionsParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionListResponse>(
|
||||
`/admin/promotions`,
|
||||
{
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async create(
|
||||
payload: HttpTypes.AdminCreatePromotion,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||
`/admin/promotions`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: payload,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
payload: HttpTypes.AdminUpdatePromotion,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||
`/admin/promotions/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: payload,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"promotion">>(
|
||||
`/admin/promotions/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async addRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: HttpTypes.BatchAddPromotionRulesReq,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: { create: payload.rules },
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async updateRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: HttpTypes.BatchUpdatePromotionRulesReq,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: { update: payload.rules },
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async removeRules(
|
||||
id: string,
|
||||
ruleType: string,
|
||||
payload: HttpTypes.BatchRemovePromotionRulesReq,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminPromotionResponse>(
|
||||
`/admin/promotions/${id}/${ruleType}/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: { delete: payload.rule_ids },
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async listRules(
|
||||
id: string | null,
|
||||
ruleType: string,
|
||||
query?: HttpTypes.AdminGetPromotionRuleParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
// eslint-disable-next-line max-len
|
||||
return await this.client.fetch<HttpTypes.AdminRuleAttributeOptionsListResponse>(
|
||||
`/admin/promotions/${id}/${ruleType}`,
|
||||
{
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async listRuleAttributes(
|
||||
ruleType: string,
|
||||
promotionType?: string,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
// eslint-disable-next-line max-len
|
||||
return await this.client.fetch<HttpTypes.AdminRuleAttributeOptionsListResponse>(
|
||||
`/admin/promotions/rule-attribute-options/${ruleType}`,
|
||||
{
|
||||
headers,
|
||||
query: { promotion_type: promotionType },
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async listRuleValues(
|
||||
ruleType: string,
|
||||
ruleValue: string,
|
||||
query?: HttpTypes.AdminGetPromotionsRuleValueParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminRuleValueOptionsListResponse>(
|
||||
`/admin/promotions/rule-value-options/${ruleType}/${ruleValue}`,
|
||||
{
|
||||
headers,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
|
||||
|
||||
16
packages/core/types/src/http/campaign/admin/queries.ts
Normal file
16
packages/core/types/src/http/campaign/admin/queries.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { BaseFilterable } from "../../../dal"
|
||||
import { FindParams, SelectParams } from "../../common"
|
||||
|
||||
export interface AdminGetCampaignsParams
|
||||
extends FindParams,
|
||||
BaseFilterable<AdminGetCampaignsParams> {
|
||||
q?: string
|
||||
campaign_identifier?: string
|
||||
budget?: {
|
||||
currency_code?: string
|
||||
}
|
||||
$and?: AdminGetCampaignsParams[]
|
||||
$or?: AdminGetCampaignsParams[]
|
||||
}
|
||||
|
||||
export interface AdminGetCampaignParams extends SelectParams {}
|
||||
@@ -5,7 +5,8 @@ import {
|
||||
} from "../common"
|
||||
|
||||
export interface AdminCustomerFilters extends BaseCustomerFilters {
|
||||
groups: CustomerGroupInCustomerFilters | string[] | string
|
||||
groups?: CustomerGroupInCustomerFilters | string[] | string
|
||||
has_account?: boolean
|
||||
}
|
||||
export interface AdminCustomerAddressFilters
|
||||
extends BaseCustomerAddressFilters {}
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./responses"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
|
||||
83
packages/core/types/src/http/promotion/admin/payloads.ts
Normal file
83
packages/core/types/src/http/promotion/admin/payloads.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
ApplicationMethodAllocationValues,
|
||||
ApplicationMethodTargetTypeValues,
|
||||
ApplicationMethodTypeValues,
|
||||
PromotionRuleOperatorValues,
|
||||
PromotionTypeValues,
|
||||
} from "../../../promotion"
|
||||
import { AdminCreateCampaign } from "../../campaign"
|
||||
|
||||
export interface AdminCreatePromotionRule {
|
||||
operator: PromotionRuleOperatorValues
|
||||
description?: string | null
|
||||
attribute: string
|
||||
values: string | string[]
|
||||
}
|
||||
|
||||
export interface AdminUpdatePromotionRule {
|
||||
id: string
|
||||
operator?: PromotionRuleOperatorValues
|
||||
description?: string | null
|
||||
attribute?: string
|
||||
values: string | string[]
|
||||
}
|
||||
|
||||
export interface AdminCreateApplicationMethod {
|
||||
description?: string | null
|
||||
value: number
|
||||
currency_code?: string | null
|
||||
max_quantity?: number | null
|
||||
type: ApplicationMethodTypeValues
|
||||
target_type: ApplicationMethodTargetTypeValues
|
||||
allocation?: ApplicationMethodAllocationValues
|
||||
target_rules?: AdminCreatePromotionRule[]
|
||||
buy_rules?: AdminCreatePromotionRule[]
|
||||
apply_to_quantity?: number | null
|
||||
buy_rules_min_quantity?: number | null
|
||||
}
|
||||
|
||||
export interface AdminUpdateApplicationMethod {
|
||||
description?: string | null
|
||||
value?: number
|
||||
max_quantity?: number | null
|
||||
currency_code?: string | null
|
||||
type?: ApplicationMethodTypeValues
|
||||
target_type?: ApplicationMethodTargetTypeValues
|
||||
allocation?: ApplicationMethodAllocationValues
|
||||
target_rules?: AdminCreatePromotionRule[]
|
||||
buy_rules?: AdminCreatePromotionRule[]
|
||||
apply_to_quantity?: number | null
|
||||
buy_rules_min_quantity?: number | null
|
||||
}
|
||||
|
||||
export interface AdminCreatePromotion {
|
||||
code: string
|
||||
is_automatic?: boolean
|
||||
type: PromotionTypeValues
|
||||
campaign_id?: string | null
|
||||
campaign?: AdminCreateCampaign
|
||||
application_method: AdminCreateApplicationMethod
|
||||
rules?: AdminCreatePromotionRule[]
|
||||
}
|
||||
|
||||
export interface AdminUpdatePromotion {
|
||||
code?: string
|
||||
is_automatic?: boolean
|
||||
type?: PromotionTypeValues
|
||||
campaign_id?: string | null
|
||||
campaign?: AdminCreateCampaign
|
||||
application_method?: AdminUpdateApplicationMethod
|
||||
rules?: AdminCreatePromotionRule[]
|
||||
}
|
||||
|
||||
export interface BatchAddPromotionRulesReq {
|
||||
rules: AdminCreatePromotionRule[]
|
||||
}
|
||||
|
||||
export interface BatchRemovePromotionRulesReq {
|
||||
rule_ids: string[]
|
||||
}
|
||||
|
||||
export interface BatchUpdatePromotionRulesReq {
|
||||
rules: AdminUpdatePromotionRule[]
|
||||
}
|
||||
35
packages/core/types/src/http/promotion/admin/queries.ts
Normal file
35
packages/core/types/src/http/promotion/admin/queries.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { BaseFilterable, OperatorMap } from "../../../dal"
|
||||
import { FindParams, SelectParams } from "../../common"
|
||||
|
||||
export interface AdminGetPromotionParams extends SelectParams {}
|
||||
|
||||
export interface AdminGetPromotionsParams
|
||||
extends FindParams,
|
||||
BaseFilterable<AdminGetPromotionsParams> {
|
||||
q?: string
|
||||
code?: string | string[]
|
||||
campaign_id?: string | string[]
|
||||
application_method?: {
|
||||
currency_code?: string | string[]
|
||||
}
|
||||
created_at?: OperatorMap<string>
|
||||
updated_at?: OperatorMap<string>
|
||||
deleted_at?: OperatorMap<string>
|
||||
$and?: AdminGetPromotionsParams[]
|
||||
$or?: AdminGetPromotionsParams[]
|
||||
}
|
||||
|
||||
export interface AdminGetPromotionRuleParams {
|
||||
promotion_type?: string
|
||||
application_method_type?: string
|
||||
}
|
||||
|
||||
export interface AdminGetPromotionRuleTypeParams extends SelectParams {
|
||||
promotion_type?: string
|
||||
application_method_type?: string
|
||||
}
|
||||
|
||||
export interface AdminGetPromotionsRuleValueParams extends FindParams {
|
||||
q?: string
|
||||
value?: string | string[]
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user