Skip to content

Commit

Permalink
Merge pull request #18 from experianplc/format_and_enrich
Browse files Browse the repository at this point in the history
Implement format and enrich in a single request
  • Loading branch information
ZharkoEx authored Mar 13, 2024
2 parents 8017531 + 34518fb commit 9bd9baa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/js/address-metadata-display.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/js/experian-address-validation.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/lib/address-search.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Request from './request';
import { AddressSearchOptions, AddressValidationMode, AddressValidationSearchType } from './search-options';
import { EnrichmentDetails } from './class-types';
import { EnrichmentDetails, EnrichmentResponse } from './class-types';
export default class AddressValidation {
options: AddressSearchOptions;
searchType: AddressValidationSearchType;
Expand Down Expand Up @@ -47,7 +47,8 @@ export default class AddressValidation {
setToken(token: string): void;
setSearchType(searchType: AddressValidationSearchType): void;
getLookupEnrichmentData(key: string): void;
getEnrichmentData(globalAddressKey: string): void;
getEnrichmentData(data: EnrichmentResponse): void;
private getEnrichmentAttributes;
private callEnrichment;
private setup;
private getParameter;
Expand Down
4 changes: 2 additions & 2 deletions src/js/address-metadata-display.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Display a map with the lat/long details after a data enrichment lookup
address.events.on("post-enrichment", function (data) {
let enrichmentElement = document.querySelector("#enrichment");
if (address.geocodes.detailsMap.size > 0 || (data.result.what3words && data.result.what3words.latitude)) {
if (address.geocodes.detailsMap.size > 0 || (data.result.what3words && data.result.what3words.latitude) || address.cvHousehold.detailsMap.size > 0) {
document.querySelector(".metadata #what3words-key").classList.add("hidden");
document.querySelector(".metadata #what3words-value").classList.add("hidden");

Expand Down Expand Up @@ -93,7 +93,7 @@ address.events.on("post-enrichment", function (data) {
// Display and populate the "metadata" container
function populateMetadata(data) {
// Try and get some geocoded enrichment data
address.getEnrichmentData(data.result.global_address_key);
address.getEnrichmentData(data.enrichment);

const confidence = data.result.confidence;
if (confidence) {
Expand Down
27 changes: 20 additions & 7 deletions src/ts/address-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export default class AddressValidation {
}
}

public getEnrichmentData(globalAddressKey: string) {
public getEnrichmentData(data: EnrichmentResponse) {
this.events.trigger('pre-enrichment');
this.result.handleEnrichmentResponse(data);
}

private getEnrichmentAttributes(globalAddressKey: string) {
if (globalAddressKey) {
let regionalAttributes: {};
let premium_location_insight: {} = [
Expand All @@ -130,7 +135,7 @@ export default class AddressValidation {
usa_regional_geocodes: Object.keys(enrichmentOutput.USA.usa_regional_geocodes),
premium_location_insight
}
} else if (this.currentCountryCode == "GBR") {
} else if (this.currentCountryCode == "GBR") {
regionalAttributes = {
uk_location_essential: Object.keys(enrichmentOutput.GBR.uk_location_essential),
what3words: Object.keys(enrichmentOutput.GBR.what3words),
Expand All @@ -142,7 +147,7 @@ export default class AddressValidation {
premium_location_insight
}
}
this.callEnrichment(globalAddressKey, regionalAttributes);
return regionalAttributes;
}
}

Expand Down Expand Up @@ -515,6 +520,8 @@ export default class AddressValidation {
if (regex.test(this.currentSearchTerm.trim())) {
this.avMode = AddressValidationMode.WHAT3WORDS;
this.currentSearchTerm = this.currentSearchTerm.trim();
} else if (this.avMode != AddressValidationMode.LOOKUPV2){
this.avMode = AddressValidationMode.SEARCH;
}

// is UPRN or UDPRN
Expand All @@ -536,7 +543,7 @@ export default class AddressValidation {
let url, headers, callback, data;

// Construct the new Search URL and data
switch(this.avMode) {
switch(this.avMode as any) {
case AddressValidationMode.WHAT3WORDS: {
data = this.generateLookupDataForApiCall(this.getWhat3WordsLookupValue(this.currentSearchTerm, true), AddressValidationLookupKeywords.WHAT3WORDS.key);
url = this.baseUrl + this.lookupV2Endpoint;
Expand Down Expand Up @@ -1221,10 +1228,16 @@ export default class AddressValidation {
// Hide the searching spinner
this.searchSpinner.hide();

let data = {
layouts: [ "default" ],
layout_format: "default",
attributes: this.getEnrichmentAttributes(url.split('/')[6])
}

// Initiate a new Format request
this.request.send(url, 'GET', this.result.show, undefined,
[{key: 'Add-Components', value: true}, { key: 'Add-Metadata', value: true }/*, {key: 'Add-Components', value: true}*/]);
}
this.request.send(url, 'POST', this.result.show, JSON.stringify(data),
[{ key: 'Add-Components', value: true }, { key: 'Add-Metadata', value: true }, { key: 'Add-Enrichment', value: true}]);
}

private refine(key: string) {
// Trigger an event
Expand Down

0 comments on commit 9bd9baa

Please sign in to comment.