rl-core-api 0.5.0 → 0.7.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.
@@ -0,0 +1,10 @@
1
+ import { Actor } from "./actor.interface";
2
+ export type OwnershipScope = {
3
+ kind: "all";
4
+ } | {
5
+ kind: "own";
6
+ userId: string;
7
+ } | {
8
+ kind: "none";
9
+ };
10
+ export declare const resolveOwnershipScope: (actor: Actor, action: string) => OwnershipScope;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveOwnershipScope = void 0;
4
+ const permissionScope_util_1 = require("./permissionScope.util");
5
+ const resolveOwnershipScope = (actor, action) => {
6
+ if (actor.permissions.includes(`${action}:${permissionScope_util_1.SCOPE_ANY}`)) {
7
+ return { kind: "all" };
8
+ }
9
+ if (actor.permissions.includes(`${action}:${permissionScope_util_1.SCOPE_OWN}`)) {
10
+ return { kind: "own", userId: actor.id };
11
+ }
12
+ return { kind: "none" };
13
+ };
14
+ exports.resolveOwnershipScope = resolveOwnershipScope;
@@ -1,3 +1,5 @@
1
1
  export declare const SCOPE_ANY = "any";
2
2
  export declare const SCOPE_TEAM = "team";
3
+ export declare const SCOPE_OWN = "own";
3
4
  export declare const anyOrTeam: (action: string) => [string, string];
5
+ export declare const anyOrOwn: (action: string) => [string, string];
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.anyOrTeam = exports.SCOPE_TEAM = exports.SCOPE_ANY = void 0;
3
+ exports.anyOrOwn = exports.anyOrTeam = exports.SCOPE_OWN = exports.SCOPE_TEAM = exports.SCOPE_ANY = void 0;
4
4
  exports.SCOPE_ANY = "any";
5
5
  exports.SCOPE_TEAM = "team";
6
+ exports.SCOPE_OWN = "own";
6
7
  const anyOrTeam = (action) => [
7
8
  `${action}:${exports.SCOPE_ANY}`,
8
9
  `${action}:${exports.SCOPE_TEAM}`,
9
10
  ];
10
11
  exports.anyOrTeam = anyOrTeam;
12
+ const anyOrOwn = (action) => [
13
+ `${action}:${exports.SCOPE_ANY}`,
14
+ `${action}:${exports.SCOPE_OWN}`,
15
+ ];
16
+ exports.anyOrOwn = anyOrOwn;
@@ -133,11 +133,18 @@ class InitialSchema1710000000000 {
133
133
  description varchar(255) NULL,
134
134
  type varchar(50) NOT NULL DEFAULT 'team',
135
135
  parent_id char(36) NULL,
136
+ manager_id char(36) NULL,
136
137
  is_active tinyint NOT NULL DEFAULT 1,
137
138
  ${ts},
138
139
  PRIMARY KEY (id),
139
140
  KEY IDX_groups_parent (parent_id),
140
- CONSTRAINT FK_groups_parent FOREIGN KEY (parent_id) REFERENCES \`groups\` (id)
141
+ KEY IDX_groups_manager (manager_id),
142
+ CONSTRAINT FK_groups_parent FOREIGN KEY (parent_id) REFERENCES \`groups\` (id),
143
+ -- Quem manda no grupo, base do escopo \`team\`. \`ON DELETE SET NULL\` de
144
+ -- propósito: apagar a pessoa não pode apagar o grupo junto — o time
145
+ -- continua existindo e fica sem gerente até alguém assumir.
146
+ CONSTRAINT FK_groups_manager FOREIGN KEY (manager_id)
147
+ REFERENCES users (id) ON DELETE SET NULL
141
148
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
142
149
  `);
143
150
  await queryRunner.query(`
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.coreMigrations = void 0;
4
4
  const _1710000000000_InitialSchema_1 = require("./1710000000000-InitialSchema");
5
- const _1787270400000_GroupManager_1 = require("./1787270400000-GroupManager");
6
5
  exports.coreMigrations = [
7
6
  _1710000000000_InitialSchema_1.InitialSchema1710000000000,
8
- _1787270400000_GroupManager_1.GroupManager1787270400000,
9
7
  ];
@@ -1,2 +1,21 @@
1
1
  import { DataSource } from "typeorm";
2
- export declare function seedPermissions(ds: DataSource): Promise<void>;
2
+ interface CatalogEntry {
3
+ name: string;
4
+ description: string;
5
+ }
6
+ export interface RbacCatalogExtension {
7
+ resources?: CatalogEntry[];
8
+ actions?: CatalogEntry[];
9
+ scopes?: CatalogEntry[];
10
+ permissions?: {
11
+ code: string;
12
+ description: string;
13
+ }[];
14
+ roles?: {
15
+ name: string;
16
+ description: string;
17
+ permissions: string[] | "*";
18
+ }[];
19
+ }
20
+ export declare function seedPermissions(ds: DataSource, extension?: RbacCatalogExtension): Promise<void>;
21
+ export {};
@@ -7,47 +7,40 @@ const permission_schema_1 = require("../../../features/rbac/infra/schema/permiss
7
7
  const resource_schema_1 = require("../../../features/rbac/infra/schema/resource.schema");
8
8
  const role_schema_1 = require("../../../features/rbac/infra/schema/role.schema");
9
9
  const scope_schema_1 = require("../../../features/rbac/infra/schema/scope.schema");
10
- async function seedPermissions(ds) {
11
- const resourceRepo = ds.getRepository(resource_schema_1.Resource);
12
- const actionRepo = ds.getRepository(action_schema_1.Action);
13
- const scopeRepo = ds.getRepository(scope_schema_1.Scope);
14
- const permissionRepo = ds.getRepository(permission_schema_1.Permission);
15
- const roleRepo = ds.getRepository(role_schema_1.Role);
16
- const resources = new Map();
17
- for (const r of rbac_catalog_1.RESOURCES) {
18
- let entity = await resourceRepo.findOne({
19
- where: { name: r.name },
20
- withDeleted: true,
21
- });
22
- if (!entity) {
23
- entity = await resourceRepo.save(resourceRepo.create(r));
24
- }
25
- resources.set(r.name, entity);
26
- }
27
- const actions = new Map();
28
- for (const a of rbac_catalog_1.ACTIONS) {
29
- let entity = await actionRepo.findOne({
30
- where: { name: a.name },
10
+ async function seedCatalog(repo, entries) {
11
+ const byName = new Map();
12
+ for (const entry of entries) {
13
+ let row = await repo.findOne({
14
+ where: { name: entry.name },
31
15
  withDeleted: true,
32
16
  });
33
- if (!entity) {
34
- entity = await actionRepo.save(actionRepo.create(a));
17
+ if (!row) {
18
+ row = await repo.save(repo.create(entry));
35
19
  }
36
- actions.set(a.name, entity);
37
- }
38
- const scopes = new Map();
39
- for (const s of rbac_catalog_1.SCOPES) {
40
- let entity = await scopeRepo.findOne({
41
- where: { name: s.name },
42
- withDeleted: true,
43
- });
44
- if (!entity) {
45
- entity = await scopeRepo.save(scopeRepo.create(s));
20
+ else if (row.description !== entry.description) {
21
+ row.description = entry.description;
22
+ row = await repo.save(row);
46
23
  }
47
- scopes.set(s.name, entity);
24
+ byName.set(entry.name, row);
48
25
  }
26
+ return byName;
27
+ }
28
+ async function seedPermissions(ds, extension = {}) {
29
+ const allResources = [...rbac_catalog_1.RESOURCES, ...(extension.resources ?? [])];
30
+ const allActions = [...rbac_catalog_1.ACTIONS, ...(extension.actions ?? [])];
31
+ const allScopes = [...rbac_catalog_1.SCOPES, ...(extension.scopes ?? [])];
32
+ const allPermissions = [...rbac_catalog_1.PERMISSIONS, ...(extension.permissions ?? [])];
33
+ const allRoles = [...rbac_catalog_1.ROLES, ...(extension.roles ?? [])];
34
+ const resourceRepo = ds.getRepository(resource_schema_1.Resource);
35
+ const actionRepo = ds.getRepository(action_schema_1.Action);
36
+ const scopeRepo = ds.getRepository(scope_schema_1.Scope);
37
+ const permissionRepo = ds.getRepository(permission_schema_1.Permission);
38
+ const roleRepo = ds.getRepository(role_schema_1.Role);
39
+ const resources = await seedCatalog(resourceRepo, allResources);
40
+ const actions = await seedCatalog(actionRepo, allActions);
41
+ const scopes = await seedCatalog(scopeRepo, allScopes);
49
42
  const permissions = new Map();
50
- for (const p of rbac_catalog_1.PERMISSIONS) {
43
+ for (const p of allPermissions) {
51
44
  let entity = await permissionRepo.findOne({
52
45
  where: { code: p.code },
53
46
  withDeleted: true,
@@ -70,7 +63,7 @@ async function seedPermissions(ds) {
70
63
  }
71
64
  permissions.set(p.code, entity);
72
65
  }
73
- for (const r of rbac_catalog_1.ROLES) {
66
+ for (const r of allRoles) {
74
67
  let role = await roleRepo.findOne({
75
68
  where: { name: r.name },
76
69
  relations: { permissions: true },
@@ -83,11 +76,11 @@ async function seedPermissions(ds) {
83
76
  permissions: [],
84
77
  });
85
78
  }
86
- const codes = r.permissions === "*" ? rbac_catalog_1.PERMISSIONS.map((p) => p.code) : r.permissions;
79
+ const codes = r.permissions === "*" ? allPermissions.map((p) => p.code) : r.permissions;
87
80
  role.permissions = codes
88
81
  .map((code) => permissions.get(code))
89
82
  .filter(Boolean);
90
83
  await roleRepo.save(role);
91
84
  }
92
- console.log(`[seed] RBAC: ${resources.size} resources, ${actions.size} actions, ${scopes.size} scopes, ${permissions.size} permissions, ${rbac_catalog_1.ROLES.length} roles`);
85
+ console.log(`[seed] RBAC: ${resources.size} resources, ${actions.size} actions, ${scopes.size} scopes, ${permissions.size} permissions, ${allRoles.length} roles`);
93
86
  }
@@ -0,0 +1,7 @@
1
+ import { ObjectLiteral, SelectQueryBuilder } from "typeorm";
2
+ import { OwnershipScope } from "../auth/ownershipScope.util";
3
+ export interface OwnershipScopeOptions {
4
+ alias: string;
5
+ column?: string;
6
+ }
7
+ export declare const applyOwnershipScope: <T extends ObjectLiteral>(qb: SelectQueryBuilder<T>, scope: OwnershipScope, options: OwnershipScopeOptions) => SelectQueryBuilder<T>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyOwnershipScope = void 0;
4
+ const applyOwnershipScope = (qb, scope, options) => {
5
+ const { alias, column = "ownerId" } = options;
6
+ if (scope.kind === "all") {
7
+ return qb;
8
+ }
9
+ if (scope.kind === "none") {
10
+ return qb.andWhere("1 = 0");
11
+ }
12
+ return qb.andWhere(`${alias}.${column} = :ownershipScopeUserId`, {
13
+ ownershipScopeUserId: scope.userId,
14
+ });
15
+ };
16
+ exports.applyOwnershipScope = applyOwnershipScope;
@@ -49,6 +49,10 @@ class BaseGateway {
49
49
  this.logger.warn(`Evento ${event} descartado: sem sala de destino`);
50
50
  return;
51
51
  }
52
+ if (!this.server) {
53
+ this.logger.warn(`Evento ${event} descartado: servidor de socket não inicializado`);
54
+ return;
55
+ }
52
56
  this.server.to(targets).emit(event, (0, socketEvent_envelope_1.wrapSocketEvent)(event, data));
53
57
  }
54
58
  scheduleExpiry(socket, expiresAt) {
@@ -40,6 +40,6 @@ exports.NotificationsModule = NotificationsModule = __decorate([
40
40
  notifications_publisher_1.NotificationsPublisher,
41
41
  domainEvents_listener_1.DomainEventsListener,
42
42
  ],
43
- exports: [notifications_service_1.NotificationsService],
43
+ exports: [notifications_service_1.NotificationsService, notifications_publisher_1.NotificationsPublisher],
44
44
  })
45
45
  ], NotificationsModule);
@@ -8,17 +8,15 @@ exports.RESOURCES = [
8
8
  { name: "groups", description: "Gestão de grupos" },
9
9
  { name: "audit", description: "Logs e auditoria" },
10
10
  { name: "notifications", description: "Notificações" },
11
- { name: "reports", description: "Relatórios" },
12
- { name: "resources", description: "Catálogo RBACresources" },
13
- { name: "actions", description: "Catálogo RBACactions" },
14
- { name: "scopes", description: "Catálogo RBAC — scopes" },
11
+ { name: "resources", description: "Controle de acesso — áreas" },
12
+ { name: "actions", description: "Controle de acesso ações" },
13
+ { name: "scopes", description: "Controle de acesso alcances" },
15
14
  ];
16
15
  exports.ACTIONS = [
17
16
  { name: "create", description: "Criar" },
18
17
  { name: "read", description: "Ler/visualizar" },
19
18
  { name: "update", description: "Atualizar" },
20
19
  { name: "delete", description: "Remover" },
21
- { name: "export", description: "Exportar" },
22
20
  { name: "promote", description: "Alterar papel/promover" },
23
21
  { name: "deactivate", description: "Ativar/desativar" },
24
22
  { name: "reset-password", description: "Resetar senha de usuário" },
@@ -26,13 +24,12 @@ exports.ACTIONS = [
26
24
  { name: "update-email", description: "Alterar email de usuário" },
27
25
  {
28
26
  name: "read-trail",
29
- description: "Ler trilha de auditoria de dados (old/new data)",
27
+ description: "Ler trilha de auditoria (tela Auditoria)",
30
28
  },
31
29
  ];
32
30
  exports.SCOPES = [
33
31
  { name: "own", description: "Apenas recursos próprios" },
34
32
  { name: "team", description: "Recursos da equipe" },
35
- { name: "department", description: "Recursos do departamento" },
36
33
  { name: "any", description: "Todos os recursos" },
37
34
  ];
38
35
  exports.PERMISSIONS = [
@@ -103,12 +100,6 @@ exports.PERMISSIONS = [
103
100
  code: "audit:read-trail:any",
104
101
  description: "Ler trilha de auditoria de dados (old/new data) — restrito a administradores",
105
102
  },
106
- { code: "reports:read:any", description: "Ler todos os relatórios" },
107
- {
108
- code: "reports:read:department",
109
- description: "Ler relatórios do departamento",
110
- },
111
- { code: "reports:export:any", description: "Exportar todos os relatórios" },
112
103
  {
113
104
  code: "notifications:read:own",
114
105
  description: "Ler e marcar como lidas as próprias notificações",
@@ -164,8 +155,6 @@ exports.ROLES = [
164
155
  "users:invite:team",
165
156
  "users:reset-password:team",
166
157
  "users:deactivate:team",
167
- "reports:read:department",
168
- "reports:read:any",
169
158
  "audit:read:any",
170
159
  "notifications:read:own",
171
160
  ],
@@ -175,7 +164,6 @@ exports.ROLES = [
175
164
  description: "Somente leitura",
176
165
  permissions: [
177
166
  "users:read:own",
178
- "reports:read:department",
179
167
  "notifications:read:own",
180
168
  ],
181
169
  },
@@ -184,7 +184,10 @@ let RbacService = class RbacService {
184
184
  await this.scopeRepo.softRemove(scope);
185
185
  }
186
186
  listPermissions() {
187
- return this.permissionRepo.find({ order: { code: "ASC" } });
187
+ return this.permissionRepo.find({
188
+ order: { code: "ASC" },
189
+ relations: { resource: true, action: true, scope: true },
190
+ });
188
191
  }
189
192
  async createPermission(dto) {
190
193
  const exists = await this.permissionRepo.findOne({
@@ -6,6 +6,7 @@ export declare class TeamScopeService {
6
6
  private readonly rbac;
7
7
  constructor(groupRepo: GroupRepository, rbac: RbacService);
8
8
  reachableUserIds(actor: Actor, action: string): Promise<string[] | null>;
9
+ private withSelf;
9
10
  managedGroupIds(managerId: string): Promise<string[]>;
10
11
  private reachOf;
11
12
  assertCanAct(actor: Actor, targetUserId: string, action: string): Promise<void>;
@@ -23,11 +23,17 @@ let TeamScopeService = class TeamScopeService {
23
23
  if (this.has(actor, action, permissionScope_util_1.SCOPE_ANY)) {
24
24
  return null;
25
25
  }
26
- if (!this.has(actor, action, permissionScope_util_1.SCOPE_TEAM)) {
27
- return [];
26
+ if (this.has(actor, action, permissionScope_util_1.SCOPE_TEAM)) {
27
+ const reach = await this.reachOf(actor.id);
28
+ return this.withSelf(reach.userIds, actor.id);
28
29
  }
29
- const reach = await this.reachOf(actor.id);
30
- return reach.userIds;
30
+ if (this.has(actor, action, permissionScope_util_1.SCOPE_OWN)) {
31
+ return [actor.id];
32
+ }
33
+ return [];
34
+ }
35
+ withSelf(userIds, actorId) {
36
+ return userIds.includes(actorId) ? userIds : [...userIds, actorId];
31
37
  }
32
38
  async managedGroupIds(managerId) {
33
39
  return this.groupRepo.findManagedGroupIds(managerId);
@@ -17,7 +17,7 @@ let Scope = class Scope extends base_schema_1.BaseEntity {
17
17
  };
18
18
  exports.Scope = Scope;
19
19
  __decorate([
20
- (0, swagger_1.ApiProperty)({ description: "own | team | department | any" }),
20
+ (0, swagger_1.ApiProperty)({ description: "own | team | any" }),
21
21
  (0, typeorm_1.Column)({ type: "varchar", length: 100, unique: true }),
22
22
  __metadata("design:type", String)
23
23
  ], Scope.prototype, "name", void 0);
@@ -16,7 +16,7 @@ class CreateScopeCommand {
16
16
  }
17
17
  exports.CreateScopeCommand = CreateScopeCommand;
18
18
  __decorate([
19
- (0, swagger_1.ApiProperty)({ example: "own", description: "own | team | department | any" }),
19
+ (0, swagger_1.ApiProperty)({ example: "own", description: "own | team | any" }),
20
20
  (0, class_validator_1.IsString)(),
21
21
  (0, class_validator_1.Matches)(/^[a-z-]+$/, {
22
22
  message: "name deve conter só letras minúsculas e hífen",
package/dist/index.d.ts CHANGED
@@ -18,8 +18,10 @@ export { AppThrottlerGuard } from "./core/auth/guards/appThrottler.guard";
18
18
  export { CsrfGuard } from "./core/auth/guards/csrf.guard";
19
19
  export { JwtAuthGuard } from "./core/auth/guards/jwtAuth.guard";
20
20
  export { PermissionsGuard } from "./core/auth/guards/permissions.guard";
21
- export { anyOrTeam, SCOPE_ANY, SCOPE_TEAM, } from "./core/auth/permissionScope.util";
21
+ export { OwnershipScope, resolveOwnershipScope, } from "./core/auth/ownershipScope.util";
22
+ export { anyOrOwn, anyOrTeam, SCOPE_ANY, SCOPE_OWN, SCOPE_TEAM, } from "./core/auth/permissionScope.util";
22
23
  export { applyFilter, FilterSql } from "./core/query/applyFilter.util";
24
+ export { applyOwnershipScope, OwnershipScopeOptions, } from "./core/query/applyOwnershipScope.util";
23
25
  export { DEFAULT_OPERATORS, FILTER_MAX_DEPTH, FILTER_MAX_IN_ITEMS, FILTER_MAX_LENGTH, FILTER_MAX_NODES, } from "./core/query/filter.constants";
24
26
  export { FilterCatalog, FilterCondition, FilterFieldDefinition, FilterGroup, FilterNode, FilterOption, FilterRelation, } from "./core/query/filterField.interface";
25
27
  export { FilterFieldType } from "./core/query/filterFieldType.enum";
@@ -32,13 +34,19 @@ export { Paginated, PaginationMeta, PaginationQuery, resolveOrder, SortDir, } fr
32
34
  export { PaginationMetaResponse } from "./core/utils/paginationMeta.response";
33
35
  export { BaseEntity } from "./core/database/base.schema";
34
36
  export { seedAdmin } from "./core/database/seeds/seedAdmin";
35
- export { seedPermissions } from "./core/database/seeds/seedPermissions";
37
+ export { RbacCatalogExtension, seedPermissions, } from "./core/database/seeds/seedPermissions";
36
38
  export { AuditDataChange } from "./features/audit/infra/schema/auditDataChange.schema";
37
39
  export { RequestLog } from "./features/audit/infra/schema/requestLog.schema";
38
40
  export { AuthToken } from "./features/auth/infra/schema/authToken.schema";
41
+ export { ACTIONS, PERMISSIONS, RESOURCES, ROLES, SCOPES, } from "./features/rbac/domain/rbac.catalog";
42
+ export { NotificationType } from "./features/notifications/domain/enums/notificationType.enum";
43
+ export { ScopeType } from "./features/notifications/domain/enums/scopeType.enum";
44
+ export { NotificationsService, NotificationTarget, PublishNotificationParams, UserNotification, } from "./features/notifications/domain/notifications.service";
39
45
  export { Notification } from "./features/notifications/infra/schema/notification.schema";
40
46
  export { NotificationRead } from "./features/notifications/infra/schema/notificationRead.schema";
41
47
  export { NotificationScope } from "./features/notifications/infra/schema/notificationScope.schema";
48
+ export { NotificationsModule } from "./features/notifications/notifications.module";
49
+ export { NotificationsPublisher } from "./features/notifications/presentation/notifications.publisher";
42
50
  export { Action } from "./features/rbac/infra/schema/action.schema";
43
51
  export { Group } from "./features/rbac/infra/schema/group.schema";
44
52
  export { Permission } from "./features/rbac/infra/schema/permission.schema";
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.seedPermissions = exports.seedAdmin = exports.BaseEntity = exports.PaginationMetaResponse = exports.resolveOrder = exports.PaginationQuery = exports.Paginated = exports.parseFilter = exports.paginateWithFilter = exports.resolveCatalogOrder = exports.toFilterSchema = exports.FilterOptionResponse = exports.FilterFieldResponse = exports.FilterOperator = exports.FilterCombinator = exports.FilterFieldType = exports.FILTER_MAX_NODES = exports.FILTER_MAX_LENGTH = exports.FILTER_MAX_IN_ITEMS = exports.FILTER_MAX_DEPTH = exports.DEFAULT_OPERATORS = exports.applyFilter = exports.SCOPE_TEAM = exports.SCOPE_ANY = exports.anyOrTeam = exports.PermissionsGuard = exports.JwtAuthGuard = exports.CsrfGuard = exports.AppThrottlerGuard = exports.RequirePermission = exports.RequireAnyPermission = exports.PERMISSIONS_KEY = exports.ANY_PERMISSIONS_KEY = exports.Public = exports.IS_PUBLIC_KEY = exports.CurrentUser = exports.setAuthCookies = exports.REFRESH_COOKIE = exports.clearAuthCookies = exports.ACCESS_COOKIE = exports.EnvService = exports.validateEnv = exports.envSchema = exports.ConfigModule = exports.RlCoreModule = exports.coreEntities = exports.coreMigrations = exports.createCoreDataSource = exports.CoreModule = exports.bootstrapCore = void 0;
4
- exports.normalizeIp = exports.sha256 = exports.randomToken = exports.numericCode = exports.backupCode = exports.encryptSecret = exports.decryptSecret = exports.MailerService = exports.createAppLogger = exports.WS_USER_RESOLVER = exports.WsAuthService = exports.wrapSocketEvent = exports.SOCKET_EVENT_VERSION = exports.userRoom = exports.SESSION_REFRESH_EVENT = exports.roleRoom = exports.NOTIFICATIONS_NAMESPACE = exports.BaseGateway = exports.Auditable = exports.RequestOutcome = exports.ErrorType = exports.codedUnauthorized = exports.codedTooManyRequests = exports.codedBadRequest = exports.AppErrorCode = exports.AppEvent = exports.auditContext = exports.User = exports.PasswordHistory = exports.Scope = exports.Role = exports.Resource = exports.Permission = exports.Group = exports.Action = exports.NotificationScope = exports.NotificationRead = exports.Notification = exports.AuthToken = exports.RequestLog = exports.AuditDataChange = void 0;
3
+ exports.resolveOrder = exports.PaginationQuery = exports.Paginated = exports.parseFilter = exports.paginateWithFilter = exports.resolveCatalogOrder = exports.toFilterSchema = exports.FilterOptionResponse = exports.FilterFieldResponse = exports.FilterOperator = exports.FilterCombinator = exports.FilterFieldType = exports.FILTER_MAX_NODES = exports.FILTER_MAX_LENGTH = exports.FILTER_MAX_IN_ITEMS = exports.FILTER_MAX_DEPTH = exports.DEFAULT_OPERATORS = exports.applyOwnershipScope = exports.applyFilter = exports.SCOPE_TEAM = exports.SCOPE_OWN = exports.SCOPE_ANY = exports.anyOrTeam = exports.anyOrOwn = exports.resolveOwnershipScope = exports.PermissionsGuard = exports.JwtAuthGuard = exports.CsrfGuard = exports.AppThrottlerGuard = exports.RequirePermission = exports.RequireAnyPermission = exports.PERMISSIONS_KEY = exports.ANY_PERMISSIONS_KEY = exports.Public = exports.IS_PUBLIC_KEY = exports.CurrentUser = exports.setAuthCookies = exports.REFRESH_COOKIE = exports.clearAuthCookies = exports.ACCESS_COOKIE = exports.EnvService = exports.validateEnv = exports.envSchema = exports.ConfigModule = exports.RlCoreModule = exports.coreEntities = exports.coreMigrations = exports.createCoreDataSource = exports.CoreModule = exports.bootstrapCore = void 0;
4
+ exports.encryptSecret = exports.decryptSecret = exports.MailerService = exports.createAppLogger = exports.WS_USER_RESOLVER = exports.WsAuthService = exports.wrapSocketEvent = exports.SOCKET_EVENT_VERSION = exports.userRoom = exports.SESSION_REFRESH_EVENT = exports.roleRoom = exports.NOTIFICATIONS_NAMESPACE = exports.BaseGateway = exports.Auditable = exports.RequestOutcome = exports.ErrorType = exports.codedUnauthorized = exports.codedTooManyRequests = exports.codedBadRequest = exports.AppErrorCode = exports.AppEvent = exports.auditContext = exports.User = exports.PasswordHistory = exports.Scope = exports.Role = exports.Resource = exports.Permission = exports.Group = exports.Action = exports.NotificationsPublisher = exports.NotificationsModule = exports.NotificationScope = exports.NotificationRead = exports.Notification = exports.NotificationsService = exports.ScopeType = exports.NotificationType = exports.SCOPES = exports.ROLES = exports.RESOURCES = exports.PERMISSIONS = exports.ACTIONS = exports.AuthToken = exports.RequestLog = exports.AuditDataChange = exports.seedPermissions = exports.seedAdmin = exports.BaseEntity = exports.PaginationMetaResponse = void 0;
5
+ exports.normalizeIp = exports.sha256 = exports.randomToken = exports.numericCode = exports.backupCode = void 0;
5
6
  var bootstrapCore_util_1 = require("./core/bootstrap/bootstrapCore.util");
6
7
  Object.defineProperty(exports, "bootstrapCore", { enumerable: true, get: function () { return bootstrapCore_util_1.bootstrapCore; } });
7
8
  var core_module_1 = require("./core/core.module");
@@ -44,12 +45,18 @@ var jwtAuth_guard_1 = require("./core/auth/guards/jwtAuth.guard");
44
45
  Object.defineProperty(exports, "JwtAuthGuard", { enumerable: true, get: function () { return jwtAuth_guard_1.JwtAuthGuard; } });
45
46
  var permissions_guard_1 = require("./core/auth/guards/permissions.guard");
46
47
  Object.defineProperty(exports, "PermissionsGuard", { enumerable: true, get: function () { return permissions_guard_1.PermissionsGuard; } });
48
+ var ownershipScope_util_1 = require("./core/auth/ownershipScope.util");
49
+ Object.defineProperty(exports, "resolveOwnershipScope", { enumerable: true, get: function () { return ownershipScope_util_1.resolveOwnershipScope; } });
47
50
  var permissionScope_util_1 = require("./core/auth/permissionScope.util");
51
+ Object.defineProperty(exports, "anyOrOwn", { enumerable: true, get: function () { return permissionScope_util_1.anyOrOwn; } });
48
52
  Object.defineProperty(exports, "anyOrTeam", { enumerable: true, get: function () { return permissionScope_util_1.anyOrTeam; } });
49
53
  Object.defineProperty(exports, "SCOPE_ANY", { enumerable: true, get: function () { return permissionScope_util_1.SCOPE_ANY; } });
54
+ Object.defineProperty(exports, "SCOPE_OWN", { enumerable: true, get: function () { return permissionScope_util_1.SCOPE_OWN; } });
50
55
  Object.defineProperty(exports, "SCOPE_TEAM", { enumerable: true, get: function () { return permissionScope_util_1.SCOPE_TEAM; } });
51
56
  var applyFilter_util_1 = require("./core/query/applyFilter.util");
52
57
  Object.defineProperty(exports, "applyFilter", { enumerable: true, get: function () { return applyFilter_util_1.applyFilter; } });
58
+ var applyOwnershipScope_util_1 = require("./core/query/applyOwnershipScope.util");
59
+ Object.defineProperty(exports, "applyOwnershipScope", { enumerable: true, get: function () { return applyOwnershipScope_util_1.applyOwnershipScope; } });
53
60
  var filter_constants_1 = require("./core/query/filter.constants");
54
61
  Object.defineProperty(exports, "DEFAULT_OPERATORS", { enumerable: true, get: function () { return filter_constants_1.DEFAULT_OPERATORS; } });
55
62
  Object.defineProperty(exports, "FILTER_MAX_DEPTH", { enumerable: true, get: function () { return filter_constants_1.FILTER_MAX_DEPTH; } });
@@ -89,12 +96,28 @@ var requestLog_schema_1 = require("./features/audit/infra/schema/requestLog.sche
89
96
  Object.defineProperty(exports, "RequestLog", { enumerable: true, get: function () { return requestLog_schema_1.RequestLog; } });
90
97
  var authToken_schema_1 = require("./features/auth/infra/schema/authToken.schema");
91
98
  Object.defineProperty(exports, "AuthToken", { enumerable: true, get: function () { return authToken_schema_1.AuthToken; } });
99
+ var rbac_catalog_1 = require("./features/rbac/domain/rbac.catalog");
100
+ Object.defineProperty(exports, "ACTIONS", { enumerable: true, get: function () { return rbac_catalog_1.ACTIONS; } });
101
+ Object.defineProperty(exports, "PERMISSIONS", { enumerable: true, get: function () { return rbac_catalog_1.PERMISSIONS; } });
102
+ Object.defineProperty(exports, "RESOURCES", { enumerable: true, get: function () { return rbac_catalog_1.RESOURCES; } });
103
+ Object.defineProperty(exports, "ROLES", { enumerable: true, get: function () { return rbac_catalog_1.ROLES; } });
104
+ Object.defineProperty(exports, "SCOPES", { enumerable: true, get: function () { return rbac_catalog_1.SCOPES; } });
105
+ var notificationType_enum_1 = require("./features/notifications/domain/enums/notificationType.enum");
106
+ Object.defineProperty(exports, "NotificationType", { enumerable: true, get: function () { return notificationType_enum_1.NotificationType; } });
107
+ var scopeType_enum_1 = require("./features/notifications/domain/enums/scopeType.enum");
108
+ Object.defineProperty(exports, "ScopeType", { enumerable: true, get: function () { return scopeType_enum_1.ScopeType; } });
109
+ var notifications_service_1 = require("./features/notifications/domain/notifications.service");
110
+ Object.defineProperty(exports, "NotificationsService", { enumerable: true, get: function () { return notifications_service_1.NotificationsService; } });
92
111
  var notification_schema_1 = require("./features/notifications/infra/schema/notification.schema");
93
112
  Object.defineProperty(exports, "Notification", { enumerable: true, get: function () { return notification_schema_1.Notification; } });
94
113
  var notificationRead_schema_1 = require("./features/notifications/infra/schema/notificationRead.schema");
95
114
  Object.defineProperty(exports, "NotificationRead", { enumerable: true, get: function () { return notificationRead_schema_1.NotificationRead; } });
96
115
  var notificationScope_schema_1 = require("./features/notifications/infra/schema/notificationScope.schema");
97
116
  Object.defineProperty(exports, "NotificationScope", { enumerable: true, get: function () { return notificationScope_schema_1.NotificationScope; } });
117
+ var notifications_module_1 = require("./features/notifications/notifications.module");
118
+ Object.defineProperty(exports, "NotificationsModule", { enumerable: true, get: function () { return notifications_module_1.NotificationsModule; } });
119
+ var notifications_publisher_1 = require("./features/notifications/presentation/notifications.publisher");
120
+ Object.defineProperty(exports, "NotificationsPublisher", { enumerable: true, get: function () { return notifications_publisher_1.NotificationsPublisher; } });
98
121
  var action_schema_1 = require("./features/rbac/infra/schema/action.schema");
99
122
  Object.defineProperty(exports, "Action", { enumerable: true, get: function () { return action_schema_1.Action; } });
100
123
  var group_schema_1 = require("./features/rbac/infra/schema/group.schema");
@@ -33,6 +33,7 @@ let RlCoreModule = RlCoreModule_1 = class RlCoreModule {
33
33
  maintenance_module_1.MaintenanceModule,
34
34
  notifications_module_1.NotificationsModule,
35
35
  ],
36
+ exports: [notifications_module_1.NotificationsModule],
36
37
  };
37
38
  }
38
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rl-core-api",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Core NestJS: autenticação com 2FA, RBAC, auditoria, notificações e listagens com filtro dinâmico",
5
5
  "author": "Rodrigo Liberti",
6
6
  "license": "MIT",
@@ -1,6 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from "typeorm";
2
- export declare class GroupManager1787270400000 implements MigrationInterface {
3
- name: string;
4
- up(queryRunner: QueryRunner): Promise<void>;
5
- down(queryRunner: QueryRunner): Promise<void>;
6
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GroupManager1787270400000 = void 0;
4
- class GroupManager1787270400000 {
5
- constructor() {
6
- this.name = "GroupManager1787270400000";
7
- }
8
- async up(queryRunner) {
9
- await queryRunner.query(`
10
- ALTER TABLE \`groups\`
11
- ADD COLUMN manager_id char(36) NULL AFTER parent_id,
12
- ADD KEY IDX_groups_manager (manager_id),
13
- ADD CONSTRAINT FK_groups_manager FOREIGN KEY (manager_id)
14
- REFERENCES users (id) ON DELETE SET NULL;
15
- `);
16
- }
17
- async down(queryRunner) {
18
- await queryRunner.query(`
19
- ALTER TABLE \`groups\`
20
- DROP FOREIGN KEY FK_groups_manager,
21
- DROP KEY IDX_groups_manager,
22
- DROP COLUMN manager_id;
23
- `);
24
- }
25
- }
26
- exports.GroupManager1787270400000 = GroupManager1787270400000;