1
- const SmartySDK = require ( "../dist/cjs/index.cjs " ) ;
1
+ const SmartySDK = require ( "smartystreets-javascript-sdk " ) ;
2
2
const SmartyCore = SmartySDK . core ;
3
3
const Lookup = SmartySDK . usStreet . Lookup ;
4
4
@@ -8,8 +8,7 @@ const Lookup = SmartySDK.usStreet.Lookup;
8
8
// const credentials = new SmartyCore.StaticCredentials(authId, authToken);
9
9
10
10
// for client-side requests (browser/mobile), use this code:
11
- // Note: key must be a string
12
- let key = "your key" ;
11
+ let key = process . env . SMARTY_EMBEDDED_KEY ;
13
12
const credentials = new SmartyCore . SharedCredentials ( key ) ;
14
13
15
14
// The appropriate license values to be used for your subscriptions
@@ -24,17 +23,37 @@ let client = clientBuilder.buildUsStreetApiClient();
24
23
// https://www.smarty.com/docs/us-street-api#input-fields
25
24
26
25
let lookup1 = new Lookup ( ) ;
27
- lookup1 . street = "805 Tye Crossing Ct" ;
28
- lookup1 . city = "Burleson" ;
29
- lookup1 . state = "TX" ;
30
- lookup1 . zipCode = "76028" ;
31
- lookup1 . candidates = 10 ;
32
- lookup1 . match = "enhanced" ;
33
- // lookup1.countySource = "geographic";
34
-
35
- ( async ( ) => {
36
- await handleResponse ( lookup1 ) ;
37
- } ) ( ) ;
26
+ lookup1 . inputId = "24601" ; // Optional ID from your system
27
+ lookup1 . addressee = "John Doe" ;
28
+ lookup1 . street = "330 N 100 W" ;
29
+ lookup1 . street2 = "closet under the stairs" ;
30
+ lookup1 . secondary = "APT 2" ;
31
+ lookup1 . urbanization = "" ; // Only applies to Puerto Rico addresses
32
+ lookup1 . city = "Provo" ;
33
+ lookup1 . state = "Utah" ;
34
+ lookup1 . zipCode = "84601" ;
35
+ lookup1 . maxCandidates = 3 ;
36
+ lookup1 . match = "invalid" ; // "invalid" is the most permissive match,
37
+ // this will always return at least one result even if the address is invalid.
38
+ // Refer to the documentation for additional MatchStrategy options.
39
+
40
+ let lookup2 = new Lookup ( ) ;
41
+ lookup2 . street = "1600 Amphitheater Pkwy" ;
42
+ lookup2 . lastLine = "Mountainview, CA" ;
43
+ lookup2 . maxCandidates = 5 ;
44
+
45
+ let lookup3 = new Lookup ( ) ;
46
+ lookup3 . inputId = "8675309" ;
47
+ lookup3 . street = "1600 Amphitheatre Parkway Mountain View, CA 94043" ;
48
+ lookup3 . maxCandidates = 1 ;
49
+
50
+ // NOTE: batches are not supported when using SharedCredentials.
51
+ let batch = new SmartyCore . Batch ( ) ;
52
+ batch . add ( lookup1 ) ;
53
+ batch . add ( lookup2 ) ;
54
+ batch . add ( lookup3 ) ;
55
+
56
+ await handleResponse ( batch ) ;
38
57
39
58
function handleSuccess ( response ) {
40
59
response . lookups . map ( lookup => console . log ( lookup . result ) ) ;
0 commit comments