@experteam-mx/ngx-services 0.1.1 → 15.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.
Files changed (40) hide show
  1. package/esm2020/lib/apis/api-companies.service.mjs +255 -0
  2. package/esm2020/lib/apis/api-security.service.mjs +53 -53
  3. package/esm2020/lib/apis/models/api-catalog.interfaces.mjs +2 -0
  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/api-token.interceptor.mjs +10 -6
  11. package/esm2020/lib/interceptors/http-caching.interceptor.mjs +38 -0
  12. package/esm2020/lib/ngx-services.models.mjs +1 -1
  13. package/esm2020/public-api.mjs +10 -3
  14. package/fesm2015/experteam-mx-ngx-services.mjs +445 -129
  15. package/fesm2015/experteam-mx-ngx-services.mjs.map +1 -1
  16. package/fesm2020/experteam-mx-ngx-services.mjs +438 -129
  17. package/fesm2020/experteam-mx-ngx-services.mjs.map +1 -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-catalog.interfaces.d.ts +71 -0
  21. package/lib/apis/models/api-companies.interfaces.d.ts +380 -0
  22. package/lib/apis/models/api-companies.types.d.ts +75 -0
  23. package/lib/apis/{api-security.models.d.ts → models/api-security.interfaces.d.ts} +3 -38
  24. package/lib/apis/models/api-security.types.d.ts +30 -0
  25. package/lib/apis/{api.models.d.ts → models/api.models.d.ts} +3 -11
  26. package/lib/helpers/http.d.ts +11 -4
  27. package/lib/interceptors/api-token.interceptor.d.ts +3 -1
  28. package/lib/interceptors/http-caching.interceptor.d.ts +12 -0
  29. package/lib/ngx-services.models.d.ts +2 -0
  30. package/package.json +3 -2
  31. package/public-api.d.ts +8 -2
  32. package/esm2020/experteam-ngx-services.mjs +0 -5
  33. package/esm2020/lib/apis/api-catalog.models.mjs +0 -2
  34. package/esm2020/lib/apis/api-security.models.mjs +0 -2
  35. package/esm2020/lib/apis/api.models.mjs +0 -2
  36. package/fesm2015/experteam-ngx-services.mjs +0 -283
  37. package/fesm2015/experteam-ngx-services.mjs.map +0 -1
  38. package/fesm2020/experteam-ngx-services.mjs +0 -280
  39. package/fesm2020/experteam-ngx-services.mjs.map +0 -1
  40. package/lib/apis/api-catalog.models.d.ts +0 -5
@@ -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';
6
- import * as i2 from 'ngx-cookie-service';
4
+ import { HttpClientModule, HttpParams, HttpHeaders, HttpResponse } from '@angular/common/http';
5
+ import { map, mergeMap, forkJoin, tap, of } from 'rxjs';
6
+ import * as i1$1 from 'ngx-cookie-service';
7
+ import { tap as tap$1 } from 'rxjs/operators';
7
8
 
8
9
  class NgxServicesModule {
9
10
  /**
@@ -39,62 +40,380 @@ 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, cookie, http) {
44
362
  this.environments = environments;
45
- this.httpClient = httpClient;
46
363
  this.cookie = cookie;
364
+ this.http = http;
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.
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.
375
+ * Authenticates a user with the provided credentials and role.
63
376
  *
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,
71
388
  role,
72
- }).pipe(map(({ data }) => data), tap(({ access_token }) => this.cookie.set('tokenCRA', access_token, { path: '/' })));
389
+ }).pipe(map(({ data }) => data), tap(({ access_token }) => this.cookie.set(this.environments.tokenName, 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,54 +421,53 @@ 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`)
111
- .pipe(map(({ data }) => data));
112
- }
113
- /**
114
- * Retrieves user information from the API.
115
- *
116
- * @param {GetUserIn} user - The user object containing the user ID.
117
- *
118
- * @returns {Observable<GetUserOut>} - An observable that emits the retrieved user data.
119
- */
120
- user({ userId }) {
121
- return this.httpClient.get(`${this.url}/users/${userId}`)
431
+ return this.http.get(`${this.url}/auth/me`)
122
432
  .pipe(map(({ data }) => data));
123
433
  }
124
434
  /**
125
- * Get user information
435
+ * Fetches the authenticated user's details from the server.
126
436
  *
127
- * @param {string} token - The user's authentication token
128
- *
129
- * @return {Observable<MeOut>} - An observable that emits the user's information
437
+ * @param token The JWT token used for authorization.
438
+ * @return An Observable that emits the user's details encapsulated in a MeOut object.
130
439
  */
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
  }
151
469
  }
152
- ApiSecurityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, deps: [{ token: 'env' }, { token: i1.HttpClient }, { token: i2.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
470
+ ApiSecurityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, deps: [{ token: 'env' }, { token: i1$1.CookieService }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
153
471
  ApiSecurityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, providedIn: 'root' });
154
472
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiSecurityService, decorators: [{
155
473
  type: Injectable,
@@ -160,41 +478,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
160
478
  return [{ type: undefined, decorators: [{
161
479
  type: Inject,
162
480
  args: ['env']
163
- }] }, { type: i1.HttpClient }, { type: i2.CookieService }];
481
+ }] }, { type: i1$1.CookieService }, { type: i1.HttpClient }];
164
482
  } });
165
483
 
166
- class ApiTokenInterceptor {
167
- constructor(cookie) {
168
- this.cookie = cookie;
169
- }
170
- /**
171
- * Intercepts the HTTP request and adds the Authorization header.
172
- *
173
- * @param {HttpRequest<unknown>} request - The HTTP request to intercept.
174
- * @param {HttpHandler} next - The next HTTP handler in the chain.
175
- *
176
- * @returns {Observable<HttpEvent<unknown>>} - An observable containing the HTTP event.
177
- */
178
- intercept(request, next) {
179
- if (request.headers.has('Authorization'))
180
- return next.handle(request);
181
- const token = this.cookie.get('tokenCRA');
182
- if (!token)
183
- return next.handle(request);
184
- request = request.clone({
185
- setHeaders: {
186
- Authorization: `Bearer ${token}`
187
- }
188
- });
189
- return next.handle(request);
190
- }
191
- }
192
- ApiTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, deps: [{ token: i2.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
193
- ApiTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor });
194
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, decorators: [{
195
- type: Injectable
196
- }], ctorParameters: function () { return [{ type: i2.CookieService }]; } });
197
-
198
484
  class ApiHeadersInterceptor {
199
485
  /**
200
486
  * Intercepts HTTP requests and adds common headers.
@@ -227,49 +513,79 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
227
513
  type: Injectable
228
514
  }] });
229
515
 
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
- };
516
+ class ApiTokenInterceptor {
517
+ constructor(environments, cookie) {
518
+ this.environments = environments;
519
+ this.cookie = cookie;
520
+ }
521
+ /**
522
+ * Intercepts the HTTP request and adds the Authorization header.
523
+ *
524
+ * @param {HttpRequest<unknown>} request - The HTTP request to intercept.
525
+ * @param {HttpHandler} next - The next HTTP handler in the chain.
526
+ *
527
+ * @returns {Observable<HttpEvent<unknown>>} - An observable containing the HTTP event.
528
+ */
529
+ intercept(request, next) {
530
+ if (request.headers.has('Authorization'))
531
+ return next.handle(request);
532
+ const token = this.cookie.get(this.environments.tokenName);
533
+ if (!token)
534
+ return next.handle(request);
535
+ request = request.clone({
536
+ setHeaders: {
537
+ Authorization: `Bearer ${token}`
538
+ }
539
+ });
540
+ return next.handle(request);
541
+ }
542
+ }
543
+ ApiTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, deps: [{ token: 'env' }, { token: i1$1.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
544
+ ApiTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor });
545
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ApiTokenInterceptor, decorators: [{
546
+ type: Injectable
547
+ }], ctorParameters: function () {
548
+ return [{ type: undefined, decorators: [{
549
+ type: Inject,
550
+ args: ['env']
551
+ }] }, { type: i1$1.CookieService }];
552
+ } });
553
+
554
+ const DEFAULT_TTL = 10000; // ttl in ms
555
+ class HttpCachingInterceptor {
556
+ constructor(envs) {
557
+ this.envs = envs;
558
+ this.cache = new Map();
559
+ }
560
+ intercept(req, next) {
561
+ if (req.method !== 'GET')
562
+ return next.handle(req);
563
+ const cached = this.cache.get(req.urlWithParams);
564
+ if (cached) {
565
+ const isExpired = Date.now() > cached.ttl;
566
+ if (!isExpired)
567
+ return of(cached.res);
568
+ this.cache.delete(req.urlWithParams); // If expired, remove the entry from cache
569
+ }
570
+ return next.handle(req).pipe(tap$1((res) => {
571
+ var _a;
572
+ if (!(res instanceof HttpResponse))
573
+ return;
574
+ const ttl = Date.now() + ((_a = this.envs.cacheTtl) !== null && _a !== void 0 ? _a : DEFAULT_TTL);
575
+ this.cache.set(req.urlWithParams, { res, ttl });
576
+ }));
577
+ }
578
+ }
579
+ HttpCachingInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, deps: [{ token: 'env' }], target: i0.ɵɵFactoryTarget.Injectable });
580
+ HttpCachingInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor });
581
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: HttpCachingInterceptor, decorators: [{
582
+ type: Injectable
583
+ }], ctorParameters: function () {
584
+ return [{ type: undefined, decorators: [{
585
+ type: Inject,
586
+ args: ['env']
587
+ }] }];
588
+ } });
273
589
 
274
590
  /*
275
591
  * Public API Surface of ngx-services
@@ -279,5 +595,5 @@ const xmlHeaders = (format = 'object') => {
279
595
  * Generated bundle index. Do not edit.
280
596
  */
281
597
 
282
- export { ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, NgxServicesModule, pdfHeaders, queryString, xmlHeaders };
598
+ export { ApiCompaniesService, ApiHeadersInterceptor, ApiSecurityService, ApiTokenInterceptor, HttpCachingInterceptor, NgxServicesModule, httpParams, pdfHeaders, queryString, xmlHeaders };
283
599
  //# sourceMappingURL=experteam-mx-ngx-services.mjs.map