refactor: 拆分 API Client 资源模块
This commit is contained in:
1 parent
f3adf7bc15
commit
357f271639
24 files changed
+1280
-905
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import type { ApiErrorBody } from "../types/common.js";
|
||||
|
||||
export interface FetchResponse {
|
||||
readonly status: number;
|
||||
readonly ok: boolean;
|
||||
json(): Promise<unknown>;
|
||||
}
|
||||
|
||||
export type FetchLike = (
|
||||
input: string,
|
||||
init?: { method?: string; headers?: Record<string, string>; body?: string },
|
||||
) => Promise<FetchResponse>;
|
||||
|
||||
export interface ApiClientOptions {
|
||||
baseUrl: string;
|
||||
fetcher: FetchLike;
|
||||
token?: string;
|
||||
}
|
||||
|
||||
export type RequestFn = <T>(
|
||||
path: string,
|
||||
options?: { method?: string; body?: unknown },
|
||||
) => Promise<T>;
|
||||
|
||||
export async function request<T>(
|
||||
state: { baseUrl: string; fetcher: FetchLike; token?: string | undefined },
|
||||
path: string,
|
||||
options: { method?: string; body?: unknown } = {},
|
||||
): Promise<T> {
|
||||
const headers: Record<string, string> = { accept: "application/json" };
|
||||
if (options.body !== undefined) headers["content-type"] = "application/json";
|
||||
if (state.token) headers.authorization = `Bearer ${state.token}`;
|
||||
const response = await state.fetcher(`${state.baseUrl}${path}`, {
|
||||
method: options.method ?? "GET",
|
||||
headers,
|
||||
...(options.body === undefined ? {} : { body: JSON.stringify(options.body) }),
|
||||
});
|
||||
const body = await response.json();
|
||||
if (!response.ok) throw new ApiClientError(response.status, body as ApiErrorBody);
|
||||
return body as T;
|
||||
}
|
||||
|
||||
export class ApiClientError extends Error {
|
||||
constructor(
|
||||
readonly status: number,
|
||||
readonly body: ApiErrorBody,
|
||||
) {
|
||||
super(body.error.message);
|
||||
this.name = "ApiClientError";
|
||||
}
|
||||
|
||||
get code(): string {
|
||||
return this.body.error.code;
|
||||
}
|
||||
|
||||
get requestId(): string | null {
|
||||
return this.body.requestId;
|
||||
}
|
||||
}
|
||||
+272
-905
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,55 @@
|
||||
import type { BookingStatus } from "@personal-brand/types";
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type {
|
||||
AdminBooking,
|
||||
Booking,
|
||||
BookingTag,
|
||||
CreateBookingInput,
|
||||
BookingSummary,
|
||||
} from "../types/booking.js";
|
||||
|
||||
export interface BookingMethods {
|
||||
listCustomerBookings(): Promise<Booking[]>;
|
||||
createCustomerBooking(input: CreateBookingInput): Promise<BookingSummary>;
|
||||
cancelCustomerBooking(id: string): Promise<Booking>;
|
||||
listAdminBookings(filters?: {
|
||||
status?: BookingStatus;
|
||||
unreadOnly?: boolean;
|
||||
tagId?: string;
|
||||
}): Promise<AdminBooking[]>;
|
||||
getAdminBooking(id: string): Promise<AdminBooking>;
|
||||
getAdminUnreadCount(): Promise<{ count: number }>;
|
||||
updateAdminBookingStatus(id: string, status: BookingStatus, adminNote?: string): Promise<Booking>;
|
||||
markAdminBookingRead(id: string): Promise<Booking>;
|
||||
listAdminTags(): Promise<BookingTag[]>;
|
||||
createAdminTag(name: string): Promise<BookingTag>;
|
||||
}
|
||||
|
||||
export function bookingMethods({ request }: { request: RequestFn }): BookingMethods {
|
||||
return {
|
||||
listCustomerBookings: () => request("/customer/bookings"),
|
||||
createCustomerBooking: (input) =>
|
||||
request("/customer/bookings", { method: "POST", body: input }),
|
||||
cancelCustomerBooking: (id) =>
|
||||
request(`/customer/bookings/${encodeURIComponent(id)}/cancel`, { method: "POST" }),
|
||||
listAdminBookings: (filters = {}) => {
|
||||
const params: string[] = [];
|
||||
if (filters.status) params.push(`status=${encodeURIComponent(filters.status)}`);
|
||||
if (filters.unreadOnly !== undefined) params.push(`unreadOnly=${filters.unreadOnly}`);
|
||||
if (filters.tagId) params.push(`tagId=${encodeURIComponent(filters.tagId)}`);
|
||||
const query = params.join("&");
|
||||
return request(`/admin/bookings${query ? `?${query}` : ""}`);
|
||||
},
|
||||
getAdminBooking: (id) => request(`/admin/bookings/${encodeURIComponent(id)}`),
|
||||
getAdminUnreadCount: () => request("/admin/bookings/unread-count"),
|
||||
updateAdminBookingStatus: (id, status, adminNote) =>
|
||||
request(`/admin/bookings/${encodeURIComponent(id)}/status`, {
|
||||
method: "POST",
|
||||
body: { status, ...(adminNote === undefined ? {} : { adminNote }) },
|
||||
}),
|
||||
markAdminBookingRead: (id) =>
|
||||
request(`/admin/bookings/${encodeURIComponent(id)}/read`, { method: "POST" }),
|
||||
listAdminTags: () => request("/admin/bookings/tags"),
|
||||
createAdminTag: (name) => request("/admin/bookings/tags", { method: "POST", body: { name } }),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type {
|
||||
AdminBrandMember,
|
||||
AdminBrandMembership,
|
||||
BrandPresentationUpdate,
|
||||
BrandProfile,
|
||||
BrandReleaseSummary,
|
||||
BrandUpdate,
|
||||
} from "../types/brand.js";
|
||||
|
||||
export interface BrandMethods {
|
||||
getAdminBrand(): Promise<BrandProfile>;
|
||||
listAdminBrands(): Promise<AdminBrandMembership[]>;
|
||||
switchAdminBrand(
|
||||
brandId: string,
|
||||
): Promise<{ token: string; brand: AdminBrandMembership["brand"] }>;
|
||||
listAdminMembers(): Promise<AdminBrandMember[]>;
|
||||
createAdminMember(body: {
|
||||
username: string;
|
||||
displayName: string;
|
||||
password: string;
|
||||
role: "owner" | "editor";
|
||||
}): Promise<AdminBrandMember>;
|
||||
updateAdminMember(
|
||||
id: string,
|
||||
body: Partial<Pick<AdminBrandMember, "role" | "isEnabled">>,
|
||||
): Promise<AdminBrandMember>;
|
||||
getAdminVisualTemplatePreview(): Promise<{
|
||||
current: {
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
theme: { colors: Record<string, string> };
|
||||
variants: Record<string, string>;
|
||||
} | null;
|
||||
available: string[];
|
||||
}>;
|
||||
getAdminVisualTemplateHistory(): Promise<{
|
||||
history: Array<{ visualTemplateKey: string; savedAt: string }>;
|
||||
}>;
|
||||
rollbackAdminVisualTemplate(): Promise<{ visualTemplateKey: string; rolledBack: boolean }>;
|
||||
updateAdminBrand(body: BrandUpdate): Promise<BrandProfile>;
|
||||
updateAdminBrandPresentation(body: BrandPresentationUpdate): Promise<{
|
||||
visualPresentation: Record<string, Record<string, string>>;
|
||||
}>;
|
||||
listAdminReleases(): Promise<BrandReleaseSummary[]>;
|
||||
getAdminReleaseReadiness(): Promise<{
|
||||
ready: boolean;
|
||||
checks: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
passed: boolean;
|
||||
help?: string;
|
||||
destination?: string;
|
||||
}>;
|
||||
}>;
|
||||
publishAdminRelease(note?: string): Promise<BrandReleaseSummary>;
|
||||
rollbackAdminRelease(version: number, note?: string): Promise<BrandReleaseSummary>;
|
||||
revokeAdminRelease(): Promise<
|
||||
Pick<BrandReleaseSummary, "id" | "version" | "status" | "revokedAt">
|
||||
>;
|
||||
}
|
||||
|
||||
export function brandMethods({ request }: { request: RequestFn }): BrandMethods {
|
||||
return {
|
||||
getAdminBrand: () => request("/admin/config/brand"),
|
||||
listAdminBrands: () => request("/admin/brands"),
|
||||
switchAdminBrand: (brandId) =>
|
||||
request(`/admin/brands/${encodeURIComponent(brandId)}/switch`, { method: "POST" }),
|
||||
listAdminMembers: () => request("/admin/brands/members"),
|
||||
createAdminMember: (body) => request("/admin/brands/members", { method: "POST", body }),
|
||||
updateAdminMember: (id, body) =>
|
||||
request(`/admin/brands/members/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body,
|
||||
}),
|
||||
getAdminVisualTemplatePreview: () => request("/admin/config/visual-template/preview"),
|
||||
getAdminVisualTemplateHistory: () => request("/admin/config/visual-template/history"),
|
||||
rollbackAdminVisualTemplate: () =>
|
||||
request("/admin/config/visual-template/rollback", { method: "POST" }),
|
||||
updateAdminBrand: (body) => request("/admin/config/brand", { method: "PATCH", body }),
|
||||
updateAdminBrandPresentation: (body) =>
|
||||
request("/admin/config/presentation", { method: "PATCH", body }),
|
||||
listAdminReleases: () => request("/admin/releases"),
|
||||
getAdminReleaseReadiness: () => request("/admin/releases/readiness"),
|
||||
publishAdminRelease: (note) =>
|
||||
request("/admin/releases/publish", {
|
||||
method: "POST",
|
||||
body: note === undefined ? {} : { note },
|
||||
}),
|
||||
rollbackAdminRelease: (version, note) =>
|
||||
request(`/admin/releases/${version}/rollback`, {
|
||||
method: "POST",
|
||||
body: note === undefined ? {} : { note },
|
||||
}),
|
||||
revokeAdminRelease: () => request("/admin/releases/revoke", { method: "POST" }),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { BrandFieldDefinition } from "../types/field.js";
|
||||
import type { InquiryForm, InquirySubmission } from "../types/inquiry.js";
|
||||
|
||||
export interface InquiryMethods {
|
||||
createAdminField(
|
||||
body: Omit<BrandFieldDefinition, "id" | "source">,
|
||||
): Promise<BrandFieldDefinition>;
|
||||
deleteAdminField(id: string): Promise<{ deleted: boolean }>;
|
||||
listAdminInquiryForms(): Promise<InquiryForm[]>;
|
||||
listAdminInquirySubmissions(): Promise<InquirySubmission[]>;
|
||||
updateAdminInquirySubmission(
|
||||
id: string,
|
||||
body: { status: InquirySubmission["status"]; adminNote?: string },
|
||||
): Promise<InquirySubmission>;
|
||||
createAdminInquiryForm(body: {
|
||||
name: string;
|
||||
offeringId?: string;
|
||||
fieldsSnapshot: unknown[];
|
||||
isEnabled?: boolean;
|
||||
purpose?: InquiryForm["purpose"];
|
||||
targetType?: InquiryForm["targetType"];
|
||||
submissionAction?: InquiryForm["submissionAction"];
|
||||
}): Promise<InquiryForm>;
|
||||
updateAdminInquiryForm(
|
||||
id: string,
|
||||
body: Partial<{
|
||||
name: string;
|
||||
offeringId: string;
|
||||
fieldsSnapshot: unknown[];
|
||||
isEnabled: boolean;
|
||||
purpose?: InquiryForm["purpose"];
|
||||
targetType?: InquiryForm["targetType"];
|
||||
submissionAction?: InquiryForm["submissionAction"];
|
||||
}>,
|
||||
): Promise<InquiryForm>;
|
||||
}
|
||||
|
||||
export function inquiryMethods({ request }: { request: RequestFn }): InquiryMethods {
|
||||
return {
|
||||
createAdminField: (body) => request("/admin/workspace/fields", { method: "POST", body }),
|
||||
deleteAdminField: (id) =>
|
||||
request(`/admin/workspace/fields/${encodeURIComponent(id)}`, { method: "DELETE" }),
|
||||
listAdminInquiryForms: () => request("/admin/workspace/forms"),
|
||||
listAdminInquirySubmissions: () => request("/admin/workspace/submissions"),
|
||||
updateAdminInquirySubmission: (id, body) =>
|
||||
request(`/admin/workspace/submissions/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body,
|
||||
}),
|
||||
createAdminInquiryForm: (body) => request("/admin/workspace/forms", { method: "POST", body }),
|
||||
updateAdminInquiryForm: (id, body) =>
|
||||
request(`/admin/workspace/forms/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body,
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { PresignedUpload, UploadConfig } from "../types/media.js";
|
||||
|
||||
export interface MediaMethods {
|
||||
getUploadConfig(): Promise<UploadConfig>;
|
||||
createPresignedUpload(body: {
|
||||
fileName: string;
|
||||
contentType: string;
|
||||
scope?: "brand" | "offering" | "trust";
|
||||
}): Promise<PresignedUpload>;
|
||||
}
|
||||
|
||||
export function mediaMethods({ request }: { request: RequestFn }): MediaMethods {
|
||||
return {
|
||||
getUploadConfig: () => request("/admin/uploads/config"),
|
||||
createPresignedUpload: (body) => request("/admin/uploads/presign", { method: "POST", body }),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { Offering } from "../types/offering.js";
|
||||
|
||||
export interface OfferingMethods {
|
||||
getPublicOffering(id: string): Promise<Offering>;
|
||||
listPublicOfferings(): Promise<Offering[]>;
|
||||
listAdminOfferings(): Promise<Offering[]>;
|
||||
createAdminOffering(body: Omit<Offering, "id" | "brandId">): Promise<Offering>;
|
||||
updateAdminOffering(
|
||||
id: string,
|
||||
body: Partial<Omit<Offering, "id" | "brandId">>,
|
||||
): Promise<Offering>;
|
||||
deleteAdminOffering(id: string): Promise<{ deleted: boolean }>;
|
||||
}
|
||||
|
||||
export function offeringMethods({ request }: { request: RequestFn }): OfferingMethods {
|
||||
return {
|
||||
getPublicOffering: (id) => request(`/public/offerings/${encodeURIComponent(id)}`),
|
||||
listPublicOfferings: () => request("/public/offerings"),
|
||||
listAdminOfferings: () => request("/admin/workspace/offerings"),
|
||||
createAdminOffering: (body) => request("/admin/workspace/offerings", { method: "POST", body }),
|
||||
updateAdminOffering: (id, body) =>
|
||||
request(`/admin/workspace/offerings/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body,
|
||||
}),
|
||||
deleteAdminOffering: (id) =>
|
||||
request(`/admin/workspace/offerings/${encodeURIComponent(id)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { PublicOffering } from "@personal-brand/types";
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { BrandProfile } from "../types/brand.js";
|
||||
import type { InquiryForm, InquirySubmission } from "../types/inquiry.js";
|
||||
import type { PublicWorkspace } from "../types/workspace.js";
|
||||
|
||||
export interface PublicMethods {
|
||||
getBrand(): Promise<BrandProfile>;
|
||||
listOfferings(): Promise<PublicOffering[]>;
|
||||
getPublicWorkspace(): Promise<PublicWorkspace>;
|
||||
getPublicInquiryForm(id: string): Promise<InquiryForm>;
|
||||
createCustomerInquirySubmission(
|
||||
formId: string,
|
||||
values: Record<string, unknown>,
|
||||
): Promise<InquirySubmission>;
|
||||
listCustomerInquirySubmissions(): Promise<InquirySubmission[]>;
|
||||
getCustomerInquirySubmission(id: string): Promise<InquirySubmission>;
|
||||
createCustomerSession(code: string): Promise<{ token: string }>;
|
||||
}
|
||||
|
||||
export function publicMethods({ request }: { request: RequestFn }): PublicMethods {
|
||||
return {
|
||||
getBrand: () => request("/public/brand"),
|
||||
listOfferings: () => request("/public/offerings"),
|
||||
getPublicWorkspace: () => request("/public/workspace"),
|
||||
getPublicInquiryForm: (id) => request(`/public/inquiry-forms/${encodeURIComponent(id)}`),
|
||||
createCustomerInquirySubmission: (formId, values) =>
|
||||
request("/customer/inquiry-submissions", {
|
||||
method: "POST",
|
||||
body: { formId, values },
|
||||
}),
|
||||
listCustomerInquirySubmissions: () => request("/customer/inquiry-submissions"),
|
||||
getCustomerInquirySubmission: (id) =>
|
||||
request(`/customer/inquiry-submissions/${encodeURIComponent(id)}`),
|
||||
createCustomerSession: (code) =>
|
||||
request("/customer/session/wechat", { method: "POST", body: { code } }),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
|
||||
export interface SessionMethods {
|
||||
loginAdmin(
|
||||
username: string,
|
||||
password: string,
|
||||
): Promise<{
|
||||
token: string;
|
||||
displayName: string;
|
||||
mustChangePassword: boolean;
|
||||
role: string;
|
||||
}>;
|
||||
changeAdminPassword(currentPassword: string, newPassword: string): Promise<{ changed: true }>;
|
||||
}
|
||||
|
||||
export function sessionMethods({ request }: { request: RequestFn }): SessionMethods {
|
||||
return {
|
||||
loginAdmin: (username, password) =>
|
||||
request("/admin/session/login", { method: "POST", body: { username, password } }),
|
||||
changeAdminPassword: (currentPassword, newPassword) =>
|
||||
request("/admin/session/change-password", {
|
||||
method: "POST",
|
||||
body: { currentPassword, newPassword },
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import type { BrandTemplateKey, RuntimeWorkspace } from "@personal-brand/types";
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { BrandProfile } from "../types/brand.js";
|
||||
import type { CapabilityInstallation } from "../types/capability.js";
|
||||
import type { BrandFieldDefinition } from "../types/field.js";
|
||||
import type { Offering } from "../types/offering.js";
|
||||
import type { AdminTemplateContent } from "../types/template.js";
|
||||
import type { BrandTemplateDefinition } from "../types/template-definition.js";
|
||||
|
||||
export interface TemplateMethods {
|
||||
getPublicTemplate(key: BrandTemplateKey): Promise<BrandTemplateDefinition>;
|
||||
listPublicTemplates(): Promise<{
|
||||
industries: BrandTemplateDefinition[];
|
||||
visuals: Array<{
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
supportedIndustryTemplates: BrandTemplateKey[];
|
||||
variants: Record<string, string>;
|
||||
theme: { colors: Record<string, string> };
|
||||
}>;
|
||||
}>;
|
||||
previewPublicTemplateCombination(
|
||||
industry: string,
|
||||
visual: string,
|
||||
): Promise<{
|
||||
industry: BrandTemplateDefinition;
|
||||
visual: {
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
supportedIndustryTemplates: BrandTemplateKey[];
|
||||
variants: Record<string, string>;
|
||||
theme: { colors: Record<string, string> };
|
||||
};
|
||||
runtime: {
|
||||
schemaVersion: string;
|
||||
capabilities: Array<{ key: string; version: string }>;
|
||||
theme: unknown;
|
||||
};
|
||||
}>;
|
||||
getAdminWorkspace(): Promise<{
|
||||
brand: BrandProfile;
|
||||
visualTemplate?: {
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
supportedIndustryTemplates: BrandTemplateKey[];
|
||||
variants: Record<string, string>;
|
||||
} | null;
|
||||
installations: Array<{ id: string; templateKey: BrandTemplateKey; templateVersion: string }>;
|
||||
fields: BrandFieldDefinition[];
|
||||
offerings: Offering[];
|
||||
forms: unknown[];
|
||||
templateContent: AdminTemplateContent | null;
|
||||
}>;
|
||||
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace>;
|
||||
installAdminTemplate(templateKey: "personal" | "food" | "doors"): Promise<unknown>;
|
||||
listAdminCapabilities(): Promise<CapabilityInstallation[]>;
|
||||
updateAdminCapability(
|
||||
key: string,
|
||||
body: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
config?: Record<string, unknown>;
|
||||
},
|
||||
): Promise<CapabilityInstallation>;
|
||||
previewAdminSampleContent(): Promise<{
|
||||
templateKey: string;
|
||||
alreadyImported: boolean;
|
||||
counts: Record<string, number>;
|
||||
willCreateInquiryForm: boolean;
|
||||
}>;
|
||||
importAdminSampleContent(): Promise<{ imported: boolean; counts: Record<string, number> }>;
|
||||
getAdminTemplateUpgradePreview(): Promise<{
|
||||
currentVersion: string;
|
||||
latestVersion: string;
|
||||
canUpgrade: boolean;
|
||||
canRollback: boolean;
|
||||
missingModules: unknown[];
|
||||
missingFields: unknown[];
|
||||
}>;
|
||||
upgradeAdminTemplate(): Promise<unknown>;
|
||||
rollbackAdminTemplate(): Promise<unknown>;
|
||||
}
|
||||
|
||||
export function templateMethods({ request }: { request: RequestFn }): TemplateMethods {
|
||||
return {
|
||||
getPublicTemplate: (key) => request(`/public/templates/${key}`),
|
||||
listPublicTemplates: () =>
|
||||
request<{
|
||||
industries: BrandTemplateDefinition[];
|
||||
visuals: Array<{
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
supportedIndustryTemplates?: unknown;
|
||||
variants?: unknown;
|
||||
theme?: unknown;
|
||||
}>;
|
||||
}>("/public/templates").then((catalog) => ({
|
||||
industries: Array.isArray(catalog.industries) ? catalog.industries : [],
|
||||
visuals: Array.isArray(catalog.visuals)
|
||||
? catalog.visuals.map((visual) => ({
|
||||
key: String(visual.key ?? ""),
|
||||
version: String(visual.version ?? ""),
|
||||
name: String(visual.name ?? "未命名视觉模板"),
|
||||
description: String(visual.description ?? ""),
|
||||
supportedIndustryTemplates: Array.isArray(visual.supportedIndustryTemplates)
|
||||
? visual.supportedIndustryTemplates.filter(
|
||||
(item): item is BrandTemplateKey =>
|
||||
item === "personal" || item === "food" || item === "doors",
|
||||
)
|
||||
: [],
|
||||
variants:
|
||||
visual.variants && typeof visual.variants === "object"
|
||||
? (visual.variants as Record<string, string>)
|
||||
: {},
|
||||
theme:
|
||||
visual.theme && typeof visual.theme === "object"
|
||||
? (visual.theme as { colors: Record<string, string> })
|
||||
: { colors: {} },
|
||||
}))
|
||||
: [],
|
||||
})),
|
||||
previewPublicTemplateCombination: (industry, visual) =>
|
||||
request(
|
||||
`/public/templates/preview?industry=${encodeURIComponent(industry)}&visual=${encodeURIComponent(visual)}`,
|
||||
),
|
||||
getAdminWorkspace: () => request("/admin/workspace"),
|
||||
getAdminPreviewWorkspace: () => request("/admin/workspace/preview"),
|
||||
installAdminTemplate: (templateKey) =>
|
||||
request("/admin/workspace/install", { method: "POST", body: { templateKey } }),
|
||||
listAdminCapabilities: () => request("/admin/workspace/capabilities"),
|
||||
updateAdminCapability: (key, body) =>
|
||||
request(`/admin/workspace/capabilities/${encodeURIComponent(key)}`, {
|
||||
method: "PATCH",
|
||||
body,
|
||||
}),
|
||||
previewAdminSampleContent: () => request("/admin/workspace/sample-content/preview"),
|
||||
importAdminSampleContent: () =>
|
||||
request("/admin/workspace/sample-content/import", { method: "POST" }),
|
||||
getAdminTemplateUpgradePreview: () => request("/admin/workspace/template/preview"),
|
||||
upgradeAdminTemplate: () => request("/admin/workspace/template/upgrade", { method: "POST" }),
|
||||
rollbackAdminTemplate: () => request("/admin/workspace/template/rollback", { method: "POST" }),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { TrustContent, TrustContentInput } from "../types/trust.js";
|
||||
|
||||
export interface TrustMethods {
|
||||
listAdminTrustContent(): Promise<TrustContent[]>;
|
||||
createAdminTrustContent(body: TrustContentInput): Promise<TrustContent>;
|
||||
updateAdminTrustContent(id: string, body: Partial<TrustContentInput>): Promise<TrustContent>;
|
||||
deleteAdminTrustContent(id: string): Promise<{ deleted: boolean }>;
|
||||
}
|
||||
|
||||
export function trustMethods({ request }: { request: RequestFn }): TrustMethods {
|
||||
return {
|
||||
listAdminTrustContent: () => request("/admin/config/trust-content"),
|
||||
createAdminTrustContent: (body) =>
|
||||
request("/admin/config/trust-content", { method: "POST", body }),
|
||||
updateAdminTrustContent: (id, body) =>
|
||||
request(`/admin/config/trust-content/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
body,
|
||||
}),
|
||||
deleteAdminTrustContent: (id) =>
|
||||
request(`/admin/config/trust-content/${encodeURIComponent(id)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import type {
|
||||
BookingRequestType,
|
||||
BookingStatus,
|
||||
ContactPreference,
|
||||
FulfillmentType,
|
||||
} from "@personal-brand/types";
|
||||
|
||||
export interface BookingItemInput {
|
||||
offeringId: string;
|
||||
quantity: number;
|
||||
}
|
||||
|
||||
export interface CreateBookingInput {
|
||||
requestType: BookingRequestType;
|
||||
customerName: string;
|
||||
phone?: string;
|
||||
wechatId?: string;
|
||||
contactPreference: ContactPreference;
|
||||
fulfillmentType?: FulfillmentType;
|
||||
offeringId?: string;
|
||||
requestedDate?: string;
|
||||
requestedTime?: string;
|
||||
deliveryAddress?: string;
|
||||
note?: string;
|
||||
extraData?: Record<string, unknown>;
|
||||
items: BookingItemInput[];
|
||||
}
|
||||
|
||||
export interface BookingSummary {
|
||||
bookingNo: string;
|
||||
status: BookingStatus;
|
||||
estimatedAmount: number | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Booking extends BookingSummary {
|
||||
id: string;
|
||||
customerName: string;
|
||||
adminNote?: string | null;
|
||||
}
|
||||
|
||||
export interface BookingTag {
|
||||
id: string;
|
||||
name: string;
|
||||
isPreset: boolean;
|
||||
isEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface AdminBooking extends Booking {
|
||||
tags?: Array<{ tag: BookingTag }>;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { BrandTemplateKey } from "@personal-brand/types";
|
||||
|
||||
export interface BrandProfile {
|
||||
id: string;
|
||||
slug?: string;
|
||||
name: string;
|
||||
templateKey: BrandTemplateKey;
|
||||
tagline: string | null;
|
||||
description: string | null;
|
||||
avatarUrl: string | null;
|
||||
coverUrl: string | null;
|
||||
hours: string | null;
|
||||
address: string | null;
|
||||
deliveryNote: string | null;
|
||||
contactPhone: string | null;
|
||||
contactWechat: string | null;
|
||||
config?: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
export interface AdminBrandMembership {
|
||||
id: string;
|
||||
role: string;
|
||||
brand: Pick<BrandProfile, "id" | "name" | "templateKey"> & { slug?: string };
|
||||
}
|
||||
|
||||
export interface AdminBrandMember {
|
||||
id: string;
|
||||
role: string;
|
||||
isEnabled: boolean;
|
||||
adminUser: {
|
||||
id: string;
|
||||
username: string;
|
||||
displayName: string;
|
||||
isEnabled: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export type BrandUpdate = Partial<Omit<BrandProfile, "id">>;
|
||||
|
||||
export interface BrandReleaseSummary {
|
||||
id: string;
|
||||
version: number;
|
||||
status: string;
|
||||
note: string | null;
|
||||
actorId: string;
|
||||
createdAt: string;
|
||||
revokedAt: string | null;
|
||||
revokedBy?: string | null;
|
||||
}
|
||||
|
||||
export type BrandPresentationUpdate = Partial<
|
||||
Record<
|
||||
"identity" | "home" | "offerings" | "detail" | "profile" | "inquiry" | "success" | "records",
|
||||
Record<string, string>
|
||||
>
|
||||
>;
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface CapabilityInstallation {
|
||||
id: string | null;
|
||||
capabilityKey: string;
|
||||
capabilityVersion: string;
|
||||
status: "enabled" | "disabled" | "degraded";
|
||||
config?: Record<string, unknown> | null;
|
||||
updatedAt: string | null;
|
||||
source?: "template" | "brand";
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface ApiErrorBody {
|
||||
data: null;
|
||||
error: { code: string; message: string };
|
||||
requestId: string | null;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface BrandFieldDefinition {
|
||||
id: string;
|
||||
scope: string;
|
||||
key: string;
|
||||
label: string;
|
||||
type: string;
|
||||
required: boolean;
|
||||
isVisible: boolean;
|
||||
sortOrder: number;
|
||||
source: string;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
export interface InquiryForm {
|
||||
id: string;
|
||||
name: string;
|
||||
offeringId?: string | null;
|
||||
version: number;
|
||||
isEnabled: boolean;
|
||||
fieldsSnapshot: unknown[];
|
||||
purpose: "inquiry" | "booking" | "quote-request";
|
||||
targetType: "brand" | "offering";
|
||||
submissionAction: "create-inquiry" | "create-booking" | "create-quote";
|
||||
}
|
||||
|
||||
export interface InquirySubmission {
|
||||
id: string;
|
||||
inquiryFormId: string;
|
||||
formVersion: number;
|
||||
fieldsSnapshot: unknown[];
|
||||
values: Record<string, unknown>;
|
||||
activeFields: Record<string, boolean>;
|
||||
createdAt: string;
|
||||
status: "new" | "reviewing" | "replied" | "qualified" | "converted" | "closed";
|
||||
adminNote?: string | null;
|
||||
inquiryForm?: { name: string };
|
||||
offering?: { id: string; name: string } | null;
|
||||
statusHistory?: Array<{
|
||||
fromStatus?: string | null;
|
||||
toStatus: string;
|
||||
createdAt: string;
|
||||
}>;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface UploadConfig {
|
||||
configured: boolean;
|
||||
status: "ok" | "unavailable" | "unconfigured";
|
||||
bucket?: string;
|
||||
}
|
||||
|
||||
export interface PresignedUpload {
|
||||
uploadUrl: string;
|
||||
key: string;
|
||||
publicUrl: string;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { InquiryForm } from "./inquiry.js";
|
||||
|
||||
export interface OfferingSection {
|
||||
type: "text" | "image-list" | "timeline" | "faq";
|
||||
title: string;
|
||||
content?: string;
|
||||
items?: unknown[];
|
||||
}
|
||||
|
||||
export interface OfferingMedia {
|
||||
url: string;
|
||||
alt?: string;
|
||||
type?: "image" | "video";
|
||||
}
|
||||
|
||||
export interface OfferingCta {
|
||||
type: "inquiry" | "booking" | "contact" | "external-link";
|
||||
label: string;
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface Offering {
|
||||
id: string;
|
||||
brandId?: string;
|
||||
kind: "service" | "product" | "package" | "subscription";
|
||||
name: string;
|
||||
summary?: string | null;
|
||||
description?: string | null;
|
||||
coverUrl?: string | null;
|
||||
priceText?: string | null;
|
||||
priceAmount?: number | null;
|
||||
isEnabled: boolean;
|
||||
sortOrder: number;
|
||||
config?: Record<string, unknown> | null;
|
||||
sections?: OfferingSection[];
|
||||
media?: OfferingMedia[];
|
||||
cta?: OfferingCta;
|
||||
inquiryForms?: Array<Pick<InquiryForm, "id" | "name" | "purpose" | "targetType" | "version">>;
|
||||
}
|
||||
|
||||
export interface OfferingUpdate {
|
||||
name?: string;
|
||||
description?: string;
|
||||
coverUrl?: string;
|
||||
priceText?: string;
|
||||
priceAmount?: number;
|
||||
sortOrder?: number;
|
||||
bookingEnabled?: boolean;
|
||||
isEnabled?: boolean;
|
||||
categoryKey?: string;
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
export interface BrandTemplateDefinition {
|
||||
key: "personal" | "food" | "doors";
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
serviceCategories: string[];
|
||||
trustContentTypes: string[];
|
||||
modules: Array<{
|
||||
key: string;
|
||||
type: string;
|
||||
title: string;
|
||||
required: boolean;
|
||||
}>;
|
||||
fields: Array<{
|
||||
scope: string;
|
||||
key: string;
|
||||
label: string;
|
||||
type: string;
|
||||
required: boolean;
|
||||
}>;
|
||||
capabilities: string[];
|
||||
runtimeCapabilities: Array<{
|
||||
key: string;
|
||||
version: string;
|
||||
workflowKey?: string;
|
||||
}>;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
export interface TemplateAdminField {
|
||||
key: string;
|
||||
page?: string;
|
||||
binding: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
input:
|
||||
| "text"
|
||||
| "textarea"
|
||||
| "phone"
|
||||
| "image"
|
||||
| "number"
|
||||
| "boolean"
|
||||
| "select"
|
||||
| "multi-select"
|
||||
| "list";
|
||||
itemFields?: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
input?: "text" | "textarea";
|
||||
required?: boolean;
|
||||
}>;
|
||||
itemValueKey?: string;
|
||||
required?: boolean;
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
previewTarget?: string;
|
||||
}
|
||||
|
||||
export interface TemplateAdminSection {
|
||||
key: string;
|
||||
title: string;
|
||||
description: string;
|
||||
page: string;
|
||||
target: "brand" | "offering" | "trust" | "inquiry";
|
||||
previewTargets?: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
composite?: boolean;
|
||||
children?: string[];
|
||||
}>;
|
||||
fields: TemplateAdminField[];
|
||||
}
|
||||
|
||||
export interface AdminTemplateContent {
|
||||
displayName: string;
|
||||
admin: { sections: TemplateAdminSection[] };
|
||||
navigation: Array<{ key: string; label: string; page: string }>;
|
||||
templateFields?: TemplateAdminField[];
|
||||
trustContentTypes?: Array<{
|
||||
type: string;
|
||||
label: string;
|
||||
adminFields: {
|
||||
title: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
summaryHelp?: string;
|
||||
summaryPlaceholder?: string;
|
||||
};
|
||||
pages?: string[];
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
previewTargets?: Array<{ key: string; label: string; page?: string }>;
|
||||
maxPublishedItems?: number;
|
||||
hideStandardFields?: Array<"summary" | "content">;
|
||||
}>;
|
||||
assetSlots: Array<{
|
||||
key: string;
|
||||
binding: string;
|
||||
target: "brand" | "offering" | "trust";
|
||||
label: string;
|
||||
help: string;
|
||||
required: boolean;
|
||||
kind: "image" | "logo" | "portrait" | "texture";
|
||||
aspectRatio?: string;
|
||||
}>;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export interface TrustContent {
|
||||
id: string;
|
||||
type: string;
|
||||
title: string;
|
||||
summary?: string | null;
|
||||
content: string;
|
||||
coverUrl?: string | null;
|
||||
sortOrder: number;
|
||||
isPublished: boolean;
|
||||
config?: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
export interface TrustContentInput {
|
||||
type: string;
|
||||
title: string;
|
||||
summary?: string;
|
||||
content: string;
|
||||
coverUrl?: string;
|
||||
sortOrder?: number;
|
||||
isPublished?: boolean;
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import type {
|
||||
BrandTemplateKey,
|
||||
RuntimeCapability,
|
||||
RuntimeInquiryForm,
|
||||
RuntimeOffering,
|
||||
RuntimeTrustItem,
|
||||
ThemeManifest,
|
||||
} from "@personal-brand/types";
|
||||
import type { BrandProfile } from "./brand.js";
|
||||
|
||||
export interface PublicWorkspace {
|
||||
schemaVersion: string;
|
||||
contractVersion: string;
|
||||
publication: {
|
||||
status: "published" | "unpublished";
|
||||
version: number | null;
|
||||
publishedAt?: string;
|
||||
};
|
||||
brand: (BrandProfile & Record<string, unknown>) | null;
|
||||
template: { key: BrandTemplateKey; version: string; name: string } | null;
|
||||
visualTemplate: {
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
supportedIndustryTemplates: BrandTemplateKey[];
|
||||
variants: Record<string, string>;
|
||||
} | null;
|
||||
visualTemplateManifest?: {
|
||||
schemaVersion: "1.0";
|
||||
key: string;
|
||||
version: string;
|
||||
name: string;
|
||||
brandFirst: true;
|
||||
tokens: {
|
||||
colors: Record<string, string>;
|
||||
spacing: Record<string, string>;
|
||||
typography: Record<string, string>;
|
||||
radius: Record<string, string>;
|
||||
shadows?: Record<string, string>;
|
||||
};
|
||||
pages: Array<{
|
||||
key: string;
|
||||
title: string;
|
||||
modules: Array<{
|
||||
key: string;
|
||||
type: string;
|
||||
variant: string;
|
||||
required: boolean;
|
||||
dataSlots?: string[];
|
||||
assetSlots?: string[];
|
||||
capability?: string;
|
||||
}>;
|
||||
}>;
|
||||
assets: Array<Record<string, unknown>>;
|
||||
dataSlots: Array<Record<string, unknown>>;
|
||||
capabilities: string[];
|
||||
};
|
||||
capabilities: RuntimeCapability[];
|
||||
offerings: RuntimeOffering[];
|
||||
inquiryForms: RuntimeInquiryForm[];
|
||||
trustItems: RuntimeTrustItem[];
|
||||
navigation: { tabs: Array<{ key: string; label: string; page: string }> };
|
||||
trustPresentation: Record<string, unknown>;
|
||||
theme: ThemeManifest;
|
||||
layout?: { home: string[]; offerings: string[]; detail: string[]; profile: string[] };
|
||||
plugins?: Array<{
|
||||
key: string;
|
||||
version: string;
|
||||
displayName: string;
|
||||
purpose: string;
|
||||
requiredModules: string[];
|
||||
apiContract: string;
|
||||
configSchema: string;
|
||||
status: string;
|
||||
}>;
|
||||
}
|
||||
Reference in new issue
Block a user