{"action":"created","issue":{"url":"https://api.github.com/repos/deployd/deployd/issues/253","labels_url":"https://api.github.com/repos/deployd/deployd/issues/253/labels{/name}","comments_url":"https://api.github.com/repos/deployd/deployd/issues/253/comments","events_url":"https://api.github.com/repos/deployd/deployd/issues/253/events","html_url":"https://github.com/deployd/deployd/issues/253","id":18369666,"number":253,"title":"emitToAll via internal-client should work","user":{"login":"rngadam","id":538542,"avatar_url":"https://avatars.githubusercontent.com/u/538542?v=3","gravatar_id":"","url":"https://api.github.com/users/rngadam","html_url":"https://github.com/rngadam","followers_url":"https://api.github.com/users/rngadam/followers","following_url":"https://api.github.com/users/rngadam/following{/other_user}","gists_url":"https://api.github.com/users/rngadam/gists{/gist_id}","starred_url":"https://api.github.com/users/rngadam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rngadam/subscriptions","organizations_url":"https://api.github.com/users/rngadam/orgs","repos_url":"https://api.github.com/users/rngadam/repos","events_url":"https://api.github.com/users/rngadam/events{/privacy}","received_events_url":"https://api.github.com/users/rngadam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2013-08-21T17:49:46Z","updated_at":"2015-03-13T13:31:15Z","closed_at":null,"body":"This was posted at the end of issue #120 after it was closed and I believe it's still a real issue:\r\n\r\n> Also, calls made via dpd (via internal-client), throw error while trying to emit event > as there is no session. \r\n> e.g.\r\n> emit('object.updated', this);\r\n> \r\n> fail. While its understandable that there is no session, but emitToAll should still be > able to publish the event.\r\n\r\nIn addition, there's a couple places where the code doesn't check for a session object to exist before trying to call emitToAll.\r\n\r\nIn the following, ```if(session.emitToAll)```  should be changed to ```if(session && session.emitToAll)```\r\n\r\n```\r\n$ grep -r \"emitToAll\" *\r\nnode_modules/deployd/lib/resources/collection/index.js:      if(session.emitToAll) session.emitToAll(collection.name + ':changed');\r\nnode_modules/deployd/lib/resources/collection/index.js:          if(session && session.emitToAll) session.emitToAll(collection.name + ':changed');\r\nnode_modules/deployd/lib/resources/collection/index.js:        if(session && session.emitToAll) session.emitToAll(collection.name + ':changed');\r\nnode_modules/deployd/lib/resources/collection/index.js:      if(session && session.emitToAll) session.emitToAll(collection.name + ':changed');\r\nnode_modules/deployd/lib/script.js:        if(session.emitToAll) session.emitToAll(event, data);\r\nnode_modules/deployd/lib/session.js:  this.emitToAll = function() {\r\n```\r\nwhich given this line in the On Post:\r\n\r\n```\r\nemit('emails:create', this);\r\n```\r\nwill cause this line to be emitted:\r\n\r\n```\r\nDEBUG: {\"message\":\"Cannot read property 'emitToAll' of undefined\",\"status\":400\r\n```\r\n\r\nYou can't login from an internal client either to get around the lack of session:\r\n\r\n```\r\n{\"message\":\"resource not found\",\"status\":404}\r\n```"},"comment":{"url":"https://api.github.com/repos/deployd/deployd/issues/comments/78970861","html_url":"https://github.com/deployd/deployd/issues/253#issuecomment-78970861","issue_url":"https://api.github.com/repos/deployd/deployd/issues/253","id":78970861,"user":{"login":"losttime","id":3085626,"avatar_url":"https://avatars.githubusercontent.com/u/3085626?v=3","gravatar_id":"","url":"https://api.github.com/users/losttime","html_url":"https://github.com/losttime","followers_url":"https://api.github.com/users/losttime/followers","following_url":"https://api.github.com/users/losttime/following{/other_user}","gists_url":"https://api.github.com/users/losttime/gists{/gist_id}","starred_url":"https://api.github.com/users/losttime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/losttime/subscriptions","organizations_url":"https://api.github.com/users/losttime/orgs","repos_url":"https://api.github.com/users/losttime/repos","events_url":"https://api.github.com/users/losttime/events{/privacy}","received_events_url":"https://api.github.com/users/losttime/received_events","type":"User","site_admin":false},"created_at":"2015-03-13T13:31:15Z","updated_at":"2015-03-13T13:31:15Z","body":"I ran into this same issue. Is there a workaround?"}}