@spinajs/rbac-http 1.2.125 → 1.2.136

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 (53) hide show
  1. package/lib/decorators.d.ts +2 -1
  2. package/lib/decorators.js +18 -3
  3. package/lib/decorators.js.map +1 -1
  4. package/lib/http/src/interfaces.d.ts +443 -0
  5. package/lib/http/src/interfaces.js +222 -0
  6. package/lib/http/src/interfaces.js.map +1 -0
  7. package/lib/interfaces.d.ts +3 -3
  8. package/lib/policies.d.ts +6 -2
  9. package/lib/policies.js +24 -4
  10. package/lib/policies.js.map +1 -1
  11. package/lib/rbac-http/src/augumentation.d.ts +7 -0
  12. package/lib/rbac-http/src/augumentation.js +4 -0
  13. package/lib/rbac-http/src/augumentation.js.map +1 -0
  14. package/lib/rbac-http/src/config/rbac-http.d.ts +1 -0
  15. package/lib/rbac-http/src/config/rbac-http.js +21 -0
  16. package/lib/rbac-http/src/config/rbac-http.js.map +1 -0
  17. package/lib/rbac-http/src/controllers/LoginController.d.ts +12 -0
  18. package/lib/rbac-http/src/controllers/LoginController.js +91 -0
  19. package/lib/rbac-http/src/controllers/LoginController.js.map +1 -0
  20. package/lib/rbac-http/src/controllers/UsersController.d.ts +17 -0
  21. package/lib/rbac-http/src/controllers/UsersController.js +199 -0
  22. package/lib/rbac-http/src/controllers/UsersController.js.map +1 -0
  23. package/lib/rbac-http/src/decorators.d.ts +18 -0
  24. package/lib/rbac-http/src/decorators.js +80 -0
  25. package/lib/rbac-http/src/decorators.js.map +1 -0
  26. package/lib/rbac-http/src/dto/login-dto.d.ts +20 -0
  27. package/lib/rbac-http/src/dto/login-dto.js +27 -0
  28. package/lib/rbac-http/src/dto/login-dto.js.map +1 -0
  29. package/lib/rbac-http/src/dto/password-dto.d.ts +22 -0
  30. package/lib/rbac-http/src/dto/password-dto.js +27 -0
  31. package/lib/rbac-http/src/dto/password-dto.js.map +1 -0
  32. package/lib/rbac-http/src/dto/user-dto.d.ts +42 -0
  33. package/lib/rbac-http/src/dto/user-dto.js +31 -0
  34. package/lib/rbac-http/src/dto/user-dto.js.map +1 -0
  35. package/lib/rbac-http/src/index.d.ts +8 -0
  36. package/lib/rbac-http/src/index.js +25 -0
  37. package/lib/rbac-http/src/index.js.map +1 -0
  38. package/lib/rbac-http/src/interfaces.d.ts +23 -0
  39. package/lib/rbac-http/src/interfaces.js +3 -0
  40. package/lib/rbac-http/src/interfaces.js.map +1 -0
  41. package/lib/rbac-http/src/middlewares.d.ts +11 -0
  42. package/lib/rbac-http/src/middlewares.js +85 -0
  43. package/lib/rbac-http/src/middlewares.js.map +1 -0
  44. package/lib/rbac-http/src/policies.d.ts +13 -0
  45. package/lib/rbac-http/src/policies.js +57 -0
  46. package/lib/rbac-http/src/policies.js.map +1 -0
  47. package/lib/rbac-http/src/route-args.d.ts +9 -0
  48. package/lib/rbac-http/src/route-args.js +24 -0
  49. package/lib/rbac-http/src/route-args.js.map +1 -0
  50. package/lib/rbac-http/src/transformers.d.ts +11 -0
  51. package/lib/rbac-http/src/transformers.js +34 -0
  52. package/lib/rbac-http/src/transformers.js.map +1 -0
  53. package/package.json +11 -10
@@ -1,5 +1,6 @@
1
- import { PermissionType } from './interfaces';
1
+ import { IRbacDescriptor, PermissionType } from './interfaces';
2
2
  export declare const ACL_CONTROLLER_DESCRIPTOR: unique symbol;
3
+ export declare function setRbacMetadata(target: any, callback: (meta: IRbacDescriptor) => void): void;
3
4
  /**
4
5
  * Assign resource for controller
5
6
  *
package/lib/decorators.js CHANGED
@@ -1,9 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FromUser = exports.Permission = exports.Resource = exports.ACL_CONTROLLER_DESCRIPTOR = void 0;
3
+ exports.FromUser = exports.Permission = exports.Resource = exports.setRbacMetadata = exports.ACL_CONTROLLER_DESCRIPTOR = void 0;
4
4
  const http_1 = require("@spinajs/http");
5
5
  const policies_1 = require("./policies");
6
6
  exports.ACL_CONTROLLER_DESCRIPTOR = Symbol('ACL_CONTROLLER_DESCRIPTOR_SYMBOL');
7
+ function setRbacMetadata(target, callback) {
8
+ let metadata = Reflect.getMetadata(exports.ACL_CONTROLLER_DESCRIPTOR, target.prototype || target);
9
+ if (!metadata) {
10
+ metadata = {
11
+ Resource: '',
12
+ Routes: new Map(),
13
+ Permission: 'readOwn',
14
+ };
15
+ Reflect.defineMetadata(exports.ACL_CONTROLLER_DESCRIPTOR, metadata, target.prototype || target);
16
+ }
17
+ if (callback) {
18
+ callback(metadata);
19
+ }
20
+ }
21
+ exports.setRbacMetadata = setRbacMetadata;
7
22
  function descriptor(callback) {
8
23
  return (target, propertyKey, indexOrDescriptor) => {
9
24
  let metadata = Reflect.getMetadata(exports.ACL_CONTROLLER_DESCRIPTOR, target.prototype || target);
@@ -28,7 +43,7 @@ function descriptor(callback) {
28
43
  */
29
44
  function Resource(resource, permission = 'readOwn') {
30
45
  return descriptor((metadata, target) => {
31
- (0, http_1.Policy)(policies_1.AclPolicy)(target, null, null);
46
+ (0, http_1.Policy)(policies_1.RbacPolicy)(target, null, null);
32
47
  metadata.Resource = resource;
33
48
  metadata.Permission = permission;
34
49
  });
@@ -54,7 +69,7 @@ function Permission(permission = 'readOwn') {
54
69
  }
55
70
  metadata.Routes.set(propertyKey, route);
56
71
  }
57
- (0, http_1.Policy)(policies_1.AclPolicy)(target, propertyKey, null);
72
+ (0, http_1.Policy)(policies_1.RbacPolicy)(target, propertyKey, null);
58
73
  });
59
74
  }
60
75
  exports.Permission = Permission;
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AACA,wCAAyD;AACzD,yCAAuC;AAE1B,QAAA,yBAAyB,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAEpF,SAAS,UAAU,CAAC,QAAyI;IAC3J,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,iBAA8C,EAAE,EAAE;QACnG,IAAI,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M,EAAC,qBAAU,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC;AAlBD,gCAkBC;AAED,SAAgB,QAAQ;IACtB,OAAO,IAAA,YAAK,EAAC,IAAA,gBAAS,EAAC,SAAS,CAAC,CAAC,CAAC;AACrC,CAAC;AAFD,4BAEC"}
@@ -0,0 +1,443 @@
1
+ import * as express from 'express';
2
+ import { Constructor, AsyncModule } from '@spinajs/di';
3
+ import { Configuration } from '@spinajs/configuration';
4
+ /**
5
+ * Accept header enum
6
+ */
7
+ export declare enum HttpAcceptHeaders {
8
+ /**
9
+ * Accept header for JSON
10
+ */
11
+ JSON = 1,
12
+ /**
13
+ * Accept header for HTML
14
+ */
15
+ HTML = 2,
16
+ /**
17
+ * Accept header for XML
18
+ */
19
+ XML = 4,
20
+ /**
21
+ * Accept all accept headers shorcut
22
+ */
23
+ ALL = 7
24
+ }
25
+ /**
26
+ * Config options for static files
27
+ */
28
+ export interface IHttpStaticFileConfiguration {
29
+ /**
30
+ * virtual prefix in url eg. http://localhost:3000/static/images/kitten.jpg
31
+ */
32
+ Route: string;
33
+ /**
34
+ * full path to folder with static content
35
+ */
36
+ Path: string;
37
+ }
38
+ /**
39
+ * Uploaded file fields
40
+ */
41
+ export interface IUploadedFile {
42
+ Size: number;
43
+ Path: string;
44
+ Name: string;
45
+ Type: string;
46
+ LastModifiedDate?: Date;
47
+ Hash?: string;
48
+ }
49
+ export interface Request extends express.Request {
50
+ storage: IActionLocalStoregeContext;
51
+ }
52
+ export interface IActionLocalStoregeContext {
53
+ requestId: string;
54
+ responseStart: Date;
55
+ }
56
+ export declare abstract class ServerMiddleware extends AsyncModule {
57
+ Order: number;
58
+ abstract before(): (req: express.Request, res: express.Response, next: express.NextFunction) => void | null;
59
+ abstract after(): (req: express.Request, res: express.Response, next: express.NextFunction) => void | null;
60
+ }
61
+ /**
62
+ * HTTP response statuses
63
+ */
64
+ export declare enum HTTP_STATUS_CODE {
65
+ /**
66
+ * All ok with content
67
+ */
68
+ OK = 200,
69
+ /**
70
+ * Request is OK and new resource has been created.
71
+ */
72
+ CREATED = 201,
73
+ /**
74
+ * Request is accepted, but has not been completed yet.
75
+ */
76
+ ACCEPTED = 202,
77
+ /**
78
+ * ALl is ok & no content to return
79
+ */
80
+ NO_CONTENT = 204,
81
+ /**
82
+ * The server is delivering only part of the resource (byte serving) due to a range header
83
+ * sent by the client. The range header is used by HTTP clients to enable resuming of
84
+ * interrupted downloads, or split a download into multiple simultaneous streams.
85
+ */
86
+ PARTIAL_CONTENT = 206,
87
+ /**
88
+ * Resource is not modified
89
+ */
90
+ NOT_MODIFIED = 304,
91
+ /**
92
+ * Invalid request, eg. invalid parameters
93
+ */
94
+ BAD_REQUEST = 400,
95
+ /**
96
+ * Auth required
97
+ */
98
+ UNAUTHORIZED = 401,
99
+ /**
100
+ * No permission
101
+ */
102
+ FORBIDDEN = 403,
103
+ /**
104
+ * Resource not found
105
+ */
106
+ NOT_FOUND = 404,
107
+ /**
108
+ * Not acceptable request headers (Accept header)
109
+ */
110
+ NOT_ACCEPTABLE = 406,
111
+ /**
112
+ * Conflict
113
+ */
114
+ CONFLICT = 409,
115
+ /**
116
+ * Internal server error.
117
+ */
118
+ INTERNAL_ERROR = 500,
119
+ /**
120
+ * Method not implemented
121
+ */
122
+ NOT_IMPLEMENTED = 501
123
+ }
124
+ /**
125
+ * Avaible route types, match HTTP methods
126
+ */
127
+ export declare enum RouteType {
128
+ /**
129
+ * POST method - used to create new resource or send data to server
130
+ */
131
+ POST = "post",
132
+ /**
133
+ * GET method - used to retrieve data from server
134
+ */
135
+ GET = "get",
136
+ /**
137
+ * PUT method - used to updates resource
138
+ */
139
+ PUT = "put",
140
+ /**
141
+ * DELETE method - used to delete resource
142
+ */
143
+ DELETE = "delete",
144
+ /**
145
+ * PATCH method - used to partially update resource eg. one field
146
+ */
147
+ PATCH = "patch",
148
+ /**
149
+ * HEAD method - same as get, but returns no data. usefull for checking if resource exists etc.
150
+ */
151
+ HEAD = "head",
152
+ /**
153
+ * FILE method - spine special route type. Internall its simple GET method, but informs that specified route returns binary file
154
+ */
155
+ FILE = "file",
156
+ UNKNOWN = "unknown"
157
+ }
158
+ export declare enum UuidVersion {
159
+ v1 = 0,
160
+ v3 = 1,
161
+ v4 = 2,
162
+ v5 = 3
163
+ }
164
+ /**
165
+ * Avaible route parameters type
166
+ */
167
+ export declare enum ParameterType {
168
+ /**
169
+ * Parameter is injected from DI container & resolved
170
+ */
171
+ FromDi = "FromDi",
172
+ /**
173
+ * Parameter value is taken from query string eg. `?name=flavio`
174
+ */
175
+ FromQuery = "FromQuery",
176
+ /**
177
+ * From message body, eg. POST json object
178
+ */
179
+ FromBody = "FromBody",
180
+ /**
181
+ * From url params eg: `/:id`
182
+ */
183
+ FromParams = "FromParams",
184
+ /**
185
+ * From form file field
186
+ */
187
+ FromFile = "FromFile",
188
+ /**
189
+ * From form
190
+ */
191
+ FromForm = "FromForm",
192
+ /**
193
+ * From cvs file
194
+ */
195
+ FromCSV = "FromCSV",
196
+ /**
197
+ * From JSON file
198
+ */
199
+ FromJSONFile = "FromJSONFile",
200
+ /**
201
+ * From form field
202
+ */
203
+ FormField = "FromFormField",
204
+ /**
205
+ * From model object
206
+ */
207
+ FromModel = "FromModel",
208
+ /**
209
+ * Data from coockie
210
+ */
211
+ FromCookie = "FromCookie",
212
+ /**
213
+ * From http header
214
+ */
215
+ FromHeader = "FromHeader",
216
+ /**
217
+ * Req from express
218
+ */
219
+ Req = "ArgAsRequest",
220
+ Res = "ArgAsResponse"
221
+ }
222
+ export interface IFormOptions {
223
+ multiples: boolean;
224
+ }
225
+ export interface IFormOptions {
226
+ /**
227
+ * default 1000; limit the number of fields that the Querystring parser will decode, set 0 for unlimited
228
+ */
229
+ maxFields?: number;
230
+ /**
231
+ * default 20 * 1024 * 1024 (20mb); limit the amount of memory all fields together (except files) can allocate in bytes.
232
+ */
233
+ maxFieldsSize?: number;
234
+ /**
235
+ * default 'utf-8'; sets encoding for incoming form fields,
236
+ */
237
+ encoding?: string;
238
+ }
239
+ export interface IUploadOptions {
240
+ /**
241
+ * default false; include checksums calculated for incoming files, set this to some hash algorithm, see crypto.createHash for available algorithms
242
+ */
243
+ hash?: false;
244
+ /**
245
+ * default os.tmpdir(); the directory for placing file uploads in. You can move them later by using fs.rename()
246
+ */
247
+ uploadDir?: string | ((cfg: Configuration) => string);
248
+ /**
249
+ * default false; when you call the .parse method, the files argument (of the callback) will contain arrays of files for inputs which submit multiple files using the HTML5 multiple attribute. Also, the fields argument will contain arrays of values for fields that have names ending with '[]'.
250
+ */
251
+ multiples?: boolean;
252
+ enabledPlugins?: string[];
253
+ /**
254
+ * default 200 * 1024 * 1024 (200mb); limit the size of uploaded file.
255
+ */
256
+ maxFileSize?: number;
257
+ /**
258
+ * default false; to include the extensions of the original files or not
259
+ */
260
+ keepExtensions?: boolean;
261
+ }
262
+ /**
263
+ * Describes parameters passed to route.
264
+ */
265
+ export interface IRouteParameter {
266
+ /**
267
+ * Parameter index in function args
268
+ */
269
+ Index: number;
270
+ /**
271
+ * Is value taken from query string, url params or message body
272
+ */
273
+ Type: ParameterType | string;
274
+ /**
275
+ * Schema for validation parameter ( raw value eg. to check if matches string / number constrain)
276
+ */
277
+ RouteParamSchema?: any;
278
+ /**
279
+ * Schema for paramater
280
+ */
281
+ Schema?: any;
282
+ /**
283
+ * Additional options
284
+ */
285
+ Options?: any;
286
+ /**
287
+ * Parameter runtime type eg. number or class
288
+ */
289
+ RuntimeType: any;
290
+ /**
291
+ * Name of parameter eg. `id`
292
+ */
293
+ Name: string;
294
+ }
295
+ /**
296
+ * Route action call spefici data. Used to pass data / arguments when parsing
297
+ * action parameters for specific call. Eg. to parse form data, and extract it
298
+ * as different arguments.
299
+ */
300
+ export interface IRouteCall {
301
+ Payload: any;
302
+ }
303
+ export interface IRoute {
304
+ /**
305
+ * url path eg. /foo/bar/:id
306
+ */
307
+ Path: string;
308
+ /**
309
+ * HTTP request method, used internally. Not visible to others.
310
+ */
311
+ InternalType: RouteType;
312
+ /**
313
+ * SPINAJS API method type, mostly same as HTTP type, but can be non standard type eg. FILE
314
+ * This type is visible outside in api discovery.
315
+ */
316
+ Type: RouteType;
317
+ /**
318
+ * Method name assigned to this route eg. `findUsers`
319
+ */
320
+ Method: string;
321
+ /**
322
+ * Custom route parameters taken from query string or message body
323
+ */
324
+ Parameters: Map<number, IRouteParameter>;
325
+ /**
326
+ * Assigned middlewares to route
327
+ */
328
+ Middlewares: IMiddlewareDescriptor[];
329
+ /**
330
+ * Assigned policies to route
331
+ */
332
+ Policies: IPolicyDescriptor[];
333
+ /**
334
+ * Additional route options eg. file size etc.
335
+ */
336
+ Options: any;
337
+ Schema: any;
338
+ }
339
+ export interface IMiddlewareDescriptor {
340
+ Type: Constructor<BaseMiddleware>;
341
+ Options: any[];
342
+ }
343
+ export interface IController {
344
+ /**
345
+ * Express router with middleware stack
346
+ */
347
+ Router: express.Router;
348
+ /**
349
+ * Controller descriptor
350
+ */
351
+ Descriptor: IControllerDescriptor;
352
+ /**
353
+ * Base path for all controller routes eg. my/custom/path/
354
+ *
355
+ * It can be defined via `@BasePath` decorator, defaults to controller name without `Controller` part.
356
+ */
357
+ BasePath: string;
358
+ }
359
+ /**
360
+ * Middlewares are classes that can change request object or perform specific task before & after route execution
361
+ * eg. route parameter logging / headers check etc.
362
+ */
363
+ export declare abstract class BaseMiddleware {
364
+ /**
365
+ * Inform, if middleware is enabled for given action
366
+ */
367
+ abstract isEnabled(action: IRoute, instance: IController): boolean;
368
+ /**
369
+ * Called before action in middleware stack eg. to modify req or resp objects.
370
+ */
371
+ abstract onBeforeAction(req: express.Request): Promise<void>;
372
+ /**
373
+ * Called after action in middleware stack eg. to modify response
374
+ */
375
+ abstract onAfterAction(req: express.Request): Promise<void>;
376
+ }
377
+ /**
378
+ * Descriptor for policies eg. attached routes, passed options eg. token etc.
379
+ */
380
+ export interface IPolicyDescriptor {
381
+ Type: Constructor<BasePolicy>;
382
+ Options: any[];
383
+ }
384
+ /**
385
+ * Base class for policies.
386
+ *
387
+ * Policies checks if route can be executed eg. user have proper role
388
+ */
389
+ export declare abstract class BasePolicy {
390
+ /**
391
+ * Checks if policy is enabled for given action & controlle eg. user session exists
392
+ *
393
+ * @param action action that is executed ( route info )
394
+ * @param instance controller instance
395
+ */
396
+ abstract isEnabled(action: IRoute, instance: IController): boolean;
397
+ /**
398
+ *
399
+ * Executes policy, when throws exception - route is not executed
400
+ *
401
+ * @param req express request object
402
+ */
403
+ abstract execute(req: express.Request, action: IRoute, instance: IController): Promise<void>;
404
+ }
405
+ /**
406
+ * Descriptor for controller
407
+ */
408
+ export interface IControllerDescriptor {
409
+ /**
410
+ * Controller routes
411
+ */
412
+ Routes: Map<string | symbol, IRoute>;
413
+ /**
414
+ * Controller - wise middlewares
415
+ */
416
+ Middlewares: IMiddlewareDescriptor[];
417
+ /**
418
+ * Controller - wise policies
419
+ */
420
+ Policies: IPolicyDescriptor[];
421
+ /**
422
+ * Base url path for controller ( added for all child url's)
423
+ */
424
+ BasePath: string;
425
+ }
426
+ /**
427
+ * Base class for data transformers.
428
+ *
429
+ * Data formatter helps transforms data for desired format.
430
+ * Eg. we have API function that returns some data, but we want
431
+ * to easily transform data for some client
432
+ * eg. plain array to format that datatables.net can easily read
433
+ */
434
+ export declare abstract class DataTransformer<T = any, U = any> {
435
+ /**
436
+ * Transforms data from one format to another
437
+ *
438
+ * @param data - input data
439
+ */
440
+ abstract transform(data: T, request: express.Request): U;
441
+ abstract get Type(): string;
442
+ }
443
+ export declare type RouteCallback = (req: express.Request, res: express.Response, next: express.NextFunction) => (req: express.Request, res: express.Response) => void;