@xemahq/entitlement-client 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 +201 -0
- package/README.md +70 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/entitlement-client.module.d.ts +14 -0
- package/dist/lib/entitlement-client.module.d.ts.map +1 -0
- package/dist/lib/entitlement-client.module.js +45 -0
- package/dist/lib/entitlement-client.module.js.map +1 -0
- package/dist/lib/entitlement.guard.d.ts +14 -0
- package/dist/lib/entitlement.guard.d.ts.map +1 -0
- package/dist/lib/entitlement.guard.js +67 -0
- package/dist/lib/entitlement.guard.js.map +1 -0
- package/dist/lib/entitlement.service.d.ts +24 -0
- package/dist/lib/entitlement.service.d.ts.map +1 -0
- package/dist/lib/entitlement.service.js +116 -0
- package/dist/lib/entitlement.service.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 describing the origin of the Work and
|
|
141
|
+
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 Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend, and
|
|
172
|
+
hold each Contributor harmless for any liability incurred by, or
|
|
173
|
+
claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Xema
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="@xemahq/entitlement-client">
|
|
3
|
+
<rect width="680" height="120" rx="14" fill="#0B1020"/>
|
|
4
|
+
<g transform="translate(28,34)">
|
|
5
|
+
<path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="#8B5CF6" opacity="0.18"/>
|
|
6
|
+
<path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#8B5CF6"/>
|
|
7
|
+
</g>
|
|
8
|
+
<text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="22" fill="#F8FAFC" font-weight="700">@xemahq/entitlement-client</text>
|
|
9
|
+
<text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">NestJS client that resolves per-org entitlements.</text>
|
|
10
|
+
<text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>
|
|
11
|
+
</svg>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://xema.dev">Website</a> ·
|
|
16
|
+
<a href="https://www.npmjs.com/package/@xemahq/entitlement-client">npm</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Fentitlement-client?color=2563eb&label=npm">
|
|
21
|
+
<img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Fentitlement-client?color=10b981">
|
|
22
|
+
<img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Fentitlement-client?color=3178c6">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
# @xemahq/entitlement-client
|
|
26
|
+
|
|
27
|
+
> NestJS client that resolves per-org entitlements.
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
A NestJS module and injectable service that resolves an organization's
|
|
32
|
+
effective entitlement at runtime. It fetches the per-org entitlement, applies
|
|
33
|
+
the deployment ceiling client-side so a stale upstream can never grant more
|
|
34
|
+
than the build allows, and caches results with a short TTL and in-flight
|
|
35
|
+
de-duplication. It is fail-closed: any error, timeout, or unknown state
|
|
36
|
+
resolves to the most restrictive edition.
|
|
37
|
+
|
|
38
|
+
## When to use it
|
|
39
|
+
|
|
40
|
+
- Use it inside a NestJS service that needs to gate a feature on an
|
|
41
|
+
organization's effective entitlement.
|
|
42
|
+
- Reach for `@xemahq/entitlement-contracts` instead when you only need the pure
|
|
43
|
+
types and resolvers without a NestJS client.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm add @xemahq/entitlement-client
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { EntitlementService } from '@xemahq/entitlement-client';
|
|
55
|
+
|
|
56
|
+
constructor(private readonly entitlements: EntitlementService) {}
|
|
57
|
+
|
|
58
|
+
async canUse(orgId: string, key: EntitlementKey): Promise<boolean> {
|
|
59
|
+
return this.entitlements.isEntitled(orgId, key);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Peer requirements
|
|
64
|
+
|
|
65
|
+
- `@nestjs/common` and `@nestjs/core` >= 10
|
|
66
|
+
- `reflect-metadata` >= 0.1.12
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
Apache-2.0 © Xema — [xema.dev](https://xema.dev)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./lib/entitlement.service"), exports);
|
|
18
|
+
__exportStar(require("./lib/entitlement-client.module"), exports);
|
|
19
|
+
__exportStar(require("./lib/entitlement.guard"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,kEAAgD;AAChD,0DAAwC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DynamicModule, type ForwardReference, type InjectionToken, type Type } from '@nestjs/common';
|
|
2
|
+
import { type EntitlementClientConfig } from './entitlement.service';
|
|
3
|
+
type ModuleImport = Type<unknown> | ForwardReference<unknown> | DynamicModule | Promise<DynamicModule>;
|
|
4
|
+
export interface EntitlementClientModuleAsyncOptions {
|
|
5
|
+
imports?: ModuleImport[];
|
|
6
|
+
useFactory: (...args: any[]) => Promise<EntitlementClientConfig> | EntitlementClientConfig;
|
|
7
|
+
inject?: InjectionToken[];
|
|
8
|
+
}
|
|
9
|
+
export declare class EntitlementClientModule {
|
|
10
|
+
static forRoot(config: EntitlementClientConfig): DynamicModule;
|
|
11
|
+
static forRootAsync(options: EntitlementClientModuleAsyncOptions): DynamicModule;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=entitlement-client.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement-client.module.d.ts","sourceRoot":"","sources":["../../src/lib/entitlement-client.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAGnB,KAAK,IAAI,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,uBAAuB,CAAC;AAE/B,KAAK,YAAY,GACb,IAAI,CAAC,OAAO,CAAC,GACb,gBAAgB,CAAC,OAAO,CAAC,GACzB,aAAa,GACb,OAAO,CAAC,aAAa,CAAC,CAAC;AAU3B,MAAM,WAAW,mCAAmC;IAClD,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,UAAU,EAAE,CAEV,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,OAAO,CAAC,uBAAuB,CAAC,GAAG,uBAAuB,CAAC;IAChE,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;CAC3B;AAgCD,qBACa,uBAAuB;IAElC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,uBAAuB,GAAG,aAAa;IAe9D,MAAM,CAAC,YAAY,CACjB,OAAO,EAAE,mCAAmC,GAC3C,aAAa;CAejB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var EntitlementClientModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EntitlementClientModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const entitlement_service_1 = require("./entitlement.service");
|
|
13
|
+
let EntitlementClientModule = EntitlementClientModule_1 = class EntitlementClientModule {
|
|
14
|
+
static forRoot(config) {
|
|
15
|
+
const configProvider = {
|
|
16
|
+
provide: entitlement_service_1.ENTITLEMENT_CLIENT_CONFIG,
|
|
17
|
+
useValue: config,
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
module: EntitlementClientModule_1,
|
|
21
|
+
global: true,
|
|
22
|
+
providers: [configProvider, entitlement_service_1.EntitlementService],
|
|
23
|
+
exports: [entitlement_service_1.EntitlementService],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static forRootAsync(options) {
|
|
27
|
+
const configProvider = {
|
|
28
|
+
provide: entitlement_service_1.ENTITLEMENT_CLIENT_CONFIG,
|
|
29
|
+
useFactory: options.useFactory,
|
|
30
|
+
inject: options.inject ?? [],
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
module: EntitlementClientModule_1,
|
|
34
|
+
global: true,
|
|
35
|
+
imports: options.imports ?? [],
|
|
36
|
+
providers: [configProvider, entitlement_service_1.EntitlementService],
|
|
37
|
+
exports: [entitlement_service_1.EntitlementService],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.EntitlementClientModule = EntitlementClientModule;
|
|
42
|
+
exports.EntitlementClientModule = EntitlementClientModule = EntitlementClientModule_1 = __decorate([
|
|
43
|
+
(0, common_1.Module)({})
|
|
44
|
+
], EntitlementClientModule);
|
|
45
|
+
//# sourceMappingURL=entitlement-client.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement-client.module.js","sourceRoot":"","sources":["../../src/lib/entitlement-client.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAOwB;AACxB,+DAI+B;AAwDxB,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAElC,MAAM,CAAC,OAAO,CAAC,MAA+B;QAC5C,MAAM,cAAc,GAAa;YAC/B,OAAO,EAAE,+CAAyB;YAClC,QAAQ,EAAE,MAAM;SACjB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,yBAAuB;YAC/B,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,CAAC,cAAc,EAAE,wCAAkB,CAAC;YAC/C,OAAO,EAAE,CAAC,wCAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;IAGD,MAAM,CAAC,YAAY,CACjB,OAA4C;QAE5C,MAAM,cAAc,GAAa;YAC/B,OAAO,EAAE,+CAAyB;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;SAC7B,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,yBAAuB;YAC/B,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS,EAAE,CAAC,cAAc,EAAE,wCAAkB,CAAC;YAC/C,OAAO,EAAE,CAAC,wCAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AAlCY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,uBAAuB,CAkCnC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CanActivate, type ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { EntitlementKey } from '@xemahq/entitlement-contracts';
|
|
4
|
+
import { EntitlementService } from './entitlement.service';
|
|
5
|
+
export declare const REQUIRE_ENTITLEMENT = "xema:require-entitlement";
|
|
6
|
+
export declare const RequireEntitlement: (key: EntitlementKey) => MethodDecorator & ClassDecorator;
|
|
7
|
+
export declare class EntitlementGuard implements CanActivate {
|
|
8
|
+
private readonly reflector;
|
|
9
|
+
private readonly entitlements;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
constructor(reflector: Reflector, entitlements: EntitlementService);
|
|
12
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=entitlement.guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.guard.d.ts","sourceRoot":"","sources":["../../src/lib/entitlement.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAMtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG3D,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAmB9D,eAAO,MAAM,kBAAkB,GAC7B,KAAK,cAAc,KAClB,eAAe,GAAG,cAAuD,CAAC;AAW7E,qBACa,gBAAiB,YAAW,WAAW;IAIhD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAJ/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;gBAGzC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB;IAG7C,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA0C/D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var EntitlementGuard_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.EntitlementGuard = exports.RequireEntitlement = exports.REQUIRE_ENTITLEMENT = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
16
|
+
const platform_common_1 = require("@xemahq/platform-common");
|
|
17
|
+
const entitlement_service_1 = require("./entitlement.service");
|
|
18
|
+
exports.REQUIRE_ENTITLEMENT = 'xema:require-entitlement';
|
|
19
|
+
const RequireEntitlement = (key) => (0, common_1.SetMetadata)(exports.REQUIRE_ENTITLEMENT, key);
|
|
20
|
+
exports.RequireEntitlement = RequireEntitlement;
|
|
21
|
+
let EntitlementGuard = EntitlementGuard_1 = class EntitlementGuard {
|
|
22
|
+
reflector;
|
|
23
|
+
entitlements;
|
|
24
|
+
logger = new common_1.Logger(EntitlementGuard_1.name);
|
|
25
|
+
constructor(reflector, entitlements) {
|
|
26
|
+
this.reflector = reflector;
|
|
27
|
+
this.entitlements = entitlements;
|
|
28
|
+
}
|
|
29
|
+
async canActivate(context) {
|
|
30
|
+
const key = this.reflector.getAllAndOverride(exports.REQUIRE_ENTITLEMENT, [context.getHandler(), context.getClass()]);
|
|
31
|
+
if (!key) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
const request = context.switchToHttp().getRequest();
|
|
35
|
+
const ctx = request[platform_common_1.REQUEST_CONTEXT];
|
|
36
|
+
if (!ctx) {
|
|
37
|
+
this.logger.error('RequestContext missing — EntitlementGuard requires ' +
|
|
38
|
+
'RequestContextMiddleware (configureAuthMiddleware).');
|
|
39
|
+
throw new common_1.InternalServerErrorException({
|
|
40
|
+
code: 'REQUEST_CONTEXT_MISSING',
|
|
41
|
+
message: 'Internal route misconfigured: missing request context.',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const entitled = await this.entitlements.isEntitled(ctx.orgId, key);
|
|
45
|
+
if (!entitled) {
|
|
46
|
+
this.logger.warn({
|
|
47
|
+
message: 'entitlement-denied',
|
|
48
|
+
route: `${request.method} ${request.originalUrl}`,
|
|
49
|
+
orgId: ctx.orgId,
|
|
50
|
+
actorId: ctx.actorId,
|
|
51
|
+
requiredEntitlement: key,
|
|
52
|
+
});
|
|
53
|
+
throw new common_1.ForbiddenException({
|
|
54
|
+
code: 'FEATURE_NOT_ENTITLED',
|
|
55
|
+
message: `This feature requires the '${key}' entitlement.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.EntitlementGuard = EntitlementGuard;
|
|
62
|
+
exports.EntitlementGuard = EntitlementGuard = EntitlementGuard_1 = __decorate([
|
|
63
|
+
(0, common_1.Injectable)(),
|
|
64
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
65
|
+
entitlement_service_1.EntitlementService])
|
|
66
|
+
], EntitlementGuard);
|
|
67
|
+
//# sourceMappingURL=entitlement.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.guard.js","sourceRoot":"","sources":["../../src/lib/entitlement.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAQwB;AACxB,uCAAyC;AAEzC,6DAA0D;AAG1D,+DAA2D;AAG9C,QAAA,mBAAmB,GAAG,0BAA0B,CAAC;AAmBvD,MAAM,kBAAkB,GAAG,CAChC,GAAmB,EACe,EAAE,CAAC,IAAA,oBAAW,EAAC,2BAAmB,EAAE,GAAG,CAAC,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AAE,GAAG,CAAC,OAAO;gBACpB,mBAAmB,EAAE,GAAG;aACzB,CAAC,CAAC;YACH,MAAM,IAAI,2BAAkB,CAAC;gBAC3B,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE,8BAA8B,GAAG,gBAAgB;aAC3D,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAlDY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAKmB,gBAAS;QACN,wCAAkB;GALxC,gBAAgB,CAkD5B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Edition, EntitlementKey, type EntitlementSet } from '@xemahq/entitlement-contracts';
|
|
2
|
+
export declare const ENTITLEMENT_CLIENT_CONFIG: unique symbol;
|
|
3
|
+
export interface EntitlementClientConfig {
|
|
4
|
+
deploymentCeiling: Edition;
|
|
5
|
+
identityApiUrl: string;
|
|
6
|
+
tokenProvider: () => Promise<string>;
|
|
7
|
+
cacheTtlMs?: number;
|
|
8
|
+
requestTimeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class EntitlementService {
|
|
11
|
+
private readonly config;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly cacheTtlMs;
|
|
14
|
+
private readonly requestTimeoutMs;
|
|
15
|
+
private readonly cache;
|
|
16
|
+
private readonly inflight;
|
|
17
|
+
constructor(config: EntitlementClientConfig);
|
|
18
|
+
isEntitled(orgId: string, key: EntitlementKey): Promise<boolean>;
|
|
19
|
+
getEffective(orgId: string): Promise<EntitlementSet>;
|
|
20
|
+
private resolve;
|
|
21
|
+
private fetchOrgEntitlement;
|
|
22
|
+
}
|
|
23
|
+
export declare function resolveDeploymentCeiling(rawEdition: string | undefined): Edition;
|
|
24
|
+
//# sourceMappingURL=entitlement.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.service.d.ts","sourceRoot":"","sources":["../../src/lib/entitlement.service.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAEP,cAAc,EACd,KAAK,cAAc,EAIpB,MAAM,+BAA+B,CAAC;AAIvC,eAAO,MAAM,yBAAyB,eAAsC,CAAC;AAQ7E,MAAM,WAAW,uBAAuB;IAOtC,iBAAiB,EAAE,OAAO,CAAC;IAG3B,cAAc,EAAE,MAAM,CAAC;IAOvB,aAAa,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAMrC,UAAU,CAAC,EAAE,MAAM,CAAC;IAMpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAsBD,qBACa,kBAAkB;IAa3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAZzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAI1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IAEvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8C;gBAIpD,MAAM,EAAE,uBAAuB;IAY5C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAUhE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;YAyB5C,OAAO;YAyBP,mBAAmB;CAsDlC;AAOD,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGhF"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var EntitlementService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.EntitlementService = exports.ENTITLEMENT_CLIENT_CONFIG = void 0;
|
|
17
|
+
exports.resolveDeploymentCeiling = resolveDeploymentCeiling;
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const entitlement_contracts_1 = require("@xemahq/entitlement-contracts");
|
|
20
|
+
exports.ENTITLEMENT_CLIENT_CONFIG = Symbol('ENTITLEMENT_CLIENT_CONFIG');
|
|
21
|
+
let EntitlementService = EntitlementService_1 = class EntitlementService {
|
|
22
|
+
config;
|
|
23
|
+
logger = new common_1.Logger(EntitlementService_1.name);
|
|
24
|
+
cacheTtlMs;
|
|
25
|
+
requestTimeoutMs;
|
|
26
|
+
cache = new Map();
|
|
27
|
+
inflight = new Map();
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
this.cacheTtlMs = config.cacheTtlMs ?? 60_000;
|
|
31
|
+
this.requestTimeoutMs = config.requestTimeoutMs ?? 5_000;
|
|
32
|
+
}
|
|
33
|
+
async isEntitled(orgId, key) {
|
|
34
|
+
const effective = await this.getEffective(orgId);
|
|
35
|
+
return (0, entitlement_contracts_1.isFeatureEntitled)(effective, key);
|
|
36
|
+
}
|
|
37
|
+
async getEffective(orgId) {
|
|
38
|
+
const cached = this.cache.get(orgId);
|
|
39
|
+
if (cached && Date.now() < cached.expiresAt) {
|
|
40
|
+
return cached.value;
|
|
41
|
+
}
|
|
42
|
+
const existing = this.inflight.get(orgId);
|
|
43
|
+
if (existing) {
|
|
44
|
+
return existing;
|
|
45
|
+
}
|
|
46
|
+
const promise = this.resolve(orgId).finally(() => {
|
|
47
|
+
this.inflight.delete(orgId);
|
|
48
|
+
});
|
|
49
|
+
this.inflight.set(orgId, promise);
|
|
50
|
+
return promise;
|
|
51
|
+
}
|
|
52
|
+
async resolve(orgId) {
|
|
53
|
+
const orgEntitlement = await this.fetchOrgEntitlement(orgId);
|
|
54
|
+
const effective = (0, entitlement_contracts_1.resolveEffectiveEntitlement)(this.config.deploymentCeiling, orgEntitlement);
|
|
55
|
+
this.cache.set(orgId, {
|
|
56
|
+
value: effective,
|
|
57
|
+
expiresAt: Date.now() + this.cacheTtlMs,
|
|
58
|
+
});
|
|
59
|
+
return effective;
|
|
60
|
+
}
|
|
61
|
+
async fetchOrgEntitlement(orgId) {
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
const timer = setTimeout(() => controller.abort(), this.requestTimeoutMs);
|
|
64
|
+
try {
|
|
65
|
+
const token = await this.config.tokenProvider();
|
|
66
|
+
const url = `${this.config.identityApiUrl}/internal/orgs/${encodeURIComponent(orgId)}/entitlements`;
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
70
|
+
signal: controller.signal,
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
if (response.status !== 404) {
|
|
74
|
+
this.logger.warn({
|
|
75
|
+
message: 'identity-api entitlement fetch returned non-2xx — failing closed to community',
|
|
76
|
+
orgId,
|
|
77
|
+
status: response.status,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const body = await response.json();
|
|
83
|
+
const parsed = entitlement_contracts_1.EntitlementSetSchema.safeParse(body);
|
|
84
|
+
if (!parsed.success) {
|
|
85
|
+
this.logger.warn({
|
|
86
|
+
message: 'identity-api entitlement payload failed schema validation — failing closed to community',
|
|
87
|
+
orgId,
|
|
88
|
+
});
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
return parsed.data;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.logger.warn({
|
|
95
|
+
message: 'identity-api entitlement fetch failed — failing closed to community',
|
|
96
|
+
orgId,
|
|
97
|
+
error: error instanceof Error ? error.message : String(error),
|
|
98
|
+
});
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
exports.EntitlementService = EntitlementService;
|
|
107
|
+
exports.EntitlementService = EntitlementService = EntitlementService_1 = __decorate([
|
|
108
|
+
(0, common_1.Injectable)(),
|
|
109
|
+
__param(0, (0, common_1.Inject)(exports.ENTITLEMENT_CLIENT_CONFIG)),
|
|
110
|
+
__metadata("design:paramtypes", [Object])
|
|
111
|
+
], EntitlementService);
|
|
112
|
+
function resolveDeploymentCeiling(rawEdition) {
|
|
113
|
+
const parsed = entitlement_contracts_1.EditionSchema.safeParse(rawEdition);
|
|
114
|
+
return parsed.success ? parsed.data : entitlement_contracts_1.Edition.Community;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=entitlement.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement.service.js","sourceRoot":"","sources":["../../src/lib/entitlement.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA4NA,4DAGC;AA/ND,2CAA4D;AAC5D,yEAQuC;AAI1B,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AA6DtE,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAaV;IAZF,MAAM,GAAG,IA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|
1
|
+
{
|
|
2
|
+
"name": "@xemahq/entitlement-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Layer-1 NestJS client for the Xema edition/entitlement primitive. EntitlementService resolves per-org entitlement against identity-api and applies the deployment ceiling (XEMA_EDITION) CLIENT-SIDE via @xemahq/entitlement-contracts, fail-closed to community on any error.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://npm.pkg.github.com"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@nestjs/common": ">=10",
|
|
15
|
+
"@nestjs/core": ">=10",
|
|
16
|
+
"reflect-metadata": ">=0.1.12"
|
|
17
|
+
},
|
|
18
|
+
"peerDependenciesMeta": {
|
|
19
|
+
"@nestjs/common": {
|
|
20
|
+
"optional": true
|
|
21
|
+
},
|
|
22
|
+
"@nestjs/core": {
|
|
23
|
+
"optional": true
|
|
24
|
+
},
|
|
25
|
+
"reflect-metadata": {
|
|
26
|
+
"optional": true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@xemahq/entitlement-contracts": "0.1.0",
|
|
31
|
+
"@xemahq/platform-common": "0.1.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@nestjs/common": "11.1.13",
|
|
35
|
+
"@nestjs/core": "11.1.13",
|
|
36
|
+
"@types/express": "5.0.3",
|
|
37
|
+
"@types/node": "25.2.3",
|
|
38
|
+
"prettier": "3.6.2",
|
|
39
|
+
"reflect-metadata": "0.2.2",
|
|
40
|
+
"typescript": "5.9.3"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"xema-source": "./src/index.ts",
|
|
46
|
+
"default": "./dist/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./dist/lib/*": {
|
|
49
|
+
"types": "./dist/lib/*.d.ts",
|
|
50
|
+
"default": "./dist/lib/*.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"clean": "rm -rf dist",
|
|
55
|
+
"build": "tsc -p tsconfig.json",
|
|
56
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
58
|
+
}
|
|
59
|
+
}
|