diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index d1edde5..462231d 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -128,7 +128,7 @@ export class PublicWorkspaceController { @Get() async get(): Promise { 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, + }; } } diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 86ca542..c6dd291 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -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}` }, diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index 92d3f34..727e3a2 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -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 | null; + }>; fields: BrandFieldDefinition[]; offerings: Offering[]; inquiryForm: InquiryForm | null;