Registry / http-networking / smartystreets-javascript-sdk-utils

smartystreets-javascript-sdk-utils

JSON →
library1.2.9jsnpmunverified

This library provides utility functions to perform additional analysis on responses from the SmartyStreets US Street API, specifically for lookups validated through the `smartystreets-javascript-sdk`. It offers functions like `isValid()`, `isInvalid()`, `isAmbiguous()`, and `isMissingSecondary()` to interpret the deliverability and clarity of address lookups based on USPS standards. The current stable version is 1.2.9. As per Smarty's disclaimer, this software is provided 'as is' and 'as a gift,' implying an infrequent or demand-driven release cadence and limited official support, differentiating it from commercially maintained libraries. It serves as an auxiliary package to enhance the core SmartyStreets JavaScript SDK functionality rather than a standalone solution.

npm install smartystreets-javascript-sdk-utils
INSTALL
IMPORT
SIG · SMARTYSTREETS-JAVA
S
smartystreets-javascript-sdk-utils
http-networkingjavascriptv1.2.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

utils
import * as utils from 'smartystreets-javascript-sdk-utils';
const utils = require('smartystreets-javascript-sdk-utils');
The README example uses CommonJS `require`, but for modern Node.js and browser environments, ESM `import * as utils` is preferred for named exports.
isValid
import { isValid } from 'smartystreets-javascript-sdk-utils';
import isValid from 'smartystreets-javascript-sdk-utils';
Functions like `isValid`, `isInvalid`, etc., are named exports from the utility package. The `utils` object contains these as properties if imported as `* as utils`.
isAmbiguous
import { isAmbiguous } from 'smartystreets-javascript-sdk-utils';
const { isAmbiguous } = require('smartystreets-javascript-sdk-utils');
Direct destructuring from CommonJS `require` is common, but named imports are the modern standard for modularity.

This example demonstrates how to integrate `smartystreets-javascript-sdk-utils` with the main SmartyStreets SDK to perform address validation and then analyze the response using the utility functions like `isValid`, `isInvalid`, `isAmbiguous`, and `isMissingSecondary`. It covers authentication setup, creating a lookup, sending it via the client, and then interpreting the results programmatically using the utility library.

import * as SmartySDK from 'smartystreets-javascript-sdk'; import * as SmartyUtils from 'smartystreets-javascript-sdk-utils'; const SmartyCore = SmartySDK.core; const Lookup = SmartySDK.usStreet.Lookup; // Use environment variables for credentials const authId = process.env.SMARTY_AUTH_ID ?? 'YOUR_SMARTY_AUTH_ID'; const authToken = process.env.SMARTY_AUTH_TOKEN ?? 'YOUR_SMARTY_AUTH_TOKEN'; if (authId === 'YOUR_SMARTY_AUTH_ID' || authToken === 'YOUR_SMARTY_AUTH_TOKEN') { console.warn('Please set SMARTY_AUTH_ID and SMARTY_AUTH_TOKEN environment variables or replace placeholders.'); } let clientBuilder = new SmartyCore.ClientBuilder(new SmartyCore.StaticCredentials(authId, authToken)); let client = clientBuilder.buildUsStreetApiClient(); let lookup1 = new Lookup(); lookup1.street = "1600 Pennsylvania Ave NW"; lookup1.city = "Washington"; lookup1.state = "DC"; client.send(lookup1) .then(handleSuccess) .catch(handleError); function handleSuccess(response) { response.lookups.map(lookup => console.log('Result for ' + lookup.inputString + ':', lookup.result)); // Demonstrate utility functions for the first lookup in the response if (response.lookups.length > 0) { const firstLookupResult = response.lookups[0]; console.log(`Is '${firstLookupResult.inputString}' valid (mail deliverable)?`, SmartyUtils.isValid(firstLookupResult)); console.log(`Is '${firstLookupResult.inputString}' invalid (not mail deliverable)?`, SmartyUtils.isInvalid(firstLookupResult)); console.log(`Is '${firstLookupResult.inputString}' ambiguous (multiple candidates)?`, SmartyUtils.isAmbiguous(firstLookupResult)); console.log(`Is '${firstLookupResult.inputString}' missing a secondary address?`, SmartyUtils.isMissingSecondary(firstLookupResult)); } } function handleError(error) { console.error("Error sending lookup:", error); }
Debug
Known issues
gotchaThe SmartyStreets JavaScript SDK Utils package is provided 'AS IS' and 'as a gift.' This means that while enhancement requests may be considered, there is no guarantee of official support, bug fixes, or new features. Users should be aware of this limited maintenance model.
fix
Plan for potential self-maintenance or be prepared for the library's functionality to remain static.
affects: >=1.0.0
gotchaThis utility library is specifically designed to work with lookup objects returned by the `smartystreets-javascript-sdk`. Passing objects from other sources or incorrectly structured lookup objects will lead to undefined behavior or incorrect results.
fix
Always ensure the input to utility functions like `isValid()` is a `US Street Lookup` object that has been processed by the `smartystreets-javascript-sdk`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'result')
The utility functions (e.g., `isValid`, `isAmbiguous`) expect a `lookup` object that has successfully been processed by the SmartyStreets SDK and contains a `result` property, which might be `undefined` if the API call failed or the lookup itself was malformed.
fix
Ensure that the `lookup` object passed to the utility functions is valid and populated from a successful API response. Add error handling for the `client.send()` promise to catch failures before attempting to use the utilities.
ReferenceError: require is not defined
This error occurs when attempting to use CommonJS `require()` syntax in an environment configured for ES Modules (ESM), such as a modern Node.js project with `"type": "module"` in `package.json` or in a browser context without a transpiler.
fix
Switch to ES Module `import` syntax. For example, change `const utils = require("smartystreets-javascript-sdk-utils");` to `import * as utils from "smartystreets-javascript-sdk-utils";` or `import { isValid } from "smartystreets-javascript-sdk-utils";`.
Upgrade
Version history
1.2.9latest on npm
Audit
Dependencies
smartystreets-javascript-sdkrequiredThis package analyzes lookup objects generated and validated by the main SmartyStreets JavaScript SDK. It cannot function independently.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
smartystreets-javascript-sdk-utils — npm install smartystreets-javascript-sdk-utils · libregistry