@arcraz/common 1.0.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.
Files changed (174) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +373 -0
  3. package/dist/aws/bedrock/client-factory.d.ts +45 -0
  4. package/dist/aws/bedrock/client-factory.d.ts.map +1 -0
  5. package/dist/aws/bedrock/client-factory.js +113 -0
  6. package/dist/aws/bedrock/index.d.ts +3 -0
  7. package/dist/aws/bedrock/index.d.ts.map +1 -0
  8. package/dist/aws/bedrock/index.js +1 -0
  9. package/dist/aws/bedrock/types.d.ts +95 -0
  10. package/dist/aws/bedrock/types.d.ts.map +1 -0
  11. package/dist/aws/bedrock/types.js +1 -0
  12. package/dist/aws/cloudfront/index.d.ts +3 -0
  13. package/dist/aws/cloudfront/index.d.ts.map +1 -0
  14. package/dist/aws/cloudfront/index.js +1 -0
  15. package/dist/aws/cloudfront/signer-factory.d.ts +36 -0
  16. package/dist/aws/cloudfront/signer-factory.d.ts.map +1 -0
  17. package/dist/aws/cloudfront/signer-factory.js +75 -0
  18. package/dist/aws/cloudfront/types.d.ts +52 -0
  19. package/dist/aws/cloudfront/types.d.ts.map +1 -0
  20. package/dist/aws/cloudfront/types.js +1 -0
  21. package/dist/aws/s3/client-factory.d.ts +13 -0
  22. package/dist/aws/s3/client-factory.d.ts.map +1 -0
  23. package/dist/aws/s3/client-factory.js +25 -0
  24. package/dist/aws/s3/index.d.ts +4 -0
  25. package/dist/aws/s3/index.d.ts.map +1 -0
  26. package/dist/aws/s3/index.js +2 -0
  27. package/dist/aws/s3/operations.d.ts +106 -0
  28. package/dist/aws/s3/operations.d.ts.map +1 -0
  29. package/dist/aws/s3/operations.js +234 -0
  30. package/dist/aws/s3/types.d.ts +88 -0
  31. package/dist/aws/s3/types.d.ts.map +1 -0
  32. package/dist/aws/s3/types.js +1 -0
  33. package/dist/caches/api-cache.d.ts +40 -0
  34. package/dist/caches/api-cache.d.ts.map +1 -0
  35. package/dist/caches/api-cache.js +65 -0
  36. package/dist/caches/database-cache.d.ts +40 -0
  37. package/dist/caches/database-cache.d.ts.map +1 -0
  38. package/dist/caches/database-cache.js +65 -0
  39. package/dist/caches/index.d.ts +3 -0
  40. package/dist/caches/index.d.ts.map +1 -0
  41. package/dist/caches/index.js +2 -0
  42. package/dist/config/env-loader.d.ts +28 -0
  43. package/dist/config/env-loader.d.ts.map +1 -0
  44. package/dist/config/env-loader.js +39 -0
  45. package/dist/config/index.d.ts +5 -0
  46. package/dist/config/index.d.ts.map +1 -0
  47. package/dist/config/index.js +2 -0
  48. package/dist/config/schemas.d.ts +193 -0
  49. package/dist/config/schemas.d.ts.map +1 -0
  50. package/dist/config/schemas.js +92 -0
  51. package/dist/config/types.d.ts +23 -0
  52. package/dist/config/types.d.ts.map +1 -0
  53. package/dist/config/types.js +2 -0
  54. package/dist/constants/cache-durations.d.ts +29 -0
  55. package/dist/constants/cache-durations.d.ts.map +1 -0
  56. package/dist/constants/cache-durations.js +27 -0
  57. package/dist/constants/defaults.d.ts +50 -0
  58. package/dist/constants/defaults.d.ts.map +1 -0
  59. package/dist/constants/defaults.js +49 -0
  60. package/dist/constants/index.d.ts +4 -0
  61. package/dist/constants/index.d.ts.map +1 -0
  62. package/dist/constants/index.js +2 -0
  63. package/dist/database/base-repository.d.ts +45 -0
  64. package/dist/database/base-repository.d.ts.map +1 -0
  65. package/dist/database/base-repository.js +57 -0
  66. package/dist/database/helpers/converter-helper.d.ts +9 -0
  67. package/dist/database/helpers/converter-helper.d.ts.map +1 -0
  68. package/dist/database/helpers/converter-helper.js +20 -0
  69. package/dist/database/helpers/index.d.ts +3 -0
  70. package/dist/database/helpers/index.d.ts.map +1 -0
  71. package/dist/database/helpers/index.js +2 -0
  72. package/dist/database/helpers/paged-response-helper.d.ts +33 -0
  73. package/dist/database/helpers/paged-response-helper.d.ts.map +1 -0
  74. package/dist/database/helpers/paged-response-helper.js +64 -0
  75. package/dist/database/index.d.ts +6 -0
  76. package/dist/database/index.d.ts.map +1 -0
  77. package/dist/database/index.js +4 -0
  78. package/dist/database/pool-factory.d.ts +24 -0
  79. package/dist/database/pool-factory.d.ts.map +1 -0
  80. package/dist/database/pool-factory.js +91 -0
  81. package/dist/database/query-helpers.d.ts +36 -0
  82. package/dist/database/query-helpers.d.ts.map +1 -0
  83. package/dist/database/query-helpers.js +68 -0
  84. package/dist/database/types.d.ts +55 -0
  85. package/dist/database/types.d.ts.map +1 -0
  86. package/dist/database/types.js +1 -0
  87. package/dist/helpers/data-obscurer.d.ts +18 -0
  88. package/dist/helpers/data-obscurer.d.ts.map +1 -0
  89. package/dist/helpers/data-obscurer.js +29 -0
  90. package/dist/helpers/enum-converters.d.ts +27 -0
  91. package/dist/helpers/enum-converters.d.ts.map +1 -0
  92. package/dist/helpers/enum-converters.js +37 -0
  93. package/dist/helpers/index.d.ts +5 -0
  94. package/dist/helpers/index.d.ts.map +1 -0
  95. package/dist/helpers/index.js +3 -0
  96. package/dist/helpers/remove-sensitive-values.d.ts +20 -0
  97. package/dist/helpers/remove-sensitive-values.d.ts.map +1 -0
  98. package/dist/helpers/remove-sensitive-values.js +72 -0
  99. package/dist/index.d.ts +11 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +20 -0
  102. package/dist/logging/formatters.d.ts +19 -0
  103. package/dist/logging/formatters.d.ts.map +1 -0
  104. package/dist/logging/formatters.js +94 -0
  105. package/dist/logging/index.d.ts +4 -0
  106. package/dist/logging/index.d.ts.map +1 -0
  107. package/dist/logging/index.js +2 -0
  108. package/dist/logging/logger-factory.d.ts +8 -0
  109. package/dist/logging/logger-factory.d.ts.map +1 -0
  110. package/dist/logging/logger-factory.js +86 -0
  111. package/dist/logging/types.d.ts +52 -0
  112. package/dist/logging/types.d.ts.map +1 -0
  113. package/dist/logging/types.js +1 -0
  114. package/dist/rabbitmq/connection-factory.d.ts +8 -0
  115. package/dist/rabbitmq/connection-factory.d.ts.map +1 -0
  116. package/dist/rabbitmq/connection-factory.js +117 -0
  117. package/dist/rabbitmq/consumer.d.ts +44 -0
  118. package/dist/rabbitmq/consumer.d.ts.map +1 -0
  119. package/dist/rabbitmq/consumer.js +107 -0
  120. package/dist/rabbitmq/index.d.ts +6 -0
  121. package/dist/rabbitmq/index.d.ts.map +1 -0
  122. package/dist/rabbitmq/index.js +4 -0
  123. package/dist/rabbitmq/namespace-helpers.d.ts +33 -0
  124. package/dist/rabbitmq/namespace-helpers.d.ts.map +1 -0
  125. package/dist/rabbitmq/namespace-helpers.js +44 -0
  126. package/dist/rabbitmq/publisher.d.ts +27 -0
  127. package/dist/rabbitmq/publisher.d.ts.map +1 -0
  128. package/dist/rabbitmq/publisher.js +94 -0
  129. package/dist/rabbitmq/types.d.ts +94 -0
  130. package/dist/rabbitmq/types.d.ts.map +1 -0
  131. package/dist/rabbitmq/types.js +1 -0
  132. package/dist/redis/client-factory.d.ts +14 -0
  133. package/dist/redis/client-factory.d.ts.map +1 -0
  134. package/dist/redis/client-factory.js +98 -0
  135. package/dist/redis/index.d.ts +6 -0
  136. package/dist/redis/index.d.ts.map +1 -0
  137. package/dist/redis/index.js +4 -0
  138. package/dist/redis/namespace-helpers.d.ts +33 -0
  139. package/dist/redis/namespace-helpers.d.ts.map +1 -0
  140. package/dist/redis/namespace-helpers.js +43 -0
  141. package/dist/redis/operations/index.d.ts +3 -0
  142. package/dist/redis/operations/index.d.ts.map +1 -0
  143. package/dist/redis/operations/index.js +2 -0
  144. package/dist/redis/operations/list.d.ts +102 -0
  145. package/dist/redis/operations/list.d.ts.map +1 -0
  146. package/dist/redis/operations/list.js +136 -0
  147. package/dist/redis/operations/standard.d.ts +85 -0
  148. package/dist/redis/operations/standard.d.ts.map +1 -0
  149. package/dist/redis/operations/standard.js +136 -0
  150. package/dist/redis/types.d.ts +81 -0
  151. package/dist/redis/types.d.ts.map +1 -0
  152. package/dist/redis/types.js +8 -0
  153. package/dist/security/cors-factory.d.ts +28 -0
  154. package/dist/security/cors-factory.d.ts.map +1 -0
  155. package/dist/security/cors-factory.js +73 -0
  156. package/dist/security/helmet-factory.d.ts +14 -0
  157. package/dist/security/helmet-factory.d.ts.map +1 -0
  158. package/dist/security/helmet-factory.js +80 -0
  159. package/dist/security/index.d.ts +4 -0
  160. package/dist/security/index.d.ts.map +1 -0
  161. package/dist/security/index.js +2 -0
  162. package/dist/security/types.d.ts +103 -0
  163. package/dist/security/types.d.ts.map +1 -0
  164. package/dist/security/types.js +1 -0
  165. package/dist/types/custom-types.d.ts +102 -0
  166. package/dist/types/custom-types.d.ts.map +1 -0
  167. package/dist/types/custom-types.js +45 -0
  168. package/dist/types/enums.d.ts +26 -0
  169. package/dist/types/enums.d.ts.map +1 -0
  170. package/dist/types/enums.js +30 -0
  171. package/dist/types/index.d.ts +4 -0
  172. package/dist/types/index.d.ts.map +1 -0
  173. package/dist/types/index.js +2 -0
  174. package/package.json +154 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024-2026 Arcraz
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,373 @@
1
+ # @arcraz/common
2
+
3
+ A TypeScript utilities library for the arcraz ecosystem, providing shared functionality across microservices.
4
+
5
+ Complete overhaul with factory pattern, Zod validation, and ESM-only build.
6
+
7
+ ## Requirements
8
+
9
+ - **Node.js 24+** (ESM-only)
10
+ - Yarn package manager
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ yarn add @arcraz/common
16
+ ```
17
+
18
+ ## Features
19
+
20
+ - **Factory Pattern** - No singletons, full control over instances
21
+ - **Zod Config Validation** - Type-safe configuration with runtime validation
22
+ - **Subpath Exports** - Tree-shaking support for smaller bundles
23
+ - **Namespace Isolation** - Redis keys and RabbitMQ queues are automatically namespaced by `NODE_ENV`
24
+ - **Native Drivers** - Direct `pg` Pool and `amqplib` (no wrappers)
25
+
26
+ ## Quick Start
27
+
28
+ ### Configuration
29
+
30
+ ```typescript
31
+ import { loadEnv, getEnv, requireEnv } from '@arcraz/common/config';
32
+ import { DatabaseConfigSchema, RedisConfigSchema } from '@arcraz/common/config';
33
+
34
+ // Load .env file
35
+ loadEnv();
36
+
37
+ // Get environment variables
38
+ const nodeEnv = getEnv('NODE_ENV', 'development');
39
+ const dbHost = requireEnv('DATABASE_HOST'); // Throws if not set
40
+
41
+ // Validate configuration with Zod
42
+ const dbConfig = DatabaseConfigSchema.parse({
43
+ name: 'main',
44
+ host: process.env.DB_HOST,
45
+ port: parseInt(process.env.DB_PORT || '5432'),
46
+ database: process.env.DB_NAME,
47
+ user: process.env.DB_USER,
48
+ password: process.env.DB_PASSWORD,
49
+ });
50
+ ```
51
+
52
+ ### Database (PostgreSQL)
53
+
54
+ ```typescript
55
+ import { createDatabasePool } from '@arcraz/common/database';
56
+ import { BaseRepository, PagedResponseHelper, ConverterHelper } from '@arcraz/common/database';
57
+
58
+ // Create a connection pool
59
+ const pool = createDatabasePool({
60
+ name: 'main',
61
+ host: 'localhost',
62
+ port: 5432,
63
+ database: 'myapp',
64
+ user: 'api',
65
+ password: 'secret',
66
+ });
67
+
68
+ // Direct query
69
+ const result = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);
70
+
71
+ // Using BaseRepository
72
+ class UserRepository extends BaseRepository {
73
+ async getById(id: string) {
74
+ return this.queryOne<User>(
75
+ 'SELECT * FROM users WHERE id = $1',
76
+ [id]
77
+ );
78
+ }
79
+
80
+ async getPaged(page: number, pageSize: number) {
81
+ const pager = new PagedResponseHelper(page, pageSize);
82
+ const results = await this.query<User>(
83
+ `SELECT *, COUNT(*) OVER() as full_count
84
+ FROM users
85
+ LIMIT $1 OFFSET $2`,
86
+ [pager.limit, pager.offset]
87
+ );
88
+ return pager.result(results);
89
+ }
90
+ }
91
+
92
+ const userRepo = new UserRepository(pool);
93
+ const user = await userRepo.getById('123');
94
+
95
+ // Cleanup
96
+ await pool.end();
97
+ ```
98
+
99
+ ### Redis
100
+
101
+ ```typescript
102
+ import { createRedisClient, getNamespacedKey } from '@arcraz/common/redis';
103
+
104
+ // Create client
105
+ const redis = createRedisClient({
106
+ host: 'localhost',
107
+ port: 6379,
108
+ });
109
+
110
+ // Keys are automatically namespaced by NODE_ENV
111
+ // With NODE_ENV=production: "{production}:user:123"
112
+ const key = getNamespacedKey('user:123');
113
+
114
+ await redis.set(key, JSON.stringify({ name: 'John' }), 'EX', 3600);
115
+ const data = await redis.get(key);
116
+
117
+ // Cleanup
118
+ await redis.quit();
119
+ ```
120
+
121
+ ### RabbitMQ
122
+
123
+ ```typescript
124
+ import {
125
+ createRabbitMQConnection,
126
+ createPublisher,
127
+ createConsumer,
128
+ getNamespacedQueue
129
+ } from '@arcraz/common/rabbitmq';
130
+
131
+ // Create connection
132
+ const connection = await createRabbitMQConnection({
133
+ host: 'localhost',
134
+ port: 5672,
135
+ username: 'guest',
136
+ password: 'guest',
137
+ });
138
+
139
+ const channel = await connection.createChannel();
140
+
141
+ // Queues are namespaced by NODE_ENV
142
+ // With NODE_ENV=production: "production-my-queue"
143
+ const queueName = getNamespacedQueue('my-queue');
144
+
145
+ await channel.assertQueue(queueName, { durable: true });
146
+
147
+ // Publish messages
148
+ const publisher = createPublisher(channel);
149
+ await publisher.publish(queueName, { event: 'user.created', data: { id: '123' } });
150
+
151
+ // Consume messages
152
+ const consumer = createConsumer(channel);
153
+ await consumer.consume(queueName, async (message) => {
154
+ console.log('Received:', message);
155
+ // Return true to ack, false to nack
156
+ return true;
157
+ });
158
+
159
+ // Cleanup
160
+ await channel.close();
161
+ await connection.close();
162
+ ```
163
+
164
+ ### Caching
165
+
166
+ ```typescript
167
+ import { createRedisClient } from '@arcraz/common/redis';
168
+ import { ApiCache, DatabaseCache } from '@arcraz/common/caches';
169
+
170
+ const redis = createRedisClient({ host: 'localhost' });
171
+
172
+ // API Cache - for caching external API responses
173
+ const apiCache = new ApiCache(redis, 'weather', async (city: string) => {
174
+ const response = await fetch(`https://api.weather.com/${city}`);
175
+ return response.json();
176
+ }, 3600); // 1 hour TTL
177
+
178
+ const weather = await apiCache.getCached('new-york');
179
+
180
+ // Database Cache - for caching query results
181
+ const dbCache = new DatabaseCache(redis, 'users', async (id: string) => {
182
+ return userRepo.getById(id);
183
+ }, 300); // 5 minute TTL
184
+
185
+ const user = await dbCache.getCached('123');
186
+ await dbCache.deleteCached('123'); // Invalidate on update
187
+ ```
188
+
189
+ ### Logging
190
+
191
+ ```typescript
192
+ import { createLogger } from '@arcraz/common/logging';
193
+
194
+ const logger = createLogger({
195
+ level: 'info',
196
+ format: 'json', // 'json' | 'logfmt' | 'pretty'
197
+ service: 'my-service',
198
+ });
199
+
200
+ logger.info('Server started', { port: 3000 });
201
+ logger.error('Failed to connect', { error: err.message });
202
+ ```
203
+
204
+ ### Security (Express Middleware)
205
+
206
+ ```typescript
207
+ import { createHelmetConfig, createCorsConfig } from '@arcraz/common/security';
208
+ import express from 'express';
209
+ import helmet from 'helmet';
210
+ import cors from 'cors';
211
+
212
+ const app = express();
213
+
214
+ // Secure headers
215
+ app.use(helmet(createHelmetConfig()));
216
+
217
+ // CORS
218
+ app.use(cors(createCorsConfig({
219
+ origins: ['https://myapp.com'],
220
+ credentials: true,
221
+ })));
222
+ ```
223
+
224
+ ### Helpers
225
+
226
+ ```typescript
227
+ import {
228
+ dataObscurer,
229
+ removeSensitiveValues,
230
+ redactSensitiveValues,
231
+ convertToEnum,
232
+ isValidEnumValue
233
+ } from '@arcraz/common/helpers';
234
+
235
+ // Mask sensitive data
236
+ const masked = dataObscurer('4111111111111111', { showLeft: 4, showRight: 4 });
237
+ // "4111********1111"
238
+
239
+ // Remove sensitive fields
240
+ const clean = removeSensitiveValues(
241
+ { name: 'John', password: 'secret', ssn: '123-45-6789' },
242
+ ['password', 'ssn']
243
+ );
244
+ // { name: 'John' }
245
+
246
+ // Redact instead of remove
247
+ const redacted = redactSensitiveValues(
248
+ { name: 'John', password: 'secret' },
249
+ ['password']
250
+ );
251
+ // { name: 'John', password: '[REDACTED]' }
252
+
253
+ // Enum conversion
254
+ enum Status { Active = 'ACTIVE', Inactive = 'INACTIVE' }
255
+ const status = convertToEnum('ACTIVE', Status); // Status.Active
256
+ const isValid = isValidEnumValue('ACTIVE', Status); // true
257
+ ```
258
+
259
+ ### Types
260
+
261
+ ```typescript
262
+ import { Result, ok, err, isOk, isErr, unwrap, unwrapOr } from '@arcraz/common/types';
263
+
264
+ // Result type for error handling without exceptions
265
+ function divide(a: number, b: number): Result<number, string> {
266
+ if (b === 0) return err('Division by zero');
267
+ return ok(a / b);
268
+ }
269
+
270
+ const result = divide(10, 2);
271
+
272
+ if (isOk(result)) {
273
+ console.log('Result:', unwrap(result)); // 5
274
+ }
275
+
276
+ // Or with default value
277
+ const value = unwrapOr(divide(10, 0), 0); // 0
278
+ ```
279
+
280
+ ## Subpath Exports
281
+
282
+ Import only what you need for optimal tree-shaking:
283
+
284
+ ```typescript
285
+ import { ... } from '@arcraz/common'; // Everything
286
+ import { ... } from '@arcraz/common/config'; // Config & Zod schemas
287
+ import { ... } from '@arcraz/common/database'; // PostgreSQL
288
+ import { ... } from '@arcraz/common/redis'; // Redis
289
+ import { ... } from '@arcraz/common/rabbitmq'; // RabbitMQ
290
+ import { ... } from '@arcraz/common/caches'; // Caching utilities
291
+ import { ... } from '@arcraz/common/logging'; // Logger
292
+ import { ... } from '@arcraz/common/security'; // Helmet & CORS configs
293
+ import { ... } from '@arcraz/common/helpers'; // Utility functions
294
+ import { ... } from '@arcraz/common/types'; // TypeScript types & enums
295
+ import { ... } from '@arcraz/common/constants'; // Default values
296
+ ```
297
+
298
+ ## Namespace Isolation
299
+
300
+ Redis and RabbitMQ resources are automatically namespaced by `NODE_ENV` to prevent collisions in shared environments:
301
+
302
+ | Service | Pattern | Example (NODE_ENV=staging) |
303
+ |-----------|--------------------------|--------------------------------|
304
+ | Redis | `{NODE_ENV}:key` | `{staging}:user:123` |
305
+ | RabbitMQ | `NODE_ENV-queue` | `staging-notifications` |
306
+
307
+ ```typescript
308
+ // Redis - curly braces ensure cluster slot compatibility
309
+ getNamespacedKey('user:123'); // "{staging}:user:123"
310
+ stripNamespace('{staging}:user:123'); // "user:123"
311
+ extractNamespace('{staging}:user:123'); // "staging"
312
+
313
+ // RabbitMQ
314
+ getNamespacedQueue('notifications'); // "staging-notifications"
315
+ getNamespacedExchange('events'); // "staging-events"
316
+ stripQueueNamespace('staging-notifications'); // "notifications"
317
+ ```
318
+
319
+ ## Development
320
+
321
+ ### Scripts
322
+
323
+ ```bash
324
+ yarn install # Install dependencies
325
+ yarn lint # Run ESLint
326
+ yarn test # Run Vitest tests
327
+ yarn build # Build to dist/
328
+ ```
329
+
330
+ ### Testing
331
+
332
+ Tests use Vitest and are located in `__tests__/`:
333
+
334
+ ```bash
335
+ yarn test # Run all tests
336
+ yarn test:watch # Watch mode
337
+ yarn test:coverage # With coverage report
338
+ ```
339
+
340
+ ## Migration from v1.x
341
+
342
+ ### Breaking Changes
343
+
344
+ 1. **No more singletons** - Use factory functions:
345
+ ```typescript
346
+ // Before (v1.x)
347
+ import { Services } from '@arcraz/common';
348
+ const { mainDb } = Services.Postgres;
349
+
350
+ // After (v2.x)
351
+ import { createDatabasePool } from '@arcraz/common/database';
352
+ const pool = createDatabasePool(config);
353
+ ```
354
+
355
+ 2. **No more YAML config** - Use Zod schemas with environment variables:
356
+ ```typescript
357
+ // Before (v1.x)
358
+ // config/default.yaml
359
+
360
+ // After (v2.x)
361
+ import { DatabaseConfigSchema } from '@arcraz/common/config';
362
+ const config = DatabaseConfigSchema.parse({ ... });
363
+ ```
364
+
365
+ 3. **ESM-only** - No more CommonJS support. Requires Node.js 24+.
366
+
367
+ 4. **Removed modules**:
368
+ - `Extensions` - `String.prototype.replaceAll` is now native
369
+ - `Services` - Replaced by factory functions
370
+
371
+ ## License
372
+
373
+ Apache-2.0 - See [LICENSE](LICENSE) for details.
@@ -0,0 +1,45 @@
1
+ import type { BedrockClientConfig, BedrockInstance, ClaudeMessage, ClaudeInvokeOptions, ClaudeResponse, EmbeddingOptions, EmbeddingResponse } from './types.js';
2
+ /**
3
+ * Creates a Bedrock client instance
4
+ * @param config Bedrock client configuration
5
+ * @returns Bedrock instance
6
+ */
7
+ export declare function createBedrockClient(config: BedrockClientConfig): BedrockInstance;
8
+ /**
9
+ * Closes a Bedrock client connection
10
+ * @param bedrock Bedrock instance to close
11
+ */
12
+ export declare function closeBedrockClient(bedrock: BedrockInstance): void;
13
+ /**
14
+ * Invokes Claude model with messages
15
+ * @param bedrock Bedrock instance
16
+ * @param messages Conversation messages
17
+ * @param options Invoke options
18
+ * @returns Claude response
19
+ */
20
+ export declare function invokeClaude(bedrock: BedrockInstance, messages: ClaudeMessage[], options?: ClaudeInvokeOptions): Promise<ClaudeResponse>;
21
+ /**
22
+ * Simple text completion with Claude
23
+ * @param bedrock Bedrock instance
24
+ * @param prompt User prompt
25
+ * @param options Invoke options
26
+ * @returns Generated text
27
+ */
28
+ export declare function complete(bedrock: BedrockInstance, prompt: string, options?: ClaudeInvokeOptions): Promise<string>;
29
+ /**
30
+ * Generates embeddings using Titan Embeddings
31
+ * @param bedrock Bedrock instance
32
+ * @param text Text to embed
33
+ * @param options Embedding options
34
+ * @returns Embedding response
35
+ */
36
+ export declare function generateEmbedding(bedrock: BedrockInstance, text: string, options?: EmbeddingOptions): Promise<EmbeddingResponse>;
37
+ /**
38
+ * Generates embeddings for multiple texts
39
+ * @param bedrock Bedrock instance
40
+ * @param texts Texts to embed
41
+ * @param options Embedding options
42
+ * @returns Array of embedding responses
43
+ */
44
+ export declare function generateEmbeddings(bedrock: BedrockInstance, texts: string[], options?: EmbeddingOptions): Promise<EmbeddingResponse[]>;
45
+ //# sourceMappingURL=client-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-factory.d.ts","sourceRoot":"","sources":["../../../src/aws/bedrock/client-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEhK;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,eAAe,CAUhF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAEjE;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC,CA4ClJ;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3H;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqB1I;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAEhJ"}