@midwayjs/casbin 3.5.3

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 ADDED
@@ -0,0 +1,12 @@
1
+ # midwayjs casbin module
2
+
3
+ [![Package Quality](http://npm.packagequality.com/shield/midway-core.svg)](http://packagequality.com/#?package=midway-core)
4
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
+
6
+ this is a sub package for midway.
7
+
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
+
10
+ ## License
11
+
12
+ [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -0,0 +1,30 @@
1
+ import { FilteredAdapter, Model } from 'casbin';
2
+ interface Line {
3
+ ptype: string;
4
+ v0: string;
5
+ v1: string;
6
+ v2: string;
7
+ v3: string;
8
+ v4: string;
9
+ v5: string;
10
+ }
11
+ export declare abstract class BaseAdapter<AdapterLine extends Line> implements FilteredAdapter {
12
+ private filtered;
13
+ private policies;
14
+ isFiltered(): boolean;
15
+ loadPolicy(model: Model): Promise<void>;
16
+ savePolicy(model: Model): Promise<boolean>;
17
+ addPolicy(sec: string, ptype: string, rule: string[]): Promise<void>;
18
+ removePolicy(sec: string, ptype: string, rule: string[]): Promise<void>;
19
+ loadFilteredPolicy(model: Model, filter: any): Promise<void>;
20
+ removeFilteredPolicy(sec: string, ptype: string, fieldIndex: number, ...fieldValues: string[]): Promise<void>;
21
+ private loadPolicyLine;
22
+ private savePolicyLine;
23
+ protected abstract getAdapterLine(): new () => AdapterLine;
24
+ protected abstract loadPolicyByAdapter(): Promise<AdapterLine[]>;
25
+ protected abstract loadPolicyWithFilterByAdapter(filter: any): Promise<AdapterLine[]>;
26
+ protected abstract savePolicyByAdapter(policies: AdapterLine[]): Promise<void>;
27
+ protected abstract removePolicyByAdapter(removePolicy: AdapterLine, newestPolicies?: AdapterLine[]): Promise<void>;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAdapter = void 0;
4
+ const casbin_1 = require("casbin");
5
+ class BaseAdapter {
6
+ constructor() {
7
+ this.filtered = false;
8
+ }
9
+ isFiltered() {
10
+ return this.filtered;
11
+ }
12
+ async loadPolicy(model) {
13
+ const policies = await this.loadPolicyByAdapter();
14
+ this.policies = policies;
15
+ for (const line of policies) {
16
+ this.loadPolicyLine(line, model);
17
+ }
18
+ }
19
+ async savePolicy(model) {
20
+ const policyRuleAST = model.model.get('p');
21
+ const groupingPolicyAST = model.model.get('g');
22
+ const policies = [];
23
+ for (const astMap of [policyRuleAST, groupingPolicyAST]) {
24
+ for (const [ptype, ast] of astMap) {
25
+ for (const rule of ast.policy) {
26
+ const line = this.savePolicyLine(ptype, rule);
27
+ policies.push(line);
28
+ }
29
+ }
30
+ }
31
+ await this.savePolicyByAdapter(policies);
32
+ return true;
33
+ }
34
+ async addPolicy(sec, ptype, rule) {
35
+ const line = this.savePolicyLine(ptype, rule);
36
+ this.policies.push(line);
37
+ await this.savePolicyByAdapter(this.policies);
38
+ }
39
+ async removePolicy(sec, ptype, rule) {
40
+ const filteredPolicies = this.policies.filter(policy => {
41
+ let flag = true;
42
+ flag && (flag = ptype === policy.ptype);
43
+ if (rule.length > 0) {
44
+ flag && (flag = rule[0] === policy.v0);
45
+ }
46
+ if (rule.length > 1) {
47
+ flag && (flag = rule[1] === policy.v1);
48
+ }
49
+ if (rule.length > 2) {
50
+ flag && (flag = rule[2] === policy.v2);
51
+ }
52
+ if (rule.length > 3) {
53
+ flag && (flag = rule[3] === policy.v3);
54
+ }
55
+ if (rule.length > 4) {
56
+ flag && (flag = rule[4] === policy.v4);
57
+ }
58
+ if (rule.length > 5) {
59
+ flag && (flag = rule[5] === policy.v5);
60
+ }
61
+ return !flag;
62
+ });
63
+ this.policies = filteredPolicies;
64
+ const line = this.savePolicyLine(ptype, rule);
65
+ await this.removePolicyByAdapter(line, filteredPolicies);
66
+ }
67
+ async loadFilteredPolicy(model, filter) {
68
+ const filteredPolicies = await this.loadPolicyWithFilterByAdapter(filter);
69
+ this.policies = filteredPolicies;
70
+ filteredPolicies.forEach((policy) => {
71
+ this.loadPolicyLine(policy, model);
72
+ });
73
+ this.filtered = true;
74
+ }
75
+ async removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues) {
76
+ const rule = new Array(fieldIndex).fill('');
77
+ rule.push(...fieldValues);
78
+ const filteredPolicies = this.policies.filter(policy => {
79
+ let flag = true;
80
+ flag && (flag = ptype === policy.ptype);
81
+ if (rule.length > 0 && rule[0]) {
82
+ flag && (flag = rule[0] === policy.v0);
83
+ }
84
+ if (rule.length > 1 && rule[1]) {
85
+ flag && (flag = rule[1] === policy.v1);
86
+ }
87
+ if (rule.length > 2 && rule[2]) {
88
+ flag && (flag = rule[2] === policy.v2);
89
+ }
90
+ if (rule.length > 3 && rule[3]) {
91
+ flag && (flag = rule[3] === policy.v3);
92
+ }
93
+ if (rule.length > 4 && rule[4]) {
94
+ flag && (flag = rule[4] === policy.v4);
95
+ }
96
+ if (rule.length > 5 && rule[5]) {
97
+ flag && (flag = rule[5] === policy.v5);
98
+ }
99
+ return !flag;
100
+ });
101
+ this.policies = filteredPolicies;
102
+ const line = new (this.getAdapterLine())();
103
+ line.ptype = ptype;
104
+ if (fieldIndex <= 0 && 0 < fieldIndex + fieldValues.length) {
105
+ line.v0 = fieldValues[0 - fieldIndex];
106
+ }
107
+ if (fieldIndex <= 1 && 1 < fieldIndex + fieldValues.length) {
108
+ line.v1 = fieldValues[1 - fieldIndex];
109
+ }
110
+ if (fieldIndex <= 2 && 2 < fieldIndex + fieldValues.length) {
111
+ line.v2 = fieldValues[2 - fieldIndex];
112
+ }
113
+ if (fieldIndex <= 3 && 3 < fieldIndex + fieldValues.length) {
114
+ line.v3 = fieldValues[3 - fieldIndex];
115
+ }
116
+ if (fieldIndex <= 4 && 4 < fieldIndex + fieldValues.length) {
117
+ line.v4 = fieldValues[4 - fieldIndex];
118
+ }
119
+ if (fieldIndex <= 5 && 5 < fieldIndex + fieldValues.length) {
120
+ line.v5 = fieldValues[5 - fieldIndex];
121
+ }
122
+ return this.removePolicyByAdapter(line, filteredPolicies);
123
+ }
124
+ loadPolicyLine(line, model) {
125
+ const lineText = line.ptype +
126
+ ', ' +
127
+ [line.v0, line.v1, line.v2, line.v3, line.v4, line.v5]
128
+ .filter(n => n)
129
+ .join(', ');
130
+ casbin_1.Helper.loadPolicyLine(lineText, model);
131
+ }
132
+ savePolicyLine(ptype, rule) {
133
+ const line = new (this.getAdapterLine())();
134
+ line.ptype = ptype;
135
+ if (rule.length > 0) {
136
+ line.v0 = rule[0];
137
+ }
138
+ if (rule.length > 1) {
139
+ line.v1 = rule[1];
140
+ }
141
+ if (rule.length > 2) {
142
+ line.v2 = rule[2];
143
+ }
144
+ if (rule.length > 3) {
145
+ line.v3 = rule[3];
146
+ }
147
+ if (rule.length > 4) {
148
+ line.v4 = rule[4];
149
+ }
150
+ if (rule.length > 5) {
151
+ line.v5 = rule[5];
152
+ }
153
+ return line;
154
+ }
155
+ }
156
+ exports.BaseAdapter = BaseAdapter;
157
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1,11 @@
1
+ import { IGuard, IMidwayContext } from '@midwayjs/core';
2
+ import { CasbinEnforcerService } from './enforcer.service';
3
+ import { CasbinConfigOptions } from './interface';
4
+ export declare class AuthGuard implements IGuard {
5
+ enforcer: CasbinEnforcerService;
6
+ casbinConfig: CasbinConfigOptions;
7
+ canActivate(context: IMidwayContext, supplierClz: any, methodName: string): Promise<boolean>;
8
+ static asyncSome<T>(array: T[], callback: (value: T, index: number, a: T[]) => Promise<boolean>): Promise<boolean>;
9
+ static asyncEvery<T>(array: T[], callback: (value: T, index: number, a: T[]) => Promise<boolean>): Promise<boolean>;
10
+ }
11
+ //# sourceMappingURL=auth.guard.d.ts.map
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var AuthGuard_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.AuthGuard = void 0;
14
+ const core_1 = require("@midwayjs/core");
15
+ const enforcer_service_1 = require("./enforcer.service");
16
+ const constants_1 = require("./constants");
17
+ let AuthGuard = AuthGuard_1 = class AuthGuard {
18
+ async canActivate(context, supplierClz, methodName) {
19
+ const permissions = (0, core_1.getPropertyMetadata)(constants_1.PERMISSIONS_METADATA_KEY, supplierClz, methodName);
20
+ if (!permissions) {
21
+ return true;
22
+ }
23
+ const username = this.casbinConfig.usernameFromContext(context);
24
+ if (!username) {
25
+ return false;
26
+ }
27
+ const hasPermission = async (user, permission) => {
28
+ const { possession, resource, action } = permission;
29
+ const poss = [];
30
+ if (possession === constants_1.AuthPossession.OWN_ANY) {
31
+ poss.push(constants_1.AuthPossession.ANY, constants_1.AuthPossession.OWN);
32
+ }
33
+ else {
34
+ poss.push(possession);
35
+ }
36
+ return AuthGuard_1.asyncSome(poss, async (p) => {
37
+ if (p === constants_1.AuthPossession.OWN) {
38
+ return permission.isOwn(context);
39
+ }
40
+ else {
41
+ return this.enforcer.enforce(user, resource, `${action}:${p}`);
42
+ }
43
+ });
44
+ };
45
+ return await AuthGuard_1.asyncEvery(permissions, async (permission) => hasPermission(username, permission));
46
+ }
47
+ static async asyncSome(array, callback) {
48
+ for (let i = 0; i < array.length; i++) {
49
+ const result = await callback(array[i], i, array);
50
+ if (result) {
51
+ return result;
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ static async asyncEvery(array, callback) {
57
+ for (let i = 0; i < array.length; i++) {
58
+ const result = await callback(array[i], i, array);
59
+ if (!result) {
60
+ return result;
61
+ }
62
+ }
63
+ return true;
64
+ }
65
+ };
66
+ __decorate([
67
+ (0, core_1.Inject)(),
68
+ __metadata("design:type", enforcer_service_1.CasbinEnforcerService)
69
+ ], AuthGuard.prototype, "enforcer", void 0);
70
+ __decorate([
71
+ (0, core_1.Config)('casbin'),
72
+ __metadata("design:type", Object)
73
+ ], AuthGuard.prototype, "casbinConfig", void 0);
74
+ AuthGuard = AuthGuard_1 = __decorate([
75
+ (0, core_1.Guard)()
76
+ ], AuthGuard);
77
+ exports.AuthGuard = AuthGuard;
78
+ //# sourceMappingURL=auth.guard.js.map
@@ -0,0 +1,4 @@
1
+ export declare class CasbinConfiguration {
2
+ onReady(container: any): Promise<void>;
3
+ }
4
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CasbinConfiguration = void 0;
10
+ const core_1 = require("@midwayjs/core");
11
+ const enforcer_service_1 = require("./enforcer.service");
12
+ let CasbinConfiguration = class CasbinConfiguration {
13
+ async onReady(container) {
14
+ await container.getAsync(enforcer_service_1.CasbinEnforcerService);
15
+ }
16
+ };
17
+ CasbinConfiguration = __decorate([
18
+ (0, core_1.Configuration)({
19
+ namespace: 'casbin',
20
+ importConfigs: [
21
+ {
22
+ default: {
23
+ casbin: {},
24
+ },
25
+ },
26
+ ],
27
+ })
28
+ ], CasbinConfiguration);
29
+ exports.CasbinConfiguration = CasbinConfiguration;
30
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,23 @@
1
+ export declare const PERMISSIONS_METADATA_KEY = "casbin:permission_metadata";
2
+ export declare enum AuthActionVerb {
3
+ CREATE = "create",
4
+ UPDATE = "update",
5
+ DELETE = "delete",
6
+ READ = "read"
7
+ }
8
+ export declare enum AuthPossession {
9
+ ANY = "any",
10
+ OWN = "own",
11
+ OWN_ANY = "own|any"
12
+ }
13
+ export declare enum AuthAction {
14
+ CREATE_ANY = "create:any",
15
+ CREATE_OWN = "create:own",
16
+ UPDATE_ANY = "update:any",
17
+ UPDATE_OWN = "update:own",
18
+ DELETE_ANY = "delete:any",
19
+ DELETE_OWN = "delete:own",
20
+ READ_ANY = "read:any",
21
+ READ_OWN = "read:own"
22
+ }
23
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthAction = exports.AuthPossession = exports.AuthActionVerb = exports.PERMISSIONS_METADATA_KEY = void 0;
4
+ exports.PERMISSIONS_METADATA_KEY = 'casbin:permission_metadata';
5
+ var AuthActionVerb;
6
+ (function (AuthActionVerb) {
7
+ AuthActionVerb["CREATE"] = "create";
8
+ AuthActionVerb["UPDATE"] = "update";
9
+ AuthActionVerb["DELETE"] = "delete";
10
+ AuthActionVerb["READ"] = "read";
11
+ })(AuthActionVerb = exports.AuthActionVerb || (exports.AuthActionVerb = {}));
12
+ var AuthPossession;
13
+ (function (AuthPossession) {
14
+ AuthPossession["ANY"] = "any";
15
+ AuthPossession["OWN"] = "own";
16
+ AuthPossession["OWN_ANY"] = "own|any";
17
+ })(AuthPossession = exports.AuthPossession || (exports.AuthPossession = {}));
18
+ var AuthAction;
19
+ (function (AuthAction) {
20
+ AuthAction["CREATE_ANY"] = "create:any";
21
+ AuthAction["CREATE_OWN"] = "create:own";
22
+ AuthAction["UPDATE_ANY"] = "update:any";
23
+ AuthAction["UPDATE_OWN"] = "update:own";
24
+ AuthAction["DELETE_ANY"] = "delete:any";
25
+ AuthAction["DELETE_OWN"] = "delete:own";
26
+ AuthAction["READ_ANY"] = "read:any";
27
+ AuthAction["READ_OWN"] = "read:own";
28
+ })(AuthAction = exports.AuthAction || (exports.AuthAction = {}));
29
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,7 @@
1
+ import { Permission } from './interface';
2
+ /**
3
+ * You can define multiple permissions, but only
4
+ * when all of them satisfied, could you access the route.
5
+ */
6
+ export declare function UsePermission(...permissions: Permission[]): MethodDecorator;
7
+ //# sourceMappingURL=decorator.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsePermission = void 0;
4
+ const constants_1 = require("./constants");
5
+ const core_1 = require("@midwayjs/core");
6
+ const defaultIsOwn = (ctx) => false;
7
+ /**
8
+ * You can define multiple permissions, but only
9
+ * when all of them satisfied, could you access the route.
10
+ */
11
+ function UsePermission(...permissions) {
12
+ return (target, propertyKey, descriptor) => {
13
+ const perms = permissions.map(item => {
14
+ if (!item.isOwn) {
15
+ item.isOwn = defaultIsOwn;
16
+ }
17
+ return item;
18
+ });
19
+ (0, core_1.savePropertyMetadata)(constants_1.PERMISSIONS_METADATA_KEY, perms, target, propertyKey);
20
+ };
21
+ }
22
+ exports.UsePermission = UsePermission;
23
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1,13 @@
1
+ import { Enforcer } from 'casbin';
2
+ import { IMidwayContainer } from '@midwayjs/core';
3
+ import { CasbinConfigOptions } from './interface';
4
+ export declare class CasbinEnforcerService {
5
+ private instance;
6
+ protected casbinConfig: CasbinConfigOptions;
7
+ applicationContext: IMidwayContainer;
8
+ protected init(): Promise<void>;
9
+ getEnforcer(): Enforcer;
10
+ }
11
+ export interface CasbinEnforcerService extends Enforcer {
12
+ }
13
+ //# sourceMappingURL=enforcer.service.d.ts.map
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CasbinEnforcerService = void 0;
13
+ const casbin_1 = require("casbin");
14
+ const core_1 = require("@midwayjs/core");
15
+ let CasbinEnforcerService = class CasbinEnforcerService {
16
+ async init() {
17
+ if (typeof this.casbinConfig.policyAdapter === 'function') {
18
+ this.casbinConfig.policyAdapter = await this.casbinConfig.policyAdapter(this.applicationContext);
19
+ }
20
+ this.instance = await (0, casbin_1.newEnforcer)(this.casbinConfig.modelPath, this.casbinConfig.policyAdapter);
21
+ }
22
+ getEnforcer() {
23
+ return this.instance;
24
+ }
25
+ };
26
+ __decorate([
27
+ (0, core_1.Config)('casbin'),
28
+ __metadata("design:type", Object)
29
+ ], CasbinEnforcerService.prototype, "casbinConfig", void 0);
30
+ __decorate([
31
+ (0, core_1.ApplicationContext)(),
32
+ __metadata("design:type", Object)
33
+ ], CasbinEnforcerService.prototype, "applicationContext", void 0);
34
+ __decorate([
35
+ (0, core_1.Init)(),
36
+ __metadata("design:type", Function),
37
+ __metadata("design:paramtypes", []),
38
+ __metadata("design:returntype", Promise)
39
+ ], CasbinEnforcerService.prototype, "init", null);
40
+ CasbinEnforcerService = __decorate([
41
+ (0, core_1.Provide)(),
42
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
43
+ ], CasbinEnforcerService);
44
+ exports.CasbinEnforcerService = CasbinEnforcerService;
45
+ (0, core_1.delegateTargetAllPrototypeMethod)(CasbinEnforcerService, casbin_1.Enforcer);
46
+ //# sourceMappingURL=enforcer.service.js.map
@@ -0,0 +1,8 @@
1
+ export { CasbinConfiguration as Configuration } from './configuration';
2
+ export * from './enforcer.service';
3
+ export * from './auth.guard';
4
+ export * from './decorator';
5
+ export * from './interface';
6
+ export * from './constants';
7
+ export * from './adapter';
8
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Configuration = void 0;
18
+ var configuration_1 = require("./configuration");
19
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.CasbinConfiguration; } });
20
+ __exportStar(require("./enforcer.service"), exports);
21
+ __exportStar(require("./auth.guard"), exports);
22
+ __exportStar(require("./decorator"), exports);
23
+ __exportStar(require("./interface"), exports);
24
+ __exportStar(require("./constants"), exports);
25
+ __exportStar(require("./adapter"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import { Adapter } from 'casbin';
2
+ import { AuthActionVerb, AuthPossession } from './constants';
3
+ import { IMidwayContainer, IMidwayContext } from '@midwayjs/core';
4
+ export interface CasbinConfigOptions {
5
+ modelPath: string;
6
+ policyAdapter: string | ((applicationContext: IMidwayContainer) => Adapter) | Adapter;
7
+ usernameFromContext: (ctx: IMidwayContext) => string;
8
+ }
9
+ export interface Permission {
10
+ resource: string;
11
+ action: AuthActionVerb | CustomAuthActionVerb;
12
+ possession: AuthPossession;
13
+ isOwn?: (ctx: IMidwayContext) => boolean;
14
+ }
15
+ export declare type CustomAuthActionVerb = string;
16
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { CasbinConfigOptions } from './dist/index';
2
+
3
+ export * from './dist/index';
4
+
5
+ declare module '@midwayjs/core/dist/interface' {
6
+ interface MidwayConfig {
7
+ casbin?: Partial<CasbinConfigOptions>;
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@midwayjs/casbin",
3
+ "description": "midway casbin component",
4
+ "version": "3.5.3",
5
+ "main": "dist/index",
6
+ "typings": "index.d.ts",
7
+ "files": [
8
+ "dist/**/*.js",
9
+ "dist/**/*.d.ts",
10
+ "index.d.ts"
11
+ ],
12
+ "devDependencies": {
13
+ "@midwayjs/core": "^3.5.3",
14
+ "@midwayjs/koa": "^3.5.3",
15
+ "@midwayjs/mock": "^3.5.3"
16
+ },
17
+ "dependencies": {
18
+ "casbin": "5.19.1"
19
+ },
20
+ "keywords": [
21
+ "midway",
22
+ "component",
23
+ "casbin"
24
+ ],
25
+ "author": "czy88840616 <czy88840616@gmail.com>",
26
+ "license": "MIT",
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
30
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
31
+ "ci": "npm run test",
32
+ "lint": "mwts check"
33
+ },
34
+ "engines": {
35
+ "node": ">=12"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/midwayjs/midway.git"
40
+ }
41
+ }