@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.
- package/LICENSE +20 -0
- package/README.md +76 -0
- package/dist/index.d.ts +39 -40
- package/dist/index.js +1 -1
- package/package.json +30 -8
- package/shell/_build/.vite/manifest.json +59 -59
- package/shell/_build/.vite/manifest.json.br +0 -0
- package/shell/_build/.vite/manifest.json.gz +0 -0
- package/shell/_build/assets/{_...slug_-BNycC89F.js → _...slug_-BcdF4l5Z.js} +1 -1
- package/shell/_build/assets/_...slug_-BcdF4l5Z.js.br +0 -0
- package/shell/_build/assets/_...slug_-BcdF4l5Z.js.gz +0 -0
- package/shell/_build/assets/{api-keys-zDu0DTIi.js → api-keys-BNWgFkG0.js} +1 -1
- package/shell/_build/assets/{auth-CPW4mGTx.js → auth-DnjIzX2B.js} +5 -5
- package/shell/_build/assets/auth-DnjIzX2B.js.br +0 -0
- package/shell/_build/assets/auth-DnjIzX2B.js.gz +0 -0
- package/shell/_build/assets/client-BmadCoeU.css +1 -0
- package/shell/_build/assets/client-BmadCoeU.css.br +0 -0
- package/shell/_build/assets/client-BmadCoeU.css.gz +0 -0
- package/shell/_build/assets/client-StEn6jq1.js +2 -0
- package/shell/_build/assets/client-StEn6jq1.js.br +0 -0
- package/shell/_build/assets/client-StEn6jq1.js.gz +0 -0
- package/shell/_build/assets/{components-kMeatXhB.js → components-CWmQ2MDX.js} +1 -1
- package/shell/_build/assets/dashboard-pbkizuaa.js +1 -0
- package/shell/_build/assets/{index-dCQOOcel.js → index-CwObwzl5.js} +1 -1
- package/shell/_build/assets/login-pbkizuaa.js +1 -0
- package/shell/_build/assets/{members-CKVe_2mI.js → members-49i-57sG.js} +1 -1
- package/shell/_build/assets/plugin-ui-CBTroTyb.js +10 -0
- package/shell/_build/assets/plugin-ui-CBTroTyb.js.br +0 -0
- package/shell/_build/assets/plugin-ui-CBTroTyb.js.gz +0 -0
- package/shell/_build/assets/register-pbkizuaa.js +1 -0
- package/shell/_build/assets/routing-C6AwqsGL.js +1 -0
- package/shell/_build/assets/routing-C6AwqsGL.js.br +0 -0
- package/shell/_build/assets/routing-C6AwqsGL.js.gz +0 -0
- package/shell/_build/assets/settings-pbkizuaa.js +1 -0
- package/shell/_build/assets/users-pbkizuaa.js +1 -0
- package/shell/_build/assets/{workspace-nav-DsOJmRdY.js → workspace-nav-fkYL3-AV.js} +1 -1
- package/shell/_build/assets/workspace-nav-fkYL3-AV.js.br +0 -0
- package/shell/_build/assets/workspace-nav-fkYL3-AV.js.gz +0 -0
- package/shell/_build/assets/workspace-settings-pbkizuaa.js +1 -0
- package/shell/_build/assets/workspaces-pbkizuaa.js +1 -0
- package/shell/_server/assets/app-BmadCoeU.css +1 -0
- package/shell/_server/assets/app-BmadCoeU.css.br +0 -0
- package/shell/_server/assets/app-BmadCoeU.css.gz +0 -0
- package/shell/index.html +1 -1
- package/shell/index.html.br +0 -0
- package/shell/index.html.gz +0 -0
- package/shell/sw.js +2 -2
- package/shell/sw.js.br +0 -0
- package/shell/sw.js.gz +0 -0
- package/src/dev/dev-host.ts +3 -1
- package/shell/_build/assets/_...slug_-BNycC89F.js.br +0 -0
- package/shell/_build/assets/_...slug_-BNycC89F.js.gz +0 -0
- package/shell/_build/assets/auth-CPW4mGTx.js.br +0 -0
- package/shell/_build/assets/auth-CPW4mGTx.js.gz +0 -0
- package/shell/_build/assets/client-B0tH7z8C.css +0 -1
- package/shell/_build/assets/client-B0tH7z8C.css.br +0 -0
- package/shell/_build/assets/client-B0tH7z8C.css.gz +0 -0
- package/shell/_build/assets/client-BuqEzg-5.js +0 -2
- package/shell/_build/assets/client-BuqEzg-5.js.br +0 -0
- package/shell/_build/assets/client-BuqEzg-5.js.gz +0 -0
- package/shell/_build/assets/dashboard-BwMkrsX2.js +0 -1
- package/shell/_build/assets/login-BwMkrsX2.js +0 -1
- package/shell/_build/assets/plugin-ui-rgxz3UHD.js +0 -10
- package/shell/_build/assets/plugin-ui-rgxz3UHD.js.br +0 -0
- package/shell/_build/assets/plugin-ui-rgxz3UHD.js.gz +0 -0
- package/shell/_build/assets/register-BwMkrsX2.js +0 -1
- package/shell/_build/assets/routing-BlHUL5zP.js +0 -1
- package/shell/_build/assets/routing-BlHUL5zP.js.br +0 -0
- package/shell/_build/assets/routing-BlHUL5zP.js.gz +0 -0
- package/shell/_build/assets/settings-BwMkrsX2.js +0 -1
- package/shell/_build/assets/users-BwMkrsX2.js +0 -1
- package/shell/_build/assets/workspace-nav-DsOJmRdY.js.br +0 -0
- package/shell/_build/assets/workspace-nav-DsOJmRdY.js.gz +0 -0
- package/shell/_build/assets/workspace-settings-BwMkrsX2.js +0 -1
- package/shell/_build/assets/workspaces-BwMkrsX2.js +0 -1
- package/shell/_server/assets/app-B0tH7z8C.css +0 -1
- package/shell/_server/assets/app-B0tH7z8C.css.br +0 -0
- 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 {
|
|
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;
|