faithlife-api
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -7,3 +7,3 @@ /*! | ||
*/ | ||
var BaseApiClient = require('./base'); | ||
var ProxyClient = require('proxy-client'); | ||
@@ -13,3 +13,3 @@ /** | ||
* | ||
* See `BaseApiClient` for available options. | ||
* See `ProxyClient` for available options. | ||
*/ | ||
@@ -25,12 +25,30 @@ function AccountsApiClient(options) { | ||
BaseApiClient.call(this, options); | ||
ProxyClient.call(this, options); | ||
} | ||
BaseApiClient.inherit(AccountsApiClient); | ||
ProxyClient.inherit(AccountsApiClient); | ||
/** | ||
* Gets the currently logged-in User, returning a promise to be fulfilled with | ||
* the Response or rejected with an HTTP error. | ||
* the User or rejected with an appropriate error. | ||
*/ | ||
AccountsApiClient.prototype.getLoggedInUser = function getLoggedInUser() { | ||
return this.get('/v1/users/me').then(); | ||
var self = this; | ||
return self.get('/v1/users/me') | ||
.end() | ||
.then(function (response) { | ||
if (response.status === 404) { | ||
return null; | ||
} | ||
if (response.status !== 200) { | ||
return self.rejectResponse(response); | ||
} | ||
if (response.body.id === -1) { | ||
return null; | ||
} | ||
return response.body; | ||
}); | ||
}; | ||
@@ -40,6 +58,20 @@ | ||
* Gets the specified User by `userId`, returning a promise to be fulfilled | ||
* with the Response or rejected with an HTTP error. | ||
* with the User or rejected with an appropriate error. | ||
*/ | ||
AccountsApiClient.prototype.getUser = function getUser(userId) { | ||
return this.get('/v1/users/' + userId).then(); | ||
var self = this; | ||
return self.get('/v1/users/' + userId) | ||
.end() | ||
.then(function (response) { | ||
if (response.status === 404) { | ||
return null; | ||
} | ||
if (response.status !== 200) { | ||
return self.rejectResponse(response); | ||
} | ||
return response.body; | ||
}); | ||
}; | ||
@@ -49,6 +81,20 @@ | ||
* Creates a new Group based on `group`, returning a promise to be fulfilled | ||
* with the Response or rejected with an HTTP error. | ||
* with the User or rejected with an appropriate error. | ||
*/ | ||
AccountsApiClient.prototype.createGroup = function createGroup(group) { | ||
return this.post('/v1/groups').send(group).then(); | ||
var self = this; | ||
return self.post('/v1/groups') | ||
.send(group) | ||
.end({ | ||
name: group.name, | ||
privacy: group.privacy | ||
}) | ||
.then(function (response) { | ||
if (response.status !== 200) { | ||
return self.rejectResponse(response); | ||
} | ||
return response.body; | ||
}); | ||
}; | ||
@@ -58,6 +104,20 @@ | ||
* Gets the specified Group by either Group ID or Group "token", returning a | ||
* promise to be fulfilled with the Response or rejected with an HTTP error. | ||
* promise to be fulfilled with the Group or rejected with an appropriate error. | ||
*/ | ||
AccountsApiClient.prototype.getGroup = function getGroup(groupIdOrToken) { | ||
return this.get('/v1/groups/' + groupIdOrToken).then(); | ||
var self = this; | ||
return self.get('/v1/groups/' + groupIdOrToken) | ||
.end() | ||
.then(function (response) { | ||
if (response.status === 404) { | ||
return null; | ||
} | ||
if (response.status !== 200) { | ||
return self.rejectResponse(response); | ||
} | ||
return response.body; | ||
}); | ||
}; | ||
@@ -67,6 +127,18 @@ | ||
* Gets all the groups the specified User is a part of, returning a | ||
* promise to be fulfilled with the Response or rejected with an HTTP error. | ||
* promise to be fulfilled with the User's Groups or rejected with an | ||
* appropriate error. | ||
*/ | ||
AccountsApiClient.prototype.getGroupsForUser = function getGroupsForUser(userId) { | ||
return this.get('/v1/users/' + userId + '/groups').then(); | ||
AccountsApiClient.prototype.getGroupsForUser = function getGroupsForUser(userId, options) { | ||
var self = this; | ||
return self.get('/v1/users/' + userId + '/groups') | ||
.query(options) | ||
.end() | ||
.then(function (response) { | ||
if (response.status !== 200) { | ||
return self.rejectResponse(response); | ||
} | ||
return response.body.groups; | ||
}); | ||
}; | ||
@@ -73,0 +145,0 @@ |
@@ -1,7 +0,5 @@ | ||
var BaseApiClient = require('./base'); | ||
var AccountsApiClient = require('./accounts'); | ||
module.exports = { | ||
Client: BaseApiClient, | ||
Accounts: AccountsApiClient | ||
}; |
{ | ||
"name": "faithlife-api", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "A collection of CommonJS modules for interacting with the Faithlife API.", | ||
@@ -15,7 +15,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"express": "~4.9.4", | ||
"mi": "~1.0.0", | ||
"superagent": "~0.19.0", | ||
"superagent-then": "~1.0.0", | ||
"when": "~3.4.4" | ||
"proxy-client": "~0.3.0" | ||
}, | ||
@@ -22,0 +18,0 @@ "devDependencies": { |
var assert = require('assert'); | ||
var faithlifeOAuth = require('faithlife-oauth'); | ||
var mach = require('mach'); | ||
var lib = require('../lib'); | ||
var TOKEN = '491D486DD7C22BAEC44A06E802272139E6A10D62'; | ||
var SECRET = '839A6F206D70619D45F204FD2CF7E35E6AEEFFDD'; | ||
var consumer = faithlifeOAuth.createConsumer({ | ||
token: TOKEN, | ||
secret: SECRET | ||
}); | ||
@@ -21,60 +13,5 @@ /** | ||
client.getLoggedInUser() | ||
.then(function (response) { | ||
// 1. Should respond with a 200. | ||
assert.equal(response.status, 200, 'Non-success status code.'); | ||
// 2. Should respond with JSON. | ||
assert.ok(response.content && typeof response.content === 'object', 'Missing anonymous response body.'); | ||
// 3. Should respond with a -1 ID if no user is logged-in. | ||
assert.deepEqual( | ||
response.content, | ||
{ id: -1 }, | ||
'Invalid anonymous response body.' | ||
); | ||
.then(function (user) { | ||
assert.equal(user, null, 'Did not assert.'); | ||
}) | ||
.done(); | ||
// TODO(schoon) - Automate the sign-in form submission and test while | ||
// authenticated. | ||
/* | ||
* The Proxy | ||
*/ | ||
var app = mach.stack(); | ||
app.use(mach.session, { | ||
secret: 'test', | ||
store: mach.session.MemoryStore() | ||
}); | ||
consumer.mount(app, '/oauth'); | ||
app.map('/api', function (subapp) { | ||
subapp.use(consumer.generateMiddleware()); | ||
client.mount(subapp, '/accounts'); | ||
}); | ||
var server = mach.serve(app, process.env.PORT || 22222); | ||
/** | ||
* getLoggedInUser | ||
*/ | ||
var proxy = lib.Accounts.createClient({ rootUrl: 'http://127.0.0.1:22222/api/accounts' }); | ||
proxy.getLoggedInUser() | ||
.then(function (response) { | ||
// 1. Should respond with a 200. | ||
assert.equal(response.status, 200, 'Non-success status code.'); | ||
// 2. Should respond with JSON. | ||
assert.ok(response.content && typeof response.content === 'object', 'Missing anonymous response body.'); | ||
// 3. Should respond with a -1 ID if no user is logged-in. | ||
assert.deepEqual( | ||
response.content, | ||
{ id: -1 }, | ||
'Invalid anonymous response body.' | ||
); | ||
}) | ||
.then(function () { | ||
server.close(); | ||
}) | ||
.done(); |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
1
4442
7
137
+ Addedproxy-client@~0.3.0
+ Addedasap@2.0.6(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcolors@0.6.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcookiejar@2.1.4(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddezalgo@1.0.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedformidable@3.5.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhexoid@2.0.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@2.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.1.3(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedproxy-client@0.3.0(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedsawmill@0.2.2(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedsuperagent@10.1.1(transitive)
+ Addedsuperagent-then@1.1.2(transitive)
+ Addedwhen@3.6.4(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedexpress@~4.9.4
- Removedmi@~1.0.0
- Removedsuperagent@~0.19.0
- Removedsuperagent-then@~1.0.0
- Removedwhen@~3.4.4
- Removedasync@0.9.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcomponent-emitter@1.1.2(transitive)
- Removedcookiejar@2.0.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@1.0.5(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedextend@1.2.1(transitive)
- Removedform-data@0.1.3(transitive)
- Removedformidable@1.0.14(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmethods@1.0.1(transitive)
- Removedms@2.0.0(transitive)
- Removedqs@1.2.0(transitive)
- Removedreadable-stream@1.0.27-1(transitive)
- Removedreduce-component@1.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedsuperagent@0.19.1(transitive)
- Removedsuperagent-then@1.0.1(transitive)