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

faithlife-api

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faithlife-api - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

102

lib/accounts.js

@@ -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 @@

2

lib/index.js

@@ -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();
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