@kubun/plugin-http 0.13.2 → 0.15.0

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 (3) hide show
  1. package/lib/index.d.ts +17 -12
  2. package/lib/index.js +32 -10
  3. package/package.json +10 -7
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { KubunPlugin, PluginFactoryParams } from '@kubun/engine';
2
- import type { RPCPluginAPI } from '@kubun/plugin-rpc';
2
+ import type { AccessRules } from '@kubun/plugin-service-api';
3
+ import type { ServiceServerPluginAPI } from '@kubun/plugin-service-server';
3
4
  import { Hono } from 'hono';
4
5
  /**
5
6
  * Options for the HTTP infrastructure plugin.
@@ -13,25 +14,29 @@ export type HTTPPluginOptions = {
13
14
  prefix?: string;
14
15
  /** Maximum request body size in bytes, enforced by the transport. Default: 1 MiB. */
15
16
  bodyLimit?: number;
17
+ /**
18
+ * Access posture for the graph service served over HTTP. `false` disables auth
19
+ * entirely; an `AccessRules` object grants the enumerated procedures; omit for
20
+ * the server-only default.
21
+ */
22
+ accessRules?: false | AccessRules;
16
23
  };
17
24
  /**
18
25
  * API provided by the HTTP infrastructure plugin.
19
26
  * Provides a shared routing surface for other plugins to register routes on.
20
27
  */
21
- export type HTTPPluginAPI = {
22
- /** Resolves when the HTTP server is accepting connections. */
23
- listening: Promise<void>;
24
- registerRoute: (method: string, path: string, handler: (c: unknown) => unknown) => void;
25
- registerProtocol: (name: string, fetch: (req: Request) => Response | Promise<Response>) => void;
26
- getPort: () => number;
27
- getURL: () => string;
28
- };
29
28
  /**
30
29
  * Options for creating a standalone graph protocol Hono app.
31
30
  */
32
31
  export type GraphAppOptions = {
33
- /** The RPC plugin API (already resolved). */
34
- rpc: RPCPluginAPI;
32
+ /** The service host API (already resolved). */
33
+ host: ServiceServerPluginAPI;
34
+ /**
35
+ * Access posture for the graph service. `false` disables auth entirely; an
36
+ * `AccessRules` object grants the enumerated procedures; omit for the
37
+ * server-only default.
38
+ */
39
+ accessRules?: false | AccessRules;
35
40
  /** Allowed CORS origin(s). Default: deny cross-origin. */
36
41
  allowedOrigin?: string | Array<string>;
37
42
  /** Maximum request body size in bytes, enforced by the transport. Default: 1 MiB. */
@@ -52,7 +57,7 @@ export type GraphApp = {
52
57
  *
53
58
  * The caller is responsible for:
54
59
  * - Creating and awaiting the KubunEngine
55
- * - Resolving the RPCPluginAPI via engine.getAPI('rpc')
60
+ * - Resolving the ServiceServerPluginAPI via engine.getAPI('service-server')
56
61
  * - Mounting the returned app and managing the HTTP server lifecycle
57
62
  */
58
63
  export declare function createGraphApp(options: GraphAppOptions): GraphApp;
package/lib/index.js CHANGED
@@ -28,7 +28,7 @@ function createProtocolHandler(fetch) {
28
28
  *
29
29
  * The caller is responsible for:
30
30
  * - Creating and awaiting the KubunEngine
31
- * - Resolving the RPCPluginAPI via engine.getAPI('rpc')
31
+ * - Resolving the ServiceServerPluginAPI via engine.getAPI('service-server')
32
32
  * - Mounting the returned app and managing the HTTP server lifecycle
33
33
  */ export function createGraphApp(options) {
34
34
  const app = new Hono();
@@ -38,9 +38,20 @@ function createProtocolHandler(fetch) {
38
38
  maxRequestBodySize: options.bodyLimit ?? DEFAULT_BODY_LIMIT_BYTES
39
39
  });
40
40
  const handler = createProtocolHandler(transport.fetch.bind(transport));
41
- // @ts-expect-error: type instantiation too deep
42
- const server = options.rpc.serve({
43
- transport
41
+ const requireAuth = options.accessRules === false;
42
+ const services = options.accessRules != null && options.accessRules !== false ? {
43
+ graph: {
44
+ rules: options.accessRules
45
+ }
46
+ } : {
47
+ graph: true
48
+ };
49
+ const server = options.host.serve({
50
+ transport,
51
+ services,
52
+ ...requireAuth ? {
53
+ requireAuth: false
54
+ } : {}
44
55
  });
45
56
  app.post('/graph', handler);
46
57
  app.post('/graph/*', handler);
@@ -128,12 +139,23 @@ function createProtocolHandler(fetch) {
128
139
  maxRequestBodySize: options?.bodyLimit ?? DEFAULT_BODY_LIMIT_BYTES
129
140
  });
130
141
  api.registerProtocol('graph', transport.fetch.bind(transport));
131
- // Get handlers from plugin-rpc's API instead of the engine's merged handler map.
132
- // This decouples plugin-http from the engine's handler merging mechanism.
133
- const rpcPlugin = await params.engine.getAPI('rpc');
134
- // @ts-expect-error: type instantiation too deep
135
- enkakuServer = rpcPlugin.serve({
136
- transport
142
+ // Serve the graph service through the service host rather than the engine's
143
+ // merged handler map, decoupling plugin-http from handler merging.
144
+ const host = await params.engine.getAPI('service-server');
145
+ const requireAuth = options?.accessRules === false;
146
+ const services = options?.accessRules != null && options.accessRules !== false ? {
147
+ graph: {
148
+ rules: options.accessRules
149
+ }
150
+ } : {
151
+ graph: true
152
+ };
153
+ enkakuServer = host.serve({
154
+ transport,
155
+ services,
156
+ ...requireAuth ? {
157
+ requireAuth: false
158
+ } : {}
137
159
  });
138
160
  httpServer = serve({
139
161
  fetch: app.fetch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/plugin-http",
3
- "version": "0.13.2",
3
+ "version": "0.15.0",
4
4
  "license": "see LICENSE.md",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -18,17 +18,20 @@
18
18
  "@enkaku/protocol": "^0.21.0",
19
19
  "@enkaku/server": "^0.21.2",
20
20
  "@hono/node-server": "^2.1.1",
21
+ "@kubun/engine": "^0.15.0",
22
+ "@kubun/http-util": "^0.15.0",
23
+ "@kubun/plugin-http-api": "^0.15.0",
21
24
  "@sozai/async": "^0.2.1",
22
25
  "get-port": "^7.2.0",
23
- "hono": "^4.13.3",
24
- "@kubun/engine": "^0.13.1",
25
- "@kubun/http-util": "^0.13.0"
26
+ "hono": "^4.13.5"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@enkaku/http-fetch": "^0.21.0",
29
- "@kubun/client": "^0.13.0",
30
- "@kubun/plugin-rpc": "^0.13.2",
31
- "@kubun/protocol": "^0.13.1",
30
+ "@kubun/client": "^0.15.0",
31
+ "@kubun/plugin-service-api": "^0.15.0",
32
+ "@kubun/plugin-service-server": "^0.15.0",
33
+ "@kubun/protocol": "^0.15.0",
34
+ "@kubun/service-graph-api": "^0.15.0",
32
35
  "@kubun/test-utils": "^0.13.0"
33
36
  },
34
37
  "publishConfig": {