@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 CHANGED
@@ -1,5 +1,4 @@
1
- import { Router, Request, RequestHandler, Response as Response$1, NextFunction, Express } from 'express';
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: RequestHandler;
100
- requireWorkspace: RequestHandler;
101
- requireRole: (...roles: string[]) => RequestHandler;
102
- requireWorkspaceRole: (...roles: string[]) => RequestHandler;
103
- requirePermission: (...codes: string[]) => RequestHandler;
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: Router;
190
+ router: unknown;
192
191
  };
193
192
  type PluginInitOutput = {
194
- router?: 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[]): (req: Request, res: Response$1, next: NextFunction) => void;
235
- declare function requireAuth(req: Request, res: Response$1, next: NextFunction): void;
236
- declare function requireWorkspace(req: Request, res: Response$1, next: NextFunction): void;
237
- declare function parseIdentity(req: Request, _res: Response$1, next: NextFunction): void;
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): Identity | null;
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 function withTenantContext(req: Request, _res: Response$1, next: NextFunction): void;
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: (req: Request, res: Response$1, next: NextFunction) => unknown | Promise<unknown>): RequestHandler;
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): (req: Request, res: Response$1, next: NextFunction) => void;
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: RequestHandler;
559
- requireWorkspace: RequestHandler;
560
- requirePermission?: (...codes: string[]) => RequestHandler;
563
+ requireAuth: MiddlewareHandler;
564
+ requireWorkspace: MiddlewareHandler;
565
+ requirePermission?: (...codes: string[]) => MiddlewareHandler;
561
566
  }
562
- declare function buildResourceRouter(resource: DefinedResource, deps: ResourceRouterDeps): Router;
567
+ declare function buildResourceRouter(resource: DefinedResource, deps: ResourceRouterDeps): Hono;
563
568
  type ServiceHandler$1 = (args: unknown, ctx: {
564
- req: Request;
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): string | undefined;
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: Request;
590
+ req: unknown;
584
591
  }) => Promise<unknown> | unknown;
585
- declare function mountPluginServices(app: Express, handlers: Record<string, ServiceHandler>, opts: {
586
- parseIdentity: RequestHandler;
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) => Router;
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: Express, ctx: PluginServerContext) => void | Promise<void>;
688
+ configure?: (app: Hono, ctx: PluginServerContext) => void | Promise<void>;
682
689
  }
683
690
  interface PluginServerHandle {
684
- app: Express;
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): WsServer | null;
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;