feat(js-sdk): Add API key (#8838)
* feat(js-sdk): Add API key * address PR comments * Allow params to create + update
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { AdminApiKeyListResponse, AdminApiKeyResponse } from "@medusajs/types"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
|
import { FetchError } from "@medusajs/js-sdk"
|
||||||
import {
|
import {
|
||||||
MutationOptions,
|
MutationOptions,
|
||||||
QueryKey,
|
QueryKey,
|
||||||
@@ -7,11 +8,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 { CreateApiKeyReq, UpdateApiKeyReq } from "../../types/api-payloads"
|
|
||||||
import { ApiKeyDeleteRes } from "../../types/api-responses"
|
|
||||||
import { salesChannelsQueryKeys } from "./sales-channels"
|
import { salesChannelsQueryKeys } from "./sales-channels"
|
||||||
|
|
||||||
const API_KEYS_QUERY_KEY = "api_keys" as const
|
const API_KEYS_QUERY_KEY = "api_keys" as const
|
||||||
@@ -19,14 +18,18 @@ export const apiKeysQueryKeys = queryKeysFactory(API_KEYS_QUERY_KEY)
|
|||||||
|
|
||||||
export const useApiKey = (
|
export const useApiKey = (
|
||||||
id: string,
|
id: string,
|
||||||
query?: Record<string, any>,
|
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<AdminApiKeyResponse, Error, AdminApiKeyResponse, QueryKey>,
|
UseQueryOptions<
|
||||||
|
HttpTypes.AdminApiKeyResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminApiKeyResponse,
|
||||||
|
QueryKey
|
||||||
|
>,
|
||||||
"queryKey" | "queryFn"
|
"queryKey" | "queryFn"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.apiKeys.retrieve(id, query),
|
queryFn: () => sdk.admin.apiKey.retrieve(id),
|
||||||
queryKey: apiKeysQueryKeys.detail(id),
|
queryKey: apiKeysQueryKeys.detail(id),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -35,19 +38,19 @@ export const useApiKey = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useApiKeys = (
|
export const useApiKeys = (
|
||||||
query?: Record<string, any>,
|
query?: HttpTypes.AdminGetApiKeysParams,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
AdminApiKeyListResponse,
|
HttpTypes.AdminGetApiKeysParams,
|
||||||
Error,
|
FetchError,
|
||||||
AdminApiKeyListResponse,
|
HttpTypes.AdminApiKeyListResponse,
|
||||||
QueryKey
|
QueryKey
|
||||||
>,
|
>,
|
||||||
"queryKey" | "queryFn"
|
"queryKey" | "queryFn"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
const { data, ...rest } = useQuery({
|
const { data, ...rest } = useQuery({
|
||||||
queryFn: () => client.apiKeys.list(query),
|
queryFn: () => sdk.admin.apiKey.list(query),
|
||||||
queryKey: apiKeysQueryKeys.list(query),
|
queryKey: apiKeysQueryKeys.list(query),
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
@@ -56,10 +59,14 @@ export const useApiKeys = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useCreateApiKey = (
|
export const useCreateApiKey = (
|
||||||
options?: UseMutationOptions<AdminApiKeyResponse, Error, CreateApiKeyReq>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminApiKeyResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminCreateApiKey
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.apiKeys.create(payload),
|
mutationFn: (payload) => sdk.admin.apiKey.create(payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
||||||
|
|
||||||
@@ -71,10 +78,14 @@ export const useCreateApiKey = (
|
|||||||
|
|
||||||
export const useUpdateApiKey = (
|
export const useUpdateApiKey = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<AdminApiKeyResponse, Error, UpdateApiKeyReq>
|
options?: UseMutationOptions<
|
||||||
|
HttpTypes.AdminApiKeyResponse,
|
||||||
|
FetchError,
|
||||||
|
HttpTypes.AdminUpdateApiKey
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.apiKeys.update(id, payload),
|
mutationFn: (payload) => sdk.admin.apiKey.update(id, payload),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
||||||
@@ -87,10 +98,10 @@ export const useUpdateApiKey = (
|
|||||||
|
|
||||||
export const useRevokeApiKey = (
|
export const useRevokeApiKey = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<AdminApiKeyResponse, Error, void>
|
options?: UseMutationOptions<HttpTypes.AdminApiKeyResponse, FetchError, void>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.apiKeys.revoke(id),
|
mutationFn: () => sdk.admin.apiKey.revoke(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
||||||
@@ -102,10 +113,14 @@ export const useRevokeApiKey = (
|
|||||||
|
|
||||||
export const useDeleteApiKey = (
|
export const useDeleteApiKey = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: MutationOptions<ApiKeyDeleteRes, Error, void>
|
options?: MutationOptions<
|
||||||
|
HttpTypes.DeleteResponse<"api_key">,
|
||||||
|
FetchError,
|
||||||
|
void
|
||||||
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => client.apiKeys.delete(id),
|
mutationFn: () => sdk.admin.apiKey.delete(id),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
||||||
@@ -118,14 +133,14 @@ export const useDeleteApiKey = (
|
|||||||
export const useBatchRemoveSalesChannelsFromApiKey = (
|
export const useBatchRemoveSalesChannelsFromApiKey = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminApiKeyResponse,
|
HttpTypes.AdminApiKeyResponse,
|
||||||
Error,
|
FetchError,
|
||||||
{ sales_channel_ids: string[] }
|
HttpTypes.AdminBatchLink["remove"]
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) =>
|
mutationFn: (payload) =>
|
||||||
client.apiKeys.batchRemoveSalesChannels(id, payload),
|
sdk.admin.apiKey.batchSalesChannels(id, { remove: payload }),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
||||||
@@ -142,13 +157,14 @@ export const useBatchRemoveSalesChannelsFromApiKey = (
|
|||||||
export const useBatchAddSalesChannelsToApiKey = (
|
export const useBatchAddSalesChannelsToApiKey = (
|
||||||
id: string,
|
id: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
AdminApiKeyResponse,
|
HttpTypes.AdminApiKeyResponse,
|
||||||
Error,
|
FetchError,
|
||||||
{ sales_channel_ids: string[] }
|
HttpTypes.AdminBatchLink["add"]
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload) => client.apiKeys.batchAddSalesChannels(id, payload),
|
mutationFn: (payload) =>
|
||||||
|
sdk.admin.apiKey.batchSalesChannels(id, { add: payload }),
|
||||||
onSuccess: (data, variables, context) => {
|
onSuccess: (data, variables, context) => {
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() })
|
||||||
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) })
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
import { AdminApiKeyListResponse, AdminApiKeyResponse } from "@medusajs/types"
|
|
||||||
import { CreateApiKeyReq, UpdateApiKeyReq } from "../../types/api-payloads"
|
|
||||||
import { ApiKeyDeleteRes } from "../../types/api-responses"
|
|
||||||
import { deleteRequest, getRequest, postRequest } from "./common"
|
|
||||||
|
|
||||||
const retrieveApiKey = async (id: string, query?: Record<string, any>) => {
|
|
||||||
return getRequest<AdminApiKeyResponse>(`/admin/api-keys/${id}`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
const listApiKeys = async (query?: Record<string, any>) => {
|
|
||||||
return getRequest<AdminApiKeyListResponse>(`/admin/api-keys`, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
const deleteApiKey = async (id: string) => {
|
|
||||||
return deleteRequest<ApiKeyDeleteRes>(`/admin/api-keys/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const revokeApiKey = async (id: string) => {
|
|
||||||
return postRequest<AdminApiKeyResponse>(`/admin/api-keys/${id}/revoke`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const createApiKey = async (payload: CreateApiKeyReq) => {
|
|
||||||
return postRequest<AdminApiKeyResponse>(`/admin/api-keys`, payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateApiKey = async (id: string, payload: UpdateApiKeyReq) => {
|
|
||||||
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`,
|
|
||||||
{
|
|
||||||
remove: payload.sales_channel_ids,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const batchAddSalesChannelsFromApiKey = async (
|
|
||||||
id: string,
|
|
||||||
payload: { sales_channel_ids: string[] }
|
|
||||||
) => {
|
|
||||||
return postRequest<AdminApiKeyResponse>(
|
|
||||||
`/admin/api-keys/${id}/sales-channels`,
|
|
||||||
{
|
|
||||||
add: payload.sales_channel_ids,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const apiKeys = {
|
|
||||||
retrieve: retrieveApiKey,
|
|
||||||
list: listApiKeys,
|
|
||||||
delete: deleteApiKey,
|
|
||||||
create: createApiKey,
|
|
||||||
update: updateApiKey,
|
|
||||||
revoke: revokeApiKey,
|
|
||||||
batchRemoveSalesChannels: batchRemoveSalesChannelsFromApiKey,
|
|
||||||
batchAddSalesChannels: batchAddSalesChannelsFromApiKey,
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import Medusa from "@medusajs/js-sdk"
|
import Medusa from "@medusajs/js-sdk"
|
||||||
import { apiKeys } from "./api-keys"
|
|
||||||
import { campaigns } from "./campaigns"
|
import { campaigns } from "./campaigns"
|
||||||
import { categories } from "./categories"
|
import { categories } from "./categories"
|
||||||
import { currencies } from "./currencies"
|
import { currencies } from "./currencies"
|
||||||
@@ -24,7 +23,6 @@ import { workflowExecutions } from "./workflow-executions"
|
|||||||
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
export const backendUrl = __BACKEND_URL__ ?? "http://localhost:9000"
|
||||||
|
|
||||||
export const client = {
|
export const client = {
|
||||||
apiKeys: apiKeys,
|
|
||||||
campaigns: campaigns,
|
campaigns: campaigns,
|
||||||
categories: categories,
|
categories: categories,
|
||||||
customerGroups: customerGroups,
|
customerGroups: customerGroups,
|
||||||
|
|||||||
+23
-33
@@ -76,24 +76,19 @@ export const ApiKeySalesChannelSection = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await mutateAsync(
|
await mutateAsync(keys, {
|
||||||
{
|
onSuccess: () => {
|
||||||
sales_channel_ids: keys,
|
toast.success(
|
||||||
|
t("apiKeyManagement.removeSalesChannel.successToastBatch", {
|
||||||
|
count: keys.length,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
setRowSelection({})
|
||||||
},
|
},
|
||||||
{
|
onError: (err) => {
|
||||||
onSuccess: () => {
|
toast.error(err.message)
|
||||||
toast.success(
|
},
|
||||||
t("apiKeyManagement.removeSalesChannel.successToastBatch", {
|
})
|
||||||
count: keys.length,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
setRowSelection({})
|
|
||||||
},
|
|
||||||
onError: (err) => {
|
|
||||||
toast.error(err.message)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -167,23 +162,18 @@ const SalesChannelActions = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await mutateAsync(
|
await mutateAsync([salesChannel.id], {
|
||||||
{
|
onSuccess: () => {
|
||||||
sales_channel_ids: [salesChannel.id],
|
toast.success(
|
||||||
|
t("apiKeyManagement.removeSalesChannel.successToast", {
|
||||||
|
count: 1,
|
||||||
|
})
|
||||||
|
)
|
||||||
},
|
},
|
||||||
{
|
onError: (err) => {
|
||||||
onSuccess: () => {
|
toast.error(err.message)
|
||||||
toast.success(
|
},
|
||||||
t("apiKeyManagement.removeSalesChannel.successToast", {
|
})
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onError: (err) => {
|
|
||||||
toast.error(err.message)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+2
-2
@@ -2,12 +2,12 @@ import { LoaderFunctionArgs } from "react-router-dom"
|
|||||||
|
|
||||||
import { AdminApiKeyResponse } from "@medusajs/types"
|
import { AdminApiKeyResponse } from "@medusajs/types"
|
||||||
import { apiKeysQueryKeys } from "../../../hooks/api/api-keys"
|
import { apiKeysQueryKeys } from "../../../hooks/api/api-keys"
|
||||||
import { client } from "../../../lib/client"
|
import { sdk } from "../../../lib/client"
|
||||||
import { queryClient } from "../../../lib/query-client"
|
import { queryClient } from "../../../lib/query-client"
|
||||||
|
|
||||||
const apiKeyDetailQuery = (id: string) => ({
|
const apiKeyDetailQuery = (id: string) => ({
|
||||||
queryKey: apiKeysQueryKeys.detail(id),
|
queryKey: apiKeysQueryKeys.detail(id),
|
||||||
queryFn: async () => client.apiKeys.retrieve(id),
|
queryFn: async () => sdk.admin.apiKey.retrieve(id),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const apiKeyLoader = async ({ params }: LoaderFunctionArgs) => {
|
export const apiKeyLoader = async ({ params }: LoaderFunctionArgs) => {
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { GetPublishableApiKeysParams } from "@medusajs/medusa"
|
import { HttpTypes } from "@medusajs/types"
|
||||||
import { useQueryParams } from "../../../../../hooks/use-query-params"
|
import { useQueryParams } from "../../../../../hooks/use-query-params"
|
||||||
|
|
||||||
type UseApiKeyManagementTableQueryProps = {
|
type UseApiKeyManagementTableQueryProps = {
|
||||||
@@ -17,7 +17,7 @@ export const useApiKeyManagementTableQuery = ({
|
|||||||
|
|
||||||
const { offset, created_at, updated_at, revoked_at, q, order } = queryObject
|
const { offset, created_at, updated_at, revoked_at, q, order } = queryObject
|
||||||
|
|
||||||
const searchParams: GetPublishableApiKeysParams = {
|
const searchParams: HttpTypes.AdminGetApiKeysParams = {
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: offset ? Number(offset) : 0,
|
offset: offset ? Number(offset) : 0,
|
||||||
created_at: created_at ? JSON.parse(created_at) : undefined,
|
created_at: created_at ? JSON.parse(created_at) : undefined,
|
||||||
|
|||||||
+13
-18
@@ -96,25 +96,20 @@ export const ApiKeySalesChannelsForm = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleSubmit = form.handleSubmit(async (values) => {
|
const handleSubmit = form.handleSubmit(async (values) => {
|
||||||
await mutateAsync(
|
await mutateAsync(values.sales_channel_ids, {
|
||||||
{
|
onSuccess: () => {
|
||||||
sales_channel_ids: values.sales_channel_ids,
|
toast.success(
|
||||||
},
|
t("apiKeyManagement.salesChannels.successToast", {
|
||||||
{
|
count: values.sales_channel_ids.length,
|
||||||
onSuccess: () => {
|
})
|
||||||
toast.success(
|
)
|
||||||
t("apiKeyManagement.salesChannels.successToast", {
|
|
||||||
count: values.sales_channel_ids.length,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
handleSuccess()
|
handleSuccess()
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
toast.error(err.message)
|
toast.error(err.message)
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import { HttpTypes, PaginatedResponse } from "@medusajs/types"
|
||||||
|
import { Client } from "../client"
|
||||||
|
import { ClientHeaders } from "../types"
|
||||||
|
|
||||||
|
export class ApiKey {
|
||||||
|
private client: Client
|
||||||
|
constructor(client: Client) {
|
||||||
|
this.client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
async list(
|
||||||
|
queryParams?: HttpTypes.AdminGetApiKeysParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<
|
||||||
|
PaginatedResponse<HttpTypes.AdminApiKeyListResponse>
|
||||||
|
>(`/admin/api-keys`, {
|
||||||
|
query: queryParams,
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
body: HttpTypes.AdminCreateApiKey,
|
||||||
|
query?: HttpTypes.AdminGetApiKeysParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminApiKeyResponse>(
|
||||||
|
`/admin/api-keys`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async revoke(id: string, headers?: ClientHeaders) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminApiKeyResponse>(
|
||||||
|
`/admin/api-keys/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async retrieve(id: string, headers?: ClientHeaders) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminApiKeyResponse>(
|
||||||
|
`/admin/api-keys/${id}`,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(
|
||||||
|
id: string,
|
||||||
|
body: HttpTypes.AdminUpdateApiKey,
|
||||||
|
query?: HttpTypes.AdminGetApiKeysParams,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminApiKeyResponse>(
|
||||||
|
`/admin/api-keys/${id}`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string, headers?: ClientHeaders) {
|
||||||
|
return await this.client.fetch<HttpTypes.DeleteResponse<"api_key">>(
|
||||||
|
`/admin/api-keys/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
headers,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchSalesChannels(
|
||||||
|
id: string,
|
||||||
|
body: HttpTypes.AdminBatchLink,
|
||||||
|
headers?: ClientHeaders
|
||||||
|
) {
|
||||||
|
return await this.client.fetch<HttpTypes.AdminApiKeyResponse>(
|
||||||
|
`/admin/api-keys/${id}/sales-channels`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Client } from "../client"
|
import { Client } from "../client"
|
||||||
|
import { ApiKey } from "./api-key"
|
||||||
import { Claim } from "./claim"
|
import { Claim } from "./claim"
|
||||||
import { Currency } from "./currency"
|
import { Currency } from "./currency"
|
||||||
import { Customer } from "./customer"
|
import { Customer } from "./customer"
|
||||||
@@ -10,6 +11,7 @@ import { InventoryItem } from "./inventory-item"
|
|||||||
import { Invite } from "./invite"
|
import { Invite } from "./invite"
|
||||||
import { Notification } from "./notification"
|
import { Notification } from "./notification"
|
||||||
import { Order } from "./order"
|
import { Order } from "./order"
|
||||||
|
import { OrderEdit } from "./order-edit"
|
||||||
import { Payment } from "./payment"
|
import { Payment } from "./payment"
|
||||||
import { PaymentCollection } from "./payment-collection"
|
import { PaymentCollection } from "./payment-collection"
|
||||||
import { PriceList } from "./price-list"
|
import { PriceList } from "./price-list"
|
||||||
@@ -33,7 +35,6 @@ import { TaxRate } from "./tax-rate"
|
|||||||
import { TaxRegion } from "./tax-region"
|
import { TaxRegion } from "./tax-region"
|
||||||
import { Upload } from "./upload"
|
import { Upload } from "./upload"
|
||||||
import { User } from "./user"
|
import { User } from "./user"
|
||||||
import { OrderEdit } from "./order-edit"
|
|
||||||
|
|
||||||
export class Admin {
|
export class Admin {
|
||||||
public invite: Invite
|
public invite: Invite
|
||||||
@@ -71,6 +72,7 @@ export class Admin {
|
|||||||
public productVariant: ProductVariant
|
public productVariant: ProductVariant
|
||||||
public refundReason: RefundReason
|
public refundReason: RefundReason
|
||||||
public paymentCollection: PaymentCollection
|
public paymentCollection: PaymentCollection
|
||||||
|
public apiKey: ApiKey
|
||||||
|
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
this.invite = new Invite(client)
|
this.invite = new Invite(client)
|
||||||
@@ -108,5 +110,6 @@ export class Admin {
|
|||||||
this.refundReason = new RefundReason(client)
|
this.refundReason = new RefundReason(client)
|
||||||
this.exchange = new Exchange(client)
|
this.exchange = new Exchange(client)
|
||||||
this.paymentCollection = new PaymentCollection(client)
|
this.paymentCollection = new PaymentCollection(client)
|
||||||
|
this.apiKey = new ApiKey(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
export * from "./api-key"
|
export * from "./api-key"
|
||||||
|
export * from "./payloads"
|
||||||
|
export * from "./queries"
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { ApiKeyType } from "../../../api-key"
|
||||||
|
|
||||||
|
export interface AdminCreateApiKey {
|
||||||
|
title: string
|
||||||
|
type: ApiKeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminUpdateApiKey {
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminRevokeApiKey {
|
||||||
|
revoke_in?: number
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { ApiKeyType } from "../../../api-key"
|
||||||
|
import { BaseFilterable, OperatorMap } from "../../../dal"
|
||||||
|
import { FindParams } from "../../common"
|
||||||
|
|
||||||
|
export interface AdminGetApiKeysParams
|
||||||
|
extends FindParams,
|
||||||
|
BaseFilterable<AdminGetApiKeysParams> {
|
||||||
|
q?: string
|
||||||
|
id?: string | string[]
|
||||||
|
title?: string | string[]
|
||||||
|
token?: string | string[]
|
||||||
|
type?: ApiKeyType
|
||||||
|
created_at?: OperatorMap<string>
|
||||||
|
updated_at?: OperatorMap<string>
|
||||||
|
deleted_at?: OperatorMap<string>
|
||||||
|
revoked_at?: OperatorMap<string>
|
||||||
|
$and?: AdminGetApiKeysParams[]
|
||||||
|
$or?: AdminGetApiKeysParams[]
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ export const AdminGetApiKeysParams = createFindParams({
|
|||||||
created_at: createOperatorMap().optional(),
|
created_at: createOperatorMap().optional(),
|
||||||
updated_at: createOperatorMap().optional(),
|
updated_at: createOperatorMap().optional(),
|
||||||
deleted_at: createOperatorMap().optional(),
|
deleted_at: createOperatorMap().optional(),
|
||||||
|
revoked_at: createOperatorMap().optional(),
|
||||||
$and: z.lazy(() => AdminGetApiKeysParams.array()).optional(),
|
$and: z.lazy(() => AdminGetApiKeysParams.array()).optional(),
|
||||||
$or: z.lazy(() => AdminGetApiKeysParams.array()).optional(),
|
$or: z.lazy(() => AdminGetApiKeysParams.array()).optional(),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user