@comasoft/nestjs 0.1.53 → 0.1.54
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/database/entities/logs-audit.entity.d.ts +1 -0
- package/dist/database/entities/logs-audit.entity.js +1 -1
- package/dist/database/entities/logs-event.entity.d.ts +1 -0
- package/dist/database/entities/logs-event.entity.js +1 -1
- package/dist/events/services/event-storage.service.js +1 -1
- package/dist/events/types/audit-events.type.d.ts +3 -1
- package/dist/filters/http-exception.filter.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,o,n){var i,r=arguments.length,l=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,o,n);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(l=(r<3?i(l):r>3?i(t,o,l):i(t,o))||l);return r>3&&l&&Object.defineProperty(t,o,l),l},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogsAudit=void 0;const o=require("typeorm"),n=require("../../enums.common");let i=class LogsAudit{};exports.LogsAudit=i,e([(0,o.PrimaryGeneratedColumn)(),t("design:type",Number)],i.prototype,"id",void 0),e([(0,o.Column)("char",{length:21}),t("design:type",String)],i.prototype,"uid",void 0),e([(0,o.Column)("varchar",{length:255}),t("design:type",String)],i.prototype,"name",void 0),e([(0,o.Column)("varchar",{length:50,nullable:!0}),t("design:type",String)],i.prototype,"entity",void 0),e([(0,o.Column)("int",{nullable:!0,comment:"-1: all, 0: none"}),t("design:type",Number)],i.prototype,"entity_id",void 0),e([(0,o.Column)("enum",{enum:n.AUDIT_ACTION,nullable:!0}),t("design:type",String)],i.prototype,"action",void 0),e([(0,o.Column)("int"),t("design:type",Number)],i.prototype,"user_id",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],i.prototype,"changes",void 0),e([(0,o.Column)("varchar",{length:45,nullable:!0}),t("design:type",String)],i.prototype,"ip_address",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],i.prototype,"user_agent",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],i.prototype,"description",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],i.prototype,"meta",void 0),e([(0,o.Column)("timestamptz"),t("design:type",Date)],i.prototype,"occurred_at",void 0),e([(0,o.CreateDateColumn)({type:"timestamptz"}),t("design:type",Date)],i.prototype,"created_at",void 0),exports.LogsAudit=i=e([(0,o.Entity)("logs_audit"),(0,o.Index)(["uid"]),(0,o.Index)(["name","entity_id"]),(0,o.Index)(["user_id","name","entity_id"])],i);
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,o,n){var i,r=arguments.length,l=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,o,n);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(l=(r<3?i(l):r>3?i(t,o,l):i(t,o))||l);return r>3&&l&&Object.defineProperty(t,o,l),l},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogsAudit=void 0;const o=require("typeorm"),n=require("../../enums.common");let i=class LogsAudit{};exports.LogsAudit=i,e([(0,o.PrimaryGeneratedColumn)(),t("design:type",Number)],i.prototype,"id",void 0),e([(0,o.Column)("char",{length:21}),t("design:type",String)],i.prototype,"uid",void 0),e([(0,o.Column)("varchar",{length:255}),t("design:type",String)],i.prototype,"name",void 0),e([(0,o.Column)("varchar",{length:50,nullable:!0}),t("design:type",String)],i.prototype,"entity",void 0),e([(0,o.Column)("int",{nullable:!0,comment:"-1: all, 0: none"}),t("design:type",Number)],i.prototype,"entity_id",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Array)],i.prototype,"entity_ids",void 0),e([(0,o.Column)("enum",{enum:n.AUDIT_ACTION,nullable:!0}),t("design:type",String)],i.prototype,"action",void 0),e([(0,o.Column)("int"),t("design:type",Number)],i.prototype,"user_id",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],i.prototype,"changes",void 0),e([(0,o.Column)("varchar",{length:45,nullable:!0}),t("design:type",String)],i.prototype,"ip_address",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],i.prototype,"user_agent",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],i.prototype,"description",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],i.prototype,"meta",void 0),e([(0,o.Column)("timestamptz"),t("design:type",Date)],i.prototype,"occurred_at",void 0),e([(0,o.CreateDateColumn)({type:"timestamptz"}),t("design:type",Date)],i.prototype,"created_at",void 0),exports.LogsAudit=i=e([(0,o.Entity)("logs_audit"),(0,o.Index)(["uid"]),(0,o.Index)(["name","entity_id"]),(0,o.Index)(["user_id","name","entity_id"])],i);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,o,n){var r,i=arguments.length,l=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,o,n);else for(var p=e.length-1;p>=0;p--)(r=e[p])&&(l=(i<3?r(l):i>3?r(t,o,l):r(t,o))||l);return i>3&&l&&Object.defineProperty(t,o,l),l},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogsEvent=void 0;const o=require("typeorm"),n=require("../../enums.common");let r=class LogsEvent{};exports.LogsEvent=r,e([(0,o.PrimaryGeneratedColumn)(),t("design:type",Number)],r.prototype,"id",void 0),e([(0,o.Column)("char",{length:21}),t("design:type",String)],r.prototype,"uid",void 0),e([(0,o.Column)("varchar",{length:255}),t("design:type",String)],r.prototype,"name",void 0),e([(0,o.Column)("varchar",{length:50,nullable:!0}),t("design:type",String)],r.prototype,"entity",void 0),e([(0,o.Column)("int",{nullable:!0}),t("design:type",Number)],r.prototype,"entity_id",void 0),e([(0,o.Column)("enum",{enum:n.AUDIT_ACTION,nullable:!0}),t("design:type",String)],r.prototype,"action",void 0),e([(0,o.Column)("int",{nullable:!0}),t("design:type",Number)],r.prototype,"user_id",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],r.prototype,"changes",void 0),e([(0,o.Column)("varchar",{length:45,nullable:!0}),t("design:type",String)],r.prototype,"ip_address",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],r.prototype,"user_agent",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],r.prototype,"description",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],r.prototype,"meta",void 0),e([(0,o.Column)("timestamptz"),t("design:type",Date)],r.prototype,"occurred_at",void 0),e([(0,o.CreateDateColumn)({type:"timestamptz"}),t("design:type",Date)],r.prototype,"created_at",void 0),exports.LogsEvent=r=e([(0,o.Entity)("logs_event")],r);
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,o,n){var r,i=arguments.length,l=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,o,n);else for(var p=e.length-1;p>=0;p--)(r=e[p])&&(l=(i<3?r(l):i>3?r(t,o,l):r(t,o))||l);return i>3&&l&&Object.defineProperty(t,o,l),l},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogsEvent=void 0;const o=require("typeorm"),n=require("../../enums.common");let r=class LogsEvent{};exports.LogsEvent=r,e([(0,o.PrimaryGeneratedColumn)(),t("design:type",Number)],r.prototype,"id",void 0),e([(0,o.Column)("char",{length:21}),t("design:type",String)],r.prototype,"uid",void 0),e([(0,o.Column)("varchar",{length:255}),t("design:type",String)],r.prototype,"name",void 0),e([(0,o.Column)("varchar",{length:50,nullable:!0}),t("design:type",String)],r.prototype,"entity",void 0),e([(0,o.Column)("int",{nullable:!0}),t("design:type",Number)],r.prototype,"entity_id",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Array)],r.prototype,"entity_ids",void 0),e([(0,o.Column)("enum",{enum:n.AUDIT_ACTION,nullable:!0}),t("design:type",String)],r.prototype,"action",void 0),e([(0,o.Column)("int",{nullable:!0}),t("design:type",Number)],r.prototype,"user_id",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],r.prototype,"changes",void 0),e([(0,o.Column)("varchar",{length:45,nullable:!0}),t("design:type",String)],r.prototype,"ip_address",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],r.prototype,"user_agent",void 0),e([(0,o.Column)("varchar",{length:255,nullable:!0}),t("design:type",String)],r.prototype,"description",void 0),e([(0,o.Column)("jsonb",{nullable:!0}),t("design:type",Object)],r.prototype,"meta",void 0),e([(0,o.Column)("timestamptz"),t("design:type",Date)],r.prototype,"occurred_at",void 0),e([(0,o.CreateDateColumn)({type:"timestamptz"}),t("design:type",Date)],r.prototype,"created_at",void 0),exports.LogsEvent=r=e([(0,o.Entity)("logs_event")],r);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__decorate||function(e,t,i,
|
|
1
|
+
var e=this&&this.__decorate||function(e,t,i,n){var o,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(r<3?o(s):r>3?o(t,i,s):o(t,i))||s);return r>3&&s&&Object.defineProperty(t,i,s),s},t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},i=this&&this.__param||function(e,t){return function(i,n){t(i,n,e)}},n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function fulfilled(e){try{step(n.next(e))}catch(e){r(e)}}function rejected(e){try{step(n.throw(e))}catch(e){r(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof i?e:new i(function(t){t(e)})}(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventStorageService=void 0;const o=require("@nestjs/common"),r=require("@nestjs/typeorm"),s=require("nanoid"),a=require("typeorm"),d=require("../../database/entities");let u=class EventStorageService{constructor(e,t,i){this.eventLogRepository=e,this.auditLogRepository=t,this.dataSource=i}store(e){return n(this,void 0,void 0,function*(){var t,i,n;const o=this.eventLogRepository.create({uid:e.uid||(0,s.nanoid)(),name:e.name,user_id:(null===(t=e.user)||void 0===t?void 0:t.user_id)||0,ip_address:null===(i=e.user)||void 0===i?void 0:i.ip_address,user_agent:null===(n=e.user)||void 0===n?void 0:n.user_agent,occurred_at:e.timestamp||new Date});yield this.eventLogRepository.save(o)})}storeAuditEvent(e){return n(this,void 0,void 0,function*(){yield this.dataSource.transaction(t=>n(this,void 0,void 0,function*(){var i,n,o;const r=t.create(d.LogsAudit,{uid:e.uid||(0,s.nanoid)(),name:e.name,user_id:(null===(i=e.user)||void 0===i?void 0:i.user_id)||0,entity:e.entity,entity_id:e.entity_id,entity_ids:e.entity_ids,action:e.action,changes:e.changes,ip_address:null===(n=e.user)||void 0===n?void 0:n.ip_address,user_agent:null===(o=e.user)||void 0===o?void 0:o.user_agent,occurred_at:e.timestamp||new Date,meta:e.meta});yield t.save(r)}))})}};exports.EventStorageService=u,exports.EventStorageService=u=e([(0,o.Injectable)(),i(0,(0,r.InjectRepository)(d.LogsEvent)),i(1,(0,r.InjectRepository)(d.LogsAudit)),t("design:paramtypes",[a.Repository,a.Repository,a.DataSource])],u);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { AUDIT_ACTION } from '../../enums.common';
|
|
2
1
|
import { BaseEvent } from '.';
|
|
2
|
+
import { AUDIT_ACTION } from '../../enums.common';
|
|
3
3
|
export interface AuditEventBase<TName extends string = string> extends BaseEvent {
|
|
4
4
|
readonly name: TName;
|
|
5
5
|
readonly entity: string;
|
|
6
6
|
readonly entity_id: number;
|
|
7
|
+
readonly entity_ids?: string[];
|
|
7
8
|
readonly action: AUDIT_ACTION;
|
|
8
9
|
readonly changes?: Record<string, {
|
|
9
10
|
before: any;
|
|
10
11
|
after: any;
|
|
11
12
|
}>;
|
|
13
|
+
readonly meta?: Record<string, any>;
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t=this&&this.__decorate||function(e,t,r,o){var n,s=arguments.length,
|
|
1
|
+
var e,t=this&&this.__decorate||function(e,t,r,o){var n,s=arguments.length,i=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,o);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(i=(s<3?n(i):s>3?n(t,r,i):n(t,r))||i);return s>3&&i&&Object.defineProperty(t,r,i),i},r=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.HttpExceptionFilter=void 0;const o=require("@nestjs/common"),n=require("@nestjs/event-emitter");let s=e=class HttpExceptionFilter{constructor(t){this.eventEmitter=t,this.logger=new o.Logger(e.name)}catch(e,t){var r,n,s;const i=t.switchToHttp(),a=i.getResponse(),c=i.getRequest();o.ForbiddenException;let l=e instanceof o.HttpException?e.getStatus():o.HttpStatus.INTERNAL_SERVER_ERROR,p={};if(e instanceof o.HttpException?p=e.getResponse():(this.logger.error(`Unhandled exception: ${c.method} ${c.url}`),"TokenError"===(null==e?void 0:e.name)?(l=o.HttpStatus.UNAUTHORIZED,p={error:"Unauthorized"}):p={error:"Internal Server Error",message:"An unexpected error occurred."}),"string"==typeof p)a.status(l).json({success:!1,code:l,timestamp:(new Date).toISOString(),path:c.url,message:p});else{let e=null!==(r=p.message)&&void 0!==r?r:p.error;Array.isArray(e)&&e.length>0&&"object"==typeof e[0]&&(e=e.map(e=>e.constraints?Object.values(e.constraints):"Invalid input").flat()),a.status(l).json({success:!1,status:l,path:c.url,message:e,code:null!==(n=p.code)&&void 0!==n?n:void 0,meta:null!==(s=p.meta)&&void 0!==s?s:void 0})}}};exports.HttpExceptionFilter=s,exports.HttpExceptionFilter=s=e=t([(0,o.Catch)(),r("design:paramtypes",[n.EventEmitter2])],s);
|