fix: 修复系统一致性与安全问题

This commit is contained in:
que01 committed 2026-10-14 17:36:46 +08:00
1 parent aaeec14733
commit f158f906d5
19 files changed
+194 -34

No files matched your search

+1 -1
View File
@@ -79,7 +79,7 @@ export interface BrandMethods {
getAdminMiniAppSettings(): Promise<MiniAppReleaseSettings>;
updateAdminMiniAppSettings(body: {
appId?: string;
artifactPath?: string;
apiBaseUrl?: string;
privateKey?: string;
}): Promise<MiniAppReleaseSettings>;
}
+1
View File
@@ -8,4 +8,5 @@ export interface PresignedUpload {
uploadUrl: string;
key: string;
publicUrl: string;
mode?: "local";
}
+26
View File
@@ -69,3 +69,29 @@ test("发布检查与发布操作使用当前品牌的管理接口", async () =>
},
]);
});
test("小程序上传配置会提交请求地址", async () => {
const calls: Array<{ url: string; method?: string; body?: string }> = [];
const client = new ApiClient({
baseUrl: "http://api.test",
token: "brand-token",
fetcher: async (url, init) => {
calls.push({ url, method: init?.method, body: init?.body });
return response({ appId: "wx123", apiBaseUrl: "https://wechat.example.com/api" });
},
});
await client.updateAdminMiniAppSettings({
appId: "wx123",
apiBaseUrl: "https://wechat.example.com/api",
});
assert.deepEqual(calls, [
{
url: "http://api.test/admin/miniapp-releases/settings",
method: "PATCH",
body: JSON.stringify({
appId: "wx123",
apiBaseUrl: "https://wechat.example.com/api",
}),
},
]);
});
+39 -12
View File
@@ -21,6 +21,12 @@ const inquiryFieldOptionSchema = z.object({
value: z.string().min(1),
});
const visibilityRuleSchema = z.object({
field: z.string().regex(/^[a-z][a-zA-Z0-9_]*$/),
operator: z.enum(["equals", "not-equals", "exists", "in"]),
value: z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]).optional(),
});
export const inquiryFieldSchema = z
.object({
// 字段 key 允许 snake_case 和 camelCase,模板字段通常使用 camelCase。
@@ -29,6 +35,7 @@ export const inquiryFieldSchema = z
label: z.string().min(1),
required: z.boolean().optional(),
options: z.array(inquiryFieldOptionSchema).optional(),
visibleWhen: z.array(visibilityRuleSchema).optional(),
})
.passthrough()
.superRefine((field, context) => {
@@ -41,19 +48,39 @@ export const inquiryFieldSchema = z
}
});
export const fieldSnapshotSchema = z.array(inquiryFieldSchema).superRefine((fields, context) => {
const seen = new Set<string>();
fields.forEach((field, index) => {
if (seen.has(field.key)) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: [index, "key"],
message: "字段 key 不能重复",
});
}
seen.add(field.key);
const fieldVisibilityRulesRefinement = (
fields: Array<z.infer<typeof inquiryFieldSchema>>,
context: z.RefinementCtx,
) => {
fields.forEach((field, fieldIndex) => {
(field.visibleWhen ?? []).forEach((rule, ruleIndex) => {
if (!fields.some((target) => target.key === rule.field)) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: [fieldIndex, "visibleWhen", ruleIndex, "field"],
message: "可见性规则引用的字段不存在",
});
}
});
});
});
};
export const fieldSnapshotSchema = z
.array(inquiryFieldSchema)
.superRefine((fields, context) => {
const seen = new Set<string>();
fields.forEach((field, index) => {
if (seen.has(field.key)) {
context.addIssue({
code: z.ZodIssueCode.custom,
path: [index, "key"],
message: "字段 key 不能重复",
});
}
seen.add(field.key);
});
})
.superRefine(fieldVisibilityRulesRefinement);
export const offeringConfigSchema = z
.object({