@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationPermissionBuilder = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Builders for `Permission` catalog rows (the `obj` axis the scoped matcher resolves).
|
|
7
|
+
*
|
|
8
|
+
* Generic over the name/description type (`TName`) so an app with i18n `name`/`description` columns and
|
|
9
|
+
* one with plain-text names both fit. Produces the framework-owned columns
|
|
10
|
+
* (code/subject/method/action/scope/description/parentId); `description` defaults to `null`.
|
|
11
|
+
* App-specific columns are added by the caller.
|
|
12
|
+
*/
|
|
13
|
+
class AuthorizationPermissionBuilder {
|
|
14
|
+
/** Sentinel `method` for a coarse resource node (a grant target that is not a route). */
|
|
15
|
+
static { this.RESOURCE_NODE_METHOD = '*'; }
|
|
16
|
+
/** Standard repository method → base action. Unlisted methods (custom ops, aggregates) resolve to `execute`. */
|
|
17
|
+
static { this.METHOD_ACTIONS = {
|
|
18
|
+
find: constants_1.AuthorizationActions.READ,
|
|
19
|
+
findById: constants_1.AuthorizationActions.READ,
|
|
20
|
+
findOne: constants_1.AuthorizationActions.READ,
|
|
21
|
+
count: constants_1.AuthorizationActions.READ,
|
|
22
|
+
create: constants_1.AuthorizationActions.CREATE,
|
|
23
|
+
updateById: constants_1.AuthorizationActions.UPDATE,
|
|
24
|
+
updateBy: constants_1.AuthorizationActions.UPDATE,
|
|
25
|
+
deleteById: constants_1.AuthorizationActions.DELETE,
|
|
26
|
+
deleteBy: constants_1.AuthorizationActions.DELETE,
|
|
27
|
+
}; }
|
|
28
|
+
/** The CRUD methods {@link crud} generates by default. */
|
|
29
|
+
static { this.DEFAULT_CRUD_METHODS = [
|
|
30
|
+
'find',
|
|
31
|
+
'findById',
|
|
32
|
+
'findOne',
|
|
33
|
+
'count',
|
|
34
|
+
'create',
|
|
35
|
+
'updateById',
|
|
36
|
+
'updateBy',
|
|
37
|
+
'deleteById',
|
|
38
|
+
'deleteBy',
|
|
39
|
+
]; }
|
|
40
|
+
/** Base action for a method: a known CRUD method maps to read/create/update/delete; anything else → `execute`. */
|
|
41
|
+
static actionForMethod(method) {
|
|
42
|
+
return AuthorizationPermissionBuilder.METHOD_ACTIONS[method] ?? constants_1.AuthorizationActions.EXECUTE;
|
|
43
|
+
}
|
|
44
|
+
/** One operation-level permission, `code = <subject>.<method>`. `action` defaults to {@link actionForMethod}. */
|
|
45
|
+
static operation(opts) {
|
|
46
|
+
return {
|
|
47
|
+
code: [opts.subject, opts.method].join('.'),
|
|
48
|
+
subject: opts.subject,
|
|
49
|
+
method: opts.method,
|
|
50
|
+
action: opts.action ?? AuthorizationPermissionBuilder.actionForMethod(opts.method),
|
|
51
|
+
scope: opts.scope,
|
|
52
|
+
description: opts.description ?? null,
|
|
53
|
+
parentId: opts.parentId ?? null,
|
|
54
|
+
name: opts.name,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A coarse resource node (module or subject) used as a grant target, e.g. `Sale` or `SaleOrder`.
|
|
59
|
+
* `code` is the bare name (no dotted method); `method` is the {@link RESOURCE_NODE_METHOD} sentinel.
|
|
60
|
+
* `action` defaults to `manage` (the broadest), though the grant on this node carries its own action.
|
|
61
|
+
*/
|
|
62
|
+
static resourceNode(opts) {
|
|
63
|
+
return {
|
|
64
|
+
code: opts.code,
|
|
65
|
+
subject: opts.subject ?? opts.code,
|
|
66
|
+
method: AuthorizationPermissionBuilder.RESOURCE_NODE_METHOD,
|
|
67
|
+
action: opts.action ?? constants_1.AuthorizationActions.MANAGE,
|
|
68
|
+
scope: opts.scope,
|
|
69
|
+
description: opts.description ?? null,
|
|
70
|
+
parentId: opts.parentId ?? null,
|
|
71
|
+
name: opts.name,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The CRUD permission set for a subject. `name` (and optional `description`) are per-method formatters,
|
|
76
|
+
* so the app supplies its own labels/i18n; the framework only owns the method→action map and code shape.
|
|
77
|
+
*/
|
|
78
|
+
static crud(opts) {
|
|
79
|
+
const methods = opts.methods ?? AuthorizationPermissionBuilder.DEFAULT_CRUD_METHODS;
|
|
80
|
+
return methods.map(method => {
|
|
81
|
+
const action = AuthorizationPermissionBuilder.actionForMethod(method);
|
|
82
|
+
const ctx = {
|
|
83
|
+
subject: opts.subject,
|
|
84
|
+
method,
|
|
85
|
+
action,
|
|
86
|
+
};
|
|
87
|
+
return AuthorizationPermissionBuilder.operation({
|
|
88
|
+
subject: opts.subject,
|
|
89
|
+
method,
|
|
90
|
+
scope: opts.scope,
|
|
91
|
+
action,
|
|
92
|
+
name: opts.name(ctx),
|
|
93
|
+
description: opts.description ? opts.description(ctx) : undefined,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.AuthorizationPermissionBuilder = AuthorizationPermissionBuilder;
|
|
99
|
+
//# sourceMappingURL=permission-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-builder.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/common/permission-builder.ts"],"names":[],"mappings":";;;AAEA,2CAAyE;AAEzE;;;;;;;GAOG;AACH,MAAa,8BAA8B;IACzC,yFAAyF;aACzE,yBAAoB,GAAG,GAAG,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} from '../../../../base';
|
|
2
|
+
import { TNullable } from '../../../../helpers';
|
|
3
|
+
import { TAuthorizationAction, TAuthorizationDecision } from './constants';
|
|
4
|
+
/** A grant/assignment domain: a scope literal (`SYSTEM_WIDE`/`ANY_MEMBER`) or a typed domain entity. */
|
|
5
|
+
export type TPolicyDomainInput = string | {
|
|
6
|
+
type: string;
|
|
7
|
+
id: IdType;
|
|
8
|
+
};
|
|
9
|
+
export declare class AuthorizationPolicyBuilder {
|
|
10
|
+
static readonly ACTION_PRINCIPAL = "Action";
|
|
11
|
+
/**
|
|
12
|
+
* Serialize a domain to the casbin token the matcher compares against {@link resolveRequestDomain}'s
|
|
13
|
+
* output: a scope literal (`SYSTEM_WIDE`/`ANY_MEMBER`) passes through unchanged; a typed domain becomes
|
|
14
|
+
* `<type>_<id>` so `g3(r.dom, p.dom)` cascades; null ⇒ null (the adapter then defaults grants to `ANY_MEMBER`).
|
|
15
|
+
*/
|
|
16
|
+
private static serializeDomain;
|
|
17
|
+
/**
|
|
18
|
+
* A grant (casbin `p`): role/user → permission, carrying action + effect + domain.
|
|
19
|
+
* `domain` null ⇒ `ANY_MEMBER` (adapter default). Pass a scope literal or a typed `{ type, id }` domain.
|
|
20
|
+
*/
|
|
21
|
+
static grant(opts: {
|
|
22
|
+
subject: {
|
|
23
|
+
type: string;
|
|
24
|
+
id: IdType;
|
|
25
|
+
};
|
|
26
|
+
permission: {
|
|
27
|
+
type: string;
|
|
28
|
+
id: IdType;
|
|
29
|
+
};
|
|
30
|
+
action: string;
|
|
31
|
+
domain?: TNullable<TPolicyDomainInput>;
|
|
32
|
+
effect: TAuthorizationDecision;
|
|
33
|
+
}): {
|
|
34
|
+
variant: "grant";
|
|
35
|
+
subjectType: string;
|
|
36
|
+
subjectId: IdType;
|
|
37
|
+
targetType: string;
|
|
38
|
+
targetId: IdType;
|
|
39
|
+
action: string;
|
|
40
|
+
effect: string;
|
|
41
|
+
domain: TNullable<string>;
|
|
42
|
+
};
|
|
43
|
+
/** Assign a role to a user (casbin `g`). `domain` null ⇒ `*` (every domain). */
|
|
44
|
+
static assignRole(opts: {
|
|
45
|
+
user: {
|
|
46
|
+
type: string;
|
|
47
|
+
id: IdType;
|
|
48
|
+
};
|
|
49
|
+
role: {
|
|
50
|
+
type: string;
|
|
51
|
+
id: IdType;
|
|
52
|
+
};
|
|
53
|
+
domain?: TNullable<TPolicyDomainInput>;
|
|
54
|
+
}): {
|
|
55
|
+
variant: "assign_role";
|
|
56
|
+
subjectType: string;
|
|
57
|
+
subjectId: IdType;
|
|
58
|
+
targetType: string;
|
|
59
|
+
targetId: IdType;
|
|
60
|
+
domain: TNullable<string>;
|
|
61
|
+
};
|
|
62
|
+
/** A user joins a domain (casbin `g2`) — backs the `ANY_MEMBER` grant scope. */
|
|
63
|
+
static joinDomain(opts: {
|
|
64
|
+
user: {
|
|
65
|
+
type: string;
|
|
66
|
+
id: IdType;
|
|
67
|
+
};
|
|
68
|
+
domain: {
|
|
69
|
+
type: string;
|
|
70
|
+
id: IdType;
|
|
71
|
+
};
|
|
72
|
+
}): {
|
|
73
|
+
variant: "join_domain";
|
|
74
|
+
subjectType: string;
|
|
75
|
+
subjectId: IdType;
|
|
76
|
+
targetType: string;
|
|
77
|
+
targetId: IdType;
|
|
78
|
+
};
|
|
79
|
+
/** A role inherits another role (casbin `g`, shared relation with assign_role). */
|
|
80
|
+
static roleInherits(opts: {
|
|
81
|
+
child: {
|
|
82
|
+
type: string;
|
|
83
|
+
id: IdType;
|
|
84
|
+
};
|
|
85
|
+
parent: {
|
|
86
|
+
type: string;
|
|
87
|
+
id: IdType;
|
|
88
|
+
};
|
|
89
|
+
}): {
|
|
90
|
+
variant: "role_inherits";
|
|
91
|
+
subjectType: string;
|
|
92
|
+
subjectId: IdType;
|
|
93
|
+
targetType: string;
|
|
94
|
+
targetId: IdType;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* A resource inherits another (casbin `g4`): a grant on the PARENT covers the CHILD.
|
|
98
|
+
* e.g. `{ child: SaleOrder, parent: Sale }` — grant on module `Sale` covers subject `SaleOrder`.
|
|
99
|
+
* Many-to-many: a subject may inherit several module parents (add one edge each).
|
|
100
|
+
*/
|
|
101
|
+
static resourceInherits(opts: {
|
|
102
|
+
child: {
|
|
103
|
+
type: string;
|
|
104
|
+
id: IdType;
|
|
105
|
+
};
|
|
106
|
+
parent: {
|
|
107
|
+
type: string;
|
|
108
|
+
id: IdType;
|
|
109
|
+
};
|
|
110
|
+
}): {
|
|
111
|
+
variant: "resource_inherits";
|
|
112
|
+
subjectType: string;
|
|
113
|
+
subjectId: IdType;
|
|
114
|
+
targetType: string;
|
|
115
|
+
targetId: IdType;
|
|
116
|
+
};
|
|
117
|
+
/** An action inherits another (casbin `g5`): the child action is implied by the parent, e.g. read ⊂ manage. */
|
|
118
|
+
static actionInherits(opts: {
|
|
119
|
+
child: TAuthorizationAction;
|
|
120
|
+
parent: TAuthorizationAction;
|
|
121
|
+
}): {
|
|
122
|
+
variant: "action_inherits";
|
|
123
|
+
subjectType: string;
|
|
124
|
+
subjectId: string;
|
|
125
|
+
targetType: string;
|
|
126
|
+
targetId: string;
|
|
127
|
+
};
|
|
128
|
+
/** All `action_inherits` rows for the standard {@link AuthorizationActions.LATTICE}. Seed once, idempotently. */
|
|
129
|
+
static actionLattice(): {
|
|
130
|
+
variant: "action_inherits";
|
|
131
|
+
subjectType: string;
|
|
132
|
+
subjectId: string;
|
|
133
|
+
targetType: string;
|
|
134
|
+
targetId: string;
|
|
135
|
+
}[];
|
|
136
|
+
/** A domain inherits another (casbin `g3`): a grant in the parent domain cascades to the child. e.g. Merchant ⊂ Organizer. */
|
|
137
|
+
static domainInherits(opts: {
|
|
138
|
+
child: {
|
|
139
|
+
type: string;
|
|
140
|
+
id: IdType;
|
|
141
|
+
};
|
|
142
|
+
parent: {
|
|
143
|
+
type: string;
|
|
144
|
+
id: IdType;
|
|
145
|
+
};
|
|
146
|
+
}): {
|
|
147
|
+
variant: "domain_inherits";
|
|
148
|
+
subjectType: string;
|
|
149
|
+
subjectId: IdType;
|
|
150
|
+
targetType: string;
|
|
151
|
+
targetId: IdType;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Build a role's coarse grant rows from resolved permission ids. The caller resolves each
|
|
155
|
+
* `resourceCode` (subject/module) to a `Permission` and supplies the lookup; unresolved codes are skipped.
|
|
156
|
+
*/
|
|
157
|
+
static roleGrants(opts: {
|
|
158
|
+
role: {
|
|
159
|
+
type: string;
|
|
160
|
+
id: IdType;
|
|
161
|
+
};
|
|
162
|
+
permission: {
|
|
163
|
+
type: string;
|
|
164
|
+
idByCode: ReadonlyMap<string, string>;
|
|
165
|
+
};
|
|
166
|
+
grants: ReadonlyArray<{
|
|
167
|
+
resourceCode: string;
|
|
168
|
+
action: string;
|
|
169
|
+
domain?: TNullable<TPolicyDomainInput>;
|
|
170
|
+
effect: TAuthorizationDecision;
|
|
171
|
+
}>;
|
|
172
|
+
}): {
|
|
173
|
+
variant: "grant";
|
|
174
|
+
subjectType: string;
|
|
175
|
+
subjectId: IdType;
|
|
176
|
+
targetType: string;
|
|
177
|
+
targetId: IdType;
|
|
178
|
+
action: string;
|
|
179
|
+
effect: string;
|
|
180
|
+
domain: TNullable<string>;
|
|
181
|
+
}[];
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=policy-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-builder.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/common/policy-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAGL,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,wGAAwG;AACxG,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EA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ChC,CAAC,CAAC;KACJ;;;;;;;;;;CAsBF"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationPolicyBuilder = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
class AuthorizationPolicyBuilder {
|
|
6
|
+
static { this.ACTION_PRINCIPAL = 'Action'; }
|
|
7
|
+
/**
|
|
8
|
+
* Serialize a domain to the casbin token the matcher compares against {@link resolveRequestDomain}'s
|
|
9
|
+
* output: a scope literal (`SYSTEM_WIDE`/`ANY_MEMBER`) passes through unchanged; a typed domain becomes
|
|
10
|
+
* `<type>_<id>` so `g3(r.dom, p.dom)` cascades; null ⇒ null (the adapter then defaults grants to `ANY_MEMBER`).
|
|
11
|
+
*/
|
|
12
|
+
static serializeDomain(domain) {
|
|
13
|
+
if (domain == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof domain === 'string') {
|
|
17
|
+
return domain;
|
|
18
|
+
}
|
|
19
|
+
return [domain.type, domain.id].join('_');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A grant (casbin `p`): role/user → permission, carrying action + effect + domain.
|
|
23
|
+
* `domain` null ⇒ `ANY_MEMBER` (adapter default). Pass a scope literal or a typed `{ type, id }` domain.
|
|
24
|
+
*/
|
|
25
|
+
static grant(opts) {
|
|
26
|
+
return {
|
|
27
|
+
variant: constants_1.AuthorizationPolicyVariants.GRANT.action,
|
|
28
|
+
subjectType: opts.subject.type,
|
|
29
|
+
subjectId: opts.subject.id,
|
|
30
|
+
targetType: opts.permission.type,
|
|
31
|
+
targetId: opts.permission.id,
|
|
32
|
+
action: opts.action,
|
|
33
|
+
effect: opts.effect,
|
|
34
|
+
domain: AuthorizationPolicyBuilder.serializeDomain(opts.domain),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Assign a role to a user (casbin `g`). `domain` null ⇒ `*` (every domain). */
|
|
38
|
+
static assignRole(opts) {
|
|
39
|
+
return {
|
|
40
|
+
variant: constants_1.AuthorizationPolicyVariants.ASSIGN_ROLE.action,
|
|
41
|
+
subjectType: opts.user.type,
|
|
42
|
+
subjectId: opts.user.id,
|
|
43
|
+
targetType: opts.role.type,
|
|
44
|
+
targetId: opts.role.id,
|
|
45
|
+
domain: AuthorizationPolicyBuilder.serializeDomain(opts.domain),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** A user joins a domain (casbin `g2`) — backs the `ANY_MEMBER` grant scope. */
|
|
49
|
+
static joinDomain(opts) {
|
|
50
|
+
return {
|
|
51
|
+
variant: constants_1.AuthorizationPolicyVariants.JOIN_DOMAIN.action,
|
|
52
|
+
subjectType: opts.user.type,
|
|
53
|
+
subjectId: opts.user.id,
|
|
54
|
+
targetType: opts.domain.type,
|
|
55
|
+
targetId: opts.domain.id,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** A role inherits another role (casbin `g`, shared relation with assign_role). */
|
|
59
|
+
static roleInherits(opts) {
|
|
60
|
+
return {
|
|
61
|
+
variant: constants_1.AuthorizationPolicyVariants.ROLE_INHERITS.action,
|
|
62
|
+
subjectType: opts.child.type,
|
|
63
|
+
subjectId: opts.child.id,
|
|
64
|
+
targetType: opts.parent.type,
|
|
65
|
+
targetId: opts.parent.id,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A resource inherits another (casbin `g4`): a grant on the PARENT covers the CHILD.
|
|
70
|
+
* e.g. `{ child: SaleOrder, parent: Sale }` — grant on module `Sale` covers subject `SaleOrder`.
|
|
71
|
+
* Many-to-many: a subject may inherit several module parents (add one edge each).
|
|
72
|
+
*/
|
|
73
|
+
static resourceInherits(opts) {
|
|
74
|
+
return {
|
|
75
|
+
variant: constants_1.AuthorizationPolicyVariants.RESOURCE_INHERITS.action,
|
|
76
|
+
subjectType: opts.child.type,
|
|
77
|
+
subjectId: opts.child.id,
|
|
78
|
+
targetType: opts.parent.type,
|
|
79
|
+
targetId: opts.parent.id,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** An action inherits another (casbin `g5`): the child action is implied by the parent, e.g. read ⊂ manage. */
|
|
83
|
+
static actionInherits(opts) {
|
|
84
|
+
return {
|
|
85
|
+
variant: constants_1.AuthorizationPolicyVariants.ACTION_INHERITS.action,
|
|
86
|
+
subjectType: this.ACTION_PRINCIPAL,
|
|
87
|
+
subjectId: opts.child,
|
|
88
|
+
targetType: this.ACTION_PRINCIPAL,
|
|
89
|
+
targetId: opts.parent,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** All `action_inherits` rows for the standard {@link AuthorizationActions.LATTICE}. Seed once, idempotently. */
|
|
93
|
+
static actionLattice() {
|
|
94
|
+
return constants_1.AuthorizationActions.LATTICE.map(action => this.actionInherits(action));
|
|
95
|
+
}
|
|
96
|
+
/** A domain inherits another (casbin `g3`): a grant in the parent domain cascades to the child. e.g. Merchant ⊂ Organizer. */
|
|
97
|
+
static domainInherits(opts) {
|
|
98
|
+
return {
|
|
99
|
+
variant: constants_1.AuthorizationPolicyVariants.DOMAIN_INHERITS.action,
|
|
100
|
+
subjectType: opts.child.type,
|
|
101
|
+
subjectId: opts.child.id,
|
|
102
|
+
targetType: opts.parent.type,
|
|
103
|
+
targetId: opts.parent.id,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build a role's coarse grant rows from resolved permission ids. The caller resolves each
|
|
108
|
+
* `resourceCode` (subject/module) to a `Permission` and supplies the lookup; unresolved codes are skipped.
|
|
109
|
+
*/
|
|
110
|
+
static roleGrants(opts) {
|
|
111
|
+
const rows = [];
|
|
112
|
+
for (const grant of opts.grants) {
|
|
113
|
+
const permissionId = opts.permission.idByCode.get(grant.resourceCode);
|
|
114
|
+
if (!permissionId) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const policy = AuthorizationPolicyBuilder.grant({
|
|
118
|
+
subject: { type: opts.role.type, id: opts.role.id },
|
|
119
|
+
permission: { type: opts.permission.type, id: permissionId },
|
|
120
|
+
action: grant.action,
|
|
121
|
+
domain: grant.domain,
|
|
122
|
+
effect: grant.effect,
|
|
123
|
+
});
|
|
124
|
+
rows.push(policy);
|
|
125
|
+
}
|
|
126
|
+
return rows;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.AuthorizationPolicyBuilder = AuthorizationPolicyBuilder;
|
|
130
|
+
//# sourceMappingURL=policy-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-builder.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/common/policy-builder.ts"],"names":[],"mappings":";;;AAEA,2CAKqB;AAKrB,MAAa,0BAA0B;aACrB,qBAAgB,GAAG,QAAQ,CAAC;IAE5C;;;;OAIG;IACK,MAAM,CAAC,eAAe,CAAC,MAAsC;QACnE,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,IAMZ;QACC,OAAO;YACL,OAAO,EAAE,uCAA2B,CAAC,KAAK,CAAC,MAAM;YACjD,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YAC9B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1B,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI;YAChC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE;YAC5B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,E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,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACtE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,SAAS;YACX,CAAC;YAED,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,CAAC;gBAC9C,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;gBACnD,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE;gBAC5D,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;;AA7KH,gEA8KC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TContext } from '../../../../base/controllers/common/types';
|
|
2
|
+
import { TNullable } from '@venizia/ignis-helpers';
|
|
3
|
+
import { Env } from 'hono';
|
|
4
|
+
import { IAuthorizationDomainSource, IAuthorizationSpec, IAuthorizeOptions } from './types';
|
|
5
|
+
/** Read a domain value from a declarative source on the Hono context. */
|
|
6
|
+
export declare const readDeclarative: (opts: {
|
|
7
|
+
source: IAuthorizationDomainSource;
|
|
8
|
+
context: TContext<Env, string>;
|
|
9
|
+
}) => TNullable<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the request domain scope with precedence:
|
|
12
|
+
* spec.domain (method | declarative) → options.domainResolver → SYSTEM_WIDE.
|
|
13
|
+
* Returns a casbin domain string ("<type>_<id>") or the SYSTEM_WIDE sentinel.
|
|
14
|
+
*/
|
|
15
|
+
export declare const resolveRequestDomain: (opts: {
|
|
16
|
+
spec: IAuthorizationSpec;
|
|
17
|
+
context: TContext<Env, string>;
|
|
18
|
+
options: TNullable<IAuthorizeOptions>;
|
|
19
|
+
}) => Promise<string>;
|
|
20
|
+
//# sourceMappingURL=resolve-request-domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-request-domain.d.ts","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/common/resolve-request-domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE3B,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5F,yEAAyE;AACzE,eAAO,MAAM,eAAe,GAAI,MAAM;IACpC,MAAM,EAAE,0BAA0B,CAAC;IACnC,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAChC,KAAG,SAAS,CAAC,MAAM,CAoBnB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAU,MAAM;IAC/C,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC/B,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;CACvC,KAAG,OAAO,CAAC,MAAM,CA4BjB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRequestDomain = exports.readDeclarative = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/** Read a domain value from a declarative source on the Hono context. */
|
|
6
|
+
const readDeclarative = (opts) => {
|
|
7
|
+
const { source, context } = opts;
|
|
8
|
+
switch (source.from) {
|
|
9
|
+
case 'param': {
|
|
10
|
+
return context.req.param(source.key) ?? null;
|
|
11
|
+
}
|
|
12
|
+
case 'header': {
|
|
13
|
+
return context.req.header(source.key) ?? null;
|
|
14
|
+
}
|
|
15
|
+
case 'query': {
|
|
16
|
+
return context.req.query(source.key) ?? null;
|
|
17
|
+
}
|
|
18
|
+
case 'context': {
|
|
19
|
+
const value = context.get(source.key);
|
|
20
|
+
return value == null ? null : String(value);
|
|
21
|
+
}
|
|
22
|
+
default: {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.readDeclarative = readDeclarative;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the request domain scope with precedence:
|
|
30
|
+
* spec.domain (method | declarative) → options.domainResolver → SYSTEM_WIDE.
|
|
31
|
+
* Returns a casbin domain string ("<type>_<id>") or the SYSTEM_WIDE sentinel.
|
|
32
|
+
*/
|
|
33
|
+
const resolveRequestDomain = async (opts) => {
|
|
34
|
+
const { spec, context, options } = opts;
|
|
35
|
+
// (1) spec.domain as a method
|
|
36
|
+
if (typeof spec.domain === 'function') {
|
|
37
|
+
const resolved = await spec.domain({ context });
|
|
38
|
+
return resolved
|
|
39
|
+
? [resolved.type, resolved.id].join('_')
|
|
40
|
+
: constants_1.AuthorizationDomainScopes.SYSTEM_WIDE;
|
|
41
|
+
}
|
|
42
|
+
// (2) spec.domain as declarative
|
|
43
|
+
if (spec.domain) {
|
|
44
|
+
const id = (0, exports.readDeclarative)({ source: spec.domain, context });
|
|
45
|
+
return id ? [spec.domain.type, id].join('_') : constants_1.AuthorizationDomainScopes.SYSTEM_WIDE;
|
|
46
|
+
}
|
|
47
|
+
// (3) global resolver
|
|
48
|
+
const globalResolver = options?.domainResolver ?? null;
|
|
49
|
+
if (globalResolver) {
|
|
50
|
+
const resolved = await globalResolver({ context });
|
|
51
|
+
return resolved
|
|
52
|
+
? [resolved.type, resolved.id].join('_')
|
|
53
|
+
: constants_1.AuthorizationDomainScopes.SYSTEM_WIDE;
|
|
54
|
+
}
|
|
55
|
+
// (4) nothing → SYSTEM_WIDE
|
|
56
|
+
return constants_1.AuthorizationDomainScopes.SYSTEM_WIDE;
|
|
57
|
+
};
|
|
58
|
+
exports.resolveRequestDomain = resolveRequestDomain;
|
|
59
|
+
//# sourceMappingURL=resolve-request-domain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-request-domain.js","sourceRoot":"","sources":["../../../../../src/components/auth/authorize/common/resolve-request-domain.ts"],"names":[],"mappings":";;;AAGA,2CAAwD;AAGxD,yEAAyE;AAClE,MAAM,eAAe,GAAG,CAAC,IAG/B,EAAqB,EAAE;IACtB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;QAC/C,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;QAChD,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;QAC/C,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAY,CAAC,CAAC;YAC/C,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO,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