@exyconn/common 2.1.0 → 2.3.3

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 (142) hide show
  1. package/README.md +969 -261
  2. package/dist/client/hooks/index.d.mts +1042 -0
  3. package/dist/client/hooks/index.d.ts +1042 -0
  4. package/dist/client/hooks/index.js +2276 -0
  5. package/dist/client/hooks/index.js.map +1 -0
  6. package/dist/client/hooks/index.mjs +2217 -0
  7. package/dist/client/hooks/index.mjs.map +1 -0
  8. package/dist/client/http/index.d.mts +217 -49
  9. package/dist/client/http/index.d.ts +217 -49
  10. package/dist/client/http/index.js +473 -94
  11. package/dist/client/http/index.js.map +1 -1
  12. package/dist/client/http/index.mjs +441 -84
  13. package/dist/client/http/index.mjs.map +1 -1
  14. package/dist/client/index.d.mts +6 -4
  15. package/dist/client/index.d.ts +6 -4
  16. package/dist/client/index.js +481 -319
  17. package/dist/client/index.js.map +1 -1
  18. package/dist/client/index.mjs +449 -290
  19. package/dist/client/index.mjs.map +1 -1
  20. package/dist/client/utils/index.d.mts +3 -279
  21. package/dist/client/utils/index.d.ts +3 -279
  22. package/dist/client/web/index.d.mts +1461 -0
  23. package/dist/client/web/index.d.ts +1461 -0
  24. package/dist/client/web/index.js +2681 -0
  25. package/dist/client/web/index.js.map +1 -0
  26. package/dist/client/web/index.mjs +2618 -0
  27. package/dist/client/web/index.mjs.map +1 -0
  28. package/dist/data/brand-identity.d.mts +149 -0
  29. package/dist/data/brand-identity.d.ts +149 -0
  30. package/dist/data/brand-identity.js +235 -0
  31. package/dist/data/brand-identity.js.map +1 -0
  32. package/dist/data/brand-identity.mjs +220 -0
  33. package/dist/data/brand-identity.mjs.map +1 -0
  34. package/dist/data/countries.d.mts +61 -0
  35. package/dist/data/countries.d.ts +61 -0
  36. package/dist/data/countries.js +987 -0
  37. package/dist/data/countries.js.map +1 -0
  38. package/dist/data/countries.mjs +971 -0
  39. package/dist/data/countries.mjs.map +1 -0
  40. package/dist/data/currencies.d.mts +19 -0
  41. package/dist/data/currencies.d.ts +19 -0
  42. package/dist/data/currencies.js +162 -0
  43. package/dist/data/currencies.js.map +1 -0
  44. package/dist/data/currencies.mjs +153 -0
  45. package/dist/data/currencies.mjs.map +1 -0
  46. package/dist/data/index.d.mts +7 -0
  47. package/dist/data/index.d.ts +7 -0
  48. package/dist/data/index.js +2087 -0
  49. package/dist/data/index.js.map +1 -0
  50. package/dist/data/index.mjs +1948 -0
  51. package/dist/data/index.mjs.map +1 -0
  52. package/dist/data/phone-codes.d.mts +15 -0
  53. package/dist/data/phone-codes.d.ts +15 -0
  54. package/dist/data/phone-codes.js +219 -0
  55. package/dist/data/phone-codes.js.map +1 -0
  56. package/dist/data/phone-codes.mjs +211 -0
  57. package/dist/data/phone-codes.mjs.map +1 -0
  58. package/dist/data/regex.d.mts +287 -0
  59. package/dist/data/regex.d.ts +287 -0
  60. package/dist/data/regex.js +306 -0
  61. package/dist/data/regex.js.map +1 -0
  62. package/dist/data/regex.mjs +208 -0
  63. package/dist/data/regex.mjs.map +1 -0
  64. package/dist/data/timezones.d.mts +16 -0
  65. package/dist/data/timezones.d.ts +16 -0
  66. package/dist/data/timezones.js +98 -0
  67. package/dist/data/timezones.js.map +1 -0
  68. package/dist/data/timezones.mjs +89 -0
  69. package/dist/data/timezones.mjs.map +1 -0
  70. package/dist/index-BZf42T3R.d.mts +305 -0
  71. package/dist/index-CF0D8PGE.d.ts +305 -0
  72. package/dist/index-Ckhm_HaX.d.mts +138 -0
  73. package/dist/index-DKn4raO7.d.ts +222 -0
  74. package/dist/index-NS8dS0p9.d.mts +222 -0
  75. package/dist/index-Nqm5_lwT.d.ts +188 -0
  76. package/dist/index-br6POSyA.d.ts +138 -0
  77. package/dist/index-jBi3V6e5.d.mts +188 -0
  78. package/dist/index.d.mts +21 -580
  79. package/dist/index.d.ts +21 -580
  80. package/dist/index.js +1839 -347
  81. package/dist/index.js.map +1 -1
  82. package/dist/index.mjs +1850 -359
  83. package/dist/index.mjs.map +1 -1
  84. package/dist/packageCheck-B_qfsD6R.d.ts +280 -0
  85. package/dist/packageCheck-C2_FT_Rl.d.mts +280 -0
  86. package/dist/server/configs/index.d.mts +602 -0
  87. package/dist/server/configs/index.d.ts +602 -0
  88. package/dist/server/configs/index.js +707 -0
  89. package/dist/server/configs/index.js.map +1 -0
  90. package/dist/server/configs/index.mjs +665 -0
  91. package/dist/server/configs/index.mjs.map +1 -0
  92. package/dist/server/index.d.mts +4 -1
  93. package/dist/server/index.d.ts +4 -1
  94. package/dist/server/index.js +1330 -0
  95. package/dist/server/index.js.map +1 -1
  96. package/dist/server/index.mjs +1286 -2
  97. package/dist/server/index.mjs.map +1 -1
  98. package/dist/server/middleware/index.d.mts +283 -2
  99. package/dist/server/middleware/index.d.ts +283 -2
  100. package/dist/server/middleware/index.js +761 -0
  101. package/dist/server/middleware/index.js.map +1 -1
  102. package/dist/server/middleware/index.mjs +751 -1
  103. package/dist/server/middleware/index.mjs.map +1 -1
  104. package/dist/shared/config/index.d.mts +40 -0
  105. package/dist/shared/config/index.d.ts +40 -0
  106. package/dist/shared/config/index.js +58 -0
  107. package/dist/shared/config/index.js.map +1 -0
  108. package/dist/shared/config/index.mjs +51 -0
  109. package/dist/shared/config/index.mjs.map +1 -0
  110. package/dist/shared/constants/index.d.mts +593 -0
  111. package/dist/shared/constants/index.d.ts +593 -0
  112. package/dist/shared/constants/index.js +391 -0
  113. package/dist/shared/constants/index.js.map +1 -0
  114. package/dist/shared/constants/index.mjs +360 -0
  115. package/dist/shared/constants/index.mjs.map +1 -0
  116. package/dist/shared/index.d.mts +5 -1
  117. package/dist/shared/index.d.ts +5 -1
  118. package/dist/shared/types/index.d.mts +140 -0
  119. package/dist/shared/types/index.d.ts +140 -0
  120. package/dist/shared/types/index.js +4 -0
  121. package/dist/shared/types/index.js.map +1 -0
  122. package/dist/shared/types/index.mjs +3 -0
  123. package/dist/shared/types/index.mjs.map +1 -0
  124. package/dist/shared/utils/index.d.mts +255 -0
  125. package/dist/shared/utils/index.d.ts +255 -0
  126. package/dist/shared/utils/index.js +623 -0
  127. package/dist/shared/utils/index.js.map +1 -0
  128. package/dist/shared/utils/index.mjs +324 -0
  129. package/dist/shared/utils/index.mjs.map +1 -0
  130. package/dist/shared/validation/index.d.mts +258 -0
  131. package/dist/shared/validation/index.d.ts +258 -0
  132. package/dist/shared/validation/index.js +185 -0
  133. package/dist/shared/validation/index.js.map +1 -0
  134. package/dist/shared/validation/index.mjs +172 -0
  135. package/dist/shared/validation/index.mjs.map +1 -0
  136. package/package.json +127 -62
  137. package/dist/index-BcxL4_V4.d.ts +0 -2946
  138. package/dist/index-DEzgM15j.d.ts +0 -67
  139. package/dist/index-DNFVgQx8.d.ts +0 -1375
  140. package/dist/index-DbV04Dx8.d.mts +0 -67
  141. package/dist/index-DfqEP6Oe.d.mts +0 -1375
  142. package/dist/index-bvvCev9Q.d.mts +0 -2946
@@ -0,0 +1,665 @@
1
+ import rateLimit from 'express-rate-limit';
2
+
3
+ // src/server/configs/cors.config.ts
4
+ var DEFAULT_CORS_CONFIG = {
5
+ productionOrigins: [],
6
+ developmentOrigins: [
7
+ "http://localhost:3000",
8
+ "http://localhost:4000",
9
+ "http://localhost:5000",
10
+ "http://localhost:5173",
11
+ "http://localhost:8080",
12
+ "http://127.0.0.1:3000",
13
+ "http://127.0.0.1:4000",
14
+ "http://127.0.0.1:5000",
15
+ "http://127.0.0.1:5173",
16
+ "http://127.0.0.1:8080"
17
+ ],
18
+ allowedSubdomains: [],
19
+ originPatterns: [],
20
+ allowNoOrigin: true,
21
+ allowAllInDev: true,
22
+ credentials: true,
23
+ methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"],
24
+ allowedHeaders: [
25
+ "Content-Type",
26
+ "Authorization",
27
+ "X-Requested-With",
28
+ "Accept",
29
+ "Origin",
30
+ "X-API-Key",
31
+ "X-Organization-Id",
32
+ "X-Request-Id"
33
+ ],
34
+ exposedHeaders: [
35
+ "Content-Range",
36
+ "X-Content-Range",
37
+ "X-Total-Count",
38
+ "X-Request-Id"
39
+ ],
40
+ maxAge: 86400
41
+ // 24 hours
42
+ };
43
+ var createCorsOptions = (config = {}) => {
44
+ const finalConfig = { ...DEFAULT_CORS_CONFIG, ...config };
45
+ const {
46
+ productionOrigins,
47
+ developmentOrigins,
48
+ allowedSubdomains,
49
+ originPatterns,
50
+ allowNoOrigin,
51
+ allowAllInDev,
52
+ customValidator,
53
+ credentials,
54
+ methods,
55
+ allowedHeaders,
56
+ exposedHeaders,
57
+ maxAge
58
+ } = finalConfig;
59
+ const allOrigins = /* @__PURE__ */ new Set([...productionOrigins, ...developmentOrigins]);
60
+ const originHandler = (origin, callback) => {
61
+ if (!origin) {
62
+ callback(null, allowNoOrigin);
63
+ return;
64
+ }
65
+ if (allOrigins.has(origin)) {
66
+ callback(null, true);
67
+ return;
68
+ }
69
+ if (allowedSubdomains.some((subdomain) => origin.endsWith(subdomain))) {
70
+ callback(null, true);
71
+ return;
72
+ }
73
+ if (originPatterns.some((pattern) => pattern.test(origin))) {
74
+ callback(null, true);
75
+ return;
76
+ }
77
+ if (customValidator && customValidator(origin)) {
78
+ callback(null, true);
79
+ return;
80
+ }
81
+ if (process.env.NODE_ENV !== "production" && allowAllInDev) {
82
+ callback(null, true);
83
+ return;
84
+ }
85
+ if (process.env.NODE_ENV === "production") {
86
+ callback(new Error(`Origin ${origin} not allowed by CORS`));
87
+ return;
88
+ }
89
+ callback(null, true);
90
+ };
91
+ return {
92
+ origin: originHandler,
93
+ credentials,
94
+ methods,
95
+ allowedHeaders,
96
+ exposedHeaders,
97
+ maxAge
98
+ };
99
+ };
100
+ var createBrandCorsOptions = (brandDomain, additionalConfig = {}) => {
101
+ const productionOrigins = [
102
+ `https://${brandDomain}`,
103
+ `https://www.${brandDomain}`
104
+ ];
105
+ const allowedSubdomains = [`.${brandDomain}`];
106
+ return createCorsOptions({
107
+ productionOrigins,
108
+ allowedSubdomains,
109
+ ...additionalConfig
110
+ });
111
+ };
112
+ var createMultiBrandCorsOptions = (domains, additionalConfig = {}) => {
113
+ const productionOrigins = domains.flatMap((domain) => [
114
+ `https://${domain}`,
115
+ `https://www.${domain}`
116
+ ]);
117
+ const allowedSubdomains = domains.map((domain) => `.${domain}`);
118
+ return createCorsOptions({
119
+ productionOrigins,
120
+ allowedSubdomains,
121
+ ...additionalConfig
122
+ });
123
+ };
124
+ var EXYCONN_CORS_CONFIG = {
125
+ productionOrigins: [
126
+ "https://exyconn.com",
127
+ "https://www.exyconn.com",
128
+ "https://botify.life",
129
+ "https://www.botify.life",
130
+ "https://partywings.fun",
131
+ "https://www.partywings.fun",
132
+ "https://sibera.work",
133
+ "https://www.sibera.work",
134
+ "https://spentiva.com",
135
+ "https://www.spentiva.com"
136
+ ],
137
+ allowedSubdomains: [
138
+ ".exyconn.com",
139
+ ".botify.life",
140
+ ".partywings.fun",
141
+ ".sibera.work",
142
+ ".spentiva.com"
143
+ ],
144
+ developmentOrigins: [
145
+ "http://localhost:3000",
146
+ "http://localhost:4000",
147
+ "http://localhost:4001",
148
+ "http://localhost:4002",
149
+ "http://localhost:4003",
150
+ "http://localhost:4004",
151
+ "http://localhost:4005",
152
+ "http://localhost:5173",
153
+ "http://127.0.0.1:3000",
154
+ "http://127.0.0.1:4000",
155
+ "http://127.0.0.1:5173"
156
+ ]
157
+ };
158
+ var STRICT_CORS_CONFIG = {
159
+ allowNoOrigin: false,
160
+ allowAllInDev: false,
161
+ methods: ["GET", "POST", "PUT", "DELETE"]
162
+ };
163
+ var PERMISSIVE_CORS_CONFIG = {
164
+ allowNoOrigin: true,
165
+ allowAllInDev: true,
166
+ originPatterns: [/localhost/, /127\.0\.0\.1/]
167
+ };
168
+ var corsOptions = createCorsOptions(EXYCONN_CORS_CONFIG);
169
+ var DEFAULT_RATE_LIMIT_TIERS = {
170
+ STANDARD: {
171
+ windowMs: 15 * 60 * 1e3,
172
+ // 15 minutes
173
+ maxRequests: 100,
174
+ message: "Too many requests, please try again later.",
175
+ skipSuccessfulRequests: false,
176
+ skipFailedRequests: false
177
+ },
178
+ STRICT: {
179
+ windowMs: 15 * 60 * 1e3,
180
+ // 15 minutes
181
+ maxRequests: 20,
182
+ message: "Too many requests, please try again later.",
183
+ skipSuccessfulRequests: false,
184
+ skipFailedRequests: false
185
+ },
186
+ DDOS: {
187
+ windowMs: 60 * 1e3,
188
+ // 1 minute
189
+ maxRequests: 60,
190
+ message: "Rate limit exceeded. Please slow down.",
191
+ skipSuccessfulRequests: false,
192
+ skipFailedRequests: false
193
+ },
194
+ // Additional presets
195
+ VERY_STRICT: {
196
+ windowMs: 60 * 60 * 1e3,
197
+ // 1 hour
198
+ maxRequests: 5,
199
+ message: "Too many attempts. Please try again in an hour.",
200
+ skipSuccessfulRequests: false,
201
+ skipFailedRequests: false
202
+ },
203
+ RELAXED: {
204
+ windowMs: 15 * 60 * 1e3,
205
+ // 15 minutes
206
+ maxRequests: 500,
207
+ message: "Rate limit exceeded.",
208
+ skipSuccessfulRequests: false,
209
+ skipFailedRequests: false
210
+ },
211
+ API: {
212
+ windowMs: 60 * 1e3,
213
+ // 1 minute
214
+ maxRequests: 30,
215
+ message: "API rate limit exceeded.",
216
+ skipSuccessfulRequests: false,
217
+ skipFailedRequests: false
218
+ }
219
+ };
220
+ var defaultKeyGenerator = (req) => {
221
+ const forwarded = req.headers["x-forwarded-for"];
222
+ const ip = forwarded ? Array.isArray(forwarded) ? forwarded[0] : forwarded.split(",")[0].trim() : req.ip || req.socket.remoteAddress || "unknown";
223
+ return ip;
224
+ };
225
+ var createPrefixedKeyGenerator = (prefix) => (req) => {
226
+ return `${prefix}:${defaultKeyGenerator(req)}`;
227
+ };
228
+ var createUserKeyGenerator = (getUserId) => (req) => {
229
+ const userId = getUserId(req);
230
+ return userId || defaultKeyGenerator(req);
231
+ };
232
+ var createApiKeyGenerator = (headerName = "x-api-key") => (req) => {
233
+ const apiKey = req.headers[headerName.toLowerCase()];
234
+ return apiKey || defaultKeyGenerator(req);
235
+ };
236
+ var createRateLimitResponse = (message, retryAfter) => ({
237
+ status: "error",
238
+ statusCode: 429,
239
+ message,
240
+ ...retryAfter
241
+ });
242
+ var createRateLimiter = (tierConfig, options = {}) => {
243
+ const {
244
+ standardHeaders = true,
245
+ legacyHeaders = false,
246
+ keyGenerator = defaultKeyGenerator,
247
+ skip,
248
+ handler
249
+ } = options;
250
+ return rateLimit({
251
+ windowMs: tierConfig.windowMs,
252
+ max: tierConfig.maxRequests,
253
+ message: createRateLimitResponse(tierConfig.message),
254
+ standardHeaders,
255
+ legacyHeaders,
256
+ keyGenerator,
257
+ skip,
258
+ handler,
259
+ skipSuccessfulRequests: tierConfig.skipSuccessfulRequests,
260
+ skipFailedRequests: tierConfig.skipFailedRequests
261
+ });
262
+ };
263
+ var createStandardRateLimiter = (config = {}, options = {}) => {
264
+ const tierConfig = { ...DEFAULT_RATE_LIMIT_TIERS.STANDARD, ...config };
265
+ return createRateLimiter(tierConfig, options);
266
+ };
267
+ var createStrictRateLimiter = (config = {}, options = {}) => {
268
+ const tierConfig = { ...DEFAULT_RATE_LIMIT_TIERS.STRICT, ...config };
269
+ return createRateLimiter(tierConfig, options);
270
+ };
271
+ var createDdosRateLimiter = (config = {}, options = {}) => {
272
+ const tierConfig = { ...DEFAULT_RATE_LIMIT_TIERS.DDOS, ...config };
273
+ return createRateLimiter(tierConfig, options);
274
+ };
275
+ var createApiRateLimiter = (config = {}, options = {}) => {
276
+ const tierConfig = { ...DEFAULT_RATE_LIMIT_TIERS.API, ...config };
277
+ return createRateLimiter(tierConfig, {
278
+ keyGenerator: createApiKeyGenerator(),
279
+ ...options
280
+ });
281
+ };
282
+ var RateLimiterBuilder = class {
283
+ constructor(preset = "STANDARD") {
284
+ const presetConfig = DEFAULT_RATE_LIMIT_TIERS[preset];
285
+ this.config = {
286
+ windowMs: presetConfig.windowMs,
287
+ maxRequests: presetConfig.maxRequests,
288
+ message: presetConfig.message,
289
+ skipSuccessfulRequests: presetConfig.skipSuccessfulRequests ?? false,
290
+ skipFailedRequests: presetConfig.skipFailedRequests ?? false
291
+ };
292
+ this.options = {};
293
+ }
294
+ /**
295
+ * Set window duration
296
+ */
297
+ windowMs(ms) {
298
+ this.config.windowMs = ms;
299
+ return this;
300
+ }
301
+ /**
302
+ * Set window duration in minutes
303
+ */
304
+ windowMinutes(minutes) {
305
+ this.config.windowMs = minutes * 60 * 1e3;
306
+ return this;
307
+ }
308
+ /**
309
+ * Set window duration in hours
310
+ */
311
+ windowHours(hours) {
312
+ this.config.windowMs = hours * 60 * 60 * 1e3;
313
+ return this;
314
+ }
315
+ /**
316
+ * Set maximum requests
317
+ */
318
+ max(requests) {
319
+ this.config.maxRequests = requests;
320
+ return this;
321
+ }
322
+ /**
323
+ * Set error message
324
+ */
325
+ message(msg) {
326
+ this.config.message = msg;
327
+ return this;
328
+ }
329
+ /**
330
+ * Skip successful requests
331
+ */
332
+ skipSuccessful(skip = true) {
333
+ this.config.skipSuccessfulRequests = skip;
334
+ return this;
335
+ }
336
+ /**
337
+ * Skip failed requests
338
+ */
339
+ skipFailed(skip = true) {
340
+ this.config.skipFailedRequests = skip;
341
+ return this;
342
+ }
343
+ /**
344
+ * Set key generator
345
+ */
346
+ keyBy(generator) {
347
+ this.options.keyGenerator = generator;
348
+ return this;
349
+ }
350
+ /**
351
+ * Key by IP (default)
352
+ */
353
+ keyByIp() {
354
+ this.options.keyGenerator = defaultKeyGenerator;
355
+ return this;
356
+ }
357
+ /**
358
+ * Key by API key
359
+ */
360
+ keyByApiKey(headerName) {
361
+ this.options.keyGenerator = createApiKeyGenerator(headerName);
362
+ return this;
363
+ }
364
+ /**
365
+ * Skip certain requests
366
+ */
367
+ skipWhen(predicate) {
368
+ this.options.skip = predicate;
369
+ return this;
370
+ }
371
+ /**
372
+ * Build the rate limiter
373
+ */
374
+ build() {
375
+ return createRateLimiter(this.config, this.options);
376
+ }
377
+ };
378
+ var rateLimiter = (preset) => {
379
+ return new RateLimiterBuilder(preset);
380
+ };
381
+ var RATE_LIMIT_CONFIG = {
382
+ STANDARD: DEFAULT_RATE_LIMIT_TIERS.STANDARD,
383
+ STRICT: DEFAULT_RATE_LIMIT_TIERS.STRICT,
384
+ DDOS: DEFAULT_RATE_LIMIT_TIERS.DDOS
385
+ };
386
+ var standardRateLimiter = createStandardRateLimiter();
387
+ var strictRateLimiter = createStrictRateLimiter();
388
+ var ddosProtectionLimiter = createDdosRateLimiter();
389
+
390
+ // src/server/configs/server.config.ts
391
+ var DEFAULT_SERVER_CONFIG = {
392
+ name: "app-server",
393
+ version: "1.0.0",
394
+ environment: process.env.NODE_ENV || "development",
395
+ port: parseInt(process.env.PORT || "3000", 10),
396
+ host: process.env.HOST || "0.0.0.0",
397
+ basePath: "/api",
398
+ debug: process.env.DEBUG === "true",
399
+ trustProxy: true
400
+ };
401
+ var DEFAULT_DATABASE_CONFIG = {
402
+ uri: process.env.DATABASE_URL || process.env.MONGODB_URI || "",
403
+ name: process.env.DATABASE_NAME || "app_db",
404
+ maxPoolSize: process.env.NODE_ENV === "production" ? 50 : 10,
405
+ minPoolSize: process.env.NODE_ENV === "production" ? 10 : 5,
406
+ socketTimeoutMS: 45e3,
407
+ serverSelectionTimeoutMS: 1e4,
408
+ maxIdleTimeMS: 1e4,
409
+ retryWrites: true,
410
+ retryReads: true,
411
+ writeConcern: "majority"
412
+ };
413
+ var DEFAULT_AUTH_CONFIG = {
414
+ jwtSecret: process.env.JWT_SECRET || "",
415
+ jwtExpiresIn: process.env.JWT_EXPIRES_IN || "7d",
416
+ refreshTokenExpiresIn: process.env.REFRESH_TOKEN_EXPIRES_IN || "30d",
417
+ enableRefreshTokens: true,
418
+ apiKeyHeader: "x-api-key",
419
+ orgHeader: "x-organization-id"
420
+ };
421
+ var DEFAULT_LOGGING_CONFIG = {
422
+ level: process.env.LOG_LEVEL || "info",
423
+ logsDir: process.env.LOGS_DIR || "logs",
424
+ maxSize: "20m",
425
+ maxFiles: "14d",
426
+ errorMaxFiles: "30d",
427
+ console: true,
428
+ file: process.env.NODE_ENV === "production",
429
+ json: process.env.NODE_ENV === "production"
430
+ };
431
+ var DEFAULT_CORS_ORIGINS = {
432
+ production: [],
433
+ development: [
434
+ "http://localhost:3000",
435
+ "http://localhost:4000",
436
+ "http://localhost:5173",
437
+ "http://127.0.0.1:3000",
438
+ "http://127.0.0.1:4000",
439
+ "http://127.0.0.1:5173"
440
+ ],
441
+ patterns: []
442
+ };
443
+ var DEFAULT_RATE_LIMIT_CONFIG = {
444
+ enabled: true,
445
+ standard: {
446
+ windowMs: 15 * 60 * 1e3,
447
+ // 15 minutes
448
+ maxRequests: 100,
449
+ message: "Too many requests, please try again later."
450
+ },
451
+ strict: {
452
+ windowMs: 15 * 60 * 1e3,
453
+ // 15 minutes
454
+ maxRequests: 20,
455
+ message: "Too many requests, please try again later."
456
+ },
457
+ ddos: {
458
+ windowMs: 60 * 1e3,
459
+ // 1 minute
460
+ maxRequests: 60,
461
+ message: "Rate limit exceeded. Please slow down.",
462
+ skipSuccessfulRequests: false
463
+ }
464
+ };
465
+ function deepMerge(target, source) {
466
+ const result = { ...target };
467
+ for (const key in source) {
468
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
469
+ const sourceValue = source[key];
470
+ const targetValue = target[key];
471
+ if (sourceValue !== void 0 && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
472
+ result[key] = deepMerge(
473
+ targetValue,
474
+ sourceValue
475
+ );
476
+ } else if (sourceValue !== void 0) {
477
+ result[key] = sourceValue;
478
+ }
479
+ }
480
+ }
481
+ return result;
482
+ }
483
+ var ConfigBuilder = class {
484
+ constructor() {
485
+ this.config = {
486
+ server: { ...DEFAULT_SERVER_CONFIG },
487
+ database: { ...DEFAULT_DATABASE_CONFIG },
488
+ auth: { ...DEFAULT_AUTH_CONFIG },
489
+ logging: { ...DEFAULT_LOGGING_CONFIG },
490
+ cors: { ...DEFAULT_CORS_ORIGINS },
491
+ rateLimit: { ...DEFAULT_RATE_LIMIT_CONFIG }
492
+ };
493
+ }
494
+ /**
495
+ * Set server configuration
496
+ */
497
+ setServer(config) {
498
+ this.config.server = deepMerge(this.config.server, config);
499
+ return this;
500
+ }
501
+ /**
502
+ * Set database configuration
503
+ */
504
+ setDatabase(config) {
505
+ this.config.database = deepMerge(this.config.database, config);
506
+ return this;
507
+ }
508
+ /**
509
+ * Set auth configuration
510
+ */
511
+ setAuth(config) {
512
+ this.config.auth = deepMerge(this.config.auth, config);
513
+ return this;
514
+ }
515
+ /**
516
+ * Set logging configuration
517
+ */
518
+ setLogging(config) {
519
+ this.config.logging = deepMerge(this.config.logging, config);
520
+ return this;
521
+ }
522
+ /**
523
+ * Set CORS origins
524
+ */
525
+ setCorsOrigins(config) {
526
+ this.config.cors = deepMerge(this.config.cors, config);
527
+ return this;
528
+ }
529
+ /**
530
+ * Add CORS production origin
531
+ */
532
+ addProductionOrigin(origin) {
533
+ if (!this.config.cors.production.includes(origin)) {
534
+ this.config.cors.production.push(origin);
535
+ }
536
+ return this;
537
+ }
538
+ /**
539
+ * Add CORS development origin
540
+ */
541
+ addDevelopmentOrigin(origin) {
542
+ if (!this.config.cors.development.includes(origin)) {
543
+ this.config.cors.development.push(origin);
544
+ }
545
+ return this;
546
+ }
547
+ /**
548
+ * Add CORS pattern
549
+ */
550
+ addCorsPattern(pattern) {
551
+ if (!this.config.cors.patterns.includes(pattern)) {
552
+ this.config.cors.patterns.push(pattern);
553
+ }
554
+ return this;
555
+ }
556
+ /**
557
+ * Set rate limit configuration
558
+ */
559
+ setRateLimit(config) {
560
+ this.config.rateLimit = deepMerge(this.config.rateLimit, config);
561
+ return this;
562
+ }
563
+ /**
564
+ * Add custom rate limit tier
565
+ */
566
+ addRateLimitTier(name, tier) {
567
+ if (!this.config.rateLimit.custom) {
568
+ this.config.rateLimit.custom = {};
569
+ }
570
+ this.config.rateLimit.custom[name] = tier;
571
+ return this;
572
+ }
573
+ /**
574
+ * Set custom configuration
575
+ */
576
+ setCustom(key, value) {
577
+ if (!this.config.custom) {
578
+ this.config.custom = {};
579
+ }
580
+ this.config.custom[key] = value;
581
+ return this;
582
+ }
583
+ /**
584
+ * Load configuration from environment variables
585
+ */
586
+ loadFromEnv() {
587
+ if (process.env.SERVER_NAME) this.config.server.name = process.env.SERVER_NAME;
588
+ if (process.env.SERVER_VERSION) this.config.server.version = process.env.SERVER_VERSION;
589
+ if (process.env.PORT) this.config.server.port = parseInt(process.env.PORT, 10);
590
+ if (process.env.HOST) this.config.server.host = process.env.HOST;
591
+ if (process.env.BASE_PATH) this.config.server.basePath = process.env.BASE_PATH;
592
+ if (process.env.DATABASE_URL) this.config.database.uri = process.env.DATABASE_URL;
593
+ if (process.env.MONGODB_URI) this.config.database.uri = process.env.MONGODB_URI;
594
+ if (process.env.DATABASE_NAME) this.config.database.name = process.env.DATABASE_NAME;
595
+ if (process.env.JWT_SECRET) this.config.auth.jwtSecret = process.env.JWT_SECRET;
596
+ if (process.env.JWT_EXPIRES_IN) this.config.auth.jwtExpiresIn = process.env.JWT_EXPIRES_IN;
597
+ if (process.env.LOG_LEVEL) this.config.logging.level = process.env.LOG_LEVEL;
598
+ if (process.env.LOGS_DIR) this.config.logging.logsDir = process.env.LOGS_DIR;
599
+ if (process.env.CORS_ORIGINS) {
600
+ const origins = process.env.CORS_ORIGINS.split(",").map((o) => o.trim());
601
+ this.config.cors.production.push(...origins);
602
+ }
603
+ return this;
604
+ }
605
+ /**
606
+ * Validate configuration
607
+ */
608
+ validate() {
609
+ const errors = [];
610
+ if (!this.config.server.name) errors.push("Server name is required");
611
+ if (this.config.server.port < 1 || this.config.server.port > 65535) {
612
+ errors.push("Server port must be between 1 and 65535");
613
+ }
614
+ if (this.config.server.environment === "production") {
615
+ if (!this.config.auth.jwtSecret || this.config.auth.jwtSecret.length < 32) {
616
+ errors.push("JWT secret must be at least 32 characters in production");
617
+ }
618
+ }
619
+ return { valid: errors.length === 0, errors };
620
+ }
621
+ /**
622
+ * Build the final configuration
623
+ */
624
+ build() {
625
+ return { ...this.config };
626
+ }
627
+ };
628
+ var createConfig = () => {
629
+ return new ConfigBuilder();
630
+ };
631
+ var buildConfig = (partial = {}) => {
632
+ const builder = createConfig().loadFromEnv();
633
+ if (partial.server) builder.setServer(partial.server);
634
+ if (partial.database) builder.setDatabase(partial.database);
635
+ if (partial.auth) builder.setAuth(partial.auth);
636
+ if (partial.logging) builder.setLogging(partial.logging);
637
+ if (partial.cors) builder.setCorsOrigins(partial.cors);
638
+ if (partial.rateLimit) builder.setRateLimit(partial.rateLimit);
639
+ return builder.build();
640
+ };
641
+ var isProduction = (config) => {
642
+ return (config?.environment || process.env.NODE_ENV) === "production";
643
+ };
644
+ var isDevelopment = (config) => {
645
+ return (config?.environment || process.env.NODE_ENV) === "development";
646
+ };
647
+ var isTest = (config) => {
648
+ return (config?.environment || process.env.NODE_ENV) === "test";
649
+ };
650
+ var getDatabaseOptions = (config) => {
651
+ return {
652
+ maxPoolSize: config.maxPoolSize,
653
+ minPoolSize: config.minPoolSize,
654
+ socketTimeoutMS: config.socketTimeoutMS,
655
+ serverSelectionTimeoutMS: config.serverSelectionTimeoutMS,
656
+ maxIdleTimeMS: config.maxIdleTimeMS,
657
+ retryWrites: config.retryWrites,
658
+ retryReads: config.retryReads,
659
+ w: config.writeConcern
660
+ };
661
+ };
662
+
663
+ export { ConfigBuilder, DEFAULT_AUTH_CONFIG, DEFAULT_CORS_CONFIG, DEFAULT_CORS_ORIGINS, DEFAULT_DATABASE_CONFIG, DEFAULT_LOGGING_CONFIG, DEFAULT_RATE_LIMIT_CONFIG, DEFAULT_RATE_LIMIT_TIERS, DEFAULT_SERVER_CONFIG, EXYCONN_CORS_CONFIG, PERMISSIVE_CORS_CONFIG, RATE_LIMIT_CONFIG, RateLimiterBuilder, STRICT_CORS_CONFIG, buildConfig, corsOptions, createApiKeyGenerator, createApiRateLimiter, createBrandCorsOptions, createConfig, createCorsOptions, createDdosRateLimiter, createMultiBrandCorsOptions, createPrefixedKeyGenerator, createRateLimiter, createStandardRateLimiter, createStrictRateLimiter, createUserKeyGenerator, ddosProtectionLimiter, defaultKeyGenerator, getDatabaseOptions, isDevelopment, isProduction, isTest, rateLimiter, standardRateLimiter, strictRateLimiter };
664
+ //# sourceMappingURL=index.mjs.map
665
+ //# sourceMappingURL=index.mjs.map