forked from flexbase-eng/postgrid-node-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddress-verification.ts
More file actions
550 lines (458 loc) · 12.6 KB
/
address-verification.ts
File metadata and controls
550 lines (458 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import * as AddressVerificationAPI from './address-verification';
import { APIPromise } from '../core/api-promise';
import { RequestOptions } from '../internal/request-options';
/**
* Standard Address Verification API.
*
* Provides endpoints to verify and standardize addresses across US and Canada,
* supporting both structured and freeform inputs.
*
* Note that this uses a different set of lookups than our international API.
*/
export class AddressVerification extends APIResource {
/**
* 1. **Structured Address** — Verify and standardize a structured address (e.g.,
* with `line1`, `city`, etc.).
* 2. **Freeform Address** — Verify and standardize a freeform address written on
* one line. For best results, append the ISO 2-letter country code (e.g., `US`,
* `CA`) to the end of the line.
*
* - Specifying `includeDetails=true` will provide additional output as documented
* in the `Details` schema.
* - Uses 1 lookup for verification, and 1 more if geocoding (unless your contract
* says otherwise).
*
* @example
* ```ts
* const response = await client.addressVerification.verify({
* address: '1234 Elm St, Los Angeles, CA 90001, US',
* });
* ```
*/
verify(
params: AddressVerificationVerifyParams,
options?: RequestOptions,
): APIPromise<AddressVerificationVerifyResponse> {
const { geocode, includeDetails, properCase, ...body } = params;
return this._client.post('/v1/addver/verifications', {
query: { geocode, includeDetails, properCase },
body,
...options,
});
}
}
/**
* Errors encountered during address verification.
*/
export interface Errors {
/**
* Errors related to the city.
*/
city?: Array<string>;
/**
* Generic errors not tied to a specific field.
*/
generic?: Array<string>;
/**
* Errors related to the first address line.
*/
line1?: Array<string>;
/**
* Errors related to the second address line.
*/
line2?: Array<string>;
/**
* Errors related to the province or state.
*/
provinceOrState?: Array<string>;
}
/**
* The verification status of an address.
*/
export type Status = 'verified' | 'corrected' | 'failed';
export interface AddressVerificationVerifyResponse {
data: AddressVerificationVerifyResponse.Data;
message: string;
status: 'success' | 'error';
}
export namespace AddressVerificationVerifyResponse {
export interface Data {
/**
* The city name of the address.
*/
city: string;
/**
* The country code of the address.
*/
country: string;
/**
* The first line of the address.
*/
line1: string;
/**
* The postal code or ZIP code of the address.
*/
postalOrZip: string;
/**
* The province or state of the address.
*/
provinceOrState: string;
/**
* The country name of the address.
*/
countryName?: string;
/**
* If you supply `includeDetails=true` as a query parameter, we will also populate
* an additional `details` field that follows the
* [Address Details](https://avdocs.postgrid.com/#address-details) schema.
*/
details?: Data.Details;
/**
* Errors encountered during address verification.
*/
errors?: AddressVerificationAPI.Errors;
/**
* The firm name of the address.
*/
firmName?: string;
/**
* If the `geocode=true` query parameter is supplied, the response will include a
* geocodeResult which follows the
* [Geocoding](https://avdocs.postgrid.com/#geocoding) schema. You can request this
* feature be enabled by emailing `support@postgrid.com`. This includes our
* verification, batch verification, suggestions, and POST /completions endpoint.
* Note that you must supply country when geocoding to get the result successfully.
*/
geocodeResult?: Data.GeocodeResult;
/**
* The second line of the address.
*/
line2?: string;
/**
* The verification status of an address.
*/
status?: AddressVerificationAPI.Status;
/**
* The zip plus 4 code of the address.
*/
zipPlus4?: string;
}
export namespace Data {
/**
* If you supply `includeDetails=true` as a query parameter, we will also populate
* an additional `details` field that follows the
* [Address Details](https://avdocs.postgrid.com/#address-details) schema.
*/
export interface Details {
/**
* PO Box ID
*/
boxID?: string;
/**
* County in the United States (US address only)
*/
county?: string;
/**
* FIPS code for county (US address only)
*/
countyNum?: string;
/**
* Delivery installation area name
*/
deliveryInstallationAreaName?: string;
/**
* Delivery installation qualifier
*/
deliveryInstallationQualifier?: string;
/**
* Delivery installation type
*/
deliveryInstallationType?: string;
/**
* Any extra information relevant to the address
*/
extraInfo?: string;
/**
* The post-direction of the street (after the street name, US addresses only)
*/
postDirection?: string;
/**
* The pre-direction of the street (before the street name, US addresses only)
*/
preDirection?: string;
/**
* Indicates that the address is residential (US address only)
*/
residential?: boolean;
/**
* Rural route number
*/
ruralRouteNumber?: string;
/**
* Rural route type
*/
ruralRouteType?: string;
/**
* The direction of the street (N, S, E, W, etc)
*/
streetDirection?: string;
/**
* Name of the street where the address is located
*/
streetName?: string;
/**
* Street number (e.g. the 20 in 20 Bay St)
*/
streetNumber?: string;
/**
* Type of the street (DR, ST, BLVD, etc)
*/
streetType?: string;
/**
* The unit number/name
*/
suiteID?: string;
/**
* The suite key
*/
suiteKey?: string;
/**
* US Census block number
*/
usCensusBlockNumber?: string;
/**
* US Census consolidated metropolitan statistical area
*/
usCensusCMSA?: string;
/**
* US Census metropolitan area
*/
usCensusMA?: string;
/**
* US Census metropolitan statistical area
*/
usCensusMSA?: string;
/**
* US Census primary metropolitan statistical area
*/
usCensusPMSA?: string;
/**
* US Census tract number
*/
usCensusTractNumber?: string;
/**
* US congressional district number
*/
usCongressionalDistrictNumber?: string;
/**
* True if address location recognizes DST
*/
usHasDaylightSavings?: boolean;
/**
* PostNet barcode digit
*/
usMailingCheckDigit?: string;
/**
* 4-character code assigned to mail delivery route within a 5 digit zip code
*/
usMailingsCarrierRoute?: string;
/**
* True if US address matches a high-rise default or rural route default in the
* USPS data
*/
usMailingsDefaultFlag?: boolean;
/**
* Unique USPS identifier for the delivery point
*/
usMailingsDeliveryPoint?: string;
/**
* See [USPS DPV](https://avdocs.postgrid.com/#usps-dpv)
*/
usMailingsDpvConfirmationIndicator?: string;
/**
* Y if this is a commercial mail receiving agency, N otherwise
*/
usMailingsDpvCrmaIndicator?: string;
/**
* See [USPS DPV](https://avdocs.postgrid.com/#usps-dpv)
*/
usMailingsDpvFootnote1?: string;
/**
* See [USPS DPV](https://avdocs.postgrid.com/#usps-dpv)
*/
usMailingsDpvFootnote2?: string;
/**
* See [USPS DPV](https://avdocs.postgrid.com/#usps-dpv)
*/
usMailingsDpvFootnote3?: string;
/**
* A for ascending, D for descending
*/
usMailingsElotAscDesc?: string;
/**
* eLOT sequence number
*/
usMailingsElotSequenceNumber?: string;
/**
* Y if address is in early warning system database
*/
usMailingsEWSFlag?: string;
/**
* Y if address converted by LACS
*/
usMailingsLACSFlag?: string;
/**
* Corresponds to USPS LACSLink return code
*/
usMailingsLACSReturnCode?: string;
/**
* See [USPS DPV](https://avdocs.postgrid.com/#usps-dpv)
*/
usMailingsRecordTypeCode?: string;
/**
* See [USPS DPV](https://avdocs.postgrid.com/#usps-dpv)
*/
usMailingsSuiteLinkReturnCode?: string;
/**
* Lower legislative district for the US address
*/
usStateLegislativeLower?: string;
/**
* Upper legislative district for the US address
*/
usStateLegislativeUpper?: string;
/**
* Time zone for the US address area
*/
usTimeZone?: string;
/**
* Indicates that the address is vacant according to the USPS (US address only)
*/
vacant?: boolean;
}
/**
* If the `geocode=true` query parameter is supplied, the response will include a
* geocodeResult which follows the
* [Geocoding](https://avdocs.postgrid.com/#geocoding) schema. You can request this
* feature be enabled by emailing `support@postgrid.com`. This includes our
* verification, batch verification, suggestions, and POST /completions endpoint.
* Note that you must supply country when geocoding to get the result successfully.
*/
export interface GeocodeResult {
/**
* A real number from 0.00 to 1.00 which represents an
* [accuracy score](https://avdocs.postgrid.com/#accuracy-score)
*/
accuracy: number;
/**
* A string representing the
* [accuracy type](https://avdocs.postgrid.com/#accuracy-type)
*/
accuracyType:
| 'rooftop'
| 'point'
| 'range_interpolation'
| 'nearest_rooftop_match'
| 'intersection'
| 'street_center'
| 'place'
| 'state';
/**
* Object that contains `lat`, `lng` properties with number values
*/
location: GeocodeResult.Location;
}
export namespace GeocodeResult {
/**
* Object that contains `lat`, `lng` properties with number values
*/
export interface Location {
lat: number;
lng: number;
}
}
}
}
export type AddressVerificationVerifyParams =
| AddressVerificationVerifyParams.StandardFreeformAddressInput
| AddressVerificationVerifyParams.StandardStructuredAddressInput;
export declare namespace AddressVerificationVerifyParams {
export interface StandardFreeformAddressInput {
/**
* Body param: The address you want to verify, written on a single line.
*/
address: string;
/**
* Query param
*/
geocode?: boolean;
/**
* Query param
*/
includeDetails?: boolean;
/**
* Query param
*/
properCase?: boolean;
}
export interface StandardStructuredAddressInput {
/**
* Body param
*/
address: StandardStructuredAddressInput.Address;
/**
* Query param
*/
geocode?: boolean;
/**
* Query param
*/
includeDetails?: boolean;
/**
* Query param
*/
properCase?: boolean;
}
export namespace StandardStructuredAddressInput {
export interface Address {
/**
* The city of the address.
*/
city: string;
/**
* The country of your address, one of `ca` or `us`.
*/
country: 'ca' | 'us';
/**
* The first line of the address.
*/
line1: string;
/**
* The postal code or ZIP code of the address.
*/
postalOrZip: string;
/**
* The province or state of the address.
*/
provinceOrState: string;
/**
* The second line of the address.
*/
line2?: string;
/**
* The optional firm/recipient name.
*/
recipient?: string;
}
}
}
export declare namespace AddressVerification {
export {
type Errors as Errors,
type Status as Status,
type AddressVerificationVerifyResponse as AddressVerificationVerifyResponse,
type AddressVerificationVerifyParams as AddressVerificationVerifyParams,
};
}