@esolve/ng-esolve-connect 0.5.1 → 0.6.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.
@@ -1,19 +1,20 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Inject, NgModule } from '@angular/core';
3
3
  import { CommonModule } from '@angular/common';
4
- import * as i1 from '@angular/common/http';
5
- import { HttpParams, HTTP_INTERCEPTORS, HttpClientModule, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
6
- import { iif, throwError, BehaviorSubject, of } from 'rxjs';
7
- import { map, catchError, tap, switchMap } from 'rxjs/operators';
8
- import * as i1$1 from '@angular/platform-browser';
4
+ import * as i1$1 from '@angular/common/http';
5
+ import { HttpParams, HTTP_INTERCEPTORS, HttpClientModule, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
6
+ import { BehaviorSubject, throwError, iif, of } from 'rxjs';
7
+ import * as i1 from '@angular/platform-browser';
8
+ import { map, tap, catchError, switchMap } from 'rxjs/operators';
9
9
 
10
10
  const ESOLVE_CONNECT_CONFIG = new InjectionToken('esolve.connect.config');
11
- const GLOBAL_CONFIG = {
12
- images_url: '',
13
- media_path: '/media',
14
- stock_path: '/stock',
15
- banner_path: '/banners'
16
- };
11
+ // For future development
12
+ // export const GLOBAL_CONFIG = {
13
+ // images_url: '',
14
+ // media_path: '/media',
15
+ // stock_path: '/stock',
16
+ // banner_path: '/banners'
17
+ // };
17
18
 
18
19
  class EsolveSession {
19
20
  constructor(id = -1, _key = '', _key_expiration_date) {
@@ -42,89 +43,13 @@ class EsolveSession {
42
43
  }
43
44
  }
44
45
 
45
- class EsolveAddress {
46
- constructor(id, recipient, address_type, pobox, place_name, street_number, street, suburb, city, province, country, postal_code, latitude, longitude) {
47
- this.id = id;
48
- this.recipient = recipient;
49
- this.address_type = address_type;
50
- this.pobox = pobox;
51
- this.place_name = place_name;
52
- this.street_number = street_number;
53
- this.street = street;
54
- this.suburb = suburb;
55
- this.city = city;
56
- this.province = province;
57
- this.country = country;
58
- this.postal_code = postal_code;
59
- this.latitude = latitude;
60
- this.longitude = longitude;
61
- }
62
- }
63
-
64
- class EsolveAccountService {
65
- constructor(config, http) {
66
- this.config = config;
67
- this.http = http;
68
- this._user_id = 0;
69
- }
70
- get user_id() {
71
- return this._user_id;
72
- }
73
- set user_id(value) {
74
- value = ((value > 0) ? value : 0);
75
- if (this._user_id !== value) {
76
- this._user_id = value;
77
- }
78
- }
79
- processUserAddress(records) {
80
- const user_addesses = [];
81
- if (records && (this._user_id > 0)) {
82
- for (const record of records) {
83
- if (+record.userid === this._user_id) {
84
- user_addesses.push(new EsolveAddress(+record.id, record.recipient, record.address_type, record.pobox, record.place_name, record.street_number, record.street, record.suburb, record.city, record.province, record.country, record.postal_code, +record.latitude, +record.longitude));
85
- }
86
- }
87
- }
88
- return user_addesses;
89
- }
90
- getAddress() {
91
- let params = new HttpParams();
92
- params = params.set('ws_id', this.config.wsid);
93
- params = params.set('user_id', this.user_id.toString());
94
- return iif(() => (this.user_id > 0), this.http.get(`${this.config.api_url}/service/get-addresses.php`, { params }).pipe(map(response => {
95
- if (response.records === undefined) {
96
- throw response;
97
- }
98
- return this.processUserAddress(response.records);
99
- }), catchError((err) => {
100
- return throwError(err);
101
- })), throwError('Log in is required'));
102
- }
103
- }
104
- EsolveAccountService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAccountService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
105
- EsolveAccountService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAccountService, providedIn: 'root' });
106
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAccountService, decorators: [{
107
- type: Injectable,
108
- args: [{
109
- providedIn: 'root'
110
- }]
111
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
112
- type: Inject,
113
- args: [ESOLVE_CONNECT_CONFIG]
114
- }] }, { type: i1.HttpClient }]; } });
115
-
116
46
  class EsolveSessionService {
117
- constructor(config, account) {
47
+ constructor(config) {
118
48
  this.config = config;
119
49
  this.storage_key = 'ngEslvUserSession';
120
50
  this.setStorageKey();
121
51
  this._session = new BehaviorSubject(new EsolveSession(0, ''));
122
52
  this.session = this._session.asObservable();
123
- this._session.subscribe((session) => {
124
- if (session.key !== '') {
125
- account.user_id = session.id;
126
- }
127
- });
128
53
  }
129
54
  get currentSession() {
130
55
  return this._session.value;
@@ -180,7 +105,7 @@ class EsolveSessionService {
180
105
  }
181
106
  }
182
107
  }
183
- EsolveSessionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSessionService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: EsolveAccountService }], target: i0.ɵɵFactoryTarget.Injectable });
108
+ EsolveSessionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSessionService, deps: [{ token: ESOLVE_CONNECT_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
184
109
  EsolveSessionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSessionService, providedIn: 'root' });
185
110
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSessionService, decorators: [{
186
111
  type: Injectable,
@@ -190,7 +115,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
190
115
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
191
116
  type: Inject,
192
117
  args: [ESOLVE_CONNECT_CONFIG]
193
- }] }, { type: EsolveAccountService }]; } });
118
+ }] }]; } });
194
119
 
195
120
  class EsolveAuthInterceptorService {
196
121
  constructor(config, session) {
@@ -267,6 +192,67 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
267
192
  }]
268
193
  }] });
269
194
 
195
+ class EsolveHttpError {
196
+ constructor(type, message, error_code) {
197
+ this.type = type;
198
+ this.message = message;
199
+ this.error_code = error_code;
200
+ }
201
+ }
202
+
203
+ class EsolveErrorHandlerService {
204
+ constructor() { }
205
+ parseException(exception) {
206
+ const error = new EsolveHttpError('exception', exception.message || 'Unknown exception has occurred', exception.additional_data.exception_type || 'unknown');
207
+ return error;
208
+ }
209
+ parseErrors(response) {
210
+ const error = new EsolveHttpError('error', 'Unknown error has occurred', 'unknown');
211
+ if ((response.status.state === 'none') && (response.log.length > 0)) {
212
+ error.error_code = 'no_response';
213
+ error.message = 'Response was provided';
214
+ }
215
+ else if (response.status.state === 'error') {
216
+ const login_error_log = response.log[0];
217
+ error.error_code = login_error_log.message_code;
218
+ error.message = login_error_log.message;
219
+ }
220
+ return error;
221
+ }
222
+ handleHttpError(service_type, errorRes) {
223
+ if (errorRes instanceof HttpErrorResponse) {
224
+ if (errorRes.status === 500) {
225
+ const server_error = errorRes.error;
226
+ if ((server_error.service_type === service_type) ||
227
+ (server_error.type !== undefined) ||
228
+ (server_error.message !== undefined) ||
229
+ (server_error.additional_data !== undefined)) {
230
+ return throwError(this.parseException(server_error));
231
+ }
232
+ }
233
+ }
234
+ else {
235
+ if (errorRes.type !== undefined) {
236
+ if (errorRes.type === 'exception') {
237
+ return throwError(this.parseException(errorRes));
238
+ }
239
+ }
240
+ else if (errorRes.transaction_type !== undefined) {
241
+ return throwError(this.parseErrors(errorRes));
242
+ }
243
+ }
244
+ return throwError(errorRes);
245
+ }
246
+ }
247
+ EsolveErrorHandlerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveErrorHandlerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
248
+ EsolveErrorHandlerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveErrorHandlerService, providedIn: 'root' });
249
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveErrorHandlerService, decorators: [{
250
+ type: Injectable,
251
+ args: [{
252
+ providedIn: 'root'
253
+ }]
254
+ }], ctorParameters: function () { return []; } });
255
+
270
256
  /**
271
257
  * Search Engine Optimization information.
272
258
  */
@@ -375,7 +361,7 @@ class EsolveSeoService {
375
361
  this.setPageKeywordsTags(seoInfo.keywords);
376
362
  }
377
363
  }
378
- EsolveSeoService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSeoService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.Title }, { token: i1$1.Meta }], target: i0.ɵɵFactoryTarget.Injectable });
364
+ EsolveSeoService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSeoService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.Title }, { token: i1.Meta }], target: i0.ɵɵFactoryTarget.Injectable });
379
365
  EsolveSeoService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSeoService, providedIn: 'root' });
380
366
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveSeoService, decorators: [{
381
367
  type: Injectable,
@@ -385,13 +371,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
385
371
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
386
372
  type: Inject,
387
373
  args: [ESOLVE_CONNECT_CONFIG]
388
- }] }, { type: i1$1.Title }, { type: i1$1.Meta }]; } });
374
+ }] }, { type: i1.Title }, { type: i1.Meta }]; } });
375
+
376
+ class EsolveAddress {
377
+ constructor(id, recipient, address_type, pobox, place_name, street_number, street, suburb, city, province, country, postal_code, latitude, longitude) {
378
+ this.id = id;
379
+ this.recipient = recipient;
380
+ this.address_type = address_type;
381
+ this.pobox = pobox;
382
+ this.place_name = place_name;
383
+ this.street_number = street_number;
384
+ this.street = street;
385
+ this.suburb = suburb;
386
+ this.city = city;
387
+ this.province = province;
388
+ this.country = country;
389
+ this.postal_code = postal_code;
390
+ this.latitude = latitude;
391
+ this.longitude = longitude;
392
+ }
393
+ }
389
394
 
390
395
  class EsolveAuthService {
391
- constructor(config, http, session) {
396
+ constructor(config, http, session, errorHandler) {
392
397
  this.config = config;
393
398
  this.http = http;
394
399
  this.session = session;
400
+ this.errorHandler = errorHandler;
395
401
  }
396
402
  checkAccessToken(session) {
397
403
  var _a;
@@ -409,7 +415,9 @@ class EsolveAuthService {
409
415
  'Accept-Language': '*'
410
416
  })
411
417
  }).pipe(map(responseData => {
412
- if ((responseData.type === 'error') || (responseData.type === 'exception') || (!responseData.additional_data.key_okay)) {
418
+ if ((responseData.type === 'error') ||
419
+ (responseData.type === 'exception') ||
420
+ (!responseData.additional_data.key_okay)) {
413
421
  throw responseData;
414
422
  }
415
423
  responseData.additional_data.key = token;
@@ -434,7 +442,8 @@ class EsolveAuthService {
434
442
  'Accept-Language': '*'
435
443
  })
436
444
  }).pipe(tap(responseData => {
437
- if ((responseData.type === 'error') || (responseData.type === 'exception')) {
445
+ if ((responseData.type === 'error') ||
446
+ (responseData.type === 'exception')) {
438
447
  throw responseData;
439
448
  }
440
449
  }), catchError(this.handleError), tap(responseData => {
@@ -465,11 +474,13 @@ class EsolveAuthService {
465
474
  responseType: 'json',
466
475
  observe: 'body'
467
476
  }).pipe(map(response => {
468
- if ((response.responses === undefined) || (response.responses.length <= 0)) {
477
+ if ((response.responses === undefined) ||
478
+ (response.responses.length <= 0)) {
469
479
  throw response;
470
480
  }
471
481
  const login_response = response.responses[0];
472
- if ((login_response.status.state !== 'success') && (login_response.status.state !== 'warning')) {
482
+ if ((login_response.status.state !== 'success') &&
483
+ (login_response.status.state !== 'warning')) {
473
484
  throw login_response;
474
485
  }
475
486
  for (const response_log of login_response.log) {
@@ -480,54 +491,7 @@ class EsolveAuthService {
480
491
  }
481
492
  throw login_response;
482
493
  }), catchError((errorRes) => {
483
- const parseException = (exception) => {
484
- const exception_type = exception.additional_data.exception_type;
485
- const error = {
486
- type: 'exception',
487
- message: exception.message || '',
488
- error_code: exception_type || 'unknown'
489
- };
490
- return error;
491
- };
492
- const parseLoginErrors = (login_response) => {
493
- const error = {
494
- type: 'error',
495
- message: 'Unknown error has occured',
496
- error_code: 'unknown'
497
- };
498
- if ((login_response.status.state === 'none') && (login_response.log.length > 0)) {
499
- error.error_code = 'no_response';
500
- error.message = 'Response was provided';
501
- }
502
- else if (login_response.status.state === 'error') {
503
- const login_error_log = login_response.log[0];
504
- error.error_code = login_error_log.message_code;
505
- error.message = login_error_log.message;
506
- }
507
- return error;
508
- };
509
- if (errorRes instanceof HttpErrorResponse) {
510
- if (errorRes.status === 500) {
511
- const server_error = errorRes.error;
512
- if ((server_error.service_type === 'set-login') ||
513
- (server_error.type !== undefined) ||
514
- (server_error.message !== undefined) ||
515
- (server_error.additional_data !== undefined)) {
516
- return throwError(parseException(server_error));
517
- }
518
- }
519
- }
520
- else {
521
- if (errorRes.type !== undefined) {
522
- if (errorRes.type === 'exception') {
523
- return throwError(parseException(errorRes));
524
- }
525
- }
526
- else if (errorRes.transaction_type === 'Login') {
527
- return throwError(parseLoginErrors(errorRes));
528
- }
529
- }
530
- return throwError(errorRes);
494
+ return this.errorHandler.handleHttpError('set-login', errorRes);
531
495
  }));
532
496
  }
533
497
  logout() {
@@ -536,6 +500,7 @@ class EsolveAuthService {
536
500
  console.log(error);
537
501
  });
538
502
  }
503
+ // Handlers
539
504
  handleExpiration() {
540
505
  return (session) => {
541
506
  this.checkAccessToken(session).then((response) => {
@@ -555,7 +520,9 @@ class EsolveAuthService {
555
520
  message: 'An unknown error occurred',
556
521
  data: {}
557
522
  };
558
- if ((!errorRes.type) || (!errorRes.service_type) || (!errorRes.message)) {
523
+ if ((!errorRes.type) ||
524
+ (!errorRes.service_type) ||
525
+ (!errorRes.message)) {
559
526
  return throwError(error);
560
527
  }
561
528
  if (errorRes.message.trim() !== '') {
@@ -567,7 +534,7 @@ class EsolveAuthService {
567
534
  return throwError(error);
568
535
  }
569
536
  }
570
- EsolveAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAuthService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }, { token: EsolveSessionService }], target: i0.ɵɵFactoryTarget.Injectable });
537
+ EsolveAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAuthService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }, { token: EsolveSessionService }, { token: EsolveErrorHandlerService }], target: i0.ɵɵFactoryTarget.Injectable });
571
538
  EsolveAuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAuthService, providedIn: 'root' });
572
539
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAuthService, decorators: [{
573
540
  type: Injectable,
@@ -577,7 +544,100 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
577
544
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
578
545
  type: Inject,
579
546
  args: [ESOLVE_CONNECT_CONFIG]
580
- }] }, { type: i1.HttpClient }, { type: EsolveSessionService }]; } });
547
+ }] }, { type: i1$1.HttpClient }, { type: EsolveSessionService }, { type: EsolveErrorHandlerService }]; } });
548
+
549
+ class EsolveAccountService {
550
+ constructor(config, http, sessionService, errorHandler) {
551
+ this.config = config;
552
+ this.http = http;
553
+ this.sessionService = sessionService;
554
+ this.errorHandler = errorHandler;
555
+ this._user_id = 0;
556
+ this.sessionService.session.subscribe((session) => {
557
+ if (session.key !== '') {
558
+ this.user_id = session.id;
559
+ }
560
+ });
561
+ }
562
+ get user_id() {
563
+ return this._user_id;
564
+ }
565
+ set user_id(value) {
566
+ value = ((value > 0) ? value : 0);
567
+ if (this._user_id !== value) {
568
+ this._user_id = value;
569
+ }
570
+ }
571
+ processUserAddress(records) {
572
+ const user_addresses = [];
573
+ if (records && (this._user_id > 0)) {
574
+ for (const record of records) {
575
+ if (+record.userid === this._user_id) {
576
+ user_addresses.push(new EsolveAddress(+record.id, record.recipient, record.address_type, record.pobox, record.place_name, record.street_number, record.street, record.suburb, record.city, record.province, record.country, record.postal_code, +record.latitude, +record.longitude));
577
+ }
578
+ }
579
+ }
580
+ return user_addresses;
581
+ }
582
+ getAddress() {
583
+ let params = new HttpParams();
584
+ params = params.set('ws_id', this.config.wsid);
585
+ params = params.set('user_id', this.user_id.toString());
586
+ return iif(() => (this.user_id > 0), this.http.get(`${this.config.api_url}/service/get-addresses.php`, { params }).pipe(map(response => {
587
+ if (response.records === undefined) {
588
+ throw response;
589
+ }
590
+ return this.processUserAddress(response.records);
591
+ }), catchError((err) => {
592
+ return throwError(err);
593
+ })), throwError('Log in is required'));
594
+ }
595
+ registration(user_registration) {
596
+ const body = {
597
+ user: user_registration
598
+ };
599
+ return this.http.post(`${this.config.api_url}/service/set-registration.php`, body, {
600
+ headers: {
601
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
602
+ },
603
+ params: {
604
+ ws_id: this.config.wsid
605
+ },
606
+ responseType: 'json',
607
+ observe: 'body'
608
+ }).pipe(map(response => {
609
+ if ((response.responses === undefined) ||
610
+ (response.responses.length <= 0)) {
611
+ throw response;
612
+ }
613
+ const registration_response = response.responses[0];
614
+ if ((registration_response.status.state !== 'success') &&
615
+ (registration_response.status.state !== 'warning')) {
616
+ throw registration_response;
617
+ }
618
+ for (const response_log of registration_response.log) {
619
+ if ((response_log.type === 'success') && (response_log.message_code === 'registration_success')) {
620
+ this.sessionService.handleUpdateSession(registration_response.esolve_id);
621
+ return registration_response.esolve_id;
622
+ }
623
+ }
624
+ throw registration_response;
625
+ }), catchError((errorRes) => {
626
+ return this.errorHandler.handleHttpError('set-registration', errorRes);
627
+ }));
628
+ }
629
+ }
630
+ EsolveAccountService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAccountService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }, { token: EsolveSessionService }, { token: EsolveErrorHandlerService }], target: i0.ɵɵFactoryTarget.Injectable });
631
+ EsolveAccountService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAccountService, providedIn: 'root' });
632
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveAccountService, decorators: [{
633
+ type: Injectable,
634
+ args: [{
635
+ providedIn: 'root'
636
+ }]
637
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
638
+ type: Inject,
639
+ args: [ESOLVE_CONNECT_CONFIG]
640
+ }] }, { type: i1$1.HttpClient }, { type: EsolveSessionService }, { type: EsolveErrorHandlerService }]; } });
581
641
 
582
642
  class EsolveMediaArticle {
583
643
  constructor(identifier, title, article, image_url = '', tags = [], topics = [], seo_title = '', seo_keywords = '', seo_description = '') {
@@ -685,7 +745,7 @@ class EsolveMediaService {
685
745
  }));
686
746
  }
687
747
  }
688
- EsolveMediaService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMediaService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
748
+ EsolveMediaService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMediaService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
689
749
  EsolveMediaService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMediaService, providedIn: 'root' });
690
750
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMediaService, decorators: [{
691
751
  type: Injectable,
@@ -695,7 +755,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
695
755
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
696
756
  type: Inject,
697
757
  args: [ESOLVE_CONNECT_CONFIG]
698
- }] }, { type: i1.HttpClient }]; } });
758
+ }] }, { type: i1$1.HttpClient }]; } });
699
759
 
700
760
  class EsolveNewsArticle {
701
761
  constructor(id, title, sef_title, article, short_description, txdate, active, image, featured, author, seo_title = '', seo_keywords = '') {
@@ -827,7 +887,7 @@ class EsolveNewsService {
827
887
  return new EsolveNewsArticle(newsRecord.id, newsRecord.title, newsRecord.sef_title, newsRecord.article, newsRecord.short_description, newsRecord.txdate, newsRecord.active, newsRecord.image, newsRecord.featured, author, newsRecord.seo_page_title, newsRecord.seo_keywords);
828
888
  }
829
889
  }
830
- EsolveNewsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveNewsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
890
+ EsolveNewsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveNewsService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
831
891
  EsolveNewsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveNewsService, providedIn: 'root' });
832
892
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveNewsService, decorators: [{
833
893
  type: Injectable,
@@ -837,7 +897,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
837
897
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
838
898
  type: Inject,
839
899
  args: [ESOLVE_CONNECT_CONFIG]
840
- }] }, { type: i1.HttpClient }]; } });
900
+ }] }, { type: i1$1.HttpClient }]; } });
841
901
 
842
902
  class EsolveBanner {
843
903
  constructor(id, banner_display_container, identifier, type, title, article, sort_priority, link, images) {
@@ -970,7 +1030,7 @@ class EsolveBannerService {
970
1030
  }));
971
1031
  }
972
1032
  }
973
- EsolveBannerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveBannerService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1033
+ EsolveBannerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveBannerService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
974
1034
  EsolveBannerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveBannerService, providedIn: 'root' });
975
1035
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveBannerService, decorators: [{
976
1036
  type: Injectable,
@@ -980,7 +1040,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
980
1040
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
981
1041
  type: Inject,
982
1042
  args: [ESOLVE_CONNECT_CONFIG]
983
- }] }, { type: i1.HttpClient }]; } });
1043
+ }] }, { type: i1$1.HttpClient }]; } });
984
1044
 
985
1045
  class EsolveMenuItem {
986
1046
  constructor(url, name, target, children = []) {
@@ -1020,7 +1080,7 @@ class EsolveMenuService {
1020
1080
  return menu;
1021
1081
  }
1022
1082
  }
1023
- EsolveMenuService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMenuService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1083
+ EsolveMenuService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMenuService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1024
1084
  EsolveMenuService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMenuService, providedIn: 'root' });
1025
1085
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveMenuService, decorators: [{
1026
1086
  type: Injectable,
@@ -1030,7 +1090,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
1030
1090
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1031
1091
  type: Inject,
1032
1092
  args: [ESOLVE_CONNECT_CONFIG]
1033
- }] }, { type: i1.HttpClient }]; } });
1093
+ }] }, { type: i1$1.HttpClient }]; } });
1034
1094
 
1035
1095
  class EsolveTopicService {
1036
1096
  constructor(config, http) {
@@ -1070,7 +1130,7 @@ class EsolveTopicService {
1070
1130
  }));
1071
1131
  }
1072
1132
  }
1073
- EsolveTopicService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveTopicService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1133
+ EsolveTopicService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveTopicService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1074
1134
  EsolveTopicService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveTopicService, providedIn: 'root' });
1075
1135
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveTopicService, decorators: [{
1076
1136
  type: Injectable,
@@ -1080,7 +1140,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
1080
1140
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1081
1141
  type: Inject,
1082
1142
  args: [ESOLVE_CONNECT_CONFIG]
1083
- }] }, { type: i1.HttpClient }]; } });
1143
+ }] }, { type: i1$1.HttpClient }]; } });
1084
1144
 
1085
1145
  class EsolveStockBadge {
1086
1146
  constructor(id, text, identifier, font_colour, badge_colour, sort_priority) {
@@ -1398,7 +1458,7 @@ class EsolveStockService {
1398
1458
  }));
1399
1459
  }
1400
1460
  }
1401
- EsolveStockService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveStockService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1461
+ EsolveStockService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveStockService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1402
1462
  EsolveStockService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveStockService, providedIn: 'root' });
1403
1463
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveStockService, decorators: [{
1404
1464
  type: Injectable,
@@ -1408,7 +1468,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
1408
1468
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1409
1469
  type: Inject,
1410
1470
  args: [ESOLVE_CONNECT_CONFIG]
1411
- }] }, { type: i1.HttpClient }]; } });
1471
+ }] }, { type: i1$1.HttpClient }]; } });
1412
1472
 
1413
1473
  class EsolveCategoryTreeItem {
1414
1474
  constructor(type, esolve_id, parent_id, description, sef_description, short_description, sort_priority, active, display_only, image_name, seo_title, seo_keywords, seo_description, children) {
@@ -1563,7 +1623,7 @@ class EsolveCategoryTreeService {
1563
1623
  return throwError('Invalid options');
1564
1624
  }
1565
1625
  }
1566
- EsolveCategoryTreeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCategoryTreeService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1626
+ EsolveCategoryTreeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCategoryTreeService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
1567
1627
  EsolveCategoryTreeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCategoryTreeService, providedIn: 'root' });
1568
1628
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCategoryTreeService, decorators: [{
1569
1629
  type: Injectable,
@@ -1573,7 +1633,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
1573
1633
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1574
1634
  type: Inject,
1575
1635
  args: [ESOLVE_CONNECT_CONFIG]
1576
- }] }, { type: i1.HttpClient }]; } });
1636
+ }] }, { type: i1$1.HttpClient }]; } });
1577
1637
 
1578
1638
  class EsolveStockLocation {
1579
1639
  constructor(record) {
@@ -1858,9 +1918,10 @@ class EsolveCartStockItem {
1858
1918
  }
1859
1919
 
1860
1920
  class EsolveCartService {
1861
- constructor(config, http) {
1921
+ constructor(config, http, errorHandler) {
1862
1922
  this.config = config;
1863
1923
  this.http = http;
1924
+ this.errorHandler = errorHandler;
1864
1925
  this._cached_tracking = 0;
1865
1926
  }
1866
1927
  /**
@@ -2150,59 +2211,12 @@ class EsolveCartService {
2150
2211
  }
2151
2212
  return checkout_result.esolve_id;
2152
2213
  }), catchError((errorRes) => {
2153
- const parseException = (exception) => {
2154
- const exception_type = exception.additional_data.exception_type;
2155
- const error = {
2156
- type: 'exception',
2157
- message: exception.message || '',
2158
- error_code: exception_type || 'unknown'
2159
- };
2160
- return error;
2161
- };
2162
- const parseCheckoutErrors = (response) => {
2163
- const error = {
2164
- type: 'error',
2165
- message: 'Unknown error has occured',
2166
- error_code: 'unknown'
2167
- };
2168
- if ((response.status.state === 'none') || (response.log.length === 0)) {
2169
- error.error_code = 'no_response';
2170
- error.message = 'Response was provided';
2171
- }
2172
- else if (response.status.state === 'error') {
2173
- const error_log = response.log[0];
2174
- error.error_code = error_log.message_code;
2175
- error.message = error_log.message;
2176
- }
2177
- return error;
2178
- };
2179
- if (errorRes instanceof HttpErrorResponse) {
2180
- if (errorRes.status === 500) {
2181
- const server_error = errorRes.error;
2182
- if ((server_error.service_type === 'set-checkout') ||
2183
- (server_error.type !== undefined) ||
2184
- (server_error.message !== undefined) ||
2185
- (server_error.additional_data !== undefined)) {
2186
- return throwError(parseException(server_error));
2187
- }
2188
- }
2189
- }
2190
- else {
2191
- if (errorRes.type !== undefined) {
2192
- if (errorRes.type === 'exception') {
2193
- return throwError(parseException(errorRes));
2194
- }
2195
- }
2196
- else if (errorRes.transaction_type !== undefined) {
2197
- return throwError(parseCheckoutErrors(errorRes));
2198
- }
2199
- }
2200
- return throwError(errorRes);
2214
+ return this.errorHandler.handleHttpError('set-checkout', errorRes);
2201
2215
  }));
2202
2216
  }));
2203
2217
  }
2204
2218
  }
2205
- EsolveCartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCartService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
2219
+ EsolveCartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCartService, deps: [{ token: ESOLVE_CONNECT_CONFIG }, { token: i1$1.HttpClient }, { token: EsolveErrorHandlerService }], target: i0.ɵɵFactoryTarget.Injectable });
2206
2220
  EsolveCartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCartService, providedIn: 'root' });
2207
2221
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0, type: EsolveCartService, decorators: [{
2208
2222
  type: Injectable,
@@ -2212,7 +2226,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
2212
2226
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
2213
2227
  type: Inject,
2214
2228
  args: [ESOLVE_CONNECT_CONFIG]
2215
- }] }, { type: i1.HttpClient }]; } });
2229
+ }] }, { type: i1$1.HttpClient }, { type: EsolveErrorHandlerService }]; } });
2216
2230
 
2217
2231
  /*
2218
2232
  * Public API Surface of ng-esolve-connect
@@ -2222,5 +2236,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImpor
2222
2236
  * Generated bundle index. Do not edit.
2223
2237
  */
2224
2238
 
2225
- export { BankingDetails, EsolveAccountService, EsolveAddress, EsolveAuthService, EsolveBanner, EsolveBannerImage, EsolveBannerImageHotspot, EsolveBannerService, EsolveCartItem, EsolveCartService, EsolveCartTotals, EsolveCategoryTreeItem, EsolveCategoryTreeService, EsolveMediaArticle, EsolveMediaService, EsolveMenuItem, EsolveMenuService, EsolveNewsArticle, EsolveNewsArticleAuthor, EsolveNewsArticleList, EsolveNewsGroup, EsolveNewsService, EsolvePaymentMethod, EsolveSEOInfo, EsolveSeoService, EsolveSession, EsolveSessionService, EsolveShippingCost, EsolveShippingMethod, EsolveStockBadge, EsolveStockItem, EsolveStockItemList, EsolveStockLocation, EsolveStockPrice, EsolveStockService, EsolveTag, EsolveTopic, EsolveTopicService, NgEsolveConnectModule };
2239
+ export { BankingDetails, EsolveAccountService, EsolveAddress, EsolveAuthService, EsolveBanner, EsolveBannerImage, EsolveBannerImageHotspot, EsolveBannerService, EsolveCartItem, EsolveCartService, EsolveCartTotals, EsolveCategoryTreeItem, EsolveCategoryTreeService, EsolveErrorHandlerService, EsolveHttpError, EsolveMediaArticle, EsolveMediaService, EsolveMenuItem, EsolveMenuService, EsolveNewsArticle, EsolveNewsArticleAuthor, EsolveNewsArticleList, EsolveNewsGroup, EsolveNewsService, EsolvePaymentMethod, EsolveSEOInfo, EsolveSeoService, EsolveSession, EsolveSessionService, EsolveShippingCost, EsolveShippingMethod, EsolveStockBadge, EsolveStockItem, EsolveStockItemList, EsolveStockLocation, EsolveStockPrice, EsolveStockService, EsolveTag, EsolveTopic, EsolveTopicService, NgEsolveConnectModule };
2226
2240
  //# sourceMappingURL=esolve-ng-esolve-connect.js.map