identity-admin 1.26.13 → 1.26.14

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 CHANGED
@@ -1,35 +1,42 @@
1
1
  # Identity Admin Dashboard
2
+
2
3
  [![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)
3
4
 
4
5
  ## How to install
6
+
5
7
  ```bash
6
8
  npm i identity-admin
7
9
  ```
10
+
8
11
  ## Features
12
+
9
13
  - Creating Dashboard with minimal Ui for mongoose models.
10
14
  - Provide DashboardController for custom routing and middlewares.
11
15
  - Provide multiple dashboard instances with diffrent routes.
12
16
 
17
+ ## Create new `unAuthenticated` Dashboard:
13
18
 
14
-
15
- ## Create new ```unAuthenticated``` Dashboard:
16
19
  - 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
+ - Provide Resources array of
21
+ resources file.
22
+ - Build the instance after mongoose setup by passing app instance to the build function.
23
+
20
24
  ```Typescript
21
25
  const dashboard: Dashboard = new Dashboard({ resources:[ <Resource: IResourceFile> ]);
22
26
  ```
27
+
23
28
  ```Typescript
24
29
  dashboard.build(app);
25
30
  ```
26
- ## To create new ```Authenticated``` Dashboard:
31
+
32
+ ## To create new `Authenticated` Dashboard:
33
+
27
34
  - Create new instance from Dashboard.
28
- - Provide Resources array of
29
- resources file.
35
+ - Provide Resources array of
36
+ resources file.
30
37
  - Provide authenticate function which take AdminCredentials as parameter and return a promise of boolean or user data.
31
38
  - Provide cookiesConfiguration (cookie name and cookie secret).
32
- - Build the instance after mongoose setup by passing app instance to the build function.
39
+ - Build the instance after mongoose setup by passing app instance to the build function.
33
40
 
34
41
  ```Typescript
35
42
  const dashboard = new Dashboard({
@@ -50,21 +57,25 @@ const dashboard = new Dashboard({
50
57
  }
51
58
  })
52
59
  ```
60
+
53
61
  ```Typescript
54
62
  dashboard.build(app);
55
63
  ```
56
- ## To create new ```CustomRoutes``` Dashboard:
57
- ``` This method require to implement your own view and new react app ```
64
+
65
+ ## To create new `CustomRoutes` Dashboard:
66
+
67
+ `This method require to implement your own view and new react app`
68
+
58
69
  - Create new controller class with invirsify-express-utils notaitions and extend ActionController.
59
70
  - Create new controller class with invirsify-express-utils notaitions and extend ResourceController.
60
71
  - Create new controller class with invirsify-express-utils notaitions and extend DashboardController.
61
72
  - 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```
73
+ - ` Following class will create new route /v1/contries ***Now you can pass any auth middlewares you want`
63
74
 
64
75
  ```TypeScript
65
76
  @controller('/v1/actions', defaultHeaders)
66
77
  export default class ActionsController extends ActionController{
67
-
78
+
68
79
  constructor(
69
80
  @inject(TYPES.IResources) private resources: IResourceFile[]) {
70
81
  super(resources);
@@ -75,7 +86,7 @@ export default class ActionsController extends ActionController{
75
86
  ```TypeScript
76
87
  @controller('/v1/resources', defaultHeaders)
77
88
  export default class ResourcesController extends ResourceController{
78
-
89
+
79
90
  constructor(
80
91
  @inject(TYPES.IResources) private resources: IResourceFile[]) {
81
92
  super(resources);
@@ -86,7 +97,7 @@ export default class ResourcesController extends ResourceController{
86
97
  ```TypeScript
87
98
  @controller('/v1/contries', defaultHeaders)
88
99
  export default class CountryController extends DashboardController{
89
-
100
+
90
101
  constructor(
91
102
  @inject(TYPES.ICountryRepository) private countryRepository: CountryRepository,
92
103
  @inject(TYPES.ICountryResource) private countryResource: IResourceFile ) {
@@ -97,28 +108,34 @@ export default class CountryController extends DashboardController{
97
108
  ```
98
109
 
99
110
  ## Documentaion:
111
+
100
112
  ```Typescript
101
113
  Dashboard(dashBoardConfig: DashboardConfig);
102
114
  build(app: Application): void;
103
115
  ```
104
116
 
105
117
  #### Dashboard:
118
+
106
119
  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
+ - dashBoardConfig:
122
+
123
+ ```js
124
+ {
125
+ resources: IResourceFile[]; // Array of resources files.
126
+ rootPath?: string; // optional root path default to /dashboard
127
+ localesOptions?: i18n.ConfigurationOptions; // locales options for custom dashboard
128
+ cookiesConfiguration: CookieConfiguration; // cookies configuration in case of authenticated dashboard
129
+ authenticate?: AuthenticateMiddleWare; // authenticate function used to login the admin.
130
+ }
131
+ ```
132
+
133
+ - IResourceFile
134
+ ` For resource file example check`
135
+ [IResourceFile](src/types/IResourceFile.ts)
120
136
 
121
137
  - CookieConfiguration
138
+
122
139
  ```js
123
140
  {
124
141
  cookiesSecret: string; // cookie secret to handle sessions
@@ -127,9 +144,12 @@ Dashboard constructor to create new instance from idntity-admin.
127
144
  ```
128
145
 
129
146
  ## Admin Notifications:
130
- ``` To add admin notifications in your project you should add the following ```
147
+
148
+ `To add admin notifications in your project you should add the following`
149
+
131
150
  - Enable the admin notifications in the configuration file of the dashboard.
132
- > Configuration.ts
151
+ > Configuration.ts
152
+
133
153
  ```Typescript
134
154
  import { IConfiguartionFile } from "identity-admin/lib/types/IConfigurationFile";
135
155
 
@@ -139,19 +159,24 @@ export const configuration: IConfiguartionFile = {
139
159
  adminNotifications: true // enable admin notifications
140
160
  }
141
161
  ```
162
+
142
163
  - Add these lines for the admin notification repository in the inversify container.
143
- > RepositoryTypes.ts
164
+ > RepositoryTypes.ts
165
+
144
166
  ```Typescript
145
167
  IAdminNotificationRepository: Symbol.for('IAdminNotificationRepository')
146
168
 
147
169
  ```
170
+
148
171
  > RepositoryInversify.ts
172
+
149
173
  ```Typescript
150
174
  container.bind<IAdminNotificationRepository>(TYPES.IAdminNotificationRepository).to(AdminNotificationRepository);
151
175
 
152
176
  ```
153
- - Create new dashboard controller for the admin notifications.
154
- > AdminNotificationController.ts
177
+
178
+ - Create new dashboard controller for the admin notifications CRUD operations and another controller for the notifications services.
179
+ > AdminNotificationController.ts
155
180
 
156
181
  ```TypeScript
157
182
  import { controller } from "inversify-express-utils";
@@ -180,14 +205,35 @@ export default class DashboardAdminNotificationController extends DashboardContr
180
205
 
181
206
  ```
182
207
 
183
- - Import this controller in the index file of the controllers folder.
184
- > index.ts
208
+ > DashboardNotifications.ts
209
+
210
+ ```TypeScript
211
+ import { defaultHeaders, isSessionAuth } from "@pbb/middlewares/isAuth";
212
+ import { controller } from "inversify-express-utils";
213
+
214
+ import NotificationController from "identity-admin/lib/controllers/AdminNotificationController";
215
+
216
+ @controller("/v1/admin/notifications", isSessionAuth, defaultHeaders) // You can change the base route as your need.
217
+ export default class DashboardNotificationController extends NotificationController {
218
+ constructor() {
219
+ super();
220
+ }
221
+ }
222
+
223
+
224
+ ```
225
+
226
+ - Import these 2 controllers in the index file of the controllers folder.
227
+ > index.ts
228
+
185
229
  ```Typescript
186
230
  import './AdminNotificationController'
231
+ import './DashboardNotifications';
187
232
  ```
188
233
 
189
234
  - Add the resource file of the admin notifications in your index file of the resources folder.
190
- > index.ts
235
+ > index.ts
236
+
191
237
  ```Typescript
192
238
  // other imports
193
239
  import AdminNotificationsResource from 'identity-admin/lib/resources/AdminNotificationsResource'
@@ -203,7 +249,8 @@ const resources: IResourceFile[] = [
203
249
  ```
204
250
 
205
251
  #### Add new notification:
206
- ``` To add a new notification just call the AdminNotificationCreation class as below ```
252
+
253
+ `To add a new notification just call the AdminNotificationCreation class as below`
207
254
 
208
255
  ```Typescript
209
256
 
@@ -222,4 +269,4 @@ const record = await AdminNotificationCreation.insert({
222
269
 
223
270
  - In case you choose **NotificationNavigationType.LIST** then you should provide a model name to be navigated to
224
271
  - In case you choose **NotificationNavigationType.SHOW** then you should provide a model name to be navigated to and the relatedId of the record to be shown
225
- - In case you choose **NotificationNavigationType.EXTERNAL_LINK** then you should provide the external link
272
+ - In case you choose **NotificationNavigationType.EXTERNAL_LINK** then you should provide the external link
@@ -1,7 +1,8 @@
1
1
  import { Response } from 'express';
2
2
  import { IRequest } from '../middlewares/isAuth';
3
- export default class AdminNotificationController {
3
+ export default class DashboardNotificationController {
4
4
  constructor();
5
5
  index(req: IRequest, res: Response): Promise<Response<any, Record<string, any>>>;
6
- update(req: IRequest, res: Response): Promise<void>;
6
+ markOneRead(req: IRequest, res: Response): Promise<void>;
7
+ markAllRead(req: IRequest, res: Response): Promise<void>;
7
8
  }
@@ -24,18 +24,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  const inversify_express_utils_1 = require("inversify-express-utils");
25
25
  const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
26
26
  const inversify_1 = require("inversify");
27
- let AdminNotificationController = class AdminNotificationController {
27
+ const AdminNotificationFetcher_1 = require("../helpers/AdminNotifications/AdminNotificationFetcher");
28
+ const AdminNotification_1 = __importDefault(require("../models/adminNotification/AdminNotification"));
29
+ let DashboardNotificationController = class DashboardNotificationController {
28
30
  constructor() { }
29
31
  index(req, res) {
30
32
  return __awaiter(this, void 0, void 0, function* () {
31
- // var notifications: IDashboardNotifications[] = await this.dashboardNotificationsService.getNotifications();
32
- // notifications.sort(compare);
33
- return ResponseUtils_1.default.send(res, 200, 'OK', []);
33
+ const notifications = yield AdminNotificationFetcher_1.AdminNotificationFetcher.fetchNotifications();
34
+ return ResponseUtils_1.default.send(res, 200, 'OK', notifications);
34
35
  });
35
36
  }
36
- update(req, res) {
37
+ markOneRead(req, res) {
37
38
  return __awaiter(this, void 0, void 0, function* () {
38
- //const adminNotifications = await AdminNotification.updateMany({ isRead: false }, { $set: { isRead: true } });
39
+ const { id } = req.params;
40
+ yield AdminNotification_1.default.updateOne({ _id: id }, { isRead: true });
41
+ return ResponseUtils_1.default.ok(res, {});
42
+ });
43
+ }
44
+ markAllRead(req, res) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ yield AdminNotification_1.default.updateMany({ isRead: false }, { $set: { isRead: true } });
39
47
  return ResponseUtils_1.default.ok(res, {});
40
48
  });
41
49
  }
@@ -44,13 +52,18 @@ __decorate([
44
52
  (0, inversify_express_utils_1.httpGet)('/'),
45
53
  __param(0, (0, inversify_express_utils_1.request)()),
46
54
  __param(1, (0, inversify_express_utils_1.response)())
47
- ], AdminNotificationController.prototype, "index", null);
55
+ ], DashboardNotificationController.prototype, "index", null);
56
+ __decorate([
57
+ (0, inversify_express_utils_1.httpPost)('/markAsRead/:id'),
58
+ __param(0, (0, inversify_express_utils_1.request)()),
59
+ __param(1, (0, inversify_express_utils_1.response)())
60
+ ], DashboardNotificationController.prototype, "markOneRead", null);
48
61
  __decorate([
49
62
  (0, inversify_express_utils_1.httpPost)('/markAllAsRead'),
50
63
  __param(0, (0, inversify_express_utils_1.request)()),
51
64
  __param(1, (0, inversify_express_utils_1.response)())
52
- ], AdminNotificationController.prototype, "update", null);
53
- AdminNotificationController = __decorate([
65
+ ], DashboardNotificationController.prototype, "markAllRead", null);
66
+ DashboardNotificationController = __decorate([
54
67
  (0, inversify_1.injectable)()
55
- ], AdminNotificationController);
56
- exports.default = AdminNotificationController;
68
+ ], DashboardNotificationController);
69
+ exports.default = DashboardNotificationController;
@@ -0,0 +1,51 @@
1
+ /// <reference types="mongoose" />
2
+ /// <reference types="mongoose" />
3
+ /// <reference types="mongoose" />
4
+ /// <reference types="mongoose" />
5
+ /// <reference types="mongoose" />
6
+ /// <reference types="mongoose" />
7
+ /// <reference types="mongoose" />
8
+ /// <reference types="mongoose" />
9
+ /// <reference types="mongoose" />
10
+ /// <reference types="mongoose" />
11
+ /// <reference types="mongoose" />
12
+ /// <reference types="mongoose" />
13
+ /// <reference types="mongoose" />
14
+ /// <reference types="mongoose" />
15
+ /// <reference types="mongoose" />
16
+ /// <reference types="mongoose" />
17
+ /// <reference types="mongoose" />
18
+ /// <reference types="mongoose" />
19
+ /// <reference types="mongoose" />
20
+ /// <reference types="mongoose" />
21
+ /// <reference types="mongoose" />
22
+ /// <reference types="mongoose" />
23
+ /// <reference types="mongoose" />
24
+ /// <reference types="mongoose" />
25
+ /// <reference types="passport-local-mongoose" />
26
+ /// <reference types="mongoose" />
27
+ import { AdminNotificationNavigationType, AdminNotificationTypePriority } from '../../models/adminNotification/IAdminNotification';
28
+ export interface IMappedAdminNotification {
29
+ id: string;
30
+ text: string;
31
+ createdAt: Date;
32
+ clickable: boolean;
33
+ redirectUrl?: string;
34
+ redirectUrlType: AdminNotificationNavigationType;
35
+ isRead: boolean;
36
+ priority: AdminNotificationTypePriority;
37
+ type?: string;
38
+ }
39
+ export declare class AdminNotificationFetcher {
40
+ static fetchNotifications(): Promise<{
41
+ id: import("mongoose").Types.ObjectId;
42
+ text: string;
43
+ createdAt: Date;
44
+ clickable: boolean;
45
+ redirectUrl: String | undefined;
46
+ redirectUrlType: AdminNotificationNavigationType | undefined;
47
+ isRead: boolean | undefined;
48
+ priority: AdminNotificationTypePriority | undefined;
49
+ type: string | undefined;
50
+ }[]>;
51
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AdminNotificationFetcher = void 0;
16
+ const AdminNotification_1 = __importDefault(require("../../models/adminNotification/AdminNotification"));
17
+ const IAdminNotification_1 = require("../../models/adminNotification/IAdminNotification");
18
+ class AdminNotificationFetcher {
19
+ static fetchNotifications() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const notifications = yield AdminNotification_1.default.find({ isRead: false }).sort({ createdAt: -1 });
22
+ const mappedNotifications = notifications.map((notification) => {
23
+ return {
24
+ id: notification._id,
25
+ text: notification.title,
26
+ createdAt: notification.createdAt,
27
+ clickable: notification.redirectUrlType === IAdminNotification_1.AdminNotificationNavigationType.NONE ? false : true,
28
+ redirectUrl: notification.redirectUrl,
29
+ redirectUrlType: notification.redirectUrlType,
30
+ isRead: notification.isRead,
31
+ priority: notification.priority,
32
+ type: notification.type,
33
+ };
34
+ });
35
+ return mappedNotifications;
36
+ });
37
+ }
38
+ }
39
+ exports.AdminNotificationFetcher = AdminNotificationFetcher;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.26.13",
3
+ "version": "1.26.14",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",