@nuskin/address-lookup 1.0.1-pa-1033.3 → 1.0.1-pa-1033.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/address-lookup",
3
- "version": "1.0.1-pa-1033.3",
3
+ "version": "1.0.1-pa-1033.5",
4
4
  "description": "React component for address autocomplete using Egon and Smarty services",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -20,6 +20,15 @@ const EgonResults = ({ countryCode, onSelect }) => {
20
20
 
21
21
  const displayAddress = normalizedAddress || selectedAddress;
22
22
 
23
+ const renderField = (label, value) => {
24
+ if (!value) return null;
25
+ return (
26
+ <div>
27
+ <strong>{label}:</strong> {value}
28
+ </div>
29
+ );
30
+ };
31
+
23
32
  return (
24
33
  <div style={{ flex: 1 }}>
25
34
  <h4>Egon</h4>
@@ -35,7 +44,7 @@ const EgonResults = ({ countryCode, onSelect }) => {
35
44
  />
36
45
  {responseTime && (
37
46
  <div style={{ fontSize: '12px', color: '#666', marginBottom: '10px' }}>
38
- Response time: {responseTime}ms
47
+ Search response time: {responseTime}ms
39
48
  </div>
40
49
  )}
41
50
  {loading && <div>Loading...</div>}
@@ -48,33 +57,33 @@ const EgonResults = ({ countryCode, onSelect }) => {
48
57
  )}
49
58
  {normalizeResponseTime && (
50
59
  <div style={{ fontSize: '12px', color: '#666', marginBottom: '10px' }}>
51
- Normalize time: {normalizeResponseTime}ms
60
+ Detail response time: {normalizeResponseTime}ms
52
61
  </div>
53
62
  )}
54
63
  {displayAddress?.standard ? (
55
64
  <>
56
- <div><strong>Address:</strong> {displayAddress.standard.address}</div>
57
- <div><strong>Full Address:</strong> {displayAddress.standard.full_address}</div>
58
- <div><strong>Street:</strong> {displayAddress.standard.street}</div>
59
- <div><strong>City:</strong> {displayAddress.standard.city}</div>
60
- <div><strong>State:</strong> {displayAddress.standard.state}</div>
61
- <div><strong>Province:</strong> {displayAddress.standard.province}</div>
62
- <div><strong>Region:</strong> {displayAddress.standard.region}</div>
63
- <div><strong>Postal Code:</strong> {displayAddress.standard.zipcode}</div>
64
- <div><strong>Country:</strong> {displayAddress.standard.country}</div>
65
+ {renderField('Address', displayAddress.standard.address)}
66
+ {renderField('Full Address', displayAddress.standard.full_address)}
67
+ {renderField('Street', displayAddress.standard.street)}
68
+ {renderField('City', displayAddress.standard.city)}
69
+ {renderField('State', displayAddress.standard.state)}
70
+ {renderField('Province', displayAddress.standard.province)}
71
+ {renderField('Region', displayAddress.standard.region)}
72
+ {renderField('Postal Code', displayAddress.standard.zipcode)}
73
+ {renderField('Country', displayAddress.standard.country)}
65
74
  </>
66
75
  ) : displayAddress ? (
67
76
  <>
68
- <div>
69
- <strong>Street:</strong> {displayAddress.hn_num}
70
- {displayAddress.hn_exp || ''} {displayAddress.street}
71
- </div>
72
- <div><strong>City:</strong> {displayAddress.city}</div>
73
- <div><strong>State:</strong> {displayAddress.standard.state}</div>
74
- <div><strong>Province:</strong> {displayAddress.province}</div>
75
- <div><strong>Region:</strong> {displayAddress.region}</div>
76
- <div><strong>Postal Code:</strong> {displayAddress.zipcode}</div>
77
- <div><strong>Country:</strong> {displayAddress.country}</div>
77
+ {renderField(
78
+ 'Street',
79
+ `${displayAddress.hn_num || ''}${displayAddress.hn_exp || ''} ${displayAddress.street || ''}`.trim()
80
+ )}
81
+ {renderField('City', displayAddress.city)}
82
+ {renderField('State', displayAddress.state)}
83
+ {renderField('Province', displayAddress.province)}
84
+ {renderField('Region', displayAddress.region)}
85
+ {renderField('Postal Code', displayAddress.zipcode)}
86
+ {renderField('Country', displayAddress.country)}
78
87
  </>
79
88
  ) : null}
80
89
  <button
@@ -28,16 +28,16 @@ const SmartyResults = ({ countryCode, onSelect }) => {
28
28
  const error = isUS ? smartyUSError : smartyIntlError;
29
29
  const responseTime = isUS ? smartyUSResponseTime : smartyIntlResponseTime;
30
30
 
31
- // Auto-select detailed results (don't show as list)
31
+ // Auto-select detailed results (don't show as list) - International only
32
32
  useEffect(() => {
33
- if (suggestions.length === 1 && suggestions[0].isDetailed) {
33
+ if (!isUS && suggestions.length === 1 && suggestions[0].isDetailed) {
34
34
  setSelectedAddress(suggestions[0]);
35
35
  onSelect?.({ type: 'smarty', address: suggestions[0] });
36
- } else if (suggestions.length > 0 && !suggestions[0].isDetailed) {
37
- // Clear selection when we get new summary results
36
+ } else if (!isUS && suggestions.length > 0 && !suggestions[0].isDetailed) {
37
+ // Clear selection when we get new summary results (International only)
38
38
  setSelectedAddress(null);
39
39
  }
40
- }, [suggestions, onSelect]);
40
+ }, [suggestions, onSelect, isUS]);
41
41
 
42
42
  const handleInputChange = (e) => {
43
43
  setSelectedAddress(null);
@@ -70,6 +70,15 @@ const SmartyResults = ({ countryCode, onSelect }) => {
70
70
  }
71
71
  };
72
72
 
73
+ const renderField = (label, value) => {
74
+ if (!value) return null;
75
+ return (
76
+ <div>
77
+ <strong>{label}:</strong> {value}
78
+ </div>
79
+ );
80
+ };
81
+
73
82
  return (
74
83
  <div style={{ flex: 1 }}>
75
84
  <h4>Smarty</h4>
@@ -82,38 +91,39 @@ const SmartyResults = ({ countryCode, onSelect }) => {
82
91
  />
83
92
  {responseTime && (
84
93
  <div style={{ fontSize: '12px', color: '#666', marginBottom: '10px' }}>
85
- Response time: {responseTime}ms
94
+ Search response time: {responseTime}ms
86
95
  </div>
87
96
  )}
88
97
  {loading && <div>Loading...</div>}
89
98
  {error && <div>Error: {error}</div>}
90
99
  {selectedAddress ? (
91
100
  <div style={{ border: '1px solid #ccc', padding: '10px', borderRadius: '5px' }}>
101
+ {responseTime && (
102
+ <div style={{ fontSize: '12px', color: '#666', marginBottom: '10px' }}>
103
+ Detail response time: {responseTime}ms
104
+ </div>
105
+ )}
92
106
  {selectedAddress.street_line ? (
93
107
  // US format
94
108
  <>
95
- <div><strong>Street:</strong> {selectedAddress.street_line}</div>
96
- {selectedAddress.secondary && (
97
- <div><strong>Secondary:</strong> {selectedAddress.secondary}</div>
98
- )}
99
- <div><strong>City:</strong> {selectedAddress.city}</div>
100
- <div><strong>State:</strong> {selectedAddress.state}</div>
101
- <div><strong>Zipcode:</strong> {selectedAddress.zipcode}</div>
102
- {selectedAddress.entries > 0 && (
103
- <div><strong>Entries:</strong> {selectedAddress.entries}</div>
104
- )}
109
+ {renderField('Street', selectedAddress.street_line)}
110
+ {renderField('Secondary', selectedAddress.secondary)}
111
+ {renderField('City', selectedAddress.city)}
112
+ {renderField('State', selectedAddress.state)}
113
+ {renderField('Zipcode', selectedAddress.zipcode)}
114
+ {selectedAddress.entries > 0 && renderField('Entries', selectedAddress.entries)}
105
115
  </>
106
116
  ) : (
107
117
  // International format
108
118
  <>
109
- <div><strong>Street:</strong> {selectedAddress.street}</div>
110
- <div><strong>Locality:</strong> {selectedAddress.locality}</div>
111
- <div>
112
- <strong>Administrative Area:</strong>{' '}
113
- {selectedAddress.administrative_area_long || selectedAddress.administrative_area}
114
- </div>
115
- <div><strong>Postal Code:</strong> {selectedAddress.postal_code}</div>
116
- <div><strong>Country:</strong> {selectedAddress.country_iso3}</div>
119
+ {renderField('Street', selectedAddress.street)}
120
+ {renderField('Locality', selectedAddress.locality)}
121
+ {renderField(
122
+ 'Administrative Area',
123
+ selectedAddress.administrative_area_long || selectedAddress.administrative_area
124
+ )}
125
+ {renderField('Postal Code', selectedAddress.postal_code)}
126
+ {renderField('Country', selectedAddress.country_iso3)}
117
127
  </>
118
128
  )}
119
129
  <button
package/src/countries.js CHANGED
@@ -1,24 +1,26 @@
1
1
  export const COUNTRY_MAP = {
2
- 'US': { name: 'United States', iso2: 'US', iso3: 'USA' },
3
- 'CA': { name: 'Canada', iso2: 'CA', iso3: 'CAN' },
4
- 'MX': { name: 'Mexico', iso2: 'MX', iso3: 'MEX' },
5
- 'PE': { name: 'Peru', iso2: 'PE', iso3: 'PER' },
6
- 'CO': { name: 'Colombia', iso2: 'CO', iso3: 'COL' },
7
- 'CL': { name: 'Chile', iso2: 'CL', iso3: 'CHL' },
8
- 'AR': { name: 'Argentina', iso2: 'AR', iso3: 'ARG' },
9
- 'DE': { name: 'Germany', iso2: 'DE', iso3: 'DEU' },
10
- 'FR': { name: 'France', iso2: 'FR', iso3: 'FRA' },
11
- 'IT': { name: 'Italy', iso2: 'IT', iso3: 'ITA' },
12
- 'ES': { name: 'Spain', iso2: 'ES', iso3: 'ESP' },
13
- 'GB': { name: 'United Kingdom', iso2: 'GB', iso3: 'GBR' },
14
- 'NL': { name: 'Netherlands', iso2: 'NL', iso3: 'NLD' },
15
- 'BE': { name: 'Belgium', iso2: 'BE', iso3: 'BEL' },
16
- 'AT': { name: 'Austria', iso2: 'AT', iso3: 'AUT' },
17
- 'CH': { name: 'Switzerland', iso2: 'CH', iso3: 'CHE' },
18
- 'PL': { name: 'Poland', iso2: 'PL', iso3: 'POL' },
19
- 'PT': { name: 'Portugal', iso2: 'PT', iso3: 'PRT' },
20
- 'SE': { name: 'Sweden', iso2: 'SE', iso3: 'SWE' },
21
- 'NO': { name: 'Norway', iso2: 'NO', iso3: 'NOR' },
22
- 'DK': { name: 'Denmark', iso2: 'DK', iso3: 'DNK' },
23
- 'FI': { name: 'Finland', iso2: 'FI', iso3: 'FIN' }
2
+ 'CA': { name: 'Canada', iso2: 'CA', iso3: 'CAN', houseNumberFirst: true },
3
+ 'US': { name: 'United States', iso2: 'US', iso3: 'USA', houseNumberFirst: true },
4
+ 'AU': { name: 'Australia', iso2: 'AU', iso3: 'AUS', houseNumberFirst: true },
5
+ 'NZ': { name: 'New Zealand', iso2: 'NZ', iso3: 'NZL', houseNumberFirst: true },
6
+ 'AR': { name: 'Argentina', iso2: 'AR', iso3: 'ARG', houseNumberFirst: false },
7
+ 'CL': { name: 'Chile', iso2: 'CL', iso3: 'CHL', houseNumberFirst: false },
8
+ 'CO': { name: 'Colombia', iso2: 'CO', iso3: 'COL', houseNumberFirst: false },
9
+ 'MX': { name: 'Mexico', iso2: 'MX', iso3: 'MEX', houseNumberFirst: false },
10
+ 'PE': { name: 'Peru', iso2: 'PE', iso3: 'PER', houseNumberFirst: false },
11
+ 'AT': { name: 'Austria', iso2: 'AT', iso3: 'AUT', houseNumberFirst: false },
12
+ 'BE': { name: 'Belgium', iso2: 'BE', iso3: 'BEL', houseNumberFirst: false },
13
+ 'CH': { name: 'Switzerland', iso2: 'CH', iso3: 'CHE', houseNumberFirst: false },
14
+ 'DE': { name: 'Germany', iso2: 'DE', iso3: 'DEU', houseNumberFirst: false },
15
+ 'DK': { name: 'Denmark', iso2: 'DK', iso3: 'DNK', houseNumberFirst: false },
16
+ 'ES': { name: 'Spain', iso2: 'ES', iso3: 'ESP', houseNumberFirst: false },
17
+ 'FI': { name: 'Finland', iso2: 'FI', iso3: 'FIN', houseNumberFirst: false },
18
+ 'FR': { name: 'France', iso2: 'FR', iso3: 'FRA', houseNumberFirst: false },
19
+ 'GB': { name: 'United Kingdom', iso2: 'GB', iso3: 'GBR', houseNumberFirst: false },
20
+ 'IT': { name: 'Italy', iso2: 'IT', iso3: 'ITA', houseNumberFirst: false },
21
+ 'NL': { name: 'Netherlands', iso2: 'NL', iso3: 'NLD', houseNumberFirst: false },
22
+ 'NO': { name: 'Norway', iso2: 'NO', iso3: 'NOR', houseNumberFirst: false },
23
+ 'PL': { name: 'Poland', iso2: 'PL', iso3: 'POL', houseNumberFirst: false },
24
+ 'PT': { name: 'Portugal', iso2: 'PT', iso3: 'PRT', houseNumberFirst: false },
25
+ 'SE': { name: 'Sweden', iso2: 'SE', iso3: 'SWE', houseNumberFirst: false }
24
26
  };
@@ -45,18 +45,32 @@ const useEgonLookup = (query, countryCode = '', debounceMs = 300) => {
45
45
  setResponseTime(Math.round(endTime - startTime));
46
46
 
47
47
  const results = response.data.data?.results || [];
48
+ const houseNumberFirst = COUNTRY_MAP[countryCode].houseNumberFirst;
49
+
48
50
  const formattedSuggestions = results.map(result => {
49
- const parts = [
50
- result.hn_num,
51
- result.street,
52
- result.city,
53
- result.state,
54
- result.zipcode
55
- ].filter(Boolean);
51
+ const houseNumber = result.hn_num;
52
+ const street = result.street;
53
+
54
+ // Build address parts based on country format
55
+ const addressParts = [];
56
+
57
+ if (houseNumberFirst) {
58
+ // Format: "123 Main St, City, State Zipcode"
59
+ if (houseNumber) addressParts.push(houseNumber);
60
+ if (street) addressParts.push(street);
61
+ } else {
62
+ // Format: "Main St 123, City, State Zipcode"
63
+ if (street) addressParts.push(street);
64
+ if (houseNumber) addressParts.push(houseNumber);
65
+ }
66
+
67
+ if (result.city) addressParts.push(result.city);
68
+ if (result.state) addressParts.push(result.state);
69
+ if (result.zipcode) addressParts.push(result.zipcode);
56
70
 
57
71
  return {
58
72
  ...result,
59
- displayText: parts.join(' ')
73
+ displayText: addressParts.join(' ')
60
74
  };
61
75
  });
62
76
 
@@ -23,7 +23,7 @@ const useEgonNormalize = (address, countryCode) => {
23
23
  const normalizeAddress = async () => {
24
24
  try {
25
25
  const iso3 = COUNTRY_MAP[countryCode].iso3;
26
-
26
+
27
27
  // Build address object with all available fields from suggestion
28
28
  const addressData = {};
29
29
  const fieldMap = {
@@ -63,7 +63,7 @@ const useEgonNormalize = (address, countryCode) => {
63
63
  const hnExpValue = address.hn_exp || '';
64
64
  addressData.hn = hnExpValue ? `${hnValue}/${hnExpValue}` : hnValue;
65
65
  }
66
-
66
+
67
67
  const startTime = performance.now();
68
68
  const response = await axios.post(
69
69
  'https://egonapis.egoncloud.com:1257/Egon/api/norm',