@andrewcaires/api 4.5.2 → 5.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.
package/dist/index.d.ts CHANGED
@@ -1,178 +1,166 @@
1
1
  /*!
2
- * @andrewcaires/api v4.5.2
2
+ * @andrewcaires/api v5.0.0
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, CreateOptions, Attributes, FindOptions, UpdateOptions, ModelStatic, FindAttributeOptions } 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;
43
+ key: string;
47
44
  tag: 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;
67
65
  description: string;
68
66
  state: boolean;
69
67
  readonly created_at: Date;
70
68
  readonly updated_at: Date;
71
69
  readonly deleted_at: Date | null;
72
- groups_routes: Array<GroupPermission>;
73
- users_groups: Array<UserGroup>;
70
+ users_groups: Array<UserGroupModel>;
71
+ groups_Permission: Array<GroupPermissionModel>;
74
72
  }
75
73
 
76
- declare class UserGroup extends Model {
74
+ declare class UserGroupModel extends Model {
77
75
  readonly created_at: Date;
78
- group_id: number;
79
- group: Group;
80
- user_id: number;
81
- user: User;
76
+ group_id: string;
77
+ group: GroupModel;
78
+ user_id: string;
79
+ user: UserModel;
82
80
  }
83
81
 
84
- declare class UserHistory extends Model {
85
- password: string;
82
+ declare class UserPasswordModel extends Model {
83
+ readonly id: string;
84
+ value: string;
85
+ state: boolean;
86
86
  readonly created_at: Date;
87
- user_id: number;
88
- user: User;
87
+ readonly updated_at: Date;
88
+ readonly deleted_at: Date | null;
89
+ user_id: string;
90
+ user: UserModel;
89
91
  }
90
92
 
91
- declare class User extends Model {
92
- readonly id: number;
93
+ declare class UserModel extends Model {
94
+ readonly id: string;
93
95
  name: string;
94
96
  email: string;
95
97
  username: string;
96
- password: string;
97
- salt: string;
98
- token: string;
99
- avatar: string;
100
- date: string;
101
98
  description: string;
102
99
  state: boolean;
103
100
  readonly created_at: Date;
104
101
  readonly updated_at: Date;
105
102
  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>;
103
+ audits: Array<AuditModel>;
104
+ users_auths: Array<UserAuthModel>;
105
+ registers: Array<RegisterModel>;
106
+ users_groups: Array<UserGroupModel>;
107
+ users_passwords: Array<UserPasswordModel>;
111
108
  }
112
109
 
113
- declare class Audit extends Model {
114
- readonly id: number;
115
- type: string;
110
+ declare class AuditModel extends Model {
111
+ readonly id: string;
112
+ type: "CREATE" | "DELETE" | "UPDATE";
116
113
  model: string;
117
114
  record: string;
118
115
  data: TypeAnyObject;
119
116
  previously: TypeAnyObject;
120
- client: string;
121
- href: string;
117
+ full_url: string;
118
+ ip_address: string;
122
119
  user_agent: string;
123
120
  state: boolean;
124
121
  readonly created_at: Date;
125
122
  readonly updated_at: Date;
126
123
  readonly deleted_at: Date | null;
127
- user_id: number;
128
- user: User;
124
+ user_id: string;
125
+ user: UserModel;
129
126
  }
130
127
 
131
- declare class Config extends Model {
128
+ declare class ConfigModel extends Model {
129
+ readonly id: string;
132
130
  key: string;
133
131
  value: string;
134
132
  readonly created_at: Date;
135
133
  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
134
  }
141
135
 
142
- declare class Forgot extends Model {
143
- readonly id: number;
144
- token: string;
145
- timestamp: number;
136
+ declare class ForgotModel extends Model {
137
+ readonly id: string;
138
+ secret: string;
139
+ expired_at: number;
146
140
  state: boolean;
147
141
  readonly created_at: Date;
148
142
  readonly updated_at: Date;
149
143
  readonly deleted_at: Date | null;
150
- user_id: number;
151
- user: User;
144
+ user_id: string;
145
+ user: UserModel;
152
146
  }
153
147
 
154
- declare class Log extends Model {
155
- readonly id: number;
156
- type: string;
157
- source: string;
148
+ declare class LogModel extends Model {
149
+ readonly id: string;
150
+ level: "info" | "warn" | "error";
158
151
  message: string;
152
+ source: string;
159
153
  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
154
  }
167
155
 
168
- declare class Migration extends Model {
156
+ declare class MigrationModel extends Model {
169
157
  model: string;
170
158
  version: string;
171
159
  readonly created_at: Date;
172
160
  readonly updated_at: Date;
173
161
  }
174
162
 
175
- declare class Session extends Model {
163
+ declare class SessionModel extends Model {
176
164
  session: string;
177
165
  json: string;
178
166
  expired: number;
@@ -180,36 +168,30 @@ declare class Session extends Model {
180
168
  readonly updated_at: Date;
181
169
  }
182
170
 
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;
171
+ declare class UserMetadataModel extends Model {
172
+ readonly id: string;
173
+ key: string;
174
+ value: string;
175
+ readonly created_at: Date;
176
+ readonly updated_at: Date;
177
+ readonly deleted_at: Date | null;
178
+ user_id: string;
179
+ user: UserModel;
192
180
  }
193
181
 
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>;
182
+ declare class UserProfileModel extends Model {
183
+ readonly id: string;
184
+ key: string;
185
+ value: string;
186
+ readonly created_at: Date;
187
+ readonly updated_at: Date;
188
+ readonly deleted_at: Date | null;
189
+ user_id: string;
190
+ user: UserModel;
209
191
  }
210
192
 
211
193
  interface ArgumentsModel<M extends Model$1<M>> {
212
- ctx: Context;
194
+ ctx?: Context;
213
195
  }
214
196
 
215
197
  interface ArgumentsModelCreate<M extends Model$1<M>> extends ArgumentsModel<M> {
@@ -218,65 +200,201 @@ interface ArgumentsModelCreate<M extends Model$1<M>> extends ArgumentsModel<M> {
218
200
  }
219
201
 
220
202
  interface ArgumentsModelDelete<M extends Model$1<M>> extends ArgumentsModel<M> {
203
+ id?: string | number;
221
204
  options?: FindOptions<Attributes<M>>;
222
205
  }
223
206
 
224
- type CallbackModelAll<M> = (_records: Array<M>) => Array<any> | Promise<Array<any>>;
207
+ type CallbackModelFindAll<M> = (_records: Array<M>) => Array<any> | Promise<Array<any>>;
225
208
 
226
209
  interface ArgumentsModelFindAll<M extends Model$1<any>> extends ArgumentsModel<M> {
227
210
  options?: FindOptions<Attributes<M>>;
228
- callback?: CallbackModelAll<M>;
229
- scope?: string;
211
+ callback?: CallbackModelFindAll<M>;
230
212
  advanced?: boolean;
231
- attributes?: Array<string>;
232
213
  limited?: boolean;
233
214
  }
234
215
 
235
- type CallbackModelGet<M> = (_records: M) => any | Promise<any>;
216
+ type CallbackModelFindOne<M> = (_records: M) => any | Promise<any>;
236
217
 
237
218
  interface ArgumentsModelFindOne<M extends Model$1<M>> extends ArgumentsModel<M> {
238
219
  options?: FindOptions<Attributes<M>>;
239
- callback?: CallbackModelGet<M>;
240
- scope?: string;
220
+ callback?: CallbackModelFindOne<M>;
241
221
  }
242
222
 
243
223
  interface ArgumentsModelUpdate<M extends Model$1<M>> extends ArgumentsModel<M> {
224
+ id?: string | number;
244
225
  options?: UpdateOptions<Attributes<M>>;
245
226
  body?: TypeAnyObject;
246
227
  }
247
228
 
229
+ interface ResultModelFindAll<M extends Model<M>> {
230
+ count: number;
231
+ records: Array<M>;
232
+ }
233
+
248
234
  interface IAuthParameters {
249
- auth?: Auth;
235
+ auth?: UserAuthModel;
250
236
  decode?: TypeAnyObject;
251
- error?: string;
252
- forgot?: Forgot;
237
+ forgot?: ForgotModel;
253
238
  token?: string;
254
- user?: User;
239
+ user?: UserModel;
255
240
  }
256
241
 
257
- interface ResultModelAll<M extends Model$1<M>> {
258
- count: number;
259
- records: Array<M>;
242
+ declare module "express-serve-static-core" {
243
+ interface Request {
244
+ auth?: UserAuthModel;
245
+ }
246
+ }
247
+
248
+ declare module "express-serve-static-core" {
249
+ interface Request {
250
+ groups?: Array<string>;
251
+ }
260
252
  }
261
253
 
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>;
254
+ declare module "express-serve-static-core" {
255
+ interface Request {
256
+ permissions?: Array<string>;
257
+ }
258
+ }
259
+
260
+ declare module "express-serve-static-core" {
261
+ interface Request {
262
+ profile?: TypeObjectString;
263
+ }
264
+ }
265
+
266
+ declare module "express-serve-static-core" {
267
+ interface Request {
268
+ user?: UserModel;
269
+ }
270
+ }
271
+
272
+ declare class Loggable {
273
+ get log(): (message: string) => void;
274
+ static get log(): (message: string) => void;
275
+ get error(): (error: any) => void;
276
+ static get error(): (error: any) => void;
277
+ private static logError;
278
+ private static logInfo;
279
+ private static source;
280
+ }
281
+
282
+ declare class Config extends Loggable {
283
+ static all(): Promise<TypeObjectString>;
284
+ static del(key: string, user?: UserModel): Promise<boolean>;
285
+ static get(key: string, value?: string): Promise<string>;
286
+ static set(key: string, value: string, user?: UserModel): Promise<void>;
287
+ }
288
+
289
+ declare class Log {
290
+ protected static colors: TypeAnyObject;
291
+ static error(message: string, source?: string, show?: boolean): Promise<void>;
292
+ static info(message: string, source?: string, show?: boolean): Promise<void>;
293
+ static warn(message: string, source?: string, show?: boolean): Promise<void>;
294
+ private static writeRaw;
295
+ }
296
+
297
+ declare class SessionStore extends Store {
298
+ private loop;
299
+ constructor();
300
+ all: (callback: TypeAnyFunction) => Promise<void>;
301
+ clear: (callback: TypeAnyFunction) => Promise<void>;
302
+ destroy: (session_id: string, callback: TypeAnyFunction) => Promise<void>;
303
+ expired: () => Promise<void>;
304
+ get: (session_id: string, callback: TypeAnyFunction) => Promise<void>;
305
+ length: (callback: TypeAnyFunction) => Promise<void>;
306
+ set: (session_id: any, session: SessionData, callback: TypeAnyFunction) => Promise<void>;
307
+ }
308
+
309
+ interface Service extends Loggable {
310
+ }
311
+ declare abstract class Service {
312
+ }
313
+
314
+ declare class AuthService extends Service {
315
+ create(user: UserModel): Promise<IAuthParameters>;
316
+ destroy(auth?: UserAuthModel): Promise<boolean>;
317
+ renew(token: string): Promise<IAuthParameters>;
318
+ user(token: string): Promise<IAuthParameters>;
319
+ private options;
320
+ private verify;
321
+ key(value: string): Promise<IAuthParameters>;
322
+ }
323
+
324
+ declare class ModelService<M extends Model$1<any>> extends Service {
325
+ protected model: ModelStatic<M>;
326
+ protected attributes: Array<string>;
327
+ protected filter: FindAttributeOptions;
328
+ constructor(model: ModelStatic<M>, attributes?: FindAttributeOptions);
329
+ create({ ctx, options, body }: ArgumentsModelCreate<M>): Promise<M | null>;
330
+ delete({ ctx, options, id: _id }: ArgumentsModelDelete<M>): Promise<number>;
331
+ private filterAttributes;
332
+ findAll({ ctx, options, callback, advanced, limited }: ArgumentsModelFindAll<M>): Promise<ResultModelFindAll<M>>;
333
+ findOne({ ctx, options, callback }: ArgumentsModelFindOne<M>): Promise<M | null>;
334
+ getAttributes(options: FindAttributeOptions): Array<string>;
335
+ update({ ctx, options, body, id: _id }: ArgumentsModelUpdate<M>): Promise<boolean>;
336
+ name(): string;
337
+ }
338
+
339
+ declare class UserService extends Service {
340
+ getMetadata(user_id: string): Promise<TypeObjectString>;
341
+ getProfile(user_id: string): Promise<TypeObjectString>;
342
+ getGroups(user_id: string): Promise<Array<string>>;
343
+ getPermissions(user_id: string): Promise<Array<string>>;
344
+ }
345
+
346
+ declare class Application extends Application$1 {
347
+ readonly hash: Hash;
348
+ authService: AuthService;
349
+ userService: UserService;
350
+ private _webSocket?;
351
+ constructor(controllers: Array<object | TypeAnyConstructor<object>>, options?: IOptions);
352
+ error(error: any, source?: string): void;
353
+ log(message: string, source?: string): void;
354
+ listen(): Promise<void>;
355
+ migrations(database: Sequelize): Promise<void>;
356
+ websocket(): WebSocketServer | undefined;
357
+ }
358
+
359
+ interface BaseController extends Loggable {
360
+ }
361
+ declare abstract class BaseController extends EventEmitter {
362
+ protected readonly permissions: Array<string>;
363
+ name(): string;
364
+ session(ctx: Context, user_agent: string, store: IStore): Promise<void>;
272
365
  sync(): Promise<void>;
273
- protected update({ ctx, options, body }: ArgumentsModelUpdate<M>): Promise<boolean>;
274
- key(): string;
366
+ }
367
+
368
+ declare abstract class ModelController<M extends Model$1<any>> extends BaseController {
369
+ protected readonly attributes: Array<string>;
370
+ protected abstract readonly model: ModelStatic<M>;
371
+ protected readonly permissions: Array<string>;
372
+ private service;
373
+ protected create(options: ArgumentsModelCreate<M>): Promise<M | null>;
374
+ protected delete(options: ArgumentsModelDelete<M>): Promise<number>;
375
+ protected findAll(options: ArgumentsModelFindAll<M>): Promise<ResultModelFindAll<M>>;
376
+ protected findOne(options: ArgumentsModelFindOne<M>): Promise<M | null>;
377
+ sync(): Promise<void>;
378
+ protected update(options: ArgumentsModelUpdate<M>): Promise<boolean>;
275
379
  name(): string;
276
- scope(name?: string): ModelStatic<M>;
277
380
  }
278
381
 
279
- declare abstract class ControllerCrud<M extends Model$1<any>> extends ControllerModel<M> {
382
+ declare class AuditsController extends ModelController<AuditModel> {
383
+ protected readonly model: typeof AuditModel;
384
+ protected all(ctx: Context, type: string, table: string): Promise<void>;
385
+ protected get(ctx: Context): Promise<void>;
386
+ }
387
+
388
+ declare class AuthController extends BaseController {
389
+ protected readonly authService: AuthService;
390
+ constructor(authService: AuthService);
391
+ protected login(ctx: Context, user_agent: string, username: string, password: string, remember: boolean, app: Application): Promise<void>;
392
+ protected logout(ctx: Context, auth: UserAuthModel, user: UserModel, app: Application): Promise<void>;
393
+ protected renew(ctx: Context, user_agent: string, old: string, app: Application): Promise<void>;
394
+ protected user(ctx: Context, user: UserModel): Promise<void>;
395
+ }
396
+
397
+ declare abstract class CrudController<M extends Model$1<any>> extends ModelController<M> {
280
398
  private _crud;
281
399
  CrudArgumentsCreate(ctx: Context): ArgumentsModelUpdate<M>;
282
400
  CrudArgumentsFindAll(ctx: Context): ArgumentsModelFindAll<M>;
@@ -294,214 +412,157 @@ declare abstract class ControllerCrud<M extends Model$1<any>> extends Controller
294
412
  protected validationUpdate(ctx: Context): Promise<void>;
295
413
  }
296
414
 
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;
343
- }
344
-
345
- declare class AuditsController extends ControllerModel<Audit> {
346
- model(): typeof Audit;
347
- protected all(ctx: Context, type: string, table: string): Promise<void>;
348
- protected get(ctx: Context): Promise<void>;
349
- }
350
-
351
- declare class AuthController extends ControllerBase {
352
- 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>;
354
- protected renew(ctx: Context, user_agent: string, old: string, app: Application): Promise<void>;
355
- protected user(ctx: Context, user: User): Promise<void>;
356
- }
357
-
358
- declare class FilesController extends ControllerBase {
359
- protected [ControllerBase.PERMISSIONS]: Array<string>;
360
- directory(): string;
415
+ declare class FilesController extends BaseController {
416
+ protected readonly directory: string;
417
+ protected readonly permissions: Array<string>;
361
418
  protected files(ctx: Context): Promise<TypeAnyObject | void>;
362
- protected access(ctx: Context, name: string, user: User): Promise<void>;
363
419
  private info;
364
420
  name(): string;
365
421
  sync(): Promise<void>;
366
422
  }
367
423
 
368
- declare class ForgotController extends ControllerBase {
424
+ declare class ForgotController extends BaseController {
369
425
  protected check(ctx: Context, token: string): Promise<void>;
370
426
  protected forgot(ctx: Context, username: string, app: Application): Promise<void>;
371
427
  protected reset(ctx: Context, token: string, password: string, app: Application): Promise<void>;
372
428
  private find;
373
429
  }
374
430
 
375
- declare class GroupsController extends ControllerCrud<Group> {
431
+ declare class GroupsController extends CrudController<GroupModel> {
432
+ protected readonly model: typeof GroupModel;
376
433
  private schemaCreate;
377
434
  private schemaUpdate;
378
- model(): typeof Group;
379
- CrudArgumentsFindAll(ctx: Context): ArgumentsModelFindAll<Group>;
380
435
  CrudValidationCreate(): TypeObject<ValidationBase>;
381
436
  CrudValidationUpdate(): TypeObject<ValidationBase>;
382
437
  }
383
438
 
384
- declare class GroupsPermissionsController extends ControllerModel<GroupPermission> {
385
- model(): typeof GroupPermission;
439
+ declare class GroupsPermissionsController extends ModelController<GroupPermissionModel> {
440
+ protected readonly model: typeof GroupPermissionModel;
386
441
  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>;
442
+ protected me(ctx: Context, user: UserModel): Promise<void>;
443
+ protected set(ctx: Context, id: string, permissions: Array<string>): Promise<void>;
389
444
  }
390
445
 
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>;
446
+ declare class LogsController extends ModelController<LogModel> {
447
+ protected readonly model: typeof LogModel;
448
+ protected readonly permissions: Array<string>;
449
+ protected all(ctx: Context): Promise<void>;
395
450
  }
396
451
 
397
- declare class PermissionsController extends ControllerCrud<Permission> {
452
+ declare class PermissionsController extends CrudController<PermissionModel> {
453
+ protected readonly model: typeof PermissionModel;
398
454
  private schemaCreate;
399
455
  private schemaUpdate;
400
- model(): typeof Permission;
401
- CrudArgumentsFindAll(ctx: Context): ArgumentsModelFindAll<Permission>;
402
456
  CrudValidationCreate(): TypeObject<ValidationBase>;
403
457
  CrudValidationUpdate(): TypeObject<ValidationBase>;
404
458
  }
405
459
 
406
- declare class RegisterController extends ControllerBase {
460
+ declare class RegisterController extends BaseController {
407
461
  protected register(ctx: Context, body: TypeAnyObject, app: Application): Promise<void>;
408
462
  protected confirm(ctx: Context, token: string, app: Application): Promise<void>;
409
463
  protected send(ctx: Context, username: string, app: Application): Promise<void>;
410
464
  private getId;
411
465
  }
412
466
 
413
- declare class SetupController extends ControllerBase {
414
- protected setup(ctx: Context, audit: TypeAnyObject): Promise<void>;
467
+ declare class SetupController extends BaseController {
468
+ protected setup(ctx: Context): Promise<void>;
415
469
  }
416
470
 
417
- declare class UsersController extends ControllerModel<User> {
471
+ declare class UsersController extends ModelController<UserModel> {
472
+ protected readonly model: typeof UserModel;
418
473
  path: string;
419
- model(): typeof User;
420
474
  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>;
475
+ protected avatar(ctx: Context, user: UserModel): Promise<void>;
428
476
  private token_new;
429
- protected add(ctx: Context, password: string): Promise<void>;
477
+ protected add(ctx: Context): Promise<void>;
430
478
  protected all(ctx: Context): Promise<void>;
431
- protected del(ctx: Context, id: string, user: User): Promise<void>;
479
+ protected del(ctx: Context, id: string, user: UserModel): Promise<void>;
432
480
  protected get(ctx: Context): Promise<void>;
433
- protected set(ctx: Context, id: string, password: string): Promise<void>;
481
+ protected set(ctx: Context): Promise<void>;
434
482
  }
435
483
 
436
- declare class UsersGroupsController extends ControllerModel<UserGroup> {
437
- model(): typeof UserGroup;
484
+ declare class UsersGroupsController extends ModelController<UserGroupModel> {
485
+ protected readonly model: typeof UserGroupModel;
438
486
  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>;
487
+ protected me(ctx: Context, user: UserModel): Promise<void>;
488
+ protected set(ctx: Context, id: string, groups: Array<string>): Promise<void>;
441
489
  }
442
490
 
443
- declare const database: Sequelize;
491
+ declare const sequelize: Sequelize;
444
492
 
445
- declare const ReqAudit: (key?: string) => ParameterDecorator;
493
+ declare const CanCreate: (name?: string) => MethodDecorator;
446
494
 
447
- declare const ReqAuth: (key?: string) => ParameterDecorator;
495
+ declare const CanDelete: (name?: string) => MethodDecorator;
448
496
 
449
- declare const ReqUser: (key?: string) => ParameterDecorator;
497
+ declare const canFactory: (key: string) => (name?: string) => MethodDecorator;
450
498
 
451
- declare global {
452
- export namespace Express {
453
- interface Request {
454
- auth?: Auth;
455
- user?: User;
456
- }
457
- }
458
- }
499
+ declare const CanRead: (name?: string) => MethodDecorator;
459
500
 
460
- declare class AuthBase {
461
- protected static error(error: any): void;
462
- }
501
+ declare const CanUpdate: (name?: string) => MethodDecorator;
463
502
 
464
- declare class AuthKey extends AuthBase {
465
- static user(key: string, app: Application): Promise<IAuthParameters>;
466
- }
503
+ declare const HasGroups: (...groups: Array<string>) => MethodDecorator;
467
504
 
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
- }
505
+ declare const HasPermissions: (...permissions: Array<string>) => MethodDecorator;
476
506
 
477
- declare const audit: (ctx: Context) => TypeAnyObject;
507
+ declare const IsAuthenticated: () => MethodDecorator;
478
508
 
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
- };
509
+ declare const ReqAuth: (key?: string) => ParameterDecorator;
484
510
 
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
- };
511
+ declare const ReqGroup: (key?: string) => ParameterDecorator;
493
512
 
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>;
513
+ declare const ReqGroups: (key?: string) => ParameterDecorator;
514
+
515
+ declare const ReqPermission: (key?: string) => ParameterDecorator;
516
+
517
+ declare const ReqPermissions: (key?: string) => ParameterDecorator;
518
+
519
+ declare const ReqUser: (key?: string) => ParameterDecorator;
520
+
521
+ declare const Audit: (active?: boolean) => ClassDecorator;
522
+
523
+ declare class Env extends Env$1 {
524
+ static readonly BASE_NAME: string;
525
+ static readonly CONSOLE_ERROR: boolean;
526
+ static readonly DATABASE_URI: string;
527
+ static readonly DATABASE_LOG: boolean;
528
+ static readonly DATABASE_AUDIT: boolean;
529
+ static readonly DATABASE_PREFIX: string;
530
+ static readonly DATABASE_TIMEZONE: string;
531
+ static readonly HTTP_CRT: Buffer<ArrayBufferLike> | null;
532
+ static readonly HTTP_KEY: Buffer<ArrayBufferLike> | null;
533
+ static readonly TOKEN_CRT: Buffer<ArrayBufferLike> | null;
534
+ static readonly TOKEN_KEY: Buffer<ArrayBufferLike> | null;
535
+ static readonly API_BODYPARSER_STRICT: boolean;
536
+ static readonly API_BODYPARSER_INFLATE: boolean;
537
+ static readonly API_BODYPARSER_LIMIT: string;
538
+ static readonly API_BODYPARSER_TYPE: string;
539
+ static readonly API_HTTP_PORT: number;
540
+ static readonly API_HTTP_PUBLIC: string;
541
+ static readonly API_HTTP_CROSS: boolean;
542
+ static readonly API_HTTP_HYBRID: boolean;
543
+ static readonly API_HTTP_NOTFOUND: string;
544
+ static readonly API_HTTP_PATH: string;
545
+ static readonly API_HTTP_REDIRECT: string;
546
+ static readonly API_KEY_HASH: string;
547
+ static readonly API_KEY_HEADER: string;
548
+ static readonly API_MODEL_LIMIT: number;
549
+ static readonly API_MODEL_LIMIT_MAX: number;
550
+ static readonly API_SLEEP_AUTH: number;
551
+ static readonly API_SLEEP_FORGOT: number;
552
+ static readonly API_SLEEP_REGISTRY: number;
553
+ static readonly API_SESSION_NAME: string;
554
+ static readonly API_SESSION_LIFETIME: number;
555
+ static readonly API_SESSION_SECRET: string;
556
+ static readonly API_TOKEN_COOKIE: string;
557
+ static readonly API_TOKEN_COOKIE_SET: boolean;
558
+ static readonly API_TOKEN_FORGOT: number;
559
+ static readonly API_TOKEN_HEADER: string;
560
+ static readonly API_TOKEN_HEADER_KEY: string;
561
+ static readonly API_TOKEN_LIFETIME: number;
562
+ static readonly API_TOKEN_RENEW: number;
563
+ static readonly API_USER_HISTORY: boolean;
564
+ static readonly API_WEBSOCKET_START: boolean;
504
565
  }
505
566
 
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 };
567
+ 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, canFactory, sequelize };
568
+ export type { ArgumentsModel, ArgumentsModelCreate, ArgumentsModelDelete, ArgumentsModelFindAll, ArgumentsModelFindOne, ArgumentsModelUpdate, CallbackModelFindAll, CallbackModelFindOne, IAuthParameters, ResultModelFindAll };