feat: 增加运行时工作空间契约
This commit is contained in:
1 parent
36f5415483
commit
549b488d51
3 files changed
+51
-4
No files matched your search
+32
-2
@@ -128,7 +128,7 @@ export class PublicWorkspaceController {
|
||||
@Get()
|
||||
async get(): Promise<unknown> {
|
||||
const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
||||
const [brand, modules, fields, offerings, inquiryForm] = await Promise.all([
|
||||
const [brand, modules, fields, offerings, inquiryForm, installation] = await Promise.all([
|
||||
this.prisma.brandProfile.findUnique({ where: { id: brandId } }),
|
||||
this.prisma.brandModule.findMany({
|
||||
where: { brandId, isEnabled: true },
|
||||
@@ -146,8 +146,38 @@ export class PublicWorkspaceController {
|
||||
where: { brandId, isEnabled: true },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
}),
|
||||
this.prisma.brandTemplateInstallation.findFirst({
|
||||
where: { brandId },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
}),
|
||||
]);
|
||||
return { brand, modules, fields, offerings, inquiryForm };
|
||||
const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
||||
const template = getBrandTemplate(templateKey);
|
||||
const runtimeModules = modules.map((module) => ({
|
||||
key: module.type,
|
||||
type: module.type,
|
||||
title: module.title,
|
||||
schemaVersion: "1.0",
|
||||
sortOrder: module.sortOrder,
|
||||
config: module.config,
|
||||
}));
|
||||
return {
|
||||
contractVersion: "1.0",
|
||||
brand,
|
||||
template: template
|
||||
? {
|
||||
key: template.key,
|
||||
version: installation?.templateVersion ?? template.version,
|
||||
name: template.name,
|
||||
}
|
||||
: null,
|
||||
capabilities: template?.capabilities ?? [],
|
||||
modules,
|
||||
runtimeModules,
|
||||
fields,
|
||||
offerings,
|
||||
inquiryForm,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,8 +102,14 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
assert.equal(JSON.parse(workspace.body).fields.length, 5);
|
||||
const publicWorkspace = await request("/public/workspace");
|
||||
assert.equal(publicWorkspace.statusCode, 200);
|
||||
assert.equal(JSON.parse(publicWorkspace.body).modules.length, 5);
|
||||
assert.equal(JSON.parse(publicWorkspace.body).inquiryForm, null);
|
||||
const workspaceBody = JSON.parse(publicWorkspace.body);
|
||||
assert.equal(workspaceBody.contractVersion, "1.0");
|
||||
assert.equal(workspaceBody.template.key, "personal");
|
||||
assert.deepEqual(workspaceBody.capabilities, ["offerings", "inquiry"]);
|
||||
assert.equal(workspaceBody.modules.length, 5);
|
||||
assert.equal(workspaceBody.runtimeModules.length, 5);
|
||||
assert.equal(workspaceBody.runtimeModules[0].schemaVersion, "1.0");
|
||||
assert.equal(workspaceBody.inquiryForm, null);
|
||||
const conflict = await request("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
|
||||
@@ -183,8 +183,19 @@ export interface InquirySubmission {
|
||||
inquiryForm?: { name: string };
|
||||
}
|
||||
export interface PublicWorkspace {
|
||||
contractVersion: string;
|
||||
brand: BrandProfile | null;
|
||||
template: { key: BrandTemplateKey; version: string; name: string } | null;
|
||||
capabilities: string[];
|
||||
modules: BrandModule[];
|
||||
runtimeModules: Array<{
|
||||
key: string;
|
||||
type: string;
|
||||
title: string;
|
||||
schemaVersion: string;
|
||||
sortOrder: number;
|
||||
config?: Record<string, unknown> | null;
|
||||
}>;
|
||||
fields: BrandFieldDefinition[];
|
||||
offerings: Offering[];
|
||||
inquiryForm: InquiryForm | null;
|
||||
|
||||
Reference in new issue
Block a user