diff --git a/Auth.js b/Auth.js index faa1ffd6..ad905654 100644 --- a/Auth.js +++ b/Auth.js @@ -64,6 +64,7 @@ var getAuthForSessionToken = function(config, sessionToken) { var obj = results[0]['user']; delete obj.password; obj['className'] = '_User'; + obj['sessionToken'] = sessionToken; var userObject = Parse.Object.fromJSON(obj); cache.setUser(sessionToken, userObject); return new Auth(config, false, userObject); diff --git a/ExportAdapter.js b/ExportAdapter.js index 89cb6c59..0277e882 100644 --- a/ExportAdapter.js +++ b/ExportAdapter.js @@ -34,8 +34,21 @@ ExportAdapter.prototype.connect = function() { return this.connectionPromise; } + //http://regexr.com/3cn6m + if (!this.mongoURI.match(/^mongodb:\/\/((.+):(.+)@)?([^:@]+):([^:]+)\/(.+?)$/gm)) { + throw new Error("Invalid mongoURI: " + this.mongoURI) + } + var usernameStart = this.mongoURI.indexOf('://') + 3; + var lastAtIndex = this.mongoURI.lastIndexOf('@'); + var encodedMongoURI = this.mongoURI; + var split = null; + if (lastAtIndex > 0) { + split = this.mongoURI.slice(usernameStart, lastAtIndex).split(':'); + encodedMongoURI = this.mongoURI.slice(0, usernameStart) + encodeURIComponent(split[0]) + ':' + encodeURIComponent(split[1]) + this.mongoURI.slice(lastAtIndex); + } + this.connectionPromise = Promise.resolve().then(() => { - return MongoClient.connect(this.mongoURI); + return MongoClient.connect(encodedMongoURI, {uri_decode_auth:true}); }).then((db) => { this.db = db; }); @@ -232,7 +245,7 @@ ExportAdapter.prototype.handleRelationUpdates = function(className, } if (op.__op == 'Batch') { - for (x of op.ops) { + for (var x of op.ops) { process(x, key); } } diff --git a/RestQuery.js b/RestQuery.js index f136206a..8c9bf712 100644 --- a/RestQuery.js +++ b/RestQuery.js @@ -434,7 +434,7 @@ function includePath(config, auth, response, path) { function findPointers(object, path) { if (object instanceof Array) { var answer = []; - for (x of object) { + for (var x of object) { answer = answer.concat(findPointers(x, path)); } return answer; diff --git a/RestWrite.js b/RestWrite.js index e1f3b624..263073f6 100644 --- a/RestWrite.js +++ b/RestWrite.js @@ -371,7 +371,7 @@ RestWrite.prototype.handleFollowup = function() { }; delete this.storage['clearSessions']; return this.config.database.destroy('_Session', sessionQuery) - .then(this.handleFollowup); + .then(this.handleFollowup.bind(this)); } }; diff --git a/functions.js b/functions.js index cf4aeb28..ee2ac541 100644 --- a/functions.js +++ b/functions.js @@ -8,12 +8,12 @@ var express = require('express'), var router = new PromiseRouter(); function handleCloudFunction(req) { - // TODO: set user from req.auth if (Parse.Cloud.Functions[req.params.functionName]) { return new Promise(function (resolve, reject) { var response = createResponseObject(resolve, reject); var request = { - params: req.body || {} + params: req.body || {}, + user: req.auth && req.auth.user || {} }; Parse.Cloud.Functions[req.params.functionName](request, response); }); diff --git a/index.js b/index.js index 6c0a6e13..e884eb67 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,9 @@ addParseCloud(); // and delete // "databaseURI": a uri like mongodb://localhost:27017/dbname to tell us // what database this Parse API connects to. -// "cloud": relative location to cloud code to require +// "cloud": relative location to cloud code to require, or a function +// that is given an instance of Parse as a parameter. Use this instance of Parse +// to register your cloud code hooks and functions. // "appId": the application id to host // "masterKey": the master key for requests to this app // "facebookAppIds": an array of valid Facebook Application IDs, required @@ -52,7 +54,14 @@ function ParseServer(args) { } if (args.cloud) { addParseCloud(); - require(args.cloud); + if (typeof args.cloud === 'function') { + args.cloud(Parse) + } else if (typeof args.cloud === 'string') { + require(args.cloud); + } else { + throw "argument 'cloud' must either be a string or a function"; + } + } cache.apps[args.appId] = { diff --git a/package.json b/package.json index abdcbca8..62c6aec7 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "jasmine": "^2.3.2" }, "scripts": { - "test": "TESTING=1 jasmine" + "test": "TESTING=1 ./node_modules/.bin/jasmine" }, "engines": { "node": ">=4.1" diff --git a/spec/helper.js b/spec/helper.js index 255d61f8..761796a6 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -153,7 +153,7 @@ function normalize(obj) { return '[' + obj.map(normalize).join(', ') + ']'; } var answer = '{'; - for (key of Object.keys(obj).sort()) { + for (var key of Object.keys(obj).sort()) { answer += key + ': '; answer += normalize(obj[key]); answer += ', '; @@ -192,7 +192,7 @@ function mockFacebook() { function clearData() { var promises = []; - for (conn in DatabaseAdapter.dbConnections) { + for (var conn in DatabaseAdapter.dbConnections) { promises.push(DatabaseAdapter.dbConnections[conn].deleteEverything()); } return Promise.all(promises); diff --git a/users.js b/users.js index 8694d0ce..7c0a0a30 100644 --- a/users.js +++ b/users.js @@ -73,7 +73,7 @@ function handleLogIn(req) { 'authProvider': 'password' }, restricted: false, - expiresAt: Parse._encode(expiresAt).iso + expiresAt: Parse._encode(expiresAt) }; if (req.info.installationId) {