From e652d03b9878846ad33465d2337383ab24483b98 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:51:23 +0200 Subject: [PATCH] chore: Replace reservation customer group client with JS-SDK + clean up (#8857) --- .../src/hooks/api/customer-groups.tsx | 50 ++++----- .../dashboard/src/hooks/api/reservations.tsx | 64 ++++++----- .../dashboard/src/lib/client/client.ts | 8 -- .../dashboard/src/lib/client/currencies.ts | 15 --- .../src/lib/client/customer-groups.ts | 79 ------------- .../src/lib/client/fulfillment-providers.ts | 13 --- .../dashboard/src/lib/client/reservations.ts | 41 ------- .../src/lib/client/sales-channels.ts | 78 ------------- .../src/lib/client/shipping-options.ts | 41 ------- .../src/lib/client/shipping-profiles.ts | 35 ------ .../src/lib/client/stock-locations.ts | 106 ------------------ .../dashboard/src/lib/client/stores.ts | 25 ----- .../add-customers-form/add-customers-form.tsx | 31 +++-- .../customer-group-customer-section.tsx | 17 +-- .../customer-group-detail/loader.ts | 6 +- .../customer-group-section.tsx | 19 ++-- .../add-customer-groups-form.tsx | 6 +- .../inventory-item-general-section.tsx | 4 +- .../reservations/reservation-detail/loader.ts | 11 +- .../use-reservation-table-query.tsx | 5 +- .../core/js-sdk/src/admin/customer-group.ts | 97 ++++++++++++++++ packages/core/js-sdk/src/admin/index.ts | 6 + packages/core/js-sdk/src/admin/reservation.ts | 84 ++++++++++++++ .../src/http/customer-group/admin/entities.ts | 3 + .../src/http/customer-group/admin/index.ts | 4 + .../src/http/customer-group/admin/payloads.ts | 9 ++ .../src/http/customer-group/admin/queries.ts | 33 ++++++ .../http/customer-group/admin/responses.ts | 10 ++ .../types/src/http/customer-group/common.ts | 10 ++ .../types/src/http/customer-group/index.ts | 2 + .../types/src/http/customer/admin/entities.ts | 10 +- .../src/http/customer/admin/responses.ts | 16 +-- packages/core/types/src/http/index.ts | 1 + .../types/src/http/reservation/admin/index.ts | 2 + .../src/http/reservation/admin/payloads.ts | 15 +++ .../src/http/reservation/admin/queries.ts | 17 +++ 36 files changed, 404 insertions(+), 569 deletions(-) delete mode 100644 packages/admin-next/dashboard/src/lib/client/currencies.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/customer-groups.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/fulfillment-providers.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/reservations.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/sales-channels.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/shipping-options.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/shipping-profiles.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/stock-locations.ts delete mode 100644 packages/admin-next/dashboard/src/lib/client/stores.ts create mode 100644 packages/core/js-sdk/src/admin/customer-group.ts create mode 100644 packages/core/js-sdk/src/admin/reservation.ts create mode 100644 packages/core/types/src/http/customer-group/admin/entities.ts create mode 100644 packages/core/types/src/http/customer-group/admin/index.ts create mode 100644 packages/core/types/src/http/customer-group/admin/payloads.ts create mode 100644 packages/core/types/src/http/customer-group/admin/queries.ts create mode 100644 packages/core/types/src/http/customer-group/admin/responses.ts create mode 100644 packages/core/types/src/http/customer-group/common.ts create mode 100644 packages/core/types/src/http/customer-group/index.ts create mode 100644 packages/core/types/src/http/reservation/admin/payloads.ts create mode 100644 packages/core/types/src/http/reservation/admin/queries.ts diff --git a/packages/admin-next/dashboard/src/hooks/api/customer-groups.tsx b/packages/admin-next/dashboard/src/hooks/api/customer-groups.tsx index cbd697e98b..916690e795 100644 --- a/packages/admin-next/dashboard/src/hooks/api/customer-groups.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/customer-groups.tsx @@ -1,5 +1,5 @@ import { FetchError } from "@medusajs/js-sdk" -import { HttpTypes, PaginatedResponse } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { QueryKey, UseMutationOptions, @@ -7,12 +7,9 @@ import { useMutation, useQuery, } from "@tanstack/react-query" -import { z } from "zod" -import { client } from "../../lib/client" +import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" -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 { customersQueryKeys } from "./customers" const CUSTOMER_GROUPS_QUERY_KEY = "customer_groups" as const @@ -22,12 +19,11 @@ export const customerGroupsQueryKeys = queryKeysFactory( export const useCustomerGroup = ( id: string, - query?: Record, options?: Omit< UseQueryOptions< - { customer_group: HttpTypes.AdminCustomerGroup }, + HttpTypes.AdminCustomerGroupResponse, FetchError, - { customer_group: HttpTypes.AdminCustomerGroup }, + HttpTypes.AdminCustomerGroupResponse, QueryKey >, "queryFn" | "queryKey" @@ -35,7 +31,7 @@ export const useCustomerGroup = ( ) => { const { data, ...rest } = useQuery({ queryKey: customerGroupsQueryKeys.detail(id), - queryFn: async () => client.customerGroups.retrieve(id, query), + queryFn: async () => sdk.admin.customerGroup.retrieve(id), ...options, }) @@ -46,16 +42,16 @@ export const useCustomerGroups = ( query?: Record, options?: Omit< UseQueryOptions< - PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>, + HttpTypes.AdminGetCustomerGroupsParams, FetchError, - PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }>, + HttpTypes.AdminCustomerGroupListResponse, QueryKey >, "queryFn" | "queryKey" > ) => { const { data, ...rest } = useQuery({ - queryFn: () => client.customerGroups.list(query), + queryFn: () => sdk.admin.customerGroup.list(query), queryKey: customerGroupsQueryKeys.list(query), ...options, }) @@ -65,13 +61,13 @@ export const useCustomerGroups = ( export const useCreateCustomerGroup = ( options?: UseMutationOptions< - { customer_group: HttpTypes.AdminCustomerGroup }, + HttpTypes.AdminCustomerGroupResponse, FetchError, - z.infer + HttpTypes.AdminCreateCustomerGroup > ) => { return useMutation({ - mutationFn: (payload) => client.customerGroups.create(payload), + mutationFn: (payload) => sdk.admin.customerGroup.create(payload), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.lists(), @@ -85,13 +81,13 @@ export const useCreateCustomerGroup = ( export const useUpdateCustomerGroup = ( id: string, options?: UseMutationOptions< - { customer_group: HttpTypes.AdminCustomerGroup }, + HttpTypes.AdminCustomerGroupResponse, FetchError, - z.infer + HttpTypes.AdminUpdateCustomerGroup > ) => { return useMutation({ - mutationFn: (payload) => client.customerGroups.update(id, payload), + mutationFn: (payload) => sdk.admin.customerGroup.update(id, payload), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.lists(), @@ -109,13 +105,13 @@ export const useUpdateCustomerGroup = ( export const useDeleteCustomerGroup = ( id: string, options?: UseMutationOptions< - { id: string; object: "customer-group"; deleted: boolean }, + HttpTypes.DeleteResponse<"customer_group">, FetchError, void > ) => { return useMutation({ - mutationFn: () => client.customerGroups.delete(id), + mutationFn: () => sdk.admin.customerGroup.delete(id), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.lists(), @@ -133,13 +129,14 @@ export const useDeleteCustomerGroup = ( export const useAddCustomersToGroup = ( id: string, options?: UseMutationOptions< - { customer_group: HttpTypes.AdminCustomerGroup }, + HttpTypes.AdminCustomerGroupResponse, FetchError, - { customer_ids: string[] } + HttpTypes.AdminBatchLink["add"] > ) => { return useMutation({ - mutationFn: (payload) => client.customerGroups.addCustomers(id, payload), + mutationFn: (payload) => + sdk.admin.customerGroup.batchCustomers(id, { add: payload }), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.lists(), @@ -160,13 +157,14 @@ export const useAddCustomersToGroup = ( export const useRemoveCustomersFromGroup = ( id: string, options?: UseMutationOptions< - { customer_group: HttpTypes.AdminCustomerGroup }, + HttpTypes.AdminCustomerGroupResponse, FetchError, - { customer_ids: string[] } + HttpTypes.AdminBatchLink["remove"] > ) => { return useMutation({ - mutationFn: (payload) => client.customerGroups.removeCustomers(id, payload), + mutationFn: (payload) => + sdk.admin.customerGroup.batchCustomers(id, { remove: payload }), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: customerGroupsQueryKeys.lists(), diff --git a/packages/admin-next/dashboard/src/hooks/api/reservations.tsx b/packages/admin-next/dashboard/src/hooks/api/reservations.tsx index 679547ac6f..14c4303b60 100644 --- a/packages/admin-next/dashboard/src/hooks/api/reservations.tsx +++ b/packages/admin-next/dashboard/src/hooks/api/reservations.tsx @@ -5,24 +5,15 @@ import { useMutation, useQuery, } from "@tanstack/react-query" -import { - CreateReservationReq, - UpdateReservationReq, -} from "../../types/api-payloads" -import { - ReservationItemDeleteRes, - ReservationItemListRes, - ReservationItemRes, -} from "../../types/api-responses" - -import { InventoryTypes } from "@medusajs/types" -import { client } from "../../lib/client" +import { HttpTypes } from "@medusajs/types" +import { sdk } from "../../lib/client" import { queryClient } from "../../lib/query-client" import { queryKeysFactory } from "../../lib/query-key-factory" import { inventoryItemLevelsQueryKeys, inventoryItemsQueryKeys, } from "./inventory.tsx" +import { FetchError } from "@medusajs/js-sdk" const RESERVATION_ITEMS_QUERY_KEY = "reservation_items" as const export const reservationItemsQueryKeys = queryKeysFactory( @@ -31,15 +22,20 @@ export const reservationItemsQueryKeys = queryKeysFactory( export const useReservationItem = ( id: string, - query?: Record, + query?: HttpTypes.AdminReservationParams, options?: Omit< - UseQueryOptions, + UseQueryOptions< + HttpTypes.AdminReservationResponse, + FetchError, + HttpTypes.AdminReservationResponse, + QueryKey + >, "queryFn" | "queryKey" > ) => { const { data, ...rest } = useQuery({ queryKey: reservationItemsQueryKeys.detail(id), - queryFn: async () => client.reservations.retrieve(id, query), + queryFn: async () => sdk.admin.reservation.retrieve(id, query), ...options, }) @@ -47,19 +43,19 @@ export const useReservationItem = ( } export const useReservationItems = ( - query?: Record, + query?: HttpTypes.AdminGetReservationsParams, options?: Omit< UseQueryOptions< - ReservationItemListRes, - Error, - ReservationItemListRes, + HttpTypes.AdminGetReservationsParams, + FetchError, + HttpTypes.AdminReservationListResponse, QueryKey >, "queryKey" | "queryFn" > ) => { const { data, ...rest } = useQuery({ - queryFn: () => client.reservations.list(query), + queryFn: () => sdk.admin.reservation.list(query), queryKey: reservationItemsQueryKeys.list(query), ...options, }) @@ -69,11 +65,15 @@ export const useReservationItems = ( export const useUpdateReservationItem = ( id: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReservationResponse, + FetchError, + HttpTypes.AdminUpdateReservation + > ) => { return useMutation({ - mutationFn: (payload: InventoryTypes.UpdateReservationItemInput) => - client.reservations.update(id, payload), + mutationFn: (payload: HttpTypes.AdminUpdateReservation) => + sdk.admin.reservation.update(id, payload), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: reservationItemsQueryKeys.detail(id), @@ -94,11 +94,15 @@ export const useUpdateReservationItem = ( } export const useCreateReservationItem = ( - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.AdminReservationResponse, + FetchError, + HttpTypes.AdminCreateReservation + > ) => { return useMutation({ - mutationFn: (payload: CreateReservationReq) => - client.reservations.create(payload), + mutationFn: (payload: HttpTypes.AdminCreateReservation) => + sdk.admin.reservation.create(payload), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: reservationItemsQueryKeys.lists(), @@ -117,10 +121,14 @@ export const useCreateReservationItem = ( export const useDeleteReservationItem = ( id: string, - options?: UseMutationOptions + options?: UseMutationOptions< + HttpTypes.DeleteResponse<"reservation">, + FetchError, + void + > ) => { return useMutation({ - mutationFn: () => client.reservations.delete(id), + mutationFn: () => sdk.admin.reservation.delete(id), onSuccess: (data, variables, context) => { queryClient.invalidateQueries({ queryKey: reservationItemsQueryKeys.lists(), diff --git a/packages/admin-next/dashboard/src/lib/client/client.ts b/packages/admin-next/dashboard/src/lib/client/client.ts index ed91fe7a7f..09efb4c72d 100644 --- a/packages/admin-next/dashboard/src/lib/client/client.ts +++ b/packages/admin-next/dashboard/src/lib/client/client.ts @@ -1,11 +1,7 @@ import Medusa from "@medusajs/js-sdk" import { campaigns } from "./campaigns" import { categories } from "./categories" -import { customerGroups } from "./customer-groups" -import { fulfillmentProviders } from "./fulfillment-providers" import { promotions } from "./promotions" -import { reservations } from "./reservations" -import { stockLocations } from "./stock-locations" import { workflowExecutions } from "./workflow-executions" export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000" @@ -13,11 +9,7 @@ export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000" export const client = { campaigns: campaigns, categories: categories, - customerGroups: customerGroups, promotions: promotions, - reservations: reservations, - fulfillmentProviders: fulfillmentProviders, - stockLocations: stockLocations, workflowExecutions: workflowExecutions, } diff --git a/packages/admin-next/dashboard/src/lib/client/currencies.ts b/packages/admin-next/dashboard/src/lib/client/currencies.ts deleted file mode 100644 index 0ccb46a0e8..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/currencies.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { CurrencyListRes, CurrencyRes } from "../../types/api-responses" -import { getRequest } from "./common" - -async function retrieveCurrency(id: string, query?: Record) { - return getRequest(`/admin/currencies/${id}`, query) -} - -async function listCurrencies(query?: Record) { - return getRequest("/admin/currencies", query) -} - -export const currencies = { - retrieve: retrieveCurrency, - list: listCurrencies, -} diff --git a/packages/admin-next/dashboard/src/lib/client/customer-groups.ts b/packages/admin-next/dashboard/src/lib/client/customer-groups.ts deleted file mode 100644 index 3f5172420c..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/customer-groups.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { z } from "zod" -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 { deleteRequest, getRequest, postRequest } from "./common" -import { HttpTypes, PaginatedResponse } from "@medusajs/types" - -async function retrieveCustomerGroup(id: string, query?: Record) { - return getRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>( - `/admin/customer-groups/${id}`, - query - ) -} - -async function listCustomerGroups(query?: Record) { - return getRequest< - PaginatedResponse<{ customer_groups: HttpTypes.AdminCustomerGroup[] }> - >(`/admin/customer-groups`, query) -} - -async function createCustomerGroup( - payload: z.infer -) { - return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>( - `/admin/customer-groups`, - payload - ) -} - -async function updateCustomerGroup( - id: string, - payload: z.infer -) { - return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>( - `/admin/customer-groups/${id}`, - payload - ) -} - -async function deleteCustomerGroup(id: string) { - return deleteRequest<{ - id: string - deleted: boolean - object: "customer-group" - }>(`/admin/customer-groups/${id}`) -} - -async function batchAddCustomers( - id: string, - payload: { customer_ids: string[] } -) { - return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>( - `/admin/customer-groups/${id}/customers`, - { - add: payload.customer_ids, - } - ) -} - -async function batchRemoveCustomers( - id: string, - payload: { customer_ids: string[] } -) { - return postRequest<{ customer_group: HttpTypes.AdminCustomerGroup }>( - `/admin/customer-groups/${id}/customers`, - { - remove: payload.customer_ids, - } - ) -} - -export const customerGroups = { - retrieve: retrieveCustomerGroup, - list: listCustomerGroups, - create: createCustomerGroup, - update: updateCustomerGroup, - delete: deleteCustomerGroup, - addCustomers: batchAddCustomers, - removeCustomers: batchRemoveCustomers, -} diff --git a/packages/admin-next/dashboard/src/lib/client/fulfillment-providers.ts b/packages/admin-next/dashboard/src/lib/client/fulfillment-providers.ts deleted file mode 100644 index 8853a44d24..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/fulfillment-providers.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getRequest } from "./common" -import { FulfillmentProvidersListRes } from "../../types/api-responses" - -async function listFulfillmentProviders(query?: Record) { - return getRequest( - `/admin/fulfillment-providers`, - query - ) -} - -export const fulfillmentProviders = { - list: listFulfillmentProviders, -} diff --git a/packages/admin-next/dashboard/src/lib/client/reservations.ts b/packages/admin-next/dashboard/src/lib/client/reservations.ts deleted file mode 100644 index 0a3597fa97..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/reservations.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - ReservationDeleteRes, - ReservationListRes, - ReservationRes, -} from "../../types/api-responses" -import { deleteRequest, getRequest, postRequest } from "./common" - -import { InventoryTypes } from "@medusajs/types" - -async function retrieveReservation(id: string, query?: Record) { - return getRequest(`/admin/reservations/${id}`, query) -} - -async function listReservations(query?: Record) { - return getRequest(`/admin/reservations`, query) -} - -async function createReservation( - payload: InventoryTypes.CreateReservationItemInput -) { - return postRequest(`/admin/reservations`, payload) -} - -async function updateReservation( - id: string, - payload: InventoryTypes.UpdateReservationItemInput -) { - return postRequest(`/admin/reservations/${id}`, payload) -} - -async function deleteReservation(id: string) { - return deleteRequest(`/admin/reservations/${id}`) -} - -export const reservations = { - retrieve: retrieveReservation, - list: listReservations, - create: createReservation, - update: updateReservation, - delete: deleteReservation, -} diff --git a/packages/admin-next/dashboard/src/lib/client/sales-channels.ts b/packages/admin-next/dashboard/src/lib/client/sales-channels.ts deleted file mode 100644 index 7494d72ed5..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/sales-channels.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - AdminSalesChannelListResponse, - AdminSalesChannelResponse, -} from "@medusajs/types" -import { - AddProductsSalesChannelReq, - CreateSalesChannelReq, - RemoveProductsSalesChannelReq, - UpdateSalesChannelReq, -} from "../../types/api-payloads" -import { SalesChannelDeleteRes } from "../../types/api-responses" -import { deleteRequest, getRequest, postRequest } from "./common" - -async function retrieveSalesChannel(id: string, query?: Record) { - return getRequest>( - `/admin/sales-channels/${id}`, - query - ) -} - -async function listSalesChannels(query?: Record) { - return getRequest>( - `/admin/sales-channels`, - query - ) -} - -async function createSalesChannel(payload: CreateSalesChannelReq) { - return postRequest( - `/admin/sales-channels`, - payload - ) -} - -async function updateSalesChannel(id: string, payload: UpdateSalesChannelReq) { - return postRequest( - `/admin/sales-channels/${id}`, - payload - ) -} - -async function deleteSalesChannel(id: string) { - return deleteRequest(`/admin/sales-channels/${id}`) -} - -async function batchRemoveProducts( - id: string, - payload: RemoveProductsSalesChannelReq -) { - return postRequest( - `/admin/sales-channels/${id}/products`, - { - remove: payload.product_ids, - } - ) -} - -async function batchAddProducts( - id: string, - payload: AddProductsSalesChannelReq -) { - return postRequest( - `/admin/sales-channels/${id}/products`, - { - add: payload.product_ids, - } - ) -} - -export const salesChannels = { - retrieve: retrieveSalesChannel, - list: listSalesChannels, - create: createSalesChannel, - update: updateSalesChannel, - delete: deleteSalesChannel, - removeProducts: batchRemoveProducts, - addProducts: batchAddProducts, -} diff --git a/packages/admin-next/dashboard/src/lib/client/shipping-options.ts b/packages/admin-next/dashboard/src/lib/client/shipping-options.ts deleted file mode 100644 index 75cbbac1aa..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/shipping-options.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { deleteRequest, getRequest, postRequest } from "./common" -import { - ShippingOptionDeleteRes, - ShippingOptionListRes, - ShippingOptionRes, -} from "../../types/api-responses" -import { - CreateShippingOptionReq, - UpdateShippingOptionReq, -} from "../../types/api-payloads" - -async function createShippingOptions(payload: CreateShippingOptionReq) { - return postRequest(`/admin/shipping-options`, payload) -} - -async function updateShippingOptions( - id: string, - payload: UpdateShippingOptionReq -) { - return postRequest( - `/admin/shipping-options/${id}`, - payload - ) -} - -async function listShippingOptions(query?: Record) { - return getRequest(`/admin/shipping-options`, query) -} - -async function deleteShippingOption(optionId: string) { - return deleteRequest( - `/admin/shipping-options/${optionId}` - ) -} - -export const shippingOptions = { - create: createShippingOptions, - update: updateShippingOptions, - delete: deleteShippingOption, - list: listShippingOptions, -} diff --git a/packages/admin-next/dashboard/src/lib/client/shipping-profiles.ts b/packages/admin-next/dashboard/src/lib/client/shipping-profiles.ts deleted file mode 100644 index f716db1e30..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/shipping-profiles.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { CreateShippingProfileReq } from "../../types/api-payloads" -import { - ShippingProfileDeleteRes, - ShippingProfileListRes, - ShippingProfileRes, -} from "../../types/api-responses" -import { deleteRequest, getRequest, postRequest } from "./common" - -async function createShippingProfile(payload: CreateShippingProfileReq) { - return postRequest(`/admin/shipping-profiles`, payload) -} - -async function retrieveShippingProfile( - id: string, - query?: Record -) { - return getRequest(`/admin/shipping-profiles/${id}`, query) -} - -async function listShippingProfiles(query?: Record) { - return getRequest(`/admin/shipping-profiles`, query) -} - -async function deleteShippingProfile(id: string) { - return deleteRequest( - `/admin/shipping-profiles/${id}` - ) -} - -export const shippingProfiles = { - retrieve: retrieveShippingProfile, - list: listShippingProfiles, - create: createShippingProfile, - delete: deleteShippingProfile, -} diff --git a/packages/admin-next/dashboard/src/lib/client/stock-locations.ts b/packages/admin-next/dashboard/src/lib/client/stock-locations.ts deleted file mode 100644 index dc57dd9f2a..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/stock-locations.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { - CreateFulfillmentSetReq, - CreateServiceZoneReq, - CreateStockLocationReq, - UpdateServiceZoneReq, - UpdateStockLocationReq, - UpdateStockLocationSalesChannelsReq, -} from "../../types/api-payloads" -import { - FulfillmentSetDeleteRes, - ServiceZoneDeleteRes, - StockLocationDeleteRes, - StockLocationListRes, - StockLocationRes, -} from "../../types/api-responses" -import { deleteRequest, getRequest, postRequest } from "./common" - -async function listStockLocations(query?: Record) { - return getRequest(`/admin/stock-locations`, query) -} - -async function retrieveStockLocation(id: string, query?: Record) { - return getRequest(`/admin/stock-locations/${id}`, query) -} - -async function createStockLocation(payload: CreateStockLocationReq) { - return postRequest(`/admin/stock-locations`, payload) -} - -async function createFulfillmentSet( - locationId: string, - payload: CreateFulfillmentSetReq -) { - return postRequest( - `/admin/stock-locations/${locationId}/fulfillment-sets`, - payload - ) -} - -async function createServiceZone( - fulfillmentSetId: string, - payload: CreateServiceZoneReq -) { - return postRequest( - `/admin/fulfillment-sets/${fulfillmentSetId}/service-zones`, - payload - ) -} - -async function updateServiceZone( - fulfillmentSetId: string, - serviceZoneId: string, - payload: UpdateServiceZoneReq -) { - return postRequest( - `/admin/fulfillment-sets/${fulfillmentSetId}/service-zones/${serviceZoneId}`, - payload - ) -} - -async function updateStockLocation( - id: string, - payload: UpdateStockLocationReq -) { - return postRequest(`/admin/stock-locations/${id}`, payload) -} - -async function updateStockLocationSalesChannels( - id: string, - payload: UpdateStockLocationSalesChannelsReq -) { - return postRequest( - `/admin/stock-locations/${id}/sales-channels`, - payload - ) -} - -async function deleteStockLocation(id: string) { - return deleteRequest(`/admin/stock-locations/${id}`) -} - -async function deleteFulfillmentSet(setId: string) { - return deleteRequest( - `/admin/fulfillment-sets/${setId}` - ) -} - -async function deleteServiceZone(setId: string, zoneId: string) { - return deleteRequest( - `/admin/fulfillment-sets/${setId}/service-zones/${zoneId}` - ) -} - -export const stockLocations = { - list: listStockLocations, - retrieve: retrieveStockLocation, - create: createStockLocation, - update: updateStockLocation, - delete: deleteStockLocation, - updateSalesChannels: updateStockLocationSalesChannels, - createFulfillmentSet, - deleteFulfillmentSet, - createServiceZone, - deleteServiceZone, - updateServiceZone, -} diff --git a/packages/admin-next/dashboard/src/lib/client/stores.ts b/packages/admin-next/dashboard/src/lib/client/stores.ts deleted file mode 100644 index 987558e03d..0000000000 --- a/packages/admin-next/dashboard/src/lib/client/stores.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { UpdateStoreReq } from "../../types/api-payloads" -import { StoreListRes, StoreRes } from "../../types/api-responses" -import { getRequest, postRequest } from "./common" - -async function retrieveStore(query?: Record): Promise { - const response = await getRequest("/admin/stores", query) - - const activeStore = response.stores?.[0] - - if (!activeStore) { - // Temp: Add proper error handling - throw new Error("No active store found") - } - - return { store: activeStore } -} - -async function updateStore(id: string, payload: UpdateStoreReq) { - return postRequest(`/admin/stores/${id}`, payload) -} - -export const stores = { - retrieve: retrieveStore, - update: updateStore, -} diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx index 51efe99733..aa1580422a 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-add-customers/components/add-customers-form/add-customers-form.tsx @@ -103,25 +103,20 @@ export const AddCustomersForm = ({ const { mutateAsync, isPending } = useAddCustomersToGroup(customerGroupId) const handleSubmit = form.handleSubmit(async (data) => { - await mutateAsync( - { - customer_ids: data.customer_ids, - }, - { - onSuccess: () => { - toast.success( - t("customerGroups.customers.add.successToast", { - count: data.customer_ids.length, - }) - ) + await mutateAsync(data.customer_ids, { + onSuccess: () => { + toast.success( + t("customerGroups.customers.add.successToast", { + count: data.customer_ids.length, + }) + ) - handleSuccess(`/customer-groups/${customerGroupId}`) - }, - onError: (error) => { - toast.error(error.message) - }, - } - ) + handleSuccess(`/customer-groups/${customerGroupId}`) + }, + onError: (error) => { + toast.error(error.message) + }, + }) }) if (isError) { diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-customer-section/customer-group-customer-section.tsx b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-customer-section/customer-group-customer-section.tsx index 0379af2dba..e0b4f66502 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-customer-section/customer-group-customer-section.tsx +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/components/customer-group-customer-section/customer-group-customer-section.tsx @@ -78,16 +78,11 @@ export const CustomerGroupCustomerSection = ({ return } - await mutateAsync( - { - customer_ids: keys.map((k) => ({ id: k })), + await mutateAsync(keys, { + onSuccess: () => { + setRowSelection({}) }, - { - onSuccess: () => { - setRowSelection({}) - }, - } - ) + }) } return ( @@ -162,9 +157,7 @@ const CustomerActions = ({ return } - await mutateAsync({ - customer_ids: [{ id: customer.id }], - }) + await mutateAsync([customer.id]) } return ( diff --git a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/loader.ts b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/loader.ts index 0b40c5ab69..8538ead153 100644 --- a/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/customer-groups/customer-group-detail/loader.ts @@ -1,13 +1,13 @@ +import { HttpTypes } from "@medusajs/types" import { LoaderFunctionArgs } from "react-router-dom" import { productsQueryKeys } from "../../../hooks/api/products" -import { client } from "../../../lib/client" +import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { HttpTypes } from "@medusajs/types" const customerGroupDetailQuery = (id: string) => ({ queryKey: productsQueryKeys.detail(id), queryFn: async () => - client.customerGroups.retrieve(id, { + sdk.admin.customerGroup.retrieve(id, { fields: "+customers.id", }), }) diff --git a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx index 16f0e7e0e7..3b65d7a4c1 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customer-detail/components/customer-group-section/customer-group-section.tsx @@ -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 } from "../../../../../lib/client/index.ts" +import { client, sdk } from "../../../../../lib/client/index.ts" import { queryClient } from "../../../../../lib/query-client.ts" type CustomerGroupSectionProps = { @@ -98,8 +98,8 @@ export const CustomerGroupSection = ({ * TODO: use this for now until add customer groups to customers batch is implemented */ const promises = customerGroupIds.map((id) => - client.customerGroups.removeCustomers(id, { - customer_ids: [customer.id], + sdk.admin.customerGroup.batchCustomers(id, { + remove: [customer.id], }) ) @@ -180,14 +180,11 @@ const CustomerGroupRowActions = ({ return } - await mutateAsync( - { customer_ids: [customerId] }, - { - onError: (error) => { - toast.error(error.message) - }, - } - ) + await mutateAsync([customerId], { + onError: (error) => { + toast.error(error.message) + }, + }) } return ( diff --git a/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx b/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx index ba217b4b3b..33cf90e38b 100644 --- a/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx +++ b/packages/admin-next/dashboard/src/routes/customers/customers-add-customer-group/components/add-customers-form/add-customer-groups-form.tsx @@ -23,7 +23,7 @@ import { useCustomerGroupTableColumns } from "../../../../../hooks/table/columns import { useCustomerGroupTableFilters } from "../../../../../hooks/table/filters/use-customer-group-table-filters" import { useCustomerGroupTableQuery } from "../../../../../hooks/table/query/use-customer-group-table-query" import { useDataTable } from "../../../../../hooks/use-data-table" -import { client } from "../../../../../lib/client" +import { client, sdk } from "../../../../../lib/client" import { queryClient } from "../../../../../lib/query-client" type AddCustomerGroupsFormProps = { @@ -119,7 +119,9 @@ export const AddCustomerGroupsForm = ({ * TODO: use this for now until add customer groups to customers batch is implemented */ const promises = data.customer_group_ids.map((id) => - client.customerGroups.addCustomers(id, { customer_ids: [customerId] }) + sdk.admin.customerGroup.batchCustomers(id, { + add: [customerId], + }) ) await Promise.all(promises) diff --git a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-general-section.tsx b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-general-section.tsx index e1eb5e2676..85e28f398a 100644 --- a/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-general-section.tsx +++ b/packages/admin-next/dashboard/src/routes/inventory/inventory-detail/components/inventory-item-general-section.tsx @@ -1,5 +1,5 @@ import { Container, Heading } from "@medusajs/ui" -import { AdminInventoryItemResponse } from "@medusajs/types" +import { HttpTypes } from "@medusajs/types" import { ActionMenu } from "../../../../components/common/action-menu" import { PencilSquare } from "@medusajs/icons" @@ -7,7 +7,7 @@ import { SectionRow } from "../../../../components/common/section" import { useTranslation } from "react-i18next" type InventoryItemGeneralSectionProps = { - inventoryItem: AdminInventoryItemResponse["inventory_item"] + inventoryItem: HttpTypes.AdminInventoryItemResponse["inventory_item"] } export const InventoryItemGeneralSection = ({ inventoryItem, diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/loader.ts b/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/loader.ts index 27c873ce18..dedf1c4622 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/loader.ts +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-detail/loader.ts @@ -1,12 +1,12 @@ +import { HttpTypes } from "@medusajs/types" import { LoaderFunctionArgs } from "react-router-dom" import { reservationItemsQueryKeys } from "../../../hooks/api/reservations" -import { client } from "../../../lib/client" +import { sdk } from "../../../lib/client" import { queryClient } from "../../../lib/query-client" -import { ReservationItemRes } from "../../../types/api-responses" const reservationDetailQuery = (id: string) => ({ queryKey: reservationItemsQueryKeys.detail(id), - queryFn: async () => client.reservations.retrieve(id), + queryFn: async () => sdk.admin.reservation.retrieve(id), }) export const reservationItemLoader = async ({ params }: LoaderFunctionArgs) => { @@ -14,7 +14,8 @@ export const reservationItemLoader = async ({ params }: LoaderFunctionArgs) => { const query = reservationDetailQuery(id!) return ( - queryClient.getQueryData(query.queryKey) ?? - (await queryClient.fetchQuery(query)) + queryClient.getQueryData( + query.queryKey + ) ?? (await queryClient.fetchQuery(query)) ) } diff --git a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-query.tsx b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-query.tsx index 7d2478049a..5fc93f485e 100644 --- a/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-query.tsx +++ b/packages/admin-next/dashboard/src/routes/reservations/reservation-list/components/reservation-list-table/use-reservation-table-query.tsx @@ -1,4 +1,4 @@ -import { AdminGetReservationsParams } from "@medusajs/medusa" +import { HttpTypes } from "@medusajs/types" import { useQueryParams } from "../../../../../hooks/use-query-params" export const useReservationTableQuery = ({ @@ -15,13 +15,12 @@ export const useReservationTableQuery = ({ const { location_id, created_at, updated_at, quantity, offset, ...rest } = raw - const searchParams: AdminGetReservationsParams = { + const searchParams: HttpTypes.AdminGetReservationsParams = { limit: pageSize, offset: offset ? parseInt(offset) : undefined, location_id: location_id, created_at: created_at ? JSON.parse(created_at) : undefined, updated_at: updated_at ? JSON.parse(updated_at) : undefined, - quantity: quantity ? JSON.parse(quantity) : undefined, ...rest, } diff --git a/packages/core/js-sdk/src/admin/customer-group.ts b/packages/core/js-sdk/src/admin/customer-group.ts new file mode 100644 index 0000000000..f78899707c --- /dev/null +++ b/packages/core/js-sdk/src/admin/customer-group.ts @@ -0,0 +1,97 @@ +import { HttpTypes } from "@medusajs/types" +import { Client } from "../client" +import { ClientHeaders } from "../types" + +export class CustomerGroup { + private client: Client + constructor(client: Client) { + this.client = client + } + + async retrieve( + id: string, + query?: HttpTypes.AdminGetCustomerGroupParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/customer-groups/${id}`, + { + method: "GET", + query, + headers, + } + ) + } + + async list( + query?: HttpTypes.AdminGetCustomerGroupsParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/customer-groups`, + { + method: "GET", + headers, + query, + } + ) + } + + async create( + body: HttpTypes.AdminCreateCustomerGroup, + query?: HttpTypes.AdminGetCustomerGroupsParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/customer-groups`, + { + method: "POST", + headers, + body, + query, + } + ) + } + + async update( + id: string, + body: HttpTypes.AdminUpdateCustomerGroup, + query?: HttpTypes.AdminGetCustomerGroupsParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/customer-groups/${id}`, + { + method: "POST", + headers, + body, + query, + } + ) + } + + async delete(id: string, headers?: ClientHeaders) { + return await this.client.fetch>( + `/admin/customer-groups/${id}`, + { + method: "DELETE", + headers, + } + ) + } + + async batchCustomers( + id: string, + body: HttpTypes.AdminBatchLink, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/customer-groups/${id}/customers`, + { + method: "POST", + headers, + body, + } + ) + } +} diff --git a/packages/core/js-sdk/src/admin/index.ts b/packages/core/js-sdk/src/admin/index.ts index 1600ab2b82..e701066e49 100644 --- a/packages/core/js-sdk/src/admin/index.ts +++ b/packages/core/js-sdk/src/admin/index.ts @@ -3,6 +3,7 @@ import { ApiKey } from "./api-key" import { Claim } from "./claim" import { Currency } from "./currency" import { Customer } from "./customer" +import { CustomerGroup } from "./customer-group" import { Exchange } from "./exchange" import { Fulfillment } from "./fulfillment" import { FulfillmentProvider } from "./fulfillment-provider" @@ -24,6 +25,7 @@ import { ProductType } from "./product-type" import { ProductVariant } from "./product-variant" import { RefundReason } from "./refund-reasons" import { Region } from "./region" +import Reservation from "./reservation" import { Return } from "./return" import { ReturnReason } from "./return-reason" import { SalesChannel } from "./sales-channel" @@ -73,6 +75,8 @@ export class Admin { public refundReason: RefundReason public paymentCollection: PaymentCollection public apiKey: ApiKey + public reservation: Reservation + public customerGroup: CustomerGroup constructor(client: Client) { this.invite = new Invite(client) @@ -111,5 +115,7 @@ export class Admin { this.exchange = new Exchange(client) this.paymentCollection = new PaymentCollection(client) this.apiKey = new ApiKey(client) + this.reservation = new Reservation(client) + this.customerGroup = new CustomerGroup(client) } } diff --git a/packages/core/js-sdk/src/admin/reservation.ts b/packages/core/js-sdk/src/admin/reservation.ts new file mode 100644 index 0000000000..46dccb4da6 --- /dev/null +++ b/packages/core/js-sdk/src/admin/reservation.ts @@ -0,0 +1,84 @@ +import { HttpTypes } from "@medusajs/types" +import { Client } from "../client" +import { ClientHeaders } from "../types" + +class Reservation { + private client: Client + constructor(client: Client) { + this.client = client + } + + async retrieve( + id: string, + query?: HttpTypes.AdminReservationParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/reservations/${id}`, + { + method: "GET", + headers, + query, + } + ) + } + + async list( + query?: HttpTypes.AdminGetReservationsParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + "/admin/reservations", + { + method: "GET", + query, + headers, + } + ) + } + + async create( + body: HttpTypes.AdminCreateReservation, + query?: HttpTypes.AdminGetReservationsParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + "/admin/reservations", + { + method: "POST", + body, + query, + headers, + } + ) + } + + async update( + id: string, + body: HttpTypes.AdminUpdateReservation, + query?: HttpTypes.AdminGetReservationsParams, + headers?: ClientHeaders + ) { + return await this.client.fetch( + `/admin/reservations/${id}`, + { + method: "POST", + body, + query, + headers, + } + ) + } + + async delete(id: string, headers?: ClientHeaders) { + return await this.client.fetch>( + `/admin/reservations/${id}`, + { + method: "DELETE", + headers, + } + ) + } +} + +export default Reservation diff --git a/packages/core/types/src/http/customer-group/admin/entities.ts b/packages/core/types/src/http/customer-group/admin/entities.ts new file mode 100644 index 0000000000..01bed97327 --- /dev/null +++ b/packages/core/types/src/http/customer-group/admin/entities.ts @@ -0,0 +1,3 @@ +import { BaseCustomerGroup } from "../common" + +export interface AdminCustomerGroup extends BaseCustomerGroup {} diff --git a/packages/core/types/src/http/customer-group/admin/index.ts b/packages/core/types/src/http/customer-group/admin/index.ts new file mode 100644 index 0000000000..2f1b9df166 --- /dev/null +++ b/packages/core/types/src/http/customer-group/admin/index.ts @@ -0,0 +1,4 @@ +export * from "./entities" +export * from "./payloads" +export * from "./queries" +export * from "./responses" \ No newline at end of file diff --git a/packages/core/types/src/http/customer-group/admin/payloads.ts b/packages/core/types/src/http/customer-group/admin/payloads.ts new file mode 100644 index 0000000000..ab837ca7e6 --- /dev/null +++ b/packages/core/types/src/http/customer-group/admin/payloads.ts @@ -0,0 +1,9 @@ +export interface AdminCreateCustomerGroup { + name: string + metadata?: Record | null +} + +export interface AdminUpdateCustomerGroup { + name?: string + metadata?: Record | null +} diff --git a/packages/core/types/src/http/customer-group/admin/queries.ts b/packages/core/types/src/http/customer-group/admin/queries.ts new file mode 100644 index 0000000000..3dc0d67b6f --- /dev/null +++ b/packages/core/types/src/http/customer-group/admin/queries.ts @@ -0,0 +1,33 @@ +import { OperatorMap } from "../../../dal" +import { SelectParams } from "../../common" + +export interface AdminCustomerInGroupFilters { + id?: string | string[] + email?: string | string[] | OperatorMap + default_billing_address_id?: string | string[] + default_shipping_address_id?: string | string[] + company_name?: string | string[] + first_name?: string | string[] + last_name?: string | string[] + created_by?: string | string[] + created_at?: OperatorMap + updated_at?: OperatorMap + deleted_at?: OperatorMap +} + +export interface AdminGetCustomerGroupsParams { + limit?: number + offset?: number + q?: string + id?: string | string[] + name?: string | string[] + customers?: string | string[] | AdminCustomerInGroupFilters + created_by?: string | string[] + created_at?: OperatorMap + updated_at?: OperatorMap + deleted_at?: OperatorMap + $and?: AdminGetCustomerGroupsParams[] + $or?: AdminGetCustomerGroupsParams[] +} + +export interface AdminGetCustomerGroupParams extends SelectParams {} diff --git a/packages/core/types/src/http/customer-group/admin/responses.ts b/packages/core/types/src/http/customer-group/admin/responses.ts new file mode 100644 index 0000000000..586eb02e3a --- /dev/null +++ b/packages/core/types/src/http/customer-group/admin/responses.ts @@ -0,0 +1,10 @@ +import { PaginatedResponse } from "../../common" +import { AdminCustomerGroup } from "./entities" + +export interface AdminCustomerGroupResponse { + customer_group: AdminCustomerGroup +} + +export type AdminCustomerGroupListResponse = PaginatedResponse<{ + customer_groups: AdminCustomerGroup[] +}> diff --git a/packages/core/types/src/http/customer-group/common.ts b/packages/core/types/src/http/customer-group/common.ts new file mode 100644 index 0000000000..9797711821 --- /dev/null +++ b/packages/core/types/src/http/customer-group/common.ts @@ -0,0 +1,10 @@ +import { BaseCustomer } from "../customer/common" + +export interface BaseCustomerGroup { + id: string + name: string | null + customers: BaseCustomer[] + metadata: Record | null + created_at: string + updated_at: string +} diff --git a/packages/core/types/src/http/customer-group/index.ts b/packages/core/types/src/http/customer-group/index.ts new file mode 100644 index 0000000000..9335a78736 --- /dev/null +++ b/packages/core/types/src/http/customer-group/index.ts @@ -0,0 +1,2 @@ +export * from "./admin"; + diff --git a/packages/core/types/src/http/customer/admin/entities.ts b/packages/core/types/src/http/customer/admin/entities.ts index e1019d470b..8cd83ca2df 100644 --- a/packages/core/types/src/http/customer/admin/entities.ts +++ b/packages/core/types/src/http/customer/admin/entities.ts @@ -1,12 +1,8 @@ -import { - BaseCustomer, - BaseCustomerAddress, - BaseCustomerGroup, -} from "../common" +import { AdminCustomerGroup } from "../../customer-group" +import { BaseCustomer, BaseCustomerAddress } from "../common" -export interface AdminCustomerGroup extends BaseCustomerGroup {} export interface AdminCustomer extends BaseCustomer { has_account: boolean groups?: AdminCustomerGroup[] } -export interface AdminCustomerAddress extends BaseCustomerAddress {} \ No newline at end of file +export interface AdminCustomerAddress extends BaseCustomerAddress {} diff --git a/packages/core/types/src/http/customer/admin/responses.ts b/packages/core/types/src/http/customer/admin/responses.ts index 5a55d30d97..1ef83316f4 100644 --- a/packages/core/types/src/http/customer/admin/responses.ts +++ b/packages/core/types/src/http/customer/admin/responses.ts @@ -1,18 +1,12 @@ -import { PaginatedResponse } from "../../common"; -import { AdminCustomer, AdminCustomerAddress, AdminCustomerGroup } from "./entities"; +import { PaginatedResponse } from "../../common" +import { AdminCustomer, AdminCustomerAddress } from "./entities" export interface AdminCustomerResponse { customer: AdminCustomer } -export type AdminCustomerListResponse = PaginatedResponse<{ customers: AdminCustomer }> - -export interface AdminCustomerGroupResponse { - customer_group: AdminCustomerGroup -} - -export type AdminCustomerGroupListResponse = PaginatedResponse<{ - customer_groups: AdminCustomerGroup[] +export type AdminCustomerListResponse = PaginatedResponse<{ + customers: AdminCustomer }> export interface AdminCustomerAddressResponse { @@ -21,4 +15,4 @@ export interface AdminCustomerAddressResponse { export type AdminCustomerAddressListResponse = PaginatedResponse<{ addresses: AdminCustomerAddress[] -}> \ No newline at end of file +}> diff --git a/packages/core/types/src/http/index.ts b/packages/core/types/src/http/index.ts index ece9ffb7e7..08409da573 100644 --- a/packages/core/types/src/http/index.ts +++ b/packages/core/types/src/http/index.ts @@ -6,6 +6,7 @@ export * from "./collection" export * from "./common" export * from "./currency" export * from "./customer" +export * from "./customer-group" export * from "./exchange" export * from "./file" export * from "./fulfillment" diff --git a/packages/core/types/src/http/reservation/admin/index.ts b/packages/core/types/src/http/reservation/admin/index.ts index e6c04bce7f..1f82a2ead5 100644 --- a/packages/core/types/src/http/reservation/admin/index.ts +++ b/packages/core/types/src/http/reservation/admin/index.ts @@ -1,2 +1,4 @@ export * from "./entities" +export * from "./payloads" +export * from "./queries" export * from "./responses" diff --git a/packages/core/types/src/http/reservation/admin/payloads.ts b/packages/core/types/src/http/reservation/admin/payloads.ts new file mode 100644 index 0000000000..404f18a691 --- /dev/null +++ b/packages/core/types/src/http/reservation/admin/payloads.ts @@ -0,0 +1,15 @@ +export interface AdminCreateReservation { + line_item_id?: string | null + location_id: string + inventory_item_id: string + quantity: number + description?: string | null + metadata?: Record | null +} + +export interface AdminUpdateReservation { + location_id?: string + quantity?: number + description?: string | null + metadata?: Record | null +} diff --git a/packages/core/types/src/http/reservation/admin/queries.ts b/packages/core/types/src/http/reservation/admin/queries.ts new file mode 100644 index 0000000000..68f1185535 --- /dev/null +++ b/packages/core/types/src/http/reservation/admin/queries.ts @@ -0,0 +1,17 @@ +import { OperatorMap } from "../../../dal" +import { SelectParams } from "../../common" + +export interface AdminGetReservationsParams { + limit?: number + offset?: number + location_id?: string | string[] + inventory_item_id?: string | string[] + line_item_id?: string | string[] + created_by?: string | string[] + description?: string | OperatorMap + created_at?: OperatorMap + updated_at?: OperatorMap + deleted_at?: OperatorMap +} + +export interface AdminReservationParams extends SelectParams {}