@diia-inhouse/diia-queue 14.0.12 → 14.0.14

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.
@@ -32,6 +32,11 @@ type QueueConfigByQueueName = { [k in QueueName]: {
32
32
  topics: ExchangeName[];
33
33
  } };
34
34
  type QueueConfig = Record<QueueConfigType.Internal, QueueConfigByQueueName>;
35
+ /**
36
+ * Under QueueConfigType.External, each key is auto-prefixed
37
+ * with 'TopicExternal' to form the broker exchange name (e.g.
38
+ * 'Auth' → 'TopicExternalAuth'). See ExternalEventBus.
39
+ */
35
40
  type TopicConfigByConfigType = { [k in ExchangeName]: {
36
41
  events: EventName[];
37
42
  } };
@@ -9,7 +9,7 @@ import { AmqpConnection } from "./amqpConnection.js";
9
9
  import { AmqpListener } from "./amqpListener.js";
10
10
  import { AmqpPublisher } from "./amqpPublisher.js";
11
11
  import { InternalServerError } from "@diia-inhouse/errors";
12
- import lodash from "lodash";
12
+ import _ from "lodash";
13
13
  import { randomUUID } from "node:crypto";
14
14
  import { EventEmitter } from "node:events";
15
15
  import pTimeout from "p-timeout";
@@ -111,7 +111,7 @@ var RabbitMQProvider = class extends EventEmitter {
111
111
  };
112
112
  }
113
113
  async makeAMQPConnection(client) {
114
- return new AmqpConnection(this.rabbitmqConfig.connection, this.logger, this.rabbitmqConfig.reconnectOptions, lodash.merge({ clientProperties: { connectionClientType: client } }, this.rabbitmqConfig.socketOptions));
114
+ return new AmqpConnection(this.rabbitmqConfig.connection, this.logger, this.rabbitmqConfig.reconnectOptions, _.merge({ clientProperties: { connectionClientType: client } }, this.rabbitmqConfig.socketOptions));
115
115
  }
116
116
  async makeAMQPListener(queuesOptions) {
117
117
  return new AmqpListener(await this.getConnection("listener"), this.logger, this.rabbitMQMetricsService, queuesOptions, this.systemServiceName);
@@ -1,5 +1,5 @@
1
1
  import { collectEventBusListeners } from "../utils.js";
2
- import lodash from "lodash";
2
+ import _ from "lodash";
3
3
  //#region src/services/eventCommunicator.ts
4
4
  var EventCommunicator = class {
5
5
  logger;
@@ -31,8 +31,8 @@ var EventCommunicator = class {
31
31
  getUnicastListeners() {
32
32
  const listeners = [];
33
33
  const { queuesOptions, exchangesOptions } = this.queueProvider.getMessageBrokerServiceConfig();
34
- const queuesOptionsMap = lodash.keyBy(queuesOptions, "name");
35
- const exchangesOptionsMap = lodash.keyBy(exchangesOptions, "name");
34
+ const queuesOptionsMap = _.keyBy(queuesOptions, "name");
35
+ const exchangesOptionsMap = _.keyBy(exchangesOptions, "name");
36
36
  for (const eventListener of this.listenerList) {
37
37
  const { queueNames = [] } = eventListener;
38
38
  for (const queueName of queueNames) {
@@ -21,7 +21,7 @@ declare class EventMessageHandler {
21
21
  private getServiceCode;
22
22
  private prepareQueueMessageError;
23
23
  private resolveTraceId;
24
- private extractTraceparentTraceId;
24
+ private toPropagationCarrier;
25
25
  }
26
26
  //#endregion
27
27
  export { EventMessageHandler };
@@ -2,7 +2,7 @@ import { NackOptions } from "../interfaces/providers/rabbitmq/index.js";
2
2
  import "../interfaces/index.js";
3
3
  import { ApiError, ValidationError } from "@diia-inhouse/errors";
4
4
  import { randomBytes } from "node:crypto";
5
- import { isValidTraceId, trace } from "@opentelemetry/api";
5
+ import { context, isValidTraceId, propagation, trace } from "@opentelemetry/api";
6
6
  import { utils } from "@diia-inhouse/utils";
7
7
  //#region src/services/eventMessageHandler.ts
8
8
  var EventMessageHandler = class {
@@ -107,17 +107,20 @@ var EventMessageHandler = class {
107
107
  };
108
108
  }
109
109
  resolveTraceId(properties) {
110
- const extractedTraceId = this.extractTraceparentTraceId(properties.headers?.traceparent);
110
+ const carrier = this.toPropagationCarrier(properties.headers);
111
+ const extractedTraceId = trace.getSpan(propagation.extract(context.active(), carrier))?.spanContext().traceId ?? "";
111
112
  if (isValidTraceId(extractedTraceId)) return extractedTraceId;
112
113
  const activeSpanTraceId = trace.getActiveSpan()?.spanContext().traceId ?? "";
113
114
  if (isValidTraceId(activeSpanTraceId)) return activeSpanTraceId;
114
115
  return properties.headers?.traceId || randomBytes(16).toString("hex");
115
116
  }
116
- extractTraceparentTraceId(raw) {
117
- if (raw === void 0 || raw === null) return "";
118
- const [version, traceId] = (Buffer.isBuffer(raw) ? raw.toString("utf8") : raw).split("-");
119
- if (version !== "00" || !traceId) return "";
120
- return isValidTraceId(traceId) ? traceId : "";
117
+ toPropagationCarrier(headers) {
118
+ const carrier = {};
119
+ for (const [key, value] of Object.entries(headers ?? {})) {
120
+ if (value === void 0 || value === null) continue;
121
+ carrier[key] = Buffer.isBuffer(value) ? value.toString("utf8") : String(value);
122
+ }
123
+ return carrier;
121
124
  }
122
125
  };
123
126
  //#endregion
@@ -2,7 +2,7 @@ import { QueueTypes } from "../interfaces/messageBrokerServiceConfig.js";
2
2
  import "../interfaces/index.js";
3
3
  import constants_default from "../constants.js";
4
4
  import Communicator from "./communicator.js";
5
- import lodash from "lodash";
5
+ import _ from "lodash";
6
6
  //#region src/services/task.ts
7
7
  var Task = class extends Communicator {
8
8
  serviceName;
@@ -18,8 +18,8 @@ var Task = class extends Communicator {
18
18
  }
19
19
  async onInit() {
20
20
  const { queuesOptions, exchangesOptions } = await this.init();
21
- const queuesOptionsMap = lodash.keyBy(queuesOptions, "name");
22
- const exchangesOptionsMap = lodash.keyBy(exchangesOptions, "name");
21
+ const queuesOptionsMap = _.keyBy(queuesOptions, "name");
22
+ const exchangesOptionsMap = _.keyBy(exchangesOptions, "name");
23
23
  for (const task of this.taskList) {
24
24
  const { name: taskName, isDelayed = false, queueNames = [] } = task;
25
25
  if (queueNames.length === 0) {
@@ -69,8 +69,8 @@ var Task = class extends Communicator {
69
69
  getUnicastListeners() {
70
70
  const listeners = [];
71
71
  const { queuesOptions, exchangesOptions } = this.queueProvider.getMessageBrokerServiceConfig();
72
- const queuesOptionsMap = lodash.keyBy(queuesOptions, "name");
73
- const exchangesOptionsMap = lodash.keyBy(exchangesOptions, "name");
72
+ const queuesOptionsMap = _.keyBy(queuesOptions, "name");
73
+ const exchangesOptionsMap = _.keyBy(exchangesOptions, "name");
74
74
  for (const task of this.taskList) {
75
75
  const { queueNames = [], name: taskName, isDelayed = false } = task;
76
76
  if (queueNames.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/diia-queue",
3
- "version": "14.0.12",
3
+ "version": "14.0.14",
4
4
  "type": "module",
5
5
  "description": "Package provide queue functionality",
6
6
  "main": "dist/index.js",
@@ -52,9 +52,9 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@diia-inhouse/configs": "7.0.0",
55
- "@diia-inhouse/diia-logger": "4.2.4",
56
- "@diia-inhouse/diia-metrics": "7.1.5",
57
- "@diia-inhouse/env": "3.3.1",
55
+ "@diia-inhouse/diia-logger": "4.3.0",
56
+ "@diia-inhouse/diia-metrics": "7.1.6",
57
+ "@diia-inhouse/env": "3.3.2",
58
58
  "@diia-inhouse/errors": "2.1.1",
59
59
  "@diia-inhouse/oxc-config": "1.10.0",
60
60
  "@diia-inhouse/test": "8.2.1",