@vritti/api-sdk 0.0.6 → 0.0.8

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
- import { DynamicModule, OnModuleDestroy, OnModuleInit, Logger, CanActivate, ExecutionContext, ExceptionFilter, ArgumentsHost } from '@nestjs/common';
2
+ import { DynamicModule, OnModuleDestroy, OnModuleInit, Logger, CanActivate, ExecutionContext, ExceptionFilter, ArgumentsHost, HttpException, HttpStatus } from '@nestjs/common';
3
3
  import { ConfigService } from '@nestjs/config';
4
4
  import { Reflector } from '@nestjs/core';
5
5
  import { JwtService } from '@nestjs/jwt';
@@ -1300,29 +1300,468 @@ declare class CsrfGuard implements CanActivate {
1300
1300
  }
1301
1301
 
1302
1302
  /**
1303
- * Global HTTP Exception Filter
1303
+ * Converts an HTTP status code to its corresponding title string.
1304
+ * Uses the HttpStatus enum to map status codes to human-readable titles.
1304
1305
  *
1305
- * Standardizes all error responses in the format:
1306
+ * @param status - The HTTP status code
1307
+ * @returns The human-readable title for the status code
1308
+ *
1309
+ * @example
1310
+ * getHttpStatusTitle(400) // Returns: "Bad Request"
1311
+ * getHttpStatusTitle(404) // Returns: "Not Found"
1312
+ * getHttpStatusTitle(500) // Returns: "Internal Server Error"
1313
+ */
1314
+ declare function getHttpStatusTitle(status: number): string;
1315
+ /**
1316
+ * Global HTTP Exception Filter implementing RFC 7807 Problem Details
1317
+ *
1318
+ * Transforms all exceptions into a standardized RFC 7807 format:
1306
1319
  * {
1307
- * errors: [{ field: string, message: string }],
1308
- * message?: string,
1309
- * statusCode: number,
1310
- * timestamp: string,
1311
- * path: string
1320
+ * title: string, // Human-readable status title
1321
+ * status: number, // HTTP status code
1322
+ * detail: string, // Detailed error description
1323
+ * errors: FieldError[] // Field-specific error messages
1312
1324
  * }
1313
1325
  *
1314
1326
  * Handles:
1315
- * - Validation errors (class-validator) - Converts to field-specific errors
1316
- * - HTTP exceptions - Maps to standardized format
1317
- * - Unknown errors - Returns generic 500 error
1327
+ * - Custom field exceptions from @vritti/api-sdk (BaseFieldException)
1328
+ * - Class-validator DTO validation errors
1329
+ * - Standard NestJS HTTP exceptions
1330
+ * - Unknown errors
1318
1331
  */
1319
1332
  declare class HttpExceptionFilter implements ExceptionFilter {
1320
1333
  private readonly logger;
1321
1334
  catch(exception: unknown, host: ArgumentsHost): void;
1322
- /**
1323
- * Parse class-validator error messages into field-specific errors
1324
- */
1325
- private parseValidationErrors;
1326
1335
  }
1327
1336
 
1328
- export { AuthConfigModule, CsrfGuard, DatabaseModule, type DatabaseModuleOptions, HttpExceptionFilter, HttpModule, Onboarding, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, Public, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, VrittiAuthGuard };
1337
+ interface FieldError$1 {
1338
+ field?: string;
1339
+ message: string;
1340
+ }
1341
+ interface ProblemDetails {
1342
+ title: string;
1343
+ status: number;
1344
+ detail: string;
1345
+ }
1346
+ interface ApiErrorResponse extends ProblemDetails {
1347
+ errors: FieldError$1[];
1348
+ }
1349
+
1350
+ interface FieldError {
1351
+ field?: string;
1352
+ message: string;
1353
+ }
1354
+ declare abstract class BaseFieldException extends HttpException {
1355
+ constructor(statusOrMessageOrErrors: HttpStatus | string | FieldError[], messageOrStatus?: string | HttpStatus, statusOrDetail?: HttpStatus | string, detail?: string);
1356
+ }
1357
+
1358
+ /**
1359
+ * Exception thrown when a request is malformed or contains invalid data (HTTP 400).
1360
+ *
1361
+ * @example
1362
+ * // Simple message
1363
+ * throw new BadRequestException('Invalid request data');
1364
+ *
1365
+ * // Field-specific error
1366
+ * throw new BadRequestException('email', 'Invalid email format');
1367
+ *
1368
+ * // With detail
1369
+ * throw new BadRequestException('email', 'Invalid email format', 'Email must be in valid format');
1370
+ *
1371
+ * // Multiple field errors
1372
+ * throw new BadRequestException([
1373
+ * { field: 'email', message: 'Invalid email' },
1374
+ * { field: 'password', message: 'Password too short' }
1375
+ * ]);
1376
+ */
1377
+ declare class BadRequestException extends BaseFieldException {
1378
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1379
+ }
1380
+
1381
+ /**
1382
+ * Exception thrown when authentication is required or has failed (HTTP 401).
1383
+ *
1384
+ * @example
1385
+ * // Simple message
1386
+ * throw new UnauthorizedException('Authentication required');
1387
+ *
1388
+ * // Field-specific error
1389
+ * throw new UnauthorizedException('token', 'Invalid or expired token');
1390
+ *
1391
+ * // With detail
1392
+ * throw new UnauthorizedException('token', 'Invalid token', 'Please login again');
1393
+ *
1394
+ * // Multiple field errors
1395
+ * throw new UnauthorizedException([
1396
+ * { field: 'token', message: 'Token expired' }
1397
+ * ]);
1398
+ */
1399
+ declare class UnauthorizedException extends BaseFieldException {
1400
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1401
+ }
1402
+
1403
+ /**
1404
+ * Exception thrown when the user does not have permission to access a resource (HTTP 403).
1405
+ *
1406
+ * @example
1407
+ * // Simple message
1408
+ * throw new ForbiddenException('Access denied');
1409
+ *
1410
+ * // Field-specific error
1411
+ * throw new ForbiddenException('resource', 'You do not have permission');
1412
+ *
1413
+ * // With detail
1414
+ * throw new ForbiddenException('resource', 'Access denied', 'Admin role required');
1415
+ *
1416
+ * // Multiple field errors
1417
+ * throw new ForbiddenException([
1418
+ * { field: 'action', message: 'Insufficient permissions' }
1419
+ * ]);
1420
+ */
1421
+ declare class ForbiddenException extends BaseFieldException {
1422
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1423
+ }
1424
+
1425
+ /**
1426
+ * Exception thrown when a requested resource cannot be found (HTTP 404).
1427
+ *
1428
+ * @example
1429
+ * // Simple message
1430
+ * throw new NotFoundException('Resource not found');
1431
+ *
1432
+ * // Field-specific error
1433
+ * throw new NotFoundException('userId', 'User not found');
1434
+ *
1435
+ * // With detail
1436
+ * throw new NotFoundException('userId', 'User not found', 'No user exists with the provided ID');
1437
+ *
1438
+ * // Multiple field errors
1439
+ * throw new NotFoundException([
1440
+ * { field: 'userId', message: 'User does not exist' }
1441
+ * ]);
1442
+ */
1443
+ declare class NotFoundException extends BaseFieldException {
1444
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1445
+ }
1446
+
1447
+ /**
1448
+ * Exception thrown when a request conflicts with the current state (HTTP 409).
1449
+ * Commonly used for duplicate resources or concurrent modification issues.
1450
+ *
1451
+ * @example
1452
+ * // Simple message
1453
+ * throw new ConflictException('Resource already exists');
1454
+ *
1455
+ * // Field-specific error
1456
+ * throw new ConflictException('email', 'Email already registered');
1457
+ *
1458
+ * // With detail
1459
+ * throw new ConflictException('email', 'Email already exists', 'Try logging in instead');
1460
+ *
1461
+ * // Multiple field errors
1462
+ * throw new ConflictException([
1463
+ * { field: 'email', message: 'Email already in use' }
1464
+ * ]);
1465
+ */
1466
+ declare class ConflictException extends BaseFieldException {
1467
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1468
+ }
1469
+
1470
+ /**
1471
+ * Exception thrown when an unexpected server error occurs (HTTP 500).
1472
+ *
1473
+ * @example
1474
+ * // Simple message
1475
+ * throw new InternalServerErrorException('An unexpected error occurred');
1476
+ *
1477
+ * // Field-specific error
1478
+ * throw new InternalServerErrorException('database', 'Database connection failed');
1479
+ *
1480
+ * // With detail
1481
+ * throw new InternalServerErrorException('database', 'Connection failed', 'Please try again later');
1482
+ *
1483
+ * // Multiple field errors
1484
+ * throw new InternalServerErrorException([
1485
+ * { field: 'system', message: 'Internal error' }
1486
+ * ]);
1487
+ */
1488
+ declare class InternalServerErrorException extends BaseFieldException {
1489
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1490
+ }
1491
+
1492
+ /**
1493
+ * Exception thrown when request validation fails (HTTP 400).
1494
+ * Typically used for form validation or DTO validation errors.
1495
+ *
1496
+ * @example
1497
+ * // Multiple validation errors
1498
+ * throw new ValidationException([
1499
+ * { field: 'email', message: 'Invalid email format' },
1500
+ * { field: 'password', message: 'Password must be at least 8 characters' }
1501
+ * ]);
1502
+ *
1503
+ * // With detail
1504
+ * throw new ValidationException(
1505
+ * [{ field: 'email', message: 'Invalid format' }],
1506
+ * 'Please correct the errors and try again'
1507
+ * );
1508
+ */
1509
+ declare class ValidationException extends BaseFieldException {
1510
+ constructor(errors: FieldError[], detail?: string);
1511
+ }
1512
+
1513
+ /**
1514
+ * Exception thrown when the request is well-formed but contains semantic errors (HTTP 422).
1515
+ * Used for business logic validation failures that prevent processing.
1516
+ *
1517
+ * @example
1518
+ * // Simple message
1519
+ * throw new UnprocessableEntityException('Cannot process the request');
1520
+ *
1521
+ * // Field-specific error
1522
+ * throw new UnprocessableEntityException('age', 'Age must be 18 or older');
1523
+ *
1524
+ * // With detail
1525
+ * throw new UnprocessableEntityException('quantity', 'Insufficient stock', 'Only 5 items available');
1526
+ *
1527
+ * // Multiple field errors
1528
+ * throw new UnprocessableEntityException([
1529
+ * { field: 'startDate', message: 'Start date must be before end date' },
1530
+ * { field: 'endDate', message: 'End date cannot be in the past' }
1531
+ * ]);
1532
+ */
1533
+ declare class UnprocessableEntityException extends BaseFieldException {
1534
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1535
+ }
1536
+
1537
+ /**
1538
+ * Exception thrown when rate limiting is triggered (HTTP 429).
1539
+ * Used to prevent abuse and ensure fair resource usage.
1540
+ *
1541
+ * @example
1542
+ * // Simple message
1543
+ * throw new TooManyRequestsException('Too many requests');
1544
+ *
1545
+ * // Field-specific error
1546
+ * throw new TooManyRequestsException('api', 'Rate limit exceeded');
1547
+ *
1548
+ * // With detail
1549
+ * throw new TooManyRequestsException('api', 'Rate limit exceeded', 'Try again in 60 seconds');
1550
+ *
1551
+ * // Multiple field errors
1552
+ * throw new TooManyRequestsException([
1553
+ * { field: 'requests', message: 'Rate limit exceeded for this endpoint' }
1554
+ * ]);
1555
+ */
1556
+ declare class TooManyRequestsException extends BaseFieldException {
1557
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1558
+ }
1559
+
1560
+ /**
1561
+ * Exception thrown when the service is temporarily unavailable (HTTP 503).
1562
+ * Used during maintenance, overload, or temporary outages.
1563
+ *
1564
+ * @example
1565
+ * // Simple message
1566
+ * throw new ServiceUnavailableException('Service temporarily unavailable');
1567
+ *
1568
+ * // Field-specific error
1569
+ * throw new ServiceUnavailableException('service', 'Scheduled maintenance in progress');
1570
+ *
1571
+ * // With detail
1572
+ * throw new ServiceUnavailableException('service', 'Maintenance', 'Service will be back at 2 PM EST');
1573
+ *
1574
+ * // Multiple field errors
1575
+ * throw new ServiceUnavailableException([
1576
+ * { field: 'database', message: 'Database is temporarily unavailable' }
1577
+ * ]);
1578
+ */
1579
+ declare class ServiceUnavailableException extends BaseFieldException {
1580
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1581
+ }
1582
+
1583
+ /**
1584
+ * Exception thrown when an HTTP method is not supported for the endpoint (HTTP 405).
1585
+ * For example, when a POST is sent to a GET-only endpoint.
1586
+ *
1587
+ * @example
1588
+ * // Simple message
1589
+ * throw new MethodNotAllowedException('Method not allowed');
1590
+ *
1591
+ * // Field-specific error
1592
+ * throw new MethodNotAllowedException('method', 'POST method not allowed on this endpoint');
1593
+ *
1594
+ * // With detail
1595
+ * throw new MethodNotAllowedException('method', 'Not allowed', 'Only GET and PUT are supported');
1596
+ *
1597
+ * // Multiple field errors
1598
+ * throw new MethodNotAllowedException([
1599
+ * { field: 'method', message: 'DELETE is not allowed on this resource' }
1600
+ * ]);
1601
+ */
1602
+ declare class MethodNotAllowedException extends BaseFieldException {
1603
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1604
+ }
1605
+
1606
+ /**
1607
+ * Exception thrown when a resource has been permanently removed (HTTP 410).
1608
+ * Unlike 404, this indicates the resource existed but is intentionally gone.
1609
+ *
1610
+ * @example
1611
+ * // Simple message
1612
+ * throw new GoneException('Resource permanently deleted');
1613
+ *
1614
+ * // Field-specific error
1615
+ * throw new GoneException('account', 'Account has been permanently deleted');
1616
+ *
1617
+ * // With detail
1618
+ * throw new GoneException('account', 'Deleted', 'This account was removed on user request');
1619
+ *
1620
+ * // Multiple field errors
1621
+ * throw new GoneException([
1622
+ * { field: 'resource', message: 'This content has been permanently removed' }
1623
+ * ]);
1624
+ */
1625
+ declare class GoneException extends BaseFieldException {
1626
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1627
+ }
1628
+
1629
+ /**
1630
+ * Exception thrown when content negotiation fails (HTTP 406).
1631
+ * Used when the server cannot produce a response matching the Accept headers.
1632
+ *
1633
+ * @example
1634
+ * // Simple message
1635
+ * throw new NotAcceptableException('Requested format not available');
1636
+ *
1637
+ * // Field-specific error
1638
+ * throw new NotAcceptableException('accept', 'Cannot produce response in requested format');
1639
+ *
1640
+ * // With detail
1641
+ * throw new NotAcceptableException('accept', 'Format not supported', 'Only JSON is available');
1642
+ *
1643
+ * // Multiple field errors
1644
+ * throw new NotAcceptableException([
1645
+ * { field: 'contentType', message: 'XML format is not supported' }
1646
+ * ]);
1647
+ */
1648
+ declare class NotAcceptableException extends BaseFieldException {
1649
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1650
+ }
1651
+
1652
+ /**
1653
+ * Exception thrown when a request takes too long to process (HTTP 408).
1654
+ * Used when the client or server times out while waiting for completion.
1655
+ *
1656
+ * @example
1657
+ * // Simple message
1658
+ * throw new RequestTimeoutException('Request timeout');
1659
+ *
1660
+ * // Field-specific error
1661
+ * throw new RequestTimeoutException('operation', 'Operation timed out');
1662
+ *
1663
+ * // With detail
1664
+ * throw new RequestTimeoutException('query', 'Database query timeout', 'Try with fewer filters');
1665
+ *
1666
+ * // Multiple field errors
1667
+ * throw new RequestTimeoutException([
1668
+ * { field: 'processing', message: 'Request took too long to complete' }
1669
+ * ]);
1670
+ */
1671
+ declare class RequestTimeoutException extends BaseFieldException {
1672
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1673
+ }
1674
+
1675
+ /**
1676
+ * Exception thrown when request payload exceeds size limits (HTTP 413).
1677
+ * Commonly used for file upload size restrictions or large request bodies.
1678
+ *
1679
+ * @example
1680
+ * // Simple message
1681
+ * throw new PayloadTooLargeException('Request payload too large');
1682
+ *
1683
+ * // Field-specific error
1684
+ * throw new PayloadTooLargeException('file', 'File size exceeds maximum allowed');
1685
+ *
1686
+ * // With detail
1687
+ * throw new PayloadTooLargeException('file', 'File too large', 'Maximum size is 10MB');
1688
+ *
1689
+ * // Multiple field errors
1690
+ * throw new PayloadTooLargeException([
1691
+ * { field: 'upload', message: 'File exceeds 10MB limit' }
1692
+ * ]);
1693
+ */
1694
+ declare class PayloadTooLargeException extends BaseFieldException {
1695
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1696
+ }
1697
+
1698
+ /**
1699
+ * Exception thrown when the media type of the request is not supported (HTTP 415).
1700
+ * Used when the Content-Type header specifies an unsupported format.
1701
+ *
1702
+ * @example
1703
+ * // Simple message
1704
+ * throw new UnsupportedMediaTypeException('Unsupported media type');
1705
+ *
1706
+ * // Field-specific error
1707
+ * throw new UnsupportedMediaTypeException('contentType', 'XML is not supported');
1708
+ *
1709
+ * // With detail
1710
+ * throw new UnsupportedMediaTypeException('contentType', 'Not supported', 'Only JSON and form-data are accepted');
1711
+ *
1712
+ * // Multiple field errors
1713
+ * throw new UnsupportedMediaTypeException([
1714
+ * { field: 'contentType', message: 'application/xml is not supported' }
1715
+ * ]);
1716
+ */
1717
+ declare class UnsupportedMediaTypeException extends BaseFieldException {
1718
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1719
+ }
1720
+
1721
+ /**
1722
+ * Exception thrown when a feature or endpoint is not yet implemented (HTTP 501).
1723
+ * Used for planned but unavailable functionality.
1724
+ *
1725
+ * @example
1726
+ * // Simple message
1727
+ * throw new NotImplementedException('Feature not yet implemented');
1728
+ *
1729
+ * // Field-specific error
1730
+ * throw new NotImplementedException('feature', 'This feature is coming soon');
1731
+ *
1732
+ * // With detail
1733
+ * throw new NotImplementedException('export', 'Not implemented', 'PDF export will be available in v2.0');
1734
+ *
1735
+ * // Multiple field errors
1736
+ * throw new NotImplementedException([
1737
+ * { field: 'functionality', message: 'This functionality is not available yet' }
1738
+ * ]);
1739
+ */
1740
+ declare class NotImplementedException extends BaseFieldException {
1741
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1742
+ }
1743
+
1744
+ /**
1745
+ * Exception thrown when a gateway or proxy receives an invalid response (HTTP 502).
1746
+ * Used when a server acting as a gateway gets an error from an upstream server.
1747
+ *
1748
+ * @example
1749
+ * // Simple message
1750
+ * throw new BadGatewayException('Bad gateway');
1751
+ *
1752
+ * // Field-specific error
1753
+ * throw new BadGatewayException('upstream', 'Upstream service returned invalid response');
1754
+ *
1755
+ * // With detail
1756
+ * throw new BadGatewayException('proxy', 'Gateway error', 'Payment service is not responding correctly');
1757
+ *
1758
+ * // Multiple field errors
1759
+ * throw new BadGatewayException([
1760
+ * { field: 'gateway', message: 'Invalid response from upstream server' }
1761
+ * ]);
1762
+ */
1763
+ declare class BadGatewayException extends BaseFieldException {
1764
+ constructor(messageOrField: string | FieldError[], fieldMessageOrDetail?: string, detail?: string);
1765
+ }
1766
+
1767
+ export { type ApiErrorResponse, AuthConfigModule, BadGatewayException, BadRequestException, BaseFieldException, ConflictException, CsrfGuard, DatabaseModule, type DatabaseModuleOptions, type FieldError, ForbiddenException, GoneException, HttpExceptionFilter, HttpModule, InternalServerErrorException, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, Public, RequestTimeoutException, ServiceUnavailableException, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, TooManyRequestsException, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, ValidationException, VrittiAuthGuard, getHttpStatusTitle };