nestjs-iacry 0.0.10 → 0.2.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/CHANGELOG.md +9 -0
- package/LICENSE +0 -0
- package/README.md +2 -2
- package/dist/constants.d.ts +0 -0
- package/dist/constants.js +0 -0
- package/dist/decorators/action.d.ts +0 -0
- package/dist/decorators/action.js +1 -1
- package/dist/decorators/constants.d.ts +0 -0
- package/dist/decorators/constants.js +0 -0
- package/dist/decorators/entity.d.ts +0 -0
- package/dist/decorators/entity.js +0 -0
- package/dist/decorators/firewall.d.ts +0 -0
- package/dist/decorators/firewall.guard.d.ts +0 -0
- package/dist/decorators/firewall.guard.js +11 -14
- package/dist/decorators/firewall.js +1 -1
- package/dist/decorators/helper.d.ts +1 -1
- package/dist/decorators/helper.js +2 -2
- package/dist/decorators/principal.d.ts +0 -0
- package/dist/decorators/principal.js +1 -1
- package/dist/decorators/resource.d.ts +0 -0
- package/dist/decorators/resource.js +1 -1
- package/dist/errors/decorator.error.d.ts +0 -0
- package/dist/errors/decorator.error.js +0 -0
- package/dist/errors/iacry.error.d.ts +0 -0
- package/dist/errors/iacry.error.js +0 -0
- package/dist/errors/missing-policy-props.error.d.ts +0 -0
- package/dist/errors/missing-policy-props.error.js +0 -0
- package/dist/errors/wrong-policy-prop-format.error.d.ts +0 -0
- package/dist/errors/wrong-policy-prop-format.error.js +0 -0
- package/dist/firewall.d.ts +0 -0
- package/dist/firewall.js +14 -23
- package/dist/helpers/core.d.ts +0 -0
- package/dist/helpers/core.js +2 -2
- package/dist/iacry.module.d.ts +0 -0
- package/dist/iacry.module.js +6 -7
- package/dist/iacry.service.d.ts +0 -0
- package/dist/iacry.service.js +16 -19
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/matcher-result.d.ts +0 -0
- package/dist/interfaces/matcher-result.js +0 -0
- package/dist/interfaces/matcher.d.ts +0 -0
- package/dist/interfaces/matcher.js +0 -0
- package/dist/interfaces/module-async.options.d.ts +0 -0
- package/dist/interfaces/module-async.options.js +0 -0
- package/dist/interfaces/module-options.factory.d.ts +0 -0
- package/dist/interfaces/module-options.factory.js +0 -0
- package/dist/interfaces/module.options.d.ts +0 -0
- package/dist/interfaces/module.options.js +0 -0
- package/dist/interfaces/policy-storage.d.ts +0 -0
- package/dist/interfaces/policy-storage.js +0 -0
- package/dist/interfaces/policy.d.ts +7 -7
- package/dist/interfaces/policy.js +1 -1
- package/dist/matcher.d.ts +0 -0
- package/dist/matcher.js +0 -0
- package/dist/policy-vector.d.ts +0 -0
- package/dist/policy-vector.js +0 -0
- package/dist/policy.d.ts +0 -0
- package/dist/policy.js +0 -0
- package/dist/policy.manager.d.ts +0 -0
- package/dist/policy.manager.js +35 -48
- package/dist/storages/cache/cache.error.d.ts +0 -0
- package/dist/storages/cache/cache.error.js +0 -0
- package/dist/storages/cache/cache.interface.d.ts +0 -0
- package/dist/storages/cache/cache.interface.js +0 -0
- package/dist/storages/cache/ioredis.d.ts +0 -0
- package/dist/storages/cache/ioredis.js +11 -20
- package/dist/storages/cached.storage.d.ts +0 -0
- package/dist/storages/cached.storage.js +41 -56
- package/dist/storages/global.storage.d.ts +0 -0
- package/dist/storages/global.storage.js +18 -29
- package/dist/storages/multiple.storage.d.ts +0 -0
- package/dist/storages/multiple.storage.js +32 -45
- package/dist/storages/sequelize/sequelize.error.d.ts +0 -0
- package/dist/storages/sequelize/sequelize.error.js +0 -0
- package/dist/storages/sequelize/storage.interface.d.ts +0 -0
- package/dist/storages/sequelize/storage.interface.js +0 -0
- package/dist/storages/sequelize/storage.model.d.ts +0 -0
- package/dist/storages/sequelize/storage.model.js +75 -82
- package/dist/storages/sequelize.storage.d.ts +0 -0
- package/dist/storages/sequelize.storage.js +10 -21
- package/index.d.ts +0 -0
- package/index.js +0 -0
- package/jest.config.js +0 -0
- package/package.json +38 -38
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [0.2.0](https://github.com/AlexanderC/nestjs-iacry/compare/v0.0.12...v0.2.0) (2023-07-10)
|
|
6
|
+
|
|
7
|
+
### [0.0.12](https://github.com/AlexanderC/nestjs-iacry/compare/v0.0.10...v0.0.12) (2022-12-07)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* Dependencies issues ([1d4d56e](https://github.com/AlexanderC/nestjs-iacry/commit/1d4d56ef2e69894c955a07d7710f59dc66191a38))
|
|
13
|
+
|
|
5
14
|
### [0.0.10](https://github.com/AlexanderC/nestjs-iacry/compare/v0.0.9...v0.0.10) (2020-09-02)
|
|
6
15
|
|
|
7
16
|
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
|
|
8
|
+
An Identity and Access Control (Management) module for Nest framework (node.js) highly inspired by the <a href="https://aws.amazon.com/iam/">AWS IAM</a>.
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
@@ -266,4 +266,4 @@ npm run deploy
|
|
|
266
266
|
|
|
267
267
|
### License
|
|
268
268
|
|
|
269
|
-
MIT
|
|
269
|
+
MIT
|
package/dist/constants.d.ts
CHANGED
|
File without changes
|
package/dist/constants.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ exports.Action = exports.extractDynamicIdentifier = void 0;
|
|
|
4
4
|
const policy_1 = require("../interfaces/policy");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const helper_1 = require("./helper");
|
|
7
|
-
exports.extractDynamicIdentifier = helper_1.dynamicIdentifierExtractor(constants_1.ACTION_META_FIELD, {
|
|
7
|
+
exports.extractDynamicIdentifier = (0, helper_1.dynamicIdentifierExtractor)(constants_1.ACTION_META_FIELD, {
|
|
8
8
|
preHook(value, ctx) {
|
|
9
9
|
if (!ctx || value !== constants_1.CTRL_ACTION_PLACEHOLDER) {
|
|
10
10
|
return value;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -8,24 +8,21 @@ const iacry_service_1 = require("../iacry.service");
|
|
|
8
8
|
const action_1 = require("./action");
|
|
9
9
|
const resource_1 = require("./resource");
|
|
10
10
|
const principal_1 = require("./principal");
|
|
11
|
-
let FirewallGuard = class FirewallGuard {
|
|
11
|
+
let FirewallGuard = exports.FirewallGuard = class FirewallGuard {
|
|
12
12
|
constructor(service) {
|
|
13
13
|
this.service = service;
|
|
14
14
|
}
|
|
15
|
-
canActivate(context) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return this.service.isGranted(action, principal, resource || iacry_service_1.IACryService.ANY);
|
|
24
|
-
});
|
|
15
|
+
async canActivate(context) {
|
|
16
|
+
const action = (0, action_1.extractDynamicIdentifier)(context.getHandler(), context);
|
|
17
|
+
const principal = (0, principal_1.extractDynamicIdentifier)(context.getHandler(), context);
|
|
18
|
+
const resource = (0, resource_1.extractDynamicIdentifier)(context.getHandler(), context);
|
|
19
|
+
if (!action || !principal) {
|
|
20
|
+
throw new decorator_error_1.DecoratorError('You must decorate your controller with @IACryFirewall or at least @IACryAction and @IACryPrincipal decorators');
|
|
21
|
+
}
|
|
22
|
+
return this.service.isGranted(action, principal, resource || iacry_service_1.IACryService.ANY);
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
|
-
FirewallGuard = tslib_1.__decorate([
|
|
28
|
-
common_1.Injectable(),
|
|
25
|
+
exports.FirewallGuard = FirewallGuard = tslib_1.__decorate([
|
|
26
|
+
(0, common_1.Injectable)(),
|
|
29
27
|
tslib_1.__metadata("design:paramtypes", [iacry_service_1.IACryService])
|
|
30
28
|
], FirewallGuard);
|
|
31
|
-
exports.FirewallGuard = FirewallGuard;
|
|
@@ -6,6 +6,6 @@ const action_1 = require("./action");
|
|
|
6
6
|
const resource_1 = require("./resource");
|
|
7
7
|
const principal_1 = require("./principal");
|
|
8
8
|
function Firewall(options = {}) {
|
|
9
|
-
return common_1.applyDecorators(action_1.Action(options.action), principal_1.Principal(options.principal), ...(options.resource ? [resource_1.Resource(options.resource)] : []));
|
|
9
|
+
return (0, common_1.applyDecorators)((0, action_1.Action)(options.action), (0, principal_1.Principal)(options.principal), ...(options.resource ? [(0, resource_1.Resource)(options.resource)] : []));
|
|
10
10
|
}
|
|
11
11
|
exports.Firewall = Firewall;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExecutionContext } from '@nestjs/common';
|
|
2
2
|
export declare function processTemplate(template: string, context: object): string;
|
|
3
|
-
|
|
3
|
+
type DIEHook = (value: any, ctx?: ExecutionContext) => any;
|
|
4
4
|
export declare function dynamicIdentifierExtractor<T>(metadataField: string, hooks?: {
|
|
5
5
|
preHook?: DIEHook;
|
|
6
6
|
postHook?: DIEHook;
|
|
@@ -17,8 +17,8 @@ function processTemplate(template, context) {
|
|
|
17
17
|
throw new decorator_error_1.DecoratorError(`Unable to find ${varPath} property in Request from metadata field`);
|
|
18
18
|
}
|
|
19
19
|
let varValue = dotProp.get(context, varPath);
|
|
20
|
-
if (entity_1.isEntity(varValue)) {
|
|
21
|
-
varValue = entity_1.toPlainDynamicIdentifier(varValue);
|
|
20
|
+
if ((0, entity_1.isEntity)(varValue)) {
|
|
21
|
+
varValue = (0, entity_1.toPlainDynamicIdentifier)(varValue);
|
|
22
22
|
}
|
|
23
23
|
template = template.replace(definition, varValue.toString());
|
|
24
24
|
}
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Principal = exports.extractDynamicIdentifier = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const helper_1 = require("./helper");
|
|
6
|
-
exports.extractDynamicIdentifier = helper_1.dynamicIdentifierExtractor(constants_1.PRINCIPAL_META_FIELD);
|
|
6
|
+
exports.extractDynamicIdentifier = (0, helper_1.dynamicIdentifierExtractor)(constants_1.PRINCIPAL_META_FIELD);
|
|
7
7
|
function Principal(principal) {
|
|
8
8
|
return (target, key, descriptor) => {
|
|
9
9
|
Reflect.defineMetadata(constants_1.PRINCIPAL_META_FIELD, principal || constants_1.REQUEST_USER, descriptor.value);
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Resource = exports.extractDynamicIdentifier = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const helper_1 = require("./helper");
|
|
6
|
-
exports.extractDynamicIdentifier = helper_1.dynamicIdentifierExtractor(constants_1.RESOURCE_META_FIELD);
|
|
6
|
+
exports.extractDynamicIdentifier = (0, helper_1.dynamicIdentifierExtractor)(constants_1.RESOURCE_META_FIELD);
|
|
7
7
|
function Resource(resource) {
|
|
8
8
|
return (target, key, descriptor) => {
|
|
9
9
|
Reflect.defineMetadata(constants_1.RESOURCE_META_FIELD, resource, descriptor.value);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/firewall.d.ts
CHANGED
|
File without changes
|
package/dist/firewall.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Firewall = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const policy_1 = require("./interfaces/policy");
|
|
6
5
|
const matcher_1 = require("./matcher");
|
|
7
6
|
const global_storage_1 = require("./storages/global.storage");
|
|
@@ -16,31 +15,23 @@ class Firewall extends core_1.CoreHelper {
|
|
|
16
15
|
static create(storage, matcher) {
|
|
17
16
|
return new this(storage || new global_storage_1.GlobalStorage(), matcher || new matcher_1.Matcher());
|
|
18
17
|
}
|
|
19
|
-
isAllowed(rawResource, rawAction, rawPrincipal) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return resolution.allow.length > 0 && resolution.deny.length <= 0;
|
|
23
|
-
});
|
|
18
|
+
async isAllowed(rawResource, rawAction, rawPrincipal) {
|
|
19
|
+
const resolution = await this.resolve(rawResource, rawAction, rawPrincipal);
|
|
20
|
+
return resolution.allow.length > 0 && resolution.deny.length <= 0;
|
|
24
21
|
}
|
|
25
|
-
isAllowedAny(rawResource, rawAction, rawPrincipal) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return resolution.allow.length > 0;
|
|
29
|
-
});
|
|
22
|
+
async isAllowedAny(rawResource, rawAction, rawPrincipal) {
|
|
23
|
+
const resolution = await this.resolve(rawResource, rawAction, rawPrincipal);
|
|
24
|
+
return resolution.allow.length > 0;
|
|
30
25
|
}
|
|
31
|
-
isAllowedImplicit(rawResource, rawAction, rawPrincipal) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return resolution.deny.length <= 0;
|
|
35
|
-
});
|
|
26
|
+
async isAllowedImplicit(rawResource, rawAction, rawPrincipal) {
|
|
27
|
+
const resolution = await this.resolve(rawResource, rawAction, rawPrincipal);
|
|
28
|
+
return resolution.deny.length <= 0;
|
|
36
29
|
}
|
|
37
|
-
resolve(rawResource, rawAction, rawPrincipal) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return this.matcher.match(rawResource, rawAction, principal, policies);
|
|
43
|
-
});
|
|
30
|
+
async resolve(rawResource, rawAction, rawPrincipal) {
|
|
31
|
+
const principal = (this.normalizeDynamicIdentifier(rawPrincipal, policy_1.PRINCIPAL));
|
|
32
|
+
const rawPolicies = await this.storage.fetch(principal);
|
|
33
|
+
const policies = policy_vector_1.PolicyVector.create(...rawPolicies);
|
|
34
|
+
return this.matcher.match(rawResource, rawAction, principal, policies);
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
37
|
exports.Firewall = Firewall;
|
package/dist/helpers/core.d.ts
CHANGED
|
File without changes
|
package/dist/helpers/core.js
CHANGED
|
@@ -52,8 +52,8 @@ class CoreHelper {
|
|
|
52
52
|
return thing;
|
|
53
53
|
}
|
|
54
54
|
normalizeDynamicObject(thing, prop) {
|
|
55
|
-
return entity_1.isEntity(thing)
|
|
56
|
-
? entity_1.toDynamicIdentifier(thing)
|
|
55
|
+
return (0, entity_1.isEntity)(thing)
|
|
56
|
+
? (0, entity_1.toDynamicIdentifier)(thing)
|
|
57
57
|
: prop
|
|
58
58
|
? (this.normalizeDynamicIdentifier(thing, prop))
|
|
59
59
|
: thing;
|
package/dist/iacry.module.d.ts
CHANGED
|
File without changes
|
package/dist/iacry.module.js
CHANGED
|
@@ -6,7 +6,7 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
7
|
const iacry_service_1 = require("./iacry.service");
|
|
8
8
|
const constants_1 = require("./constants");
|
|
9
|
-
let IACryModule = IACryModule_1 = class IACryModule {
|
|
9
|
+
let IACryModule = exports.IACryModule = IACryModule_1 = class IACryModule {
|
|
10
10
|
static forRoot(options) {
|
|
11
11
|
const OptionsProvider = {
|
|
12
12
|
provide: constants_1.IACRY_OPTIONS,
|
|
@@ -49,15 +49,14 @@ let IACryModule = IACryModule_1 = class IACryModule {
|
|
|
49
49
|
return {
|
|
50
50
|
name: constants_1.IACRY_OPTIONS,
|
|
51
51
|
provide: constants_1.IACRY_OPTIONS,
|
|
52
|
-
useFactory: (optionsFactory) =>
|
|
52
|
+
useFactory: async (optionsFactory) => {
|
|
53
53
|
return optionsFactory.createOptions();
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
55
|
inject: [options.useExisting || options.useClass],
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
IACryModule = IACryModule_1 = tslib_1.__decorate([
|
|
60
|
-
common_1.Global(),
|
|
61
|
-
common_1.Module({})
|
|
59
|
+
exports.IACryModule = IACryModule = IACryModule_1 = tslib_1.__decorate([
|
|
60
|
+
(0, common_1.Global)(),
|
|
61
|
+
(0, common_1.Module)({})
|
|
62
62
|
], IACryModule);
|
|
63
|
-
exports.IACryModule = IACryModule;
|
package/dist/iacry.service.d.ts
CHANGED
|
File without changes
|
package/dist/iacry.service.js
CHANGED
|
@@ -14,26 +14,24 @@ const core_1 = require("./helpers/core");
|
|
|
14
14
|
const ioredis_1 = require("./storages/cache/ioredis");
|
|
15
15
|
const cached_storage_1 = require("./storages/cached.storage");
|
|
16
16
|
const policy_manager_1 = require("./policy.manager");
|
|
17
|
-
let IACryService = class IACryService extends policy_manager_1.PolicyManager {
|
|
17
|
+
let IACryService = exports.IACryService = class IACryService extends policy_manager_1.PolicyManager {
|
|
18
18
|
constructor(options) {
|
|
19
19
|
super(new multiple_storage_1.MultipleStorage());
|
|
20
20
|
this.options = options;
|
|
21
21
|
this.setup(options);
|
|
22
22
|
}
|
|
23
|
-
isGranted(rawAction, rawPrincipal, rawResource = core_1.CoreHelper.ANY, rule = constants_1.IS_ALLOWED) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return this.firewall[rule](resource, rawAction, principal);
|
|
36
|
-
});
|
|
23
|
+
async isGranted(rawAction, rawPrincipal, rawResource = core_1.CoreHelper.ANY, rule = constants_1.IS_ALLOWED) {
|
|
24
|
+
switch (rule) {
|
|
25
|
+
case constants_1.IS_ALLOWED:
|
|
26
|
+
case constants_1.IS_ALLOWED_ANY:
|
|
27
|
+
case constants_1.IS_ALLOWED_IMPLICIT:
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
throw new iacry_error_1.BaseError(`Unrecognized firewall rule: ${rule}`);
|
|
31
|
+
}
|
|
32
|
+
const resource = (this.normalizeDynamicObject(rawResource));
|
|
33
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal));
|
|
34
|
+
return this.firewall[rule](resource, rawAction, principal);
|
|
37
35
|
}
|
|
38
36
|
setup(options) {
|
|
39
37
|
if (options.storage) {
|
|
@@ -74,9 +72,8 @@ let IACryService = class IACryService extends policy_manager_1.PolicyManager {
|
|
|
74
72
|
this.firewall = firewall_1.Firewall.create(this.storage, new matcher_1.Matcher(options.strict));
|
|
75
73
|
}
|
|
76
74
|
};
|
|
77
|
-
IACryService = tslib_1.__decorate([
|
|
78
|
-
common_1.Injectable(),
|
|
79
|
-
tslib_1.__param(0, common_1.Inject(constants_1.IACRY_OPTIONS)),
|
|
75
|
+
exports.IACryService = IACryService = tslib_1.__decorate([
|
|
76
|
+
(0, common_1.Injectable)(),
|
|
77
|
+
tslib_1.__param(0, (0, common_1.Inject)(constants_1.IACRY_OPTIONS)),
|
|
80
78
|
tslib_1.__metadata("design:paramtypes", [Object])
|
|
81
79
|
], IACryService);
|
|
82
|
-
exports.IACryService = IACryService;
|
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WrongPolicyPropFormat = exports.MissingPolicyProps = exports.IACryDecoratorError = exports.IACryError = exports.Firewall = exports.Matcher = exports.PolicyVector = exports.Policy = exports.IACryFirewallGuard = exports.IACryFirewall = exports.IACryPrincipal = exports.IACryResource = exports.IACryAction = exports.IACryEntity = exports.PoliciesStorageSequelizeModel = exports.IACryService = exports.Effect = exports.REQUEST_USER = exports.IS_ALLOWED_IMPLICIT = exports.IS_ALLOWED_ANY = exports.IS_ALLOWED = exports.IOREDIS_CACHE = exports.SEQUELIZE_STORAGE = exports.IACryModule = void 0;
|
|
3
4
|
var iacry_module_1 = require("./iacry.module");
|
|
4
5
|
Object.defineProperty(exports, "IACryModule", { enumerable: true, get: function () { return iacry_module_1.IACryModule; } });
|
|
5
6
|
var constants_1 = require("./constants");
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -17,28 +17,28 @@ export declare enum Effect {
|
|
|
17
17
|
ALLOW = "Allow",
|
|
18
18
|
DENY = "Deny"
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type ANY = '*';
|
|
21
21
|
export interface ActionObject {
|
|
22
22
|
readonly service: string | ANY;
|
|
23
23
|
readonly action: string | ANY;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
25
|
+
export type Action = string | ActionObject;
|
|
26
26
|
export interface ResourceObject {
|
|
27
27
|
readonly entity: string | ANY;
|
|
28
28
|
readonly id: number | string | ANY;
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type Resource = string | ResourceObject;
|
|
31
31
|
export interface PrincipalObject {
|
|
32
32
|
readonly entity: string | ANY;
|
|
33
33
|
readonly id: number | string | ANY;
|
|
34
34
|
}
|
|
35
|
-
export
|
|
36
|
-
export
|
|
35
|
+
export type Principal = string | PrincipalObject;
|
|
36
|
+
export type DynamicIdentifierItem<T> = {
|
|
37
37
|
value: T;
|
|
38
38
|
parse(thing: T): Array<string | ANY>;
|
|
39
39
|
};
|
|
40
|
-
export
|
|
41
|
-
export
|
|
40
|
+
export type DynamicIdentifier<T> = T | DynamicIdentifierItem<T>;
|
|
41
|
+
export type DynamicIdentifierVector<T> = Array<DynamicIdentifier<T>>;
|
|
42
42
|
export interface PolicyInterface {
|
|
43
43
|
Sid?: string;
|
|
44
44
|
Effect: Effect;
|
package/dist/matcher.d.ts
CHANGED
|
File without changes
|
package/dist/matcher.js
CHANGED
|
File without changes
|
package/dist/policy-vector.d.ts
CHANGED
|
File without changes
|
package/dist/policy-vector.js
CHANGED
|
File without changes
|
package/dist/policy.d.ts
CHANGED
|
File without changes
|
package/dist/policy.js
CHANGED
|
File without changes
|
package/dist/policy.manager.d.ts
CHANGED
|
File without changes
|
package/dist/policy.manager.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PolicyManager = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const core_1 = require("./helpers/core");
|
|
6
5
|
const policy_1 = require("./interfaces/policy");
|
|
7
6
|
class PolicyManager extends core_1.CoreHelper {
|
|
@@ -13,53 +12,41 @@ class PolicyManager extends core_1.CoreHelper {
|
|
|
13
12
|
this.storage = storage;
|
|
14
13
|
return this;
|
|
15
14
|
}
|
|
16
|
-
attach(rawPrincipal, rawPolicies) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const resource = (this.normalizeDynamicObject(rawResource));
|
|
53
|
-
const principal = (this.normalizeDynamicObject(rawPrincipal));
|
|
54
|
-
const policy = {
|
|
55
|
-
[policy_1.SID]: sid,
|
|
56
|
-
[policy_1.EFFECT]: effect,
|
|
57
|
-
[policy_1.ACTION]: rawAction,
|
|
58
|
-
[policy_1.RESOURCE]: resource,
|
|
59
|
-
[policy_1.PRINCIPAL]: principal,
|
|
60
|
-
};
|
|
61
|
-
return this.attach(rawPrincipal, [policy]);
|
|
62
|
-
});
|
|
15
|
+
async attach(rawPrincipal, rawPolicies) {
|
|
16
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal, policy_1.PRINCIPAL));
|
|
17
|
+
return this.storage.add(principal, rawPolicies);
|
|
18
|
+
}
|
|
19
|
+
async reset(rawPrincipal, rawPolicies) {
|
|
20
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal, policy_1.PRINCIPAL));
|
|
21
|
+
return rawPolicies
|
|
22
|
+
? this.storage.save(principal, rawPolicies)
|
|
23
|
+
: this.storage.purge(principal);
|
|
24
|
+
}
|
|
25
|
+
async retrieve(rawPrincipal) {
|
|
26
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal, policy_1.PRINCIPAL));
|
|
27
|
+
const rawPolicies = await this.storage.fetch(principal);
|
|
28
|
+
return rawPolicies.map((rawPolicy) => typeof rawPolicy === 'string' ? core_1.CoreHelper.decode(rawPolicy) : rawPolicy);
|
|
29
|
+
}
|
|
30
|
+
async retrieveBySid(sid, rawPrincipal) {
|
|
31
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal, policy_1.PRINCIPAL));
|
|
32
|
+
const rawPolicies = await this.storage.fetchBySid(sid, principal);
|
|
33
|
+
return rawPolicies.map((rawPolicy) => typeof rawPolicy === 'string' ? core_1.CoreHelper.decode(rawPolicy) : rawPolicy);
|
|
34
|
+
}
|
|
35
|
+
async upsertBySid(sid, rawPrincipal, rawPolicies) {
|
|
36
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal, policy_1.PRINCIPAL));
|
|
37
|
+
return this.storage.saveBySid(sid, principal, rawPolicies);
|
|
38
|
+
}
|
|
39
|
+
async grant(rawAction, rawPrincipal, rawResource = core_1.CoreHelper.ANY, effect = policy_1.Effect.ALLOW, sid) {
|
|
40
|
+
const resource = (this.normalizeDynamicObject(rawResource));
|
|
41
|
+
const principal = (this.normalizeDynamicObject(rawPrincipal));
|
|
42
|
+
const policy = {
|
|
43
|
+
[policy_1.SID]: sid,
|
|
44
|
+
[policy_1.EFFECT]: effect,
|
|
45
|
+
[policy_1.ACTION]: rawAction,
|
|
46
|
+
[policy_1.RESOURCE]: resource,
|
|
47
|
+
[policy_1.PRINCIPAL]: principal,
|
|
48
|
+
};
|
|
49
|
+
return this.attach(rawPrincipal, [policy]);
|
|
63
50
|
}
|
|
64
51
|
}
|
|
65
52
|
exports.PolicyManager = PolicyManager;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IoRedis = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
class IoRedis {
|
|
6
5
|
constructor(client) {
|
|
7
6
|
this.client = client;
|
|
8
7
|
this.SUCCESS = 'OK';
|
|
9
8
|
this.EXPIRE = 'EX';
|
|
10
9
|
}
|
|
11
|
-
set(key, value, expire) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return ((yield this.client.set(key, value, this.EXPIRE, expire)) === this.SUCCESS);
|
|
17
|
-
});
|
|
10
|
+
async set(key, value, expire) {
|
|
11
|
+
if (!expire) {
|
|
12
|
+
return (await this.client.set(key, value)) === this.SUCCESS;
|
|
13
|
+
}
|
|
14
|
+
return ((await this.client.set(key, value, this.EXPIRE, expire)) === this.SUCCESS);
|
|
18
15
|
}
|
|
19
|
-
has(key) {
|
|
20
|
-
return
|
|
21
|
-
return (yield this.client.exists(key)) === 1;
|
|
22
|
-
});
|
|
16
|
+
async has(key) {
|
|
17
|
+
return (await this.client.exists(key)) === 1;
|
|
23
18
|
}
|
|
24
|
-
get(key) {
|
|
25
|
-
return
|
|
26
|
-
return this.client.get(key);
|
|
27
|
-
});
|
|
19
|
+
async get(key) {
|
|
20
|
+
return this.client.get(key);
|
|
28
21
|
}
|
|
29
|
-
remove(key) {
|
|
30
|
-
return
|
|
31
|
-
return (yield this.client.del(key)) === 1;
|
|
32
|
-
});
|
|
22
|
+
async remove(key) {
|
|
23
|
+
return (await this.client.del(key)) === 1;
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
26
|
exports.IoRedis = IoRedis;
|
|
File without changes
|