@xemahq/xema-service-nest 0.1.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 +176 -0
- package/README.md +84 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/apply-xema-service-middleware.d.ts +4 -0
- package/dist/lib/apply-xema-service-middleware.d.ts.map +1 -0
- package/dist/lib/apply-xema-service-middleware.js +8 -0
- package/dist/lib/apply-xema-service-middleware.js.map +1 -0
- package/dist/lib/biome-service-descriptor.d.ts +14 -0
- package/dist/lib/biome-service-descriptor.d.ts.map +1 -0
- package/dist/lib/biome-service-descriptor.js +37 -0
- package/dist/lib/biome-service-descriptor.js.map +1 -0
- package/dist/lib/xema-service-module.d.ts +16 -0
- package/dist/lib/xema-service-module.d.ts.map +1 -0
- package/dist/lib/xema-service-module.js +117 -0
- package/dist/lib/xema-service-module.js.map +1 -0
- package/package.json +87 -0
- package/src/index.ts +20 -0
- package/src/lib/apply-xema-service-middleware.ts +36 -0
- package/src/lib/biome-service-descriptor.ts +97 -0
- package/src/lib/xema-service-module.ts +233 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @xemahq/xema-service-nest
|
|
2
|
+
|
|
3
|
+
This package belongs to **Layer 1 — Kernel SDKs** (the sanctioned SDK-tier
|
|
4
|
+
*aggregate*). It composes sibling Layer-1 SDKs and Layer-0 contracts into a
|
|
5
|
+
single platform-service bootstrap; nothing in Layer 0 or the individual SDKs
|
|
6
|
+
may depend on it (the dependency edge runs downward only).
|
|
7
|
+
|
|
8
|
+
`XemaServiceModule.forBiome(descriptor)` wires the entire platform service stack
|
|
9
|
+
behind one call so a biome API is auth-correct in ~5 lines and **never re-wires
|
|
10
|
+
authentication**. It composes — it does not reimplement:
|
|
11
|
+
|
|
12
|
+
| Concern | Composed module |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| Self-registration + typed peer clients | `@xemahq/service-registry-nest` |
|
|
15
|
+
| Service token mint/refresh + Keycloak config | `@xemahq/identity-client` |
|
|
16
|
+
| Global JWT verification + request context | `@xemahq/platform-common` (`AuthModule`) |
|
|
17
|
+
| Fail-closed route/capability decorator scan | `@xemahq/xema-decorators` (`XemaRuntimeModule`) |
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
The `descriptor` is generated from the biome's `xema-biome.json` by
|
|
22
|
+
`tooling/codegen/generate-service-bootstrap.mjs` — you declare name/version/
|
|
23
|
+
dependencies **once** in the manifest, never again in `app.module.ts`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Module, type MiddlewareConsumer, type NestModule } from '@nestjs/common';
|
|
27
|
+
import { ConfigModule } from '@nestjs/config';
|
|
28
|
+
import {
|
|
29
|
+
XemaServiceModule,
|
|
30
|
+
applyXemaServiceMiddleware,
|
|
31
|
+
} from '@xemahq/xema-service-nest';
|
|
32
|
+
import { MAILOPS_API_BOOTSTRAP } from './generated/mailops-api.bootstrap.generated';
|
|
33
|
+
|
|
34
|
+
@Module({
|
|
35
|
+
imports: [
|
|
36
|
+
ConfigModule.forRoot({ isGlobal: true, load: [appConfig] }),
|
|
37
|
+
XemaServiceModule.forBiome(MAILOPS_API_BOOTSTRAP),
|
|
38
|
+
// ...feature modules
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
export class AppModule implements NestModule {
|
|
42
|
+
configure(consumer: MiddlewareConsumer): void {
|
|
43
|
+
applyXemaServiceMiddleware(consumer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Route policy stays with the biome
|
|
49
|
+
|
|
50
|
+
This module wires the auth **stack**; it does **not** decide what your endpoints
|
|
51
|
+
expose. Classify each route on your own controllers exactly as before:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
@XemaPublicRoute({ reason: PublicRouteReason.K8sProbe }) // public
|
|
55
|
+
@XemaInternalRoute({ audience: InternalRouteAudience.Service }) // service-to-service
|
|
56
|
+
@RequireOrgRole(OrgRole.Admin) // org-admin only
|
|
57
|
+
@RequireTokenClass(TokenClass.AgentRuntimeToken) // scoped runtime token
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A biome keeps full per-route freedom — like a core app — bounded only by the
|
|
61
|
+
platform's fail-closed scan (every route must be classified). The test suite
|
|
62
|
+
pins this invariant.
|
|
63
|
+
|
|
64
|
+
## Capability auto-register (opt-in)
|
|
65
|
+
|
|
66
|
+
When a biome ships fully-described `@XemaCapability` providers, pass
|
|
67
|
+
`registerCapabilities: true` plus a client factory; the composed runtime POSTs
|
|
68
|
+
them to `capability-registry-api` at boot:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
XemaServiceModule.forBiome(MAILOPS_API_BOOTSTRAP, {
|
|
72
|
+
registerCapabilities: true,
|
|
73
|
+
imports: [CapabilityClientModule],
|
|
74
|
+
inject: [ConfigService, IdentityBootstrapService],
|
|
75
|
+
useCapabilityRegistryClient: (cfg, idb) => new CapabilityRegistryClient(cfg, idb),
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Required environment
|
|
80
|
+
|
|
81
|
+
The module owns the auth/identity/registry env vars internally:
|
|
82
|
+
`IDENTITY_API_URL`, `IDENTITY_API_INTERNAL_TOKEN`, `XEMA_KERNEL_STATE_PROFILE`
|
|
83
|
+
(plus the kernel-state backing config). A consuming service does not redeclare
|
|
84
|
+
them per call.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { XemaServiceModule, type XemaServiceModuleOptions, } from './lib/xema-service-module';
|
|
2
|
+
export { applyXemaServiceMiddleware } from './lib/apply-xema-service-middleware';
|
|
3
|
+
export { type ConfigureAuthMiddlewareOptions } from '@xemahq/platform-common';
|
|
4
|
+
export { validateBiomeServiceDescriptor, BiomeServiceDescriptorError, type BiomeServiceDescriptor, } from './lib/biome-service-descriptor';
|
|
5
|
+
export { ServiceKind } from '@xemahq/xema-decorators';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,KAAK,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAG9E,OAAO,EACL,8BAA8B,EAC9B,2BAA2B,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceKind = exports.BiomeServiceDescriptorError = exports.validateBiomeServiceDescriptor = exports.applyXemaServiceMiddleware = exports.XemaServiceModule = void 0;
|
|
4
|
+
var xema_service_module_1 = require("./lib/xema-service-module");
|
|
5
|
+
Object.defineProperty(exports, "XemaServiceModule", { enumerable: true, get: function () { return xema_service_module_1.XemaServiceModule; } });
|
|
6
|
+
var apply_xema_service_middleware_1 = require("./lib/apply-xema-service-middleware");
|
|
7
|
+
Object.defineProperty(exports, "applyXemaServiceMiddleware", { enumerable: true, get: function () { return apply_xema_service_middleware_1.applyXemaServiceMiddleware; } });
|
|
8
|
+
var biome_service_descriptor_1 = require("./lib/biome-service-descriptor");
|
|
9
|
+
Object.defineProperty(exports, "validateBiomeServiceDescriptor", { enumerable: true, get: function () { return biome_service_descriptor_1.validateBiomeServiceDescriptor; } });
|
|
10
|
+
Object.defineProperty(exports, "BiomeServiceDescriptorError", { enumerable: true, get: function () { return biome_service_descriptor_1.BiomeServiceDescriptorError; } });
|
|
11
|
+
var xema_decorators_1 = require("@xemahq/xema-decorators");
|
|
12
|
+
Object.defineProperty(exports, "ServiceKind", { enumerable: true, get: function () { return xema_decorators_1.ServiceKind; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,iEAGmC;AAFjC,wHAAA,iBAAiB,OAAA;AAKnB,qFAAiF;AAAxE,2IAAA,0BAA0B,OAAA;AAInC,2EAIwC;AAHtC,0IAAA,8BAA8B,OAAA;AAC9B,uIAAA,2BAA2B,OAAA;AAM7B,2DAAsD;AAA7C,8GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
+
import { type ConfigureAuthMiddlewareOptions } from '@xemahq/platform-common';
|
|
3
|
+
export declare function applyXemaServiceMiddleware(consumer: MiddlewareConsumer, options?: ConfigureAuthMiddlewareOptions): void;
|
|
4
|
+
//# sourceMappingURL=apply-xema-service-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-xema-service-middleware.d.ts","sourceRoot":"","sources":["../../src/lib/apply-xema-service-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,yBAAyB,CAAC;AA0BjC,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,GAAE,8BAAmC,GAC3C,IAAI,CAEN"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyXemaServiceMiddleware = applyXemaServiceMiddleware;
|
|
4
|
+
const platform_common_1 = require("@xemahq/platform-common");
|
|
5
|
+
function applyXemaServiceMiddleware(consumer, options = {}) {
|
|
6
|
+
(0, platform_common_1.configureAuthMiddleware)(consumer, options);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=apply-xema-service-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-xema-service-middleware.js","sourceRoot":"","sources":["../../src/lib/apply-xema-service-middleware.ts"],"names":[],"mappings":";;AA8BA,gEAKC;AAlCD,6DAGiC;AA0BjC,SAAgB,0BAA0B,CACxC,QAA4B,EAC5B,UAA0C,EAAE;IAE5C,IAAA,yCAAuB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ServiceKind } from '@xemahq/xema-decorators';
|
|
2
|
+
export interface BiomeServiceDescriptor {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly semver: string;
|
|
5
|
+
readonly serviceKind: ServiceKind;
|
|
6
|
+
readonly displayName: string;
|
|
7
|
+
readonly requiresServices: readonly string[];
|
|
8
|
+
readonly exposesCapabilities: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare class BiomeServiceDescriptorError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function validateBiomeServiceDescriptor(descriptor: BiomeServiceDescriptor): void;
|
|
14
|
+
//# sourceMappingURL=biome-service-descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"biome-service-descriptor.d.ts","sourceRoot":"","sources":["../../src/lib/biome-service-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAkBtD,MAAM,WAAW,sBAAsB;IAErC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAElC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAO7B,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IAE7C,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;CACjD;AAOD,qBAAa,2BAA4B,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAInC;AAQD,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,sBAAsB,GACjC,IAAI,CAsCN"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BiomeServiceDescriptorError = void 0;
|
|
4
|
+
exports.validateBiomeServiceDescriptor = validateBiomeServiceDescriptor;
|
|
5
|
+
const xema_decorators_1 = require("@xemahq/xema-decorators");
|
|
6
|
+
class BiomeServiceDescriptorError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(`[xema-service-nest] ${message}`);
|
|
9
|
+
this.name = 'BiomeServiceDescriptorError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.BiomeServiceDescriptorError = BiomeServiceDescriptorError;
|
|
13
|
+
const SLUG_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
14
|
+
function validateBiomeServiceDescriptor(descriptor) {
|
|
15
|
+
if (!descriptor || typeof descriptor !== 'object') {
|
|
16
|
+
throw new BiomeServiceDescriptorError('forBiome requires a BiomeServiceDescriptor (did you import the generated bootstrap constant?).');
|
|
17
|
+
}
|
|
18
|
+
if (!descriptor.name || !SLUG_PATTERN.test(descriptor.name)) {
|
|
19
|
+
throw new BiomeServiceDescriptorError(`descriptor.name must be a kebab-case slug; got ${JSON.stringify(descriptor.name)}.`);
|
|
20
|
+
}
|
|
21
|
+
if (!descriptor.semver || descriptor.semver.trim() === '') {
|
|
22
|
+
throw new BiomeServiceDescriptorError(`descriptor.semver is required for ${descriptor.name}.`);
|
|
23
|
+
}
|
|
24
|
+
if (!Object.values(xema_decorators_1.ServiceKind).includes(descriptor.serviceKind)) {
|
|
25
|
+
throw new BiomeServiceDescriptorError(`descriptor.serviceKind for ${descriptor.name} must be one of ${Object.values(xema_decorators_1.ServiceKind).join(', ')}; got ${JSON.stringify(descriptor.serviceKind)}.`);
|
|
26
|
+
}
|
|
27
|
+
if (!descriptor.displayName || descriptor.displayName.trim() === '') {
|
|
28
|
+
throw new BiomeServiceDescriptorError(`descriptor.displayName is required for ${descriptor.name}.`);
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(descriptor.requiresServices)) {
|
|
31
|
+
throw new BiomeServiceDescriptorError(`descriptor.requiresServices for ${descriptor.name} must be an array (may be empty).`);
|
|
32
|
+
}
|
|
33
|
+
if (!Array.isArray(descriptor.exposesCapabilities)) {
|
|
34
|
+
throw new BiomeServiceDescriptorError(`descriptor.exposesCapabilities for ${descriptor.name} must be an array (may be empty).`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=biome-service-descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"biome-service-descriptor.js","sourceRoot":"","sources":["../../src/lib/biome-service-descriptor.ts"],"names":[],"mappings":";;;AAwDA,wEAwCC;AAhGD,6DAAsD;AA2CtD,MAAa,2BAA4B,SAAQ,KAAK;IACpD,YAAmB,OAAe;QAChC,KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AALD,kEAKC;AAED,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAMzC,SAAgB,8BAA8B,CAC5C,UAAkC;IAElC,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QAClD,MAAM,IAAI,2BAA2B,CACnC,gGAAgG,CACjG,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,2BAA2B,CACnC,kDAAkD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CACrF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,2BAA2B,CACnC,qCAAqC,UAAU,CAAC,IAAI,GAAG,CACxD,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,6BAAW,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,2BAA2B,CACnC,8BAA8B,UAAU,CAAC,IAAI,mBAAmB,MAAM,CAAC,MAAM,CAC3E,6BAAW,CACZ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAC/D,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACpE,MAAM,IAAI,2BAA2B,CACnC,0CAA0C,UAAU,CAAC,IAAI,GAAG,CAC7D,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,2BAA2B,CACnC,mCAAmC,UAAU,CAAC,IAAI,mCAAmC,CACtF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,2BAA2B,CACnC,sCAAsC,UAAU,CAAC,IAAI,mCAAmC,CACzF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DynamicModule, ModuleMetadata, FactoryProvider } from '@nestjs/common';
|
|
2
|
+
import { DiscoveryMode, PolicyMode, type XemaCapabilityRegistryClient } from '@xemahq/xema-decorators';
|
|
3
|
+
import { type BiomeServiceDescriptor } from './biome-service-descriptor';
|
|
4
|
+
export interface XemaServiceModuleOptions {
|
|
5
|
+
readonly policy?: PolicyMode;
|
|
6
|
+
readonly discovery?: DiscoveryMode;
|
|
7
|
+
readonly manifestOutputDir?: string;
|
|
8
|
+
readonly registerCapabilities?: boolean;
|
|
9
|
+
readonly useCapabilityRegistryClient?: (...args: never[]) => XemaCapabilityRegistryClient | Promise<XemaCapabilityRegistryClient>;
|
|
10
|
+
readonly inject?: FactoryProvider['inject'];
|
|
11
|
+
readonly imports?: ModuleMetadata['imports'];
|
|
12
|
+
}
|
|
13
|
+
export declare class XemaServiceModule {
|
|
14
|
+
static forBiome(descriptor: BiomeServiceDescriptor, options?: XemaServiceModuleOptions): DynamicModule;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=xema-service-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xema-service-module.d.ts","sourceRoot":"","sources":["../../src/lib/xema-service-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAkBrF,OAAO,EACL,aAAa,EACb,UAAU,EAEV,KAAK,4BAA4B,EAClC,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,4BAA4B,CAAC;AAQpC,MAAM,WAAW,wBAAwB;IAMvC,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAE7B,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;IAKnC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAMpC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAExC,QAAQ,CAAC,2BAA2B,CAAC,EAAE,CACrC,GAAG,IAAI,EAAE,KAAK,EAAE,KACb,4BAA4B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAE1E,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAE5C,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CAC9C;AAsCD,qBAAa,iBAAiB;WACd,QAAQ,CACpB,UAAU,EAAE,sBAAsB,EAClC,OAAO,GAAE,wBAA6B,GACrC,aAAa;CAejB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XemaServiceModule = void 0;
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const identity_client_1 = require("@xemahq/identity-client");
|
|
6
|
+
const service_registry_1 = require("@xemahq/kernel-contracts/service-registry");
|
|
7
|
+
const kernel_state_runtime_1 = require("@xemahq/kernel-state-runtime");
|
|
8
|
+
const platform_common_1 = require("@xemahq/platform-common");
|
|
9
|
+
const service_registry_nest_1 = require("@xemahq/service-registry-nest");
|
|
10
|
+
const xema_decorators_1 = require("@xemahq/xema-decorators");
|
|
11
|
+
const biome_service_descriptor_1 = require("./biome-service-descriptor");
|
|
12
|
+
class XemaServiceModule {
|
|
13
|
+
static forBiome(descriptor, options = {}) {
|
|
14
|
+
(0, biome_service_descriptor_1.validateBiomeServiceDescriptor)(descriptor);
|
|
15
|
+
const consumes = [...descriptor.requiresServices];
|
|
16
|
+
return {
|
|
17
|
+
module: XemaServiceModule,
|
|
18
|
+
imports: [
|
|
19
|
+
buildServiceRegistryModule(descriptor, consumes),
|
|
20
|
+
buildIdentityBootstrapModule(descriptor),
|
|
21
|
+
buildAuthModule(),
|
|
22
|
+
buildRuntimeModule(descriptor, options),
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.XemaServiceModule = XemaServiceModule;
|
|
28
|
+
function buildServiceRegistryModule(descriptor, consumes) {
|
|
29
|
+
return service_registry_nest_1.ServiceRegistryModule.forRootAsync({
|
|
30
|
+
imports: [config_1.ConfigModule],
|
|
31
|
+
consumes,
|
|
32
|
+
useFactory: (config) => ({
|
|
33
|
+
adapter: service_registry_nest_1.ServiceRegistryAdapterKind.KernelState,
|
|
34
|
+
kernelStateFactory: () => (0, kernel_state_runtime_1.createKernelState)({
|
|
35
|
+
profile: (0, service_registry_nest_1.parseKernelStateProfile)(config.get('XEMA_KERNEL_STATE_PROFILE')),
|
|
36
|
+
}),
|
|
37
|
+
consumes,
|
|
38
|
+
descriptor: {
|
|
39
|
+
name: descriptor.name,
|
|
40
|
+
semver: descriptor.semver,
|
|
41
|
+
instanceId: `${descriptor.name}:${process.pid}`,
|
|
42
|
+
endpoints: [
|
|
43
|
+
{
|
|
44
|
+
protocol: service_registry_1.ServiceEndpointProtocol.Http,
|
|
45
|
+
url: (0, service_registry_nest_1.buildSelfHttpEndpointUrl)(config, descriptor.name),
|
|
46
|
+
auth: service_registry_1.ServiceEndpointAuth.ServiceToken,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
exposesCapabilities: [...descriptor.exposesCapabilities],
|
|
50
|
+
requiresServices: consumes,
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
inject: [config_1.ConfigService],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function buildIdentityBootstrapModule(descriptor) {
|
|
57
|
+
return identity_client_1.IdentityBootstrapModule.forRootAsync({
|
|
58
|
+
imports: [config_1.ConfigModule],
|
|
59
|
+
useFactory: (config) => ({
|
|
60
|
+
identityApiUrl: config.getOrThrow('IDENTITY_API_URL'),
|
|
61
|
+
identityApiInternalToken: config.getOrThrow('IDENTITY_API_INTERNAL_TOKEN'),
|
|
62
|
+
serviceName: descriptor.name,
|
|
63
|
+
serviceDisplayName: descriptor.displayName,
|
|
64
|
+
}),
|
|
65
|
+
inject: [config_1.ConfigService],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function buildAuthModule() {
|
|
69
|
+
return platform_common_1.AuthModule.forRootAsync({
|
|
70
|
+
useFactory: (bootstrap) => ({
|
|
71
|
+
keycloakBaseUrlProvider: async () => {
|
|
72
|
+
await bootstrap.waitForReady();
|
|
73
|
+
const url = bootstrap.getKeycloakBaseUrl();
|
|
74
|
+
if (!url) {
|
|
75
|
+
throw new Error('IdentityBootstrapService did not return keycloakBaseUrl from identity-api');
|
|
76
|
+
}
|
|
77
|
+
return url;
|
|
78
|
+
},
|
|
79
|
+
allowedRealmsProvider: async () => {
|
|
80
|
+
await bootstrap.waitForReady();
|
|
81
|
+
return bootstrap.getAllowedRealms();
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
inject: [identity_client_1.IdentityBootstrapService],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function buildRuntimeModule(descriptor, options) {
|
|
88
|
+
const discovery = options.discovery ?? xema_decorators_1.DiscoveryMode.Decorators;
|
|
89
|
+
const policy = options.policy ?? xema_decorators_1.PolicyMode.FailClosed;
|
|
90
|
+
if (options.registerCapabilities) {
|
|
91
|
+
return xema_decorators_1.XemaRuntimeModule.forServiceAsync({
|
|
92
|
+
serviceName: descriptor.name,
|
|
93
|
+
serviceKind: descriptor.serviceKind,
|
|
94
|
+
discovery,
|
|
95
|
+
policy,
|
|
96
|
+
registerCapabilities: true,
|
|
97
|
+
...(options.manifestOutputDir !== undefined && {
|
|
98
|
+
manifestOutputDir: options.manifestOutputDir,
|
|
99
|
+
}),
|
|
100
|
+
...(options.useCapabilityRegistryClient !== undefined && {
|
|
101
|
+
useCapabilityRegistryClient: options.useCapabilityRegistryClient,
|
|
102
|
+
}),
|
|
103
|
+
...(options.inject !== undefined && { inject: options.inject }),
|
|
104
|
+
...(options.imports !== undefined && { imports: options.imports }),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return xema_decorators_1.XemaRuntimeModule.forService({
|
|
108
|
+
serviceName: descriptor.name,
|
|
109
|
+
serviceKind: descriptor.serviceKind,
|
|
110
|
+
discovery,
|
|
111
|
+
policy,
|
|
112
|
+
...(options.manifestOutputDir !== undefined && {
|
|
113
|
+
manifestOutputDir: options.manifestOutputDir,
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=xema-service-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xema-service-module.js","sourceRoot":"","sources":["../../src/lib/xema-service-module.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xemahq/xema-service-nest",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Xema platform service-bootstrap SDK. `XemaServiceModule.forBiome(descriptor)` composes the full platform service stack — Service Registry, Identity bootstrap, Auth (JWT verification + request context), and the Xema runtime route/capability scanner — behind a single call, so a biome API is auth-correct in ~5 lines and never re-wires authentication.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"xema",
|
|
7
|
+
"xema-platform",
|
|
8
|
+
"nestjs",
|
|
9
|
+
"biome",
|
|
10
|
+
"bootstrap",
|
|
11
|
+
"auth",
|
|
12
|
+
"service-registry",
|
|
13
|
+
"identity"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://docs.xema.dev/xema-service-nest",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/xema-dev/xema-monorepo/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/xema-dev/xema-monorepo.git",
|
|
22
|
+
"directory": "packages/sdks/xema-service-nest"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"registry": "https://registry.npmjs.org/"
|
|
28
|
+
},
|
|
29
|
+
"main": "dist/index.js",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@nestjs/common": "^10 || ^11",
|
|
39
|
+
"@nestjs/config": "^3 || ^4",
|
|
40
|
+
"@nestjs/core": "^10 || ^11",
|
|
41
|
+
"reflect-metadata": "^0.2"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@nestjs/common": "11.1.13",
|
|
45
|
+
"@nestjs/config": "4.0.2",
|
|
46
|
+
"@nestjs/core": "11.1.13",
|
|
47
|
+
"@nestjs/platform-express": "11.1.13",
|
|
48
|
+
"@nestjs/testing": "11.1.13",
|
|
49
|
+
"@types/jest": "^30.0.0",
|
|
50
|
+
"class-transformer": "0.5.1",
|
|
51
|
+
"class-validator": "0.14.4",
|
|
52
|
+
"@types/node": "25.2.3",
|
|
53
|
+
"jest": "^30.3.0",
|
|
54
|
+
"prettier": "3.6.2",
|
|
55
|
+
"reflect-metadata": "0.2.2",
|
|
56
|
+
"rxjs": "7.8.2",
|
|
57
|
+
"ts-jest": "^29.4.9",
|
|
58
|
+
"typescript": "5.9.3"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@xemahq/identity-client": "^0.3.2",
|
|
62
|
+
"@xemahq/kernel-contracts": "^0.3.0",
|
|
63
|
+
"@xemahq/kernel-state-runtime": "^0.1.4",
|
|
64
|
+
"@xemahq/platform-common": "^0.1.7",
|
|
65
|
+
"@xemahq/service-registry-nest": "^0.1.4",
|
|
66
|
+
"@xemahq/xema-decorators": "^0.1.3"
|
|
67
|
+
},
|
|
68
|
+
"exports": {
|
|
69
|
+
".": {
|
|
70
|
+
"types": "./dist/index.d.ts",
|
|
71
|
+
"xema-source": "./src/index.ts",
|
|
72
|
+
"default": "./dist/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./dist/lib/*": {
|
|
75
|
+
"types": "./dist/lib/*.d.ts",
|
|
76
|
+
"default": "./dist/lib/*.js"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"clean": "rm -rf dist",
|
|
81
|
+
"build": "tsc -p tsconfig.build.json",
|
|
82
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
83
|
+
"lint": "tsc -p tsconfig.json --noEmit",
|
|
84
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
85
|
+
"test": "jest"
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The single-call platform service bootstrap.
|
|
2
|
+
export {
|
|
3
|
+
XemaServiceModule,
|
|
4
|
+
type XemaServiceModuleOptions,
|
|
5
|
+
} from './lib/xema-service-module';
|
|
6
|
+
|
|
7
|
+
// Root-module middleware helper (request context).
|
|
8
|
+
export { applyXemaServiceMiddleware } from './lib/apply-xema-service-middleware';
|
|
9
|
+
export { type ConfigureAuthMiddlewareOptions } from '@xemahq/platform-common';
|
|
10
|
+
|
|
11
|
+
// The manifest-derived bootstrap identity consumed by `forBiome`.
|
|
12
|
+
export {
|
|
13
|
+
validateBiomeServiceDescriptor,
|
|
14
|
+
BiomeServiceDescriptorError,
|
|
15
|
+
type BiomeServiceDescriptor,
|
|
16
|
+
} from './lib/biome-service-descriptor';
|
|
17
|
+
|
|
18
|
+
// Re-export `ServiceKind` so a generated bootstrap constant can name its kind
|
|
19
|
+
// without a second import from `@xemahq/xema-decorators`.
|
|
20
|
+
export { ServiceKind } from '@xemahq/xema-decorators';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
configureAuthMiddleware,
|
|
4
|
+
type ConfigureAuthMiddlewareOptions,
|
|
5
|
+
} from '@xemahq/platform-common';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Apply the platform request-context middleware from a biome's root
|
|
9
|
+
* `AppModule.configure()`. Wraps `configureAuthMiddleware` so a biome calls
|
|
10
|
+
* exactly ONE thing and never imports the raw middleware wiring.
|
|
11
|
+
*
|
|
12
|
+
* NestJS only invokes `configure()` on the ROOT module, so this cannot be done
|
|
13
|
+
* inside `XemaServiceModule.forBiome` — the host module must call it.
|
|
14
|
+
*
|
|
15
|
+
* The optional second argument is forwarded verbatim, so a service keeps full
|
|
16
|
+
* control over `extraExcludes` (extra public routes) and `additionalControllers`
|
|
17
|
+
* (internal routes that authenticate via service-account JWTs and should still
|
|
18
|
+
* receive `RequestContext`).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* export class AppModule implements NestModule {
|
|
23
|
+
* configure(consumer: MiddlewareConsumer): void {
|
|
24
|
+
* applyXemaServiceMiddleware(consumer);
|
|
25
|
+
* // or, opting an internal controller into request-context:
|
|
26
|
+
* // applyXemaServiceMiddleware(consumer, { additionalControllers: [InternalFooController] });
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function applyXemaServiceMiddleware(
|
|
32
|
+
consumer: MiddlewareConsumer,
|
|
33
|
+
options: ConfigureAuthMiddlewareOptions = {},
|
|
34
|
+
): void {
|
|
35
|
+
configureAuthMiddleware(consumer, options);
|
|
36
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ServiceKind } from '@xemahq/xema-decorators';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The single-source-of-truth bootstrap identity of a biome API service.
|
|
5
|
+
*
|
|
6
|
+
* Every field here is derived from the biome's `xema-biome.json` manifest by
|
|
7
|
+
* `tooling/codegen/generate-service-bootstrap.mjs`, which emits one
|
|
8
|
+
* `src/generated/<service>.bootstrap.generated.ts` per `ships.apis[]` entry.
|
|
9
|
+
* `XemaServiceModule.forBiome(descriptor)` consumes that generated constant —
|
|
10
|
+
* so a developer declares name / version / dependencies ONCE in the manifest
|
|
11
|
+
* and never re-types them in `app.module.ts`.
|
|
12
|
+
*
|
|
13
|
+
* This type intentionally carries ONLY the identity a service registration
|
|
14
|
+
* needs. It does NOT carry route policy: a biome keeps full per-route freedom
|
|
15
|
+
* via the `@XemaPublicRoute` / `@XemaInternalRoute` / `@RequireOrgRole` /
|
|
16
|
+
* `@RequireTokenClass` decorators on its own controllers. The module wires the
|
|
17
|
+
* auth STACK; the biome decides what each endpoint exposes.
|
|
18
|
+
*/
|
|
19
|
+
export interface BiomeServiceDescriptor {
|
|
20
|
+
/** Canonical service slug (a `ServiceName` value), e.g. `'mailops-api'`. */
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/** Published semver, mirrored from the manifest `version`. */
|
|
23
|
+
readonly semver: string;
|
|
24
|
+
/** Whether this is a platform service or a biome API. */
|
|
25
|
+
readonly serviceKind: ServiceKind;
|
|
26
|
+
/** Human-readable display name registered with identity-api. */
|
|
27
|
+
readonly displayName: string;
|
|
28
|
+
/**
|
|
29
|
+
* Names of services this one calls. Each becomes a typed-client provider
|
|
30
|
+
* (`@InjectService(name)`) AND a `requiresServices` entry on the registry
|
|
31
|
+
* descriptor. Always include the services the auth stack itself needs
|
|
32
|
+
* (e.g. `identity-api`).
|
|
33
|
+
*/
|
|
34
|
+
readonly requiresServices: readonly string[];
|
|
35
|
+
/** Capability refs this service exposes (registry descriptor metadata). */
|
|
36
|
+
readonly exposesCapabilities: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A `BiomeServiceDescriptor` value error. Thrown at module-construction time
|
|
41
|
+
* so a malformed/empty descriptor fails the boot fast rather than registering
|
|
42
|
+
* a half-identified service.
|
|
43
|
+
*/
|
|
44
|
+
export class BiomeServiceDescriptorError extends Error {
|
|
45
|
+
public constructor(message: string) {
|
|
46
|
+
super(`[xema-service-nest] ${message}`);
|
|
47
|
+
this.name = 'BiomeServiceDescriptorError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const SLUG_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Fail-fast validation of a bootstrap descriptor. Centralized so both
|
|
55
|
+
* `forBiome` and any test harness enforce the same invariants.
|
|
56
|
+
*/
|
|
57
|
+
export function validateBiomeServiceDescriptor(
|
|
58
|
+
descriptor: BiomeServiceDescriptor,
|
|
59
|
+
): void {
|
|
60
|
+
if (!descriptor || typeof descriptor !== 'object') {
|
|
61
|
+
throw new BiomeServiceDescriptorError(
|
|
62
|
+
'forBiome requires a BiomeServiceDescriptor (did you import the generated bootstrap constant?).',
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (!descriptor.name || !SLUG_PATTERN.test(descriptor.name)) {
|
|
66
|
+
throw new BiomeServiceDescriptorError(
|
|
67
|
+
`descriptor.name must be a kebab-case slug; got ${JSON.stringify(descriptor.name)}.`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (!descriptor.semver || descriptor.semver.trim() === '') {
|
|
71
|
+
throw new BiomeServiceDescriptorError(
|
|
72
|
+
`descriptor.semver is required for ${descriptor.name}.`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (!Object.values(ServiceKind).includes(descriptor.serviceKind)) {
|
|
76
|
+
throw new BiomeServiceDescriptorError(
|
|
77
|
+
`descriptor.serviceKind for ${descriptor.name} must be one of ${Object.values(
|
|
78
|
+
ServiceKind,
|
|
79
|
+
).join(', ')}; got ${JSON.stringify(descriptor.serviceKind)}.`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (!descriptor.displayName || descriptor.displayName.trim() === '') {
|
|
83
|
+
throw new BiomeServiceDescriptorError(
|
|
84
|
+
`descriptor.displayName is required for ${descriptor.name}.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (!Array.isArray(descriptor.requiresServices)) {
|
|
88
|
+
throw new BiomeServiceDescriptorError(
|
|
89
|
+
`descriptor.requiresServices for ${descriptor.name} must be an array (may be empty).`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (!Array.isArray(descriptor.exposesCapabilities)) {
|
|
93
|
+
throw new BiomeServiceDescriptorError(
|
|
94
|
+
`descriptor.exposesCapabilities for ${descriptor.name} must be an array (may be empty).`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import type { DynamicModule, ModuleMetadata, FactoryProvider } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
3
|
+
import {
|
|
4
|
+
IdentityBootstrapModule,
|
|
5
|
+
IdentityBootstrapService,
|
|
6
|
+
} from '@xemahq/identity-client';
|
|
7
|
+
import {
|
|
8
|
+
ServiceEndpointAuth,
|
|
9
|
+
ServiceEndpointProtocol,
|
|
10
|
+
} from '@xemahq/kernel-contracts/service-registry';
|
|
11
|
+
import { createKernelState } from '@xemahq/kernel-state-runtime';
|
|
12
|
+
import { AuthModule } from '@xemahq/platform-common';
|
|
13
|
+
import {
|
|
14
|
+
buildSelfHttpEndpointUrl,
|
|
15
|
+
parseKernelStateProfile,
|
|
16
|
+
ServiceRegistryAdapterKind,
|
|
17
|
+
ServiceRegistryModule,
|
|
18
|
+
} from '@xemahq/service-registry-nest';
|
|
19
|
+
import {
|
|
20
|
+
DiscoveryMode,
|
|
21
|
+
PolicyMode,
|
|
22
|
+
XemaRuntimeModule,
|
|
23
|
+
type XemaCapabilityRegistryClient,
|
|
24
|
+
} from '@xemahq/xema-decorators';
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
validateBiomeServiceDescriptor,
|
|
28
|
+
type BiomeServiceDescriptor,
|
|
29
|
+
} from './biome-service-descriptor';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Optional behaviour overrides for {@link XemaServiceModule.forBiome}. Sane
|
|
33
|
+
* defaults are prod-safe (fail-closed route scan, KernelState registry
|
|
34
|
+
* adapter, capability auto-register OFF). A biome only sets these when it has
|
|
35
|
+
* a real reason to.
|
|
36
|
+
*/
|
|
37
|
+
export interface XemaServiceModuleOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Route-classification policy for the composed runtime scanner. Defaults to
|
|
40
|
+
* {@link PolicyMode.FailClosed} — unclassified routes crash boot in
|
|
41
|
+
* production. Override to {@link PolicyMode.FailOpen} only for local dev.
|
|
42
|
+
*/
|
|
43
|
+
readonly policy?: PolicyMode;
|
|
44
|
+
/** Discovery mode for the runtime scanner. Defaults to decorators. */
|
|
45
|
+
readonly discovery?: DiscoveryMode;
|
|
46
|
+
/**
|
|
47
|
+
* Override the runtime manifest output dir (tests / sandboxed tmpdir). See
|
|
48
|
+
* `XemaRuntimeModule` docs.
|
|
49
|
+
*/
|
|
50
|
+
readonly manifestOutputDir?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Opt into the boot-time capability auto-register path (Phase H#2). When
|
|
53
|
+
* `true`, `useCapabilityRegistryClient` + `inject` MUST be supplied — the
|
|
54
|
+
* runtime module refuses the flag without a client (no silent no-op).
|
|
55
|
+
*/
|
|
56
|
+
readonly registerCapabilities?: boolean;
|
|
57
|
+
/** Factory producing the capability-registry client (DI-resolved). */
|
|
58
|
+
readonly useCapabilityRegistryClient?: (
|
|
59
|
+
...args: never[]
|
|
60
|
+
) => XemaCapabilityRegistryClient | Promise<XemaCapabilityRegistryClient>;
|
|
61
|
+
/** DI tokens for {@link useCapabilityRegistryClient}. */
|
|
62
|
+
readonly inject?: FactoryProvider['inject'];
|
|
63
|
+
/** Extra modules the capability-client factory needs (e.g. a client module). */
|
|
64
|
+
readonly imports?: ModuleMetadata['imports'];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The one module a biome API imports to be platform-correct.
|
|
69
|
+
*
|
|
70
|
+
* `XemaServiceModule.forBiome(descriptor)` **composes** (never reimplements)
|
|
71
|
+
* the full platform service stack, in dependency order:
|
|
72
|
+
*
|
|
73
|
+
* 1. `ServiceRegistryModule` — self-registers with the cluster KernelState and
|
|
74
|
+
* pre-wires one typed client per `requiresServices` entry.
|
|
75
|
+
* 2. `IdentityBootstrapModule` — registers with identity-api, mints + refreshes
|
|
76
|
+
* the service `service_jwt`, and exposes the Keycloak base URL + realms.
|
|
77
|
+
* 3. `AuthModule` — the global `JwtVerificationGuard` (+ `RolesGuard`), wired
|
|
78
|
+
* lazily off `IdentityBootstrapService` so the realm config resolves after
|
|
79
|
+
* bootstrap.
|
|
80
|
+
* 4. `XemaRuntimeModule` — the fail-closed route/capability decorator scan.
|
|
81
|
+
*
|
|
82
|
+
* All four are `global: true`, so importing this one module makes the whole
|
|
83
|
+
* stack available app-wide. The biome still owns its route policy: classify
|
|
84
|
+
* each endpoint with `@XemaPublicRoute` / `@XemaInternalRoute` /
|
|
85
|
+
* `@RequireOrgRole` / `@RequireTokenClass` exactly as before — this module wires
|
|
86
|
+
* the stack, it does not constrain what a biome exposes.
|
|
87
|
+
*
|
|
88
|
+
* The root `AppModule` must additionally call `applyXemaServiceMiddleware(consumer)`
|
|
89
|
+
* in its `configure()` — NestJS only lets the root module register global
|
|
90
|
+
* middleware (`RequestContextMiddleware`), so a dynamic module cannot do it.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { XemaServiceModule, applyXemaServiceMiddleware } from '@xemahq/xema-service-nest';
|
|
95
|
+
* import { MAILOPS_API_BOOTSTRAP } from './generated/mailops-api.bootstrap.generated';
|
|
96
|
+
*
|
|
97
|
+
* @Module({ imports: [ConfigModule.forRoot({ isGlobal: true }), XemaServiceModule.forBiome(MAILOPS_API_BOOTSTRAP), ...] })
|
|
98
|
+
* export class AppModule implements NestModule {
|
|
99
|
+
* configure(c: MiddlewareConsumer) { applyXemaServiceMiddleware(c); }
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export class XemaServiceModule {
|
|
104
|
+
public static forBiome(
|
|
105
|
+
descriptor: BiomeServiceDescriptor,
|
|
106
|
+
options: XemaServiceModuleOptions = {},
|
|
107
|
+
): DynamicModule {
|
|
108
|
+
validateBiomeServiceDescriptor(descriptor);
|
|
109
|
+
|
|
110
|
+
const consumes = [...descriptor.requiresServices];
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
module: XemaServiceModule,
|
|
114
|
+
imports: [
|
|
115
|
+
buildServiceRegistryModule(descriptor, consumes),
|
|
116
|
+
buildIdentityBootstrapModule(descriptor),
|
|
117
|
+
buildAuthModule(),
|
|
118
|
+
buildRuntimeModule(descriptor, options),
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function buildServiceRegistryModule(
|
|
125
|
+
descriptor: BiomeServiceDescriptor,
|
|
126
|
+
consumes: string[],
|
|
127
|
+
): DynamicModule {
|
|
128
|
+
return ServiceRegistryModule.forRootAsync({
|
|
129
|
+
imports: [ConfigModule],
|
|
130
|
+
// Authoritative for typed-client provider creation (must be sync).
|
|
131
|
+
consumes,
|
|
132
|
+
useFactory: (config: ConfigService) => ({
|
|
133
|
+
adapter: ServiceRegistryAdapterKind.KernelState,
|
|
134
|
+
kernelStateFactory: () =>
|
|
135
|
+
createKernelState({
|
|
136
|
+
profile: parseKernelStateProfile(
|
|
137
|
+
config.get<string>('XEMA_KERNEL_STATE_PROFILE'),
|
|
138
|
+
),
|
|
139
|
+
}),
|
|
140
|
+
consumes,
|
|
141
|
+
descriptor: {
|
|
142
|
+
name: descriptor.name,
|
|
143
|
+
semver: descriptor.semver,
|
|
144
|
+
instanceId: `${descriptor.name}:${process.pid}`,
|
|
145
|
+
endpoints: [
|
|
146
|
+
{
|
|
147
|
+
protocol: ServiceEndpointProtocol.Http,
|
|
148
|
+
url: buildSelfHttpEndpointUrl(config, descriptor.name),
|
|
149
|
+
auth: ServiceEndpointAuth.ServiceToken,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
exposesCapabilities: [...descriptor.exposesCapabilities],
|
|
153
|
+
requiresServices: consumes,
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
inject: [ConfigService],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildIdentityBootstrapModule(
|
|
161
|
+
descriptor: BiomeServiceDescriptor,
|
|
162
|
+
): DynamicModule {
|
|
163
|
+
return IdentityBootstrapModule.forRootAsync({
|
|
164
|
+
imports: [ConfigModule],
|
|
165
|
+
useFactory: (config: ConfigService) => ({
|
|
166
|
+
identityApiUrl: config.getOrThrow<string>('IDENTITY_API_URL'),
|
|
167
|
+
identityApiInternalToken: config.getOrThrow<string>(
|
|
168
|
+
'IDENTITY_API_INTERNAL_TOKEN',
|
|
169
|
+
),
|
|
170
|
+
serviceName: descriptor.name,
|
|
171
|
+
serviceDisplayName: descriptor.displayName,
|
|
172
|
+
}),
|
|
173
|
+
inject: [ConfigService],
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function buildAuthModule(): DynamicModule {
|
|
178
|
+
return AuthModule.forRootAsync({
|
|
179
|
+
useFactory: (bootstrap: IdentityBootstrapService) => ({
|
|
180
|
+
keycloakBaseUrlProvider: async () => {
|
|
181
|
+
await bootstrap.waitForReady();
|
|
182
|
+
const url = bootstrap.getKeycloakBaseUrl();
|
|
183
|
+
if (!url) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
'IdentityBootstrapService did not return keycloakBaseUrl from identity-api',
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return url;
|
|
189
|
+
},
|
|
190
|
+
allowedRealmsProvider: async () => {
|
|
191
|
+
await bootstrap.waitForReady();
|
|
192
|
+
return bootstrap.getAllowedRealms();
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
inject: [IdentityBootstrapService],
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function buildRuntimeModule(
|
|
200
|
+
descriptor: BiomeServiceDescriptor,
|
|
201
|
+
options: XemaServiceModuleOptions,
|
|
202
|
+
): DynamicModule {
|
|
203
|
+
const discovery = options.discovery ?? DiscoveryMode.Decorators;
|
|
204
|
+
const policy = options.policy ?? PolicyMode.FailClosed;
|
|
205
|
+
|
|
206
|
+
if (options.registerCapabilities) {
|
|
207
|
+
return XemaRuntimeModule.forServiceAsync({
|
|
208
|
+
serviceName: descriptor.name,
|
|
209
|
+
serviceKind: descriptor.serviceKind,
|
|
210
|
+
discovery,
|
|
211
|
+
policy,
|
|
212
|
+
registerCapabilities: true,
|
|
213
|
+
...(options.manifestOutputDir !== undefined && {
|
|
214
|
+
manifestOutputDir: options.manifestOutputDir,
|
|
215
|
+
}),
|
|
216
|
+
...(options.useCapabilityRegistryClient !== undefined && {
|
|
217
|
+
useCapabilityRegistryClient: options.useCapabilityRegistryClient,
|
|
218
|
+
}),
|
|
219
|
+
...(options.inject !== undefined && { inject: options.inject }),
|
|
220
|
+
...(options.imports !== undefined && { imports: options.imports }),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return XemaRuntimeModule.forService({
|
|
225
|
+
serviceName: descriptor.name,
|
|
226
|
+
serviceKind: descriptor.serviceKind,
|
|
227
|
+
discovery,
|
|
228
|
+
policy,
|
|
229
|
+
...(options.manifestOutputDir !== undefined && {
|
|
230
|
+
manifestOutputDir: options.manifestOutputDir,
|
|
231
|
+
}),
|
|
232
|
+
});
|
|
233
|
+
}
|