mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
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:
@@ -1,6 +1,7 @@
|
||||
import type { PrimaryFieldType } from "core";
|
||||
import { $console, type PrimaryFieldType } from "core";
|
||||
import { isDebug } from "core/env";
|
||||
import { encodeSearch } from "core/utils/reqres";
|
||||
import type { ApiFetcher } from "Api";
|
||||
|
||||
export type { PrimaryFieldType };
|
||||
export type BaseModuleApiOptions = {
|
||||
@@ -24,11 +25,11 @@ export type ApiResponse<Data = any> = {
|
||||
export type TInput = string | (string | number | PrimaryFieldType)[];
|
||||
|
||||
export abstract class ModuleApi<Options extends BaseModuleApiOptions = BaseModuleApiOptions> {
|
||||
protected fetcher: typeof fetch;
|
||||
protected fetcher: ApiFetcher;
|
||||
|
||||
constructor(
|
||||
protected readonly _options: Partial<Options> = {},
|
||||
fetcher?: typeof fetch,
|
||||
fetcher?: ApiFetcher,
|
||||
) {
|
||||
this.fetcher = fetcher ?? fetch;
|
||||
}
|
||||
@@ -87,7 +88,6 @@ export abstract class ModuleApi<Options extends BaseModuleApiOptions = BaseModul
|
||||
|
||||
// only add token if initial headers not provided
|
||||
if (this.options.token && this.options.token_transport === "header") {
|
||||
//console.log("setting token", this.options.token);
|
||||
headers.set("Authorization", `Bearer ${this.options.token}`);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ export class FetchPromise<T = ApiResponse<any>> implements Promise<T> {
|
||||
constructor(
|
||||
public request: Request,
|
||||
protected options?: {
|
||||
fetcher?: typeof fetch;
|
||||
fetcher?: ApiFetcher;
|
||||
verbose?: boolean;
|
||||
},
|
||||
// keep "any" here, it gets inferred correctly with the "refine" fn
|
||||
@@ -245,7 +245,7 @@ export class FetchPromise<T = ApiResponse<any>> implements Promise<T> {
|
||||
|
||||
const fetcher = this.options?.fetcher ?? fetch;
|
||||
if (this.verbose) {
|
||||
console.log("[FetchPromise] Request", {
|
||||
$console.debug("[FetchPromise] Request", {
|
||||
method: this.request.method,
|
||||
url: this.request.url,
|
||||
});
|
||||
@@ -253,7 +253,7 @@ export class FetchPromise<T = ApiResponse<any>> implements Promise<T> {
|
||||
|
||||
const res = await fetcher(this.request);
|
||||
if (this.verbose) {
|
||||
console.log("[FetchPromise] Response", {
|
||||
$console.debug("[FetchPromise] Response", {
|
||||
res: res,
|
||||
ok: res.ok,
|
||||
status: res.status,
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
Default,
|
||||
type Static,
|
||||
StringEnum,
|
||||
Type,
|
||||
mark,
|
||||
objectEach,
|
||||
stripMark,
|
||||
@@ -34,6 +33,8 @@ import { AppFlows } from "../flows/AppFlows";
|
||||
import { AppMedia } from "../media/AppMedia";
|
||||
import type { ServerEnv } from "./Controller";
|
||||
import { Module, type ModuleBuildContext } from "./Module";
|
||||
import * as tbbox from "@sinclair/typebox";
|
||||
const { Type } = tbbox;
|
||||
|
||||
export type { ModuleBuildContext };
|
||||
|
||||
@@ -644,7 +645,7 @@ export class ModuleManager {
|
||||
// revert to previous config & rebuild using original listener
|
||||
this.revertModules();
|
||||
await this.onModuleConfigUpdated(name, module.config as any);
|
||||
$console.log(`[Safe Mutate] reverted "${name}":`);
|
||||
$console.warn(`[Safe Mutate] reverted "${name}":`);
|
||||
|
||||
// make sure to throw the error
|
||||
throw e;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { auth, permission } from "auth/middlewares";
|
||||
@@ -1,7 +1,6 @@
|
||||
import { _jsonp, transformObject } from "core/utils";
|
||||
import { type Kysely, sql } from "kysely";
|
||||
import { transformObject } from "core/utils";
|
||||
import type { Kysely } from "kysely";
|
||||
import { set } from "lodash-es";
|
||||
import type { InitialModuleConfigs } from "modules/ModuleManager";
|
||||
|
||||
export type MigrationContext = {
|
||||
db: Kysely<any>;
|
||||
@@ -17,7 +16,6 @@ export type Migration = {
|
||||
export const migrations: Migration[] = [
|
||||
{
|
||||
version: 1,
|
||||
//schema: true,
|
||||
up: async (config) => config,
|
||||
},
|
||||
{
|
||||
@@ -28,7 +26,6 @@ export const migrations: Migration[] = [
|
||||
},
|
||||
{
|
||||
version: 3,
|
||||
//schema: true,
|
||||
up: async (config) => config,
|
||||
},
|
||||
{
|
||||
@@ -46,7 +43,6 @@ export const migrations: Migration[] = [
|
||||
{
|
||||
version: 5,
|
||||
up: async (config, { db }) => {
|
||||
//console.log("config", _jsonp(config));
|
||||
const cors = config.server.cors?.allow_methods ?? [];
|
||||
set(config.server, "cors.allow_methods", [...new Set([...cors, "PATCH"])]);
|
||||
return config;
|
||||
@@ -114,15 +110,12 @@ export async function migrateTo(
|
||||
config: GenericConfigObject,
|
||||
ctx: MigrationContext,
|
||||
): Promise<[number, GenericConfigObject]> {
|
||||
//console.log("migrating from", current, "to", CURRENT_VERSION, config);
|
||||
const todo = migrations.filter((m) => m.version > current && m.version <= to);
|
||||
//console.log("todo", todo.length);
|
||||
let updated = Object.assign({}, config);
|
||||
|
||||
let i = 0;
|
||||
let version = current;
|
||||
for (const migration of todo) {
|
||||
//console.log("-- running migration", i + 1, "of", todo.length, { version: migration.version });
|
||||
try {
|
||||
updated = await migration.up(updated, ctx);
|
||||
version = migration.version;
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
/** @jsxImportSource hono/jsx */
|
||||
|
||||
import type { App } from "App";
|
||||
import { config, isDebug } from "core";
|
||||
import { $console, config, isDebug } from "core";
|
||||
import { addFlashMessage } from "core/server/flash";
|
||||
import { html } from "hono/html";
|
||||
import { Fragment } from "hono/jsx";
|
||||
import { css, Style } from "hono/css";
|
||||
import { Controller } from "modules/Controller";
|
||||
import * as SystemPermissions from "modules/permissions";
|
||||
import type { TApiUser } from "Api";
|
||||
|
||||
const htmlBkndContextReplace = "<!-- BKND_CONTEXT -->";
|
||||
|
||||
export type AdminBkndWindowContext = {
|
||||
user?: TApiUser;
|
||||
logout_route: string;
|
||||
admin_basepath: string;
|
||||
};
|
||||
|
||||
// @todo: add migration to remove admin path from config
|
||||
export type AdminControllerOptions = {
|
||||
basepath?: string;
|
||||
@@ -80,6 +87,7 @@ export class AdminController extends Controller {
|
||||
const obj = {
|
||||
user: c.get("auth")?.user,
|
||||
logout_route: this.withAdminBasePath(authRoutes.logout),
|
||||
admin_basepath: this.options.adminBasepath,
|
||||
};
|
||||
const html = await this.getHtml(obj);
|
||||
if (!html) {
|
||||
@@ -99,7 +107,7 @@ export class AdminController extends Controller {
|
||||
onGranted: async (c) => {
|
||||
// @todo: add strict test to permissions middleware?
|
||||
if (c.get("auth")?.user) {
|
||||
console.log("redirecting to success");
|
||||
$console.log("redirecting to success");
|
||||
return c.redirect(authRoutes.success);
|
||||
}
|
||||
},
|
||||
@@ -125,7 +133,7 @@ export class AdminController extends Controller {
|
||||
onDenied: async (c) => {
|
||||
addFlashMessage(c, "You are not authorized to access the Admin UI", "error");
|
||||
|
||||
console.log("redirecting");
|
||||
$console.log("redirecting");
|
||||
return c.redirect(authRoutes.login);
|
||||
},
|
||||
}),
|
||||
@@ -142,7 +150,7 @@ export class AdminController extends Controller {
|
||||
return hono;
|
||||
}
|
||||
|
||||
private async getHtml(obj: any = {}) {
|
||||
private async getHtml(obj: AdminBkndWindowContext) {
|
||||
const bknd_context = `window.__BKND__ = JSON.parse('${JSON.stringify(obj)}');`;
|
||||
|
||||
if (this.options.html) {
|
||||
@@ -153,7 +161,7 @@ export class AdminController extends Controller {
|
||||
);
|
||||
}
|
||||
|
||||
console.warn(
|
||||
$console.warn(
|
||||
`Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context`,
|
||||
);
|
||||
return this.options.html as string;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Exception, isDebug } from "core";
|
||||
import { type Static, StringEnum, Type } from "core/utils";
|
||||
import { Exception, isDebug, $console } from "core";
|
||||
import { type Static, StringEnum } from "core/utils";
|
||||
import { cors } from "hono/cors";
|
||||
import { Module } from "modules/Module";
|
||||
import * as tbbox from "@sinclair/typebox";
|
||||
import { AuthException } from "auth/errors";
|
||||
const { Type } = tbbox;
|
||||
|
||||
const serverMethods = ["GET", "POST", "PATCH", "PUT", "DELETE"];
|
||||
|
||||
@@ -29,8 +32,6 @@ export const serverConfigSchema = Type.Object(
|
||||
export type AppServerConfig = Static<typeof serverConfigSchema>;
|
||||
|
||||
export class AppServer extends Module<typeof serverConfigSchema> {
|
||||
//private admin_html?: string;
|
||||
|
||||
override getRestrictedPaths() {
|
||||
return [];
|
||||
}
|
||||
@@ -70,14 +71,17 @@ export class AppServer extends Module<typeof serverConfigSchema> {
|
||||
|
||||
this.client.onError((err, c) => {
|
||||
//throw err;
|
||||
console.error(err);
|
||||
$console.error("[AppServer:onError]", err);
|
||||
|
||||
if (err instanceof Response) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (err instanceof AuthException) {
|
||||
return c.json(err.toJSON(), err.getSafeErrorAndCode().code);
|
||||
}
|
||||
|
||||
if (err instanceof Exception) {
|
||||
console.log("---is exception", err.code);
|
||||
return c.json(err.toJSON(), err.code as any);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import type { App } from "App";
|
||||
import { $console, tbValidator as tb } from "core";
|
||||
import {
|
||||
StringEnum,
|
||||
Type,
|
||||
TypeInvalidError,
|
||||
datetimeStringLocal,
|
||||
datetimeStringUTC,
|
||||
@@ -14,6 +13,8 @@ import {
|
||||
import { getRuntimeKey } from "core/utils";
|
||||
import type { Context, Hono } from "hono";
|
||||
import { Controller } from "modules/Controller";
|
||||
import * as tbbox from "@sinclair/typebox";
|
||||
const { Type } = tbbox;
|
||||
|
||||
import {
|
||||
MODULE_NAMES,
|
||||
@@ -99,7 +100,7 @@ export class SystemController extends Controller {
|
||||
try {
|
||||
return c.json(await cb(), { status: 202 });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
$console.error("config update error", e);
|
||||
|
||||
if (e instanceof TypeInvalidError) {
|
||||
return c.json(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Type } from "core/utils";
|
||||
import type { ModuleConfigs } from "modules/ModuleManager";
|
||||
import type { OpenAPIV3 as OAS } from "openapi-types";
|
||||
import * as tbbox from "@sinclair/typebox";
|
||||
const { Type } = tbbox;
|
||||
|
||||
function prefixPaths(paths: OAS.PathsObject, prefix: string): OAS.PathsObject {
|
||||
const result: OAS.PathsObject = {};
|
||||
|
||||
Reference in New Issue
Block a user