@kahitsan/plugin-sdk 0.4.0 → 0.4.2-staging.18

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.
Files changed (78) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +76 -0
  3. package/dist/index.d.ts +39 -40
  4. package/dist/index.js +1 -1
  5. package/package.json +30 -8
  6. package/shell/_build/.vite/manifest.json +59 -59
  7. package/shell/_build/.vite/manifest.json.br +0 -0
  8. package/shell/_build/.vite/manifest.json.gz +0 -0
  9. package/shell/_build/assets/{_...slug_-BNycC89F.js → _...slug_-BcdF4l5Z.js} +1 -1
  10. package/shell/_build/assets/_...slug_-BcdF4l5Z.js.br +0 -0
  11. package/shell/_build/assets/_...slug_-BcdF4l5Z.js.gz +0 -0
  12. package/shell/_build/assets/{api-keys-zDu0DTIi.js → api-keys-BNWgFkG0.js} +1 -1
  13. package/shell/_build/assets/{auth-CPW4mGTx.js → auth-DnjIzX2B.js} +5 -5
  14. package/shell/_build/assets/auth-DnjIzX2B.js.br +0 -0
  15. package/shell/_build/assets/auth-DnjIzX2B.js.gz +0 -0
  16. package/shell/_build/assets/client-BmadCoeU.css +1 -0
  17. package/shell/_build/assets/client-BmadCoeU.css.br +0 -0
  18. package/shell/_build/assets/client-BmadCoeU.css.gz +0 -0
  19. package/shell/_build/assets/client-StEn6jq1.js +2 -0
  20. package/shell/_build/assets/client-StEn6jq1.js.br +0 -0
  21. package/shell/_build/assets/client-StEn6jq1.js.gz +0 -0
  22. package/shell/_build/assets/{components-kMeatXhB.js → components-CWmQ2MDX.js} +1 -1
  23. package/shell/_build/assets/dashboard-pbkizuaa.js +1 -0
  24. package/shell/_build/assets/{index-dCQOOcel.js → index-CwObwzl5.js} +1 -1
  25. package/shell/_build/assets/login-pbkizuaa.js +1 -0
  26. package/shell/_build/assets/{members-CKVe_2mI.js → members-49i-57sG.js} +1 -1
  27. package/shell/_build/assets/plugin-ui-CBTroTyb.js +10 -0
  28. package/shell/_build/assets/plugin-ui-CBTroTyb.js.br +0 -0
  29. package/shell/_build/assets/plugin-ui-CBTroTyb.js.gz +0 -0
  30. package/shell/_build/assets/register-pbkizuaa.js +1 -0
  31. package/shell/_build/assets/routing-C6AwqsGL.js +1 -0
  32. package/shell/_build/assets/routing-C6AwqsGL.js.br +0 -0
  33. package/shell/_build/assets/routing-C6AwqsGL.js.gz +0 -0
  34. package/shell/_build/assets/settings-pbkizuaa.js +1 -0
  35. package/shell/_build/assets/users-pbkizuaa.js +1 -0
  36. package/shell/_build/assets/{workspace-nav-DsOJmRdY.js → workspace-nav-fkYL3-AV.js} +1 -1
  37. package/shell/_build/assets/workspace-nav-fkYL3-AV.js.br +0 -0
  38. package/shell/_build/assets/workspace-nav-fkYL3-AV.js.gz +0 -0
  39. package/shell/_build/assets/workspace-settings-pbkizuaa.js +1 -0
  40. package/shell/_build/assets/workspaces-pbkizuaa.js +1 -0
  41. package/shell/_server/assets/app-BmadCoeU.css +1 -0
  42. package/shell/_server/assets/app-BmadCoeU.css.br +0 -0
  43. package/shell/_server/assets/app-BmadCoeU.css.gz +0 -0
  44. package/shell/index.html +1 -1
  45. package/shell/index.html.br +0 -0
  46. package/shell/index.html.gz +0 -0
  47. package/shell/sw.js +2 -2
  48. package/shell/sw.js.br +0 -0
  49. package/shell/sw.js.gz +0 -0
  50. package/src/dev/dev-host.ts +3 -1
  51. package/shell/_build/assets/_...slug_-BNycC89F.js.br +0 -0
  52. package/shell/_build/assets/_...slug_-BNycC89F.js.gz +0 -0
  53. package/shell/_build/assets/auth-CPW4mGTx.js.br +0 -0
  54. package/shell/_build/assets/auth-CPW4mGTx.js.gz +0 -0
  55. package/shell/_build/assets/client-B0tH7z8C.css +0 -1
  56. package/shell/_build/assets/client-B0tH7z8C.css.br +0 -0
  57. package/shell/_build/assets/client-B0tH7z8C.css.gz +0 -0
  58. package/shell/_build/assets/client-BuqEzg-5.js +0 -2
  59. package/shell/_build/assets/client-BuqEzg-5.js.br +0 -0
  60. package/shell/_build/assets/client-BuqEzg-5.js.gz +0 -0
  61. package/shell/_build/assets/dashboard-BwMkrsX2.js +0 -1
  62. package/shell/_build/assets/login-BwMkrsX2.js +0 -1
  63. package/shell/_build/assets/plugin-ui-rgxz3UHD.js +0 -10
  64. package/shell/_build/assets/plugin-ui-rgxz3UHD.js.br +0 -0
  65. package/shell/_build/assets/plugin-ui-rgxz3UHD.js.gz +0 -0
  66. package/shell/_build/assets/register-BwMkrsX2.js +0 -1
  67. package/shell/_build/assets/routing-BlHUL5zP.js +0 -1
  68. package/shell/_build/assets/routing-BlHUL5zP.js.br +0 -0
  69. package/shell/_build/assets/routing-BlHUL5zP.js.gz +0 -0
  70. package/shell/_build/assets/settings-BwMkrsX2.js +0 -1
  71. package/shell/_build/assets/users-BwMkrsX2.js +0 -1
  72. package/shell/_build/assets/workspace-nav-DsOJmRdY.js.br +0 -0
  73. package/shell/_build/assets/workspace-nav-DsOJmRdY.js.gz +0 -0
  74. package/shell/_build/assets/workspace-settings-BwMkrsX2.js +0 -1
  75. package/shell/_build/assets/workspaces-BwMkrsX2.js +0 -1
  76. package/shell/_server/assets/app-B0tH7z8C.css +0 -1
  77. package/shell/_server/assets/app-B0tH7z8C.css.br +0 -0
  78. package/shell/_server/assets/app-B0tH7z8C.css.gz +0 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ @kahitsan/plugin-sdk — PROPRIETARY & CONFIDENTIAL
2
+ Copyright (c) KahitSan Corp. All rights reserved. Licensed, not sold.
3
+
4
+ This software is the property of KahitSan Corp. and is provided to authorized
5
+ licensees solely to build, run, and test plugins for the Hilinga ERP platform.
6
+
7
+ The published runtime (`dist/index.js`) is intentionally OBFUSCATED to protect
8
+ trade secrets. De-obfuscating, decompiling, reverse-engineering, beautifying, or
9
+ reconstructing its source is STRICTLY PROHIBITED by this license and by law,
10
+ including anti-circumvention statutes (e.g. 17 U.S.C. § 1201 / DMCA and
11
+ equivalents).
12
+
13
+ No part of this package may be copied, modified, redistributed, sublicensed, or
14
+ used to create a competing product without the prior written permission of
15
+ KahitSan Corp. (https://kahitsan.com).
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH
20
+ THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @kahitsan/plugin-sdk
2
+
3
+ The author surface + dev toolkit for building [Hilinga](https://www.hilinga.com) ERP plugins —
4
+ build, run, and test a plugin locally against a **kernel-identical dev shell**, with **no kernel
5
+ source required**.
6
+
7
+ Hilinga is a kernel (`kserp`) plus process-isolated plugins. Each plugin is its own repo with its
8
+ own API routes, UI bundle, Postgres schema, migrations, and pm2 process. This package is the single
9
+ public specifier a plugin author installs: it provides the server bootstrap, the workspace-scoped
10
+ data surface, auth/permission guards, the cross-plugin RPC + wire-protocol verify surface, and a Bun
11
+ dev toolkit that boots your plugin inside the real, kernel-identical app shell.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @kahitsan/plugin-sdk
17
+ ```
18
+
19
+ ## The dev toolkit
20
+
21
+ ```bash
22
+ npx @kahitsan/plugin-sdk <pluginDir> [<pluginDir> …]
23
+ ```
24
+
25
+ Boots a dev-kernel mediator + each plugin on [Bun](https://bun.sh) (local SQLite + a synthetic
26
+ logged-in admin) **entirely from the installed package** — no kernel checkout, no Postgres. It also
27
+ serves the prebuilt **kernel-identical host-UI shell** (sidebar, plugin route renderer, the settings
28
+ gear + modal — the real visual app), so you develop against what production actually renders.
29
+
30
+ Pass several plugin dirs to exercise the **contract between plugins** locally — does B expose the
31
+ method A consumes?
32
+
33
+ ```bash
34
+ npx @kahitsan/plugin-sdk ./kplugin_transactions ./kplugin_payees
35
+ ```
36
+
37
+ Requires [Bun](https://bun.sh). `Ctrl-C` stops every plugin.
38
+
39
+ ## The server surface — `createPluginServer`
40
+
41
+ `createPluginServer` is the one shared bootstrap. It collapses a plugin's hand-written
42
+ `server/main.ts` (manifest + port + pg pool + migrations + identity verify + RLS tenant context +
43
+ services + routers + listen) into a single call, and is the seam the Express → Bun + WS transport
44
+ cutover moves through. Opt-in capabilities (each gated by the kernel + consent model at runtime):
45
+
46
+ - `settings` — a plugin's private, workspace-scoped KV store (`ctx.settings`)
47
+ - `assets` — the kernel object store (`ctx.assets`)
48
+ - `kernel` — the kernel-data read channel (`ctx.kernel.workspace.get()`)
49
+ - `plugins` — the mediated inter-plugin call surface (`ctx.plugins.get(peer).call(...)`)
50
+ - `events` — emit a domain event the kernel fans out (`ctx.events.emit(topic, payload)`)
51
+ - `flows` — the §9 node-step flow authoring DSL (`buildFlow`, `defineFlow`), imported from
52
+ `@kahitsan/plugin-sdk/flow` (a browser-safe subpath with no Node built-ins, for plugin UI bundles)
53
+
54
+ The package **never** includes `signIdentity` (the identity-forging capability) or any shared
55
+ secret — that is the one genuine package-level boundary, enforced by the build's leak gate.
56
+
57
+ ## Authoring guide
58
+
59
+ The full new-plugin walkthrough lives in the Hilinga docs: **<https://kdocs.kahitsan.com>**
60
+ (`create-plugin/step-1…6`) and in-app at `/docs/plugins`.
61
+
62
+ ## Publishing (maintainers)
63
+
64
+ This repo publishes `@kahitsan/plugin-sdk` to public npm **independently of any kernel deploy**,
65
+ and builds with **ZERO live kernel** — no submodule, no `KERNEL_REPO_TOKEN`. The minimal `@ks-erp`
66
+ runtime/type surface the SDK inlines is **vendored** at `src/vendor-kernel/` (regenerate it from a
67
+ kernel checkout with `node sync-vendor.mjs <path-to-kserp>`), and the toolkit host-UI shell source
68
+ lives at `shell-src/` (`kserp/src` built with `KSERP_TOOLKIT=1`; its only kernel coupling is two
69
+ pure nav helpers vendored under `shell-src/kernel/`). `build.mjs` produces a self-contained,
70
+ obfuscated `dist/` and runs the K1/K2 leak gate over both the JS and the `.d.ts`; `npm run
71
+ build:shell` builds the kernel-identical static shell from `shell-src/`. CI is
72
+ `.github/workflows/publish-sdk.yml`.
73
+
74
+ ## License
75
+
76
+ Proprietary. Copyright (c) KahitSan Corp. All rights reserved. Licensed, not sold.
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;