feat: Bring back API key sales channel management (#6976)

- Add API key sales channel management
- Add HTTP responses for API keys and sales channels
- Use HTTP responses in `dashboard` and remove now redundant types
This commit is contained in:
Oli Juhl
2024-04-06 16:30:27 +00:00
committed by GitHub
parent 58c68f6715
commit 5724d80286
22 changed files with 533 additions and 607 deletions
@@ -1,17 +1,14 @@
import { AdminApiKeyListResponse, AdminApiKeyResponse } from "@medusajs/types"
import { CreateApiKeyReq, UpdateApiKeyReq } from "../../types/api-payloads"
import {
ApiKeyDeleteRes,
ApiKeyListRes,
ApiKeyRes,
} from "../../types/api-responses"
import { ApiKeyDeleteRes } from "../../types/api-responses"
import { deleteRequest, getRequest, postRequest } from "./common"
const retrieveApiKey = async (id: string, query?: Record<string, any>) => {
return getRequest<ApiKeyRes>(`/admin/api-keys/${id}`, query)
return getRequest<AdminApiKeyResponse>(`/admin/api-keys/${id}`, query)
}
const listApiKeys = async (query?: Record<string, any>) => {
return getRequest<ApiKeyListRes>(`/admin/api-keys`, query)
return getRequest<AdminApiKeyListResponse>(`/admin/api-keys`, query)
}
const deleteApiKey = async (id: string) => {
@@ -19,15 +16,35 @@ const deleteApiKey = async (id: string) => {
}
const revokeApiKey = async (id: string) => {
return postRequest<ApiKeyRes>(`/admin/api-keys/${id}/revoke`)
return postRequest<AdminApiKeyResponse>(`/admin/api-keys/${id}/revoke`)
}
const createApiKey = async (payload: CreateApiKeyReq) => {
return postRequest<ApiKeyRes>(`/admin/api-keys`, payload)
return postRequest<AdminApiKeyResponse>(`/admin/api-keys`, payload)
}
const updateApiKey = async (id: string, payload: UpdateApiKeyReq) => {
return postRequest<ApiKeyRes>(`/admin/api-keys/${id}`, payload)
return postRequest<AdminApiKeyResponse>(`/admin/api-keys/${id}`, payload)
}
const batchRemoveSalesChannelsFromApiKey = async (
id: string,
payload: { sales_channel_ids: string[] }
) => {
return postRequest<AdminApiKeyResponse>(
`/admin/api-keys/${id}/sales-channels/batch/remove`,
payload
)
}
const batchAddSalesChannelsFromApiKey = async (
id: string,
payload: { sales_channel_ids: string[] }
) => {
return postRequest<AdminApiKeyResponse>(
`/admin/api-keys/${id}/sales-channels/batch/add`,
payload
)
}
export const apiKeys = {
@@ -37,4 +54,6 @@ export const apiKeys = {
create: createApiKey,
update: updateApiKey,
revoke: revokeApiKey,
batchRemoveSalesChannels: batchRemoveSalesChannelsFromApiKey,
batchAddSalesChannels: batchAddSalesChannelsFromApiKey,
}