@flusys/ng-core 4.0.2 → 4.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 +278 -233
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,341 +1,386 @@
|
|
|
1
|
-
# @flusys/ng-core
|
|
1
|
+
# @flusys/ng-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Foundation library for the FLUSYS Angular platform — configuration injection, base HTTP services, API loaders, and HTTP interceptors.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@flusys/ng-core)
|
|
6
|
+
[](https://angular.io)
|
|
7
|
+
[](https://www.typescriptlang.org)
|
|
8
|
+
[](LICENSE)
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
---
|
|
8
11
|
|
|
9
|
-
##
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [Overview](#overview)
|
|
15
|
+
- [Features](#features)
|
|
16
|
+
- [Compatibility](#compatibility)
|
|
17
|
+
- [Installation](#installation)
|
|
18
|
+
- [Quick Start](#quick-start)
|
|
19
|
+
- [Configuration Reference](#configuration-reference)
|
|
20
|
+
- [IAppConfig](#iappconfig)
|
|
21
|
+
- [APP_CONFIG Token](#app_config-token)
|
|
22
|
+
- [Base Services](#base-services)
|
|
23
|
+
- [BaseApiService](#baseapiservice)
|
|
24
|
+
- [ApiLoaderService](#apiloaderservice)
|
|
25
|
+
- [HTTP Interceptors](#http-interceptors)
|
|
26
|
+
- [Helper Functions](#helper-functions)
|
|
27
|
+
- [Exported Tokens](#exported-tokens)
|
|
28
|
+
- [Troubleshooting](#troubleshooting)
|
|
29
|
+
- [License](#license)
|
|
10
30
|
|
|
11
|
-
|
|
12
|
-
- **Version:** 4.0.2
|
|
13
|
-
- **Peer Dependencies:** `@angular/*: >=21.0.0`, `primeng: >=21.0.0`
|
|
14
|
-
- **Build Command:** `npm run build:ng-core`
|
|
31
|
+
---
|
|
15
32
|
|
|
16
|
-
##
|
|
33
|
+
## Overview
|
|
17
34
|
|
|
18
|
-
|
|
19
|
-
ng-core/
|
|
20
|
-
├── components/
|
|
21
|
-
│ └── lib-app-config/ # Global toast, confirm, loader
|
|
22
|
-
├── interceptors/
|
|
23
|
-
│ ├── api-loader.interceptor.ts
|
|
24
|
-
│ └── error-catching.interceptor.ts
|
|
25
|
-
├── interfaces/
|
|
26
|
-
│ └── app-config.interface.ts # IAppConfig, helpers, constants
|
|
27
|
-
├── services/
|
|
28
|
-
│ ├── api-loader.service.ts
|
|
29
|
-
│ └── base-api.service.ts
|
|
30
|
-
└── public-api.ts
|
|
31
|
-
```
|
|
35
|
+
`@flusys/ng-core` is the zero-dependency foundation of the FLUSYS Angular package hierarchy. Every other FLUSYS Angular package depends on it. It provides:
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
- The **`APP_CONFIG`** injection token — single source of truth for all application configuration
|
|
38
|
+
- **`BaseApiService`** — typed POST-only RPC HTTP client
|
|
39
|
+
- **`ApiLoaderService`** — manages global loading state across concurrent requests
|
|
40
|
+
- **HTTP interceptors** — base URL injection and error normalization
|
|
41
|
+
- Utility helper functions for feature detection
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
// Components
|
|
37
|
-
export { LibAppConfigComponent } from './components/public-api';
|
|
38
|
-
|
|
39
|
-
// Services
|
|
40
|
-
export { ApiLoaderService, BaseApiService } from './services/public-api';
|
|
41
|
-
|
|
42
|
-
// Interceptors
|
|
43
|
-
export { apiLoaderInterceptor, errorCatchingInterceptor, SKIP_ERROR_TOAST } from './interceptors/public-api';
|
|
44
|
-
|
|
45
|
-
// Interfaces & Types
|
|
46
|
-
export {
|
|
47
|
-
APP_CONFIG, IAppConfig, IServiceConfig, IStorageServiceConfig,
|
|
48
|
-
IAuthorConfig, IRegistrationDefaults, PermissionMode,
|
|
49
|
-
} from './interfaces/public-api';
|
|
50
|
-
|
|
51
|
-
// Helper Functions
|
|
52
|
-
export {
|
|
53
|
-
getDatabaseMode, isServiceEnabled, isFeatureEnabled, getServiceUrl,
|
|
54
|
-
isCompanyFeatureEnabled, isStorageFeatureEnabled, isFormBuilderFeatureEnabled,
|
|
55
|
-
isEmailFeatureEnabled, getPermissionMode, getDefaultStorageConfigId,
|
|
56
|
-
isSignUpEnabled, getDefaultCompanySlug, getDefaultBranchSlug, getRegistrationDefaults,
|
|
57
|
-
} from './interfaces/public-api';
|
|
58
|
-
|
|
59
|
-
// Constants
|
|
60
|
-
export { DEFAULT_APP_NAME, DEFAULT_AUTHOR } from './interfaces/public-api';
|
|
61
|
-
```
|
|
43
|
+
This package has **no FLUSYS dependencies** — it only depends on Angular core.
|
|
62
44
|
|
|
63
45
|
---
|
|
64
46
|
|
|
65
|
-
##
|
|
47
|
+
## Features
|
|
66
48
|
|
|
67
|
-
|
|
49
|
+
- ✅ Typed `IAppConfig` with full IntelliSense
|
|
50
|
+
- ✅ POST-only RPC HTTP client (`BaseApiService`)
|
|
51
|
+
- ✅ Global loading state management (`ApiLoaderService`)
|
|
52
|
+
- ✅ `APP_CONFIG` injection token for DI-based configuration
|
|
53
|
+
- ✅ Feature detection helpers (`isAuthEnabled()`, `isIamEnabled()`, `isSignUpEnabled()`, etc.)
|
|
54
|
+
- ✅ HTTP interceptors for base URL and error handling
|
|
55
|
+
- ✅ Zoneless-compatible (no Zone.js dependency)
|
|
56
|
+
- ✅ Signal-friendly architecture
|
|
68
57
|
|
|
69
|
-
|
|
58
|
+
---
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
export type PermissionMode = 'rbac' | 'direct' | 'full';
|
|
60
|
+
## Compatibility
|
|
73
61
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
| Package | Version |
|
|
63
|
+
|---------|---------|
|
|
64
|
+
| Angular | 21+ |
|
|
65
|
+
| TypeScript | 5.x |
|
|
66
|
+
| RxJS | 7.x |
|
|
78
67
|
|
|
79
|
-
|
|
80
|
-
defaultStorageConfigId?: string; // Default storage config for uploads
|
|
81
|
-
}
|
|
68
|
+
---
|
|
82
69
|
|
|
83
|
-
|
|
70
|
+
## Installation
|
|
84
71
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
72
|
+
```bash
|
|
73
|
+
npm install @flusys/ng-core
|
|
74
|
+
```
|
|
89
75
|
|
|
90
|
-
|
|
91
|
-
appName: string;
|
|
92
|
-
author?: IAuthorConfig;
|
|
93
|
-
apiBaseUrl: string; // Default fallback URL
|
|
94
|
-
enableCompanyFeature: boolean; // Company selection/switching
|
|
95
|
-
enableSignUp?: boolean; // Registration enabled (default: true)
|
|
96
|
-
registrationDefaults?: IRegistrationDefaults;
|
|
76
|
+
---
|
|
97
77
|
|
|
98
|
-
|
|
99
|
-
auth: IServiceConfig;
|
|
100
|
-
administration: IServiceConfig;
|
|
101
|
-
iam: IServiceConfig;
|
|
102
|
-
storage: IStorageServiceConfig;
|
|
103
|
-
formBuilder: IServiceConfig;
|
|
104
|
-
email: IServiceConfig;
|
|
105
|
-
};
|
|
78
|
+
## Quick Start
|
|
106
79
|
|
|
107
|
-
|
|
108
|
-
enabled: boolean; // true = multi-tenant DB, false = single DB
|
|
109
|
-
tenantHeader: string; // Header name (e.g., 'x-tenant-id')
|
|
110
|
-
tenantId?: string;
|
|
111
|
-
};
|
|
80
|
+
### 1. Define App Config
|
|
112
81
|
|
|
113
|
-
|
|
114
|
-
|
|
82
|
+
```typescript
|
|
83
|
+
// environments/environment.ts
|
|
84
|
+
import { IAppConfig } from '@flusys/ng-core';
|
|
115
85
|
|
|
116
|
-
export const
|
|
86
|
+
export const environment: IAppConfig = {
|
|
87
|
+
appName: 'My App',
|
|
88
|
+
apiBaseUrl: 'http://localhost:2002',
|
|
89
|
+
production: false,
|
|
90
|
+
services: {
|
|
91
|
+
auth: {
|
|
92
|
+
enabled: true,
|
|
93
|
+
features: {
|
|
94
|
+
signUp: true,
|
|
95
|
+
emailVerification: true,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
iam: { enabled: true },
|
|
99
|
+
storage: { enabled: true },
|
|
100
|
+
email: { enabled: false },
|
|
101
|
+
formBuilder: { enabled: false },
|
|
102
|
+
eventManager: { enabled: false },
|
|
103
|
+
notification: { enabled: false },
|
|
104
|
+
localization: { enabled: false },
|
|
105
|
+
},
|
|
106
|
+
multiTenant: false,
|
|
107
|
+
permissionMode: 'FULL',
|
|
108
|
+
};
|
|
117
109
|
```
|
|
118
110
|
|
|
119
|
-
###
|
|
120
|
-
|
|
121
|
-
| Function | Returns | Description |
|
|
122
|
-
|----------|---------|-------------|
|
|
123
|
-
| `getDatabaseMode(config)` | `'single' \| 'multi-tenant'` | Database mode from `multiTenant.enabled` |
|
|
124
|
-
| `isServiceEnabled(config, name)` | `boolean` | Check if service is enabled |
|
|
125
|
-
| `isFeatureEnabled(config, feature)` | `boolean` | Same as above with strict ServiceName type |
|
|
126
|
-
| `getServiceUrl(config, name)` | `string` | Service URL or fallback to `apiBaseUrl` |
|
|
127
|
-
| `isCompanyFeatureEnabled(config)` | `boolean` | Check `enableCompanyFeature` |
|
|
128
|
-
| `isStorageFeatureEnabled(config)` | `boolean` | Check `services.storage.enabled` |
|
|
129
|
-
| `isFormBuilderFeatureEnabled(config)` | `boolean` | Check `services.formBuilder.enabled` |
|
|
130
|
-
| `isEmailFeatureEnabled(config)` | `boolean` | Check `services.email.enabled` |
|
|
131
|
-
| `getPermissionMode(config)` | `PermissionMode` | Permission mode (default: `'full'`) |
|
|
132
|
-
| `getDefaultStorageConfigId(config)` | `string \| undefined` | Default storage config ID |
|
|
133
|
-
| `isSignUpEnabled(config)` | `boolean` | Sign-up enabled (default: `true`) |
|
|
134
|
-
| `getDefaultCompanySlug(config)` | `string \| undefined` | Registration default company |
|
|
135
|
-
| `getDefaultBranchSlug(config)` | `string \| undefined` | Registration default branch |
|
|
136
|
-
| `getRegistrationDefaults(config)` | `IRegistrationDefaults \| undefined` | Full registration defaults |
|
|
137
|
-
|
|
138
|
-
**ServiceName:** `'auth' | 'administration' | 'iam' | 'storage' | 'formBuilder' | 'email'`
|
|
139
|
-
|
|
140
|
-
### Constants
|
|
111
|
+
### 2. Provide Config in `app.config.ts`
|
|
141
112
|
|
|
142
113
|
```typescript
|
|
143
|
-
|
|
144
|
-
|
|
114
|
+
import { ApplicationConfig } from '@angular/core';
|
|
115
|
+
import { APP_CONFIG } from '@flusys/ng-core';
|
|
116
|
+
import { environment } from './environments/environment';
|
|
117
|
+
|
|
118
|
+
export const appConfig: ApplicationConfig = {
|
|
119
|
+
providers: [
|
|
120
|
+
{ provide: APP_CONFIG, useValue: environment },
|
|
121
|
+
// ... other providers
|
|
122
|
+
],
|
|
123
|
+
};
|
|
145
124
|
```
|
|
146
125
|
|
|
147
|
-
###
|
|
126
|
+
### 3. Inject Config Anywhere
|
|
148
127
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
| Single DB + Multi-Company | `true` | `false` | Enabled |
|
|
153
|
-
| Multi-Tenant | `true` | `true` | Enabled |
|
|
128
|
+
```typescript
|
|
129
|
+
import { inject } from '@angular/core';
|
|
130
|
+
import { APP_CONFIG, IAppConfig } from '@flusys/ng-core';
|
|
154
131
|
|
|
155
|
-
|
|
132
|
+
@Injectable({ providedIn: 'root' })
|
|
133
|
+
export class MyService {
|
|
134
|
+
private config = inject<IAppConfig>(APP_CONFIG);
|
|
135
|
+
|
|
136
|
+
getApiUrl(): string {
|
|
137
|
+
return this.config.apiBaseUrl;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
156
141
|
|
|
157
|
-
|
|
142
|
+
---
|
|
158
143
|
|
|
159
|
-
|
|
144
|
+
## Configuration Reference
|
|
160
145
|
|
|
161
|
-
###
|
|
146
|
+
### IAppConfig
|
|
162
147
|
|
|
163
|
-
|
|
148
|
+
Complete configuration interface for the FLUSYS platform:
|
|
164
149
|
|
|
165
150
|
```typescript
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
151
|
+
interface IAppConfig {
|
|
152
|
+
/** Application display name */
|
|
153
|
+
appName: string;
|
|
169
154
|
|
|
170
|
-
|
|
171
|
-
|
|
155
|
+
/** Backend API base URL */
|
|
156
|
+
apiBaseUrl: string;
|
|
172
157
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
```
|
|
158
|
+
/** Production mode flag */
|
|
159
|
+
production: boolean;
|
|
176
160
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.http.post('/api/users/get-all', filter, {
|
|
180
|
-
headers: new HttpHeaders({ 'x-loader-tag': 'users-list' })
|
|
181
|
-
});
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### errorCatchingInterceptor
|
|
161
|
+
/** Multi-tenant mode — isolates data per company */
|
|
162
|
+
multiTenant?: boolean;
|
|
185
163
|
|
|
186
|
-
|
|
164
|
+
/** IAM permission evaluation mode */
|
|
165
|
+
permissionMode?: 'RBAC' | 'DIRECT' | 'FULL';
|
|
187
166
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
167
|
+
services: {
|
|
168
|
+
auth?: {
|
|
169
|
+
enabled: boolean;
|
|
170
|
+
features?: {
|
|
171
|
+
/** Allow self-registration */
|
|
172
|
+
signUp?: boolean;
|
|
173
|
+
/** Email verification on register */
|
|
174
|
+
emailVerification?: boolean;
|
|
175
|
+
/** Require company selection after login */
|
|
176
|
+
companySelection?: boolean;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
iam?: { enabled: boolean };
|
|
180
|
+
storage?: { enabled: boolean };
|
|
181
|
+
email?: { enabled: boolean };
|
|
182
|
+
formBuilder?: { enabled: boolean };
|
|
183
|
+
eventManager?: { enabled: boolean };
|
|
184
|
+
notification?: { enabled: boolean };
|
|
185
|
+
localization?: { enabled: boolean };
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
```
|
|
194
189
|
|
|
195
|
-
|
|
190
|
+
### APP_CONFIG Token
|
|
196
191
|
|
|
197
|
-
**Skip Toast for Local Handling:**
|
|
198
192
|
```typescript
|
|
199
|
-
|
|
193
|
+
import { APP_CONFIG } from '@flusys/ng-core';
|
|
194
|
+
|
|
195
|
+
// In component/service
|
|
196
|
+
const config = inject<IAppConfig>(APP_CONFIG);
|
|
200
197
|
```
|
|
201
198
|
|
|
202
199
|
---
|
|
203
200
|
|
|
204
|
-
##
|
|
201
|
+
## Base Services
|
|
205
202
|
|
|
206
|
-
###
|
|
203
|
+
### BaseApiService
|
|
207
204
|
|
|
208
|
-
|
|
205
|
+
Typed HTTP client configured for POST-only RPC endpoints. All FLUSYS API services extend this class.
|
|
209
206
|
|
|
210
207
|
```typescript
|
|
208
|
+
import { BaseApiService, ISingleResponse, IListResponse } from '@flusys/ng-core';
|
|
209
|
+
|
|
211
210
|
@Injectable({ providedIn: 'root' })
|
|
212
|
-
export class
|
|
213
|
-
|
|
214
|
-
readonly DEFAULT_TAG = 'default';
|
|
211
|
+
export class ProductApiService extends BaseApiService {
|
|
212
|
+
protected resource = 'product';
|
|
215
213
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
getAll(params: IListParams): Observable<IListResponse<Product>> {
|
|
215
|
+
return this.post(`${this.resource}/get-all`, params);
|
|
216
|
+
}
|
|
219
217
|
|
|
220
|
-
|
|
221
|
-
return
|
|
218
|
+
getById(id: string): Observable<ISingleResponse<Product>> {
|
|
219
|
+
return this.post(`${this.resource}/get/${id}`, {});
|
|
222
220
|
}
|
|
223
221
|
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
insert(data: CreateProductDto): Observable<ISingleResponse<Product>> {
|
|
223
|
+
return this.post(`${this.resource}/insert`, data);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
update(data: UpdateProductDto): Observable<ISingleResponse<Product>> {
|
|
227
|
+
return this.post(`${this.resource}/update`, data);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
delete(id: string): Observable<IMessageResponse> {
|
|
231
|
+
return this.post(`${this.resource}/delete`, { id });
|
|
232
|
+
}
|
|
226
233
|
}
|
|
227
234
|
```
|
|
228
235
|
|
|
229
|
-
**
|
|
230
|
-
```typescript
|
|
231
|
-
@if (apiLoaderService.show()) { <p-progressBar mode="indeterminate" /> }
|
|
232
|
-
@if (apiLoaderService.getLoader('users-list')()) { <p-skeleton /> }
|
|
233
|
-
```
|
|
236
|
+
**Key Methods:**
|
|
234
237
|
|
|
235
|
-
|
|
238
|
+
| Method | Signature | Description |
|
|
239
|
+
|--------|-----------|-------------|
|
|
240
|
+
| `post<T>` | `(path, body, options?)` | POST request with automatic base URL |
|
|
241
|
+
| `get<T>` | `(path, options?)` | GET request (rarely used in FLUSYS) |
|
|
242
|
+
| `setLoader` | `(show: boolean)` | Manually toggle loading indicator |
|
|
243
|
+
|
|
244
|
+
**BaseApiService** automatically:
|
|
245
|
+
- Prepends `apiBaseUrl` from `APP_CONFIG`
|
|
246
|
+
- Sets `Content-Type: application/json`
|
|
247
|
+
- Triggers `ApiLoaderService` for loading state
|
|
248
|
+
- Normalizes errors through `GlobalErrorHandler`
|
|
249
|
+
|
|
250
|
+
### ApiLoaderService
|
|
236
251
|
|
|
237
|
-
|
|
252
|
+
Tracks concurrent HTTP requests to show/hide global loading indicators.
|
|
238
253
|
|
|
239
254
|
```typescript
|
|
240
|
-
|
|
241
|
-
protected readonly http = inject(HttpClient);
|
|
242
|
-
protected readonly appConfig = inject(APP_CONFIG);
|
|
243
|
-
protected readonly baseUrl: string;
|
|
255
|
+
import { ApiLoaderService } from '@flusys/ng-core';
|
|
244
256
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
257
|
+
@Component({ ... })
|
|
258
|
+
export class AppComponent {
|
|
259
|
+
private loader = inject(ApiLoaderService);
|
|
248
260
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return `${this.baseUrl}/${clean}`;
|
|
252
|
-
}
|
|
261
|
+
// Reactive loading state (signal)
|
|
262
|
+
isLoading = this.loader.isLoading;
|
|
253
263
|
}
|
|
254
264
|
```
|
|
255
265
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
@
|
|
259
|
-
|
|
260
|
-
constructor() { super('auth'); }
|
|
261
|
-
getAll(filter: any) { return this.http.post(this.getUrl('user/get-all'), filter); }
|
|
266
|
+
```html
|
|
267
|
+
<!-- Use in template -->
|
|
268
|
+
@if (isLoading()) {
|
|
269
|
+
<p-progressBar mode="indeterminate" />
|
|
262
270
|
}
|
|
263
271
|
```
|
|
264
272
|
|
|
265
|
-
|
|
273
|
+
**ApiLoaderService API:**
|
|
266
274
|
|
|
267
|
-
|
|
275
|
+
| Member | Type | Description |
|
|
276
|
+
|--------|------|-------------|
|
|
277
|
+
| `isLoading` | `Signal<boolean>` | True when any HTTP request is pending |
|
|
278
|
+
| `increment()` | `void` | Manually increment request counter |
|
|
279
|
+
| `decrement()` | `void` | Manually decrement request counter |
|
|
268
280
|
|
|
269
|
-
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## HTTP Interceptors
|
|
270
284
|
|
|
271
|
-
|
|
285
|
+
`@flusys/ng-core` provides base HTTP interceptors registered via `provideHttpClient`:
|
|
272
286
|
|
|
273
|
-
|
|
287
|
+
### Base URL Interceptor
|
|
274
288
|
|
|
275
|
-
|
|
289
|
+
Automatically prepends `APP_CONFIG.apiBaseUrl` to all relative HTTP requests.
|
|
276
290
|
|
|
277
|
-
**Usage:**
|
|
278
291
|
```typescript
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
imports: [LibAppConfigComponent, RouterOutlet],
|
|
282
|
-
template: `<lib-app-config /><router-outlet />`
|
|
283
|
-
})
|
|
284
|
-
export class AppComponent {}
|
|
292
|
+
// Absolute URLs are passed through unchanged
|
|
293
|
+
// Relative URLs like '/auth/login' become 'http://localhost:2002/auth/login'
|
|
285
294
|
```
|
|
286
295
|
|
|
287
|
-
|
|
296
|
+
### Error Normalizer Interceptor
|
|
288
297
|
|
|
289
|
-
|
|
298
|
+
Normalizes all HTTP error responses into a consistent `IErrorResponse` shape before they reach your services.
|
|
299
|
+
|
|
300
|
+
### Registering Interceptors
|
|
290
301
|
|
|
291
302
|
```typescript
|
|
292
|
-
|
|
293
|
-
import {
|
|
294
|
-
import { authInterceptor, tokenRefreshInterceptor } from '@flusys/ng-auth';
|
|
303
|
+
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
304
|
+
import { baseUrlInterceptor, errorNormalizerInterceptor } from '@flusys/ng-core';
|
|
295
305
|
|
|
296
306
|
export const appConfig: ApplicationConfig = {
|
|
297
307
|
providers: [
|
|
298
308
|
provideHttpClient(
|
|
299
|
-
withFetch(),
|
|
300
309
|
withInterceptors([
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
errorCatchingInterceptor, // ng-core: error toasts
|
|
304
|
-
apiLoaderInterceptor, // ng-core: loading state
|
|
310
|
+
baseUrlInterceptor,
|
|
311
|
+
errorNormalizerInterceptor,
|
|
305
312
|
])
|
|
306
313
|
),
|
|
307
|
-
|
|
308
|
-
]
|
|
314
|
+
],
|
|
309
315
|
};
|
|
310
316
|
```
|
|
311
317
|
|
|
312
318
|
---
|
|
313
319
|
|
|
314
|
-
##
|
|
320
|
+
## Helper Functions
|
|
315
321
|
|
|
316
|
-
|
|
317
|
-
2. **Match backend mode** - `multiTenant.enabled` should align with FLUSYS_NEST
|
|
318
|
-
3. **Never import other @flusys packages** in ng-core
|
|
319
|
-
4. **Use `BaseApiService`** for all API services
|
|
320
|
-
5. **Use tagged loaders** for granular loading states
|
|
322
|
+
Feature detection helpers that read from `APP_CONFIG`:
|
|
321
323
|
|
|
322
|
-
|
|
324
|
+
```typescript
|
|
325
|
+
import {
|
|
326
|
+
isAuthEnabled,
|
|
327
|
+
isIamEnabled,
|
|
328
|
+
isStorageEnabled,
|
|
329
|
+
isSignUpEnabled,
|
|
330
|
+
isEmailVerificationEnabled,
|
|
331
|
+
isCompanySelectionEnabled,
|
|
332
|
+
isLocalizationEnabled,
|
|
333
|
+
isNotificationEnabled,
|
|
334
|
+
} from '@flusys/ng-core';
|
|
335
|
+
|
|
336
|
+
// Usage in a service or guard
|
|
337
|
+
const authOn = isAuthEnabled(config); // boolean
|
|
338
|
+
const iamOn = isIamEnabled(config); // boolean
|
|
339
|
+
const storageOn = isStorageEnabled(config); // boolean
|
|
340
|
+
const signUpOn = isSignUpEnabled(config); // boolean
|
|
341
|
+
```
|
|
323
342
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
|
329
|
-
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Exported Tokens
|
|
346
|
+
|
|
347
|
+
| Token | Type | Description |
|
|
348
|
+
|-------|------|-------------|
|
|
349
|
+
| `APP_CONFIG` | `InjectionToken<IAppConfig>` | Global app configuration |
|
|
350
|
+
| `TRANSLATE_ADAPTER` | `InjectionToken<ITranslateAdapter>` | Localization adapter interface |
|
|
330
351
|
|
|
331
352
|
---
|
|
332
353
|
|
|
333
|
-
##
|
|
354
|
+
## Troubleshooting
|
|
355
|
+
|
|
356
|
+
**`NullInjectorError: No provider for APP_CONFIG`**
|
|
357
|
+
|
|
358
|
+
You forgot to provide `APP_CONFIG` in `app.config.ts`:
|
|
334
359
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
360
|
+
```typescript
|
|
361
|
+
providers: [
|
|
362
|
+
{ provide: APP_CONFIG, useValue: environment },
|
|
363
|
+
]
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**`Cannot read properties of undefined (reading 'apiBaseUrl')`**
|
|
367
|
+
|
|
368
|
+
`APP_CONFIG` was provided but the environment object is missing the required field. Check that your environment file implements the full `IAppConfig` interface.
|
|
369
|
+
|
|
370
|
+
**`HTTP 404 on API requests`**
|
|
371
|
+
|
|
372
|
+
Check that `apiBaseUrl` does not have a trailing slash:
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
// ❌ Wrong
|
|
376
|
+
apiBaseUrl: 'http://localhost:2002/'
|
|
377
|
+
|
|
378
|
+
// ✅ Correct
|
|
379
|
+
apiBaseUrl: 'http://localhost:2002'
|
|
380
|
+
```
|
|
338
381
|
|
|
339
382
|
---
|
|
340
383
|
|
|
341
|
-
|
|
384
|
+
## License
|
|
385
|
+
|
|
386
|
+
MIT © FLUSYS
|