Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smartystreets-javascript-sdk

Package Overview
Dependencies
Maintainers
7
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smartystreets-javascript-sdk - npm Package Compare versions

Comparing version 2.2.1 to 3.0.0

33

examples/us_autocomplete_pro.js

@@ -6,9 +6,9 @@ const SmartySDK = require("smartystreets-javascript-sdk");

// for Server-to-server requests, use this code:
let authId = "f0fd813a-2c37-2afe-a322-1a46794d6c91";
let authToken = "sPDMxTLaMh8BCp6YWSNW";
const credentials = new SmartyCore.StaticCredentials(authId, authToken);
// let authId = process.env.SMARTY_AUTH_ID;
// let authToken = process.env.SMARTY_AUTH_TOKEN;
// const credentials = new SmartyCore.StaticCredentials(authId, authToken);
// for client-side requests (browser/mobile), use this code:
// let key = process.env.SMARTY_EMBEDDED_KEY;
// const credentials = new SmartyCore.SharedCredentials(key);
let key = process.env.SMARTY_EMBEDDED_KEY;
const credentials = new SmartyCore.SharedCredentials(key);

@@ -27,8 +27,23 @@ // The appropriate license values to be used for your subscriptions

let lookup = new Lookup("4770 Lincoln");
lookup.excludeStates = ["CA"];
(async () => {
await handleRequest(lookup, "Simple Lookup");
})()
await handleRequest(lookup, "Simple Lookup");
// *** Using Filter and Prefer ***
lookup = new Lookup("4770 Lincoln");
lookup.maxResults = 10;
lookup.includeOnlyCities = ["Chicago,La Grange,IL", "Blaine,WA"];
lookup.preferStates = ["IL"];
lookup.preferRatio = 33;
lookup.source = "all";
await handleRequest(lookup, "Using Filter and Prefer");
// *** Using 'selected' to Expand Secondaries ***
lookup = new Lookup("4770 Lincoln");
lookup.selected = "4770 N Lincoln Ave Ste 2 (3) Chicago, IL 60625";
await handleRequest(lookup, "Using 'selected' to Expand Secondaries")
// ************************************************

@@ -35,0 +50,0 @@

{
"name": "smartystreets-javascript-sdk",
"version": "2.2.1",
"version": "3.0.0",
"description": "Quick and easy Smarty address validation.",

@@ -5,0 +5,0 @@ "keywords": [

class SmartyError extends Error {
constructor(message = "unexpected error") {
super(message);
}
}
class DefaultError extends SmartyError {
constructor(message) {
super(message);
}
}

@@ -91,3 +98,4 @@

ServiceUnavailableError: ServiceUnavailableError,
GatewayTimeoutError: GatewayTimeoutError
GatewayTimeoutError: GatewayTimeoutError,
DefaultError: DefaultError
};

@@ -14,26 +14,2 @@ const Errors = require("./Errors");

switch (error.statusCode) {
case 400:
error.error = new Errors.BadRequestError();
break;
case 401:
error.error = new Errors.BadCredentialsError();
break;
case 402:
error.error = new Errors.PaymentRequiredError();
break;
case 413:
error.error = new Errors.RequestEntityTooLargeError();
break;
case 422:
error.error = new Errors.UnprocessableEntityError("GET request lacked required fields.");
break;
case 429:
error.error = new Errors.TooManyRequestsError();
break;
case 500:

@@ -50,4 +26,6 @@ error.error = new Errors.InternalServerError();

break;
default:
error.error = new Errors.DefaultError(error && error.payload && error.payload.errors[0] && error.payload.errors[0].message);
}
reject(error);

@@ -54,0 +32,0 @@ });

@@ -26,31 +26,20 @@ const chai = require("chai");

it("gives a Bad Credentials error on a 401.", function () {
return expectedErrorForStatusCode(errors.BadCredentialsError, 401);
});
it("gives a custom message for 400", function () {
const payload = {
errors: [
{message: "custom message"}
]
};
return expectedErrorWithPayloadMessage(400, payload);
})
it("gives a Payment Required error on a 402.", function () {
return expectedErrorForStatusCode(errors.PaymentRequiredError, 402);
});
it("returns an error message if payload is undefined", function () {
return expectedDefaultError()
})
it("gives a Request Entity Too Large error on a 413.", function () {
return expectedErrorForStatusCode(errors.RequestEntityTooLargeError, 413);
});
it("gives a Bad Request error on a 400.", function () {
return expectedErrorForStatusCode(errors.BadRequestError, 400);
});
it("gives an Unprocessable Entity error on a 422.", function () {
return expectedErrorForStatusCode(errors.UnprocessableEntityError, 422);
});
it("gives a Too Many Requests error on a 429.", function () {
return expectedErrorForStatusCode(errors.TooManyRequestsError, 429);
});
it("gives an Internal Server Error error on a 500.", function () {
it("gives an Internal Server Error on a 500.", function () {
return expectedErrorForStatusCode(errors.InternalServerError, 500);
});
it("gives an Service Unvailable error on a 503.", function () {
it("gives an Service Unavailable error on a 503.", function () {
return expectedErrorForStatusCode(errors.ServiceUnavailableError, 503);

@@ -64,2 +53,26 @@ });

const expectedErrorWithPayloadMessage = (errorCode, payload) => {
let mockSender = generateMockSender(errorCode, payload);
let statusCodeSender = new StatusCodeSender(mockSender);
let request = new Request();
return statusCodeSender.send(request).then(() => {
}, error => {
expect(error.error).to.be.an.instanceOf(errors.DefaultError);
expect(error.error.message).to.be.equal(payload.errors[0].message);
})
}
const expectedDefaultError = () => {
let mockSender = generateMockSender(400);
let statusCodeSender = new StatusCodeSender(mockSender);
let request = new Request();
return statusCodeSender.send(request).then(() => {
}, error => {
expect(error.error).to.be.an.instanceOf(errors.DefaultError);
expect(error.error.message).to.be.equal("unexpected error");
})
}
function expectedErrorForStatusCode(expectedError, errorCode) {

@@ -70,3 +83,3 @@ let mockSender = generateMockSender(errorCode);

return statusCodeSender.send(request).then(response => {
return statusCodeSender.send(request).then(() => {
}, error => {

@@ -77,7 +90,7 @@ expect(error.error).to.be.an.instanceOf(expectedError);

function generateMockSender(errorCode) {
function generateMockSender(errorCode, payload) {
return {
send: () => {
return new Promise((resolve, reject) => {
reject(new Response(errorCode))
reject(new Response(errorCode, payload))
});

@@ -84,0 +97,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc