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:
99
packages/core/js-sdk/src/admin/api-key.ts
Normal file
99
packages/core/js-sdk/src/admin/api-key.ts
Normal file
@@ -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 { ApiKey } from "./api-key"
|
||||
import { Claim } from "./claim"
|
||||
import { Currency } from "./currency"
|
||||
import { Customer } from "./customer"
|
||||
@@ -10,6 +11,7 @@ import { InventoryItem } from "./inventory-item"
|
||||
import { Invite } from "./invite"
|
||||
import { Notification } from "./notification"
|
||||
import { Order } from "./order"
|
||||
import { OrderEdit } from "./order-edit"
|
||||
import { Payment } from "./payment"
|
||||
import { PaymentCollection } from "./payment-collection"
|
||||
import { PriceList } from "./price-list"
|
||||
@@ -33,7 +35,6 @@ import { TaxRate } from "./tax-rate"
|
||||
import { TaxRegion } from "./tax-region"
|
||||
import { Upload } from "./upload"
|
||||
import { User } from "./user"
|
||||
import { OrderEdit } from "./order-edit"
|
||||
|
||||
export class Admin {
|
||||
public invite: Invite
|
||||
@@ -71,6 +72,7 @@ export class Admin {
|
||||
public productVariant: ProductVariant
|
||||
public refundReason: RefundReason
|
||||
public paymentCollection: PaymentCollection
|
||||
public apiKey: ApiKey
|
||||
|
||||
constructor(client: Client) {
|
||||
this.invite = new Invite(client)
|
||||
@@ -108,5 +110,6 @@ export class Admin {
|
||||
this.refundReason = new RefundReason(client)
|
||||
this.exchange = new Exchange(client)
|
||||
this.paymentCollection = new PaymentCollection(client)
|
||||
this.apiKey = new ApiKey(client)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user