fix: 收口依赖兼容与会话撤销

为 miniprogram-ci 和 Jimp 依赖增加兼容 patch 与 smoke test;修复平台模板管理员路由漏配;收紧模板契约校验;为 admin/customer 增加 token 撤销和集中会话存储;同步品牌切换角色、doctor source hash、多屏宽截图证据和 CI 构建门禁。
This commit is contained in:
que01 committed 2026-10-18 23:43:25 +08:00
1 parent 4f0b50c7f1
commit 3017e3eb49
65 files changed
+1623 -975

No files matched your search

+4
View File
@@ -160,6 +160,10 @@ export class ApiClient
this.resources.session.loginAdmin(...arguments_);
changeAdminPassword = (...arguments_: Parameters<SessionMethods["changeAdminPassword"]>) =>
this.resources.session.changeAdminPassword(...arguments_);
logoutAdmin = (...arguments_: Parameters<SessionMethods["logoutAdmin"]>) =>
this.resources.session.logoutAdmin(...arguments_);
logoutCustomer = (...arguments_: Parameters<SessionMethods["logoutCustomer"]>) =>
this.resources.session.logoutCustomer(...arguments_);
listCustomerBookings = (...arguments_: Parameters<BookingMethods["listCustomerBookings"]>) =>
this.resources.booking.listCustomerBookings(...arguments_);
createCustomerBooking = (...arguments_: Parameters<BookingMethods["createCustomerBooking"]>) =>
+1 -1
View File
@@ -15,7 +15,7 @@ export interface BrandMethods {
listAdminBrands(): Promise<AdminBrandMembership[]>;
switchAdminBrand(
brandId: string,
): Promise<{ token: string; brand: AdminBrandMembership["brand"] }>;
): Promise<{ token: string; role: string; brand: AdminBrandMembership["brand"] }>;
listAdminMembers(): Promise<AdminBrandMember[]>;
createAdminMember(body: {
username: string;
@@ -12,6 +12,8 @@ export interface SessionMethods {
platformTemplateRole: "none" | "template_admin";
}>;
changeAdminPassword(currentPassword: string, newPassword: string): Promise<{ changed: true }>;
logoutAdmin(): Promise<{ loggedOut: true }>;
logoutCustomer(): Promise<{ loggedOut: true }>;
}
export function sessionMethods({ request }: { request: RequestFn }): SessionMethods {
@@ -23,5 +25,7 @@ export function sessionMethods({ request }: { request: RequestFn }): SessionMeth
method: "POST",
body: { currentPassword, newPassword },
}),
logoutAdmin: () => request("/admin/session/logout", { method: "POST", body: {} }),
logoutCustomer: () => request("/customer/session/logout", { method: "POST", body: {} }),
};
}
+18
View File
@@ -27,6 +27,24 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
assert.equal(calls[1]?.init?.body, JSON.stringify({ name: "重点" }));
});
test("客户端登出会调用当前会话接口", async () => {
const calls: Array<{ url: string; method?: string; body?: string }> = [];
const client = new ApiClient({
baseUrl: "http://api.test",
token: "admin-token",
fetcher: async (url, init) => {
calls.push({ url, method: init?.method, body: init?.body });
return response({ loggedOut: true });
},
});
await client.logoutAdmin();
await client.logoutCustomer();
assert.deepEqual(calls, [
{ url: "http://api.test/admin/session/logout", method: "POST", body: "{}" },
{ url: "http://api.test/customer/session/logout", method: "POST", body: "{}" },
]);
});
test("客户端将统一错误响应转换为 ApiClientError", async () => {
const client = new ApiClient({
baseUrl: "http://api.test",
+46 -25
View File
@@ -189,37 +189,58 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
if (!manifest.packageKey?.trim()) errors.push("packageKey is required");
if (!manifest.version?.trim()) errors.push("version is required");
if (!manifest.visualTemplateKey?.trim()) errors.push("visualTemplateKey is required");
if (manifest.packageKey !== manifest.visualTemplateKey)
errors.push("visualTemplateKey must match packageKey");
if (manifest.runtimeContract !== TEMPLATE_RUNTIME_CONTRACT)
errors.push(`runtimeContract must be ${TEMPLATE_RUNTIME_CONTRACT}`);
if (!manifest.displayName?.trim()) errors.push("displayName is required");
const presentation = manifest.visualPresentation;
if (
!presentation ||
typeof presentation !== "object" ||
!presentation.description?.trim() ||
!presentation.variants ||
typeof presentation.variants !== "object" ||
Array.isArray(presentation.variants) ||
!Object.values(presentation.variants).every(
(variant) => typeof variant === "string" && variant.trim(),
) ||
!presentation.theme ||
typeof presentation.theme !== "object" ||
!presentation.theme.colors ||
typeof presentation.theme.colors !== "object" ||
!presentation.theme.radius ||
typeof presentation.theme.radius !== "object"
) {
const validPresentation =
presentation &&
typeof presentation === "object" &&
presentation.description?.trim() &&
presentation.variants &&
typeof presentation.variants === "object" &&
!Array.isArray(presentation.variants) &&
presentation.theme &&
typeof presentation.theme === "object" &&
presentation.theme.colors &&
typeof presentation.theme.colors === "object" &&
presentation.theme.radius &&
typeof presentation.theme.radius === "object";
if (!validPresentation) {
errors.push("visualPresentation requires description, variants, theme.colors and theme.radius");
} else if (presentation.layout) {
const layout = presentation.layout;
} else {
const requiredVariant = (key: string) =>
typeof presentation.variants[key] === "string" && presentation.variants[key].trim();
if (!(["hero", "offeringList", "detail"] as const).every(requiredVariant))
errors.push("visualPresentation.variants requires hero, offeringList and detail");
const requiredColor = (key: string) =>
typeof presentation.theme.colors[key] === "string" && presentation.theme.colors[key].trim();
if (!(["background", "foreground", "accent", "dark"] as const).every(requiredColor))
errors.push(
"visualPresentation.theme.colors requires background, foreground, accent and dark",
);
if (
!(["home", "offerings", "detail", "profile"] as const).every(
(page) =>
Array.isArray(layout[page]) && layout[page].every((item) => typeof item === "string"),
)
) {
errors.push("visualPresentation.layout must contain page module arrays");
typeof presentation.theme.radius.card !== "string" ||
!presentation.theme.radius.card.trim()
)
errors.push("visualPresentation.theme.radius requires card");
if (presentation.layout) {
const layout = presentation.layout;
if (
!(["home", "offerings", "detail", "profile"] as const).every(
(page) =>
Array.isArray(layout[page]) &&
layout[page].length > 0 &&
layout[page].every((item) => typeof item === "string" && item.trim()),
)
) {
errors.push("visualPresentation.layout must contain non-empty page module arrays");
}
}
}
if (
@@ -74,6 +74,29 @@ test("template contract rejects technical or incomplete admin declarations", ()
]);
});
test("template package manifests reject mismatched visual keys and empty visual presentation", () => {
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
manifest.visualTemplateKey = "different-visual";
assert.ok(
validateTemplatePackageManifest(manifest).includes("visualTemplateKey must match packageKey"),
);
manifest.visualTemplateKey = manifest.packageKey;
manifest.visualPresentation = {
description: "无效视觉",
variants: {},
theme: { colors: {}, radius: {} },
layout: { home: [], offerings: [], detail: [], profile: [] },
};
assert.deepEqual(validateTemplatePackageManifest(manifest), [
"visualPresentation.variants requires hero, offeringList and detail",
"visualPresentation.theme.colors requires background, foreground, accent and dark",
"visualPresentation.theme.radius requires card",
"visualPresentation.layout must contain non-empty page module arrays",
]);
});
test("template package manifests must declare package-owned visual presentation", () => {
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
@@ -83,10 +106,18 @@ test("template package manifests must declare package-owned visual presentation"
]);
manifest.visualPresentation = {
description: "无效视觉",
variants: { hero: "hero" },
theme: { colors: { background: "#fff" }, radius: { card: "16rpx" } },
layout: { home: ["hero"], offerings: [], detail: [], profile: [] },
description: "有效视觉",
variants: { hero: "hero", offeringList: "service-list", detail: "case" },
theme: {
colors: { background: "#fff", foreground: "#111", accent: "#333", dark: "#000" },
radius: { card: "16rpx" },
},
layout: {
home: ["hero"],
offerings: ["service-list"],
detail: ["case"],
profile: ["contact"],
},
};
assert.deepEqual(validateTemplatePackageManifest(manifest), []);
});