feat(assist-platform): add assist platform automation and tenant onboarding
- Add SSO QR status poller and assist platform HTTP client - Add assist-platform session store with 0600 secure permissions - Implement domains/assist-platform (api, services, types) for corporation search, detail, tickets, staff query and passwordless token generation - Implement cli/commands/assist-platform with aliases assist-center and ap - Support seamless --save --switch --elevate pipeline to import tenant and extract persistent OpenAPI credentials - Update embedded skill documentation, reference guide, and test suites
This commit is contained in:
1 parent
d839fcbe2b
commit
ed9fa979e0
25 files changed
+1811
-2
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import ky, { type KyInstance } from "ky";
|
||||
import { AuthenticationError } from "../errors.js";
|
||||
|
||||
export const DEFAULT_ASSIST_PLATFORM_API_URL = "https://unity.ekuaibao.com/api";
|
||||
|
||||
export interface AssistPlatformClientOptions {
|
||||
token: string;
|
||||
baseUrl?: string;
|
||||
hoseAccessToken?: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export function createAssistPlatformClient(options: AssistPlatformClientOptions): KyInstance {
|
||||
if (!options.token || !options.token.trim()) {
|
||||
throw new AuthenticationError("缺少协助平台凭证 Token,请先登录协助平台");
|
||||
}
|
||||
|
||||
const baseUrl = options.baseUrl || DEFAULT_ASSIST_PLATFORM_API_URL;
|
||||
const cookieParts: string[] = [];
|
||||
if (options.hoseAccessToken) {
|
||||
cookieParts.push(`hose-access-token=${options.hoseAccessToken}`);
|
||||
}
|
||||
|
||||
return ky.create({
|
||||
prefix: baseUrl,
|
||||
timeout: options.timeout ?? 30000,
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
"content-type": "application/json;charset=UTF-8",
|
||||
token: options.token.trim(),
|
||||
referer: "https://unity.ekuaibao.com/platform-charge/index.html",
|
||||
...(cookieParts.length > 0 ? { cookie: cookieParts.join("; ") } : {}),
|
||||
},
|
||||
hooks: {
|
||||
afterResponse: [
|
||||
async ({ response }) => {
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new AuthenticationError("协助平台凭证已过期或无效,请重新登录协助平台");
|
||||
}
|
||||
return response;
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import ky, { type KyInstance } from "ky";
|
||||
import { AuthenticationError } from "../errors.js";
|
||||
|
||||
export const DEFAULT_SSO_BASE_URL = "https://sso.hosecloud.com";
|
||||
|
||||
export interface SsoClientOptions {
|
||||
baseUrl?: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export function createSsoClient(options: SsoClientOptions = {}): KyInstance {
|
||||
const baseUrl = options.baseUrl || DEFAULT_SSO_BASE_URL;
|
||||
return ky.create({
|
||||
prefix: baseUrl,
|
||||
timeout: options.timeout ?? 15000,
|
||||
headers: {
|
||||
accept: "application/json, text/plain, */*",
|
||||
"user-agent": "hose-use/assist-platform-client",
|
||||
referer: `${baseUrl}/`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export interface QrCodeStatusResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
data?: {
|
||||
token?: string;
|
||||
ticket?: string;
|
||||
redirectUrl?: string;
|
||||
[key: string]: unknown;
|
||||
} | string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 轮询 HoseCloudSSO 钉钉扫码登录确认状态
|
||||
*/
|
||||
export async function pollSsoQrCodeStatus(
|
||||
client: KyInstance,
|
||||
options: {
|
||||
sessionId?: string;
|
||||
cookie?: string;
|
||||
signal?: AbortSignal;
|
||||
} = {}
|
||||
): Promise<QrCodeStatusResponse> {
|
||||
const headers: Record<string, string> = {};
|
||||
if (options.cookie) {
|
||||
headers.cookie = options.cookie;
|
||||
} else if (options.sessionId) {
|
||||
headers.cookie = `SSO_SESSION_ID=${options.sessionId}`;
|
||||
}
|
||||
|
||||
try {
|
||||
return await client
|
||||
.get("api/v1/user/login/qrcode/status", {
|
||||
searchParams: { _t: Date.now() },
|
||||
headers,
|
||||
signal: options.signal,
|
||||
})
|
||||
.json<QrCodeStatusResponse>();
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === "AbortError") {
|
||||
throw error;
|
||||
}
|
||||
throw new AuthenticationError(
|
||||
`SSO 状态轮询异常: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user