@acontplus/ng-infrastructure 1.0.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/index.d.ts ADDED
@@ -0,0 +1,259 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken } from '@angular/core';
3
+ import { HttpContextToken, HttpInterceptorFn, HttpContext, HttpRequest, HttpClient } from '@angular/common/http';
4
+ import { Observable } from 'rxjs';
5
+ import { PaginationParams, PagedResult, UserData, HttpPort, HttpOptions } from '@acontplus/core';
6
+
7
+ interface ITokenProvider {
8
+ getToken(): string | null;
9
+ isAuthenticated(): boolean;
10
+ }
11
+ declare const TOKEN_PROVIDER: InjectionToken<ITokenProvider>;
12
+
13
+ declare const SKIP_NOTIFICATION: HttpContextToken<boolean>;
14
+ declare const SHOW_NOTIFICATIONS: HttpContextToken<boolean | undefined>;
15
+ declare const apiInterceptor: HttpInterceptorFn;
16
+
17
+ declare function customUrl(): HttpContext;
18
+ declare function skipContextHeaders(): HttpContext;
19
+ declare function withCustomHeaders(headers: Record<string, string>): HttpContext;
20
+ interface HttpContextConfig {
21
+ enableCorrelationTracking?: boolean;
22
+ enableRequestLogging?: boolean;
23
+ enableErrorLogging?: boolean;
24
+ customHeaders?: Record<string, string | (() => string)>;
25
+ clientVersion?: string;
26
+ tenantIdHeader?: string;
27
+ correlationIdHeader?: string;
28
+ requestIdHeader?: string;
29
+ timestampHeader?: string;
30
+ excludeUrls?: string[];
31
+ includeAuthToken?: boolean;
32
+ baseUrlInjection?: boolean;
33
+ }
34
+ declare const HTTP_CONTEXT_CONFIG: InjectionToken<HttpContextConfig>;
35
+ declare const httpContextInterceptor: HttpInterceptorFn;
36
+ interface HttpRequestLog {
37
+ method: string;
38
+ url: string;
39
+ originalUrl: string;
40
+ requestId: string;
41
+ correlationId: string;
42
+ tenantId: string;
43
+ timestamp: string;
44
+ headers: string[];
45
+ isCustomUrl: boolean;
46
+ }
47
+ interface HttpErrorLog extends HttpRequestLog {
48
+ status: number;
49
+ statusText: string;
50
+ message: string;
51
+ errorDetails: any;
52
+ environment: string;
53
+ }
54
+ declare function createHttpContextConfig(overrides?: Partial<HttpContextConfig>): HttpContextConfig;
55
+ declare function provideHttpContext(config?: Partial<HttpContextConfig>): {
56
+ provide: InjectionToken<HttpContextConfig>;
57
+ useValue: HttpContextConfig;
58
+ }[];
59
+
60
+ /**
61
+ * Helper function to disable spinner for specific requests
62
+ * @returns HttpContext with spinner disabled
63
+ */
64
+ declare function withoutSpinner(): HttpContext;
65
+ /**
66
+ * Service to track active HTTP requests
67
+ */
68
+ declare class ActiveRequestsTracker {
69
+ get count(): number;
70
+ add(request: HttpRequest<any>): void;
71
+ remove(request: HttpRequest<any>): void;
72
+ static ɵfac: i0.ɵɵFactoryDeclaration<ActiveRequestsTracker, never>;
73
+ static ɵprov: i0.ɵɵInjectableDeclaration<ActiveRequestsTracker>;
74
+ }
75
+ /**
76
+ * Interceptor that shows/hides a loading spinner based on active HTTP requests
77
+ */
78
+ declare const spinnerInterceptor: HttpInterceptorFn;
79
+
80
+ interface Repository<TEntity = any, TId = number> {
81
+ getById?(id: TId): Observable<TEntity>;
82
+ getAll?(pagination?: PaginationParams): Observable<PagedResult<TEntity>>;
83
+ create?(entity: Partial<TEntity>): Observable<TEntity>;
84
+ update?(id: TId, entity: Partial<TEntity>): Observable<TEntity>;
85
+ remove?(id: TId): Observable<void>;
86
+ }
87
+ interface SearchableRepository<TEntity = any, TId = number> extends Repository<TEntity, TId> {
88
+ search?(query: string, pagination: PaginationParams): Observable<PagedResult<TEntity>>;
89
+ }
90
+ interface RepositoryConfig {
91
+ endpoint: string;
92
+ baseUrl?: string;
93
+ version?: string;
94
+ }
95
+
96
+ declare abstract class BaseHttpRepository {
97
+ protected http: HttpClient;
98
+ protected abstract config: RepositoryConfig;
99
+ protected buildUrl(path?: string): string;
100
+ protected get<T>(path?: string, params?: any): Observable<T>;
101
+ protected post<T>(path: string | undefined, body: any): Observable<T>;
102
+ protected put<T>(path: string | undefined, body: any): Observable<T>;
103
+ protected patch<T>(path: string | undefined, body: any): Observable<T>;
104
+ protected delete<T>(path?: string): Observable<T>;
105
+ static ɵfac: i0.ɵɵFactoryDeclaration<BaseHttpRepository, never>;
106
+ static ɵprov: i0.ɵɵInjectableDeclaration<BaseHttpRepository>;
107
+ }
108
+
109
+ declare const REPOSITORY_CONFIG: InjectionToken<RepositoryConfig>;
110
+ declare class GenericRepository<TEntity = any, TId extends string | number = number> extends BaseHttpRepository implements Repository<TEntity, TId> {
111
+ protected config: RepositoryConfig;
112
+ constructor();
113
+ getById(id: TId): Observable<TEntity>;
114
+ getAll(pagination?: PaginationParams): Observable<PagedResult<TEntity>>;
115
+ create(entity: Partial<TEntity>): Observable<TEntity>;
116
+ update(id: TId, entity: Partial<TEntity>): Observable<TEntity>;
117
+ remove(id: TId): Observable<void>;
118
+ protected buildParams(pagination?: PaginationParams, filters?: Record<string, any>): any;
119
+ static ɵfac: i0.ɵɵFactoryDeclaration<GenericRepository<any, any>, never>;
120
+ static ɵprov: i0.ɵɵInjectableDeclaration<GenericRepository<any, any>>;
121
+ }
122
+ declare class SearchableGenericRepository<TEntity = any, TId extends string | number = number> extends GenericRepository<TEntity, TId> implements SearchableRepository<TEntity, TId> {
123
+ search(query: string, pagination: PaginationParams): Observable<PagedResult<TEntity>>;
124
+ static ɵfac: i0.ɵɵFactoryDeclaration<SearchableGenericRepository<any, any>, never>;
125
+ static ɵprov: i0.ɵɵInjectableDeclaration<SearchableGenericRepository<any, any>>;
126
+ }
127
+
128
+ declare class RepositoryFactory {
129
+ private http;
130
+ create<TEntity, TId extends string | number = number>(config: RepositoryConfig): Repository<TEntity, TId>;
131
+ static ɵfac: i0.ɵɵFactoryDeclaration<RepositoryFactory, never>;
132
+ static ɵprov: i0.ɵɵInjectableDeclaration<RepositoryFactory>;
133
+ }
134
+
135
+ declare class UserRepository {
136
+ private readonly tokenProvider;
137
+ getCurrentUser(): UserData | null;
138
+ static ɵfac: i0.ɵɵFactoryDeclaration<UserRepository, never>;
139
+ static ɵprov: i0.ɵɵInjectableDeclaration<UserRepository>;
140
+ }
141
+
142
+ declare class AngularHttpAdapter implements HttpPort {
143
+ private readonly http;
144
+ private readonly baseURL?;
145
+ constructor(http: HttpClient, baseURL?: string | undefined);
146
+ private buildOptions;
147
+ private request;
148
+ /** GET */
149
+ get<T>(url: string, options?: HttpOptions): Promise<T>;
150
+ /** POST */
151
+ post<T>(url: string, data?: any, options?: HttpOptions): Promise<T>;
152
+ /** PUT */
153
+ put<T>(url: string, data?: any, options?: HttpOptions): Promise<T>;
154
+ /** DELETE */
155
+ delete<T>(url: string, options?: HttpOptions): Promise<T>;
156
+ }
157
+
158
+ interface CoreConfig {
159
+ apiBaseUrl?: string;
160
+ apiTimeout?: number;
161
+ retryAttempts?: number;
162
+ retryDelay?: number;
163
+ enableCorrelationTracking?: boolean;
164
+ enableRequestLogging?: boolean;
165
+ enableErrorLogging?: boolean;
166
+ enableToastNotifications?: boolean;
167
+ includeAuthToken?: boolean;
168
+ authTokenHeader?: string;
169
+ enableMultiTenancy?: boolean;
170
+ tenantIdHeader?: string;
171
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
172
+ enableConsoleLogging?: boolean;
173
+ customHeaders?: Record<string, string | (() => string)>;
174
+ excludeUrls?: string[];
175
+ excludeMethods?: string[];
176
+ }
177
+ declare const CORE_CONFIG: InjectionToken<CoreConfig>;
178
+ declare class CoreConfigService {
179
+ private config;
180
+ private environment;
181
+ constructor();
182
+ /**
183
+ * Initialize configuration with defaults and environment overrides
184
+ */
185
+ private initializeConfig;
186
+ /**
187
+ * Get the current configuration
188
+ */
189
+ getConfig(): Required<CoreConfig>;
190
+ /**
191
+ * Update configuration at runtime
192
+ */
193
+ updateConfig(updates: Partial<CoreConfig>): void;
194
+ /**
195
+ * Get a specific configuration value
196
+ */
197
+ get<K extends keyof CoreConfig>(key: K): CoreConfig[K];
198
+ /**
199
+ * Check if a feature is enabled
200
+ */
201
+ isFeatureEnabled(feature: keyof CoreConfig): boolean;
202
+ /**
203
+ * Get API URL for a specific entity
204
+ */
205
+ getApiUrl(entityName?: string): string;
206
+ /**
207
+ * Check if a URL should be excluded from processing
208
+ */
209
+ shouldExcludeUrl(url: string): boolean;
210
+ /**
211
+ * Check if a method should be excluded from processing
212
+ */
213
+ shouldExcludeMethod(method: string): boolean;
214
+ /**
215
+ * Get custom headers with dynamic values resolved
216
+ */
217
+ getCustomHeaders(): Record<string, string>;
218
+ /**
219
+ * Reset configuration to defaults
220
+ */
221
+ resetConfig(): void;
222
+ static ɵfac: i0.ɵɵFactoryDeclaration<CoreConfigService, never>;
223
+ static ɵprov: i0.ɵɵInjectableDeclaration<CoreConfigService>;
224
+ }
225
+ declare function provideCoreConfig(config?: Partial<CoreConfig>): {
226
+ provide: InjectionToken<CoreConfig>;
227
+ useValue: Partial<CoreConfig>;
228
+ }[];
229
+ declare function createCoreConfig(overrides?: Partial<CoreConfig>): CoreConfig;
230
+
231
+ declare class CorrelationService {
232
+ private correlationId;
233
+ private readonly CORRELATION_KEY;
234
+ readonly currentCorrelationId: i0.Signal<string | null>;
235
+ getOrCreateCorrelationId(): string;
236
+ setCorrelationId(correlationId: string): void;
237
+ resetCorrelationId(): void;
238
+ getId(): string;
239
+ static ɵfac: i0.ɵɵFactoryDeclaration<CorrelationService, never>;
240
+ static ɵprov: i0.ɵɵInjectableDeclaration<CorrelationService>;
241
+ }
242
+
243
+ declare class LoggingService {
244
+ private environment;
245
+ log(level: 'info' | 'warn' | 'error', message: string, context?: any): void;
246
+ info(message: string, context?: any): void;
247
+ warn(message: string, context?: any): void;
248
+ error(message: string, context?: any): void;
249
+ logHttpRequest(log: HttpRequestLog): void;
250
+ logHttpError(error: HttpErrorLog): void;
251
+ logNetworkError(correlationId: string): void;
252
+ logRateLimitError(correlationId: string, url: string): void;
253
+ private logToExternalService;
254
+ static ɵfac: i0.ɵɵFactoryDeclaration<LoggingService, never>;
255
+ static ɵprov: i0.ɵɵInjectableDeclaration<LoggingService>;
256
+ }
257
+
258
+ export { ActiveRequestsTracker, AngularHttpAdapter, BaseHttpRepository, CORE_CONFIG, CoreConfigService, CorrelationService, GenericRepository, HTTP_CONTEXT_CONFIG, LoggingService, REPOSITORY_CONFIG, RepositoryFactory, SHOW_NOTIFICATIONS, SKIP_NOTIFICATION, SearchableGenericRepository, TOKEN_PROVIDER, UserRepository, apiInterceptor, createCoreConfig, createHttpContextConfig, customUrl, httpContextInterceptor, provideCoreConfig, provideHttpContext, skipContextHeaders, spinnerInterceptor, withCustomHeaders, withoutSpinner };
259
+ export type { CoreConfig, HttpContextConfig, HttpErrorLog, HttpRequestLog, ITokenProvider };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@acontplus/ng-infrastructure",
3
+ "version": "1.0.0",
4
+ "description": "Acontplus Angular Infrastructure library for managing HTTP interceptors and repositories.",
5
+ "dependencies": {
6
+ "tslib": "^2.3.0"
7
+ },
8
+ "peerDependencies": {
9
+ "@acontplus/core": "^1.0.12",
10
+ "@acontplus/ng-config": "^1.0.0",
11
+ "@acontplus/ng-notifications": "^1.0.7",
12
+ "@acontplus/ng-components": "^1.0.11",
13
+ "@angular/common": "^20.3.2",
14
+ "@angular/core": "^20.3.2"
15
+ },
16
+ "sideEffects": false,
17
+ "main": "fesm2022/acontplus-ng-infrastructure.mjs",
18
+ "module": "fesm2022/acontplus-ng-infrastructure.mjs",
19
+ "typings": "index.d.ts",
20
+ "files": [
21
+ "index.d.ts",
22
+ "*.d.ts",
23
+ "**/*.d.ts",
24
+ "fesm2022/**/*"
25
+ ],
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "keywords": [
34
+ "acontplus",
35
+ "angular",
36
+ "infrastructure",
37
+ "interceptors",
38
+ "repositories",
39
+ "typescript",
40
+ "frontend",
41
+ "library"
42
+ ],
43
+ "author": "Ivan Paz <ifer343@gmail.com>",
44
+ "license": "MIT",
45
+ "bugs": {
46
+ "url": "https://github.com/Acontplus-S-A-S/acontplus-libs/issues"
47
+ },
48
+ "homepage": "https://github.com/Acontplus-S-A-S/acontplus-libs#readme",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/Acontplus-S-A-S/acontplus-libs.git"
52
+ },
53
+ "release": {
54
+ "branches": [
55
+ "main"
56
+ ]
57
+ },
58
+ "exports": {
59
+ "./package.json": {
60
+ "default": "./package.json"
61
+ },
62
+ ".": {
63
+ "types": "./index.d.ts",
64
+ "default": "./fesm2022/acontplus-ng-infrastructure.mjs"
65
+ }
66
+ }
67
+ }