@seidor-cloud-produtos/orbit-backend-lib 0.0.48 → 0.0.49

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 (136) hide show
  1. package/README.md +0 -0
  2. package/dist/clean-arch/application/queue/handler.d.ts +0 -0
  3. package/dist/clean-arch/application/queue/handler.js +0 -0
  4. package/dist/clean-arch/application/queue/messages-in-memory.d.ts +0 -0
  5. package/dist/clean-arch/application/queue/messages-in-memory.js +0 -0
  6. package/dist/clean-arch/application/queue/queue-connection.d.ts +0 -0
  7. package/dist/clean-arch/application/queue/queue-connection.js +0 -0
  8. package/dist/clean-arch/application/queue/queue.d.ts +0 -0
  9. package/dist/clean-arch/application/queue/queue.js +0 -0
  10. package/dist/clean-arch/domain/entities/aggregate-root.d.ts +0 -0
  11. package/dist/clean-arch/domain/entities/aggregate-root.js +0 -0
  12. package/dist/clean-arch/domain/entities/common-dto.d.ts +0 -0
  13. package/dist/clean-arch/domain/entities/common-dto.js +0 -0
  14. package/dist/clean-arch/domain/entities/entity.d.ts +0 -0
  15. package/dist/clean-arch/domain/entities/entity.js +4 -1
  16. package/dist/clean-arch/domain/entities/unique-entity-id.d.ts +0 -0
  17. package/dist/clean-arch/domain/entities/unique-entity-id.js +4 -1
  18. package/dist/clean-arch/domain/entities/value-object.d.ts +0 -0
  19. package/dist/clean-arch/domain/entities/value-object.js +0 -0
  20. package/dist/clean-arch/domain/entities/watched-list.d.ts +0 -0
  21. package/dist/clean-arch/domain/entities/watched-list.js +0 -0
  22. package/dist/clean-arch/domain/entities/watched-list.spec.d.ts +0 -0
  23. package/dist/clean-arch/domain/entities/watched-list.spec.js +0 -0
  24. package/dist/clean-arch/domain/errors/application-error.d.ts +0 -0
  25. package/dist/clean-arch/domain/errors/application-error.js +0 -0
  26. package/dist/clean-arch/domain/errors/domain-error.d.ts +0 -0
  27. package/dist/clean-arch/domain/errors/domain-error.js +0 -0
  28. package/dist/clean-arch/domain/errors/invalid-password-algorithm-error.d.ts +0 -0
  29. package/dist/clean-arch/domain/errors/invalid-password-algorithm-error.js +0 -0
  30. package/dist/clean-arch/domain/errors/invalid-password-length-error.d.ts +0 -0
  31. package/dist/clean-arch/domain/errors/invalid-password-length-error.js +0 -0
  32. package/dist/clean-arch/domain/errors/validation-error.d.ts +0 -0
  33. package/dist/clean-arch/domain/errors/validation-error.js +0 -0
  34. package/dist/clean-arch/domain/events/domain-event.d.ts +0 -0
  35. package/dist/clean-arch/domain/events/domain-event.js +0 -0
  36. package/dist/clean-arch/domain/factories/create-password-factory.d.ts +0 -0
  37. package/dist/clean-arch/domain/factories/create-password-factory.js +0 -0
  38. package/dist/clean-arch/domain/factories/random-password-temporary-factory.d.ts +0 -0
  39. package/dist/clean-arch/domain/factories/random-password-temporary-factory.js +0 -0
  40. package/dist/clean-arch/domain/types/optional.d.ts +0 -0
  41. package/dist/clean-arch/domain/types/optional.js +0 -0
  42. package/dist/clean-arch/domain/value-objects/password.d.ts +0 -0
  43. package/dist/clean-arch/domain/value-objects/password.js +0 -0
  44. package/dist/clean-arch/domain/value-objects/pbkdf2-password.d.ts +0 -0
  45. package/dist/clean-arch/domain/value-objects/pbkdf2-password.js +0 -0
  46. package/dist/clean-arch/domain/value-objects/sha1-password.d.ts +0 -0
  47. package/dist/clean-arch/domain/value-objects/sha1-password.js +0 -0
  48. package/dist/clean-arch/infra/adapters/express-adapter.d.ts +0 -0
  49. package/dist/clean-arch/infra/adapters/express-adapter.js +0 -0
  50. package/dist/clean-arch/infra/adapters/fastify-adapter.d.ts +0 -0
  51. package/dist/clean-arch/infra/adapters/fastify-adapter.js +4 -1
  52. package/dist/clean-arch/infra/authorizations/authorization.d.ts +0 -0
  53. package/dist/clean-arch/infra/authorizations/authorization.js +0 -0
  54. package/dist/clean-arch/infra/authorizations/authorizer.d.ts +0 -0
  55. package/dist/clean-arch/infra/authorizations/authorizer.js +0 -0
  56. package/dist/clean-arch/infra/authorizations/authorizer.spec.d.ts +0 -0
  57. package/dist/clean-arch/infra/authorizations/authorizer.spec.js +0 -0
  58. package/dist/clean-arch/infra/authorizations/not-allowed.d.ts +0 -0
  59. package/dist/clean-arch/infra/authorizations/not-allowed.js +0 -0
  60. package/dist/clean-arch/infra/errors/infra-error.d.ts +0 -0
  61. package/dist/clean-arch/infra/errors/infra-error.js +0 -0
  62. package/dist/clean-arch/infra/http/controller.d.ts +0 -0
  63. package/dist/clean-arch/infra/http/controller.js +0 -0
  64. package/dist/clean-arch/infra/http/handle-bool-filter.d.ts +0 -0
  65. package/dist/clean-arch/infra/http/handle-bool-filter.js +0 -0
  66. package/dist/clean-arch/infra/http/handle-is-active-query.d.ts +0 -0
  67. package/dist/clean-arch/infra/http/handle-is-active-query.js +0 -0
  68. package/dist/clean-arch/infra/http/handle-sort-param-query.d.ts +0 -0
  69. package/dist/clean-arch/infra/http/handle-sort-param-query.js +0 -0
  70. package/dist/clean-arch/infra/http/handle-user-headers.d.ts +0 -0
  71. package/dist/clean-arch/infra/http/handle-user-headers.js +0 -0
  72. package/dist/clean-arch/infra/http/health-connections.d.ts +0 -0
  73. package/dist/clean-arch/infra/http/health-connections.js +0 -0
  74. package/dist/clean-arch/infra/http/http.d.ts +0 -0
  75. package/dist/clean-arch/infra/http/http.js +0 -0
  76. package/dist/clean-arch/infra/queue/create-consumers.d.ts +0 -0
  77. package/dist/clean-arch/infra/queue/create-consumers.js +0 -0
  78. package/dist/clean-arch/infra/queue/in-memory/in-memory-queue.d.ts +0 -0
  79. package/dist/clean-arch/infra/queue/in-memory/in-memory-queue.js +0 -0
  80. package/dist/clean-arch/infra/queue/queue-controller.d.ts +0 -0
  81. package/dist/clean-arch/infra/queue/queue-controller.js +0 -0
  82. package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +1 -3
  83. package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +12 -15
  84. package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.spec.d.ts +0 -0
  85. package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.spec.js +0 -0
  86. package/dist/clean-arch/shared/pagination/dto-response.d.ts +0 -0
  87. package/dist/clean-arch/shared/pagination/dto-response.js +0 -0
  88. package/dist/clean-arch/shared/pagination/get-take-and-skip.d.ts +0 -0
  89. package/dist/clean-arch/shared/pagination/get-take-and-skip.js +0 -0
  90. package/dist/clean-arch/shared/pagination/pagination.d.ts +0 -0
  91. package/dist/clean-arch/shared/pagination/pagination.js +0 -0
  92. package/dist/frameworks/express/api-gateway/mapping-model.d.ts +0 -0
  93. package/dist/frameworks/express/api-gateway/mapping-model.js +0 -0
  94. package/dist/frameworks/express/api-gateway/mapping-model.spec.d.ts +0 -0
  95. package/dist/frameworks/express/api-gateway/mapping-model.spec.js +0 -0
  96. package/dist/frameworks/express/api-gateway/middleware-express.d.ts +0 -0
  97. package/dist/frameworks/express/api-gateway/middleware-express.js +0 -0
  98. package/dist/frameworks/express/authorizations/authorization-express.d.ts +0 -0
  99. package/dist/frameworks/express/authorizations/authorization-express.js +0 -0
  100. package/dist/frameworks/express/authorizations/authorization-express.spec.d.ts +0 -0
  101. package/dist/frameworks/express/authorizations/authorization-express.spec.js +0 -0
  102. package/dist/frameworks/express/authorizations/middleware-express.d.ts +0 -0
  103. package/dist/frameworks/express/authorizations/middleware-express.js +0 -0
  104. package/dist/frameworks/express/types.d.ts +0 -0
  105. package/dist/frameworks/express/types.js +0 -0
  106. package/dist/frameworks/nest/authorizations/authorization-nest.d.ts +0 -0
  107. package/dist/frameworks/nest/authorizations/authorization-nest.js +0 -0
  108. package/dist/frameworks/nest/authorizations/guard-nest.d.ts +0 -0
  109. package/dist/frameworks/nest/authorizations/guard-nest.js +0 -0
  110. package/dist/index.d.ts +0 -0
  111. package/dist/index.js +0 -0
  112. package/dist/infra/authorizations/auth-matcher.d.ts +0 -0
  113. package/dist/infra/authorizations/auth-matcher.js +12 -2
  114. package/dist/infra/authorizations/auth-matcher.spec.d.ts +0 -0
  115. package/dist/infra/authorizations/auth-matcher.spec.js +32 -0
  116. package/dist/infra/authorizations/validator/api/api-validator.d.ts +0 -0
  117. package/dist/infra/authorizations/validator/api/api-validator.js +0 -0
  118. package/dist/infra/authorizations/validator/api/factories/unauthorized-response-factory.d.ts +0 -0
  119. package/dist/infra/authorizations/validator/api/factories/unauthorized-response-factory.js +0 -0
  120. package/dist/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.d.ts +0 -0
  121. package/dist/infra/authorizations/validator/api/factories/unauthorized-response-factory.spec.js +0 -0
  122. package/dist/infra/authorizations/validator/auth-validator.d.ts +0 -0
  123. package/dist/infra/authorizations/validator/auth-validator.js +0 -0
  124. package/dist/infra/authorizations/validator/auth-validator.spec.d.ts +0 -0
  125. package/dist/infra/authorizations/validator/auth-validator.spec.js +0 -0
  126. package/dist/infra/http/api-gateway/mapping-model.d.ts +0 -0
  127. package/dist/infra/http/api-gateway/mapping-model.js +0 -0
  128. package/dist/infra/http/api-gateway/mapping-model.spec.d.ts +0 -0
  129. package/dist/infra/http/api-gateway/mapping-model.spec.js +0 -0
  130. package/dist/infra/http/errors/api-common-error.d.ts +0 -0
  131. package/dist/infra/http/errors/api-common-error.js +0 -0
  132. package/dist/infra/http/errors/api-error.d.ts +0 -0
  133. package/dist/infra/http/errors/api-error.js +0 -0
  134. package/dist/infra/http/errors/unauthorized-response.d.ts +0 -0
  135. package/dist/infra/http/errors/unauthorized-response.js +0 -0
  136. package/package.json +1 -1
package/README.md CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,7 +10,10 @@ class Entity {
10
10
  this._id = id;
11
11
  }
12
12
  constructor(props, id) {
13
- this._id = id ?? new unique_entity_id_1.UniqueEntityId(id);
13
+ this._id =
14
+ id !== null && id !== void 0
15
+ ? id
16
+ : new unique_entity_id_1.UniqueEntityId(id);
14
17
  this.props = props;
15
18
  }
16
19
  equals(entity) {
@@ -4,7 +4,10 @@ exports.UniqueEntityId = void 0;
4
4
  const node_crypto_1 = require('node:crypto');
5
5
  class UniqueEntityId {
6
6
  constructor(value) {
7
- this.value = value ?? (0, node_crypto_1.randomUUID)();
7
+ this.value =
8
+ value !== null && value !== void 0
9
+ ? value
10
+ : (0, node_crypto_1.randomUUID)();
8
11
  }
9
12
  toString() {
10
13
  return this.value;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -33,11 +33,14 @@ class FastifyAdapter {
33
33
  async listen(port) {
34
34
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
35
35
  this.instance.listen({ port }, async (err, _) => {
36
+ var _a;
36
37
  if (err) {
37
38
  console.error(err);
38
39
  process.exit();
39
40
  }
40
- await this.instance?.ready();
41
+ await ((_a = this.instance) === null || _a === void 0
42
+ ? void 0
43
+ : _a.ready());
41
44
  if (this.envs.NODE_ENV !== 'test') {
42
45
  console.log(`🚀 Server is running on PORT ${port}`);
43
46
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,7 +9,6 @@ export default class AmqpQueue implements QueueConnection {
9
9
  private connection;
10
10
  private messagesInMemory;
11
11
  private controller;
12
- private channels;
13
12
  constructor();
14
13
  connect(vHost: string): Promise<any>;
15
14
  close(): Promise<void>;
@@ -22,8 +21,7 @@ export default class AmqpQueue implements QueueConnection {
22
21
  createConsumers(queueName: string, configs: CreateConsumers): Promise<void>;
23
22
  setController(controller?: QueueController): this;
24
23
  static getInstance(vHost: string): Promise<AmqpQueue>;
25
- private treatReconnection;
26
- private closeChannels;
24
+ private registerEvents;
27
25
  private publishMessagesOfMemory;
28
26
  }
29
27
  type CreateConsumers = {
@@ -5,14 +5,13 @@ const amqplib_1 = tslib_1.__importDefault(require('amqplib'));
5
5
  class AmqpQueue {
6
6
  constructor() {
7
7
  this.messagesInMemory = [];
8
- this.channels = [];
9
8
  this.uri = process.env.BROKER_AMQP;
10
9
  }
11
10
  async connect(vHost) {
12
11
  const urlConnection = `${this.uri}/${vHost}`;
13
12
  this.connection = await amqplib_1.default.connect(urlConnection);
14
13
  this.vHost = vHost;
15
- await this.treatReconnection(vHost);
14
+ this.registerEvents(vHost);
16
15
  if (process.env.NODE_ENV !== 'test') {
17
16
  console.log(`🐝 Queue connected on vHost: ${this.vHost}`);
18
17
  }
@@ -27,11 +26,16 @@ class AmqpQueue {
27
26
  async on(queueName, callback) {
28
27
  try {
29
28
  const channel = await this.connection.createChannel();
30
- this.channels.push(channel);
31
29
  await channel.prefetch(callback.getSimultaneity());
32
30
  await channel.consume(queueName, async message => {
33
31
  try {
34
- await callback.handle(JSON.parse(message?.content.toString()));
32
+ await callback.handle(
33
+ JSON.parse(
34
+ message === null || message === void 0
35
+ ? void 0
36
+ : message.content.toString(),
37
+ ),
38
+ );
35
39
  channel.ack(message);
36
40
  } catch (_) {
37
41
  if (process.env.NODE_ENV === 'test') return;
@@ -120,27 +124,20 @@ class AmqpQueue {
120
124
  AmqpQueue.instance = await queue.connect(vHost);
121
125
  return AmqpQueue.instance;
122
126
  }
123
- async treatReconnection(vHost) {
124
- this.connection.removeAllListeners('close');
125
- this.connection.on('close', async () => {
126
- await this.closeChannels();
127
+ registerEvents(vHost) {
128
+ this.connection.on('close', () => {
127
129
  const interval = setInterval(async () => {
128
130
  try {
129
131
  AmqpQueue.instance = await this.connect(vHost);
130
132
  this.controller;
131
- await this.publishMessagesOfMemory();
133
+ this.publishMessagesOfMemory();
132
134
  clearInterval(interval);
133
135
  } catch {
134
136
  console.log(`try connection on vHost: ${vHost}`);
135
137
  }
136
138
  }, 5000);
137
139
  });
138
- }
139
- async closeChannels() {
140
- for (const channel of this.channels) {
141
- await channel.close();
142
- }
143
- this.channels = [];
140
+ this.connection.removeListener('close', this.registerEvents);
144
141
  }
145
142
  async publishMessagesOfMemory() {
146
143
  if (this.messagesInMemory.length > 0) {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/dist/index.d.ts CHANGED
File without changes
package/dist/index.js CHANGED
File without changes
File without changes
@@ -12,7 +12,12 @@ class AuthMatcher {
12
12
  return $andResult && $orResult;
13
13
  }
14
14
  static handleOr(authorizationsFromRequest, requiredUserAuthorizations) {
15
- if (!requiredUserAuthorizations?.length) {
15
+ if (
16
+ !(requiredUserAuthorizations === null ||
17
+ requiredUserAuthorizations === void 0
18
+ ? void 0
19
+ : requiredUserAuthorizations.length)
20
+ ) {
16
21
  return true;
17
22
  }
18
23
  for (let i = 0; i < requiredUserAuthorizations.length; i++) {
@@ -24,7 +29,12 @@ class AuthMatcher {
24
29
  return false;
25
30
  }
26
31
  static handleAnd(authorizationsFromRequest, requiredUserAuthorizations) {
27
- if (!requiredUserAuthorizations?.length) {
32
+ if (
33
+ !(requiredUserAuthorizations === null ||
34
+ requiredUserAuthorizations === void 0
35
+ ? void 0
36
+ : requiredUserAuthorizations.length)
37
+ ) {
28
38
  return true;
29
39
  }
30
40
  for (let i = 0; i < requiredUserAuthorizations.length; i++) {
File without changes
@@ -71,6 +71,38 @@ describe('AuthMatcher', () => {
71
71
  const result = auth_matcher_1.default.isMatch(params, authorizations);
72
72
  expect(result).toBe(true);
73
73
  });
74
+ it('4Unity - case', () => {
75
+ const params = {
76
+ $and: ['4unity.documents.create', '4unity.documents.update'],
77
+ };
78
+ const authorizations = [
79
+ '4unity.configurations.create',
80
+ '4unity.configurations.list',
81
+ '4unity.configurations.list-client-configration',
82
+ '4unity.configurations.list-general-politcs',
83
+ '4unity.configurations.update',
84
+ '4unity.configurations.update-payment',
85
+ '4unity.documents.create',
86
+ '4unity.documents.export',
87
+ '4unity.documents.list',
88
+ '4unity.documents.read',
89
+ '4unity.documents.update',
90
+ '4unity.home.read',
91
+ '4unity.payment-management.check',
92
+ '4unity.payment-management.create',
93
+ '4unity.payment-management.list',
94
+ '4unity.profiles.client-supplier',
95
+ '4unity.profiles.supplier',
96
+ '4unity.purchase-orders.list',
97
+ '4unity.purchase-orders.read',
98
+ '4unity.suppliers.list',
99
+ '4unity.suppliers.update',
100
+ 'common.partners.list',
101
+ 'common.states.list',
102
+ ];
103
+ const result = auth_matcher_1.default.isMatch(params, authorizations);
104
+ expect(result).toBe(true);
105
+ });
74
106
  });
75
107
  describe('handleOr', () => {
76
108
  it('should return true if acceptValues is undefined or empty', () => {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",