@xeno-js/shared 2.0.0 → 3.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.
package/dist/axios.cjs ADDED
@@ -0,0 +1,2230 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/axios.ts
21
+ var axios_exports = {};
22
+ __export(axios_exports, {
23
+ AxiosHttpClient: () => AxiosHttpClient
24
+ });
25
+ module.exports = __toCommonJS(axios_exports);
26
+
27
+ // src/infrastructure/http/axios.http.ts
28
+ var import_axios = require("axios");
29
+
30
+ // src/shared/constants/concurrency.constants.ts
31
+ var DEFAULT_CONCURRENCY = Object.freeze({
32
+ /**
33
+ * @description Number of maximum retry attempts for handling concurrency conflicts in the pipeline. If the number of attempts exceeds this value, the pipeline will return a failed Result with an AppError indicating that the maximum retry attempts have been exceeded due to concurrency conflicts.
34
+
35
+ *
36
+ * @author Xeno
37
+ * @version 1.0.0
38
+ * @since 2025-09-30
39
+ * @link https://github.com/xeno-js/xeno-js
40
+ */
41
+ MAX_RETRIES: 3,
42
+ /**
43
+ * @description Base delay in milliseconds for retrying a request after a concurrency conflict is detected. The actual delay will be calculated using an exponential backoff strategy with added jitter to prevent thundering herd problems when multiple requests are retried simultaneously.
44
+
45
+ *
46
+ * @author Xeno
47
+ * @version 1.0.0
48
+ * @since 2025-09-30
49
+ * @link https://github.com/xeno-js/xeno-js
50
+ */
51
+ BASE_DELAY: 20,
52
+ /**
53
+ * @description Maximum jitter in milliseconds to be added to the base delay when retrying a request after a concurrency conflict is detected. This helps to randomize the retry attempts and reduce the likelihood of multiple requests being retried at the same time, which can lead to further conflicts. The actual delay for each retry will be calculated as baseDelayMs * (2 ** attempt) + randomJitter, where randomJitter is a random value between 0 and maxJitterMs.
54
+
55
+ *
56
+ * @author Xeno
57
+ * @version 1.0.0
58
+ * @since 2025-09-30
59
+ * @link https://github.com/xeno-js/xeno-js
60
+ */
61
+ MAX_JITTER: 30
62
+ });
63
+
64
+ // src/shared/constants/error.constants.ts
65
+ var ERROR_CODES = Object.freeze({
66
+ // ── Generic / System ─────────────────────────────────────────────────────
67
+ /** @description Unclassified or unexpected infrastructure-level failure.
68
+ *
69
+ * @author Xeno
70
+ * @version 1.0.0
71
+ * @since 2025-09-30
72
+ * @link https://github.com/xeno-js/xeno-js
73
+ */
74
+ SYSTEM_ERROR: "SYSTEM_ERROR",
75
+ /** @description An operation that has not yet been implemented was invoked.
76
+ *
77
+ * @author Xeno
78
+ * @version 1.0.0
79
+ * @since 2025-09-30
80
+ * @link https://github.com/xeno-js/xeno-js
81
+ */
82
+ NOT_IMPLEMENTED: "NOT_IMPLEMENTED",
83
+ /** @description An external API call failed due to network issues or a 5xx response.
84
+ *
85
+ * @author Xeno
86
+ * @version 1.0.0
87
+ * @since 2025-09-30
88
+ * @link https://github.com/xeno-js/xeno-js
89
+ */
90
+ EXTERNAL_SERVICE_ERROR: "EXTERNAL_SERVICE_ERROR",
91
+ /** @description One or more input fields failed invariant or schema validation.
92
+ *
93
+ * @author Xeno
94
+ * @version 1.0.0
95
+ * @since 2025-09-30
96
+ * @link https://github.com/xeno-js/xeno-js
97
+ */
98
+ VALIDATION_FAILED: "VALIDATION_FAILED",
99
+ /** @description Authentication failed due to invalid credentials or token.
100
+ *
101
+ * @author Xeno
102
+ * @version 1.0.0
103
+ * @since 2025-09-30
104
+ * @link https://github.com/xeno-js/xeno-js
105
+ */
106
+ AUTHENTICATION_FAILED: "AUTHENTICATION_FAILED",
107
+ /** @description The caller is not authenticated.
108
+ *
109
+ * @author Xeno
110
+ * @version 1.0.0
111
+ * @since 2025-09-30
112
+ * @link https://github.com/xeno-js/xeno-js
113
+ */
114
+ UNAUTHORIZED: "UNAUTHORIZED",
115
+ /** @description The caller is authenticated but lacks the required permissions.
116
+ *
117
+ * @author Xeno
118
+ * @version 1.0.0
119
+ * @since 2025-09-30
120
+ * @link https://github.com/xeno-js/xeno-js
121
+ */
122
+ FORBIDDEN: "FORBIDDEN",
123
+ /** @description The request was well-formed but semantically invalid.
124
+ *
125
+ * @author Xeno
126
+ * @version 1.0.0
127
+ * @since 2025-09-30
128
+ * @link https://github.com/xeno-js/xeno-js
129
+ */
130
+ BAD_REQUEST: "BAD_REQUEST",
131
+ /** @description The request was aborted before it could be processed.
132
+ *
133
+ * @author Xeno
134
+ * @version 1.0.0
135
+ * @since 2025-09-30
136
+ * @link https://github.com/xeno-js/xeno-js
137
+ */
138
+ ABORTED: "ABORTED",
139
+ /** @description Required service scope is not available in the request context.
140
+ *
141
+ * @author Xeno
142
+ * @version 1.0.0
143
+ * @since 2025-09-30
144
+ * @link https://github.com/xeno-js/xeno-js
145
+ */
146
+ SCOPE_NOT_AVAILABLE: "SCOPE_NOT_AVAILABLE",
147
+ /** @description The request conflicts with the current state of the resource.
148
+ *
149
+ * @author Xeno
150
+ * @version 1.0.0
151
+ * @since 2025-09-30
152
+ * @link https://github.com/xeno-js/xeno-js
153
+ */
154
+ CONFLICT: "CONFLICT",
155
+ /** @description The requested resource does not exist.
156
+ *
157
+ * @author Xeno
158
+ * @version 1.0.0
159
+ * @since 2025-09-30
160
+ * @link https://github.com/xeno-js/xeno-js
161
+ */
162
+ NOT_FOUND: "NOT_FOUND",
163
+ /** @description No handler was found for the given request type.
164
+ *
165
+ * @author Xeno
166
+ * @version 1.0.0
167
+ * @since 2025-09-30
168
+ * @link https://github.com/xeno-js/xeno-js
169
+ */
170
+ HANDLER_NOT_FOUND: "HANDLER_NOT_FOUND",
171
+ /** @description No pipeline behavior was found for the given request type.
172
+ *
173
+ * @author Xeno
174
+ * @version 1.0.0
175
+ * @since 2025-09-30
176
+ * @link https://github.com/xeno-js/xeno-js
177
+ */
178
+ PIPELINE_NOT_AVAILABLE: "PIPELINE_NOT_AVAILABLE",
179
+ NOT_ALLOWED: "METHOD_NOT_ALLOWED",
180
+ TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS"
181
+ });
182
+ var STATUS_CODES = Object.freeze({
183
+ // ── 2xx Success ───────────────────────────────────────────────────────────
184
+ /** @description The request succeeded and a response body is present.
185
+ *
186
+ * @author Xeno
187
+ * @version 1.0.0
188
+ * @since 2025-09-30
189
+ * @link https://github.com/xeno-js/xeno-js
190
+ */
191
+ OK: 200,
192
+ /** @description A new resource has been successfully created.
193
+ *
194
+ * @author Xeno
195
+ * @version 1.0.0
196
+ * @since 2025-09-30
197
+ * @link https://github.com/xeno-js/xeno-js
198
+ */
199
+ CREATED: 201,
200
+ /** @description The request succeeded but there is no response body (e.g. DELETE).
201
+ *
202
+ * @author Xeno
203
+ * @version 1.0.0
204
+ * @since 2025-09-30
205
+ * @link https://github.com/xeno-js/xeno-js
206
+ */
207
+ NO_CONTENT: 204,
208
+ // ── 4xx Client Errors ─────────────────────────────────────────────────────
209
+ /** @description The request payload is malformed or contains invalid parameters.
210
+ *
211
+ * @author Xeno
212
+ * @version 1.0.0
213
+ * @since 2025-09-30
214
+ * @link https://github.com/xeno-js/xeno-js
215
+ */
216
+ BAD_REQUEST: 400,
217
+ /** @description Authentication credentials are missing or invalid.
218
+ *
219
+ * @author Xeno
220
+ * @version 1.0.0
221
+ * @since 2025-09-30
222
+ * @link https://github.com/xeno-js/xeno-js
223
+ */
224
+ UNAUTHORIZED: 401,
225
+ /** @description The caller lacks permission to perform the requested operation.
226
+ *
227
+ * @author Xeno
228
+ * @version 1.0.0
229
+ * @since 2025-09-30
230
+ * @link https://github.com/xeno-js/xeno-js
231
+ */
232
+ FORBIDDEN: 403,
233
+ /** @description The requested resource does not exist.
234
+ *
235
+ * @author Xeno
236
+ * @version 1.0.0
237
+ * @since 2025-09-30
238
+ * @link https://github.com/xeno-js/xeno-js
239
+ */
240
+ NOT_FOUND: 404,
241
+ NOT_ALLOWED: 405,
242
+ /** @description The request conflicts with the current state of the resource.
243
+ *
244
+ * @author Xeno
245
+ * @version 1.0.0
246
+ * @since 2025-09-30
247
+ * @link https://github.com/xeno-js/xeno-js
248
+ */
249
+ CONFLICT: 409,
250
+ /** @description The payload is syntactically valid but semantically unprocessable.
251
+ *
252
+ * @author Xeno
253
+ * @version 1.0.0
254
+ * @since 2025-09-30
255
+ * @link https://github.com/xeno-js/xeno-js
256
+ */
257
+ UNPROCESSABLE_ENTITY: 422,
258
+ /** @description The caller has exceeded its allowed rate limit.
259
+ *
260
+ * @author Xeno
261
+ * @version 1.0.0
262
+ * @since 2025-09-30
263
+ * @link https://github.com/xeno-js/xeno-js
264
+ */
265
+ TOO_MANY_REQUESTS: 429,
266
+ /** @description The client closed the connection before the server finished responding.
267
+ *
268
+ * @author Xeno
269
+ * @version 1.0.0
270
+ * @since 2025-09-30
271
+ * @link https://github.com/xeno-js/xeno-js
272
+ */
273
+ ABORTED: 499,
274
+ // ── 5xx Server Errors ─────────────────────────────────────────────────────
275
+ /** @description An unexpected condition was encountered by the server.
276
+ *
277
+ * @author Xeno
278
+ * @version 1.0.0
279
+ * @since 2025-09-30
280
+ * @link https://github.com/xeno-js/xeno-js
281
+ */
282
+ INTERNAL_SERVER_ERROR: 500,
283
+ /** @description A downstream dependency is temporarily unavailable.
284
+ *
285
+ * @author Xeno
286
+ * @version 1.0.0
287
+ * @since 2025-09-30
288
+ * @link https://github.com/xeno-js/xeno-js
289
+ */
290
+ SERVICE_UNAVAILABLE: 503
291
+ });
292
+ var ERROR_CODE_MESSAGES = Object.freeze({
293
+ [ERROR_CODES.SYSTEM_ERROR]: "errors.system_error",
294
+ [ERROR_CODES.NOT_IMPLEMENTED]: "errors.not_implemented",
295
+ [ERROR_CODES.EXTERNAL_SERVICE_ERROR]: "errors.external_service_error",
296
+ [ERROR_CODES.VALIDATION_FAILED]: "errors.validation_failed",
297
+ [ERROR_CODES.UNAUTHORIZED]: "errors.unauthorized",
298
+ [ERROR_CODES.FORBIDDEN]: "errors.forbidden",
299
+ [ERROR_CODES.BAD_REQUEST]: "errors.bad_request",
300
+ [ERROR_CODES.ABORTED]: "errors.aborted",
301
+ [ERROR_CODES.AUTHENTICATION_FAILED]: "errors.authentication_failed",
302
+ [ERROR_CODES.SCOPE_NOT_AVAILABLE]: "errors.scope_not_available",
303
+ [ERROR_CODES.CONFLICT]: "errors.conflict",
304
+ [ERROR_CODES.NOT_FOUND]: "errors.not_found",
305
+ [ERROR_CODES.HANDLER_NOT_FOUND]: "errors.handler_not_found",
306
+ [ERROR_CODES.PIPELINE_NOT_AVAILABLE]: "errors.pipeline_not_available",
307
+ [ERROR_CODES.NOT_ALLOWED]: "errors.method_not_allowed",
308
+ [ERROR_CODES.TOO_MANY_REQUESTS]: "errors.too_many_requests"
309
+ });
310
+
311
+ // src/shared/constants/roles.constants.ts
312
+ var ROLES = Object.freeze({
313
+ /** @description The SUPER_ADMIN role, which typically has the highest level of permissions and access within the application.
314
+ *
315
+ * @author Xeno
316
+ * @version 1.0.0
317
+ * @since 2025-09-30
318
+ * @link https://github.com/xeno-js/xeno-js
319
+ */
320
+ SUPER_ADMIN: "super_admin",
321
+ /** @description The ADMIN role, which typically has elevated permissions and access within the application, but may have some restrictions compared to the SUPER_ADMIN role.
322
+ *
323
+ * @author Xeno
324
+ * @version 1.0.0
325
+ * @since 2025-09-30
326
+ * @link https://github.com/xeno-js/xeno-js
327
+ */
328
+ ADMIN: "admin",
329
+ /** @description The USER role, which typically has standard permissions and access within the application, allowing them to perform regular user actions but with limited administrative capabilities.
330
+ *
331
+ * @author Xeno
332
+ * @version 1.0.0
333
+ * @since 2025-09-30
334
+ * @link https://github.com/xeno-js/xeno-js
335
+ */
336
+ USER: "user",
337
+ /** @description The GUEST role, which typically has the most limited permissions and access within the application, often used for unauthenticated users or users with very restricted access.
338
+ *
339
+ * @author Xeno
340
+ * @version 1.0.0
341
+ * @since 2025-09-30
342
+ * @link https://github.com/xeno-js/xeno-js
343
+ */
344
+ GUEST: "guest"
345
+ });
346
+ var PERMISSIONS = Object.freeze({
347
+ /** @description The READ permission, which typically allows access to resources or actions within the application that require read-only access.
348
+ *
349
+ * @author Xeno
350
+ * @version 1.0.0
351
+ * @since 2025-09-30
352
+ * @link https://github.com/xeno-js/xeno-js
353
+ */
354
+ READ: "read"
355
+ });
356
+
357
+ // src/shared/constants/guest.constants.ts
358
+ var GUEST = Object.freeze({
359
+ /** @description The unique identifier for the guest user, which is set to undefined since guest users do not have a specific user ID. This allows the application to differentiate between authenticated users with valid IDs and unauthenticated guest users.
360
+ *
361
+ * @author Xeno
362
+ * @version 1.0.0
363
+ * @since 2025-09-30
364
+ * @link https://github.com/xeno-js/xeno-js
365
+ */
366
+ userId: void 0,
367
+ /** @description The email for guest user, which is set to undefined since guest users do not have a specific email.
368
+ *
369
+ * @author Xeno
370
+ * @version 1.0.0
371
+ * @since 2025-09-30
372
+ * @link https://github.com/xeno-js/xeno-js
373
+ */
374
+ email: void 0,
375
+ /** @description The unique identifier for the tenant associated with the guest user, which is set to undefined since guest users do not belong to a specific tenant. This allows the application to handle multi-tenancy scenarios while still accommodating unauthenticated users who do not have an associated tenant.
376
+ *
377
+ * @author Xeno
378
+ * @version 1.0.0
379
+ * @since 2025-09-30
380
+ * @link https://github.com/xeno-js/xeno-js
381
+ */
382
+ tenantId: void 0,
383
+ /** @description An array of roles assigned to the guest user, which includes only the GUEST role. This indicates that the user has minimal access rights and is typically used to represent unauthenticated users or users with limited permissions in the application.
384
+ *
385
+ * @author Xeno
386
+ * @version 1.0.0
387
+ * @since 2025-09-30
388
+ * @link https://github.com/xeno-js/xeno-js
389
+ */
390
+ roles: [ROLES.GUEST],
391
+ /** @description An array of permissions assigned to the guest user, which is empty since guest users do not have any specific permissions. This reinforces the idea that guest users have minimal access rights and cannot perform actions that require specific permissions in the application.
392
+ *
393
+ * @author Xeno
394
+ * @version 1.0.0
395
+ * @since 2025-09-30
396
+ * @link https://github.com/xeno-js/xeno-js
397
+ */
398
+ permissions: [PERMISSIONS.READ]
399
+ });
400
+
401
+ // src/shared/constants/idempotency.constants.ts
402
+ var IDEMPOTENCY_CONSTANTS = Object.freeze({
403
+ /**
404
+ * @description Prefix for keys used to store locks in the idempotency store. This prefix is used to differentiate lock entries from other types of entries in the cache, allowing for efficient management of locks when acquiring and releasing them during command processing. The lock key prefix helps ensure that lock-related data is organized and easily identifiable within the caching mechanism.
405
+
406
+ *
407
+ * @author Xeno
408
+ * @version 1.0.0
409
+ * @since 2025-09-30
410
+ * @link https://github.com/xeno-js/xeno-js
411
+ */
412
+ LOCK_KEY_PREFIX: "idempotency_lock:",
413
+ /**
414
+ * @description Prefix for keys used to store processed command results in the idempotency store. This prefix is used to differentiate processed command entries from lock entries and other types of data in the cache, allowing for efficient retrieval of stored results when checking if a command has already been processed. The processed key prefix helps maintain a clear structure within the caching mechanism, making it easier to manage and query processed command data.
415
+
416
+ *
417
+ * @author Xeno
418
+ * @version 1.0.0
419
+ * @since 2025-09-30
420
+ * @link https://github.com/xeno-js/xeno-js
421
+ */
422
+ PROCESSED_KEY_PREFIX: "idempotency_processed:",
423
+ /**
424
+ * @description Default time-to-live (TTL) in seconds for locks and processed command entries in the idempotency store. This value is used when acquiring locks and marking commands as processed to specify how long the lock or stored result should remain valid before it expires. The default TTL helps ensure that locks and processed command entries do not persist indefinitely, allowing for automatic cleanup of stale data and preventing potential issues with long-lived locks or outdated results in the idempotency store.
425
+
426
+ *
427
+ * @author Xeno
428
+ * @version 1.0.0
429
+ * @since 2025-09-30
430
+ * @link https://github.com/xeno-js/xeno-js
431
+ */
432
+ DEFAULT_TTL_SECONDS: 86400,
433
+ /**
434
+ * @description Default time-to-live (TTL) in seconds for locks in the idempotency store. This value is used when acquiring locks to specify how long the lock should remain valid before it expires. The default lock TTL helps ensure that locks do not persist indefinitely, allowing for automatic cleanup of stale locks and preventing potential issues with long-lived locks in the idempotency mechanism.
435
+
436
+ *
437
+ * @author Xeno
438
+ * @version 1.0.0
439
+ * @since 2025-09-30
440
+ * @link https://github.com/xeno-js/xeno-js
441
+ */
442
+ DEFAULT_IDEMPOTENCY_LOCK_TTL_SECONDS: 60,
443
+ /**
444
+ * @description Standard value used to indicate that a lock has been acquired for a specific commandId in the idempotency store. This value is stored in the cache when a lock is successfully acquired, allowing other instances of the command to recognize that the command is currently being processed and prevent duplicate processing. The locked value serves as a marker for active locks in the idempotency mechanism, helping to manage concurrent command processing effectively.
445
+
446
+ *
447
+ * @author Xeno
448
+ * @version 1.0.0
449
+ * @since 2025-09-30
450
+ * @link https://github.com/xeno-js/xeno-js
451
+ */
452
+ LOCKED_VALUE: "LOCKED",
453
+ /**
454
+ * @description Standard value used to indicate that a command has been processed and its result has been stored in the idempotency store. This value is stored in the cache when a command is marked as processed, allowing subsequent attempts to process the same commandId to recognize that it has already been handled and return the stored result instead of executing the command again. The processed value serves as a marker for completed commands in the idempotency mechanism, helping to manage command processing outcomes and prevent redundant executions.
455
+
456
+ *
457
+ * @author Xeno
458
+ * @version 1.0.0
459
+ * @since 2025-09-30
460
+ * @link https://github.com/xeno-js/xeno-js
461
+ */
462
+ PROCESSED_VALUE: "PROCESSED"
463
+ });
464
+
465
+ // src/shared/constants/log-level.constants.ts
466
+ var LOG_LEVEL = Object.freeze({
467
+ /** * Debug level for detailed debugging information. This level is typically used during development and should be turned off in production to avoid verbose logging.
468
+
469
+ *
470
+ * @author Xeno
471
+ * @version 1.0.0
472
+ * @since 2025-09-30
473
+ * @link https://github.com/xeno-js/xeno-js
474
+ */
475
+ DEBUG: 0,
476
+ /** * Info level for general informational messages that highlight the progress of the application at a coarse-grained level. This level is suitable for production environments to track the normal operation of the application.
477
+
478
+ *
479
+ * @author Xeno
480
+ * @version 1.0.0
481
+ * @since 2025-09-30
482
+ * @link https://github.com/xeno-js/xeno-js
483
+ */
484
+ INFO: 1,
485
+ /** * Warn level for potentially harmful situations that are not necessarily errors but may require attention. This level is useful for identifying issues that could lead to errors if not addressed.
486
+
487
+ *
488
+ * @author Xeno
489
+ * @version 1.0.0
490
+ * @since 2025-09-30
491
+ * @link https://github.com/xeno-js/xeno-js
492
+ */
493
+ WARN: 2,
494
+ /** * Error level for serious issues that have caused or are likely to cause the application to fail. This level is critical for identifying and addressing problems that need immediate attention.
495
+
496
+ *
497
+ * @author Xeno
498
+ * @version 1.0.0
499
+ * @since 2025-09-30
500
+ * @link https://github.com/xeno-js/xeno-js
501
+ */
502
+ ERROR: 3
503
+ });
504
+ var LOG_LEVEL_NAMES = {
505
+ /** Debug level for detailed debugging information. This level is typically used during development and should be turned off in production to avoid verbose logging.
506
+ *
507
+ * @author Xeno
508
+ * @version 1.0.0
509
+ * @since 2025-09-30
510
+ * @link https://github.com/xeno-js/xeno-js
511
+ */
512
+ [LOG_LEVEL.DEBUG]: "DEBUG",
513
+ /** Info level for general informational messages that highlight the progress of the application at a coarse-grained level. This level is suitable for production environments to track the normal operation of the application.
514
+ *
515
+ * @author Xeno
516
+ * @version 1.0.0
517
+ * @since 2025-09-30
518
+ * @link https://github.com/xeno-js/xeno-js
519
+ */
520
+ [LOG_LEVEL.INFO]: "INFO",
521
+ /** Warn level for potentially harmful situations that are not necessarily errors but may require attention. This level is useful for identifying issues that could lead to errors if not addressed.
522
+ *
523
+ * @author Xeno
524
+ * @version 1.0.0
525
+ * @since 2025-09-30
526
+ * @link https://github.com/xeno-js/xeno-js
527
+ */
528
+ [LOG_LEVEL.WARN]: "WARN",
529
+ /** Error level for serious issues that have caused or are likely to cause the application to fail. This level is critical for identifying and addressing problems that need immediate attention.
530
+ *
531
+ * @author Xeno
532
+ * @version 1.0.0
533
+ * @since 2025-09-30
534
+ * @link https://github.com/xeno-js/xeno-js
535
+ */
536
+ [LOG_LEVEL.ERROR]: "ERROR"
537
+ };
538
+
539
+ // src/shared/constants/pagination.constants.ts
540
+ var DEFAULT_PAGE = 1;
541
+ var DEFAULT_PAGE_SIZE = 20;
542
+ var MAX_PAGE_SIZE = 100;
543
+ var PAGINATION_DEFAULTS = Object.freeze({
544
+ /** @description Default page index (1-based).
545
+ *
546
+ * @author Xeno
547
+ * @version 1.0.0
548
+ * @since 2025-09-30
549
+ * @link https://github.com/xeno-js/xeno-js
550
+ */
551
+ PAGE: DEFAULT_PAGE,
552
+ /** @description Default maximum items per page.
553
+ *
554
+ * @author Xeno
555
+ * @version 1.0.0
556
+ * @since 2025-09-30
557
+ * @link https://github.com/xeno-js/xeno-js
558
+ */
559
+ PAGE_SIZE: DEFAULT_PAGE_SIZE,
560
+ /** @description Hard ceiling on page size accepted by the system.
561
+ *
562
+ * @author Xeno
563
+ * @version 1.0.0
564
+ * @since 2025-09-30
565
+ * @link https://github.com/xeno-js/xeno-js
566
+ */
567
+ MAX_PAGE_SIZE
568
+ });
569
+ var SORT_DIRECTION = Object.freeze({
570
+ /** @description Ascending order (A → Z, 0 → 9, oldest → newest).
571
+ *
572
+ * @author Xeno
573
+ * @version 1.0.0
574
+ * @since 2025-09-30
575
+ * @link https://github.com/xeno-js/xeno-js
576
+ */
577
+ ASC: "asc",
578
+ /** @description Descending order (Z → A, 9 → 0, newest → oldest).
579
+ *
580
+ * @author Xeno
581
+ * @version 1.0.0
582
+ * @since 2025-09-30
583
+ * @link https://github.com/xeno-js/xeno-js
584
+ */
585
+ DESC: "desc"
586
+ });
587
+
588
+ // src/shared/constants/request.constants.ts
589
+ var REQUEST_TYPE = Object.freeze({
590
+ /** @description A request that intends to modify state (e.g. create, update, delete).
591
+ *
592
+ * @author Xeno
593
+ * @version 1.0.0
594
+ * @since 2025-09-30
595
+ * @link https://github.com/xeno-js/xeno-js
596
+ */
597
+ COMMAND: "COMMAND",
598
+ /** @description A request that intends to retrieve data without modifying state.
599
+ *
600
+ * @author Xeno
601
+ * @version 1.0.0
602
+ * @since 2025-09-30
603
+ * @link https://github.com/xeno-js/xeno-js
604
+ */
605
+ QUERY: "QUERY"
606
+ });
607
+
608
+ // src/shared/constants/resilience.constants.ts
609
+ var RESILIENCE_DEFAULTS = Object.freeze({
610
+ /** @description Default retry policy values.
611
+ *
612
+ * @author Xeno
613
+ * @version 1.0.0
614
+ * @since 2025-09-30
615
+ * @link https://github.com/xeno-js/xeno-js
616
+ */
617
+ RETRY: Object.freeze({
618
+ /** @description Default number of retry attempts.
619
+ *
620
+ * @author Xeno
621
+ * @version 1.0.0
622
+ * @since 2025-09-30
623
+ * @link https://github.com/xeno-js/xeno-js
624
+ */
625
+ ATTEMPTS: 3,
626
+ /** @description Default base delay in milliseconds for retry backoff.
627
+ *
628
+ * @author Xeno
629
+ * @version 1.0.0
630
+ * @since 2025-09-30
631
+ * @link https://github.com/xeno-js/xeno-js
632
+ */
633
+ BASE_DELAY_MS: 100,
634
+ /** @description Default maximum delay in milliseconds for retry backoff.
635
+ *
636
+ * @author Xeno
637
+ * @version 1.0.0
638
+ * @since 2025-09-30
639
+ * @link https://github.com/xeno-js/xeno-js
640
+ */
641
+ MAX_DELAY_MS: 1e3
642
+ }),
643
+ /** @description Default circuit breaker policy values.
644
+ *
645
+ * @author Xeno
646
+ * @version 1.0.0
647
+ * @since 2025-09-30
648
+ * @link https://github.com/xeno-js/xeno-js
649
+ */
650
+ CIRCUIT_BREAKER: Object.freeze({
651
+ /** @description Default number of consecutive failures before opening the circuit.
652
+ *
653
+ * @author Xeno
654
+ * @version 1.0.0
655
+ * @since 2025-09-30
656
+ * @link https://github.com/xeno-js/xeno-js
657
+ */
658
+ CONSECUTIVE_FAILURES: 5,
659
+ /** @description Default half-open timeout in milliseconds.
660
+ *
661
+ * @author Xeno
662
+ * @version 1.0.0
663
+ * @since 2025-09-30
664
+ * @link https://github.com/xeno-js/xeno-js
665
+ */
666
+ HALF_OPEN_TIMEOUT_MS: 3e4
667
+ }),
668
+ /** @description Default bulkhead policy values.
669
+ *
670
+ * @author Xeno
671
+ * @version 1.0.0
672
+ * @since 2025-09-30
673
+ * @link https://github.com/xeno-js/xeno-js
674
+ */
675
+ BULKHEAD: Object.freeze({
676
+ /** @description Default maximum number of concurrent operations.
677
+ *
678
+ * @author Xeno
679
+ * @version 1.0.0
680
+ * @since 2025-09-30
681
+ * @link https://github.com/xeno-js/xeno-js
682
+ */
683
+ MAX_CONCURRENT: 10
684
+ })
685
+ });
686
+
687
+ // src/shared/constants/tokens.constants.ts
688
+ var TOKENS = Object.freeze({
689
+ /** @description Token used to register and resolve the Extendend AuthService instance in the dependency injection container.
690
+ *
691
+ * @author Xeno
692
+ * @version 1.0.0
693
+ * @since 2025-09-30
694
+ * @link https://github.com/xeno-js/xeno-js
695
+ */
696
+ AUTH_SERVICE: "AUTH_SERVICE",
697
+ /** @description Token used to register and resolve the BaseAuthService instance in the dependency injection container.
698
+ *
699
+ * @author Xeno
700
+ * @version 1.0.0
701
+ * @since 2025-09-30
702
+ * @link https://github.com/xeno-js/xeno-js
703
+ */
704
+ BASE_AUTH_SERVICE: "BASE_AUTH_SERVICE",
705
+ /** @description Token used to register and resolve the InMemoryCache instance in the dependency injection container.
706
+ *
707
+ * @author Xeno
708
+ * @version 1.0.0
709
+ * @since 2025-09-30
710
+ * @link https://github.com/xeno-js/xeno-js
711
+ */
712
+ CACHE: "CACHE",
713
+ /** @description Token used to register and resolve the CacheKeyBuilder instance in the dependency injection container.
714
+ *
715
+ * @author Xeno
716
+ * @version 1.0.0
717
+ * @since 2025-09-30
718
+ * @link https://github.com/xeno-js/xeno-js
719
+ */
720
+ CACHE_KEY_BUILDER: "CACHE_KEY_BUILDER",
721
+ /** @description Token used to register and resolve command pipeline behaviors in the dependency injection container.
722
+ *
723
+ * @author Xeno
724
+ * @version 1.0.0
725
+ * @since 2025-09-30
726
+ * @link https://github.com/xeno-js/xeno-js
727
+ */
728
+ COMMAND_PIPELINES_BEHAVIOR: "COMMAND_PIPELINES_BEHAVIOR",
729
+ /** @description Token used to register and resolve the ConcurrencyService instance in the dependency injection container.
730
+ *
731
+ * @author Xeno
732
+ * @version 1.0.0
733
+ * @since 2025-09-30
734
+ * @link https://github.com/xeno-js/xeno-js
735
+ */
736
+ CONCURRENCY_SERVICE: "CONCURRENCY_SERVICE",
737
+ /** @description Token used to register and resolve the ConfigurationService instance in the dependency injection container.
738
+ *
739
+ * @author Xeno
740
+ * @version 1.0.0
741
+ * @since 2025-09-30
742
+ * @link https://github.com/xeno-js/xeno-js
743
+ */
744
+ CONFIGURATION_SERVICE: "CONFIGURATION_SERVICE",
745
+ /** @description Token used to register and resolve the ContextAccessor instance in the dependency injection container.
746
+ *
747
+ * @author Xeno
748
+ * @version 1.0.0
749
+ * @since 2025-09-30
750
+ * @link https://github.com/xeno-js/xeno-js
751
+ */
752
+ CONTEXT_ACCESSOR: "CONTEXT_ACCESSOR",
753
+ /** @description Token used to register and resolve the CryptoService instance in the dependency injection container.
754
+ *
755
+ * @author Xeno
756
+ * @version 1.0.0
757
+ * @since 2025-09-30
758
+ * @link https://github.com/xeno-js/xeno-js
759
+ */
760
+ CRYPTO_SERVICE: "CRYPTO_SERVICE",
761
+ /** @description Token used to register and resolve the CsrfTokenService instance in the dependency injection container.
762
+ *
763
+ * @author Xeno
764
+ * @version 1.0.0
765
+ * @since 2025-09-30
766
+ * @link https://github.com/xeno-js/xeno-js
767
+ */
768
+ CSRF_TOKEN_SERVICE: "CSRF_TOKEN_SERVICE",
769
+ /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
770
+ *
771
+ * @author Xeno
772
+ * @version 1.0.0
773
+ * @since 2025-09-30
774
+ * @link https://github.com/xeno-js/xeno-js
775
+ */
776
+ DB_CONTEXT: "DB_CONTEXT",
777
+ /** @description Token used to register and resolve the IdentityAccessor instance in the dependency injection container.
778
+ *
779
+ * @author Xeno
780
+ * @version 1.0.0
781
+ * @since 2025-09-30
782
+ * @link https://github.com/xeno-js/xeno-js
783
+ */
784
+ IDENTITY_ACCESSOR: "IDENTITY_ACCESSOR",
785
+ /** @description Token used to register and resolve the Logger instance in the dependency injection container.
786
+ *
787
+ * @author Xeno
788
+ * @version 1.0.0
789
+ * @since 2025-09-30
790
+ * @link https://github.com/xeno-js/xeno-js
791
+ */
792
+ LOGGER: "LOGGER",
793
+ /** @description Token used to register and resolve the Mediator instance in the dependency injection container.
794
+ *
795
+ * @author Xeno
796
+ * @version 1.0.0
797
+ * @since 2025-09-30
798
+ * @link https://github.com/xeno-js/xeno-js
799
+ */
800
+ MEDIATOR: "MEDIATOR",
801
+ /** @description Token used to register and resolve the NetworkContextFactory in the dependency injection container.
802
+ *
803
+ * @author Xeno
804
+ * @version 1.0.0
805
+ * @since 2025-09-30
806
+ * @link https://github.com/xeno-js/xeno-js
807
+ */
808
+ NETWORK_CONTEXT_ACCESSOR: "NETWORK_CONTEXT_ACCESSOR",
809
+ /** @description Token used to register and resolve query pipeline behaviors in the dependency injection container.
810
+ *
811
+ * @author Xeno
812
+ * @version 1.0.0
813
+ * @since 2025-09-30
814
+ * @link https://github.com/xeno-js/xeno-js
815
+ */
816
+ QUERY_PIPELINES_BEHAVIOR: "QUERY_PIPELINES_BEHAVIOR",
817
+ /** @description Token used to register and resolve the RequestContext instance in the dependency injection container.
818
+ *
819
+ * @author Xeno
820
+ * @version 1.0.0
821
+ * @since 2025-09-30
822
+ * @link https://github.com/xeno-js/xeno-js
823
+ */
824
+ REQUEST_CONTEXT: "REQUEST_CONTEXT",
825
+ /** @description Token used to register and resolve the CompositeMiddleware in the dependency injection container.
826
+ *
827
+ * @author Xeno
828
+ * @version 1.0.0
829
+ * @since 2025-09-30
830
+ * @link https://github.com/xeno-js/xeno-js
831
+ */
832
+ MIDDLEWARE: "MIDDLEWARE",
833
+ /** @description Token used to register and resolve the IServiceResilience instance in the dependency injection container.
834
+ *
835
+ * @author Xeno
836
+ * @version 1.0.0
837
+ * @since 2025-09-30
838
+ * @link https://github.com/xeno-js/xeno-js
839
+ */
840
+ RESILIENCE_CLIENT: "RESILIENCE_CLIENT",
841
+ /** @description Token used to register and resolve the SchemaValidationStrategy instance in the dependency injection container.
842
+ *
843
+ * @author Xeno
844
+ * @version 1.0.0
845
+ * @since 2025-09-30
846
+ * @link https://github.com/xeno-js/xeno-js
847
+ */
848
+ SCHEMA_VALIDATION_STRATEGY: "SCHEMA_VALIDATION_STRATEGY",
849
+ /** @description Token used to register and resolve the ServiceContainer instance in the dependency injection container.
850
+ *
851
+ * @author Xeno
852
+ * @version 1.0.0
853
+ * @since 2025-09-30
854
+ * @link https://github.com/xeno-js/xeno-js
855
+ */
856
+ SERVICE_CONTAINER: "SERVICE_CONTAINER",
857
+ /** @description Token used to register and resolve the ServiceExtractor instance in the dependency injection container.
858
+ *
859
+ * @author Xeno
860
+ * @version 1.0.0
861
+ * @since 2025-09-30
862
+ * @link https://github.com/xeno-js/xeno-js
863
+ */
864
+ SERVICE_EXTRACTOR: "SERVICE_EXTRACTOR",
865
+ /** @description Token used to register and resolve the ServiceScopeAccessor in the dependency injection container.
866
+ *
867
+ * @author Xeno
868
+ * @version 1.0.0
869
+ * @since 2025-09-30
870
+ * @link https://github.com/xeno-js/xeno-js
871
+ */
872
+ SERVICE_SCOPE_ACCESSOR: "SERVICE_SCOPE_ACCESSOR",
873
+ /** @description Token used to register and resolve the UnitOfWork instance in the dependency injection container.
874
+ *
875
+ * @author Xeno
876
+ * @version 1.0.0
877
+ * @since 2025-09-30
878
+ * @link https://github.com/xeno-js/xeno-js
879
+ */
880
+ UNIT_OF_WORK: "UNIT_OF_WORK",
881
+ /** @description Token used to register and resolve the ValidatorService instance in the dependency injection container.
882
+ *
883
+ * @author Xeno
884
+ * @version 1.0.0
885
+ * @since 2025-09-30
886
+ * @link https://github.com/xeno-js/xeno-js
887
+ */
888
+ VALIDATOR_SERVICE: "VALIDATOR_SERVICE"
889
+ });
890
+
891
+ // src/shared/utils/guards.utils.ts
892
+ var OBJECT_TAG = "[object Object]";
893
+ var DATE_TAG = "[object Date]";
894
+ var Guards = Object.freeze({
895
+ /**
896
+ * @description Checks value is neither null nor undefined.
897
+ * @param value Candidate value.
898
+ * @returns True when value is defined.
899
+
900
+ *
901
+ * @author Xeno
902
+ * @version 1.0.0
903
+ * @since 2025-09-30
904
+ * @link https://github.com/xeno-js/xeno-js
905
+ */
906
+ isDefined(value) {
907
+ return value !== null && value !== void 0 && value !== "" && !Number.isNaN(value);
908
+ },
909
+ /**
910
+ * @description Checks value is null, undefined, empty string, or false.
911
+ * @param value Candidate value.
912
+ * @returns True when value is null, undefined, empty string, or false.
913
+
914
+ *
915
+ * @author Xeno
916
+ * @version 1.0.0
917
+ * @since 2025-09-30
918
+ * @link https://github.com/xeno-js/xeno-js
919
+ */
920
+ isNullOrEmpty(value) {
921
+ return !Guards.isDefined(value) || Guards.isString(value) && value.trim() === "" || Guards.isArray(value) && value.length === 0;
922
+ },
923
+ /**
924
+ * @description Throws an error if the value is null, undefined, empty string, or false.
925
+ * @param value Candidate value.
926
+ * @param errorMessage Error message to throw if the check fails.
927
+ * @throws Error with the provided message if the value is null, undefined, empty string, or false.
928
+
929
+ *
930
+ * @author Xeno
931
+ * @version 1.0.0
932
+ * @since 2025-09-30
933
+ * @link https://github.com/xeno-js/xeno-js
934
+ */
935
+ throwIfNullOrEmpty(value, errorMessage) {
936
+ if (Guards.isNullOrEmpty(value)) {
937
+ throw new Error(errorMessage);
938
+ }
939
+ },
940
+ /**
941
+ * @description Throws an error if the value is not a positive integer.
942
+ * @param value Candidate value.
943
+ * @param errorMessage Error message to throw if the check fails.
944
+ * @throws Error with the provided message if the value is not a positive integer.
945
+
946
+ *
947
+ * @author Xeno
948
+ * @version 1.0.0
949
+ * @since 2025-09-30
950
+ * @link https://github.com/xeno-js/xeno-js
951
+ */
952
+ throwIfNegative(value, errorMessage) {
953
+ if (Guards.isInteger(value) && value < 0) {
954
+ throw new Error(errorMessage);
955
+ }
956
+ },
957
+ /**
958
+ * @description Throws an error if the value is not an integer.
959
+ * @param value Candidate value.
960
+ * @param errorMessage Error message to throw if the check fails.
961
+ * @throws Error with the provided message if the value is not an integer.
962
+
963
+ *
964
+ * @author Xeno
965
+ * @version 1.0.0
966
+ * @since 2025-09-30
967
+ * @link https://github.com/xeno-js/xeno-js
968
+ */
969
+ throwIfNotInteger(value, errorMessage) {
970
+ if (!Guards.isInteger(value)) {
971
+ throw new Error(errorMessage);
972
+ }
973
+ },
974
+ /**
975
+ * @description Checks if an object has a method with the given name.
976
+ * @param obj Object to check.
977
+ * @param methodName Name of the method to look for.
978
+ * @returns True when obj has a function property named methodName.
979
+
980
+ *
981
+ * @author Xeno
982
+ * @version 1.0.0
983
+ * @since 2025-09-30
984
+ * @link https://github.com/xeno-js/xeno-js
985
+ */
986
+ hasMethod(obj, methodName) {
987
+ if (!this.isDefined(obj)) return false;
988
+ return Guards.isFunction(obj[methodName]);
989
+ },
990
+ /**
991
+ * @description Checks value is a string.
992
+ * @param value Candidate value.
993
+ * @returns True when value is string.
994
+
995
+ *
996
+ * @author Xeno
997
+ * @version 1.0.0
998
+ * @since 2025-09-30
999
+ * @link https://github.com/xeno-js/xeno-js
1000
+ */
1001
+ isString(value) {
1002
+ return typeof value === "string";
1003
+ },
1004
+ /**
1005
+ * @description Checks value is a finite number.
1006
+ * @param value Candidate value.
1007
+ * @returns True when value is finite number.
1008
+
1009
+ *
1010
+ * @author Xeno
1011
+ * @version 1.0.0
1012
+ * @since 2025-09-30
1013
+ * @link https://github.com/xeno-js/xeno-js
1014
+ */
1015
+ isNumber(value) {
1016
+ return typeof value === "number" && Number.isFinite(value);
1017
+ },
1018
+ /**
1019
+ * @description Checks value is an integer number.
1020
+ * @param value Candidate value.
1021
+ * @returns True when value is integer number.
1022
+
1023
+ *
1024
+ * @author Xeno
1025
+ * @version 1.0.0
1026
+ * @since 2025-09-30
1027
+ * @link https://github.com/xeno-js/xeno-js
1028
+ */
1029
+ isInteger(value) {
1030
+ return Guards.isNumber(value) && Number.isInteger(value);
1031
+ },
1032
+ /**
1033
+ * @description Checks value is boolean.
1034
+ * @param value Candidate value.
1035
+ * @returns True when value is boolean.
1036
+
1037
+ *
1038
+ * @author Xeno
1039
+ * @version 1.0.0
1040
+ * @since 2025-09-30
1041
+ * @link https://github.com/xeno-js/xeno-js
1042
+ */
1043
+ isBoolean(value) {
1044
+ return typeof value === "boolean";
1045
+ },
1046
+ /**
1047
+ * @description Checks value is bigint.
1048
+ * @param value Candidate value.
1049
+ * @returns True when value is bigint.
1050
+
1051
+ *
1052
+ * @author Xeno
1053
+ * @version 1.0.0
1054
+ * @since 2025-09-30
1055
+ * @link https://github.com/xeno-js/xeno-js
1056
+ */
1057
+ isBigInt(value) {
1058
+ return typeof value === "bigint";
1059
+ },
1060
+ /**
1061
+ * @description Checks value is symbol.
1062
+ * @param value Candidate value.
1063
+ * @returns True when value is symbol.
1064
+
1065
+ *
1066
+ * @author Xeno
1067
+ * @version 1.0.0
1068
+ * @since 2025-09-30
1069
+ * @link https://github.com/xeno-js/xeno-js
1070
+ */
1071
+ isSymbol(value) {
1072
+ return typeof value === "symbol";
1073
+ },
1074
+ /**
1075
+ * @description Checks value is a function.
1076
+ * @param value Candidate value.
1077
+ * @returns True when value is function.
1078
+
1079
+ *
1080
+ * @author Xeno
1081
+ * @version 1.0.0
1082
+ * @since 2025-09-30
1083
+ * @link https://github.com/xeno-js/xeno-js
1084
+ */
1085
+ isFunction(value) {
1086
+ return typeof value === "function";
1087
+ },
1088
+ /**
1089
+ * @description Checks value is an array.
1090
+ * @param value Candidate value.
1091
+ * @returns True when value is array.
1092
+
1093
+ *
1094
+ * @author Xeno
1095
+ * @version 1.0.0
1096
+ * @since 2025-09-30
1097
+ * @link https://github.com/xeno-js/xeno-js
1098
+ */
1099
+ isArray(value) {
1100
+ return Array.isArray(value);
1101
+ },
1102
+ /**
1103
+ * @description Checks value is a Date instance with valid timestamp.
1104
+ * @param value Candidate value.
1105
+ * @returns True when value is valid Date.
1106
+
1107
+ *
1108
+ * @author Xeno
1109
+ * @version 1.0.0
1110
+ * @since 2025-09-30
1111
+ * @link https://github.com/xeno-js/xeno-js
1112
+ */
1113
+ isDate(value) {
1114
+ if (Object.prototype.toString.call(value) !== DATE_TAG) {
1115
+ return false;
1116
+ }
1117
+ return Number.isFinite(value.getTime());
1118
+ },
1119
+ /**
1120
+ * @description Checks value is an Error instance.
1121
+ * @param value Candidate value.
1122
+ * @returns True when value is Error.
1123
+
1124
+ *
1125
+ * @author Xeno
1126
+ * @version 1.0.0
1127
+ * @since 2025-09-30
1128
+ * @link https://github.com/xeno-js/xeno-js
1129
+ */
1130
+ isError(value) {
1131
+ return value instanceof Error;
1132
+ },
1133
+ /**
1134
+ * @description Checks value is a plain object record.
1135
+ * @param value Candidate value.
1136
+ * @returns True when value is object record.
1137
+
1138
+ *
1139
+ * @author Xeno
1140
+ * @version 1.0.0
1141
+ * @since 2025-09-30
1142
+ * @link https://github.com/xeno-js/xeno-js
1143
+ */
1144
+ isObjectRecord(value) {
1145
+ if (!Guards.isDefined(value)) {
1146
+ return false;
1147
+ }
1148
+ return Object.prototype.toString.call(value) === OBJECT_TAG;
1149
+ },
1150
+ /**
1151
+ * @description Checks value is an object (not null).
1152
+ * @param value Candidate value.
1153
+ * @returns True when value is object.
1154
+
1155
+ *
1156
+ * @author Xeno
1157
+ * @version 1.0.0
1158
+ * @since 2025-09-30
1159
+ * @link https://github.com/xeno-js/xeno-js
1160
+ */
1161
+ isObject(value) {
1162
+ return typeof value === "object" && Guards.isDefined(value);
1163
+ },
1164
+ /**
1165
+ * @description Checks value is PromiseLike.
1166
+ * @param value Candidate value.
1167
+ * @returns True when value has then function.
1168
+
1169
+ *
1170
+ * @author Xeno
1171
+ * @version 1.0.0
1172
+ * @since 2025-09-30
1173
+ * @link https://github.com/xeno-js/xeno-js
1174
+ */
1175
+ isPromiseLike(value) {
1176
+ if (!Guards.isDefined(value)) {
1177
+ return false;
1178
+ }
1179
+ if (!Guards.isObject(value) && !Guards.isFunction(value)) {
1180
+ return false;
1181
+ }
1182
+ const thenMember = value["then"];
1183
+ return Guards.isFunction(thenMember);
1184
+ }
1185
+ });
1186
+
1187
+ // src/shared/utils/abort.utils.ts
1188
+ var AbortSignalHelper = Object.freeze({
1189
+ /**
1190
+ * Executes a promise with an optional AbortSignal. If the signal is provided and is aborted, the promise will be rejected with the signal's reason.
1191
+ * @template T - The type of the promise's resolved value.
1192
+ * @param promise - The promise to execute.
1193
+ * @param signal - An optional AbortSignal to cancel the promise.
1194
+ * @returns A promise that resolves with the original promise's value or rejects if the signal is aborted.
1195
+ *
1196
+ * @author Xeno
1197
+ * @version 1.0.0
1198
+ * @since 2025-09-30
1199
+ * @link www.github.com/Mattia-Carcione/xeno-js
1200
+ */
1201
+ execute(promise, signal) {
1202
+ if (!Guards.isDefined(signal)) return promise;
1203
+ if (signal.aborted) return Promise.reject(new Error("Operation aborted"));
1204
+ return new Promise((resolve, reject) => {
1205
+ const onAbort = () => {
1206
+ signal.removeEventListener("abort", onAbort);
1207
+ reject(new Error("Operation aborted by the client."));
1208
+ };
1209
+ signal.addEventListener("abort", onAbort);
1210
+ promise.then((res) => {
1211
+ signal.removeEventListener("abort", onAbort);
1212
+ resolve(res);
1213
+ }).catch((_err) => {
1214
+ signal.removeEventListener("abort", onAbort);
1215
+ reject(new Error("Operation aborted by the client."));
1216
+ });
1217
+ });
1218
+ }
1219
+ });
1220
+
1221
+ // src/shared/utils/date.utils.ts
1222
+ var MS_PER_DAY = 864e5;
1223
+ var DateHelper = Object.freeze({
1224
+ /**
1225
+ * @description Converts a Date to an ISO 8601 string.
1226
+ * @param date Input date.
1227
+ * @returns ISO 8601 UTC string.
1228
+
1229
+ *
1230
+ * @author Xeno
1231
+ * @version 1.0.0
1232
+ * @since 2025-09-30
1233
+ * @link https://github.com/xeno-js/xeno-js
1234
+ */
1235
+ toISOString(date) {
1236
+ return date.toISOString();
1237
+ },
1238
+ /**
1239
+ * @description Returns a new Date with the given number of days added.
1240
+ * @param date Base date.
1241
+ * @param days Number of days to add (negative values subtract).
1242
+ * @returns New Date instance.
1243
+
1244
+ *
1245
+ * @author Xeno
1246
+ * @version 1.0.0
1247
+ * @since 2025-09-30
1248
+ * @link https://github.com/xeno-js/xeno-js
1249
+ */
1250
+ addDays(date, days) {
1251
+ return new Date(date.getTime() + days * MS_PER_DAY);
1252
+ },
1253
+ /**
1254
+ * @description Checks whether a date has elapsed relative to a reference time.
1255
+ * @param expiresAt Expiry date.
1256
+ * @param nowMs Reference epoch in milliseconds (defaults to Date.now()).
1257
+ * @returns True when expiresAt is in the past.
1258
+
1259
+ *
1260
+ * @author Xeno
1261
+ * @version 1.0.0
1262
+ * @since 2025-09-30
1263
+ * @link https://github.com/xeno-js/xeno-js
1264
+ */
1265
+ isExpired(expiresAt, nowMs) {
1266
+ const now = nowMs ?? Date.now();
1267
+ return expiresAt.getTime() < now;
1268
+ },
1269
+ /**
1270
+ * @description Checks if one date is after another.
1271
+ * @param after Date to check if it is after.
1272
+ * @param before Date to check against.
1273
+ * @returns True when after is after before.
1274
+
1275
+ *
1276
+ * @author Xeno
1277
+ * @version 1.0.0
1278
+ * @since 2025-09-30
1279
+ * @link https://github.com/xeno-js/xeno-js
1280
+ */
1281
+ isAfter(after, before) {
1282
+ return Guards.isDate(after) && Guards.isDate(before) && after.getTime() > before.getTime();
1283
+ },
1284
+ /**
1285
+ * @description Checks if a date is in the future relative to now.
1286
+ * @param date Date to check.
1287
+ * @returns True when date is in the future.
1288
+
1289
+ *
1290
+ * @author Xeno
1291
+ * @version 1.0.0
1292
+ * @since 2025-09-30
1293
+ * @link https://github.com/xeno-js/xeno-js
1294
+ */
1295
+ isFuture(date) {
1296
+ return Guards.isDate(date) && date.getTime() > Date.now();
1297
+ }
1298
+ });
1299
+
1300
+ // src/shared/utils/enumerable.utils.ts
1301
+ var Enumerable = Object.freeze({
1302
+ /**
1303
+ * Retrieves the first element of an array that satisfies the provided predicate function. If no predicate is provided, it returns the first element of the array. If the array is empty or no elements satisfy the predicate, an error is thrown.
1304
+ * @template T - The type of elements in the array.
1305
+ * @param array - The array to search.
1306
+ * @param predicate - An optional function to test each element.
1307
+ * @returns The first element that satisfies the predicate.
1308
+ * @throws {Error} If the array is empty or no elements satisfy the predicate.
1309
+ *
1310
+ * @author Xeno
1311
+ * @version 1.0.0
1312
+ * @since 2025-09-30
1313
+ * @link www.github.com/Mattia-Carcione/xeno-js
1314
+ */
1315
+ first(array, predicate) {
1316
+ const item = Guards.isDefined(predicate) ? array.find(predicate) : array[0];
1317
+ if (!Guards.isDefined(item)) {
1318
+ throw new Error("Sequence contains no elements.");
1319
+ }
1320
+ return item;
1321
+ },
1322
+ /**
1323
+ * Retrieves the first element of an array that satisfies the provided predicate function. If no predicate is provided, it returns the first element of the array. If the array is empty or no elements satisfy the predicate, undefined is returned.
1324
+ * @template T - The type of elements in the array.
1325
+ * @param array - The array to search.
1326
+ * @param predicate - An optional function to test each element.
1327
+ * @returns The first element that satisfies the predicate or undefined.
1328
+ *
1329
+ * @author Xeno
1330
+ * @version 1.0.0
1331
+ * @since 2025-09-30
1332
+ * @link www.github.com/Mattia-Carcione/xeno-js
1333
+ */
1334
+ firstOrDefault(array, predicate) {
1335
+ const item = Guards.isDefined(predicate) ? array.find(predicate) : array[0];
1336
+ return Guards.isDefined(item) ? item : void 0;
1337
+ }
1338
+ });
1339
+
1340
+ // src/shared/utils/guid.utils.ts
1341
+ var GuidHelper = Object.freeze({
1342
+ /**
1343
+ * @description Generates a cryptographically-random UUID v4.
1344
+ * @returns Lowercase UUID v4 string.
1345
+
1346
+ *
1347
+ * @author Xeno
1348
+ * @version 1.0.0
1349
+ * @since 2025-09-30
1350
+ * @link https://github.com/xeno-js/xeno-js
1351
+ */
1352
+ generate() {
1353
+ return crypto.randomUUID();
1354
+ },
1355
+ /**
1356
+ * @description Validates if a value is a valid GUID (UUID v4) and not empty.
1357
+ * @param value The value to validate.
1358
+ * @returns True if the value is a valid and non-empty GUID, false otherwise.
1359
+
1360
+ *
1361
+ * @author Xeno
1362
+ * @version 1.0.0
1363
+ * @since 2025-09-30
1364
+ * @link https://github.com/xeno-js/xeno-js
1365
+ */
1366
+ isValidGuid(value) {
1367
+ const guid = value.toString();
1368
+ return GuidHelper.isValid(guid) && !GuidHelper.isEmpty(guid);
1369
+ },
1370
+ /**
1371
+ * @description Validates if a string is a valid UUID v4.
1372
+ * @param value Candidate string to validate.
1373
+ * @returns True if the string is a valid UUID v4, false otherwise.
1374
+
1375
+ *
1376
+ * @author Xeno
1377
+ * @version 1.0.0
1378
+ * @since 2025-09-30
1379
+ * @link https://github.com/xeno-js/xeno-js
1380
+ */
1381
+ isValid(value) {
1382
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1383
+ return uuidRegex.test(value);
1384
+ },
1385
+ /**
1386
+ * @description Converts a string to a GUID if it's valid.
1387
+ * @param value The string to convert.
1388
+ * @returns The GUID if the string is valid, otherwise undefined.
1389
+
1390
+ *
1391
+ * @author Xeno
1392
+ * @version 1.0.0
1393
+ * @since 2025-09-30
1394
+ * @link https://github.com/xeno-js/xeno-js
1395
+ */
1396
+ parse(value) {
1397
+ if (!Guards.isNullOrEmpty(value) && this.isValid(value) && !this.isEmpty(value)) {
1398
+ return value;
1399
+ }
1400
+ return void 0;
1401
+ },
1402
+ /**
1403
+ * @description Checks if a GUID is the empty GUID (all zeros).
1404
+ * @param value The GUID to check.
1405
+ * @returns True if the GUID is the empty GUID, false otherwise.
1406
+
1407
+ *
1408
+ * @author Xeno
1409
+ * @version 1.0.0
1410
+ * @since 2025-09-30
1411
+ * @link https://github.com/xeno-js/xeno-js
1412
+ */
1413
+ isEmpty(value) {
1414
+ const emptyGuid = "00000000-0000-0000-0000-000000000000";
1415
+ return value === emptyGuid;
1416
+ }
1417
+ });
1418
+
1419
+ // src/shared/utils/http.utils.ts
1420
+ var HttpHelper = Object.freeze({
1421
+ /**
1422
+ * @description A function that masks the IP address in the given headers object.
1423
+ * @param ip The IP address to mask.
1424
+ * @returns The masked IP address.
1425
+ */
1426
+ maskIp(ip) {
1427
+ if (!Guards.isDefined(ip)) return void 0;
1428
+ if (ip.includes(".")) {
1429
+ const parts = ip.split(".");
1430
+ if (parts.length === 4) {
1431
+ parts[3] = "x";
1432
+ return parts.join(".");
1433
+ }
1434
+ }
1435
+ if (ip.includes(":")) {
1436
+ const parts = ip.split(":");
1437
+ if (parts.length > 0) {
1438
+ parts[parts.length - 1] = "x";
1439
+ return parts.join(":");
1440
+ }
1441
+ }
1442
+ return ip;
1443
+ },
1444
+ /**
1445
+ * @description Normalizes HTTP headers by converting all header values to strings. If a header value is an array, it joins the array elements into a single string separated by commas. This method ensures that the headers are in a consistent format, which can be particularly useful when working with different HTTP client libraries that may represent headers in various ways. If the input headers are not defined or not an object, it returns an empty object.
1446
+ * @param headers The input headers to be normalized, which can be of any type. The method checks if the headers are defined and are an object before processing them.
1447
+ * @returns An object containing the normalized headers, where each header value is a string. If the input headers were not valid, it returns an empty object.
1448
+
1449
+ *
1450
+ * @author Xeno
1451
+ * @version 1.0.0
1452
+ * @since 2025-09-30
1453
+ * @link https://github.com/xeno-js/xeno-js
1454
+ */
1455
+ normalizeHeaders(headers) {
1456
+ if (!Guards.isDefined(headers) || !Guards.isObject(headers)) return {};
1457
+ const normalized = {};
1458
+ for (const [key, value] of Object.entries(headers)) {
1459
+ if (!Guards.isDefined(value)) {
1460
+ continue;
1461
+ }
1462
+ normalized[key] = Array.isArray(value) ? value.map((part) => String(part)).join(",") : String(value);
1463
+ }
1464
+ return normalized;
1465
+ },
1466
+ /**
1467
+ * @description Sanitizes the origin URL by parsing it and extracting the origin part. If the URL is not valid or cannot be parsed or does not contain an origin, it returns undefined.
1468
+ * @param url The URL to be sanitized.
1469
+ * @returns The sanitized origin URL or undefined if the URL is not valid or cannot be parsed or does not contain an origin.
1470
+ *
1471
+ *
1472
+ * @author Xeno
1473
+ * @version 1.0.0
1474
+ * @since 2025-09-30
1475
+ * @link https://github.com/xeno-js/xeno-js
1476
+ */
1477
+ sanitizeOriginUrl(url) {
1478
+ if (!Guards.isDefined(url)) return void 0;
1479
+ try {
1480
+ const parsed = new URL(url);
1481
+ return parsed.origin;
1482
+ } catch {
1483
+ return void 0;
1484
+ }
1485
+ },
1486
+ /**
1487
+ * @description Generates a standardized successful HTTP response with the provided data, status code, metadata, and custom headers. The response includes a success flag set to true, the data payload, and any additional metadata. The headers include a default 'Content-Type' of 'application/json' along with any custom headers provided.
1488
+ * @param data The actual data payload to be included in the successful response. This can be of any type and will be wrapped in a SuccessResponseDto structure.
1489
+ * @param status The HTTP status code for the response, defaulting to 200 (OK) if not provided. This allows for flexibility in indicating different types of successful responses (e.g., 201 for created, 204 for no content).
1490
+ * @param meta Optional metadata to be included in the response. This can contain additional information relevant to the response, such as pagination details, rate limit information, or any other contextual data that may be useful for clients consuming the API.
1491
+ * @param customHeaders Optional custom HTTP headers to be included in the response. This allows for adding any additional headers that may be necessary for specific responses, such as caching directives, custom authentication headers, or other relevant information.
1492
+ * @returns A ResponseDto object representing the successful HTTP response, containing the status code, success flag, headers, and data payload structured as a SuccessResponseDto.
1493
+
1494
+ *
1495
+ * @author Xeno
1496
+ * @version 1.0.0
1497
+ * @since 2025-09-30
1498
+ * @link https://github.com/xeno-js/xeno-js
1499
+ */
1500
+ success(data, status = 200, meta = {}, customHeaders = {}) {
1501
+ const successPayload = {
1502
+ success: true,
1503
+ data,
1504
+ meta
1505
+ };
1506
+ return {
1507
+ status,
1508
+ ok: true,
1509
+ headers: {
1510
+ ...customHeaders,
1511
+ "Content-Type": ["application/json"]
1512
+ },
1513
+ data: successPayload
1514
+ };
1515
+ },
1516
+ /**
1517
+ * @description Generates a standardized error HTTP response with the provided error details, status code, correlation ID, request ID, timestamp, and custom headers. The response includes a success flag set to false, an error object containing the error code, message, and optional details, as well as metadata such as correlation ID and request ID for tracking purposes. The headers include a default 'Content-Type' of 'application/json' along with any custom headers provided.
1518
+ * @param dto An object containing the error details, including the error code, message, optional details, and optional path. This information is structured as an ErrorResponseDto and provides context about the error that occurred.
1519
+ * @param status The HTTP status code for the response, defaulting to 500 (Internal Server Error) if not provided. This allows for flexibility in indicating different types of error responses (e.g., 400 for bad request, 404 for not found).
1520
+ * @param customHeaders Optional custom HTTP headers to be included in the response. This allows for adding any additional headers that may be necessary for specific error responses, such as caching directives, custom authentication headers, or other relevant information.
1521
+ * @returns A ResponseDto object representing the error HTTP response, containing the status code, success flag, headers, and data payload structured as an ErrorResponseDto.
1522
+
1523
+ *
1524
+ * @author Xeno
1525
+ * @version 1.0.0
1526
+ * @since 2025-09-30
1527
+ * @link https://github.com/xeno-js/xeno-js
1528
+ */
1529
+ error(dto, status = STATUS_CODES.INTERNAL_SERVER_ERROR, customHeaders = void 0) {
1530
+ const errorPayload = {
1531
+ success: false,
1532
+ error: {
1533
+ code: dto.error.code,
1534
+ message: dto.error.message,
1535
+ details: dto.error.details,
1536
+ path: dto.error.path
1537
+ },
1538
+ correlationId: dto.correlationId,
1539
+ requestId: dto.requestId,
1540
+ spanId: dto.spanId,
1541
+ timestamp: DateHelper.toISOString(/* @__PURE__ */ new Date())
1542
+ };
1543
+ return {
1544
+ status,
1545
+ ok: false,
1546
+ headers: {
1547
+ "Content-Type": ["application/json"],
1548
+ "X-Correlation-Id": [dto.correlationId],
1549
+ "X-Request-Id": [dto.requestId],
1550
+ "X-Span-Id": [dto.spanId ?? ""],
1551
+ "Cache-Control": ["no-store, no-cache, must-revalidate, proxy-revalidate"],
1552
+ "Pragma": ["no-cache"],
1553
+ "Expires": ["0"],
1554
+ ...customHeaders ?? {}
1555
+ },
1556
+ data: errorPayload
1557
+ };
1558
+ }
1559
+ });
1560
+
1561
+ // src/shared/utils/math.utils.ts
1562
+ var MathHelper = Object.freeze({
1563
+ /**
1564
+ * @description Constrains a value within an inclusive min-max range.
1565
+ * @param value Input value.
1566
+ * @param min Minimum bound.
1567
+ * @param max Maximum bound.
1568
+ * @returns Clamped value.
1569
+
1570
+ *
1571
+ * @author Xeno
1572
+ * @version 1.0.0
1573
+ * @since 2025-09-30
1574
+ * @link https://github.com/xeno-js/xeno-js
1575
+ */
1576
+ clamp(value, min, max) {
1577
+ return Math.min(Math.max(value, min), max);
1578
+ },
1579
+ /**
1580
+ * @description Rounds a number to the specified decimal precision.
1581
+ * @param value Input value.
1582
+ * @param decimals Number of decimal places.
1583
+ * @returns Rounded value.
1584
+
1585
+ *
1586
+ * @author Xeno
1587
+ * @version 1.0.0
1588
+ * @since 2025-09-30
1589
+ * @link https://github.com/xeno-js/xeno-js
1590
+ */
1591
+ roundTo(value, decimals) {
1592
+ const factor = 10 ** decimals;
1593
+ return Math.round(value * factor) / factor;
1594
+ },
1595
+ /**
1596
+ * @description Divides two numbers, returning a safe fallback on zero denominator.
1597
+ * @param numerator Numerator.
1598
+ * @param denominator Denominator.
1599
+ * @param fallback Return value when denominator is zero.
1600
+ * @returns Division result or fallback.
1601
+
1602
+ *
1603
+ * @author Xeno
1604
+ * @version 1.0.0
1605
+ * @since 2025-09-30
1606
+ * @link https://github.com/xeno-js/xeno-js
1607
+ */
1608
+ safeDivide(numerator, denominator, fallback = 0) {
1609
+ if (denominator === 0) return fallback;
1610
+ return numerator / denominator;
1611
+ },
1612
+ /**
1613
+ * @description Returns the percentage of part over total (0–100 scale).
1614
+ * @param part Part value.
1615
+ * @param total Total value.
1616
+ * @returns Percentage or 0 when total is zero.
1617
+
1618
+ *
1619
+ * @author Xeno
1620
+ * @version 1.0.0
1621
+ * @since 2025-09-30
1622
+ * @link https://github.com/xeno-js/xeno-js
1623
+ */
1624
+ toPercentage(part, total) {
1625
+ if (total === 0) return 0;
1626
+ return part / total * 100;
1627
+ },
1628
+ /**
1629
+ * @description Converts a value to a number, returning a fallback for non-numeric inputs.
1630
+ * @param value Input value.
1631
+ * @param fallback Fallback value for non-numeric inputs.
1632
+ * @returns Numeric value or fallback.
1633
+ *
1634
+ * @author Xeno
1635
+ * @version 1.0.0
1636
+ * @since 2025-09-30
1637
+ * @link https://github.com/xeno-js/xeno-js
1638
+ */
1639
+ toNumber(value, fallback = 0) {
1640
+ if (!Guards.isDefined(value) || !Guards.isNumber(value)) return fallback;
1641
+ const num = Number(value);
1642
+ return isNaN(num) ? fallback : num;
1643
+ }
1644
+ });
1645
+
1646
+ // src/shared/utils/promise.utils.ts
1647
+ var PromiseHelper = Object.freeze({
1648
+ /**
1649
+ * @description Sospende l'esecuzione asincrona per un numero esatto di millisecondi.
1650
+ * @param ms I millisecondi di attesa.
1651
+ * @returns Una Promise che si risolve al termine del tempo.
1652
+
1653
+ *
1654
+ * @author Xeno
1655
+ * @version 1.0.0
1656
+ * @since 2025-09-30
1657
+ * @link https://github.com/xeno-js/xeno-js
1658
+ */
1659
+ delay(ms) {
1660
+ return new Promise((resolve) => setTimeout(resolve, ms));
1661
+ },
1662
+ /**
1663
+ * @description Introduce un ritardo asincrono composto da un tempo base più una variazione casuale.
1664
+ * Fondamentale per mitigare il "Thundering Herd problem" (effetto gregge) distribuendo
1665
+ * nel tempo i retry simultanei di più client.
1666
+ * * @param baseDelayMs Il ritardo minimo garantito.
1667
+ * @param maxJitterMs La variazione massima casuale aggiuntiva.
1668
+ * @returns Una Promise che si risolve al termine del calcolo.
1669
+
1670
+ *
1671
+ * @author Xeno
1672
+ * @version 1.0.0
1673
+ * @since 2025-09-30
1674
+ * @link https://github.com/xeno-js/xeno-js
1675
+ */
1676
+ delayWithJitter(baseDelayMs, maxJitterMs) {
1677
+ const jitter = Math.floor(Math.random() * maxJitterMs);
1678
+ return new Promise((resolve) => setTimeout(resolve, baseDelayMs + jitter));
1679
+ }
1680
+ });
1681
+
1682
+ // src/shared/utils/sanitize.utils.ts
1683
+ var start = String.fromCharCode(0);
1684
+ var end = String.fromCharCode(31);
1685
+ var del = String.fromCharCode(127);
1686
+ var CONTROL_CHARS_REGEX = new RegExp(`[\\r\\n\\t${start}-${end}${del}]`, "g");
1687
+ var DANGEROUS_PROTOCOLS_REGEX = /^(javascript|data|vbscript):/i;
1688
+ var SanitizeHelper = Object.freeze({
1689
+ /**
1690
+ * @description Removes carriage returns, line feeds, null bytes, and non-printable control characters.
1691
+ * Mitigates Log Forging and Log Injection attacks (CWE-117).
1692
+ * @param value The candidate string to sanitize.
1693
+ * @param maxLength Maximum allowable length after sanitization. Defaults to 256.
1694
+ * @returns Sanitized string or undefined if empty/non-string.
1695
+ */
1696
+ stripControlChars(value, maxLength = 256) {
1697
+ if (Guards.isNullOrEmpty(value)) return void 0;
1698
+ const clean = value.replace(CONTROL_CHARS_REGEX, "").trim();
1699
+ if (Guards.isNullOrEmpty(clean)) return void 0;
1700
+ return clean.slice(0, maxLength);
1701
+ },
1702
+ /**
1703
+ * @description Sanitizes navigation paths and URLs, removing control characters
1704
+ * and preventing execution of dangerous pseudo-protocols (e.g. javascript:, data:).
1705
+ * @param path The path string to sanitize.
1706
+ * @param maxLength Maximum length of the path. Defaults to 512.
1707
+ * @returns Sanitized path or '/' fallback for unsafe inputs.
1708
+ */
1709
+ sanitizePath(path, maxLength = 512) {
1710
+ if (Guards.isNullOrEmpty(path)) return void 0;
1711
+ const clean = path.replace(CONTROL_CHARS_REGEX, "").trim();
1712
+ if (Guards.isNullOrEmpty(clean) || DANGEROUS_PROTOCOLS_REGEX.test(clean)) {
1713
+ return "/";
1714
+ }
1715
+ return clean.slice(0, maxLength);
1716
+ },
1717
+ /**
1718
+ * @description Sanitizes an array of strings (e.g. roles, permissions, scopes).
1719
+ * Strips control characters, filters out empty entries, and limits collection size.
1720
+ * @param items Array of strings to sanitize.
1721
+ * @param maxItemLength Maximum allowable character length per item. Defaults to 64.
1722
+ * @param maxItems Maximum total number of elements kept. Defaults to 50.
1723
+ * @returns Immutable array of sanitized strings.
1724
+ */
1725
+ sanitizeStringArray(items, maxItemLength = 64, maxItems = 50) {
1726
+ if (Guards.isNullOrEmpty(items)) return void 0;
1727
+ const sanitized = items.slice(0, maxItems).map((item) => SanitizeHelper.stripControlChars(item, maxItemLength)).filter((item) => Guards.isDefined(item));
1728
+ return sanitized;
1729
+ }
1730
+ });
1731
+
1732
+ // src/shared/utils/string.utils.ts
1733
+ var StringHelper = Object.freeze({
1734
+ /**
1735
+ * @description Safely converts a value to a JSON string, falling back to String() on failure.
1736
+ * @param value The value to stringify.
1737
+ * @returns A JSON string representation of the value, or a fallback string if serialization fails.
1738
+
1739
+ *
1740
+ * @author Xeno
1741
+ * @version 1.0.0
1742
+ * @since 2025-09-30
1743
+ * @link https://github.com/xeno-js/xeno-js
1744
+ */
1745
+ safeStringify(value) {
1746
+ try {
1747
+ return JSON.stringify(value);
1748
+ } catch {
1749
+ return String(value);
1750
+ }
1751
+ },
1752
+ /**
1753
+ * @description Safely parses a JSON string, returning a fallback value on failure.
1754
+ * @param input The JSON string to parse.
1755
+ * @param fallback Optional fallback value to return if parsing fails.
1756
+ * @returns The parsed value, or the fallback value if parsing fails.
1757
+
1758
+ *
1759
+ * @author Xeno
1760
+ * @version 1.0.0
1761
+ * @since 2025-09-30
1762
+ * @link https://github.com/xeno-js/xeno-js
1763
+ */
1764
+ safeParse(input, fallback = void 0) {
1765
+ try {
1766
+ return JSON.parse(input);
1767
+ } catch {
1768
+ return fallback ?? input;
1769
+ }
1770
+ },
1771
+ /**
1772
+ * @description Converts a string to camelCase.
1773
+ * @param input Input string (supports snake_case, kebab-case, or space-separated).
1774
+ * @returns camelCase string.
1775
+
1776
+ *
1777
+ * @author Xeno
1778
+ * @version 1.0.0
1779
+ * @since 2025-09-30
1780
+ * @link https://github.com/xeno-js/xeno-js
1781
+ */
1782
+ camelCase(input) {
1783
+ const segments = input.split(/[-_\s]+/);
1784
+ const [first, ...rest] = segments;
1785
+ const head = Guards.isDefined(first) ? first.toLowerCase() : "";
1786
+ return head + rest.map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1)).join("");
1787
+ },
1788
+ /**
1789
+ * @description Interpolates {{key}} placeholders in a template string.
1790
+ * @param template Template string with {{key}} tokens.
1791
+ * @param vars Key-value substitution map.
1792
+ * @returns Interpolated string with resolved placeholders.
1793
+
1794
+ *
1795
+ * @author Xeno
1796
+ * @version 1.0.0
1797
+ * @since 2025-09-30
1798
+ * @link https://github.com/xeno-js/xeno-js
1799
+ */
1800
+ interpolate(template, vars) {
1801
+ return template.replace(/\{\{(\w+)\}\}/g, (_match, key) => {
1802
+ const value = vars[key];
1803
+ return Guards.isDefined(value) ? String(value) : `{{${key}}}`;
1804
+ });
1805
+ },
1806
+ /**
1807
+ * @description Truncates a string to maxLength, appending a suffix when truncated.
1808
+ * @param input Input string.
1809
+ * @param maxLength Maximum character length including the suffix.
1810
+ * @param suffix Appended suffix on truncation.
1811
+ * @returns Truncated string.
1812
+
1813
+ *
1814
+ * @author Xeno
1815
+ * @version 1.0.0
1816
+ * @since 2025-09-30
1817
+ * @link https://github.com/xeno-js/xeno-js
1818
+ */
1819
+ truncate(input, maxLength, suffix = "\u2026") {
1820
+ if (input.length <= maxLength) return input;
1821
+ const cutAt = Math.max(0, maxLength - suffix.length);
1822
+ return input.slice(0, cutAt) + suffix;
1823
+ },
1824
+ /**
1825
+ * @description Generates a reference code with a prefix, random alphanumeric part, and year.
1826
+ * @param prefix Custom prefix for the reference code (e.g., "TRV" for travel).
1827
+ * @returns Formatted reference code string.
1828
+
1829
+ *
1830
+ * @author Xeno
1831
+ * @version 1.0.0
1832
+ * @since 2025-09-30
1833
+ * @link https://github.com/xeno-js/xeno-js
1834
+ */
1835
+ generateReferenceCode(prefix) {
1836
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1837
+ let randomPart = "";
1838
+ for (let i = 0; i < 6; i++) {
1839
+ randomPart += chars.charAt(Math.floor(Math.random() * chars.length));
1840
+ }
1841
+ const year = (/* @__PURE__ */ new Date()).getFullYear();
1842
+ return `${prefix}-${randomPart}-${year}`;
1843
+ },
1844
+ /**
1845
+ * @description Extracts a single string value from a header that may be a string or an array of strings.
1846
+ * @param value The header value, which can be a string or an array of strings.
1847
+ * @returns The first string value if it's an array, the string itself if it's a string, or undefined if it's empty or not defined.
1848
+
1849
+ *
1850
+ * @author Xeno
1851
+ * @version 1.0.0
1852
+ * @since 2025-09-30
1853
+ * @link https://github.com/xeno-js/xeno-js
1854
+ */
1855
+ getSingleValue(value, separator) {
1856
+ if (!Guards.isDefined(value)) return value;
1857
+ if (Guards.isArray(value)) {
1858
+ if (Guards.isNullOrEmpty(value)) {
1859
+ return void 0;
1860
+ }
1861
+ if (Guards.isDefined(separator))
1862
+ return StringHelper.getSingleValueWithSplit(value[0], separator);
1863
+ return value[0];
1864
+ }
1865
+ if (Guards.isDefined(separator)) return StringHelper.getSingleValueWithSplit(value, separator);
1866
+ return value;
1867
+ },
1868
+ getSingleValueWithSplit(value, separator) {
1869
+ if (value.includes(separator)) return value.split(separator)[0].trim();
1870
+ return value;
1871
+ }
1872
+ });
1873
+
1874
+ // src/domain/errors/app-error.ts
1875
+ var AppError = class _AppError extends Error {
1876
+ /**
1877
+ * The error code representing the type of error.
1878
+
1879
+ *
1880
+ * @author Xeno
1881
+ * @version 1.0.0
1882
+ * @since 2025-09-30
1883
+ * @link https://github.com/xeno-js/xeno-js
1884
+ */
1885
+ code;
1886
+ /**
1887
+ * The HTTP status code associated with the error.
1888
+
1889
+ *
1890
+ * @author Xeno
1891
+ * @version 1.0.0
1892
+ * @since 2025-09-30
1893
+ * @link https://github.com/xeno-js/xeno-js
1894
+ */
1895
+ status;
1896
+ /**
1897
+ * Private constructor to prevent direct instantiation. Use the static methods `create` and `throw` to create instances.
1898
+ *
1899
+ * @param payload - The payload containing error details.
1900
+
1901
+ *
1902
+ * @author Xeno
1903
+ * @version 1.0.0
1904
+ * @since 2025-09-30
1905
+ * @link https://github.com/xeno-js/xeno-js
1906
+ */
1907
+ constructor(payload) {
1908
+ super(payload.message);
1909
+ this.code = payload.code;
1910
+ this.status = payload.status;
1911
+ Object.assign(this, payload);
1912
+ }
1913
+ /**
1914
+ * Creates an AppError instance with the given error payload.
1915
+ *
1916
+ * @param payload - The payload containing error details.
1917
+ * @returns An AppError instance representing the error.
1918
+
1919
+ *
1920
+ * @author Xeno
1921
+ * @version 1.0.0
1922
+ * @since 2025-09-30
1923
+ * @link https://github.com/xeno-js/xeno-js
1924
+ */
1925
+ static create(payload) {
1926
+ return new _AppError(payload);
1927
+ }
1928
+ /**
1929
+ * Creates an AppError instance and throws it immediately.
1930
+ * @param payload - The payload containing error details.
1931
+ * @throws An AppError instance representing the error.
1932
+
1933
+ *
1934
+ * @author Xeno
1935
+ * @version 1.0.0
1936
+ * @since 2025-09-30
1937
+ * @link https://github.com/xeno-js/xeno-js
1938
+ */
1939
+ static throw(payload) {
1940
+ throw new _AppError(payload);
1941
+ }
1942
+ /**
1943
+ * Creates an AppError instance representing an aborted request.
1944
+ * @param name - The name of the error, typically the class name or context where the error occurred.
1945
+ * @returns An AppError instance representing the aborted request error.
1946
+
1947
+ *
1948
+ * @author Xeno
1949
+ * @version 1.0.0
1950
+ * @since 2025-09-30
1951
+ * @link https://github.com/xeno-js/xeno-js
1952
+ */
1953
+ static aborted(name) {
1954
+ return new _AppError({
1955
+ code: ERROR_CODES.ABORTED,
1956
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.ABORTED],
1957
+ status: STATUS_CODES.ABORTED,
1958
+ name,
1959
+ cause: new Error("The client closed the connection before the server finished responding.")
1960
+ });
1961
+ }
1962
+ /**
1963
+ * Utility method to check if an AbortSignal has been triggered and throw an AppError if it has.
1964
+ * @param signal - The AbortSignal to check for abortion.
1965
+ * @param name - The name of the error, typically the class name or context where the error occurred.
1966
+
1967
+ *
1968
+ * @author Xeno
1969
+ * @version 1.0.0
1970
+ * @since 2025-09-30
1971
+ * @link https://github.com/xeno-js/xeno-js
1972
+ */
1973
+ static throwIfAborted(signal, name) {
1974
+ if (Guards.isDefined(signal) && signal.aborted) {
1975
+ throw _AppError.aborted(name);
1976
+ }
1977
+ }
1978
+ /** @description Creates an AppError instance representing an unauthorized access error. This method is used to generate a standardized error response when a user attempts to access a resource or perform an action without the necessary authentication or authorization.
1979
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
1980
+ * @param message A custom message describing the reason for the unauthorized access. This message is included in the AppError's cause for detailed error reporting.
1981
+ * @returns An AppError instance representing the unauthorized access error.
1982
+ *
1983
+ * @author Xeno
1984
+ * @version 1.0.0
1985
+ * @since 2025-09-30
1986
+ * @link https://github.com/xeno-js/xeno-js
1987
+ */
1988
+ static unauthorized(name, message) {
1989
+ return _AppError.create({
1990
+ code: ERROR_CODES.UNAUTHORIZED,
1991
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.UNAUTHORIZED],
1992
+ status: STATUS_CODES.UNAUTHORIZED,
1993
+ name,
1994
+ cause: new Error(message),
1995
+ header: { "WWW-Authenticate": ['Bearer realm="api"'] }
1996
+ });
1997
+ }
1998
+ static notSupported(name, message) {
1999
+ return _AppError.create({
2000
+ code: ERROR_CODES.NOT_ALLOWED,
2001
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.NOT_ALLOWED],
2002
+ status: STATUS_CODES.NOT_ALLOWED,
2003
+ name,
2004
+ cause: new Error(message)
2005
+ });
2006
+ }
2007
+ /** @description Creates an AppError instance representing a forbidden access error. This method is used to generate a standardized error response when a user attempts to access a resource or perform an action that they are not authorized to access, even if they are authenticated.
2008
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
2009
+ * @param message A custom message describing the reason for the forbidden access. This message is included in the AppError's cause for detailed error reporting.
2010
+ * @returns An AppError instance representing the forbidden access error.
2011
+ *
2012
+ * @author Xeno
2013
+ * @version 1.0.0
2014
+ * @since 2025-09-30
2015
+ * @link https://github.com/xeno-js/xeno-js
2016
+ */
2017
+ static forbidden(name, message) {
2018
+ return _AppError.create({
2019
+ code: ERROR_CODES.FORBIDDEN,
2020
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.FORBIDDEN],
2021
+ status: STATUS_CODES.FORBIDDEN,
2022
+ name,
2023
+ cause: new Error(message)
2024
+ });
2025
+ }
2026
+ /** @description Creates an AppError instance representing a bad request error. This method is used to generate a standardized error response when a request made by the client is invalid or cannot be processed due to client-side issues, such as validation errors or malformed requests.
2027
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
2028
+ * @param message A custom message describing the reason for the bad request. This message is included in the AppError's cause for detailed error reporting.
2029
+ * @returns An AppError instance representing the bad request error.
2030
+ *
2031
+ * @author Xeno
2032
+ * @version 1.0.0
2033
+ * @since 2025-09-30
2034
+ * @link https://github.com/xeno-js/xeno-js
2035
+ */
2036
+ static badRequest(name, message) {
2037
+ return _AppError.create({
2038
+ code: ERROR_CODES.BAD_REQUEST,
2039
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.BAD_REQUEST],
2040
+ status: STATUS_CODES.BAD_REQUEST,
2041
+ name,
2042
+ cause: new Error(message)
2043
+ });
2044
+ }
2045
+ /** @description Creates an AppError instance representing a validation error. This method is used to generate a standardized error response when one or more input fields fail invariant or schema validation, indicating that the request cannot be processed due to invalid data.
2046
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
2047
+ * @param message A custom message describing the reason for the validation failure. This message is included in the AppError's cause for detailed error reporting.
2048
+ * @returns An AppError instance representing the validation error.
2049
+ *
2050
+ * @author Xeno
2051
+ * @version 1.0.0
2052
+ * @since 2025-09-30
2053
+ * @link https://github.com/xeno-js/xeno-js
2054
+ */
2055
+ static validationError(name, message) {
2056
+ return _AppError.create({
2057
+ code: ERROR_CODES.VALIDATION_FAILED,
2058
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.VALIDATION_FAILED],
2059
+ status: STATUS_CODES.BAD_REQUEST,
2060
+ name,
2061
+ cause: new Error(message)
2062
+ });
2063
+ }
2064
+ /** @description Creates an AppError instance representing a conflict error. This method is used to generate a standardized error response when a request conflicts with the current state of the resource, such as when attempting to create a resource that already exists or update a resource that has been modified by another process.
2065
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
2066
+ * @param message A custom message describing the reason for the conflict. This message is included in the AppError's cause for detailed error reporting.
2067
+ * @returns An AppError instance representing the conflict error.
2068
+ *
2069
+ * @author Xeno
2070
+ * @version 1.0.0
2071
+ * @since 2025-09-30
2072
+ * @link https://github.com/xeno-js/xeno-js
2073
+ */
2074
+ static conflict(name, message) {
2075
+ return _AppError.create({
2076
+ code: ERROR_CODES.CONFLICT,
2077
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.CONFLICT],
2078
+ status: STATUS_CODES.CONFLICT,
2079
+ name,
2080
+ cause: new Error(message)
2081
+ });
2082
+ }
2083
+ /** @description Creates an AppError instance representing a not found error. This method is used to generate a standardized error response when a requested resource does not exist, indicating that the client attempted to access a resource that could not be found on the server.
2084
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
2085
+ * @param message A custom message describing the reason for the not found error. This message is included in the AppError's cause for detailed error reporting.
2086
+ * @returns An AppError instance representing the not found error.
2087
+ *
2088
+ * @author Xeno
2089
+ * @version 1.0.0
2090
+ * @since 2025-09-30
2091
+ * @link https://github.com/xeno-js/xeno-js
2092
+ */
2093
+ static notFound(name, message) {
2094
+ return _AppError.create({
2095
+ code: ERROR_CODES.NOT_FOUND,
2096
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.NOT_FOUND],
2097
+ status: STATUS_CODES.NOT_FOUND,
2098
+ name,
2099
+ cause: new Error(message)
2100
+ });
2101
+ }
2102
+ /** @description Creates an AppError instance representing a Authentication failed. This method is used to generate a standardized error response when an auth requested produce an error..
2103
+ * @param name The name of the error, typically the class name or context where the error occurred. This helps in identifying the source of the error in logs and error reports.
2104
+ * @param message A custom message describing the reason for the Authentication failed. This message is included in the AppError's cause for detailed error reporting.
2105
+ * @returns An AppError instance representing the Authentication failed.
2106
+ *
2107
+ * @author Xeno
2108
+ * @version 1.0.0
2109
+ * @since 2025-09-30
2110
+ * @link https://github.com/xeno-js/xeno-js
2111
+ */
2112
+ static authFailed(name, message) {
2113
+ return _AppError.create({
2114
+ code: ERROR_CODES.AUTHENTICATION_FAILED,
2115
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.AUTHENTICATION_FAILED],
2116
+ name,
2117
+ status: STATUS_CODES.UNAUTHORIZED,
2118
+ cause: new Error(message)
2119
+ });
2120
+ }
2121
+ };
2122
+
2123
+ // src/infrastructure/http/axios.http.ts
2124
+ var AxiosHttpClient = class {
2125
+ constructor(_client) {
2126
+ this._client = _client;
2127
+ }
2128
+ _client;
2129
+ async executInAsync(callback, opts) {
2130
+ AppError.throwIfAborted(opts.signal, opts.name);
2131
+ try {
2132
+ return await callback();
2133
+ } catch (error) {
2134
+ this.handleError(error, "AxiosHttpClient.get");
2135
+ }
2136
+ }
2137
+ async get(url, options) {
2138
+ return await this.executInAsync(
2139
+ async () => {
2140
+ const response = await this._client.get(url, this.buildConfig(options));
2141
+ return this.handleResponse(response);
2142
+ },
2143
+ { signal: options?.signal, name: "AxiosHttpClient.get" }
2144
+ );
2145
+ }
2146
+ async post(url, body, options) {
2147
+ return await this.executInAsync(
2148
+ async () => {
2149
+ const response = await this._client.post(url, body, this.buildConfig(options));
2150
+ return this.handleResponse(response);
2151
+ },
2152
+ { signal: options?.signal, name: "AxiosHttpClient.post" }
2153
+ );
2154
+ }
2155
+ async put(url, body, options) {
2156
+ return await this.executInAsync(
2157
+ async () => {
2158
+ const response = await this._client.put(url, body, this.buildConfig(options));
2159
+ return this.handleResponse(response);
2160
+ },
2161
+ { signal: options?.signal, name: "AxiosHttpClient.put" }
2162
+ );
2163
+ }
2164
+ async patch(url, body, options) {
2165
+ return await this.executInAsync(
2166
+ async () => {
2167
+ const response = await this._client.patch(url, body, this.buildConfig(options));
2168
+ return this.handleResponse(response);
2169
+ },
2170
+ { signal: options?.signal, name: "AxiosHttpClient.patch" }
2171
+ );
2172
+ }
2173
+ async delete(url, options) {
2174
+ return await this.executInAsync(
2175
+ async () => {
2176
+ const response = await this._client.delete(url, this.buildConfig(options));
2177
+ return this.handleResponse(response);
2178
+ },
2179
+ { signal: options?.signal, name: "AxiosHttpClient.delete" }
2180
+ );
2181
+ }
2182
+ buildConfig(options) {
2183
+ return {
2184
+ headers: options?.headers,
2185
+ params: options?.query,
2186
+ signal: options?.signal,
2187
+ timeout: options?.timeoutMs,
2188
+ validateStatus: () => true
2189
+ };
2190
+ }
2191
+ handleResponse(response) {
2192
+ if (!Guards.isDefined(response.status) || response.status >= 400) {
2193
+ AppError.throw({
2194
+ code: ERROR_CODES.EXTERNAL_SERVICE_ERROR,
2195
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.EXTERNAL_SERVICE_ERROR],
2196
+ status: response.status,
2197
+ name: "AxiosHttpClientException",
2198
+ cause: new import_axios.AxiosError(
2199
+ `Request failed with status code ${response.status}`,
2200
+ ERROR_CODES.EXTERNAL_SERVICE_ERROR,
2201
+ response.config,
2202
+ response.request,
2203
+ response
2204
+ )
2205
+ });
2206
+ }
2207
+ return {
2208
+ status: response.status,
2209
+ ok: response.status >= 200 && response.status < 300,
2210
+ headers: HttpHelper.normalizeHeaders(response.headers),
2211
+ data: response.data
2212
+ };
2213
+ }
2214
+ handleError(error, name) {
2215
+ if (error instanceof AppError) throw error;
2216
+ const status = error instanceof import_axios.AxiosError && Guards.isDefined(error.response) ? error.response.status : STATUS_CODES.INTERNAL_SERVER_ERROR;
2217
+ AppError.throw({
2218
+ code: ERROR_CODES.EXTERNAL_SERVICE_ERROR,
2219
+ message: ERROR_CODE_MESSAGES[ERROR_CODES.EXTERNAL_SERVICE_ERROR],
2220
+ status,
2221
+ name,
2222
+ cause: error
2223
+ });
2224
+ }
2225
+ };
2226
+ // Annotate the CommonJS export names for ESM import in node:
2227
+ 0 && (module.exports = {
2228
+ AxiosHttpClient
2229
+ });
2230
+ //# sourceMappingURL=axios.cjs.map