@xemahq/entitlement-client 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  <path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#8B5CF6"/>
7
7
  </g>
8
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>
9
+ <text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">NestJS enforcement point for Xema entitlement, resolved offline from a license.</text>
10
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
11
  </svg>
12
12
  </p>
@@ -24,23 +24,33 @@
24
24
 
25
25
  # @xemahq/entitlement-client
26
26
 
27
- > NestJS client that resolves per-org entitlements.
27
+ > NestJS enforcement point for Xema entitlement, resolved offline from a license.
28
28
 
29
29
  ## Overview
30
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.
31
+ The platform's enforcement point for entitlement. It resolves the installation's
32
+ Xema license **offline** with `@xemahq/license-verifier` — no network call, no
33
+ service to be reachable, identical behaviour on a connected control plane and on
34
+ an air-gapped appliance — and answers both entitlement faces from that one
35
+ source:
36
+
37
+ - **the license axis** — `requireEntitled` / `requireBiomeInstallEntitled` /
38
+ `requireEditionEntitled`, gating biome installation and the running edition
39
+ over `{ distribution | biome | capability-class }`;
40
+ - **the platform axis** — `isEntitled` / `getEffective`, the `Edition` plus the
41
+ closed `EntitlementKey` feature flags, projected from the same license by
42
+ `@xemahq/kernel-contracts/entitlement`.
43
+
44
+ It is fail-closed: an unverifiable license grants nothing, and a license in
45
+ force grants only what it enumerates. It never fails *fast* at boot — expiry
46
+ degrades what may be done next and never stops a running workload.
37
47
 
38
48
  ## When to use it
39
49
 
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.
50
+ - Use it inside a NestJS service that gates a NEW action (installing a biome,
51
+ an upgrade, provisioning an org) or an enterprise-only feature.
52
+ - Reach for `@xemahq/license-verifier` directly when you need offline license
53
+ verification with no NestJS container at all.
44
54
 
45
55
  ## Installation
46
56
 
@@ -51,12 +61,21 @@ pnpm add @xemahq/entitlement-client
51
61
  ## Usage
52
62
 
53
63
  ```ts
54
- import { EntitlementService } from '@xemahq/entitlement-client';
64
+ import {
65
+ EntitlementClientModule,
66
+ EntitlementService,
67
+ readLicenseFromEnv,
68
+ } from '@xemahq/entitlement-client';
69
+
70
+ EntitlementClientModule.forRoot({
71
+ customerLicense: readLicenseFromEnv(), // XEMA_LICENSE; undefined ⇒ the OSS license
72
+ distributionId: 'core', // what this deployment actually runs
73
+ });
55
74
 
56
75
  constructor(private readonly entitlements: EntitlementService) {}
57
76
 
58
- async canUse(orgId: string, key: EntitlementKey): Promise<boolean> {
59
- return this.entitlements.isEntitled(orgId, key);
77
+ installBiome(biomeId: string): void {
78
+ this.entitlements.requireBiomeInstallEntitled(biomeId); // 403 when unentitled
60
79
  }
61
80
  ```
62
81
 
@@ -64,6 +83,7 @@ async canUse(orgId: string, key: EntitlementKey): Promise<boolean> {
64
83
 
65
84
  - `@nestjs/common` and `@nestjs/core` >= 10
66
85
  - `reflect-metadata` >= 0.1.12
86
+ - `@xemahq/kernel-contracts` and `@xemahq/license-verifier`
67
87
 
68
88
  ## License
69
89
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- export * from './lib/entitlement.service';
2
- export * from './lib/entitlement-client.module';
3
- export * from './lib/entitlement.guard';
1
+ export * from './lib/entitlement.service.ts';
2
+ export * from './lib/entitlement-client.module.ts';
3
+ export * from './lib/entitlement.guard.ts';
4
+ export * from './lib/installation-license.ts';
5
+ export * from './lib/license-refused.exception.ts';
6
+ export * from './lib/license-warnings.ts';
7
+ export { EntitlementAction, EntitlementDenialReason, EntitlementKind, LicenseLifecycleStage, LicenseSource, LicenseStatus, LicenseTier, LicenseVerificationFailureCode, LICENSE_GRACE_PERIOD_MS, type EntitlementQuery, type LicenseEntitlement, type LicenseState, type LicenseTrustStore, type VerifiedLicense, } from '@xemahq/license-verifier';
4
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,2BAA2B,CAAC;AAQ1C,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,WAAW,EACX,8BAA8B,EAC9B,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACrB,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -14,7 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
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);
17
+ exports.LICENSE_GRACE_PERIOD_MS = exports.LicenseVerificationFailureCode = exports.LicenseTier = exports.LicenseStatus = exports.LicenseSource = exports.LicenseLifecycleStage = exports.EntitlementKind = exports.EntitlementDenialReason = exports.EntitlementAction = void 0;
18
+ __exportStar(require("./lib/entitlement.service.js"), exports);
19
+ __exportStar(require("./lib/entitlement-client.module.js"), exports);
20
+ __exportStar(require("./lib/entitlement.guard.js"), exports);
21
+ __exportStar(require("./lib/installation-license.js"), exports);
22
+ __exportStar(require("./lib/license-refused.exception.js"), exports);
23
+ __exportStar(require("./lib/license-warnings.js"), exports);
24
+ var license_verifier_1 = require("@xemahq/license-verifier");
25
+ Object.defineProperty(exports, "EntitlementAction", { enumerable: true, get: function () { return license_verifier_1.EntitlementAction; } });
26
+ Object.defineProperty(exports, "EntitlementDenialReason", { enumerable: true, get: function () { return license_verifier_1.EntitlementDenialReason; } });
27
+ Object.defineProperty(exports, "EntitlementKind", { enumerable: true, get: function () { return license_verifier_1.EntitlementKind; } });
28
+ Object.defineProperty(exports, "LicenseLifecycleStage", { enumerable: true, get: function () { return license_verifier_1.LicenseLifecycleStage; } });
29
+ Object.defineProperty(exports, "LicenseSource", { enumerable: true, get: function () { return license_verifier_1.LicenseSource; } });
30
+ Object.defineProperty(exports, "LicenseStatus", { enumerable: true, get: function () { return license_verifier_1.LicenseStatus; } });
31
+ Object.defineProperty(exports, "LicenseTier", { enumerable: true, get: function () { return license_verifier_1.LicenseTier; } });
32
+ Object.defineProperty(exports, "LicenseVerificationFailureCode", { enumerable: true, get: function () { return license_verifier_1.LicenseVerificationFailureCode; } });
33
+ Object.defineProperty(exports, "LICENSE_GRACE_PERIOD_MS", { enumerable: true, get: function () { return license_verifier_1.LICENSE_GRACE_PERIOD_MS; } });
20
34
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,kEAAgD;AAChD,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,qEAAmD;AACnD,6DAA2C;AAC3C,gEAA8C;AAC9C,qEAAmD;AACnD,4DAA0C;AAQ1C,6DAekC;AAdhC,qHAAA,iBAAiB,OAAA;AACjB,2HAAA,uBAAuB,OAAA;AACvB,mHAAA,eAAe,OAAA;AACf,yHAAA,qBAAqB,OAAA;AACrB,iHAAA,aAAa,OAAA;AACb,iHAAA,aAAa,OAAA;AACb,+GAAA,WAAW,OAAA;AACX,kIAAA,8BAA8B,OAAA;AAC9B,2HAAA,uBAAuB,OAAA"}
@@ -1,5 +1,5 @@
1
1
  import { type DynamicModule, type ForwardReference, type InjectionToken, type Type } from '@nestjs/common';
2
- import { type EntitlementClientConfig } from './entitlement.service';
2
+ import { type EntitlementClientConfig } from './entitlement.service.ts';
3
3
  type ModuleImport = Type<unknown> | ForwardReference<unknown> | DynamicModule | Promise<DynamicModule>;
4
4
  export interface EntitlementClientModuleAsyncOptions {
5
5
  imports?: ModuleImport[];
@@ -1 +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"}
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,0BAA0B,CAAC;AAElC,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;AA+BD,qBACa,uBAAuB;IAElC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,uBAAuB,GAAG,aAAa;IAe9D,MAAM,CAAC,YAAY,CACjB,OAAO,EAAE,mCAAmC,GAC3C,aAAa;CAejB"}
@@ -9,23 +9,23 @@ var EntitlementClientModule_1;
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.EntitlementClientModule = void 0;
11
11
  const common_1 = require("@nestjs/common");
12
- const entitlement_service_1 = require("./entitlement.service");
12
+ const entitlement_service_ts_1 = require("./entitlement.service.js");
13
13
  let EntitlementClientModule = EntitlementClientModule_1 = class EntitlementClientModule {
14
14
  static forRoot(config) {
15
15
  const configProvider = {
16
- provide: entitlement_service_1.ENTITLEMENT_CLIENT_CONFIG,
16
+ provide: entitlement_service_ts_1.ENTITLEMENT_CLIENT_CONFIG,
17
17
  useValue: config,
18
18
  };
19
19
  return {
20
20
  module: EntitlementClientModule_1,
21
21
  global: true,
22
- providers: [configProvider, entitlement_service_1.EntitlementService],
23
- exports: [entitlement_service_1.EntitlementService],
22
+ providers: [configProvider, entitlement_service_ts_1.EntitlementService],
23
+ exports: [entitlement_service_ts_1.EntitlementService],
24
24
  };
25
25
  }
26
26
  static forRootAsync(options) {
27
27
  const configProvider = {
28
- provide: entitlement_service_1.ENTITLEMENT_CLIENT_CONFIG,
28
+ provide: entitlement_service_ts_1.ENTITLEMENT_CLIENT_CONFIG,
29
29
  useFactory: options.useFactory,
30
30
  inject: options.inject ?? [],
31
31
  };
@@ -33,8 +33,8 @@ let EntitlementClientModule = EntitlementClientModule_1 = class EntitlementClien
33
33
  module: EntitlementClientModule_1,
34
34
  global: true,
35
35
  imports: options.imports ?? [],
36
- providers: [configProvider, entitlement_service_1.EntitlementService],
37
- exports: [entitlement_service_1.EntitlementService],
36
+ providers: [configProvider, entitlement_service_ts_1.EntitlementService],
37
+ exports: [entitlement_service_ts_1.EntitlementService],
38
38
  };
39
39
  }
40
40
  };
@@ -1 +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,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E,2CAAkB,CAAC;YAC/C,OAAO,EAAE,CAAC,2CAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;IAGD,MAAM,CAAC,YAAY,CACjB,OAA4C;QAE5C,MAAM,cAAc,GAAa;YAC/B,OAAO,EAAE,kDAAyB;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,2CAAkB,CAAC;YAC/C,OAAO,EAAE,CAAC,2CAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AAlCY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,uBAAuB,CAkCnC"}
@@ -1,7 +1,7 @@
1
1
  import { type CanActivate, type ExecutionContext } from '@nestjs/common';
2
2
  import { Reflector } from '@nestjs/core';
3
3
  import { EntitlementKey } from '@xemahq/kernel-contracts/entitlement';
4
- import { EntitlementService } from './entitlement.service';
4
+ import { EntitlementService } from './entitlement.service.ts';
5
5
  export declare const REQUIRE_ENTITLEMENT = "xema:require-entitlement";
6
6
  export declare const RequireEntitlement: (key: EntitlementKey) => MethodDecorator & ClassDecorator;
7
7
  export declare class EntitlementGuard implements CanActivate {
@@ -1 +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,sCAAsC,CAAC;AAItE,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"}
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,sCAAsC,CAAC;AAItE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAmB9D,eAAO,MAAM,kBAAkB,GAC7B,KAAK,cAAc,KAClB,eAAe,GAAG,cAAuD,CAAC;AAkB7E,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"}
@@ -14,7 +14,7 @@ exports.EntitlementGuard = exports.RequireEntitlement = exports.REQUIRE_ENTITLEM
14
14
  const common_1 = require("@nestjs/common");
15
15
  const core_1 = require("@nestjs/core");
16
16
  const platform_common_1 = require("@xemahq/platform-common");
17
- const entitlement_service_1 = require("./entitlement.service");
17
+ const entitlement_service_ts_1 = require("./entitlement.service.js");
18
18
  exports.REQUIRE_ENTITLEMENT = 'xema:require-entitlement';
19
19
  const RequireEntitlement = (key) => (0, common_1.SetMetadata)(exports.REQUIRE_ENTITLEMENT, key);
20
20
  exports.RequireEntitlement = RequireEntitlement;
@@ -62,6 +62,6 @@ exports.EntitlementGuard = EntitlementGuard;
62
62
  exports.EntitlementGuard = EntitlementGuard = EntitlementGuard_1 = __decorate([
63
63
  (0, common_1.Injectable)(),
64
64
  __metadata("design:paramtypes", [core_1.Reflector,
65
- entitlement_service_1.EntitlementService])
65
+ entitlement_service_ts_1.EntitlementService])
66
66
  ], EntitlementGuard);
67
67
  //# sourceMappingURL=entitlement.guard.js.map
@@ -1 +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,CAAC;AAFhE,QAAA,kBAAkB,sBAE8C;AAYtE,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAIR;IACA;IAJF,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IAE5D,YACmB,SAAoB,EACpB,YAAgC;QADhC,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAoB;IAChD,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC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AAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACf,OAAO,EAAE,oBAAoB;gBAC7B,KAAK,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,WAAW,EAAE;gBACjD,KAAK,EAAE,GAAG,CAAC,KAAK;gBAChB,OAAO,EAAE,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,2CAAkB;GALxC,gBAAgB,CAkD5B"}
@@ -1,24 +1,23 @@
1
- import { Edition, EntitlementKey, type EntitlementSet } from '@xemahq/kernel-contracts/entitlement';
1
+ import { type OnModuleInit } from '@nestjs/common';
2
+ import { type EntitlementKey, type EntitlementSet } from '@xemahq/kernel-contracts/entitlement';
3
+ import { type EntitlementQuery } from '@xemahq/license-verifier';
4
+ import { type InstallationLicenseConfig, type LicenseEvaluationOptions, type LicenseGateOutcome, type LicensePosture } from './installation-license.ts';
2
5
  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;
6
+ export type EntitlementClientConfig = InstallationLicenseConfig;
7
+ export declare class EntitlementService implements OnModuleInit {
12
8
  private readonly logger;
13
- private readonly cacheTtlMs;
14
- private readonly requestTimeoutMs;
15
- private readonly cache;
16
- private readonly inflight;
9
+ private readonly installation;
17
10
  constructor(config: EntitlementClientConfig);
11
+ onModuleInit(): void;
12
+ evaluate(query: EntitlementQuery, options?: LicenseEvaluationOptions): LicenseGateOutcome;
13
+ requireEntitled(query: EntitlementQuery, options?: LicenseEvaluationOptions): void;
14
+ biomeInstallGate(biomeId: string, options?: LicenseEvaluationOptions): LicenseGateOutcome;
15
+ requireEditionEntitled(options?: LicenseEvaluationOptions): void;
16
+ requireBiomeInstallEntitled(biomeId: string, options?: LicenseEvaluationOptions): void;
17
+ private enforce;
18
+ getPosture(options?: LicenseEvaluationOptions): LicensePosture;
18
19
  isEntitled(orgId: string, key: EntitlementKey): Promise<boolean>;
19
- getEffective(orgId: string): Promise<EntitlementSet>;
20
- private resolve;
21
- private fetchOrgEntitlement;
20
+ getEffective(orgId: string, options?: LicenseEvaluationOptions): EntitlementSet;
22
21
  }
23
- export declare function resolveDeploymentCeiling(rawEdition: string | undefined): Edition;
22
+ export declare function readLicenseFromEnv(env?: NodeJS.ProcessEnv): string | undefined;
24
23
  //# sourceMappingURL=entitlement.service.d.ts.map
@@ -1 +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,sCAAsC,CAAC;AAI9C,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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N,KAAK,EAAE,gBAAgB,EACvB,OAAO,GAAE,wBAA6B,GACrC,kBAAkB;IAarB,eAAe,CACb,KAAK,EAAE,gBAAgB,EACvB,OAAO,GAAE,wBAA6B,GACrC,IAAI;IAaP,gBAAgB,CACd,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,wBAA6B,GACrC,kBAAkB;IAarB,sBAAsB,CAAC,OAAO,GAAE,wBAA6B,GAAG,IAAI;IAiBpE,2BAA2B,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,wBAA6B,GACrC,IAAI;IASP,OAAO,CAAC,OAAO;IAef,UAAU,CAAC,OAAO,GAAE,wBAA6B,GAAG,cAAc;IAiB5D,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBtE,YAAY,CACV,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,wBAA6B,GACrC,cAAc;CASlB;AAUD,wBAAgB,kBAAkB,CAChC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,GAAG,SAAS,CAGpB"}
@@ -14,93 +14,117 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  var EntitlementService_1;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.EntitlementService = exports.ENTITLEMENT_CLIENT_CONFIG = void 0;
17
- exports.resolveDeploymentCeiling = resolveDeploymentCeiling;
17
+ exports.readLicenseFromEnv = readLicenseFromEnv;
18
18
  const common_1 = require("@nestjs/common");
19
19
  const entitlement_1 = require("@xemahq/kernel-contracts/entitlement");
20
+ const license_verifier_1 = require("@xemahq/license-verifier");
21
+ const installation_license_ts_1 = require("./installation-license.js");
22
+ const license_refused_exception_ts_1 = require("./license-refused.exception.js");
23
+ const license_warnings_ts_1 = require("./license-warnings.js");
20
24
  exports.ENTITLEMENT_CLIENT_CONFIG = Symbol('ENTITLEMENT_CLIENT_CONFIG');
21
25
  let EntitlementService = EntitlementService_1 = class EntitlementService {
22
- config;
23
26
  logger = new common_1.Logger(EntitlementService_1.name);
24
- cacheTtlMs;
25
- requestTimeoutMs;
26
- cache = new Map();
27
- inflight = new Map();
27
+ installation;
28
28
  constructor(config) {
29
- this.config = config;
30
- this.cacheTtlMs = config.cacheTtlMs ?? 60_000;
31
- this.requestTimeoutMs = config.requestTimeoutMs ?? 5_000;
29
+ this.installation = new installation_license_ts_1.InstallationLicense(config);
32
30
  }
33
- async isEntitled(orgId, key) {
34
- const effective = await this.getEffective(orgId);
35
- return (0, entitlement_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;
31
+ onModuleInit() {
32
+ const posture = this.getPosture();
33
+ const severity = (0, installation_license_ts_1.worstWarningSeverity)(posture.warnings);
34
+ if (posture.licensed) {
35
+ this.logger.log({
36
+ message: 'license resolved',
37
+ source: posture.source,
38
+ licenseId: posture.licenseId,
39
+ customerId: posture.customerId,
40
+ tier: posture.tier,
41
+ status: posture.state.status,
42
+ stage: posture.state.stage,
43
+ edition: posture.entitlement.edition,
44
+ distributionId: posture.distributionId,
45
+ distributionEntitled: posture.distributionEntitled,
46
+ });
41
47
  }
42
- const existing = this.inflight.get(orgId);
43
- if (existing) {
44
- return existing;
48
+ else {
49
+ this.logger.error({
50
+ message: `no Xema license could be verified — enterprise features are off ` +
51
+ `and new biome installs will be refused. Supply one via the ` +
52
+ `${installation_license_ts_1.LICENSE_ENV_VAR} environment variable.`,
53
+ source: posture.source,
54
+ code: posture.code,
55
+ detail: posture.message,
56
+ remediation: posture.remediation,
57
+ });
45
58
  }
46
- const promise = this.resolve(orgId).finally(() => {
47
- this.inflight.delete(orgId);
48
- });
49
- this.inflight.set(orgId, promise);
50
- return promise;
59
+ for (const warning of posture.warnings) {
60
+ const line = { message: warning.message, code: warning.code };
61
+ if (warning.severity === license_warnings_ts_1.LicenseWarningSeverity.Critical) {
62
+ this.logger.error(line);
63
+ }
64
+ else {
65
+ this.logger.warn(line);
66
+ }
67
+ }
68
+ if (severity === undefined && posture.licensed) {
69
+ this.logger.log('license posture: healthy');
70
+ }
71
+ }
72
+ evaluate(query, options = {}) {
73
+ return this.installation.evaluate(query, options);
74
+ }
75
+ requireEntitled(query, options = {}) {
76
+ this.enforce(this.evaluate(query, options), query);
77
+ }
78
+ biomeInstallGate(biomeId, options = {}) {
79
+ return this.installation.biomeInstallGate(biomeId, options);
80
+ }
81
+ requireEditionEntitled(options = {}) {
82
+ this.enforce(this.installation.editionGate(options), this.installation.editionQuery() ?? undefined);
51
83
  }
52
- async resolve(orgId) {
53
- const orgEntitlement = await this.fetchOrgEntitlement(orgId);
54
- const effective = (0, entitlement_1.resolveEffectiveEntitlement)(this.config.deploymentCeiling, orgEntitlement);
55
- this.cache.set(orgId, {
56
- value: effective,
57
- expiresAt: Date.now() + this.cacheTtlMs,
84
+ requireBiomeInstallEntitled(biomeId, options = {}) {
85
+ this.enforce(this.installation.biomeInstallGate(biomeId, options), {
86
+ kind: license_verifier_1.EntitlementKind.Biome,
87
+ id: biomeId,
88
+ action: license_verifier_1.EntitlementAction.Install,
58
89
  });
59
- return effective;
60
90
  }
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_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;
91
+ enforce(outcome, query) {
92
+ if (outcome.granted) {
93
+ return;
92
94
  }
93
- catch (error) {
94
- this.logger.warn({
95
- message: 'identity-api entitlement fetch failed — failing closed to community',
95
+ this.logger.warn({
96
+ message: 'license-refused',
97
+ ...(query === undefined
98
+ ? {}
99
+ : { kind: query.kind, id: query.id, action: query.action }),
100
+ refusal: outcome.refusal,
101
+ });
102
+ throw new license_refused_exception_ts_1.LicenseRefusedException(outcome.refusal, query);
103
+ }
104
+ getPosture(options = {}) {
105
+ return this.installation.posture(options);
106
+ }
107
+ async isEntitled(orgId, key) {
108
+ const effective = this.getEffective(orgId);
109
+ const entitled = (0, entitlement_1.isFeatureEntitled)(effective, key);
110
+ if (!entitled) {
111
+ this.logger.debug({
112
+ message: 'feature-not-entitled',
96
113
  orgId,
97
- error: error instanceof Error ? error.message : String(error),
114
+ key,
115
+ edition: effective.edition,
98
116
  });
99
- return undefined;
100
- }
101
- finally {
102
- clearTimeout(timer);
103
117
  }
118
+ return entitled;
119
+ }
120
+ getEffective(orgId, options = {}) {
121
+ const effective = this.installation.entitlementSet(options);
122
+ this.logger.debug({
123
+ message: 'entitlement-resolved',
124
+ orgId,
125
+ edition: effective.edition,
126
+ });
127
+ return effective;
104
128
  }
105
129
  };
106
130
  exports.EntitlementService = EntitlementService;
@@ -109,8 +133,8 @@ exports.EntitlementService = EntitlementService = EntitlementService_1 = __decor
109
133
  __param(0, (0, common_1.Inject)(exports.ENTITLEMENT_CLIENT_CONFIG)),
110
134
  __metadata("design:paramtypes", [Object])
111
135
  ], EntitlementService);
112
- function resolveDeploymentCeiling(rawEdition) {
113
- const parsed = entitlement_1.EditionSchema.safeParse(rawEdition);
114
- return parsed.success ? parsed.data : entitlement_1.Edition.Community;
136
+ function readLicenseFromEnv(env = process.env) {
137
+ const raw = env[installation_license_ts_1.LICENSE_ENV_VAR]?.trim();
138
+ return raw === undefined || raw.length === 0 ? undefined : raw;
115
139
  }
116
140
  //# sourceMappingURL=entitlement.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entitlement.service.js","sourceRoot":"","sources":["../../src/lib/entitlement.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA4NA,4DAGC;AA/ND,2CAA4D;AAC5D,sEAQ8C;AAIjC,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AA6DtE,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAaV;IAZF,MAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;IAC7C,UAAU,CAAS;IACnB,gBAAgB,CAAS;IAIzB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEtC,QAAQ,GAAG,IAAI,GAAG,EAAmC,CAAC;IAEvE,YAEmB,MAA+B;QAA/B,WAAM,GAAN,MAAM,CAAyB;QAEhD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC;QAC9C,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,KAAK,CAAC;IAC3D,CAAC;IAQD,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,GAAmB;QACjD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,IAAA,+BAAiB,EAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IAOD,KAAK,CAAC,YAAY,CAAC,KAAa;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;YAC5C,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC;QAED,MAAM,QAAQ,GAAG,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,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;AACjE,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { type EntitlementSet } from '@xemahq/kernel-contracts/entitlement';
2
+ import { EntitlementDenialReason, LicenseSource, LicenseVerificationFailureCode, type EntitlementQuery, type LicenseEntitlement, type LicenseState, type LicenseTier, type LicenseTrustStore, type VerifiedLicense } from '@xemahq/license-verifier';
3
+ import { LicenseWarningSeverity, type LicenseWarning } from './license-warnings.ts';
4
+ export declare const LICENSE_ENV_VAR = "XEMA_LICENSE";
5
+ export interface InstallationLicenseConfig {
6
+ readonly customerLicense: string | undefined;
7
+ readonly distributionId: string | null;
8
+ readonly trustStore?: LicenseTrustStore;
9
+ }
10
+ export interface LicenseEvaluationOptions {
11
+ readonly now?: number;
12
+ }
13
+ export declare enum LicenseRefusalKind {
14
+ Unverifiable = "unverifiable",
15
+ NotEntitled = "not-entitled",
16
+ DistributionUndeclared = "distribution-undeclared"
17
+ }
18
+ export interface LicenseUnverifiableRefusal {
19
+ readonly kind: LicenseRefusalKind.Unverifiable;
20
+ readonly code: LicenseVerificationFailureCode;
21
+ readonly message: string;
22
+ readonly remediation: string;
23
+ }
24
+ export interface LicenseNotEntitledRefusal {
25
+ readonly kind: LicenseRefusalKind.NotEntitled;
26
+ readonly reason: EntitlementDenialReason;
27
+ readonly state: LicenseState;
28
+ }
29
+ export interface LicenseDistributionUndeclaredRefusal {
30
+ readonly kind: LicenseRefusalKind.DistributionUndeclared;
31
+ readonly remediation: string;
32
+ }
33
+ export type LicenseRefusal = LicenseUnverifiableRefusal | LicenseNotEntitledRefusal | LicenseDistributionUndeclaredRefusal;
34
+ export declare const DISTRIBUTION_UNDECLARED_REFUSAL: LicenseDistributionUndeclaredRefusal;
35
+ export type LicenseGateOutcome = {
36
+ readonly granted: true;
37
+ readonly matched: LicenseEntitlement;
38
+ readonly state: LicenseState;
39
+ } | {
40
+ readonly granted: false;
41
+ readonly refusal: LicenseRefusal;
42
+ };
43
+ export type LicensePosture = {
44
+ readonly licensed: true;
45
+ readonly source: LicenseSource;
46
+ readonly licenseId: string;
47
+ readonly customerId: string;
48
+ readonly customerName: string;
49
+ readonly tier: LicenseTier;
50
+ readonly state: LicenseState;
51
+ readonly entitlement: EntitlementSet;
52
+ readonly distributionId: string | null;
53
+ readonly distributionEntitled: boolean;
54
+ readonly warnings: readonly LicenseWarning[];
55
+ } | {
56
+ readonly licensed: false;
57
+ readonly source: LicenseSource;
58
+ readonly code: LicenseVerificationFailureCode;
59
+ readonly message: string;
60
+ readonly remediation: string;
61
+ readonly entitlement: EntitlementSet;
62
+ readonly distributionId: string | null;
63
+ readonly distributionEntitled: false;
64
+ readonly warnings: readonly LicenseWarning[];
65
+ };
66
+ export declare class InstallationLicense {
67
+ private readonly config;
68
+ private verification;
69
+ private highestObservedTimeMs;
70
+ constructor(config: InstallationLicenseConfig);
71
+ evaluate(query: EntitlementQuery, options?: LicenseEvaluationOptions): LicenseGateOutcome;
72
+ entitlementSet(options?: LicenseEvaluationOptions): EntitlementSet;
73
+ editionQuery(): EntitlementQuery | null;
74
+ editionGate(options?: LicenseEvaluationOptions): LicenseGateOutcome;
75
+ biomeInstallGate(biomeId: string, options?: LicenseEvaluationOptions): LicenseGateOutcome;
76
+ distributionEntitled(options?: LicenseEvaluationOptions): boolean;
77
+ posture(options?: LicenseEvaluationOptions): LicensePosture;
78
+ verifiedLicense(): VerifiedLicense | undefined;
79
+ private effective;
80
+ private stateOptions;
81
+ private observe;
82
+ }
83
+ export declare function worstWarningSeverity(warnings: readonly LicenseWarning[]): LicenseWarningSeverity | undefined;
84
+ export declare function isUnprovisionedBuildRefusal(refusal: LicenseRefusal): boolean;
85
+ //# sourceMappingURL=installation-license.d.ts.map