refactor: 模板注册与默认模板收敛到目录驱动
This commit is contained in:
1 parent
f87b26b201
commit
89fdfd7d83
25 files changed
+122
-96
No files matched your search
@@ -2,6 +2,7 @@ node_modules/
|
||||
.pnpm-store/
|
||||
.turbo/
|
||||
dist/
|
||||
packages/config/dist/
|
||||
.next/
|
||||
coverage/
|
||||
.env
|
||||
|
||||
@@ -104,7 +104,7 @@ export function RecordContentEditor({
|
||||
onClick={() =>
|
||||
navigate("/admin/brand", {
|
||||
state: {
|
||||
targetKey: visualSelection?.targetKey ?? "linjing-editorial.offerings.item",
|
||||
targetKey: visualSelection?.targetKey ?? "offering.list.item",
|
||||
recordId: record.id,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -48,6 +48,10 @@ export function BrandPage() {
|
||||
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
||||
enabled: Boolean(brand.data?.templateKey),
|
||||
});
|
||||
const templateCatalog = useQuery({
|
||||
queryKey: ["template-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const save = useMutation({
|
||||
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
||||
onSuccess: () => {
|
||||
@@ -190,10 +194,10 @@ export function BrandPage() {
|
||||
>
|
||||
<Select
|
||||
disabled
|
||||
options={[
|
||||
{ value: "personal", label: "个人品牌" },
|
||||
{ value: "food", label: "餐饮模板" },
|
||||
]}
|
||||
options={(templateCatalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
|
||||
@@ -3,8 +3,6 @@ import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
import { Alert } from "antd";
|
||||
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||
import "../../../../../packages/template-acheng-campus-food/taro/style.css";
|
||||
import "../../../../../packages/template-linjing-editorial/taro/style.css";
|
||||
import "./ComponentTemplatePreview.css";
|
||||
|
||||
type PreviewProps = {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { TemplatePage as FoodTemplatePage } from "../../../../../packages/template-acheng-campus-food/taro/index.tsx";
|
||||
import { TemplatePage as EditorialTemplatePage } from "../../../../../packages/template-linjing-editorial/taro/index.tsx";
|
||||
import React from "react";
|
||||
import { Inquiry } from "../../../../taro/src/components/Inquiry.tsx";
|
||||
import { Records } from "../../../../taro/src/components/Records.tsx";
|
||||
import { Success } from "../../../../taro/src/components/Success.tsx";
|
||||
import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||
|
||||
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
|
||||
eager: true,
|
||||
});
|
||||
|
||||
function pageContent({ workspace, page }) {
|
||||
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||
if (page === "records") return <Records workspace={workspace} preview />;
|
||||
@@ -13,28 +15,22 @@ function pageContent({ workspace, page }) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function FoodPreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value="acheng-campus-food">
|
||||
<FoodTemplatePage {...props}>{pageContent(props)}</FoodTemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
}
|
||||
function EditorialPreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value="linjing-editorial">
|
||||
<EditorialTemplatePage {...props}>{pageContent(props)}</EditorialTemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveTemplateRenderer(workspace) {
|
||||
const config = workspace?.brand?.config;
|
||||
const key =
|
||||
config && typeof config === "object" && !Array.isArray(config)
|
||||
? config.visualTemplateKey
|
||||
: undefined;
|
||||
if (key === "acheng-campus-food") return FoodPreview;
|
||||
if (key === "linjing-editorial") return EditorialPreview;
|
||||
return null;
|
||||
if (typeof key !== "string") return null;
|
||||
const suffix = `/template-${key}/taro/index.tsx`;
|
||||
const entry = Object.entries(templateRenderers).find(([path]) => path.endsWith(suffix));
|
||||
const TemplatePage = entry?.[1]?.TemplatePage;
|
||||
if (!TemplatePage) return null;
|
||||
return function TemplatePreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value={key}>
|
||||
<TemplatePage {...props}>{pageContent(props)}</TemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -147,14 +147,16 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
workspace.data?.installations[0]?.templateKey ??
|
||||
workspace.data?.brand?.templateKey ??
|
||||
brand.data?.templateKey ??
|
||||
"personal";
|
||||
const visuals = (catalog.data?.visuals ?? []).filter((item) =>
|
||||
item.supportedIndustryTemplates.includes(industryKey),
|
||||
catalog.data?.industries[0]?.key ??
|
||||
null;
|
||||
const visuals = (catalog.data?.visuals ?? []).filter(
|
||||
(item) =>
|
||||
typeof industryKey === "string" && item.supportedIndustryTemplates.includes(industryKey),
|
||||
);
|
||||
const visualKey =
|
||||
typeof brand.data?.config?.visualTemplateKey === "string"
|
||||
? brand.data.config.visualTemplateKey
|
||||
: "linjing-editorial";
|
||||
: (visuals[0]?.key ?? null);
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
|
||||
@@ -31,7 +31,7 @@ export function ServicesPage() {
|
||||
const listTarget = previewTargets.offerings.find((target) =>
|
||||
templateFields.some((field) => field.previewTarget === target.key),
|
||||
) ?? {
|
||||
key: "linjing-editorial.offerings.item",
|
||||
key: "offering.list.item",
|
||||
label: "业务卡片",
|
||||
page: "offerings",
|
||||
source: "offering",
|
||||
|
||||
@@ -51,8 +51,8 @@ export function WorkspacePage() {
|
||||
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
|
||||
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
||||
const [industryTarget, setIndustryTarget] = useState<IndustryTarget | null>(null);
|
||||
const [previewIndustry, setPreviewIndustry] = useState<BrandTemplateKey>("personal");
|
||||
const [previewVisual, setPreviewVisual] = useState("linjing-editorial");
|
||||
const [previewIndustry, setPreviewIndustry] = useState<BrandTemplateKey | null>(null);
|
||||
const [previewVisual, setPreviewVisual] = useState<string | null>(null);
|
||||
const [form] = Form.useForm<Record<string, unknown>>();
|
||||
const [inquiryForm] = Form.useForm<Record<string, unknown>>();
|
||||
const openNewInquiryForm = () => {
|
||||
@@ -69,14 +69,28 @@ export function WorkspacePage() {
|
||||
setFormOpen(true);
|
||||
};
|
||||
const { query, runtimeQuery, templateCatalog, forms, templatePreview } = useWorkspaceQueries();
|
||||
const previewIndustryKey =
|
||||
previewIndustry ??
|
||||
query.data?.installations[0]?.templateKey ??
|
||||
query.data?.brand.templateKey ??
|
||||
templateCatalog.data?.industries[0]?.key;
|
||||
const previewVisualKey =
|
||||
previewVisual ??
|
||||
runtimeQuery.data?.visualTemplate?.key ??
|
||||
(templateCatalog.data?.visuals ?? []).find((visual) =>
|
||||
supportsIndustry(visual, previewIndustryKey ?? ""),
|
||||
)?.key;
|
||||
const combinationPreview = useQuery({
|
||||
queryKey: ["template-combination-preview", previewIndustry, previewVisual],
|
||||
queryKey: ["template-combination-preview", previewIndustryKey, previewVisualKey],
|
||||
queryFn: () =>
|
||||
createApiClient().previewPublicTemplateCombination(previewIndustry, previewVisual),
|
||||
enabled: Boolean(templateCatalog.data),
|
||||
createApiClient().previewPublicTemplateCombination(
|
||||
previewIndustryKey ?? "",
|
||||
previewVisualKey ?? "",
|
||||
),
|
||||
enabled: Boolean(templateCatalog.data && previewIndustryKey && previewVisualKey),
|
||||
});
|
||||
const compatibleVisuals = (templateCatalog.data?.visuals ?? []).filter((visual) =>
|
||||
supportsIndustry(visual, query.data?.brand?.templateKey ?? "personal"),
|
||||
supportsIndustry(visual, query.data?.brand?.templateKey ?? ""),
|
||||
);
|
||||
const { visualTemplate, rollbackVisual, install, upgrade, rollback } = useTemplateMutations({
|
||||
runtimeConfig: runtimeQuery.data?.brand?.config ?? undefined,
|
||||
@@ -185,9 +199,9 @@ export function WorkspacePage() {
|
||||
<Space wrap>
|
||||
<Typography.Text strong>视觉模板</Typography.Text>
|
||||
<Select
|
||||
value={runtimeQuery.data?.visualTemplate?.key ?? "linjing-editorial"}
|
||||
value={runtimeQuery.data?.visualTemplate?.key}
|
||||
loading={visualTemplate.isPending}
|
||||
onChange={(key) => setVisualTarget(key)}
|
||||
onChange={(key) => setVisualTarget(key ?? null)}
|
||||
options={[
|
||||
...compatibleVisuals.map((visual) => ({ value: visual.key, label: visual.name })),
|
||||
]}
|
||||
@@ -354,18 +368,18 @@ export function WorkspacePage() {
|
||||
</Typography.Paragraph>
|
||||
<Space wrap>
|
||||
<Select
|
||||
value={previewIndustry}
|
||||
onChange={setPreviewIndustry}
|
||||
value={previewIndustryKey ?? null}
|
||||
onChange={(key) => setPreviewIndustry(key)}
|
||||
options={(templateCatalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
/>
|
||||
<Select
|
||||
value={previewVisual}
|
||||
onChange={setPreviewVisual}
|
||||
value={previewVisualKey ?? null}
|
||||
onChange={(key) => setPreviewVisual(key)}
|
||||
options={(templateCatalog.data?.visuals ?? [])
|
||||
.filter((item) => supportsIndustry(item, previewIndustry))
|
||||
.filter((item) => supportsIndustry(item, previewIndustryKey ?? ""))
|
||||
.map((item) => ({ value: item.key, label: item.name }))}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
@@ -11,10 +11,12 @@ import {
|
||||
Max,
|
||||
Min,
|
||||
} from "class-validator";
|
||||
import { brandTemplateKeys } from "@personal-brand/config";
|
||||
import type { BrandTemplateKey } from "@personal-brand/config";
|
||||
|
||||
export class UpdateBrandDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@IsOptional() @IsIn(["food", "personal", "doors"]) templateKey?: "food" | "personal" | "doors";
|
||||
@IsOptional() @IsIn(brandTemplateKeys) templateKey?: BrandTemplateKey;
|
||||
@IsOptional() @IsString() tagline?: string;
|
||||
@IsOptional() @IsString() description?: string;
|
||||
@IsOptional() @IsString() avatarUrl?: string;
|
||||
@@ -101,8 +103,8 @@ export class UpdateBookingTagsDto {
|
||||
}
|
||||
|
||||
export class InstallTemplateDto {
|
||||
@IsIn(["personal", "food", "doors"])
|
||||
templateKey!: "personal" | "food" | "doors";
|
||||
@IsIn(brandTemplateKeys)
|
||||
templateKey!: BrandTemplateKey;
|
||||
}
|
||||
|
||||
export class UpdateCapabilityInstallationDto {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import {
|
||||
defaultBrandTemplateKey,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
isVisualTemplateCompatible,
|
||||
@@ -67,7 +68,7 @@ export class BrandReleaseApiService {
|
||||
const visualKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||
const visual = getVisualTemplate(visualKey);
|
||||
const packageManifest = getTemplatePackageManifestForVisualKey(visualKey);
|
||||
const [offerings, forms, trustItems] = await Promise.all([
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import {
|
||||
defaultBrandTemplateKey,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
getVisualTemplateManifest,
|
||||
@@ -44,7 +45,7 @@ export async function buildBrandReleaseSnapshot(
|
||||
database.trustContent.findMany({ where: { brandId }, orderBy: { sortOrder: "asc" } }),
|
||||
database.capabilityInstallation.findMany({ where: { brandId } }),
|
||||
]);
|
||||
const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
||||
const templateKey = installation?.templateKey ?? brand?.templateKey ?? defaultBrandTemplateKey;
|
||||
const config =
|
||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||
? (brand.config as Record<string, unknown>)
|
||||
@@ -52,7 +53,7 @@ export async function buildBrandReleaseSnapshot(
|
||||
const visualKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||
const jsonObject = (value: object): Record<string, unknown> =>
|
||||
JSON.parse(JSON.stringify(value)) as Record<string, unknown>;
|
||||
return {
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
UpdateTrustContentDto,
|
||||
} from "../../admin.dto.js";
|
||||
import {
|
||||
defaultVisualTemplateKey,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
isVisualTemplateCompatible,
|
||||
@@ -278,7 +279,7 @@ export class AdminConfigController {
|
||||
const currentKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: "linjing-editorial";
|
||||
: defaultVisualTemplateKey;
|
||||
const current = getVisualTemplate(currentKey);
|
||||
return {
|
||||
current: current
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { BrandReleaseSnapshot } from "../../brand-release.service.js";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import {
|
||||
capabilityPlugins,
|
||||
defaultBrandTemplateKey,
|
||||
type BrandTemplateKey,
|
||||
getBrandTemplate,
|
||||
getDefaultVisualTemplateKey,
|
||||
@@ -96,7 +97,7 @@ export function assemblePublicWorkspace(input: {
|
||||
asString(releaseSnapshot.templateKey) ||
|
||||
asString(installationData.templateKey) ||
|
||||
asString(brandData.templateKey) ||
|
||||
"personal";
|
||||
defaultBrandTemplateKey;
|
||||
const template = releaseSnapshot.templateDefinition ?? getBrandTemplate(templateKey);
|
||||
const capabilityData = asArray(releaseSnapshot.capabilities) as Array<Record<string, unknown>>;
|
||||
const capabilities = capabilityData.length
|
||||
|
||||
@@ -2,12 +2,16 @@ import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/comm
|
||||
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||
import { BrandReleaseService } from "../../brand-release.service.js";
|
||||
import {
|
||||
defaultBrandTemplateKey,
|
||||
defaultVisualTemplateKey,
|
||||
brandTemplates,
|
||||
brandTemplateKeys,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
isVisualTemplateCompatible,
|
||||
resolveCapabilities,
|
||||
visualTemplates,
|
||||
visualTemplateKeys,
|
||||
} from "@personal-brand/config";
|
||||
|
||||
@Controller("public")
|
||||
@@ -74,15 +78,15 @@ export class PublicTemplateController {
|
||||
@Get()
|
||||
list(): unknown {
|
||||
return {
|
||||
industries: Object.values(brandTemplates),
|
||||
visuals: Object.values(visualTemplates),
|
||||
industries: brandTemplateKeys.map((key) => brandTemplates[key]),
|
||||
visuals: visualTemplateKeys.map((key) => visualTemplates[key]),
|
||||
};
|
||||
}
|
||||
|
||||
@Get("preview")
|
||||
preview(
|
||||
@Query("industry") industry = "personal",
|
||||
@Query("visual") visual = "linjing-editorial",
|
||||
@Query("industry") industry = defaultBrandTemplateKey,
|
||||
@Query("visual") visual = defaultVisualTemplateKey,
|
||||
): unknown {
|
||||
const industryTemplate = getBrandTemplate(industry);
|
||||
const visualTemplate = getVisualTemplate(visual);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import {
|
||||
defaultBrandTemplateKey,
|
||||
getDefaultVisualTemplateKey,
|
||||
getTemplatePackageManifestForVisualKey,
|
||||
} from "@personal-brand/config";
|
||||
@@ -28,7 +29,7 @@ export class AdminWorkspaceService {
|
||||
const templateKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||
const manifest = getTemplatePackageManifestForVisualKey(templateKey);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import {
|
||||
type BrandTemplateKey,
|
||||
defaultBrandTemplateKey,
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
getVisualTemplateManifest,
|
||||
@@ -9,7 +11,6 @@ import {
|
||||
isVisualTemplateCompatible,
|
||||
} from "@personal-brand/config";
|
||||
import type { CreateTrustContentDto, UpdateTrustContentDto } from "./admin.dto.js";
|
||||
import type { BrandTemplateKey } from "@personal-brand/types";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
|
||||
@Injectable()
|
||||
@@ -27,7 +28,7 @@ export class TemplateWorkspaceService {
|
||||
const visualKey =
|
||||
typeof config.visualTemplateKey === "string"
|
||||
? config.visualTemplateKey
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? defaultBrandTemplateKey);
|
||||
return (
|
||||
getTemplatePackageManifestForVisualKey(visualKey)?.trustContentTypes?.map(
|
||||
(item) => item.type,
|
||||
@@ -72,10 +73,12 @@ export class TemplateWorkspaceService {
|
||||
select: { templateKey: true },
|
||||
}),
|
||||
]);
|
||||
const key = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
||||
return getBrandTemplate(key) ? (key as BrandTemplateKey) : "personal";
|
||||
const key =
|
||||
getBrandTemplate(installation?.templateKey ?? brand?.templateKey ?? defaultBrandTemplateKey)
|
||||
?.key ?? defaultBrandTemplateKey;
|
||||
return key;
|
||||
}
|
||||
async install(brandId: string, templateKey: "personal" | "food" | "doors") {
|
||||
async install(brandId: string, templateKey: BrandTemplateKey) {
|
||||
const template = getBrandTemplate(templateKey);
|
||||
if (!template) throw new BadRequestException("行业模板不存在");
|
||||
const [existing, brand] = await Promise.all([
|
||||
|
||||
@@ -34,7 +34,8 @@ export function Inquiry({
|
||||
const [sending, setSending] = useState(false);
|
||||
const busy = useRef(false);
|
||||
const p = presentation(workspace, "inquiry");
|
||||
const food = workspace.brand.visualTemplateKey === "acheng-campus-food";
|
||||
const compactFieldKeys = new Set(["people", "date", "budget", "delivery"]);
|
||||
const compactForm = Boolean(form?.fields.some((field) => compactFieldKeys.has(field.key)));
|
||||
useDidShow(() => {
|
||||
const query = takeQuery("inquiry");
|
||||
if (query.offeringId) setOfferingId(query.offeringId);
|
||||
@@ -82,7 +83,7 @@ export function Inquiry({
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={`inquiry-page ${food ? "food-inquiry" : "editorial-inquiry"}`}>
|
||||
<View className={`inquiry-page ${compactForm ? "food-inquiry" : "editorial-inquiry"}`}>
|
||||
<View className="form-intro">
|
||||
<Text className="eyebrow">{p.eyebrow}</Text>
|
||||
<Text className="form-title">{p.title || "提交咨询"}</Text>
|
||||
@@ -98,10 +99,10 @@ export function Inquiry({
|
||||
const value = values[field.key];
|
||||
const stringValue = typeof value === "string" ? value : "";
|
||||
const chips =
|
||||
food && field.key === "type" && ["select", "radio"].includes(field.type);
|
||||
compactForm && field.key === "type" && ["select", "radio"].includes(field.type);
|
||||
return (
|
||||
<View
|
||||
className={`form-field ${food && ["people", "date", "budget", "delivery"].includes(field.key) ? "half-field" : ""}`}
|
||||
className={`form-field ${compactForm && compactFieldKeys.has(field.key) ? "half-field" : ""}`}
|
||||
key={field.key}
|
||||
data-editor-target={preview ? `inquiry-field:${field.key}` : undefined}
|
||||
>
|
||||
|
||||
@@ -57,7 +57,7 @@ export interface TemplateMethods {
|
||||
templateContent: AdminTemplateContent | null;
|
||||
}>;
|
||||
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace>;
|
||||
installAdminTemplate(templateKey: "personal" | "food" | "doors"): Promise<unknown>;
|
||||
installAdminTemplate(templateKey: BrandTemplateKey): Promise<unknown>;
|
||||
listAdminCapabilities(): Promise<CapabilityInstallation[]>;
|
||||
updateAdminCapability(
|
||||
key: string,
|
||||
@@ -111,8 +111,7 @@ export function templateMethods({ request }: { request: RequestFn }): TemplateMe
|
||||
description: String(visual.description ?? ""),
|
||||
supportedIndustryTemplates: Array.isArray(visual.supportedIndustryTemplates)
|
||||
? visual.supportedIndustryTemplates.filter(
|
||||
(item): item is BrandTemplateKey =>
|
||||
item === "personal" || item === "food" || item === "doors",
|
||||
(item): item is BrandTemplateKey => typeof item === "string",
|
||||
)
|
||||
: [],
|
||||
variants:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface BrandTemplateDefinition {
|
||||
key: "personal" | "food" | "doors";
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
|
||||
@@ -135,5 +135,9 @@ export function isBrandTemplateKey(value: string): value is BrandTemplateKey {
|
||||
}
|
||||
|
||||
export function getBrandTemplate(key: string): BrandTemplateDefinition | undefined {
|
||||
return isBrandTemplateKey(key) ? brandTemplates[key] : undefined;
|
||||
return isBrandTemplateKey(key) ? brandTemplates[key as keyof typeof brandTemplates] : undefined;
|
||||
}
|
||||
|
||||
export const defaultBrandTemplateKey = "personal" satisfies BrandTemplateKey;
|
||||
|
||||
export const brandTemplateKeys = Object.keys(brandTemplates);
|
||||
@@ -1,3 +1,3 @@
|
||||
export type BrandTemplateKey = "personal" | "food" | "doors";
|
||||
export type VisualTemplateKey = "linjing-editorial" | "acheng-campus-food";
|
||||
export type BrandTemplateKey = string;
|
||||
export type VisualTemplateKey = string;
|
||||
export type CapabilityKey = "offerings" | "inquiry" | "booking" | "quote-request";
|
||||
@@ -130,15 +130,15 @@ const personalSampleContent: TemplateSampleContent = {
|
||||
capabilityKey: "inquiry",
|
||||
};
|
||||
|
||||
export const templateSampleContent: Record<BrandTemplateKey, TemplateSampleContent> = {
|
||||
export const templateSampleContent = {
|
||||
personal: personalSampleContent,
|
||||
food: foodSampleContent,
|
||||
doors: doorsSampleContent,
|
||||
};
|
||||
} as const;
|
||||
|
||||
export function getTemplateSampleContent(templateKey: string): TemplateSampleContent | undefined {
|
||||
const packageSample = templatePackageRegistry.find((item) =>
|
||||
item.supportedIndustryTemplates.includes(templateKey as BrandTemplateKey),
|
||||
)?.sampleContent?.[templateKey as BrandTemplateKey];
|
||||
item.supportedIndustryTemplates.includes(templateKey),
|
||||
)?.sampleContent?.[templateKey];
|
||||
return packageSample ?? templateSampleContent[templateKey as keyof typeof templateSampleContent];
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { BrandTemplateKey } from "./template-keys.js";
|
||||
import type { VisualTemplateKey } from "./template-keys.js";
|
||||
import type { VisualTemplateDefinition, VisualTemplateManifest } from "./brand-contracts.js";
|
||||
|
||||
@@ -269,14 +268,12 @@ export const visualTemplateManifests: Record<VisualTemplateKey, VisualTemplateMa
|
||||
};
|
||||
|
||||
export function getVisualTemplateManifest(key: string): VisualTemplateManifest | undefined {
|
||||
return visualTemplateManifests[key as VisualTemplateKey];
|
||||
return visualTemplateManifests[key];
|
||||
}
|
||||
|
||||
export function isVisualTemplateCompatible(
|
||||
visualTemplate: VisualTemplateDefinition | VisualTemplateManifest,
|
||||
industryTemplateKey: string,
|
||||
): boolean {
|
||||
return visualTemplate.supportedIndustryTemplates.includes(
|
||||
industryTemplateKey as BrandTemplateKey,
|
||||
);
|
||||
return visualTemplate.supportedIndustryTemplates.includes(industryTemplateKey);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { BrandTemplateKey } from "./template-keys.js";
|
||||
import type { VisualTemplateKey } from "./template-keys.js";
|
||||
import type { VisualTemplateDefinition } from "./brand-contracts.js";
|
||||
|
||||
@@ -42,19 +41,21 @@ export const visualTemplates: Record<VisualTemplateKey, VisualTemplateDefinition
|
||||
};
|
||||
|
||||
export function listVisualTemplateKeys(): VisualTemplateKey[] {
|
||||
return Object.keys(visualTemplates) as VisualTemplateKey[];
|
||||
return Object.keys(visualTemplates);
|
||||
}
|
||||
|
||||
export const visualTemplateKeys = listVisualTemplateKeys();
|
||||
|
||||
export function getVisualTemplate(key: string): VisualTemplateDefinition | undefined {
|
||||
return visualTemplates[key as VisualTemplateKey];
|
||||
return visualTemplates[key];
|
||||
}
|
||||
|
||||
export function getDefaultVisualTemplateKey(industryTemplateKey: string): VisualTemplateKey {
|
||||
return (
|
||||
listVisualTemplateKeys().find((key) =>
|
||||
visualTemplates[key].supportedIndustryTemplates.includes(
|
||||
industryTemplateKey as BrandTemplateKey,
|
||||
),
|
||||
) ?? "linjing-editorial"
|
||||
getVisualTemplate(key)?.supportedIndustryTemplates.includes(industryTemplateKey),
|
||||
) ?? defaultVisualTemplateKey
|
||||
);
|
||||
}
|
||||
|
||||
export const defaultVisualTemplateKey = "linjing-editorial" satisfies VisualTemplateKey;
|
||||
@@ -3,12 +3,7 @@ export type BookingRequestType = "package" | "private_chef" | "inquiry";
|
||||
export type ContactPreference = "wechat" | "phone" | "none";
|
||||
export type FulfillmentType = "pickup" | "delivery";
|
||||
export type OrderStatus = BookingStatus;
|
||||
export type BrandTemplateKey = "food" | "personal" | "doors";
|
||||
export const BRAND_TEMPLATE = {
|
||||
FOOD: "food",
|
||||
PERSONAL: "personal",
|
||||
DOORS: "doors",
|
||||
} as const satisfies Record<Uppercase<BrandTemplateKey>, BrandTemplateKey>;
|
||||
export type BrandTemplateKey = string;
|
||||
|
||||
export const HTTP_STATUS = {
|
||||
OK: 200,
|
||||
|
||||
Reference in new issue
Block a user