http-request-manager 18.11.22 → 18.11.23
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
|
@@ -128,7 +128,7 @@ export class UsersComponent {
|
|
|
128
128
|
|
|
129
129
|
ngOnInit() {
|
|
130
130
|
this.httpManager.getRequest(
|
|
131
|
-
ApiRequest.adapt({ path: ['users'] })
|
|
131
|
+
ApiRequest.adapt({ path: ['users'], displaySuccess: true, successMessage: 'Loaded users!' })
|
|
132
132
|
).subscribe();
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -219,7 +219,8 @@ export class AppModule { }
|
|
|
219
219
|
| `stream` | `boolean` | Enable streaming by default | `false` |
|
|
220
220
|
| `displayError` | `boolean` | Show toast errors by default | `false` |
|
|
221
221
|
| `displaySuccess` | `boolean` | Show toast on success by default | `false` |
|
|
222
|
-
| `successMessage` | `string` | Custom success toast message | `
|
|
222
|
+
| `successMessage` | `string` | Custom success toast message (optional) | `undefined` |
|
|
223
|
+
| `errorMessage` | `string` | Custom error toast message (optional, overrides default) | `undefined` |
|
|
223
224
|
|
|
224
225
|
#### Local Storage Options (`LocalStorageOptions`)
|
|
225
226
|
|
|
@@ -2935,17 +2935,17 @@ class RetryOptions {
|
|
|
2935
2935
|
}
|
|
2936
2936
|
|
|
2937
2937
|
class BatchOptions {
|
|
2938
|
-
constructor(mode = 'sequential', stopOnError = false, concurrency = 3, ignoreErrors = false, logErrors = true, displaySuccess,
|
|
2938
|
+
constructor(mode = 'sequential', stopOnError = false, concurrency = 3, ignoreErrors = false, logErrors = true, displaySuccess, displayError) {
|
|
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
2944
|
this.displaySuccess = displaySuccess;
|
|
2945
|
-
this.
|
|
2945
|
+
this.displayError = displayError;
|
|
2946
2946
|
}
|
|
2947
2947
|
static adapt(item) {
|
|
2948
|
-
return new BatchOptions(item?.mode ?? 'sequential', item?.stopOnError ?? false, item?.concurrency ?? 3, item?.ignoreErrors ?? false, item?.logErrors !== false, item?.displaySuccess ?? false, item?.
|
|
2948
|
+
return new BatchOptions(item?.mode ?? 'sequential', item?.stopOnError ?? false, item?.concurrency ?? 3, item?.ignoreErrors ?? false, item?.logErrors !== false, item?.displaySuccess ?? false, item?.displayError ?? false);
|
|
2949
2949
|
}
|
|
2950
2950
|
}
|
|
2951
2951
|
|
|
@@ -2990,7 +2990,7 @@ var DataType;
|
|
|
2990
2990
|
})(DataType || (DataType = {}));
|
|
2991
2991
|
|
|
2992
2992
|
class ConfigHTTPOptions {
|
|
2993
|
-
constructor(server = '', path, headers, polling, retry, stream, displayError, displaySuccess
|
|
2993
|
+
constructor(server = '', path, headers, polling, retry, stream, displayError, displaySuccess) {
|
|
2994
2994
|
this.server = server;
|
|
2995
2995
|
this.path = path;
|
|
2996
2996
|
this.headers = headers;
|
|
@@ -2999,12 +2999,11 @@ class ConfigHTTPOptions {
|
|
|
2999
2999
|
this.stream = stream;
|
|
3000
3000
|
this.displayError = displayError;
|
|
3001
3001
|
this.displaySuccess = displaySuccess;
|
|
3002
|
-
this.successMessage = successMessage;
|
|
3003
3002
|
}
|
|
3004
3003
|
static adapt(item) {
|
|
3005
3004
|
const server = Array.isArray(item?.server) ? item.server.join('/') : item?.server || '';
|
|
3006
3005
|
const retryOptions = item?.retry ? RetryOptions.adapt(item.retry) : RetryOptions.adapt();
|
|
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
|
|
3006
|
+
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);
|
|
3008
3007
|
}
|
|
3009
3008
|
}
|
|
3010
3009
|
|
|
@@ -3628,7 +3627,7 @@ class HTTPManagerService extends RequestService {
|
|
|
3628
3627
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
3629
3628
|
})).pipe(finalize(() => this.isPending.next(false)), catchError((err) => {
|
|
3630
3629
|
if (updatedOptions.displayError)
|
|
3631
|
-
this.handleErrorWithSnackBar(err);
|
|
3630
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage || err?.message);
|
|
3632
3631
|
this.isPending.next(false);
|
|
3633
3632
|
return this.handleError(err);
|
|
3634
3633
|
}));
|
|
@@ -3645,7 +3644,7 @@ class HTTPManagerService extends RequestService {
|
|
|
3645
3644
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
3646
3645
|
}), finalize(() => this.isPending.next(false)), catchError((err) => {
|
|
3647
3646
|
if (updatedOptions.displayError)
|
|
3648
|
-
this.handleErrorWithSnackBar(err);
|
|
3647
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage || err?.message);
|
|
3649
3648
|
this.isPending.next(false);
|
|
3650
3649
|
return this.handleError(err);
|
|
3651
3650
|
}));
|
|
@@ -3662,7 +3661,7 @@ class HTTPManagerService extends RequestService {
|
|
|
3662
3661
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
3663
3662
|
}), finalize(() => this.isPending.next(false)), catchError((err) => {
|
|
3664
3663
|
if (updatedOptions.displayError)
|
|
3665
|
-
this.handleErrorWithSnackBar(err);
|
|
3664
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage || err?.message);
|
|
3666
3665
|
this.isPending.next(false);
|
|
3667
3666
|
return this.handleError(err);
|
|
3668
3667
|
}));
|
|
@@ -3679,7 +3678,7 @@ class HTTPManagerService extends RequestService {
|
|
|
3679
3678
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
3680
3679
|
}), finalize(() => this.isPending.next(false)), catchError((err) => {
|
|
3681
3680
|
if (updatedOptions.displayError)
|
|
3682
|
-
this.handleErrorWithSnackBar(err);
|
|
3681
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage || err?.message);
|
|
3683
3682
|
this.isPending.next(false);
|
|
3684
3683
|
return this.handleError(err);
|
|
3685
3684
|
}));
|
|
@@ -3768,9 +3767,9 @@ class HTTPManagerService extends RequestService {
|
|
|
3768
3767
|
this.error.next(error.message || `${error.status} - ${error.statusText}`);
|
|
3769
3768
|
return throwError(() => error);
|
|
3770
3769
|
}
|
|
3771
|
-
handleErrorWithSnackBar(error) {
|
|
3770
|
+
handleErrorWithSnackBar(error, message) {
|
|
3772
3771
|
const displayError = ToastDisplay.adapt({
|
|
3773
|
-
message: error.message || `${error.status} - ${error.statusText}`,
|
|
3772
|
+
message: message || error.message || `${error.status} - ${error.statusText}`,
|
|
3774
3773
|
action: 'OK',
|
|
3775
3774
|
color: ToastColors.ERROR,
|
|
3776
3775
|
icon: 'error',
|
|
@@ -3780,7 +3779,7 @@ class HTTPManagerService extends RequestService {
|
|
|
3780
3779
|
}
|
|
3781
3780
|
handleSuccessWithSnackBar(message) {
|
|
3782
3781
|
const displaySuccess = ToastDisplay.adapt({
|
|
3783
|
-
message: message || '
|
|
3782
|
+
message: message || 'Success',
|
|
3784
3783
|
action: 'OK',
|
|
3785
3784
|
color: ToastColors.SUCCESS,
|
|
3786
3785
|
icon: 'check_circle',
|
|
@@ -3823,16 +3822,16 @@ class HTTPManagerService extends RequestService {
|
|
|
3823
3822
|
* @param options Optional batch configuration
|
|
3824
3823
|
* @returns Observable emitting array of data when all requests complete
|
|
3825
3824
|
*/
|
|
3826
|
-
getSequentialRequest(requests, options) {
|
|
3825
|
+
getSequentialRequest(requests, options, successMessage, errorMessage) {
|
|
3827
3826
|
const batchOptions = BatchOptions.adapt(options);
|
|
3828
3827
|
const results = new Array(requests.length);
|
|
3829
3828
|
return from(requests).pipe(concatMap((req, index) => {
|
|
3830
|
-
return this.getRequest(req).pipe(tap(data => {
|
|
3829
|
+
return this.getRequest(req, undefined).pipe(tap(data => {
|
|
3831
3830
|
results[index] = data;
|
|
3832
3831
|
}), catchError(error => this.handleSequentialError(req, error, index, batchOptions)));
|
|
3833
3832
|
}), toArray(), tap(() => {
|
|
3834
3833
|
if (batchOptions.displaySuccess)
|
|
3835
|
-
this.handleSuccessWithSnackBar(
|
|
3834
|
+
this.handleSuccessWithSnackBar(successMessage);
|
|
3836
3835
|
}), map(() => results));
|
|
3837
3836
|
}
|
|
3838
3837
|
/**
|
|
@@ -3841,17 +3840,17 @@ class HTTPManagerService extends RequestService {
|
|
|
3841
3840
|
* @param options Optional batch configuration with concurrency limit
|
|
3842
3841
|
* @returns Observable emitting array of data when all requests complete
|
|
3843
3842
|
*/
|
|
3844
|
-
getParallelRequest(requests, options) {
|
|
3843
|
+
getParallelRequest(requests, options, successMessage, errorMessage) {
|
|
3845
3844
|
const batchOptions = BatchOptions.adapt(options);
|
|
3846
3845
|
const concurrency = batchOptions.concurrency || 3;
|
|
3847
3846
|
const results = new Array(requests.length);
|
|
3848
3847
|
return from(requests).pipe(mergeMap((req, index) => {
|
|
3849
|
-
return this.getRequest(req).pipe(tap(data => {
|
|
3848
|
+
return this.getRequest(req, undefined).pipe(tap(data => {
|
|
3850
3849
|
results[index] = data;
|
|
3851
3850
|
}), catchError(error => this.handleParallelError(req, error, index, batchOptions)));
|
|
3852
3851
|
}, concurrency), toArray(), tap(() => {
|
|
3853
3852
|
if (batchOptions.displaySuccess)
|
|
3854
|
-
this.handleSuccessWithSnackBar(
|
|
3853
|
+
this.handleSuccessWithSnackBar(successMessage);
|
|
3855
3854
|
}), map(() => results));
|
|
3856
3855
|
}
|
|
3857
3856
|
/**
|
|
@@ -4312,7 +4311,7 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4312
4311
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
4313
4312
|
}), finalize(() => this.isPending.set(false)), catchError((err) => {
|
|
4314
4313
|
if (updatedOptions.displayError)
|
|
4315
|
-
this.handleErrorWithSnackBar(err);
|
|
4314
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage || err?.message);
|
|
4316
4315
|
this.isPending.set(false);
|
|
4317
4316
|
return this.handleError(err);
|
|
4318
4317
|
}));
|
|
@@ -4329,7 +4328,7 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4329
4328
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
4330
4329
|
}), finalize(() => this.isPending.set(false)), catchError((err) => {
|
|
4331
4330
|
if (updatedOptions.displayError)
|
|
4332
|
-
this.handleErrorWithSnackBar(err);
|
|
4331
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage);
|
|
4333
4332
|
this.isPending.set(false);
|
|
4334
4333
|
return this.handleError(err);
|
|
4335
4334
|
}));
|
|
@@ -4346,7 +4345,7 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4346
4345
|
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
4347
4346
|
}), finalize(() => this.isPending.set(false)), catchError((err) => {
|
|
4348
4347
|
if (updatedOptions.displayError)
|
|
4349
|
-
this.handleErrorWithSnackBar(err);
|
|
4348
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage);
|
|
4350
4349
|
this.isPending.set(false);
|
|
4351
4350
|
return this.handleError(err);
|
|
4352
4351
|
}));
|
|
@@ -4357,9 +4356,13 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4357
4356
|
const updatedOptions = this.defineReqOptions(options, params);
|
|
4358
4357
|
const func = this.deleteRecordRequest;
|
|
4359
4358
|
const requests = this.createRequest(func, updatedOptions);
|
|
4360
|
-
return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data =>
|
|
4359
|
+
return this.createObservable(updatedOptions, requests, func.name).pipe(tap(data => {
|
|
4360
|
+
this.data.set(data);
|
|
4361
|
+
if (updatedOptions.displaySuccess)
|
|
4362
|
+
this.handleSuccessWithSnackBar(updatedOptions.successMessage);
|
|
4363
|
+
}), finalize(() => this.isPending.set(false)), catchError((err) => {
|
|
4361
4364
|
if (updatedOptions.displayError)
|
|
4362
|
-
this.handleErrorWithSnackBar(err);
|
|
4365
|
+
this.handleErrorWithSnackBar(err, updatedOptions.errorMessage);
|
|
4363
4366
|
this.isPending.set(false);
|
|
4364
4367
|
return this.handleError(err);
|
|
4365
4368
|
}));
|
|
@@ -4444,9 +4447,9 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4444
4447
|
this.error.set(error.message || `${error.status} - ${error.statusText}`);
|
|
4445
4448
|
return throwError(() => error);
|
|
4446
4449
|
}
|
|
4447
|
-
handleErrorWithSnackBar(error) {
|
|
4450
|
+
handleErrorWithSnackBar(error, message) {
|
|
4448
4451
|
const displayError = ToastDisplay.adapt({
|
|
4449
|
-
message: error.message || `${error.status} - ${error.statusText}`,
|
|
4452
|
+
message: message || error.message || `${error.status} - ${error.statusText}`,
|
|
4450
4453
|
action: 'OK',
|
|
4451
4454
|
color: ToastColors.ERROR,
|
|
4452
4455
|
icon: 'error',
|
|
@@ -4456,7 +4459,7 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4456
4459
|
}
|
|
4457
4460
|
handleSuccessWithSnackBar(message) {
|
|
4458
4461
|
const displaySuccess = ToastDisplay.adapt({
|
|
4459
|
-
message: message || '
|
|
4462
|
+
message: message || 'Success',
|
|
4460
4463
|
action: 'OK',
|
|
4461
4464
|
color: ToastColors.SUCCESS,
|
|
4462
4465
|
icon: 'check_circle',
|
|
@@ -4499,16 +4502,16 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4499
4502
|
* @param options Optional batch configuration
|
|
4500
4503
|
* @returns Observable emitting array of data when all requests complete
|
|
4501
4504
|
*/
|
|
4502
|
-
getSequentialRequest(requests, options) {
|
|
4505
|
+
getSequentialRequest(requests, options, successMessage, errorMessage) {
|
|
4503
4506
|
const batchOptions = BatchOptions.adapt(options);
|
|
4504
4507
|
const results = new Array(requests.length);
|
|
4505
4508
|
return from(requests).pipe(concatMap((req, index) => {
|
|
4506
|
-
return this.getRequest(req).pipe(tap(data => {
|
|
4509
|
+
return this.getRequest(req, undefined).pipe(tap(data => {
|
|
4507
4510
|
results[index] = data;
|
|
4508
4511
|
}), catchError(error => this.handleSequentialError(req, error, index, batchOptions)));
|
|
4509
4512
|
}), toArray(), tap(() => {
|
|
4510
4513
|
if (batchOptions.displaySuccess)
|
|
4511
|
-
this.handleSuccessWithSnackBar(
|
|
4514
|
+
this.handleSuccessWithSnackBar(successMessage);
|
|
4512
4515
|
}), map(() => results));
|
|
4513
4516
|
}
|
|
4514
4517
|
/**
|
|
@@ -4517,17 +4520,17 @@ class HTTPManagerSignalsService extends RequestSignalsService {
|
|
|
4517
4520
|
* @param options Optional batch configuration with concurrency limit
|
|
4518
4521
|
* @returns Observable emitting array of data when all requests complete
|
|
4519
4522
|
*/
|
|
4520
|
-
getParallelRequest(requests, options) {
|
|
4523
|
+
getParallelRequest(requests, options, successMessage, errorMessage) {
|
|
4521
4524
|
const batchOptions = BatchOptions.adapt(options);
|
|
4522
4525
|
const concurrency = batchOptions.concurrency || 3;
|
|
4523
4526
|
const results = new Array(requests.length);
|
|
4524
4527
|
return from(requests).pipe(mergeMap((req, index) => {
|
|
4525
|
-
return this.getRequest(req).pipe(tap(data => {
|
|
4528
|
+
return this.getRequest(req, undefined).pipe(tap(data => {
|
|
4526
4529
|
results[index] = data;
|
|
4527
4530
|
}), catchError(error => this.handleParallelError(req, error, index, batchOptions)));
|
|
4528
4531
|
}, concurrency), toArray(), tap(() => {
|
|
4529
4532
|
if (batchOptions.displaySuccess)
|
|
4530
|
-
this.handleSuccessWithSnackBar(
|
|
4533
|
+
this.handleSuccessWithSnackBar(successMessage);
|
|
4531
4534
|
}), map(() => results));
|
|
4532
4535
|
}
|
|
4533
4536
|
/**
|
|
@@ -4632,7 +4635,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
4632
4635
|
}] }] });
|
|
4633
4636
|
|
|
4634
4637
|
class ApiRequest {
|
|
4635
|
-
constructor(server = '', path, headers, adapter, mapper, polling, retry, stream, streamType, displayError, displaySuccess, successMessage, saveAs, fileContentHeader, ws, env) {
|
|
4638
|
+
constructor(server = '', path, headers, adapter, mapper, polling, retry, stream, streamType, displayError, displaySuccess, successMessage, errorMessage, saveAs, fileContentHeader, ws, env) {
|
|
4636
4639
|
this.server = server;
|
|
4637
4640
|
this.path = path;
|
|
4638
4641
|
this.headers = headers;
|
|
@@ -4645,6 +4648,7 @@ class ApiRequest {
|
|
|
4645
4648
|
this.displayError = displayError;
|
|
4646
4649
|
this.displaySuccess = displaySuccess;
|
|
4647
4650
|
this.successMessage = successMessage;
|
|
4651
|
+
this.errorMessage = errorMessage;
|
|
4648
4652
|
this.saveAs = saveAs;
|
|
4649
4653
|
this.fileContentHeader = fileContentHeader;
|
|
4650
4654
|
this.ws = ws;
|
|
@@ -4652,7 +4656,7 @@ class ApiRequest {
|
|
|
4652
4656
|
}
|
|
4653
4657
|
static adapt(item) {
|
|
4654
4658
|
const server = Array.isArray(item?.server) ? item.server.join('/') : item?.server || '';
|
|
4655
|
-
return new ApiRequest(server,
|
|
4659
|
+
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?.errorMessage, item?.saveAs, item?.fileContentHeader, item?.ws, item?.env || 'dev');
|
|
4656
4660
|
}
|
|
4657
4661
|
}
|
|
4658
4662
|
|