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,68 @@
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 StringUtils_1 = __importDefault(require("../utils/StringUtils"));
7
+ const SchemaGenerator_1 = __importDefault(require("./SchemaGenerator"));
8
+ const ResourceHelper_1 = __importDefault(require("./ResourceHelper"));
9
+ const ActionsGenerator_1 = __importDefault(require("./ActionsGenerator"));
10
+ const SetupParent = {
11
+ name: 'Setup',
12
+ icon: 'PermDataSetting'
13
+ };
14
+ class ResourceGenerator {
15
+ static generate(resource) {
16
+ const modelName = resource.properties.modelName;
17
+ const modifiedResource = JSON.parse(JSON.stringify(resource));
18
+ const schema = resource.properties.resource.schema.paths;
19
+ const title = ResourceHelper_1.default.getSchemaTitle(schema, resource);
20
+ const recordFields = ResourceHelper_1.default.manageFields(schema, title, resource.properties.hiddenProperties);
21
+ const modelCheck = resource.properties.model ? JSON.parse(JSON.stringify(resource.properties.model)) : undefined;
22
+ const actionsCheck = resource.properties.actions;
23
+ const modelAndPopulatedString = SchemaGenerator_1.default.generateSchema(schema, modelCheck, modelName, resource);
24
+ modifiedResource.properties.model = modelAndPopulatedString[0];
25
+ modifiedResource.properties.populatedString = modelAndPopulatedString[1];
26
+ const modifiedProperties = ResourceHelper_1.default.addVirtualFields(JSON.parse(JSON.stringify(recordFields)), modelCheck);
27
+ modifiedResource.properties.path = ResourceHelper_1.default.getModelPath(modelName);
28
+ const modifiedListProperties = modifiedProperties[0];
29
+ const modifiedShowProperties = modifiedProperties[1];
30
+ const modifiedFormProperties = modifiedProperties[2];
31
+ if (!resource.properties.parent) {
32
+ modifiedResource.properties.parent = SetupParent;
33
+ }
34
+ if (!resource.properties.name) {
35
+ modifiedResource.properties.name = StringUtils_1.default.convertCamelCaseToWord(modelName);
36
+ }
37
+ if (!resource.showProperties) {
38
+ modifiedResource.showProperties = modifiedShowProperties;
39
+ }
40
+ if (!resource.listProperties) {
41
+ modifiedResource.listProperties = ResourceHelper_1.default.exchangeFirstFieldWithTitle(JSON.parse(JSON.stringify(modifiedListProperties)), title);
42
+ }
43
+ if (!resource.formProperties) {
44
+ modifiedResource.formProperties = ResourceHelper_1.default.removeUnWantedFieldsFromCreateOrUpdate(JSON.parse(JSON.stringify(modifiedFormProperties)));
45
+ }
46
+ modifiedResource.properties.title = title;
47
+ if (!resource.properties.defaultOrderBy) {
48
+ modifiedResource.properties.defaultOrderBy = title;
49
+ }
50
+ if (!resource.properties.defaultOrder) {
51
+ modifiedResource.properties.defaultOrder = 'asc';
52
+ }
53
+ if (!resource.properties.defaultrowsPerPage) {
54
+ modifiedResource.properties.defaultrowsPerPage = 10;
55
+ }
56
+ modifiedResource.listProperties = ResourceHelper_1.default.prepareProperties(resource.listProperties ? resource.listProperties : modifiedResource.listProperties, modelName, modifiedResource.properties.model, resource);
57
+ modifiedResource.showProperties = ResourceHelper_1.default.prepareProperties(resource.showProperties ? resource.showProperties : modifiedResource.showProperties, modelName, modifiedResource.properties.model, resource);
58
+ modifiedResource.properties.filters = ResourceHelper_1.default.getFilters(resource.properties.filters ? JSON.parse(JSON.stringify(resource.properties.filters)) : undefined);
59
+ if (modifiedResource.properties.filters && modifiedResource.properties.filters.scopes && modifiedResource.properties.filters.scopes.isAccessible) {
60
+ const options = resource.properties.filters.scopes.options;
61
+ modifiedResource.properties.filters.scopes.options = ResourceHelper_1.default.setScopeFilterOptions(modelName, options);
62
+ }
63
+ const actions = ActionsGenerator_1.default.generateActions(actionsCheck, resource);
64
+ modifiedResource.properties.actions = actions;
65
+ return modifiedResource;
66
+ }
67
+ }
68
+ exports.default = ResourceGenerator;
@@ -0,0 +1,23 @@
1
+ import { IResourceFile } from "../types/IResourceFile";
2
+ import { IDashboardRepository } from "../repositories/Repository";
3
+ export default class ResourcesHelper {
4
+ static getSchemaTitle(schema: any, resource: any): any;
5
+ static prepareProperties(properties: string[], modelName: string, model: any, resource: IResourceFile): {}[];
6
+ static getFieldType(schemaField: any): any;
7
+ static checkResourceTranslation(resource: IResourceFile, key: string): string | undefined;
8
+ static checkActionTranslation(resource: IResourceFile, action: string): string | undefined;
9
+ static setScopeFilterOptions(modelName: string, options: string[]): any;
10
+ static getFilters(filters: any): {
11
+ scopes: {};
12
+ searchBar: {};
13
+ };
14
+ static addExtraFields(showProperties: any, model: any, record: any, filterBy: string, repo: IDashboardRepository): Promise<any>;
15
+ static getTitle(schema: any): "title" | "name" | "_id" | "email";
16
+ static exchangeFirstFieldWithTitle(arrayOfFields: any, title: string): any;
17
+ static addVirtualFields(arrayOfFields: string[], model: any): any[];
18
+ static manageFields(schema: any, title: string, hiddenProperties: any): any[];
19
+ static checkUnwantedFields(fieldKey: string, title: string): boolean;
20
+ static getModelPath(modelName: string): any;
21
+ static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields: string[]): string[];
22
+ static checkCreateBeforeHandler(resource: any): boolean;
23
+ }
@@ -0,0 +1,274 @@
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
+ const helpers_1 = require("../types/helpers");
16
+ const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
17
+ const i18n_1 = require("i18n");
18
+ var pluralize = require('pluralize');
19
+ class ResourcesHelper {
20
+ static getSchemaTitle(schema, resource) {
21
+ if (resource.properties.title) {
22
+ return resource.properties.title;
23
+ }
24
+ return this.getTitle(schema);
25
+ }
26
+ static prepareProperties(properties, modelName, model, resource) {
27
+ var preparedProperties = [];
28
+ properties.forEach(key => {
29
+ if (model[key]) {
30
+ const refCheck = model[key].type === 'ref';
31
+ var path = undefined;
32
+ if (refCheck) {
33
+ path = model[key].path;
34
+ }
35
+ const translation = this.checkResourceTranslation(resource, key);
36
+ const propertyObject = {
37
+ key,
38
+ value: translation ? translation : StringUtils_1.default.checkRefId(key) ? StringUtils_1.default.convertCamelCaseToWord(key.slice(0, -2)) : StringUtils_1.default.convertCamelCaseToWord(key),
39
+ path: path
40
+ };
41
+ preparedProperties.push(propertyObject);
42
+ }
43
+ });
44
+ return preparedProperties;
45
+ }
46
+ static getFieldType(schemaField) {
47
+ if (schemaField.instance === 'password') {
48
+ return 'password';
49
+ }
50
+ if (schemaField.instance === 'Embedded') {
51
+ return 'nestedSchema';
52
+ }
53
+ if (schemaField.options.ref) {
54
+ return 'ref';
55
+ }
56
+ else if (schemaField.enumValues && schemaField.enumValues.length !== 0) {
57
+ return 'enum';
58
+ }
59
+ else {
60
+ return schemaField.instance;
61
+ }
62
+ }
63
+ static checkResourceTranslation(resource, key) {
64
+ var translation = undefined;
65
+ if (!resource.properties.keysTranslations || !resource.properties.keysTranslations[key]) {
66
+ return translation;
67
+ }
68
+ translation = (0, i18n_1.__)(resource.properties.keysTranslations[key]);
69
+ return translation;
70
+ }
71
+ static checkActionTranslation(resource, action) {
72
+ var translation = undefined;
73
+ if (!resource.properties.actionsTranslations || !resource.properties.actionsTranslations[action]) {
74
+ return translation;
75
+ }
76
+ translation = (0, i18n_1.__)(resource.properties.actionsTranslations[action]);
77
+ return translation;
78
+ }
79
+ static setScopeFilterOptions(modelName, options) {
80
+ var arrayOfOptions = [];
81
+ options.forEach((key) => {
82
+ const valueOfOption = StringUtils_1.default.lowerCaseFirstLetter(modelName) + '_filter_scope_' + key;
83
+ const optionObject = {
84
+ key,
85
+ value: (0, i18n_1.__)(valueOfOption)
86
+ };
87
+ arrayOfOptions.push(optionObject);
88
+ });
89
+ return arrayOfOptions;
90
+ }
91
+ static getFilters(filters) {
92
+ var filterObject = {
93
+ scopes: {},
94
+ searchBar: {}
95
+ };
96
+ if (!filters || Object.keys(filters).length === 0) {
97
+ filterObject = {
98
+ scopes: {
99
+ isAccessible: false
100
+ },
101
+ searchBar: {
102
+ isAccessible: true
103
+ }
104
+ };
105
+ return filterObject;
106
+ }
107
+ if (!filters.searchBar || !filters.searchBar.hasOwnProperty('isAccessible')) {
108
+ filterObject.searchBar = {
109
+ isAccessible: true
110
+ };
111
+ }
112
+ else {
113
+ filterObject.searchBar = filters.searchBar;
114
+ }
115
+ if (!filters.scopes || !filters.scopes.hasOwnProperty('isAccessible')) {
116
+ filterObject.scopes = {
117
+ isAccessible: false
118
+ };
119
+ }
120
+ else {
121
+ filterObject.scopes = filters.scopes;
122
+ }
123
+ return filterObject;
124
+ }
125
+ static addExtraFields(showProperties, model, record, filterBy, repo) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ for (var i = 0; i < showProperties.length; i++) {
128
+ // if (!model.hasOwnProperty(showProperties[i].key)) {
129
+ // const modelName = pluralize.singular(showProperties[i].key)
130
+ // const repository: any = this.getResourceSymbol(modelName)
131
+ // filterBy = filterBy + "Id"
132
+ // const filterQuery: {[key:string]: any} = {}
133
+ // filterQuery[filterBy] = record._id
134
+ // const extraRecords = await repository.findMany({
135
+ // filter: filterQuery
136
+ // });
137
+ // record[showProperties[i].key] = extraRecords
138
+ // }
139
+ const key = showProperties[i].key;
140
+ if ((model[key].type === 'ref' && model.virtuals && model.virtuals[key]) || (model[key].type === 'Array' && model.virtuals && model.virtuals[key] && model[key].arrayType === 'ref')) {
141
+ const modelName = pluralize.singular(showProperties[i].key);
142
+ const repository = repo;
143
+ filterBy = filterBy + "Id";
144
+ const filterQuery = {};
145
+ filterQuery[filterBy] = record._id;
146
+ const extraRecords = yield repository.findMany({
147
+ filter: filterQuery
148
+ });
149
+ record[showProperties[i].key] = extraRecords;
150
+ }
151
+ }
152
+ ;
153
+ return record;
154
+ });
155
+ }
156
+ // public static getResourceRepository(resourceName: string) {
157
+ // const resource = StringUtils.upperCaseFirstLetter(resourceName);
158
+ // const repositorySymbol = Symbol.for(`I${resource}Repository`)
159
+ // const repository = container.get(repositorySymbol)
160
+ // return repository;
161
+ // }
162
+ static getTitle(schema) {
163
+ if (schema['title']) {
164
+ return 'title';
165
+ }
166
+ if (schema['name']) {
167
+ return 'name';
168
+ }
169
+ if (schema['email']) {
170
+ return 'email';
171
+ }
172
+ return '_id';
173
+ }
174
+ static exchangeFirstFieldWithTitle(arrayOfFields, title) {
175
+ if (arrayOfFields[0] !== title) {
176
+ for (var i = 1; i < arrayOfFields.length; i++) {
177
+ const field = arrayOfFields[i];
178
+ if (field === title) {
179
+ const temp = arrayOfFields[0];
180
+ arrayOfFields[0] = title;
181
+ arrayOfFields[i] = temp;
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ return arrayOfFields;
187
+ }
188
+ static addVirtualFields(arrayOfFields, model) {
189
+ var showProperties = JSON.parse(JSON.stringify(arrayOfFields));
190
+ var listProperties = JSON.parse(JSON.stringify(arrayOfFields));
191
+ var formProperties = JSON.parse(JSON.stringify(arrayOfFields));
192
+ if (!model || !model.virtuals || !(Object.keys(model.virtuals))) {
193
+ return [listProperties, showProperties, formProperties];
194
+ }
195
+ const virtualFields = model.virtuals;
196
+ for (const extraField in virtualFields) {
197
+ if (virtualFields[extraField].showIn) {
198
+ switch (virtualFields[extraField].showIn) {
199
+ case helpers_1.Virtuals.SHOW:
200
+ showProperties.push(extraField);
201
+ break;
202
+ case helpers_1.Virtuals.LIST:
203
+ listProperties.push(extraField);
204
+ break;
205
+ case helpers_1.Virtuals.FORM:
206
+ formProperties.push(extraField);
207
+ break;
208
+ }
209
+ }
210
+ else {
211
+ showProperties.push(extraField);
212
+ listProperties.push(extraField);
213
+ formProperties.push(extraField);
214
+ }
215
+ }
216
+ return [listProperties, showProperties, formProperties];
217
+ }
218
+ static manageFields(schema, title, hiddenProperties) {
219
+ var arrayOfFields = [];
220
+ if (!hiddenProperties || !hiddenProperties.includes('_id')) {
221
+ arrayOfFields.push('_id');
222
+ }
223
+ if (title !== '_id' && (!hiddenProperties || !hiddenProperties.includes(title))) {
224
+ arrayOfFields.push(title);
225
+ }
226
+ const fields = Object.keys(schema);
227
+ for (var i = 0; i < fields.length; i++) {
228
+ const fieldKey = fields[i];
229
+ if (hiddenProperties && hiddenProperties.includes(fieldKey)) {
230
+ continue;
231
+ }
232
+ const unwantedField = this.checkUnwantedFields(fieldKey, title);
233
+ if (unwantedField) {
234
+ continue;
235
+ }
236
+ arrayOfFields.push(fieldKey);
237
+ }
238
+ return arrayOfFields;
239
+ }
240
+ static checkUnwantedFields(fieldKey, title) {
241
+ if (fieldKey === '__v' || fieldKey === '_id' || fieldKey === title || fieldKey === 'salt' || fieldKey === 'hash' || fieldKey === 'forgotPasswordToken') {
242
+ return true;
243
+ }
244
+ return false;
245
+ }
246
+ static getModelPath(modelName) {
247
+ const modelPath = pluralize(StringUtils_1.default.lowerCaseFirstLetter(modelName));
248
+ return modelPath;
249
+ }
250
+ static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields) {
251
+ var modifiedArrayOfFields = [];
252
+ arrayOfFields.forEach(field => {
253
+ if (field !== '_id' && field !== 'createdAt' && field !== 'updatedAt') {
254
+ modifiedArrayOfFields.push(field);
255
+ }
256
+ });
257
+ return modifiedArrayOfFields;
258
+ }
259
+ // public static checkIndexBeforeHandler(resource: any) {
260
+ // const crudOperations = resource.properties.crudOperations
261
+ // if (crudOperations && crudOperations.index && crudOperations.index.before) {
262
+ // return true
263
+ // }
264
+ // return false
265
+ // }
266
+ static checkCreateBeforeHandler(resource) {
267
+ const crudOperations = resource.properties.crudOperations;
268
+ if (crudOperations && crudOperations.create && crudOperations.create.before) {
269
+ return true;
270
+ }
271
+ return false;
272
+ }
273
+ }
274
+ exports.default = ResourcesHelper;
@@ -0,0 +1,5 @@
1
+ import { IResourceFile } from "../types/IResourceFile";
2
+ export default class SchemaGenerator {
3
+ static generateSchema(schema: any, model: any, modelName: string, resource: IResourceFile): any[];
4
+ private static setNestedSchema;
5
+ }
@@ -0,0 +1,87 @@
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 StringUtils_1 = __importDefault(require("../utils/StringUtils"));
7
+ const ResourceHelper_1 = __importDefault(require("./ResourceHelper"));
8
+ var pluralize = require('pluralize');
9
+ class SchemaGenerator {
10
+ static generateSchema(schema, model, modelName, resource) {
11
+ const schemaFields = Object.keys(schema);
12
+ var populatedString = '';
13
+ if (!model) {
14
+ model = {};
15
+ }
16
+ schemaFields.forEach(field => {
17
+ const schemaField = schema[field];
18
+ const refCheck = schemaField.options.ref;
19
+ const translation = ResourceHelper_1.default.checkResourceTranslation(resource, field);
20
+ const fieldType = ResourceHelper_1.default.getFieldType(schemaField);
21
+ model[field] = model[field] ? model[field] : {};
22
+ if (fieldType === 'ref') {
23
+ populatedString = StringUtils_1.default.getPopulatedString(populatedString, field);
24
+ model[field].path = StringUtils_1.default.lowerCaseFirstLetter(refCheck);
25
+ }
26
+ if (fieldType === 'nestedSchema') {
27
+ const modelAndPopulatedString = this.setNestedSchema(schema[field].schema.paths, modelName, model, field, populatedString, resource);
28
+ model = modelAndPopulatedString[0];
29
+ populatedString = modelAndPopulatedString[1];
30
+ }
31
+ else if (fieldType === 'Array') {
32
+ model[field].required = schema[field].caster.isRequired;
33
+ if (schema[field].schema) {
34
+ const modelAndPopulatedString = this.setNestedSchema(schema[field].schema.paths, modelName, model, field, populatedString, resource);
35
+ model = modelAndPopulatedString[0];
36
+ populatedString = modelAndPopulatedString[1];
37
+ model[field].arrayType = 'nestedSchema';
38
+ }
39
+ else if (schema[field].caster.options.ref) {
40
+ populatedString = StringUtils_1.default.getPopulatedString(populatedString, field);
41
+ model[field].path = StringUtils_1.default.lowerCaseFirstLetter(schema[field].caster.options.ref);
42
+ model[field].apiRoute = 'admin/' + StringUtils_1.default.lowerCaseFirstLetter(pluralize(schema[field].caster.options.ref));
43
+ model[field].arrayType = 'ref';
44
+ }
45
+ else {
46
+ model[field].arrayType = schema[field].caster.instance;
47
+ }
48
+ }
49
+ model[field].type = model[field].type ? model[field].type : fieldType;
50
+ model[field].defaultValue = schema[field].defaultValue ? schema[field].defaultValue : undefined;
51
+ model[field].required = model[field].required ? model[field].required : schemaField.isRequired ? schemaField.isRequired : false;
52
+ model[field].apiRoute = model[field].apiRoute ? model[field].apiRoute : schemaField.options.ref ? 'admin/' + StringUtils_1.default.lowerCaseFirstLetter(pluralize(schemaField.options.ref)) : undefined;
53
+ model[field].enumValues = model[field].type === 'enum' ? schemaField.enumValues : undefined;
54
+ model[field].value = model[field].value ? model[field].value : translation ? translation : refCheck ? StringUtils_1.default.checkRefId(field) ? StringUtils_1.default.convertCamelCaseToWord(field.slice(0, -2)) : StringUtils_1.default.convertCamelCaseToWord(field) : StringUtils_1.default.convertCamelCaseToWord(field);
55
+ });
56
+ if (model.virtuals) {
57
+ for (const extraField in model.virtuals) {
58
+ model[extraField] = model[extraField] ? model[extraField] : {};
59
+ model[extraField].type = model.virtuals[extraField].type;
60
+ model[extraField].arrayType = model.virtuals[extraField].arrayType ? model.virtuals[extraField].arrayType : undefined;
61
+ model[extraField].required = model.virtuals[extraField].required;
62
+ model[extraField].value = ResourceHelper_1.default.checkResourceTranslation(resource, extraField) ? ResourceHelper_1.default.checkResourceTranslation(resource, extraField) : StringUtils_1.default.convertCamelCaseToWord(extraField);
63
+ model[extraField].path = StringUtils_1.default.getRefPath(extraField);
64
+ }
65
+ }
66
+ return [model, populatedString];
67
+ }
68
+ static setNestedSchema(paths, modelName, model, field, populatedString, resource) {
69
+ var nestedSchema = {};
70
+ var nestedSchemaKeys = [];
71
+ const nestedModelodelAndPopulatedString = this.generateSchema(paths, nestedSchema, modelName, resource);
72
+ model[field].schema = nestedModelodelAndPopulatedString[0];
73
+ model[field].populatedString = nestedModelodelAndPopulatedString[1];
74
+ const populatedStringArray = nestedModelodelAndPopulatedString[1].split(' ');
75
+ populatedStringArray.forEach((nestedSchemaPopulatedString) => {
76
+ if (nestedSchemaPopulatedString) {
77
+ populatedString = StringUtils_1.default.getPopulatedString(populatedString, field + '.' + nestedSchemaPopulatedString);
78
+ }
79
+ });
80
+ for (const key in model[field].schema) {
81
+ nestedSchemaKeys.push(key);
82
+ }
83
+ model[field].keys = nestedSchemaKeys;
84
+ return [model, populatedString];
85
+ }
86
+ }
87
+ exports.default = SchemaGenerator;
@@ -0,0 +1,5 @@
1
+ import { Schema } from 'mongoose';
2
+ export default class SchemaHelper {
3
+ static belongsTo(schema: Schema, modelName: string): void;
4
+ private static lowerFirstLetter;
5
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class SchemaHelper {
4
+ static belongsTo(schema, modelName) {
5
+ const fieldName = this.lowerFirstLetter(modelName);
6
+ const localFieldName = fieldName + 'Id';
7
+ schema.virtual(fieldName, {
8
+ ref: modelName,
9
+ localField: localFieldName,
10
+ foreignField: '_id',
11
+ justOne: true
12
+ });
13
+ }
14
+ static lowerFirstLetter(value) {
15
+ if (value.length == 0) {
16
+ return '';
17
+ }
18
+ return value.charAt(0).toLowerCase() + value.slice(1);
19
+ }
20
+ }
21
+ exports.default = SchemaHelper;
@@ -0,0 +1,11 @@
1
+ {
2
+ "actions_new": "Create New",
3
+ "actions_edit": "Edit",
4
+ "actions_delete": "Delete",
5
+ "actions_delete_confirmMessage_title": "Do you really want to delete this record?",
6
+ "actions_delete_confirmMessage_body": "If you clicked yes, this record will be permanently deleted.",
7
+ "actions_bulkDelete_confirmMessage_title": "Do you really want to delete these records?",
8
+ "actions_bulkDelete_confirmMessage_body": "If you clicked yes, these records will be permanently deleted.",
9
+ "actions_delete_options_yes": "Delete",
10
+ "actions_delete_options_no": "No"
11
+ }
@@ -0,0 +1,13 @@
1
+ import { NextFunction, Request, Response } from "express";
2
+ import { AuthenticateMiddleWare } from "../types/DashbordConfig";
3
+ import { Document } from "mongoose";
4
+ export interface IRequest extends Request {
5
+ user: Document;
6
+ language: string;
7
+ timezone: string;
8
+ startTime: Date;
9
+ }
10
+ export declare const defaultHeaders: (req: IRequest, res: Response, next: NextFunction) => void;
11
+ export declare const authenticate: (req: IRequest, res: Response, next: NextFunction, authenticate: AuthenticateMiddleWare) => Promise<void>;
12
+ declare const isAuth: (req: IRequest, res: Response, next: NextFunction) => void;
13
+ export default isAuth;
@@ -0,0 +1,43 @@
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.authenticate = exports.defaultHeaders = void 0;
16
+ const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
17
+ const defaultHeaders = function (req, res, next) {
18
+ req.language = req.headers['accept-language'] ? req.headers['accept-language'] : 'en';
19
+ req.timezone = req.headers.timezone ? req.headers.timezone : 'UTC';
20
+ next();
21
+ };
22
+ exports.defaultHeaders = defaultHeaders;
23
+ const authenticate = (req, res, next, authenticate) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const adminCredentials = {
25
+ email: req.body.user.email,
26
+ password: req.body.user.password
27
+ };
28
+ const user = yield authenticate(adminCredentials);
29
+ if (!user) {
30
+ return ResponseUtils_1.default.unauthorized(res);
31
+ }
32
+ req.user = user;
33
+ next();
34
+ });
35
+ exports.authenticate = authenticate;
36
+ const isAuth = function (req, res, next) {
37
+ const session = req.session;
38
+ if (!session.userName) {
39
+ return ResponseUtils_1.default.unauthorized(res);
40
+ }
41
+ next();
42
+ };
43
+ exports.default = isAuth;
@@ -0,0 +1,4 @@
1
+ export default class ModelNames {
2
+ static User: string;
3
+ static RequestLog: string;
4
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ModelNames {
4
+ }
5
+ exports.default = ModelNames;
6
+ ModelNames.User = 'IdentityUser';
7
+ ModelNames.RequestLog = 'RequestLog';
@@ -0,0 +1,22 @@
1
+ import { Document, Model, Types } from 'mongoose';
2
+ export interface IRequestLogProps {
3
+ _id?: Types.ObjectId;
4
+ method: string;
5
+ endpoint: string;
6
+ url: string;
7
+ startTime: Date;
8
+ durationInMilliseconds: number;
9
+ query: string;
10
+ body: string;
11
+ userAgent?: string;
12
+ headers?: string;
13
+ status?: number;
14
+ message?: string;
15
+ }
16
+ export interface IRequestLogDocument extends IRequestLogProps, Document {
17
+ _id: Types.ObjectId;
18
+ createdAt: Date;
19
+ updatedAt: Date;
20
+ }
21
+ export default interface IRequestLogModel extends Model<IRequestLogDocument> {
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import IRequestLogModel from './IRequestLog';
2
+ declare const RequestLog: IRequestLogModel;
3
+ export default RequestLog;
@@ -0,0 +1,51 @@
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 SchemaHelper_1 = __importDefault(require("../../helpers/SchemaHelper"));
7
+ const mongoose_1 = require("mongoose");
8
+ const ModelNames_1 = __importDefault(require("../ModelNames"));
9
+ // belongs_to User
10
+ const RequestLogSchema = new mongoose_1.Schema({
11
+ method: {
12
+ type: String
13
+ },
14
+ endpoint: {
15
+ type: String
16
+ },
17
+ url: {
18
+ type: String
19
+ },
20
+ startTime: {
21
+ type: Date
22
+ },
23
+ durationInMilliseconds: {
24
+ type: Number
25
+ },
26
+ userId: {
27
+ type: mongoose_1.Schema.Types.ObjectId,
28
+ default: null
29
+ },
30
+ query: {
31
+ type: String
32
+ },
33
+ body: {
34
+ type: String
35
+ },
36
+ userAgent: {
37
+ type: String
38
+ },
39
+ headers: {
40
+ type: String
41
+ },
42
+ message: {
43
+ type: String
44
+ },
45
+ status: {
46
+ type: Number
47
+ }
48
+ }, { timestamps: true });
49
+ SchemaHelper_1.default.belongsTo(RequestLogSchema, ModelNames_1.default.User);
50
+ const RequestLog = (0, mongoose_1.model)(ModelNames_1.default.RequestLog, RequestLogSchema);
51
+ exports.default = RequestLog;
@@ -0,0 +1,5 @@
1
+ import Repository from "./Repository";
2
+ import { Document, Model } from "mongoose";
3
+ export default class DashboardRepository extends Repository<Document> {
4
+ constructor(model: Model<Document, Model<Document>>);
5
+ }