identity-admin 1.0.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/README.md +127 -0
- package/lib/Dashboard.d.ts +14 -0
- package/lib/Dashboard.js +84 -0
- package/lib/container/helpers/HelperInversify.d.ts +6 -0
- package/lib/container/helpers/HelperInversify.js +10 -0
- package/lib/container/helpers/HelperTypes.d.ts +5 -0
- package/lib/container/helpers/HelperTypes.js +7 -0
- package/lib/container/index.d.ts +1 -0
- package/lib/container/index.js +14 -0
- package/lib/container/repositories/RepositoryInversify.d.ts +4 -0
- package/lib/container/repositories/RepositoryInversify.js +13 -0
- package/lib/container/repositories/RepositoryTypes.d.ts +4 -0
- package/lib/container/repositories/RepositoryTypes.js +6 -0
- package/lib/container/types.d.ts +8 -0
- package/lib/container/types.js +9 -0
- package/lib/controllers/ActionController.d.ts +8 -0
- package/lib/controllers/ActionController.js +74 -0
- package/lib/controllers/DashboardController.d.ts +36 -0
- package/lib/controllers/DashboardController.js +335 -0
- package/lib/controllers/ResourceController.d.ts +9 -0
- package/lib/controllers/ResourceController.js +95 -0
- package/lib/helpers/ActionsGenerator.d.ts +9 -0
- package/lib/helpers/ActionsGenerator.js +77 -0
- package/lib/helpers/LocalesHelper.d.ts +4 -0
- package/lib/helpers/LocalesHelper.js +73 -0
- package/lib/helpers/ResourceGenerator.d.ts +4 -0
- package/lib/helpers/ResourceGenerator.js +68 -0
- package/lib/helpers/ResourceHelper.d.ts +23 -0
- package/lib/helpers/ResourceHelper.js +274 -0
- package/lib/helpers/SchemaGenerator.d.ts +5 -0
- package/lib/helpers/SchemaGenerator.js +87 -0
- package/lib/helpers/SchemaHelper.d.ts +5 -0
- package/lib/helpers/SchemaHelper.js +21 -0
- package/lib/locales/en.json +11 -0
- package/lib/middlewares/isAuth.d.ts +13 -0
- package/lib/middlewares/isAuth.js +43 -0
- package/lib/models/ModelNames.d.ts +4 -0
- package/lib/models/ModelNames.js +7 -0
- package/lib/models/request-log/IRequestLog.d.ts +22 -0
- package/lib/models/request-log/IRequestLog.js +2 -0
- package/lib/models/request-log/RequestLog.d.ts +3 -0
- package/lib/models/request-log/RequestLog.js +51 -0
- package/lib/repositories/DashboardRepository.d.ts +5 -0
- package/lib/repositories/DashboardRepository.js +12 -0
- package/lib/repositories/Repository.d.ts +68 -0
- package/lib/repositories/Repository.js +212 -0
- package/lib/repositories/RequestLogRepository.d.ts +10 -0
- package/lib/repositories/RequestLogRepository.js +54 -0
- package/lib/repositories/SaveResult.d.ts +14 -0
- package/lib/repositories/SaveResult.js +18 -0
- package/lib/router/index.d.ts +8 -0
- package/lib/router/index.js +95 -0
- package/lib/types/DashbordConfig.d.ts +19 -0
- package/lib/types/DashbordConfig.js +2 -0
- package/lib/types/IResourceFile.d.ts +123 -0
- package/lib/types/IResourceFile.js +2 -0
- package/lib/types/helpers.d.ts +15 -0
- package/lib/types/helpers.js +21 -0
- package/lib/utils/ResourceUtils.d.ts +2 -0
- package/lib/utils/ResourceUtils.js +7 -0
- package/lib/utils/ResponseUtils.d.ts +12 -0
- package/lib/utils/ResponseUtils.js +72 -0
- package/lib/utils/StringUtils.d.ts +9 -0
- package/lib/utils/StringUtils.js +46 -0
- package/lib/view/_redirects +1 -0
- package/lib/view/asset-manifest.json +19 -0
- package/lib/view/assets/bg_card.png +0 -0
- package/lib/view/assets/bg_gradient.jpeg +0 -0
- package/lib/view/assets/icons/delete_icon.svg +3 -0
- package/lib/view/assets/icons/flags/ic_flag_cn.svg +10 -0
- package/lib/view/assets/icons/flags/ic_flag_de.svg +1 -0
- package/lib/view/assets/icons/flags/ic_flag_en.svg +1 -0
- package/lib/view/assets/icons/flags/ic_flag_fr.svg +1 -0
- package/lib/view/assets/icons/flags/ic_flag_kr.svg +1 -0
- package/lib/view/assets/icons/flags/ic_flag_sa.svg +10 -0
- package/lib/view/assets/icons/flags/ic_flag_us.svg +1 -0
- package/lib/view/assets/icons/flags/ic_flag_vn.svg +10 -0
- package/lib/view/assets/icons/info_icon.svg +3 -0
- package/lib/view/assets/icons/navbar/ic_analytics.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_banking.svg +5 -0
- package/lib/view/assets/icons/navbar/ic_blog.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_booking.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_calendar.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_cart.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_chat.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_dashboard.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_ecommerce.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_invoice.svg +4 -0
- package/lib/view/assets/icons/navbar/ic_kanban.svg +8 -0
- package/lib/view/assets/icons/navbar/ic_mail.svg +1 -0
- package/lib/view/assets/icons/navbar/ic_menu_item.svg +9 -0
- package/lib/view/assets/icons/navbar/ic_user.svg +1 -0
- package/lib/view/assets/icons/small_info_icon.svg +3 -0
- package/lib/view/assets/illustrations/Group 16.svg +4 -0
- package/lib/view/assets/illustrations/illustration_components.png +0 -0
- package/lib/view/assets/illustrations/illustration_dashboard.png +0 -0
- package/lib/view/assets/illustrations/illustration_empty_cart.svg +1 -0
- package/lib/view/assets/illustrations/illustration_empty_content.svg +1 -0
- package/lib/view/assets/illustrations/illustration_empty_mail.svg +1 -0
- package/lib/view/assets/illustrations/illustration_invite.png +0 -0
- package/lib/view/assets/illustrations/illustration_login.png +0 -0
- package/lib/view/assets/illustrations/illustration_register.png +0 -0
- package/lib/view/assets/illustrations/logo.svg +5 -0
- package/lib/view/assets/illustrations/welcome_image.png +0 -0
- package/lib/view/assets/overlay.svg +1 -0
- package/lib/view/assets/placeholder.svg +1 -0
- package/lib/view/favicon/android-chrome-192x192.png +0 -0
- package/lib/view/favicon/android-chrome-512x512.png +0 -0
- package/lib/view/favicon/apple-touch-icon-precomposed.png +0 -0
- package/lib/view/favicon/apple-touch-icon.png +0 -0
- package/lib/view/favicon/browserconfig.xml +9 -0
- package/lib/view/favicon/favicon-16x16.png +0 -0
- package/lib/view/favicon/favicon-32x32.png +0 -0
- package/lib/view/favicon/favicon.ico +0 -0
- package/lib/view/favicon/mstile-150x150.png +0 -0
- package/lib/view/favicon/safari-pinned-tab.svg +182 -0
- package/lib/view/favicon/site.webmanifest +19 -0
- package/lib/view/fonts/CircularStd-Bold.otf +0 -0
- package/lib/view/fonts/CircularStd-Book.otf +0 -0
- package/lib/view/fonts/CircularStd-Medium.otf +0 -0
- package/lib/view/fonts/Roboto-Bold.ttf +0 -0
- package/lib/view/fonts/Roboto-Regular.ttf +0 -0
- package/lib/view/fonts/index.css +18 -0
- package/lib/view/index.html +1 -0
- package/lib/view/logo/logo_full.jpg +0 -0
- package/lib/view/logo/logo_full.svg +1 -0
- package/lib/view/logo/logo_single.svg +1 -0
- package/lib/view/manifest.json +20 -0
- package/lib/view/robots.txt +3 -0
- package/lib/view/static/css/main.faf63983.css +2 -0
- package/lib/view/static/css/main.faf63983.css.map +1 -0
- package/lib/view/static/js/13.d8bc0c19.chunk.js +2 -0
- package/lib/view/static/js/13.d8bc0c19.chunk.js.map +1 -0
- package/lib/view/static/js/574.f1fff658.chunk.js +2 -0
- package/lib/view/static/js/574.f1fff658.chunk.js.map +1 -0
- package/lib/view/static/js/678.fddff388.chunk.js +2 -0
- package/lib/view/static/js/678.fddff388.chunk.js.map +1 -0
- package/lib/view/static/js/main.2a2ccfb1.js +3 -0
- package/lib/view/static/js/main.2a2ccfb1.js.LICENSE.txt +223 -0
- package/lib/view/static/js/main.2a2ccfb1.js.map +1 -0
- package/package.json +44 -0
- package/src/Dashboard.ts +74 -0
- package/src/controllers/ActionController.ts +64 -0
- package/src/controllers/DashboardController.ts +388 -0
- package/src/controllers/ResourceController.ts +62 -0
- package/src/helpers/ActionsGenerator.ts +106 -0
- package/src/helpers/ResourceGenerator.ts +90 -0
- package/src/helpers/ResourceHelper.ts +391 -0
- package/src/helpers/SchemaGenerator.ts +120 -0
- package/src/helpers/SchemaHelper.ts +27 -0
- package/src/locales/en.json +11 -0
- package/src/middlewares/isAuth.ts +46 -0
- package/src/models/ModelNames.ts +6 -0
- package/src/models/request-log/IRequestLog.ts +25 -0
- package/src/models/request-log/RequestLog.ts +52 -0
- package/src/repositories/DashboardRepository.ts +11 -0
- package/src/repositories/Repository.ts +269 -0
- package/src/repositories/RequestLogRepository.ts +40 -0
- package/src/repositories/SaveResult.ts +31 -0
- package/src/router/index.ts +91 -0
- package/src/types/DashbordConfig.ts +24 -0
- package/src/types/IResourceFile.ts +240 -0
- package/src/types/helpers.ts +17 -0
- package/src/utils/ResourceUtils.ts +5 -0
- package/src/utils/ResponseUtils.ts +68 -0
- package/src/utils/StringUtils.ts +63 -0
- package/tsconfig.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Identity Admin Dashboard
|
|
2
|
+
[](https://travis-ci.org/joemccann/dillinger)
|
|
3
|
+
|
|
4
|
+
## How to install
|
|
5
|
+
```bash
|
|
6
|
+
npm i identity-admin
|
|
7
|
+
```
|
|
8
|
+
## Features
|
|
9
|
+
- Creating Dashboard with minimal Ui for mongoose models.
|
|
10
|
+
- Provide DashboardController for custom routing and middlewares.
|
|
11
|
+
- Provide multiple dashboard instances with diffrent routes.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Create new ```unAuthenticated``` Dashboard:
|
|
16
|
+
- Create new instance from Dashboard.
|
|
17
|
+
- Provide Resources array of
|
|
18
|
+
resources file.
|
|
19
|
+
- Build the instance after mongoose setup by passing app instance to the build function.
|
|
20
|
+
```Typescript
|
|
21
|
+
const dashboard: Dashboard = new Dashboard({ resources:[ <Resource: IResourceFile> ]);
|
|
22
|
+
```
|
|
23
|
+
```Typescript
|
|
24
|
+
dashboard.build(app);
|
|
25
|
+
```
|
|
26
|
+
## To create new ```Authenticated``` Dashboard:
|
|
27
|
+
- Create new instance from Dashboard.
|
|
28
|
+
- Provide Resources array of
|
|
29
|
+
resources file.
|
|
30
|
+
- Provide authenticate function which take AdminCredentials as parameter and return a promise of boolean or user data.
|
|
31
|
+
- Provide cookiesConfiguration (cookie name and cookie secret).
|
|
32
|
+
- Build the instance after mongoose setup by passing app instance to the build function.
|
|
33
|
+
|
|
34
|
+
```Typescript
|
|
35
|
+
const dashboard = new Dashboard({
|
|
36
|
+
resources: [ UserResource ],
|
|
37
|
+
cookiesConfiguration: {
|
|
38
|
+
cookiesSecret: "cokieieSecret",
|
|
39
|
+
cookieName: "connect.sid"
|
|
40
|
+
},
|
|
41
|
+
authenticate: async (credentials: AdminCredentials) => {
|
|
42
|
+
const user = await Admin.findOne({ email: credentials.email });
|
|
43
|
+
if (user) {
|
|
44
|
+
const matched = await bcrypt.compare(credentials.password, user.encryptedPassword);
|
|
45
|
+
if (matched) {
|
|
46
|
+
return user;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
```Typescript
|
|
54
|
+
dashboard.build(app);
|
|
55
|
+
```
|
|
56
|
+
## To create new ```CustomRoutes``` Dashboard:
|
|
57
|
+
``` This method require to implement your own view and new react app ```
|
|
58
|
+
- Create new controller class with invirsify-express-utils notaitions and extend ActionController.
|
|
59
|
+
- Create new controller class with invirsify-express-utils notaitions and extend ResourceController.
|
|
60
|
+
- Create new controller class with invirsify-express-utils notaitions and extend DashboardController.
|
|
61
|
+
- Provide resource file and repository in super constructor.
|
|
62
|
+
- ``` Following class will create new route /v1/contries ***Now you can pass any auth middlewares you want```
|
|
63
|
+
|
|
64
|
+
```TypeScript
|
|
65
|
+
@controller('/v1/actions', defaultHeaders)
|
|
66
|
+
export default class ActionsController extends ActionController{
|
|
67
|
+
|
|
68
|
+
constructor(
|
|
69
|
+
@inject(TYPES.IResources) private resources: IResourceFile[]) {
|
|
70
|
+
super(resources);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```TypeScript
|
|
76
|
+
@controller('/v1/resources', defaultHeaders)
|
|
77
|
+
export default class ResourcesController extends ResourceController{
|
|
78
|
+
|
|
79
|
+
constructor(
|
|
80
|
+
@inject(TYPES.IResources) private resources: IResourceFile[]) {
|
|
81
|
+
super(resources);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```TypeScript
|
|
87
|
+
@controller('/v1/contries', defaultHeaders)
|
|
88
|
+
export default class CountryController extends DashboardController{
|
|
89
|
+
|
|
90
|
+
constructor(
|
|
91
|
+
@inject(TYPES.ICountryRepository) private countryRepository: CountryRepository,
|
|
92
|
+
@inject(TYPES.ICountryResource) private countryResource: IResourceFile ) {
|
|
93
|
+
|
|
94
|
+
super(CountryResource, countryRepository);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Documentaion:
|
|
100
|
+
```Typescript
|
|
101
|
+
Dashboard(dashBoardConfig: DashboardConfig);
|
|
102
|
+
build(app: Application): void;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Dashboard:
|
|
106
|
+
Dashboard constructor to create new instance from idntity-admin.
|
|
107
|
+
- dashBoardConfig:
|
|
108
|
+
```js
|
|
109
|
+
{
|
|
110
|
+
resources: IResourceFile[]; // Array of resources files.
|
|
111
|
+
rootPath?: string; // optional root path default to /dashboard
|
|
112
|
+
localesOptions?: i18n.ConfigurationOptions; // locales options for custom dashboard
|
|
113
|
+
cookiesConfiguration: CookieConfiguration; // cookies configuration in case of authenticated dashboard
|
|
114
|
+
authenticate?: AuthenticateMiddleWare; // authenticate function used to login the admin.
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
- IResourceFile
|
|
118
|
+
``` For resource file example check```
|
|
119
|
+
[IResourceFile](src/types/IResourceFile.ts)
|
|
120
|
+
|
|
121
|
+
- CookieConfiguration
|
|
122
|
+
```js
|
|
123
|
+
{
|
|
124
|
+
cookiesSecret: string; // cookie secret to handle sessions
|
|
125
|
+
cookieName: string; // cookie name as appeared in browser
|
|
126
|
+
}
|
|
127
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Application } from "express";
|
|
2
|
+
import i18n from "i18n";
|
|
3
|
+
import DashboardConfig from "./types/DashbordConfig";
|
|
4
|
+
export default class Dashboard {
|
|
5
|
+
private dashBoardConfig;
|
|
6
|
+
private DEFAULT_ROOT_PATH;
|
|
7
|
+
constructor(dashBoardConfig: DashboardConfig);
|
|
8
|
+
build(app: Application): void;
|
|
9
|
+
private configureLocalization;
|
|
10
|
+
private buildRouter;
|
|
11
|
+
private configureAuthentication;
|
|
12
|
+
private configureSession;
|
|
13
|
+
static configurBaseLocalization(options: i18n.ConfigurationOptions): void;
|
|
14
|
+
}
|
package/lib/Dashboard.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const express_1 = __importDefault(require("express"));
|
|
26
|
+
const DashboardController_1 = __importDefault(require("./controllers/DashboardController"));
|
|
27
|
+
const router_1 = __importStar(require("./router"));
|
|
28
|
+
const i18n_1 = __importDefault(require("i18n"));
|
|
29
|
+
const ResourceController_1 = __importDefault(require("./controllers/ResourceController"));
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const ActionController_1 = __importDefault(require("./controllers/ActionController"));
|
|
32
|
+
var session = require('express-session');
|
|
33
|
+
var cookieParser = require('cookie-parser');
|
|
34
|
+
class Dashboard {
|
|
35
|
+
constructor(dashBoardConfig) {
|
|
36
|
+
this.dashBoardConfig = dashBoardConfig;
|
|
37
|
+
this.DEFAULT_ROOT_PATH = "/dashboard";
|
|
38
|
+
}
|
|
39
|
+
build(app) {
|
|
40
|
+
this.configureLocalization();
|
|
41
|
+
this.configureAuthentication(app);
|
|
42
|
+
this.buildRouter(app);
|
|
43
|
+
}
|
|
44
|
+
configureLocalization() {
|
|
45
|
+
var _a;
|
|
46
|
+
i18n_1.default.configure((_a = this.dashBoardConfig.localesOptions) !== null && _a !== void 0 ? _a : {
|
|
47
|
+
locales: ["en"],
|
|
48
|
+
directory: __dirname + '/locales',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
buildRouter(app) {
|
|
52
|
+
var _a;
|
|
53
|
+
const dashboardController = new DashboardController_1.default(undefined, undefined, this.dashBoardConfig.resources);
|
|
54
|
+
const resourceController = new ResourceController_1.default(this.dashBoardConfig.resources);
|
|
55
|
+
const actionController = new ActionController_1.default(this.dashBoardConfig.resources);
|
|
56
|
+
const appPath = path_1.default.normalize(path_1.default.join(__dirname, '/view'));
|
|
57
|
+
const router = (0, router_1.default)(dashboardController, resourceController, actionController, this.dashBoardConfig.authenticate);
|
|
58
|
+
app.use(express_1.default.static(appPath));
|
|
59
|
+
(0, router_1.createViewRoute)(router, appPath);
|
|
60
|
+
app.use((_a = this.dashBoardConfig.rootPath) !== null && _a !== void 0 ? _a : this.DEFAULT_ROOT_PATH, router);
|
|
61
|
+
}
|
|
62
|
+
configureAuthentication(app) {
|
|
63
|
+
if (!this.dashBoardConfig.authenticate || !this.dashBoardConfig.cookiesConfiguration) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
app.use(cookieParser());
|
|
67
|
+
this.configureSession(app, this.dashBoardConfig.cookiesConfiguration);
|
|
68
|
+
}
|
|
69
|
+
configureSession(app, cookiesConfiguration) {
|
|
70
|
+
var _a;
|
|
71
|
+
const rootPath = (_a = this.dashBoardConfig.rootPath) !== null && _a !== void 0 ? _a : this.DEFAULT_ROOT_PATH;
|
|
72
|
+
app.use(`${rootPath}`, session({
|
|
73
|
+
secret: cookiesConfiguration.cookiesSecret,
|
|
74
|
+
resave: false,
|
|
75
|
+
saveUninitialized: false,
|
|
76
|
+
name: cookiesConfiguration.cookieName,
|
|
77
|
+
cookie: { path: `${rootPath}`, httpOnly: true }
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
static configurBaseLocalization(options) {
|
|
81
|
+
i18n_1.default.configure(options);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.default = Dashboard;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Container } from 'inversify';
|
|
2
|
+
import { IResourceFile } from '../../types/IResourceFile';
|
|
3
|
+
export default class HelperInversify {
|
|
4
|
+
static register(container: Container): void;
|
|
5
|
+
static registerResources(container: Container, resources: IResourceFile[]): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class HelperInversify {
|
|
4
|
+
static register(container) {
|
|
5
|
+
// container.bind<IResourceFile[]>(TYPES.Resources).toConstantValue([]);
|
|
6
|
+
}
|
|
7
|
+
static registerResources(container, resources) {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = HelperInversify;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// let weapons = new ContainerModule(
|
|
4
|
+
// (
|
|
5
|
+
// bind: interfaces.Bind,
|
|
6
|
+
// unbind: interfaces.Unbind,
|
|
7
|
+
// isBound: interfaces.IsBound,
|
|
8
|
+
// rebind: interfaces.Rebind
|
|
9
|
+
// ) => {
|
|
10
|
+
// bind<Katana>("Katana").to(Katana);
|
|
11
|
+
// bind<Shuriken>("Shuriken").to(Shuriken);
|
|
12
|
+
// }
|
|
13
|
+
// );
|
|
14
|
+
// export default container;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const RequestLogRepository_1 = __importDefault(require("../../repositories/RequestLogRepository"));
|
|
7
|
+
const types_1 = __importDefault(require("../types"));
|
|
8
|
+
class RepositoryInversify {
|
|
9
|
+
static register(container) {
|
|
10
|
+
container.bind(types_1.default.IRequestLogRepository).to(RequestLogRepository_1.default);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = RepositoryInversify;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const HelperTypes_1 = __importDefault(require("./helpers/HelperTypes"));
|
|
7
|
+
const RepositoryTypes_1 = __importDefault(require("./repositories/RepositoryTypes"));
|
|
8
|
+
const TYPES = Object.assign(Object.assign(Object.assign({}, HelperTypes_1.default), RepositoryTypes_1.default), { DashboardController: Symbol.for('dashboardController'), ResourceController: Symbol.for('resourceController') });
|
|
9
|
+
exports.default = TYPES;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Response } from 'express';
|
|
2
|
+
import { IRequest } from '../middlewares/isAuth';
|
|
3
|
+
import { IResourceFile } from '../types/IResourceFile';
|
|
4
|
+
export default class ActionController {
|
|
5
|
+
private resources;
|
|
6
|
+
constructor(resources: IResourceFile[]);
|
|
7
|
+
execute(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
const inversify_express_utils_1 = require("inversify-express-utils");
|
|
25
|
+
const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
|
|
26
|
+
const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
|
|
27
|
+
const Repository_1 = __importDefault(require("../repositories/Repository"));
|
|
28
|
+
const ResourceUtils_1 = require("../utils/ResourceUtils");
|
|
29
|
+
class ActionController {
|
|
30
|
+
constructor(resources) {
|
|
31
|
+
this.resources = resources;
|
|
32
|
+
}
|
|
33
|
+
execute(req, res) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const record = req.body.record;
|
|
37
|
+
const modelName = req.body.modelName;
|
|
38
|
+
const resource = (0, ResourceUtils_1.getResource)(modelName, this.resources);
|
|
39
|
+
if (!resource) {
|
|
40
|
+
return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
|
|
41
|
+
}
|
|
42
|
+
const repository = new Repository_1.default(resource.properties.resource);
|
|
43
|
+
const actionKey = req.params.actionKey;
|
|
44
|
+
const currentUser = req.user;
|
|
45
|
+
var response = {};
|
|
46
|
+
const data = {
|
|
47
|
+
record,
|
|
48
|
+
currentUser,
|
|
49
|
+
resource: {
|
|
50
|
+
name: modelName,
|
|
51
|
+
path: StringUtils_1.default.lowerCaseFirstLetter(modelName),
|
|
52
|
+
repository
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const extraActions = (_b = (_a = resource.properties.actions) === null || _a === void 0 ? void 0 : _a.extras) !== null && _b !== void 0 ? _b : [];
|
|
56
|
+
for (var i = 0; i < extraActions.length; i++) {
|
|
57
|
+
const extraAction = extraActions[i];
|
|
58
|
+
if (extraAction.key === actionKey) {
|
|
59
|
+
response = yield extraAction.handler(req, res, data);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return ResponseUtils_1.default.send(res, 200, 'Ok', {
|
|
64
|
+
response
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, inversify_express_utils_1.httpPost)('/execute/:actionKey'),
|
|
71
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
72
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
73
|
+
], ActionController.prototype, "execute", null);
|
|
74
|
+
exports.default = ActionController;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Response } from 'express';
|
|
2
|
+
import { Document } from 'mongoose';
|
|
3
|
+
import { IResourceFile } from '../types/IResourceFile';
|
|
4
|
+
import { IDashboardRepository } from '../repositories/Repository';
|
|
5
|
+
import { IRequest } from '../middlewares/isAuth';
|
|
6
|
+
export interface PaginateParams {
|
|
7
|
+
page: number;
|
|
8
|
+
perPage: number;
|
|
9
|
+
}
|
|
10
|
+
export default class DashboardController {
|
|
11
|
+
private resource?;
|
|
12
|
+
private repository?;
|
|
13
|
+
private resources?;
|
|
14
|
+
protected static DEFAULT_PAGE: number;
|
|
15
|
+
protected static DEFAULT_PER_PAGE: number;
|
|
16
|
+
constructor(resource?: IResourceFile, repository?: IDashboardRepository);
|
|
17
|
+
constructor(resource?: IResourceFile, repository?: IDashboardRepository, resources?: IResourceFile[]);
|
|
18
|
+
protected validateRequest(req: IRequest, res: Response): boolean;
|
|
19
|
+
protected paginateParams(request: IRequest): PaginateParams;
|
|
20
|
+
protected getSearchableSubStringFilter(resource: IResourceFile, filter: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}, subString: RegExp): {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
protected getScopeFilter(filter: {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}, scope: string): {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
protected getVisibileExtrsActions(currentUser: Document, record: any, resource: any, repository: any, modelName: string): Promise<any[] | undefined>;
|
|
31
|
+
index(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
32
|
+
create(req: IRequest, res: Response): Promise<void>;
|
|
33
|
+
update(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
34
|
+
show(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
35
|
+
delete(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
36
|
+
}
|