@venizia/ignis 0.0.9-9 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/dist/base/middlewares/app-error/app-error.middleware.d.ts +15 -0
- package/dist/base/middlewares/app-error/app-error.middleware.d.ts.map +1 -0
- package/dist/base/middlewares/app-error/app-error.middleware.js +81 -0
- package/dist/base/middlewares/app-error/app-error.middleware.js.map +1 -0
- package/dist/base/middlewares/app-error/database.handler.d.ts +20 -0
- package/dist/base/middlewares/app-error/database.handler.d.ts.map +1 -0
- package/dist/base/middlewares/app-error/database.handler.js +55 -0
- package/dist/base/middlewares/app-error/database.handler.js.map +1 -0
- package/dist/base/middlewares/app-error/definition.d.ts +59 -0
- package/dist/base/middlewares/app-error/definition.d.ts.map +1 -0
- package/dist/base/middlewares/app-error/definition.js +98 -0
- package/dist/base/middlewares/app-error/definition.js.map +1 -0
- package/dist/base/middlewares/app-error/index.d.ts +2 -0
- package/dist/base/middlewares/app-error/index.d.ts.map +1 -0
- package/dist/{components/auth/authorize/models/abilities → base/middlewares/app-error}/index.js +1 -2
- package/dist/base/middlewares/app-error/index.js.map +1 -0
- package/dist/base/middlewares/app-error/types.d.ts +18 -0
- package/dist/base/middlewares/app-error/types.d.ts.map +1 -0
- package/dist/base/middlewares/app-error/types.js +3 -0
- package/dist/base/middlewares/app-error/types.js.map +1 -0
- package/dist/base/middlewares/app-error/zod.handler.d.ts +28 -0
- package/dist/base/middlewares/app-error/zod.handler.d.ts.map +1 -0
- package/dist/base/middlewares/app-error/zod.handler.js +64 -0
- package/dist/base/middlewares/app-error/zod.handler.js.map +1 -0
- package/dist/base/middlewares/emoji-favicon/emoji-favicon.middleware.d.ts.map +1 -0
- package/dist/base/middlewares/emoji-favicon/emoji-favicon.middleware.js.map +1 -0
- package/dist/base/middlewares/emoji-favicon/index.d.ts +2 -0
- package/dist/base/middlewares/emoji-favicon/index.d.ts.map +1 -0
- package/dist/base/middlewares/emoji-favicon/index.js +18 -0
- package/dist/base/middlewares/emoji-favicon/index.js.map +1 -0
- package/dist/base/middlewares/index.d.ts +4 -4
- package/dist/base/middlewares/index.d.ts.map +1 -1
- package/dist/base/middlewares/index.js +4 -4
- package/dist/base/middlewares/index.js.map +1 -1
- package/dist/base/middlewares/not-found/index.d.ts +2 -0
- package/dist/base/middlewares/not-found/index.d.ts.map +1 -0
- package/dist/base/middlewares/not-found/index.js +18 -0
- package/dist/base/middlewares/not-found/index.js.map +1 -0
- package/dist/base/middlewares/{not-found.middleware.d.ts → not-found/not-found.middleware.d.ts} +0 -1
- package/dist/base/middlewares/not-found/not-found.middleware.d.ts.map +1 -0
- package/dist/base/middlewares/{not-found.middleware.js → not-found/not-found.middleware.js} +2 -3
- package/dist/base/middlewares/{not-found.middleware.js.map → not-found/not-found.middleware.js.map} +1 -1
- package/dist/base/middlewares/request-spy/index.d.ts +2 -0
- package/dist/base/middlewares/request-spy/index.d.ts.map +1 -0
- package/dist/base/middlewares/request-spy/index.js +18 -0
- package/dist/base/middlewares/request-spy/index.js.map +1 -0
- package/dist/base/middlewares/{request-spy.middleware.d.ts → request-spy/request-spy.middleware.d.ts} +1 -1
- package/dist/base/middlewares/request-spy/request-spy.middleware.d.ts.map +1 -0
- package/dist/base/middlewares/{request-spy.middleware.js → request-spy/request-spy.middleware.js} +1 -1
- package/dist/base/middlewares/request-spy/request-spy.middleware.js.map +1 -0
- package/dist/base/models/common/columns.d.ts +22 -0
- package/dist/base/models/common/columns.d.ts.map +1 -0
- package/dist/base/models/common/columns.js +43 -0
- package/dist/base/models/common/columns.js.map +1 -0
- package/dist/base/models/common/index.d.ts +1 -0
- package/dist/base/models/common/index.d.ts.map +1 -1
- package/dist/base/models/common/index.js +1 -0
- package/dist/base/models/common/index.js.map +1 -1
- package/dist/base/models/enrichers/principal.enricher.d.ts +6 -5
- package/dist/base/models/enrichers/principal.enricher.d.ts.map +1 -1
- package/dist/base/models/enrichers/principal.enricher.js +8 -3
- package/dist/base/models/enrichers/principal.enricher.js.map +1 -1
- package/dist/base/models/enrichers/tz.enricher.d.ts +9 -8
- package/dist/base/models/enrichers/tz.enricher.d.ts.map +1 -1
- package/dist/base/models/enrichers/tz.enricher.js +10 -10
- package/dist/base/models/enrichers/tz.enricher.js.map +1 -1
- package/dist/base/repositories/core/readable.d.ts.map +1 -1
- package/dist/base/repositories/core/readable.js +16 -4
- package/dist/base/repositories/core/readable.js.map +1 -1
- package/dist/base/repositories/core/soft-deletable.d.ts +1 -1
- package/dist/base/repositories/core/soft-deletable.d.ts.map +1 -1
- package/dist/components/auth/authorize/adapters/base-filtered.d.ts +26 -56
- package/dist/components/auth/authorize/adapters/base-filtered.d.ts.map +1 -1
- package/dist/components/auth/authorize/adapters/base-filtered.js +23 -70
- package/dist/components/auth/authorize/adapters/base-filtered.js.map +1 -1
- package/dist/components/auth/authorize/adapters/index.d.ts +2 -1
- package/dist/components/auth/authorize/adapters/index.d.ts.map +1 -1
- package/dist/components/auth/authorize/adapters/index.js +2 -1
- package/dist/components/auth/authorize/adapters/index.js.map +1 -1
- package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.d.ts +138 -0
- package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.d.ts.map +1 -0
- package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.js +300 -0
- package/dist/components/auth/authorize/adapters/scoped-casbin.adapter.js.map +1 -0
- package/dist/components/auth/authorize/adapters/types.d.ts +31 -0
- package/dist/components/auth/authorize/adapters/types.d.ts.map +1 -0
- package/dist/components/auth/authorize/adapters/types.js +3 -0
- package/dist/components/auth/authorize/adapters/types.js.map +1 -0
- package/dist/components/auth/authorize/common/constants.d.ts +144 -8
- package/dist/components/auth/authorize/common/constants.d.ts.map +1 -1
- package/dist/components/auth/authorize/common/constants.js +171 -13
- package/dist/components/auth/authorize/common/constants.js.map +1 -1
- package/dist/components/auth/authorize/common/index.d.ts +4 -0
- package/dist/components/auth/authorize/common/index.d.ts.map +1 -1
- package/dist/components/auth/authorize/common/index.js +4 -0
- package/dist/components/auth/authorize/common/index.js.map +1 -1
- package/dist/components/auth/authorize/common/object-match.d.ts +21 -0
- package/dist/components/auth/authorize/common/object-match.d.ts.map +1 -0
- package/dist/components/auth/authorize/common/object-match.js +33 -0
- package/dist/components/auth/authorize/common/object-match.js.map +1 -0
- package/dist/components/auth/authorize/common/permission-builder.d.ts +92 -0
- package/dist/components/auth/authorize/common/permission-builder.d.ts.map +1 -0
- package/dist/components/auth/authorize/common/permission-builder.js +99 -0
- package/dist/components/auth/authorize/common/permission-builder.js.map +1 -0
- package/dist/components/auth/authorize/common/policy-builder.d.ts +183 -0
- package/dist/components/auth/authorize/common/policy-builder.d.ts.map +1 -0
- package/dist/components/auth/authorize/common/policy-builder.js +130 -0
- package/dist/components/auth/authorize/common/policy-builder.js.map +1 -0
- package/dist/components/auth/authorize/common/resolve-request-domain.d.ts +20 -0
- package/dist/components/auth/authorize/common/resolve-request-domain.d.ts.map +1 -0
- package/dist/components/auth/authorize/common/resolve-request-domain.js +59 -0
- package/dist/components/auth/authorize/common/resolve-request-domain.js.map +1 -0
- package/dist/components/auth/authorize/common/types.d.ts +70 -23
- package/dist/components/auth/authorize/common/types.d.ts.map +1 -1
- package/dist/components/auth/authorize/enforcers/casbin.enforcer.d.ts +120 -28
- package/dist/components/auth/authorize/enforcers/casbin.enforcer.d.ts.map +1 -1
- package/dist/components/auth/authorize/enforcers/casbin.enforcer.js +324 -124
- package/dist/components/auth/authorize/enforcers/casbin.enforcer.js.map +1 -1
- package/dist/components/auth/authorize/enforcers/enforcer-registry.d.ts +19 -1
- package/dist/components/auth/authorize/enforcers/enforcer-registry.d.ts.map +1 -1
- package/dist/components/auth/authorize/enforcers/enforcer-registry.js +23 -0
- package/dist/components/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
- package/dist/components/auth/authorize/enforcers/index.d.ts +1 -0
- package/dist/components/auth/authorize/enforcers/index.d.ts.map +1 -1
- package/dist/components/auth/authorize/enforcers/index.js +1 -0
- package/dist/components/auth/authorize/enforcers/index.js.map +1 -1
- package/dist/components/auth/authorize/enforcers/models/index.d.ts +2 -0
- package/dist/components/auth/authorize/enforcers/models/index.d.ts.map +1 -0
- package/dist/components/auth/authorize/enforcers/models/index.js +18 -0
- package/dist/components/auth/authorize/enforcers/models/index.js.map +1 -0
- package/dist/components/auth/authorize/enforcers/models/rbac-domain.model.d.ts +32 -0
- package/dist/components/auth/authorize/enforcers/models/rbac-domain.model.d.ts.map +1 -0
- package/dist/components/auth/authorize/enforcers/models/rbac-domain.model.js +54 -0
- package/dist/components/auth/authorize/enforcers/models/rbac-domain.model.js.map +1 -0
- package/dist/components/auth/authorize/models/index.d.ts +0 -1
- package/dist/components/auth/authorize/models/index.d.ts.map +1 -1
- package/dist/components/auth/authorize/models/index.js +0 -1
- package/dist/components/auth/authorize/models/index.js.map +1 -1
- package/dist/components/auth/authorize/providers/authorization.provider.d.ts.map +1 -1
- package/dist/components/auth/authorize/providers/authorization.provider.js +12 -0
- package/dist/components/auth/authorize/providers/authorization.provider.js.map +1 -1
- package/dist/components/auth/models/entities/permission.model.d.ts +2 -0
- package/dist/components/auth/models/entities/permission.model.d.ts.map +1 -1
- package/dist/components/auth/models/entities/permission.model.js +4 -0
- package/dist/components/auth/models/entities/permission.model.js.map +1 -1
- package/dist/components/auth/models/entities/user.model.d.ts +16 -2
- package/dist/components/auth/models/entities/user.model.d.ts.map +1 -1
- package/dist/components/auth/models/entities/user.model.js +3 -2
- package/dist/components/auth/models/entities/user.model.js.map +1 -1
- package/dist/components/mail/helpers/executors/internal-queue-executor.helper.d.ts.map +1 -1
- package/dist/components/mail/helpers/executors/internal-queue-executor.helper.js +1 -1
- package/dist/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
- package/dist/components/static-asset/models/base.model.d.ts +24 -16
- package/dist/components/static-asset/models/base.model.d.ts.map +1 -1
- package/package.json +6 -5
- package/dist/base/middlewares/app-error.middleware.d.ts +0 -8
- package/dist/base/middlewares/app-error.middleware.d.ts.map +0 -1
- package/dist/base/middlewares/app-error.middleware.js +0 -138
- package/dist/base/middlewares/app-error.middleware.js.map +0 -1
- package/dist/base/middlewares/emoji-favicon.middleware.d.ts.map +0 -1
- package/dist/base/middlewares/emoji-favicon.middleware.js.map +0 -1
- package/dist/base/middlewares/not-found.middleware.d.ts.map +0 -1
- package/dist/base/middlewares/request-spy.middleware.d.ts.map +0 -1
- package/dist/base/middlewares/request-spy.middleware.js.map +0 -1
- package/dist/components/auth/authorize/adapters/drizzle-casbin.d.ts +0 -46
- package/dist/components/auth/authorize/adapters/drizzle-casbin.d.ts.map +0 -1
- package/dist/components/auth/authorize/adapters/drizzle-casbin.js +0 -104
- package/dist/components/auth/authorize/adapters/drizzle-casbin.js.map +0 -1
- package/dist/components/auth/authorize/models/abilities/index.d.ts +0 -3
- package/dist/components/auth/authorize/models/abilities/index.d.ts.map +0 -1
- package/dist/components/auth/authorize/models/abilities/index.js.map +0 -1
- package/dist/components/auth/authorize/models/abilities/string-action.model.d.ts +0 -14
- package/dist/components/auth/authorize/models/abilities/string-action.model.d.ts.map +0 -1
- package/dist/components/auth/authorize/models/abilities/string-action.model.js +0 -23
- package/dist/components/auth/authorize/models/abilities/string-action.model.js.map +0 -1
- package/dist/components/auth/authorize/models/abilities/string-resource.model.d.ts +0 -13
- package/dist/components/auth/authorize/models/abilities/string-resource.model.d.ts.map +0 -1
- package/dist/components/auth/authorize/models/abilities/string-resource.model.js +0 -19
- package/dist/components/auth/authorize/models/abilities/string-resource.model.js.map +0 -1
- /package/dist/base/middlewares/{emoji-favicon.middleware.d.ts → emoji-favicon/emoji-favicon.middleware.d.ts} +0 -0
- /package/dist/base/middlewares/{emoji-favicon.middleware.js → emoji-favicon/emoji-favicon.middleware.js} +0 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopedCasbinAdapter = void 0;
|
|
4
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
const base_filtered_1 = require("./base-filtered");
|
|
7
|
+
const DEFAULT_SCHEMA = 'public';
|
|
8
|
+
/**
|
|
9
|
+
* Filtered casbin adapter for the scoped RBAC model: loads ONE principal's edges (role assignments,
|
|
10
|
+
* memberships, grants) plus the shared structural hierarchy trees as casbin lines. Read-only.
|
|
11
|
+
*/
|
|
12
|
+
class ScopedCasbinAdapter extends base_filtered_1.BaseFilteredAdapter {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super({ scope: ScopedCasbinAdapter.name, dataSource: opts.dataSource });
|
|
15
|
+
this.entities = opts.entities;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Casbin's filtered-load entry point: build the full line set for ONE principal and load it into
|
|
19
|
+
* the model. Runs in two waves —
|
|
20
|
+
* Wave 1 (parallel): the principal's own edges (role assignments → g, memberships → g2, direct
|
|
21
|
+
* grants → p) plus the shared structural trees (role/resource/action/domain inherits).
|
|
22
|
+
* Wave 2: expand the assigned roles to their transitive parents (role closure over role_inherits),
|
|
23
|
+
* then fetch the grants those roles carry — so a user inherits permissions from parent roles.
|
|
24
|
+
* The concatenated lines are handed to {@link loadLines}; the enforcer caches the result per user
|
|
25
|
+
* in Redis, so this only runs on a cache MISS.
|
|
26
|
+
*/
|
|
27
|
+
async loadFilteredPolicy(model, filter) {
|
|
28
|
+
const { principal } = filter;
|
|
29
|
+
// Wave 1 — independent per-user queries + structural trees, in parallel.
|
|
30
|
+
const [assignments, memberships, userGrants, structural] = await Promise.all([
|
|
31
|
+
this.queryRoleAssignments({ principal }),
|
|
32
|
+
this.queryMemberships({ principal }),
|
|
33
|
+
this.queryGrants({ subject: { type: principal.type, ids: [principal.id] } }),
|
|
34
|
+
this.loadStructuralTrees(),
|
|
35
|
+
]);
|
|
36
|
+
// Wave 2 — role grants need the role closure (built from the role_inherits edges loaded above).
|
|
37
|
+
const roleClosure = this.expandRoleClosure({
|
|
38
|
+
role: {
|
|
39
|
+
ids: assignments.roleIds,
|
|
40
|
+
edges: structural.filter(line => {
|
|
41
|
+
return line.startsWith(`${common_1.AuthorizationPolicyVariants.ROLE_INHERITS.rule}, `);
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const roleGrants = await this.queryGrants({
|
|
46
|
+
subject: { type: this.entities.principals.role, ids: roleClosure },
|
|
47
|
+
});
|
|
48
|
+
const lines = [
|
|
49
|
+
...assignments.lines,
|
|
50
|
+
...memberships,
|
|
51
|
+
...userGrants,
|
|
52
|
+
...roleGrants,
|
|
53
|
+
...structural,
|
|
54
|
+
];
|
|
55
|
+
await this.loadLines({ model, lines });
|
|
56
|
+
}
|
|
57
|
+
/** Schema for a table, defaulting to `public`. */
|
|
58
|
+
schemaOf(table) {
|
|
59
|
+
return table.schemaName ?? DEFAULT_SCHEMA;
|
|
60
|
+
}
|
|
61
|
+
/** Schema-qualified table reference (`"<schema>"."<table>"`) for use after FROM/JOIN with an alias. */
|
|
62
|
+
qualifiedTable(opts) {
|
|
63
|
+
const { table } = opts;
|
|
64
|
+
return (0, drizzle_orm_1.sql) `${drizzle_orm_1.sql.identifier(this.schemaOf(table))}.${drizzle_orm_1.sql.identifier(table.tableName)}`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `AND <alias>.<col> IS NULL` when soft-delete on; empty otherwise. The alias is emitted RAW (not
|
|
68
|
+
* quoted) so it matches the unquoted alias declared in the FROM clause (`FROM ... policyDefinition`):
|
|
69
|
+
* Postgres folds unquoted identifiers to lower-case, so a quoted `"policyDefinition"` would resolve
|
|
70
|
+
* to a DIFFERENT relation than the unquoted FROM alias → 42P01 "missing FROM-clause entry". The alias
|
|
71
|
+
* is always a hard-coded literal supplied by this adapter, never user input, so emitting it raw is
|
|
72
|
+
* safe; the (config-supplied) column name stays quoted via `sql.identifier`.
|
|
73
|
+
*/
|
|
74
|
+
softDeleteClause(opts) {
|
|
75
|
+
const sd = this.entities.softDelete;
|
|
76
|
+
if (!sd?.use) {
|
|
77
|
+
return drizzle_orm_1.sql.empty();
|
|
78
|
+
}
|
|
79
|
+
return (0, drizzle_orm_1.sql) ` AND ${drizzle_orm_1.sql.raw(opts.alias)}.${drizzle_orm_1.sql.identifier(sd.columnName)} IS NULL`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Fetch the principal's `assign_role` edges and emit them as casbin `g` lines (role membership).
|
|
83
|
+
* Returns both the lines AND the raw `roleIds`, which Wave 2 feeds into {@link expandRoleClosure}.
|
|
84
|
+
* A null domain widens the assignment to every domain (`*`).
|
|
85
|
+
* e.g. `g, User_u1, Role_r1, *` — "u1 holds Role r1 in any domain".
|
|
86
|
+
*/
|
|
87
|
+
async queryRoleAssignments(opts) {
|
|
88
|
+
const { policyDefinition, principals } = this.entities;
|
|
89
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
90
|
+
const { principal } = opts;
|
|
91
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
92
|
+
SELECT
|
|
93
|
+
policyDefinition.target_id AS "roleId",
|
|
94
|
+
policyDefinition.domain
|
|
95
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
96
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.ASSIGN_ROLE.action}
|
|
97
|
+
AND policyDefinition.subject_type = ${principal.type}
|
|
98
|
+
AND policyDefinition.subject_id = ${principal.id}
|
|
99
|
+
AND policyDefinition.target_type = ${principals.role}${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
100
|
+
`);
|
|
101
|
+
const lines = [];
|
|
102
|
+
const roleIds = [];
|
|
103
|
+
for (const row of result.rows) {
|
|
104
|
+
roleIds.push(row.roleId);
|
|
105
|
+
const domain = row.domain ?? '*';
|
|
106
|
+
lines.push(`${common_1.AuthorizationPolicyVariants.ASSIGN_ROLE.rule}, ${principal.type}_${principal.id}, ${principals.role}_${row.roleId}, ${domain}`);
|
|
107
|
+
}
|
|
108
|
+
return { lines, roleIds };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fetch the principal's `join_domain` edges (restricted to the configured `domainTypes`) and emit
|
|
112
|
+
* them as casbin `g2` lines — the membership relation the matcher uses to scope `ANY_MEMBER` grants.
|
|
113
|
+
* e.g. `g2, User_u1, Merchant_7` — "u1 is a member of Merchant 7".
|
|
114
|
+
*/
|
|
115
|
+
async queryMemberships(opts) {
|
|
116
|
+
const { policyDefinition, domainTypes } = this.entities;
|
|
117
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
118
|
+
const { principal } = opts;
|
|
119
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
120
|
+
SELECT
|
|
121
|
+
policyDefinition.target_type AS "domainType",
|
|
122
|
+
policyDefinition.target_id AS "domainId"
|
|
123
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
124
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.JOIN_DOMAIN.action}
|
|
125
|
+
AND policyDefinition.subject_type = ${principal.type}
|
|
126
|
+
AND policyDefinition.subject_id = ${principal.id}
|
|
127
|
+
AND policyDefinition.target_type IN (${drizzle_orm_1.sql.join(domainTypes.map(t => (0, drizzle_orm_1.sql) `${t}`), (0, drizzle_orm_1.sql) `, `)})${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
128
|
+
`);
|
|
129
|
+
return result.rows.map(row => `${common_1.AuthorizationPolicyVariants.JOIN_DOMAIN.rule}, ${principal.type}_${principal.id}, ${row.domainType}_${row.domainId}`);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Fetch `grant` edges for the given subjects (a User or a set of Roles) joined to `Permission` for
|
|
133
|
+
* the object code, and emit them as casbin `p` policy lines. Used twice per load: once for the
|
|
134
|
+
* user's direct grants, once for the grants of every role in the closure. Rows with no `action` are
|
|
135
|
+
* skipped; a null effect defaults to allow, a null domain to `ANY_MEMBER`. Empty `ids` short-circuits
|
|
136
|
+
* without touching the DB.
|
|
137
|
+
* e.g. `p, Role_5, ANY_MEMBER, Order, read, allow` — "Role 5 may read Order in any joined domain".
|
|
138
|
+
*/
|
|
139
|
+
async queryGrants(opts) {
|
|
140
|
+
if (!opts.subject.ids.length) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
const { policyDefinition, permission } = this.entities;
|
|
144
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
145
|
+
const permissionTable = this.qualifiedTable({ table: permission });
|
|
146
|
+
const { subject } = opts;
|
|
147
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
148
|
+
SELECT
|
|
149
|
+
policyDefinition.subject_id AS "subjectId",
|
|
150
|
+
permission.code AS "objectCode",
|
|
151
|
+
policyDefinition.action,
|
|
152
|
+
policyDefinition.effect,
|
|
153
|
+
policyDefinition.domain
|
|
154
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
155
|
+
INNER JOIN ${permissionTable} permission
|
|
156
|
+
ON policyDefinition.target_id = permission.id${this.softDeleteClause({ alias: 'permission' })}
|
|
157
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.GRANT.action}
|
|
158
|
+
AND policyDefinition.subject_type = ${subject.type}
|
|
159
|
+
AND policyDefinition.subject_id IN (${drizzle_orm_1.sql.join(subject.ids.map(id => (0, drizzle_orm_1.sql) `${id}`), (0, drizzle_orm_1.sql) `, `)})${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
160
|
+
`);
|
|
161
|
+
const lines = [];
|
|
162
|
+
for (const row of result.rows) {
|
|
163
|
+
if (!row.action) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const domain = row.domain ?? common_1.AuthorizationDomainScopes.ANY_MEMBER;
|
|
167
|
+
const effect = row.effect ?? common_1.AuthorizationDecisions.ALLOW;
|
|
168
|
+
lines.push(`${common_1.AuthorizationPolicyVariants.GRANT.rule}, ${subject.type}_${row.subjectId}, ${domain}, ${row.objectCode}, ${row.action}, ${effect}`);
|
|
169
|
+
}
|
|
170
|
+
return lines;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Load the system-wide hierarchy edges (role/resource/action/domain inherits) — read fresh on each
|
|
174
|
+
* call. These are the same for every user, but at this scale the four queries are cheap and run in
|
|
175
|
+
* the same parallel wave as the per-user queries; the per-user `lines` are themselves cached in Redis
|
|
176
|
+
* by the enforcer, so this only runs on a cache MISS. (No in-process cache → never goes stale.)
|
|
177
|
+
*/
|
|
178
|
+
async loadStructuralTrees() {
|
|
179
|
+
const [roleEdges, resourceEdges, actionEdges, domainEdges] = await Promise.all([
|
|
180
|
+
this.queryRoleInherits(),
|
|
181
|
+
this.queryResourceInherits(),
|
|
182
|
+
this.queryActionInherits(),
|
|
183
|
+
this.queryDomainInherits(),
|
|
184
|
+
]);
|
|
185
|
+
return [...roleEdges, ...resourceEdges, ...actionEdges, ...domainEdges];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Shared role hierarchy: every `role_inherits` edge as a casbin `g` line with a wildcard domain.
|
|
189
|
+
* These are the SAME for all users (org structure, not a user) and also seed {@link expandRoleClosure}.
|
|
190
|
+
* e.g. `g, Role_r2, Role_r1, *` — "Role r2 inherits Role r1 in any domain".
|
|
191
|
+
*/
|
|
192
|
+
async queryRoleInherits() {
|
|
193
|
+
const { policyDefinition, principals } = this.entities;
|
|
194
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
195
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
196
|
+
SELECT
|
|
197
|
+
policyDefinition.subject_id AS "childId",
|
|
198
|
+
policyDefinition.target_id AS "parentId"
|
|
199
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
200
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.ROLE_INHERITS.action}${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
201
|
+
`);
|
|
202
|
+
return result.rows.map(r => {
|
|
203
|
+
return `${common_1.AuthorizationPolicyVariants.ROLE_INHERITS.rule}, ${principals.role}_${r.childId}, ${principals.role}_${r.parentId}, *`;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Shared resource hierarchy: every `resource_inherits` edge as a casbin `g4` line, joining
|
|
208
|
+
* `Permission` twice (child + parent) to emit the resource CODES the `objectMatch` g4-func traverses.
|
|
209
|
+
* The `obj` axis — a permission on a parent resource also covers its children.
|
|
210
|
+
* e.g. `g4, OrderItem, Order` — "OrderItem is a child resource of Order".
|
|
211
|
+
*/
|
|
212
|
+
async queryResourceInherits() {
|
|
213
|
+
const { policyDefinition, permission } = this.entities;
|
|
214
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
215
|
+
const permissionTable = this.qualifiedTable({ table: permission });
|
|
216
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
217
|
+
SELECT
|
|
218
|
+
child_permission.code AS "childCode",
|
|
219
|
+
parent_permission.code AS "parentCode"
|
|
220
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
221
|
+
INNER JOIN ${permissionTable} child_permission ON policyDefinition.subject_id = child_permission.id
|
|
222
|
+
INNER JOIN ${permissionTable} parent_permission ON policyDefinition.target_id = parent_permission.id
|
|
223
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.RESOURCE_INHERITS.action}${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
224
|
+
`);
|
|
225
|
+
return result.rows.map(r => `${common_1.AuthorizationPolicyVariants.RESOURCE_INHERITS.rule}, ${r.childCode}, ${r.parentCode}`);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Shared action hierarchy: every `action_inherits` edge as a casbin `g5` line. Same shape as
|
|
229
|
+
* resource_inherits but a DIFFERENT axis — the `act` axis (e.g. `manage` covers `read`/`update`).
|
|
230
|
+
* Kept separate so resource × action stays factored instead of exploding to R×A combined edges.
|
|
231
|
+
* e.g. `g5, read, manage` — "the read action is implied by manage".
|
|
232
|
+
*/
|
|
233
|
+
async queryActionInherits() {
|
|
234
|
+
const { policyDefinition } = this.entities;
|
|
235
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
236
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
237
|
+
SELECT
|
|
238
|
+
policyDefinition.subject_id AS "childCode",
|
|
239
|
+
policyDefinition.target_id AS "parentCode"
|
|
240
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
241
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.ACTION_INHERITS.action}${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
242
|
+
`);
|
|
243
|
+
return result.rows.map(r => `${common_1.AuthorizationPolicyVariants.ACTION_INHERITS.rule}, ${r.childCode}, ${r.parentCode}`);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Shared domain hierarchy: every `domain_inherits` edge as a casbin `g3` line, with typed
|
|
247
|
+
* `<type>_<id>` endpoints — lets a grant in a parent domain cascade to child domains.
|
|
248
|
+
* e.g. `g3, Branch_1, Company_2` — "Branch 1 sits under Company 2".
|
|
249
|
+
*/
|
|
250
|
+
async queryDomainInherits() {
|
|
251
|
+
const { policyDefinition } = this.entities;
|
|
252
|
+
const policyDefinitionTable = this.qualifiedTable({ table: policyDefinition });
|
|
253
|
+
const result = await this.connector.execute((0, drizzle_orm_1.sql) `
|
|
254
|
+
SELECT
|
|
255
|
+
policyDefinition.subject_type AS "childType",
|
|
256
|
+
policyDefinition.subject_id AS "childId",
|
|
257
|
+
policyDefinition.target_type AS "parentType",
|
|
258
|
+
policyDefinition.target_id AS "parentId"
|
|
259
|
+
FROM ${policyDefinitionTable} policyDefinition
|
|
260
|
+
WHERE policyDefinition.variant = ${common_1.AuthorizationPolicyVariants.DOMAIN_INHERITS.action}${this.softDeleteClause({ alias: 'policyDefinition' })}
|
|
261
|
+
`);
|
|
262
|
+
return result.rows.map(r => `${common_1.AuthorizationPolicyVariants.DOMAIN_INHERITS.rule}, ${r.childType}_${r.childId}, ${r.parentType}_${r.parentId}`);
|
|
263
|
+
}
|
|
264
|
+
/** BFS over role_inherits edges to collect a role set + all transitive parents. Cycle-safe. */
|
|
265
|
+
expandRoleClosure(opts) {
|
|
266
|
+
const { role } = this.entities.principals;
|
|
267
|
+
const prefix = `${role}_`;
|
|
268
|
+
// Build child → parents map from "g, Role_<child>, Role_<parent>, *" lines.
|
|
269
|
+
const parentsOf = new Map();
|
|
270
|
+
for (const line of opts.role.edges) {
|
|
271
|
+
const parts = line.split(',').map(s => s.trim()); // ['g','Role_child','Role_parent','*']
|
|
272
|
+
if (parts[0] !== common_1.AuthorizationPolicyVariants.ROLE_INHERITS.rule || parts.length < 3) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const child = parts[1].startsWith(prefix) ? parts[1].slice(prefix.length) : parts[1];
|
|
276
|
+
const parent = parts[2].startsWith(prefix) ? parts[2].slice(prefix.length) : parts[2];
|
|
277
|
+
const list = parentsOf.get(child) ?? [];
|
|
278
|
+
list.push(parent);
|
|
279
|
+
parentsOf.set(child, list);
|
|
280
|
+
}
|
|
281
|
+
const rs = new Set();
|
|
282
|
+
const queue = opts.role.ids.map(String);
|
|
283
|
+
while (queue.length) {
|
|
284
|
+
const current = queue.shift();
|
|
285
|
+
if (rs.has(current)) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
rs.add(current);
|
|
289
|
+
const parents = parentsOf.get(current) ?? [];
|
|
290
|
+
for (const parent of parents) {
|
|
291
|
+
if (!rs.has(parent)) {
|
|
292
|
+
queue.push(parent);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return [...rs];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
exports.ScopedCasbinAdapter = ScopedCasbinAdapter;
|
|
300
|
+
//# sourceMappingURL=scoped-casbin.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-casbin.adapter.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/scoped-casbin.adapter.ts"],"names":[],"mappings":";;;AAGA,6CAA4C;AAC5C,sCAImB;AACnB,mDAAsD;AAUtD,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,mCAA8C;IAGrF,YAAY,IAAkE;QAC5E,KAAK,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,kBAAkB,CAAC,KAAY,EAAE,MAAiC;QACtE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;QAE7B,yEAAyE;QACzE,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC3E,IAAI,CAAC,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5E,IAAI,CAAC,mBAAmB,EAAE;SAC3B,CAAC,CAAC;QAEH,gGAAgG;QAChG,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACzC,IAAI,EAAE;gBACJ,GAAG,EAAE,WAAW,CAAC,OAAO;gBACxB,KAAK,EAAE,UAAU,CAAC,MAAM,CAA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CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;oBACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjB,CAAC;CACF;AAhYD,kDAgYC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Maps a logical table onto its physical name + schema. */
|
|
2
|
+
export interface IScopedCasbinTable {
|
|
3
|
+
tableName: string;
|
|
4
|
+
schemaName?: string;
|
|
5
|
+
}
|
|
6
|
+
/** All physical mapping the ScopedCasbinAdapter needs. App provides this; framework stays decoupled. */
|
|
7
|
+
export interface IScopedCasbinEntities {
|
|
8
|
+
/**
|
|
9
|
+
* The single edge table: each row links a subject (type+id) to a target (type+id), with a `variant`
|
|
10
|
+
* column saying what kind of edge it is (grant / assign_role / *_inherits …) plus optional
|
|
11
|
+
* action / effect / domain.
|
|
12
|
+
*/
|
|
13
|
+
policyDefinition: IScopedCasbinTable;
|
|
14
|
+
/** Permission catalog (id, code, ...). */
|
|
15
|
+
permission: IScopedCasbinTable;
|
|
16
|
+
/** Principal type labels used as casbin name prefixes. */
|
|
17
|
+
principals: {
|
|
18
|
+
user: string;
|
|
19
|
+
role: string;
|
|
20
|
+
};
|
|
21
|
+
/** Domain type labels (e.g. ['Merchant', 'Organizer']). */
|
|
22
|
+
domainTypes: string[];
|
|
23
|
+
/** Soft-delete handling for both tables. */
|
|
24
|
+
softDelete?: {
|
|
25
|
+
use: false;
|
|
26
|
+
} | {
|
|
27
|
+
use: true;
|
|
28
|
+
columnName: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wGAAwG;AACxG,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,gBAAgB,EAAE,kBAAkB,CAAC;IAErC,0CAA0C;IAC1C,UAAU,EAAE,kBAAkB,CAAC;IAE/B,0DAA0D;IAC1D,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAE3C,2DAA2D;IAC3D,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB,4CAA4C;IAC5C,UAAU,CAAC,EAAE;QAAE,GAAG,EAAE,KAAK,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CACjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/types.ts"],"names":[],"mappings":""}
|
|
@@ -4,14 +4,21 @@ export declare class Authorization {
|
|
|
4
4
|
static readonly RULES = "authorization.rules";
|
|
5
5
|
static readonly SKIP_AUTHORIZATION = "authorization.skip";
|
|
6
6
|
static readonly ENFORCER = "authorization.enforcer";
|
|
7
|
+
static readonly DOMAIN = "authorization.domain";
|
|
7
8
|
}
|
|
8
9
|
export declare class AuthorizationActions {
|
|
9
10
|
static readonly CREATE = "create";
|
|
10
|
-
static readonly READ = "read";
|
|
11
11
|
static readonly UPDATE = "update";
|
|
12
12
|
static readonly DELETE = "delete";
|
|
13
13
|
static readonly EXECUTE = "execute";
|
|
14
|
+
static readonly READ = "read";
|
|
15
|
+
static readonly WRITE = "write";
|
|
16
|
+
static readonly MANAGE = "manage";
|
|
14
17
|
static readonly SCHEME_SET: Set<string>;
|
|
18
|
+
static readonly LATTICE: ReadonlyArray<{
|
|
19
|
+
child: TAuthorizationAction;
|
|
20
|
+
parent: TAuthorizationAction;
|
|
21
|
+
}>;
|
|
15
22
|
static isValid(input: string): boolean;
|
|
16
23
|
}
|
|
17
24
|
export type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;
|
|
@@ -43,7 +50,6 @@ export declare class AuthorizationEnforcerTypes {
|
|
|
43
50
|
}
|
|
44
51
|
export type TAuthorizationEnforcerType = TConstValue<typeof AuthorizationEnforcerTypes>;
|
|
45
52
|
export declare class CasbinEnforcerCachedDrivers {
|
|
46
|
-
static readonly IN_MEMORY = "in-memory";
|
|
47
53
|
static readonly REDIS = "redis";
|
|
48
54
|
static readonly SCHEME_SET: Set<string>;
|
|
49
55
|
static isValid(input: string): boolean;
|
|
@@ -56,15 +62,145 @@ export declare class CasbinEnforcerModelDrivers {
|
|
|
56
62
|
static isValid(input: string): boolean;
|
|
57
63
|
}
|
|
58
64
|
export type TCasbinEnforcerModelDriver = TConstValue<typeof CasbinEnforcerModelDrivers>;
|
|
65
|
+
export declare class CasbinDomainMatchingFunctions {
|
|
66
|
+
/** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */
|
|
67
|
+
static readonly KEY_MATCH = "keyMatch";
|
|
68
|
+
/** Adds URL-path `:param` segment matching. */
|
|
69
|
+
static readonly KEY_MATCH_2 = "keyMatch2";
|
|
70
|
+
/** Adds `{param}` segment matching. */
|
|
71
|
+
static readonly KEY_MATCH_3 = "keyMatch3";
|
|
72
|
+
/** `{param}` matching with repeated-name equality checks. */
|
|
73
|
+
static readonly KEY_MATCH_4 = "keyMatch4";
|
|
74
|
+
/** Treats the stored/policy value as a full regular expression. */
|
|
75
|
+
static readonly REGEX_MATCH = "regexMatch";
|
|
76
|
+
static readonly SCHEME_SET: Set<string>;
|
|
77
|
+
static isValid(input: string): boolean;
|
|
78
|
+
}
|
|
79
|
+
export type TCasbinDomainMatchingFunction = TConstValue<typeof CasbinDomainMatchingFunctions>;
|
|
80
|
+
export declare class AuthorizationDomainScopes {
|
|
81
|
+
/** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */
|
|
82
|
+
static readonly ANY_MEMBER = "ANY_MEMBER";
|
|
83
|
+
/** Grant applies system-wide, bypassing membership — super-admin only. */
|
|
84
|
+
static readonly SYSTEM_WIDE = "SYSTEM_WIDE";
|
|
85
|
+
static readonly SCHEME_SET: Set<string>;
|
|
86
|
+
static isValid(input: string): boolean;
|
|
87
|
+
}
|
|
88
|
+
export type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;
|
|
89
|
+
/**
|
|
90
|
+
* Engine-level vocabulary: the relation prefixes the Casbin MODEL declares — `p` for permission
|
|
91
|
+
* policies and `g`/`g2`…`g5` for grouping relations. This is the low-level building block that
|
|
92
|
+
* {@link AuthorizationPolicyVariants} maps onto (many app edge-types → one rule, e.g. both
|
|
93
|
+
* `assign_role` and `role_inherits` use `g`). Keep these in sync with the model's `[role_definition]`.
|
|
94
|
+
*/
|
|
59
95
|
export declare class CasbinRuleVariants {
|
|
60
|
-
|
|
61
|
-
static readonly GROUP = "group";
|
|
62
|
-
/** Casbin line prefix for policy rules. */
|
|
96
|
+
/** Permission policy line. */
|
|
63
97
|
static readonly P = "p";
|
|
64
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Numbered in request-tuple order (`sub → dom → obj → act`) so the matcher reads left-to-right:
|
|
100
|
+
* g (sub), g2/g3 (dom), g4 (obj), g5 (act).
|
|
101
|
+
*/
|
|
102
|
+
/** Grouping #1 — role membership + role inheritance (user→role, role→role). The `sub` axis. */
|
|
65
103
|
static readonly G = "g";
|
|
66
|
-
|
|
67
|
-
static
|
|
104
|
+
/** Grouping #2 — user→domain membership (join_domain). The `dom` axis (membership). */
|
|
105
|
+
static readonly G2 = "g2";
|
|
106
|
+
/** Grouping #3 — domain hierarchy. The `dom` axis (nesting). */
|
|
107
|
+
static readonly G3 = "g3";
|
|
108
|
+
/** Grouping #4 — resource hierarchy. The `obj` axis. */
|
|
109
|
+
static readonly G4 = "g4";
|
|
110
|
+
/** Grouping #5 — action hierarchy. The `act` axis. */
|
|
111
|
+
static readonly G5 = "g5";
|
|
68
112
|
}
|
|
69
113
|
export type TCasbinRuleVariant = TConstValue<typeof CasbinRuleVariants>;
|
|
114
|
+
/**
|
|
115
|
+
* The kinds of "edge" stored in the single `PolicyDefinition` table. Every row links a `subject`
|
|
116
|
+
* (type + id) to a `target` (type + id); the `variant` column says WHAT kind of link it is.
|
|
117
|
+
*
|
|
118
|
+
* Picture the whole RBAC state as a graph — nodes are User / Role / Permission / Domain, and each
|
|
119
|
+
* PolicyDefinition row is one edge. `ScopedCasbinAdapter` reads these rows and emits one casbin line
|
|
120
|
+
* per edge. Each entry below carries:
|
|
121
|
+
* - `action` — the value stored in the DB `variant` column (what the adapter filters on).
|
|
122
|
+
* - `rule` — the casbin grouping/policy prefix the adapter emits for that edge (`p`, `g`, `g2`…).
|
|
123
|
+
*
|
|
124
|
+
* Per-USER edges (differ per user): GRANT, ASSIGN_ROLE, JOIN_DOMAIN.
|
|
125
|
+
* Shared HIERARCHY edges (same for everyone — describe the org structure, not a user):
|
|
126
|
+
* ROLE_INHERITS, RESOURCE_INHERITS, ACTION_INHERITS, DOMAIN_INHERITS.
|
|
127
|
+
*/
|
|
128
|
+
export declare class AuthorizationPolicyVariants {
|
|
129
|
+
/**
|
|
130
|
+
* Give a Permission to a User or Role (the grant row also carries action / effect / domain).
|
|
131
|
+
* casbin `p`: `p, <Role|User>_<id>, <domain>, <permissionCode>, <action>, <allow|deny>`
|
|
132
|
+
* e.g. `p, Role_5, ANY_MEMBER, Order, read, allow` — "Role 5 may read Order in any joined domain".
|
|
133
|
+
*/
|
|
134
|
+
static readonly GRANT: {
|
|
135
|
+
readonly action: "grant";
|
|
136
|
+
readonly rule: "p";
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Give a User a Role (optionally scoped to a domain; no domain → `*` = every domain).
|
|
140
|
+
* casbin `g`: `g, User_<id>, Role_<id>, <domain|*>`
|
|
141
|
+
* e.g. `g, User_42, Role_5, *` — "User 42 holds Role 5 everywhere".
|
|
142
|
+
*/
|
|
143
|
+
static readonly ASSIGN_ROLE: {
|
|
144
|
+
readonly action: "assign_role";
|
|
145
|
+
readonly rule: "g";
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* A Role inherits another Role (DAG). Shares the `g` relation with ASSIGN_ROLE so a
|
|
149
|
+
* user → role → parent-role chain resolves in one lookup. Emitted with domain `*`.
|
|
150
|
+
* casbin `g`: `g, Role_<child>, Role_<parent>, *`
|
|
151
|
+
* e.g. `g, Role_5, Role_9, *` — "Role 5 inherits everything Role 9 has".
|
|
152
|
+
*/
|
|
153
|
+
static readonly ROLE_INHERITS: {
|
|
154
|
+
readonly action: "role_inherits";
|
|
155
|
+
readonly rule: "g";
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* A User is a member of a Domain. Powers the `ANY_MEMBER` grant scope — a grant with domain
|
|
159
|
+
* `ANY_MEMBER` applies in every domain the user joined. Matcher uses `g2(r.sub, r.dom)`.
|
|
160
|
+
* casbin `g2`: `g2, User_<id>, <Type>_<domainId>`
|
|
161
|
+
* e.g. `g2, User_42, Merchant_7` — "User 42 is a member of Merchant 7".
|
|
162
|
+
*/
|
|
163
|
+
static readonly JOIN_DOMAIN: {
|
|
164
|
+
readonly action: "join_domain";
|
|
165
|
+
readonly rule: "g2";
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* DOMAIN axis (the `dom` of a request). One domain is nested under a parent domain.
|
|
169
|
+
* Matcher: `g3(r.dom, p.dom)` (+ self-link, so an exact domain always matches itself).
|
|
170
|
+
* casbin `g3`: `g3, <Type>_<childId>, <Type>_<parentId>`
|
|
171
|
+
* e.g. `g3, Branch_1, Company_9` — "a grant scoped to Company 9 also applies in Branch 1".
|
|
172
|
+
*/
|
|
173
|
+
static readonly DOMAIN_INHERITS: {
|
|
174
|
+
readonly action: "domain_inherits";
|
|
175
|
+
readonly rule: "g3";
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* RESOURCE axis (the `obj` of a request). One resource is nested under a broader one — for
|
|
179
|
+
* NON-standard nesting only; dotted nesting (`Order.findById ⊂ Order`) is handled by `objectMatch`
|
|
180
|
+
* WITHOUT an edge. Matcher: `objectMatch(r.obj, p.obj) || g4(r.obj, p.obj)`.
|
|
181
|
+
* casbin `g4`: `g4, <childCode>, <parentCode>`
|
|
182
|
+
* e.g. `g4, OrderItem, Order` — "a grant on Order also covers OrderItem".
|
|
183
|
+
*/
|
|
184
|
+
static readonly RESOURCE_INHERITS: {
|
|
185
|
+
readonly action: "resource_inherits";
|
|
186
|
+
readonly rule: "g4";
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* ACTION axis (the `act` of a request) — SAME shape as RESOURCE_INHERITS but a DIFFERENT axis: a
|
|
190
|
+
* narrow action is covered by a broader one. No dotted shortcut — needs an explicit edge.
|
|
191
|
+
* Matcher: `g5(r.act, p.act)`.
|
|
192
|
+
* casbin `g5`: `g5, <childAction>, <parentAction>`
|
|
193
|
+
* e.g. `g5, read, manage` — "a grant of manage also allows read".
|
|
194
|
+
* (g4 + g5 combine multiplicatively: a `manage Order` grant covers a `read OrderItem` request.)
|
|
195
|
+
*/
|
|
196
|
+
static readonly ACTION_INHERITS: {
|
|
197
|
+
readonly action: "action_inherits";
|
|
198
|
+
readonly rule: "g5";
|
|
199
|
+
};
|
|
200
|
+
static readonly ACTION_SCHEME_SET: Set<string>;
|
|
201
|
+
static readonly RULE_SCHEME_SET: Set<string>;
|
|
202
|
+
static isValidAction(input: string): boolean;
|
|
203
|
+
static isValidRule(input: string): boolean;
|
|
204
|
+
}
|
|
205
|
+
export type TAuthorizationPolicyVariant = TConstValue<typeof AuthorizationPolicyVariants>;
|
|
70
206
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/common/constants.ts"],"names":[],"m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