http-request-manager 18.11.19 → 18.11.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -218,6 +218,8 @@ export class AppModule { }
218
218
  | `retry` | `RetryOptions` | Default retry configuration | `{ times: 0, delay: 3 }` |
219
219
  | `stream` | `boolean` | Enable streaming by default | `false` |
220
220
  | `displayError` | `boolean` | Show toast errors by default | `false` |
221
+ | `displaySuccess` | `boolean` | Show toast on success by default | `false` |
222
+ | `successMessage` | `string` | Custom success toast message | `'OK'` |
221
223
 
222
224
  #### Local Storage Options (`LocalStorageOptions`)
223
225
 
@@ -2935,15 +2935,17 @@ class RetryOptions {
2935
2935
  }
2936
2936
 
2937
2937
  class BatchOptions {
2938
- constructor(mode = 'sequential', stopOnError = false, concurrency = 3, ignoreErrors = false, logErrors = true) {
2938
+ constructor(mode = 'sequential', stopOnError = false, concurrency = 3, ignoreErrors = false, logErrors = true, displaySuccess, successMessage) {
2939
2939
  this.mode = mode;
2940
2940
  this.stopOnError = stopOnError;
2941
2941
  this.concurrency = concurrency;
2942
2942
  this.ignoreErrors = ignoreErrors;
2943
2943
  this.logErrors = logErrors;
2944
+ this.displaySuccess = displaySuccess;
2945
+ this.successMessage = successMessage;
2944
2946
  }
2945
2947
  static adapt(item) {
2946
- return new BatchOptions(item?.mode ?? 'sequential', item?.stopOnError ?? false, item?.concurrency ?? 3, item?.ignoreErrors ?? false, item?.logErrors !== false);
2948
+ return new BatchOptions(item?.mode ?? 'sequential', item?.stopOnError ?? false, item?.concurrency ?? 3, item?.ignoreErrors ?? false, item?.logErrors !== false, item?.displaySuccess ?? false, item?.successMessage);
2947
2949
  }
2948
2950
  }
2949
2951
 
@@ -2988,7 +2990,7 @@ var DataType;
2988
2990
  })(DataType || (DataType = {}));
2989
2991
 
2990
2992
  class ConfigHTTPOptions {
2991
- constructor(server = '', path, headers, polling, retry, stream, displayError) {
2993
+ constructor(server = '', path, headers, polling, retry, stream, displayError, displaySuccess, successMessage) {
2992
2994
  this.server = server;
2993
2995
  this.path = path;
2994
2996
  this.headers = headers;
@@ -2996,11 +2998,13 @@ class ConfigHTTPOptions {
2996
2998
  this.retry = retry;
2997
2999
  this.stream = stream;
2998
3000
  this.displayError = displayError;
3001
+ this.displaySuccess = displaySuccess;
3002
+ this.successMessage = successMessage;
2999
3003
  }
3000
3004
  static adapt(item) {
3001
3005
  const server = Array.isArray(item?.server) ? item.server.join('/') : item?.server || '';
3002
3006
  const retryOptions = item?.retry ? RetryOptions.adapt(item.retry) : RetryOptions.adapt();
3003
- return new ConfigHTTPOptions(server, (item?.path) ? item.path : [], (item?.headers) ? item.headers : {}, item?.polling ? Math.floor(item.polling) : 0, retryOptions, (item?.stream) ? item.stream : false, (item?.displayError) ? item.displayError : false);
3007
+ return new ConfigHTTPOptions(server, (item?.path) ? item.path : [], (item?.headers) ? item.headers : {}, item?.polling ? Math.floor(item.polling) : 0, retryOptions, (item?.stream) ? item.stream : false, (item?.displayError) ? item.displayError : false, (item?.displaySuccess) ? item.displaySuccess : false, item?.successMessage);
3004
3008
  }
3005
3009
  }
3006
3010
 
@@ -3618,7 +3622,11 @@ class HTTPManagerService extends RequestService {
3618
3622
  const func = this.getRecordRequest;
3619
3623
  const requests = this.createRequest(func, updatedOptions);
3620
3624
  return this.createObservable(updatedOptions, requests, func.name)
3621
- .pipe(tap(data => this.data.next(data))).pipe(finalize(() => this.isPending.next(false)), catchError((err) => {
3625
+ .pipe(tap(data => {
3626
+ this.data.next(data);
3627
+ if (updatedOptions.displaySuccess)
3628
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
3629
+ })).pipe(finalize(() => this.isPending.next(false)), catchError((err) => {
3622
3630
  if (updatedOptions.displayError)
3623
3631
  this.handleErrorWithSnackBar(err);
3624
3632
  this.isPending.next(false);
@@ -3631,8 +3639,11 @@ class HTTPManagerService extends RequestService {
3631
3639
  const updatedOptions = this.defineReqOptions(options, params);
3632
3640
  const func = this.createRecordRequest;
3633
3641
  const requests = this.createRequest(func, updatedOptions, data);
3634
- return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => this.data.next(data)))
3635
- .pipe(finalize(() => this.isPending.next(false)), catchError((err) => {
3642
+ return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
3643
+ this.data.next(data);
3644
+ if (updatedOptions.displaySuccess)
3645
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
3646
+ }), finalize(() => this.isPending.next(false)), catchError((err) => {
3636
3647
  if (updatedOptions.displayError)
3637
3648
  this.handleErrorWithSnackBar(err);
3638
3649
  this.isPending.next(false);
@@ -3645,8 +3656,11 @@ class HTTPManagerService extends RequestService {
3645
3656
  const updatedOptions = this.defineReqOptions(options, params);
3646
3657
  const func = this.updateRecordRequest;
3647
3658
  const requests = this.createRequest(func, updatedOptions, data);
3648
- return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => this.data.next(data)))
3649
- .pipe(finalize(() => this.isPending.next(false)), catchError((err) => {
3659
+ return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
3660
+ this.data.next(data);
3661
+ if (updatedOptions.displaySuccess)
3662
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
3663
+ }), finalize(() => this.isPending.next(false)), catchError((err) => {
3650
3664
  if (updatedOptions.displayError)
3651
3665
  this.handleErrorWithSnackBar(err);
3652
3666
  this.isPending.next(false);
@@ -3659,8 +3673,11 @@ class HTTPManagerService extends RequestService {
3659
3673
  const updatedOptions = this.defineReqOptions(options, params);
3660
3674
  const func = this.deleteRecordRequest;
3661
3675
  const requests = this.createRequest(func, updatedOptions);
3662
- return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => this.data.next(data)))
3663
- .pipe(finalize(() => this.isPending.next(false)), catchError((err) => {
3676
+ return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
3677
+ this.data.next(data);
3678
+ if (updatedOptions.displaySuccess)
3679
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
3680
+ }), finalize(() => this.isPending.next(false)), catchError((err) => {
3664
3681
  if (updatedOptions.displayError)
3665
3682
  this.handleErrorWithSnackBar(err);
3666
3683
  this.isPending.next(false);
@@ -3761,6 +3778,16 @@ class HTTPManagerService extends RequestService {
3761
3778
  });
3762
3779
  this.toastMessage.toastMessage(displayError);
3763
3780
  }
3781
+ handleSuccessWithSnackBar(message) {
3782
+ const displaySuccess = ToastDisplay.adapt({
3783
+ message: message || 'OK',
3784
+ action: 'OK',
3785
+ color: ToastColors.SUCCESS,
3786
+ icon: 'check_circle',
3787
+ duration: 3 * 1000, //3 seconds
3788
+ });
3789
+ this.toastMessage.toastMessage(displaySuccess);
3790
+ }
3764
3791
  stopPolling() {
3765
3792
  this.isPending.next(false);
3766
3793
  this.polling$.next();
@@ -3803,7 +3830,10 @@ class HTTPManagerService extends RequestService {
3803
3830
  return this.getRequest(req).pipe(tap(data => {
3804
3831
  results[index] = data;
3805
3832
  }), catchError(error => this.handleSequentialError(req, error, index, batchOptions)));
3806
- }), toArray(), map(() => results));
3833
+ }), toArray(), tap(() => {
3834
+ if (batchOptions.displaySuccess)
3835
+ this.handleSuccessWithSnackBar(batchOptions.successMessage);
3836
+ }), map(() => results));
3807
3837
  }
3808
3838
  /**
3809
3839
  * Execute requests in parallel with concurrency control
@@ -3819,7 +3849,10 @@ class HTTPManagerService extends RequestService {
3819
3849
  return this.getRequest(req).pipe(tap(data => {
3820
3850
  results[index] = data;
3821
3851
  }), catchError(error => this.handleParallelError(req, error, index, batchOptions)));
3822
- }, concurrency), toArray(), map(() => results));
3852
+ }, concurrency), toArray(), tap(() => {
3853
+ if (batchOptions.displaySuccess)
3854
+ this.handleSuccessWithSnackBar(batchOptions.successMessage);
3855
+ }), map(() => results));
3823
3856
  }
3824
3857
  /**
3825
3858
  * Execute multiple HTTP requests and emit individual state changes in real-time
@@ -4273,7 +4306,11 @@ class HTTPManagerSignalsService extends RequestSignalsService {
4273
4306
  const updatedOptions = this.defineReqOptions(options, params);
4274
4307
  const func = this.getRecordRequest;
4275
4308
  const requests = this.createRequest(func, updatedOptions);
4276
- return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => this.data.set(data)), finalize(() => this.isPending.set(false)), catchError((err) => {
4309
+ return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
4310
+ this.data.set(data);
4311
+ if (updatedOptions.displaySuccess)
4312
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
4313
+ }), finalize(() => this.isPending.set(false)), catchError((err) => {
4277
4314
  if (updatedOptions.displayError)
4278
4315
  this.handleErrorWithSnackBar(err);
4279
4316
  this.isPending.set(false);
@@ -4286,7 +4323,11 @@ class HTTPManagerSignalsService extends RequestSignalsService {
4286
4323
  const updatedOptions = this.defineReqOptions(options, params);
4287
4324
  const func = this.createRecordRequest;
4288
4325
  const requests = this.createRequest(func, updatedOptions, data);
4289
- return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => this.data.set(data)), finalize(() => this.isPending.set(false)), catchError((err) => {
4326
+ return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
4327
+ this.data.set(data);
4328
+ if (updatedOptions.displaySuccess)
4329
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
4330
+ }), finalize(() => this.isPending.set(false)), catchError((err) => {
4290
4331
  if (updatedOptions.displayError)
4291
4332
  this.handleErrorWithSnackBar(err);
4292
4333
  this.isPending.set(false);
@@ -4299,7 +4340,11 @@ class HTTPManagerSignalsService extends RequestSignalsService {
4299
4340
  const updatedOptions = this.defineReqOptions(options, params);
4300
4341
  const func = this.updateRecordRequest;
4301
4342
  const requests = this.createRequest(func, updatedOptions, data);
4302
- return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => this.data.set(data)), finalize(() => this.isPending.set(false)), catchError((err) => {
4343
+ return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
4344
+ this.data.set(data);
4345
+ if (updatedOptions.displaySuccess)
4346
+ this.handleSuccessWithSnackBar(updatedOptions.successMessage);
4347
+ }), finalize(() => this.isPending.set(false)), catchError((err) => {
4303
4348
  if (updatedOptions.displayError)
4304
4349
  this.handleErrorWithSnackBar(err);
4305
4350
  this.isPending.set(false);
@@ -4409,6 +4454,16 @@ class HTTPManagerSignalsService extends RequestSignalsService {
4409
4454
  });
4410
4455
  this.toastMessage.toastMessage(displayError);
4411
4456
  }
4457
+ handleSuccessWithSnackBar(message) {
4458
+ const displaySuccess = ToastDisplay.adapt({
4459
+ message: message || 'OK',
4460
+ action: 'OK',
4461
+ color: ToastColors.SUCCESS,
4462
+ icon: 'check_circle',
4463
+ duration: 3 * 1000,
4464
+ });
4465
+ this.toastMessage.toastMessage(displaySuccess);
4466
+ }
4412
4467
  stopPolling() {
4413
4468
  this.isPending.set(false);
4414
4469
  this.polling$.next();
@@ -4451,7 +4506,10 @@ class HTTPManagerSignalsService extends RequestSignalsService {
4451
4506
  return this.getRequest(req).pipe(tap(data => {
4452
4507
  results[index] = data;
4453
4508
  }), catchError(error => this.handleSequentialError(req, error, index, batchOptions)));
4454
- }), toArray(), map(() => results));
4509
+ }), toArray(), tap(() => {
4510
+ if (batchOptions.displaySuccess)
4511
+ this.handleSuccessWithSnackBar(batchOptions.successMessage);
4512
+ }), map(() => results));
4455
4513
  }
4456
4514
  /**
4457
4515
  * Execute requests in parallel with concurrency control
@@ -4467,7 +4525,10 @@ class HTTPManagerSignalsService extends RequestSignalsService {
4467
4525
  return this.getRequest(req).pipe(tap(data => {
4468
4526
  results[index] = data;
4469
4527
  }), catchError(error => this.handleParallelError(req, error, index, batchOptions)));
4470
- }, concurrency), toArray(), map(() => results));
4528
+ }, concurrency), toArray(), tap(() => {
4529
+ if (batchOptions.displaySuccess)
4530
+ this.handleSuccessWithSnackBar(batchOptions.successMessage);
4531
+ }), map(() => results));
4471
4532
  }
4472
4533
  /**
4473
4534
  * Execute multiple HTTP requests and emit individual state changes in real-time
@@ -4571,7 +4632,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
4571
4632
  }] }] });
4572
4633
 
4573
4634
  class ApiRequest {
4574
- constructor(server = '', path, headers, adapter, mapper, polling, retry, stream, streamType, displayError, saveAs, fileContentHeader, ws, env) {
4635
+ constructor(server = '', path, headers, adapter, mapper, polling, retry, stream, streamType, displayError, displaySuccess, successMessage, saveAs, fileContentHeader, ws, env) {
4575
4636
  this.server = server;
4576
4637
  this.path = path;
4577
4638
  this.headers = headers;
@@ -4582,6 +4643,8 @@ class ApiRequest {
4582
4643
  this.stream = stream;
4583
4644
  this.streamType = streamType;
4584
4645
  this.displayError = displayError;
4646
+ this.displaySuccess = displaySuccess;
4647
+ this.successMessage = successMessage;
4585
4648
  this.saveAs = saveAs;
4586
4649
  this.fileContentHeader = fileContentHeader;
4587
4650
  this.ws = ws;
@@ -4589,7 +4652,7 @@ class ApiRequest {
4589
4652
  }
4590
4653
  static adapt(item) {
4591
4654
  const server = Array.isArray(item?.server) ? item.server.join('/') : item?.server || '';
4592
- return new ApiRequest(server, (item?.path) ? item.path : [], (item?.headers) ? item.headers : {}, item?.adapter, item?.mapper, item?.polling ? Math.floor(item.polling) : 0, item?.retry ? RetryOptions.adapt(item.retry) : RetryOptions.adapt(), (item?.stream) ? item.stream : false, item?.streamType || StreamType.AI_STREAMING, (item?.displayError) ? item.displayError : false, item?.saveAs, item?.fileContentHeader, item?.ws, item?.env || 'dev');
4655
+ return new ApiRequest(server, (item?.path) ? item.path : [], (item?.headers) ? item.headers : {}, item?.adapter, item?.mapper, item?.polling ? Math.floor(item.polling) : 0, item?.retry ? RetryOptions.adapt(item.retry) : RetryOptions.adapt(), (item?.stream) ? item.stream : false, item?.streamType || StreamType.AI_STREAMING, (item?.displayError) ? item.displayError : false, (item?.displaySuccess) ? item.displaySuccess : false, item?.successMessage, item?.saveAs, item?.fileContentHeader, item?.ws, item?.env || 'dev');
4593
4656
  }
4594
4657
  }
4595
4658
 
@@ -8658,6 +8721,7 @@ class RequestManagerDemoComponent {
8658
8721
  requestParams.retry = { times: 0, delay: 0 };
8659
8722
  }
8660
8723
  const apiOptions = ApiRequest.adapt(requestParams);
8724
+ apiOptions.displayError = true;
8661
8725
  apiOptions.path = [];
8662
8726
  apiOptions.server = this.server;
8663
8727
  apiOptions.adapter = this.adapter;