refactor: 收口 Admin 会话与授权边界

This commit is contained in:
que01 committed 2026-10-19 10:13:13 +08:00
1 parent 0788480ce3
commit 4ef4be2071
67 files changed
+1890 -392

No files matched your search

+3
View File
@@ -45,6 +45,7 @@ export type {
TemplatePackagePreview,
TemplatePackageVersion,
} from "./resources/template.js";
export type { AdminLoginSession, AdminSession } from "./resources/session.js";
export type { TrustContent, TrustContentInput } from "./types/trust.js";
export type { PublicWorkspace } from "./types/workspace.js";
export { projectBrandAliases, projectTrustPresentation } from "@personal-brand/types";
@@ -156,6 +157,8 @@ export class ApiClient
) => this.resources.public.getCustomerInquirySubmission(...arguments_);
createCustomerSession = (...arguments_: Parameters<PublicMethods["createCustomerSession"]>) =>
this.resources.public.createCustomerSession(...arguments_);
getAdminSession = (...arguments_: Parameters<SessionMethods["getAdminSession"]>) =>
this.resources.session.getAdminSession(...arguments_);
loginAdmin = (...arguments_: Parameters<SessionMethods["loginAdmin"]>) =>
this.resources.session.loginAdmin(...arguments_);
changeAdminPassword = (...arguments_: Parameters<SessionMethods["changeAdminPassword"]>) =>
+1 -1
View File
@@ -15,7 +15,7 @@ export interface BrandMethods {
listAdminBrands(): Promise<AdminBrandMembership[]>;
switchAdminBrand(
brandId: string,
): Promise<{ token: string; role: string; brand: AdminBrandMembership["brand"] }>;
): Promise<{ role: string; brand: AdminBrandMembership["brand"] }>;
listAdminMembers(): Promise<AdminBrandMember[]>;
createAdminMember(body: {
username: string;
+13 -10
View File
@@ -1,16 +1,18 @@
import type { RequestFn } from "../client/request.js";
export type AdminSession = {
authenticated: true;
displayName: string;
mustChangePassword: boolean;
role: string;
platformTemplateRole: "none" | "template_admin";
};
export type AdminLoginSession = Omit<AdminSession, "authenticated">;
export interface SessionMethods {
loginAdmin(
username: string,
password: string,
): Promise<{
token: string;
displayName: string;
mustChangePassword: boolean;
role: string;
platformTemplateRole: "none" | "template_admin";
}>;
getAdminSession(): Promise<AdminSession>;
loginAdmin(username: string, password: string): Promise<AdminLoginSession>;
changeAdminPassword(currentPassword: string, newPassword: string): Promise<{ changed: true }>;
logoutAdmin(): Promise<{ loggedOut: true }>;
logoutCustomer(): Promise<{ loggedOut: true }>;
@@ -18,6 +20,7 @@ export interface SessionMethods {
export function sessionMethods({ request }: { request: RequestFn }): SessionMethods {
return {
getAdminSession: () => request("/admin/session/current"),
loginAdmin: (username, password) =>
request("/admin/session/login", { method: "POST", body: { username, password } }),
changeAdminPassword: (currentPassword, newPassword) =>