feat: implement governed service directory
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { apiFetch, apiPath, type ApiSettings } from "@govoplan/core-webui";
|
||||
|
||||
|
||||
export type PortalServiceBinding = {
|
||||
kind: string;
|
||||
reference: string;
|
||||
required: boolean;
|
||||
};
|
||||
|
||||
export type PortalServiceDefinition = {
|
||||
reference: {
|
||||
object_id: string;
|
||||
version?: string | null;
|
||||
};
|
||||
key: string;
|
||||
title: string;
|
||||
audience: string[];
|
||||
prerequisites: string[];
|
||||
required_evidence_types: string[];
|
||||
fee_refs: string[];
|
||||
deadline_refs: string[];
|
||||
channels: string[];
|
||||
publication_state: string;
|
||||
};
|
||||
|
||||
export type PortalServiceEntry = {
|
||||
definition: PortalServiceDefinition;
|
||||
state: "available" | "unavailable";
|
||||
reason_codes: string[];
|
||||
entry_binding?: PortalServiceBinding | null;
|
||||
availability_evidence: Array<Record<string, unknown>>;
|
||||
};
|
||||
|
||||
export type PortalServiceListResponse = {
|
||||
services: PortalServiceEntry[];
|
||||
};
|
||||
|
||||
export type PortalServiceLaunchResult = {
|
||||
service_ref: PortalServiceDefinition["reference"];
|
||||
binding: PortalServiceBinding;
|
||||
state: "started" | "redirect";
|
||||
target_ref?: Record<string, unknown> | null;
|
||||
href?: string | null;
|
||||
replayed: boolean;
|
||||
evidence: Array<Record<string, unknown>>;
|
||||
metadata: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function listPortalServices(
|
||||
settings: ApiSettings,
|
||||
options: {
|
||||
query?: string;
|
||||
includeUnavailable?: boolean;
|
||||
limit?: number;
|
||||
},
|
||||
signal?: AbortSignal
|
||||
): Promise<PortalServiceListResponse> {
|
||||
return apiFetch<PortalServiceListResponse>(
|
||||
settings,
|
||||
apiPath("/api/v1/portal/services", {
|
||||
q: options.query,
|
||||
include_unavailable: options.includeUnavailable,
|
||||
limit: options.limit
|
||||
}),
|
||||
{ signal }
|
||||
);
|
||||
}
|
||||
|
||||
export function launchPortalService(
|
||||
settings: ApiSettings,
|
||||
serviceId: string,
|
||||
payload: {
|
||||
service_version: string;
|
||||
idempotency_key: string;
|
||||
requested_at: string;
|
||||
parameters?: Record<string, unknown>;
|
||||
}
|
||||
): Promise<PortalServiceLaunchResult> {
|
||||
return apiFetch<PortalServiceLaunchResult>(
|
||||
settings,
|
||||
`/api/v1/portal/services/${encodeURIComponent(serviceId)}/launch`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload)
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user