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

deployd

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deployd - npm Package Compare versions

Comparing version 0.6.7 to 0.6.8

test-app/resources/users/put.js

2

ABOUT.md

@@ -32,3 +32,3 @@ # Deployd Server

Consult the [documentation](http://deployd.github.com/deployd) or contact `ritchie at deployd com`.
Consult the [documentation](http://docs.deployd.com/) or contact `ritchie at deployd com`.

@@ -35,0 +35,0 @@ ## license

@@ -275,3 +275,34 @@ (function (undefined) {

window.dpd.once = function(name, fn) {
var _fn = function() {
socket.removeListener(name, _fn);
fn.apply(this, arguments);
};
socket.on(name, _fn);
};
window.dpd.off = function(name, fn) {
if (fn == null) {
socket.removeAllListeners(name);
} else {
socket.removeListener(name, fn);
}
};
var isSocketReady = false;
window.dpd.once('connect', function() {
isSocketReady = true;
});
window.dpd.socketReady = function(fn) {
if (isSocketReady) {
setTimeout(fn, 0);
} else {
window.dpd.once('connect', fn);
}
};
window.dpd.socket = socket;
})();
# History
## 0.6.8
- Fixed CORS incorrectly requiring a referer header
- Added `dpd.once(name, fn)` function to execute a realtime handler exactly once
- Added `dpd.off(name, [fn])` function to remove a realtime handler
- Added `dpd.socketReady(fn)` function to listen for the built-in `connect` event
- Added `dpd.socket` property to provide direct access to socket.io.
- Fixed bug where username and password could be updated by an unauthenticated put.
- Usernames and passwords can be updated only by that user's session, a root session, or an internal request.
- Made `data` folder smaller by default in `development` environment
- Added `cancelIf()`, `cancelUnless()`, `errorIf()`, and `errorUnless()` functions to event API for more declarative events
- Added `hasErrors()` function to event API
- Added `isMe()` function to event API
- Fixed external prototype bug causing custom external prototypes to fail
- Removed docs from repository. They are now available at http://docs.deployd.com or https://github.com/deployd/docs.
## 0.6.7

@@ -12,3 +29,3 @@

- Fixed unnecessary error when parsing JSON body
- Added more intelegent body parsing
- Added more intelligent body parsing
- Added `changed()` method in collection events

@@ -15,0 +32,0 @@ - Added `previous` object in collection events

@@ -10,3 +10,4 @@ var fs = require('fs')

, domain = require('domain')
, async = require('async');
, async = require('async')
, Q = require('q');

@@ -151,12 +152,35 @@ /*!

function addInternalResources(server, basepath, resources, fn) {
var internals = [
new Files('', { config: { 'public': './public' }, server: server })
, new ClientLib('dpd.js', { config: { resources: resources }, server: server})
, new InternalResources('__resources', {config: {configPath: basepath}, server: server})
, new Dashboard('dashboard', {server: server})
];
async.forEach(internals, loadResourceExtras, function(err) {
fn(err, resources.concat(internals));
var publicFolderQ = Q.fcall(function() {
var defaultFolder = './public';
if (server.options && typeof server.options.env === 'string') {
var altPublic = './public-' + server.options.env;
var altPublicExistsQ = Q.defer();
fs.exists(altPublic, function(exists) {
altPublicExistsQ.resolve(exists);
});
return altPublicExistsQ.promise.then(function(exists) {
if (exists) {
return altPublic;
} else {
return defaultFolder;
}
});
} else {
return defaultFolder;
}
});
publicFolderQ.then(function(publicFolder) {
var internals = [
new Files('', { config: { 'public': publicFolder }, server: server })
, new ClientLib('dpd.js', { config: { resources: resources }, server: server})
, new InternalResources('__resources', {config: {configPath: basepath}, server: server})
, new Dashboard('dashboard', {server: server})
];
async.forEach(internals, loadResourceExtras, function(err) {
fn(err, resources.concat(internals));
});
});
}

@@ -88,2 +88,8 @@ var Resource = require('../resource')

res.write('}\n');
res.write('dpd.' + jsName + '.once = function(ev, fn) {\n');
res.write(' return dpd.once("' + r.path.replace('/', '') + '" + ":" + ev, fn);\n');
res.write('}\n');
res.write('dpd.' + jsName + '.off = function(ev, fn) {\n');
res.write(' return dpd.off("' + r.path.replace('/', '') + '" + ":" + ev, fn);\n');
res.write('}\n');
}

@@ -94,3 +100,3 @@

res.write('dpd.' + jsName + '.' + name + ' = function (path, body, fn) {\n');
res.write(' dpd.exec("' + name + '", path, body, fn);\n');
res.write(' dpd.' + jsName + '.exec("' + name + '", path, body, fn);\n');
res.write('}\n');

@@ -97,0 +103,0 @@ });

@@ -307,7 +307,7 @@ var validation = require('validation')

}
var errors = {};
if(Array.isArray(result)) {
var errors = {};
var remaining = result && result.length;

@@ -317,13 +317,3 @@ if(!remaining) return done(err, result);

// domain for onGet event scripts
var domain = {
error: function(key, val) {
errors = errors || {};
errors[key] = val || true;
},
hide: function(property) {
delete data[property];
},
'this': data,
data: data
};
var domain = createDomain(data, errors);

@@ -350,13 +340,3 @@ collection.events.Get.run(ctx, domain, function (err) {

data = result;
var domain = {
error: function(key, val) {
errors = errors || {};
errors[key] = val || true;
},
hide: function(property) {
delete data[property];
},
'this': data,
data: data
};
var domain = createDomain(data, errors);

@@ -402,8 +382,3 @@ collection.events.Get.run(ctx, domain, function (err) {

if(collection.shouldRunEvent(collection.events.Delete, ctx)) {
var domain = {
error: function(key, val) {
errors = errors || {};
errors[key] = val || true;
}
};
var domain = createDomain(result, errors);

@@ -434,3 +409,3 @@ domain['this'] = domain.data = result;

, client = ctx.dpd
, errors;
, errors = {};

@@ -461,3 +436,3 @@ if(!item) return done('You must include an object when saving or updating.');

function done(err, item) {
errors = errors && {errors: errors};
errors = domain && domain.hasErrors() && {errors: errors};
debug('errors: %j', err);

@@ -467,23 +442,15 @@ fn(errors || err, item);

var domain = {
error: function(key, val) {
debug('error %s %s', key, val);
errors = errors || {};
errors[key] = val || true;
},
hide: function(property) {
delete item[property];
},
protect: function(property) {
delete item[property];
},
changed: function (property) {
if(item.hasOwnProperty(property)) return true;
return false;
},
'this': item,
data: item,
previous: {}
var domain = createDomain(item, errors);
domain.protect = function(property) {
delete domain.data[property];
};
domain.changed = function (property) {
if(domain.data.hasOwnProperty(property)) return true;
return false;
};
domain.previous = {};
function put() {

@@ -534,3 +501,3 @@ var id = query.id

function commit(err) {
if(err || errors) {
if(err || domain.hasErrors()) {
return done(err || errors);

@@ -552,3 +519,3 @@ }

collection.events.Validate.run(ctx, domain, function (err) {
if(err || errors) return done(err || errors);
if(err || domain.hasErrors()) return done(err || errors);
runPutEvent(err);

@@ -576,3 +543,3 @@ });

}
if(err || errors) return done(err || errors);
if(err || domain.hasErrors()) return done(err || errors);
debug('inserting item', item);

@@ -592,3 +559,3 @@ store.insert(item, done);

collection.events.Validate.run(ctx, domain, function (err) {
if(err || errors) return done(err || errors);
if(err || domain.hasErrors()) return done(err || errors);
post();

@@ -601,2 +568,30 @@ });

function createDomain(data, errors) {
var hasErrors = false;
var domain = {
error: function(key, val) {
debug('error %s %s', key, val);
errors[key] = val || true;
hasErrors = true;
},
errorIf: function(condition, key, value) {
if (condition) {
domain.error(key, value);
}
},
errorUnless: function(condition, key, value) {
domain.errorIf(!condition, key, value);
},
hasErrors: function() {
return hasErrors;
},
hide: function(property) {
delete domain.data[property];
},
'this': data,
data: data
};
return domain;
}
Collection.defaultPath = '/my-objects';

@@ -603,0 +598,0 @@

@@ -120,2 +120,8 @@ var validation = require('validation')

}
var isSelf = ctx.session.user && ctx.session.user.id === ctx.query.id || ctx.body.id;
if ((ctx.query.id || ctx.body.id) && ctx.body && !isSelf && !ctx.session.isRoot && !ctx.req.internal) {
delete ctx.body.username;
delete ctx.body.password;
}
function done(err, res) {

@@ -122,0 +128,0 @@ if (res) delete res.password;

@@ -42,3 +42,14 @@ var vm = require('vm')

},
cancelIf: function(condition, msg, status) {
if (condition) {
scriptContext.cancel(msg, status);
}
},
cancelUnless: function(condition, msg, status) {
scriptContext.cancelIf(!condition, msg, status);
},
me: session && session.user,
isMe: function(id) {
return (scriptContext.me && scriptContext.me.id === id) || false;
},
console: console,

@@ -45,0 +56,0 @@ query: ctx.query,

@@ -12,6 +12,13 @@ var Cookies = require('cookies')

exports.setup = function(req, res, next) {
var remoteHost = parseUrl(req.headers.referer || '').host
, origins = ['http://' + remoteHost, 'https://' + remoteHost]
, handler = corser.create({supportsCredentials: true, methods: ALLOWED_METHODS, origins: origins});
var remoteHost = req.headers.origin
, corsOpts = {supportsCredentials: true, methods: ALLOWED_METHODS};
if(remoteHost) {
corsOpts.origins = [remoteHost];
} else {
corsOpts.supportsCredentials = false;
}
var handler = corser.create(corsOpts);
handler(req, res, function () {

@@ -18,0 +25,0 @@ req.cookies = res.cookies = new Cookies(req, res);

@@ -27,3 +27,8 @@ var fs = require('fs')

var options = ['--dbpath', './data', '--pidfilepath', './.dpd/pids/mongod', '--port', port];
if(env === 'development') options.push('--nojournal');
if(env === 'development') {
options.push('--nojournal');
options.push('--smallfiles');
options.push('--nssize');
options.push('4');
}

@@ -30,0 +35,0 @@ var proc = spawn(mongod, options, {title: 'FOOBAR'})

{
"author": "Ritchie Martori",
"author": "Ritchie Martori",
"name": "deployd",
"version": "0.6.7",
"version": "0.6.8",
"description": "the simplest way to build realtime APIs for web and mobile apps",

@@ -38,2 +38,3 @@ "repository": {

"keypress": "~0.1.0",
"q": "~0.8.9",
"opener": "~1.3.0",

@@ -40,0 +41,0 @@ "corser": "~1.1.1",

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

# deployd v0.6.7
# deployd v0.6.8

@@ -27,7 +27,7 @@ [![Build Status](https://secure.travis-ci.org/deployd/deployd.png)](http://travis-ci.org/deployd/deployd)

- [Docs](http://deployd.com/docs/)
- [Getting Started Guide](http://deployd.com/docs/)
- [Hello World Tutorial](http://deployd.com/docs/tutorials/hello-world.html)
- [Docs](http://docs.deployd.com/)
- [Getting Started Guide](http://docs.deployd.com/docs/getting-started/what-is-deployd.md)
- [Hello World Tutorial](http://docs.deployd.com/docs/getting-started/your-first-api.md)
- [Community Discussion Page](http://deployd.com/community.html)
- [Example Apps](http://deployd.com/docs/examples.html)
- [Example Apps](http://docs.deployd.com/examples/)

@@ -34,0 +34,0 @@ ## install from npm

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

/*global _dpd:false */
/*global _dpd:false, $:false */
describe('Collection', function() {

@@ -11,9 +11,11 @@ describe('dpd.todos', function() {

this.timeout(1500);
dpd.on('createTodo', function(todo) {
expect(todo).to.exist;
expect(todo.title).to.equal('$REALTIME');
done();
dpd.socketReady(function() {
dpd.once('createTodo', function(todo) {
expect(todo).to.exist;
expect(todo.title).to.equal('$REALTIME');
done();
});
dpd.todos.post({title: '$REALTIME'});
});
dpd.todos.post({title: '$REALTIME'});
});

@@ -24,8 +26,10 @@ });

it('should respond to a realtime event without a parameter', function(done) {
dpd.on('createTodo2', function(todo) {
expect(todo).to.not.exist;
done();
dpd.socketReady(function() {
dpd.once('createTodo2', function(todo) {
expect(todo).to.not.exist;
done();
});
dpd.todos.post({title: '$REALTIME2'});
});
dpd.todos.post({title: '$REALTIME2'});
});

@@ -36,7 +40,9 @@ });

it('should respond to the built-in changed event on post', function(done) {
dpd.todos.on('changed', function() {
done();
dpd.socketReady(function() {
dpd.todos.once('changed', function() {
done();
});
dpd.todos.post({title: 'changed - create'});
});
dpd.todos.post({title: 'changed - create'});
});

@@ -46,7 +52,9 @@

dpd.todos.post({title: 'changed - create'}, function(item) {
dpd.todos.on('changed', function() {
done();
dpd.socketReady(function() {
dpd.todos.once('changed', function() {
done();
});
dpd.todos.put(item.id, {title: 'changed - updated'});
});
dpd.todos.put(item.id, {title: 'changed - updated'});
});

@@ -57,7 +65,9 @@ });

dpd.todos.post({title: 'changed - create'}, function(item) {
dpd.todos.on('changed', function() {
done();
dpd.socketReady(function() {
dpd.todos.once('changed', function() {
done();
});
dpd.todos.del(item.id);
});
dpd.todos.del(item.id);
});

@@ -635,2 +645,57 @@ });

describe('events', function() {
describe('cancelIf()', function() {
it('should cancel', function(done) {
dpd.todos.post({title: "$CANCEL_IF_TEST"}, function(todo, err) {
expect(err).to.exist;
expect(err.message).to.equal("Cancel if");
done();
});
});
});
describe('cancelUnless()', function() {
it('should cancel', function(done) {
dpd.todos.post({title: "$CANCEL_UNLESS_TEST"}, function(todo, err) {
expect(err).to.exist;
expect(err.message).to.equal("Cancel unless");
done();
});
});
});
describe('hasErrors()', function() {
it('should cancel', function(done) {
dpd.todos.post({title: "$HAS_ERRORS_TEST"}, function(todo, err) {
expect(err).to.exist;
expect(err.errors.hasErrors).to.equal("Yep");
expect(err.errors.otherError).to.exist;
done();
});
});
});
describe('errorIf()', function() {
it('should error', function(done) {
dpd.todos.post({title: "$ERROR_IF_TEST"}, function(todo, err) {
expect(err).to.exist;
expect(err.errors).to.exist;
expect(err.errors.errorIf).to.equal("Yep");
done();
});
});
});
describe('errorUnless()', function() {
it('should error', function(done) {
dpd.todos.post({title: "$ERROR_UNLESS_TEST"}, function(todo, err) {
expect(err).to.exist;
expect(err.errors).to.exist;
expect(err.errors.errorUnless).to.equal("Yep");
done();
});
});
});
});
describe('root', function() {

@@ -637,0 +702,0 @@ afterEach(function(done) {

@@ -110,7 +110,9 @@ var credentials = {

it('should respond to the built-in changed event on post', function(done) {
dpd.users.on('changed', function() {
done();
dpd.socketReady(function() {
dpd.users.once('changed', function() {
done();
});
dpd.users.post({username: 'foo@bar.com', password: '123456'});
});
dpd.users.post({username: 'foo@bar.com', password: '123456'});
});

@@ -120,7 +122,9 @@

dpd.users.post({username: 'foo2@bar.com', password: '123456'}, function(item) {
dpd.users.on('changed', function() {
done();
dpd.socketReady(function() {
dpd.users.once('changed', function() {
done();
});
dpd.users.put(item.id, {username: 'foo3@bar.com'});
});
dpd.users.put(item.id, {username: 'foo3@bar.com'});
});

@@ -131,7 +135,9 @@ });

dpd.users.post({username: 'foo2@bar.com', password: '123456'}, function(item) {
dpd.users.on('changed', function() {
done();
dpd.socketReady(function() {
dpd.users.once('changed', function() {
done();
});
dpd.users.del(item.id);
});
dpd.users.del(item.id);
});

@@ -146,7 +152,87 @@ });

}).chain(function(next, res, err) {
dpd.users.put(res.id, {username: 'test'}, next);
dpd.users.put(res.id, {reputation: 10}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
expect(res.reputation).to.equal(10);
done(err);
});
});
it('should not allow unauthenticated changes to username or password', function(done) {
chain(function(next) {
dpd.users.post({username: 'foo', password: 'bar'}, next);
}).chain(function(next, res, err) {
dpd.users.put(res.id, {username: 'changed', password: 'changed'}, next);
}).chain(function(next, res, err) {
expect(res.username).to.equal('foo');
dpd.users.login({username: 'changed', password: 'changed'}, next);
}).chain(function(next, res, err) {
expect(err).to.exist;
done();
});
});
it('should allow authenticated changes to username or password', function(done) {
var id;
chain(function(next) {
dpd.users.post({username: 'foo', password: 'bar'}, next);
}).chain(function(next, res, err) {
id = res.id;
dpd.users.login({username: 'foo', password: 'bar'}, next);
}).chain(function(next) {
dpd.users.put(id, {username: 'changed', password: 'changed'}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
expect(res.username).to.equal('changed');
dpd.users.login({username: 'changed', password: 'changed'}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
done();
});
});
it('should allow changes to username and password via events', function(done) {
chain(function(next) {
dpd.users.post({username: 'foo', password: 'bar'}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
dpd.users.put(res.id, {displayName: "$CHANGEPASSWORD"}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
dpd.users.login({username: 'foo', password: 'changed'}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
done();
});
});
it('should return true for isMe()', function(done) {
var id;
chain(function(next) {
dpd.users.post({username: 'foo', password: 'bar'}, next);
}).chain(function(next, res, err) {
id = res.id;
dpd.users.login({username: 'foo', password: 'bar'}, next);
}).chain(function(next, res, err) {
dpd.users.put(id, {displayName: "Foo Bar!"}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
expect(res.isMe).to.equal(true);
done(err);
});
});
it('should return false for isMe()', function(done) {
var id;
chain(function(next) {
dpd.users.post({username: 'foo', password: 'bar'}, next);
}).chain(function(next, res, err) {
id = res.id;
dpd.users.put(id, {displayName: "Foo Bar!"}, next);
}).chain(function(next, res, err) {
if(err) return done(err);
expect(res.isMe).to.equal(false);
done(err);
});
});
});

@@ -153,0 +239,0 @@

@@ -42,2 +42,12 @@ if (this.title == "$REQUIRE_AUTH") {

this.isRoot = true;
}
cancelIf(this.title === "$CANCEL_IF_TEST", "Cancel if");
cancelUnless(this.title !== "$CANCEL_UNLESS_TEST", "Cancel unless");
if (this.title === "$HAS_ERRORS_TEST") {
error('hasErrors', "Yep");
if (hasErrors()) {
error('otherError', "Yep");
}
}

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

if (this.message === 'notvalid') {

@@ -11,2 +12,5 @@ error('message', "Message must not be notvalid");

this.message += "x";
}
}
errorIf(this.title === "$ERROR_IF_TEST", 'errorIf', "Yep");
errorUnless(this.title !== "$ERROR_UNLESS_TEST", 'errorUnless', "Yep");

@@ -8,3 +8,21 @@ {

"typeLabel": "array",
"id": "friends"
"id": "friends",
"name": "friends",
"order": 0
},
"reputation": {
"name": "reputation",
"type": "number",
"typeLabel": "number",
"required": false,
"id": "reputation",
"order": 1
},
"displayName": {
"name": "displayName",
"type": "string",
"typeLabel": "string",
"required": false,
"id": "displayName",
"order": 2
}

@@ -11,0 +29,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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