Files
hose-use/src/domains/bill/api.ts
T
2026-08-27 11:48:20 +08:00

72 lines
2.2 KiB
TypeScript

import { KyInstance } from "ky";
import {
RawBillSearchResponseSchema,
RawBillBatchGetResponseSchema,
EntityListResponseSchema,
type RawBillSearchResponse,
type RawBillItem,
type EntityMeta,
} from "./types.js";
// ── 原始单据检索 API ──────────────────────────────────────────────────────────
export async function searchRawBills(
client: KyInstance,
corpId: string,
options: { start?: number; count?: number } = {}
): Promise<RawBillSearchResponse> {
const response = await client.post("api/v2/invoice/search", {
searchParams: { corporationId: corpId, corpId },
json: {
limit: {
start: options.start ?? 0,
count: options.count ?? 50,
},
},
});
const json = await response.json();
return RawBillSearchResponseSchema.parse(json);
}
// ── 按 ID 列表精确拉取单据详情 API ─────────────────────────────────────────────
export async function getRawBillsByIds(
client: KyInstance,
corpId: string,
ids: string[]
): Promise<RawBillItem[]> {
if (ids.length === 0) return [];
const response = await client.post("api/v2/invoice", {
searchParams: { corporationId: corpId, corpId },
json: { ids },
});
const json = await response.json();
const parsed = RawBillBatchGetResponseSchema.parse(json);
return parsed.items;
}
// ── 单据实体与字段元数据字典 API ───────────────────────────────────────────────
export async function listEntitySchemas(
client: KyInstance,
corpId: string,
options: { start?: number; count?: number } = {}
): Promise<EntityMeta[]> {
const response = await client.post("api/v2/datalink/entity/search", {
searchParams: { corporationId: corpId, corpId },
json: {
limit: {
start: options.start ?? 0,
count: options.count ?? 100,
},
},
});
const json = await response.json();
const parsed = EntityListResponseSchema.parse(json);
return parsed.items;
}