- Add Hose flow domain with OpenAPI & CloseAPI timeline and staff opinion parsing - Add E人工行为 and E人工意见 columns in approval runs Excel export - Add pre-flight scale/duration warning and smooth concurrency throttling (default concurrency 3, batch delay 150ms) - Add seal-use approval-runs flow diagnostic CLI command and tool - Support --to-downloads and --flow-concurrency CLI flags
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import ky, { HTTPError, type KyInstance } from "ky";
|
|
import { ensureHoseOpenapiToken, normalizeBaseUrl } from "../../../core/auth/hose.js";
|
|
import type { CorpConfig } from "../../../core/config/types.js";
|
|
|
|
export interface HoseOpenClientCredentials {
|
|
domain?: string;
|
|
accessToken: string;
|
|
}
|
|
|
|
export function createHoseOpenClientWithCredentials(
|
|
credentials: HoseOpenClientCredentials,
|
|
customHeaders?: Record<string, string>
|
|
): KyInstance {
|
|
const baseUrl = normalizeBaseUrl(credentials.domain || "https://app.ekuaibao.com");
|
|
return ky.create({
|
|
prefix: baseUrl,
|
|
timeout: 30000,
|
|
searchParams: {
|
|
accessToken: credentials.accessToken
|
|
},
|
|
headers: {
|
|
...customHeaders
|
|
},
|
|
hooks: {
|
|
beforeError: [
|
|
async ({ error }) => {
|
|
const body =
|
|
error instanceof HTTPError
|
|
? await error.response.text().catch(() => "")
|
|
: "";
|
|
error.message = `${error.message}${body ? `: ${body}` : ""}`;
|
|
return error;
|
|
}
|
|
]
|
|
}
|
|
});
|
|
}
|
|
|
|
export async function createHoseOpenClient(
|
|
corp: CorpConfig,
|
|
customHeaders?: Record<string, string>
|
|
): Promise<KyInstance> {
|
|
if (corp.source.type !== "hose") {
|
|
throw new Error(`Unsupported Hose source type: ${corp.source.type}. Expected 'hose'.`);
|
|
}
|
|
|
|
const token = await ensureHoseOpenapiToken(corp);
|
|
return createHoseOpenClientWithCredentials(
|
|
{
|
|
domain: corp.source.domain,
|
|
accessToken: token
|
|
},
|
|
customHeaders
|
|
);
|
|
}
|