rabbitmq-sdk 0.0.1-security → 1.2.0

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.

Potentially problematic release.


This version of rabbitmq-sdk might be problematic. Click here for more details.

Files changed (140) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.kiro/specs/sdk-rabbitmq/design.md +369 -0
  3. package/.kiro/specs/sdk-rabbitmq/requirements.md +97 -0
  4. package/.kiro/specs/sdk-rabbitmq/tasks.md +248 -0
  5. package/README.md +273 -5
  6. package/bun.lock +790 -0
  7. package/config.example.json +13 -0
  8. package/dist/components/ConfigurationManager.d.ts +35 -0
  9. package/dist/components/ConfigurationManager.d.ts.map +1 -0
  10. package/dist/components/ConfigurationManager.js +118 -0
  11. package/dist/components/ConfigurationManager.js.map +1 -0
  12. package/dist/components/ConnectionManager.d.ts +93 -0
  13. package/dist/components/ConnectionManager.d.ts.map +1 -0
  14. package/dist/components/ConnectionManager.js +349 -0
  15. package/dist/components/ConnectionManager.js.map +1 -0
  16. package/dist/components/DLQHandler.d.ts +81 -0
  17. package/dist/components/DLQHandler.d.ts.map +1 -0
  18. package/dist/components/DLQHandler.js +228 -0
  19. package/dist/components/DLQHandler.js.map +1 -0
  20. package/dist/components/Logger.d.ts +77 -0
  21. package/dist/components/Logger.d.ts.map +1 -0
  22. package/dist/components/Logger.js +193 -0
  23. package/dist/components/Logger.js.map +1 -0
  24. package/dist/components/MessagePublisher.d.ts +49 -0
  25. package/dist/components/MessagePublisher.d.ts.map +1 -0
  26. package/dist/components/MessagePublisher.js +158 -0
  27. package/dist/components/MessagePublisher.js.map +1 -0
  28. package/dist/components/MessageSubscriber.d.ts +108 -0
  29. package/dist/components/MessageSubscriber.d.ts.map +1 -0
  30. package/dist/components/MessageSubscriber.js +503 -0
  31. package/dist/components/MessageSubscriber.js.map +1 -0
  32. package/dist/components/ResourceCreator.d.ts +89 -0
  33. package/dist/components/ResourceCreator.d.ts.map +1 -0
  34. package/dist/components/ResourceCreator.js +352 -0
  35. package/dist/components/ResourceCreator.js.map +1 -0
  36. package/dist/components/SdkRabbitmq.d.ts +103 -0
  37. package/dist/components/SdkRabbitmq.d.ts.map +1 -0
  38. package/dist/components/SdkRabbitmq.js +364 -0
  39. package/dist/components/SdkRabbitmq.js.map +1 -0
  40. package/dist/components/index.d.ts +9 -0
  41. package/dist/components/index.d.ts.map +1 -0
  42. package/dist/components/index.js +20 -0
  43. package/dist/components/index.js.map +1 -0
  44. package/dist/index.d.ts +5 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +27 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/interfaces/IConfiguration.d.ts +35 -0
  49. package/dist/interfaces/IConfiguration.d.ts.map +1 -0
  50. package/dist/interfaces/IConfiguration.js +3 -0
  51. package/dist/interfaces/IConfiguration.js.map +1 -0
  52. package/dist/interfaces/IConnection.d.ts +21 -0
  53. package/dist/interfaces/IConnection.d.ts.map +1 -0
  54. package/dist/interfaces/IConnection.js +3 -0
  55. package/dist/interfaces/IConnection.js.map +1 -0
  56. package/dist/interfaces/IDLQ.d.ts +12 -0
  57. package/dist/interfaces/IDLQ.d.ts.map +1 -0
  58. package/dist/interfaces/IDLQ.js +3 -0
  59. package/dist/interfaces/IDLQ.js.map +1 -0
  60. package/dist/interfaces/IErrors.d.ts +33 -0
  61. package/dist/interfaces/IErrors.d.ts.map +1 -0
  62. package/dist/interfaces/IErrors.js +56 -0
  63. package/dist/interfaces/IErrors.js.map +1 -0
  64. package/dist/interfaces/ILogger.d.ts +14 -0
  65. package/dist/interfaces/ILogger.d.ts.map +1 -0
  66. package/dist/interfaces/ILogger.js +3 -0
  67. package/dist/interfaces/ILogger.js.map +1 -0
  68. package/dist/interfaces/IMessage.d.ts +52 -0
  69. package/dist/interfaces/IMessage.d.ts.map +1 -0
  70. package/dist/interfaces/IMessage.js +3 -0
  71. package/dist/interfaces/IMessage.js.map +1 -0
  72. package/dist/interfaces/IResource.d.ts +31 -0
  73. package/dist/interfaces/IResource.d.ts.map +1 -0
  74. package/dist/interfaces/IResource.js +3 -0
  75. package/dist/interfaces/IResource.js.map +1 -0
  76. package/dist/interfaces/ISdkRabbitmq.d.ts +17 -0
  77. package/dist/interfaces/ISdkRabbitmq.d.ts.map +1 -0
  78. package/dist/interfaces/ISdkRabbitmq.js +3 -0
  79. package/dist/interfaces/ISdkRabbitmq.js.map +1 -0
  80. package/dist/interfaces/index.d.ts +9 -0
  81. package/dist/interfaces/index.d.ts.map +1 -0
  82. package/dist/interfaces/index.js +33 -0
  83. package/dist/interfaces/index.js.map +1 -0
  84. package/dist/utils/configSchema.d.ts +8 -0
  85. package/dist/utils/configSchema.d.ts.map +1 -0
  86. package/dist/utils/configSchema.js +51 -0
  87. package/dist/utils/configSchema.js.map +1 -0
  88. package/docker-compose.yml +24 -0
  89. package/example.ts +65 -0
  90. package/examples/README-dynamic-routing.md +155 -0
  91. package/examples/bind-unbind-example.js +56 -0
  92. package/examples/test-chatbot-exchange.ts +83 -0
  93. package/examples/test-dynamic-routing-flow.js +299 -0
  94. package/examples/test-dynamic-routing-flow.ts +355 -0
  95. package/examples/test-no-disconnect.ts +0 -0
  96. package/examples/test-raw-rabbitmq.js +68 -0
  97. package/examples/test-same-channel.ts +81 -0
  98. package/examples/test-schedule-flow.ts +713 -0
  99. package/examples/test-simple-greeting.ts +66 -0
  100. package/examples/test-simple-schedule.ts +76 -0
  101. package/examples/test-wildcard.ts +364 -0
  102. package/jest.config.js +17 -0
  103. package/package.json +42 -4
  104. package/preinstall.js +1 -0
  105. package/prompts/test-dynamic-routing-flow.md +46 -0
  106. package/run.js +4 -0
  107. package/scripts/run-dynamic-routing-test.ts +31 -0
  108. package/src/.gitkeep +1 -0
  109. package/src/components/.gitkeep +1 -0
  110. package/src/components/ConfigurationManager.ts +104 -0
  111. package/src/components/ConnectionManager.ts +357 -0
  112. package/src/components/DLQHandler.ts +271 -0
  113. package/src/components/Logger.ts +224 -0
  114. package/src/components/MessagePublisher.ts +180 -0
  115. package/src/components/MessageSubscriber.ts +597 -0
  116. package/src/components/ResourceCreator.ts +411 -0
  117. package/src/components/SdkRabbitmq.ts +443 -0
  118. package/src/components/__tests__/ConfigurationManager.test.ts +357 -0
  119. package/src/components/__tests__/ConnectionManager.test.ts +387 -0
  120. package/src/components/__tests__/DLQHandler.test.ts +399 -0
  121. package/src/components/__tests__/Logger.test.ts +354 -0
  122. package/src/components/__tests__/MessagePublisher.test.ts +337 -0
  123. package/src/components/__tests__/MessageSubscriber.test.ts +542 -0
  124. package/src/components/__tests__/ResourceCreator.test.ts +465 -0
  125. package/src/components/__tests__/SdkRabbitmq.integration.test.ts +433 -0
  126. package/src/components/index.ts +8 -0
  127. package/src/index.ts +11 -0
  128. package/src/interfaces/.gitkeep +1 -0
  129. package/src/interfaces/IConfiguration.ts +38 -0
  130. package/src/interfaces/IConnection.ts +27 -0
  131. package/src/interfaces/IDLQ.ts +13 -0
  132. package/src/interfaces/IErrors.ts +53 -0
  133. package/src/interfaces/ILogger.ts +16 -0
  134. package/src/interfaces/IMessage.ts +65 -0
  135. package/src/interfaces/IResource.ts +35 -0
  136. package/src/interfaces/ISdkRabbitmq.ts +26 -0
  137. package/src/interfaces/index.ts +23 -0
  138. package/src/utils/.gitkeep +1 -0
  139. package/src/utils/configSchema.ts +58 -0
  140. package/tsconfig.json +34 -0
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Queue options for resource creation
3
+ */
4
+ export interface QueueOptions {
5
+ durable?: boolean;
6
+ exclusive?: boolean;
7
+ autoDelete?: boolean;
8
+ arguments?: Record<string, any>;
9
+ }
10
+
11
+ /**
12
+ * Exchange options for resource creation
13
+ */
14
+ export interface ExchangeOptions {
15
+ durable?: boolean;
16
+ autoDelete?: boolean;
17
+ arguments?: Record<string, any>;
18
+ }
19
+
20
+ /**
21
+ * Resource creator interface for auto-creating exchanges and queues
22
+ */
23
+ export interface IResourceCreator {
24
+ /** Ensure exchange exists, create if it doesn't */
25
+ ensureExchange(exchange: string, type?: string, options?: ExchangeOptions): Promise<void>;
26
+
27
+ /** Ensure queue exists, create if it doesn't */
28
+ ensureQueue(queue: string, options?: QueueOptions): Promise<void>;
29
+
30
+ /** Bind queue to exchange with routing key */
31
+ bindQueue(queue: string, exchange: string, routingKey: string): Promise<void>;
32
+
33
+ /** Unbind queue from exchange with routing key */
34
+ unbindQueue(queue: string, exchange: string, routingKey: string): Promise<void>;
35
+ }
@@ -0,0 +1,26 @@
1
+ import { MessageCallback } from './IMessage';
2
+
3
+ /**
4
+ * Main SDK RabbitMQ interface - the public API
5
+ */
6
+ export interface ISdkRabbitmq {
7
+ /** Publish a message to an exchange */
8
+ publish(exchange: string, routingKey: string, payload: any): Promise<boolean>;
9
+
10
+ /** Subscribe to messages from a queue */
11
+ subscribe(
12
+ exchange: string,
13
+ queue: string,
14
+ routingKey: string,
15
+ callback: MessageCallback
16
+ ): Promise<void>;
17
+
18
+ /** Bind a queue to an exchange with a routing key */
19
+ bind(queue: string, exchange: string, routingKey: string): Promise<void>;
20
+
21
+ /** Unbind a queue from an exchange with a routing key */
22
+ unbind(queue: string, exchange: string, routingKey: string): Promise<void>;
23
+
24
+ /** Disconnect from RabbitMQ gracefully */
25
+ disconnect(): Promise<void>;
26
+ }
@@ -0,0 +1,23 @@
1
+ // Configuration interfaces
2
+ export * from './IConfiguration';
3
+
4
+ // Connection interfaces
5
+ export * from './IConnection';
6
+
7
+ // Message interfaces
8
+ export * from './IMessage';
9
+
10
+ // Resource interfaces
11
+ export * from './IResource';
12
+
13
+ // DLQ interfaces
14
+ export * from './IDLQ';
15
+
16
+ // Logger interfaces
17
+ export * from './ILogger';
18
+
19
+ // Main SDK interface
20
+ export * from './ISdkRabbitmq';
21
+
22
+ // Error classes
23
+ export * from './IErrors';
@@ -0,0 +1 @@
1
+ # This file ensures the utils directory is tracked by git
@@ -0,0 +1,58 @@
1
+ import { IConfiguration } from '../interfaces/IConfiguration';
2
+ import { ConfigurationError } from '../interfaces/IErrors';
3
+
4
+ /**
5
+ * Validates the configuration object against the expected schema
6
+ * @param config - Configuration object to validate
7
+ * @throws ConfigurationError if validation fails
8
+ */
9
+ export function validateConfigurationSchema(config: any): asserts config is IConfiguration {
10
+ if (!config || typeof config !== 'object') {
11
+ throw new ConfigurationError('Configuration must be a valid object');
12
+ }
13
+
14
+ // Validate required url property
15
+ if (!config.url || typeof config.url !== 'string') {
16
+ throw new ConfigurationError('Configuration must include a valid "url" string property');
17
+ }
18
+
19
+ // Validate required dlq property
20
+ if (!config.dlq || typeof config.dlq !== 'object') {
21
+ throw new ConfigurationError('Configuration must include a valid "dlq" object property');
22
+ }
23
+
24
+ // Validate dlq.active property
25
+ if (typeof config.dlq.active !== 'boolean') {
26
+ throw new ConfigurationError('Configuration dlq.active must be a boolean value');
27
+ }
28
+
29
+ // Validate optional dlq properties
30
+ if (config.dlq.ttl !== undefined && (typeof config.dlq.ttl !== 'number' || config.dlq.ttl < 0)) {
31
+ throw new ConfigurationError('Configuration dlq.ttl must be a positive number');
32
+ }
33
+
34
+ if (config.dlq.maxRetries !== undefined && (typeof config.dlq.maxRetries !== 'number' || config.dlq.maxRetries < 0)) {
35
+ throw new ConfigurationError('Configuration dlq.maxRetries must be a positive number');
36
+ }
37
+
38
+ if (config.dlq.retryDelay !== undefined && (typeof config.dlq.retryDelay !== 'number' || config.dlq.retryDelay < 0)) {
39
+ throw new ConfigurationError('Configuration dlq.retryDelay must be a positive number');
40
+ }
41
+
42
+ // Validate optional logging property
43
+ if (config.logging !== undefined) {
44
+ if (typeof config.logging !== 'object') {
45
+ throw new ConfigurationError('Configuration logging must be an object');
46
+ }
47
+
48
+ const validLevels = ['error', 'warn', 'info', 'debug'];
49
+ if (config.logging.level !== undefined && !validLevels.includes(config.logging.level)) {
50
+ throw new ConfigurationError(`Configuration logging.level must be one of: ${validLevels.join(', ')}`);
51
+ }
52
+
53
+ const validFormats = ['json', 'text'];
54
+ if (config.logging.format !== undefined && !validFormats.includes(config.logging.format)) {
55
+ throw new ConfigurationError(`Configuration logging.format must be one of: ${validFormats.join(', ')}`);
56
+ }
57
+ }
58
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "removeComments": false,
16
+ "noImplicitAny": true,
17
+ "strictNullChecks": true,
18
+ "strictFunctionTypes": true,
19
+ "noImplicitReturns": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+ "exactOptionalPropertyTypes": true,
23
+ "resolveJsonModule": true
24
+ },
25
+ "include": [
26
+ "src/**/*"
27
+ ],
28
+ "exclude": [
29
+ "node_modules",
30
+ "dist",
31
+ "**/*.test.ts",
32
+ "**/*.spec.ts"
33
+ ]
34
+ }