@grupo-argenta/schema-kit-nest 0.0.20 → 0.0.21

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.
Files changed (157) hide show
  1. package/config/naming-strategy.d.ts +6 -0
  2. package/config/naming-strategy.js +17 -0
  3. package/config/redis.constants.d.ts +1 -0
  4. package/config/redis.constants.js +4 -0
  5. package/context-logger.service.d.ts +4 -0
  6. package/context-logger.service.js +23 -0
  7. package/decorators/date-range.d.ts +4 -0
  8. package/decorators/date-range.js +17 -0
  9. package/decorators/encrypted.d.ts +10 -0
  10. package/decorators/encrypted.js +15 -0
  11. package/decorators/file-column.d.ts +17 -0
  12. package/decorators/file-column.js +20 -0
  13. package/decorators/get-user.decorator.d.ts +6 -0
  14. package/decorators/get-user.decorator.js +12 -0
  15. package/decorators/luxon.d.ts +6 -0
  16. package/decorators/luxon.js +20 -0
  17. package/decorators/multipart.decorator.d.ts +4 -0
  18. package/decorators/multipart.decorator.js +51 -0
  19. package/decorators/post-get.decorator.d.ts +10 -0
  20. package/decorators/post-get.decorator.js +25 -0
  21. package/decorators/query-or-body.decorator.d.ts +8 -0
  22. package/decorators/query-or-body.decorator.js +15 -0
  23. package/decorators/when.decorator.d.ts +8 -0
  24. package/decorators/when.decorator.js +16 -0
  25. package/html/components/badge.d.ts +13 -0
  26. package/html/components/badge.js +29 -0
  27. package/html/components/colors.d.ts +11 -0
  28. package/html/components/colors.js +15 -0
  29. package/html/components/component.d.ts +11 -0
  30. package/html/components/component.js +35 -0
  31. package/html/components/default/default-footer.d.ts +6 -0
  32. package/html/components/default/default-footer.js +18 -0
  33. package/html/components/default/default-header.d.ts +13 -0
  34. package/html/components/default/default-header.js +30 -0
  35. package/html/components/env-badge.d.ts +7 -0
  36. package/html/components/env-badge.js +29 -0
  37. package/html/components/grid.d.ts +17 -0
  38. package/html/components/grid.js +44 -0
  39. package/html/components/shell.d.ts +18 -0
  40. package/html/components/shell.js +423 -0
  41. package/html/components/table.d.ts +16 -0
  42. package/html/components/table.js +55 -0
  43. package/html/components/unordered-list.d.ts +6 -0
  44. package/html/components/unordered-list.js +21 -0
  45. package/index.d.ts +49 -0
  46. package/index.js +65 -0
  47. package/interfaces/paginated-result.d.ts +21 -0
  48. package/interfaces/paginated-result.js +12 -0
  49. package/modules/auth/access-token.d.ts +27 -0
  50. package/modules/auth/access-token.js +14 -0
  51. package/modules/auth/known-module.d.ts +45 -0
  52. package/modules/auth/known-module.js +46 -0
  53. package/modules/auth/refresh-token.d.ts +18 -0
  54. package/modules/auth/refresh-token.js +2 -0
  55. package/modules/auth/token-type.d.ts +4 -0
  56. package/modules/auth/token-type.js +8 -0
  57. package/modules/encrypted-column/encrypted-column.module.d.ts +16 -0
  58. package/modules/encrypted-column/encrypted-column.module.js +35 -0
  59. package/modules/pubsub/pubsub-dynamic-topic.service.d.ts +77 -0
  60. package/modules/pubsub/pubsub-dynamic-topic.service.js +324 -0
  61. package/modules/pubsub/pubsub-redeliver-subscriber.service.d.ts +14 -0
  62. package/modules/pubsub/pubsub-redeliver-subscriber.service.js +77 -0
  63. package/modules/pubsub/pubsub-redeliver.service.d.ts +22 -0
  64. package/modules/pubsub/pubsub-redeliver.service.js +48 -0
  65. package/modules/pubsub/pubsub.constants.d.ts +2 -0
  66. package/modules/pubsub/pubsub.constants.js +5 -0
  67. package/modules/pubsub/pubsub.methods.d.ts +18 -0
  68. package/modules/pubsub/pubsub.methods.js +18 -0
  69. package/modules/pubsub/pubsub.methods.redelivery.d.ts +3 -0
  70. package/modules/pubsub/pubsub.methods.redelivery.js +2 -0
  71. package/modules/redis/redis.module.d.ts +10 -0
  72. package/modules/redis/redis.module.js +59 -0
  73. package/modules/redis/redis.options.d.ts +7 -0
  74. package/modules/redis/redis.options.js +4 -0
  75. package/modules/storage/storage.service.d.ts +16 -0
  76. package/modules/storage/storage.service.js +61 -0
  77. package/monitoramento/http-request-log/http-request-log.controller.d.ts +184 -0
  78. package/monitoramento/http-request-log/http-request-log.controller.js +32 -0
  79. package/monitoramento/http-request-log/http-request-log.dto.d.ts +220 -0
  80. package/monitoramento/http-request-log/http-request-log.dto.js +42 -0
  81. package/monitoramento/http-request-log/http-request-log.entity.d.ts +17 -0
  82. package/monitoramento/http-request-log/http-request-log.entity.js +87 -0
  83. package/monitoramento/http-request-log/http-request-log.module.d.ts +2 -0
  84. package/monitoramento/http-request-log/http-request-log.module.js +26 -0
  85. package/monitoramento/http-request-log/http-request-log.service.d.ts +8 -0
  86. package/monitoramento/http-request-log/http-request-log.service.js +35 -0
  87. package/monitoramento/index.d.ts +17 -0
  88. package/monitoramento/index.js +33 -0
  89. package/monitoramento/migrations/1792689106394-create_http_request_logs_table.d.ts +5 -0
  90. package/monitoramento/migrations/1792689106394-create_http_request_logs_table.js +96 -0
  91. package/monitoramento/migrations/1792689106395-create_pubsub_message_logs_table.d.ts +5 -0
  92. package/monitoramento/migrations/1792689106395-create_pubsub_message_logs_table.js +157 -0
  93. package/monitoramento/monitoramento.constants.d.ts +2 -0
  94. package/monitoramento/monitoramento.constants.js +5 -0
  95. package/monitoramento/monitoramento.entities.d.ts +1 -0
  96. package/monitoramento/monitoramento.entities.js +7 -0
  97. package/monitoramento/monitoramento.module.d.ts +6 -0
  98. package/monitoramento/monitoramento.module.js +61 -0
  99. package/monitoramento/monitoramento.options.d.ts +15 -0
  100. package/monitoramento/monitoramento.options.js +2 -0
  101. package/monitoramento/outbound-request.interceptor.d.ts +14 -0
  102. package/monitoramento/outbound-request.interceptor.js +113 -0
  103. package/monitoramento/pubsub-message-log/pubsub-message-log.controller.d.ts +257 -0
  104. package/monitoramento/pubsub-message-log/pubsub-message-log.controller.js +34 -0
  105. package/monitoramento/pubsub-message-log/pubsub-message-log.dto.d.ts +320 -0
  106. package/monitoramento/pubsub-message-log/pubsub-message-log.dto.js +57 -0
  107. package/monitoramento/pubsub-message-log/pubsub-message-log.entity.d.ts +44 -0
  108. package/monitoramento/pubsub-message-log/pubsub-message-log.entity.js +152 -0
  109. package/monitoramento/pubsub-message-log/pubsub-message-log.module.d.ts +2 -0
  110. package/monitoramento/pubsub-message-log/pubsub-message-log.module.js +26 -0
  111. package/monitoramento/pubsub-message-log/pubsub-message-log.service.d.ts +20 -0
  112. package/monitoramento/pubsub-message-log/pubsub-message-log.service.js +99 -0
  113. package/monitoramento/pubsub-self-check/pubsub-self-check.controller.d.ts +9 -0
  114. package/monitoramento/pubsub-self-check/pubsub-self-check.controller.js +45 -0
  115. package/monitoramento/pubsub-self-check/pubsub-self-check.module.d.ts +11 -0
  116. package/monitoramento/pubsub-self-check/pubsub-self-check.module.js +41 -0
  117. package/monitoramento/pubsub-self-check/pubsub-self-check.options.d.ts +10 -0
  118. package/monitoramento/pubsub-self-check/pubsub-self-check.options.js +4 -0
  119. package/monitoramento/pubsub-self-check/pubsub-self-check.service.d.ts +68 -0
  120. package/monitoramento/pubsub-self-check/pubsub-self-check.service.js +213 -0
  121. package/package.json +1 -1
  122. package/schema/abstract.entity.d.ts +28 -0
  123. package/schema/abstract.entity.js +68 -0
  124. package/schema/schema-builder.d.ts +131 -0
  125. package/schema/schema-builder.js +162 -0
  126. package/schema/schema.controller.d.ts +51 -0
  127. package/schema/schema.controller.js +121 -0
  128. package/schema/schema.service.d.ts +81 -0
  129. package/schema/schema.service.js +305 -0
  130. package/schema/typeorm-extensions.d.ts +6 -0
  131. package/schema/typeorm-extensions.js +6 -0
  132. package/schema/zod-extensions/cnpj.validator.d.ts +28 -0
  133. package/schema/zod-extensions/cnpj.validator.js +133 -0
  134. package/schema/zod-extensions/cpf-cnpj.validator.d.ts +2 -0
  135. package/schema/zod-extensions/cpf-cnpj.validator.js +8 -0
  136. package/schema/zod-extensions/cpf.validator.d.ts +18 -0
  137. package/schema/zod-extensions/cpf.validator.js +166 -0
  138. package/schema/zod-extensions.d.ts +50 -0
  139. package/schema/zod-extensions.js +144 -0
  140. package/schema-kit.module.d.ts +2 -0
  141. package/schema-kit.module.js +23 -0
  142. package/transformers/date-range.transformer.d.ts +6 -0
  143. package/transformers/date-range.transformer.js +44 -0
  144. package/transformers/encrypted.transformer.d.ts +11 -0
  145. package/transformers/encrypted.transformer.js +35 -0
  146. package/transformers/luxon.transformer.d.ts +3 -0
  147. package/transformers/luxon.transformer.js +12 -0
  148. package/utils/utils.d.ts +49 -0
  149. package/utils/utils.js +79 -0
  150. package/validators/ip-validator.d.ts +3 -0
  151. package/validators/ip-validator.js +8 -0
  152. package/validators/pubsub-delete.validator.d.ts +6 -0
  153. package/validators/pubsub-delete.validator.js +11 -0
  154. package/validators/url-validator.d.ts +3 -0
  155. package/validators/url-validator.js +8 -0
  156. package/validators/uuid-validator.d.ts +3 -0
  157. package/validators/uuid-validator.js +8 -0
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.IndexPubsubMessageLogSchema = exports.PatchPubsubMessageLogSchema = exports.SavePubsubMessageLogSchema = exports.CreatePubsubMessageLogSchema = exports.indexSchemaPubsubMessageLog = exports.modelSchemaPubsubMessageLog = void 0;
7
+ const schema_builder_1 = require("../../schema/schema-builder");
8
+ const zod_extensions_1 = require("../../schema/zod-extensions");
9
+ const zod_1 = __importDefault(require("zod"));
10
+ const pubsub_message_log_entity_1 = require("./pubsub-message-log.entity");
11
+ exports.modelSchemaPubsubMessageLog = zod_1.default.object({
12
+ uuid: zod_1.default.uuidv7(),
13
+ direction: zod_1.default.enum(pubsub_message_log_entity_1.PubsubMessageDirection),
14
+ topic: zod_1.default.string().min(1, 'Tópico é obrigatório'),
15
+ originApi: zod_1.default.string().nullable().optional(),
16
+ subscription: zod_1.default.string().nullable().optional(),
17
+ messageId: zod_1.default.string().nullable().optional(),
18
+ orderingKey: zod_1.default.string().nullable().optional(),
19
+ handler: zod_1.default.string().nullable().optional(),
20
+ attributes: zod_1.default.record(zod_1.default.string(), zod_1.default.unknown()).nullable().optional(),
21
+ payload: zod_1.default.unknown().optional(),
22
+ payloadSizeBytes: zod_1.default.number().int().nullable().optional(),
23
+ contentType: zod_1.default.string().nullable().optional(),
24
+ publishTime: zod_extensions_1.zExt.dateTime().nullable().optional(),
25
+ deliveryAttempt: zod_1.default.number().int().nullable().optional(),
26
+ ackStatus: zod_1.default.enum(pubsub_message_log_entity_1.PubsubAckStatus).nullable().optional(),
27
+ correlationId: zod_1.default.string().nullable().optional(),
28
+ traceId: zod_1.default.string().nullable().optional(),
29
+ startedAt: zod_extensions_1.zExt.dateTime().optional(),
30
+ finishedAt: zod_extensions_1.zExt.dateTime().nullable().optional(),
31
+ durationMs: zod_1.default.number().int().nullable().optional(),
32
+ errorMessage: zod_1.default.string().nullable().optional(),
33
+ errorStack: zod_1.default.string().nullable().optional(),
34
+ });
35
+ exports.indexSchemaPubsubMessageLog = {
36
+ uuid: { type: schema_builder_1.FieldType.UUID },
37
+ direction: { type: schema_builder_1.FieldType.String, validator: zod_1.default.enum(pubsub_message_log_entity_1.PubsubMessageDirection) },
38
+ topic: { type: schema_builder_1.FieldType.String },
39
+ originApi: { type: schema_builder_1.FieldType.String },
40
+ subscription: { type: schema_builder_1.FieldType.String },
41
+ messageId: { type: schema_builder_1.FieldType.String },
42
+ handler: { type: schema_builder_1.FieldType.String },
43
+ ackStatus: { type: schema_builder_1.FieldType.String, validator: zod_1.default.enum(pubsub_message_log_entity_1.PubsubAckStatus) },
44
+ correlationId: { type: schema_builder_1.FieldType.String },
45
+ traceId: { type: schema_builder_1.FieldType.String },
46
+ startedAt: { type: schema_builder_1.FieldType.DateTime },
47
+ durationMs: { type: schema_builder_1.FieldType.Number },
48
+ errorMessage: { type: schema_builder_1.FieldType.TextArea },
49
+ };
50
+ const { createValidator, saveValidator, patchValidator, indexValidator } = schema_builder_1.SchemaBuilder.build({
51
+ modelSchema: exports.modelSchemaPubsubMessageLog,
52
+ indexSchema: exports.indexSchemaPubsubMessageLog,
53
+ });
54
+ exports.CreatePubsubMessageLogSchema = createValidator;
55
+ exports.SavePubsubMessageLogSchema = saveValidator;
56
+ exports.PatchPubsubMessageLogSchema = patchValidator;
57
+ exports.IndexPubsubMessageLogSchema = indexValidator;
@@ -0,0 +1,44 @@
1
+ import { DateTime } from 'luxon';
2
+ import { UuidEntity } from '../../schema/abstract.entity';
3
+ export declare class PubsubMessageLog extends UuidEntity {
4
+ /** Mensagem enviada ou recebida */
5
+ direction: PubsubMessageDirection;
6
+ topic: string;
7
+ /** API que publicou a mensagem (`from` do envelope) */
8
+ originApi: string | null;
9
+ /** NULL no publish */
10
+ subscription: string | null;
11
+ /** ID atribuído pelo broker (conhecido após o publish / no recebimento) */
12
+ messageId: string | null;
13
+ orderingKey: string | null;
14
+ /** Handler do consumer / função do publisher */
15
+ handler: string | null;
16
+ attributes: Record<string, unknown> | null;
17
+ payload: unknown;
18
+ payloadSizeBytes: number | null;
19
+ contentType: string | null;
20
+ /** Timestamp de publish do broker */
21
+ publishTime: DateTime | null;
22
+ /** 1 na primeira entrega, incrementa a cada reentrega */
23
+ deliveryAttempt: number | null;
24
+ ackStatus: PubsubAckStatus | null;
25
+ /** Requisição HTTP ou job que originou a mensagem */
26
+ correlationId: string | null;
27
+ traceId: string | null;
28
+ startedAt: DateTime;
29
+ finishedAt: DateTime | null;
30
+ durationMs: number | null;
31
+ errorMessage: string | null;
32
+ errorStack: string | null;
33
+ createdAt: DateTime;
34
+ }
35
+ export declare enum PubsubMessageDirection {
36
+ PUBLISH = "publish",
37
+ RECEIVE = "receive"
38
+ }
39
+ export declare enum PubsubAckStatus {
40
+ ACK = "ack",
41
+ NACK = "nack",
42
+ DEAD_LETTERED = "dead_lettered",
43
+ IGNORED = "ignored"
44
+ }
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PubsubAckStatus = exports.PubsubMessageDirection = exports.PubsubMessageLog = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const luxon_1 = require("luxon");
15
+ const abstract_entity_1 = require("../../schema/abstract.entity");
16
+ const luxon_2 = require("../../decorators/luxon");
17
+ let PubsubMessageLog = class PubsubMessageLog extends abstract_entity_1.UuidEntity {
18
+ /** Mensagem enviada ou recebida */
19
+ direction;
20
+ topic;
21
+ /** API que publicou a mensagem (`from` do envelope) */
22
+ originApi;
23
+ /** NULL no publish */
24
+ subscription;
25
+ /** ID atribuído pelo broker (conhecido após o publish / no recebimento) */
26
+ messageId;
27
+ orderingKey;
28
+ /** Handler do consumer / função do publisher */
29
+ handler;
30
+ attributes;
31
+ payload;
32
+ payloadSizeBytes;
33
+ contentType;
34
+ /** Timestamp de publish do broker */
35
+ publishTime;
36
+ /** 1 na primeira entrega, incrementa a cada reentrega */
37
+ deliveryAttempt;
38
+ ackStatus;
39
+ /** Requisição HTTP ou job que originou a mensagem */
40
+ correlationId;
41
+ traceId;
42
+ startedAt;
43
+ finishedAt;
44
+ durationMs;
45
+ errorMessage;
46
+ errorStack;
47
+ createdAt;
48
+ };
49
+ exports.PubsubMessageLog = PubsubMessageLog;
50
+ __decorate([
51
+ (0, typeorm_1.Column)({ type: 'varchar', length: 10 }),
52
+ __metadata("design:type", String)
53
+ ], PubsubMessageLog.prototype, "direction", void 0);
54
+ __decorate([
55
+ (0, typeorm_1.Column)('text'),
56
+ __metadata("design:type", String)
57
+ ], PubsubMessageLog.prototype, "topic", void 0);
58
+ __decorate([
59
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
60
+ __metadata("design:type", Object)
61
+ ], PubsubMessageLog.prototype, "originApi", void 0);
62
+ __decorate([
63
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
64
+ __metadata("design:type", Object)
65
+ ], PubsubMessageLog.prototype, "subscription", void 0);
66
+ __decorate([
67
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
68
+ __metadata("design:type", Object)
69
+ ], PubsubMessageLog.prototype, "messageId", void 0);
70
+ __decorate([
71
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
72
+ __metadata("design:type", Object)
73
+ ], PubsubMessageLog.prototype, "orderingKey", void 0);
74
+ __decorate([
75
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
76
+ __metadata("design:type", Object)
77
+ ], PubsubMessageLog.prototype, "handler", void 0);
78
+ __decorate([
79
+ (0, typeorm_1.Column)({ type: 'jsonb', nullable: true }),
80
+ __metadata("design:type", Object)
81
+ ], PubsubMessageLog.prototype, "attributes", void 0);
82
+ __decorate([
83
+ (0, typeorm_1.Column)({ type: 'jsonb', nullable: true }),
84
+ __metadata("design:type", Object)
85
+ ], PubsubMessageLog.prototype, "payload", void 0);
86
+ __decorate([
87
+ (0, typeorm_1.Column)({ type: 'integer', nullable: true }),
88
+ __metadata("design:type", Object)
89
+ ], PubsubMessageLog.prototype, "payloadSizeBytes", void 0);
90
+ __decorate([
91
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
92
+ __metadata("design:type", Object)
93
+ ], PubsubMessageLog.prototype, "contentType", void 0);
94
+ __decorate([
95
+ (0, luxon_2.DateTimeColumn)({ nullable: true }),
96
+ __metadata("design:type", Object)
97
+ ], PubsubMessageLog.prototype, "publishTime", void 0);
98
+ __decorate([
99
+ (0, typeorm_1.Column)({ type: 'integer', nullable: true }),
100
+ __metadata("design:type", Object)
101
+ ], PubsubMessageLog.prototype, "deliveryAttempt", void 0);
102
+ __decorate([
103
+ (0, typeorm_1.Column)({ type: 'varchar', length: 20, nullable: true }),
104
+ __metadata("design:type", Object)
105
+ ], PubsubMessageLog.prototype, "ackStatus", void 0);
106
+ __decorate([
107
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
108
+ __metadata("design:type", Object)
109
+ ], PubsubMessageLog.prototype, "correlationId", void 0);
110
+ __decorate([
111
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
112
+ __metadata("design:type", Object)
113
+ ], PubsubMessageLog.prototype, "traceId", void 0);
114
+ __decorate([
115
+ (0, luxon_2.DateTimeColumn)({ default: () => 'now()' }),
116
+ __metadata("design:type", luxon_1.DateTime)
117
+ ], PubsubMessageLog.prototype, "startedAt", void 0);
118
+ __decorate([
119
+ (0, luxon_2.DateTimeColumn)({ nullable: true }),
120
+ __metadata("design:type", Object)
121
+ ], PubsubMessageLog.prototype, "finishedAt", void 0);
122
+ __decorate([
123
+ (0, typeorm_1.Column)({ type: 'integer', nullable: true }),
124
+ __metadata("design:type", Object)
125
+ ], PubsubMessageLog.prototype, "durationMs", void 0);
126
+ __decorate([
127
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
128
+ __metadata("design:type", Object)
129
+ ], PubsubMessageLog.prototype, "errorMessage", void 0);
130
+ __decorate([
131
+ (0, typeorm_1.Column)({ type: 'text', nullable: true }),
132
+ __metadata("design:type", Object)
133
+ ], PubsubMessageLog.prototype, "errorStack", void 0);
134
+ __decorate([
135
+ (0, luxon_2.CreateDateTimeColumn)(),
136
+ __metadata("design:type", luxon_1.DateTime)
137
+ ], PubsubMessageLog.prototype, "createdAt", void 0);
138
+ exports.PubsubMessageLog = PubsubMessageLog = __decorate([
139
+ (0, typeorm_1.Entity)('pubsub_message_logs')
140
+ ], PubsubMessageLog);
141
+ var PubsubMessageDirection;
142
+ (function (PubsubMessageDirection) {
143
+ PubsubMessageDirection["PUBLISH"] = "publish";
144
+ PubsubMessageDirection["RECEIVE"] = "receive";
145
+ })(PubsubMessageDirection || (exports.PubsubMessageDirection = PubsubMessageDirection = {}));
146
+ var PubsubAckStatus;
147
+ (function (PubsubAckStatus) {
148
+ PubsubAckStatus["ACK"] = "ack";
149
+ PubsubAckStatus["NACK"] = "nack";
150
+ PubsubAckStatus["DEAD_LETTERED"] = "dead_lettered";
151
+ PubsubAckStatus["IGNORED"] = "ignored";
152
+ })(PubsubAckStatus || (exports.PubsubAckStatus = PubsubAckStatus = {}));
@@ -0,0 +1,2 @@
1
+ export declare class PubsubMessageLogModule {
2
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PubsubMessageLogModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const typeorm_1 = require("@nestjs/typeorm");
12
+ const monitoramento_constants_1 = require("../monitoramento.constants");
13
+ const pubsub_message_log_service_1 = require("./pubsub-message-log.service");
14
+ const pubsub_message_log_controller_1 = require("./pubsub-message-log.controller");
15
+ const pubsub_message_log_entity_1 = require("./pubsub-message-log.entity");
16
+ let PubsubMessageLogModule = class PubsubMessageLogModule {
17
+ };
18
+ exports.PubsubMessageLogModule = PubsubMessageLogModule;
19
+ exports.PubsubMessageLogModule = PubsubMessageLogModule = __decorate([
20
+ (0, common_1.Module)({
21
+ imports: [typeorm_1.TypeOrmModule.forFeature([pubsub_message_log_entity_1.PubsubMessageLog], monitoramento_constants_1.MONITORAMENTO_CONNECTION)],
22
+ controllers: [pubsub_message_log_controller_1.PubsubMessageLogController],
23
+ providers: [pubsub_message_log_service_1.PubsubMessageLogService],
24
+ exports: [pubsub_message_log_service_1.PubsubMessageLogService],
25
+ })
26
+ ], PubsubMessageLogModule);
@@ -0,0 +1,20 @@
1
+ import type { Message } from '@google-cloud/pubsub';
2
+ import { DeepPartial, Repository } from 'typeorm';
3
+ import { SchemaService } from '../../schema/schema.service';
4
+ import { CreatePubsubMessageLogDto, IndexPubsubMessageLogParamsDto, PatchPubsubMessageLogDto } from './pubsub-message-log.dto';
5
+ import { PubsubMessageLog } from './pubsub-message-log.entity';
6
+ export declare class PubsubMessageLogService extends SchemaService<PubsubMessageLog, CreatePubsubMessageLogDto, PatchPubsubMessageLogDto, IndexPubsubMessageLogParamsDto> {
7
+ private pubsubMessageLogRepository;
8
+ constructor(pubsubMessageLogRepository: Repository<PubsubMessageLog>);
9
+ /**
10
+ * Executa `run` registrando a mensagem. `run` recebe o log para completar o que só se sabe depois
11
+ * (ex.: `messageId` do publish, `ackStatus` do consumo). Duração e erro são preenchidos aqui; o erro é relançado.
12
+ * O save não é aguardado e falhas nele só são logadas, para o log nunca atrasar ou quebrar o fluxo da mensagem.
13
+ */
14
+ register<R>(data: DeepPartial<PubsubMessageLog> & Pick<PubsubMessageLog, 'direction' | 'topic'>, run: (log: PubsubMessageLog) => Promise<R>): Promise<R>;
15
+ /** Registra o consumo de `message`, preenchendo os dados que vêm do broker */
16
+ registerReceive<R>(message: Message, data: DeepPartial<PubsubMessageLog> & Pick<PubsubMessageLog, 'topic' | 'subscription'>, run: (log: PubsubMessageLog) => Promise<R>): Promise<R>;
17
+ /** Registra o publish de `payload`; o `messageId` devolvido por `publish` vai para o log */
18
+ registerPublish(payload: Buffer, data: DeepPartial<PubsubMessageLog> & Pick<PubsubMessageLog, 'topic'>, publish: (log: PubsubMessageLog) => Promise<string>): Promise<string>;
19
+ private parsePayload;
20
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PubsubMessageLogService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const typeorm_1 = require("@nestjs/typeorm");
18
+ const luxon_1 = require("luxon");
19
+ const typeorm_2 = require("typeorm");
20
+ const schema_service_1 = require("../../schema/schema.service");
21
+ const monitoramento_constants_1 = require("../monitoramento.constants");
22
+ const pubsub_message_log_dto_1 = require("./pubsub-message-log.dto");
23
+ const pubsub_message_log_entity_1 = require("./pubsub-message-log.entity");
24
+ let PubsubMessageLogService = class PubsubMessageLogService extends schema_service_1.SchemaService {
25
+ pubsubMessageLogRepository;
26
+ constructor(pubsubMessageLogRepository) {
27
+ super(pubsubMessageLogRepository, pubsub_message_log_dto_1.indexSchemaPubsubMessageLog);
28
+ this.pubsubMessageLogRepository = pubsubMessageLogRepository;
29
+ }
30
+ /**
31
+ * Executa `run` registrando a mensagem. `run` recebe o log para completar o que só se sabe depois
32
+ * (ex.: `messageId` do publish, `ackStatus` do consumo). Duração e erro são preenchidos aqui; o erro é relançado.
33
+ * O save não é aguardado e falhas nele só são logadas, para o log nunca atrasar ou quebrar o fluxo da mensagem.
34
+ */
35
+ async register(data, run) {
36
+ const startedAt = luxon_1.DateTime.now();
37
+ const log = this.pubsubMessageLogRepository.create({ ...data, startedAt });
38
+ try {
39
+ return await run(log);
40
+ }
41
+ catch (error) {
42
+ log.errorMessage = error instanceof Error ? error.message : String(error);
43
+ log.errorStack = error instanceof Error ? (error.stack ?? null) : null;
44
+ // Falha no consumo sem ack/nack explícito: a mensagem volta para reentrega
45
+ if (log.direction === pubsub_message_log_entity_1.PubsubMessageDirection.RECEIVE)
46
+ log.ackStatus ??= pubsub_message_log_entity_1.PubsubAckStatus.NACK;
47
+ throw error;
48
+ }
49
+ finally {
50
+ // Mensagem ignorada (ex.: vinda da própria API) não gera log
51
+ if (log.ackStatus !== pubsub_message_log_entity_1.PubsubAckStatus.IGNORED) {
52
+ const finishedAt = luxon_1.DateTime.now();
53
+ log.finishedAt = finishedAt;
54
+ log.durationMs = Math.round(finishedAt.diff(startedAt).as('milliseconds'));
55
+ this.pubsubMessageLogRepository.save(log).catch((error) => {
56
+ this.logger.error('Error saving Pub/Sub message log:', error);
57
+ });
58
+ }
59
+ }
60
+ }
61
+ /** Registra o consumo de `message`, preenchendo os dados que vêm do broker */
62
+ registerReceive(message, data, run) {
63
+ return this.register({
64
+ messageId: message.id,
65
+ orderingKey: message.orderingKey || null,
66
+ attributes: Object.keys(message.attributes ?? {}).length ? message.attributes : null,
67
+ ...this.parsePayload(message.data),
68
+ publishTime: message.publishTime ? luxon_1.DateTime.fromJSDate(message.publishTime) : null,
69
+ // 0 quando a subscription não tem dead-letter policy (o broker não conta as entregas)
70
+ deliveryAttempt: message.deliveryAttempt || null,
71
+ ...data,
72
+ direction: pubsub_message_log_entity_1.PubsubMessageDirection.RECEIVE,
73
+ }, run);
74
+ }
75
+ /** Registra o publish de `payload`; o `messageId` devolvido por `publish` vai para o log */
76
+ registerPublish(payload, data, publish) {
77
+ return this.register({ ...this.parsePayload(payload), ...data, subscription: null, direction: pubsub_message_log_entity_1.PubsubMessageDirection.PUBLISH }, async (log) => {
78
+ const messageId = await publish(log);
79
+ log.messageId = messageId;
80
+ return messageId;
81
+ });
82
+ }
83
+ parsePayload(buffer) {
84
+ const text = buffer.toString();
85
+ try {
86
+ return { payload: JSON.parse(text), payloadSizeBytes: buffer.length };
87
+ }
88
+ catch {
89
+ // jsonb aceita string JSON
90
+ return { payload: text, payloadSizeBytes: buffer.length };
91
+ }
92
+ }
93
+ };
94
+ exports.PubsubMessageLogService = PubsubMessageLogService;
95
+ exports.PubsubMessageLogService = PubsubMessageLogService = __decorate([
96
+ (0, common_1.Injectable)(),
97
+ __param(0, (0, typeorm_1.InjectRepository)(pubsub_message_log_entity_1.PubsubMessageLog, monitoramento_constants_1.MONITORAMENTO_CONNECTION)),
98
+ __metadata("design:paramtypes", [typeorm_2.Repository])
99
+ ], PubsubMessageLogService);
@@ -0,0 +1,9 @@
1
+ import { PubsubSelfCheckService } from './pubsub-self-check.service';
2
+ export declare class PubsubSelfCheckController {
3
+ private readonly pubsubSelfCheckService;
4
+ constructor(pubsubSelfCheckService: PubsubSelfCheckService);
5
+ /** APIs que não responderam ao ping há 5 minutos ou mais */
6
+ getUnhealthyApis(): Promise<import("./pubsub-self-check.service").IPubsubSelfCheckUnhealthyApi[]>;
7
+ /** Todas as APIs da lista, com o ping pendente e o último PONG de cada uma */
8
+ all(): Promise<import("./pubsub-self-check.service").IPubsubSelfCheckApiStatus[]>;
9
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PubsubSelfCheckController = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const pubsub_self_check_service_1 = require("./pubsub-self-check.service");
15
+ let PubsubSelfCheckController = class PubsubSelfCheckController {
16
+ pubsubSelfCheckService;
17
+ constructor(pubsubSelfCheckService) {
18
+ this.pubsubSelfCheckService = pubsubSelfCheckService;
19
+ }
20
+ /** APIs que não responderam ao ping há 5 minutos ou mais */
21
+ getUnhealthyApis() {
22
+ return this.pubsubSelfCheckService.getUnhealthyApis();
23
+ }
24
+ /** Todas as APIs da lista, com o ping pendente e o último PONG de cada uma */
25
+ all() {
26
+ return this.pubsubSelfCheckService.getAll();
27
+ }
28
+ };
29
+ exports.PubsubSelfCheckController = PubsubSelfCheckController;
30
+ __decorate([
31
+ (0, common_1.Get)('unhealthy'),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", []),
34
+ __metadata("design:returntype", void 0)
35
+ ], PubsubSelfCheckController.prototype, "getUnhealthyApis", null);
36
+ __decorate([
37
+ (0, common_1.Get)(),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", []),
40
+ __metadata("design:returntype", void 0)
41
+ ], PubsubSelfCheckController.prototype, "all", null);
42
+ exports.PubsubSelfCheckController = PubsubSelfCheckController = __decorate([
43
+ (0, common_1.Controller)('monitoramento/pubsub-self-check'),
44
+ __metadata("design:paramtypes", [pubsub_self_check_service_1.PubsubSelfCheckService])
45
+ ], PubsubSelfCheckController);
@@ -0,0 +1,11 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { IPubsubSelfCheckModuleAsyncOptions, IPubsubSelfCheckOptions } from './pubsub-self-check.options';
3
+ /**
4
+ * Self-check do Pub/Sub entre APIs. Independe do banco de monitoramento; usa os providers globais `PubSub`,
5
+ * `ContextLogger`, `PUBSUB_API_NAME` e `REDIS_CLIENT` (estado comum às réplicas) e precisa do `ScheduleModule.forRoot()`
6
+ * na app para o cron rodar. Registra o próprio tópico e subscription na subida.
7
+ */
8
+ export declare class PubsubSelfCheckModule {
9
+ static forRoot(options: IPubsubSelfCheckOptions): DynamicModule;
10
+ static forRootAsync(options: IPubsubSelfCheckModuleAsyncOptions): DynamicModule;
11
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var PubsubSelfCheckModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PubsubSelfCheckModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const pubsub_self_check_options_1 = require("./pubsub-self-check.options");
13
+ const pubsub_self_check_service_1 = require("./pubsub-self-check.service");
14
+ const pubsub_self_check_controller_1 = require("./pubsub-self-check.controller");
15
+ /**
16
+ * Self-check do Pub/Sub entre APIs. Independe do banco de monitoramento; usa os providers globais `PubSub`,
17
+ * `ContextLogger`, `PUBSUB_API_NAME` e `REDIS_CLIENT` (estado comum às réplicas) e precisa do `ScheduleModule.forRoot()`
18
+ * na app para o cron rodar. Registra o próprio tópico e subscription na subida.
19
+ */
20
+ let PubsubSelfCheckModule = PubsubSelfCheckModule_1 = class PubsubSelfCheckModule {
21
+ static forRoot(options) {
22
+ return this.forRootAsync({ useFactory: () => options });
23
+ }
24
+ static forRootAsync(options) {
25
+ return {
26
+ module: PubsubSelfCheckModule_1,
27
+ // O provider de opções usa `inject`, então os módulos que fornecem essas dependências precisam estar aqui
28
+ imports: options.imports ?? [],
29
+ controllers: [pubsub_self_check_controller_1.PubsubSelfCheckController],
30
+ providers: [
31
+ { provide: pubsub_self_check_options_1.PUBSUB_SELF_CHECK_OPTIONS, inject: options.inject ?? [], useFactory: options.useFactory },
32
+ pubsub_self_check_service_1.PubsubSelfCheckService,
33
+ ],
34
+ exports: [pubsub_self_check_service_1.PubsubSelfCheckService],
35
+ };
36
+ }
37
+ };
38
+ exports.PubsubSelfCheckModule = PubsubSelfCheckModule;
39
+ exports.PubsubSelfCheckModule = PubsubSelfCheckModule = PubsubSelfCheckModule_1 = __decorate([
40
+ (0, common_1.Module)({})
41
+ ], PubsubSelfCheckModule);
@@ -0,0 +1,10 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const PUBSUB_SELF_CHECK_OPTIONS = "PUBSUB_SELF_CHECK_OPTIONS";
3
+ export interface IPubsubSelfCheckOptions {
4
+ /** Lista de APIs que serão verificadas o health do pubsub */
5
+ lstApiPubSubCheck: string[];
6
+ }
7
+ export interface IPubsubSelfCheckModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
8
+ inject?: any[];
9
+ useFactory: (...args: any[]) => IPubsubSelfCheckOptions | Promise<IPubsubSelfCheckOptions>;
10
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PUBSUB_SELF_CHECK_OPTIONS = void 0;
4
+ exports.PUBSUB_SELF_CHECK_OPTIONS = 'PUBSUB_SELF_CHECK_OPTIONS';
@@ -0,0 +1,68 @@
1
+ import { OnApplicationBootstrap } from '@nestjs/common';
2
+ import { DateTime } from 'luxon';
3
+ import z from 'zod';
4
+ import { PubSubDynamicTopicService } from '../../modules/pubsub/pubsub-dynamic-topic.service';
5
+ import { PubSubSave } from '../../modules/pubsub/pubsub.methods';
6
+ export interface IPubsubSelfCheckUnhealthyApi {
7
+ apiName: string;
8
+ /** Horário do primeiro ping que ficou sem resposta */
9
+ pendingSince: DateTime;
10
+ }
11
+ export interface IPubsubSelfCheckLastPong {
12
+ /** Envio do PING que o PONG respondeu */
13
+ pingSentAt: DateTime;
14
+ /** Envio do PONG pela API alvo */
15
+ pongSentAt: DateTime;
16
+ /** Recebimento do PONG por esta API */
17
+ receivedAt: DateTime;
18
+ /** Tempo total do PING até o recebimento do PONG */
19
+ roundTripMs: number;
20
+ }
21
+ export interface IPubsubSelfCheckApiStatus {
22
+ apiName: string;
23
+ /** Horário do primeiro ping sem resposta; null se não há ping pendente */
24
+ pendingSince: DateTime | null;
25
+ /** Último PONG recebido da API; null se ainda não respondeu */
26
+ lastPong: IPubsubSelfCheckLastPong | null;
27
+ }
28
+ export declare class PubsubSelfCheckService extends PubSubDynamicTopicService implements PubSubSave<PubSubSelfCheckDto>, OnApplicationBootstrap {
29
+ constructor();
30
+ private selfCheckOptions;
31
+ private pubsubApiName;
32
+ private pubSubClient;
33
+ private redis;
34
+ /** Só envia pings depois que o tópico e a subscription existem */
35
+ private ready;
36
+ /** Hash com os pings sem resposta (campo: API alvo; valor: ISO do primeiro ping sem resposta), comum às réplicas */
37
+ private get pendingKey();
38
+ /** Hash com o último PONG de cada API (campo: API alvo; valor: JSON com os horários), comum às réplicas */
39
+ private get lastPongKey();
40
+ private get lockKey();
41
+ /** Registra o próprio tópico e subscription, sem depender da lista de services de Pub/Sub da app */
42
+ onApplicationBootstrap(): Promise<void>;
43
+ /** Envia um ping para todas as APIs que estão na lista de monitoramento */
44
+ check(): Promise<void>;
45
+ /** Trata a mensagem de self-check */
46
+ onSave(message: PubSubSelfCheckDto): Promise<void>;
47
+ /** Retorna as APIs da lista que estão sem resposta há 5 minutos ou mais */
48
+ getUnhealthyApis(): Promise<IPubsubSelfCheckUnhealthyApi[]>;
49
+ /** Retorna o estado de todas as APIs da lista, com o último PONG de cada uma */
50
+ getAll(): Promise<IPubsubSelfCheckApiStatus[]>;
51
+ private parseLastPong;
52
+ }
53
+ declare enum PubSubSelfCheckType {
54
+ PING = "PING",
55
+ PONG = "PONG"
56
+ }
57
+ declare const PubSubSelfCheckValidator: z.ZodDiscriminatedUnion<[z.ZodObject<{
58
+ type: z.ZodLiteral<PubSubSelfCheckType.PING>;
59
+ apiName: z.ZodString;
60
+ sentAt: z.ZodUnion<readonly [z.ZodCustom<DateTime<boolean>, DateTime<boolean>>, z.ZodPipe<z.ZodISODateTime, z.ZodTransform<DateTime<true> | DateTime<false>, string>>]>;
61
+ }, z.core.$strip>, z.ZodObject<{
62
+ type: z.ZodLiteral<PubSubSelfCheckType.PONG>;
63
+ apiName: z.ZodString;
64
+ sentAt: z.ZodUnion<readonly [z.ZodCustom<DateTime<boolean>, DateTime<boolean>>, z.ZodPipe<z.ZodISODateTime, z.ZodTransform<DateTime<true> | DateTime<false>, string>>]>;
65
+ pingSentAt: z.ZodUnion<readonly [z.ZodCustom<DateTime<boolean>, DateTime<boolean>>, z.ZodPipe<z.ZodISODateTime, z.ZodTransform<DateTime<true> | DateTime<false>, string>>]>;
66
+ }, z.core.$strip>], "type">;
67
+ type PubSubSelfCheckDto = z.infer<typeof PubSubSelfCheckValidator>;
68
+ export {};