usps-webtools-promise
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -179,3 +179,3 @@ import USPSError from "./error"; | ||
} | ||
export interface Address { | ||
export interface AddressRequest { | ||
firm_name?: string; | ||
@@ -190,7 +190,18 @@ street1?: string; | ||
} | ||
export interface AddressResponse { | ||
firm_name?: string; | ||
street1?: string; | ||
street2?: string; | ||
city?: string; | ||
state?: string; | ||
zip?: string; | ||
Zip4?: string; | ||
Zip5?: string; | ||
urbanization?: string; | ||
} | ||
export default class { | ||
#private; | ||
constructor(config: Config); | ||
verify(address: Address): Promise<Address | USPSError>; | ||
zipCodeLookup(address: Address): Promise<USPSError | Address>; | ||
verify(address: AddressRequest): Promise<AddressResponse | USPSError>; | ||
zipCodeLookup(address: AddressRequest): Promise<USPSError | AddressResponse>; | ||
pricingRateV4(pricingRate: PricingRateInput): Promise<USPSError | { | ||
@@ -221,3 +232,3 @@ CLASSID?: string | undefined; | ||
}>; | ||
cityStateLookup(zip: string): Promise<USPSError | Address>; | ||
cityStateLookup(zip: string): Promise<USPSError | AddressResponse>; | ||
} |
@@ -78,5 +78,25 @@ "use strict"; | ||
State: "state", | ||
Zip5: "zip", | ||
FirmName: 'firm_name', | ||
Address2Abbreviation: 'address2_abbreviation', | ||
CityAbbreviation: 'city_abbreviation', | ||
Urbanization: 'urbanization', | ||
DeliveryPoint: 'delivery_point', | ||
CarrierRoute: 'carrier_route', | ||
Footnotes: 'footnotes', | ||
DPVConfirmation: 'dpv_confirmation', | ||
DPVCMRA: 'dpvcmra', | ||
DPVFalse: 'dpv_false', | ||
DPVFootnotes: 'dpv_footnotes', | ||
Business: 'business', | ||
CentralDeliveryPoint: 'central_delivery_point', | ||
Vacant: 'vacant' | ||
}; | ||
const newAddress = renameKeys(keysMap, Address); | ||
if (typeof newAddress.Zip4 === "object") { | ||
newAddress.Zip4 = ""; | ||
newAddress.zip = newAddress.Zip5; | ||
} | ||
else { | ||
newAddress.zip = `${newAddress.Zip5}-${newAddress.Zip4}`; | ||
} | ||
if (propercase) { | ||
@@ -83,0 +103,0 @@ newAddress.street1 = proper_case_1.default(newAddress.street1 ? newAddress.street1 : ""); |
@@ -5,3 +5,3 @@ { | ||
"description": "API wrapper for the USPS Web-Tools, with Promises!", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"main": "./dist/usps.js", | ||
@@ -43,9 +43,9 @@ "types": "./dist/usps.d.ts", | ||
"@types/lodash.merge": "^4.6.6", | ||
"@types/node": "^13.11.1", | ||
"@typescript-eslint/eslint-plugin": "^2.28.0", | ||
"@typescript-eslint/parser": "^2.28.0", | ||
"ava": "^3.7.0", | ||
"@types/node": "^13.13.2", | ||
"@typescript-eslint/eslint-plugin": "^2.29.0", | ||
"@typescript-eslint/parser": "^2.29.0", | ||
"ava": "^3.7.1", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-config-unicorn": "^0.5.0", | ||
@@ -58,3 +58,3 @@ "eslint-import-resolver-typescript": "^2.0.0", | ||
"nyc": "^15.0.1", | ||
"prettier": "^2.0.4", | ||
"prettier": "^2.0.5", | ||
"typescript": "^3.8.3" | ||
@@ -61,0 +61,0 @@ }, |
### About: | ||
This package was forked from [MadisonReed/usps-webtools](https://github.com/MadisonReed/usps-webtools), but it has been modernized with Typescript and Promises (async/await). Note: The output differs between this package and MadisonReed/usps-webtools. | ||
This package was forked from [MadisonReed/usps-webtools](https://github.com/MadisonReed/usps-webtools), but it has been modernized with Typescript and Promises (async/await). Note: This is a drop-in replacement for MadisonReed/usps-webtools, it produces the same output. | ||
@@ -19,2 +19,4 @@ ### Installation: | ||
const USPS = require('usps-webtools-promise').default; | ||
// or | ||
import USPS from "usps-webtools-promise"; | ||
@@ -24,3 +26,3 @@ const usps = new USPS({ | ||
userId: 'USPS User id', | ||
// USPS returns ALL CAPS, this boolean turns on Proper Caps for both Address lines and City. This is an optional item. | ||
// USPS returns ALL CAPS, this boolean turns on Proper Caps for both Street lines and City. This is an optional item. | ||
properCase: boolean | ||
@@ -27,0 +29,0 @@ }); |
@@ -198,3 +198,3 @@ import { RequestOptions } from "https"; | ||
export interface Address { | ||
export interface AddressRequest { | ||
firm_name?: string; | ||
@@ -210,2 +210,14 @@ street1?: string; | ||
export interface AddressResponse { | ||
firm_name?: string; | ||
street1?: string; | ||
street2?: string; | ||
city?: string; | ||
state?: string; | ||
zip?: string; | ||
Zip4?: string; | ||
Zip5?: string; | ||
urbanization?: string; | ||
} | ||
/** | ||
@@ -299,3 +311,3 @@ Method to call USPS | ||
const renameKeys = (keysMap: any, object: any): Address => | ||
const renameKeys = (keysMap: any, object: any): AddressResponse => | ||
Object.keys(object).reduce( | ||
@@ -319,3 +331,3 @@ (accumulator, key) => ({ | ||
propercase: boolean | ||
): Address => { | ||
): AddressResponse => { | ||
const keysMap = { | ||
@@ -326,6 +338,28 @@ Address1: "street2", | ||
State: "state", | ||
Zip5: "zip", | ||
FirmName: "firm_name", | ||
Address2Abbreviation: "address2_abbreviation", | ||
CityAbbreviation: "city_abbreviation", | ||
Urbanization: "urbanization", | ||
DeliveryPoint: "delivery_point", | ||
CarrierRoute: "carrier_route", | ||
Footnotes: "footnotes", | ||
DPVConfirmation: "dpv_confirmation", | ||
DPVCMRA: "dpvcmra", | ||
DPVFalse: "dpv_false", | ||
DPVFootnotes: "dpv_footnotes", | ||
Business: "business", | ||
CentralDeliveryPoint: "central_delivery_point", | ||
Vacant: "vacant", | ||
}; | ||
const newAddress: Address = renameKeys(keysMap, Address); | ||
const newAddress: AddressResponse = renameKeys(keysMap, Address); | ||
if (typeof newAddress.Zip4 === "object") { | ||
// If Zip4 is not found, USPS returns a {}, change it to a blank string | ||
newAddress.Zip4 = ""; | ||
newAddress.zip = newAddress.Zip5; | ||
} else { | ||
// Combine the zip5 and zip4 into zip | ||
newAddress.zip = `${newAddress.Zip5}-${newAddress.Zip4}`; | ||
} | ||
if (propercase) { | ||
@@ -366,3 +400,3 @@ newAddress.street1 = properCase( | ||
*/ | ||
async verify(address: Address): Promise<Address | USPSError> { | ||
async verify(address: AddressRequest): Promise<AddressResponse | USPSError> { | ||
const parameters: AddressValidateRequest = { | ||
@@ -411,3 +445,3 @@ Revision: 1, | ||
*/ | ||
async zipCodeLookup(address: Address) { | ||
async zipCodeLookup(address: AddressRequest) { | ||
const parameters: ZipCodeLookupRequest = { | ||
@@ -414,0 +448,0 @@ Address: { |
45976
1355
81