Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -12,8 +12,18 @@ import {
buildFileScanJob,
buildIdempotentJobId,
buildImportJob,
buildAdminSalesContactsImportJob,
buildAdminSalesContactsExportJob,
buildKwpArchiveDiscoveryJob,
buildKwpArchiveFileSyncJob,
buildKwpContractSentinelJob,
buildKwpProjectCatalogSyncJob,
buildKwpProjectSyncJob,
buildNotificationJob,
buildPlatformNotificationJob,
buildPlatformNotificationRequestedOutboxEvent,
buildPluginInvokeJob,
buildPortalDocumentReadyOutboxEvent,
buildRetryJobOptions,
buildTransactionalMailJob,
buildWebhookDeliveryJob,
@@ -132,6 +142,178 @@ describe("queue producers", () => {
).toThrow("Notification jobs require tenantId.");
});
test("builds a strictly tenantless platform notification descriptor", () => {
expect(
buildPlatformNotificationJob({
userId: " user_haris ",
sourceKey: " platform-lead:lead_1:email ",
channel: "email",
messageKey: "platform.leads.captured",
category: "Leads",
email: "haris@example.test",
subject: "Neuer Lead in HiveGrid",
text: "Ein neuer Lead ist eingegangen.",
metadata: {
deliveryId: "delivery_1",
leadId: "lead_1",
sourceId: "hivegrid-website",
deeplink: "/leads/lead_1",
},
})
).toEqual({
queueName: queueNames.notifications,
jobName: "send-notification",
payload: {
kind: "notification.platform.send",
tenantId: null,
userId: "user_haris",
sourceKey: "platform-lead:lead_1:email",
channel: "email",
messageKey: "platform.leads.captured",
category: "leads",
email: "haris@example.test",
subject: "Neuer Lead in HiveGrid",
text: "Ein neuer Lead ist eingegangen.",
metadata: {
deliveryId: "delivery_1",
leadId: "lead_1",
sourceId: "hivegrid-website",
deeplink: "/leads/lead_1",
},
},
});
});
test("preserves a safe task subject for platform reminder jobs", () => {
expect(
buildPlatformNotificationJob({
adminUserId: "admin_1",
sourceKey: "admin-sales:task-reminder:task_1:2026-07-25",
channel: "in-app",
messageKey: "admin.sales.notifications.taskreminder",
metadata: { taskId: "task_1", deeplink: "/sales/tasks/today" },
}).payload
).toMatchObject({
adminUserId: "admin_1",
metadata: {
taskId: "task_1",
deeplink: "/sales/tasks/today",
},
});
});
test("requires exactly one tenant or admin recipient identity", () => {
expect(() =>
buildPlatformNotificationJob({
sourceKey: "admin-email-open:event_1",
channel: "in-app",
messageKey: "admin.sales.email.notifications.opened",
})
).toThrow("exactly one recipient identity");
expect(() =>
buildPlatformNotificationRequestedOutboxEvent({
deliveryId: "delivery_1",
userId: "user_1",
adminUserId: "admin_1",
sourceKey: "admin-email-open:event_1",
channel: "in-app",
messageKey: "admin.sales.email.notifications.opened",
})
).toThrow("exactly one recipient identity");
});
test("rejects invalid platform scope and strips non-allowlisted queue metadata", () => {
expect(() =>
buildPlatformNotificationJob({
userId: " ",
sourceKey: "platform-lead:lead_1:email",
channel: "email",
messageKey: "platform.leads.captured",
})
).toThrow("userId to be a stable non-secret identifier");
expect(() =>
buildPlatformNotificationJob({
userId: "user_haris",
sourceKey: "Bearer secret/value",
channel: "email",
messageKey: "platform.leads.captured",
})
).toThrow("sourceKey to be a stable non-secret identifier");
const descriptor = buildPlatformNotificationJob({
tenantId: "tenant_escape",
userId: "user_haris",
sourceKey: "platform-lead:lead_1:in-app",
channel: "in-app",
messageKey: "platform.leads.captured",
metadata: {
leadId: "lead_1",
email: "lead@example.test",
phone: "+491701234567",
message: "private message",
token: "secret-token",
},
} as never);
expect(descriptor.payload.tenantId).toBeNull();
expect(descriptor.payload.metadata).toEqual({ leadId: "lead_1" });
expect(JSON.stringify(descriptor)).not.toContain("lead@example.test");
expect(JSON.stringify(descriptor)).not.toContain("private message");
expect(JSON.stringify(descriptor)).not.toContain("secret-token");
});
test("builds a PII-minimized platform notification outbox event", () => {
const event = buildPlatformNotificationRequestedOutboxEvent({
deliveryId: "delivery_1",
userId: "user_haris",
sourceKey: "platform-lead:lead_1:email",
channel: "email",
messageKey: "platform.leads.captured",
category: "leads",
metadata: {
deliveryId: "must_not_be_nested",
leadId: "lead_1",
sourceId: "hivegrid-website",
deeplink: "/leads/lead_1",
email: "lead@example.test",
},
} as never);
expect(event).toEqual({
tenantId: null,
type: "notification.platform.requested.v1",
payload: {
deliveryId: "delivery_1",
userId: "user_haris",
sourceKey: "platform-lead:lead_1:email",
channel: "email",
messageKey: "platform.leads.captured",
category: "leads",
metadata: {
leadId: "lead_1",
sourceId: "hivegrid-website",
deeplink: "/leads/lead_1",
},
},
dispatchKey: "platform-notification:delivery_1",
});
expect(JSON.stringify(event)).not.toContain("lead@example.test");
});
test("uses the recipient-specific delivery id for platform outbox dispatch dedupe", () => {
const common = {
sourceKey: "platform-lead:lead_1:email",
channel: "email" as const,
messageKey: "platform.leads.captured",
};
const first = buildPlatformNotificationRequestedOutboxEvent({ ...common, deliveryId: "delivery_user_1", userId: "user_1" });
const second = buildPlatformNotificationRequestedOutboxEvent({ ...common, deliveryId: "delivery_user_2", userId: "user_2" });
expect(first.dispatchKey).toBe("platform-notification:delivery_user_1");
expect(second.dispatchKey).toBe("platform-notification:delivery_user_2");
});
test("builds maintenance cleanup descriptors", () => {
expect(
buildCleanupJob({
@@ -208,6 +390,33 @@ describe("queue producers", () => {
});
});
test("builds telephony webhook maintenance descriptors on the maintenance queue", () => {
const descriptor = buildCleanupJob({ task: "telephony-webhook-maintenance" });
expect(descriptor).toEqual({
queueName: queueNames.maintenance,
jobName: "run-cleanup",
payload: {
kind: "cleanup.run",
task: "telephony-webhook-maintenance",
},
});
});
test("builds product acquisition reconciliation descriptors on the maintenance queue", () => {
const descriptor = buildCleanupJob({ task: "product-acquisition-reconcile", take: 50 });
expect(descriptor).toEqual({
queueName: queueNames.maintenance,
jobName: "run-cleanup",
payload: {
kind: "cleanup.run",
task: "product-acquisition-reconcile",
take: 50,
},
});
});
test("builds expired export artifact retention descriptors on the maintenance queue", () => {
const descriptor = buildCleanupJob({
task: "expired-export-artifacts",
@@ -453,6 +662,39 @@ describe("queue producers", () => {
});
});
test("builds tenant-less admin sales data jobs on the imports queue", () => {
expect(
buildAdminSalesContactsImportJob({
importJobId: "admin_import_1",
requestedByAdminUserId: "admin_1",
requestId: "request_1",
})
).toEqual({
queueName: queueNames.imports,
jobName: "run-import",
payload: {
kind: "admin-sales.contacts-import",
importJobId: "admin_import_1",
requestedByAdminUserId: "admin_1",
requestId: "request_1",
},
});
expect(
buildAdminSalesContactsExportJob({
exportJobId: "admin_export_1",
requestedByAdminUserId: "admin_1",
})
).toEqual({
queueName: queueNames.imports,
jobName: "run-import",
payload: {
kind: "admin-sales.contacts-export",
exportJobId: "admin_export_1",
requestedByAdminUserId: "admin_1",
},
});
});
test("keeps import descriptors off export and email queues", () => {
const descriptor = buildImportJob({
importJobId: "import_job_queue_guard_1",
@@ -472,6 +714,114 @@ describe("queue producers", () => {
expect(descriptor.payload.requestId).toBe("req_import_queue_guard_1");
});
test("rejects every unstable KWP project-sync identifier", () => {
const valid = {
tenantId: "tenant_1",
bindingId: "binding_1",
dataConnectionId: "connection_1",
cadenceBucket: "2026-07-23T11:30Z",
};
expect(buildKwpProjectSyncJob(valid)).toMatchObject({
queueName: queueNames.kwpImports,
jobName: "run-kwp-import",
payload: { kind: "kwp.project-sync", ...valid },
});
for (const field of ["tenantId", "bindingId", "dataConnectionId", "cadenceBucket"] as const) {
expect(() => buildKwpProjectSyncJob({ ...valid, [field]: " " }))
.toThrow("KWP project sync jobs require stable tenant, binding, connection and cadence identifiers.");
}
});
test("rejects every unstable KWP contract-sentinel identifier", () => {
const valid = {
tenantId: "tenant_1",
dataConnectionId: "connection_1",
cadenceBucket: "2026-07-23",
};
expect(buildKwpContractSentinelJob(valid)).toMatchObject({
queueName: queueNames.kwpImports,
jobName: "run-kwp-import",
payload: { kind: "kwp.contract-sentinel", ...valid },
});
for (const field of ["tenantId", "dataConnectionId", "cadenceBucket"] as const) {
expect(() => buildKwpContractSentinelJob({ ...valid, [field]: " " }))
.toThrow("KWP contract sentinel jobs require stable tenant, connection and cadence identifiers.");
}
});
test("builds a stable KWP project-catalog descriptor and rejects unstable identifiers", () => {
const valid = {
tenantId: "tenant_1",
dataConnectionId: "connection_1",
cadenceBucket: "2026-07-23T11:30Z",
};
expect(buildKwpProjectCatalogSyncJob(valid)).toMatchObject({
queueName: queueNames.kwpImports,
jobName: "run-kwp-import",
payload: { kind: "kwp.project-catalog-sync", ...valid },
});
for (const field of ["tenantId", "dataConnectionId", "cadenceBucket"] as const) {
expect(() => buildKwpProjectCatalogSyncJob({ ...valid, [field]: " " }))
.toThrow("KWP project catalog jobs require stable tenant, connection and cadence identifiers.");
}
});
test("builds a stable KWP archive-file descriptor and rejects an unstable revision", () => {
const input = {
tenantId: "tenant_1",
bindingId: "binding_1",
dataConnectionId: "connection_1",
cadenceBucket: "2026-07-23T11:30Z",
archiveFile: {
externalId: "1:2:3",
headerId: 1,
revisionId: 3,
revision: 1,
folderId: 0,
displayName: "plan.pdf",
documentType: null,
providerFileType: "PDF",
providerSizeBytes: 123,
lastModifiedAt: null,
},
};
expect(buildKwpArchiveFileSyncJob(input)).toEqual({
queueName: queueNames.kwpImports,
jobName: "run-kwp-import",
payload: { kind: "kwp.archive-file-sync", ...input },
});
expect(() => buildKwpArchiveFileSyncJob({
...input,
archiveFile: { ...input.archiveFile, revisionId: 1.5 },
})).toThrow("KWP archive file jobs require stable tenant, binding, connection, cadence and revision identifiers.");
});
test("builds bounded resumable KWP archive-discovery descriptors", () => {
const input = {
tenantId: "tenant_1",
bindingId: "binding_1",
dataConnectionId: "connection_1",
cadenceBucket: "2026-07-23T11:30Z",
batchNumber: 2,
cursor: { pendingFolderIds: [-5, 6], visitedFolderIds: [0, -2, -1, 3, 4] },
};
expect(buildKwpArchiveDiscoveryJob(input)).toEqual({
queueName: queueNames.kwpImports,
jobName: "run-kwp-import",
payload: { kind: "kwp.archive-discovery", ...input },
});
expect(() => buildKwpArchiveDiscoveryJob({
...input,
cursor: { pendingFolderIds: [], visitedFolderIds: [0] },
})).toThrow("KWP archive discovery jobs require a stable project binding and a bounded folder cursor.");
expect(() => buildKwpArchiveDiscoveryJob({
...input,
cursor: { pendingFolderIds: [2_147_483_648], visitedFolderIds: [0] },
})).toThrow("KWP archive discovery jobs require a stable project binding and a bounded folder cursor.");
});
test("builds plugin invoke descriptors for the isolated plugin queue", () => {
expect(
buildPluginInvokeJob({
@@ -518,6 +868,28 @@ describe("queue producers", () => {
});
});
test("builds DB-authoritative portal document-ready events without a caller-supplied document type", () => {
expect(
buildPortalDocumentReadyOutboxEvent({
tenantId: "tenant_1",
projectId: "project_1",
fileId: "file_1",
fileEntityLinkId: "link_1",
linkVersion: new Date("2026-07-16T10:00:00.000Z"),
userId: "user_1",
})
).toEqual({
tenantId: "tenant_1",
type: "workflow.trigger.event",
payload: {
event: "portal.document_ready",
data: { projectId: "project_1", fileId: "file_1", fileEntityLinkId: "link_1" },
userId: "user_1",
},
dispatchKey: "workflow-trigger:portal-document-ready:link_1:1784196000000",
});
});
test("builds workflow execution request outbox events for queued manual runs", () => {
expect(
buildWorkflowExecutionRequestedOutboxEvent({
@@ -602,15 +974,9 @@ describe("queue producers", () => {
sourceId: "event_1",
};
expect(() => buildWorkflowTriggerOutboxEvent({ ...input, event: " " })).toThrow(
"workflow.trigger.event outbox events require event."
);
expect(() => buildWorkflowTriggerOutboxEvent({ ...input, sourceId: "" })).toThrow(
"workflow.trigger.event outbox events require sourceId."
);
expect(() => buildWorkflowTriggerOutboxEvent({ ...input, sourceId: "event 1" })).toThrow(
"workflow.trigger.event outbox events require sourceId to match"
);
expect(() => buildWorkflowTriggerOutboxEvent({ ...input, event: " " })).toThrow("workflow.trigger.event outbox events require event.");
expect(() => buildWorkflowTriggerOutboxEvent({ ...input, sourceId: "" })).toThrow("workflow.trigger.event outbox events require sourceId.");
expect(() => buildWorkflowTriggerOutboxEvent({ ...input, sourceId: "event 1" })).toThrow("workflow.trigger.event outbox events require sourceId to match");
});
test("rejects malformed workflow execution request outbox event keys before publishing", () => {
@@ -824,7 +1190,7 @@ describe("queue producers", () => {
await enqueueJob(queue, descriptor, { idempotencyKey: "safe-key", jobId: "explicit-job-id" });
expect(add).toHaveBeenCalledWith("deliver-webhook", descriptor.payload, {
...buildRetryJobOptions(descriptor),
removeOnComplete: false,
removeOnComplete: 10_000,
jobId: "explicit-job-id",
});
const enqueuedPayload = add.mock.calls[0]?.[1];
@@ -846,7 +1212,21 @@ describe("queue producers", () => {
expect(buildIdempotentJobId(descriptor)).toBe("metadata-key");
});
test("keeps completed idempotent jobs unless callers override completion retention", async () => {
test("encodes BullMQ-reserved custom job id characters without collisions", () => {
const descriptor = buildNotificationJob({
tenantId: "tenant_1",
userId: "user_1",
channel: "in-app",
messageKey: "message.ready",
metadata: { idempotencyKey: "notification:delivery%3A1" },
});
expect(buildIdempotentJobId(descriptor)).toBe("notification%3Adelivery%253A1");
expect(buildIdempotentJobId(descriptor, { idempotencyKey: "123" })).toBe("job-123");
expect(buildIdempotentJobId(descriptor, { idempotencyKey: "notification%3Adelivery%253A1" })).not.toBe(buildIdempotentJobId(descriptor));
});
test("bounds completed idempotent jobs unless callers override completion retention", async () => {
const add = vi.fn(async () => ({ id: "job_idempotent" }));
const queue = { add } as unknown as TypedQueue<typeof queueNames.notifications>;
const descriptor = buildNotificationJob({
@@ -860,7 +1240,7 @@ describe("queue producers", () => {
await enqueueJob(queue, descriptor);
expect(add).toHaveBeenLastCalledWith("send-notification", descriptor.payload, {
...buildRetryJobOptions(descriptor),
removeOnComplete: false,
removeOnComplete: 10_000,
jobId: "metadata-key",
});
@@ -915,7 +1295,7 @@ describe("queue producers", () => {
await enqueueJob(queue, descriptor);
expect(add).toHaveBeenCalledWith("run-export", descriptor.payload, {
...buildRetryJobOptions(descriptor),
removeOnComplete: false,
removeOnComplete: 10_000,
jobId: "export_job_enqueue_1",
});
});
@@ -960,7 +1340,7 @@ describe("queue producers", () => {
await enqueueJob(queue, descriptor);
expect(add).toHaveBeenCalledWith("run-import", descriptor.payload, {
...buildRetryJobOptions(descriptor),
removeOnComplete: false,
removeOnComplete: 10_000,
jobId: "import_job_enqueue_1",
});
});