@venizia/ignis 0.0.9-8 → 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/metadata/persistents.d.ts.map +1 -1
- package/dist/base/metadata/persistents.js +6 -0
- package/dist/base/metadata/persistents.js.map +1 -1
- 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/abstract.d.ts +2 -0
- package/dist/base/repositories/core/abstract.d.ts.map +1 -1
- package/dist/base/repositories/core/readable.d.ts.map +1 -1
- package/dist/base/repositories/core/readable.js +17 -5
- 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/base/repositories/mixins/default-filter.d.ts +3 -0
- package/dist/base/repositories/mixins/default-filter.d.ts.map +1 -1
- package/dist/base/repositories/mixins/default-filter.js +11 -0
- package/dist/base/repositories/mixins/default-filter.js.map +1 -1
- package/dist/base/repositories/operators/filter.d.ts +4 -0
- package/dist/base/repositories/operators/filter.d.ts.map +1 -1
- package/dist/base/repositories/operators/filter.js +19 -1
- package/dist/base/repositories/operators/filter.js.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/dist/helpers/inversion/common/types.d.ts +2 -0
- package/dist/helpers/inversion/common/types.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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC"}
|
|
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./base-filtered"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./scoped-casbin.adapter"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/adapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,0DAAwC;AACxC,0CAAwB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { IdType } from '../../../../base';
|
|
2
|
+
import { IDataSource } from '../../../../base/datasources';
|
|
3
|
+
import { type Model } from 'casbin';
|
|
4
|
+
import { type SQL } from 'drizzle-orm';
|
|
5
|
+
import { BaseFilteredAdapter } from './base-filtered';
|
|
6
|
+
import { type IScopedCasbinEntities } from './types';
|
|
7
|
+
export type { IScopedCasbinEntities };
|
|
8
|
+
export interface IScopedCasbinPolicyFilter {
|
|
9
|
+
principal: {
|
|
10
|
+
type: string;
|
|
11
|
+
id: IdType;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Filtered casbin adapter for the scoped RBAC model: loads ONE principal's edges (role assignments,
|
|
16
|
+
* memberships, grants) plus the shared structural hierarchy trees as casbin lines. Read-only.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ScopedCasbinAdapter extends BaseFilteredAdapter<IScopedCasbinPolicyFilter> {
|
|
19
|
+
protected readonly entities: IScopedCasbinEntities;
|
|
20
|
+
constructor(opts: {
|
|
21
|
+
dataSource: IDataSource;
|
|
22
|
+
entities: IScopedCasbinEntities;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Casbin's filtered-load entry point: build the full line set for ONE principal and load it into
|
|
26
|
+
* the model. Runs in two waves —
|
|
27
|
+
* Wave 1 (parallel): the principal's own edges (role assignments → g, memberships → g2, direct
|
|
28
|
+
* grants → p) plus the shared structural trees (role/resource/action/domain inherits).
|
|
29
|
+
* Wave 2: expand the assigned roles to their transitive parents (role closure over role_inherits),
|
|
30
|
+
* then fetch the grants those roles carry — so a user inherits permissions from parent roles.
|
|
31
|
+
* The concatenated lines are handed to {@link loadLines}; the enforcer caches the result per user
|
|
32
|
+
* in Redis, so this only runs on a cache MISS.
|
|
33
|
+
*/
|
|
34
|
+
loadFilteredPolicy(model: Model, filter: IScopedCasbinPolicyFilter): Promise<void>;
|
|
35
|
+
/** Schema for a table, defaulting to `public`. */
|
|
36
|
+
protected schemaOf(table: {
|
|
37
|
+
schemaName?: string;
|
|
38
|
+
}): string;
|
|
39
|
+
/** Schema-qualified table reference (`"<schema>"."<table>"`) for use after FROM/JOIN with an alias. */
|
|
40
|
+
protected qualifiedTable(opts: {
|
|
41
|
+
table: {
|
|
42
|
+
schemaName?: string;
|
|
43
|
+
tableName: string;
|
|
44
|
+
};
|
|
45
|
+
}): SQL;
|
|
46
|
+
/**
|
|
47
|
+
* `AND <alias>.<col> IS NULL` when soft-delete on; empty otherwise. The alias is emitted RAW (not
|
|
48
|
+
* quoted) so it matches the unquoted alias declared in the FROM clause (`FROM ... policyDefinition`):
|
|
49
|
+
* Postgres folds unquoted identifiers to lower-case, so a quoted `"policyDefinition"` would resolve
|
|
50
|
+
* to a DIFFERENT relation than the unquoted FROM alias → 42P01 "missing FROM-clause entry". The alias
|
|
51
|
+
* is always a hard-coded literal supplied by this adapter, never user input, so emitting it raw is
|
|
52
|
+
* safe; the (config-supplied) column name stays quoted via `sql.identifier`.
|
|
53
|
+
*/
|
|
54
|
+
protected softDeleteClause(opts: {
|
|
55
|
+
alias: string;
|
|
56
|
+
}): SQL;
|
|
57
|
+
/**
|
|
58
|
+
* Fetch the principal's `assign_role` edges and emit them as casbin `g` lines (role membership).
|
|
59
|
+
* Returns both the lines AND the raw `roleIds`, which Wave 2 feeds into {@link expandRoleClosure}.
|
|
60
|
+
* A null domain widens the assignment to every domain (`*`).
|
|
61
|
+
* e.g. `g, User_u1, Role_r1, *` — "u1 holds Role r1 in any domain".
|
|
62
|
+
*/
|
|
63
|
+
protected queryRoleAssignments(opts: {
|
|
64
|
+
principal: {
|
|
65
|
+
type: string;
|
|
66
|
+
id: IdType;
|
|
67
|
+
};
|
|
68
|
+
}): Promise<{
|
|
69
|
+
lines: string[];
|
|
70
|
+
roleIds: IdType[];
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch the principal's `join_domain` edges (restricted to the configured `domainTypes`) and emit
|
|
74
|
+
* them as casbin `g2` lines — the membership relation the matcher uses to scope `ANY_MEMBER` grants.
|
|
75
|
+
* e.g. `g2, User_u1, Merchant_7` — "u1 is a member of Merchant 7".
|
|
76
|
+
*/
|
|
77
|
+
protected queryMemberships(opts: {
|
|
78
|
+
principal: {
|
|
79
|
+
type: string;
|
|
80
|
+
id: IdType;
|
|
81
|
+
};
|
|
82
|
+
}): Promise<string[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Fetch `grant` edges for the given subjects (a User or a set of Roles) joined to `Permission` for
|
|
85
|
+
* the object code, and emit them as casbin `p` policy lines. Used twice per load: once for the
|
|
86
|
+
* user's direct grants, once for the grants of every role in the closure. Rows with no `action` are
|
|
87
|
+
* skipped; a null effect defaults to allow, a null domain to `ANY_MEMBER`. Empty `ids` short-circuits
|
|
88
|
+
* without touching the DB.
|
|
89
|
+
* e.g. `p, Role_5, ANY_MEMBER, Order, read, allow` — "Role 5 may read Order in any joined domain".
|
|
90
|
+
*/
|
|
91
|
+
protected queryGrants(opts: {
|
|
92
|
+
subject: {
|
|
93
|
+
type: string;
|
|
94
|
+
ids: IdType[];
|
|
95
|
+
};
|
|
96
|
+
}): Promise<string[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Load the system-wide hierarchy edges (role/resource/action/domain inherits) — read fresh on each
|
|
99
|
+
* call. These are the same for every user, but at this scale the four queries are cheap and run in
|
|
100
|
+
* the same parallel wave as the per-user queries; the per-user `lines` are themselves cached in Redis
|
|
101
|
+
* by the enforcer, so this only runs on a cache MISS. (No in-process cache → never goes stale.)
|
|
102
|
+
*/
|
|
103
|
+
protected loadStructuralTrees(): Promise<string[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Shared role hierarchy: every `role_inherits` edge as a casbin `g` line with a wildcard domain.
|
|
106
|
+
* These are the SAME for all users (org structure, not a user) and also seed {@link expandRoleClosure}.
|
|
107
|
+
* e.g. `g, Role_r2, Role_r1, *` — "Role r2 inherits Role r1 in any domain".
|
|
108
|
+
*/
|
|
109
|
+
protected queryRoleInherits(): Promise<string[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Shared resource hierarchy: every `resource_inherits` edge as a casbin `g4` line, joining
|
|
112
|
+
* `Permission` twice (child + parent) to emit the resource CODES the `objectMatch` g4-func traverses.
|
|
113
|
+
* The `obj` axis — a permission on a parent resource also covers its children.
|
|
114
|
+
* e.g. `g4, OrderItem, Order` — "OrderItem is a child resource of Order".
|
|
115
|
+
*/
|
|
116
|
+
protected queryResourceInherits(): Promise<string[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Shared action hierarchy: every `action_inherits` edge as a casbin `g5` line. Same shape as
|
|
119
|
+
* resource_inherits but a DIFFERENT axis — the `act` axis (e.g. `manage` covers `read`/`update`).
|
|
120
|
+
* Kept separate so resource × action stays factored instead of exploding to R×A combined edges.
|
|
121
|
+
* e.g. `g5, read, manage` — "the read action is implied by manage".
|
|
122
|
+
*/
|
|
123
|
+
protected queryActionInherits(): Promise<string[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Shared domain hierarchy: every `domain_inherits` edge as a casbin `g3` line, with typed
|
|
126
|
+
* `<type>_<id>` endpoints — lets a grant in a parent domain cascade to child domains.
|
|
127
|
+
* e.g. `g3, Branch_1, Company_2` — "Branch 1 sits under Company 2".
|
|
128
|
+
*/
|
|
129
|
+
protected queryDomainInherits(): Promise<string[]>;
|
|
130
|
+
/** BFS over role_inherits edges to collect a role set + all transitive parents. Cycle-safe. */
|
|
131
|
+
protected expandRoleClosure(opts: {
|
|
132
|
+
role: {
|
|
133
|
+
ids: IdType[];
|
|
134
|
+
edges: string[];
|
|
135
|
+
};
|
|
136
|
+
}): IdType[];
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=scoped-casbin.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-casbin.adapter.d.ts","sourceRoot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
|
|
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,C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,CAAC,IAAI,EAAE,CAAC;YAC7C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC,EAAE,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":""}
|