@acontplus/core 1.0.16 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @acontplus/core
2
2
 
3
- Core library for AcontPlus applications, providing essential utilities and functionalities for business logic, calculations, and configuration management.
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
 
@@ -10,19 +10,55 @@ npm install @acontplus/core
10
10
 
11
11
  ## Features
12
12
 
13
- - **Pricing Calculations**: Comprehensive pricing utilities including discount calculators, line item calculators, pricing calculators, profit calculators, and tax calculators
14
- - **Constants**: Predefined constants for SRI (Servicio de Rentas Internas) document types and separators
13
+ - **Clean Architecture**: Ports and adapters pattern for external integrations
14
+ - **Domain Models**: Base entities, value objects, and domain-specific models
15
+ - **Pricing Engine**: Comprehensive pricing calculations with discount, tax, profit, and line item calculators
16
+ - **HTTP Adapters**: Axios and Fetch adapters with HTTP client factory
17
+ - **Use Cases**: Base use case pattern for business logic encapsulation
18
+ - **Value Objects**: Money, EntityId, IdentificationNumber, and AuthTokens value objects
15
19
  - **Environment Configuration**: Type-safe environment configuration interfaces
16
- - **Models & Value Objects**: Domain models and value objects for business entities
17
- - **Ports & Adapters**: Clean architecture patterns with ports and adapters for external integrations
18
- - **Type Definitions**: Comprehensive TypeScript type definitions for type safety
20
+ - **Constants**: Application constants including SRI document types
21
+ - **Type Definitions**: Comprehensive TypeScript type definitions for pricing and business logic
22
+
23
+ ## Architecture
24
+
25
+ This library follows Clean Architecture principles with clear separation of concerns:
26
+
27
+ - **Adapters**: External service integrations (HTTP clients)
28
+ - **Ports**: Interfaces for external dependencies
29
+ - **Models**: Domain entities and data transfer objects
30
+ - **Value Objects**: Immutable objects representing domain concepts
31
+ - **Use Cases**: Business logic encapsulation
32
+ - **Types**: TypeScript definitions for type safety
19
33
 
20
34
  ## Usage
21
35
 
36
+ ### HTTP Adapters
37
+
38
+ ```typescript
39
+ import { HttpClientFactory, AxiosAdapter, FetchAdapter } from '@acontplus/core';
40
+
41
+ // Create HTTP client with Axios
42
+ const axiosClient = HttpClientFactory.create('axios');
43
+
44
+ // Create HTTP client with Fetch
45
+ const fetchClient = HttpClientFactory.create('fetch');
46
+
47
+ // Use adapter directly
48
+ const axiosAdapter = new AxiosAdapter();
49
+ const response = await axiosAdapter.get('https://api.example.com/data');
50
+ ```
51
+
22
52
  ### Pricing Calculations
23
53
 
24
54
  ```typescript
25
- import { DiscountCalculator, TaxCalculator, PricingCalculator } from '@acontplus/core';
55
+ import {
56
+ DiscountCalculator,
57
+ TaxCalculator,
58
+ PricingCalculator,
59
+ ProfitCalculator,
60
+ LineItemCalculator,
61
+ } from '@acontplus/core';
26
62
 
27
63
  // Calculate discounts
28
64
  const discountCalc = new DiscountCalculator();
@@ -32,21 +68,105 @@ const discount = discountCalc.calculate(100, 10); // 10% discount on $100
32
68
  const taxCalc = new TaxCalculator();
33
69
  const tax = taxCalc.calculate(100, 0.12); // 12% tax on $100
34
70
 
71
+ // Calculate profit margins
72
+ const profitCalc = new ProfitCalculator();
73
+ const profit = profitCalc.calculate(cost, sellingPrice);
74
+
75
+ // Line item calculations
76
+ const lineItemCalc = new LineItemCalculator();
77
+ const lineTotal = lineItemCalc.calculate(quantity, unitPrice, discount, tax);
78
+
35
79
  // Complex pricing calculations
36
80
  const pricingCalc = new PricingCalculator();
37
81
  const finalPrice = pricingCalc.calculateTotal(items, discounts, taxes);
38
82
  ```
39
83
 
40
- ### Constants
84
+ ### Value Objects
41
85
 
42
86
  ```typescript
43
- import { SRI_DOCUMENT_TYPE, SEPARATOR_KEY_CODE } from '@acontplus/core';
87
+ import { Money, EntityId, IdentificationNumber, AuthTokens } from '@acontplus/core';
88
+
89
+ // Money value object for financial calculations
90
+ const price = new Money(99.99, 'USD');
91
+ const discountedPrice = price.subtract(new Money(10.0, 'USD'));
44
92
 
45
- // Use SRI document types for Ecuadorian tax system
46
- const documentType = SRI_DOCUMENT_TYPE.RUC; // '04'
93
+ // Entity ID for domain entities
94
+ const customerId = new EntityId(12345);
47
95
 
48
- // Use separator constants
49
- const separator = SEPARATOR_KEY_CODE.SLASH; // '|'
96
+ // Identification number with validation
97
+ const ecuadorianId = new IdentificationNumber('1234567890');
98
+
99
+ // Authentication tokens
100
+ const tokens = new AuthTokens('access_token', 'refresh_token');
101
+ ```
102
+
103
+ ### Domain Models
104
+
105
+ ```typescript
106
+ import { BaseEntity, ApiResponse, PaginatedResult } from '@acontplus/core';
107
+
108
+ // Base entity for domain objects
109
+ class Customer extends BaseEntity {
110
+ constructor(
111
+ id: number,
112
+ public readonly name: string,
113
+ public readonly email: string,
114
+ ) {
115
+ super(id);
116
+ }
117
+ }
118
+
119
+ // API response handling
120
+ const response: ApiResponse<Customer> = {
121
+ success: true,
122
+ data: customer,
123
+ message: 'Customer retrieved successfully',
124
+ };
125
+
126
+ // Paginated results
127
+ const paginatedCustomers: PaginatedResult<Customer> = {
128
+ items: customers,
129
+ totalCount: 100,
130
+ pageSize: 10,
131
+ currentPage: 1,
132
+ };
133
+ ```
134
+
135
+ ### Use Cases
136
+
137
+ ```typescript
138
+ import { UseCase } from '@acontplus/core';
139
+
140
+ // Business logic encapsulation
141
+ class CreateCustomerUseCase extends UseCase<CreateCustomerRequest, Customer> {
142
+ constructor(private customerRepository: CustomerRepository) {
143
+ super();
144
+ }
145
+
146
+ async execute(request: CreateCustomerRequest): Promise<Customer> {
147
+ // Validate business rules
148
+ this.validateRequest(request);
149
+
150
+ // Execute business logic
151
+ return await this.customerRepository.create(request);
152
+ }
153
+
154
+ private validateRequest(request: CreateCustomerRequest): void {
155
+ if (!request.name || request.name.trim().length === 0) {
156
+ throw new Error('Customer name is required');
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ ### Constants
163
+
164
+ ```typescript
165
+ import { APP_CONSTANTS } from '@acontplus/core';
166
+
167
+ // Application constants
168
+ const maxRetries = APP_CONSTANTS.MAX_RETRY_ATTEMPTS;
169
+ const timeout = APP_CONSTANTS.DEFAULT_TIMEOUT;
50
170
  ```
51
171
 
52
172
  ### Environment Configuration
@@ -64,6 +184,16 @@ const environment: Environment = {
64
184
  };
65
185
  ```
66
186
 
67
- ## Running unit tests
187
+ ### Pricing Types
68
188
 
69
- Run `nx test core` to execute the unit tests.
189
+ ```typescript
190
+ import { PricingTypes } from '@acontplus/core';
191
+
192
+ // Type-safe pricing calculations
193
+ const calculation: PricingTypes.PricingCalculation = {
194
+ basePrice: 100,
195
+ discounts: [{ type: 'percentage', value: 10 }],
196
+ taxes: [{ type: 'percentage', value: 8.25 }],
197
+ finalPrice: 97.43,
198
+ };
199
+ ```
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@acontplus/core",
3
- "version": "1.0.16",
4
- "description": "Core library for Acontplus projects, providing essential utilities and functionalities.",
3
+ "version": "1.1.0",
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
5
  "dependencies": {
6
- "@acontplus/utils": "^1.0.8",
6
+ "@acontplus/utils": "^1.0.10",
7
7
  "tslib": "^2.8.1",
8
8
  "uuid": "^13.0.0"
9
9
  },
@@ -30,11 +30,26 @@
30
30
  "test": "nx test core"
31
31
  },
32
32
  "keywords": [
33
+ "acontplus",
34
+ "core",
35
+ "ddd",
36
+ "domain-driven-design",
37
+ "clean-architecture",
38
+ "use-cases",
39
+ "value-objects",
40
+ "entities",
41
+ "adapters",
42
+ "ports",
43
+ "pricing",
33
44
  "calculations",
34
45
  "constants",
35
46
  "environment",
36
- "pricing",
37
- "typescript"
47
+ "http-client",
48
+ "api-response",
49
+ "pagination",
50
+ "jwt",
51
+ "typescript",
52
+ "library"
38
53
  ],
39
54
  "author": "Ivan Paz <ifer343@gmail.com>",
40
55
  "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,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=core-config.js.map
@@ -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 './paginated-result';
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';
@@ -1,7 +1,9 @@
1
1
  export * from './api-response';
2
- export * from './jwt';
3
2
  export * from './base-entity';
4
- export * from './paginated-result';
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,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,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,5 @@
1
+ export interface RepositoryConfig {
2
+ endpoint: string;
3
+ baseUrl?: string;
4
+ version?: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=repository-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-config.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/models/repository-config.ts"],"names":[],"mappings":""}