diff --git a/package.json b/package.json index 77b80f6..9ad98d2 100644 --- a/package.json +++ b/package.json @@ -13,24 +13,22 @@ "bugs": "https://github.com/goto-bus-stop/plug-login/issues", "author": "René Kooi ", "engines": { - "node": ">= 0.12" + "node": ">= 4" }, "dependencies": { "cookie": "^0.3.1", "got": "^6.5.0", + "object-assign": "^4.1.0", "promise-props": "^1.0.0" }, "devDependencies": { - "babel-cli": "^6.7.7", - "babel-plugin-transform-object-rest-spread": "^6.5.0", - "babel-preset-es2015": "^6.18.0", - "babel-register": "^6.5.0", + "buble": "^0.14.2", "mocha": "^3.0.2", "standard": "^8.0.0" }, "scripts": { - "prepublish": "npm run babel", - "babel": "babel --out-dir lib src", - "test": "mocha --compilers js:babel-register && standard" + "prepublish": "npm run build", + "build": "buble --output lib --target node:4 --objectAssign assign src", + "test": "npm run build && mocha && standard" } } diff --git a/src/index.js b/src/index.js index 3ffe9ff..3cfe93a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,8 @@ -import got from 'got' -import { parse, serialize } from 'cookie' -import props from 'promise-props' +'use strict' +const got = require('got') +const { parse, serialize } = require('cookie') +const props = require('promise-props') +const assign = require('object-assign') const DEFAULT_HOST = 'https://plug.dj' @@ -41,7 +43,7 @@ function makeSessionCookieHeader (session) { function addCookieToHeaders (opts, session) { if (!opts.headers || !opts.headers.cookie) { - opts.headers = Object.assign(opts.headers || {}, { + opts.headers = assign(opts.headers || {}, { cookie: makeSessionCookieHeader(session) }) } diff --git a/test/test.js b/test/test.js index f279050..3bd8f90 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,9 @@ /* global describe, it, before */ -import got from 'got' -import { strictEqual as eq, fail, ok } from 'assert' -import login from '../src' +'use strict' + +const got = require('got') +const assert = require('assert') +const login = require('../lib') const host = process.env.PLUG_LOGIN_HOST || 'https://plug.dj' @@ -17,8 +19,8 @@ describe('plug-login', function () { }) ) - ok(process.env.PLUG_LOGIN_NAME, 'pass your test email in the PLUG_LOGIN_NAME env var') - ok(process.env.PLUG_LOGIN_PASS, 'pass your test password in the PLUG_LOGIN_PASS env var') + assert.ok(process.env.PLUG_LOGIN_NAME, 'pass your test email in the PLUG_LOGIN_NAME env var') + assert.ok(process.env.PLUG_LOGIN_PASS, 'pass your test password in the PLUG_LOGIN_PASS env var') const args = { email: process.env.PLUG_LOGIN_NAME, @@ -28,39 +30,39 @@ describe('plug-login', function () { const INVALID_EMAIL = 'invalid-email@invalid-domain.com' const INVALID_PASSWORD = 'not_the_password' it('cannot login with invalid credentials', () => - login(INVALID_EMAIL, INVALID_PASSWORD, { host }).then(fail, (result) => { - ok(result) + login(INVALID_EMAIL, INVALID_PASSWORD, { host }).then(assert.fail, (result) => { + assert.ok(result) }) ) it('can login with valid credentials', () => login(args.email, args.password, { host }).then((result) => { - ok(result.session) + assert.ok(result.session) }) ) it('returns a cookie string that can be used for authenticated requests', () => login(args.email, args.password, { host }).then((result) => { - ok(result.session) + assert.ok(result.session) return got(`${host}/_/users/me`, { headers: { cookie: result.cookie }, json: true }) - }).then(({ body }) => { - ok(body.data[0].id) + }).then((response) => { + assert.ok(response.body.data[0].id) }) ) it('can optionally retrieve an auth token', () => login(args.email, args.password, { host, authToken: true }).then((result) => { - ok(result.session) - eq(typeof result.token, 'string') + assert.ok(result.session) + assert.strictEqual(typeof result.token, 'string') }) ) it('can retrieve auth tokens for guest users', () => login.guest({ host, authToken: true }).then((result) => { - eq(typeof result.token, 'string') + assert.strictEqual(typeof result.token, 'string') }) ) @@ -69,6 +71,6 @@ describe('plug-login', function () { login.user(args.email, args.password, { host, _simulateMaintenance: true - }).then(fail, ok) + }).then(assert.fail, assert.ok) ) })