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.
Files changed (167) hide show
  1. package/README.md +127 -0
  2. package/lib/Dashboard.d.ts +14 -0
  3. package/lib/Dashboard.js +84 -0
  4. package/lib/container/helpers/HelperInversify.d.ts +6 -0
  5. package/lib/container/helpers/HelperInversify.js +10 -0
  6. package/lib/container/helpers/HelperTypes.d.ts +5 -0
  7. package/lib/container/helpers/HelperTypes.js +7 -0
  8. package/lib/container/index.d.ts +1 -0
  9. package/lib/container/index.js +14 -0
  10. package/lib/container/repositories/RepositoryInversify.d.ts +4 -0
  11. package/lib/container/repositories/RepositoryInversify.js +13 -0
  12. package/lib/container/repositories/RepositoryTypes.d.ts +4 -0
  13. package/lib/container/repositories/RepositoryTypes.js +6 -0
  14. package/lib/container/types.d.ts +8 -0
  15. package/lib/container/types.js +9 -0
  16. package/lib/controllers/ActionController.d.ts +8 -0
  17. package/lib/controllers/ActionController.js +74 -0
  18. package/lib/controllers/DashboardController.d.ts +36 -0
  19. package/lib/controllers/DashboardController.js +335 -0
  20. package/lib/controllers/ResourceController.d.ts +9 -0
  21. package/lib/controllers/ResourceController.js +95 -0
  22. package/lib/helpers/ActionsGenerator.d.ts +9 -0
  23. package/lib/helpers/ActionsGenerator.js +77 -0
  24. package/lib/helpers/LocalesHelper.d.ts +4 -0
  25. package/lib/helpers/LocalesHelper.js +73 -0
  26. package/lib/helpers/ResourceGenerator.d.ts +4 -0
  27. package/lib/helpers/ResourceGenerator.js +68 -0
  28. package/lib/helpers/ResourceHelper.d.ts +23 -0
  29. package/lib/helpers/ResourceHelper.js +274 -0
  30. package/lib/helpers/SchemaGenerator.d.ts +5 -0
  31. package/lib/helpers/SchemaGenerator.js +87 -0
  32. package/lib/helpers/SchemaHelper.d.ts +5 -0
  33. package/lib/helpers/SchemaHelper.js +21 -0
  34. package/lib/locales/en.json +11 -0
  35. package/lib/middlewares/isAuth.d.ts +13 -0
  36. package/lib/middlewares/isAuth.js +43 -0
  37. package/lib/models/ModelNames.d.ts +4 -0
  38. package/lib/models/ModelNames.js +7 -0
  39. package/lib/models/request-log/IRequestLog.d.ts +22 -0
  40. package/lib/models/request-log/IRequestLog.js +2 -0
  41. package/lib/models/request-log/RequestLog.d.ts +3 -0
  42. package/lib/models/request-log/RequestLog.js +51 -0
  43. package/lib/repositories/DashboardRepository.d.ts +5 -0
  44. package/lib/repositories/DashboardRepository.js +12 -0
  45. package/lib/repositories/Repository.d.ts +68 -0
  46. package/lib/repositories/Repository.js +212 -0
  47. package/lib/repositories/RequestLogRepository.d.ts +10 -0
  48. package/lib/repositories/RequestLogRepository.js +54 -0
  49. package/lib/repositories/SaveResult.d.ts +14 -0
  50. package/lib/repositories/SaveResult.js +18 -0
  51. package/lib/router/index.d.ts +8 -0
  52. package/lib/router/index.js +95 -0
  53. package/lib/types/DashbordConfig.d.ts +19 -0
  54. package/lib/types/DashbordConfig.js +2 -0
  55. package/lib/types/IResourceFile.d.ts +123 -0
  56. package/lib/types/IResourceFile.js +2 -0
  57. package/lib/types/helpers.d.ts +15 -0
  58. package/lib/types/helpers.js +21 -0
  59. package/lib/utils/ResourceUtils.d.ts +2 -0
  60. package/lib/utils/ResourceUtils.js +7 -0
  61. package/lib/utils/ResponseUtils.d.ts +12 -0
  62. package/lib/utils/ResponseUtils.js +72 -0
  63. package/lib/utils/StringUtils.d.ts +9 -0
  64. package/lib/utils/StringUtils.js +46 -0
  65. package/lib/view/_redirects +1 -0
  66. package/lib/view/asset-manifest.json +19 -0
  67. package/lib/view/assets/bg_card.png +0 -0
  68. package/lib/view/assets/bg_gradient.jpeg +0 -0
  69. package/lib/view/assets/icons/delete_icon.svg +3 -0
  70. package/lib/view/assets/icons/flags/ic_flag_cn.svg +10 -0
  71. package/lib/view/assets/icons/flags/ic_flag_de.svg +1 -0
  72. package/lib/view/assets/icons/flags/ic_flag_en.svg +1 -0
  73. package/lib/view/assets/icons/flags/ic_flag_fr.svg +1 -0
  74. package/lib/view/assets/icons/flags/ic_flag_kr.svg +1 -0
  75. package/lib/view/assets/icons/flags/ic_flag_sa.svg +10 -0
  76. package/lib/view/assets/icons/flags/ic_flag_us.svg +1 -0
  77. package/lib/view/assets/icons/flags/ic_flag_vn.svg +10 -0
  78. package/lib/view/assets/icons/info_icon.svg +3 -0
  79. package/lib/view/assets/icons/navbar/ic_analytics.svg +1 -0
  80. package/lib/view/assets/icons/navbar/ic_banking.svg +5 -0
  81. package/lib/view/assets/icons/navbar/ic_blog.svg +1 -0
  82. package/lib/view/assets/icons/navbar/ic_booking.svg +1 -0
  83. package/lib/view/assets/icons/navbar/ic_calendar.svg +1 -0
  84. package/lib/view/assets/icons/navbar/ic_cart.svg +1 -0
  85. package/lib/view/assets/icons/navbar/ic_chat.svg +1 -0
  86. package/lib/view/assets/icons/navbar/ic_dashboard.svg +1 -0
  87. package/lib/view/assets/icons/navbar/ic_ecommerce.svg +1 -0
  88. package/lib/view/assets/icons/navbar/ic_invoice.svg +4 -0
  89. package/lib/view/assets/icons/navbar/ic_kanban.svg +8 -0
  90. package/lib/view/assets/icons/navbar/ic_mail.svg +1 -0
  91. package/lib/view/assets/icons/navbar/ic_menu_item.svg +9 -0
  92. package/lib/view/assets/icons/navbar/ic_user.svg +1 -0
  93. package/lib/view/assets/icons/small_info_icon.svg +3 -0
  94. package/lib/view/assets/illustrations/Group 16.svg +4 -0
  95. package/lib/view/assets/illustrations/illustration_components.png +0 -0
  96. package/lib/view/assets/illustrations/illustration_dashboard.png +0 -0
  97. package/lib/view/assets/illustrations/illustration_empty_cart.svg +1 -0
  98. package/lib/view/assets/illustrations/illustration_empty_content.svg +1 -0
  99. package/lib/view/assets/illustrations/illustration_empty_mail.svg +1 -0
  100. package/lib/view/assets/illustrations/illustration_invite.png +0 -0
  101. package/lib/view/assets/illustrations/illustration_login.png +0 -0
  102. package/lib/view/assets/illustrations/illustration_register.png +0 -0
  103. package/lib/view/assets/illustrations/logo.svg +5 -0
  104. package/lib/view/assets/illustrations/welcome_image.png +0 -0
  105. package/lib/view/assets/overlay.svg +1 -0
  106. package/lib/view/assets/placeholder.svg +1 -0
  107. package/lib/view/favicon/android-chrome-192x192.png +0 -0
  108. package/lib/view/favicon/android-chrome-512x512.png +0 -0
  109. package/lib/view/favicon/apple-touch-icon-precomposed.png +0 -0
  110. package/lib/view/favicon/apple-touch-icon.png +0 -0
  111. package/lib/view/favicon/browserconfig.xml +9 -0
  112. package/lib/view/favicon/favicon-16x16.png +0 -0
  113. package/lib/view/favicon/favicon-32x32.png +0 -0
  114. package/lib/view/favicon/favicon.ico +0 -0
  115. package/lib/view/favicon/mstile-150x150.png +0 -0
  116. package/lib/view/favicon/safari-pinned-tab.svg +182 -0
  117. package/lib/view/favicon/site.webmanifest +19 -0
  118. package/lib/view/fonts/CircularStd-Bold.otf +0 -0
  119. package/lib/view/fonts/CircularStd-Book.otf +0 -0
  120. package/lib/view/fonts/CircularStd-Medium.otf +0 -0
  121. package/lib/view/fonts/Roboto-Bold.ttf +0 -0
  122. package/lib/view/fonts/Roboto-Regular.ttf +0 -0
  123. package/lib/view/fonts/index.css +18 -0
  124. package/lib/view/index.html +1 -0
  125. package/lib/view/logo/logo_full.jpg +0 -0
  126. package/lib/view/logo/logo_full.svg +1 -0
  127. package/lib/view/logo/logo_single.svg +1 -0
  128. package/lib/view/manifest.json +20 -0
  129. package/lib/view/robots.txt +3 -0
  130. package/lib/view/static/css/main.faf63983.css +2 -0
  131. package/lib/view/static/css/main.faf63983.css.map +1 -0
  132. package/lib/view/static/js/13.d8bc0c19.chunk.js +2 -0
  133. package/lib/view/static/js/13.d8bc0c19.chunk.js.map +1 -0
  134. package/lib/view/static/js/574.f1fff658.chunk.js +2 -0
  135. package/lib/view/static/js/574.f1fff658.chunk.js.map +1 -0
  136. package/lib/view/static/js/678.fddff388.chunk.js +2 -0
  137. package/lib/view/static/js/678.fddff388.chunk.js.map +1 -0
  138. package/lib/view/static/js/main.2a2ccfb1.js +3 -0
  139. package/lib/view/static/js/main.2a2ccfb1.js.LICENSE.txt +223 -0
  140. package/lib/view/static/js/main.2a2ccfb1.js.map +1 -0
  141. package/package.json +44 -0
  142. package/src/Dashboard.ts +74 -0
  143. package/src/controllers/ActionController.ts +64 -0
  144. package/src/controllers/DashboardController.ts +388 -0
  145. package/src/controllers/ResourceController.ts +62 -0
  146. package/src/helpers/ActionsGenerator.ts +106 -0
  147. package/src/helpers/ResourceGenerator.ts +90 -0
  148. package/src/helpers/ResourceHelper.ts +391 -0
  149. package/src/helpers/SchemaGenerator.ts +120 -0
  150. package/src/helpers/SchemaHelper.ts +27 -0
  151. package/src/locales/en.json +11 -0
  152. package/src/middlewares/isAuth.ts +46 -0
  153. package/src/models/ModelNames.ts +6 -0
  154. package/src/models/request-log/IRequestLog.ts +25 -0
  155. package/src/models/request-log/RequestLog.ts +52 -0
  156. package/src/repositories/DashboardRepository.ts +11 -0
  157. package/src/repositories/Repository.ts +269 -0
  158. package/src/repositories/RequestLogRepository.ts +40 -0
  159. package/src/repositories/SaveResult.ts +31 -0
  160. package/src/router/index.ts +91 -0
  161. package/src/types/DashbordConfig.ts +24 -0
  162. package/src/types/IResourceFile.ts +240 -0
  163. package/src/types/helpers.ts +17 -0
  164. package/src/utils/ResourceUtils.ts +5 -0
  165. package/src/utils/ResponseUtils.ts +68 -0
  166. package/src/utils/StringUtils.ts +63 -0
  167. package/tsconfig.json +17 -0
@@ -0,0 +1,12 @@
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 Repository_1 = __importDefault(require("./Repository"));
7
+ class DashboardRepository extends Repository_1.default {
8
+ constructor(model) {
9
+ super(model);
10
+ }
11
+ }
12
+ exports.default = DashboardRepository;
@@ -0,0 +1,68 @@
1
+ import { Aggregate, Document, Model } from 'mongoose';
2
+ import SaveResult from './SaveResult';
3
+ export interface PaginateParams {
4
+ page: number;
5
+ perPage: number;
6
+ }
7
+ interface IQueryOptions {
8
+ filter?: any;
9
+ sort?: any;
10
+ select?: any;
11
+ limit?: number;
12
+ skip?: number;
13
+ paginateParams?: PaginateParams;
14
+ populate?: any;
15
+ }
16
+ interface PageInfo {
17
+ currentPage: number;
18
+ pagesCount: number;
19
+ nextPage: number;
20
+ recordsCount: number;
21
+ perPage: number;
22
+ }
23
+ interface Page<T> {
24
+ records: T[];
25
+ pageInfo: PageInfo;
26
+ }
27
+ export interface IDashboardRepository {
28
+ }
29
+ export interface IRepository<T extends Document> {
30
+ findById(id: any): Promise<T | null>;
31
+ findOne(queryOptions?: IQueryOptions): Promise<T | null>;
32
+ findMany(queryOptions?: IQueryOptions): Promise<T[]>;
33
+ count(filterOptions: any): Promise<number>;
34
+ save(props: any): Promise<SaveResult<T>>;
35
+ saveAll(props: any[]): Promise<any>;
36
+ findByIdAndUpdate(id: any, props: any): Promise<T | null>;
37
+ findOneAndUpdate(filter: any, props: any, options?: any): Promise<T | null>;
38
+ remove(filterOptions: any): Promise<T | null>;
39
+ distinct(field: string, filterOptions: any): Promise<T[] | null>;
40
+ paginate(queryOptions: IQueryOptions): Promise<Page<T>>;
41
+ update(instance: T, props: any): Promise<SaveResult<T>>;
42
+ saveInstance(instance: T): Promise<SaveResult<T>>;
43
+ }
44
+ export default class Repository<T extends Document> implements IRepository<T>, IDashboardRepository {
45
+ protected model: Model<T>;
46
+ private static NO_NEXT_PAGE;
47
+ constructor(model: Model<T>);
48
+ findById(id: any): Promise<T | null>;
49
+ findOne(queryOptions?: IQueryOptions): Promise<T | null>;
50
+ findMany(queryOptions: IQueryOptions): Promise<T[]>;
51
+ paginate(queryOptions: IQueryOptions): Promise<Page<T>>;
52
+ private getLimit;
53
+ private getSkip;
54
+ toLimitSkip(paginateParams: PaginateParams): [number, number];
55
+ protected createPageInfo(filter: any, skip: number, limit: number): Promise<PageInfo>;
56
+ protected createPageInfoFromAggregate(aggregate: Aggregate<any[]>, skip: number, limit: number): Promise<PageInfo>;
57
+ count(filter: any): Promise<number>;
58
+ countAggregate(aggregate: Aggregate<any[]>): Promise<number>;
59
+ update(instance: T, props: any): Promise<SaveResult<T>>;
60
+ save(props: any): Promise<SaveResult<T>>;
61
+ saveInstance(instance: T): Promise<SaveResult<T>>;
62
+ saveAll(props: any[]): Promise<any>;
63
+ findByIdAndUpdate(id: any, props: any): Promise<T | null>;
64
+ findOneAndUpdate(filter: any, props: any): Promise<T | null>;
65
+ remove(filter: any): Promise<T | null>;
66
+ distinct(field: string, filter: any): Promise<T[] | null>;
67
+ }
68
+ export {};
@@ -0,0 +1,212 @@
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
+ var Repository_1;
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const inversify_1 = require("inversify");
26
+ const mongoose_1 = require("mongoose");
27
+ const SaveResult_1 = __importDefault(require("./SaveResult"));
28
+ let Repository = Repository_1 = class Repository {
29
+ constructor(model) {
30
+ this.model = model;
31
+ }
32
+ findById(id) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return yield this.model.findById(id);
35
+ });
36
+ }
37
+ findOne(queryOptions) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const filter = (queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.filter) ? queryOptions.filter : {};
40
+ const populate = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.populate;
41
+ return this.model.findOne(filter).populate(populate).exec();
42
+ });
43
+ }
44
+ findMany(queryOptions) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const filter = queryOptions.filter ? queryOptions.filter : {};
47
+ const sort = queryOptions.sort;
48
+ const select = queryOptions.select;
49
+ const limit = this.getLimit(queryOptions);
50
+ const skip = this.getSkip(queryOptions);
51
+ const populate = queryOptions.populate;
52
+ var query = this.model.find(filter);
53
+ if (select) {
54
+ query = query.select(select);
55
+ }
56
+ if (sort) {
57
+ query = query.sort(sort);
58
+ }
59
+ if (skip) {
60
+ query = query.skip(skip);
61
+ }
62
+ if (limit) {
63
+ query = query.limit(limit);
64
+ }
65
+ if (populate) {
66
+ query = query.populate(populate);
67
+ }
68
+ return yield query;
69
+ });
70
+ }
71
+ paginate(queryOptions) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const filter = queryOptions.filter ? queryOptions.filter : {};
74
+ const limit = this.getLimit(queryOptions);
75
+ const skip = this.getSkip(queryOptions);
76
+ const pageInfoPromise = yield this.createPageInfo(filter, skip, limit);
77
+ const recordsPromise = yield this.findMany(queryOptions);
78
+ const [records, pageInfo] = yield Promise.all([recordsPromise, pageInfoPromise]);
79
+ return {
80
+ records: records,
81
+ pageInfo
82
+ };
83
+ });
84
+ }
85
+ getLimit(queryOptions) {
86
+ if (queryOptions.paginateParams) {
87
+ return queryOptions.paginateParams.perPage;
88
+ }
89
+ return queryOptions.limit;
90
+ }
91
+ getSkip(queryOptions) {
92
+ if (queryOptions.paginateParams) {
93
+ return queryOptions.paginateParams.perPage * (queryOptions.paginateParams.page - 1);
94
+ }
95
+ return queryOptions.skip;
96
+ }
97
+ toLimitSkip(paginateParams) {
98
+ return [paginateParams.perPage, paginateParams.perPage * (paginateParams.page - 1)];
99
+ }
100
+ createPageInfo(filter, skip, limit) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const count = yield this.count(filter);
103
+ const currentPage = (skip / limit) + 1;
104
+ const pagesCount = Math.ceil(count / limit);
105
+ const nextPage = currentPage < pagesCount ? (currentPage + 1) : Repository_1.NO_NEXT_PAGE;
106
+ return {
107
+ currentPage,
108
+ pagesCount,
109
+ nextPage,
110
+ perPage: limit,
111
+ recordsCount: count
112
+ };
113
+ });
114
+ }
115
+ createPageInfoFromAggregate(aggregate, skip, limit) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const count = yield this.countAggregate(aggregate);
118
+ const currentPage = (skip / limit) + 1;
119
+ const pagesCount = Math.ceil(count / limit);
120
+ const nextPage = currentPage < pagesCount ? (currentPage + 1) : Repository_1.NO_NEXT_PAGE;
121
+ return {
122
+ currentPage,
123
+ pagesCount,
124
+ nextPage,
125
+ perPage: limit,
126
+ recordsCount: count
127
+ };
128
+ });
129
+ }
130
+ count(filter) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ return this.model.countDocuments(filter);
133
+ });
134
+ }
135
+ countAggregate(aggregate) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const queryResult = yield aggregate.count('count');
138
+ if (queryResult.length == 0) {
139
+ return 0;
140
+ }
141
+ return queryResult[0].count;
142
+ });
143
+ }
144
+ update(instance, props) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const allProps = Object.assign(Object.assign({}, instance.toObject()), props);
147
+ return this.save(allProps);
148
+ });
149
+ }
150
+ save(props) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ const instance = new this.model(props);
153
+ const hasId = !!props._id;
154
+ instance.isNew = !hasId;
155
+ return this.saveInstance(instance);
156
+ });
157
+ }
158
+ saveInstance(instance) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ var document;
161
+ var errors = [];
162
+ try {
163
+ document = yield instance.save();
164
+ return new SaveResult_1.default(document, errors);
165
+ }
166
+ catch (e) {
167
+ if (e instanceof mongoose_1.Error.ValidationError) {
168
+ errors = Object.keys(e.errors).map((key) => {
169
+ const saveError = e.errors[key];
170
+ return {
171
+ path: saveError.path,
172
+ type: saveError.kind,
173
+ message: saveError.message
174
+ };
175
+ });
176
+ }
177
+ }
178
+ return new SaveResult_1.default(document, errors);
179
+ });
180
+ }
181
+ saveAll(props) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ return this.model.insertMany(props);
184
+ });
185
+ }
186
+ findByIdAndUpdate(id, props) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ return yield this.model.findByIdAndUpdate(id, props, { new: true, returnOriginal: false, returnDocument: 'after' });
189
+ });
190
+ }
191
+ findOneAndUpdate(filter, props) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ return yield this.model.findOneAndUpdate(filter, props, { new: true, returnOriginal: false, returnDocument: 'after', setDefaultsOnInsert: true, upsert: true });
194
+ });
195
+ }
196
+ remove(filter) {
197
+ return __awaiter(this, void 0, void 0, function* () {
198
+ return yield this.model.findOneAndRemove(filter);
199
+ });
200
+ }
201
+ distinct(field, filter) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ return yield this.model.distinct(field, filter);
204
+ });
205
+ }
206
+ };
207
+ Repository.NO_NEXT_PAGE = -1;
208
+ Repository = Repository_1 = __decorate([
209
+ (0, inversify_1.injectable)(),
210
+ __param(0, (0, inversify_1.unmanaged)())
211
+ ], Repository);
212
+ exports.default = Repository;
@@ -0,0 +1,10 @@
1
+ import { IRequestLogDocument } from '../models/request-log/IRequestLog';
2
+ import Repository, { IRepository } from './Repository';
3
+ export interface IRequestLogRepository extends IRepository<IRequestLogDocument> {
4
+ deleteTillLastDays(days: number): Promise<void>;
5
+ }
6
+ export default class RequestLogRepository extends Repository<IRequestLogDocument> {
7
+ constructor();
8
+ deleteTillLastDays(days: number): Promise<void>;
9
+ getRequestLogsStats(): Promise<any[]>;
10
+ }
@@ -0,0 +1,54 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const inversify_1 = require("inversify");
22
+ const RequestLog_1 = __importDefault(require("../models/request-log/RequestLog"));
23
+ const Repository_1 = __importDefault(require("./Repository"));
24
+ let RequestLogRepository = class RequestLogRepository extends Repository_1.default {
25
+ constructor() {
26
+ super(RequestLog_1.default);
27
+ }
28
+ deleteTillLastDays(days) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const day = 1000 * 60 * 60 * 24;
31
+ const currentTime = Date.now();
32
+ const time = new Date(currentTime - days * day);
33
+ yield RequestLog_1.default.deleteMany({ createdAt: { $lt: time } });
34
+ });
35
+ }
36
+ getRequestLogsStats() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const stats = yield RequestLog_1.default
39
+ .aggregate()
40
+ .match({})
41
+ .group({
42
+ _id: { endpoint: '$endpoint' },
43
+ count: { $sum: 1 },
44
+ average: { $avg: '$durationInMilliseconds' }
45
+ })
46
+ .sort({ count: -1 });
47
+ return stats;
48
+ });
49
+ }
50
+ };
51
+ RequestLogRepository = __decorate([
52
+ (0, inversify_1.injectable)()
53
+ ], RequestLogRepository);
54
+ exports.default = RequestLogRepository;
@@ -0,0 +1,14 @@
1
+ import { Document } from "mongoose";
2
+ export default class SaveResult<T extends Document> {
3
+ private document;
4
+ private errors;
5
+ constructor(document: T | undefined, errors: ISaveError[]);
6
+ getDocument(): T | undefined;
7
+ getErrors(): ISaveError[];
8
+ isValid(): boolean;
9
+ }
10
+ export interface ISaveError {
11
+ type: string;
12
+ path: string;
13
+ message: string;
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class SaveResult {
4
+ constructor(document, errors) {
5
+ this.document = document;
6
+ this.errors = errors;
7
+ }
8
+ getDocument() {
9
+ return this.document;
10
+ }
11
+ getErrors() {
12
+ return this.errors;
13
+ }
14
+ isValid() {
15
+ return this.errors.length === 0;
16
+ }
17
+ }
18
+ exports.default = SaveResult;
@@ -0,0 +1,8 @@
1
+ import { Router } from "express";
2
+ import DashboardController from "../controllers/DashboardController";
3
+ import ResourceController from "../controllers/ResourceController";
4
+ import { AuthenticateMiddleWare } from "../types/DashbordConfig";
5
+ import ActionController from "../controllers/ActionController";
6
+ declare const createRouter: (dashboardController: DashboardController, resourceController: ResourceController, ActionController: ActionController, authenticate?: AuthenticateMiddleWare | undefined) => Router;
7
+ export declare const createViewRoute: (router: Router, appPath: string) => void;
8
+ export default createRouter;
@@ -0,0 +1,95 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.createViewRoute = void 0;
35
+ const express_1 = require("express");
36
+ const path_1 = __importDefault(require("path"));
37
+ const i18n_1 = __importDefault(require("i18n"));
38
+ const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
39
+ const isAuth_1 = __importStar(require("../middlewares/isAuth"));
40
+ const createMainRouter = (router, controller) => {
41
+ router.use((req, res, next) => (0, isAuth_1.defaultHeaders)(req, res, next));
42
+ router
43
+ .route(`/api/:resource`)
44
+ .get((req, res) => controller.index(req, res))
45
+ .post((req, res) => controller.create(req, res));
46
+ router
47
+ .route("/api/:resource/:id")
48
+ .get((req, res) => controller.show(req, res))
49
+ .patch((req, res) => controller.update(req, res))
50
+ .delete((req, res) => controller.delete(req, res));
51
+ };
52
+ const createResourceRouter = (router, controller) => {
53
+ router
54
+ .route("/api/resources")
55
+ .get((req, res) => controller.index(req, res));
56
+ };
57
+ const createActionsRouter = (router, controller) => {
58
+ router
59
+ .route("actions/:actionKey")
60
+ .post((req, res) => controller.execute(req, res));
61
+ };
62
+ const createLoginRoute = (router, verify) => {
63
+ router
64
+ .route("/api/auth/login")
65
+ .all((req, res, next) => (0, isAuth_1.authenticate)(req, res, next, verify))
66
+ .post((req, res) => __awaiter(void 0, void 0, void 0, function* () {
67
+ const session = req.session;
68
+ session.userName = req.user.email;
69
+ return ResponseUtils_1.default.ok(res, {
70
+ user: req.user,
71
+ });
72
+ }));
73
+ };
74
+ const createRouter = (dashboardController, resourceController, ActionController, authenticate) => {
75
+ const router = (0, express_1.Router)();
76
+ if (authenticate) {
77
+ createLoginRoute(router, authenticate);
78
+ router.route(`/api/:resource`).all((req, res, next) => (0, isAuth_1.default)(req, res, next));
79
+ }
80
+ createResourceRouter(router, resourceController);
81
+ createMainRouter(router, dashboardController);
82
+ createActionsRouter(router, ActionController);
83
+ router.use(i18n_1.default.init);
84
+ return router;
85
+ };
86
+ const createViewRoute = (router, appPath) => {
87
+ router
88
+ .get(`(/*)?`, (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
89
+ console.log(req.path);
90
+ console.log(appPath);
91
+ return res.sendFile(path_1.default.join(appPath, "index.html"));
92
+ }));
93
+ };
94
+ exports.createViewRoute = createViewRoute;
95
+ exports.default = createRouter;
@@ -0,0 +1,19 @@
1
+ import { Document } from "mongoose";
2
+ import { IResourceFile } from "./IResourceFile";
3
+ import i18n from "i18n";
4
+ export declare type AuthenticateMiddleWare = (adminCredentials: AdminCredentials) => Promise<boolean | Document>;
5
+ export interface AdminCredentials {
6
+ email: string;
7
+ password: string;
8
+ }
9
+ export interface CookieConfiguration {
10
+ cookiesSecret: string;
11
+ cookieName: string;
12
+ }
13
+ export default interface DashboardConfig {
14
+ resources: IResourceFile[];
15
+ rootPath?: string;
16
+ localesOptions?: i18n.ConfigurationOptions;
17
+ cookiesConfiguration?: CookieConfiguration;
18
+ authenticate?: AuthenticateMiddleWare;
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,123 @@
1
+ import { Request } from "express";
2
+ import { Document, Model } from "mongoose";
3
+ import { ActionTypes, Virtuals } from "./helpers";
4
+ declare type orderTypes = 'asc' | 'desc';
5
+ declare type VirtualFieldTypes = 'password' | 'ref' | 'Array';
6
+ declare type Severity = 'success' | 'info' | 'warning' | 'error';
7
+ interface Parent {
8
+ name: string;
9
+ icon: string;
10
+ }
11
+ interface Action {
12
+ isAccessible?: boolean;
13
+ }
14
+ interface ICrudOperations {
15
+ index?: {
16
+ before: (filter: {
17
+ [key: string]: any;
18
+ }, currentUser: Document) => {
19
+ [key: string]: any;
20
+ };
21
+ };
22
+ create?: {
23
+ before: (params: any, currentUser: Document) => any;
24
+ };
25
+ }
26
+ export interface ActionData {
27
+ record: any;
28
+ currentUser: Document;
29
+ resource: {
30
+ name: string;
31
+ path: string;
32
+ repository: any;
33
+ };
34
+ }
35
+ interface IFilters {
36
+ scopes?: {
37
+ isAccessible: boolean;
38
+ key?: string;
39
+ options?: string[];
40
+ };
41
+ searchBar?: {
42
+ isAccessible: boolean;
43
+ };
44
+ }
45
+ interface IFieldValue {
46
+ required?: boolean;
47
+ isEditable?: boolean;
48
+ }
49
+ interface IVirtualValue {
50
+ type: VirtualFieldTypes;
51
+ arrayType?: string;
52
+ showIn: Virtuals;
53
+ required: boolean;
54
+ }
55
+ interface IModel {
56
+ virtuals?: {
57
+ [key: string]: IVirtualValue;
58
+ };
59
+ }
60
+ interface ActionOptions {
61
+ show?: Action;
62
+ new?: Action;
63
+ edit?: Action;
64
+ delete?: Action;
65
+ bulkDelete?: Action;
66
+ extras?: ExtraAction[];
67
+ }
68
+ interface ExtraAction {
69
+ key: string;
70
+ name: string;
71
+ /**
72
+ * Icon of this action.
73
+ * @reference 'https://mui.com/material-ui/material-icons/'
74
+ */
75
+ icon: string;
76
+ actionType: ActionTypes;
77
+ /**
78
+ * Guard message that appears before executing the action to confirm execution.
79
+ * @default 'No guard message'
80
+ */
81
+ guard?: string;
82
+ /**
83
+ * Alert message appear after executing this action.
84
+ * @default 'Action was executed successfully'
85
+ */
86
+ message?: string;
87
+ /**
88
+ * The severity of the alert. This defines the color and icon used.
89
+ * @default 'success'
90
+ */
91
+ severity?: Severity;
92
+ isVisible?: (data: ActionData) => boolean;
93
+ handler: (req: Request, res: any, data: ActionData) => Promise<any>;
94
+ }
95
+ export interface IResourceFile {
96
+ properties: {
97
+ resource: Model<any, any>;
98
+ modelName: string;
99
+ name?: string;
100
+ title?: string;
101
+ defaultOrderBy?: string;
102
+ defaultrowsPerPage?: number;
103
+ defaultOrder?: orderTypes;
104
+ parent?: Parent;
105
+ hiddenProperties?: string[];
106
+ actions?: ActionOptions;
107
+ filters?: IFilters;
108
+ crudOperations?: ICrudOperations;
109
+ keysTranslations?: {
110
+ [key: string]: any;
111
+ };
112
+ actionsTranslations?: {
113
+ [key: string]: any;
114
+ };
115
+ model?: {
116
+ [key: string]: IFieldValue;
117
+ } | IModel;
118
+ };
119
+ listProperties?: string[];
120
+ showProperties?: string[];
121
+ formProperties?: string[];
122
+ }
123
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ export declare enum Virtuals {
2
+ SHOW = "SHOW",
3
+ LIST = "LIST",
4
+ FORM = "FORM"
5
+ }
6
+ export declare enum ActionNames {
7
+ SHOW = "SHOW",
8
+ LIST = "LIST",
9
+ NEW = "NEW",
10
+ EDIT = "EDIT"
11
+ }
12
+ export declare enum ActionTypes {
13
+ RECORD = "record",
14
+ Resource = "resource"
15
+ }