feat: Update customer related typings and sdk methods (#7440)
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
import {
|
|
||||||
AdminCustomerGroupListResponse,
|
|
||||||
AdminCustomerGroupResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
UseMutationOptions,
|
UseMutationOptions,
|
||||||
@@ -16,6 +12,7 @@ import { queryKeysFactory } from "../../lib/query-key-factory"
|
|||||||
import { CreateCustomerGroupSchema } from "../../routes/customer-groups/customer-group-create/components/create-customer-group-form"
|
import { CreateCustomerGroupSchema } from "../../routes/customer-groups/customer-group-create/components/create-customer-group-form"
|
||||||
import { EditCustomerGroupSchema } from "../../routes/customer-groups/customer-group-edit/components/edit-customer-group-form"
|
import { EditCustomerGroupSchema } from "../../routes/customer-groups/customer-group-edit/components/edit-customer-group-form"
|
||||||
import { customersQueryKeys } from "./customers"
|
import { customersQueryKeys } from "./customers"
|
||||||
|
import { HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||||
|
|
||||||
const CUSTOMER_GROUPS_QUERY_KEY = "customer_groups" as const
|
const CUSTOMER_GROUPS_QUERY_KEY = "customer_groups" as const
|
||||||
export const customerGroupsQueryKeys = queryKeysFactory(
|
export const customerGroupsQueryKeys = queryKeysFactory(
|
||||||
@@ -27,9 +24,9 @@ export const useCustomerGroup = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminCustomerGroupResponse,
|
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||||
Error,
|
Error,
|
||||||
AdminCustomerGroupResponse,
|
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -48,9 +45,9 @@ export const useCustomerGroups = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminCustomerGroupListResponse,
|
PaginatedResponse<HttpTypes.AdminCustomerGroup[]>,
|
||||||
Error,
|
Error,
|
||||||
AdminCustomerGroupListResponse,
|
PaginatedResponse<HttpTypes.AdminCustomerGroup[]>,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -67,7 +64,7 @@ export const useCustomerGroups = (
|
|||||||
|
|
||||||
export const useCreateCustomerGroup = (
|
export const useCreateCustomerGroup = (
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminCustomerGroupResponse,
|
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||||
Error,
|
Error,
|
||||||
z.infer<typeof CreateCustomerGroupSchema>
|
z.infer<typeof CreateCustomerGroupSchema>
|
||||||
>
|
>
|
||||||
@@ -87,7 +84,7 @@ export const useCreateCustomerGroup = (
|
|||||||
export const useUpdateCustomerGroup = (
|
export const useUpdateCustomerGroup = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminCustomerGroupResponse,
|
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||||
Error,
|
Error,
|
||||||
z.infer<typeof EditCustomerGroupSchema>
|
z.infer<typeof EditCustomerGroupSchema>
|
||||||
>
|
>
|
||||||
@@ -135,7 +132,7 @@ export const useDeleteCustomerGroup = (
|
|||||||
export const useAddCustomersToGroup = (
|
export const useAddCustomersToGroup = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminCustomerGroupResponse,
|
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||||
Error,
|
Error,
|
||||||
{ customer_ids: string[] }
|
{ customer_ids: string[] }
|
||||||
>
|
>
|
||||||
@@ -162,7 +159,7 @@ export const useAddCustomersToGroup = (
|
|||||||
export const useRemoveCustomersFromGroup = (
|
export const useRemoveCustomersFromGroup = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminCustomerGroupResponse,
|
{ customer_group: HttpTypes.AdminCustomerGroup },
|
||||||
Error,
|
Error,
|
||||||
{ customer_ids: string[] }
|
{ customer_ids: string[] }
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { DeleteResponse, HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||||
AdminCustomerListResponse,
|
|
||||||
AdminCustomerResponse,
|
|
||||||
DeleteResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
QueryKey,
|
QueryKey,
|
||||||
UseMutationOptions,
|
UseMutationOptions,
|
||||||
@@ -10,10 +6,9 @@ import {
|
|||||||
useMutation,
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
} from "@tanstack/react-query"
|
} from "@tanstack/react-query"
|
||||||
import { client } from "../../lib/client"
|
import { sdk } from "../../lib/client"
|
||||||
import { queryClient } from "../../lib/query-client"
|
import { queryClient } from "../../lib/query-client"
|
||||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||||
import { CreateCustomerReq, UpdateCustomerReq } from "../../types/api-payloads"
|
|
||||||
|
|
||||||
const CUSTOMERS_QUERY_KEY = "customers" as const
|
const CUSTOMERS_QUERY_KEY = "customers" as const
|
||||||
export const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY)
|
export const customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY)
|
||||||
@@ -23,9 +18,9 @@ export const useCustomer = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminCustomerResponse,
|
{ customer: HttpTypes.AdminCustomer },
|
||||||
Error,
|
Error,
|
||||||
AdminCustomerResponse,
|
{ customer: HttpTypes.AdminCustomer },
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
@@ -33,7 +28,7 @@ export const useCustomer = (
|
|||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryKey: customersQueryKeys.detail(id),
|
queryKey: customersQueryKeys.detail(id),
|
||||||
queryFn: async () => client.customers.retrieve(id, query),
|
queryFn: async () => sdk.admin.customer.retrieve(id, query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -44,16 +39,16 @@ export const useCustomers = (
|
|||||||
query?: Record<string, any>,
|
query?: Record<string, any>,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminCustomerListResponse,
|
PaginatedResponse<{ customers: HttpTypes.AdminCustomer[] }>,
|
||||||
Error,
|
Error,
|
||||||
AdminCustomerListResponse,
|
PaginatedResponse<{ customers: HttpTypes.AdminCustomer[] }>,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryFn" | "queryKey"
|
"queryFn" | "queryKey"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.customers.list(query),
|
queryFn: () => sdk.admin.customer.list(query),
|
||||||
queryKey: customersQueryKeys.list(query),
|
queryKey: customersQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -62,10 +57,14 @@ export const useCustomers = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useCreateCustomer = (
|
export const useCreateCustomer = (
|
||||||
options?: UseMutationOptions<AdminCustomerResponse, Error, CreateCustomerReq>
|
options?: UseMutationOptions<
|
||||||
|
{ customer: HttpTypes.AdminCustomer; token: string },
|
||||||
|
Error,
|
||||||
|
HttpTypes.AdminCreateCustomer
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.customers.create(payload),
|
mutationFn: (payload) => sdk.admin.customer.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||||
options?.onSuccess?.(data, variables, context)
|
options?.onSuccess?.(data, variables, context)
|
||||||
@@ -76,10 +75,14 @@ export const useCreateCustomer = (
|
|||||||
|
|
||||||
export const useUpdateCustomer = (
|
export const useUpdateCustomer = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<AdminCustomerResponse, Error, UpdateCustomerReq>
|
options?: UseMutationOptions<
|
||||||
|
{ customer: HttpTypes.AdminCustomer },
|
||||||
|
Error,
|
||||||
|
HttpTypes.AdminUpdateCustomer
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.customers.update(id, payload),
|
mutationFn: (payload) => sdk.admin.customer.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) })
|
||||||
@@ -92,10 +95,10 @@ export const useUpdateCustomer = (
|
|||||||
|
|
||||||
export const useDeleteCustomer = (
|
export const useDeleteCustomer = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<DeleteResponse, Error, void>
|
options?: UseMutationOptions<DeleteResponse<"customer">, Error, void>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.customers.delete(id),
|
mutationFn: () => sdk.admin.customer.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import { createColumnHelper } from "@tanstack/react-table"
|
import { createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
|
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import {
|
import {
|
||||||
TextCell,
|
TextCell,
|
||||||
TextHeader,
|
TextHeader,
|
||||||
} from "../../../components/table/table-cells/common/text-cell"
|
} from "../../../components/table/table-cells/common/text-cell"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const columnHelper =
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()
|
||||||
createColumnHelper<AdminCustomerGroupResponse["customer_group"]>()
|
|
||||||
|
|
||||||
export const useCustomerGroupTableColumns = () => {
|
export const useCustomerGroupTableColumns = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { createColumnHelper } from "@tanstack/react-table"
|
import { createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
|
|
||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
EmailCell,
|
EmailCell,
|
||||||
EmailHeader,
|
EmailHeader,
|
||||||
@@ -18,8 +17,9 @@ import {
|
|||||||
FirstSeenCell,
|
FirstSeenCell,
|
||||||
FirstSeenHeader,
|
FirstSeenHeader,
|
||||||
} from "../../../components/table/table-cells/customer/first-seen-cell"
|
} from "../../../components/table/table-cells/customer/first-seen-cell"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<AdminCustomerResponse["customer"]>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomer>()
|
||||||
|
|
||||||
export const useCustomerTableColumns = () => {
|
export const useCustomerTableColumns = () => {
|
||||||
return useMemo(
|
return useMemo(
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { categories } from "./categories"
|
|||||||
import { collections } from "./collections"
|
import { collections } from "./collections"
|
||||||
import { currencies } from "./currencies"
|
import { currencies } from "./currencies"
|
||||||
import { customerGroups } from "./customer-groups"
|
import { customerGroups } from "./customer-groups"
|
||||||
import { customers } from "./customers"
|
|
||||||
import { fulfillmentProviders } from "./fulfillment-providers"
|
import { fulfillmentProviders } from "./fulfillment-providers"
|
||||||
import { fulfillments } from "./fulfillments"
|
import { fulfillments } from "./fulfillments"
|
||||||
import { inventoryItems } from "./inventory"
|
import { inventoryItems } from "./inventory"
|
||||||
@@ -33,7 +32,6 @@ export const client = {
|
|||||||
apiKeys: apiKeys,
|
apiKeys: apiKeys,
|
||||||
campaigns: campaigns,
|
campaigns: campaigns,
|
||||||
categories: categories,
|
categories: categories,
|
||||||
customers: customers,
|
|
||||||
customerGroups: customerGroups,
|
customerGroups: customerGroups,
|
||||||
currencies: currencies,
|
currencies: currencies,
|
||||||
collections: collections,
|
collections: collections,
|
||||||
|
|||||||
@@ -1,30 +1,26 @@
|
|||||||
import {
|
|
||||||
AdminCustomerGroupListResponse,
|
|
||||||
AdminCustomerGroupResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { CreateCustomerGroupSchema } from "../../routes/customer-groups/customer-group-create/components/create-customer-group-form"
|
import { CreateCustomerGroupSchema } from "../../routes/customer-groups/customer-group-create/components/create-customer-group-form"
|
||||||
import { EditCustomerGroupSchema } from "../../routes/customer-groups/customer-group-edit/components/edit-customer-group-form"
|
import { EditCustomerGroupSchema } from "../../routes/customer-groups/customer-group-edit/components/edit-customer-group-form"
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
import { deleteRequest, getRequest, postRequest } from "./common"
|
||||||
|
import { HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||||
|
|
||||||
async function retrieveCustomerGroup(id: string, query?: Record<string, any>) {
|
async function retrieveCustomerGroup(id: string, query?: Record<string, any>) {
|
||||||
return getRequest<AdminCustomerGroupResponse>(
|
return getRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>(
|
||||||
`/admin/customer-groups/${id}`,
|
`/admin/customer-groups/${id}`,
|
||||||
query
|
query
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listCustomerGroups(query?: Record<string, any>) {
|
async function listCustomerGroups(query?: Record<string, any>) {
|
||||||
return getRequest<AdminCustomerGroupListResponse>(
|
return getRequest<
|
||||||
`/admin/customer-groups`,
|
PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>
|
||||||
query
|
>(`/admin/customer-groups`, query)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createCustomerGroup(
|
async function createCustomerGroup(
|
||||||
payload: z.infer<typeof CreateCustomerGroupSchema>
|
payload: z.infer<typeof CreateCustomerGroupSchema>
|
||||||
) {
|
) {
|
||||||
return postRequest<AdminCustomerGroupResponse>(
|
return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>(
|
||||||
`/admin/customer-groups`,
|
`/admin/customer-groups`,
|
||||||
payload
|
payload
|
||||||
)
|
)
|
||||||
@@ -34,7 +30,7 @@ async function updateCustomerGroup(
|
|||||||
id: string,
|
id: string,
|
||||||
payload: z.infer<typeof EditCustomerGroupSchema>
|
payload: z.infer<typeof EditCustomerGroupSchema>
|
||||||
) {
|
) {
|
||||||
return postRequest<AdminCustomerGroupResponse>(
|
return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>(
|
||||||
`/admin/customer-groups/${id}`,
|
`/admin/customer-groups/${id}`,
|
||||||
payload
|
payload
|
||||||
)
|
)
|
||||||
@@ -52,7 +48,7 @@ async function batchAddCustomers(
|
|||||||
id: string,
|
id: string,
|
||||||
payload: { customer_ids: string[] }
|
payload: { customer_ids: string[] }
|
||||||
) {
|
) {
|
||||||
return postRequest<AdminCustomerGroupResponse>(
|
return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>(
|
||||||
`/admin/customer-groups/${id}/customers`,
|
`/admin/customer-groups/${id}/customers`,
|
||||||
{
|
{
|
||||||
add: payload.customer_ids,
|
add: payload.customer_ids,
|
||||||
@@ -64,7 +60,7 @@ async function batchRemoveCustomers(
|
|||||||
id: string,
|
id: string,
|
||||||
payload: { customer_ids: string[] }
|
payload: { customer_ids: string[] }
|
||||||
) {
|
) {
|
||||||
return postRequest<AdminCustomerGroupResponse>(
|
return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>(
|
||||||
`/admin/customer-groups/${id}/customers`,
|
`/admin/customer-groups/${id}/customers`,
|
||||||
{
|
{
|
||||||
remove: payload.customer_ids,
|
remove: payload.customer_ids,
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import {
|
|
||||||
AdminCustomerListResponse,
|
|
||||||
AdminCustomerResponse,
|
|
||||||
DeleteResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import { CreateCustomerReq, UpdateCustomerReq } from "../../types/api-payloads"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
async function retrieveCustomer(id: string, query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminCustomerResponse>(`/admin/customers/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listCustomers(query?: Record<string, any>) {
|
|
||||||
return getRequest<AdminCustomerListResponse>(`/admin/customers`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createCustomer(payload: CreateCustomerReq) {
|
|
||||||
return postRequest<AdminCustomerResponse>(`/admin/customers`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateCustomer(id: string, payload: UpdateCustomerReq) {
|
|
||||||
return postRequest<AdminCustomerResponse>(`/admin/customers/${id}`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteCustomer(id: string) {
|
|
||||||
return deleteRequest<DeleteResponse>(`/admin/customers/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const customers = {
|
|
||||||
retrieve: retrieveCustomer,
|
|
||||||
list: listCustomers,
|
|
||||||
create: createCustomer,
|
|
||||||
update: updateCustomer,
|
|
||||||
delete: deleteCustomer,
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import { AdminCollectionsRes, AdminProductsRes } from "@medusajs/medusa"
|
|
||||||
import {
|
import {
|
||||||
AdminApiKeyResponse,
|
AdminApiKeyResponse,
|
||||||
AdminCustomerGroupResponse,
|
|
||||||
AdminProductCategoryResponse,
|
AdminProductCategoryResponse,
|
||||||
AdminTaxRateResponse,
|
AdminTaxRateResponse,
|
||||||
AdminTaxRegionResponse,
|
AdminTaxRegionResponse,
|
||||||
@@ -65,7 +63,8 @@ export const RouteMap: RouteObject[] = [
|
|||||||
path: ":id",
|
path: ":id",
|
||||||
lazy: () => import("../../routes/products/product-detail"),
|
lazy: () => import("../../routes/products/product-detail"),
|
||||||
handle: {
|
handle: {
|
||||||
crumb: (data: AdminProductsRes) => data.product.title,
|
crumb: (data: { product: HttpTypes.AdminProduct }) =>
|
||||||
|
data.product.title,
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@@ -261,7 +260,8 @@ export const RouteMap: RouteObject[] = [
|
|||||||
lazy: () =>
|
lazy: () =>
|
||||||
import("../../routes/collections/collection-detail"),
|
import("../../routes/collections/collection-detail"),
|
||||||
handle: {
|
handle: {
|
||||||
crumb: (data: AdminCollectionsRes) => data.collection.title,
|
crumb: (data: { collection: HttpTypes.AdminCollection }) =>
|
||||||
|
data.collection.title,
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@@ -390,8 +390,9 @@ export const RouteMap: RouteObject[] = [
|
|||||||
lazy: () =>
|
lazy: () =>
|
||||||
import("../../routes/customer-groups/customer-group-detail"),
|
import("../../routes/customer-groups/customer-group-detail"),
|
||||||
handle: {
|
handle: {
|
||||||
crumb: (data: AdminCustomerGroupResponse) =>
|
crumb: (data: {
|
||||||
data.customer_group.name,
|
customer_group: HttpTypes.AdminCustomerGroup
|
||||||
|
}) => data.customer_group.name,
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { useForm } from "react-hook-form"
|
|||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import * as zod from "zod"
|
import * as zod from "zod"
|
||||||
|
|
||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
RouteFocusModal,
|
RouteFocusModal,
|
||||||
useRouteModal,
|
useRouteModal,
|
||||||
@@ -22,6 +21,7 @@ import { useCustomerTableColumns } from "../../../../../hooks/table/columns/use-
|
|||||||
import { useCustomerTableFilters } from "../../../../../hooks/table/filters/use-customer-table-filters"
|
import { useCustomerTableFilters } from "../../../../../hooks/table/filters/use-customer-table-filters"
|
||||||
import { useCustomerTableQuery } from "../../../../../hooks/table/query/use-customer-table-query"
|
import { useCustomerTableQuery } from "../../../../../hooks/table/query/use-customer-table-query"
|
||||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type AddCustomersFormProps = {
|
type AddCustomersFormProps = {
|
||||||
customerGroupId: string
|
customerGroupId: string
|
||||||
@@ -180,7 +180,7 @@ export const AddCustomersForm = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<AdminCustomerResponse["customer"]>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomer>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||||
import {
|
import { HttpTypes } from "@medusajs/types"
|
||||||
AdminCustomerGroupResponse,
|
|
||||||
AdminCustomerResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import { Button, Checkbox, Container, Heading, usePrompt } from "@medusajs/ui"
|
import { Button, Checkbox, Container, Heading, usePrompt } from "@medusajs/ui"
|
||||||
import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
|
import { RowSelectionState, createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useMemo, useState } from "react"
|
import { useMemo, useState } from "react"
|
||||||
@@ -19,7 +16,7 @@ import { useCustomerTableQuery } from "../../../../../hooks/table/query/use-cust
|
|||||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||||
|
|
||||||
type CustomerGroupCustomerSectionProps = {
|
type CustomerGroupCustomerSectionProps = {
|
||||||
group: AdminCustomerGroupResponse["customer_group"]
|
group: HttpTypes.AdminCustomerGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
const PAGE_SIZE = 10
|
const PAGE_SIZE = 10
|
||||||
@@ -138,7 +135,7 @@ const CustomerActions = ({
|
|||||||
customer,
|
customer,
|
||||||
customerGroupId,
|
customerGroupId,
|
||||||
}: {
|
}: {
|
||||||
customer: AdminCustomerResponse["customer"]
|
customer: HttpTypes.AdminCustomer
|
||||||
customerGroupId: string
|
customerGroupId: string
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -193,7 +190,7 @@ const CustomerActions = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<AdminCustomerResponse["customer"]>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomer>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const columns = useCustomerTableColumns()
|
const columns = useCustomerTableColumns()
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import { Container, Heading, Text, toast, usePrompt } from "@medusajs/ui"
|
import { Container, Heading, Text, toast, usePrompt } from "@medusajs/ui"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||||
import { useDeleteCustomerGroup } from "../../../../../hooks/api/customer-groups"
|
import { useDeleteCustomerGroup } from "../../../../../hooks/api/customer-groups"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type CustomerGroupGeneralSectionProps = {
|
type CustomerGroupGeneralSectionProps = {
|
||||||
group: AdminCustomerGroupResponse["customer_group"]
|
group: HttpTypes.AdminCustomerGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CustomerGroupGeneralSection = ({
|
export const CustomerGroupGeneralSection = ({
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
|
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||||
import { client } from "../../../lib/client"
|
import { client } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const customerGroupDetailQuery = (id: string) => ({
|
const customerGroupDetailQuery = (id: string) => ({
|
||||||
queryKey: productsQueryKeys.detail(id),
|
queryKey: productsQueryKeys.detail(id),
|
||||||
@@ -18,7 +17,8 @@ export const customerGroupLoader = async ({ params }: LoaderFunctionArgs) => {
|
|||||||
const query = customerGroupDetailQuery(id!)
|
const query = customerGroupDetailQuery(id!)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
queryClient.getQueryData<AdminCustomerGroupResponse>(query.queryKey) ??
|
queryClient.getQueryData<{
|
||||||
(await queryClient.fetchQuery(query))
|
customer_group: HttpTypes.AdminCustomerGroup
|
||||||
|
}>(query.queryKey) ?? (await queryClient.fetchQuery(query))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import { Button, Input, toast } from "@medusajs/ui"
|
import { Button, Input, toast } from "@medusajs/ui"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
@@ -10,9 +9,10 @@ import {
|
|||||||
useRouteModal,
|
useRouteModal,
|
||||||
} from "../../../../../components/route-modal"
|
} from "../../../../../components/route-modal"
|
||||||
import { useUpdateCustomerGroup } from "../../../../../hooks/api/customer-groups"
|
import { useUpdateCustomerGroup } from "../../../../../hooks/api/customer-groups"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type EditCustomerGroupFormProps = {
|
type EditCustomerGroupFormProps = {
|
||||||
group: AdminCustomerGroupResponse["customer_group"]
|
group: HttpTypes.AdminCustomerGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EditCustomerGroupSchema = z.object({
|
export const EditCustomerGroupSchema = z.object({
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import { Button, Container, Heading, toast, usePrompt } from "@medusajs/ui"
|
import { Button, Container, Heading, toast, usePrompt } from "@medusajs/ui"
|
||||||
import { createColumnHelper } from "@tanstack/react-table"
|
import { createColumnHelper } from "@tanstack/react-table"
|
||||||
import { useMemo } from "react"
|
import { useMemo } from "react"
|
||||||
@@ -16,6 +15,7 @@ import { useCustomerGroupTableColumns } from "../../../../../hooks/table/columns
|
|||||||
import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters"
|
import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters"
|
||||||
import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query"
|
import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query"
|
||||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const PAGE_SIZE = 20
|
const PAGE_SIZE = 20
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ export const CustomerGroupListTable = () => {
|
|||||||
const CustomerGroupRowActions = ({
|
const CustomerGroupRowActions = ({
|
||||||
group,
|
group,
|
||||||
}: {
|
}: {
|
||||||
group: AdminCustomerGroupResponse["customer_group"]
|
group: HttpTypes.AdminCustomerGroup
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const prompt = usePrompt()
|
const prompt = usePrompt()
|
||||||
@@ -142,8 +142,7 @@ const CustomerGroupRowActions = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper =
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()
|
||||||
createColumnHelper<AdminCustomerGroupResponse["customer_group"]>()
|
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const columns = useCustomerGroupTableColumns()
|
const columns = useCustomerGroupTableColumns()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { PencilSquare, Trash } from "@medusajs/icons"
|
import { PencilSquare, Trash } from "@medusajs/icons"
|
||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Heading,
|
Heading,
|
||||||
@@ -12,9 +11,10 @@ import { useTranslation } from "react-i18next"
|
|||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { ActionMenu } from "../../../../../components/common/action-menu"
|
import { ActionMenu } from "../../../../../components/common/action-menu"
|
||||||
import { useDeleteCustomer } from "../../../../../hooks/api/customers"
|
import { useDeleteCustomer } from "../../../../../hooks/api/customers"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type CustomerGeneralSectionProps = {
|
type CustomerGeneralSectionProps = {
|
||||||
customer: AdminCustomerResponse["customer"]
|
customer: HttpTypes.AdminCustomer
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CustomerGeneralSection = ({
|
export const CustomerGeneralSection = ({
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { HttpTypes } from "@medusajs/types"
|
||||||
AdminCustomerGroupResponse,
|
|
||||||
AdminCustomerResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -33,7 +30,7 @@ import { client } from "../../../../../lib/client/index.ts"
|
|||||||
import { queryClient } from "../../../../../lib/query-client.ts"
|
import { queryClient } from "../../../../../lib/query-client.ts"
|
||||||
|
|
||||||
type CustomerGroupSectionProps = {
|
type CustomerGroupSectionProps = {
|
||||||
customer: AdminCustomerResponse["customer"]
|
customer: HttpTypes.AdminCustomer
|
||||||
}
|
}
|
||||||
|
|
||||||
const PAGE_SIZE = 10
|
const PAGE_SIZE = 10
|
||||||
@@ -161,7 +158,7 @@ const CustomerGroupRowActions = ({
|
|||||||
group,
|
group,
|
||||||
customerId,
|
customerId,
|
||||||
}: {
|
}: {
|
||||||
group: AdminCustomerGroupResponse["customer_group"]
|
group: HttpTypes.AdminCustomerGroup
|
||||||
customerId: string
|
customerId: string
|
||||||
}) => {
|
}) => {
|
||||||
const prompt = usePrompt()
|
const prompt = usePrompt()
|
||||||
@@ -215,8 +212,7 @@ const CustomerGroupRowActions = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper =
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()
|
||||||
createColumnHelper<AdminCustomerGroupResponse["customer_group"]>()
|
|
||||||
|
|
||||||
const useColumns = (customerId: string) => {
|
const useColumns = (customerId: string) => {
|
||||||
const columns = useCustomerGroupTableColumns()
|
const columns = useCustomerGroupTableColumns()
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import { LoaderFunctionArgs } from "react-router-dom"
|
import { LoaderFunctionArgs } from "react-router-dom"
|
||||||
import { productsQueryKeys } from "../../../hooks/api/products"
|
import { productsQueryKeys } from "../../../hooks/api/products"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const customerDetailQuery = (id: string) => ({
|
const customerDetailQuery = (id: string) => ({
|
||||||
queryKey: productsQueryKeys.detail(id),
|
queryKey: productsQueryKeys.detail(id),
|
||||||
queryFn: async () => client.customers.retrieve(id),
|
queryFn: async () => sdk.admin.customer.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const customerLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const customerLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
@@ -14,7 +14,8 @@ export const customerLoader = async ({ params }: LoaderFunctionArgs) => {
|
|||||||
const query = customerDetailQuery(id!)
|
const query = customerDetailQuery(id!)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
queryClient.getQueryData<AdminCustomerResponse>(query.queryKey) ??
|
queryClient.getQueryData<{ customer: HttpTypes.AdminCustomer }>(
|
||||||
(await queryClient.fetchQuery(query))
|
query.queryKey
|
||||||
|
) ?? (await queryClient.fetchQuery(query))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import { Button, Input, toast } from "@medusajs/ui"
|
import { Button, Input, toast } from "@medusajs/ui"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
@@ -17,9 +16,10 @@ import {
|
|||||||
metadataToFormValues,
|
metadataToFormValues,
|
||||||
} from "../../../../../lib/metadata.ts"
|
} from "../../../../../lib/metadata.ts"
|
||||||
import { metadataFormSchema } from "../../../../../lib/validation.ts"
|
import { metadataFormSchema } from "../../../../../lib/validation.ts"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type EditCustomerFormProps = {
|
type EditCustomerFormProps = {
|
||||||
customer: AdminCustomerResponse["customer"]
|
customer: HttpTypes.AdminCustomer
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditCustomerSchema = zod.object({
|
const EditCustomerSchema = zod.object({
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { PencilSquare } from "@medusajs/icons"
|
import { PencilSquare } from "@medusajs/icons"
|
||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import { Button, Container, Heading } from "@medusajs/ui"
|
import { Button, Container, Heading } from "@medusajs/ui"
|
||||||
import { keepPreviousData } from "@tanstack/react-query"
|
import { keepPreviousData } from "@tanstack/react-query"
|
||||||
import { createColumnHelper } from "@tanstack/react-table"
|
import { createColumnHelper } from "@tanstack/react-table"
|
||||||
@@ -14,6 +13,7 @@ import { useCustomerTableColumns } from "../../../../../hooks/table/columns/use-
|
|||||||
import { useCustomerTableFilters } from "../../../../../hooks/table/filters/use-customer-table-filters"
|
import { useCustomerTableFilters } from "../../../../../hooks/table/filters/use-customer-table-filters"
|
||||||
import { useCustomerTableQuery } from "../../../../../hooks/table/query/use-customer-table-query"
|
import { useCustomerTableQuery } from "../../../../../hooks/table/query/use-customer-table-query"
|
||||||
import { useDataTable } from "../../../../../hooks/use-data-table"
|
import { useDataTable } from "../../../../../hooks/use-data-table"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
const PAGE_SIZE = 20
|
const PAGE_SIZE = 20
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ export const CustomerListTable = () => {
|
|||||||
const CustomerActions = ({
|
const CustomerActions = ({
|
||||||
customer,
|
customer,
|
||||||
}: {
|
}: {
|
||||||
customer: AdminCustomerResponse["customer"]
|
customer: HttpTypes.AdminCustomer
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ const CustomerActions = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<AdminCustomerResponse["customer"]>()
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomer>()
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const columns = useCustomerTableColumns()
|
const columns = useCustomerTableColumns()
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { useForm } from "react-hook-form"
|
|||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import * as zod from "zod"
|
import * as zod from "zod"
|
||||||
|
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
RouteFocusModal,
|
RouteFocusModal,
|
||||||
useRouteModal,
|
useRouteModal,
|
||||||
@@ -191,8 +190,7 @@ export const AddCustomerGroupsForm = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper =
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()
|
||||||
createColumnHelper<AdminCustomerGroupResponse["customer_group"]>()
|
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import { useFieldArray, type UseFormReturn } from "react-hook-form"
|
|||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
|
||||||
import { XMarkMini } from "@medusajs/icons"
|
import { XMarkMini } from "@medusajs/icons"
|
||||||
import { AdminCustomerGroupResponse } from "@medusajs/types"
|
|
||||||
import { keepPreviousData } from "@tanstack/react-query"
|
import { keepPreviousData } from "@tanstack/react-query"
|
||||||
import {
|
import {
|
||||||
OnChangeFn,
|
OnChangeFn,
|
||||||
@@ -35,6 +34,7 @@ import type {
|
|||||||
PricingCreateSchemaType,
|
PricingCreateSchemaType,
|
||||||
PricingCustomerGroupsArrayType,
|
PricingCustomerGroupsArrayType,
|
||||||
} from "./schema"
|
} from "./schema"
|
||||||
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
|
||||||
type PricingDetailsFormProps = {
|
type PricingDetailsFormProps = {
|
||||||
form: UseFormReturn<PricingCreateSchemaType>
|
form: UseFormReturn<PricingCreateSchemaType>
|
||||||
@@ -511,8 +511,7 @@ const CustomerGroupDrawer = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnHelper =
|
const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()
|
||||||
createColumnHelper<AdminCustomerGroupResponse["customer_group"]>()
|
|
||||||
|
|
||||||
const useColumns = () => {
|
const useColumns = () => {
|
||||||
const base = useCustomerGroupTableColumns()
|
const base = useCustomerGroupTableColumns()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
import {
|
import {
|
||||||
CreateApiKeyDTO,
|
CreateApiKeyDTO,
|
||||||
CreateCampaignDTO,
|
CreateCampaignDTO,
|
||||||
CreateCustomerDTO,
|
|
||||||
CreateFulfillmentSetDTO,
|
CreateFulfillmentSetDTO,
|
||||||
CreateInviteDTO,
|
CreateInviteDTO,
|
||||||
CreatePriceListDTO,
|
CreatePriceListDTO,
|
||||||
@@ -20,7 +19,6 @@ import {
|
|||||||
InventoryNext,
|
InventoryNext,
|
||||||
UpdateApiKeyDTO,
|
UpdateApiKeyDTO,
|
||||||
UpdateCampaignDTO,
|
UpdateCampaignDTO,
|
||||||
UpdateCustomerDTO,
|
|
||||||
UpdatePriceListDTO,
|
UpdatePriceListDTO,
|
||||||
UpdateProductCollectionDTO,
|
UpdateProductCollectionDTO,
|
||||||
UpdatePromotionDTO,
|
UpdatePromotionDTO,
|
||||||
@@ -43,10 +41,6 @@ export type UpdateStoreReq = UpdateStoreDTO
|
|||||||
export type CreateApiKeyReq = CreateApiKeyDTO
|
export type CreateApiKeyReq = CreateApiKeyDTO
|
||||||
export type UpdateApiKeyReq = UpdateApiKeyDTO
|
export type UpdateApiKeyReq = UpdateApiKeyDTO
|
||||||
|
|
||||||
// Customers
|
|
||||||
export type CreateCustomerReq = CreateCustomerDTO
|
|
||||||
export type UpdateCustomerReq = Omit<UpdateCustomerDTO, "id">
|
|
||||||
|
|
||||||
// Sales Channels
|
// Sales Channels
|
||||||
export type CreateSalesChannelReq = CreateSalesChannelDTO
|
export type CreateSalesChannelReq = CreateSalesChannelDTO
|
||||||
export type UpdateSalesChannelReq = UpdateSalesChannelDTO
|
export type UpdateSalesChannelReq = UpdateSalesChannelDTO
|
||||||
|
|||||||
@@ -28,8 +28,15 @@ const server = setupServer(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
http.get(`${baseUrl}/replaced-header`, ({ request, params, cookies }) => {
|
||||||
|
request.headers
|
||||||
|
if (request.headers.get("Content-Type") === "application/xml") {
|
||||||
|
return HttpResponse.json({
|
||||||
|
test: "test",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
http.get(`${baseUrl}/apikey`, ({ request, params, cookies }) => {
|
http.get(`${baseUrl}/apikey`, ({ request, params, cookies }) => {
|
||||||
console.log(request.headers.get("authorization"))
|
|
||||||
if (request.headers.get("authorization")?.startsWith("Basic")) {
|
if (request.headers.get("authorization")?.startsWith("Basic")) {
|
||||||
return HttpResponse.json({
|
return HttpResponse.json({
|
||||||
test: "test",
|
test: "test",
|
||||||
@@ -85,6 +92,14 @@ describe("Client", () => {
|
|||||||
expect(resp).toEqual({ test: "test" })
|
expect(resp).toEqual({ test: "test" })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should allow replacing a default header", async () => {
|
||||||
|
const resp = await client.fetch<any>("replaced-header", {
|
||||||
|
headers: { "content-Type": "application/xml" },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(resp).toEqual({ test: "test" })
|
||||||
|
})
|
||||||
|
|
||||||
it("should allow passing global headers", async () => {
|
it("should allow passing global headers", async () => {
|
||||||
const headClient = new Client({
|
const headClient = new Client({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
|||||||
@@ -152,4 +152,68 @@ export class Admin {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public customer = {
|
||||||
|
create: async (
|
||||||
|
body: HttpTypes.AdminCreateCustomer,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{
|
||||||
|
customer: HttpTypes.AdminCustomer
|
||||||
|
token: string
|
||||||
|
}>(`/admin/customers`, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
update: async (
|
||||||
|
id: string,
|
||||||
|
body: HttpTypes.AdminUpdateCustomer,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{ customer: HttpTypes.AdminCustomer }>(
|
||||||
|
`/admin/customers/${id}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
list: async (queryParams?: FindParams, headers?: ClientHeaders) => {
|
||||||
|
return this.client.fetch<
|
||||||
|
PaginatedResponse<{ customers: HttpTypes.AdminCustomer[] }>
|
||||||
|
>(`/admin/customers`, {
|
||||||
|
headers,
|
||||||
|
query: queryParams,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
retrieve: async (
|
||||||
|
id: string,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{ customer: HttpTypes.AdminCustomer }>(
|
||||||
|
`/admin/customers/${id}`,
|
||||||
|
{
|
||||||
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
delete: async (id: string, headers?: ClientHeaders) => {
|
||||||
|
return this.client.fetch<DeleteResponse<"customer">>(
|
||||||
|
`/admin/customers/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ export class Auth {
|
|||||||
} else {
|
} else {
|
||||||
this.client.setToken(token)
|
this.client.setToken(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
logout = async () => {
|
logout = async () => {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const toBase64 = (str: string) => {
|
|||||||
const sanitizeHeaders = (headers: Headers) => {
|
const sanitizeHeaders = (headers: Headers) => {
|
||||||
return {
|
return {
|
||||||
...Object.fromEntries(headers.entries()),
|
...Object.fromEntries(headers.entries()),
|
||||||
Authorization: "<REDACTED>",
|
authorization: "<REDACTED>",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,9 @@ const normalizeRequest = (
|
|||||||
|
|
||||||
const normalizeResponse = async (resp: Response, reqHeaders: Headers) => {
|
const normalizeResponse = async (resp: Response, reqHeaders: Headers) => {
|
||||||
if (resp.status >= 300) {
|
if (resp.status >= 300) {
|
||||||
const jsonError = await resp.json().catch(() => ({})) as { message?: string }
|
const jsonError = (await resp.json().catch(() => ({}))) as {
|
||||||
|
message?: string
|
||||||
|
}
|
||||||
throw new FetchError(
|
throw new FetchError(
|
||||||
jsonError.message ?? resp.statusText,
|
jsonError.message ?? resp.statusText,
|
||||||
resp.statusText,
|
resp.statusText,
|
||||||
|
|||||||
@@ -314,6 +314,17 @@ export class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public order = {
|
public order = {
|
||||||
|
list: async (
|
||||||
|
query?: FindParams & HttpTypes.StoreOrderFilters,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<
|
||||||
|
PaginatedResponse<{ orders: HttpTypes.StoreOrder[] }>
|
||||||
|
>(`/store/orders`, {
|
||||||
|
query,
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
},
|
||||||
retrieve: async (
|
retrieve: async (
|
||||||
id: string,
|
id: string,
|
||||||
query?: SelectParams,
|
query?: SelectParams,
|
||||||
@@ -328,4 +339,46 @@ export class Store {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public customer = {
|
||||||
|
create: async (
|
||||||
|
body: HttpTypes.StoreCreateCustomer,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{
|
||||||
|
customer: HttpTypes.StoreCustomer
|
||||||
|
token: string
|
||||||
|
}>(`/store/customers`, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
update: async (
|
||||||
|
body: HttpTypes.StoreUpdateCustomer,
|
||||||
|
query?: SelectParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) => {
|
||||||
|
return this.client.fetch<{ customer: HttpTypes.StoreCustomer }>(
|
||||||
|
`/store/customers/me`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
retrieve: async (query?: SelectParams, headers?: ClientHeaders) => {
|
||||||
|
return this.client.fetch<{ customer: HttpTypes.StoreCustomer }>(
|
||||||
|
`/store/customers/me`,
|
||||||
|
{
|
||||||
|
query,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
packages/core/types/src/http/customer/admin.ts
Normal file
25
packages/core/types/src/http/customer/admin.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import {
|
||||||
|
BaseCreateCustomer,
|
||||||
|
BaseCustomer,
|
||||||
|
BaseCustomerAddress,
|
||||||
|
BaseCustomerAddressFilters,
|
||||||
|
BaseCustomerFilters,
|
||||||
|
BaseCustomerGroup,
|
||||||
|
BaseUpdateCustomer,
|
||||||
|
CustomerGroupInCustomerFilters,
|
||||||
|
} from "./common"
|
||||||
|
|
||||||
|
export interface AdminCustomerGroup extends BaseCustomerGroup {}
|
||||||
|
export interface AdminCustomer extends BaseCustomer {
|
||||||
|
has_account: boolean
|
||||||
|
groups?: AdminCustomerGroup[]
|
||||||
|
}
|
||||||
|
export interface AdminCustomerAddress extends BaseCustomerAddress {}
|
||||||
|
export interface AdminCustomerFilters extends BaseCustomerFilters {
|
||||||
|
groups: CustomerGroupInCustomerFilters | string[] | string
|
||||||
|
}
|
||||||
|
export interface AdminCustomerAddressFilters
|
||||||
|
extends BaseCustomerAddressFilters {}
|
||||||
|
|
||||||
|
export interface AdminCreateCustomer extends BaseCreateCustomer {}
|
||||||
|
export interface AdminUpdateCustomer extends BaseUpdateCustomer {}
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import { PaginatedResponse } from "../../common"
|
|
||||||
|
|
||||||
export interface CustomerGroupResponse {
|
|
||||||
id: string
|
|
||||||
name: string | null
|
|
||||||
customers: CustomerResponse[]
|
|
||||||
metadata: Record<string, unknown> | null
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CustomerAddressResponse {
|
|
||||||
id: string
|
|
||||||
address_name: string | null
|
|
||||||
is_default_shipping: boolean
|
|
||||||
is_default_billing: boolean
|
|
||||||
customer_id: string
|
|
||||||
company: string | null
|
|
||||||
first_name: string | null
|
|
||||||
last_name: string | null
|
|
||||||
address_1: string | null
|
|
||||||
address_2: string | null
|
|
||||||
city: string | null
|
|
||||||
country_code: string | null
|
|
||||||
province: string | null
|
|
||||||
postal_code: string | null
|
|
||||||
phone: string | null
|
|
||||||
metadata: Record<string, unknown> | null
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CustomerResponse {
|
|
||||||
id: string
|
|
||||||
email: string
|
|
||||||
default_billing_address_id: string | null
|
|
||||||
default_shipping_address_id: string | null
|
|
||||||
company_name: string | null
|
|
||||||
first_name: string | null
|
|
||||||
last_name: string | null
|
|
||||||
has_account: boolean
|
|
||||||
addresses: CustomerAddressResponse[]
|
|
||||||
phone?: string | null
|
|
||||||
groups?: CustomerGroupResponse[]
|
|
||||||
metadata?: Record<string, unknown>
|
|
||||||
created_by?: string | null
|
|
||||||
deleted_at?: Date | string | null
|
|
||||||
created_at?: Date | string
|
|
||||||
updated_at?: Date | string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AdminCustomerResponse {
|
|
||||||
customer: CustomerResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AdminCustomerListResponse = PaginatedResponse<{
|
|
||||||
customers: CustomerResponse[]
|
|
||||||
}>
|
|
||||||
|
|
||||||
export interface AdminCustomerGroupResponse {
|
|
||||||
customer_group: CustomerGroupResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AdminCustomerGroupListResponse = PaginatedResponse<{
|
|
||||||
customer_groups: CustomerGroupResponse[]
|
|
||||||
}>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from "./customer"
|
|
||||||
97
packages/core/types/src/http/customer/common.ts
Normal file
97
packages/core/types/src/http/customer/common.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||||
|
|
||||||
|
export interface BaseCustomerGroup {
|
||||||
|
id: string
|
||||||
|
name: string | null
|
||||||
|
customers: BaseCustomer[]
|
||||||
|
metadata: Record<string, unknown> | null
|
||||||
|
created_at: string
|
||||||
|
updated_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseCustomerAddress {
|
||||||
|
id: string
|
||||||
|
address_name: string | null
|
||||||
|
is_default_shipping: boolean
|
||||||
|
is_default_billing: boolean
|
||||||
|
customer_id: string
|
||||||
|
company: string | null
|
||||||
|
first_name: string | null
|
||||||
|
last_name: string | null
|
||||||
|
address_1: string | null
|
||||||
|
address_2: string | null
|
||||||
|
city: string | null
|
||||||
|
country_code: string | null
|
||||||
|
province: string | null
|
||||||
|
postal_code: string | null
|
||||||
|
phone: string | null
|
||||||
|
metadata: Record<string, unknown> | null
|
||||||
|
created_at: string
|
||||||
|
updated_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseCustomer {
|
||||||
|
id: string
|
||||||
|
email: string
|
||||||
|
default_billing_address_id: string | null
|
||||||
|
default_shipping_address_id: string | null
|
||||||
|
company_name: string | null
|
||||||
|
first_name: string | null
|
||||||
|
last_name: string | null
|
||||||
|
addresses: BaseCustomerAddress[]
|
||||||
|
phone?: string | null
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
created_by?: string | null
|
||||||
|
deleted_at?: Date | string | null
|
||||||
|
created_at?: Date | string
|
||||||
|
updated_at?: Date | string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomerGroupInCustomerFilters {
|
||||||
|
id: string[] | string
|
||||||
|
name: string[] | string
|
||||||
|
created_at: OperatorMap<string>
|
||||||
|
updated_at: OperatorMap<string>
|
||||||
|
deleted_at: OperatorMap<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseCustomerFilters
|
||||||
|
extends BaseFilterable<BaseCustomerFilters> {
|
||||||
|
q?: string
|
||||||
|
id?: string[] | string | OperatorMap<string | string[]>
|
||||||
|
email?: string[] | string | OperatorMap<string>
|
||||||
|
company_name?: string[] | string | OperatorMap<string>
|
||||||
|
first_name?: string[] | string | OperatorMap<string>
|
||||||
|
last_name?: string[] | string | OperatorMap<string>
|
||||||
|
created_by?: string[] | string | OperatorMap<string>
|
||||||
|
created_at?: OperatorMap<string>
|
||||||
|
updated_at?: OperatorMap<string>
|
||||||
|
deleted_at?: OperatorMap<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseCustomerAddressFilters
|
||||||
|
extends BaseFilterable<BaseCustomerAddressFilters> {
|
||||||
|
q?: string
|
||||||
|
company?: string[] | string
|
||||||
|
city?: string[] | string
|
||||||
|
country_code?: string[] | string
|
||||||
|
province?: string[] | string
|
||||||
|
postal_code?: string[] | string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseCreateCustomer {
|
||||||
|
email: string
|
||||||
|
company_name?: string
|
||||||
|
first_name?: string
|
||||||
|
last_name?: string
|
||||||
|
phone?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BaseUpdateCustomer {
|
||||||
|
company_name?: string
|
||||||
|
first_name?: string
|
||||||
|
last_name?: string
|
||||||
|
phone?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from "./admin"
|
export * from "./admin"
|
||||||
|
export * from "./store"
|
||||||
|
|||||||
17
packages/core/types/src/http/customer/store.ts
Normal file
17
packages/core/types/src/http/customer/store.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import {
|
||||||
|
BaseCreateCustomer,
|
||||||
|
BaseCustomer,
|
||||||
|
BaseCustomerAddress,
|
||||||
|
BaseCustomerAddressFilters,
|
||||||
|
BaseCustomerFilters,
|
||||||
|
BaseUpdateCustomer,
|
||||||
|
} from "./common"
|
||||||
|
|
||||||
|
export interface StoreCustomer extends BaseCustomer {}
|
||||||
|
export interface StoreCustomerAddress extends BaseCustomerAddress {}
|
||||||
|
export interface StoreCustomerFilters extends BaseCustomerFilters {}
|
||||||
|
export interface StoreCustomerAddressFilters
|
||||||
|
extends BaseCustomerAddressFilters {}
|
||||||
|
|
||||||
|
export interface StoreCreateCustomer extends BaseCreateCustomer {}
|
||||||
|
export interface StoreUpdateCustomer extends BaseUpdateCustomer {}
|
||||||
@@ -19,4 +19,3 @@ export * from "./sales-channel"
|
|||||||
export * from "./stock-locations"
|
export * from "./stock-locations"
|
||||||
export * from "./tax"
|
export * from "./tax"
|
||||||
export * from "./user"
|
export * from "./user"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||||
import { BigNumberValue } from "../../totals"
|
import { BigNumberValue } from "../../totals"
|
||||||
import { BasePaymentCollection } from "../payment/common"
|
import { BasePaymentCollection } from "../payment/common"
|
||||||
import { BaseProduct, BaseProductVariant } from "../product/common"
|
import { BaseProduct, BaseProductVariant } from "../product/common"
|
||||||
@@ -262,3 +263,8 @@ export interface BaseOrder {
|
|||||||
original_shipping_subtotal: number
|
original_shipping_subtotal: number
|
||||||
original_shipping_tax_total: number
|
original_shipping_tax_total: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BaseOrderFilters extends BaseFilterable<BaseOrderFilters> {
|
||||||
|
id?: string[] | string | OperatorMap<string | string[]>
|
||||||
|
status?: string[] | string | OperatorMap<string | string[]>
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
BaseOrder,
|
BaseOrder,
|
||||||
BaseOrderAddress,
|
BaseOrderAddress,
|
||||||
|
BaseOrderFilters,
|
||||||
BaseOrderLineItem,
|
BaseOrderLineItem,
|
||||||
BaseOrderShippingMethod,
|
BaseOrderShippingMethod,
|
||||||
} from "./common"
|
} from "./common"
|
||||||
@@ -9,3 +10,5 @@ export interface StoreOrder extends BaseOrder {}
|
|||||||
export interface StoreOrderLineItem extends BaseOrderLineItem {}
|
export interface StoreOrderLineItem extends BaseOrderLineItem {}
|
||||||
export interface StoreOrderAddress extends BaseOrderAddress {}
|
export interface StoreOrderAddress extends BaseOrderAddress {}
|
||||||
export interface StoreOrderShippingMethod extends BaseOrderShippingMethod {}
|
export interface StoreOrderShippingMethod extends BaseOrderShippingMethod {}
|
||||||
|
|
||||||
|
export interface StoreOrderFilters extends BaseOrderFilters {}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
deleteCustomersWorkflow,
|
deleteCustomersWorkflow,
|
||||||
updateCustomersWorkflow,
|
updateCustomersWorkflow,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { AdminCustomerResponse } from "@medusajs/types"
|
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
@@ -10,10 +9,11 @@ import {
|
|||||||
} from "../../../../types/routing"
|
} from "../../../../types/routing"
|
||||||
import { refetchCustomer } from "../helpers"
|
import { refetchCustomer } from "../helpers"
|
||||||
import { AdminUpdateCustomerType } from "../validators"
|
import { AdminUpdateCustomerType } from "../validators"
|
||||||
|
import { AdminCustomer } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse<AdminCustomerResponse>
|
res: MedusaResponse<{ customer: AdminCustomer }>
|
||||||
) => {
|
) => {
|
||||||
const customer = await refetchCustomer(
|
const customer = await refetchCustomer(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
@@ -33,7 +33,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminUpdateCustomerType>,
|
req: AuthenticatedMedusaRequest<AdminUpdateCustomerType>,
|
||||||
res: MedusaResponse<AdminCustomerResponse>
|
res: MedusaResponse<{ customer: AdminCustomer }>
|
||||||
) => {
|
) => {
|
||||||
const { errors } = await updateCustomersWorkflow(req.scope).run({
|
const { errors } = await updateCustomersWorkflow(req.scope).run({
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { createCustomersWorkflow } from "@medusajs/core-flows"
|
import { createCustomersWorkflow } from "@medusajs/core-flows"
|
||||||
import {
|
|
||||||
AdminCustomerListResponse,
|
|
||||||
AdminCustomerResponse,
|
|
||||||
} from "@medusajs/types"
|
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
@@ -13,10 +10,11 @@ import {
|
|||||||
} from "../../../types/routing"
|
} from "../../../types/routing"
|
||||||
import { AdminCreateCustomerType } from "./validators"
|
import { AdminCreateCustomerType } from "./validators"
|
||||||
import { refetchCustomer } from "./helpers"
|
import { refetchCustomer } from "./helpers"
|
||||||
|
import { AdminCustomer, PaginatedResponse } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest,
|
req: AuthenticatedMedusaRequest,
|
||||||
res: MedusaResponse<AdminCustomerListResponse>
|
res: MedusaResponse<PaginatedResponse<{ customers: AdminCustomer }>>
|
||||||
) => {
|
) => {
|
||||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
|
|
||||||
@@ -41,7 +39,7 @@ export const GET = async (
|
|||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: AuthenticatedMedusaRequest<AdminCreateCustomerType>,
|
req: AuthenticatedMedusaRequest<AdminCreateCustomerType>,
|
||||||
res: MedusaResponse<AdminCustomerResponse>
|
res: MedusaResponse<{ customer: AdminCustomer }>
|
||||||
) => {
|
) => {
|
||||||
const createCustomers = createCustomersWorkflow(req.scope)
|
const createCustomers = createCustomersWorkflow(req.scope)
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
|||||||
actor_type,
|
actor_type,
|
||||||
auth_identity_id: authIdentity.id,
|
auth_identity_id: authIdentity.id,
|
||||||
app_metadata: {
|
app_metadata: {
|
||||||
entityIdKey: entityId,
|
[entityIdKey]: entityId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,5 +59,5 @@ export const retrieveTransformQueryConfig = {
|
|||||||
|
|
||||||
export const listTransformQueryConfig = {
|
export const listTransformQueryConfig = {
|
||||||
defaults: defaultStoreOrderFields,
|
defaults: defaultStoreOrderFields,
|
||||||
isList: false,
|
isList: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type MedusaSession = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const authenticate = (
|
export const authenticate = (
|
||||||
actorType: string,
|
actorType: string | string[],
|
||||||
authType: AuthType | AuthType[],
|
authType: AuthType | AuthType[],
|
||||||
options: { allowUnauthenticated?: boolean; allowUnregistered?: boolean } = {}
|
options: { allowUnauthenticated?: boolean; allowUnregistered?: boolean } = {}
|
||||||
): RequestHandler => {
|
): RequestHandler => {
|
||||||
|
|||||||
Reference in New Issue
Block a user