import {z} from 'zod' export type GetApiSnapshotsSnapshotIdExternalSystemsPackageKeyGraphArgs = {snapshot_id: string, package_key: string, scope?: ('primary' | 'all') | undefined, node_limit?: number | undefined, edge_limit?: number | undefined}; export type GetApiSnapshotsSnapshotIdExternalSystemsPackageKeyGraphOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const externalSystemGraphTarget = z.object({node_id: z.string(), match_basis: z.enum(["exact", "subpath", "mapped"])}); export const externalSystemRelationshipNode = z.object({aggregate_key: z.string(), label: z.string(), community_id: z.number().int(), importing_file_count: z.number().int(), import_edge_count: z.number().int(), top_file: z.string().nullable().optional()}); export const externalSystemRelationshipEdge = z.object({source: z.string(), target: z.string(), import_edge_count: z.number().int()}); export const externalSystemRelationshipGraphResponse = z.object({package_key: z.string().optional(), package_name: z.string().optional(), package_node_id: z.string().optional(), match_basis: z.enum(["exact", "subpath", "mapped", "mixed", "unresolved"]).optional(), matched_external_nodes: z.array(externalSystemGraphTarget).optional(), matched_external_nodes_total: z.number().int().optional(), matched_external_nodes_truncated: z.boolean().optional(), evidence_target_limit: z.number().int().optional(), evidence_truncated: z.boolean().optional(), nodes: z.array(externalSystemRelationshipNode).optional(), edges: z.array(externalSystemRelationshipEdge).optional(), aggregate_total: z.number().int().optional(), aggregate_returned: z.number().int().optional(), edge_total: z.number().int().optional(), edge_returned: z.number().int().optional(), importing_file_total: z.number().int().optional(), import_edge_total: z.number().int().optional(), node_limit: z.number().int().optional(), edge_limit: z.number().int().optional(), truncated: z.boolean().optional(), scope: z.enum(["primary", "all"]).optional(), state: z.string().optional(), reason: z.string().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * External System Relationship Graph * * GET /snapshots/{snapshot_id}/external-systems/{package_key}/graph */ export const getApiSnapshotsSnapshotIdExternalSystemsPackageKeyGraph = async (args: GetApiSnapshotsSnapshotIdExternalSystemsPackageKeyGraphArgs, options: GetApiSnapshotsSnapshotIdExternalSystemsPackageKeyGraphOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.scope != null) query.append("scope", String(args.scope)) if (args.node_limit != null) query.append("node_limit", String(args.node_limit)) if (args.edge_limit != null) query.append("edge_limit", String(args.edge_limit)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/snapshots/${encodeURIComponent(String(args.snapshot_id))}/external-systems/${encodeURIComponent(String(args.package_key))}/graph${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(externalSystemRelationshipGraphResponse, await res.json()) };