@bpost/bp-address-auto-complete-by-component 1.0.25 → 1.0.29

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 (28) hide show
  1. package/VERSION.md +17 -0
  2. package/bpost-bp-address-auto-complete-by-component.metadata.json +1 -1
  3. package/bundles/bpost-bp-address-auto-complete-by-component.umd.js +56 -8
  4. package/bundles/bpost-bp-address-auto-complete-by-component.umd.js.map +1 -1
  5. package/bundles/bpost-bp-address-auto-complete-by-component.umd.min.js +1 -1
  6. package/bundles/bpost-bp-address-auto-complete-by-component.umd.min.js.map +1 -1
  7. package/esm2015/lib/lib-address-autocomplete-by-component.component.js +21 -6
  8. package/esm2015/lib/locality/locality.component.js +21 -3
  9. package/esm2015/lib/model/query-parameters.model.js +2 -2
  10. package/esm2015/lib/services/adress.service.js +2 -1
  11. package/esm2015/lib/services/http.service.js +15 -2
  12. package/esm2015/lib/utils/prefill-data.js +3 -1
  13. package/esm5/lib/lib-address-autocomplete-by-component.component.js +21 -6
  14. package/esm5/lib/locality/locality.component.js +21 -3
  15. package/esm5/lib/model/query-parameters.model.js +2 -2
  16. package/esm5/lib/services/adress.service.js +2 -1
  17. package/esm5/lib/services/http.service.js +16 -3
  18. package/esm5/lib/utils/prefill-data.js +3 -1
  19. package/fesm2015/bpost-bp-address-auto-complete-by-component.js +57 -9
  20. package/fesm2015/bpost-bp-address-auto-complete-by-component.js.map +1 -1
  21. package/fesm5/bpost-bp-address-auto-complete-by-component.js +58 -10
  22. package/fesm5/bpost-bp-address-auto-complete-by-component.js.map +1 -1
  23. package/lib/lib-address-autocomplete-by-component.component.d.ts +5 -1
  24. package/lib/model/query-parameters.model.d.ts +1 -1
  25. package/lib/services/adress.service.d.ts +1 -0
  26. package/lib/services/http.service.d.ts +4 -1
  27. package/lib/utils/prefill-data.d.ts +1 -0
  28. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { __decorate } from 'tslib';
2
2
  import { ɵɵdefineInjectable, Injectable, ɵɵinject, EventEmitter, ViewChild, Input, Output, Component, Pipe, ElementRef, Renderer2, Directive, NgModule } from '@angular/core';
3
3
  import { map, catchError, tap } from 'rxjs/operators';
4
4
  import { throwError, BehaviorSubject } from 'rxjs';
5
- import { HttpClient, HttpClientModule } from '@angular/common/http';
5
+ import { HttpHeaders, HttpClient, HttpClientModule } from '@angular/common/http';
6
6
  import { TranslateService, TranslateModule } from '@ngx-translate/core';
7
7
  import { CommonModule } from '@angular/common';
8
8
  import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@@ -56,7 +56,7 @@ class QueryParameters {
56
56
  this.sortByStreetNumber = enable;
57
57
  }
58
58
  sortByBox(enable) {
59
- this.sortbyBoxNumber = enable;
59
+ this.sortByBoxNumber = enable;
60
60
  }
61
61
  }
62
62
 
@@ -64,12 +64,25 @@ let HttpService = class HttpService {
64
64
  constructor(httpClient) {
65
65
  this.httpClient = httpClient;
66
66
  this.openConnections = 0;
67
+ this.apiKey = 'no-value';
68
+ }
69
+ setApiKey(apiKey) {
70
+ this.apiKey = apiKey;
71
+ }
72
+ getHttpHeaders() {
73
+ let headers = new HttpHeaders();
74
+ // Attention !
75
+ // Need to reassign as the 'set' is returning a clone of the headera object !!!
76
+ headers = headers.set('x-api-key', /*'bBkvimXYnAaEEKMyGqoWO2XiaZCQyqUi7VReYzPJ'*/ this.apiKey);
77
+ return headers;
67
78
  }
68
79
  get(url, options) {
69
80
  return this.request('GET', url, options);
70
81
  }
71
82
  request(method, url, options) {
72
83
  options = !!options ? options : {};
84
+ options = Object.assign(Object.assign({}, options), { headers: this.getHttpHeaders() });
85
+ console.log('options:', JSON.stringify(options));
73
86
  this.openConnections++;
74
87
  return this.httpClient.request(method, url, options).pipe(map((response) => this.handleResponse(response)), catchError((error) => this.handleError(error)));
75
88
  }
@@ -187,6 +200,7 @@ let AddressService = class AddressService {
187
200
  this.httpService = httpService;
188
201
  this.domain = 'http://10.194.73.9:8080';
189
202
  this.localityURL = this.domain + '/AddressAutoComplete/autocomplete/locality?IncludeGeographicalSanction=true';
203
+ this.log = true;
190
204
  }
191
205
  getLocality(baseUrl, params) {
192
206
  const url = baseUrl !== '' ? baseUrl : this.localityURL;
@@ -1132,11 +1146,29 @@ let LocalityComponent = class LocalityComponent {
1132
1146
  const suggestionMunicipality = this.transformMunicipalityInLowercaseAndWithoutDiacritics(sugAddress.municipalityName);
1133
1147
  if (suggestionLocality === this.prefillData.prefillMunicipalityName
1134
1148
  || suggestionMunicipality === this.prefillData.prefillMunicipalityName) {
1149
+ if (this.prefillData.prefillMunicipalityAndLocalityPerfectMatchFound === true) {
1150
+ if (this.showDebugMessageToConsole) {
1151
+ console.log('LOCALITY - PREFILL - skipping suggestion:', suggestion);
1152
+ }
1153
+ if (this.showDebugMessageToConsole) {
1154
+ console.log('LOCALITY - PREFILL - keeping suggestion:', this.prefillData.prefillMunicipalityPerfectMatchSuggestion);
1155
+ }
1156
+ return;
1157
+ }
1135
1158
  this.prefillData.prefillMunicipalityPerfectMatchFound = true;
1136
1159
  this.prefillData.prefillMunicipalityPerfectMatchSuggestion = suggestion;
1137
1160
  this.searchText = sugAddress.postalCode + ' ' + sugAddress.localityName;
1138
- if (this.showDebugMessageToConsole) {
1139
- console.log('LOCALITY - PREFILL - Perfect match:', suggestion);
1161
+ this.prefillData.prefillMunicipalityAndLocalityPerfectMatchFound = (suggestionLocality === this.prefillData.prefillMunicipalityName
1162
+ && suggestionMunicipality === this.prefillData.prefillMunicipalityName) ? true : false;
1163
+ if (this.prefillData.prefillMunicipalityAndLocalityPerfectMatchFound === true) {
1164
+ if (this.showDebugMessageToConsole) {
1165
+ console.log('LOCALITY - PREFILL - Perfect match - Municipality & location:', suggestion);
1166
+ }
1167
+ }
1168
+ else {
1169
+ if (this.showDebugMessageToConsole) {
1170
+ console.log('LOCALITY - PREFILL - Perfect match:', suggestion);
1171
+ }
1140
1172
  }
1141
1173
  }
1142
1174
  }
@@ -3855,6 +3887,8 @@ class PrefillData // extends PrefilledParameters
3855
3887
  this.prefillMunicipalityName = null;
3856
3888
  this.prefillMunicipalityPerfectMatchFound = false;
3857
3889
  this.prefillMunicipalityPerfectMatchSuggestion = null;
3890
+ // This is a working field, do not document
3891
+ this.prefillMunicipalityAndLocalityPerfectMatchFound = false;
3858
3892
  this.prefillStreetName = null;
3859
3893
  this.prefillStreetPerfectMatchFound = false;
3860
3894
  this.prefillStreetPerfectMatchSuggestion = null;
@@ -3870,32 +3904,34 @@ class PrefillData // extends PrefilledParameters
3870
3904
  }
3871
3905
 
3872
3906
  let LibAddressAutocompleteByComponentComponent = class LibAddressAutocompleteByComponentComponent {
3873
- constructor() {
3907
+ constructor(httpService) {
3908
+ this.httpService = httpService;
3874
3909
  this.selectedLanguage = null;
3910
+ this.baseUrl = "https://api.mailops.bpost.cloud/roa-info/externalMailingAddressProofingRest/autocomplete/";
3875
3911
  this.showDebugMessageToConsole = false;
3876
3912
  this.notInListAllowed = true;
3877
3913
  this.messageOption = 'Y';
3878
3914
  // LOCALITY
3879
- this.localityUrl = 'https://webservices-pub.bpost.be/ws/ExternalMailingAddressProofingCSREST_v1/address/autocomplete/locality';
3915
+ this.localityUrl = this.baseUrl + 'locality';
3880
3916
  this.maxSuggestionLocality = 5;
3881
3917
  this.visibleSuggestionLocalityCount = 5;
3882
3918
  // localityParams: PrefilledParameters;
3883
3919
  this.localityPrefillData = null;
3884
3920
  // STREET
3885
- this.streetUrl = 'https://webservices-pub.bpost.be/ws/ExternalMailingAddressProofingCSREST_v1/address/autocomplete/street';
3921
+ this.streetUrl = this.baseUrl + 'street';
3886
3922
  this.maxSuggestionStreet = 5;
3887
3923
  this.visibleSuggestionStreetCount = 5;
3888
3924
  // streetParams: PrefilledParameters;
3889
3925
  this.streetPrefillData = null;
3890
3926
  // STREET NUMBER
3891
3927
  // tslint:disable-next-line:max-line-length
3892
- this.streetNumberUrl = 'https://webservices-pub.bpost.be/ws/ExternalMailingAddressProofingCSREST_v1/address/autocomplete/streetNumber';
3928
+ this.streetNumberUrl = this.baseUrl + 'streetNumber';
3893
3929
  this.maxSuggestionStreetNb = 5;
3894
3930
  this.visibleSuggestionStreetNbCount = 5;
3895
3931
  // streetNumberParams: PrefilledParameters;
3896
3932
  this.streetNumberPrefillData = null;
3897
3933
  // BOX NUMBER
3898
- this.boxNumberUrl = 'https://webservices-pub.bpost.be/ws/ExternalMailingAddressProofingCSREST_v1/address/autocomplete/boxNumber';
3934
+ this.boxNumberUrl = this.baseUrl + 'boxNumber';
3899
3935
  this.maxSuggestionBoxNb = 5;
3900
3936
  this.visibleSuggestionBoxNbCount = 5;
3901
3937
  // boxParams: PrefilledParameters;
@@ -3906,6 +3942,8 @@ let LibAddressAutocompleteByComponentComponent = class LibAddressAutocompleteByC
3906
3942
  this.validationMessageEventEmitter = new EventEmitter();
3907
3943
  this.clearInputEventEmitter = new EventEmitter();
3908
3944
  this.processingPrefillData = false;
3945
+ // Pass the API key as a property of the library !
3946
+ this.apiKey = 'cyRkKOD73O1DOdgcDLLnsaOiDh6OyOkt3BBT5JU1';
3909
3947
  }
3910
3948
  // @ts-ignore
3911
3949
  set inputLang(val) {
@@ -3920,6 +3958,7 @@ let LibAddressAutocompleteByComponentComponent = class LibAddressAutocompleteByC
3920
3958
  this.setValidationMessageOptionFromInput(option);
3921
3959
  }
3922
3960
  ngOnInit() {
3961
+ this.httpService.setApiKey(this.apiKey);
3923
3962
  if (this.addressParams) {
3924
3963
  this.prefillData = this.addressParams;
3925
3964
  }
@@ -3936,6 +3975,9 @@ let LibAddressAutocompleteByComponentComponent = class LibAddressAutocompleteByC
3936
3975
  if (this.showDebugMessageToConsole) {
3937
3976
  this.displayParametersChangesToConsole(changes);
3938
3977
  }
3978
+ if (changes.hasOwnProperty('apiKey') && !changes.apiKey.firstChange) {
3979
+ this.httpService.setApiKey(this.apiKey);
3980
+ }
3939
3981
  if (changes.hasOwnProperty('addressParams') && !changes.addressParams.firstChange) {
3940
3982
  // if (changes.hasOwnProperty('addressParams')) {
3941
3983
  this.processingPrefillData = true;
@@ -4795,6 +4837,9 @@ let LibAddressAutocompleteByComponentComponent = class LibAddressAutocompleteByC
4795
4837
  this.quitPrefillMode();
4796
4838
  }
4797
4839
  };
4840
+ LibAddressAutocompleteByComponentComponent.ctorParameters = () => [
4841
+ { type: HttpService }
4842
+ ];
4798
4843
  __decorate([
4799
4844
  ViewChild(LocalityComponent, { static: false })
4800
4845
  ], LibAddressAutocompleteByComponentComponent.prototype, "autocompleteLocality", void 0);
@@ -4891,6 +4936,9 @@ __decorate([
4891
4936
  __decorate([
4892
4937
  Output()
4893
4938
  ], LibAddressAutocompleteByComponentComponent.prototype, "clearInputEventEmitter", void 0);
4939
+ __decorate([
4940
+ Input()
4941
+ ], LibAddressAutocompleteByComponentComponent.prototype, "apiKey", void 0);
4894
4942
  LibAddressAutocompleteByComponentComponent = __decorate([
4895
4943
  Component({
4896
4944
  selector: 'bp-lib-address-autocomplete-by-component',