@carbonbox/domain 0.29.0 → 0.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/build/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidContractStatusError.js +24 -7
  2. package/build/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidPaymentTermsError.js +24 -7
  3. package/build/carbonbox/shared/domain/exceptions/AccountLockedError.js +58 -0
  4. package/build/carbonbox/shared/domain/exceptions/CodedRootError.js +6 -6
  5. package/build/carbonbox/shared/domain/exceptions/ConfigurationNotFoundError.js +62 -0
  6. package/build/carbonbox/shared/domain/exceptions/ContractNotFoundError.js +58 -0
  7. package/build/carbonbox/shared/domain/exceptions/EmailNotVerifiedError.js +61 -0
  8. package/build/carbonbox/shared/domain/exceptions/InvalidBusinessStatusError.js +56 -0
  9. package/build/carbonbox/shared/domain/exceptions/InvalidCredentialsError.js +35 -0
  10. package/build/carbonbox/shared/domain/exceptions/InvalidCurrencyError.js +51 -6
  11. package/build/carbonbox/shared/domain/exceptions/InvalidDateFormatError.js +1 -1
  12. package/build/carbonbox/shared/domain/exceptions/MissingCredentialsError.js +53 -0
  13. package/build/carbonbox/shared/domain/exceptions/OrderExceedsBudgetError.js +98 -0
  14. package/build/carbonbox/shared/domain/exceptions/ServiceCatalogNotFoundError.js +64 -0
  15. package/build/carbonbox/shared/domain/exceptions/StakeholderNotFoundError.js +49 -0
  16. package/build/carbonbox/shared/domain/exceptions/TokenExpiredError.js +48 -0
  17. package/build/carbonbox/stakeholders/carbon-clients/domain/entity/CarbonClient.js +10 -8
  18. package/build/carbonbox/stakeholders/carbon-coordinators/domain/entity/CarbonCoordinator.js +10 -8
  19. package/build/carbonbox/stakeholders/carbon-host/domain/entity/CarbonHost.js +5 -4
  20. package/build/carbonbox/stakeholders/carbon-managers/domain/entity/CarbonManager.js +10 -8
  21. package/build/main/index.js +31 -5
  22. package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidContractStatusError.d.ts +9 -3
  23. package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidContractStatusError.d.ts.map +1 -1
  24. package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidPaymentTermsError.d.ts +9 -3
  25. package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidPaymentTermsError.d.ts.map +1 -1
  26. package/build/types/carbonbox/shared/domain/exceptions/AccountLockedError.d.ts +25 -0
  27. package/build/types/carbonbox/shared/domain/exceptions/AccountLockedError.d.ts.map +1 -0
  28. package/build/types/carbonbox/shared/domain/exceptions/CodedRootError.d.ts.map +1 -1
  29. package/build/types/carbonbox/shared/domain/exceptions/ConfigurationNotFoundError.d.ts +29 -0
  30. package/build/types/carbonbox/shared/domain/exceptions/ConfigurationNotFoundError.d.ts.map +1 -0
  31. package/build/types/carbonbox/shared/domain/exceptions/ContractNotFoundError.d.ts +25 -0
  32. package/build/types/carbonbox/shared/domain/exceptions/ContractNotFoundError.d.ts.map +1 -0
  33. package/build/types/carbonbox/shared/domain/exceptions/EmailNotVerifiedError.d.ts +27 -0
  34. package/build/types/carbonbox/shared/domain/exceptions/EmailNotVerifiedError.d.ts.map +1 -0
  35. package/build/types/carbonbox/shared/domain/exceptions/InvalidBusinessStatusError.d.ts +25 -0
  36. package/build/types/carbonbox/shared/domain/exceptions/InvalidBusinessStatusError.d.ts.map +1 -0
  37. package/build/types/carbonbox/shared/domain/exceptions/InvalidCredentialsError.d.ts +13 -0
  38. package/build/types/carbonbox/shared/domain/exceptions/InvalidCredentialsError.d.ts.map +1 -0
  39. package/build/types/carbonbox/shared/domain/exceptions/InvalidCurrencyError.d.ts +23 -3
  40. package/build/types/carbonbox/shared/domain/exceptions/InvalidCurrencyError.d.ts.map +1 -1
  41. package/build/types/carbonbox/shared/domain/exceptions/MissingCredentialsError.d.ts +25 -0
  42. package/build/types/carbonbox/shared/domain/exceptions/MissingCredentialsError.d.ts.map +1 -0
  43. package/build/types/carbonbox/shared/domain/exceptions/OrderExceedsBudgetError.d.ts +42 -0
  44. package/build/types/carbonbox/shared/domain/exceptions/OrderExceedsBudgetError.d.ts.map +1 -0
  45. package/build/types/carbonbox/shared/domain/exceptions/ServiceCatalogNotFoundError.d.ts +29 -0
  46. package/build/types/carbonbox/shared/domain/exceptions/ServiceCatalogNotFoundError.d.ts.map +1 -0
  47. package/build/types/carbonbox/shared/domain/exceptions/StakeholderNotFoundError.d.ts +21 -0
  48. package/build/types/carbonbox/shared/domain/exceptions/StakeholderNotFoundError.d.ts.map +1 -0
  49. package/build/types/carbonbox/shared/domain/exceptions/TokenExpiredError.d.ts +21 -0
  50. package/build/types/carbonbox/shared/domain/exceptions/TokenExpiredError.d.ts.map +1 -0
  51. package/build/types/carbonbox/stakeholders/carbon-clients/domain/entity/CarbonClient.d.ts.map +1 -1
  52. package/build/types/carbonbox/stakeholders/carbon-coordinators/domain/entity/CarbonCoordinator.d.ts.map +1 -1
  53. package/build/types/carbonbox/stakeholders/carbon-host/domain/entity/CarbonHost.d.ts.map +1 -1
  54. package/build/types/carbonbox/stakeholders/carbon-managers/domain/entity/CarbonManager.d.ts.map +1 -1
  55. package/build/types/main/index.d.ts +11 -0
  56. package/build/types/main/index.d.ts.map +1 -1
  57. package/package.json +1 -1
@@ -1,19 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvalidContractStatusError = void 0;
4
- const RootError_1 = require("../../../../shared/domain/exceptions/RootError");
5
- class InvalidContractStatusError extends RootError_1.RootError {
4
+ const CodedRootError_1 = require("../../../../shared/domain/exceptions/CodedRootError");
5
+ const ErrorCode_1 = require("../../../../shared/domain/enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when an invalid contract status is provided
8
+ * This error occurs when the contract status doesn't match allowed values
9
+ *
10
+ * Error code: CBX-PMS-002
11
+ * @since 1.0.0
12
+ */
13
+ class InvalidContractStatusError extends CodedRootError_1.CodedRootError {
6
14
  constructor(contractStatus, validStatuses) {
15
+ const errorCode = ErrorCode_1.ErrorCode.INVALID_CONTRACT_STATUS;
7
16
  const validStatusesText = validStatuses.join(', ');
8
- const message = `Invalid contract status '${contractStatus}'. Valid contract statuses are: ${validStatusesText}`;
9
- super(message);
17
+ const technicalMessage = `Invalid contract status '${contractStatus}'. Valid contract statuses are: ${validStatusesText}`;
18
+ const context = {
19
+ providedStatus: contractStatus,
20
+ validStatuses,
21
+ timestamp: new Date().toISOString(),
22
+ };
23
+ const suggestions = [
24
+ `Use one of the valid contract statuses: ${validStatusesText}`,
25
+ 'Common statuses include: DRAFT, ACTIVE, SUSPENDED, TERMINATED, EXPIRED',
26
+ 'Check the contract lifecycle for valid status transitions',
27
+ 'Contact contract administration for status change requests',
28
+ ];
29
+ super(errorCode, technicalMessage, context, suggestions);
10
30
  this.name = 'InvalidContractStatusError';
11
31
  }
12
32
  static create(contractStatus, validStatuses) {
13
33
  return new InvalidContractStatusError(contractStatus, validStatuses);
14
34
  }
15
- logError() {
16
- return `${this.name}: ${this.message}`;
17
- }
18
35
  }
19
36
  exports.InvalidContractStatusError = InvalidContractStatusError;
@@ -1,19 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvalidPaymentTermsError = void 0;
4
- const RootError_1 = require("../../../../shared/domain/exceptions/RootError");
5
- class InvalidPaymentTermsError extends RootError_1.RootError {
4
+ const CodedRootError_1 = require("../../../../shared/domain/exceptions/CodedRootError");
5
+ const ErrorCode_1 = require("../../../../shared/domain/enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when invalid payment terms are provided for a contract
8
+ * This error occurs when the payment terms don't match allowed values
9
+ *
10
+ * Error code: CBX-PMS-003
11
+ * @since 1.0.0
12
+ */
13
+ class InvalidPaymentTermsError extends CodedRootError_1.CodedRootError {
6
14
  constructor(paymentTerms, validTerms) {
15
+ const errorCode = ErrorCode_1.ErrorCode.INVALID_PAYMENT_TERMS;
7
16
  const validTermsText = validTerms.join(', ');
8
- const message = `Invalid payment terms '${paymentTerms}'. Valid payment terms are: ${validTermsText}`;
9
- super(message);
17
+ const technicalMessage = `Invalid payment terms '${paymentTerms}'. Valid payment terms are: ${validTermsText}`;
18
+ const context = {
19
+ providedTerms: paymentTerms,
20
+ validTerms,
21
+ timestamp: new Date().toISOString(),
22
+ };
23
+ const suggestions = [
24
+ `Use one of the valid payment terms: ${validTermsText}`,
25
+ 'Common payment terms include: NET30, NET60, NET90, IMMEDIATE',
26
+ 'Check contract requirements for specific payment terms',
27
+ 'Contact the finance team for special payment term requests',
28
+ ];
29
+ super(errorCode, technicalMessage, context, suggestions);
10
30
  this.name = 'InvalidPaymentTermsError';
11
31
  }
12
32
  static create(paymentTerms, validTerms) {
13
33
  return new InvalidPaymentTermsError(paymentTerms, validTerms);
14
34
  }
15
- logError() {
16
- return `${this.name}: ${this.message}`;
17
- }
18
35
  }
19
36
  exports.InvalidPaymentTermsError = InvalidPaymentTermsError;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountLockedError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when a user account is locked
8
+ * This error occurs when too many failed login attempts or security violations
9
+ *
10
+ * Error code: CBX-AUTH-005
11
+ * @since 1.0.0
12
+ */
13
+ class AccountLockedError extends CodedRootError_1.CodedRootError {
14
+ constructor(email, reason, lockedUntil, attemptCount) {
15
+ const errorCode = ErrorCode_1.ErrorCode.ACCOUNT_LOCKED;
16
+ const lockedInfo = lockedUntil ? ` until ${lockedUntil.toISOString()}` : '';
17
+ const attemptInfo = attemptCount ? ` after ${attemptCount} failed attempts` : '';
18
+ const technicalMessage = `Account locked for ${email}: ${reason}${attemptInfo}${lockedInfo}`;
19
+ const context = {
20
+ email,
21
+ reason,
22
+ ...(lockedUntil && { lockedUntil: lockedUntil.toISOString() }),
23
+ ...(attemptCount !== undefined && { attemptCount }),
24
+ timestamp: new Date().toISOString(),
25
+ };
26
+ const suggestions = [
27
+ 'Wait for the lockout period to expire',
28
+ 'Contact support to unlock your account',
29
+ 'Use the password reset option if available',
30
+ 'Verify you are using the correct email address',
31
+ 'Check with your administrator for account status',
32
+ ];
33
+ super(errorCode, technicalMessage, context, suggestions);
34
+ this.name = 'AccountLockedError';
35
+ }
36
+ static create(email, reason, lockedUntil, attemptCount) {
37
+ return new AccountLockedError(email, reason, lockedUntil, attemptCount);
38
+ }
39
+ /**
40
+ * Creates an AccountLockedError for too many failed attempts
41
+ */
42
+ static tooManyAttempts(email, attemptCount, lockedUntil) {
43
+ return new AccountLockedError(email, 'Too many failed login attempts', lockedUntil, attemptCount);
44
+ }
45
+ /**
46
+ * Creates an AccountLockedError for security violation
47
+ */
48
+ static securityViolation(email, lockedUntil) {
49
+ return new AccountLockedError(email, 'Security violation detected', lockedUntil);
50
+ }
51
+ /**
52
+ * Creates an AccountLockedError for administrative lock
53
+ */
54
+ static administrativeLock(email, reason) {
55
+ return new AccountLockedError(email, `Administrative lock: ${reason}`);
56
+ }
57
+ }
58
+ exports.AccountLockedError = AccountLockedError;
@@ -52,12 +52,12 @@ class CodedRootError extends RootError_1.RootError {
52
52
  * Checks if an error implements the ICodedError interface
53
53
  */
54
54
  static isCodedError(error) {
55
- return (typeof error === 'object' &&
56
- error !== null &&
57
- 'errorCode' in error &&
58
- 'technicalMessage' in error &&
59
- typeof error.errorCode === 'string' &&
60
- typeof error.technicalMessage === 'string');
55
+ return (typeof error === 'object'
56
+ && error !== null
57
+ && 'errorCode' in error
58
+ && 'technicalMessage' in error
59
+ && typeof error.errorCode === 'string'
60
+ && typeof error.technicalMessage === 'string');
61
61
  }
62
62
  }
63
63
  exports.CodedRootError = CodedRootError;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigurationNotFoundError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when a carbon footprint configuration is not found
8
+ * This error occurs when searching for configurations by ID, type, or other criteria
9
+ *
10
+ * Error code: CBX-CFC-001
11
+ * @since 1.0.0
12
+ */
13
+ class ConfigurationNotFoundError extends CodedRootError_1.CodedRootError {
14
+ constructor(configurationType, searchCriteria, searchValue, clientId) {
15
+ const errorCode = ErrorCode_1.ErrorCode.CONFIGURATION_NOT_FOUND;
16
+ const clientInfo = clientId ? ` for client ${clientId}` : '';
17
+ const technicalMessage = `${configurationType} configuration not found: ${searchCriteria}='${searchValue}'${clientInfo}`;
18
+ const context = {
19
+ configurationType,
20
+ searchCriteria,
21
+ searchValue,
22
+ ...(clientId && { clientId }),
23
+ timestamp: new Date().toISOString(),
24
+ };
25
+ const suggestions = [
26
+ `Verify the ${configurationType} configuration ID is correct`,
27
+ 'Check if the configuration has been properly initialized',
28
+ 'Ensure the configuration period is active',
29
+ 'Contact an administrator to set up the required configuration',
30
+ ];
31
+ super(errorCode, technicalMessage, context, suggestions);
32
+ this.name = 'ConfigurationNotFoundError';
33
+ }
34
+ static create(configurationType, searchCriteria, searchValue, clientId) {
35
+ return new ConfigurationNotFoundError(configurationType, searchCriteria, searchValue, clientId);
36
+ }
37
+ /**
38
+ * Creates an error for missing corporate configuration
39
+ */
40
+ static corporate(id, clientId) {
41
+ return new ConfigurationNotFoundError('Corporate', 'id', id, clientId);
42
+ }
43
+ /**
44
+ * Creates an error for missing product configuration
45
+ */
46
+ static product(id, clientId) {
47
+ return new ConfigurationNotFoundError('Product', 'id', id, clientId);
48
+ }
49
+ /**
50
+ * Creates an error for missing event configuration
51
+ */
52
+ static event(id, clientId) {
53
+ return new ConfigurationNotFoundError('Event', 'id', id, clientId);
54
+ }
55
+ /**
56
+ * Creates an error for missing configuration by period
57
+ */
58
+ static byPeriod(configurationType, period, clientId) {
59
+ return new ConfigurationNotFoundError(configurationType, 'period', period, clientId);
60
+ }
61
+ }
62
+ exports.ConfigurationNotFoundError = ConfigurationNotFoundError;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContractNotFoundError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when a purchase contract is not found in the system
8
+ * This error occurs when searching for contracts by ID, client, or other criteria
9
+ *
10
+ * Error code: CBX-PMS-001
11
+ * @since 1.0.0
12
+ */
13
+ class ContractNotFoundError extends CodedRootError_1.CodedRootError {
14
+ constructor(searchCriteria, searchValue, clientId, contractType) {
15
+ const errorCode = ErrorCode_1.ErrorCode.CONTRACT_NOT_FOUND;
16
+ const clientInfo = clientId ? ` for client ${clientId}` : '';
17
+ const typeInfo = contractType ? ` (type: ${contractType})` : '';
18
+ const technicalMessage = `Purchase contract not found: ${searchCriteria}='${searchValue}'${clientInfo}${typeInfo}`;
19
+ const context = {
20
+ searchCriteria,
21
+ searchValue,
22
+ ...(clientId && { clientId }),
23
+ ...(contractType && { contractType }),
24
+ timestamp: new Date().toISOString(),
25
+ };
26
+ const suggestions = [
27
+ 'Verify the contract ID is correct',
28
+ 'Check if the contract has been properly created',
29
+ 'Ensure the contract has not been deleted or archived',
30
+ 'Verify you have permission to access this contract',
31
+ 'Contact the contract administrator for assistance',
32
+ ];
33
+ super(errorCode, technicalMessage, context, suggestions);
34
+ this.name = 'ContractNotFoundError';
35
+ }
36
+ static create(searchCriteria, searchValue, clientId, contractType) {
37
+ return new ContractNotFoundError(searchCriteria, searchValue, clientId, contractType);
38
+ }
39
+ /**
40
+ * Creates a ContractNotFoundError specifically for ID searches
41
+ */
42
+ static byId(id, clientId) {
43
+ return new ContractNotFoundError('id', id, clientId);
44
+ }
45
+ /**
46
+ * Creates a ContractNotFoundError specifically for contract number searches
47
+ */
48
+ static byContractNumber(contractNumber, clientId) {
49
+ return new ContractNotFoundError('contractNumber', contractNumber, clientId);
50
+ }
51
+ /**
52
+ * Creates a ContractNotFoundError for active contracts
53
+ */
54
+ static noActiveContract(clientId) {
55
+ return new ContractNotFoundError('status', 'ACTIVE', clientId);
56
+ }
57
+ }
58
+ exports.ContractNotFoundError = ContractNotFoundError;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmailNotVerifiedError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Error thrown when a user tries to perform an action that requires
8
+ * a verified email address, but their email has not been verified yet.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class EmailNotVerifiedError extends CodedRootError_1.CodedRootError {
13
+ constructor(email, actionAttempted) {
14
+ const technicalMessage = actionAttempted
15
+ ? `User with email ${email} attempted to ${actionAttempted} without verifying their email address`
16
+ : `User with email ${email} has not verified their email address`;
17
+ const context = {
18
+ email,
19
+ timestamp: new Date().toISOString(),
20
+ };
21
+ if (actionAttempted) {
22
+ context.actionAttempted = actionAttempted;
23
+ }
24
+ const suggestions = [
25
+ 'Check your email inbox for a verification link',
26
+ 'Request a new verification email if the previous one expired',
27
+ 'Ensure you are checking the correct email account',
28
+ 'Check your spam/junk folder for the verification email',
29
+ ];
30
+ super(ErrorCode_1.ErrorCode.EMAIL_NOT_VERIFIED, technicalMessage, context, suggestions);
31
+ this.name = 'EmailNotVerifiedError';
32
+ }
33
+ /**
34
+ * Factory method to create a new EmailNotVerifiedError instance
35
+ *
36
+ * @param email - The unverified email address
37
+ * @param actionAttempted - Optional description of the action the user attempted
38
+ * @returns A new EmailNotVerifiedError instance
39
+ */
40
+ static create(email, actionAttempted) {
41
+ return new EmailNotVerifiedError(email, actionAttempted);
42
+ }
43
+ /**
44
+ * Returns whether the error is related to accessing restricted features
45
+ */
46
+ isAccessRestriction() {
47
+ return this.context?.actionAttempted !== undefined;
48
+ }
49
+ /**
50
+ * Returns a user-friendly message based on the locale
51
+ */
52
+ getUserMessage(locale = 'en') {
53
+ const messages = {
54
+ en: 'Please verify your email address to continue',
55
+ es: 'Por favor, verifica tu dirección de correo electrónico para continuar',
56
+ pt: 'Por favor, verifique seu endereço de e-mail para continuar',
57
+ };
58
+ return messages[locale] || messages.en;
59
+ }
60
+ }
61
+ exports.EmailNotVerifiedError = EmailNotVerifiedError;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidBusinessStatusError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when a business status transition is invalid
8
+ * This error occurs when attempting to change a stakeholder or entity status to an invalid state
9
+ *
10
+ * Error code: CBX-STK-005
11
+ * @since 1.0.0
12
+ */
13
+ class InvalidBusinessStatusError extends CodedRootError_1.CodedRootError {
14
+ constructor(currentStatus, attemptedStatus, entityType, entityId) {
15
+ const errorCode = ErrorCode_1.ErrorCode.INVALID_BUSINESS_STATUS;
16
+ const entityInfo = entityId ? ` (ID: ${entityId})` : '';
17
+ const technicalMessage = `Invalid business status transition for ${entityType}${entityInfo}: Cannot change from '${currentStatus}' to '${attemptedStatus}'`;
18
+ const context = {
19
+ currentStatus,
20
+ attemptedStatus,
21
+ entityType,
22
+ ...(entityId && { entityId }),
23
+ timestamp: new Date().toISOString(),
24
+ };
25
+ const suggestions = [
26
+ `Current status '${currentStatus}' does not allow transition to '${attemptedStatus}'`,
27
+ 'Review the allowed status transitions for this entity type',
28
+ 'Ensure all required conditions are met for the status change',
29
+ 'Contact an administrator if you believe this transition should be allowed',
30
+ ];
31
+ super(errorCode, technicalMessage, context, suggestions);
32
+ this.name = 'InvalidBusinessStatusError';
33
+ }
34
+ static create(currentStatus, attemptedStatus, entityType, entityId) {
35
+ return new InvalidBusinessStatusError(currentStatus, attemptedStatus, entityType, entityId);
36
+ }
37
+ /**
38
+ * Creates an error for invalid activation attempts
39
+ */
40
+ static cannotActivate(currentStatus, entityType, entityId) {
41
+ return new InvalidBusinessStatusError(currentStatus, 'ACTIVE', entityType, entityId);
42
+ }
43
+ /**
44
+ * Creates an error for invalid deactivation attempts
45
+ */
46
+ static cannotDeactivate(currentStatus, entityType, entityId) {
47
+ return new InvalidBusinessStatusError(currentStatus, 'INACTIVE', entityType, entityId);
48
+ }
49
+ /**
50
+ * Creates an error for invalid deletion attempts
51
+ */
52
+ static cannotDelete(currentStatus, entityType, entityId) {
53
+ return new InvalidBusinessStatusError(currentStatus, 'DELETED', entityType, entityId);
54
+ }
55
+ }
56
+ exports.InvalidBusinessStatusError = InvalidBusinessStatusError;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidCredentialsError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when authentication credentials are invalid
8
+ * This error is used when the email/password combination is incorrect
9
+ *
10
+ * Error code: CBX-AUTH-001
11
+ * @since 1.0.0
12
+ */
13
+ class InvalidCredentialsError extends CodedRootError_1.CodedRootError {
14
+ constructor(email, attemptNumber) {
15
+ const errorCode = ErrorCode_1.ErrorCode.INVALID_CREDENTIALS;
16
+ const technicalMessage = `Invalid credentials for user: ${email}${attemptNumber ? ` (attempt ${attemptNumber})` : ''}`;
17
+ const context = {
18
+ email,
19
+ ...(attemptNumber !== undefined && { attemptNumber }),
20
+ timestamp: new Date().toISOString(),
21
+ };
22
+ const suggestions = [
23
+ 'Verify your email and password are correct',
24
+ 'Check if Caps Lock is enabled',
25
+ 'Use "Forgot Password" if you cannot remember your credentials',
26
+ 'Contact support if you continue having issues',
27
+ ];
28
+ super(errorCode, technicalMessage, context, suggestions);
29
+ this.name = 'InvalidCredentialsError';
30
+ }
31
+ static create(email, attemptNumber) {
32
+ return new InvalidCredentialsError(email, attemptNumber);
33
+ }
34
+ }
35
+ exports.InvalidCredentialsError = InvalidCredentialsError;
@@ -1,19 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvalidCurrencyError = void 0;
4
- const RootError_1 = require("./RootError");
5
- class InvalidCurrencyError extends RootError_1.RootError {
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Error thrown when an invalid currency code is provided
8
+ * that does not match the accepted currency standards.
9
+ *
10
+ * @since 1.0.0
11
+ */
12
+ class InvalidCurrencyError extends CodedRootError_1.CodedRootError {
6
13
  constructor(currency, validCurrencies) {
7
14
  const validCurrenciesText = validCurrencies.join(', ');
8
- const message = `Invalid currency '${currency}'. Valid currencies are: ${validCurrenciesText}`;
9
- super(message);
15
+ const technicalMessage = `Invalid currency '${currency}'. Valid currencies are: ${validCurrenciesText}`;
16
+ const context = {
17
+ providedCurrency: currency,
18
+ validCurrencies,
19
+ totalValidCurrencies: validCurrencies.length,
20
+ timestamp: new Date().toISOString(),
21
+ };
22
+ const suggestions = [
23
+ `Use one of the supported currency codes: ${validCurrencies.slice(0, 5).join(', ')}${validCurrencies.length > 5 ? '...' : ''}`,
24
+ 'Currency codes should be in ISO 4217 format (e.g., USD, EUR, GBP)',
25
+ 'Check for typos in the currency code',
26
+ 'Ensure the currency code is in uppercase',
27
+ ];
28
+ super(ErrorCode_1.ErrorCode.INVALID_CURRENCY, technicalMessage, context, suggestions);
10
29
  this.name = 'InvalidCurrencyError';
11
30
  }
31
+ /**
32
+ * Factory method to create a new InvalidCurrencyError instance
33
+ *
34
+ * @param currency - The invalid currency code provided
35
+ * @param validCurrencies - List of valid currency codes
36
+ * @returns A new InvalidCurrencyError instance
37
+ */
12
38
  static create(currency, validCurrencies) {
13
39
  return new InvalidCurrencyError(currency, validCurrencies);
14
40
  }
15
- logError() {
16
- return `${this.name}: ${this.message}`;
41
+ /**
42
+ * Checks if the provided currency might be a common typo
43
+ */
44
+ isPossibleTypo() {
45
+ const currency = this.context?.providedCurrency;
46
+ const validCurrencies = this.context?.validCurrencies;
47
+ if (!currency || !validCurrencies)
48
+ return false;
49
+ // Check if it's just a case issue
50
+ return validCurrencies.some((valid) => valid.toLowerCase() === currency.toLowerCase());
51
+ }
52
+ /**
53
+ * Returns a user-friendly message based on the locale
54
+ */
55
+ getUserMessage(locale = 'en') {
56
+ const messages = {
57
+ en: 'The currency code provided is not supported',
58
+ es: 'El código de moneda proporcionado no está soportado',
59
+ pt: 'O código de moeda fornecido não é suportado',
60
+ };
61
+ return messages[locale] || messages.en;
17
62
  }
18
63
  }
19
64
  exports.InvalidCurrencyError = InvalidCurrencyError;
@@ -29,7 +29,7 @@ class InvalidDateFormatError extends CodedRootError_1.CodedRootError {
29
29
  'YYYY-MM-DD': '2024-03-15',
30
30
  'DD/MM/YYYY': '15/03/2024',
31
31
  'MM/DD/YYYY': '03/15/2024',
32
- 'ISO8601': '2024-03-15T10:30:00Z',
32
+ ISO8601: '2024-03-15T10:30:00Z',
33
33
  'YYYY-MM-DDTHH:mm:ss': '2024-03-15T10:30:00',
34
34
  };
35
35
  return examples[format] || '2024-03-15';
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingCredentialsError = void 0;
4
+ const CodedRootError_1 = require("./CodedRootError");
5
+ const ErrorCode_1 = require("../enums/ErrorCode");
6
+ /**
7
+ * Exception thrown when required authentication credentials are missing
8
+ * This error occurs when email, password, or both are not provided
9
+ *
10
+ * Error code: CBX-AUTH-004
11
+ * @since 1.0.0
12
+ */
13
+ class MissingCredentialsError extends CodedRootError_1.CodedRootError {
14
+ constructor(missingFields) {
15
+ const errorCode = ErrorCode_1.ErrorCode.MISSING_CREDENTIALS;
16
+ const fieldsList = missingFields.join(', ');
17
+ const technicalMessage = `Missing required authentication credentials: ${fieldsList}`;
18
+ const context = {
19
+ missingFields,
20
+ timestamp: new Date().toISOString(),
21
+ };
22
+ const suggestions = [
23
+ 'Provide all required credentials (email and password)',
24
+ 'Ensure no fields are left empty',
25
+ 'Check that your request includes all required authentication data',
26
+ 'If using an API, verify the request payload structure',
27
+ ];
28
+ super(errorCode, technicalMessage, context, suggestions);
29
+ this.name = 'MissingCredentialsError';
30
+ }
31
+ static create(missingFields) {
32
+ return new MissingCredentialsError(missingFields);
33
+ }
34
+ /**
35
+ * Creates a MissingCredentialsError for missing email
36
+ */
37
+ static missingEmail() {
38
+ return new MissingCredentialsError(['email']);
39
+ }
40
+ /**
41
+ * Creates a MissingCredentialsError for missing password
42
+ */
43
+ static missingPassword() {
44
+ return new MissingCredentialsError(['password']);
45
+ }
46
+ /**
47
+ * Creates a MissingCredentialsError for both missing email and password
48
+ */
49
+ static missingBoth() {
50
+ return new MissingCredentialsError(['email', 'password']);
51
+ }
52
+ }
53
+ exports.MissingCredentialsError = MissingCredentialsError;