@kahitsan/plugin-sdk 0.4.2 → 0.4.3-staging.25
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 +52 -41
- package/dist/index.js +1 -1
- package/dist/test.d.ts +32 -0
- package/dist/test.js +121 -0
- package/package.json +8 -4
- package/src/dev/dev-host.ts +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Router } from 'express';
|
|
1
|
+
import { MiddlewareHandler, Context, Hono } from 'hono';
|
|
3
2
|
import pg, { QueryResultRow, QueryResult, PoolClient, Pool } from 'pg';
|
|
4
3
|
import { Server } from 'node:http';
|
|
5
4
|
interface PluginDb {
|
|
@@ -96,11 +95,11 @@ type AuthProviderDecl = {
|
|
|
96
95
|
validatePath: string;
|
|
97
96
|
};
|
|
98
97
|
type AuthService = {
|
|
99
|
-
requireAuth:
|
|
100
|
-
requireWorkspace:
|
|
101
|
-
requireRole: (...roles: string[]) =>
|
|
102
|
-
requireWorkspaceRole: (...roles: string[]) =>
|
|
103
|
-
requirePermission: (...codes: string[]) =>
|
|
98
|
+
requireAuth: MiddlewareHandler;
|
|
99
|
+
requireWorkspace: MiddlewareHandler;
|
|
100
|
+
requireRole: (...roles: string[]) => MiddlewareHandler;
|
|
101
|
+
requireWorkspaceRole: (...roles: string[]) => MiddlewareHandler;
|
|
102
|
+
requirePermission: (...codes: string[]) => MiddlewareHandler;
|
|
104
103
|
registerAuthProvider: (provider: AuthProvider) => void;
|
|
105
104
|
};
|
|
106
105
|
type PluginManifest = {
|
|
@@ -188,10 +187,10 @@ type PluginInitInput = {
|
|
|
188
187
|
};
|
|
189
188
|
type AdditionalMount = {
|
|
190
189
|
basePath: string;
|
|
191
|
-
router:
|
|
190
|
+
router: unknown;
|
|
192
191
|
};
|
|
193
192
|
type PluginInitOutput = {
|
|
194
|
-
router?:
|
|
193
|
+
router?: unknown;
|
|
195
194
|
additionalMounts?: AdditionalMount[];
|
|
196
195
|
dispose?: () => Promise<void> | void;
|
|
197
196
|
};
|
|
@@ -231,10 +230,10 @@ interface JobDefinition {
|
|
|
231
230
|
run: (ctx: JobContext) => Promise<void> | void;
|
|
232
231
|
}
|
|
233
232
|
declare function defineJob(name: string, run: (ctx: JobContext) => Promise<void> | void): JobDefinition;
|
|
234
|
-
declare function requirePermission(...codes: string[]):
|
|
235
|
-
declare
|
|
236
|
-
declare
|
|
237
|
-
declare
|
|
233
|
+
declare function requirePermission(...codes: string[]): MiddlewareHandler;
|
|
234
|
+
declare const requireAuth: MiddlewareHandler;
|
|
235
|
+
declare const requireWorkspace: MiddlewareHandler;
|
|
236
|
+
declare const parseIdentity: MiddlewareHandler;
|
|
238
237
|
declare const IDENTITY_HEADER = "x-kserp-identity";
|
|
239
238
|
declare const INTERNAL_SECRET_HEADER = "x-kserp-internal";
|
|
240
239
|
declare const PROTOCOL_VERSION = 1;
|
|
@@ -268,7 +267,13 @@ declare const IdentityBrand: unique symbol;
|
|
|
268
267
|
type Identity = ForwardedIdentity & {
|
|
269
268
|
readonly [IdentityBrand]: true;
|
|
270
269
|
};
|
|
271
|
-
declare function readIdentity(req: Request
|
|
270
|
+
declare function readIdentity(req: Request | {
|
|
271
|
+
req: {
|
|
272
|
+
raw: Request;
|
|
273
|
+
};
|
|
274
|
+
} | {
|
|
275
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
276
|
+
}): Identity | null;
|
|
272
277
|
interface WhereOpts {
|
|
273
278
|
where?: string;
|
|
274
279
|
params?: readonly unknown[];
|
|
@@ -310,7 +315,7 @@ interface TenantContext {
|
|
|
310
315
|
}
|
|
311
316
|
declare function runWithTenantContext<T>(ctx: TenantContext, fn: () => T): T;
|
|
312
317
|
declare function applyTenantContext(client: PoolClient, ctx?: TenantContext | undefined): Promise<void>;
|
|
313
|
-
declare
|
|
318
|
+
declare const withTenantContext: MiddlewareHandler;
|
|
314
319
|
type Engine = "postgres" | "sqlite";
|
|
315
320
|
type ColumnKind = "id" | "string" | "text" | "int" | "bigint" | "float" | "decimal" | "boolean" | "timestamp" | "date" | "json" | "enum";
|
|
316
321
|
type ColumnDefault = "now" | string | number | boolean | null;
|
|
@@ -405,9 +410,9 @@ interface MigrationOpts {
|
|
|
405
410
|
useTransaction?: boolean;
|
|
406
411
|
}
|
|
407
412
|
declare function migration(name: string, up: (db: MigrationBuilder) => Promise<void>, opts?: MigrationOpts): Migration;
|
|
408
|
-
declare function asyncHandler(fn: (
|
|
413
|
+
declare function asyncHandler(fn: (c: Context) => unknown | Promise<unknown>): MiddlewareHandler;
|
|
409
414
|
declare function escapeLike(s: string): string;
|
|
410
|
-
declare function checkProtocol(min?: number, max?: number):
|
|
415
|
+
declare function checkProtocol(min?: number, max?: number): MiddlewareHandler;
|
|
411
416
|
type ResourceColumns = Readonly<Record<string, ColumnDef>>;
|
|
412
417
|
type IndexMember = string | {
|
|
413
418
|
readonly ci: string;
|
|
@@ -555,13 +560,13 @@ declare function resourceMigrations(resource: DefinedResource): Migration[];
|
|
|
555
560
|
type DbHandle = Parameters<typeof makeDataSurface>[0];
|
|
556
561
|
interface ResourceRouterDeps {
|
|
557
562
|
db: DbHandle;
|
|
558
|
-
requireAuth:
|
|
559
|
-
requireWorkspace:
|
|
560
|
-
requirePermission?: (...codes: string[]) =>
|
|
563
|
+
requireAuth: MiddlewareHandler;
|
|
564
|
+
requireWorkspace: MiddlewareHandler;
|
|
565
|
+
requirePermission?: (...codes: string[]) => MiddlewareHandler;
|
|
561
566
|
}
|
|
562
|
-
declare function buildResourceRouter(resource: DefinedResource, deps: ResourceRouterDeps):
|
|
567
|
+
declare function buildResourceRouter(resource: DefinedResource, deps: ResourceRouterDeps): Hono;
|
|
563
568
|
type ServiceHandler$1 = (args: unknown, ctx: {
|
|
564
|
-
req:
|
|
569
|
+
req: unknown;
|
|
565
570
|
}) => Promise<Array<Record<string, unknown>>>;
|
|
566
571
|
declare function buildResourceServices(resource: DefinedResource, deps: {
|
|
567
572
|
db: DbHandle;
|
|
@@ -578,13 +583,27 @@ declare function tryCallPlugin<T = unknown>(target: string, method: string, args
|
|
|
578
583
|
identityHeader?: string;
|
|
579
584
|
sourcePlugin?: string;
|
|
580
585
|
}): Promise<T | null>;
|
|
581
|
-
declare function identityHeaderOf(req: Request
|
|
586
|
+
declare function identityHeaderOf(req: Request | Context | {
|
|
587
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
588
|
+
}): string | undefined;
|
|
582
589
|
type ServiceHandler = (args: unknown, ctx: {
|
|
583
|
-
req:
|
|
590
|
+
req: unknown;
|
|
584
591
|
}) => Promise<unknown> | unknown;
|
|
585
|
-
declare function mountPluginServices(app:
|
|
586
|
-
parseIdentity:
|
|
592
|
+
declare function mountPluginServices(app: Hono, handlers: Record<string, ServiceHandler>, opts: {
|
|
593
|
+
parseIdentity: MiddlewareHandler;
|
|
587
594
|
}): void;
|
|
595
|
+
declare function s3Enabled(): boolean;
|
|
596
|
+
declare function s3PublicUrl(key: string): string;
|
|
597
|
+
declare function s3KeyFromUrl(s3Link: string | null | undefined): string | null;
|
|
598
|
+
declare function s3PutObject(key: string, body: Buffer, contentType: string, opts?: {
|
|
599
|
+
acl?: "public-read" | "private";
|
|
600
|
+
}): Promise<void>;
|
|
601
|
+
declare function s3GetObject(key: string): Promise<{
|
|
602
|
+
body: Buffer;
|
|
603
|
+
contentType: string | null;
|
|
604
|
+
}>;
|
|
605
|
+
declare function s3DeleteObject(key: string): Promise<void>;
|
|
606
|
+
declare function s3PresignUrl(key: string, expirySeconds?: number): string;
|
|
588
607
|
interface PluginSettings {
|
|
589
608
|
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
590
609
|
all(): Promise<Record<string, unknown>>;
|
|
@@ -664,7 +683,7 @@ interface PluginServerContext {
|
|
|
664
683
|
plugins?: PluginRpc;
|
|
665
684
|
events?: PluginEvents;
|
|
666
685
|
}
|
|
667
|
-
type PluginRouterFactory = (ctx: PluginServerContext) =>
|
|
686
|
+
type PluginRouterFactory = (ctx: PluginServerContext) => Hono;
|
|
668
687
|
type PluginServicesFactory = (ctx: PluginServerContext) => Record<string, ServiceHandler>;
|
|
669
688
|
interface CreatePluginServerOptions {
|
|
670
689
|
importMetaUrl: string;
|
|
@@ -678,30 +697,22 @@ interface CreatePluginServerOptions {
|
|
|
678
697
|
events?: boolean;
|
|
679
698
|
services?: PluginServicesFactory;
|
|
680
699
|
routers?: PluginRouterFactory[];
|
|
681
|
-
configure?: (app:
|
|
700
|
+
configure?: (app: Hono, ctx: PluginServerContext) => void | Promise<void>;
|
|
682
701
|
}
|
|
683
702
|
interface PluginServerHandle {
|
|
684
|
-
app:
|
|
703
|
+
app: Hono;
|
|
685
704
|
server: Server;
|
|
686
705
|
ctx?: PluginServerContext;
|
|
687
706
|
}
|
|
688
707
|
declare function createPluginServer(opts: CreatePluginServerOptions): Promise<PluginServerHandle>;
|
|
689
|
-
interface WsSocket {
|
|
690
|
-
on(event: "message", cb: (data: {
|
|
691
|
-
toString(): string;
|
|
692
|
-
}) => void): void;
|
|
693
|
-
send(data: string): void;
|
|
694
|
-
}
|
|
695
|
-
interface WsServer {
|
|
696
|
-
on(event: "connection", cb: (socket: WsSocket) => void): void;
|
|
697
|
-
close(): void;
|
|
698
|
-
}
|
|
699
708
|
interface WsReceiverOptions {
|
|
700
709
|
httpPort: number;
|
|
701
710
|
secret: string;
|
|
702
711
|
host?: string;
|
|
703
712
|
}
|
|
704
|
-
declare function mountWsReceiver(opts: WsReceiverOptions):
|
|
713
|
+
declare function mountWsReceiver(opts: WsReceiverOptions): {
|
|
714
|
+
stop: () => void;
|
|
715
|
+
} | null;
|
|
705
716
|
type FlowNodeKind = "data" | "trigger" | "modal" | "load" | "call" | "compute" | "condition" | "commit" | "emit" | "effect" | "terminal";
|
|
706
717
|
interface FlowPort {
|
|
707
718
|
id: string;
|
|
@@ -781,5 +792,5 @@ type ExecFlow = Omit<FlowDefinition, "nodes"> & {
|
|
|
781
792
|
nodes: ExecNode[];
|
|
782
793
|
};
|
|
783
794
|
declare function runFlow(flow: ExecFlow, startId: string, ctx: FlowContext): Promise<void>;
|
|
784
|
-
export { FlowSteps, IDENTITY_HEADER, INTERNAL_SECRET_HEADER, MIGRATION_ADVISORY_LOCK_KEY, MigrationBuilder, PROTOCOL_VERSION, PluginUnavailableError, Types, applyTenantContext, asyncHandler, buildFlow, buildResourceRouter, buildResourceServices, callPlugin, checkInternalSecret, checkProtocol, compileCreateTable, composeWhere, createPlugin, createPluginServer, defineFlow, defineJob, defineResource, defineSchema, edge, escapeLike, identityHeaderOf, indexExpr, loadMigrations, makeDataSurface, makeDatabaseService, migration, mountPluginServices, mountWsReceiver, node, parseIdentity, quoteIdent, readIdentity, requireAuth, requirePermission, requireWorkspace, resolveEngine, resourceMigrations, rollbackMigration, runFlow, runMigrationList, runMigrations, runWithTenantContext, searchFragment, statusFilter, tenant, tryCallPlugin, verifyIdentity, withTenantContext };
|
|
795
|
+
export { FlowSteps, IDENTITY_HEADER, INTERNAL_SECRET_HEADER, MIGRATION_ADVISORY_LOCK_KEY, MigrationBuilder, PROTOCOL_VERSION, PluginUnavailableError, Types, applyTenantContext, asyncHandler, buildFlow, buildResourceRouter, buildResourceServices, callPlugin, checkInternalSecret, checkProtocol, compileCreateTable, composeWhere, createPlugin, createPluginServer, defineFlow, defineJob, defineResource, defineSchema, edge, escapeLike, identityHeaderOf, indexExpr, loadMigrations, makeDataSurface, makeDatabaseService, migration, mountPluginServices, mountWsReceiver, node, parseIdentity, quoteIdent, readIdentity, requireAuth, requirePermission, requireWorkspace, resolveEngine, resourceMigrations, rollbackMigration, runFlow, runMigrationList, runMigrations, runWithTenantContext, s3DeleteObject, s3Enabled, s3GetObject, s3KeyFromUrl, s3PresignUrl, s3PublicUrl, s3PutObject, searchFragment, statusFilter, tenant, tryCallPlugin, verifyIdentity, withTenantContext };
|
|
785
796
|
export type { AdditionalMount, AuthProvider, AuthProviderDecl, AuthService, AuthenticatedUser, BackfillOpts, ColumnDef, ColumnDefault, ColumnKind, ColumnOpts, CompileTableOpts, CoreServices, CreatePluginServerOptions, DataSurface, DecimalOpts, DefinedResource, Engine, EscapeHatch, ExecFlow, ExecNode, FindOpts, FlowContext, FlowDefinition, FlowNode, FlowNodeDef, FlowNodeKind, FlowPort, ForwardedIdentity, Identity, IndexMember, IndexOpts, Logger, MemberDTO, Migration, MigrationContext, MigrationOpts, NodeExec, PermissionsService, PluginAsset, PluginAssets, PluginContext, PluginDb, PluginDefinition, PluginEvents, PluginInitInput, PluginInitOutput, PluginKernel, PluginManifest, PluginPeer, PluginRouterFactory, PluginRpc, PluginServerContext, PluginServerHandle, PluginServicesFactory, PluginSettings, PresignedAsset, ResourceColumns, ResourceCreateSpec, ResourceField, ResourceFields, ResourceFilter, ResourceIndex, ResourceListSpec, ResourcePagination, ResourceRouterDeps, ResourceSearch, ResourceService, ResourceSoftDelete, ResourceSort, ResourceSpec, ResourceUpdateSpec, RunMigrationsOptions, SchemaDef, SqlFragment, StringOpts, TableDef, TenantContext, TenantDb, WhereOpts, WorkspaceDTO, WsReceiverOptions };
|