@xemahq/org-erasure-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 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,116 @@
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/org-erasure-nest">
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/org-erasure-nest</text>
9
+ <text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">The org-erasure participant contract and its fenced endpoint</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> &middot;
16
+ <a href="https://www.npmjs.com/package/@xemahq/org-erasure-nest">npm</a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Forg-erasure-nest?color=2563eb&label=npm">
21
+ <img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Forg-erasure-nest?color=10b981">
22
+ <img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Forg-erasure-nest?color=3178c6">
23
+ </p>
24
+
25
+ # @xemahq/org-erasure-nest
26
+
27
+ > The org-erasure participant contract, its fenced internal endpoint, and the protected-organization guard
28
+
29
+ ## Overview
30
+
31
+ An **org-erasure participant** is any service that holds an organisation's data
32
+ and can be told to destroy it. An orchestrator discovers participants from the
33
+ service registry by a declared capability and fans out to one internal route on
34
+ each of them.
35
+
36
+ This package is the participant half of that contract, and nothing else:
37
+
38
+ - the two protocol strings — the capability a participant declares, and the
39
+ route path the orchestrator POSTs to;
40
+ - `OrgErasureController`, the route, behind **two independent fences**;
41
+ - `OrgProtectionGuard` and its identity probe, which answer *may this
42
+ organisation be destroyed at all?* and fail **closed** on every uncertainty;
43
+ - `OrgErasureEndpointModule.forRunner(...)`, which mounts the route over an
44
+ eraser you supply.
45
+
46
+ It deliberately knows nothing about storage. The Prisma-backed eraser — walk
47
+ every model carrying the org column and delete its rows in an FK-safe order —
48
+ lives in `@xemahq/biome-database-nest`, which composes this package.
49
+
50
+ ## Install
51
+
52
+ ```sh
53
+ pnpm add @xemahq/org-erasure-nest
54
+ ```
55
+
56
+ Peers: `@nestjs/common`, `@nestjs/core`, `@nestjs/swagger`,
57
+ `@xemahq/identity-client`, `@xemahq/kernel-contracts`,
58
+ `@xemahq/platform-common`, `@xemahq/service-registry-nest`,
59
+ `@xemahq/xema-decorators`.
60
+
61
+ ## Usage
62
+
63
+ A participant whose data Prisma cannot reach supplies its own eraser:
64
+
65
+ ```ts
66
+ import { OrgErasureEndpointModule } from '@xemahq/org-erasure-nest';
67
+
68
+ @Module({
69
+ imports: [
70
+ OrgErasureEndpointModule.forRunner({
71
+ useFactory: (cache: CacheClient) => ({
72
+ erase: async (orgId) => cache.dropOrgNamespace(orgId),
73
+ }),
74
+ inject: [CacheClient],
75
+ }),
76
+ ],
77
+ })
78
+ export class AppModule {}
79
+ ```
80
+
81
+ A participant that stores rows in Postgres uses the Prisma binding instead:
82
+
83
+ ```ts
84
+ import { OrgErasureModule } from '@xemahq/biome-database-nest';
85
+
86
+ imports: [OrgErasureModule.forRoot({ prismaServiceToken: PrismaService })];
87
+ ```
88
+
89
+ Either way the service must declare `ORG_DATA_ERASURE_CAPABILITY` in its
90
+ service descriptor, or the orchestrator will never find it.
91
+
92
+ ## Two fences, and why both
93
+
94
+ | guard | answers |
95
+ | --- | --- |
96
+ | `ServiceActorGuard` | is the caller a non-delegated **service**? |
97
+ | `OrgProtectionGuard` | may this **organisation** be destroyed at all? |
98
+
99
+ Neither substitutes for the other. `ServiceActorGuard` proves *a* service token,
100
+ not *which* service, so any service in the fleet reaches this route directly —
101
+ which is why an orchestrator-side protection check cannot be the only one.
102
+
103
+ `OrgProtectionGuard` **fails closed** on every uncertainty: an unreachable or
104
+ non-2xx identity service, a malformed body, a record without a boolean
105
+ protection field, or an organisation that does not resolve in any realm this
106
+ service can see. Erasure is irreversible; a wrongful refusal costs one retry.
107
+
108
+ The guard injects only tokens the platform bootstrap exports globally and builds
109
+ its own probe, so it arms identically whether the endpoint is mounted through
110
+ `forRunner` or declared in a module of your own. A service that has not wired
111
+ the platform bootstrap refuses to **start**, with a named error, rather than
112
+ serving an unfenced irreversible route.
113
+
114
+ ## Licence
115
+
116
+ Apache-2.0
@@ -0,0 +1,4 @@
1
+ export { ORG_DATA_ERASURE_CAPABILITY, ORG_ERASURE_ROUTE_PATH, ORG_ERASURE_RUNNER, type OrgErasureReport, type OrgErasureRunner, } from './lib/org-erasure-contract';
2
+ export { OrgErasureController, OrgErasureEndpointModule, type OrgErasureEndpointModuleOptions, } from './lib/org-erasure-endpoint.module';
3
+ export { assertOrgNotProtected, assertOrgProtectionArmable, IdentityOrgProtectionProbe, IDENTITY_SERVICE_NAME, ORGANIZATION_PROTECTED_ERROR_CODE, OrgProtectionGuard, OrgProtectionUnavailableError, ProtectedOrgErasureRefusedError, type OrgProtectionProbe, } from './lib/org-protection';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,+BAA+B,GACrC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,iCAAiC,EACjC,kBAAkB,EAClB,6BAA6B,EAC7B,+BAA+B,EAC/B,KAAK,kBAAkB,GACxB,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProtectedOrgErasureRefusedError = exports.OrgProtectionUnavailableError = exports.OrgProtectionGuard = exports.ORGANIZATION_PROTECTED_ERROR_CODE = exports.IDENTITY_SERVICE_NAME = exports.IdentityOrgProtectionProbe = exports.assertOrgProtectionArmable = exports.assertOrgNotProtected = exports.OrgErasureEndpointModule = exports.OrgErasureController = exports.ORG_ERASURE_RUNNER = exports.ORG_ERASURE_ROUTE_PATH = exports.ORG_DATA_ERASURE_CAPABILITY = void 0;
4
+ var org_erasure_contract_1 = require("./lib/org-erasure-contract");
5
+ Object.defineProperty(exports, "ORG_DATA_ERASURE_CAPABILITY", { enumerable: true, get: function () { return org_erasure_contract_1.ORG_DATA_ERASURE_CAPABILITY; } });
6
+ Object.defineProperty(exports, "ORG_ERASURE_ROUTE_PATH", { enumerable: true, get: function () { return org_erasure_contract_1.ORG_ERASURE_ROUTE_PATH; } });
7
+ Object.defineProperty(exports, "ORG_ERASURE_RUNNER", { enumerable: true, get: function () { return org_erasure_contract_1.ORG_ERASURE_RUNNER; } });
8
+ var org_erasure_endpoint_module_1 = require("./lib/org-erasure-endpoint.module");
9
+ Object.defineProperty(exports, "OrgErasureController", { enumerable: true, get: function () { return org_erasure_endpoint_module_1.OrgErasureController; } });
10
+ Object.defineProperty(exports, "OrgErasureEndpointModule", { enumerable: true, get: function () { return org_erasure_endpoint_module_1.OrgErasureEndpointModule; } });
11
+ var org_protection_1 = require("./lib/org-protection");
12
+ Object.defineProperty(exports, "assertOrgNotProtected", { enumerable: true, get: function () { return org_protection_1.assertOrgNotProtected; } });
13
+ Object.defineProperty(exports, "assertOrgProtectionArmable", { enumerable: true, get: function () { return org_protection_1.assertOrgProtectionArmable; } });
14
+ Object.defineProperty(exports, "IdentityOrgProtectionProbe", { enumerable: true, get: function () { return org_protection_1.IdentityOrgProtectionProbe; } });
15
+ Object.defineProperty(exports, "IDENTITY_SERVICE_NAME", { enumerable: true, get: function () { return org_protection_1.IDENTITY_SERVICE_NAME; } });
16
+ Object.defineProperty(exports, "ORGANIZATION_PROTECTED_ERROR_CODE", { enumerable: true, get: function () { return org_protection_1.ORGANIZATION_PROTECTED_ERROR_CODE; } });
17
+ Object.defineProperty(exports, "OrgProtectionGuard", { enumerable: true, get: function () { return org_protection_1.OrgProtectionGuard; } });
18
+ Object.defineProperty(exports, "OrgProtectionUnavailableError", { enumerable: true, get: function () { return org_protection_1.OrgProtectionUnavailableError; } });
19
+ Object.defineProperty(exports, "ProtectedOrgErasureRefusedError", { enumerable: true, get: function () { return org_protection_1.ProtectedOrgErasureRefusedError; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAMoC;AALlC,mIAAA,2BAA2B,OAAA;AAC3B,8HAAA,sBAAsB,OAAA;AACtB,0HAAA,kBAAkB,OAAA;AAIpB,iFAI2C;AAHzC,mIAAA,oBAAoB,OAAA;AACpB,uIAAA,wBAAwB,OAAA;AAG1B,uDAU8B;AAT5B,uHAAA,qBAAqB,OAAA;AACrB,4HAAA,0BAA0B,OAAA;AAC1B,4HAAA,0BAA0B,OAAA;AAC1B,uHAAA,qBAAqB,OAAA;AACrB,mIAAA,iCAAiC,OAAA;AACjC,oHAAA,kBAAkB,OAAA;AAClB,+HAAA,6BAA6B,OAAA;AAC7B,iIAAA,+BAA+B,OAAA"}
@@ -0,0 +1,13 @@
1
+ export declare const ORG_DATA_ERASURE_CAPABILITY = "xema.org-data-erasure";
2
+ export declare const ORG_ERASURE_ROUTE_PATH = "internal/org-erasure";
3
+ export declare const ORG_ERASURE_RUNNER: unique symbol;
4
+ export interface OrgErasureReport {
5
+ readonly orgId: string;
6
+ readonly deletedByModel: Readonly<Record<string, number>>;
7
+ readonly totalDeleted: number;
8
+ readonly passes: number;
9
+ }
10
+ export interface OrgErasureRunner {
11
+ erase(orgId: string): Promise<OrgErasureReport>;
12
+ }
13
+ //# sourceMappingURL=org-erasure-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-erasure-contract.d.ts","sourceRoot":"","sources":["../../src/lib/org-erasure-contract.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AAGnE,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAG7D,eAAO,MAAM,kBAAkB,eAE9B,CAAC;AAUF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAYD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACjD"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ORG_ERASURE_RUNNER = exports.ORG_ERASURE_ROUTE_PATH = exports.ORG_DATA_ERASURE_CAPABILITY = void 0;
4
+ exports.ORG_DATA_ERASURE_CAPABILITY = 'xema.org-data-erasure';
5
+ exports.ORG_ERASURE_ROUTE_PATH = 'internal/org-erasure';
6
+ exports.ORG_ERASURE_RUNNER = Symbol.for('@xemahq/org-erasure-nest/org-erasure-runner');
7
+ //# sourceMappingURL=org-erasure-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-erasure-contract.js","sourceRoot":"","sources":["../../src/lib/org-erasure-contract.ts"],"names":[],"mappings":";;;AA2Ba,QAAA,2BAA2B,GAAG,uBAAuB,CAAC;AAGtD,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAGhD,QAAA,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAC1C,6CAA6C,CAC9C,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type DynamicModule, type InjectionToken, type OptionalFactoryDependency, type Provider } from '@nestjs/common';
2
+ import { type OrgErasureReport, type OrgErasureRunner } from './org-erasure-contract';
3
+ export declare class OrgErasureController {
4
+ private readonly runner;
5
+ constructor(runner: OrgErasureRunner);
6
+ erase(orgId: string): Promise<OrgErasureReport>;
7
+ }
8
+ export interface OrgErasureEndpointModuleOptions {
9
+ readonly useFactory: (...args: never[]) => OrgErasureRunner;
10
+ readonly inject?: readonly (InjectionToken | OptionalFactoryDependency)[];
11
+ readonly providers?: readonly Provider[];
12
+ readonly imports?: DynamicModule['imports'];
13
+ }
14
+ export declare class OrgErasureEndpointModule {
15
+ static forRunner(options: OrgErasureEndpointModuleOptions): DynamicModule;
16
+ }
17
+ //# sourceMappingURL=org-erasure-endpoint.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-erasure-endpoint.module.d.ts","sourceRoot":"","sources":["../../src/lib/org-erasure-endpoint.module.ts"],"names":[],"mappings":"AAwCA,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAGhC,qBAGa,oBAAoB;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,gBAAgB;IASvE,KAAK,CAAiB,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAGhE;AAGD,MAAM,WAAW,+BAA+B;IAQ9C,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,gBAAgB,CAAC;IAE5D,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,cAAc,GAAG,yBAAyB,CAAC,EAAE,CAAC;IAE1E,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IAEzC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CAC7C;AAwBD,qBAAa,wBAAwB;IACnC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,+BAA+B,GAAG,aAAa;CAe1E"}
@@ -0,0 +1,68 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OrgErasureEndpointModule = exports.OrgErasureController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const swagger_1 = require("@nestjs/swagger");
18
+ const platform_common_1 = require("@xemahq/platform-common");
19
+ const xema_decorators_1 = require("@xemahq/xema-decorators");
20
+ const org_erasure_contract_1 = require("./org-erasure-contract");
21
+ const org_protection_1 = require("./org-protection");
22
+ let OrgErasureController = class OrgErasureController {
23
+ runner;
24
+ constructor(runner) {
25
+ this.runner = runner;
26
+ }
27
+ erase(orgId) {
28
+ return this.runner.erase(orgId);
29
+ }
30
+ };
31
+ exports.OrgErasureController = OrgErasureController;
32
+ __decorate([
33
+ (0, xema_decorators_1.XemaInternalRoute)({ audience: xema_decorators_1.InternalRouteAudience.Service }),
34
+ (0, common_1.Post)(':orgId'),
35
+ (0, swagger_1.ApiOperation)({
36
+ summary: "Erase every row belonging to an org across this service's org-scoped models",
37
+ }),
38
+ __param(0, (0, common_1.Param)('orgId')),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", [String]),
41
+ __metadata("design:returntype", Promise)
42
+ ], OrgErasureController.prototype, "erase", null);
43
+ exports.OrgErasureController = OrgErasureController = __decorate([
44
+ (0, swagger_1.ApiTags)('org-erasure'),
45
+ (0, common_1.UseGuards)(platform_common_1.ServiceActorGuard, org_protection_1.OrgProtectionGuard),
46
+ (0, common_1.Controller)('internal/org-erasure'),
47
+ __param(0, (0, common_1.Inject)(org_erasure_contract_1.ORG_ERASURE_RUNNER)),
48
+ __metadata("design:paramtypes", [Object])
49
+ ], OrgErasureController);
50
+ class OrgErasureEndpointModule {
51
+ static forRunner(options) {
52
+ return {
53
+ module: OrgErasureEndpointModule,
54
+ ...(options.imports === undefined ? {} : { imports: options.imports }),
55
+ controllers: [OrgErasureController],
56
+ providers: [
57
+ ...(options.providers ?? []),
58
+ {
59
+ provide: org_erasure_contract_1.ORG_ERASURE_RUNNER,
60
+ useFactory: options.useFactory,
61
+ ...(options.inject === undefined ? {} : { inject: [...options.inject] }),
62
+ },
63
+ ],
64
+ };
65
+ }
66
+ }
67
+ exports.OrgErasureEndpointModule = OrgErasureEndpointModule;
68
+ //# sourceMappingURL=org-erasure-endpoint.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-erasure-endpoint.module.js","sourceRoot":"","sources":["../../src/lib/org-erasure-endpoint.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwCA,2CAUwB;AACxB,6CAAwD;AACxD,6DAA4D;AAC5D,6DAAmF;AAEnF,iEAIgC;AAChC,qDAAsD;AAK/C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAEgB;IAD/C,YAC+C,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;IACpE,CAAC;IAQJ,KAAK,CAAiB,KAAa;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF,CAAA;AAdY,oDAAoB;AAW/B;IANC,IAAA,mCAAiB,EAAC,EAAE,QAAQ,EAAE,uCAAqB,CAAC,OAAO,EAAE,CAAC;IAC9D,IAAA,aAAI,EAAC,QAAQ,CAAC;IACd,IAAA,sBAAY,EAAC;QACZ,OAAO,EACL,6EAA6E;KAChF,CAAC;IACK,WAAA,IAAA,cAAK,EAAC,OAAO,CAAC,CAAA;;;;iDAEpB;+BAbU,oBAAoB;IAHhC,IAAA,iBAAO,EAAC,aAAa,CAAC;IACtB,IAAA,kBAAS,EAAC,mCAAiB,EAAE,mCAAkB,CAAC;IAChD,IAAA,mBAAU,EAAC,sBAAsB,CAAC;IAG9B,WAAA,IAAA,eAAM,EAAC,yCAAkB,CAAC,CAAA;;GAFlB,oBAAoB,CAchC;AA0CD,MAAa,wBAAwB;IACnC,MAAM,CAAC,SAAS,CAAC,OAAwC;QACvD,OAAO;YACL,MAAM,EAAE,wBAAwB;YAChC,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;YACtE,WAAW,EAAE,CAAC,oBAAoB,CAAC;YACnC,SAAS,EAAE;gBACT,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;gBAC5B;oBACE,OAAO,EAAE,yCAAkB;oBAC3B,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;iBACzE;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAhBD,4DAgBC"}
@@ -0,0 +1,33 @@
1
+ import { ForbiddenException, ServiceUnavailableException, type CanActivate, type ExecutionContext } from '@nestjs/common';
2
+ import { IdentityBootstrapService } from '@xemahq/identity-client';
3
+ import type { ServiceRegistry } from '@xemahq/contracts/service-registry';
4
+ export declare const IDENTITY_SERVICE_NAME = "identity-api";
5
+ export declare const ORGANIZATION_PROTECTED_ERROR_CODE = "ORGANIZATION_PROTECTED";
6
+ export interface OrgProtectionProbe {
7
+ isOrgProtected(orgId: string): Promise<boolean>;
8
+ }
9
+ export declare class ProtectedOrgErasureRefusedError extends ForbiddenException {
10
+ readonly orgId: string;
11
+ constructor(orgId: string);
12
+ }
13
+ export declare class OrgProtectionUnavailableError extends ServiceUnavailableException {
14
+ readonly orgId: string;
15
+ readonly reason: string;
16
+ constructor(orgId: string, reason: string);
17
+ }
18
+ export declare function assertOrgNotProtected(probe: OrgProtectionProbe, orgId: string): Promise<void>;
19
+ export declare class IdentityOrgProtectionProbe implements OrgProtectionProbe {
20
+ private readonly registry;
21
+ private readonly identity;
22
+ private readonly logger;
23
+ constructor(registry: ServiceRegistry, identity: IdentityBootstrapService);
24
+ isOrgProtected(orgId: string): Promise<boolean>;
25
+ private fetchOrganization;
26
+ }
27
+ export declare function assertOrgProtectionArmable(registry: ServiceRegistry | null | undefined, identity: IdentityBootstrapService | null | undefined): asserts registry is ServiceRegistry;
28
+ export declare class OrgProtectionGuard implements CanActivate {
29
+ private readonly probe;
30
+ constructor(registry: ServiceRegistry | null, identity: IdentityBootstrapService | null);
31
+ canActivate(context: ExecutionContext): Promise<boolean>;
32
+ }
33
+ //# sourceMappingURL=org-protection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-protection.d.ts","sourceRoot":"","sources":["../../src/lib/org-protection.ts"],"names":[],"mappings":"AA8CA,OAAO,EACL,kBAAkB,EAKlB,2BAA2B,EAC3B,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAOnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAG1E,eAAO,MAAM,qBAAqB,iBAAi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C,OAAO,CAAC;CAiB/D"}
@@ -0,0 +1,189 @@
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 IdentityOrgProtectionProbe_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.OrgProtectionGuard = exports.IdentityOrgProtectionProbe = exports.OrgProtectionUnavailableError = exports.ProtectedOrgErasureRefusedError = exports.ORGANIZATION_PROTECTED_ERROR_CODE = exports.IDENTITY_SERVICE_NAME = void 0;
17
+ exports.assertOrgNotProtected = assertOrgNotProtected;
18
+ exports.assertOrgProtectionArmable = assertOrgProtectionArmable;
19
+ const common_1 = require("@nestjs/common");
20
+ const identity_client_1 = require("@xemahq/identity-client");
21
+ const platform_common_1 = require("@xemahq/platform-common");
22
+ const service_registry_nest_1 = require("@xemahq/service-registry-nest");
23
+ exports.IDENTITY_SERVICE_NAME = 'identity-api';
24
+ exports.ORGANIZATION_PROTECTED_ERROR_CODE = 'ORGANIZATION_PROTECTED';
25
+ class ProtectedOrgErasureRefusedError extends common_1.ForbiddenException {
26
+ orgId;
27
+ constructor(orgId) {
28
+ super({
29
+ error: exports.ORGANIZATION_PROTECTED_ERROR_CODE,
30
+ message: `Refusing to erase organization "${orgId}": it is marked protected in ` +
31
+ `identity-api. Protection is a property of the organization, not of ` +
32
+ `the caller — clear it there first if the protection no longer applies.`,
33
+ });
34
+ this.orgId = orgId;
35
+ }
36
+ }
37
+ exports.ProtectedOrgErasureRefusedError = ProtectedOrgErasureRefusedError;
38
+ class OrgProtectionUnavailableError extends common_1.ServiceUnavailableException {
39
+ orgId;
40
+ reason;
41
+ constructor(orgId, reason) {
42
+ super({
43
+ error: 'ORG_PROTECTION_UNDETERMINED',
44
+ message: `Refusing to erase organization "${orgId}": could not establish ` +
45
+ `whether it is protected (${reason}). Erasure is irreversible, so an ` +
46
+ `undetermined protection status fails CLOSED. Retry once the ` +
47
+ `protection lookup succeeds.`,
48
+ });
49
+ this.orgId = orgId;
50
+ this.reason = reason;
51
+ }
52
+ }
53
+ exports.OrgProtectionUnavailableError = OrgProtectionUnavailableError;
54
+ async function assertOrgNotProtected(probe, orgId) {
55
+ const trimmed = orgId.trim();
56
+ if (trimmed === '') {
57
+ throw new OrgProtectionUnavailableError(orgId, 'orgId is empty');
58
+ }
59
+ let isProtected;
60
+ try {
61
+ isProtected = await probe.isOrgProtected(trimmed);
62
+ }
63
+ catch (error) {
64
+ throw new OrgProtectionUnavailableError(trimmed, error instanceof Error ? error.message : String(error));
65
+ }
66
+ if (isProtected) {
67
+ throw new ProtectedOrgErasureRefusedError(trimmed);
68
+ }
69
+ }
70
+ let IdentityOrgProtectionProbe = IdentityOrgProtectionProbe_1 = class IdentityOrgProtectionProbe {
71
+ registry;
72
+ identity;
73
+ logger = new common_1.Logger(IdentityOrgProtectionProbe_1.name);
74
+ constructor(registry, identity) {
75
+ this.registry = registry;
76
+ this.identity = identity;
77
+ }
78
+ async isOrgProtected(orgId) {
79
+ const realms = this.identity.getAllowedRealms();
80
+ if (realms.length === 0) {
81
+ throw new Error('this service has no allowed realms — identity registration has not ' +
82
+ 'completed, so no organization can be resolved');
83
+ }
84
+ const baseUrl = (await (0, service_registry_nest_1.resolveHttpUrl)(this.registry, exports.IDENTITY_SERVICE_NAME))
85
+ .replace(/\/$/, '');
86
+ const token = await this.identity.getAccessToken();
87
+ for (const realm of realms) {
88
+ const record = await this.fetchOrganization(baseUrl, token, orgId, realm);
89
+ if (record === null) {
90
+ continue;
91
+ }
92
+ const isProtected = record['isProtected'];
93
+ if (typeof isProtected !== 'boolean') {
94
+ throw new Error(`identity-api returned organization "${orgId}" (realm "${realm}") ` +
95
+ `without a boolean "isProtected" field (present keys: ` +
96
+ `[${Object.keys(record).join(', ')}]). An identity-api that cannot ` +
97
+ `report protection cannot be read as reporting "unprotected".`);
98
+ }
99
+ if (isProtected) {
100
+ this.logger.warn(`organization "${orgId}" is protected in realm "${realm}" — erasure refused`);
101
+ }
102
+ return isProtected;
103
+ }
104
+ throw new Error(`identity-api has no organization "${orgId}" in any realm this service ` +
105
+ `is registered for [${realms.join(', ')}]. "Not found" is not "not ` +
106
+ `protected": either the organization id is wrong, or it lives in a ` +
107
+ `realm this service cannot see.`);
108
+ }
109
+ async fetchOrganization(baseUrl, token, orgId, realm) {
110
+ const url = `${baseUrl}/internal/organizations/${encodeURIComponent(orgId)}` +
111
+ `?realm=${encodeURIComponent(realm)}`;
112
+ const response = await fetch(url, {
113
+ method: 'GET',
114
+ headers: {
115
+ authorization: `Bearer ${token}`,
116
+ accept: 'application/json',
117
+ },
118
+ });
119
+ if (response.status === 404) {
120
+ return null;
121
+ }
122
+ if (!response.ok) {
123
+ const body = await response.text().catch(() => '<unreadable body>');
124
+ throw new Error(`GET ${url} responded ${response.status} ${response.statusText}: ${body}`);
125
+ }
126
+ const payload = await response.json();
127
+ const record = (0, platform_common_1.unwrapPlatformResponseEnvelope)(payload, `orgProtectionProbe: ${url}`);
128
+ if (record === null || typeof record !== 'object') {
129
+ throw new Error(`GET ${url} returned a non-object organization record ` +
130
+ `(${JSON.stringify(record)}).`);
131
+ }
132
+ return record;
133
+ }
134
+ };
135
+ exports.IdentityOrgProtectionProbe = IdentityOrgProtectionProbe;
136
+ exports.IdentityOrgProtectionProbe = IdentityOrgProtectionProbe = IdentityOrgProtectionProbe_1 = __decorate([
137
+ (0, common_1.Injectable)(),
138
+ __param(0, (0, common_1.Inject)(service_registry_nest_1.SERVICE_REGISTRY_TOKEN)),
139
+ __metadata("design:paramtypes", [Object, identity_client_1.IdentityBootstrapService])
140
+ ], IdentityOrgProtectionProbe);
141
+ function assertOrgProtectionArmable(registry, identity) {
142
+ const missing = [];
143
+ if (registry === null || registry === undefined) {
144
+ missing.push('SERVICE_REGISTRY_TOKEN (@xemahq/service-registry-nest)');
145
+ }
146
+ if (identity === null || identity === undefined) {
147
+ missing.push('IdentityBootstrapService (@xemahq/identity-client)');
148
+ }
149
+ if (missing.length > 0) {
150
+ throw new Error(`[org-erasure] this service mounts the org-erasure route but cannot ` +
151
+ `construct its protected-organization fence: ${missing.join(' and ')} ` +
152
+ `${missing.length > 1 ? 'are' : 'is'} not resolvable. Both are ` +
153
+ `exported GLOBALLY by \`XemaServiceModule.forBiome\` (which composes ` +
154
+ `ServiceRegistryModule + IdentityBootstrapModule, each \`global: ` +
155
+ `true\`), so a service reaching this error has not wired the platform ` +
156
+ `bootstrap. Refusing to start: an org-erasure route served without the ` +
157
+ `fence lets any service token in the fleet irreversibly erase a ` +
158
+ `PROTECTED organization.`);
159
+ }
160
+ }
161
+ let OrgProtectionGuard = class OrgProtectionGuard {
162
+ probe;
163
+ constructor(registry, identity) {
164
+ assertOrgProtectionArmable(registry, identity);
165
+ this.probe = new IdentityOrgProtectionProbe(registry, identity);
166
+ }
167
+ async canActivate(context) {
168
+ const request = context
169
+ .switchToHttp()
170
+ .getRequest();
171
+ const orgId = request.params?.['orgId'];
172
+ if (typeof orgId !== 'string' || orgId.trim() === '') {
173
+ throw new OrgProtectionUnavailableError(String(orgId), 'the route declares no ":orgId" parameter — OrgProtectionGuard is ' +
174
+ 'mounted on a route it cannot fence');
175
+ }
176
+ await assertOrgNotProtected(this.probe, orgId);
177
+ return true;
178
+ }
179
+ };
180
+ exports.OrgProtectionGuard = OrgProtectionGuard;
181
+ exports.OrgProtectionGuard = OrgProtectionGuard = __decorate([
182
+ (0, common_1.Injectable)(),
183
+ __param(0, (0, common_1.Optional)()),
184
+ __param(0, (0, common_1.Inject)(service_registry_nest_1.SERVICE_REGISTRY_TOKEN)),
185
+ __param(1, (0, common_1.Optional)()),
186
+ __param(1, (0, common_1.Inject)(identity_client_1.IdentityBootstrapService)),
187
+ __metadata("design:paramtypes", [Object, Object])
188
+ ], OrgProtectionGuard);
189
+ //# sourceMappingURL=org-protection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-protection.js","sourceRoot":"","sources":["../../src/lib/org-protection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA4HA,sDAyBC;AA8HD,gEAwBC;AA7PD,2CASwB;AACxB,6DAAmE;AACnE,6DAAyE;AACzE,yEAGuC;AAK1B,QAAA,qBAAqB,GAAG,cAAc,CAAC;AAGvC,QAAA,iCAAiC,GAAG,wBAAwB,CAAC;AAiB1E,MAAa,+BAAgC,SAAQ,2BAAkB;IAChD;IAArB,YAAqB,KAAa;QAChC,KAAK,CAAC;YACJ,KAAK,EAAE,yCAAiC;YACxC,OAAO,EACL,mCAAmC,KAAK,+BAA+B;gBACvE,qEAAqE;gBACrE,wEAAwE;SAC3E,CAAC,CAAC;QAPgB,UAAK,GAAL,KAAK,CAAQ;IAQlC,CAAC;CACF;AAVD,0EAUC;AAMD,MAAa,6BAA8B,SAAQ,oCAA2B;IAEjE;IACA;IAFX,YACW,KAAa,EACb,MAAc;QAEvB,KAAK,CAAC;YACJ,KAAK,EAAE,6BAA6B;YACpC,OAAO,EACL,mCAAmC,KAAK,yBAAyB;gBACjE,4BAA4B,MAAM,oCAAoC;gBACtE,8DAA8D;gBAC9D,6BAA6B;SAChC,CAAC,CAAC;QAVM,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAQ;IAUzB,CAAC;CACF;AAdD,sEAcC;AAQM,KAAK,UAAU,qBAAqB,C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C;IACd,CAAC;CACF,CAAA;AA7CY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,8CAAsB,CAAC,CAAA;IAQ9B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,0CAAwB,CAAC,CAAA;;GAdxB,kBAAkB,CA6C9B"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@xemahq/org-erasure-nest",
3
+ "version": "0.1.0",
4
+ "description": "The org-erasure participant contract, its fenced internal endpoint, and the protected-organization guard for Xema services.",
5
+ "license": "Apache-2.0",
6
+ "author": "Neuralchowder Inc. <developer@xema.dev> (https://xema.dev)",
7
+ "homepage": "https://xema.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/xema-dev/xema-kernel-sdk.git",
11
+ "directory": "packages/sdks/org-erasure-nest"
12
+ },
13
+ "bugs": "https://github.com/xema-dev/xema-kernel-sdk/issues",
14
+ "publishConfig": {
15
+ "registry": "https://registry.npmjs.org/",
16
+ "access": "public"
17
+ },
18
+ "main": "dist/index.js",
19
+ "types": "dist/index.d.ts",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "devDependencies": {
24
+ "@nestjs/common": "11.1.18",
25
+ "@nestjs/core": "11.1.18",
26
+ "@nestjs/swagger": "11.2.6",
27
+ "@types/jest": "^30.0.0",
28
+ "@types/node": "25.2.3",
29
+ "@xemahq/identity-client": "^0.9.1",
30
+ "@xemahq/contracts": "^0.1.0",
31
+ "@xemahq/platform-common": "^0.31.0",
32
+ "eslint": "^9.39.4",
33
+ "jest": "^30.3.0",
34
+ "prettier": "3.6.2",
35
+ "ts-jest": "^29.4.9",
36
+ "typescript": "5.9.3",
37
+ "@xemahq/service-registry-nest": "0.9.0",
38
+ "@xemahq/eslint-config": "0.6.0",
39
+ "@xemahq/xema-decorators": "0.16.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@nestjs/common": "^10 || ^11",
43
+ "@nestjs/core": "^10 || ^11",
44
+ "@nestjs/swagger": "^10 || ^11",
45
+ "@xemahq/identity-client": "^0.9.0",
46
+ "@xemahq/contracts": "^0.1.0",
47
+ "@xemahq/platform-common": ">=0.18.0",
48
+ "@xemahq/service-registry-nest": ">=0.8.0",
49
+ "@xemahq/xema-decorators": ">=0.7.0"
50
+ },
51
+ "exports": {
52
+ ".": {
53
+ "types": "./dist/index.d.ts",
54
+ "xema-source": "./src/index.ts",
55
+ "default": "./dist/index.js"
56
+ }
57
+ },
58
+ "scripts": {
59
+ "clean": "rm -rf dist",
60
+ "build": "tsc -p tsconfig.build.json",
61
+ "format": "prettier --write \"src/**/*.ts\"",
62
+ "lint": "eslint .",
63
+ "test": "jest",
64
+ "typecheck": "tsc -p tsconfig.json --noEmit"
65
+ }
66
+ }