269 lines
7.5 KiB
TypeScript
269 lines
7.5 KiB
TypeScript
import { queueNames, type QueueName } from "./names.js";
|
|
|
|
export type MailAddressPayload = string | { email: string; name?: string };
|
|
export type MailAttachmentPayload = {
|
|
content: string;
|
|
filename: string;
|
|
disposition?: "attachment" | "inline";
|
|
id?: string;
|
|
};
|
|
export type MailHeaderPayload = {
|
|
name: string;
|
|
value: string;
|
|
};
|
|
export type MailTrackingSettingsPayload = {
|
|
trackClicks?: boolean;
|
|
trackOpens?: boolean;
|
|
trackContent?: boolean;
|
|
};
|
|
|
|
export type TransactionalMailJob = {
|
|
kind: "mail.transactional";
|
|
from?: MailAddressPayload;
|
|
to: readonly MailAddressPayload[];
|
|
cc?: readonly MailAddressPayload[];
|
|
bcc?: readonly MailAddressPayload[];
|
|
replyTo?: MailAddressPayload;
|
|
subject?: string;
|
|
text?: string;
|
|
html?: string;
|
|
templateId?: string;
|
|
attachments?: readonly MailAttachmentPayload[];
|
|
tags?: readonly string[];
|
|
precedenceBulk?: boolean;
|
|
sendAt?: number;
|
|
inReplyTo?: string;
|
|
references?: readonly string[];
|
|
settings?: MailTrackingSettingsPayload;
|
|
headers?: readonly MailHeaderPayload[];
|
|
listUnsubscribe?: string;
|
|
templateData?: Record<string, unknown>;
|
|
tenantId?: string;
|
|
userId?: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type WebhookDeliveryJob = {
|
|
kind: "webhook.deliver";
|
|
url: string;
|
|
method?: "POST" | "PUT" | "PATCH";
|
|
headers?: Record<string, string>;
|
|
body?: unknown;
|
|
tenantId?: string;
|
|
eventName: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type NotificationJob = {
|
|
kind: "notification.send";
|
|
userId: string;
|
|
channel: "email" | "in-app";
|
|
messageKey: string;
|
|
tenantId: string;
|
|
category?: string;
|
|
email?: string;
|
|
subject?: string;
|
|
text?: string;
|
|
html?: string;
|
|
templateId?: string;
|
|
templateData?: Record<string, unknown>;
|
|
metadata?: Record<string, unknown>;
|
|
sourceKey?: string;
|
|
};
|
|
|
|
export type CleanupJob = {
|
|
kind: "cleanup.run";
|
|
task:
|
|
| "expired-sessions"
|
|
| "anonymous-chat"
|
|
| "audit-log-retention"
|
|
| "temporary-files"
|
|
| "expired-export-artifacts"
|
|
| "dsgvo-grace-period-scan"
|
|
| "ai-cost-billing-report"
|
|
| "outbox-done-retention"
|
|
| "workflow-execution-stalled-reconcile"
|
|
| "task-archive-retention"
|
|
| "task-reminder-sweep"
|
|
| "integrations-token-refresh"
|
|
| "integrations-health-sweep"
|
|
| "calendar-token-refresh"
|
|
| "calendar-webhook-renewal"
|
|
| "calendar-webhook-drain"
|
|
| "calendar-internal-write-sync"
|
|
| "email-inbox-token-refresh"
|
|
| "email-inbox-webhook-renewal"
|
|
| "email-inbox-webhook-drain"
|
|
| "email-inbox-initial-sync"
|
|
| "email-inbox-stale-poll"
|
|
| "email-inbox-event-cleanup"
|
|
| "hr-upload-reminder-dispatch"
|
|
| "email-domain-probe"
|
|
| "lead-retention-sweep";
|
|
olderThanHours?: number;
|
|
olderThanMinutes?: number;
|
|
take?: number;
|
|
requestedBy?: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type BrowserAutomationJob = {
|
|
kind: "browser.session-run" | "browser.session-cleanup" | "usage.flush";
|
|
tenantId?: string;
|
|
userId?: string;
|
|
sessionId?: string;
|
|
policyId?: string;
|
|
allowedOrigins?: readonly string[];
|
|
task?: Record<string, unknown>;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type FileScanJob = {
|
|
kind: "scan.file";
|
|
bucket: string;
|
|
key: string;
|
|
tenantId?: string;
|
|
uploadId?: string;
|
|
contentType?: string;
|
|
// AK-P4a §5 — the File row this object belongs to. The worker writes the
|
|
// scan verdict (clean|infected) back onto File.scanStatus so the fail-closed
|
|
// media proxy can serve it. Optional for legacy import-path scans that have
|
|
// no File row yet.
|
|
fileId?: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type FilePreviewJob = {
|
|
kind: "preview.file";
|
|
fileId: string;
|
|
tenantId: string;
|
|
bucket: string;
|
|
storageKey: string;
|
|
mimeType: string;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type ExportJob = {
|
|
kind: "export.run";
|
|
exportJobId: string;
|
|
tenantId: string;
|
|
requestedByUserId: string;
|
|
exportType: string;
|
|
format: "csv" | "json";
|
|
requestId?: string;
|
|
complianceGate?: {
|
|
state: "active" | "paused";
|
|
reason?: string;
|
|
resumedAt?: string;
|
|
requestId?: string;
|
|
};
|
|
metadata?: Record<string, unknown>;
|
|
filters?: Record<string, unknown>;
|
|
};
|
|
|
|
export type ImportJob = {
|
|
kind: "import.run";
|
|
importJobId: string;
|
|
tenantId: string;
|
|
requestedByUserId: string;
|
|
importType: string;
|
|
format: "csv" | "json" | "xlsx";
|
|
sourceBucket: string;
|
|
sourceKey: string;
|
|
requestId?: string;
|
|
fileName?: string;
|
|
contentType?: string;
|
|
mappings?: Record<string, string>;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
/**
|
|
* Plugin invocation payload — Phase 06 #21 foundation. Carries the
|
|
* minimal identifying tuple a worker needs to load the right Plugin
|
|
* row + invoke the right hook against a fresh WASM sandbox. Structured
|
|
* payloads (typed per hook) are deferred to #22's hook lifecycle work.
|
|
*/
|
|
export type PluginInvokeJob = {
|
|
kind: "plugin.invoke";
|
|
tenantId: string;
|
|
pluginId: string;
|
|
version: string;
|
|
hookName: string;
|
|
/** Free-form JSON-serialisable payload; passed through to the plugin. */
|
|
input?: unknown;
|
|
metadata?: Record<string, unknown>;
|
|
};
|
|
|
|
export type QueueJsonPrimitive = string | number | boolean | null;
|
|
export type QueueJsonValue = QueueJsonPrimitive | { [key: string]: QueueJsonValue } | QueueJsonValue[];
|
|
|
|
export type WorkflowTriggerOutboxPayload = {
|
|
event: string;
|
|
data: QueueJsonValue;
|
|
userId: string | null;
|
|
};
|
|
|
|
export type WorkflowTriggerOutboxEvent = {
|
|
tenantId: string | null;
|
|
type: "workflow.trigger.event";
|
|
payload: WorkflowTriggerOutboxPayload;
|
|
dispatchKey: `workflow-trigger:${string}`;
|
|
};
|
|
|
|
export type WorkflowExecutionRequestedOutboxPayload = {
|
|
workflowId: string;
|
|
executionId: string;
|
|
type: "manual" | "api";
|
|
input: QueueJsonValue;
|
|
userId: string | null;
|
|
};
|
|
|
|
export type WorkflowExecutionRequestedOutboxEvent = {
|
|
tenantId: string | null;
|
|
type: "workflow.execution.requested";
|
|
payload: WorkflowExecutionRequestedOutboxPayload;
|
|
dispatchKey: `workflow-execution:${string}`;
|
|
};
|
|
|
|
export type WorkflowExecutionContinueRequestedOutboxPayload = WorkflowExecutionRequestedOutboxPayload;
|
|
|
|
export type WorkflowExecutionContinueRequestedOutboxEvent = {
|
|
tenantId: string | null;
|
|
type: "workflow.execution.continue.requested";
|
|
payload: WorkflowExecutionContinueRequestedOutboxPayload;
|
|
dispatchKey: `workflow-continuation:${string}`;
|
|
};
|
|
|
|
export type QueueJobPayloads = {
|
|
[queueNames.email]: TransactionalMailJob | WebhookDeliveryJob;
|
|
[queueNames.notifications]: NotificationJob;
|
|
[queueNames.maintenance]: CleanupJob;
|
|
[queueNames.browserAutomation]: BrowserAutomationJob;
|
|
[queueNames.fileScan]: FileScanJob;
|
|
[queueNames.filePreview]: FilePreviewJob;
|
|
[queueNames.exports]: ExportJob;
|
|
[queueNames.imports]: ImportJob;
|
|
[queueNames.pluginInvoke]: PluginInvokeJob;
|
|
};
|
|
|
|
export type QueueJobNames = {
|
|
[queueNames.email]: "send-transactional-email" | "deliver-webhook";
|
|
[queueNames.notifications]: "send-notification";
|
|
[queueNames.maintenance]: "run-cleanup" | "dsgvo-grace-period-scan";
|
|
[queueNames.browserAutomation]: "browser-session-run" | "browser-session-cleanup" | "usage-flush";
|
|
[queueNames.fileScan]: "scan-file";
|
|
[queueNames.filePreview]: "generate-file-preview";
|
|
[queueNames.exports]: "run-export";
|
|
[queueNames.imports]: "run-import";
|
|
[queueNames.pluginInvoke]: "invoke-plugin";
|
|
};
|
|
|
|
export type QueuePayload<Name extends QueueName = QueueName> = QueueJobPayloads[Name];
|
|
export type QueueJobName<Name extends QueueName = QueueName> = QueueJobNames[Name];
|
|
|
|
export type QueueJobDescriptor<Name extends QueueName = QueueName> = {
|
|
queueName: Name;
|
|
jobName: QueueJobName<Name>;
|
|
payload: QueuePayload<Name>;
|
|
};
|