@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,348 @@ 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
+ var _a, _b;
250
+ return (Object.assign(Object.assign({}, country_reference_currency), { rate: (_b = (_a = exchangesData.exchanges[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 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 () {
354
+ return [{ type: undefined, decorators: [{
355
+ type: Inject,
356
+ args: ['env']
357
+ }] }, { type: i1.HttpClient }];
358
+ } });
359
+
42
360
  class ApiSecurityService {
43
- constructor(environments, httpClient, cookie) {
361
+ constructor(environments, http, cookie) {
44
362
  this.environments = environments;
45
- this.httpClient = httpClient;
363
+ this.http = http;
46
364
  this.cookie = cookie;
47
365
  }
48
366
  /**
49
- * Retrieves the API security URL.
367
+ * Retrieves the API security URL from the environments configuration.
50
368
  *
51
- * @returns {string} The API security URL.
369
+ * @return {string} The API security URL.
52
370
  */
53
371
  get url() {
54
372
  return this.environments.apiSecurityUrl;
55
373
  }
56
374
  /**
57
- * Logs in the user using the provided login credentials.
375
+ * Authenticates a user with the provided credentials and role.
58
376
  *
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.
63
- *
64
- * @returns {Observable<LoginOut>} - An observable that emits the logged-in user's information.
377
+ * @param {Object} param0 - The login input object.
378
+ * @param {string} param0.username - The username of the user.
379
+ * @param {string} param0.password - The password of the user.
380
+ * @param {string} param0.role - The role of the user.
381
+ * @return {Observable<LoginOut>} An observable emitting the login output object.
65
382
  */
66
383
  login({ username, password, role, }) {
67
- return this.httpClient.post(`${this.url}/auth/login`, {
384
+ return this.http.post(`${this.url}/auth/login`, {
68
385
  system_name: 'CRA',
69
386
  username,
70
387
  password,
@@ -72,29 +389,31 @@ class ApiSecurityService {
72
389
  }).pipe(map(({ data }) => data), tap(({ access_token }) => this.cookie.set('tokenCRA', access_token, { path: '/' })));
73
390
  }
74
391
  /**
75
- * Logs out the user from the application.
392
+ * Logs out the current user by making a POST request to the logout endpoint.
393
+ *
394
+ * This method deletes all cookies after a successful logout.
76
395
  *
77
- * @return {Observable<{}>} An observable that emits an empty object upon successful logout.
396
+ * @return {Observable<{}>} An observable that emits the server's response to the logout request.
78
397
  */
79
398
  logout() {
80
- return this.httpClient.post(`${this.url}/auth/logout`, null)
399
+ return this.http.post(`${this.url}/auth/logout`, null)
81
400
  .pipe(map(({ data }) => data), tap(() => this.cookie.deleteAll('/')));
82
401
  }
83
402
  /**
84
- * Creates a session with the given parameters.
403
+ * Creates a new session for a specified model.
85
404
  *
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.
405
+ * @param {Object} params - The parameters for creating the session.
406
+ * @param {string} params.modelType - The type of the model.
407
+ * @param {string} params.modelId - The ID of the model.
408
+ * @param {string} [params.token] - Optional authorization token.
90
409
  *
91
- * @return {Observable<CreateSessionOut>} - An Observable that emits the result of the session creation.
410
+ * @return {Observable<CreateSessionOut>} An observable containing the created session details.
92
411
  */
93
412
  createSession({ modelType, modelId, token, }) {
94
413
  let headers = new HttpHeaders({});
95
414
  if (token)
96
415
  headers = headers.set('Authorization', `Bearer ${token}`);
97
- return this.httpClient.post(`${this.url}/sessions`, {
416
+ return this.http.post(`${this.url}/sessions`, {
98
417
  model_type: modelType,
99
418
  model_id: modelId,
100
419
  }, {
@@ -102,49 +421,48 @@ class ApiSecurityService {
102
421
  }).pipe(map(({ data }) => data));
103
422
  }
104
423
  /**
105
- * Retrieves user information.
424
+ * Fetches the authenticated user's information.
425
+ * Sends a GET request to the endpoint '/auth/me' to retrieve information
426
+ * about the currently authenticated user.
106
427
  *
107
- * @returns {Observable<MeOut>} Observable of user information.
428
+ * @return {Observable<MeOut>} An observable that emits the authenticated user's data.
108
429
  */
109
430
  me() {
110
- return this.httpClient.get(`${this.url}/auth/me`)
431
+ return this.http.get(`${this.url}/auth/me`)
111
432
  .pipe(map(({ data }) => data));
112
433
  }
113
434
  /**
114
- * Retrieves user information from the API.
435
+ * Fetches the authenticated user's details from the server.
115
436
  *
116
- * @param {GetUserIn} user - The user object containing the user ID.
117
- *
118
- * @returns {Observable<GetUserOut>} - An observable that emits the retrieved user data.
437
+ * @param token The JWT token used for authorization.
438
+ * @return An Observable that emits the user's details encapsulated in a MeOut object.
119
439
  */
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`, {
440
+ otherMe(token) {
441
+ return this.http.get(`${this.url}/auth/me`, {
133
442
  headers: {
134
443
  Authorization: `Bearer ${token}`
135
444
  }
136
445
  }).pipe(map(({ data }) => data));
137
446
  }
138
447
  /**
139
- * Changes the language of the authenticated user.
448
+ * Fetches a user by their unique ID.
140
449
  *
141
- * @param {Object} params - The parameters for changing the language.
142
- * @param {string} params.languageId - The ID of the language to change to.
450
+ * @param {number} id - The unique identifier of the user to be fetched.
451
+ * @return {Observable<GetUserOut>} An observable containing the user information.
452
+ */
453
+ user(id) {
454
+ return this.http.get(`${this.url}/users/${id}`)
455
+ .pipe(map(({ data }) => data));
456
+ }
457
+ /**
458
+ * Changes the language for the authenticated user.
143
459
  *
144
- * @returns {Observable<Object>} - An observable that emits the updated user data.
460
+ * @param {Object} params - The input parameters for changing the language.
461
+ * @param {string} params.languageId - The ID of the new language to be set.
462
+ * @return {Observable<ApiSuccess<MeOut>>} An observable that emits the result of the language change request.
145
463
  */
146
464
  changeLanguage({ languageId }) {
147
- return this.httpClient.put(`${this.url}/auth/me`, {
465
+ return this.http.put(`${this.url}/auth/me`, {
148
466
  language_id: languageId
149
467
  }).pipe(map(({ data }) => data));
150
468
  }
@@ -163,6 +481,38 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
163
481
  }] }, { type: i1.HttpClient }, { type: i2.CookieService }];
164
482
  } });
165
483
 
484
+ class ApiHeadersInterceptor {
485
+ /**
486
+ * Intercepts HTTP requests and adds common headers.
487
+ *
488
+ * @param {HttpRequest<unknown>} request - The HTTP request intercepted.
489
+ * @param {HttpHandler} next - The next handler in the chain.
490
+ *
491
+ * @returns {Observable<HttpEvent<unknown>>} - Observable of the HTTP event after interception.
492
+ */
493
+ intercept(request, next) {
494
+ var _a;
495
+ let headers = new HttpHeaders({
496
+ 'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
497
+ 'expires': '0',
498
+ 'pragma': 'no-cache'
499
+ });
500
+ if (!request.headers.has('Content-Type'))
501
+ headers = headers.set('Content-Type', 'application/json');
502
+ if (!request.headers.has('Accept'))
503
+ headers = headers.set('Accept', 'application/json');
504
+ if (!request.headers.has('Accept-Language'))
505
+ headers = headers.set('Accept-Language', (_a = localStorage.getItem('lang')) !== null && _a !== void 0 ? _a : 'en');
506
+ request = request.clone({ headers });
507
+ return next.handle(request);
508
+ }
509
+ }
510
+ ApiHeadersInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
511
+ ApiHeadersInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor });
512
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, decorators: [{
513
+ type: Injectable
514
+ }] });
515
+
166
516
  class ApiTokenInterceptor {
167
517
  constructor(cookie) {
168
518
  this.cookie = cookie;
@@ -195,81 +545,41 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
195
545
  type: Injectable
196
546
  }], ctorParameters: function () { return [{ type: i2.CookieService }]; } });
197
547
 
198
- class ApiHeadersInterceptor {
199
- /**
200
- * Intercepts HTTP requests and adds common headers.
201
- *
202
- * @param {HttpRequest<unknown>} request - The HTTP request intercepted.
203
- * @param {HttpHandler} next - The next handler in the chain.
204
- *
205
- * @returns {Observable<HttpEvent<unknown>>} - Observable of the HTTP event after interception.
206
- */
207
- intercept(request, next) {
208
- var _a;
209
- let headers = new HttpHeaders({
210
- 'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
211
- 'expires': '0',
212
- 'pragma': 'no-cache'
213
- });
214
- if (!request.headers.has('Content-Type'))
215
- headers = headers.set('Content-Type', 'application/json');
216
- if (!request.headers.has('Accept'))
217
- headers = headers.set('Accept', 'application/json');
218
- if (!request.headers.has('Accept-Language'))
219
- headers = headers.set('Accept-Language', (_a = localStorage.getItem('lang')) !== null && _a !== void 0 ? _a : 'en');
220
- request = request.clone({ headers });
221
- return next.handle(request);
548
+ const DEFAULT_TTL = 10000; // ttl in ms
549
+ class HttpCachingInterceptor {
550
+ constructor(envs) {
551
+ this.envs = envs;
552
+ this.cache = new Map();
553
+ }
554
+ intercept(req, next) {
555
+ if (req.method !== 'GET')
556
+ return next.handle(req);
557
+ const cached = this.cache.get(req.urlWithParams);
558
+ if (cached) {
559
+ const isExpired = Date.now() > cached.ttl;
560
+ if (!isExpired)
561
+ return of(cached.res);
562
+ this.cache.delete(req.urlWithParams); // If expired, remove the entry from cache
563
+ }
564
+ return next.handle(req).pipe(tap$1((res) => {
565
+ var _a;
566
+ if (!(res instanceof HttpResponse))
567
+ return;
568
+ const ttl = Date.now() + ((_a = this.envs.cacheTtl) !== null && _a !== void 0 ? _a : DEFAULT_TTL);
569
+ this.cache.set(req.urlWithParams, { res, ttl });
570
+ }));
222
571
  }
223
572
  }
224
- ApiHeadersInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
225
- ApiHeadersInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor });
226
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiHeadersInterceptor, decorators: [{
573
+ HttpCachingInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, deps: [{ token: 'env' }], target: i0.ɵɵFactoryTarget.Injectable });
574
+ HttpCachingInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor });
575
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, decorators: [{
227
576
  type: Injectable
228
- }] });
229
-
230
- /**
231
- * Convert an object of key-value pairs into a URL query string.
232
- *
233
- * @param {Object} params - The key-value pairs to converted into a query string.
234
- *
235
- * @return {string} - The generated query string.
236
- */
237
- const queryString = (params) => {
238
- const query = Object.keys(params)
239
- .map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
240
- .join('&');
241
- return query.length ? `?${query}` : '';
242
- };
243
- /**
244
- * Returns the headers for generating PDF files.
245
- *
246
- * @param {string} format - The format of the headers, 'object' or 'http_header'.
247
- *
248
- * @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating PDF files.
249
- */
250
- const pdfHeaders = (format = 'object') => {
251
- const headers = {
252
- 'Accept': 'application/pdf'
253
- };
254
- return format === 'object'
255
- ? headers
256
- : new HttpHeaders(headers);
257
- };
258
- /**
259
- * Returns the headers for generating XML files.
260
- *
261
- * @param {string} format - The format of the headers, 'object' or 'http_header'.
262
- *
263
- * @returns {HttpHeaders | { [header: string]: string | string[] }} - The headers for generating XML files.
264
- */
265
- const xmlHeaders = (format = 'object') => {
266
- const headers = {
267
- 'Accept': 'application/xml',
268
- };
269
- return format === 'object'
270
- ? headers
271
- : new HttpHeaders(headers);
272
- };
577
+ }], ctorParameters: function () {
578
+ return [{ type: undefined, decorators: [{
579
+ type: Inject,
580
+ args: ['env']
581
+ }] }];
582
+ } });
273
583
 
274
584
  /*
275
585
  * Public API Surface of ngx-services
@@ -279,5 +589,5 @@ const xmlHeaders = (format = 'object') => {
279
589
  * Generated bundle index. Do not edit.
280
590
  */
281
591
 
282
- export { ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, NgxServicesModule, pdfHeaders, queryString, xmlHeaders };
592
+ export { ApiCompaniesService, ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, HttpCachingInterceptor, NgxServicesModule, httpParams, pdfHeaders, queryString, xmlHeaders };
283
593
  //# sourceMappingURL=experteam-mx-ngx-services.mjs.map