@xemahq/authorization-nest 0.0.0-stage → 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.
Files changed (39) hide show
  1. package/LICENSE +175 -0
  2. package/dist/anchor-predicate.d.ts +61 -0
  3. package/dist/anchor-predicate.d.ts.map +1 -0
  4. package/dist/anchor-predicate.js +140 -0
  5. package/dist/anchor-predicate.js.map +1 -0
  6. package/dist/authorization.module.d.ts +6 -0
  7. package/dist/authorization.module.d.ts.map +1 -0
  8. package/dist/authorization.module.js +41 -0
  9. package/dist/authorization.module.js.map +1 -0
  10. package/dist/authorization.options.d.ts +7 -0
  11. package/dist/authorization.options.d.ts.map +1 -0
  12. package/dist/authorization.options.js +14 -0
  13. package/dist/authorization.options.js.map +1 -0
  14. package/dist/authorize.decorator.d.ts +19 -0
  15. package/dist/authorize.decorator.d.ts.map +1 -0
  16. package/dist/authorize.decorator.js +51 -0
  17. package/dist/authorize.decorator.js.map +1 -0
  18. package/dist/authzen.transport.d.ts +30 -0
  19. package/dist/authzen.transport.d.ts.map +1 -0
  20. package/dist/authzen.transport.js +105 -0
  21. package/dist/authzen.transport.js.map +1 -0
  22. package/dist/index.d.ts +9 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +25 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/policy-decisions.d.ts +22 -0
  27. package/dist/policy-decisions.d.ts.map +1 -0
  28. package/dist/policy-decisions.js +163 -0
  29. package/dist/policy-decisions.js.map +1 -0
  30. package/dist/subject-from-context.d.ts +28 -0
  31. package/dist/subject-from-context.d.ts.map +1 -0
  32. package/dist/subject-from-context.js +87 -0
  33. package/dist/subject-from-context.js.map +1 -0
  34. package/dist/xema-authz.service.d.ts +41 -0
  35. package/dist/xema-authz.service.d.ts.map +1 -0
  36. package/dist/xema-authz.service.js +181 -0
  37. package/dist/xema-authz.service.js.map +1 -0
  38. package/package.json +61 -3
  39. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,175 @@
1
+ Xema Business Source License 1.1
2
+
3
+ License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Neuralchowder Inc.
11
+
12
+ Licensed Work: Xema. The Licensed Work is (c) 2026 Neuralchowder Inc.
13
+
14
+ The Licensed Work includes, without limitation, Xema Core, Xema Runtime,
15
+ Xema Kernel, Xema control plane, Xema application runtime, Xema biome
16
+ runtime, Xema biome registry, Xema store services, Xema orchestration
17
+ services, Xema agents, Xema skills, Xema memory services, Xema APIs, Xema
18
+ user interfaces, Xema command-line tools, Xema deployment artifacts, Xema
19
+ templates, Xema specifications, Xema schemas, Xema manifests, Xema
20
+ documentation, Xema examples, and all source code, object code, binaries,
21
+ packages, modules, configuration files, manifests, schemas, examples,
22
+ templates, documentation, and derivative works included in or distributed
23
+ as part of the Xema software project.
24
+
25
+ The Licensed Work does not include any third-party software, libraries,
26
+ dependencies, packages, assets, or components that are distributed with the
27
+ Licensed Work but are governed by their own separate license terms. Such
28
+ third-party materials remain subject to their respective licenses.
29
+
30
+ A specific file, package, component, or directory may state that it is
31
+ governed by a different license. In that case, that specific file, package,
32
+ component, or directory is governed by the license expressly stated therein.
33
+
34
+ Additional Use Grant:
35
+
36
+ You may make production use of the Licensed Work, provided that your use
37
+ does not include offering, providing, making available, distributing,
38
+ hosting, managing, embedding, reselling, white-labeling, sublicensing,
39
+ commercializing, or otherwise making the Licensed Work, or any modified
40
+ version or derivative work of the Licensed Work, available to Third Parties
41
+ as part of a Competitive Offering.
42
+
43
+ The following definitions and clarifications form part of, and govern
44
+ the interpretation of, the Additional Use Grant set out above.
45
+
46
+ 1. "Production Use" means any use of the Licensed Work other than for
47
+ development, testing, evaluation, demonstration, experimentation,
48
+ benchmarking, or other non-production purposes.
49
+
50
+ 2. "Affiliate" means any entity that, directly or indirectly,
51
+ controls, is controlled by, or is under common control with you,
52
+ where "control" means ownership of more than fifty percent (50%) of
53
+ the voting interests of the entity, or the power to direct its
54
+ management.
55
+
56
+ 3. "Third Party" means any natural person or legal entity other than
57
+ you and your Affiliates.
58
+
59
+ 4. "Competitive Offering" means any product or service, made available
60
+ to one or more Third Parties for a fee or other consideration
61
+ (including without limitation on a paid, subscription,
62
+ advertising-supported, hosted, or managed-service basis), that is
63
+ offered or marketed as, or that competes with, a software platform,
64
+ runtime, orchestration system, agent or automation system,
65
+ extension or distribution marketplace, or other software system
66
+ that provides, in substantial part, the same or substantially
67
+ similar capabilities as those provided by the Licensed Work. A
68
+ product or service is a Competitive Offering whether the Licensed
69
+ Work is provided in whole or in part, alone or bundled with other
70
+ software, and whether modified or unmodified.
71
+
72
+ 5. Providing, hosting, or managing the Licensed Work for a Third Party,
73
+ or otherwise making the Licensed Work available to a Third Party as
74
+ a hosted or managed service such that the Third Party obtains the
75
+ principal value or functionality of the Licensed Work, is a
76
+ Competitive Offering and is not permitted by the Additional Use
77
+ Grant.
78
+
79
+ 6. Subject to the foregoing, the Additional Use Grant permits you to
80
+ make Production Use of the Licensed Work for your own internal
81
+ business purposes and to build, operate, and provide your own
82
+ products and services to Third Parties, provided that the Licensed
83
+ Work itself (whether modified or unmodified) is not the product or
84
+ service, and is not a Competitive Offering, made available to those
85
+ Third Parties.
86
+
87
+ 7. You may modify the Licensed Work and create derivative works for
88
+ any purpose permitted by this License. Any Production Use of such
89
+ modified or derivative works remains subject to the same
90
+ restrictions as the Licensed Work, including the prohibition on
91
+ Competitive Offerings.
92
+
93
+ 8. Use of the Licensed Work by your own employees, contractors, and
94
+ agents, acting on your behalf and for your benefit, is not by
95
+ itself making the Licensed Work available to a Third Party.
96
+
97
+ 9. Embedding or distributing the Licensed Work as a component of your
98
+ own product or service is permitted only where the Licensed Work
99
+ does not constitute the principal value of that product or service
100
+ and the product or service is not a Competitive Offering.
101
+
102
+ 10. Nothing in this Additional Use Grant grants any right to use any
103
+ name, trademark, service mark, or logo of the Licensor or its
104
+ Affiliates, except as reasonably required for customary
105
+ attribution.
106
+
107
+ 11. The rights stated in this Additional Use Grant are the maximum
108
+ rights granted for Production Use prior to the Change Date. Any
109
+ Production Use not expressly permitted requires a separate
110
+ commercial license from the Licensor.
111
+
112
+ 12. If any provision of this Additional Use Grant is held invalid or
113
+ unenforceable, that provision shall be limited or eliminated to
114
+ the minimum extent necessary so that the remainder of this
115
+ Additional Use Grant, and of this License, remains in full force
116
+ and effect. The Licensor reserves all rights not expressly granted
117
+ by this License.
118
+
119
+
120
+ Change Date: Four years from the date the specific version of the Licensed
121
+ Work is first publicly released by Licensor.
122
+
123
+ Change License: Mozilla Public License, Version 2.0
124
+
125
+ For information about alternative licensing arrangements, commercial
126
+ licensing, enterprise licensing, OEM licensing, appliance licensing, managed
127
+ service licensing, cloud provider licensing, or other commercial use of the
128
+ Licensed Work, please contact: licensing@neuralchowder.com
129
+
130
+ -----------------------------------------------------------------------------
131
+
132
+ Notice
133
+
134
+ Business Source License 1.1
135
+
136
+ Terms
137
+
138
+ The Licensor hereby grants you the right to copy, modify, create derivative
139
+ works, redistribute, and make non-production use of the Licensed Work. The
140
+ Licensor may make an Additional Use Grant, above, permitting limited
141
+ production use.
142
+
143
+ Effective on the Change Date, or the fourth anniversary of the first publicly
144
+ available distribution of a specific version of the Licensed Work under this
145
+ License, whichever comes first, the Licensor hereby grants you rights under
146
+ the terms of the Change License, and the rights granted in the paragraph above
147
+ terminate.
148
+
149
+ If your use of the Licensed Work does not comply with the requirements
150
+ currently in effect as described in this License, you must purchase a
151
+ commercial license from the Licensor, its affiliated entities, or authorized
152
+ resellers, or you must refrain from using the Licensed Work.
153
+
154
+ All copies of the original and modified Licensed Work, and derivative works of
155
+ the Licensed Work, are subject to this License. This License applies separately
156
+ for each version of the Licensed Work and the Change Date may vary for each
157
+ version of the Licensed Work released by Licensor.
158
+
159
+ You must conspicuously display this License on each original or modified copy
160
+ of the Licensed Work. If you receive the Licensed Work in original or modified
161
+ form from a third party, the terms and conditions set forth in this License
162
+ apply to your use of that work.
163
+
164
+ Any use of the Licensed Work in violation of this License will automatically
165
+ terminate your rights under this License for the current and all other
166
+ versions of the Licensed Work.
167
+
168
+ This License does not grant you any right in any trademark or logo of Licensor
169
+ or its affiliates, provided that you may use a trademark or logo of Licensor
170
+ as expressly required by this License.
171
+
172
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN
173
+ "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS
174
+ OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS
175
+ FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
@@ -0,0 +1,61 @@
1
+ import { z } from 'zod';
2
+ export type XemaAnchorPredicate = {
3
+ readonly op: 'true';
4
+ } | {
5
+ readonly op: 'false';
6
+ } | {
7
+ readonly op: 'edge_in';
8
+ readonly relation: string;
9
+ readonly targetType: string;
10
+ readonly ids: readonly string[];
11
+ } | {
12
+ readonly op: 'edge_match';
13
+ readonly relation: string;
14
+ readonly targetType: string;
15
+ readonly predicate: XemaAnchorPredicate;
16
+ } | {
17
+ readonly op: 'subject_in';
18
+ readonly relation: string;
19
+ readonly subjects: readonly string[];
20
+ } | {
21
+ readonly op: 'condition';
22
+ readonly relation: string;
23
+ readonly condition: string;
24
+ readonly subject: string;
25
+ } | {
26
+ readonly op: 'and';
27
+ readonly args: readonly XemaAnchorPredicate[];
28
+ } | {
29
+ readonly op: 'or';
30
+ readonly args: readonly XemaAnchorPredicate[];
31
+ } | {
32
+ readonly op: 'not';
33
+ readonly arg: XemaAnchorPredicate;
34
+ };
35
+ export declare const XemaAnchorPredicateSchema: z.ZodType<XemaAnchorPredicate>;
36
+ export declare const XemaAnchorSearchContextSchema: z.ZodObject<{
37
+ searchedType: z.ZodString;
38
+ predicate: z.ZodType<XemaAnchorPredicate, unknown, z.core.$ZodTypeInternals<XemaAnchorPredicate, unknown>>;
39
+ }, z.core.$strict>;
40
+ export type XemaAnchorSearchContext = z.infer<typeof XemaAnchorSearchContextSchema>;
41
+ export interface AnchorSqlMapping {
42
+ readonly edgeColumns: Readonly<Record<string, string>>;
43
+ readonly subjectColumns?: Readonly<Record<string, string>>;
44
+ readonly nested?: Readonly<Record<string, {
45
+ readonly select: string;
46
+ readonly mapping: AnchorSqlMapping;
47
+ }>>;
48
+ readonly conditions?: Readonly<Record<string, (subjectParam: string) => string>>;
49
+ }
50
+ export interface AnchorSql {
51
+ readonly sql: string;
52
+ readonly params: readonly unknown[];
53
+ }
54
+ export declare function anchorPredicateToSql(predicate: XemaAnchorPredicate, mapping: AnchorSqlMapping, firstParamIndex?: number): AnchorSql;
55
+ export interface AnchorRowFacts {
56
+ readonly values: (relation: string) => readonly string[];
57
+ readonly nested?: (relation: string) => readonly AnchorRowFacts[];
58
+ readonly condition?: (condition: string, subject: string) => boolean;
59
+ }
60
+ export declare function evaluateAnchorPredicate(predicate: XemaAnchorPredicate, row: AnchorRowFacts): boolean;
61
+ //# sourceMappingURL=anchor-predicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-predicate.d.ts","sourceRoot":"","sources":["../src/anchor-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA2BxB,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACvB;IAAE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;CAAE,GACxB;IACE,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC,GACD;IACE,QAAQ,CAAC,E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C,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAK3D,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CACxB,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;KAAE,CAAC,CAChF,CAAC;IAKF,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAC5B,MAAM,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC,CACjD,CAAC;CACH;AAED,MAAM,WAAW,SAAS;IAExB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CACrC;AAOD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,gBAAgB,EACzB,eAAe,SAAI,GAClB,SAAS,CAgEX;AAOD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,SAAS,MAAM,EAAE,CAAC;IAEzD,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,SAAS,cAAc,EAAE,CAAC;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CACtE;AAGD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,GAAG,EAAE,cAAc,GAClB,OAAO,CAoCT"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XemaAnchorSearchContextSchema = exports.XemaAnchorPredicateSchema = void 0;
4
+ exports.anchorPredicateToSql = anchorPredicateToSql;
5
+ exports.evaluateAnchorPredicate = evaluateAnchorPredicate;
6
+ const zod_1 = require("zod");
7
+ const name = zod_1.z.string().min(1);
8
+ exports.XemaAnchorPredicateSchema = zod_1.z.lazy(() => zod_1.z.discriminatedUnion('op', [
9
+ zod_1.z.object({ op: zod_1.z.literal('true') }).strict(),
10
+ zod_1.z.object({ op: zod_1.z.literal('false') }).strict(),
11
+ zod_1.z
12
+ .object({
13
+ op: zod_1.z.literal('edge_in'),
14
+ relation: name,
15
+ targetType: name,
16
+ ids: zod_1.z.array(name),
17
+ })
18
+ .strict(),
19
+ zod_1.z
20
+ .object({
21
+ op: zod_1.z.literal('edge_match'),
22
+ relation: name,
23
+ targetType: name,
24
+ predicate: exports.XemaAnchorPredicateSchema,
25
+ })
26
+ .strict(),
27
+ zod_1.z
28
+ .object({
29
+ op: zod_1.z.literal('subject_in'),
30
+ relation: name,
31
+ subjects: zod_1.z.array(name),
32
+ })
33
+ .strict(),
34
+ zod_1.z
35
+ .object({
36
+ op: zod_1.z.literal('condition'),
37
+ relation: name,
38
+ condition: name,
39
+ subject: name,
40
+ })
41
+ .strict(),
42
+ zod_1.z.object({ op: zod_1.z.literal('and'), args: zod_1.z.array(exports.XemaAnchorPredicateSchema) }).strict(),
43
+ zod_1.z.object({ op: zod_1.z.literal('or'), args: zod_1.z.array(exports.XemaAnchorPredicateSchema) }).strict(),
44
+ zod_1.z.object({ op: zod_1.z.literal('not'), arg: exports.XemaAnchorPredicateSchema }).strict(),
45
+ ]));
46
+ exports.XemaAnchorSearchContextSchema = zod_1.z
47
+ .object({
48
+ searchedType: name,
49
+ predicate: exports.XemaAnchorPredicateSchema,
50
+ })
51
+ .strict();
52
+ function anchorPredicateToSql(predicate, mapping, firstParamIndex = 1) {
53
+ const params = [];
54
+ const placeholder = (value) => {
55
+ params.push(value);
56
+ return `$${firstParamIndex + params.length - 1}`;
57
+ };
58
+ const column = (table, relation, op) => {
59
+ const found = table?.[relation];
60
+ if (found === undefined) {
61
+ throw new Error(`anchorPredicateToSql: the mapping has no column for relation "${relation}" (${op}).`);
62
+ }
63
+ return found;
64
+ };
65
+ const render = (p, m) => {
66
+ switch (p.op) {
67
+ case 'true':
68
+ return 'TRUE';
69
+ case 'false':
70
+ return 'FALSE';
71
+ case 'edge_in':
72
+ return p.ids.length === 0
73
+ ? 'FALSE'
74
+ : `${column(m.edgeColumns, p.relation, p.op)} = ANY(${placeholder([...p.ids])})`;
75
+ case 'edge_match': {
76
+ const nested = m.nested?.[p.targetType];
77
+ if (nested === undefined) {
78
+ throw new Error(`anchorPredicateToSql: no nested mapping for type "${p.targetType}" (edge_match).`);
79
+ }
80
+ return `${column(m.edgeColumns, p.relation, p.op)} IN (${nested.select} ${render(p.predicate, nested.mapping)})`;
81
+ }
82
+ case 'subject_in':
83
+ return p.subjects.length === 0
84
+ ? 'FALSE'
85
+ : `${column(m.subjectColumns, p.relation, p.op)} = ANY(${placeholder([...p.subjects])})`;
86
+ case 'condition': {
87
+ const renderCondition = m.conditions?.[p.condition];
88
+ if (renderCondition === undefined) {
89
+ throw new Error(`anchorPredicateToSql: no SQL for condition "${p.condition}" on relation "${p.relation}".`);
90
+ }
91
+ return `(${renderCondition(placeholder(p.subject))})`;
92
+ }
93
+ case 'and':
94
+ return p.args.length === 0
95
+ ? 'TRUE'
96
+ : `(${p.args.map((a) => render(a, m)).join(' AND ')})`;
97
+ case 'or':
98
+ return p.args.length === 0
99
+ ? 'FALSE'
100
+ : `(${p.args.map((a) => render(a, m)).join(' OR ')})`;
101
+ case 'not':
102
+ return `(NOT ${render(p.arg, m)})`;
103
+ }
104
+ };
105
+ return { sql: render(predicate, mapping), params };
106
+ }
107
+ function evaluateAnchorPredicate(predicate, row) {
108
+ switch (predicate.op) {
109
+ case 'true':
110
+ return true;
111
+ case 'false':
112
+ return false;
113
+ case 'edge_in':
114
+ return row.values(predicate.relation).some((v) => predicate.ids.includes(v));
115
+ case 'edge_match': {
116
+ const nested = row.nested?.(predicate.relation);
117
+ if (nested === undefined) {
118
+ throw new Error(`evaluateAnchorPredicate: the row exposes no nested rows for "${predicate.relation}".`);
119
+ }
120
+ return nested.some((n) => evaluateAnchorPredicate(predicate.predicate, n));
121
+ }
122
+ case 'subject_in':
123
+ return row
124
+ .values(predicate.relation)
125
+ .some((v) => predicate.subjects.includes(v));
126
+ case 'condition': {
127
+ if (row.condition === undefined) {
128
+ throw new Error(`evaluateAnchorPredicate: the row cannot evaluate condition "${predicate.condition}".`);
129
+ }
130
+ return row.condition(predicate.condition, predicate.subject);
131
+ }
132
+ case 'and':
133
+ return predicate.args.every((a) => evaluateAnchorPredicate(a, row));
134
+ case 'or':
135
+ return predicate.args.some((a) => evaluateAnchorPredicate(a, row));
136
+ case 'not':
137
+ return !evaluateAnchorPredicate(predicate.arg, row);
138
+ }
139
+ }
140
+ //# sourceMappingURL=anchor-predicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-predicate.js","sourceRoot":"","sources":["../src/anchor-predicate.ts"],"names":[],"mappings":";;;AAmJA,oDAoEC;AAeD,0DAuCC;AA7QD,6BAAwB;AAyDxB,MAAM,IAAI,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAElB,QAAA,yBAAyB,GAAmC,OAAC,CAAC,IAAI,CAC7E,GAAG,EAAE,CACH,OAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE;IACzB,OAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IAC5C,OAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IAC7C,OAAC;SACE,MAAM,CAAC;QACN,EAAE,EAAE,OAAC,CAAC,OAAO,CAAC,SAAS,CAAC;QACxB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,GAAG,EAAE,OAAC,CAAC,KAAK,CAAC,IAAI,CAAC;KACnB,CAAC;SAC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AAC;QAC7E,CAAC;QACD,KAAK,YAAY;YACf,OAAO,GAAG;iBACP,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;iBAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CACb,+DAA+D,SAAS,CAAC,SAAS,IAAI,CACvF,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QAC/D,CAAC;QACD,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACtE,KAAK,IAAI;YACP,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACrE,KAAK,KAAK;YACR,OAAO,CAAC,uBAAuB,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ import { type XemaAuthorizationOptions } from './authorization.options';
3
+ export declare class XemaAuthorizationModule {
4
+ static forRoot(options?: Partial<XemaAuthorizationOptions>): DynamicModule;
5
+ }
6
+ //# sourceMappingURL=authorization.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.module.d.ts","sourceRoot":"","sources":["../src/authorization.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,yBAAyB,CAAC;AAqBjC,qBACa,uBAAuB;WACpB,OAAO,CACnB,OAAO,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAC1C,aAAa;CAkBjB"}
@@ -0,0 +1,41 @@
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 XemaAuthorizationModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.XemaAuthorizationModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const authorization_options_1 = require("./authorization.options");
13
+ const authorize_decorator_1 = require("./authorize.decorator");
14
+ const authzen_transport_1 = require("./authzen.transport");
15
+ const policy_decisions_1 = require("./policy-decisions");
16
+ const xema_authz_service_1 = require("./xema-authz.service");
17
+ let XemaAuthorizationModule = XemaAuthorizationModule_1 = class XemaAuthorizationModule {
18
+ static forRoot(options) {
19
+ return {
20
+ module: XemaAuthorizationModule_1,
21
+ global: true,
22
+ providers: [
23
+ {
24
+ provide: authorization_options_1.XEMA_AUTHORIZATION_OPTIONS,
25
+ useValue: (0, authorization_options_1.resolveXemaAuthorizationOptions)(options),
26
+ },
27
+ authzen_transport_1.HttpAuthzenPdpTransport,
28
+ { provide: authzen_transport_1.AUTHZEN_PDP_TRANSPORT, useExisting: authzen_transport_1.HttpAuthzenPdpTransport },
29
+ xema_authz_service_1.XemaAuthz,
30
+ policy_decisions_1.XemaPolicyDecisions,
31
+ authorize_decorator_1.XemaAuthorizeGuard,
32
+ ],
33
+ exports: [xema_authz_service_1.XemaAuthz, policy_decisions_1.XemaPolicyDecisions, authorize_decorator_1.XemaAuthorizeGuard, authzen_transport_1.AUTHZEN_PDP_TRANSPORT],
34
+ };
35
+ }
36
+ };
37
+ exports.XemaAuthorizationModule = XemaAuthorizationModule;
38
+ exports.XemaAuthorizationModule = XemaAuthorizationModule = XemaAuthorizationModule_1 = __decorate([
39
+ (0, common_1.Module)({})
40
+ ], XemaAuthorizationModule);
41
+ //# sourceMappingURL=authorization.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.module.js","sourceRoot":"","sources":["../src/authorization.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA4D;AAE5D,mEAIiC;AACjC,+DAA2D;AAC3D,2DAG6B;AAC7B,yDAAyD;AACzD,6DAAiD;AAe1C,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAC3B,MAAM,CAAC,OAAO,CACnB,OAA2C;QAE3C,OAAO;YACL,MAAM,EAAE,yBAAuB;YAC/B,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,kDAA0B;oBACnC,QAAQ,EAAE,IAAA,uDAA+B,EAAC,OAAO,CAAC;iBACnD;gBACD,2CAAuB;gBACvB,EAAE,OAAO,EAAE,yCAAqB,EAAE,WAAW,EAAE,2CAAuB,EAAE;gBACxE,8BAAS;gBACT,sCAAmB;gBACnB,wCAAkB;aACnB;YACD,OAAO,EAAE,CAAC,8BAAS,EAAE,sCAAmB,EAAE,wCAAkB,EAAE,yCAAqB,CAAC;SACrF,CAAC;IACJ,CAAC;CACF,CAAA;AArBY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,uBAAuB,CAqBnC"}
@@ -0,0 +1,7 @@
1
+ export interface XemaAuthorizationOptions {
2
+ readonly requestTimeoutMs: number;
3
+ }
4
+ export declare const XEMA_AUTHORIZATION_OPTIONS: unique symbol;
5
+ export declare const DEFAULT_XEMA_AUTHORIZATION_OPTIONS: XemaAuthorizationOptions;
6
+ export declare function resolveXemaAuthorizationOptions(overrides: Partial<XemaAuthorizationOptions> | undefined): XemaAuthorizationOptions;
7
+ //# sourceMappingURL=authorization.options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.options.d.ts","sourceRoot":"","sources":["../src/authorization.options.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,wBAAwB;IAEvC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,0BAA0B,eAAuC,CAAC;AAE/E,eAAO,MAAM,kCAAkC,EAAE,wBACJ,CAAC;AAE9C,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,SAAS,GACvD,wBAAwB,CAQ1B"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_XEMA_AUTHORIZATION_OPTIONS = exports.XEMA_AUTHORIZATION_OPTIONS = void 0;
4
+ exports.resolveXemaAuthorizationOptions = resolveXemaAuthorizationOptions;
5
+ exports.XEMA_AUTHORIZATION_OPTIONS = Symbol('XEMA_AUTHORIZATION_OPTIONS');
6
+ exports.DEFAULT_XEMA_AUTHORIZATION_OPTIONS = Object.freeze({ requestTimeoutMs: 10_000 });
7
+ function resolveXemaAuthorizationOptions(overrides) {
8
+ const resolved = { ...exports.DEFAULT_XEMA_AUTHORIZATION_OPTIONS, ...overrides };
9
+ if (!Number.isSafeInteger(resolved.requestTimeoutMs) || resolved.requestTimeoutMs <= 0) {
10
+ throw new Error(`XemaAuthorizationModule: requestTimeoutMs must be a positive integer, got ${String(resolved.requestTimeoutMs)}.`);
11
+ }
12
+ return resolved;
13
+ }
14
+ //# sourceMappingURL=authorization.options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.options.js","sourceRoot":"","sources":["../src/authorization.options.ts"],"names":[],"mappings":";;;AAeA,0EAUC;AAfY,QAAA,0BAA0B,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAElE,QAAA,kCAAkC,GAC7C,MAAM,CAAC,MAAM,CAAC,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC,CAAC;AAE9C,SAAgB,+BAA+B,CAC7C,SAAwD;IAExD,MAAM,QAAQ,GAAG,EAAE,GAAG,0CAAkC,EAAE,GAAG,SAAS,EAAE,CAAC;IACzE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,QAAQ,CAAC,gBAAgB,IAAI,CAAC,EAAE,CAAC;QACvF,MAAM,IAAI,KAAK,CACb,6EAA6E,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAClH,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type CanActivate, type ExecutionContext } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ import { XemaAuthz } from './xema-authz.service';
4
+ export interface AuthorizeRouteSpec {
5
+ readonly type: string;
6
+ readonly idParam: string;
7
+ readonly view: string;
8
+ readonly action?: string;
9
+ readonly capability?: string;
10
+ }
11
+ export declare const AUTHORIZE_ROUTE_METADATA = "xema:authorize-route";
12
+ export declare class XemaAuthorizeGuard implements CanActivate {
13
+ private readonly reflector;
14
+ private readonly authz;
15
+ constructor(reflector: Reflector, authz: XemaAuthz);
16
+ canActivate(context: ExecutionContext): Promise<boolean>;
17
+ }
18
+ export declare function Authorize(spec: AuthorizeRouteSpec): MethodDecorator & ClassDecorator;
19
+ //# sourceMappingURL=authorize.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.decorator.d.ts","sourceRoot":"","sources":["../src/authorize.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,MAAM,WAAW,kBAAkB;IAEjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAQ/D,qBACa,kBAAmB,YAAW,WAAW;IAElD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,SAAS;IAGtB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA4BtE;AAYD,wBAAgB,SAAS,CAAC,IAAI,EAAE,kBAAkB,GAAG,eAAe,GAAG,cAAc,CAKpF"}
@@ -0,0 +1,51 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.XemaAuthorizeGuard = exports.AUTHORIZE_ROUTE_METADATA = void 0;
13
+ exports.Authorize = Authorize;
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 xema_authz_service_1 = require("./xema-authz.service");
18
+ exports.AUTHORIZE_ROUTE_METADATA = 'xema:authorize-route';
19
+ let XemaAuthorizeGuard = class XemaAuthorizeGuard {
20
+ reflector;
21
+ authz;
22
+ constructor(reflector, authz) {
23
+ this.reflector = reflector;
24
+ this.authz = authz;
25
+ }
26
+ async canActivate(context) {
27
+ const spec = this.reflector.getAllAndOverride(exports.AUTHORIZE_ROUTE_METADATA, [context.getHandler(), context.getClass()]);
28
+ if (spec === undefined) {
29
+ throw new Error('XemaAuthorizeGuard is mounted on a route with no @Authorize spec.');
30
+ }
31
+ const request = context
32
+ .switchToHttp()
33
+ .getRequest();
34
+ const id = request.params?.[spec.idParam];
35
+ if (id === undefined || id === '') {
36
+ throw new Error(`@Authorize names route parameter "${spec.idParam}", which the route does not carry.`);
37
+ }
38
+ await this.authz.assert((0, platform_common_1.getRequestContext)(request), spec.view, spec.action ?? spec.view, { type: spec.type, id }, spec.capability === undefined ? {} : { capability: spec.capability });
39
+ return true;
40
+ }
41
+ };
42
+ exports.XemaAuthorizeGuard = XemaAuthorizeGuard;
43
+ exports.XemaAuthorizeGuard = XemaAuthorizeGuard = __decorate([
44
+ (0, common_1.Injectable)(),
45
+ __metadata("design:paramtypes", [core_1.Reflector,
46
+ xema_authz_service_1.XemaAuthz])
47
+ ], XemaAuthorizeGuard);
48
+ function Authorize(spec) {
49
+ return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.AUTHORIZE_ROUTE_METADATA, spec), (0, common_1.UseGuards)(XemaAuthorizeGuard));
50
+ }
51
+ //# sourceMappingURL=authorize.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.decorator.js","sourceRoot":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,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CACrE,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAlCY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAGmB,gBAAS;QACb,8BAAS;GAHxB,kBAAkB,CAkC9B;AAYD,SAAgB,SAAS,CAAC,IAAwB;IAChD,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,gCAAwB,EAAE,IAAI,CAAC,EAC3C,IAAA,kBAAS,EAAC,kBAAkB,CAAC,CAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type AccessEvaluationRequest, type AccessEvaluationResponse, type AccessEvaluationsRequest, type AccessEvaluationsResponse, type ActionSearchRequest, type ActionSearchResponse, type ResourceSearchRequest, type ResourceSearchResponse, type SubjectSearchRequest, type SubjectSearchResponse } from '@xemahq/contracts/authzen';
2
+ import { type ServiceRegistry } from '@xemahq/contracts/service-registry';
3
+ import { IdentityBootstrapService } from '@xemahq/identity-client';
4
+ import { type XemaAuthorizationOptions } from './authorization.options';
5
+ export interface AuthzenPdpTransport {
6
+ evaluation(orgId: string, request: AccessEvaluationRequest): Promise<AccessEvaluationResponse>;
7
+ evaluations(orgId: string, request: AccessEvaluationsRequest): Promise<AccessEvaluationsResponse>;
8
+ searchResource(orgId: string, request: ResourceSearchRequest): Promise<ResourceSearchResponse>;
9
+ searchSubject(orgId: string, request: SubjectSearchRequest): Promise<SubjectSearchResponse>;
10
+ searchAction(orgId: string, request: ActionSearchRequest): Promise<ActionSearchResponse>;
11
+ }
12
+ export declare const AUTHZEN_PDP_TRANSPORT: unique symbol;
13
+ export declare class AuthzenPdpError extends Error {
14
+ readonly status: number;
15
+ readonly code: string | undefined;
16
+ constructor(message: string, status: number, code: string | undefined);
17
+ }
18
+ export declare class HttpAuthzenPdpTransport implements AuthzenPdpTransport {
19
+ private readonly registry;
20
+ private readonly identityBootstrap;
21
+ private readonly options;
22
+ constructor(registry: ServiceRegistry, identityBootstrap: IdentityBootstrapService, options: XemaAuthorizationOptions);
23
+ evaluation(orgId: string, request: AccessEvaluationRequest): Promise<AccessEvaluationResponse>;
24
+ evaluations(orgId: string, request: AccessEvaluationsRequest): Promise<AccessEvaluationsResponse>;
25
+ searchResource(orgId: string, request: ResourceSearchRequest): Promise<ResourceSearchResponse>;
26
+ searchSubject(orgId: string, request: SubjectSearchRequest): Promise<SubjectSearchResponse>;
27
+ searchAction(orgId: string, request: ActionSearchRequest): Promise<ActionSearchResponse>;
28
+ private post;
29
+ }
30
+ //# sourceMappingURL=authzen.transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authzen.transport.d.ts","sourceRoot":"","sources":["../src/authzen.transport.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAMnE,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,yBAAyB,CAAC;AAajC,MAAM,WAAW,mBAAmB;IAClC,UAAU,CACR,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACrC,WAAW,CACT,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACtC,cAAc,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,sBAAsB,CAAC,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