@experteam-mx/ngx-services 0.1.1 → 15.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.
Files changed (36) hide show
  1. package/esm2020/lib/apis/api-catalog.models.mjs +1 -1
  2. package/esm2020/lib/apis/api-companies.service.mjs +255 -0
  3. package/esm2020/lib/apis/api-security.service.mjs +48 -48
  4. package/esm2020/lib/apis/models/api-companies.interfaces.mjs +2 -0
  5. package/esm2020/lib/apis/models/api-companies.types.mjs +2 -0
  6. package/esm2020/lib/apis/models/api-security.interfaces.mjs +2 -0
  7. package/esm2020/lib/apis/models/api-security.types.mjs +2 -0
  8. package/esm2020/lib/apis/models/api.models.mjs +2 -0
  9. package/esm2020/lib/helpers/http.mjs +27 -6
  10. package/esm2020/lib/interceptors/http-caching.interceptor.mjs +38 -0
  11. package/esm2020/lib/ngx-services.models.mjs +1 -1
  12. package/esm2020/public-api.mjs +10 -3
  13. package/fesm2015/experteam-mx-ngx-services.mjs +432 -122
  14. package/fesm2015/experteam-mx-ngx-services.mjs.map +1 -1
  15. package/fesm2020/experteam-mx-ngx-services.mjs +426 -121
  16. package/fesm2020/experteam-mx-ngx-services.mjs.map +1 -1
  17. package/lib/apis/api-catalog.models.d.ts +67 -1
  18. package/lib/apis/api-companies.service.d.ts +163 -0
  19. package/lib/apis/api-security.service.d.ts +37 -37
  20. package/lib/apis/models/api-companies.interfaces.d.ts +380 -0
  21. package/lib/apis/models/api-companies.types.d.ts +75 -0
  22. package/lib/apis/{api-security.models.d.ts → models/api-security.interfaces.d.ts} +3 -38
  23. package/lib/apis/models/api-security.types.d.ts +30 -0
  24. package/lib/apis/{api.models.d.ts → models/api.models.d.ts} +3 -11
  25. package/lib/helpers/http.d.ts +11 -4
  26. package/lib/interceptors/http-caching.interceptor.d.ts +12 -0
  27. package/lib/ngx-services.models.d.ts +1 -0
  28. package/package.json +3 -2
  29. package/public-api.d.ts +8 -2
  30. package/esm2020/experteam-ngx-services.mjs +0 -5
  31. package/esm2020/lib/apis/api-security.models.mjs +0 -2
  32. package/esm2020/lib/apis/api.models.mjs +0 -2
  33. package/fesm2015/experteam-ngx-services.mjs +0 -283
  34. package/fesm2015/experteam-ngx-services.mjs.map +0 -1
  35. package/fesm2020/experteam-ngx-services.mjs +0 -280
  36. package/fesm2020/experteam-ngx-services.mjs.map +0 -1
@@ -1,9 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { NgModule, Injectable, Inject } from '@angular/core';
3
3
  import * as i1 from '@angular/common/http';
4
- import { HttpClientModule, HttpHeaders } from '@angular/common/http';
5
- import { map, tap } from 'rxjs';
4
+ import { HttpClientModule, HttpParams, HttpHeaders, HttpResponse } from '@angular/common/http';
5
+ import { map, mergeMap, forkJoin, tap, of } from 'rxjs';
6
6
  import * as i2 from 'ngx-cookie-service';
7
+ import { tap as tap$1 } from 'rxjs/operators';
7
8
 
8
9
  class NgxServicesModule {
9
10
  /**
@@ -39,32 +40,346 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
39
40
  }]
40
41
  }] });
41
42
 
43
+ /**
44
+ * Convert an object of key-value pairs into a URL query string.
45
+ *
46
+ * @param {Object} params - The key-value pairs to converted into a query string.
47
+ *
48
+ * @return {string} - The generated query string.
49
+ */
50
+ const queryString = (params) => {
51
+ let queryElements = [];
52
+ Object.entries(params).forEach(([key, value]) => {
53
+ if (Array.isArray(value)) {
54
+ const arrayQuery = value
55
+ .map((item) => `${encodeURIComponent(key)}=${encodeURIComponent(item)}`)
56
+ .join('&');
57
+ queryElements.push(arrayQuery);
58
+ }
59
+ else {
60
+ const encodedQuery = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
61
+ queryElements.push(encodedQuery);
62
+ }
63
+ });
64
+ const queryString = queryElements.join('&');
65
+ return queryString.length ? `?${queryString}` : '';
66
+ };
67
+ /**
68
+ * Creates an instance of HttpParams using the provided params object.
69
+ *
70
+ * @param {Object} params - The object containing the params to the HttpParams constructor.
71
+ *
72
+ * @returns {HttpParams} - An instance of HttpParams created from the params object.
73
+ */
74
+ const httpParams = (params) => new HttpParams({
75
+ fromObject: params
76
+ });
77
+ /**
78
+ * Returns the headers for generating PDF files.
79
+ *
80
+ * @param {string} format - The format of the headers, 'object' or 'http_header'.
81
+ *
82
+ * @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating PDF files.
83
+ */
84
+ const pdfHeaders = (format = 'object') => {
85
+ const headers = {
86
+ 'Accept': 'application/pdf'
87
+ };
88
+ return format === 'object'
89
+ ? headers
90
+ : new HttpHeaders(headers);
91
+ };
92
+ /**
93
+ * Returns the headers for generating XML files.
94
+ *
95
+ * @param {string} format - The format of the headers, 'object' or 'http_header'.
96
+ *
97
+ * @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating XML files.
98
+ */
99
+ const xmlHeaders = (format = 'object') => {
100
+ const headers = {
101
+ 'Accept': 'application/xml',
102
+ };
103
+ return format === 'object'
104
+ ? headers
105
+ : new HttpHeaders(headers);
106
+ };
107
+
108
+ class ApiCompaniesService {
109
+ constructor(environments, http) {
110
+ this.environments = environments;
111
+ this.http = http;
112
+ }
113
+ /**
114
+ * Retrieves the URL for the companies API from the environment configurations.
115
+ *
116
+ * @return {string} The URL of the companies API.
117
+ */
118
+ get url() {
119
+ return this.environments.apiCompaniesUrl;
120
+ }
121
+ /**
122
+ * Fetches the installations based on the provided query parameters.
123
+ *
124
+ * @param {QueryParams} params - The parameters used to filter the installations query.
125
+ * @return {Observable<InstallationsData>} An observable that emits the installations data.
126
+ */
127
+ getInstallations(params) {
128
+ return this.http.get(`${this.url}/installations`, {
129
+ params: httpParams(params),
130
+ }).pipe(map(({ data }) => data));
131
+ }
132
+ /**
133
+ * Retrieves the installation details based on the given installation ID.
134
+ *
135
+ * @param {number} id - The unique identifier of the installation to retrieve.
136
+ * @returns {Observable<InstallationData>} An observable of the installation details.
137
+ */
138
+ getInstallation(id) {
139
+ return this.http.get(`${this.url}/installations/${id}`)
140
+ .pipe(map(({ data }) => data));
141
+ }
142
+ /**
143
+ * Retrieves a list of locations based on the provided query parameters.
144
+ *
145
+ * @param {QueryParams} params - The parameters to use for querying locations.
146
+ * @return {Observable<LocationsData>} An observable that emits the locations data.
147
+ */
148
+ getLocations(params) {
149
+ return this.http.get(`${this.url}/locations`, {
150
+ params: httpParams(params),
151
+ }).pipe(map(({ data }) => data));
152
+ }
153
+ /**
154
+ * Fetches the location details for a given location ID.
155
+ *
156
+ * @param {number} id - The unique identifier of the location.
157
+ * @return {Observable<LocationData>} An Observable containing the location details.
158
+ */
159
+ getLocation(id) {
160
+ return this.http.get(`${this.url}/locations/${id}`)
161
+ .pipe(map(({ data }) => data));
162
+ }
163
+ /**
164
+ * Retrieves a list of active supply entities.
165
+ *
166
+ * @param {QueryParams} params - The query parameters to filter supply entities.
167
+ * @return {Observable<SupplyEntitiesData>} Observable emitting supply entities data.
168
+ */
169
+ getSupplyEntitiesActive(params) {
170
+ return this.http.get(`${this.url}/supply-entities/actives`, {
171
+ params: httpParams(params),
172
+ }).pipe(map(({ data }) => data));
173
+ }
174
+ /**
175
+ * Fetches a list of employees based on the specified query parameters.
176
+ *
177
+ * @param {QueryParams} params - The parameters to filter and sort the employees.
178
+ * @return {Observable<EmployeesData>} An observable that emits the list of employees.
179
+ */
180
+ getEmployees(params) {
181
+ return this.http.get(`${this.url}/employees`, {
182
+ params: httpParams(params),
183
+ }).pipe(map(({ data }) => data));
184
+ }
185
+ /**
186
+ * Fetches an employee's details based on the provided employee ID.
187
+ *
188
+ * @param {number} id - The unique identifier of the employee.
189
+ * @return {Observable<EmployeeData>} An observable that emits the employee's details.
190
+ */
191
+ getEmployee(id) {
192
+ return this.http.get(`${this.url}/employees/${id}`)
193
+ .pipe(map(({ data }) => data));
194
+ }
195
+ /**
196
+ * Retrieves the list of employees for a specified location based on provided query parameters.
197
+ *
198
+ * @param {QueryParams} params - The query parameters used to filter and retrieve the location employees.
199
+ * @returns {Observable<LocationEmployeesData>} An observable that emits the list of employees for the specified location.
200
+ */
201
+ getLocationEmployees(params) {
202
+ return this.http.get(`${this.url}/location-employees`, {
203
+ params: httpParams(params),
204
+ }).pipe(map(({ data }) => data));
205
+ }
206
+ /**
207
+ * Retrieves a list of countries where the company operates.
208
+ *
209
+ * @param {QueryParams} params - The query parameters for the API request.
210
+ * @return {Observable<CompanyCountriesData>} An observable containing the list of company countries.
211
+ */
212
+ getCompanyCountries(params) {
213
+ return this.http.get(`${this.url}/company-countries`, {
214
+ params: httpParams(params),
215
+ }).pipe(map(({ data }) => data));
216
+ }
217
+ /**
218
+ * Retrieves the country information for a specified company by its ID.
219
+ *
220
+ * @param {number} id - The unique identifier of the company.
221
+ * @return {Observable<CompanyCountryData>} An observable containing the country information of the company.
222
+ */
223
+ getCompanyCountry(id) {
224
+ return this.http.get(`${this.url}/company-countries/${id}`)
225
+ .pipe(map(({ data }) => data));
226
+ }
227
+ /**
228
+ * Fetches the reference currencies for a given country.
229
+ *
230
+ * @param {QueryParams} params - The query parameters to include in the request.
231
+ * @return {Observable<CountryReferenceCurrenciesData>} The observable containing the country reference currencies data.
232
+ */
233
+ getCountryReferenceCurrencies(params) {
234
+ return this.http.get(`${this.url}/country-reference-currencies`, { params }).pipe(map(({ data }) => data));
235
+ }
236
+ /**
237
+ * Retrieves a list of currencies for different countries along with their current exchange rates.
238
+ *
239
+ * @param {QueryParams} params - The query parameters used to fetch the country reference currencies.
240
+ * @return {Observable<CountryCurrencyRate[]>} An observable that emits an array of country currency rates.
241
+ */
242
+ getCountryCurrenciesWithRate(params) {
243
+ return this.getCountryReferenceCurrencies(params)
244
+ .pipe(mergeMap((currenciesData) => {
245
+ const $observables = currenciesData.country_reference_currencies
246
+ .map((country_reference_currency) => this.getCurrentExchanges({
247
+ currency_id: country_reference_currency.currency.id,
248
+ }).pipe(map((exchangesData) => ({
249
+ ...country_reference_currency,
250
+ rate: exchangesData.exchanges[0]?.value ?? 1.00,
251
+ }))));
252
+ return forkJoin($observables);
253
+ }));
254
+ }
255
+ /**
256
+ * Retrieves the current exchanges based on the given query parameters.
257
+ *
258
+ * @param {QueryParams} params - The query parameters to filter the exchanges.
259
+ *
260
+ * @returns {Observable<ExchangesData>} - An observable that emits the API response data containing the current exchanges.
261
+ */
262
+ getCurrentExchanges(params) {
263
+ return this.http.get(`${this.url}/exchanges/current`, {
264
+ params: httpParams(params),
265
+ }).pipe(map(({ data }) => data));
266
+ }
267
+ /**
268
+ * Fetches the country-specific tax information for a company.
269
+ *
270
+ * @param {QueryParams} params - The parameters used to filter and query the taxes.
271
+ * @return {Observable<CompanyCountryTaxesData>} An observable that emits the tax information.
272
+ */
273
+ getCompanyCountryTaxes(params) {
274
+ return this.http.get(`${this.url}/company-country-taxes`, {
275
+ params: httpParams(params),
276
+ }).pipe(map(({ data }) => data));
277
+ }
278
+ /**
279
+ * Retrieves the list of active account entities based on the provided query parameters.
280
+ *
281
+ * @param {QueryParams} params - The parameters to filter and query active account entities.
282
+ * @return {Observable<AccountEntitiesData>} An observable that emits the list of active account entities.
283
+ */
284
+ getActiveAccountEntities(params) {
285
+ return this.http.get(`${this.url}/account-entities/actives`, {
286
+ params: httpParams(params),
287
+ }).pipe(map(({ data }) => data));
288
+ }
289
+ /**
290
+ * Retrieves the parameter values based on the provided parameter names.
291
+ *
292
+ * @param {Object} params - An object containing the required parameters.
293
+ * @param {string[]} params.paramNames - An array of parameter names for which the values need to be fetched.
294
+ * @return {Observable<ParametersData>} An observable that emits the fetched parameter values.
295
+ */
296
+ getParameters({ paramNames, }) {
297
+ const parameters = paramNames.map((p) => ({ name: p }));
298
+ return this.http.post(`${this.url}/parameters-values`, {
299
+ parameters
300
+ }).pipe(map(({ data }) => data));
301
+ }
302
+ /**
303
+ * Retrieves the value of a specified parameter.
304
+ *
305
+ * @param {Object} input - The input object containing the parameter details.
306
+ * @param {string} input.paramName - The name of the parameter whose value is to be retrieved.
307
+ * @return {Observable<ParameterValueData>} An observable emitting the value of the specified parameter.
308
+ */
309
+ getParameterValue({ paramName, }) {
310
+ return this.http.get(`${this.url}/parameters-values/${paramName}`)
311
+ .pipe(map(({ data }) => data));
312
+ }
313
+ /**
314
+ * Retrieves a list of country references based on the given query parameters.
315
+ *
316
+ * @param {QueryParams} params - The query parameters for retrieving country references.
317
+ * @return {Observable<CountryReferencesData>} An observable containing the country reference data.
318
+ */
319
+ getCountryReferences(params) {
320
+ return this.http.get(`${this.url}/country-references`, {
321
+ params: httpParams(params),
322
+ }).pipe(map(({ data }) => data));
323
+ }
324
+ /**
325
+ * Fetches the country reference data for a given country ID.
326
+ *
327
+ * @param {number} id - The unique identifier of the country for which the reference data is to be retrieved.
328
+ * @return {Observable<CountryReferenceData>} An observable containing the country reference data.
329
+ */
330
+ getCountryReference(id) {
331
+ return this.http.get(`${this.url}/country-references/${id}`)
332
+ .pipe(map(({ data }) => data));
333
+ }
334
+ /**
335
+ * Fetches the list of workflows based on the provided query parameters.
336
+ *
337
+ * @param {QueryParams} params - The query parameters used to filter workflows.
338
+ * @return {Observable<WorkflowsData>} An observable containing the workflow data.
339
+ */
340
+ getWorkflows(params) {
341
+ return this.http.get(`${this.url}/workflows`, {
342
+ params: httpParams(params),
343
+ }).pipe(map(({ data }) => data));
344
+ }
345
+ }
346
+ ApiCompaniesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiCompaniesService, deps: [{ token: 'env' }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
347
+ ApiCompaniesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiCompaniesService, providedIn: 'root' });
348
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiCompaniesService, decorators: [{
349
+ type: Injectable,
350
+ args: [{
351
+ providedIn: 'root'
352
+ }]
353
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
354
+ type: Inject,
355
+ args: ['env']
356
+ }] }, { type: i1.HttpClient }]; } });
357
+
42
358
  class ApiSecurityService {
43
- constructor(environments, httpClient, cookie) {
359
+ constructor(environments, http, cookie) {
44
360
  this.environments = environments;
45
- this.httpClient = httpClient;
361
+ this.http = http;
46
362
  this.cookie = cookie;
47
363
  }
48
364
  /**
49
- * Retrieves the API security URL.
365
+ * Retrieves the API security URL from the environments configuration.
50
366
  *
51
- * @returns {string} The API security URL.
367
+ * @return {string} The API security URL.
52
368
  */
53
369
  get url() {
54
370
  return this.environments.apiSecurityUrl;
55
371
  }
56
372
  /**
57
- * Logs in the user using the provided login credentials.
58
- *
59
- * @param {object} loginParams - The login parameters.
60
- * @param {string} loginParams.username - The username of the user.
61
- * @param {string} loginParams.password - The password of the user.
62
- * @param {string} loginParams.role - The role of the user.
373
+ * Authenticates a user with the provided credentials and role.
63
374
  *
64
- * @returns {Observable<LoginOut>} - An observable that emits the logged-in user's information.
375
+ * @param {Object} param0 - The login input object.
376
+ * @param {string} param0.username - The username of the user.
377
+ * @param {string} param0.password - The password of the user.
378
+ * @param {string} param0.role - The role of the user.
379
+ * @return {Observable<LoginOut>} An observable emitting the login output object.
65
380
  */
66
381
  login({ username, password, role, }) {
67
- return this.httpClient.post(`${this.url}/auth/login`, {
382
+ return this.http.post(`${this.url}/auth/login`, {
68
383
  system_name: 'CRA',
69
384
  username,
70
385
  password,
@@ -72,29 +387,31 @@ class ApiSecurityService {
72
387
  }).pipe(map(({ data }) => data), tap(({ access_token }) => this.cookie.set('tokenCRA', access_token, { path: '/' })));
73
388
  }
74
389
  /**
75
- * Logs out the user from the application.
390
+ * Logs out the current user by making a POST request to the logout endpoint.
76
391
  *
77
- * @return {Observable<{}>} An observable that emits an empty object upon successful logout.
392
+ * This method deletes all cookies after a successful logout.
393
+ *
394
+ * @return {Observable<{}>} An observable that emits the server's response to the logout request.
78
395
  */
79
396
  logout() {
80
- return this.httpClient.post(`${this.url}/auth/logout`, null)
397
+ return this.http.post(`${this.url}/auth/logout`, null)
81
398
  .pipe(map(({ data }) => data), tap(() => this.cookie.deleteAll('/')));
82
399
  }
83
400
  /**
84
- * Creates a session with the given parameters.
401
+ * Creates a new session for a specified model.
85
402
  *
86
- * @param {CreateSessionIn} options - The input parameters for session creation.
87
- * @param {string} options.modelType - The session model type.
88
- * @param {string} options.modelId - The session model ID.
89
- * @param {string} options.token - The authorization token. Optional.
403
+ * @param {Object} params - The parameters for creating the session.
404
+ * @param {string} params.modelType - The type of the model.
405
+ * @param {string} params.modelId - The ID of the model.
406
+ * @param {string} [params.token] - Optional authorization token.
90
407
  *
91
- * @return {Observable<CreateSessionOut>} - An Observable that emits the result of the session creation.
408
+ * @return {Observable<CreateSessionOut>} An observable containing the created session details.
92
409
  */
93
410
  createSession({ modelType, modelId, token, }) {
94
411
  let headers = new HttpHeaders({});
95
412
  if (token)
96
413
  headers = headers.set('Authorization', `Bearer ${token}`);
97
- return this.httpClient.post(`${this.url}/sessions`, {
414
+ return this.http.post(`${this.url}/sessions`, {
98
415
  model_type: modelType,
99
416
  model_id: modelId,
100
417
  }, {
@@ -102,49 +419,48 @@ class ApiSecurityService {
102
419
  }).pipe(map(({ data }) => data));
103
420
  }
104
421
  /**
105
- * Retrieves user information.
422
+ * Fetches the authenticated user's information.
423
+ * Sends a GET request to the endpoint '/auth/me' to retrieve information
424
+ * about the currently authenticated user.
106
425
  *
107
- * @returns {Observable<MeOut>} Observable of user information.
426
+ * @return {Observable<MeOut>} An observable that emits the authenticated user's data.
108
427
  */
109
428
  me() {
110
- return this.httpClient.get(`${this.url}/auth/me`)
429
+ return this.http.get(`${this.url}/auth/me`)
111
430
  .pipe(map(({ data }) => data));
112
431
  }
113
432
  /**
114
- * Retrieves user information from the API.
115
- *
116
- * @param {GetUserIn} user - The user object containing the user ID.
433
+ * Fetches the authenticated user's details from the server.
117
434
  *
118
- * @returns {Observable<GetUserOut>} - An observable that emits the retrieved user data.
435
+ * @param token The JWT token used for authorization.
436
+ * @return An Observable that emits the user's details encapsulated in a MeOut object.
119
437
  */
120
- user({ userId }) {
121
- return this.httpClient.get(`${this.url}/users/${userId}`)
122
- .pipe(map(({ data }) => data));
123
- }
124
- /**
125
- * Get user information
126
- *
127
- * @param {string} token - The user's authentication token
128
- *
129
- * @return {Observable<MeOut>} - An observable that emits the user's information
130
- */
131
- userInfo({ token }) {
132
- return this.httpClient.get(`${this.url}/auth/me`, {
438
+ otherMe(token) {
439
+ return this.http.get(`${this.url}/auth/me`, {
133
440
  headers: {
134
441
  Authorization: `Bearer ${token}`
135
442
  }
136
443
  }).pipe(map(({ data }) => data));
137
444
  }
138
445
  /**
139
- * Changes the language of the authenticated user.
446
+ * Fetches a user by their unique ID.
140
447
  *
141
- * @param {Object} params - The parameters for changing the language.
142
- * @param {string} params.languageId - The ID of the language to change to.
448
+ * @param {number} id - The unique identifier of the user to be fetched.
449
+ * @return {Observable<GetUserOut>} An observable containing the user information.
450
+ */
451
+ user(id) {
452
+ return this.http.get(`${this.url}/users/${id}`)
453
+ .pipe(map(({ data }) => data));
454
+ }
455
+ /**
456
+ * Changes the language for the authenticated user.
143
457
  *
144
- * @returns {Observable<Object>} - An observable that emits the updated user data.
458
+ * @param {Object} params - The input parameters for changing the language.
459
+ * @param {string} params.languageId - The ID of the new language to be set.
460
+ * @return {Observable<ApiSuccess<MeOut>>} An observable that emits the result of the language change request.
145
461
  */
146
462
  changeLanguage({ languageId }) {
147
- return this.httpClient.put(`${this.url}/auth/me`, {
463
+ return this.http.put(`${this.url}/auth/me`, {
148
464
  language_id: languageId
149
465
  }).pipe(map(({ data }) => data));
150
466
  }
@@ -161,6 +477,37 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
161
477
  args: ['env']
162
478
  }] }, { type: i1.HttpClient }, { type: i2.CookieService }]; } });
163
479
 
480
+ class ApiHeadersInterceptor {
481
+ /**
482
+ * Intercepts HTTP requests and adds common headers.
483
+ *
484
+ * @param {HttpRequest<unknown>} request - The HTTP request intercepted.
485
+ * @param {HttpHandler} next - The next handler in the chain.
486
+ *
487
+ * @returns {Observable<HttpEvent<unknown>>} - Observable of the HTTP event after interception.
488
+ */
489
+ intercept(request, next) {
490
+ let headers = new HttpHeaders({
491
+ 'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
492
+ 'expires': '0',
493
+ 'pragma': 'no-cache'
494
+ });
495
+ if (!request.headers.has('Content-Type'))
496
+ headers = headers.set('Content-Type', 'application/json');
497
+ if (!request.headers.has('Accept'))
498
+ headers = headers.set('Accept', 'application/json');
499
+ if (!request.headers.has('Accept-Language'))
500
+ headers = headers.set('Accept-Language', localStorage.getItem('lang') ?? 'en');
501
+ request = request.clone({ headers });
502
+ return next.handle(request);
503
+ }
504
+ }
505
+ ApiHeadersInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
506
+ ApiHeadersInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor });
507
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, decorators: [{
508
+ type: Injectable
509
+ }] });
510
+
164
511
  class ApiTokenInterceptor {
165
512
  constructor(cookie) {
166
513
  this.cookie = cookie;
@@ -193,80 +540,38 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
193
540
  type: Injectable
194
541
  }], ctorParameters: function () { return [{ type: i2.CookieService }]; } });
195
542
 
196
- class ApiHeadersInterceptor {
197
- /**
198
- * Intercepts HTTP requests and adds common headers.
199
- *
200
- * @param {HttpRequest<unknown>} request - The HTTP request intercepted.
201
- * @param {HttpHandler} next - The next handler in the chain.
202
- *
203
- * @returns {Observable<HttpEvent<unknown>>} - Observable of the HTTP event after interception.
204
- */
205
- intercept(request, next) {
206
- let headers = new HttpHeaders({
207
- 'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
208
- 'expires': '0',
209
- 'pragma': 'no-cache'
210
- });
211
- if (!request.headers.has('Content-Type'))
212
- headers = headers.set('Content-Type', 'application/json');
213
- if (!request.headers.has('Accept'))
214
- headers = headers.set('Accept', 'application/json');
215
- if (!request.headers.has('Accept-Language'))
216
- headers = headers.set('Accept-Language', localStorage.getItem('lang') ?? 'en');
217
- request = request.clone({ headers });
218
- return next.handle(request);
543
+ const DEFAULT_TTL = 10000; // ttl in ms
544
+ class HttpCachingInterceptor {
545
+ constructor(envs) {
546
+ this.envs = envs;
547
+ this.cache = new Map();
548
+ }
549
+ intercept(req, next) {
550
+ if (req.method !== 'GET')
551
+ return next.handle(req);
552
+ const cached = this.cache.get(req.urlWithParams);
553
+ if (cached) {
554
+ const isExpired = Date.now() > cached.ttl;
555
+ if (!isExpired)
556
+ return of(cached.res);
557
+ this.cache.delete(req.urlWithParams); // If expired, remove the entry from cache
558
+ }
559
+ return next.handle(req).pipe(tap$1((res) => {
560
+ if (!(res instanceof HttpResponse))
561
+ return;
562
+ const ttl = Date.now() + (this.envs.cacheTtl ?? DEFAULT_TTL);
563
+ this.cache.set(req.urlWithParams, { res, ttl });
564
+ }));
219
565
  }
220
566
  }
221
- ApiHeadersInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
222
- ApiHeadersInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor });
223
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, decorators: [{
567
+ HttpCachingInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, deps: [{ token: 'env' }], target: i0.ɵɵFactoryTarget.Injectable });
568
+ HttpCachingInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor });
569
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, decorators: [{
224
570
  type: Injectable
225
- }] });
226
-
227
- /**
228
- * Convert an object of key-value pairs into a URL query string.
229
- *
230
- * @param {Object} params - The key-value pairs to converted into a query string.
231
- *
232
- * @return {string} - The generated query string.
233
- */
234
- const queryString = (params) => {
235
- const query = Object.keys(params)
236
- .map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
237
- .join('&');
238
- return query.length ? `?${query}` : '';
239
- };
240
- /**
241
- * Returns the headers for generating PDF files.
242
- *
243
- * @param {string} format - The format of the headers, 'object' or 'http_header'.
244
- *
245
- * @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating PDF files.
246
- */
247
- const pdfHeaders = (format = 'object') => {
248
- const headers = {
249
- 'Accept': 'application/pdf'
250
- };
251
- return format === 'object'
252
- ? headers
253
- : new HttpHeaders(headers);
254
- };
255
- /**
256
- * Returns the headers for generating XML files.
257
- *
258
- * @param {string} format - The format of the headers, 'object' or 'http_header'.
259
- *
260
- * @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating XML files.
261
- */
262
- const xmlHeaders = (format = 'object') => {
263
- const headers = {
264
- 'Accept': 'application/xml',
265
- };
266
- return format === 'object'
267
- ? headers
268
- : new HttpHeaders(headers);
269
- };
571
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
572
+ type: Inject,
573
+ args: ['env']
574
+ }] }]; } });
270
575
 
271
576
  /*
272
577
  * Public API Surface of ngx-services
@@ -276,5 +581,5 @@ const xmlHeaders = (format = 'object') => {
276
581
  * Generated bundle index. Do not edit.
277
582
  */
278
583
 
279
- export { ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, NgxServicesModule, pdfHeaders, queryString, xmlHeaders };
584
+ export { ApiCompaniesService, ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, HttpCachingInterceptor, NgxServicesModule, httpParams, pdfHeaders, queryString, xmlHeaders };
280
585
  //# sourceMappingURL=experteam-mx-ngx-services.mjs.map