@kahitsan/plugin-sdk 0.4.1 → 0.4.2-staging.21
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 +39 -40
- package/dist/index.js +1 -1
- package/package.json +4 -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,12 +583,14 @@ 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;
|
|
588
595
|
interface PluginSettings {
|
|
589
596
|
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
@@ -664,7 +671,7 @@ interface PluginServerContext {
|
|
|
664
671
|
plugins?: PluginRpc;
|
|
665
672
|
events?: PluginEvents;
|
|
666
673
|
}
|
|
667
|
-
type PluginRouterFactory = (ctx: PluginServerContext) =>
|
|
674
|
+
type PluginRouterFactory = (ctx: PluginServerContext) => Hono;
|
|
668
675
|
type PluginServicesFactory = (ctx: PluginServerContext) => Record<string, ServiceHandler>;
|
|
669
676
|
interface CreatePluginServerOptions {
|
|
670
677
|
importMetaUrl: string;
|
|
@@ -678,30 +685,22 @@ interface CreatePluginServerOptions {
|
|
|
678
685
|
events?: boolean;
|
|
679
686
|
services?: PluginServicesFactory;
|
|
680
687
|
routers?: PluginRouterFactory[];
|
|
681
|
-
configure?: (app:
|
|
688
|
+
configure?: (app: Hono, ctx: PluginServerContext) => void | Promise<void>;
|
|
682
689
|
}
|
|
683
690
|
interface PluginServerHandle {
|
|
684
|
-
app:
|
|
691
|
+
app: Hono;
|
|
685
692
|
server: Server;
|
|
686
693
|
ctx?: PluginServerContext;
|
|
687
694
|
}
|
|
688
695
|
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
696
|
interface WsReceiverOptions {
|
|
700
697
|
httpPort: number;
|
|
701
698
|
secret: string;
|
|
702
699
|
host?: string;
|
|
703
700
|
}
|
|
704
|
-
declare function mountWsReceiver(opts: WsReceiverOptions):
|
|
701
|
+
declare function mountWsReceiver(opts: WsReceiverOptions): {
|
|
702
|
+
stop: () => void;
|
|
703
|
+
} | null;
|
|
705
704
|
type FlowNodeKind = "data" | "trigger" | "modal" | "load" | "call" | "compute" | "condition" | "commit" | "emit" | "effect" | "terminal";
|
|
706
705
|
interface FlowPort {
|
|
707
706
|
id: string;
|