feat: Modify api key and sales channel link to use modules and add test (#6546)
This commit is contained in:
@@ -284,6 +284,19 @@ moduleIntegrationTestRunner({
|
||||
expect(apiKeysInDatabase).toHaveLength(2)
|
||||
})
|
||||
|
||||
it("should only return keys with matching token", async function () {
|
||||
const created = await service.create([
|
||||
createPublishableKeyFixture,
|
||||
createPublishableKeyFixture,
|
||||
])
|
||||
|
||||
const apiKeysInDatabase = await service.list({
|
||||
token: created[0].token,
|
||||
})
|
||||
expect(apiKeysInDatabase).toHaveLength(1)
|
||||
expect(apiKeysInDatabase[0].token).toEqual(created[0].token)
|
||||
})
|
||||
|
||||
it("should not return the token and salt for secret keys when listing", async function () {
|
||||
await service.create([createSecretKeyFixture])
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export const joinerConfig: ModuleJoinerConfig = {
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: [
|
||||
{
|
||||
name: ["api-key", "api-keys"],
|
||||
name: ["api_key", "api_keys"],
|
||||
args: { entity: ApiKey.name },
|
||||
},
|
||||
],
|
||||
|
||||
@@ -3,7 +3,7 @@ import { CreateApiKeyDTO, IApiKeyModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type CreateApiKeysStepInput = {
|
||||
apiKeysData: CreateApiKeyDTO[]
|
||||
api_keys: CreateApiKeyDTO[]
|
||||
}
|
||||
|
||||
export const createApiKeysStepId = "create-api-keys"
|
||||
@@ -13,7 +13,7 @@ export const createApiKeysStep = createStep(
|
||||
const service = container.resolve<IApiKeyModuleService>(
|
||||
ModuleRegistrationName.API_KEY
|
||||
)
|
||||
const created = await service.create(data.apiKeysData)
|
||||
const created = await service.create(data.api_keys)
|
||||
return new StepResponse(
|
||||
created,
|
||||
created.map((apiKey) => apiKey.id)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ApiKeyDTO, CreateApiKeyDTO } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { createApiKeysStep } from "../steps"
|
||||
|
||||
type WorkflowInput = { apiKeysData: CreateApiKeyDTO[] }
|
||||
type WorkflowInput = { api_keys: CreateApiKeyDTO[] }
|
||||
|
||||
export const createApiKeysWorkflowId = "create-api-keys"
|
||||
export const createApiKeysWorkflow = createWorkflow(
|
||||
|
||||
@@ -9,4 +9,3 @@ export * from "./product-shipping-profile"
|
||||
export * from "./product-variant-inventory-item"
|
||||
export * from "./product-variant-price-set"
|
||||
export * from "./publishable-api-key-sales-channel"
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { LINKS } from "../links"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
export const PublishableApiKeySalesChannel: ModuleJoinerConfig = {
|
||||
serviceName: LINKS.PublishableApiKeySalesChannel,
|
||||
@@ -19,14 +20,14 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = {
|
||||
primaryKeys: ["id", "publishable_key_id", "sales_channel_id"],
|
||||
relationships: [
|
||||
{
|
||||
serviceName: "publishableApiKeyService",
|
||||
serviceName: Modules.API_KEY,
|
||||
isInternalService: true,
|
||||
primaryKey: "id",
|
||||
foreignKey: "publishable_key_id",
|
||||
alias: "publishable_key",
|
||||
alias: "api_key",
|
||||
},
|
||||
{
|
||||
serviceName: "salesChannelService",
|
||||
serviceName: Modules.SALES_CHANNEL,
|
||||
isInternalService: true,
|
||||
primaryKey: "id",
|
||||
foreignKey: "sales_channel_id",
|
||||
@@ -35,7 +36,7 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = {
|
||||
],
|
||||
extends: [
|
||||
{
|
||||
serviceName: "publishableApiKeyService",
|
||||
serviceName: Modules.API_KEY,
|
||||
fieldAlias: {
|
||||
sales_channels: "sales_channels_link.sales_channel",
|
||||
},
|
||||
@@ -49,13 +50,16 @@ export const PublishableApiKeySalesChannel: ModuleJoinerConfig = {
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceName: "salesChannelService",
|
||||
serviceName: Modules.SALES_CHANNEL,
|
||||
fieldAlias: {
|
||||
api_keys: "api_keys_link.api_key",
|
||||
},
|
||||
relationship: {
|
||||
serviceName: LINKS.PublishableApiKeySalesChannel,
|
||||
isInternalService: true,
|
||||
primaryKey: "sales_channel_id",
|
||||
foreignKey: "id",
|
||||
alias: "publishable_keys_link",
|
||||
alias: "api_keys_link",
|
||||
isList: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -41,8 +41,8 @@ export const LINKS = {
|
||||
"sales_channel_id"
|
||||
),
|
||||
PublishableApiKeySalesChannel: composeLinkName(
|
||||
"publishableApiKeyService",
|
||||
"publishable_key_id",
|
||||
Modules.API_KEY,
|
||||
"api_key_id",
|
||||
Modules.SALES_CHANNEL,
|
||||
"sales_channel_id"
|
||||
),
|
||||
|
||||
@@ -20,7 +20,7 @@ export const GET = async (
|
||||
const variables = { id: req.params.id }
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "api-key",
|
||||
entryPoint: "api_key",
|
||||
variables,
|
||||
fields: defaultAdminApiKeyFields,
|
||||
})
|
||||
@@ -66,7 +66,7 @@ export const DELETE = async (
|
||||
|
||||
res.status(200).json({
|
||||
id,
|
||||
object: "api-key",
|
||||
object: "api_key",
|
||||
deleted: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export const GET = async (
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "api-key",
|
||||
entryPoint: "api_key",
|
||||
variables: {
|
||||
filters: req.filterableFields,
|
||||
order: req.listConfig.order,
|
||||
@@ -47,7 +47,7 @@ export const POST = async (
|
||||
]
|
||||
|
||||
const { result, errors } = await createApiKeysWorkflow(req.scope).run({
|
||||
input: { apiKeysData: input },
|
||||
input: { api_keys: input },
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
|
||||
@@ -34,6 +34,13 @@ export class AdminGetApiKeysParams extends extendedFindParamsMixin({
|
||||
@IsOptional()
|
||||
title?: string | string[]
|
||||
|
||||
/**
|
||||
* Filter by token
|
||||
*/
|
||||
@IsString({ each: true })
|
||||
@IsOptional()
|
||||
token?: string | string[]
|
||||
|
||||
/**
|
||||
* Filter by type
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,7 @@ export interface ApiKeyDTO {
|
||||
export interface FilterableApiKeyProps
|
||||
extends BaseFilterable<FilterableApiKeyProps> {
|
||||
id?: string | string[]
|
||||
token?: string | string[]
|
||||
title?: string | string[]
|
||||
type?: ApiKeyType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user