@venizia/ignis-kernel 0.5.0-2 → 0.5.0-4
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/dist/esm/base/applications/boot-sequence.d.ts +2 -3
- package/dist/esm/base/applications/boot-sequence.js +2 -17
- package/dist/esm/base/applications/boot-sequence.js.map +1 -1
- package/dist/esm/base/applications/common/constants.d.ts +3 -6
- package/dist/esm/base/applications/common/constants.js +3 -17
- package/dist/esm/base/applications/common/constants.js.map +1 -1
- package/dist/esm/base/applications/rest.js +3 -3
- package/dist/esm/base/applications/rest.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/constants/authentication.d.ts +3 -7
- package/dist/esm/base/auth/authenticate/common/constants/authentication.js +3 -11
- package/dist/esm/base/auth/authenticate/common/constants/authentication.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/constants/jose.d.ts +6 -15
- package/dist/esm/base/auth/authenticate/common/constants/jose.js +6 -25
- package/dist/esm/base/auth/authenticate/common/constants/jose.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/authorization.d.ts +4 -9
- package/dist/esm/base/auth/authorize/common/constants/authorization.js +4 -15
- package/dist/esm/base/auth/authorize/common/constants/authorization.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/enforcer.d.ts +5 -12
- package/dist/esm/base/auth/authorize/common/constants/enforcer.js +5 -26
- package/dist/esm/base/auth/authorize/common/constants/enforcer.js.map +1 -1
- package/dist/esm/base/controllers/common/constants.d.ts +3 -6
- package/dist/esm/base/controllers/common/constants.js +3 -11
- package/dist/esm/base/controllers/common/constants.js.map +1 -1
- package/dist/esm/base/controllers/factory/controller.js +1 -1
- package/dist/esm/base/controllers/factory/controller.js.map +1 -1
- package/dist/esm/base/datasources/common/types.d.ts +2 -3
- package/dist/esm/base/datasources/common/types.js +2 -5
- package/dist/esm/base/datasources/common/types.js.map +1 -1
- package/dist/esm/base/events/common/constants.d.ts +3 -4
- package/dist/esm/base/events/common/constants.js +3 -6
- package/dist/esm/base/events/common/constants.js.map +1 -1
- package/dist/esm/base/events/event-bus.d.ts +2 -2
- package/dist/esm/base/events/event-bus.js +6 -6
- package/dist/esm/base/events/event-bus.js.map +1 -1
- package/dist/esm/base/metadata/injectable.js +1 -1
- package/dist/esm/base/metadata/injectable.js.map +1 -1
- package/dist/esm/base/metadata/model-metadata.js +1 -1
- package/dist/esm/base/metadata/model-metadata.js.map +1 -1
- package/dist/esm/base/metadata/persistents/datasource.js +1 -1
- package/dist/esm/base/metadata/persistents/datasource.js.map +1 -1
- package/dist/esm/base/metadata/persistents/repository/validate.js +1 -1
- package/dist/esm/base/metadata/persistents/repository/validate.js.map +1 -1
- package/dist/esm/base/models/common/constants.d.ts +5 -11
- package/dist/esm/base/models/common/constants.js +5 -23
- package/dist/esm/base/models/common/constants.js.map +1 -1
- package/dist/esm/base/repositories/common/constants.d.ts +7 -18
- package/dist/esm/base/repositories/common/constants.js +7 -35
- package/dist/esm/base/repositories/common/constants.js.map +1 -1
- package/dist/esm/base/repositories/core/abstract.js +2 -2
- package/dist/esm/base/repositories/core/abstract.js.map +1 -1
- package/dist/esm/common/statuses/user.d.ts +2 -3
- package/dist/esm/common/statuses/user.js +2 -5
- package/dist/esm/common/statuses/user.js.map +1 -1
- package/dist/esm/helpers/inversion/common/constants.d.ts +3 -6
- package/dist/esm/helpers/inversion/common/constants.js +3 -18
- package/dist/esm/helpers/inversion/common/constants.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/model.d.ts +1 -1
- package/dist/esm/helpers/inversion/common/types/model.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,47 +1,28 @@
|
|
|
1
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/** The token standards the JWT service can use: `JWS` (shared-secret signing) or `JWKS` (key-pair signing, published or fetched as a key set). */
|
|
2
|
-
export class JOSEStandards {
|
|
3
|
+
export class JOSEStandards extends ConstClass {
|
|
3
4
|
static { this.JWS = 'JWS'; }
|
|
4
5
|
static { this.JWKS = 'JWKS'; }
|
|
5
|
-
static { this.SCHEME_SET = new Set([this.JWS, this.JWKS]); }
|
|
6
|
-
static isValid(input) {
|
|
7
|
-
return this.SCHEME_SET.has(input);
|
|
8
|
-
}
|
|
9
6
|
}
|
|
10
7
|
/** The role a JWKS setup plays: `issuer` signs tokens, `verifier` checks them against a remote key set. */
|
|
11
|
-
export class JWKSModes {
|
|
8
|
+
export class JWKSModes extends ConstClass {
|
|
12
9
|
static { this.ISSUER = 'issuer'; }
|
|
13
10
|
static { this.VERIFIER = 'verifier'; }
|
|
14
|
-
static { this.SCHEME_SET = new Set([this.ISSUER, this.VERIFIER]); }
|
|
15
|
-
static isValid(input) {
|
|
16
|
-
return this.SCHEME_SET.has(input);
|
|
17
|
-
}
|
|
18
11
|
}
|
|
19
12
|
/** Where JWKS key material comes from: inline `text` content or a `file` path. */
|
|
20
|
-
export class JWKSKeyDrivers {
|
|
13
|
+
export class JWKSKeyDrivers extends ConstClass {
|
|
21
14
|
static { this.TEXT = 'text'; }
|
|
22
15
|
static { this.FILE = 'file'; }
|
|
23
|
-
static { this.SCHEME_SET = new Set([this.TEXT, this.FILE]); }
|
|
24
|
-
static isValid(input) {
|
|
25
|
-
return this.SCHEME_SET.has(input);
|
|
26
|
-
}
|
|
27
16
|
}
|
|
28
17
|
/** Encoding of JWKS key material: `pem` or `jwk`. */
|
|
29
|
-
export class JWKSKeyFormats {
|
|
18
|
+
export class JWKSKeyFormats extends ConstClass {
|
|
30
19
|
static { this.PEM = 'pem'; }
|
|
31
20
|
static { this.JWK = 'jwk'; }
|
|
32
|
-
static { this.SCHEME_SET = new Set([this.PEM, this.JWK]); }
|
|
33
|
-
static isValid(input) {
|
|
34
|
-
return this.SCHEME_SET.has(input);
|
|
35
|
-
}
|
|
36
21
|
}
|
|
37
22
|
/** The signing algorithms a JWKS issuer supports. */
|
|
38
|
-
export class JWKSAlgorithms {
|
|
23
|
+
export class JWKSAlgorithms extends ConstClass {
|
|
39
24
|
static { this.ES256 = 'ES256'; }
|
|
40
25
|
static { this.RS256 = 'RS256'; }
|
|
41
26
|
static { this.EDDSA = 'EdDSA'; }
|
|
42
|
-
static { this.SCHEME_SET = new Set([this.ES256, this.RS256, this.EDDSA]); }
|
|
43
|
-
static isValid(value) {
|
|
44
|
-
return this.SCHEME_SET.has(value);
|
|
45
|
-
}
|
|
46
27
|
}
|
|
47
28
|
//# sourceMappingURL=jose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jose.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authenticate/common/constants/jose.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jose.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authenticate/common/constants/jose.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,kJAAkJ;AAClJ,MAAM,OAAO,aAAc,SAAQ,UAAU;aAC3B,QAAG,GAAG,KAAK,CAAC;aACZ,SAAI,GAAG,MAAM,CAAC;;AAMhC,2GAA2G;AAC3G,MAAM,OAAO,SAAU,SAAQ,UAAU;aACvB,WAAM,GAAG,QAAQ,CAAC;aAClB,aAAQ,GAAG,UAAU,CAAC;;AAMxC,kFAAkF;AAClF,MAAM,OAAO,cAAe,SAAQ,UAAU;aAC5B,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;;AAMhC,qDAAqD;AACrD,MAAM,OAAO,cAAe,SAAQ,UAAU;aAC5B,QAAG,GAAG,KAAK,CAAC;aACZ,QAAG,GAAG,KAAK,CAAC;;AAM9B,qDAAqD;AACrD,MAAM,OAAO,cAAe,SAAQ,UAAU;aAC5B,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { ConstClass } from '@venizia/ignis-helpers/common';\n\n/** The token standards the JWT service can use: `JWS` (shared-secret signing) or `JWKS` (key-pair signing, published or fetched as a key set). */\nexport class JOSEStandards extends ConstClass {\n static readonly JWS = 'JWS';\n static readonly JWKS = 'JWKS';\n}\n\n/** A valid value of `JOSEStandards`. */\nexport type TJOSEStandard = TConstValue<typeof JOSEStandards>;\n\n/** The role a JWKS setup plays: `issuer` signs tokens, `verifier` checks them against a remote key set. */\nexport class JWKSModes extends ConstClass {\n static readonly ISSUER = 'issuer';\n static readonly VERIFIER = 'verifier';\n}\n\n/** A valid value of `JWKSModes`. */\nexport type TJWKSMode = TConstValue<typeof JWKSModes>;\n\n/** Where JWKS key material comes from: inline `text` content or a `file` path. */\nexport class JWKSKeyDrivers extends ConstClass {\n static readonly TEXT = 'text';\n static readonly FILE = 'file';\n}\n\n/** A valid value of `JWKSKeyDrivers`. */\nexport type TJWKSKeyDriver = TConstValue<typeof JWKSKeyDrivers>;\n\n/** Encoding of JWKS key material: `pem` or `jwk`. */\nexport class JWKSKeyFormats extends ConstClass {\n static readonly PEM = 'pem';\n static readonly JWK = 'jwk';\n}\n\n/** A valid value of `JWKSKeyFormats`. */\nexport type TJWKSKeyFormat = TConstValue<typeof JWKSKeyFormats>;\n\n/** The signing algorithms a JWKS issuer supports. */\nexport class JWKSAlgorithms extends ConstClass {\n static readonly ES256 = 'ES256';\n static readonly RS256 = 'RS256';\n static readonly EDDSA = 'EdDSA';\n}\n\n/** Valid JWKS algorithm values. */\nexport type TJWKSAlgorithm = TConstValue<typeof JWKSAlgorithms>;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
2
|
import { AuthorizationRole } from '../../models/authorization-role.model.js';
|
|
3
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
3
4
|
/** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */
|
|
4
5
|
export declare class Authorization {
|
|
5
6
|
static readonly RULES = "authorization.rules";
|
|
@@ -28,12 +29,10 @@ export declare class AuthorizationActions {
|
|
|
28
29
|
/** Union of the `AuthorizationActions` values. */
|
|
29
30
|
export type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;
|
|
30
31
|
/** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */
|
|
31
|
-
export declare class AuthorizationDecisions {
|
|
32
|
+
export declare class AuthorizationDecisions extends ConstClass {
|
|
32
33
|
static readonly ALLOW = "allow";
|
|
33
34
|
static readonly DENY = "deny";
|
|
34
35
|
static readonly ABSTAIN = "abstain";
|
|
35
|
-
static readonly SCHEME_SET: Set<string>;
|
|
36
|
-
static isValid(input: string): boolean;
|
|
37
36
|
static isAllow(input: string | number): boolean;
|
|
38
37
|
static isDeny(input: string | number): boolean;
|
|
39
38
|
static isAbstain(input: string | number): boolean;
|
|
@@ -51,13 +50,11 @@ export declare class AuthorizationRoles {
|
|
|
51
50
|
static isValid(input: string): boolean;
|
|
52
51
|
}
|
|
53
52
|
/** Scope literals a grant can carry instead of a concrete domain. */
|
|
54
|
-
export declare class AuthorizationDomainScopes {
|
|
53
|
+
export declare class AuthorizationDomainScopes extends ConstClass {
|
|
55
54
|
/** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */
|
|
56
55
|
static readonly ANY_MEMBER = "ANY_MEMBER";
|
|
57
56
|
/** Grant applies system-wide, bypassing membership - super-admin only. */
|
|
58
57
|
static readonly SYSTEM_WIDE = "SYSTEM_WIDE";
|
|
59
|
-
static readonly SCHEME_SET: Set<string>;
|
|
60
|
-
static isValid(input: string): boolean;
|
|
61
58
|
}
|
|
62
59
|
/** Union of the `AuthorizationDomainScopes` values. */
|
|
63
60
|
export type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;
|
|
@@ -129,13 +126,11 @@ export declare class AuthorizationPolicyVariants {
|
|
|
129
126
|
/** The `variant` column's full value set, derived from {@link AuthorizationPolicyVariants.ALL} - never hand-list the seven strings again. */
|
|
130
127
|
export type TAuthorizationPolicyVariant = (typeof AuthorizationPolicyVariants.ALL)[number]['action'];
|
|
131
128
|
/** Where an `IAuthorizationDomainSource` reads the request domain from. */
|
|
132
|
-
export declare class AuthorizationDomainSources {
|
|
129
|
+
export declare class AuthorizationDomainSources extends ConstClass {
|
|
133
130
|
static readonly PARAM = "param";
|
|
134
131
|
static readonly HEADER = "header";
|
|
135
132
|
static readonly QUERY = "query";
|
|
136
133
|
static readonly CONTEXT = "context";
|
|
137
|
-
static readonly SCHEME_SET: Set<string>;
|
|
138
|
-
static isValid(value: string): boolean;
|
|
139
134
|
}
|
|
140
135
|
/** Valid authorization domain source values. */
|
|
141
136
|
export type TAuthorizationDomainSource = TConstValue<typeof AuthorizationDomainSources>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthorizationRole } from '../../models/authorization-role.model.js';
|
|
2
2
|
import { CasbinRuleVariants } from './enforcer.js';
|
|
3
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
3
4
|
/** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */
|
|
4
5
|
export class Authorization {
|
|
5
6
|
static { this.RULES = 'authorization.rules'; }
|
|
@@ -41,14 +42,10 @@ export class AuthorizationActions {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
/** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */
|
|
44
|
-
export class AuthorizationDecisions {
|
|
45
|
+
export class AuthorizationDecisions extends ConstClass {
|
|
45
46
|
static { this.ALLOW = 'allow'; }
|
|
46
47
|
static { this.DENY = 'deny'; }
|
|
47
48
|
static { this.ABSTAIN = 'abstain'; }
|
|
48
|
-
static { this.SCHEME_SET = new Set([this.ALLOW, this.DENY, this.ABSTAIN]); }
|
|
49
|
-
static isValid(input) {
|
|
50
|
-
return this.SCHEME_SET.has(input);
|
|
51
|
-
}
|
|
52
49
|
static isAllow(input) {
|
|
53
50
|
if (typeof input === 'number') {
|
|
54
51
|
return input > 0;
|
|
@@ -102,15 +99,11 @@ export class AuthorizationRoles {
|
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
101
|
/** Scope literals a grant can carry instead of a concrete domain. */
|
|
105
|
-
export class AuthorizationDomainScopes {
|
|
102
|
+
export class AuthorizationDomainScopes extends ConstClass {
|
|
106
103
|
/** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */
|
|
107
104
|
static { this.ANY_MEMBER = 'ANY_MEMBER'; }
|
|
108
105
|
/** Grant applies system-wide, bypassing membership - super-admin only. */
|
|
109
106
|
static { this.SYSTEM_WIDE = 'SYSTEM_WIDE'; }
|
|
110
|
-
static { this.SCHEME_SET = new Set([this.ANY_MEMBER, this.SYSTEM_WIDE]); }
|
|
111
|
-
static isValid(input) {
|
|
112
|
-
return this.SCHEME_SET.has(input);
|
|
113
|
-
}
|
|
114
107
|
}
|
|
115
108
|
/** Edge kinds in the `PolicyDefinition` table (each row: subject -> target, `variant` = kind), carrying `action` (DB `variant` value) + `rule` (casbin prefix emitted per edge). Per-USER edges: GRANT, ASSIGN_ROLE, JOIN_DOMAIN; shared org-structure edges: the *_INHERITS ones. */
|
|
116
109
|
export class AuthorizationPolicyVariants {
|
|
@@ -157,14 +150,10 @@ export class AuthorizationPolicyVariants {
|
|
|
157
150
|
}
|
|
158
151
|
}
|
|
159
152
|
/** Where an `IAuthorizationDomainSource` reads the request domain from. */
|
|
160
|
-
export class AuthorizationDomainSources {
|
|
153
|
+
export class AuthorizationDomainSources extends ConstClass {
|
|
161
154
|
static { this.PARAM = 'param'; }
|
|
162
155
|
static { this.HEADER = 'header'; }
|
|
163
156
|
static { this.QUERY = 'query'; }
|
|
164
157
|
static { this.CONTEXT = 'context'; }
|
|
165
|
-
static { this.SCHEME_SET = new Set([this.PARAM, this.HEADER, this.QUERY, this.CONTEXT]); }
|
|
166
|
-
static isValid(value) {
|
|
167
|
-
return this.SCHEME_SET.has(value);
|
|
168
|
-
}
|
|
169
158
|
}
|
|
170
159
|
//# sourceMappingURL=authorization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/authorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,kKAAkK;AAClK,MAAM,OAAO,aAAa;aACR,UAAK,GAAG,qBAAqB,CAAC;aAC9B,uBAAkB,GAAG,oBAAoB,CAAC;aAC1C,aAAQ,GAAG,wBAAwB,CAAC;aACpC,WAAM,GAAG,sBAAsB,CAAC;;AAGlD,oJAAoJ;AACpJ,MAAM,OAAO,oBAAoB;aACf,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;aAEpB,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;IAElC,+FAA+F;aAC/E,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QAEZ,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,MAAM;QAEX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;aAEa,YAAO,GAGlB;QACH,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;QACzC,EAAE,KAAK,EAAE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izationRole } from '../../models/authorization-role.model';\nimport { CasbinRuleVariants } from './enforcer';\n\n/** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */\nexport class Authorization {\n static readonly RULES = 'authorization.rules';\n static readonly SKIP_AUTHORIZATION = 'authorization.skip';\n static readonly ENFORCER = 'authorization.enforcer';\n static readonly DOMAIN = 'authorization.domain';\n}\n\n/** Actions a grant or request can name. `manage` covers `read`/`write`/`execute`, and `write` covers `create`/`update`/`delete` (see `LATTICE`). */\nexport class AuthorizationActions {\n static readonly CREATE = 'create';\n static readonly UPDATE = 'update';\n static readonly DELETE = 'delete';\n static readonly EXECUTE = 'execute';\n\n static readonly READ = 'read';\n static readonly WRITE = 'write';\n static readonly MANAGE = 'manage';\n\n /** Grant-mode marker for a subset grant carrying `metadata.ops`; never a member of LATTICE. */\n static readonly CUSTOM = 'custom';\n\n static readonly SCHEME_SET = new Set([\n this.CREATE,\n this.UPDATE,\n this.DELETE,\n this.EXECUTE,\n\n this.READ,\n this.WRITE,\n this.MANAGE,\n\n this.CUSTOM,\n ]);\n\n static readonly LATTICE: ReadonlyArray<{\n child: TAuthorizationAction;\n parent: TAuthorizationAction;\n }> = [\n { child: this.READ, parent: this.MANAGE },\n { child: this.WRITE, parent: this.MANAGE },\n { child: this.EXECUTE, parent: this.MANAGE },\n { child: this.CREATE, parent: this.WRITE },\n { child: this.UPDATE, parent: this.WRITE },\n { child: this.DELETE, parent: this.WRITE },\n ];\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n/** Union of the `AuthorizationActions` values. */\nexport type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;\n\n/** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */\nexport class AuthorizationDecisions {\n static readonly ALLOW = 'allow';\n static readonly DENY = 'deny';\n static readonly ABSTAIN = 'abstain';\n\n static readonly SCHEME_SET = new Set([this.ALLOW, this.DENY, this.ABSTAIN]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n\n static isAllow(input: string | number): boolean {\n if (typeof input === 'number') {\n return input > 0;\n }\n\n return input.toLowerCase() === this.ALLOW;\n }\n\n static isDeny(input: string | number): boolean {\n if (typeof input === 'number') {\n return input < 0;\n }\n\n return input.toLowerCase() === this.DENY;\n }\n\n static isAbstain(input: string | number): boolean {\n if (typeof input === 'number') {\n return input === 0;\n }\n\n return input.toLowerCase() === this.ABSTAIN;\n }\n}\n/** Union of the `AuthorizationDecisions` values. */\nexport type TAuthorizationDecision = TConstValue<typeof AuthorizationDecisions>;\n\n/** Built-in roles ordered by priority (`super-admin` 999, `admin` 900, `user` 10, `guest` 1, `unknown-user` 0). `SCHEME_SET` and `isValid` work on the role `identifier` (e.g. `010_user`), not the bare name. */\nexport class AuthorizationRoles {\n static readonly SUPER_ADMIN = AuthorizationRole.build({\n name: 'super-admin',\n priority: 999,\n });\n\n static readonly ADMIN = AuthorizationRole.build({\n name: 'admin',\n priority: 900,\n });\n\n static readonly USER = AuthorizationRole.build({\n name: 'user',\n priority: 10,\n });\n\n static readonly GUEST = AuthorizationRole.build({\n name: 'guest',\n priority: 1,\n });\n\n static readonly UNKNOWN_USER = AuthorizationRole.build({\n name: 'unknown-user',\n priority: 0,\n });\n\n static readonly SCHEME_SET = new Set<string>([\n this.SUPER_ADMIN.identifier,\n this.ADMIN.identifier,\n this.USER.identifier,\n this.GUEST.identifier,\n this.UNKNOWN_USER.identifier,\n ]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Scope literals a grant can carry instead of a concrete domain. */\nexport class AuthorizationDomainScopes {\n /** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */\n static readonly ANY_MEMBER = 'ANY_MEMBER';\n\n /** Grant applies system-wide, bypassing membership - super-admin only. */\n static readonly SYSTEM_WIDE = 'SYSTEM_WIDE';\n\n static readonly SCHEME_SET = new Set([this.ANY_MEMBER, this.SYSTEM_WIDE]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n/** Union of the `AuthorizationDomainScopes` values. */\nexport type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;\n\n/** Edge kinds in the `PolicyDefinition` table (each row: subject -> target, `variant` = kind), carrying `action` (DB `variant` value) + `rule` (casbin prefix emitted per edge). Per-USER edges: GRANT, ASSIGN_ROLE, JOIN_DOMAIN; shared org-structure edges: the *_INHERITS ones. */\nexport class AuthorizationPolicyVariants {\n /** Give a Permission to a User/Role (row also carries action / effect / domain). casbin `p`: `p, <Role|User>_<id>, <domain>, <permissionCode>, <action>, <allow|deny>` */\n static readonly GRANT = { action: 'grant', rule: CasbinRuleVariants.P } as const;\n\n /** Give a User a Role (optionally domain-scoped; no domain -> `*` = every domain). casbin `g`: `g, User_<id>, Role_<id>, <domain|*>` */\n static readonly ASSIGN_ROLE = { action: 'assign_role', rule: CasbinRuleVariants.G } as const;\n\n /** A Role inherits another Role (DAG). Shares `g` with ASSIGN_ROLE so user -> role -> parent-role resolves in one lookup. Emitted with domain `*`: `g, Role_<child>, Role_<parent>, *` */\n static readonly ROLE_INHERITS = { action: 'role_inherits', rule: CasbinRuleVariants.G } as const;\n\n /** User is a member of a Domain; powers the `ANY_MEMBER` grant scope via `g2(r.sub, r.dom)`. casbin `g2`: `g2, User_<id>, <Type>_<domainId>` */\n static readonly JOIN_DOMAIN = { action: 'join_domain', rule: CasbinRuleVariants.G2 } as const;\n\n /** DOMAIN axis (`dom`): domain nesting. Matcher: `g3(r.dom, p.dom)` + self-link so an exact domain always matches itself. casbin `g3`: `g3, <Type>_<childId>, <Type>_<parentId>` */\n static readonly DOMAIN_INHERITS = {\n action: 'domain_inherits',\n rule: CasbinRuleVariants.G3,\n } as const;\n\n /** RESOURCE axis (`obj`), NON-standard nesting only - dotted nesting (`Order.findById ⊂ Order`) is handled by `objectMatch` WITHOUT an edge. Matcher: `objectMatch(r.obj, p.obj) || g4(r.obj, p.obj)`, casbin `g4`: `g4, <childCode>, <parentCode>` */\n static readonly RESOURCE_INHERITS = {\n action: 'resource_inherits',\n rule: CasbinRuleVariants.G4,\n } as const;\n\n /** ACTION axis (`act`): a narrow action covered by a broader one; no dotted shortcut, so it needs an explicit edge. Matcher: `g5(r.act, p.act)`, casbin `g5`: `g5, <childAction>, <parentAction>`. g4 + g5 combine multiplicatively: `manage Order` covers a `read OrderItem` request. */\n static readonly ACTION_INHERITS = {\n action: 'action_inherits',\n rule: CasbinRuleVariants.G5,\n } as const;\n\n /** Every edge kind, in declaration order - the one place the scheme sets and the `variant` column's literal type both derive from. */\n static readonly ALL = [\n this.GRANT,\n this.ASSIGN_ROLE,\n this.ROLE_INHERITS,\n this.JOIN_DOMAIN,\n this.DOMAIN_INHERITS,\n this.RESOURCE_INHERITS,\n this.ACTION_INHERITS,\n ] as const;\n\n static readonly ACTION_SCHEME_SET = new Set(this.ALL.map((variant) => variant.action.toString()));\n\n static readonly RULE_SCHEME_SET = new Set(this.ALL.map((variant) => variant.rule.toString()));\n\n static isValidAction(input: string): boolean {\n return this.ACTION_SCHEME_SET.has(input);\n }\n\n static isValidRule(input: string): boolean {\n return this.RULE_SCHEME_SET.has(input);\n }\n}\n\n/** The `variant` column's full value set, derived from {@link AuthorizationPolicyVariants.ALL} - never hand-list the seven strings again. */\nexport type TAuthorizationPolicyVariant =\n (typeof AuthorizationPolicyVariants.ALL)[number]['action'];\n\n/** Where an `IAuthorizationDomainSource` reads the request domain from. */\nexport class AuthorizationDomainSources {\n static readonly PARAM = 'param';\n static readonly HEADER = 'header';\n static readonly QUERY = 'query';\n static readonly CONTEXT = 'context';\n\n static readonly SCHEME_SET = new Set<string>([this.PARAM, this.HEADER, this.QUERY, this.CONTEXT]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid authorization domain source values. */\nexport type TAuthorizationDomainSource = TConstValue<typeof AuthorizationDomainSources>;\n"]}
|
|
1
|
+
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/authorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,kKAAkK;AAClK,MAAM,OAAO,aAAa;aACR,UAAK,GAAG,qBAAqB,CAAC;aAC9B,uBAAkB,GAAG,oBAAoB,CAAC;aAC1C,aAAQ,GAAG,wBAAwB,CAAC;aACpC,WAAM,GAAG,sBAAsB,CAAC;;AAGlD,oJAAoJ;AACpJ,MAAM,OAAO,oBAAoB;aACf,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;aAEpB,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;IAElC,+FAA+F;aAC/E,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QAEZ,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,MAAM;QAEX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;aAEa,YAAO,GAGlB;QACH,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;QACzC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;QAC1C,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EA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AAC,KAAa;QAChC,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,KAAa;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;;AAOH,2EAA2E;AAC3E,MAAM,OAAO,0BAA2B,SAAQ,UAAU;aACxC,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,UAAK,GAAG,OAAO,CAAC;aAChB,YAAO,GAAG,SAAS,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { AuthorizationRole } from '../../models/authorization-role.model';\nimport { CasbinRuleVariants } from './enforcer';\nimport { ConstClass } from '@venizia/ignis-helpers/common';\n\n/** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */\nexport class Authorization {\n static readonly RULES = 'authorization.rules';\n static readonly SKIP_AUTHORIZATION = 'authorization.skip';\n static readonly ENFORCER = 'authorization.enforcer';\n static readonly DOMAIN = 'authorization.domain';\n}\n\n/** Actions a grant or request can name. `manage` covers `read`/`write`/`execute`, and `write` covers `create`/`update`/`delete` (see `LATTICE`). */\nexport class AuthorizationActions {\n static readonly CREATE = 'create';\n static readonly UPDATE = 'update';\n static readonly DELETE = 'delete';\n static readonly EXECUTE = 'execute';\n\n static readonly READ = 'read';\n static readonly WRITE = 'write';\n static readonly MANAGE = 'manage';\n\n /** Grant-mode marker for a subset grant carrying `metadata.ops`; never a member of LATTICE. */\n static readonly CUSTOM = 'custom';\n\n static readonly SCHEME_SET = new Set([\n this.CREATE,\n this.UPDATE,\n this.DELETE,\n this.EXECUTE,\n\n this.READ,\n this.WRITE,\n this.MANAGE,\n\n this.CUSTOM,\n ]);\n\n static readonly LATTICE: ReadonlyArray<{\n child: TAuthorizationAction;\n parent: TAuthorizationAction;\n }> = [\n { child: this.READ, parent: this.MANAGE },\n { child: this.WRITE, parent: this.MANAGE },\n { child: this.EXECUTE, parent: this.MANAGE },\n { child: this.CREATE, parent: this.WRITE },\n { child: this.UPDATE, parent: this.WRITE },\n { child: this.DELETE, parent: this.WRITE },\n ];\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n/** Union of the `AuthorizationActions` values. */\nexport type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;\n\n/** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */\nexport class AuthorizationDecisions extends ConstClass {\n static readonly ALLOW = 'allow';\n static readonly DENY = 'deny';\n static readonly ABSTAIN = 'abstain';\n\n static isAllow(input: string | number): boolean {\n if (typeof input === 'number') {\n return input > 0;\n }\n\n return input.toLowerCase() === this.ALLOW;\n }\n\n static isDeny(input: string | number): boolean {\n if (typeof input === 'number') {\n return input < 0;\n }\n\n return input.toLowerCase() === this.DENY;\n }\n\n static isAbstain(input: string | number): boolean {\n if (typeof input === 'number') {\n return input === 0;\n }\n\n return input.toLowerCase() === this.ABSTAIN;\n }\n}\n/** Union of the `AuthorizationDecisions` values. */\nexport type TAuthorizationDecision = TConstValue<typeof AuthorizationDecisions>;\n\n/** Built-in roles ordered by priority (`super-admin` 999, `admin` 900, `user` 10, `guest` 1, `unknown-user` 0). `SCHEME_SET` and `isValid` work on the role `identifier` (e.g. `010_user`), not the bare name. */\nexport class AuthorizationRoles {\n static readonly SUPER_ADMIN = AuthorizationRole.build({\n name: 'super-admin',\n priority: 999,\n });\n\n static readonly ADMIN = AuthorizationRole.build({\n name: 'admin',\n priority: 900,\n });\n\n static readonly USER = AuthorizationRole.build({\n name: 'user',\n priority: 10,\n });\n\n static readonly GUEST = AuthorizationRole.build({\n name: 'guest',\n priority: 1,\n });\n\n static readonly UNKNOWN_USER = AuthorizationRole.build({\n name: 'unknown-user',\n priority: 0,\n });\n\n static readonly SCHEME_SET = new Set<string>([\n this.SUPER_ADMIN.identifier,\n this.ADMIN.identifier,\n this.USER.identifier,\n this.GUEST.identifier,\n this.UNKNOWN_USER.identifier,\n ]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Scope literals a grant can carry instead of a concrete domain. */\nexport class AuthorizationDomainScopes extends ConstClass {\n /** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */\n static readonly ANY_MEMBER = 'ANY_MEMBER';\n\n /** Grant applies system-wide, bypassing membership - super-admin only. */\n static readonly SYSTEM_WIDE = 'SYSTEM_WIDE';\n}\n/** Union of the `AuthorizationDomainScopes` values. */\nexport type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;\n\n/** Edge kinds in the `PolicyDefinition` table (each row: subject -> target, `variant` = kind), carrying `action` (DB `variant` value) + `rule` (casbin prefix emitted per edge). Per-USER edges: GRANT, ASSIGN_ROLE, JOIN_DOMAIN; shared org-structure edges: the *_INHERITS ones. */\nexport class AuthorizationPolicyVariants {\n /** Give a Permission to a User/Role (row also carries action / effect / domain). casbin `p`: `p, <Role|User>_<id>, <domain>, <permissionCode>, <action>, <allow|deny>` */\n static readonly GRANT = { action: 'grant', rule: CasbinRuleVariants.P } as const;\n\n /** Give a User a Role (optionally domain-scoped; no domain -> `*` = every domain). casbin `g`: `g, User_<id>, Role_<id>, <domain|*>` */\n static readonly ASSIGN_ROLE = { action: 'assign_role', rule: CasbinRuleVariants.G } as const;\n\n /** A Role inherits another Role (DAG). Shares `g` with ASSIGN_ROLE so user -> role -> parent-role resolves in one lookup. Emitted with domain `*`: `g, Role_<child>, Role_<parent>, *` */\n static readonly ROLE_INHERITS = { action: 'role_inherits', rule: CasbinRuleVariants.G } as const;\n\n /** User is a member of a Domain; powers the `ANY_MEMBER` grant scope via `g2(r.sub, r.dom)`. casbin `g2`: `g2, User_<id>, <Type>_<domainId>` */\n static readonly JOIN_DOMAIN = { action: 'join_domain', rule: CasbinRuleVariants.G2 } as const;\n\n /** DOMAIN axis (`dom`): domain nesting. Matcher: `g3(r.dom, p.dom)` + self-link so an exact domain always matches itself. casbin `g3`: `g3, <Type>_<childId>, <Type>_<parentId>` */\n static readonly DOMAIN_INHERITS = {\n action: 'domain_inherits',\n rule: CasbinRuleVariants.G3,\n } as const;\n\n /** RESOURCE axis (`obj`), NON-standard nesting only - dotted nesting (`Order.findById ⊂ Order`) is handled by `objectMatch` WITHOUT an edge. Matcher: `objectMatch(r.obj, p.obj) || g4(r.obj, p.obj)`, casbin `g4`: `g4, <childCode>, <parentCode>` */\n static readonly RESOURCE_INHERITS = {\n action: 'resource_inherits',\n rule: CasbinRuleVariants.G4,\n } as const;\n\n /** ACTION axis (`act`): a narrow action covered by a broader one; no dotted shortcut, so it needs an explicit edge. Matcher: `g5(r.act, p.act)`, casbin `g5`: `g5, <childAction>, <parentAction>`. g4 + g5 combine multiplicatively: `manage Order` covers a `read OrderItem` request. */\n static readonly ACTION_INHERITS = {\n action: 'action_inherits',\n rule: CasbinRuleVariants.G5,\n } as const;\n\n /** Every edge kind, in declaration order - the one place the scheme sets and the `variant` column's literal type both derive from. */\n static readonly ALL = [\n this.GRANT,\n this.ASSIGN_ROLE,\n this.ROLE_INHERITS,\n this.JOIN_DOMAIN,\n this.DOMAIN_INHERITS,\n this.RESOURCE_INHERITS,\n this.ACTION_INHERITS,\n ] as const;\n\n static readonly ACTION_SCHEME_SET = new Set(this.ALL.map((variant) => variant.action.toString()));\n\n static readonly RULE_SCHEME_SET = new Set(this.ALL.map((variant) => variant.rule.toString()));\n\n static isValidAction(input: string): boolean {\n return this.ACTION_SCHEME_SET.has(input);\n }\n\n static isValidRule(input: string): boolean {\n return this.RULE_SCHEME_SET.has(input);\n }\n}\n\n/** The `variant` column's full value set, derived from {@link AuthorizationPolicyVariants.ALL} - never hand-list the seven strings again. */\nexport type TAuthorizationPolicyVariant =\n (typeof AuthorizationPolicyVariants.ALL)[number]['action'];\n\n/** Where an `IAuthorizationDomainSource` reads the request domain from. */\nexport class AuthorizationDomainSources extends ConstClass {\n static readonly PARAM = 'param';\n static readonly HEADER = 'header';\n static readonly QUERY = 'query';\n static readonly CONTEXT = 'context';\n}\n\n/** Valid authorization domain source values. */\nexport type TAuthorizationDomainSource = TConstValue<typeof AuthorizationDomainSources>;\n"]}
|
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
3
|
/** Kinds of enforcer a registration can declare; `casbin` takes `ICasbinEnforcerOptions`, `custom` takes untyped options. */
|
|
3
|
-
export declare class AuthorizationEnforcerTypes {
|
|
4
|
+
export declare class AuthorizationEnforcerTypes extends ConstClass {
|
|
4
5
|
static readonly CASBIN = "casbin";
|
|
5
6
|
static readonly CUSTOM = "custom";
|
|
6
|
-
static readonly SCHEME_SET: Set<string>;
|
|
7
|
-
static isValid(input: string): boolean;
|
|
8
7
|
}
|
|
9
8
|
/** Union of the `AuthorizationEnforcerTypes` values. */
|
|
10
9
|
export type TAuthorizationEnforcerType = TConstValue<typeof AuthorizationEnforcerTypes>;
|
|
11
10
|
/** Cache backends for a Casbin enforcer's per-user policy lines. */
|
|
12
|
-
export declare class CasbinEnforcerCachedDrivers {
|
|
11
|
+
export declare class CasbinEnforcerCachedDrivers extends ConstClass {
|
|
13
12
|
static readonly REDIS = "redis";
|
|
14
|
-
static readonly SCHEME_SET: Set<string>;
|
|
15
|
-
static isValid(input: string): boolean;
|
|
16
13
|
}
|
|
17
14
|
/** Union of the `CasbinEnforcerCachedDrivers` values. */
|
|
18
15
|
export type TCasbinEnforcerCachedDriver = TConstValue<typeof CasbinEnforcerCachedDrivers>;
|
|
19
16
|
/** Where a Casbin enforcer reads its model from: a `file` path or inline `text`. */
|
|
20
|
-
export declare class CasbinEnforcerModelDrivers {
|
|
17
|
+
export declare class CasbinEnforcerModelDrivers extends ConstClass {
|
|
21
18
|
static readonly FILE = "file";
|
|
22
19
|
static readonly TEXT = "text";
|
|
23
|
-
static readonly SCHEME_SET: Set<string>;
|
|
24
|
-
static isValid(input: string): boolean;
|
|
25
20
|
}
|
|
26
21
|
/** Union of the `CasbinEnforcerModelDrivers` values. */
|
|
27
22
|
export type TCasbinEnforcerModelDriver = TConstValue<typeof CasbinEnforcerModelDrivers>;
|
|
28
23
|
/** Casbin matching functions selectable for the domain match in `ICasbinEnforcerOptions.domainMatching`. */
|
|
29
|
-
export declare class CasbinDomainMatchingFunctions {
|
|
24
|
+
export declare class CasbinDomainMatchingFunctions extends ConstClass {
|
|
30
25
|
/** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */
|
|
31
26
|
static readonly KEY_MATCH = "keyMatch";
|
|
32
27
|
/** Adds URL-path `:param` segment matching. */
|
|
@@ -37,8 +32,6 @@ export declare class CasbinDomainMatchingFunctions {
|
|
|
37
32
|
static readonly KEY_MATCH_4 = "keyMatch4";
|
|
38
33
|
/** Treats the stored/policy value as a full regular expression. */
|
|
39
34
|
static readonly REGEX_MATCH = "regexMatch";
|
|
40
|
-
static readonly SCHEME_SET: Set<string>;
|
|
41
|
-
static isValid(input: string): boolean;
|
|
42
35
|
}
|
|
43
36
|
/** Union of the `CasbinDomainMatchingFunctions` values. */
|
|
44
37
|
export type TCasbinDomainMatchingFunction = TConstValue<typeof CasbinDomainMatchingFunctions>;
|
|
@@ -1,31 +1,20 @@
|
|
|
1
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/** Kinds of enforcer a registration can declare; `casbin` takes `ICasbinEnforcerOptions`, `custom` takes untyped options. */
|
|
2
|
-
export class AuthorizationEnforcerTypes {
|
|
3
|
+
export class AuthorizationEnforcerTypes extends ConstClass {
|
|
3
4
|
static { this.CASBIN = 'casbin'; }
|
|
4
5
|
static { this.CUSTOM = 'custom'; }
|
|
5
|
-
static { this.SCHEME_SET = new Set([this.CASBIN, this.CUSTOM]); }
|
|
6
|
-
static isValid(input) {
|
|
7
|
-
return this.SCHEME_SET.has(input);
|
|
8
|
-
}
|
|
9
6
|
}
|
|
10
7
|
/** Cache backends for a Casbin enforcer's per-user policy lines. */
|
|
11
|
-
export class CasbinEnforcerCachedDrivers {
|
|
8
|
+
export class CasbinEnforcerCachedDrivers extends ConstClass {
|
|
12
9
|
static { this.REDIS = 'redis'; }
|
|
13
|
-
static { this.SCHEME_SET = new Set([this.REDIS]); }
|
|
14
|
-
static isValid(input) {
|
|
15
|
-
return this.SCHEME_SET.has(input);
|
|
16
|
-
}
|
|
17
10
|
}
|
|
18
11
|
/** Where a Casbin enforcer reads its model from: a `file` path or inline `text`. */
|
|
19
|
-
export class CasbinEnforcerModelDrivers {
|
|
12
|
+
export class CasbinEnforcerModelDrivers extends ConstClass {
|
|
20
13
|
static { this.FILE = 'file'; }
|
|
21
14
|
static { this.TEXT = 'text'; }
|
|
22
|
-
static { this.SCHEME_SET = new Set([this.FILE, this.TEXT]); }
|
|
23
|
-
static isValid(input) {
|
|
24
|
-
return this.SCHEME_SET.has(input);
|
|
25
|
-
}
|
|
26
15
|
}
|
|
27
16
|
/** Casbin matching functions selectable for the domain match in `ICasbinEnforcerOptions.domainMatching`. */
|
|
28
|
-
export class CasbinDomainMatchingFunctions {
|
|
17
|
+
export class CasbinDomainMatchingFunctions extends ConstClass {
|
|
29
18
|
/** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */
|
|
30
19
|
static { this.KEY_MATCH = 'keyMatch'; }
|
|
31
20
|
/** Adds URL-path `:param` segment matching. */
|
|
@@ -36,16 +25,6 @@ export class CasbinDomainMatchingFunctions {
|
|
|
36
25
|
static { this.KEY_MATCH_4 = 'keyMatch4'; }
|
|
37
26
|
/** Treats the stored/policy value as a full regular expression. */
|
|
38
27
|
static { this.REGEX_MATCH = 'regexMatch'; }
|
|
39
|
-
static { this.SCHEME_SET = new Set([
|
|
40
|
-
this.KEY_MATCH,
|
|
41
|
-
this.KEY_MATCH_2,
|
|
42
|
-
this.KEY_MATCH_3,
|
|
43
|
-
this.KEY_MATCH_4,
|
|
44
|
-
this.REGEX_MATCH,
|
|
45
|
-
]); }
|
|
46
|
-
static isValid(input) {
|
|
47
|
-
return this.SCHEME_SET.has(input);
|
|
48
|
-
}
|
|
49
28
|
}
|
|
50
29
|
/** Relation prefixes the Casbin MODEL declares (`p` + `g`..`g5`), which {@link AuthorizationPolicyVariants} maps onto (many app edge-types -> one rule). Keep in sync with the model's `[role_definition]`. */
|
|
51
30
|
export class CasbinRuleVariants {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enforcer.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/enforcer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enforcer.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/enforcer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,6HAA6H;AAC7H,MAAM,OAAO,0BAA2B,SAAQ,UAAU;aACxC,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;;AAMpC,oEAAoE;AACpE,MAAM,OAAO,2BAA4B,SAAQ,UAAU;aACzC,UAAK,GAAG,OAAO,CAAC;;AAMlC,oFAAoF;AACpF,MAAM,OAAO,0BAA2B,SAAQ,UAAU;aACxC,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;;AAMhC,4GAA4G;AAC5G,MAAM,OAAO,6BAA8B,SAAQ,UAAU;IAC3D,+FAA+F;aAC/E,cAAS,GAAG,UAAU,CAAC;IAEvC,+CAA+C;aAC/B,gBAAW,GAAG,WAAW,CAAC;IAE1C,uCAAuC;aACvB,gBAAW,GAAG,WAAW,CAAC;IAE1C,6DAA6D;aAC7C,gBAAW,GAAG,WAAW,CAAC;IAE1C,mEAAmE;aACnD,gBAAW,GAAG,YAAY,CAAC;;AAM7C,+MAA+M;AAC/M,MAAM,OAAO,kBAAkB;IAC7B,8BAA8B;aACd,MAAC,GAAG,GAAG,CAAC;IAExB,4GAA4G;IAE5G,+FAA+F;aAC/E,MAAC,GAAG,GAAG,CAAC;IAExB,uFAAuF;aACvE,OAAE,GAAG,IAAI,CAAC;IAE1B,gEAAgE;aAChD,OAAE,GAAG,IAAI,CAAC;IAE1B,wDAAwD;aACxC,OAAE,GAAG,IAAI,CAAC;IAE1B,sDAAsD;aACtC,OAAE,GAAG,IAAI,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { ConstClass } from '@venizia/ignis-helpers/common';\n\n/** Kinds of enforcer a registration can declare; `casbin` takes `ICasbinEnforcerOptions`, `custom` takes untyped options. */\nexport class AuthorizationEnforcerTypes extends ConstClass {\n static readonly CASBIN = 'casbin';\n static readonly CUSTOM = 'custom';\n}\n\n/** Union of the `AuthorizationEnforcerTypes` values. */\nexport type TAuthorizationEnforcerType = TConstValue<typeof AuthorizationEnforcerTypes>;\n\n/** Cache backends for a Casbin enforcer's per-user policy lines. */\nexport class CasbinEnforcerCachedDrivers extends ConstClass {\n static readonly REDIS = 'redis';\n}\n\n/** Union of the `CasbinEnforcerCachedDrivers` values. */\nexport type TCasbinEnforcerCachedDriver = TConstValue<typeof CasbinEnforcerCachedDrivers>;\n\n/** Where a Casbin enforcer reads its model from: a `file` path or inline `text`. */\nexport class CasbinEnforcerModelDrivers extends ConstClass {\n static readonly FILE = 'file';\n static readonly TEXT = 'text';\n}\n\n/** Union of the `CasbinEnforcerModelDrivers` values. */\nexport type TCasbinEnforcerModelDriver = TConstValue<typeof CasbinEnforcerModelDrivers>;\n\n/** Casbin matching functions selectable for the domain match in `ICasbinEnforcerOptions.domainMatching`. */\nexport class CasbinDomainMatchingFunctions extends ConstClass {\n /** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */\n static readonly KEY_MATCH = 'keyMatch';\n\n /** Adds URL-path `:param` segment matching. */\n static readonly KEY_MATCH_2 = 'keyMatch2';\n\n /** Adds `{param}` segment matching. */\n static readonly KEY_MATCH_3 = 'keyMatch3';\n\n /** `{param}` matching with repeated-name equality checks. */\n static readonly KEY_MATCH_4 = 'keyMatch4';\n\n /** Treats the stored/policy value as a full regular expression. */\n static readonly REGEX_MATCH = 'regexMatch';\n}\n\n/** Union of the `CasbinDomainMatchingFunctions` values. */\nexport type TCasbinDomainMatchingFunction = TConstValue<typeof CasbinDomainMatchingFunctions>;\n\n/** Relation prefixes the Casbin MODEL declares (`p` + `g`..`g5`), which {@link AuthorizationPolicyVariants} maps onto (many app edge-types -> one rule). Keep in sync with the model's `[role_definition]`. */\nexport class CasbinRuleVariants {\n /** Permission policy line. */\n static readonly P = 'p';\n\n /** Numbered in request-tuple order (sub -> dom -> obj -> act): g (sub), g2/g3 (dom), g4 (obj), g5 (act). */\n\n /** Grouping #1 - role membership + role inheritance (user→role, role→role). The `sub` axis. */\n static readonly G = 'g';\n\n /** Grouping #2 - user→domain membership (join_domain). The `dom` axis (membership). */\n static readonly G2 = 'g2';\n\n /** Grouping #3 - domain hierarchy. The `dom` axis (nesting). */\n static readonly G3 = 'g3';\n\n /** Grouping #4 - resource hierarchy. The `obj` axis. */\n static readonly G4 = 'g4';\n\n /** Grouping #5 - action hierarchy. The `act` axis. */\n static readonly G5 = 'g5';\n}\n\n/** Union of the `CasbinRuleVariants` values. */\nexport type TCasbinRuleVariant = TConstValue<typeof CasbinRuleVariants>;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
3
|
import type { TResponseHeaders } from './types/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Constants with NO zod import, deliberately. The container's controller mixin imports
|
|
@@ -13,11 +14,9 @@ export declare class ControllerTransports {
|
|
|
13
14
|
/** Union of the `ControllerTransports` values. */
|
|
14
15
|
export type TControllerTransport = TConstValue<typeof ControllerTransports>;
|
|
15
16
|
/** Shape of `data` in a `{ count, data }` response, echoed in the `X-Response-Format` header. */
|
|
16
|
-
export declare class ResponseFormats {
|
|
17
|
+
export declare class ResponseFormats extends ConstClass {
|
|
17
18
|
static readonly OBJECT = "object";
|
|
18
19
|
static readonly ARRAY = "array";
|
|
19
|
-
static readonly SCHEME_SET: Set<string>;
|
|
20
|
-
static isValid(value: string): boolean;
|
|
21
20
|
}
|
|
22
21
|
/** Union of the `ResponseFormats` values. */
|
|
23
22
|
export type TResponseFormat = TConstValue<typeof ResponseFormats>;
|
|
@@ -43,12 +42,10 @@ export declare const commonResponseHeaders: TResponseHeaders;
|
|
|
43
42
|
/** OpenAPI response headers of a list route: `commonResponseHeaders` plus `Content-Range` for pagination. */
|
|
44
43
|
export declare const findResponseHeaders: TResponseHeaders;
|
|
45
44
|
/** Which decorator-defined routes `registerRoutesFromRegistry` registers: STATIC (no path parameter), PARAM (a path parameter) or ALL. */
|
|
46
|
-
export declare class RoutePathScopes {
|
|
45
|
+
export declare class RoutePathScopes extends ConstClass {
|
|
47
46
|
static readonly STATIC = "static";
|
|
48
47
|
static readonly PARAM = "param";
|
|
49
48
|
static readonly ALL = "all";
|
|
50
|
-
static readonly SCHEME_SET: Set<string>;
|
|
51
|
-
static isValid(value: string): boolean;
|
|
52
49
|
}
|
|
53
50
|
/** Valid route path scope values. */
|
|
54
51
|
export type TRoutePathScope = TConstValue<typeof RoutePathScopes>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTTP } from '@venizia/ignis-helpers/common';
|
|
1
|
+
import { HTTP, ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
2
|
/**
|
|
3
3
|
* Constants with NO zod import, deliberately. The container's controller mixin imports
|
|
4
4
|
* `ControllerTransports` from here, so anything this file pulls in reaches every consumer of
|
|
@@ -10,13 +10,9 @@ export class ControllerTransports {
|
|
|
10
10
|
static { this.GRPC = 'grpc'; }
|
|
11
11
|
}
|
|
12
12
|
/** Shape of `data` in a `{ count, data }` response, echoed in the `X-Response-Format` header. */
|
|
13
|
-
export class ResponseFormats {
|
|
13
|
+
export class ResponseFormats extends ConstClass {
|
|
14
14
|
static { this.OBJECT = 'object'; }
|
|
15
15
|
static { this.ARRAY = 'array'; }
|
|
16
|
-
static { this.SCHEME_SET = new Set([this.OBJECT, this.ARRAY]); }
|
|
17
|
-
static isValid(value) {
|
|
18
|
-
return this.SCHEME_SET.has(value);
|
|
19
|
-
}
|
|
20
16
|
}
|
|
21
17
|
/** Standard REST API path constants for CRUD controllers. */
|
|
22
18
|
export class RestPaths {
|
|
@@ -59,13 +55,9 @@ export const findResponseHeaders = {
|
|
|
59
55
|
},
|
|
60
56
|
};
|
|
61
57
|
/** Which decorator-defined routes `registerRoutesFromRegistry` registers: STATIC (no path parameter), PARAM (a path parameter) or ALL. */
|
|
62
|
-
export class RoutePathScopes {
|
|
58
|
+
export class RoutePathScopes extends ConstClass {
|
|
63
59
|
static { this.STATIC = 'static'; }
|
|
64
60
|
static { this.PARAM = 'param'; }
|
|
65
61
|
static { this.ALL = 'all'; }
|
|
66
|
-
static { this.SCHEME_SET = new Set([this.STATIC, this.PARAM, this.ALL]); }
|
|
67
|
-
static isValid(value) {
|
|
68
|
-
return this.SCHEME_SET.has(value);
|
|
69
|
-
}
|
|
70
62
|
}
|
|
71
63
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/controllers/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/controllers/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGjE;;;;GAIG;AAEH,oDAAoD;AACpD,MAAM,OAAO,oBAAoB;aACf,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C,EAAE;QAC5B,WAAW,EAAE,yDAAyD;QACtE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,EAAE;KAChF;CACF,CAAC;AAEF,0IAA0I;AAC1I,MAAM,OAAO,eAAgB,SAAQ,UAAU;aAC7B,WAAM,GAAG,QAAQ,CAAC;aAClB,UAAK,GAAG,OAAO,CAAC;aAChB,QAAG,GAAG,KAAK,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { HTTP, ConstClass } from '@venizia/ignis-helpers/common';\nimport type { TCrudRoutes, TResponseHeaders } from './types';\n\n/**\n * Constants with NO zod import, deliberately. The container's controller mixin imports\n * `ControllerTransports` from here, so anything this file pulls in reaches every consumer of\n * `Container` - the request schemas live in `schemas.ts` for exactly that reason.\n */\n\n/** Transport protocol constants for controllers. */\nexport class ControllerTransports {\n static readonly REST = 'rest';\n static readonly GRPC = 'grpc';\n}\n\n/** Union of the `ControllerTransports` values. */\nexport type TControllerTransport = TConstValue<typeof ControllerTransports>;\n\n/** Shape of `data` in a `{ count, data }` response, echoed in the `X-Response-Format` header. */\nexport class ResponseFormats extends ConstClass {\n static readonly OBJECT = 'object';\n static readonly ARRAY = 'array';\n}\n\n/** Union of the `ResponseFormats` values. */\nexport type TResponseFormat = TConstValue<typeof ResponseFormats>;\n\n/** Standard REST API path constants for CRUD controllers. */\nexport class RestPaths {\n static readonly ROOT = '/';\n static readonly COUNT = '/count';\n static readonly FIND_ONE = '/find-one';\n static readonly RESTORE = '/restore';\n}\n\n/** Route groups to spread into the `routes` of a CRUD controller. */\nexport class CrudRoutes {\n /** The four read routes: `count`, `find`, `findById` and `findOne`. */\n static readonly READ = {\n count: true,\n find: true,\n findById: true,\n findOne: true,\n } satisfies TCrudRoutes;\n}\n\n/** OpenAPI response headers every CRUD route documents: the request tracing id, the record count and the response format. */\nexport const commonResponseHeaders: TResponseHeaders = {\n [HTTP.Headers.REQUEST_TRACING_ID]: {\n description: 'Echo of the request tracing ID',\n schema: { type: 'string' },\n },\n [HTTP.Headers.RESPONSE_COUNT_DATA]: {\n description: 'Number of records in response',\n schema: { type: 'string', examples: ['1', '10', '100'] },\n },\n [HTTP.Headers.RESPONSE_FORMAT]: {\n description: 'Response format indicator',\n schema: { type: 'string', examples: ['array', 'object'] },\n },\n};\n\n/** OpenAPI response headers of a list route: `commonResponseHeaders` plus `Content-Range` for pagination. */\nexport const findResponseHeaders: TResponseHeaders = {\n ...commonResponseHeaders,\n [HTTP.Headers.CONTENT_RANGE]: {\n description: 'Content range for pagination (e.g., \"records 0-24/100\")',\n schema: { type: 'string', examples: ['records 0-24/100', 'records 25-49/100'] },\n },\n};\n\n/** Which decorator-defined routes `registerRoutesFromRegistry` registers: STATIC (no path parameter), PARAM (a path parameter) or ALL. */\nexport class RoutePathScopes extends ConstClass {\n static readonly STATIC = 'static';\n static readonly PARAM = 'param';\n static readonly ALL = 'all';\n}\n\n/** Valid route path scope values. */\nexport type TRoutePathScope = TConstValue<typeof RoutePathScopes>;\n"]}
|
|
@@ -79,7 +79,7 @@ export class CrudControllerFactory extends BaseHelper {
|
|
|
79
79
|
create: entityInstance.getSchema({ type: SchemaTypes.CREATE }),
|
|
80
80
|
update: entityInstance.getSchema({ type: SchemaTypes.UPDATE }),
|
|
81
81
|
},
|
|
82
|
-
serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.
|
|
82
|
+
serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.values())],
|
|
83
83
|
});
|
|
84
84
|
const controllerClass = class extends PersistableCrudController {
|
|
85
85
|
constructor(repositoryInstance) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../src/base/controllers/factory/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAG9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE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IAAI,CAAC,CAAC;YAE7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/F,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,cAAc,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9E,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE;gBACP,gGAAgG,cAAc,cAAc,KAAK,iBAAiB,SAAS,EAAE;gBAC7J,sEAAsE;gBACtE,0HAA0H;aAC3H,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC","sourcesContent":["import type { AbstractRepository } from '@/base/repositories';\nimport { AuthorizationActions } from '@/base/auth/authorize/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { AbstractEntity } from '@/base/models';\nimport { AuditFields, SchemaTypes } from '@/base/models/common/constants';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { BindingNamespaces } from '@/common/bindings';\nimport { BindingKeys, MetadataRegistry } from '@/helpers/inversion';\nimport type { TClass, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { isClass } from '@venizia/ignis-inversion';\nimport type { Env, Schema } from 'hono';\nimport type {\n ICrudControllerOptions,\n TCrudRepositoryClass,\n TCrudRoutes,\n TRepositoryDataObject,\n TRepositoryPersistObject,\n} from '../common';\nimport { PersistableCrudController } from './crud';\nimport { RouteConfigResolver } from './definition';\n\n/** Factory for generating typed CRUD controllers from entity definitions. */\nexport class CrudControllerFactory extends BaseHelper {\n /** The generated routes that change data: the ones that must never be answered by a `read` permission. */\n private static readonly WRITE_VERBS = [\n 'create',\n 'updateById',\n 'updateBy',\n 'deleteById',\n 'deleteBy',\n 'restoreById',\n 'restoreBy',\n ] as const;\n\n constructor() {\n super({ scope: CrudControllerFactory.name });\n }\n\n /**\n * Injects `repositories.<repositoryName>` into constructor parameter 0 of a factory-generated\n * controller, so a subclass needs no constructor. Recorded as metadata rather than a parameter\n * decorator, which Bun drops in some configurations. A subclass that declares its own `@inject` at\n * index 0 wins, and a sibling subclass keeps the factory's key.\n */\n static registerRepositoryInjection(opts: {\n target: TClass<unknown>;\n factoryName: string;\n repositoryName: string;\n }): void {\n const { target, factoryName, repositoryName } = opts;\n\n if (!repositoryName) {\n throw getError({\n message: `[${factoryName}] Invalid repository name | repository.name must name the repository binding`,\n });\n }\n\n MetadataRegistry.getInstance().setInjectMetadata({\n target,\n index: 0,\n metadata: {\n key: BindingKeys.build<unknown>({\n namespace: BindingNamespaces.REPOSITORY,\n key: repositoryName,\n }),\n index: 0,\n isOptional: false,\n },\n });\n }\n\n static build<\n Repository extends TCrudRepositoryClass,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TRepositoryDataObject<InstanceType<Repository>>,\n TPersistObject extends object = TRepositoryPersistObject<InstanceType<Repository>>,\n >(opts: ICrudControllerOptions<Repository>) {\n const { repository, authenticate, authorize, routes, isStrict = {} } = opts;\n\n CrudControllerFactory.assertWriteVerbsDeclareAuthorize({\n repositoryName: repository.name,\n authorize,\n routes,\n });\n CrudControllerFactory.assertRestoreRoutesSupported({ repository, routes });\n\n const model = MetadataRegistry.getInstance().getRepositoryBinding({\n target: repository,\n })?.model;\n\n if (!model) {\n throw getError({\n message: `[CrudControllerFactory.build] Cannot resolve the entity | repository: ${repository.name} | declare it with @repository({ model })`,\n });\n }\n\n const entityClass = isClass(model) ? model : model();\n const entityInstance = new entityClass();\n const settings = MetadataRegistry.getInstance().getModelMetadata({\n target: entityClass,\n })?.settings;\n\n const routeDefinitions = RouteConfigResolver.defineControllerRouteConfigs({\n isStrict: isStrict.requestSchema ?? true,\n idType: entityInstance.getIdType(),\n authenticate,\n authorize,\n routes,\n schema: {\n select: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.SELECT }),\n create: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.CREATE }),\n update: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.UPDATE }),\n },\n serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.SCHEME_SET)],\n });\n\n const controllerClass = class extends PersistableCrudController<\n AbstractEntity<TAnyObjectSchema>,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n > {\n constructor(repositoryInstance: AbstractRepository<TDataObject, TPersistObject>) {\n super({\n scope: new.target.name,\n isStrict: isStrict.path ?? true,\n repository: repositoryInstance,\n definitions: routeDefinitions,\n });\n }\n\n /** The routes of a generated controller come from `routes`; a subclass adds its own here. */\n override binding(): ValueOrPromise<void> {}\n\n /** Registers each listed CRUD route, after `binding()`: a custom static path is never taken by `/{id}`. */\n override bindDefaultRoutes(): ValueOrPromise<void> {\n if (routeDefinitions.COUNT) {\n this.defineRoute({\n configs: routeDefinitions.COUNT,\n handler: async (context) => this.count({ context }),\n });\n }\n\n if (routeDefinitions.FIND) {\n this.defineRoute({\n configs: routeDefinitions.FIND,\n handler: async (context) => this.find({ context }),\n });\n }\n\n if (routeDefinitions.FIND_ONE) {\n this.defineRoute({\n configs: routeDefinitions.FIND_ONE,\n handler: async (context) => this.findOne({ context }),\n });\n }\n\n if (routeDefinitions.FIND_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.FIND_BY_ID,\n handler: async (context) => this.findById({ context }),\n });\n }\n\n if (routeDefinitions.CREATE) {\n this.defineRoute({\n configs: routeDefinitions.CREATE,\n handler: async (context) => this.create({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY_ID,\n handler: async (context) => this.updateById({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY,\n handler: async (context) => this.updateBy({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY_ID,\n handler: async (context) => this.deleteById({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY,\n handler: async (context) => this.deleteBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY,\n handler: async (context) => this.restoreBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY_ID,\n handler: async (context) => this.restoreById({ context }),\n });\n }\n }\n };\n\n CrudControllerFactory.registerRepositoryInjection({\n target: controllerClass,\n factoryName: 'CrudControllerFactory.build',\n repositoryName: repository.name,\n });\n\n return controllerClass;\n }\n\n /** A restore route needs a repository that has the restore methods; the types already refuse one, this is the backstop for an untyped caller. */\n private static assertRestoreRoutesSupported(opts: {\n repository: TCrudRepositoryClass;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repository, routes } = opts;\n\n const isRestoreListed = routes?.restoreById !== undefined || routes?.restoreBy !== undefined;\n const isRestorable =\n typeof repository.prototype.restoreById === 'function' &&\n typeof repository.prototype.restoreBy === 'function';\n\n if (isRestoreListed && !isRestorable) {\n throw getError({\n message: `[CrudControllerFactory.build] a restore route needs a repository with both restoreById and restoreBy | repository: ${repository.name}`,\n });\n }\n }\n\n private static describeSpec(opts: { spec: IAuthorizationSpec }): string {\n const { spec } = opts;\n\n return `{ action: ${String(spec.action)}, resource: ${String(spec.resource)} }`;\n }\n\n /**\n * Refuses a CRUD controller that lists a write verb which would inherit a controller-level `authorize`\n * that is only a `read` permission: the verb would then answer to anyone who may read.\n *\n * A listed write verb is fine when it declares its own `authorize` (a spec, an array, or `{ skip: true }`) or\n * skips authentication. Only the literal action `read` is detected; a custom action name is the application's own\n * vocabulary. An array counts when every spec in it is `read`, since the specs of one route must all pass.\n */\n static assertWriteVerbsDeclareAuthorize(opts: {\n repositoryName: string;\n authorize: IAuthorizationSpec | IAuthorizationSpec[] | undefined;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repositoryName, authorize, routes } = opts;\n\n if (authorize == null) {\n return;\n }\n\n const specs = Array.isArray(authorize) ? authorize : [authorize];\n const isReadOnlyPermission =\n specs.length > 0 && specs.every((spec) => spec.action === AuthorizationActions.READ);\n\n if (!isReadOnlyPermission) {\n return;\n }\n\n const offending = CrudControllerFactory.WRITE_VERBS.filter((verb) => {\n const route = routes?.[verb];\n\n if (route === undefined) {\n return false;\n }\n\n return route === true || (route.authenticate?.skip !== true && route.authorize == null);\n });\n\n if (offending.length === 0) {\n return;\n }\n\n const inherited = specs.map((spec) => CrudControllerFactory.describeSpec({ spec })).join(', ');\n const verbs = offending.map((verb) => `${repositoryName}.${verb}`).join(', ');\n\n throw getError({\n message: [\n `[CrudControllerFactory.build] Write routes would inherit a read-only authorize | repository: ${repositoryName} | routes: ${verbs} | inherited: ${inherited}`,\n 'Anyone allowed to read could then create, update, delete or restore.',\n 'Fix: declare routes.<verb>.authorize for each of them (a spec, an array or { skip: true }), or leave them out of routes.',\n ].join(' | '),\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"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B,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,qBAAqB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAClE,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;YAE7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/F,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,cAAc,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9E,MAAM,QAAQ,CAAC;YACb,OAAO,EAAE;gBACP,gGAAgG,cAAc,cAAc,KAAK,iBAAiB,SAAS,EAAE;gBAC7J,sEAAsE;gBACtE,0HAA0H;aAC3H,CAAC,IAAI,CAAC,KAAK,CAAC;SACd,CAAC,CAAC;IACL,CAAC","sourcesContent":["import type { AbstractRepository } from '@/base/repositories';\nimport { AuthorizationActions } from '@/base/auth/authorize/common/constants';\nimport type { IAuthorizationSpec } from '@/base/auth/authorize/common/types';\nimport type { AbstractEntity } from '@/base/models';\nimport { AuditFields, SchemaTypes } from '@/base/models/common/constants';\nimport type { TAnyObjectSchema } from '@/base/controllers/common/schema-builders';\nimport { BindingNamespaces } from '@/common/bindings';\nimport { BindingKeys, MetadataRegistry } from '@/helpers/inversion';\nimport type { TClass, ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { BaseHelper, getError } from '@venizia/ignis-helpers/core';\nimport { isClass } from '@venizia/ignis-inversion';\nimport type { Env, Schema } from 'hono';\nimport type {\n ICrudControllerOptions,\n TCrudRepositoryClass,\n TCrudRoutes,\n TRepositoryDataObject,\n TRepositoryPersistObject,\n} from '../common';\nimport { PersistableCrudController } from './crud';\nimport { RouteConfigResolver } from './definition';\n\n/** Factory for generating typed CRUD controllers from entity definitions. */\nexport class CrudControllerFactory extends BaseHelper {\n /** The generated routes that change data: the ones that must never be answered by a `read` permission. */\n private static readonly WRITE_VERBS = [\n 'create',\n 'updateById',\n 'updateBy',\n 'deleteById',\n 'deleteBy',\n 'restoreById',\n 'restoreBy',\n ] as const;\n\n constructor() {\n super({ scope: CrudControllerFactory.name });\n }\n\n /**\n * Injects `repositories.<repositoryName>` into constructor parameter 0 of a factory-generated\n * controller, so a subclass needs no constructor. Recorded as metadata rather than a parameter\n * decorator, which Bun drops in some configurations. A subclass that declares its own `@inject` at\n * index 0 wins, and a sibling subclass keeps the factory's key.\n */\n static registerRepositoryInjection(opts: {\n target: TClass<unknown>;\n factoryName: string;\n repositoryName: string;\n }): void {\n const { target, factoryName, repositoryName } = opts;\n\n if (!repositoryName) {\n throw getError({\n message: `[${factoryName}] Invalid repository name | repository.name must name the repository binding`,\n });\n }\n\n MetadataRegistry.getInstance().setInjectMetadata({\n target,\n index: 0,\n metadata: {\n key: BindingKeys.build<unknown>({\n namespace: BindingNamespaces.REPOSITORY,\n key: repositoryName,\n }),\n index: 0,\n isOptional: false,\n },\n });\n }\n\n static build<\n Repository extends TCrudRepositoryClass,\n RouteEnv extends Env = Env,\n RouteSchema extends Schema = {},\n BasePath extends string = '/',\n ConfigurableOptions extends object = {},\n TDataObject extends object = TRepositoryDataObject<InstanceType<Repository>>,\n TPersistObject extends object = TRepositoryPersistObject<InstanceType<Repository>>,\n >(opts: ICrudControllerOptions<Repository>) {\n const { repository, authenticate, authorize, routes, isStrict = {} } = opts;\n\n CrudControllerFactory.assertWriteVerbsDeclareAuthorize({\n repositoryName: repository.name,\n authorize,\n routes,\n });\n CrudControllerFactory.assertRestoreRoutesSupported({ repository, routes });\n\n const model = MetadataRegistry.getInstance().getRepositoryBinding({\n target: repository,\n })?.model;\n\n if (!model) {\n throw getError({\n message: `[CrudControllerFactory.build] Cannot resolve the entity | repository: ${repository.name} | declare it with @repository({ model })`,\n });\n }\n\n const entityClass = isClass(model) ? model : model();\n const entityInstance = new entityClass();\n const settings = MetadataRegistry.getInstance().getModelMetadata({\n target: entityClass,\n })?.settings;\n\n const routeDefinitions = RouteConfigResolver.defineControllerRouteConfigs({\n isStrict: isStrict.requestSchema ?? true,\n idType: entityInstance.getIdType(),\n authenticate,\n authorize,\n routes,\n schema: {\n select: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.SELECT }),\n create: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.CREATE }),\n update: entityInstance.getSchema<TAnyObjectSchema>({ type: SchemaTypes.UPDATE }),\n },\n serverStampedKeys: [...(settings?.properties?.stamped ?? AuditFields.values())],\n });\n\n const controllerClass = class extends PersistableCrudController<\n AbstractEntity<TAnyObjectSchema>,\n RouteEnv,\n RouteSchema,\n BasePath,\n ConfigurableOptions,\n TDataObject,\n TPersistObject\n > {\n constructor(repositoryInstance: AbstractRepository<TDataObject, TPersistObject>) {\n super({\n scope: new.target.name,\n isStrict: isStrict.path ?? true,\n repository: repositoryInstance,\n definitions: routeDefinitions,\n });\n }\n\n /** The routes of a generated controller come from `routes`; a subclass adds its own here. */\n override binding(): ValueOrPromise<void> {}\n\n /** Registers each listed CRUD route, after `binding()`: a custom static path is never taken by `/{id}`. */\n override bindDefaultRoutes(): ValueOrPromise<void> {\n if (routeDefinitions.COUNT) {\n this.defineRoute({\n configs: routeDefinitions.COUNT,\n handler: async (context) => this.count({ context }),\n });\n }\n\n if (routeDefinitions.FIND) {\n this.defineRoute({\n configs: routeDefinitions.FIND,\n handler: async (context) => this.find({ context }),\n });\n }\n\n if (routeDefinitions.FIND_ONE) {\n this.defineRoute({\n configs: routeDefinitions.FIND_ONE,\n handler: async (context) => this.findOne({ context }),\n });\n }\n\n if (routeDefinitions.FIND_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.FIND_BY_ID,\n handler: async (context) => this.findById({ context }),\n });\n }\n\n if (routeDefinitions.CREATE) {\n this.defineRoute({\n configs: routeDefinitions.CREATE,\n handler: async (context) => this.create({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY_ID,\n handler: async (context) => this.updateById({ context }),\n });\n }\n\n if (routeDefinitions.UPDATE_BY) {\n this.defineRoute({\n configs: routeDefinitions.UPDATE_BY,\n handler: async (context) => this.updateBy({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY_ID,\n handler: async (context) => this.deleteById({ context }),\n });\n }\n\n if (routeDefinitions.DELETE_BY) {\n this.defineRoute({\n configs: routeDefinitions.DELETE_BY,\n handler: async (context) => this.deleteBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY,\n handler: async (context) => this.restoreBy({ context }),\n });\n }\n\n if (routeDefinitions.RESTORE_BY_ID) {\n this.defineRoute({\n configs: routeDefinitions.RESTORE_BY_ID,\n handler: async (context) => this.restoreById({ context }),\n });\n }\n }\n };\n\n CrudControllerFactory.registerRepositoryInjection({\n target: controllerClass,\n factoryName: 'CrudControllerFactory.build',\n repositoryName: repository.name,\n });\n\n return controllerClass;\n }\n\n /** A restore route needs a repository that has the restore methods; the types already refuse one, this is the backstop for an untyped caller. */\n private static assertRestoreRoutesSupported(opts: {\n repository: TCrudRepositoryClass;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repository, routes } = opts;\n\n const isRestoreListed = routes?.restoreById !== undefined || routes?.restoreBy !== undefined;\n const isRestorable =\n typeof repository.prototype.restoreById === 'function' &&\n typeof repository.prototype.restoreBy === 'function';\n\n if (isRestoreListed && !isRestorable) {\n throw getError({\n message: `[CrudControllerFactory.build] a restore route needs a repository with both restoreById and restoreBy | repository: ${repository.name}`,\n });\n }\n }\n\n private static describeSpec(opts: { spec: IAuthorizationSpec }): string {\n const { spec } = opts;\n\n return `{ action: ${String(spec.action)}, resource: ${String(spec.resource)} }`;\n }\n\n /**\n * Refuses a CRUD controller that lists a write verb which would inherit a controller-level `authorize`\n * that is only a `read` permission: the verb would then answer to anyone who may read.\n *\n * A listed write verb is fine when it declares its own `authorize` (a spec, an array, or `{ skip: true }`) or\n * skips authentication. Only the literal action `read` is detected; a custom action name is the application's own\n * vocabulary. An array counts when every spec in it is `read`, since the specs of one route must all pass.\n */\n static assertWriteVerbsDeclareAuthorize(opts: {\n repositoryName: string;\n authorize: IAuthorizationSpec | IAuthorizationSpec[] | undefined;\n routes: TCrudRoutes | undefined;\n }): void {\n const { repositoryName, authorize, routes } = opts;\n\n if (authorize == null) {\n return;\n }\n\n const specs = Array.isArray(authorize) ? authorize : [authorize];\n const isReadOnlyPermission =\n specs.length > 0 && specs.every((spec) => spec.action === AuthorizationActions.READ);\n\n if (!isReadOnlyPermission) {\n return;\n }\n\n const offending = CrudControllerFactory.WRITE_VERBS.filter((verb) => {\n const route = routes?.[verb];\n\n if (route === undefined) {\n return false;\n }\n\n return route === true || (route.authenticate?.skip !== true && route.authorize == null);\n });\n\n if (offending.length === 0) {\n return;\n }\n\n const inherited = specs.map((spec) => CrudControllerFactory.describeSpec({ spec })).join(', ');\n const verbs = offending.map((verb) => `${repositoryName}.${verb}`).join(', ');\n\n throw getError({\n message: [\n `[CrudControllerFactory.build] Write routes would inherit a read-only authorize | repository: ${repositoryName} | routes: ${verbs} | inherited: ${inherited}`,\n 'Anyone allowed to read could then create, update, delete or restore.',\n 'Fix: declare routes.<verb>.authorize for each of them (a spec, an array or { skip: true }), or leave them out of routes.',\n ].join(' | '),\n });\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IConfigurable, TClass, TConstValue, ValueOrPromise } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
3
|
/** Names of the supported datasource drivers, split into relational and search sets. `isValid` checks a value against all of them. */
|
|
3
4
|
export declare class DataSourceDrivers {
|
|
4
5
|
static readonly NODE_POSTGRES = "node-postgres";
|
|
@@ -13,11 +14,9 @@ export declare class DataSourceDrivers {
|
|
|
13
14
|
static isValid(value: string): boolean;
|
|
14
15
|
}
|
|
15
16
|
/** When a datasource opens: with the application (`start`, the default) or at the first call that needs it (`first-use`). */
|
|
16
|
-
export declare class DataSourceOpenModes {
|
|
17
|
+
export declare class DataSourceOpenModes extends ConstClass {
|
|
17
18
|
static readonly START = "start";
|
|
18
19
|
static readonly FIRST_USE = "first-use";
|
|
19
|
-
static readonly SCHEME_SET: Set<string>;
|
|
20
|
-
static isValid(value: string): value is TDataSourceOpenMode;
|
|
21
20
|
}
|
|
22
21
|
/** Defaults of the `open` option. */
|
|
23
22
|
export declare class DataSourceOpenDefaults {
|