fix(medusa, medusa-js): publishable api key bugs (#5926)
* fix: publishable api key bugs * Create old-meals-run.md
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/medusa-js": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa, medusa-js): publishable api key bugs
|
||||||
@@ -1,32 +1,32 @@
|
|||||||
import qs from "qs"
|
import qs from "qs"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AdminPublishableApiKeyDeleteRes,
|
|
||||||
AdminPublishableApiKeysRes,
|
|
||||||
GetPublishableApiKeysParams,
|
|
||||||
AdminPublishableApiKeysListRes,
|
|
||||||
AdminPostPublishableApiKeysReq,
|
|
||||||
AdminPostPublishableApiKeysPublishableApiKeyReq,
|
|
||||||
AdminPostPublishableApiKeySalesChannelsBatchReq,
|
|
||||||
AdminDeletePublishableApiKeySalesChannelsBatchReq,
|
AdminDeletePublishableApiKeySalesChannelsBatchReq,
|
||||||
|
AdminPostPublishableApiKeySalesChannelsBatchReq,
|
||||||
|
AdminPostPublishableApiKeysPublishableApiKeyReq,
|
||||||
|
AdminPostPublishableApiKeysReq,
|
||||||
|
AdminPublishableApiKeyDeleteRes,
|
||||||
|
AdminPublishableApiKeysListRes,
|
||||||
|
AdminPublishableApiKeysRes,
|
||||||
GetPublishableApiKeySalesChannelsParams,
|
GetPublishableApiKeySalesChannelsParams,
|
||||||
|
GetPublishableApiKeysParams,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
|
|
||||||
|
import { AdminPublishableApiKeysListSalesChannelsRes } from "@medusajs/medusa"
|
||||||
import { ResponsePromise } from "../../typings"
|
import { ResponsePromise } from "../../typings"
|
||||||
import BaseResource from "../base"
|
import BaseResource from "../base"
|
||||||
import { AdminPublishableApiKeysListSalesChannelsRes } from "@medusajs/medusa"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to send requests to [Admin Publishable API Key API Routes](https://docs.medusajs.com/api/admin#publishable-api-keys). All its method
|
* This class is used to send requests to [Admin Publishable API Key API Routes](https://docs.medusajs.com/api/admin#publishable-api-keys). All its method
|
||||||
* are available in the JS Client under the `medusa.admin.publishableApiKeys` property.
|
* are available in the JS Client under the `medusa.admin.publishableApiKeys` property.
|
||||||
*
|
*
|
||||||
* All methods in this class require {@link AdminAuthResource.createSession | user authentication}.
|
* All methods in this class require {@link AdminAuthResource.createSession | user authentication}.
|
||||||
*
|
*
|
||||||
* Publishable API Keys can be used to scope Store API calls with an API key, determining what resources are retrieved when querying the API.
|
* Publishable API Keys can be used to scope Store API calls with an API key, determining what resources are retrieved when querying the API.
|
||||||
* For example, a publishable API key can be associated with one or more sales channels. When it is passed in the header of a request to the List Product store API Route,
|
* For example, a publishable API key can be associated with one or more sales channels. When it is passed in the header of a request to the List Product store API Route,
|
||||||
* the sales channels are inferred from the key and only products associated with those sales channels are retrieved.
|
* the sales channels are inferred from the key and only products associated with those sales channels are retrieved.
|
||||||
* Admins can manage publishable API keys and their associated resources. Currently, only Sales Channels are supported as a resource.
|
* Admins can manage publishable API keys and their associated resources. Currently, only Sales Channels are supported as a resource.
|
||||||
*
|
*
|
||||||
* Related Guide: [How to manage publishable API keys](https://docs.medusajs.com/development/publishable-api-keys/admin/manage-publishable-api-keys).
|
* Related Guide: [How to manage publishable API keys](https://docs.medusajs.com/development/publishable-api-keys/admin/manage-publishable-api-keys).
|
||||||
*/
|
*/
|
||||||
class AdminPublishableApiKeyResource extends BaseResource {
|
class AdminPublishableApiKeyResource extends BaseResource {
|
||||||
@@ -37,7 +37,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {Record<string, any>} query
|
* @param {Record<string, any>} query
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishable API key's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishable API key's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -49,16 +49,10 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
*/
|
*/
|
||||||
retrieve(
|
retrieve(
|
||||||
id: string,
|
id: string,
|
||||||
query: Record<string, any> = {},
|
|
||||||
customHeaders: Record<string, any> = {}
|
customHeaders: Record<string, any> = {}
|
||||||
): ResponsePromise<AdminPublishableApiKeysRes> {
|
): ResponsePromise<AdminPublishableApiKeysRes> {
|
||||||
let path = `/admin/publishable-api-keys/${id}`
|
let path = `/admin/publishable-api-keys/${id}`
|
||||||
|
|
||||||
if (query) {
|
|
||||||
const queryString = qs.stringify(query)
|
|
||||||
path += `?${queryString}`
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +61,10 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {GetPublishableApiKeysParams} query - Filters and pagination configurations to apply on the retrieved publishable API keys.
|
* @param {GetPublishableApiKeysParams} query - Filters and pagination configurations to apply on the retrieved publishable API keys.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysListRes>} Resolves to the list of publishable API keys with pagination fields.
|
* @returns {ResponsePromise<AdminPublishableApiKeysListRes>} Resolves to the list of publishable API keys with pagination fields.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* To list publishable API keys:
|
* To list publishable API keys:
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -80,9 +74,9 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* console.log(publishable_api_keys)
|
* console.log(publishable_api_keys)
|
||||||
* })
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
|
* By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -115,7 +109,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {AdminPostPublishableApiKeysReq} payload - The publishable API key to be created.
|
* @param {AdminPostPublishableApiKeysReq} payload - The publishable API key to be created.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -141,7 +135,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {AdminPostPublishableApiKeysPublishableApiKeyReq} payload - The attributes to update in the publishable API key.
|
* @param {AdminPostPublishableApiKeysPublishableApiKeyReq} payload - The attributes to update in the publishable API key.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -167,7 +161,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {string} id - The ID of the publishable API key
|
* @param {string} id - The ID of the publishable API key
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeyDeleteRes>} Resolves to the delete operation's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeyDeleteRes>} Resolves to the delete operation's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -190,7 +184,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {string} id - The ID of the publishable API key.
|
* @param {string} id - The ID of the publishable API key.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -214,7 +208,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {AdminPostPublishableApiKeySalesChannelsBatchReq} payload - The sales channels to add.
|
* @param {AdminPostPublishableApiKeySalesChannelsBatchReq} payload - The sales channels to add.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -245,7 +239,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {AdminDeletePublishableApiKeySalesChannelsBatchReq} payload - The sales channels to delete from the publishable API key.
|
* @param {AdminDeletePublishableApiKeySalesChannelsBatchReq} payload - The sales channels to delete from the publishable API key.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
* @returns {ResponsePromise<AdminPublishableApiKeysRes>} Resolves to the publishbale API key's details.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
@@ -276,7 +270,7 @@ class AdminPublishableApiKeyResource extends BaseResource {
|
|||||||
* @param {GetPublishableApiKeySalesChannelsParams} query - Filters to apply on the retrieved sales channels.
|
* @param {GetPublishableApiKeySalesChannelsParams} query - Filters to apply on the retrieved sales channels.
|
||||||
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
|
||||||
* @returns {ResponsePromise<AdminPublishableApiKeysListSalesChannelsRes>} Resolves to the list of sales channels.
|
* @returns {ResponsePromise<AdminPublishableApiKeysListSalesChannelsRes>} Resolves to the list of sales channels.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* import Medusa from "@medusajs/medusa-js"
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
import { Router } from "express"
|
import { Router } from "express"
|
||||||
|
|
||||||
|
import { PublishableApiKey, SalesChannel } from "../../../../models"
|
||||||
|
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||||
import middlewares, {
|
import middlewares, {
|
||||||
transformBody,
|
transformBody,
|
||||||
transformQuery,
|
transformQuery,
|
||||||
} from "../../../middlewares"
|
} from "../../../middlewares"
|
||||||
import { GetPublishableApiKeysParams } from "./list-publishable-api-keys"
|
|
||||||
import { PublishableApiKey, SalesChannel } from "../../../../models"
|
|
||||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
|
||||||
import { AdminPostPublishableApiKeysReq } from "./create-publishable-api-key"
|
|
||||||
import { AdminPostPublishableApiKeysPublishableApiKeyReq } from "./update-publishable-api-key"
|
|
||||||
import { AdminDeletePublishableApiKeySalesChannelsBatchReq } from "./delete-channels-batch"
|
|
||||||
import { AdminPostPublishableApiKeySalesChannelsBatchReq } from "./add-channels-batch"
|
import { AdminPostPublishableApiKeySalesChannelsBatchReq } from "./add-channels-batch"
|
||||||
import { GetPublishableApiKeySalesChannelsParams } from "./list-publishable-api-key-sales-channels"
|
import { AdminPostPublishableApiKeysReq } from "./create-publishable-api-key"
|
||||||
|
import { AdminDeletePublishableApiKeySalesChannelsBatchReq } from "./delete-channels-batch"
|
||||||
|
import { GetPublishableApiKeysParams } from "./list-publishable-api-keys"
|
||||||
|
import { AdminPostPublishableApiKeysPublishableApiKeyReq } from "./update-publishable-api-key"
|
||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
@@ -55,7 +54,6 @@ export default (app) => {
|
|||||||
|
|
||||||
route.get(
|
route.get(
|
||||||
"/:id/sales-channels",
|
"/:id/sales-channels",
|
||||||
transformQuery(GetPublishableApiKeySalesChannelsParams, { isList: true }),
|
|
||||||
middlewares.wrap(
|
middlewares.wrap(
|
||||||
require("./list-publishable-api-key-sales-channels").default
|
require("./list-publishable-api-key-sales-channels").default
|
||||||
)
|
)
|
||||||
@@ -158,8 +156,8 @@ export type AdminPublishableApiKeysListSalesChannelsRes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export * from "./add-channels-batch"
|
export * from "./add-channels-batch"
|
||||||
export * from "./delete-channels-batch"
|
|
||||||
export * from "./list-publishable-api-keys"
|
|
||||||
export * from "./list-publishable-api-key-sales-channels"
|
|
||||||
export * from "./create-publishable-api-key"
|
export * from "./create-publishable-api-key"
|
||||||
|
export * from "./delete-channels-batch"
|
||||||
|
export * from "./list-publishable-api-key-sales-channels"
|
||||||
|
export * from "./list-publishable-api-keys"
|
||||||
export * from "./update-publishable-api-key"
|
export * from "./update-publishable-api-key"
|
||||||
|
|||||||
+8
-5
@@ -1,8 +1,8 @@
|
|||||||
import { Request, Response } from "express"
|
|
||||||
import { IsOptional, IsString } from "class-validator"
|
import { IsOptional, IsString } from "class-validator"
|
||||||
|
import { Request, Response } from "express"
|
||||||
|
|
||||||
import PublishableApiKeyService from "../../../../services/publishable-api-key"
|
import PublishableApiKeyService from "../../../../services/publishable-api-key"
|
||||||
import { extendedFindParamsMixin } from "../../../../types/common"
|
import { validator } from "../../../../utils/validator"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /admin/publishable-api-keys/{id}/sales-channels
|
* @oas [get] /admin/publishable-api-keys/{id}/sales-channels
|
||||||
@@ -64,10 +64,13 @@ export default async (req: Request, res: Response) => {
|
|||||||
"publishableApiKeyService"
|
"publishableApiKeyService"
|
||||||
)
|
)
|
||||||
|
|
||||||
const filterableFields = req.filterableFields
|
const validated = await validator(
|
||||||
|
GetPublishableApiKeySalesChannelsParams,
|
||||||
|
req.query
|
||||||
|
)
|
||||||
|
|
||||||
const salesChannels = await publishableApiKeyService.listSalesChannels(id, {
|
const salesChannels = await publishableApiKeyService.listSalesChannels(id, {
|
||||||
q: filterableFields.q as string | undefined,
|
q: validated.q,
|
||||||
})
|
})
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
@@ -78,7 +81,7 @@ export default async (req: Request, res: Response) => {
|
|||||||
/**
|
/**
|
||||||
* Parameters used to filter the sales channels.
|
* Parameters used to filter the sales channels.
|
||||||
*/
|
*/
|
||||||
export class GetPublishableApiKeySalesChannelsParams extends extendedFindParamsMixin() {
|
export class GetPublishableApiKeySalesChannelsParams {
|
||||||
/**
|
/**
|
||||||
* Search term to search sales channels' names and descriptions.
|
* Search term to search sales channels' names and descriptions.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user