identity-admin 1.0.0 → 1.2.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/lib/router/index.js +0 -2
- package/lib/types/IResourceFile.d.ts +1 -0
- package/lib/utils/ResponseUtils.d.ts +0 -2
- package/lib/utils/ResponseUtils.js +0 -34
- package/package.json +9 -2
- package/src/Dashboard.ts +0 -74
- package/src/controllers/ActionController.ts +0 -64
- package/src/controllers/DashboardController.ts +0 -388
- package/src/controllers/ResourceController.ts +0 -62
- package/src/helpers/ActionsGenerator.ts +0 -106
- package/src/helpers/ResourceGenerator.ts +0 -90
- package/src/helpers/ResourceHelper.ts +0 -391
- package/src/helpers/SchemaGenerator.ts +0 -120
- package/src/helpers/SchemaHelper.ts +0 -27
- package/src/locales/en.json +0 -11
- package/src/middlewares/isAuth.ts +0 -46
- package/src/models/ModelNames.ts +0 -6
- package/src/models/request-log/IRequestLog.ts +0 -25
- package/src/models/request-log/RequestLog.ts +0 -52
- package/src/repositories/DashboardRepository.ts +0 -11
- package/src/repositories/Repository.ts +0 -269
- package/src/repositories/RequestLogRepository.ts +0 -40
- package/src/repositories/SaveResult.ts +0 -31
- package/src/router/index.ts +0 -91
- package/src/types/DashbordConfig.ts +0 -24
- package/src/types/IResourceFile.ts +0 -240
- package/src/types/helpers.ts +0 -17
- package/src/utils/ResourceUtils.ts +0 -5
- package/src/utils/ResponseUtils.ts +0 -68
- package/src/utils/StringUtils.ts +0 -63
- package/tsconfig.json +0 -17
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import { Document, Model } from "mongoose";
|
|
3
|
-
import { ActionNames, ActionTypes, Virtuals } from "./helpers"
|
|
4
|
-
|
|
5
|
-
type orderTypes = 'asc' | 'desc'
|
|
6
|
-
|
|
7
|
-
type VirtualFieldTypes = 'password' | 'ref' | 'Array'
|
|
8
|
-
|
|
9
|
-
type Severity = 'success' | 'info' | 'warning' | 'error';
|
|
10
|
-
|
|
11
|
-
interface Parent {
|
|
12
|
-
|
|
13
|
-
// Name of the parent
|
|
14
|
-
name: string,
|
|
15
|
-
|
|
16
|
-
// Icon of the parent. You can get the icons from https://mui.com/material-ui/material-icons/
|
|
17
|
-
icon: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface Action {
|
|
21
|
-
|
|
22
|
-
// Specify if this action is accessible or not. True is the default for show, edit, delete, and new while false for bulk delete. You can ovveride any of these values here.
|
|
23
|
-
isAccessible?: boolean,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface ICrudOperations {
|
|
27
|
-
|
|
28
|
-
index?: {
|
|
29
|
-
|
|
30
|
-
// Before handler that gives you the access to the filter object. You can add to the filter object any key and value that will be used in the filter query before getting the records for list. You should return the filter object
|
|
31
|
-
before: (filter: {[key:string]: any}, currentUser: Document) => {[key:string]: any};
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
create?: {
|
|
35
|
-
|
|
36
|
-
// Before handler that is called before creating a new record. This function gives you the access to the record params before saving it, you can perform any update to the params before saving it. This function should return the params
|
|
37
|
-
before: (params: any, currentUser: Document) => any;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ActionData {
|
|
42
|
-
|
|
43
|
-
// Record document
|
|
44
|
-
record: any,
|
|
45
|
-
|
|
46
|
-
// Current user data
|
|
47
|
-
currentUser: Document,
|
|
48
|
-
|
|
49
|
-
// Resource data to which this record belongs
|
|
50
|
-
resource: {
|
|
51
|
-
|
|
52
|
-
// Model name of this table.
|
|
53
|
-
name: string,
|
|
54
|
-
|
|
55
|
-
// Path of the resource to which you can redirect.
|
|
56
|
-
path: string,
|
|
57
|
-
|
|
58
|
-
// Repository of this resource.
|
|
59
|
-
repository: any
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface IFilters {
|
|
64
|
-
|
|
65
|
-
// Scope filter props. If used you should override the scope filter function in the controller of this resource. This filter is not accessible by default
|
|
66
|
-
scopes?: {
|
|
67
|
-
|
|
68
|
-
// Specify if this filter is accessible or not
|
|
69
|
-
isAccessible: boolean,
|
|
70
|
-
|
|
71
|
-
// This field is optional, exists only if this filter is accessible. Specify the key of field in the database that is used to filter by
|
|
72
|
-
key?: string,
|
|
73
|
-
|
|
74
|
-
// Options that appear in the scope filter
|
|
75
|
-
options?: string[]
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
// This filter is accessibile by default
|
|
79
|
-
searchBar?: {
|
|
80
|
-
|
|
81
|
-
// Specify if this filter is accessible or not
|
|
82
|
-
isAccessible: boolean,
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface IFieldValue {
|
|
87
|
-
|
|
88
|
-
// If the field is required in the schema and you don't want it to be required in the form, you can override this here. If not mentioned it will be set as the schema.
|
|
89
|
-
required?: boolean,
|
|
90
|
-
|
|
91
|
-
// Specify either this field can be edited or not.
|
|
92
|
-
isEditable?: boolean
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
interface IVirtualValue {
|
|
96
|
-
|
|
97
|
-
// For now this feature is supported for password field, if you want to add password field in the create form for example, and ref which means that it is a one to many realtion. For example, if you want to get all subCatogeries that belong to a category when you show the category record
|
|
98
|
-
type: VirtualFieldTypes,
|
|
99
|
-
|
|
100
|
-
// Array type exists only if the type is array
|
|
101
|
-
arrayType?: string,
|
|
102
|
-
|
|
103
|
-
// Defines where this virtaul field need to be appeared
|
|
104
|
-
showIn: Virtuals,
|
|
105
|
-
|
|
106
|
-
required: boolean
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
interface IModel {
|
|
110
|
-
|
|
111
|
-
// Add virtual data
|
|
112
|
-
virtuals?: {[key:string]: IVirtualValue}
|
|
113
|
-
}
|
|
114
|
-
interface ActionOptions {
|
|
115
|
-
|
|
116
|
-
show?: Action,
|
|
117
|
-
new?: Action,
|
|
118
|
-
edit?: Action,
|
|
119
|
-
delete?: Action,
|
|
120
|
-
bulkDelete?: Action,
|
|
121
|
-
|
|
122
|
-
// Any extra action that is required to be added.
|
|
123
|
-
extras?: ExtraAction[]
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface ExtraAction {
|
|
127
|
-
|
|
128
|
-
// Key of this action which must be unique in the same resource file
|
|
129
|
-
key: string,
|
|
130
|
-
|
|
131
|
-
// Name of this action
|
|
132
|
-
name: string,
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Icon of this action.
|
|
136
|
-
* @reference 'https://mui.com/material-ui/material-icons/'
|
|
137
|
-
*/
|
|
138
|
-
icon: string,
|
|
139
|
-
|
|
140
|
-
// Action type if it is record action or resource action.
|
|
141
|
-
actionType: ActionTypes,
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Guard message that appears before executing the action to confirm execution.
|
|
145
|
-
* @default 'No guard message'
|
|
146
|
-
*/
|
|
147
|
-
guard?: string,
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Alert message appear after executing this action.
|
|
151
|
-
* @default 'Action was executed successfully'
|
|
152
|
-
*/
|
|
153
|
-
message?: string,
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* The severity of the alert. This defines the color and icon used.
|
|
157
|
-
* @default 'success'
|
|
158
|
-
*/
|
|
159
|
-
severity?: Severity
|
|
160
|
-
|
|
161
|
-
// Is visibile function returns a boolean that specifies to which records should this action appears. Action is shown to all records by default
|
|
162
|
-
isVisible?: (data: ActionData) => boolean;
|
|
163
|
-
|
|
164
|
-
// Handler function that is executed after clicking the action.
|
|
165
|
-
handler: (req: Request, res: any, data: ActionData) => Promise<any>
|
|
166
|
-
|
|
167
|
-
// The action in which is redirected to after executing the action. For example, if you would like to go to list after executing the action, just set this value by list
|
|
168
|
-
// action: ActionNames,
|
|
169
|
-
|
|
170
|
-
// Path of the resource that is intended to redirect. Is set to resource.path if you would like to go to be in the same table
|
|
171
|
-
// path: string,
|
|
172
|
-
|
|
173
|
-
// Id of the record that is used in actions that needs record Id like show or edit
|
|
174
|
-
// recordId: string
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export interface IResourceFile {
|
|
180
|
-
|
|
181
|
-
properties: {
|
|
182
|
-
|
|
183
|
-
// Model
|
|
184
|
-
resource: Model<any, any>,
|
|
185
|
-
|
|
186
|
-
// Model name should be set here. This field is required
|
|
187
|
-
modelName: string,
|
|
188
|
-
|
|
189
|
-
// Name of this model appeared on the nav bar. If not mentioned the model name is taken.
|
|
190
|
-
name?: string,
|
|
191
|
-
|
|
192
|
-
// Property of this table that is shown as the link and used to be searched by in the search bar. If not mentioned explicitly, a search is done on the schema to check for property (title, name, email). If not found _id is taken.
|
|
193
|
-
title?: string,
|
|
194
|
-
|
|
195
|
-
// The property of this model that is used in the default sort at the beginning. If not mentioned is set by the schema's title.
|
|
196
|
-
defaultOrderBy?: string,
|
|
197
|
-
|
|
198
|
-
//Number of rows per page. If not mentioned, it is set to 10.
|
|
199
|
-
defaultrowsPerPage?: number,
|
|
200
|
-
|
|
201
|
-
// The default order if ascending or descending. Ascending is the default.
|
|
202
|
-
defaultOrder?: orderTypes,
|
|
203
|
-
|
|
204
|
-
//The parent that this model is belong to in the nav bar. Setup parent is the default.
|
|
205
|
-
parent?: Parent
|
|
206
|
-
|
|
207
|
-
// Array of fields that are completely hidden from all properties
|
|
208
|
-
hiddenProperties?: string[],
|
|
209
|
-
|
|
210
|
-
// Main actions accessibility are overriden here, also you can customize new action here
|
|
211
|
-
actions?: ActionOptions,
|
|
212
|
-
|
|
213
|
-
// Override filters here
|
|
214
|
-
filters?: IFilters
|
|
215
|
-
|
|
216
|
-
// Override before handler for list and create here
|
|
217
|
-
crudOperations?: ICrudOperations,
|
|
218
|
-
|
|
219
|
-
// Translations of fields
|
|
220
|
-
keysTranslations?: {[key:string]: any};
|
|
221
|
-
|
|
222
|
-
// Translations od actions
|
|
223
|
-
actionsTranslations?: {[key:string]: any};
|
|
224
|
-
|
|
225
|
-
// Override some props of a field's schema structure or create a new virtual property
|
|
226
|
-
model?: {[key:string]: IFieldValue} | IModel
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
// Array of properties that should be appeared in the list action. If not set the whole record is listed
|
|
231
|
-
listProperties?: string[],
|
|
232
|
-
|
|
233
|
-
// Arrays of properties that should be appeared in the show action. If not set the whole record is shown
|
|
234
|
-
showProperties?: string[],
|
|
235
|
-
|
|
236
|
-
// Array of properties that should be appeared in the create/edit form. If not set the whole record is shown in the form
|
|
237
|
-
formProperties?: string[]
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
package/src/types/helpers.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export enum Virtuals {
|
|
2
|
-
SHOW = 'SHOW',
|
|
3
|
-
LIST = 'LIST',
|
|
4
|
-
FORM = 'FORM'
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export enum ActionNames {
|
|
8
|
-
SHOW = 'SHOW',
|
|
9
|
-
LIST = 'LIST',
|
|
10
|
-
NEW = 'NEW',
|
|
11
|
-
EDIT = 'EDIT'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export enum ActionTypes {
|
|
15
|
-
RECORD = 'record',
|
|
16
|
-
Resource = 'resource'
|
|
17
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { IRequestLogProps } from '../models/request-log/IRequestLog';
|
|
2
|
-
import RequestLogRepository, { IRequestLogRepository } from '../repositories/RequestLogRepository';
|
|
3
|
-
import { ISaveError } from '../repositories/SaveResult';
|
|
4
|
-
import { Response } from 'express';
|
|
5
|
-
|
|
6
|
-
export default class ResponseUtils {
|
|
7
|
-
private static logRepository = new RequestLogRepository();
|
|
8
|
-
|
|
9
|
-
public static send(res: Response, status: number, message: string, data?: object, errors?: ISaveError []) {
|
|
10
|
-
|
|
11
|
-
this.log(res.req, status, message);
|
|
12
|
-
const splittedMessage = message.split(', ');
|
|
13
|
-
return res.format({
|
|
14
|
-
json: () => {
|
|
15
|
-
res.status(status).json({
|
|
16
|
-
meta: {
|
|
17
|
-
status,
|
|
18
|
-
message: res.__(splittedMessage[0], { attribute: splittedMessage[1] })
|
|
19
|
-
},
|
|
20
|
-
data,
|
|
21
|
-
errors
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
default: () => {
|
|
25
|
-
res.status(406).send();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public static created(res: Response, data: object) {
|
|
31
|
-
this.send(res, 201, 'Created', data);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public static ok(res: Response, data: object) {
|
|
35
|
-
this.send(res, 200, 'Ok', data);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public static unauthorized(res: Response) {
|
|
39
|
-
this.send(res, 401, 'Unauthenticated')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public static unprocessable(res: Response, message: string, errors: ISaveError[]) {
|
|
43
|
-
this.send(res, 422, message, {}, errors)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public static notFound(res: Response, message: string, errors: ISaveError[]) {
|
|
47
|
-
this.send(res, 404, message, {}, errors);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private static async log(req: any, status: number, message: string): Promise<void> {
|
|
51
|
-
const duration = new Date().getTime() - req.startTime.getTime();
|
|
52
|
-
const logProps: IRequestLogProps = {
|
|
53
|
-
method: req.method,
|
|
54
|
-
endpoint: req.route.path,
|
|
55
|
-
url: req.originalUrl.split('?')[0],
|
|
56
|
-
startTime: req.startTime,
|
|
57
|
-
durationInMilliseconds: duration,
|
|
58
|
-
query: JSON.stringify(req.query),
|
|
59
|
-
body: JSON.stringify(req.body),
|
|
60
|
-
userAgent: req.headers['user-agent'],
|
|
61
|
-
headers: JSON.stringify(req.headers),
|
|
62
|
-
status: status,
|
|
63
|
-
message: message
|
|
64
|
-
};
|
|
65
|
-
await ResponseUtils.logRepository.save(logProps);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}
|
package/src/utils/StringUtils.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
var pluralize = require('pluralize')
|
|
2
|
-
|
|
3
|
-
export default class StringUtils {
|
|
4
|
-
|
|
5
|
-
public static convertCamelCaseToWord(camelCaseWord: string ) {
|
|
6
|
-
|
|
7
|
-
if (camelCaseWord === '_id') {
|
|
8
|
-
return 'Id'
|
|
9
|
-
}
|
|
10
|
-
var result = camelCaseWord.replace( /([A-Z])/g, " $1" );
|
|
11
|
-
var word = result.charAt(0).toUpperCase() + result.slice(1);
|
|
12
|
-
|
|
13
|
-
if (word.charAt(0) === ' ') {
|
|
14
|
-
word = word.substring(1)
|
|
15
|
-
}
|
|
16
|
-
return word
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public static checkRefId(word: string ) {
|
|
20
|
-
const check = word.slice(-2) === 'Id'
|
|
21
|
-
return check
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static lowerCaseFirstLetter(word: string) {
|
|
25
|
-
return word.charAt(0).toLocaleLowerCase() + word.slice(1);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public static upperCaseFirstLetter(word: string) {
|
|
29
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public static removeResourceWord(word: string) {
|
|
33
|
-
return this.lowerCaseFirstLetter(word.split('Resource')[0])
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public static getRefPath(word: string) {
|
|
37
|
-
|
|
38
|
-
const check = word.slice(-2) === 'Id'
|
|
39
|
-
|
|
40
|
-
if (check) {
|
|
41
|
-
return word.slice(0, -2)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return this.lowerCaseFirstLetter(pluralize.singular(word))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public static getPopulatedString(populatedString: string, addedString: string) {
|
|
48
|
-
|
|
49
|
-
if (populatedString.length === 0) {
|
|
50
|
-
populatedString = populatedString + addedString
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
else {
|
|
54
|
-
populatedString = populatedString + ' ' + addedString
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return populatedString
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"experimentalDecorators": true,
|
|
4
|
-
"target": "es2016",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"outDir": "./lib",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"watch": false
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
"include": ["src", "lib/view"],
|
|
15
|
-
"exclude": ["node_modules", "**/__tests__/*"]
|
|
16
|
-
|
|
17
|
-
}
|