@kubun/plugin-http 0.13.0 → 0.14.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.
- package/lib/index.d.ts +17 -12
- package/lib/index.js +34 -8
- 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 {
|
|
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
|
|
34
|
-
|
|
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
|
|
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
|
|
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,8 +38,21 @@ function createProtocolHandler(fetch) {
|
|
|
38
38
|
maxRequestBodySize: options.bodyLimit ?? DEFAULT_BODY_LIMIT_BYTES
|
|
39
39
|
});
|
|
40
40
|
const handler = createProtocolHandler(transport.fetch.bind(transport));
|
|
41
|
-
|
|
42
|
-
const
|
|
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
|
+
} : {}
|
|
55
|
+
});
|
|
43
56
|
app.post('/graph', handler);
|
|
44
57
|
app.post('/graph/*', handler);
|
|
45
58
|
app.options('/graph', handler);
|
|
@@ -126,11 +139,24 @@ function createProtocolHandler(fetch) {
|
|
|
126
139
|
maxRequestBodySize: options?.bodyLimit ?? DEFAULT_BODY_LIMIT_BYTES
|
|
127
140
|
});
|
|
128
141
|
api.registerProtocol('graph', transport.fetch.bind(transport));
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
} : {}
|
|
159
|
+
});
|
|
134
160
|
httpServer = serve({
|
|
135
161
|
fetch: app.fetch,
|
|
136
162
|
port
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/plugin-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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.14.0",
|
|
22
|
+
"@kubun/http-util": "^0.14.0",
|
|
23
|
+
"@kubun/plugin-http-api": "^0.14.0",
|
|
21
24
|
"@sozai/async": "^0.2.1",
|
|
22
25
|
"get-port": "^7.2.0",
|
|
23
|
-
"hono": "^4.13.
|
|
24
|
-
"@kubun/engine": "^0.13.0",
|
|
25
|
-
"@kubun/http-util": "^0.13.0"
|
|
26
|
+
"hono": "^4.13.4"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@enkaku/http-fetch": "^0.21.0",
|
|
29
|
-
"@kubun/client": "^0.
|
|
30
|
-
"@kubun/plugin-
|
|
31
|
-
"@kubun/
|
|
30
|
+
"@kubun/client": "^0.14.0",
|
|
31
|
+
"@kubun/plugin-service-api": "^0.14.0",
|
|
32
|
+
"@kubun/plugin-service-server": "^0.14.0",
|
|
33
|
+
"@kubun/protocol": "^0.14.0",
|
|
34
|
+
"@kubun/service-graph-api": "^0.14.0",
|
|
32
35
|
"@kubun/test-utils": "^0.13.0"
|
|
33
36
|
},
|
|
34
37
|
"publishConfig": {
|