smartystreets-javascript-sdk 5.0.0 → 5.0.1

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/Makefile CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/make -f
2
2
 
3
- VERSION := $(shell tagit -M --dry-run)
3
+ VERSION := $(shell tagit -p --dry-run)
4
4
  VERSION_FILE1 := package.json
5
5
  VERSION_FILE2 := package-lock.json
6
6
 
@@ -11,7 +11,7 @@ node_modules:
11
11
  npm install
12
12
 
13
13
  publish: test version upload unversion
14
- tagit -M
14
+ tagit -p
15
15
  git push origin --tags
16
16
 
17
17
  upload:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartystreets-javascript-sdk",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Quick and easy Smarty address validation.",
5
5
  "keywords": [
6
6
  "smarty",
package/src/Request.js CHANGED
@@ -1,11 +1,9 @@
1
1
  class Request {
2
- constructor(payload) {
2
+ constructor(payload, headers = {"Content-Type": "application/json; charset=utf-8"}) {
3
3
  this.baseUrl = "";
4
4
  this.baseUrlParam = "";
5
5
  this.payload = payload;
6
- this.headers = {
7
- "Content-Type": "application/json; charset=utf-8",
8
- };
6
+ this.headers = headers;
9
7
 
10
8
  this.parameters = {};
11
9
  }
@@ -16,7 +16,7 @@ class Client {
16
16
  send(lookup) {
17
17
  if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
18
18
 
19
- let request = new Request(lookup.text);
19
+ let request = new Request(lookup.text, {"Content-Type": "text/plain; charset=utf-8"});
20
20
  request.parameters = buildInputData(lookup, keyTranslationFormat);
21
21
 
22
22
  return new Promise((resolve, reject) => {
@@ -0,0 +1,167 @@
1
+ const chai = require("chai");
2
+ const expect = chai.expect;
3
+ const SmartySDK = require("../index");
4
+
5
+ describe("Extract example test", () => {
6
+ const authId = "";
7
+ const authToken = "";
8
+ const SmartyCore = SmartySDK.core;
9
+ const credentials = new SmartyCore.StaticCredentials(authId, authToken);
10
+ const clientBuilder = new SmartyCore.ClientBuilder(credentials);
11
+ clientBuilder.withBaseUrl("https://us-extract.api.hobbes.smartyops.net");
12
+
13
+ const usExtractClient = clientBuilder.buildUsExtractClient();
14
+
15
+ it("Check multi-line test", async () => {
16
+ if (!(authId && authToken)) {
17
+ expect("bypass").to.equal("bypass");
18
+ } else {
19
+ const lookup = new SmartySDK.usExtract.Lookup(`
20
+ 1476 Sandhill Rd, Orem, UT asdlfkjasldfkja sldfj 350 E University Pkwy, Orem, UT 84058 asldfkjasldfj asldkfjasldfj
21
+ 417 W 1300 S, Orem, UT asdlfkjasldfkjal skdjf alskdjf 309 E University Pkwy, Orem, UT 84058
22
+ `);
23
+
24
+ lookup.addressesHaveLineBreaks = true;
25
+ lookup.addressesPerLine = 1;
26
+
27
+ const result = await usExtractClient.send(lookup);
28
+
29
+ expect(result.result.meta.addressCount).to.equal(2);
30
+ expect(result.result.meta.verifiedCount).to.equal(2);
31
+
32
+ }
33
+ });
34
+
35
+ it("Check HTML test", async () => {
36
+ if (!(authId && authToken)) {
37
+ expect("bypass").to.equal("bypass");
38
+ } else {
39
+ const lookup = new SmartySDK.usExtract.Lookup(`
40
+ HTML is automatically detected and, if found, ignored. You can override this behavior with API calls by manually setting the 'html' parameter to true or false.
41
+
42
+ For input with <b>HTML code</code> like this, addresses will be scraped from outside the tags. The HTML should be properly formatted, valid HTML.<br><br>
43
+
44
+ 7584<span class='street-name'>Big Canyon</span> Anaheim Hills, CA <span class='zip-code'>92808</span><br><br>
45
+
46
+ You can force HTML mode if auto-detect doesn't work properly.
47
+ `);
48
+
49
+ const result = await usExtractClient.send(lookup);
50
+
51
+ expect(result.result.meta.addressCount).to.equal(1);
52
+ }
53
+ });
54
+
55
+ it("Check addresses with line breaks", async () => {
56
+ if (!(authId && authToken)) {
57
+ expect("bypass").to.equal("bypass");
58
+ } else {
59
+ const lookup = new SmartySDK.usExtract.Lookup(`
60
+ This address is valid:
61
+
62
+ 1109 Ninth 85007
63
+
64
+ but this one is not:
65
+
66
+ 3777 Las Vegas Blvd
67
+ Las Vegas, Nevada
68
+
69
+ However, this nearby location is valid, despite the poor spelling:
70
+
71
+ 3785 Las Vegs Av.
72
+ Los Vegas, Nevada
73
+ `);
74
+
75
+ lookup.addressesHaveLineBreaks = true;
76
+
77
+ const result = await usExtractClient.send(lookup);
78
+
79
+ expect(result.result.meta.addressCount).to.equal(3);
80
+ expect(result.result.meta.verifiedCount).to.equal(2);
81
+ }
82
+ });
83
+
84
+ it("Check addresses needing aggressive mode", async () => {
85
+ if (!(authId && authToken)) {
86
+ expect("bypass").to.equal("bypass");
87
+ } else {
88
+ const lookup = new SmartySDK.usExtract.Lookup(`
89
+ With aggressive mode on, popular US cities may be matched if no state or ZIP code can be found.
90
+
91
+ This means addresses like 5455 North 250 West, Provo, can be found even though it doesn't have anything looking like a state or ZIP code following it.
92
+ `);
93
+
94
+ lookup.aggressive = true;
95
+
96
+ const result = await usExtractClient.send(lookup);
97
+
98
+ expect(result.result.meta.addressCount).to.equal(1);
99
+ expect(result.result.meta.verifiedCount).to.equal(1);
100
+ }
101
+ });
102
+
103
+ it("Check addresses in URLs", async () => {
104
+ if (!(authId && authToken)) {
105
+ expect("bypass").to.equal("bypass");
106
+ } else {
107
+ const lookup = new SmartySDK.usExtract.Lookup(`
108
+ Smarty can handle addresses in URLs, as long as there are no spaces in them or they are surrounded by quotes.
109
+
110
+ Address in one parameter: https://maps.google.com/?q=1+Rosedale+St+Baltimore+MD&ie=UTF8
111
+ or,
112
+ same URL with spaces surrounded by quotes: "https://maps.google.com/?q=1 Rosedale St Baltimore MD&ie=UTF8"
113
+ ...
114
+
115
+ Address across multiple parameters: https://example.com/?street=4004%20Grant%20St%20&state=WA&zipcode=98660&city=Vancouver
116
+ We can find them either way.
117
+ `);
118
+
119
+ const result = await usExtractClient.send(lookup);
120
+
121
+ expect(result.result.meta.addressCount).to.equal(3);
122
+ expect(result.result.meta.verifiedCount).to.equal(3);
123
+ }
124
+ });
125
+
126
+ it("Check address with unicode character", async () => {
127
+ if (!(authId && authToken)) {
128
+ expect("bypass").to.equal("bypass");
129
+ } else {
130
+ const lookup = new SmartySDK.usExtract.Lookup(`
131
+ This address has a Unicode character in it (the special í in María): 123 María Lane Tempe, AZ, 85284
132
+
133
+ Addresses with Unicode can still be found and verified.
134
+ `);
135
+
136
+ const result = await usExtractClient.send(lookup);
137
+
138
+ expect(result.result.meta.addressCount).to.equal(1);
139
+ expect(result.result.meta.verifiedCount).to.equal(1);
140
+ }
141
+ });
142
+
143
+ it("Check more addresses needing aggressive mode", async () => {
144
+ if (!(authId && authToken)) {
145
+ expect("bypass").to.equal("bypass");
146
+ } else {
147
+ const lookup = new SmartySDK.usExtract.Lookup(`
148
+ Try this one with and without aggressive mode. The '10379' looks like a ZIP code but is actually a primary number:
149
+
150
+ 8465 Park Meadows Center Drive
151
+ Lone Tree, CO
152
+ 303-799-3400
153
+
154
+ 10379 South State Street
155
+ Sandy, UT 84070
156
+ 801-432-5100
157
+
158
+ This input has two addresses and only one is found without aggressive mode.
159
+ `);
160
+
161
+ const result = await usExtractClient.send(lookup);
162
+
163
+ expect(result.result.meta.addressCount).to.equal(1);
164
+ expect(result.result.meta.verifiedCount).to.equal(1);
165
+ }
166
+ });
167
+ });