@onlineapps/mq-client-core 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/mq-client-core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Core MQ client library for RabbitMQ - shared by infrastructure services and connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -18,10 +18,11 @@
18
18
  "author": "OnlineApps",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "amqplib": "^0.10.3",
21
+ "@onlineapps/infra-logger": "2.0.0",
22
+ "@onlineapps/runtime-config": "1.0.3",
22
23
  "ajv": "^8.12.0",
23
- "lodash.merge": "^4.6.2",
24
- "@onlineapps/runtime-config": "1.0.3"
24
+ "amqplib": "^0.10.3",
25
+ "lodash.merge": "^4.6.2"
25
26
  },
26
27
  "devDependencies": {
27
28
  "jest": "^29.7.0"
@@ -13,7 +13,9 @@ const {
13
13
  PermanentPublishError,
14
14
  QueueNotFoundError,
15
15
  classifyPublishError,
16
+ missingInfrastructureQueueMessage,
16
17
  } = require('../utils/publishErrors');
18
+ const { createLogger } = require('@onlineapps/infra-logger');
17
19
  const PublishLayer = require('../layers/PublishLayer');
18
20
  const RecoveryWorker = require('../workers/RecoveryWorker');
19
21
  const PublishMonitor = require('../monitoring/PublishMonitor');
@@ -54,33 +56,6 @@ function buildAmqpMessageProperties(options, persistent, headers) {
54
56
  return props;
55
57
  }
56
58
 
57
- /**
58
- * Local structured logger (module-owned) to avoid dependency cycles.
59
- *
60
- * IMPORTANT:
61
- * - mq-client-core is a low-level library used by infrastructure-tools.
62
- * - Therefore mq-client-core MUST NOT depend on infrastructure-tools.
63
- */
64
- function createInfraLogger(service, layer) {
65
- const prefix = (contextId, action) => `[${contextId}:${service}:${layer}:${action}]`;
66
-
67
- const toJson = (data) => {
68
- try {
69
- return JSON.stringify(data);
70
- } catch (e) {
71
- return JSON.stringify({ error: 'failed_to_serialize', message: e.message });
72
- }
73
- };
74
-
75
- return {
76
- input: (contextId, action, data) => console.log(prefix(contextId, action), toJson(data)),
77
- output: (contextId, action, data) => console.log(prefix(contextId, action), toJson(data)),
78
- process: (contextId, action, data) => console.log(prefix(contextId, action), toJson(data)),
79
- lifecycle: (contextId, action, data) => console.log(prefix(contextId, action), toJson(data)),
80
- fail: (contextId, action, data) => console.error(prefix(contextId, action), toJson(data)),
81
- };
82
- }
83
-
84
59
  class RabbitMQClient extends EventEmitter {
85
60
  /**
86
61
  * @param {Object} config
@@ -167,7 +142,14 @@ class RabbitMQClient extends EventEmitter {
167
142
  this._criticalHealthStartTime = null; // Track when critical health started
168
143
 
169
144
  // Create structured logger for infrastructure logging (module-owned)
170
- this._log = createInfraLogger('mq-client-core', 'transport');
145
+ // ONE implementation of the infrastructure logger, in
146
+ // @onlineapps/infra-logger. A private copy lived here until 2026-08-29,
147
+ // justified as avoiding a dependency cycle — a cycle that is not there:
148
+ // the comment named infrastructure-tools, but the logger is infra-logger,
149
+ // which declares no @onlineapps dependency at all. The copy meanwhile
150
+ // missed the identity fail-fast that 2.0.0 added (change-discipline.md:
151
+ // one fact, one owner).
152
+ this._log = createLogger('mq-client-core', 'transport');
171
153
 
172
154
  // Publish layer (retry + buffer)
173
155
  this._publishLayer = new PublishLayer({
@@ -1685,10 +1667,7 @@ class RabbitMQClient extends EventEmitter {
1685
1667
  console.log(`[RabbitMQClient] [mq-client-core] [CONSUMER] ✓ Infrastructure queue ${queue} exists (consumer will proceed)`);
1686
1668
  } catch (checkErr) {
1687
1669
  if (checkErr.code === 404) {
1688
- throw new Error(
1689
- `Infrastructure queue ${queue} is missing. ` +
1690
- 'Ownership rule: infrastructure queues must be created by their owning infrastructure service via initInfrastructureQueues().'
1691
- );
1670
+ throw new Error(missingInfrastructureQueueMessage(queue));
1692
1671
  }
1693
1672
  throw checkErr;
1694
1673
  }
@@ -67,6 +67,32 @@ class QueueNotFoundError extends PermanentPublishError {
67
67
  }
68
68
  }
69
69
 
70
+ /**
71
+ * The message a CONSUMER gets when an infrastructure queue it must attach to
72
+ * does not exist (TODO §22).
73
+ *
74
+ * It used to state the rule and leave the reader stuck: it named
75
+ * `initInfrastructureQueues()`, a function this package does not export and
76
+ * never has. `mq-client-core` sits deliberately BELOW `infrastructure-tools`
77
+ * and must not depend on it, so naming the owning package is the only thing
78
+ * that can bridge the two — and without it the fix is unfindable.
79
+ *
80
+ * @param {string} queueName
81
+ * @returns {string}
82
+ */
83
+ function missingInfrastructureQueueMessage(queueName) {
84
+ if (!queueName) {
85
+ throw new Error('[publishErrors] queueName is required - Expected the name of the missing infrastructure queue');
86
+ }
87
+
88
+ return `[RabbitMQClient] Infrastructure queue ${queueName} is missing - `
89
+ + 'Expected: it to be created by the infrastructure service that owns it, before any consumer starts. '
90
+ + 'Consumers never create infrastructure queues: sendToQueue() and consume() would declare them with '
91
+ + 'default arguments (no TTL, no max-length) and every later declaration would fail with 406. '
92
+ + 'Fix: start the owning infrastructure service, which calls initInfrastructureQueues() from '
93
+ + '@onlineapps/infrastructure-tools.';
94
+ }
95
+
70
96
  /**
71
97
  * Best-effort klasifikace chyb z publishu do specializovaných typů.
72
98
  * Vrací původní chybu, pokud neodpovídá žádnému známému patternu.
@@ -116,6 +142,7 @@ function classifyPublishError(err) {
116
142
  }
117
143
 
118
144
  module.exports = {
145
+ missingInfrastructureQueueMessage,
119
146
  TransientPublishError,
120
147
  PermanentPublishError,
121
148
  QueueNotFoundError,