@cargolift-cdi/lib-repositories 0.0.2

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 (23) hide show
  1. package/LICENSE +9 -0
  2. package/dist/integration/integration-agent-repository.service.d.ts +10 -0
  3. package/dist/integration/integration-agent-repository.service.d.ts.map +1 -0
  4. package/dist/integration/integration-agent-repository.service.js +34 -0
  5. package/dist/integration/integration-credential-repository.service.d.ts +8 -0
  6. package/dist/integration/integration-credential-repository.service.d.ts.map +1 -0
  7. package/dist/integration/integration-credential-repository.service.js +26 -0
  8. package/dist/integration/integration-endpoint-repository.service.d.ts +10 -0
  9. package/dist/integration/integration-endpoint-repository.service.d.ts.map +1 -0
  10. package/dist/integration/integration-endpoint-repository.service.js +60 -0
  11. package/dist/integration/integration-entity-repository.service.d.ts +10 -0
  12. package/dist/integration/integration-entity-repository.service.d.ts.map +1 -0
  13. package/dist/integration/integration-entity-repository.service.js +34 -0
  14. package/dist/integration/integration-inbound-repository.service.d.ts +9 -0
  15. package/dist/integration/integration-inbound-repository.service.d.ts.map +1 -0
  16. package/dist/integration/integration-inbound-repository.service.js +67 -0
  17. package/dist/integration/integration-outbound-repository.service.d.ts +9 -0
  18. package/dist/integration/integration-outbound-repository.service.d.ts.map +1 -0
  19. package/dist/integration/integration-outbound-repository.service.js +81 -0
  20. package/dist/log/log-integration-inbound.service.d.ts +20 -0
  21. package/dist/log/log-integration-inbound.service.d.ts.map +1 -0
  22. package/dist/log/log-integration-inbound.service.js +57 -0
  23. package/package.json +45 -0
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Licença MIT
2
+
3
+ Copyright (c) 2025 Cargolift
4
+
5
+ A permissão é concedida, gratuitamente, a qualquer pessoa que obtenha uma cópia deste software e dos arquivos de documentação associados (o "Software"), para lidar com o Software sem restrições, incluindo, sem limitação, os direitos de usar, copiar, modificar, mesclar, publicar, distribuir, sublicenciar e/ou vender cópias do Software, e permitir que pessoas a quem o Software é fornecido o façam, sujeito às seguintes condições:
6
+
7
+ O aviso de copyright acima e este aviso de permissão devem ser incluídos em todas as cópias ou partes substanciais do Software.
8
+
9
+ O SOFTWARE É FORNECIDO "NO ESTADO EM QUE SE ENCONTRA", SEM GARANTIA DE QUALQUER TIPO, EXPRESSA OU IMPLÍCITA, INCLUINDO, MAS NÃO SE LIMITANDO ÀS GARANTIAS DE COMERCIALIZAÇÃO, ADEQUAÇÃO A UM DETERMINADO FIM E NÃO VIOLAÇÃO. EM NENHUMA HIPÓTESE OS AUTORES OU DETENTORES DOS DIREITOS AUTORAIS SERÃO RESPONSÁVEIS POR QUALQUER REIVINDICAÇÃO, DANO OU OUTRA RESPONSABILIDADE, SEJA EM UMA AÇÃO DE CONTRATO, DELITO OU DE OUTRA FORMA, DECORRENTE DE, FORA DE OU EM CONEXÃO COM O SOFTWARE OU O USO OU OUTRAS NEGOCIAÇÕES NO SOFTWARE.
@@ -0,0 +1,10 @@
1
+ import { Repository } from "typeorm";
2
+ import { IntegrationAgent } from "@cargolift-cdi/types";
3
+ export declare class AgentRepositoryService {
4
+ private readonly repo;
5
+ constructor(repo: Repository<IntegrationAgent>);
6
+ get(agent: string): Promise<IntegrationAgent | null>;
7
+ getAllActive(): Promise<IntegrationAgent[]>;
8
+ getByApiClientId(apiClientId: string): Promise<IntegrationAgent | null>;
9
+ }
10
+ //# sourceMappingURL=integration-agent-repository.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-agent-repository.service.d.ts","sourceRoot":"","sources":["../../src/integration/integration-agent-repository.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,qBACa,sBAAsB;IAG/B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;IAG/C,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAKpD,YAAY,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAK3C,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;CAG9E"}
@@ -0,0 +1,34 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Injectable } from "@nestjs/common";
11
+ import { InjectRepository } from "@nestjs/typeorm";
12
+ import { IntegrationAgent } from "@cargolift-cdi/types";
13
+ let AgentRepositoryService = class AgentRepositoryService {
14
+ repo;
15
+ constructor(repo) {
16
+ this.repo = repo;
17
+ }
18
+ async get(agent) {
19
+ return await this.repo.findOne({ where: { agent, active: true } });
20
+ }
21
+ // Busca todos os entidades ativos
22
+ async getAllActive() {
23
+ return await this.repo.find({ where: { active: true } });
24
+ }
25
+ // Busca a entidade com base no clientId do KeyCloak
26
+ async getByApiClientId(apiClientId) {
27
+ return await this.repo.findOne({ where: { apiClientId, active: true } });
28
+ }
29
+ };
30
+ AgentRepositoryService = __decorate([
31
+ Injectable(),
32
+ __param(0, InjectRepository(IntegrationAgent))
33
+ ], AgentRepositoryService);
34
+ export { AgentRepositoryService };
@@ -0,0 +1,8 @@
1
+ import { IntegrationCredential } from '@cargolift-cdi/types';
2
+ import { Repository } from 'typeorm';
3
+ export declare class CredentialRepositoryService {
4
+ private readonly repo;
5
+ constructor(repo: Repository<IntegrationCredential>);
6
+ find(credentialId: string): Promise<IntegrationCredential | null>;
7
+ }
8
+ //# sourceMappingURL=integration-credential-repository.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-credential-repository.service.d.ts","sourceRoot":"","sources":["../../src/integration/integration-credential-repository.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,qBACa,2BAA2B;IAGpC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU,CAAC,qBAAqB,CAAC;IAGpD,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;CAGxE"}
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { IntegrationCredential } from '@cargolift-cdi/types';
11
+ import { Injectable } from '@nestjs/common';
12
+ import { InjectRepository } from '@nestjs/typeorm';
13
+ let CredentialRepositoryService = class CredentialRepositoryService {
14
+ repo;
15
+ constructor(repo) {
16
+ this.repo = repo;
17
+ }
18
+ async find(credentialId) {
19
+ return await this.repo.findOne({ where: { id: credentialId, active: true } });
20
+ }
21
+ };
22
+ CredentialRepositoryService = __decorate([
23
+ Injectable(),
24
+ __param(0, InjectRepository(IntegrationCredential))
25
+ ], CredentialRepositoryService);
26
+ export { CredentialRepositoryService };
@@ -0,0 +1,10 @@
1
+ import { Repository } from 'typeorm';
2
+ import { IntegrationEndpoint, IntegrationCredential } from '@cargolift-cdi/types';
3
+ export declare class EndpointRepositoryService {
4
+ private readonly repo;
5
+ private readonly repoCredential;
6
+ constructor(repo: Repository<IntegrationEndpoint>, repoCredential: Repository<IntegrationCredential>);
7
+ find(agent: string, entity: string, action: string): Promise<IntegrationEndpoint | null>;
8
+ getCredential(endpoint: IntegrationEndpoint): Promise<IntegrationCredential | null>;
9
+ }
10
+ //# sourceMappingURL=integration-endpoint-repository.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-endpoint-repository.service.d.ts","sourceRoot":"","sources":["../../src/integration/integration-endpoint-repository.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElF,qBACa,yBAAyB;IAGlC,OAAO,CAAC,QAAQ,CAAC,IAAI;IAErB,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAFd,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAErC,cAAc,EAAE,UAAU,CAAC,qBAAqB,CAAC;IAG9D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAqCxF,aAAa,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;CAI1F"}
@@ -0,0 +1,60 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Injectable } from '@nestjs/common';
11
+ import { InjectRepository } from '@nestjs/typeorm';
12
+ import { IntegrationEndpoint, IntegrationCredential } from '@cargolift-cdi/types';
13
+ let EndpointRepositoryService = class EndpointRepositoryService {
14
+ repo;
15
+ repoCredential;
16
+ constructor(repo, repoCredential) {
17
+ this.repo = repo;
18
+ this.repoCredential = repoCredential;
19
+ }
20
+ async find(agent, entity, action) {
21
+ const qb = this.repo
22
+ .createQueryBuilder('integration_endpoint')
23
+ .where('integration_endpoint.agent = :agent', { agent })
24
+ .andWhere('integration_endpoint.entity = :entity', { entity })
25
+ .andWhere('integration_endpoint.active = :active', { active: true })
26
+ .andWhere(`(
27
+ integration_endpoint.action = 'all' OR
28
+ integration_endpoint.action = :action OR
29
+ integration_endpoint.action LIKE :actionListPrefix OR
30
+ integration_endpoint.action LIKE :actionListInfix OR
31
+ integration_endpoint.action LIKE :actionListSuffix
32
+ )`, {
33
+ action,
34
+ actionListPrefix: `${action},%`,
35
+ actionListInfix: `%,${action},%`,
36
+ actionListSuffix: `%,${action}`,
37
+ })
38
+ .orderBy(`CASE
39
+ WHEN integration_endpoint.action = :action THEN 1
40
+ WHEN integration_endpoint.action LIKE :actionListPrefix OR
41
+ integration_endpoint.action LIKE :actionListInfix OR
42
+ integration_endpoint.action LIKE :actionListSuffix THEN 2
43
+ WHEN integration_endpoint.action = 'all' THEN 3
44
+ ELSE 4
45
+ END`, 'ASC')
46
+ .addOrderBy('integration_endpoint.version', 'DESC');
47
+ return await qb.getOne();
48
+ }
49
+ async getCredential(endpoint) {
50
+ if (!endpoint?.credentialId)
51
+ return null;
52
+ return await this.repoCredential.findOne({ where: { id: endpoint.credentialId, active: true } });
53
+ }
54
+ };
55
+ EndpointRepositoryService = __decorate([
56
+ Injectable(),
57
+ __param(0, InjectRepository(IntegrationEndpoint)),
58
+ __param(1, InjectRepository(IntegrationCredential))
59
+ ], EndpointRepositoryService);
60
+ export { EndpointRepositoryService };
@@ -0,0 +1,10 @@
1
+ import { Repository } from "typeorm";
2
+ import { IntegrationEntity } from "@cargolift-cdi/types";
3
+ export declare class EntityRepositoryService {
4
+ private readonly repo;
5
+ constructor(repo: Repository<IntegrationEntity>);
6
+ getFirstActive(entity: string): Promise<IntegrationEntity | null>;
7
+ getAllActive(): Promise<IntegrationEntity[]>;
8
+ getAllActiveByRoutingMode(routingMode: IntegrationEntity["routingMode"]): Promise<IntegrationEntity[]>;
9
+ }
10
+ //# sourceMappingURL=integration-entity-repository.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-entity-repository.service.d.ts","sourceRoot":"","sources":["../../src/integration/integration-entity-repository.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,qBACa,uBAAuB;IAGhC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU,CAAC,iBAAiB,CAAC;IAGhD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAKjE,YAAY,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAK5C,yBAAyB,CAAC,WAAW,EAAE,iBAAiB,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;CAG7G"}
@@ -0,0 +1,34 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Injectable } from "@nestjs/common";
11
+ import { InjectRepository } from "@nestjs/typeorm";
12
+ import { IntegrationEntity } from "@cargolift-cdi/types";
13
+ let EntityRepositoryService = class EntityRepositoryService {
14
+ repo;
15
+ constructor(repo) {
16
+ this.repo = repo;
17
+ }
18
+ async getFirstActive(entity) {
19
+ return await this.repo.findOne({ where: { entity, active: true }, order: { version: "DESC" } });
20
+ }
21
+ // Busca todos os entityos ativos
22
+ async getAllActive() {
23
+ return await this.repo.find({ where: { active: true } });
24
+ }
25
+ // Busca todos os entityos ativos
26
+ async getAllActiveByRoutingMode(routingMode) {
27
+ return await this.repo.find({ where: { active: true, routingMode } });
28
+ }
29
+ };
30
+ EntityRepositoryService = __decorate([
31
+ Injectable(),
32
+ __param(0, InjectRepository(IntegrationEntity))
33
+ ], EntityRepositoryService);
34
+ export { EntityRepositoryService };
@@ -0,0 +1,9 @@
1
+ import { Repository } from "typeorm";
2
+ import { IntegrationInbound } from "@cargolift-cdi/types";
3
+ export declare class InboundRepositoryService {
4
+ private readonly repo;
5
+ constructor(repo: Repository<IntegrationInbound>);
6
+ get(agent: string, entity: string, method: string): Promise<IntegrationInbound[]>;
7
+ getFirstActive(agent: string, entity: string, method: string): Promise<IntegrationInbound | null>;
8
+ }
9
+ //# sourceMappingURL=integration-inbound-repository.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-inbound-repository.service.d.ts","sourceRoot":"","sources":["../../src/integration/integration-inbound-repository.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBACa,wBAAwB;IAGjC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU,CAAC,kBAAkB,CAAC;IAGjD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAmDjF,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;CAKxG"}
@@ -0,0 +1,67 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Injectable } from "@nestjs/common";
11
+ import { InjectRepository } from "@nestjs/typeorm";
12
+ import { IntegrationInbound } from "@cargolift-cdi/types";
13
+ let InboundRepositoryService = class InboundRepositoryService {
14
+ repo;
15
+ constructor(repo) {
16
+ this.repo = repo;
17
+ }
18
+ async get(agent, entity, method) {
19
+ const qb = this.repo
20
+ .createQueryBuilder("integration_inbound")
21
+ .where("integration_inbound.agent = :agent", { agent })
22
+ .andWhere("integration_inbound.entity = :entity", { entity })
23
+ .andWhere("integration_inbound.active = :active", { active: true })
24
+ .andWhere(`(
25
+ UPPER(integration_inbound.method) = 'ALL' OR
26
+ UPPER(integration_inbound.method) = :method OR
27
+ UPPER(integration_inbound.method) LIKE :methodListPrefix OR
28
+ UPPER(integration_inbound.method) LIKE :methodListInfix OR
29
+ UPPER(integration_inbound.method) LIKE :methodListSuffix
30
+ )`, {
31
+ method: method.toUpperCase(),
32
+ methodListPrefix: `${method.toUpperCase()},%`,
33
+ methodListInfix: `%,${method.toUpperCase()},%`,
34
+ methodListSuffix: `%,${method.toUpperCase()}`,
35
+ });
36
+ const rows = await qb
37
+ .orderBy(`CASE
38
+ WHEN UPPER(integration_inbound.method) = :method THEN 1
39
+ WHEN UPPER(integration_inbound.method) LIKE :methodListPrefix OR
40
+ UPPER(integration_inbound.method) LIKE :methodListInfix OR
41
+ UPPER(integration_inbound.method) LIKE :methodListSuffix THEN 2
42
+ WHEN UPPER(integration_inbound.method) = 'ALL' THEN 3
43
+ ELSE 4
44
+ END`, "ASC")
45
+ .addOrderBy("integration_inbound.agent", "ASC")
46
+ .addOrderBy("integration_inbound.entity", "ASC")
47
+ .addOrderBy("integration_inbound.version", "DESC")
48
+ .getMany();
49
+ const resultMap = new Map();
50
+ for (const row of rows) {
51
+ const key = `${row.agent}::${row.entity}::${row.method.toUpperCase()}`;
52
+ if (!resultMap.has(key)) {
53
+ resultMap.set(key, row);
54
+ }
55
+ }
56
+ return Array.from(resultMap.values());
57
+ }
58
+ async getFirstActive(agent, entity, method) {
59
+ const records = await this.get(agent, entity, method);
60
+ return records.length > 0 ? records[0] : null;
61
+ }
62
+ };
63
+ InboundRepositoryService = __decorate([
64
+ Injectable(),
65
+ __param(0, InjectRepository(IntegrationInbound))
66
+ ], InboundRepositoryService);
67
+ export { InboundRepositoryService };
@@ -0,0 +1,9 @@
1
+ import { Repository } from "typeorm";
2
+ import { IntegrationOutbound } from "@cargolift-cdi/types";
3
+ export declare class OutboundRepositoryService {
4
+ private readonly repo;
5
+ constructor(repo: Repository<IntegrationOutbound>);
6
+ getRoutes(agent: string, entity: string, action: string): Promise<IntegrationOutbound[]>;
7
+ find(agent: string, entity: string, action: string): Promise<IntegrationOutbound | null>;
8
+ }
9
+ //# sourceMappingURL=integration-outbound-repository.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-outbound-repository.service.d.ts","sourceRoot":"","sources":["../../src/integration/integration-outbound-repository.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,qBACa,yBAAyB;IAGlC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC;IAGlD,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAqCxF,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;CAoC/F"}
@@ -0,0 +1,81 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Injectable } from "@nestjs/common";
11
+ import { InjectRepository } from "@nestjs/typeorm";
12
+ import { IntegrationOutbound } from "@cargolift-cdi/types";
13
+ let OutboundRepositoryService = class OutboundRepositoryService {
14
+ repo;
15
+ constructor(repo) {
16
+ this.repo = repo;
17
+ }
18
+ async getRoutes(agent, entity, action) {
19
+ const qb = this.repo
20
+ .createQueryBuilder("integration_outbound")
21
+ .where("integration_outbound.agent = :agent", { agent })
22
+ .andWhere("integration_outbound.entity = :entity", { entity })
23
+ .andWhere("integration_outbound.active = :active", { active: true })
24
+ .andWhere(`(
25
+ integration_outbound.action = 'all' OR
26
+ integration_outbound.action = :action OR
27
+ integration_outbound.action LIKE :actionListPrefix OR
28
+ integration_outbound.action LIKE :actionListInfix OR
29
+ integration_outbound.action LIKE :actionListSuffix
30
+ )`, {
31
+ action,
32
+ actionListPrefix: `${action},%`,
33
+ actionListInfix: `%,${action},%`,
34
+ actionListSuffix: `%,${action}`,
35
+ })
36
+ .orderBy(`CASE
37
+ WHEN integration_outbound.action = :action THEN 1
38
+ WHEN integration_outbound.action LIKE :actionListPrefix OR
39
+ integration_outbound.action LIKE :actionListInfix OR
40
+ integration_outbound.action LIKE :actionListSuffix THEN 2
41
+ WHEN integration_outbound.action = 'all' THEN 3
42
+ ELSE 4
43
+ END`, "ASC")
44
+ .addOrderBy("integration_outbound.version", "DESC");
45
+ return qb.getMany();
46
+ }
47
+ async find(agent, entity, action) {
48
+ const qb = this.repo
49
+ .createQueryBuilder("integration_outbound")
50
+ .where("integration_outbound.agent = :agent", { agent })
51
+ .andWhere("integration_outbound.entity = :entity", { entity })
52
+ .andWhere("integration_outbound.active = :active", { active: true })
53
+ .andWhere(`(
54
+ integration_outbound.action = 'all' OR
55
+ integration_outbound.action = :action OR
56
+ integration_outbound.action LIKE :actionListPrefix OR
57
+ integration_outbound.action LIKE :actionListInfix OR
58
+ integration_outbound.action LIKE :actionListSuffix
59
+ )`, {
60
+ action,
61
+ actionListPrefix: `${action},%`,
62
+ actionListInfix: `%,${action},%`,
63
+ actionListSuffix: `%,${action}`,
64
+ })
65
+ .orderBy(`CASE
66
+ WHEN integration_outbound.action = :action THEN 1
67
+ WHEN integration_outbound.action LIKE :actionListPrefix OR
68
+ integration_outbound.action LIKE :actionListInfix OR
69
+ integration_outbound.action LIKE :actionListSuffix THEN 2
70
+ WHEN integration_outbound.action = 'all' THEN 3
71
+ ELSE 4
72
+ END`, "ASC")
73
+ .addOrderBy("integration_outbound.version", "DESC");
74
+ return qb.getOne();
75
+ }
76
+ };
77
+ OutboundRepositoryService = __decorate([
78
+ Injectable(),
79
+ __param(0, InjectRepository(IntegrationOutbound))
80
+ ], OutboundRepositoryService);
81
+ export { OutboundRepositoryService };
@@ -0,0 +1,20 @@
1
+ import { Repository } from 'typeorm';
2
+ import { LogIntegrationInbound } from '@cargolift-cdi/types';
3
+ /**
4
+ * Repositório de log de integração de entrada (inbound).
5
+ * Responsável por criar/atualizar registros de latência associados a um id.
6
+ * Possibilidade de reprocessamento e auditoria.
7
+ */
8
+ export declare class LogInboundRepositoryService {
9
+ private readonly repo;
10
+ constructor(repo: Repository<LogIntegrationInbound>);
11
+ /**
12
+ * Cria um novo registro de latência.
13
+ * @param id
14
+ * @param correlation_id
15
+ * @param timestamp_start
16
+ * @returns
17
+ */
18
+ register(correlationId: string, data?: Partial<LogIntegrationInbound>): Promise<LogIntegrationInbound | null>;
19
+ }
20
+ //# sourceMappingURL=log-integration-inbound.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-integration-inbound.service.d.ts","sourceRoot":"","sources":["../../src/log/log-integration-inbound.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAChF;;;;GAIG;AACH,qBACa,2BAA2B;IAGpC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU,CAAC,qBAAqB,CAAC;IAG1D;;;;;;OAMG;IACG,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,CAAC,qBAAqB,CAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;CA0BxH"}
@@ -0,0 +1,57 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Injectable } from '@nestjs/common';
11
+ import { InjectRepository } from '@nestjs/typeorm';
12
+ import { IntegrationStatus, LogIntegrationInbound } from '@cargolift-cdi/types';
13
+ /**
14
+ * Repositório de log de integração de entrada (inbound).
15
+ * Responsável por criar/atualizar registros de latência associados a um id.
16
+ * Possibilidade de reprocessamento e auditoria.
17
+ */
18
+ let LogInboundRepositoryService = class LogInboundRepositoryService {
19
+ repo;
20
+ constructor(repo) {
21
+ this.repo = repo;
22
+ }
23
+ /**
24
+ * Cria um novo registro de latência.
25
+ * @param id
26
+ * @param correlation_id
27
+ * @param timestamp_start
28
+ * @returns
29
+ */
30
+ async register(correlationId, data = {}) {
31
+ const payload = {
32
+ correlationId,
33
+ durationProcessMs: data.timestampProcess
34
+ ? Date.now() - new Date(data.timestampProcess || "").getTime()
35
+ : undefined,
36
+ ...data,
37
+ };
38
+ if (data.status === IntegrationStatus.SUCCESS || data.status === IntegrationStatus.FAILED) {
39
+ const endTime = Date.now();
40
+ payload.timestampEnd = new Date();
41
+ if (payload.timestampStart) {
42
+ payload.durationMs = endTime - new Date(payload.timestampStart).getTime();
43
+ }
44
+ }
45
+ await this.repo.upsert(payload, ["correlationId"]);
46
+ return this.repo.findOne({
47
+ where: {
48
+ correlationId,
49
+ },
50
+ });
51
+ }
52
+ };
53
+ LogInboundRepositoryService = __decorate([
54
+ Injectable(),
55
+ __param(0, InjectRepository(LogIntegrationInbound))
56
+ ], LogInboundRepositoryService);
57
+ export { LogInboundRepositoryService };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@cargolift-cdi/lib-repositories",
3
+ "version": "0.0.2",
4
+ "description": "Repositórios de acesso a dados via TypeORM para projetos da Cargolift para o Middleware CDI",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/cargolift-cdi/lib-repositories.git"
9
+ },
10
+ "sideEffects": false,
11
+ "type": "module",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist/**/*",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "scripts": {
27
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
28
+ "build": "npm run clean && tsc -p tsconfig.json",
29
+ "prepublishOnly": "npm run clean && npm run build && npm version patch --no-git-tag-version",
30
+ "updatelibs": "npm update @cargolift-cdi/types"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "devDependencies": {
36
+ "@cargolift-cdi/types": "^0.1.158",
37
+ "@types/node": "^25.2.2",
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "dependencies": {
41
+ "@nestjs/common": "^11.1.13",
42
+ "@nestjs/typeorm": "^11.0.0",
43
+ "typeorm": "^0.3.28"
44
+ }
45
+ }