@kubun/plugin-service-server 0.17.0 → 0.17.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type Server } from '@enkaku/server';
2
2
  import { type DIDResolver, type MethodRegistry } from '@kokuin/token';
3
3
  import type { KubunPlugin, PluginFactoryParams } from '@kubun/engine';
4
- import type { ServiceHandler, ServiceProtocol, ServiceServerServeParams } from '@kubun/plugin-service-api';
4
+ import type { ServiceAuthorizer, ServiceHandler, ServiceProtocol, ServiceServerServeParams } from '@kubun/plugin-service-api';
5
5
  export type { AccessRules, Handlers, ServiceAuthorizer, ServiceConfig, ServiceHandler, ServiceHandlerContext, ServiceProviderImpl, ServiceServerServeParams, } from '@kubun/plugin-service-api';
6
6
  export { type AuthorizeParams, type AuthorizeReadParams, authorizeRead, authorizeWrite, type CreateCallerMayActForParams, createCallerMayActFor, SERVICE_ACT_FOR_ACTION, ServiceAuthorizationError, serviceUserResource, } from './authorizer.js';
7
7
  /**
@@ -67,6 +67,17 @@ export type ServiceServerPluginAPI = {
67
67
  * verification (`methods = [controllerResolverFor(db)]`, pre-transaction).
68
68
  */
69
69
  export declare function createServiceServerPlugin(options?: ServiceServerPluginOptions): (params: PluginFactoryParams) => KubunPlugin;
70
+ /** Params for {@link wrapHandler}. */
71
+ export type WrapHandlerParams = {
72
+ /** Fully-qualified procedure name, e.g. `echo/ping`. */
73
+ procedure: string;
74
+ /** The service handler to wrap. */
75
+ handler: ServiceHandler;
76
+ /** The per-serve authorizer; absent falls back to {@link selfOnlyAuthorizer}. */
77
+ authorizer?: ServiceAuthorizer;
78
+ /** The per-serve group id, forwarded to the handler's context. */
79
+ groupID?: string;
80
+ };
70
81
  /**
71
82
  * Wrap a service handler so the host — not the caller — supplies the verified
72
83
  * `iss` and the `procedure` name to the per-serve authorizer, and so a forged
@@ -78,4 +89,4 @@ export declare function createServiceServerPlugin(options?: ServiceServerPluginO
78
89
  * receives a bound `authorize(subject)` that calls the per-serve authorizer with
79
90
  * host-supplied `{ iss, procedure }`; a handler cannot spoof either.
80
91
  */
81
- export declare function wrapHandler(procedure: string, handler: ServiceHandler, authorizer: ServiceServerServeParams['authorizer']): ServiceHandler;
92
+ export declare function wrapHandler(params: WrapHandlerParams): ServiceHandler;
package/lib/index.js CHANGED
@@ -114,7 +114,7 @@ const SERVICE_KIND = 'service';
114
114
  ];
115
115
  const api = {
116
116
  serve: (serveParams)=>{
117
- const { transport, services, authorizer, signal, requireAuth, cache } = serveParams;
117
+ const { transport, services, authorizer, signal, requireAuth, cache, groupID } = serveParams;
118
118
  const providerList = engine.getProvidersSync(SERVICE_KIND);
119
119
  const providers = new Map();
120
120
  for (const provider of providerList){
@@ -134,7 +134,12 @@ const SERVICE_KIND = 'service';
134
134
  if (procedure in mergedHandlers) {
135
135
  throw new ServiceProcedureCollisionError(procedure);
136
136
  }
137
- mergedHandlers[procedure] = wrapHandler(procedure, handler, authorizer);
137
+ mergedHandlers[procedure] = wrapHandler({
138
+ procedure,
139
+ handler,
140
+ authorizer,
141
+ groupID
142
+ });
138
143
  }
139
144
  Object.assign(mergedRules, selected.rules);
140
145
  }
@@ -208,7 +213,8 @@ const selfOnlyAuthorizer = ({ iss, subject })=>subject == null || normalizeDID(i
208
213
  * rejected outright, mirroring the RPC plugin's `resolveViewerDID`. The handler
209
214
  * receives a bound `authorize(subject)` that calls the per-serve authorizer with
210
215
  * host-supplied `{ iss, procedure }`; a handler cannot spoof either.
211
- */ export function wrapHandler(procedure, handler, authorizer) {
216
+ */ export function wrapHandler(params) {
217
+ const { procedure, handler, authorizer, groupID } = params;
212
218
  const check = authorizer ?? selfOnlyAuthorizer;
213
219
  return async (context)=>{
214
220
  // One gate: apply authz context, then translate on throw. A refusal carrying a
@@ -236,7 +242,8 @@ const selfOnlyAuthorizer = ({ iss, subject })=>subject == null || normalizeDID(i
236
242
  return await handler({
237
243
  ...context,
238
244
  iss,
239
- authorize
245
+ authorize,
246
+ groupID
240
247
  });
241
248
  } catch (cause) {
242
249
  throw toHandlerError(cause);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/plugin-service-server",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "license": "see LICENSE.md",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -18,9 +18,9 @@
18
18
  "@enkaku/server": "^0.21.2",
19
19
  "@kokuin/capability": "^0.3.0",
20
20
  "@kokuin/token": "^0.5.0",
21
- "@kubun/engine": "^0.17.0",
22
- "@kubun/plugin-service-api": "^0.17.0",
23
- "@kubun/protocol": "^0.17.0"
21
+ "@kubun/engine": "^0.17.2",
22
+ "@kubun/plugin-service-api": "^0.17.1",
23
+ "@kubun/protocol": "^0.17.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@enkaku/client": "^0.21.2",
@@ -28,7 +28,7 @@
28
28
  "@kokuin/controller": "^0.1.0",
29
29
  "@kubun/db": "^0.17.0",
30
30
  "@kubun/store-controller": "^0.17.0",
31
- "@kubun/store-graph": "^0.17.0",
31
+ "@kubun/store-graph": "^0.17.1",
32
32
  "@kubun/test-utils": "^0.0.0"
33
33
  },
34
34
  "publishConfig": {