@lightdash/common 0.1930.2 → 0.1931.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/authorization/parseScopes.d.ts +8 -0
- package/dist/cjs/authorization/parseScopes.d.ts.map +1 -0
- package/dist/cjs/authorization/parseScopes.js +27 -0
- package/dist/cjs/authorization/parseScopes.js.map +1 -0
- package/dist/cjs/authorization/parseScopes.test.d.ts +2 -0
- package/dist/cjs/authorization/parseScopes.test.d.ts.map +1 -0
- package/dist/cjs/authorization/parseScopes.test.js +109 -0
- package/dist/cjs/authorization/parseScopes.test.js.map +1 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.d.ts +23 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.d.ts.map +1 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.js +58 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.js.map +1 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.test.d.ts +2 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.test.d.ts.map +1 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.test.js +955 -0
- package/dist/cjs/authorization/scopeAbilityBuilder.test.js.map +1 -0
- package/dist/cjs/authorization/scopes.d.ts +8 -0
- package/dist/cjs/authorization/scopes.d.ts.map +1 -0
- package/dist/cjs/authorization/scopes.js +633 -0
- package/dist/cjs/authorization/scopes.js.map +1 -0
- package/dist/cjs/types/scopes.d.ts +30 -3
- package/dist/cjs/types/scopes.d.ts.map +1 -1
- package/dist/cjs/types/scopes.js.map +1 -1
- package/dist/esm/authorization/parseScopes.d.ts +8 -0
- package/dist/esm/authorization/parseScopes.d.ts.map +1 -0
- package/dist/esm/authorization/parseScopes.js +22 -0
- package/dist/esm/authorization/parseScopes.js.map +1 -0
- package/dist/esm/authorization/parseScopes.test.d.ts +2 -0
- package/dist/esm/authorization/parseScopes.test.d.ts.map +1 -0
- package/dist/esm/authorization/parseScopes.test.js +107 -0
- package/dist/esm/authorization/parseScopes.test.js.map +1 -0
- package/dist/esm/authorization/scopeAbilityBuilder.d.ts +23 -0
- package/dist/esm/authorization/scopeAbilityBuilder.d.ts.map +1 -0
- package/dist/esm/authorization/scopeAbilityBuilder.js +54 -0
- package/dist/esm/authorization/scopeAbilityBuilder.js.map +1 -0
- package/dist/esm/authorization/scopeAbilityBuilder.test.d.ts +2 -0
- package/dist/esm/authorization/scopeAbilityBuilder.test.d.ts.map +1 -0
- package/dist/esm/authorization/scopeAbilityBuilder.test.js +953 -0
- package/dist/esm/authorization/scopeAbilityBuilder.test.js.map +1 -0
- package/dist/esm/authorization/scopes.d.ts +8 -0
- package/dist/esm/authorization/scopes.d.ts.map +1 -0
- package/dist/esm/authorization/scopes.js +628 -0
- package/dist/esm/authorization/scopes.js.map +1 -0
- package/dist/esm/types/scopes.d.ts +30 -3
- package/dist/esm/types/scopes.d.ts.map +1 -1
- package/dist/esm/types/scopes.js.map +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/authorization/parseScopes.d.ts +8 -0
- package/dist/types/authorization/parseScopes.d.ts.map +1 -0
- package/dist/types/authorization/parseScopes.test.d.ts +2 -0
- package/dist/types/authorization/parseScopes.test.d.ts.map +1 -0
- package/dist/types/authorization/scopeAbilityBuilder.d.ts +23 -0
- package/dist/types/authorization/scopeAbilityBuilder.d.ts.map +1 -0
- package/dist/types/authorization/scopeAbilityBuilder.test.d.ts +2 -0
- package/dist/types/authorization/scopeAbilityBuilder.test.d.ts.map +1 -0
- package/dist/types/authorization/scopes.d.ts +8 -0
- package/dist/types/authorization/scopes.d.ts.map +1 -0
- package/dist/types/types/scopes.d.ts +30 -3
- package/dist/types/types/scopes.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/authorization/scopes/index.d.ts +0 -5
- package/dist/cjs/authorization/scopes/index.d.ts.map +0 -1
- package/dist/cjs/authorization/scopes/index.js +0 -372
- package/dist/cjs/authorization/scopes/index.js.map +0 -1
- package/dist/esm/authorization/scopes/index.d.ts +0 -5
- package/dist/esm/authorization/scopes/index.d.ts.map +0 -1
- package/dist/esm/authorization/scopes/index.js +0 -368
- package/dist/esm/authorization/scopes/index.js.map +0 -1
- package/dist/types/authorization/scopes/index.d.ts +0 -5
- package/dist/types/authorization/scopes/index.d.ts.map +0 -1
@@ -0,0 +1,8 @@
|
|
1
|
+
import { type ScopeName } from '../types/scopes';
|
2
|
+
import { type AbilityAction, type CaslSubjectNames } from './types';
|
3
|
+
export declare const parseScope: (scope: string) => [AbilityAction, CaslSubjectNames];
|
4
|
+
export declare const parseScopes: ({ scopes, isEnterprise, }: {
|
5
|
+
scopes: string[];
|
6
|
+
isEnterprise: boolean;
|
7
|
+
}) => Set<ScopeName>;
|
8
|
+
//# sourceMappingURL=parseScopes.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseScopes.d.ts","sourceRoot":"","sources":["../../../src/authorization/parseScopes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpE,eAAO,MAAM,UAAU,UACZ,MAAM,KACd,CAAC,aAAa,EAAE,gBAAgB,CAKlC,CAAC;AAEF,eAAO,MAAM,WAAW,8BAGrB;IACC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;CACzB,KAAG,GAAG,CAAC,SAAS,CAiBhB,CAAC"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parseScopes = exports.parseScope = void 0;
|
4
|
+
const lodash_1 = require("lodash");
|
5
|
+
const errors_1 = require("../types/errors");
|
6
|
+
const scopes_1 = require("./scopes");
|
7
|
+
const parseScope = (scope) => {
|
8
|
+
const [action, subjectPart] = scope.split(':');
|
9
|
+
const subject = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(subjectPart));
|
10
|
+
return [action, subject];
|
11
|
+
};
|
12
|
+
exports.parseScope = parseScope;
|
13
|
+
const parseScopes = ({ scopes, isEnterprise, }) => {
|
14
|
+
const scopeMap = (0, scopes_1.getAllScopeMap)({ isEnterprise });
|
15
|
+
const filtered = scopes
|
16
|
+
.map((scope) => (0, exports.parseScope)(scope).join(':'))
|
17
|
+
.filter((scope) => {
|
18
|
+
const foundScope = scopeMap[scope];
|
19
|
+
if (!foundScope) {
|
20
|
+
throw new errors_1.ParameterError(`Invalid scope: ${scope}. Please check the scope name and try again.`);
|
21
|
+
}
|
22
|
+
return true;
|
23
|
+
});
|
24
|
+
return new Set(filtered);
|
25
|
+
};
|
26
|
+
exports.parseScopes = parseScopes;
|
27
|
+
//# sourceMappingURL=parseScopes.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseScopes.js","sourceRoot":"","sources":["../../../src/authorization/parseScopes.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAC/C,4CAAiD;AAEjD,qCAA0C;AAGnC,MAAM,UAAU,GAAG,CACtB,KAAa,EACoB,EAAE;IACnC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAA,mBAAU,EAAC,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAC,CAAC;IAEnD,OAAO,CAAC,MAAuB,EAAE,OAA2B,CAAC,CAAC;AAClE,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAEK,MAAM,WAAW,GAAG,CAAC,EACxB,MAAM,EACN,YAAY,GAIf,EAAkB,EAAE;IACjB,MAAM,QAAQ,GAAG,IAAA,uBAAc,EAAC,EAAE,YAAY,EAAE,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,MAAM;SAClB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAc,CAAC;SACxD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACd,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,uBAAc,CACpB,kBAAkB,KAAK,8CAA8C,CACxE,CAAC;QACN,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEP,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC,CAAC;AAvBW,QAAA,WAAW,eAuBtB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseScopes.test.d.ts","sourceRoot":"","sources":["../../../src/authorization/parseScopes.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const errors_1 = require("../types/errors");
|
4
|
+
const parseScopes_1 = require("./parseScopes");
|
5
|
+
describe('parseScopes', () => {
|
6
|
+
describe('with valid scopes', () => {
|
7
|
+
it('should return a Set of valid scope names for non-enterprise', () => {
|
8
|
+
const result = (0, parseScopes_1.parseScopes)({
|
9
|
+
scopes: ['view:dashboard', 'manage:dashboard'],
|
10
|
+
isEnterprise: false,
|
11
|
+
});
|
12
|
+
expect(result).toBeInstanceOf(Set);
|
13
|
+
expect(result.size).toBe(2);
|
14
|
+
expect(result.has('view:Dashboard')).toBe(true);
|
15
|
+
expect(result.has('manage:Dashboard')).toBe(true);
|
16
|
+
});
|
17
|
+
it('should return a Set of valid scope names for enterprise', () => {
|
18
|
+
const result = (0, parseScopes_1.parseScopes)({
|
19
|
+
scopes: ['view:ai_agent', 'manage:ai_agent'],
|
20
|
+
isEnterprise: true,
|
21
|
+
});
|
22
|
+
expect(result).toBeInstanceOf(Set);
|
23
|
+
expect(result.size).toBe(2);
|
24
|
+
expect(result.has('view:AiAgent')).toBe(true);
|
25
|
+
expect(result.has('manage:AiAgent')).toBe(true);
|
26
|
+
});
|
27
|
+
it('should handle mixed case scope names correctly', () => {
|
28
|
+
const result = (0, parseScopes_1.parseScopes)({
|
29
|
+
scopes: [
|
30
|
+
'export:dashboard_csv',
|
31
|
+
'manage:personal_access_token',
|
32
|
+
],
|
33
|
+
isEnterprise: true,
|
34
|
+
});
|
35
|
+
expect(result.size).toBe(2);
|
36
|
+
expect(result.has('export:DashboardCsv')).toBe(true);
|
37
|
+
expect(result.has('manage:PersonalAccessToken')).toBe(true);
|
38
|
+
});
|
39
|
+
it('should handle single scope correctly', () => {
|
40
|
+
const result = (0, parseScopes_1.parseScopes)({
|
41
|
+
scopes: ['view:project'],
|
42
|
+
isEnterprise: false,
|
43
|
+
});
|
44
|
+
expect(result.size).toBe(1);
|
45
|
+
expect(result.has('view:Project')).toBe(true);
|
46
|
+
});
|
47
|
+
it('should handle empty scopes array', () => {
|
48
|
+
const result = (0, parseScopes_1.parseScopes)({
|
49
|
+
scopes: [],
|
50
|
+
isEnterprise: false,
|
51
|
+
});
|
52
|
+
expect(result).toBeInstanceOf(Set);
|
53
|
+
expect(result.size).toBe(0);
|
54
|
+
});
|
55
|
+
});
|
56
|
+
describe('with invalid scopes', () => {
|
57
|
+
it('should throw ParameterError for invalid scope name', () => {
|
58
|
+
expect(() => (0, parseScopes_1.parseScopes)({
|
59
|
+
scopes: ['view:dashboard', 'invalid:scope'],
|
60
|
+
isEnterprise: false,
|
61
|
+
})).toThrow(errors_1.ParameterError);
|
62
|
+
expect(() => (0, parseScopes_1.parseScopes)({
|
63
|
+
scopes: ['view:dashboard', 'invalid:scope'],
|
64
|
+
isEnterprise: false,
|
65
|
+
})).toThrow('Invalid scope: invalid:Scope. Please check the scope name and try again.');
|
66
|
+
});
|
67
|
+
it('should throw ParameterError for enterprise scope when not enterprise', () => {
|
68
|
+
expect(() => (0, parseScopes_1.parseScopes)({
|
69
|
+
scopes: ['view:dashboard', 'view:ai_agent'],
|
70
|
+
isEnterprise: false,
|
71
|
+
})).toThrow(errors_1.ParameterError);
|
72
|
+
expect(() => (0, parseScopes_1.parseScopes)({
|
73
|
+
scopes: ['view:dashboard', 'view:ai_agent'],
|
74
|
+
isEnterprise: false,
|
75
|
+
})).toThrow('Invalid scope: view:AiAgent. Please check the scope name and try again.');
|
76
|
+
});
|
77
|
+
});
|
78
|
+
describe('scope parsing logic', () => {
|
79
|
+
it('should transform snake_case to PascalCase correctly', () => {
|
80
|
+
const result = (0, parseScopes_1.parseScopes)({
|
81
|
+
scopes: [
|
82
|
+
'export:dashboard_csv',
|
83
|
+
'manage:personal_access_token',
|
84
|
+
'view:semantic_viewer',
|
85
|
+
],
|
86
|
+
isEnterprise: true,
|
87
|
+
});
|
88
|
+
expect(result.has('export:DashboardCsv')).toBe(true);
|
89
|
+
expect(result.has('manage:PersonalAccessToken')).toBe(true);
|
90
|
+
expect(result.has('view:SemanticViewer')).toBe(true);
|
91
|
+
});
|
92
|
+
it('should handle camelCase input correctly', () => {
|
93
|
+
const result = (0, parseScopes_1.parseScopes)({
|
94
|
+
scopes: ['view:dashboard', 'manage:savedChart'],
|
95
|
+
isEnterprise: false,
|
96
|
+
});
|
97
|
+
expect(result.has('view:Dashboard')).toBe(true);
|
98
|
+
expect(result.has('manage:SavedChart')).toBe(true);
|
99
|
+
});
|
100
|
+
it('should handle mixed case input correctly', () => {
|
101
|
+
const result = (0, parseScopes_1.parseScopes)({
|
102
|
+
scopes: ['view:underlying_data'],
|
103
|
+
isEnterprise: false,
|
104
|
+
});
|
105
|
+
expect(result.has('view:UnderlyingData')).toBe(true);
|
106
|
+
});
|
107
|
+
});
|
108
|
+
});
|
109
|
+
//# sourceMappingURL=parseScopes.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseScopes.test.js","sourceRoot":"","sources":["../../../src/authorization/parseScopes.test.ts"],"names":[],"mappings":";;AAAA,4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AI,CAAC,IAAI,CAAC,CAAC;YACrD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5D,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YAC/C,MAAM,MAAM,GAAG,IAAA,yBAAW,EAAC;gBACvB,MAAM,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;gBAC/C,YAAY,EAAE,KAAK;aACtB,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAChD,MAAM,MAAM,GAAG,IAAA,yBAAW,EAAC;gBACvB,MAAM,EAAE,CAAC,sBAAsB,CAAC;gBAChC,YAAY,EAAE,KAAK;aACtB,CAAC,CAAC;YAEH,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { type MemberAbility } from './types';
|
2
|
+
type BuilderOptions = {
|
3
|
+
organizationUuid: string;
|
4
|
+
projectUuid: string;
|
5
|
+
userUuid?: string;
|
6
|
+
scopes: string[];
|
7
|
+
isEnterprise: boolean;
|
8
|
+
organizationRole: string;
|
9
|
+
permissionsConfig?: {
|
10
|
+
pat: {
|
11
|
+
enabled: boolean;
|
12
|
+
allowedOrgRoles: string[];
|
13
|
+
};
|
14
|
+
};
|
15
|
+
};
|
16
|
+
/**
|
17
|
+
* Build a complete CASL ability from scope names and context
|
18
|
+
* @param context - Context containing organization, project, user, and space access information
|
19
|
+
* @returns CASL Ability with applied permissions
|
20
|
+
*/
|
21
|
+
export declare const buildAbilityFromScopes: (context: BuilderOptions) => MemberAbility;
|
22
|
+
export {};
|
23
|
+
//# sourceMappingURL=scopeAbilityBuilder.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"scopeAbilityBuilder.d.ts","sourceRoot":"","sources":["../../../src/authorization/scopeAbilityBuilder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAoD7C,KAAK,cAAc,GAAG;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE;QAChB,GAAG,EAAE;YACD,OAAO,EAAE,OAAO,CAAC;YACjB,eAAe,EAAE,MAAM,EAAE,CAAC;SAC7B,CAAC;KACL,CAAC;CACL,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,YACtB,cAAc,KACxB,aAcF,CAAC"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.buildAbilityFromScopes = void 0;
|
4
|
+
const ability_1 = require("@casl/ability");
|
5
|
+
const parseScopes_1 = require("./parseScopes");
|
6
|
+
const scopes_1 = require("./scopes");
|
7
|
+
const handlePatConfigApplication = (context, builder) => {
|
8
|
+
const { pat } = context?.permissionsConfig || {};
|
9
|
+
const hasPatRule = builder.rules.find((rule) => rule.action === 'manage' && rule.subject === 'PersonalAccessToken');
|
10
|
+
if (!hasPatRule &&
|
11
|
+
pat?.enabled &&
|
12
|
+
pat?.allowedOrgRoles?.includes(context.organizationRole)) {
|
13
|
+
builder.can('manage', 'PersonalAccessToken');
|
14
|
+
}
|
15
|
+
};
|
16
|
+
/**
|
17
|
+
* Apply scope-based abilities to a CASL ability builder
|
18
|
+
* @param scopeNames - Array of scope names to apply
|
19
|
+
* @param context - Context containing organization, project, user, and space access information
|
20
|
+
* @param builder - CASL ability builder to add permissions to
|
21
|
+
*/
|
22
|
+
const applyScopeAbilities = (context, builder) => {
|
23
|
+
const scopeMap = (0, scopes_1.getAllScopeMap)({ isEnterprise: context.isEnterprise });
|
24
|
+
context.scopes.forEach((scopeName) => {
|
25
|
+
const scope = scopeMap[scopeName];
|
26
|
+
if (!scope)
|
27
|
+
return;
|
28
|
+
const [action, subject] = (0, parseScopes_1.parseScope)(scopeName);
|
29
|
+
const conditionsList = scope.getConditions
|
30
|
+
? scope.getConditions(context)
|
31
|
+
: [];
|
32
|
+
// Apply each condition set
|
33
|
+
conditionsList.forEach((conditions) => {
|
34
|
+
builder.can(action, subject, conditions);
|
35
|
+
});
|
36
|
+
});
|
37
|
+
handlePatConfigApplication(context, builder);
|
38
|
+
};
|
39
|
+
/**
|
40
|
+
* Build a complete CASL ability from scope names and context
|
41
|
+
* @param context - Context containing organization, project, user, and space access information
|
42
|
+
* @returns CASL Ability with applied permissions
|
43
|
+
*/
|
44
|
+
const buildAbilityFromScopes = (context) => {
|
45
|
+
const builder = new ability_1.AbilityBuilder(ability_1.Ability);
|
46
|
+
const scopes = (0, parseScopes_1.parseScopes)({
|
47
|
+
scopes: context.scopes,
|
48
|
+
isEnterprise: context.isEnterprise,
|
49
|
+
});
|
50
|
+
const parsedContext = {
|
51
|
+
...context,
|
52
|
+
scopes,
|
53
|
+
};
|
54
|
+
applyScopeAbilities(parsedContext, builder);
|
55
|
+
return builder.build();
|
56
|
+
};
|
57
|
+
exports.buildAbilityFromScopes = buildAbilityFromScopes;
|
58
|
+
//# sourceMappingURL=scopeAbilityBuilder.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"scopeAbilityBuilder.js","sourceRoot":"","sources":["../../../src/authorization/scopeAbilityBuilder.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AAExD,+CAAwD;AACxD,qCAA0C;AAG1C,MAAM,0BAA0B,GAAG,CAC/B,OAAqB,EACrB,OAAsC,EACxC,EAAE;IACA,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,iBAAiB,IAAI,EAAE,CAAC;IACjD,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CACjC,CAAC,IAAI,EAAE,EAAE,CACL,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,qBAAqB,CACzE,CAAC;IAEF,IACI,CAAC,UAAU;QACX,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,eAAe,EAAE,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAC1D,CAAC;QACC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IACjD,CAAC;AACL,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,CACxB,OAAqB,EACrB,OAAsC,EAClC,EAAE;IACN,MAAM,QAAQ,GAAG,IAAA,uBAAc,EAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAExE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAA,wBAAU,EAAC,SAAS,CAAC,CAAC;QAChD,MAAM,cA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