@getworkbench/core 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +164 -4
- package/dist/index.js +641 -296
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Hono } from 'hono';
|
|
2
1
|
import { Queue, RedisOptions } from 'bullmq';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Job status types matching BullMQ states
|
|
@@ -651,15 +651,175 @@ declare class WorkbenchCore {
|
|
|
651
651
|
};
|
|
652
652
|
}
|
|
653
653
|
|
|
654
|
+
interface FetchHandlerResult {
|
|
655
|
+
/**
|
|
656
|
+
* Web-standard fetch handler. Accepts a `Request` and returns a `Response`.
|
|
657
|
+
* Suitable for Elysia's `.mount(path, handler)`, Next.js route handlers,
|
|
658
|
+
* Bun.serve, and any other web-standards-friendly runtime.
|
|
659
|
+
*/
|
|
660
|
+
fetch: (req: Request) => Promise<Response>;
|
|
661
|
+
/**
|
|
662
|
+
* The underlying `WorkbenchCore` instance. Exposed so adapters can read
|
|
663
|
+
* config, query state, or wire up custom auth strategies.
|
|
664
|
+
*/
|
|
665
|
+
core: WorkbenchCore;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Build a self-contained web-fetch handler for Workbench: API routes,
|
|
669
|
+
* `/config`, static `/assets/:file`, an `index.html` catch-all with a
|
|
670
|
+
* correct `<base href>`, CORS on `/api/*`, and optional Basic Auth on
|
|
671
|
+
* everything.
|
|
672
|
+
*
|
|
673
|
+
* This is the engine shared by every fetch-native adapter (Elysia, Next.js).
|
|
674
|
+
* Express and Fastify adapters use {@link buildRouteTable} directly instead.
|
|
675
|
+
*
|
|
676
|
+
* When `options.basePath` is set, the handler rewrites the incoming Request
|
|
677
|
+
* URL to strip that prefix before routing. This makes the bridge work
|
|
678
|
+
* uniformly for both fetch hosts:
|
|
679
|
+
*
|
|
680
|
+
* - `Elysia.mount()` already strips the prefix before calling us — the
|
|
681
|
+
* strip below is a no-op in that case.
|
|
682
|
+
* - Next.js App Router preserves the full path — the strip is what lets
|
|
683
|
+
* our internal routes (`/api/*`, `/config`, …) match.
|
|
684
|
+
*/
|
|
685
|
+
declare function createFetchHandler(options: WorkbenchOptions | Queue[]): FetchHandlerResult;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Framework-agnostic HTTP method.
|
|
689
|
+
*/
|
|
690
|
+
type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
654
691
|
/**
|
|
655
|
-
*
|
|
692
|
+
* Normalized input passed to every handler. Adapters are responsible for
|
|
693
|
+
* mapping their framework-specific request shape to this.
|
|
694
|
+
*/
|
|
695
|
+
interface HandlerInput {
|
|
696
|
+
params: Record<string, string>;
|
|
697
|
+
query: Record<string, string | undefined>;
|
|
698
|
+
body?: unknown;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Normalized output returned by every handler. Adapters serialize this
|
|
702
|
+
* onto their framework-specific response object.
|
|
703
|
+
*/
|
|
704
|
+
interface HandlerResult {
|
|
705
|
+
status: number;
|
|
706
|
+
body: unknown;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* A framework-agnostic route handler. Closes over a `WorkbenchCore` and
|
|
710
|
+
* takes a normalized request envelope.
|
|
711
|
+
*/
|
|
712
|
+
type Handler = (input: HandlerInput) => Promise<HandlerResult>;
|
|
713
|
+
/**
|
|
714
|
+
* A framework-agnostic route definition.
|
|
715
|
+
*
|
|
716
|
+
* `path` uses `:param` syntax compatible with Hono, Express, and Fastify.
|
|
717
|
+
* Paths are relative to `/api` — adapters mount them under that prefix.
|
|
718
|
+
*/
|
|
719
|
+
interface RouteDef {
|
|
720
|
+
method: HttpMethod;
|
|
721
|
+
path: string;
|
|
722
|
+
handler: Handler;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Build the framework-agnostic route table for the Workbench API.
|
|
726
|
+
*
|
|
727
|
+
* Adapters iterate this list and register each route on their host framework.
|
|
728
|
+
* Paths are relative to `/api`.
|
|
729
|
+
*/
|
|
730
|
+
declare function buildRouteTable(core: WorkbenchCore): RouteDef[];
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Create API routes for Workbench as a Hono app.
|
|
734
|
+
*
|
|
735
|
+
* Iterates the framework-agnostic `buildRouteTable(core)` and registers
|
|
736
|
+
* each route on a fresh Hono instance. Adapters that don't speak Hono can
|
|
737
|
+
* use `buildRouteTable` directly — see `@getworkbench/express` and
|
|
738
|
+
* `@getworkbench/fastify`.
|
|
656
739
|
*/
|
|
657
740
|
declare function createApiRoutes(core: WorkbenchCore): Hono;
|
|
658
741
|
|
|
742
|
+
declare function computeBasePath(pathname: string): string;
|
|
743
|
+
/**
|
|
744
|
+
* Resolve the dashboard's base path, preferring an explicit override.
|
|
745
|
+
*
|
|
746
|
+
* Adapters where the host framework preserves the mount prefix on the
|
|
747
|
+
* incoming URL (Hono `.route()`, Express `req.originalUrl`, Next.js route
|
|
748
|
+
* files) can rely on auto-detection. Adapters where the prefix is stripped
|
|
749
|
+
* before the handler runs (Elysia `.mount()`) require the user to pass
|
|
750
|
+
* `basePath` so the dashboard's HTML still references assets under the
|
|
751
|
+
* correct prefix.
|
|
752
|
+
*/
|
|
753
|
+
declare function resolveBasePath(override: string | undefined, pathname: string): string;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Parse a `Basic` Authorization header and check it against the configured
|
|
757
|
+
* credentials. Uses constant-time comparison to avoid leaking timing info
|
|
758
|
+
* about which character mismatched.
|
|
759
|
+
*
|
|
760
|
+
* Returns `true` when credentials are valid, `false` otherwise. Both inputs
|
|
761
|
+
* being undefined or empty count as a failed check — adapters should only
|
|
762
|
+
* call this when `core.requiresAuth()` is true.
|
|
763
|
+
*/
|
|
764
|
+
declare function checkBasicAuth(authHeader: string | undefined, username: string, password: string): boolean;
|
|
765
|
+
/**
|
|
766
|
+
* Standard 401 response body + header for an unauthenticated Basic auth
|
|
767
|
+
* request. Adapters use this when `checkBasicAuth` returns false.
|
|
768
|
+
*/
|
|
769
|
+
declare const BASIC_AUTH_CHALLENGE: {
|
|
770
|
+
status: 401;
|
|
771
|
+
headers: {
|
|
772
|
+
"WWW-Authenticate": string;
|
|
773
|
+
};
|
|
774
|
+
body: string;
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Build a fully-wired Hono app for Workbench:
|
|
779
|
+
*
|
|
780
|
+
* - `POST /api/*`, `GET /api/*` etc. — JSON API
|
|
781
|
+
* - `GET /config` — UI bootstrap config
|
|
782
|
+
* - `GET /assets/:file` — static asset reader
|
|
783
|
+
* - `GET *` — `index.html` with `<base href>`
|
|
784
|
+
* - CORS on `/api/*`
|
|
785
|
+
* - Basic auth on everything when `core.requiresAuth()` is true
|
|
786
|
+
*
|
|
787
|
+
* Used directly by `@getworkbench/hono` (returned as-is for `.route()`
|
|
788
|
+
* mounting) and indirectly by `createFetchHandler` for non-Hono adapters.
|
|
789
|
+
*/
|
|
790
|
+
declare function buildWorkbenchApp(core: WorkbenchCore): Hono;
|
|
791
|
+
|
|
792
|
+
interface StaticAssetResult {
|
|
793
|
+
status: 200 | 404;
|
|
794
|
+
body: Buffer | null;
|
|
795
|
+
contentType: string;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Read a bundled UI asset from `UI_DIST_PATH/assets/<filename>`.
|
|
799
|
+
*
|
|
800
|
+
* Returns a uniform `{ status, body, contentType }` shape so each adapter
|
|
801
|
+
* can serialize it onto its framework-native response without re-implementing
|
|
802
|
+
* the file lookup or content-type sniffing.
|
|
803
|
+
*/
|
|
804
|
+
declare function serveStaticAsset(filename: string): StaticAssetResult;
|
|
805
|
+
interface IndexHtmlResult {
|
|
806
|
+
body: string;
|
|
807
|
+
contentType: "text/html; charset=utf-8";
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Read the bundled `index.html`, inject a `<base href>` matching the request's
|
|
811
|
+
* mount path so client-side asset URLs resolve correctly, and return it.
|
|
812
|
+
*
|
|
813
|
+
* Falls back to a tiny "UI assets not found" stub when the core package has
|
|
814
|
+
* not been built yet — useful for `bun run dev` against a fresh checkout.
|
|
815
|
+
*/
|
|
816
|
+
declare function renderIndexHtml(basePath: string, title: string): IndexHtmlResult;
|
|
817
|
+
|
|
659
818
|
/**
|
|
660
819
|
* Absolute filesystem path to the bundled UI assets (index.html + /assets).
|
|
661
|
-
* Adapters
|
|
820
|
+
* Adapters that don't go through {@link createFetchHandler} serve static
|
|
821
|
+
* files from this directory directly.
|
|
662
822
|
*/
|
|
663
823
|
declare const UI_DIST_PATH: string;
|
|
664
824
|
|
|
665
|
-
export { type ActivityBucket, type ActivityStatsResponse, type CreateFlowChildRequest, type CreateFlowRequest, type DelayedJobInfo, type DelayedSortField, type FailingJobType, type FlowNode, type FlowSummary, type HourlyBucket, type JobInfo, type JobStatus, type JobTags, type MetricsResponse, type OverviewStats, type PaginatedResponse, type QueueInfo, QueueManager, type QueueMetrics, type RepeatableSortField, type RunInfo, type RunInfoList, type RunSortField, type SchedulerInfo, type SearchResult, type SlowestJob, type SortDirection, type SortOptions, type TestJobRequest, UI_DIST_PATH, WorkbenchCore, type WorkbenchOptions, type WorkerInfo, createApiRoutes };
|
|
825
|
+
export { type ActivityBucket, type ActivityStatsResponse, BASIC_AUTH_CHALLENGE, type CreateFlowChildRequest, type CreateFlowRequest, type DelayedJobInfo, type DelayedSortField, type FailingJobType, type FetchHandlerResult, type FlowNode, type FlowSummary, type Handler, type HandlerInput, type HandlerResult, type HourlyBucket, type HttpMethod, type IndexHtmlResult, type JobInfo, type JobStatus, type JobTags, type MetricsResponse, type OverviewStats, type PaginatedResponse, type QueueInfo, QueueManager, type QueueMetrics, type RepeatableSortField, type RouteDef, type RunInfo, type RunInfoList, type RunSortField, type SchedulerInfo, type SearchResult, type SlowestJob, type SortDirection, type SortOptions, type StaticAssetResult, type TestJobRequest, UI_DIST_PATH, WorkbenchCore, type WorkbenchOptions, type WorkerInfo, buildRouteTable, buildWorkbenchApp, checkBasicAuth, computeBasePath, createApiRoutes, createFetchHandler, renderIndexHtml, resolveBasePath, serveStaticAsset };
|