New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

getstream-node

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getstream-node - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

CHANGELOG

10

package.json
{
"name": "getstream-node",
"version": "0.3.0",
"version": "1.0.0",
"description": "Build newsfeeds and activity feeds on node.js using getstream.io",

@@ -16,5 +16,7 @@ "author": "Tommaso Barbugli <tbarbugli@gmail.com> (http://getstream.io/)",

"async": "^0.9.0",
"getstream": "~v2.2.2",
"extend": "^3.0.0",
"getstream": "~v3.0.0",
"istanbul": "^0.3.13",
"mockery": "^1.4.0",
"promise": "^7.0.4",
"sinon": "^1.14.1"

@@ -29,3 +31,5 @@ },

"scripts": {
"test": "STREAM_URL='https://key:secret@us-east.getstream.io/?app_id=42' NODE_ENV=test ./node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha test/backends test"
"test": "STREAM_URL='https://key:secret@us-east.getstream.io/?app_id=42' NODE_ENV=test ./node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha test/backends test",
"preversion": "npm test",
"postversion": "git push && git push --tags"
},

@@ -32,0 +36,0 @@ "engines": {

##Stream NodeJS
[![Build Status](https://travis-ci.org/tbarbugli/stream-node.svg)](https://travis-ci.org/tbarbugli/stream-node)
[![npm version](https://badge.fury.io/js/getstream-node.svg)](http://badge.fury.io/js/getstream-node)

@@ -51,3 +52,3 @@ This package helps you create activity streams & newsfeeds with NodeJS and [GetStream.io](https://getstream.io).

stream.mongoose.activitySchema(tweetSchema);
tweetSchema.plugin(stream.mongoose.activity);

@@ -79,3 +80,3 @@ // register your mongoose connection with the library

stream.mongoose.activitySchema(tweetSchema);
tweetSchema.plugin(stream.mongoose.activity);

@@ -161,14 +162,15 @@ tweetSchema.methods.activityActorProp = function() {

```js
```
router.get('/flat', ensureAuthenticated, function(req, res, next){
var flatFeed = FeedManager.getNewsFeeds(req.user.id)['flat'];
flatFeed.get({}, function(err, response, body){
if (err) return next(err);
var activities = body.results;
StreamBackend.enrichActivities(activities,
function(err, enrichedActivities){
flatFeed.get({})
.then(function (body) {
var activities = body.results;
return StreamBackend.enrichActivities(activities);
})
.then(function (enrichedActivities) {
return res.render('feed', {location: 'feed', user: req.user, activities: enrichedActivities, path: req.url});
}
);
})
.catch(next)
});

@@ -178,2 +180,4 @@ });

Promises are used to pipe the asynchronous result of `flatFeed.get` and `StreamBackend.enrichActivities` through our code.
###Temporarily disabling the model sync

@@ -180,0 +184,0 @@

@@ -1,72 +0,67 @@

var BaseActivity = function() {
};
module.exports = function (schema, options) {
// Common proto functions
schema.methods.activityActorFeed = function() {
return null;
};
BaseActivity.methods = {};
BaseActivity.statics = {};
schema.methods.activityGetActor = function() {
var actor = this[this.activityActorProp()];
if (typeof(actor) === 'undefined'){
// todo: throw a clear error here
}
return actor;
};
// Common proto functions
BaseActivity.methods.activityActorFeed = function() {
return null;
};
schema.methods.activityActor = function() {
var actor = this.activityGetActor();
return actor;
};
BaseActivity.methods.activityGetActor = function() {
var actor = this[this.activityActorProp()];
if (typeof(actor) === 'undefined'){
// todo: throw a clear error here
}
return actor;
};
schema.methods.activityObject = function() {
return this;
};
BaseActivity.methods.activityActor = function() {
var actor = this.activityGetActor();
return actor;
};
schema.methods.activityForeignId = function() {
return this;
};
BaseActivity.methods.activityObject = function() {
return this;
};
schema.methods.createActivity = function() {
var activity = {};
var extra_data = this.activityExtraData();
for (var key in extra_data) {
activity[key] = extra_data[key];
}
activity.to = (this.activityNotify() || []).map(function(x){return x.id});
activity.actor = this.activityActor();
activity.verb = this.activityVerb();
activity.object = this.activityObject();
activity.foreign_id = this.activityForeignId();
if (this.activityTime()) {
activity.time = this.activityTime();
}
return activity;
}
BaseActivity.methods.activityForeignId = function() {
return this;
};
// User specific proto functions (with decent defaults)
schema.methods.getStreamBackend = function() {
var stream = require('../index.js');
return new stream.BaseBackend();
};
BaseActivity.methods.createActivity = function() {
var activity = {};
var extra_data = this.activityExtraData();
for (var key in extra_data) {
activity[key] = extra_data[key];
}
activity.to = (this.activityNotify() || []).map(function(x){return x.id});
activity.actor = this.activityActor();
activity.verb = this.activityVerb();
activity.object = this.activityObject();
activity.foreign_id = this.activityForeignId();
if (this.activityTime()) {
activity.time = this.activityTime();
}
return activity;
}
schema.methods.activityActorProp = function() {
return 'user'
};
// User specific proto functions (with decent defaults)
BaseActivity.methods.getStreamBackend = function() {
var stream = require('../index.js');
return new stream.BaseBackend();
};
schema.methods.activityVerb = function() {
return this.constructor.name;
};
BaseActivity.methods.activityActorProp = function() {
return 'user'
};
schema.methods.activityExtraData = function() {
return {};
};
BaseActivity.methods.activityVerb = function() {
return this.constructor.name;
};
schema.methods.activityTime = function() {};
BaseActivity.methods.activityExtraData = function() {
return {};
schema.methods.activityNotify = function() {};
};
BaseActivity.methods.activityTime = function() {};
BaseActivity.methods.activityNotify = function() {};
module.exports = BaseActivity;
var async = require("async");
var Promise = require("promise");

@@ -70,8 +71,5 @@ var BaseBackend = function() {

},
enrichActivities: function(activities, callback) {
try {
this._enrichActivities(activities, callback);
} catch (err) {
callback(err, activities);
}
enrichActivities: function(activities) {
// Return a Promise instead of using node style callbacks (_enrichActivities accepts one argument + callback)
return Promise.denodeify(this._enrichActivities, 1).call(this, activities);
},

@@ -90,8 +88,5 @@ _enrichActivities: function(activities, callback) {

},
enrichAggregatedActivities: function(aggregatedActivities, callback) {
try {
this._enrichAggregatedActivities(aggregatedActivities, callback);
} catch (err) {
callback(err, aggregatedActivities);
}
enrichAggregatedActivities: function(aggregatedActivities) {
// Return a Promise instead of using node style callbacks (_enrichAggregatedActivities accepts one argument + callback)
return Promise.denodeify(this._enrichAggregatedActivities, 1).call(this, aggregatedActivities);
},

@@ -104,9 +99,8 @@ _enrichAggregatedActivities: function(aggregatedActivities, callback) {

enrichments.push(
function(aggregated){
(function(aggregated){
return function(done) {
self.enrichActivities(aggregated['activities'], function(err, results) {
done(err, aggregated);
});
self.enrichActivities(aggregated['activities'])
.then(done.bind(this, null), done);
}
}(aggregatedActivities[i]))
})(aggregatedActivities[i]))
}

@@ -113,0 +107,0 @@ async.parallel(enrichments, function(err) { callback(err, aggregatedActivities); });

@@ -1,2 +0,2 @@

var BaseActivity = require('./activity.js');
var baseActivitySchemaPlugin = require('./activity.js');
var util = require("util");

@@ -46,18 +46,2 @@ var stream = require('../index.js');

function extendSchema(base, mixin) {
if (typeof base.methods === 'undefined') {
base.methods = {};
}
if (typeof base.statics === 'undefined') {
base.statics = {};
}
for (var fn in mixin.methods) {
base.methods[fn] = mixin.methods[fn];
}
for (var fn in mixin.statics) {
base.statics[fn] = mixin.statics[fn];
}
return base;
}
function getReferencePaths(paths) {

@@ -73,8 +57,4 @@ var names = [];

var activitySchema = function(Schema) {
// add base proto functions from BaseActivity
extendSchema(Schema, BaseActivity);
Schema.pre('save', function(next) {
var mongooseActivitySchemaPlugin = function(schema, options) {
schema.pre('save', function(next) {
this.wasNew = this.isNew;

@@ -84,3 +64,3 @@ next();

Schema.post('save', function(doc) {
schema.post('save', function(doc) {
var paths = getReferencePaths(doc.schema.paths);

@@ -94,3 +74,3 @@ doc.populate(paths, function(err, docP) {

Schema.post('remove', function(doc) {
schema.post('remove', function(doc) {
var paths = getReferencePaths(doc.schema.paths);

@@ -103,19 +83,19 @@ doc.populate(paths, function(err, docP) {

// add Mongoose specific proto functions
Schema.methods.referencesPaths = function() {
schema.methods.referencesPaths = function() {
return this;
}
};
Schema.methods.getStreamBackend = function() {
schema.methods.getStreamBackend = function() {
return new Backend();
}
};
Schema.statics.activityModelReference = function() {
schema.statics.activityModelReference = function() {
return this.modelName;
}
};
Schema.methods.activityVerb = function() {
schema.methods.activityVerb = function() {
return this.constructor.modelName;
};
Schema.statics.pathsToPopulate = function() {
schema.statics.pathsToPopulate = function() {
return [];

@@ -125,4 +105,8 @@ };

module.exports.activitySchema = activitySchema;
module.exports.activity = function(schema, options) {
schema.plugin(baseActivitySchemaPlugin);
schema.plugin(mongooseActivitySchemaPlugin);
};
module.exports.Backend = Backend;
module.exports.setupMongoose = setupMongoose;

@@ -19,2 +19,4 @@ var path = require('path'),

var Config = function () {
var settings = {},
config_file = '';
// load config from defaults or config file

@@ -21,0 +23,0 @@

@@ -23,3 +23,3 @@ var stream = require('getstream');

}
},

@@ -26,0 +26,0 @@

@@ -7,4 +7,15 @@ var FeedManager = require('./FeedManager.js');

module.exports.FeedManager = new FeedManager(settings);
module.exports.feedManagerFactory = function (options) {
options = options || {};
for(var key in settings) {
if(settings.hasOwnProperty(key) && options.hasOwnProperty(key)) {
settings[key] = options[key];
}
}
return new FeedManager(settings);
}
module.exports.BaseBackend = BaseBackend;
module.exports.mongoose = require('./backends/mongoose.js');
module.exports.settings = settings;

@@ -10,13 +10,13 @@ var async = require("async");

mongoose.connect('mongodb://localhost/test');
var connection = mongoose.connect('mongodb://localhost/test');
var userSchema = Schema({
var userSchema = new Schema({
name : String
});
var linkSchema = Schema({
var linkSchema = new Schema({
href : String
});
var tweetSchema = Schema({
var tweetSchema = new Schema({
text : String,

@@ -28,3 +28,3 @@ actor : { type: Schema.Types.ObjectId, ref: 'User' },

StreamMongoose.activitySchema(tweetSchema);
tweetSchema.plugin(StreamMongoose.activity);

@@ -82,8 +82,9 @@ tweetSchema.statics.pathsToPopulate = function() {

backend.serializeActivities([activity]);
backend.enrichActivities([activity], function(err, enriched) {
should.not.exist(err);
enriched.should.length(1);
enriched[0].should.have.property('object', null);
done();
});
backend.enrichActivities([activity])
.then(function(enriched) {
enriched.should.length(1);
enriched[0].should.have.property('object', null);
done();
})
.catch(done);
});

@@ -93,6 +94,8 @@

var activity = {'object': 'user:42'};
backend.enrichActivities([activity], function(err, enriched) {
(err).should.be.an.instanceOf(Error);
done();
});
backend.enrichActivities([activity])
.then(done)
.catch(function(err) {
(err).should.be.an.instanceOf(Error);
done();
});
});

@@ -102,8 +105,9 @@

var activity = {'origin': 'user:42'};
backend.enrichActivities([activity], function(err, enriched) {
should.not.exist(err);
enriched.should.length(1);
enriched[0].should.have.property('origin', 'user:42');
done();
});
backend.enrichActivities([activity])
.then(function(enriched) {
enriched.should.length(1);
enriched[0].should.have.property('origin', 'user:42');
done();
})
.catch(done);
});

@@ -130,19 +134,20 @@

];
backend.enrichAggregatedActivities(aggregatedActivities, function(err, enriched) {
should.not.exist(err);
enriched.should.length(2);
var firstAggregation = enriched[0];
var secondAggregation = enriched[1];
firstAggregation.should.have.property('activities').with.lengthOf(1);
firstAggregation['activities'][0].should.have.property('actor');
firstAggregation['activities'][0].should.have.property('object');
firstAggregation['activities'][0].object.should.have.property('_id');
firstAggregation['activities'][0].should.have.property('verb');
secondAggregation['activities'][0].should.have.property('actor');
secondAggregation['activities'][0].should.have.property('object');
secondAggregation['activities'][0].object.should.have.property('_id');
secondAggregation['activities'][0].should.have.property('verb');
(firstAggregation['activities'][0].object._id).should.not.equal((secondAggregation['activities'][0].object._id));
done();
});
backend.enrichAggregatedActivities(aggregatedActivities)
.then(function(enriched) {
enriched.should.length(2);
var firstAggregation = enriched[0];
var secondAggregation = enriched[1];
firstAggregation.should.have.property('activities').with.lengthOf(1);
firstAggregation['activities'][0].should.have.property('actor');
firstAggregation['activities'][0].should.have.property('object');
firstAggregation['activities'][0].object.should.have.property('_id');
firstAggregation['activities'][0].should.have.property('verb');
secondAggregation['activities'][0].should.have.property('actor');
secondAggregation['activities'][0].should.have.property('object');
secondAggregation['activities'][0].object.should.have.property('_id');
secondAggregation['activities'][0].should.have.property('verb');
(firstAggregation['activities'][0].object._id).should.not.equal((secondAggregation['activities'][0].object._id));
done();
})
.catch(done);
});

@@ -163,11 +168,12 @@ });

];
backend.enrichAggregatedActivities(aggregatedActivities, function(err, enriched) {
should.not.exist(err);
enriched.should.length(1);
enriched[0].should.have.property('activities').with.lengthOf(1);
enriched[0]['activities'][0].should.have.property('actor');
enriched[0]['activities'][0].should.have.property('object');
enriched[0]['activities'][0].should.have.property('verb');
done();
});
backend.enrichAggregatedActivities(aggregatedActivities)
.then(function(enriched) {
enriched.should.length(1);
enriched[0].should.have.property('activities').with.lengthOf(1);
enriched[0]['activities'][0].should.have.property('actor');
enriched[0]['activities'][0].should.have.property('object');
enriched[0]['activities'][0].should.have.property('verb');
done();
})
.catch(done);
});

@@ -189,16 +195,17 @@ });

];
backend.enrichAggregatedActivities(aggregatedActivities, function(err, enriched) {
should.not.exist(err);
enriched.should.length(2);
enriched[0].should.have.property('activities').with.lengthOf(1);
enriched[0]['activities'][0].should.have.property('actor');
enriched[0]['activities'][0].should.have.property('object');
enriched[0]['activities'][0].should.have.property('verb');
backend.enrichAggregatedActivities(aggregatedActivities)
.then(function(enriched) {
enriched.should.length(2);
enriched[0].should.have.property('activities').with.lengthOf(1);
enriched[0]['activities'][0].should.have.property('actor');
enriched[0]['activities'][0].should.have.property('object');
enriched[0]['activities'][0].should.have.property('verb');
enriched[1].should.have.property('activities').with.lengthOf(2);
enriched[1]['activities'][0].should.have.property('actor');
enriched[1]['activities'][0].should.have.property('object');
enriched[1]['activities'][0].should.have.property('verb');
done();
});
enriched[1].should.have.property('activities').with.lengthOf(2);
enriched[1]['activities'][0].should.have.property('actor');
enriched[1]['activities'][0].should.have.property('object');
enriched[1]['activities'][0].should.have.property('verb');
done();
})
.catch(done);
});

@@ -227,10 +234,11 @@ });

activity = JSON.parse(JSON.stringify(activity));
backend.enrichActivities([activity], function(err, enriched) {
should.not.exist(err);
enriched.should.length(1);
enriched[0].should.have.property('actor');
enriched[0]['actor'].should.have.property('_id', self.actor._id);
enriched[0].should.have.property('foreign_id', 'Tweet:'+tweet._id);
done();
});
backend.enrichActivities([activity])
.then(function(enriched) {
enriched.should.length(1);
enriched[0].should.have.property('actor');
enriched[0]['actor'].should.have.property('_id', self.actor._id);
enriched[0].should.have.property('foreign_id', 'Tweet:'+tweet._id);
done();
})
.catch(done);
});

@@ -249,15 +257,16 @@ });

var activity = tweet.createActivity();
backend.enrichActivities([activity], function(err, enriched) {
should.not.exist(err);
enriched.should.length(1);
enriched[0].should.have.property('actor');
enriched[0]['actor'].should.have.property('_id', self.actor._id);
enriched[0].should.have.property('object');
enriched[0]['object'].should.have.property('_id', tweet._id);
enriched[0]['object'].should.have.property('text', tweet.text);
enriched[0].should.have.property('bg', 'bgvalue');
enriched[0].should.have.property('link');
enriched[0]['link'].should.have.property('_id', this.link._id);
done();
});
backend.enrichActivities([activity])
.then(function(enriched) {
enriched.should.length(1);
enriched[0].should.have.property('actor');
enriched[0]['actor'].should.have.property('_id', self.actor._id);
enriched[0].should.have.property('object');
enriched[0]['object'].should.have.property('_id', tweet._id);
enriched[0]['object'].should.have.property('text', tweet.text);
enriched[0].should.have.property('bg', 'bgvalue');
enriched[0].should.have.property('link');
enriched[0]['link'].should.have.property('_id', this.link._id);
done();
})
.catch(done);
});

@@ -308,12 +317,13 @@ });

var activity = tweet.createActivity();
backend.enrichActivities([activity], function(err, enriched){
should.not.exist(err);
enriched.should.length(1);
enriched[0].should.have.property('actor');
enriched[0]['actor'].should.have.property('_id', self.actor._id);
enriched[0].should.have.property('object');
enriched[0]['object'].should.have.property('_id', tweet._id);
enriched[0]['object'].should.have.property('text', tweet.text);
done();
});
backend.enrichActivities([activity])
.then(function(enriched){
enriched.should.length(1);
enriched[0].should.have.property('actor');
enriched[0]['actor'].should.have.property('_id', self.actor._id);
enriched[0].should.have.property('object');
enriched[0]['object'].should.have.property('_id', tweet._id);
enriched[0]['object'].should.have.property('text', tweet.text);
done();
})
.catch(done);
});

@@ -338,4 +348,4 @@ });

var activities = [tweet1.createActivity(), tweet2.createActivity()];
backend.enrichActivities(activities,
function(err, enriched){
backend.enrichActivities(activities)
.then(function(enriched){
enriched.should.length(2);

@@ -346,6 +356,7 @@ enriched[0].should.have.property('foreign_id');

done();
}
)}
);
});
})
.catch(done);
}
);
});
});

@@ -352,0 +363,0 @@

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