Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,16 @@
import { WorkflowBlockDto } from "./WorkflowBlockDto";
import { WorkflowDto } from "./WorkflowDto";
import type { OutboundHttpFetchOptions } from "~/utils/outboundHttp.server";
export type BlockExecutionParamsDto = {
workflow: WorkflowDto;
workflowContext: { [key: string]: any };
block: WorkflowBlockDto;
workflowExecutionId: string;
session: {
tenantId: string | null;
userId: string | null;
};
executionPath?: string[];
httpFetchOptions?: OutboundHttpFetchOptions;
};
@@ -0,0 +1,6 @@
export type BlockExecutionResultDto = {
output: { [key: string]: any } | any | null;
toBlockIds: string[];
error?: string | null;
throwsError?: boolean;
};
@@ -0,0 +1,25 @@
import { WorkflowConditionsGroupDto } from "./WorkflowConditionDtos";
import { WorkflowBlockType } from "./WorkflowBlockTypes";
export type WorkflowBlockDto = {
id: string;
index: number;
type: WorkflowBlockType;
variableName: string;
description: string;
input: { [key: string]: any };
isTrigger: boolean;
isBlock: boolean;
// position: {
// x: number;
// y: number;
// };
conditionGroups: WorkflowConditionsGroupDto[];
toBlocks: {
id: string;
// flowId: string;
// sourceHandle?: string | null;
toBlockId: string;
condition: string | null;
}[];
};
@@ -0,0 +1,18 @@
import { WorkflowBlockType } from "./WorkflowBlockTypes";
import { WorkflowStatus } from "./WorkflowStatus";
export type WorkflowBlockExecutionDto = {
id: string;
workflowBlockId: string;
fromWorkflowBlockId: string | null;
status: WorkflowStatus;
startedAt: Date;
endedAt: Date | null;
input: { [key: string]: any } | null;
output: { [key: string]: any } | null;
error: string | null;
workflowBlock: {
type: WorkflowBlockType;
description: string;
};
};
@@ -0,0 +1,190 @@
import { describe, expect, it } from "vitest";
import fs from "node:fs";
import path from "node:path";
import { NATIVE_WORKFLOW_TRIGGER_SUPPORTED_BLOCK_TYPES, workflowBlockContracts } from "@toolctrl/foundation";
import { WorkflowBlockTypes } from "./WorkflowBlockTypes";
import { CORE_WORKFLOW_BLOCK_TYPES } from "../services/blocks/WorkflowBlockService";
import { PRO_WORKFLOW_BLOCK_TYPES } from "../services/blocks/WorkflowBlockProService";
import { getWorkflowBlockOptionLabel } from "./WorkflowBlockTypes";
const repoRoot = process.cwd();
describe("WorkflowBlockTypes registry contract", () => {
it("keeps registry block values unique", () => {
const values = WorkflowBlockTypes.map((block) => block.value);
expect(new Set(values).size).toBe(values.length);
});
it("keeps every visible block backed by exactly one executor", () => {
const registryValues = WorkflowBlockTypes.map((block) => block.value).sort();
const executorValues = [...CORE_WORKFLOW_BLOCK_TYPES, ...PRO_WORKFLOW_BLOCK_TYPES].sort();
expect(registryValues).toEqual(executorValues);
});
it("keeps the visible registry in sync with the worker-safe block contract", () => {
const registryValues = WorkflowBlockTypes.map((block) => block.value).sort();
const contractValues = workflowBlockContracts.map((contract) => contract.value).sort();
expect(registryValues).toEqual(contractValues);
for (const contract of workflowBlockContracts) {
const block = WorkflowBlockTypes.find((candidate) => candidate.value === contract.value);
const requiredInputs = block?.inputs
.filter((input) => input.required)
.map((input) => input.name)
.sort();
expect(requiredInputs).toEqual([...contract.requiredInputs].sort());
}
});
it("keeps executor ownership aligned with the shared contract", () => {
const coreContracts = workflowBlockContracts
.filter((contract) => contract.executor === "core")
.map((contract) => contract.value)
.sort();
const proContracts = workflowBlockContracts
.filter((contract) => contract.executor === "pro")
.map((contract) => contract.value)
.sort();
expect([...CORE_WORKFLOW_BLOCK_TYPES].sort()).toEqual(coreContracts);
expect([...PRO_WORKFLOW_BLOCK_TYPES].sort()).toEqual(proContracts);
});
it("keeps native worker support aligned with the shared contract", () => {
const nativeContracts = workflowBlockContracts
.filter((contract) => contract.nativeSupport === "supported")
.map((contract) => contract.value)
.sort();
expect([...NATIVE_WORKFLOW_TRIGGER_SUPPORTED_BLOCK_TYPES].sort()).toEqual(nativeContracts);
expect(workflowBlockContracts.find((contract) => contract.value === "if")?.nativeSupport).toBe("supported");
expect(workflowBlockContracts.find((contract) => contract.value === "switch")?.nativeSupport).toBe("supported");
expect(workflowBlockContracts.find((contract) => contract.value === "rowGet")?.nativeSupport).toBe("supported");
expect(workflowBlockContracts.find((contract) => contract.value === "iterator")?.nativeSupport).toBe("supported");
});
it("keeps the production worker block surface classified intentionally", () => {
const surface = Object.fromEntries(
workflowBlockContracts.map((contract) => [
contract.value,
{
executor: contract.executor,
nativeSupport: contract.nativeSupport,
},
])
);
expect(surface).toEqual({
alertUser: { executor: "core", nativeSupport: "supported" },
doNothing: { executor: "core", nativeSupport: "supported" },
email: { executor: "pro", nativeSupport: "supported" },
event: { executor: "core", nativeSupport: "supported" },
httpRequest: { executor: "core", nativeSupport: "supported" },
if: { executor: "core", nativeSupport: "supported" },
iterator: { executor: "core", nativeSupport: "supported" },
log: { executor: "core", nativeSupport: "supported" },
manual: { executor: "core", nativeSupport: "supported" },
rowCreate: { executor: "pro", nativeSupport: "preflight-skip" },
rowDelete: { executor: "pro", nativeSupport: "preflight-skip" },
rowGet: { executor: "pro", nativeSupport: "supported" },
rowUpdate: { executor: "pro", nativeSupport: "preflight-skip" },
switch: { executor: "core", nativeSupport: "supported" },
variable: { executor: "core", nativeSupport: "supported" },
waitForInput: { executor: "pro", nativeSupport: "preflight-skip" },
});
});
it("keeps visible registry copy as translation tokens", () => {
for (const block of WorkflowBlockTypes) {
expect(block.name).toBe(block.value);
expect(block.category).toMatch(/^[a-z]+$/u);
for (const input of block.inputs) {
expect(input.label).toBe(input.name);
if (input.href) {
expect(input.href.label).toMatch(/^[a-z][a-zA-Z0-9]*$/u);
}
if (input.placeholder) {
expect(input.placeholder).toMatch(/^(https:\/\/|workflows\.blocks\.)/u);
}
}
for (const output of block.outputs) {
expect(output.label).toBe(output.name);
}
}
});
it("publishes the complete http request runner output contract", () => {
const httpRequestBlock = WorkflowBlockTypes.find((block) => block.value === "httpRequest");
expect(httpRequestBlock?.outputs.map((output) => output.name).sort()).toEqual(["body", "error", "statusCode", "truncated"]);
});
it("keeps every visible block category backed by en/de translations", () => {
const locales = ["en", "de"] as const;
const categoryKeys = [...new Set(WorkflowBlockTypes.map((block) => block.category))].sort();
for (const locale of locales) {
const translations = JSON.parse(fs.readFileSync(path.join(repoRoot, "apps/web/public/locales", locale, "translations.json"), "utf8"));
for (const category of categoryKeys) {
expect(translations.workflows.blocks.categories, `${locale} workflows.blocks.categories.${category}`).toHaveProperty(category);
}
}
});
it("keeps every visible block label backed by en/de translations", () => {
const locales = ["en", "de"] as const;
const inputKeys = [...new Set(WorkflowBlockTypes.flatMap((block) => block.inputs.map((input) => input.name)))].sort();
const optionKeys = [
...new Set(
WorkflowBlockTypes.flatMap((block) =>
block.value === "event" ? [] : block.inputs.flatMap((input) => input.options?.map((option) => option.value) ?? [])
)
),
].sort();
for (const locale of locales) {
const translations = JSON.parse(fs.readFileSync(path.join(repoRoot, "apps/web/public/locales", locale, "translations.json"), "utf8"));
for (const block of WorkflowBlockTypes) {
expect(translations.workflows.blocks[block.value], `${locale} workflows.blocks.${block.value}.name`).toHaveProperty("name");
}
for (const input of inputKeys) {
expect(translations.workflows.blocks.inputs, `${locale} workflows.blocks.inputs.${input}`).toHaveProperty(input);
}
for (const option of optionKeys) {
expect(translations.workflows.blocks.options, `${locale} workflows.blocks.options.${option}`).toHaveProperty(option);
}
}
});
it("keeps every visible block output backed by en/de translations", () => {
const locales = ["en", "de"] as const;
const outputKeys = [...new Set(WorkflowBlockTypes.flatMap((block) => block.outputs.map((output) => output.name)))].sort();
expect(outputKeys).toContain("truncated");
for (const locale of locales) {
const translations = JSON.parse(fs.readFileSync(path.join(repoRoot, "apps/web/public/locales", locale, "translations.json"), "utf8"));
for (const output of outputKeys) {
expect(translations.workflows.blocks.outputs, `${locale} workflows.blocks.outputs.${output}`).toHaveProperty(output);
}
}
});
it("localizes application event option labels with readable names", () => {
const label = getWorkflowBlockOptionLabel(
{ value: "row.created", label: "row.created (row.created)" },
(key, defaultValue) => (key === "events.names.row_created" ? "Localized row created" : defaultValue)
);
expect(label).toBe("row.created - Localized row created");
});
});
@@ -0,0 +1,328 @@
import { ApplicationEvents, getApplicationEventNameKey } from "~/modules/events/types/ApplicationEvent";
import WorkflowBlockActionIcon from "../components/icons/WorkflowBlockActionIcon";
import ConditionalIcon from "../components/nodes/flow/conditional/ConditionalIcon";
import DoNothingIcon from "../components/nodes/helpers/doNothing/DoNothingIcon";
import HttpRequestIcon from "../components/nodes/helpers/httpRequest/HttpRequestIcon";
import LogIcon from "../components/nodes/helpers/log/LogIcon";
import TriggerManualIcon from "../components/nodes/triggers/manual/TriggerManualIcon";
export const WorkflowBlockTypes: WorkflowBlockTypeDto[] = [
{
type: "trigger",
category: "misc",
name: "manual",
value: "manual",
icon: TriggerManualIcon,
inputs: [
{ name: "validation", type: "monaco", label: "validation", required: false, href: { url: "https://github.com/ajv-validator/ajv", label: "learnMore" } },
],
outputs: [],
},
{
type: "trigger",
category: "app",
name: "event",
value: "event",
icon: WorkflowBlockActionIcon,
appliesToAllTenants: true,
inputs: [
{
name: "event",
type: "select",
label: "event",
required: true,
options: ApplicationEvents.map((f) => ({ value: f.value, label: `${f.value} (${f.value})`, adminOnly: f.adminOnly })),
},
{ name: "entity", type: "string", label: "entity", required: false, if: { name: "event", values: ["row.created", "row.updated", "row.deleted"] } },
],
outputs: [{ name: "data", label: "data" }],
},
{
type: "action",
category: "flow",
name: "if",
value: "if",
icon: ConditionalIcon,
inputs: [],
outputs: [],
},
{
type: "action",
category: "flow",
name: "switch",
value: "switch",
icon: ConditionalIcon,
inputs: [],
outputs: [],
},
{
type: "action",
category: "helpers",
name: "httpRequest",
value: "httpRequest",
icon: HttpRequestIcon,
inputs: [
{ name: "url", type: "string", label: "url", required: true, placeholder: "https://api.example.com" },
{
name: "method",
type: "select",
label: "method",
required: true,
options: [
{ label: "GET", value: "GET" },
{ label: "POST", value: "POST" },
{ label: "PUT", value: "PUT" },
{ label: "DELETE", value: "DELETE" },
{ label: "PATCH", value: "PATCH" },
{ label: "HEAD", value: "HEAD" },
{ label: "OPTIONS", value: "OPTIONS" },
],
},
{ name: "body", type: "monaco", label: "body", required: false },
{ name: "headers", type: "keyValue", label: "headers", required: false },
{ name: "throwsError", type: "boolean", label: "throwsError", defaultValue: true },
],
outputs: [
{ name: "statusCode", label: "statusCode" },
{ name: "body", label: "body" },
{ name: "error", label: "error" },
{ name: "truncated", label: "truncated" },
],
},
{
type: "action",
category: "helpers",
name: "log",
value: "log",
icon: LogIcon,
inputs: [{ name: "message", type: "string", label: "message", required: true, placeholder: "workflows.blocks.log.inputs.message.placeholder" }],
outputs: [],
},
{
type: "action",
category: "helpers",
name: "alertUser",
value: "alertUser",
icon: LogIcon,
inputs: [
{ name: "message", type: "string", label: "message", required: true, placeholder: "workflows.blocks.alertUser.inputs.message.placeholder" },
{
name: "type",
type: "select",
label: "type",
required: false,
defaultValue: "success",
options: [
{ label: "success", value: "success" },
{ label: "error", value: "error" },
],
},
],
outputs: [],
},
{
type: "action",
category: "helpers",
name: "doNothing",
value: "doNothing",
icon: DoNothingIcon,
inputs: [],
outputs: [],
},
{
type: "action",
category: "interaction",
name: "waitForInput",
value: "waitForInput",
icon: WorkflowBlockActionIcon,
inputs: [
{ name: "title", type: "string", label: "title", required: false },
{ name: "placeholder", type: "string", label: "placeholder", required: false },
],
outputs: [{ name: "input", label: "input" }],
},
{
type: "action",
category: "entities",
name: "rowGet",
value: "rowGet",
icon: WorkflowBlockActionIcon,
inputs: [
{ name: "entity", type: "string", label: "entity", required: true },
{ name: "id", type: "string", label: "id", required: true },
],
outputs: [{ name: "row", label: "row" }],
},
{
type: "action",
category: "entities",
name: "rowCreate",
value: "rowCreate",
icon: WorkflowBlockActionIcon,
inputs: [
{ name: "entity", type: "string", label: "entity", required: true },
{ name: "row", type: "monaco", label: "row", required: true },
],
outputs: [{ name: "row", label: "row" }],
},
{
type: "action",
category: "entities",
name: "rowUpdate",
value: "rowUpdate",
icon: WorkflowBlockActionIcon,
inputs: [
{ name: "entity", type: "string", label: "entity", required: true },
{ name: "id", type: "string", label: "id", required: true },
{ name: "data", type: "monaco", label: "data", required: true },
],
outputs: [{ name: "row", label: "row" }],
},
{
type: "action",
category: "entities",
name: "rowDelete",
value: "rowDelete",
icon: WorkflowBlockActionIcon,
inputs: [
{ name: "entity", type: "string", label: "entity", required: true },
{ name: "id", type: "string", label: "id", required: true },
],
outputs: [{ name: "row", label: "row" }],
},
{
type: "action",
category: "flow",
name: "iterator",
value: "iterator",
icon: WorkflowBlockActionIcon,
inputs: [{ name: "variableName", type: "string", label: "variableName", required: true }],
outputs: [
{ name: "index", label: "index" },
{ name: "item", label: "item" },
{ name: "isFirst", label: "isFirst" },
{ name: "isLast", label: "isLast" },
],
},
{
type: "action",
category: "flow",
name: "variable",
value: "variable",
icon: WorkflowBlockActionIcon,
inputs: [
{ name: "variableName", type: "string", label: "variableName", required: true },
{ name: "value", type: "string", label: "value", required: true },
],
outputs: [],
},
{
type: "action",
category: "app",
name: "email",
value: "email",
icon: WorkflowBlockActionIcon,
inputs: [
{
name: "provider",
type: "select",
label: "provider",
required: true,
options: [
{ label: "Mailjet", value: "mailjet" },
],
},
{ name: "to", type: "string", label: "to", required: true },
{ name: "subject", type: "string", label: "subject", required: true },
{ name: "body", type: "string", label: "body", required: true },
],
outputs: [],
},
];
export type WorkflowBlockType =
| "manual"
| "if"
| "switch"
| "httpRequest"
| "log"
| "alertUser"
| "doNothing"
| "waitForInput"
| "rowGet"
| "rowCreate"
| "rowUpdate"
| "rowDelete"
| "iterator"
| "variable"
| "event"
| "email";
export type WorkflowBlockTypeDto = {
type: "trigger" | "action";
category: "misc" | "flow" | "helpers" | "interaction" | "ai" | "entities" | "app";
name: string;
value: WorkflowBlockType;
icon: any;
inputs: WorkflowBlockInput[];
outputs: WorkflowBlockOutput[];
appliesToAllTenants?: boolean;
};
export type WorkflowBlockInput = {
name: string;
type: "string" | "monaco" | "keyValue" | "select" | "boolean";
label: string;
required?: boolean;
placeholder?: string;
options?: {
label: string;
value: string;
adminOnly?: boolean;
}[];
defaultValue?: string | boolean;
href?: { url: string; label: string };
if?: { name: string; values: string[] };
};
export type WorkflowBlockOutput = {
name: string;
label: string;
};
type WorkflowBlockTranslator = (key: string, defaultValue: string) => string;
export function getWorkflowBlockName(block: Pick<WorkflowBlockTypeDto, "value" | "name">, t: WorkflowBlockTranslator): string {
return t(`workflows.blocks.${block.value}.name`, block.name);
}
export function getWorkflowBlockCategoryLabel(category: WorkflowBlockTypeDto["category"], t: WorkflowBlockTranslator): string {
return t(`workflows.blocks.categories.${category}`, category);
}
export function getWorkflowBlockInputLabel(input: Pick<WorkflowBlockInput, "name" | "label">, t: WorkflowBlockTranslator): string {
return t(`workflows.blocks.inputs.${input.name}`, input.label);
}
export function getWorkflowBlockInputPlaceholder(
block: Pick<WorkflowBlockTypeDto, "value">,
input: Pick<WorkflowBlockInput, "name" | "placeholder">,
t: WorkflowBlockTranslator
): string | undefined {
if (!input.placeholder) return undefined;
return t(`workflows.blocks.${block.value}.inputs.${input.name}.placeholder`, input.placeholder);
}
export function getWorkflowBlockInputHrefLabel(input: Pick<WorkflowBlockInput, "href">, t: WorkflowBlockTranslator): string | undefined {
if (!input.href) return undefined;
return t("workflows.blocks.common.learnMore", input.href.label);
}
export function getWorkflowBlockOptionLabel(option: { label: string; value: string }, t: WorkflowBlockTranslator): string {
const event = ApplicationEvents.find((item) => item.value === option.value);
if (event) {
const eventLabel = t(getApplicationEventNameKey(event.value), event.value);
return `${option.value} - ${eventLabel}`;
}
return t(`workflows.blocks.options.${option.value}`, option.label);
}
export function getWorkflowBlockOutputLabel(output: Pick<WorkflowBlockOutput, "name" | "label">, t: WorkflowBlockTranslator): string {
return t(`workflows.blocks.outputs.${output.name}`, output.label);
}
@@ -0,0 +1,30 @@
export type WorkflowConditionsGroupDto = {
// id: string;
index: number;
type: "AND" | "OR";
conditions: WorkflowConditionsDto[];
};
export type WorkflowConditionsDto = {
// id: string;
index: number;
variable: string; // Refers to the variable in the workflow context
operator: WorkflowConditionOperator; // '=', '!=', '>', '<', '>=', '<=', etc.
value: string; // The value to compare against
};
export type WorkflowConditionOperator = typeof WorkflowConditionOperators[number]["value"];
export const WorkflowConditionOperators = [
{ name: "Equals", value: "=", requiresValue: true, translationKey: "workflows.conditions.operators.equals" },
{ name: "Not equals", value: "!=", requiresValue: true, translationKey: "workflows.conditions.operators.notEquals" },
{ name: "Greater than", value: ">", requiresValue: true, translationKey: "workflows.conditions.operators.greaterThan" },
{ name: "Less than", value: "<", requiresValue: true, translationKey: "workflows.conditions.operators.lessThan" },
{ name: "Greater than or equals", value: ">=", requiresValue: true, translationKey: "workflows.conditions.operators.greaterThanOrEquals" },
{ name: "Less than or equals", value: "<=", requiresValue: true, translationKey: "workflows.conditions.operators.lessThanOrEquals" },
{ name: "Contains", value: "contains", requiresValue: true, translationKey: "workflows.conditions.operators.contains" },
{ name: "Does not contain", value: "doesNotContain", requiresValue: true, translationKey: "workflows.conditions.operators.doesNotContain" },
{ name: "Starts with", value: "startsWith", requiresValue: true, translationKey: "workflows.conditions.operators.startsWith" },
{ name: "Ends with", value: "endsWith", requiresValue: true, translationKey: "workflows.conditions.operators.endsWith" },
{ name: "Is empty", value: "isEmpty", requiresValue: false, translationKey: "workflows.conditions.operators.isEmpty" },
{ name: "Is not empty", value: "isNotEmpty", requiresValue: false, translationKey: "workflows.conditions.operators.isNotEmpty" },
] as const;
@@ -0,0 +1,22 @@
import { TenantSimple } from "~/utils/db/tenants.db.server";
import { WorkflowBlockDto } from "./WorkflowBlockDto";
import { WorkflowInputExampleDto } from "./WorkflowInputExampleDto";
export type WorkflowDto = {
id: string;
tenantId: string | null;
tenant: TenantSimple | null;
name: string;
description: string;
status: "draft" | "live" | "archived";
createdAt: Date;
updatedAt: Date | null;
appliesToAllTenants: boolean;
blocks: WorkflowBlockDto[];
inputExamples: WorkflowInputExampleDto[];
_count: {
executions: number;
};
$variables?: string[];
$credentials?: string[];
};
@@ -0,0 +1,17 @@
import { WorkflowBlockDto } from "./WorkflowBlockDto";
import { WorkflowBlockExecutionDto } from "./WorkflowBlockExecutionDto";
import { WorkflowStatus } from "./WorkflowStatus";
export type WorkflowExecutionDto = {
id: string;
createdAt: Date;
status: WorkflowStatus;
input: { [key: string]: any } | null;
output: { [key: string]: any } | null;
duration: number | null;
endedAt: Date | null;
error: string | null;
blockRuns: WorkflowBlockExecutionDto[];
executionAlerts: { type: "success" | "error"; message: string }[];
waitingBlock: WorkflowBlockDto | null;
};
@@ -0,0 +1,6 @@
export type WorkflowInputExampleDto = {
id?: string;
title: string;
input: { [key: string]: any };
createdAt?: Date;
};
@@ -0,0 +1 @@
export type WorkflowStatus = "running" | "success" | "error" | "waitingBlock";
@@ -0,0 +1,44 @@
import { WorkflowBlockType } from "./WorkflowBlockTypes";
import { WorkflowConditionOperator } from "./WorkflowConditionDtos";
export type WorkflowsTemplateDto = {
key?: string;
title: string;
workflows: WorkflowTemplateDto[];
variables?: { name: string; value: string }[];
credentialsRequired?: string[];
adminOnly?: boolean;
};
export type WorkflowTemplateDto = {
key?: string;
name: string;
description?: string;
blocks: {
id: string;
type: WorkflowBlockType; // "manual" | "api" | "if" | "switch" | "httpRequest" | "log" | "doNothing"
description?: string;
input?: { [key: string]: any };
conditionGroups?: {
// index: number;
type: "AND" | "OR";
case?: string; // switch (case1,case2,default)
conditions: {
// index: number;
variable: string;
operator: WorkflowConditionOperator; // '=', '!=', '>', '<', '>=', '<=', 'contains', 'doesNotContain', 'startsWith', 'endsWith', 'isEmpty', 'isNotEmpty'
value: string; // The value to compare against
}[];
}[];
}[];
toBlocks: {
fromBlockId: string;
toBlockId: string;
condition?: string; // if (true, false), switch (case1,case2,default)
}[];
inputExamples: {
key?: string;
title: string;
input: { [key: string]: any };
}[];
};