@andrewcaires/api 4.5.2 → 5.0.1

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/dist/index.d.ts CHANGED
@@ -1,178 +1,179 @@
1
1
  /*!
2
- * @andrewcaires/api v4.5.2
2
+ * @andrewcaires/api v5.0.1
3
3
  * Simple api for small applications using express, jsonwebtoken, sequelize and websocket
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import { EventEmitter, TypeAnyObject, TypeObjectString, TypeObject, ValidationBase, TypeAnyFunction } from '@andrewcaires/utils.js';
8
- import { Application as Application$1, Context, IStore, IUpload, IFile } from '@andrewcaires/express';
9
- import { WhereOptions, Model as Model$1, CreateOptions, Attributes, FindOptions, UpdateOptions, FindAttributeOptions, ModelStatic } from 'sequelize';
10
- import { Model, Sequelize } from '@andrewcaires/sequelize';
7
+ import { Context, Application as Application$1, IOptions, IStore } from '@andrewcaires/express';
11
8
  import { Hash, Env as Env$1 } from '@andrewcaires/node';
9
+ import { Model, Sequelize } from '@andrewcaires/sequelize';
10
+ import { TypeAnyObject, TypeObjectString, TypeAnyFunction, TypeAnyConstructor, EventEmitter, TypeObject, ValidationBase } from '@andrewcaires/utils.js';
12
11
  import { WebSocketServer } from 'ws';
13
- import { Store as Store$1, SessionData } from 'express-session';
14
-
15
- declare abstract class Controller extends EventEmitter {
16
- static readonly ATTRIBUTES: unique symbol;
17
- static readonly PERMISSIONS: unique symbol;
18
- }
12
+ import { Model as Model$1, FindOptions, Attributes, CreateOptions, UpdateOptions, FindAttributeOptions, ModelStatic } from 'sequelize';
13
+ import { Store, SessionData } from 'express-session';
19
14
 
20
- declare class Auth extends Model {
21
- readonly id: number;
15
+ declare class RegisterModel extends Model {
16
+ readonly id: string;
22
17
  secret: string;
23
- logout: Date | null;
24
- user_agent: string;
18
+ expired_at: number;
19
+ state: boolean;
25
20
  readonly created_at: Date;
26
21
  readonly updated_at: Date;
27
22
  readonly deleted_at: Date | null;
28
- user_id: number;
29
- user: User;
23
+ user_id: string;
24
+ user: UserModel;
30
25
  }
31
26
 
32
- declare class Register extends Model {
33
- readonly id: number;
34
- token: string;
35
- state: boolean;
27
+ declare class UserAuthModel extends Model {
28
+ readonly id: string;
29
+ secret: string;
30
+ ip_address: string;
31
+ user_agent: string;
32
+ revoked_at: Date | null;
36
33
  readonly created_at: Date;
37
34
  readonly updated_at: Date;
38
35
  readonly deleted_at: Date | null;
39
- user_id: number;
40
- user: User;
36
+ user_id: string;
37
+ user: UserModel;
41
38
  }
42
39
 
43
- declare class Permission extends Model {
44
- readonly id: number;
40
+ declare class PermissionModel extends Model {
41
+ readonly id: string;
45
42
  name: string;
46
- route: string;
47
- tag: string;
43
+ key: string;
44
+ tags: string;
48
45
  description: string;
49
46
  state: boolean;
50
47
  readonly created_at: Date;
51
48
  readonly updated_at: Date;
52
49
  readonly deleted_at: Date | null;
53
- groups_permissions: Array<GroupPermission>;
50
+ groups_permissions: Array<GroupPermissionModel>;
54
51
  }
55
52
 
56
- declare class GroupPermission extends Model {
53
+ declare class GroupPermissionModel extends Model {
57
54
  readonly created_at: Date;
58
- group_id: number;
59
- group: Group;
60
- permission_id: number;
61
- permission: Permission;
55
+ group_id: string;
56
+ group: GroupModel;
57
+ permission_id: string;
58
+ permission: PermissionModel;
62
59
  }
63
60
 
64
- declare class Group extends Model {
65
- readonly id: number;
61
+ declare class GroupModel extends Model {
62
+ readonly id: string;
66
63
  name: string;
64
+ key: string;
65
+ tags: string;
67
66
  description: string;
68
67
  state: boolean;
69
68
  readonly created_at: Date;
70
69
  readonly updated_at: Date;
71
70
  readonly deleted_at: Date | null;
72
- groups_routes: Array<GroupPermission>;
73
- users_groups: Array<UserGroup>;
71
+ users_groups: Array<UserGroupModel>;
72
+ groups_Permission: Array<GroupPermissionModel>;
74
73
  }
75
74
 
76
- declare class UserGroup extends Model {
75
+ declare class UserGroupModel extends Model {
77
76
  readonly created_at: Date;
78
- group_id: number;
79
- group: Group;
80
- user_id: number;
81
- user: User;
77
+ group_id: string;
78
+ group: GroupModel;
79
+ user_id: string;
80
+ user: UserModel;
82
81
  }
83
82
 
84
- declare class UserHistory extends Model {
85
- password: string;
83
+ declare class UserPasswordModel extends Model {
84
+ readonly id: string;
85
+ value: string;
86
+ state: boolean;
86
87
  readonly created_at: Date;
87
- user_id: number;
88
- user: User;
88
+ readonly updated_at: Date;
89
+ readonly deleted_at: Date | null;
90
+ user_id: string;
91
+ user: UserModel;
92
+ }
93
+
94
+ declare class UserProfileModel extends Model {
95
+ readonly id: string;
96
+ data: TypeAnyObject;
97
+ readonly created_at: Date;
98
+ readonly updated_at: Date;
99
+ readonly deleted_at: Date | null;
100
+ user_id: string;
101
+ user: UserModel;
89
102
  }
90
103
 
91
- declare class User extends Model {
92
- readonly id: number;
104
+ declare class UserModel extends Model {
105
+ readonly id: string;
93
106
  name: string;
94
107
  email: string;
95
108
  username: string;
96
- password: string;
97
- salt: string;
98
- token: string;
99
- avatar: string;
100
- date: string;
101
109
  description: string;
102
110
  state: boolean;
103
111
  readonly created_at: Date;
104
112
  readonly updated_at: Date;
105
113
  readonly deleted_at: Date | null;
106
- audits: Array<Audit>;
107
- auths: Array<Auth>;
108
- registers: Array<Register>;
109
- users_groups: Array<UserGroup>;
110
- users_histories: Array<UserHistory>;
114
+ audits: Array<AuditModel>;
115
+ users_auths: Array<UserAuthModel>;
116
+ registers: Array<RegisterModel>;
117
+ users_groups: Array<UserGroupModel>;
118
+ users_passwords: Array<UserPasswordModel>;
119
+ users_profiles: Array<UserProfileModel>;
111
120
  }
112
121
 
113
- declare class Audit extends Model {
114
- readonly id: number;
115
- type: string;
122
+ declare class AuditModel extends Model {
123
+ readonly id: string;
124
+ type: "CREATE" | "DELETE" | "UPDATE";
116
125
  model: string;
117
126
  record: string;
118
127
  data: TypeAnyObject;
119
128
  previously: TypeAnyObject;
120
- client: string;
121
- href: string;
129
+ full_url: string;
130
+ ip_address: string;
122
131
  user_agent: string;
132
+ app_name: string;
123
133
  state: boolean;
124
134
  readonly created_at: Date;
125
135
  readonly updated_at: Date;
126
136
  readonly deleted_at: Date | null;
127
- user_id: number;
128
- user: User;
137
+ user_id: string;
138
+ user: UserModel;
129
139
  }
130
140
 
131
- declare class Config extends Model {
141
+ declare class ConfigModel extends Model {
142
+ readonly id: string;
132
143
  key: string;
133
144
  value: string;
134
145
  readonly created_at: Date;
135
146
  readonly updated_at: Date;
136
- static all(): Promise<TypeObjectString>;
137
- static del(key: string, user?: User): Promise<boolean>;
138
- static get(key: string, value?: string): Promise<string>;
139
- static set(key: string, value: string, user?: User): Promise<void>;
140
147
  }
141
148
 
142
- declare class Forgot extends Model {
143
- readonly id: number;
144
- token: string;
145
- timestamp: number;
149
+ declare class ForgotModel extends Model {
150
+ readonly id: string;
151
+ secret: string;
152
+ expired_at: number;
146
153
  state: boolean;
147
154
  readonly created_at: Date;
148
155
  readonly updated_at: Date;
149
156
  readonly deleted_at: Date | null;
150
- user_id: number;
151
- user: User;
157
+ user_id: string;
158
+ user: UserModel;
152
159
  }
153
160
 
154
- declare class Log extends Model {
155
- readonly id: number;
156
- type: string;
157
- source: string;
161
+ declare class LogModel extends Model {
162
+ readonly id: string;
163
+ level: "info" | "warn" | "error";
158
164
  message: string;
165
+ source: string;
159
166
  readonly created_at: Date;
160
- static write(message: string, source?: string, show?: boolean): Promise<void>;
161
- static error(message: string, source?: string, show?: boolean): Promise<void>;
162
- static info(message: string, source?: string, show?: boolean): Promise<void>;
163
- static success(message: string, source?: string, show?: boolean): Promise<void>;
164
- static warning(message: string, source?: string, show?: boolean): Promise<void>;
165
- private static writeRaw;
166
167
  }
167
168
 
168
- declare class Migration extends Model {
169
+ declare class MigrationModel extends Model {
169
170
  model: string;
170
171
  version: string;
171
172
  readonly created_at: Date;
172
173
  readonly updated_at: Date;
173
174
  }
174
175
 
175
- declare class Session extends Model {
176
+ declare class SessionModel extends Model {
176
177
  session: string;
177
178
  json: string;
178
179
  expired: number;
@@ -180,328 +181,472 @@ declare class Session extends Model {
180
181
  readonly updated_at: Date;
181
182
  }
182
183
 
183
- declare class Application extends Application$1 {
184
- readonly hash: Hash;
185
- private _webSocket?;
186
- constructor(controllers: Array<Controller>);
187
- error(error: any, source?: string): void;
188
- log(message: string, source?: string): void;
189
- listen(): Promise<void>;
190
- migrations(database: Sequelize): Promise<void>;
191
- websocket(): WebSocketServer | undefined;
184
+ declare class UserMetadataModel extends Model {
185
+ readonly id: string;
186
+ data: TypeAnyObject;
187
+ readonly created_at: Date;
188
+ readonly updated_at: Date;
189
+ readonly deleted_at: Date | null;
190
+ user_id: string;
191
+ user: UserModel;
192
192
  }
193
193
 
194
- declare abstract class ControllerBase extends Controller {
195
- protected [Controller.PERMISSIONS]: Array<string>;
196
- auth(ctx: Context, key_header: string, token_header: string, token_cookie: string, key_query: string, user_agent: string, app: Application): Promise<void>;
197
- canCreate(ctx: Context, name: string, user: User): Promise<void>;
198
- canDelete(ctx: Context, name: string, user: User): Promise<void>;
199
- canRead(ctx: Context, name: string, user: User): Promise<void>;
200
- canUpdate(ctx: Context, name: string, user: User): Promise<void>;
201
- error(error: any): void;
202
- name(): string;
203
- permission(ctx: Context, route: string, user: User): Promise<void>;
204
- permissions(user: User, where?: WhereOptions): Promise<Array<Permission>>;
205
- session(ctx: Context, user_agent: string, store: IStore): Promise<void>;
206
- sync(): Promise<void>;
207
- upload(ctx: Context, options: IUpload): void;
208
- validation(ctx: Context, options: TypeObject<ValidationBase>): Promise<void>;
194
+ interface IAuthParameters {
195
+ auth?: UserAuthModel;
196
+ decode?: TypeAnyObject;
197
+ forgot?: ForgotModel;
198
+ token?: string;
199
+ user?: UserModel;
200
+ }
201
+
202
+ interface AuthEvents {
203
+ "auth.activation": {
204
+ ctx: Context;
205
+ register: RegisterModel;
206
+ user: UserModel;
207
+ };
208
+ "auth.failure": {
209
+ ctx: Context;
210
+ user?: UserModel;
211
+ };
212
+ "auth.login": {
213
+ ctx: Context;
214
+ auth: UserAuthModel;
215
+ user: UserModel;
216
+ };
217
+ "auth.logout": {
218
+ ctx: Context;
219
+ auth: UserAuthModel;
220
+ user: UserModel;
221
+ };
222
+ "auth.renew": {
223
+ ctx: Context;
224
+ auth: UserAuthModel;
225
+ };
226
+ }
227
+
228
+ interface ForgotEvents {
229
+ "forgot.reset": {
230
+ ctx: Context;
231
+ user?: UserModel;
232
+ };
233
+ "forgot.send": {
234
+ ctx: Context;
235
+ forgot: ForgotModel;
236
+ user: UserModel;
237
+ };
238
+ }
239
+
240
+ interface RegisterEvents {
241
+ "register.confirm": {
242
+ ctx: Context;
243
+ register: RegisterModel;
244
+ user?: UserModel;
245
+ };
246
+ "register.send": {
247
+ ctx: Context;
248
+ register: RegisterModel;
249
+ user?: UserModel;
250
+ };
251
+ "register.user": {
252
+ ctx: Context;
253
+ register: RegisterModel;
254
+ user?: UserModel;
255
+ };
256
+ }
257
+
258
+ interface ApplicationEvents extends AuthEvents, ForgotEvents, RegisterEvents {
259
+ }
260
+
261
+ declare module "express-serve-static-core" {
262
+ interface Request {
263
+ auth?: UserAuthModel;
264
+ }
265
+ }
266
+
267
+ declare module "express-serve-static-core" {
268
+ interface Request {
269
+ groups?: Array<string>;
270
+ }
271
+ }
272
+
273
+ declare module "express-serve-static-core" {
274
+ interface Request {
275
+ permissions?: Array<string>;
276
+ }
277
+ }
278
+
279
+ declare module "express-serve-static-core" {
280
+ interface Request {
281
+ profile?: TypeObjectString;
282
+ }
283
+ }
284
+
285
+ declare module "express-serve-static-core" {
286
+ interface Request {
287
+ user?: UserModel;
288
+ }
289
+ }
290
+
291
+ interface ModelArgumentsBase<M extends Model$1<M>> {
292
+ ctx?: Context;
209
293
  }
210
294
 
211
- interface ArgumentsModel<M extends Model$1<M>> {
212
- ctx: Context;
295
+ interface ModelArgumentsCount<M extends Model$1<any>> extends ModelArgumentsBase<M> {
296
+ options?: FindOptions<Attributes<M>>;
213
297
  }
214
298
 
215
- interface ArgumentsModelCreate<M extends Model$1<M>> extends ArgumentsModel<M> {
299
+ interface ModelArgumentsCreate<M extends Model$1<M>> extends ModelArgumentsBase<M> {
216
300
  options?: CreateOptions<Attributes<M>>;
217
301
  body?: TypeAnyObject;
218
302
  }
219
303
 
220
- interface ArgumentsModelDelete<M extends Model$1<M>> extends ArgumentsModel<M> {
304
+ interface ModelArgumentsDelete<M extends Model$1<M>> extends ModelArgumentsBase<M> {
305
+ id?: string | number;
221
306
  options?: FindOptions<Attributes<M>>;
222
307
  }
223
308
 
224
- type CallbackModelAll<M> = (_records: Array<M>) => Array<any> | Promise<Array<any>>;
309
+ type ModelCallbackFindAll<M> = (_records: Array<M>) => Array<any> | Promise<Array<any>>;
225
310
 
226
- interface ArgumentsModelFindAll<M extends Model$1<any>> extends ArgumentsModel<M> {
311
+ interface ModelArgumentsFindAll<M extends Model$1<any>> extends ModelArgumentsBase<M> {
227
312
  options?: FindOptions<Attributes<M>>;
228
- callback?: CallbackModelAll<M>;
229
- scope?: string;
230
- advanced?: boolean;
231
- attributes?: Array<string>;
313
+ callback?: ModelCallbackFindAll<M>;
232
314
  limited?: boolean;
233
315
  }
234
316
 
235
- type CallbackModelGet<M> = (_records: M) => any | Promise<any>;
317
+ type ModelCallbackFindOne<M> = (_records: M) => any | Promise<any>;
236
318
 
237
- interface ArgumentsModelFindOne<M extends Model$1<M>> extends ArgumentsModel<M> {
319
+ interface ModelArgumentsFindOne<M extends Model$1<M>> extends ModelArgumentsBase<M> {
238
320
  options?: FindOptions<Attributes<M>>;
239
- callback?: CallbackModelGet<M>;
240
- scope?: string;
321
+ callback?: ModelCallbackFindOne<M>;
241
322
  }
242
323
 
243
- interface ArgumentsModelUpdate<M extends Model$1<M>> extends ArgumentsModel<M> {
324
+ interface ModelArgumentsUpdate<M extends Model$1<M>> extends ModelArgumentsBase<M> {
325
+ id?: string | number;
244
326
  options?: UpdateOptions<Attributes<M>>;
245
327
  body?: TypeAnyObject;
246
328
  }
247
329
 
248
- interface IAuthParameters {
249
- auth?: Auth;
250
- decode?: TypeAnyObject;
251
- error?: string;
252
- forgot?: Forgot;
253
- token?: string;
254
- user?: User;
330
+ interface ModelOptions {
331
+ attributes?: FindAttributeOptions;
332
+ permissions?: Array<string>;
255
333
  }
256
334
 
257
- interface ResultModelAll<M extends Model$1<M>> {
335
+ interface ModelResultFindAll<M extends Model<M>> {
258
336
  count: number;
259
337
  records: Array<M>;
260
338
  }
261
339
 
262
- declare abstract class ControllerModel<M extends Model$1<any>> extends ControllerBase {
263
- protected [ControllerBase.ATTRIBUTES]: Array<string>;
264
- protected [ControllerBase.PERMISSIONS]: Array<string>;
265
- protected attributes(options: FindAttributeOptions): Array<string>;
266
- protected create({ ctx, options, body }: ArgumentsModelCreate<M>): Promise<M | void>;
267
- protected delete({ ctx, options }: ArgumentsModelDelete<M>): Promise<number>;
268
- error(error: any): void;
269
- protected findAll({ ctx, options, callback, scope, advanced, attributes, limited }: ArgumentsModelFindAll<M>): Promise<ResultModelAll<M>>;
270
- protected findOne({ ctx, options, callback, scope }: ArgumentsModelFindOne<M>): Promise<M | void>;
271
- abstract model(): ModelStatic<M>;
340
+ declare class Loggable {
341
+ get log(): (message: string) => void;
342
+ static get log(): (message: string) => void;
343
+ get error(): (error: any) => void;
344
+ static get error(): (error: any) => void;
345
+ private static logError;
346
+ private static logInfo;
347
+ private static source;
348
+ }
349
+
350
+ declare class Config extends Loggable {
351
+ static all(keys?: Array<string>): Promise<TypeObjectString>;
352
+ static del(key: string): Promise<boolean>;
353
+ static get(key: string, value?: string): Promise<string>;
354
+ static set(key: string, value: string): Promise<void>;
355
+ }
356
+
357
+ declare class Log {
358
+ protected static colors: TypeAnyObject;
359
+ static error(message: string, source?: string, show?: boolean): Promise<void>;
360
+ static info(message: string, source?: string, show?: boolean): Promise<void>;
361
+ static warn(message: string, source?: string, show?: boolean): Promise<void>;
362
+ private static writeRaw;
363
+ }
364
+
365
+ declare class SessionStore extends Store {
366
+ private loop;
367
+ constructor();
368
+ all: (callback: TypeAnyFunction) => Promise<void>;
369
+ clear: (callback: TypeAnyFunction) => Promise<void>;
370
+ destroy: (session_id: string, callback: TypeAnyFunction) => Promise<void>;
371
+ expired: () => Promise<void>;
372
+ get: (session_id: string, callback: TypeAnyFunction) => Promise<void>;
373
+ length: (callback: TypeAnyFunction) => Promise<void>;
374
+ set: (session_id: any, session: SessionData, callback: TypeAnyFunction) => Promise<void>;
375
+ }
376
+
377
+ interface Service extends Loggable {
378
+ }
379
+ declare abstract class Service {
380
+ }
381
+
382
+ declare class AuthService extends Service {
383
+ create(user: UserModel): Promise<IAuthParameters>;
384
+ destroy(auth?: UserAuthModel): Promise<boolean>;
385
+ renew(token: string): Promise<IAuthParameters>;
386
+ user(token: string): Promise<IAuthParameters>;
387
+ private options;
388
+ private verify;
389
+ key(value: string): Promise<IAuthParameters>;
390
+ }
391
+
392
+ declare class ModelService<M extends Model$1<any>> extends Service {
393
+ protected model: ModelStatic<M>;
394
+ protected attributes: Array<string>;
395
+ protected filter: FindAttributeOptions;
396
+ protected permissions: Array<string>;
397
+ constructor(model: ModelStatic<M>, options?: ModelOptions);
398
+ countAll({ ctx, options }: ModelArgumentsCount<M>): Promise<number>;
399
+ create({ ctx, options, body }: ModelArgumentsCreate<M>): Promise<M | null>;
400
+ delete({ ctx, options, id: _id }: ModelArgumentsDelete<M>): Promise<number>;
401
+ private filterAttributes;
402
+ findAll({ ctx, options, callback, limited }: ModelArgumentsFindAll<M>): Promise<ModelResultFindAll<M>>;
403
+ findOne({ ctx, options, callback }: ModelArgumentsFindOne<M>): Promise<M | null>;
404
+ getAttributes(options: FindAttributeOptions): Array<string>;
272
405
  sync(): Promise<void>;
273
- protected update({ ctx, options, body }: ArgumentsModelUpdate<M>): Promise<boolean>;
274
- key(): string;
406
+ update({ ctx, options, body, id: _id }: ModelArgumentsUpdate<M>): Promise<boolean>;
275
407
  name(): string;
276
- scope(name?: string): ModelStatic<M>;
277
408
  }
278
409
 
279
- declare abstract class ControllerCrud<M extends Model$1<any>> extends ControllerModel<M> {
280
- private _crud;
281
- CrudArgumentsCreate(ctx: Context): ArgumentsModelUpdate<M>;
282
- CrudArgumentsFindAll(ctx: Context): ArgumentsModelFindAll<M>;
283
- CrudArgumentsFindOne(ctx: Context): ArgumentsModelFindOne<M>;
284
- CrudArgumentsDelete(ctx: Context): ArgumentsModelDelete<M>;
285
- CrudArgumentsUpdate(ctx: Context): ArgumentsModelUpdate<M>;
286
- CrudValidationCreate(): TypeObject<ValidationBase>;
287
- CrudValidationUpdate(): TypeObject<ValidationBase>;
288
- protected add(ctx: Context): Promise<void>;
289
- protected all(ctx: Context): Promise<void>;
290
- protected del(ctx: Context): Promise<void>;
291
- protected get(ctx: Context): Promise<void>;
292
- protected set(ctx: Context): Promise<void>;
293
- protected validationCreate(ctx: Context): Promise<void>;
294
- protected validationUpdate(ctx: Context): Promise<void>;
410
+ declare class UserService extends Service {
411
+ getMetadata(user_id: string): Promise<TypeObjectString>;
412
+ getProfile(user_id: string): Promise<TypeObjectString>;
413
+ getGroups(user_id: string): Promise<Array<string>>;
414
+ getPermissions(user_id: string): Promise<Array<string>>;
295
415
  }
296
416
 
297
- declare class Env extends Env$1 {
298
- static readonly API_BASE_NAME: string;
299
- static readonly API_BODYPARSER_STRICT: boolean;
300
- static readonly API_BODYPARSER_INFLATE: boolean;
301
- static readonly API_BODYPARSER_LIMIT: string;
302
- static readonly API_BODYPARSER_TYPE: string;
303
- static readonly API_CONSOLE_ERROR: boolean;
304
- static readonly API_DATABASE_URL: string;
305
- static readonly API_DATABASE_LOG: boolean;
306
- static readonly API_DATABASE_AUDIT: boolean;
307
- static readonly API_DATABASE_PREFIX: string;
308
- static readonly API_DATABASE_TIMEZONE: string;
309
- static readonly API_HTTP_CRT: string;
310
- static readonly API_HTTP_KEY: string;
311
- static readonly API_HTTP_PORT: number;
312
- static readonly API_HTTP_PUBLIC: string;
313
- static readonly API_HTTP_CROSS: boolean;
314
- static readonly API_HTTP_HYBRID: boolean;
315
- static readonly API_HTTP_NOTFOUND: string;
316
- static readonly API_HTTP_PATH: string;
317
- static readonly API_HTTP_REDIRECT: string;
318
- static readonly API_KEY_HASH: string;
319
- static readonly API_KEY_HEADER: string;
320
- static readonly API_MODEL_LIMIT: number;
321
- static readonly API_MODEL_LIMIT_MAX: number;
322
- static readonly API_SLEEP_AUTH: number;
323
- static readonly API_SLEEP_FORGOT: number;
324
- static readonly API_SLEEP_REGISTRY: number;
325
- static readonly API_SESSION_NAME: string;
326
- static readonly API_SESSION_LIFETIME: number;
327
- static readonly API_SESSION_SECRET: string;
328
- static readonly API_TOKEN_COOKIE: string;
329
- static readonly API_TOKEN_COOKIE_SET: boolean;
330
- static readonly API_TOKEN_CRT: string;
331
- static readonly API_TOKEN_KEY: string;
332
- static readonly API_TOKEN_FORGOT: number;
333
- static readonly API_TOKEN_HEADER: string;
334
- static readonly API_TOKEN_HEADER_KEY: string;
335
- static readonly API_TOKEN_LIFETIME: number;
336
- static readonly API_TOKEN_RENEW: number;
337
- static readonly API_UPLOAD_COUNT: number;
338
- static readonly API_UPLOAD_FIELD: string;
339
- static readonly API_UPLOAD_SIZE: number;
340
- static readonly API_UPLOAD_TEMP: string;
341
- static readonly API_USER_HISTORY: boolean;
342
- static readonly API_WEBSOCKET_START: boolean;
417
+ declare class Application<T extends TypeAnyObject = ApplicationEvents> extends Application$1<T> {
418
+ readonly hash: Hash;
419
+ authService: AuthService;
420
+ userService: UserService;
421
+ private _webSocket?;
422
+ constructor(controllers: Array<object | TypeAnyConstructor<object>>, options?: IOptions);
423
+ error(error: any, source?: string): void;
424
+ log(message: string, source?: string): void;
425
+ listen(): Promise<void>;
426
+ migrations(database: Sequelize): Promise<void>;
427
+ websocket(): WebSocketServer | undefined;
428
+ }
429
+
430
+ interface BaseController extends Loggable {
431
+ }
432
+ declare abstract class BaseController<T extends TypeAnyObject = TypeAnyObject> extends EventEmitter<T> {
433
+ protected readonly permissions: Array<string>;
434
+ name(): string;
435
+ session(ctx: Context, user_agent: string, store: IStore): Promise<void>;
436
+ sync(): Promise<void>;
343
437
  }
344
438
 
345
- declare class AuditsController extends ControllerModel<Audit> {
346
- model(): typeof Audit;
439
+ declare abstract class ModelController<M extends Model$1<any>, T extends TypeAnyObject = TypeAnyObject> extends BaseController<T> {
440
+ protected readonly attributes: Array<string>;
441
+ protected abstract readonly model: ModelStatic<M>;
442
+ protected readonly permissions: Array<string>;
443
+ private service;
444
+ protected countAll(options: ModelArgumentsCount<M>): Promise<number>;
445
+ protected create(options: ModelArgumentsCreate<M>): Promise<M | null>;
446
+ protected delete(options: ModelArgumentsDelete<M>): Promise<number>;
447
+ protected findAll(options: ModelArgumentsFindAll<M>): Promise<ModelResultFindAll<M>>;
448
+ protected findOne(options: ModelArgumentsFindOne<M>): Promise<M | null>;
449
+ sync(): Promise<void>;
450
+ protected update(options: ModelArgumentsUpdate<M>): Promise<boolean>;
451
+ name(): string;
452
+ }
453
+
454
+ declare class AuditsController extends ModelController<AuditModel> {
455
+ protected readonly model: typeof AuditModel;
456
+ protected readonly permissions: string[];
347
457
  protected all(ctx: Context, type: string, table: string): Promise<void>;
348
458
  protected get(ctx: Context): Promise<void>;
349
459
  }
350
460
 
351
- declare class AuthController extends ControllerBase {
461
+ declare class AuthController extends BaseController<AuthEvents> {
462
+ protected readonly authService: AuthService;
463
+ constructor(authService: AuthService);
352
464
  protected login(ctx: Context, user_agent: string, username: string, password: string, remember: boolean, app: Application): Promise<void>;
353
- protected logout(ctx: Context, auth: Auth, user: User, app: Application): Promise<void>;
465
+ protected logout(ctx: Context, auth: UserAuthModel, user: UserModel, app: Application): Promise<void>;
354
466
  protected renew(ctx: Context, user_agent: string, old: string, app: Application): Promise<void>;
355
- protected user(ctx: Context, user: User): Promise<void>;
467
+ protected user(ctx: Context, user: UserModel): Promise<void>;
468
+ }
469
+
470
+ declare abstract class CrudController<M extends Model$1<any>, T extends TypeAnyObject = TypeAnyObject> extends ModelController<M, T> {
471
+ private _crud;
472
+ CrudArgumentscountAll(ctx: Context): ModelArgumentsUpdate<M>;
473
+ CrudArgumentsCreate(ctx: Context): ModelArgumentsUpdate<M>;
474
+ CrudArgumentsFindAll(ctx: Context): ModelArgumentsFindAll<M>;
475
+ CrudArgumentsFindOne(ctx: Context): ModelArgumentsFindOne<M>;
476
+ CrudArgumentsDelete(ctx: Context): ModelArgumentsDelete<M>;
477
+ CrudArgumentsUpdate(ctx: Context): ModelArgumentsUpdate<M>;
478
+ CrudValidationCreate(): TypeObject<ValidationBase>;
479
+ CrudValidationUpdate(): TypeObject<ValidationBase>;
480
+ protected add(ctx: Context): Promise<void>;
481
+ protected all(ctx: Context): Promise<void>;
482
+ protected number(ctx: Context): Promise<void>;
483
+ protected del(ctx: Context): Promise<void>;
484
+ protected get(ctx: Context): Promise<void>;
485
+ protected set(ctx: Context): Promise<void>;
486
+ protected validationCreate(ctx: Context): Promise<void>;
487
+ protected validationUpdate(ctx: Context): Promise<void>;
356
488
  }
357
489
 
358
- declare class FilesController extends ControllerBase {
359
- protected [ControllerBase.PERMISSIONS]: Array<string>;
360
- directory(): string;
490
+ declare class FilesController extends BaseController {
491
+ protected readonly directory: string;
492
+ protected readonly permissions: Array<string>;
361
493
  protected files(ctx: Context): Promise<TypeAnyObject | void>;
362
- protected access(ctx: Context, name: string, user: User): Promise<void>;
363
494
  private info;
364
495
  name(): string;
365
496
  sync(): Promise<void>;
366
497
  }
367
498
 
368
- declare class ForgotController extends ControllerBase {
499
+ declare class ForgotController extends BaseController<ForgotEvents> {
369
500
  protected check(ctx: Context, token: string): Promise<void>;
370
501
  protected forgot(ctx: Context, username: string, app: Application): Promise<void>;
371
502
  protected reset(ctx: Context, token: string, password: string, app: Application): Promise<void>;
372
503
  private find;
373
504
  }
374
505
 
375
- declare class GroupsController extends ControllerCrud<Group> {
506
+ declare class GroupsController extends CrudController<GroupModel> {
507
+ protected readonly model: typeof GroupModel;
376
508
  private schemaCreate;
377
509
  private schemaUpdate;
378
- model(): typeof Group;
379
- CrudArgumentsFindAll(ctx: Context): ArgumentsModelFindAll<Group>;
380
510
  CrudValidationCreate(): TypeObject<ValidationBase>;
381
511
  CrudValidationUpdate(): TypeObject<ValidationBase>;
382
512
  }
383
513
 
384
- declare class GroupsPermissionsController extends ControllerModel<GroupPermission> {
385
- model(): typeof GroupPermission;
514
+ declare class GroupsPermissionsController extends ModelController<GroupPermissionModel> {
515
+ protected readonly model: typeof GroupPermissionModel;
516
+ protected readonly permissions: never[];
386
517
  protected all(ctx: Context, group_id: string): Promise<void>;
387
- protected me(ctx: Context, user: User): Promise<void>;
388
- protected set(ctx: Context, id: string, permissions: Array<number>, audit: TypeAnyObject): Promise<void>;
518
+ protected set(ctx: Context, id: string, permissions: Array<string>): Promise<void>;
389
519
  }
390
520
 
391
- declare class LogsController extends ControllerModel<Log> {
392
- protected [ControllerModel.PERMISSIONS]: Array<string>;
393
- model(): typeof Log;
394
- protected all(ctx: Context, type: string, source: string): Promise<void>;
521
+ declare class LogsController extends ModelController<LogModel> {
522
+ protected readonly model: typeof LogModel;
523
+ protected readonly permissions: Array<string>;
524
+ protected all(ctx: Context): Promise<void>;
395
525
  }
396
526
 
397
- declare class PermissionsController extends ControllerCrud<Permission> {
527
+ declare class PermissionsController extends CrudController<PermissionModel> {
528
+ protected readonly model: typeof PermissionModel;
398
529
  private schemaCreate;
399
530
  private schemaUpdate;
400
- model(): typeof Permission;
401
- CrudArgumentsFindAll(ctx: Context): ArgumentsModelFindAll<Permission>;
402
531
  CrudValidationCreate(): TypeObject<ValidationBase>;
403
532
  CrudValidationUpdate(): TypeObject<ValidationBase>;
404
533
  }
405
534
 
406
- declare class RegisterController extends ControllerBase {
535
+ declare class RegisterController extends BaseController<RegisterEvents> {
407
536
  protected register(ctx: Context, body: TypeAnyObject, app: Application): Promise<void>;
408
537
  protected confirm(ctx: Context, token: string, app: Application): Promise<void>;
409
538
  protected send(ctx: Context, username: string, app: Application): Promise<void>;
410
539
  private getId;
411
540
  }
412
541
 
413
- declare class SetupController extends ControllerBase {
414
- protected setup(ctx: Context, audit: TypeAnyObject): Promise<void>;
542
+ declare class SetupController extends BaseController {
543
+ protected setup(ctx: Context): Promise<void>;
415
544
  }
416
545
 
417
- declare class UsersController extends ControllerModel<User> {
546
+ declare class UsersController extends ModelController<UserModel> {
547
+ protected readonly model: typeof UserModel;
418
548
  path: string;
419
- model(): typeof User;
420
549
  constructor();
421
- protected avatar(ctx: Context, files: Array<IFile>, user: User, audit: TypeAnyObject): Promise<void>;
422
- protected avatar_del(ctx: Context, user: User, audit: TypeAnyObject): Promise<void>;
423
- protected password(ctx: Context, oldPassword: string, newPassword: string, user: User, audit: TypeAnyObject): Promise<void>;
424
- protected token(ctx: Context, user: User, app: Application): Promise<void>;
425
- protected token_del(ctx: Context, id: string, audit: TypeAnyObject): Promise<void>;
426
- protected token_get(ctx: Context, id: string, app: Application): Promise<void>;
427
- protected token_renew(ctx: Context, id: string, audit: TypeAnyObject, app: Application): Promise<void>;
550
+ protected avatar(ctx: Context, user: UserModel): Promise<void>;
428
551
  private token_new;
429
- protected add(ctx: Context, password: string): Promise<void>;
552
+ protected add(ctx: Context): Promise<void>;
430
553
  protected all(ctx: Context): Promise<void>;
431
- protected del(ctx: Context, id: string, user: User): Promise<void>;
554
+ protected number(ctx: Context): Promise<void>;
555
+ protected del(ctx: Context, id: string, user: UserModel): Promise<void>;
432
556
  protected get(ctx: Context): Promise<void>;
433
- protected set(ctx: Context, id: string, password: string): Promise<void>;
557
+ protected set(ctx: Context): Promise<void>;
434
558
  }
435
559
 
436
- declare class UsersGroupsController extends ControllerModel<UserGroup> {
437
- model(): typeof UserGroup;
560
+ declare class UsersGroupsController extends ModelController<UserGroupModel> {
561
+ protected readonly model: typeof UserGroupModel;
562
+ protected readonly permissions: never[];
438
563
  protected all(ctx: Context, user_id: string): Promise<void>;
439
- protected me(ctx: Context, user: User): Promise<void>;
440
- protected set(ctx: Context, id: string, groups: Array<number>, audit: TypeAnyObject): Promise<void>;
564
+ protected set(ctx: Context, id: string, groups: Array<string>): Promise<void>;
441
565
  }
442
566
 
443
- declare const database: Sequelize;
567
+ declare class UsersProfilesController extends ModelController<UserProfileModel> {
568
+ protected readonly model: typeof UserProfileModel;
569
+ protected readonly permissions: never[];
570
+ protected all(ctx: Context): Promise<void>;
571
+ protected get(ctx: Context, user_id: string): Promise<void>;
572
+ protected set(ctx: Context, id: string, body: TypeAnyObject): Promise<void>;
573
+ }
444
574
 
445
- declare const ReqAudit: (key?: string) => ParameterDecorator;
575
+ declare const sequelize: Sequelize;
446
576
 
447
- declare const ReqAuth: (key?: string) => ParameterDecorator;
577
+ declare const CanCreate: (name?: string) => MethodDecorator;
448
578
 
449
- declare const ReqUser: (key?: string) => ParameterDecorator;
579
+ declare const CanDelete: (name?: string) => MethodDecorator;
450
580
 
451
- declare global {
452
- export namespace Express {
453
- interface Request {
454
- auth?: Auth;
455
- user?: User;
456
- }
457
- }
458
- }
581
+ declare const canFactory: (key: string) => (name?: string) => MethodDecorator;
459
582
 
460
- declare class AuthBase {
461
- protected static error(error: any): void;
462
- }
583
+ declare const CanRead: (name?: string) => MethodDecorator;
463
584
 
464
- declare class AuthKey extends AuthBase {
465
- static user(key: string, app: Application): Promise<IAuthParameters>;
466
- }
585
+ declare const CanUpdate: (name?: string) => MethodDecorator;
467
586
 
468
- declare class AuthToken extends AuthBase {
469
- private static options;
470
- static create(user: User): Promise<IAuthParameters>;
471
- static destroy(auth?: Auth): Promise<boolean>;
472
- static renew(token: string): Promise<IAuthParameters>;
473
- static user(token: string): Promise<IAuthParameters>;
474
- private static verify;
475
- }
587
+ declare const HasGroups: (...groups: Array<string>) => MethodDecorator;
476
588
 
477
- declare const audit: (ctx: Context) => TypeAnyObject;
589
+ declare const HasPermissions: (...permissions: Array<string>) => MethodDecorator;
478
590
 
479
- declare const hooks: {
480
- afterCreate: (record: Model, options: TypeAnyObject) => Promise<void>;
481
- afterUpdate: (record: Model, options: TypeAnyObject) => Promise<void>;
482
- afterDestroy: (record: Model, options: TypeAnyObject) => Promise<void>;
483
- };
591
+ declare const IsAuthenticated: () => MethodDecorator;
484
592
 
485
- declare const crt: {
486
- http: Buffer<ArrayBufferLike> | undefined;
487
- token: Buffer<ArrayBufferLike> | undefined;
488
- };
489
- declare const key: {
490
- http: Buffer<ArrayBufferLike> | undefined;
491
- token: Buffer<ArrayBufferLike> | undefined;
492
- };
593
+ declare const ReqAuth: (key?: string) => ParameterDecorator;
493
594
 
494
- declare class Store extends Store$1 {
495
- private loop;
496
- constructor();
497
- all: (callback: TypeAnyFunction) => Promise<void>;
498
- clear: (callback: TypeAnyFunction) => Promise<void>;
499
- destroy: (session_id: string, callback: TypeAnyFunction) => Promise<void>;
500
- expired: () => Promise<void>;
501
- get: (session_id: string, callback: TypeAnyFunction) => Promise<void>;
502
- length: (callback: TypeAnyFunction) => Promise<void>;
503
- set: (session_id: any, session: SessionData, callback: TypeAnyFunction) => Promise<void>;
595
+ declare const ReqGroup: (key?: string) => ParameterDecorator;
596
+
597
+ declare const ReqGroups: (key?: string) => ParameterDecorator;
598
+
599
+ declare const ReqPermission: (key?: string) => ParameterDecorator;
600
+
601
+ declare const ReqPermissions: (key?: string) => ParameterDecorator;
602
+
603
+ declare const ReqUser: (key?: string) => ParameterDecorator;
604
+
605
+ declare const Audit: (active?: boolean) => ClassDecorator;
606
+
607
+ declare class Env extends Env$1 {
608
+ static readonly BASE_NAME: string;
609
+ static readonly CONSOLE_ERROR: boolean;
610
+ static readonly DATABASE_URI: string;
611
+ static readonly DATABASE_LOG: boolean;
612
+ static readonly DATABASE_AUDIT: boolean;
613
+ static readonly DATABASE_PREFIX: string;
614
+ static readonly DATABASE_TIMEZONE: string;
615
+ static readonly HTTP_CRT: Buffer<ArrayBufferLike> | null;
616
+ static readonly HTTP_KEY: Buffer<ArrayBufferLike> | null;
617
+ static readonly SLEEP_AUTH: number;
618
+ static readonly SLEEP_FORGOT: number;
619
+ static readonly SLEEP_REGISTRY: number;
620
+ static readonly TOKEN_CRT: Buffer<ArrayBufferLike> | null;
621
+ static readonly TOKEN_KEY: Buffer<ArrayBufferLike> | null;
622
+ static readonly TOKEN_TTL: number;
623
+ static readonly API_BODYPARSER_STRICT: boolean;
624
+ static readonly API_BODYPARSER_INFLATE: boolean;
625
+ static readonly API_BODYPARSER_LIMIT: string;
626
+ static readonly API_BODYPARSER_TYPE: string;
627
+ static readonly API_HTTP_PORT: number;
628
+ static readonly API_HTTP_PUBLIC: string;
629
+ static readonly API_HTTP_CROSS: boolean;
630
+ static readonly API_HTTP_HYBRID: boolean;
631
+ static readonly API_HTTP_NOTFOUND: string;
632
+ static readonly API_HTTP_PATH: string;
633
+ static readonly API_HTTP_REDIRECT: string;
634
+ static readonly API_KEY_HASH: string;
635
+ static readonly API_KEY_HEADER: string;
636
+ static readonly API_MODEL_LIMIT: number;
637
+ static readonly API_MODEL_LIMIT_MAX: number;
638
+ static readonly API_SESSION_NAME: string;
639
+ static readonly API_SESSION_LIFETIME: number;
640
+ static readonly API_SESSION_SECRET: string;
641
+ static readonly API_TOKEN_COOKIE: string;
642
+ static readonly API_TOKEN_COOKIE_SET: boolean;
643
+ static readonly API_TOKEN_FORGOT: number;
644
+ static readonly API_TOKEN_HEADER: string;
645
+ static readonly API_TOKEN_HEADER_KEY: string;
646
+ static readonly API_TOKEN_RENEW: number;
647
+ static readonly API_USER_HISTORY: boolean;
648
+ static readonly API_WEBSOCKET_START: boolean;
504
649
  }
505
650
 
506
- export { Application, Audit, AuditsController, Auth, AuthBase, AuthController, AuthKey, AuthToken, Config, Controller, ControllerBase, ControllerCrud, ControllerModel, Env, FilesController, Forgot, ForgotController, Group, GroupPermission, GroupsController, GroupsPermissionsController, Log, LogsController, Migration, Permission, PermissionsController, Register, RegisterController, ReqAudit, ReqAuth, ReqUser, Session, SetupController, Store, User, UserGroup, UserHistory, UsersController, UsersGroupsController, audit, crt, database, hooks, key };
507
- export type { ArgumentsModel, ArgumentsModelCreate, ArgumentsModelDelete, ArgumentsModelFindAll, ArgumentsModelFindOne, ArgumentsModelUpdate, CallbackModelAll, CallbackModelGet, IAuthParameters, ResultModelAll };
651
+ export { Application, Audit, AuditModel, AuditsController, AuthController, AuthService, BaseController, CanCreate, CanDelete, CanRead, CanUpdate, Config, ConfigModel, CrudController, Env, FilesController, ForgotController, ForgotModel, GroupModel, GroupPermissionModel, GroupsController, GroupsPermissionsController, HasGroups, HasPermissions, IsAuthenticated, Log, LogModel, Loggable, LogsController, MigrationModel, ModelController, ModelService, PermissionModel, PermissionsController, RegisterController, RegisterModel, ReqAuth, ReqGroup, ReqGroups, ReqPermission, ReqPermissions, ReqUser, Service, SessionModel, SessionStore, SetupController, UserAuthModel, UserGroupModel, UserMetadataModel, UserModel, UserPasswordModel, UserProfileModel, UserService, UsersController, UsersGroupsController, UsersProfilesController, canFactory, sequelize };
652
+ export type { ApplicationEvents, AuthEvents, ForgotEvents, IAuthParameters, ModelArgumentsBase, ModelArgumentsCount, ModelArgumentsCreate, ModelArgumentsDelete, ModelArgumentsFindAll, ModelArgumentsFindOne, ModelArgumentsUpdate, ModelCallbackFindAll, ModelCallbackFindOne, ModelOptions, ModelResultFindAll, RegisterEvents };