@carbonbox/domain 0.29.0 → 0.29.1
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/build/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidContractStatusError.js +24 -7
- package/build/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidPaymentTermsError.js +24 -7
- package/build/carbonbox/shared/domain/exceptions/AccountLockedError.js +58 -0
- package/build/carbonbox/shared/domain/exceptions/ConfigurationNotFoundError.js +62 -0
- package/build/carbonbox/shared/domain/exceptions/ContractNotFoundError.js +58 -0
- package/build/carbonbox/shared/domain/exceptions/EmailNotVerifiedError.js +61 -0
- package/build/carbonbox/shared/domain/exceptions/InvalidBusinessStatusError.js +56 -0
- package/build/carbonbox/shared/domain/exceptions/InvalidCredentialsError.js +35 -0
- package/build/carbonbox/shared/domain/exceptions/InvalidCurrencyError.js +51 -6
- package/build/carbonbox/shared/domain/exceptions/MissingCredentialsError.js +53 -0
- package/build/carbonbox/shared/domain/exceptions/OrderExceedsBudgetError.js +98 -0
- package/build/carbonbox/shared/domain/exceptions/ServiceCatalogNotFoundError.js +64 -0
- package/build/carbonbox/shared/domain/exceptions/StakeholderNotFoundError.js +49 -0
- package/build/carbonbox/shared/domain/exceptions/TokenExpiredError.js +48 -0
- package/build/main/index.js +31 -5
- package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidContractStatusError.d.ts +9 -3
- package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidContractStatusError.d.ts.map +1 -1
- package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidPaymentTermsError.d.ts +9 -3
- package/build/types/carbonbox/purchase-management-system/purchase-contracts/domain/exceptions/InvalidPaymentTermsError.d.ts.map +1 -1
- package/build/types/carbonbox/shared/domain/exceptions/AccountLockedError.d.ts +25 -0
- package/build/types/carbonbox/shared/domain/exceptions/AccountLockedError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/ConfigurationNotFoundError.d.ts +29 -0
- package/build/types/carbonbox/shared/domain/exceptions/ConfigurationNotFoundError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/ContractNotFoundError.d.ts +25 -0
- package/build/types/carbonbox/shared/domain/exceptions/ContractNotFoundError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/EmailNotVerifiedError.d.ts +27 -0
- package/build/types/carbonbox/shared/domain/exceptions/EmailNotVerifiedError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/InvalidBusinessStatusError.d.ts +25 -0
- package/build/types/carbonbox/shared/domain/exceptions/InvalidBusinessStatusError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/InvalidCredentialsError.d.ts +13 -0
- package/build/types/carbonbox/shared/domain/exceptions/InvalidCredentialsError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/InvalidCurrencyError.d.ts +23 -3
- package/build/types/carbonbox/shared/domain/exceptions/InvalidCurrencyError.d.ts.map +1 -1
- package/build/types/carbonbox/shared/domain/exceptions/MissingCredentialsError.d.ts +25 -0
- package/build/types/carbonbox/shared/domain/exceptions/MissingCredentialsError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/OrderExceedsBudgetError.d.ts +42 -0
- package/build/types/carbonbox/shared/domain/exceptions/OrderExceedsBudgetError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/ServiceCatalogNotFoundError.d.ts +29 -0
- package/build/types/carbonbox/shared/domain/exceptions/ServiceCatalogNotFoundError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/StakeholderNotFoundError.d.ts +21 -0
- package/build/types/carbonbox/shared/domain/exceptions/StakeholderNotFoundError.d.ts.map +1 -0
- package/build/types/carbonbox/shared/domain/exceptions/TokenExpiredError.d.ts +21 -0
- package/build/types/carbonbox/shared/domain/exceptions/TokenExpiredError.d.ts.map +1 -0
- package/build/types/main/index.d.ts +11 -0
- package/build/types/main/index.d.ts.map +1 -1
- 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
|
|
5
|
-
|
|
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
|
|
9
|
-
|
|
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
|
|
5
|
-
|
|
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
|
|
9
|
-
|
|
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;
|
|
@@ -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
|
|
5
|
-
|
|
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
|
|
9
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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;
|
|
@@ -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;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrderExceedsBudgetError = void 0;
|
|
4
|
+
const CodedRootError_1 = require("./CodedRootError");
|
|
5
|
+
const ErrorCode_1 = require("../enums/ErrorCode");
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when a purchase order exceeds the allocated budget limit.
|
|
8
|
+
* This error helps prevent overspending and maintains financial controls.
|
|
9
|
+
*
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
class OrderExceedsBudgetError extends CodedRootError_1.CodedRootError {
|
|
13
|
+
constructor(orderAmount, budgetLimit, currency, orderId, projectName) {
|
|
14
|
+
const exceedAmount = orderAmount - budgetLimit;
|
|
15
|
+
const exceedPercentage = ((exceedAmount / budgetLimit) * 100).toFixed(2);
|
|
16
|
+
const technicalMessage = `Order ${orderId ? `#${orderId} ` : ''}exceeds budget limit by ${currency} ${exceedAmount.toFixed(2)} (${exceedPercentage}% over limit). Order amount: ${currency} ${orderAmount.toFixed(2)}, Budget limit: ${currency} ${budgetLimit.toFixed(2)}${projectName ? ` for project '${projectName}'` : ''}`;
|
|
17
|
+
const context = {
|
|
18
|
+
orderAmount,
|
|
19
|
+
budgetLimit,
|
|
20
|
+
exceedAmount,
|
|
21
|
+
exceedPercentage: parseFloat(exceedPercentage),
|
|
22
|
+
currency,
|
|
23
|
+
timestamp: new Date().toISOString(),
|
|
24
|
+
};
|
|
25
|
+
if (orderId) {
|
|
26
|
+
context.orderId = orderId;
|
|
27
|
+
}
|
|
28
|
+
if (projectName) {
|
|
29
|
+
context.projectName = projectName;
|
|
30
|
+
}
|
|
31
|
+
const suggestions = [
|
|
32
|
+
'Review the order items and quantities to reduce the total amount',
|
|
33
|
+
'Request a budget increase approval from the appropriate authority',
|
|
34
|
+
'Split the order into multiple smaller orders if possible',
|
|
35
|
+
'Consider alternative products or services that fit within budget',
|
|
36
|
+
'Check if there are any available discounts or promotions',
|
|
37
|
+
];
|
|
38
|
+
super(ErrorCode_1.ErrorCode.ORDER_EXCEEDS_BUDGET, technicalMessage, context, suggestions);
|
|
39
|
+
this.name = 'OrderExceedsBudgetError';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Factory method to create a new OrderExceedsBudgetError instance
|
|
43
|
+
*
|
|
44
|
+
* @param orderAmount - The total amount of the order
|
|
45
|
+
* @param budgetLimit - The maximum budget allowed
|
|
46
|
+
* @param currency - The currency code (e.g., USD, EUR)
|
|
47
|
+
* @param orderId - Optional order identifier
|
|
48
|
+
* @param projectName - Optional project or department name
|
|
49
|
+
* @returns A new OrderExceedsBudgetError instance
|
|
50
|
+
*/
|
|
51
|
+
static create(orderAmount, budgetLimit, currency = 'USD', orderId, projectName) {
|
|
52
|
+
return new OrderExceedsBudgetError(orderAmount, budgetLimit, currency, orderId, projectName);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the amount by which the order exceeds the budget
|
|
56
|
+
*/
|
|
57
|
+
getExceedAmount() {
|
|
58
|
+
return this.context?.exceedAmount || 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the percentage by which the order exceeds the budget
|
|
62
|
+
*/
|
|
63
|
+
getExceedPercentage() {
|
|
64
|
+
return this.context?.exceedPercentage || 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the order is slightly over budget (less than 10%)
|
|
68
|
+
*/
|
|
69
|
+
isSlightlyOverBudget() {
|
|
70
|
+
return this.getExceedPercentage() < 10;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns a user-friendly message based on the locale
|
|
74
|
+
*/
|
|
75
|
+
getUserMessage(locale = 'en') {
|
|
76
|
+
const messages = {
|
|
77
|
+
en: 'The order amount exceeds the available budget',
|
|
78
|
+
es: 'El monto de la orden excede el presupuesto disponible',
|
|
79
|
+
pt: 'O valor do pedido excede o orçamento disponível',
|
|
80
|
+
};
|
|
81
|
+
return messages[locale] || messages.en;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns a detailed user message with amounts
|
|
85
|
+
*/
|
|
86
|
+
getDetailedUserMessage(locale = 'en') {
|
|
87
|
+
const currency = this.context?.currency || 'USD';
|
|
88
|
+
const exceedAmount = this.context?.exceedAmount || 0;
|
|
89
|
+
const exceedPercentage = this.context?.exceedPercentage || 0;
|
|
90
|
+
const messages = {
|
|
91
|
+
en: `Order exceeds budget by ${currency} ${exceedAmount.toFixed(2)} (${exceedPercentage}% over limit)`,
|
|
92
|
+
es: `La orden excede el presupuesto por ${currency} ${exceedAmount.toFixed(2)} (${exceedPercentage}% sobre el límite)`,
|
|
93
|
+
pt: `O pedido excede o orçamento em ${currency} ${exceedAmount.toFixed(2)} (${exceedPercentage}% acima do limite)`,
|
|
94
|
+
};
|
|
95
|
+
return messages[locale] || messages.en;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.OrderExceedsBudgetError = OrderExceedsBudgetError;
|