@andrewcaires/api 5.5.0 → 5.6.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,5 +1,5 @@
1
1
  /*!
2
- * @andrewcaires/api v5.5.0
2
+ * @andrewcaires/api v5.6.0
3
3
  * Simple api for small applications using express, jsonwebtoken, sequelize and websocket
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
@@ -258,28 +258,53 @@ declare class PageModel extends Model$1 {
258
258
  declare class PermissionModel extends Model$1 {
259
259
  readonly id: string;
260
260
  name: string;
261
+ permission: string;
261
262
  description: string;
262
263
  active: boolean;
263
264
  metadata: TypeAnyObject;
264
265
  readonly created_at: Date;
265
266
  readonly updated_at: Date;
266
267
  readonly deleted_at: Date | null;
267
- groups_permissions: Array<GroupPermissionModel>;
268
+ roles_permissions: Array<RolePermissionModel>;
268
269
  pages: Array<PageModel>;
269
270
  }
270
271
 
271
- declare class GroupPermissionModel extends Model$1 {
272
+ declare class RolePermissionModel extends Model$1 {
272
273
  readonly id: string;
273
274
  readonly created_at: Date;
274
- group_id: string;
275
- group: GroupModel;
276
275
  permission_id: string;
277
276
  permission: PermissionModel;
277
+ role_id: string;
278
+ role: RoleModel;
279
+ }
280
+
281
+ declare class RoleModel extends Model$1 {
282
+ readonly id: string;
283
+ name: string;
284
+ role: string;
285
+ description: string;
286
+ active: boolean;
287
+ metadata: TypeAnyObject;
288
+ readonly created_at: Date;
289
+ readonly updated_at: Date;
290
+ readonly deleted_at: Date | null;
291
+ groups_roles: Array<GroupRoleModel>;
292
+ roles_permissions: Array<RolePermissionModel>;
293
+ }
294
+
295
+ declare class GroupRoleModel extends Model$1 {
296
+ readonly id: string;
297
+ readonly created_at: Date;
298
+ group_id: string;
299
+ group: GroupModel;
300
+ role_id: string;
301
+ role: RoleModel;
278
302
  }
279
303
 
280
304
  declare class GroupModel extends Model$1 {
281
305
  readonly id: string;
282
306
  name: string;
307
+ group: string;
283
308
  description: string;
284
309
  type: GroupTypes;
285
310
  active: boolean;
@@ -288,7 +313,7 @@ declare class GroupModel extends Model$1 {
288
313
  readonly updated_at: Date;
289
314
  readonly deleted_at: Date | null;
290
315
  users_groups: Array<UserGroupModel>;
291
- groups_permissions: Array<GroupPermissionModel>;
316
+ groups_roles: Array<GroupRoleModel>;
292
317
  }
293
318
 
294
319
  declare class UserTenantModel extends Model$1 {
@@ -494,17 +519,21 @@ declare class AuthService extends Service {
494
519
  private readonly options;
495
520
  private readonly userAttributes;
496
521
  private readonly userService;
497
- constructor();
498
- createApiKey(ctx: Context, name: string, expires_at: Date, user: UserModel): Promise<string>;
522
+ apiAuth(ctx: Context): Promise<AuthResult>;
523
+ apiKeyAuth(key: string): Promise<AuthResult>;
524
+ apiTokenAuth(token: string): Promise<AuthResult>;
525
+ createApiKey(ctx: Context, name: string, expires_at: Date, user: UserModel): Promise<{
526
+ id: string;
527
+ key: string;
528
+ }>;
499
529
  createApiToken(ctx: Context, user: UserModel): Promise<{
500
530
  token: string;
501
531
  }>;
532
+ deleteApiKey(ctx: Context, id: string, user: UserModel): Promise<boolean>;
502
533
  renewApiToken(token: string): Promise<{
503
534
  token: string;
504
535
  }>;
505
- apiAuth(ctx: Context): Promise<AuthResult>;
506
- apiKeyAuth(key: string): Promise<AuthResult>;
507
- apiTokenAuth(token: string): Promise<AuthResult>;
536
+ revokeApiKey(ctx: Context, id: string, user: UserModel): Promise<boolean>;
508
537
  private attachAuthContext;
509
538
  private safeEqual;
510
539
  private verifyJwt;
@@ -541,6 +570,7 @@ declare class UserService extends Service {
541
570
  createPassword(user_id: string, value: string, ctx?: Context): Promise<boolean>;
542
571
  getGroups(user_id: string, tenant_id?: string | null): Promise<Array<string>>;
543
572
  getPermissions(user_id: string, tenant_id?: string | null): Promise<Array<string>>;
573
+ getGroupPermissions(group_id: string): Promise<Array<string>>;
544
574
  getTenants(user_id: string): Promise<Array<{
545
575
  id: string;
546
576
  name: string;
@@ -595,6 +625,7 @@ declare class AuditsController extends ModelController<AuditModel> {
595
625
  protected readonly model: typeof AuditModel;
596
626
  protected readonly permissions: string[];
597
627
  protected all(ctx: Context): Promise<void>;
628
+ protected record(ctx: Context, record: string): Promise<void>;
598
629
  protected get(ctx: Context): Promise<void>;
599
630
  }
600
631
 
@@ -655,16 +686,22 @@ declare class GroupsController extends CrudController<GroupModel> {
655
686
  private checkGroup;
656
687
  }
657
688
 
658
- declare class GroupsPermissionsController extends ModelController<PermissionModel> {
659
- protected readonly model: typeof PermissionModel;
689
+ declare class GroupsPermissionsController extends BaseController {
690
+ private readonly userService;
691
+ protected all(ctx: Context, group_id: string): Promise<void>;
692
+ private checkGroup;
693
+ }
694
+
695
+ declare class GroupsRolesController extends ModelController<RoleModel> {
696
+ protected readonly model: typeof RoleModel;
660
697
  protected readonly permissions: never[];
661
- protected add(ctx: Context, group_id: string, permissions: Array<string>): Promise<void>;
698
+ protected add(ctx: Context, group_id: string, roles: Array<string>): Promise<void>;
662
699
  protected all(ctx: Context, group_id: string): Promise<void>;
663
- protected del(ctx: Context, group_id: string, permissions: Array<string>): Promise<void>;
664
- protected set(ctx: Context, group_id: string, permissions: Array<string>): Promise<void>;
665
- private addPermissions;
700
+ protected del(ctx: Context, group_id: string, roles: Array<string>): Promise<void>;
701
+ protected set(ctx: Context, group_id: string, roles: Array<string>): Promise<void>;
702
+ private addRoles;
666
703
  private checkGroup;
667
- private checkPermissions;
704
+ private checkRoles;
668
705
  }
669
706
 
670
707
  declare class HealthController {
@@ -735,6 +772,30 @@ declare class RegisterController extends BaseController<RegisterEvents> {
735
772
  private getId;
736
773
  }
737
774
 
775
+ declare class RolesController extends CrudController<RoleModel> {
776
+ protected readonly model: typeof RoleModel;
777
+ protected groupModelService: ModelService<GroupModel>;
778
+ private schemaCreate;
779
+ private schemaUpdate;
780
+ CrudValidateCreate(): TypeObject<ValidationBase>;
781
+ CrudValidateUpdate(): TypeObject<ValidationBase>;
782
+ sync(): Promise<void>;
783
+ protected groups(ctx: Context, role_id: string): Promise<void>;
784
+ private checkRole;
785
+ }
786
+
787
+ declare class RolesPermissionsController extends ModelController<PermissionModel> {
788
+ protected readonly model: typeof PermissionModel;
789
+ protected readonly permissions: never[];
790
+ protected add(ctx: Context, role_id: string, permissions: Array<string>): Promise<void>;
791
+ protected all(ctx: Context, role_id: string): Promise<void>;
792
+ protected del(ctx: Context, role_id: string, permissions: Array<string>): Promise<void>;
793
+ protected set(ctx: Context, role_id: string, permissions: Array<string>): Promise<void>;
794
+ private addPermissions;
795
+ private checkPermissions;
796
+ private checkRole;
797
+ }
798
+
738
799
  declare class SetupController extends BaseController {
739
800
  protected readonly userService: UserService;
740
801
  protected setup(ctx: Context): Promise<void>;
@@ -1082,8 +1143,14 @@ declare class UsersKeysController extends ModelController<UserKeyModel> {
1082
1143
  protected readonly permissions: string[];
1083
1144
  protected add(ctx: Context, user: UserModel, body: TypeAnyObject, app: Application): Promise<void>;
1084
1145
  protected add_admin(ctx: Context, id: string, body: TypeAnyObject, app: Application): Promise<void>;
1146
+ protected revoke(ctx: Context, id: string, user: UserModel, app: Application): Promise<void>;
1147
+ protected revoke_admin(ctx: Context, id: string, key: string, app: Application): Promise<void>;
1148
+ protected del(ctx: Context, id: string, user: UserModel, app: Application): Promise<void>;
1149
+ protected del_admin(ctx: Context, id: string, key: string, app: Application): Promise<void>;
1085
1150
  protected all(ctx: Context, user: UserModel): Promise<void>;
1151
+ protected get(ctx: Context, user: UserModel): Promise<void>;
1086
1152
  protected all_admin(ctx: Context, id: string): Promise<void>;
1153
+ protected get_admin(ctx: Context, id: string): Promise<void>;
1087
1154
  private checkUser;
1088
1155
  }
1089
1156
 
@@ -1202,5 +1269,5 @@ declare class Env extends Env$1 {
1202
1269
  static readonly API_WEBSOCKET_START: boolean;
1203
1270
  }
1204
1271
 
1205
- export { Application, Audit, AuditModel, AuditTypes, AuditsController, AuthController, AuthService, BaseController, CanCreate, CanDelete, CanRead, CanUpdate, Config, ConfigModel, CrudController, Env, FilesController, ForgotController, ForgotModel, GroupModel, GroupPermissionModel, GroupTypes, GroupsController, GroupsPermissionsController, HasGroups, HasPermissions, HasScope, HealthController, IsAuthenticated, Log, LogLevels, LogModel, Loggable, LogsController, MCP_DEFAULT_PROTOCOL_VERSION, MCP_HTTP_ALLOW, MCP_HTTP_ALLOWED_METHODS, MCP_HTTP_DEFAULT_ALLOWED_HEADERS, MCP_PROTOCOL_VERSION_HEADER, MCP_SESSION_ID_HEADER, MCP_SUPPORTED_PROTOCOL_VERSIONS, MCP_TOOL_METADATA, McpController, McpError, McpErrorCode, McpHttpHandler, McpInternalError, McpInvalidParamsError, McpInvalidRequestError, McpInvalidSessionError, McpMethodNotFoundError, McpParseError, McpServerError, McpSessionStore, McpTool, McpToolNotFoundError, McpToolRegistry, MigrationModel, ModelController, ModelService, PageModel, PageTypes, PagesController, PermissionModel, PermissionsController, ProfileController, RegisterController, RegisterModel, ReqAccess, ReqGroup, ReqGroups, ReqPermission, ReqPermissions, ReqTenant, ReqTenants, ReqUser, Secret, SecretModel, Service, SessionModel, SessionStore, SetupController, TenantModel, TenantStatus, TenantsController, TestController, UserAuthModel, UserGroupModel, UserKeyModel, UserModel, UserPasswordModel, UserService, UserStatus, UserTenantModel, UsersController, UsersGroupsController, UsersKeysController, UsersTenantsController, WORKER_METADATA, Worker, assertValidMcpToolDefinition, canFactory, discoverMcpTools, discoverWorkers, getMcpToolMetadata, getWorkerMetadata, isJsonParseError, isJsonRpcId, jsonParseErrorResponse, jsonRpcError, jsonRpcErrorFromCode, jsonRpcResult, parseJsonRpcRequest, runWorker, sequelize };
1272
+ export { Application, Audit, AuditModel, AuditTypes, AuditsController, AuthController, AuthService, BaseController, CanCreate, CanDelete, CanRead, CanUpdate, Config, ConfigModel, CrudController, Env, FilesController, ForgotController, ForgotModel, GroupModel, GroupRoleModel, GroupTypes, GroupsController, GroupsPermissionsController, GroupsRolesController, HasGroups, HasPermissions, HasScope, HealthController, IsAuthenticated, Log, LogLevels, LogModel, Loggable, LogsController, MCP_DEFAULT_PROTOCOL_VERSION, MCP_HTTP_ALLOW, MCP_HTTP_ALLOWED_METHODS, MCP_HTTP_DEFAULT_ALLOWED_HEADERS, MCP_PROTOCOL_VERSION_HEADER, MCP_SESSION_ID_HEADER, MCP_SUPPORTED_PROTOCOL_VERSIONS, MCP_TOOL_METADATA, McpController, McpError, McpErrorCode, McpHttpHandler, McpInternalError, McpInvalidParamsError, McpInvalidRequestError, McpInvalidSessionError, McpMethodNotFoundError, McpParseError, McpServerError, McpSessionStore, McpTool, McpToolNotFoundError, McpToolRegistry, MigrationModel, ModelController, ModelService, PageModel, PageTypes, PagesController, PermissionModel, PermissionsController, ProfileController, RegisterController, RegisterModel, ReqAccess, ReqGroup, ReqGroups, ReqPermission, ReqPermissions, ReqTenant, ReqTenants, ReqUser, RoleModel, RolePermissionModel, RolesController, RolesPermissionsController, Secret, SecretModel, Service, SessionModel, SessionStore, SetupController, TenantModel, TenantStatus, TenantsController, TestController, UserAuthModel, UserGroupModel, UserKeyModel, UserModel, UserPasswordModel, UserService, UserStatus, UserTenantModel, UsersController, UsersGroupsController, UsersKeysController, UsersTenantsController, WORKER_METADATA, Worker, assertValidMcpToolDefinition, canFactory, discoverMcpTools, discoverWorkers, getMcpToolMetadata, getWorkerMetadata, isJsonParseError, isJsonRpcId, jsonParseErrorResponse, jsonRpcError, jsonRpcErrorFromCode, jsonRpcResult, parseJsonRpcRequest, runWorker, sequelize };
1206
1273
  export type { ApplicationEvents, AuthEvents, AuthResult, ForgotEvents, McpCallToolResult, McpDecoratedToolHandler, McpHttpHandlerOptions, McpHttpResponse, McpJsonRpcErrorBody, McpJsonRpcErrorResult, McpJsonRpcId, McpJsonRpcRequest, McpJsonRpcResult, McpLogger, McpNormalizedValidation, McpProtocolVersion, McpRegisteredTool, McpSession, McpToolCallLog, McpToolContext, McpToolDeclaration, McpToolDefinition, McpToolHandlerResult, McpToolInput, McpToolMetadata, McpToolOptions, McpToolOutput, ModelArgumentsBase, ModelArgumentsCount, ModelArgumentsCreate, ModelArgumentsDelete, ModelArgumentsFindAll, ModelArgumentsFindOne, ModelArgumentsInclude, ModelArgumentsUpdate, ModelCallbackFindAll, ModelCallbackFindOne, ModelOptions, ModelResultFindAll, RegisterEvents, WorkerCliRequest, WorkerDeclaration, WorkerHandler, WorkerHandlerResult, WorkerMetadata, WorkerRegistered };