// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0 // A domain producer supplies only its recipient, occurrence and authorized app route. Inbox // storage, read state, localization and rendering remain the notifications kit's responsibility. import type { Container, ProjectScope } from "@conusai-kit/core" import { DATA_SOURCE } from "@conusai-kit/data" import { files } from "@conusai-kit/files" import { deliverNotification } from "@conusai-kit/notifications" import { organizations, projects, workspaces } from "@conusai-kit/tenancy" import { documents } from "../contract/index.js" export async function notifyDocumentResult(container: Container, scope: ProjectScope, fileId: string): Promise { await container.resolve(DATA_SOURCE).unitOfWork.run(scope, async (tx) => { const row = (await tx.of(documents).list({ where: [{ field: "fileId", op: "eq", value: fileId }], limit: 1 })) .items[0] const file = await tx.of(files).get(fileId) if (!row || !file || row.status === "processing" || row.finishedAt === null) return const [org, workspace, project] = await Promise.all([ tx.global(organizations).require(scope.orgId), tx.of(workspaces).require(scope.workspaceId), tx.of(projects).require(scope.projectId), ]) await deliverNotification(tx, { recipientId: file.uploadedBy, key: `documents:${row.id}:${row.status}`, category: "job", code: row.status === "failed" ? "job_failed" : "job_completed", href: `/${org.slug}/${workspace.slug}/${project.slug}/documents/${fileId}`, }) }) }