feat: initialize governed postbox module
This commit is contained in:
@@ -0,0 +1,362 @@
|
||||
import {
|
||||
apiFetch,
|
||||
apiPath,
|
||||
apiPostJson,
|
||||
type ApiSettings
|
||||
} from "@govoplan/core-webui";
|
||||
|
||||
export type PostboxAccessDecision = {
|
||||
allowed: boolean;
|
||||
action: string;
|
||||
postbox_id: string;
|
||||
reason_code: string;
|
||||
explanation: string;
|
||||
organization_unit_id?: string | null;
|
||||
function_id?: string | null;
|
||||
assignment_ids: string[];
|
||||
assignment_sources: string[];
|
||||
selected_assignment_id?: string | null;
|
||||
holder_count: number;
|
||||
vacant: boolean;
|
||||
};
|
||||
|
||||
export type PostboxDirectoryItem = {
|
||||
id: string;
|
||||
tenant_id: string;
|
||||
address: string;
|
||||
address_key: string;
|
||||
name: string;
|
||||
status: string;
|
||||
classification: string;
|
||||
organization_unit_id?: string | null;
|
||||
organization_unit_name?: string | null;
|
||||
function_id?: string | null;
|
||||
function_name?: string | null;
|
||||
context_key?: string | null;
|
||||
template_revision_id?: string | null;
|
||||
holder_count: number;
|
||||
vacant: boolean;
|
||||
access?: PostboxAccessDecision | null;
|
||||
};
|
||||
|
||||
export type PostboxParticipant = {
|
||||
kind: string;
|
||||
reference_type: string;
|
||||
reference_id?: string | null;
|
||||
label?: string | null;
|
||||
address?: string | null;
|
||||
};
|
||||
|
||||
export type PostboxAttachment = {
|
||||
reference_type: string;
|
||||
reference_id: string;
|
||||
name?: string | null;
|
||||
media_type?: string | null;
|
||||
size_bytes?: number | null;
|
||||
digest?: string | null;
|
||||
metadata: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type PostboxMessage = {
|
||||
id: string;
|
||||
tenant_id: string;
|
||||
postbox_id: string;
|
||||
subject: string;
|
||||
body_text?: string | null;
|
||||
status: string;
|
||||
classification: string;
|
||||
sender_label?: string | null;
|
||||
delivered_at: string;
|
||||
read_at?: string | null;
|
||||
acknowledged_at?: string | null;
|
||||
expires_at?: string | null;
|
||||
withdrawn_at?: string | null;
|
||||
producer_module?: string | null;
|
||||
producer_resource_type?: string | null;
|
||||
producer_resource_id?: string | null;
|
||||
encryption_profile: string;
|
||||
key_epoch: number;
|
||||
ciphertext_ref?: string | null;
|
||||
signed_manifest_ref?: string | null;
|
||||
participants: PostboxParticipant[];
|
||||
attachments: PostboxAttachment[];
|
||||
metadata: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type PostboxGrouping = {
|
||||
id: string;
|
||||
name: string;
|
||||
is_default: boolean;
|
||||
postbox_ids: string[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type PostboxOrganizationFunction = {
|
||||
id: string;
|
||||
slug: string;
|
||||
name: string;
|
||||
function_type_id?: string | null;
|
||||
delegable: boolean;
|
||||
act_in_place_allowed: boolean;
|
||||
};
|
||||
|
||||
export type PostboxOrganizationUnit = {
|
||||
id: string;
|
||||
slug: string;
|
||||
name: string;
|
||||
unit_type_id?: string | null;
|
||||
parent_id?: string | null;
|
||||
functions: PostboxOrganizationFunction[];
|
||||
};
|
||||
|
||||
export type PostboxTemplateRevision = {
|
||||
id: string;
|
||||
revision: number;
|
||||
function_type_id?: string | null;
|
||||
scope_kind: "tenant" | "unit" | "subtree" | "unit_type";
|
||||
scope_id?: string | null;
|
||||
name_pattern: string;
|
||||
address_pattern: string;
|
||||
classification: string;
|
||||
allow_vacant_delivery: boolean;
|
||||
encryption_profile: string;
|
||||
history_policy: Record<string, unknown>;
|
||||
routing_policy: Record<string, unknown>;
|
||||
retention_policy: Record<string, unknown>;
|
||||
published_at?: string | null;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export type PostboxTemplate = {
|
||||
id: string;
|
||||
tenant_id: string;
|
||||
slug: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
status: string;
|
||||
current_revision: number;
|
||||
published_revision_id?: string | null;
|
||||
revisions: PostboxTemplateRevision[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type PostboxTemplateRevisionPayload = Pick<
|
||||
PostboxTemplateRevision,
|
||||
| "function_type_id"
|
||||
| "scope_kind"
|
||||
| "scope_id"
|
||||
| "name_pattern"
|
||||
| "address_pattern"
|
||||
| "classification"
|
||||
| "allow_vacant_delivery"
|
||||
>;
|
||||
|
||||
export type PostboxTemplateCreatePayload = PostboxTemplateRevisionPayload & {
|
||||
slug: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
};
|
||||
|
||||
export type PostboxExactCreatePayload = {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
organization_unit_id: string;
|
||||
function_id: string;
|
||||
address_key?: string | null;
|
||||
classification: string;
|
||||
};
|
||||
|
||||
export async function listPostboxes(settings: ApiSettings): Promise<PostboxDirectoryItem[]> {
|
||||
const response = await apiFetch<{ postboxes: PostboxDirectoryItem[] }>(
|
||||
settings,
|
||||
"/api/v1/postbox/directory"
|
||||
);
|
||||
return response.postboxes;
|
||||
}
|
||||
|
||||
export async function listPostboxMessages(
|
||||
settings: ApiSettings,
|
||||
postboxIds: string[],
|
||||
limit = 100,
|
||||
offset = 0,
|
||||
query = "",
|
||||
state: "all" | "unread" | "read" | "acknowledged" = "all"
|
||||
): Promise<{ messages: PostboxMessage[]; total: number; limit: number; offset: number }> {
|
||||
return apiFetch(
|
||||
settings,
|
||||
apiPath("/api/v1/postbox/messages", {
|
||||
postbox_id: postboxIds,
|
||||
limit,
|
||||
offset,
|
||||
q: query || undefined,
|
||||
state
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function getPostboxMessage(
|
||||
settings: ApiSettings,
|
||||
messageId: string
|
||||
): Promise<PostboxMessage> {
|
||||
return apiFetch(settings, `/api/v1/postbox/messages/${encodeURIComponent(messageId)}`);
|
||||
}
|
||||
|
||||
export function markPostboxMessage(
|
||||
settings: ApiSettings,
|
||||
messageId: string,
|
||||
state: "read" | "acknowledged"
|
||||
): Promise<PostboxMessage> {
|
||||
return apiFetch(
|
||||
settings,
|
||||
`/api/v1/postbox/messages/${encodeURIComponent(messageId)}/state`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ state })
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function listPostboxGroupings(settings: ApiSettings): Promise<PostboxGrouping[]> {
|
||||
const response = await apiFetch<{ groupings: PostboxGrouping[] }>(
|
||||
settings,
|
||||
"/api/v1/postbox/groupings"
|
||||
);
|
||||
return response.groupings;
|
||||
}
|
||||
|
||||
export function createPostboxGrouping(
|
||||
settings: ApiSettings,
|
||||
payload: Omit<PostboxGrouping, "id" | "created_at" | "updated_at">
|
||||
): Promise<PostboxGrouping> {
|
||||
return apiPostJson(settings, "/api/v1/postbox/groupings", payload);
|
||||
}
|
||||
|
||||
export function updatePostboxGrouping(
|
||||
settings: ApiSettings,
|
||||
groupingId: string,
|
||||
payload: Omit<PostboxGrouping, "id" | "created_at" | "updated_at">
|
||||
): Promise<PostboxGrouping> {
|
||||
return apiFetch(
|
||||
settings,
|
||||
`/api/v1/postbox/groupings/${encodeURIComponent(groupingId)}`,
|
||||
{
|
||||
method: "PUT",
|
||||
body: JSON.stringify(payload)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePostboxGrouping(
|
||||
settings: ApiSettings,
|
||||
groupingId: string
|
||||
): Promise<void> {
|
||||
return apiFetch(
|
||||
settings,
|
||||
`/api/v1/postbox/groupings/${encodeURIComponent(groupingId)}`,
|
||||
{ method: "DELETE" }
|
||||
);
|
||||
}
|
||||
|
||||
export async function listAdminPostboxes(settings: ApiSettings): Promise<PostboxDirectoryItem[]> {
|
||||
const response = await apiFetch<{ postboxes: PostboxDirectoryItem[] }>(
|
||||
settings,
|
||||
"/api/v1/postbox/admin/postboxes"
|
||||
);
|
||||
return response.postboxes;
|
||||
}
|
||||
|
||||
export async function listPostboxOrganizationTargets(
|
||||
settings: ApiSettings
|
||||
): Promise<PostboxOrganizationUnit[]> {
|
||||
const response = await apiFetch<{ units: PostboxOrganizationUnit[] }>(
|
||||
settings,
|
||||
"/api/v1/postbox/admin/organization-targets"
|
||||
);
|
||||
return response.units;
|
||||
}
|
||||
|
||||
export function createExactPostbox(
|
||||
settings: ApiSettings,
|
||||
payload: PostboxExactCreatePayload
|
||||
): Promise<PostboxDirectoryItem> {
|
||||
return apiPostJson(settings, "/api/v1/postbox/admin/postboxes", payload);
|
||||
}
|
||||
|
||||
export function archivePostbox(
|
||||
settings: ApiSettings,
|
||||
postboxId: string
|
||||
): Promise<PostboxDirectoryItem> {
|
||||
return apiFetch(
|
||||
settings,
|
||||
`/api/v1/postbox/admin/postboxes/${encodeURIComponent(postboxId)}`,
|
||||
{ method: "DELETE" }
|
||||
);
|
||||
}
|
||||
|
||||
export async function listPostboxTemplates(settings: ApiSettings): Promise<PostboxTemplate[]> {
|
||||
const response = await apiFetch<{ templates: PostboxTemplate[] }>(
|
||||
settings,
|
||||
"/api/v1/postbox/admin/templates"
|
||||
);
|
||||
return response.templates;
|
||||
}
|
||||
|
||||
export function createPostboxTemplate(
|
||||
settings: ApiSettings,
|
||||
payload: PostboxTemplateCreatePayload
|
||||
): Promise<PostboxTemplate> {
|
||||
return apiPostJson(settings, "/api/v1/postbox/admin/templates", payload);
|
||||
}
|
||||
|
||||
export function revisePostboxTemplate(
|
||||
settings: ApiSettings,
|
||||
templateId: string,
|
||||
payload: PostboxTemplateRevisionPayload
|
||||
): Promise<PostboxTemplate> {
|
||||
return apiPostJson(
|
||||
settings,
|
||||
`/api/v1/postbox/admin/templates/${encodeURIComponent(templateId)}/revisions`,
|
||||
payload
|
||||
);
|
||||
}
|
||||
|
||||
export function publishPostboxTemplate(
|
||||
settings: ApiSettings,
|
||||
templateId: string,
|
||||
revision?: number
|
||||
): Promise<PostboxTemplate> {
|
||||
return apiPostJson(
|
||||
settings,
|
||||
`/api/v1/postbox/admin/templates/${encodeURIComponent(templateId)}/publish`,
|
||||
{ revision: revision ?? null }
|
||||
);
|
||||
}
|
||||
|
||||
export function retirePostboxTemplate(
|
||||
settings: ApiSettings,
|
||||
templateId: string
|
||||
): Promise<PostboxTemplate> {
|
||||
return apiPostJson(
|
||||
settings,
|
||||
`/api/v1/postbox/admin/templates/${encodeURIComponent(templateId)}/retire`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
export function materializePostboxTemplate(
|
||||
settings: ApiSettings,
|
||||
templateId: string,
|
||||
payload: {
|
||||
organization_unit_id: string;
|
||||
function_id: string;
|
||||
context_key?: string | null;
|
||||
}
|
||||
): Promise<PostboxDirectoryItem> {
|
||||
return apiPostJson(
|
||||
settings,
|
||||
`/api/v1/postbox/admin/templates/${encodeURIComponent(templateId)}/materialize`,
|
||||
payload
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user