@kubun/plugin-service-api 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/LICENSE.md +57 -0
- package/lib/index.d.ts +102 -0
- package/lib/index.js +7 -0
- package/package.json +33 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# The Prosperity Public License 3.0.0
|
|
2
|
+
|
|
3
|
+
Contributor: Paul Le Cam
|
|
4
|
+
|
|
5
|
+
Source Code: https://github.com/PaulLeCam/kubun
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
|
|
10
|
+
|
|
11
|
+
## Agreement
|
|
12
|
+
|
|
13
|
+
In order to receive this license, you have to agree to its rules. Those rules are both obligations under that agreement and conditions to your license. Don't do anything with this software that triggers a rule you can't or won't follow.
|
|
14
|
+
|
|
15
|
+
## Notices
|
|
16
|
+
|
|
17
|
+
Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
|
|
18
|
+
|
|
19
|
+
## Commercial Trial
|
|
20
|
+
|
|
21
|
+
Limit your use of this software for commercial purposes to a thirty-day trial period. If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
|
|
22
|
+
|
|
23
|
+
## Contributions Back
|
|
24
|
+
|
|
25
|
+
Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
|
|
26
|
+
|
|
27
|
+
## Personal Uses
|
|
28
|
+
|
|
29
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
|
|
30
|
+
|
|
31
|
+
## Noncommercial Organizations
|
|
32
|
+
|
|
33
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
|
|
34
|
+
|
|
35
|
+
## Defense
|
|
36
|
+
|
|
37
|
+
Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
|
|
38
|
+
|
|
39
|
+
## Copyright
|
|
40
|
+
|
|
41
|
+
The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
|
|
42
|
+
|
|
43
|
+
## Patent
|
|
44
|
+
|
|
45
|
+
The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
|
|
46
|
+
|
|
47
|
+
## Reliability
|
|
48
|
+
|
|
49
|
+
The contributor can't revoke this license.
|
|
50
|
+
|
|
51
|
+
## Excuse
|
|
52
|
+
|
|
53
|
+
You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
|
|
54
|
+
|
|
55
|
+
## No Liability
|
|
56
|
+
|
|
57
|
+
***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { ProtocolDefinition, ServerTransportOf } from '@enkaku/protocol';
|
|
2
|
+
import type { AccessRules } from '@enkaku/server';
|
|
3
|
+
export type { AccessRules };
|
|
4
|
+
/**
|
|
5
|
+
* Permissive protocol at the host's merge boundary. The host serves the union of
|
|
6
|
+
* the services it is configured with, so the concrete procedure map is not known
|
|
7
|
+
* statically — each service narrows its own protocol in its own `-api` package.
|
|
8
|
+
* `ProtocolDefinition` is `Record<string, AnyProcedureDefinition>`, which is the
|
|
9
|
+
* loosest shape Enkaku's `serve`/`Server` accept.
|
|
10
|
+
*/
|
|
11
|
+
export type ServiceProtocol = ProtocolDefinition;
|
|
12
|
+
/** Server-side transport the host serves a merged service protocol over. */
|
|
13
|
+
export type ServiceServerTransport = ServerTransportOf<ServiceProtocol>;
|
|
14
|
+
/**
|
|
15
|
+
* Subject-authorization check made available to service handlers via their call
|
|
16
|
+
* context. A handler calls it to gate an action a caller asserts on another
|
|
17
|
+
* subject's behalf. This contract only PLUMBS it through; the host's enforcement
|
|
18
|
+
* semantics are defined by later work.
|
|
19
|
+
*/
|
|
20
|
+
export type ServiceAuthorizer = (params: {
|
|
21
|
+
/** Verified caller DID (the message issuer). */
|
|
22
|
+
iss: string;
|
|
23
|
+
/** Fully-qualified procedure name, e.g. `echo/ping`. */
|
|
24
|
+
procedure: string;
|
|
25
|
+
/** Caller-asserted subject the action is taken on behalf of, when present. */
|
|
26
|
+
subject?: string;
|
|
27
|
+
}) => boolean | Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Context a service handler receives: the Enkaku request-handler context
|
|
30
|
+
* (`message`/`param`/`signal`) augmented with the verified caller `iss` and a
|
|
31
|
+
* bound {@link authorize} check. Kept structural because the host serves a union
|
|
32
|
+
* of services and cannot know the concrete procedure's param/result statically; a
|
|
33
|
+
* concrete service narrows these against its own protocol.
|
|
34
|
+
*
|
|
35
|
+
* `iss` and the `procedure` name are host-supplied (from the verified signed
|
|
36
|
+
* message, not the handler), so a handler can gate a caller-asserted `subject`
|
|
37
|
+
* but cannot spoof who the caller is or which procedure is running.
|
|
38
|
+
*/
|
|
39
|
+
export type ServiceHandlerContext = {
|
|
40
|
+
message: unknown;
|
|
41
|
+
param: unknown;
|
|
42
|
+
signal: AbortSignal;
|
|
43
|
+
/** Verified caller DID (the signed message issuer), when the request is authenticated. */
|
|
44
|
+
iss?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Ask the per-serve {@link ServiceAuthorizer} whether the verified caller may
|
|
47
|
+
* act for `subject`. `iss`/`procedure` are supplied by the host; only `subject`
|
|
48
|
+
* comes from the handler. With no `subject`, the caller acts only for itself.
|
|
49
|
+
*/
|
|
50
|
+
authorize: (subject?: string) => Promise<boolean>;
|
|
51
|
+
};
|
|
52
|
+
/** A single namespaced procedure handler, e.g. the impl behind `echo/ping`. */
|
|
53
|
+
export type ServiceHandler = (context: ServiceHandlerContext) => unknown | Promise<unknown>;
|
|
54
|
+
/**
|
|
55
|
+
* Namespaced handler map for a service, e.g. `{ 'echo/ping': handler }`. This is
|
|
56
|
+
* the canonical service-handler-map type; Enkaku's `ProcedureHandlers<Protocol>`
|
|
57
|
+
* is the strongly-typed form a concrete service produces against its own protocol.
|
|
58
|
+
*/
|
|
59
|
+
export type Handlers = Record<string, ServiceHandler>;
|
|
60
|
+
/**
|
|
61
|
+
* What a plugin passes to `registerProvider('service', impl)`: a named service's
|
|
62
|
+
* handlers plus its own access rules. `'service'` is the registry key (not
|
|
63
|
+
* repeated here); the engine wraps this with the envelope fields (`kind`,
|
|
64
|
+
* `transport`, `priority`).
|
|
65
|
+
*/
|
|
66
|
+
export type ServiceProviderImpl = {
|
|
67
|
+
name: string;
|
|
68
|
+
handlers: Handlers;
|
|
69
|
+
accessRules?: AccessRules;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Per-service configuration, keyed by service NAME. Discriminated by explicit
|
|
73
|
+
* key, never by shape-sniffing:
|
|
74
|
+
* - `boolean` — toggle a provider-registered service. `true` serves it with its
|
|
75
|
+
* own access rules; `false` leaves it registered but not served.
|
|
76
|
+
* - `{ handlers }` — a CUSTOM service impl (optional `rules`). Its name must NOT
|
|
77
|
+
* be provider-registered (that collision is a serve-time error).
|
|
78
|
+
* - `{ rules }` with no `handlers` — an access-rules OVERRIDE for a
|
|
79
|
+
* provider-registered service.
|
|
80
|
+
* - `{}` (neither key) is equivalent to `true`.
|
|
81
|
+
*/
|
|
82
|
+
export type ServiceConfig = boolean | {
|
|
83
|
+
rules?: AccessRules;
|
|
84
|
+
handlers?: Handlers;
|
|
85
|
+
};
|
|
86
|
+
/** Parameters for a single host `serve()` call. */
|
|
87
|
+
export type ServiceServerServeParams = {
|
|
88
|
+
/** Server-side transport this server reads and writes. */
|
|
89
|
+
transport: ServiceServerTransport;
|
|
90
|
+
/** Which services to serve, keyed by service name. See {@link ServiceConfig}. */
|
|
91
|
+
services: Record<string, ServiceConfig>;
|
|
92
|
+
/** Subject-auth check plumbed into each served handler's context. */
|
|
93
|
+
authorizer?: ServiceAuthorizer;
|
|
94
|
+
/**
|
|
95
|
+
* Disable auth for THIS serve — unauthenticated local mode; serves the
|
|
96
|
+
* configured services' procedures with no signature requirement.
|
|
97
|
+
* `accessRules`/`authorizer` are moot when set.
|
|
98
|
+
*/
|
|
99
|
+
requireAuth?: false;
|
|
100
|
+
/** Aborts the server when signalled. */
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Cross-plugin contract for the service framework: the shapes a service package
|
|
2
|
+
// registers with the host (`registerProvider('service', impl)`) and the shapes a
|
|
3
|
+
// host consumes to serve them over a transport. Types only — importing this
|
|
4
|
+
// creates no runtime edge on the host plugin, so a service package stays
|
|
5
|
+
// independently loadable. The host implements the serving; each concrete service
|
|
6
|
+
// keeps its own typed protocol in its own `-api` package.
|
|
7
|
+
/** Parameters for a single host `serve()` call. */ export { };
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubun/plugin-service-api",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"keywords": [],
|
|
5
|
+
"license": "see LICENSE.md",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"types": "lib/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"lib/*",
|
|
15
|
+
"LICENSE.md"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@enkaku/protocol": "^0.21.0",
|
|
19
|
+
"@enkaku/server": "^0.21.2"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
26
|
+
"build:clean": "del lib",
|
|
27
|
+
"build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
28
|
+
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
29
|
+
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
30
|
+
"test": "pnpm run test:types",
|
|
31
|
+
"test:types": "tsc --noEmit --skipLibCheck"
|
|
32
|
+
}
|
|
33
|
+
}
|