59 lines
2.2 KiB
TypeScript
59 lines
2.2 KiB
TypeScript
import { listAllWorkflows } from "../../../domains/platform/services.js";
|
|
import { stringOption } from "../../parser.js";
|
|
import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js";
|
|
import type { CliParsedArgs, CliRuntime } from "../../types.js";
|
|
|
|
export const PLATFORM_ID_OPTION_KEYS = ["platform-id", "platformId", "app-id", "appId"];
|
|
|
|
export async function createWorkflowDetailClient(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime,
|
|
pipelineId: string,
|
|
): Promise<{
|
|
client: Awaited<ReturnType<typeof createPiperClientForCorp>>;
|
|
clients: Awaited<ReturnType<typeof createClientsForCorp>>;
|
|
}> {
|
|
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
|
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
|
let platformId = explicit;
|
|
if (!platformId) {
|
|
try {
|
|
const corpId = runtime.selectedCorp!.corpId || runtime.selectedCorp!.id;
|
|
const { listPlatforms } = await import("../../../domains/platform/services.js");
|
|
const platforms = await listPlatforms(clients.ekbClient, corpId);
|
|
const firstActive = platforms.find((p) => p.active) ?? platforms[0];
|
|
platformId = firstActive?.id;
|
|
} catch {
|
|
// Fall back to easoClient
|
|
}
|
|
}
|
|
return {
|
|
client: platformId ? await createPiperClientForCorp(runtime.selectedCorp!, platformId) : clients.easoClient,
|
|
clients,
|
|
};
|
|
}
|
|
|
|
export async function createJobPiperClient(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<Awaited<ReturnType<typeof createPiperClientForCorp>>> {
|
|
const corp = runtime.selectedCorp!;
|
|
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
|
if (explicit) {
|
|
return createPiperClientForCorp(corp, explicit);
|
|
}
|
|
const clients = await createClientsForCorp(corp);
|
|
try {
|
|
const corpId = corp.corpId || corp.id;
|
|
const { listPlatforms } = await import("../../../domains/platform/services.js");
|
|
const platforms = await listPlatforms(clients.ekbClient, corpId);
|
|
const firstActive = platforms.find((p) => p.active) ?? platforms[0];
|
|
if (firstActive?.id) {
|
|
return await createPiperClientForCorp(corp, firstActive.id);
|
|
}
|
|
} catch {
|
|
// Fall back to default easoClient
|
|
}
|
|
return clients.easoClient;
|
|
}
|