deskbookers
Advanced tools
Comparing version 0.1.0 to 0.2.0
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', './resources/Resource', './resources/Users', './resources/Workplaces', './resources/Cart'], factory); | ||
define(['exports', './resources/Users', './resources/Workplaces', './resources/Cart'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('./resources/Resource'), require('./resources/Users'), require('./resources/Workplaces'), require('./resources/Cart')); | ||
factory(exports, require('./resources/Users'), require('./resources/Workplaces'), require('./resources/Cart')); | ||
} else { | ||
@@ -10,6 +10,6 @@ var mod = { | ||
}; | ||
factory(mod.exports, global.Resource, global.Users, global.Workplaces, global.Cart); | ||
factory(mod.exports, global.Users, global.Workplaces, global.Cart); | ||
global.index = mod.exports; | ||
} | ||
})(this, function (exports, _Resource, _Users, _Workplaces, _Cart) { | ||
})(this, function (exports, _Users, _Workplaces, _Cart) { | ||
'use strict'; | ||
@@ -21,4 +21,2 @@ | ||
var _Resource2 = _interopRequireDefault(_Resource); | ||
var _Users2 = _interopRequireDefault(_Users); | ||
@@ -127,13 +125,9 @@ | ||
try { | ||
const resource = new _Resource2.default(_this); | ||
const result = yield resource.request({ | ||
method: 'GET', | ||
// TODO | ||
path: 'test' | ||
}); | ||
return !!result; | ||
const result = yield _this.users.current(); | ||
if (result && result.id === _this.session.user.id) { | ||
// Update user info | ||
_this.session_.user = result; | ||
return true; | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
return false; | ||
@@ -157,2 +151,3 @@ } | ||
return _asyncToGenerator(function* () { | ||
yield _this2.users.logout(); | ||
_this2.session = null; | ||
@@ -159,0 +154,0 @@ return _this2; |
@@ -176,3 +176,3 @@ (function (global, factory) { | ||
method: 'POST', | ||
path: 'booking/batchCheck', | ||
path: 'booking/batchCheck', // TODO: implement this method in User API | ||
params: { | ||
@@ -179,0 +179,0 @@ group: _this.getGroup(), |
@@ -132,6 +132,9 @@ (function (global, factory) { | ||
const msg = data.errors[i].title || data.errors[i].detail; | ||
console.error(data.errors[i]); | ||
throw new Error(`${ data.errors[i].code || 500 }: ${ msg }`); | ||
} | ||
} else if ('result' in data) return data.result; | ||
} else if ('result' in data) { | ||
return data.result; | ||
} else if ('data' in data) { | ||
return data.data; | ||
} | ||
} | ||
@@ -138,0 +141,0 @@ |
@@ -96,15 +96,10 @@ (function (global, factory) { | ||
return _asyncToGenerator(function* () { | ||
try { | ||
const salt = (yield _this3.retrieveSalt(email || '')) || ''; | ||
const hash = yield _bcryptjs2.default.hash(password || '', salt); | ||
const result = yield _this3.validateCredentials(email, hash); | ||
return { | ||
privateKey: result.privateKey, | ||
publicKey: result.publicKey, | ||
user: result.user | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
const salt = (yield _this3.retrieveSalt(email || '')) || ''; | ||
const hash = yield _bcryptjs2.default.hash(password || '', salt); | ||
const result = yield _this3.validateCredentials(email, hash); | ||
return { | ||
privateKey: result.privateKey, | ||
publicKey: result.publicKey, | ||
user: result.user | ||
}; | ||
})(); | ||
@@ -117,28 +112,45 @@ } | ||
return _asyncToGenerator(function* () { | ||
try { | ||
const salt = yield _this4.retrieveSalt(); | ||
const hash = yield _bcryptjs2.default.hash(password || '', salt); | ||
const result = yield _this4.request({ | ||
method: 'GET', | ||
path: 'register', | ||
params: { | ||
firstName, | ||
lastName, | ||
email, | ||
password: hash | ||
} | ||
}); | ||
return { | ||
privateKey: result.privateKey, | ||
publicKey: result.publicKey, | ||
user: result.user | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
const salt = yield _this4.retrieveSalt(); | ||
const hash = yield _bcryptjs2.default.hash(password || '', salt); | ||
const result = yield _this4.request({ | ||
method: 'GET', | ||
path: 'register', | ||
params: { | ||
firstName, | ||
lastName, | ||
email, | ||
password: hash | ||
} | ||
}); | ||
return { | ||
privateKey: result.privateKey, | ||
publicKey: result.publicKey, | ||
user: result.user | ||
}; | ||
})(); | ||
} | ||
logout() { | ||
var _this5 = this; | ||
return _asyncToGenerator(function* () { | ||
return yield _this5.request({ | ||
method: 'POST', | ||
path: 'logout' | ||
}); | ||
})(); | ||
} | ||
current() { | ||
var _this6 = this; | ||
return _asyncToGenerator(function* () { | ||
return yield _this6.request({ | ||
method: 'GET', | ||
path: 'user' | ||
}); | ||
})(); | ||
} | ||
} | ||
exports.default = Users; | ||
}); |
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', 'hash.js', 'url', 'qs', 'json_encode', 'urlencode-for-php'], factory); | ||
define(['exports', 'hash.js', 'url', 'qs', 'json_encode', 'phpurlencode'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('hash.js'), require('url'), require('qs'), require('json_encode'), require('urlencode-for-php')); | ||
factory(exports, require('hash.js'), require('url'), require('qs'), require('json_encode'), require('phpurlencode')); | ||
} else { | ||
@@ -10,6 +10,6 @@ var mod = { | ||
}; | ||
factory(mod.exports, global.hash, global.url, global.qs, global.json_encode, global.urlencodeForPhp); | ||
factory(mod.exports, global.hash, global.url, global.qs, global.json_encode, global.phpurlencode); | ||
global.requests = mod.exports; | ||
} | ||
})(this, function (exports, _hash, _url, _qs, _json_encode, _urlencodeForPhp) { | ||
})(this, function (exports, _hash, _url, _qs, _json_encode, _phpurlencode) { | ||
'use strict'; | ||
@@ -24,3 +24,3 @@ | ||
var _urlencodeForPhp2 = _interopRequireDefault(_urlencodeForPhp); | ||
var _phpurlencode2 = _interopRequireDefault(_phpurlencode); | ||
@@ -77,9 +77,9 @@ function _interopRequireDefault(obj) { | ||
const buildCheckData = exports.buildCheckData = (url, options, args, timestamp) => [options.method.toUpperCase(), timestamp, (0, _url.parse)(url).path, phpJsonEncode(jsonifyArgs(args))].join('\n'); | ||
const buildCheckData = exports.buildCheckData = (url, options, args, timestamp) => [options.method.toUpperCase(), timestamp, (0, _url.parse)(url).path, options.method.toUpperCase() === 'POST' ? phpJsonEncode(jsonifyArgs(args)) : phpJsonEncode([])].join('\n'); | ||
const phpJsonEncode = exports.phpJsonEncode = _json_encode2.default; | ||
const phpJsonEncode = exports.phpJsonEncode = val => (0, _json_encode2.default)(typeof val === 'undefined' ? null : val); | ||
const onlyAmpEncode = exports.onlyAmpEncode = str => (str + '').toString().replace('&', '%26'); | ||
const phpUrlEncode = exports.phpUrlEncode = _urlencodeForPhp2.default; | ||
const phpUrlEncode = exports.phpUrlEncode = _phpurlencode2.default; | ||
}); |
{ | ||
"name": "deskbookers", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Deskbookers API JavaScript SDK", | ||
@@ -28,6 +28,6 @@ "main": "dist/index.js", | ||
"moment": "^2.17.1", | ||
"phpurlencode": "^1.0.0", | ||
"qs": "^6.3.0", | ||
"rndm": "^1.2.0", | ||
"url": "^0.11.0", | ||
"urlencode-for-php": "^1.0.2" | ||
"url": "^0.11.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
112
test.js
@@ -13,20 +13,42 @@ import dotenv from 'dotenv' | ||
// Users | ||
// test('Login', async t => { | ||
// await t.notThrows(deskbookers.users.login( | ||
// process.env.LOGIN_EMAIL, | ||
// process.env.LOGIN_PASSWORD | ||
// )) | ||
// }) | ||
test('Login', async t => { | ||
await t.notThrows(async () => await deskbookers.login( | ||
process.env.LOGIN_EMAIL, | ||
process.env.LOGIN_PASSWORD | ||
)) | ||
}) | ||
test('Signup', async t => { | ||
// Generate random data | ||
const firstName = `First${Math.random()}` | ||
const lastName = `Last${Math.random()}` | ||
const email = `email${Math.random()}@example.org` | ||
const password = 'pass1234' | ||
// test('Signup', async t => { | ||
// await t.notThrows(deskbookers.users.signup({ | ||
// firstName: process.env.SIGNUP_FIRST_NAME, | ||
// lastName: process.env.SIGNUP_LAST_NAME, | ||
// email: process.env.SIGNUP_EMAIL, | ||
// password: process.env.SIGNUP_PASSWORD | ||
// })) | ||
// }) | ||
// Test signup | ||
await t.notThrows(async () => await deskbookers.signup({ | ||
firstName, | ||
lastName, | ||
email, | ||
password | ||
})) | ||
}) | ||
test('Logout', async t => { | ||
// Login and store session | ||
await deskbookers.login( | ||
process.env.LOGIN_EMAIL, | ||
process.env.LOGIN_PASSWORD | ||
) | ||
const session = deskbookers.session | ||
// Test shopping cart | ||
test('Cart 1', async t => { | ||
// Logout | ||
await deskbookers.logout() | ||
t.is(deskbookers.session, null) | ||
// Reuse previous session | ||
deskbookers.session = session | ||
t.false(await deskbookers.validateSession()) | ||
}) | ||
// Validate session | ||
test('Validate session', async t => { | ||
// Login | ||
@@ -38,27 +60,45 @@ await deskbookers.login( | ||
// Test cart | ||
const space = deskbookers.cart.addSpace({ | ||
id: 13235, | ||
start: moment('2016-12-30 12:00'), | ||
end: moment('2016-12-30 14:00') | ||
}) | ||
space.addProduct({ | ||
id: 10469 | ||
}) | ||
await deskbookers.cart.refresh() | ||
// Validate session | ||
t.true(await deskbookers.validateSession()) | ||
t.is(deskbookers.cart.available(), true) | ||
// Check email for logged in user | ||
const current = await deskbookers.users.current() | ||
t.not(current, null) | ||
if (current) { | ||
t.is(current.email, process.env.LOGIN_EMAIL) | ||
} | ||
}) | ||
for (let key in deskbookers.cart.spaces()) { | ||
const space = deskbookers.cart.getSpace(key) | ||
// Shopping cart | ||
test('Test cart availability', async t => { | ||
const cart = await prepareCart(t) | ||
console.log(space) | ||
t.true(deskbookers.cart.available()) | ||
console.log( | ||
`${space.start().format('YYYY-MM-DD HH:mm')} - ${space.end().format('YYYY-MM-DD HH:mm')} ::`, | ||
`${space.available() ? 'available' : 'unavailable'} ::`, | ||
`${space.meta().name} - ${space.meta().location_name}` | ||
// TODO: test more | ||
}) | ||
const prepareCart = async (t) => { | ||
try { | ||
// Login | ||
await deskbookers.login( | ||
process.env.LOGIN_EMAIL, | ||
process.env.LOGIN_PASSWORD | ||
) | ||
// Test cart | ||
const space = deskbookers.cart.addSpace({ | ||
id: 13235, | ||
start: moment('2016-12-30 12:00'), | ||
end: moment('2016-12-30 14:00') | ||
}) | ||
space.addProduct({ | ||
id: 10469 | ||
}) | ||
await deskbookers.cart.refresh() | ||
return deskbookers.cart | ||
} catch (e) { | ||
t.fail(`Error while preparing cart: ${e && e.message || 'Exception occurred'}`) | ||
return deskbookers.cart | ||
} | ||
console.log('Possible vouchers:', deskbookers.cart.possibleVouchers()) | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
142753
1003
1
12
+ Addedphpurlencode@^1.0.0
+ Addedphpurlencode@1.1.2(transitive)
- Removedurlencode-for-php@^1.0.2
- Removedflat@1.6.2(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedurlencode-for-php@1.0.4(transitive)