Release 0.12 (#143)

* changed tb imports

* cleanup: replace console.log/warn with $console, remove commented-out code

Removed various commented-out code and replaced direct `console.log` and `console.warn` usage across the codebase with `$console` from "core" for standardized logging. Also adjusted linting rules in biome.json to enable warnings for `console.log` usage.

* ts: enable incremental

* fix imports in test files

reorganize imports to use "@sinclair/typebox" directly, replacing local utility references, and add missing "override" keywords in test classes.

* added media permissions (#142)

* added permissions support for media module

introduced `MediaPermissions` for fine-grained access control in the media module, updated routes to enforce these permissions, and adjusted permission registration logic.

* fix: handle token absence in getUploadHeaders and add tests for transport modes

ensure getUploadHeaders does not set Authorization header when token is missing. Add unit tests to validate behavior for different token_transport options.

* remove console.log on DropzoneContainer.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* add bcrypt and refactored auth resolve (#147)

* reworked auth architecture with improved password handling and claims

Refactored password strategy to prepare supporting bcrypt, improving hashing/encryption flexibility. Updated authentication flow with enhanced user resolution mechanisms, safe JWT generation, and consistent profile handling. Adjusted dependencies to include bcryptjs and updated lock files accordingly.

* fix strategy forms handling, add register route and hidden fields

Refactored strategy forms to include hidden fields for type and name. Added a registration route with necessary adjustments to the admin controller and routes. Corrected field handling within relevant forms and components.

* refactored auth handling to support bcrypt, extracted user pool

* update email regex to allow '+' and '_' characters

* update test stub password for AppAuth spec

* update data exceptions to use HttpStatus constants, adjust logging level in AppUserPool

* rework strategies to extend a base class instead of interface

* added simple bcrypt test

* add validation logs and improve data validation handling (#157)

Added warning logs for invalid data during mutator validation, refined field validation logic to handle undefined values, and adjusted event validation comments for clarity. Minor improvements include exporting events from core and handling optional chaining in entity field validation.

* modify MediaApi to support custom fetch implementation, defaults to native fetch (#158)

* modify MediaApi to support custom fetch implementation, defaults to native fetch

added an optional `fetcher` parameter to allow usage of a custom fetch function in both `upload` and `fetcher` methods. Defaults to the standard `fetch` if none is provided.

* fix tests and improve api fetcher types

* update admin basepath handling and window context integration (#155)

Refactored `useBkndWindowContext` to include `admin_basepath` and updated its usage in routing. Improved type consistency with `AdminBkndWindowContext` and ensured default values are applied for window context.

* trigger `repository-find-[one|many]-[before|after]` based on `limit` (#160)

* refactor error handling in authenticator and password strategy (#161)

made `respondWithError` method public, updated login and register routes in `PasswordStrategy` to handle errors using `respondWithError` for consistency.

* add disableSubmitOnError prop to NativeForm and export getFlashMessage (#162)

Introduced a `disableSubmitOnError` prop to NativeForm to control submit button behavior when errors are present. Also exported `getFlashMessage` from the core for external usage.

* update dependencies in package.json (#156)

moved several dependencies between devDependencies and dependencies for better categorization and removed redundant entries.

* update imports to adjust nodeTestRunner path and remove unused export (#163)

updated imports in test files to reflect the correct path for nodeTestRunner. removed redundant export of nodeTestRunner from index file to clean up module structure. In some environments this could cause issues requiring to exclude `node:test`, just removing it for now.

* fix sync events not awaited (#164)

* refactor(dropzone): extract DropzoneInner and unify state management with zustand (#165)

Simplified Dropzone implementation by extracting inner logic to a new component, `DropzoneInner`. Replaced local dropzone state logic with centralized state management using zustand. Adjusted API exports and props accordingly for consistency and maintainability.

* replace LiquidJs rendering with simplified renderer (#167)

* replace LiquidJs rendering with simplified renderer

Removed dependency on LiquidJS and replaced it with a custom templating solution using lodash `get`. Updated corresponding components, editors, and tests to align with the new rendering approach. Removed unused filters and tags.

* remove liquid js from package json

* feat/cli-generate-types (#166)

* init types generation

* update type generation for entities and fields

Refactored `EntityTypescript` to support improved field types and relations. Added `toType` method overrides for various fields to define accurate TypeScript types. Enhanced CLI `types` command with new options for output style and file handling. Removed redundant test files.

* update type generation code and CLI option description

removed unused imports definition, adjusted formatting in EntityTypescript, and clarified the CLI style option description.

* fix json schema field type generation

* reworked system entities to prevent recursive types

* reworked system entities to prevent recursive types

* remove unused object function

* types: use number instead of Generated

* update data hooks and api types

* update data hooks and api types

* update data hooks and api types

* update data hooks and api types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
dswbx
2025-05-01 10:12:18 +02:00
committed by GitHub
parent d6f94a2ce1
commit 372f94d22a
186 changed files with 2617 additions and 1997 deletions

View File

@@ -25,7 +25,6 @@ export class AppFlows extends Module<typeof flowsConfigSchema> {
}
override async build() {
//console.log("building flows", this.config);
const flows = transformObject(this.config.flows, (flowConfig, name) => {
return Flow.fromObject(name, flowConfig as any, TASKS);
});

View File

@@ -1,5 +1,7 @@
import { Const, type Static, StringRecord, Type, transformObject } from "core/utils";
import { Const, type Static, StringRecord, transformObject } from "core/utils";
import { TaskMap, TriggerMap } from "flows";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const TASKS = {
...TaskMap,

View File

@@ -2,6 +2,7 @@ import { Event, EventManager, type ListenerHandler } from "core/events";
import type { EmitsEvents } from "core/events";
import type { Task, TaskResult } from "../tasks/Task";
import type { Flow } from "./Flow";
import { $console } from "core";
export type TaskLog = TaskResult & {
task: Task;
@@ -185,10 +186,9 @@ export class Execution implements EmitsEvents {
await Promise.all(promises);
return this.run();
} catch (e) {
console.log("RuntimeExecutor: error", e);
$console.error("RuntimeExecutor: error", e);
// for now just throw
// biome-ignore lint/complexity/noUselessCatch: @todo: add error task on flow
throw e;
}
}

View File

@@ -5,6 +5,7 @@ import { Condition, TaskConnection } from "../tasks/TaskConnection";
import { Execution } from "./Execution";
import { FlowTaskConnector } from "./FlowTaskConnector";
import { Trigger } from "./triggers/Trigger";
import { $console } from "core";
type Jsoned<T extends { toJSON: () => object }> = ReturnType<T["toJSON"]>;
@@ -53,8 +54,6 @@ export class Flow {
}
getSequence(sequence: Task[][] = []): Task[][] {
//console.log("queue", queue.map((step) => step.map((t) => t.name)));
// start task
if (sequence.length === 0) {
sequence.push([this.startTask]);
@@ -69,7 +68,6 @@ export class Flow {
// check if task already in one of queue steps
// this is when we have a circle back
if (sequence.some((step) => step.includes(outTask))) {
//console.log("Task already in queue", outTask.name);
return;
}
nextStep.push(outTask);
@@ -110,14 +108,6 @@ export class Flow {
return this;
}
/*getResponse() {
if (!this.respondingTask) {
return;
}
return this.respondingTask.log.output;
}*/
// @todo: check for existence
addConnection(connection: TaskConnection) {
// check if connection already exists
@@ -179,7 +169,7 @@ export class Flow {
// @ts-ignore
return new cls(name, obj.params);
} catch (e: any) {
console.log("Error creating task", name, obj.type, obj, taskClass);
$console.error("Error creating task", name, obj.type, obj, taskClass);
throw new Error(`Error creating task ${obj.type}: ${e.message}`);
}
});

View File

@@ -31,37 +31,11 @@ export class FlowTaskConnector {
}
}
/*const targetDepth = this.task(target).getDepth();
console.log("depth", ownDepth, targetDepth);
// if target has a lower depth
if (targetDepth > 0 && ownDepth >= targetDepth) {
// check for unique out conditions
console.log(
"out conditions",
this.source.name,
this.getOutConnections().map((c) => [c.target.name, c.condition])
);
if (
this.getOutConnections().some(
(c) =>
c.condition[0] === condition[0] &&
c.condition[1] === condition[1]
)
) {
throw new Error(
"Task cannot be connected to a deeper task with the same condition"
);
}
}*/
this.flow.addConnection(new TaskConnection(this.source, target, { condition, max_retries }));
}
asOutputFor(target: Task, condition?: Condition) {
this.task(target).asInputFor(this.source, condition);
//new FlowTaskConnector(this.flow, target).asInputFor(this.source);
//this.flow.addConnection(new TaskConnection(target, this.source));
}
getNext() {
@@ -107,12 +81,4 @@ export class FlowTaskConnector {
getOutTasks(result?: TaskResult): Task[] {
return this.getOutConnections(result).map((c) => c.target);
}
/*getNextRunnableConnections() {
return this.getOutConnections().filter((c) => c.source.log.success);
}
getNextRunnableTasks() {
return this.getNextRunnableConnections().map((c) => c.target);
}*/
}

View File

@@ -1,4 +1,5 @@
import type { Task } from "../../tasks/Task";
import { $console } from "core";
export class RuntimeExecutor {
async run(
@@ -10,7 +11,6 @@ export class RuntimeExecutor {
return;
}
//const promises = tasks.map((t) => t.run());
const promises = tasks.map(async (t) => {
const result = await t.run();
onDone?.(t, result);
@@ -20,7 +20,7 @@ export class RuntimeExecutor {
try {
await Promise.all(promises);
} catch (e) {
console.log("RuntimeExecutor: error", e);
$console.error("RuntimeExecutor: error", e);
}
return this.run(nextTasks, onDone);

View File

@@ -1,7 +1,9 @@
import type { EventManager } from "core/events";
import { Type } from "core/utils";
import type { Flow } from "../Flow";
import { Trigger } from "./Trigger";
import { $console } from "core";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class EventTrigger extends Trigger<typeof EventTrigger.schema> {
override type = "event";
@@ -22,17 +24,13 @@ export class EventTrigger extends Trigger<typeof EventTrigger.schema> {
emgr.on(
this.config.event,
async (event) => {
console.log("event", event);
/*if (!this.match(event)) {
return;
}*/
const execution = flow.createExecution();
this.executions.push(execution);
try {
await execution.start(event.params);
} catch (e) {
console.error(e);
$console.error(e);
}
},
this.config.mode,

View File

@@ -1,7 +1,9 @@
import { StringEnum, Type } from "core/utils";
import { StringEnum } from "core/utils";
import type { Context, Hono } from "hono";
import type { Flow } from "../Flow";
import { Trigger } from "./Trigger";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const httpMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"] as const;
@@ -10,14 +12,11 @@ export class HttpTrigger extends Trigger<typeof HttpTrigger.schema> {
static override schema = Type.Composite([
Trigger.schema,
Type.Object(
{
path: Type.String({ pattern: "^/.*$" }),
method: StringEnum(httpMethods, { default: "GET" }),
response_type: StringEnum(["json", "text", "html"], { default: "json" }),
},
//{ additionalProperties: false }
),
Type.Object({
path: Type.String({ pattern: "^/.*$" }),
method: StringEnum(httpMethods, { default: "GET" }),
response_type: StringEnum(["json", "text", "html"], { default: "json" }),
}),
]);
override async register(flow: Flow, hono: Hono<any>) {
@@ -43,7 +42,5 @@ export class HttpTrigger extends Trigger<typeof HttpTrigger.schema> {
execution.start(params);
return c.json({ success: true });
});
//console.log("--registered flow", flow.name, "on", method, this.config.path);
}
}

View File

@@ -1,6 +1,8 @@
import { type Static, StringEnum, Type, parse } from "core/utils";
import { type Static, StringEnum, parse } from "core/utils";
import type { Execution } from "../Execution";
import type { Flow } from "../Flow";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class Trigger<Schema extends typeof Trigger.schema = typeof Trigger.schema> {
// @todo: remove this
@@ -8,12 +10,9 @@ export class Trigger<Schema extends typeof Trigger.schema = typeof Trigger.schem
type = "manual";
config: Static<Schema>;
static schema = Type.Object(
{
mode: StringEnum(["sync", "async"], { default: "async" }),
},
//{ additionalProperties: false }
);
static schema = Type.Object({
mode: StringEnum(["sync", "async"], { default: "async" }),
});
constructor(config?: Partial<Static<Schema>>) {
const schema = (this.constructor as typeof Trigger).schema;

View File

@@ -4,7 +4,6 @@ import { Trigger } from "./Trigger";
export { Trigger, EventTrigger, HttpTrigger };
//export type TriggerMapType = { [key: string]: { cls: typeof Trigger } };
export const TriggerMap = {
manual: { cls: Trigger },
event: { cls: EventTrigger },

View File

@@ -23,13 +23,9 @@ export {
} from "./flows/triggers";
import { Task } from "./tasks/Task";
export { type TaskResult, type TaskRenderProps } from "./tasks/Task";
export type { TaskResult, TaskRenderProps } from "./tasks/Task";
export { TaskConnection, Condition } from "./tasks/TaskConnection";
// test
//export { simpleFetch } from "./examples/simple-fetch";
//export type TaskMapType = { [key: string]: { cls: typeof Task<any> } };
export const TaskMap = {
fetch: { cls: FetchTask },
log: { cls: LogTask },

View File

@@ -1,8 +1,9 @@
import type { StaticDecode, TSchema } from "@sinclair/typebox";
import type { NodeProps } from "@xyflow/react";
import { BkndError, SimpleRenderer } from "core";
import { type Static, type TObject, Type, Value, parse, ucFirst } from "core/utils";
import type { ExecutionEvent, InputsMap } from "../flows/Execution";
import { type Static, type TObject, Value, parse, ucFirst } from "core/utils";
import type { InputsMap } from "../flows/Execution";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
//type InstanceOf<T> = T extends new (...args: any) => infer R ? R : never;
export type TaskResult<Output = any> = {
@@ -13,10 +14,6 @@ export type TaskResult<Output = any> = {
params: any;
};
/*export type TaskRenderProps<T extends Task = Task> = NodeProps<{
task: T;
state: { i: number; isStartTask: boolean; isRespondingTask; event: ExecutionEvent | undefined };
}>;*/
export type TaskRenderProps<T extends Task = Task> = any;
export function dynamic<Type extends TSchema>(
@@ -93,21 +90,6 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
// @todo: string enums fail to validate
this._params = parse(schema, params || {});
/*const validator = new Validator(schema as any);
const _params = Default(schema, params || {});
const result = validator.validate(_params);
if (!result.valid) {
//console.log("---errors", result, { params, _params });
const error = result.errors[0]!;
throw new Error(
`Invalid params for task "${name}.${error.keyword}": "${
error.error
}". Params given: ${JSON.stringify(params)}`
);
}
this._params = _params as Static<Params>;*/
}
get params() {
@@ -124,13 +106,10 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
inputs: object = {},
): Promise<StaticDecode<S>> {
const newParams: any = {};
const renderer = new SimpleRenderer(inputs, { strictVariables: true, renderKeys: true });
//console.log("--resolveParams", params);
const renderer = new SimpleRenderer(inputs, { renderKeys: true });
for (const [key, value] of Object.entries(params)) {
if (value && SimpleRenderer.hasMarkup(value)) {
//console.log("--- has markup", value);
try {
newParams[key] = await renderer.render(value as string);
} catch (e: any) {
@@ -150,29 +129,21 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
throw e;
}
continue;
} else {
//console.log("-- no markup", key, value);
}
newParams[key] = value;
}
//console.log("--beforeDecode", newParams);
const v = Value.Decode(schema, newParams);
//console.log("--afterDecode", v);
//process.exit();
return v;
return Value.Decode(schema, newParams);
}
private async cloneWithResolvedParams(_inputs: Map<string, any>) {
const inputs = Object.fromEntries(_inputs.entries());
//console.log("--clone:inputs", inputs, this.params);
const newParams = await Task.resolveParams(
(this.constructor as any).schema,
this._params,
inputs,
);
//console.log("--clone:newParams", this.name, newParams);
return this.clone(this.name, newParams as any);
}
@@ -200,7 +171,6 @@ export abstract class Task<Params extends TObject = TObject, Output = unknown> {
success = true;
} catch (e: any) {
success = false;
//status.output = undefined;
if (e instanceof BkndError) {
error = e.toJSON();

View File

@@ -80,7 +80,6 @@ export class Condition {
return result.success === false;
case "matches":
return get(result.output, this.path) === this.value;
//return this.value === output[this.path];
}
}

View File

@@ -1,6 +1,7 @@
import { StringEnum, Type } from "core/utils";
import type { InputsMap } from "../../flows/Execution";
import { StringEnum } from "core/utils";
import { Task, dynamic } from "../Task";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const FetchMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
@@ -14,8 +15,6 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
url: Type.String({
pattern: "^(http|https)://",
}),
//method: Type.Optional(Type.Enum(FetchMethodsEnum)),
//method: Type.Optional(dynamic(Type.String({ enum: FetchMethods, default: "GET" }))),
method: Type.Optional(dynamic(StringEnum(FetchMethods, { default: "GET" }))),
headers: Type.Optional(
dynamic(
@@ -42,7 +41,6 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
}
async execute() {
//console.log(`method: (${this.params.method})`);
if (!FetchMethods.includes(this.params.method ?? "GET")) {
throw this.error("Invalid method", {
given: this.params.method,
@@ -53,19 +51,12 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
const body = this.getBody();
const headers = new Headers(this.params.headers?.map((h) => [h.key, h.value]));
/*console.log("[FETCH]", {
url: this.params.url,
method: this.params.method ?? "GET",
headers,
body
});*/
const result = await fetch(this.params.url, {
method: this.params.method ?? "GET",
headers,
body,
});
//console.log("fetch:response", result);
if (!result.ok) {
throw this.error("Failed to fetch", {
status: result.status,
@@ -74,8 +65,6 @@ export class FetchTask<Output extends Record<string, any>> extends Task<
}
const data = (await result.json()) as Output;
//console.log("fetch:response:data", data);
return data;
}
}

View File

@@ -1,5 +1,7 @@
import { Type } from "core/utils";
import { Task } from "../Task";
import { $console } from "core";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class LogTask extends Task<typeof LogTask.schema> {
type = "log";
@@ -10,7 +12,7 @@ export class LogTask extends Task<typeof LogTask.schema> {
async execute() {
await new Promise((resolve) => setTimeout(resolve, this.params.delay));
console.log(`[DONE] LogTask: ${this.name}`);
$console.log(`[DONE] LogTask: ${this.name}`);
return true;
}
}

View File

@@ -1,5 +1,6 @@
import { Type } from "core/utils";
import { Task } from "../Task";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class RenderTask<Output extends Record<string, any>> extends Task<
typeof RenderTask.schema,

View File

@@ -1,6 +1,7 @@
import { Type } from "core/utils";
import { Flow } from "../../flows/Flow";
import { Task, dynamic } from "../Task";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class SubFlowTask<Output extends Record<string, any>> extends Task<
typeof SubFlowTask.schema,