@spinajs/rbac-http 1.2.108
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 +11 -0
- package/lib/config/rbac-http.d.ts +1 -0
- package/lib/config/rbac-http.js +23 -0
- package/lib/config/rbac-http.js.map +1 -0
- package/lib/controllers/LoginController.d.ts +12 -0
- package/lib/controllers/LoginController.js +91 -0
- package/lib/controllers/LoginController.js.map +1 -0
- package/lib/controllers/UsersController.d.ts +17 -0
- package/lib/controllers/UsersController.js +199 -0
- package/lib/controllers/UsersController.js.map +1 -0
- package/lib/decorators.d.ts +16 -0
- package/lib/decorators.js +65 -0
- package/lib/decorators.js.map +1 -0
- package/lib/dto/login-dto.d.ts +20 -0
- package/lib/dto/login-dto.js +27 -0
- package/lib/dto/login-dto.js.map +1 -0
- package/lib/dto/password-dto.d.ts +22 -0
- package/lib/dto/password-dto.js +27 -0
- package/lib/dto/password-dto.js.map +1 -0
- package/lib/dto/user-dto.d.ts +42 -0
- package/lib/dto/user-dto.js +31 -0
- package/lib/dto/user-dto.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces.d.ts +22 -0
- package/lib/interfaces.js +3 -0
- package/lib/interfaces.js.map +1 -0
- package/lib/middlewares.d.ts +6 -0
- package/lib/middlewares.js +71 -0
- package/lib/middlewares.js.map +1 -0
- package/lib/policies.d.ts +9 -0
- package/lib/policies.js +37 -0
- package/lib/policies.js.map +1 -0
- package/lib/rbac-http.js +7 -0
- package/lib/route-args.d.ts +9 -0
- package/lib/route-args.js +24 -0
- package/lib/route-args.js.map +1 -0
- package/lib/transformers.d.ts +11 -0
- package/lib/transformers.js +34 -0
- package/lib/transformers.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const middlewares_1 = require("../middlewares");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function dir(path) {
|
|
6
|
+
return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
|
|
7
|
+
}
|
|
8
|
+
module.exports = {
|
|
9
|
+
system: {
|
|
10
|
+
dirs: {
|
|
11
|
+
controllers: [dir('./../controllers')],
|
|
12
|
+
locales: [dir('./../locales')],
|
|
13
|
+
views: [dir('./../views')],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
http: {
|
|
17
|
+
middlewares: [
|
|
18
|
+
// add global user from session middleware
|
|
19
|
+
(0, middlewares_1.UserFromSession)(),
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=rbac-http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac-http.js","sourceRoot":"","sources":["../../src/config/rbac-http.ts"],"names":[],"mappings":";;AAAA,gDAAiD;AACjD,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AACD,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,WAAW,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACtC,OAAO,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC9B,KAAK,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC3B;KACF;IACD,IAAI,EAAE;QACJ,WAAW,EAAE;YACX,0CAA0C;YAC1C,IAAA,6BAAe,GAAE;SAClB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LoginDto } from './../dto/login-dto';
|
|
2
|
+
import { BaseController, Ok, CookieResponse, Unauthorized } from '@spinajs/http';
|
|
3
|
+
import { AuthProvider, SessionProvider } from '@spinajs/rbac';
|
|
4
|
+
import { Configuration } from '@spinajs/configuration';
|
|
5
|
+
export declare class LoginController extends BaseController {
|
|
6
|
+
protected Configuration: Configuration;
|
|
7
|
+
protected AuthProvider: AuthProvider;
|
|
8
|
+
protected SessionProvider: SessionProvider;
|
|
9
|
+
protected SessionExpirationTime: number;
|
|
10
|
+
login(credentials: LoginDto): Promise<Unauthorized | CookieResponse>;
|
|
11
|
+
logout(ssid: string): Promise<Ok | CookieResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LoginController = void 0;
|
|
16
|
+
const login_dto_1 = require("./../dto/login-dto");
|
|
17
|
+
const http_1 = require("@spinajs/http");
|
|
18
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
19
|
+
const di_1 = require("@spinajs/di");
|
|
20
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
21
|
+
const luxon_1 = require("luxon");
|
|
22
|
+
let LoginController = class LoginController extends http_1.BaseController {
|
|
23
|
+
async login(credentials) {
|
|
24
|
+
const user = await this.AuthProvider.authenticate(credentials.Login, credentials.Password);
|
|
25
|
+
if (!user) {
|
|
26
|
+
return new http_1.Unauthorized({
|
|
27
|
+
error: {
|
|
28
|
+
message: 'login or password incorrect',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const lifetime = luxon_1.DateTime.now().plus({ minutes: this.SessionExpirationTime });
|
|
33
|
+
const uObject = {
|
|
34
|
+
Login: user.Login,
|
|
35
|
+
Email: user.Email,
|
|
36
|
+
NiceName: user.NiceName,
|
|
37
|
+
Metadata: user.Metadata.map((m) => ({ Key: m.Key, Value: m.Value })),
|
|
38
|
+
Role: user.Role,
|
|
39
|
+
Id: user.Id,
|
|
40
|
+
};
|
|
41
|
+
const session = new rbac_1.Session({
|
|
42
|
+
Data: uObject,
|
|
43
|
+
Expiration: lifetime,
|
|
44
|
+
});
|
|
45
|
+
await this.SessionProvider.updateSession(session);
|
|
46
|
+
return new http_1.CookieResponse('ssid', session.SessionId, this.SessionExpirationTime, uObject);
|
|
47
|
+
}
|
|
48
|
+
async logout(ssid) {
|
|
49
|
+
if (!ssid) {
|
|
50
|
+
return new http_1.Ok();
|
|
51
|
+
}
|
|
52
|
+
await this.SessionProvider.deleteSession(ssid);
|
|
53
|
+
// send empty cookie to confirm session deletion
|
|
54
|
+
return new http_1.CookieResponse('ssid', null, this.SessionExpirationTime);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, di_1.Autoinject)(),
|
|
59
|
+
__metadata("design:type", configuration_1.Configuration)
|
|
60
|
+
], LoginController.prototype, "Configuration", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, di_1.Autoinject)(),
|
|
63
|
+
__metadata("design:type", rbac_1.AuthProvider)
|
|
64
|
+
], LoginController.prototype, "AuthProvider", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, di_1.Autoinject)(),
|
|
67
|
+
__metadata("design:type", rbac_1.SessionProvider)
|
|
68
|
+
], LoginController.prototype, "SessionProvider", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, configuration_1.Config)('acl.session.expiration', 10),
|
|
71
|
+
__metadata("design:type", Number)
|
|
72
|
+
], LoginController.prototype, "SessionExpirationTime", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, http_1.Post)(),
|
|
75
|
+
__param(0, (0, http_1.Body)()),
|
|
76
|
+
__metadata("design:type", Function),
|
|
77
|
+
__metadata("design:paramtypes", [login_dto_1.LoginDto]),
|
|
78
|
+
__metadata("design:returntype", Promise)
|
|
79
|
+
], LoginController.prototype, "login", null);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, http_1.Get)(),
|
|
82
|
+
__param(0, (0, http_1.Cookie)()),
|
|
83
|
+
__metadata("design:type", Function),
|
|
84
|
+
__metadata("design:paramtypes", [String]),
|
|
85
|
+
__metadata("design:returntype", Promise)
|
|
86
|
+
], LoginController.prototype, "logout", null);
|
|
87
|
+
LoginController = __decorate([
|
|
88
|
+
(0, http_1.BasePath)('auth')
|
|
89
|
+
], LoginController);
|
|
90
|
+
exports.LoginController = LoginController;
|
|
91
|
+
//# sourceMappingURL=LoginController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoginController.js","sourceRoot":"","sources":["../../src/controllers/LoginController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA8C;AAC9C,wCAAoH;AACpH,wCAAuE;AACvE,oCAAyC;AACzC,0DAA+D;AAC/D,iCAAiC;AAGjC,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,qBAAc;IAc1C,KAAK,CAAC,KAAK,CAAS,WAAqB;QAC9C,MAAM,IAAI,GAAG,MAAM,IAAI,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AgD;QAChD,OAAO,IAAI,qBAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACtE,CAAC;CACF,CAAA;AAtDC;IADC,IAAA,eAAU,GAAE;8BACY,6BAAa;sDAAC;AAGvC;IADC,IAAA,eAAU,GAAE;8BACW,mBAAY;qDAAC;AAGrC;IADC,IAAA,eAAU,GAAE;8BACc,sBAAe;wDAAC;AAG3C;IADC,IAAA,sBAAM,EAAC,wBAAwB,EAAE,EAAE,CAAC;;8DACG;AAGxC;IADC,IAAA,WAAI,GAAE;IACa,WAAA,IAAA,WAAI,GAAE,CAAA;;qCAAc,oBAAQ;;4CA6B/C;AAGD;IADC,IAAA,UAAG,GAAE;IACe,WAAA,IAAA,aAAM,GAAE,CAAA;;;;6CAS5B;AAvDU,eAAe;IAD3B,IAAA,eAAQ,EAAC,MAAM,CAAC;GACJ,eAAe,CAwD3B;AAxDY,0CAAe"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PasswordDto } from './../dto/password-dto';
|
|
2
|
+
import { UserDto } from './../dto/user-dto';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
import { BaseController, Ok, NotFound } from '@spinajs/http';
|
|
5
|
+
import { IContainer } from '@spinajs/di';
|
|
6
|
+
import { UserDataTransformer, IUserResult } from '../transformers';
|
|
7
|
+
import { SORT_ORDER } from '@spinajs/orm/lib/enums';
|
|
8
|
+
export declare class UsersController extends BaseController {
|
|
9
|
+
protected DataTransformer: UserDataTransformer<IUserResult>;
|
|
10
|
+
protected Container: IContainer;
|
|
11
|
+
listUsers(search: string, page: number, perPage: number, order: string, orderDirection: SORT_ORDER, request: express.Request): Promise<NotFound | Ok>;
|
|
12
|
+
getUser(id: number): Promise<Ok>;
|
|
13
|
+
addUser(user: UserDto): Promise<Ok>;
|
|
14
|
+
deleteUser(id: number): Promise<Ok>;
|
|
15
|
+
updateUser(id: number, user: UserDto): Promise<Ok>;
|
|
16
|
+
updateUserPassword(id: number, pwd: PasswordDto): Promise<Ok>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
34
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
35
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.UsersController = void 0;
|
|
39
|
+
const password_dto_1 = require("./../dto/password-dto");
|
|
40
|
+
const user_dto_1 = require("./../dto/user-dto");
|
|
41
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
42
|
+
const express = __importStar(require("express"));
|
|
43
|
+
const http_1 = require("@spinajs/http");
|
|
44
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
45
|
+
const orm_1 = require("@spinajs/orm");
|
|
46
|
+
const di_1 = require("@spinajs/di");
|
|
47
|
+
const transformers_1 = require("../transformers");
|
|
48
|
+
const enums_1 = require("@spinajs/orm/lib/enums");
|
|
49
|
+
const OrderSchema = {
|
|
50
|
+
type: 'string',
|
|
51
|
+
enum: ['asc', 'desc'],
|
|
52
|
+
};
|
|
53
|
+
let UsersController = class UsersController extends http_1.BaseController {
|
|
54
|
+
async listUsers(search, page, perPage, order, orderDirection, request) {
|
|
55
|
+
const query = rbac_1.User.all()
|
|
56
|
+
.whereNull('DeletedAt')
|
|
57
|
+
.skip((page - 1) * perPage)
|
|
58
|
+
.take(perPage)
|
|
59
|
+
.order(order, orderDirection)
|
|
60
|
+
.populate('Roles')
|
|
61
|
+
.populate('Metadata');
|
|
62
|
+
const countQuery = rbac_1.User.query().select(new orm_1.RawQuery('count(*) as count')).whereNull('DeletedAt');
|
|
63
|
+
if (search) {
|
|
64
|
+
const searchFunc = function () {
|
|
65
|
+
this.where('Email', 'like', `%${search}%`);
|
|
66
|
+
this.orWhere('Login', 'like', `${search}%`);
|
|
67
|
+
this.orWhere('NiceName', 'like', `%${search}%`);
|
|
68
|
+
};
|
|
69
|
+
query.where(searchFunc);
|
|
70
|
+
countQuery.where(searchFunc);
|
|
71
|
+
}
|
|
72
|
+
const r = await query;
|
|
73
|
+
const c = await countQuery.asRaw();
|
|
74
|
+
if (r.length === 0) {
|
|
75
|
+
return new http_1.NotFound('no users met search criteria');
|
|
76
|
+
}
|
|
77
|
+
return new http_1.Ok(this.DataTransformer.transform({
|
|
78
|
+
Data: r,
|
|
79
|
+
Total: c[0].count,
|
|
80
|
+
}, request));
|
|
81
|
+
}
|
|
82
|
+
async getUser(id) {
|
|
83
|
+
const user = await rbac_1.User.where({
|
|
84
|
+
Id: id,
|
|
85
|
+
})
|
|
86
|
+
.whereNull('DeletedAt')
|
|
87
|
+
.populate('Metadata')
|
|
88
|
+
.populate('Roles')
|
|
89
|
+
.firstOrFail();
|
|
90
|
+
return new http_1.Ok(user);
|
|
91
|
+
}
|
|
92
|
+
async addUser(user) {
|
|
93
|
+
const password = this.Container.resolve(rbac_1.PasswordProvider);
|
|
94
|
+
if (user.Password !== user.ConfirmPassword) {
|
|
95
|
+
throw new exceptions_1.InvalidArgument('password does not match');
|
|
96
|
+
}
|
|
97
|
+
let hashedPassword = '';
|
|
98
|
+
let userPassword = user.Password;
|
|
99
|
+
if (!userPassword) {
|
|
100
|
+
userPassword = password.generate();
|
|
101
|
+
}
|
|
102
|
+
hashedPassword = await password.hash(userPassword);
|
|
103
|
+
const entity = new rbac_1.User({
|
|
104
|
+
Email: user.Email,
|
|
105
|
+
Login: user.Login,
|
|
106
|
+
NiceName: user.NiceName,
|
|
107
|
+
Password: hashedPassword,
|
|
108
|
+
CreatedAt: new Date(),
|
|
109
|
+
});
|
|
110
|
+
await entity.insert();
|
|
111
|
+
return new http_1.Ok({ Id: entity.Id });
|
|
112
|
+
}
|
|
113
|
+
async deleteUser(id) {
|
|
114
|
+
const entity = await rbac_1.User.getOrFail(id);
|
|
115
|
+
await entity.destroy();
|
|
116
|
+
return new http_1.Ok();
|
|
117
|
+
}
|
|
118
|
+
async updateUser(id, user) {
|
|
119
|
+
const entity = await rbac_1.User.getOrFail(id);
|
|
120
|
+
entity.Email = user.Email;
|
|
121
|
+
entity.NiceName = user.NiceName;
|
|
122
|
+
entity.Login = user.Login;
|
|
123
|
+
await entity.update();
|
|
124
|
+
return new http_1.Ok();
|
|
125
|
+
}
|
|
126
|
+
async updateUserPassword(id, pwd) {
|
|
127
|
+
if (pwd.Password !== pwd.ConfirmPassword) {
|
|
128
|
+
throw new exceptions_1.InvalidArgument('password does not match');
|
|
129
|
+
}
|
|
130
|
+
const entity = await rbac_1.User.getOrFail(id);
|
|
131
|
+
const password = this.Container.resolve(rbac_1.PasswordProvider);
|
|
132
|
+
const hashedPassword = await password.hash(pwd.Password);
|
|
133
|
+
entity.Password = hashedPassword;
|
|
134
|
+
await entity.update();
|
|
135
|
+
return new http_1.Ok();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, di_1.Autoinject)(),
|
|
140
|
+
__metadata("design:type", transformers_1.UserDataTransformer)
|
|
141
|
+
], UsersController.prototype, "DataTransformer", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, di_1.Autoinject)(di_1.Container),
|
|
144
|
+
__metadata("design:type", Object)
|
|
145
|
+
], UsersController.prototype, "Container", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, http_1.Get)('/'),
|
|
148
|
+
__param(0, (0, http_1.Query)()),
|
|
149
|
+
__param(1, (0, http_1.Query)({ type: 'number', min: 1, default: 0 })),
|
|
150
|
+
__param(2, (0, http_1.Query)({ type: 'number', min: 1, default: 30 })),
|
|
151
|
+
__param(3, (0, http_1.Query)()),
|
|
152
|
+
__param(4, (0, http_1.Query)(OrderSchema)),
|
|
153
|
+
__param(5, (0, http_1.Req)()),
|
|
154
|
+
__metadata("design:type", Function),
|
|
155
|
+
__metadata("design:paramtypes", [String, Number, Number, String, String, Object]),
|
|
156
|
+
__metadata("design:returntype", Promise)
|
|
157
|
+
], UsersController.prototype, "listUsers", null);
|
|
158
|
+
__decorate([
|
|
159
|
+
(0, http_1.Get)(':id'),
|
|
160
|
+
__param(0, (0, http_1.PKey)()),
|
|
161
|
+
__metadata("design:type", Function),
|
|
162
|
+
__metadata("design:paramtypes", [Number]),
|
|
163
|
+
__metadata("design:returntype", Promise)
|
|
164
|
+
], UsersController.prototype, "getUser", null);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, http_1.Post)('/'),
|
|
167
|
+
__param(0, (0, http_1.Body)()),
|
|
168
|
+
__metadata("design:type", Function),
|
|
169
|
+
__metadata("design:paramtypes", [user_dto_1.UserDto]),
|
|
170
|
+
__metadata("design:returntype", Promise)
|
|
171
|
+
], UsersController.prototype, "addUser", null);
|
|
172
|
+
__decorate([
|
|
173
|
+
(0, http_1.Del)(':id'),
|
|
174
|
+
__param(0, (0, http_1.PKey)()),
|
|
175
|
+
__metadata("design:type", Function),
|
|
176
|
+
__metadata("design:paramtypes", [Number]),
|
|
177
|
+
__metadata("design:returntype", Promise)
|
|
178
|
+
], UsersController.prototype, "deleteUser", null);
|
|
179
|
+
__decorate([
|
|
180
|
+
(0, http_1.Put)(':id'),
|
|
181
|
+
__param(0, (0, http_1.PKey)()),
|
|
182
|
+
__param(1, (0, http_1.Body)()),
|
|
183
|
+
__metadata("design:type", Function),
|
|
184
|
+
__metadata("design:paramtypes", [Number, user_dto_1.UserDto]),
|
|
185
|
+
__metadata("design:returntype", Promise)
|
|
186
|
+
], UsersController.prototype, "updateUser", null);
|
|
187
|
+
__decorate([
|
|
188
|
+
(0, http_1.Put)(':id/change-password'),
|
|
189
|
+
__param(0, (0, http_1.PKey)()),
|
|
190
|
+
__param(1, (0, http_1.Body)()),
|
|
191
|
+
__metadata("design:type", Function),
|
|
192
|
+
__metadata("design:paramtypes", [Number, password_dto_1.PasswordDto]),
|
|
193
|
+
__metadata("design:returntype", Promise)
|
|
194
|
+
], UsersController.prototype, "updateUserPassword", null);
|
|
195
|
+
UsersController = __decorate([
|
|
196
|
+
(0, http_1.BasePath)('users')
|
|
197
|
+
], UsersController);
|
|
198
|
+
exports.UsersController = UsersController;
|
|
199
|
+
//# sourceMappingURL=UsersController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersController.js","sourceRoot":"","sources":["../../src/controllers/UsersController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAoD;AACpD,gDAA4C;AAC5C,wCAAuD;AACvD,iDAAmC;AACnC,wCAAoH;AACpH,oDAAsD;AACtD,sCAAwC;AACxC,oCAAgE;AAChE,kDAAmE;AACnE,kDAAoD;AAEpD,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;CACtB,CAAC;AAGF,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,qBAAc;IAQ1C,KAAK,CAAC,SAAS,CAAU,MAAc,EAAiD,IAAY,EAAkD,OAAe,EAAW,KAAa,EAAsB,cAA0B,EAAS,OAAwB;QACnR,MAAM,KAAK,GAAG,WAAI,CAAC,GAAG,EAAE;aACrB,SAAS,CAAC,WAAW,CAAC;aACtB,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;aAC1B,IAAI,CAAC,OAAO,CAAC;aACb,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC;aAC5B,QAAQ,CAAC,OAAO,CAAC;aACjB,QAAQ,CAAC,UAAU,CAAC,CAAC;QACxB,MAAM,UAAU,GAAG,WAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,IAAI,cAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAEjG,IAAI,MAAM,EAAE;YACV,MAAM,UAAU,GAAG;gBACjB,IAAI,CAAC,KAAK,CAAC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IAAA,WAAI,EAAC,GAAG,CAAC;IACY,WAAA,IAAA,WAAI,GAAE,CAAA;;qCAAO,kBAAO;;8CAyBzC;AAGD;IADC,IAAA,UAAG,EAAC,KAAK,CAAC;IACc,WAAA,IAAA,WAAI,GAAE,CAAA;;;;iDAI9B;AAGD;IADC,IAAA,UAAG,EAAC,KAAK,CAAC;IACc,WAAA,IAAA,WAAI,GAAE,CAAA;IAAc,WAAA,IAAA,WAAI,GAAE,CAAA;;6CAAO,kBAAO;;iDAShE;AAGD;IADC,IAAA,UAAG,EAAC,qBAAqB,CAAC;IACM,WAAA,IAAA,WAAI,GAAE,CAAA;IAAc,WAAA,IAAA,WAAI,GAAE,CAAA;;6CAAM,0BAAW;;yDAY3E;AAxHU,eAAe;IAD3B,IAAA,eAAQ,EAAC,OAAO,CAAC;GACL,eAAe,CAyH3B;AAzHY,0CAAe"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const ACL_CONTROLLER_DESCRIPTOR: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* Assign resource for controller
|
|
4
|
+
*
|
|
5
|
+
* @param resource - name of resource
|
|
6
|
+
* @param permission - default permission
|
|
7
|
+
*/
|
|
8
|
+
export declare function Resource(resource: string, permission?: 'readAny' | 'readOwn' | 'updateAny' | 'updateOwn' | 'deleteAny' | 'deleteOwn' | 'createAny' | 'createOwn'): any;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* Assigns permission for controller route
|
|
12
|
+
*
|
|
13
|
+
* @param permission - permission to set
|
|
14
|
+
*/
|
|
15
|
+
export declare function Permission(permission: string): any;
|
|
16
|
+
export declare function FromUser(): (target: any, propertyKey?: string | symbol, indexOrDescriptor?: number | PropertyDescriptor) => void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromUser = exports.Permission = exports.Resource = exports.ACL_CONTROLLER_DESCRIPTOR = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
const policies_1 = require("./policies");
|
|
6
|
+
exports.ACL_CONTROLLER_DESCRIPTOR = Symbol('ACL_CONTROLLER_DESCRIPTOR_SYMBOL');
|
|
7
|
+
function descriptor(callback) {
|
|
8
|
+
return (target, propertyKey, indexOrDescriptor) => {
|
|
9
|
+
let metadata = Reflect.getMetadata(exports.ACL_CONTROLLER_DESCRIPTOR, target.prototype || target);
|
|
10
|
+
if (!metadata) {
|
|
11
|
+
metadata = {
|
|
12
|
+
Resource: '',
|
|
13
|
+
Routes: new Map(),
|
|
14
|
+
Permission: 'readOwn',
|
|
15
|
+
};
|
|
16
|
+
Reflect.defineMetadata(exports.ACL_CONTROLLER_DESCRIPTOR, metadata, target.prototype || target);
|
|
17
|
+
}
|
|
18
|
+
if (callback) {
|
|
19
|
+
callback(metadata, target, propertyKey, indexOrDescriptor);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Assign resource for controller
|
|
25
|
+
*
|
|
26
|
+
* @param resource - name of resource
|
|
27
|
+
* @param permission - default permission
|
|
28
|
+
*/
|
|
29
|
+
function Resource(resource, permission = 'readOwn') {
|
|
30
|
+
return descriptor((metadata, target) => {
|
|
31
|
+
(0, http_1.Policy)(policies_1.AclPolicy)(target, null, null);
|
|
32
|
+
metadata.Resource = resource;
|
|
33
|
+
metadata.Permission = permission;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.Resource = Resource;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* Assigns permission for controller route
|
|
40
|
+
*
|
|
41
|
+
* @param permission - permission to set
|
|
42
|
+
*/
|
|
43
|
+
function Permission(permission) {
|
|
44
|
+
return descriptor((metadata, target, propertyKey) => {
|
|
45
|
+
let route = null;
|
|
46
|
+
if (propertyKey) {
|
|
47
|
+
if (metadata.Routes.has(propertyKey)) {
|
|
48
|
+
route = metadata.Routes.get(propertyKey);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
route = {
|
|
52
|
+
Permission: permission,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
metadata.Routes.set(propertyKey, route);
|
|
56
|
+
}
|
|
57
|
+
(0, http_1.Policy)(policies_1.AclPolicy)(target, propertyKey, null);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.Permission = Permission;
|
|
61
|
+
function FromUser() {
|
|
62
|
+
return (0, http_1.Route)((0, http_1.Parameter)('UserArg'));
|
|
63
|
+
}
|
|
64
|
+
exports.FromUser = FromUser;
|
|
65
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AACA,wCAAyD;AACzD,yCAAuC;AAE1B,QAAA,yBAAyB,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAEpF,SAAS,UAAU,CAAC,QAAyI;IAC3J,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,iBAA8C,EAAE,EAAE;QACnG,IAAI,QAAQ,GAAmB,OAAO,CAAC,WAAW,CAAC,iCAAyB,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;QAC1G,IAAI,CAAC,QAAQ,EAAE;YACb,QAAQ,GAAG;gBACT,QAAQ,EAAE,EAAE;gBACZ,MAAM,EAAE,IAAI,GAAG,EAAyC;gBACxD,UAAU,EAAE,SAAS;aACtB,CAAC;YAEF,OAAO,CAAC,cAAc,CAAC,iCAAyB,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;SACzF;QAED,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;SAC5D;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,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
|
|
8
|
+
maxLength: number;
|
|
9
|
+
};
|
|
10
|
+
Password: {
|
|
11
|
+
type: string;
|
|
12
|
+
maxLength: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
required: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare class LoginDto {
|
|
18
|
+
Login: string;
|
|
19
|
+
Password: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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.LoginDto = exports.LoginDtoSchema = void 0;
|
|
10
|
+
const validation_1 = require("@spinajs/validation");
|
|
11
|
+
exports.LoginDtoSchema = {
|
|
12
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
13
|
+
title: 'User login DTO',
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
Login: { type: 'string', maxLength: 32 },
|
|
17
|
+
Password: { type: 'string', maxLength: 32 },
|
|
18
|
+
},
|
|
19
|
+
required: ['Login', 'Password'],
|
|
20
|
+
};
|
|
21
|
+
let LoginDto = class LoginDto {
|
|
22
|
+
};
|
|
23
|
+
LoginDto = __decorate([
|
|
24
|
+
(0, validation_1.Schema)(exports.LoginDtoSchema)
|
|
25
|
+
], LoginDto);
|
|
26
|
+
exports.LoginDto = LoginDto;
|
|
27
|
+
//# sourceMappingURL=login-dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-dto.js","sourceRoot":"","sources":["../../src/dto/login-dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;QACxC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;KAC5C;IACD,QAAQ,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;CAChC,CAAC;AAGF,IAAa,QAAQ,GAArB,MAAa,QAAQ;CAIpB,CAAA;AAJY,QAAQ;IADpB,IAAA,mBAAM,EAAC,sBAAc,CAAC;GACV,QAAQ,CAIpB;AAJY,4BAAQ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const PasswordDtoSchema: {
|
|
2
|
+
$schema: string;
|
|
3
|
+
title: string;
|
|
4
|
+
type: string;
|
|
5
|
+
properties: {
|
|
6
|
+
Password: {
|
|
7
|
+
type: string;
|
|
8
|
+
maxLength: number;
|
|
9
|
+
minLength: number;
|
|
10
|
+
};
|
|
11
|
+
ConfirmPassword: {
|
|
12
|
+
type: string;
|
|
13
|
+
maxLength: number;
|
|
14
|
+
minLength: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
required: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare class PasswordDto {
|
|
20
|
+
Password: string;
|
|
21
|
+
ConfirmPassword: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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.PasswordDto = exports.PasswordDtoSchema = void 0;
|
|
10
|
+
const validation_1 = require("@spinajs/validation");
|
|
11
|
+
exports.PasswordDtoSchema = {
|
|
12
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
13
|
+
title: 'User password DTO',
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
Password: { type: 'string', maxLength: 32, minLength: 6 },
|
|
17
|
+
ConfirmPassword: { type: 'string', maxLength: 32, minLength: 6 },
|
|
18
|
+
},
|
|
19
|
+
required: ['Password', 'ConfirmPassword'],
|
|
20
|
+
};
|
|
21
|
+
let PasswordDto = class PasswordDto {
|
|
22
|
+
};
|
|
23
|
+
PasswordDto = __decorate([
|
|
24
|
+
(0, validation_1.Schema)(exports.PasswordDtoSchema)
|
|
25
|
+
], PasswordDto);
|
|
26
|
+
exports.PasswordDto = PasswordDto;
|
|
27
|
+
//# sourceMappingURL=password-dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-dto.js","sourceRoot":"","sources":["../../src/dto/password-dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,mBAAmB;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;QACzD,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;KACjE;IACD,QAAQ,EAAE,CAAC,UAAU,EAAE,iBAAiB,CAAC;CAC1C,CAAC;AAGF,IAAa,WAAW,GAAxB,MAAa,WAAW;CAIvB,CAAA;AAJY,WAAW;IADvB,IAAA,mBAAM,EAAC,yBAAiB,CAAC;GACb,WAAW,CAIvB;AAJY,kCAAW"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const UserDtoSchema: {
|
|
2
|
+
$schema: string;
|
|
3
|
+
title: string;
|
|
4
|
+
type: string;
|
|
5
|
+
properties: {
|
|
6
|
+
Id: {
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
Email: {
|
|
10
|
+
type: string;
|
|
11
|
+
format: string;
|
|
12
|
+
maxLength: number;
|
|
13
|
+
};
|
|
14
|
+
Login: {
|
|
15
|
+
type: string;
|
|
16
|
+
maxLength: number;
|
|
17
|
+
};
|
|
18
|
+
ConfirmPassword: {
|
|
19
|
+
type: string;
|
|
20
|
+
maxLength: number;
|
|
21
|
+
minLength: number;
|
|
22
|
+
};
|
|
23
|
+
Password: {
|
|
24
|
+
type: string;
|
|
25
|
+
maxLength: number;
|
|
26
|
+
minLength: number;
|
|
27
|
+
};
|
|
28
|
+
NiceName: {
|
|
29
|
+
type: string;
|
|
30
|
+
maxLength: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
required: string[];
|
|
34
|
+
};
|
|
35
|
+
export declare class UserDto {
|
|
36
|
+
Id?: number;
|
|
37
|
+
Email: string;
|
|
38
|
+
Login: string;
|
|
39
|
+
Password: string;
|
|
40
|
+
ConfirmPassword: string;
|
|
41
|
+
NiceName: string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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.UserDto = exports.UserDtoSchema = void 0;
|
|
10
|
+
const validation_1 = require("@spinajs/validation");
|
|
11
|
+
exports.UserDtoSchema = {
|
|
12
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
13
|
+
title: 'User DTO',
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
Id: { type: 'number' },
|
|
17
|
+
Email: { type: 'string', format: 'email', maxLength: 64 },
|
|
18
|
+
Login: { type: 'string', maxLength: 64 },
|
|
19
|
+
ConfirmPassword: { type: 'string', maxLength: 32, minLength: 6 },
|
|
20
|
+
Password: { type: 'string', maxLength: 32, minLength: 6 },
|
|
21
|
+
NiceName: { type: 'string', maxLength: 64 },
|
|
22
|
+
},
|
|
23
|
+
required: ['Email', 'NiceName'],
|
|
24
|
+
};
|
|
25
|
+
let UserDto = class UserDto {
|
|
26
|
+
};
|
|
27
|
+
UserDto = __decorate([
|
|
28
|
+
(0, validation_1.Schema)(exports.UserDtoSchema)
|
|
29
|
+
], UserDto);
|
|
30
|
+
exports.UserDto = UserDto;
|
|
31
|
+
//# sourceMappingURL=user-dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-dto.js","sourceRoot":"","sources":["../../src/dto/user-dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAA6C;AAChC,QAAA,aAAa,GAAG;IAC3B,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACtB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE;QACzD,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;QACxC,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;QAChE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;QACzD,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;KAC5C;IACD,QAAQ,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;CAChC,CAAC;AAGF,IAAa,OAAO,GAApB,MAAa,OAAO;CAYnB,CAAA;AAZY,OAAO;IADnB,IAAA,mBAAM,EAAC,qBAAa,CAAC;GACT,OAAO,CAYnB;AAZY,0BAAO"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './decorators';
|
|
2
|
+
export * from './interfaces';
|
|
3
|
+
export * from './middlewares';
|
|
4
|
+
export * from './policies';
|
|
5
|
+
export * from './controllers/LoginController';
|
|
6
|
+
export * from './controllers/UsersController';
|
|
7
|
+
export * from './transformers';
|
|
8
|
+
export * from './route-args';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
__exportStar(require("./decorators"), exports);
|
|
18
|
+
__exportStar(require("./interfaces"), exports);
|
|
19
|
+
__exportStar(require("./middlewares"), exports);
|
|
20
|
+
__exportStar(require("./policies"), exports);
|
|
21
|
+
__exportStar(require("./controllers/LoginController"), exports);
|
|
22
|
+
__exportStar(require("./controllers/UsersController"), exports);
|
|
23
|
+
__exportStar(require("./transformers"), exports);
|
|
24
|
+
__exportStar(require("./route-args"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,6CAA2B;AAC3B,gEAA8C;AAC9C,gEAA8C;AAC9C,iDAA+B;AAC/B,+CAA6B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface IAclDescriptor {
|
|
2
|
+
/**
|
|
3
|
+
* Resource name
|
|
4
|
+
*/
|
|
5
|
+
Resource: string;
|
|
6
|
+
/**
|
|
7
|
+
* Assigned permission
|
|
8
|
+
*
|
|
9
|
+
* '*' means that to acces resource we only need role with assigned resource
|
|
10
|
+
*/
|
|
11
|
+
Permission: 'readAny' | 'readOwn' | 'updateAny' | 'updateOwn' | 'deleteAny' | 'deleteOwn' | 'createAny' | 'createOwn';
|
|
12
|
+
/**
|
|
13
|
+
* Per routes permissions
|
|
14
|
+
*/
|
|
15
|
+
Routes: Map<string, IAclRoutePermissionDescriptor>;
|
|
16
|
+
}
|
|
17
|
+
export interface IAclRoutePermissionDescriptor {
|
|
18
|
+
/**
|
|
19
|
+
* controller route permission. It overrides acl descriptor options
|
|
20
|
+
*/
|
|
21
|
+
Permission: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import * as express from 'express';
|
|
3
|
+
/**
|
|
4
|
+
* global express middleware that loads user from session
|
|
5
|
+
*/
|
|
6
|
+
export declare function UserFromSession(): (req: express.Request, _res: express.Response, next: express.NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,71 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.UserFromSession = void 0;
|
|
27
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
28
|
+
const di_1 = require("@spinajs/di");
|
|
29
|
+
require("reflect-metadata");
|
|
30
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
31
|
+
const cs = __importStar(require("cookie-signature"));
|
|
32
|
+
const console_1 = require("console");
|
|
33
|
+
const luxon_1 = require("luxon");
|
|
34
|
+
/**
|
|
35
|
+
* global express middleware that loads user from session
|
|
36
|
+
*/
|
|
37
|
+
function UserFromSession() {
|
|
38
|
+
const wrapper = async (req, _res, next) => {
|
|
39
|
+
if (req.cookies.ssid) {
|
|
40
|
+
const secureKey = di_1.DI.get(configuration_1.Configuration).get('http.cookie.secret');
|
|
41
|
+
if (!secureKey) {
|
|
42
|
+
next();
|
|
43
|
+
(0, console_1.assert)(secureKey, 'coockie secure key should be set');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const ssid = cs.unsign(req.cookies.ssid, secureKey);
|
|
47
|
+
if (ssid) {
|
|
48
|
+
const sessionProvider = di_1.DI.has(rbac_1.SessionProvider) ? di_1.DI.get(rbac_1.SessionProvider) : await di_1.DI.resolve(rbac_1.SessionProvider);
|
|
49
|
+
const session = (await sessionProvider.restoreSession(ssid));
|
|
50
|
+
if (session) {
|
|
51
|
+
req.User = new rbac_1.User(session.Data);
|
|
52
|
+
const liveTimeDiff = session.Expiration.diff(luxon_1.DateTime.now());
|
|
53
|
+
if (liveTimeDiff.minutes < 30) {
|
|
54
|
+
await sessionProvider.refreshSession(session);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
req.User = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
next();
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(wrapper, 'name', {
|
|
65
|
+
value: 'userFromSession',
|
|
66
|
+
writable: true,
|
|
67
|
+
});
|
|
68
|
+
return wrapper;
|
|
69
|
+
}
|
|
70
|
+
exports.UserFromSession = UserFromSession;
|
|
71
|
+
//# sourceMappingURL=middlewares.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAmE;AACnE,oCAAiC;AACjC,4BAA0B;AAE1B,0DAAuD;AACvD,qDAAuC;AACvC,qCAAiC;AACjC,iCAAiC;AAEjC;;GAEG;AACH,SAAgB,eAAe;IAC7B,MAAM,OAAO,GAAG,KAAK,EAAE,GAAoB,EAAE,IAAsB,EAAE,IAA0B,EAAE,EAAE;QACjG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;YACpB,MAAM,SAAS,GAAG,OAAE,CAAC,GAAG,CAAC,6BAAa,CAAC,CAAC,GAAG,CAAS,oBAAoB,CAAC,CAAC;YAE1E,IAAI,CAAC,SAAS,EAAE;gBACd,IAAI,EAAE,CAAC;gBACP,IAAA,gBAAM,EAAC,SAAS,EAAE,kCAAkC,CAAC,CAAC;gBACtD,OAAO;aACR;YAED,MAAM,IAAI,GAAmB,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACpE,IAAI,IAAI,EAAE;gBACR,MAAM,eAAe,GAAG,OAAE,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC,CAAC,CAAC,OAAE,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC,CAAC,CAAC,MAAM,OAAE,CAAC,OAAO,CAAC,sBAAe,CAAC,CAAC;gBAC9G,MAAM,OAAO,GAAG,CAAC,MAAM,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,CAAgB,CAAC;gBAC5E,IAAI,OAAO,EAAE;oBACX,GAAG,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;oBAClC,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;oBAC7D,IAAI,YAAY,CAAC,OAAO,GAAG,EAAE,EAAE;wBAC7B,MAAM,eAAe,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;qBAC/C;iBACF;aACF;iBAAM;gBACL,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;aACjB;SACF;QAED,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;IAEF,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE;QACrC,KAAK,EAAE,iBAAiB;QACxB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AApCD,0CAoCC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccessControl } from '@spinajs/rbac';
|
|
2
|
+
import { BasePolicy, IController, IRoute } from '@spinajs/http';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
export declare class AclPolicy extends BasePolicy {
|
|
5
|
+
protected Ac: AccessControl;
|
|
6
|
+
constructor();
|
|
7
|
+
isEnabled(_action: IRoute, _instance: IController): boolean;
|
|
8
|
+
execute(req: express.Request, action: IRoute, instance: IController): Promise<void>;
|
|
9
|
+
}
|
package/lib/policies.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AclPolicy = void 0;
|
|
4
|
+
const http_1 = require("@spinajs/http");
|
|
5
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
6
|
+
const decorators_1 = require("./decorators");
|
|
7
|
+
const di_1 = require("@spinajs/di");
|
|
8
|
+
class AclPolicy extends http_1.BasePolicy {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.Ac = di_1.DI.get('AccessControl');
|
|
12
|
+
}
|
|
13
|
+
isEnabled(_action, _instance) {
|
|
14
|
+
// acl is always on if set
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
async execute(req, action, instance) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const descriptor = Reflect.getMetadata(decorators_1.ACL_CONTROLLER_DESCRIPTOR, instance);
|
|
20
|
+
let permission = (_a = descriptor.Permission) !== null && _a !== void 0 ? _a : '';
|
|
21
|
+
// check if route has its own permission
|
|
22
|
+
if (descriptor.Routes.has(action.Method)) {
|
|
23
|
+
permission = (_b = descriptor.Routes.get(action.Method).Permission) !== null && _b !== void 0 ? _b : '';
|
|
24
|
+
}
|
|
25
|
+
if (!descriptor || !descriptor.Permission) {
|
|
26
|
+
throw new exceptions_1.Forbidden(`no route permission or resources assigned`);
|
|
27
|
+
}
|
|
28
|
+
if (!req.User) {
|
|
29
|
+
throw new exceptions_1.AuthenticationFailed();
|
|
30
|
+
}
|
|
31
|
+
if (!this.Ac.can(req.User.Role.split(',')).resource(descriptor.Resource)[permission]()) {
|
|
32
|
+
throw new exceptions_1.Forbidden(`role(s) ${req.User.Role} does not have permission ${permission} for resource ${descriptor.Resource}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.AclPolicy = AclPolicy;
|
|
37
|
+
//# sourceMappingURL=policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies.js","sourceRoot":"","sources":["../src/policies.ts"],"names":[],"mappings":";;;AACA,wCAAgE;AAEhE,oDAAsE;AACtE,6CAAyD;A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D,8BAmCC"}
|
package/lib/rbac-http.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RouteArgs, IRouteParameter, ParameterType, IRouteCall } from '@spinajs/http';
|
|
2
|
+
import * as express from 'express';
|
|
3
|
+
export declare class UserArg extends RouteArgs {
|
|
4
|
+
get SupportedType(): ParameterType;
|
|
5
|
+
extract(callData: IRouteCall, _param: IRouteParameter, req: express.Request): Promise<{
|
|
6
|
+
CallData: IRouteCall;
|
|
7
|
+
Args: import("@spinajs/rbac/lib").User;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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.UserArg = void 0;
|
|
10
|
+
const http_1 = require("@spinajs/http");
|
|
11
|
+
const di_1 = require("@spinajs/di");
|
|
12
|
+
let UserArg = class UserArg extends http_1.RouteArgs {
|
|
13
|
+
get SupportedType() {
|
|
14
|
+
return http_1.ParameterType.Res;
|
|
15
|
+
}
|
|
16
|
+
async extract(callData, _param, req) {
|
|
17
|
+
return { CallData: callData, Args: req.User };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
UserArg = __decorate([
|
|
21
|
+
(0, di_1.Injectable)()
|
|
22
|
+
], UserArg);
|
|
23
|
+
exports.UserArg = UserArg;
|
|
24
|
+
//# sourceMappingURL=route-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-args.js","sourceRoot":"","sources":["../src/route-args.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wCAAsF;AAEtF,oCAAyC;AAGzC,IAAa,OAAO,GAApB,MAAa,OAAQ,SAAQ,gBAAS;IACpC,IAAW,aAAa;QACtB,OAAO,oBAAa,CAAC,GAAG,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,QAAoB,EAAE,MAAuB,EAAE,GAAoB;QACtF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;CACF,CAAA;AARY,OAAO;IADnB,IAAA,eAAU,GAAE;GACA,OAAO,CAQnB;AARY,0BAAO"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DataTransformer } from '@spinajs/http';
|
|
2
|
+
import { User } from '@spinajs/rbac';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
export interface IUserResult {
|
|
5
|
+
Data: User[] | User;
|
|
6
|
+
Total: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class UserDataTransformer<T> extends DataTransformer<IUserResult, IUserResult | T> {
|
|
9
|
+
get Type(): string;
|
|
10
|
+
transform(data: IUserResult, _request: express.Request): IUserResult | T;
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserDataTransformer = void 0;
|
|
13
|
+
const http_1 = require("@spinajs/http");
|
|
14
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
15
|
+
const di_1 = require("@spinajs/di");
|
|
16
|
+
let UserDataTransformer = class UserDataTransformer extends http_1.DataTransformer {
|
|
17
|
+
get Type() {
|
|
18
|
+
return 'user-model-result';
|
|
19
|
+
}
|
|
20
|
+
transform(data, _request) {
|
|
21
|
+
if (lodash_1.default.isArray(data.Data)) {
|
|
22
|
+
data.Data.forEach((x) => delete x.Password);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
delete data.Data.Password;
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
UserDataTransformer = __decorate([
|
|
31
|
+
(0, di_1.Injectable)()
|
|
32
|
+
], UserDataTransformer);
|
|
33
|
+
exports.UserDataTransformer = UserDataTransformer;
|
|
34
|
+
//# sourceMappingURL=transformers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformers.js","sourceRoot":"","sources":["../src/transformers.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAgD;AAChD,oDAAuB;AAEvB,oCAAyC;AASzC,IAAa,mBAAmB,GAAhC,MAAa,mBAAuB,SAAQ,sBAA6C;IACvF,IAAI,IAAI;QACN,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAEM,SAAS,CAAC,IAAiB,EAAE,QAAyB;QAC3D,IAAI,gBAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;SAC7C;aAAM;YACL,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC3B;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAdY,mBAAmB;IAD/B,IAAA,eAAU,GAAE;GACA,mBAAmB,CAc/B;AAdY,kDAAmB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spinajs/rbac-http",
|
|
3
|
+
"version": "1.2.108",
|
|
4
|
+
"description": "HTTP API for user session & permissions",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"private": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npm run clean && npm run compile",
|
|
9
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
10
|
+
"clean": "",
|
|
11
|
+
"test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
|
|
12
|
+
"coverage": "nyc npm run test",
|
|
13
|
+
"build-docs": "rimraf docs && typedoc --options typedoc.json src/",
|
|
14
|
+
"prepare": "npm run build",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
16
|
+
"lint": "eslint -c .eslintrc.js --ext .ts src --fix",
|
|
17
|
+
"prepublishOnly": "npm test && npm run lint",
|
|
18
|
+
"preversion": "npm run lint",
|
|
19
|
+
"version": "npm run format && git add -A src",
|
|
20
|
+
"postversion": "git push && git push --tags"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib/**/*"
|
|
24
|
+
],
|
|
25
|
+
"types": "lib",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/spinajs/main.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"spinajs",
|
|
32
|
+
"rbac"
|
|
33
|
+
],
|
|
34
|
+
"author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/main)",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/spinajs/main/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/spinajs/main#readme",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@spinajs/configuration": "^1.2.81",
|
|
42
|
+
"@spinajs/di": "^1.2.81",
|
|
43
|
+
"@spinajs/exceptions": "^1.2.81",
|
|
44
|
+
"@spinajs/log": "^1.2.103",
|
|
45
|
+
"@spinajs/orm": "^1.2.108",
|
|
46
|
+
"@spinajs/rbac": "^1.2.108",
|
|
47
|
+
"@spinajs/reflection": "^1.2.103",
|
|
48
|
+
"luxon": "^2.4.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@spinajs/orm-sqlite": "^1.2.108"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "81e996198a9d4dac8970f71181b0f5eaf6070918"
|
|
54
|
+
}
|