Skip to content

Commit

Permalink
Merge pull request EasyPost#88 from EasyPost/fix-superagent-auth
Browse files Browse the repository at this point in the history
Fix superagent auth
  • Loading branch information
ajacksified authored Nov 1, 2017
2 parents b2293d8 + ecb7e60 commit 13f9ae7
Show file tree
Hide file tree
Showing 17 changed files with 931 additions and 130 deletions.
13 changes: 10 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"presets": ["es2015", "es2017", "stage-2"],
"plugins": ["transform-class-properties"],
"presets": [
["env", {"targets": {"node": "current" }}],
"stage-2"
],
"plugins": [
"transform-class-properties",
"transform-es2015-classes",
],

"env": {
"test": {
"presets": ["es2015", "es2017", "stage-2"],
"presets": [["env", {"targets": {"node": "current" }}], "stage-2"],
"plugins": [
"transform-class-properties",
"transform-es2015-classes",
["istanbul", {
"exclude": [
"test/**/*"
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Use this file as a starting point for your project's .eslintrc.
// Copy this file, and add rule overrides as needed.
{
"extends": "airbnb/base",
"extends": "airbnb-base",
"parser": "babel-eslint",
"ecmaFeatures": {
"classes": true,
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ EasyPost is a simple shipping API. You can sign up for an account at https://eas
[![CircleCI](https://circleci.com/gh/EasyPost/easypost-web.svg?style=svg&circle-token=6f1cef70e775021a0e45c9c8bc367943927e9bba)](https://circleci.com/gh/EasyPost/easypost-web)

Installation
---------------
------------

```
npm install --save @easypost/api
Expand All @@ -28,10 +28,22 @@ const EasyPost = require('@easypost/api');
To test out the API, you can run `npm install -g @easypost/api` and run
`easypost`. you can also clone this repository, `npm install` to install
dependencies, `npm run build` to build the project, and run
`API_KEY=yourkey ./repl.js --local` to try out an interactive CLI.
`API_KEY=yourkey ./repl.js --local easypost.js` to try out an interactive CLI.
(Replace easypost.js with whatever compatabile version you wish, as defined
below.)

Compatability
-------------

By default, @easypost/api works with Node v6 LTS. To include for other versions
of node, you can use:

* `require('@easpost/api/easypost.8-lts.js')` (Node 8.9+
* `require('@easpost/api/easypost.6-lts.js')` (Node 6.9+)
* `require('@easpost/api/easypost.legacy.js')` (Node 0.10+)

Example
------------------
-------

```javascript
const apiKey = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi';
Expand Down
259 changes: 259 additions & 0 deletions easypost.6-lts.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions easypost.6-lts.js.map

Large diffs are not rendered by default.

259 changes: 259 additions & 0 deletions easypost.8-lts.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions easypost.8-lts.js.map

Large diffs are not rendered by default.

259 changes: 259 additions & 0 deletions easypost.legacy.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions easypost.legacy.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
require('regenerator-runtime/runtime');
module.exports = require('./easypost.js').default;
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@easypost/api",
"description": "EasyPost Node Client Library",
"version": "3.0.12",
"version": "3.1.0",
"author": "Easypost Engineering <[email protected]>",
"homepage": "https://easypost.com",
"bin": {
Expand All @@ -25,36 +25,36 @@
},
"dependencies": {
"babel-polyfill": "^6.23.0",
"proptypes": "^0.14.3",
"regenerator-runtime": "^0.10.1",
"source-map-support": "^0.4.6",
"superagent": "^3.5.2",
"yargs": "^7.1.0"
"proptypes": "^1.1.0",
"regenerator-runtime": "^0.11.0",
"source-map-support": "^0.5.0",
"superagent": "^3.8.0",
"yargs": "^10.0.3"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-eslint": "^8.0.1",
"babel-loader": "^7.0.0",
"babel-plugin-istanbul": "^4.1.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.2.0",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.24.1",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"cross-env": "^4.0.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^5.1.1",
"eslint": "^4.10.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-import-resolver-webpack": "^0.8.1",
"eslint-plugin-import": "^2.2.0",
"fast-async": "^6.3.0",
"json-loader": "^0.5.4",
"mocha": "^3.3.0",
"nyc": "^10.2.0",
"progress-bar-webpack-plugin": "^1.9.3",
"sinon": "^2.1.0",
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"sinon": "^4.0.2",
"sinon-chai": "^2.9.0",
"vows": "~0.8.1",
"webpack": "^2.4.1",
"webpack": "^3.8.1",
"webpack-node-externals": "^1.5.4"
}
}
2 changes: 1 addition & 1 deletion repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let API;

if (args.local) {
packageInfo = require('./package.json');
API = require('./index');
API = require('./' + args.local).default;
} else {
packageInfo = require('@easypost/api/package.json');
API = require('@easypost/api');
Expand Down
8 changes: 4 additions & 4 deletions src/easypost.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ export default class API {
} = params;

const req = this.agent[method](this.buildPath(path))
.accept('json')
.set('Content-Type', 'application/json')
.set(API.buildHeaders(headers))
.auth(`${this.key}:`);
.accept('json')
.set('Content-Type', 'application/json')
.set(API.buildHeaders(headers))
.auth(this.key);

if (body) { req.send(body); }

Expand Down
2 changes: 1 addition & 1 deletion src/resources/customsItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default api => (
}

constructor(data) {
let value = data.value;
let { value } = data;

if (value && typeof value !== 'string') {
value = value.toString();
Expand Down
2 changes: 1 addition & 1 deletion test/easypost.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('Base API object', () => {

it('sets auth', (done) => {
api.request('').then(() => {
expect(api.agent.getStub.auth).to.have.been.calledWith(`${key}:`);
expect(api.agent.getStub.auth).to.have.been.calledWith(key);
done();
});
});
Expand Down
3 changes: 1 addition & 2 deletions test/resources/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ describe('Base Resource', () => {
expect(b._validationErrors.a).to.be.a('string');
});

it('throws a validationerror on failed validation and throw = false', () => {
it('throws a validationerror on failed validation', () => {
const b = new Base({ a: 1 });
Base.proptypes = null;

expect(() => b.validateProperties()).to.throw(ValidationError);
});

Expand Down
194 changes: 99 additions & 95 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,110 @@
const chalk = require('chalk');
const webpack = require('webpack');
const path = require('path');

const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const externals = require('webpack-node-externals');

const sourceDir = './src/';
const extensions = ['.js', '.json'];
const destDir = './';
const input = 'easypost.js';
const output = 'easypost.js';
const cwd = `${process.cwd()}/`;

module.exports = {
cache: true,
target: 'node',
externals: [ externals() ],
devtool: 'source-map',
context: path.join(cwd, sourceDir),
entry: {
js: path.join(cwd, sourceDir, input),
},
resolve: {
extensions: extensions,
modules: [
path.join(cwd, 'node_modules'),
path.join(cwd, sourceDir),
]
},
resolveLoader: {
modules: [
path.join(cwd, 'node_modules'),
]
},
output: {
path: path.join(cwd, destDir),
filename: output,
libraryTarget: 'commonjs'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: [
[ require.resolve('babel-preset-es2015'), {
loose: true,
modules: false
} ],
require.resolve('babel-preset-es2017'),
require.resolve('babel-preset-stage-2'),
],
plugins: [
'babel-plugin-transform-class-properties',
]
}
},
{
test: /\.json$/,
loader: 'json-loader',
}
]
},
plugins: [
new ProgressBarPlugin({
clear: false,
format: 'build [:bar] ' + chalk.green(':percent') + ' (:elapsed seconds)',
}),
new webpack.BannerPlugin({
banner: 'require("source-map-support").install();',
}),
//new webpack.ProgressPlugin(),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: true
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
debug: true,
output: {
comments: false
},
sourceMap: true
}),
],
node: {
global: false,
process: false,
Buffer: false,
crypto: false,
module: false,
clearImmediate: false,
setImmediate: false,
clearTimeout: false,
setTimeout: false,
os: false,
_filename: true,
__dirname: true,
}
};
function config(output, nodestr) {
return {
// cache: true,
target: 'node',
externals: [externals()],
devtool: 'source-map',
context: path.join(cwd, sourceDir),
entry: {
js: path.join(cwd, sourceDir, input),
},
resolve: {
extensions,
modules: [
path.join(cwd, 'node_modules'),
path.join(cwd, sourceDir),
],
},
resolveLoader: {
modules: [
path.join(cwd, 'node_modules'),
],
},
output: {
path: path.join(cwd, destDir),
filename: output,
libraryTarget: 'commonjs',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
// cacheDirectory: true,
babelrc: false,
presets: [
['env', {
targets: {
node: nodestr,
},
debug: true,
exclude: [
'transform-async-to-generator',
'transform-regenerator',
],
include: [
// TEMPORARY: until babel v7 is out.
// https://github.com/babel/babel/issues/3930
'transform-es2015-classes',
],
}],
'stage-2',
['minify', {
}],
],
plugins: [
'transform-class-properties',
['fast-async', {
useRuntimeModule: true,
}],
],
},
},
{
test: /\.json$/,
loader: 'json-loader',
},
],
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: true,
}),
],
node: {
global: false,
process: false,
Buffer: false,
crypto: false,
module: false,
clearImmediate: false,
setImmediate: false,
clearTimeout: false,
setTimeout: false,
os: false,
_filename: true,
__dirname: true,
},
};
}

module.exports = [
config('easypost.js', '6.9'),
config('easypost.6-lts.js', '6.9'),
config('easypost.8-lts.js', '8.9'),
config('easypost.legacy.js', '0.10'),
];

0 comments on commit 13f9ae7

Please sign in to comment.