* feat: add view_configurations feature flag - Add feature flag provider and hooks to admin dashboard - Add backend API endpoint for feature flags - Create view_configurations feature flag (disabled by default) - Update order list table to use legacy version when flag is disabled - Can be enabled with MEDUSA_FF_VIEW_CONFIGURATIONS=true env var * fix: naming * fix: feature flags unauthenticated * fix: add test * feat: add settings module * fix: deps * fix: cleanup * fix: add more tetsts * fix: rm changelog * fix: deps * fix: add settings module to default modules list * feat(api): add view configuration API routes - Add CRUD endpoints for view configurations - Add active view configuration management endpoints - Add feature flag middleware for view config routes - Add comprehensive integration tests - Add HTTP types for view configuration payloads and responses - Support system defaults and user-specific configurations - Enable setting views as active during create/update operations * fix: test * fix: test * fix: test * fix: change view configuration path * fix: tests * fix: remove manual settings module config from integration tests * fix: container typing * fix: workflows
102 lines
2.4 KiB
TypeScript
102 lines
2.4 KiB
TypeScript
import {
|
|
ApiKeyDTO,
|
|
IApiKeyModuleService,
|
|
IAuthModuleService,
|
|
IUserModuleService,
|
|
MedusaContainer,
|
|
} from "@medusajs/framework/types"
|
|
import {
|
|
ApiKeyType,
|
|
ContainerRegistrationKeys,
|
|
Modules,
|
|
PUBLISHABLE_KEY_HEADER,
|
|
} from "@medusajs/framework/utils"
|
|
import jwt from "jsonwebtoken"
|
|
import Scrypt from "scrypt-kdf"
|
|
import { getContainer } from "../environment-helpers/use-container"
|
|
|
|
export const adminHeaders = {
|
|
headers: { "x-medusa-access-token": "test_token" },
|
|
}
|
|
|
|
export const createAdminUser = async (
|
|
dbConnection,
|
|
adminHeaders,
|
|
container?,
|
|
options?: { email?: string }
|
|
) => {
|
|
const appContainer = container ?? getContainer()!
|
|
const email = options?.email ?? "admin@medusa.js"
|
|
|
|
const userModule: IUserModuleService = appContainer.resolve(Modules.USER)
|
|
const authModule: IAuthModuleService = appContainer.resolve(Modules.AUTH)
|
|
const user = await userModule.createUsers({
|
|
first_name: "Admin",
|
|
last_name: "User",
|
|
email,
|
|
})
|
|
|
|
const hashConfig = { logN: 15, r: 8, p: 1 }
|
|
const passwordHash = await Scrypt.kdf("somepassword", hashConfig)
|
|
|
|
const authIdentity = await authModule.createAuthIdentities({
|
|
provider_identities: [
|
|
{
|
|
provider: "emailpass",
|
|
entity_id: email,
|
|
provider_metadata: {
|
|
password: passwordHash.toString("base64"),
|
|
},
|
|
},
|
|
],
|
|
app_metadata: {
|
|
user_id: user.id,
|
|
},
|
|
})
|
|
|
|
const config = container.resolve(ContainerRegistrationKeys.CONFIG_MODULE)
|
|
const { projectConfig } = config
|
|
const { jwtSecret, jwtOptions } = projectConfig.http
|
|
const token = jwt.sign(
|
|
{
|
|
actor_id: user.id,
|
|
actor_type: "user",
|
|
auth_identity_id: authIdentity.id,
|
|
},
|
|
jwtSecret,
|
|
{
|
|
expiresIn: "1d",
|
|
...jwtOptions,
|
|
}
|
|
)
|
|
|
|
adminHeaders.headers["authorization"] = `Bearer ${token}`
|
|
|
|
return { user, authIdentity }
|
|
}
|
|
|
|
export const generatePublishableKey = async (container?: MedusaContainer) => {
|
|
const appContainer = container ?? getContainer()!
|
|
const apiKeyModule = appContainer.resolve<IApiKeyModuleService>(
|
|
Modules.API_KEY
|
|
)
|
|
|
|
return await apiKeyModule.createApiKeys({
|
|
title: "test publishable key",
|
|
type: ApiKeyType.PUBLISHABLE,
|
|
created_by: "test",
|
|
})
|
|
}
|
|
|
|
export const generateStoreHeaders = ({
|
|
publishableKey,
|
|
}: {
|
|
publishableKey: ApiKeyDTO
|
|
}) => {
|
|
return {
|
|
headers: {
|
|
[PUBLISHABLE_KEY_HEADER]: publishableKey.token,
|
|
},
|
|
}
|
|
}
|