@experteam-mx/ngx-services 20.3.6-dev1.1 → 20.3.6-dev1.2

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.
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
2
2
  import { InjectionToken, makeEnvironmentProviders, NgModule, inject, Injectable } from '@angular/core';
3
3
  import { provideHttpClient, HttpClient, HttpHeaders, HttpResponse, HttpParams } from '@angular/common/http';
4
4
  import { map, mergeMap, forkJoin, tap, Observable, of } from 'rxjs';
5
- import { map as map$1, tap as tap$1 } from 'rxjs/operators';
5
+ import { map as map$1, tap as tap$1, finalize, shareReplay } from 'rxjs/operators';
6
6
  import { CookieService } from 'ngx-cookie-service';
7
7
  import Pusher from 'pusher-js';
8
8
 
@@ -1270,6 +1270,64 @@ class ApiCatalogsService {
1270
1270
  return this.http.get(`${this.url}/package-locations`, { params })
1271
1271
  .pipe(map(({ data }) => data));
1272
1272
  }
1273
+ /**
1274
+ * Retrieves export reasons based on the provided query parameters.
1275
+ * @param params - Query parameters to filter, sort, or paginate export reasons
1276
+ * @returns An Observable that emits the export reasons data
1277
+ */
1278
+ getExportReasons(params) {
1279
+ return this.http.get(`${this.url}/export-reasons`, { params })
1280
+ .pipe(map(({ data }) => data));
1281
+ }
1282
+ /**
1283
+ * Creates a new export reason.
1284
+ * @param body - Export reason data to create
1285
+ * @returns An Observable that emits the created export reason
1286
+ */
1287
+ postExportReason(body) {
1288
+ return this.http.post(`${this.url}/export-reasons`, body)
1289
+ .pipe(map(({ data }) => data));
1290
+ }
1291
+ /**
1292
+ * Updates an existing export reason.
1293
+ * @param id - Identifier of the export reason to update
1294
+ * @param body - Updated export reason data
1295
+ * @returns An Observable that emits the updated export reason
1296
+ */
1297
+ putExportReason(id, body) {
1298
+ return this.http.put(`${this.url}/export-reasons/${id}`, body)
1299
+ .pipe(map(({ data }) => data));
1300
+ }
1301
+ /**
1302
+ * Deletes an export reason by its identifier.
1303
+ * @param id - Identifier of the export reason to delete
1304
+ * @returns An Observable that emits the operation result
1305
+ */
1306
+ deleteExportReason(id) {
1307
+ return this.http.delete(`${this.url}/export-reasons/${id}`)
1308
+ .pipe(map(({ data }) => data));
1309
+ }
1310
+ /**
1311
+ * Updates the active status of an export reason.
1312
+ * @param id - Identifier of the export reason
1313
+ * @param isActive - Indicates whether the export reason should be active or inactive
1314
+ * @returns An Observable that emits the operation result
1315
+ */
1316
+ patchExportReason(id, isActive) {
1317
+ return this.http.patch(`${this.url}/export-reasons/${id}`, {
1318
+ isActive
1319
+ })
1320
+ .pipe(map(({ data }) => data));
1321
+ }
1322
+ /**
1323
+ * Retrieves export reason types based on the provided query parameters.
1324
+ * @param params - Query parameters to filter, sort, or paginate export reason types
1325
+ * @returns An Observable that emits the export reason types data
1326
+ */
1327
+ getExportReasonTypes(params) {
1328
+ return this.http.get(`${this.url}/export-reason-types`, { params })
1329
+ .pipe(map(({ data }) => data));
1330
+ }
1273
1331
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.21", ngImport: i0, type: ApiCatalogsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1274
1332
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.21", ngImport: i0, type: ApiCatalogsService, providedIn: 'root' });
1275
1333
  }
@@ -5292,6 +5350,7 @@ function apiTokenInterceptor(req, next) {
5292
5350
 
5293
5351
  const DEFAULT_TTL = 10000; // ttl in ms
5294
5352
  const cache = new Map();
5353
+ const inFlightRequests = new Map();
5295
5354
  /**
5296
5355
  * Interceptor function to handle HTTP caching for GET requests. It retrieves cached responses
5297
5356
  * if available and valid; otherwise, it processes the request and caches the response for future use.
@@ -5305,21 +5364,30 @@ function httpCachingInterceptor(req, next) {
5305
5364
  const { cacheTtl } = inject(ENVIRONMENT_TOKEN);
5306
5365
  if (req.method !== 'GET')
5307
5366
  return next(req);
5308
- const cached = cache.get(req.urlWithParams);
5367
+ const key = req.urlWithParams;
5368
+ const cached = cache.get(key);
5309
5369
  if (cached) {
5310
5370
  const isExpired = Date.now() > cached.ttl;
5311
5371
  if (!isExpired) {
5312
5372
  return of(cached.res);
5313
5373
  }
5314
- cache.delete(req.urlWithParams); // If expired, remove the entry from cache
5374
+ cache.delete(key); // If expired, remove the entry from cache
5375
+ }
5376
+ const inFlight = inFlightRequests.get(key);
5377
+ if (inFlight) {
5378
+ return inFlight;
5315
5379
  }
5316
- return next(req).pipe(tap$1((res) => {
5380
+ const sharedRequest = next(req).pipe(tap$1((res) => {
5317
5381
  if (!(res instanceof HttpResponse)) {
5318
5382
  return;
5319
5383
  }
5320
5384
  const ttl = Date.now() + (cacheTtl ?? DEFAULT_TTL);
5321
- cache.set(req.urlWithParams, { res, ttl });
5322
- }));
5385
+ cache.set(key, { res, ttl });
5386
+ }), finalize(() => {
5387
+ inFlightRequests.delete(key);
5388
+ }), shareReplay(1));
5389
+ inFlightRequests.set(key, sharedRequest);
5390
+ return sharedRequest;
5323
5391
  }
5324
5392
 
5325
5393
  const base64PdfToUrl = (base64) => {