@acontplus/core 1.0.17 → 1.1.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/README.md +149 -15
- package/package.json +21 -14
- package/src/lib/constants/app.constants.d.ts +20 -0
- package/src/lib/constants/app.constants.js +24 -0
- package/src/lib/constants/app.constants.js.map +1 -0
- package/src/lib/constants/index.d.ts +1 -1
- package/src/lib/constants/index.js +1 -1
- package/src/lib/constants/index.js.map +1 -1
- package/src/lib/models/core-config.d.ts +19 -0
- package/src/lib/models/core-config.js +2 -0
- package/src/lib/models/core-config.js.map +1 -0
- package/src/lib/models/index.d.ts +4 -2
- package/src/lib/models/index.js +4 -2
- package/src/lib/models/index.js.map +1 -1
- package/src/lib/models/repository-config.d.ts +5 -0
- package/src/lib/models/repository-config.js +2 -0
- package/src/lib/models/repository-config.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,28 +1,68 @@
|
|
|
1
1
|
# @acontplus/core
|
|
2
2
|
|
|
3
|
-
Core library for AcontPlus applications, providing essential utilities
|
|
3
|
+
Core library for AcontPlus applications, providing essential utilities, domain models, clean architecture patterns, and business logic components following Domain-Driven Design (DDD) principles.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
# Using npm
|
|
8
9
|
npm install @acontplus/core
|
|
10
|
+
|
|
11
|
+
# Using pnpm
|
|
12
|
+
pnpm add @acontplus/core
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
## Features
|
|
12
16
|
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
17
|
+
- **Clean Architecture**: Ports and adapters pattern for external integrations
|
|
18
|
+
- **Domain Models**: Base entities, value objects, and domain-specific models
|
|
19
|
+
- **Pricing Engine**: Comprehensive pricing calculations with discount, tax, profit, and line item calculators
|
|
20
|
+
- **HTTP Adapters**: Axios and Fetch adapters with HTTP client factory
|
|
21
|
+
- **Use Cases**: Base use case pattern for business logic encapsulation
|
|
22
|
+
- **Value Objects**: Money, EntityId, IdentificationNumber, and AuthTokens value objects
|
|
15
23
|
- **Environment Configuration**: Type-safe environment configuration interfaces
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
|
|
24
|
+
- **Constants**: Application constants including SRI document types
|
|
25
|
+
- **Type Definitions**: Comprehensive TypeScript type definitions for pricing and business logic
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
This library follows Clean Architecture principles with clear separation of concerns:
|
|
30
|
+
|
|
31
|
+
- **Adapters**: External service integrations (HTTP clients)
|
|
32
|
+
- **Ports**: Interfaces for external dependencies
|
|
33
|
+
- **Models**: Domain entities and data transfer objects
|
|
34
|
+
- **Value Objects**: Immutable objects representing domain concepts
|
|
35
|
+
- **Use Cases**: Business logic encapsulation
|
|
36
|
+
- **Types**: TypeScript definitions for type safety
|
|
19
37
|
|
|
20
38
|
## Usage
|
|
21
39
|
|
|
40
|
+
### HTTP Adapters
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { HttpClientFactory, AxiosAdapter, FetchAdapter } from '@acontplus/core';
|
|
44
|
+
|
|
45
|
+
// Create HTTP client with Axios
|
|
46
|
+
const axiosClient = HttpClientFactory.create('axios');
|
|
47
|
+
|
|
48
|
+
// Create HTTP client with Fetch
|
|
49
|
+
const fetchClient = HttpClientFactory.create('fetch');
|
|
50
|
+
|
|
51
|
+
// Use adapter directly
|
|
52
|
+
const axiosAdapter = new AxiosAdapter();
|
|
53
|
+
const response = await axiosAdapter.get('https://api.example.com/data');
|
|
54
|
+
```
|
|
55
|
+
|
|
22
56
|
### Pricing Calculations
|
|
23
57
|
|
|
24
58
|
```typescript
|
|
25
|
-
import {
|
|
59
|
+
import {
|
|
60
|
+
DiscountCalculator,
|
|
61
|
+
TaxCalculator,
|
|
62
|
+
PricingCalculator,
|
|
63
|
+
ProfitCalculator,
|
|
64
|
+
LineItemCalculator,
|
|
65
|
+
} from '@acontplus/core';
|
|
26
66
|
|
|
27
67
|
// Calculate discounts
|
|
28
68
|
const discountCalc = new DiscountCalculator();
|
|
@@ -32,21 +72,105 @@ const discount = discountCalc.calculate(100, 10); // 10% discount on $100
|
|
|
32
72
|
const taxCalc = new TaxCalculator();
|
|
33
73
|
const tax = taxCalc.calculate(100, 0.12); // 12% tax on $100
|
|
34
74
|
|
|
75
|
+
// Calculate profit margins
|
|
76
|
+
const profitCalc = new ProfitCalculator();
|
|
77
|
+
const profit = profitCalc.calculate(cost, sellingPrice);
|
|
78
|
+
|
|
79
|
+
// Line item calculations
|
|
80
|
+
const lineItemCalc = new LineItemCalculator();
|
|
81
|
+
const lineTotal = lineItemCalc.calculate(quantity, unitPrice, discount, tax);
|
|
82
|
+
|
|
35
83
|
// Complex pricing calculations
|
|
36
84
|
const pricingCalc = new PricingCalculator();
|
|
37
85
|
const finalPrice = pricingCalc.calculateTotal(items, discounts, taxes);
|
|
38
86
|
```
|
|
39
87
|
|
|
40
|
-
###
|
|
88
|
+
### Value Objects
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { Money, EntityId, IdentificationNumber, AuthTokens } from '@acontplus/core';
|
|
92
|
+
|
|
93
|
+
// Money value object for financial calculations
|
|
94
|
+
const price = new Money(99.99, 'USD');
|
|
95
|
+
const discountedPrice = price.subtract(new Money(10.0, 'USD'));
|
|
96
|
+
|
|
97
|
+
// Entity ID for domain entities
|
|
98
|
+
const customerId = new EntityId(12345);
|
|
99
|
+
|
|
100
|
+
// Identification number with validation
|
|
101
|
+
const ecuadorianId = new IdentificationNumber('1234567890');
|
|
102
|
+
|
|
103
|
+
// Authentication tokens
|
|
104
|
+
const tokens = new AuthTokens('access_token', 'refresh_token');
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Domain Models
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { BaseEntity, ApiResponse, PaginatedResult } from '@acontplus/core';
|
|
111
|
+
|
|
112
|
+
// Base entity for domain objects
|
|
113
|
+
class Customer extends BaseEntity {
|
|
114
|
+
constructor(
|
|
115
|
+
id: number,
|
|
116
|
+
public readonly name: string,
|
|
117
|
+
public readonly email: string,
|
|
118
|
+
) {
|
|
119
|
+
super(id);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// API response handling
|
|
124
|
+
const response: ApiResponse<Customer> = {
|
|
125
|
+
success: true,
|
|
126
|
+
data: customer,
|
|
127
|
+
message: 'Customer retrieved successfully',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Paginated results
|
|
131
|
+
const paginatedCustomers: PaginatedResult<Customer> = {
|
|
132
|
+
items: customers,
|
|
133
|
+
totalCount: 100,
|
|
134
|
+
pageSize: 10,
|
|
135
|
+
currentPage: 1,
|
|
136
|
+
};
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Use Cases
|
|
41
140
|
|
|
42
141
|
```typescript
|
|
43
|
-
import {
|
|
142
|
+
import { UseCase } from '@acontplus/core';
|
|
143
|
+
|
|
144
|
+
// Business logic encapsulation
|
|
145
|
+
class CreateCustomerUseCase extends UseCase<CreateCustomerRequest, Customer> {
|
|
146
|
+
constructor(private customerRepository: CustomerRepository) {
|
|
147
|
+
super();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async execute(request: CreateCustomerRequest): Promise<Customer> {
|
|
151
|
+
// Validate business rules
|
|
152
|
+
this.validateRequest(request);
|
|
153
|
+
|
|
154
|
+
// Execute business logic
|
|
155
|
+
return await this.customerRepository.create(request);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private validateRequest(request: CreateCustomerRequest): void {
|
|
159
|
+
if (!request.name || request.name.trim().length === 0) {
|
|
160
|
+
throw new Error('Customer name is required');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
44
165
|
|
|
45
|
-
|
|
46
|
-
const documentType = SRI_DOCUMENT_TYPE.RUC; // '04'
|
|
166
|
+
### Constants
|
|
47
167
|
|
|
48
|
-
|
|
49
|
-
|
|
168
|
+
```typescript
|
|
169
|
+
import { APP_CONSTANTS } from '@acontplus/core';
|
|
170
|
+
|
|
171
|
+
// Application constants
|
|
172
|
+
const maxRetries = APP_CONSTANTS.MAX_RETRY_ATTEMPTS;
|
|
173
|
+
const timeout = APP_CONSTANTS.DEFAULT_TIMEOUT;
|
|
50
174
|
```
|
|
51
175
|
|
|
52
176
|
### Environment Configuration
|
|
@@ -64,6 +188,16 @@ const environment: Environment = {
|
|
|
64
188
|
};
|
|
65
189
|
```
|
|
66
190
|
|
|
67
|
-
|
|
191
|
+
### Pricing Types
|
|
68
192
|
|
|
69
|
-
|
|
193
|
+
```typescript
|
|
194
|
+
import { PricingTypes } from '@acontplus/core';
|
|
195
|
+
|
|
196
|
+
// Type-safe pricing calculations
|
|
197
|
+
const calculation: PricingTypes.PricingCalculation = {
|
|
198
|
+
basePrice: 100,
|
|
199
|
+
discounts: [{ type: 'percentage', value: 10 }],
|
|
200
|
+
taxes: [{ type: 'percentage', value: 8.25 }],
|
|
201
|
+
finalPrice: 97.43,
|
|
202
|
+
};
|
|
203
|
+
```
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acontplus/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Enterprise-grade core library implementing Domain-Driven Design (DDD) and Clean Architecture patterns. Provides value objects, use cases, entities, HTTP adapters, pricing calculations, API response handling, and foundational utilities for Angular applications.",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"@acontplus/utils": "^1.0.9",
|
|
7
|
-
"tslib": "^2.8.1",
|
|
8
|
-
"uuid": "^13.0.0"
|
|
9
|
-
},
|
|
10
5
|
"peerDependencies": {
|
|
6
|
+
"@acontplus/utils": "^1.0.11",
|
|
7
|
+
"tslib": "^2.8.1",
|
|
8
|
+
"uuid": "^13.0.0",
|
|
11
9
|
"typescript": "^5.9.2"
|
|
12
10
|
},
|
|
13
11
|
"type": "module",
|
|
@@ -35,21 +33,30 @@
|
|
|
35
33
|
"ddd",
|
|
36
34
|
"domain-driven-design",
|
|
37
35
|
"clean-architecture",
|
|
36
|
+
"hexagonal-architecture",
|
|
38
37
|
"use-cases",
|
|
39
38
|
"value-objects",
|
|
40
39
|
"entities",
|
|
41
40
|
"adapters",
|
|
42
41
|
"ports",
|
|
43
|
-
"pricing",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
42
|
+
"pricing-calculator",
|
|
43
|
+
"tax-calculator",
|
|
44
|
+
"discount-calculator",
|
|
45
|
+
"profit-calculator",
|
|
46
|
+
"money-value-object",
|
|
47
|
+
"http-client-factory",
|
|
48
|
+
"api-response-handling",
|
|
49
49
|
"pagination",
|
|
50
|
-
"jwt",
|
|
50
|
+
"jwt-tokens",
|
|
51
|
+
"base-entity",
|
|
52
|
+
"identification-number",
|
|
53
|
+
"entity-id",
|
|
54
|
+
"auth-tokens",
|
|
55
|
+
"axios-adapter",
|
|
56
|
+
"fetch-adapter",
|
|
51
57
|
"typescript",
|
|
52
|
-
"
|
|
58
|
+
"angular",
|
|
59
|
+
"enterprise"
|
|
53
60
|
],
|
|
54
61
|
"author": "Ivan Paz <ifer343@gmail.com>",
|
|
55
62
|
"license": "MIT",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum SRI_DOCUMENT_TYPE {
|
|
2
|
+
RUC = "04",
|
|
3
|
+
CEDULA = "05",
|
|
4
|
+
PASSPORT = "06",
|
|
5
|
+
CONSUMIDOR_FINAL = "07",
|
|
6
|
+
IDENTIFICACION_EXTERIOR = "08"
|
|
7
|
+
}
|
|
8
|
+
export declare enum SRI_DOCUMENT_TYPE_CUSTOM {
|
|
9
|
+
RUC = "R",
|
|
10
|
+
CEDULA = "C",
|
|
11
|
+
PASSPORT = "P",
|
|
12
|
+
CONSUMIDOR_FINAL = "CF",
|
|
13
|
+
IDENTIFICACION_EXTERIOR = "IE"
|
|
14
|
+
}
|
|
15
|
+
export declare enum SEPARATOR_KEY_CODE {
|
|
16
|
+
SLASH = "|",
|
|
17
|
+
PUNTO_COMA = ";",
|
|
18
|
+
DOS_PUNTOS = ":"
|
|
19
|
+
}
|
|
20
|
+
export declare const SEPARADORES_REGEX: RegExp;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var SRI_DOCUMENT_TYPE;
|
|
2
|
+
(function (SRI_DOCUMENT_TYPE) {
|
|
3
|
+
SRI_DOCUMENT_TYPE["RUC"] = "04";
|
|
4
|
+
SRI_DOCUMENT_TYPE["CEDULA"] = "05";
|
|
5
|
+
SRI_DOCUMENT_TYPE["PASSPORT"] = "06";
|
|
6
|
+
SRI_DOCUMENT_TYPE["CONSUMIDOR_FINAL"] = "07";
|
|
7
|
+
SRI_DOCUMENT_TYPE["IDENTIFICACION_EXTERIOR"] = "08";
|
|
8
|
+
})(SRI_DOCUMENT_TYPE || (SRI_DOCUMENT_TYPE = {}));
|
|
9
|
+
export var SRI_DOCUMENT_TYPE_CUSTOM;
|
|
10
|
+
(function (SRI_DOCUMENT_TYPE_CUSTOM) {
|
|
11
|
+
SRI_DOCUMENT_TYPE_CUSTOM["RUC"] = "R";
|
|
12
|
+
SRI_DOCUMENT_TYPE_CUSTOM["CEDULA"] = "C";
|
|
13
|
+
SRI_DOCUMENT_TYPE_CUSTOM["PASSPORT"] = "P";
|
|
14
|
+
SRI_DOCUMENT_TYPE_CUSTOM["CONSUMIDOR_FINAL"] = "CF";
|
|
15
|
+
SRI_DOCUMENT_TYPE_CUSTOM["IDENTIFICACION_EXTERIOR"] = "IE";
|
|
16
|
+
})(SRI_DOCUMENT_TYPE_CUSTOM || (SRI_DOCUMENT_TYPE_CUSTOM = {}));
|
|
17
|
+
export var SEPARATOR_KEY_CODE;
|
|
18
|
+
(function (SEPARATOR_KEY_CODE) {
|
|
19
|
+
SEPARATOR_KEY_CODE["SLASH"] = "|";
|
|
20
|
+
SEPARATOR_KEY_CODE["PUNTO_COMA"] = ";";
|
|
21
|
+
SEPARATOR_KEY_CODE["DOS_PUNTOS"] = ":";
|
|
22
|
+
})(SEPARATOR_KEY_CODE || (SEPARATOR_KEY_CODE = {}));
|
|
23
|
+
export const SEPARADORES_REGEX = new RegExp(`[${Object.values(SEPARATOR_KEY_CODE).join('')}]`);
|
|
24
|
+
//# sourceMappingURL=app.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.constants.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/constants/app.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,+BAAU,CAAA;IACV,kCAAa,CAAA;IACb,oCAAe,CAAA;IACf,4CAAuB,CAAA;IACvB,mDAA8B,CAAA;AAChC,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAN,IAAY,wBAMX;AAND,WAAY,wBAAwB;IAClC,qCAAS,CAAA;IACT,wCAAY,CAAA;IACZ,0CAAc,CAAA;IACd,mDAAuB,CAAA;IACvB,0DAA8B,CAAA;AAChC,CAAC,EANW,wBAAwB,KAAxB,wBAAwB,QAMnC;AAED,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,iCAAW,CAAA;IACX,sCAAgB,CAAA;IAChB,sCAAgB,CAAA;AAClB,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B;AACD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './constants';
|
|
1
|
+
export * from './app.constants';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './constants';
|
|
1
|
+
export * from './app.constants';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface CoreConfig {
|
|
2
|
+
apiBaseUrl?: string;
|
|
3
|
+
apiTimeout?: number;
|
|
4
|
+
retryAttempts?: number;
|
|
5
|
+
retryDelay?: number;
|
|
6
|
+
enableCorrelationTracking?: boolean;
|
|
7
|
+
enableRequestLogging?: boolean;
|
|
8
|
+
enableErrorLogging?: boolean;
|
|
9
|
+
enableToastNotifications?: boolean;
|
|
10
|
+
includeAuthToken?: boolean;
|
|
11
|
+
authTokenHeader?: string;
|
|
12
|
+
enableMultiTenancy?: boolean;
|
|
13
|
+
tenantIdHeader?: string;
|
|
14
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
15
|
+
enableConsoleLogging?: boolean;
|
|
16
|
+
customHeaders?: Record<string, string | (() => string)>;
|
|
17
|
+
excludeUrls?: string[];
|
|
18
|
+
excludeMethods?: string[];
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-config.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/models/core-config.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './api-response';
|
|
2
|
-
export * from './jwt';
|
|
3
2
|
export * from './base-entity';
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './core-config';
|
|
4
|
+
export * from './jwt';
|
|
5
5
|
export * from './pagination-params';
|
|
6
|
+
export * from './paginated-result';
|
|
7
|
+
export * from './repository-config';
|
|
6
8
|
export * from './user-data';
|
package/src/lib/models/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './api-response';
|
|
2
|
-
export * from './jwt';
|
|
3
2
|
export * from './base-entity';
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './core-config';
|
|
4
|
+
export * from './jwt';
|
|
5
5
|
export * from './pagination-params';
|
|
6
|
+
export * from './paginated-result';
|
|
7
|
+
export * from './repository-config';
|
|
6
8
|
export * from './user-data';
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-config.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/models/repository-config.ts"],"names":[],"mappings":""}
|